From ajsiegel at optonline.com Fri Aug 6 09:08:05 2004 From: ajsiegel at optonline.com (Arthur) Date: Fri, 06 Aug 2004 13:08:05 GMT Subject: tweaking @decorator syntax References: Message-ID: On 06 Aug 2004 11:53:29 +0200, Hallvard B Furuseth wrote: > >Still, if we do get a new way to indicate that something is parsed >differently, then a special character like @ would be good for that. >'@some-directive' in general could be a statement which the compiler >reacts to in some way, and decorators could be a special case: > @decorator >instead of just > @ It's mildly interesting, and perhaps slightly relevant, that '@some-directive' fools my news reader into thinking there is a email address reference involved. '@' seeming a strange choice for decorator syntax perhaps in part because it already has a much more pandemic meaning, and in that meaning the thing that is in fact '@' the address precedes the symbol. The Python syntax will be the opposite. Though I find the arguments about viusal layout/ indentation the more compelling, and don't think a change of symbol or the introduction of a keyword in substitution for '@' will help with that more substantial issue. That being said, as a founding memeber of CLA (Chicken Littles Anonymous), it is therapeutic to predict publically that Python will survive the @ decorator syntax, should it stick. Art From alikakakhel3 at hotmail.com Tue Aug 17 18:03:41 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 17 Aug 2004 15:03:41 -0700 Subject: how to display unicode in a Label in Tkinter References: Message-ID: <8f17f4bc.0408171403.313a4f8b@posting.google.com> So how about this: I open MS Word and use the Insert>Symbol method to insert the text I want then copy that into the python editor? From adurdin at gmail.com Thu Aug 5 22:38:22 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Fri, 6 Aug 2004 12:38:22 +1000 Subject: tweaking @decorator syntax In-Reply-To: References: Message-ID: <59e9fd3a04080519383aa7e6c3@mail.gmail.com> On 5 Aug 2004 16:04:00 -0700, Sandy Norton wrote: > Here are some more variations. > > Please copy/paste the code below into your favourite python editor and see > how each syntactical variation of the decorator code reads, and how quickly > you grok its structure and meaning. *snip examples* Of the examples above, I find the "Nested, 'decorate' keyword syntax" by far the most clear. It has the following features (in no particular order) which I find attractive: 1. The nesting makes it abundantly clear what the decoration applies to, namely the function definitions at the next indentation level. And the colon at the end of the "decorate" line is consistent with all other Python keywords which result in another indentation level (def, if, class, etc.) -- which is one reason why I dislike the "nested @decorator" and "nested |decorator|" options. The "Nested, minimal decorator syntax" has indentation, but lacks clarity: it appears merely to be one or a sequence of function calls followed inexplicably by a nested block. 2. The nesting makes it convenient to apply the same decoration to multiple functions, which I guess will be fairly common wherever decorators are used. 3. It doesn't involve adding any additional punctuation to the language. I strongly believe that the general lack of punctuation contributes greatly towards Python's readability. 4. The comma-separated list of decorators allows for more compactness without sacrificing legibility when multiple decorators are used. Whereas I quite dislike the @ syntax, for almost opposite reasons: 5. In appearance it looks like a special kind of statement; and it is not at all obvious to me that it is rather a kind of attribute or modifier of the following function definition. I don't know of any other construction in Python that performs a similar, unmarked (i.e. non-explicit) modification of the following statement. So to me the @syntax comes across as extremely un-Pythonic (by that I mean radically inconsistent with the conventions of the rest of the language). For this same reason, I dislike all the proposed syntaxes which involve placing something before the "def" without a subsequent indented block. 6. When using the same sets of decorators for multiple functions/methods in the same module/class, the @ syntax is inconvenient, as the decorators need to be repeated for each function. (Of course, the current (2.3) syntax to achieve the same result is similarly inconvenient; the @ syntax adds no benefit in this regard, but the "decorate" syntax does). 7. The @ syntax adds more punctuation to Python's syntax: a Bad Thing. Despite the risk of breaking compatibility with some older programs, I firmly believe that adding new keywords is a much better idea in general than adding new punctuation, because (a) keywords are more readable (especially to those unfamiliar with them), and (b) there is a very limited supply of punctuation marks on the keyboard, but a very large supply of words. 8. When using multiple decorators, each appears on a separate line. This not only confuses things with respect to point 5 above (e.g. does the first decorator somehow decorate the second, or do both apply to the function?), but also is IMO unnecessarily lengthy, as each line has the same basic purpose; In analogy, the latter is similar to the difference between x = 1 y = 2 z = 3 and x, y, z = 1, 2, 3 where a compact representation is possible and suitable where the three variables are relating to the same purpose within the program. -- Andrew Durdin From mwh at python.net Sat Aug 7 15:44:59 2004 From: mwh at python.net (Michael Hudson) Date: Sat, 7 Aug 2004 19:44:59 GMT Subject: upper memory limit References: Message-ID: Leandro writes: > There is an upper memory limit in Python? > I have 2GB RAM and 2 processors Xeon 2.4 - (Windows XP), but I just can use > 1.2G of memory, after this python crashes. > Does someone know if python has some memory limit? Not deliberately :-) What are you filling all that memory with? What does "crash" mean? MemoryError, or something more exciting? Cheers, mwh -- ... when all the programmes on all the channels actually were made by actors with cleft pallettes speaking lines by dyslexic writers filmed by blind cameramen instead of merely seeming like that, it somehow made the whole thing more worthwhile. -- HHGTG, Episode 11 From reinhold-birkenfeld-nospam at wolke7.net Fri Aug 20 14:30:22 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Fri, 20 Aug 2004 20:30:22 +0200 Subject: classes are objects... so how can we custom print them: we need a classmethod syntax In-Reply-To: References: Message-ID: <2omu6eFcj75uU1@uni-berlin.de> Neil Zanella wrote: > Hello, > > In Python, classes are objects. But there is no way to custom print a class > object. This would require some syntax such as the one commented out below: > With the current "foo = classmethod(foo)" mechanism custom printing for > class objects is not possible. > > #!/usr/bin/python > > class Foo: > def __str__(self): > return "foo" > #def classmethod __str__(cls): > # return "pythons bite" > > foo = Foo() > s = "hello %s!" % foo # custom text here > print s > > print Foo # no custom text here possible it seems, unless we call > # a staticmethod such as Foo.printMe() You need Metaclasses for that. Consider: >>> class PrintTest(object): ... class __metaclass__(type): ... def __str__(self): ... return "I'm a PrintTest" ... >>> print PrintTest I'm a PrintTest >>> Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From ptmcg at austin.rr._bogus_.com Wed Aug 25 23:36:50 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Thu, 26 Aug 2004 03:36:50 GMT Subject: Is it a bug (or a feature)? References: Message-ID: "Anthony Baxter" wrote in message news:mailman.2373.1093455703.5135.python-list at python.org... > This looks like a bug. Please open a bug on SF, with the example code. Do you mean me or the OP? -- Paul From paolo.veronelli at yahoo.it Thu Aug 26 04:28:14 2004 From: paolo.veronelli at yahoo.it (Paolo Veronelli) Date: Thu, 26 Aug 2004 10:28:14 +0200 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> Message-ID: <412D9F1E.6000809@yahoo.it> Anthony Baxter wrote: > On Wed, 25 Aug 2004 19:47:35 -0400, Paul Morrow wrote: > >>What you're trying to illustrate (I believe) is a superclass doing >>something based on the docstring of a subclass. Yes this certainly does >>happen. But the superclass and subclass are separate objects. I was >>talking about the situation where a function does something based on >>/its own/ metadata. That is what I'm saying virtually never happens, >>and therefore it's ok to make all assignments to __xxx__ attributes >>inside of a function def create /function attributes/ rather than /local >>variables/. > > > This is an extraordinarily complex idea - you're proposing that inside > a function there is now access to a brand new namespace, that of the > function object itself. I don't think you appreciate just _how_ much > work this would requre, nor the complexity of trying to explain this > to users. Remember, at the moment, you can't even get access to the > function object itself from inside the function, without using a hack > like sys._getframe() or raising an exception. It's not the ideas complexity that fears,but the feeling we are trying to bring down to earth the supposed magic of some language solutions. There is nothing good in magic,specially when you have to build robust things on it. > Putting aside nested scopes for the moment, there are three namespaces > that are used in Python - local, module level global, and builtins. > You're proposing that there is a new namespace, that of the function > object, and that it only be used by accessing any local variable that > starts or ends with two underscores. At the moment, the scoping rules > for Python are _extremely_ simple. Do you really want to add something > like this, that looks like a hack, smells like a hack, and who's > implementation would be a hack? I know I don't want to see something > like this. If this blows away clouds on the language future and bring back the useful features in a wider theory where metaclasses and decorators are members of,this shouldn't be considered a hack.If it becomes a hack the problem is to be searched and solved above generalizing the scope system. From mark_bottjer at hotmail.com Thu Aug 12 20:13:53 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Thu, 12 Aug 2004 20:13:53 -0400 Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: References: Message-ID: <411c07c1$1@nntp.zianet.com> Michael Sparks wrote: > On Thu, 12 Aug 2004, Mark Bottjer wrote: >>class C: >> def c(self): >> meta: #declare, decorate, transform, fubar, whatever... >> staticmethod >> doc('Doc.') >> pass > > FWIW, I _personally_ prefer this approach, and the reason I implemented J2 > was solely because I went a) "oooh", b) it looks like it has the same > advantages as the @pies c) the number of times it's been pointed out that > syntaxes with decorators inside the function won't go anywhere, d) The > wiki page said (sorta) that it couldn't be done. Just out of curiosity, how hard do you think it would be to implement this syntax? I know there's not much point, but just for giggles... -- Mark From peter at engcorp.com Wed Aug 4 13:59:46 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 04 Aug 2004 13:59:46 -0400 Subject: web resources to explain why Python is best? In-Reply-To: <41111c24$0$26982$cc9e4d1f@news.dial.pipex.com> References: <41111c24$0$26982$cc9e4d1f@news.dial.pipex.com> Message-ID: davout wrote: > Can anybody point me at some web resources that explain why Python is better > than Perl, TCL, Ruby etc? See the article titled something like "Python vs. Perl according to ..." that is at the very end of the first page returned by Google in response to this search: http://www.google.com/search?q=python+is+better+than+perl By the way, I highly recommend learning to use Google. It's a very effective tool, and avoids wasting lots of other people's time when you have a question which is inevitably going to have been asked many times in the past.... (hint hint) -Peter From daniel at syrinx.net Mon Aug 16 13:09:11 2004 From: daniel at syrinx.net (Daniel Ellison) Date: Mon, 16 Aug 2004 13:09:11 -0400 Subject: Flython? In-Reply-To: References: <411cbcb1$0$3894$4d4ebb8e@news.nl.uu.net><30260531.0408131856.5ef3b0d3@posting.google.com> <2oc547F86br8U1@uni-berlin.de> Message-ID: <2oc7ufF86br8U2@uni-berlin.de> Mike Rovner wrote: > Daniel Ellison wrote: > >>Peter Hansen wrote: > > >>>to come. Flash has a compact bytecode, while SVG comes >>>as XML. Need I say more? >> >>Nope! :) > > > OTOH, Flash bytecode is proprientary and may change "without notice", SVG is > an open standard. Client machines spped is also tend to increase. > > I wish bytecode format be published somewhere. ;) > > Mike > > > The swf file format is proprietary, yes, but the spec is public; you can download it from Macromedia's web site, as Peter did recently. From abra9823 at mail.usyd.edu.au Wed Aug 4 09:56:56 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Wed, 4 Aug 2004 23:56:56 +1000 Subject: Perl's Crypt::PasswdMD5 In-Reply-To: References: Message-ID: <1091627816.4110eb2887355@www-mail.usyd.edu.au> hi! the pycrypto package at http://www.amk.ca/python/code/crypto.html has MD5 and a few other digests and other cryptography tools cheers -- Ajay Brar, CS Honours 2004 Smart Internet Technology Research Group Quoting Bart Nessux : > Does Python have anything similar to Perl's Crypt::PasswdMD5??? > > I read about the crypt module... but it only does DES. Any plans to add > md5 or other digests to it in the future? > -- > http://mail.python.org/mailman/listinfo/python-list > ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From sbabbitt at commspeed.net Fri Aug 13 01:47:01 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Thu, 12 Aug 2004 22:47:01 -0700 Subject: Displaying images stored as binary in MySQL References: Message-ID: <1092376445.837409@news.commspeed.net> "Blaktyger" wrote in message news:c9e6ac92.0408122047.1e3a4309 at posting.google.com... > How can this be done? Images are stored in a LONGBLOB field. When I > try to display them, it prints out the binary data as it is... > > Thank you You could get PIL at http://www.pythonware.com/products/pil/ and try the Image.fromstring() function. Tom From peter at engcorp.com Mon Aug 16 23:14:01 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 23:14:01 -0400 Subject: http://www.freecrm.com In-Reply-To: References: Message-ID: Carol Carrot wrote: > In what ways would I get dorked if I use this website? 1. Please define "dorked" in this context. 2. What, if anything, does this have to do with Python. 3. Why do you think we might know anything about that site? -Peter From __peter__ at web.de Tue Aug 10 03:37:35 2004 From: __peter__ at web.de (Peter Otten) Date: Tue, 10 Aug 2004 09:37:35 +0200 Subject: profile stats interpretation References: Message-ID: Robert Brewer wrote: > I've been working on optimizing some code (yes, it really needs it--it's > too slow ;) -- decided to use hotshot. I'm assuming things about the > output of hotshot.stats that I want to verify before I make decisions > off of them. > > Here's an example of output I'm getting. I coded the same function 3 > different ways--it's basically a type coercer. Each method results in > different stats (for the same request): > > ncalls tottime percall cumtime percall filename:lineno(function) > 17582 0.670 0.000 1.428 0.000 logic.py:133(coerce) > > ncalls tottime percall cumtime percall filename:lineno(function) > 17582 0.509 0.000 1.829 0.000 logic.py:133(coerce) > > ncalls tottime percall cumtime percall filename:lineno(function) > 17582 0.604 0.000 1.202 0.000 logic.py:133(coerce) > > The question is: which of these three should I keep? Is "tottime" the > time of the code within coerce(), without regard to functions called > from coerce()? If so, it seems method #2 is superior. Finally, why might Judging from http://docs.python.org/lib/module-profile.html I would think so. However, You should always pick a function based on its cumulated time. If tottime is low in relation to cumtime that would merely be a hint that you should rather optimize the called functions (not an option in your example) or replace them which may require other changes to the caller (which is what you did). > #3 have a much lower cumtime but higher tottime than #2, given that I > didn't change any other code? Hmmm. > > > FWIW, here's the function. > > Method #1: > > def coerce(self, value, valuetype=None): > if valuetype is None: Instead of > valuetype = type(value) valuetype = value.__class__ might work, too. > try: > xform = self.processors[valuetype] > except KeyError: > xform = self.default_processor # assuming the normal type/value ratio the following # line could drastically increase your hit rate. self.processors[valuetype] = xform > return xform(value) > > Method #2: > > def coerce(self, value, valuetype=None): > if valuetype is None: > valuetype = type(value) > xform = self.processors.get(valuetype, self.default_processor) > return xform(value) > > Method #3: > > def coerce(self, value, valuetype=None): > if valuetype is None: > valuetype = type(value) > if valuetype in self.processors: > xform = self.processors[valuetype] > else: > xform = self.default_processor > return xform(value) > > > Any advice would be appreciated. Once you have spotted a single slow function in heavy usage you can resort to a micro-optimization tool like timeit. A function is "slow" when your app spends a long time in it and the subroutine calls are necessary and cannot be optimized themselves. Then picking the variant with the smallest cumulated time should be a no-brainer. Put another way, hotshot is useful to find the hotspots, i. e. the functions that need optimizing, but not the optimization itself. (Silly disclaimer: I have not yet worked with hotshot, so take this with caution - the experts all seem to be redecorating :-) Peter From lbates at swamisoft.com Mon Aug 2 17:10:24 2004 From: lbates at swamisoft.com (Larry Bates) Date: Mon, 2 Aug 2004 16:10:24 -0500 Subject: How to clear previous console output? References: Message-ID: Try this class I use on both Linux and Windows (console apps). See main program for example usage. HTH, Larry Bates class progressbarClass: def __init__(self, finalcount, progresschar=None): import sys self.finalcount=finalcount self.blockcount=0 # # See if caller passed me a character to use on the # progress bar (like "*"). If not use the block # character that makes it look like a real progress # bar. # if not progresschar: self.block=chr(178) else: self.block=progresschar # # Get pointer to sys.stdout so I can use the write/flush # methods to display the progress bar. # self.f=sys.stdout # # If the final count is zero, don't start the progress gauge # if not self.finalcount : return self.f.write('\n------------------ % Progress -------------------1\n') self.f.write(' 1 2 3 4 5 6 7 8 9 0\n') self.f.write('----0----0----0----0----0----0----0----0----0----0\n') return def progress(self, count): # # Make sure I don't try to go off the end (e.g. >100%) # count=min(count, self.finalcount) # # If finalcount is zero, I'm done # if self.finalcount: percentcomplete=int(round(100*count/self.finalcount)) if percentcomplete < 1: percentcomplete=1 else: percentcomplete=100 #print "percentcomplete=",percentcomplete blockcount=int(percentcomplete/2) #print "blockcount=",blockcount if blockcount > self.blockcount: for i in range(self.blockcount,blockcount): self.f.write(self.block) self.f.flush() if percentcomplete == 100: self.f.write("\n") self.blockcount=blockcount return if __name__ == "__main__": from time import sleep pb=progressbarClass(8,"*") count=0 while count<9: count+=1 pb.progress(count) sleep(0.2) pb=progressbarClass(100) pb.progress(20) sleep(0.2) pb.progress(47) sleep(0.2) pb.progress(90) sleep(0.2) pb.progress(100) print "testing 1:" pb=progressbarClass(1) pb.progress(1) "Newgene" wrote in message news:cem5jm$pcs at odbk17.prod.google.com... > Hi, group, > May I ask a newbie question? > > Given the below example: > > for i in range(100): > print "%s%%" % i > > I want to show the progress by print 1% to 100%. But I hope each > output will clear the previous output before print, so that I can see a > dynamic updated display of percentage, instead of print all percentages > one by one. How can I do that(what about on both windows and unix > platform)? > > Thank you in advance for your expertise. > > Best, > > Cl > From dennis.benzinger at gmx.net Fri Aug 20 07:25:19 2004 From: dennis.benzinger at gmx.net (Dennis Benzinger) Date: 20 Aug 2004 04:25:19 -0700 Subject: Alternative decorator syntax decision References: Message-ID: <3734459e.0408200325.4d413ea2@posting.google.com> My favorites are: J2 J2 K From ndeskins at ecn.purdue.edu Mon Aug 16 11:16:11 2004 From: ndeskins at ecn.purdue.edu (Aaron Deskins) Date: Mon, 16 Aug 2004 10:16:11 -0500 Subject: Newbie question about file input Message-ID: Hello everyone, I'm trying to make a simple python script that will read a text file with a bunch of chess games and tell me how many games there are. The common format for such chess games is the .pgn format (which is just a text file) with the following being typical (with the following file having 2 games): [Event "Quizzes"] [Site "?"] [Date "????.??.??"] [Round "?"] [White "?"] [Black "?"] [Result "*"] [SetUp "1"] [FEN "6k1/5p2/8/4p3/pp1qPn2/5P2/PP2B3/2Q2K2 b - - 0 1"] [PlyCount "5"] 1... Qg1+ 2. Kxg1 Nxe2+ 3. Kf1 Nxc1 * [Event "Quizzes"] [Site "?"] [Date "????.??.??"] [Round "?"] [White "?"] [Black "?"] [Result "*"] [SetUp "1"] [FEN "8/r4pbk/4p2p/8/p5R1/Pq3N1P/1P1Q1PP1/6K1 w - - 0 1"] [PlyCount "5"] 1. Rxg7+ Kxg7 2. Qd4+ Kf8 3. Qxa7 * Basically every game starts with the [Event "..."] header and then the information about the game is given. My first attempt at the python script is: #! /usr/bin/env python import string import sys zf=open('test.pgn','r') # games is number of games games = 0 while 1: line = zf.readline() if line == '': break ls = line.split() print ls[0] if ls[0] == '[Event': games+=1 zf.close() print games I'm having problems when the script reads a blank line from the pgn file. I get the following error message: IndexError: list index out of range The problem is that ls[0] does not exist when a blank line is read. What would be the best way of fixing this? -- Aaron Deskins Graduate Student Chemical Engineering Purdue University From jh at nospam.com Sun Aug 29 06:54:41 2004 From: jh at nospam.com (Hillairet Julien) Date: Sun, 29 Aug 2004 12:54:41 +0200 Subject: [PIL] about the difference between pudata and putpixel Message-ID: Hello, I don't understand how "putdata" from the PIL works : I've got a (N,N) matrix : "color" (an array from numarray lib.), where (N,N) is the size of a image. The next code, give to each pixel of the image the color (an integer 0~255) which is associate in the "color" matrix (an integer matrix, 0~255). It works well, but it's a bit slow: for i in range(N): for j in range(N): im.putpixel((i,j), color[i][j]) Although, this code doesn't work: im.putdata(color) There is no error message, but the image's pixels stay black (0) ! (The color matrix is not an 0-matrix !) Is someone can explain me my misunderstanding of putdata ? Thanks a lot, Julien Hillairet From tim.hochberg at ieee.org Fri Aug 20 11:37:51 2004 From: tim.hochberg at ieee.org (Tim Hochberg) Date: Fri, 20 Aug 2004 08:37:51 -0700 Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: Reid Nichol wrote: > Gerrit Muller wrote: > >> Roel Schroeven wrote: >> >>> Roel Schroeven wrote: >>> >>>> I spotted some errors in your list, added new entries, and made a >>>> histogram: http://roelschroeven.net/pythonages/ >>> >>> >>> >> Very cool. It might be good idea to add a date and time at the top, >> since new datapoint keep coming in? > > How about labels for the axes as well. > > >> and then a quantum leap towards Python. > > You're aware that a quantum leap means a extremely small leap, right? While quanta are typically very-very-very small, last I checked the key feature of quantum transitions is not that they're small, but that there are no intermediate steps. The object is in state A then it's in state B, but it's never halfway (or anywhere) between. Like most quantum stuff it's better not to think about that too closely. -tim From deetsNOSPAM at web.de Thu Aug 26 11:54:43 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Thu, 26 Aug 2004 17:54:43 +0200 Subject: object.* References: Message-ID: DeadWisdom wrote: > I think there should be an ability in python to write something like > "object.*" which should return a dictionary object containing all the > members and their values for the given object. Maybe ".*" could be > treated as an operator. ::shrug:: > > Perhaps the functionality already exists in some other syntax; if so > please splain. dict([(n, getattr(object, n)) for n in dir(object)]) Not really worth an operator :) -- Regards, Diez B. Roggisch From mlh at furu.idi.ntnu.no Tue Aug 24 04:40:27 2004 From: mlh at furu.idi.ntnu.no (Magnus Lie Hetland) Date: Tue, 24 Aug 2004 08:40:27 +0000 (UTC) Subject: Standard graph API? References: Message-ID: In article , David Eppstein wrote: [snip] >I would strongly prefer not to have weights or similar attributes as >part of a graph API. I would rather have the weights be a separate dict >or function or whatever passed to the graph algorithm. The main reason >is that I might want the same algorithm to be applied to the same graph >with a different set of weights. I can see that. [snip stuff about using dicts] This can be said about all objects, really; no reason to have attributes as long as we can associate values with the objects using dicts. This is where things start to look implementation-specific, even though it is *possible* to keep it abstract using this interface. One of my motivations is allowing arbitrary structures behind the scenes, e.g. the graph may be a front-end for something that is computed on-the-fly using specialized hardware (in fact a very real possibilit in my case). I could have something like this be represented by several distinct objects (e.g. one for the topological structure, one for the weights), of course, but I'd certainly have to implement the weight mapping myself, and not use built-in dicts. I do think your API is nice in that it is simple, but I also have the feeling that using it with other implementations would be sort of unnatural; one would be trying to emulate the "dict-of-lists with dicts for properties" implementation, because that implementation *would* have been simple -- had one used it. Also, again, this doesn't lend itself very well to manipulating graphs. If I set one weight to infinity, I might expect (perhaps) the corresponding edge to disappear (otherwise the graph would have to be complete in the first place) or similar things; there may also be other dependencies between properties. Not easily handled with a separate object for each property. And using functions for everything that needs calculating doesn't easily lead to polymorphism... It's not horribly inconvenient, of course (just a matter of defining a few objects referring to the same underlying mechanism, each with a different __getitem__ method). I'm just airing my thoughts about why it *might* be useful to have something else -- possibly in addition. Perhaps one could have something like two levels? The Level 1 Graph API would support the "graph as mapping from nodes to neighbors" with "properties as separate mappings" and the Level 2 Graph API could add some convenience methods/properties for encapsulation and manipulation? [snip] > I think this may contradict some things I said a year or two ago > about using a dict-of-dicts representation in which G[v][w] provides > the weight; Yeah, I remember you saying that :) > I've changed my mind. Fair enough. FWIW, I agree with your new position when it comes to the simple dict-based implementation; this is basically how it's done in pseudocode, usually (e.g. having pi[v] represent the predecessor of v and so forth). -- Magnus Lie Hetland "Canned Bread: The greatest thing since sliced http://hetland.org bread!" [from a can in Spongebob Squarepants] From Florian.Lindner at xgm.de Sun Aug 29 11:29:24 2004 From: Florian.Lindner at xgm.de (Florian Lindner) Date: Sun, 29 Aug 2004 17:29:24 +0200 Subject: os.walk: Get entire path Message-ID: Hello, when I'm walking through a file system hierarchy using os.walk, how can I get the full path of a file or dir? normpath and abspath don't work. Thx, Florian From krajicek at ics.muni.cz Thu Aug 12 13:43:49 2004 From: krajicek at ics.muni.cz (Ondrej Krajicek) Date: Thu, 12 Aug 2004 17:43:49 GMT Subject: Keyword substitution in string Message-ID: Hello, in my application, I want to do keyword substituion in a string from a dictionary. The problem is indeed easy to solve, but seems quite common to me, so I wonder wheter there is already a function in Python which does just that. I want to substitute values for keywords in strings, the keywords and values are stored in a dictionary. Something like this: def subst(string, dict): ... where: subst('Hello, !', {'key1': 'Python', 'key2': 'rules' }) gives: 'Hello, Python rules!' The keyword quoting style does not matter. Thanks, Ondra -- ____________________________\\--//_________________________ Ondrej Krajicek \\// krajicek at ics.muni.cz Institute of Computer Science,||Masaryk University Brno, CR _____________________________//\\__________________________ From mensanator at aol.com Thu Aug 19 19:49:02 2004 From: mensanator at aol.com (mensanator at aol.com) Date: 19 Aug 2004 16:49:02 -0700 Subject: age of Python programmers Message-ID: Roel Schroeven wrote: > Only Event Horizon on TV tonight... What network? For those who haven't seen it, I call a half filled bottle of Coke that's been frozen solid an "Event Horizon" for the explosive decompression that happens when you open it. From cookedm+news at physics.mcmaster.ca Wed Aug 25 23:22:22 2004 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Wed, 25 Aug 2004 23:22:22 -0400 Subject: numarray speed question References: <953AD3D0Didtoken@128.91.2.239> <953C4DD4idtoken@128.91.2.239> <144d0df.0408070828.338f8c19@posting.google.com> <9540516Didtoken@128.91.2.239> <144d0df.0408251616.5758d6e7@posting.google.com> Message-ID: At some point, Tim Hochberg wrote: > grv575 wrote: > > Is it possible to do single precision ffts in numarray or >> no? > > I believe so, but I'm not sure off the top of my head. I recommend > that you ask on numpy-discussion > or peek at the > implementation. It's possible that all FFTs are done double precision, > but I don't think so. Looks like the numarray.fft package uses doubles. If you really need floats, SciPy wraps the single- and double-precision versions of FFTW. (Although SciPy uses Numeric, not numarray). Or, you can make your own version of numarray.fft using floats (actually looks to relatively simple to do). -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From cousinstanley at hotmail.com Wed Aug 18 16:03:36 2004 From: cousinstanley at hotmail.com (Cousin Stanley) Date: 18 Aug 2004 20:03:36 GMT Subject: age of Python programmers References: Message-ID: <2ohr0nFakl4sU1@uni-berlin.de> On 2004-08-18, Lucas Raab wrote: | One thing I've always kind of wondered is what is the average age | of a Python programmer ?? | | What age groups use Python ?? | | Something to think about.... >>> import time >>> >>> tup_lt = time.localtime() >>> >>> now_yr = tup_lt[ 0 ] >>> now_mo = tup_lt[ 1 ] >>> now_da = tup_lt[ 2 ] >>> >>> dob_yr = 1946 >>> dob_mo = 8 >>> dob_da = 9 >>> >>> dy = now_yr - dob_yr >>> dm = now_mo - dob_mo >>> dd = now_da - dob_da >>> >>> print '\n %d Years .... %d Months .... %d Days .... Old \n' % ( dy , dm , dd ) 58 Years .... 0 Months .... 9 Days .... Old >>> -- Cousin Stanley Human Being Phoenix, Arizona From james.collier at xtra.co.nz Wed Aug 11 19:58:34 2004 From: james.collier at xtra.co.nz (James Collier) Date: 11 Aug 2004 23:58:34 -0000 Subject: Capturing repeating group matches in regular expressions In-Reply-To: References: Message-ID: <20040811235834.45616.qmail@cyberdyne.co.mars> Michael Hudson [ mwh at python.net ] writes: > James Collier writes: > >> Is it possible to capture the results of repeating group matches in >> the python regular expression module? > > Not easily; there's a small dicussion on python-dev at the moment > about this. Erik Heneryd hacked up something that might be useful: > > http://mail.python.org/pipermail/python-dev/attachments/20040810/a5e602ab/structmatch.py > > And there's always the "use a real parser" option :-) > > Cheers, > mwh Many thanks for the answer Michael - I take your point on the "real parser" option, but I don't feel that the nut I'm cracking has that thick a shell. It is some coincidence that this should be under current discussion on python-dev. For what it's worth, I'd support Mike Coleman's PEP. To give some more background, I'm tweaking someone else's code and therefore I want to keep the change as concise as is reasonable. structmatch() is exactly what I'm looking for - but for now I'll just split the task into two parts. Thanks again -- James. From aahz at pythoncraft.com Mon Aug 23 14:11:56 2004 From: aahz at pythoncraft.com (Aahz) Date: 23 Aug 2004 14:11:56 -0400 Subject: Has anyone implemented BASIC in Python? References: <2oo13eFcj548U1@uni-berlin.de> <41295D22.8702D583@alcyone.com> Message-ID: In article <41295D22.8702D583 at alcyone.com>, Erik Max Francis wrote: >Leif K-Brooks wrote: >> >> Has anyone ever tried implementing a simple unstructured BASIC dialect >> in Python? I'm getting interested in language implementation, and >> looking at a reasonably simple example like that could be pretty >> interesting. > >On a whim, I implemented a Python BASIC interpreter which supported all >statements in primitive BASIC, but got bored before I implemented all >the standard operators in expressions. For some reason, I thought that after "but" you were going to write, "...but I don't have the proof handy." ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From sholden at flexal.cs.usyd.edu.au Tue Aug 10 03:01:41 2004 From: sholden at flexal.cs.usyd.edu.au (Sam Holden) Date: 10 Aug 2004 07:01:41 GMT Subject: Python equivalent to a C trick References: <1d7b6d0d.0408092255.1177908e@posting.google.com> Message-ID: On 9 Aug 2004 23:55:08 -0700, Dan wrote: > Is there a python equivalent of this trick in C? > > Logic_Test ? True_Result : False_Result > > Example: > printf( "you have %i %s", num_eggs, num_eggs > 1 ? "eggs" : "egg" ); print "you have %i %s" % ( num_eggs, ("egg","eggs")[num_eggs>1] ) But I don't know if int(False)==0 and int(True)==1 are actually guaranteed. And I wouldn't use it since it's ugly (IMHO). You don't get the "only evaluate one" goodness of ?: -- Sam Holden From rschroev_nospam_ml at fastmail.fm Tue Aug 24 03:50:42 2004 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Tue, 24 Aug 2004 07:50:42 GMT Subject: Time-date as an integer In-Reply-To: References: Message-ID: Charles Hixson wrote: > This is a concept, not a finished program, and an extract from a class > at that...so forgive any illegalities, but: > import datetime; > def calcNodeId(self): > t = datetime.utcnow() > val = t.year * 133920000000 + # 12 months > t.month * 11160000000 + # 31 days > t.hour * 3600000000 + # 60 minutes > t.minute * 60000000 + # 60 seconds > t.second * 1000000 + t.microsecond > if val <= self._dTime: > val = self._dTime + 1 > self._dTime = val > return val > > This is the best that I've been able to come up with in getting a > date-time as an integer. It feels like one of the time or date > libraries should have a better solution, but if so, I haven't found it. > Can anyone suggest a better approach? int(time.time()) That gives only second precision, though. Calculations such as the one above can be simplified somewhat by grouping: val = t.microsecond + 1000000 * (t.second + 60 * (t.minute + 60 * (t.hour + 24 * (t.day + # (you forgot this one) 31 * (t.month + 12 * year))))) Or with less indentation, I used it here just to make the grouping clear. -- "Codito ergo sum" Roel Schroeven From aahz at pythoncraft.com Mon Aug 2 10:44:38 2004 From: aahz at pythoncraft.com (Aahz) Date: 2 Aug 2004 10:44:38 -0400 Subject: The term "Protocol" References: <1f7befae04080117515cbb0ca9@mail.gmail.com> <6910338109.20040801192523@ Message-ID: [cc'ing Alex so he can jump in if he wants] In article , Bruce Eckel wrote: > >I know the term "protocol" has been used to describe a language feature >in a number of languages, but since we have no official "protocol" >support in Python I'm interested in what "we" mean by this term. I'm >going to guess that a protocol is like an interface in Java, except >that it doesn't have a concrete definition anywhere, but it is implied >through convention and use. Thus a protocol is a "latent interface." Am >I close? I'd like to understand this term better. Alex Martelli gave an excellent presentation on Design Patterns at OSCON, where he made the point that "interface" is roughly equivalent to syntax, whereas "protocol" is roughly equivalent to syntax plus semantics. In other words, computer langauges rarely (if ever -- although I suppose Eiffel comes close) enforce protocols in any meaningful way. I'm hoping Alex posts his slides soon. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From squirrel at WPI.EDU Tue Aug 10 15:17:13 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 10 Aug 2004 15:17:13 -0400 Subject: decorators vs GIL In-Reply-To: References: <0bidnfbR2_PZOIjcRVn-pA@giganews.com> Message-ID: On 10 Aug 2004, Jacob Hallen wrote: > >That a fairly bright guy (Greg Stein) removed it once and found > >performance to be disappointing doesn't advocate strongly for removal > >of the GIL either. > > So, what we really want to do is to remove the GIL, and keep it. > > Ignoring trivialities like practical implementation, we can do this, since > the moment we start running our program, we will be able to find out > if we are running in an environment were we have access to multiple > processors (and if the program has the ability to use them (at least most > of the time)). If we can use multi-processing, we invoke a Python > interpreter with fine grained locking, otherwise we stick with the > GIL. The real reason behind the GIL is that the Python interpreter is not re-entrant; it keeps internal state in a global structure which must be switched out (and stored somewhere) on thread changes. The real solution to this problem is to make the interpreter stateless, thus obviating the need for the GIL entirely. I think this task would be much easier to do in Stackless than in CPython, but I may be wrong. From kirk at eyegor.jobsluder.net Fri Aug 27 12:10:39 2004 From: kirk at eyegor.jobsluder.net (Kirk Job-Sluder) Date: Fri, 27 Aug 2004 16:10:39 GMT Subject: Regular Expressions References: <808f000f.0408270703.27540e26@posting.google.com> Message-ID: On 2004-08-27, Oriana wrote: > hi! > > I am trying to do some replacements using regular expressions, but > I'm not exactly sure how to do it. I need to replace all ocurrences of > > /****************************************** OR > /* > > for /** ....meaning, any / (forward slash) followed by one or more > asterisks needs to be replaced with /** ....how would I write a pieco > of code to do this?? Please help! Thanks in advance... #first create a regular expression object. foo = re.compile(r"^/\*+") #The regular expression here means match any pattern at the start #of a line (^) followed by a literal asterisk (\*) repeated one or #more times (+). #then use the re object to do the substitution magic. I find the #syntax for re.sub() to be a bit backwards myself. It might help to #think of it as "put the replacement into the line." newline = foo.sub("/**",line) > > Ori -- Kirk Job-Sluder "The square-jawed homunculi of Tommy Hilfinger ads make every day an existential holocaust." --Scary Go Round From roy at panix.com Mon Aug 2 11:24:16 2004 From: roy at panix.com (Roy Smith) Date: Mon, 02 Aug 2004 11:24:16 -0400 Subject: Strange timing data for list.pop() References: Message-ID: In article , Istvan Albert wrote: > Roy Smith wrote: > > > > anybody have any clue what might be causing this behavior? > > Bad experimental setup. Of course it was a bad experimental setup. I didn't measure what I set out to measure. But, I did measure something interesting, and I'm trying to figure out what it was. From rnichol_rrc at yahoo.com Mon Aug 16 23:03:27 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Mon, 16 Aug 2004 22:03:27 -0500 Subject: Python secure? In-Reply-To: References: <2xXTc.3775$bJ2.24876@news1.mts.net> Message-ID: Terry Reedy wrote: > "Peter Hansen" wrote in message > news:NIydnd-skK0q173cRVn-ow at powergate.ca... > >>Reid Nichol wrote: >> >> >>>Terry Reedy wrote: >>> >>> >>>>... compiled C can be terribly insecure relative to >>>>Python. C has dangerous functions like strcpy() which, if used with >>>>external input, can make a program subject to buffer overrun exploits >>>>that >>>>can do explosive damage. >>> >>>But this doesn't make C an insecure language. No language is either >>>secure nor insecure. It's what the programer does with it that > > matters. > > Yes, and in a later sentence, I said something about smarter programmers > and code check policies. Indeed, by the mid-1980s, I knew that giving > control of copying to the block copied, by copying until the block > contained a null byte, could be dangerous. But somewhere around 2000, > Microsoft shipped product that did exactly that with data taken off the > Internet. And because some M$ employee did something sloppy it is an implication that C is bad. Hell, even strncpy can be dangerous. How many times do I have to say the responsibility is the programmers, *not* the language. And what language is Python programmed in... oh yah, C. Perhaps people shouldn't talk about how poorly secure C and then go off to how secure Python is when Python is written in C. Houses built on sand... > Especially if a programmer is rewarded for faster code -- which one write > by copying dangerously -- and pushing the hidden costs off onto customers. If a programmer wanted to finish a program quickly then then shouldn't use C. If the programmer is required to use C then (s)he is working for a bad company that knows nothing of such things and would have produced poor software from the beginning because of such silly things. From martin at v.loewis.de Tue Aug 17 02:42:34 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 17 Aug 2004 08:42:34 +0200 Subject: 'ascii' codec can't encode character u'\xf3' In-Reply-To: References: <4120F820.4000703@fusiondementes.com> Message-ID: <4121A8DA.30802@v.loewis.de> Martin Slouf wrote: > the solution seems to be: > > 0. string is not in unicode encoding (assumption) > 1. before printing out, convert the string to unicode > 2. when printing, convert to whatever charset you like There is an alternative, if the print is a debug print: - print a repr() of the unicode object instead of the unicode object itself. This will work on all terminals, and show hex escapes of non-ASCII characters. > 1. why the string is not in unicode can have several reasons -- i guess: > - does ogg stores tags in unicode? > - you have parsed an xml file with encoding attribute set (that > is what i do) > - etc Correct. > 2. "replace" parameter in encode causes non-printable chars to be > replaced with '?' (you can use "ignore" or strict", see your python > doc) Correct. > 3. the above will work _only_ _if_ the 'str' encoding is "iso-8859-2" -- > a funny thing -- first line of code converts from unknown (but the > programmer must know it) to unicode and the second one converts it back > from unicode to unknown (now the programmer tells that secret to python > :) No. unicode(text) uses the system default encoding (sys.getdefaultencoding()) which normally is ASCII. Printing a Unicode string to a terminal should work fine if the terminal is properly configured. What that means depends on your operating system. > * my assumptions are right Most of them. > > * why is that behaviour? -- if you search google you get > thousands of errors like this -- with no proper solutions i must add There is a proper solution. Unfortunately, very similar yet different problems cause the same error message, and each problem has a different proper solution: - A Unicode error is raised when trying to combine a Unicode string and a byte string, if the byte string contains non-ASCII characters, e.g. u"Martin v. " + "L?wis" The proper solution is to convert the second string into a Unicode object, e.g. through unicode("L?wis", "iso-8859-1") - A unicode error is raised when a Unicode string is printed to a terminal. The proper solution is that the system administrator or the user should properly administer the locale, so that Python knows what characters the terminal can print. For characters that are then still non-printable, repr() is the proper solution. - A unicode error is raised when a library does not support Unicode for some reason. The proper solution is to fix the library. A proper work-around is to explicitly convert Unicode strings into the encoding that the library expects. > * is there an easier portable way (no sitecustomize.py changes) > to do it Yes, see above. > * i was looking in site.py and there is deleted the > sys.setdefaultencoding() function, but from the comments i do > not know why -- you know it? why is user not allowed to change the > default encoding? it seems reasonable to me if he/she could do that. Yes, but that would not be a proper solution. It would mean that your script now only works on your system, and fails on a system where the default encoding has not been changed, or has been changed to something else. Users should use a proper solution instead. Regards, Martin From peter at engcorp.com Mon Aug 30 15:40:41 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 30 Aug 2004 15:40:41 -0400 Subject: Call for signatories for J2 In-Reply-To: <14JYc.8263$6o3.4262@newsread2.news.atl.earthlink.net> References: <14JYc.8263$6o3.4262@newsread2.news.atl.earthlink.net> Message-ID: Arthur wrote: > There is some other syntactical aim here that I wouldn't call "sugar". Once > again, in the context of "decorators", we might need a new word to express > what the intention is here. > > If a core argument in favor is to shortcut programmer input, I think it > should be expressed as an unadorned shortcut. And think @ expresses the > intent, in this respect more baldly and clearly. It looked a whole awful lot to me like the driving force behind the decorator syntax was not to shortcut programmer input, but to move the decorator up to a more prominent position than it occupied with the existing syntax (i.e. after the function, possibly even after lots of other functions, and thus somewhat hidden from the reader). Shortcutting programmer input has, as far as I can tell, never been a goal of Python syntax except, perhaps, the += form when applied merely to primitives... -Peter From alikakakhel3 at hotmail.com Wed Aug 18 17:45:48 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 18 Aug 2004 14:45:48 -0700 Subject: what is wrong with this program? References: <8f17f4bc.0408171623.4f055fb3@posting.google.com> <8VxUc.898$2L3.1@newsread3.news.atl.earthlink.net> Message-ID: <8f17f4bc.0408181345.4871eb89@posting.google.com> Thank you From sdm7g at datastore.lib.Virginia.EDU Thu Aug 12 19:33:53 2004 From: sdm7g at datastore.lib.Virginia.EDU (Steven D. Majewski) Date: Thu, 12 Aug 2004 23:33:53 +0000 (UTC) Subject: pycore (Python on a Smalltalk VM) Message-ID: via Alan Schiffman's blog via Ted Leung's via Lisa Dusseault: http://webpages.charter.net/allanms/2004/08/you-dont-tug-on-supermans-cape.html L. Peter Deutsch is working on implementing Python on top of the VisualWorks Smalltalk VM & JIT compiler. -- Steve Majewski From newsgroups at jhrothjr.com Tue Aug 10 16:06:54 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Tue, 10 Aug 2004 16:06:54 -0400 Subject: PEP-0318 References: <41122FC2.1080608@interlink.com.au><4114152f@nntp.zianet.com><411421bf@nntp.zianet.com> Message-ID: <10hianhqvg1qc8d@news.supernews.com> "Skip Montanaro" wrote in message news:mailman.1459.1092154652.5135.python-list at python.org... > > >> Do people anticipate having lots of decorators for a given function? > > Mark> The way they've been talking, it would appear so. > > Most of the lots-of-decorator examples were probably designed to make a > competing decorator proposal look bad. ;-) > > In reality, I think the number of functions acquiring decorators will be > fairly small unless you go whole hog for something like the > accepts()/returns() example in PEP 318 or do lots of Objective C interfacing > as Bob Ippolito expects to do. In places where decorators will be used, I > suspect their number will typically be smaller than the number of parameters > to the decorated functions. A quick scan of the standard library: > > find . -name '*.py' \ > | xargs cat \ > | egrep '^ *def .*\(.*\):$' \ > | sed -e 's/.*(//' -e 's/).*//' \ > | python -c 'import sys > for l in sys.stdin: > l = l.strip() > if not l: print 0 > else: print len(l.split()) > ' | sort -n | uniq -c > > suggests that most functions have three or fewer parameters: > > 1096 0 > 8072 1 > 4024 2 > 1696 3 > 981 4 > 278 5 > 76 6 > 57 7 > 8 8 > 10 9 > 5 10 > 1 11 > 1 13 > > Even if you account for functions whose parameter lists span multiple lines > I doubt that distribution will change very much. > > My guess is that use of decorators will be even more heavily weighted toward > 0, even after a number of Python releases. One additional use case for decorators: prototype object systems. I've been experimenting with Hans Nowak's system, and I am now quite looking forward to having a single decorator that will bind the function into an instance. For example: @instancemethod(myinstance) def go(self, wordList): ---stuff--- The result is that the function gets wrapped by new.instancemethod and bound into the instance that's bound to myinstance. For a program that uses this style of objects, just about every module level function will be decorated. John Roth > > Skip From indigo at bitglue.com Tue Aug 17 07:29:46 2004 From: indigo at bitglue.com (Phil Frost) Date: Tue, 17 Aug 2004 07:29:46 -0400 Subject: music resources In-Reply-To: References: Message-ID: <20040817112946.GA6630@unununium.org> You might find csound to be useful. It's a very powerful language for expressing a software synthisizer. It has constructs to create instruments and to sequence them. On Mon, Aug 16, 2004 at 11:54:10PM +0000, Elaine Jackson wrote: > Is there such a thing as an executable language for music? If not, why not? And > if yes, where can I find it? Naturally the ideal thing would be if such a > language were implemented within python, but I would be willing to learn a > lesser programming language if I had a reasonable assurance that it had what I'm > looking for. I have, of course, googled for a solution, and I may have even > found it, but if so I didn't recognize it as such. Any pointers will be mucho > appreciado. > > Peace From mark at deverter.net Thu Aug 19 16:07:05 2004 From: mark at deverter.net (md) Date: Thu, 19 Aug 2004 20:07:05 GMT Subject: apache 2 & python In-Reply-To: References: Message-ID: Krzysztof Drozd wrote: > how to configure apache 2 to work with python or mod_python? > > > > krzysiek > > ps: sory,my english is't perfect :) I use Python for my Apache2 CGI scripts without mod_python (have not tried it yet). Using the cgi module you can POST and GET quite easily and it makes for very simple to write dynamic web pages. First, you will need to add an item to httpd.conf. In httpd.conf add a ScriptAlias for your script name(you should already have one for /cgi-bin/ ): ... ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin" ScriptAlias /nameScript/ "/usr/local/apache2/cgi-bin/nameScript.py" ... Then write your script in that location. The script below would expect an http POST or url value like this: http://www.whatever.com/?nameScript&user_name=Foo The script below ties it all in.... +------ #!/usr/bin/python import cgitb; cgitb.enable() #provides HTML error support import cgi form = cgi.FieldStorage() def CGI(content_type="text/html"): return 'Content type: %s\n\n' % content_type def form_val(key): """ Use this simple method to get http POST's """ val = form.getlist(key): if (val == None): return None return val user_name = form_value('user_name') def display_page(name): print CGI() print ""\ "This is %s's page"\ "

Welcome, %s"\ "

" %(name, name) return 1 # display_page(the_name) ----+ There are also other modules you can use to help produce your HTML with out typing it out for yourself and thus making it all more Pythonesque. Hope this wasn't over the top and that it helps. Mark d. From jwkenne at attglobal.net Tue Aug 31 17:36:56 2004 From: jwkenne at attglobal.net (John W. Kennedy) Date: Tue, 31 Aug 2004 21:36:56 GMT Subject: Xah Lee's Unixism In-Reply-To: <4134a207$0$65568$a1866201@newsreader.visi.com> References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <%T%Yc.29567$Es2.11957889@news4.srv.hcvlny.cv.net> <4134a207$0$65568$a1866201@newsreader.visi.com> Message-ID: Craig A. Finseth wrote: > Wrong. The / was chosen as the command line option separator because > whoever wrote MSDOS was looking to CP/M, who modelled their commands > after a PDP-11 operating system (RT-11?). Consider the "PIP" command. > When they went to MS/DOS 2.0 and needed path separators, they found > that "/" was already taken, so they used "\". But there was a hidden > way to tell the command interpreter that it could use "-" for options. Except, of course, that it was useless, because 99% of programs did their own option parsing, and still do. The hidden option only lasted one .1 subrelease, as I recall. > And in all systems starting with 2.0, the system calls have taken "/" > and "\" interchangably. ...which is /one/ thing that the FLOSS community can honestly thank them for. -- John W. Kennedy "Compact is becoming contract, Man only earns and pays." -- Charles Williams. "Bors to Elayne: On the King's Coins" From rschroev_nospam_ml at fastmail.fm Fri Aug 27 05:26:04 2004 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Fri, 27 Aug 2004 09:26:04 GMT Subject: How to generically transform a list? In-Reply-To: References: Message-ID: Roel Schroeven wrote: >> Just out of pure curiosity: Is there a langue that allows vertical and >> horizontal slicing and dicing with the same built-in pattern? > > > You can do it (sorta) in Python: use zip to turn the columns into rows > and vice-versa, apply the slicing, than zip back: > > >>> l = [['a', 1, 11, 'aa'], ['b', 2, 22, 'bb'], ['c', 3, 33, 'cc']] > >>> zip(*(zip(*l)[2:0:-1])) > [(11, 1), (22, 2), (33, 3)] You end up with a list of tuples instead of a list of lists though. -- "Codito ergo sum" Roel Schroeven From nytimes at swiftdsl.com.au Tue Aug 17 11:28:39 2004 From: nytimes at swiftdsl.com.au (huy) Date: Wed, 18 Aug 2004 01:28:39 +1000 Subject: SockerServer.TCPServer problem In-Reply-To: References: <4122147e$0$27220$61ce578d@news.syd.swiftdsl.com.au> Message-ID: <412223af$0$27217$61ce578d@news.syd.swiftdsl.com.au> Jeremy Jones wrote: > huy wrote: > >> Hi All, >> >> Can someone explain why this bit of code can't keep up with some java >> code which spawns about 200 (threads) simultaneous connections each >> sending about 10 mesgs each. I basically don't get the 2000 >> connections i expect on the python side. I end up with some number >> very close on different runs eg. 1989, 1972, 1992 etc. > > > > > (Sorry if I post this twice - I'm trying out a new mail client.) > > You may want to try using the ThreadingTCPServer class rather than > TCPServer. Just change this line: > >> msg_server = SocketServer.TCPServer(("", LISTENING_PORT), PDAHandler) > > > > to this: > > msg_server = SocketServer.ThreadingTCPServer(("", LISTENING_PORT), > PDAHandler) Thanks, I'll try that. > BTW - how are you tracking how many connections you have open with the > Python server? It may be that the process accepts the connection, puts > them into a queue to be handled, and waits for the deals with them as it > can. Or is the 2000 the total number of connections that the 200 > threads produce over the whole run (each making 10 connections)? > every connection creates a file. i count the number of files created. > Jeremy Jones From tvlgiao at yahoo.com Tue Aug 3 09:44:29 2004 From: tvlgiao at yahoo.com (tvlgiao(tm)) Date: Tue, 3 Aug 2004 06:44:29 -0700 (PDT) Subject: problem with unicode? Message-ID: <20040803134429.96407.qmail@web52306.mail.yahoo.com> Hi, I have a problem with unicode. In the Python Shell (Python GUI), i wrote a line: >>> print u"tr???nh v?? long giao" i want to print an unicode string, but the interpreter printed an error: Unsupported characters in input does the interpreter not understand unicode chars? my program has some unicode strings, i can not save it with Python GUI IDE. does my python have problem? i use Python 2.3. can anybody help me? thanks tvlgiao --------------------------------- Do you Yahoo!? New and Improved Yahoo! Mail - 100MB free storage! -------------- next part -------------- An HTML attachment was scrubbed... URL: From MKUMBALE at southernco.com Fri Aug 27 13:25:12 2004 From: MKUMBALE at southernco.com (Kumbale, Murali T.) Date: Fri, 27 Aug 2004 13:25:12 -0400 Subject: Help with Fortran output Message-ID: <430EA1CD6A7724418280E742512F2F9A075ABD@GAXGPEX22.southernco.com> I am new to Python and redirection etc. I created a simple COM object in Visual FORTRAN called "disp.disp" that writes to the WINDOWS console. I wrote a Python script which looks like the following import win32com.client o = win32com.client.Dispatch("disp.disp") o.SimpeAdd(5) SimpleAdd method takes the argument supplied (the number 5 in this case) and adds 10 to it and then writes to FORTRAN standard output using WRITE(6,...). This bombs as I don't know how to capture the FORTRAN output written to WINDOWS console to Python console. Please help. Murali From imbaczek-nospam at poczta.fm.cut-from-here.no-spam.info Mon Aug 2 08:33:18 2004 From: imbaczek-nospam at poczta.fm.cut-from-here.no-spam.info (Marek =?iso-8859-2?Q?Baczy=F1ski?=) Date: Mon, 2 Aug 2004 14:33:18 +0200 Subject: Sets Module Bug? References: Message-ID: <1v4c457rlxrze.dlg@baczek.net.invalid> Dnia Mon, 02 Aug 2004 05:25:50 -0400, Chris S. napisa?(a): > How can a Set using a tuple or list be ok, but not a tuple of lists? Because tuples can't be changed once they're constructed (= immutable.) You'd get the same error if you tried to do >>> d = {[1,2]: 'foo'} Traceback (most recent call last): File "", line 1, in -toplevel- d = {[1,2]: 'foo'} TypeError: list objects are unhashable -- Marek Baczy?ski :: UIN 57114871 :: GG 161671 :: JID imbaczek at jabber.gda.pl He who knows best best knows how little he knows. -- Thomas Jefferson From brett at python.org Mon Aug 30 15:02:10 2004 From: brett at python.org (Brett C.) Date: 30 Aug 2004 12:02:10 -0700 Subject: TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' In-Reply-To: Message-ID: For Bourne-style shells (BASH, ZSH, etc.) ``export CC=gcc`` will do it for the current shell (won't save it for future use, that requires setting it in your shell's config file. For CSH style I think it is ``setenv CC gcc`` but I am not sure. From roy at panix.com Sun Aug 15 21:48:55 2004 From: roy at panix.com (Roy Smith) Date: Sun, 15 Aug 2004 21:48:55 -0400 Subject: Python secure? References: <411ffef6$0$65603$a1866201@newsreader.visi.com> <41200b23$0$8090$a1866201@newsreader.visi.com> Message-ID: Grant Edwards wrote: > > That being true, it's still a good idea for me to lock the > > door when I leave the house. > > I suppose so, but it has nothing to do with the topic at hand. The OP was asking if Python offered a way to prevent disclosure of his source code. The statement was made that copyright laws would protect him. My point was not to examine the details of copyright and/or reverse engineering laws, but to point out that even if there is legal protection for the code, it's still a good idea to take active steps to prevent its disclosure. Protecting the code prevents theft. IP laws only give you a basis for legal action after the code is stolen. From newgene at bigfoot.com Mon Aug 2 16:11:13 2004 From: newgene at bigfoot.com (Newgene) Date: 2 Aug 2004 13:11:13 -0700 Subject: How to clear previous console output? Message-ID: Hi, group, May I ask a newbie question? Given the below example: for i in range(100): print "%s%%" % i I want to show the progress by print 1% to 100%. But I hope each output will clear the previous output before print, so that I can see a dynamic updated display of percentage, instead of print all percentages one by one. How can I do that(what about on both windows and unix platform)? Thank you in advance for your expertise. Best, Cl From reinhold-birkenfeld-nospam at wolke7.net Sat Aug 7 14:39:17 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Sat, 07 Aug 2004 20:39:17 +0200 Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) In-Reply-To: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> References: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> Message-ID: <2nklgpF1ph3dU2@uni-berlin.de> Istvan Albert wrote: > Voting for the "list-after-def" syntax as shown above: > > Peter Hansen > AdSR > Paul McGuire m > Phillip J. Eby pje at telecommunity.com > C. Barnes > Aahz aahz at pythoncraft.com > Skip Montanaro skip at pobox.com > Bill Janssen janssen at parc.com > Istvan Albert ialbert at mailblocks.com +1 Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From gh at ghaering.de Fri Aug 6 14:22:42 2004 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Fri, 06 Aug 2004 20:22:42 +0200 Subject: Obscure bug in pyPgSQL In-Reply-To: <246a4e07.0408052331.2cdd7e92@posting.google.com> References: <246a4e07.0408052331.2cdd7e92@posting.google.com> Message-ID: <4113CC72.6090500@ghaering.de> Frank Millman wrote: > Hi all > > Below is the text of a message I was about to send in connection with > an obscure problem. I have now almost got to the bottom of it, and am > fairly confident that it is a bug in pyPgSQL. I hope this is the > correct place to report such bugs. If not, please advise the correct > forum. [...] Please file a bug on the pyPgSQL bug tracker on Sourceforge. This way, it's less likely that this will get lost: http://sourceforge.net/projects/pypgsql -- Gerhard From grante at visi.com Sat Aug 28 12:36:41 2004 From: grante at visi.com (Grant Edwards) Date: 28 Aug 2004 16:36:41 GMT Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1ry8k0d2az.fsf@rovereto.ifi.uio.no> <87acwgvy51.fsf@sinken.local.csis.hku.hk> <2pb36dFibuj3U1@uni-berlin.de> <41309d32$0$65611$a1866201@newsreader.visi.com> <1gj8pg5.1e6z0kiprvfxuN%aleaxit@yahoo.com> Message-ID: <4130b499$0$62953$a1866201@newsreader.visi.com> On 2004-08-28, Alex Martelli wrote: >> IMO, the only non-ugly, non-hack solution would be to have >> another set of delimters that are used as tuple-constructors so >> tha the syntax for a literal tuple, a literal list, and a >> literal dictionary are consistent. [...] > I think 'commas makes tuples when the commas don't mean anything else' > should stay, though, because somedict[x, y] or a,b=b,a depend on that, > and I find them just too sweet to lose!-) > > This of course is all pretty hypothetical, just like the idea > of introducing a new set of delimiters -- won't happen in > Python, not even in 3.0. Just musing about some details of > language design. Mostly it won't happen because there just aren't enough delimiters in any common characer set for everything -- especially if you want indexing and function-calling to have postfix-operator-delimters that are unique from all of the aroundfix-literal-contsructor-delimiters. Or something like that. -- Grant Edwards grante Yow! I'm a GENIUS! I at want to dispute sentence visi.com structure with SUSAN SONTAG!! From tor.iver.wilhelmsen at broadpark.no Sat Aug 14 03:57:22 2004 From: tor.iver.wilhelmsen at broadpark.no (Tor Iver Wilhelmsen) Date: 14 Aug 2004 09:57:22 +0200 Subject: Import command References: Message-ID: yong at net.tamu.edu (Yong Wang) writes: > ImportError: ld.so.1: /usr/local/bin/python: fatal: relocation error: file /usr/local/lib/libreadline.so: symbol tputs: referenced symbol not found This looks like a problem with the version of the native readline library; that is, it seems to be the Python runtime, independent of the script run. Do you get the same error running other Python scripts as well? From h.b.furuseth at usit.uio.no Sat Aug 28 12:42:59 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 28 Aug 2004 18:42:59 +0200 Subject: pep-318 questions References: Message-ID: Sorry with the late reply; when I got back to clp I had the silly idea that I'd try to catch up with the decorator threads before answering... Anyway, Skip Montanaro wrote: > Hallvard> The current syntax seems like the clear loser here too: No > Hallvard> whitespace above the function name. Not too bad with a single > Hallvard> decorator, but several is a problem. > > There's no requirement that you smash them all together. This is valid with > the current patch: > > @ a > > # comment > # comment > # comment > # comment > @ b > > > def func(*args, **kwds): > ... Which is even worse because one can easily miss some of the decorators after locating the function. > >> Finally, it would require the introduction of a new keyword. > > Hallvard> Actually, I'm wondering about that too. > > Nobody has so far been able to come up with a single keyword that seems to > connote "this is a decorator function that is to be applied to the next > function definition". I thought the main objection to a keyword is that it breaks existing code; I wasn't talking about _which_ keyword to choose. My point is that maybe the J2 syntax does _not_ need to be a keyword. It should work to recognize statements that begin with one word and a colon, and treat that word as a pseudo-keyword in that statement. As far as I can tell, that does not break anything: A valid statement cannot begin with a non-keyword followed by a colon today. That also makes 'apply' a candidate for the... pseudo-keyword, if anyone still wants that one. And if anyone wanted to, one could make 'else', 'try' and 'finally' into non-keywords so they could be used as variables:-) -- Hallvard From alikakakhel3 at hotmail.com Wed Aug 18 18:02:36 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 18 Aug 2004 15:02:36 -0700 Subject: what wrong with this program? References: <8f17f4bc.0408171632.787eb6f8@posting.google.com> Message-ID: <8f17f4bc.0408181314.29d2136c@posting.google.com> Robert Kern wrote in message news:... > Ali wrote: > > > The following program is supposed to display a dropdown menu, however, > > it only shows the File and Help things. > > > > from Tkinter import * > > > > root = Tk() > > > > #create menu > > m = Menu(root) > > root.config(menu=m) > > > > filemenu = Menu(m) > > m.add_cascade(label="File", menu="filemenu") > > The menu= argument needs to be the object itself, not a string. > > See, e.g. > > http://www.pythonware.com/library/tkinter/introduction/x5819-patterns.htm ok I will try it out. Thanks for your help From eadorio at yahoo.com Sun Aug 1 07:41:49 2004 From: eadorio at yahoo.com (Ernie) Date: 1 Aug 2004 04:41:49 -0700 Subject: Quixote demo References: <5b42ae4.0407301634.2e72a8f8@posting.google.com> <5b42ae4.0407311512.b9928f6@posting.google.com> Message-ID: <5b42ae4.0408010341.76555c1@posting.google.com> Regarding my post below, I rewrote RewriteRule ^/qdemo(/.*) /var/www/cgi-bin/demo.cgi$1 [last] as RewriteRule ^/qdemo(/.*) http://%{HTTP-HOST}/cgi-bin/demo.cgi$1 [last] and it now works, at least on Mozilla and Opera amd in Konqueror partly. The latter pops up a window to ask me to save or open the page on some selections, say on "error" and "factorial". I wonder when the majority of the Python community decide on a preferred app/web server framework or combine the commonalities of many rich, powerful and unfortunately fragmented choices: webware, quixote, spyce, snakelets, webware, zope, twisted, etc? You don't have to think or learn more than "one obvious way to do it" in Java or PHP. When Pythonistas claim Python is indeed better for writing web apps, what mature Python production quality package will you recommend instead of Java or Php? Ernie eadorio at yahoo.com (Ernie) wrote in message news:<5b42ae4.0407311512.b9928f6 at posting.google.com>... > Hi, > > Now, this is OT (sorry). Any hints from users of quixote uing Linux > Mandrake version 9.1 (or greater) Linux distribution on how to do > successfully do the indirect running of demo.cgi? The docs say I have > to add the line in Apache httpd.conf > > RewriteRule ^/qdemo(/.*) /www/cgi-bin/demo.cgi$1 [last] > > Unfortunately, there are a lot of confusing places for httpd.conf's in > my system. > > /usr/share/ADVX/compat/httpd.conf > /usr/share/ADVX/advx-migrate-commonhttpd.conf > /usr/share/ADVX/advx-migrate-httpd.conf > /etc/httpd/conf/commonhttpd.conf > and also > /etc/httpd/conf/httpd2.conf > /etc/httpd/2.0/conf/httpd2.conf > /etc/httpd/2.0/conf/commonhttpd.conf > > I picked on, say, /etc/httpd/2.0/conf/httpd2.conf and just appended > > RewriteEngine on > RewriteRule ^/qdemo(/.*) /var/www/cgi-bin/demo.cgi$1 [last] > > However, the http://localhost/qdemo/ does not work in my browser. I > have tried the other locations, and still no go. > > TIA for any helps. > > Ernie. From Florian.Lindner at xgm.de Sun Aug 29 09:02:00 2004 From: Florian.Lindner at xgm.de (Florian Lindner) Date: Sun, 29 Aug 2004 15:02:00 +0200 Subject: Get all subdirs Message-ID: Hello, how can I get all subdirectories of a given directory. os.listdir(dir) doesn't differentiate between directories and files, os.walk seems to me a bit overkill since it also descends in the subdirs. Thx, Florian From newsgroups at jhrothjr.com Thu Aug 19 16:27:56 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Thu, 19 Aug 2004 16:27:56 -0400 Subject: PEP 318: Can't we all just get along? References: <20040817181725194-0400@braeburn.themorgue.org> <10i9msuatli5p84@news.supernews.com> Message-ID: <10ia3aa8j6tbma5@news.supernews.com> "Michael J. Fromberger" wrote in message news:Michael.J.Fromberger-D24476.14010119082004 at localhost... > In article <10i9msuatli5p84 at news.supernews.com>, > "John Roth" wrote: > > > "Kevin Smith" wrote in message > > news:20040817181725194-0400 at braeburn.themorgue.org... > > > For what it's worth, I wrote the original PEP 318. [...] > > > > > > In my opinion, none of the proposed syntaxes really seem Pythonic. > > > This PEP just seems to be trying to solve too many problems. > > > > The arguement is, and always has been, about syntax. Everyone agrees > > that the current situation is not ideal; putting the wrapping > > assignment statement after the method is a very poor way of declaring > > intent. > > I agree that the current situation is not ideal. However, I would also > argue that many of the proposed replacements are even worse. Kevin > Smith's latest proposal (cf. ) is, in > my view, the most reasonable suggestion so far. > > > In other words, forget the use cases. They're irrelevant. > > On this point, I strongly disagree. If you don't have a use case, there > is no point whatsoever in arguing about the syntax of a feature. There is a use case. If you go back and read the original post I was replying to, it contains the sentence: [begin quote] I guess others had bigger plans for my proposal that I had planned. It has turned into the "solution" to many problems: type checking (both arguments and returned values), metaclasses, metadata, interfaces, function attributes, etc.). [end quote] This is the context in which you should have taken my comment to "forget the use cases." The original use case (classmethod and staticmethod) is clearly still there, as my comments in the post you reply to should have made clear. John Roth > > Now, if you want to argue about general syntactic design principles, > maybe that is an interesting topic -- but it is one level removed from > what PEP-318 is all about, and therefore (in my opinion) not really > germane to the present discussion. > > -M > > -- > Michael J. Fromberger | Lecturer, Dept. of Computer Science > http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From jeff at ccvcorp.com Tue Aug 24 14:45:53 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Tue, 24 Aug 2004 11:45:53 -0700 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 23) In-Reply-To: References: Message-ID: <10in35vb3n72led@corp.supernews.com> Anthony Baxter wrote: >[1] I don't count my snarking as a particularly useful form of >participation - more a combination of trying to keep people honest and >my normal contrariness. > > On the contrary, I'd say that your commentary has had a very useful effect, even if only by defining a target for those who were interested in actually *doing* something as opposed to just complaining. It's only by shifting gears to aim for that target that anything useful (the J2 implementation and paper) came about. Jeff Shannon Technician/Programmer Credit International From joewong at mango.cc Tue Aug 24 06:07:57 2004 From: joewong at mango.cc (Joe Wong) Date: Tue, 24 Aug 2004 18:07:57 +0800 Subject: is this thread safe? Message-ID: <090f01c489c2$3beb3eb0$7f00a8c0@scl01.siliconcreation.com> Hi, I have a variable that need to be incremented by 1 as follow: v += 1 Is this threadsafe? Do I need to put a lock around this? Best regards, - Joe -------------- next part -------------- An HTML attachment was scrubbed... URL: From justin__devine at hotmail.com Mon Aug 30 14:09:38 2004 From: justin__devine at hotmail.com (Justin) Date: 30 Aug 2004 11:09:38 -0700 Subject: "Content-Length" header In-Reply-To: <41336be3$0$8079$a1866201@newsreader.visi.com> Message-ID: I just figured I narrowed my problem down so I would check if anyone knew how to request the header I need. From martin at v.loewis.de Sat Aug 7 01:03:51 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 07 Aug 2004 07:03:51 +0200 Subject: Further changes to source encodings (Was: PEP 263 status check) In-Reply-To: <10h8f3md11sou81@news.supernews.com> References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> <10h5hgvpafm8a64@news.supernews.com> <41133C76.8040302@v.loewis.de> <10h6rklt3fa1690@news.supernews.com> <41137799.70808@v.loewis.de> <10h724r20kkeqb2@news.supernews.com> <4113D8DF.8080106@v.loewis.de> <10h7tb8nn53ajbb@news.supernews.com> <4114070F.90507@v.loewis.de> <10h8f3md11sou81@news.supernews.com> Message-ID: <411462b5$0$27020$9b622d9e@news.freenet.de> John Roth wrote: > I don't believe I ever said that PEP 263 said there was > a difference. If I gave you that impression, I will > appologize if you can show me where it I did it. In <10h5hgvpafm8a64 at news.supernews.com>, titled " PEP 263 status check", you write [quote] My specific question there was how the code handles the combination of UTF-8 as the encoding and a non-ascii character in an 8-bit string literal. Is this an error? [end quote] So I assumed you were all the time talking about how this is implemented, and how you expected to be implemented, and I assumed we agree that the implementation should match the specification in PEP 263. > As far as I'm concerned, what PEP 263 says is utterly > irrelevant to the point I'm trying to make. Then I don't know what the point is you are trying to make. It appears that you are now saying that Python does not work the way it should work. IOW, you are proposing that it be changed, right? This sounds like another PEP. > The only connection PEP 263 has to the entire thread > (at least from my view) is that I wanted to check on > whether phase 2, as described in the PEP, was > scheduled for 2.4. I was under the impression it was > and was puzzled by not seeing it. You said it wouldn't > be in 2.4. Question answered, no further issue on > that point (but see below for an additonal puzzlement.) Ok. A change of subject might have helped. > 8-bit strings have a builtin assumption that one > byte equals one character. Not at all. Some 8-bit strings don't denote characters at all, and some 8-bit string, atleast in some regions of the world, are deliberately using multi-byte character encodings. In particular, UTF-8 is such an encoding. > It's a basic assumption > in the string module, the string methods and all through > just about everything, and it's something that most > programmers expect, and IMO have every right > to expect. Not at all. Most string methods don't assume anything about characters. Instead, they assume that the building block of a byte string is a "byte", and operate on those. Only some methods of the string objects assume that the bytes denote characters; they typically assume that the current locale provides the definition of the character set. > Now, people violate this assumption all the time, > for a number of reasons, including binary data and > encoded data (including utf-8 encodings) > but they do so deliberately, knowing what they're > doing. These particular exceptions don't negate the > rule. Not at all. These usages are deliberate, equally-righted applications of the string type. In Python, the string type really is meant for binary data (unlike, say, C, which has issues with NUL bytes). > The problem I have is that if you use utf-8 as the > source encoding, you can suddenly drop multi-byte > characters into an 8-bit string ***BY ACCIDENT***. Ok. > (I don't know what happens with far Eastern multi-byte > encodings.) The same issues as UTF-8, plus some additional worse issues. > Now, my suggested solution of this problem was > to require that 8-bit string literals in source that was > encoded with UTF-8 be restricted to the 7-bit > ascii subset. Ok. I disagree that this is desirable; if you really want to see that happen, you should write a PEP. > The second possibility begs the question of what > encoding to use, which is why I don't seriously > propose it (although if I understand Hallvard's > position correctly, that's essentially his proposal.) No. He proposes your third alternative (ban non-ASCII characters in byte string literals), not just for UTF-8, but for all encodings. Not for all files, though, but only for selected files. >>If >>there is no encoding declaration whatsoever, Python will >>assume that the source is us-ascii. [...] > The last sentence puzzles me. In 2.3, absent a declaration > (and absent a parameter on the interpreter) Python assumes > that the source is Latin-1, and phase 2 was to change > this to the 7-bit ascii subset (US-Ascii). That was the > original question at the start of this thread. I had assumed > that change was to go into 2.4, your reply made it seem > that it would go into 2.5 (maybe.) This statement makes > it seem that it is the current state in 2.3. With "will assume", I actually meant future tense. Not being a native speaker, I'm uncertain how to distinguish this from the conditional form that you apparently understood. > Specifically, what would the Python 2.2 interpreter > have done if I handed it a program encoded in utf-8? > Was that a legitimate encoding? Yes, the Python interpeter would have processed it. print "Gr?? Gott" would have send the greeting to the terminal. > I don't know whether > it was or not. Clearly it wouldn't have been possible > before the unicode support in 2.0. Why do you think so? The above print statement has worked since Python 1.0 or so. Before PEP 263, Python was unaware of source encodings, and would literally copy the bytes from the source code file into the string object - whether they were latin-1, UTF-8, or some other encoding. The only requirement was that the encoding needs to be an ASCII superset, so that Python properly detects the end of the string. Regards, Martin From ndeskins at ecn.purdue.edu Tue Aug 17 11:07:42 2004 From: ndeskins at ecn.purdue.edu (Aaron Deskins) Date: Tue, 17 Aug 2004 10:07:42 -0500 Subject: Newbie question about file input In-Reply-To: References: Message-ID: Christopher T King wrote: > On Tue, 17 Aug 2004, Aaron Deskins wrote: > > >> Also, what exactly is stored when a blank line is read by the >>readline command? A zero, blank, or what??? > > > readline() always includes the '\n' that terminates the line, so any > 'blank' line that is read will be returned as a simply '\n'. The only > time readline() won't return a line terminated with '\n' is if the last > line of the file isn't terminated with '\n' (common on Windows), in which > context a blank line is meaningless. > So why does a linesplit fail after the program reads a blank line (or a '\n')? Is this simply because there's no way to assign the variable '\n' ? -- Aaron Deskins Graduate Student Chemical Engineering Purdue University From anthonybaxter at gmail.com Sun Aug 8 04:24:58 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sun, 8 Aug 2004 18:24:58 +1000 Subject: @decorator syntax is sugar, but for what exactly? In-Reply-To: References: Message-ID: On Sat, 7 Aug 2004 20:24:45 -0400, Robert wrote: > I have read a few Python blogs and not a one is taking the decorator syntax > in a good way. Most of the posts I read seemed to be from people having a visceral response to the syntax. I think it's fair to say that many of the people complaining about the syntax have not actually downloaded the alpha and tried out the new decorators in actual code. > The Python of 1.5.2 simplicity will be long gone. The "Python of 1.5.2 simplicitly" is long, long gone. I don't agree that newer Python's are somehow worse because new things have been added. A short list: new style classes foo(*arg, **kwarg) iterators generators list comprehensions In many cases, these new features actually lead to smaller, simpler code. I challenge _anyone_ to tell me that apply(func, args, kwargs) is better than func(*args, **kwargs) From in.aqua.scribis at nl.invalid Thu Aug 19 10:16:24 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Thu, 19 Aug 2004 16:16:24 +0200 Subject: speed In-Reply-To: References: Message-ID: John Lenton schreef: > flex has an option to generate code without the gotos... I have the latest version. I can't find it, not as run time option, not as build option. -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From peter at engcorp.com Thu Aug 5 08:41:05 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 05 Aug 2004 08:41:05 -0400 Subject: Decorator syntax In-Reply-To: <10h46c0l0kol830@corp.supernews.com> References: <38ednYT1NLz1P4zcRVn-uA@powergate.ca> <10h46c0l0kol830@corp.supernews.com> Message-ID: <5cKdnSPsIed_t4_cRVn-pg@powergate.ca> Edward K. Ream wrote: >>Anyway, check the past discussions before going back around >>the same arguments yet again. > > And exactly how is one supposed to do this? I would have thought the pep > would be the place to start, but pep 318 is actively misleading as to the > state of the project. I'm pretty sure it would involve using Google Groups and keywords such as "decorator syntax", but I haven't personally tried. I can provide remedial instruction to those who try the above and variations on it but who are still unable to find *any* past discussions of this topic. ;-) -Peter From roy at panix.com Wed Aug 25 08:59:07 2004 From: roy at panix.com (Roy Smith) Date: Wed, 25 Aug 2004 08:59:07 -0400 Subject: Why return None? References: Message-ID: In article , Martin DeMello wrote: > Dan Sommers wrote: > > > If list.sort returned the sorted list, how many lists would there be > > after this code executed? > > > > original_list = a_function_that_returns_a_list( ) > > sorted_list = original_list.sort( ) > > One - sorted_list would be a reference to the (now sorted) original > list. The newbie problem could be solved by having and > versions of each destructive method - i.e. list.sort() to sort the list > in-place and return it, and list.sorted() to return a new, sorted list, > and experienced users could chain methods and all that other good stuff. > > martin The problem with sort() vs. sorted() is that it's obscure. I'm not a big fan of quoting gospel, but it seems to me that it violates the gospel of "explicit is better than implicit". If I took 10 programmers who were generally familiar with typical OO syntax, but not specifically with Python and asked them what list.sort() and list.sorted() did, I imagine all of them would say something like, "Well, they both obviously sort a list, and clearly the existence of two different methods means they do it differently somehow, but I can't for the life of me guess what the difference is". Explicit would be something like having two methods named in ways that people could figure out without having to RTFM: list.sort () ==> returns a sorted copy of the list list.sort_in_place () ==> sorts in place, returns None or if you prefer to do it the other way: list.sort () ==> sorts in place, returns None list.sort_copy () ==> returns a sorted copy of the list But, personally, I find that all kind of silly; IMHO, list.sort () should have just returned self to begin with and then we wouldn't be having this discussion. heretic-ly yours. From pm_mon at yahoo.com Sun Aug 15 15:44:25 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sun, 15 Aug 2004 15:44:25 -0400 Subject: Decorators: an outsider's perspective In-Reply-To: References: <20040814153534.8AC171E4007@bag.python.org> Message-ID: Bengt Richter wrote: > > I think I pretty much agree with you (Paul), except that I think the test for > 'self' (and analogously 'cls') should be a name.startswith(...) test. > There are a few nested-scope cases where it is necessary to distinguish > two simultaneous and distinct 'self'-parameter bindings, and you need distinct > names to avoid shadowing the outer with the inner. No time to look for the example > I'm thinking of, but I'm sure you can create one (if Peter Otten doesn't beat you to it ;-) > Ok, I spent 10 minutes thinking about the situation you describe and can't come up with anything. I'd love to see the example you're referring to. I'm even more curious how you would document such a class :-) From tchur at optushome.com.au Wed Aug 4 19:43:50 2004 From: tchur at optushome.com.au (Tim Churches) Date: Thu, 05 Aug 2004 09:43:50 +1000 Subject: Finding all time periods for a given interval within a daterange Message-ID: <200408042343.i74NhpL01678@mail015.syd.optusnet.com.au> An embedded and charset-unspecified text was scrubbed... Name: not available URL: From indigo at bitglue.com Wed Aug 18 18:51:26 2004 From: indigo at bitglue.com (Phil Frost) Date: Wed, 18 Aug 2004 18:51:26 -0400 Subject: static class methods and data members In-Reply-To: References: Message-ID: <20040818225126.GA14005@unununium.org> take a look at classmethod and staticmethod with pydoc, in the docs, or help(). Static data members are done like so: Class C: iAmStatic = 1 def __init__(self): self.iAmNotStatic = 2 Thinking of this in terms of "static" and "automatic" isn't the way to go, really. That's C's way of doing it, and it's in Java only because Java is nothing more than C. Here's how it works: There are classes, and there are instances of those classes. Each has a namespace. when one does .name, "name" is located first in the instance namespace, then in the class namespace. However, assignment is different. Assignment just looks in the instance namespace, and if it's not there, it creates it. Thus if one were to do "self.iAmStatic" in a method of C, that does not change the value of iAmStatic for all instances of C. However, one can do "C.iAmStatic" anywhere, and that will change "iAmStatic" for all instances of C that do not have 'iAmStatic' bound to something at the instance level. The best way to understand this is through experimentation in the interactive interpreter. To make things easier, you can peek inside python's implementation by doing C.__dict__ or anInstanceOfC.__dict__ to see the dictionary that represents that namespace. After you have absorbed this, you will probably see the use of classmethod, as it's not immediately apparent if you aren't familiar with Python. Happy hacking! On Wed, Aug 18, 2004 at 02:42:19PM -0700, Neil Zanella wrote: > Hello, > > I would like to know whether it is possible to define static class methods > and data members in Python (similar to the way it can be done in C++ or Java). > These do not seem to be mentioned in "Learning Python" by Mark Lutz and David > Ascher. It seems like they are a relatively new feature... It seems to me that > any truly OO programming language should support these so I'm sure that Python > is no exception, but how can these be defined/implemented in Python? Currently > I have Python version 2.3 installed on my system. > > Thanks, > > Neil From eric_brunel at despammed.com Tue Aug 17 03:46:02 2004 From: eric_brunel at despammed.com (Eric Brunel) Date: Tue, 17 Aug 2004 09:46:02 +0200 Subject: how to display unicode in a Label in Tkinter References: <8f17f4bc.0408151819.c06a79e@posting.google.com> <8f17f4bc.0408161437.2f557935@posting.google.com> Message-ID: Ali wrote: > Eric Brunel wrote in message news:... > >>Ali wrote: >> >>>I was wondering how one would go about displaying unicode in a Label >>>object in a Tkinter window. I am trying to display text in another >>>language. Please help. >> >>Just put it in a Unicode string or in a raw string encoded in UTF-8 and you >>should be going: >> >> >>> from Tkinter import * >> >>> root = Tk() >> >>> s = '????: ?a marche!' >> >>> u = unicode(s, 'iso8859-1') >> >>> Label(root, text=u).pack() >> >>(The code above supposes your default encoding is iso8859-1, a.k.a latin-1; >>otherwise, you can do: s = '\xe0\xe9\xe8\xf9: \xe7a marche!') >> >>HTH > > > So how I write in Arabic? The general answer would be to use the unicode codes for the various characters you use, e.g.: >>> from Tkinter import * >>> root = Tk() >>> Label(root, text=u'\u0646').pack() If you want to do that, you'll find http://www.unicode.org/versions/Unicode4.0.0/bookmarks.html very useful (especially section 8 in your case). But it's quite hard to type characters this way... There must be another simpler way, based on the standard encoding used when using Arabic characters. But I don't know this encoding, so I cannot help you much here. I also don't know how you can input these characters in a computer (especially in a source file, where the character flow is from left to right) So I can only return the question: how do *you* usually input Arabic characters in a source file? Knowing that and the encoding you use, putting Arabic text in Tkinter labels won't be difficult at all. HTH -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From nomail at nomail.nomail Sun Aug 8 09:25:44 2004 From: nomail at nomail.nomail (Dominic) Date: Sun, 08 Aug 2004 15:25:44 +0200 Subject: Going the PL/1 way In-Reply-To: References: Message-ID: > I've got a faint idea that this "subset" approach greatly contributes to the > unpopularity of Ada. Well, this may be true. I do not know. I have read some papers about the SPARK ADA subset. It has been chosen so that they can prove certain properties and be happy with most compilers. For safety critical or embedded applications ADA is not too bad. It is probably more often used in this field than Python. Maybe this can be changed for better.. ;-) > And perhaps he might stay healthy longer than that young one who eats each > and every new nutriment and colourful shiny berries. Yes, there is some truth in here. I knew you were going to write that. ;-) Nikolaus Wirth must have had such an attitude when he designed Oberon. Aesthetically Oberon is a very fine language. However if you peek into Oberon source code you will often see that they have used linked lists and rewritten the code everywhere. Because they do not have _generics_ and casting seems not popular among Oberon programmers. Purity comes with a price tag. Nevertheless, I think Python has been pretty feature complete and I am not sure if @decorators are good or bad. The addition of generators though has helped me a lot. I'll have to trust the Python language designers since nobody seems to have actual data to support or discard @decorators. As far as I know they are part of C# and Java (recently). Maybe some experience and data has been gathered by them. Ciao, Dominic From jerf at jerf.org Mon Aug 30 00:32:05 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Mon, 30 Aug 2004 04:32:05 GMT Subject: allowing braces around suites References: Message-ID: On Mon, 30 Aug 2004 10:54:08 +1000, Delaney, Timothy C (Timothy) wrote: > Igor V. Rafienko wrote: > >> As a side note -- my last employer had absolutely horrible coding >> conventions. No one liked them (developers and management included). >> However, everyone had to comply, and despite an occasional nastiness, >> the bug that you illustrated could not have happened in that >> environment, because _every_ if was required to have its body within >> braces. > > In C/C++/Java, that's a sensible coding convention. I won't quibble that > there may have been other ones in the coding standards that were bad, > but that specific example is not. It is a continual surprise to me that the Great Mother of TMTOWIDI (Perl) actually got this right. (In Perl, "if", "for", and friends all *require* braces when used conventionally. When used as a suffix ("print $x if $iShould;"), it doesn't, but I don't find that offensive.... partially because I only rarely use it.) From ajsiegel at optonline.com Wed Aug 25 09:22:33 2004 From: ajsiegel at optonline.com (Arthur) Date: Wed, 25 Aug 2004 13:22:33 GMT Subject: python-dev Summary for 2004-08-01 through 2004-08-15 References: Message-ID: <3l3pi0pgmgu0uir1ucnj0rlfo355c6i5cp@4ax.com> On Mon, 23 Aug 2004 21:50:48 -0700, Brett Cannon wrote: > >But then Guido decided to make my life difficult by saying that if the >community could come up with an agreed-upon alternative syntax to >propose to him he would consider ripping out the '@' syntax; decorators >have always been experimental and '@' was checked in so people had >*something* to play with. This meant everyone and their mother started >to propose both new and old syntaxes for decorators. This led to a >record amount of email on python-dev (at least compared to what we have >archives for; back to April 1999). >"In the old days, Guido would Pronounce, and we'd all bite our tongues >(although not necessarily each his own). The less time Guido can make >for Python, the more important becomes graceful capitulation." Tim said >this and it makes me wish for the old days. People had *months* to >comment on decorators and no one spoke up until something went into the >language. Procrastination is not a virtue when it comes to major >language evolution discussions. What was worse was when the emails >started repeating themselves (which was pretty much from the get-go when >this exploded). Seemed like people decided to start talking without >doing some research. Granted the PEP was outdated and the wiki page was >not up yet, but this stuff was covered in the Summaries before and you >could have just Googled for the previous threads. Perhaps you could clarify your position a bit. I think the "community" understands some fundamental difference between posting to python-dev and to python-list. If not Aahz is normally there to remind them. Guido's "genius" extends to marketing, IMO. Having some sense of participation in the fate of Python, even if bit hullicinatory, is fundamental to the development of its following. A clasic form of guerilla marketing. Considering that the Python markteing budget in $ is 0, I think it would be a mistake to have the community believe that their only role is to read the release notes. > >Personally, if I was Guido, I would have said that the community had >their chance to speak up and they just didn't take it. I think you are inadvertently going somewhere dangerous here. A significant part of the community finds that their first appropriate opportunity to comment to be after some initial decision at python-dev - the Senate. It then goes to the People. We the rowdy poeple then do our rowdy thing. You see the point... I don't think you want to say to the People, either to crash the Senate floor, or hold their peace, Art From dave at pythonapocrypha.com Fri Aug 13 15:27:32 2004 From: dave at pythonapocrypha.com (Dave Brueck) Date: Fri, 13 Aug 2004 13:27:32 -0600 Subject: Why I love python. In-Reply-To: References: Message-ID: <411D1624.5000700@pythonapocrypha.com> Nick Patavalis wrote: > On 2004-08-13, Dave Brueck wrote: >>Nobody is arguing that Python is as fast as C. But being slower does >>not imply that Python is unsuitable for those tasks. I'd consider >>your list to be pretty atypical of normal development (how many TCP >>stacks and relational databases need to get written each year?), > > > I also mentioned web-browsers, ray-tracers, circuit-simulators. I > could add word-processor, spreadsheets, video editing programs, and > GUI toolkits to the list. Are they still too exotic? No - but I still don't think they reflect anywhere near a majority of the development that goes on. I'm not at all saying that there aren't applications where performance matters, just that (1) it tends to be far less common than most people believe/realize (2) when it does matter, it usually matters in a very tiny portion of the total code, and (3) rarely in today's development do you need to build from scratch everything down to the building blocks themselves anyway (so if you're e.g. building a web browser, in many cases you won't even be dealing with lowest level data anyway - you won't be handling individual pixels but will be calling a library somewhere else to render an image for you - and as the developer of the web browser, that's just peachy) IOW, it'd be lovely to have a blazingly fast-as-C Python, but the lack of fast-as-C performance is rarely the most important problem in practice. > To cut the thread > short, what I mean is that an application that has to do something > like: > > for i in range(N): > a[i] = b[i] + c[i] > > is bound to be 10 to 100 times slower than the equivalent coded in > C. Which means that the cost of doing *computation* in Python is > prohibitively high! Not necessarily, and that's the point. You're making the assumption that 10-100 times slower is too slow. In some cases it most definitely is. In many cases it most definitely is not. > Have you ever seen, say, an AVL-tree > implementation in production Python code? Probably not. Have you ever > seen someone implementing some sort of string-lookup algorithm in > Python (instead of using the build-in dictionaries)? Again no. Is it > because Python has found the "one-size-fits-all", > "best-algorithm-ever-devised" solution? Or is it because in 99% of the cases what is there works good enough, so much so that obtaining the difference is not worth the opportunity cost of working on something else? If you have an overabundance of a particular resource, and you can gain some advantage in exchange for some of that abundance, it's nearly always worth the trade. Such is the case with CPU - for many, many programs we have oodles of excess CPU time lying around, so it's a worthwhile trade. And that's exactly why everybody would love a faster Python but most people aren't willing to invest time working on it. I welcome any speed boost we see from people working on improving performance, but it's just not what's standing between me and most of my development goals. Heck, right now I'm writing this message, I've got my mail & IM messages going, a couple of code editors open, a virtual PC instance running my database and webserver, and I'm building web pages off content in the database and saving them to disk. CPU usage is hovering around 5%. If I were to increase the speed of all of these applications by a factor of 1000 I wouldn't even notice. Add a few features to any of them, and I would. > Or is it because the weight of > the language itself is such that even a suboptimal algorithm > implemented in C will never be matched by a python implementation? Practice has shown that, not only is this not true, but that a lot of times working in a higher level language is also worth it because the cost of discovering and implementing a better algorithm is cheaper, so you could end up with better performance than going to C. Or, you'd arrive at plenty-fast-enough sooner. > No, but the performance difference between C and Assembly was > *small*. Over time, yes, but certainly not initially. I still remember how appallingly slow my graphics routines were in C - way too much overhead - while in assembly they had no problems at all. > And at some point the C compilers became so good, that you > couldn't beat them by hand coding something (of considerable length) > in assembly. That happened later, at least on PCs. The real transition happened as CPU speed grew so much that the difference between e.g. 4.77 MHz and 10 MHz was boring. > As for C++, one of its primary design-goals were "zero > unneeded overhead"; so it *is* possible to write a C++ program that is > as fast as a C program, if you want to do it. It was a design goal, but (1) implementations didn't achieve it very well initially and (2) in the end it didn't matter that they didn't achieve it. More and more people migrated to C++ because the cost of doing so (overhead) fell steadily over time - even more quickly than the compilers improved. > and I want to be sure that---by guiding > the compiler properly---it will produce code that is as efficient as a > well-written C program, or hand-coded assembly (or at least close to > that). Ugh - any time you spend guiding the compiler is time you could have spent actually solving a problem. I find it interesting that when programming in C we don't use the 'register' compiler hint anymore. Why? It's a combination of smarter compilers and faster computers, but either way its existence was awful IMO - don't distract the programmer like that. I *love* it whenever I see that Pystone benchmarks are improving, or that any of the various VM implementations are making headway, and I'll gladly use them. But at the same time, I have to admit that they aren't solving any problems I encounter on a daily basis. > For Python to become a "primary" language, there's > still much work to be done. Couldn't disagree more. Yes, things like interpreters, compilers, etc. could use more maturity and will continue to evolve over time, but even _lacking_ those things it's still far enough ahead of other "primary" languages to make the _net_ result a huge advantage. With the evolution of those things the advantage will just become more pronounced. > But some of it has to do with > ensuring---at the language level---that efficient environments are > possible. Again, I disagree. IMO one of the benefits of higher level languages is that they underlying implementation technology takes care of details that the developer need not be concerned with. Overall, every little performance improvement in a Python implementation extends the domain in which Python is a good tool for the job, and that's great. But AFAICT it's already a terrific fit for a massive chunk of real-world development, so much so that increasing its speed by, say, a factor of 10 isn't going to even double its domain of usability. -Dave From rschroev_nospam_ml at fastmail.fm Thu Aug 26 16:22:48 2004 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Thu, 26 Aug 2004 20:22:48 GMT Subject: age of Python programmers In-Reply-To: <3353cd1e.0408261150.c0c6fc5@posting.google.com> References: <3353cd1e.0408261150.c0c6fc5@posting.google.com> Message-ID: Tony Clarke wrote: > If this carries on, we'll all be a year older , and have to start again... I've been thinking about writing a small web application that allows everyone to enter his/her birthday (and gender perhaps?), so the ages are always up-to-date. But alas, I don't have the time to do it. Would be nice, though. -- "Codito ergo sum" Roel Schroeven From mdione at vialibre.org.ar Fri Aug 20 18:05:27 2004 From: mdione at vialibre.org.ar (Marcos Dione) Date: Fri, 20 Aug 2004 19:05:27 -0300 Subject: "Socket" files? In-Reply-To: <1093035812.83612@jubilee.esoterica.pt> References: <1093035812.83612@jubilee.esoterica.pt> Message-ID: <20040820220527.GE31960@martina.fsl.org.ar> On Fri, Aug 20, 2004 at 09:58:43PM +0100, Paulo da Silva wrote: > How are those "files" of type "socket", whose name > begins with "=", created? How can I create them with > python? they don't start w/ =; that's just ls being verbose. try 'ls -1'. you can create them with os.mkfifo. see lib doc, section 6.1.4. From peter at engcorp.com Tue Aug 17 09:45:52 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 17 Aug 2004 09:45:52 -0400 Subject: How big can a Python program be? In-Reply-To: References: Message-ID: Ben Last wrote: > Unless I've misremembered, the Python interpreter executes lines as they're > entered, whether read from a file or typed in (with the exception that > blocks of code made up of multiple lines are executed when the last line is > complete), so in theory, one could feed code to Python indefinitely and it'd > just keep going. You've misremembered. Python actually *compiles* the code prior to executing it, turning it into bytecode. That means there is definitely a limit on how much code can be handled, based if nothing else on the memory in your PC. -Peter From detlev at die-offenbachs.de Mon Aug 9 14:20:27 2004 From: detlev at die-offenbachs.de (Detlev Offenbach) Date: Mon, 09 Aug 2004 20:20:27 +0200 Subject: VB-like GUI designer? References: Message-ID: Fred wrote: > Hi, > > I'm currently checking out Python as an alternative to VB.Net > to moving from VB, but can't find a GUI designer that is as good as > VB. > > I tried wxDesigner and wxGlade, but neither lets me move the widgets > around. I also tried Dialogblocks, but it seems to only handle C++ or > XRC, not Python. > > Is this all there is, or is there a gem I missed? > > Thank you > Fred. Give "eric3" a try (http://www.die-offenbachs.de/detlev/eric3.html). It is a complete Python IDE using Qt-Designer for GUI development and Qt-Linguist for translating the GUI. Detlev -- Detlev Offenbach detlev at die-offenbachs.de From Scott.Daniels at Acm.Org Thu Aug 26 19:16:17 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 26 Aug 2004 16:16:17 -0700 Subject: What GCC version had defined? In-Reply-To: <412E55A9.9070400@v.loewis.de> References: <412e39d1$1@nntp0.pdx.net> <412E55A9.9070400@v.loewis.de> Message-ID: <412e70d3$1@nntp0.pdx.net> Martin v. L?wis wrote: > Scott David Daniels wrote: > >> Does anyone know which version of GCC introduced stdint.h (and >> thereby uintptr_t and intptr_t)? I'd like to get the conditionals >> right. > > > stdint.h is not part of GCC; it is part of libc6. You shouldn't do > #ifdefs based on version numbers, but instead, you should do checks > based on the features of the software, like autoconf does. > > Regards, > Martin Well, currently pyconfig.h for 2.4 says: ... #if _MSC_VER != 1200 #define HAVE_UINTPTR_T 1 #define HAVE_INTPTR_T 1 #endif ... which is actually a pretty low bar to get over. I'd like to change it to something like: ... #if _MSC_VER > 1200 #define HAVE_UINTPTR_T 1 #define HAVE_INTPTR_T 1 #endif ... #if GCC_VERSION >= 30100 #define HAVE_UINTPTR_T 1 #define HAVE_INTPTR_T 1 #endif ... which is arguably better even if not good enough. Is there a better test I can do at compile time? -Scott David Daniels Scott.Daniels at Acm.Org From wweston at att.net Wed Aug 4 10:54:14 2004 From: wweston at att.net (wes weston) Date: Wed, 04 Aug 2004 14:54:14 GMT Subject: MySQLdb 'server not initialized' In-Reply-To: References: Message-ID: Daniel Baggott wrote: > Hi, > > I'm seeking assistance in troubleshooting connecting to MySQL (4.0.20) > using Python (2.3.4) and MySQLdb (1.0.0). When I attempt to make a > connection, I get the following exception: > _mysql_exceptions.InternalError: (-1, 'server not initialized') > > The database is definitely running as I can connect to it using the > mysql client. Also, when I attempt to connect to MySQL from within > Python, I don't see any messages in the MySQL logs (ie the .log and .err > files in /usr/local/mysql/data/). > > Does anyone have any advice or suggestions as to how to figure out > what's going wrong? Also, if there's a better forum for posting this > question, please point me in the right direction. > > Thanks! > > Dan > > > [baggott2 at goingto baggott2]$ python > Python 2.3.4 (#1, Jul 26 2004, 15:14:49) > [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-34)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>>>import MySQLdb >>>>c = > > MySQLdb.connect(host='localhost',user='gbd',passwd='xxxxxxx',db='zinc') > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/local/lib/python2.3/site-packages/MySQLdb/__init__.py", > line 64, in Connect > return apply(Connection, args, kwargs) > File "/usr/local/lib/python2.3/site-packages/MySQLdb/connections.py", > line 116, in __init__ > self._make_connection(args, kwargs2) > File "/usr/local/lib/python2.3/site-packages/MySQLdb/connections.py", > line 41, in _make_connection > apply(super(ConnectionBase, self).__init__, args, kwargs) > _mysql_exceptions.InternalError: (-1, 'server not initialized') > > > > [baggott2 at goingto baggott2]$ mysql -h localhost -u gbd -p > Enter password: > Welcome to the MySQL monitor. Commands end with ; or \g. > Your MySQL connection id is 9 to server version: 4.0.20-standard-log > > Type 'help;' or '\h' for help. Type '\c' to clear the buffer. > > mysql> show databases; > +----------+ > | Database | > +----------+ > | zinc | > +----------+ > 1 row in set (0.00 sec) > > mysql> Bye > [baggott2 at goingto baggott2]$ > > Daniel, I have these two additional args in my connect call: port=3306,unix_socket="/tmp/mysql.sock" wes From Scott.Daniels at Acm.Org Sun Aug 29 08:31:42 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 29 Aug 2004 05:31:42 -0700 Subject: my first class: Args In-Reply-To: References: <4130cf9d@nntp0.pdx.net> <41315680$1@nntp0.pdx.net> Message-ID: <4131ce22$1@nntp0.pdx.net> Peter Kleiweg wrote: > Scott David Daniels schreef: >> > class Args: ... >> > def __init__(self,usage=): >> > ... >> > self._argv = sys.argv[1:] >>if __name__ == '__main__': >> --> >> class Args: ... >> def __init__(self, progname, args, usage=): >> >> def demo(progname, args): >> a = Args(progname, args, >> 'Usage: %(progname)s [-a value] [-b value] [-c] word [file...]') >> >> >>if __name__ == '__main__': >> demo(sys.argv[0], sys.argv[1:]) > > This goes against the purpose of the class: to take care of as > much of the overhead of script writing as possible. So I can > simply do this: ^^ By the way, this goes at the top of your module comment -- it lets users understand in 3 (or 6 if you add the example) lines. > > import args > > a = args.Args() > for line in a: ... I am not saying you are wrong, exactly, but I will explain why I prefer my style. In my style, I increase the chance that I can reuse programs without changing (or even really reading) them. This allows something else to get "in the way" when you decide to build another application from some you already have. For example: import sys, app1, app2 progname = sys.argv[0] break = sys.argv.index(1, ';') app1.main(progname + 'part1', sys.argv[1 : sep]) app2.main(progname + 'part2', sys.argv[sep :]) Perhaps a compromise between the two styles would be closer to your aesthetic, where the call is: > a = args.Args(sys.argv) > for line in a: ... More work on combining, but less work on using. At any rate it has been fun blathering about style. --Scott David Daniels Scott.Daniels at Acm.Org From fuzzyman at gmail.com Wed Aug 25 10:33:25 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 25 Aug 2004 07:33:25 -0700 Subject: Begginers questions on different distributions of py References: Message-ID: <6f402501.0408250633.ed3a129@posting.google.com> Python 2.3.4 is a lsight bugfix on previous 2.3 serious distributions. To the best of my knowledge you won't notice *any* difference in practise. I've been coding python for over a year and doen quite a lot with it - and haven't got into anything esoteric enough to be able to tell the difference between 2.3.2 and 2.3.4 (in any 2.x distribution the 'interfaces' ought to remain stable - even if bugs are fixed, the way you use stuff doesn't change. That doesn't apply to the 2.4 alpha releases of course). HTH Regards, Fuzzy http://www.voidspace.org.uk/atlantibots/pythonutils.html From anthonybaxter at gmail.com Fri Aug 6 12:33:12 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 7 Aug 2004 02:33:12 +1000 Subject: @decorators In-Reply-To: References: Message-ID: On Fri, 06 Aug 2004 08:19:43 -0400, Roy Smith wrote: > I just went to read pep-318 in its entirety, and discovered that the > last modified date is only a few hours ago. People might want to go > read the latest version. Don't get too excited - there's going to be a lot more updates happening to it still. From hans at zephyrfalcon.org Sat Aug 14 13:57:48 2004 From: hans at zephyrfalcon.org (Hans Nowak) Date: Sat, 14 Aug 2004 13:57:48 -0400 Subject: Decorators: an outsider's perspective In-Reply-To: References: Message-ID: <411E529C.2070808@zephyrfalcon.org> Chas Emerick wrote: > I thought I'd finally break my lurker status here by passing along a > comment I made in connection with this weblog post > , one of many > deriding the controversial feature of @decorators. This post wasn't deriding decorators; rather, it explains them, and provides some examples of how to use them. I do question their usefulness, but I'm not deriding them, nor the "@" syntax. -- Hans Nowak (hans at zephyrfalcon.org) http://zephyrfalcon.org/ From cjw at sympatico.ca Tue Aug 24 14:00:23 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Tue, 24 Aug 2004 14:00:23 -0400 Subject: How does a "script" differ from a "program" or "subroutine"? In-Reply-To: References: <2p0v42FfaqerU1@uni-berlin.de> Message-ID: Dennis Lee Bieber wrote: [snip] > And to confuse the matter, the old FORTRAN terminology (at > least, in my old classes) referred to "function subprograms" and > "subroutine subprograms". > Yes, because the former returned a value, the latter did not. Colin W. From davebrok at soda.csua.berkeley.edu Mon Aug 23 04:36:31 2004 From: davebrok at soda.csua.berkeley.edu (David Pokorny) Date: Mon, 23 Aug 2004 01:36:31 -0700 Subject: J2 proposal: keyword References: Message-ID: "Anthony Baxter" wrote in message news:mailman.2175.1093233838.5135.python-list at python.org... > On Mon, 23 Aug 2004 00:23:32 +0100 (BST), Michael Sparks > wrote: > > I discovered this after replacing "decorate" with "using" and > > rerunning the test suite... Incidentally the syntax also allows > > code like this: > > > > using: > > staticmethod synchronised memoise deprecated > > def: foo(bar): > > "This function foos bars all day long" > > pass > > The pie-decorator syntax was modified shortly after a2 to require > one decorator per line. I think for readability's sake, this was a good > call, and would urge you to do this in any new syntax. There must be some cognitive-visual thingamajig going on here because I find using: staticmethod synchronized memoize def bar(foo): "upends the established order of metasyntactic keywords" pass much more readable than @staticmethod synchronized memoize def bar(foo): "upends the established order of metasyntactic keywords" pass [I think it has something to do with the traffic jam at the left margin.] Aesthetically, putting multiple decorators per line allows the eye to scan in all of them in one fell swoop. In other words, the one-liner using: staticmethod synchronized memoize def bar(foo): "To colon or not to colon? Def is the question." pass is easy on the eye while using: staticmethod synchronized memoize def bar(foo): "english teachers will call you on putting two colons in one sentence" pass looks like the SUV of decorators ;) David From beliavsky at aol.com Fri Aug 6 15:27:14 2004 From: beliavsky at aol.com (beliavsky at aol.com) Date: 6 Aug 2004 12:27:14 -0700 Subject: Paul Graham on Python hackers Message-ID: <3064b51d.0408061127.32536826@posting.google.com> Paul Graham's recent book "Hackers & Painters" may be interesting readers for Python programmers. He likes flexible languages like Python, although Lisp is his favorite. Here is a quote from his book, also online at http://www.paulgraham.com/gh.html , where he contrasts Python and Java programmers. He is opinionated :). "When you decide what infrastructure to use for a project, you're not just making a technical decision. You're also making a social decision, and this may be the more important of the two. For example, if your company wants to write some software, it might seem a prudent choice to write it in Java. But when you choose a language, you're also choosing a community. The programmers you'll be able to hire to work on a Java project won't be as smart as the ones you could get to work on a project written in Python. [2] And the quality of your hackers probably matters more than the language you choose. Though, frankly, the fact that good hackers prefer Python to Java should tell you something about the relative merits of those languages. Business types prefer the most popular languages because they view languages as standards. They don't want to bet the company on Betamax. The thing about languages, though, is that they're not just standards. If you have to move bits over a network, by all means use TCP/IP. But a programming language isn't just a format. A programming language is a medium of expression." From abra9823 at mail.usyd.edu.au Wed Aug 4 21:08:07 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Thu, 5 Aug 2004 11:08:07 +1000 Subject: bsddb In-Reply-To: <411185C7.2020705@bitglue.com> References: <41110FDB.9080307@mail.usyd.edu.au> <411185C7.2020705@bitglue.com> Message-ID: <1091668087.41118877a493a@www-mail.usyd.edu.au> hi! nope no bsddbmodule either. the pythonce package doesn't seem to have bsddb. What i tried to do was use the normal windows release of python2.3.4 and copy the bsddb module from there along with _bsddb.lib and _bsddb.pyd to the python\lib directory on the pocket pc. earlier i hadn't copied the _bsddb.pyd and _bsddb.lib files and so it couldn't find the _bsddb module. when i copied these the error was Import Error: DLL load failed with error code 193 cheers -- Ajay Brar, CS Honours 2004 Smart Internet Technology Research Group Quoting Phil Frost : > I'm guessing, but _bsddb is probably in Modules, called something like > "bsddbmodule". It's common for a module written in Python to have a > helper module written in C with the same name prefixed by an underscore. > > Ajay Brar wrote: > > > hi! > > > > when i do an import bsddb, it tries do do an import _bsddb > > i looked around Python23\Lib but couldn't find any _bsddp file....or > > am i totally on the wrong track. > > the reason i am asking is, i am trying to port a Python app to a > > pocket pc and python release for pocket pc does not have bsddb module. > > > > thanks > > > > cheers > > -- > http://mail.python.org/mailman/listinfo/python-list > ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From sbabbitt at commspeed.net Fri Aug 6 09:54:46 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Fri, 6 Aug 2004 06:54:46 -0700 Subject: @decorators References: Message-ID: <1091800879.399791@news.commspeed.net> "daishi" wrote in message news:d22692a3.0408052233.3459c3fa at posting.google.com... > For what it's worth: > > As far as I know, the proposed @decorator syntax will be the first > time that two logical lines of python with the same indentation will > not be independent of one another. Previously, when looking at: > I think the @decorator syntax was invented by Microsoft to sabotage Python, Tom From f.geiger at vol.at Mon Aug 16 09:13:07 2004 From: f.geiger at vol.at (F. GEIGER) Date: Mon, 16 Aug 2004 15:13:07 +0200 Subject: [py2exe] py2exe and datetime -> No module named datetime Message-ID: py2exe and datetime -> No module named datetime I've begun to use the stdlib module datetime instead of my home brewn classes. Since then a py2exe app doesn't run anymore: Traceback (most recent call last): File "MainFrame.py", line 26, in ? File "Notebook.pyo", line 125, in ? File "NotebookPage_Activities.pyo", line 7, in ? File "Editors.pyo", line 3, in ? ImportError: No module named datetime Strange enough, py2exe seems to have added datetime: D:\Project\DDG\exTract2>setup.py py2exe -O1 --packages encodings running py2exe *** searching for required modules *** *** parsing results *** creating python loader for extension 'wx._gdi' creating python loader for extension 'win32evtlog' creating python loader for extension 'datetime' creating python loader for extension 'wx._misc' creating python loader for extension 'zlib' creating python loader for extension '_winreg' creating python loader for extension 'wx._windows' creating python loader for extension 'wx._html' creating python loader for extension 'win32api' creating python loader for extension '_sre' creating python loader for extension 'select' creating python loader for extension 'wx._core' creating python loader for extension '_socket' creating python loader for extension 'wx._controls' creating python loader for extension 'unicodedata' creating python loader for extension 'win32file' creating python loader for extension 'winsound' creating python loader for extension '_mysql' creating python loader for extension '_ssl' creating python loader for extension 'wx._calendar' *** finding dlls needed *** *** create binaries *** *** byte compile python files *** byte-compiling D:\Project\DDG\exTract2\build\bdist.win32\winexe\temp\_mysql.py to _mysql.pyo byte-compiling D:\Project\DDG\exTract2\build\bdist.win32\winexe\temp\_socket.py to _socket.pyo byte-compiling D:\Project\DDG\exTract2\build\bdist.win32\winexe\temp\_sre.py to _sre.pyo byte-compiling D:\Project\DDG\exTract2\build\bdist.win32\winexe\temp\_ssl.py to _ssl.pyo byte-compiling D:\Project\DDG\exTract2\build\bdist.win32\winexe\temp\_winreg.py to _winreg.pyo byte-compiling D:\Project\DDG\exTract2\build\bdist.win32\winexe\temp\datetime.py to datetime.pyo byte-compiling D:\Project\DDG\exTract2\build\bdist.win32\winexe\temp\select.py to select.pyo byte-compiling D:\Project\DDG\exTract2\build\bdist.win32\winexe\temp\unicodedata.py to unicodedata.pyo byte-compiling D:\Project\DDG\exTract2\build\bdist.win32\winexe\temp\win32api.py to win32api.pyo byte-compiling D:\Project\DDG\exTract2\build\bdist.win32\winexe\temp\win32evtlog.py to win32evtlog.pyo byte-compiling D:\Project\DDG\exTract2\build\bdist.win32\winexe\temp\win32file.py to win32file.pyo byte-compiling D:\Project\DDG\exTract2\build\bdist.win32\winexe\temp\winsound.py to winsound.pyo byte-compiling D:\Project\DDG\exTract2\build\bdist.win32\winexe\temp\wx._calendar.py to wx\_calendar.pyo byte-compiling D:\Project\DDG\exTract2\build\bdist.win32\winexe\temp\wx._controls.py to wx\_controls.pyo byte-compiling D:\Project\DDG\exTract2\build\bdist.win32\winexe\temp\wx._core.py to wx\_core.pyo byte-compiling D:\Project\DDG\exTract2\build\bdist.win32\winexe\temp\wx._gdi.py to wx\_gdi.pyo byte-compiling D:\Project\DDG\exTract2\build\bdist.win32\winexe\temp\wx._html.py to wx\_html.pyo byte-compiling D:\Project\DDG\exTract2\build\bdist.win32\winexe\temp\wx._misc.py to wx\_misc.pyo byte-compiling D:\Project\DDG\exTract2\build\bdist.win32\winexe\temp\wx._windows.py to wx\_windows.pyo byte-compiling D:\Project\DDG\exTract2\build\bdist.win32\winexe\temp\zlib.py to zlib.pyo removing c:\dokume~1\ddg_fge\lokale~1\temp\tmp1psfqf.py Has anybody else experienced this? Python 2.3.4 on WinXP py2exe 0.5.2 Many thanks in advance and best regards Franz GEIGER From in.aqua.scribis at nl.invalid Mon Aug 30 15:53:28 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Mon, 30 Aug 2004 21:53:28 +0200 Subject: Size of a remote URL In-Reply-To: References: Message-ID: Justin schreef: > Ok so the problem is that my code is not requesting the headers > properly. I get back. Just that. I don't know what the difference is > between the IE request and mine > > \ Date: Mon, 30 Aug 2004 19:36:20 GMT > Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12 > OpenSSL/0.9.6b DAV/ > 1.0.3 PHP/4.3.2 mod_perl/1.26 > Connection: close > Content-Type: text/html; charset=iso-8859-1 > > > My code: > for y in linklisttype: > w = urlopen(y) > z = w.info() > x = z.getheader("Content-Length") > file_sizes.append(x) > Is there a better method for getting headers than urlopen? This works: import httplib conn = httplib.HTTPConnection("www.ecs.soton.ac.uk") conn.request("HEAD", "/~harnad/Temp/Ariadne-RAE.doc") r1 = conn.getresponse() r1.getheader('Content-length') -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From FBatista at uniFON.com.ar Fri Aug 20 10:26:29 2004 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Fri, 20 Aug 2004 11:26:29 -0300 Subject: Newbie to XML in Python Message-ID: [Jens Thiede] #- XML in Python doesn't seem easy or intuitive. All I need to #- do, is to #- interpret a small piece of XML in which I store data for the #- contents of #- an autorun menu. What is the quickest/most effective way to do this? I used xml.parsers.expat my first time, and it was some orders of magnitude easier than I thought (and a lot more easier that parse it by hand). . Facundo From Moiz.Golawala at ge.com Tue Aug 17 14:47:10 2004 From: Moiz.Golawala at ge.com (Golawala, Moiz M (GE Infrastructure)) Date: Tue, 17 Aug 2004 13:47:10 -0500 Subject: read input file a line as a list in python Message-ID: <4BF8D93CF6F73F4890EB6ED8009ECE198AFA27@FTWMLVEM01.e2k.ad.ge.com> You could do this: fileList = [] file = open("fileName.txt","r") #read one line at a time into a list fileList.append(file.readline()) Moiz Golawala GE Infrastructure, Security Software Engineer Enterprise Solutions T 561 994 5972 F 561 994 6572 E moiz.golawala at ge.com www.gesecurity.com 791 Park of Commerce Blvd., Suite 100 Boca Raton, FL, 33487, U.S.A. GE Security, Inc. -----Original Message----- From: python-list-bounces+moiz.golawala=ge.com at python.org [mailto:python-list-bounces+moiz.golawala=ge.com at python.org]On Behalf Of Yong Wang Sent: Tuesday, August 17, 2004 2:41 PM To: python-list at python.org Subject: read input file a line as a list in python Hi, All: I need to read a input file as soucre to process data. Ideally if I can read a line from input file as a list (coloumn separate by white space), reorganize field in a line. Does python has this kind of command ? for example, I read a line has: "IP MAC Date..." as a line from input file, How can I only get MAC ? Thanks, Yong -- http://mail.python.org/mailman/listinfo/python-list From nospam at nowhere.hu Sat Aug 7 15:08:48 2004 From: nospam at nowhere.hu (Miklós) Date: Sat, 7 Aug 2004 21:08:48 +0200 Subject: Going the PL/1 way Message-ID: Ok, seems like we have @decorators. It's a nice tribute to Intercal. But I'd prefer #decorators. We have metaclasses for pleasure brain-melting. We have generators, new-style classes and old-style classes. Lambdas are wonderful. We do need real interfaces, not abused classes. Python still needs to have inlined functions, macros and templates. Operator overloading is not enough, one should be able to introduce new ones freely. There's a heavy demand for terciary comparisons. Why don't we have a 'case' statement and 'do... repeat ()'? We cannot do without general closures, of course. Hm, automatic garbage collection is sometimes fine but explicite memory allocation/deallocation is really unavoidable for efficient programs. Wait, pointers are a must! Static typing should have been introduced a long time ago. You just cannot do without absolute address variables. Yes, I'm thorougly annoyed with creeping featurism. Mikl?s From dd55 at cornell.edu Tue Aug 3 15:46:19 2004 From: dd55 at cornell.edu (Darren Dale) Date: Tue, 03 Aug 2004 15:46:19 -0400 Subject: executing python programs as if they were on OS path (noob) In-Reply-To: References: Message-ID: > > At least two options (assuming you're on Linux... you > didn't specify your OS unfortunately): > I am currently on windows. I didnt think it would matter, sorry I left that out. From ajsiegel at optonline.com Thu Aug 12 15:46:39 2004 From: ajsiegel at optonline.com (Arthur) Date: Thu, 12 Aug 2004 19:46:39 GMT Subject: PEP318 References: <20040812090056.00001e31@titan> <7ttmh0t8c3cogtbhhnp1ohqu8b51pda461@4ax.com> Message-ID: On Thu, 12 Aug 2004 10:35:02 -0700, David Eppstein wrote: >In article <7ttmh0t8c3cogtbhhnp1ohqu8b51pda461 at 4ax.com>, > Arthur wrote: > >> foo=staticmathed(foo). >> >> That is the universal langauge for transformations. And when we try >> to explain to anybody what it is that @decorator means, we go back to >> the pseudo code that is in fact the existing syntax. >> >> I guess I am mystified what it is that is perceived to have been >> gained ... by moving magic outside the function block to the top of a >> function in lieu of expressive code outside the function block at the >> bottom of the function. > >Not having to write the function name three times? If it's just foo, >that would be one thing, but have you seen the PyObjC examples? Does def __f(something): dosomething the_name_I_really_ant_to_call=transform(__f) work? > >Also, it's not in the Zen of Python, but maybe declarative is better >than imperative? Starting now, I guess. ;) Art From therning at gforge.natlab.research.philips.com Tue Aug 10 07:08:10 2004 From: therning at gforge.natlab.research.philips.com (Magnus Therning) Date: Tue, 10 Aug 2004 11:08:10 +0000 (UTC) Subject: Is there something else but Automake? Message-ID: I am currently using Automake to make distributable tar-balls of my application. Is there something else (hopefully better) that I can use? I use the following functionality of Automake: - Modification of sources at build time for things like paths and version numbers. - Building an archive suitable for distributing both to people who are interested in contributing and to people who are just using it. - Installation of the application. /M -- ----------------------------------------------------------------------- Magnus Therning Philips Research Laboratories Eindhoven Phone: +31 40 2745179 (OpenPGP: 0x4FBB2C40) The only way to be truly creative is to never repeat yourself. -- Rob Breszny From lbates at swamisoft.com Tue Aug 24 15:54:57 2004 From: lbates at swamisoft.com (Larry Bates) Date: Tue, 24 Aug 2004 14:54:57 -0500 Subject: Printing date a file References: Message-ID: Take a look at time.strftime() HTH, Larry Bates Syscon, Inc. "Kory Wheatley" wrote in message news:mailman.2296.1093373725.5135.python-list at python.org... > In Python how would you print the date in a file, I > have a logging program written in python and for each > new recorded added to the file, I would like to print > the > date, something like this below: > > 08/24/2004 or 08-24-2004 > > -- > Kory Wheatley > > > > __________________________________ > Do you Yahoo!? > New and Improved Yahoo! Mail - Send 10MB messages! > http://promotions.yahoo.com/new_mail From michele.simionato at gmail.com Thu Aug 12 09:46:44 2004 From: michele.simionato at gmail.com (Michele Simionato) Date: 12 Aug 2004 06:46:44 -0700 Subject: The winner of the Python Decorator Poll is... References: <4edc17eb.0408112052.1bbd85b3@posting.google.com> Message-ID: <4edc17eb.0408120546.7bbc799b@posting.google.com> Andrew Durdin wrote in message news:... > On 11 Aug 2004 21:52:03 -0700, Michele Simionato > wrote: > > > > Indeed. Actually I did not vote since I like the current proposal (maybe > > I would like "|" more than "@") and I dislike all the alternatives, > > especially having decorators inside the def. > > Since you like the current proposal, why *didn't* you vote for it (it > was the first one)? I didn't care to vote, since I thought it will win in any case, having the support from Guido. Michele Simionato From grante at visi.com Mon Aug 9 00:09:18 2004 From: grante at visi.com (Grant Edwards) Date: 09 Aug 2004 04:09:18 GMT Subject: how many bytes in an int References: <9ACRc.1523$bJ2.9739@news1.mts.net> Message-ID: <4116f8ee$0$8076$a1866201@newsreader.visi.com> On 2004-08-09, Reid Nichol wrote: > I was wondering if I could control how many bytes are in an int and > the byte order. In C/C++ I can use int32 but how do I do this in > python? How can I control byte order? I suspect you want to use the "struct" module -- but it's a guess, since you haven't really said what it is you're trying to accomplish. -- Grant Edwards grante Yow! My polyvinyl cowboy at wallet was made in Hong visi.com Kong by Montgomery Clift! From dan.greenblatt at gmail.com Fri Aug 13 15:36:13 2004 From: dan.greenblatt at gmail.com (Dan Greenblatt) Date: 13 Aug 2004 12:36:13 -0700 Subject: 'post'ing Tkinter menus on windows..... Message-ID: <7021e822.0408131136.53a96943@posting.google.com> I am trying to programmatically manipulate the menus in my application, for purposes of a tutorial, showing users where things are in our application's menu interface. My goal is to be able to programmatically say 'show the menu cascade: Menu1 Menu2 Menu3 Action' and these menus will post as they would if they were being scrolled over by the mouse. I've got this working on *nix platforms, but cannot get it to work on windows because the menu.post() function doesnt return until you click somewhere else in the app, while on *nix platforms, that method returns immediately... Does anyone have any suggestions as to what i would have to do to get this to work, as far as messing with grab/focus/etc... ? Thanks Dan From mwh at python.net Wed Aug 25 13:23:51 2004 From: mwh at python.net (Michael Hudson) Date: Wed, 25 Aug 2004 17:23:51 GMT Subject: Capturing exceptions? References: Message-ID: Dfenestr8 writes: > Hi. > > What's the easiest way to capture the traceback from an exception, and > write it to a file? Ideally, I'd like to be able to do something like: > > >try: > > main() > >except: > > write the traceback to a file Read up on the traceback module. Cheers, mwh -- 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 ptmcg at austin.rr._bogus_.com Fri Aug 20 10:12:05 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 20 Aug 2004 14:12:05 GMT Subject: Decorator keyword options References: <7knVc.4599$Jn5.3074@fe1.texas.rr.com> <2CnVc.4606$Jn5.4384@fe1.texas.rr.com> Message-ID: "Paul McGuire" wrote in message news:2CnVc.4606$Jn5.4384 at fe1.texas.rr.com... > (If you do not see the "EditPage" option at the bottom of the page, select > the "Preferences" item on the left-side menu and enter your info. Once this > is done, you should be able to edit pages.) Um, not sure I got that quite right. UserPreferences instructions can be found at the top of the Wiki home page, http://www.python.org/cgi-bin/moinmoin/FrontPage. -- Paul From John.Marshall at ec.gc.ca Sat Aug 21 20:17:28 2004 From: John.Marshall at ec.gc.ca (John Marshall) Date: 22 Aug 2004 00:17:28 +0000 Subject: J2 decorator grammar In-Reply-To: References: Message-ID: <1093133848.15524.16.camel@mango.cmc.ec.gc.ca> On Sun, 2004-08-22 at 00:20, Michael Sparks wrote: > On Fri, 20 Aug 2004, Robert Brewer wrote: > ... > > Did you ever fix the scope issue? > > I've fixed the scoping issue. > > I'll clean up the changes I made to get a minimal patch against 2.4a2, and > then put it somewhere handy. Now that I've got a much clearer idea of how > the python source tree hangs together adding in the short form should be > relatively simple. > > The current patch uses "decorate" as the keyword. Changing that of course > is utterly trivial - it's also something I think *should* be changed. > > The reason for suggesting this change is for one simple reason - python > makes often use of the idiom "decorate-dosomething-undecorate" - eg in > sorting. Using decorate would probably clash heavily with people's code. > > The closest word that strikes me that has a similar meaning to > decorate, using and applying would be "decorating". If anyone has > a closer suggestion to a short single word meaning "decorate using", > it'd be great. > One might consider "deco" in place of "decorate" giving a deco-def block pair if "decorate" is not desirable but the something like "decorate" is still appropriate. This would not be entirely out of place given that def (short for define) already exists. John From tjreedy at udel.edu Sat Aug 14 01:20:42 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Aug 2004 01:20:42 -0400 Subject: Why I love python. References: Message-ID: "Michael Scarlett" wrote in message > someone once said python is runable pseudocode. or 'executable pseudocode' (which I originally misspelled :-( ) http://groups.google.com/groups?selm=5if2a8%249r2%241%40news.udel.edu Terry J. Reedy From roy at panix.com Thu Aug 19 21:54:07 2004 From: roy at panix.com (Roy Smith) Date: Thu, 19 Aug 2004 21:54:07 -0400 Subject: PEP 318: Can't we all just get along? References: Message-ID: In article , "Delaney, Timothy C (Timothy)" wrote: > Neil Zanella wrote: > > > Well, allow me to contribute my thoughts on staticmethod and > > classmethod: > > I am barely starting out with Python and my class objects are already > > loaded with so many > > > > foo = staticmethod(foo) > > These two facts could be somewhat related ... ;) > > Tim Delaney I never quite understood the point of static methods inside classes. When would you ever need to do that, as opposed to just a function in a module? In Java's "everything is part of a class" philosophy, it makes sense, but in Python? From ken.beesley at xrce.xerox.com Sat Aug 21 15:14:12 2004 From: ken.beesley at xrce.xerox.com (Ken Beesley) Date: Sat, 21 Aug 2004 21:14:12 +0200 Subject: Question about importing modules In-Reply-To: References: Message-ID: <41279F04.30309@xrce.xerox.com> pythos at bag.python.org wrote: >Newbie at python (but not programming) here... > >I have a program that has "import os" at the top, and then later a call to >utime() is made. The python interpreter says "name 'utime' is not defined". >But if I change "utime(...)" to "os.utime(...)" then it works fine. Perhaps I >am expecting the "import os" statement to work the same way as "import >.*" does in Java. So is it the case that if I write "import os" >in python, then I still need to write "os.utime(...)"? Or is there something >else wrong? Thanks. > > > What you want is from os import utime which will make 'utime' a name in the local namespace. Ken From tmohr at s.netic.de Sun Aug 1 12:39:19 2004 From: tmohr at s.netic.de (Torsten Mohr) Date: Sun, 01 Aug 2004 18:39:19 +0200 Subject: Tkinter, Simple Table Message-ID: Hi everybody, i'd like to have a small python script that creates a table (like in Excel) and where i can enter multiline text in the tables cells. Can anybody give me a hint where to look? Does TList do what i want? THe description looked good, but i didn't find an example for it. Regards, Torsten. From maxm at mxm.dk Mon Aug 30 02:57:37 2004 From: maxm at mxm.dk (Max M) Date: Mon, 30 Aug 2004 08:57:37 +0200 Subject: play a midi file from the interpreter? In-Reply-To: <95tYc.261224$J06.123492@pd7tw2no> References: <95tYc.261224$J06.123492@pd7tw2no> Message-ID: <4132CFE1.20004@mxm.dk> Elaine Jackson wrote: > (How) can you make it so that a function invoked in the python interpreter can > run another program? (Like the webbrowser module does, only not with a web > browser.) If it matters the OS is Windows98 and the specific aim in mind is to > have a function that saves some data as a midi file and then causes the said > midi file to play. Use the popen() call in the os module. regards Max M From fakeaddress at nowhere.org Mon Aug 9 02:33:44 2004 From: fakeaddress at nowhere.org (Bryan Olson) Date: Mon, 09 Aug 2004 06:33:44 GMT Subject: Encryption between Python & PHP In-Reply-To: References: Message-ID: Geoff Caplan wrote: > Looks like I should persist and track down the > problem. Perhaps something to do with the keys? When I try to > decrypt I am getting binary garbage out instead of an ascii string. > > Any pointers about where to start looking would be welcome! First check the obvious: do you have exactly the same key/IV/ciphertext. If that's not it, the most popular bug in Blowfish implementations is an endian dependency. It causes implementations to be self-consistent, but ciphertext is not portable between big-endian and little-endian machines. Bruce Schneier's original implementation had the bug, and many others followed. -- --Bryan From jack at performancedrivers.com Wed Aug 18 16:06:34 2004 From: jack at performancedrivers.com (Jack Diederich) Date: Wed, 18 Aug 2004 16:06:34 -0400 Subject: Embedding Python in Python In-Reply-To: References: <7xu0v0l2be.fsf@ruckus.brouhaha.com> <7x3c2kkzn8.fsf@ruckus.brouhaha.com> Message-ID: <20040818200634.GY23725@performancedrivers.com> On Wed, Aug 18, 2004 at 07:44:47PM +0000, JCM wrote: > Paul Rubin wrote: > > JCM writes: > >> If you're concerned about security, another possibility is to parse > >> the user's code and look for anything potentially dangerous. You'll > >> need to be aggressive, but I believe it's possible. For example, > >> disallow exec statements, the identifier "eval", any identifier of > >> __this__ form, import statements, etc. This is overly restrictive, > >> but it will provide security. > > > By the time you're done with all that, you may as well design a new > > restricted language and interpret just that. > > > Hint: > > e = vars()['__builtins__'].eval > > print e('2+2') > > > Even Java keeps getting new holes found, and Python is not anywhere > > near Java when it comes to this kind of thing. > > I don't think it's as difficult as you think. Your snippet of code > would be rejected by the rules I suggested. You'd also want to > prohibit other builtins like compile, execfile, input, reload, vars, > etc. > foo = "ev" + "al" e = vars()['__builtins__'].__dict__[foo] print e('2+2') This is a job for the operating system and not python. Google groups for rexec and Bastion if you want to read ten lenghty discussions of why this is the OS's job. -Jack From evenprimes at gmail.com Mon Aug 16 09:20:24 2004 From: evenprimes at gmail.com (Chris Cioffi) Date: Mon, 16 Aug 2004 09:20:24 -0400 Subject: Why does this (very simple piece of) code does not work? In-Reply-To: References: Message-ID: Just a guess here, but is ':' a valid filename character on your OS? Most OSes seem to have it reserved for system use. Try using a hyphen. Chris On Mon, 16 Aug 2004 15:03:51 +0200, jblazi wrote: > import os > > L = os.listdir('.') > > for x in L: > print '!'+x+'!'+x[0] > if x != 'rename.py': > y = 'Kapustin (Hamelin): '+x > os.rename(x,y) > > I get > > Traceback (most recent call last): > File "", line 9, in ? > OSError: [Errno 22] Invalid argument > > TIA, > > jb > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Still searching for an even prime > 2! From duncan.booth at invalid.invalid Wed Aug 11 06:56:47 2004 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 11 Aug 2004 10:56:47 GMT Subject: class in IronPython? References: <316f1dc0.0408110240.4c83fb42@posting.google.com> Message-ID: mike1 at tumladen.net (Mike Greaves) wrote in news:316f1dc0.0408110240.4c83fb42 at posting.google.com: > In Jim H.'s new IronPython 0.6: > > mono bin/IronPythonConsole.exe >>>> class myClass: > ... pass > ... > System.NullReferenceException: Object reference not set to an instance > of an object > > ... > > Am I missing something basic? I think you will find that classes don't (yet) work in interactive mode. Try putting the class in a .py file and using that. From pinard at iro.umontreal.ca Sun Aug 1 18:36:17 2004 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Sun, 1 Aug 2004 18:36:17 -0400 Subject: Module for converting XML to Python object(s)? In-Reply-To: References: Message-ID: <20040801223617.GA11209@titan.progiciels-bpi.ca> [Robert Oschler] > Has anybody seen a Python module that will take an XML document (not a > colossal one), and convert it to a Python nested class object? You might want to check this announcement: From: "Fredrik Lundh" Date: Fri, 18 Jun 2004 17:07:43 +0200 Subject: ANN: ElementTree 1.2 final (june 18, 2004) To: python-announce-list at python.org Newsgroups: comp.lang.python.announce The Element type is a simple but flexible container object, designed to store hierarchical data structures, such as simplified XML infosets, in memory. The ElementTree package provides a Python implementation of this type, plus code to serialize element trees to and from XML files. The 1.2 release adds limited support for XPath and XInclude, and also fixes a number of serialization bugs, mostly related to extensive use of namespaces and unicode in tags and attribute names. For a complete list of changes, see the CHANGES document in the source kit. You can get the ElementTree toolkit from: http://effbot.org/downloads Documentation, articles, and some code samples (including an XML-RPC unmarshaller in 16 lines) are available from: http://effbot.org/zone/element.htm enjoy /F -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From pythos Mon Aug 23 21:05:15 2004 From: pythos (pythos) Date: Mon, 23 Aug 2004 21:05:15 -0400 Subject: Help with trapping an exception Message-ID: I have a piece of code like this: try: some code except: print >> sys.stderr, "error: ", sys.exc_info() When an exception is thrown from the code, what I see on the console is this: error: (, , ) I had a lot of trouble figuring out what was causing the NameError. I finally figured it out by removing the "try" and "except" statements so that my code didn't catch any exceptions. When I did that, I saw the following on my console: Traceback (most recent call last): File "c:\Documents and Settings\xxxxx\rot.PspScript", line 79, in Do os.path.walk(baseDirectory, ProcessDirectory, Environment) File "c:\Program Files\xxxxxx\Python Libraries\lib\ntpath.py", line 318, in walk func(arg, top, names) File "c:\Documents and Settings\xxxxx\rot.PspScript", line 36, in ProcessDirectory App.Do(Environment, 'FileOpen', { NameError: global name 'Environment' is not defined Now that was much more helpful. Once I knew that 'Environment' was not defined, I easily figured out the problem. But I need to use "try" and "except" to catch the exception, otherwise my program will end abruptly without finishing. So how can I see the "NameError: global name 'Environment' is not defined" message in the "except" section of my code? A call to sys.exc_info() doesn't show it. Is there another function I can use? Thanks. From indigo at bitglue.com Wed Aug 18 18:56:08 2004 From: indigo at bitglue.com (Phil Frost) Date: Wed, 18 Aug 2004 18:56:08 -0400 Subject: introspection? In-Reply-To: References: Message-ID: <20040818225608.GB14005@unununium.org> >>> class C: ... pass >>> C().__class__.__name__ 'C' That is, __class__ of an instance gives you the class object of which it's an instance, and __name__ gives you the identifier that represents the class. Classes also have a __module__ attribute. On Wed, Aug 18, 2004 at 02:43:46PM -0700, Jim Benson wrote: > > newbie question here: > > How does one get the class and method name from within > a method? i.e here i have obviously hardcoded the class > and method name: > > class JJTest: > > def methodA(self): > > print 'ERROR: in JJTest.methodA' > > >>> from jjtest import JJTest > >>> jj = JJTest() > >>> jj.methodA() > ERROR: in JJTest.methodA > >>> > > The Java way of doing this would be something like: > > System.out.println("ERROR in: " + this.getClass().getName()); > > I suspect that there are attributes that one can use to do > something similar in Python. > > If any of you Python experts would let me know how to do this in > Python, i would appreciate it. > > Thanks, > > Jim From steven.bethard at gmail.com Tue Aug 24 18:55:09 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Tue, 24 Aug 2004 22:55:09 +0000 (UTC) Subject: Are decorators really that different from metaclasses... References: Message-ID: Paul Morrow yahoo.com> writes: > > ...that they warrant an entirely new syntax? [snip] > So why don't they share a similar syntax? > > class Foo: > """ This is the docstring for class Foo. """ > __metaclass__ = M > # body of class goes here > > > def baz(): > """ This is the docstring for function baz. """ > __features__ = synchronized, memoized > # body of function goes here. As I'm sure someone has already mentioned, this has been brought up before. I'd especially look at: http://mail.python.org/pipermail/python-dev/2004-August/048176.html That being said, I think the main objection to this syntax is the same objection to any inside-def syntax: The code inside a funcdef block (with the exception of docstrings, which Guido has repeatedly said he regrets putting there) is executed as part of the /execution/ of the function, not the /definition/. Note a classdef is not really the same in this respect. The code inside a classdef block is executed as part of the /definition/ of the class. Compare what happens when you call Foo() with what happens when you call baz(). With the call to Foo(), you don't execute the code in the classdef block; you execute the code in __new__ and/or __init__. With the call to baz(), you /do/ execute the code in the funcdef block. So the basic answer is that decorators are different from metaclasses because the code inside the funcdef block is executed when the function is /called/, while the code inside the classdef is executed when the class is /declared/. It may be a subtle difference, but I believe this is what Guido disliked so much about the inside-def syntaxes... Steve From justin__devine at hotmail.com Mon Aug 30 15:40:53 2004 From: justin__devine at hotmail.com (Justin) Date: 30 Aug 2004 12:40:53 -0700 Subject: Size of a remote URL In-Reply-To: Message-ID: Ok so the problem is that my code is not requesting the headers properly. I get back. Just that. I don't know what the difference is between the IE request and mine \ Date: Mon, 30 Aug 2004 19:36:20 GMT Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12 OpenSSL/0.9.6b DAV/ 1.0.3 PHP/4.3.2 mod_perl/1.26 Connection: close Content-Type: text/html; charset=iso-8859-1 My code: for y in linklisttype: w = urlopen(y) z = w.info() x = z.getheader("Content-Length") file_sizes.append(x) Is there a better method for getting headers than urlopen? From sbabbitt at commspeed.net Thu Aug 26 21:33:32 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Thu, 26 Aug 2004 18:33:32 -0700 Subject: Newbie question on dictionary!!! References: <494182a9.0408261150.a4c767f@posting.google.com> Message-ID: <1093571530.107321@news.commspeed.net> "Balaji" wrote in message news:494182a9.0408261150.a4c767f at posting.google.com... > Hello everybody... > > I want to ask a simple question. > > Suppose I have an list say g=['a','b','c','d'] > > and I have an dictionary say k={'b':20,'a':10} > > Now I want to sort this dictionary on the basis of the list and if it > doesnt find any of the element in the list then I wud like to replace > it with zero.. > > so I would like to modify k into {'a':10,'b':20,'c':0,'d':0} > > I have tried all the built in associated with dict and lists but was > not able to come up with an solution... > > Can anyone help... Dictionarys are not sortable but you can easaly acess the values in an sorted order, dict = {'a':123,'c':456,'b':789} l = dict.keys() l.sort() for i in l: print dict[i] Tom From sbabbitt at commspeed.net Sun Aug 29 09:38:13 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Sun, 29 Aug 2004 06:38:13 -0700 Subject: Dynamic languages References: <278de0e.0408271349.26762174@posting.google.com> <1093650026.763899@news.commspeed.net> <98862c6.0408280531.6064d510@posting.google.com> Message-ID: <1093787221.707030@news.commspeed.net> I was actually trying to make a point about semantics in that the terms 'dynamic' and 'static' are too generic. In computer science it is the custom (but not always) to name a process as accurately as possible and use acronyms. This way a Dynamically Typed Language becomes DTL and a Dynamically Run Language becomes DRL, insuring that Python remains superior in more way than one. Tom From martin.clausen at get2net.dk Thu Aug 26 17:00:03 2004 From: martin.clausen at get2net.dk (Martin) Date: Thu, 26 Aug 2004 21:00:03 +0000 (UTC) Subject: Web Application - User Management - RBAC References: <412dfc53@news.highway1.com.au> Message-ID: > > Hi Martin > > IYou probably know this already but the obvious response is to use Zope > > Tim Yeah, but I am doing this also as an exercise. I want to understand how to put RBAC together. Do I really have to start from scratch ? I am not pretending to know much about web applications, but I would think there would be a lot of generic stuff involved ? Martin From jacek.generowicz at cern.ch Mon Aug 30 03:20:14 2004 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 30 Aug 2004 09:20:14 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1ry8k0d2az.fsf@rovereto.ifi.uio.no> Message-ID: Kjetil Torgrim Homme writes: > "pass" is a no-op, Can't aruge with that. > and should only be used when a suite is required, but the suite > should do nothing. I'll have to take your word for it, that this is THE WAY. Oh, wait a minute ... I don't take people's word for it, and I don't subscribe to programming dogmas, partuclarly when they get in the way of getting something useful done. Never mind, then. > you're proposing a convention saying > > ''if "pass" appears in a suite which also contains other > expressions, the "pass" signals the end of the suite'' You had a problem with indent-region in Emacs not doing the right thing. Your proposed solution is to try to modify the language, in a way which is guaranteed not to be accepted. I proposed a solution which (while not one which overwhelms me with its beauty) works today ... to solve the problem _you_ had. I'm not presupposing any convention, I'm observing the current state of the world and finding a working solution in it. You are tilting at windmills. > that's a hack, And like so many hacks, IT WORKS. > and IMHO not worthy of a Python program. Whereas braces are worthy of a Python program. From anthonybaxter at gmail.com Sun Aug 8 04:16:46 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sun, 8 Aug 2004 18:16:46 +1000 Subject: decorators vs GIL In-Reply-To: <0bidnfbR2_PZOIjcRVn-pA@giganews.com> References: <8YudnZoJ4NdLEYjcRVn-jA@speakeasy.net> <0bidnfbR2_PZOIjcRVn-pA@giganews.com> Message-ID: On Sun, 08 Aug 2004 00:00:25 -0400, Istvan Albert wrote: > Just because someone sits down and codes it does not mean it > should be added to the language. Features are forever, you > cannot just can't eliminate them in the next version. The discussion on decorators has been going on for over 2 years on python-dev. There is a broad concensus that they're a useful feature, and are not _just_ being added for PyObjC. As far as "fixing" the GIL - well, no-one on Python-Dev has obviously found it to be a problem for them. I certainly can't recall a time in the last 5 years where the GIL has been a problem in any application I've written (including a number of heavily threaded applications). Coding threaded applications in Python does require _knowledge_ of the GIL, true, but there's nearly always ways to get around it. As a couple of people have said already - if it's truly a problem for you, you're able to do something about it. Either look into how it could be fixed, or hell, pay someone else to work on it for you. No-one is going to work on something merely because you assert that it is important. Heck, put together a decent case for _why_ it is a problem. Greg's free-threading patches for Python 1.4 were there for years. The interest in them was so low that no-one was even interested in keeping them up-to-date with current Python (which would have been a much smaller task than writing them from scratch). One final point is that with the various new implementations of Python (Jython, IronPython, Python-on-Parrot, Python-on-smalltalk-VM, Python-on-Scheme-VM) it's quite possible that one or more of these new implementations won't have the GIL. You might look into one of these implementations, and if it looks good to you, contribute! This is not saying "fix it yourself". This is saying "the people who work on Python, in their own spare time (almost no-one is paid to hack on Python) don't consider that the GIL is an issue for them". You can't just say "fix it!" and expect volunteers to do the work for you. Anthony From iketo2 at netscape.net Mon Aug 30 11:39:34 2004 From: iketo2 at netscape.net (Isaac To) Date: 30 Aug 2004 23:39:34 +0800 Subject: allowing braces around suites References: Message-ID: <87d618ocsp.fsf@sinken.local.csis.hku.hk> >>>>> "Jeremy" == Jeremy Bowers writes: Jeremy> (In Perl, "if", "for", and friends all *require* braces Jeremy> when used conventionally. When used as a suffix ("print $x Jeremy> if $iShould;"), it doesn't, but I don't find that Jeremy> offensive.... partially because I only rarely use it.) Hm... then you lose one of the features that I miss most when coding Python. I actually use them much more often than a full if-else when coding Perl. In Perl, because you have your freedom to put things in different ordering, you can easily document your program by simply reversing the way you write. By writing "print $x if $x_is_not_bad;" instead of "if ($x_is_not_bad) { print $x; }" (or, "$x_is_not_bad and print $x;" or "!$x_is_not_bad or print $x"), you document that (1) you expect $x_is_not_bad most of the time, and (2) your main concern of that piece of code is to print out $x rather than to check the condition. In Python I got no such freedom. Anyways, Python is not designed to be that implicit. Regards, Isaac. From r.kleger at chello.nl Fri Aug 20 13:48:31 2004 From: r.kleger at chello.nl (Rafal Kleger-Rudomin) Date: Fri, 20 Aug 2004 17:48:31 GMT Subject: How to clean python interpreter's environment? Message-ID: Hello, I'm looking for a command to reset interpreter's environment i.e. unload all modules, delete variables etc. Regards, Rafal From fumanchu at amor.org Mon Aug 23 11:02:07 2004 From: fumanchu at amor.org (Robert Brewer) Date: Mon, 23 Aug 2004 08:02:07 -0700 Subject: J2 paper 0.2.1 Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E3C@exchange.hqamor.amorhq.net> Paul McGuire wrote: > Beautiful work - where do I sign? (as a supporter, of course) Not so much "where" as "when". :) If no other subprocess in this thing goes right, I'd like this one to. To everyone, If you support the proposal: 1. Help refine it if you can. If you have no issues with it, help me discuss issues other people have with it. 2. Answer the "call for signatories" when the final draft is ready. I don't want to add any names prior to that, since the content may change. I really don't want to chase down everyone each time and re-secure their support. If you don't support the proposal: 1. Let me know. If there is a way to address your concerns to mutual satisfaction, I will hunt it down, shoot it, stuff it, and hang it over the mantel. Oh, and put it in the document. 2. Answer the "call for signatories" when the final draft is ready. If you still cannot agree to the arguments, add your name to those against the proposal. Guido deserves an accurate representation of the opinion of the whole community. If you consider yourself a "lurker", one who cannot contribute to the technical discussion, I still want you as a signatory, for or against. If you favor C1 over both J2 and A1, I still want you as a signatory, either for or against. Robert Brewer MIS Amor Ministries fumanchu at amor.org From ayinger at alumni.cmu.edu Sun Aug 22 16:19:38 2004 From: ayinger at alumni.cmu.edu (Andrew Yinger) Date: 22 Aug 2004 13:19:38 -0700 Subject: printing a wxIEHtmlWin window Message-ID: hi, python version 2.3, wxpython version 2.4 i know i can right click a wxIEHtmlWin window and select print, but is there a way to programatically print the contents of a wxIEHtmlWin window? thanks, andrew From jim_8421 at hotmail.com Wed Aug 4 16:45:47 2004 From: jim_8421 at hotmail.com (Jim) Date: 4 Aug 2004 13:45:47 -0700 Subject: logging / FileHandler Message-ID: Hi, with the logging module, I am using the FileHandler formatter. Is there a setting to stop the logger from putting the same message more than once? So it would say: Message whatever Repeated X times Thanks From http Thu Aug 26 16:53:20 2004 From: http (Paul Rubin) Date: 26 Aug 2004 13:53:20 -0700 Subject: Call for signatories for J2 References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> <7xhdqp967k.fsf@ruckus.brouhaha.com> <412e3ba4$0$92817$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <7xk6vloc3j.fsf@ruckus.brouhaha.com> Michael Sparks writes: > It's very possible that we might end up with @pie syntax or nothing. (I > suspect the latter is very unlikely, but it's still possible) I don't have a strong opinion of whether J2 is better than @pie or vice versa. I dislike both. > My personal initial reaction to the syntax was "ugh", followed by listening > to arguments and deciding that I could live with @pie happily (I do like > perl after all so I've not got a huge aversion to punctuation). My problem with @pie is that it doesn't get enough mileage out of the @ character. I'd almost rather use @ as a keyword introducer, like # in the prepreprocessor. And of course, @pie should be useable on classes rather than just functions. > * People will revert to using metaclass approaches, which having > tried them I think people will find worse than something more > explicit & in your face. (Almost any syntax on the wiki IMO is > better than a metaclass approach) I think decorators can do things that metaclasses can't. > been used in earnest then IMHO option A1 should be chosen, via a > __future__ import. Whilst I'm obviously in favour of J2, option A1 > strikes me as by _far_ the simplest to write or provide tools to > programmatically munge people's code if syntax does change. (Much > like the tools to remove unnecessary __future__ statements) I really wouldn't worry too much about the effect on current syntax tools. There aren't that many of them, and they do get updated. Changing Python's syntax will have longer-lasting consequences than having to update some tools. From tblack at biamp.com Mon Aug 2 15:29:12 2004 From: tblack at biamp.com (Tim Black) Date: 2 Aug 2004 12:29:12 -0700 Subject: socket.sendall(), non-blocking sockets, and multi-threaded socket sending Message-ID: My application requires sending a large piece (~2MB) of data to several devices on a network via TCP sockets. I have experimented with different methods for doing this and this has raised some questions about the implementation of Python sockets. (both methods use blocking sockets) Method 1: Calls socket.sendall(data) for each device in sequence, all in a single thread. Method 2: Each socket has its own thread that calls socket.send(datachunk) iteratively until all data is sent. So Method 1 sends all data to device1, then send all data to device2, etc... until all data is sent to all devices. Method 2 sends chunks of data to all devices in parallel. What I am seeing is that Method 1 is faster than Method 2. Given that the bottleneck is the actual sending of data on the sockets and not some latency in processing the message at the other end, this result makes sense to me. Method 2 involves sending the data in smaller chunks, whereas with Method 1 the chunksize is selected by the TCP/IP stack implementation, which is probably more efficient. Also, Method 2 entails context switching between the send threads. It turns out that using Method 1, all sendall() calls return immediately. I am assuming at this point that my app is in the hands of the TCP/IP stack implementation on my machine (win32-XP). Can anyone explain what happens inside sendall() for Win32? Also, I would like to get advice and opinions on what is the most efficient way to broadcast data to several devices on a network. Thanks, T From noone at here.com Wed Aug 18 23:20:42 2004 From: noone at here.com (M. Clift) Date: Thu, 19 Aug 2004 04:20:42 +0100 Subject: get last two in a length of unknown length? References: Message-ID: Thankyou all for your help. Exactly what I needed : ) From ialbert at mailblocks.com Tue Aug 24 10:51:00 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Tue, 24 Aug 2004 10:51:00 -0400 Subject: python-dev Summary for 2004-08-01 through 2004-08-15 In-Reply-To: References: Message-ID: Anthony Baxter wrote: > Er. Did you _read_ the rest of the section you quoted? > > """In the end, though, this went in with a warning that the speed > performance is not portable. It is not to be used in the stdlib ever."""" I read the whole thread. It is very clear from it that the only reason this feature made it in (in whatever form) is that it has already been committed without Guido's permission and removing it would have been quite a bit insulting. If it was up to Guido would not have made it. On my part calling it 'an idea that was shot down' is an exaggeration, but then what does: > It is not to be used in the stdlib ever. mean in this context? Istvan. From wilberforce at gmail.com Sun Aug 29 11:49:36 2004 From: wilberforce at gmail.com (xtian) Date: 29 Aug 2004 08:49:36 -0700 Subject: os.walk: Get entire path Message-ID: Florian Lindner wrote: > Hello, > when I'm walking through a file system hierarchy using os.walk, how can I > get the full path of a file or dir? normpath and abspath don't work. > Thx, > Florian os.walk() is a generator that yields (current directory, subdirectories, files), and subdirectories and files are lists of relative names. (See http://docs.python.org/lib/os-file-dir.html#l2h-1474) To get the full path of a file or subdirectory while doing a walk, you can join the name to the current directory (using os.path.join()), and then use os.path.abspath() on the lot to get the full path (if current directory is already absolute you don't need that last step). >>> for d, subs, files in os.walk("."): print os.path.abspath(os.path.join(d, subs[0])) break C:\Python23\BACKUP On a general note, if you're not sure what something does or the exact format something is returned in, try playing around with it at the interactive prompt. If you do: >>> for item in os.walk("."): print item break ...it's pretty easy to see what's going on. Cheers, xtian From chrisks at NOSPAM.udel.edu Sat Aug 28 22:04:32 2004 From: chrisks at NOSPAM.udel.edu (Chris S.) Date: Sun, 29 Aug 2004 02:04:32 GMT Subject: Dynamic languages In-Reply-To: <1093703465.236222@news.commspeed.net> References: <278de0e.0408271349.26762174@posting.google.com> <1093650026.763899@news.commspeed.net> <98862c6.0408280531.6064d510@posting.google.com> <1093703465.236222@news.commspeed.net> Message-ID: Tom B. wrote: > "Marcel van den Dungen" wrote in message > news:98862c6.0408280531.6064d510 at posting.google.com... > >>"Tom B." wrote in message > > news:<1093650026.763899 at news.commspeed.net>... > >>>I doubt that this is what they mean but a dynamic language is a language >>>that is still evolving (Python) as opposed to a dead language (COBOL). >>> >>>They probably are referring to programs that can add and remove > > components > >>>during runtime. >> >>Dynamic refers to the typing of variables. In Python variables get a >>type dynamically when assigned a value. >>See also: http://www.artima.com/weblogs/viewpost.jsp?thread=4639 >>and several blog posting of Bruce Eckel on this subject: >>http://www.mindview.net/WebLog/ >> >>Marcel. > > > Those languages are called dynamically typed languages, this implies that > there is a statically typed language, which there is. > All languages are dynamic, this slang is bad computer science. There is no > such thing as a static computer language. I respectively disagree. The difference between static and dynamic is an important one. There are things I can do in Python that are synatically impossible in C or C++ simply due to their absence of a native eval(). From greg at cosc.canterbury.ac.nz Tue Aug 24 00:57:38 2004 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Tue, 24 Aug 2004 16:57:38 +1200 Subject: Overriding logical operators? In-Reply-To: References: Message-ID: <2p0064Ff28qtU1@uni-berlin.de> Robert Brewer wrote: > This has come up before--in particular, I think Greg Ewing was taking a > stab at it last. I have some ideas on how it could be done, although I haven't gotten around to trying them out yet. Essentially, there would be two special methods corresponding to each of these, e.g. '__and1__' and '__and2__' etc. The first operand would be evaluated and passed to __and1__. If that can determine the result, it returns it, and evaluation of the other operand is skipped. If not, it returns a special value (or maybe raises a special exception) which means "other operand needed". The second operand is evaluated, and both operands are passed to __and2__, which returns the final result. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From pete at shinners.org Tue Aug 10 01:01:38 2004 From: pete at shinners.org (Pete Shinners) Date: Mon, 09 Aug 2004 22:01:38 -0700 Subject: Mechwarrior Python Game In-Reply-To: References: Message-ID: Jared wrote: > Has anybody played the Mechwarrior Miniatures game? I'm trying to > represent the game in python. First thing I need to do is make a > playing field. Mechs will move on the playing field based on inches > to scale in any direction. Any ideas? You'll probably want to get comfortable working with a game on a hex grid. You can usually treat it as a skewed 2D grid. There are plenty of articles on developing hex games. There are a few examples on the Pygame site, but most are either incomplete or very deep. I haven't seen any clean examples out there that show you how it's all done with Python code. But I know there's a few people working on that sort of thing. From squirrel at WPI.EDU Fri Aug 6 15:38:35 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Fri, 6 Aug 2004 15:38:35 -0400 Subject: Prothon is switching to the .NET platform In-Reply-To: <10h7lb21dhbuc12@news.supernews.com> References: <000401c47b59$32539220$0d01a8c0@MarkVaio> <10h7lb21dhbuc12@news.supernews.com> Message-ID: On Fri, 6 Aug 2004, John Roth wrote: > I think it's possible to do prototypes within Python by > overriding the __getattribute__() magic method. It still > wouldn't be very pretty, but it should be able to do > everything except override the magic methods (those > seem to have to be in the class object for new style > classes). Hm, I'd never thought of this before; something along the lines of: class derive(object): def __init__(self,parent): self.parent = parent def __getattribute__(self,attr): return getattr(self.parent,attr) myderivedobject = derive(myprototypeobject) would do the trick quite nicely I guess. I have one application that could benefit quite nicely from prototypes; I'll see if I can't work this in. Thanks for the enlightenment! From unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom Sat Aug 7 15:28:02 2004 From: unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom (Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.) Date: Sat, 7 Aug 2004 21:28:02 +0200 Subject: Prothon is switching to the .NET platform References: <000401c47b59$32539220$0d01a8c0@MarkVaio> <30260531.0408070142.7e87a655@posting.google.com> Message-ID: Hi ! Sure ; but IronPython is only a pre-alpha idea. With IronPython, try "import string"... I hope for much IronPython (for to work) ; I would not like to be disappointed. But I would like to play with Prothon # (as with F #, RubyDotNet, processing #, etc.) Dreams ? @-salutations -- Michel Claveau m?l : http://cerbermail.com/?6J1TthIa8B sites : http://mclaveau.com http://bergoiata.org http://ponx.org From fuzzyman at gmail.com Thu Aug 12 05:08:15 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 12 Aug 2004 02:08:15 -0700 Subject: ClientCookie References: <6f402501.0408110018.1e4e5ca8@posting.google.com> <87llglqp0l.fsf@pobox.com> Message-ID: <6f402501.0408120108.5a8f03ae@posting.google.com> jjl at pobox.com (John J. Lee) wrote in message news:<87llglqp0l.fsf at pobox.com>... > fuzzyman at gmail.com (Michael Foord) writes: > > > Has anyone used ClientCookie to store cookies ? > > I'm going to play around with 'pickling cookies' - but I wondered if > > anyone had any experience of this. > [...] > > There shouldn't be any problem with that. You can pickle the > CookieJar itself, or the cookies inside it ([c for c in cookiejar] -- > and use .set_cookie() to get them back into a new CookieJar). > At the moment I can't get at the cookies at *all*. Can you see what I'm doing wrong. Here's my code (simplified) : import ClientCookie openfun = ClientCookie.urlopen cj = ClientCookie.CookieJar() req = ClientCookie.Request(theurl, txdata, txheaders) u = openfun(req) info = u.info() print '
'        # This is ina CGI after all :-)
print info           # This prints the headers from the server
print
print 'Cookies :'
print cj                
for c in cj:
    print c
print '
' Now if I set theurl to 'http://www.google.co.uk' I get the following response : (txdata=None, txheaders={ 'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)' })
Cache-Control: private
Content-Type: text/html
Set-Cookie: PREF=ID=0bac71b03c6b1aa8:LD=en:TM=1092300998:LM=1092300998:S=YasA-Kgirv2NPnd9;
expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.google.co.uk
Server: GWS/2.1
Content-Length: 2901
Date: Thu, 12 Aug 2004 08:56:38 GMT
X-Cache: MISS from dav-serv.tbsmerchants.co.uk
Proxy-Connection: close


Cookies :

And I'm getting this consistently - I can see a cookie in the header, but it never appears in the CookieJar - so loading and saving the CookieJar is of no avail. I'm sure I'm making an obvious mistake - but short of subclassing the CookieProcessor and doing it all manually (which seems overkill) - I'm a bit stumped. > May I suggest instead using cookielib, from Python CVS? (note that > POSTs with urllib2 are broken in 2.4a2, so don't use that) > > cookielib is a new module in 2.4, and is a cleaned-up version of the > cookie-handling parts of ClientCookie. > > I'll have a look in a bit... once I can get any kind of response !! Thanks for your help. Fuzzy http://www.voidspace.org.uk/atlantibots/pythonutils.html > John From R.Brodie at rl.ac.uk Mon Aug 16 09:16:21 2004 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Mon, 16 Aug 2004 14:16:21 +0100 Subject: Why does this (very simple piece of) code does not work? References: Message-ID: "jblazi" wrote in message news:pan.2004.08.16.13.03.51.421000 at hotmail.com... > y = 'Kapustin (Hamelin): '+x > os.rename(x,y) > OSError: [Errno 22] Invalid argument You didn't say what platform you are on but if it's Windows, then colons aren't allowed in filenames. From pm_mon at yahoo.com Wed Aug 11 14:14:13 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Wed, 11 Aug 2004 14:14:13 -0400 Subject: Rather than decorators, how about sections? In-Reply-To: References: Message-ID: Paul McGuire wrote: > "Paul Morrow" wrote in message > news:mailman.1509.1092238688.5135.python-list at python.org... > >>I like many am not wild about the operator. I also don't think >>that the decorator syntax should be so directly attached to the method, >>since what we're trying to do is to say something about the >>*relationship between* a method and a class (e.g. "method m is a >>staticmethod of class C"). >> >>So if we are going to extend the Python grammar to support this sort of >>thing (which I believe is a good idea), my preference would be to >>introduce named sections within a class definition, such as... >> >> class Foo(object): >> staticmethods: >> def baz(a,b): >> print "I'm a static method." >> def bez(c,d): >> print "I'm a static method too." >> >> classmethods: >> def biz(klass): >> print "I'm a class method." >> >> >> def __init__(self): >> print "We all know what I am." >> > > This only addresses the "decoration" for declaring static and class methods. > The decorator mechanism is intended to include much more than this simple > class declaration feature. See > http://www.python.org/cgi-bin/moinmoin/PythonDecoratorLibrary for the first > application (memoize - a return value cacheing helper/decorator, to optimize > access to repetitive or compute-intensive function calls, with NO changes > needed to the function itself). Other decorator candidates I've seen > mentioned are: > - mutex lock/unlock wrapper > - debugging/logging wrapper > - pre-condition/post-condition assertion wrappers > - input argument validation/typing wrapper > - return value type validation wrapper > > For this degree of flexibility, you can't hard-wire in specific section > names. > > -- Paul > > I agree. My proposal wasn't looking at the bigger picture here. But see the post by Stepfan Eischet in this thread. It doesn't address all of those issues either, but it does make the bigger problem smaller, by using an obvious interpretation of the method arguments to infer the type of method (i.e. class -versus- static -versus- instance). By using this simple convention (that most everyone is probably using already), that aspect of the annotations require no additional syntax. Hmmm... did I say 'aspect'? Maybe instead of cluttering up the code with all of these 'declarations' (which is clearly where the decoration movement is headed), we should have some sort of companion file that contains these annotations, similar to what you see in the AOP languages. From mwilson at the-wire.com Fri Aug 20 07:56:21 2004 From: mwilson at the-wire.com (Mel Wilson) Date: Fri, 20 Aug 2004 07:56:21 -0400 Subject: PEP 318: Can't we all just get along? References: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: In article , "Michael J. Fromberger" wrote: >By contrast, the special leading-double-underscore convention for class >members and the idea to identify instance, static, or class methods >based on the name of their first parameter, are not even a visibly >syntactic change. Each of these ideas specially overloads the single >most common programming-language operation -- interpretation of a >variable name -- under particular circumstances. This technique is (as >far as I know) nearly unprecedented in other languages, so it would be >surprising to most programmers. Furthermore, I think it makes code less >readable, by hiding important facts inside an implicit assumption about >the content of non-keyword identifiers, which are otherwise never >special. It relates to Standard C, where the standard divides up the namespace into names available to the implementation, and names which a programmer can use without risk of being clobbered by an implementation. The distinction is based on leading underscores and uppercase letters. FORTRAN applied a default type of INTEGER to variables whose names began with I, J, K, L, M or N. Such a move in Python might make i = raw_input ('Number, please: ') equivalent to @raw_input @int i = 'Number, please: ' (which I don't recommend) or i = raw_input ('Number, please: ') i = int (i) >Many people respond to this by saying, "The programmer has to be careful >anyway, so what is one more thing?" You could ask the same question >about drivers and beer. Little distractions add up to big mistakes. Yeah. At some point in a language's life, it begins to matter just how many things the programmer has to be careful about. Gerald Weinberg has something to say about this in _The Psychology of Computer Programming_. The generality vs raggedness of the distinctions that have to be made matter. One of Weinberg's examples is in FORTRAN which had tricky but not essentially difficult rules for which expressions were and were not allowed in array subscripts. It was found that many programmers shied away from using some legal forms, because it was less trouble to avoid the forms than to remember where the edge was between legal and illegal. Regards. Mel. From fumanchu at amor.org Wed Aug 25 10:44:21 2004 From: fumanchu at amor.org (Robert Brewer) Date: Wed, 25 Aug 2004 07:44:21 -0700 Subject: Generators versus Coroutines Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E6C@exchange.hqamor.amorhq.net> Pierre-Fr?d?ric Caillaud wrote: > I want co-routines too ! > There is a web framework (don't remember the name) > which models page > sequences as continuations. This is terrific. Think about > multipage forms, > for instance. > I wish Python could do this. Thinking about Seaside? http://www.beta4.com/seaside2/ Robert Brewer MIS Amor Ministries fumanchu at amor.org From cjw at sympatico.ca Wed Aug 25 22:00:59 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Wed, 25 Aug 2004 22:00:59 -0400 Subject: Alternative decorator syntax decision In-Reply-To: <412cc31c$1@news.012.net.il> References: <412cc31c$1@news.012.net.il> Message-ID: <412D445B.1060703@sympatico.ca> Avner Ben wrote: > I believe putting the decorator list before the function header is > generally a bad design decision. While it may make parsing-related > sense, it violates Python's greatest asset: being executable pseudocode. > The way I see it, the latter quality means being able to look at the > code and see clearly and immediately what requirements from the real > world the code was written the serve. Functions and methods are major > code entities that are naturally expected to represent discrete > functional requirements from the code, to this or that level of detail. > I expect to learn from the method name, the class it is in and the list > of arguments it takes, everything I need to know about the functional > requirement it implements. If that is not enough, I will look at the > docstring, if present. Everything else the method has to offer is > conveniently hidden below. Decorators of the type discussed recently - > with the exception of staticmethod and classmethod - are technical > detail of the kind I would like to see hidden below. Putting them on > top, prior to the what the method does (its name etc.) compromises the > design quality of the code, reducing it to yet another > abbreviation-based, self-centered technical scripting language. > The one esception I saw was J2, which, although putting the decorators > before the proper method header, uses indentation to state "this is an > extra piece of technicality which you are free to ignore - the def is > below." > > My vote: C2, E4, J2 > > Avner. Your expectation list makes sense to me. There is merit in having the docstring before the 'decorator', i.e. E4 Colin W. From pm_mon at yahoo.com Fri Aug 27 07:41:14 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Fri, 27 Aug 2004 07:41:14 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: <59e9fd3a04082618327b772ffd@mail.gmail.com> References: <412C09B4.5070106@yahoo.com> <59e9fd3a04082618327b772ffd@mail.gmail.com> Message-ID: Andrew Durdin wrote: > On Thu, 26 Aug 2004 20:54:22 -0400, Paul Morrow wrote: > >>Sure the interpreter uses __getitem__, but you use it too, right? I >>mean, you don't need the interpreter to tell you whether instances of >>the following class can act like a dictionary, do you? >> >> class Foo: >> def __getitem__(self, x): pass >> >>No you don't. Nor do you need to pretend that you're the interpreter, >>and simulate a call to an instance of Foo. That's because the mere >>presence of def __getitem__ tells you what you need to know. In this >>way, __getitem__ *does* serve as a declaration (of dictionary semantics) >>[*] to you and anyone reading your code. > > > That's because the dictionary interface/protocol requires a > __getitem__ method; there's no magical/technical reason why it should > be called __getitem__ rather than, say, dict_get_item. Um. Actually there is a reason why __getitem__ should be named something that starts and ends with double underscores. It's magical. By defining that method, instances of your class have special behavior. The *convention* is to surround magic methods with double underscores. So no, dict_get_item would not be a proper substitute name. > As an example, the iterator protocol requires two methods: __iter__() > and next() -- the second doesn't have the double underscores Ok I'll just say it (ban me from the newsgroup if this stings too much). The 'next' method is poorly named. It doesn't follow conventions for magic methods. It should be fixed. It should be __next__ > > All the "magic" > __X__ methods are just those methods required by certain built-in > interfaces/protocols. And there's syntactic sugar to make them > convenient. They don't affect the creation of the class at all, as you > can (if necessary) add them in after the fact: > Of course you can. In fact, you could do all of your programming that way, where you create an empty class, then add the methods and attributes after the fact. Even more fun would be to not even explicitly create the class (with a class statement), but instead call a function that returns an empty class, and then add your attributes to the function result. But that's not a very effective way to program if you care about program maintenance. As a reader of your code, I'll have a much harder time understanding what you're doing than if you adhered to basic conventions (like defining all of your methods and attributes inside of a class statement). But my point was that the presence of certain magic methods/attributes 'says' [*] something to the reader about our code. Paul * implicitly 'declares'. From f.dimmling at remove-this.snafu.de Tue Aug 31 14:51:28 2004 From: f.dimmling at remove-this.snafu.de (Friedrich Dimmling) Date: Tue, 31 Aug 2004 20:51:28 +0200 Subject: Newby pango problem In-Reply-To: References: <2pg9tfFjilreU1@uni-berlin.de> Message-ID: <2pjvlgFlnogfU1@uni-berlin.de> John Hunter wrote: > > Here is pango_demo.py from my pygtk examples dir. I wrote this a long > time ago, so it may not be the best or most modern usage, but it may > help you along your way > Hi John, it helped me along my way by pointing to the right section in the PyGtk Tutorial. Thanks Friedrich From pm_mon at yahoo.com Fri Aug 20 21:34:27 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Fri, 20 Aug 2004 21:34:27 -0400 Subject: Alternative decorator syntax decision In-Reply-To: <4126982d$0$22032$626a14ce@news.free.fr> References: <4126982d$0$22032$626a14ce@news.free.fr> Message-ID: Christophe Cavalaria wrote: > Paul Morrow wrote: > > >>Note: This is *not* about implicit method typing... :-) >> >>Although I haven't seen it discussed anywhere, we already have a >>decorator syntax (of sorts) that we use to annotate functions and >>classes. The " __var__ = " business. Have we decided that it is >>woefully insufficient? I know that there is a preference for the >>decorators to appear outside of the function def, but putting that >>aside, this 'style' of decorating already has a precendent in python, so >>it is probably as pythonic as you can get... >> >> class Foo: >> __metaclass__ = M >> __automethods__ = True >> __author__ = 'Paul Morrow' >> __version__ = '0.1' >> >> def baz(a,b,c): >> __synchronized__ = True >> __accepts__ = (int,int,int) >> __returns__ = int >> __author__ = 'Fred Flintstone' >> >>return a + b + c >> >> >>What is the burning desire to abandon this style? >> >>Paul > > > By what kind of black magic would setting the property __synchronized__ to > True would make that function synchronized ? And how can I define my own > decorators then ? There would be two kinds of decorators. Those that are simply informative (like __author__ or __version__), and those that have side-effects (like __metaclass__, __synchronized__, __automethods__, etc.). Those with side-effects would be implemented as special functions... def synchronized(func, trueOrFalse): __decorator__ = True __author__ = 'Billy Batson' __version__ = '0.1' # # perform the synchronized operation on func... # Here 'func' would be bound to baz (the function being decorated), and trueOrFalse would be bound to True (the value assigned to __synchronized__ in the definition of baz). So we could define our own decorator functions and they would get called the same way that synchronized does. def simpleFunction(a, b, c): __myDecorator__ = (73, 'hello', [5,6,7]) # ... def myDecorator(func, a, b, c): __decorator__ = True print func # 1. print a # 2. print b # 3. print c # 4. """Footnotes: 1. prints 2. prints 73 3. prints 'hello' 4. prints [5,6,7] """ > > And what about the other usage patterns for decorators > like the easy property getter/setter definition ? > Sorry, not sure what you mean. But would the above cover it? Paul From grante at visi.com Sun Aug 15 21:17:23 2004 From: grante at visi.com (Grant Edwards) Date: 16 Aug 2004 01:17:23 GMT Subject: Python secure? References: <411ffef6$0$65603$a1866201@newsreader.visi.com> Message-ID: <41200b23$0$8090$a1866201@newsreader.visi.com> On 2004-08-16, Roy Smith wrote: >>>> Sorry I should have said I'm new to programming let alone >>>> Python. I wish to know whether Python is secure as an exe for >>>> a commercial product. >>> >>> Yes. Anyone who recovers your "code" and/or uses it will be >>> in violation of copyright >> >> I don't see how decompiling is a copyright violation. If I >> buy a copy of a book, I'm pretty sure I can translate it into >> another language if I want to form my own use. > > It is illegal for you to walk in my front door when I'm not home, take > my silverware, and leave with it. True, but I don't see what that has to do with a discussion on copyright law. We were not discussing silverware theft, we were discussing whether decompiling code is a copyright violation. I said I don't think it is. I may be wrong, but anecdotes about getting your silver stolen in NYC don't refute my claim. Citing the statute or case law regarding decompiling object code would. > I am basing this statement on the laws applicable to where I > live (New York City), but am reasonably sure it's pretty much > the same in most places. > > That being true, it's still a good idea for me to lock the > door when I leave the house. I suppose so, but it has nothing to do with the topic at hand. -- Grant Edwards grante Yow! What PROGRAM are at they watching? visi.com From peter at engcorp.com Mon Aug 9 07:06:36 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 09 Aug 2004 07:06:36 -0400 Subject: Klingon (was Re: RELEASED Python 2.4, alpha 2) In-Reply-To: <53449fcb.0408081956.37a73abe@posting.google.com> References: <411231C8.3020308@interlink.com.au> <2-SdnZCwNs1SwI_cRVn-uQ@powergate.ca> <53449fcb.0408062138.68a1c196@posting.google.com> <53449fcb.0408081956.37a73abe@posting.google.com> Message-ID: Alan Anderson wrote: > The usual quote is from a 1996 issue of Wired magazine: "All the > fluent Klingon speakers can comfortably go out to dinner together." That's not the quote I heard, but it's not particularly important what I actually heard as you have more factual and current info. > There are no official counts of who speaks Klingon at various levels > of fluency. The Klingon Language Institute does offer certification > testing, though not everyone who speaks Klingon has had both the > desire and opportunity to take such a test. If you're still > interested, I might be able to find out how many people have passed > each "rank". No need to do that. Counts of those who speak a spoken language, much as with counts of those who use a given computer language, have very little meaning. It's enough to know that you and a large handful (for the hands of some appropriate alien species ;-) of others do speak it well. Thanks for the correction. -Peter From h.b.furuseth at usit.uio.no Tue Aug 24 16:08:29 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 24 Aug 2004 22:08:29 +0200 Subject: Regular expression guaranteed to fail References: <96jmi0pt39frp5n3r34afrt21cfeclp0mi@4ax.com> Message-ID: Eric Brunel wrote: >Hallvard B Furuseth wrote: >> Anyway, I note that r'x\A' beats all the other regexps suggested so far >> with a factor of 20 when searching 's'*10000. > > And when searching 'x'*10000? Since there is an 'x' in the re, it may change > things a lot... Heh. You are right: That's about almost as slow as the others. A bit slower than \Zx and \Ax\A, but still faster than the other alternatives. -- Hallvard From fredrik at pythonware.com Wed Aug 11 08:02:34 2004 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 11 Aug 2004 14:02:34 +0200 Subject: SQL Qeries via XMLRPC References: <3ovlu1-l6f.ln1@home.rogerbinns.com> Message-ID: Roger Binns wrote: > The existing standard Python library XML-RPC works > well, but has the limitation that it doesn't fully > support HTTP authentication and it uses one connection > per request. The authentication issue can be solved > by making authentication part of your exposed APIs, > not the underlying XML-RPC transport. > > The one connection per request will presumably be > solved in a future release of the Python library > and generally is not an issue on a LAN. the standard transport does this, yes. it's fairly easy to plug in your own transports (just subclass Transport, override as necessary, and pass an instance of your custom transport to the ServerProxy class). From justin__devine at hotmail.com Mon Aug 30 16:28:50 2004 From: justin__devine at hotmail.com (Justin) Date: 30 Aug 2004 13:28:50 -0700 Subject: "Content-Length" header In-Reply-To: Message-ID: Ok I have now discovered the oddest problem ever. Check this out it seems that the same code that works outside of a for loop doesn't work in one check it out. Even though the first entry in the list linklisttype is the same exact URL. (THIS WORKS) temp = urlopen("http://www.ecs.soton.ac.uk/~harnad/Temp/Ariadne-RAE.doc") print temp temp2 = temp.info() print temp2 temp3 = temp2.getheader("Content-Length") print temp3 (THIS DOESN't) for y in linklisttype: x = y temp = urlopen(x) print temp temp2 = temp.info() print temp2 temp3 = temp2.getheader("Content-Length") print temp3 From steven.bethard at gmail.com Wed Aug 25 02:51:42 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Wed, 25 Aug 2004 06:51:42 +0000 (UTC) Subject: with as J2 keyword (WAS: Re: J2 0-2-6 is available) References: <7xr7pvsp3i.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin <"http://phr.cx" NOSPAM.invalid> writes: > > Steven Bethard writes: > > @classmethod > > @funcattrs(author="Fran??ois Pinard") > > def foo(cls): > > pass > > How about double colon instead of @? > > ::classmethod > ::funcattrs(author="Fran??ois Pinard") > def foo(cls): > pass Well, a double colon isn't valid decorator syntax, so it wouldn't be good for me to present examples of decorator usage in that form... Maybe I misunderstand you? Or maybe you're using a quote from me out of context? I'm confused... Steve From rschroev_nospam_ml at fastmail.fm Fri Aug 20 03:02:26 2004 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Fri, 20 Aug 2004 07:02:26 GMT Subject: age of Python programmers In-Reply-To: References: Message-ID: <6mhVc.219633$p67.10887223@phobos.telenet-ops.be> mensanator at aol.com wrote: > Roel Schroeven wrote: > >>Only Event Horizon on TV tonight... > > > What network? VT4, a Flemish (Belgian) network. -- "Codito ergo sum" Roel Schroeven From raims at dot.com Sun Aug 1 04:17:28 2004 From: raims at dot.com (Lawrence Oluyede) Date: Sun, 1 Aug 2004 10:17:28 +0200 Subject: Importance of C# (was Re: IronPython-0.6 is now available!) References: <278de0e.0407281353.27b6a457@posting.google.com> <7u5tpvap1oh5.1h1v27kmjvf04$.dlg@40tude.net> Message-ID: <14falq1p3y33s.lnhptj281b9o$.dlg@40tude.net> In data 31 Jul 2004 17:30:23 -0700, Dan Bishop ha scritto: > And ironically, there's less of a need for MI (and inheritance in > general) in Python, because it's dynamically typed. > > I don't think I've ever used MI in Python. Yeah, me too, I prefer the mixin approach, anyway, if you want to take a look at a framework (with a wonderful API IMHO) that massively uses MI watch Soya3D sources: http://home.gna.org/oomadness/en/soya/ -- Lawrence (l dot oluyede at virgilio dot it) "In IE we trust" From user at domain.invalid Thu Aug 19 06:29:54 2004 From: user at domain.invalid (Robbie) Date: Thu, 19 Aug 2004 20:29:54 +1000 Subject: age of Python programmers In-Reply-To: References: Message-ID: I'm 18, discovered Python about 4 years ago, didn't really realise what is could do til 2 years ago. Only just got really into it recently. Man my english skills are bad, can Python fix those? From gregor.jan at NOSPAMquick.cz Wed Aug 4 15:21:57 2004 From: gregor.jan at NOSPAMquick.cz (Jan Gregor) Date: Wed, 4 Aug 2004 21:21:57 +0200 Subject: jython and java exceptions Message-ID: Hello I found that jython catches exact java exceptions, not their subclasses. Is there some way to get around this limitation (or error) ? My program has class representing database source and specialed classes for particulars databases. Now there are two options - to include exception (subclasses of SQLException) for every db in except (so all drivers has to be present) or to move methods to subclasses. Jan From ben at benlast.com Tue Aug 17 09:48:21 2004 From: ben at benlast.com (Ben Last) Date: Tue, 17 Aug 2004 14:48:21 +0100 Subject: How big can a Python program be? In-Reply-To: Message-ID: > -----Original Message----- > From: python-list-bounces+ben=benlast.com at python.org > [mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of > Christopher T King > Sent: 17 August 2004 14:13 > To: python-list at python.org > Subject: Re: How big can a Python program be? > > > On 17 Aug 2004 vronskij at post.sk wrote: > > > Suppose , you are a sole programmer (lonewolf). How many lines can one > > handle? > > $ wc -l my_current_big_project_that_is_very_far_from_being_complete/* > 2945 > > I'm sure others can do better than that. > > -- > http://mail.python.org/mailman/listinfo/python-list From blaktyger at hotmail.com Wed Aug 11 21:47:33 2004 From: blaktyger at hotmail.com (Blaktyger) Date: 11 Aug 2004 18:47:33 -0700 Subject: Images not diplayed... Message-ID: Helllo, I'm trying to set up a web page where users can upload their pictures. I wrote a python script witch allows users to preview the pictures posted to the database. Problem is that under Mozilla Firefox, the images are not displayed. This is the script I wrote: #!/usr/bin/python2.3 print 'Content-Type: text/html\n\n' import blakHtml, sys, cgi, urllib sys.stderr = sys.stdout prevSt=cgi.FieldStorage() 1 if not prevSt.has_key('nbOfPic'): 2 print 'blah blah!' 3 else: 4 nbOfPic2=prevSt['nbOfPic'].value 5prevPg=blakHtml.HTMLDocument() 6 header=prevPg.htmlHeader('Picture Preview') 7 beginTable=prevPg.tableTag() 8 p=0 9 nbOfLine=0 10 addLine=' ' 11 for picLinked in range(int(nbOfPic2)): 12 p=p+1 13 exec("""if not prevSt.has_key('pin_nb_%s'): 14 pass 15 else: 16 addLine=addLine +' '+prevSt['pin_nb_%s'].value 18 nbOfLine=nbOfLine+1 19 if nbOfLine==5: 20 nbOfLine=0 21 addLine=addLine+'
' """)%(p,p,p) 22 print header+addLine+prevPg.htmlFooter() line 6 generates the web page title the loop check for non-null cgi values and creates the corresponding tag Link to webpage http://pythonboard.homelinux.com/cgi-bin/howManyPics.py Thanks! From vonehr at ipm.fhg.de Mon Aug 23 12:01:40 2004 From: vonehr at ipm.fhg.de (Markus von Ehr) Date: Mon, 23 Aug 2004 18:01:40 +0200 Subject: Executing bytecode from a string. In-Reply-To: References: Message-ID: Benjamin Scherrey schrieb: > I'm curious as to how difficult it would be to take a string that contains > compiled bytecode, load it into memory, give it a function name then > execute that function. I'm thinking of a database that contains compiled > objects that I can load and execute. I'm also curious as to what level of > grainularity this would work - module, class, class method, function? > Anyone tried to do this before? Obviously dependencies are a consideration > but I'm more interested in the mechanics of this. Appreciate ideas & > pointers you might have... > > Ben Scherrey I am just writing my Macro/Script in python sourcecode. In the program I'm doing: f = open('segment.py','r') str = f.read() f.close() segment_code = compile(str, '', 'exec') exec(segment_code) Markus From indrek.kruusa at tuleriit.ee Sat Aug 7 03:34:43 2004 From: indrek.kruusa at tuleriit.ee (Indrek Kruusa) Date: Sat, 07 Aug 2004 10:34:43 +0300 Subject: Importance of C# (was Re: IronPython-0.6 is now available!) In-Reply-To: References: <278de0e.0407281353.27b6a457@posting.google.com> <5dydnZSDZaARoZXcRVn-ug@powergate.ca> <9418be08.0407292114.129c856f@posting.google.com> Message-ID: <41148613.6060807@tuleriit.ee> Peter Hansen wrote: > Indrek Kruusa wrote: > >> A little comparison of C#, perl and python here (Speed test in menu): >> >> http://www.tuleriit.ee/progs/ > > > > Do you pick a new test case, or write inefficient code that no > programmer experienced in that > language would actually write? I'm not sure of the answer... This is just an attempt to provide something more fun and "real" than just simple measuring of millions of iterations over a+=1 in different languages. It includes simple string operations, date manipulating, some calculating and I/O. Those things are somehow comparable in the means of execution speed. To compare fullblown solutions...I don't know...you can write thesis about it but among other aspects you definitely need a fair and simple speed test and then I suppose you will find my 2c quite usable :) Indrek From peter at engcorp.com Fri Aug 27 07:51:54 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 27 Aug 2004 07:51:54 -0400 Subject: Larry Wall & Cults In-Reply-To: References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: norman werner wrote: > Peter Hansen wrote: >>Robert wrote: >>>Isn't "Xah Lee" chinese for "Moron"? >>No, it's Esperanto (universal language) for "troll"... > > Bonvolu ne s:ercu pri nekonatoj aferoj. "Xah Lee" certe - pro manko de > Ikso - ne estas esperanto. Kaj via s:erco nur s:tulta estas. > > Norman > tradukita: > You certainly have not the slightest idea about esperanto. So please > dont't emberass yourself. And back to topic(?): "Xah lee" is not > esperanto. Well, let's see how your clear your mind was today. Either it's a joke, in which case it is clear to all that it doesn't really mean troll, or it's not a joke in which case I obviously don't know Esperanto. Here are the facts: 1. It's a joke, as you surmised. 2. I know Esperanto. Now can you perhaps see that your first comment in the poor translation of your own Esperanto is invalid and offensive? By the way, to those not fluent in both languages, what this fellow really wrote was more along the lines of "Please do not joke about things you don't know about. Xah Lee certainly -- because Esperanto has no "x" -- is not Esperanto. And your joke is merely stupid." If you're going to accuse me of stupidity, please at least get your own translation and logic skills in working order first. -Peter From elainejackson7355 at home.com Sun Aug 29 18:50:45 2004 From: elainejackson7355 at home.com (Elaine Jackson) Date: Sun, 29 Aug 2004 22:50:45 GMT Subject: play a midi file from the interpreter? Message-ID: <95tYc.261224$J06.123492@pd7tw2no> (How) can you make it so that a function invoked in the python interpreter can run another program? (Like the webbrowser module does, only not with a web browser.) If it matters the OS is Windows98 and the specific aim in mind is to have a function that saves some data as a midi file and then causes the said midi file to play. From ajsiegel at optonline.com Wed Aug 25 22:01:21 2004 From: ajsiegel at optonline.com (Arthur) Date: Thu, 26 Aug 2004 02:01:21 GMT Subject: python-dev Summary for 2004-08-01 through 2004-08-15 References: <3l3pi0pgmgu0uir1ucnj0rlfo355c6i5cp@4ax.com> <8ab0589d.0408251103.13ddda04@posting.google.com> Message-ID: On 25 Aug 2004 12:03:49 -0700, brett at python.org (Brett C.) wrote: >Arthur wrote in message news:<3l3pi0pgmgu0uir1ucnj0rlfo355c6i5cp at 4ax.com>... > >python-dev is meant for discussing details about Python's evolution. >The idea is that pie-in-the-sky ideas get hashed out in the community >(which c.l.py is the gateway), once it gets clarified and has >community support it moves over to python-dev, it gets discussed >there, and either gets accepted, canned, or revised and sent back out >to the community for more refinement. Huh? I don't agree that it is supposed to work in any particular way. It works the way it works. There *is* a BDFL, Which is fine with me, but inconsistent with a defined structure of the kind you are trying to describe, or any other kind for that matter. >> You see the point... >> >> I don't think you want to say to the People, either to crash the >> Senate floor, or hold their peace, >> > >Just to start off, I hope everyone realizes this is my opinion and in >no way do I represent python-dev in any official way. Even with the >Summaries I just happen to be dumb enough to do them so they just let >me play in my little corner while I write up the history book. =) > >OK, with that disclaimer out of the way... > >That is the reverse order of things are supposed to be. Huh? I don't agree that it is supposed to work in any particular way. It works the way it works. There *is* a BDFL, Which is fine with me, but inconsistent with a defined structure of the kind you are trying to describe, or any other kind for that matter. Art From eurleif at ecritters.biz Wed Aug 18 13:29:37 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Wed, 18 Aug 2004 13:29:37 -0400 Subject: age of Python programmers In-Reply-To: References: Message-ID: <2ohhqhFa1qgmU1@uni-berlin.de> Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... I'm 13, I'll be 14 in 89 days. I started doing somewhat real programming at around 11; I had done silly things in a VB-like language for Mac OS before then, mostly "viruses" that displayed a full-screen window with no close button, but hadn't written any code. From __peter__ at web.de Thu Aug 12 08:45:33 2004 From: __peter__ at web.de (Peter Otten) Date: Thu, 12 Aug 2004 14:45:33 +0200 Subject: Integers have docstring for int() References: <59e9fd3a04081105087366db98@mail.gmail.com> <16666.13564.527138.202013@montanaro.dyndns.org> <21064255.0408120327.4092144c@posting.google.com> Message-ID: Peter Abel wrote: > The following seems to be unaccustomed, but it's good Python: > >>>> class myInt(int): > ... """Instance of myInt""" > ... def __init__(self,val): > ... self=int(val) > ... >>>> i=myInt(10) Minor nit: assigning to self has no effect. you can leave out the above __init__() altogether. >>> class myInt(int): ... "instance of myInt" ... >>> mi = myInt(10) >>> mi 10 >>> type(mi) >>> As int is immutable, all the "interesting stuff" has to be performed in __new__(). A more detailed view of what is going on in __init__(): >>> class myInt(int): ... def __init__(self, val): ... print "val-id", id(val) ... print "self before assignment", id(self) ... self = int(val) ... print "self after assignment", id(self) ... >>> mi = myInt(1000) val-id 135719460 self before assignment 1076456780 self after assignment 135719460 >>> id(mi) 1076456780 >>> I. e. you create an integer from another integer and immediately throw it away. I used 1000 because some low numbers are "interned". For them "val-id" and "self after assignment" would have been the same. Peter From barry at python.org Sun Aug 22 23:47:12 2004 From: barry at python.org (Barry Warsaw) Date: Sun, 22 Aug 2004 23:47:12 -0400 Subject: PEP 292 - Simpler String Substitutions Message-ID: <1093232832.28573.16.camel@geddy.wooz.org> Attached is the latest version of PEP 292, which describes simpler string substitutions. This PEP is slated for inclusion in Python 2.4 and will likely be checked in before the next alpha release. The canonical location of the PEP is here: http://www.python.org/peps/pep-0292.html Cheers, -Barry -------------- next part -------------- PEP: 292 Title: Simpler String Substitutions Version: $Revision: 1.12 $ Last-Modified: $Date: 2004/08/23 03:31:45 $ Author: barry at python.org (Barry A. Warsaw) Status: Draft Type: Standards Track Created: 18-Jun-2002 Python-Version: 2.4 Post-History: 18-Jun-2002, 23-Mar-2004, 22-Aug-2004 Abstract This PEP describes a simpler string substitution feature, also known as string interpolation. This PEP is "simpler" in two respects: 1. Python's current string substitution feature (i.e. %-substitution) is complicated and error prone. This PEP is simpler at the cost of some expressiveness. 2. PEP 215 proposed an alternative string interpolation feature, introducing a new `$' string prefix. PEP 292 is simpler than this because it involves no syntax changes and has much simpler rules for what substitutions can occur in the string. Rationale Python currently supports a string substitution syntax based on C's printf() '%' formatting character[1]. While quite rich, %-formatting codes are also error prone, even for experienced Python programmers. A common mistake is to leave off the trailing format character, e.g. the `s' in "%(name)s". In addition, the rules for what can follow a % sign are fairly complex, while the usual application rarely needs such complexity. Most scripts need to do some string interpolation, but most of those use simple `stringification' formats, i.e. %s or %(name)s This form should be made simpler and less error prone. A Simpler Proposal We propose the addition of a new class -- called 'Template', which will live in the string module -- derived from the built-in unicode type. The Template class supports new rules for string substitution; its value contains placeholders, introduced with the $ character. The following rules for $-placeholders apply: 1. $$ is an escape; it is replaced with a single $ 2. $identifier names a substitution placeholder matching a mapping key of "identifier". By default, "identifier" must spell a Python identifier as defined in [2]. The first non-identifier character after the $ character terminates this placeholder specification. 3. ${identifier} is equivalent to $identifier. It is required when valid identifier characters follow the placeholder but are not part of the placeholder, e.g. "${noun}ification". If the $ character appears at the end of the line, or is followed by any other character than those described above, it is treated as if it had been escaped, appearing in the resulting string unchanged. NOTE: see open issues below. No other characters have special meaning, however it is possible to derive from the Template class to define different rules for the placeholder. For example, a derived class could allow for periods in the placeholder (e.g. to support a kind of dynamic namespace and attribute path lookup). Once the Template has been created, substitutions can be performed using traditional Python syntax. For example: >>> from string import Template >>> mapping = dict(name='Guido', country='the Netherlands') >>> s = Template('${name} was born in ${country}') >>> print s % mapping Guido was born in the Netherlands Another class is provided which derives from Template. This class is called 'SafeTemplate' and supports rules identical to those above. The difference between Template instances and SafeTemplate instances is that in SafeTemplate if a placeholder is missing from the interpolation mapping, no KeyError is raised. Instead, the original placeholder is included in the result string unchanged. For example: >>> from string import Template, SafeTemplate >>> mapping = dict(name='Guido', country='the Netherlands') >>> s = Template('$who was born in $country') >>> print s % mapping Traceback (most recent call last): [...traceback omitted...] KeyError: u'who' >>> s = SafeTemplate('$who was born in $country') >>> print s % mapping $who was born in the Netherlands Why `$' and Braces? The BDFL said it best: The $ means "substitution" in so many languages besides Perl that I wonder where you've been. [...] We're copying this from the shell. Comparison to PEP 215 PEP 215 describes an alternate proposal for string interpolation. Unlike that PEP, this one does not propose any new syntax for Python. All the proposed new features are embodied in a new library module. PEP 215 proposes a new string prefix representation such as $"" which signal to Python that a new type of string is present. $-strings would have to interact with the existing r-prefixes and u-prefixes, essentially doubling the number of string prefix combinations. PEP 215 also allows for arbitrary Python expressions inside the $-strings, so that you could do things like: import sys print $"sys = $sys, sys = $sys.modules['sys']" which would return sys = , sys = It's generally accepted that the rules in PEP 215 are safe in the sense that they introduce no new security issues (see PEP 215, "Security Issues" for details). However, the rules are still quite complex, and make it more difficult to see the substitution placeholder in the original $-string. The interesting thing is that the Template class defined in this PEP has nothing to say about the values that are substituted for the placeholders. Thus, with a little extra work, it's possible to support PEP 215's functionality using existing Python syntax. For example, one could define subclasses of Template and dict that allowed for a more complex placeholder syntax and a mapping that evaluated those placeholders. Internationalization The implementation supports internationalization magic by keeping the original string value intact. In fact, all the work of the special substitution rules are implemented by overriding the __mod__() operator. However the string value of a Template (or SafeTemplate) is the string that was passed to its constructor. This approach allows a gettext-based internationalized program to use the Template instance as a lookup into the catalog; in fact gettext doesn't care that the catalog key is a Template. Because the value of the Template is the original $-string, translators also never need to use %-strings. The right thing will happen at run-time. Reference Implementation A SourceForge patch[4] is available which implements this proposal, include unit tests and documentation changes. Open Issues - Should the Template and SafeTemplate classes convert mapping values to strings (or unicodes)? I.e. what should this code do: >>> from string import Template >>> Template('The cost was $amount euros') % {'amount': 7} Should this raise an exception such as TypeError, or should this return the string 'The cose was 7 euros'? Proposed resolution: no automatic stringification. - The pattern for placeholders in the Template and SafeTemplate classes matches Python identifiers. Some people want to match Python attribute paths, e.g. "$os.path.sep". This can be useful in some applications, however note that it is up to the interpolation mapping to provide namespace lookup for the attribute paths. Should we include AttributeTemplate and SafeAttributeTemplate in the standard library? What about more complex patterns such as Python expressions? Proposed resolution: No, we don't include them for now. Such classes are easily derived, and besides, we're not proposing to include any interpolation mappings, and without such a specialized mapping, a pattern matching attribute paths or expressions aren't useful. - Where does the Template and SafeTemplate classes live? Some people have suggested creating a stringtools or stringlib module to house these two classes. The PEP author has proposed a re-organization of the existing string module, turning it into a string package. Proposed resolution: There seems little consensus around either suggestion, and since the classes are just a few lines of Python, I propose no string module re-organization, but to add these two classes to string.py. - Should the $-placeholder rules be more strict? Specifically, objections have been raised about 'magically' escaping $'s at the end of strings, or in strings like '$100'. The suggestion was that we add another matching group which matches bare $'s, raising a ValueError if we find such a match. Proposed resolution: There seems to be consensus for strictness on the grounds of explicit is better than implicit. References [1] String Formatting Operations http://www.python.org/doc/current/lib/typesseq-strings.html [2] Identifiers and Keywords http://www.python.org/doc/current/ref/identifiers.html [3] Guido's python-dev posting from 21-Jul-2002 http://mail.python.org/pipermail/python-dev/2002-July/026397.html [4] Reference Implementation http://sourceforge.net/tracker/index.php?func=detail&aid=1014055&group_id=5470&atid=305470 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: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 316 bytes Desc: This is a digitally signed message part URL: From kjetilho at yksi.ifi.uio.no Fri Aug 27 11:32:36 2004 From: kjetilho at yksi.ifi.uio.no (Kjetil Torgrim Homme) Date: Fri, 27 Aug 2004 17:32:36 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> Message-ID: <1ry8k0d2az.fsf@rovereto.ifi.uio.no> [Jacek Generowicz]: > > How about > > for car in rental_cars: > if car.make == "Lamborghini": > car.insurance = 1000.00 > elif car.make == "Lada": > car.insurance = 50.00 > else: > car.insurance = 100.00 > pass > pass > logger.debug("Insurance values updated") > > ? > > Hmm ... not pretty, but at least it doesn't PERLize the language. "pass" is a no-op, and should only be used when a suite is required, but the suite should do nothing. you're proposing a convention saying ''if "pass" appears in a suite which also contains other expressions, the "pass" signals the end of the suite'' that's a hack, and IMHO not worthy of a Python program. not even Perl has anything like that, AFAIK. -- Kjetil T. From richard.scothern at gmail.com Fri Aug 6 10:57:44 2004 From: richard.scothern at gmail.com (Richy2004) Date: 6 Aug 2004 07:57:44 -0700 Subject: Unicode support In-Reply-To: Message-ID: code: import sys,codecs file = codecs.open("accountmgr_words_arb.txt", "r", "utf-16") print (file.readline()) output: File "./test.py", line 5, in ? print (file.readline()) File "C:\Python23\lib\codecs.py", line 384, in readline return self.reader.readline(size) File "c:\Python23\lib\encodings\utf_16.py", line 57, in readline raise NotImplementedError, '.readline() is not implemented for UTF-16' NotImplementedError: .readline() is not implemented for UTF-16 ====================================================== code: import sys, codecs file = codecs.open("accountmgr_words_arb.txt", "r", "utf-16") print (file.read()) output: Traceback (most recent call last): File "./test.py", line 5, in ? print (file.read()) File "c:\Python23\lib\encodings\cp850.py", line 18, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-2: character maps to ====================================================== code: import sys, codecs file = codecs.open("accountmgr_words_arb.txt", "rb", "utf-16") lines = file.readlines() print lines this works !, output: [u'\u0646\u0648\u0639 \u062d\u0633\u0627\u0628 \u062c\u062f\u064a\u062f \u0645\u062e\u062a\u0627\u0631.\r\n'] if I add these lines: line = lines[0] tokens = line.split("\\u") print tokens[0] I get this: :( Traceback (most recent call last): File "./test.py", line 8, in ? print tokens[0] File "c:\Python23\lib\encodings\cp850.py", line 18, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-2: character maps to Thanks, Richard From steven.bethard at gmail.com Fri Aug 6 13:19:21 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: 6 Aug 2004 10:19:21 -0700 Subject: elements of decorator syntax suggestions Message-ID: I think one of the biggest reasons we're having such problems coming to any agreement on decorator syntax is that each proposal makes a number of syntax decisions, not just one. For decorators, I see the following decisions that must be made: 1) Indicator Proposals differ on how some sort of indicator of "decoratorhood" is use. These include: * none (e.g. just the list, as in the "list-after-def" suggestion) * the '@' character * a new keyword (with, using, decorate, etc.) 2) Location Proposals also differ on exactly where the decorator declaration should be made. These include: * before def * between def and function name * between function name and argument list * between argument list and colon * after colon (first line in body) 3) List notation As I understand it, it's already decided that any implementation of decorators must allow for a list of decorators to be applied. So proposals that might be accepted must explain how this can be done. The options I've seen: * one per line (as currently) * commas only * current list syntax (or some similar variant) 4) Indentation Proposals also differ on whether or not decorators should introduce a new block. What I've seen: * no block * block I thought the summary above might put some things into perspective so that when you're arguing for one syntax or another, you can argue separately for the points that matter most to you. It might be that we mostly agree on, say, the need for a keyword, or the block indentation (though I'm certainly not holding my breath). But I'd rather hear arguments for the different sections separately because, to some degree, they're pretty much orthogonal. In case you were just asking yourself, "well, gee, Steve, what do you think?", =) here's what I think for each of the points above: 1) Indicator I want a new keyword. A list alone (no matter where it's placed) doesn't look any more like a decorator to me than '@' does. I want some sort of cue that reads more clearly. I'm not picky on what this keyword is -- 'decorate' seemed like a reasonable proposal, but I'd even be happy with 'with' or 'using' -- but I don't just want arbitrary symbols. I think this is most important from the perspective of new Python users, who will have to guess the meaning of such syntax from someone else's code. Having a keyword that makes the usage clear makes this reading much easier. 2) Location I don't like "between def and function name" or "between function name and argument list" because I think they make it harder to see the basic signature of the function. Remember that we have to support lists, so just sticking a in single word, like staticmethod or classmethod, isn't an option -- otherwise, I could have perhaps seen the merit of "between def and function name". I'm not a big fan of "after colon" (like a doc-string) because I'm more likely to read this as part of the function definition. (In fact, that's what I'd do now, so this is a semantic change, one of the things I'd rather avoid.) As far as "before def" or "betwen argument list and colon" go (and I believe these are the major contenders), I could go either way -- and I'm really not particular here; I'd rather have /some/ decorator syntax than argue over these forever. "before def" seems to deal better with functions that have long names or argument lists (Guido's example convinced me that I'd be confused where arguments ended and decorators started), but "between argument list and colon" avoids the two-lines-define-a-single-function problem. Eh... Like I say, I'm not going to argue this one -- I could be happy with either. 3) List notation I don't really have a preference here. I can see that commas only might be a pain if you need to use multiple lines perhaps. But "one per line" or "list syntax" would both be fine with me. 4) Indentation I'd prefer that decorators didn't start a new block mainly because that makes, for example, an instance method with an 'accepts' decorator on a different block level than an instance method without one. Still, I could live with indented decorators. So in summary -> yay keywords! -> before def or before colon, and -> whatever list notation and indentation floats your boat =) Steve From brian at sweetapp.com Fri Aug 13 10:14:16 2004 From: brian at sweetapp.com (Brian Quinlan) Date: Fri, 13 Aug 2004 16:14:16 +0200 Subject: Pyhton Interpreter Startup time In-Reply-To: <411CC6A2.7060202@cenix-bioscience.com> References: <30260531.0408120829.27a536bc@posting.google.com> <411C7262.1000803@cenix-bioscience.com> <411C8FB8.20901@sweetapp.com> <411CC6A2.7060202@cenix-bioscience.com> Message-ID: <411CCCB8.6030401@sweetapp.com> Neil Benn wrote: > Brian Quinlan wrote: > >> >> Neil, are you using Norton Antivirus with autoprotect enabled? I've >> seen that cause problems in the past because NAV scans every file as >> it is opened and Python loads a lot of file on startup. > Good guess but no cigar!!! Some other suggestions: 1. try running Python with the -v option is seeing if there is any obvious pause between imports, any imports of uncompiled modules or any importing of seemingly unnecessary modules 2. check your sys.path for references to potentially slow file systems e.g. network drives What version of Python are you using? Cheers, Brian From martin at v.loewis.de Fri Aug 6 18:16:41 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 07 Aug 2004 00:16:41 +0200 Subject: Proposal: require 7-bit source str's In-Reply-To: References: <4112AC7B.1060508@v.loewis.de> <411343D7.3020604@v.loewis.de> <411353A3.8090502@v.loewis.de> <4113759E.2070405@v.loewis.de> <4113E755.8060205@v.loewis.de> Message-ID: <41140349.6090202@v.loewis.de> Hallvard B Furuseth wrote: > - For a number of source encodings (like utf-8:-) it should be easy > to parse and charset-convert in the same step, and only convert > selected parts of the source to Unicode. Correct. However, that it works "for a number of source encodings" is insufficient - if it doesn't work for all of them, it only unreasonably complicates the code. For some source encodings (namely the CJK ones), conversion to UTF-8 is absolutely necessary even for proper lexical analysis, as the byte that represents a backslash in ASCII might be the first byte of a two-byte sequence. > - I think the spec is buggy anyway. Converting to Unicode and back > can change the string representation. But I'll file a separate > bug report for that. That is by design. The only effect of such a bug report will be that the documentation clearly clarifies that. Users that need to make sure the run-time representation of a string is the same of as the source representation need to pick a source encoding that round-trips. > Sorry, I thought you were speaking of promising a __future__ when all > string literals are required to be 7-bit or u'' literals. Yes, but that *will* cause a wide debate. Say, Python 3.5, to be release 2017 or so. I could live with such a language, but I'm certain many users can't, in any foreseeable future. Regards, Martin From mlh at furu.idi.ntnu.no Mon Aug 23 16:42:46 2004 From: mlh at furu.idi.ntnu.no (Magnus Lie Hetland) Date: Mon, 23 Aug 2004 20:42:46 +0000 (UTC) Subject: Standard graph API? References: Message-ID: In article , Paul McGuire wrote: [snip] >Not sure if this falls under the category of an API, but it may be >relevant to what you are doing. > >This is a Python API to the Graphviz DOT language: >http://dkbza.org/pydot.html Yes, I found that -- probably quite useful. >So I think this is evidence you are not alone. :) >-- Paul -- Magnus Lie Hetland "Canned Bread: The greatest thing since sliced http://hetland.org bread!" [from a can in Spongebob Squarepants] From tim.peters at gmail.com Fri Aug 6 17:19:13 2004 From: tim.peters at gmail.com (Tim Peters) Date: Fri, 6 Aug 2004 17:19:13 -0400 Subject: @decorators In-Reply-To: <10h7qlg5adbfj86@news.supernews.com> References: <10h73e5kh1et536@news.supernews.com> <4113e5be@nntp.zianet.com> <10h7qlg5adbfj86@news.supernews.com> Message-ID: <1f7befae040806141923baaf07@mail.gmail.com> [John Roth] > ... > Since I wrote that, I managed to read the new, improved > and rewritten PEP, and discovered that the new syntax > doesn't allow parameters. It does. What it says is "arbitrary expressions will not work", and I would agree that's vague if you insisted it was . What it means is that parameters are fine, but things like @list_of_decorators[index] @eatme and deco1 or deco2 @random.choice([deco1, deco2, deco3]) are right out. Note that the PEP still contains examples of decorators with arguments, and the people who want decorators most need them to accept arguments. From python-url at phaseit.net Mon Aug 23 15:12:20 2004 From: python-url at phaseit.net (Peter Otten) Date: Mon, 23 Aug 2004 19:12:20 +0000 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 23) Message-ID: QOTW: "Lucky for me I found python before Java took over my brain." - Huy "Python fits my brain" - c.l.py proverb "So as far as I'm concerned, SOAP is not XML, nor is it useful to even a fraction of the degree to which it is destructive." - Uche Ogbuji Over the weekend Andrea Griffini has implemented a toy Basic interpreter in Python, inspired by a post of Leif K-Brooks. A few other languages are also available. http://groups.google.com/groups?threadm=2oo13eFcj548U1%40uni-berlin.de Jeff Epler and Martin von Loewis help Vincent Delft to overcome the lack of encoding-awareness in the zip file format. http://groups.google.com/groups?threadm=4127a6d7%240%244090%24ba620e4c%40news.skynet.be As of June 2004, Pythonology has a few new success stories. http://www.pythonology.com/success Python people are nice, says Andy Todd. http://www.halfcooked.com/mt/archives/000833.html Something new from the decorator front: Paul McGuire initates another decorator poll and a new keyword followed by a suite seems to emerge as a viable contender with a small chance to beat the pie syntax. http://groups.google.com/groups?threadm=t07Vc.1179%24v86.188%40fe2.texas.rr.com Thanks to the work of Michael Sparks building on previous efforts by Mark Russell there is already a patch. Anthony Baxter, the outspoken proponent of the pie syntax, helps with some useful hints, too. http://www.python.org/sf/1013835 Robert Brewer volunteers to "sell" the result to GvR. http://www.aminus.org/rbre/python/pydec.html Too old/too young is no excuse for not learning Python, according to a thread started by Lucas Raab, asking for the "Age of Python programmers" with the only word of caution, "Not yet, but our day will come" being uttered by Robey Holderith. http://groups.google.com/groups?th=5f4805189aa2470d ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous 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 newsgroup weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Brett Cannon continues the marvelous tradition established by Andrew Kuchling and Michael Hudson of intelligently summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Business Forum "further[s] the interests of companies that base their business on ... Python." http://www.python-in-business.org Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donate.html Cetus collects Python hyperlinks. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://aspn.activestate.com/ASPN/Cookbook/Python Among several Python-oriented RSS/RDF feeds available are http://www.python.org/channews.rdf http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi http://python.de/backend.php For more, see http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. *Py: the Journal of the Python Language* http://www.pyzine.com Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. From beliavsky at aol.com Tue Aug 10 09:56:41 2004 From: beliavsky at aol.com (beliavsky at aol.com) Date: 10 Aug 2004 06:56:41 -0700 Subject: Paul Graham on Python hackers References: <3064b51d.0408090448.31806af5@posting.google.com> Message-ID: <3064b51d.0408100556.1962ba58@posting.google.com> Bryan Olson wrote in message news:... > Functional? Not so much. In viable functional languages > expressions/statement are evaluated primarily for their return > values and not their side-effects. (In purely functional > languages, there are no side-effects). I don't know enough about functional programming (FP) to argue. David Mertz wrote some articles on FP in Python -- see http://www-106.ibm.com/developerworks/library/l-prog.html . From d-hanst at online.no Thu Aug 12 13:03:22 2004 From: d-hanst at online.no (Dag Hansteen) Date: Thu, 12 Aug 2004 19:03:22 +0200 Subject: Question References: <002b01c47fdd$bf0c2280$4e01a8c0@dagan> <411A9AD3.2020401@ieee.org> Message-ID: <002e01c4808e$5c0a0b50$4e01a8c0@dagan> hi Shane! What I want is *just* to resolve an expression in a string like: a = "2+2" then b = eval(a) so b = 4 I dont want it to be possible to type for example commands such as __import__('os') and be able to use any functions in that module in the wxTextCtrl which is only ment to calculate numbers! If you understand.... regards Dag Hansteen! ----- Original Message ----- From: "Shane Holloway (IEEE)" To: "Dag Hansteen" Cc: Sent: Thursday, August 12, 2004 12:16 AM Subject: Re: Question > Dag, > > If you want to execute python-type statements, then you will want to use > eval(). However, if your input is limited to smaller expressions, you > can parse the input into pieces and then interpret them. > > So, what I'm saying is that you need to provide more information. What > subset of eval's functionality do you need? > > Regards, > -Shane Holloway > > Dag Hansteen wrote: > > I make a GUI calculator in wxPython. > > How can I do the following without having to use eval?: > > > > def OnCalc(self, event): > > try: > > regnestykke = self.formel.GetValue() > > svar = eval(regnestykke) > > svar = str(svar) > > self.answer.SetValue(svar) > > except: > > self.answer.SetValue("Error! Check Syntax!") > > > > """ > > self.formel is defined as wxTextCtrl for the input from user to be > > calculated > > self.answer is defined as wxTextCtrl for the answer of the users input > > """ > > > From sross at connectmail.carleton.ca Wed Aug 11 19:56:00 2004 From: sross at connectmail.carleton.ca (Sean Ross) Date: Wed, 11 Aug 2004 19:56:00 -0400 Subject: Set, Mark, and Apply Decoration Message-ID: <8mySc.15584$a65.742069@news20.bellglobal.com> Set, Mark, and Apply Decoration Provide a means to set the decoration that will be applied to all marked functions (and maybe classes) within a scope (module, class, or function). For example purposes, I will use a decor object that would presumably be made available in each scope (via locals, perhaps). I'll say that it has (atleast[*]) a method set() with the following signature: def set(self, *decorators, **attributes): ... This method could be used to set/reset the decor, 0 to n times, within a given scope. The decor of one scope would only be applicable within itself and, perhaps, within its nested scopes. In this way, you could define a region(s) wherein the same decoration(s) could be applied to marked functions - there would be no need to repeat the decoration declarations for functions that share the same decor. The functions to be decorated (using the current decor) would be marked. This demarcation could be done by a symbol or by a keyword. E.g., ' def foo():' OR 'def foo():' OR 'def foo() :' Where can be replaced by whatever is deemed the least objectionable symbol or keyword. For example purposes, I'll use 'def *foo():'. I'll give an example, now, showing this proposal side by side with the current decoration scheme: # current scheme # proposed scheme class A(object): class A(object): # static methods # static methods @staticmethod decor.set(staticmethod) def f(): def *f(): pass pass @staticmethod def *g(): def g(): pass pass ... ... ... # undecorated # undecorated def h(): def h(): pass pass # class methods # class methods @classmethod decor.set(classmethod) def i(): def *i(): pass pass @classmethod def *j(): def j(): pass pass ... ... ... # garish # garish D = compose(A,B,C, decor.set(A,B,C, funcattrs(d='d', d='d',e='e',f='f' e='e',f='f')) def *k(): @D pass def k(): def *l(): pass pass @D ... def l(): ... pass ... NOTE: That garish one is *much* worse if you don't use function composition. [*] You might want a way to clear the decor, or a way to add or remove decorations without resetting the entire decor, or a way to ask what the current decor is, if any. From aahz at pythoncraft.com Fri Aug 6 17:05:43 2004 From: aahz at pythoncraft.com (Aahz) Date: 6 Aug 2004 17:05:43 -0400 Subject: Queue qsize = unreliable? References: Message-ID: In article , Ames Andreas (MPA/DF) wrote: > >I've got one: If you have the special situation that there is only a >single consumer with potentially multiple suppliers (or similarly if >you have it the other way around), you could implement the consumer in >a non-blocking manner. Then it's not that important to get "the exact >current size" which would still be unreliable but it is important to >have a reliable empty method (or rather !empty() and full() are >reliable in this situation). I think Queue is reliable in this >respect but to get it additionally non-blocking you will have to roll >your own queue. Try reading the Queue docs -- there IS a non-blocking Queue already. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From __peter__ at web.de Mon Aug 16 16:40:43 2004 From: __peter__ at web.de (Peter Otten) Date: Mon, 16 Aug 2004 22:40:43 +0200 Subject: Simple exceptions question References: Message-ID: Nick Jacobson wrote: > Say I have a function foo that throws an IndexError exception, and I > want to handle it: > > def foo(a, b, c): > print a[10], b[10], c[10] #, etc. > > def main(): > #define vars > try: > foo(a, b, c) > except IndexError: > print "Accessed array ", x, " out of bounds!" #??? > > When the exception is thrown, I don't know what triggered it! a, b, > or c? > > I could put a series of if statements in the except clause, but that > defeats the whole purpose of having the exception, right? Is there a Not necessarily. If you expect the IndexError to be rare you could easily afford the extra time to detect the source of the error. > better way? The problems I see with your approach: You are interested in the details of a failure that happens in another function. That breaks the abstraction and I'd rather invent a custom Exception. You wrap multiple points of failure into one try block when you are interested in the exact source of failure. foo() can "semi-fail", i. e. start printing something and then choke. Here is how I would do it: class FooError(Exception): pass def foo(a, b, c): try: a = a[10] except IndexError: raise FooError("a out of bounds") try: b = b[10] except IndexError: raise FooError("b out of bounds") try: c = c[10] except IndexError: raise FooError("c out of bounds") print a, b, c def main(): try: foo(*map(range, [11, 11, 5])) except FooError, e: print "Problem in foo():", e main() Peter From stefan at eischet.com Wed Aug 11 16:30:50 2004 From: stefan at eischet.com (Stefan Eischet) Date: Wed, 11 Aug 2004 22:30:50 +0200 Subject: Rather than decorators, how about sections? In-Reply-To: <411a6b9d$0$13688$636a15ce@news.free.fr> References: <1C74C038-EBB6-11D8-8889-000A95857E5C@eischet.com> <411a6b9d$0$13688$636a15ce@news.free.fr> Message-ID: <55C5E32E-EBD5-11D8-8889-000A95857E5C@eischet.com> Hi. On 11.08.2004, at 20:55, Christophe Cavalaria wrote: > Paul Morrow wrote: > >>> class Foo(object): >>> def spam(Foo): >>> print "Class Method" > > What is that ? It's ugly, it's a name alias and it'll be incredibly > confusing when classmethods are inherited, which is exactly the most > common > use case for classmethods. Right, I don't even like it myself, but I still like it better than the pie for daily work. How about using "class" as a first parameter? Even uglier, I fear. You cut the good part of my post, I think ;-) >> I like it! It's simple, clear, ... Why isn't this the hands-down best >> solution? Why do we want to be more verbose than necessary? > > It isn't a solution. It only "resolves" the problem for staticmethod > and > classmethod which are only a very small part of what we do/want to do > with > decorators. And IMHO this is a part you should keep your ugly pies out of, because they're suggesting that something special is going on, though it's just a static method you're defining. I was only referring to static methods and class methods, and since I don't see no use in decorators for my daily work (which does NOT mean they won't help many people!), I won't argue about other uses. If you really think it's necessary to have special syntax for caching return values, for checking parameter types etc, you're welcome, even if I personally doubt the usefullness of that stuff - you can still cache results *in your method*, for example. Or will we decorate our methods so much that they all resolve to a single "pass" instruction in the body? Some pie decorator examples look like the function body, stacked on top of the def line. *That* is ugly. ;-) For common stuff like static methods, I do still think decorators are overkill and the wrong way to go. >> I wonder if there are people out there who've chosen something other >> than *self* for the 1st arg (shame on them if they did! ) who's >> code this would break. I've never understood why we didn't require >> that >> it be called self in the first place --- why give them more than one >> way >> to do *that*? > > Well, it might seem strange but : > - It will break a lot of code which use a name different than self for > the > first argument Right. Starting with the usual Python tutorials and lots of books, I trained myself not to use other first args than self for normal methods *as they all suggest*. Perhaps self should've been a keyword from the start? > - It'll break all existing classmethods I didn't say "get rid of the old way of doing def m(x); m=classmethod(m);", so I don't think it would break any existing classmethod. When @decorators are in 2.4, will classmethod() and staticmethod() be removed at the same time? That would also break each and every legacy classmethod, wouldn't it? > - It'll break code that binds arbitrary functions as a member > function. You > can't do things like that anymore : > >>>> def f(s): >>>> print "Hi, I'm function f" >>>> class Klass: >>>> doIt = f >>>> Klass().doIt() Okay, this might break, depending on how all this gets implemented. I wasn't even aware that this worked, perhaps because I'm usually restricting myself to a *very* obvious subset of Python. (My general rule is: I might be hit by a bus tomorrow, so a poor Java programmer might need to learn to read my code very quickly. I try to never write stuff that breaks this rule.) How would you solve this problem with decorators, btw? class Klass: @stuff doIt = f ? If there was a rule that assigned functions in the class body (doIt=f) default to normal methods whatever their first arg is called, would that be okay? After all, that is how it works right now. Stefan // stefan at eischet.com // From steven.bethard at gmail.com Thu Aug 19 18:28:26 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 19 Aug 2004 22:28:26 +0000 (UTC) Subject: Alternative decorator syntax decision References: Message-ID: David Fraser sjsoft.com> writes: > > J2 L L > I second that. Steve From squirrel at WPI.EDU Wed Aug 4 15:59:39 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Wed, 4 Aug 2004 15:59:39 -0400 Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) In-Reply-To: References: <10h24oace15n97a@news.supernews.com> Message-ID: On 4 Aug 2004, Nick Vargish wrote: > I just don't know where else to voice my opinion on this matter, but I > absolutely hate the new decorator syntax. I wish PEPs had a method through which votes could be cast, for or against the PEP (or parts of it), not unlike Bugzilla bugs. At least then we'd have an easier and more organized way to give the BDFL some democratic input. Either way, I really wish he would hold off on decorators until there's a consensus on them, rather than forcing them in amidst all the disagreements surrounding them. From ayose.cazorla at hispalinux.es Thu Aug 19 20:20:43 2004 From: ayose.cazorla at hispalinux.es (Ayose) Date: Fri, 20 Aug 2004 01:20:43 +0100 Subject: speed In-Reply-To: References: Message-ID: <20040820002042.GA6711@setepo.gotdns.org> Hi, On Thu, Aug 19, 2004 at 03:37:26PM +0200, Peter Kleiweg wrote: > > I implemented a lexer in Pylly and compared it to the version I > had written in Flex. Processing 219062 lines took 0.9 seconds in > C (from Flex), and 5 minutes 54 second in Python (from Pylly), a > ratio of 393 to 1. > > Is this normal for Python, or does Flex produce better parsers > than Pylly? I have been looking at the code produced by Flex to > see if I could translate it to Python automaticly. But it has a > lot of goto statements, and I haven't figured out how to > translate those to Python efficiently. Don't try to translate the generated code to python. Python code is (almost) always slower than C code, because C is converted into machine code, and Python has to be interpreted by the VM. Besides, python does a lot of checks. Try with PLY, . If you have experience with flex/yacc in C, this module should be easy to use. You can also play with Psyco (a JIT compiler for x86) or even with Pyrex. But, IMHO, if you has to process very big files, don't do it with python. Instead, write a simple C-module, which uses your Flex parser and creates python objects with that information. It should be trivial if you have experience with the C API. :-) > > What are the average times used for text processing of Python > compared to C? > IMO, Python is a powerful language to do almost everything, but in some cases it is bad. One of this cases is intensive computing (like parsing a big file). Use the correct tool =) -- Ayose Cazorla Le?n Debian GNU/Linux - setepo From ivoras at __geri.cc.fer.hr Sat Aug 7 17:10:28 2004 From: ivoras at __geri.cc.fer.hr (Ivan Voras) Date: Sat, 07 Aug 2004 23:10:28 +0200 Subject: psyco out of memory In-Reply-To: References: Message-ID: Christian Tismer wrote: > Michael Hudson wrote: > >> Ivan Voras writes: >> >> >>> I have this simple *dumb* benchmark-like program: >>> >>> #import psyco > > > It crashes here, right? yes. -- What part of "Ph'nglui mglw'nath Cthulhu R'lyeh wgah'nagl fhtagn" don't you understand? From export at hope.cz Tue Aug 17 03:07:50 2004 From: export at hope.cz (Lad) Date: 17 Aug 2004 00:07:50 -0700 Subject: News server(NNTP library) and Python Message-ID: <81a41dd.0408162307.3eb1ea36@posting.google.com> I have a program that can send posts to a news server.The problem is that I must find a free usenet(news) server that allows posting, which is not easy. For this reason I would like to make a modification in my program so that the program can act in a similar way how real news server, that is to spread the new posts to another news server. But I do not have much knowledge about the way how news server chooses another news server to send it's new posting. Can anybody give me a hint( idea)? Thanks Lad From mensanator at aol.com Thu Aug 26 22:59:36 2004 From: mensanator at aol.com (mensanator at aol.com) Date: 26 Aug 2004 19:59:36 -0700 Subject: about presicion Message-ID: Ali wrote: > I was wondering if it was posible to get very good presicion. I mean > like to the to the 100 th or more decimal place. if so how? Get the gmpy module. >>> import gmpy >>> fn = gmpy.mpf(3**1996) >>> fd = gmpy.mpf(3**2000) >>> s = fn/fd + 1 >>> gd = gmpy.fdigits(s,10,100) >>> print gd 1.012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679e0 >>> From rmkrauter at yahoo.com Wed Aug 18 01:05:13 2004 From: rmkrauter at yahoo.com (Rich Krauter) Date: Wed, 18 Aug 2004 01:05:13 -0400 Subject: Piping stdout to Python callable In-Reply-To: <4122DFE3.7060407@yahoo.com> References: <4122DFE3.7060407@yahoo.com> Message-ID: <4122E389.7060906@yahoo.com> Rich Krauter wrote: > [silly post snipped] Oh, duh. You you said you need to invoke the code in the if __name__ == '__main__': part of the code. Sorry, I saw your post yesterday and didn't register that then. Obviously my suggestion doesn't help you. Well, unless A.py looks something like def main(): ... ... if __name__ == '__main__: main() Rich From ast-python-list at treibsand.com Wed Aug 18 11:00:29 2004 From: ast-python-list at treibsand.com (Axel Steiner) Date: Wed, 18 Aug 2004 17:00:29 +0200 Subject: age of Python programmers In-Reply-To: References: Message-ID: <20040818150029.GH20829@chronix.treibsand.com> > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... 22....started programming with 15 (Perl) ... -- $|=1;@a=(a..z,' ','!',"\n");@n=(9,20,19,27,20,15,1,19,20,5,4,28, 29);for($i=10;$i>0;$i--){print$i;sleep(1);for("\b",' ',"\b") {print$_ x length ($i);}}foreach$e(@n){print$a[$e-1];}print$a[28]; PGP-Fingerprint: 34A0 EF34 5033 14BE B7C3 D857 6FBD 9AE5 7C09 6C6A From mauriceling at acm.org Tue Aug 3 19:44:15 2004 From: mauriceling at acm.org (Maurice Ling) Date: Wed, 04 Aug 2004 09:44:15 +1000 Subject: Call for Grant Proposals In-Reply-To: References: Message-ID: <4110234F.1080004@acm.org> Thanks for the reminder that it will stay in mail folders for a "LOOONG" time. I think I need to apologize for it. The fact here is that the wordings of the call for proposal is not concise and instead on looking at the wordings clearly and suggesting better wordings, everyone seems to be only interested in attacking the open source vs. closed source of the problem, which might just be a minor problem here. If only open sourced projects are logically funded, then by changing the words, "The Python Software Foundation is seeking grant proposals for projects related to the further development of Python, Python-related technology, and educational resources." to "The Python Software Foundation is seeking grant proposals for projects related to the further open-sourced development of Python, Python-related technology, and educational resources." will solve the problem. The crucial issues here are in my other questions that everyone convienently forgot, such as, what constitutes complete failure or partial failure of the project? Is not delivering a single deliverable account for complete failure? And what are the penalties? I can't imagine that if you had been granted a grant for an open sourced development in python and was not told way in advanced that a delay in delivering a deliverable will result in you being forfeited the rest of the grant money and will have to pay back 150% of all the money you had received from the grant, until you had accepted the grant and working on the project? There are more important issues here to solve than an argument between open and close source development. Maurice Michael Sparks wrote: >>In either sense, I hate to think that I may eventually force >>PSF to give me a grant for close sourced project. >> >> > >*Force* a registered charity to give you money ? > >*FORCE* ? > >I doubt I'm the only one **utterly disgusted** by that apparent attitude. > >Consider what you say before you send things - you've just stated the >moral equivalent of mugging a nun, and now it's on record in google and >mailing lists and in everyone's mail folders for a LOOONG time to come. > >The only positive things you've done here is remind me that I should >contribute to the PSF, and I sincerely hope 2 things a) that only OSS >projects get financed, since they have very few ways of getting financed >otherwise b) that some project like Star Killer gets financed to finish >off what's necessary - open or closed that project will be a boost to >many, many other projects. (I really hope they've applied) > >If it's closed however in the long term its net value is zero. (Much like >much closed software I've paid for over the years) > > >Michael. > > > > -------------- next part -------------- A non-text attachment was scrubbed... Name: mauriceling.vcf Type: text/x-vcard Size: 155 bytes Desc: not available URL: From a at b.com Sun Aug 15 07:12:04 2004 From: a at b.com (wonder) Date: Sun, 15 Aug 2004 19:12:04 +0800 Subject: A email.cgi script Message-ID: Hi, I would like to write a python script that can be used in my website for other people whoever browse my webside to send an email using my smtp server. Is there any sample python script can do that? Here is my python script, but it does not display To and From editbox in the webpage for user type in their addresses: #!/usr/bin/python import smtplib, cgi, string form = cgi.FieldStorage() # Change the lines below to specify the TO and # FROM addresses toaddr = 'dest at abc.com' fromaddr = '' # Special form fields used by the email.cgi # script ack_url = form.getvalue('ack_url',None) ack_text = form.getvalue('ack_text','Your submission was successful') subject = form.getvalue('subject', '') # form fields to skip to_skip = ['ack_url', 'ack_text', 'subject', 'to'] # create the email headers msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (fromaddr, toaddr, subject) for key in form.keys(): if string.lower(key) in to_skip: continue msg = msg + "%s: %s\n\n" % (key, form.getvalue(key)) server = smtplib.SMTP('mail.xyx.com') server.set_debuglevel(0) server.sendmail(fromaddr, toaddr, msg) server.quit() if ack_url: print "Location: %s" % (ack_url) print else: print "Content-type: text/html" print print ack_text From tjreedy at udel.edu Tue Aug 31 16:57:10 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 31 Aug 2004 16:57:10 -0400 Subject: python 2 coercion References: Message-ID: >What happens (on the C level) if the python interpreter executes >a statement like >if == None: For Jython, there is no C level ;-) For CPython, the beginning point for such a question is the byte code (this is 2.2, but should be same in 2.3, but you can check): >>> def equalNone(a): return a == None ... >>> import dis >>> dis.dis(equalNone) 0 SET_LINENO 1 3 SET_LINENO 1 6 LOAD_FAST 0 (a) 9 LOAD_GLOBAL 1 (None) 12 COMPARE_OP 2 (==) 15 RETURN_VALUE 16 LOAD_CONST 0 (None) 19 RETURN_VALUE Now go to ceval.c, find the COMPARE_OP branch in the master switch statement, and see what gets called. Note that at this point, the interpreter has no idea what is bound to 'a'. Terry J. Reedy From in.aqua.scribis at nl.invalid Sun Aug 29 06:49:27 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Sun, 29 Aug 2004 12:49:27 +0200 Subject: my first class: Args In-Reply-To: <41315680$1@nntp0.pdx.net> References: <4130cf9d@nntp0.pdx.net> <41315680$1@nntp0.pdx.net> Message-ID: Scott David Daniels schreef: > I missed the sys.argv -- here is a sketch of a slightly better rewrite: > > > class Args: > > """...""" > > def __init__(self,usage='Usage: %(progname)s [opt...] [file...]'): > > "init, usage string: embed program name as %(progname)s" > > self.progname = os.path.basename(sys.argv[0]) > > ... > > self._argv = sys.argv[1:] > class Args: > """...""" > def __init__(self, progname, args, > usage='Usage: %(progname)s [opt...] [file...]'): > "usage string: embed program name as %(progname)s" > self.progname = progname > self._argv = args > ... > > > > if __name__ == '__main__': > > ... > > def demo(progname, args): > a = Args(progname, args, > 'Usage: %(progname)s [-a value] [-b value] [-c] word [file...]') > ... > > if __name__ == '__main__': > demo(sys.argv[0], sys.argv[1:]) This goes against the purpose of the class: to take care of as much of the overhead of script writing as possible. So I can simply do this: import args a = Args() for line in a: do_something_with(line) Or with some extras: import args a = Args() for line in a: try: do_something_with(line) except SomeError: a.error("something wrong") In the last example, I would get filename and line number of the input were the error occured, in the format understood by the 'make' parser of Emacs. -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From aleaxit at yahoo.com Fri Aug 27 12:06:31 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 27 Aug 2004 18:06:31 +0200 Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> <1gj4fb5.607xsc51izh8N%aleaxit@yahoo.com> <7xllg25lkt.fsf@ruckus.brouhaha.com> <1gj4u3a.12ttba9fynd6uN%aleaxit@yahoo.com> <1gj5bp4.qhup8tldmvebN%aleaxit@yahoo.com> <1gj6cfv.nv3fziwoc81nN%aleaxit@yahoo.com> Message-ID: <1gj6pih.6lolffzvm5ucN%aleaxit@yahoo.com> Antoon Pardon wrote: ... > > Do I really need to point out that a.extend(b) doesn't work for tuples > > and strings, while a+=b works as polymorphically as feasible on all > > these types? > > That extend doesn't work for strings and tupples is irrelevant. > for those types that have an extend a.extend(b) is equivallent > to a+=b It's perfectly relevant, because not all types have extend and += works para-polymorphically anyway. > In other words there is no reason to have an extend member for > lists. If lists were being designed from scratch today, there would be a design decision involved: give them a nicely named normal method 'extend' that is a synonym for __iadd__, so that the callable bound method can be nicely extracted as 'mylist.extend' and passed around / stored somewhere / etc etc, or demand that people wanting to pass the callable bound method around use 'mylist.__iadd__' which is somewhat goofied and less readable. I'm glad I do not have to make that decision myself, but if I did I would probably tend to err on the side of minimalism -- no synonyms. However, lists had extend before += existed, so clearly they kept it for backwards compatibility. Similarly, dicts keep their method has_key even though it later became just a synonym for __contains__, etc etc. If the point you're trying to make here is that Python chooses to be constrained by backwards compatibility, keeping older approaches around as new ones get introduced, I do not believe I ever heard anybody arguing otherwise. You may know that at some unspecified time in the future a Python 3.0 version will be designed, unconstrained by strict needs of backwards compatibility and specifically oriented to removing aspects that have become redundant. Guido has stated so repeatedly, although he steadfastly refuses to name a precise date. At that time every aspect of redundancy will be carefully scrutinized, extend versus _iadd__ and has_key versus __contains__ being just two examples; any such redundancy that still remain in Python 3.0 will then have done so by deliberate, specific decision, rather than due to the requirements of backwards compatibility. A "greenfield design", an entirely new language designed from scratch, has no backwards compatibility constraints -- there do not exist million of lines of production code that must be preserved. One can also decide to develop a language without special regards to backwards compatibility, routinely breaking any amount of working code, but that would be more appropriate to a language meant for such purposes as research and experimentation, rather than for writing applications in. > furthermore a+=b doesn't work polymorphically feasable because > the result of > > a=c > a+=b > > is different depending on the type of c. Indeed it's _para_-polymorphic, exactly as I said, not fully polymorphic. In many cases, as you code, you know you have no other references bound to the object in question, and in that case the polymorphism applies. > > > It should be pretty obvious, I think. So, if you want to > > get an AttributeError exception when 'a' is a tuple or str, a.extend(b) > > is clearly the way to go -- if you want para-polymorphic behavior in > > those cases, a+=b. Isn't it obvious, too? > > No it isn't obvious. No design is so stupid that you can't find > an example for it's use. That you have found a specific use > here doesn't say anything. I can silently suffer MOST spelling mistakes, but please, PLEASE do not write "it's" where you mean "its", or viceversa: it's the most horrible thing you can do to the poor, old, long-suffering English language, and it makes me physically ill. Particularly in a paragraph as content-free as this one of yours that I've just quoted, where you're really saying nothing at all, you could AT LEAST make an attempt to respect the rules of English, if not of logic and common sense. On to the substance: your assertion is absurd. You say it isn't obvious that a.extend(b) will raise an exception if a is bound to a str or tuple, yet it patently IS obvious, given that str and tuple do not have a method named 'extend'. Whether that's stupid or clever is a completely different issue, and one which doesn't make your "No it isn't obvious" assertion any closer to sanity one way or another. > > in-place mutation. *IN GENERAL*, the effects of a+=b and a=a+b may > > differ, though in specific cases ('a' being immutable, or of a mutable > > type which strangely chooses to define __add__ but not __iadd__) they > > may be identical. > > which makes them para-polymorphic infeasable. I don't know what "infeasable" means -- it's a word I cannot find in the dictionary -- and presumably, if it means something like "unfeasible", you do not know what the construct 'para-polymorphic' means (it means: polymorphic under given environmental constraints -- I constructed it from a common general use of the prefix 'para'). > > Like for a+b vs b+a: in general they may differ, but > > they won't differ if the types involved just happen to have commutative > > addition, of if a and b are equal or identical objects, i.e., in various > > special cases. > > > > "You get different effects *in general*" does not rule out that there > > may be special cases (immutable types for one issue, > > If those specific cases can be half of the total cases I wouldn't > call the not specific cases *in general*. There is no sensible way to specify how to count "cases" of types that have or don't have commutative addition -- anybody can code their own types and have their addition operation behave either way. Therefore, it makes no sense to speak of "half the total cases". Still, the English expression "in general" is ambiguous, as it may be used to mean either "in the general case" (that's how it's normally used in mathematical discourse in English, for example) or "in most cases" (which is how you appear to think it should exclusively be used). > The point is that there is a difference between what is obvious in > general and what is obvious within a certain tradition. If python Absolutely true: the fact that a cross like + stands for addition is only obvious for people coming from cultures in which that symbol has been used to signify addition for centuries, for example. There is nothing intrinsical in the graphics of the glyph '+' that makes it 'obviously' mean 'addition'. > would limit itself to only one obvious way for those things that > are obvious in general that would be one way. I cannot think of _any_ aspect of a programming language that might pertain to 'things that are obvious in general' as opposed to culturally determined traits -- going left to right, using ASCII rather than other alphabets, using '+' to indicate addition, and so on, and so forth. Please give examples of these 'things that are obvious in general' where you think Python might 'limit oneself to only one obvious way'. > But here you are defending one thing that is only obvious through > tradition, by pointing out that something that hasn't had the time > to become a tradition isn't obvious. When there is one operator to do one job, _in the context of that set of operator_, it IS obviously right to use that operator, rather than using two operators which, combined, give the same effect. I claim that, no matter what symbols you use to represent the operators, "TO a, ADD b" is 'more obvious' than "FROM a, SUBTRACT the NEGATIVE of b", because the former requires one operator, binary ADD, the latter requires two, binary SUBTRACT and unary NEGATIVE. I do not claim that this is necessarily so in any culture or tradition whatsoever: I do claim it is true for cultures sufficiently influenced by Occam's Razor, "Entities are not to be multiplied beyond necessity", and that the culture to which Python addresses itself is in fact so influenced. ((If you feel unable to relate to a culture influenced by Occam's Razor, then it is quite possible that Python is in fact not suitable for you)). > Personly I don't find the use of "+" as a concat operator obvious. > There are types for which both addition and concatenation can be > a usefull operator. Using the same symbol for both will make > it just that much harder to implement such types and as a result > there is no obvious interface for such types. True, if I were designing a language from scratch I would surely consider the possiibly of using different operators for addition and concatenation, and, similarly, for multiplication and repetition -- there are clearly difficult trade-offs here. On one side, in the future I may want to have a type that has both addition and concatenation (presumably a numeric array); on the other, if concatenation is a frequent need in the typical use cases of the language it's hard to think of a neater way to express it than '+, in this culture (where, for example, PL/I's concatenation operator '||' has been appropriated by C to mean something completely different, 'logical or' -- now, using '||' for concatenation would be very confusing to a target audience that is more familiar with C than with PL/I or SQL...). Any design choice in the presence of such opposite constraints can hardly be 'obvious' (and in designing a language from scratch there is an enormously high number of such choices to be made -- not independently from each other, either). But note that the fact that choosing to use the same operator was not an _obvious_ choice at the time the language was designed has nothing to do with the application of the Zen of Python point to 'how to concatenate two strings'. Python _is_ designed in such a way that the task "how do I concatenate the strings denoted by names a and b" has one obvious answer: a+b. This is because of how Python is designed (with + between sequences meaning concatenation) and already-mentioned cultural aspects (using a single operator that does job X is the obvious way in a culture influenced by Occam's Razor to do job X). All alternatives require multiple operations ('JOIN the LIST FORMED BY ITEMS a and b' -- you have to form an intermediate list, or tuple, and then join it, for example) and therefore are not obvious under these conditions. This is even sometimes unfortunate, since for piece in makepieces(): bigstring += piece is such a performance disaster (less so in Python 2.4, happily!), yet people keep committing it because it IS an "attractive nuisance" -- an OBVIOUS solution that is not the RIGHT solution. That it's obvious to most beginners is proven by the fact that so many beginners continue to do it, even though ''.join(makepieces()) is shorter and faster. I once hoped that sum(makepieces()) could field this issue, but Guido decided that having an alternative to ''.join would be bad and had me take the code out of 'sum' to handle string arguments . Note that I do not _whine_ about it, even though it meant giving up both one of my pet ideas _and_ some work I had already done, rather I admit it's his call... and I use his language rather than making my own because over the years I've learned that _overall_ his decisions make a better language than mine would, even though I may hotly differ with him regarding a few specific decisions out of the huge numbers needed to build and grow a programming language. If I didn't think that, I wouldn't use Python, of course: besides the possibility of making my own languages, there are many truly excellent very high level languages to choose among -- Lisp, Smalltalk, Haskell, ML of many stripes, Erlang, Ruby. I think I could be pretty happy with any of these... just not quite as happy as I am with Python, therefore it is with Python that I stick! > >> If someway of doing it > >> is usefull then I think it should be included and the fact that > >> it introduces more than one obvious way to do some things shouldn't > >> count for much. > > > > This is exactly Perl's philosophy, of course. > > No it isn't. Perl offers you choice in a number of situations > where a number of the alternatives don't offer you anything usefull. > unless a way to do things differently and eliminate a few characters. And for some people eliminating some characters is very important and makes those alternatives preferable and useful to them, according to their criteria. > >> Sure you shouldn't go the perl-way where things seemed to have > >> been introduced just for the sake of having more than obvious way > >> to do things. But eliminating possibilities (method chaining) > >> just because you don't like them and because they would create > >> more than one obvious way to do things, seems just as bad to > >> me. > > > > If a language should not eliminate possibilities because its designer > > does not like those possibilities, indeed if it's BAD for a language > > designer to omit from his language the possibilities he dislikes, what > > else should a language designer do then, except include every > > possibility that somebody somewhere MIGHT like? > > So if you think it is good for a language designer to omit what > he dislikes. Do you think it is equally good for a language > designer to add just because he likes it. And if you think so, > do you think the earlier versions of perl, where we can think > the language was still mainly driven by what Larry Wall liked, > was a good language. Do you know how to use the question mark punctuation character? It's hard to say whether you're asking questions or making assertions, when your word order suggests one thing and your punctuation says otherwise. "You know a design is finished, not when there is nothing left to add, but when there is nothing left to take away" (Antoine de Saint Exupery, widely quoted and differently translated from French). There is no necessary symmetry between adding features and avoiding them. But sure, it's a designer's job to add what he likes and thinks necessary and omit what he dislikes and thinks redundant or worse. I met Perl when Perl was at release 3.something, and by that time it was already florid with redundancy -- I believe it was designed that way from the start, with "&foo if $blah;" and "if($blah) {&foo;}" both included because some people would like one and others would like the other, 'unless' as a synonym of 'if not' for similar reasons, etc, etc, with a design principle based on the enormous redundancy of natural language (Wall's field of study). ((However, I have no experience with the very first few releases of Perl)). At the time when I met Perl 3 I thought it was the best language for my needs under Unix given the alternatives I believed I had (sh and its descendants, awk -- Rexx was not available for Unix then, Python I'd never heard of, Lisp would have cost me money, etc, etc), which is why I used it for years (all the way to Perl 4 and the dawn of Perl 5...) -- but, no, I never particularly liked its florid redundancy, its lack of good data structures (at the time, I do understand the current Perl is a bit better there!), and the need for stropping just about every identifier. Why do you ask? I do not see the connection between my opinion of Perl and anything else we were discussing. > > I can understand that a designer has to make choices, but > if the designer can allow a choice and has no other arguments > to limit that choice than that he doesn't like one alternative > then that is IMO a bad design decision. Ah, you're making a common but deep mistake here: the ability to DO something great, and the ability to explain WHY one has acted in one way or another in the process of doing that something, are not connected. Consider a musician composing a song: the musician's ability to choose a sequence of notes that when played will sound just wonderful is one thing, his ability to explain WHY he's put a Re there instead of a Mi is quite another issue. Would you say "if a musician could have used a note and has no other arguments to omit that note than that he doesn't like it then than is a bad music composition decision"? I think it's absurd to infer, from somebody's inability to explain a decision to your satisfaction, _or at all_, that the decision is bad. "Those who can, do, those who can't, explain" may come closer (except that there _are_ a few musicians, language designers, architects, and other creative types, who happen to be good at both doing and explaining, but they're a minority, I believe). I've never made any claim about Guido's skill as an explainer or debater, please note. I do implicitly claim he's great at language design, by freely choosing to use the language he's designed when there are so many others I could just as freely choose among. (_Your_ use of Python, on the other hand, is obviously totally contradictory with your opinion, which you just expressed, that it's a horribly badly designed language, since its designer is not good at argumenting about each and every one of the uncountable decisions he's made -- to disallow possibility a, possibility b, possibility c, and so on, and so forth). > > target = mydict[foo].bar[23].zepp > > target.pop(xu1) > > target.sort() > > target.pop(xu3) > > target.reverse() > > target.pop(xu7) > > I find this a questionable practice. What if you need to make the list > empty at some time. The most obvious way to do so after a number of > such statements would be: > > target = [] > > But of course that won't work. That would be 'obvious' only to someone so totally ignorant of Python's most fundamental aspects that I _cringe_ to think of that someone using Python. By just asserting it would be obvous you must justify serious doubts about your competence in Python use. Assigning to a bare name NEVER mutates the object to which that name previously referred to, if any. NEVER. Therefore, thinking of assigning to a bare name as a way of mutating an object is not obvious -- on the contrary, it's absurd, in Python. One obvious way is: target[:] = [] "assigning to the CONTENTS of the object" does mutate it, and this works just fine, of course. Unfortunately there is another way, also obvious: del target[:] "deleting the CONTENTS of the object". This will also work just fine. Alas, it's only _preferable_ that the obvious way be just one, and we cannot always reach the results we would prefer. So, your assertion that this is a questionable practice proves untenable. But then, as this thread shows, _most_ of your assertions are untenable, so you're clearly comfortable with the fact. I guess it goes well with freely choosing to use a language which you consider so badly designed! > If a language goes so far as to make a particular coding impossible > while that would have been the prefered coding style for most of > the project members then such a limitation can hinder the decision > to agree upon a certain style instead of helping. And in this case the team should definitely choose another language, just like you should do instead of wasting your time using Python, and yours AND ours whining against it. > I also think this attitude is appalling. Python is for consenting > adults I hear. But that doesn't seem to apply here, as python > seems to want to enforce a certain coding style instead of > letting consenting adults work it out among themselves. Python most definitely does not multiply entities beyond necessity in order to allow multiple equivalent coding styles -- it's that Occam Razor thing again, see. If a team wants enormous freedom of design, short of designing their own language from scratch, they can choose among Lisp, Scheme, Dylan -- all good languages with enormously powerful MACRO systems which let you go wild in ways languages without macros just can't match. Of course, it's likely that nobody besides the original team can maintain their code later -- that's the flip side of that freedom... it can go all the way to designing your own language, and who else but you will know it so they can advise, consult, maintain, and so on, once you choose to avail yourself of that freedom? Python values uniformity -- values the ability of somebody "from outside the team" read the code, advise and consult about it, and maintain it later, higher than it values the possibility of giving the team *yet another way* to design their own language... why would you NEED another Lisp? There IS one, go and use THAT (or if you can't stand parentheses, use Dylan -- not far from Lisp with different surface syntax after all). I also appreciate this uniformity highly -- it lets me advise and consult all manners of teams using Python, it makes my books and courses and presentations more useful to them, it lets me turn for advice and consultancy to the general community regarding my own projects and teams, all without difficulty. What could possibly be "appalling" in not wanting to be yet another Lisp, yet another Perl, and so on?! Why shouldn't there be on this Earth ONE language which makes software maintenance easier, ONE language which care more about the ease of reading others' code than about the ease of writing that code?! Now THAT absolutism, this absurd attitude of yours that wants to wipe out from the face of the Earth the ONLY language so focused on uniformity, egoless and ownerless code, community, maintenance, etc, to turn it into yet another needless would-be clone of Lisp, Perl, etc... *THAT* is truly appalling indeed! > > Great, so, I repeat: go away and design your language, one that WILL > > impress you with its design. Here, you're just waiting your precious > > time and energy, as well of course as ours. > > That you waste yours, is entirly your choice, nobody forces your hand > to reply to me. Absolutely my choice, of course. But I have a reasonable motivation, which I have already explained: there may be other readers which would be ill-served by leaving your untenable assertions, etc etc, unchallenged, when those assertions &c are so easy to tear into small bloody pieces and deserve nothing better. YOUR motivation for using a language you consider badly designed, one whose underlying culture you find APPALLING (!your choice of word!), and then spending your time spewing venom against it, is, on the other hand, totally mysterious. > > Practicality beats purity: needing to polymorphically concatenate two > > sequences of any kind, without caring if one gets modified or not, is a > > reasonably frequent need and is quite well satisfied by += for example. > > It isn't. Either you know what types the variables are and then > using a different operator depending on the type is no big deal, > or you don't know what type the variables are and then not caring > if one gets modified or not, is a disaster in waiting. Your assertion is, once again, totally false and untenable. def frooble(target, how_many, generator, *args, **kwds): for i in xrange(how_many): target += generator(i, *args, **kwds) return target Where is the "disaster in waiting" here? The specifications of 'frooble' are analogous to those of '+=': if you pass it a first argument that is mutable it will extend it, otherwise it obviously won't. Alex From cemerick at snowtide.com Mon Aug 16 07:39:02 2004 From: cemerick at snowtide.com (Chas Emerick) Date: Mon, 16 Aug 2004 07:39:02 -0400 Subject: Decorators: an outsider's perspective In-Reply-To: <20040816022635.C24B71E4005@bag.python.org> References: <20040816022635.C24B71E4005@bag.python.org> Message-ID: On Aug 15, 2004, at 10:26 PM, Paul Morrow wrote: >> I think the source of my gut reaction to the proposal you've advanced >> (aside from the conceptual action-at-a-distance violation that I >> already cited) is my past experience with Hungarian notation, where >> the name of a variable indicates its type. The comparison isn't >> totally clean cut because of the special peculiarities of Hn, but I >> think the folly that it represents is a clear warning to stay away >> from taking type information based on naming conventions. > > I don't see your point about an 'action-at-a-distance' violation. > Wouldn't that only be the case if something we do locally has side > effects that break something in another part of the application? In a previous message, I was talking about how a function declaration and that function's arguments are conceptually atomic, and that making any semantic connection between the two was conceptual action-at-a-distance. It's a stretch of the term, but the best way I had to describe it at the time. > As for the Hungarian notation, I agree that in its most abused state, > it can be a real mess for all sorts of reasons. However in Python we > do use a very lightweight form of that in the way we identify private > and semi-private methods. Ugh. I know, and it's one of the little things about python that I am not so fond of. It has the feel of something that GvM did in one of the earliest python scripts that just ended up catching on with a wider audience. It screams 'accident', not 'designed'. Please, no more of that. - Chas Emerick From davidf at sjsoft.com Thu Aug 19 04:51:23 2004 From: davidf at sjsoft.com (David Fraser) Date: Thu, 19 Aug 2004 10:51:23 +0200 Subject: Standalone Python Programs... In-Reply-To: <30260531.0408061548.283e96b1@posting.google.com> References: <-aSdndbo7ry5E47cRVn-ig@comcast.com> <41139ac9$0$65604$a1866201@newsreader.visi.com> <30260531.0408061548.283e96b1@posting.google.com> Message-ID: simo wrote: > One of the attractions of IronPython is that you can build a single > .exe (or .bin on Linux I guess?) although the user still needs the CLR > runtime installed. One of the attractions of Python is that you can build a single frozen file although the user still needs the Python interpreter installed ... David From oziko at fusiondementes.com Wed Aug 18 10:32:11 2004 From: oziko at fusiondementes.com (oziko) Date: Wed, 18 Aug 2004 09:32:11 -0500 Subject: age of Python programmers In-Reply-To: References: Message-ID: <4123686B.4080106@fusiondementes.com> I am 24 years old! Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... > > From nobody at nowhere.com Thu Aug 19 13:02:43 2004 From: nobody at nowhere.com (Fred) Date: Thu, 19 Aug 2004 19:02:43 +0200 Subject: Interface graphique pour python References: <8e16829.0408190650.3fa62d5e@posting.google.com> <2ok3isFbgtl3U1@uni-berlin.de> Message-ID: On Thu, 19 Aug 2004 12:43:55 -0400, Daniel Ellison wrote: >It looks like he actually has besion d'une application for >*constructing* a Python application. Perhaps Boa Constructor would help: Hard to tell, even though I'm a native speaker :-) I'm currently looking at PythonWin to avoid having to distribute wxWidgets, but it looks like using wxPython is less hassle. As for VB- or Delphi-like GUI builders, I launched a threat recently in this ng which the original poster could read for a list of available tools (short answer: QT Designer was the closest equivalent.) Fred. From tjreedy at udel.edu Sat Aug 21 03:35:25 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 21 Aug 2004 03:35:25 -0400 Subject: Overriding logical operators? References: <59e9fd3a04082022392b749256@mail.gmail.com> Message-ID: "Andrew Durdin" wrote in message news:59e9fd3a04082022392b749256 at mail.gmail.com... > I noticed that, although there are special methods for most operators, > they are conspicuously absent for the logical "or" and "and". I'm > guessing that the reason for this is that these operators > short-circuit if their first operand answers the whole question? If you think of a op b as being an alternate, abbreviated syntax for the function call op(a,b), then short-circuiting 'and' and 'or' are not really operators. Various Lisp dialects have various terms, such as 'special form' for syntax that looks like a normal function call but isn't. I think we need a special term in Python also, such as 'pseudo-op' or 'syntax operator' to flag 'and' and 'or' as importantly different from regular operators. Terry J. Reedy From vwehren at home.nl Fri Aug 6 02:18:21 2004 From: vwehren at home.nl (Vincent Wehren) Date: Fri, 6 Aug 2004 08:18:21 +0200 Subject: [Python-Dev] RELEASED Python 2.4, alpha 2 References: <411231C8.3020308@interlink.com.au> Message-ID: "Martin v. L?wis" schrieb im Newsbeitrag news:mailman.1196.1091715567.5135.python-list at python.org... | Anthony Baxter wrote: | > Python 2.4a2 is an alpha release. We'd greatly appreciate it if you | > could download it, kick the tires and let us know of any problems you | > find, but it is not suitable for production usage. | | The Windows installer should support upgrading from a previous Python | 2.4 installation. If you have previously installed 2.4a1, you may try | this out; please report any problems you find. | | Regards, | Martin What surprised me a little is that on Win XP I could install 2.4a2 as a user with restricted rights over a previously administrator-installed for-all-users 2.4a1 standard-paths-used installation without warnings/problems - well, except for the obvious errors writing to the registry (and yes, I tried it intentionally ;). I am not entirely on board with the MSI's capabilities, but is there a way to tell the user (before the registry errors happen), that he/she may have insufficient rights to install? -- Vincent Wehren From in.aqua.scribis at nl.invalid Tue Aug 17 18:08:26 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Wed, 18 Aug 2004 00:08:26 +0200 Subject: flex: plex? In-Reply-To: References: Message-ID: Jeff Epler schreef: > If plex uses python regular expressions, you can use the zero-length > lookahead assertion instead of flex's A/B syntax: "A(?=B)" Alas, it doesn't. -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From luismg at gmx.net Sun Aug 22 19:01:12 2004 From: luismg at gmx.net (Neuruss) Date: 22 Aug 2004 16:01:12 -0700 Subject: Python is to C as letters are to words. References: Message-ID: <278de0e.0408221501.6754d211@posting.google.com> > My nine word description of the python language. Huh? I guess you mean: "C is to Python as letters are to words" or "Python is to C as words are to letters" Am I right? From sbabbitt at commspeed.net Thu Aug 26 21:43:59 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Thu, 26 Aug 2004 18:43:59 -0700 Subject: Newbie question on dictionary!!! References: <494182a9.0408261150.a4c767f@posting.google.com> Message-ID: <1093571549.673654@news.commspeed.net> "Balaji" wrote in message news:494182a9.0408261150.a4c767f at posting.google.com... > Hello everybody... > > I want to ask a simple question. > > Suppose I have an list say g=['a','b','c','d'] > > and I have an dictionary say k={'b':20,'a':10} > > Now I want to sort this dictionary on the basis of the list and if it > doesnt find any of the element in the list then I wud like to replace > it with zero.. > > so I would like to modify k into {'a':10,'b':20,'c':0,'d':0} > > I have tried all the built in associated with dict and lists but was > not able to come up with an solution... > > Can anyone help... Dictionaries are not sortable but you can easily access the values in an sorted order, list = ['a','b','d'] dict = {'a':123,'c':456,'b':789} newdict = {} l = dict.keys() + list l.sort() for i in l: if dict.has_key(i): newdict[i] = dict[i] else: newdict[i] = 0 dict = newdict That should do it, Tom print dict[i] Tom From ramen at lackingtalent.com Wed Aug 18 15:25:21 2004 From: ramen at lackingtalent.com (Dave Benjamin) Date: Wed, 18 Aug 2004 19:25:21 -0000 Subject: age of Python programmers References: Message-ID: In article , Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... I'm 25. Been using Python for about 3 years. I started programming in BASIC on a Commodore 64 when I was about 8 years old. -- .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:. "talking about music is like dancing about architecture." From peter at engcorp.com Wed Aug 18 09:09:53 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 18 Aug 2004 09:09:53 -0400 Subject: age of Python programmers In-Reply-To: References: Message-ID: Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? My average age has been increasing steadily for years. :-( From CousinStanley at HotMail.Com Tue Aug 3 09:54:11 2004 From: CousinStanley at HotMail.Com (Cousin Stanley) Date: Tue, 03 Aug 2004 06:54:11 -0700 Subject: intersection of 2 strings References: Message-ID: <2n9jggFug56rU1@uni-berlin.de> Antoine Logean wrote: > Hi, > > What is the easiest way to get the intersection of two strings in > python (a kind a "and" operator) ? > ex: > > string_1 = > "the_car_of_my_fried_is_bigger_as_mine_but_my_girlfriend_is_more_beautifull" > > string_2 = > "my_girlfriend_is_more_beautifull_and_has_blue_eyes" > > and the intersection : > string_1 "and" string_2 = "my_girlfriend_is_more_beautifull" > > thanks for your help > Antoine .... You might try the sets module .... The following provides the intersection, but I don't know how to maintain the order from the original strings .... sk at cpq1 : /mnt/win_k/Python/py_Work/Sets $ python Python 2.3.4 (#2, Jul 5 2004, 09:15:05) [GCC 3.3.4 (Debian 1:3.3.4-2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> str_1 = "the_car_of_my_fried_is_bigger_as_mine_but_my_girlfriend_is_more_beautifull" >>> >>> str_2 = "my_girlfriend_is_more_beautifull_and_has_blue_eyes" >>> >>> list_1 = str_1.split( '_' ) >>> list_2 = str_2.split( '_' ) >>> >>> import sets >>> >>> set_1 = sets.Set( list_1 ) >>> set_2 = sets.Set( list_2 ) >>> >>> is_12 = set_1.intersection( set_2 ) >>> >>> print is_12 Set(['girlfriend', 'is', 'my', 'beautifull', 'more']) >>> -- Cousin Stanley Human Being Phoenix, Arizona From mark_bottjer at hotmail.com Thu Aug 12 19:16:22 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Thu, 12 Aug 2004 19:16:22 -0400 Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: <10hnqqm8h7b3k89@corp.supernews.com> References: <60dfb6f6.0408111846.615ee9eb@posting.google.com> <3YWdnYxLf--ObofcRVn-pw@powergate.ca> <411ba1db$1@nntp.zianet.com> <411bd3f0$1@nntp.zianet.com> <10hnqqm8h7b3k89@corp.supernews.com> Message-ID: <411bfa47$1@nntp.zianet.com> Jeff Shannon wrote: > Mark Bottjer wrote: >> FWIW, I don't object to the keyword, I object to the indented >> block. I agree that newbies will need to look either up. My only >> real concern is that certain suggested syntaxes (mostly the list or >> tuple forms) look innocuous enough that newbies may not realize >> that they've hit something new. Everything past there seems more >> and more like simple preference. > > The interesting thing here is that it seems that the reason you > dislike the indented block is the reason given for preferring it by > those people who *do* like it -- the fact that it *looks* like normal > Python. Essentially, yes. Because to me it doesn't *act* like normal Python. > Frankly, if a new feature is so radically different from the rest of > Python that it's deemed that it needs to *look* radically different > from the rest of Python for it to be understood... that, to me, > suggests that it's a feature that shouldn't exist in Python. Again, yes. In fact, I think that this is why the ternary operator finally got dropped. It just didn't fit, and the angst over trying to force it to made that clear. > All the criticisms aimed at the decorate: syntax, ISTM, apply equally > well to @pie syntax, except for the few that are based on indentation > level. Which are the only ones *I* was really trying to debate. :) BTW: "ISTM"? > And on those, *I* at least feel that it'd be preferable to pattern > decorators after existing language constructs, rather than > deliberately breaking all the patterns that Python has established. Again, agreed. It seems like we both agree that the @pie syntax doesn't follow any extant pattern. Where we seem to differ is in our opinions of how well the decorate: syntax follows those same patterns. > I see your point about it looking a bit odd that an indented block > contain only declarative statements. However, the @pie mess in front > of function defs looks, to me, to be not just odd, but downright > obfuscatory. It's *much* harder for my eyes to pick out the def and > thus the function name, and all I see is a function body dangling > from a blob of @pies. Yup. > Yes, this is personal preference, but it seems that it's a preference > shared by many people -- isn't Python supposed to fit my brain, > rather than forcing my brain into Python's shape? There seem to be many people who share a preference for each of the other options, as well. That's the problem: they all look horrible to someone. We can't seem to agree what "fits"; maybe that's a clue that the idea itself doesn't fit. > The fact that one can get used to @pie-syntax doesn't mean it's > intuitive. This argument can be used for any of the syntaxes. "Intuitive" is in the eye of the beholder. In this case, what GvR's eye beholds is all that really matters. > The fact that the feature is new doesn't mean that we need an entire > new code-layout principle. The differences between class & def, on > the one hand, and try/except & if/else on the other, don't seem to > confuse people too much. I'd rather see the same layout principle > applied in a different way than see an unprecedented and unfamiliar > layout principle used in one or two special cases. FWIW, I agree. That's why I like this option the best: class C: def c(self): meta: #declare, decorate, transform, fubar, whatever... staticmethod doc('Doc.') pass IMHO, this form passes all the of the criteria we've been debating. The only criterion it fails is that it is "inside" the function, but I don't consider that too big an issue: once you know where to look for the additional information, you'll look there. Where-ever that may be. -- Mark From nid_oizo at yahoo.com_removethe_ Fri Aug 20 03:48:56 2004 From: nid_oizo at yahoo.com_removethe_ (Nicolas Fleury) Date: Fri, 20 Aug 2004 03:48:56 -0400 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: You've been quicker than me to post "Alternative decorator syntax decision". My post doesn't appear in the newsgroup on my side, so I post it in this thread. Hi all, The part of the Python community that doesn't like @decorators needs to unite behind an alternative syntax to propose to Guido. I suggest we use this thread to try to do it. If you agree with @decorators, then I suggest you stop reading this message;) Many syntaxes have been put on http://www.python.org/moin/PythonDecorators. I suggest to fight the current @descriptors on these two points: - Less Readable. The @ character adds a new character with a magical sense. It doesn't read in english as the rest of Python. - Not Pythonic. It's a line without a block (like try/finally) that affects a following line of code. It breaks interactive shells. I suggest that the alternative syntax to be both more readable and more pythonic. Many syntaxes have been ruled out by Guido, but he seems to be open to a new keyword accessible with a "from __future__ import". Since a new keyword would make the syntax more readable (and easier to find doc about), I suggest to discuss these two alternatives, not necessarily with these keywords: Proposal 1: decorate: staticmethod def foo(a, b): ... decorate: accepts(int,int) returns(float) def bar(low, high): ... other possible keywords: predef, from, as, with This proposal has basically the advantages of @decorators with a more Pythonic approach. The main drawback is that the decorate block doesn't contain anything like normal statements, as with @decorators. Implementation already exists. Proposal 2: def foo(a,b): using staticmethod ... def bar(low, high): using accepts(int, int) using returns(float) other possible keywords: decorate, transform, with, postdef, as The pool on Wiki suggest that most people would prefer an inside def syntax. It would place decorators at the same place as docstrings, which is very Pythonic, since it's consistent with the rest of the language. The main concern is that it places information that can be important to callers far from the def. I guess the answer would be that it's not that far from the def and that sometimes the parameters names would give strong hints about the decorators. For example, even if it's not forced by the language, a method with a first parameter not named self would be strong hint to check the first line of the body to see if it's a static method, etc. I suggest to force descriptors to be before the docstring to make them as closer as possible to the def and ease finding them. (Another answer could be that scanning down from the def is not that more bad than scanning up from the def). Is there any implementation existing? My questions would be: which of these proposals do you prefer to current @decorators. Both? None? What keywords would you prefer? Do you see any that I have not listed? Do you think there's an alternative that I should have listed, even considering what have been ruled out by Guido? Regards, Nicolas From lbates at swamisoft.com Wed Aug 18 11:04:00 2004 From: lbates at swamisoft.com (Larry Bates) Date: Wed, 18 Aug 2004 10:04:00 -0500 Subject: age of Python programmers References: Message-ID: I'll be 50 in October. Larry Bates Syscon, Inc. "Lucas Raab" wrote in message news:jQHUc.1529$2L3.505 at newsread3.news.atl.earthlink.net... > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... > > From peter at semantico.com Wed Aug 18 10:54:35 2004 From: peter at semantico.com (Peter Hickman) Date: Wed, 18 Aug 2004 15:54:35 +0100 Subject: age of Python programmers In-Reply-To: References: Message-ID: <41236dac$0$8717$afc38c87@news.easynet.co.uk> Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... > > 43 (20 years a programmer). From peter at engcorp.com Fri Aug 20 10:52:55 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 20 Aug 2004 10:52:55 -0400 Subject: Newbie to XML in Python In-Reply-To: References: Message-ID: Jens Thiede wrote: > XML in Python doesn't seem easy or intuitive. All I need to do, is to > interpret a small piece of XML in which I store data for the contents of > an autorun menu. What is the quickest/most effective way to do this? Quickest to run or quickest to write? Most effective how? The answer might, as answers often do, depend on the specific characteristics of your "small piece of XML". I could easily picture a tiny non-XML parser being considered the "quickest and most effective" way for certain jobs... -Peter From tim.peters at gmail.com Tue Aug 3 19:59:01 2004 From: tim.peters at gmail.com (Tim Peters) Date: Tue, 3 Aug 2004 19:59:01 -0400 Subject: Call for Grant Proposals In-Reply-To: <4110234F.1080004@acm.org> References: <4110234F.1080004@acm.org> Message-ID: <1f7befae04080316593355ce1d@mail.gmail.com> [Maurice Ling] > ... > The crucial issues here are in my other questions that everyone > convienently forgot, such as, what constitutes complete failure or > partial failure of the project? Is not delivering a single deliverable > account for complete failure? And what are the penalties? Nobody on comp.lang.python can answer those questions, no matter how often they're repeated, and for the obvious reason: comp.lang.python doesn't adminster the grant program. Nobody here is competent to answer them. Only the grant committee can. As has already been explained too, the grant program is just starting, and has no procedures in place. All questions are brand new. They have no canned answers to give you, and it takes significant time and effort to define everything to the level of detail you seem to want. There's nothing wrong with wanting that. It does seem peculiar to belabor it in an irrelevant forum, though. > I can't imagine that if you had been granted a grant for an open sourced > development in python and was not told way in advanced that a delay in > delivering a deliverable will result in you being forfeited the rest of > the grant money and will have to pay back 150% of all the money you had > received from the grant, until you had accepted the grant and working on > the project? I'm not sure I can parse that, but to the extent that I think I can, I also find it unimaginable. If you're going to presume that common sense and good will are absent, I'm not sure the PSF can afford all the lawyer time it would take to draft a grant agreement you can live with . From ville at spammers.com Sun Aug 22 04:36:16 2004 From: ville at spammers.com (Ville Vainio) Date: 22 Aug 2004 11:36:16 +0300 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> <7x4qmv6cwo.fsf@ruckus.brouhaha.com> Message-ID: >>>>> "Paul" == Paul Rubin writes: Paul> Well, whenever I want to write a mainstream application and Paul> think of using Python, my first reaction is that Python is Paul> too slow... What kind of mainstream application would be too slow if implemented in Python? Well, perhaps image / video editing... -- Ville Vainio http://tinyurl.com/2prnb From chrisks at NOSPAMudel.edu Mon Aug 2 05:25:50 2004 From: chrisks at NOSPAMudel.edu (Chris S.) Date: Mon, 02 Aug 2004 05:25:50 -0400 Subject: Sets Module Bug? Message-ID: >>> from sets import * >>> Set((1,2,3)) Set([1, 2, 3]) >>> Set([1,2,3]) Set([1, 2, 3]) >>> Set(([1,2,3],[4,5,6])) Traceback (most recent call last): File "", line 1, in ? File "sets.py", line 399, in __init__ self._update(iterable) File "sets.py", line 344, in _update data[element] = value TypeError: list objects are unhashable How can a Set using a tuple or list be ok, but not a tuple of lists? From robin at reportlab.com Wed Aug 18 09:59:37 2004 From: robin at reportlab.com (Robin Becker) Date: Wed, 18 Aug 2004 14:59:37 +0100 Subject: Python-2.1.x.tgz In-Reply-To: <41235D37.7060102@chamonix.reportlab.co.uk> References: <41235D37.7060102@chamonix.reportlab.co.uk> Message-ID: <412360C9.5080105@chamonix.reportlab.co.uk> Robin Becker wrote: > Does anyone know where I can get the latest source for Python-2.1. I > looked in www.python.org/2.1 and seem to see only Python-2.1.tgz. I am a moron :( there's a link at the top of that page -- Robin Becker From Michael.J.Fromberger at Clothing.Dartmouth.EDU Fri Aug 13 00:36:56 2004 From: Michael.J.Fromberger at Clothing.Dartmouth.EDU (Michael J. Fromberger) Date: Fri, 13 Aug 2004 00:36:56 -0400 Subject: PEP318 References: <20040812090056.00001e31@titan> <7ttmh0t8c3cogtbhhnp1ohqu8b51pda461@4ax.com> Message-ID: In article , David Eppstein wrote: > > Also, it's not in the Zen of Python, but maybe declarative is better > than imperative? This one comment particularly caught my attention. I generally agree with your above statement, but I don't think that this alone really justifies the proposed "decorators" (leaving aside the fact that they are still a moving target, semantically). The basic idea behind PEP-318 wasn't too bad, in my opinion -- but I think in discussion it's been overloaded with a lot of declaration work that would be better off factored out over other parts of the language (e.g., type declarations in the parameter list; method transformations wherever the syntactic dust settles over PEP-318; documentary metadata preferably left out of the syntax and parsed from comments or doc strings). To use the example of list comprehensions, I think we can agree that declarative constructs have excellent potential. But this is Python, not Perl, we don't need to make a Swiss Army knife out of this one piece of syntax. I realize you're not proposing we do so -- but, "declarative is better than imperative" could be taken too far by others. -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From Andreas.Ames at tenovis.com Mon Aug 9 07:06:41 2004 From: Andreas.Ames at tenovis.com (Ames Andreas (MPA/DF)) Date: Mon, 9 Aug 2004 13:06:41 +0200 Subject: Queue qsize = unreliable? Message-ID: <788E231C269961418F38D3E360D1652526CA20@tndefr-ws00021.tenovis.corp.lan> Hi, aahz wrote: > Try reading the Queue docs -- there IS a non-blocking Queue already. I did. But reading the source suggests something different. cheers, andreas From gen2n at seznam.cz Tue Aug 31 08:06:33 2004 From: gen2n at seznam.cz (p.kosina) Date: Tue, 31 Aug 2004 14:06:33 +0200 Subject: PyPI Message-ID: I tried to make a registration on www.python.org/PyPI, but no email confirmation received. Is it working? Is anyone responsible for that here? Thanks a lot Pavel From mwh at python.net Fri Aug 6 09:41:13 2004 From: mwh at python.net (Michael Hudson) Date: Fri, 6 Aug 2004 13:41:13 GMT Subject: static python build? References: Message-ID: mudd at vex.net writes: > How do I build Python so that I get static libraries instead of dynamic > libraries (e.g. build/lib.solaris-2.8-sun4u-2.3/math.so)? Edit Modules/Setup. The comments in the file should get you started. Cheers, mwh -- Monte Carlo sampling is no way to understand code. -- Gordon McMillan, comp.lang.python From aleaxit at yahoo.com Thu Aug 5 11:06:21 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 5 Aug 2004 17:06:21 +0200 Subject: The term "Protocol" In-Reply-To: <200408021444.i72Eidm11469@panix3.panix.com> References: <1f7befae04080117515cbb0ca9@mail.gmail.com> <6910338109.20040801192523@ <200408021444.i72Eidm11469@panix3.panix.com> Message-ID: <0300B212-E6F1-11D8-B90F-000A95EFAE9E@yahoo.com> On 2004 Aug 02, at 16:44, Aahz wrote: > [cc'ing Alex so he can jump in if he wants] > > In article , > Bruce Eckel wrote: >> >> I know the term "protocol" has been used to describe a language >> feature >> in a number of languages, but since we have no official "protocol" >> support in Python I'm interested in what "we" mean by this term. I'm >> going to guess that a protocol is like an interface in Java, except >> that it doesn't have a concrete definition anywhere, but it is implied >> through convention and use. Thus a protocol is a "latent interface." >> Am >> I close? I'd like to understand this term better. > > Alex Martelli gave an excellent presentation on Design Patterns at > OSCON, > where he made the point that "interface" is roughly equivalent to > syntax, > whereas "protocol" is roughly equivalent to syntax plus semantics. In > other words, computer langauges rarely (if ever -- although I suppose > Eiffel comes close) enforce protocols in any meaningful way. > > I'm hoping Alex posts his slides soon. Sorry, ADSL down, leaving for the Alps tomorrow, emergency netting from an internet cafe` at $$/hour. Hope to have my slides up when I get back (Aug 17 or thereabouts). But yes, what I deduced as the meaning of "protocol" from its occasional usage in the literature (about components, mostly) is that it adds to the interface (syntax==method names/signatures) the semantics and pragmatics ("you cannot call any other method after calling close" being more pragmatics than semantics, at least in linguistics terms). Languages do enforce protocols (e.g., raise an exception if you do mistakenly call something else after calling close), just not "at compile time" (not even Eiffel, where contract checking is runtime -- not even Haskell for its typeclasses, which is what I believe comes closest to compiletime protocol checking). Alex From mwh at python.net Fri Aug 13 11:04:44 2004 From: mwh at python.net (Michael Hudson) Date: Fri, 13 Aug 2004 15:04:44 GMT Subject: Difference between readlines() and iterating on a file object? References: <411cd102$1@mail.hmgcc.gov.uk> Message-ID: Duncan Booth writes: > "Richard" wrote in > news:411cd102$1 at mail.hmgcc.gov.uk: > > > Hi, > > > > Can anyone tell me what the difference is between > > > > for line in file.readlines( ): > > reads the entire file into memory and splits it up into a list of lines > then iterates over the list. If you break from the loop, tough you've lost > any lines that were read but you didn't handle. > > > > > and > > > > for line in file: > > reads part of the file and strips off one line at a time. Never creates a > list. Reads more only when it runs out of the block it read. If you break > from the loop you can do another 'for line in file' and get the remaining > lines. But this last part only works the way you expect in 2.3, I think. Cheers, mwh -- Ability to type on a computer terminal is no guarantee of sanity, intelligence, or common sense. -- Gene Spafford's Axiom #2 of Usenet From askari at addressNonValide.com Sun Aug 1 16:23:49 2004 From: askari at addressNonValide.com (Askari) Date: Sun, 01 Aug 2004 20:23:49 GMT Subject: Pygame - Only ONE Font found!? References: Message-ID: "Terry Reedy" wrote in news:mailman.994.1091237691.5135.python-list at python.org: > If you don't get an answer here (pygame is an application of Python, but > not Python itself), try the pygame mail list or gmane.comp.python.pygame > via gmane.org. > > tjr > > > "Pygame is a set of Python modules designed for writing games." And I'm redirect to group "comp.lang.python" if I need help. For "gmane.org"... too long for access help... Askari From a.clarke11 at ntlworld.com Sun Aug 22 11:55:13 2004 From: a.clarke11 at ntlworld.com (Tony Clarke) Date: 22 Aug 2004 08:55:13 -0700 Subject: Help with Calculater (first program) References: <8ff6f02e.0408211839.4057ff5@posting.google.com> <7xsmafhn8s.fsf@ruckus.brouhaha.com> Message-ID: <3353cd1e.0408220755.23dc18e9@posting.google.com> Paul Rubin wrote in message news:<7xsmafhn8s.fsf at ruckus.brouhaha.com>... > dave at inthegarage.net (aToaster) writes: > > Hey guys, I'm just getting the hang of Python and Tkinter and I could > > use some help. I wrote most of the gui for my calculator program, > > well I haven't gotten around to putting in the > > Hey, that was my first tkinter experiment too. > > http://www.nightsong.com/phr/python/calc.py Mine too! I think the answer to your biggest question is to mutiply 3 by ten before 4 is added to it, that would be a simple change. Ciao Tony From prabhu at aero.iitm.ernet.in Sun Aug 15 14:54:16 2004 From: prabhu at aero.iitm.ernet.in (Prabhu Ramachandran) Date: Sun, 15 Aug 2004 14:54:16 -0400 Subject: Trouble with file.seek/file.tell on Win32? Message-ID: <16671.45400.965715.943437@enthought.hathway.com> Hi, I noticed peculiar behavior under Python-2.3.4 under Win32. When I run something like this: f = open('t.txt', 'wb') f.write('1\012'+'2\012'+'3\012') f.close() f = open('t.txt', 'r') f.readline() pos = f.tell() val = f.read(1) f.seek(pos) assert val == f.read(1) I get an assertion error at this point. Everything works fine if I read the file with 'rb' instead of 'r'. But I can almost swear that this used to work earlier. I suspect that this behavior arises due to recent changes in fileobject.c (specifically, v2.187) where universal newline support was removed. http://cvs.sf.net/viewcvs.py/python/python/dist/src/Objects/fileobject.c?rev=2.192&view=log Could someone please clarify if this is this a bug or not? I would like to think that using tell and seek should work reliably enough for text files. The reason this is important for me is that I've been generating text files (with gay abandon) for MayaVi (http://mayavi.sf.net) for three years now. I always open the file using 'r'/'w' and not 'rb'/'wb'. Everything used to work fine. It never mattered where and how exactly the files were generated. Now, I get strange errors since I can no longer seek into these files reliably. I could switch to using 'rb'/'wb' universally but all existing files will no longer work without either requiring a fair bit of effort on my part or on the part of users changing their saved files. I am loathe to ask every user to change all their files and change the newlines. Thanks. cheers, prabhu p.s. Please CC me in on replies. I'm not tracking c.l.py. Thanks. From vjshield-widgets at yahoo.com Mon Aug 23 12:34:38 2004 From: vjshield-widgets at yahoo.com (vjshield-widgets at yahoo.com) Date: Mon, 23 Aug 2004 09:34:38 -0700 (PDT) Subject: Executing bytecode from a string. Message-ID: <20040823163438.25379.qmail@web41314.mail.yahoo.com> > I am just writing my Macro/Script in python >>sourcecode. > In the program I'm doing: > > f = open('segment.py','r') > str = f.read() > f.close() > > segment_code = compile(str, '', 'exec') > > exec(segment_code) I have the same problem. I'm currently storing the source in the db. From my application I get the source code, save it to a local file and then do the following: module = sys.modules[randomModuleFullPath] classObj = getattr(module, customClassName) self.system = classObj() The current doucmentation specifiees compile usage as: compile( file[, cfile[, dfile[, doraise]]]) Compile a source file to byte-code and write out the byte-code cache file. The source code is loaded from the file name file. The byte-code is written to cfile, which defaults to file + 'c' ('o' if optimization is enabled in the current interpreter). If dfile is specified, it is used as the name of the source file in error messages instead of file. If doraise = True, a PyCompileError is raised when an error is encountered while compiling file. If doraise = False (the default), an error string is written to sys.stderr, but no exception is raised. Is your compile the same function? Does it reutrn the byte code of the module. If the bytecode contains a Class definition, how do i instantiate a class object from it. Thanks, VJ From h.b.furuseth at usit.uio.no Mon Aug 2 17:21:03 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 02 Aug 2004 23:21:03 +0200 Subject: Class optimization at runtime References: Message-ID: Larry Bates wrote: > Kind of hard to tell what you are trying to accomplish > but I'll try. Define the class with no if/else statements. > They only get parsed once. It is the "class instance" > creations that may get created millions of times. They > will be inside your logical structure. Yup. > class Foo: > def __init__(self): > # do stuff > > class Bar: > def __init__(self): > # do stuff > > if option: x=Foo() > else: x=Bar() I don't see anything wrong with his original suggestion, provided that makes the rest of the code simpler: >> class Foo: >> if option: >> def __init__: >> #do stuff >> else: >> def __init__: >> #do other stuff That 'if' also gets run only once - when the class is created. Note that if your class instances only have a few instance variables, the most effective optimization may be something quite else: To make them subclasses of 'object', and define __slots__. A program of mine ran in about half the time after doing so. There are a number of dangers involved with __slots__, though. Check the reference manual. For other optimization hints, see section 1.5 of the Python Programming FAQ at . -- Hallvard From peter at engcorp.com Wed Aug 4 22:58:47 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 04 Aug 2004 22:58:47 -0400 Subject: Decorator syntax In-Reply-To: References: Message-ID: <38ednYT1NLz1P4zcRVn-uA@powergate.ca> C. Barnes wrote: > I vote for > > def f(): [synchronized, classmethod] > (body of function) > > This is backwards compatible (Python <= 2.3 raise > SyntaxError), and looks much nicer than @. I'm nearly certain, without bothering to check, that this was one of the many proposals already discussed and rejected, if nothing else for the simple reason that it only works nicely when you have a short definition such as your example (with "f()") and not nicely at all with a much longer name and argument list. Inevitably you would need to split the decorator part onto a second line, either requiring a backslash (ugly) or changing your second comment about it raising a SyntaxError with previous versions (because it then matches valid though meaningless code). Anyway, check the past discussions before going back around the same arguments yet again. For the record, the @ syntax is despicable and horribly un-Pythonic, IMHO, and I really hope never to read code that uses it. :-( (And my preferred syntax was "def f() [classmethod]:", FWIW) -Peter From scott.b.drummonds.nospam at intel.com Wed Aug 11 12:45:28 2004 From: scott.b.drummonds.nospam at intel.com (Scott Brady Drummonds) Date: Wed, 11 Aug 2004 09:45:28 -0700 Subject: 'break' Causes Execution of Procedure? Message-ID: Hi, everyone, I have a bug in a script of several hundred lines of code that I cannot figure out. I have attempted (unsuccessfully) to duplicate this problem in a smaller script that I can post here but have been unsuccessful. As such, I'm posting code snippets here in the hopes that someone recognizes a very basic mistake I've made and can straighten me out. First, the portion of my text file that executes my code: if __name__ == '__main__': if len(sys.argv) != 2: print('usage: %s ' % sys.argv[0]) sys.exit() main(sys.argv[1]) Here are the first few lines of my 'main' procedure: def main(fileName): print('DEBUG: begin main procedure') ... And here is the part that is causing problems: # 'keys' is a list of integers returned from dict.keys() for cycle in keys: if key in skipList: print ('skipping %d/%d' % (cycle, cycleMap[cycle])) continue try: print('DEBUG: advancing both simulators to %d' % cycle) procedureThatCouldRaiseEOFError() except EOFError: print('DEBUG: encountered EOFError; breaking loop') break print('DEBUG: All cycles processed') Here's what I can't figure out. I'm seeing the following text generated during this script's execution: DEBUG: advancing both simulators to 20178 DEBUG: encountered EOFError; breaking loop DEBUG: begin main procedure How is it possible that the call to 'break' is seemingly being replaced with a call to 'main'? Thanks! Scott -- Remove .nospam from my e-mail address to mail me. From abra9823 at mail.usyd.edu.au Wed Aug 11 11:04:46 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Thu, 12 Aug 2004 01:04:46 +1000 Subject: p3p Message-ID: <1092236686.411a358e04d9c@www-mail.usyd.edu.au> hi! does anyone know of a Python implementation of a P3P proxy? thanks cheers -- Ajay Brar, ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From nmkolev at uni-bonn.de Thu Aug 5 08:27:41 2004 From: nmkolev at uni-bonn.de (Nickolay Kolev) Date: Thu, 05 Aug 2004 14:27:41 +0200 Subject: Scope Problem In-Reply-To: References: Message-ID: Thanks guys, I should have seen it myself, it?s stupid enough. @Irmen: I am implementing the algorithms not for the purpose of using them, but for the purpose of learning them. I thinks it is a bit early for trying to outsmart the python dev-people. :-) @Daniel: It should be pretty obvious form my mistake that it is not. A real Lisper would never do such a thing. :-) Thanks again, Nicky From nid_oizo at yahoo.com_remove_the_ Wed Aug 25 18:12:41 2004 From: nid_oizo at yahoo.com_remove_the_ (Nicolas Fleury) Date: Wed, 25 Aug 2004 18:12:41 -0400 Subject: Call for signatories for J2 In-Reply-To: References: Message-ID: For. Regards, Nicolas Fleury From M.Waack at gmx.de Fri Aug 20 16:47:53 2004 From: M.Waack at gmx.de (Mathias Waack) Date: Fri, 20 Aug 2004 22:47:53 +0200 Subject: sub-shell errors References: Message-ID: Bigbowser wrote: > while(1): > > userInput == raw_input('ICE> ') > cmds = { 'help' : commands.displayHelp, 'version' : > commands.displayVersion, > 'authors' : commands.displayAuthors, 'exit' : > commands.exitIce} > > for cmd, callback in cmds: > if userInput == cmd: > callback() You mean for cmd, callback in cmds.items() ? Or much shorter: cmds[cmd]() Mathias From noone at here.com Mon Aug 16 09:48:21 2004 From: noone at here.com (M. Clift) Date: Mon, 16 Aug 2004 14:48:21 +0100 Subject: random / lists References: <7xr7q7edg0.fsf@ruckus.brouhaha.com> Message-ID: Hi Paul, No, not homework, I'm a bit old for that : ) It's an idea for a simple decision maker. Malcolm From po-yung.liu at pandora.be Mon Aug 16 20:29:56 2004 From: po-yung.liu at pandora.be (Vent d'Est - East Wind) Date: Tue, 17 Aug 2004 00:29:56 GMT Subject: Python / scheme implement Message-ID: <8kcUc.216223$pC2.10693727@phobos.telenet-ops.be> Can somebody tell me what s exactly the difference beetween scheme and python languages i m thiking to learn one of them but i m not sure wich one somebody told me python is better and have much library somebody told me scheme is much smarter and have nice structure i also see a project about a scheme/python implementation here is the url http://plt-spy.sourceforge.net/home.html i m not sure what s really but seems cool if someone know more about it or have some concrete exemple it can be more understable i m not sure what to do ps i want programming some open source soft for network with gui thankx a lot east wind From martindemello at yahoo.com Tue Aug 3 01:56:52 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Tue, 03 Aug 2004 05:56:52 GMT Subject: Newbie: pywin problem References: <1091491406.159993@news.commspeed.net> Message-ID: Tom B. wrote: > > I would try wxPython at http://wxpython.org/ they have a wrapper for > scintilla and are it is much more Pythonic. I know :-/ I got a wxPython example up and running in under half an hour, but I'm hoping to integrate this with a C++/MFC app and have the python windows open within the main C++ app (MDI style). > You probably need to do a > > somename = view.CreateWindow(fr) > somename.Show(1) > > to get your current app to work, but Win32Ui is kinda funny. Nope, didn't work either, and 'somename' appears to be null martin From kjetilho at ifi.uio.no Fri Aug 27 21:21:36 2004 From: kjetilho at ifi.uio.no (Kjetil Torgrim Homme) Date: Sat, 28 Aug 2004 03:21:36 +0200 Subject: allowing braces around suites In-Reply-To: References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> Message-ID: <1093656096.749.69.camel@chico.njus.no> Anthony Baxter wrote: > Kjetil Torgrim Homme wrote: > > what do you think? should I write a PEP? > > I've changed my mind. You should indeed write a PEP. I strongly > suggest you adopt the spirit of PEP-666 in doing this, as a PEP on > braces will get the same response. I'd even suggest PEP 667 (The > Neighbour of the Beast) as the PEP number. interesting, can I choose the number? (btw, I always thought 668 was the neighbour of the beast.) I'll write a PEP, but it will have to wait until next week. thank you for your feedback! -- Kjetil T. From ialbert at mailblocks.com Thu Aug 5 15:58:56 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Thu, 05 Aug 2004 15:58:56 -0400 Subject: Decorator syntax In-Reply-To: References: <788E231C269961418F38D3E360D1652526CA1A@tndefr-ws00021.tenovis.corp.lan> Message-ID: Terry Reedy wrote: > Also, some of the major proponents want parameterized decorators and > multiple decorators, not just a different position for staticmethod and > classmethod. So And that's the problem. The example and motivation in PEP318 are both vague and misleading. The disagreement is caused by trying to achieve a lot of different things with one feature. Thus the solution that is emerging is to cram everything in front of the function definition. Istvan. From http Tue Aug 24 21:12:06 2004 From: http (Paul Rubin) Date: 24 Aug 2004 18:12:06 -0700 Subject: Book Recommendation References: Message-ID: <7x7jro9g2h.fsf@ruckus.brouhaha.com> Anthony Greene writes: > I'm new to programming entirely, and I'm simply looking for some insight, > can you guys recommend some introductory documentation for me to read, and > what I read, and, do concurrently why reading the primary "book" ou guys > recommend. Thanks, and any advice is great appreciated. Kind of hard to say. Depends on your general experience level, e.g. how much math do you know? Some other people have suggested good books about Python, but those don't say so much about programming in general. For that, you may need to look to other kinds of books. I really liked "Software Tools", by Kernighan and Plauger, but it's about a billion years out of date by now. From ville at spammers.com Fri Aug 20 10:45:33 2004 From: ville at spammers.com (Ville Vainio) Date: 20 Aug 2004 17:45:33 +0300 Subject: age of Python programmers References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: >>>>> "Christos" == TZOTZIOY writes: Christos> On Fri, 20 Aug 2004 10:23:16 +0200, rumours say that Christos> Gerrit Muller might Christos> have written: >> The most >> positive experiences were Sinclair QL-basic, [snip] Christos> I'll drink to that! Apparently there is some good karma in Sinclair QL - Linus also used to hack on it. I had MSX (SVI-728), which probably steered me more towards coding than C64 would have (most friends had one of those, along with 500+ games ;-) - it had a decent basic (MS basic) from Microsoft's pre-evil era. Ah, even seeing the SVI-728 acronym puts me on the nostalgy train... -- Ville Vainio http://tinyurl.com/2prnb From davebrok at soda.csua.berkeley.edu Sun Aug 22 19:05:42 2004 From: davebrok at soda.csua.berkeley.edu (David Pokorny) Date: Sun, 22 Aug 2004 16:05:42 -0700 Subject: Python is to C as letters are to words. References: Message-ID: Yes! I totally agree. One of Python's hats is "the ultimate C scripting language." On this note, has anyone written something along the lines of "Companion to the C Python implementation"? Source code comments are great, but there is so much more that one could say about the theory, big ideas, the creative solutions that people came up with, etc... David From tom at scoosh.com Wed Aug 18 17:52:04 2004 From: tom at scoosh.com (tom at scoosh.com) Date: Wed, 18 Aug 2004 22:52:04 +0100 Subject: test please ignire Message-ID: From psXdaXsilva at esotericaX.ptX Fri Aug 13 21:00:35 2004 From: psXdaXsilva at esotericaX.ptX (Paulo da Silva) Date: Sat, 14 Aug 2004 02:00:35 +0100 Subject: A problem with GzipFile (BUG?) Message-ID: <1092445509.64317@jubilee.esoterica.pt> Hi. I am writing to a file mixing "Normal" with gziped Data. For that I am using GzipFile. For ex. 1st I write some data (A), then I open a GzipFile and write let's say N (uncompressed) bytes (B). Then I close GzipFile, write some more data (C) and close the file. Unfortunately, when reading the the N compressed bytes (B) and closing GzipFile, I didn't *always* get correctly positioned at the beginning of (C)! Is this a bug? Is there a way to exhaust all the bytes written to GzipFile so that the file pointer *always* point to beginning of (C)? Most of times this works fine, but not always! Thanks for any help. From tjreedy at udel.edu Fri Aug 6 18:49:24 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 6 Aug 2004 18:49:24 -0400 Subject: PEP 263 status check References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de><10h5hgvpafm8a64@news.supernews.com> <41133C76.8040302@v.loewis.de><10h6rklt3fa1690@news.supernews.com> <41137799.70808@v.loewis.de><10h724r20kkeqb2@news.supernews.com> <4113D8DF.8080106@v.loewis.de> Message-ID: "Martin v. L?wis" wrote in message news:4113D8DF.8080106 at v.loewis.de... > If you think that only Unicode literals and comments should be > allowed to contain non-ASCII, I disagree: At some point, I'd > like to propose support for non-ASCII in identifiers. This would > allow people to make identifiers that represent words from their > native language, which is helpful for people who don't speak > English well. Off the main topic of this thread, but... While sympathizing with this notion, I have hitherto opposed it on the basis that this would lead to code that could only be read by people within each language group. But, rereading your idea, I realize that this objection would be overcome by a reader that displayed for each Unicode char (codepoint?) not its native glyph but a roman transliteration. As far as I know, such tranliterations, more or less standardized, exist at least for all major alphabets and syllable systems. Indeed, I would find Japanese code displayed as for sushi in michiro.readlines(): print fuji(sushi) clearer than 'English' code using identifiers like Q8zB2_0Ol1! If the Unicode group does not distribute a master roman tranliteration table at least for alphabetic symbols, I would consider it a lack that hinders adoption of Unicode. Some writing systems also have different number digits, which could also be used natively and tranliterated. A Unicode Python could also use a set of user codepoints as an alternate coding of keywords for almost complete nativification. I believe the math symbols are pretty universal (but could be educated if not). Terry J. Reedy From dale at riverhall_nospam_.co.uk Thu Aug 26 09:54:54 2004 From: dale at riverhall_nospam_.co.uk (Dale Strickland-Clark) Date: Thu, 26 Aug 2004 14:54:54 +0100 Subject: Fun transformation problem Message-ID: A guy in the office has come up with this interesting transformation problem. We have a solution but I'm sure there's a neater, more 'pythonic' approach. I thought this might appeal to some here: I want a function to convert a list of tuples into a hierarchy of dictionaries. ?Let me first demonstrate with an example: >>> lstA = [(1, 2, 3), (1, 3, 4), (2, 5, 6)] >>> dctA = fncA(lstA) >>> print dctA {1: {2: 3, 3: 4}, 2: {5: 6}} >>> I essentially want the definition to fncA. ?Here is another example: >>> lstA = [(1, 2, 3, 4) ,(3, 4, 5, 6), (3, 4, 6, 7), (3, 4, 6, 8), (3, 4, 5, 1), (3, 4, 7, 9)] >>> dctA = fncA(lstA) >>> print dctA {1: {2: {3: 4}}, 3: {4: {5: 1, 6: 8, 7: 9}}} >>> Each tuple in the original list must be unique after the last value is excluded (since these values are used to form the "hierarchical key". I have written a function, which seems to work but looks very cumbersome. Could anyone point me to a simpler solution? Dale Strickland-Clark Riverhall Systems From eurleif at ecritters.biz Sat Aug 7 18:39:26 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sat, 07 Aug 2004 18:39:26 -0400 Subject: Image manipulation library under a GPL-compatible license? Message-ID: <2nl3suF1vntdU1@uni-berlin.de> I need to do some simple image editing (pretty much just scaling) in a GPLed program. Unfortunatly, both of the Python libraries for image editing that I found (gdmodule and PIL) are under the GPL-incompatible original BSD license. Is there another library under a friendlier library? From dippyd at yahoo.com Thu Aug 12 21:01:08 2004 From: dippyd at yahoo.com (Steve) Date: Fri, 13 Aug 2004 11:01:08 +1000 Subject: Rather than decorators, how about sections? References: Message-ID: <411C12D4.7010400@yahoo.com> Paul Morrow wrote: > class Foo(object): > staticmethods: > def baz(a,b): > print "I'm a static method." > def bez(c,d): > print "I'm a static method too." > > classmethods: > def biz(klass): > print "I'm a class method." > > > def __init__(self): > print "We all know what I am." I don't. Is there a simple primer for static and class methods and decorators and such that you can recommend? I've looked at the URL you gave with the Memoize class http://www.python.org/cgi-bin/moinmoin/PythonDecoratorLibrary, but it assumes you already know what decorators are. Then, later, Paul Morrow wrote: > Fine, instead of Foo (the name of the class), use the > word klass. It's a popular name for the first > parameter of a class method. "klass" isn't a word. It is a twee deliberate mispelling of a word. It also runs the risk of causing confusion when code is spoken aloud (eg in actual human-to-human communication using alternating high and low pressure atmospheric waves to deliver packets of information, or in text readers for the blind). It is bad enough when coders (including myself) choose to deliberately mispell words, but to make it required is unforgivable. -- Steven. Any mispellings in the above post are deliberate, and are there to show the reader wonderful new ways of spelling old words. From mwh at python.net Fri Aug 6 09:56:18 2004 From: mwh at python.net (Michael Hudson) Date: Fri, 6 Aug 2004 13:56:18 GMT Subject: Getting around the GIL with POSH References: <2nhgq0Fvu3qU1@uni-berlin.de> Message-ID: Jon Perez writes: > Is anyone out there using POSH and is it reliable enough for > production use? Any plans to incorporate it into the Python > distribution? Well, I think it currently only works on x86, which is a bit of a bind (I may be out of date). Cheers, mwh -- ... 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 michaels at rd.bbc.co.uk Mon Aug 23 07:18:57 2004 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Mon, 23 Aug 2004 12:18:57 +0100 Subject: Python is to C as letters are to words. References: Message-ID: David Pokorny wrote: ... > On this note, has anyone written something along the lines of > "Companion to the C Python implementation"? Certainly would've helped at the weekend... ;-) Michael. -- Michael.Sparks at rd.bbc.co.uk British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From greg.lindstrom at novasyshealth.com Tue Aug 10 12:43:33 2004 From: greg.lindstrom at novasyshealth.com (Greg Lindstrom) Date: Tue, 10 Aug 2004 11:43:33 -0500 Subject: pyDAV Message-ID: <004901c47ef9$2d348670$054b12ac@D18SYX41> I am in need of retrieving files from a host running DAV and would like to use the pyDAV library, but can not find any documentation on how to use it. Can anyone point me to some examples, or show me the steps required to retrieve a file using pyDAV? Thanks! --greg Greg Lindstrom (501) 975-4859 NovaSys Health greg.lindstrom at novasyshealth.com "We are the music makers, and we are the dreamers of dreams" W.W. From aleaxit at yahoo.com Thu Aug 26 04:35:14 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 10:35:14 +0200 Subject: A question?? References: <938a4680.0408252138.1580ac93@posting.google.com> Message-ID: <1gj4fvw.svtd4815ar727N%aleaxit@yahoo.com> Ishwar Rattan wrote: > I thought that Python has no concept of reference/pointer > (probably incorrect assumption). No pointers, but any name you use, any slot in a list, any key or value slot in a dict, etc, IS a reference. Nothing to do with your question anyway. > def run(program, *args): > pid = os.fork() > if not pid: > os.execvp(program, (program,)+args) > > and call to run as > > run("pyhton", "a.py") > > What is the interpretation of *args (in def run(..)? It is: 'run' takes any number of positional arguments after the ones specified so far. Python collects them all into a tuple and your code refers to that tuple with the name 'args'. > Looks like a reference to me, so, how does one decide when to use > a reference or not? 'args' is a reference just like any other name is. > Any pointers to info will be appreciated. "Python in a Nutshell", among other reference works, covers argument passing and such subjects quite well, I think;-). Alex From rnichol_rrc at yahoo.com Sat Aug 28 13:24:26 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Sat, 28 Aug 2004 12:24:26 -0500 Subject: Dynamic languages In-Reply-To: <1093650026.763899@news.commspeed.net> References: <278de0e.0408271349.26762174@posting.google.com> <1093650026.763899@news.commspeed.net> Message-ID: Tom B. wrote: > I doubt that this is what they mean but a dynamic language is a language > that is still evolving (Python) as opposed to a dead language (COBOL). During my "education" at my school of unfortunate choice I had to learn the script of the damned... sorry, COBOL. I learned that it has indeed gone through some developments in the past years ie COBOL now is object oriented COBOL. It *should* be dead though, but companies don't want to develope any new systems. So, they fund a programming program at some local college at "suggest" that they include it so that they have a work force availible to make changes to there system. That of course doesn't mean that this certain company's COBOL programmer lasts on average < 6 months. Which certainly is the case. Quite frankly I don't know how they last so long. From fumanchu at amor.org Sat Aug 21 02:28:20 2004 From: fumanchu at amor.org (Robert Brewer) Date: Fri, 20 Aug 2004 23:28:20 -0700 Subject: Overriding logical operators? Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E1C@exchange.hqamor.amorhq.net> Andrew Durdin wrote: > In Python, you can override the behaviour of most operators for a > class, by defining __add__, __gt__, and the other special object > methods. > > I noticed that, although there are special methods for most operators, > they are conspicuously absent for the logical "or" and "and". I'm > guessing that the reason for this is that these operators > short-circuit if their first operand answers the whole question? > > Would it be possible to allow overriding the logical operators, with > the caveat that overriding it would prevent short-circuiting? This has come up before--in particular, I think Greg Ewing was taking a stab at it last. Google is your friend. Anything's possible if you're willing to write it. ;) The first barrier is that 'or' and 'and' get compiled down to jump codes, as opposed to operations: >>> dis.dis(lambda x: (x + 3) or (x - 5)) 1 0 LOAD_FAST 0 (x) 3 LOAD_CONST 1 (3) 6 BINARY_ADD 7 JUMP_IF_TRUE 8 (to 18) 10 POP_TOP 11 LOAD_FAST 0 (x) 14 LOAD_CONST 2 (5) 17 BINARY_SUBTRACT >> 18 RETURN_VALUE ...so you'd be hacking a completely different section of the compiler to enable such overriding. Robert Brewer MIS Amor Ministries fumanchu at amor.org From tjreedy at udel.edu Mon Aug 2 21:10:33 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 2 Aug 2004 21:10:33 -0400 Subject: How to clear previous console output? References: Message-ID: "Mike Rovner" wrote in message news:cem9bk$200$1 at sea.gmane.org... > (For console output) Use \r. > > Example: > > for i in range(100): > print '%s\r' % ' '*20, # clean up row > print '%d%%' % i, # note ending with comma > print > > Note that it works only in real console window, not in simulated one (like > in WinIDE). > That is cross-platform. If you do not want to erase everything, \10 in string inserts backspace character, but blanking and rewriting everything may be easier. tjr From aahz at pythoncraft.com Mon Aug 30 20:57:52 2004 From: aahz at pythoncraft.com (Aahz) Date: 30 Aug 2004 20:57:52 -0400 Subject: initializing mutable class attributes References: <1gjc8cs.sqvo1v1fhabdjN%aleaxit@yahoo.com> Message-ID: In article , Shalabh Chaturvedi wrote: > >In Python you either have an __init__ or you don't. There is no 'default >constructor' - or if there is, it does nothing. Actually, that's not quite true. Python does indeed have a default constructor that returns the object. This isn't particularly visible from classic classes because there's no way to get access to a constructor. New-style classes make the constructor available through __new__(). __init__() is an initializer. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From steven.bethard at gmail.com Thu Aug 5 18:30:57 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: 5 Aug 2004 15:30:57 -0700 Subject: Confused about pep 318 References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: steven.bethard at gmail.com (Steven Bethard) wrote in message news:... > > Not a big fan of this syntax -- no intuitive reason why @ would mean > decorator -- but I presume this has already been complained about... > Could someone direct me to the discussions about this? I'd like to > see why it was the eventual favored syntax... > So, I did my homework and read way too much python-dev for a mere mortal, and found a good synopsis that is worth looking at if you haven't already: http://www.python.org/moin/PythonDecorators It gives a bunch of the different considered syntaxes, pros and cons, etc. I have to say, after reading the archives and the wiki, I like @ a little bit more. The other major frontrunners I saw were a list-before-def syntax and a function-call-before-def syntax. Both of these have the major flaw that they take currently valid Python code and give it a different meaning. I don't like that -- it means I have to relearn part of Python semantics. Even the list-after-def syntax, which doesn't introduce semantics changes, isn't substantially clearer to me as a decorator than @ is -- why is a list before the : a list of decorators? Seems almost as arbitrary as @. What would have seemed most Pythonic to me is a new keyword -- like was done for 'yield' -- but that seems to have been voted down. (Guido especially dislikes the use of 'as' for these purposes.) I'd still prefer a new keyword over @, but if a new keyword is out of the question, I'll take @ over any syntaxes that change Python's current semantics, and I'll take an implemented and working @ over an as-yet unimplemented list-after-def syntax. Steve From peter at engcorp.com Fri Aug 6 12:50:19 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 06 Aug 2004 12:50:19 -0400 Subject: [Newby question] List comprehension In-Reply-To: References: Message-ID: Eelco Hoekema wrote: > Peter Hansen schreef: >>List comprehensions may be faster, but that is never a valid reason, >>in isolation, for choosing one construct over another. > >>If (a) list comprehensions can't do this, or (b) one has to jump >>through hoops and make the construct completely unreadable to make >>it work, then list comprehensions are completely unsuited to the >>task at hand. > >>A loop, on the other hand, works just fine and is very readable. >>Use a loop. > > I'm a bit puzzled. Are you saying one should never use a list > comprehension? Or are you just referring to this specific problem, where i > would have to cheat in order to get the things done in one single list > comprehension? Definitely referring only to cases such as this one, where you have to "cheat". The fact that it's not straightforward to do should immediately lead someone in the direction of finding the more obvious and simple approach. In this case, that's a loop. (Someone may well find an elegant way to do it with a nice concise list comprehension. Such a way may well become an accepted idiom at some point in the future. Neither of these points has any bearing on the fact that most of us shouldn't spend time trying to shoehorn overly complicated structures into constructs that can't easily handle them.) I do use list comprehensions myself. Never (yet) for reasons of performance, and never for complicated ones because I always find the loop variant to be more readable once they've grown beyond the relatively simple ones like this: [(foo, bar(foo)) for foo in someList if foo is not a baz] -Peter From h.b.furuseth at usit.uio.no Fri Aug 6 17:10:44 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 06 Aug 2004 23:10:44 +0200 Subject: PEP 263 status check References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> <10h5hgvpafm8a64@news.supernews.com> <41133C76.8040302@v.loewis.de> <10h6rklt3fa1690@news.supernews.com> <41137799.70808@v.loewis.de> <10h724r20kkeqb2@news.supernews.com> Message-ID: An addition to Martin's reply: John Roth wrote: >"Martin v. L?wis" wrote in message >news:41137799.70808 at v.loewis.de... >>John Roth wrote: >> >> To be more specific: In an UTF-8 source file, doing >> >> print "?" == "\xc3\xb6" >> print "?"[0] == "\xc3" >> >> would print two times "True", and len("?") is 2. >> OTOH, len(u"?")==1. >> >>> The point of this is that I don't think that either behavior >>> is what one would expect. It's also an open invitation >>> for someone to make an unchecked mistake! I think this >>> may be Hallvard's underlying issue in the other thread. >> >> What would you expect instead? Do you think your expectation >> is implementable? > > I'd expect that the compiler would reject anything that > wasn't either in the 7-bit ascii subset, or else defined > with a hex escape. Then you should also expect a lot of people to move to another language - one whose designers live in the real world instead of your Utopian Unicode world. > The reason for this is simply that wanting to put characters > outside of the 7-bit ascii subset into a byte character string > isn't portable. Unicode isn't portable either. Try to output a Unicode string to a device (e.g. your terminal) whose character encoding is not known to the program. The program will fail, or just output the raw utf-8 string or something, or just guess some character set the program's author is fond of. For that matter, tell me why my programs should spend any time on converting between UTF-8 and the character set the application actually works with just because you are fond of Unicode. That might be a lot more time than just the time spent parsing the program. Or tell me why I should spell quite normal text strings with hex escaping or something, if that's what you mean. And tell me why I shouldn't be allowed to work easily with raw UTF-8 strings, if I do use coding:utf-8. -- Hallvard From peter at engcorp.com Thu Aug 19 07:43:31 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 19 Aug 2004 07:43:31 -0400 Subject: Py2Exe PROBLEM In-Reply-To: <81a41dd.0408190023.44d34c44@posting.google.com> References: <81a41dd.0408190023.44d34c44@posting.google.com> Message-ID: <2tGdncgUvpKRD7ncRVn-oQ@powergate.ca> Lad wrote: > I try to make an exe file from my script with help of Py2exe but I am > not successfull. ... > When compilation finishes I get: > > The following modules appear to be missing > ['blackbox', 'timing', 'rgs.py'] > > Can you please help me how to solve the problem? If you explain what problem you are actually having. Are you assuming simply because of that warning message that it didn't work? What happens when you try to run the resulting .exe file? Note that py2exe will sometimes complain about modules that are not actually required for the program to run. Also please explain what "blackbox" and "timing" are, if they are part of the problem. Finally (and this might be the whole problem), you seem to be using "import rgs.py" when you really meant to use just "import rgs". You don't import Python modules using the full filename of the source file... -Peter From flupke at nonexistingdomain.com Thu Aug 19 05:53:41 2004 From: flupke at nonexistingdomain.com (flupke) Date: Thu, 19 Aug 2004 09:53:41 GMT Subject: anonymous function? In-Reply-To: References: Message-ID: Thanks Richie and Benjamin, that solved the error i got. (timer is not yet working correctly but that's for another thread :) ) From dostatnig at yahoo.com Tue Aug 10 16:37:41 2004 From: dostatnig at yahoo.com (Grzegorz Dostatni) Date: Tue, 10 Aug 2004 14:37:41 -0600 Subject: remaining decorator syntax options References: Message-ID: Keyword. Definitely keyword. One of the great stong points of python (for me at least) is that it uses next to no special symbols. Now, I could go on and say how ugly I find code that uses these kinds of symbols. I've been doing python programming for about 5 years. I've done ruby for the last two years and I still find those @, @@ and $ to be both ugly and annoying to write. Whenever I am forced to include a special symbol, I pretty much stop and rever to "hunting and pecking". By comparison, writing python code is not much more difficult than writing english text. (Although it requires far more concentration). Besides, typing speed is not an issue in programming. Saving 4 keystrokes by going @foo instead of self.foo is not going to make a difference. What makes python a rapid development language is documentation, powerful base data types and the ability to read other people's code. Most of the time ;-) At the end of the day, I would look for precedents: Python: c/c++ Ruby and & and or | or self.foo @foo global $foo I am aware of the symbols python uses (#, %, **, &, |). With the exception of #, I generally find a way to avoid them. Greg On 10 Aug 2004 12:33:36 -0700, Steven Bethard wrote: > So I'd suggest that we put all our effort into the indicator > discussions. If you have a good argument for why a keyword is better > than a symbol, or why a symbol is better than a keyword, please voice > them now. And remember that 'because it's prettier' or 'because it's > uglier' are not aguments GvR will consider. We need strong arguments, > that argue on the basis of readability or learnability or > maintainability, etc. From aleaxit at yahoo.com Thu Aug 26 09:40:40 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 15:40:40 +0200 Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> <1gj4fb5.607xsc51izh8N%aleaxit@yahoo.com> <7xllg25lkt.fsf@ruckus.brouhaha.com> Message-ID: <1gj4u3a.12ttba9fynd6uN%aleaxit@yahoo.com> Paul Rubin wrote: > aleaxit at yahoo.com (Alex Martelli) writes: > > There should be one-- and preferably only one --obvious way to do it. > > > > Not leaving stylistic choice (which would lead to more than one obvious > > way to do it) is quite consonant with the Zen of Python. > > Well, what you're left with is that doing it the one obvious way > doesn't work, and you have to do it in some contorted way instead. If somelist.sort() returned the list there could not possibly be one obvious way to do it, since both print somelist.sort() and somelist.sort() print somelist would be ways to do it, both pretty obvious to different people. [[The introduction of 'sorted' will muddy 'obviousness' for some, but IMHO it just changes what the one obvious way is: if you do want an inplace sort, then somelist.sort(), otherwise then sorted(somelist) when you do not want to alter somelist in place.]] Alex From martin at v.loewis.de Tue Aug 3 08:02:52 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 03 Aug 2004 14:02:52 +0200 Subject: More charset troubles (Re: Codecs for ISO 8859-11 (Thai) and 8859-16 (Romanian)) In-Reply-To: References: <410c2827$0$24830$9b622d9e@news.freenet.de> <410D7AB5.9040100@v.loewis.de> <410E4B49.7030805@v.loewis.de> Message-ID: <410F7EEC.5040104@v.loewis.de> Peter Jacobi wrote: > Looking around: > - the RFC references a fixed year old version > - Unicode mapping files and libiconv track the newest version > - IBM ICU4C provides all versions > - Python (not by planning, I assume) has a "middle" version with > some features of the old mapping table (no currency signs) and some > features of the new (0xA1=0x2018, 0xA2=0x2019) Indeed. Adding new codecs is not a matter of just compiling a few files that somebody else has produced, but requires a lot of expertise. Therefore, I would have preferred if Python would not have included any codecs, but relied on the codecs that come with the platform (e.g. iconv on Unix, IE DLLs on Windows). Now, things came out differently, and we are now in charge of maintaining what we got. This requires great care, and expert volunteers are always welcome. Unfortunately, in the Unicode/character sets/l10n world, there is no one true way, so experts need to stand up and voice their opinion, hoping that contributors become atleast aware of the issues. In the specific case of ISO-8859-7, I was until just now unaware of the issue - I would not have guessed that ISO dared to ever change a part of 8859. If this is ever going to be changed, I would suggest the following approach: - provide two encodings: ISO-8859-7:1987, and ISO-8859-7:2003. Without checking, I would hope that the version in RFC 1345 is identical with 8859-7:1987 - Make ISO-8859-7 an alias for ISO-8859-7:1987 Of course, somebody should really talk to IANA and come up with preferred MIME name. Apparently, ISO-8859-7-EURO and ISO-8859-7-2003 have been proposed. Regards, Martin From mcfletch at rogers.com Thu Aug 12 02:32:05 2004 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Thu, 12 Aug 2004 02:32:05 -0400 Subject: Arranging a dependency tree In-Reply-To: References: <6ccff37a.0408111831.6eb25a4e@posting.google.com> Message-ID: <411B0EE5.3080308@rogers.com> Bryan Olson wrote: ... > If you want an ordering in which each module follows the > modules on which it depends, you want a 'topological sort' based > on the depends relation. There's a module here: http://www.vrplumber.com/programming/ which provides two implementations of topological sorting in Python. With that, should be a trivial task to do a dependency sort on the OP's graph. HTH, Mike ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From chris.cavalaria at free.fr Wed Aug 11 14:55:25 2004 From: chris.cavalaria at free.fr (Christophe Cavalaria) Date: Wed, 11 Aug 2004 20:55:25 +0200 Subject: Rather than decorators, how about sections? References: <1C74C038-EBB6-11D8-8889-000A95857E5C@eischet.com> Message-ID: <411a6b9d$0$13688$636a15ce@news.free.fr> Paul Morrow wrote: >> class Foo(object): >> def spam(Foo): >> print "Class Method" What is that ? It's ugly, it's a name alias and it'll be incredibly confusing when classmethods are inherited, which is exactly the most common use case for classmethods. > I like it! It's simple, clear, ... Why isn't this the hands-down best > solution? Why do we want to be more verbose than necessary? It isn't a solution. It only "resolves" the problem for staticmethod and classmethod which are only a very small part of what we do/want to do with decorators. > I wonder if there are people out there who've chosen something other > than *self* for the 1st arg (shame on them if they did! ) who's > code this would break. I've never understood why we didn't require that > it be called self in the first place --- why give them more than one way > to do *that*? Well, it might seem strange but : - It will break a lot of code which use a name different than self for the first argument - It'll break all existing classmethods - It'll break code that binds arbitrary functions as a member function. You can't do things like that anymore : >>> def f(s): >>> print "Hi, I'm function f" >>> class Klass: >>> doIt = f >>> Klass().doIt() From fumanchu at amor.org Tue Aug 24 21:58:56 2004 From: fumanchu at amor.org (Robert Brewer) Date: Tue, 24 Aug 2004 18:58:56 -0700 Subject: python cgi speedup on iis Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E63@exchange.hqamor.amorhq.net> Charlie Taylor wrote: > >> I'm looking for advice on how to speed up python cgi on > Windows IIS ... > > Gilles Lenfant wrote: > >Use the excellent pywin32 > >http://sourceforge.net/projects/pywin32 > >Look at the help in the "ASP and Python" section that shows > how to register > >Python as ASP engine... > > pywin32 ASP turned out to be EXACTLY what I needed. > > It took very little effort to convert my CGI scripts, and the > performance > boost was terrific. > > There are a few nagging issues regarding the reload of > modified modules. > The ASP engine often overlooks changed pyc files and > therefore does not > reload the modified modules (this requires IIS restarts), > however, it is > very good at detecting changes to the ASP files themselves. > I've taken to > debugging imported modules via CGI scripts to get around > having to restart > IIS. I ended up writing a reload tool for admins to use from the webapp itself. Lots of hooks here to functions you never heard of, but it should give you the idea: def reimport(UI): """Reload the requested module. reload = module name """ if not UI.user in UI.application.superusers: raise dejavu.AccessDeniedError redir = html.RedirectPage(UI.application) UI.write(redir.top(u'Reloading...')) # Locate the requested module. moduleName = UI.requestParams.get(u'module', u'') try: reqModule = sys.modules[moduleName] except KeyError: raise StandardError(u"Module '%s' could not be found." % moduleName) reload(reqModule) UI.write(redir.bottom(UI.root() + u'/admin.htm')) HTH, Robert Brewer MIS Amor Ministries fumanchu at amor.org From peter at engcorp.com Mon Aug 16 00:48:10 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 00:48:10 -0400 Subject: Python indentation deters newbies? In-Reply-To: <5hbvh0hnngn8sotqkgav3o1mvs61n039e5@4ax.com> References: <3064b51d.0408130615.3fc4a760@posting.google.com> <56cfb0e3.0408142004.511a8a8e@posting.google.com> <5hbvh0hnngn8sotqkgav3o1mvs61n039e5@4ax.com> Message-ID: Dennis Lee Bieber wrote: > Missed one variant ... Since the brackets are, in my mind, > noise, I prefer to keep /them/ aligned (easiest means of drawing lines > on a listing... > > if (condition) > { > stmt-1 > stmt-2 > } > else > { > stmt-3 > stmt-4 > } Missed another! (The best! ;-) if (condition) { stmt-1; stmt-2; } else { stmt-3; stmt-4; } After all, the braces are basically part of the blocks, so they really should be indented the same as the statements in the blocks. Furthermore this way it's easier to scan down to find the else or subsequent code. Basically, this way the braces don't really get in the way at all, except for using up some vertical space. -indentation-wars-backwards-r-us-ly y'rs, Peter From meastwood at sibelius.com Tue Aug 31 12:54:51 2004 From: meastwood at sibelius.com (Michael Eastwood) Date: Tue, 31 Aug 2004 16:54:51 -0000 Subject: Bundles on Mac OS X Message-ID: <006201c48f7b$3bd28be0$300110ac@aulis> Hi, Does anybody know how to copy a bundle across a network so it will run successfully on the destination machine? At the moment I am using macostools.copytree which appears to copy the entire bundle across correctly, but when I try and run it, it does absolutely nothing. I guess I could probably use the Carbon library, but as it isn't documented I don't know where to start! Any help would me much appreciated. Thanks in advance, Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: From shane.holloway at ieee.org Sun Aug 22 19:28:33 2004 From: shane.holloway at ieee.org (Shane Holloway (IEEE)) Date: Sun, 22 Aug 2004 17:28:33 -0600 Subject: Rita Sue and Bob too In-Reply-To: <27a5ac50.0408200749.a1fd32f@posting.google.com> References: <27a5ac50.0408200749.a1fd32f@posting.google.com> Message-ID: <41292C21.3090107@ieee.org> > You can do it with list List Comprehensions: > > BigList = ['Jean', 'Eric', 'Remy', 'Anne', 'Denis', 'Alain', 'Armel', > 'Louis'] > SmallList = ['Eric', 'Denis', 'Georges', 'Jean'] > > if ( [x for x in SmallList if x in BigList] == SmallList ): > print "They were found" > else: > print "They are not in list" > > > [x for x in SmallList if x in BigList] evaluates to a list with common > elements of SmallList and BigList A little change: Difference = [x for x in SmallList if x not in BigList] if not Difference: print "They were found" else: print Difference, "were not found in the list" From fuzzyman at gmail.com Thu Aug 12 07:52:27 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 12 Aug 2004 04:52:27 -0700 Subject: ClientCookie References: <6f402501.0408110018.1e4e5ca8@posting.google.com> Message-ID: <6f402501.0408120352.680496bc@posting.google.com> fuzzyman at gmail.com (Michael Foord) wrote in message news:<6f402501.0408110018.1e4e5ca8 at posting.google.com>... > Has anyone used ClientCookie to store cookies ? > I'm going to play around with 'pickling cookies' - but I wondered if > anyone had any experience of this. > > (For session persistence in approx - my cgi proxy) > > Regards, > > > Fuzzy > > http://www.voidspace.org.uk/atlantibots/pythonutils.html Ok, I've got somewhere. I'm now using the 0.9 version and I found the debugging section in the docs. I'm using the example from the docs - but I'm pickling a list of the pickles rather than using the load and save methods (as the docs suggest) because I get an NotImplemented error for the save method (so what use is the load method ?). COOKIEFILE = 'cookies.pkl' import ClientCookie openfun = ClientCookie.urlopen cj = ClientCookie.CookieJar() opener = ClientCookie.build_opener(ClientCookie.HTTPCookieProcessor(cj)) ClientCookie.install_opener(opener) if os.path.isfile(COOKIEFILE): cookies = open(COOKIEFILE, 'rb') for entry in pickle.load(cookies): cj.set_cookie(entry) cookies.close() cookies = open(COOKIEFILE, 'wb') pickle.dump([c for c in cj], cookies) cookies.close() req = ClientCookie.Request(theurl) req.add_header('User-agent', 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)') u = openfun(req) info = u.info() print HR print '
'
print info                     # print the headers
print
print 'Cookies :'
a = 0
for c in cj:
    a += 1
    print a, c.__repr__()      # print each cookie
print '
' and I'm now seeing persistent cookies..... hurrah....... Can I save each cookie as a line of text ? Would that work with the load method ? Anyway - now I need to learn about server side cookies so that I can give each user an 'id' and also write code to clean up unused cookie files... *Then* I need to do a seperate CGI that will let users 'manage' their cookies. (So I'll need to start understanding cookies a bit more) Great Regards, Fuzzy http://www.voidspace.org.uk/atlantibots/pythonutils.html From ialbert at mailblocks.com Thu Aug 19 12:31:06 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Thu, 19 Aug 2004 12:31:06 -0400 Subject: My only complaint about Python In-Reply-To: References: Message-ID: Darren Dale wrote: > I love the language. I love the community. My only complaint is that > Python for Windows is built with Visual Studio. > > It is too difficult to build python, or a module, from source. In all fairness this is more the problem with Microsoft than python. If they had a free fully-featured compiler then Python would be compiled with that. Microsoft seems to have made some half-hearted attempt in this direction so that is promising. I know that there are other compilers for windows but their market penetration is far less and thus expertise to use them is hard to come by. I myself am in a very similar position, have a hard time deploying extension modules on windows. My usual workaround is to have a second python available via cygwin where I can compile everything then then use remote procedural calls via XMPRPC to connect from the windows python. Clearly this will work only in certain cases. Istvan. From grv575 at hotmail.com Sat Aug 7 12:28:08 2004 From: grv575 at hotmail.com (grv575) Date: 7 Aug 2004 09:28:08 -0700 Subject: numarray speed question References: <953AD3D0Didtoken@128.91.2.239> <953C4DD4idtoken@128.91.2.239> Message-ID: <144d0df.0408070828.338f8c19@posting.google.com> cookedm+news at physics.mcmaster.ca (David M. Cooke) wrote in message news:... > Well, numarray probably isn't faster for this case (adding a scalar to > a vector). In fact, the relevant numarray code looks like this: > > static int add_Float64_vector_scalar(long niter, long ninargs, long noutargs, vo > id **buffers, long *bsizes) { > long i; > Float64 *tin1 = (Float64 *) buffers[0]; > Float64 tscalar = *(Float64 *) buffers[1]; > Float64 *tout = (Float64 *) buffers[2]; > > for (i=0; i *tout = *tin1 + tscalar; > } > return 0; > } OK good. So doing it in C isn't really that much of a headache when it comes to optimization. > What you *do* get with numarray is: > > 1) transparent handling of byteswapped, misaligned, discontiguous, > type-mismatched data (say, from a memory-mapped file generated on a > system with a different byte order as single-precision instead of > double-precision). Heh. Try timing the example I gave (a += 5) using byteswapped vs. byteswap(). It's fairly fast to do the byteswap. If you go the interpretation way (byteswapped) then all subsequent array operations are at least an order of magnitude slower (5 million elements test example). > 2) ease-of-use. That two lines of python code above is _it_ (except > for an 'import numarray' statement). Your C code isn't anywhere > nearly complete enough to use. You would need to add routines to > read the file, etc. Can't argue here. > 3) interactive use. You can do all this in the Python command line. If > you want to multiply instead of add, an up-arrow and some editing > will do that. With C, you'd have to recompile. As much as I hate the .edu push for interpreted languages like lisp and ml, having a python interpreter to test code out real quickly before it goes into the source script is real nice. > If you need the best possible speed (after doing it in numarray and > finding it isn't fast enough), you can write an extension module to > do that bit in C, or look into scipy.weave for inlining C code, or into > f2py for linking Fortran code to Python. Well re speed what really bothers me is the slowness in which numarray is improving in this area. If I have to take 1000 FFT's over 32 element arrays, then it's useless. I'll have to install both numarray and numeric :/ From fuf at mageo.cz Thu Aug 19 11:15:50 2004 From: fuf at mageo.cz (Michal Vitecek) Date: Thu, 19 Aug 2004 17:15:50 +0200 Subject: distutils help In-Reply-To: References: Message-ID: <20040819151550.GB24749@foof.i3.cz> Mark Jaffe wrote: >I am customizing a setup script and need to pass in some additional >parameters specifying includes and libs. The build_ext lists some user >variables such as "include-dirs" and "library-dirs" but I am unclear on >how to access these within the setup.py. Are there any distutils gurus >here? ... setup( name = "xxx", ... ext_modules = [ Extension("xxx", sources = ["a.c", "b.c",], include_dirs = [get_python_inc(plat_specific = 1), "my_own_include_dir",]), ], ) try to look at other setup.py files - they might help you a lot. -- fuf (fuf at mageo.cz) From ed-no at spam-eepatents.com Mon Aug 16 15:43:53 2004 From: ed-no at spam-eepatents.com (Ed Suominen) Date: Mon, 16 Aug 2004 12:43:53 -0700 Subject: Newbie 1st program References: Message-ID: Peter Hansen wrote: > (Congratulations, though. After six weeks of programming I'm > quite sure I wasn't capable of writing anything that would > have been worth posting to Sourceforge, had it existed at > the time.) Congratulation from me, too. After six weeks of programming, I'm also quite sure I wasn't capable of writing anything that would have been worth posting anywhere, had there been any means to do so other than saving it to the tape drive. :-) Sadly, it took about 95% of my programming lifetime before object-oriented programming came along and I (much later) truly realized what a wonder it is. --- Ed Suominen Registered Patent Agent Open-Source Software Author (yes, both...) Web Site: http://www.eepatents.com From Michael.J.Fromberger at Clothing.Dartmouth.EDU Wed Aug 18 17:42:46 2004 From: Michael.J.Fromberger at Clothing.Dartmouth.EDU (Michael J. Fromberger) Date: Wed, 18 Aug 2004 17:42:46 -0400 Subject: PEP 318: Can't we all just get along? References: <20040817181725194-0400@braeburn.themorgue.org> Message-ID: In article , aahz at pythoncraft.com (Aahz) wrote: > In article <20040817181725194-0400 at braeburn.themorgue.org>, > Kevin Smith wrote: > > > >Bear with me, but I'd like to propose one more syntax that is simple, > >easy for newbies to understand, and nowhere near as powerful as the > >current PEP's syntax. However, it doesn't add incoherent, arbitrary > >syntax either. > > > >def classmethod foo(x, y, z): > > pass > > You can't do ``grep "def foo"``; therefore, Guido rejected this. (It's > a tiny bit more complicated than that, but that's the essence.) I suppose that's understandable; but would it really be so much worse to have to write: egrep "def [_a-z0-9]* *foo" or, even grep "def" | grep "foo(" I respectfully submit that this, while it makes a certain amount of sense, is probably not a very good design criterion for new syntactic features. -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From npat at efault.net Fri Aug 13 09:04:28 2004 From: npat at efault.net (Nick Patavalis) Date: Fri, 13 Aug 2004 13:04:28 +0000 (UTC) Subject: Why I love python. References: Message-ID: On 2004-08-13, Anthony Baxter wrote: > > I'm biased, having done a paper on this at the most recent PyCon, but > I firmly believe that much of the "Python is too slow" arguments can be > answered with "too slow for what?" See the pycon proceedings, but I've > been doing VoIP in Python, complete with audio mixing, and it's been > more than fast enough. > Yes but what parts of it were done in python, and what parts were done inside modules written in C? Do you believe, for example, that a web-server written in python could outperform apache? How about an H323 implementation, or a TCP/IP stack? Or a font renderer? Or a ray-tracer? A gate-level circuit simulator? A web-browser? A relational database? > > Sure, you're not going to get great performance for your numerical > computation in Python, but luckily, we have numarray for this. > If numarray was written *in Python* I would be delighted. But even with numarray, if you want to do FFT, you do it in C, not in Python. And if FFT is not good for you and you need DCT, again in C. And if the FFT of numarray is not sufficient (e.g. you want an integer version with certain bit-exact properties), hmmm sory, you have to do it in C. At this moment Python is an excelent *glue* language for stuff written in low-level laguages. It is also an exelent prototyping language. It has a long way to go before becomming a true "production" language (in the sense outlined above). Most of this way has to do with Python *implementations* and not with Python-the-Language. But it seems that there are some steps that must be taken by the language itself in order to open the road to efficient implementations. /npat From fperez528 at yahoo.com Tue Aug 31 01:41:36 2004 From: fperez528 at yahoo.com (Fernando Perez) Date: Mon, 30 Aug 2004 23:41:36 -0600 Subject: ANN: IPython 0.6.3 Message-ID: Announcing an update to IPython, an enhanced interactive Python shell. As always, a big Thank You goes to Enthought and the SciPy crowd for hosting ipython and all its attending support services (bug tracker, mailing lists, website and downloads, etc). * WHAT is IPython? IPython tries to: 1. Provide an interactive shell superior to Python's default. IPython has many features for object introspection, system shell access, and its own special command system for adding functionality when working interactively. 2. Serve as an embeddable, ready to use interpreter for your own programs. IPython can be started with a single call from inside another program, providing access to the current namespace. 3. Offer a flexible framework which can be used as the base environment for other systems with Python as the underlying language. * WHERE to find it: http://ipython.scipy.org * Some highlights of this release (details in the changelog): 1. Matplotlib support The major new feature this time is integrated support for matplotlib (http://matplotlib.sourceforge.net). Thanks to the help of John Hunter (matplotlib's author) and others, IPython now has a new option -pylab. With this flag, it loads and configures matplotlib for interactive use, automatically adapting thread handling to whatever backend is configured in your .matplotlibrc file. This means that you can use Tk, GTK, or WX and IPython automatically handles threading for you so that the matplotlib figure windows do NOT block the shell. The matplotlib features have been tested and work fairly well under Linux, though it's quite possible that bugs remain (threading code is particularly tricky to debug). However, under Mac OSX and Windows we have run into difficulties which we don't know how to solve yet. It appears that for these platforms, at this point only the Tk/TkAgg backends work well. Anyone who works on these systems and knows about threads is welcome to help; the place to look is towards the end of Ipython/Shell.py, where all the thread-handling classes reside. I'd like to thank John for all the time he spent helping me with this. I think for those interested in scientific computing, the combination of matplotlib and ipython makes for a very interesting environment. Please note that this requires matplotlib version 0.62.4 or newer, as John and I coordinated the development of these features, and it required changes to both ipython and matplotlib. 2. GTK & WXPython threading There is also experimental, but disabled by default, support for generic (i.e. not specific to matplotlib) GTK and WX threading. Ideally, IPython should allow you to run arbitrary GTK or WX programs without blocking, and new -gthread/-wthread options were introduced for this purpose. However, this code is not working correctly and my threading knowledge is very limited. If anyone is interested in this kind of functionality, and can help with debugging, simply modify the start() function at the end of IPython/Shell.py to re-enable those options (they are commented out). At that point the threading code will become active again. Any fixes for this will be most welcome. 3. As usual, a number of fixes for recently reported bugs are also included. Enjoy, and please report any problems. Best, Fernando Perez. From ville at spammers.com Sat Aug 7 22:03:21 2004 From: ville at spammers.com (Ville Vainio) Date: 08 Aug 2004 05:03:21 +0300 Subject: Going the PL/1 way References: Message-ID: >>>>> "Jarek" == Jarek Zgoda writes: Jarek> Most of features that made into Python after 2.1 are "just Jarek> that", like "nobody has it, so we should" or "somebody has Jarek> it, so we would too". The only thing I welcomed in 2.3 was Jarek> some interpreter speedup, not new features. No way, Python 2.2 was the best thing to happen to Python so far. Jarek> Come on, guys, fix real problems like interpreter thread Jarek> safety, improve performance, don't make us, "real-world Jarek> software developers", screaming with every new release, Jarek> please. I guess this depends on the developer. I can't help lovin' stuff like genexps that are coming in 2.4, while I would harly notice GIL extermination. It's something that looks important on paper and will surely help advocacy efforts, but probably wouldn't have significant impact on the day-to-day lives of the developers. In the meantime, I don't mind the efforts to shorten that already small gap between the algorithm in my brain and what's on the editor screen. I guess this is my feeble attempt to thank the core Python developers that get all too much flak considering the good job they do. That's probably how open source works when people care deeply about the project :-). Then again, it's 5am in Finland and I'm still moderately drunk. -- Ville Vainio http://tinyurl.com/2prnb From reinhold-birkenfeld-nospam at wolke7.net Thu Aug 12 16:24:37 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Thu, 12 Aug 2004 22:24:37 +0200 Subject: decorator with keyword In-Reply-To: References: Message-ID: <2o21foF65snnU2@uni-berlin.de> Peter Hansen wrote: > Christopher T King wrote: > > [about the "decorate:" syntax] >> The PythonDecorators wiki doesn't say Guido has specifically shot this >> style down, so it may yet have a chance. > > The python-dev mailing list doesn't appear to have discussed this one > yet, but given that much of the, uh, "chatter" that I detect there > is about minor tweaking of the @pie syntax, I fear they are so not > likely to pay much attention to new syntaxes and it might be too > late to get much support for it amongst the core folks. (Guido > referred to @pie as "the humble @decorator" yesterday...) I'm sure it would help if every supporter of this syntax started a thread of his own on python-dev *wink* Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From esj at harvee.org Fri Aug 20 10:32:20 2004 From: esj at harvee.org (Eric S. Johansson) Date: Fri, 20 Aug 2004 10:32:20 -0400 Subject: age of Python programmers In-Reply-To: <10i7da3cu03eabb@corp.supernews.com> References: <10i7da3cu03eabb@corp.supernews.com> Message-ID: when I first saw the title, I thought it was along the same theme as the "age of dinosaurs" or some such thing. but my answer is just 48, two years, more languages and I care to think about including mess of assembly languages, tpl (a weird form of ratfor), and pl/1 subset g. Python made it possible for me to write code again. After 18 years of programming, RSI went critical and I stopped programming pretty much for about 10 years. Python syntax is simple enough that I can, with proper variable naming patterns, write code. The 5000+ lines of code and comment in the camram project are proof of that. I do wish there was better handicap accessibility for programming as there are a bunch of us damaged programmers about to undertake a rather significant project, namely making speech recognition work on Linux. The details a boring if you're not interested so I will spare you but this project is essential for those of us wishing for a choice in our development environments. ---eric -- Speech recognition in use. It makes mistakes, I correct most From des.small at bristol.ac.uk Tue Aug 24 10:28:20 2004 From: des.small at bristol.ac.uk (Des Small) Date: Tue, 24 Aug 2004 14:28:20 GMT Subject: Regular expression guaranteed to fail References: <96jmi0pt39frp5n3r34afrt21cfeclp0mi@4ax.com> Message-ID: Greg Chapman writes: > On 22 Aug 2004 20:07:51 +0200, Hallvard B Furuseth > wrote: > > >Eric Brunel wrote: > > > >> I also looked for a never-matching re just a few days ago and > >> ended up with "^(?!$)$". It's certainly not more "standard" than > >> yours, but I find it a wee tad more readable (for a regular > >> expression, I mean...): > > > >I think e.g. r'\Zx' and r'x\A' are more readable. In particular > >the latter, but perhaps that causes Python to locate every 'x' in > >the string and then check if the string starts at the next > >character... > > Why not just "(?!)": this always fails immediately (since an empty > pattern matches any string, the negation of an empty pattern match > always fails). I think we have a winner! Des thanks all the persons who contributed, of course. -- "[T]he structural trend in linguistics which took root with the International Congresses of the twenties and early thirties [...] had close and effective connections with phenomenology in its Husserlian and Hegelian versions." -- Roman Jakobson From mcfletch at rogers.com Wed Aug 18 22:36:17 2004 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Wed, 18 Aug 2004 22:36:17 -0400 Subject: metaclass ??? In-Reply-To: <20040819015843.22FF025CDD@smaug.vex.net> References: <20040819015843.22FF025CDD@smaug.vex.net> Message-ID: <41241221.2080404@rogers.com> BruceKL WhoH wrote: ... > What I'm trying to do is : > I want to make two class, they are just subtly different,for example > > ... >all other codes are identical,just f is different. > So can I use meta-class here? Or I should do this by another way? > > If this is the entire specification of what you need to do, it really seems as though you'd be better off with mix-in classes. Your code would then look like this: class Base: """Base class providing common functionality""" # your shared code here class A( Base ): """Overrides method f only""" def f(self): print 'a' class B( Base ): """Overrides method f only""" def f(self): print 'b' The first page of the presentation is intended to warn you that, in general, most programmers never need to use metaclasses, even after years of work in the language. The use cases for them are fairly exotic, not the kind of thing you find in "normal" programming operations. There are cases where you might want to use metaclasses to inject a method into a class (as covered in the presentation), but those use-cases tend to be more involved than simply wanting to have 1 method change. Those cases are normally going to involve making a *decision* at run-time as to which method implementation to include, for instance based on the presence/absence of other methods or a data-attribute of the class. > BTW,your pdf is quite nice,how do you make it? Beamer,pdfscreen, or PPT ? > > OpenOffice.org Presenter (PowerPoint-like app) has a built-in export to PDF. Have fun, Mike ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From FBatista at uniFON.com.ar Fri Aug 27 09:19:37 2004 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Fri, 27 Aug 2004 10:19:37 -0300 Subject: Call for signatories for J2 Message-ID: [Robert Brewer] #- The J2 proposal is as complete as it will ever be. #- #- http://www.aminus.org/rbre/python/pydec.html Great work! #- This is a call for all who wish to sign the proposal, either for, #- against, or abstaining. Please sign by either posting on I'm FOR it. Full name: Facundo Batista Regards, . Facundo From tom at scoosh.com Wed Aug 18 17:48:52 2004 From: tom at scoosh.com (tom at scoosh.com) Date: Wed, 18 Aug 2004 22:48:52 +0100 Subject: 654 Message-ID: From jack at performancedrivers.com Wed Aug 18 17:52:32 2004 From: jack at performancedrivers.com (Jack Diederich) Date: Wed, 18 Aug 2004 17:52:32 -0400 Subject: Decorators: an outsider's perspective In-Reply-To: References: <20040814153534.8AC171E4007@bag.python.org> Message-ID: <20040818215232.GB23725@performancedrivers.com> On Tue, Aug 17, 2004 at 04:25:51PM -0400, Aahz wrote: > In article , > Anthony Baxter wrote: > > > >I know that. When writing something as obviously taking the piss as my > >comment, I don't think it's necessarily to include a smiley - that's > >for the people who don't get humour, like Americans. > > No, no, no, Americans get humor just fine -- what they don't get is > irony. Anyone remember that small study that ranked 'funniest' jokes by nationality? [little bit of googling] http://www.laughlab.co.uk/ Top American joke: A man and a friend are playing golf one day at their local golf course. One of the guys is about to chip onto the green when he sees a long funeral procession on the road next to the course. He stops in mid-swing, takes off his golf cap, closes his eyes, and bows down in prayer. His friend says: Wow, that is the most thoughtful and touching thing I have ever seen. You truly are a kind man. The man then replies: Yeah, well we were married 35 years. I'd chalk that up to irony. But all the "best of" jokes had a few out of the set of irony, wordplay, misogyny, and absurdity. And it was a small sample, and it was a self selected group, and ... Well, studies are only science sometimes. The country results ended up with Germans having little sense of humor (they thought everything was funny) to Canadians being the most picky. Most "American" comedians are from Canada (SCTV, SNL) so that at least jives with my personal experience. That post was too long, -Jack NB, and as an American with a German ancestry [check the last name] I'm conflicted. From arien_malec at yahoo.com.REMOVE Mon Aug 23 13:14:23 2004 From: arien_malec at yahoo.com.REMOVE (Arien Malec) Date: Mon, 23 Aug 2004 17:14:23 GMT Subject: [PATCH] RE: J2 decorator grammar References: <412889c8$0$81159$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: Michael Sparks wrote in news:412889c8$0$81159$ed2619ec at ptn-nntp-reader02.plus.net: > So some other keyword is definitely preferable. Currently I'm swayed > heavily by arguments in favour of "using" [...] "using" doesn't make the semantics clear. The naming for "decorators" should be influenced not only by the basic use cases (in which the function is annotated with metadata), but also the more edge-pushing use cases, like classmethod, in which the semantics of the function are changed. Me, I like: "transform:"... Arien From jdhunter at ace.bsd.uchicago.edu Fri Aug 20 21:28:44 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Fri, 20 Aug 2004 20:28:44 -0500 Subject: age of Python programmers In-Reply-To: (Roel Schroeven's message of "Fri, 20 Aug 2004 15:37:21 GMT") References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: >>>>> "Roel" == Roel Schroeven writes: Roel> I thought it would be fairly obvious, but I added labels Roel> anyway. I'm not satisfied with there positioning though, and Roel> I don't know how to correct it (it's the first time ever I Roel> use matplotlib). How would you like them to be different? They look pretty good to me.... :-) JDH From dody at postaccesslite.com Fri Aug 27 00:42:22 2004 From: dody at postaccesslite.com (dody) Date: Fri, 27 Aug 2004 11:42:22 +0700 Subject: ASPN Python cookbook in a chm In-Reply-To: <8d3e714e.0408261437.3b53c413@posting.google.com> References: <8d3e714e.0408261437.3b53c413@posting.google.com> Message-ID: <50498806.20040827114222@postaccesslite.com> of course not :) here you go. sorry, it's a little bit messy. > Thanks a lot !!! > This should be included in the next Python distribution! > Would you mind posting the script tha mde the CHM file ? (unless you > did it in Perl) :-) -------------- next part -------------- A non-text attachment was scrubbed... Name: cookbookgenerator.py Type: application/octet-stream Size: 9003 bytes Desc: not available URL: From jburns131 at adelphia.net Tue Aug 10 22:24:48 2004 From: jburns131 at adelphia.net (Jesse B.) Date: Tue, 10 Aug 2004 19:24:48 -0700 Subject: IDLE vs Command Line Message-ID: <8PidncxTb4muxITcRVn-oQ@adelphia.com> I like to work with xemacs, so I've been coding modules with xemacs and running them using the dos prompt (using windows port of xemacs). Some scripts that work fine with IDLE don't work at the dos prompt. For example: import random for i in range(10): x = random.random() print x This simple script doesn't work if I use the command prompt, with this syntax: python random.py I am just wondering why that is. From me at privacy.net Sat Aug 28 17:05:28 2004 From: me at privacy.net (Richard Hanson) Date: Sat, 28 Aug 2004 14:05:28 -0700 Subject: MSI Installer Problem: can't install 2.4a2 on new install of Win2kSP2 References: <412d7dcd$0$26184$9b622d9e@news.freenet.de> <412e5452$0$24835$9b622d9e@news.freenet.de> <92uui05l49lurff1depfmvblq8esqllcpg@4ax.com> <412f8ebd$0$13030$9b622d9e@news.freenet.de> Message-ID: [Dual-booting Python 2.3.4 on Win98, and Python 2.3.4 and 2.4a2 on new install of Win2k. Initial install of 2.4a2 on Win2k didn't work, but now is. Strangeness noted. Ongoing discussion:] Martin v. L?wis wrote: >I'm not quite sure why you have the Win98 path in W2k, but it may be >that W2k also executes certain autoexec things. [FWIW, more testing this morning, unsure of its the relevancy:] First, I searched the Fujitsu's Win2k (E:) partition for "autoexec" and only turned up "autoexec.nt" which is the same as the autoexec file found on my HP laptop's Win2k. Nothing unusual noted there. Then, I decided to try and "break" Win2k's 2.4a2 again by putting Python back into the Win98 (C:) partition's PATH -- today, that *didn't* break Win2k's 2.4a2. I next cleaned up Win98's PATH of other extraneous entries, but left the Python entry in Win98's PATH for testing purposes. No change noted with this step -- Python 2.3.4's IDLE still worked booting into Win98, and 2.4a2's IDLE still worked booting into Win2k. Thinking that the problem may only crop up with the initial installation of 2.4a2 under my dual-booting conditions, I uninstalled Python 2.4a2 (Win2k's 2.3.4 already being uninstalled) from E:'s Win2k. I then checked the registry. The registry still had a few references to Python 2.4 as well as several to Python 2.3 in places other than MRUs, etc. For example, the Python file associations were still in the registry, and Python 2.4 appeared in branches labeled "Shell" and such. The desktop icons to things Python also still retained their usual Python appearance. Not being familiar enough, I tried no manual removal of the Python entries from Win2k's registry. I did try MS's RegClean 4.1a and another registry cleaner, but the Python entries remained. Nonetheless, I reinstalled 2.4a2, and again IDLE works with Python 2.3 in the other OS's partition. (I'm still picking up my Win98's PATH in my Win2k's PATH using "path" at a cmd.exe console, however...?) A more complete testing will have to wait till I get a new harddrive and again reinstall. (I can't *wait*! ) >> [...] I don't understand why having a separate OS on a different >> partition affected 2.4a2 on Win2k as above (remembering that 2.3.4 on >> Win2k worked fine with that configuration) [...] > >That might be a subtle bug. Python tries to find out its own executable >path name, in order to find the location to the Python installation. It >considers two alternatives >a) argv[0] contains a \. If so, python.exe was fully qualified, so we > know the path. >b) if there is no \, python.exe must be on the PATH. So we look there, > and find one in C:\python23, and believe this is us. This logic is > flawed, as we should *first* look into the current directory (I > think) > > From then on, everything fails: we load the 2.3 library, which has a >different sre version. So regular expressions don't work, and that >causes pretty much everything to break. Check. I follow up to here -- thanks! >What surprises me, though, that this algorithm is *only* executed >if GetModuleFileName fails, which should not happen in your case... But now I'm way over my depth -- and today's further testing only made things more murky for me, alas. (If I discover anything else that seems relevant to me in my ignorance, I'll post -- also, alas. ) At any rate, thanks, Martin, for taking the time to help edify me a little about the nuts-and-bolts of Python. I'm just glad that things are currently working! :-) Best regards, Richard -- email works if unmunged: sickolefartnewsguycom From fumanchu at amor.org Mon Aug 9 19:55:22 2004 From: fumanchu at amor.org (Robert Brewer) Date: Mon, 9 Aug 2004 16:55:22 -0700 Subject: Popular Python projects with lots of pure Python code Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022DEA@exchange.hqamor.amorhq.net> Brett C. wrote: > For my thesis (once the bloody thing stops throwing bugs at me) I am > going to need to collect stats on the frequency that atomic types in > local variables are applied to various opcodes and methods. > That means that I need something to collect stats off of. > > So I am trying to come up with a list of projects I can use to get my > stats from. the stdlib is a no-brainer. Also plan to use Docutils. > But beyond those most of the big Python projects I can think > of have a > ton of C code which is of no use to me. I don't need to be > able to run > it, just going to be compiling to .py files. > > Any suggestions? If you need just stats (without drilling down into code to interpret those stats), you might package up your stat-generation code and hand it out on c.l.p. That way, I and many others could run it against our proprietary code and just give you results without exposing source code. Might be a way to get a broader range of results--most of the "big projects" in the wild are frameworks, not apps. Robert Brewer MIS Amor Ministries fumanchu at amor.org From dw at botanicus.net Mon Aug 30 04:27:01 2004 From: dw at botanicus.net (David Wilson) Date: Mon, 30 Aug 2004 09:27:01 +0100 Subject: The voodoo of zip(*someList) In-Reply-To: References: Message-ID: <4132E4D5.6050801@botanicus.net> Message Drop Box wrote: >All, > >How (and why) does zip(*someList) work? > > > >>>>s = [[1, 2, 3], ['one', 'two', 'three'], ['I', 'II', 'III']] >>>>zip(*s) >>>> >>>> >[(1, 'one', 'I'), (2, 'two', 'II'), (3, 'three', 'III')] > >I've never seen the star '*' outside of function/method definitions >and I've looked in the Python documentation without success. This >syntax is voodoo to me at the moment. I'm stumped. > >Thanks, >Stuart > > Help on built-in function zip: zip(...) zip(seq1 [, seq2 [...]]) -> [(seq1[0], seq2[0] ...), (...)] Return a list of tuples, where each tuple contains the i-th element from each of the argument sequences. The returned list is truncated in length to the length of the shortest argument sequence. On the asterisk syntax: http://docs.python.org/tut/node6.html#SECTION006730000000000000000 http://docs.python.org/ref/calls.html Basically, your_sequence = [ 1, 2, 3, 4 ] zip(*your_sequence) is equivalent to: zip(1, 2, 3, 4) In other words, it allows you to programmatically build an argument list. Similarly, your_mapping = { 'cmpfunc': lambda x: x } some_list = [ 3, 1, 6, 2 ] some_list.sort(**your_mapping) is equivalent to: zip(cmpfunc = lambda x: x) The zip function takes an item from each of the sequences given as arguments, and packs them into a tuple, continuing until the sequences are exhausted. seq1 = [ 1, 2, 3, 4 ] seq2 = [ 4, 3, 2, 1 ] seq3 = "dave" zip(seq1, seq2) is: [ (1, 4), (2, 3), (3, 2), (4, 1) ] zip(seq1, seq2, seq3) is: [ (1, 4, "d"), (2, 3, "a"), (3, 2, "v"), (4, 1, "e") ] There is also an itertools.izip which does the same thing in a generator. HTH, David. From cito at online.de Fri Aug 13 00:59:16 2004 From: cito at online.de (Christoph Zwerschke) Date: Fri, 13 Aug 2004 06:59:16 +0200 Subject: multiline snippets with triple quotes References: Message-ID: > The textwrap.dedent() function is provided for just this purpose: Thanks. That was the thing I was looking for, though it's a big ugly, plus it eats some unnecessary CPU cycles at run time. But I think one can live with that. Chris From martin at v.loewis.de Mon Aug 30 02:43:44 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 30 Aug 2004 08:43:44 +0200 Subject: would be nice: import from archive In-Reply-To: <7x1xhqg3kb.fsf@ruckus.brouhaha.com> References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <7xzn4gwgea.fsf@ruckus.brouhaha.com> <1gj7a1o.1a5d2q410jsn2kN%aleaxit@yahoo.com> <7xisb4xnh5.fsf@ruckus.brouhaha.com> <1gj7c1a.tfdm14p3hclcN%aleaxit@yahoo.com> <7xd61benm9.fsf@ruckus.brouhaha.com> <1gj82n3.1ylkr3nierngmN%aleaxit@yahoo.com> <7xd61b8uh2.fsf@ruckus.brouhaha.com> <7x1xhqg3kb.fsf@ruckus.brouhaha.com> Message-ID: <4132cc9d$0$26202$9b622d9e@news.freenet.de> Paul Rubin wrote: > so you could say > import x(signed) > or > import x(signed, certfile='mycerts.pem') > > or whatever. I believe that import is the wrong point in time for checking signatures. You want to check the signature when the file is added to sys.path, i.e. imp.verify_signature(filename) sys.path.append(filename) or imp.verify_all_signatures(sys.path) That way, you can guarantee that trusted code is on sys.path all the time. Then, you can also trust any import statement. Regards, Martin From roy at panix.com Sat Aug 21 15:18:42 2004 From: roy at panix.com (Roy Smith) Date: Sat, 21 Aug 2004 15:18:42 -0400 Subject: age of Python programmers References: <41245e57$0$29668$636a15ce@news.free.fr> Message-ID: Alan Gauld wrote: > I'm 46, started programming in 74 in BASIC (dunno what machine, > it was located at the local university and we downloaded the > programs from a teletype over a modem(120 baud) and got back > printouts 3 days later...) Basic in 1974 sounds just like where I got started. We had a teletype too (the modem was 110 baud, BTW, not 120), but we were connected to another regional high school's time sharing system (an HP-3000, IIRC), so we got our stuff immediately. Oh, oh, oh, oh, stayin' on-line, stayin' on-line! Since then, I've done Fortran, lisp, a few different flavors of assembler, C, C++, Java, HyperCard/SuperCard, TCL, Perl, Postscript (yes, it's a real programming language) and of course Python. Oh, and NewtonTalk. How could I forget NewtonTalk :-) And a few different HP calculator languages. From kaede.news at online.ru Tue Aug 31 23:41:22 2004 From: kaede.news at online.ru (Eugene Morozov) Date: Wed, 01 Sep 2004 07:41:22 +0400 Subject: GUI Designer References: Message-ID: <87n00azme5.fsf@nezumi.home.spb> Doug Holton writes: > A.M wrote: >> Hi, >> Do we have any OpenSource GUI designer for Python ? > > It depends on whether you are running Windows or Linux/Mac, and what > GUI toolkit you want to use (wxpython, qt, gtk, tkinter, > windows.forms, etc.). > > If you are on Linux, a good GUI builder you might try is QT > Designer. There is a Windows version, too, but you only use it for > non-commercial development. See http://developers.coedit.net/QtKde > I think that Qt Designer is not the best choice. For example if you want to add widget in already designed layout, you'll have to break all layouts first and start packing widgets from scratch. Eugene -- Email: eugene @ renice.org From vinay_sajip at yahoo.co.uk Tue Aug 24 10:05:50 2004 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: 24 Aug 2004 07:05:50 -0700 Subject: logging package log_test3.py problem References: Message-ID: <2e37dc1.0408240605.2d7848fd@posting.google.com> > I expect the Windows NT EventLog handler to fail since I am running under an > account that does not have Windows Registry update privileges. > > However, I did not expect to see the message: > > No handlers could be found for logger "root" This appears to be a bug in fileConfig exception handling. I'll look into it. > Also, I have not been able to get a demo script to work that uses > logging.config.fileConfig with custom handlers I have written. Is this > permissable? If so, how? Here is a sample error I'm seeing: > > NameError: name 'Details_Log' is not defined If your custom handler Details_Log is defined in module "mymodule" then in the config file, name the handler as e.g. mymodule.Details_Log. Then, do import logging import mymodule logging.mymodule = mymodule Then fileConfig() should work. The reason for all this is that fileConfig evaluates the string "mymodule.Details_Log" in the namespace of the logging module. By adding the "logging.mymodule = mymodule" line, you allow logging to know about the "mymodule" module. Best regards Vinay Sajip From alikakakhel3 at hotmail.com Sun Aug 15 22:19:57 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 15 Aug 2004 19:19:57 -0700 Subject: how to display unicode in a Label in Tkinter Message-ID: <8f17f4bc.0408151819.c06a79e@posting.google.com> I was wondering how one would go about displaying unicode in a Label object in a Tkinter window. I am trying to display text in another language. Please help. From peter at engcorp.com Thu Aug 26 08:54:13 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 26 Aug 2004 08:54:13 -0400 Subject: vars() and dir() In-Reply-To: References: Message-ID: Claire wrote: > i use vars() or dir() to get variables. I use them in a def block, so > i get variables of that block. How can i get variables from the > namespace __main__ ? vars(__main__) or dir(__main__) works if you import __main__ first. > I use python in interactive mode and want to have a function to get a > dictionnary for python types (int, ...) and another for my types (my > classes). this function will be in my pythonstartup file. > > If i use python in interactive mode, is there a main module defined ? Yes, but you always have to import stuff before you can use it. Do import __main__ and it gives you an alias for the current namespace, but the result is the same as using plain vars() or dir() there. > i don't know how to use namespace __main__ to get information on this > "global namespace" like i can do with math or another module No difference, just import first. If this doesn't help, please try explaining further what you are trying to accomplish. I don't think it's entirely clear from what you have said above. -Peter From shalabh at cafepy.com Mon Aug 23 17:24:52 2004 From: shalabh at cafepy.com (Shalabh Chaturvedi) Date: Mon, 23 Aug 2004 14:24:52 -0700 Subject: J2 paper 0.2.1 In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022E36@exchange.hqamor.amorhq.net> References: <3A81C87DC164034AA4E2DDFE11D258E3022E36@exchange.hqamor.amorhq.net> Message-ID: <412A60A4.6020601@cafepy.com> Robert Brewer wrote: > The first draft of the J2 proposal is ready. You can read it here: > http://www.aminus.org/rbre/python/pydec.html > > At this point, I am looking for comments regarding the proposal. Good work! I raise some concerns but don't claim to offer solutions (that I leave to others :). I.3 Additional Benifits: 1. Within a suite, my editor (and many Python editors) indents code to 4 spaces. This aligns the decorators with the function name itself, due to which the function name gets a little lost. In fact, this happens in your examples as well. 2. Using '|' instead of '@' in the example reduces the visual readability advantage of the suite version IMO. 3. Nitpick. Since you are selling to GvR, it might be nice to spell his name correctly in the code examples :) Use lowercase 'v' in van when writing the full name. III Choosing a keyword: 1. "Reads correctly" but only if you know that 'using' preceeds the definition. using: classmethod def foo(cls): pass using: staticmethod def bar(): pass Using classmethod def foo or def foo using staticmethod? 2. "Should be easy to search for, in both docs and Google." Hmm, 'Python using' is more likely to show irrelevant results than, say, 'Python predef'. 3. Because of above I'd favour the 'predef' keyword. It has almost all the advantages you list for 'using', and a few more. I don't mind the @ syntax at all, but I'll consider signing the proposal as an alternative since I now think it to be at least as good. Perhaps only if you change the keyword . Cheers, Shalabh From squirrel at WPI.EDU Wed Aug 11 11:58:26 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Wed, 11 Aug 2004 11:58:26 -0400 Subject: Yet another decorator proposal In-Reply-To: References: <2ntvn1F4mgskU1@uni-berlin.de> Message-ID: On Wed, 11 Aug 2004, Marco Aschwanden wrote: > On Wed, 11 Aug 2004 10:55:40 -0400, Christopher T King > wrote: > > > Also, don't forget docstrings get thrown away when using python -OO. > > Great voodoo would be needed to prevent this from happening. > > Like I said, great voodoo ;) From eppstein at ics.uci.edu Mon Aug 23 16:49:17 2004 From: eppstein at ics.uci.edu (David Eppstein) Date: Mon, 23 Aug 2004 13:49:17 -0700 Subject: Standard graph API? References: Message-ID: In article , mlh at furu.idi.ntnu.no (Magnus Lie Hetland) wrote: > >- It doesn't directly represent multigraphs > > Unless you insist on having neighbor-sets, it does, doesn't it? > Neighbor-lists can be used for this...? If you're doing anything serious with a multigraph you need to have some way of distinguishing different edges between the same pair of vertices. For instance, an edge object for each edge, that you can use as an index to store information about that edge. A neighbor list that has multiple copies of the same neighbor won't let you do that, you can iterate through the edges but not distinguish one from another. Another possibility, which fits into the same general abstract API but is more specialized, would be to represent a multigraph by a dict of dicts, where the outer dict maps each vertex to its neighbors and the inner dict maps each neighbor to the number of edges; then you could represent each edge by a tuple (v,w,index) with index in range(G[v][w]). -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ From areiner at tph.tuwien.ac.at Thu Aug 26 17:11:55 2004 From: areiner at tph.tuwien.ac.at (Albert Reiner) Date: 26 Aug 2004 23:11:55 +0200 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: ["Michiel Borkent" , Thu, 26 Aug 2004 13:35:38 +0200]: > LISP and Esperanto: my favorite languages. Ankaux miaj - krom, eble, ankaux la Haskella. Stranga koncentrigxo de verdlingvanoj cxe cll, cxu ne? Albert. From squirrel at WPI.EDU Tue Aug 10 15:26:52 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 10 Aug 2004 15:26:52 -0400 Subject: Prothon is switching to the .NET platform In-Reply-To: References: <000401c47b59$32539220$0d01a8c0@MarkVaio> <10h7lb21dhbuc12@news.supernews.com> <10h7rittck6ct75@news.supernews.com> Message-ID: On Sat, 7 Aug 2004, Peter Otten wrote: > This means that an object sees all changes in its prototypes until > explicitly assigned an attribute. Is this intentional? (real question, I'm > not familiar with prototyped languages) Fully intentional -- that's one of the benefits of prototyped languages! If you didn't want ancestral changes reflected in an object, then you would copy the object instead of deriving from it. From alikakakhel3 at hotmail.com Sat Aug 14 23:32:49 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 14 Aug 2004 20:32:49 -0700 Subject: Anyone use VPython? Message-ID: <8f17f4bc.0408141932.46b7c405@posting.google.com> Anyone use VPython? From jfl at webcom.dk Thu Aug 5 08:03:20 2004 From: jfl at webcom.dk (Jacob Friis Larsen) Date: Thu, 05 Aug 2004 14:03:20 +0200 Subject: Freelance job: Store Universal Feed Parser data in MySQL In-Reply-To: <20040805112023.D82A2235DAC@web1.webalogic.com> References: <20040805112023.D82A2235DAC@web1.webalogic.com> Message-ID: <41122208.30400@webcom.dk> Anyone interested in a freelance job like this? > Category Python > Amount Offer wanted > > I need a Python script that stores all data from UFP (http://feedparser.org/) in a MySQL database. > > All feeds are stored locally, and updated every hour or more often. Thus the script must run every hour or as often as possible. > All data from all feeds must be stores in MySQL. Old feed data should never be deleted. > > Let me know if you need more info. > > http://www.sharksforum.com/q/698 From sharidas at zeomega.com Thu Aug 19 03:48:24 2004 From: sharidas at zeomega.com (Satchidanand Haridas) Date: Thu, 19 Aug 2004 13:18:24 +0530 Subject: inverse of izip In-Reply-To: References: Message-ID: <41245B48.3020000@zeomega.com> Hi, How about using iter() to get another solution like the following: >>> starzip2 = lambda it: tuple([iter(x) for x in itertools.izip(*it)]) >>> l,m = starzip2(itertools.izip(range(10),range(10))) >>> l >>> m >>> list(l) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> list(m) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Thanks, Satchit ---- Satchidanand Haridas (sharidas at zeomega dot com) ZeOmega (www.zeomega.com) Open Minds' Open Solutions #20,Rajalakshmi Plaza, South End Road, Basavanagudi, Bangalore-560 004, India Steven Bethard wrote: >Steven Bethard gmail.com> writes: > > >>What's the inverse of izip? Of course, I could use zip(*) or izip(*), >>e.g.: >> >> >> >>>>>zip(*itertools.izip(range(10), range(10))) >>>>> >>>>> >>[(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)] >> >> >>>>>x, y = itertools.izip(*itertools.izip(range(10), range(10))) >>>>>x, y >>>>> >>>>> >>((0, 1, 2, 3, 4, 5, 6, 7, 8, 9), (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)) >> >>But then I get a pair of tuples, not a pair of iterators. Basically, >>I want to convert an iterator of tuples into a tuple of iterators. >> >> > >Sorry to respond to myself, but after playing around with itertools for a >while, this seems to work: > > > >>>>import itertools >>>>starzip = lambda iterables: ((tuple[i] for tuple in itr) for i, itr in >>>> >>>> >enumerate(itertools.tee(iterables))) > > >>>>starzip(itertools.izip(range(10), range(10))) >>>> >>>> > > > >>>>x, y = starzip(itertools.izip(range(10), range(10))) >>>>x >>>> >>>> > > > >>>>y >>>> >>>> > > > >>>>list(x) >>>> >>>> >[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > > >>>>list(y) >>>> >>>> >[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > >Seems like a bit of work for the inverse of izip though so I'll wait to see if >anyone else has a better solution. (Not to mention, it wouldn't be a single >line solution if I wasn't using 2.4...) > >Steve > > > > From squirrel at WPI.EDU Tue Aug 17 09:12:46 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 17 Aug 2004 09:12:46 -0400 Subject: How big can a Python program be? In-Reply-To: <903b3fba.0408170333.49ce3944@posting.google.com> References: <903b3fba.0408170333.49ce3944@posting.google.com> Message-ID: On 17 Aug 2004 vronskij at post.sk wrote: > Suppose , you are a sole programmer (lonewolf). How many lines can one > handle? $ wc -l my_current_big_project_that_is_very_far_from_being_complete/* 2945 I'm sure others can do better than that. From ccurvey at earthlink.net Sun Aug 29 20:36:53 2004 From: ccurvey at earthlink.net (Chris Curvey) Date: Mon, 30 Aug 2004 00:36:53 GMT Subject: cPickle and __getattr__ In-Reply-To: References: Message-ID: > > Potentially lots of things. But the problem isn't that cPickle is > calling __getattr__, exactly. The problem is that your __getattr__ > isn't properly signalling non-existent attributes. You should raise > AttributeError instead of implicitly returning None for which there is > no attribute. Adding "raise AttributeError(name)" to the end of the > definition unbreaks it enough to let pickle work. > Ah, that's it. Many thanks! From maxwell at ldc.upenn.edu Tue Aug 31 15:51:21 2004 From: maxwell at ldc.upenn.edu (Mike Maxwell) Date: 31 Aug 2004 12:51:21 -0700 Subject: -c input Message-ID: <367a4461.0408311151.59b61f54@posting.google.com> python -c "print 'hi'; for i in [1,2]: print i" gives me an invalid syntax error, with the carat pointing to the end of the word 'for'. But python -c "print 'hi'; print 'i'" works fine, as does python -c "for i in [1,2]: print i" What gives? Why can't 'for' appear after a semicolon? (Similar for 'while'.) If there's some reason the 'for' can't be made to work after the semicolon, is there some simple way to get a newline into the string on the cmd line? (short of using 'echo' twice, or putting the commands into a file) (I've tested this in v2.3.3 under both CygWin and Linux.) From rogerb at rogerbinns.com Tue Aug 10 19:15:23 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Tue, 10 Aug 2004 16:15:23 -0700 Subject: Printing in Python References: Message-ID: uri bushey wrote: > I am trying to print the contents of the WaveSurfer canvas. Is there > an easy way to do this in Python? Also, I can pretty easily use the > WaveSurfer "print" function in my program, but taht only prints to a > PostScript printer or prints out a PostScript file. Printing was one major reason I dumped Tkinter in favour of wxPython which does the printing side on all platforms well. > I would like to automate the process of printing the PostScript file > in a manner that is not terribly unwieldy and as transparent to the > user as possible. Is this possible? On Windows, users can install PDFCreator and associate it with .ps files. You may also want to look to see if you can generate PDF instead of postscript (eg reportlab). Roger From raims at dot.com Sun Aug 1 18:14:10 2004 From: raims at dot.com (Lawrence Oluyede) Date: Mon, 2 Aug 2004 00:14:10 +0200 Subject: Module for converting XML to Python object(s)? References: Message-ID: In data Sun, 1 Aug 2004 17:42:14 -0400, Robert Oschler ha scritto: > Has anybody seen a Python module that will take an XML document (not a > colossal one), and convert it to a Python nested class object? Maybe this can help you: http://xmlobject.base-art.net/ -- Lawrence (l dot oluyede at virgilio dot it) "In IE we trust" From peter at engcorp.com Mon Aug 9 08:33:45 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 09 Aug 2004 08:33:45 -0400 Subject: PEP-0318 In-Reply-To: References: <41122FC2.1080608@interlink.com.au> <4114152f@nntp.zianet.com> <4116bc20$1@nntp.zianet.com> Message-ID: <6NCdncg4ssq28orcRVn-uQ@powergate.ca> Arthur wrote: > On the other hand, when I # comment a function, my instinct has always > been to place the comment directly above the function, rather than in > the body. Which I seem to think is common practice. So I need to > admit that with the freedom to comment anywhere, the fact that > instinct, and nothing but, has led me to place it outside and above > the body perhaps sabotages, a bit, my own and others position that > decorators outside and above the function is somehow unnatural. Comments are not decorators, and vice versa. Editing tools have been evolved to subtly de-emphasize comments, often, so that even when they appear above a function def they do not inhibit (much) the process of finding the function def when one scans the code. Comments above the code are generally ignored, while decorators may well be highly significant in the new world order. Some people eschew comments above the functions and use only doc-comments in Python, partly to avoid the situation where the comments would obscure the function def. It's probably not instinct, but experience (reading others' code) that has led you to put the comments above function. All in all, I'm not sure any of the points you raise sabotage the position that decorators above the function are somehow unnatural. Unfortunately, decorators in the function are also unnatural. In fact, they really need a separate dimension, but unfortunately we're using a 2D system to describe them and probably have to make a choice. After, within, or before. After is right out now, it seems. Within has been discussed, and while many of us still find it has the greatest merit (in the form of list-after-def), those who argue it _can be_ harder to find speak the truth. (Many of us say "so what" to that, and still think the elegance and other advantages of the approach outweigh that argument, but we're not going to succeed with our argument. :-) Therefore it will be before... the only important choice left seems to be what bizarre and arbitrary punctuation symbol will be chosen for the purpose. (To be fair, it's not "arbitrary" any more: clearly the sole requirement for this is how loud and in-your-face the decorator symbol will be. I don't know when this sort of thing became considered good style for Python, but this too is the new world order.) -Peter From peter at engcorp.com Tue Aug 24 08:48:58 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 24 Aug 2004 08:48:58 -0400 Subject: How does a "script" differ from a "program" or "subroutine"? In-Reply-To: <56cfb0e3.0408232247.2df68078@posting.google.com> References: <56cfb0e3.0408232247.2df68078@posting.google.com> Message-ID: Porky Pig Jr wrote: > Phil Frost wrote in message news:... >>A script is just a program, but has the implication that it's a simple >>program for a simple task. >> > I think the major implication is not that it's simple but it's written > in some 'interpreted' (rather than compiled) language. so we say > Python or Perl or Bash script, but not 'C script'. Look at the job > openings: you'll often see something like this: 'knowledge of > scripting languages (such as Perl and/or Python)'. Before this explodes into another long thread, please check the archives for this newsgroup if you have any interest in this topic. It has been discussed at length, and both Phil's and Porky Pig's responses have been posted before, along with others (which I have a feeling we're about to see yet again from other people in spite of this post... ;-). -Peter From grzegorz at ee.ualberta.ca Fri Aug 6 12:34:47 2004 From: grzegorz at ee.ualberta.ca (Grzegorz Dostatni) Date: Fri, 6 Aug 2004 12:34:47 -0400 Subject: Extending python. Message-ID: Cheers. More questions. Let's say I'm trying to extend python with a c module. That module cannot be dynamically loaded (for reasons outside my control). I have to create a custom python executable (or more likely custom python library). How would I do that? Is there documentation on that somewhere? Most of what I've seen was for dynamic loading. 2nd Step: Let's say I'm doing it under windows, using Visual Studio. Is there anything I have to be aware of? 3rd Step: Let's say I don't have the source available. I do have the object files, the resulting libraries and the header files though. Greg "The optimist proclaims that we live in the best of all possible worlds, and the pessimist fears this is true." - James Branch Cabell From export at hope.cz Wed Aug 11 15:57:58 2004 From: export at hope.cz (Lad) Date: 11 Aug 2004 12:57:58 -0700 Subject: Apache web server and CGI References: <81a41dd.0408090447.7f27a092@posting.google.com> <10hf2ugjngver5e@corp.supernews.com> <81a41dd.0408092306.264beed@posting.google.com> <81a41dd.0408101143.43fea836@posting.google.com> Message-ID: <81a41dd.0408111157.69703c2@posting.google.com> Peter van Kampen wrote in message news:... > In article <81a41dd.0408101143.43fea836 at posting.google.com>, Lad wrote: > > >> > > >> > >> AllowOverride None > >> Options ExecCGI > >> Order allow,deny > >> Allow from all > >> > > > Thanks Peter for help. Now I can run cgi scripts in default > > c:/program files/apache group/apache/cgi-bin/ > > directory. > > The problem was that there was not last "/" > > > > But how can I forced the Apache to allowed to run scripts in a > > different directory for example C:\Test\MyScripts\ > > I would guess you have something like the above in your httpd.conf > > ScriptAlias /cgi-bin/ c:/program files/apache group/apache/cgi-bin/ > > > AllowOverride None > Options ExecCGI > Order allow,deny > Allow from all > > > Simply replace c:/program files/apache group/apache/cgi-bin/ with > C:\Test\MyScripts > > Hth, > > PterK Peter, Thanks a lot. Now it works, but the scripts must be still started as http://localhost/cgi-bin/test2.py eventhough the scripts are not /cgi-bin/ directory but in MyScripts directory. I think that Apache maps MyScripts directory to /cgi-bin/ directory. Thanks again for help Lad From nicklaforge at gmail.com Thu Aug 26 21:34:14 2004 From: nicklaforge at gmail.com (Nick LaForge) Date: Thu, 26 Aug 2004 18:34:14 -0700 Subject: gmail messes up code? Message-ID: <1fc0d98004082618346dff83d8@mail.gmail.com> Hello python-list! I just signed up for gmail, and I am hearing some complaints about gmail not correctly showing code in the gmail interface. 1. What can I do to make it more readable for myself? and 2. What can I do to make my messages more readable for others? Thank you! -- Nick LaForge Mystic0 From fuzzyman at gmail.com Fri Aug 27 04:00:34 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 27 Aug 2004 01:00:34 -0700 Subject: lambda ?? Message-ID: <6f402501.0408270000.31ad1455@posting.google.com> I'm starting to read through the developer works article on Functional Programming - http://www-106.ibm.com/developerworks/library/l-prog.html It starts by giving some basic examples using lambda. What I'm wondering is what's the actual difference between these two forms ? pr = lambda s:s *and* def pr(s): return s Both bind the name 'pr' to a function object that does the same thing ?? I know that lambda functions can only be a single expression...... Is it just a basic example (and so in this case there is no difference).. or am I missing something. (What's the point of an 'anonymous' function... if you give a name to it !!). Regards, Fuzzy http://www.voidspace.org.uk/atlatnibots/pythonutils.html From imbosol at aerojockey.com Wed Aug 11 22:46:49 2004 From: imbosol at aerojockey.com (Carl Banks) Date: 11 Aug 2004 19:46:49 -0700 Subject: A decorator syntax not yet mentioned (I think!) References: Message-ID: <60dfb6f6.0408111846.615ee9eb@posting.google.com> steven.bethard at gmail.com (Steven Bethard) wrote in message news:... > I know there were complaints before about this sort of indentation, > but I couldn't find them in python-dev and the comments in the wiki > don't discuss this in any detail. Can anyone tell me why this > indentation syntax was dispreferred? Specifically, I'm interested in > why this is so drastically different from the other paired blocks: > if/elif/else, try/except, try/finally, etc. One thing that's different is that, in all those cases, the second block has a keyword that can't appear alone. You can't have an except without a try, or an else without an if, but you could have a def without a decorate. For that reason, I suggest it would be a bit more congruent (not necessarily enough to justify another new keyword) with the rest of Python to also use a keyword different from def, say ddef. decorate: ... ddef function(args): ... Either is definitely very passable if we must go the before-the-def route. > Also, there's a comment > in the wiki that says that there are technical problems with the > grammar if a block *starts* with an optional part. Does this not > apply to the @ case (which also starts a block with an optional part)? It doesn't seem like there would be a problem defining it in, for example, yacc. def and decorate...def could be two different statements. From rickh Tue Aug 3 18:45:06 2004 From: rickh (Richard Hilburger) Date: Tue, 3 Aug 2004 15:45:06 -0700 Subject: flowcharting is automatic for Python via preprocessor References: Message-ID: I would describe "grasp" as a "Control Structure Diagrammer" and not a "Control Flow Diagrammer". I could easily "dumb down" getCET and make it into a structure diagrammer, but that kind of functionality has already been done many times over. Yawn. "Neil Hodgson" wrote in message news:IUzPc.29707$K53.23470 at news-server.bigpond.net.au... > Connelly: > > > I think your visual diagrams could help, if they are: > > ... > > 2. Integrated into a code editor. > > > > I could see this being a new code editor fad, like collapsable > > functions and classes. > > http://www.eng.auburn.edu/grasp/index.html > > Neil > > From asif at go-away-spammer.com Tue Aug 31 13:23:23 2004 From: asif at go-away-spammer.com (Player) Date: Tue, 31 Aug 2004 18:23:23 +0100 Subject: Beginners question. Message-ID: Hi all I am teaching myself python and so am following a few tutorials from online. In one of the tutorials an exercise is the following... As an exercise, write a loop that traverses the previous list and prints the length of each element. Firstly I just wanted to see if I could get the length out of those elements that were list type. I no thats not exactly what the exercise asks for, but I thought I would start there. However I am stuck and cant figure out why my code is doing what it's doing. My code is as follows.... mylist = [1, 2, ["three", "four"], "five"] for item in mylist: if item == type(list): myitem = len(item) print myitem else: print item All my code seems to do is print out each element of the list on a new line. What I had expected it to do was this.... 1 2 2 'five' but it doesn't, what it does do is this... 1 2 ['three', 'four'] 'five' I expected the line, myitem = len(item) to issue the variable, myitem, with a value that was the length of item. But as you cans ee it doesn't and simply ignores all that code and does the else: print item part instead, misisng out the first half of the for loop. Were am I going wrong ?? Thanks in advance for any help :) M.B aka - Player - -- ************* The Imagination may be compared to Adam's dream- he awoke and found it truth. John Keats. ************* From pf_moore at yahoo.co.uk Tue Aug 24 17:22:23 2004 From: pf_moore at yahoo.co.uk (Paul Moore) Date: Tue, 24 Aug 2004 22:22:23 +0100 Subject: J2 paper 0.2.1 References: Message-ID: "Robert Brewer" writes: > First, thanks for the comments! > > Paul Moore wrote: >> 1. I differ on the "it doesn't matter what the keyword is" statement. >> On the contrary, my view could completely change depending on the >> keyword - I'd loathe "predef", whereas "using" is acceptable to me. >> Putting the proposal forward *without* an agreed keyword isn't >> (IMHO) fair to people who have this view. > > I understand your emotion, now, but not your reasoning, and in the > absence of that, I can't generate a fix for the proposal. If you could > go into more detail *why* you would loathe predef, it would go a long > way toward allowing a stronger statement in the doc. I feel "using" has > positives, but I don't know what the negatives of "predef" are. That's fair. I'm not sure I fully understand my own reasoning, but I'll see what I can do. My biggest problem, I guess, is that "predef" isn't a real word. Possibly one of the reasons I feel more comfortable with "using" is that there is prior art for it being a language keyword (C++ and C#) even though it doesn't mean anything remotely similar in those languages. But I don't want to get sucked into the potentially endless arguments over what keyword to use. I really don't care enough. And from your point of view, I don't think my vote is important enough that catering to my likes and dislikes is a key point. On the other hand, I *can* defend an argument that the proposal must take a stance on the keyword proposed. The existence of people (me, as an example :-)) whose vote would be changed by the choice of a keyword implies that not taking a stance leaves those people with no basis for making their decision. Of course, how significant this argument is depends on how many people fall into this category - and I have no facts on that. By pointing out that the two key contenders represent opposite extremes to me, all I can hope to do is to prompt people to think about how much the choice of keyword matters to them. >> 2. Does the patch support decorating classes? The @ syntax *might* by >> now (in CVS), there was discussion of adding it but I'm not sure it >> went in. The patch should probably provide the same functionality >> as CVS @-syntax, rather than just 2.4a2. > > The patch does not support decorating classes, because @ doesn't. > There's a patch submitted for that*, but it hasn't been accepted, IIRC. > The PEP says 2.4 will see only function decorators. Fair enough. I'd say that the existence of a patch which extends the decorator syntax to classes is a benefit for @ syntax over J2. I don't have a feel for whether there's a likelihood of class decorators being accepted for 2.4, and hence how strong a benefit it is. I would, however, argue that regardless of this, PEP 318 should say "For Python 2.4, only function/method decorators are being proposed", rather than "... are being added". But I take your point - chasing possible extensions is fruitless. Paul. -- The only reason some people get lost in thought is because it's unfamiliar territory -- Paul Fix From firemoth at gmail.com Mon Aug 16 00:53:42 2004 From: firemoth at gmail.com (Timothy Fitz) Date: 15 Aug 2004 21:53:42 -0700 Subject: Generators versus Coroutines References: <972ec5bd.0408141032.385fe115@posting.google.com> <972ec5bd.0408142203.5a8d5d04@posting.google.com> Message-ID: <972ec5bd.0408152053.67b13c35@posting.google.com> > For general coroutines it would have been. For Simple Generators (the > PEP's title) I think it was the right decision -- "simple" isn't > consistent with piling on gimmicks. > > If you want to change it, write a new PEP. Hmm, I do agree in the context of "Simple Generators" yield implying None would not make sense and (as shown by the fact that nobody else seems to care) is a good parse-time error facility. Is there, then, demand for full on Coroutines? I will live having to type those extra four letters, or maybe I'll cop out and yield 0 (hah) but it seems other people are used to coroutines in other languages (python is my first and only) and there might be demand. (Also, my first post on Usenet, ever, and in under two hours I get a respond from someone whose name I recognize on sight... I am impressed!) From tzot at sil-tec.gr Sat Aug 21 15:35:22 2004 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 21 Aug 2004 22:35:22 +0300 Subject: Detecteing Unicode encodings References: Message-ID: On Sat, 21 Aug 2004 10:57:34 -0700, rumours say that Jason Diamond might have written: >If I read up to four bytes from the byte stream, I can figure out what >encoding the stream is in but that has problems for UTF-8 streams >without BOMs--I would have just eaten one or more bytes that might need >to be decoded by the StreamReader. I could seek back to the beginning of >the stream but what if the file-like object I was reading from didn't >support seeking? Two options pop up instantly: 1. "Programmers do it byte by byte" (mainly a joke, so go to option 2 :) 2. wrap your file-like object in a custom object, which implements a pushback method and its read method returns first from the push-back buffer. If you read data that you shouldn't, push them back and give your custom object to the StreamReader. -- TZOTZIOY, I speak England very best, "Tssss!" --Brad Pitt as Achilles in unprecedented Ancient Greek From fumanchu at amor.org Sun Aug 22 14:55:59 2004 From: fumanchu at amor.org (Robert Brewer) Date: Sun, 22 Aug 2004 11:55:59 -0700 Subject: J2 proposal: keyword Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E2A@exchange.hqamor.amorhq.net> Roy Smith wrote: > Putting on my "Slightly Silly Party" hat... My turn for slightly silly (perhaps I shouldn't drink so much before noon on a Sunday ;) transform -> xform -> xf -> xdef xdef: staticmethod def foo(): pass We would at least be seen as an up-and-coming big-advertising product, having an 'x' in there. ;) -> xef? xef: staticmethod def foo(): pass Nah. Too silly. FuManChu From rnichol_rrc at yahoo.com Tue Aug 24 13:05:59 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Tue, 24 Aug 2004 12:05:59 -0500 Subject: age of Python programmers In-Reply-To: References: <20040819231139.D039A1E4003@bag.python.org> Message-ID: My jaw just dropped. School-mates not continually learning, man, have I been there. After I graduated, I coded C++ just for fun as a hobby thing (required by the BeAPI). Every once in while the class got together for a supper or lunch and we talked (of course) about what we've been up to. One girl mentioned that she was coding C++. I asked her some questions about what she was doing and all I got was a "deer in headlights" look and a smile. She just looked at the others and made the "over the head" gesture. I fully wanted to know and learn something. After all, she was doing this professionally, but there was nothing there. No wounder most software is crap nowadays. But installing word for data conversions, amoung those others? All I have is sympathy. 'Tis a sad state of affairs indeed. Andrea Griffini wrote: > On Tue, 24 Aug 2004 01:07:01 -0500, Reid Nichol > wrote: > > >>Perhaps it's just >>where I went to school though or where I hang out, but it can't all be >>coincidence. > > > IMO it's no coincidence. I think that *most* professional > programmers are not regular readers of usenet newsgroups > about the languages they use... not only that... IMO in > the bigger part they don't actually know what usenet > newsgroups are. And most didn't even read any book on the > languages and tools they use unless that happened when > they were still at school. > > I decided that for myself I'll always cut out enough time > to keep studying. But many just go forever with what they > learned when they were forced to because of an exam. > > I've personally lived totally absurd situations where > experienced programmers were just spending a lot of time > and energy (and were making a lot of mistakes) because > they never heard about make tools. I'm NOT kidding. > > I've seen things you people wouldn't believe... ;-) > MS Word macros taking ages and requiring superservers > (yes... they were installing office purposely to > superservers so that MS word could use that RAM to be > able to load the file to convert) to do data conversions > that someone knowing perl wouldn't even save the script > for (but would just invoke perl with "-e"). > > This is no joke. I was consulted for help when the word > macro stopped working complaining first about being unable > to "undo" changes and then crashing ms word anyway after. > > > Looks like keeping studying, observing and "learning" is > considered "out" by many of my collegues. > > Andrea From gandalf at geochemsource.com Wed Aug 18 05:38:21 2004 From: gandalf at geochemsource.com (Gandalf) Date: Wed, 18 Aug 2004 11:38:21 +0200 Subject: Platform independent way to play an mp3 file Message-ID: <4123238D.7040705@geochemsource.com> Does anyone know a platform independent way to play an mp3 file from Python? I believe the standard library cannot do this. L 2.0 From squirrel at WPI.EDU Thu Aug 12 11:24:09 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 12 Aug 2004 11:24:09 -0400 Subject: Pyhton Interpreter Startup time In-Reply-To: References: Message-ID: On Thu, 12 Aug 2004, Neil Benn wrote: > Is there a way to have a 'stripped' down Python interpreter which can > start up very quickly on a windows box. Two things you can do are: 1) Run Python as "python -S". Normally, Python does an 'import site' before running other code. Starting with 2.3, this does lots of expensive localization goo, etc.; my guess is your script doesn't need it to execute correctly, if it doesn't use any i18n functions. 2) Pre-compile the script. Normally, Python generates .pyc files for imported modules so it doesn't have to re-parse the source code, but it won't do this for a script specified on the command line. You can force it to compile your script by importing the script in the interactive interpreter, but this will also run your script (possibly not desirable). You can compile the script without running it by using the py_compile module: python -c 'import py_compile; py_compile.compile("my_script.py")' You can then run the compiled version using 'python my_script.pyc' ('python my_script.py' will ignore the compiled version). > Once thing I was thinking of was to use PyExe to make a > quick startup (does it compile down to C code, therefore not using the > Python interpreter at runtime?). Is this a possible solution? Nope. py2exe just embeds the Python interpreter in the .exe. If anything, startup would be slower, since py2exe also places all required modules in a ZIP archive. From leandro_ricardo at yahoo.com Fri Aug 6 08:34:20 2004 From: leandro_ricardo at yahoo.com (=?iso-8859-1?q?Leandro?=) Date: Fri, 6 Aug 2004 09:34:20 -0300 (ART) Subject: upper memory limit Message-ID: <20040806123420.20214.qmail@web10703.mail.yahoo.com> There is an upper memory limit in Python? I have 2GB RAM and 2 processors Xeon 2.4 - (Windows XP), but I just can use 1.2G of memory, after this python crashes. Does someone know if python has some memory limit? _______________________________________________________ Yahoo! Acesso Gr?tis - navegue de gra?a com conex?o de qualidade! Acesse: http://br.acesso.yahoo.com/ From mfranklin1 at gatwick.westerngeco.slb.com Wed Aug 25 06:40:53 2004 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Wed, 25 Aug 2004 11:40:53 +0100 Subject: age of Python programmers References: Message-ID: On Wed, 18 Aug 2004 12:20:31 GMT, Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... > > I'm 31 I've been _using_ since 1999 my first post to this new group was in 2000. Python is my first real programming language (a little bit of basic on the Spectrum 48 (k!) bbc basic at upper school (13-16) I've since learned Java and C# - my main language is still Python waiting-for-the-decorator-discussion-to-stop-ly Martin -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ From nicksjacobson at yahoo.com Mon Aug 16 15:06:52 2004 From: nicksjacobson at yahoo.com (Nick Jacobson) Date: 16 Aug 2004 12:06:52 -0700 Subject: Simple exceptions question Message-ID: Say I have a function foo that throws an IndexError exception, and I want to handle it: def foo(a, b, c): print a[10], b[10], c[10] #, etc. def main(): #define vars try: foo(a, b, c) except IndexError: print "Accessed array ", x, " out of bounds!" #??? When the exception is thrown, I don't know what triggered it! a, b, or c? I could put a series of if statements in the except clause, but that defeats the whole purpose of having the exception, right? Is there a better way? Thanks in advance! --Nick From s.mail at westo.at Thu Aug 26 13:48:18 2004 From: s.mail at westo.at (Stefan Stolz) Date: Thu, 26 Aug 2004 19:48:18 +0200 Subject: Mysql in Python? Message-ID: <2p6m32Fh7o9oU1@uni-berlin.de> Hello, i tried to find something about mysql in www.python.org, but found nothing... What can you recommend to use for getting and putting data from and into a mysql database? On my Suse 9.1 i found a rpm python-mysql. In the web i found the hk_classes from www.knoda.org. This should do also such things. Can you recommend something? What do you use? Thank you very much for the info. -- Gr?sse/Greets Stolz Stefan From ialbert at mailblocks.com Wed Aug 18 10:48:07 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Wed, 18 Aug 2004 10:48:07 -0400 Subject: Databases: Getting values by column name In-Reply-To: References: Message-ID: Robert Ferber wrote: >>As other pointed out you have everything you need, using dtuple.py at: >> >>http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81252 > > Of course I looked at that webpage, but if I'm not mistaken, mx.ODBC.Windows > is only available on Windows which makes it useless for me, I can not find > a ODBC Package for my Linux distribution and the webpage doesn't give the > slightest hint what the package name is (which probably would make > searching for it too easy) or where to get it. The dtuple.py module is database independent and will work with just about all database connectors. The fact that the example uses mx.ODBC.Windows is completely irrelevant it will work the same way with every other connector. > I didn't know that the Python-community was infested by so much > Microsoft-only code. Both of your hints seem to be Win-only. And it's >" Alpha quality". Heh, while I would agree that the formatting on the page is both slightly misleading and does not visually separate the different downloads well, you'd save yourself a lot of aggravation just by spending a little more time on each of these pages. The module that I (and others) talked about is called db_row and is located right above the on one you talk about (the windows specific database *driver*). Istvan. From google at daishi.fastmail.fm Fri Aug 20 15:07:22 2004 From: google at daishi.fastmail.fm (daishi) Date: 20 Aug 2004 12:07:22 -0700 Subject: Alternative decorator syntax decision References: Message-ID: C1 C1 C1 If we are allowed to make negative votes: -J2 -J2 -J2 I personally find J2 worse than the current pie syntax. Something that looks odd and does something odd seems the lesser evil vs something that looks normal yet does something odd. Also, it seems the options in J have very little to do with each other. E.g., I would actually support J1. From janeaustine50 at hotmail.com Fri Aug 13 01:46:27 2004 From: janeaustine50 at hotmail.com (Jane Austine) Date: 12 Aug 2004 22:46:27 -0700 Subject: Why can't pickle dump this instance? Message-ID: Hi. class A: def __init__(self,tick): if tick: self.foo=self.bar else: self.foo=self.bur def bar(self): print 'bar' def bur(self): print 'bur' import pickle pickle.dumps(A()) running this script results in "TypeError: can't pickle function objects" Why does this happen? and what can I do? Jane From spam at mouse-potato.com Thu Aug 26 21:36:37 2004 From: spam at mouse-potato.com (Pascal Bourguignon) Date: 27 Aug 2004 03:36:37 +0200 Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> Message-ID: <87hdqptl96.fsf_-_@thalassa.informatimago.com> otto.wyss at orpatec.ch (Otto Wyss) writes: > Xah Lee wrote: > > > this earth. Two things are on the top of my agenda: Unixism and Perl. > > > What you mean with Unixism? It's always funny to observe people's contradictions: Last week i bought a chain saw with a twisted handle. Perhaps i wasn't careful, but by accident it chopped one of my arm off, then i thought to myself "gosh, this is POWERFUL!". This seems to be the fashionable mode of thinking among the unixers or unixer-to-be, who would equate power and flexibility with rawness and complexity; disciplined by repeated accidents. Such a tool would first chop off the user's brain, molding a mass of brainless imbeciles and microcephalic charlatans the likes of Larry Wall and Linus Torvald jolly asses. --Xah Lee $ telnet xahlee.org 80; Trying 208.186.130.4... Connected to xahlee.org. Escape character is '^]'. GET / HTTP/1.1 HTTP/1.1 400 Bad Request Date: Fri, 27 Aug 2004 01:35:52 GMT Server: Apache/2.0.50 (Fedora) ^^^^^^^^^^^^^^^^^^^^^^ -- __Pascal Bourguignon__ http://www.informatimago.com/ Our enemies are innovative and resourceful, and so are we. They never stop thinking about new ways to harm our country and our people, and neither do we. From anthonybaxter at gmail.com Thu Aug 26 00:05:26 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Thu, 26 Aug 2004 14:05:26 +1000 Subject: On consensus decision-making (was Re: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WEDONE?) In-Reply-To: <2p52tbFh1eb5U1@uni-berlin.de> References: <2p52tbFh1eb5U1@uni-berlin.de> Message-ID: On Thu, 26 Aug 2004 15:14:48 +1200, Greg Ewing wrote: > Peter Hansen wrote: > > > > Has anything really changed? Would it now be correct to say > > that C1 has a serious chance of being accepted if someone would > > just update the implementation to the state and quality (?) of > > the other two? > > In a recent python-dev message, Guido said that, if it > were the agreed-upon alternative, he would reconsider it. No implementation means that this isn't likely... From peter at engcorp.com Thu Aug 19 16:09:12 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 19 Aug 2004 16:09:12 -0400 Subject: Alternative decorator syntax decision In-Reply-To: <10ia1a9jm9tkuca@corp.supernews.com> References: <10ia1a9jm9tkuca@corp.supernews.com> Message-ID: Jeff Shannon wrote: > My votes: J2 J2 E2 I second that. (J2 J2 E2) -Peter From wweston at att.net Tue Aug 24 15:34:46 2004 From: wweston at att.net (wes weston) Date: Tue, 24 Aug 2004 19:34:46 GMT Subject: Printing date a file In-Reply-To: References: Message-ID: Kory Wheatley wrote: > In Python how would you print the date in a file, I > have a logging program written in python and for each > new recorded added to the file, I would like to print > the > date, something like this below: > > 08/24/2004 or 08-24-2004 > > -- > Kory Wheatley > > > > __________________________________ > Do you Yahoo!? > New and Improved Yahoo! Mail - Send 10MB messages! > http://promotions.yahoo.com/new_mail Kory, Works. Maybe a better way. wes >>> import datetime >>> d = datetime.datetime(2004,1,1).today() >>> d datetime.datetime(2004, 8, 24, 12, 29, 25, 784935) >>> d.year 2004 >>> d.month 8 >>> d.day 24 From elainejackson7355 at home.com Tue Aug 31 14:10:13 2004 From: elainejackson7355 at home.com (Elaine Jackson) Date: Tue, 31 Aug 2004 18:10:13 GMT Subject: Splitting a list References: Message-ID: <9a3Zc.284965$J06.148496@pd7tw2no> def indices(x,y): if y in x: i = x.index(y) j = i+1 return [i]+[z+j for z in indices(x[j:],y)] return [] def listSplit(x,y): z = [-1] + indices(x,y) + [len(x)] return [x[z[i]+1:z[i+1]] for i in range(len(z)-1)] "Ian Sparks" wrote in message news:mailman.2673.1093960462.5135.python-list at python.org... string.split() is very useful, but what if I want to split a list of integers on some element value? e.g. : >> l = [1,2,3,-1,4,5,-1,8,9] >> l.split(-1) >> [[1,2,3],[4,5],[8,9]] Here's my hideous first pass : >> [[int(z) for z in x.split(',') if z] for x in ','.join([str(a) for a in l]).split('-1')] >> [[1, 2, 3], [4, 5], [8, 9]] When I see code like that I just know I've missed something obvious.... From brent.hughes at comcast.net Mon Aug 23 15:58:38 2004 From: brent.hughes at comcast.net (Brent W. Hughes) Date: Mon, 23 Aug 2004 19:58:38 GMT Subject: Why are strings immutable? References: Message-ID: Let me give two examples of where I think it would be nice to be able to change strings in place: First example: I want to add about 20,000 words to the end of a string, something like this: Str = [ ] for i in range(20000): Word = DoSomeProcessing() Str += Word I'd actually like to say Str.extend(Word). As it is, I'm thinking of something like this: List = [ ] for i in range(20000): Word = DoSomeProcessing() List.extend(list(Word)) Str = ''.join(List) Second example: I would like to reverse a string containing about 120,000 characters. I'd like to do it in place, but I'm planning to do something like this: List = list(Str) List.reverse() Str = ''.join(List) From j_mckitrick at bigfoot.com Tue Aug 17 11:53:35 2004 From: j_mckitrick at bigfoot.com (j_mckitrick) Date: 17 Aug 2004 08:53:35 -0700 Subject: Problem with floating point precision Message-ID: I checked the docs, but found nothing about floating point issues. I am working on an app that deals with currency values, and only does addition and subtraction (no division). But I am starting to see values that should be the same failing a compare! What is the workaround or correct way to compare 2 floats? It worked fine for months, then suddenly starting acting odd. I might have upgraded Python somewhere in between, I can't recall. jonathon From agriff at tin.it Tue Aug 24 02:35:45 2004 From: agriff at tin.it (Andrea Griffini) Date: Tue, 24 Aug 2004 06:35:45 GMT Subject: python doesn't like my numbers References: <2osfspFdnjbcU1@uni-berlin.de> <2osm7nFe3t34U1@uni-berlin.de> Message-ID: On Sun, 22 Aug 2004 18:52:50 -0400, Leif K-Brooks wrote: >paul k wrote: >> is there any way to convince python not to take my (phone)numbers >> starting with zero as octals? >> >> >>> int(088) >> File "", line 1 >> int(088) >> ^ >> SyntaxError: invalid token > >Why do they have to start with zeros in your source code? My guess is that his program was simply using "input()" Im rather new to python and I've to say that I found quite surprising that the "input" function does also evaluate (so entering "1+1" i get the number 2 and not the string "1+1") and that I've to use "raw_input" to get what the user typed in. Andrea From eppstein at ics.uci.edu Tue Aug 10 13:02:30 2004 From: eppstein at ics.uci.edu (David Eppstein) Date: Tue, 10 Aug 2004 10:02:30 -0700 Subject: @decorator syntax is sugar, but for what exactly? (decorator libraries). References: Message-ID: In article , steven.bethard at gmail.com (Steven Bethard) wrote: > I don't remember who, but someone already mentioned that you can do > all of these things with the limited syntax if you really want to, > either with operator.* or eval: > > @eval("foo().bar()") > @eval("foo or bar") > @operator.getitem(mydecorators, 'foo') > @eval("lambda f: foo(f) or bar(f)") A little more cleanly like this? def id(x): return x @id(foo().bar()) @id(foo or bar) @id(mydecorators['foo']) @id(lambda f: foo(f) or bar(f)) -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ From BrenBarn at aol.com Wed Aug 18 10:46:04 2004 From: BrenBarn at aol.com (OKB (not okblacke)) Date: 18 Aug 2004 14:46:04 GMT Subject: age of Python programmers References: Message-ID: Gerrit Muller wrote: > how many teeners are still programming? Most teeners I know build > websites, but they don't program. I turned 20 about 6 months ago and I've been goofing around with Python for about 2 years. I'd also been programming in other languages (like Basic :-) for a long time before that. -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown From mark_bottjer at hotmail.com Thu Aug 12 20:08:38 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Thu, 12 Aug 2004 20:08:38 -0400 Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: <10hnvtn1184q773@corp.supernews.com> References: <60dfb6f6.0408111846.615ee9eb@posting.google.com> <3YWdnYxLf--ObofcRVn-pw@powergate.ca> <411ba1db$1@nntp.zianet.com> <411bd3f0$1@nntp.zianet.com> <10hnqqm8h7b3k89@corp.supernews.com> <411bfa47$1@nntp.zianet.com> <10hnvtn1184q773@corp.supernews.com> Message-ID: <411c0687@nntp.zianet.com> Jeff Shannon wrote: > Mark Bottjer wrote: >> BTW: "ISTM"? > > "... it seems to me ..." :) Ah! GTK :) > I'd be happiest with this option, too. But it seems that GvR has > already ruled out anything other than prefix syntax, so I'm not > wasting my energy backing this. That's why I hadn't mentioned it before now, either. Not much point. > With prefix syntax as a given, I'd prefer to have the closest we can > come to this form, which is to have the meta (or decorate, or > whatever) block immediately preceding the def. Personally, I think that the most "Pythonic" prefix form would be: class C: decorate (d1, d2, d3): def f(self): pass But down that road lies madness... *ducks* > Though I must say, I don't see how putting a meta: block inside the > function is any less a violation of established patterns than having > it outside the function. You seem to be implying that you think it's > fine inside, but an abomination outside. Not an abomination, no. I just think it fits better inside. It's nicely scoped, it's contents are well delineated, it doesn't couple with the next statement at the same indentation level, and plays nicely with where we already look for the docstring (for now). Of course, it couples with the outer scope, but docstrings already set the precedent for that. It just seems more "Pythonic" to me to have it inside, is all. > I'm saying that this sort of block structure is (IMO) the most > pythonic way to do this, and while I'd like it inside I don't > particularly care if it's outside, and that in any case it's far less > of an abomination that @pies are. :) There's that word again... :) -- Mark From peter at engcorp.com Sun Aug 22 11:23:54 2004 From: peter at engcorp.com (Peter Hansen) Date: Sun, 22 Aug 2004 11:23:54 -0400 Subject: Python future performance and speed In-Reply-To: <278de0e.0408220636.3ee25f9d@posting.google.com> References: <278de0e.0408211605.426e5129@posting.google.com> <278de0e.0408220636.3ee25f9d@posting.google.com> Message-ID: Neuruss wrote: >>What makes you think speed is Python's primary limitation for mainstream >>acceptance? > > Why would someone reject to use a language that is clean, very well > designed, intuitive, expresive, flexible and a pleasure to use? > Perhaps the fact that i is 100 times slower than c... Statements like that serve only to demonstrate the narrowness of thought of the writer. In some cases, often contrived examples or with poorly written code, Python can be about 100 times slower than C. Much more often it lies somewhere between 10 and 30 times slower. In a surprising number of cases, it is faster than 10 times slower and in a few cases it can even achieve rough parity. And if we have to rehash the old arguments again for those who haven't taken the time to search the archives, we can point out once more things like how a Python program will be completed much sooner than the C program, resulting in lots of extra time to run the program (and many programs are not run very often). We can also point to the fact that most performance issues are more heavily affected by poor algorithms than by anything else, and the Python programmer has both the tools and the time to improve the algorithms whereas the C programmer will not... -Peter From anthonybaxter at gmail.com Fri Aug 13 03:25:44 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 13 Aug 2004 17:25:44 +1000 Subject: decorator with keyword In-Reply-To: References: <2o21foF65snnU2@uni-berlin.de> Message-ID: On Thu, 12 Aug 2004 23:03:39 -0400, Peter Hansen wrote: > Reinhold Birkenfeld wrote: > > I'm sure it would help if every supporter of this syntax started a > > thread of his own on python-dev *wink* > Glad you put the wink in... I doubt that would help the > cause. And Brett Cannon would probably have you whacked if you did it. > that there > is a fairly wide consensus that decorate: (possibly with > a different keyword) is far preferred to @pie... FWIW, I still prefer pie-decorators to decorate. That's just from translating my trusty decorator-testbed-code into it. > At least, > I think that was roughly what was asked for of the masses, > if the masses had anything to say about the matter. Pretty much - although the theory was that there would need to be a discussion on technical merits of one over the other, rather than "here's a list of people who prefer this or that". But you knew that already... From leor at bdsoft.com Sun Aug 29 21:20:43 2004 From: leor at bdsoft.com (Leor Zolman) Date: Mon, 30 Aug 2004 01:20:43 GMT Subject: simple compiled languages? References: <7xzn4fu188.fsf_-_@ruckus.brouhaha.com> <_1bYc.855$2s.374@twister.nyroc.rr.com> <7xbrguvfn6.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 29 Aug 2004 03:09:03 GMT, "Cy Edmunds" wrote: >"Paul Rubin" wrote in message >news:7xbrguvfn6.fsf at ruckus.brouhaha.com... >> "Cy Edmunds" writes: >> > Turbo Pascal. I used to think it was great in 1983. :) >> >> Yeah, they never released the source code though. I should have added >> that as a qualification. >> >> BDS C was released, by the way, but it's written entirely in 8080 >> assembler. > >Ah, yes. "Brain Dead Software". Great name. lol "Brain Damage" software, actually. A Tribute to Dark Side of the Moon, sort of the official album of the dorm I'd been living in shortly before writing BDS C. In case anyone's interested, this is the home page for it these days: http://www.bdsoft.com/resources/bdsc.html I really have to find some time to learn Python. My 12-year-old daughter asked me about the difference between C, C++, Java and Python the other day. I tried to explain it as best I could, and she then said she wanted to learn Python. I gave her the book and asked her to teach it to *me* after she figured it out ;-) -leor -- Leor Zolman --- BD Software --- www.bdsoft.com On-Site Training in C/C++, Java, Perl and Unix C++ users: download BD Software's free STL Error Message Decryptor at: www.bdsoft.com/tools/stlfilt.html From squirrel at WPI.EDU Wed Aug 18 09:45:45 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Wed, 18 Aug 2004 09:45:45 -0400 Subject: age of Python programmers In-Reply-To: References: Message-ID: On Wed, 18 Aug 2004, Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... I'm 19. The only other Python programmer I know personally is 21. Congrats on discovering Python at 14; back then I thought VB was a godsend. ;) From jjl at pobox.com Wed Aug 11 19:42:01 2004 From: jjl at pobox.com (John J. Lee) Date: 12 Aug 2004 00:42:01 +0100 Subject: 'break' Causes Execution of Procedure? References: Message-ID: <871xidqm2e.fsf@pobox.com> "Scott Brady Drummonds" writes: [...] > DEBUG: advancing both simulators to 20178 [...] Is this a threaded program? John From twanger at bluetwanger.de Tue Aug 10 08:19:05 2004 From: twanger at bluetwanger.de (Markus Bertheau) Date: Tue, 10 Aug 2004 14:19:05 +0200 Subject: Multiple inheritance with a common base class In-Reply-To: <1092137872.2624.16.camel@dicaprio.akademie1.de> References: <1092137872.2624.16.camel@dicaprio.akademie1.de> Message-ID: <1092140345.2624.28.camel@dicaprio.akademie1.de> ? ???, 10.08.2004, ? 13:37, Markus Bertheau ?????: Also I observe that the instance will in fact _not_ have a single copy of the data attributes used by the common base class. The following example demonstrates this: class CommonBase: def __init__(self): self.no = 0 def setNo(self, no): self.no = no class LeafA(CommonBase): def __init__(self): CommonBase.__init__(self) print("CommonBase.no: %i" % self.no) CommonBase.setNo(self, 3) class LeafB(CommonBase): def __init__(self): CommonBase.__init__(self) print("CommonBase.no: %i" % self.no) CommonBase.setNo(self, 4) class Multi(LeafA, LeafB): def __init__(self): LeafA.__init__(self) LeafB.__init__(self) m = Multi() It outputs: CommonBase.no: 0 CommonBase.no: 0 If there was only one copy of the common base class, I'd have expected an output similar to CommonBase.no: 0 CommonBase.no: 3 This renders multiple inheritance pretty useless for me. Can someone clear this all up and tell me how multiple inheritance is supposed to work in python? Thanks -- Markus Bertheau From arien_malec at yahoo.com.REMOVE Mon Aug 16 14:38:46 2004 From: arien_malec at yahoo.com.REMOVE (Arien Malec) Date: Mon, 16 Aug 2004 18:38:46 GMT Subject: PEP 318 decorators are not Decorators References: Message-ID: "Colin J. Williams" wrote in news:Ns3Uc.5169$Tr.369640 at news20.bellglobal.com: > Arien Malec wrote: >> Clearly, Python can choose any name for the >> auto-function-transformation syntax in question, but it's rather >> willfully confusing to choose a name that's heavily identified with a >> profoundly different semantics that's superficially similar in >> intent. > This is especially confusing as, in everyday english usage, to > decorate is not the same as to transform. > > Perhaps "transform" could be consdered as an alternative. That would be my leaning, as well. Ideally, the name would make it clear that the application order of the transformations is significant.... Arien From jerf at jerf.org Tue Aug 31 13:04:22 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Tue, 31 Aug 2004 17:04:22 GMT Subject: "Content-Length" header References: <96c2e938.0408302057.61df147b@posting.google.com> Message-ID: On Mon, 30 Aug 2004 21:57:02 -0700, G. S. Hayes wrote: > Something related to think about: if most users use only letters in their > passwords, making the passwords case-insensitive potentially makes it take > crackers HALF the time to crack a password by brute force. Much worse than that. Assuming 8 letters only: Both cases: 52 ^ 8: 53,459,728,531,456 (53 trillion) One case : 26 ^ 8: 208,827,064,576 (208 billion) It's halved *per character*. Moral of the story: Use symbols and mix cases in your passwords; you want to get to the bigger spaces for security. Both cases + numbers + symbols can reasonably come to 92 chars on a standard (american) keyboard, for a total of 92 ^ 8 passwords = 5,132,188,731,375,616 (5 quadrillion). From robin at reportlab.com Wed Aug 18 09:44:23 2004 From: robin at reportlab.com (Robin Becker) Date: Wed, 18 Aug 2004 14:44:23 +0100 Subject: Python-2.1.x.tgz Message-ID: <41235D37.7060102@chamonix.reportlab.co.uk> Does anyone know where I can get the latest source for Python-2.1. I looked in www.python.org/2.1 and seem to see only Python-2.1.tgz. -- Robin Becker From jacek.generowicz at cern.ch Mon Aug 30 04:52:27 2004 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 30 Aug 2004 10:52:27 +0200 Subject: Generator expressions v/s list comprehensions References: <1gj8y77.6qshr41q531veN%aleaxit@yahoo.com> <87llfywooz.fsf@sinken.local.csis.hku.hk> <1gjbs1e.assxlxlud1m0N%aleaxit@yahoo.com> <7xbrgtrq4r.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes: > Those features are in other languages for a reason, and there's been > enough experience using them (in those languages) that their > desirability for Python should never have seriously been in > question. While I feel a lot of sympathy towards this statement in principle, the other side of the coin is extremely important too. One of Python's strengths is exactly that it does _not_ import many tried and tested features from other languages (braces as delimiters, access restriction, static typing, meaningful line noise, etc.) However, it is also one of its weaknesses (nested scopes, for example, as you mentioned). It all depends on the actual feature in question, and the programmer in question. > So it would have been better to include them from the beginning, > instead of through separate episodes of prolonged agony for each > one. Python occupies some position in the space of all possible programming languages. Its position changes, as the language evolves. The language evolves because the Python community pushes it in some direction that it considers to be a good one. Judgements about which directions are good, come from experience with using the language. The language evolves into one which the community finds more useful, the language arrives at some local maximum in programming language space. You would like it to have been placed at the local maximum in the first place. So would I, but that is not realistically possible. And remember, the landscape looks very different from different people's perspectives, what might look like a local maximum to you, might seem to be in a deep trench from my point of view. Macros, anyone? Lambda? From news at woody.datatailors.com Fri Aug 13 07:49:45 2004 From: news at woody.datatailors.com (Peter van Kampen) Date: Fri, 13 Aug 2004 13:49:45 +0200 Subject: Blocking the execution of a script References: Message-ID: In article , Angelo Secchi wrote: > > Hi, > I would like Python to interrupt the execution of a script in case an if > condition turns out to be TRUE. What is the proper way to do that? > > Thanks, > a. import sys if cond: sys.exit(1) Hth, PterK -- Peter van Kampen pterk -- at -- datatailors.com From cass at skynet.be Thu Aug 26 15:03:21 2004 From: cass at skynet.be (Guillaume Desmottes) Date: Thu, 26 Aug 2004 21:03:21 +0200 Subject: Install a gconf schemas with distutils Message-ID: <1093547000.13838.0.camel@localhost.localdomain> Hi! I would like to use distutils to install a gconf schemas. The distutils doc is very poor and I don't understand how to make that. The 'manual' command is: GCONF_CONFIG_SOURCE=`gconftool-2 --get-default-source` gconftool-2 --makefile-install-rule my_file.schemas Thanks a lot. G. -- Guillaume Desmottes Jabber GPG 1024D/711E31B1 | 1B5A 1BA8 11AA F0F1 2169 E28A AC55 8671 711E 31B1 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Ceci est une partie de message num?riquement sign?e. URL: From cckk_lin at yahoo.ie Mon Aug 30 20:57:45 2004 From: cckk_lin at yahoo.ie (Lin Jingxian) Date: Tue, 31 Aug 2004 08:57:45 +0800 Subject: use win32 COM in python References: Message-ID: thanks, Dave and Peter I can use pythoncom, but since there isn't pointer in python (is it?), I dont know how to call the : int read(unsigned char* buf, int length) method in python.what unsigned char* buf should be represented in python?thanks again. "Lin Jingxian" ???????? news:cguo6j$j67$1 at news.yaako.com... > hi, > I have a C++ implemented COM server that give out a method like: int > read(unsigned char* buf, int lenth), How can I use this method from python? > what is the signature? > or anyone can tell me how should I design the COM interface so I can use > python to read a chunk of bytes from a C++ implemented COM server. > > thanks. > > From raims at dot.com Thu Aug 5 05:23:59 2004 From: raims at dot.com (Lawrence Oluyede) Date: Thu, 5 Aug 2004 11:23:59 +0200 Subject: Need help on how to use Pymedia! References: Message-ID: <3x8w4pqd3emo.15wp1jkrwkqua.dlg@40tude.net> In data Thu, 05 Aug 2004 02:28:48 GMT, CptPicard ha scritto: > Could someone give me a more detailed documentation on pymedia or some clues > on how to get the information I need ? AFAIK Pymedia cannot extract ID3 infos from MP3 (altough you can study by yourself the ID3 format a inspect the raw info of the file), anyway the web is full of ID3 tools for python such as: http://id3-py.sourceforge.net/ bye! -- Lawrence (l dot oluyede at virgilio dot it) "In IE we trust" From arien_malec at yahoo.com.REMOVE Thu Aug 19 21:03:53 2004 From: arien_malec at yahoo.com.REMOVE (Arien Malec) Date: Fri, 20 Aug 2004 01:03:53 GMT Subject: Alternative decorator syntax decision References: Message-ID: "Paul McGuire" wrote in news:t07Vc.1179$v86.188 at fe2.texas.rr.com: > There are a number of messages on the python-dev mail list that > indicate that Guido is looking for some concensus to come from this > list as to what *one* alternative syntax for decorators M, any keyword option using "transform" (I care more about semantics than syntax) Arien From lbates at swamisoft.com Fri Aug 6 09:44:55 2004 From: lbates at swamisoft.com (Larry Bates) Date: Fri, 6 Aug 2004 08:44:55 -0500 Subject: [Newby question] List comprehension References: Message-ID: Actually I think (??) this is better done in a loop: (not tested) toc=[] for root, dir, files in os.walk(os.path.abspath('.')): mp3files=[f for f in files if f.lower().endswith('.mp3')] if mp3files: toc.append((root, mp3files)) HTH, Larry Bates Syscon, Inc. "Eelco Hoekema" wrote in message news:pan.2004.08.06.13.22.50.75041 at xs4all.nl... > > I'm trying to get a list of tuples, with each tuple consisting of a > directory, and a list of files. I only want a tuple if and only if the > filtered list of files is not empty. And, i want the list of files in the > tuples to be filtered. For this, i came up with the following code: > > > > # song filter: will return true if the file seems to be an mp3 file. > # (may not be the best way to do this) > def song(f): > (name, ext) = os.path.splitext(f) > return ext.lower() == '.mp3' > > # list comprehension walking through a directory tree > [(root, filter(song, files)) for (root, dir, files) in os.walk(os.path.abspath('.')) if filter(song, files)] > > > > > Now, this will work. However, it seems kind of silly to call the filter > twice. Is there a way to keep this in one list comprehension, but with > just filtering once? > > eelco > > From BruceWhoHKL at gawab.com Wed Aug 18 04:23:33 2004 From: BruceWhoHKL at gawab.com (BruceKL WhoH) Date: Wed, 18 Aug 2004 16:23:33 +0800 Subject: metaclass ??? Message-ID: <20040818082245.89FEA1E4003@bag.python.org> Hi, I have just read David Mertz's Metaclass programming in Python,but I'm still confused. can someone show me an example to explain when metaclass is needed? I think metaclass can be treated as a class factory,but how to specify the class generated? For example: class ChattyType(type): def __new__(cls, name, bases, dct): print "Allocating memory for class", name return type.__new__(cls, name, bases, dct) def __init__(cls, name, bases, dct): print "Init'ing (configuring) class", name super(ChattyType, cls).__init__(name, bases, dct) if I want to create two different class A and B with different behaviours like this : A = ChattyType(arg='xxx') B = ChattyType(arg='yyy') how to modify the ChattyType code ? ????????BruceKL WhoH ????????BruceWhoHKL at gawab.com ??????????2004-08-18 From egbert.list at hccnet.nl Thu Aug 19 17:17:07 2004 From: egbert.list at hccnet.nl (Egbert Bouwman) Date: Thu, 19 Aug 2004 23:17:07 +0200 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: <20040819211707.GA4399@mirk.lan> My vote: C1 D1 K egbert -- Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991 ======================================================================== From pythongnome at hotmail.com Wed Aug 18 08:51:29 2004 From: pythongnome at hotmail.com (Lucas Raab) Date: Wed, 18 Aug 2004 12:51:29 GMT Subject: age of Python programmers References: Message-ID: I myself am only 14. I've been programming for two years with Python. I've tried C++, but found it a pain in the area that Preparation H fixes. I got started programming with Python as a result of a 4-H computer science project. I was looking for a free, easy to learn language and happily found it with Python. I'm currently interested in the network-centered areas of Python. "Gerrit Muller" wrote in message news:cfvi4r$bn7$1 at news.tue.nl... > Most Python programmers I know are 40+. I am myself 47 (born in december > 1956). > > regards Gerrit > > P.S., > > how many teeners are still programming? Most teeners I know build > websites, but they don't program. > > -- > Gaudi systems architecting: > > From peter at engcorp.com Mon Aug 9 19:49:38 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 09 Aug 2004 19:49:38 -0400 Subject: Purely emotional perspective In-Reply-To: <10hg1hg1pidqs96@corp.supernews.com> References: <10hf3oaltbo7o74@corp.supernews.com> <10hg1hg1pidqs96@corp.supernews.com> Message-ID: Jeff Shannon wrote: > Personally, I'm seeing more and more usefulness in decorators as the > discussion progresses, and I'm seeing more reasons why the most obvious > alternatives to the currently proposed syntax are not optimal. But I > still find the current syntax to be *extremely* (painfully) > uncomfortable -- this sort of prefix syntax is unlike anything else *I* > can think of in Python. That's precisely my feeling at this point as well. Oddly enough, I think with the slight change to use | instead of @ (or perhaps even Barry's preferred =) it would be easier to swallow. Fundamentally though it is things like the strangeness of these lines that are somehow "bound" to the following (next) function definition, yet have no connection to it other than coming at the same indentation level. (At least the | syntax does feel like it has a visual "link" to the following def.) And the reversed order of application (non-intuitive, I feel). And the restriction to dotted names instead of arbitrary expressions, making it feel even more weird and non-Pythonic (and that in spite of the workarounds that have been shown for perhaps all cases anyway). And other subtleties. > I'm particularly worried about the proposals of using this as metadata > for things like author -- that seems to be begging for almost every > function to use half a dozen or more decorators (accepts, returns, > author, design date, last revision date, etc., etc.) which will (IMO) > seriously degrade code readability. (This syntax is okay for one or two > decorators, but more than that quickly becomes obfuscatory.) This paragraph also seemed worth leaving in. :-) -Peter From tim.peters at gmail.com Thu Aug 5 01:29:08 2004 From: tim.peters at gmail.com (Tim Peters) Date: Thu, 5 Aug 2004 01:29:08 -0400 Subject: Timing Difference: insert vs. append & reverse In-Reply-To: References: <35b736b9.0408020330.53b24ed3@posting.google.com> <1a517b5.0408031027.60554dfb@posting.google.com> <1a517b5.0408041305.3927a6c8@posting.google.com> Message-ID: <1f7befae0408042229365aede0@mail.gmail.com> [Bryan Olson, on complicating the list object again, and 2.4's deque type] > But it breaks (efficient) indexing. Since we can have it all > like Perl, why not? As I said, the best Perl can do is O(1) amortized. 2.4's deque does better than that, and that can be important in classes like Python's Queue.Queue where threads typically block waiting for pops and pushes (but has no use at all for random access). If you follow the link you gave last time and read to the bottom following the other links, you'll find that Perl lists had quadratic-time behavior under the steady-state queue pattern for a long time. That was eventually fixed -- or so they say. Small details are both tricky and vital. 2.4's deque implementation is obviously immune to "bad" patterns, steady-state queue or otherwise. Most immediately damning, adding another member to the list struct (to keep track of the "low bound") would increase the size of every list object by 8 bytes, on 32-bit boxes. Python lists are easy to spell, use and access, and some Python apps use millions of small lists. They wouldn't appreciate the RAM hit for a mostly-useless feature. Most Perl programmers seem to be so confused by Perl lists that they only use them when they have to, to shift function arguments in and out <0.6 wink>. That's a use case for lists Python doesn't have at all. You can pursue it if you want to, but with the 2.4 deque type I have no interest in messing more with the list type. From anthonybaxter at gmail.com Thu Aug 5 21:59:34 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 11:59:34 +1000 Subject: Confused about pep 318 In-Reply-To: References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: On 05 Aug 2004 22:16:44 +0300, Ville Vainio wrote: > The problem with @ as I see it (FWIW, of course) is that the new > syntax wastes @ for a minor feature. I wouldn't mind @[decorator], > which would allow reserving stuff like @private (compiler / type > inferrer / macro / whatever) for future extension of the language. See, that's a matter of opinion. I don't think decorators will end up being a "minor feature". I think they have the potential for much interesting meta-programming. I also don't think that hanging onto a particular ascii glyph for "some future use" is particularly useful - I'm not aware of any other potential use for this. Unless we use it to indicate an array . From zathras at thwackety.com Sun Aug 22 11:45:22 2004 From: zathras at thwackety.com (Michael Sparks) Date: Sun, 22 Aug 2004 16:45:22 +0100 Subject: Alternative decorator syntax - keyword choice References: Message-ID: <4128c45d$0$40942$ed2619ec@ptn-nntp-reader03.plus.net> Colin J. Williams wrote: ... > Three issues which have not been discussed much are: > 1. the purpose of the docstring in J2 preceding the funcdef. It it > to describe the transformers or the function? I'm not sure I understand this - the implementation as is doesn't make any changes to the position of the docstring. In some examples I've put: # Bla # Bla decorate: staticmethod def foo(bar): "rhubarb" pass Largely because some doc generators currently take code like: # Bla # Bla def foo(bar): "rhubarb" pass And concatenate the "Bla Bla" docs with the "rhubarb" docs. The location/meaning of the docstring itself is left unchanged. > 2. the placement of the extra code relative to the funcdef. > (incidentally, I don't find docstring in the Python grammar) The docstring isn't handled by the grammar - it's "manually" yanked out the codeblock during compilation. ie it's based on the semantics of codeblocks rather than purely the syntax. I suspect that this is the key reason why putting the extra code inside the function's code block was ruled out. > 3. whether the PEP 318 processes are to apply to classes as well > as functions. The code/grammar tend to suggest not. The implementation I've done for J2 is really syntactic sugar on top so the semantics aren't changed from 2.4a2. (The simplest way of testing these things really is to take the easy way out - download, build and play :) Regards, Michael. From jason at injektilo.org Tue Aug 24 15:00:03 2004 From: jason at injektilo.org (Jason Diamond) Date: Tue, 24 Aug 2004 12:00:03 -0700 Subject: fun with unicode files In-Reply-To: References: <6579x7eo.fsf@python.net> Message-ID: Jason Diamond wrote: > Roger Binns wrote: > >> Here is my own more complete implementation: >> >> http://www.bitpim.org/pyxr/c/projects/bitpim/common.py.html#0286 > > > When I do import encodings.utf_32 on Python 2.3.3, I get an ImportError. > What verson of Python are you using where that works? > > I can't find any documentation of the encodings module in the Python > Library Reference. Where can I read more about it? Never mind. I continued reading your code and found the comment about those modules not existing (yet). -- Jason From __peter__ at web.de Wed Aug 11 15:29:10 2004 From: __peter__ at web.de (Peter Otten) Date: Wed, 11 Aug 2004 21:29:10 +0200 Subject: Python equivalent to a C trick References: <1d7b6d0d.0408092255.1177908e@posting.google.com> Message-ID: Dan wrote: > Is there a python equivalent of this trick in C? > > Logic_Test ? True_Result : False_Result > > Example: > printf( "you have %i %s", num_eggs, num_eggs > 1 ? "eggs" : "egg" ); >>> def numerus(n, sg, pl=None): ... if n == 1: ... return article(sg) ... elif n == 0: ... return "no " + plural(sg, pl) ... else: ... return "%d %s" % (n, plural(sg, pl)) ... >>> def article(sg): ... if sg[:1].lower() in "aeiou": # uniforms are off-limit ... return "an " + sg ... else: ... return "a " + sg ... >>> def plural(sg, pl): ... if pl is None: ... return sg + "s" ... else: ... return pl ... >>> numerus(1, "egg") 'an egg' >>> numerus(2, "egg") '2 eggs' >>> numerus(0, "egg") 'no eggs' >>> numerus(1, "solution") 'a solution' >>> :-) Refine as needed. Peter PS: The trick is to not use a trick. From John.Marshall at ec.gc.ca Wed Aug 11 11:52:26 2004 From: John.Marshall at ec.gc.ca (John Marshall) Date: 11 Aug 2004 15:52:26 +0000 Subject: [Python-Dev] A decorator syntax not yet mentioned (I think!) In-Reply-To: <492EA476-EBAB-11D8-87F8-000A95686CD8@redivi.com> References: <1092237417.22674.12.camel@mango.cmc.ec.gc.ca> <492EA476-EBAB-11D8-87F8-000A95686CD8@redivi.com> Message-ID: <1092239547.22674.39.camel@mango.cmc.ec.gc.ca> On Wed, 2004-08-11 at 15:29, Bob Ippolito wrote: > On Aug 11, 2004, at 11:16 AM, John Marshall wrote: > > > How about the following, which I am almost positive > > has not been suggested: > > ----- > > class Klass: > > def __init__(self, name): > > self.name = name > > > > deco meth0: > > staticmethod > > def meth0(x): > > return x > > > > deco meth1: > > classmethod > > def meth1(cls): > > return cls > > > > deco sayhello: > > funcattrs(name='GvR', language='python') > > log(file='func.log') > > def sayhello(self): > > print 'hello python world' > > > > ----- > > 1) The decorators clearly apply to a specific method/function, > > therefore there is no need to do any stack pushing in memory > > until the method/function definition is done. > > None of that code can actually execute until the method/function > definition is done, how is this different at all? > I am not refering to actually executing the code but addressing people's point that when they read through the code, they need to keep all the decorator items in memory until they come to the "def ...". One person described the process as push each decorator onto a stack (in his head) until he found the def. > > 2) The decorators are "outside" of the method/function they > > decorate: > > a) which will please those who want the outside location > > b) will not be folded within the function > > Doesn't a) imply b)? > Sure. But this addresses two concerns explicitly. > > c) folding on the decorators can be done so that the > > def is not obfuscated > > This could probably be done with the @syntax too if the editor was > smart enough I imagine it is possible. But the point was to make the signature clearly visible/prominent but also indicate that there _are_ decorators associated with the method/function. > > > d) can be located anywhere in the code--but most likely > > before the "def ...()" > > I don't think that is a bonus at all. > I am not claiming this as a bonus. Rather, I am making it clear that the mention of the method/function name does not require any special/forced placement. > > 3) The sequence in which the decorators are applied is just > > like code would be--this is certainly intuitive given > > that we are writing code. > > That's not really obvious. > I am not claiming that it is obvious but that it could be understood that way (rather than leave it to interpretation, I made it explicit as an option). Note how the sequence issue has come up recently with respect to the @-syntax and the list syntax, which apparently have been understood to apply in the opposite order. > > This approach could also be applied to classes in case > > decorators should ever be extended to them: > > So can any of the other proposals. That may be, but to be able to do so this way makes it an viable option. > > > ----- > > deco Klass: > > doc("This is a class to ...") > > class Klass: > > : > > : > > ----- > > > > Any comments? > > Yeah, this is no less than twice as bad as any of the current decorator > proposals because you have to repeat the function name :) > Personally, I might opt for something else, but having the decorators outside have raised concerns for some. With this approach the tagging makes things explicit, which is often a good thing. The current @-syntax _implicitly_ identifies the decorators with the method/function/class which people have said they don't like. Thanks for the comments. John > -bob From Michael.J.Fromberger at Clothing.Dartmouth.EDU Tue Aug 17 20:56:02 2004 From: Michael.J.Fromberger at Clothing.Dartmouth.EDU (Michael J. Fromberger) Date: Tue, 17 Aug 2004 20:56:02 -0400 Subject: PEP 318: Can't we all just get along? References: <20040817181725194-0400@braeburn.themorgue.org> Message-ID: In article <20040817181725194-0400 at braeburn.themorgue.org>, Kevin Smith wrote: > > Bear with me, but I'd like to propose one more syntax that is simple, > easy for newbies to understand, and nowhere near as powerful as the > current PEP's syntax. However, it doesn't add incoherent, arbitrary > syntax either. > > def classmethod foo(x, y, z): > pass > > That's it. One "decorator" that is a callable object that takes a > method as it's only argument. No expressions, lists, tuples, etc. Just > one callable object. Ok, if you absolutely must have more than one. > > def classmethod synchronized foo(x, y, z): > pass > > Once again, no expressions. I know that this isn't going to solve > everyone's type-checking, metadata, and function attribute problems, but > let's face it, using this PEP for all of those things just creates ugly > syntax. There must be more Pythonic ways to do those things in their > own PEPs. Kevin, +1 for this idea. I completely agree that the original PEP-318 proposed a simple and reasonable idea, and I too have been much dismayed by all that seems to have been grafted onto it since. This latest idea of yours certainly sounds a lot more reasonable than anything else I've seen so far. It solves the original well-defined problem cleanly, and probably solves some of the other proposed uses too. I would even go so far as to say: Go ahead and restrict it to at most one callable object. If someone really wants to define a flaming hot crossed synchronized blue classmethod foo, they can bloody well define a callable object that has the (in)appropriate behaviour. I hope that perhaps cooler heads (such as yours) will prevail, and keep Python's syntax and semantics relatively neat and tidy. We don't need the One PEP to Rule Them All, in the Land of Python where the shadows -- so far -- do not lie. -M, "one more PEP out of you, mister, and you're history!" ;) -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From dperl at rogers.com Fri Aug 27 16:23:25 2004 From: dperl at rogers.com (Dan Perl) Date: Fri, 27 Aug 2004 20:23:25 GMT Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> Message-ID: <1LMXc.67190$UTP.37420@twister01.bloor.is.net.cable.rogers.com> ----- Original Message ----- From: "Alex Martelli" Newsgroups: comp.lang.python Sent: Friday, August 27, 2004 1:37 PM Subject: Re: would be nice: import from archive > Python 2.3 lets you import modules from a zipfile. The zip format is > better than tar when you just need to get one file from it, which is why > java's jar files are also basically zipfiles. [...] > It's there already, and has been for over a year now;-). > > Alex Alright, alright! And given the fact that it was added only in 2.3, that explains why I couldn't find any mention of the feature in 'Python Cookbook', the 1st ed. I'm looking forward to seeing it mentioned in the 2nd ed. ;-) Dan From http Thu Aug 26 03:27:37 2004 From: http (Paul Rubin) Date: 26 Aug 2004 00:27:37 -0700 Subject: Why return None? References: Message-ID: <7x65762wba.fsf@ruckus.brouhaha.com> Peter Hansen writes: > > instance, I can't say move(Vector([a,b,c]).normalize()), I have to do > > a = Vector([a,b,c]) > > a.normalize() > > move(a) > > By the way, the second version is much more readable than the first, That's a matter of opinion. The lines are shorter but there are three times as many of them. I think programmers ought to be able to make their own choices about this. There are a lot of different styles that are equally legitimate. From insert at spam.here Sun Aug 22 09:07:53 2004 From: insert at spam.here (Doug Holton) Date: Sun, 22 Aug 2004 08:07:53 -0500 Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? In-Reply-To: References: Message-ID: Paul McGuire wrote: > Total voters: 55 > Of all of the votes cast, J2 > received 48%, C1 received 18%. No other option received more than 10% of > any votes. I vote 3 times for C1. So just my one vote raises C1 to 20%. I think you need to do an online poll so you get more people than just those who have been discussing the decorator keyword here this past week. I got over 250 votes for C1 just last week vs. the 22 who voted for J2 here. During this 2nd poll people were confused about whether they could vote for A1 or not, and some people said many of the options on the wiki page were not allowed anymore. Just make a poll with J2 vs. C1 and see what you find. From grv575 at hotmail.com Mon Aug 23 18:55:31 2004 From: grv575 at hotmail.com (grv575) Date: 23 Aug 2004 15:55:31 -0700 Subject: % format strings Message-ID: <144d0df.0408231455.6b664466@posting.google.com> For a string like print '%.*f' % (prec_length, float_var) How does python convert this to a C printf sytle format string? Is there a way to specify the precision length for floating points in C format strings? From peter at engcorp.com Mon Aug 30 09:30:39 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 30 Aug 2004 09:30:39 -0400 Subject: PHP Documentation In-Reply-To: <4133124f$0$281$4d4ebb8e@news.nl.uu.net> References: <4133124f$0$281$4d4ebb8e@news.nl.uu.net> Message-ID: Guyon Mor?e wrote: > hi, I've been working with PHP lately and what I found is that the docs are > awesome, as is the python are python docs btw. but one thing that I really > like about theirs is the doc-commenting system it has. > > any user can comment on any page in the docs. this results in a lot of > clarifications and examples for the subjects at hand. > > is it an idea to implement this in the python docs? > i believe it's a good idea what are your thoughts? This comes up every month or three in this newsgroup and I think I can summarize the comments of others by saying two things: 1) Thinking it's a good idea isn't enough if you want it: somebody has to implement it. It's been suggested before, so at this point the next step is for someone who likes the idea enough to just do it. 2) Many people think that the noise created by lots of user comments would far outweigh the value of the good comments that might be hidden somewhere within. -Peter From fumanchu at amor.org Wed Aug 4 13:09:14 2004 From: fumanchu at amor.org (Robert Brewer) Date: Wed, 4 Aug 2004 10:09:14 -0700 Subject: Finding all time periods for a given interval within a date range Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022DD9@exchange.hqamor.amorhq.net> Graeme Longman wrote: > I was wondering if anyone has written some Python code which > uses a start > date and end date and a given interval (day, month or year) > and outputs all > the time periods for that range and interval. > > For example you may wish to find all the months between the dates > '2004-02-14' and '2004-08-04'. You would maybe use a function > where you pass > in those starting and ending dates and the interval 'month' > and you'd get > back a list of those months. I guess you would need to year > part of the date > too, so ['2004-02', '2004-03', '2004-04', '2004-05', > '2004-06', '2004-07', > '2004-08']. If you had passed in 'day' as the interval then > you would be > given back a list of all the days in those months. Look at my 'recur' module and see if it fits your requirements: http://www.aminus.org/rbre/python/index.html Start with the Recurrence class and play with it--then dig deeper if you need to. HTH, Robert Brewer MIS Amor Ministries fumanchu at amor.org From 510046470588-0001 at t-online.de Sat Aug 21 03:54:49 2004 From: 510046470588-0001 at t-online.de (510046470588-0001 at t-online.de) Date: 21 Aug 2004 09:54:49 +0200 Subject: Fate of lambda, Functional Programming in Python... References: <412636D1.6070808@noaa.gov> <41265E67.A08409A6@juno.com> <2on5k1FcjmvdU1@uni-berlin.de> <4dxun9nvgeaz.dlg@baczek.net.invalid> Message-ID: <87y8k9hqnq.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Marek Baczy?ski writes: > > [lambda x, y: x+y, lambda x, y: x*y, ... (etc.)] > > I don't say it's impossible, but largely superfluous. (Note that this > *particular* case can be (better) solved by operator.*.) i find infix notation disgusting, thus refuse to use it globally. may map, filter, reduce be implemented in pure python if they weren't built-in? scheme e.g. does not have built-in filter, but may implement it on the fly. may lambda be implemented with exec if it isn't built-in? i've seen something like this done in php4 by E. Ellingsen. would that work in crippled python, too? Klaus Schilling From rnd at onego.ru Wed Aug 18 15:09:49 2004 From: rnd at onego.ru (Roman Suzi) Date: Wed, 18 Aug 2004 23:09:49 +0400 (MSD) Subject: age of Python programmers In-Reply-To: References: Message-ID: On Wed, 18 Aug 2004, Lucas Raab wrote: >One thing I've always kind of wondered is what is the average age of a >Python programmer?? What age groups use Python?? Something to think >about.... I am still younger than average Python programmer: 30 Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3 From geoff at variosoft.com Sat Aug 7 17:18:55 2004 From: geoff at variosoft.com (Geoff Caplan) Date: Sat, 7 Aug 2004 22:18:55 +0100 Subject: Compiling disutil modules on Windows In-Reply-To: References: Message-ID: <19249730658.20040807221855@variosoft.com> Michel, MCamgntefp> Look the message "Building Python 2.4 extensions with the Microsoft Toolkit MCamgntefp> Compiler" from 17 jul 2004 Thanks for the link, but I don't think it's a viable solution for me. First, it seems to be aimed at the official Alpha release of 2.4 which is compiled with the MVC++ 7. I need to get something working with the stable Active State distro, which is compiled with MVC++ 6. Also, Mike says it's aimed at experienced extension developers with experience of C compilers, and that "It is not really targeted at end-users." He also says: "Note that this document represents the findings of a very limited set of tests with what is essentially an unsupported approach to building extensions. You should expect to find bugs. No warranty is made that the approach outlined is safe or appropriate." I think that this approach would be well beyond my level of competence! What is the best way for an end-user with minimal C skills to get extensions working on Windows? I would abandon the Active State distro if I had to, but only reluctantly, as in other respects it seems very convenient. ------------------ Geoff Caplan Vario Software Ltd (+44) 121-515 1154 From me at privacy.net Sun Aug 15 14:00:12 2004 From: me at privacy.net (Tobias Pfeiffer) Date: 15 Aug 2004 18:00:12 GMT Subject: Stopping a socket.accept() method Message-ID: <2o9mlbF8ff8rU1@uni-berlin.de> Hi! I am writing a network game where the server runs in a console window. The person who has opened the server shall be able to stop the process of accepting new clients. By now, I am handling that like this: while 1: try: bla = socket.accept() except KeyboardInterrupt: break socket.shutdown(2) So the user can Ctrl+C and no more clients will be accepted. Unfortunately, this doesn't work in Windows. So how can I give the user the ability to quit the loop interactively? Any ideas? Bye Tobias -- please send any mail to botedesschattens(at)web(dot)de From tdelaney at avaya.com Sun Aug 29 20:38:49 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Mon, 30 Aug 2004 10:38:49 +1000 Subject: Alex Martelli: Welcome back! Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01DCFEFB@au3010avexu1.global.avaya.com> Alex Martelli wrote: > This time around I'm gonna try -- I'm as busy as ever (the 2nd Edition > of the Python Cookbook is at least as intense a project as the first > was...), but if I can steel myself to use my killfile 100 times more > than in the past, and still try to respond on some threads which might > be interesting or useful. We'll see if it works! I've actually found that spambayes works fairly well as a killfile - enough that I don't bother top maintain any other killfile. It usually takes about 3 posts added as spam for someone to start disappearing ... Tim Delaney From ptmcg at austin.rr._bogus_.com Mon Aug 23 11:17:31 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 23 Aug 2004 15:17:31 GMT Subject: 2 GB files References: <9418be08.0408221427.182a4d30@posting.google.com> <9418be08.0408221939.7003bd3c@posting.google.com> Message-ID: "Bart Nessux" wrote in message news:cgcv5v$sjq$1 at solaris.cc.vt.edu... > Oh, I forgot, Python is free. Perhaps the developers are willing to > provide a refund to dissatisfied users ;) Just like Microsoft - return the unused portion of the software, and we'll return the unused portion of your money! -- Paul From cjw at sympatico.ca Wed Aug 25 22:01:25 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Wed, 25 Aug 2004 22:01:25 -0400 Subject: Alternative decorator syntax decision In-Reply-To: <412cc31c$1@news.012.net.il> References: <412cc31c$1@news.012.net.il> Message-ID: Avner Ben wrote: > I believe putting the decorator list before the function header is > generally a bad design decision. While it may make parsing-related > sense, it violates Python's greatest asset: being executable pseudocode. > The way I see it, the latter quality means being able to look at the > code and see clearly and immediately what requirements from the real > world the code was written the serve. Functions and methods are major > code entities that are naturally expected to represent discrete > functional requirements from the code, to this or that level of detail. > I expect to learn from the method name, the class it is in and the list > of arguments it takes, everything I need to know about the functional > requirement it implements. If that is not enough, I will look at the > docstring, if present. Everything else the method has to offer is > conveniently hidden below. Decorators of the type discussed recently - > with the exception of staticmethod and classmethod - are technical > detail of the kind I would like to see hidden below. Putting them on > top, prior to the what the method does (its name etc.) compromises the > design quality of the code, reducing it to yet another > abbreviation-based, self-centered technical scripting language. > The one esception I saw was J2, which, although putting the decorators > before the proper method header, uses indentation to state "this is an > extra piece of technicality which you are free to ignore - the def is > below." > > My vote: C2, E4, J2 > > Avner. Your expectation list makes sense to me. There is merit in having the docstring before the 'decorator', i.e. E4 Colin W. From peter at engcorp.com Thu Aug 26 01:36:10 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 26 Aug 2004 01:36:10 -0400 Subject: Why return None? In-Reply-To: References: Message-ID: Martin DeMello wrote: > It seems to be a fairly common pattern for an object-modifying method to > return None - however, this is often quite inconvenient. http://www.python.org/doc/faq/general.html#why-doesn-t-list-sort-return-the-sorted-list (Not an answer to the general question you ask, unless you extrapolate from the specific answer given there to the more general case.) -Peter From espen at *do-not-spam-me*.vestre.net Thu Aug 26 03:12:58 2004 From: espen at *do-not-spam-me*.vestre.net (Espen Vestre) Date: Thu, 26 Aug 2004 09:12:58 +0200 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: Rich Teer writes: > I think you're getting confused with the Blue ?yster Cult. > Don't Fear the Reaper - great song. Great song, but their hard-hitting stuff is even better. For instance "Lisp in the Hills" or "Career of Eval". -- (espen ;-) From db3l at fitlinxx.com Thu Aug 26 18:23:48 2004 From: db3l at fitlinxx.com (David Bolen) Date: 26 Aug 2004 18:23:48 -0400 Subject: Message queues [Re: Best processor (i386) for Python performance?] References: <412dfb17$0$65599$a1866201@newsreader.visi.com> Message-ID: Ville Vainio writes: > >>>>> "David" == David Bolen writes: > > David> I do think it can be tricky to determine just what case an > David> application falls into (and many oscillate between I/O and > David> CPU bound modes), and indeed a purely CPU bound Python > David> application (if in Python code and not a well-behaving > David> extension module) isn't going to be helped at all. > > The sensible thing to do then is to use multiple processes, not just > multiple threads. Many Python apps use Queue.Queue anyway, and such an > approach is often easy to convert over to use processes instead of > threads. Well, "sensible" may depend on your needs and environment. I'm far less a fan of multi-process situations under Windows than I am under Unix systems for example. In Windows process creation is far less efficient, and proper parent/child relationships don't always work properly (particularly when it comes to killing processes off) and such. Threading, on the other hand, just plain works extremely well, at least on the WinNT/2K/XP variants. That's almost backwards to the way I feel about things under Unix, where the various thread implementations and support for them on different systems can make separate processes more attractive. But you're right that multi-process solutions are certainly something to keep in the toolbox as available options. -- David From pinard at iro.umontreal.ca Mon Aug 23 12:44:45 2004 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Mon, 23 Aug 2004 12:44:45 -0400 Subject: J2 decorator grammar In-Reply-To: <2orckjFdtljaU1@uni-berlin.de> References: <2orckjFdtljaU1@uni-berlin.de> Message-ID: <20040823164445.GB8036@titan.progiciels-bpi.ca> [Peter Maas] > Robert Brewer schrieb: > with: > return ... > accept ... > classmethod > def func(): > > "using" instead of "with" would be equally satisfactory for me. I > don't like "decorate" because it sounds like "attaching some bells > and whistles" or "making it look pretty" which isn't adequate for the > meaning of this syntax. I'm not especially crusading for `with', but it has the advantage that it will likely become a keyword in some later version of Python, and likely also, will be used in `with SOMETHING:' and not barely as `with:'. Reserving a keyword is a lengthy process, like it was demonstrated by the progressive implementation of `yield'. So using `with' here would be a nice investment for the future in that regard. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From uche at ogbuji.net Mon Aug 9 10:22:14 2004 From: uche at ogbuji.net (Uche Ogbuji) Date: 9 Aug 2004 07:22:14 -0700 Subject: Module for converting XML to Python object(s)? References: Message-ID: "Robert Oschler" wrote in message news:... > Has anybody seen a Python module that will take an XML document (not a > colossal one), and convert it to a Python nested class object? I'm > basically looking for something that would allow me to parse an XML document > (not tokenize it like SAX or make it into an XPath accessible DOM object > like others), directly into a nested Python object so I could access > everything through Python class attribute references. There is a metric ton of these "data bindings". See: http://www.xml.com/pub/a/2003/06/11/py-xml.html http://www.xml.com/pub/a/2003/07/02/py-xml.html http://www.xml.com/pub/a/2003/08/13/py-xml.html http://www.xml.com/pub/a/2003/12/17/py-xml.html Based on your description, your best bets are generate_ds, gnosis objectify, xmltramp and Anobind. Good luck, and do report back on your experiences. -- Uche Ogbuji Fourthought, Inc. http://uche.ogbuji.net http://4Suite.org http://fourthought.com Perspective on XML: Steady steps spell success with Google - http://www.adtmag.com/article.asp?id=9663 Use XML namespaces with care - http://www-106.ibm.com/developerworks/xml/library/x-namcar.html Managing XML libraries - http://www.adtmag.com/article.asp?id=9160 Commentary on "Objects. Encapsulation. XML?" - http://www.adtmag.com/article.asp?id=9090 Harold's Effective XML - http://www.ibm.com/developerworks/xml/library/x-think25.html A survey of XML standards - http://www-106.ibm.com/developerworks/xml/library/x-stand4/ From john at grulic.org.ar Mon Aug 30 16:33:10 2004 From: john at grulic.org.ar (John Lenton) Date: Mon, 30 Aug 2004 17:33:10 -0300 Subject: Search for AVI file? In-Reply-To: References: Message-ID: <20040830203310.GB10271@grulic.org.ar> On Mon, Aug 30, 2004 at 10:23:05PM +0200, Peter Kleiweg wrote: > Peter Kleiweg schreef: > > > John Doe schreef: > > > > > I realise that this is not really a python question, but python's the > > > only language I'd be comfortable trying to deal with this. > > > > > > What I need is to search a drive and find all the AVI format files > > > that are NOT listed with the AVI extension. I'm looking over an old > > > drive of mine from an old computer. I know the files were renamed > > > with the wrong extension, but I know that they were originally AVI > > > files. Can python do this for me? Any hints? Anybody have a link to > > > something that would already do this? I appreciate any help. > > > > Use walk() to find all files. Open each file and read in the > > first 12 bytes. The last four of those 12 bytes should be > > 'AVI ', if I'm not mistaken. > > Or from the command line: > > find / -type f -exec file '{}' ';' | grep AVI if that's GNU find, you'll find find / -type f -print0 | xargs -0 file | grep AVI a lot faster, usually. -- John Lenton (john at grulic.org.ar) -- Random fortune: Them as has, gets. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From uri.nix at zoran.com Sun Aug 22 06:51:17 2004 From: uri.nix at zoran.com (Uri Nix) Date: 22 Aug 2004 03:51:17 -0700 Subject: Process spawning in win32 Message-ID: <309a1af8.0408220251.15b8084b@posting.google.com> Hello, I'm using Python to automate some test suites for an external simulator. Up to now I've been using the os.spawnl() successfully. Recently, I've changed simulator versions and encountered the following problem: using os.spawnl() from within the IDLE activates the simulator just fine; using the _same_ code from a script (either from IDLE or command line) doesn't. It looks like the simulator isn't being activated from its working directory. I've tried using Mark Hammond's win32process to verify I'm passing the correct environment and working directory, but get the same results. Why should spawnl() work differently from within IDLE or otherwise? (Using Python 2.3.4 on WindowsXP) Cheers, Uri From rnichol_rrc at yahoo.com Tue Aug 17 12:21:38 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Tue, 17 Aug 2004 11:21:38 -0500 Subject: Python secure? In-Reply-To: References: <2xXTc.3775$bJ2.24876@news1.mts.net> Message-ID: Terry Reedy wrote: > As we both said, C is safer in the hands of expert, experienced, careful > programmers. People like you claim to be and people like Guido and Tim > Peters. They program in C so we have less need to. And I am grateful for > that. Oh yah, when did I claim to be like Guido and/or Tim Peters? From asif at go-away-spammer.com Wed Aug 25 19:16:43 2004 From: asif at go-away-spammer.com (Player) Date: Thu, 26 Aug 2004 00:16:43 +0100 Subject: Begginer question about py install References: Message-ID: "vincent wehren" wrote in message news:cginse$nog$1 at news1.tilbu1.nb.home.nl... : Player wrote: : : > Also PyWin32 the latest version or build, will not install with the latest : > version of python, it requires 2.2 version of python, while the latest v of : > python is 2.3. :( : > : > M.B : > : > : You probably just grabbed the wrong version. Note that build numbers are : now the same for all, but for Python 2.3.x you need: : : http://prdownloads.sourceforge.net/pywin32/pywin32-202.win32-py2.3.exe?download : : : HTH, : : -- : Vincent Wehren Cheers, yeah I realised after someone told me about the different releases, what I had done. D'OH!! Thanks anyways.. M.B From littlejohn.75 at noos.fr Sun Aug 15 11:53:42 2004 From: littlejohn.75 at noos.fr (F. Petitjean) Date: 15 Aug 2004 15:53:42 GMT Subject: Python secure? References: Message-ID: <411f8706$0$29658$636a15ce@news.free.fr> On Sun, 15 Aug 2004 15:10:07 +0100, Calvin wrote: > > Sorry I should have said I'm new to programming let alone Python. I wish to > know whether Python is secure as an exe for a commercial product. i.e. can > someone see your code more easily than in say using another language. We're > not talking financial / security type software here just a basic windows > app. to be clear commercial product == some software (you said exe) which is delivered and can run only if "the client" has paid some amount. and in your mind secure == someone cannot easily see the code it is the archetypical (sp?) definition of "security by obscurity" Since you are new to prograaming (and to python) let me explain that for me python is a opensource language/system and as such the main goal is not to have the most obscure code :-) (it is rather difficult to create hard to read python code) And do you know that there is more than just "a basic windows app" ? How do you explain that a system such as Debian exists ? (http://www.debian.org ) The "applications" are not called exe, do they run or not ? > > Thanks > > From joshl at commenspace.org Tue Aug 24 12:31:59 2004 From: joshl at commenspace.org (Josh) Date: Tue, 24 Aug 2004 09:31:59 -0700 Subject: Newbie: Downloading a pushed file Message-ID: First, I'm new at this. Next, my question: I'm trying to write a script that downloads requested files from a website. The site works, I think, as follows: 1: Give the site a URL 2: Site comes back with a 'waiting' message, then after some time returns a bunch of download URL's 3: If you open a window with the new download url _in the same browser session_ then you get a new window which says things like 'processing' for a while, and then pushes you a file, for lack of a better word. It's sort of like when you go to sourceforge and click a download mirror, and then after a few seconds you get a window pop up asking to save the file. Now, so far I've managed, in an ugly manner I am sure, to get the initial page, parse the download URL's, and I did this having pything use an IE browser, as described in: http://vsbabu.org/mt/archives/2003/06/13/ie_automation.html My problem is when I get to the download page, how do I tell ie to go ahead and save the file it gets pushed? Another question would be how do I do it without IE .. I assume if I keep the socket open and send the site some header, perhaps HTTP_REFERER, then it will let me move on to the download pages, but I havent even figured out how to re-read the socket after the initial page refreshes (every re-read comes up blank, even though I know the page should have sent me new data) Sorry for my probably poorly worded descriptions, and thanks for any help. -Josh From xnews2 at fredp.lautre.net Tue Aug 10 05:50:52 2004 From: xnews2 at fredp.lautre.net (Fred Pacquier) Date: 10 Aug 2004 09:50:52 GMT Subject: VB-like GUI designer? References: Message-ID: Geoff Caplan said : > Check out VisualWx. > > http://visualwx.altervista.org/ Hey, thanks for the pointer, this one looks really nice (even if it's only available for Windows ATM)... Out of curiosity, how did you come across it ? This sort of topic pops up every month or so on this group, and I'd never seen it mentioned before, although it seems the project has been going on for a while already... -- YAFAP : http://www.multimania.com/fredp/ From fredrik at pythonware.com Wed Aug 11 11:51:03 2004 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 11 Aug 2004 17:51:03 +0200 Subject: Pilprint References: Message-ID: Chris Jankowski wrote: >I am a newbie to the world of Python and trying to print some > images(.tif). I have installed the PIL Library and can use the some > of the fuctions like: m.format, im.size, im.mode without any problem. > When I try to use the Tools like pilprint and pilfile, I can't seem to > get them to work. Any help would be greatly appreciated. > > Examples: >>>> pilfile *.tif > Traceback ( File "", line 1 > pilfile *.tif > >>>> pilprint 'c:/chris.TIF' > Traceback ( File "", line 1 > pilprint 'c:/chris.TIF' > ^ > SyntaxError: invalid syntax pilprint (etc) are programs, not Python statements. you're supposed to run them from the standard command line, not Python's interactive prompt. depending on your operating system, and how things are set up, some of these should work: pilprint.py c:/chris.tif python pilprint.py c:/chris.tif pilprint c:/chris.tif From skip at pobox.com Tue Aug 10 12:27:20 2004 From: skip at pobox.com (Skip Montanaro) Date: Tue, 10 Aug 2004 11:27:20 -0500 Subject: unicode to ascii converting In-Reply-To: References: <1091815856.527127@news.commspeed.net> Message-ID: <16664.63336.545893.13383@montanaro.dyndns.org> Michel> # -*- coding: cp1252 -*- Michel> aa = u"?" Michel> aa.encode("ascii","ignore") A somewhat less destructive solution might be to try my latscii codec: http://manatee.mojam.com/~skip/python/latscii.py (assuming your input is encoded as latin-1). Skip From mudd at vex.net Tue Aug 10 08:48:42 2004 From: mudd at vex.net (mudd at vex.net) Date: Tue, 10 Aug 2004 08:48:42 -0400 (EDT) Subject: decorators vs GIL In-Reply-To: <96c2e938.0408091819.2cd7b50d@posting.google.com> References: <96c2e938.0408091819.2cd7b50d@posting.google.com> Message-ID: <43428.12.151.80.14.1092142122.squirrel@webmail.vex.net> state machines and processes [and inter-process communication/coordination]? It sounds like you're saying the alternative to threads is "home brewed" threads. I don't follow. Until recently linux implemented threads as processes. I'm really not concerned with how the threads are implemented in the thread library. I just don't want a language to prevent me from accessing the thread library. > > Threads often seem simple at the outset, but most of the time they > wind up being far more complex to program and debug than judicious use > of state machines and processes. From beliavsky at 127.0.0.1 Tue Aug 3 16:31:28 2004 From: beliavsky at 127.0.0.1 (beliavsky@aol.com) Date: 3 Aug 2004 15:31:28 -0500 Subject: How to dynamically access Numeric subarrays References: Message-ID: <410ff620_1@127.0.0.1> Gaubitzer Erwin wrote: >So my questions to out there: >How can I extract a (Numeric Python) subarray whose indices >have to be built dynamically. Can the "take" function do what you want? ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--- From python at rcn.com Thu Aug 26 02:01:12 2004 From: python at rcn.com (Raymond Hettinger) Date: 25 Aug 2004 23:01:12 -0700 Subject: Proposal for removing self References: Message-ID: <5d83790c.0408252119.1852f7e@posting.google.com> "Brent W. Hughes" wrote in message news:... > When doing object-oriented stuff, it bothers me to have to type "self" so > many times. I propose that Python allow the programmer to optionally type > ".variable" instead of "self.variable" to mean the same thing. Of course, > the interpreter would have to be more careful about detecting floats that > begin with just a period as in ".5". What are your thoughts? There's a FAQ on the subject: http://www.python.org/doc/faq/general.html#why-must-self-be-used-explicitly-in-method-definitions-and-calls Raymond Hettinger From tim.peters at gmail.com Fri Aug 6 10:34:48 2004 From: tim.peters at gmail.com (Tim Peters) Date: Fri, 6 Aug 2004 10:34:48 -0400 Subject: Timing Difference: insert vs. append & reverse In-Reply-To: References: <35b736b9.0408020330.53b24ed3@posting.google.com> <1a517b5.0408031027.60554dfb@posting.google.com> <1a517b5.0408041305.3927a6c8@posting.google.com> Message-ID: <1f7befae040806073458c115f0@mail.gmail.com> [Bryan Olson, on deques & Python's list type] ... > Agreed. But those Perl wizards, misguided as they may be, are > pretty sharp. Yup. ... [Tim] >> You can pursue it if you want to, but with the 2.4 deque type I have >> no interest in messing more with the list type. [Bryan] > I'm talking about facilities and their implementations, not people. Sure! I'm one of the handful of people who might actually "do something" about this kind of issue, and I was telling you that I won't. Your chances of seeing what you suggest are highly correlated with finding someone who will "do something" . I don't know whether Raymond Hettinger is interested in pursuing this further, but if he isn't either (that's my guess), then the only realistic chance is if you do the work yourself. > True, when I pointed out that Perl nails this one, Which part I disagree with, for reasons already given. > I was kinda' thinking the comparison might motivate Pythoners to > pursue the same enhancement. And the desire for efficient "both ends" operation led to 2.4's deque type, which isn't "the same" enhancement because it didn't end up in the base list type, but is a better enhancement for people who truly need both-ends performance. > It was certainly *not* meant to deride anyone who contributed to implementing > Python. I didn't read it that way. > Is Tim the superior Pythoner? Duh. Does Python rock? Sure. > Is saving four-or-eight bytes more or less valuable than > providing efficient insert at both ends? In the basic list type, yes, it's more valuable in Python to save the 8 bytes. The speed of "left end" insert/remove is insignificant for most Python apps, and is quite fast anyway for small lists. It's a major concern for *some* Python apps, and the deque type serves those better than fudging the list type could. The majority who don't care don't pay for it. > With all due respect to Python and the people who implemented it, Perl kicks > on this one. I agree that Perl has a good approach here. I think Python's is better, though. From fumanchu at amor.org Tue Aug 24 13:11:08 2004 From: fumanchu at amor.org (Robert Brewer) Date: Tue, 24 Aug 2004 10:11:08 -0700 Subject: J2 paper 0.2.1 Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E51@exchange.hqamor.amorhq.net> Greg Chapman wrote: > Note that this: > > : > memoize > classmethod > synchronize > funcattrs(author="Guido van Rossum") > def foo(cls, *args): > pass > > is probably broken, at least given most of the proposed > implementations, in which classmethod and staticmethod > would have to be either first or last. Thanks! Fixed. > Also this: > > "In contrast, the current Python decorator proposal provides the exact > opposite--all decorators accept one function and return one > function. Although > they are not required to return a new function, or change > function signatures or > calling semantics, many will, including the most common > decorators, classmethod > and staticmethod." > > is wrong in that classmethod and staticmethod do not return > functions (or even > callables), which is why they have to be in a special place. However, they "change calling semantics" both for the caller ( Thing.method() versus Thing().method() ) and the callee (instead of receiving self as the first arg, they receive cls or nothing). I'll try to think of a way to rewrite it where that's more clear. Thanks for the comments! Robert Brewer MIS Amor Ministries fumanchu at amor.org From michael at hobbshouse.org Wed Aug 25 12:56:32 2004 From: michael at hobbshouse.org (Michael Hobbs) Date: Wed, 25 Aug 2004 11:56:32 -0500 (CDT) Subject: ANN: Python + Erlang = Candygram Message-ID: <16999.209.46.8.140.1093452992.squirrel@mail.hobbshouse.org> Announcing the first public release of Candygram: Candygram 1.0 beta 1 Candygram is a Python implementation of Erlang concurrency primitives. Erlang is widely respected for its elegant built-in facilities for concurrent programming. This package attempts to emulate those facilities as closely as possible in Python. With Candygram, developers can send and receive messages between threads using semantics nearly identical to those in the Erlang language. More information about Candygram can be found at http://candygram.sourceforge.net From anthonybaxter at gmail.com Sun Aug 22 04:55:48 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sun, 22 Aug 2004 18:55:48 +1000 Subject: Python future performance and speed In-Reply-To: References: <278de0e.0408211605.426e5129@posting.google.com> <7x4qmv6cwo.fsf@ruckus.brouhaha.com> Message-ID: On 22 Aug 2004 11:36:16 +0300, Ville Vainio wrote: > What kind of mainstream application would be too slow if implemented > in Python? Well, perhaps image / video editing... Maybe. You could, however, do the computationally expensive parts in numarray. (As a random-anecdote on the topic - experiments with using shtoom to transmit and receive video over IP as well as audio over IP show that Python is fast enough to do this...) From Sibylle.Koczian at Bibliothek.Uni-Augsburg.de Fri Aug 27 04:14:02 2004 From: Sibylle.Koczian at Bibliothek.Uni-Augsburg.de (Sibylle Koczian) Date: Fri, 27 Aug 2004 10:14:02 +0200 Subject: mySQLdb In-Reply-To: <1093558526.705789@seven.kulnet.kuleuven.ac.be> References: <1093558526.705789@seven.kulnet.kuleuven.ac.be> Message-ID: <2p88qaFhfaeqU1@uni-berlin.de> m0226065 schrieb: > so I have a mySQL server > and mySQLdb as an interface (do I us this term correct here?) to this server > from python > now I have a game: > I want to read a file into the db > I want other data to be kept in the db from now on > > problem: > since I have special things I want to do (like write a dict into a db), do I > have to write a specialized class, derived from mySQLdb, or would that be > dumb? I mean, I guess it would be easier to write some functions that take > care of everything, while I just say "write this dict to that table" or > "write this dict item to that table" and so on. > You can't derive a class from mySQLdb, because that is a module containing several classes. If I understand your description correctly, you would need functions that - convert a data structure, for example a dict or a dict item, to parameters suitable for a SQL query, - execute (and possibly construct) the right query with those parameters. Right? That might quite well be encapsulated into a class, but I don't think such a class would have an "is-a" relationship to a MySQLdb class. I'd rather give it a MySQLdb.cursor and possibly a MySQL.connection instance as attributes. Koczian -- Dr. Sibylle Koczian Universitaetsbibliothek, Abt. Naturwiss. D-86135 Augsburg Tel.: (0821) 598-2400, Fax : (0821) 598-2410 e-mail : Sibylle.Koczian at Bibliothek.Uni-Augsburg.DE From newsgroups at jhrothjr.com Thu Aug 5 09:06:01 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Thu, 5 Aug 2004 09:06:01 -0400 Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) References: <1646998998.20040804190026@MailBlocks.com> <10h34ivio5s2c21@news.supernews.com> Message-ID: <10h4c5iicgv7k74@news.supernews.com> "Michael Hudson" wrote in message news:m3pt65g4hb.fsf at pc150.maths.bris.ac.uk... > "John Roth" writes: > > > "Bruce Eckel" wrote in message > > news:mailman.1168.1091667628.5135.python-list at python.org... > > > I'll weigh in a little on this one. > > > > > > This is very similar to attributes/metadata in Java J2SE 5 and in C#. > > > The thing is, metadata is a little bit weird; it's intentionally > > > outside of the domain of the 'normal' programming language, because it > > > expresses things that you can't or shouldn't within the normal > > > programming language. > > Except, of course, this is Python so there isn't any such thing as > metadata, really. Objects all the way down. > > > > So you _do_ need an escape mechanism. And it also takes a little > > > bit of getting used to; it's orthogonal to what you normally think > > > of as a language feature. But the potential for metadata features, > > > at least in Java, is very powerful. > > > > I'd be a lot happier if it was, in fact, a general metadata > > facility. Unfortunately, it only seems to work on functions > > (methods), and for what I'm working on I need metadata for > > properties and fields as well, that is, any identifier that you can > > bind an object to. > > Well, that would be because that's impossible :-) I wish you'd have told me that before I did it. As I said in a prior post, I had to put a general metadata facility into PyFIT, and it's working quite nicely, thank you. What I did was put a dictionary with a known name (_typeDict) into the class, and stick the metadata in there. It's nowhere near as convenient as being able to directly associate it with the needed bindings, but it does serve my needs in that particular package. > Where would you > attach the data in: > > class C(object): > @funky > i = 0 > > ? > > You can't attach it to 'i' -- that's just a string. '0' is just an > integer. The class doesn't exist at the time the body is executed. Two of which are exactly the points I mentioned. The third is piffle. If the implementer wanted to do it, there is no reason why it couldn't be done. > > What you can do (today) of course is stuff like: > > class C(object): > i = MagicProperty(int, default=0) > > or something -- which obviously leaves ample space for metadata in the > argument list -- but that can be painful, I grant. > > What kind of metadata do you want? Type and other declaration information for any identifiers that will be referenced in the FIT tests. Other information includes things like precision for floating point numbers, strings that are accepted as "true" or "false" for booleans, the subtype for lists and tuples, references to custom type adapters and other stuff. > (I have to admit I read your first post on this thread a bit like > "this hammer doesn't do a very good job of screwing in screws" :-) Well, that's basically what it said, after all. I was trying to find something I could use the facility for. I can always dream up ways someone else could use it, but I've found out after long and painful experiance that if I'm not the developer in question, at best it's a futile exercise. That was basically my comment about ctypes. AMK's blog entry referenced the ctype's documentation page, which didn't tell me anything about what Thomas Heller would do with it in the context of that package, and I'm not enough of an expert on ctypes to see it myself. John Roth > > Cheers, > mwh > > -- > It is time-consuming to produce high-quality software. However, > that should not alone be a reason to give up the high standards > of Python development. -- Martin von Loewis, python-dev From crichton314 at btinternet.com Thu Aug 26 06:37:04 2004 From: crichton314 at btinternet.com (John Crichton) Date: 26 Aug 2004 03:37:04 -0700 Subject: Call for signatories for J2 References: Message-ID: <3b2846c4.0408260237.182e749d@posting.google.com> Vote: FOR Could I also echo Fernando Perez's sentiments in thanking the people who have worked so hard putting this proposal together. Best wishes, John Crichton From jdhunter at ace.bsd.uchicago.edu Mon Aug 30 08:54:44 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Mon, 30 Aug 2004 07:54:44 -0500 Subject: Newby pango problem In-Reply-To: <2pg9tfFjilreU1@uni-berlin.de> (Friedrich Dimmling's message of "Mon, 30 Aug 2004 11:21:58 +0200") References: <2pg9tfFjilreU1@uni-berlin.de> Message-ID: >>>>> "Friedrich" == Friedrich Dimmling writes: Friedrich> Hi, I would like to use pango.layout to display text in Friedrich> a pygtk2 project. However I could not manage to get the Friedrich> pango.layout object incorporated in my toplevel Friedrich> gtk.Window and have it displayed. Friedrich> If anyone could help me either with a minimal example Friedrich> like 'Hello World' displayed in italics in an Friedrich> pango.layout or the URL to a tutorial where I can find Friedrich> the relevant infos (the PyGtk tutorial seems not to Friedrich> contain it, unless I'm really blind) Here is pango_demo.py from my pygtk examples dir. I wrote this a long time ago, so it may not be the best or most modern usage, but it may help you along your way from __future__ import division import pygtk pygtk.require('2.0') import gtk from gtk import gdk import pango win = gtk.Window() win.show() vbox = gtk.VBox() vbox.show() win.add(vbox) figsize = 4,4 dpi = 72 def draw(widget): gc = widget.window.new_gc() context = widget.create_pango_context() layout = widget.create_pango_layout('Some Text') desc = pango.FontDescription('Times 14') layout.set_font_description(desc) widget.window.draw_layout(gc, x=100, y=200, layout=layout) widget.window.draw_rectangle( gc, 1, 100,100,100,100) def configure_event(widget, event): global pixmap pixmap = gtk.gdk.Pixmap(widget.window, 500, 500) draw(widget) return gtk.TRUE def expose_event(widget, event): draw(widget) return gtk.TRUE da = gtk.DrawingArea() da.connect('configure_event', configure_event) da.connect('expose_event', configure_event) da.set_size_request(figsize[0]*dpi, figsize[1]*dpi) da.show() vbox.pack_start(da, gtk.TRUE, gtk.TRUE) def byebye(button): pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, 0, 8, 500,500) pixbuf.get_from_drawable(pixmap, pixmap.get_colormap(), 0, 0, 0, 0, 500, 500) pixbuf.save('somefile.png', 'png') gtk.mainquit() button = gtk.Button('Quit') button.show() vbox.pack_start(button, gtk.TRUE, gtk.TRUE) button.connect('clicked', byebye) gtk.mainloop() From sysfault at scrpy.org Tue Aug 24 19:37:19 2004 From: sysfault at scrpy.org (Anthony Greene) Date: Tue, 24 Aug 2004 23:37:19 GMT Subject: Book Recommendation Message-ID: I'm new to programming entirely, and I'm simply looking for some insight, can you guys recommend some introductory documentation for me to read, and what I read, and, do concurrently why reading the primary "book" ou guys recommend. Thanks, and any advice is great appreciated. From cjw at sympatico.ca Fri Aug 27 18:37:12 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Fri, 27 Aug 2004 18:37:12 -0400 Subject: Alex Martelli: Welcome back! In-Reply-To: <1gj70sk.1o4cuwepco564N%aleaxit@yahoo.com> References: <1gj70sk.1o4cuwepco564N%aleaxit@yahoo.com> Message-ID: <412FB798.1020300@sympatico.ca> It's great to see you back. Your freely given wisdom and learning have enlightened many. Congratulations on your marriage and best wishes to Anna. I liked your choice of readings. Colin W. Alex Martelli wrote: > Batista, Facundo wrote: > > >>[Dave Benjamin] >> >>#- Asunto: Alex Martelli: Welcome back! >>#- >>#- It's nice to see you around here again! >> >>+1 > > > Heh, thanks. BTW, anybody interested in the readings we choose for our > marriage (me and Anna, who's also going to be my coeditor for the Python > Cookbook Second Edition) can have a look at http://www.aleax.it/mar.html > .... Pythonistas will find one of the poems, ahem, interesting. (Some > photos are at http://bonanna.multiply.com/photos/album/1 , but > mentioning them would be OT, since they're not Python-related;-). > > > Alex From heikowu at ceosg.de Mon Aug 9 12:53:48 2004 From: heikowu at ceosg.de (Heiko Wundram) Date: Mon, 9 Aug 2004 18:53:48 +0200 Subject: Purely emotional perspective In-Reply-To: References: <10hf3oaltbo7o74@corp.supernews.com> Message-ID: <200408091853.48251.heikowu@ceosg.de> Am Montag, 9. August 2004 18:03 schrieb Peter Hansen: > After a while, when everyone is used to decorators, it won't > be important to have them way out front like that, and they > could just as well, and perhaps more readably (at that time), > be moved to after the def. I don't think this is true... Decorators are not simply "meta-data" that is attached to a function, they change the functions behaviour. As such, they create a different function than the one which is declared. Consider: def somedecorator(f): def fdec(*args,**kwargs): return f("somearg",*args,**kwargs) return staticmethod(fdec) With definitions: class x(object): def y(some,arg): @ somedecorator Versus: class x(object): @ somedecorator def y(some,arg): Now, say you folded out the body of x with some form of decent editor. In the first example, @somedecorator disappears, as it is part of the function body, in the second example, it stays in (and I wouldn't want an editor to fold out the decorating statements for a function, and it would be kind'a hard to have a sensible way for the editor to display the first few lines decorating the function inside the function body while the function is folded out). What the catch is: somedecorator does not only change the function "type", as you would consider staticmethod or classmethod do, but also changes the function signature, as the first argument to the function is fixed by the decorator (I actually have use cases for this). Now, it is very important that at first glance you see that the function only takes one parameter (as it is decorated by somedecorator), and this only stands out clearly in the second example (at least for my taste), if you know what somedecorator does, obviously. The docstring of a function actually is only meta-data (in my taste), and thus should remain inside the function definition. When and how decorators do something to the method is unimportant to my taste (they are executed after the function definition has been executed), but visibly seeing that the decorator is being applied to the function is much easier for the second syntax. I won't try to throw in some form of debate about the character used to attribute decorators, but I'm for @, because it stands out much more than | does. Anyway, my 2 cents... Heiko. From a.neudecker at uni-bonn.de Mon Aug 9 11:49:17 2004 From: a.neudecker at uni-bonn.de (Andreas Neudecker) Date: Mon, 09 Aug 2004 17:49:17 +0200 Subject: Find out the file name of a module from inside the module? In-Reply-To: References: Message-ID: <41179CFD.20800@uni-bonn.de> Hi Michael, sorry for making your head spin ;-) I think, Christian's answer is exactly what I was looking for: Just cut out the following code snippets and put them in files called program.py and module.py, respectively. Run program.py and you will see ... ;-) Thanks to both of you, Michael, Christian. Kind regards Andreas program.py: 8<------------------------------------------------------------------------ #!/usr/bin/env python import sys import os # Check if running as program if __name__ == '__main__': print "I was run as a PROGRAM and my path is \n\n\t'%s'\n" % os.path.abspath (sys.argv[0]) print "Now, I will call the module 'module' ..." import module print "Let's see, what 'module' says about itself, calling 'module.whoami()':\n\n" module.whoami() else: print "Hey, I was not run as a program. What's on?" # EOF -------------------------------------------------------------------------# module.py 8<------------------------------------------------------------------------ # Module 'module.py' ----------------------------------------------------------# try: THIS_FILE = __file__ except NameError: print "I guess I was not called as a module. That's strange." def whoami (): print "I was called as a MODULE and my path is \n\n\t'%s'\n" % THIS_FILE # EOF -------------------------------------------------------------------------# Michael Hudson schrieb: > Andreas Neudecker writes: > > >>Hi. >> >>I know you can read the filename of a program as sys.argv[0]. But what >>about modules? Is there a similar way to find out the file name of a >>module (called by some other module or program) from inside this >>module? > > > Uh, your question makes my head spin a bit, but is __file__ what you > want? > > >>>>import os >>>>os.__file__ > > '/usr/lib/python2.2/os.pyc' > > Cheers, > mwh > From greg at invalid.invalid Fri Aug 6 12:30:54 2004 From: greg at invalid.invalid (Greg Krohn) Date: Fri, 06 Aug 2004 16:30:54 GMT Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) In-Reply-To: References: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> Message-ID: <2nOQc.10856$9Y6.9004@newsread1.news.pas.earthlink.net> Anthony Baxter wrote: > The solution, if you don't like the syntax, is not voting. It's to propose an > argument that Guido will accept, in favour of your preferred option. Yes, I suppose so. +1 in favor of Anthony's proposal to come up with a persuasive argument instead of 'voting'. ;) The reason I don't like the proposed @ construct is that the decorators don't seem to be actually part of the function def. They seem to be separate statements before the def. With the list-after-def construct the decorators appear after 'def' and before ':'; clearly part of the function def. I will concede that the @ example someone posted with a long argument list is slightly more readable than the corresponding list-after-def. BUT, I think with a shorter arg list list-after-def is more readable/intuitive. I believe that shorter args lists are more common than long ones. I think the decorator syntax should favor the more common usage. Greg Krohn From me at privacy.net Sun Aug 8 12:01:48 2004 From: me at privacy.net (Dan Sommers) Date: 08 Aug 2004 12:01:48 -0400 Subject: @decorator syntax is sugar, but for what exactly? References: Message-ID: On 8 Aug 2004 13:20:34 GMT, Duncan Booth wrote: > Dan Sommers wrote in > news:m2u0vdj1bn.fsf at unique.fully.qualified.domain.name.yeah.right: >> On Sun, 8 Aug 2004 18:24:58 +1000, >> Anthony Baxter wrote: >> >>> In many cases, these new features actually lead to smaller, simpler >>> code. I challenge _anyone_ to tell me that >>> apply(func, args, kwargs) >>> is better than >>> func(*args, **kwargs) >> >> Okay, I will. The old way is better than the new way. >> >> Explicit is better than implicit, after all. >> >> Given your second example, is func the name of a function or an object >> that references a function? Can I grep my source code to find a >> function named func? (Okay, I'll find the variable named func, so at >> least I'll have some clue as to what's going on.) Is there a "from >> module import func" statement in sight? What happens when I look up >> "func" in the Python documentation to see if it's a built in name? > Why do you ask this about the second form only? func is a name that > references a function in both cases. It doesn't matter whether that > name was assigned directly with a def statement, or is the result of a > subsequent binding. Technically, that is correct. Optimally, I can treat any application of any function like a black box that takes some inputs and returns a value (and possibly changes the inputs or has other (desireable) side effects, but that's another topic entirely). I shouldn't have to care where it is, or who defined it, or how they defined it, or whether it's always the same function throughout the execution of the program, as long as it does what it's supposed to do when I invoke it. Maybe that's my problem. I want to know a little more when I'm looking at code that calls a function. When I see f( x ), I think that f is a function bound by def (or an extremely close relative, such as class or staticmethod), and that I can grep for it somewhere, either in the source code or the library reference. I also think, rightly or wrongly, that f *was* bound, *before* I needed it, and *does not change over time*. When I see apply( f, x ), I think that f varies over time, and is some sort of a callback or plugin or whatever, and is *not* the name of an actual function bound by def. I also accept (and expect) that a different function may be called the next time this particular code executes; those functions have their own names in their own contexts and namespaces. Yes, I know that all functions are free to redefine anything, but functions that do are usually labelled pathological and then blamed for the lack of optimizing python compilers. ObDecorator Question: Does some decorator that specify that a function is not knowingly rebound within its own namespace, such that f( x ) now means the same as f( x ) later, assuming that x is the same? What about at least that f is the same (and need not be looked up again), even if x isn't? This question lurks in the minds of every potential Python optimizing compiler author. If the two forms of function application are truly interchangeable, then why do we have both of them in the first place? >> C did the same thing recently. >> >> Old C: (*f)( argument ); >> >> New C: f( argument ); [snip my reasons for not liking that bit of New C] > For 'recently' read 1987. In fact most C compilers probably > implemented this feature before the ISO standard came out, but it was > a feature of the first standardised version of C. I remember around > that time being extremely glad that I could finally omit those > extraneous parentheses. I must be getting old. :-/ My Second Edition K&R confirms that you are correct on all counts except that bit about you being happy, but I'll take your word for that . It seems more recent than that, or it might be that I spent an awful lot of time in environments (office/political and target system) where the difference remained important for design, documentation, extensibility, performance, resource usage, testing, and/or debugging purposes. Regards, Dan -- Dan Sommers Never play leapfrog with a unicorn. From 510046470588-0001 at t-online.de Tue Aug 17 05:06:08 2004 From: 510046470588-0001 at t-online.de (510046470588-0001 at t-online.de) Date: 17 Aug 2004 11:06:08 +0200 Subject: Python / scheme implement References: <8kcUc.216223$pC2.10693727@phobos.telenet-ops.be> Message-ID: <87brhagmm7.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Daniel Yoo writes: > It's not perfect (and frankly, is a little outdated!), but it's a > proof-of-concept that one language can model the other. how does python model call-with-current-continuation? Klaus Schilling From ajsiegel at optonline.com Sun Aug 8 14:18:43 2004 From: ajsiegel at optonline.com (Arthur) Date: Sun, 08 Aug 2004 18:18:43 GMT Subject: Going the PL/1 way References: Message-ID: On Sun, 8 Aug 2004 16:14:09 +0200, "Mikl?s" wrote: >Decorators, the way things are now, will IMHO actively entice people to >abuse code. Undoubtedly we will begin to see the decorator equivalent of the 3-tier architecture embedded in a list comprehension that one comes across from time to time. Though I find it hard to get too upset about the addition of a feature that accommodates a portion of the community, and that can be safely ignored in writing one's own code if it serves no needs of one's own. And while I guess that could be said of most, if not all new features that have caused controversy, I somehow see this feature more modularized and offset than the others. Perhaps the fact that it is so appraently unPythonic is what modularizes it effectly enough to be considered non-infectious. One hopes. Art From mmccrack at gradlab.ucsd.edu Wed Aug 4 15:25:47 2004 From: mmccrack at gradlab.ucsd.edu (Michael McCracken) Date: 04 Aug 2004 12:25:47 -0700 Subject: help: Unit test fixture returning the same object References: <9895e897.0408031533.26720ba0@posting.google.com> <9895e897.0408040851.21ac7caa@posting.google.com> Message-ID: Roy Smith writes: > michael_mccracken at mac.com (Michael McCracken) wrote: > > So, I'm still surprised that id() would point to the same object every > > time, but I'm willing to believe it. However, I don't think that's the > > only thing that's going on - the reason I noticed this in the first > > place is that the setUp method was opening a file and populating some > > lists in my File object, and those lists were accumulating objects > > between test methods. > > My first guess would be that you're using class variables instead of > instance variables, but you say: > > > I don't think I'm accidentally using class variables > > so I'm stumped. Can you post your code? I managed to fix my problem, but I don't understand why the fix works yet, so I'm not quite satisfied. I am trying to narrow it down so I can post more informatively. So far my attempts at making a minimal example don't exhibit the same problem. While I'm trying to get the smallest example with the problem, I will describe what happened and how I 'fixed' it. The File id() was indeed a red herring. The problem was that in __init__, File reads a bunch of stuff (in XML using libxml2) and populates some internal lists. The one that had the problem was a list of Modules, which has a list of Procedures which has a list of Blocks. Each Block has predecessors and successors. Block looks like this: class Block: def __init__(self, name, preds = [], succs = []): self.name = name self.predecessors = preds self.successors = succs self.metrics = [] for pred in self.predecessors: pred.addSuccessor(self) for succ in self.successors: succ.addPredecessor(self) # add* just append to the lists, avoiding cycles. def __repr__(self): s = "{%d -> %s (0x%d) -> %d (%d)}" %\ (len(self.predecessors), self.name,\ id(self), len(self.successors), len(self.metrics)) return s In File, Blocks are created in a method that gets called as we're parsing out the Procedures and Modules. I make a new Block with empty preds and succs initially, then link them up after they're all created: in File.py: def blockForXMLNode(self, n): name = safeGetAttribute(n, "label", xlinkNSURI) # this is called during the first pass, can't link up yet preds = [] succs = [] block = Block.Block(name)# preds, succs) print 'DEBUG: Making new block: ', block The problem: if I run it as is, I get this output: (During the first testCase:) DEBUG: Making new block: {0 -> no_exit.1 (0x2714520) -> 0 (0)} DEBUG: Making new block: {0 -> loopexit.1 (0x2714840) -> 0 (0)} DEBUG: Making new block: {0 -> loopexit.0 (0x2715000) -> 0 (0)} (During the next testCase:) DEBUG: Making new block: {3 -> no_exit.1 (0x2735080) -> 5 (0)} DEBUG: Making new block: {4 -> loopexit.1 (0x2735400) -> 6 (0)} DEBUG: Making new block: {5 -> loopexit.0 (0x2735560) -> 7 (0)} (and so on...) So it does look like a class variable vs. instance variable problem, but I can't say why. The fix is to uncomment the "# preds, succs)" and pass in those empty lists to the Block constructor. That gives the expected results, but I can't explain the difference. -mike -- From __peter__ at web.de Tue Aug 10 08:15:18 2004 From: __peter__ at web.de (Peter Otten) Date: Tue, 10 Aug 2004 14:15:18 +0200 Subject: decorators, function signature, and help() Message-ID: After a week or so I'm finally getting accustomed to the pie-pre-def syntax. Consider a simple-minded decorator that doesn't care about the signature of the function it wraps: >>> def noisy(f): ... def g(*args, **kw): ... print f.__name__ ... return f(*args, **kw) ... return g ... >>> @noisy ... def naught(): ... "does nothing" ... >>> naught() naught Now help() is less than helpful: >>> help(naught) Help on function g: g(*args, **kw) While the docstring can easily be copied and might even be prefixed g.__doc__ = "@noisy\n" + f.__doc__ the name currently can not. I do not see a way to preserve the signature either. It seems that when decoration is a built-in feature that even has syntax support it should play nice in these cases by default. Any ideas? Could there be a smooth way to quote an argument list, e. g: def f(a, b, c): pass def g(/*same args as f*/): pass Peter From rnichol_rrc at yahoo.com Fri Aug 20 18:35:36 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Fri, 20 Aug 2004 17:35:36 -0500 Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: Peter Hansen wrote: > Tim Hochberg wrote: > >> Reid Nichol wrote: >> >>> Gerrit Muller wrote: >>> >>>> and then a quantum leap towards Python. >>> >>> You're aware that a quantum leap means a extremely small leap, right? >> >> >> While quanta are typically very-very-very small, last I checked the >> key feature of quantum transitions is not that they're small, but that >> there are no intermediate steps. The object is in state A then it's in >> state B, but it's never halfway (or anywhere) between. Like most >> quantum stuff it's better not to think about that too closely. > > > And at least some dictionaries give it as a synonym for "large" > or "significant". (www.m-w.com for one) > > -Peter Such things are only the result of a misunderstanding of the word some time ago. Even though it is wrong, it has become common use, thus the incorrect definition definition(s). From simoninusa2001 at yahoo.co.uk Sun Aug 22 22:44:25 2004 From: simoninusa2001 at yahoo.co.uk (Simon John) Date: 22 Aug 2004 19:44:25 -0700 Subject: Having problems installing wxPython Message-ID: I've just installed the binary RPM on my RH9 box, it went fine, did you try the binary before the source? I noticed that SUSE's YAST2 doesn't have anything newer than 2.5.1.5 From rupole at hotmail.com Wed Aug 4 02:22:13 2004 From: rupole at hotmail.com (Roger Upole) Date: Wed, 4 Aug 2004 02:22:13 -0400 Subject: Can somebody help me ? References: <9f6a3388.0408031923.11cfa62d@posting.google.com> Message-ID: <41107ae3$1_4@127.0.0.1> You should be able to get at the data with something like this: cdb=db1.CurrentDb() rs=cdb.OpenRecordset('yourtablename') while not rs.EOF: print rs.Fields(0) rs.MoveNext() hth Roger "Patrick" wrote in message news:9f6a3388.0408031923.11cfa62d at posting.google.com... > Hi, > > I managed to open a msaccess database with python. > > import win32com.client.dynamic > db1 = win32com.client.dynamic.Dispatch("Access.Application") > dbname = "D:\\Project\\Database\\database.mdb" > db1.OpenCurrentDatabase(dbname) > > Now, I have the problem, that I don't know how I can read the lines > of my table. Can somebody help me please and give me an example code ? > > I'm looking forward to your answers, and thank u very much in advance. > > Cheers > > Patrick From heikowu at ceosg.de Wed Aug 11 23:13:36 2004 From: heikowu at ceosg.de (Heiko Wundram) Date: Thu, 12 Aug 2004 05:13:36 +0200 Subject: Arranging a dependency tree In-Reply-To: <6ccff37a.0408111831.6eb25a4e@posting.google.com> References: <6ccff37a.0408111831.6eb25a4e@posting.google.com> Message-ID: <200408120513.36921.heikowu@ceosg.de> Basically, dependencies (should) create a tree structure, except when you have circular dependencies. Now, what you have to do to resolve the tree structure in case there are no circular dependencies is to walk the edges of the graph, from leaf to top. Example graph: x | ----> y | ----> z | ----> a | | ----> b | ----> a Now, you need a way to store this in Python, I'd use dictionaries: deps = {"x": {"y":{}, "z":{"a":{}} }} Reading the data into a format like this is pretty simple too: def makeTree(files): """Pass in a list of files for which dependency info should be generated.""" deps = {} cur_files = [(fname,deps) for fname in files] all_deps = {} while cur_files: cur_file, cur_deps = cur_files.pop() if cur_file in all_deps: cur_deps[cur_file] = all_deps[cur_file] continue new_deps = {} # getDeps returns the dependencies needed by cur_file. for dep in getDeps(cur_file): cur_files.append((dep,new_deps)) cur_deps[cur_file] = new_deps all_deps[cur_file] = new_deps return deps Now, reading in the dependency list as done above properly takes care of circular dependencies, and might create dictionaries which contain themselves at some depth. It won't read dependency info more than once for a given file, too. The following code will walk the tree generated by makeTree, but it will barf on circular dependencies. You'll have to devise some means to deal with these, the most common form being simply to break tree walking at the current level in case you encounter a circular dependency. The algorithm is recursive. Doing it iteratively would be possible too, but at quite some cost. def _walkTree(tree,cur_files,walked_files): for cur_file, cur_deps in tree.iteritems(): if cur_file in walked_files: continue elif cur_file in cur_files: # Deal with circular deps here. You might just do: # raise StopIteration raise ValueError, "Circular tree structure." if cur_deps: for sub_file in _walkTree(cur_deps,cur_files+(cur_file,),walked_files): yield sub_file walked_files.append(cur_file) yield cur_file def walkTree(tree): """Walk a tree as generated by makeTree.""" for f in _walkTree(tree,(),[]): yield f Well, hope this helps and gives you some hints! Heiko. From PPNTWIMBXFFC at spammotel.com Wed Aug 11 02:06:33 2004 From: PPNTWIMBXFFC at spammotel.com (Marco Aschwanden) Date: Wed, 11 Aug 2004 08:06:33 +0200 Subject: Yet another decorator proposal Message-ID: Here is yet another decorator proposal: def sumSequencesLengths(var1, var2): """Computes something very important. __decorators__: staticmethod __parameters__: var1=Sequences var2=Sequences __returns__: int """ result = len(var1) + len(var2) return result Reasoning: Decorators are important to communicate to the programmer. So, if someone wants to use decorators she better writes a documentation for it. So why not let the documentation enforce the whole decoration system? The main advantages: - Keeps the documentation up-to-date! The first language to do so (- doesn't it?) - Enforces Python's readability further. - Needs no new language constructs. The main disadvantages: - The values are frozen... the __decorators__ are set in a static string - The definition follows after the def - A "static" description has an impact on the "acting" program There are really more pros and cons... it might be also only a "Schnapsidee" - after all I am no language designer. Have a nice day, Marco From justin__devine at hotmail.com Mon Aug 30 17:58:42 2004 From: justin__devine at hotmail.com (Justin) Date: 30 Aug 2004 14:58:42 -0700 Subject: "Content-Length" header In-Reply-To: <4p6dnegTwNnsA67cRVn-tg@powergate.ca> Message-ID: I found the answer. After about 3 hours of agonizing over it it turned out to be CASE some webservers are CASE SENSITVE about their urls and some are not. unfortunately in order to standardize another part of my program I was converting all the urls to .lower() un-believeable Thanks for your help -Justin From greg at cosc.canterbury.ac.nz Wed Aug 25 23:05:14 2004 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Thu, 26 Aug 2004 15:05:14 +1200 Subject: esoteric question about dict keys In-Reply-To: References: Message-ID: <2p52bcFgrnkbU1@uni-berlin.de> > In article , > Alexis Roda wrote: > >> If I write my own dictionary-like >> object, on wich the mutability of the keys is not a technical issue, is >> considered blasphemous the use of dicts as keys? No, not at all. If the algorithm you use for looking up your mapping doesn't have any problem with mutability, then using a dict (or indeed any comparable object) as a key is fine. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From scott.b.drummonds.nospam at intel.com Thu Aug 12 13:31:43 2004 From: scott.b.drummonds.nospam at intel.com (Scott Brady Drummonds) Date: Thu, 12 Aug 2004 10:31:43 -0700 Subject: 'break' Causes Execution of Procedure? References: <871xidqm2e.fsf@pobox.com> Message-ID: "John J. Lee" wrote in message news:871xidqm2e.fsf at pobox.com... > "Scott Brady Drummonds" writes: > [...] > > DEBUG: advancing both simulators to 20178 > [...] > > Is this a threaded program? Nope. Scott -- Remove .nospam from my e-mail address to mail me. From rnichol_rrc at yahoo.com Mon Aug 16 22:50:16 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Mon, 16 Aug 2004 21:50:16 -0500 Subject: Python secure? In-Reply-To: References: <2xXTc.3775$bJ2.24876@news1.mts.net> Message-ID: <4neUc.3991$bJ2.26560@news1.mts.net> Peter Hansen wrote: > "unsecure language": a programming language which, by virtue > of its structure, primitive libraries, awkward syntax, non- > existent runtime, or other limitations tends to encourage > and lead to the creation of software with gross security > holes". Viz. "C" > > A given programmer will be more likely to create safe and > secure software using Python than with C, thereby making > C the less secure... > > -Peter Quite frankly I find C a perfectly viable language to write secure code. It's only failing is that people don't understand how to use it before they type (which isn't exactly a failing of the language itself, but of the person using it). A perfect example of this is pointers. If people wouldn't rush, if they took there time to learn what's actually going on, they wouldn't make those mistakes. I have avoided many a bug just by thinking about it for just a few minutes more, than typing the first thing (or second or third) that popped in my head. It has made me slower than other programmers in the beginning of projects, but in the end I am as or more efficient than the others. One cannot judge a language by it's ability to allow sloppyness. In fact the structure of my code (ie indentation) didn't change one bit from C to when I learned Python. Quite frankly, I've seen some crap Python code. It's the programmer NOT the language. I hope others see your clear bias towards Python as I have (One need only to look at your descriptions to see it.). Remember, there is no one language that everything is good for. Python, C, C++, Lisp, etc all have things that it is best to program in them. It all depends on the projects requirements. From Jeffrey at Fro.man Fri Aug 20 01:03:59 2004 From: Jeffrey at Fro.man (Jeffrey Froman) Date: Thu, 19 Aug 2004 22:03:59 -0700 Subject: Rita Sue and Bob too References: Message-ID: Jeffrey Froman wrote: > How about a generator? Sorry, bad paste on my previous reply. The generator example should look like: def replace_in_list(apple, worm, new_worm): while apple: if worm == apple[:len(worm)]: apple = apple[len(worm):] for w in new_worm: yield w else: yield apple.pop(0) From michaels at rd.bbc.co.uk Fri Aug 20 06:19:45 2004 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Fri, 20 Aug 2004 11:19:45 +0100 Subject: Alternative decorator syntax decision References: Message-ID: Paul McGuire wrote: ... > I would propose a multivote survey: each poster gets 3 votes among the > lettered choices on the Wiki page above. You can use all 3 for a > single option, or split them across 2 or 3 options if you are open to > more than one. My vote is: J2 J2 C1 Michael. -- Michael.Sparks at rd.bbc.co.uk British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From ajsiegel at optonline.com Sat Aug 21 11:29:47 2004 From: ajsiegel at optonline.com (Arthur) Date: Sat, 21 Aug 2004 15:29:47 GMT Subject: Alternative decorator syntax decision References: Message-ID: On 20 Aug 2004 12:07:22 -0700, google at daishi.fastmail.fm (daishi) wrote: >C1 C1 C1 > >If we are allowed to make negative votes: > >-J2 -J2 -J2 > >I personally find J2 worse than the current pie >syntax. Something that looks odd and does something >odd seems the lesser evil vs something that looks >normal yet does something odd. > A1 A1 A1 On a similar line of thinking - if we do indeed need some syntax. And the vote seems to assume we do, or at least accepts Anthony as speaking with some authority (I hope he hasn't overstepped) by declaring that not having some syntax in 2.4 is not an option. And finding @before def is in-your-face odd. Nobody would confuse it with real Python ;) Art From rpw3 at rpw3.org Sun Aug 29 00:14:55 2004 From: rpw3 at rpw3.org (Rob Warnock) Date: Sat, 28 Aug 2004 23:14:55 -0500 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <412e199e$0$8076$a1866201@newsreader.visi.com> <4130654c$0$19703$61fed72c@news.rcn.com> Message-ID: +--------------- | jdoherty at nowhere.null.not (John Doherty) wrote: | >AND HOW MANY SPACES PER TAB STOP? | | Eight. Now talk about indenting skip returns...that one | required blood transfusions. [emoticon looks at list of n.g.] | I guess not many will understand. +--------------- You might be surprised, Barb. Quite a few of the comp.lang.lisp crew are former PDP-10 geeks. ;-} And just to be sure *I'm* understanding what you're talking about, ;-} did you mean the convention of the second line of the following snippet? foo: pushj p,ckperm pjrst badprm ; user lacks privs, complain & return. movei t0,cmdblk ; o.k. to proceed. ... Indenting the non-skip return for a subroutine call was always pretty clear to me. Where things got really muddled (and contentious!) was when you had long skip chains of T{R,L}{Z,O,C,~}{N,E} instructions in which whether a particular instruction was in the skipped-to or non-skipped position depended dynamically on the flow of control above it. [HAKMEM was chock-full of that kind of "efficient" code.] In that case, it seemed more readable to simply not indent anything in the skip chain, and put a scary comment warning about the tricky code. -Rob ----- Rob Warnock 627 26th Avenue San Mateo, CA 94403 (650)572-2607 From porky_pig_jr at my-deja.com Tue Aug 24 02:47:12 2004 From: porky_pig_jr at my-deja.com (Porky Pig Jr) Date: 23 Aug 2004 23:47:12 -0700 Subject: How does a "script" differ from a "program" or "subroutine"? References: Message-ID: <56cfb0e3.0408232247.2df68078@posting.google.com> Phil Frost wrote in message news:... > A script is just a program, but has the implication that it's a simple > program for a simple task. > I think the major implication is not that it's simple but it's written in some 'interpreted' (rather than compiled) language. so we say Python or Perl or Bash script, but not 'C script'. Look at the job openings: you'll often see something like this: 'knowledge of scripting languages (such as Perl and/or Python)'. From esj at harvee.org Thu Aug 26 20:30:45 2004 From: esj at harvee.org (Eric S. Johansson) Date: Thu, 26 Aug 2004 20:30:45 -0400 Subject: file based queues Message-ID: seems to me this would be a fairly obvious component to be part of the Python repertoire but I haven't found any yet. I want to store objects persistently and have the underlying object behavior be that of a queue. usually, this is implemented as a series of files within a directory or directory hierarchy but I'm not fussy. Just as long as it doesn't have much overhead like mysql or twisted. any suggestions? --- eric From specmark at aol.com Wed Aug 11 16:38:46 2004 From: specmark at aol.com (expecthealth) Date: Wed, 11 Aug 2004 20:38:46 -0000 Subject: CSV Specialists -- NEW JERSEY - WORK Day or Night ............ Message-ID: Job responsibilities: Execution of protocols only. No writing on this project. Requirements: Previous company experience (we are aware that not everyone has previous company experience, but are trying to group them with some Sr. Consultants we have that do) Execution of CSV protocols and Knowledge or exposure to calibration systems...will be trained further.Bill rate will vary based on experience and company experience: $32-37/hr,all inclusive .Shifts will be 9 hour shifts having a one hour overlap to hand over work to the next team:12am- 9am, 8am-4pm, 3pm-12am (please let me know preference...but if they are flexible that would be great)Location: Kenilworth, NJ Start Date: the week of August 16th, probably a couple of weeks work. There will be a couple of downtimes and the Consultants will be offered additional work to do or to take the time off. Thanks, Bill NorrisDIAMOND CONSULTING INC.630-586-0000 x19specmark at aol.com From me at privacy.net Thu Aug 19 11:09:50 2004 From: me at privacy.net (Richard Hanson) Date: Thu, 19 Aug 2004 08:09:50 -0700 Subject: age of Python programmers References: Message-ID: Peter Hansen wrote: >Lucas Raab wrote: >> One thing I've always kind of wondered is what is the average age of a >> Python programmer?? > >My average age has been increasing steadily for years. :-( :-) (And ditto on the ':-('.) While I agree with Peter -- and particularly, his ending emoticon on *all* levels, I have to ask: -- Was the OP asking about my age in *human* years... -- or *Richard* years? (One Richard year approximately equals *two* human years...) ;-) over-a-century-in-"Richard"-years'ly y'rs, Richard -- R Hanson [The mangled email addie below works.] sickolefartnewsguycom From erica55 at bol.com.br Mon Aug 16 00:20:42 2004 From: erica55 at bol.com.br (Erica Silveira) Date: Mon, 16 Aug 2004 01:20:42 -0300 Subject: listagem de e-mails Message-ID: <20040816042025.065BA1E4007@bag.python.org> Mais Emails, venda online de listas de email, fazemos mala direta e propaganda de sua empresa ou neg?cio para milh?es de emails. Temos listas de email Mala Direta, Mala-Direta, Cadastro de Emails, Lista de Emails, Mailing List, Milh?es de Emails, Programas de Envio de Email, Email Bombers, Extratores de Email, Listas Segmentadas de Email, Emails Segmentados, Emails em Massa, E-mails http://www.promonet.mx.gs Temos listas de email Mala Direta, Mala-Direta, Cadastro de Emails, Lista de Emails, Mailing List, Milh?es de Emails, Programas de Envio de Email, Email Bombers, Extratores de Email, Listas Segmentadas de Email, Emails Segmentados, Emails em Massa, E-mails http://www.promonet.mx.gs From http Thu Aug 26 13:09:35 2004 From: http (Paul Rubin) Date: 26 Aug 2004 10:09:35 -0700 Subject: Call for signatories for J2 References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> Message-ID: <7xhdqp967k.fsf@ruckus.brouhaha.com> Michael Sparks writes: > It might (or might not) be too late but just as a check I checked > to see if "per" is used by any projects listed in the proposal. (I > was checking Twisted and Zope for "using" so decided to do "per" as well) I'm still not crazy about J2 but I like "per" much better than "using". I'm afraid that the clpy proposals, and the @pie syntax, both seem to me like "extreme programming", i.e. an approach of "if you see a reasonable looking approach to a problem, implement it without worrying too much, and re-do ('refactor') it afterwards if it turns out not to be the right thing. But for new language syntax, whatever gets implemented, we are going to be stuck with. There will be no refactoring possible. It's imperative to get it right the first time. The Scheme community understood this idea and was extremely careful about adding new features to Scheme even when it was clear that the features were needed. I think Scheme benefited as a result. From richardjones at optushome.com.au Tue Aug 3 06:49:41 2004 From: richardjones at optushome.com.au (richard) Date: Tue, 03 Aug 2004 20:49:41 +1000 Subject: advice for perl expert wanting to learn python References: Message-ID: <410f6dcb$0$16887$afc38c87@news.optusnet.com.au> Zeljko Vrba wrote: > What's the easiest way of learning python knowing perl? Is there somewhere > a 'how-to' cookbook with parallel examples of frequent idioms in perl and > python? A good start might be: http://www.python.org/doc/Intros.html under the "Introductions for programmers" heading. Then there's http://www.python.org/doc/Comparisons.html#perl which has direct comparisons. > And most important thing, how does Python deal with database connectivity? > Is there a single API (akin to DBI) for connecting to databases? There is a DB-API standard, which is implemented by the various connectors. > How does Python support the following databases: > - Oracle > - Postgres > - MySQL > - SQLServer (maybe using freetds?) > - ODBC connectivity (connecting to MS Access) Well. Richard From pm_mon at yahoo.com Wed Aug 18 08:35:21 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Wed, 18 Aug 2004 08:35:21 -0400 Subject: PEP 318: Can't we all just get along? In-Reply-To: References: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: Dan Sommers wrote: > On Tue, 17 Aug 2004 21:13:47 -0400, > Paul Morrow wrote: > > >>First though, I still believe that we should exploit existing >>conventions (recommended coding practices) as a way of getting 'free' >>declarations for class, static, and instance methods (e.g. methods >>whose first param is 'self' are instance methods, etc.). That feels >>very pythonic to me, just as we use naming conventions to distinguish >>public, private, and semi-private methods. > > > I don't understand how assigning semantic significance to a "recommended > coding practice" is Pythonic. > > In the face of ambiguity, refuse to guess. > > Explicit is better than implicit. > Good conventions prevent ambiguity. class Foo: def method1(self, a, b): pass # clearly an instance method def method2(cls, a, b): pass # clearly a class method def method3(a, b): pass # clearly a static method When declarations conflict with conventions, it makes us wonder what the author really intended. def staticmethod setX(self, x): self.x = x > > I think that the idea that started this thread is just right: > You're right, this thread is about decorators, not about more opportunities for dynamic typing. I just wanted to remind us that decorators are a lot like static typing, which isn't terribly pythonic. From peter at engcorp.com Tue Aug 17 07:30:38 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 17 Aug 2004 07:30:38 -0400 Subject: serial and threads In-Reply-To: <39ba6e78.0408170215.3368be4e@posting.google.com> References: <39ba6e78.0408170215.3368be4e@posting.google.com> Message-ID: <6KSdnRe269vCcbzcRVn-rg@powergate.ca> Silke wrote: > I'm trying to write a program in python using the modules > 'serialwin32' and 'thread' to create one thread that writes to a > serial port and another one that reads from it at 'the same time'. My > definitions are > > def NetworkToSerial(input): > s.write(binascii.unhexlify(input)) > print "SENT: %s" % input > > def SerialToNetwork(): > result = s.read(1) > print "RECEIVED:" > print binascii.hexlify(result) > > and I call them with > > thread.start_new_thread(NetworkToSerial, (command,)) > thread.start_new_thread(SerialToNetwork, ()) > > The first one seems to run fine, but for the second one I get the > error message 'ClearCommError', 'the handle is invalid'. How do you open the serial port and pass the "handle" to the two threads? Or are you just using a global "s"? From nospam at mega-nerd.com Fri Aug 13 05:41:45 2004 From: nospam at mega-nerd.com (Erik de Castro Lopo) Date: Fri, 13 Aug 2004 19:41:45 +1000 Subject: Why I love python. References: Message-ID: <411C8CD9.32F39C2@mega-nerd.com> Nick Patavalis wrote: > > Python needs drastic performance improvement if it is to scrap-off the > "scripting language" stigma. The only way to get these improvements is > making it possible for a python implementation to produce *efficient* > *compiled* code. At the same time the dynamic-typing nature of the > language is one of its most valuable characteristics. And this is one > of the hardest problems when trying to write a decent python > compiler. If you define a function like: > > def sum (a, b): > return a + b > > How can the compiler know what code to produce? I know of at least one language which has solved this problem, Ocaml http://www.ocaml.org/ Its called type inferencing and since there is at least one working implementation, it can't be THAT hard. Erik -- +-----------------------------------------------------------+ Erik de Castro Lopo nospam at mega-nerd.com (Yes it's valid) +-----------------------------------------------------------+ Never argue with stupid people. They'll just drag you down to their level and beat you with experience From kjetilho at yksi.ifi.uio.no Mon Aug 30 20:10:13 2004 From: kjetilho at yksi.ifi.uio.no (Kjetil Torgrim Homme) Date: Tue, 31 Aug 2004 02:10:13 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1ry8k0d2az.fsf@rovereto.ifi.uio.no> <10iv0kid2ig9ka6@corp.supernews.com> <1rpt5ccbso.fsf@rovereto.ifi.uio.no> <10ivpk9inpnh65@corp.supernews.com> <1rd61bd26k.fsf@rovereto.ifi.uio.no> <1gj892g.1hlc8ar1po78b6N%aleaxit@yahoo.com> Message-ID: <1rwtzg9nh6.fsf@rovereto.ifi.uio.no> [Alex Martelli]: > > [good stuff] I just wanted to thank you for your input, I'll try to mention some of these ideas in the text of the PEP. -- Kjetil T. From borkent at cs.utwente.nl Thu Aug 26 07:35:38 2004 From: borkent at cs.utwente.nl (Michiel Borkent) Date: Thu, 26 Aug 2004 13:35:38 +0200 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: Jes, mi komprenis. Dankon por la inspiro: mi jxus kreis novan subskribajxon. Amike, Michiel -- LISP and Esperanto: my favorite languages. Visit http://www.pictureofthemoon.net/~borkent for my webpage. --- "Peter Hansen" wrote in message news:Nbudnes8cfDjWLDcRVn-sA at powergate.ca... > Michiel Borkent wrote: > > > "Peter Hansen" wrote: > >>No, it's Esperanto (universal language) for "troll"... > > > Erm, please don't make false propaganda for the language I happen to love > > ;). > > > > Btw: > > > > (english-to-esperanto "troll") ==> "trolo" > > Pardonu... estis sxerco, evidente! > > -Peter From indigo at bitglue.com Tue Aug 17 18:26:28 2004 From: indigo at bitglue.com (Phil Frost) Date: Tue, 17 Aug 2004 18:26:28 -0400 Subject: favorite python web development tool? In-Reply-To: <10i4nttktcvltdd@corp.supernews.com> References: <10i4nttktcvltdd@corp.supernews.com> Message-ID: <20040817222628.GB13426@unununium.org> I use Twisted + Nevow. twistedmatrix.com, divmod.org, nevow.com On Tue, Aug 17, 2004 at 03:43:22PM -0400, mike wrote: > hi all - > > > i'm fairly new to python, coming from a java servlet / velocity template > background. i'm looking for a good python web development tool, and > hope to find some suggestions here. > > given my background, webware+cheetah feels comfortingly familiar, and > i'm leaning toward it. before i dive in, though, i'm wondering what you > experienced users think about it, compared to the other tools that are > out there. eg, does the python environment have strengths that are > better exploited with something other than a servlet-like model? > > > thanks for your thoughts! From fumanchu at amor.org Mon Aug 30 11:13:52 2004 From: fumanchu at amor.org (Robert Brewer) Date: Mon, 30 Aug 2004 08:13:52 -0700 Subject: why does this fail on python 2.2? Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E96@exchange.hqamor.amorhq.net> John Hunter wrote: > class Results(object): > __slots__ = ( "__doinit" ) > def __new__(cls): > retobj = object.__new__(cls) > retobj.__doinit = True > return retobj Not sure why that fails, but I am wondering why you chose: retobj = object.__new__(cls) over: retobj = cls() Perhaps you're "digging too deep" on the supercall. Robert Brewer MIS Amor Ministries fumanchu at amor.org From ialbert at mailblocks.com Fri Aug 20 10:12:50 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Fri, 20 Aug 2004 10:12:50 -0400 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: <1IqdnUhRpch8m7vcRVn-vQ@giganews.com> David Fraser wrote: > Thats because the point of this vote is to try and gather a consensus > about what the best alternative is, But what if the alternative is that you don't need a best alternative? There lies the crux of the problem. > not to try and out-vote the original contender. If you cannot out-vote the original contender than what is the whole point of the poll? Why would this proposal be accepted if it cannot outclass the original one? Voting is an extremely tricky business. Arrow's theorem proves that there is not voting scheme that could provide a proper selection whenever there are more than two candidates (in the two candidate case the scheme is simple majority). Yet there are better and there are worse ways to reduce the field to two candidates. What this poll attempts to do (going only after the second place) is incorrect. It is bad not just from the inherent unreliability of internet polling but from design perspective. Istvan. From elciof at gmail.com Mon Aug 16 12:22:39 2004 From: elciof at gmail.com (Elcio Ferreira) Date: Mon, 16 Aug 2004 13:22:39 -0300 Subject: Newbie question about file input In-Reply-To: References: Message-ID: <75fc9ad504081609226eca03f@mail.gmail.com> > while 1: > line = zf.readline() > if not line: > break Newbie's question: Isn't it a strange way to do a loop? Create a loop with a foo condition and use an if to break it? ===== line=zf.readline() while line: . . . line=zf.readline() ===== Isn't this code much more easy to understand? -- -- Um [ ]! Elcio http://elcio.locaweb.com.br/ http://www.tableless.com.br/ http://www.atipico.com.br/ From follower at gmail.com Tue Aug 10 10:01:22 2004 From: follower at gmail.com (Follower) Date: 10 Aug 2004 07:01:22 -0700 Subject: [ANN] libgmail 0.0.1 -- Gmail access via Python References: <3c18c08f.0407011159.9243ee1@posting.google.com> <6491b0ab.0407241411.2fa426b3@posting.google.com> Message-ID: <3c18c08f.0408100601.2f45aa5a@posting.google.com> Hi Fazer, Thanks for your feedback. faizans at gmail.com (Fazer) wrote in message news:<6491b0ab.0407241411.2fa426b3 at posting.google.com>... > [Snip] > Is it possible to delete an email using this library? I hope you don't mind me delaying the answer to this question until I could answer in the affirmative. (Rather than promising vapourware... :-) ) I have just committed code into CVS to enable message and thread trashing functionality. (It will appear in the 0.0.8 release.) The new `GmailAccount` methods `trashMessage` and `trashThread` will move a message or thread into the trash. I intend to add functionality to permanently delete items & mark items as spam in the future, but it's not there yet. Hope this is useful. --Phil. From Sibylle.Koczian at Bibliothek.Uni-Augsburg.de Thu Aug 26 04:21:53 2004 From: Sibylle.Koczian at Bibliothek.Uni-Augsburg.de (Sibylle Koczian) Date: Thu, 26 Aug 2004 10:21:53 +0200 Subject: Idle problem In-Reply-To: References: <6haXc.183583$8_6.163380@attbi_s04> Message-ID: <2p5kt1Fgka4tU1@uni-berlin.de> Ian J Cottee schrieb: > Brent W. Hughes wrote: > >> Sometimes when I try to start up idle.py (by double-clicking on the >> icon), I >> get the message: >> Python subprocess socket error: Connection refused, retrying.... >> It repeats the message a couple of times and then prints: >> Connection to Idle failed, exiting. >> >> Any idea what's going on? > > > http://aspn.activestate.com/ASPN/Mail/Message/python-dev/1748187 > > Doesn't offer any conclusions but might point you in the right direction. > Seems to suggest two possibilities: the firewall issue mentioned in Ben McGinnes' answer or else no sockets - if a machine is not part of any local network and has no network software at all installed. If I understand that thread correctly that might even be the case if it's connected to the internet by modem and dial-up access. I'd think a "ping localhost" should show this. Koczian -- Dr. Sibylle Koczian Universitaetsbibliothek, Abt. Naturwiss. D-86135 Augsburg Tel.: (0821) 598-2400, Fax : (0821) 598-2410 e-mail : Sibylle.Koczian at Bibliothek.Uni-Augsburg.DE From peter at engcorp.com Mon Aug 23 13:09:24 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 23 Aug 2004 13:09:24 -0400 Subject: J2 proposal: keyword In-Reply-To: <2ouldeFf0ujnU2@uni-berlin.de> References: <2ouldeFf0ujnU2@uni-berlin.de> Message-ID: Oliver Fromme wrote: > Aren't decorators just functions that are applied to the > function definition? Then how about "apply"? It's short > (for those lazy typers), and it expresses exactly what > happens. Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32 >>> apply I'm fairly sure that fact alone would cause a lot of grief in one way or the other. -Peter From BruceWhoHKL at gawab.com Wed Aug 18 23:02:23 2004 From: BruceWhoHKL at gawab.com (BruceKL WhoH) Date: Thu, 19 Aug 2004 11:02:23 +0800 Subject: metaclass ??? Message-ID: <20040819030134.ACD6D1E4005@bag.python.org> Mike C. Fletcher: Now I know that we can use metaclass to add method for class,not instance. Maybe I never need to use metaclass. Perhaps I'll understand it when I'm really need something like this. Thanks for your help. ======= 2004-08-19 10:36:17 Mike C. Fletcher wrote: ======= >BruceKL WhoH wrote: >... > >> What I'm trying to do is : >> I want to make two class, they are just subtly different,for example >> >> >... > >>all other codes are identical,just f is different. >> So can I use meta-class here? Or I should do this by another way? >> >> >If this is the entire specification of what you need to do, it really >seems as though you'd be better off with mix-in classes. Your code would >then look like this: > >class Base: >"""Base class providing common functionality""" ># your shared code here > >class A( Base ): >"""Overrides method f only""" >def f(self): >print 'a' > >class B( Base ): >"""Overrides method f only""" >def f(self): >print 'b' > >The first page of the presentation is intended to warn you that, in >general, most programmers never need to use metaclasses, even after >years of work in the language. The use cases for them are fairly exotic, >not the kind of thing you find in "normal" programming operations. > >There are cases where you might want to use metaclasses to inject a >method into a class (as covered in the presentation), but those >use-cases tend to be more involved than simply wanting to have 1 method >change. Those cases are normally going to involve making a *decision* at >run-time as to which method implementation to include, for instance >based on the presence/absence of other methods or a data-attribute of >the class. > >> BTW,your pdf is quite nice,how do you make it? Beamer,pdfscreen, or PPT ? >> >> >OpenOffice.org Presenter (PowerPoint-like app) has a built-in export to PDF. > >Have fun, >Mike > >________________________________________________ > Mike C. Fletcher > Designer, VR Plumber, Coder > http://www.vrplumber.com > http://blog.vrplumber.com > >-- >http://mail.python.org/mailman/listinfo/python-list >. = = = = = = = = = = = = = = = = = = = = ????????BruceKL WhoH ????????BruceWhoHKL at gawab.com ??????????2004-08-19 From bik.mido at tiscalinet.it Mon Aug 30 02:19:18 2004 From: bik.mido at tiscalinet.it (Michele Dondi) Date: Mon, 30 Aug 2004 08:19:18 +0200 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <2a56f6a3.0408252257.4f1f92e@posting.google.com> <2p5j10FesankU1@uni-berlin.de> Message-ID: On Thu, 26 Aug 2004 09:49:48 +0200, "Tassilo v. Parseval" wrote: >> I bet Larry Wall's life insurance premiums just skyrocketed. > >It would, if anyone could take Xah Lee Loo seriously. But really, no one >can. He's more like the court jester, creeping out of the dark every so >and so months. We're all very much enjoying his sporadic shows. Really. Really! Michele -- you'll see that it shouldn't be so. AND, the writting as usuall is fantastic incompetent. To illustrate, i quote: - Xah Lee trolling on clpmisc, "perl bug File::Basename and Perl's nature" From claird at lairds.us Tue Aug 24 09:08:12 2004 From: claird at lairds.us (Cameron Laird) Date: Tue, 24 Aug 2004 13:08:12 GMT Subject: How does a "script" differ from a "program" or "subroutine"? References: <56cfb0e3.0408232247.2df68078@posting.google.com> Message-ID: In article <56cfb0e3.0408232247.2df68078 at posting.google.com>, Porky Pig Jr wrote: >Phil Frost wrote in message >news:... > >> A script is just a program, but has the implication that it's a simple >> program for a simple task. >> > >I think the major implication is not that it's simple but it's written >in some 'interpreted' (rather than compiled) language. so we say >Python or Perl or Bash script, but not 'C script'. Look at the job >openings: you'll often see something like this: 'knowledge of >scripting languages (such as Perl and/or Python)'. All true--but we also shouldn't limit ourselves to the notoriously imprecise dialect of employment advertisements. Let's recognize that's how managers and HR functionaries talk, but recognize that our own concepts need to be sharper. From eppstein at ics.uci.edu Sun Aug 29 16:58:38 2004 From: eppstein at ics.uci.edu (David Eppstein) Date: Sun, 29 Aug 2004 13:58:38 -0700 Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: In article , Paul Morrow wrote: > Anthony Baxter wrote: > > On Sun, 29 Aug 2004 12:10:13 -0400, Paul Morrow wrote: > > > >>For example, in the following function def, the comments specify (what I > >>believe is) the author's intention behind each assignment. > >> > >> def circu(diameter): > >> """Info about circu.""" # defines circu.__doc__ > >> __author__ = 'Paul Morrow' # defines circu.__author__ > >> __features__ = memoized # defines circu.__features__ > >> pi = 3.14 # local variable definition > >> return pi * diameter > > > > > > Not in any Python I know of. I look at that and I think "oo, local > > variables". > > > > That you have a different belief doesn't make it right - I remain > > _extremely_ unconvinced. > > > > Anthony > > My belief doesn't make it right, that's true. But I think that a > preponderance of supporting evidence does. > > Have you seen a significant number of cases where a function uses > __xxx__ attributes as local variables? Have you seen any? So we really need to return to the FORTRAN days where variables have different semantics depending on their first character? Anyway, regardless of whether it's a local variable or an attribute, if it's in the function body I expect it to be executed at call time not def time. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ From gh at ghaering.de Mon Aug 2 13:08:43 2004 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Mon, 02 Aug 2004 19:08:43 +0200 Subject: MySQLdb select In-Reply-To: References: Message-ID: <410E751B.6000604@ghaering.de> Jaco Smuts wrote: > Gerhard > > That's sounds like great advice, not sure I've seen documentation on how > to do this though? [...] Harald Massa explained it really good in this thread. -- Gerhard From peter at engcorp.com Tue Aug 31 15:19:36 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 31 Aug 2004 15:19:36 -0400 Subject: Immutable sequence types lacking index() method In-Reply-To: References: Message-ID: Anne Wangnick wrote: > I don't get why the index() method is only defined for mutable sequence > types. This is not what I expected. Shouldn't this be added in Python? Is > there such a PEP already? I don't believe such simple changes require a PEP. They do, however, require someone actually requesting it (which is to say not here, but in the appropriate Sourceforge tracker) and someone else deciding it should be done and maybe a third person actually doing it. I suspect no one has done the first step yet, though before you do, check past requests to see if it was requested and rejected. Note that the only reason .index() exists even for lists (as opposed to merely for strings) was because I** requested it, and someone implemented it (I believe it was Raymond Hettinger but my memory is notoriously poor). Note that while .index() makes sense for some sequences, such as strings and lists, it doesn't make sense for the way in which tuples are "supposed to be used", which is as collections of heterogeneous data and not usually as simply read-only lists. Of course, that debate is still ongoing and there is always the argument that one has to turn lists into tuples to use them as dictionary keys, so the only way to resolve the question is to request the change (but not here) and see what happens. -Peter ** I think it was me, but I'm not even sure about that. From sharidas at zeomega.com Thu Aug 19 02:37:48 2004 From: sharidas at zeomega.com (Satchidanand Haridas) Date: Thu, 19 Aug 2004 12:07:48 +0530 Subject: inverse of izip In-Reply-To: References: Message-ID: <41244ABC.5020704@zeomega.com> Steven Bethard wrote: >So I know that zip(*) is the inverse of zip(), e.g.: > > > >>>>zip(*zip(range(10), range(10))) >>>> >>>> >[(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)] > >What's the inverse of izip? Of course, I could use zip(*) or izip(*), >e.g.: > > > >>>>zip(*itertools.izip(range(10), range(10))) >>>> >>>> >[(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)] > > >>>>x, y = itertools.izip(*itertools.izip(range(10), range(10))) >>>>x, y >>>> >>>> >((0, 1, 2, 3, 4, 5, 6, 7, 8, 9), (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)) > >But then I get a pair of tuples, not a pair of iterators. Basically, >I want to convert an iterator of tuples into a tuple of iterators. > >Steve > > --------------------------------- >>> a = itertools.izip(*itertools.izip(range(10),range(10))) >>> a >>>a.next() (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) >>> a.next() (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) >>> a.next() Traceback (most recent call last): File "", line 1, in ? StopIteration ----------------------------- Regards, Satchit ---- Satchidanand Haridas (sharidas at zeomega dot com) ZeOmega (www.zeomega.com) Open Minds' Open Solutions #20,Rajalakshmi Plaza, South End Road, Basavanagudi, Bangalore-560 004, India From peter at engcorp.com Thu Aug 12 00:33:23 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 12 Aug 2004 00:33:23 -0400 Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: <60dfb6f6.0408111846.615ee9eb@posting.google.com> References: <60dfb6f6.0408111846.615ee9eb@posting.google.com> Message-ID: <3YWdnYxLf--ObofcRVn-pw@powergate.ca> Carl Banks wrote: > steven.bethard at gmail.com (Steven Bethard) wrote in message news:... > >>I know there were complaints before about this sort of indentation, >>but I couldn't find them in python-dev and the comments in the wiki >>don't discuss this in any detail. Can anyone tell me why this >>indentation syntax was dispreferred? Specifically, I'm interested in >>why this is so drastically different from the other paired blocks: >>if/elif/else, try/except, try/finally, etc. > > One thing that's different is that, in all those cases, the second > block has a keyword that can't appear alone. You can't have an except > without a try, or an else without an if, but you could have a def > without a decorate. Is this merely a pedantic argument (not sure I use "pedantic" correctly) or is this an argument based on presumed difficulties in implementing the idea? I ask because I'm not sure the issue matters to anyone writing or reading the code. It certainly wouldn't bother me that with if/else it's the first part that's required, while with decorate/def it's the second part. -Peter From maxm at mxm.dk Wed Aug 25 05:10:47 2004 From: maxm at mxm.dk (Max M) Date: Wed, 25 Aug 2004 11:10:47 +0200 Subject: Why return None? In-Reply-To: References: Message-ID: <412c57c2$0$194$edfadb0f@dread12.news.tele.dk> Martin DeMello wrote: > It seems to be a fairly common pattern for an object-modifying method to > return None - however, this is often quite inconvenient. With newstyle classe you can subclass the list class and make some functions return self. class List(list): def sort(self): list.sort(self) return self l = List([1,2,4,2,5,2,6]) print l.sort() >>>[1, 2, 2, 2, 4, 5, 6] Well ok. Sort is a bad example, as you could just use sorted() insted. regards Max M From zathras at thwackety.com Thu Aug 26 15:14:33 2004 From: zathras at thwackety.com (Michael Sparks) Date: Thu, 26 Aug 2004 20:14:33 +0100 Subject: Call for signatories for J2 References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> <7xhdqp967k.fsf@ruckus.brouhaha.com> Message-ID: <412e3ba4$0$92817$ed2619ec@ptn-nntp-reader02.plus.net> Paul Rubin wrote: > Michael Sparks writes: >> It might (or might not) be too late but just as a check I checked >> to see if "per" is used by any projects listed in the proposal. (I >> was checking Twisted and Zope for "using" so decided to do "per" as well) > > I'm still not crazy about J2 but I like "per" much better than "using". It's very possible that we might end up with @pie syntax or nothing. (I suspect the latter is very unlikely, but it's still possible) > I'm afraid that the clpy proposals, and the @pie syntax, both seem to > me like "extreme programming", [ which isn't really very good for > language _design _ ] I think I'd agree. However for many people outside of python-dev and those who only dip into c.l.p, the @pie came as a big shock. I think that was compounded by the impact on commonly used tools. Why a shock? My recollection of the discussion regarding decorators (which I first encountered at EuroPython) was pretty much: * Who wants list before def? (Lots of votes - let's call it X) * Who prefers list after def? (Lots of votes - about the same as X) * Who'd prefer to delay their introduction in favour of a better syntax (about 2*X) ? There was also a comment regarding Java style decorators using an @ sign, but I don't recall any real discussion on the topic, and I also don't recall any example. There's a good chance I've misremembered things however! Between Europython and now despite dipping in & out of occasional posts for the mailing list digest I didn't spot anything serious regarding decorators until the @pie syntax was merged. That's not anyone's fault IMO, just the way it is, most people tend to concentrate more on what they're doing than everyone else. I also suspect that I'm not atypical - it's not that I didn't care, it's just that as has been said we all have a finite amount of time to devote to things we care about, and lets face it, we do all trust Guido and the rest of the team. My personal initial reaction to the syntax was "ugh", followed by listening to arguments and deciding that I could live with @pie happily (I do like perl after all so I've not got a huge aversion to punctuation). Then a nice alternative (IMO) was posted leading to me wondering how hard it would be to implement. (I've been rather pleasantly surprised I'm pleased to say :) Personally I think this has led to a useful discussion, albeit crushed up in a very short time span. However there are several things could happen now: 1 The @pie implementation might stay as is. 2 The @pie implementation might stay, but require explicit activation needing a __future__ statement. This to my mind is a good option - it clearly marks the feature as experimental, making people shy away from use unless they really do need it. 3 J2 might be accepted. 4 The feature might be ripped out * etc... Options 2 or 3 strike me as the best approach here - introduce a feature, mark it as experimental, with a large warning that it might change in the next release. That potentially allows the best of both worlds - people can use the feature in earnest, but do so on the understanding that the feature may change in a later release meaning that if they use it they have to be prepared to change their code. Furthermore if they release code using the feature they should be very careful how they use the feature. Speaking from personal experience we started using generators in 2.2 because they allowed a modicum of co-routine type behaviour (indeed this was part of the reason for choosing python), but the fact you had to put __future__ statements in everywhere in order to use them ensured that we limited their use to one location. I would hope that functionality added into a __future__ module would move from __future__ to standard syntax unchanged, but it does allow Guido and co the ability to change the language in those areas. It's for this reason that I *hope* that any decorator syntax when the final decision is taken is only introduced via the __future__ module approach. I do share your concerns about "if it's a mistake we're stuck with it", but unless something goes in there are two problems: * People will revert to using metaclass approaches, which having tried them I think people will find worse than something more explicit & in your face. (Almost any syntax on the wiki IMO is better than a metaclass approach) * There will be no single approach taken - leading to more hidden magic than you can shake a stick at... At the end of the day though, the decision lies with someone we all trust the judgement of. Even the J2 patch is just a means of opening up options. The only way sometimes of discovering something is a mistake is to try it. The patch allows Guido and everyone else to decide whether it is a mistake or not. Almost finally, personally I think this process has been enormously productive - it's gotten many more people involved in python than before, there has been constructive discussion that whilst perhaps it should've happened months ago it HAS happened. Personally this strikes me as incredibly healthy. Finally, if there is a chance that the syntax will have to change after it's been used in earnest then IMHO option A1 should be chosen, via a __future__ import. Whilst I'm obviously in favour of J2, option A1 strikes me as by _far_ the simplest to write or provide tools to programmatically munge people's code if syntax does change. (Much like the tools to remove unnecessary __future__ statements) Best Regards, Michael. From squirrel at WPI.EDU Thu Aug 5 13:39:25 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 5 Aug 2004 13:39:25 -0400 Subject: Confused about pep 318 In-Reply-To: References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: On Fri, 6 Aug 2004, Anthony Baxter wrote: > > That thread reaches no consensus, other than, in his sole post in the > > thread, Guido stating "I would love to see an implementation of this > > idea." Nothing about "this is going to be in 2.4a2, anybody vehemently > > opposed to it?" Like I said, the go-ahead was given privately. > > None of the decorator discussions _ever_ reached a conclusion. As mwh put it, > "bike-shed-the-ultimate". At the end of the day, Guido's the one who makes > these decisions. His decision was that the @ syntax should go into 2.4a2. I can't speak for everybody, but I would've liked some closure on the issue before it was injected into 2.4a2. From what I can tell, in the public's mind, the syntax of decorators was still an open issue, and if anything was going to make it in, it was going to be the "def foo() [dec]:" syntax that was currently in favour. No-one was prepared for the introduction of the @ syntax. From chrisks at NOSPAMudel.edu Fri Aug 6 04:50:19 2004 From: chrisks at NOSPAMudel.edu (Chris S.) Date: Fri, 06 Aug 2004 08:50:19 GMT Subject: Object Reference? In-Reply-To: References: Message-ID: Anthony Baxter wrote: > On Fri, 06 Aug 2004 05:39:51 GMT, Chris S. wrote: > >>Naturally, I could just recursively parse all the data comparing every >>element to every previously listed object, but is there a less obtrusive >>method? Python figures out when to delete objects based on the remaining >>references to an object. Is there a way to access this information to >>automatically lookup these references? Any help is greatly appreciated. > > > Use the "id()" of the objects? Well, I was thinking of a function that takes an object's id and returns the ids of all the objects that reference it. Given that Python keeps this information internally (I believe), my question is how do I access his data and what would be the easiest way to code this function? From vsoftsmith at aol.com Wed Aug 18 16:20:25 2004 From: vsoftsmith at aol.com (VSOFTSMITH) Date: 18 Aug 2004 20:20:25 GMT Subject: age of Python programmers References: Message-ID: <20040818162025.23951.00004040@mb-m28.aol.com> age 62 yes it is harder, less willing to "waste" time on unnecessary complexity but i know what questions to ask so it is a lot of fun From simoninusa2001 at yahoo.co.uk Wed Aug 11 00:05:32 2004 From: simoninusa2001 at yahoo.co.uk (simo) Date: 10 Aug 2004 21:05:32 -0700 Subject: VB-like GUI designer? References: Message-ID: <30260531.0408102005.5847b9c@posting.google.com> "Roger Binns" wrote: > You will also see the downloads for Windows, Linux and Mac. > End users simply see what looks like a normal setup and > a normal program. They never know or need to know that > there is Python involved. I noticed you have RPMs for Linux - so what do they include - a complete wxWidgets/GTK+/Python distribution, plus your files? From dougfort at dougfort.com Fri Aug 6 11:06:29 2004 From: dougfort at dougfort.com (Doug Fort) Date: Fri, 06 Aug 2004 15:06:29 GMT Subject: 'Using is not None, may not always work' References: Message-ID: On Fri, 06 Aug 2004 17:02:43 +0200, Peter Otten wrote: > Doug Fort wrote: > >> Since I installed 2.4a2 I've been getting a warning from pychecker: Using >> is not None, may not always work'. I thought 'is not None' was the right >> thing to do. I've had problems with 'if not x:', because some objects >> return False in this context. > > This is harmless. Starting with 2.4a2 None is a constant: Thanks, that it. > > Python 2.3.3 (#1, Jan 3 2004, 13:57:08) > [GCC 3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import dis >>>> def f(): > ... if x is None: pass > ... >>>> dis.dis(f) > 2 0 LOAD_GLOBAL 0 (x) > 3 LOAD_GLOBAL 1 (None) > 6 COMPARE_OP 8 (is) > 9 JUMP_IF_FALSE 4 (to 16) > 12 POP_TOP > 13 JUMP_FORWARD 1 (to 17) > >> 16 POP_TOP > >> 17 LOAD_CONST 0 (None) > 20 RETURN_VALUE >>>> > > Python 2.4a2 (#1, Aug 6 2004, 16:38:38) > [GCC 3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > [python 2.4a2] >>>> import dis >>>> def f(): > ... if x is None: pass > ... >>>> dis.dis(f) > 2 0 LOAD_GLOBAL 0 (x) > 3 LOAD_CONST 0 (None) > 6 COMPARE_OP 8 (is) > 9 JUMP_IF_FALSE 4 (to 16) > 12 POP_TOP > 13 JUMP_FORWARD 1 (to 17) > >> 16 POP_TOP > >> 17 LOAD_CONST 0 (None) > 20 RETURN_VALUE > > > When PyChecker sees the constant it supposes you are doing something like > > if x is "some string": pass > > which always had the LOAD_CONST op-code and is indeed dangerous. PyChecker > needs to be fixed to special-case None for 2.4. > > Peter -- Doug Fort, Consulting Programmer http://www.dougfort.com From export at hope.cz Mon Aug 23 16:16:15 2004 From: export at hope.cz (Lad) Date: 23 Aug 2004 13:16:15 -0700 Subject: Py2Exe and Threading Message-ID: <81a41dd.0408231216.6f919ff4@posting.google.com> Does anyone use Py2exe for a script that uses threading modul. In have a main thread and another in which I use smtplib to send email while the main thread is running. Under Python it works well but after compilation into exe it hangs( freezes) in the thread where I send email with smtplib. Lad From bjg at network-theory.co.uk Wed Aug 25 06:35:50 2004 From: bjg at network-theory.co.uk (Brian Gough) Date: 25 Aug 2004 11:35:50 +0100 Subject: Shell used by os.system References: Message-ID: <87vff7v721.fsf@network-theory.co.uk> Jacek Generowicz writes: > Is there a way of specifying the shell in which os.system commands are > executed[1]? Is there a way of specifying what startup scripts should > be read? It uses the underlying system() function, and that calls /bin/sh -c ... on Unix systems. -- Brian Gough Network Theory Ltd, Publishing the Python Manuals --- http://www.network-theory.co.uk/python/ From greg at cosc.canterbury.ac.nz Thu Aug 19 22:40:23 2004 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Fri, 20 Aug 2004 14:40:23 +1200 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: <2ol6kpFc24nrU1@uni-berlin.de> My vote: C1 D1 E1 -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From bingham at cenix-bioscience.com Thu Aug 5 07:35:19 2004 From: bingham at cenix-bioscience.com (Aaron Bingham) Date: Thu, 05 Aug 2004 13:35:19 +0200 Subject: Barcode Layout In-Reply-To: References: <4110CA81.6060706@cenix-bioscience.com> Message-ID: <41121B77.8030405@cenix-bioscience.com> John Hunter wrote: >>>>>>"Aaron" == Aaron Bingham writes: >>>>>> >>>>>> > > Aaron> I've been looking at Piddle > Aaron> (http://piddle.sourceforge.net/) and it appears we could > Aaron> write a backend to support our barcode printer with extra > Aaron> methods for higher-level entities, but I'm reluctant > Aaron> committing to apparent abandonware. Does anyone have > Aaron> experience doing similar things with Piddle? Are there any > Aaron> plans to maintain/enhance/replace Piddle? Are there other > Aaron> packages I should look at? > >I am the author of matplotlib - a 2D plotting library for python. >Like piddle, it is organized around various backends. It is a very >active project, with a number of developers who make regular >contributions in addition to myself. We have PS/EPS, SVG, wxpython, >gtk, tkinter, agg (pngs) and more. It is fairly easy to write a new >backend if you need to for your barcode printer (4 backends are user >contributed). > > Hi John, Thanks for the pointer. As it happens, I was already looking at matlibplot. One thing about piddle that's a good fit for our needs is that we can add methods to the canvases e.g. drawBarcode() just by adding that method to our backends. Is there any easy way to add such high-level drawing commands in matlibplot that are passed down to the backend level? Thanks, -- -------------------------------------------------------------------- Aaron Bingham Application Developer Cenix BioScience GmbH -------------------------------------------------------------------- From nicksjacobson at yahoo.com Fri Aug 20 11:50:47 2004 From: nicksjacobson at yahoo.com (Nick Jacobson) Date: 20 Aug 2004 08:50:47 -0700 Subject: Alternative decorator syntax decision References: <10ia1a9jm9tkuca@corp.supernews.com> <84GdneSa3r-TR7jcRVn-tw@powergate.ca> Message-ID: > I'd like to change my vote to J2 J2 J2. > > -Peter I also vote J2 J2 J2. --Nick From t-meyer at ihug.co.nz Mon Aug 9 20:50:31 2004 From: t-meyer at ihug.co.nz (Tony Meyer) Date: Tue, 10 Aug 2004 12:50:31 +1200 Subject: Popular Python projects with lots of pure Python code In-Reply-To: Message-ID: > So I am trying to come up with a list of projects I can use to get my > stats from. the stdlib is a no-brainer. Also plan to use Docutils. > But beyond those most of the big Python projects I can think > of have a ton of C code which is of no use to me. I don't need to be > able to run it, just going to be compiling to .py files. > > Any suggestions? How big is 'big'? The 1.0 SpamBayes release is pure Python; the .py files have 42,495 \n characters, so about that many lines. This includes comments and the like, of course. The source in CVS HEAD is probably a little bit larger, although it also includes one C file. Using the same na?ve line counting method, twisted has something like 320,000 lines of Python. There's some C, but you can run a fair chunk of twisted without it (at least last time I tried), so it's non-essential. =Tony Meyer From beliavsky at 127.0.0.1 Mon Aug 16 19:25:37 2004 From: beliavsky at 127.0.0.1 (beliavsky@aol.com) Date: 16 Aug 2004 18:25:37 -0500 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: <41214271_1@127.0.0.1> Jorge Godoy wrote: >Just an attempt and trying to keep it like your code. Thanks. My code did not correctly illustrate breaking out of more than one level of loop. How would the following code be translated to Python? It is silly of course, but real-world situations where you want to exit a nested loop are not that rare. program xnest_loop ! illustrate breaking a nested loop integer :: i,j,k,n n = 4 ido: do i=1,n jdo: do j=1,n if (i+j > n) exit ido do k=1,n if (i+j-k < 0) exit jdo print*,i,j,k end do end do jdo end do ido end program xnest_loop output: 1 1 1 1 1 2 2 1 1 2 1 2 2 1 3 3 1 1 3 1 2 3 1 3 3 1 4 ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--- From Kevin.Smith at sas.com Wed Aug 18 09:01:06 2004 From: Kevin.Smith at sas.com (Kevin Smith) Date: 18 Aug 2004 13:01:06 GMT Subject: PEP 318: Can't we all just get along? References: <20040817181725194-0400@braeburn.themorgue.org> <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: <20040818090138220-0400@braeburn.themorgue.org> In Paul Morrow wrote: > Peter Hansen wrote: > > Questions (for Kevin): > > 1. Would > > def deco1 foo(a, b, c): pass > > be the same as (just syntactic sugar for) > > def foo(a, b, c): pass > foo = deco1(foo) > > or would it mean something else? Sorry, I guess I should have put the equivalent current Python code in my first post. The example above is exactly what I meant. > 2. Would > > def deco1 deco2 foo(a, b, c): pass > > be the same as > > def foo(a, b, c): pass > foo = deco1(deco2(foo)) > > or > > def foo(a, b, c): pass > foo = deco2(deco1(foo)) I would choose the first option since it's easier to transform the string "deco1 deco2 foo" to "deco1(deco2(foo))" while I'm reading it (i. e. it fits my head :) ). > 3. Would there be any restrictions on what a decorator could *do* to > the method it was passed? e.g. Could it change: > > * the method's name (which could of course affect the method's > visibility: public|private|semi-private)? Nope, beginners wouldn't understand it immediately. That's just too magical. > * whether the method was a static, class, or instance method? Yes. > * the method's signature (formal parameter names, parameter order, > defaults values)? I guess, in theory, it could since the object returned by the "decorator" (I really hate that term) could return a completely different object, but I wouldn't suggest it. -- Kevin Smith Kevin.Smith at sas.com From michele.simionato at gmail.com Sat Aug 7 01:25:14 2004 From: michele.simionato at gmail.com (Michele Simionato) Date: 6 Aug 2004 22:25:14 -0700 Subject: elements of decorator syntax suggestions References: Message-ID: <4edc17eb.0408062125.231f7bef@posting.google.com> Anthony Baxter wrote in message news:... > This is the biggy, it seems. Current (as of a couple of hours ago) > discussions on python-dev are discussing other alternatives instead > of @, that will hopefully make it easier for IPython or Leo to cope > for now (but note that in the future, some other use for @ might be > found, so anyone relying on it at the moment might want to think > about that). One current suggestion is to use the | character, instead. > What about "-" ? - syncronized - classmethod def f(cls, *args): pass Any punctuation already used in current Python would go for me (., :, -, +, *, /, |, \, ^, etc. etc.) ! Michele Simionato From http Mon Aug 23 17:16:31 2004 From: http (Paul Rubin) Date: 23 Aug 2004 14:16:31 -0700 Subject: Why are strings immutable? References: Message-ID: <7xd61h368g.fsf@ruckus.brouhaha.com> "Larry Bates" writes: > Think about it. Since strings occupy a fixed > number of bytes in memory, a mutable string would > just be a linked list of strings. Eh? It would be treated just like Python currently treats lists. In fact, array('B') does just about exactly what Brent is asking for. From peter at engcorp.com Mon Aug 16 17:22:36 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 17:22:36 -0400 Subject: Python indentation deters newbies? In-Reply-To: References: <3064b51d.0408130615.3fc4a760@posting.google.com> <30260531.0408131853.18ec2446@posting.google.com> <412040f8$0$8087$a1866201@newsreader.visi.com> Message-ID: Paramjit Oberoi wrote: >>>It seems to me that you're asking for a rational explanation >>>for an emotional response. It's like asking somebody "*why* >>>don't you like pickled beets?" The answer you get is "I just >>>don't." >> >>Hmm... not for me. The answer would be "because they >>taste like dirt", or "I hate purple", or "anything pickled >>sucks". "I just don't" looks a lot like a cop-out. If > > That's what you would say, but who knows whether that answer would be > correct? It could be that you are simply not comfortable with answers > like "I just don't" which go beyond logic, and thus your brain > manufactures reasonable logical reasons when needed. "I don't know" may > actually be a more honest response than whatever logical response is > offered. If this had much to do with Python at this point, I might respond that it's easy to verify whether such a logical answer is in fact correct. For example, serve up some pickled beets that don't taste like dirt, or die them yellow. If I like them, then it is highly likely that I was in fact correct about my guess/logical answer... But really, is there much point in a meta-discussion about psychology, emotions, and the ways our brains trick ourselves? Or are you just looking for an argument? :-) -Peter From http Sat Aug 28 05:47:37 2004 From: http (Paul Rubin) Date: 28 Aug 2004 02:47:37 -0700 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <7xzn4gwgea.fsf@ruckus.brouhaha.com> <1gj7a1o.1a5d2q410jsn2kN%aleaxit@yahoo.com> <7xisb4xnh5.fsf@ruckus.brouhaha.com> <1gj7c1a.tfdm14p3hclcN%aleaxit@yahoo.com> <7xd61benm9.fsf@ruckus.brouhaha.com> <1gj82n3.1ylkr3nierngmN%aleaxit@yahoo.com> Message-ID: <7xd61b8uh2.fsf@ruckus.brouhaha.com> Benjamin Niemann writes: > import mymodule > verify_module(mymodule) This is no good. The import runs any code in the module, so the sig has to verify BEFORE the module loads. > Another question is, where to place (require|verify)_signature() (that > could also take a CA key (or list of) as optional argument to only > allow modules signed by this CA). It must not be imported from an > untrusted module. Correct, that's the messy infrastructure I mentioned. My basic idea is "do whatever Java does". From dale at riverhall.NOSPAM.co.uk Fri Aug 27 05:20:18 2004 From: dale at riverhall.NOSPAM.co.uk (Dale Strickland-Clak) Date: 27 Aug 2004 09:20:18 GMT Subject: Fun transformation problem References: Message-ID: Thanks to everyone for your replies. Very interesting. It is not too embarrasing to admit that these were better than we'd come up with. My colleague will be getting to grips with a newsreader in the near future and may be along later to express his own gratitude. -- Dale Strickland-Clark Riverhall Systems Ltd, www.riverhall.co.uk From godoy at ieee.org Sun Aug 29 17:44:49 2004 From: godoy at ieee.org (Jorge Godoy) Date: Sun, 29 Aug 2004 18:44:49 -0300 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <1LMXc.67190$UTP.37420@twister01.bloor.is.net.cable.rogers.com> <1gj7a9r.g7ec5a1g89rj0N%aleaxit@yahoo.com> Message-ID: Just writes: > But since .pyc's are always generated in the same directory as the .py > files, where else would you expect them to be generated? At the directory where the zip archive is stored. -- Godoy. From sbabbitt at commspeed.net Sun Aug 29 11:15:37 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Sun, 29 Aug 2004 08:15:37 -0700 Subject: Announcing PyCs, a new Python-like language on .Net References: <1093788608.645541@news.commspeed.net> Message-ID: <1093793065.258215@news.commspeed.net> "Peter Kleiweg" wrote in message news:Pine.LNX.4.44.0408291606250.2571-100000 at kleigh.nl... > Tom B. schreef: > > > > > "Mark Hahn" wrote in message > > news:mailman.2572.1093751093.5135.python-list at python.org... > > > > Please join the PyCs team. The only effort involved is particpating in a > > > low-traffic, high-content, mailing list. You will be able to influence > > the > > > design of the latest and greatest dynamic language. > > > > > > -- Mark Hahn, http://pycs.org > > > > > > > Python already does all the things that M*soft has tacked on in a kludgy > > way, in a beautiful pythonic way. I have been using windows based machines > > for a long time and in the language department (as well as others) M*soft > > has been superceded by the open source community. > > Is there a real danger that MS will make its own version of > Python, pushing it into the market, and we end up with a > dominant version that only works with MS software? > > -- > Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) > info: http://www.let.rug.nl/~kleiweg/ls.html > > The Halloween Documents: http://www.opensource.org/halloween/ > What M*soft should do is build libraries like the Speech Development Kit and Direct X into open source modules for Python. This way they are not trying to destroy open source but to join with it. Tom From fumanchu at amor.org Fri Aug 20 18:31:48 2004 From: fumanchu at amor.org (Robert Brewer) Date: Fri, 20 Aug 2004 15:31:48 -0700 Subject: Decorator keyword options - brainstorming Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E18@exchange.hqamor.amorhq.net> Paul McGuire: > Some other ideas: I still secretly favor "sorcerize". :) FuManChu From heikowu at ceosg.de Tue Aug 10 09:58:21 2004 From: heikowu at ceosg.de (Heiko Wundram) Date: Tue, 10 Aug 2004 15:58:21 +0200 Subject: pro python paper In-Reply-To: <3064b51d.0408100549.213dad5@posting.google.com> References: <305aa162.0408091905.5bce8f9a@posting.google.com> <3064b51d.0408100549.213dad5@posting.google.com> Message-ID: <200408101558.21907.heikowu@ceosg.de> Am Dienstag, 10. August 2004 15:49 schrieb beliavsky at aol.com: > [snip] > pretends that the main alternative to Python is Assembly, or some > other > "very low-level language". Have the authors not heard of C++ (with the > Standard Template Library) or Fortran 95 (with multidimensional arrays > and associated intrinsic functions)? You won't call C++ or Fortran 95 high-level languages, will you? ;) For me, the border between low-level programming and high-level programming lies where memory management becomes automatic. Heiko. From greg at cosc.canterbury.ac.nz Wed Aug 18 23:14:33 2004 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Thu, 19 Aug 2004 15:14:33 +1200 Subject: Best programming language In-Reply-To: References: <5155aad2.0408161008.40c57262@posting.google.com> Message-ID: <2oik8pFaqm1qU1@uni-berlin.de> Ravi Teja Bhupatiraju wrote: > Just type programming and Python is second. First is C. From which the conclusion is obvious: While C can be used for programming, it doesn't deserve to be called a language. :-) -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From dan.greenblatt at gmail.com Tue Aug 10 20:33:42 2004 From: dan.greenblatt at gmail.com (Dan Greenblatt) Date: 10 Aug 2004 17:33:42 -0700 Subject: Programmatically posting tkinter menus Message-ID: <7021e822.0408101633.35ace3d@posting.google.com> I know this can be done for context menus with the 'post' command.... What I'm trying to do, though, is programmatically post non-contextual menus (i.e. menus that exist on a horizontal menu bar at the top of my application window) in the correct place. So if I have five different menus (i guess these are menubuttons?) placed horizontally on my menu bar, and the third one is 'Actions', what is the best way to determine the x and y coordinates of these menu items, so that i can supply these coordinates to the post command and make the Actions menu pop up in the same place as if the user selected the 'Actions' menubutton from the menu bar??? I'm sure there's some Tkinter trickery involved, I just don't know how to get location information for these individual menubuttons as opposed to the containing menu as a whole. Thanks in advance, Dan From gregor.jan at NOSPAMquick.cz Wed Aug 11 06:26:06 2004 From: gregor.jan at NOSPAMquick.cz (Jan Gregor) Date: Wed, 11 Aug 2004 10:26:06 +0000 (UTC) Subject: jython and java exceptions References: Message-ID: Hello > I tried it again with SQLException only but my main loop ends with uncatched com.sybase.jdbc2.jdbc.SybSQLException. > This is extract from my code, exception is thrown by self.db.executeSql(iline), def run (self): while (1): gr_mode= 0 iline= Readline.readline(":", 0) if iline==None: continue iline= strip(iline) if iline=='\q': try: Readline.writeHistoryFile(self.rl_history.getName()) except: print ("Error writing history file!") System.exit(0) break if iline=='\gr': continue > Readline.addToHistory(iline) > if re.match(r'^\+ ', iline): gr_mode= 1 iline= strip(iline[2:]) > try: type, result= self.db.executeSql(iline) if result==None: continue if type=='resultSet': self.process(result) elif type=='table': if gr_mode: wnd = swingWnd.SimpleSwing(result.to_html()) wnd.size= (600,600) wnd.setVisible(1) else: self._print_table(result) elif type=='viewSource' or type=='procSource': self.println(result) elif type=='tableDesc': self._print_table(result) elif type=='error': self.println(result) # except (SQLException, PSQLException, SybSQLException), e: except java.sql.SQLException, e: self.println(e.getMessage()) # except: # pass Jan From olli at haluter.fromme.com Tue Aug 24 09:07:19 2004 From: olli at haluter.fromme.com (Oliver Fromme) Date: 24 Aug 2004 13:07:19 GMT Subject: "Socket" files? References: <1093035812.83612@jubilee.esoterica.pt> <4126824a$0$566$e4fe514c@news.xs4all.nl> <1093050493.502706@jubilee.esoterica.pt> <1093302968.204485@iceman.esoterica.pt> Message-ID: <2p0ss7Ffh1bdU2@uni-berlin.de> Paulo da Silva wrote: > Irmen de Jong wrote: > > from socket import * > > sock=socket(AF_UNIX,SOCK_STREAM) > > sock.bind("/tmp/mysocket") > [...] > > OK. It works! I'll use mkfifo for "fifo" type and this for > "socket" type. > BTW, don't I need to close "sock.close()"? I don't want to > do anything with the socket except keeping it on disk. Uhm, are you sure you know what you're doing? UNIX domain sockets work very similar to Internet domain sockets, i.e. they disappear when they're closed (or when your program exits, in which case everything is closed implicitly). Why exactly do you want to create one and keep it on disk without doing anything with it? That doesn't seem make any sense at all. Best regards Oliver -- Oliver Fromme, Konrad-Celtis-Str. 72, 81369 Munich, Germany ``All that we see or seem is just a dream within a dream.'' (E. A. Poe) From del at mjclift.freeserve.co.uk Fri Aug 13 02:57:13 2004 From: del at mjclift.freeserve.co.uk (Calvin79) Date: Fri, 13 Aug 2004 02:57:13 -0400 Subject: while and if References: Message-ID: Satchit, You've been great, saved me a lot of time and probably stopped me going bald as I won't be scratching my head half as much trying to get to grips with all this. Once again thankyou! Calvin From roy at panix.com Sun Aug 8 09:32:21 2004 From: roy at panix.com (Roy Smith) Date: Sun, 08 Aug 2004 09:32:21 -0400 Subject: @decorator syntax is sugar, but for what exactly? (decorator libraries). References: Message-ID: Anthony Baxter wrote: > The "Python of 1.5.2 simplicitly" is long, long gone. I don't agree that > newer Python's are somehow worse because new things have been > added. A short list: > > new style classes > foo(*arg, **kwarg) > iterators > generators > list comprehensions Perhaps I'm just a luddite, but I don't actually use most of those features. I have started playing around with iterators/generators, and find them very cool. The single biggest improvement I see in the language since 1.5.2 is string methods! After that, maybe augmented assignments (or whatever you call them; the ability to write "x += 1"). Most of the big improvements I've seen are in the library. When did unitest get added? I can't live without unittest. I like the logging module, even if I think it's about twice as complicated as it should be. A lot of my own personal growth in how I use the language is discovering modules which, while not new to the language, are new to me because I'd never noticed them before. Speaking of libraries, Dan Bishop posted some interesting example of @memoize and @printreturns utility wrappers. This leads me to think that a good way to leverage the idea of decorators would be a module of common utility functions which could be used as decorators by anybody. I'll call the module martha (since it supplies things used for decorating). Does the proposed mechanism support something like (to use one of Dan's exmaples, written with two different syntaxen): import martha @martha.memoize def fibonacci(n): if n in (0, 1): return n return fibonacci(n - 1) + fibonacci(n - 2) def fibonacci(n): @martha.memoize if n in (0, 1): return n return fibonacci(n - 1) + fibonacci(n - 2) Some of these things might even be usefully re-written in C for improved performance. I'm even wondering if somehow decorators could be used for i18n? The obvious problem there, is print is a statement not a function, and you can't decorate statements (or can you???). From abrady at prontomail.com Tue Aug 24 19:11:57 2004 From: abrady at prontomail.com (Art) Date: 24 Aug 2004 16:11:57 -0700 Subject: python line editor Message-ID: <6c283161.0408241511.625ea118@posting.google.com> Hello all, this is possibly a not well-formed question, but are there any python modules out there to do vi/ex/ed style script editing? i.e. the kind where you pass the commands thru stdin. ie: /sFoo :i"Bar" :wq or something like that. I'm porting some software right now so I have thousands of files to do replaces on. I want to do everything in Python, but I find myself writing a bunch of functions that look like this: for line in fileinput.input( os.path.join( dir, file ), inplace=1, backup="~"): m = xbrex.match( line ) if m: resdef = "" #is this an ndef? if m.group(1): resdef = "#if !defined(_XBOX) && !defined(_PS2)" else: resdef = "#if defined(_XBOX) || defined(_PS2)" #fixup the line line = line.replace(m.group(0), resdef) # write the line sys.stdout.write(line) Basically my problem is that I have to operate on files on a line by line basis using this method. This case works fine, but there are cases where I would like multi-line changes, basically mini-editor support. I know that this could be done with code i.e. if( startFound ): ..., but I don't want to have to track a bunch of flags. . . I know I could slurp the whole file into a string, but that still doesn't have the simplicity of the ed syntax. Since I'm basically asking for editor functionality, an alternative would be to do this with ed and scripts, or elisp, but I'd like to try python for this first. Any suggestions? Best regards, Aaron From nickjacobson at gmail.com Thu Aug 19 16:00:52 2004 From: nickjacobson at gmail.com (Nick Jacobson) Date: 19 Aug 2004 13:00:52 -0700 Subject: age of Python programmers References: <2ojheuFb9j2eU1@uni-berlin.de> Message-ID: <4d958f27.0408191200.5d9aa8ce@posting.google.com> Nicolas ?vrard wrote in message news:... > * Oliver Fromme [13:32 19/08/04 CEST]: > >Lucas Raab wrote: > > > One thing I've always kind of wondered is what is the average age of a > > > Python programmer?? What age groups use Python?? Something to think > > > about.... > > > >I'm 00100001b (or 021h ... or if you prefer decimal, it's > >33 years). Although I feel more like 27, which is the age > >of my GF. :-) > > Well if everybody feels like the age of his GF/BF, I'm 75 although I'm > only 27. I don't mean to pry, but you're a 27 year-old dating a 75 year-old? Like a "Harold and Maud" type deal? From maxm at mxm.dk Tue Aug 31 06:56:38 2004 From: maxm at mxm.dk (Max M) Date: Tue, 31 Aug 2004 12:56:38 +0200 Subject: File System In-Reply-To: References: <10j7r3cflo61680@corp.supernews.com> Message-ID: <41345966.3020103@mxm.dk> Aaron Bingham wrote: > Hello Maboroshi, > > You are not the first to think that there might be an alternative to the > filesystem. Here are a few links to sites for projects where > filesystems have been rethought or eliminated in very different ways. > Most of this is unfortunately vaporware. This is by no means a complete No, you forgot www.zope.org Especially Zope 3 This could easily be seen as a model for an object oriented filesystem. regards Max M From user at domain.invalid Thu Aug 19 03:01:41 2004 From: user at domain.invalid (Robbie) Date: Thu, 19 Aug 2004 17:01:41 +1000 Subject: Python and Apache Message-ID: Ok I've just about given up with mod_python. ATM It apache can't even FIND the files even though they're in a directory listing and all. What other ways can you use python with apache? If there is no other way I might try to solve the mod_python problem... hmmm From pm_mon at yahoo.com Sun Aug 29 20:28:34 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sun, 29 Aug 2004 20:28:34 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: David Eppstein wrote: > > So we really need to return to the FORTRAN days where variables have > different semantics depending on their first character? A little of that is a good thing (IMO). The alternative is that we explicitly declare each variable's semantics, which makes for a much more wordy language. > Anyway, regardless of whether it's a local variable or an attribute, if > it's in the function body I expect it to be executed at call time not > def time. > I believe that we should think of assignments to __xxx__ attributes as not being part of the function's body, but instead part of its declaration, just as we do with its docstring. def circum(diameter): """This describe's foo.""" __author__ = 'Paul Morrow' __version__ = '0.1' __features__ = synchronized, memoized # Everything above here is declaration. # Everything below here is in the body. pi = 3.14 return pi * diameter Paul From eldiener at earthlink.net Tue Aug 10 22:40:07 2004 From: eldiener at earthlink.net (Edward Diener) Date: Wed, 11 Aug 2004 02:40:07 GMT Subject: Static method object not callable References: Message-ID: Paul Morrow wrote: > Edward Diener wrote: >> This simple code example gives me the message, "TypeError: >> 'staticmethod' object is not callable". >> >> class X(object): >> def Y(x): >> print x >> Y = staticmethod(Y) >> ad = { 1 : Y } >> def Z(self): >> self.ad[1](3) >> x = X() >> x.Z() >> print "Done." >> >> I know there must be a way to have a class attribute reference a >> static method, and then call that static method through the >> reference, so if anyone can correct this it would be appreciated. >> >> >> > > Here are two alternatives. snip... Neither alternative is satisfactory. Surely there must be some means of directly specifying a reference to a static method in a class attribute in Python, and calling it from an instance method through the class attribute. From torsten.marek at student.uni-tuebingen.de Fri Aug 6 13:45:39 2004 From: torsten.marek at student.uni-tuebingen.de (Torsten Marek) Date: Fri, 06 Aug 2004 19:45:39 +0200 Subject: PyQT tutorial In-Reply-To: <410f8d35$0$31408$636a15ce@news.free.fr> References: <410f8d35$0$31408$636a15ce@news.free.fr> Message-ID: Olivier Thiery schrieb: > Hello, > > Do you know any good and fairly complete tutorial about PyQT, Eric and > QtDesigner ? > > Thank you, Have a look at the PyQt wiki, there are links on plenty of tutorials http://www.diotavelli.net/PyQtWiki greetings Torsten From djc at object-craft.com.au Wed Aug 4 02:29:29 2004 From: djc at object-craft.com.au (Dave Cole) Date: Wed, 04 Aug 2004 16:29:29 +1000 Subject: checking whether a var is empty or not In-Reply-To: References: Message-ID: Dave Benjamin wrote: > In article , Pierre-Fr?d?ric Caillaud wrote: > >> This smells like PHP to me... >> >>if var is not None: >> if var has not been assigned, it raises an exception. >> if var has been assigned, it contains a value which can be None or >>someting else. >> >> This is different from PHP where you can't know if a variable exists or >>not, because a non-existent variable will contain null if you check it, >>and putting null in a variable is like deleting it, but noone knows >>because there's no way of checking if a variable really exists, etc. > > > No, in PHP, you can find out if a variable exists using isset(). And trying > to dereference an uninitialized variable will generate a warning if you have > error reporting turned up all the way (error_reporting(E_ALL)). >>> def isset(var): ... return var in globals() ... >>> print isset('var') 0 >>> var = 43 >>> print isset('var') 1 Not that I can see any good use for this :-). - Dave -- http://www.object-craft.com.au From gerritvd at decillion.net Thu Aug 19 07:03:08 2004 From: gerritvd at decillion.net (Gerrit van Dyk) Date: Thu, 19 Aug 2004 13:03:08 +0200 Subject: age of Python programmers References: Message-ID: I am 39 and has been programming fulltime in python for the last 6 years. Prior to that I have been programming in Objective-C,C++ and C for a good 12 years. Python rocks, and I wouldn't change it for anything else, except when writing extensions in C Gerrit From SBrunning at trisystems.co.uk Fri Aug 20 06:56:25 2004 From: SBrunning at trisystems.co.uk (SBrunning at trisystems.co.uk) Date: Fri, 20 Aug 2004 11:56:25 +0100 Subject: Alternative decorator syntax decision Message-ID: <31575A892FF6D1118F5800600846864D01AE29D1@intrepid> J2 J2 J2 I like that one. ;-) Cheers, Simon B. simon at brunningonline.net http://www.brunningonline.net/simon/blog/ ----------------------------------------------------------------------- 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 rnichol_rrc at yahoo.com Sat Aug 21 13:58:39 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Sat, 21 Aug 2004 12:58:39 -0500 Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: @Ian J Cottee: Perhaps you should read some of my earlier posts. From sandysj at juno.com Fri Aug 20 16:02:35 2004 From: sandysj at juno.com (Jeff Sandys) Date: Fri, 20 Aug 2004 20:02:35 GMT Subject: Install Python on win32 without modifying registry References: <2260b3c5.0408200600.4c0550c4@posting.google.com> Message-ID: <412658DB.E23E5F25@juno.com> Install Python-2.3 on a computer that you have registry permissions, like your home computer, copy everything in the Python23 directory onto a CDROM, also search for python23.dll and copy it to the CDROM. You will be able to run Python off of the CDROM. Copy the CDROM onto the restricted computer and you can run Python on it without using the registry. I think that Pythonwin needs to register to activate the COM interface, I could be wrong, try copying the PythonCOM23.dll and PyWinTypes23.dll and see if it works. SeaPIG members have worked on a Python distribution with a webserver that will run off of a USB zipdrive, on any Windows, Linux and Mac computer. Thanks, Jeff Sandys QyRoN wrote: > > Hi > > I need to install python-2.3 on my computer. The problem is that > python and many programs written in python (pythonwin for example) use > registry for storing parameters on python installation. Is there a way > to install without modifying the registry? From megalomaan at hotmail.com Thu Aug 26 18:15:26 2004 From: megalomaan at hotmail.com (m0226065) Date: Fri, 27 Aug 2004 00:15:26 +0200 Subject: mySQLdb Message-ID: <1093558526.705789@seven.kulnet.kuleuven.ac.be> Ok so I have a mySQL server and mySQLdb as an interface (do I us this term correct here?) to this server from python now I have a game: I want to read a file into the db I want other data to be kept in the db from now on problem: since I have special things I want to do (like write a dict into a db), do I have to write a specialized class, derived from mySQLdb, or would that be dumb? I mean, I guess it would be easier to write some functions that take care of everything, while I just say "write this dict to that table" or "write this dict item to that table" and so on. I know there are things like ZOPE, but I just want to get an understanding of this... -- ____________________________________________________ Johan Potums --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.737 / Virus Database: 491 - Release Date: 12/08/2004 From abra9823 at mail.usyd.edu.au Thu Aug 26 21:12:19 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Fri, 27 Aug 2004 11:12:19 +1000 Subject: key storage Message-ID: <1093569139.412e8a738462b@www-mail.usyd.edu.au> hi! i am building a web application. for client authentication, i am using cookies which include the HMAC of the data. the server also has a public/private key pair for signing and verifying information. my question is how should these be stored on the server? encryption is the best solution, but if i encrypt them with another key, the question is where does this key get stored? i am using SunOS. the problem is i dont have access to the webserver. my web applications consists of a number of python scripts that allow you to create user models. Thus there is no application start or end and all state (including keys used) must be stored in files which are read when a request is made. if i could actually configure the server (or if i had written my own server app) i could make it read a set of keys (or a passphrase) from a file (stored on removable media) at startup and use those. the media itself could be removed. But i cant really do that with a whole lot of cgi scripts, can i? since the webserver is an apache, i think i should look at what features it offers in such a situation - i was hoping someone would have come across this problem before and solved it cheers -- Ajay Brar, ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From john at grulic.org.ar Sat Aug 14 06:29:21 2004 From: john at grulic.org.ar (John Lenton) Date: Sat, 14 Aug 2004 07:29:21 -0300 Subject: multiline snippets with triple quotes In-Reply-To: References: Message-ID: <20040814102921.GD12793@grulic.org.ar> On Fri, Aug 13, 2004 at 09:22:38AM -0400, Christopher T King wrote: > > AFAIK, triple quotes do everything heredocs do (but with a cleaner > syntax!); the following produce identical output: > > bash heredocs: > > echo -n < Some text. > Woo! > The end. > EOF > > Python triple quotes: > > print '''\ > Some text. > Woo! > The end.''' what about cat <<-EOF > 1 > 2 > 3 > EOF 1 2 3 -- John Lenton (john at grulic.org.ar) -- Random fortune: Somehow I have more respect for 14 year old Debian developers than 14 year old Certified Microsoft Serfs. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From zanesdad at bellsouth.net Tue Aug 31 12:47:33 2004 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Tue, 31 Aug 2004 12:47:33 -0400 Subject: convert string to input stream In-Reply-To: References: Message-ID: <4134ABA5.5040109@bellsouth.net> Titus Barik wrote: >Hi, > >I've used Google quite a bit in an attempt to find an answer to this >question, but have found no leads, possibly because I'm not sure I'm >wording my question properly. So I thought I'd try here. > >Basically I have a function that accepts an input file stream as an >argument: > > handle = open(SOME_FILE) > my_function(handle) > >But occasionally, I end up with a string ("Hello world") that I need to >convert to a stream in order to pass it into this function. Perhaps >something like: > > fake_handle = convert_to_handle("Hello world!") > > What you want is StringIO: http://www.python.org/doc/current/lib/module-StringIO.html or cStringIO: http://www.python.org/doc/current/lib/module-cStringIO.html I'll leave usage between you and the pydocs (unless, of course, you try it and have some problems with it). >so that it appears to this function to be a file handle. I've seen >functions in other languages that will take strings and convert them to >streams via IO Memory Buffers and such, but can't seem to find anything in >Python; or at least I don't know where to look. > >One solution that I didn't like was to do the following: > > 1. Open a temporary file. > 2. Write the string to that file. > 3. Read it back. > > Yeah - that's a nasty answer. You don't wanna go there. >Any suggestions are appreciated. > >Regards, > > > > From b.niemann at betternet.de Wed Aug 25 09:19:29 2004 From: b.niemann at betternet.de (Benjamin Niemann) Date: Wed, 25 Aug 2004 15:19:29 +0200 Subject: Just a quick one In-Reply-To: References: Message-ID: lists cannot be used as dictionary keys (because lists are mutable, they have no invariant hash value -> unhashable), use tuples instead: nextName = {('Bob','One'):['Rita','Sue'],\ 'Rita':['Mary','Sue',['Bob','One']],\ 'Sue':['Rita','Mary',['Bob','One']],\ 'Mary':['Sue','Rita']} M. Clift wrote: > Hi, > > Just a quick one. I'm trying to call [Bob','One'] with this, but I keep > getting 'unhashable'. I've tried various ' " and [ and can't get the thing > to work. Any offers? > > Thanks, > > M > > > > from random import * > > Name_Number = xrange(int(raw_input("Choose number of Names (1-20)? "))) > > state = [None,None] > > nextName = {['Bob','One']:['Rita','Sue'],\ > 'Rita':['Mary','Sue',['Bob','One']],\ > 'Sue':['Rita','Mary',['Bob','One']],\ > 'Mary':['Sue','Rita']} > > Name_List = [] > > tmp = choice((['Bob','One'],'Rita','Sue','Mary')) > > for x in Name_Number: > print state > while tmp in state[0:2]: > tmp = choice(nextName[Name_List[-1]]) > print tmp, ", ", > print > print "Name ",x+1," is ", tmp > Name_List.append(tmp) > state[x%2] = tmp > > print Name_List > > > > From jjl at pobox.com Sun Aug 29 08:26:29 2004 From: jjl at pobox.com (John J. Lee) Date: 29 Aug 2004 13:26:29 +0100 Subject: If the string module is deprecated... References: Message-ID: <87r7pqb05m.fsf@pobox.com> "Paul McGuire" writes: > ... what will become of the module-level constants, such as uppercase, > digits, hexdigits, etc.? Will they become class-level constants of the str > class? I don't see why not. One design decision I don't understand, though (which doesn't crop up in the particular cases you list above): staticmethods can be invoked through a class instance: >>> class Foo: ... @staticmethod ... def bar(): ... print 'bar' ... >>> f = Foo() >>> f.bar() bar >>> This is the issue that turned list.sorted() into builtin sorted() in 2.4 -- people would get confused expecting that [3,2,1].sorted() to return [1,2,3], rather than raise TypeError. Seems there is some disagreement amongst language desingers on whether polymorphism is a good thing in static methods. John From opengeometry at yahoo.ca Fri Aug 20 17:08:17 2004 From: opengeometry at yahoo.ca (William Park) Date: 20 Aug 2004 21:08:17 GMT Subject: Newbie to XML in Python References: Message-ID: <2on7i1Fbn7i7U1@uni-berlin.de> Jens Thiede wrote: > XML in Python doesn't seem easy or intuitive. All I need to do, is to > interpret a small piece of XML in which I store data for the contents of > an autorun menu. What is the quickest/most effective way to do this? > > What should I use for this; SAX or DOM - and which parser of ether one, > or niether (if there is a third option)? > > What are your views, It depends on your data. -- William Park Open Geometry Consulting, Toronto, Canada From peter at engcorp.com Tue Aug 3 16:23:27 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 03 Aug 2004 16:23:27 -0400 Subject: simple Thread question In-Reply-To: References: Message-ID: Christopher T King wrote: > The Python interpreter isn't too thread-friendly. Because it's not > re-entrant, it has to make use of a Global Interpreter Lock in order to > keep internal structures from getting mangled. .... Notwithstanding the rest of your answer, Christopher, I have to say that in my opinion, the Python interpreter is *very* thread-friendly. Obviously this just depends on differing ideas of what it means to be "friendly" to threads, but I find Python to be the most reliable and easiest to use environment for multi-threaded applications that I've ever used. I know what you meant by this, but if nothing else the criticism doesn't serve to promote Python very well... The world would probably be a much better place if most of its multi-threaded applications were rewritten in Python. (And it would be better still if some of them were then re-designed to use Twisted, but that's another story. ;-) -Peter From ialbert at mailblocks.com Fri Aug 20 10:13:36 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Fri, 20 Aug 2004 10:13:36 -0400 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: <1IqdnUtRpciSmrvcRVn-vQ@giganews.com> Paolino wrote: > d2 d2 j2 > > Thanks for the piece of democracy or more likely the 'illusion' of it. From asif at go-away-spammer.com Tue Aug 31 13:49:42 2004 From: asif at go-away-spammer.com (Player) Date: Tue, 31 Aug 2004 18:49:42 +0100 Subject: Beginners question. References: <2pjrbnFkpdrvU1@uni-berlin.de> Message-ID: [edit:snip] Ok thanks Russell Blau :) I can see it now heh. M.B -aka- Player From eltronic at juno.com Wed Aug 25 20:11:01 2004 From: eltronic at juno.com (eltronic at juno.com) Date: Wed, 25 Aug 2004 20:11:01 -0400 Subject: Call for signatories for J2 Message-ID: <20040825.201105.-381037.0.eltronic@juno.com> please count as for the J2 proposal of yesterday. please list as anon, email withheld. or better yet email mangled, as this and other lists promise to mangle but they never do. here comes another 100 spams and virus as a result of this post. H J2 A H (|deco | deco instead of @deco) J2 (word: suite where word is decor, using, other) include time for objections to any word picked. note, many are on vacation or only sporadically even read c.l.py and less frequently py-dev. a python-announce post woulden't be a bad idea. A (@deco, @ deco) H checked in implementation already exists that can be modified with minimal effort. solves some problems for Leo, but long range, since Leo edits multiple languages and Java, assembler, forth, perl others' use @ Leo will continue working somehow. by avoiding existing and user added @directives. by Leo allowing you to define the @ to something else. by @verbatim. any change is going to have consequences. not sure about other tools, Ipython, empy. learning new behavior for users, all the supporting doc amendments, good search for prior help tips out the window. in addition to the trivial by comparison code changes. @@ will interfere with diff listings. texi format uses @directives? has anyone checked? is it really the position of the BDFL that python must use @ at any cost? when | works. was surprise a necessary part of the strategy? folding editors and code import no worse off than how they now handle f = staticmethod(f). since they probably don't now alert the user there is something special about this def, they needed to be fixed anyway. no doubt all tools will need upgrade whichever. we could single out a few that aren't up to py 2.2 yet. that don't differentiate old from new classes. | generates syntax error? or would it be unary? why is it a problem that | looks like l or 1 on some fonts? and might '?' be another alternate char? but I will not try to find the answer if its already posted, imagine trying to lookup python related pages including ? or @, some searchers commonly ignore punctuation. are decorators destined to be forever obscured? these are not inconsequential questions! in the few weeks since wider public exposure dozens of such questions exposed. even the omnipotent can't keep them all on the same page at the same time. more than a few interested parties just tuned out early on. J2 has tacit community approval and implementation. good job on the pep, the wiki, the vote and proposal. since vote wasn't secret, probably many just decided to minimize bandwidth and held off posting. the one lopsided poll, evidence of nothing. the correct result somehow emerged. favorable words, using, deco, decor, trans, alter, declare, combine might already be used as var names. implement, may be better left for something else. with & as, overloaded, but actually not too bad. @deco is a syntax that will be tolerated, but, how can so many negatives be a positive? presumable we will be able to try/except if no def found, I have seen no mention of this. will there be a specific Exception? is there unicode or other popular name for @ besides NULL or at? the real shocker in all this is how few dev people are aware of how @deco affects Leo & IPython. guess the word is not getting out how much they are an improvement on the basic python intrepreter. oh, You dont realize Leo executes python? much pity. it is completely scriptable in nearly every way. but I guess you can cobble something together similar in emacs or vim, not to put too fine a point on it. decor: staticmethod def whatever(): pass anything more complicated than that I wince. there are people with a use case who say they need it, we all really should get out of the way. I had occasion to revisit a few methods I moved out of a class because they didn't need to be methods. I ran some quick timing tests and found staticmethod accessed from other class members appear to be faster so I made them staticmethod. I know its heresy to support a change like this based on speed, based on timing of toy pared down examples, but maybe the decorator would be seen as more directly affecting people if they realize how they can use the thing. the docs, none of the available lit even briefly touch on this aspect. or maybe I gloss over it. too few comparing and contrasting examples. need more like @memoize in a few of the posts. python is deceptively simple, you can go a long time with just the basic simple stuff. another case in point, it took a very long time to feel comfortable with slices and list comprehensions. in spite of 20 years of c. now, I see their application directly as simple. take the advice of a few early posters in this by far more archive building issue than 308 and try decorators out to see them in action. or the also good advice, to make your case, then stand back as the creators of Leo and IPy have. ask me again in 5 minutes I might say no change is justified. stop the insanity. but, the case for waiting is a fruitless non argument. recommend save pep numbers ending in 8 for only the most contentious issues. is 0332 being saved for y2032 issues? 0338 anyone up for macros? do we get @deco then ?macro soon after? do we get |deco or ?deco then @macro I sense a fork forming in a few minds. I am amused that $ slipped in as an % interpolation replacement under the radar. ________________________________________________________________ The best thing to hit the Internet in years - Juno SpeedBand! Surf the Web up to FIVE TIMES FASTER! Only $14.95/ month - visit www.juno.com to sign up today! From squirrel at WPI.EDU Tue Aug 10 13:02:50 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 10 Aug 2004 13:02:50 -0400 Subject: Decorators proposal In-Reply-To: References: <19b62f17.0408100741.7f2712ac@posting.google.com> Message-ID: On Tue, 10 Aug 2004, Daniel Dittmar wrote: > RebelGeekz wrote: > > Just my humble opinion: > > > > def bar(low,high): > > meta: > > accepts(int,int) > > returns(float) > > #more code > > +1 > > This also allows to set function properties inside of the function > def handler (match): > meta: > pattern = re.compile (...) Ooh, perty! I especially like the extension of this idea into function attributes; it looks even cleaner than the .attribute syntax I like. The only problem I see with this is that Guido seems to want decorators to be more prominent than the function signature itself, so he probably certainly won't go for "hiding" then in a doubly-nested block. (I write "hiding" in quotes because I'm of the opinion that placing decorators after a one- or two-line function signature does nothing to obscure the decorators.) From peter at engcorp.com Tue Aug 17 00:19:07 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 17 Aug 2004 00:19:07 -0400 Subject: Flython? In-Reply-To: <30260531.0408131856.5ef3b0d3@posting.google.com> References: <411cbcb1$0$3894$4d4ebb8e@news.nl.uu.net> <30260531.0408131856.5ef3b0d3@posting.google.com> Message-ID: simo wrote: > There's a few libraries for making SVG files in PHP, so there may be > Python versions too, but if you want ActionScript then I guess you're > determined to go with Flash instead..... I just stumbled over the following text in this page (http://www.webreference.com/programming/javascript/j_s/column2/) '''Now some developers might say: "Big deal, who cares about Flash animations ?" Well, as it turns out - quite a lot of folks in the software business. First, Adobe has thrown in the towel on SVG and adopted Flash's .SWF file format for animations as has just about every other major player in the graphics, 3D modeling and image design fields. ''' Adobe has thrown in the towel on SVG?! When did that happen? I can't find another reference to the news that inspired this comment. On another note: comparing Flash and SVG: http://www.theopensourcery.com/osrsvgover.htm -Peter From drconrad at metaplay.com.au Mon Aug 9 21:02:42 2004 From: drconrad at metaplay.com.au (Simon Wittber) Date: Tue, 10 Aug 2004 09:02:42 +0800 Subject: {SPAM?} SQL Qeries via XMLRPC Message-ID: <200408100050.i7A0oprv015248@redpill.digitalventures.com.au> In a recent project, we came across a problem using the FreeTDS (MS SQL / Sybase DB API) libraries on a Linux box. To cut a long story short, we ending up exposing the functions we needed from a Win32 machine, via XMLRPC, in Python, so that we could run ad-hoc queries on the SQL Server which was running on that same machine. Side point: The timeliness at which I was able to achieve this impressed the boss. Python code is now springing up everywhere :-) I am now considering implementing persistent connections, authentication, and perhaps even "stored procedures" in this tiny XMLRPC Server. This would provide a consistent database interface to all our applications (written in various languages) and allow us to consider things like load balancing and query caching. It would also make a move from the proprietary SQL Server to a Free RDBMS much easier (portable stored procedures, same API etc). The problem is, I have a tiny little nag in my mind about the use of XMLRPC (and therefore HTTP) to implement this. Has anyone done this sort of thing before? Are there any problems with this strategy that I have not considered? Should I be considering the standard python XMLRPC / HTTP / SocketServer modules for mission critical production systems? Regards, Simon Wittber. From ivoras at __geri.cc.fer.hr Sat Aug 7 17:17:28 2004 From: ivoras at __geri.cc.fer.hr (Ivan Voras) Date: Sat, 07 Aug 2004 23:17:28 +0200 Subject: psyco out of memory In-Reply-To: References: Message-ID: Tim Hochberg wrote: >> (Still, I'm surprised how slow it is. The same "program" in Java takes >> about 10sec, and here it's passed 5 minutes and I'm still waiting...) > > > > That ran in about a minute here. Psyco won't speed up floating point > operations near as much as integer ops at present, hence its speed > deficit with respect to java. Yes, it took about minute here too. While it is a ~ 30x speed gain, it shows there's still space for improvement :) -- What part of "Ph'nglui mglw'nath Cthulhu R'lyeh wgah'nagl fhtagn" don't you understand? From nzanella at cs.mun.ca Wed Aug 18 17:42:19 2004 From: nzanella at cs.mun.ca (Neil Zanella) Date: 18 Aug 2004 14:42:19 -0700 Subject: static class methods and data members Message-ID: Hello, I would like to know whether it is possible to define static class methods and data members in Python (similar to the way it can be done in C++ or Java). These do not seem to be mentioned in "Learning Python" by Mark Lutz and David Ascher. It seems like they are a relatively new feature... It seems to me that any truly OO programming language should support these so I'm sure that Python is no exception, but how can these be defined/implemented in Python? Currently I have Python version 2.3 installed on my system. Thanks, Neil From kosh at aesaeion.com Fri Aug 13 15:45:38 2004 From: kosh at aesaeion.com (kosh) Date: Fri, 13 Aug 2004 13:45:38 -0600 Subject: Why I love python. In-Reply-To: References: Message-ID: <200408131345.38773.kosh@aesaeion.com> On Friday 13 August 2004 1:34 pm, Christopher T King wrote: > On Fri, 13 Aug 2004, kosh wrote: > > Why is there a need for a stand alone executable? At least on all the > > unixes whether something is executable is just determined by the > > executable bit on the file. > > Not if you don't have the interpreter installed. > So install the runtime. If you want to run the .NET stuff you need to have the the .NET CLR or Mono installed. If you want to run java apps you need the jvm etc. Overall once a runtime is installed it makes distributing apps a lot easier since the actual thing you need to send someone is tiny. Also at least on unixes I have not run into a box in about 6 years or so that did not have python and perl installed so in practice I have not run into that problem. > > I can execute a python program just as transparently as one in > > compiled c, c++, etc. I really don't see the point of that. > > Indeed, you can do that just as easily on Windows, too. The point of a > stand-alone executable is not to make running the script easier, but to > make distribution easier. Users don't need to install Python to run a > Python script if it's a stand-alone executable. Overall it would be better if there was an easy way on windows to get the runtime installed since then you can send users far smaller files, smaller updates and it makes it easier for people to patch their systems. I have seen more then a few cases where a bug like temp file creation was found to be a problem in python and in some c code. However the difference is that you can update the python runtime and all affected python programs are fixed. The same is not true of the c versions. One of them I have run into which is a pain is stuff like openssl. When that gets updated it seems a whole bunch of programs have to be compiled to work with it again. The change is source compatible but for whatever reason the bug fix breaks binary compatibility on a number of apps. Just update the runtime though for things like python,java, etc and all apps on those runtimes just become fixed. From tdelaney at avaya.com Sun Aug 15 22:25:59 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Mon, 16 Aug 2004 12:25:59 +1000 Subject: I am in great need of code to make a dome Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01CF49B6@au3010avexu1.global.avaya.com> Ali wrote: > I am in great need of code that will make a dome. > > I would like the inputs to be similar to that of the sphere. ie: > > pos=(x0, y0, z0) > radius = R > color = (r,g,b) > etc. > > I am using VPython of course. Please help me. The correct response to your statement is here: http://www.catb.org/~esr/faqs/smart-questions.html Tim Delaney From ville at spammers.com Mon Aug 23 13:57:09 2004 From: ville at spammers.com (Ville Vainio) Date: 23 Aug 2004 20:57:09 +0300 Subject: Dynamic Scoping problem References: Message-ID: >>>>> "Andrew" == Andrew Koenig writes: Andrew> That said, I should point out that global variables are Andrew> usually a bad idea. But also let me point out that they are not as bad an idea as they are in e.g. C, because they are only *module* global, and are a handy way of implementing singletons. -- Ville Vainio http://tinyurl.com/2prnb From eppstein at ics.uci.edu Thu Aug 5 13:35:22 2004 From: eppstein at ics.uci.edu (David Eppstein) Date: Thu, 05 Aug 2004 10:35:22 -0700 Subject: RELEASED Python 2.4, alpha 2 References: <411231C8.3020308@interlink.com.au> Message-ID: In article , Christopher T King wrote: > On Fri, 6 Aug 2004, Anthony Baxter wrote: > > > On Thu, 5 Aug 2004 12:29:51 -0400, Christopher T King > > wrote: > > > What does one do if a decorator raises an exception? > > > > def deco(func): > > raise TypeError > > > > @deco > > def foo(): > > print "hello" > > Yes yes yes, I /know/ they are /able/ to raise exceptions. My point was > about handling them in a clean, concise way. What do you do if any other piece of code raises an exception? Why do you think decorators should be any different? If this is an actual possibility, there's nothing preventing you from wrapping a decorated def inside a try-except block. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ From jjl at pobox.com Wed Aug 11 18:38:18 2004 From: jjl at pobox.com (John J. Lee) Date: 11 Aug 2004 23:38:18 +0100 Subject: ClientCookie References: <6f402501.0408110018.1e4e5ca8@posting.google.com> Message-ID: <87llglqp0l.fsf@pobox.com> fuzzyman at gmail.com (Michael Foord) writes: > Has anyone used ClientCookie to store cookies ? > I'm going to play around with 'pickling cookies' - but I wondered if > anyone had any experience of this. [...] There shouldn't be any problem with that. You can pickle the CookieJar itself, or the cookies inside it ([c for c in cookiejar] -- and use .set_cookie() to get them back into a new CookieJar). May I suggest instead using cookielib, from Python CVS? (note that POSTs with urllib2 are broken in 2.4a2, so don't use that) cookielib is a new module in 2.4, and is a cleaned-up version of the cookie-handling parts of ClientCookie. John From ialbert at mailblocks.com Thu Aug 5 13:35:26 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Thu, 05 Aug 2004 13:35:26 -0400 Subject: Decorator syntax In-Reply-To: References: <38ednYT1NLz1P4zcRVn-uA@powergate.ca> Message-ID: Christopher T King wrote: > Languages with support > for these things already have a clear, consice way of specifying these > things: > > def classmethod foo(self): > pass > > Why can't we do the same with Python? The syntax doesn't have to > support user constructs (indeed, it shouldn't), and it doesn't have to exactly my thoughts, but then someone comes along and vehemently argues how this will break Emacs or Jedit and on top of that it won't allow you to do some *really cool* stuff, like multi-decorations for a truly pythonic iteration over the AccuWeather 10 day forecast datadump. > Compare to the current state of affairs: >@partializer(5) >@make_my_function_awesome >@author('Chris King') >@accepts(int,int,int) >@classmethod >def foo(self,a,b,c): > """Returns a+b*c.""" > > return a+b*c Yuck! Down with them funny symbols! i. From BruceEckel at MailBlocks.com Sun Aug 1 21:25:23 2004 From: BruceEckel at MailBlocks.com (Bruce Eckel) Date: Sun, 1 Aug 2004 19:25:23 -0600 Subject: The term "Protocol" In-Reply-To: <1f7befae04080117515cbb0ca9@mail.gmail.com> References: <1f7befae04080117515cbb0ca9@mail.gmail.com> <6910338109.20040801192523@MailBlocks.com> Message-ID: Sunday, August 1, 2004, 6:51:15 PM, Tim Peters wrote: > Iteration is a protocol, not a type. I know the term "protocol" has been used to describe a language feature in a number of languages, but since we have no official "protocol" support in Python I'm interested in what "we" mean by this term. I'm going to guess that a protocol is like an interface in Java, except that it doesn't have a concrete definition anywhere, but it is implied through convention and use. Thus a protocol is a "latent interface." Am I close? I'd like to understand this term better. Bruce Eckel From bitshadow at yahoo.com Sun Aug 15 23:46:55 2004 From: bitshadow at yahoo.com (Michael Scarlett) Date: 15 Aug 2004 20:46:55 -0700 Subject: Anyone use VPython? References: <8f17f4bc.0408141932.46b7c405@posting.google.com> <69juh0dalfeu39fpvvvcb56ukovl0o1fsb@4ax.com> <8f17f4bc.0408151258.35874dbc@posting.google.com> Message-ID: alikakakhel3 at hotmail.com (Ali) wrote in message news:<8f17f4bc.0408151258.35874dbc at posting.google.com>... > Arthur wrote in message news:<69juh0dalfeu39fpvvvcb56ukovl0o1fsb at 4ax.com>... > > On 14 Aug 2004 20:32:49 -0700, alikakakhel3 at hotmail.com (Ali) wrote: > > > > >Anyone use VPython? > > yup From jmfbahciv at aol.com Sun Aug 29 06:38:53 2004 From: jmfbahciv at aol.com (jmfbahciv at aol.com) Date: Sun, 29 Aug 04 10:38:53 GMT Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <776e0325.0408260433.449660c8@posting.google.com> <412dfc1c$0$65599$a1866201@newsreader.visi.com> <86hdqpriww.fsf@blue.stonehenge.com> <412e199e$0$8076$a1866201@newsreader.visi.com> <4130654c$0$19703$61fed72c@news.rcn.com> <0MiYc.109993$TI1.98802@attbi_s52> Message-ID: <4131c4e4$0$19722$61fed72c@news.rcn.com> In article <0MiYc.109993$TI1.98802 at attbi_s52>, Joe Smith wrote: >jmfbahciv at aol.com wrote: > >>>AND HOW MANY SPACES PER TAB STOP? >> >> Eight. Now talk about indenting skip returns...that one >> required blood transfusions. [emoticon looks at list of n.g.] >> I guess not many will understand. > >I understand. >The style I used for PDP-10 macro assembly language was > *) Indent two spaces for error return from subroutine or UUO (or jsys) > *) Indent one space for instructions that skip or may skip. > >The other point of contention was what to put between the opcode and >its arguments; space vs tab. I had some TECO macros that would >undo the damage after pristine code had been munged by someone >not conforming to style. :-) And we had some that put them back. /BAH Subtract a hundred and four for e-mail. From ely.stob at elvis.com Mon Aug 2 18:40:31 2004 From: ely.stob at elvis.com (Ely Stob) Date: 2 Aug 2004 15:40:31 -0700 Subject: IronPython-0.6 is now available! References: <278de0e.0407281353.27b6a457@posting.google.com> <410963E4.2040106@v.loewis.de> Message-ID: "Martin v. L?wis" wrote in message news:<410963E4.2040106 at v.loewis.de>... > I have worked a lot with C# and .NET lately, and found two things: > - the VM is very well designed. It does not really work for languages > other than C#, though (and, yes: I believe that it does not work > well for Python either, despite IronPython's existance (*)) ^^^ Where is the referent of your asterisk? I'm very much interested in why you insist that the CLR does not work well for Python, in the face of an apparently solid existence proof, in the form of IronPython, that that simply isn't the case. I know you have a sound understanding of Python, and sometimes understanding beats apparent empirical evidence... Ely From fumanchu at amor.org Wed Aug 25 17:09:39 2004 From: fumanchu at amor.org (Robert Brewer) Date: Wed, 25 Aug 2004 14:09:39 -0700 Subject: python-dev Summary for 2004-08-01 through 2004-08-15 Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E75@exchange.hqamor.amorhq.net> Brett C. wrote: > I just don't want people to suddenly get the impression that they can > always just throw a little mutiny every time Guido makes a decision. > Do that and he will just ignore what people want period and never even > give people a chance to propose an alternative once it reaches > python-dev. Well said. > And I want people to realize my tirade was just that, a personal > tirade. It was out of frustration and thus should be taken with a > grain of salt. But that frustration is grounded in reality. > And that frustration came from the feeling that the Python community, > which I love, seemed to suddenly form a mob, grab pitchforks and > torches, and started screaming. And then they seemed to hold a public > meeting with *everyone* proposing their idea and not completely > listening to initial decisions. I attribute the breakdown-of-process to scale issues, and not much else. The decorator debate had: a) the largest body of dissenters I've ever seen for a new Python feature, and b) the largest volume of alternate proposals. Many new features have had a certain amount of tweaking to be done even after Guido has pronounced. Each of these tweaks requires communication. In the case of decorators, the volume of communication required was simply too much for the medium of Usenet, which promotes short, tangential discussions rather than systemic analysis. This is the primary reason I felt a focused paper would benefit the process. One of my hopes is that, for large, complex community responses in the future, someone else will do the same. This proposal sets a precedent for those cases which overload the normal response process. However, it should be made clear that _not every response warrants this format_. In Brett's language, go ahead and hold "public meetings". But either hire a Usenet police force or (much better) police yourselves--when the debate begins to explode, form a task force and write a proposal or two. I am *not* placing blame on anyone here, just pointing out that this is the first time such a step was needed. We are all watching it play out for the first time. Let's learn from it and apply those lessons next time. Although I like J2, I'm not rabid about it (and despite the opinions of the pundits, I do *not* have "too much free time"; far from it). I could have written an equally-compelling paper on any of the alternatives. I am far more dedicated to the "meta-outcome" of this proposal, that Guido is presented with alternatives in a usable and effective fashion, than I am in which option he selects. The "next level" of course, is whether that goal is met and how to reproduce such a success (or avoid such a failure) in the future. > I truly hope that next time Guido makes a decision that people as a > whole disagree with everyone involved can get together and discuss it > calmly without flooding my inbox. =) Me too. This isn't a fundamentally hard problem, it simply happens to be a management issue for a bunch of techies. Once in a while, Guido's "cabinet" needs to manage people and process as much as it does source code. As Python gains more of a following, this will occur more often. Robert Brewer MIS Amor Ministries fumanchu at amor.org From russblau at hotmail.com Thu Aug 19 16:13:56 2004 From: russblau at hotmail.com (Russell Blau) Date: Thu, 19 Aug 2004 16:13:56 -0400 Subject: ZeroDivisionError: float division (baby steps) References: <6daa8765.0408191133.2f2e22e3@posting.google.com> Message-ID: <2okg05Fbh7kjU1@uni-berlin.de> "Benjamin Niemann" wrote in message news:cg3184$vbr$02$1 at news.t-online.com... > Artemisio wrote: > > I am a non programmer who just started with Python. So far I love it. > > > > I would appreciate if you could help me fix this error I get taking this exercise: > > > > count= 0 > > sum= 0.0 > > number= 1 > > print "Enter 0 to exit the loop" > > > > while number != 0 : > > number= input("Enter a number: ") > > > > count= count + 1 > > sum= sum + number > > > > count= count -1 > > print "The average is: ",sum/count > > #the error is in the above line > > > > "ZeroDivisionError: float division" > > > > Thank you in advance, Len > I think the two lines after input() should be indented as the belong to > the while loop... Note that, even after you fix this, you will still get an error if the user decides to enter "0" as the first number! -- I don't actually read my hotmail account, but you can replace hotmail with excite if you really want to reach me. From jjl at pobox.com Mon Aug 2 15:18:48 2004 From: jjl at pobox.com (John J. Lee) Date: 02 Aug 2004 20:18:48 +0100 Subject: Sending Mail via Extended MAPI References: <87llh18dqt.fsf@pobox.com> Message-ID: <87pt69uz53.fsf@pobox.com> David Fraser writes: > John J. Lee wrote: [...] > > IIRC, there's a commercial COM server that wraps up Extended MAPI and > > exposes a clone of the Simple MAPI interface. > > I think this must be Outlook Redemption ... Yeah, that rings a bell. From the name, I guess I misremeber the API it exposes, though... > anyway we'll try and see > if we can implement what we need without them :-) Rather you than me :-) John From edvard+news at majakari.net Wed Aug 4 03:54:31 2004 From: edvard+news at majakari.net (Edvard Majakari) Date: Wed, 04 Aug 2004 10:54:31 +0300 Subject: Reading message size Message-ID: <874qnjcp8o.fsf@titan.staselog.com> I'm trying to create an improved front-end for training messages for a spam filter. I discovered an excellent Python module email - now it's so easy to support variety of mailbox formats. However, I need to know exact size of the message (in bytes) and skip the message if it is too large, before passing the message to filter. This is easy with MH or Maildir style directories - because each message is on separate file, it is trivial to get the file size. However, with mbox or any other format containing several messages in a file, I'm unable to find out individual message size. Of course, I could find this out by writing a message to a temp file and afterwards checking the temp file size, but I think that's awkward and inelegant. Is it somehow possible with email module? -- # Edvard Majakari Software Engineer # PGP PUBLIC KEY available Soli Deo Gloria! $_ = '456476617264204d616a616b6172692c20612043687269737469616e20'; print join('',map{chr hex}(split/(\w{2})/)),uc substr(crypt(60281449,'es'),2,4),"\n"; From lonetwin at gmail.com Fri Aug 20 04:42:50 2004 From: lonetwin at gmail.com (Steve) Date: Fri, 20 Aug 2004 14:12:50 +0530 Subject: TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' In-Reply-To: References: Message-ID: <5a309bd30408200142e937d2d@mail.gmail.com> Hi Martin, > File "/usr/local/lib/python2.3/distutils/sysconfig.py", line 159, in > customize_compiler > cpp = cc + " -E" # not always > TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' > make: *** [build] Error 1 Judging by the error I'm guessing that you might not have a c or c++ compiler installed. Run the following command to check if you have the required rpms: rpm -q gcc rpm -q gcc-c++ Install them if you they are missing and then rerun 'configure' and 'make'. HTH Steve From squirrel at WPI.EDU Thu Aug 12 11:50:47 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 12 Aug 2004 11:50:47 -0400 Subject: os.removedirs not working In-Reply-To: References: Message-ID: On Thu, 12 Aug 2004, CptPicard wrote: > You could use shutil.rmtree : it works fine! Oh wow, I completely forgot about shutil. Good stuff, that. From nomail at nospam.no Thu Aug 19 13:51:38 2004 From: nomail at nospam.no (Dominic) Date: Thu, 19 Aug 2004 19:51:38 +0200 Subject: My only complaint about Python In-Reply-To: References: Message-ID: > I have a batch script to create libpython23.a, for those who are > interested. It requires pexports-0.42h from > http://starship.python.net/crew/kernr/mingw32/pexports-0.42h.zip > extracted to C:\Program Files\pexports-0.42h, and of course mingw. I have successfully built libpython23.a using implib.exe provided with the free Borland C/C++ command line compiler package. Once this is done, cygwin-gcc can be used to create _native_ windows modules. If someone is interested I'll try to collect the necessary commands and flags from my Makefiles. Ciao, Dominic From alex_stante at yahoo.de Sun Aug 15 18:19:29 2004 From: alex_stante at yahoo.de (Alexander Stante) Date: 15 Aug 2004 15:19:29 -0700 Subject: Control an external console program Message-ID: Martin DeMello wrote: > Check out http://pexpect.sourceforge.net/ Thank you! That is exactly was I was looking for. Alex From chris.irish at libertydistribution.com Wed Aug 4 17:31:43 2004 From: chris.irish at libertydistribution.com (Chris Irish) Date: Wed, 04 Aug 2004 14:31:43 -0700 Subject: Finding all time periods for a given interval within a date range In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022DD9@exchange.hqamor.amorhq.net> References: <3A81C87DC164034AA4E2DDFE11D258E3022DD9@exchange.hqamor.amorhq.net> Message-ID: <411155BF.1090102@libertydistribution.com> Robert Brewer wrote: >Graeme Longman wrote: > > >>I was wondering if anyone has written some Python code which >>uses a start >>date and end date and a given interval (day, month or year) >>and outputs all >>the time periods for that range and interval. >> >>For example you may wish to find all the months between the dates >>'2004-02-14' and '2004-08-04'. You would maybe use a function >>where you pass >>in those starting and ending dates and the interval 'month' >>and you'd get >>back a list of those months. I guess you would need to year >>part of the date >>too, so ['2004-02', '2004-03', '2004-04', '2004-05', >>'2004-06', '2004-07', >>'2004-08']. If you had passed in 'day' as the interval then >>you would be >>given back a list of all the days in those months. >> >> > >You should also look into the mx.DateTime module it has all sorts of time functionality already built into it much better than the python time module. Have a look here > >http://www.egenix.com/files/python/mxDateTime.html > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From grv575 at hotmail.com Tue Aug 24 22:07:45 2004 From: grv575 at hotmail.com (grv575) Date: 24 Aug 2004 19:07:45 -0700 Subject: % format strings References: <144d0df.0408231455.6b664466@posting.google.com> <412A76A7.4C87D17C@alcyone.com> <537ea4cd.0408231919.4ada3ca1@posting.google.com> <412abc53$0$8076$a1866201@newsreader.visi.com> Message-ID: <144d0df.0408241807.d0ad7e3@posting.google.com> great thx. didn't know that was valid C. it wouldn't compile on my end b/c of mixing C++ style include directives and C ones it looks like. From giva at users.sourceforge.net Thu Aug 19 16:46:21 2004 From: giva at users.sourceforge.net (Gisle Vanem) Date: Thu, 19 Aug 2004 22:46:21 +0200 Subject: My only complaint about Python References: Message-ID: <4125119b$1@news.broadpark.no> "John Hunter" wrote: > Your paths may vary... > > copy c:\windows\system32\python23.dll . > c:\progra~1\pexports-0.42h\bin\pexports python23.dll > python23.def > c:\MinGW\bin\dlltool --dllname python23.dll --def python23.def --output-lib libpython23.a > > copy libpython23.a c:\python23\libs > del python23.dll > del libpython23.a Shouldn't that be "libpython23.dll.a" as per normal conventions on MingW? I.e. a static lib would be "libpython23.a". But I guess that's impossible or impractical. --gv From elbertlev at hotmail.com Sun Aug 22 23:39:45 2004 From: elbertlev at hotmail.com (Elbert Lev) Date: 22 Aug 2004 20:39:45 -0700 Subject: 2 GB files References: <9418be08.0408221427.182a4d30@posting.google.com> Message-ID: <9418be08.0408221939.7003bd3c@posting.google.com> > Elbert: you might get a positive response if you rephrased your post. > > "Our corporation needs functionality ___. We would be happy to pay a > contract consultant $n000 to come up with a solution that will work with a > future trajectory of Python releases." > > > David David! I appreciated your sarcasm very much. I want to assure you that our corporation is perfectly able to hack code not worse then others can. But reading the postings, which talk about this issue I thought, that if this feature is "half" supported and is widely requested, why not to explain why it is needed. IMHO the most attractive feature of Python is not its syntax, but the library and the size of distribution. In fact, straight from the box 8-9 MB distribution is sufficient to solve many everyday programming/administration problems. This is good, but can be improved. There are some needed pieces missing in standard distribution and this is one of them. By the way I (almost) do not care about the speed: it is reasonable right now, can be improved, by proper data structure/algorithm selection and if one really needs speed ? C is available. I suggest start discussing additions to the library. This will improve the package and make it easier to administer. > Or you could pray to the OSS gods. All is about language acceptance. In my daily programming activities there are several alternatives to Python, f.e. Java or .NET with their comprehensive libraries of classes (much richer then Python's). And what stops me from using it? The size of the distributive! I understand that adding too much will result in an increase of the size of distribution, but something has to be done. From timr at probo.com Tue Aug 10 01:22:59 2004 From: timr at probo.com (Tim Roberts) Date: Mon, 09 Aug 2004 22:22:59 -0700 Subject: upper memory limit References: <3hdbh0d3af4gjbj6psec10nahls0u3nuu3@4ax.com> Message-ID: Peter Wilkinson wrote: > >Why do you say that single process is limited to 2 Gig? I believe that on >windows a single process can run with to 32 bits addressed or 4 Gig of >space. I have run R with over 2 Gig of memory. > >Why would python be limited to 2 Gig (including overhead)? I don't see that >python should be any different. (I responded privately, but thought I should register the answer here, too.) No, a user-mode process in Windows is limited to 2GB of address space. Addresses 80000000 and larger are kernel space. You can change the threshhold to 3GB by using the /3gb boot.ini switch, but few do so. You can certainly have more than 2GB of physical RAM in your machine, but a single process cannot use more than 2GB at a time. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From http Wed Aug 18 14:37:57 2004 From: http (Paul Rubin) Date: 18 Aug 2004 11:37:57 -0700 Subject: Embedding Python in Python References: Message-ID: <7xu0v0l2be.fsf@ruckus.brouhaha.com> Robey Holderith writes: > Anyone know a good way to embed python within python? No. > I'd like to allow user-defined scriptable objects. I'd > like to give them access to modify pieces of my classes. > I'd like to disallow access to pretty much the rest of > the modules. There was a feature called rexec/Bastion for that purposes in older version of Python, but it was removed because it was insecure. > Any ideas/examples? Run your sensitive stuff in a separate process (or separate computer) and allow the hostile clients to communicate through sockets. From calidusdk at hotmail.com Fri Aug 20 17:39:24 2004 From: calidusdk at hotmail.com (Artemisio) Date: 20 Aug 2004 14:39:24 -0700 Subject: ZeroDivisionError: float division (baby steps) References: <6daa8765.0408191133.2f2e22e3@posting.google.com> <2okg05Fbh7kjU1@uni-berlin.de> Message-ID: <6daa8765.0408201339.2ab815e9@posting.google.com> "Russell Blau" wrote in message news:<2okg05Fbh7kjU1 at uni-berlin.de>... > "Benjamin Niemann" wrote in message > news:cg3184$vbr$02$1 at news.t-online.com... > > Artemisio wrote: > > > I am a non programmer who just started with Python. So far I love it. > > > > > > I would appreciate if you could help me fix this error I get taking this > exercise: > > > > > > count= 0 > > > sum= 0.0 > > > number= 1 > > > print "Enter 0 to exit the loop" > > > > > > while number != 0 : > > > number= input("Enter a number: ") > > > > > > count= count + 1 > > > sum= sum + number > > > > > > count= count -1 > > > print "The average is: ",sum/count > > > #the error is in the above line > > > > > > "ZeroDivisionError: float division" > > > > > > Thank you in advance, Len > > I think the two lines after input() should be indented as the belong to > > the while loop... > > Note that, even after you fix this, you will still get an error if the user > decides to enter "0" as the first number! Well, thank you very much for your feedback. I've sorted out now. For some reason the last two lines were indented. Unindenting them producted the expected behaviour. I am actually amazed by how intuitive and readable Python coding is. I've spent maybe 12 hours with it and I can already code small routines of my own. I felt more frustrated last time I tried to learn VB. I gave up. Python is my game. From john.burton at jbmail.com Wed Aug 18 11:55:34 2004 From: john.burton at jbmail.com (john.burton at jbmail.com) Date: 18 Aug 2004 08:55:34 -0700 Subject: Windows URL protocol handler in python? Message-ID: Thanks, from a quick browse that sounds like a good starting point (and probably far too much effort for what I had in mind) From martin at v.loewis.de Fri Aug 6 08:12:14 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 06 Aug 2004 14:12:14 +0200 Subject: Proposal: require 7-bit source str's In-Reply-To: References: <4112AC7B.1060508@v.loewis.de> <411343D7.3020604@v.loewis.de> <411353A3.8090502@v.loewis.de> Message-ID: <4113759E.2070405@v.loewis.de> Hallvard B Furuseth wrote: >>"Written by Martin v. L?wis" > > > So if the file has -*- coding: iso-8859-1 -*-, how does that doc string > look to someone using a iso-8859-2 locale? Let's start all over. I'm referring to a time when there was no encoding declaration, and PEP 263 was not written yet. At that time, I thought that a proper encoding declaration (i.e. a statement) would be the best thing to do. So in my example, there is no -*- coding: iso-8859-1 -*- in the file. Instead, there is a directive. About the unrelated question: How should a docstring be displayed to a user working in a different locale? Well, in theory, the docstring should be converted from its source encoding to the encoding where it is displayed. In practice, this is difficult to implement, and requires access to the original source code. However, Francois Pinard has suggested to add an __encoding__ attribute to each module, which could be used to recode the docstring. About your literal question: In the current implementation, the string looks just fine, as this docstring is codepoint-by-codepoint identical in iso-8859-1 and iso-8859-2. > Just like a str7bit directive, in whatever form, would not catch the > missing u in front of the doc string. Not necessarily. It would be possible to go back and find all strings that fail to meet the requirement. Notice that your approach only works for languages with single-byte character sets anyway. Many multi-byte character sets use only bytes < 128, and still they should get the warning you want to produce. >>(of course, requiring that people use escape sequences for >>them might be acceptable). > > > Argh! Please, no. Think again. There absolutely is a need to represent byte arrays in Python source code, e.g. for libraries that manipulate binary data, e.g. generate MPEG files and so on. They do have a legitimate need to represent arbitrary bytes in source code, with no intention of these bytes being interpreted as characters. Regards, Martin From sandskyfly at hotmail.com Tue Aug 17 19:19:34 2004 From: sandskyfly at hotmail.com (Sandy Norton) Date: 17 Aug 2004 16:19:34 -0700 Subject: Flython? References: Message-ID: Peter Hansen wrote: > In the vein of Jython, I wonder what it would take to build > a Flython? (Lousy name, I know.) That would take Python > source, presumably a subset since some things couldn't be supported, > and compile it into ActionScript bytecode (aka the bytecode compiled > from ECMAScript source for the Macromedia Flash player environment). Have you looked at http://ming.sourceforge.net/ Sandy From rnichol_rrc at yahoo.com Sat Aug 21 13:54:46 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Sat, 21 Aug 2004 12:54:46 -0500 Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: <%_LVc.982$MR2.3626@news1.mts.net> > from which we conclude that "check the definition" means "check the > definition in the dictionary *I* prefer. . .AND stop reading before it > contradicts the position I espouse." > > Look, given the use of "quantum" in quantum physics it's reasonable to > expect the word to mean something small - but insisting it must do so > is flat-out wrong. For one thing this isn't Gell-Mann appropriating a > nonsense word - "quark" - from Joyce; "quantum" was a perfectly good > English word before Planck applied it to black-body radiation. The OED > has references going back to 1619 as a synonym for quantity. (It even > has a use in pharmacology - "quant. suff!", famously chanted in Alfred > Bester's /The Stars My Destination/, is an abbreviation of "quantum > sufficit," roughly "as much as necessary.) > I have my opinion, you have yours. Why get your pantyhose in a bunch. I made mention of my reasoning that you didn't touch on, you just got agressive straight away... why am I replying? From peter at engcorp.com Sun Aug 22 11:36:04 2004 From: peter at engcorp.com (Peter Hansen) Date: Sun, 22 Aug 2004 11:36:04 -0400 Subject: J2 proposal: keyword In-Reply-To: References: Message-ID: <3Ludncfl1Pd2IbXcRVn-gg@powergate.ca> Robert Brewer wrote: > III. Choosing a keyword [snip good list of principles] > -Candidates for keywords have fallen into two or three camps, and > emphasize different aspects of decorators: > > -Declarative: declare, predef, moddef > -Transformative: transform, wrap, modify, mutate > -Attributive/Annotative: amend, using, having > -Directive: pragma, signify > -Associative: helper, qualify, qual, meta > -Cross-cutting: imbue, endow, bestow, embellish, extend, accum, glom, > confer > -Prepositions/Adverbs: using, through, per, via, by > > I had an ugly paragraph promoting 'declare' as a top candidate, but I've > always liked 'using' (which many of you promoted within the past 24 > hours). Maybe the above will produce further polarization among you. ;) +1 on "using" as the best of the choices above. I find the declarative ones awkward, transform inappropriate when transforming is not going on, attributive ones okay (but "amend" sounds like it must come afterwards), directive too compiler-like, associative not bad but too abstract, cross-cutting too much like "decorate" not to mention sort of frivolous-sounding, and prepositions mostly too vague (except for "using" again). -Peter From peter at engcorp.com Tue Aug 10 21:03:43 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 10 Aug 2004 21:03:43 -0400 Subject: measuring 1/100th seconds, what function? In-Reply-To: References: Message-ID: Bengt Richter wrote: > On windows I like to use time.clock() [snip samples showing better resolution than time.time()] > IOW, time apparently gets the NT4 basic os time slice delta (10ms), > whereas clock tries to get something better (and it's pretty good). All true, though the OP said he wanted code that would work on both platforms (though Tim's response shows how trivial it is to dynamically pick the best routine). Presumably there's a human involved somewhere, plus a multitasking OS with other things going on, and Python as well (not widely known as a good hard realtime language ;-), so going for the extra resolution of time.clock() is likely to be an exercise in higher resolution, but no better accuracy... -Peter From squirrel at WPI.EDU Fri Aug 6 09:28:18 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Fri, 6 Aug 2004 09:28:18 -0400 Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) In-Reply-To: References: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> Message-ID: On Fri, 6 Aug 2004, Anthony Baxter wrote: > The solution, if you don't like the syntax, is not voting. It's to > propose an argument that Guido will accept, in favour of your preferred > option. We can't propose a dozen different syntaxes. We're voting for our benefit, not his. The argument presented will be built around the syntax voted for here. From shane.holloway at ieee.org Tue Aug 24 18:55:46 2004 From: shane.holloway at ieee.org (Shane Holloway (IEEE)) Date: Tue, 24 Aug 2004 16:55:46 -0600 Subject: Decorators: J2 and a relation to @ Message-ID: <412BC772.5000502@ieee.org> Decorators. Yep, in your inbox again. I'll be short about it. But first, I should put out a disclaimer: I'm not opposed to the pie-syntax. I'm just tired of writing my method names three times, and having the important 'classmethod' below the function. Now... on with it! From the example in Section II, part 3 of http://www.aminus.org/rbre/python/pydec.html consider the following decorated function. @using([ funcattrs(author="Guido van Rossum"), memorize, synchronize, classmethod, ]) def foo(cls, *args): pass This looks an lot like the suite method proposed in J2 in the current syntax of Python 2.4a2. All that would need to be added is a "using" decorator method. I like the @ because it makes me take note that the following is special in terms of code execution.[*] What do you think? -Shane Holloway [*] I could actually see @ being used to introduce smalltalk/ruby-esk block closures... but that's a totally different discussion for a much different time. <1.2-wink> From raims at dot.com Tue Aug 10 03:39:21 2004 From: raims at dot.com (Lawrence Oluyede) Date: Tue, 10 Aug 2004 09:39:21 +0200 Subject: Importance of C# (was Re: IronPython-0.6 is now available!) References: <278de0e.0407281353.27b6a457@posting.google.com> <5dydnZSDZaARoZXcRVn-ug@powergate.ca> <1n5z28erh2m3u.dlg@baczek.net.invalid> <537ea4cd.0408070757.14790cfe@posting.google.com> <41155c78$0$4348$626a14ce@news.free.fr> <144d0df.0408092156.1455f2af@posting.google.com> Message-ID: <1o2ouxh30essi.1eewz4ary5xj3.dlg@40tude.net> In data 9 Aug 2004 22:56:55 -0700, grv575 ha scritto: > Really MI > causes more issues and confusion than it solves. Do you know about Python new style classes and MRO? -- Lawrence (l dot oluyede at virgilio dot it) "In IE we trust" From unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom Fri Aug 6 04:36:45 2004 From: unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom (Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.) Date: Fri, 6 Aug 2004 10:36:45 +0200 Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) References: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> Message-ID: Vote... And what is the position from Kerry and/or Bush ? From tim.peters at gmail.com Mon Aug 2 16:39:55 2004 From: tim.peters at gmail.com (Tim Peters) Date: Mon, 2 Aug 2004 16:39:55 -0400 Subject: os.walk() maxdepth In-Reply-To: References: Message-ID: <1f7befae04080213396d7d1cbc@mail.gmail.com> ]GMTaglia ] > I've googled a lot but I couldn't figure out how to implement a maxdepth in > os.walk(), does anybody had the necessity to do something like that? No, but for root, dirs, files in os.walk(whatever): .... if root.count(os.sep) >= CUTOFF_DEPTH: del dirs[:] will prune the search based on the number of separator characters in the directory currently being visited. Mutating dirs in-place controls which directories the os.walk generator looks at when it's resumed. This is only effective in a top-down walk (which is the default). From apardon at forel.vub.ac.be Fri Aug 27 04:19:19 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 27 Aug 2004 08:19:19 GMT Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> <1gj4fb5.607xsc51izh8N%aleaxit@yahoo.com> <7xllg25lkt.fsf@ruckus.brouhaha.com> <1gj4u3a.12ttba9fynd6uN%aleaxit@yahoo.com> <1gj5bp4.qhup8tldmvebN%aleaxit@yahoo.com> Message-ID: Op 2004-08-26, Alex Martelli schreef : > Antoon Pardon wrote: > ... >> Then python has already deviated from the one obvious way to do it. > > Yep, ever since it let you code 2+3 and 3+2 with just the same effect -- > which was from day one, and couldn't have been otherwise. _Preferably_ > only one way, but as I said what's preferable can't always be achieved. > > Nevertheless, when for some task there _is_ one obvious way to do it, > adding a feature whose main effect would be giving two alternative > obvious ways to do it would be unPythonic. > >> I can do: >> >> a = a + b vs a += b. > > Yes you can, and in the general case get very different effects, e.g.: And what about a += b vs a.extend(b) > >>>> c=a=range(3) >>>> b=range(2) >>>> a+=b >>>> c > [0, 1, 2, 0, 1] > > versus: > >>>> c=a=range(3) >>>> b=range(2) >>>> a=a+b >>>> c > [0, 1, 2] I wouldn't say you get different effects in *general*. You get the same effect if you use numbers or tuples or any other immutable object. > So, which one is the obvious way to do it depends on what 'it' is. In > some cases it doesn't matter, just like b+a and a+b are going to have > the same effect when a and b are numbers rather than sequences, and > there's nothing Python can do to fight this -- practicality beats > purity. If you're (when feasible) altering the object to which name 'a' > is bound, a+=b is the obvious way to do it; if you're in any case > rebinding name 'a' and letting the original object stand undisturbed, > 'a=a+b' is the one obvious way to do THAT. Not all objects can be > altered, so the first ones of these tasks isn't always going to be > feasible, of course. > >> >> or >> >> a = b + c vs a = ''.join(b,c) > > You should try out the code you post, otherwise you risk ending up with > code in your face -- ''.join(b, c) will just raise an exception, which > is a VERY different effect from what b + c will give in most cases. > I'll be charitable and assume you meant ''.join((a, b)) or something > like that. > > Again, it's only in one very special case that these two very different > 'ways to do it' produce the same effect, just like in other different > special cases 'a = b + c' and 'a = c + b' produce the same effect and > there's nothing Python can do about it. > > But let's be sensible: if 'it' is joining two strings which are bound to > names b and c, b+c is the only OBVIOUS way to do it. Building a > sequence whose items are b and c and calling ''.join on it is clearly an > indirect and roundabout -- therefore NOT "the one obvious way"! -- to > achieve a result. Proof: it's so unobvious, unusual, rarely used if > ever, that you typed entirely wrong code for the purpose... That is just tradition. Suppose the "+" operator wouldn't have worked on strings an concatenating would from the start been done by joining, then that would have been the one obvious way to do it. > Nobody ever even wished for there to never be two sequences of code with > the same end-result. The idea (a target to strive for) is that out of > all the (probably countable) sequences with that property, ONE stands > out as so much simpler, clearer, more direct, more obvious, to make that > sequence the ONE OBVIOUS way. And what if it are three sequences of code with the same end-result, or four. From what number isn't it a problem any more if two sequences of that length or more produce the same result. > We can't always get even that, as a+b vs > b+a show when a and b are bound to numbers, but we can sure get closer > to it by respecting most of GvR's design decisions than by offering > unfounded, hasty and badly reasoning critiques of them. I think that this goal of GvR is a bad one. If someway of doing it is usefull then I think it should be included and the fact that it introduces more than one obvious way to do some things shouldn't count for much. Sure you shouldn't go the perl-way where things seemed to have been introduced just for the sake of having more than obvious way to do things. But eliminating possibilities (method chaining) just because you don't like them and because they would create more than one obvious way to do things, seems just as bad to me. What I have herad about the decorators is that one of the arguments in favor of decorators is, that you have to give the name of the function only once, where tradionally you have to repeat the function name and this can introduce errors. But the same argument goes for allowing method chaining. Without method chaining you have to repeat the name of the object which can introduce errors. > >> The difference between >> >> print somelist.sort() >> >> and >> >> somelist.sort() >> print somelist >> >> >> is IMO of the same order as the difference between >> >> >> print a + b >> >> and >> >> r = a + b >> print r > > For a sufficiently gross-grained comparison, sure. And so? In the > second case, if you're not interested in having the value of a+b kept > around for any subsequent use, then the first approach is the one > obvious way; No it isn't because programs evolve. So you may think you don't need the result later on, but that may change, so writing it the second way, will making changes easier later on. > if you ARE, the second, because you've bound a name to it > (which you might have avoided) so you can reuse it (if you have no > interest in such reuse, it's not obvious why you've bound any name...). > > In the first case, fortunately the first approach is illegal, the second > one is just fine. Were they exactly equivalent in effect neither would > be the one obvious way for all reasonable observer -- some would hate > the side effect in the first case, some would hate the idea of having > two statements where one might suffice in the second case. So? I sometimes get the idea that people here can't cope with differences in how people code. So any effort must be made to force people to code in one specific way. > Fortunately the first approach does NOT do the same thing as the second > (it prints out None:-) so Python sticks to its design principles. Let > me offer a private libation to whatever deities protect programmers, > that Python was designed by GvR rather than by people able to propose > analogies such as this last one without following through on all of > their implications and seeing why this SHOWS Python is consistent in > applying its own design principles! That these implications are important is just an implication on the design principles. If someone doesn't think particular design principles are that important, he doesn't care that if somethings is changed that particulat design principle will be violated. Personnaly I'm not that impressed with the design of python, it is a very usefull language but having operators like '+=' which have a different kind of result depending on whether you have a mutable or immutable object is IMO not such a good design and I wonder what design principle inspired them. -- Antoon Pardon From rnd at onego.ru Sat Aug 14 16:16:58 2004 From: rnd at onego.ru (Roman Suzi) Date: Sun, 15 Aug 2004 00:16:58 +0400 (MSD) Subject: PEP318 In-Reply-To: References: <20040812090056.00001e31@titan> <7ttmh0t8c3cogtbhhnp1ohqu8b51pda461@4ax.com> Message-ID: On Sat, 14 Aug 2004, Arthur wrote: >On Fri, 13 Aug 2004 16:43:05 +1000, Anthony Baxter > wrote: > >>On Thu, 12 Aug 2004 17:03:19 GMT, Arthur wrote: >>> >def foo (): >>> > whatever >>> >foo = decorator (foo) >>> > >>> >is that you have to type the word "foo" three times. >>> >>> Big f**king deal - all things considered. ;) >> >>When this name is a PyObjC name that might be 70 characters long, >>it becomes a big deal. > >PyObjC keeps being mentioned as the poster project for @decorator. Maybe its better idea to store decorators in resource fork ;) Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3 From justin__devine at hotmail.com Mon Aug 30 13:52:41 2004 From: justin__devine at hotmail.com (Justin) Date: 30 Aug 2004 10:52:41 -0700 Subject: "Content-Length" header Message-ID: I have a program that downloads files from the web. There are instances in which a .info() will not return a "Content-length" header to me. Is ther a way to specifically request this header or FORCE it to be sent? I know there is some way to get the file size for these files because Internet Explorer is capable of determining the size on a cut / paste of the same exact url. From __peter__ at web.de Wed Aug 4 13:18:49 2004 From: __peter__ at web.de (Peter Otten) Date: Wed, 04 Aug 2004 19:18:49 +0200 Subject: How to force a single number to be a tuple References: Message-ID: Gandalf wrote: >>y = (2,) >> > Funky. However, very logical. You can also write: >>> () == (,) File "", line 1 () == (,) ^ SyntaxError: invalid syntax >>> (1) == (1,) False >>> (1, 2) == (1, 2,) True >>> Very logical indeed... > Python is the best. :-) Of course, the above not withstanding :-) Peter From t-meyer at ihug.co.nz Mon Aug 2 20:01:39 2004 From: t-meyer at ihug.co.nz (Tony Meyer) Date: Tue, 3 Aug 2004 12:01:39 +1200 Subject: Call for Grant Proposals In-Reply-To: Message-ID: > What you are saying is that all projects should be > open sourced but that may not be the case. Either that or you are > indiscriminately lobbying for the cause of open source irregards of > whether companies are ready for it or not, and then discriminating > against companies who are not ready for it yet. [...] > I will think that it is tyrannic to assume all work must be open > sourced. It seems to me that the idea here is (or might be) that all work benefiting from these grants are open sourced, which is not the same as all work, at all. Given that Python is an open source project, and that the funding for the grant comes from Python users (and some associated open source projects like SpamBayes), this doesn't seem like a reasonable requirement. In fact, it seems that it's a reasonably logical one, one that the people that have contributed the funding would appreciate, and one that would be most likely to advance Python in some way. Given that there is a wide variety of open source licence, and that Python tends towards the least constrictive, it seems even less of a problem. If, for example, a funded project was to create some library for Python, which might help out lots of other users, there would be nothing stopping a closed source project making use of this library. Sure other people could too, but there are always strings attached to grants. > But the wordings and inexactness of this call > for grant proposal makes it hard for me even to get to convince my > people that we should put in an application, not mentioning the > rubber-stamping. Well, it seems to me that the trouble here is really that you haven't managed to hear back officially from the grant committee yet. But, as you probably know, there are always issues that need to be clarified with grants, and especially so with the first time that a grant is offered. Likewise, grant committee are always slow to respond to questions (even those that aren't run by volunteer organisations). =Tony Meyer From npat at efault.net Fri Aug 13 17:07:06 2004 From: npat at efault.net (Nick Patavalis) Date: Fri, 13 Aug 2004 21:07:06 +0000 (UTC) Subject: Why I love python. References: Message-ID: On 2004-08-13, Dave Brueck wrote: > Nick Patavalis wrote: >> >> I also mentioned web-browsers, ray-tracers, circuit-simulators. I >> could add word-processor, spreadsheets, video editing programs, and >> GUI toolkits to the list. Are they still too exotic? > > No - but I still don't think they reflect anywhere near a majority of > the development that goes on. Yes, the majority of development goes on little *glue programs* that take data from a database, and format is as XML/HTML, or aggregate and analyze data stored in a database, and stuff like that. But for all these to be possible a massive amount of *infrastructure* is required. And this infrastructure cannot be created in Python. So you don't say that Python isn't a glue language, but that the greatest percentage of development that currently goes-on *is* glue-stuff development. This of-course presupposes that the infrastructure *is* available, that it is stable, and that it doesn't have to be modified or augmented. For me a "primary" language is not the language in which you develop most of the software, but the language in which you develop the current and future software *infrastructure*. Quantitatively most of the software is glue-stuff anyway! Put yourself in this position: Its a few years ago (say 1998 or 1999), and no graphical web-browser exists for Linux. You are planning to develop the "iso-standard" web-browser for this operating system. Would you do it in Python? Remember that no HTML parsers exist, no decent HTML renderers, the GUI toolkit is more or less primitive, and the low-end desktops runs at about 200-something MHz. You might argue "this is not the case today", but how can you preclude that *similar* challenges do not occur today, or will not occur in the future? Are you saying that all the computationally hard problems have been already solved? Or are you saying that, as a Python programmer you don't want to deal with them? Another example: It's 2004 again, and you decide to scrap and replace the age-old X11 window system; do away with it and start from scratch. Build a moder windowing system; 3D all over, fully network transparent, with widget support on the server-side, fully object oriented interface, and so on. How much of it would you be able to code in Python? How much *more* would you rather be able to code in Python? /npat From edreamleo at charter.net Wed Aug 4 20:11:15 2004 From: edreamleo at charter.net (Edward K. Ream) Date: Wed, 4 Aug 2004 19:11:15 -0500 Subject: Confused about pep 318 References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: <10h2up8825kch2b@corp.supernews.com> > As in many other software efforts, the code has moved along a bit > faster than the documentation (after all, what's more fun to do?). ... > Guido indicated there that he brought up the topic at > EuroPython in his keynote talk and entertained discussion from the floor. > Based upon that discussion he decided to go with the @-decorator syntax. Well, this isn't good. We are talking about a basic design document here. I feel like I have been kept in the dark; my previous relative silence is hardly evidence of my agreement. How is it possible to pretend that people agree with a proposal that DOES NOT EXIST? I am -10 on pep 318 now: this process amounts to a rigged election. I might become neutral in the future once the hood is removed from over the candidate's head :-) > I believe the only significant differences from a pure functional > documentation standpoint to apply to the PEP are the syntax Why is something "spectacular" like the '@' sign is needed? Presumably there is some problem with the compiler? Has anyone suggested something like: from __future__ import annotation as annotate annotate.accepts(int, (int,float)) instead of: @accepts(int, (int,float)) Clearly, with enough work the Python compiler could recognize this. Yes, it's a special case, but so what? This would avoid most problems with reserved words or keywords. And it would be in the spirit of letting modules encapsulate most major features. Edward P.S. The more I think of this proposal, the more unhappy I become. In fact, this proposal may have a most unfortunate effect on Leo's future, for two reasons: 1. Although Leo handles constructs like @accepts, it does so by generating lines like this: #@verbatim @accepts(int, (int,float)) So _Leo_ has no problem, but Leo's users will likely complain that more cruft has been added to their files. 2. Leo presently supports the following directives: @ (followed by one or more whitespace characters) @all, @asis, @c, @code, @color, @comment, @delims, @doc, @encoding, @end_raw, @file, @first, @header, @ignore, @killcolor, @language, @last, @lineending, @nocolor, @noheader, @noref, @nosent, @nowrap, @others, @pagewidth, @path, @quiet, @raw, @root, @root-code, @root-doc, @silent, @tabwidth, @terse, @thin, @unit, @verbose, @wrap Worse, Leo allows plugins to define their own directives. There is already a plugin that defines @wiki. Furthermore, @run, @test and @suite are also used in special contexts. What happens when another Python @x construct conflicts with one of these directives or some other directive? I'm starting to wonder whether Python is a snake or a gorilla :-) Yes, Python does have the right to use '@'. But I would hope that GvR would choose not to do so. I was always under the impression that the clear statement in the Reference Manual that at signs are invalid everywhere (except in comments and strings) was a clear signal of an intention to keep those symbols for other valid purposes. I am extremely unhappy that this may not be so. P.P.S. I did respond earlier to the requested survey, saying in brief that I had no problems with 318 provided that '@' signs did not become a part of the syntax. I have received no reply from anyone. There is no way somebody could construe my previous statements as approval. EKR -------------------------------------------------------------------- Edward K. Ream email: edreamleo at charter.net Leo: Literate Editor with Outlines Leo: http://webpages.charter.net/edreamleo/front.html -------------------------------------------------------------------- From michael at michael.com Tue Aug 10 06:44:12 2004 From: michael at michael.com (michael) Date: Tue, 10 Aug 2004 10:44:12 GMT Subject: How do I get IDLE on Suse Linux 9.x? Message-ID: <0G1Sc.149588$fv.89578@fe2.columbus.rr.com> Hi. I am reasonably experienced with Python (and love it!) on Windows. I am a programmer that toils in c++ on Win 32 mostly but just to learn more, I am playing with Suse 9. Linux. Of course the first thing I tried to fire up was Python. From the command line, I can access Python 2.3 with no problem. I tried to run / search for IDLE which I thought was a standard install on any python installation but it is not present. My question is this: Should I just use a text editor and go without IDLE? Is there another IDE standard on Linux? Do I need to download something to get IDLE? Sorry to ask such a basic question. Michael From mark_bottjer at hotmail.com Thu Aug 12 13:04:43 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Thu, 12 Aug 2004 13:04:43 -0400 Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: References: <60dfb6f6.0408111846.615ee9eb@posting.google.com> <3YWdnYxLf--ObofcRVn-pw@powergate.ca> Message-ID: <411ba32b$1@nntp.zianet.com> Paul McGuire wrote: > Looking at the code, it appears that this is how the current '@' > syntax is defined, that a funcdef is optionally preceded by a > 'decorators' group, consisting of one or more 'decorator' (looking at > both Grammar/Grammar and compile.c). > > So I think this 'technical problem' is just conjecture. (Should > check with Anthony Baxter to confirm.) It looks like they plan on getting around this "problem" by explicitly eating newlines whenever they match the special '@' rule. This solves the look-ahead problem with the parser, albeit in kind of an ugly way. I don't have my source handy, does anything else eat newlines like this? -- Mark From luismg at gmx.net Sun Aug 15 01:26:08 2004 From: luismg at gmx.net (Neuruss) Date: 14 Aug 2004 22:26:08 -0700 Subject: IronPython-0.6 is now available! References: <278de0e.0407281353.27b6a457@posting.google.com> <278de0e.0408100515.5fd3740c@posting.google.com> <278de0e.0408101929.cc3d8c8@posting.google.com> Message-ID: <278de0e.0408142126.49ea45ba@posting.google.com> > > I that were true, no translation should be needed and no benefits of such a > translation be expected. > > But then I'm just a skeptic, don't believe me. Try it. > > Peter Even though IronPython will be fully compatible with trhe CLR, it will still be a dynamic language, with the performance penalty that it represents. So in cases where speed is critical, you'll be able to replace the bottlenecks with c# or other static typed .Net compliant language. However, Jim Hugunin announced that in the future, Ironpython will have optional static typing, theoretically making it as fast as c#. From brian at sweetapp.com Fri Aug 13 06:13:48 2004 From: brian at sweetapp.com (Brian Quinlan) Date: Fri, 13 Aug 2004 12:13:48 +0200 Subject: Why I love python. In-Reply-To: <411C8CD9.32F39C2@mega-nerd.com> References: <411C8CD9.32F39C2@mega-nerd.com> Message-ID: <411C945C.3040603@sweetapp.com> Erik de Castro Lopo wrote: >> def sum (a, b): >> return a + b >> >>How can the compiler know what code to produce? > > > I know of at least one language which has solved this problem, Ocaml > > http://www.ocaml.org/ > > Its called type inferencing and since there is at least one working > implementation, it can't be THAT hard. You are comparing apples and oranges. The programmer provides OCaml with additional information that allows it to interfer the type. Looking at the example above, the OCaml equivalent would be: let sum x,y = x + y;; But this function would only work for integers because the * operator only applies to integers. If you wanted to multipy floats then you would write: let sum x,y = x +. y;; So there is no magic in OCaml, just a different way of providing type information. Cheers, Brian From simoninusa2001 at yahoo.co.uk Sun Aug 22 03:29:50 2004 From: simoninusa2001 at yahoo.co.uk (Simon John) Date: 22 Aug 2004 00:29:50 -0700 Subject: Global config option - import issues again..... In-Reply-To: Message-ID: Been looking at using ConfigParser, which might be worth doing, but still doesn't help me select which .ini/.conf file to parse in the first place. I don't want to set a Registry value for the language to use, and I don't want to have to read/parse the .ini file for each imported module. How do people deal with swapping languages around at runtime? Is anyone going to reply to this thread but me?! ;-) From dave at boost-consulting.com Wed Aug 25 10:46:35 2004 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 25 Aug 2004 10:46:35 -0400 Subject: Unpythonic Python References: <8a638f47.0408240034.653a92ff@posting.google.com> <8a638f47.0408240700.13c39f57@posting.google.com> Message-ID: dave at boost-consulting.com (David Abrahams) writes: > Thomas Heller wrote in message news:... >> dave at boost-consulting.com (David Abrahams) writes: >> >> > I started having some weird problems with Python recently; they're so >> > weird that I can't begin to explain them. All I can do is describe >> > the symptoms and hope someone else has a clue. So here goes: >> > >> > FreeBSD 4.2, Python 2.2.2. >> > >> > I have a nightly cron job that downloads the boost cvs tarball from >> > SourceForge and bunzip2s it. For about a year everything worked with >> > no problems. About a month ago the download started getting truncated >> > with no error reported. >> >> There were some problems with anonymous CVS on sourceforge, which also >> affected the nightly CVS tarballs. Can it have to do with this? >> I also had problems downloading the CVS tarball for ctypes - but it >> seems now repaired. >> >> http://sourceforge.net/docman/display_doc.php?docid=2352&group_id=1#1093021394 > > That's not the problem. I can download the file reliably from other machines. Actually it appears that urllib is having some problem on Unix, at least the one from Python-2.2.x. This fails on Both FreeBSD and Linux: urllib.urlretrieve( 'http://cvs.sourceforge.net/cvstarballs/boost-cvsroot.tar.bz2', 'boost-cvsroot.tar.bz2') Trying again with Python 2.3 on Cygwin. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From po-yung.liu at pandora.be Sun Aug 22 06:17:59 2004 From: po-yung.liu at pandora.be (Vent d'Est - East Wind) Date: Sun, 22 Aug 2004 10:17:59 GMT Subject: 100 % portable ? Message-ID: i have some question about portability of python for my part i work under the 3 systemes (windows , linux , mac os x sometimes mac os classic too ) i want to know how i can be sure at 100 % that my programme is portable (i dont want code each times i use other system ) i suppose for GUI is same wich thing need i pay attention (language , system , library .. ) do you have some graphic library to propose (i see GTK , Tkinter and WXwindow ) thankx in advance for you reply East wind From jfabiani at yolo.com Wed Aug 4 13:14:29 2004 From: jfabiani at yolo.com (John Fabiani) Date: Wed, 04 Aug 2004 17:14:29 GMT Subject: eric3 completion References: <953AD2389idtoken@128.91.2.239> Message-ID: grv wrote: > This is the only IDE that looks very useable on linux of everything I've > looked at (and not to start a dev environment war) but one thing that is > troublesome is the word completion. > > There is a user-contributed script to parse all the dll and py files to > make a list of functions & attributes for each namespace, but it doesn't > pick up some things like file.seek() and datetime.today(). The script > complains that no source files found, yet other built-ins like open() are > picked up. Any guidelines on how to get all the default stuff working for > code completion? I didn't know Eric had any scripts that offered completion. Where can a guy find that script? John From a at b.com Wed Aug 18 03:10:05 2004 From: a at b.com (wonder) Date: Wed, 18 Aug 2004 15:10:05 +0800 Subject: passing the url of the current webpage to python script Message-ID: Dan Greenblatt wrote: > wonder wrote: > >> Hi, >> >> How can I pass the url of the current webpage link to a python script in html? >> >> thanks >> sam > > > are you using a python script as a helper application? yeah, sort of. I m building a html page that will call a python script by passing it the current URL of the webpage. The html page will be opened by any web user with any web browser. thanks sam From abra9823 at mail.usyd.edu.au Sat Aug 28 02:35:30 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Sat, 28 Aug 2004 16:35:30 +1000 Subject: loggin Message-ID: <1093674930.413027b296270@www-mail.usyd.edu.au> hi! in my web app. i log debug messages to a file. however, sometimes the messages appear more than once even though the code in which the log statement appears gets executes only once i have a utilities.py file which defines a getLogger() method as follows logger = logging.getLogger('../logs/umapp') hdlr = logging.FileHandler('../logs/umapp.log') os.system("chmod 755 ../logs/umapp.log") formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') hdlr.setFormatter(formatter) logger.addHandler(hdlr) logger.setLevel(logging.INFO) return logger all my cgi scripts the the start make the call - logger = utilities.getLogger() the scripts then log debug messages during different stages of their execution. however, some of these debug messages appear 2 or 3 times on the log file. i have verified that the particular code block in which the log statement is present is executed only once any ideas thanks cheers ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From anthonybaxter at gmail.com Fri Aug 20 02:19:01 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 20 Aug 2004 16:19:01 +1000 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: On Fri, 20 Aug 2004 06:03:12 GMT, Paul McGuire wrote: > BTW, where are all the votes for option "A"? Where are all the people who > hated it but now like it? Based on what others have said (including Peter Hansen) I was led to believe that the point of this exercise was to collect votes on _alternates_ to the current syntax. In that case, I don't see much point in "voting" for it - particularly since Guido's going to be utterly uninterested in votes. Of the syntaxes proposed on the wiki, the only one I think is worth pursuing is the 'decorate:' block before the def. I just realised I never posted my problems with this form, as I promised. They are: - a new keyword means a 'from future import decorators' for 2.4. (This is, I think, pretty much _required_) - I find the indentation counter-intuitive, but at the same time, necessary for this form. It's abusing indentation-means-new-block. Is that abuse better or worse than the pie-decorator applying to the next line? I don't know. - the choice of 'decorate'/'transform'/something else as the keyword. Please note that this post is _not_ to be considered a vote for, or against, any of the forms. FWIW, since the release of 2.4a2, I've sent something like 200 email messages (including python-list/c.l.py) on the subject of decorators. To say that I'm utterly burned out on the entire issue is something of an understatement. And to repeat a request I made to python-dev - please keep this voting thread in comp.lang.python. Unless you have _new_ technical points to raise, please, please do not flood python-dev with further "I like this" or "I don't like that" posts. From mb at muenster.de Tue Aug 3 14:42:43 2004 From: mb at muenster.de (Martin Bless) Date: Tue, 03 Aug 2004 18:42:43 GMT Subject: Newbie: pywin problem References: Message-ID: <4110dc43.3388296@news.muenster.de> ["Neil Hodgson" ]: >There is a mailing list for Win32 Python issues at >http://mail.python.org/mailman/listinfo/python-win32 That's interesting. Could it be made availabe at news.gmane.org? That would be great. mb - Martin From gk_2345 at yahoo.com Fri Aug 20 09:30:41 2004 From: gk_2345 at yahoo.com (George Kinney) Date: Fri, 20 Aug 2004 09:30:41 -0400 Subject: stopping windows services References: Message-ID: <10ibvqlagd6eg3f@corp.supernews.com> "Bart Nessux" wrote in message news:cg3lgl$eou$1 at solaris.cc.vt.edu... > Can Python be used to stop windows services? I'm writing a script to > automaically remove some troublesome Symantec software, but before > running the main removal script, I need to kill some services. if you know the services name, and are running under an account with sufficient permissions, you could just use the cmd shell. i.e. os.system('net stop Apache2') - kills my apache server, and obviously os.system('net start Apache2') starts it again. Probably a nicer API out there somewhere though. From rhh at structurelabs.com Sun Aug 22 14:55:25 2004 From: rhh at structurelabs.com (r holland) Date: 22 Aug 2004 11:55:25 -0700 Subject: Python is to C as letters are to words. Message-ID: My nine word description of the python language. From martin at v.loewis.de Fri Aug 6 18:46:57 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 07 Aug 2004 00:46:57 +0200 Subject: PEP 263 status check In-Reply-To: <10h7u8m9qknh76e@news.supernews.com> References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> <10h5hgvpafm8a64@news.supernews.com> <41133C76.8040302@v.loewis.de> <10h6rklt3fa1690@news.supernews.com> <41137799.70808@v.loewis.de> <10h724r20kkeqb2@news.supernews.com> <10h7u8m9qknh76e@news.supernews.com> Message-ID: <41140A61.3040600@v.loewis.de> John Roth wrote: > I've > been in this business for close to 40 years, and I'm > quite well aware of backwards compatibility issues > and issues with breaking existing code. > > Programmers in general have a very strong, and > let me repeat that, VERY STRONG assumption > that an 8-bit string contains one byte per character > unless there is a good reason to believe otherwise. You clearly come from a Western business. In CJK languages, people are very aware that characters can have more than one byte. They consider UTF-8 as just another multi-byte encoding, and used to consider it as an encoding that Westerners made to complicate their lifes. That attitude appears to be changing now, but UTF-8 is not a clear winner in the worlds where we Westerners would expect it to be a clear winner. > The current design allows accidental inclusion of > a character that is not in the 7bit ascii subset ***IN > A PROGRAM THAT HAS A UTF-8 CHARACTER > ENCODING DECLARATION*** to break that > assumption without any kind of notice. This is a problem only for the Western world. In the CJK languages, such programs were broken a long time ago. I don't think Python needs to be so Americo-centric as to protect American programmers from programming mistakes. > That in > turn will break all of the assumptions that the string > module and string methods are based on. That in > turn is likely to break lots of existing modules and > cause a lot of debugging time that could be avoided > by proper design. Indeed. If the program is currently not broken, why are you changing the source encoding? If you are trying to support multiple languages, a properly- designed application would use gettext instead of putting non-ASCII into source code. If you are writing a new application, and you put non-ASCII into the source, in UTF-8, are you not testing your application properly? > I'm not worried about this causing people to > abandon Python. I'm more worried about the > current situation causing enough grief that people > will decided that utf-8 source code encoding isn't > worth it. Again, this is what Hallvard's PEP is for. It does not apply to UTF-8 only, but I see no reason why UTF-8 needs to be singled out. > I'll withdraw my objection if you can seriously > assure me that working with raw utf-8 in > 8-bit character string literals is what most programmers > are going to do most of the time. In what time scale? Near time, most people will use other source encodings. In the medium term, I expect Unix will switch to UTF-8 throughout, at which point using UTF-8 byte strings will work on every Unix system - the scripts, by nature, won't work on non-Unix systems, anyway. In the long term, I expect all Python strings will be Unicode strings, unless explicitly declared as byte strings. Regards, Martin From mwh at python.net Wed Aug 18 07:38:11 2004 From: mwh at python.net (Michael Hudson) Date: Wed, 18 Aug 2004 11:38:11 GMT Subject: sys.stdin.read() replacement References: Message-ID: "Ben Last" writes: > import readline will work on Windows: > a) if you're running the cygwin python, inside cygwin > b) if you've installed a readline module; there are at least two available. > Excuse me for the self-referential answer, but about half and hour before I > read this, I wrote a blog entry all about readline modules, with links to > and comments about the Windows ones. The permalink is > http://www.livejournal.com/users/benlast/16766.html or it's the most recent > entry at http://www.livejournal.com/users/benlast/ > > Karin: if you do import a readline, you can then use sys.stdin.readline() to > read a line of input, and you should get some sort of history functionality > (up-arrow, for example, will recall a previous line). Uh, I don't think this is the case; sys.stdin.readline() never uses the readline functionality. Do you mean raw_input()? Cheers, mwh -- 8. A programming language is low level when its programs require attention to the irrelevant. -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html From tismer at stackless.com Fri Aug 6 06:42:41 2004 From: tismer at stackless.com (Christian Tismer) Date: Fri, 06 Aug 2004 12:42:41 +0200 Subject: psyco out of memory In-Reply-To: References: Message-ID: <411360A1.8060607@stackless.com> Michael Hudson wrote: > Ivan Voras writes: > > >>I have this simple *dumb* benchmark-like program: >> >>#import psyco It crashes here, right? I think I know this problem. Armin submitted a patch concerning memory mapping. Upgrading to the current cvs version and building by hand should help. >>#psyco.full() >> >>d = 0.0 >>for i in xrange(1000000000): >> d += i >>print d You need to wrap this into a function, or you will not get accelerated. >>I though I'd use it to try out psyco, but no, when I enable the first >>two lines, python core-dumps: >> >>Fatal Python error: psyco: out of memory >>Abort (core dumped) > > > Hum. Are you using the ivm or the x86 backend? > > Also, you might have better luck just using range()... No, there is no difference using range or xrange, but the fact that your machine will blow up if Psyco is not in place and you try to build a range that huge. That's why I prefer xrange. ciao - chris p.s.: Btw. there has been a bug in Psyco which made the xrange case slower when using Psyco with Stackless. No Stackless bug, simply the case that I do a PyType_Ready() on xrange which standard Python dowsn't, and that inserts a defaul init function that Psyco did not support (until Wednesday) -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From strawman at NOSPAM-DELETE-THIS.astraw.com Tue Aug 10 19:11:10 2004 From: strawman at NOSPAM-DELETE-THIS.astraw.com (Andrew Straw) Date: Tue, 10 Aug 2004 16:11:10 -0700 Subject: floating point exception (SIGFPE weirdness) Message-ID: I'm running into trouble when calling a 3rd party library (the Intel IPP library to do some fast math on a P4 processor). This is on debian linux 2.6.7 using python 2.3.4. I've been using Pyrex to wrap my calls to this C library into an extension module, and a certain function call within my extension module (to the C function ippiAddWeighted_8u32f_C1IR) will terminate my Python program when called for the 2nd time, with the line "Floating point exception" mysteriously appearing on the console. (Mysterious in part because I can't redirect these words with piping stdout or stderr.) I should note that this function calls not only the normal Pentium floating-point machinery, but should also call the SSE and SSE2 instruction sets. A few clues: 1) A trivial C program which makes the same function call repeatedly with the same data is not terminated. 2) Running the python executable under gdb causes the program to continue running without terminating. 3) The behavior (termination) is not changed after rebuilding Python from source, compiling with --with-fpectl and building the fpectl module, calling fpectl.turnoff_sigfpe(). I don't really understand what is happening, but I'd like my code to run without terminating due to this floating point exception. My best guess is that SIGFPE is being generated by the C function call, and Python does not catch it so the OS terminates Python. If this is so, however, I'm not sure why Python should be terminated and why my simple C program is not. Furthermore, I don't understand why gdb doesn't see SIGFPE if this is the case. I would be very grateful if someone could tell me how to keep my program running! Cheers! Andrew From ng01.spamguard at icewater.org Tue Aug 17 15:43:22 2004 From: ng01.spamguard at icewater.org (mike) Date: Tue, 17 Aug 2004 15:43:22 -0400 Subject: favorite python web development tool? Message-ID: <10i4nttktcvltdd@corp.supernews.com> hi all - i'm fairly new to python, coming from a java servlet / velocity template background. i'm looking for a good python web development tool, and hope to find some suggestions here. given my background, webware+cheetah feels comfortingly familiar, and i'm leaning toward it. before i dive in, though, i'm wondering what you experienced users think about it, compared to the other tools that are out there. eg, does the python environment have strengths that are better exploited with something other than a servlet-like model? thanks for your thoughts! -- pssst: ".spamguard" isn't in my real e-mail address. From nzanella at cs.mun.ca Thu Aug 19 13:22:59 2004 From: nzanella at cs.mun.ca (Neil Zanella) Date: 19 Aug 2004 10:22:59 -0700 Subject: staticmethod problems Message-ID: Hello, Coming from C++ and Java, one of the surprising things about Python is that not only class instances (AKA instance objects) but also classes themselves are objects in Python. This means that variabls such as x and y appearing inside class statements in Python essentially behave like static class variables in other languages. On the other hand a variable is specified as an instance variable as self.x and self.y inside a class in Python. Unqualified variables appearing inside the class are class variables and not instance variables. So now what I would like to do, is access the static variable of a superclass object from a subclass object from a static method in the subclass object. Here is what is not clear to me: Why don't the commentd out lines below work? I was expecting that a polymorphic search taking place when I call Y.foo() would find both x and y, but this did not happen. In particular, why does python force me to write something like I write in foo3() to enforce the behavior I want in foo()? Thanks, Neil #!/usr/bin/python class X: x = 10 class Y(X): y = 5 def foo(): print x + y foo = staticmethod(foo) def foo2(): print X.x + y foo2 = staticmethod(foo2) def foo3(): print X.x + Y.y foo3= staticmethod(foo3) #Y.foo() # I was expecting the same behavior as below, # with the value 15 printed. Why is this not # working (and where can I find more about # staticmethod)? #Y.foo2() # doesn't work either. Why? Y.foo3() # works print Y.x # Since the object.attribute notation is used # polymorphism is used to locate attribute x. # Since class object Y does not contain x the # immediate parent X is searched and x found # therein. Finally the value of x is printed. class XA: x = 10 class YA(XA): def foo(self): print self.x YA().foo() # Since the object.attribute notation is used # polymorphism is used to locate attribute foo() # which is not found in instance object YA() so # class object YA is searched next and foo() is # found therein and run. # # Once run the object.attribute notation is used # to locate x which is not found in instance object # self (AKA YA()) so class object YA is searched and # since x is not found there either the immediate parent # class object XA in the inheritance hierarchy is searched # and attribute x is found therein. # # Once the x is found the object it references is printed. From nicoe at no-log.org Thu Aug 19 07:50:25 2004 From: nicoe at no-log.org (Nicolas =?iso-8859-15?Q?=C9vrard?=) Date: Thu, 19 Aug 2004 13:50:25 +0200 Subject: age of Python programmers In-Reply-To: <2ojheuFb9j2eU1@uni-berlin.de> References: <2ojheuFb9j2eU1@uni-berlin.de> Message-ID: <20040819115025.GG4327@smarties.nutellux.ath.cx> * Oliver Fromme [13:32 19/08/04 CEST]: >Lucas Raab wrote: > > One thing I've always kind of wondered is what is the average age of a > > Python programmer?? What age groups use Python?? Something to think > > about.... > >I'm 00100001b (or 021h ... or if you prefer decimal, it's >33 years). Although I feel more like 27, which is the age >of my GF. :-) Well if everybody feels like the age of his GF/BF, I'm 75 although I'm only 27. -- (?> Nicolas ?vrard / ) Li?ge - Belgique ^^ From npat at efault.net Thu Aug 12 22:09:13 2004 From: npat at efault.net (Nick Patavalis) Date: Fri, 13 Aug 2004 02:09:13 +0000 (UTC) Subject: Why I love python. References: <10ho7626f5f3f74@news.supernews.com> Message-ID: On 2004-08-13, John Roth wrote: > > "Nick Patavalis" wrote in message > news:slrncho5aq.pfh.npat at gray.efault.net... >> On 2004-08-13, Michael Scarlett wrote: >> >> Python needs drastic performance improvement if it is to scrap-off the >> "scripting language" stigma. > > More performance would be helpful. There are a number > of projects that are working toward that end, of which > the most visible is the PyPy project. Yes, I know about PyPy, and I think what they are trying to do is write Python itself in a Python-subset that can be efficiently compiled, or something along these lines. This is interesting (to say the least). > > As far as I'm aware, the biggest current performance > sink is function and method call overhead [...] > > Another thing to notice is the garbage collection > algorithm [...] Both very true! > >> The only way to get these improvements is >> making it possible for a python implementation >> to produce *efficient* *compiled* code. > > I think there are lots of people that would dispute > you on that. Current Java environments run close > to C++ performance due to the JIT compilers > that are built into the runtimes. You 're right, I was maybe a bit too dogmatic on my point. But you must accept that JIT-compilers are, nevertheless, compilers! They may be more intelligent and more flexible than traditional "ahead of time" compilers, but still they are fundamentally compilers. Furthermore, for most cases, it might be possible for an AOT compiler to produce a "binary" that doesn't contain the compiler itself. > Current JIT technology doesn't require pre-declaration of variable > types; it's perfectly happy to insert checks at appropriate points > so that it can reuse code when the object types don't change (which > they don't most of the time.) What you mean I guess, is that the first time a function is applied, it is compiled to native-code, and a signature for the application is generated. The next time, the application is checked against the signature and if they match, the existing code is used, otherwise the function is re-compiled (preserving the previously compiled one too, is some sort of "cache"). Or am I getting it wrong? Even in such a case though per-declarations would help. Do you happen to know of any efforts to build such "AOT"/"JIT" compilation/execution environments for Python? Regards /npat From loic at fejoz.net Tue Aug 3 08:37:53 2004 From: loic at fejoz.net (Yermat) Date: Tue, 03 Aug 2004 14:37:53 +0200 Subject: automatic delegation In-Reply-To: References: Message-ID: Hallvard B Furuseth wrote: > Is it possible to write a metaclass or something so that > with a class definition not much larger than this: > > class foo: > def __init__(self, val): self.val = val > > operations on a foo instance f will be applied to f.val? > E.g. str(f) -> f.__str__() -> f.val.__str__(). > Here a simple example : class proxy(object): def __init__(self, obj): self.obj = obj def __getattr__(self, key): if key in self.__dict__: return self.__dict__[key] else: return getattr(self.obj, key) You can also look at: http://www.python.org/cgi-bin/moinmoin/ProxyProgramming -- Yermat From kraus at hagen-partner.de Fri Aug 27 10:43:40 2004 From: kraus at hagen-partner.de (Wolfram Kraus) Date: Fri, 27 Aug 2004 16:43:40 +0200 Subject: allowing braces around suites In-Reply-To: References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> Message-ID: Thomas Heller wrote: > Aaron Bingham writes: [...] >>Or C-M-\ to re-indent the region "correctly" with respect to its >>context. This works far more reliably the using TAB to re-indent >>single lines. > > > How do you enter that on a german keyboard? > > Thomas CTRL-ALT-ALTGR-? Wolfram From paolo.veronelli at yahoo.it Tue Aug 17 03:29:25 2004 From: paolo.veronelli at yahoo.it (User Paolino) Date: Tue, 17 Aug 2004 09:29:25 +0200 Subject: python packages cross references In-Reply-To: <2D89F6C4A80FA547BF5D5B8FDDD04523060CBB@exchange.adrembi.com> References: <2D89F6C4A80FA547BF5D5B8FDDD04523060CBB@exchange.adrembi.com> Message-ID: <4121B3D5.6050404@yahoo.it> Roman Yakovenko wrote: > Hi. I need help( or solution :-) ). > Problem: my project has 3 packages > prj > +------A > +------B > +------Utils > > The question is: what is the right way to use functionality from Utils in A and B packages ? > I know that after importing package I know it's location, but it doesn't help me in any module within package A or B. > I can add full path to prj to sys.path but it seems to be the wrong way. > May be I missed something? Adding fullpath is IMO even hacking than make symlinks in the directories which has been my workaround. My question still remains :why can't I walk back in directories ('packaged') whit from/import statements? Regards Paolino From ptmcg at austin.rr._bogus_.com Thu Aug 5 00:25:13 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Thu, 05 Aug 2004 04:25:13 GMT Subject: Decorator syntax References: <38ednYT1NLz1P4zcRVn-uA@powergate.ca> Message-ID: "Peter Hansen" wrote in message news:38ednYT1NLz1P4zcRVn-uA at powergate.ca... > For the record, the @ syntax is despicable and horribly > un-Pythonic, IMHO, and I really hope never to read code that > uses it. :-( > > (And my preferred syntax was "def f() [classmethod]:", FWIW) > Agreed. And I also like your preferred syntax - clear, readable, no eye-jarring symbols. The references to Java and C# as justification or rationale for using @ remind me of when I lived in Maine. When I complained about how bad the drivers were, inevitably the response was "we're not as bad as the drivers in Massachusetts!" If this was some impulsive lurch forward to just pick something and proceed, I think we are seeing another backtick in the making. I fear that $, ^ and ~ are just around the corner. -- Paul From anthonybaxter at gmail.com Thu Aug 5 13:38:45 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 03:38:45 +1000 Subject: Confused about pep 318 In-Reply-To: References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: On Thu, 05 Aug 2004 13:29:29 -0400, Peter Hansen wrote: > I'll make another donation to PSF if the final decorator syntax > does not Perlishly use arbitrary punctuation as the @ syntax does. FFS. What exactly is "Perlish" about @? It's an unused symbol. That's all. It's hardly arbitrary - Java, for instance, already uses @ for the same thing. From john.burton at jbmail.com Mon Aug 16 05:56:30 2004 From: john.burton at jbmail.com (john.burton at jbmail.com) Date: 16 Aug 2004 02:56:30 -0700 Subject: Windows URL protocol handler in python? Message-ID: Is there a way to make a handler in python presumably using the win32 extensions to handle URLS of a specific type when they are given to windows? For example if I want to handle myprotocol://server/id using my own python program? Any suggestions or references would be appreciated. From fperez528 at yahoo.com Mon Aug 16 02:17:27 2004 From: fperez528 at yahoo.com (Fernando Perez) Date: Mon, 16 Aug 2004 00:17:27 -0600 Subject: Anyone use VPython? References: <8f17f4bc.0408141932.46b7c405@posting.google.com> Message-ID: Peter Hansen wrote: > Ali wrote: > >> Anyone use VPython? > > Noting the question, the first two responses you got, and > your subsequent question, I suggest you would benefit > from reading this short essay before posting again: > > http://www.catb.org/~esr/faqs/smart-questions.html Note to the original poster: before you think Peter is being arrogant or a smartass, please realize that's probably the single most useful answer you'll ever get to a question on the internet. And yes, I've actually read that document once or twice in the past, carefully. So don't react badly, take his advice, read that document, make sure you understand it, and try again. I'm sure you'll find the result worth every minute of effort spent. Otherwise you'll continue to get correct answers like you have so far to your questions. Correct, but perfectly useless (because the questions were worded _begging_ for useless answers). best, f From insert at spam.here Fri Aug 20 10:50:18 2004 From: insert at spam.here (Doug Holton) Date: Fri, 20 Aug 2004 09:50:18 -0500 Subject: just ignore Guido's "rejections" [Re: Alternative decorator syntax decision] In-Reply-To: References: Message-ID: <2uadnbqpMuI1krvcRVn-sg@comcast.com> > Anthony Baxter wrote: >> This form (decorators inside the block) has been pretty convincingly >> ruled out by Guido. I think the "last man standing" is the >> decorator-before-def >> form, I really doubt you're going to convince people that the form >> inside the >> function is workable. We can safely ignore Guido's "rejections" when deciding upon an alternative to agree upon. Many people felt his rejections of C1 (a longtime community favorite), E1 and other alternatives were wrong. http://mail.python.org/pipermail/python-dev/2004-August/048134.html From ronaldoussoren at mac.com Fri Aug 13 07:30:57 2004 From: ronaldoussoren at mac.com (Ronald Oussoren) Date: Fri, 13 Aug 2004 13:30:57 +0200 Subject: PEP318 In-Reply-To: <0I2D001ZDU03UQ@mta9.srv.hcvlny.cv.net> References: <0I2D001ZDU03UQ@mta9.srv.hcvlny.cv.net> Message-ID: <3EC2EFCA-ED1C-11D8-9E11-000D93AD379E@mac.com> On 13-aug-04, at 13:17, Arthur wrote: > >> On Thu, 12 Aug 2004 17:03:19 GMT, Arthur >> wrote: >>>> def foo (): >>>> whatever >>>> foo = decorator (foo) >>>> >>>> is that you have to type the word "foo" three times. >>> >>> Big f**king deal - all things considered. ;) >> >> When this name is a PyObjC name that might be 70 characters long, >> it becomes a big deal. > > I had asked this before: > > Does > > def __f(something): > dosomething > > the_name_I_really_want_to_call=transform(__f) > > work? > > It is not a destructive transform of __f, but why is that important? This requires additional input if you want to have the correct __name__ attribute for the function. In your example 'transform' cannot no that the result will be bound to 'the_name_I_really_want_to_call'. In PyObjC I use the __name__ to deduce information about the function (such as the Objective-C name for the function). Another problem is that you only know the "real" name for the function some time after the function definition. > > What else am I missing? > > I thought I read the PyObjC folks saying that they saw use cases for a > decorator syntax for their project - to be sure - but that was > (mis)interpreted as meaning that they saw it as important for their > project, > which they don't. > > I could be wrong in my interpretation here. Decorators would make live a lot easier for us, but not having decorators won't kill PyObjC. I would like to have decorators, but not at every cost. The @decorator-before-def proposal looks sane. Ronald From fperez528 at yahoo.com Wed Aug 25 13:05:22 2004 From: fperez528 at yahoo.com (Fernando Perez) Date: Wed, 25 Aug 2004 11:05:22 -0600 Subject: Call for signatories for J2 References: Message-ID: Robert Brewer wrote: > The J2 proposal is as complete as it will ever be. > > http://www.aminus.org/rbre/python/pydec.html > > The patch is nearly complete; only the __future__ declaration and some > document tweaks remain. It should be updated on SourceForge today or > tomorrow. > > This is a call for all who wish to sign the proposal, either for, > against, or abstaining. Please sign by either posting on > comp.lang.python (replying to this is fine) My signature : FOR My Name: Fernando Perez. Regular email: fperez AT colorado DOT edu I am the author of IPython, one of the affected tools by the @proposal; IPython was referenced in the J2 paper. So I guess this is my 'official' stance on the matter. I like it for 2 reasons: a) It will save me a bunch of silly work changing ipython (especially the docs), and it will save my ipython users having to change their work habits. b) I just like it; I think the paper authors did a fantastic job justifying the idea with a set of very coherent reasons. By now it's clear no syntax will be deemed 'perfect' by everyone, but I found the arguments in the proposal clear, intelligent and convincing enough to be happy going along. Thanks to those who were willing to put enough effort to turn a potential disaster for the language into a rational and productive discussion. Best, f From peter at engcorp.com Mon Aug 9 09:12:14 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 09 Aug 2004 09:12:14 -0400 Subject: Exceptions as a Control Structure In-Reply-To: <411775aa$0$17867$626a14ce@news.free.fr> References: <411775aa$0$17867$626a14ce@news.free.fr> Message-ID: Olivier Parisy wrote: > I am new to Python (I just finished Guido's tutorial). > I was very surprised to learn there that the StopIteration > is used to end for loops in a standard iterator setting. > > I come from C++, where the use of exceptions as control > structures is frowned upon for efficiency reasons. In Python, very little is frowned upon solely for efficiency reasons. There are some examples, including using += repeatedly to grow a string, and some fields where efficiency is of course critical, but in Python one almost always looks for the most pragmatic approach (which is often the most elegant, too, for some people's definition of elegant) rather than obsessing about speed. > What is the Python canon on this topic ? The only Python "canon" can be found by typing "import this" at the interpreter prompt. ;-) > Are exceptions > considered as reasonable control structures, or is > StopIteration alone of its kind ? Catching an exception is considered a reasonable approach to flow control for various problems. One, for example, is in deeply nested loops, where rather than going out of one's way to avoid exceptions in favour of a flag and lots of awkward testing, one just raises a custom exception (or perhaps a standard one) and catches it outside the loops. Exceptions are also used by some as a mechanism for returning information from subroutines, though it's very likely the information will still be considered "exceptional" in some way (think of it as an out-of-band mechanism for returning special info). While some people object on stylistic grounds (or even performance ones, in some cases) to such things, you will likely find that exceptions are thrown around by Python programmers more readily than you are used to. Note also that in many cases other than algorithmic complexity, what you have learned about efficiency in C++ should be considered suspect info when it comes to Python. Function calls, for example, are much more expensive in Python than in C++ because of the time required to set up the call frame. Exceptions, on the other hand, are as I recall much more efficient. Some Google Group searches in c.l.p would probably lead to many past discussions of these things. -Peter From elbertlev at hotmail.com Mon Aug 9 09:42:59 2004 From: elbertlev at hotmail.com (Elbert Lev) Date: 9 Aug 2004 06:42:59 -0700 Subject: Komodo, debugging and multi-threading References: Message-ID: <9418be08.0408090542.37e9113@posting.google.com> Thomas Lindgaard wrote in message news:... > Hello > > I have a multi-threaded web spider and it has a problem (probably > several). Is there a way to make the debugger show me what my worker > threads are doing? I can only get it to follow the main thread. I'm using > Komodo Personal (trial). No! Komodo, IDE, IDLE all are wrappers for pdb.py, which does not allow to set a brakpoint in thereads (it allows, but does not stop). You can try it for yourself (using command line interpreter). The only way of debugging multithreaded programs - print (or log). From python-url at phaseit.net Tue Aug 17 21:08:06 2004 From: python-url at phaseit.net (Peter Otten) Date: Wed, 18 Aug 2004 01:08:06 GMT Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 18) Message-ID: QOTW "Implementations are always preferred over rhetoric." - Robert Brewer "The programmers you'll be able to hire to work on a Java project won't be as smart as the ones you could get to work on a project written in Python." - Paul Graham http://www.paulgraham.com/gh.html Colin J. Williams shows Mizrandir how to subclass numarray's arrays. http://groups.google.com/groups?threadm=df3955c3.0408140908.1b9bfb63%40posting.google.com Hoang Do receives various suggestions how to drop into the interpreter from a running script. http://groups.google.com/groups?threadm=mailman.1679.1092569474.5135.python-list%40python.org Kyle Root asks for help arranging a dependency tree of Python modules and receives both theoretical background information on the problem and code implementing a "topological sort". http://groups.google.com/groups?threadm=6ccff37a.0408111831.6eb25a4e%40posting.google.com Timothy Fitz starts a discussion of the differences between Python's generators (an overwhelming success) and coroutines. http://groups.google.com/groups?threadm=972ec5bd.0408141032.385fe115%40posting.google.com Fazer learns that he has competition in the area of scripts that retrieve weather forecasts from the web. http://groups.google.com/groups?threadm=6491b0ab.0408121917.5103b770%40posting.google.com Coming from a C++ background, Olivier Parisy feels uneasy with the use of exceptions to control program flow in non-exceptional situations. Peter Hansen and several others tell him not to worry. http://groups.google.com/groups?threadm=411775aa%240%2417867%24626a14ce%40news.free.fr Roman Suzi has a clear vision of Python 3.0's design process in 2015. http://groups.google.com/groups?selm=mailman.1672.1092553249.5135.python-list%40python.org We resist all urges to say more about decorators or white space. ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous 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 newsgroup weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Brett Cannon continues the marvelous tradition established by Andrew Kuchling and Michael Hudson of intelligently summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Business Forum "further[s] the interests of companies that base their business on ... Python." http://www.python-in-business.org The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donate.html Cetus collects Python hyperlinks. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://aspn.activestate.com/ASPN/Cookbook/Python Among several Python-oriented RSS/RDF feeds available are http://www.python.org/channews.rdf http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi http://python.de/backend.php For more, see http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. *Py: the Journal of the Python Language* http://www.pyzine.com Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. From grante at visi.com Mon Aug 23 23:56:03 2004 From: grante at visi.com (Grant Edwards) Date: 24 Aug 2004 03:56:03 GMT Subject: % format strings References: <144d0df.0408231455.6b664466@posting.google.com> <412A76A7.4C87D17C@alcyone.com> <537ea4cd.0408231919.4ada3ca1@posting.google.com> Message-ID: <412abc53$0$8076$a1866201@newsreader.visi.com> On 2004-08-24, ziller wrote: > I meant to say how does it translate the *. Python lets you use a > variable to specify the length of precision. > > int f_length = 5; > float fl = 3.5 > printf("%.*f", f_length, fl); > > doesn't compile. Of course not. It's not valid C. The following compiles just fine: #include int f_length = 5; float fl = 3.5; void foo(void) { printf("%.*f",f_length, fl); } Not sure why you're asking C questions in c.l.p... -- Grant Edwards grante Yow! Excuse me, but didn't at I tell you there's NO HOPE visi.com for the survival of OFFSET PRINTING? From daniel at syrinx.net Fri Aug 13 08:04:38 2004 From: daniel at syrinx.net (Daniel Ellison) Date: Fri, 13 Aug 2004 08:04:38 -0400 Subject: Flython? In-Reply-To: References: Message-ID: <2o3ovjF6apnoU1@uni-berlin.de> Peter Hansen wrote: > Christopher T King wrote: > >> On Thu, 12 Aug 2004, Peter Hansen wrote: >> >> >>> In the vein of Jython, I wonder what it would take to build >>> a Flython? (Lousy name, I know.) That would take Python >>> source, presumably a subset since some things couldn't be supported, >>> and compile it into ActionScript bytecode (aka the bytecode compiled >>> from ECMAScript source for the Macromedia Flash player environment). >> >> >> I don't know much about ActionScript bytecode, but I think a general >> Python -> ECMAScript translator wouldn't be too hard (presuming a Python >> subset is acceptable). ECMAScript variables are untyped, so that should >> ease translation some. Sounds like my weekend project! > > > Well, it's not the source code that I care about, it's the > object code (as in, the Flash bytecode). The only ECMAScript > to Flash bytecode compilers of which I'm aware are > commercial and expensive, and come with big useless (to me) > GUI/animation/freaky special effect generation systems... > > There are advantages in Python direct to Flash bytecode with > a simple command line compiler (particularly if one uses > test-driven development...). > > This may be where I have to dig into an area that's outside > my expertise, namely the compiler.py module, parse trees, > and code generation... > > -Peter I have to agree that Python compiled to swf bytecode would be very handy indeed. I'm no fan of HTML-based web applications, but there are currently few alternatives. Flash could be an excellent alternative, but few developers want to take the time to learn (and purchase!) the Flash authoring application to create a better web GUI. I *like* "Flython" as a name! :) A flying python! I can see the logo now... Dan Ellison From ajsiegel at optonline.com Fri Aug 20 11:10:52 2004 From: ajsiegel at optonline.com (Arthur) Date: Fri, 20 Aug 2004 15:10:52 GMT Subject: PEP 318: Can't we all just get along? References: Message-ID: <3e4ci0tcavl5qe34l9bak2h1bl2hmqaqb6@4ax.com> On Fri, 20 Aug 2004 05:45:11 -0400, Paul Morrow wrote: >Roy Smith wrote: >> >> I never quite understood the point of static methods inside classes. >> When would you ever need to do that, as opposed to just a function in a >> module? In Java's "everything is part of a class" philosophy, it makes >> sense, but in Python? > >It gives us another means of managing namespaces. Rather than having to >create a top-level function in the current (or some other) module, we >can group it with other related functions as a method in a class. "Another" means Precisely. It is not, however, the embedded means. And though the language provides this flexibility, one pays a small penalty. Some typing and a loss of readibility/elegance - whatever you might want to call it. Heh. The trade-offs are clear and the decision is in the hands o f the developer. Which is kinda typical of the kinds of decision one expects to face, as a developer. No? What, again , is the problem? Art From John.Marshall at ec.gc.ca Wed Aug 11 11:16:57 2004 From: John.Marshall at ec.gc.ca (John Marshall) Date: 11 Aug 2004 15:16:57 +0000 Subject: A decorator syntax not yet mentioned (I think!) Message-ID: <1092237417.22674.12.camel@mango.cmc.ec.gc.ca> How about the following, which I am almost positive has not been suggested: ----- class Klass: def __init__(self, name): self.name = name deco meth0: staticmethod def meth0(x): return x deco meth1: classmethod def meth1(cls): return cls deco sayhello: funcattrs(name='GvR', language='python') log(file='func.log') def sayhello(self): print 'hello python world' ----- 1) The decorators clearly apply to a specific method/function, therefore there is no need to do any stack pushing in memory until the method/function definition is done. 2) The decorators are "outside" of the method/function they decorate: a) which will please those who want the outside location b) will not be folded within the function c) folding on the decorators can be done so that the def is not obfuscated d) can be located anywhere in the code--but most likely before the "def ...()" 3) The sequence in which the decorators are applied is just like code would be--this is certainly intuitive given that we are writing code. This approach could also be applied to classes in case decorators should ever be extended to them: ----- deco Klass: doc("This is a class to ...") class Klass: : : ----- Any comments? John From mattduke at ugcs.caltech.edu Fri Aug 27 14:00:44 2004 From: mattduke at ugcs.caltech.edu (Matt Doucleff) Date: 27 Aug 2004 11:00:44 -0700 Subject: tarfile's tar.extractfile() file-like object incompatible with pickle.load()? References: <3e6d6c21.0408261043.264c3a2d@posting.google.com> <1093572564.733113@news.commspeed.net> Message-ID: <3e6d6c21.0408271000.6007a361@posting.google.com> "Tom B." wrote in message news:<1093572564.733113 at news.commspeed.net>... > "Matt Doucleff" wrote in message > news:3e6d6c21.0408261043.264c3a2d at posting.google.com... > > Hi everyone! I must be doing something wrong here :) I have a > > tarball that contains a single file whose contents are a pickled > > object. I would like to unpickle the object directly from the tarball > > using the file-like object provided by extractfile(). Attempts to do > > this result in EOFError. However if I first extract to a temporary > > file, then unpickle from there, it works. The below code reproduces > > the problem (on my machine at least). I'm running Python 2.3.4, > > manually installed on Debian Woody (original python removed). Thanks! > > > > This sample code creates (and then removes) files in the tmp directory > > and in the current working directory. > > > > # demonstrates extractfile/unpickle failure (bug?) > > > > # pickle a dict to a temp file > > # create tar file, add temp file to it, close tar file > > # open tar file for reading > > # obtain file-like object for pickled file using extractfile() > > # attempt to unpickle dict from file-like object > > # fails with EOFError exception > > > > import tarfile > > import pickle > > import tempfile > > import os > > > > if __name__ == '__main__': > > try: > > hashtopickle = { 'a' : 1, 'b' : 2 } > > > > # pickle to temp file > > (fd, tmpfilename) = tempfile.mkstemp() > > tmpfile = os.fdopen(fd, 'w') > > pickle.dump(hashtopickle, tmpfile) > > tmpfile.close() > > > > # create tar; add temp file > > tar = tarfile.open('tarpickle.tar', 'w') > > tar.add(tmpfilename, 'pickledhash') > > tar.close() > > > > # remove temp file > > os.remove(tmpfilename) > > > > # open tarfile for reading, get filelike > > tar = tarfile.open('tarpickle.tar', 'r') > > filelike = tar.extractfile('pickledhash') > > > > # fails > > hashcopy = pickle.load(filelike) > > > > finally: > > # cleanup > > os.remove('tarpickle.tar') > > It occurs to me that you need to do, > > hashcopy = pickle.loads(filelike) > > if filelike is a string. > > Tom > P.S. have a look at pickle.dumps() The tarfile.extractfile() method does not read the contents of the encapsulated file into a string, but constructs a new object that implements file operations (it is like a file) and is intended to be used as if you had simply opened the tar-encapsulated file directly. Matt From donn at u.washington.edu Mon Aug 9 17:00:50 2004 From: donn at u.washington.edu (Donn Cave) Date: Mon, 09 Aug 2004 14:00:50 -0700 Subject: os.system prob References: Message-ID: In article , Aaron Barclay wrote: > I am trying to send some commands via os.system but am getting tripped > up by it stripping out the quote marks. I have: Quoting can be tricky, when you have multiple layers of interpretation - python, shell, etc. You can probably figure it out with some experimentation, but if possible it's better to avoid the problem. Use os.spawnv - like, os.spawnv(os.P_WAIT, '/usr/local/bin/whatever', ['whatever', 'parameter one']) This invokes the command directly, so there's no shell command line parsing. Donn Cave, donn at u.washington.edu From newsgroups at jhrothjr.com Wed Aug 11 08:31:53 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Wed, 11 Aug 2004 08:31:53 -0400 Subject: Getting the docstring of a property References: Message-ID: <10hk4dhcaftsgcf@news.supernews.com> "Andrew Durdin" wrote in message news:mailman.1493.1092226382.5135.python-list at python.org... > How do you get the docstring of a property? Suppose I have the following: > > class Foo: > def _prop_get(self): > return 1 > prop = property(_prop_get, doc="This is the docstring") > > foo = Foo() > print foo.prop > print foo.prop.__doc__ > > This will display "1", followed by the docstring for an integer (which > is the docstring for the int() function). How can I get the property's > docstring as defined in the property() function? You tried to access it from the instance. However, accessing it from the instance invoked the property, returning 1, before it attempted to access the docstring. You need to get it from the class. That is: Foo.prop.__doc__ should do what you want. John Roth From konsumer at toughtechs.com Mon Aug 23 12:20:17 2004 From: konsumer at toughtechs.com (David Konsumer) Date: Mon, 23 Aug 2004 09:20:17 -0700 Subject: Class or Modules? Message-ID: <1093278017.19803.19.camel@gir> I'm writing a game to learn more about python, and I've done a little bit of programming in puthon so far, that were very small projects (single source file) shell scripts, little gui's, and the like. Now that I'm working on something larger, I'm not sure how to go about it. My question is: Which should I use for multiple source files in a large project, classes or modules? Here is an example of my sturcture main input video input and video need to get/set data from the others that needs to be persistant (like if I set video.x in main or video, input needs to see it the same way) and run functions from the others. So the way I tried to achieve this uses classes (which I'm fairly sure is BAD, it just doesn't seem right) was this: import input,video,events,gui,gameplay,player class main: def __init(self)__: input=input.Input(self) video=video.Video(self) (more like that) and then in other files: class input: def __init__(self,engine): self.engine=engine class Video: def __init__(self,engine): self.engine=engine (more like that) Is there a better way to do this? From lbates at swamisoft.com Mon Aug 23 15:09:15 2004 From: lbates at swamisoft.com (Larry Bates) Date: Mon, 23 Aug 2004 14:09:15 -0500 Subject: function taking scalar or list argument References: <412a2bce$1_1@127.0.0.1> Message-ID: <9ZCdnT9EuudK3bfcRVn-tA@comcast.com> You may want to take a look at isinstance() function. def twice(x): if isinstance(x, list): return map(twice, x) if isinstance(x, (int, float, str)): return 2*x return None print twice(3) # 6 print twice([1,4,9]) # [2,8,18] print twice('*') HTH, Larry Bates Syscon, Inc. "beliavsky at aol.com" wrote in message news:412a2bce$1_1 at 127.0.0.1... > > I can define a function that transforms either a scalar or each element in > a list as follows: > > def twice(x): > try: > return map(twice,x) > except: > return 2*x > > print twice(3) # 6 > print twice([1,4,9]) # [2,8,18] > > Is this good style? I intend to define many functions like this and want > to use the right method. Thanks. > > > > ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- > http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups > ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--- From aleaxit at yahoo.com Sat Aug 28 06:15:24 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 28 Aug 2004 12:15:24 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1ry8k0d2az.fsf@rovereto.ifi.uio.no> <10iv0kid2ig9ka6@corp.supernews.com> <1rpt5ccbso.fsf@rovereto.ifi.uio.no> <10ivpk9inpnh65@corp.supernews.com> <1rd61bd26k.fsf@rovereto.ifi.uio.no> Message-ID: <1gj892g.1hlc8ar1po78b6N%aleaxit@yahoo.com> Kjetil Torgrim Homme wrote: ... > code I read can be using "#fi", "# end if", "# }", "pass" or nothing. > sure, I can write a tool to enforce a single coding standard for my > project, but external code will naturally not comply. that's why I ... > my hope is that my solution can be ignored by those who don't need it, > and used by those who like it. Unfortunately, if you make it optional, "external code will naturally not comply" still applies. Either for your solution or for any of those you list above, you need in any case a simple tool that will take noncomplying (but otherwise assumed to be correct) code and insert the terminators. Given that you need this tool, why not also have the tool able to CHECK that a module complies? This way you don't need to change Python to give a syntax error for non compliance. Best of all, the hypothetical tool almost exists, you have it: ...whereveryoukeeppython.../Tools/scripts/pindent.py It uses the '# end if' style, but you could alter that in your copy. The 'almost' is because I don't think it has the 'just check and tell me if something wrong' functionality -- it's just able to insert or remove the terminators into/from an otherwise correct source, and to fix up indents in a source file which has proper terminators -- from the latter, a switch to have it just check shouldn't be hard to add (exit with error indicator if any fixup would be needed, say). Once you have scripts that do whatever checking you wish and have a uniform specified way to signal errors, you could think of a general and truly useful addition to Python: a commandline switch (ideally settable as a sys. attribute at runtime too) that makes it run checking scripts automatically as part of the compilation process when it imports any source (.py) file. This would put pay to the problem common to all "offline" checkers -- "the checker would have diagnosed the problem but I did not run it". You could run pindent, pychecker, unit tests, _whatever_ -- possibly at the price of slowing down imports of newly edited sources, but that depends on how thoroughly you want to check, only. What we need, I think, are good conventions to determine what to run on the source (before compilation), what on the bytecode (right after compilation, or possibly even, every time, even when importing a bytecode .pyc file), how a checker lets Python know about problems, how Python in turn diagnoses them to the user. Hmmm -- I'm thinking that the existing import hooks might be enough to let one prototype this "automatic checking" functionality, not quite as smoothly as a fully architected system maybe, but enough to get some early adopters, shake out teething problems, build a constituency to lobby for smoother integration in a future Python version... Alex From Andreas.Ames at tenovis.com Mon Aug 9 13:02:18 2004 From: Andreas.Ames at tenovis.com (Ames Andreas (MPA/DF)) Date: Mon, 9 Aug 2004 19:02:18 +0200 Subject: Queue qsize = unreliable? Message-ID: <788E231C269961418F38D3E360D1652526CA22@tndefr-ws00021.tenovis.corp.lan> Dave Brueck wrote: > But is it blocking in any way that you (the caller) will likely > notice? (probably not - the mutex is held for a relatively short How I notice a blocking function? 1) As a programmer: I have to read the docs and unfortunately all too often the code. 2) As a "caller": I'm wasting time when blocking without a reason. > period of time. Note also that the mutex that gets acquired is not > the "main" mutex of the Queue.) In CVS it acquires the only lock that is there, in the 2.3 version and below it acquires the mutex, that I'd call the "main" one, just after checking (by a non-blocking acquiration of esema) if the Queue is empty. >> With CPython's assertions about atomicity of certain list >> operations it's possible to implement a lock free queue that is >> even usable for the single producer or single consumer case. > > If you have the single producer and/or single consumer case, you > don't need a Queue at all - just use a built-in list (or in 2.4 a > collections.deque object). I think I didn't make my point clear enough. The most important word in the above paragraph was "usable", which means more to me than just thread-safe. I'd be interested in a usable (i. e. non-polling) implementation of a queue without any locks. >> if !q.empty(): >> reliableCode() >> else >> unreliableCode() >> should be absolutely okay. > > It'd probably _work_, yes, but would it offer any real advantage? On > that particular mutex, there's almost never any contention at all - > *especially* in e.g. the single consumer case. And, even if there is > some contention, it is acquired for an extremely short amount of > time (relatively speaking) - which is why the caller is not likely > to notice that any locking is going on under the covers. The cost of > having both reliableCode and unreliableCode paths seems to outweigh > any potential advantage IMO. I just included the "else" branch to make clear that only one of empty's two possible outcomes is reliable. It makes much more sense and it is much closer to my specific application to write: while !q.empty(): doSomethingToTheWorkersOutput() When leaving this loop I'll go back to sleep on select. As to the "extremely short amount of time (relatively speaking)": I'm still very impressed by Dan Kegel's c10k paper. And following that one I'm not so much concerned about the amount of time that a producer may hold the lock (that time may very well be ignorable), when the single consumer tries to acquire it, but much more about the fact that it potentially needs at least *two* context switches per iteration until the one thread that feeds all others and thus that all others depend upon gets back to work. cheers, andreas From DrColombes at yahoo.com Tue Aug 17 12:29:11 2004 From: DrColombes at yahoo.com (Dr. Colombes) Date: 17 Aug 2004 09:29:11 -0700 Subject: Plotting over MapPoint maps Message-ID: Can anyone offer pointers, suggestions on how to overlay coordinate (Lat, Long)-based MatPlotLib graphics over a MapPoint map ? Thank you for your help. From simoninusa2001 at yahoo.co.uk Wed Aug 18 14:52:20 2004 From: simoninusa2001 at yahoo.co.uk (simo) Date: 18 Aug 2004 11:52:20 -0700 Subject: age of Python programmers References: Message-ID: <30260531.0408181052.31bc054b@posting.google.com> 26, been Python'ing for 2 years or so. Started programming at about 7 with BBC BASIC IV From manuelbastioniNOSPAM at tin.it Sun Aug 29 11:10:44 2004 From: manuelbastioniNOSPAM at tin.it (manuel) Date: Sun, 29 Aug 2004 15:10:44 GMT Subject: possible python bug here Message-ID: In the sample below, the foo function modify the b list, but I think it should modify only c, not b! It work correctly if if b is one dimension list instead two. def foo(aList): print "use foo..." aList[2][0] += .35 aList[2][1] += .35 aList[2][2] += .35 p = [2.5,2.5,2.5] b = [p,p,p,p] c=b[:] #c is a totally new list cloned from b, it's not an alias! print "b = ",b[2] foo(c) #The argument is c, not b! Why b is modified too? print "b = ", b[2]# after foo(c), the list b now is different! From gj_carman at hotmail.com Sat Aug 28 16:47:07 2004 From: gj_carman at hotmail.com (George Carman) Date: Sat, 28 Aug 2004 13:47:07 -0700 Subject: IDLE does not start on WinXP Message-ID: Please excuse the following mailing, I do not have access to a news server and cannot post to comp.lang.python. I recently installed Python 2.3.4 on WinXP. Command line interpreter works fine but the IDLE GUI will not start. When run from a commandline I get the following traceback. Both WinXP and McAfee firewalls are disabled. Any suggestions would be appreciated. C:\Python23\Lib\idlelib>idle.py Traceback (most recent call last): File "C:\Python23\Lib\idlelib\idle.py", line 23, in ? idlelib.PyShell.main() File "C:\Python23\lib\idlelib\PyShell.py", line 1282, in main flist.pyshell = PyShell(flist) File "C:\Python23\lib\idlelib\PyShell.py", line 764, in __init__ self.interp.start_subprocess() File "C:\Python23\lib\idlelib\PyShell.py", line 364, in start_subprocess self.transfer_path() File "C:\Python23\lib\idlelib\PyShell.py", line 433, in transfer_path self.runcommand("""if 1: File "C:\Python23\lib\idlelib\PyShell.py", line 650, in runcommand self.rpcclt.remotequeue("exec", "runcode", (code,), {}) File "C:\Python23\lib\idlelib\rpc.py", line 214, in remotequeue return self.asyncreturn(seq) File "C:\Python23\lib\idlelib\rpc.py", line 238, in asyncreturn response = self.getresponse(seq, wait=0.05) File "C:\Python23\lib\idlelib\rpc.py", line 278, in getresponse response = self._getresponse(myseq, wait) File "C:\Python23\lib\idlelib\rpc.py", line 298, in _getresponse response = self.pollresponse(myseq, wait) File "C:\Python23\lib\idlelib\rpc.py", line 423, in pollresponse message = self.pollmessage(wait) File "C:\Python23\lib\idlelib\rpc.py", line 375, in pollmessage packet = self.pollpacket(wait) File "C:\Python23\lib\idlelib\rpc.py", line 347, in pollpacket if not self.ioready(wait): File "C:\Python23\lib\idlelib\rpc.py", line 337, in ioready r, w, x = select.select([self.sock.fileno()], [], [], wait) select.error: (10022, 'An invalid argument was supplied') _________________________________________________________________ Don?t just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/ From xtian at toysinabag.com Mon Aug 9 00:41:06 2004 From: xtian at toysinabag.com (xtian) Date: 8 Aug 2004 21:41:06 -0700 Subject: Does python support multi prototype. References: <2natmnFv86rjU1@uni-berlin.de> Message-ID: Matteo Dell'Amico wrote in message news:... > angel wrote: > > Java and cpp support one function name multi function prototype. > [...] > > Does python support it? > > Not natively, but - if you really need them - there are modules that > make them possible. > > Have a look at > http://gnosis.cx/publish/programming/charming_python_b12.html , and > maybe at > http://codespeak.net/pypy/index.cgi?doc/objspace/multimethod.html too. One thing to note is that these Lisp-ish multimethods are more powerful than Java- or C#-style method overloading, because the method dispatch is done at runtime using the actual types of the arguments. In Java and C# overload selection is done at compile time, so if you've got, frex: public class Thing { public void DoSomething(Integer val) { ... } public void DoSomething(String val) { ... } public void DoSomething(Object val) { ... } } [and then] Object o = "fish"; Thing t = new Thing(); t.DoSomething(o); ... you'll always get the object version of DoSomething called, because the declared type of o is Object. Which always annoyed me. xtian From abra9823 at mail.usyd.edu.au Sun Aug 15 10:04:18 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Mon, 16 Aug 2004 00:04:18 +1000 Subject: xml namespace error Message-ID: <1092578658.411f6d62099aa@www-mail.usyd.edu.au> hi! i have the following code to create a a document ssock = StringIO.StringIO(inputString) reader = Sax2.Reader() doc = reader.fromStream(ssock) input string simply contains when i run it, it throws a namespace error. i can understand where the error is coming from (i haven't defined the namespace), but is there a way to get past it? to get it to ignore the namespace? the same thing in Java works fine (without worrying about the namespace). thanks cheers ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From andy at andybak.net Tue Aug 3 07:26:15 2004 From: andy at andybak.net (Andy Baker) Date: Tue, 3 Aug 2004 12:26:15 +0100 Subject: Reasoning behind nested scope Message-ID: <20040803112624.2CCBD1E4002@bag.python.org> Hi there, I'm learning Python at the moment and trying to grok the thinking behind it's scoping and nesting rules. I was googling for nested functions and found this Guido quote: (http://www.python.org/search/hypermail/python-1993/0343.html) "This is because nested function definitions don't have access to the local variables of the surrounding block -- only to the globals of the containing module. This is done so that lookup of globals doesn't have to walk a chain of dictionaries -- as in C, there are just two nested scopes: locals and globals (and beyond this, built-ins). Therefore, nested functions have only a limited use. This was a deliberate decision, based upon experience with languages allowing arbitraries nesting such as Pascal and both Algols -- code with too many nested scopes is about as readable as code with too many GOTOs. And, of course, in Python, the "proper" way is to use an object-oriented programming style" This sounds reasonable to me although nested scope always struck me as more natural and intuitive ('Don't be surprising') I was wondering how the balance changed in favour of nested scope? What changed people's minds about 'readability' vs other factors? Are nested scopes still regarded as leading to spagetti code etc? (On a side note is there any way to call a nested function from outside the parent? I was kind of expecting nested functions to be addressable through dot notation like methods are but I can see why that wouldn't be quite right. This might be a better question for the tutor list...) Andy Baker From charlie at iwec.com Thu Aug 19 12:45:49 2004 From: charlie at iwec.com (Charlie Taylor) Date: Thu, 19 Aug 2004 09:45:49 -0700 Subject: python cgi speedup on iis Message-ID: I'm looking for advice on how to speed up python cgi on Windows IIS without going to an application server like Zope/WebWare/CherryPy/etc (i.e. I have existing cgi scripts). mod_python seems like a good solution for Apache, is there something comparable for IIS? I notice that ASP scripts run an asp.dll which I believe becomes memory resident to speed up VBScript execution. Is there any work on a python.dll anywhere? Thanks, ct From davZZZYYYXXXout at dial.pipex.com Wed Aug 4 13:25:37 2004 From: davZZZYYYXXXout at dial.pipex.com (davout) Date: Wed, 4 Aug 2004 18:25:37 +0100 Subject: web resources to explain why Python is best? Message-ID: <41111c24$0$26982$cc9e4d1f@news.dial.pipex.com> Can anybody point me at some web resources that explain why Python is better than Perl, TCL, Ruby etc? From peter at engcorp.com Mon Aug 16 10:07:25 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 10:07:25 -0400 Subject: Knowing a COMObject by IID In-Reply-To: References: Message-ID: <8tSdnYPuvsYDIr3cRVn-vA@powergate.ca> Mauro Baraldi wrote: > Someone can helpe-me how to get the name of a COMObject by it CLSID. > > Example: > A object got a number CLSID ({CA8A9783-280D-11CF-A24D-444553540000}). > It name is Acrobat Control for ActiveX. > > Or where can I found a good reference for this... The most direct method is to use "regedit" to search for it in your registry. You can find it under HKEY_CLASSES_ROOT\CLSID and the name will be under the default key for the entry. But I suspect you wanted to do this programmatically... and I don't know the API you would use. -Peter From russelllear at earthlink.net Fri Aug 20 11:55:09 2004 From: russelllear at earthlink.net (Russell Lear) Date: Fri, 20 Aug 2004 15:55:09 GMT Subject: Access to Oracle References: Message-ID: I'm using cx_Oracle on Windows XP to communicate with 9i. Works quite nicely. One nice thing is that, by being careful with the design (esp. the SQL generation), I'm able to bring the application to a PostgreSQL machine running Linux and things still work! But that's a little off-topic. Russell. From yaoroland07 at yahoo.com Thu Aug 19 11:03:06 2004 From: yaoroland07 at yahoo.com (Roland) Date: 19 Aug 2004 08:03:06 -0700 Subject: Tkinter Message-ID: <8e16829.0408190703.1c6845d7@posting.google.com> Salut, J'utilise LNUX RedHat 9.0 et je n'arrive pas ? utilser Tkinter car ? chaque fois que j'essaye de faire executer un code dans lequel j'ai import? le module Tkinter, j'obtient: from tkinter import* ImportError: No module named tkinter . Je croyais que ce module ?tait int?gr? ? python. AIDEZ-MOI Merci From avner at skilldesign.com Wed Aug 25 13:43:07 2004 From: avner at skilldesign.com (Avner Ben) Date: Wed, 25 Aug 2004 19:43:07 +0200 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: <412cc31c$1@news.012.net.il> I believe putting the decorator list before the function header is generally a bad design decision. While it may make parsing-related sense, it violates Python's greatest asset: being executable pseudocode. The way I see it, the latter quality means being able to look at the code and see clearly and immediately what requirements from the real world the code was written the serve. Functions and methods are major code entities that are naturally expected to represent discrete functional requirements from the code, to this or that level of detail. I expect to learn from the method name, the class it is in and the list of arguments it takes, everything I need to know about the functional requirement it implements. If that is not enough, I will look at the docstring, if present. Everything else the method has to offer is conveniently hidden below. Decorators of the type discussed recently - with the exception of staticmethod and classmethod - are technical detail of the kind I would like to see hidden below. Putting them on top, prior to the what the method does (its name etc.) compromises the design quality of the code, reducing it to yet another abbreviation-based, self-centered technical scripting language. The one esception I saw was J2, which, although putting the decorators before the proper method header, uses indentation to state "this is an extra piece of technicality which you are free to ignore - the def is below." My vote: C2, E4, J2 Avner. From pm_mon at yahoo.com Wed Aug 25 07:20:17 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Wed, 25 Aug 2004 07:20:17 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> Message-ID: Steven Bethard wrote: > Paul Morrow yahoo.com> writes: > >>I believe that (virtually) all __xxx__ attributes have this metadata >>aspect (semantics) to them. When a programmer says >> >> def foo(): >> __author__ = 'Wilma Flintstone' >> __version__ = '0.1' >> >>She does not intend for __author__ nor __version__ to be local variables >>of foo, used somehow by foo in the calculation of its return value. To >>her they are foo /metadata/ --- attributes of the foo object itself --- >>as they contain information that *describes* foo. > > > I assume you mean that this is what you'd like a programmer to intend? If I > wrote that, I would intend (and expect) __author__ to be a local variable. > I'm not saying that I couldn't be retrained. I'm just saying that right now, > I would not expect it to be otherwise. > What I mean is that this is what (I believe) veteran Python programmers always intend, because it's a Python convention (although I've never actually seen it described quite like this --- as metadata). Here's what PEP 8 (http://www.python.org/peps/pep-0008.html) has to say about __xxx__ attributes: __double_leading_and_trailing_underscore__: "magic" objects or attributes that live in user-controlled namespaces, e.g. __init__, __import__ or __file__. Sometimes these are defined by the user to trigger certain magic behavior (e.g. operator overloading); sometimes these are inserted by the infrastructure for its own use or for debugging purposes. Since the infrastructure (loosely defined as the Python interpreter and the standard library) may decide to grow its list of magic attributes in future versions, user code should generally refrain from using this convention for its own use. User code that aspires to become part of the infrastructure could combine this with a short prefix inside the underscores, e.g. __bobo_magic_attr__. Here's a link that gives some examples of them: http://cardboard.nu/blog/2003_09_18/module_level_magic_variables.html) Sure veterans know that if it looks like a local variable definition, then it is one. But my point is that (IMO) they don't normally rely on that aspect of __xxx__ variables. You'll almost never see a function that examines its own metadata in the computation of its result. > >>Likewise, when she defines __lt__, __getitem__, __init__, etc. as part >>of a class, they will not typically be called by methods of the class or >>users/consumers/clients of the class [*] the way that 'normal' >>attributes will. They contain meta info that describes a deeper level >>of class behavior. > > > This seems a little misleading to me. The only reason these methods are > special is because they override operators (something like "<", "[]", and "()" > respectively). You could provide a class with /exactly/ the same > functionality without ever implementing any of these methods. (Well, minus > __init__, but that was a special case in your discussion too.) The only thing > that implementing these methods does is allows your user to access these > methods through an operator shorthand. A simple example: > > class Identity: > def get(self, x): > return x > __getitem__ = get > > How is __getitem__ any more "metadata" then get is? They provide exactly the > same functionality. The __getitem__ declaration just allows you to access the > get method using "[...]". > Well, but that's a big difference. __getitem__ has a much deeper meaning than your 'get'. Defining it actually changes which syntax you're allowed to use on instances of your class. Now you can do things like... ident = Identity() print "%(alpha)s, %(beta)s, %(gamma)s" % ident > Are you trying to say that "metadata" is the same thing as "operator shortcut"? > Not exactly, but it would include defining those. One way to think about metadata is that it includes all information *about* an object, but no information *used by* the object. If we were to have a conversation about this conversation, then we would be having a "meta-conversation." /metadata/ is data that describes data. metadata for a function would be data that describes the function; data *about* the function as opposed to data *used by* the function. For example: def circumference(diameter): """ This is a docstring. It's metadata for this function. """ __author__ = 'Paul Morrow' # more metadata pi = 3.14 # not metadata return pi * diameter Paul From olli at haluter.fromme.com Mon Aug 23 10:27:21 2004 From: olli at haluter.fromme.com (Oliver Fromme) Date: 23 Aug 2004 14:27:21 GMT Subject: age of Python programmers References: Message-ID: <2oud69Fer8aiU1@uni-berlin.de> Peter Hansen wrote: > Bryan wrote: > > i'm 37... started programing on a TRS-80 Model I and III. i also did a > > bit a programming on a VIC-20... brownie points for anyone who can > > remember how many text characters there was in one row... > > 23! ... freakin' weird little machine that was... :-) It was 22 characters per row, and 23 rows on the screen. The little thing didn't even have a graphics mode, though you could fake it by modifying the pixel definition of the character set. I used to have a VIC-20 with a 40 Kbyte (not Mbyte) memory extension. Those 40 Kbyte costed 200 DEM at that time; roughly 100 $US. I don't dare to calculate the price factor relative to today's RAM modules ... Of course, I used the built-in BASIC, and very soon also used 6502 machine code. Yes, machine code, no assembly language, not even a hex monitor. I wrote the instructions on paper, then looked up the opcodes in a 6502 CPU table, then converted the hex/binary numbers back to decimal and entered them into BASIC "data" statements. If the CPU hung when running it, reboot (which took only 2 seconds) and re-check the paper work ... Oh joy. I could go on writing memories for hours, but I'll stop here because it's completely off-topic already. :-) Now, 20 years later, Python is my language of choice. If it just supported strong typing, it would be perfect. Best regards Oliver -- Oliver Fromme, Konrad-Celtis-Str. 72, 81369 Munich, Germany ``All that we see or seem is just a dream within a dream.'' (E. A. Poe) From nicksjacobson at yahoo.com Wed Aug 25 16:07:20 2004 From: nicksjacobson at yahoo.com (Nick Jacobson) Date: 25 Aug 2004 13:07:20 -0700 Subject: Enumerate object is destroyed by casting? Message-ID: Casting an 'enumerate' object destroys it?? Is that supposed to happen, or is it a bug? For example: a = ['a', 'b', 'c'] e = enumerate(a) print dict(e) print dict(e) Result: {0: 'a', 1: 'b', 2: 'c'} {} From jeff at ccvcorp.com Thu Aug 19 15:54:29 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Thu, 19 Aug 2004 12:54:29 -0700 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: <10ia1a9jm9tkuca@corp.supernews.com> Paul McGuire wrote: >I think special thanks are due to: >- Anthony Baxter for his continuing efforts in this regard >- Steven Bethard for some of the clearest thinking and writing on this topic >- Michael Sparks for actually implementing one of the options > > I'd definitely second these special thanks. >I would propose a multivote survey: each poster gets 3 votes among the >lettered choices on the Wiki page above. You can use all 3 for a single >option, or split them across 2 or 3 options if you are open to more than >one. > > This seems like a fairly reasonable way of at least getting an estimation of concensus. I'd also suggest that, if there's a large number of votes distributed between minor variations on a theme (i.e. they differ as to what character/keyword to use), that might be considered as a sum. If, for example, E1 and E2 are the second and third most popular choices, with a total that's higher than that of the most popular choice, it seems reasonable to me to consider them to be the "winner" and to then discuss which character is preferred. This is hard to codify, however, as some of the numbered variants are significantly different while others are only slightly different... My votes: J2 J2 E2 Jeff Shannon Technician/Programmer Credit International From anthonybaxter at gmail.com Fri Aug 6 00:10:12 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 14:10:12 +1000 Subject: Confused about pep 318 In-Reply-To: References: <10h2ihgb8c6fi97@corp.supernews.com> <10h4vhcfbsv6t30@corp.supernews.com> Message-ID: On 5 Aug 2004 23:43:29 -0400, Aahz wrote: > Also, there has historically been an expectation that PEPs will be > posted to comp.lang.python in their final draft form; That's news to me, although I think it's probably a good idea. > while I agree with > you that python-dev is a public forum, I think the outrage expressed by > those who believed that they didn't *NEED* to monitor python-dev is > entirely understandable. I'm not sure what additional benefits would have come from some more advance notice of this to c.l.py, in addition to python-list. I don't think the outrage would have been any less from the people who _really_ don't like the feature. The folks who just don't think decorators belong in the language, in any form, can hardly have missed the frequent mentions in Brett's python-dev summaries. Additionally, anyone who has a great alternative still has time to get their idea in instead of the @syntax. If anything, the availability of the current form in a released (alpha) of Python makes it easier for people to actually play with it and see what they think - this is something that's much harder to do from a proposal. From jimcser at pacifier.com Tue Aug 17 15:52:29 2004 From: jimcser at pacifier.com (Jim Cser) Date: Tue, 17 Aug 2004 12:52:29 -0700 Subject: Numarray: Using sum() within functions In-Reply-To: References: <10hsvoka533ci3c@corp.supernews.com> Message-ID: <10i4ofuc7dp3571@corp.supernews.com> >>I have a function to generate a multi-dimensional array, which then >>gets summed over one axis. The problem is that the dimensions >>are large, and I run out of memory when I create the entire array, >>so I'm trying to do the sum *within* the function. >> >>Example-- variables x,y,z,t; dimensions numX, numY, numZ, numT; >>functions f1(x,y,z,t), f2(y,z,t); want to calculate f1*f2 and >>sum over t to get out[x,y,z]. > Cobbling together a number of suggestions, what finally worked was-- def f3(x, y, z, t_range=arange(numT)): tempval = 0.* x for t in t_range: tempval += f1(x,y,z,t) + f2(y,z,t) return tempval out = fromfunction(f3,(numX,numY,numZ,1)) I couldn't quite get sum() to work inside the function, but this is definitely good enough for now. Thanks to all for your help. -Jim Cser [wrong identity on last post, sorry] From peter.maas at mplusr.de Thu Aug 19 07:50:03 2004 From: peter.maas at mplusr.de (Peter Maas) Date: Thu, 19 Aug 2004 13:50:03 +0200 Subject: age of Python programmers In-Reply-To: References: Message-ID: Aahz schrieb: > Ville Vainio wrote: > >>I'm also optimistic about retiring with Python, because *everyone* is >>going to retire with Python in 2044 :-). > > > 2038 It took slightly more than a decade to get rid of 16bit machines. I don't think that anybody will use 32bit in more than 30 years. 64bit rollover point is in 292,277,026,596. That really ought to be enough for everybody :) Mit freundlichen Gruessen, Peter Maas -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- From godoy at ieee.org Sun Aug 29 15:26:51 2004 From: godoy at ieee.org (Jorge Godoy) Date: Sun, 29 Aug 2004 16:26:51 -0300 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <1LMXc.67190$UTP.37420@twister01.bloor.is.net.cable.rogers.com> <1gj7a9r.g7ec5a1g89rj0N%aleaxit@yahoo.com> Message-ID: Just writes: > The zipimport module will never write to the zip archive, so for most > efficient imports, you have to store .pyc data in there yourself. > zipimport is mostly meant as a repackaging tool, and typical zip files > only contain .pyc files. They aren't created even outside of the zip archive, this is what I meant ;-) -- Godoy. From tim.peters at gmail.com Mon Aug 9 00:01:17 2004 From: tim.peters at gmail.com (Tim Peters) Date: Mon, 9 Aug 2004 00:01:17 -0400 Subject: MSI Installer issues In-Reply-To: <4114A02F.7060906@v.loewis.de> References: <411231C8.3020308@interlink.com.au> <411241F5.3080602@v.loewis.de> <1f7befae040805103911610582@mail.gmail.com> <411274C0.4070300@v.loewis.de> <1f7befae04080623276089908e@mail.gmail.com> <4114A02F.7060906@v.loewis.de> Message-ID: <1f7befae040808210137f08a9e@mail.gmail.com> [Martin v. L?wis] > ... > While I have your attention: you have commented that the installer logo > needs attribution, during the installation process. Is this still the > case, and what is the text I should use? Any other attribution that > needs to be made? Its creator (Erik van Blokland) asked for attribution, in return for doing the work. All I know is here: http://mail.python.org/pipermail/python-dev/2004-July/046317.html He seemed happy with the attribution quoted there. > A colleague has commented that logo is too low-res, is ugly, and does > not feature reptiles. Should we look for an update to the logo? I'm surprised this didn't trigger a flood of responses dwarfing the decorators thread! I'm out of any logo debate. "low-res" may be a feature, as some people have very low screen resolution settings and very large fonts. Etc, etc. If you want the quest to end, don't ask Guido to approve a new logo <0.9 wink>. From sridharinfinity at gmail.com Tue Aug 3 20:47:00 2004 From: sridharinfinity at gmail.com (Sridhar R) Date: 3 Aug 2004 17:47:00 -0700 Subject: guide to introspecting python? In-Reply-To: Message-ID: > What's a good document to read in order to > understand some of python's introspective functions? Read http://diveintopython.org Also see 'Python in a nutshell'. Understand the python type system, metaclassess ... Looking at the source code, helped me. From mlh at furu.idi.ntnu.no Mon Aug 23 16:38:13 2004 From: mlh at furu.idi.ntnu.no (Magnus Lie Hetland) Date: Mon, 23 Aug 2004 20:38:13 +0000 (UTC) Subject: Standard graph API? References: Message-ID: In article , David Eppstein wrote: >In article , > mlh at furu.idi.ntnu.no (Magnus Lie Hetland) wrote: > >> Yes, we have the standard ways of implementing graphs through (e.g.) >> dicts mapping nodes to neighbor-sets, but if one wants a graph that's >> implemented in some other way, this may not be the most convenient >> (or abstract) interface to emulate. > >Actually, my interpretation of this standard way is as a fairly abstract >interface, rather than a specific instantiation such as dict-of-sets: >Most of the time, I merely require that iter(G) produces a sequence of >the vertices of graph G, and iter(G[v]) produces a sequence of neighbors >of vertex v. I also sometimes use "v in G" and "w in G[v]" to test >existence of vertices or edges. Yes, I agree, to some extent. I guess the problems start when you want to manipulate the graph. I think it would be nice to be able to use an empty graph object to build a given graph without knowing the implementation. I guess you could do that in this implementation too (if all the neighbor sets were initialized). But if this does turn out to be an acceptable API, I'm all for it. I just think it would be nice to have a Recommended Standard(tm), to create interoperability. [snip] >- It doesn't provide an abstract way of changing the graph (although >that's relatively easy if G is e.g. a dict of sets) Right. >- It doesn't directly represent multigraphs Unless you insist on having neighbor-sets, it does, doesn't it? Neighbor-lists can be used for this...? [snip] -- Magnus Lie Hetland "Canned Bread: The greatest thing since sliced http://hetland.org bread!" [from a can in Spongebob Squarepants] From tdelaney at avaya.com Sun Aug 15 20:30:54 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Mon, 16 Aug 2004 10:30:54 +1000 Subject: Why I love python. Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01CF4915@au3010avexu1.global.avaya.com> Nick Patavalis wrote: > On 2004-08-13, kosh wrote: >> >> I don't want my cell phone to run python, java, ruby, c# etc etc. I >> want it to just be a telephone and do that job well. >> > > I understand. You want a nice analog cell-phone, with a large rotary > dial, and very long cord. Sorry but resistors, capacitors, and diodes > can only go that far. For everything else you need large clusters of > transistors (integrated-ccircuits they are called by some) and a lot > of them need (God forbid!) "software". I just had the same discussion on Friday with some co-workers. However, they didn't take *quite* the same idiotic point of view as you have. What I want (and can't seem to find anymore) are mobile phones that fit in the hand *comfortably*, have easy-to-use keypads (so the chance of hitting the wrong key is minimal), good reception anywhere there's any kind of signal, high battery life and usually good SMS support (i.e. intelligent look-ahead dictionary). I'm still using a Nokia 3210 because it meets most of my criteria, and doesn't have extras that get in the way of using it as a mobile phone (fortunately, I was able to get a new battery at a fairly low price). I want to get a new phone, but all the ones currently available miss out on the comfort and ease of use criteria, which to me are the two most important. I know plenty of people who have the same desires - a tool that does it's job well, and doesn't try to do lots of additional jobs poorly. Tim Delaney From Ian.Sparks at etrials.com Tue Aug 31 09:54:17 2004 From: Ian.Sparks at etrials.com (Ian Sparks) Date: Tue, 31 Aug 2004 09:54:17 -0400 Subject: Splitting a list Message-ID: <41A1CBC76FDECC42B67946519C6677A9018C2F6B@pippin.int.etrials.com> string.split() is very useful, but what if I want to split a list of integers on some element value? e.g. : >> l = [1,2,3,-1,4,5,-1,8,9] >> l.split(-1) >> [[1,2,3],[4,5],[8,9]] Here's my hideous first pass : >> [[int(z) for z in x.split(',') if z] for x in ','.join([str(a) for a in l]).split('-1')] >> [[1, 2, 3], [4, 5], [8, 9]] When I see code like that I just know I've missed something obvious.... From cjw at sympatico.ca Mon Aug 23 07:33:55 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Mon, 23 Aug 2004 07:33:55 -0400 Subject: J2 paper 0.2.1 In-Reply-To: References: Message-ID: Congratulations. This is an impressive piece of work, done in a short time. I prefer this proposal to the existing implementation. I hope that someone will prepare as thoughful a piece on one of the C options. I would prefer C2 with uses as the keyword. Since the 'decorator' is a modifier, it would make better sense for the modification to come after one has identified what is to be modified. One nit picking comment on Robert Brewer's document: An annotation is a transformation of a function, as a change to the flow of control is. Colin W. Robert Brewer wrote: > The first draft of the J2 proposal is ready. You can read it here: > http://www.aminus.org/rbre/python/pydec.html > > At this point, I am looking for comments regarding the proposal. Once I > believe I have addressed a sufficient number of concerns, I will freeze > the document and call for signatories, both for and against, then send > it to Guido. Until that time, expect the draft to change multiple times > each day (there's a meta tag with the version number if you care to > check). > > In this thread, please do not introduce discussions regarding syntaxes > other than J2 and A1. Limit your comments to the three arguments, > literary critique, and praise for Mr. Sparks who is providing the > implementation. Oh, and somebody let me know if you rampaging lot crush > my little server. ;) > > > Robert Brewer > MIS > Amor Ministries > fumanchu at amor.org From eurleif at ecritters.biz Sun Aug 29 09:22:00 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sun, 29 Aug 2004 09:22:00 -0400 Subject: Get all subdirs In-Reply-To: References: Message-ID: <2pe3bnFji0a9U1@uni-berlin.de> Florian Lindner wrote: > how can I get all subdirectories of a given directory >>> import os >>> def subdirs(dir): ... return [filename for filename in os.listdir(dir) ... if os.path.isdir(os.path.join(dir, filename))] ... >>> subdirs('.') ['foo', 'bar', 'baz'] From has.temp2 at virgin.net Thu Aug 12 08:16:04 2004 From: has.temp2 at virgin.net (has) Date: 12 Aug 2004 05:16:04 -0700 Subject: Python script to generate static site? References: Message-ID: <69cbbef2.0408120416.b2e7ab4@posting.google.com> Fred wrote in message news:... > I'd just like a script that would > 1. look in a directory for articles in raw HTML, > 2. generate a cooked output for each page (ie. add header and footer, > CSS link in HEAD, etc.), > 3. regenerate the homepage with "Last modified" bit following each > article's title, > 4. ready to be uploaded by FTP to a web server that only handles > static web pages. This should be close to what you want: . (See .) To add 'last modified' dates, replace the second-last line of write_docs.py with: import time index = '
    \n%s
' % ''.join(['\t
  • %s %s
  • \n' % (href, name, time.strftime('(last modified: %I:%M:%S %p on %Y-%m-%d)', time.localtime(os.stat(src + href).st_mtime))) for name, href in chapterNames]) From apardon at forel.vub.ac.be Fri Aug 27 11:17:53 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 27 Aug 2004 15:17:53 GMT Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> Message-ID: Op 2004-08-27, Anthony Baxter schreef : > On Fri, 27 Aug 2004 14:55:26 +0200, Kjetil Torgrim Homme >> thank you for the reference! I'm happy to see that Guido wasn't >> strictly opposed to such a feature 10 years ago. > > Regardless of what he thought back then, I think I can say with > absolutely no fear of contradiction that there is no chance in hell of > braces appearing in Python... ever. > > If your tool gets something wrong, fix the tool, don't try and change > the language, just for the convenience of a broken tool. Well people do make mistakes and it would be helpfull if the language provides some feautures to help in repairing those mistakes. It has happend that through some faulty manipulations code that came after a loop became indented at the same level as the loop. Because python has no end-markers that meant it wasn't obvious to spot where the loop was supposed to stop and from where I had to start deindenting the code. Now of course I can remedy this situation by using comments like #end, #if etc. That will make it obvious to correct such mistakes. However I think one could argue that providing such endmarkers helps readability as much as indenting code does and since that is the principal argument for the enforced indentation, one could consider the case for endmarkers. -- Antoon Pardon From skip at pobox.com Thu Aug 5 22:16:00 2004 From: skip at pobox.com (Skip Montanaro) Date: Thu, 5 Aug 2004 21:16:00 -0500 Subject: Confused about pep 318 In-Reply-To: References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: <16658.59872.760007.271839@montanaro.dyndns.org> Bengt> I too am very much against wasting '@' on @decorator! We could just switch completely to Unicode. Then we'd have all sorts of punctuation characters available. How about # -*- coding: utf-8 -*- \xe2\x98\xbadecorator def f(): pass ? Skip From fumanchu at amor.org Wed Aug 25 10:39:47 2004 From: fumanchu at amor.org (Robert Brewer) Date: Wed, 25 Aug 2004 07:39:47 -0700 Subject: python bytecodes by hand Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E6B@exchange.hqamor.amorhq.net> Maurice LING wrote: > I am just wondering about the structure of a pyc (python > bytecode) file > and has anyone successfully write a functional pyc file by hand? Yes, they have. Although, generally, you either: 1) write a program to generate the bytecode for you in some non-standard way, or 2) declare a similar target in Python, grab its bytecode, and tweak it as needed. Google for "Python bytecode hack". Robert Brewer MIS Amor Ministries fumanchu at amor.org From arambo314 at hotmail.com Thu Aug 26 22:41:14 2004 From: arambo314 at hotmail.com (Arthur Rambo) Date: 26 Aug 2004 19:41:14 -0700 Subject: How to generically transform a list? References: Message-ID: <533e1e03.0408261841.27f1ab5f@posting.google.com> As simple as theList=[['a',1,11,'aa'], ['b',2,22,'bb'],['c',3,33,'cc']] returnList=[2,1] newList=[[item[index] for index in returnList] for item in theList] Python rules... > Suppose you have a list of lists: > > theList = [['a',1,11,'aa'], ['b',2,22,'bb'],['c',3,33,'cc']] > > I would like to have a GENERIC way how to turn this list of list into > another list of list. > - A user can choose which columns she wants > - A user can select the order of the columns > > For example: > The user wants columns: 1,2 > The user wants it to be ordered: 2,1 > > A non generic approach would maybe do the following: > > >>> theList = [['a',1,11,'aa'], ['b',2,22,'bb'],['c',3,33,'cc']] > >>> new_list = [[row[2], row[1]] for row in theList] > >>> new_list > [[11, 1], [22, 2], [33, 3]] > > I am sure there must be a rather elegant generic approach, which is > lurking somewhere to be realeased. > > Thanks for any hint in advance, > Marco From zathras at thwackety.com Sun Aug 15 11:22:58 2004 From: zathras at thwackety.com (Michael Sparks) Date: Sun, 15 Aug 2004 16:22:58 +0100 (BST) Subject: Generators versus Coroutines In-Reply-To: Message-ID: On Sun, 15 Aug 2004, Nick Patavalis wrote: ... > For me it would be *tremendously* usefull if one could yield across > multiple levels of function calls. If this was supported, then most > uses of O/S treads could be replaced by generators. You can do this already if you use Armin Rigo's Greenlets which, whilst included in Stackless appear to work perfectly fine with standard python. (I've only tested with 2.3 FWIW) Trivial modification of one of the supplied examples: import greenlet def switchWrapper(): greenlet.main.switch() def doSwitch(): switchWrapper() def f(n): for i in range(n): print i doSwitch() gf = [greenlet.greenlet(f, (10+5*j,)) for j in range(2)] while 1: for g in gf: g.switch() (Mainly ripped out exception handling for clarity) One of the examples (test3.py) supplied shows how to build "standard" generators using greenlets. The differences however are a) the function has to be explicitly turned into a generator, b) you use a "Yield()" function call to return the value c) it's not limited to yielding through 1 level. (ie what you just asked for :) Example usage of the Greenlet-generators: def foobar(i): Yield(i) def g(n): for i in range(n): foobar(i) g = generator(g) for j in g(10): print j Indeed using the new decorator syntax you could probably simplify this to: def foobar(i): Yield(i) @generator def g(n): for i in range(n): foobar(i) for j in g(10): print j (Or pick your favourite decorator syntax ;-) Regards, Michael. From python at elehack.net Tue Aug 10 11:22:40 2004 From: python at elehack.net (Michael Ekstrand) Date: Tue, 10 Aug 2004 10:22:40 -0500 Subject: Secure storage for passwords for admin scripts? In-Reply-To: References: Message-ID: <200408101022.40366.python@elehack.net> On Tuesday 10 August 2004 10:11, Max wrote: > Are there are recommended methods for supplying scripts with login > information in a secure fashion? I believe the Windows task scheduler is capable of running a task as a given user, in which case the script need not worry about the password, the scheduler will store it and execute the script. I know this is the case in Win Server 2k3, it seems like it'd probably be present in 2k as well. HTH, -Michael From python at rcn.com Thu Aug 26 01:19:14 2004 From: python at rcn.com (Raymond Hettinger) Date: 25 Aug 2004 22:19:14 -0700 Subject: Proposal for removing self References: Message-ID: <5d83790c.0408252119.3e7da2a7@posting.google.com> "Brent W. Hughes" wrote in message news:... > When doing object-oriented stuff, it bothers me to have to type "self" so > many times. I propose that Python allow the programmer to optionally type > ".variable" instead of "self.variable" to mean the same thing. Of course, > the interpreter would have to be more careful about detecting floats that > begin with just a period as in ".5". What are your thoughts? There's a FAQ on the subject: http://www.python.org/doc/faq/general.html#why-must-self-be-used-explicitly-in-method-definitions-and-calls Raymond Hettinger From amk at amk.ca Mon Aug 30 20:31:05 2004 From: amk at amk.ca (A.M. Kuchling) Date: Mon, 30 Aug 2004 19:31:05 -0500 Subject: [IronPython] Jim Hugunin's web log. References: Message-ID: On Mon, 30 Aug 2004 20:11:51 +0100, David Wilson wrote: > Anti-trust conspiracy theories aside, if Microsoft adopts Python as a > part of its development toolset, the repercussions for Windows RAD and > scripting are massive... Hugunin has said his job is to "make the CLR better for dynamic languages". It's unclear to me that directive is synonymous with "develop IronPython further"; he could invent his own new language and implement that, or work with other CLR-based projects. I wouldn't conclude that Microsoft is adopting Python as a supported tool, or even that Python is Hugunin's primary focus, until he actually says that's his goal. --amk From harry.g.george at boeing.com Wed Aug 11 16:41:26 2004 From: harry.g.george at boeing.com (Harry George) Date: Wed, 11 Aug 2004 20:41:26 GMT Subject: Secure storage for passwords for admin scripts? References: <411a3602$1_2@127.0.0.1> Message-ID: "Roger Upole" writes: > You could store the passwords in a file protected by NTFS encryption, > or set the file security to only allow administrators access. > hth > Roger > > "Max" wrote in message > news:c90c3203.0408100711.3f7b056d at posting.google.com... > > I have a collection of system admin scripts (on Win 2k) that I would > > like to automate the execution of. However, some of them require the > > use of logins with admin rights, and would therefore prefer not to > > store the IDs in the clear text of the source. If memory serves > > correctly, the "compiled" .pyc files do not provide much security in > > this area. > > > > Are there are recommended methods for supplying scripts with login > > information in a secure fashion? > > Consider using ssh-agent. See "SSH The Secure Shell" from O'Reilly, chapter on "Case Studies ... Unattended SSH: batch or cron". -- harry.g.george at boeing.com 6-6M21 BCA CompArch Design Engineering Phone: (425) 342-0007 From peter at engcorp.com Thu Aug 12 15:37:15 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 12 Aug 2004 15:37:15 -0400 Subject: multiline snippets with triple quotes In-Reply-To: References: Message-ID: <9bGdnZbtJ4d2W4bcRVn-sw@powergate.ca> Christoph Zwerschke wrote: > So, what would be the pythonic way to implement such multiline snippets? Define them externally to that code block. Either put them above the function, or at the top of the module, or have them read from an external file, with the best approach being dependent on the precise situation at hand. For example, if you have only one or two such things, just use parentheses and single quotes instead of the triple quoting, while if you have a bunch of them but don't want to read them from a file, put them in a separate module and just import and reference them as required. -Peter From benzwt at yahoo.com.tw Mon Aug 9 01:26:12 2004 From: benzwt at yahoo.com.tw (benzwt at yahoo.com.tw) Date: 8 Aug 2004 22:26:12 -0700 Subject: Plotting histograms, scatter plots in Python References: Message-ID: DrColombes at yahoo.com (Dr. Colombes) wrote in message news:... > What is the easiest way to generate some plots and graphs in Python ? > > Specifically interested in simple histograms and scatter plots with > circles and regression lines. > > Thanks for your suggestions. For high quality scientific plot I suggest ppgplot and plplot. pgplot (original) http://www.astro.caltech.edu/~tjp/pgplot/ ppgplot (python module) http://efault.net/npat/hacks/ppgplot/ plplot http://plplot.sourceforge.net/ From ivoras at __-geri.cc.fer.hr Thu Aug 19 17:43:30 2004 From: ivoras at __-geri.cc.fer.hr (Ivan Voras) Date: Thu, 19 Aug 2004 23:43:30 +0200 Subject: Mixing classes... Message-ID: Is this possible: class C1: def somemethods(self): """methods do stuff, create member variables""" pass def f1(): """function returns instances of C1, somewhat manipulated into specific states""" return C1() class C2(C1): # C2 derives from C1 def othermethods(self): """new methods are introduced, but no new member variables (they work on existing ones)""" pass # So far, everything's ok. Now, i want to create instance of # C1 using f1: c = f1() # could be equal to "c=C1()", but not always... # ... and somehow "add" or "overlay" the additional methods # declared in C2 on the object "c". I tried this: c.othermethods=C2.othermethods c.othermethods() # fails here, is confused about what is 'self' ####### While this is probably considered "strange", and it's certainly not good design style, I somehow feel it could be possible to do in python. Any clues? From quaggy at gmail.com Thu Aug 26 22:24:08 2004 From: quaggy at gmail.com (Jonathan Wright) Date: 26 Aug 2004 19:24:08 -0700 Subject: Fun transformation problem In-Reply-To: Message-ID: Ooops... lets try again: .def trans(paths): . tree = {} . for path in paths: . branch = tree . for node in path[:-2]: . branch = branch.setdefault(node, {}) . branch[path[-2]] = path[-1] . return tree I don't know how that enumerate slipped in there. :) Jonathan. From tdelaney at avaya.com Fri Aug 13 03:01:27 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Fri, 13 Aug 2004 17:01:27 +1000 Subject: Why I love python. Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01CF47CD@au3010avexu1.global.avaya.com> Delaney, Timothy C (Timothy) wrote: > So did you have a similar reaction on first hitting the indentation > for blocks? I know I dimly recall thinking that this was very strange > and horrible (dimly, because it was 1992 or 1993). I should note that I've said my piece on c.l.py and python-dev about @decorators and feel that if my arguments haven't swayed anyone yet, they're not likely to so it's time to shut up. But the question asked deserved a response ;) Tim Delaney From in.aqua.scribis at nl.invalid Mon Aug 30 16:23:05 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Mon, 30 Aug 2004 22:23:05 +0200 Subject: Search for AVI file? In-Reply-To: References: Message-ID: Peter Kleiweg schreef: > John Doe schreef: > > > I realise that this is not really a python question, but python's the > > only language I'd be comfortable trying to deal with this. > > > > What I need is to search a drive and find all the AVI format files > > that are NOT listed with the AVI extension. I'm looking over an old > > drive of mine from an old computer. I know the files were renamed > > with the wrong extension, but I know that they were originally AVI > > files. Can python do this for me? Any hints? Anybody have a link to > > something that would already do this? I appreciate any help. > > Use walk() to find all files. Open each file and read in the > first 12 bytes. The last four of those 12 bytes should be > 'AVI ', if I'm not mistaken. Or from the command line: find / -type f -exec file '{}' ';' | grep AVI -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From mark_bottjer at hotmail.com Thu Aug 12 13:09:14 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Thu, 12 Aug 2004 13:09:14 -0400 Subject: PEP318 In-Reply-To: <7ttmh0t8c3cogtbhhnp1ohqu8b51pda461@4ax.com> References: <20040812090056.00001e31@titan> <7ttmh0t8c3cogtbhhnp1ohqu8b51pda461@4ax.com> Message-ID: <411ba43a$1@nntp.zianet.com> Arthur wrote: > I guess I am mystified what it is that is perceived to have been > gained ... by moving magic outside the function block to the top of a > function in lieu of expressive code outside the function block at the > bottom of the function. Something is created, and then transofrmed - > in the language of transformation that transcends the implementation > detail of what programming language is doing the work. I'm in the same boat. I wanted something (anything!) to get around the ugliness that is f=foo(f) after the def. Now that we have it (in spades, considering all the variants), I don't find it to be any more satisfying than what we already had. Sigh. -- Mark From pm_mon at yahoo.com Wed Aug 25 19:47:35 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Wed, 25 Aug 2004 19:47:35 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> Message-ID: Jess Austin wrote: > > Here I think you're making an unwarranted assumption. There is > currently nothing stopping an object from using information about > itself to do its job. And this is sometimes a useful freedom. As an > example, you might have subclasses whose only real purpose is to keep > track of their class and metadata, and have all functionality provided > by their superclass: > > class supe(object): > """this docstring is rarely frobnosticated""" > def do_something_based_on_metadata(): > frobnosticate(self.__doc__) > > class sub1(supe): > """I am sub1""" > > class sub2(supe): > """I am sub2""" > What you're trying to illustrate (I believe) is a superclass doing something based on the docstring of a subclass. Yes this certainly does happen. But the superclass and subclass are separate objects. I was talking about the situation where a function does something based on /its own/ metadata. That is what I'm saying virtually never happens, and therefore it's ok to make all assignments to __xxx__ attributes inside of a function def create /function attributes/ rather than /local variables/. Paul From indigo at bitglue.com Tue Aug 17 13:08:11 2004 From: indigo at bitglue.com (Phil Frost) Date: Tue, 17 Aug 2004 13:08:11 -0400 Subject: Is it possible to write a DLL using python In-Reply-To: References: Message-ID: <20040817170811.GA26817@unununium.org> Not directly, but yes, using libpython. Essentially you write your python code and then a thin C wrapper over it that does datatype and calling convention conversion. Since this is not a pleasant task for many people, you might take a look at Pyrex, which does this quite nicely. Generally Pyrex is considered as a way to wrap C code for use but Python, but it works just as well the other way. On Tue, Aug 17, 2004 at 03:44:50PM +0200, AMD wrote: > Hi, > > I need to write a Win32 DLL and I would like to use Python instead of > VB, C++ or Delphi. Is this possible? > > Thank you, > > Andre M. Descombes From luismg at gmx.net Fri Aug 13 11:33:14 2004 From: luismg at gmx.net (Neuruss) Date: 13 Aug 2004 08:33:14 -0700 Subject: Why I love python. References: <10ho7626f5f3f74@news.supernews.com> Message-ID: <278de0e.0408130733.78e9e922@posting.google.com> I guess you are looking for type inference or something along these lines. There's a very amibicious project called "Starkiller" which is a static type inferencer and a c++ compiler for Pyhon. It's being developed by Michael Salib, an MIT graduate, and as far as I know it will be released very soon. Preliminary results show speedups by a factor of 60. http://www.python.org/pycon/dc2004/papers/1/presentation.pdf From fumanchu at amor.org Sun Aug 1 00:18:12 2004 From: fumanchu at amor.org (Robert Brewer) Date: Sat, 31 Jul 2004 21:18:12 -0700 Subject: Returning another instance from constructor Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022DCC@exchange.hqamor.amorhq.net> Edward Diener wrote: > ...I can find no documentation in the Python 2.3 docs > for __new__ . Can you point me to it ? Start with http://www.python.org/2.2.3/descrintro.html FuManChu From deetsNOSPAM at web.de Mon Aug 2 11:57:06 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Mon, 02 Aug 2004 17:57:06 +0200 Subject: PyQt - clear widget for redraw References: <410b4492@news.maxnet.co.nz> <410bf265@news.maxnet.co.nz> <410d0699@news.maxnet.co.nz> Message-ID: > What I'm drawing is a series of lines (like a horizontal bar chart) and it > is updated several times a second. The problem is that it goes too fast. > I tried the time.sleep() function, but then it doesn't draw properly. It > seems to draw only part of the chart each time, and flickers. > Usually there is no "to fast" in graphics - so I've got to admit I'm not sure what you are talking about. Where does the data to draw come from, and how fast is it actually coming? A flickering sensation usually stems from the redrawing done so fast it interfers with the vertical retrace. Maybe it helps to put your sleep not in the drawing code, but between the arrival of different data sets to draw, thus limiting the redraws to an amount of lets say 10/s. If you'd fill us in with some more details, the suggestions might be better. And I think it would be worth asking these qustions on the PyKDE list Jim has mentioned - I'm also there :) -- Regards, Diez B. Roggisch From michaels at rd.bbc.co.uk Fri Aug 27 06:21:36 2004 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Fri, 27 Aug 2004 11:21:36 +0100 Subject: Call for signatories for J2 References: <412cf775$0$11496$ed2e19e4@ptn-nntp-reader04.plus.net> Message-ID: Richie Hindle wrote: > [Michael] >> Patch against current CVS including __future__ >> statements/declarations has now been created, tested and uploaded to >> SourceForge. All tests pass. > > Nice one - well done for all your work on this. You're very welcome. I'd encourage anyone who's interested in python's advancement to do the same, to be honest. The codebase is one of the cleanest I've encountered and fairly easy to get started with, and it's been a pleasure to work on. This experience will certainly encourage me to participate more in future. (Probably on my own time though!) >> British Broadcasting Corporation, Research and Development > > Is my license fee paying for this? If so, great! 8-) Makes for a > much better investment than Fame Academy. Yep. (Well, as well as my own time at the weekend/evenings, but that's common for open source :) We have a (small) allocation in our time for "bright ideas" regarding things that'll help the BBC in ways outside normal projects, and help further tools etc we use. :-) I think I've probably used mine up for a while now, but I think it's been worthwhile. We use Python (amongst many other languages) in R&D for prototyping ideas and I'm aware of various other parts of the BBC using python as well, so by helping the python community we help ourselves and everyone wins :) (Even if the patch is rejected it'll help resolve an argument!) I couldn't *possibly* begin to comment on Fame Academy though, I might say something I shouldn't ;-) Best Regards, Michael. -- Michael.Sparks at rd.bbc.co.uk British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From peufeu at free.fr Wed Aug 25 04:43:17 2004 From: peufeu at free.fr (=?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?=) Date: Wed, 25 Aug 2004 10:43:17 +0200 Subject: string concatenation optimizations [from python-dev Summary] References: <412AC928.7000603@ocf.berkeley.edu> Message-ID: psyco does this transparently for you. It can treat concatenated strings as arrays of strings behind the scenes, and it'll be faster than a class. (in fact, it is very fast). There is also cStringIO. If you want to write a mutable string class, though, that'd be handy. On Tue, 24 Aug 2004 18:53:35 -0400, Phil Frost wrote: > Has adding a stringish object that supports efficient slicing, > concatenation, and mutation been considered? The C++ STL rope comes to > mind. Essentially what I have in mind is a type that's a list of byte > arrays. The value is defined as the concatenation of these arrays. > > This would allow efficient implementations of things such as > s[31:35] = 'replacing a small substring with a larger one' > > I think a reasonable implementation could be done using existing python > types, and if it's useful, an opmitized C implementation could be done. > > This sort of thing is already on my stack of things to find on google, > write, or get someone else to write, just need the time. So what do you > think? Useful idea? Does this already exist? > > On Mon, Aug 23, 2004 at 09:50:48PM -0700, Brett Cannon wrote: >> python-dev Summary for 2004-08-01 through 2004-08-15 >> >> [snip] >> >> ------------------------------------------------------------------------------------- >> Changing the Big-O complexity for something in the language is now a >> language feature >> ------------------------------------------------------------------------------------- >> language evolution >> >> Armin Rigo came up with a way to have string concatenation in a loop >> (think ``for thing in iter_of_strings: concat_str += thing``) not be a >> quadratic algorithm thanks to some trickery for ``a = a + b`` and ``a += >> b`` conditions for strings. The hope was to remove the (commonly >> considered) wart of having ``"".join(iter_of_strings)`` be the suggested >> way to concatenate a bunch of strings. >> >> But Guido didn't like the patch. His reasoning was that changing >> something that led to a change in the Big-O complexity of certain >> algorithms would inherently hurt other implementations of Python when >> people would start to code specifically for that performance gain. For >> instance, having Jython be able to pull this trick off is, I believe, >> near impossible. So, in order to make sure changes like this are >> considered before applying them, Guido instated a new rule that >> "implementation features that affect not just the running speed but the >> O() rate for certain algorithms should be considered language features, >> because any implementation will be required to implement them in order >> to ensure code portability" between implementations of Python. >> >> In the end, though, this went in with a warning that the speed >> performance is not portable. It is not to be used in the stdlib ever. >> >> Contributing threads: >> - `Optimized string concatenation >> `__ >> - `PEP 0008 confusion - here it is, but don't use it? >> `__ >> >> [snip] From jpmorichon at earthlink.net Thu Aug 12 12:46:26 2004 From: jpmorichon at earthlink.net (CptPicard) Date: Thu, 12 Aug 2004 16:46:26 GMT Subject: Print command References: <2nv6roF54f7iU1@uni-berlin.de> <2o19ojF5ob9jU1@uni-berlin.de> Message-ID: "Peter Hansen" wrote in message news:MJ-dnQQiMd957obcRVn-vA at powergate.ca... > Russell Blau wrote: > > > "Peter Hansen" wrote in message > > news:cvmdnbvUcbh--obcRVn-uw at powergate.ca... > > > >>"Russell Blau" wrote in message > >> > Actually, I don't know the meaning of ``. > >> > On some languages, it means "evaluate": Is it the same meaning in > >> > Python? > > > > Ummm, actually, that wasn't me you were quoting; it was the OP who replied > > to my message pointing out that `x` doesn't mean the same as 'x'. > > Quite right... my apologies for the bad editing. It was > 'Cpt Picard' who wrote that, not Russell. > Thank you for the explanation on `` and for the fun ;-) And sorry for asking for things that I could check by myself but the "you know" at the end of Russel Blau's email sounds like a call for me to say "no, actually, I don't know". > -Peter From flupke at nonexistingdomain.com Tue Aug 10 19:56:00 2004 From: flupke at nonexistingdomain.com (flupke) Date: Tue, 10 Aug 2004 23:56:00 GMT Subject: wxPython & redirecting stderr References: <30260531.0408101452.76e424fa@posting.google.com> Message-ID: simo wrote: > "flupke" wrote: > >> i'm developing an app in wxPython but when i have an error in the >> wxPython code i've written, the app starts, an extra windows is >> opened where the error messages are print and then it closes >> again. Off course, this is to fast for the human eye to read :) >> How can i avoid this and have the wxPython messages arrive at the >> console just like the "normal" python error messages? > > As I recall it has something to do with how you call MainLoop - I > think it's the 0 below, maybe you have 1 or nothing? > > app = MyApp(0) > app.MainLoop() That's it. Thanks! Benedict From com-nospam at ccraig.org Thu Aug 12 08:52:30 2004 From: com-nospam at ccraig.org (Christopher A. Craig) Date: 12 Aug 2004 08:52:30 -0400 Subject: The winner of the Python Decorator Poll is... References: <4edc17eb.0408112052.1bbd85b3@posting.google.com> <59e9fd3a04081122235b3d9145@mail.gmail.com> Message-ID: Andrew Durdin writes: > Since you like the current proposal, why *didn't* you vote for it (it > was the first one)? I didn't vote for it because I sit comfortable in the knowledge that Guido will ignore the poll results. -- Christopher A. Craig From jpmorichon at earthlink.net Wed Aug 11 13:09:10 2004 From: jpmorichon at earthlink.net (CptPicard) Date: Wed, 11 Aug 2004 17:09:10 GMT Subject: Print command References: Message-ID: I think that you should try: string.rjust('currentTotal',6) instead of: string.rjust(`currentTotal`,6) You may also do it this this way: 'currentTotal'.rjust(6) "Yong Wang" wrote in message news:mailman.1511.1092239223.5135.python-list at python.org... > Hi, All: > For unknow reasons, I often get compiler error in the print > statements. For example: I have following codes: > > if len(currentFiberCode) > 0 : > print string.ljust(expandFiberCode(currentFiberCode,buildingRoom),30), \ > string.rjust(`currentTotal`,6), \ > string.rjust(`currentAvailable`,11), \ > string.rjust(`sm_ava`,7), \ > string.rjust(`mm_ava`,6), \ > string.rjust(`sm_used`,9), \ > string.rjust(`mm_used`,9) > else: > print 'data exist in fiber database table' > > When I comiped all the codes, I got : > Compiling ./NetDBfiber.py ... > File "./NetDBfiber.py", line 1086 > string.rjust(`currentTotal`,6), \ > ^ > SyntaxError: invalid token > > > How can I fix the problems ? > Thanks a lot. > > Yong > From scott.b.drummonds.nospam at intel.com Wed Aug 11 13:32:21 2004 From: scott.b.drummonds.nospam at intel.com (Scott Brady Drummonds) Date: Wed, 11 Aug 2004 10:32:21 -0700 Subject: 'break' Causes Execution of Procedure? References: Message-ID: "Scott Brady Drummonds" wrote in message news:cfdif9$hhm$1 at news01.intel.com... > How is it possible that the call to 'break' is seemingly being replaced with > a call to 'main'? I should also point out that the second time that the program's execution reaches the 'break' statement in the 'main' procedure, I get the following cryptic error message: DEBUG: advancing both simulators to 20178 DEBUG: encountered EOFError; breaking loop XXX lineno: 109, opcode: 0 Traceback (most recent call last): File "test.py", line 135, in ? main(sys.argv[1]) File "test.py", line 109, in main break SystemError: unknown opcode What's going on here? Scott -- Remove .nospam from my e-mail address to mail me. From sross at connectmail.carleton.ca Sat Aug 7 09:37:41 2004 From: sross at connectmail.carleton.ca (Sean Ross) Date: Sat, 7 Aug 2004 09:37:41 -0400 Subject: Decorator syntax References: <38ednYT1NLz1P4zcRVn-uA@powergate.ca><2njp58F1jj1dU1@uni-berlin.de> Message-ID: "Anthony Baxter" wrote in message news:mailman.1335.1091875631.5135.python-list at python.org... > On Sat, 07 Aug 2004 16:28:11 +0600, Yawar Amin wrote: > > How about > > > > def foo(a, b, c): > > foo.accepts = (int, int, list) > > foo.author = 'Chris King' > > How would you express foo=classmethod(foo) in this syntax? Far better to have > one flexible tool in the toolbox than a host of little, less functional tools. Well, You could add a decorate method with the following signature to functions: func.decorate(*decorators, **attributes) Then use: def foo(a, b, c): "foo can decorate itself, from the inside" foo.decorate(abstract, synchronized, classmethod, accepts=(int,int,int), author='Chris King') ... ... From guettli at thomas-guettler.de Fri Aug 20 07:02:31 2004 From: guettli at thomas-guettler.de (Thomas Guettler) Date: Fri, 20 Aug 2004 13:02:31 +0200 Subject: Feature Request: Current time in traceback Message-ID: Hi, I think it would be good, if the current time would be in the traceback. This would make it easier to read logfiles with tracebacks of python scripts. I know that I can write a custom exception handler, but why not make it the default? Regards, Thomas From justin__devine at hotmail.com Mon Aug 30 13:29:23 2004 From: justin__devine at hotmail.com (Justin) Date: 30 Aug 2004 10:29:23 -0700 Subject: Size of a remote URL Message-ID: How does Internet Explorer and other browsers do it? I have tried doing a Save As on multiple files that I know do not return a content-length header and yet it still knows the size and creates a progress bar? From jerf at jerf.org Mon Aug 23 16:22:40 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Mon, 23 Aug 2004 20:22:40 GMT Subject: Standard graph API? References: Message-ID: On Mon, 23 Aug 2004 11:58:15 -0700, David Eppstein wrote: > - It doesn't directly represent multigraphs > > - It doesn't directly represent undirected graphs (instead you have to > replace an undirected edge by two directed edges and hope your callers > don't give you a directed graph by mistake). > > - There isn't an explicit object representing an edge, although you can > create one by using a tuple (v,w) or (for undirected edges) a set. I think these three things speak to why there isn't a graph type and probably won't be one any time soon; unlike "Sets", there are just too many types of "graphs" in use, all fundamentally different in implementation, and with all differences having massive performance implications. As you indirectly point out, each of the following is an independent dimension: * Directed, undirected * Multi or non-multi * Explicit edges/explicit nodes with links/node and edge objects * Simple and fast implementation of nodes/nodes and edges that take attributes That's a good 24 possible types of graph library, each with implications w.r.t. algorithms and performance. While the abstract idea of a standard graph library is appealing to some people, any actual concrete implementation will likely leave the majority of people who want to use it out in the cold, resulting either in something only useful in the simplest of cases, or suffering from major feeping creaturitis as it tries to cover too many bases at once. From scherrey at proteus-tech.com Wed Aug 11 03:18:34 2004 From: scherrey at proteus-tech.com (Benjamin Scherrey) Date: Wed, 11 Aug 2004 03:18:34 -0400 Subject: Executing bytecode from a string. Message-ID: I'm curious as to how difficult it would be to take a string that contains compiled bytecode, load it into memory, give it a function name then execute that function. I'm thinking of a database that contains compiled objects that I can load and execute. I'm also curious as to what level of grainularity this would work - module, class, class method, function? Anyone tried to do this before? Obviously dependencies are a consideration but I'm more interested in the mechanics of this. Appreciate ideas & pointers you might have... Ben Scherrey From skip at pobox.com Tue Aug 10 13:14:57 2004 From: skip at pobox.com (Skip Montanaro) Date: Tue, 10 Aug 2004 12:14:57 -0500 Subject: @decorator syntax is sugar, but for what exactly? (decorator libraries). In-Reply-To: References: Message-ID: <16665.657.922906.180041@montanaro.dyndns.org> Roy> Does the proposed mechanism support something like (to use one of Roy> Dan's exmaples, written with two different syntaxen): ... Yes (using a class instead of a module simply for convenience): class martha: memo = {} @staticmethod def memoize(func): if func not in martha.memo: martha.memo[func] = {} def _inner(*args, **kwds): items = kwds.items() items.sort() items = tuple(items) key = (args, items) try: val = martha.memo[key] except KeyError: val = func(*args, **kwds) martha.memo[key] = val return val return _inner @martha.memoize def fib(n): assert n >= 0 print n if n <= 1: return 1 return n + fib(n-1) print fib(5) print fib(4) Running that yields this output: 5 4 3 2 1 15 10 Skip From davidf at sjsoft.com Thu Aug 26 05:25:21 2004 From: davidf at sjsoft.com (David Fraser) Date: Thu, 26 Aug 2004 11:25:21 +0200 Subject: Call for signatories for J2 In-Reply-To: References: Message-ID: FOR Thanks for all the hard work David Fraser From lbates at swamisoft.com Mon Aug 23 17:04:22 2004 From: lbates at swamisoft.com (Larry Bates) Date: Mon, 23 Aug 2004 16:04:22 -0500 Subject: Why are strings immutable? References: Message-ID: Think about it. Since strings occupy a fixed number of bytes in memory, a mutable string would just be a linked list of strings. For performance reasons you can't require that everything in memory gets moved around when you want to add one byte to a string. Multiply that by 20K and performance would be terrible. Since a mutable string is just a list of strings, Python just asks the programmer to treat it exactly like what it REALLY is. If you want to append lots of things to a string, build a list and then join it into a string at the end of processing. Your example: List = [ ] for i in range(20000): Word = DoSomeProcessing() List.extend(list(Word)) Str = ''.join(List) will work as: words=[] for i in xrange(20000): word = DoSomeProcessing() words.append(word) word_string = ' '.join(words) Notes: 1) You build the word_list by appending words that come back frmo DoSomeProcessing(). 2) If you want a space between your words you must specify it as the character before .join() call. 3) range(20000) will create a list of length=20000 and interate over it, xrange(20000) will just create an iterable object that returns the next number on each sucessive call (saving both memory and the time to create the 20K list). 4) You should stay FAR away from variables named list or str (even though you capitalized the first character). list and str are python functions that can easily get redefined by accident. List and Str will work, but I've seen MANY Python programmers walk on list, str, dict by accident and later wonder why. HTH, Larry Bates Syscon, Inc. "Brent W. Hughes" wrote in message news:O%rWc.171256$8_6.61890 at attbi_s04... > Let me give two examples of where I think it would be nice to be able to > change strings in place: > > > First example: > > I want to add about 20,000 words to the end of a string, something like > this: > > Str = [ ] > for i in range(20000): > Word = DoSomeProcessing() > Str += Word > > I'd actually like to say Str.extend(Word). As it is, I'm thinking of > something like this: > > List = [ ] > for i in range(20000): > Word = DoSomeProcessing() > List.extend(list(Word)) > Str = ''.join(List) > > > Second example: > > I would like to reverse a string containing about 120,000 characters. I'd > like to do it in place, but I'm planning to do something like this: > > List = list(Str) > List.reverse() > Str = ''.join(List) > > From ptmcg at austin.rr._bogus_.com Fri Aug 20 09:49:55 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 20 Aug 2004 13:49:55 GMT Subject: Decorator keyword options Message-ID: <7knVc.4599$Jn5.3074@fe1.texas.rr.com> Thanks to everyone who has voted so far - please keep them coming! Lurkers, this means you! In the interests of saving time, I propose that an additional thread start soon, to determine choices for a decorator keyword, in the event that our selected syntax requires one. Please visit the PythonDecorators Wiki page, and navigate to section 6.1 Indicators (or follow this link http://www.python.org/moin/PythonDecorators#head-61f608dbce6ba75b2317d7825d8529997f56fc9e ) (not sure how reliable this is?) I have started numbering the options in preparation for another voting thread, if you have other proposals, please include them on this Wiki page, along with your +/0/- commentary. -- Paul From jerf at jerf.org Mon Aug 30 14:04:32 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Mon, 30 Aug 2004 18:04:32 GMT Subject: Testing automatically on import References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1ry8k0d2az.fsf@rovereto.ifi.uio.no> <10iv0kid2ig9ka6@corp.supernews.com> <1rpt5ccbso.fsf@rovereto.ifi.uio.no> <10ivpk9inpnh65@corp.supernews.com> <1rd61bd26k.fsf@rovereto.ifi.uio.no> <1gj892g.1hlc8ar1po78b6N%aleaxit@yahoo.com> <1gja5sf.vbe56knfvu9sN%aleaxit@yahoo.com> Message-ID: On Mon, 30 Aug 2004 09:05:12 +0200, Alex Martelli wrote: > Hmmm, I could be wrong, but I think you have to check timestamps and > 'magic' signatures yourself. Pity, because imp.load_module must also do > that, but I don't think it makes this logic available separately. > Still, I believe Demo/imputil/importers.py has all the code you need. Drat, I was hoping someone would pop out with just that. Thanks for the tip and I'll see what I can do over the next few days. From arustad at gmail.com Wed Aug 25 23:10:25 2004 From: arustad at gmail.com (Aaron Rustad) Date: 25 Aug 2004 20:10:25 -0700 Subject: Proposal for removing self In-Reply-To: Message-ID: Brett C. wrote: > No thanks. This is a common suggestion and Guido has said it ain't > going to happen. I personally like 'self' a lot because ambiguity from > reading code goes away. It is easy to not see a '.' but not so for > 'self.' . It also makes teaching OOP to people much easier since you > don't need to explain why some variables and method calls are to the > instance but other are not. "Explicit is better than implicit". From arien.malec at gmail.com Tue Aug 24 18:13:01 2004 From: arien.malec at gmail.com (Arien Malec) Date: 24 Aug 2004 15:13:01 -0700 Subject: PEP318: radical notion References: <412a4222$0$293$626a14ce@news.free.fr> Message-ID: Christophe Cavalaria wrote in message news:<412a4222$0$293$626a14ce at news.free.fr>... > Arien Malec wrote: > > 1) Make PEP318 *only* implement problem (1). That is, create sematics for > > defining and retrieving function/method/class metadata > > 2) Create a new default metaclass that uses metadata for class/static > > method definitions to perform the necessary class/staticmethod > > transformations. Perhaps use this metaclass as default in 2.4 only via a > > "from __future__ import foo". > > 3) Leave any arbitrary transformations to be implemented via custom > > metaclasses -- these metaclasses will have access to the custom metadata > > to trigger method def transformations. > Unfortunately for you, you can use decorators on normal functions and not > only on member functions. It rules out any metaclass based implementation. Is there a valid use case that supports arbitrary magical non-metadata transformations of standalone functions? Arien From vronskij at post.sk Wed Aug 18 10:55:42 2004 From: vronskij at post.sk (vronskij at post.sk) Date: 18 Aug 2004 07:55:42 -0700 Subject: How big can a Python program be? References: <903b3fba.0408170333.49ce3944@posting.google.com> Message-ID: <903b3fba.0408180655.6a23aede@posting.google.com> > What are you actually asking? What technical limitations, > such as maximum line count per module, Python might have? Well this is maybe difficult to define. Programs reach some limit and become unmanagable. This is one reason why we have OOP, UML etc. > And more importantly than anything: why do you want to know > such things? Simple. Can you make an ERP in Python? Or is Python limited to little nice scripts or small programs with nice GUI? We are thinking to start a huge project, which could be hundreds of thousands of lines huge. I would finally know the answer, but it is probably better to ask first... From newsgroups at jhrothjr.com Mon Aug 9 14:33:28 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Mon, 9 Aug 2004 14:33:28 -0400 Subject: Prothon is switching to the .NET platform References: <000401c47b59$32539220$0d01a8c0@MarkVaio> <10h7lb21dhbuc12@news.supernews.com> <10h7rittck6ct75@news.supernews.com> <10h9dkm5ub5h1f2@news.supernews.com> <1dske12sbt1mj$.1aq70xrpy0r0i.dlg@40tude.net> <10hc6mk55u0qq26@news.supernews.com> Message-ID: <10hfgsf84rvtmfb@news.supernews.com> "John Roth" wrote in message news:10hc6mk55u0qq26 at news.supernews.com... > > > Hans Nowak just sent me a private e-mail pointing out that he > had done a Self-style implementation about a year ago. It looks > interesting, especially since it uses getattr and setattr rather than > getattribute. The trick with functions seems to be to use > new.instancemethod. Otherwise the code looks to be very > straightforward. __setattr__ just makes a couple of type > checks, insures that instances ending in _p are from the > selfish class, wraps functions in new.instancemethod and > rewraps methods likewise. __getattr__ implements the > inheritance rules. It does, by the way, work quite nicely. I just implemented "Cloak of Darkness" (which is the text adventure game that Roger Firth uses to assess the difficulty of writing in new interactive fiction authoring systems) in a couple of hours using TDD. The only significant problems I ran into were due to lack of support in Python itself - the package worked flawlessly. The biggest issue was that it violated one of the fundamental assumptions in unittest - since everything is initialized at module load time, each test does *not* see a fresh copy of object instances. I also forgot several times to bind functions to the objects - the same problem that people have with staticmethod and classmethod that decorators are supposed to fix. This is one of the domains where a prototype based object system shines: every object in the game is otherwise a singleton that needs its own class! John Roth > From narshe at gmail.com Wed Aug 18 15:27:39 2004 From: narshe at gmail.com (Josh Close) Date: Wed, 18 Aug 2004 14:27:39 -0500 Subject: name of current program Message-ID: <4a0cafe20408181227543a1284@mail.gmail.com> This is a simple question, but I can't find the answer for some reason. How do I get the name of the current script/program that is running? -Josh From Jared.Cohen at noaa.gov Thu Aug 19 13:09:23 2004 From: Jared.Cohen at noaa.gov (Jared Cohen) Date: Thu, 19 Aug 2004 13:09:23 -0400 Subject: Please help -- Tkinter Scale widget with DoubleVar is acting weird Message-ID: <4124DEC3.7050106@noaa.gov> I tried your code, and the exact same problem happened. When I set the slider to certain values (for instance, 0.3), the callback would start to be invoked when I just moved the mouse over the slider without even clicking. -------------- next part -------------- An HTML attachment was scrubbed... URL: From fperez528 at yahoo.com Thu Aug 12 17:02:46 2004 From: fperez528 at yahoo.com (Fernando Perez) Date: Thu, 12 Aug 2004 15:02:46 -0600 Subject: Verbosity Check Style References: Message-ID: > On Thu, 12 Aug 2004 11:23:49 -0400, > wrote: > >> I would like to get people's views on the best way to implement >> verbosity (or any command-line option) into python scripts. Command-line options are handled by the optparse module, part of python's standard library as of python 2.3. Python 2.2 had the older, somewhat less flexible getopt module (which is still there in 2.3, of course). Best, f From peter at engcorp.com Fri Aug 20 15:38:47 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 20 Aug 2004 15:38:47 -0400 Subject: How to clean python interpreter's environment? In-Reply-To: <2omtogFck37uU1@uni-berlin.de> References: <2omtogFck37uU1@uni-berlin.de> Message-ID: Reinhold Birkenfeld wrote: >>Rafal Kleger-Rudomin wrote: >> >>>I'm looking for a command to reset interpreter's environment i.e. unload >>>all modules, delete variables etc. > > What about something like this: > > def clear(keep=("__builtins__", "clear")): > keeps = {} > for name, value in globals().iteritems(): > if name in keep: keeps[name] = value > globals().clear() > for name, value in keeps.iteritems(): > globals()[name] = value Well, that only removes all the references from the globals of the current module. Is that all that's wanted? Note that threads that are already running will not be removed, nothing in sys.modules will be removed, and there are doubtless a few other things in the interpreter that aren't quite so easy to get at. -Peter From dummy at scriptolutions.com Sun Aug 1 18:38:19 2004 From: dummy at scriptolutions.com (Lothar Scholz) Date: Mon, 02 Aug 2004 00:38:19 +0200 Subject: SFTP file transfer library Message-ID: Hello, at the moment i have a program that uses FTP but some clients want to use the FTP over SSH protocol. Is there a library that does this ? And also where can i find the protocol specification. I never used SSH very much and only know how to start a SSH shell from my windows client. From kjetilho at yksi.ifi.uio.no Sat Aug 28 09:22:44 2004 From: kjetilho at yksi.ifi.uio.no (Kjetil Torgrim Homme) Date: Sat, 28 Aug 2004 15:22:44 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> <87hdqok9i6.fsf@sinken.local.csis.hku.hk> <1rfz68ely9.fsf@rovereto.ifi.uio.no> <876574k7du.fsf@sinken.local.csis.hku.hk> <1r3c28ejis.fsf@rovereto.ifi.uio.no> <5MWXc.228027$ht5.11749427@phobos.telenet-ops.be> <1rhdqnd3rm.fsf@rovereto.ifi.uio.no> Message-ID: <1r8ybzcs7v.fsf@rovereto.ifi.uio.no> [Roel Schroeven]: > > Kjetil Torgrim Homme wrote: > > when it's part of a large system, it's a bit harder. also > > consider that the db.commit() originally was correctly placed by > > the programmer, and the wrong indentation was introduced later > > by an editing glitch. > > In that case, I agree it can be harder. But IMO it gets harder > with increasing code complexity, whether braces are used or not. I > haven't yet seen very complex python programs, but I have seen C > and C++ code with multiple nesting levels, and let me assure that > it can sometimes be very difficult to spot errors. indeed, C or C++ is no better in this respect, quite the opposite IMO. Paul McGuire illustrated the corresponding problem in C: db->update_name(person); if (is_student(person)) log("update student %s", person->name); db->update_courses(person); db->commit(); I think it's harder to spot the bug here than in my Python example. this doesn't mean Python can't be improved further :-) -- Kjetil T. From P at draigBrady.com Tue Aug 3 09:57:05 2004 From: P at draigBrady.com (P at draigBrady.com) Date: Tue, 03 Aug 2004 14:57:05 +0100 Subject: PyGTK overload In-Reply-To: References: <410bb02e@sia.uibk.ac.at> Message-ID: <410F99B1.4020206@draigBrady.com> Egbert Bouwman wrote: > Glade is for later, when I am more comfortable with PyGTK. > Or am I too conservative ? Unless you need to construct the interface at run time (for e.g. creating arrays of buttons), just let libglade create the interface for you. You gain nothing by doing this drudgery yourself. P?draig. From pm_mon at yahoo.com Fri Aug 27 07:59:39 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Fri, 27 Aug 2004 07:59:39 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> Message-ID: Anthony Baxter wrote: > On Thu, 26 Aug 2004 20:54:22 -0400, Paul Morrow wrote: > >>Anthony Baxter wrote: >>Sure the interpreter uses __getitem__, but you use it too, right? I >>mean, you don't need the interpreter to tell you whether instances of >>the following class can act like a dictionary, do you? >> >> class Foo: >> def __getitem__(self, x): pass > > > Well, actually, no. The presence or absence of __getitem__ "tells" you nothing. > It depends on the implementation. > > def __getitem__(self, key): raise AttributeError, '__getitem__' > Oh my. Following conventions helps readers tremendously. Once a pythonista learns a convention, he doesn't spend as long looking at code that (appears to) follow that convention. He *assumes* that the convention means the same thing in the code he's reading as it does every else. Good developers are sensitive to this. Good developers write code that follows conventions. One convention is that classes whose instances can return values via indexing (e.g. foo['x']) define the __getitem__ method. /Because of this convention/, if we create a class that defines the __getitem__ method, our readers will expect that instances of that class can return values via indexing. Of course this means that we can have some fun with our readers too. We can create classes that define the __getitem__ method but which raise an exception when we try to use the syntax __getitem__ enables [*]. But while it may be fun to confuse readers of our code [**], its generally a bad idea. We all know that conventions have meaning. When we properly use conventions in our code, we are telling the reader a little (or in some cases a lot) about what is going on in our code, without us having to come right out and say it. This saves us time. This saves the reader time. This improves the maintainability of our code. So conventions are good. And because of that, I propose the following as the 20th Zen principle: Conventional is better than unconventional. Paul * as you did in your example. ** by writing code that follows conventions but doesn't exhibit the associated conventional behavior. From rtw at freenet.co.uk Thu Aug 5 21:47:38 2004 From: rtw at freenet.co.uk (Rob Williscroft) Date: 6 Aug 2004 01:47:38 GMT Subject: Proposed improved decorator syntax References: Message-ID: wrote in news:mailman.1235.1091753699.5135.python-list at python.org in comp.lang.python: > class foo: > def introduceNewFeature(self, someArgument, anotherArgument): > .decorate = [synchronized] > .accepts = (int, int) > .author = 'Chris King' > pass # whatever > > AIUI it is intended that prefix '.' will be used at some point with a 'with'/'using' keyword: class Foo: def f( self ): with self: .member = value But since we can have function's in function's and we already have "special" member functions (__init__ etc): class Foo: def method( self ): def __decorate__( func ): synchronized( func ) __accepts__ = (int, int) __author__ = "whoever" pass Rob. -- http://www.victim-prime.dsl.pipex.com/ From anthonybaxter at gmail.com Thu Aug 26 11:18:23 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 27 Aug 2004 01:18:23 +1000 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: On Thu, 26 Aug 2004 11:09:28 -0400, Paul Morrow wrote: > The function does *not* get a new namespace! Let me stress this point a > little further. We would simply be moving __xxx__ variables *out of* > the function's local variable namespace to where they belong, the > namespace of the function itself --- /the same namespace that __doc__ > lives in./ There _is_ _no_ _such_ _namespace_. __doc__ is an attribute of the function object. You are proposing to add one. How else is __doc__ = __doc__ + 'extra' to work? Please, please look into how python's namespaces work a bit more. This isn't super-complex stuff, and the lovely thing about Python is that it's _really_ easy to use introspection to see how these things work. From jacobsmail at postmark.net Tue Aug 24 14:03:16 2004 From: jacobsmail at postmark.net (Jacob H) Date: 24 Aug 2004 11:03:16 -0700 Subject: Getting at the bits of a 32-bit integer References: <85b54e91.0408231552.75f85727@posting.google.com> <412a98f4$0$65569$a1866201@newsreader.visi.com> <412aa5a0$0$68775$a1866201@newsreader.visi.com> Message-ID: <85b54e91.0408241003.63ffe56c@posting.google.com> Peter Hansen wrote in message news:... > Grant Edwards wrote: > > >>If you're new to Python and you are twiddling bits, the odds > >>favor the new user falsely importing old paradigms from other > >>languages, > > > > Probably so. > > Especially as the OP didn't say he was trying to break apart > Ethernet headers, serial data streams, or suchlike. He just > seems to want to grab a few bits for his own purposes, and > like Jeremy I doubt that the need is real (though also like > he I admit the possibility it could be!) and am quite curious > to hear from the OP again... > > -Peter The truth is that I have zero need to fiddle with individual bits. I just wanted to know how it was done. And now I do know! Jacob From anthonybaxter at gmail.com Sun Aug 22 02:24:56 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sun, 22 Aug 2004 16:24:56 +1000 Subject: [PATCH] RE: J2 decorator grammar In-Reply-To: References: Message-ID: On Sun, 22 Aug 2004 01:41:58 +0100 (BST), Michael Sparks wrote: > > The patch can be found here: > * http://thwackety.com/decorator_syntax_J2.patch Good to see. There's a few more bits than this that need to be done, though - see http://www.python.org/sf/979728 for the original @decorator patch, this should show you what else needs to be changed. From agriff at tin.it Sun Aug 22 20:28:29 2004 From: agriff at tin.it (Andrea Griffini) Date: Mon, 23 Aug 2004 00:28:29 GMT Subject: Has anyone implemented BASIC in Python? References: <2oo13eFcj548U1@uni-berlin.de> Message-ID: On Sat, 21 Aug 2004 00:27:33 -0400, Leif K-Brooks wrote: >Has anyone ever tried implementing a simple unstructured BASIC dialect >in Python? I'm getting interested in language implementation, and >looking at a reasonably simple example like that could be pretty >interesting. I've no idea why you think that an unstructured language would be a good starting point. IMO a good starting point would be just an expression parser; after than an interpreter that just executes a parsed tree and finally a true compiler that generates elementar instructions. Ugly non-structured languages are not going to be that easier to implement IMO. Anyway I found the idea of a BASIC interpreter in python intriguing, so I wrote one this weekend. I wrote it for my egoistic fun, so I'm not sure if it would be useful for you (or anyone else). Anyway here we go... http://www.gripho.it/py_basic.tgz Comments are welcome... Andrea From alanmk at hotmail.com Sat Aug 7 08:43:10 2004 From: alanmk at hotmail.com (Alan Kennedy) Date: Sat, 07 Aug 2004 13:43:10 +0100 Subject: jython and java exceptions In-Reply-To: References: Message-ID: [Jan Gregor] > I found that jython catches exact java exceptions, not their > subclasses. Is there some way to get around this limitation (or error) ? Hmm, not sure what you mean here. Consider the following code ################# from java.io import FileInputStream from java.io import IOException from java.io import FileNotFoundException; # Subclasses IOException dud_file_name = "does_not_exist.txt" def open_file(filename): return FileInputStream(filename) # For this function, we expect the FileNotFoundException clause # to be executed, because it is listed first, and matches the # exception precisely def catch_subclass(): try: f = open_file(dud_file_name) f.close() except FileNotFoundException, fnfx: print "Caught expected FileNotFoundException: %s" % str(fnfx) except IOException, iox: print "Error: should not have reached IOException clause" # For this function, we expect the IOException clause to be # executed, because it is listed first, and matches the exception, # because FileNotFoundException is a subclass of IOException def catch_superclass(): try: f = open_file(dud_file_name) f.close() except IOException, iox: print "Caught expected IOException: %s" % str(iox) except FileNotFoundException, fnfx: print "Error: should not have reached FileNotFoundException clause" if __name__ == "__main__": catch_subclass() catch_superclass() ######################## AFAICT, the above code demonstrates the correct behaviour for java exception handling in jython, and contradicts your statements above. Perhaps you can post a code sample that shows what you mean? > My program has class representing database source and specialed classes > for particulars databases. Now there are two options - to include > exception (subclasses of SQLException) for every db in except (so > all drivers has to be present) or to move methods to subclasses. You should be able to catch all exceptions using code like this try: # database operations except java.sql.SqlException: # This will catch all SQLExceptions and subclasses. -- alan kennedy ------------------------------------------------------ check http headers here: http://xhaus.com/headers email alan: http://xhaus.com/contact/alan From dave at pythonapocrypha.com Mon Aug 30 14:14:40 2004 From: dave at pythonapocrypha.com (Dave Brueck) Date: Mon, 30 Aug 2004 12:14:40 -0600 Subject: Size of a remote URL In-Reply-To: References: Message-ID: <41336E90.2050507@pythonapocrypha.com> Justin wrote: > Ok. I believe you are correct. I have observed the two MODES of the > download dialog box. HOWEVER there are still some instances in which > Internet Explorer knows the size of something that my code cannot > determine. So now I have this conclusion: The instances where I > cannot get the size but a browser can must exist because I am not > asking the server the right question. Post a URL and I'll give it a try for you. > Perhaps "Content-Length" is not > included in the default headers, but the server will provide this > header if it is asked too? It's _possible_ that whether or not the content-length header is returned is affected by e.g. the protocol you say you're using (HTTP 1.0 vs 1.1, for example), but that wouldn't be my first guess. > Maybe I need to ask for that header more > specifically? No, there's not really any way to do that in HTTP. > Also do you know of a simpler method than urlopen? Sure, you can always use plain old sockets: from socket import * s = socket(AF_INET, SOCK_STREAM) s.connect(('www.google.com', 80)) s.send('HEAD / HTTP/1.0\r\n\r\n') while 1: more = s.recv(4096) if not more: break print more -Dave From brent.hughes at comcast.net Sat Aug 28 15:09:53 2004 From: brent.hughes at comcast.net (Brent W. Hughes) Date: Sat, 28 Aug 2004 19:09:53 GMT Subject: Iteration over Lists and Strings References: <1gj80xs.1cfownoqz4m9N%aleaxit@yahoo.com> Message-ID: <5M4Yc.326126$a24.276550@attbi_s03> "Alex Martelli" wrote in message news:1gj80xs.1cfownoqz4m9N%aleaxit at yahoo.com... > Michel Claveau - abstraction m?ta-galactique non triviale en fuite > perp?tuelle. wrote: > > > and enumerate is more fast than index. > > Oh, absolutely. sequence.index(anitem) takes time proportional to > len(sequence), for the average item. If you repeat that operation for > all items in sequence, you end up with total time proportional to the > SQUARE of len(sequence) -- a LOT, for long sequences, enumerate itself > takes constant time, and looping over all items that enumerate yields > takes time proportional to the number of items (costant time per item). > > If you're familiar with big-O notation, we're talking O(N) vs O(N > square)... not the kind of performance issue one can ignore, for long > sequences, because the difference in performance keeps going up and up > without bounds as the sequence grows longer. > > > Alex Did you say enumerate(seq) takes constant time? I would have thought it was proportional to len(seq). From me at privacy.net Mon Aug 16 12:10:47 2004 From: me at privacy.net (Richard Hanson) Date: Mon, 16 Aug 2004 09:10:47 -0700 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> <56cfb0e3.0408142004.511a8a8e@posting.google.com> <5hbvh0hnngn8sotqkgav3o1mvs61n039e5@4ax.com> Message-ID: Peter Hansen wrote: >Richard Hanson wrote: > >> [Re Python's indentation -- "Neat!" or "Yuck!"] >> >> For the record, my first reaction to *braces* years ago, was: >> "Yuck!" > >That was my reaction as well, but my sister really needed >them as her teeth weren't straight at all. Ha! (I can almost remember when I used to *have* teeth...) :-D laughing-out-loud-heartily y'rs, Richard -- R Hanson [The mangled email addie below works.] sickolefartnewsguycom From robey at slash_dev_slash_random.org Wed Aug 18 19:17:32 2004 From: robey at slash_dev_slash_random.org (Robey Holderith) Date: Wed, 18 Aug 2004 18:17:32 -0500 Subject: age of Python programmers References: Message-ID: Not yet, but our day will come. From vincent at visualtrans.de Fri Aug 6 15:36:46 2004 From: vincent at visualtrans.de (vincent wehren) Date: Fri, 06 Aug 2004 21:36:46 +0200 Subject: unicode to ascii converting In-Reply-To: References: Message-ID: Peter Wilkinson wrote: > Hello tlistmembers, > > I am using the encoding function to convert unicode to ascii. At one > point this code was working just fine, however, now it has broken. > > I am reading a text file that has is in unicode (I am unsure of which > flavour or bit depth). as I read in the file one line at a time > (readlines()) it converts to ascii. Simple enough. At the same time I am > copressing to bz2 with the bz2 module but that works just fine. The > code is and error reported appears below. I am unsure what to do. > > I assume that because it is reporting that ordinal is not in range, that > something to do with the character width that I am reading? > > Peter W. > > def encode_file(file_path, encode_type, compress='N'): > """ > Changes encoding of file > """ > new_encode = encode_type > old_file_path = file_path + '.old' > new_file_path = file_path > os.rename(file_path,old_file_path) > file_in = file(old_file_path,'r') > > if compress == 'Y' or compress == 'y': > bz_file_path = file_path + '.bz2' > bz_file_out = bz2.BZ2File(bz_file_path, 'w') > for line in file_in.readlines(): > bz_file_out.write(line.encode(new_encode)) > bz_file_out.close() > > else: > file_out = file(file_path,'w') > for line in file_in.readlines(): > file_out.write(line.encode(new_encode)) > file_out.close() > > file_in.close() > os.remove(old_file_path) > > ERROR Reported: > > Parsing > X:\GenomeQuebec_repository\microarray\HIS\M15K\Step_1_repository\HISH0224.txt > > Traceback (most recent call last): > File "C:\Program Files\ActiveState Komodo 2.5\callkomodo\kdb.py", line > 433, in _do_start > self.kdb.run(code_ob, locals, locals) > File "C:\Python23\lib\bdb.py", line 350, in run > exec cmd in globals, locals > File "C:\Python23\Lib\site-packages\xBio\Scripts\unicodeToAscii.py", > line 158, in ? > main() > File "C:\Python23\Lib\site-packages\xBio\Scripts\unicodeToAscii.py", > line 75, in main > encode_file(fileToProcess, options.encode, 'Y') > File "C:\Python23\Lib\site-packages\xBio\Scripts\unicodeToAscii.py", > line 144, in encode_file > bz_file_out.write(line.encode(new_encode)) > UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: > ordinal not in range(128) > 0xff in position 0? If there is a 0xfe is in position 1, I would suspect your dealing with the Byte Order Mark for a UTF-16 encoded file (UTF-16 LE to be precise). What happens if you skip the first 2 bytes of the file? -- Vincent Wehren From P at draigBrady.com Mon Aug 16 06:51:47 2004 From: P at draigBrady.com (P at draigBrady.com) Date: Mon, 16 Aug 2004 11:51:47 +0100 Subject: sys.stdin.read() replacement In-Reply-To: References: Message-ID: <412091C3.4000609@draigBrady.com> Karin Lagesen wrote: > I am writing a small write-logfile script for use on the terminal. I have here > a section where the user should be able to type in several lines. I have solved > it so far by using sys.stdin.read(), which makes it possible to type in several > lines (separated by enter) and then terminate the session by typing ^D. This is > all very good. However, with this it is only possible to edit the line you are > in. If you spot an error further up in your text, you cannot get at it. Do any > of you know of a way I can do this? import readline (I don't know if it works on windos) P?draig. From krueger at k-dns.de Sun Aug 8 15:01:15 2004 From: krueger at k-dns.de (Thomas =?ISO-8859-1?Q?Kr=FCger?=) Date: Sun, 08 Aug 2004 21:01:15 +0200 Subject: What is @ used for? References: Message-ID: Darren Dale wrote: > I was looking through Pybliographer's source yesterday, and I dont > recognize this syntax: > > version = "@version@" > progname = "@package@" It looks like a special string used by an external application working with the source code. CVS for example replaces (better expands) some keywords between $ characters with information like version, author or history. AFAIK there is no special meaning in Python. Thomas From cybermanxu at hotmail.com Wed Aug 4 12:25:55 2004 From: cybermanxu at hotmail.com (Jinming Xu) Date: Wed, 04 Aug 2004 11:25:55 -0500 Subject: How to force a single number to be a tuple Message-ID: Hi Folks, I have a number sequence, which is put into a tuple like this: y=2, 3.0, 4.5 I can manipulate the sequence as a tuple when it has more than 1 number. But when the sequence has only 1 number, like y=2 I have trouble to manipulate it as a tuple. I guess there must be a way to forece a single number to be a tuple. Could anyone please tell me that? Thanks, Jinming _________________________________________________________________ FREE pop-up blocking with the new MSN Toolbar ? get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/ From daniel at syrinx.net Fri Aug 13 08:54:49 2004 From: daniel at syrinx.net (Daniel Ellison) Date: Fri, 13 Aug 2004 08:54:49 -0400 Subject: Flython? In-Reply-To: References: <2o3ovjF6apnoU1@uni-berlin.de> Message-ID: <2o3rtmF6apnoU2@uni-berlin.de> Peter Hansen wrote: > Daniel Ellison wrote: > >> I *like* "Flython" as a name! :) A flying python! I can see the logo >> now... > > > So does that mean we would have "Monty Flython's @Pie-ing Circus" BaDA-ba. Well, we definitely already have the @Pie-ing Circus here. All we need now is Monty Flython. > if the @decorator debate is still going on by the time someone > implements a Flash compiler for Python? By the time /someone/ implements a compiler? I thought that someone was going to be you! Damn this full-time contract. We could have paired on Flython. Dan From aleaxit at yahoo.com Sat Aug 28 04:45:24 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 28 Aug 2004 10:45:24 +0200 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <7xzn4gwgea.fsf@ruckus.brouhaha.com> <1gj7a1o.1a5d2q410jsn2kN%aleaxit@yahoo.com> <7xisb4xnh5.fsf@ruckus.brouhaha.com> <1gj7c1a.tfdm14p3hclcN%aleaxit@yahoo.com> <7xd61benm9.fsf@ruckus.brouhaha.com> <1gj82n3.1ylkr3nierngmN%aleaxit@yahoo.com> <7x4qmnvgcu.fsf@ruckus.brouhaha.com> Message-ID: <1gj859v.ctjokn1lgorodN%aleaxit@yahoo.com> Paul Rubin wrote: > aleaxit at yahoo.com (Alex Martelli) writes: > > Would it make sense to rely on a naming convention instead? > > I.e. foo.zip would be unsigned but bar.jar would have to be signed > > or else no go. This would have the advantage of allowing > > substantial granularity in controlling this. > > I think this is reasonable, except what does the import statement look > like? Do you say something like "import frob from bar.jar"? No, you say, as always: import frob Importing looks at each item on sys.path, and each item can be: 1. a directory X -- then import looks for X/frob.py or a subdirectory X/frob/ containing an __init__.py (or in either case .pyc or .pyo) 2. a zipfile X.zip -- then import looks inside (unsigned) file X.zip for a frob.py, frob.pyc, etc 3. [only novelty...] a signed zipfile X.jar -- then import verifies the signature then if valid proceed as in 2 > > Side question, does module zipfile already have the code to allow > > reading such signed files? > > I think jar files are just zip files containing an extra file (called > "manifest") that has signatures in it. So you can import from a jar > as if it were a zip. But it might be nice to check signatures automatically if reading such files is a common task. Alex From anthonybaxter at gmail.com Thu Aug 5 13:37:07 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 03:37:07 +1000 Subject: Confused about pep 318 In-Reply-To: References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: On Thu, 05 Aug 2004 13:29:29 -0400, Peter Hansen wrote: > I'll make another donation to PSF if the final decorator syntax > does not Perlishly use arbitrary punctuation as the @ syntax does. FFS. What exactly is "Perlish" about @? It's an unused symbol. That's all. From grante at visi.com Mon Aug 9 01:34:09 2004 From: grante at visi.com (Grant Edwards) Date: 09 Aug 2004 05:34:09 GMT Subject: how many bytes in an int References: <9ACRc.1523$bJ2.9739@news1.mts.net> <4116f8ee$0$8076$a1866201@newsreader.visi.com> Message-ID: <41170cd1$0$8076$a1866201@newsreader.visi.com> On 2004-08-09, Reid Nichol wrote: >> I suspect you want to use the "struct" module -- but it's a >> guess, since you haven't really said what it is you're trying >> to accomplish. > > I'm thinking of writing a movie file encoder (probably avi). > So, I need to output DWORD (lookup revealed its a 4-byte int) > to a binary file. Therefore I need to know whether this can > be done in python or not, which will tell me whether I'll try > to do it or not. > > But, since the 64-bit archecture is out, short, long, etc may > change there meanings quite soon. From what I've read in the > struct module docs I can only tell it that it's a short, long, > etc. but not whether it's exactly a 4-byte int. Is there a > way to do this? The struct module is the only thing I know about. If you're worried about the "C" types in the struct module changing underneat you, you could do a pure Python implimentation of "python-int" to/from DWORD. It's utterly trivial and shouldn't take more than one or two lines of code. -- Grant Edwards grante Yow! LOOK!!! I'm WALKING at in my SLEEP again!! visi.com From cbfalconer at yahoo.com Tue Aug 31 12:49:36 2004 From: cbfalconer at yahoo.com (CBFalconer) Date: Tue, 31 Aug 2004 16:49:36 GMT Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4PGdnfsOfdDPi63cRVn-tA@speakeasy.net> <41337FC9.8070902@hotmail.com> <%T%Yc.29567$Es2.11957889@news4.srv.hcvlny.cv.net> Message-ID: <4134AC88.56452265@yahoo.com> Ville Vainio wrote: >> "John" == John W Kennedy writes: > >> Yes, and also a single-process pipe emulator. Ever since >> 2.0, MS has been trying to turn MS-DOS (later, Windows) into >> a Unix clone. > > With very little success. Notepad still only understands cr-lf > line breaks, and / as path separator still screws up most of their > cmd line programs (which think / is for command line options). > > Microsoft probably thought avoiding compatibility is a good idea, > and have only lately started to have some regrets, visible as the > release & future integration of SFU. Migrating ppl from Unix > probably *is* easier when you are not doing your best to make > interoperability as painful as possible. Dump Notepad and get Textpad. www.textpad.com. First class. -- "Churchill and Bush can both be considered wartime leaders, just as Secretariat and Mr Ed were both horses." - James Rhodes. "We have always known that heedless self-interest was bad morals. We now know that it is bad economics" - FDR From roy at panix.com Wed Aug 25 08:07:50 2004 From: roy at panix.com (Roy Smith) Date: Wed, 25 Aug 2004 08:07:50 -0400 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> <3064b51d.0408221352.ca7b57e@posting.google.com> Message-ID: Jacek Generowicz wrote: >> (2) The Python approach to OOP is very different -- looser -- than >> that of C++ and has less support for data hiding. For example, one can >> add an attribute to an object anywhere, which seems like a dubious >> freedom to me. > > Seems like a damn useful freedom to me. But then I've worked with > people who refused to take the obvious clean, efficent, clear design > decision only because it violated some principle they were told about > in some OOA&D class Yeah, tell me about it. We had a really smart young guy who grew up on C++ and was convinced that C++ was the be-all and end-all of OOP. He told me flat out that Python was not an OOPL because it didn't have private data. Of course, he never actually tried Python, because he "just couldn't get past the whole indenting thing". Then he quit and took a higher paying job with a big financial company maintaining legacy Fortran code. Go figure. From secun at yahoo.com Tue Aug 17 14:13:43 2004 From: secun at yahoo.com (ChrisH) Date: Tue, 17 Aug 2004 18:13:43 GMT Subject: Editors again References: Message-ID: Doesn't it cost around $3000 for a Qt license to run the program? From rtw at freenet.co.uk Wed Aug 25 13:11:51 2004 From: rtw at freenet.co.uk (Rob Williscroft) Date: 25 Aug 2004 17:11:51 GMT Subject: Unpythonic Python References: <8a638f47.0408240034.653a92ff@posting.google.com> <8a638f47.0408240700.13c39f57@posting.google.com> Message-ID: David Abrahams wrote in news:uy8k31as1.fsf at boost-consulting.com in comp.lang.python: > Rob Williscroft writes: > >> David Abrahams wrote in news:uzn4j2s38.fsf at boost-consulting.com in >> comp.lang.python: >> >>>> That's not the problem. I can download the file reliably from >>>> other machines. >> >> At the same time, using http ? > > I can download the file reliably using IE from my WinXP box. > > I can download the file reliably using urllib from Cygwin Python 2.3.2 > > The 2nd element returned by urlretrieve is Which version, the one that works or the one that doesn't ? > > 'Date: Wed, 25 Aug 2004 14:50:17 GMT\r\nServer: Apache/2.0.40 (Red > Hat Linux)\r\nLast-Modified: Wed, 25 Aug 20 2 GMT\r\nETag: Something is missing here: Last-Modified: Wed, 25 Aug 20 2 GMT Contrast: Wed, 25 Aug 2004 14:50:17 GMT > "b63d5b-20ec84b-18057e80"\r\nAccept-Ranges: bytes\r\nContent-Length: > 34523211\r\nContent-Type: n/x-bzip2\r\nConnection: close\r\n' 34 MB's ( I got 6 MB's ) >>> Trying again with Python 2.3 on Cygwin. > > As you can see from the above, it works. Is there a known urllib bug > in earlier Pythons? Sorry I don't know, but I've seen the same truncation with no python, and no unix. >> Is it possible the file is being (re) uploaded (via cvs) during your >> cron job's download, thus truncating your download ? > > I don't think so. Can you test wether or not this is happening ? I.e if you don't get the full 34523211 bytes re-download and compare the above Length, ETag and Last-Modified. > >> Perhapse you should change to cvs: >> >> os.system( 'cvs ... ' ) > > The problem with that is that I want to capture the whole CVS > history, not just today's state. I was suggesting you get the tarball via cvs, though presumably sourceforge don't give you the option. http has the problem that the server will just truncate the download if the source file gets replaced. > >> FWIW, I tried downlading with IE using the link above I got a >> truncated 6 and bit MB's (16:15 BST (UTC +0100)). > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > Sorry, what does that mean? Did it show that message in a dialog, > or...? > No, I got a download complete, but the file was only 6 MB's, bzip2 -t told me the file was truncated, the (16:15 ...) is the time I tried downloading, BST = British Summer Time, though you wouldn't know it from the weather :). Further I just ran: import urllib filename, headers = \ urllib.urlretrieve( 'http://cvs.sourceforge.net/cvstarballs/boost-cvsroot.tar.bz2', 'boost-cvsroot.tar.bz2') print filename print headers boost-cvsroot.tar.bz2 Date: Wed, 25 Aug 2004 16:53:20 GMT Server: Apache/2.0.40 (Red Hat Linux) Last-Modified: Wed, 25 Aug 2004 14:14:02 GMT ETag: "b63d5b-20ec84b-18057e80" Accept-Ranges: bytes Content-Length: 34523211 Content-Type: application/x-bzip2 Connection: close The script ended at 17::59 BST, Note the difference bettween the two times in the headers, suggesting the file was modified 1:45 min's ago ~ the same time my attempted download with IE failed. Rob. -- http://www.victim-prime.dsl.pipex.com/ From John.Marshall at ec.gc.ca Tue Aug 31 09:40:47 2004 From: John.Marshall at ec.gc.ca (John Marshall) Date: 31 Aug 2004 13:40:47 +0000 Subject: [IronPython] Jim Hugunin's web log. In-Reply-To: <278de0e.0408302346.62cfc40b@posting.google.com> References: <278de0e.0408302346.62cfc40b@posting.google.com> Message-ID: <1093959648.3331.18.camel@mango.cmc.ec.gc.ca> On Tue, 2004-08-31 at 07:46, Neuruss wrote: > As for the concerns about Microsoft "hijacking" python, I think they > probable go too far. We all know what MS did in the past, but this > time, I think they shifted their policies drastically. > > There's a whole move of opening their source and submitting standards > that confirm that their new strategy is stabilishing .NET as "the" > platform. I'll believe they have changed after a decade of proof. Skeptical. John From brent.hughes at comcast.net Wed Aug 25 18:01:24 2004 From: brent.hughes at comcast.net (Brent W. Hughes) Date: Wed, 25 Aug 2004 22:01:24 GMT Subject: Proposal for removing self Message-ID: When doing object-oriented stuff, it bothers me to have to type "self" so many times. I propose that Python allow the programmer to optionally type ".variable" instead of "self.variable" to mean the same thing. Of course, the interpreter would have to be more careful about detecting floats that begin with just a period as in ".5". What are your thoughts? From __peter__ at web.de Wed Aug 25 06:43:04 2004 From: __peter__ at web.de (Peter Otten) Date: Wed, 25 Aug 2004 12:43:04 +0200 Subject: Why return None? References: Message-ID: Martin DeMello wrote: > Anthony Baxter wrote: >> On Wed, 25 Aug 2004 08:26:26 GMT, Martin DeMello >> wrote: >> > It seems to be a fairly common pattern for an object-modifying method >> > to return None - however, this is often quite inconvenient. >> >> list.reverse() modifies the list in place. The python idiom is that >> these don't return a reference to the modified list. Although note the > > Yes, but why? I mean, is there either an advantage to returning None or > some inherent danger in returning self? > > martin I think Guido would rather have newbies stumbling over >>> a = list("abc") >>> zip(a, a.reverse()) Traceback (most recent call last): File "", line 1, in ? TypeError: zip argument #2 must support iteration than >>> class List(list): ... def reverse(self): ... list.reverse(self) ... return self ... >>> a = List("abc") >>> zip(a, a.reverse()) [('c', 'c'), ('b', 'b'), ('a', 'a')] The latter is more likely to remain undetected until some damage is done. Still, I would prefer it. Peter From steven.bethard at gmail.com Tue Aug 24 19:07:04 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Tue, 24 Aug 2004 23:07:04 +0000 (UTC) Subject: winnowing down the keyword list (WAS: Re: J2 paper 0.2.1) References: <3A81C87DC164034AA4E2DDFE11D258E3022E59@exchange.hqamor.amorhq.net> Message-ID: Robert Brewer amor.org> writes: > Any proposal to winnow down the list is eagerly accepted. :) Yeah, so my understanding was that the point of leaving the keyword argument unresolved was that we were trusting in Guido to choose a reasonable keyword. I haven't vetoed any of the keywords that I don't like because I'm reasonably confident that Guido won't choose any of these keywords. (That and I am, like many others here, burning out on decorator arguments...) That being said, I think Robert has the right approach here -- if there are any keywords you absolutely couldn't tolerate, point them out and if no one objects, hopefully we can remove them from the list. Then we can be left with a few keywords that most of us believe are better than @, and then let Guido make the final decision. I guess my point here is that I don't think we need to narrow down the options to only one choice (but there's certainly nothing wrong with narrowing down the options if you have good reasons). Steve From faizans at gmail.com Sun Aug 15 21:32:07 2004 From: faizans at gmail.com (Fazer) Date: 15 Aug 2004 18:32:07 -0700 Subject: [ANN] libgmail 0.0.1 -- Gmail access via Python References: <3c18c08f.0407011159.9243ee1@posting.google.com> <6491b0ab.0407241411.2fa426b3@posting.google.com> <3c18c08f.0408100601.2f45aa5a@posting.google.com> Message-ID: <6491b0ab.0408151732.15773a8@posting.google.com> follower at gmail.com (Follower) wrote in message news:<3c18c08f.0408100601.2f45aa5a at posting.google.com>... > Hi Fazer, > > Thanks for your feedback. > > faizans at gmail.com (Fazer) wrote in message news:<6491b0ab.0407241411.2fa426b3 at posting.google.com>... > > [Snip] > > Is it possible to delete an email using this library? > I hope you don't mind me delaying the answer to this question until I > could answer in the affirmative. (Rather than promising vapourware... > :-) ) > > I have just committed code into CVS to enable message and thread > trashing functionality. (It will appear in the 0.0.8 release.) The new > `GmailAccount` methods `trashMessage` and `trashThread` will move a > message or thread into the trash. > > I intend to add functionality to permanently delete items & mark items > as spam in the future, but it's not there yet. > > Hope this is useful. > > --Phil. Hey Phil, I was wondering if you would also plan on writing some sort of documentation/manual for your very nifty library? That would really help others a lot. Do you need help with it? Maybe I can lend a hand if you need it. Thanks, Fazer From tjreedy at udel.edu Sat Aug 28 05:44:19 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 28 Aug 2004 05:44:19 -0400 Subject: Question about references/copies References: Message-ID: "Henning Kage" wrote in message news:pan.2004.08.28.07.52.35.422774 at gmx.de... > I'm using Python only for some months now and I'm wondering, whether such > assignments as above are creating bitwise copies of an object or just > recieve a reference. That means I wanted to know, wheter Python in > general > differs between references and copies: Better to think of Python this way: it has objects and bindings of objects to one or more targets (names and slots of composite objects). Binding statements (target = expression) always and only assign targets to objects. Terry J. Reedy From exarkun at divmod.com Sun Aug 29 20:30:48 2004 From: exarkun at divmod.com (Jp Calderone) Date: Sun, 29 Aug 2004 20:30:48 -0400 Subject: cPickle and __getattr__ In-Reply-To: References: Message-ID: <41327538.7020204@divmod.com> Chris Curvey wrote: > Hi all, > > I have this program > > class Company: > def __init__(self, revenues, costs): > self.revenues = revenues > self.costs = costs > > def __getattr__(self, name): > if name == 'profits': > return self.revenues - self.costs > > c = Company(100, 75) > print c.revenues > print c.costs > print c.profits > > import cPickle > print cPickle.dumps(c) > > Everything works fine up until the last line. If I remove the > __getattr__ function, then everything works (except "print c.profits"). > What is the cPickle class trying to get to that is causing my > __getattr__ function to be called? > Potentially lots of things. But the problem isn't that cPickle is calling __getattr__, exactly. The problem is that your __getattr__ isn't properly signalling non-existent attributes. You should raise AttributeError instead of implicitly returning None for which there is no attribute. Adding "raise AttributeError(name)" to the end of the definition unbreaks it enough to let pickle work. Jp > -Chris > From dbickett at gmail.com Tue Aug 24 10:45:48 2004 From: dbickett at gmail.com (Beeyah) Date: 24 Aug 2004 07:45:48 -0700 Subject: advice for perl expert wanting to learn python References: Message-ID: <1d6cdae3.0408240645.727059b7@posting.google.com> Harry George wrote in message news:... > For experienced scripters, I find Beazley's "Python Essential > Reference" is excellent. You already know what you want, just need to > see how Python does it, and don't need a lot of handholding. Get a > copy of "Python Cookbook" too, and scan that. Then rewrite one of > your exsiting perl scripts. OTOH, It should be a crime to purchase the Python Developer's Handbook [1]. I'm glad I only paid six dollars for a used copy, because its a load of crap. [1] http://makeashorterlink.com/?H10123029 From tismer at stackless.com Fri Aug 6 09:24:24 2004 From: tismer at stackless.com (Christian Tismer) Date: Fri, 06 Aug 2004 15:24:24 +0200 Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) In-Reply-To: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> References: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> Message-ID: <41138688.1020406@stackless.com> Istvan Albert wrote: ... > Ladies and Gents, start your engines and rally around > this syntax (if you prefer it of course) so that there > is evidence that it should be taken as a serious candidate. You have my full support. Although I'm not sure if we still have an option to choose at all. +1 -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From cjw at sympatico.ca Sun Aug 8 15:58:04 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Sun, 08 Aug 2004 15:58:04 -0400 Subject: Decorators In-Reply-To: References: <%A8Rc.50217$Vm1.1280580@news20.bellglobal.com> Message-ID: <9BvRc.3638$a65.105727@news20.bellglobal.com> Dan Bishop wrote: > "Colin J. Williams" wrote in message news:<%A8Rc.50217$Vm1.1280580 at news20.bellglobal.com>... > >>Christopher T. King suggested that "we're trying to kill too many birds >>with one stone". >> >>http://groups.google.com/groups?q=stone+birds+group:comp.lang.python&hl=en&lr=&ie=UTF-8&selm=Pine.LNX.4.44.0408050856390.31290-100000%40ccc9.wpi.edu&rnum=1 >> >>He goes on to suggest three needs which decorators serve. Are these the >>only purposes which are envisaged for decorators? > > > If I understand correctly, they'd be useful for anything where you'd > now use the syntax > > function = decorator(function) > > In addition to @staticmethod, you could have decorators for > > (1) Memoization. Makes repeated function evaluation more efficient > without having to rewrite the function. > > class memoize(object): > def __init__(self, func): > self.__func = func > self.__results = {} > def __call__(self, *args): > if args not in self.__results: > self.__results[args] = self.__func(*args) > return self.__results[args] > > def fibonacci(n): > @memoize > if n in (0, 1): > return n > return fibonacci(n - 1) + fibonacci(n - 2) > > (2) Debugging uses, like: > > class printreturns(object): > "Behaves like f but prints its return values." > def __init__(self, f): > self.__f = f > def __call__(self, *args): > result = self.__f(*args) > if debug: > print 'f%r = %r' % (args, result) > return > > def somefunc(x, y): > @printreturns > ... Dan, Many thanks for this, the examples helped to clarify things. I've attached a script which shows a significant time benefit for memoize. Also, it shows about a 24% reduction in the elapsed time as compared with version 2.3. I had expected that the unwrapped version of fibonacci would be better than the recursive method as it avoided the overhead of function calls. This test shows the reverse. Colin W. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: tFib.py URL: From shalabh at cafepy.com Tue Aug 17 16:07:41 2004 From: shalabh at cafepy.com (Shalabh Chaturvedi) Date: Tue, 17 Aug 2004 13:07:41 -0700 Subject: favorite python web development tool? In-Reply-To: <10i4nttktcvltdd@corp.supernews.com> References: <10i4nttktcvltdd@corp.supernews.com> Message-ID: mike wrote: > hi all - > > > i'm fairly new to python, coming from a java servlet / velocity template > background. i'm looking for a good python web development tool, and > hope to find some suggestions here. > > given my background, webware+cheetah feels comfortingly familiar, and > i'm leaning toward it. before i dive in, though, i'm wondering what you > experienced users think about it, compared to the other tools that are > out there. eg, does the python environment have strengths that are > better exploited with something other than a servlet-like model? > > > thanks for your thoughts! > > My favourite is Quixote. Although I haven't used Webware much one thing I can say is that Quixote is easier to grasp than Webware. It has simple and powerful concepts and as a Python programmer I found it quite intuitive. I think Quixote PTL (Python Template Language) is also the 'right way' to do web templates. With PTL, you reuse a lot of Python knowledge instead of having to learn yet another template language. Links: http://www.mems-exchange.org/software/quixote/ http://www.quixote.ca/ -- Shalabh From cemerick at snowtide.com Wed Aug 18 10:36:08 2004 From: cemerick at snowtide.com (Chas Emerick) Date: Wed, 18 Aug 2004 10:36:08 -0400 Subject: Python-list Digest, Vol 11, Issue 288 In-Reply-To: <20040818130058.808391E400B@bag.python.org> References: <20040818130058.808391E400B@bag.python.org> Message-ID: On Aug 18, 2004, at 9:00 AM, Gerrit Muller wrote: > how many teeners are still programming? Most teeners I know build > websites, but they don't program. Well, does it count if I *feel* like I'm 19 still? I'm 24 now (yikes!), although I did brush up against python when I was 17 (I was just starting an undergrad AI/cog. sci. program, so I went to lisp at that point instead). - Chas Emerick From heikowu at ceosg.de Mon Aug 9 14:41:06 2004 From: heikowu at ceosg.de (Heiko Wundram) Date: Mon, 9 Aug 2004 20:41:06 +0200 Subject: Purely emotional perspective In-Reply-To: References: <10hf3oaltbo7o74@corp.supernews.com> Message-ID: <200408092041.06021.heikowu@ceosg.de> Am Montag, 9. August 2004 20:07 schrieb Peter Hansen: > Heiko Wundram wrote: > > The docstring of a function actually is only meta-data (in my taste), and > > thus should remain inside the function definition. > > This argument makes no sense to me. Why should any meta-data be inside > the function body? There should probably be one place where all > meta-data is defined, and it should be used consistently for everything, > docstrings included. (The pie-syntaxians are heading that way, it > seems.) Basically, what I was trying to say: decorators aren't necessarily meta-data. decorators may return a new function object which does something different than the actual function in question. Thus, you could divide decorators into two categories: 1) mutating decorators, which change the function object to be a new function (and thus introduce new functionality), 2) "decorating" decorators, which add information to the presented function object. Docstrings are a decorator which falls into category 2, the example I gave falls into category 1. What my argument basically was: Decorators which fall into category 2 may safely be hidden from the programmer, as they only give "meta-information" on the function in question, and don't change it's behavior, whereas decorators which fall into category 1 may not be hidden from the programmer, as they change the functions behavior, and are thus important for understanding the function in question when reading the code. Now, what I'd like to see (hypothetically) is to have decorators which mutate the function before the actual function, because they are "equivalent" to defining a function, whereas decorators which do "decorating" inside the function body (like the doc-string), because they are equivalent to setting an attribute on the function. Now, certainly, making a distinction between the two is inappropriate, as it would only complicate code, but "hiding" mutating decorators inside the function body is also not the right way to go, so for me, it's clear that decorators should always be outside the function body. But, I hold no grudge against keeping the doc-string inside the actual function (because this actually is meta-data, it has no influence on running the function), so the following is out of the question for me: @doc("my doc-string") def f(): > To tell the truth, I think I prefer the current approach, where the > function is clearly, explicitly decorated *after* it has been defined, > and no new syntax is required. True, I use this approach a lot. But decorating a function with a clear sign before the actual method (@) only makes the code more readable for me. As I've stated elsewhere, I've ported some code of mine to use decorators for 2.4, and I've really felt that the code became quite a bit more readable just by having this little bit of syntactic sugar. > Python is clearly on a huge evolutionary surge and conservative views > on the matter are definitely not winning out right now. And that's fine. :-) Conservatism never did anybody any good. ;-) Anyway, hope that clears up my position... Heiko. From yangzhangbuffalo at hotmail.com Mon Aug 16 22:49:23 2004 From: yangzhangbuffalo at hotmail.com (Yang Zhang) Date: Mon, 16 Aug 2004 21:49:23 -0500 Subject: mailman mailing list program References: Message-ID: Hi all, I wonder if it is possible to create an object of func, class or method in the run time by it's name? To make it more clear, let me show you an example: I parsed the python code and found a function with name 'len'. I want to know if it is a build-in func(where can I look up?). If so, ignore it otherwise I want to find out which module is it defined in. All I know is the name (which is a string), and all the modules that this program have imported. In the same way, I also need to process the class and methods call. I wonder if it is possible? I will appreciate your help very much!! -Ryan From Ian.Sparks at etrials.com Tue Aug 17 10:11:56 2004 From: Ian.Sparks at etrials.com (Ian Sparks) Date: Tue, 17 Aug 2004 10:11:56 -0400 Subject: Databases: Getting values by column name Message-ID: <41A1CBC76FDECC42B67946519C6677A901915270@pippin.int.etrials.com> Robert Ferber Wrote... > Is there a way to use them as dictionaries, ie with > Index-Strings (=column > names) as indexes? I've had some success with Dtuple : http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81252 Some database adapters supply a dictionary interface as an extension to the DBAPI 2.0 (the MySQL adapter comes to mind as an example). > -----Original Message----- > From: Robert Ferber [mailto:rob at nospam.net] > Sent: Tuesday, August 17, 2004 9:53 AM > To: python-list at python.org > Subject: Databases: Getting values by column name > > > Hi, > > I can't find any good documentation about the Python-database > module, all I > found was this rudimentary (no examples, no references) piece here: > > http://www.python.org/peps/pep-0249.html > > Anyway, this and also this tutorial here: > > http://www.devshed.com/c/a/Python/MySQL-Connectivity-With-Python/2/ > > only use database rows as sequences, ie as arrays with > numerical index. > This gives you loads of problems when using "select *" and > also bad code > readability when selecting specific columns. > > Is there a way to use them as dictionaries, ie with > Index-Strings (=column > names) as indexes? > > BTW, is there any good searchable reference to Python's > functions, with > examples and cross-references to similar functions? > > Thanks a lot, > > Robert > -- > http://mail.python.org/mailman/listinfo/python-list > From peter at semantico.com Thu Aug 12 11:13:45 2004 From: peter at semantico.com (Peter Hickman) Date: Thu, 12 Aug 2004 16:13:45 +0100 Subject: Help understanding Scheme's syntax, procedures and calls In-Reply-To: <411b7bdd$0$65612$a1866201@newsreader.visi.com> References: <95f168b0.0408120120.31433dc7@posting.google.com> <411b577a$0$20523$afc38c87@news.easynet.co.uk> <411b7bdd$0$65612$a1866201@newsreader.visi.com> Message-ID: <411b892a$0$2952$afc38c87@news.easynet.co.uk> Grant Edwards wrote: > On 2004-08-12, Peter Hickman wrote: > > >>Is this someone's homework by any chance? > > > According to the OP, it's part of a final exam. > So they are completely shot then? From rpm1deleteme at direcway.com Tue Aug 17 19:16:42 2004 From: rpm1deleteme at direcway.com (RPM1) Date: Tue, 17 Aug 2004 19:16:42 -0400 Subject: Best programming language References: Message-ID: <2ofhl4F9mve8U1@uni-berlin.de> Clearly the best programming language is: Religion. Patrick "Roman Suzi" wrote in message news:mailman.1718.1092639914.5135.python-list at python.org... > > ;-) > > Just type into google > "best programming language" > and press (I am lucky) > > > Sincerely yours, Roman Suzi > -- > rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3 From jjl at pobox.com Mon Aug 2 15:34:22 2004 From: jjl at pobox.com (John J. Lee) Date: 02 Aug 2004 20:34:22 +0100 Subject: Fine-grained OSError subclasses or cross-platform errnos? Message-ID: <87llgxuyf5.fsf@pobox.com> Today, I wanted to do something like this: def nr_files(dirName) try: return len(os.listdir(dirName)) except OSError, e: if e.errno == errno.ENOENT: return 0 else: raise In other words, I wanted to trap only the case of missing directory (and not, for example, insufficient permissions), and I wanted to do it in the EAFP style. The problem is that errno is not cross-platform. Neither is there any subclass of OSError that I can conveniently catch to figure out what went wrong. Is there any better way of doing this? If not, why not? John From abra9823 at mail.usyd.edu.au Wed Aug 4 12:33:31 2004 From: abra9823 at mail.usyd.edu.au (Ajay Brar) Date: Thu, 05 Aug 2004 02:33:31 +1000 Subject: bsddb Message-ID: <41110FDB.9080307@mail.usyd.edu.au> hi! when i do an import bsddb, it tries do do an import _bsddb i looked around Python23\Lib but couldn't find any _bsddp file....or am i totally on the wrong track. the reason i am asking is, i am trying to port a Python app to a pocket pc and python release for pocket pc does not have bsddb module. thanks cheers -- Ajay Brar CS Honours 2004 Smart Internet Technology Research Group http://www.it.usyd.edu.au/~abrar1 From chrispatton at gmail.com Thu Aug 26 20:09:35 2004 From: chrispatton at gmail.com (Chris Patton) Date: 26 Aug 2004 17:09:35 -0700 Subject: A newbie in need.... Message-ID: <9c3edc58.0408261609.6640e400@posting.google.com> Hey everybody. I'm trying to make a program that requires a 2D field to run. Besides "curses" or "ncurses", is there a python module that will create a graph? --Thanks for the help! From Jeffrey at Fro.man Wed Aug 25 16:27:24 2004 From: Jeffrey at Fro.man (Jeffrey Froman) Date: Wed, 25 Aug 2004 13:27:24 -0700 Subject: Enumerate object is destroyed by casting? References: Message-ID: Nick Jacobson wrote: > Casting an 'enumerate' object destroys it????Is?that?supposed?to > happen, or is it a bug? > > > For example: > a = ['a', 'b', 'c'] > e = enumerate(a) > print dict(e) > print dict(e) > > > Result: > {0: 'a', 1: 'b', 2: 'c'} > {} This is supposed to happen. Enumerate objects are essentially generators -- casting the object doesn't "destroy" it; but iterating over its values "uses them up". In other words, after the first dict() call, your enumerator is now empty. The same thing would happen if you simply iterated over the object, like: for thing in e: print thing From grante at visi.com Fri Aug 13 15:29:18 2004 From: grante at visi.com (Grant Edwards) Date: 13 Aug 2004 19:29:18 GMT Subject: How to sort records in file References: <81a41dd.0408131122.21180d0d@posting.google.com> Message-ID: <411d168e$0$65601$a1866201@newsreader.visi.com> On 2004-08-13, Lad wrote: > What is the best( easiest)way how to sort a file? $ man sort ;) > I have a file where each record consists of 3 fields( 3 words) > and I would like to sort records by the first field( word)in > each record. lines = file('myfilename').readlines() lines.sort() for l in lines: print l, -- Grant Edwards grante Yow! I just had my entire at INTESTINAL TRACT coated visi.com with TEFLON! From __peter__ at web.de Sat Aug 14 15:49:39 2004 From: __peter__ at web.de (Peter Otten) Date: Sat, 14 Aug 2004 21:49:39 +0200 Subject: tkinter canvas bitmaps w/ xbm formated string data? References: <9578d4b.0408141100.6b88a7ab@posting.google.com> Message-ID: Brett wrote: > I'm trying to load a xbm formatted string as a bitmap and draw it to a > canvas....I don't have any trouble with loading/displaying xbm files, > it's when I've pre-created the xbm as a string I get a 'can't find > your bitmap error' > ...I have a feeling that I somehow lost a reference to my bitmap > object...I'm not sure what's happening. > > any ideas what could be wrong? No, but canvas.create_image(100, 100, image=a_bitmap) instead of > canvas.create_bitmap(100,100, bitmap=a_bitmap) #if I used seems to work. Peter From jens.news at webgear.co.za Fri Aug 20 10:11:05 2004 From: jens.news at webgear.co.za (Jens Thiede) Date: Fri, 20 Aug 2004 16:11:05 +0200 Subject: Newbie to XML in Python Message-ID: XML in Python doesn't seem easy or intuitive. All I need to do, is to interpret a small piece of XML in which I store data for the contents of an autorun menu. What is the quickest/most effective way to do this? What should I use for this; SAX or DOM - and which parser of ether one, or niether (if there is a third option)? What are your views, Jens. From cedmunds at spamless.rochester.rr.com Sat Aug 28 22:18:34 2004 From: cedmunds at spamless.rochester.rr.com (Cy Edmunds) Date: Sun, 29 Aug 2004 02:18:34 GMT Subject: simple compiled languages? References: <7xzn4fu188.fsf_-_@ruckus.brouhaha.com> Message-ID: <_1bYc.855$2s.374@twister.nyroc.rr.com> "Paul Rubin" wrote in message news:7xzn4fu188.fsf_-_ at ruckus.brouhaha.com... > I'm wondering what other languages clpy'ers are familiar with, that > have simple implmentations with compilers. I'm asking out of general > interest, not for a specific application. Usually, discussions of > small languages revolve around interpreters so I'm asking specifically > about languages with compilers. > > Qualifications: > > - Simple compact implementation, not too many LOC and not too many > machine resources needed. Example: Ron Cain's Small-C and its > descendants. Tiny CC (www.tinycc.org) is pushing the complexity > limits for what I have in mind. > > - Real compiler, must generate real machine code (not threaded code or > byte code or asm macros) that's not too horrible, but needn't make > serious optimizing attempts. Compiler should at least in principle > be retargetable to multiple cpu's. Load-and-go operation (i.e. no > external assembler needed) is highly desirable. > > - Real language with datatypes and semantics, not a fancy assembler or > FORTH. Static or dynamic typing are both fine. Fancy parsing is > not required, e.g. Lisp-like syntax is fine. > > - Preferably self hosting, i.e. the compiler should be able to compile > itself, once you've gotten a running instance of the compiler > somehow. Among other things, this helps establish that the language > is actually useable. > > Ideas? Turbo Pascal. I used to think it was great in 1983. :) -- Cy http://home.rochester.rr.com/cyhome/ From davidb at mcs.st-and.ac.uk Mon Aug 23 10:27:54 2004 From: davidb at mcs.st-and.ac.uk (David Boddie) Date: 23 Aug 2004 07:27:54 -0700 Subject: ANN: Python Decrypt PDF script -- builds on pdftools References: <4de76ee2.0408200350.3ccb9c50@posting.google.com> <3c18c08f.0408201732.6766d375@posting.google.com> Message-ID: <4de76ee2.0408230627.46ebf22c@posting.google.com> follower at gmail.com (Follower) wrote in message news:<3c18c08f.0408201732.6766d375 at posting.google.com>... > I found some examples here (protected/encrypted with no user > password): > > * > * Thanks. I'll take a look at those sites. > It also looks like the following GPL'd tool enables you to encrypt > without Adobe tools: > > * It could be interesting to see exactly what needs to be done to encrypt PDF files, but pdftools doesn't support file output at the moment. > The code works well enough for me at the moment that my motivation for > taking it further is a little low at the moment, sorry. :-) I'm not > sure how straight-forward it would be to add it transparently, as at a > minimum I think it needs to handle strings and streams differently. I > will keep your request in mind though... No problem. I've no great desire to improve it, either. I'm hoping that someone will want to take it over and maintain it. > Incidentally, have you considered making the Numeric import in > pdftools optional? I just commented it out and things worked fine for > me as I wasn't actually accessing page content. I was trying to extend the module towards support for exporting the contents in suitable file formats, and Numeric was used just for matrix handling. A streamlined pdftools would just provide a simpler wrapper around the objects in the PDF file. > Thanks for your work with pdftools. Thanks for taking it further! David From mattjensen at timetospare.net Sun Aug 29 02:55:51 2004 From: mattjensen at timetospare.net (Matthew K Jensen) Date: 28 Aug 2004 23:55:51 -0700 Subject: os.popen problem Message-ID: <173c23bb.0408282255.2f1be2ee@posting.google.com> Ok, this might seem odd as to why I am doing this in this certain way, but it's for a very specific purpose, and in so doing needs to be done this way. I am writing code on a winbloze box like so: ----------- import os vlvl = os.popen('copy con randomfilename','w') vlvl.write('some stuff') vlvl.write('some more stuff') vlvl.write(chr(0)) vlvl.close() ----------- At the next to last line, the command is supposed to complete and give output which resembles "\t1 file(s) copied.\r\n". Appearantly this is not happening. The last line just hangs there, doing nothing. Is there something I am supposed to be doing, or is there some concept that has either blown over the top of my head or just simply forgot? Any feedback is helpful. With respect, Matt K Jensen From grante at visi.com Sun Aug 15 21:12:18 2004 From: grante at visi.com (Grant Edwards) Date: 16 Aug 2004 01:12:18 GMT Subject: Python secure? References: <6o75v1-p92.ln1@home.rogerbinns.com> Message-ID: <412009f1$0$8090$a1866201@newsreader.visi.com> On 2004-08-15, Roger Binns wrote: >>> Yes. Anyone who recovers your "code" and/or uses it will be >>> in violation of copyright and several other laws. That is >>> legal protection no matter what languages or combination of >>> languages you use. >> >> I assume you are talking about reverse engineering. If so, >> that just depends on that particular countries laws. Some >> allow and some don't. > > The "uses it" bit is what is important. Even in the European > Union where reverse engineering is legal, it is only legal for > the purpose of interoperability and where the original vendor > provides no suitable other means of doing the > interoperability. > > Anyone just taking your code, or even recovered code and then redistributing > it Ah. Nobody said the decompiled code would be redistributed. Distributing copies (decompiled or otherwised) is covered by copyright law. Decompiling is not. > falls fowl of copyright laws (unless of course you GPL it :-) -- Grant Edwards grante Yow! HELLO, little boys! at Gimme a MINT TULIP!! Let's visi.com do the BOSSA NOVA!! From johnfkeeling at yahoo.com Sun Aug 15 00:32:08 2004 From: johnfkeeling at yahoo.com (John Keeling) Date: 14 Aug 2004 21:32:08 -0700 Subject: Decorators: an outsider's perspective References: Message-ID: <35b736b9.0408142032.1b41f2e0@posting.google.com> Chas, > action-at-a-distance is *always* bad. I agree, but the culprit is the poor style of writing a function/method implementation that spreads over numerous pages. If a function is large, it is good style to break it up. So, to my mind, the action-at-a-distance problem doesn't really exist ... it is just poor coding style of very large functions that creates action-at-a-distance here: > def blah (args): > ....[insert 50/100/200 lines here] > blah = staticmethod(blah) I say, if function/method blah is over a page long, then it should be broken up into smaller component functions, thus removing the action-at-a-distance complaint. So, with due respect for all honourable python devs who have given us IMO the best programming language available, decorators, to my mind, are a totally superfluous feature ... and this turns out to be a negative because they are unnecessary (and divisive). My opinion: please remove decorators forever, or at least until there is some concensus as to how they should be used. John From jepler at unpythonic.net Wed Aug 18 22:16:23 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 18 Aug 2004 21:16:23 -0500 Subject: how to display unicode in a Label in Tkinter In-Reply-To: References: Message-ID: <20040819021623.GA24118@unpythonic.net> I have to warn you, my remarks below are based on an extensive knowledge of tcl, and a tiny knowledge of arabic. On Wed, Aug 18, 2004 at 02:50:07PM -0600, A K wrote: > um i waswondering if the web page yu provided gave code that did the > following > > 1) provide a function that reverses the order of the text string:revert reverses the whole string, and turns "(" into ")" and vice versa. The first loop at the top of "proc uc:arabchar2glyph" unreverses strings of digits, possibly with embedded spaces, hyphens, dots, and commas. The next two blocks turn digits (optionally) and the punctuation characters "?" and "," into equivalents ("ARABIC QUESTION MARK" and "ARABIC THOUSANDS SEPARATOR"). The next two sections use commas (no "original" commas remain after an earlier step, so this is safe) to deal with combining characters. Here things go beyond my little knowledge of arabic. First, a comma is added at the "side" of each glyph that is a combining glyph, then the glyphs-with-commas are turned into the combined glyphs. For instance, the first two entries in that list are for turning the characters U+0622 ARABIC LETTER ALEF WITH MADDA ABOVE U+0644 ARABIC LETTER LAM into U+fef6 ARABIC LIGATURE LAM WITH ALEF WITH MADDA ABOVE FINAL FORM assuming the commas produced earlier are in the right place. List (in arabchar2glyph), any remaining commas (from glyphs that didn't combine) are removed, and the string is returned. The final "proc ar:ligatures" does even more substitution. The first pair of items turns the sequence U+fea4 ARABIC LETTER HAH MEDIAL FORM U+fee4 ARABIC LETTER MEEM MEDIAL FORM U+fedf ARABIC LETTER LAM INITIAL FORM into U+fd88 ARABIC LIGATURE LAM WITH MEEM WITH HAH INITIAL FORM I think these two specific examples will seem "backwards" to you, because at both steps the string has been "rendered" from logical order to European left-to-right order. > 2) stores the unicode number of the arabic characters in an array and > assigns them a letter or character from the keybord. Yes, the portion of the code beginning "proc buckwalter2uc" turns an ASCII representation of Arabic text into the proper unicode characters. > > Also the attachment yu sent contained a bunch of non-sense. I was wondering > what it was supposed to be. thank you for your help. The attachment is generated by software called "gpg", which is related to older software called "PGP". It is a "signature" that allows people who read messages I write to be confident that I wrote them. You could use the gpg software yourself to verify the signature. In my e-mail program, something this is displayed at the top of a signed message: [-- PGP output follows (current time: Wed 18 Aug 2004 08:38:54 PM CDT) --] gpg: Signature made Tue 17 Aug 2004 09:06:45 PM CDT using DSA key ID 96935D7D gpg: Good signature from "Jeff Epler " [-- End of PGP output --] gpg can also be used to encrypt the contents of e-mail messages, giving some measure of privacy to online conversations. You can learn more about gpg by visiting www.gnupg.org if you're interested, though that website seems to be geared to people who already know what gpg is and why they want it.. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From chotty at freenet.de Sun Aug 22 09:19:02 2004 From: chotty at freenet.de (Christian Otteneuer) Date: Sun, 22 Aug 2004 15:19:02 +0200 Subject: clear content of 'printed' Message-ID: Hello Newsgroup, I have the following problem: I want to write a python script, that writes text into files. The text is being "collected" in a for-loop, the code looks like this: for i in range(len(myList)): id = myList[i] print "some text" container.writeToFile(id, printed) Where writeToFile() creates a new file with the id 'id' and fills it with 'printed'. The problem is, that I have to delete the content of 'printed' before entering the for-loop again. Else, I'll find the content of the past for-loops in my file. (The file created in the second loop would look like this:) some text some text Is there a possibility to do clear the content of 'printed' in python? Thanks alot!! From jello at comics.com Mon Aug 23 09:06:56 2004 From: jello at comics.com (rzed) Date: Mon, 23 Aug 2004 13:06:56 GMT Subject: XMLObject - problem with recursive definitions References: <6f402501.0408222323.5fd81b2a@posting.google.com> Message-ID: fuzzyman at gmail.com (Michael Foord) wrote in news:6f402501.0408222323.5fd81b2a at posting.google.com: > I've been using the excellent XMLObject and have unfortunately > come up against what *looks* to me like a bug - although it's > very possible that the problem is mine !! > [...] I copied your code, installed XMLObject (thanks for mentioning this, by the way -- I had not been aware of it before), and ran the program, which worked fine. Output: ... but this was based on the latest XMLObject. Maybe it's been patched in response to your message? -- rzed From aleaxit at yahoo.com Thu Aug 26 16:29:45 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 22:29:45 +0200 Subject: Call for signatories for J2 References: Message-ID: <1gj5cs7.wqxd1s1ec69umN%aleaxit@yahoo.com> Robert Brewer wrote: ... > I await the ultimate irony, that after all the furor, Guido may decide > to pull decorators out of 2.4 entirely during beta. ;) I'd see nothing ironic about it. After some experimentation, I think I'd rather have no decorators than the @syntax blotch. I think a keyword that's ALREADY a keyword has been almost ignored, though people occasionally did mention it re decorators: 'as'. I'd love to see 'as' used as THE decorator keyword. personally I'd prefer 'def as classmethod foo(...):' followed by 'def foo(...) as classmethod:' followed by 'as classmethod def foo(...):' followed by 'as: classmethod def foo(...):' but even the last one of these, the one I least prefer, seem to me to be superior to all other suggestions I've seen (including J2 using 'per' instead of 'as', which I'd expressed favourable opinions on earlier). 'as' is a keyword today, VASTLY underused currently in being relegated to 'from ... import ... as' and 'import ... as' statements only. Let's get full mileage from it by making it the decorators keyword, J2 or otherwise! (( yeah the semantics are quite different -- so are those of comma: short and unobtrusive pieces of either punctuation or keywords DESERVE to get overloaded that way!!!-) )) Alex From pellis.no.spam at tampabay.rr.com Fri Aug 27 23:19:28 2004 From: pellis.no.spam at tampabay.rr.com (Patrick Ellis) Date: Sat, 28 Aug 2004 03:19:28 GMT Subject: Boa Constructor error References: <4712d252.0408260804.c69cfee@posting.google.com> <875af5e2.0408271135.7a19a30f@posting.google.com> Message-ID: <4RSXc.3563$uN5.2974@tornado.tampabay.rr.com> ake typed: > Uwe Grauer wrote >> >> Boa isn't ready for wxPython 2.5.x >> Use wxPython 2.4.2.4 instead. > > Anyone know what's happening to Boa, there doesn't seem to have been a > new version for over a year. Boa 0.3.0 and then 0.3.1 just came out in the last couple weeks. It has sizer support and updated documentation. It's still limited to wxPython 2.4, but Riann's plan was to finish up 0.3.0 on 2.4 and then start work on a version for 2.5. I'm hoping the next release will take less than a year :-). From aahz at pythoncraft.com Wed Aug 18 10:36:44 2004 From: aahz at pythoncraft.com (Aahz) Date: 18 Aug 2004 10:36:44 -0400 Subject: simple Thread question References: <1d6cdae3.0408171648.1b8767ea@posting.google.com> Message-ID: In article , Peter Hansen wrote: > >While it's true that that is all that's needed, it is not required, >and doesn't really provide any performance improvements. I often do >the above sort of thing where I use a given module in only one place, >especially when using threads where it feels subtly cleaner to defer >loading of some modules until the thread actually starts. Except that the import lock makes this a Bad Idea, IMO. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From jimmy at retzlaff.com Sun Aug 8 22:09:40 2004 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Sun, 8 Aug 2004 19:09:40 -0700 Subject: ODBC bug Message-ID: Elbert Lev wrote: > for ID, PWD in rs: > upd = "UPDATE TABLE SET PWD = \'%s\' WHERE ID = %u" % \ > (encode(PWD), ID) > mycursor.execute(upd) ... > #This script updates (encodes) passwords in the database, > #but does this rather slowly if the the recordset contains 2000 > records. Try replacing the above lines with something like this (untested, but should be close): upd = [] for ID, PWD in rs: upd.append((encode(PWD), ID)) mycursor.execute("UPDATE TABLE SET PWD = ? WHERE ID = ?", upd) This should perform pretty well for a few thousand records. For hundreds of thousands or millions of records you might want to write the contents of upd to a file and do a bulk insert to a temp table, then do an update with a join (if you'll be doing such an update often enough to justify the programming time). Jimmy From arargh407NOSPAM at NOW.AT.arargh.com Tue Aug 31 15:59:47 2004 From: arargh407NOSPAM at NOW.AT.arargh.com (arargh407NOSPAM at NOW.AT.arargh.com) Date: Tue, 31 Aug 2004 14:59:47 -0500 Subject: Xah Lee's Unixism References: <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4PGdnfsOfdDPi63cRVn-tA@speakeasy.net> <41337FC9.8070902@hotmail.com> <%T%Yc.29567$Es2.11957889@news4.srv.hcvlny.cv.net> <4134AC88.56452265@yahoo.com> Message-ID: <74m9j05av6cjpd4fs1mlatgmvlq98l9rmc@4ax.com> On Tue, 31 Aug 2004 17:43:34 GMT, red floyd wrote: >CBFalconer wrote: > >> Dump Notepad and get Textpad. www.textpad.com. First class. >> > >Let the editor flame wars begin! > >Get gvim! www.vim.org WordPerfect PE or later ED. No longer sold, AFAIK. -- Arargh407 at [drop the 'http://www.' from ->] http://www.arargh.com BCET Basic Compiler Page: http://www.arargh.com/basic/index.html To reply by email, remove the garbage from the reply address. From theller at python.net Mon Aug 16 11:41:21 2004 From: theller at python.net (Thomas Heller) Date: Mon, 16 Aug 2004 17:41:21 +0200 Subject: Knowing a COMObject by IID References: <8tSdnYPuvsYDIr3cRVn-vA@powergate.ca> Message-ID: <8ycfhyzi.fsf@python.net> Peter Hansen writes: > Mauro Baraldi wrote: > >> Someone can helpe-me how to get the name of a COMObject by it CLSID. >> Example: A object got a number CLSID >> ({CA8A9783-280D-11CF-A24D-444553540000}). >> It name is Acrobat Control for ActiveX. >> Or where can I found a good reference for this... > > The most direct method is to use "regedit" to search for it > in your registry. You can find it under HKEY_CLASSES_ROOT\CLSID > and the name will be under the default key for the entry. > > But I suspect you wanted to do this programmatically... > and I don't know the API you would use. >>> import _winreg >>> help(_winreg.QueryValue) Help on built-in function QueryValue: QueryValue(...) string = QueryValue(key, sub_key) - retrieves the unnamed value for a key. key is an already open key, or any one of the predefined HKEY_* constants. sub_key is a string that holds the name of the subkey with which the value is associated. If this parameter is None or empty, the function retrieves the value set by the SetValue() method for the key identified by key. Values in the registry have name, type, and data components. This method retrieves the data for a key's first value that has a NULL name. But the underlying API call doesn't return the type, Lame Lame Lame, DONT USE THIS!!! >>> _winreg.QueryValue(_winreg.HKEY_CLASSES_ROOT, "CLSID\\{CA8A9780-280D-11CF-A24D-444553540000}") 'Adobe Acrobat Control for ActiveX' >>> Thomas From sbabbitt at commspeed.net Thu Aug 26 21:12:03 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Thu, 26 Aug 2004 18:12:03 -0700 Subject: A newbie in need.... References: <9c3edc58.0408261609.6640e400@posting.google.com> Message-ID: <1093569633.981053@news.commspeed.net> "Chris Patton" wrote in message news:9c3edc58.0408261609.6640e400 at posting.google.com... > Hey everybody. I'm trying to make a program that requires a 2D field > to run. Besides "curses" or "ncurses", is there a python module that > will create a graph? > > --Thanks for the help! I like DISLIN at http://www.linmpi.mpg.de/dislin/, I've writen a Global Digital Evivation Data Viewer in wxPython that shows good (In my opionion) examples of shade, contour and 3d plots. You can get a copy at http://users.commspeed.net/tbabbitt/rbranch_strangness5.htm . (My python page) Tom From gerrit.muller at embeddedsystems.nl Fri Aug 20 04:53:05 2004 From: gerrit.muller at embeddedsystems.nl (Gerrit Muller) Date: Fri, 20 Aug 2004 10:53:05 +0200 Subject: Alternative decorator syntax decision In-Reply-To: <7x3c2iw9ig.fsf@ruckus.brouhaha.com> References: <7x3c2iw9ig.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > "Paul McGuire" writes: > >>I would propose a multivote survey: each poster gets 3 votes among the >>lettered choices on the Wiki page above. You can use all 3 for a single >>option, or split them across 2 or 3 options if you are open to more than >>one. > > > 1. My favorite variant was not in the list. > > 2. Any of the choices will have far reaching consequences that aren't > yet thought out very well. There is not yet enough experience > programming with the existing mechanisms (classmethods etc.) to > be sure what's really worthwhile. > > 3. There's not all that much discussion on the wiki of how other > languages do this stuff. > > 4. There's nowhere near consensus that any of the choices presented so > far are not plain horrible. > > My conclusion: Python 2.4 should not have new decorator syntax. Stay > with the existing stuff, for now. > > Discussion and exploration should continue and the question should be > revisited for 2.5. For 2.4, extend the current kludgy (decorators > separated from the function) mechanism if needed to provide necessary > functionality, but deprecate any new such feature as soon as it's > introduced, with the explanation that it's exploratory. Hear, Hear! I just replied in a similar way, before reading your response. regards Gerrit -- Gaudi systems architecting: From richard.scothern at gmail.com Fri Aug 6 09:44:37 2004 From: richard.scothern at gmail.com (Richy2004) Date: 6 Aug 2004 06:44:37 -0700 Subject: Unicode support Message-ID: I've experienced problems when trying to load a text file encoded with 2byte unicode characters. No matter what combination of the following I try, I always get an error when executing file.readline() file = open("file.txt", "r") file = open("file.txt", "rb") file = codecs.open("file.txt", "rb", "utf-16") file = unicode(open("file.txt", "r"), "utf-16") Even more strangely it does work when used in the interactive interpreter. Any ideas? Thanks, Richard From fred at acme.com Thu Aug 12 18:45:25 2004 From: fred at acme.com (Fred) Date: Fri, 13 Aug 2004 00:45:25 +0200 Subject: Python script to generate static site? References: Message-ID: On Thu, 12 Aug 2004 18:20:04 +0200, Walter D?rwald wrote: (snip) Thx a bunch everyone. I'll check all those out. Fred. From zathras at thwackety.com Thu Aug 12 20:14:58 2004 From: zathras at thwackety.com (Michael Sparks) Date: Fri, 13 Aug 2004 01:14:58 +0100 (BST) Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: <411bfa47$1@nntp.zianet.com> Message-ID: On Thu, 12 Aug 2004, Mark Bottjer wrote: > FWIW, I agree. That's why I like this option the best: > > class C: > def c(self): > meta: #declare, decorate, transform, fubar, whatever... > staticmethod > doc('Doc.') > pass FWIW, I _personally_ prefer this approach, and the reason I implemented J2 was solely because I went a) "oooh", b) it looks like it has the same advantages as the @pies c) the number of times it's been pointed out that syntaxes with decorators inside the function won't go anywhere, d) The wiki page said (sorta) that it couldn't be done. I can quite happily live with the @pie syntax, but _personally_ I find J2 clearer than @pie (and the above syntax you provide clearer still) and it also gives someone a keyword to lookup when reading code with it, rather than searching for punctuation. (punctuation also strikes me as more user/newbie hostile, but again, that's taste) Michael. From ben at benlast.com Wed Aug 25 04:40:56 2004 From: ben at benlast.com (Ben Last) Date: Wed, 25 Aug 2004 09:40:56 +0100 Subject: 100 % portable ? In-Reply-To: Message-ID: >From the Quasi source: def getHome(self): """Return the path to the home directory - a cross-platform equivalent of "~".""" #We try this on all OS's, since HOME is not set for plain vanilla #WIN32, but *is* set under Cygwin. Rather than use an exception, #and suffer the hit every time on Windows, use a key test. #NOTE; this is also done on Windows because I've had reports of people #explicitly setting HOME for some level of Posix-compatibility, so we #allow it to override the HOMEDRIVE/HOMEPATH here. if os.environ.has_key('HOME'): return os.environ['HOME'] #try the windows alternative; if HOME failed and we're under #some nature of win32 environment. if sys.platform == "win32": try: #we expect this to succeed. return os.environ['HOMEDRIVE']+os.environ['HOMEPATH'] except KeyError: pass #This is the default... no more we can really do. return "." I don't support Quasi under any Windows OS lower than 2k, so I freely admit to not having tested it on 95, 98 or Me :) ben > -----Original Message----- > From: python-list-bounces+ben=benlast.com at python.org > [mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of Dave > Cook > Sent: 23 August 2004 18:47 > To: python-list at python.org > Subject: Re: 100 % portable ? > > > In article <2otm5mFed44hU1 at uni-berlin.de>, Bernd Kaiser wrote: > > > You can use os.environ["HOME"], this will return the user's home dir. > > Doesn't work in win9x AFAIK. I do notice that some people are starting to > require XP for their apps. From slrn at toetsch.at Sat Aug 14 03:57:26 2004 From: slrn at toetsch.at (Leopold Toetsch) Date: Sat, 14 Aug 2004 09:57:26 +0200 Subject: Flython References: Message-ID: Christopher T King wrote: > (Unfortunately, AST trees don't match up exactly with Python grammar, so > I'm having to learn the format by trial-and-error. Not much fun. Is > there documentation on the AST forms anywhere?) Not really much at least in the python docs. You might have a look at ast2past.py in languages/python inside the parrot[1] CVS tree. Its a Python AST visitor that spits out a textual representation of the AST. It's not totally finished and is for 2.3. I didn't look at 2.4 yet. leo [1] http://www.parrotcode.org, there is a CVS interface too. -- Leopold Toetsch http://www.toetsch.at/linux/ - You're in a small chamber lit by an eerie green light. An extremely narrow tunnel exits to the west. A dark corridor leads ne. From mwh at python.net Wed Aug 25 07:27:20 2004 From: mwh at python.net (Michael Hudson) Date: Wed, 25 Aug 2004 11:27:20 GMT Subject: Inline Conditionals? References: Message-ID: Joshua Ginsberg writes: > Is there any plan to include inline conditionals in Python? For example: > > def isNegative(x): > return x < 0 ? True : False Read PEP 308, and note that this was probably the largest flamewar in Python history (well, before the still-ongoing decorators discussion...). But to answer your question: no. Cheers, mwh -- Linux: Horse. Like a wild horse, fun to ride. Also prone to throwing you and stamping you into the ground because it doesn't like your socks. -- Jim's pedigree of operating systems, asr From danmoskowitz at gmail.com Tue Aug 10 02:55:08 2004 From: danmoskowitz at gmail.com (Dan) Date: 9 Aug 2004 23:55:08 -0700 Subject: Python equivalent to a C trick Message-ID: <1d7b6d0d.0408092255.1177908e@posting.google.com> Is there a python equivalent of this trick in C? Logic_Test ? True_Result : False_Result Example: printf( "you have %i %s", num_eggs, num_eggs > 1 ? "eggs" : "egg" ); From chris.irish at libertydistribution.com Wed Aug 4 17:22:50 2004 From: chris.irish at libertydistribution.com (Chris Irish) Date: Wed, 04 Aug 2004 14:22:50 -0700 Subject: guide to introspecting python? In-Reply-To: References: Message-ID: <411153AA.9040205@libertydistribution.com> I saw that you work for pixar. Do they use python alot? Is it mostly for making tools for the artists or something else? And one last question does pixar use their own software for rendering or more commercial stuff like Maya/3d Studio Max. Sorry for being nosey. From unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom Sun Aug 1 02:27:18 2004 From: unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom (Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.) Date: Sun, 1 Aug 2004 08:27:18 +0200 Subject: transforming a list into a string References: Message-ID: +1 -- Michel Claveau From Jeffrey at Fro.man Fri Aug 20 00:28:55 2004 From: Jeffrey at Fro.man (Jeffrey Froman) Date: Thu, 19 Aug 2004 21:28:55 -0700 Subject: Rita Sue and Bob too References: Message-ID: M. Clift wrote: > But, how to I find a sequence in a list of unknown size? i.e. this > sequence in list of other names and replace it with three others? How about a generator? def slice(apple, worm, new_worm): while apple: if worm == apple[:len(worm)]: apple = apple[len(worm):] yield new_worm else: yield [apple.pop(0)] Jeffrey From fumanchu at amor.org Sun Aug 22 13:50:18 2004 From: fumanchu at amor.org (Robert Brewer) Date: Sun, 22 Aug 2004 10:50:18 -0700 Subject: J2 proposal: keyword Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E27@exchange.hqamor.amorhq.net> Roy Smith wrote: > Putting on my "Slightly Silly Party" hat, may I suggest that > "pie" meets > all of those constraints :-) I did leave out that important group: Silly: pie, SpanishInquisition, pythonic, stackless, sorcerize, etc... ;) Robert Brewer MIS Amor Ministries fumanchu at amor.org From john.burton at jbmail.com Thu Aug 19 17:56:59 2004 From: john.burton at jbmail.com (John Burton) Date: Thu, 19 Aug 2004 22:56:59 +0100 Subject: ANN: pyxe In-Reply-To: <41250363.6193453@news.t-online.de> References: <41250363.6193453@news.t-online.de> Message-ID: <4125222b$0$58822$5a6aecb4@news.aaisp.net.uk> Gerson Kurz wrote: > pyxe is a small executable that will run python scripts on a machine > that doesn't have Python installed. Example: You have the following > hello.py: Hmm, I tried it (on windows xp pro) and I get this error :- Traceback (most recent call last): File "C:\pyxe\pyxe_dumpmods.py", line 35, in analyze_modules exec('import %s' % scriptname) File "", line 1, in ? ImportError: No module named py This was just on the simple hello world program. Any ideas? From zoltan at teliko.net Sat Aug 7 06:51:17 2004 From: zoltan at teliko.net (Zoltan Sekeres) Date: Sat, 07 Aug 2004 12:51:17 +0200 Subject: Paul Graham on Python hackers References: Message-ID: On Fri, 06 Aug 2004 22:23:59 -0700, ellisjb wrote: > (In all seriousness I think python and java have a lot more in common than > python and perl.) This a flamebait, right? Otherwise I would be interested in the features which make Python similar to Java (shudder). -- Zoltan From anthonybaxter at gmail.com Thu Aug 19 23:16:56 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 20 Aug 2004 13:16:56 +1000 Subject: Alternative decorator syntax decision In-Reply-To: <412547B3.4020801@jessikat.fsnet.co.uk> References: <412547B3.4020801@jessikat.fsnet.co.uk> Message-ID: On Fri, 20 Aug 2004 01:37:07 +0100, Robin Becker wrote: > Is there any discussion about which versions are currently legal python > in Python-2.x x<4? I deal with lot's of cross version maintainance > issues and the very worst are where the syntax makes it illegal even to > compile the files. I believe that B is legal and has implementations for > earlier pythons available, but are others? Backwards compatibility is not considered a desirable goal. Don't forget that any code that uses generator expressions is _also_ invalid in Python 2.3 and earlier - and they'll be used a hell of a lot more than decorators. From anthonybaxter at gmail.com Fri Aug 27 00:42:34 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 27 Aug 2004 14:42:34 +1000 Subject: Call for signatories for J2 In-Reply-To: <2p7rurFhgglpU1@uni-berlin.de> References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> <7xhdqp967k.fsf@ruckus.brouhaha.com> <412e3ba4$0$92817$ed2619ec@ptn-nntp-reader02.plus.net> <2p7rurFhgglpU1@uni-berlin.de> Message-ID: On Fri, 27 Aug 2004 16:34:33 +1200, Greg Ewing wrote: > It came as a shock to people *in* python-dev, too. It just > appeared one day as a fait accompli, without any opportunity > for discussion. *shrug* I posted a couple of weeks before from Guido saying "here's another syntax that Guido is leaning towards", and asking for a volunteer to write a patch. Patch was done, there was a bit of back-and-forth in the patch tracker on SF, then it came down to a Guido decision. I don't know what additional discussion on python-dev would have accomplished. Almost no-one spoke up about the @syntax when I posted the first note. From roy at panix.com Sun Aug 8 11:24:32 2004 From: roy at panix.com (Roy Smith) Date: Sun, 08 Aug 2004 11:24:32 -0400 Subject: @decorator syntax is sugar, but for what exactly? (decorator libraries). References: Message-ID: In article , Andrew Durdin wrote: > On Sun, 08 Aug 2004 10:46:38 -0400, Roy Smith wrote: > > In article , > > > > Wow, I'm glad I asked. That answer is quite surprising, and somewhat > > disconcerting. Lot's of special cases going on here, which is bad. > > Well, I think I agree with the principle of limiting the expressions > to dotted names. Some of the possibilities if you allow arbitrary > expressions are pretty hairy: > > """ > Things someone might want to do, ordered roughly from most reasonable > to least reasonable ;) > @foo().bar() > @foo or bar > @mydecorators['foo'] > @lambda f: foo(f) or bar(f) > """ > (from http://mail.python.org/pipermail/python-dev/2004-August/046673.html) You can always do lots of hairy things all over the place. Shall we limit functions to no more than 4 arguments? Assignment statements to no more than 5 operators? Function calls to nesting no more than 3 deep? I'm not in favor of hair, but the way to contain it is with good style and practice, not with arbitrary constraints in the grammar. The most simple thing is the most general thing. The thing after the @ gets called, therefore it must be a callable object. I don't see any need to specify anything further. It's not good style to crassly split infinitives either, but it sure would be annoying if my news client prevented me from doing it. From hawk at slytherin.ds.psu.edu Fri Aug 27 11:24:43 2004 From: hawk at slytherin.ds.psu.edu (Dr. Richard E. Hawkins) Date: Fri, 27 Aug 2004 15:24:43 +0000 (UTC) Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: In article , R Baumann wrote: > >"Xah Lee" wrote in message >news:7fe97cc4.0408251356.34f2102a at posting.google.com... >> Larry Wall and Cults >> (Lazyness, Impatience and Hubris) >> 200012 >In this context --- This is the STUPIDEST thing I've ever heard. Nah. I practiced law for five years. :) hawk -- Richard E. Hawkins, Asst. Prof. of Economics /"\ ASCII ribbon campaign dochawk at psu.edu 111 Hiller (814) 375-4846 \ / against HTML mail These opinions will not be those of X and postings. Penn State until it pays my retainer. / \ From fumanchu at amor.org Sun Aug 22 00:42:24 2004 From: fumanchu at amor.org (Robert Brewer) Date: Sat, 21 Aug 2004 21:42:24 -0700 Subject: Overriding logical operators? Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E21@exchange.hqamor.amorhq.net> Andrew Durdin wrote: > I suppose now I ought to say why I need to to do more than that. I've > got a situation where I want to construct an expression, but evaluate > it later when I get more information. I came up with a "DelayedEval" > class, the instances of which can have operations performed on them, > but the result is not evaluated until a particular method is called. > I'm currently overriding all the operators I can, so that these > instances can be handled in a fairly normal fashion for the most part. > For example: > > foo = DelayedEval() > foo = (-foo + 15) * 3 > foo_positive = (foo >= 0) > > print foo.evaluate(10) # prints 15 > print foo.evaluate(20) # prints -15 > print foo_positive.evaluate(10) # prints True > print foo_positive.evaluate(20) # prints False > > In this situation, merely overriding the __nonzero__ method will not > allow me to delay the evaluation of the logical boolean operators; to > do that I need to be able to override them. > > The alternative solution that I can see to the issue is to use lambdas > to create the expressions I need, and calling them to evaluate them, Having written all four alternatives (which you're going to write ;), you also have the options of: 1) Using & and | instead of 'and' and 'or'. In this way, you can override within the class in the same maneer you do for gt, lt, etc. 2) Bytecode hacks. A fairly useful implementation of the latter (which I wrote and use regularly in my ORM) is available at http://www.aminus.org/rbre/python as 'logic.py'. It's in the public domain--steal it if you want. If you really, really want an implementation of the former, I can probably dig one up. Robert Brewer MIS Amor Ministries fumanchu at amor.org From indigo at bitglue.com Mon Aug 23 21:09:00 2004 From: indigo at bitglue.com (Phil Frost) Date: Mon, 23 Aug 2004 21:09:00 -0400 Subject: Getting at the bits of a 32-bit integer In-Reply-To: <412A8B00.A81AA015@alcyone.com> References: <85b54e91.0408231552.75f85727@posting.google.com> <412A8B00.A81AA015@alcyone.com> Message-ID: <20040824010900.GA834@unununium.org> Then you have paid the cost of a bool, and then some. > So use a Python long instead! That way the size of the Python int is > irrelevant. > > -- > __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ > / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis > \__/ It should therefore be difficult in a republic to declare war; but > not to make peace. -- John Story > On Mon, Aug 23, 2004 at 05:25:36PM -0700, Erik Max Francis wrote: > Phil Frost wrote: > > > However, doing this sort of thing is rather nonpythonic. Python > > abstracts the platform's representation of an integer. Integers in > > Python arn't always 32 bits; they are actually the size of C's 'long' > > type, which is to say you can find the size by looking at sys.maxint, > > but it's more trouble than it's worth. You will also encounter > > problems > > if you change the highest bit: > > > > >>> 10 ^ (1 << 31) > > __main__:1: FutureWarning: x< > a long in Python 2.4 and up > > -2147483638 > > > > Note that the error message isn't even accurate. This is probably a > > good > > indication that this isn't a common use case! > > > > So, short story: use a bool (True/False) From aleaxit at yahoo.com Mon Aug 30 05:59:41 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 30 Aug 2004 11:59:41 +0200 Subject: Generator expressions v/s list comprehensions References: <1gj8y77.6qshr41q531veN%aleaxit@yahoo.com> <87llfywooz.fsf@sinken.local.csis.hku.hk> <1gjbs1e.assxlxlud1m0N%aleaxit@yahoo.com> <7xbrgtrq4r.fsf@ruckus.brouhaha.com> Message-ID: <1gjbx8e.1y0xn2mpoap5dN%aleaxit@yahoo.com> Paul Rubin wrote: > aleaxit at yahoo.com (Alex Martelli) writes: > > It would sure be nice if Python had been born back from day one with all > > the neat features it has taken years to develop -- that way we wouldn't > > have any issues that are there just because of backwards compatibility. > > > > Unfortunately, this wish is totally unrealistic -- obviously people do > > come up with cool ideas such as the iterator protocol, and generators, > > after the language has been around for a while. > > And yet a lot of the unrealisticness comes directly from the Python > culture. Maybe it took a while to think up the iterator protocol, but > what about nested scopes? What about the += operator? How about the > sorted() method on lists? One could go on and on with more examples > like that. ...and some of the examples would be wrong, just like yours about "the sorted method on lists" -- sorted is a new built-in function in 2.4, not a method on lists, and it accepts any sequence, not just a list. > These things exist in other languages and had been > requested in Python for years before they got accepted. And every A million other features satisfy this description D: they exist in other languages and have been requested in Python for years. Indeed, it's hard to think of ANY feature which exists in other languages and has NOT been requested for Python. > time some little thing gets added changing the language, that creates > a new mini-dialect that users have to remember for a while and then > forget. The result is "version fatigue"; one gets bleary trying to > remember what's in the language this week. Those features are in > other languages for a reason, and there's been enough experience using > them (in those languages) that their desirability for Python should > never have seriously been in question. So it would have been better > to include them from the beginning, instead of through separate > episodes of prolonged agony for each one. If Python included every features satisfying description D, then Python would be the largest, bulkiest, most unwieldy language in the world -- in fact I think even including half the features in D would be plenty to make Python completely unusable. That a dozen features satisfying D have indeed been included is therefore a silly argument, considering that a gross more features satisfying D have not been included and hopefully never will. Moreover, the specific feature we're discussing, generator expressions, doesn't really satisfy D (what Haskell has is not quite the same thing, you know), making your argument even weirder. All features that are in any programming language are there for a reason (not necessarily a good one -- some languages may have been designed on principles close to those implied by this silly criticism you are expressing, for example) and, for old enough languages, there has been enough experience using them. Nevertheless it's perfectly proper and indeed wise to seriously question their desirability for Python. I bet that if you took a feature satisfying description D, you'd find a chance of more than 90% that it would be totally silly to have it in Python and that it will never be there. Finding out what dozen, out of dozens of dozens, of features satisfying D, would work well with Python, and which ones wouldn't, is obviously not something that can be rushed. Sure, introducing some feature in every release is not ideal, but there is really no alternative that is even in the least sensible at all. So, I find your criticisms unfounded. Alex From me at privacy.net Fri Aug 13 13:47:51 2004 From: me at privacy.net (Richard Hanson) Date: Fri, 13 Aug 2004 10:47:51 -0700 Subject: Rather than decorators, how about sections? References: Message-ID: [Bystander delurking -- idle musings...] [Paul Morrow wrote:] >Hmmm... did I say 'aspect'? Maybe instead of cluttering up the code >with all of these 'declarations' (which is clearly where the decoration >movement is headed), we should have some sort of companion file that >contains these annotations, similar to what you see in the AOP languages. Splork! -- And just yesterday, continuing to note all the discussion in py-dev (and here) involving just where in the *linear* layout of the code the decorators should go, I thought that maybe we need tables -- two-dimensional coding (orthogonal beats flat)...? 1) A column of cells (of lines, blocks?) for what we now use as our single, linear arrangement (lines) of code. 2) A column of cells for decorators and the like -- decorators would go in the cells alongside the decorated code. 3) Perhaps a column for source code documentation. 4) [...] (Of course, then we'd need new editors, etc.) ;-) thinking-laterally-y'rs, Richard -- R Hanson [The mangled email addie below works.] sickolefartnewsguycom From alanmk at hotmail.com Tue Aug 10 09:12:26 2004 From: alanmk at hotmail.com (Alan Kennedy) Date: Tue, 10 Aug 2004 14:12:26 +0100 Subject: Fixing socket.makefile() In-Reply-To: References: Message-ID: <%N3Sc.24735$Z14.7608@news.indigo.ie> [Bryan Olson] > The problem is that makefile() returns a Python object that has > its own local buffer. The recv() call reads directly from the > socket, oblivious to any data queued in the file object's > buffer. The problem is not limited to recv(); select(), and > perhaps other calls, will ignore the buffer and look directly at > the socket. Output buffering appears to have a similar problem. and > The Python Library Reference is silent on whether the > socket.makefile operations are supposed to interact correctly > with the direct socket operations. If they are supposed to play > well together, then read() is wrong. If they are not, then > readline() is absurdly slow. I'm glad you asked these questions ;-) I also am interested in the answers, because I'm just coming to end of my implementation of cpython 2.3 compatible socket, select and asyncore modules for jython, i.e. asynchronous socket support, using the new java.nio APIs in jdk1.4+. Points to make in relation to jython include 1. The problem you describe doesn't arise very often, I think. Most users who use makefile() on sockets are going to use the file-based interface exclusively and not the underlying socket interface. 2. The problem does not exist in jython, because jython implements the socket.makefile() method by returning wrappers on the java.net.socket's InputStream and OutputStream, meaning that calling either file or socket interface sends data through the same underlying streams. 3. I am eager to have the behaviour of cpython explicitly defined, since I am working hard to make my jython implementation 100% cpython compatible, right down to the exceptions. I want all cpython socket code to not know that it's running on jython. 4. I'm particularly interested in seeing documentation on how read and write operations on socket.makefile()s should behave when the socket is in non-blocking mode: Should it raise an exception? Which exception? The same exception on every platform? P.S. To those who know I've working on this for *ages* now: apologies (Hi Irmen :-) My finances have prevented me from spending too much time working on this voluntary project. However, you may be encouraged to know that I now have it passing most of the cpython 2.3 test_socket.py unit tests (including the ones that use select.select). It's only a matter of a month or two more now ..... Out of interest: Does anyone know if developing asynch-socket support for jython is the sort of work that might fall under the auspices of the PSF grant scheme? -- alan kennedy ------------------------------------------------------ email alan: http://xhaus.com/contact/alan From clarkcase at gmail.com Wed Aug 4 13:34:48 2004 From: clarkcase at gmail.com (Clark Case) Date: 4 Aug 2004 10:34:48 -0700 Subject: Downsampling streaming MP3s in Windows... Message-ID: I've been playing around with Edna, which is a Python streaming MP3 server. My setup is a WindowsXP box with Python 2.3. I'd like to downsample my high bitrate files, and based on some suggestions I found on the Edna mailing list, I replaced the line where the MP3 was being opened with the following line: f = win32pipe.popen('c:\lame\lame --mp3input -f -b 64 "' + fullpath + '" -', 'r') where "fullpath" contains the path to the MP3 file. When try to listen to the results through WinAmp, the stream seems to buffer up, but then I get a few seconds of choppy noise and then nothing. Do I need to somehow buffer the pipe on the server side? Any suggestions would be appreciated. Thanks, Clark From andrewm at object-craft.com.au Fri Aug 27 21:11:29 2004 From: andrewm at object-craft.com.au (Andrew McNamara) Date: Sat, 28 Aug 2004 11:11:29 +1000 Subject: Class Friends In-Reply-To: References: <20040827081556.657c3fac.a@c.d> Message-ID: <20040828011129.E4A6B3C113@coffee.object-craft.com.au> >Really, the double-under mangling is more about stopping a subclass >from stomping on some internal detail of the base class. In general, >though, I've found it to be a complete pain in the arse - there's been >too many times where I've been using an external library and wanted to >hook into the base class to fix something, and had to use the mangled >name. It's more useful when using Mixin classes - as you say, a subclass could validly want to mess with the implementation of a base class, but a mixin shouldn't need to touch the internals of another. -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ From peter at engcorp.com Tue Aug 3 11:44:30 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 03 Aug 2004 11:44:30 -0400 Subject: Crypto.PublicKey.RSA.error: Plaintext too large In-Reply-To: References: Message-ID: Ajay Brar wrote: > I am getting an error - Crypto.PublicKey.RSA.error: Plaintext too large > - when verifying the signature of a document. > What i am doing is - the document and the signature are downloaded off > the net, my verify script then connects to a server and obtains a public > key. It then uses the public key to verify the signature. > The whole thing works fine when i do the same thing in the interactive > interpreter. Its only when i download the files and obtain the public > key from the server and then verify, that i get the above error. > > any suggesstions...ideas??? Carriage Return/Line Feed problems? Or trailing newline problems? -Peter From squirrel at WPI.EDU Thu Aug 12 16:06:58 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 12 Aug 2004 16:06:58 -0400 Subject: multiline snippets with triple quotes In-Reply-To: References: Message-ID: On Thu, 12 Aug 2004, Christoph Zwerschke wrote: > So, what would be the pythonic way to implement such multiline snippets? The textwrap.dedent() function is provided for just this purpose: from textwrap import dedent if output == html: snip = dedent('''\ Hello, World

    What's up?

    ''') else: snip = 'Hello!' textwrap.dedent() removes uniform indentation from the beginning of each line in the string, so you can still insert desired indents in a natural way. Note the backslash after the opening quote, and how the actual string starts on the next line: dedent() isn't as smart as pydoc when it comes to uniformly indenting strings; it doesn't know to skip the first line (this helps with more general usage, though). From aleaxit at yahoo.com Thu Aug 26 17:08:59 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 23:08:59 +0200 Subject: Inline Conditionals? References: Message-ID: <1gj5est.1598gj51gx6sgrN%aleaxit@yahoo.com> Robert Brewer wrote: ... > > aux = [] > > for x in Somelist: > > if x.property: > > aux.append(foo(x)) > > else > > aux.append(foo(x)) > > > > would be vastly more readable; "sparse is better than dense" > > and any LC > > is far too dense to be Pythonic here. > > Case in point: it makes it *vastly* easier to see the typo. What > happened to bar()? Closing hours...? > But you planned that so someone else could deliver the punch line, > didn't you? ;) Ahem, yes, why, sure! Alex From jdhunter at ace.bsd.uchicago.edu Tue Aug 3 08:55:22 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Tue, 03 Aug 2004 07:55:22 -0500 Subject: How to dynamically access Numeric subarrays In-Reply-To: (Gaubitzer Erwin's message of "Tue, 03 Aug 2004 13:29:44 +0200") References: Message-ID: >>>>> "Gaubitzer" == Gaubitzer Erwin writes: Gaubitzer> The problem is that the input data varies in its Gaubitzer> dimensions so my wanted data can appear at different Gaubitzer> positions of the array. I tried to create a list with Gaubitzer> the slice on the appropriate position to use it as Gaubitzer> indices list in the array but this failed. Gaubitzer> So my questions to out there: How can I extract a Gaubitzer> (Numeric Python) subarray whose indices have to be Gaubitzer> built dynamically. In Numeric, use the take function >>> x = arange(100) >>> ind = [23,24,25] >>> take(x,ind) array([23, 24, 25]) In numarray, you can use index arrays. See section 4.8 of the numarray manual for more information - http://www.stsci.edu/resources/software_hardware/numarray/manualPDF >>> x = arange(100) >>> ind = array([23,24,25]) >>> x[ind] array([23, 24, 25]) Cheers, JDH From deets.nospaaam at web.de Thu Aug 19 08:57:09 2004 From: deets.nospaaam at web.de (Diez B. Roggisch) Date: Thu, 19 Aug 2004 14:57:09 +0200 Subject: timer problem References: <7j1Vc.218972$p67.10887223@phobos.telenet-ops.be> Message-ID: <2ojmcfFbfpq0U1@uni-berlin.de> flupke wrote: > Now, when i run it, it only prints TIMER CALLED once instead > of every 2 seconds. > What am i doing wrong? (Python 2.3.4 on Win2000) You assume that Timer is looping - it isn't. So make your command start a Timer itself, like this: def command(): print "called" t = threading.Timer(2, command ) t.start() Or use a Thread, with an endless loop in the run()-method that sleeps for two secdonds. That spares you the overhead of thread-creation. Regards, Diez From sbabbitt at commspeed.net Mon Aug 2 19:57:13 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Mon, 2 Aug 2004 16:57:13 -0700 Subject: Newbie: pywin problem References: Message-ID: <1091491406.159993@news.commspeed.net> "Martin DeMello" wrote in message news:rCrPc.154159$Mr4.50525 at pd7tw1no... > Here's a transcript: > > >>> import win32ui > >>> template = pywin.mfc.docview.DocTemplate(None) > >>> doc = pywin.scintilla.document.CScintillaDocument(template) > >>> view = pywin.scintilla.view.CScintillaView(doc) > >>> fr = win32ui.GetMainFrame() > >>> view.CreateWindow(fr) > > Now how do I get the window to display? I thought the call to > CreateWindow would do it, but the window just gets created silently. > > martin I would try wxPython at http://wxpython.org/ they have a wrapper for scintilla and are it is much more Pythonic. You probably need to do a somename = view.CreateWindow(fr) somename.Show(1) to get your current app to work, but Win32Ui is kinda funny. Tom Babbitt From paul at boddie.org.uk Fri Aug 20 09:44:00 2004 From: paul at boddie.org.uk (Paul Boddie) Date: 20 Aug 2004 06:44:00 -0700 Subject: My only complaint about Python References: Message-ID: <5339b60d.0408200544.5159c8a2@posting.google.com> Tim Peters wrote in message news:... > > So you get a fine Cygwin port from Jason Tishler, [...] Yes, it certainly is a great port! I'm rarely using the native Python under Windows, but then Cygwin is an island of sanity in that environment. Paul From John.Marshall at ec.gc.ca Thu Aug 5 10:17:25 2004 From: John.Marshall at ec.gc.ca (John Marshall) Date: 05 Aug 2004 14:17:25 +0000 Subject: tweaking @decorator syntax In-Reply-To: References: Message-ID: <1091715445.9931.17.camel@mango.cmc.ec.gc.ca> On Thu, 2004-08-05 at 08:41, Sandy Norton wrote: > On 4 Aug 2004, Christopher T King wrote: > > > Of course, I prefer the nested block idea better (either with a new > > keyword or new syntax), but I don't see those (especially the syntax one) > > flying anytime soon. > > I know further discussion of this topic is feeling futile, but one can only hope. > > > Unless someone can come up with an idea everyone can agree on Real Soon > > Now, I think the whole idea should be dropped and wait until 3.0. We'll > > have plenty of time to argue about it then. > > Agreed. > > > Sorry about the long rant, but it felt good to get that all off my chest. > > Please, we need more rants like yours. Now if they could somehow > collectively become a 'public outcry' (-; > > I realize my hasty initial post didn't actually show the present 2.4 form, > so I've included it and added your variations for the sake of comparison: > With the current choice and the list of alternatives you gave, two things struck me about the location of the decorators in the current choice: 1) They seem to be in the wrong place with respect to what they are affecting. 2) Can decorators easily be extended to apply to class and module? Whether or not the @ or some other operator/keyword/etc. is used, what is more easily understandable/readable? ----- class Klass: def __init__(self, name): self.name = name @staticmethod def statmethod1(x): return x @classmethod def classmethod1(cls): return cls @funcattrs(name='GvR', language='python') @log(file='func.log') def sayhello(self): print 'hello python world' ----- or ----- class Klass: def __init__(self, name): self.name = name def statmethod1(x): @staticmethod return x def classmethod1(cls): @classmethod return cls def sayhello(self): @funcattrs(name='GvR', language='python') @log(file='func.log') print 'hello python world' ----- If the decorators are metadata, that may be extended to affect not only functions or methods, but classes, and modules(?), I would think that wherever a variable or function call would go that would affect the function, method, class, or module, is the right place for a decorator. In the alternative above, it _may_ be that the decorators would only be valid if they are located in specific locations, e.g., before any non decorator (or comment, or __doc__ information) statements. John From grante at visi.com Mon Aug 30 13:26:10 2004 From: grante at visi.com (Grant Edwards) Date: 30 Aug 2004 17:26:10 GMT Subject: Size of a remote URL References: Message-ID: <41336331$0$65608$a1866201@newsreader.visi.com> On 2004-08-30, Justin wrote: > I want to track the download of files in a progress bar. I asume I > need the final size to do that so I can compare it to the current size > on disk. Correct. > Le tme know if you know anything I know lots of things. :) But, if the server doesn't tell you the content length in the HTTP headers, there's nothing you can do. -- Grant Edwards grante Yow! .. does your DRESSING at ROOM have enough ASPARAGUS? visi.com From rnd at onego.ru Mon Aug 16 05:56:08 2004 From: rnd at onego.ru (Roman Suzi) Date: Mon, 16 Aug 2004 13:56:08 +0400 (MSD) Subject: Best programming language In-Reply-To: References: Message-ID: On Mon, 16 Aug 2004, lopex wrote: >Roman Suzi wrote: > >> ;-) >> >> Just type into google >> "best programming language" >> and press (I am lucky) > >Ruby ? This probably indicates that Python in not well enough described as "best" for certain domains while Ruby isn't as humble ;-) >Marcin Mielzynski Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3 From evenprimes at gmail.com Mon Aug 9 09:28:39 2004 From: evenprimes at gmail.com (Chris Cioffi) Date: Mon, 9 Aug 2004 09:28:39 -0400 Subject: Exceptions as a Control Structure In-Reply-To: References: <411775aa$0$17867$626a14ce@news.free.fr> Message-ID: And don't forget about: for key in sequence: foo = dictionary.get(key, "not found") :) Chris On Mon, 09 Aug 2004 09:16:28 -0400, Roy Smith wrote: > In article <411775aa$0$17867$626a14ce at news.free.fr>, > Olivier Parisy wrote: > > > Hi all, > > > > I am new to Python (I just finished Guido's tutorial). > > I was very surprised to learn there that the StopIteration > > is used to end for loops in a standard iterator setting. > > > > I come from C++, where the use of exceptions as control > > structures is frowned upon for efficiency reasons. > > > > What is the Python canon on this topic ? Are exceptions > > considered as reasonable control structures, or is > > StopIteration alone of its kind ? > > Lots of things you do in C++ are frowned upon in Python. Lots of things > you do in Python are frowned upon in C++. > > Specifically, exceptions in C++ are generally considered fairly > heavy-weight, but not so in Python. Here's another common python idiom > that uses exceptions in a way which would probably horrify most C++ > people: > > for key in sequence: > try: > foo = dictionary [key] > except KeyError > foo = "not found" > > instead of: > > for key in sequence: > if dictionary.has_key (key): > foo = dictionary [key] > else > foo = "not found" > > If you're reasonably sure that most of the keys will be found in the > dictionary, it's probably faster to just try them all and handle the > occasional exception than to test each key to see if it exists. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Still searching for an even prime > 2! From ggg at zzz.it Tue Aug 31 12:03:39 2004 From: ggg at zzz.it (deelan) Date: Tue, 31 Aug 2004 18:03:39 +0200 Subject: mySQL access In-Reply-To: References: Message-ID: Greg Lindstrom wrote: > Hello- > > I'd like to connect to a mySQL database from Python 2.3 on Windows XP. I've > read up on the mySQLdb module, but do not have Microsoft Visual Studio for > the C++ compile part of the exercise. Am I hosed? Or is there a way do > this without having to have VS? maybe i'm missing something, but there is a win32 binary download for mysqldb 1.0 on sf.net: project page: HTH, deelan -- @prefix foaf: . <#me> a foaf:Person ; foaf:nick "deelan" ; foaf:weblog . From adurdin at gmail.com Mon Aug 16 01:08:22 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Mon, 16 Aug 2004 15:08:22 +1000 Subject: Python indentation deters newbies? In-Reply-To: References: <3064b51d.0408130615.3fc4a760@posting.google.com> <30260531.0408131853.18ec2446@posting.google.com> Message-ID: <59e9fd3a04081522086610a064@mail.gmail.com> On Mon, 16 Aug 2004 00:44:32 -0400, Peter Hansen wrote: > > I'm curious why more people don't have "neat!" as their very > first thought on encountering this, rather than "yuck!". When I first encountered python, my response was "yuck" also, though replaced in a few days with "neat". Having programmed quite a bit in C (with explicit begin and end markers), as well as Basic (with explicit end markers only), I think the initial reaction was mostly due to lack of acclimatisation to having no explicit block end-markers. From bokr at oz.net Thu Aug 26 15:46:19 2004 From: bokr at oz.net (Bengt Richter) Date: 26 Aug 2004 19:46:19 GMT Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> Message-ID: On Thu, 26 Aug 2004 11:15:46 -0400, Paul Morrow wrote: >Anthony Baxter wrote: > >> On Thu, 26 Aug 2004 09:50:43 -0400, Paul Morrow wrote: >> >>>Ok. Then let's jettison the baggage with the word metadata and just >>>call them 'magic attributes'. It doesn't matter. The essential point >>>about them is that they almost /never have 'local variable' semantics/. >>>They are attributes of the object being defined. That's the point I'm >>>trying to drive home here. When we define __xxx__ attributes, we are >>>not intending to create local variables. No. We are making declarations. >> >> >> Explain to me how __getitem__ is a declaration while getMonkey is not, >> assuming both are methods. >> >> The only magic attribute that fits your case of "magic attribute" is >> __metaclass__. >> The overwhelming number of double-under names are not magic >> attributes, or metadata, or whatever you want to call them. > >__getitem__ is most certainly magical! Defining it 'declares' >(implicitly, but we'll ignore that governing zen rule for the moment) >that instances of the containing class have dictionary semantics (that >they can be used, in some degree, like dictionaries). That's magic. No, it's convention. The convention is that you should write __getitem__ methods for YourClass so that if ycinst = YourClass() then ycinst[key_or_index] will not break expectation of dict-like or sequence-like access too badly. But you are free to break the convention. The __getitem__ name serves as a hook into implementation of ycinst[key_or_index] which has been designed to use __getitem__ in a predictable way. Similarly with other double-underscore methods. The names don't declare anything. Their use in a predictable way by generated code just gives you the opportunity to hook in your own magic for source that translates to use of such methods. Your proposal exposes the peculiar sematics of the doc string, which really should become a discarded string expression where it now appears. IMO it might have been as good or better to capture text from the first block of comments inside a function and bind __doc__ to that. Then statement semantics would have been more consistent. But you are going in the other direction, expanding on special statement semantics in special contexts, and making double underscore names into special sugar for something more than names, not just special names with special conventional bindings. I.e., your __xxx__ becomes a spelling for foo.__xxx__ etc. and an implied moving of the code to post-definition execution context. I'd rather do that with a prefixed using: block than with special interpretation of names. I would rather see see some way to access the current object and its environment without using its post-definition name binding, and controlling _when_ statements execute. The decorator syntax provide a when of post-def-execution-pre-name-binding and it provides current-object binding via the binding to the parameter in the decorator call. The _when_ for statements in a function body is during-call-execution. I'd like some of the internal whens to be exposed and hookable. E.g., expanding on try/finally to provide keyword:suite syntax for what is e.g. currently done with default-argument hack -- i.e., def-execution-time initialization of values for every-call-time initialization of local bindings to those values. A version of that might provide persistent local bindings -- like a private writable closure. A __self__ magic binding could provide access to the current object, and __self__.__enclosing__ could be magic for accessing the textually enclosing entity, which might have another enclosing entity, so __self__.__enclosing__.__enclosing__ would then be legal. Dynamic spaces similarly, perhaps locals() and outwards to locals(1) etc. >That's meta. That's profoundly deeper than anything defining getMonkey >does. ISTM you are looking at __getitem__ from the wrong end of the magic. The name is a standard method name that various specific source code texts will generate code to access, e.g. x[3] or x.__class__.__dict__['__getitem__'](x, 3). The magic is in what people have done with the names, not the names themselves. The source spelling for generating code using the __metaclass__ name is admittedly a bit more mysterious than x[y] generating code using __getitem__ ;-) Regards, Bengt Richter From FBatista at uniFON.com.ar Fri Aug 6 09:35:52 2004 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Fri, 6 Aug 2004 10:35:52 -0300 Subject: [Newby question] List comprehension Message-ID: [Eelco Hoekema] #- # song filter: will return true if the file seems to be an mp3 file. #- # (may not be the best way to do this) #- def song(f): #- (name, ext) = os.path.splitext(f) #- return ext.lower() == '.mp3' #- #- # list comprehension walking through a directory tree #- [(root, filter(song, files)) for (root, dir, files) in #- os.walk(os.path.abspath('.')) if filter(song, files)] #- #- #-
    #- #- Now, this will work. However, it seems kind of silly to call #- the filter #- twice. Is there a way to keep this in one list #- comprehension, but with #- just filtering once? files = [] for (root, dir, files) in os.walk(os.path.abspath('.')): mp3files = filter(song, files) if mp3files: files.append((root, mp3files)) Now, explain me why a list comprehension is better here. . Facundo From jeff at ccvcorp.com Tue Aug 17 16:26:46 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Tue, 17 Aug 2004 13:26:46 -0700 Subject: Generators versus Coroutines In-Reply-To: References: Message-ID: <10i4qeokpk4led5@corp.supernews.com> Michael Sparks wrote: >On 17 Aug 2004, Paul Rubin wrote: >... > > >>No, pure includes C modules included with the interpreter. >> >> > >See, this I find a ridiculous assertion. After all the modules that get >included changes. That means one week one implementation will be viewed as >impure and the next week pure. That's why I think the whole notion of >purity is ridiculous. > > The included modules will only change with new versions of Python (and not necessarily then). In practical terms, the need to consider Python version is more important for minor syntax incompatibilities than for "pure"-ness considerations, but this definition makes it quite clear whether something is "pure" Python for any given Python version. And really, it's not *that* common for major extension packages to start out independently and then later be incorporated into the Python standard distribution. There's a few examples, sure... but it's not like the list of included modules changes much from week to week, as your objection seems to be implying. Keep in mind, too, that when people talk about something being "pure" Python, they're using a practical definition of "pure" rather than a pure (theoretical) one. ;) It's very practical to say, "This program is pure Python and runs on version 2.2 or later." That tells me that if I've got a 2.2 or 2.3 interpreter installed, it'll work on my machine -- I don't have to worry about whether I can find or compile binaries that'll work for my particular system. I don't care whether or not the Python standard library ever calls into compiled code, all I care about is whether *I* need a compiler to install it. (This is especially a problem on Windows, where compilers are rarely present; *nix machines usually have gcc (or some other cc) installed by default, but compilers are not present by default on Windows.) Jeff Shannon Technician/Programmer Credit International From rogerb at rogerbinns.com Wed Aug 11 02:04:44 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Tue, 10 Aug 2004 23:04:44 -0700 Subject: VB-like GUI designer? References: <30260531.0408102005.5847b9c@posting.google.com> Message-ID: <3hpou1-09i.ln1@home.rogerbinns.com> simo wrote: > I noticed you have RPMs for Linux - so what do they include - a > complete wxWidgets/GTK+/Python distribution, plus your files? $ rpm -qpl dotamatic-0.2-0.i386.rpm /usr/bin/dotamatic /usr/lib/dotamatic-0.2 /usr/lib/dotamatic-0.2/_localemodule.so /usr/lib/dotamatic-0.2/dotamatic /usr/lib/dotamatic-0.2/dotamatic.css /usr/lib/dotamatic-0.2/libwx_gtkd-2.4.so /usr/lib/dotamatic-0.2/mathmodule.so /usr/lib/dotamatic-0.2/pcre.so /usr/lib/dotamatic-0.2/pwdmodule.so /usr/lib/dotamatic-0.2/resources /usr/lib/dotamatic-0.2/resources/dotamatic.htb /usr/lib/dotamatic-0.2/resources/standard.jpg /usr/lib/dotamatic-0.2/strop.so /usr/lib/dotamatic-0.2/timemodule.so /usr/lib/dotamatic-0.2/wxPython.htmlc.so /usr/lib/dotamatic-0.2/wxPython.wxc.so The file in /usr/bin is a shell script that just execs the dotamatic binary in /usr/lib. The dotmatic executable is actually the Python interpretter with an archive containing the bytecode appended. Only the Python and wxPython modules used are present. If you have a look at my BitPim project file you can see something that does a lot more, and consequently has way more modules included. You can compare the above directory to the one installed on Windows and will find they are remarkably similar. The Mac one is also similar but has some underlying differences. Roger From sheldon.johnston at home.firstnet.se Tue Aug 10 16:16:40 2004 From: sheldon.johnston at home.firstnet.se (Sheldon) Date: 10 Aug 2004 13:16:40 -0700 Subject: Image Message-ID: <76655b52.0408101216.4c227052@posting.google.com> Hi, Does anyone know how to read an array back into python after writing it to a .dat file using tostring()? My method using Image results in a valueerror: data is not enough... x = open('file.dat') array = x.read() print array : results in unreadle garble while im = Image.fromstring('I', (81,81),array) gives the valueError: data not enough... The tutorial on Image leaves a lot to be desired. Any help or new ideas would be welcomed! thanks, Sheldon From martin at v.loewis.de Fri Aug 6 04:25:17 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 06 Aug 2004 10:25:17 +0200 Subject: Python milestone releases In-Reply-To: References: Message-ID: <4113406D.1@v.loewis.de> Thomas D'Tak wrote: > The question is now, how to handle this kind of problems? The Python Business Forum once tried to attack the problem by planning to release a "Python-in-a-tie" release. This release would be maintained essentially forever, and they wanted PythonLabs to commit that this release is not superceded by another release for atleast a year. Python 2.2 was chosen as the basis, and indeed, it lived for 18 months without a successor. Today, 2.2 is not maintained anymore by the "usual" maintainers, which have moved towards 2.3 and 2.4. Nobody has taken over maintenance of 2.2, from which I conclude there is really no need for ongoing maintenance of old releases. Now, if your partners are still running Python versions too old for your software, the pressure to upgrade should come from you, the one who needs the newer version. Python supports side-by-side installation of multiple versions, so this should cause no problem (except for the disk space, of course). Regards, Martin From ben at benlast.com Wed Aug 18 08:15:20 2004 From: ben at benlast.com (Ben Last) Date: Wed, 18 Aug 2004 13:15:20 +0100 Subject: sys.stdin.read() replacement In-Reply-To: Message-ID: > From: python-list-bounces+ben=benlast.com at python.org > [mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of > Michael Hudson > Uh, I don't think this is the case; sys.stdin.readline() never uses > the readline functionality. Do you mean raw_input()? I think you're right, now I dig deeper: at least one readline module (on Windows) installs itself in a way that appears to make it the default handler for keystrokes input in any way. I think I generalised from that. Thanks for the correction! regards ben ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ From __peter__ at web.de Tue Aug 3 02:32:03 2004 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Aug 2004 08:32:03 +0200 Subject: Rebinding variable, despite global statement References: Message-ID: Brian Leair wrote: > I am using "from MyModule import *", (yes, yes, I know) > > MyModule has a variable "g_my_var" at the "global" scope. > > In the code that performs the import, I have a function that has the > statement > "global g_my_var". Despite this, when I try to assign to g_my_var it > appears I am rebound to a different object. > Beyond philosophical arguments about not using a "global" variable, is > there a real reason why I can't assign to the global "g_my_var". I'm > using python 2.3.2. > > One workaround is to place getter/setters in MyModule, but I was still > surprised by this behavior. Let's assume the current module is the main module __main__. After from MyModule import * or bettter from MyModule import g_my_var you have two independent bindings to the same object. You can think of it as the two-step process import MyModule g_my_var = MyModule.g_my_var # del MyModule That you are using the same name in both __main__ and MyModule has no effect on the general structure. With def f(): global g_my_var g_my_var = "some value" f() you only rebind g_my_var in the current module's global namespace (__main__ in the example). While you should always think twice before modifying a module from the outside, a reasonably clean way is to do it like so: import MyModule def f(): MyModule.g_my_var = "some value f() Peter From pellis.no.spam at tampabay.rr.com Mon Aug 9 21:57:08 2004 From: pellis.no.spam at tampabay.rr.com (Patrick Ellis) Date: Tue, 10 Aug 2004 01:57:08 GMT Subject: Popular Python projects with lots of pure Python code References: Message-ID: Brett C. wrote: > For my thesis (once the bloody thing stops throwing bugs at me) I am > going to need to collect stats on the frequency that atomic types in > local variables are applied to various opcodes and methods. That > means that I need something to collect stats off of. > > So I am trying to come up with a list of projects I can use to get my > stats from. the stdlib is a no-brainer. Also plan to use Docutils. > But beyond those most of the big Python projects I can think of have a > ton of C code which is of no use to me. I don't need to be able to > run it, just going to be compiling to .py files. > > Any suggestions? > > -Brett BoaConstructor From fumanchu at amor.org Mon Aug 16 16:21:58 2004 From: fumanchu at amor.org (Robert Brewer) Date: Mon, 16 Aug 2004 13:21:58 -0700 Subject: mailman mailing list program Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E00@exchange.hqamor.amorhq.net> Carol Carrot wrote: > Sent: Monday, August 16, 2004 12:52 PM > To: python-list at python.org > Subject: Re: mailman mailing list program > > > now what is +1 QOTW.supposed to mean? "QOTW" = "Quote Of The Week" +1 is part of a generic "voting system", IIRC first used among Apache developers: -1 = Don't do it! -0 = I don't care, so why bother. +0 = I don't care, so go ahead if you want. +1 = Do it! So "+1 QOTW" means, "this gets my positive vote for quote of the week". HTH, Robert Brewer MIS Amor Ministries fumanchu at amor.org From Vincent.Raaijmakers at ge.com Mon Aug 2 17:39:19 2004 From: Vincent.Raaijmakers at ge.com (Raaijmakers, Vincent (GE Infrastructure)) Date: Mon, 2 Aug 2004 16:39:19 -0500 Subject: MySQLdb select Message-ID: <971323274247EB44B9A01D0A3B424C850B332555@FTWMLVEM02.e2k.ad.ge.com> I'm so glad that this issue is raised here. Can someone help me in this thread explaining me how to use multiple parameters. Jaco helped me already a lot and perhaps someone in this thread can give me the final answer: My table contains a blob and a bigint for storing images. The table name is also a variable, so the query looks like: SQL = "INSERT INTO %s (number, image) VALUES (%s, %s)" Well, I get a mysql exception if the execution looks like: cursor.execute(SQL, (tableName, aValue, jpgImage)) The execution only works when I fill out the data until the blob value is a 'left over' as a %s: Yes, this looks ugly.. but it works... SQL = "INSERT INTO %s (number, image) VALUES (%s," % (tableName, aValue) ## table name and number SQL += "%s)" ## left over... only the image cursor.execute(SQL, jpgImage) Can someone explain this to me? Vincent -----Original Message----- From: python-list-bounces+vincent.raaijmakers=ge.com at python.org [mailto:python-list-bounces+vincent.raaijmakers=ge.com at python.org]On Behalf Of Harald Massa Sent: Sunday, August 01, 2004 5:41 PM To: python-list at python.org Subject: Re: MySQLdb select Ruben, it is considered bad style wihtin c.l.p. to have aggressive emotions apart from mails about a "ternary operator" The correct way would have been: > > cursor.execute("SELECT * FROM mytest where clientID = %d" % numb) >> >> That's particularly BAD STYLE. It's best to keep to letting the >> DB-API do the proper quoting for all parameters. "Gerhard, why is this BAD STYLE? And how can I make the DB-API do the proper quoting for all parameters?" And probably the answer would have been: with doing "SELECT * FROM mytest where clientID = %d" % numb you are using the standard Python String-Formatting Functions. That may or may not lead to success. Especially when using a mixture of strings and numbers, they have to be quoted differently. Also special characters within strings have to be quoted - for example, the single ' has to be quoted within SQL because it is usually used as string delimiter cursor.execute("SELECT * FROM mytest where clientID = %d" , numb) The "," is the magic - with "Bla " % sth you are passing ONE argument --- the %s gets substituted, and one argument gets passed to the function. With "," two arguments get passed to the execute-"function" so that the DB-API has the challenge to integrate the parameters into the SQL-String. And it is more bad style to write "SELECT * FROM mytest where clientID = %d" % numb because % is defined with using a Tuple as second parameter, that would be "clientID = %d" % (numb,) Using % with sth. else than a tuple may succeed or give you very funny errors if numb happens to be a List in a later run. Best wishes, Harald -- http://mail.python.org/mailman/listinfo/python-list From ptmcg at austin.rr._bogus_.com Wed Aug 11 15:08:08 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Wed, 11 Aug 2004 19:08:08 GMT Subject: pyparsing 1.2.1 preview (2) Message-ID: I'm finishing a minor bug-fix release to version 1.2 for pyparsing, and have uploaded the pyparsing code to CVS on my SourceForge project page. There is one bug-fix that may change some behavior when using results names for accessing token groups within the parsed token results. If there are any pyparsing fans out there who would like an advance look at this release, I'd appreciate any test feedback. This minor release also includes the new SkipTo class, and the dictOf(keyExpression,valueExpression) helper function. Thanks, -- Paul From db3l at fitlinxx.com Fri Aug 13 14:14:09 2004 From: db3l at fitlinxx.com (David Bolen) Date: 13 Aug 2004 14:14:09 -0400 Subject: Pyhton Interpreter Startup time References: <30260531.0408120829.27a536bc@posting.google.com> Message-ID: Peter Hansen writes: > I don't recall the OP in the last thread that discussed this > ever coming back to report on exactly what OS and CPU etc. > he was using, and whether network issues might be involved, > etc, so until someone can prove otherwise, I think it's > safe to assume that anyone with a slow startup on Windows > has a misconfiguration or is doing something wrong. I don't think that's a safe assumption. For example, on a PIII-550 box running NT that I use, the first time I start up Python after a prolonged absence (typically through a night when a virus scan is run) it can take several seconds to start. The same holds true if I switch versions of Python for comparisons (the first time a new version is run takes a few seconds). Subsequent executions of the same version are sub-second (albeit not always by much). There's no network issues involved (everything referenced during startup is local), but to be honest, I'm not surprised, as I can clearly hear my disk getting hit hard, and expect that absolutely nothing was in the disk cache related to Python, so getting it loaded and all the initial startup files loaded simply takes some time. The fact that I experience similar noticeable delays with loading just about everything else the first time after the nightly outage (e.g., the first time Outlook needs to load in IE to display an HTML message encounters a very noticeable multi-second delay with heavy disk I/O) makes me doubly think that the nightly virus scan is flushing just about everything out of cache. Similar startups on a PIII-333 running a Gentoo 2.4.x Linux install definitely "feel" a bit faster. For example, using "python -v" on both systems presents the same list of loaded modules (replacing posix/posixpath with nt/ntpath under Windows) and then an additional readline load once the interpreter starts under Linux. However, the Linux session just streams those module load messages while you can visually "see" each message coming out in turn with a tiny delay between them under Windows. I haven't run timing measurements, but it's noticeable enough that while they might not be major, I'm confident they are there. So for whatever reason, Windows does behave a bit more sluggishly than Linux in my case. Maybe it's the use of the DLL with Windows (don't know if any relocations have to take place) versus the static binary under Linux. Maybe it's just slightly better filesystem I/O (my Windows box may be more fragmented and/or fuller filesystems). Certainly doesn't affect me in normal operation, but I guess if I was starting Python very frequently I'd work on it more. I also don't think there's much room for Python to be at fault at least in my case - e.g., if anything it's system behavior and not really local operations Python is performing. But I don't think it automatically implies that my Windows system is misconfigured or that I'm doing something wrong. Of course, my timings aren't the consistent 5+ second startups that some others have posted about, in which cases I do agree there might be an unexpected network dependency or something else amiss. -- David From fumanchu at amor.org Thu Aug 26 13:52:30 2004 From: fumanchu at amor.org (Robert Brewer) Date: Thu, 26 Aug 2004 10:52:30 -0700 Subject: Call for signatories for J2 Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E88@exchange.hqamor.amorhq.net> Paul Rubin wrote: > I'm still not crazy about J2 but I like "per" much better > than "using". > > I'm afraid that the clpy proposals, and the @pie syntax, both seem to > me like "extreme programming", i.e. an approach of "if you see a > reasonable looking approach to a problem, implement it without > worrying too much, and re-do ('refactor') it afterwards if it turns > out not to be the right thing. But for new language syntax, whatever > gets implemented, we are going to be stuck with. There will be no > refactoring possible. It's imperative to get it right the first time. > The Scheme community understood this idea and was extremely careful > about adding new features to Scheme even when it was clear that the > features were needed. I think Scheme benefited as a result. FWIW, I agree. On this level, the J2 proposal is an attempt to cram what should have been a longer discussion into a short time frame. But that's our fault as a community--this should've been done in April at the latest. I await the ultimate irony, that after all the furor, Guido may decide to pull decorators out of 2.4 entirely during beta. ;) Robert Brewer MIS Amor Ministries fumanchu at amor.org From bvande at po-box.mcgill.ca Tue Aug 10 16:26:31 2004 From: bvande at po-box.mcgill.ca (Brian van den Broek) Date: Tue, 10 Aug 2004 16:26:31 -0400 Subject: Decorators proposal In-Reply-To: <10hi6bidesj3aae@corp.supernews.com> References: <19b62f17.0408100741.7f2712ac@posting.google.com> <10hi6bidesj3aae@corp.supernews.com> Message-ID: <41192F77.6030309@po-box.mcgill.ca> Jeff Shannon said unto the world upon 2004-08-10 14:52: > Christopher T King wrote: > >>> RebelGeekz wrote: >>> >>> >>>> Just my humble opinion: >>>> >>>> def bar(low,high): >>>> meta: >>>> accepts(int,int) >>>> returns(float) >>>> #more code >>>> >> >> >> Ooh, perty! I especially like the extension of this idea into function >> attributes; it looks even cleaner than the .attribute syntax I like. >> >> The only problem I see with this is that Guido seems to want >> decorators to >> be more prominent than the function signature itself, so he probably >> certainly won't go for "hiding" then in a doubly-nested block. > > > More to the point, GvR seems to have decided that decorators, as > something that *wraps* a function, belong *outside* the function def > rather than inside it. Being inside the def implies that it's internal > to the function, which decorators are not. > > I can see the logic in that, but I really dislike the contorted prefix > syntax that's necessary to support the alternative. > > Jeff Shannon > Technician/Programmer > Credit International Hi all, I'm far too new to programming and Python for my opinion to have even feather-weight. I'd been wondering about something similar to the above the last few days, but hadn't posted as I didn't feel informed enough about the issues. Now that this sort of solution is under some discussion, though, I cannot resist. From reading much of the @-explosion in the python-dev list it seemed to me that Guido's main objection to any syntax that put the decorators after the def was that it made it look like the decorators were part of the executing function, rather than run only when the def is first run. (Similar reasoning seemed behind the expression of regret that docstrings aren't above defs.) Both for decorators and docstrings, putting them above seems odd to me--documenting and modifying what exactly? Oh, something lower down :-| This way seems to separate them from the function's executable code, yet put them where my brain seems to expect them. And, the extra indent makes them fairly prominent to my eye. The other objection I've seen a lot to the general sort of thing proposed above would be that it takes a new keyword (though I've read Guido relaxing the "no new keyword for decorators" restriction). Could that be met either by using a bare ':' or by having ':meta'? (Maybe I am wrong, but :name isn't legal outside of slicing is it? And certainly not as the start of a line? Thus, wouldn't this eliminate any conflict between this use of 'meta' and any possible use of 'meta' as a variable?) Anyway, conceptually and aesthetically this sort of proposal seems the best I've read about. Here's hoping someone with more credibility, knowledge, and a better sense of pythonic politics [not meant with any snide tone] decides to champion it. Best to all, Brian vdB From mwh at python.net Fri Aug 6 11:33:20 2004 From: mwh at python.net (Michael Hudson) Date: Fri, 6 Aug 2004 15:33:20 GMT Subject: Queue qsize = unreliable? References: Message-ID: "James R. Saker Jr." writes: > I see per pydoc that Queue.Queue()'s .qsize is allegedly unreliable: > > | qsize(self) > | Return the approximate size of the queue (not reliable!). > > Any thoughts on why this is unreliable (and more curiously, why it would > be put in there as an unreliable function?) Rather than roll my own > threaded fifo class, it would seem prudent to use Python's built-in > Queue but the warning signs on a rather necessary function seem curious. Well, by the time you examine (or even get!) the answer, it might be wrong. Kinda hard to avoid this in the setting of multiple threads! Cheers, mwh -- All parts should go together without forcing. You must remember that the parts you are reassembling were disassembled by you. Therefore, if you can't get them together again, there must be a reason. By all means, do not use a hammer. -- IBM maintenance manual, 1925 From anthonybaxter at gmail.com Sun Aug 8 21:34:39 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Mon, 9 Aug 2004 11:34:39 +1000 Subject: PEP-0318 In-Reply-To: <4116bc20$1@nntp.zianet.com> References: <41122FC2.1080608@interlink.com.au> <4114152f@nntp.zianet.com> <4116bc20$1@nntp.zianet.com> Message-ID: On Sun, 08 Aug 2004 19:49:51 -0400, Mark Bottjer wrote: > > I noticed you posted the "@decorators at the top of function body" > > idea right before I posted it here, too. See the "compromise?" > > thread. > > This idea seems to have occurred to a few people independently. Another > guy apparently beat me to posting it by a day or so. Here's hoping that > someone with "cred" will see it and like it enough to promote it to GvR. Guido has ruled out decorators at the top of function body, on the grounds that it looks like something that would be executed as part of the function, but isn't. FWIW, in the same thread he's noted that having docstrings where they are is problematic in this respect. Fortunately, with the new decorator syntax, we can fix this... def doc(docstring): def add_doc_string(func, docstring=docstring): func.__doc__ = docstring return func return add_doc_string @doc("This function frobulates an input sequence") def frob(seq): .... From in.aqua.scribis at nl.invalid Sat Aug 28 20:38:27 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Sun, 29 Aug 2004 02:38:27 +0200 Subject: regex into str Message-ID: I want to use regular expressions with less typing. Like this: A / 'b.(..)' # test for regex 'b...' in A A[0] # get the last whole match A[1] # get the first group in the last match A /= 'b.','X',1 # replace first occurence of regex 'b.' # in A with 'X' A /= 'b.','X' # replace all occurences of regex 'b.' # in A with 'X' This works fine if I create a class derived from 'str' and put in the right functions. I have a demonstration below. But what I really want is to insert these functions into class 'str' itself, so I can use them on ordinary strings: def __div__(self, regex): p = re.compile(regex) self.__sre__ = p.search(self) return str(self.__sre__.group()) setattr(str, '__div__', __div__) But when I try this I get: TypeError: can't set attributes of built-in/extension type 'str' I there a way to get this done? Working example: #!/usr/bin/env python import re class Mystr(str): def __div__(self, regex): p = re.compile(regex) self.sre = p.search(self) return Mystr(self.sre.group()) def __idiv__(self, tpl): try: regex, repl, count = tpl except ValueError: regex, repl = tpl count = 0 p = re.compile(regex) return Mystr(p.sub(repl, self, count)) def __call__(self, g): return self.sre.group(g) if __name__ == '__main__': a = Mystr('abcdebfghbij') print "a :", a print "Match a / 'b(..)(..)' :", print a / 'b(..)(..)' # find match print "a[0], a[1], a[2] :", print a[0], a[1], a[2] # print letters from string print "a(0), a(1), a(2) :", print a(0), a(1), a(2) # print matches print "a :", a a /= 'b.', 'X', 1 # find and replace once print "a :", a a /= 'b.', 'X' # find and replace all print "a :", a -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From aleaxit at yahoo.com Tue Aug 31 07:00:32 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Tue, 31 Aug 2004 13:00:32 +0200 Subject: about presicion References: <8f17f4bc.0408261434.1a73e874@posting.google.com> <2e363c08.0408261912.2358a016@posting.google.com> <8f17f4bc.0408281303.3cfb4199@posting.google.com> <20040829041630.28913.00001771@mb-m26.aol.com> <1gjc13i.rx89x319njqe2N%aleaxit@yahoo.com> Message-ID: <1gjdvbc.3lhlg6soyrudN%aleaxit@yahoo.com> mensanator at aol.com wrote: ... > > > I just tried it and found out it's not compatible with gmpy. > > > > By "it" do you mean Decimal, or Python 2.4 alpha 2? > > By "it", I meant gmpy 1.0 and Python 2.4. Trying to import the > module says it can't use the Python23.dll. _Any_ binary extension Python module compiled for Python 2.3 cannot even load (on Windows) with Python 2.4 -- this has always been true on Windows between any two releases of Python and will presumably continue to be so for the foreseeable future. This doesn't mean that Python 2.4 "is not compatible with gmpy" or viceversa: it just means you obviously need to use a gmpy binary (pyd file) compiled for the version of Python you're using. Just as it would be the case for any other binary extension module whatsoever. Unfortunately, compiling any binary extension module on Windows for Python 2.4 requires Microsoft's very latest C++ compiler -- I do not own a copy, nor do I have any PC normally running Windows XP, which is required to run that compiler. Until Pyhon 2.3, I made do with a Windows 98 session running under win4lin on one of my Linux machines, and good old Microsoft Visual C++ 6 -- but such limited resources are not sufficient any longer to compile Python binary extension modules for Python 2.4. Since in terms of income-making (as well as leisure;-) I work by now only on MacOSX, Linux, and OpenBSD machines, I am not going to buy a PC loaded with Microsoft software just to be able to donate precompiled Python binary extension modules to Windows users. > > I think gmpy should > > build happily with the latter, > > I'm using the pre-built Windows binary distribution. I wouldn't > know how to re-build it. I assume that when Python 2.4 is final, > I newer compatible version of gmpy will become available. Not by magic -- I hope somebody out there owns all the needed Microsoft software and is interested in compiling gmpy for Windows under Python 2.4 and making it available, but it won't be me. > > and interoperate sensibly with Decimal > > anyway -- as gmpy's author I'd be quite happy to fix gmpy if it's > broken > > in either respect. > > Were you aware that there is apparently a memory leak in the > gmpy.divm() function? Calling it several million time caused my > computer to run out of virtual memeory. Luckily, I was able to > work around it using the gmpy.invert() which didn't consume any > memory regardless of how many times it was called. No, I was not aware of that -- I'll look into it, thanks. Alex From mwh at python.net Thu Aug 19 13:39:42 2004 From: mwh at python.net (Michael Hudson) Date: Thu, 19 Aug 2004 17:39:42 GMT Subject: Calling __init__ for all mixins References: Message-ID: Martin Maney writes: > Shalabh Chaturvedi wrote: > > The new-style super mechanism might indeed solve your problem. In the > > snippet that you mention, super(NewStyleOnly, self).__init__() would > > only call A.__init__(). But A.__init__ should itself have a super call > > of the form: > > > def __init__(self): > > super(A, self).__init__() # A's super call > > > Now *that* will call B.__init__(), which should itself have a super call > > I will be dipped in shit. So let me see... super(this_here_class, > self) can and will resolve to a class that is not in any sane meaning > of the word a super class of this_here_class, but rather a co-base of > it? No. super(this_here_class, self) returns, well, a super() object that when you look for an attribute on it acts a bit like `self.__class__' but only looks in classes later than `this_here_class' in the MRO. Don't worry too much if that didn't make sense, but it's probably a good idea to get the thought that super() returns a class out of your head. > This is either brilliant or pure crack. I'll have to ponder it for > a good long while. It's brilliant :-) Cheers, mwh -- > Well, as an American citizen I hope that the EU tells the MPAA > and RIAA to shove it where the Sun don't shine. Actually they already did. Only first they bent over and dropped their trousers. -- Shmuel (Seymour J.) Metz & Toni Lassila, asr From bockman at virgilio.it Sun Aug 22 12:06:57 2004 From: bockman at virgilio.it (Francesco Bochicchio) Date: Sun, 22 Aug 2004 16:06:57 GMT Subject: VHHL :( was Re: Python future performance and speed) References: <278de0e.0408211605.426e5129@posting.google.com> Message-ID: On Sun, 22 Aug 2004 11:20:42 -0400, Peter Hansen wrote: > * I limit this to scripting languages since it's quite certain > that the mainstream *has* accepted high level languages quite > fully. The last time I checked, Java and C++ (even C) were > widely considered to be high level languages. Has someone been > raising the bar while I wasn't looking? I heard sometime Python referred as a 'Very High Level Language', that is a notch on the top of Java, and more than that on top of C++. I concur with this definition, since Python is for me closer to the developers mind (and thus more distant from the machine) than any other language I use (including Java, C++, C and ADA). So, the bar has been raised, in a way:-). And VHLLs will become more and more used as computer power grows and becomes cheaper than developer time (it is already so in several application areas). From 510046470588-0001 at t-online.de Tue Aug 17 05:19:30 2004 From: 510046470588-0001 at t-online.de (510046470588-0001 at t-online.de) Date: 17 Aug 2004 11:19:30 +0200 Subject: Why I love python. References: <7xk6vyczck.fsf@ruckus.brouhaha.com> Message-ID: <87657iglzx.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Nick Patavalis writes: > On 2004-08-17, Paul Rubin <> wrote: > > > > Compilers for languages like Lisp and Smaltalk have dealt with this > > for decades. They can either generate code that switches on the type > > tags, or have dispatch tables in the objects that point to code for > > operations like "+", or take advice or declarations from the > > programmer about the arg types, among other possibilities. Any of > > these approaches generates code that runs much faster than > > interpreted code. > > > > Yes, I know. Something like this was what I was thinking about. I > would really love to see this technology brought to Python, or at > least a discussion as to what additions would be required in the > *language* in order for similar technologies to be easily applicable > to future Pythonic environments. > those compilers are totally unflexible, as they can't deal with data types and function code supplied at run time, and they cache too much information, causing bloat of the ram. Klaus Schilling From Sibylle.Koczian at Bibliothek.Uni-Augsburg.de Tue Aug 10 09:02:06 2004 From: Sibylle.Koczian at Bibliothek.Uni-Augsburg.de (Sibylle Koczian) Date: Tue, 10 Aug 2004 15:02:06 +0200 Subject: How do I get IDLE on Suse Linux 9.x? In-Reply-To: <0G1Sc.149588$fv.89578@fe2.columbus.rr.com> References: <0G1Sc.149588$fv.89578@fe2.columbus.rr.com> Message-ID: <2nrvaeF41g4hU1@uni-berlin.de> michael schrieb: > Hi. > > I am reasonably experienced with Python (and love it!) on Windows. I am a > programmer that toils in c++ on Win 32 mostly but just to learn more, I am > playing with Suse 9. Linux. > > Of course the first thing I tried to fire up was Python. From the command > line, I can access Python 2.3 with no problem. > > I tried to run / search for IDLE which I thought was a standard install on > any python installation but it is not present. > Did you check with Yast2 or with the rpm command? If you've got SuSE 9.1 in the professional version I can tell you for sure IDLE is on the CD but you might not have installed it. It's got its own package. I can't really think it's missing from 9.0. And with the personal version you probably wouldn't have Python either (that comes without a C compiler, even). I'm not within reach of my Linux box at the moment so I can't tell you the exact package name or things like that. But I'm a Linux newbie myself and I found it without problems so it must have been quite easy. > My question is this: Should I just use a text editor and go without IDLE? Is > there another IDE standard on Linux? Do I need to download something to get > IDLE? > Most probably no to all three. If you don't find it using Yast2 or rpm, come back and I'll look for details in my installation. HTH Koczian From grante at visi.com Fri Aug 13 12:56:20 2004 From: grante at visi.com (Grant Edwards) Date: 13 Aug 2004 16:56:20 GMT Subject: PEP 318 decorators are not Decorators References: Message-ID: <411cf2b4$0$65563$a1866201@newsreader.visi.com> On 2004-08-13, Arien Malec wrote: >>> decorator. One of the issues is that the Decorator pattern is more >> >> The term decorator as used in the current discussion comes >> from compiler writing. You have a syntax 'tree' which gets >> 'decorated' with additional attributes. > > 1) That's not mentioned in PEP 318 > 2) That's in disagreement with http://www.python.org/moin/PythonDecorators > 3) Won't most programmers think GoF decorators before compiler syntax tree > decorators? Thank you! I spent a while reading up on "decorators" the other day and was completely baffled. I couldn't see that the stuff in PEP 318 discussion threads had anything at all to do with what was discussed by the references I found on "decorators" (which were all about "design pattern" stuff). So, I gave up and went back to work on writing a strip-chart recorder using the Gnuplot module. -- Grant Edwards grante Yow! I'm shaving!! I'M at SHAVING!! visi.com From osuchw at ecn.ab.ca Sun Aug 15 18:29:27 2004 From: osuchw at ecn.ab.ca (Waldemar Osuch) Date: Sun, 15 Aug 2004 22:29:27 GMT Subject: Seperating CSV rows into new, seperate files In-Reply-To: References: Message-ID: TonyB wrote: > In any case, it appears > that the new files have some sort of additional line terminator that > creates a blank row in the outputted file making the importing of the > list impossible. When writing to a file using csv.writer on Windows open the file in binary format. > row[SECTION]) > fileobj = file(filename, 'a') > newfile = csv.writer(fileobj) > newfile.writerow(row) > fileobj.close() so fileobj = file(filename, 'a') becomes fileobj = file(filename, 'ab') That should fix it. Waldek From martin at v.loewis.de Fri Aug 6 18:32:47 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 07 Aug 2004 00:32:47 +0200 Subject: PEP 263 status check In-Reply-To: <10h7tb8nn53ajbb@news.supernews.com> References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> <10h5hgvpafm8a64@news.supernews.com> <41133C76.8040302@v.loewis.de> <10h6rklt3fa1690@news.supernews.com> <41137799.70808@v.loewis.de> <10h724r20kkeqb2@news.supernews.com> <4113D8DF.8080106@v.loewis.de> <10h7tb8nn53ajbb@news.supernews.com> Message-ID: <4114070F.90507@v.loewis.de> John Roth wrote: > Martin, I think you misinterpreted what I said at the > beginning. I'm only, and I need to repeat this, ONLY > dealing with the case where the encoding declaration > specifically says that the script is in UTF-8. No other > case. From the viewpoint of PEP 263, there is absolutely *no*, and I repeat NO difference between chosing UTF-8 and chosing windows-1252 as the source encoding. > I'm going to deal with your response point by point, > but I don't think most of this is really relevant. Your > response only makes sense if you missed the point that > I was talking about scripts that explicitly declared their > encoding to be UTF-8, and no other scripts in no > other circumstances. I don't understand why it is desirable to single out UTF-8 as a source encoding. PEP 263 does no such thing, except for allowing an addition encoding declaration for UTF-8 (by means of the UTF-8 signature). > I didn't mean the entire source was in 7-bit ascii. What > I meant was that if the encoding was utf-8 then the source > for 8-bit string literals must be in 7-bit ascii. Nothing more. PEP 263 never says such a thing. Why did you get this impression after reading it? *If* you understood that byte string literals can have the full power of the source encoding, plus hex-escaping, I can't see what made you think that power did not apply if the source encoding was UTF-8. > L:ikewise. I never thought otherwise; in fact I'd like to expand > the availible operators to include the set operators as well as > the logical operators and the "real" division operator (the one > you learned in grade school - the dash with a dot above and > below the line.) That would be a different PEP, though, and I doubt Guido will be in favour. However, this is OT for this thread. > It's predictable, but as far as I'm concerned, that's > not only useless behavior, it's counterproductive > behavior. I find it difficult to imagine any case > where the benefit of having normal character > literals accidentally contain utf-8 multi-byte > characters outweighs the pain of having it happen > accidentally, and then figuring out why your program > is giving you wierd behavior. Might be. This is precisely the issue that Hallvard is addressing. I agree there should be a mechanism to check whether all significant non-ASCII characters are inside Unicode literals. I personally would prefer a command line switch over a per-file declaration, but that would be the subject of Hallvard's PEP. Under no circumstances I would disallow using the full source encoding in byte strings, even if the source encoding is UTF-8. > There's no reason why you have to have a utf-8 > encoding declaration. If you want your source to > be utf-8, you need to accept the consequences. Even for UTF-8, you need an encoding declaration (although the UTF-8 signature is sufficient for that matter). If there is no encoding declaration whatsoever, Python will assume that the source is us-ascii. > I fully expect Python to support the usual mixture > of encodings until 3.0 at least. At that point, everything > gets to be rewritten anyway. I very much doubt that, in two ways: a) Python 3.0 will not happen, in any foreseeable future b) if it happens, much code will stay the same, or only require minor changes. I doubt that non-UTF-8 source encoding will be banned in Python 3. > Were you able to write your entire program in UTF-8? > I think not. What do you mean, your entire program? All strings? Certainly you were. Why not? Of course, before UTF-8 was an RFC, there were no editors available, nor would any operating system support output in UTF-8, so you would need to organize everything on your own (perhaps it was simpler on Plan-9 at that time, but I have never really used Plan-9 - and you might have needed UTF-1 instead, anyway). Regards, Martin From me at privacy.net Thu Aug 19 11:19:40 2004 From: me at privacy.net (Richard Hanson) Date: Thu, 19 Aug 2004 08:19:40 -0700 Subject: age of Python programmers References: <7re9i095r921mmgemacgn24rp0h7ijdun4@4ax.com> Message-ID: <04h9i05oadjlq949hrqdmu752a224r4odt@4ax.com> Richard Hanson wrote: >Mike C. Fletcher wrote: > >>It's so much more efficient to just make up the statistics. > >Not *that's* a quote! Uhh... Meant, of course: "Now, *that's* a quote!" proof-reading-after-the-fact'ly y'rs, Richard From bauer at mit.edu Fri Aug 13 09:02:38 2004 From: bauer at mit.edu (SJB) Date: 13 Aug 2004 06:02:38 -0700 Subject: Python and linux netlink sockets Message-ID: I wanted to use python to receive some messages from the linux kernel via way of netlink sockets. However this doesn't seem to be supported from everything I have been able to find so far. Can someone clue me in if I am wrong or not. Thanks, Steve From stehenry at yahoo.com Sat Aug 21 05:22:32 2004 From: stehenry at yahoo.com (stephen henry) Date: 21 Aug 2004 02:22:32 -0700 Subject: C language processing. Message-ID: <845db307.0408210122.70bfd408@posting.google.com> Hi all, I'm looking for a python module that would allow me to take an input file written in 'c' and modify the contents to allow me to, for example, add arguments to functions, insert macros at specific locations etc. I have no formal education in computer science , but, what I believe I'm looking for is somesort of parser (or lexer?). So far, I found a bunch of pasers (SimpleParse and SPARK) but these seem to be quite generic -non-language specifc. I was hoping that the 'c' langauge was sufficiently well known to be supported natively, meaning that I would't need to enter the grammar rules into the parser. Does anybody know of a way of doing this in python? (Or, for that matter, with Perl, as I would be learning either language to carry this out.) Stephen Henry From bmbeck at gmail.com Sun Aug 22 23:47:43 2004 From: bmbeck at gmail.com (Brandon) Date: 22 Aug 2004 20:47:43 -0700 Subject: Has anyone implemented BASIC in Python? References: <2oo13eFcj548U1@uni-berlin.de> Message-ID: <1b5c4527.0408221947.42b8969c@posting.google.com> Not exactly what you're looking for, but I've implemented a scheme to python translator. It converts a subset of scheme into python code that should correctly run through eval/exec. It can be found here: http://www.isomorphism.org/~bbeck/projects/scheme2py/scheme2py.html Leif K-Brooks wrote in message news:<2oo13eFcj548U1 at uni-berlin.de>... > Has anyone ever tried implementing a simple unstructured BASIC dialect > in Python? I'm getting interested in language implementation, and > looking at a reasonably simple example like that could be pretty > interesting. From porky_pig_jr at my-deja.com Mon Aug 23 21:10:36 2004 From: porky_pig_jr at my-deja.com (Porky Pig Jr) Date: 23 Aug 2004 18:10:36 -0700 Subject: newbie: confused with example in Learning Python 2nd Edition: can anyone give a hint Message-ID: <56cfb0e3.0408231710.27d78703@posting.google.com> Here is an example of Stack class which got me totally confused: >>> class Stack: ... def __init__(self, data): ... self._data = list(data) ... self.push = data.append ... self.pop = data.pop ... What I don't understand: we take the 'data' input (a list), and copy it to semi-private instance attribute _data. Something like this: >>> mystack = Stack([1,2,3]) >>> dir(mystack) ['__doc__', '__init__', '__module__', '_data', 'pop', 'push'] >>> mystack._data [1, 2, 3] So: why defitions of self.push and self.pop are defined as 'data.append' rather than '_data.append', etc. What makes me yet more confused: the whole thing works just fine, and yet I can't figure out in which attribute we store the results of pushes and where pops are coming from. Like I push '4' on a stack: >>> mystack.push(4) and yet this does not affect _data (obviously): >>> mystack._data [1, 2, 3] and yet '4' is stored *somewhere*, since pop() produces the right result: >>> mystack.pop() 4 >>> Where is that hidden instance attribute and how can I access it? Seems like very simple definition, and yet there is something tricky about it. TIA. From kevino at tulane.edu Wed Aug 25 13:41:00 2004 From: kevino at tulane.edu (Kevin Ollivier) Date: Wed, 25 Aug 2004 10:41:00 -0700 Subject: [ANN] EClass.Builder 2.5.4.17 Message-ID: EClass.Builder is a wxPython application for Windows and Mac OS X (source works on Linux, but there aren't any packages yet) that helps authors develop CD, web-based or print (PDF) tutorials or documentation, such as learning modules and product documentation. It was originally designed specifically for learning module development, hence the name "EClass". The primary goal of this software is to simplify the technical effort needed to produce a CD, web-based and print publication so that authors can focus on writing the content - not formatting and converting it. To that end, EClass.Builder has been designed with flexibility in mind, anticipating that people would use diverse content types to produce their publications and want customized look and feel for their publications. Because of this, EClass is designed from the ground up to be extensible. You can add support for new content types via plugins (written in Python, of course) and create new web designs using a simple web templating engine. (The move to a more powerful templating engine is under consideration.) You can also write Python scripts to support template macros, such as "breadcrumbs" or other navigation/functionality elements of the page. There are already a couple plugins (such as the web page plugin, which lets you visually edit HTML using wxMozilla) and themes (just a default theme now, in frames and non-frames modes). It also allows for full-text search capabilities, and with the help of Documancer (see http://documancer.sf.net) in the future it will support bookmarking of pages and highlighted search results. If you are interested in a tool that makes documentation creation easy with a clean and consistent looking interface, please take a look at EClass.Builder! You can learn more about the software and download it by going to: http://www.eclass.net Please check the documentation first - EClass is a bit different from other programs, which typically deal with "files" rather than "publications", and so it may take a few minutes to get used to. (Note that I used EClass.Builder to create the web site, using a custom theme and wxMozilla. ;-) Also, I'd love to hear people's thoughts about the product. Suggestions and constructive criticism are very welcome! =) Thanks, Kevin Ollivier From tonym1972{at}club-internet{in}fr Sun Aug 22 20:27:41 2004 From: tonym1972{at}club-internet{in}fr (Anthony McDonald) Date: Mon, 23 Aug 2004 02:27:41 +0200 Subject: Debunking Art - fraudster with python AI engine? References: <4128f60b$1@news.unimelb.edu.au> Message-ID: <412938aa$0$306$7a628cd7@news.club-internet.fr> "Nick" wrote in message news:4128f60b$1 at news.unimelb.edu.au... > Hi, > > I recently went to an art exhibition, and one of the artists had an AI > engine projected onto a screen with a keyboard for visitors to type > questions in with. > > Curiously, I asked the artist if he had written the engine. He claimed > to have, but as far as I know, he has done no AI study, and only > started programming python some months ago. > > Naturally, I find it hard to believe he has picked up on natural > language processing and the other various skills required to write AI > engines in that time. My guess is he has a python AIML interpreter, > and he's found a default "brain" somewhere and tweaked it with some of > his own stuff in order to pass it off as his own. > > The engine could answer all the usual questions, like "what is the > meaning of life" (42), "what is your name", "how old are you" etc etc. > It was just a chatterbot, so ELIZA or a deriviative is marked off the > list. I am guessing probably an ALICE engine is behind it all. Does > anyone know any questions or commands one can issue the bot which > might identify it? It required all questions to start with a capital > letter, if thats any help. > > Cheers, > > Nick. > >From the evidence you present clearly this is a fraud. Mastery of Python in just a few months with no prior programming experience is definately fishy! And never having formerly studied AI or read the tomes of literature on the subject..... why oh why do we tolerate such lies and falsehoods from our "artists". I for one vote to repress them into just painting what the eye can really see ;-)'s Originally I had planned to write a response from this point onwards about how simple it would be to achieve what you've described. Firstly I'd have mentioned that a little research would bring you to say something like Markov chains for emulating natural language structure (a number of the recent and best chatterboxes have used this technique). I'd have followed up with how these are crazily simple to implement in Python using just a dictionary and lists. And I'd have finished up by mentioning that Markov chains along with a lot of other statistical tools and algorithms originally developed outside of AI research have over time been brought into this field. Then I spoke with my Girlfriend who's an artist and not an IT professional. Who explained about the artist showing how life is really an anthropormorphic projection of ourselves onto other objects. How in our desire to communicate intelligently we project our own intelligence into everyday associations. How from this we can create our own Deus ex Machina based merely on responses that seem natural to us but as yet we don't understand. But I don't believe any of that, hell she thinks clippy is cute :-)'s But it explains your question fairly well. Presented with a non comp sci graduate doing something that appears to be the domain of a lifetimes AI research, you've projected your inability to do the task onto them and formulated the response that plagurism is at the heart of the matter. You've failed to see through the smoke and mirrors and spot just how easy on one hand Python is to learn, and just how much power on the other hand it allows you to lever. And you've forgotten that Google is not just an IPO its also your friend for research. I wish you luck in your quest to prove this was a fraud. As for me its back to updating skynet 1.0 to use decorators and some new introspection tricks ;-)'s Anthony McDonald From h.b.furuseth at usit.uio.no Thu Aug 5 16:24:19 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 05 Aug 2004 22:24:19 +0200 Subject: Proposal: require 7-bit source str's Message-ID: Now that the '-*- coding: -*-' feature has arrived, I'd like to see an addition: # -*- str7bit:True -*- After the source file has been converted to Unicode, cause a parse error if a non-u'' string contains a non-7bit source character. It can be used to ensure that the source file doesn't contain national characters that the program will treat as characters in the current locale's character set instead of in the source file's character set. An environment variable or command line option to set this for all files would also be very useful (and -*- str7bit:False -*- to override it), so one can easily check someone else's code for trouble spots. Possibly an s'' syntax or something would also be useful for non- Unicode strings that intentionally contain national characters. I dislike the '7bit' part of the name - it's misleading both because one can get 8-bit strings e.g. with the '\x' notation (a feature, not a bug) and because some 'valid' characters will be 8bit in character sets like EBCDIC. However, I can't think of a better name. Comments? Has it been discussed before? -- Hallvard From __peter__ at web.de Tue Aug 10 11:20:10 2004 From: __peter__ at web.de (Peter Otten) Date: Tue, 10 Aug 2004 17:20:10 +0200 Subject: how to dispatch objects depending on their class References: <4118dd4a$1@maser.urz.unibas.ch> Message-ID: Curzio Basso wrote: > FUNC = {"": do_something_with_A, > "": do_something_with_B} > > def func(object): > FUNC[type(object)](object) You'll have to modify that slightly for it to work. It will be very efficient, too. func_dict = {A: do_something_with_A, B: do_something_with_B} def func(obj): func_dict[obj.__class__](obj) Using classes as keys avoids the ambiguity you fear. The overhead will be one dictionary lookup and a function call. The main drawback of this simple approach is that it does not search the inheritance tree but insists on an exact class match. > I hope my problem is clear, and excuse me if I am asking about something > that is common knowledge, but I don't even know what to google for... Maybe python generic dispatch Peter From jmeile at hotmail.com Sat Aug 28 14:08:42 2004 From: jmeile at hotmail.com (Josef Meile) Date: Sat, 28 Aug 2004 20:08:42 +0200 Subject: Zope help system, password needed in windows In-Reply-To: References: Message-ID: <4130bc1e$1@pfaff2.ethz.ch> Hi, > Hi all, i may be flamed but did not find anything on that. I have zope > 2.7 running on windows 98 and I really like it. Problem is when i use > the zope help system I am asked to give a login and password to get > access to some sections (python scripts API reference and zope API > reference). I tried my standard admin login but hey it didn't work > with that one. I am a python and zope nubee so i was thinking it could > help me reading that doc. I would really appreciate it if someone > could tell me what i missed. It is a bug, it's already fixed on 2.7.2. On the future, you may subscribe to: mail.zope.org Then you can post your zope related questions to: zope at zope.org Regards, Josef From thomas.krueger at gmx.net Mon Aug 9 14:07:28 2004 From: thomas.krueger at gmx.net (Thomas =?ISO-8859-1?Q?Kr=FCger?=) Date: Mon, 09 Aug 2004 20:07:28 +0200 Subject: Question References: Message-ID: Dag Hansteen wrote: >>>> s = "2+2" >>>> answer = int(str(s)) > Traceback (most recent call last): > File "", line 1, in ? > answer = int(str(s)) > ValueError: invalid literal for int(): 2+2 > > How do I this ? I have a string with a such expression and I want to > return the answer in a variable. eval('2+2') -> 4 Thomas From zanesdad at bellsouth.net Thu Aug 26 22:07:44 2004 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Thu, 26 Aug 2004 22:07:44 -0400 Subject: file based queues In-Reply-To: References: Message-ID: <412E9770.8030402@bellsouth.net> Eric S. Johansson wrote: > seems to me this would be a fairly obvious component to be part of the > Python repertoire but I haven't found any yet. I want to store > objects persistently and have the underlying object behavior be that > of a queue. > > usually, this is implemented as a series of files within a directory > or directory hierarchy but I'm not fussy. Just as long as it doesn't > have much overhead like mysql or twisted. > > any suggestions? > > --- eric > Munkware. You can pass in any pickleable object and it will persist it to a directory. It's all pure Python, only a handfull of files to install. If you have any questions about it (usage or whether it will meet your needs), feel free to email me. Here are a couple of links: http://sourceforge.net/projects/munkware http://munkware.sourceforge.net/ From pellis.no.spam at tampabay.rr.com Tue Aug 3 22:34:04 2004 From: pellis.no.spam at tampabay.rr.com (Patrick Ellis) Date: Wed, 04 Aug 2004 02:34:04 GMT Subject: dislin interfaced with tkinter References: <34c9b4fa.0408030743.594417f9@posting.google.com> Message-ID: eesun wrote: > I've downloaded the dislin package for the scientific plotting. And I > have already created the application window with Tkinter (menu, > canvas, status bar..). I want to integrate the Dislin plotting into > the Tkinter application. For ex: show the dislin result on the Tkinter > Canvas. Anyone can help? There is a package called disipyl which provides a more object oriented interface to dislin. It includes interfaces to wxPython and Tkinter. It hasn't been updated in a couple of years, but dislin hasn't changed much in that time either. http://kim.bio.upenn.edu/~pmagwene/disipyl.html From alanmk at hotmail.com Wed Aug 11 11:31:05 2004 From: alanmk at hotmail.com (Alan Kennedy) Date: Wed, 11 Aug 2004 16:31:05 +0100 Subject: jython and java exceptions In-Reply-To: References: <4_nSc.24773$Z14.7584@news.indigo.ie> Message-ID: [Jan Gregor] > There's result - i put aa on input to force error: What execution environment are you running it in when you have this problem? A servlet container? Eclipse? From the command line? I'm beginning to suspect some form of classloader/classpath issue. > Exc com.sybase.jdbc2.jdbc.SybSQLException: Stored procedure 'aa' not > found. Specify owner.objectname or use sp_help to check whether the > object exists (sp_help may produce lots of output). > != subclass of java.sql.SQLException! So your jython code finds that the exception raised does not subclass the base exception it is trying to catch. Which could mean that the definitions of the base exception class may be different between the code trying to catch the exception (your jython) and the code trying to raise it (Sybase jdbc). Try the following experiments to see if you get behaviour that is different 1. Try this jython import java.sql try: raise java.sql.SQLWarning() # known subclass of SQLException except java.sql.SQLException: print "Successfully caught" else: print "Big trouble in Little China" 2. Write some similar code to the above in java, raising an SQLWarning when an object is created, e.g. TestSubclassExceptions.java <----------> import java.sql; public TestSubclassExceptions { public TestSubclassExceptions ( ) throws SQLWarning { throw new SQLWarning(); } } <--------------------------------------> Making sure that the class definition is on your classpath, instantiate a TestSubclassExceptions object inside a jython try..catch as in #1, and see what happens. 3. Write a version of the above class that raises com.sybase.jdbc2.jdbc.SybSQLException instead. Make sure to run this one from the command line, so that you know that the jython classloader is the one loading the class and exception definitions. If you're running inside some form of "enterprise container", you may be tripping over a classloader issue, where base classes/exceptions are being loaded by different classloaders, possibly with different security settings. Solving these problems is almost always a case of finding the right library directory to put your jython.jar, etc, in. This can sometimes require extensive documentation delving. Final sanity check: are you setting the "python.home" property if/when you are embedding jython? There are some minor complexities associated with caching of "compiled" java packages. These can cause odd behaviour if you are executing your code from two different execution environments, e.g. debugging on a command line, and then also running in a servlet container. If none of the above sheds any light, please post back with the details of the software you're using, and the locations in which you've placed your jython.jar, your sybase jdbc jars, etc. > Problem is that SybSQLException IS subclass of SQLException - verified > by Eclipse IDE (type hierarchy). Similar effects were with jdbc driver > for PostgreSQL. > > There's result: > Exc org.postgresql.util.PSQLException: ERROR: syntax error at or near > "aa" > != subclass of java.sql.SQLException! So it's definitely not a Sybase specific problem. -- alan kennedy ------------------------------------------------------ email alan: http://xhaus.com/contact/alan From jack at performancedrivers.com Wed Aug 18 17:10:46 2004 From: jack at performancedrivers.com (Jack Diederich) Date: Wed, 18 Aug 2004 17:10:46 -0400 Subject: Embedding Python in Python In-Reply-To: References: <7xu0v0l2be.fsf@ruckus.brouhaha.com> <7x3c2kkzn8.fsf@ruckus.brouhaha.com> Message-ID: <20040818211046.GZ23725@performancedrivers.com> On Wed, Aug 18, 2004 at 08:25:04PM +0000, JCM wrote: > Jack Diederich wrote: > > On Wed, Aug 18, 2004 at 07:44:47PM +0000, JCM wrote: > ... > >> I don't think it's as difficult as you think. Your snippet of code > >> would be rejected by the rules I suggested. You'd also want to > >> prohibit other builtins like compile, execfile, input, reload, vars, > >> etc. > >> > > foo = "ev" + "al" > > e = vars()['__builtins__'].__dict__[foo] > > print e('2+2') > > Also would be rejected by my original set of rules (can't use > __dict__). But I'd disallow vars too. Google groups for this topic, it's been dead horse kicked. You would have to eliminate getarr too and any C func that can result in an infite loop. Not-python's-job-ly, -Jack From cjw at sympatico.ca Fri Aug 27 09:17:50 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Fri, 27 Aug 2004 09:17:50 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: <412F347E.4040602@sympatico.ca> Paul Morrow wrote: [snip] > > > Yes, it doesn't seem all that complex, although I'm not sure that > everyone reading this understands them and their subtleties. The > following is an excerpt from > http://docs.python.org/tut/node11.html#SECTION0011200000000000000000 > > "A namespace is a mapping from names to objects. Most namespaces are > currently implemented as Python dictionaries, but that's normally not > noticeable in any way (except for performance), and it may change in the > future. Examples of namespaces are: the set of built-in names (functions > such as abs(), and built-in exception names); the global names in a > module; and the local names in a function invocation. In a sense the set > of attributes of an object also form a namespace." > > When I talk about namespaces, I include all of the above, including the > sense mentioned in the last line. So an object's attributes constitute > a namespace too. Therefore __doc__, being an attribute of the function > object, is in the function object's /namespace/. And note that this is > *not* a new namespace; it's been there all along. > Could you elaborate on the last sentence please? Is the namespace not created when the def ... line(s) is/are executed? Colin W. From robin at SPAMREMOVEjessikat.fsnet.co.uk Mon Aug 9 03:49:46 2004 From: robin at SPAMREMOVEjessikat.fsnet.co.uk (Robin Becker) Date: Mon, 09 Aug 2004 08:49:46 +0100 Subject: how many bytes in an int In-Reply-To: <41171116$0$8079$a1866201@newsreader.visi.com> References: <9ACRc.1523$bJ2.9739@news1.mts.net> <4116f8ee$0$8076$a1866201@newsreader.visi.com> <41170cd1$0$8076$a1866201@newsreader.visi.com> <41171116$0$8079$a1866201@newsreader.visi.com> Message-ID: <41172C9A.2020301@jessikat.fsnet.co.uk> Grant Edwards wrote: > On 2004-08-09, Grant Edwards wrote: > > >>The struct module is the only thing I know about. If you're >>worried about the "C" types in the struct module changing >>underneat you, you could do a pure Python implimentation of >>"python-int" to/from DWORD. It's utterly trivial and shouldn't >>take more than one or two lines of code. > > > def toLittleEndianDWORD(i): > return ''.join(map(chr,[x&0xff for x in [i,i>>8,i>>16,i>>24]])) > > def fromLittleEndianDWORD(s): > return ord(s[0]) + (ord(s[1])<<8) + (ord(s[2])<<16) + (ord(s[3])<<24) > this simple code will give warnings in 2.3, I think struct is really needed. >>> toLittleEndianDWORD(-1) '\xff\xff\xff\xff' >>> fromLittleEndianDWORD(toLittleEndianDWORD(-1)) __main__:2: FutureWarning: x<>> -- Robin Becker From pwilkinson at videotron.ca Fri Aug 6 15:35:31 2004 From: pwilkinson at videotron.ca (Peter Wilkinson) Date: Fri, 06 Aug 2004 15:35:31 -0400 Subject: unicode to ascii converting In-Reply-To: References: <1091815856.527127@news.commspeed.net> Message-ID: <6.0.3.0.0.20040806152230.01b92c08@pop.videotron.ca> Well this is interestingly annoying: u"?".encode("ascii", "ignore") -> '' # works just fine but as I have written aa = "?" aa.encode("ascii","ignore") -> Traceback (most recent call last): File "", line 1, in ? UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128) So I am guessing that I don't understand something about the syntax Peter At 02:31 PM 8/6/2004, Bernhard Herzog wrote: >Peter Wilkinson writes: > > > It would be good to find out _why_ this happens in the first place. I > > will keep do a little searching on this for a few days. > >Most likely because you have characters in that file that are not in the >ASCII character set. ASCII is after all only a very small subset of >unicode. E.g. > > >>> u"?".encode("ascii") >Traceback (most recent call last): > File "", line 1, in ? >UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in >position 0: ordinal not in range(128) > > >If it's OK to lose information, you could use the error argument to >.encode like > > >>> u"?".encode("ascii", "ignore") >'' > >or > > >>> u"?".encode("ascii", "replace") >'?' > > > Bernhard > >-- >Intevation GmbH http://intevation.de/ >Skencil http://sketch.sourceforge.net/ >Thuban http://thuban.intevation.org/ >-- >http://mail.python.org/mailman/listinfo/python-list From FBatista at uniFON.com.ar Mon Aug 30 13:19:07 2004 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Mon, 30 Aug 2004 14:19:07 -0300 Subject: about presicion Message-ID: #- > > >> The decimal module comes with python 2.4? I have 2.3, :(, what #- do I do? I missed this mail, so I answer it now. If you want to use the decimal module with Py2.3, just download it from CVS (from http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Lib/) and use it. . Facundo -------------- next part -------------- An HTML attachment was scrubbed... URL: From davidf at sjsoft.com Thu Aug 19 05:13:22 2004 From: davidf at sjsoft.com (David Fraser) Date: Thu, 19 Aug 2004 11:13:22 +0200 Subject: decorators and multimethods In-Reply-To: <4edc17eb.0408070742.664fa9c0@posting.google.com> References: <4edc17eb.0408062340.71ab270f@posting.google.com> <4edc17eb.0408070742.664fa9c0@posting.google.com> Message-ID: Michele Simionato wrote: > michele.simionato at gmail.com (Michele Simionato) wrote in message news:<4edc17eb.0408062340.71ab270f at posting.google.com>... > > > > Martin v. Lewis suggested an improvement, which involves adding the > following method to the Generic_Function class: > > def addmethod(self, *types): > "My own tiny modification to Stearns code" > return lambda f: self.setdefault(types,f) > > The advantage is that methods definitions can go in any scope now and > not only at the top level as in my original hack. > My previous example read: > > foo = Generic_Function() > > @foo.addmethod(object, object, object) > def _(call_next, x, y, z): > return 'default' > > @foo.addmethod(int, int, int) > def _(call_next, x, y, z): > return 'all ints , ' + call_next(x, y, z) > > @foo.addmethod(object, object) > def _(call_next, x, y): > return 'just two' > > where I use "_" as a poor man anonymous function. I cannot reuse the name > "foo" now, since > > @foo.addmethod(...) > def foo(..): > .... > > is really converted to > > def foo(..) > ... > > foo=foo.addmethod(...)(foo) > > and this would correctly raise a "foo function has not attribute addmethod"! > But in some sense this is better, since we avoid any confusion > between the member functions and the generic function (which is implemented > as a dictionary, BTW). Another benefit is you can give the different variants real names: @foo.addmethod(object, object): def add_objects(call_next, x, y): return 'just two' so you can call it directly if you want David From ptmcg at austin.rr._bogus_.com Thu Aug 19 10:10:41 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Thu, 19 Aug 2004 14:10:41 GMT Subject: [Python-Dev] PEP 318: Can't we all just get along? References: <200408190455.i7J4t6CN025433@cosc353.cosc.canterbury.ac.nz> Message-ID: "Andrew Durdin" wrote in message news:mailman.1928.1092895080.5135.python-list at python.org... > On Thu, 19 Aug 2004 16:55:06 +1200, Greg Ewing > wrote: > > Guido: > > > > > Is anybody seriously trying to come up with a single alternative > > > decorator proposal that most folks "out there" can support, to be > > > presented to me (with implementation, please!) in time for 2.4b1? > > > > >From the posts I've seen here, the only alternatives that have > > considerable popular support are ones that you've already rejected. So > > I suspect nobody really feels it's worth trying. > > To expand on that just a bit: the two alternatives that were most > generally favoured (in Doug Holton's estimate) were the > "list-after-def" (C1 in the wiki), and the "pie decorator at top of > function body" (E1 in the wiki), both of which Guido rejected. > In the poll that Doug ran, E1 had a slight margin over C1: > http://mail.python.org/pipermail/python-list/2004-August/233479.html > > However, C1 has an implementation, while E1 doesn't. (Aside: how > difficult would it be to create an implementation of E1?) There is an implementation of J2, to which I have converted from C1, given GvR's predisposition for some sort of prefix form. (J2 was not represented in the poll.) J2 uses a new keyword (decorate) to mark a block of 1 or more decorator methods as a prefix to the "def fn(args):" line. No offensive @, and fairly pleasant to read! -- Paul From qual at tiscali.de Fri Aug 13 16:32:39 2004 From: qual at tiscali.de (Uwe Hoffmann) Date: Fri, 13 Aug 2004 22:32:39 +0200 Subject: DIME Attachments In-Reply-To: References: Message-ID: Chris C wrote: > I've been looking all around for any libraries or code for parsing > dime attachments from Microsoft .NET Web Services. > just remembered this link http://agora.cubik.org/wiki/view/Main/DIME From noone at here.com Wed Aug 25 10:00:11 2004 From: noone at here.com (M. Clift) Date: Wed, 25 Aug 2004 15:00:11 +0100 Subject: Just a quick one References: Message-ID: Hi Benjamin, Sorry, another question. How do I remove the brackets form the list? Name_List.remove('(') doesn't work. Thanks, M From steven.bethard at gmail.com Fri Aug 20 12:49:23 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Fri, 20 Aug 2004 16:49:23 +0000 (UTC) Subject: Alternative decorator syntax decision References: <3A81C87DC164034AA4E2DDFE11D258E3022E14@exchange.hqamor.amorhq.net> Message-ID: Robert Brewer amor.org> writes: > To Paul, M. Sparks, et al: Since J2 is coming up frequently (and Guido > did not immediately reject it when asked), I'm going to follow through > and try to write a proposal this weekend for J2. I'll post it here for > feedback (and of course, wait for the 'final' count of votes) before > posting it on py-dev. This is great! Thanks so much! I wanted to say that despite my hesitations about voting, I think this voting thread has been a pretty helpful way to focus our discussions. It does look like J2 is generally the preferred syntax so far (with the C syntaxes coming in second). I hope this is an opportunity for us all to come together to support a single proposal since this is the only way GvR will really consider our suggestions. I know that J2 is not everyone's favorite, but I'm hoping that we can agree that, even if it's not our favorite, is a clear improvement over @pie syntax. Thanks everyone for all your work and discussions! Steve From aleaxit at yahoo.com Mon Aug 30 04:07:40 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 30 Aug 2004 10:07:40 +0200 Subject: Generator expressions v/s list comprehensions References: <1gj8y77.6qshr41q531veN%aleaxit@yahoo.com> <87llfywooz.fsf@sinken.local.csis.hku.hk> Message-ID: <1gjbs1e.assxlxlud1m0N%aleaxit@yahoo.com> Mahesh Padmanabhan wrote: > In article <87llfywooz.fsf at sinken.local.csis.hku.hk>, > Isaac To wrote: > > [snip] > > Thanks Isaac for providing such a detailed explanation. I understand now > why generator expressions make more sense. > > I just wish that generator expressions had been designed into the > language without going the way of list comprehension -> generator > expressions. It would sure be nice if Python had been born back from day one with all the neat features it has taken years to develop -- that way we wouldn't have any issues that are there just because of backwards compatibility. Unfortunately, this wish is totally unrealistic -- obviously people do come up with cool ideas such as the iterator protocol, and generators, after the language has been around for a while. When list comprehensions got into Python the new iterator protocol wasn't there yet, so of course generator comprehensions could not have been thought of. Similarly, dicts now have both (e.g.) a method .items() which returns a list, and a method .iteritems() which returns an iterator -- no special reason for both to be there, but the former was there first, before the iterator protocol, so it must stay for backwards compatibility. One day (Python 3.0) we'll be able to break compatibility and simplify things, but that sort of thing can be allowed only very rarely in a language's continuing evolution. Alex From alikakakhel3 at hotmail.com Mon Aug 30 13:31:14 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 30 Aug 2004 10:31:14 -0700 Subject: about presicion References: <8f17f4bc.0408261434.1a73e874@posting.google.com> <2e363c08.0408261912.2358a016@posting.google.com> <8f17f4bc.0408281303.3cfb4199@posting.google.com> <20040829041630.28913.00001771@mb-m26.aol.com> <8f17f4bc.0408291552.67e3553e@posting.google.com> <1gjc18t.1hj0z071lwprfjN%aleaxit@yahoo.com> Message-ID: <8f17f4bc.0408300931.7223af16@posting.google.com> aleaxit at yahoo.com (Alex Martelli) wrote in message news:<1gjc18t.1hj0z071lwprfjN%aleaxit at yahoo.com>... > Ali wrote: > > > So the decimal module is in 2.4 but not 2.3? Also I am not geting the > > 2.4 version because it seems that it is still in alpha. > > You _SHOULD_ get the 2.4 alpha, and try it out -- that's why alphas get > released, after all! How's the final release going to be perfect unless > people DO get and try the alphas?! > > But you shouldn't yet use 2.4 for production work (stuff you ship to > customers, etc). > > The Decimal module is in the standard library in 2.4, but Decimal itself > can support 2.3 just fine -- just download and install it. > > > Alex ok but where can i download deciaml? waht about gmpy? which is better? From ivoras at __geri.cc.fer.hr Thu Aug 5 17:32:04 2004 From: ivoras at __geri.cc.fer.hr (Ivan Voras) Date: Thu, 05 Aug 2004 23:32:04 +0200 Subject: psyco out of memory In-Reply-To: References: Message-ID: Ivan Voras wrote: > (I'm running python 2.3.4 on FreeBSD 5) Hmph. I tried on WinXP and it works. Maybe it's a platform-specific bug. (Still, I'm surprised how slow it is. The same "program" in Java takes about 10sec, and here it's passed 5 minutes and I'm still waiting...) -- What part of "Ph'nglui mglw'nath Cthulhu R'lyeh wgah'nagl fhtagn" don't you understand? From cjw at sympatico.ca Sat Aug 21 08:12:38 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Sat, 21 Aug 2004 08:12:38 -0400 Subject: PEP 318: Can't we all just get along? In-Reply-To: References: Message-ID: Neil Zanella wrote: > Paul Morrow wrote in message news:... > >>Roy Smith wrote: >> >>>I never quite understood the point of static methods inside classes. >>>When would you ever need to do that, as opposed to just a function in a >>>module? In Java's "everything is part of a class" philosophy, it makes >>>sense, but in Python? >> >>It gives us another means of managing namespaces. Rather than having to >>create a top-level function in the current (or some other) module, we >>can group it with other related functions as a method in a class. > > > This is one reason for using staticmethod. However, as I pointed out, there > is another even better reason. It allows you to use the polymorphism feature > (as in C++ virtual functions) on class objects without having to create class > instances (as would be necessary in C++). For instance, you can have a > superclass with 20 staticmethods with default behavior, and 40 subclasses > each ovrriding 5 of these staticmethods on average and using the default > for the rest. > > To summarize, here are the two reasons to use staticmethod: > > 1. You want to group a bunch of functions together. However, as it happens > such functions are not useful outside of a given class, so you use > staticmethod to place them where they belong. Perhaps you do not > have enough such functions to warrant their placement inside a > module of its own. > Surely, the price of this is the added complexity in addressing the static method? Suppose we have a module shape and within it a class Shape. Now suppose we wish to create some instances of Shape which have no special nethods, but which each has its own constructor. One could use a function with shape or a static method within Shape. We would address the function, from another module as shape.special and address the static method as shape.Shape.special. What have we gained from this added complexity? Perhaps we have reduced the pollution of the space namespace. Is that sufficient justifiction? Colin W. > 2. You need to use inheritance and polymorphism but you don't need instances, > or perhaps you simply need instance independent polymorphism at the class > level. > > Now if anyone wishes to add to the list, you're more than welcome. > > Regards, > > Neil From skip at pobox.com Fri Aug 6 17:04:25 2004 From: skip at pobox.com (Skip Montanaro) Date: Fri, 6 Aug 2004 16:04:25 -0500 Subject: bsddb port In-Reply-To: <41116E16.7000100@mail.usyd.edu.au> References: <41116E16.7000100@mail.usyd.edu.au> Message-ID: <16659.62041.92466.696771@montanaro.dyndns.org> Ajay> does anyone know of a bsddb port to pocket pc 2002. Silence should be deemed a negative answer. I know of none, but have to wonder if Berkeley DB itself runs on a pocket pc. If you're able to build extension modules for that device can you give it a whirl and submit a bug report to SourceForge identifying the problems? Skip From grepninja at yahoo.com Wed Aug 25 16:12:48 2004 From: grepninja at yahoo.com (John Tobler) Date: 25 Aug 2004 13:12:48 -0700 Subject: Has anyone implemented BASIC in Python? References: <2oo13eFcj548U1@uni-berlin.de> <2ot30hFeek8nU1@uni-berlin.de> <9h0ji0lvc0be65nuvcugaa3vsq5mcl3ck8@4ax.com> <2otkvkFe7p8oU1@uni-berlin.de> Message-ID: Leif K-Brooks wrote in message news:<2otkvkFe7p8oU1 at uni-berlin.de>... > Is there a (virtual) book you would recommend reading to learn about > writing them? A course isn't really possibly for me, so I'm hoping that > isn't the only option. Hmmmm, also check out the Compiler Design and Construction section at http://www.tcfb.com/freetechbooks/bookcp.html. Enjoy! John Tobler CSharpener's Weblog: http://weblogs.asp.net/jtobler/ From eq at eq.homelinux.org Thu Aug 19 16:32:15 2004 From: eq at eq.homelinux.org (eq) Date: Thu, 19 Aug 2004 22:32:15 +0200 Subject: problem using C-bindings Message-ID: Hi, I'm trying to create a program(written in C) that does the following things using embedded Python: 1. Create a module(say, "MyModule") 2. Create a class in that module(say, "MyClass") 3. Create a function in that module(say, "MyFunction") The Python-code would look like this: MyClass.py: class MyClass: def MyFunction(self): print 'Hello' My C-application can do all the steps except the last one. myapp.c: #include static PyMethodDef ModuleMethods[] = { {NULL} }; void attachFunc(PyObject* class,PyObject* dict,char* func_code,char* name) { PyObject* pyfunc_code; PyObject* pyfunc; pyfunc_code=Py_CompileString(func_code,"",Py_file_input); pyfunc=PyFunction_New(pyfunc_code,dict); PyObject_SetAttrString(class,name,pyfunc); } int main(int argc,char** argv) { Py_SetProgramName(argv[0]); Py_Initialize(); PyObject* module; PyObject* module_dict; PyObject* class; PyObject* class_dict; PyObject* class_name; module=Py_InitModule("MyModule",ModuleMethods); module_dict=PyModule_GetDict(module); class_dict=PyDict_New(); class_name=PyString_FromString("MyClass"); class=PyClass_New(NULL,class_dict,class_name); PyDict_SetItemString(module_dict,"MyClass",class); attachFunc(class,module_dict,"print 'hello'\n","MyFunction"); PyRun_SimpleString("import MyModule\n"); PyRun_SimpleString("t=MyModule.MyClass()\n"); PyRun_SimpleString("t.MyFunction()\n"); return 0; } When executing the application, I get the following(because of the "t.MyFunction()") Traceback (most recent call last): File "", line 1, in ? TypeError: ?() takes no arguments (1 given) What am I doing wrong? Greetings, Henning From ben at benlast.com Sat Aug 21 05:42:23 2004 From: ben at benlast.com (Ben Last) Date: Sat, 21 Aug 2004 10:42:23 +0100 Subject: My only complaint about Python In-Reply-To: <874qmxj81k.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Message-ID: > From: 510046470588-0001 at t-online.de > no cost is not the same as free > Klaus Schilling I really shouldn't, but... Klaus, it *is* the same, for one of the two perfectly good definitions of the word "free" in the English language. Actually, I regards gcc as equivalent to the free VC++ in *some* respects (waits for the gasp of horror to die away). If I need a compiler for something, I'll be looking to download one. If there's a problem with it, then frankly it makes no odds to me whether I have the source code or not - for all practical purposes I am *not* going to start hacking around with the compiler source to fix problems. It's not a task for which I have either enthusiasm or time (and seeing how long it is since I was involved in anything that low-level in C, I probably don't have the skills any more). What's needed (in my extremely humble opinion) is a way to build what I need to, using a compiler suite that I can go and get without having to spend any money. Philosophy is fine, but I dislike having an FSF agenda pushed on me as much as I dislike a Redmond agenda. I just want to get on with my job (or in this case, pursue my own interests). Anyway, having said all that, and in a vain attempt to drag this topic back to something more directly Pythonic: something that I have always admired about the Python "community" (or approach) is that those of us who, for one reason or another, use Windows have access to pretty much the same suites of tools and addons as those who use Unix. Zealotry and prejudice against people on the basis of their operating system choice is not a pretty sight, and I appreciate the general lack of it amongst Pythonistas. Now I shall put on my tin hat and hide. :) b From jjl at pobox.com Thu Aug 26 15:06:40 2004 From: jjl at pobox.com (John J. Lee) Date: 26 Aug 2004 20:06:40 +0100 Subject: waiting for html to load: a followup References: Message-ID: Josh writes: [...] > Anyway, I decided to forget IE and I am now trying to use urllib2 to > open up the page, read it, etc. My problem is the page has a built-in > refresh and I don't know how to have python re-read the page until > it's ready to hand over the links. ClientCookie does that (HTTPRefreshProcessor and HTTPEquivProcessor in particular). http://wwwsearch.sf.net/ClientCookie I recommend using the alpha release. The interface will change a little soon, but you almost certainly won't notice. > An example of the page is: > http://edcw2ks23.cr.usgs.gov/Website/zipship/waiting.jsp?areaList=49.0,47.0,-122.0,-124.08&prodList=NED, > > I believe I need to read the header, grab the cookie session id, and > add it back to the header. I can do all thus, but I'm stuck on It'll do the cookies too :-) [...] > probably very simple syntax to re-read the page rather than open a new > connection, if that makes sense (I'm new to http as well as python). You don't need to ensure it's the same connection. In fact, you can't easily do that with urllib2 (or ClientCookie) as it is currently. HTH John From kamikaze at kuoi.asui.uidaho.edu Thu Aug 5 16:31:00 2004 From: kamikaze at kuoi.asui.uidaho.edu (Mark 'Kamikaze' Hughes) Date: 5 Aug 2004 20:31:00 GMT Subject: Decorator syntax References: Message-ID: C. Barnes wrote on Wed, 4 Aug 2004 18:42:48 -0700 (PDT): > I vote for > def f(): [synchronized, classmethod] > (body of function) That syntax looks plausible in toy examples, but is terrible for a more typical invocation, like: class foo: def introduceNewFeature(self, someArgument, anotherArgument): [synchronized, types="o,i,i"] pass # whatever > This is backwards compatible (Python <= 2.3 raise > SyntaxError), That's not what "backwards compatible" means, but @-syntax also raises a syntax error in older versions, which is just what you'd expect. > and looks much nicer than @. I fail to see how that's more attractive than: class foo: @synchronized @types("o,i,i") def introduceNewFeature(self, someArgument, anotherArgument): pass # whatever I'm +1 for the @-syntax. 1) It doesn't cause needless line-wrap. 2) It causes the minimum amount of confusion, because it doesn't overload an existing symbol. [] and {} and () are already pushed to their limits and beyond in Python. Give them a day off for once. 3) A large proportion of Python programmers are also Java programmers, and won't object to the @-syntax. > The only problem is that you can't one-line a > decorated function. You can't do that with > the @ notation either, so it's not a big deal. One-liners are of negative value to a language, anyway, as they encourage bad habits. That way lies Perl and other juvenile entertainments. -- Mark Hughes "Virtues foster one another; so too, vices. Bad English kills trees, consumes energy, and befouls the Earth. Good English renews it." -The Underground Grammarian, v1n2 From nomail at nospam.no Sun Aug 15 02:45:41 2004 From: nomail at nospam.no (Dominic) Date: Sun, 15 Aug 2004 08:45:41 +0200 Subject: Generators versus Coroutines In-Reply-To: <972ec5bd.0408141032.385fe115@posting.google.com> References: <972ec5bd.0408141032.385fe115@posting.google.com> Message-ID: > values. I am currently writing a real time strategy game where I have I have written a simple 2D-real-time vehicle simulator in Python (+ graphics library Allegro), using chained generators which works well enough. If your game is more ambitious, spend some time designing a good architecture and specify your components' interfaces. Then you could generate your code-skeleton from that; simple generators should be sufficient to implement your methods which are then driven by your architectures "execution model". ciao, Dominic From anthonybaxter at gmail.com Thu Aug 26 07:05:46 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Thu, 26 Aug 2004 21:05:46 +1000 Subject: Are decorators really that different from metaclasses... In-Reply-To: <412D9F1E.6000809@yahoo.it> References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: On Thu, 26 Aug 2004 10:28:14 +0200, Paolo Veronelli wrote: > It's not the ideas complexity that fears,but the feeling we are trying > to bring down to earth the supposed magic of some language solutions. > There is nothing good in magic,specially when you have to build robust > things on it. I have no idea what you're trying to say here. Are you saying that the approach of double-under variables inside a function having some new meaning, getting put into a new scope that did not previously exist, is somehow _less_ magical that the syntactic sugar of decorators? If so, how do you intend to handle the backwards compatibility issue, where code that works on Python2.4 will do something entirely different on Python2.3 (the double-under variables will be silently ignored). Do you intend that the double-under names would also be looked for in the same scopes? That is, what will this code do? def foo(): __name__ = '%s_banana'%(__name__) > If this blows away clouds on the language future and bring back the > useful features in a wider theory where metaclasses and decorators are > members of,this shouldn't be considered a hack.If it becomes a hack the > problem is to be searched and solved above generalizing the scope system. Hand waving is all well and good, but this isn't a matter of "generalizing the scope system". This is a _radical_ change to the scoping rules of Python, and I think it's safe to say that there's *absolutely* *no* *way* something like this would be considered, without an excellent reason - and bolting some sort of strange decorator semantics doesn't cut it. Anthony From adeger at netlibrary.com Tue Aug 3 15:51:32 2004 From: adeger at netlibrary.com (adeger) Date: 3 Aug 2004 12:51:32 -0700 Subject: simple Thread question Message-ID: Having trouble with my first forays into threads. Basically, the threads don't seem to be working in parallel (or you might say are blocking). I've boiled my problems to the following short code block and ensuing output. Seems like the output should be all interleaved and of course it's not. Running Python 2.2 from ActiveState on Windows XP (also doesn't work on Windows 2000). Thanks in advance! adeger #==================================================== import threading class TestThr(threading.Thread): def __init__(self): threading.Thread.__init__(self) def run(self, name): import time for i in range(1,11): print 'thread ', name, ' instance ', str(i) time.sleep(1) threads = [] for inst in ('a', 'b', 'c'): thread = TestThr() thread.run(inst) threads.append(thread) # output below thread a instance 1 thread a instance 2 thread a instance 3 thread a instance 4 thread a instance 5 thread a instance 6 thread a instance 7 thread a instance 8 thread a instance 9 thread a instance 10 thread b instance 1 thread b instance 2 thread b instance 3 thread b instance 4 thread b instance 5 thread b instance 6 thread b instance 7 thread b instance 8 thread b instance 9 thread b instance 10 thread c instance 1 thread c instance 2 thread c instance 3 thread c instance 4 thread c instance 5 thread c instance 6 thread c instance 7 thread c instance 8 thread c instance 9 thread c instance 10 From anthonybaxter at gmail.com Thu Aug 26 23:54:37 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 27 Aug 2004 13:54:37 +1000 Subject: mixing statements into J2 In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022E85@exchange.hqamor.amorhq.net> References: <3A81C87DC164034AA4E2DDFE11D258E3022E85@exchange.hqamor.amorhq.net> Message-ID: On Thu, 26 Aug 2004 10:36:08 -0700, Robert Brewer wrote: > > > The order of operation would have to be reversed, > > > > I don't see why. > > It's not a requirement, but it seems reasonable to me. If you're going > to set off a decorator suite and then mix in normal Python statements, > the two models collide over order of operation: > > using: > if test: > memoize > else: > synchronize > classmethod > def foo(self, *args): > stuff(args) Ah - see, you've _also_ included statements in the decorator block. This is not going to be allowed - the decorators _must_ be expressions. This example code is actually a pretty strong "anti" point for J2 that I hadn't been able to quite articulate before - it _looks_ like a normal block, but it isn't. Only expressions can be in it. The above _should_ generate a SyntaxError on the 'if'. From tmj at jarmania.com Thu Aug 12 14:31:00 2004 From: tmj at jarmania.com (Tim Jarman) Date: Thu, 12 Aug 2004 19:31:00 +0100 Subject: Keyword substitution in string In-Reply-To: References: Message-ID: On 12 Aug 2004, at 18:43, Ondrej Krajicek wrote: > > Hello, > > in my application, I want to do keyword substituion in > a string from a dictionary. The problem is indeed > easy to solve, but seems quite common to me, so I wonder > wheter there is already a function in Python which > does just that. > > I want to substitute values for keywords in strings, > the keywords and values are stored in a dictionary. > > Something like this: > > def subst(string, dict): > ... > > where: > > subst('Hello, !', {'key1': 'Python', 'key2': 'rules' }) > > gives: > > 'Hello, Python rules!' > > The keyword quoting style does not matter. > > Thanks, > > Ondra Yes - so common they already thought of it! See Library Reference 2.3.6.1 or here: http://docs.python.org/lib/typesseq-strings.html for an example of exactly what you want. HTH Tim J From martin at v.loewis.de Tue Aug 3 12:09:09 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 03 Aug 2004 18:09:09 +0200 Subject: Codecs for ISO 8859-11 (Thai) and 8859-16 (Romanian) In-Reply-To: References: <410c2827$0$24830$9b622d9e@news.freenet.de> <410D7AB5.9040100@v.loewis.de> Message-ID: <410FB8A5.6030701@v.loewis.de> Peter Jacobi wrote: > a) ISO 8859-n vs ISO-8859-n > If the information at > http://en.wikipedia.org/wiki/ISO_8859-1#ISO_8859-1_vs_ISO-8859-1 > is correct, Python 8859-n > codecs do implement the ISO standard charsets ISO 8859-n > in the specialized IANA forms ISO-8859-n (and in agreement > with the Unicode mapping files). So any difficult C0/C1 > wording in the original ISO standard can be disregarded. I have just asked Markus Kuhn about this, who has registered ISO-8859-16 with IANA. He believes that his registration does not include control characters (neither C0 nor C1), just as the ISO standard does not contain any. Wrt. RFC 1345 he points out that this is not an Internet Standard, but a private collection of Keld Simonsen, i.e. it is not binding. Regards, Martin From fakeaddress at nowhere.org Mon Aug 9 23:58:13 2004 From: fakeaddress at nowhere.org (Bryan Olson) Date: Tue, 10 Aug 2004 03:58:13 GMT Subject: Fixing socket.makefile() Message-ID: Here's the problem: Suppose we use: import socket [...] f = some_socket.makefile() Then: f.read() is efficient, but verbose, and incorrect (or at least does not play will with others); f.readline() is correct, but verbose and inefficient. To justify the "verbose" part, just look at the code in the Python library's socket.py. Below, I'll explain playing well with others, and then (in)efficiency. Consider the operations: f = some_socket.makefile() ch = f.read(1) print "The first char is", ch ch = some_socket.recv(1) print "The second char is", ch The code above does *not* (usually) print the first and second characters from the socket. The problem is that makefile() returns a Python object that has its own local buffer. The recv() call reads directly from the socket, oblivious to any data queued in the file object's buffer. The problem is not limited to recv(); select(), and perhaps other calls, will ignore the buffer and look directly at the socket. Output buffering appears to have a similar problem. Now look up socket.makefile().readline(). It gets one byte at a time. It will get the byte from the Python buffer if the buffer is non-empty, otherwise it will try to recv() one byte at a time, directly from the socket. By itself, readline() never over-reads the socket; if select() and recv() would work correctly before the readline(), they'll work after. While correct, reading one byte at a time is painfully slow. The Python Library Reference is silent on whether the socket.makefile operations are supposed to interact correctly with the direct socket operations. If they are supposed to play well together, then read() is wrong. If they are not, then readline() is absurdly slow. Enough of my whining. The good news is that we can have both efficiency and correctness, and we can fix the bloat at the same time. Operating systems already do efficient buffering for sockets. That efficiency varies, but any smart operating system copies buffers to user-space in large chunks, and answers recv()'s from the buffers without system calls, when possible. Python's socket module now supports MSG_PEEK, which enables Python code to examine a socket's native buffer. Below my sig, I show code to replace the corresponding member functions in the class socket._fileobject. The updated version passes the tests in test_socket.py. Make sense? Worth doing? I thought I'd talk it up here before jumping into the devel list. -- --Bryan # class _fileobject(object): def __init__(self, sock, mode='rb', bufsize=-1): self._sock = sock if bufsize <= 0: bufsize = self.default_bufsize self.bufsize = bufsize self.softspace = False def read(self, size=-1): if size <= 0: size = sys.maxint blocks = [] while size > 0: b = self._sock.recv(min(size, self.bufsize)) size -= len(b) if not b: break blocks.append(b) return "".join(blocks) def readline(self, size=-1): if size < 0: size = sys.maxint blocks = [] read_size = min(20, size) found = 0 while size and not found: b = self._sock.recv(read_size, MSG_PEEK) if not b: break found = b.find('\n') + 1 length = found or len(b) size -= length blocks.append(self._sock.recv(length)) read_size = min(read_size * 2, size, self.bufsize) return "".join(blocks) def write(self, data): self._sock.sendall(str(data)) def writelines(self, lines): # This version mimics the current writelines, which calls # str() on each line, but comments that we should reject # non-string non-buffers. Let's omit the next line. lines = [str(s) for s in lines] self._sock.sendall(''.join(lines)) def flush(self): pass From http Sat Aug 28 04:21:29 2004 From: http (Paul Rubin) Date: 28 Aug 2004 01:21:29 -0700 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <7xzn4gwgea.fsf@ruckus.brouhaha.com> <1gj7a1o.1a5d2q410jsn2kN%aleaxit@yahoo.com> <7xisb4xnh5.fsf@ruckus.brouhaha.com> <1gj7c1a.tfdm14p3hclcN%aleaxit@yahoo.com> <7xd61benm9.fsf@ruckus.brouhaha.com> <1gj82n3.1ylkr3nierngmN%aleaxit@yahoo.com> <7x4qmnvgcu.fsf@ruckus.brouhaha.com> Message-ID: <7xvff3u0za.fsf@ruckus.brouhaha.com> Paul Rubin writes: > > Side question, does module zipfile already have the code to allow > > reading such signed files? > > I think jar files are just zip files containing an extra file (called > "manifest") that has signatures in it. So you can import from a jar > as if it were a zip. But to add to that, if module zipfile is going to eventually expect jar files to be signed, the first patch needed is that if it doesn't have code to actually check the signatures, it should refuse to load jar files. I guess I better check into what Java does about this. It's been a while since I've used Java, but I seem to remember that signing is not mandatory. From anthonybol2 at netscape.net Fri Aug 13 23:40:03 2004 From: anthonybol2 at netscape.net (TonyB) Date: 13 Aug 2004 20:40:03 -0700 Subject: Seperating CSV rows into new, seperate files Message-ID: Hi, I've searched the group and need more information and guidance on this issue I need to resolve next week. I work for the local school system and I am working on a way to parse a CSV file of class lists from MS Excel. It is a ~2MB file with all teachers and all their classes in it. I thought I would use Python to do this since many people I know tell me how great it is. The real sticking point is there are duplicates of each teacher's classes embedded in the file (don't ask why). I want to break up the source file into the seperate class files without duplication and use the teachers name, coursecode and section in the filename. Example Data: Last Name First Name Grade Period Teacher Name SMITH JOHN 8 1 JONES SALLY Student ID Course Code Course Title 12345678 1234 ALGEBRA I Course Section Session 1 0 The course code and section number are the same in the duplicate classes. The difference is that the session number changes. I'm thinking that I will need to somehow iterate through the lines and break the class when the course code changes and/or section change (course codes can be the same but section numbers change with each class). Then I have to monitor the session number to see if there is a duplicate course code and section but a different session number would indicate that the class is a duplicate. Essentially, the session number will be 0, 1, or 2 for a total of three lists of the same class. Hopefully that makes sense. Again don't ask why the data is like this. My humble attempts have not been very successful. I've been trying the csv modules to read the file but I am not sure how to procede after that. Any guidance is greatly appreciated. From arien_malec at yahoo.com.REMOVE Mon Aug 23 13:19:15 2004 From: arien_malec at yahoo.com.REMOVE (Arien Malec) Date: Mon, 23 Aug 2004 17:19:15 GMT Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? References: Message-ID: "Paul McGuire" wrote in news:pUTVc.8393$Jn5.5720 at fe1.texas.rr.com: > Please start giving some thought to what the 'decorate' keyword should > be. If we can get/keep this selection to a manageable list, then we > should have another multivote some time next week. "transform:" In general: Something that is either semantic neutral, or makes semantics explicit. Arien From squirrel at WPI.EDU Mon Aug 16 10:39:29 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Mon, 16 Aug 2004 10:39:29 -0400 Subject: NumArray array-indexing In-Reply-To: References: Message-ID: On 16 Aug 2004, Michael Drumheller wrote: > However, whereas [1, 2, 3] passed as an index-array will get you the > second, third, and fourth rows of a rank-2 matrix, [[1,2,3]] will *not* > do that. (It gets you some other weird thing that I can't remember.) > That is, a single-row matrix may be the same thing as a row vector > in a mathematical context, but it is not the same thing in an > array-indexing context. Similarly, passing [[1], > [2], > [3]] > as an index array doesn't get you anything remotely like the second > third, and fourth columns. So it seems to me that array indexing > can easily get you an arbitrary subset of rows, but not an arbitrary > subset of columns. Would you agree? Forgive the poor flow of the following; I've rewritten it a couple of times. Think about what you're trying to do for a second. You want to pass a list of indices to extract along a given axis. You need three pieces of information to do this: which indices, which axis, and possibly the geometry of the output vector. You're supplying the wrong information; you're supplying which indices, and a geometry. Matlab guesses the right information (which axis) from the wrong information (the geometry). When you index a 2-dimensional array in Matlab, what happens? If the index array is a row vector, then the indices you supply index the first dimension. If the index array is a column vector, then the indices index the second dimension. But what if the index array is two-dimensional? Which dimension should the indices index? (For the record, they seem to index the second dimension.) numarray, on the other hand, provides an exact mechanism for supplying index arrays thusly: >>> a=array([[1,2,3],[4,5,6],[7,8,9]]) >>> a[[1,2],[0,0]] array([4,7]) In this example, [1,2] are the row indices, and [0,0] are the column indices (the information Matlab guesses for you). You can abbreviate [0,0] as just 0: >>> a[[1,2],0] array([4,7]) (try the previous in Matlab; you will get similar results) You can index along another column vector if you want: >>> a[[1,2],1] array([5,8]) Or you can arbitrarily index both dimensions (AFAICT, something not possible in Matlab): >>> a[[1,2],[0,1]] array([4,8]) Note that doing the above in Matlab results in a 2x2 matrix, probably not what was wanted. The explicit numarray equivalent to that Matlab construction is a[[[1],[2]],[[0,1]]]. Note also that the output vector takes the shape of the index vector: >>> a[[[1,2]],0] array([[4,7]]) >>> a[[[1],[2]],0] array([[4], [7]]) So the answer to your question is, yes, not only can you use arbitrary array indices in numarray, they're more powerful than the Matlab equivalent. Yet another reason why explicit is better than implicit. From anthonybaxter at gmail.com Thu Aug 5 12:31:00 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 02:31:00 +1000 Subject: Confused about pep 318 In-Reply-To: References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: On Thu, 5 Aug 2004 12:12:59 -0400, Christopher T King wrote: > This is the post that started it all: > http://mail.python.org/pipermail/python-dev/2004-August/046599.html > > Quote: > The @decorator patch has been landed on the trunk, after > getting the go-ahead from the BDFL. I'll update PEP-0318 > with the final syntax in the next day or so. > > That's the first most people had heard of it. Guido had given Anthony > Baxter the go-ahead in a private e-mail. There had previously been no > public discussions about it. Nonsense. http://mail.python.org/pipermail/python-dev/2004-June/thread.html#45516 was over a month earlier. In addition, the particular SF item for this http://www.python.org/sf/979728 wasn't exactly hidden. Anthony From porky_pig_jr at my-deja.com Wed Aug 18 21:05:25 2004 From: porky_pig_jr at my-deja.com (Porky Pig Jr) Date: 18 Aug 2004 18:05:25 -0700 Subject: IDLE under Cygwin doesn't show toolbar menu Message-ID: <56cfb0e3.0408181608.794fed82@posting.google.com> Just downloaded and installed the latest Cygwin distribution which includes python 2.3.4. IDLE runs fine but for some reason the toolbar menu doesn't show up. Like, by default, it starts shell window, but no toolbar. If I type idle foobar.py it brings both shell and editor windows, but once again, no toolbar on either window -- which renders the edtior quite disfunctional. Just want to check if anyone else ever ran into this problem and what was the workaround -- before I contact Cygwin folks. TIA. From peter at engcorp.com Wed Aug 11 11:40:32 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 11 Aug 2004 11:40:32 -0400 Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: References: Message-ID: John Marshall wrote: > How about the following, which I am almost positive > has not been suggested: > ----- > class Klass: > def __init__(self, name): > self.name = name > > deco meth0: > staticmethod > def meth0(x): > return x > > ----- > 1) The decorators clearly apply to a specific method/function, > therefore there is no need to do any stack pushing in memory > until the method/function definition is done. Problems with that: duplication (since you now have the name of the function in two places) and readability (it's harder to see the "def" because the name you picked is too close to it in length and appearance). On the other hand, there's no need to have the function name there (was anyone complaining about "stack pushing"?), so maybe just using "decorate" would be okay, or a different keyword: class Klass: # init set decorate: staticmethod def meth0(x): return x > 2) The decorators are "outside" of the method/function they > decorate: > a) which will please those who want the outside location > b) will not be folded within the function > c) folding on the decorators can be done so that the > def is not obfuscated > d) can be located anywhere in the code--but most likely > before the "def ...()" > 3) The sequence in which the decorators are applied is just > like code would be--this is certainly intuitive given > that we are writing code. > Any comments? Has potential, I think, with some changes. I like the following about it: 1) keyword instead of punctuation 2) indentation consistent with rest of Python 3) similarity to try/finally or while/else and friends where the two clauses are coupled I wouldn't mind seeing exactly the same idea allowed for decorators *inside* the function as well, so that we can experiment for a while and see which, if any, is preferred, but I doubt that would happen. -Peter From anthonybaxter at gmail.com Fri Aug 6 00:21:50 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 14:21:50 +1000 Subject: Proposed improved decorator syntax In-Reply-To: References: <1091753696.4112d6e06ea9e@webmail.oregonstate.edu> <1091564446.20040805213345@MailBlocks.com> Message-ID: On Thu, 5 Aug 2004 21:33:45 -0600, Bruce Eckel wrote: > I don't know if "experimental features" have been put into the > language before, ones that actually exist in a release but have > warnings on them that say "things may change as we learn more." But if > not, it seems like this might be the time to start. I think we need > something to express metadata and/or code behavior change and/or > whatever it is that we're really trying to do, but I don't think we'll > figure out what that is until we have something to experiment with -- > and change. I don't think any "experimental features" will remain experimental beyond the alpha cycle of a release. Once we hit beta, we stop experimenting. This is a pretty fundamental thing about Python, in comparision to other languages - it's rare for something to be taken away after it's added. From nzanella at cs.mun.ca Wed Aug 11 15:19:21 2004 From: nzanella at cs.mun.ca (Neil Zanella) Date: 11 Aug 2004 12:19:21 -0700 Subject: PyQt + PygreSQL References: Message-ID: Grzegorz Dostatni wrote in message news:... > I don't know how to set it up using pygresql, but you can do it using > qtsql module. Just make sure that qt was compiled with the postgresql > support. Thanks, I should have used the Python equivalent of QSqlDatabase::addDatabase() to connect to PostgreSQL instead of using PyGreSQL. That way QDataTable can find and use the database connection handle it knows about. After all, PyQt knows nothing about PyGreSQL: as you just pointed out the two packages are completely unrelated and independent of each other. > If you need to use pygresql for some reason, you could always try to have > multiple connections to the database from you code (one through qtsql > module, another through qtsql). Exactly, but actually now that you pointed this out to me I don't think I will need PyGreSQL since I'm already using the Qt database module. Thanks, Neil From indigo at bitglue.com Wed Aug 18 15:30:00 2004 From: indigo at bitglue.com (Phil Frost) Date: Wed, 18 Aug 2004 15:30:00 -0400 Subject: name of current program In-Reply-To: <4a0cafe20408181227543a1284@mail.gmail.com> References: <4a0cafe20408181227543a1284@mail.gmail.com> Message-ID: <20040818193000.GB30372@unununium.org> sys.argv[0] will yield the command that was used to invoke the program. On Wed, Aug 18, 2004 at 02:27:39PM -0500, Josh Close wrote: > This is a simple question, but I can't find the answer for some reason. > > How do I get the name of the current script/program that is running? From sholden at holdenweb.com Tue Aug 31 09:26:36 2004 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 31 Aug 2004 09:26:36 -0400 Subject: GUI Wizard: flow control? In-Reply-To: References: Message-ID: David Chan wrote: > Hi, > > I'm trying to use python to create GUI wizards, i.e. sequences of dialog > boxes with buttons. Since I want to re-use some of the > dialog boxes in different wizards, I want to have a main function which > calls each dialog box, much like this: > > def select_item(): > """runs GUI wizard to select item""" > > client = show_client_dialog() > job = show_job_dialog(client) > invoice, rate = show_invoice_dialog(job) > item = choose_item_dialog(invoice, rate) > return item > > This works fine until you want to implement the return to the previous dialog. Theoretically, what I'd really like is to be > able to jump backwards through the control flow, like this: > > class GoBack(Exception): pass > def select_item(): > """runs GUI wizard to select item - can go back = HERE > client = show_client_dialog() > > try: job = show_job_dialog(client) > except GoBack: back.goto() > back = HERE > > try: invoice, rate = show_invoice_dialog(job) > except GoBack: back.goto() > back = HERE > > try: item = show_item_dialog(invoice, rate) > except GoBack: back.goto() > > return item > > But I couldn't find a way of doing anything like that. You could do > something almost as unhorrible with nested breaks:' > > class GoBack(Exception): pass > def select_item(): > """runs GUI wizard to select item - can go CLIENT: while 1: > client = show_client_dialog() > > JOB: while 1: > try: job = show_job_dialog(client) > except GoBack: continue CLIENT > > INVOICE: while 1: > try: invoice, rate = show_invoice_dialog(job) > except GoBack: continue JOB > > try: item = show_item_dialog(invoice, rate) > except GoBack: continue INVOICE > break CLIENT > > Or you could do all the flow control manually in a "do_wizard" function and > make the caller create a horrible data structure instead of writing readable > code: > > calls = [ > {'meth': show_client_dialog, 'args': [], 'ret': ['client']}, > {'meth': show_job_dialog, 'args': ['client'], 'ret': ['job']}, > {'meth': show_invoice_dialog, 'args': ['job'], 'ret': ['invoice', 'rate']}, > {'meth': show_item_dialog, 'args': ['invoice', 'rate'], 'ret': ['item']}, > ] # this just says: "client = show_client_dialog()", etc. > do_wizard(calls, locals()) > > > But this is too hideous to deploy, because I might have to remember what it > does in six months :-) > > Can anyone suggest something better, or should I abandon my goal of having a > main function which calls each dialog box? > > Many thanks, Caveat: I am assuming that your chosen GUI allows you to easily choose which of a number of panels is displayed inside a dialog. This is typically most easily done with the component usually known as a notebook. You create a list a panels, each of which you have constructed using your chosen GUI. You then associate the "Next" button with a function that displays the next panel in the sequence, and the "Back" button with a function that displays the preceding panel in the sequence. The dialog then becomes just a list of the panels, plus a counter to tell you which in the sequence is currently being displayed. You *don't* want to try and control flow through the sequence in the way you have attempted. Typically windows are actually just data structures, and so data-driven methods will work best. Naturally, each of the panels in the notebook will have callbacks associated with the various widgets, and interaction with those widgets will change the data that your program eventually sees when the user clicks the "Finish" button. If you want to reuse the panels then make sure they are properly modularized so their creators can be called used in different programs. regards Steve From guettli at thomas-guettler.de Thu Aug 19 10:11:51 2004 From: guettli at thomas-guettler.de (Thomas Guettler) Date: Thu, 19 Aug 2004 16:11:51 +0200 Subject: favorite python web development tool? References: <10i4nttktcvltdd@corp.supernews.com> <899f842.0408180922.38a834e9@posting.google.com> Message-ID: Am Wed, 18 Aug 2004 10:22:43 -0700 schrieb Anthony_Barker: >> given my background, webware+cheetah feels comfortingly familiar, and >> i'm leaning toward it. before i dive in, though, i'm wondering what you >> experienced users think about it, compared to the other tools that are >> out there. eg, does the python environment have strengths that are >> better exploited with something other than a servlet-like model? > > Have a look at mod_python 3.1 - I've found performance very good. I > benchmarked it against a commercial oversized J2EE app server and for > non complex app found it faster. It includes session handling and a > basic template system. However, you can use whichever templating > language you like with it. Cheetah is nice Hi Anthony, Did you compare it to SCGI, too? http://www.mems-exchange.org/software/scgi/ Thomas From bdesth.quelquechose at free.quelquepart.fr Wed Aug 18 04:20:02 2004 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 18 Aug 2004 10:20:02 +0200 Subject: favorite python web development tool? In-Reply-To: <10i4nttktcvltdd@corp.supernews.com> References: <10i4nttktcvltdd@corp.supernews.com> Message-ID: <41230917$0$20703$626a14ce@news.free.fr> mike wrote: > hi all - > > > i'm fairly new to python, coming from a java servlet / velocity template > background. i'm looking for a good python web development tool, and > hope to find some suggestions here. > > given my background, webware+cheetah feels comfortingly familiar, and > i'm leaning toward it. before i dive in, though, i'm wondering what you > experienced users think about it, compared to the other tools that are > out there. eg, does the python environment have strengths that are > better exploited with something other than a servlet-like model? > Well, I'm currently writing my first app with Zope, and I find it a wonderful (but alas very badly documented) tool, at least compared with PHP. I wrote in 3 days what would have took me *at least* twice that time with a PHP based solution. I can't tell you much about other python-based solutions since I did not try them. From mattjensen at timetospare.net Mon Aug 30 18:10:45 2004 From: mattjensen at timetospare.net (Matthew K Jensen) Date: 30 Aug 2004 15:10:45 -0700 Subject: console window not disappearing with py2exe Message-ID: <173c23bb.0408301410.49b27fe4@posting.google.com> In another one of my silly apps, I'm using 'windows=' in the setup script. I can't get the darn console window do disappear. Since the said app is going to be used with people that have less-than-average knowledge in computers, it is imperative that this window goes away. I tried sys.frozen = "windows_exe" and it doesn't work. I'm not sure what to do. Please save me! -Matt K Jensen From jaydonnell at yahoo.com Wed Aug 25 12:56:26 2004 From: jaydonnell at yahoo.com (Jay Donnell) Date: 25 Aug 2004 09:56:26 -0700 Subject: urllib hangs References: Message-ID: Your example needed the module name in front of the method calls in test.py Here it is in case anyone is interested. I had no idea that this sort of think could be done. ## foo.py def A(): print "original A called" def B(): A() # this could also be in another module # the effect would be the same ###### bar.py # this is an addon that modifies foo import foo origA = foo.A def newA(): print "new A called" foo.A = newA #!/usr/bin/python ###### test.py import foo foo.B() import bar foo.B() From Scott.Daniels at Acm.Org Sat Aug 28 14:43:56 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 28 Aug 2004 11:43:56 -0700 Subject: How to generically transform a list? In-Reply-To: References: Message-ID: <4130d3e9$1@nntp0.pdx.net> Marco Aschwanden wrote: > > Thanks to all the hints which seem to prove that there is one and only > one sensible approach - though some (like me) needed a few more lines. > > It is just funny how easy horizontal slicing is made (list[:]) but how > "difficult" vertical slicing is. It is a common task and one does not > realize how often one does need vertical slicing. eg.: getting the keys > of dictionary is a vertical slicing, or turning a list into a dict > involves vertical slicing... > > Just out of pure curiosity: Is there a langue that allows vertical and > horizontal slicing and dicing with the same built-in pattern? > > Regards, > Marco (Eagerly awaiting the cookbook's second edition) > > > Check out Numeric (for Python). They do lots of slicing anddicing. APL cetainly has (had?) it as its meat. I think J is an ASCII-friendly APL variant. -Scott David Daniels Scott.Daniels at Acm.Org From me at privacy.net Tue Aug 31 17:05:48 2004 From: me at privacy.net (James Keasley) Date: 31 Aug 2004 21:05:48 GMT Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4PGdnfsOfdDPi63cRVn-tA@speakeasy.net> <41337FC9.8070902@hotmail.com> <%T%Yc.29567$Es2.11957889@news4.srv.hcvlny.cv.net> <4134AC88.56452265@yahoo.com> <8KadnRWhvb1sRqncRVn-tg@adelphia.com> Message-ID: On 2004-08-31, Sherm Pendley wrote: > red floyd wrote: > >> Let the editor flame wars begin! > > Anyone else remember Blackbeard? Arr Sherm, me-lad, that I do, great man, never got his round in though ;) -- James jamesk[at]homeric[dot]co[dot]uk Black holes suck! From donn at drizzle.com Mon Aug 16 00:42:57 2004 From: donn at drizzle.com (Donn Cave) Date: Mon, 16 Aug 2004 04:42:57 -0000 Subject: os.system(), HTTPServer, and finishing HTTP requests References: None <41201e06@nntp.zianet.com> Message-ID: <1092631376.357585@yasure> Quoth "Erik Johnson" wellkeeper com>: ... | But if I make this same os.system() call from within my own HTTPServer, | then the browser that is making the request is left hanging until that | sleeping grandchild is done. It's like there is still a socket connection | between it and my browser?!? But the grandchild is not forked from the | server - it's an os.system() call! It should not be inherting any file | descriptors and such, right? On the contrary, system() does call fork - basically, def system(command): pid = fork() if pid: return waitpid(pid, 0)[1] else: execve('/bin/sh', ['sh', '-c', command], environ) and indeed file descriptors will be inherited. You'll have to explicitly close the socket. Donn Cave, donn at drizzle.com From in.aqua.scribis at nl.invalid Sat Aug 21 15:45:53 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Sat, 21 Aug 2004 21:45:53 +0200 Subject: unicodedata name for \u000a In-Reply-To: References: Message-ID: Ken Beesley schreef: > > There is, of course, a Unicode name for \u000a, No, there isn't. Check http://www.unicode.org/charts/PDF/U0000.pdf -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From pm_mon at yahoo.com Tue Aug 17 19:29:34 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Tue, 17 Aug 2004 19:29:34 -0400 Subject: PEP 318: Can't we all just get along? In-Reply-To: <20040817181725194-0400@braeburn.themorgue.org> References: <20040817181725194-0400@braeburn.themorgue.org> Message-ID: Kevin Smith wrote: > For what it's worth, I wrote the original PEP 318. I probably wasn't > qualified, but I just wanted a nice simple way to declare class methods > without having to repeat the function name. After submitting it to BDFL > for approval, more work was needed and the discussion of PEP 318 on > python-dev increased rapidly. It was evident that I was in over my head, > so I asked more someone more experienced to take over. > > I guess others had bigger plans for my proposal that I had planned. It > has turned into the "solution" to many problems: type checking (both > arguments and returned values), metaclasses, metadata, interfaces, > function attributes, etc.). Unfortunately, in the process, this simple > request for syntactical sugar has turned into a monstrosity. In my > opinion, none of the proposed syntaxes really seem Pythonic. This PEP > just seems to be trying to solve too many problems. > > Bear with me, but I'd like to propose one more syntax that is simple, > easy for newbies to understand, and nowhere near as powerful as the > current PEP's syntax. However, it doesn't add incoherent, arbitrary > syntax either. > > def classmethod foo(x, y, z): > pass > > That's it. One "decorator" that is a callable object that takes a > method as it's only argument. No expressions, lists, tuples, etc. Just > one callable object. Ok, if you absolutely must have more than one. > > def classmethod synchronized foo(x, y, z): > pass > > Once again, no expressions. I know that this isn't going to solve > everyone's type-checking, metadata, and function attribute problems, but > let's face it, using this PEP for all of those things just creates ugly > syntax. There must be more Pythonic ways to do those things in their > own PEPs. > Nope. That's using static declarations. We're a dynamically typed language as much as possible. Isn't there something that doesn't require any additional grammar words to identify classmethods and staticmethods? Isn't there something, inherent in the way static, class, and instance methods 'look' naturally, that would tell us what they are? From po-yung.liu at pandora.be Wed Aug 25 15:12:43 2004 From: po-yung.liu at pandora.be (Vent d'Est - East Wind) Date: Wed, 25 Aug 2004 19:12:43 GMT Subject: 100 % portable ? In-Reply-To: References: Message-ID: > > > I think you've missed the point of wxWidgets/wxPython: it uses native > widgets on each platform. On OS X, it uses Aqua widgets; on Linux, QT > or GTK, on Windows, native Windows widgets. > > So, you're not going to get the same appearence on different > platforms (which is a good thing; I don't want to use something that > looks like Windows on a Mac). > yeah i like it too Acqua style , but what i didn't understand before it s how it can be do that (my point of view was like a java vm , so that s why i think it s same apparence in other system too) now i visited wxwidget , explanation simple and interresting :) just what i search , graphical toolkit native on different plateforme supporting same code :) thankxx a lot From David.Vaughan at Gifford.UK.com Thu Aug 26 09:08:49 2004 From: David.Vaughan at Gifford.UK.com (David Vaughan) Date: Thu, 26 Aug 2004 14:08:49 +0100 Subject: Call for signatories for J2 Message-ID: I vote FOR the "J2" proposal as described at http://www.aminus.org/rbre/python/pydec.html Please add my name to the "in favor" list there. David David Vaughan Structural Analyst for Gifford _____ GIFFORD AND PARTNERS LTD Carlton House, Ringwood Road, Woodlands, Southampton, SO40 7HT, UNITED KINGDOM Tel: +44 (0)23 8081 7500 Fax: +44 (0)23 8081 7600 Email: David.Vaughan at gifford.uk.com Web: http://www.gifford.uk.com _____ This e-mail and any files transmitted with it are intended solely for the use of the individual or entity to whom they are addressed and may be confidential. If you are not the intended recipient or the person responsible for delivering the e-mail to the intended recipient, be advised that you have received this e-mail in error and that any use, dissemination, forwarding, printing or copying of this e-mail is strictly prohibited. From mwilson at the-wire.com Sat Aug 28 20:00:45 2004 From: mwilson at the-wire.com (Mel Wilson) Date: Sat, 28 Aug 2004 20:00:45 -0400 Subject: Generator expressions v/s list comprehensions References: <1gj8y77.6qshr41q531veN%aleaxit@yahoo.com> Message-ID: In article , Mahesh Padmanabhan wrote: >I am still not clear of the advantages of using generator expressions >(other than less memory consumption) instead of list comprehension for >any given class of problems. Can you cite concrete use cases where >generator expressions would be preferred over list comprehension? Storage economy and the time saved by omitting lots of object creation and destruction are the main advantages of generator expressions. The advantage of lists is that they'll stand still while you do things to them (things like iterating over them in many and novel ways.) The mind does boggle at the idea of a data-processing program that has replaced all containers with generator expressions, and creates all its information on-demand without storing anything anywhere. Regards. Mel. From justin__devine at hotmail.com Mon Aug 30 13:12:30 2004 From: justin__devine at hotmail.com (Justin) Date: 30 Aug 2004 10:12:30 -0700 Subject: Size of a remote URL In-Reply-To: Message-ID: I want to track the download of files in a progress bar. I asume I need the final size to do that so I can compare it to the current size on disk. Le tme know if you know anything From mnh at cogitation.org Tue Aug 3 13:19:25 2004 From: mnh at cogitation.org (Mark Hertel) Date: Tue, 3 Aug 2004 17:19:25 +0000 (UTC) Subject: MYSQL and use of blobs References: Message-ID: On Thu, 29 Jul 2004 08:48:28 -0500, Raaijmakers, Vincent (GE Infrastructure) wrote: > It is the first time that I use blobs in mysql Please help me out . > here.... . > > Using MSSQLdb and python 2.3.4 I was surprised to see how my > information was stored in the blob. My goal is to store JPG > images in the blob. Well, it stores it but as a string of bytes: > 'x0dx0fxffxa3......' > > So, when reading back that information into my python environment, it > seems that I need to translate the value back to the original binary > format? > > Sniffed for an hour in the asciibin, binhex and other modules... > > Somebody with experience to help me out here? Is there something > fundamentally that I do wrong here? In storage, retreiving... > > Any help would be very appreciated. Vincent I didn't have to do anything more fancy than read the information from the database and write it as a binary file. SQL table: create table if not exists audioImage(id int auto_increment primary key, problemID int, realName varchar(250), shortName varchar(250), data longblob Storing the images/audio files: fileData = open(fileName, 'rb').read() fileData = zlib.compress(fileData,9) fileData = db.escape_string(fileData) query = "insert into audioImage(problemID, data, shortName) values(%d, '%s', '%s')" % (problemID, fileData, file) Retrieving the stored images or audio files: self.db.execute('select shortName,data from audioImage where id=%d' % int(id)) result = self.db.getAll() fileName = result[0][0] retResult = result[0][0] realData = zlib.decompress(result[0][1]) open(fileName,'wb').write(realData) This deposits the audio/image files in the current directory where the program picks them up and uses them. There wasn't anything special to do, other than retrieving and decompressing the data. --Mark Hertel From peter at engcorp.com Tue Aug 31 14:40:41 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 31 Aug 2004 14:40:41 -0400 Subject: Converting integers to english representation In-Reply-To: References: Message-ID: brianc at temple.edu wrote: > I'm developing a system to parse and enumerate addresses. The > current obstacle is numbered streets. Does anybody know of a > module already written to convert integers to their english > equivalents? > > Example: > 1ST -> FIRST > SECOND -> 2ND > > Anything towards that direction would greatly help and save me > a lot of time then from starting from scratch. The word you are missing is probably 'ordinal', as opposed to cardinal (one, two, three) numbers. Google can likely help you with a search for "ordinal number convert' or such. -Peter From bulliver at badcomputer.no-ip.com Tue Aug 24 17:13:23 2004 From: bulliver at badcomputer.no-ip.com (Darren Kirby) Date: Tue, 24 Aug 2004 14:13:23 -0700 Subject: How does a "script" differ from a "program" or "subroutine"? In-Reply-To: References: Message-ID: <200408241413.23777.bulliver@badcomputer.no-ip.com> Larry Wall said it best: "A script is what you give the actors, a program is what you give the audience" -- Part of the problem since 1976 http://badcomputer.no-ip.com "...the number of UNIX installations has grown to 10, with more expected..." - Dennis Ritchie and Ken Thompson, June 1972 From fumanchu at amor.org Thu Aug 26 16:42:44 2004 From: fumanchu at amor.org (Robert Brewer) Date: Thu, 26 Aug 2004 13:42:44 -0700 Subject: Inline Conditionals? Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E8B@exchange.hqamor.amorhq.net> Alex Martelli wrote: > Antoon Pardon wrote: > ... > > When using list comprehension not having a ternary operator can be > > a PITA. It is of course possible I miss something but how am I > > supposed to do the following: > > > > [ x.property ? foo(x) : bar(x) for x in Somelist ] > > If you HAVE to use an LC by doctor's order, the above effect might be > obtained by coding something like: > > [ (bar,foo)[bool(x.property)](x) for x in Somelist ] > > If your physician should relent and let you code normal > Python, though, > > aux = [] > for x in Somelist: > if x.property: > aux.append(foo(x)) > else > aux.append(foo(x)) > > would be vastly more readable; "sparse is better than dense" > and any LC > is far too dense to be Pythonic here. Case in point: it makes it *vastly* easier to see the typo. What happened to bar()? But you planned that so someone else could deliver the punch line, didn't you? ;) Robert Brewer MIS Amor Ministries fumanchu at amor.org From peter.maas at mplusr.de Fri Aug 27 04:51:55 2004 From: peter.maas at mplusr.de (Peter Maas) Date: Fri, 27 Aug 2004 10:51:55 +0200 Subject: Larry Wall & Cults In-Reply-To: References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: George Neuner schrieb: >>Unixism >> > > > "Isms", in my opinion, are not good. A person should not believe in > an "ism". He should believe in himself. Yes! Down with electromagnetism, optimism, idealism. And first of all: Fight patriotism. ;) -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- From dperl at rogers.com Fri Aug 27 13:18:24 2004 From: dperl at rogers.com (Dan Perl) Date: Fri, 27 Aug 2004 17:18:24 GMT Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> Message-ID: Yes, I saw that after posting my initial message. Thanks though, Anthony! Dan "Anthony Baxter" wrote in message news:mailman.2538.1093626899.5135.python-list at python.org... > On Fri, 27 Aug 2004 17:06:06 GMT, Dan Perl wrote: > > Here is a python feature that I would like: to be able to import modules > > from an archive like the jar files in Java. Maybe a regular tar file? > > Maybe a python specific file type, let's call it a 'par' file? > > Or a zip file, perhaps? See PEP-0273, which was implemented in Python 2.3. > > (Hm. 273 isn't up-to-date. This is bad :-( From alikakakhel3 at hotmail.com Sun Aug 15 22:17:50 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 15 Aug 2004 19:17:50 -0700 Subject: I am in great need of code to make a dome Message-ID: <8f17f4bc.0408151817.6fa5eae0@posting.google.com> I am in great need of code that will make a dome. I would like the inputs to be similar to that of the sphere. ie: pos=(x0, y0, z0) radius = R color = (r,g,b) etc. I am using VPython of course. Please help me. From maxm at mxm.dk Mon Aug 30 18:35:11 2004 From: maxm at mxm.dk (Max M) Date: Tue, 31 Aug 2004 00:35:11 +0200 Subject: "Content-Length" header In-Reply-To: References: Message-ID: <4133ab0e$0$301$edfadb0f@dread12.news.tele.dk> Peter Kleiweg wrote: > Justin schreef: > >>I found the answer. After about 3 hours of agonizing over it it turned >>out to be CASE >>some webservers are CASE SENSITVE about their urls and some are not. > > There are case-insensitive webservers? Never knew that. As far as I remember IIS is case insensitive. I guess it would have to be when the os is. regards Max M From hbl at st-andrews.ac.uk Fri Aug 27 13:05:45 2004 From: hbl at st-andrews.ac.uk (Hamish Lawson) Date: 27 Aug 2004 10:05:45 -0700 Subject: age of Python programmers References: Message-ID: <2d0b37fc.0408270905.6306fe5c@posting.google.com> 40 Hamish Lawson From bryanjugglercryptographer at yahoo.com Wed Aug 11 21:49:45 2004 From: bryanjugglercryptographer at yahoo.com (Bryan Olson) Date: 11 Aug 2004 18:49:45 -0700 Subject: rsa implementation question References: <1092200894.4119a9beb1978@www-mail.usyd.edu.au> <200408110852.57937.heikowu@ceosg.de> <5GkSc.124$O72.121@newssvr14.news.prodigy.com> Message-ID: <1a517b5.0408111749.6428df94@posting.google.com> Ajay wrote: > could you elaborate on that? i thought signing by decrypting is > the way to do it. That is how Rivest, Shamir and Adleman originally presented it, and they did win the ACM's Turing Award for the work, but the use of 'raw' RSA is full of subtle problems. To understand the basics, see chapter 11 of the book that Heiko Wundram cited: (available free on-line) http://www.cacr.math.uwaterloo.ca/hac/ In you really want to understand the math, I cited some of the major papers in my response to Wundram. That's beyond the scope of this group. If you're implementing, just use a current standard that cryptologists respect. For basic RSA (en/de)crypt and sign/verify, PKCS#1 is a fine way to go. As I write this the current version is 2.1, which is also published as RFC 3447. -- --Bryan From Michael.J.Fromberger at Clothing.Dartmouth.EDU Sat Aug 21 18:49:43 2004 From: Michael.J.Fromberger at Clothing.Dartmouth.EDU (Michael J. Fromberger) Date: Sat, 21 Aug 2004 18:49:43 -0400 Subject: Fate of lambda, Functional Programming in Python... References: <412636D1.6070808@noaa.gov> <41265E67.A08409A6@juno.com> <2on5k1FcjmvdU1@uni-berlin.de> <4dxun9nvgeaz.dlg@baczek.net.invalid> <87y8k9hqnq.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Message-ID: In article <87y8k9hqnq.fsf at debian.i-did-not-set--mail-host-address--so-shoot-me>, 510046470588-0001 at t-online.de wrote: > Marek writes: > > may map, filter, reduce be implemented in pure python if they weren't > built-in? scheme e.g. does not have built-in filter, but may > implement it on the fly. I do not see any reason why not. Simple map and filter implementations for lists are almost trivial given list comprehensions. But, you do have to be slightly careful of return types; I think the following implementations are correct: def map(fn, *lsts): assert(len(lsts) > 0) return [ fn(*args) for args in zip(*lsts) ] def filter(fn, seq): if fn is None: out = [ x for x in seq if x ] else: out = [ x for x in seq if fn(x) ] if isinstance(seq, str): return str.join('', out) else: return type(seq)(out) Reduce is a little bit harder to get exactly right, because of the semantics of the initial value. However, I do think the following does most of what reduce() is supposed to, even though it is not quite equivalent to the existing reduce(): def reduce(fn, seq, init = None): seq = iter(seq) if init is None: try: init = seq.next() except StopIteration: raise TypeError("reduce() of empty sequence " "with no initial value") for elt in seq: init = fn(init, elt) return init To perfectly emulate the built-in reduce, you would have to declare it as reduce(fn, *args), to distinguish between the case when the user omitted the init argument, and when they actually specified it as None. That makes the code nastier, of course. > may lambda be implemented with exec if it isn't built-in? Not directly; the lambda form is currently wired into the syntax, and there is no macro system. Scheme (and other Lisp dialects) can get away with a lot fewer built-in special forms because of the relative ease of writing macros. Macros for an infix language are not impossible, by any means, but they are definitely not easy (and definitely not "Pythonic"). I would prefer to see an expression-level function constructor to remain in the language. I don't care if it's called "lambda" per se, and I don't care if the syntax changes, but I would definitely like to keep the functionality around. Now that there ARE nested scopes, it seems that Guido's initial objections to the construct are mostly moot. -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From michael at foord.net Mon Aug 2 06:45:17 2004 From: michael at foord.net (Fuzzyman) Date: 2 Aug 2004 03:45:17 -0700 Subject: Making a socket connection via a proxy server References: <8089854e.0407300433.4c09bce0@posting.google.com> <_yvOc.5828$Z14.7072@news.indigo.ie> Message-ID: <8089854e.0408020245.47bcb5df@posting.google.com> [snip..] > > > > It looks like the Tiny HTTP Proxy (using BaseHTTPServer as it's > > foundation) intercepts all requests to local addresses and then > > re-implements the request (whether it is CONNECT, GET, PUT or > > whatever). It logs everything that goes through it - I will simply > > edit it to amend the URL that is being asked for. > > Yes, that is exactly what the proxy should do. It relays requests > between client and server. However, there is one vital detail you're > probably missing that is preventing you from chaining client + proxy*N > + server together. > > When sending a HTTP GET request to a server, a client sends a request > line containing a URI without a server component. This is because the > socket connection to the server is already formed, therefore the > server connection details do not need to be repeated. So a standard > GET will look like this > > GET /index.html HTTP/1.1 > > However, it's different when a client connects to a proxy, because the > socket no longer connects directly to the server, but to the proxy > instead. The proxy still needs to know to which server it should send > the request. So the correct format for sending requests to a proxy is > to use the "absoluteURI" form, which includes the server details, e.g. > > GET http://www.python.org:80/index.html HTTP/1.1 > > Any proxy that receives such a request now knows that the server to > forward to is "www.python.org:80". It will open a connection to > www.python.org:80, and send it a GET request for the URI. > > Since you want your proxy to forward to another proxy, i.e. your proxy > is a client from your external-access-proxy's point of view, you > should also use the absoluteURI form when making requests from your > python proxy to your external proxy. Well the two minor changes you suggested worked straight away for normal HTML pages - great. It's not fetching images and a couple of other problems (possibly because that proxy server can only handle HTTP/1.0 - but I have a more advanced one called TcpWatch from Zope that I might hack around). But there's more than enough for me to go on and get it working. MANY THANKS Regards, Fuzzy http://www.voidspace.org.uk/atlantibots/pythonutils.html From rschroev_nospam_ml at fastmail.fm Thu Aug 19 18:35:53 2004 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Thu, 19 Aug 2004 22:35:53 GMT Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: Roel Schroeven wrote: > I spotted some errors in your list, added new entries, and made a > histogram: http://roelschroeven.net/pythonages/ Whoops, I had a duplicate entry. Updated: number of datapoints: 94 mean: 35.4 standard deviation: 12.6 Gerrit Muller 47 Lucas Raab 14 OKB (not okbackle) 20 Jeremy Jones 31 Ben Last 39 Neuruss 34 Tony Clarke 55 simo 26 Elbert Lev 55 Kamilche 40 Gerardo Herzig 30 JanC 30 Mike Rovner 41 Guyon Mor?e 21 Tom Brown 35 Will McGugan 30 Christopher T King 19 Skip Montanaro 50 Marcin Jurczuk 26 Reid Nichol 27 Egbert Bouwman 67 VSOFTSMITH 62 Mark Jackson 55 Harry George 52 Stephen Ferg 58 Scott David Daniels 53 Peter Wilkinson 32 oziko 24 Dave Opstad 50 Adonis 23 Jorge Godoy 25 Peter Hickman 43 Axel Steiner 22 Larry Bates 49 Robin Becker 57 Thomas Heller 48 Paul McQuire 45 wes weston 55 P at draigBrady.com 30 Ian Sparks 34 Roel Schroeven 29 Christos TZOTZIOY Georgiou 32 Gary Herron 52 Ksenia Marasanova 31 Marius Bernklev 24 Robert Boyd 40 Fred Pacquier 44 Jarek Zgoda 33 Leif K-Brooks 13 Peter Maas 48 Tim Jarman 42 Irmen de Jong 30 Ted 46 Roman Suzi 30 Dave Benjamin 25 Christian von Essen 18 Byron 28 R Baumann 55 Batista, Facundo 29 Jeff Shannon 35 Cousin Stanley 58 Berthold H?llmann 38 mensanator at aol.com 50 Ville Vainio 27 Istvan Albert 32 Andrea Griffini 38 Arthur Rambo 43 Beeyah 15 Eli Stevens (WG.c) 25 Bigbowser 15 Hemanth P.S. 32 richard 32 Marcos Eimil Pardo 28 Daniel Harding 25 Rod Haper 57 Bruno Desthuilliers 37 avaeq 19 Alexandre Fayolle 30 Andrew Durdin 24 Max M 39 Ganesan R 32 Stefan Schukat 33 Robbie 18 Marc Boeren 34 Gerrit van Dyk 39 Oliver Fromme 33 Nicolas Evrard 27 vronskij at post.sk 25 Alan Kennedy 37 Francis Lavoie 25 Richard Hanson 53 brianc at temple.edu 20 Rex 17 Wilk 35 -- "Codito ergo sum" Roel Schroeven From anthonybaxter at gmail.com Fri Aug 13 03:15:06 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 13 Aug 2004 17:15:06 +1000 Subject: @decorator syntax is sugar, but for what exactly? In-Reply-To: <898217E4-EA67-11D8-9DC2-000A9574CFD8@earthlink.net> References: <4115b53a$1@nntp0.pdx.net> <4116239e$1@news.012.net.il> <4117a43b$1@news.012.net.il> <898217E4-EA67-11D8-9DC2-000A9574CFD8@earthlink.net> Message-ID: On Mon, 9 Aug 2004 20:52:21 -0400, gohaku wrote: > In case it has not been brought up before... > > @decorator reminds me too much of Perl arrays. A number of times. And this means what? From jmeile at hotmail.com Wed Aug 11 04:02:14 2004 From: jmeile at hotmail.com (Josef Meile) Date: Wed, 11 Aug 2004 10:02:14 +0200 Subject: Python equivalent to a C trick In-Reply-To: References: <1d7b6d0d.0408092255.1177908e@posting.google.com> <4119327f$1@pfaff2.ethz.ch> Message-ID: <4119d0c0$1@pfaff2.ethz.ch> Paul McGuire wrote: > No offense taken! :) > > The OP was looking for a general solution to ? > : , then gave us the "you have n egg(s)" example. So, I guess it is like the "foo" keyword. > In the general case, the number for comparison isn't always an integer > quantity such as eggs. It could be "dollar(s)"/"euro(s)"/"Swiss > franc(s)"/"yen" (hmm, I guess "yen" isn't a problem...), or "ton(s) of > salami", or "pound(s) of cement", or "degree(s) Celsius", or... Anyway, > even though eggs are usually counted from 1 to n in integer steps, other > quantities can easily be negative and/or continuous. Still the singular - > in English, anyway - is usually used *only* when the quantity is 1. > Fractional and zero amounts, even though less than 1, still most naturally > use the plural form. > > You have 0.5 dollars > You have gained 1 pound > You increased temperature by 0 degrees > You have -2 dollars (that is, you owe 2 dollars) Good point ;-) > My point (which I guess didn't come across too well) was that this is a > typical coding and testing error, in which only positive integer values > 0 > are assumed, because we often mentally equate "plural" with "more than 1". > But whether you are working in an integer, real, positive-only, or all > numbers context, testing with n != 1 should determine whether singular noun > should be used. I like your solution and I think it even considers when n=0, while the other example fails and write "You have 0 egg" From paul at subsignal.org Sun Aug 22 17:01:11 2004 From: paul at subsignal.org (paul k) Date: Sun, 22 Aug 2004 23:01:11 +0200 Subject: python doesn't like my numbers Message-ID: <2osfspFdnjbcU1@uni-berlin.de> hi, is there any way to convince python not to take my (phone)numbers starting with zero as octals? >>> int(088) File "", line 1 int(088) ^ SyntaxError: invalid token thanks Paul From anthonybaxter at gmail.com Fri Aug 27 11:34:40 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 28 Aug 2004 01:34:40 +1000 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: [I was going to leave this thread alone now, but I need to correct another piece of misinformation before I go, in case the 3 or 4 people who've stayed with this thread get the wrong idea ] On Thu, 26 Aug 2004 16:09:42 -0400, Paul Morrow wrote: > Yes, it doesn't seem all that complex, although I'm not sure that > everyone reading this understands them and their subtleties. The > following is an excerpt from > http://docs.python.org/tut/node11.html#SECTION0011200000000000000000 > > "A namespace is a mapping from names to objects. Most namespaces are > currently implemented as Python dictionaries, but that's normally not > noticeable in any way (except for performance), and it may change in the > future. Examples of namespaces are: the set of built-in names (functions > such as abs(), and built-in exception names); the global names in a > module; and the local names in a function invocation. In a sense the set > of attributes of an object also form a namespace." > When I talk about namespaces, I include all of the above, including the > sense mentioned in the last line. So an object's attributes constitute > a namespace too. Therefore __doc__, being an attribute of the function > object, is in the function object's /namespace/. And note that this is > *not* a new namespace; it's been there all along. "In a sense" is the bit you're missing here. You can't just hand-wave and say that it's a namespace. It's *not* a namespace. If it was, you could do any of these: >>> def foo(): ... "a docstring" ... >>> >>> eval('__doc__', foo) Traceback (most recent call last): File "", line 1, in ? TypeError: globals must be a dict >>> eval('__doc__', globals(), foo) Traceback (most recent call last): File "", line 1, in ? TypeError: locals must be a mapping >>> exec '__doc__ = __doc__ + "extra"' in foo Traceback (most recent call last): File "", line 1, in ? TypeError: exec: arg 2 must be a dictionary or None Note that if I use a real dict, I get the correct result: >>> d=dict(__doc__ = 'docstring') >>> exec '__doc__ = __doc__ + "extra"' in d >>> d['__doc__'] 'docstringextra' If and when you can make the above work, then come back and re-visit your idea. Better yet, play around a bit and figure out _why_ they don't work - it's a good learning exercise. Anthony From c0dec at gmx.de Wed Aug 25 11:44:47 2004 From: c0dec at gmx.de (Henning Kage) Date: Wed, 25 Aug 2004 17:44:47 +0200 Subject: Compiling a custom python library Message-ID: I'm writing a small Python library with some generic classes and interfaces, that can be used within other Python projects in our company. Would it be a better solution to compile this library into a Python DLL (and if so, how can it be done) or to distribute the "raw" sourcecode of these classes etc.? What would be the best solution, so that other programmers can easily integrate this library into their own programs? From eric_brunel at despammed.com Tue Aug 31 09:50:47 2004 From: eric_brunel at despammed.com (Eric Brunel) Date: Tue, 31 Aug 2004 15:50:47 +0200 Subject: has_method (solution found) References: <41347BC1.5020407@geochemsource.com> Message-ID: Gandalf wrote: > > Somebody sent me a private e-mail. > It must be common for such silly questions that would just spam the > list. :-) > I'll write down the final solution anyway. > > > def getmethod(name): > methodList = [e for e in dir(self) if callable(getattr(self, e))] > if name in methodList: > return getattr(self,name) > else: > return None And why not: def getmethod(obj, name): meth = getattr(obj, name) if callable(meth): return meth else: return None ??? Why do you use a list comprehension to get the names of all methods on the object? In addition, it won't work for class instances: >>> class C: ... def m(self): ... print 'spam' ... >>> >>> o = C() >>> dir(o) [] But: >>> getattr(o, 'm') HTH -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From fuzzyman at gmail.com Wed Aug 11 11:19:25 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 11 Aug 2004 08:19:25 -0700 Subject: .idlerec Message-ID: <6f402501.0408110719.4995fe12@posting.google.com> What environment variable does Python use to determine where to say .idelrec on windows XP ? Fuzzy http://www.voidspace.org.uk/atlantibots/pythonutils.html From mauriceling at acm.org Tue Aug 3 20:01:25 2004 From: mauriceling at acm.org (Maurice LING) Date: Wed, 04 Aug 2004 00:01:25 GMT Subject: Call for Grant Proposals In-Reply-To: References: <40fcaa90$0$27091$9b622d9e@news.freenet.de> <410ED411.7090907@acm.org> <410ef314$1@news.unimelb.edu.au> Message-ID: <41102750$1@news.unimelb.edu.au> Thank you for you help. Please see inserts below. Aahz wrote: > Speaking as a PSF member who is or has been on some of the operating > committees, but not a member of the PSF board or the grant committee: > > In article <410ef314$1 at news.unimelb.edu.au>, > Maurice LING wrote: > >>2. Will there be any form of intellectual property claims, including, >>copyrights, trade marks, patents, on any form of work generated from the >>PSF Grant by the Python Software Foundation (PSF) or any of its >>associates? If so, what are the precise nature of it? This is important >>as it may injure the research work and subsequently, the resultant >>thesis and publications directing towards the award of my degree. > > > There will be no claims by the PSF itself unless you assign your work; > that follows more-or-less from choosing projects that are are Open > Source. Thanks. Quite obviously I cannot do something that will not count towards my degree at this stage. > > >>3. On the website (http://www.python.org/psf/call-2004.html), it is >>stated that the project of which the grant is granted for must be >>completed by October 30, 2005. In event of failure to meet, what will be >>the penalities? >> >>4. From Question 3, what constitutes partial failure or complete failure >>of the project? > > > We don't know. We're feeling our way into this. I suspect people would > rather take a wait-and-see attitude until we actually have to deal with > these issues. > This is by itself a tricky issue. But as with all projects, a majority of them don't end up as expected, otherwise, the world would have stop our dependency on fossil fuels years ago. Is there any general guidelines yet? > >>5. From Question 4, it is stated on the website >>(http://www.python.org/psf/call-2004.html) that a delivery plan is >>essential in the proposal. How will delay in delivery affect the payment >>plan and the grant on the whole? > > > We're talking about US$40K in grants total; I expect that grants will > simply be issued up-front for the most part. (The PSF's total monetary > resources right now are around US$115K.) I'd expect that if a grant > proposal ties payments to delivery targets, the penalty for missing > delivery will be delay of the next grant payment. > > We're putting a certain amount of formalism into this because we have > to; however, you'll be much better off if you think of this as "Python > community money" that's being spread around to grease projects that are > having trouble getting traction. There are basically two and only two > criteria that really matter: > > * Will this project benefit a large portion of the Python community? > > * Will giving money to this project move it forward? > > Instead of asking general questions like this, why don't you simply tell > us what your proposal is, and we'll help you refine it before you send > it in to the grant committee? I do wish I can put down my proposal now but I'm unable to do so due to NDAs. Especially when this forum is public. That is why I can only state my problems very generally and the only time I can disclose it in entirety is in the proposal itself. Thanks for your help. Cheers Maurice -- Maurice Han Tong LING, BSc(Hons)(Biochem), AdvDipComp, SN From paolo.veronelli at yahoo.it Thu Aug 26 12:24:02 2004 From: paolo.veronelli at yahoo.it (Paolo Veronelli) Date: Thu, 26 Aug 2004 18:24:02 +0200 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: <412E0EA2.7090703@yahoo.it> Anthony Baxter wrote: > On Thu, 26 Aug 2004 10:28:14 +0200, Paolo Veronelli > wrote: > >>It's not the ideas complexity that fears,but the feeling we are trying >>to bring down to earth the supposed magic of some language solutions. >>There is nothing good in magic,specially when you have to build robust >>things on it. > > > I have no idea what you're trying to say here. Are you saying that the > approach of double-under variables inside a function having some new > meaning, getting put into a new scope that did not previously exist, > is somehow _less_ magical that the syntactic sugar of decorators? I would like to erase magic from code and have some kind of specification for the double-under variables. if __metaclass__ is not a keyword I suppose it's a reference but.....this is not enough:assigning it is a meta-coding action. So let's classify these actions and see what kind of meta-coding decorators are . This should be done before the creation of a new syntax,a good syntax for all meta-coding. > so, how do you intend to handle the backwards compatibility issue, > where code that works on Python2.4 will do something entirely > different on Python2.3 (the double-under variables will be silently > ignored). This is not a problem for me.If it's the case I don't really care of zoombies,I'm a researcher not a politician, I'm trying to develope a thought around a pragmatic good language,and possibly evolve my knowledge of it. Next generation will measure better our efforts. > Do you intend that the double-under names would also be > looked for in the same scopes? That is, what will this code do? > > def foo(): > __name__ = '%s_banana'%(__name__) > Has it anything to do with our talking?Sharp features are sharp.If somebody want to obfuscate code he can do it,he is free of playing this game. >>If this blows away clouds on the language future and bring back the >>useful features in a wider theory where metaclasses and decorators are >>members of,this shouldn't be considered a hack.If it becomes a hack the >>problem is to be searched and solved above generalizing the scope system. > > > Hand waving is all well and good, but this isn't a matter of > "generalizing the scope system". This is a _radical_ change to the > scoping rules of Python, and I think it's safe to say that there's > *absolutely* *no* *way* something like this would be considered, > without an excellent reason - and bolting some sort of strange > decorator semantics doesn't cut it. We can use decorators issue to see how python successors will kill it in the long term or how the python will be after changing skin. In my enfant views knowledge is fractal and a the three scoping rules is hiding patterns which will be seen with the right lens. Possibly we can learn form other languages approches to the same problems but no way I matter to be considered from the higher spheres,I am a farmer taking some notes on how the plant is growing. Paolino From spam_me_gently_with_a_chainsaw at yahoo.com Mon Aug 2 11:20:49 2004 From: spam_me_gently_with_a_chainsaw at yahoo.com (Double Dumbass on You) Date: Mon, 2 Aug 2004 08:20:49 -0700 Subject: Trimming a string Message-ID: <10gsmuieo65du5d@news.supernews.com> I have a string that is 7 characters and represents file mode in UNIX/LINUX from rpm: 0100755 I don't care about the 0100 portion, I am only interested in the file permissions portion which is 755. How can I get three characters from the string starting at the right? ( -OR- strip 4 characters from the left? ) From 510046470588-0001 at t-online.de Thu Aug 19 03:21:08 2004 From: 510046470588-0001 at t-online.de (510046470588-0001 at t-online.de) Date: 19 Aug 2004 09:21:08 +0200 Subject: Embedding Python in Python References: Message-ID: <873c2j8ufv.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Robey Holderith writes: > Anyone know a good way to embed python within python? > > Now before you tell me that's silly, let me explain > what I'd like to do. > > I'd like to allow user-defined scriptable objects. I'd > like to give them access to modify pieces of my classes. > I'd like to disallow access to pretty much the rest of > the modules. > > Any ideas/examples? use the rexec module, or see how Zope does it Klaus Schilling From martin at v.loewis.de Fri Aug 6 15:15:43 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 06 Aug 2004 21:15:43 +0200 Subject: PEP 263 status check In-Reply-To: <10h724r20kkeqb2@news.supernews.com> References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> <10h5hgvpafm8a64@news.supernews.com> <41133C76.8040302@v.loewis.de> <10h6rklt3fa1690@news.supernews.com> <41137799.70808@v.loewis.de> <10h724r20kkeqb2@news.supernews.com> Message-ID: <4113D8DF.8080106@v.loewis.de> John Roth wrote: >>What would you expect instead? Do you think your expectation >>is implementable? > > > I'd expect that the compiler would reject anything that > wasn't either in the 7-bit ascii subset, or else defined > with a hex escape. Are we still talking about PEP 263 here? If the entire source code has to be in the 7-bit ASCII subset, then what is the point of encoding declarations? If you were suggesting that anything except Unicode literals should be in the 7-bit ASCII subset, then this is still unacceptable: Comments should also be allowed to contain non-ASCII characters, don't you agree? If you think that only Unicode literals and comments should be allowed to contain non-ASCII, I disagree: At some point, I'd like to propose support for non-ASCII in identifiers. This would allow people to make identifiers that represent words from their native language, which is helpful for people who don't speak English well. If you think that only Unicod literals, comments, and identifiers should be allowed non-ASCII: perhaps, but this is out of scope of PEP 263, which *only* introduces encoding declarations, and explains what they mean for all current constructs. > The reason for this is simply that wanting to put characters > outside of the 7-bit ascii subset into a byte character string > isn't portable. Define "is portable". With an encoding declaration, I can move the source code from one machine to another, open it in an editor, and have it display correctly. This was not portable without encoding declarations (likewise for comments); with PEP 263, such source code became portable. Also, the run-time behaviour is fully predictable (which it even was without PEP 263): At run-time, the string will have exactly the same bytes that it does in the .py file. This is fully portable. > It just pushes the need for a character set > (encoding) declaration down one level of recursion. It depends on the program. E.g. if the program was to generate HTML files with an explicit HTTP-Equiv charset=iso-8859-1, then the resulting program is absolutely, 100% portable. For messages directly output to a terminal, portability might not be important. > There's already a way of doing this: use a unicode string, > so it's not like we need two ways of doing it. Using a Unicode string might not work, because a library might crash when confronted with a Unicode string. You are proposing to break existing applications for no good reason, and with no simple fix. > Now I will grant you that there is a need for representing > the utf-8 encoding in a character string, but do we need > to support that in the source text when it's much more > likely that it's a programming mistake? But it isn't! People do put KOI-8R into source code, into string literals, and it works perfectly fine for them. There is no reason to arbitrarily break their code. > As far as implementation goes, it should have been done > at the beginning. Prior to 2.3, there was no way of writing > a program using the utf-8 encoding (I think - I might be > wrong on that) You are wrong. You were always able to put UTF-8 into byte strings, even at a time where UTF-8 was not yet an RFC (say, in Python 1.1). > so there were no programs out there that > put non-ascii subset characters into byte strings. That is just not true. If it were true, there would be no need to introduce a grace period in the PEP. However, *many* scripts in the world use non-ASCII in string literals; it was always possible (although the documentation was wishy-washy on what it actually meant). > Today it's one more forward migration hurdle to jump over. > I don't think it's a particularly large one, but I don't have > any real world data at hand. Trust me: the outcry for banning non-ASCII from string literals would be, by far, louder than the one for a proposed syntax on decorators. That would break many production systems, CGI scripts would suddenly stop working, GUIs would crash, etc. Regards, Martin From alanmk at hotmail.com Sat Aug 21 11:30:30 2004 From: alanmk at hotmail.com (Alan Kennedy) Date: Sat, 21 Aug 2004 16:30:30 +0100 Subject: file access in jythonc In-Reply-To: <9eabe547.0408210611.d5e54f7@posting.google.com> References: <9eabe547.0408210611.d5e54f7@posting.google.com> Message-ID: [John Howard] > I have the following in a jythonc program to be executed in a html > file. > > f1 = open("filename","r") > > I get message about filePermission read error. Program compiles and > jar file is created. Just the html code gives message. > > Any ideas? I am presuming that when you say "executed in a html file" you mean that this code is to be embedded in a rendered html page as displayed in a browser, such as mozilla or ie, which means that your code is an "applet", and thus allowed to execute only in the "applet sandbox" inside that browser. Which significantly restricts the access rights of the applet to access system resources such as local files, for a range of very good security reasons, described here http://java.sun.com/docs/books/tutorial/applet/overview/security.html http://java.sun.com/docs/books/tutorial/security1.2/overview/ You can approach the problem by 1. Digitally signing your applet or jar file. http://www.jguru.com/faq/view.jsp?EID=11475 2. Configuring the your browser to permit file access to local files (potentially opening a massive security hole in your browser). http://www.developer.com/java/ent/article.php/630621 HTH, -- alan kennedy ------------------------------------------------------ email alan: http://xhaus.com/contact/alan From ressler at cheetah.jpl.nasa.gov Wed Aug 4 19:21:37 2004 From: ressler at cheetah.jpl.nasa.gov (Michael Ressler) Date: 4 Aug 2004 23:21:37 GMT Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) References: Message-ID: On 2004-08-04, Delaney, Timothy C (Timothy) wrote: > Christopher T King wrote: > >> On 4 Aug 2004, Nick Vargish wrote: >> >>> I just don't know where else to voice my opinion on this matter, but >>> I absolutely hate the new decorator syntax. > > @classmethod > def func (args): > @attr = 1 > pass I'm just a dumb user of Python - I don't even program for a living, so there is no reason any of you should listen to me, but this @-syntax thing makes Python look like Perl. The reason I learned Python was that Perl looks like line noise to me, and I wanted a scripting language I could read. Please don't wreck a beautiful, readable language with this shortcut. Choose a word for it, not a symbol, please. Mike From fuzzyman at gmail.com Thu Aug 12 03:01:30 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 12 Aug 2004 00:01:30 -0700 Subject: .idlerec References: <6f402501.0408110719.4995fe12@posting.google.com> Message-ID: <6f402501.0408112239.4c68234a@posting.google.com> fuzzyman at gmail.com (Michael Foord) wrote in message news:<6f402501.0408110719.4995fe12 at posting.google.com>... > What environment variable does Python use to determine where to say > .idelrec on windows XP ? > > Fuzzy > > http://www.voidspace.org.uk/atlantibots/pythonutils.html Oops.. that should be 'save' .idlerec (the directory). I have two XP machines. One saves it in my 'documents and settings' folder (where I want it) and the other saves it wherever it damn well feels like........ Regards, Fuzzy http://www.voidspace.org.uk/atlantibots/pythonutils.html From peter at engcorp.com Wed Aug 4 08:05:16 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 04 Aug 2004 08:05:16 -0400 Subject: Crypto.PublicKey.RSA.error: Plaintext too large In-Reply-To: References: Message-ID: Ajay Brar wrote: > the documentation says verify should return true or false. it will > generate an error if plaintext is too large - which is not helping me much > i have pinned the problem down to the signature itself and the way i am > downloading it. > what i do is when a user clicks on a signature link, i calculate the > signature on the fly and then do > print "Content-type: application\n" > print signature > i am using content-type application to force explorer to give the > download dalog box (the application i am building will later be ported > to a pocket pc). Microsoft on their website said to put the header > "Content-disposition: attachment;filename=blah" to force dowload, but > that didn't work - i am yet to find out what i am doing wrong? > so any ideas on how i send the signature across and make the user > download it? Internet Explorer is, of course, broken. The only guaranteed solution of which I'm aware to the problem that it sounds like you are describing (IE refusing to download a file in the right way or to save it as right type) is to set the file extension to something that it recognizes as requiring a download. For example, if you use a file extension of .txt on something, it will generally not try to download it automatically. Same for other things that it recognizes. Setting the extension to .exe would presumably force the same behaviour as using content type "application". Leaving the extension off might also work, though I haven't tried that. Or I might be interpreting what you are saying incorrectly. -Peter From lbates at swamisoft.com Wed Aug 11 09:26:56 2004 From: lbates at swamisoft.com (Larry Bates) Date: Wed, 11 Aug 2004 08:26:56 -0500 Subject: loading message thingy References: Message-ID: Hope this code might help or at least point you in the correct direction. Regards, Larry Bates Syscon, Inc. Title: Console (text) progress indicator class Description: I was finding that I needed a progress indicator for Linux and Windows console applications that could be used to show the user that work was progressing and how much of the total work that had been completed. I finally broke down and wrote this class that seems to do exactly what I wanted. Since I continue to see questions about how to write such a class on Comp.Lang.Python, I thought I'd donate it to this Cookbook archive. Source: Note: Your final code will have syntax highlighting # CLASS NAME: DLLInterface # # Author: Larry Bates (lbates at syscononline.com) # # Written: 12/09/2002 # # Released under: GNU GENERAL PUBLIC LICENSE # # class progressbarClass: def __init__(self, finalcount, progresschar=None): import sys self.finalcount=finalcount self.blockcount=0 # # See if caller passed me a character to use on the # progress bar (like "*"). If not use the block # character that makes it look like a real progress # bar. # if not progresschar: self.block=chr(178) else: self.block=progresschar # # Get pointer to sys.stdout so I can use the write/flush # methods to display the progress bar. # self.f=sys.stdout # # If the final count is zero, don't start the progress gauge # if not self.finalcount : return self.f.write('\n------------------ % Progress -------------------1\n') self.f.write(' 1 2 3 4 5 6 7 8 9 0\n') self.f.write('----0----0----0----0----0----0----0----0----0----0\n') return def progress(self, count): # # Make sure I don't try to go off the end (e.g. >100%) # count=min(count, self.finalcount) # # If finalcount is zero, I'm done # if self.finalcount: percentcomplete=int(round(100*count/self.finalcount)) if percentcomplete < 1: percentcomplete=1 else: percentcomplete=100 #print "percentcomplete=",percentcomplete blockcount=int(percentcomplete/2) #print "blockcount=",blockcount if blockcount > self.blockcount: for i in range(self.blockcount,blockcount): self.f.write(self.block) self.f.flush() if percentcomplete == 100: self.f.write("\n") self.blockcount=blockcount return if __name__ == "__main__": from time import sleep pb=progressbarClass(8,"*") count=0 while count<9: count+=1 pb.progress(count) sleep(0.2) pb=progressbarClass(100) pb.progress(20) sleep(0.2) pb.progress(47) sleep(0.2) pb.progress(90) sleep(0.2) pb.progress(100) print "testing 1:" pb=progressbarClass(1) pb.progress(1) Discussion: Programs that run (FTP downloads, database insertions, etc.) sometimes require visual feedback to the user as to the progress of the task that is running. This progress bar class provides an easy to implement way of showing the percentage of completion that is updated periodically by the program. "Robbie" wrote in message news:cfcndl$28em$1 at otis.netspace.net.au... > Even though this is not very important it would be nice to get working. > > Basically all I want to do is continuously write to the same line. > So I could have a little rotating text thing showing that the script is > working or display data ie, kb downloaded so far... > > ATM I am just calling a clear screen every pass with a little nap, nasty. > > Something along these lines: > for i in range(1000): > print "Loading... %s" % file_size > os.system("clear") > sleep(0.5) > I also tried something with \r but that never quite worked... > Also it would be nice to be able to change more than one line so I could > have 4 threads open downloading something with 4 lines each stating the > current status of each thread... > From artur_spruce at yahoo.com Thu Aug 5 07:10:08 2004 From: artur_spruce at yahoo.com (AdSR) Date: 5 Aug 2004 04:10:08 -0700 Subject: Decorator syntax References: <38ednYT1NLz1P4zcRVn-uA@powergate.ca> Message-ID: "Paul McGuire" wrote in message news:... > "Peter Hansen" wrote in message > news:38ednYT1NLz1P4zcRVn-uA at powergate.ca... > > > For the record, the @ syntax is despicable and horribly > > un-Pythonic, IMHO, and I really hope never to read code that > > uses it. :-( > > > > (And my preferred syntax was "def f() [classmethod]:", FWIW) > > > > Agreed. And I also like your preferred syntax - clear, readable, no > eye-jarring symbols. That's what I think too. If there has to be a decorator syntax (other than present "f = decor(f)" rebinding, which makes the process of decorating as explicit as it gets), that's the one to go. Effbot's expression of horror at the @ syntax was no surprise to me, although sudden appearance of the latter was. I read somewhere that the BDFL allowed this patch because he was tired with the long, never-ending discussion. I have this conspiracy theory that he did so to stirr the community and finally get some clear response on what's best. Which might be a risky but good move. Which made me think: I'd rather know when I'm losing perspective (and be able to remedy that) than just try not to lose it. AdSR From gilles.lenfant at nospam.com Fri Aug 20 14:41:16 2004 From: gilles.lenfant at nospam.com (Gilles Lenfant) Date: Fri, 20 Aug 2004 20:41:16 +0200 Subject: python cgi speedup on iis In-Reply-To: References: Message-ID: <412648fc$0$18622$626a14ce@news.free.fr> Charlie Taylor a ?crit : > I'm looking for advice on how to speed up python cgi on Windows IIS without > going to an application server like Zope/WebWare/CherryPy/etc (i.e. I have > existing cgi scripts). > > mod_python seems like a good solution for Apache, is there something > comparable for IIS? > > I notice that ASP scripts run an asp.dll which I believe becomes memory > resident to speed up VBScript execution. > > Is there any work on a python.dll anywhere? > > Thanks, > ct > Use the excellent pywin32 http://sourceforge.net/projects/pywin32 Look at the help in the "ASP and Python" section that shows how to register Python as ASP engine. You can the build ASP pages like this... <%@ language =Python%> <%Response.Redirect("test.html")%> From martin at v.loewis.de Fri Aug 6 16:17:25 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 06 Aug 2004 22:17:25 +0200 Subject: Proposal: require 7-bit source str's In-Reply-To: References: <4112AC7B.1060508@v.loewis.de> <411343D7.3020604@v.loewis.de> <411353A3.8090502@v.loewis.de> <4113759E.2070405@v.loewis.de> Message-ID: <4113E755.8060205@v.loewis.de> Hallvard B Furuseth wrote: > That sounds like it could have a severe performance impact. However, > maybe the compiler can set a flag if there are any such strings when it > converts parsed strings from Unicode back to the file's encoding. Yes. Unfortunately, line information is gone by that time, so you can't point to the place of the error anymore. > I can't say I like the idea, though. It assumes Python retains the > internal implementations of 'coding:' which is described in PEP 263: > Convert the source code to Unicode, then convert string literals back > to the source character set. It's a pretty safe assumption, though. It is the only reasonable implementation strategy. >>Notice that your approach only works for languages with single-byte >>character sets anyway. Many multi-byte character sets use only >>bytes < 128, and still they should get the warning you want to produce. > > > They will. That's why I specified to do this after conversion to > Unicode. But I notice my spec was unclear about that point. Ah, ok. > None of this properly addresses encodings that are not ASCII supersets > (or subsets), like EBCDIC. Both Python and many Python programs seem to > make the assumption that the character set is ASCII-based, so plain > strings (with type str) can be output without conversion, while Unicode > strings must be converted to the output device's character set. Yes, Python assumes ASCII. There are is some code for EBCDIC support, but on those platforms, Unicode is not supported. > Sure. I wasn't protesting against people using of escape sequences. > I was protesting against requiring that people use them. But isn't that the idea of the str7bit feature? How else would you put non-ASCII bytes into a string literal while simultaneously turning on the 7-bit feature? Regards, Martin From evandro at async.com.br Thu Aug 26 10:12:02 2004 From: evandro at async.com.br (Evandro Vale Miquelito) Date: Thu, 26 Aug 2004 11:12:02 -0300 (BRST) Subject: age of Python programmers In-Reply-To: <411e4639.0408250735.2fff48bd@posting.google.com> Message-ID: I'm 23. ****************************** * Evandro Vale Miquelito * * evandro at async.com.br * ****************************** On 25 Aug 2004, Brian Almond wrote: > "Lucas Raab" wrote in message news:... > > One thing I've always kind of wondered is what is the average age of a > > Python programmer?? > > 31 here. I started experimenting with code when I was pretty young. > Started out on my father's IMSAI 8080 (which moved into my room when > we got our first IBM PC :). Python got my attention around the time > the DDJ issue came out with Guido & Larry Wall on the cover. > -- > http://mail.python.org/mailman/listinfo/python-list > From M.Waack at gmx.de Mon Aug 16 16:13:37 2004 From: M.Waack at gmx.de (Mathias Waack) Date: Mon, 16 Aug 2004 22:13:37 +0200 Subject: Simple exceptions question References: Message-ID: Nick Jacobson wrote: > Say I have a function foo that throws an IndexError exception, and > I want to handle it: > > def foo(a, b, c): > print a[10], b[10], c[10] #, etc. > > def main(): > #define vars > try: > foo(a, b, c) > except IndexError: > print "Accessed array ", x, " out of bounds!" #??? > > When the exception is thrown, I don't know what triggered it! a, > b, or c? There is IMHO no (at least no obvious) way to find it out. The "print" is a single statement - an atom from the point of view of the python interpreter. Its easy to find out, which statement caused the exception. But its impossible to find out which "part" of one single statement caused an exception. And btw what value should "x" have? An object in python has no name. > I could put a series of if statements in the except clause, but > that > defeats the whole purpose of having the exception, right? Is there > a better way? Yes: create your own list class (maybe by inheriting list). Give each instance an unique name. Use a setitem method like this: class seq(list): # some code suppressed... def __getitem__(self,index): try: list.__getitem__(self,index) except IndexError,e: e.index = index e.name = self.name raise e Thus you can write the except clause as: except IndexError, e: print "Accessed?array?", e.name, "?out?of?bounds at", e.index Mathias From stefan at eischet.com Fri Aug 13 12:32:45 2004 From: stefan at eischet.com (Stefan Eischet) Date: Fri, 13 Aug 2004 18:32:45 +0200 Subject: [OT] Keyboard layout, was Re: PEP318 In-Reply-To: References: Message-ID: <67C5E9C3-ED46-11D8-899A-000A95857E5C@eischet.com> On 13.08.2004, at 13:39, Michael Hudson wrote: > Sion Arrowsmith writes: > >> Roy Smith wrote: >>> Sion Arrowsmith wrote: >>>> As someone who's just started using a Mac for the first time(*), >>>> I'd like to add that it's not always plain-sailing on an English >>>> keyboard. >>> What's wrong with Mac keyboards? >> >> No @, hence tangential relevance to PEP318 (and a point against >> pies, before or after the def). Unless you can remember it's on >> option-3. > > Huh? On *my* mac @ is shift-2 and # is option-3. And I live > with the latter, and I type it far more often than anyone is ever > going to type @ for decorators... My german iBook uses ALT-L for @, which by itself is not a very big problem. But as an added bonus, the german PC keyboard puts @ at ALTGR+Q (right alt key), which directly translates into APPLE-Q. You know, like in "Quit". Common exclamation: "I just want to type an email address. Where is the program gone?!" (This means that if I use my usual PC-worker's keypress to type @, it should kill IDLE. Considering how I like the decorator syntax, this might actually be a feature... ;-) ) // stefan at eischet.com // From pm_mon at yahoo.com Sat Aug 14 08:15:43 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sat, 14 Aug 2004 08:15:43 -0400 Subject: AntiDecorator metaclass In-Reply-To: <411dfe05$0$6142$626a14ce@news.free.fr> References: <411dfe05$0$6142$626a14ce@news.free.fr> Message-ID: Christophe Cavalaria wrote: > Paul Morrow wrote: > > >>One of the beautiful things about Python is its clear, minimal syntax. >>So we must resist adding new syntax to the language, especially where >>there is a reasonable alternative. >> >>I believe that Stefen Eischet's suggestion for automatically determining >>a method's type (class/instance/static) from the name of its first >>formal parameter is a reasonable alternative to any/all of the decorator >>syntax proposals. > > > Here is another one that forgot that decorators aren't limited to > classmethod and staticmethod. Therefore, that proposal alone isn't an > alternative to any other syntax. > > If you want to say that decorators should be limited to classmethod and > staticmethod, say it and give us a good reason, a very very good reason. No I don't want to say that. I want to say that decorators should keep their nose out of the classmethod/staticmethod business. There's a perfectly good *no-extra-syntax-required* way to do that, thru the leveraging of conventions that most developers use already (give or take the spelling of the class parameter). The code remains readable, intuitive, obvious, unintimidating. And it makes the problem space that decorators address smaller (as it becomes everything you want decorators to do minus the classmethod/staticmethod stuff), which might give rise to a better, less objectionable solution. From zanesdad at bellsouth.net Wed Aug 25 12:24:01 2004 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Wed, 25 Aug 2004 12:24:01 -0400 Subject: Regular Expressions In-Reply-To: <808f000f.0408250802.8c303ea@posting.google.com> References: <808f000f.0408250802.8c303ea@posting.google.com> Message-ID: <412CBD21.90306@bellsouth.net> Oriana wrote: >hi! > > I've been working with Python for about two months now but I just >started learning about regular expressions. > My question is the following. I have a source file that contains >code and comments. A piece of the comments contains a revision history >that I would like to erase completely from the file since I never >update it and I don't use it anymore. The file looks something like > >/**************************************** >* Some info >* >* More info >* >*---------------------------------------- >* >* Revision History: >* >* blah >* blah >* blah >* >*---------------------------------------- > > >I would like to write some sort of regular expression to replace all >the text from the first dotted line up to the first asterisk that it's >followed either by another asterisk or by another *---- >line.....please help, I don't know where to start!!! > > On this particular problem, you might be better served to not use regexes to match the whole thing. The way that I would go about it (this is obviously not the only answer, but it'll work) is to read in the file line by line and rely on state variables to let you know when to write out and when not to write out your current line. This is kinda sketchy, but you get the idea. HTH Jeremy From Moiz.Golawala at ge.com Tue Aug 17 14:43:01 2004 From: Moiz.Golawala at ge.com (Golawala, Moiz M (GE Infrastructure)) Date: Tue, 17 Aug 2004 13:43:01 -0500 Subject: is it possible to create an object by its name in the run time Message-ID: <4BF8D93CF6F73F4890EB6ED8009ECE191C5D03@FTWMLVEM01.e2k.ad.ge.com> to find all builtins try dir(__builtins__) to get all functions in the modules try dir(moduleName) to get all the modules that you imported just type dir() to get all the methods in the class type dir(className) hope this helps. Moiz Golawala GE Infrastructure, Security Software Engineer Enterprise Solutions T 561 994 5972 F 561 994 6572 E moiz.golawala at ge.com www.gesecurity.com 791 Park of Commerce Blvd., Suite 100 Boca Raton, FL, 33487, U.S.A. GE Security, Inc. -----Original Message----- From: python-list-bounces+moiz.golawala=ge.com at python.org [mailto:python-list-bounces+moiz.golawala=ge.com at python.org]On Behalf Of Yang Zhang Sent: Tuesday, August 17, 2004 2:38 PM To: python-list at python.org Subject: is it possible to create an object by its name in the run time Hi all, I wonder if it is possible to create an object of func, class or method in the run time by it's name? To make it more clear, let me show you an example: I parsed the python code and found a function with name 'len'. I want to know if it is a build-in func(where can I look up?). If so, ignore it otherwise I want to find out which module is it defined in. All I know is the name (which is a string), and all the modules that this program have imported. In the same way, I also need to process the class and methods call. I wonder if it is possible? I will appreciate your help very much!! -Ryan -- http://mail.python.org/mailman/listinfo/python-list From pm_mon at yahoo.com Mon Aug 16 13:17:42 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Mon, 16 Aug 2004 13:17:42 -0400 Subject: Decorators: an outsider's perspective In-Reply-To: References: <20040814153534.8AC171E4007@bag.python.org> Message-ID: Anthony Baxter wrote: > On Mon, 16 Aug 2004 06:20:18 -0400, Paul Morrow wrote: > >>>Python currently doesn't _care_ about the argument list, and the variable >>>names in it. >>> >> >>One thought is, to preserve backwards compatability, this special >>behavior would only be invoked for subclasses of the new Object class. > > > How is this backwards compatible? If you'd introduced it at the same time > as object, _maybe_ you could argue that. But this isn't the case here. > > It's backwards compatible in the sense that existing code doesn't break, as it isn't derived from the new Object class (capital 'O') that enforces the conventions. >>>Adding this sort of behaviour is nasty. How, for instance, would you handle >>>adding a method to a class at runtime? Do you poke into the newly added >>>method to make sure you get it right? Do you not do this? >> >>Same rules apply. The Python system would dynamically determine the >>method's type when you add it (at runtime), so you'd need to make sure >>that the first parm name is correct in advance. > > > Really. And how would you implement this special casing in a way that > wasn't incredibly tricky to explain to users running across it? I'm not quite sure what you mean here. It would be easy to document the difference between static, class, and instance methods, and how to declare each. "To declare an instance method, use 'self' as the first param", etc... > One of the > great things about Python is that if you need to, or you want to, you can > poke into the innards of the OO system and see how it works (particularly > since descriptors were added). This adds Perl-like levels of OO-hackery. > If that comment is unclear, I mean that when you poke into Perl's OO, > it becomes very clear, very quickly, that it's a hack. > I don't see what you're talking about here either. You'd still be able to see the innards. Poke away. The methods will look as though you had explicitly declared them. >>>What about for more complex decorators? Remember, staticmethod and >>>classmethod are the trivial cases that this feature addresses. How do you >>>handle the more complex ones? >> >>The point is that method type declarations are not needed, so decorators >>wouldn't be concerned with this. Take them off the list of things >>decorators can do. > > > Huh? You proposed a hack to specify class and static methods, using a > custom meta-class that pokes at the argument list of a function, and > suddenly you've removed the need for decorators for this? Well, Yes. That's right (although the metaclass I wrote isn't finished by any means, nor am I even sure that we can do everything from a metaclass). Why have another way to do it? So that we can appease the static typing folks? We don't like unnecessary static typing, remember? > Please - feel > free to use your metaclass in your own code, but don't think that this is > in any way a solution that should be considered for "mainstream" python > use. It's a hack - a neat hack and a nice example of some of the things > metaclasses can do[1], but it's not a valid "solution" for the problem that > decorators are meant to solve. Look, staticmethod and classmethod are > a tiny tiny fraction of the things that decorator will be used for. Looking > at a large amount of Python code I've got here, I can see three examples > of classmethods (all alternate constructors) and no uses of staticmethod > at all. > > Anthony > > ([1] and, I should note, one I was about to post until I saw your post ) Well good, then you shouldn't mind if we restrict decorators to those things that you do have lots of examples of. :-) Q: What if I had a metaclass that would make any method private whose name started with two underbars (by, I dunno, mangling the name somehow)? Would you consider that a hack too? ;-) From martin at v.loewis.de Mon Aug 16 01:57:34 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 16 Aug 2004 07:57:34 +0200 Subject: undefined symbol: PyUnicodeUCS4_FromUnicode In-Reply-To: References: <411c5b24$0$26992$9b622d9e@news.freenet.de> Message-ID: <41204CCE.2090700@v.loewis.de> Bill Hodges wrote: > Your dianosis is correct. > I compiled tcl to include UCS4 and > Python then compiled to UCS4 > (nm revealed the difference). Are you sure about that? Are you absolutely certain that the installed Python (/usr/local/bin/python2.3) is UCS-4? It appears to me that it is likely UCS-2. > PyQt compiled fine, However, it > still errors out the same way. > For some reason PyQt needs to be told to > include the UCS4 stuff in qt.so na d > I cannot find the key. Do you happen to have Python header files both in /usr/include and /usr/local/include? Make sure PyQt is using the ones in /usr/local/include, if you plan to use PyQt with that Python installation. Regards, Martin From insert at spam.here Thu Aug 12 18:55:12 2004 From: insert at spam.here (Doug Holton) Date: Thu, 12 Aug 2004 17:55:12 -0500 Subject: The winner of the Python Decorator Poll is... In-Reply-To: <87acx0p0st.fsf@pobox.com> References: <4edc17eb.0408112052.1bbd85b3@posting.google.com> <87acx0p0st.fsf@pobox.com> Message-ID: John J. Lee wrote: > Of course. *easily* > Er, yup. Can you try a non-troll response that involves a complete sentence? From dave at pythonapocrypha.com Fri Aug 13 10:44:14 2004 From: dave at pythonapocrypha.com (Dave Brueck) Date: Fri, 13 Aug 2004 08:44:14 -0600 Subject: Why I love python. In-Reply-To: References: Message-ID: <411CD3BE.505@pythonapocrypha.com> Nick Patavalis wrote: > On 2004-08-13, Anthony Baxter wrote: > >>I'm biased, having done a paper on this at the most recent PyCon, but >>I firmly believe that much of the "Python is too slow" arguments can be >>answered with "too slow for what?" See the pycon proceedings, but I've >>been doing VoIP in Python, complete with audio mixing, and it's been >>more than fast enough. >> > > Yes but what parts of it were done in python, and what parts were done > inside modules written in C? > > Do you believe, for example, that a web-server written in python could > outperform apache? Yes. Apache is not that fast, and web servers are often more network bound than CPU bound. > How about an H323 implementation, or a TCP/IP > stack? Or a font renderer? Or a ray-tracer? A gate-level circuit > simulator? A web-browser? A relational database? Nobody is arguing that Python is as fast as C. But being slower does not imply that Python is unsuitable for those tasks. I'd consider your list to be pretty atypical of normal development (how many TCP stacks and relational databases need to get written each year?), but even so most of the items on your above list _have_ been done in Python and have done pretty well for a number of applications. I'd wager that the vast majority of programs written have at their disposal more CPU than they need, so using more of that spare CPU power (by using a higher level language like Python) is a cost many people are ready to pay for many, many applications. Note also that all or most of those programs on your last at one time had to be partially implemented in assembly language even if the main language was C or C++, and yet that didn't make C or C++ unsuitable development languages for the task (nor did it make them only "glue languages"). The same can hold true for Python in many cases - if a small portion needs to be developed in a lower-level language you can still derive great benefit from doing the rest of the application in Python. In nearly all of the cases where I was sure I'd have to later recode a portion in C for performance, that day never arrived. For some reason additional performance is always welcome, but the lack thereof rarely ends up becoming a big deal. (And this is not just in my own projects - when other people/companies are driving the requirements they are pretty much always more interested in getting it to market and adding new features. On one project in particular I have on my todo list to go rewrite the performance "critical" core in C and it's been on my todo list for a couple of _years_ now because I'm the only one left who cares that it could be faster - everyone else is focused on feature set. And since the core is partially CPU bound its performance has more than doubled during that time due to faster CPUs - here I am sitting still and the problem is going away :) ). >>Sure, you're not going to get great performance for your numerical >>computation in Python, but luckily, we have numarray for this. >> > If numarray was written *in Python* I would be delighted. But even > with numarray, if you want to do FFT, you do it in C, not in > Python. And if FFT is not good for you and you need DCT, again in > C. And if the FFT of numarray is not sufficient (e.g. you want an > integer version with certain bit-exact properties), hmmm sory, you > have to do it in C. > > At this moment Python is an excelent *glue* language for stuff written > in low-level laguages. It is also an exelent prototyping language. It > has a long way to go before becomming a true "production" language (in > the sense outlined above). I have to disagree - we use it as our main production language for so many different things it's hard for me to sit still when it's pigeonholed as just a glue language (*especially* when a lot of our Python programs sit idle for large blocks of time waiting for e.g. the database to get done or for the network pipe to become less saturated). Maybe it all comes down to domain, but for me the cases you describe are rare and oddball enough that if a little C is needed to get the job done then it's no big deal because they make up such a tiny minority of all the problems we're solving. C/C++ are becoming less and less suitable for production use - their main remaining advantage is performance and that becomes a smaller and smaller issue each year. Everything from manual memory management to hacky, primitive data structures (even _with_ C++/STL) make them more of a liability than an asset - development in them is slow, error-prone, and therefore too expensive. For personal projects I don't have enough spare time to waste it coding in something so low-level as C, and for professional projects the raw speed is generally valued but much less so than time-to-market and cost of change so I can't justify C/C++/etc there either. 99% of the time the tradeoff for using Python comes down to this: Benefits: low cost, fast time to market, cheap addition of new features, fewer bugs Costs: use CPU cycles that were already idle anyway Score! -Dave From dth at vxs.com Fri Aug 13 08:25:18 2004 From: dth at vxs.com (Dan Thompson) Date: Fri, 13 Aug 2004 12:25:18 GMT Subject: drop into the interpreter References: Message-ID: Thank you much Ray... this is exactly what I needed. I use the shell almost exclusively and debugging through it helps with this little snippet. Hoang Do hoang at jotsite.com "Ray Buvel" wrote in message news:eh2Tc.92478$vN3.34773 at twister.rdc-kc.rr.com... > Hoang Do wrote: > > is there a facility to inspect the run-time of a python script? > > Essentially, it would execute a script to a set specific point and then drop > > into the interpreter. Something like a "Stop" or "Break"? > > This can be done fairly easily by creating a module (lets call it > interactive) with the following code in it. > ----------- > import sys,os > > def debug_exception(type, value, traceback): > # Restore redirected standard I/O > sys.stdin = sys.__stdin__ > sys.stdout = sys.__stdout__ > sys.stderr = sys.__stderr__ > > # Kick the interpreter into interactive mode and call the original > # exception handler. > os.environ['PYTHONINSPECT'] = '1' > sys.__excepthook__(type, value, traceback) > > sys.excepthook = debug_exception > ----------- > > Now if you import this module and raise an unhandled exception, you will > be in interactive mode. In other words, I think the following script > does what you are asking for. > > ----------- > import interactive > > raise RuntimeError('Interactive Mode') > ----------- > > This also has the advantage that if there are no unhandled exceptions in > your script, the script runs and terminates normally. > > Enjoy, > Ray Buvel From aleaxit at yahoo.com Tue Aug 31 12:19:33 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Tue, 31 Aug 2004 18:19:33 +0200 Subject: initializing mutable class attributes References: <1gjc8cs.sqvo1v1fhabdjN%aleaxit@yahoo.com> Message-ID: <1gje9dn.r6jpetyroi0N%aleaxit@yahoo.com> Dan Perl wrote: ... > > > redefine it in the method foo. But the initialization of attr2 is wrong > > > because all the instances of Father end up sharing the same value. > Maybe > > > that is desired sometimes, but usually it is just a bug. > > > > I disagree: good Python programmers often use mutable class attributes, > > and use them to good effect. I've done my share of Python teaching, > > consulting and mentoring, and I definitely do *not* think this usage "is > > desired sometimes but usually it is just a bug". > > My mistake. I shouldn't have made that statement. I don't really know > which case happens more often. Having said that, that is probably a mistake > that many beginners make. Okay, I have no real way of knowing that either, > but I think it's a good assumption. I may not have enough experience with beginners, I guess -- my wife, Anna, does have it, and I hope she sees this tidbit and shares that experience with us. In my limited experience with beginners, in a huge variety of programming languages and other technologies, they make every possible mistake and many that are patently impossible too; and if you try to design your technology to be foolproof, you're wasting your time, because fools are _extremely_ ingenious. I prefer simplicity and transparency over desperate attempts to safe fools from their foolishness -- the smaller, simpler and more transparent a language or other technology is, the earlier beginners cease to be beginners and stop making most of their earlier, incredible mistakes. > > > This is already awkward because there is such a difference between attr1 > and > > > attr2. > > > > One is a class attribute (which nobody forced you to have), the other is > > an instance attribute. If you want both to be instance attributes, > > initialize both in __init__ -- that's all there is to it. Don't use > > class attributes unless there's a reason for them to be class > > attributes, that seems like a good and sensible rule of thumb to me. > > I was using the class attribute as a default, "null", value for the instance > attributes. That works just fine for immutable attributes and it allows me > not to implement an __init__. Yes, because immutable attributes cannot be mutated -- only by rebinding that name will anything change, and name rebinding never affects the object that name previously referred to. But mutable attributes can be mutated, indeed that's the whole point of having them, rather than just having their names rebound to refer to other objects. I know you want some kind of automatic copy of (some?) class attributes to instance attributes, but I think you just haven't thought clearly enough about the issues involved, even something as trivial as whether the copy should be shallow or deep -- the difference will be enormous. > > > accentuated by the fact that you HAVE TO HAVE __init__ in order to > > > initialize attributes that are mutable. > > > > Making __init__ more common means people are more likely to get used to > > it, and thus makes the bug of not calling a parent class's __init__ > > rarer, not "accentuated". > > I'm leaving the rest of your reply out, but thanks for the suggestion of a > metaclass, I'll look into it. You're welcome. > After seeing a few replies (yours, Benjamin Niemann's and Peter Otten's) to > my initial posting, I think I am getting the picture that there is a > conscious decision to keep the use of __init__ the way it is and just make > people learn it and learn it early enough. That's a valid approach and I'll > accept it. OK. > I can also understand your frustration with people who are new to Python, > like me, coming from a background in other OO languages, who are not yet > comfortable with "the Python way" and feel that there is a "better way" and > who suggest changing Python. But you also have to be reallistic and accept > that there will always be people coming to Python from other languages and > that the adjustment is rather difficult in some areas. You may just say Sure! If they devoted their energy to understanding things in depth and complete detail, rather than campaigning to change something because they don't understand that something well enough yet, their adjustment would be less difficult and we'd all be happier, of course. But human nature will always make some people perceive that requiring THEM, their precious and unique SELVES!, to change (their habits, their minds, etc) is absurd, while it's obviously all the rest of the universe that has to change to accomodate their tastes and preferences (that may be a disaster for millions of existing users, but hey, none of those users is THEM, so they're obviously not very important). They don't generally phrase things that way (too politically incorrect) and more often than not they rationalize even to themselves the changes as being good for mankind, but, really, they're generally just sticking up for their existing attachments, habits, and worldviews. I'm quite prone to doing it myself unless I keep up a substantial guard against my own laziness -- so I try to avoid suggesting any changes in something complex, if I possibly can avoid that, until and unless I convince myself that I have a thorough, complete understanding of that something, of the reason for being and consequences of what I'm thinking of changing, and of the impact and consequences of what I'd like to change it into. > 'Tough!', or you may help them to make that adjustment (I think you are > doing that), or you may even accommodate them (you should at least consider > that). It frightens me to consider that Python might one day get designs decisions made, not because GvR sees them as useful in themselves and consistent with Python's overall workings, but to "accomodate" people who are not (yet) familiar with Python. Fortunately I can generally dispell the fear and calm down, but please don't ask me to consider such horrid scenarios, they can do nothing but frighten me uselessly. > No one, including you, has given me a reason WHY __init__ is implemented > this way. I am not bashing you for that, I would just still like to hear > that 'WHY'. I'm sure that this implementation has some advantages. But, > coming from a C++ and Java background, where parent default constructors are > automatically invoked (well, not always, and that is something that users > have to learn too), I find that that approach has some clear advantages. In this like in many other details, Python chooses simplicity and clarity against automatic, black-magic, "behind the scenes" approaches. "Explicit is better than implicit" is one part of the Zen of Python that speaks to this -- at a python interactive prompt do import this to read it all. The automatic invocation of default constructors when they exist, what you have to do instead to get different constructors for parent classes, etc etc, are all complications. When classes are designed to execute responsibilities it's not unusual that they can't really have a useful no-arguments constructor -- and when they don't have such a constructor, C++'s and Java's rules are nothing BUT overhead and conceptual complication. In C++ one often works around the burden of contraints on constructor calls via "two-phase constructors" -- a default constructor that does not really leave the instance in a usable state, just to bypass the darn rules you find "have some clear advantages", and then a normal member function that really does the job of initialization and has the enormous advantage that YOU decide when and with what arguments to call it, without all the darn rules in the way, explicitly. Well, in Python the constructor, __init__, is under you control in exactly this way -- less complication, more simplicity, more transparency, fewer rules to learn, and far fewer instances of the "two-phase constructor" pattern (not zero, mind you -- just 99% fewer). > > Those are my 2 cents. > > Dan > PS: Does my last name attract the wrong kind of attention from people in > this newsgroup? It's really my name, it's not fake, BTW. I don't think you need to worry about this!-) Alex From webraviteja at yahoo.com Tue Aug 17 00:46:03 2004 From: webraviteja at yahoo.com (Ravi Teja Bhupatiraju) Date: 16 Aug 2004 21:46:03 -0700 Subject: Best programming language References: <5155aad2.0408161008.40c57262@posting.google.com> Message-ID: No need for quotes either :-). Just type programming and Python is second. First is C. And I thought Python wasn't getting enough press :-). Now I have something to bash on the heads of people who say "Python? What's that?" Hoo Boy! kveretennicov at yahoo.com (Konstantin Veretennicov) wrote in message news:<5155aad2.0408161008.40c57262 at posting.google.com>... > Roman Suzi wrote in message news:... > > ;-) > > > > Just type into google > > "best programming language" > > and press (I am lucky) > > > > > > Sincerely yours, Roman Suzi > > Just type in "programming language" and look at #1 > ;-) > > - kv From donald.welch at hp.com Thu Aug 26 19:15:39 2004 From: donald.welch at hp.com (djw) Date: Thu, 26 Aug 2004 16:15:39 -0700 Subject: Call for signatories for J2 References: Message-ID: <412e704b@usenet01.boi.hp.com> For Don Welch From thomas.krueger at gmx.net Tue Aug 10 11:28:21 2004 From: thomas.krueger at gmx.net (Thomas =?ISO-8859-1?Q?Kr=FCger?=) Date: Tue, 10 Aug 2004 17:28:21 +0200 Subject: Secure storage for passwords for admin scripts? References: Message-ID: Max wrote: > I have a collection of system admin scripts (on Win 2k) that I would > like to automate the execution of. However, some of them require the > use of logins with admin rights, and would therefore prefer not to > store the IDs in the clear text of the source. If memory serves > correctly, the "compiled" .pyc files do not provide much security in > this area. > > Are there are recommended methods for supplying scripts with login > information in a secure fashion? Compiled Python scripts can be decompiled pretty easy. So they will not give any security at all. To store the password securely you can hash them with an algorithm like MD5. For authentication you also hash the entered password and compare it with the stored hash. Thomas From Scott.Daniels at Acm.Org Sun Aug 22 15:02:43 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 22 Aug 2004 12:02:43 -0700 Subject: How to sort this kind of list easily? In-Reply-To: References: Message-ID: <4128ef9d$1@nntp0.pdx.net> Ben Last wrote: >>From: Anthony Baxter, in response to BruceKL WhoH >>list.sort sorts tuples by first argument, then second &c. If you want a >>custom sort order, look at the decorate-sort-undecorate pattern. > > > Or if you want to sort only on your Id, use a lambda: > l.sort(lambda x,y: cmp(x[0],y[0])) > > To force sorting on just the nth element of the tuples, replace 0 with n in > the above. > > b > If you are using 2.4 (now in beta), you could also do: lst.sort(key=lambda element:element[1]) From beliavsky at aol.com Mon Aug 2 10:33:38 2004 From: beliavsky at aol.com (beliavsky at aol.com) Date: 2 Aug 2004 07:33:38 -0700 Subject: Microbenchmark: Summing over array of doubles References: <4d642979.0407312049.7a8aecab@posting.google.com> Message-ID: <3064b51d.0408020633.7698c3a2@posting.google.com> bulatov at engr.orst.edu (Yaroslav Bulatov) wrote in message news:<4d642979.0407312049.7a8aecab at posting.google.com>... > I made an array of 10 million floats timed how long it takes to sum > the elements, here's what I got (millis): > > gcc -O2: 21 > Python with numarray: 104 > Python with Numeric: 302 > java: 325 > gcc: 348 > Python with Psyco: 1317 > Pure Python using sum: 2312 > Pure Python: 5631 > > http://yaroslav.hopto.org/russianwiki/index.php/c-numeric-speed > > numarray takes over Numeric at about 1100 floats > > I'm doing intensive computation on arrays in Python, so if you have > suggestions on Python/C solutions that could push the envelope, please > let me know. What hardware are you using? On a 2.8 GHz Intel Pentium 4, a Fortran 95 code compiled with Compaq Visual Fortran 6.6C using the -optimize:5 option takes 40 milliseconds. Probably you could improve the speed of the C program by compiling it with the Intel C compiler. The Fortran program speed is constrained by array accesses, not the additions (which are done in hardware). A program to compute sum(xx**4) takes the same time as one to compute sum(xx). program xsum_double ! sum 1e7 doubles implicit none integer, parameter :: n = 10000000 real(kind=8) :: xx(n) real :: t1,t2,xsum call random_seed() call random_number(xx) call cpu_time(t1) xsum = sum(xx) call cpu_time(t2) print*,1000*(t2-t1),xsum end program xsum_double From peter at engcorp.com Sat Aug 7 08:32:24 2004 From: peter at engcorp.com (Peter Hansen) Date: Sat, 07 Aug 2004 08:32:24 -0400 Subject: Klingon (was Re: RELEASED Python 2.4, alpha 2) In-Reply-To: <53449fcb.0408062138.68a1c196@posting.google.com> References: <411231C8.3020308@interlink.com.au> <2-SdnZCwNs1SwI_cRVn-uQ@powergate.ca> <53449fcb.0408062138.68a1c196@posting.google.com> Message-ID: Alan Anderson wrote: > Peter Hansen wrote: > >>Yes, of course after using them for a while they will become more >>readable, but there are people who have learned to speak Klingon as >>well -- and that doesn't change the fact that Klingon is deliberately >>very difficult to learn and awkward. > > Pardon me for jumping in, but I happen to be attending a conference on > the Klingon language at the moment and I wanted to correct a > misunderstanding. Yes, Klingon is deliberately "alien", being > intentionally created to be unlike many natural languages in many > ways. But it's actually rather easy to learn, and it's only "awkward" > in a couple of minor ways (embedding comparatives in larger sentences, > for example) -- *every* language has its awkward spots. Hmm... the last time I heard, which admittedly was several years ago, there were only a couple of fluent Klingon speakers on the entire planet, though thousands had attempted to learn it. And one of those was the originator of the language. Maybe that data was incorrect, or has changed? > Were Klingon a natural language, its regularity would be exceptional. That does count for a lot. > This is just an anectodal data point that might let you know that what > is difficult and awkward from your point of view could very well be > simple and straightforward for others who don't share your > preconceptions. Perhaps as an Esperantist I have a pretty good idea of just how easy to learn a language can be. But you're right that I have preconceptions about Klingon. I'd be interested in stats on how many people really do speak it fluently now. Not to start a language war or anything... :-) -Peter From jbenson at lowell.edu Wed Aug 18 19:32:58 2004 From: jbenson at lowell.edu (Jim Benson) Date: Wed, 18 Aug 2004 16:32:58 -0700 (MST) Subject: introspection? In-Reply-To: <20040818225608.GB14005@unununium.org> Message-ID: On Wed, 18 Aug 2004, Phil Frost wrote: > >>> class C: > ... pass > >>> C().__class__.__name__ > 'C' > > That is, __class__ of an instance gives you the class object of which > it's an instance, and __name__ gives you the identifier that represents > the class. Classes also have a __module__ attribute. > Thank you Phil and Troy for pointing out that __class__.__name__ gives me the class name. How do i get the method name? i.e i could now modify my example as: class JJTest: def methodA(self): print 'ERROR: in JJTest.methodA' s1 = self.__class__.__name__ s2 = 'methodA' s = s1 + '.' + s2 print 'ERROR: in %s' s >>> from jjtest import JJTest >>> jj = JJTest() >>> jj.methodA() ERROR: in JJTest.methodA ERROR: in JJTest.methodA >>> how do i get s2? Thanks, Jim > On Wed, Aug 18, 2004 at 02:43:46PM -0700, Jim Benson wrote: > > > > newbie question here: > > > > How does one get the class and method name from within > > a method? i.e here i have obviously hardcoded the class > > and method name: > > > > class JJTest: > > > > def methodA(self): > > > > print 'ERROR: in JJTest.methodA' > > > > >>> from jjtest import JJTest > > >>> jj = JJTest() > > >>> jj.methodA() > > ERROR: in JJTest.methodA > > >>> > > > > The Java way of doing this would be something like: > > > > System.out.println("ERROR in: " + this.getClass().getName()); > > > > I suspect that there are attributes that one can use to do > > something similar in Python. > > > > If any of you Python experts would let me know how to do this in > > Python, i would appreciate it. > > > > Thanks, > > > > Jim > From nid_oizo at yahoo.com_removethe_ Fri Aug 20 03:58:10 2004 From: nid_oizo at yahoo.com_removethe_ (Nicolas Fleury) Date: Fri, 20 Aug 2004 03:58:10 -0400 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: My vote: E4, J2, K From ville at spammers.com Tue Aug 31 11:47:19 2004 From: ville at spammers.com (Ville Vainio) Date: 31 Aug 2004 18:47:19 +0300 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> <87hdqok9i6.fsf@sinken.local.csis.hku.hk> <1rfz68ely9.fsf@rovereto.ifi.uio.no> <876574k7du.fsf@sinken.local.csis.hku.hk> <1r3c28ejis.fsf@rovereto.ifi.uio.no> <1rllg0cb3m.fsf@rovereto.ifi.uio.no> <874qmovxna.fsf@sinken.local.csis.hku.hk> Message-ID: >>>>> "Antoon" == Antoon Pardon writes: Antoon> The nesting reflects the structure of the algorithm. If an Antoon> algorithm is best described by the nesting of a number of Antoon> control structures then i don't see how you are going to Antoon> remove that nesting. Functions and classes? -- Ville Vainio http://tinyurl.com/2prnb From albalmer at att.net Wed Aug 25 18:42:55 2004 From: albalmer at att.net (Alan Balmer) Date: Wed, 25 Aug 2004 15:42:55 -0700 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: On 25 Aug 2004 14:56:06 -0700, xah at xahlee.org (Xah Lee) wrote: > >Did you know that throughout history there's this thing called cult? Yes, we've heard of them. -- Al Balmer Balmer Consulting removebalmerconsultingthis at att.net From pm_mon at yahoo.com Mon Aug 23 14:40:29 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Mon, 23 Aug 2004 14:40:29 -0400 Subject: __name__ becoming read-write? In-Reply-To: References: <3b8ki0tlphodtt8ge8an274qp78ihp1i3n@4ax.com> Message-ID: Anthony Baxter wrote: > On Mon, 23 Aug 2004 17:00:39 GMT, Arthur wrote: > >>I see the point. >> >>But.. there is always a but. >> >>I'm thinking now a special sytnax item in the __form__ at the top of >>function that would: >> >>1) put one on notice that the function is to be transformed (as in >>"see below"). >> >>2) allow a name to be assigned to it, which will become the >>transform's __name__. > > > This is a bad idea - code inside the function should be executed when > the function is executed. docstrings are a special-case (because > they're not actually code), but, to be honest, this whole discussion > has made me deeply uncomfortable with where the docstrings sit at the > moment. Once 2.4 is out, I know I'll probably start using something > like: > > def doc(str): > def endoculate(func, str=str): > func.__doc__ = str > return func > > @doc('''This function frobulates the meta-whatsit''') > def frobulate(metawhatsit): > ..... > > (insert final decorator syntax as required) > No Anthony. Please don't ever write doc strings like that. Please... I don't care what kind of technical problems that solves, that's not good looking code (IMO). > Paul Morrow's idea of special magic __foo__ inside the function is > deeply magical, and not likely to make any new users running across it > any happier. "So wait, this stuff that _looks_ like code in a > function, isn't actually? what the hell?" The new syntax[1] for > decorators is at least very obvious that something _new_ is going on. > This has been one of the things I've been using as an internal filter > for various syntax proposals for decorators. It should _not_ look like > some existing valid python that "just happens" to have a new effect. > I'd also prefer that the syntax _not_ be valid python in pre-2.4, in > case code accidently gets run under an old interpreter. The decorator > usage I have planned will be very very ugly if the decorators _don't_ > get applied to the function, for whatever reason. > > [1] whether @syntax, or block-before-def New users just need to learn that __anythingThatLooksLikeThis__ is probably magical; that care should be taken anytime they mess with variables so obviously and particularly 'decorated' (sorry :-)). Of course experienced pythonistas already know that these things are special and that they (almost) never have the 'local variable' semantics they appear to have. So it's an education problem; making new users aware of the consequences of manipulating magical attributes. And yes, I've been suggesting that we do more with that syntax. That we create magical attributes (or a single magical attribute) that change the behavior of functions, just as __metaclass__ changes the behavior of classes [*]. Hey, how about a __features__ attribute? def foo(): __features__ = synchronized, memoized * When I say "just as", I don't mean to indicate that the mechanics of the transformation are the same. Paul From aahz at pythoncraft.com Sat Aug 21 23:42:32 2004 From: aahz at pythoncraft.com (Aahz) Date: 21 Aug 2004 23:42:32 -0400 Subject: backward compatibility? References: Message-ID: In article , Peter Kleiweg wrote: > >So how serious are plans to remove things from Python, like lambda and >map and reduce? I am just starting out with Python and if there is a >danger that the programs I write today won't work next year, I rather >invest my time in another language. I might try Ruby, or stick with >Perl. It's serious. OTOH, they'll stay in the language until Python 3.0 comes out, and there's nobody forcing you to upgrade. The useful lifespan of a Python version seems to be about three or four years (my company just switched from Python 1.5.2 to Python 2.2, so we'll be two full versions out of date by the end of the year). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From insert at spam.here Fri Aug 20 11:00:11 2004 From: insert at spam.here (Doug Holton) Date: Fri, 20 Aug 2004 10:00:11 -0500 Subject: voting method flawed? [Re: Alternative decorator syntax decision] In-Reply-To: References: Message-ID: Paul McGuire wrote: > I would propose a multivote survey: each poster gets 3 votes among the > lettered choices on the Wiki page above. You can use all 3 for a single > option, or split them across 2 or 3 options if you are open to more than > one. > My vote is: J2 J2 C1 I've heard of different voting methods like ranking your top choices, but I've never heard of this one. It appears that if someone is open minded about more than one option, their opinion counts *less* that someone who is doggedly determined about one particular syntax. They get three votes while you get one. That doesn't seem fair or the best way to determine a community favorite. From adurdin at gmail.com Sat Aug 28 18:34:11 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Sun, 29 Aug 2004 08:34:11 +1000 Subject: Iteration over Lists and Strings In-Reply-To: <5M4Yc.326126$a24.276550@attbi_s03> References: <1gj80xs.1cfownoqz4m9N%aleaxit@yahoo.com> <5M4Yc.326126$a24.276550@attbi_s03> Message-ID: <59e9fd3a0408281534594ca00d@mail.gmail.com> On Sat, 28 Aug 2004 19:09:53 GMT, Brent W. Hughes wrote: > > Did you say enumerate(seq) takes constant time? I would have thought it was > proportional to len(seq). enumerate(seq) is O(1) index(seq) is O(N) And thus: for i, val in enumerate(seq): print i is O(N) for val in seq: print seq.index(val) is O(N*N) From spam at no.thanks Sun Aug 1 19:37:18 2004 From: spam at no.thanks (aum) Date: Mon, 02 Aug 2004 11:37:18 +1200 Subject: want recommendations - distributed storage modules? Message-ID: <410d86b4@news.orcon.net.nz> Hi, I'm looking for a python-based framework for distributed storage. Needs: - high redundancy - high probability of being able to retrieve data even if (say) 30% of nodes are down - pure-python implementation - peer to peer - no central server requirement - 3rd-party module requirements - none, or pure python only - scalable A Distributed Hash Table (DHT) implementation would probably suit best. However, the only DHT implementations I've been able to find for python, such as SharkyPy and khashmir, are both broken on my box, and are under-documented and apparently unsupported. Any recommendations? Cheers aum From yeah at right.com Tue Aug 31 14:30:26 2004 From: yeah at right.com (Angus Mackay) Date: Tue, 31 Aug 2004 18:30:26 GMT Subject: generic tokenizer Message-ID: <6t3Zc.37294$A8.12593@edtnps89> I remember python having a generic tokenizer in the library. all I want is to set a list of token seperators and then read tokens out of a stream, the token seperators should be returned as themselves. is there anything like this? cheers, Angus. From zanesdad at bellsouth.net Thu Aug 19 22:17:37 2004 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Thu, 19 Aug 2004 22:17:37 -0400 Subject: Rita Sue and Bob too In-Reply-To: References: Message-ID: <41255F41.1000701@bellsouth.net> M. Clift wrote: >Hi All, > >Can someone help. I promise I've looked how to do this but can't find a >way... > >Ok, to find one name is easy > >if 'Bob' in list: > print "They were found" >else: > print "They are not in list" > >But, how to I find a sequence in a list of unknown size? i.e. this sequence >in list of other names and replace it with three others? > >'Rita','Sue','Bob' > >This is almost a nightly occurrence (my posting questions), but I am >learning : ) > > > > I'm sure someone else can come up with something more elegant, but here's a way you could do it: >>> names ['larry', 'curly', 'moe', 'shimp', 'rita', 'sue', 'bob', 'billy', 'scott'] >>> for idx in range(len(names)): ... if names[idx:idx + 3] == ['sue', 'bob', 'billy']: ... print "found 'em at element", idx ... break ... found 'em at element 5 >>> Notice, this: >>> ['sue', 'bob', 'billy'] in names False >>> returns false. The reason is, I think, because the set ['sue', 'bob', 'billy'] is not really a subset of ['larry', 'curly', 'moe', 'shimp', 'rita', 'sue', 'bob', 'billy', 'scott'], even though the three names appear sequentially in both lists. But, this: >>> names2 [['sue', 'bob', 'billy'], ['larry', 'curly', 'moe', 'shimp', 'rita', 'sue', 'bob', 'billy', 'scott']] >>> ['sue', 'bob', 'billy'] in names2 True >>> does "work" for the same reason that it doesn't work in the first example. The list ['sue', 'bob', 'billy'] itself is part of the larger list, names2. HTH, Jeremy Jones From Andreas.Ames at tenovis.com Tue Aug 3 05:13:22 2004 From: Andreas.Ames at tenovis.com (Ames Andreas (MPA/DF)) Date: Tue, 3 Aug 2004 11:13:22 +0200 Subject: IronPython-0.6 is now available! Message-ID: <788E231C269961418F38D3E360D1652526CA15@tndefr-ws00021.tenovis.corp.lan> Hi, Martin v. L?wis wrote: > is a language different from Java. Essentially, I believe that > all these .NET languages are just different ways to write C#. and futhermore it seems simply not to be true that .NET apps are language independent. For some evidence just see the most probably well known http://perso-info.enst-bretagne.fr/~beugnard/papiers/lb-sem.shtml As usual many claims about .NET seem to be pure marketing blurb. So forgive me if I'm suspicious about hilarious claims about it. cheers, andreas From knowlj at hotmail.com Mon Aug 9 13:18:42 2004 From: knowlj at hotmail.com (Jared) Date: 9 Aug 2004 10:18:42 -0700 Subject: Mechwarrior Python Game Message-ID: Has anybody played the Mechwarrior Miniatures game? I'm trying to represent the game in python. First thing I need to do is make a playing field. Mechs will move on the playing field based on inches to scale in any direction. Any ideas? From fuzzyman at gmail.com Thu Aug 12 05:13:32 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 12 Aug 2004 02:13:32 -0700 Subject: ClientCookie References: <6f402501.0408110018.1e4e5ca8@posting.google.com> <87acx1qo1z.fsf@pobox.com> Message-ID: <6f402501.0408120113.746639d4@posting.google.com> jjl at pobox.com (John J. Lee) wrote in message news:<87acx1qo1z.fsf at pobox.com>... > fuzzyman at gmail.com (Michael Foord) writes: > > > Has anyone used ClientCookie to store cookies ? > > I'm going to play around with 'pickling cookies' - but I wondered if > > anyone had any experience of this. > > > > (For session persistence in approx - my cgi proxy) > > Just thought to add: > > 1. are you using a database for this? (you should be) Look at > BSDDBCookieJar. BSDDBCookieJar isn't well-tested, but might be > just the ticket for what you're doing. It's not in cookielib yet, > but the one from ClientCookie 0.9.x should work fine with > cookielib, and I'll make it available in a separate package RSN, > along with the other stuff in ClientCookie but not in cookielib. > The program I'm writing is a CGI. I'd like to have *minimum* dependencies. The version of Python on the server is 2.2 (I have no control over that) and having a dependence on CookieClient is enough for me. I think I can only use BSDDBCookieJar if the server has the Berkely Database installed ? I'd like other people to be able to use my CGI on a basic Python 2.2 install - so even if I have it on my server, I don't want to be dependent on it. What I'm aiming to provide is persistent cookie support for multiple users of the same CGI - so I'll probably assign each user an id number via a cookie I give to them and have a pickled CookieJar for each user. I'd also like to work towards cookie management as well - so each user can see/edit/control which cookies they have saved. At the moment getting it to work at all would be a bonus........ Regards, Fuzzy http://www.voidspace.org.uk/atlantibots/pythonutils.html > 2. here's a simpler way (in a sense) of serialising a CookieJar than > pickling: > > cj = cookielib.CookieJar() > ... > s = [repr(c) for c in cj] > > > and unserialising: > > cj = cookielib.CookieJar() > for cs in s: > cj.set_cookie(eval(cs)) > ... > > You'd still need to write something like BSDDBCookieJar, though, if > I understand what you're doing. > > > John From jpmorichon at earthlink.net Fri Aug 13 12:44:42 2004 From: jpmorichon at earthlink.net (CptPicard) Date: Fri, 13 Aug 2004 16:44:42 GMT Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: <_d6Tc.23589$Jp6.3458@newsread3.news.atl.earthlink.net> "Peter Hansen" wrote in message news:Uf6dnb0hhtx1ToHcRVn-vg at powergate.ca... > beliavsky at aol.com wrote: > > > One of the most commmon reasons programmers cite for not trying Python > > is that indentation determines the program flow -- they think its > > weird. I think programmers who actually try Python adapt quickly and > > do not find the indentation rules to be a problem. > > I think you're right on both counts. For me, the adaptation > period was roughly ten seconds... > > > I wonder if there is a way to remove this initial barrier. > > Why? Is there really any evidence that the Python community > is missing a large number of really excellent programmers merely > because they are resistant to the idea of syntactically significant > indentation? Yes, it's one of the most common reasons programmers > cite as you note above, but in absolute terms I doubt it's that > significant. That's true. As the question is formulated, I don't think that a programmer will be stopped by the indentation syntax. There are so many languages with very strange syntax : we adopt them because they are efficient in what they are doing and are adaptated to our problems. But on a first approach, if you know that several languages could fix your problem, you may tend to choose the one you prefer regarding several criteria like ... syntax. And for me, the problem could be here: on a quick analysis, people may prefer Perl to Python (for example ;-) ) just because it looks like that they are doing the same thing and Perl syntax may look more appealing (not talking about regular expressions here). And once you are engaged in learning a language, you tend to think twice before learning another one. And the main question becomes : what Python will bring to me so that I stop working on my current language and learn about Python ? So I don't think that it is a problem of laziness or of being closed minded. Note: I assume here that people have the choice to choose their programming languages. I noticed too that, amazingly, a lot of programmers know about Perl but not Python. > > > I'm not saying that Python's use of indentation is bad, just that it > > stops many programmers from trying it. > > I really question whether we are looking for such programmers. > They sound rather close minded and perhaps even lazy... > > -Peter From corey.coughlin at attbi.com Tue Aug 24 19:33:04 2004 From: corey.coughlin at attbi.com (Corey Coughlin) Date: 24 Aug 2004 16:33:04 -0700 Subject: Alternative decorator syntax decision References: Message-ID: J2 J2 H Although in the H category I prefer the spaced option. The vertical line as an arrow is a little more appealing that a smudgy decoration. From jzgoda at gazeta.usun.pl Sat Aug 7 16:23:36 2004 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Sat, 07 Aug 2004 22:23:36 +0200 Subject: Going the PL/1 way In-Reply-To: References: Message-ID: Michael Hudson wrote: >>Come on, guys, fix real problems like interpreter thread safety, >>improve performance, don't make us, "real-world software >>developers", screaming with every new release, please. > > http://www.python.org/patches/ You want to say "if you want any improvement, do it yourself"? Sure, it's much better than Java's JCP, but expect http://catb.org/~esr/jargon/html/F/fork.html if enough people will share the same annoyance and anger. I write some free software, but I never tell users "go fix it yourself". This is rude. -- Jarek Zgoda http://jpa.berlios.de/ From sbabbitt at commspeed.net Mon Aug 9 20:17:01 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Mon, 9 Aug 2004 17:17:01 -0700 Subject: Parsing broken HTML via Mozilla References: Message-ID: <1092097429.844882@news.commspeed.net> "Walter D?rwald" wrote in message news:mailman.1413.1092080863.5135.python-list at python.org... > Hello all! > > I'm trying to parse broken HTML with several Python tools. > Unfortunately none of them work 100% reliable. Problems are > e.g. nested comments, bare "&" in URLs and "<" in text (e.g. > "if foo < bar") etc. > > All of these pages can be displayed properly in a browser > so why not reuse the parser in e.g. Mozilla? Is there any > way to get proper XML out of Mozilla? Calling mozilla on the > command line would be OK, but it would be better if I could > use Mozilla like a SAX parser. Is there any project that > provides this functionality? > > Bye, > Walter D?rwald > > Maybe you should preprocess your files with something like, http://www.zope.org/Members/chrisw/StripOGram which can help you get rid of the stuff you dont want Tom From jaydonnell at yahoo.com Tue Aug 24 22:30:08 2004 From: jaydonnell at yahoo.com (Jay Donnell) Date: 24 Aug 2004 19:30:08 -0700 Subject: urllib hangs References: Message-ID: Thanks a lot :) From Jeffrey at Fro.man Tue Aug 24 23:02:26 2004 From: Jeffrey at Fro.man (Jeffrey Froman) Date: Tue, 24 Aug 2004 20:02:26 -0700 Subject: Inline Conditionals? References: <1093385974.29259.146.camel@localhost.localdomain> Message-ID: Joshua Ginsberg wrote: > def foo(x): > return foo == 'bar' ? 'w00t' : 'l33t' You could do something like: def foo(x): return ((x==bar) and 'w00t') or 'l33t' But this doesn't work when you want to return a false value for a positive result on your truth test. Thus: def foo(x): return ((x==None) and None) or x[:4] always returns None, regardless of what x is. Jeffrey From aleaxit at yahoo.com Mon Aug 30 03:05:13 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 30 Aug 2004 09:05:13 +0200 Subject: Generator expressions v/s list comprehensions References: <1gj8y77.6qshr41q531veN%aleaxit@yahoo.com> Message-ID: <1gja740.1c0kkt61tlhws0N%aleaxit@yahoo.com> Mahesh Padmanabhan wrote: ... > What is "Python's applicative order evaluation" and how do generator > expressions get around it? I see you've received several answers but it doesn't seem that they address this point, so let me try. Python, like most programming languages, specifies that evaluation is in "applicative order": each argument to a function (or operator, etc) is entirely evaluated before the function executes (Python, like several other languages, makes a specific ad hoc exception for 'short-circuiting operators', namely 'and' & 'or', which may entirely omit evaluating one argument in some cases). This is also known as 'strict' or 'eager' evaluation and by other names yet (some draw subtle distinctions between the exact connotation of such names but for simplicity we'll treat them as synonyms, and similarly for terms introduced in the next paragraph). Haskell, where the concept of list comprehensions originated, is different than most languages: Haskell specifies that evaluation is in "normal order" -- each argument and PART of an argument is evaluated at the time, if ever, at which that value is needed to compute. This is also known as 'non-strict' or 'lazy' evaluation. The reason this feature of Haskell is pretty unusual is that implementing it is somewhat complicated and costly -- in a lazy-evaluation language's implementation there are typically plenty of 'thunks' of code being stashed here and yon for possible future execution. I don't even know of any lazy evaluation language that does not rely on the crucial simplification of the computation environment given by 'functional programming' aka FP (basically, the idea that all objects are immutable -- a program computes new objects, it never mutates existing objects)... and Python is not a FP language (it crucially uses mutable data, particularly mutable lists), so it would be astonishing if Python had the kind of generalized support for lazy evaluation that you see in Haskell. So, Python copied Haskell's list comprehensions, but didn't (couldn't, probably!) copy the lazy evaluation aspect. So, whenever Python evaluates a LC, it evaluates it fully -- it necessarily materializes the whole list in memory, say N items' worth. This is intrinsically O(N) in space and therefore AT BEST can be O(N) in time (it will be worse than O(N) unless each step is constant-time, i.e. O(1)...!). This doesn't apply to Haskell, thanks to lazy evaluation -- in Haskell, each item of a list comprehension will be evaluated only if and when it's needed, just like any other operand/arguments/etc... but Python can't do that. Which is why Python 2.4 introduced generator comprehensions -- in a way a closer match to Haskell's list comprehensions, than Python's own LCs! That's because generators play the role of 'thunks' -- pieces of code hanging out there in suspended animation, ready for a bit more execution if and when needed -- for the specific but crucially important case of sequential iteration over (some prefix of) the items of a (potentially unbounded) sequence [[a case which you will also find in other programming models under such names as 'streams' -- Unix pipes also implement some part of that, with various processes in a pipeline playing the role of the thunks in this case...]]. Generators (and more generally iterators, and more specifically generator comprehensions) give Python "just enough lazy evaluation to get by" -- without paying the full conceptual and practical costs in switching to "full laziness" (and totally immutable data), Python thereby nevertheless gets the ability to express some (vast and important) subset of those algorithms which non-strict evaluation makes so elegant to express. Alex From maxm at mxm.dk Wed Aug 25 06:49:18 2004 From: maxm at mxm.dk (Max M) Date: Wed, 25 Aug 2004 12:49:18 +0200 Subject: Why return None? In-Reply-To: References: Message-ID: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> Martin DeMello wrote: > Anthony Baxter wrote: > >>On Wed, 25 Aug 2004 08:26:26 GMT, Martin DeMello >> wrote: >> >>>It seems to be a fairly common pattern for an object-modifying method to >>>return None - however, this is often quite inconvenient. >> >>list.reverse() modifies the list in place. The python idiom is that >>these don't return a reference to the modified list. Although note the > > Yes, but why? I mean, is there either an advantage to returning None or > some inherent danger in returning self? It is a design philosophy. Explicit is better than implicit. what would you expect a_list.sort() to return? If it returns a list, you would expect it to be a sorted copy of the list. Not the list itself. But for performance reasons the list is sorted in place. So if you modify the list in place, why should sort() then return the list? That the sort() method returns a None is actually a pedagocical tool to tell the programmer that the list is modified in place. If it had returned the list the programmer would later be surprised to find that the list had been modified. It would seem like hard to find nasty side effect. The way it is now is very explicit and easy to find out. regards Max M From peter at engcorp.com Wed Aug 11 08:04:23 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 11 Aug 2004 08:04:23 -0400 Subject: Executing bytecode from a string. In-Reply-To: References: Message-ID: Michael Hudson wrote: > "Benjamin Scherrey" writes: > > >>I'm curious as to how difficult it would be to take a string that contains >>compiled bytecode, load it into memory, give it a function name then >>execute that function. > > Fairly hard: you'd need to guess or work out all the other parameters > to new.code such as argcount, stacksize,... I seem to recall doing this, and it wasn't hard for my particular case because it wasn't an arbitrary function. It took no arguments, returned nothing, etc... I was doing this as an experiment to see whether it was feasible to use evolutionary programming to evolve Python bytecode that would solve some problem. The idea worked in principle (I was able to get the bytecode to execute) but unfortunately there were numerous instances where the effectively random bytecode would lead to the interpreter crashing fatally. I still think it's a neat idea, but it won't work well with Python in its current form. Might be useful for doing some kind of stress testing on the interpreter though, if someone was interested in making it bullet-proof even for psychotic code (as part of a new security initiative, perhaps?). And sorry, but this was a quickie experiment and I don't have the code any more. Just wanted to say it was doable for the simplest case. -Peter From tpassin at comcast.net Mon Aug 2 09:59:25 2004 From: tpassin at comcast.net (Thomas B. Passin) Date: Mon, 02 Aug 2004 09:59:25 -0400 Subject: [XML-SIG] value error when parsing XML In-Reply-To: <410B7277.3000609@mail.usyd.edu.au> References: <410B7277.3000609@mail.usyd.edu.au> Message-ID: <410E48BD.9060202@comcast.net> Ajay Brar wrote: > > i get a value error when parsing an xml file. This is because it can't > find the DTD - > ValueError: unknown url type: ../um_xml/um.dtd > Is it a Windows machine, and if so did you try ..\um_xml\um.dtd? (or of course ..\\um_xml\\um.dtd or the raw notation if the path is in code instead of on the command line) Cheers, Tom P -- Thomas B. Passin Explorer's Guide to the Semantic Web (Manning Books) http://www.manning.com/catalog/view.php?book=passin From Jared.Cohen at noaa.gov Thu Aug 19 11:32:56 2004 From: Jared.Cohen at noaa.gov (Jared Cohen) Date: Thu, 19 Aug 2004 11:32:56 -0400 Subject: Please help -- Tkinter Scale widget with DoubleVar is acting weird Message-ID: <4124C828.5080106@noaa.gov> Hi all. I'm currently using a Tkinter Scale widget which uses a DoubleVar as its control variable. I then use the "trace_variable('w', callback)" method to invoke a callback whenever the DoubleVar changes. The problem is this: the callback is triggered when the slider moves (as it should), but it's also triggered when I just HOVER the mouse over the slider without clicking! Somehow or other, it must think that the control variable is being changed, even though it isn't. I *think* that this problem is related to the loss of precision that DoubleVars can have, but I'm not really sure. Has anyone else experienced this problem? How can I fix this? As an aid, here's a quick stub program that illustrates the problem. Try (for example) moving the slider to 0.3, release the mouse button, then move the mouse pointer back and forth over the slider WITHOUT clicking. Each time the pointer passes over the slider, it will print the value. import sys, Tkinter, types root = Tkinter.Tk() var = Tkinter.DoubleVar() def callback(*args): print var.get() var.trace_variable("w", callback) slider = Tkinter.Scale(root, from_ = 0.0, to = 1.0, resolution = 0.1, variable = var, orient = 'horizontal') slider.grid(sticky='ew') root.mainloop() -------------- next part -------------- An HTML attachment was scrubbed... URL: From dperl at rogers.com Mon Aug 30 12:05:02 2004 From: dperl at rogers.com (Dan Perl) Date: Mon, 30 Aug 2004 16:05:02 GMT Subject: initializing mutable class attributes References: <29SdnfncSK8R3K7cRVn-sA@comcast.com> Message-ID: Larry, I don't think it is very different from what I suggested. You still implement an __init__ and you initialize the instance attributes there. Thanks, though. It's a nice trick and it's useful because you have a default value that can be used also in other places in the code (like restoring the default). And it's probably a good use of pseudo-private class attributes. Dan "Larry Bates" wrote in message news:29SdnfncSK8R3K7cRVn-sA at comcast.com... > Dan, > > I too use class attributes to assign defaults, but do > it like following: > > import copy > > class Father: > _attr1default=None > _attr2default=[] > > def __init__(self): > self.attr1=self._attr1default > # Get copy of attr2default > self.attr2=list(self._attr2default) > > def foo(self, data): > self.attr1=data > self.attr2.append(data) > > > class Child (Father): > def __init__(self): > Father.__init__(self) > # > # At this point self.attr1 (instance) > # and self.attr2 (instance) hold their defaults > # while _attr1/_attr2default (class) still hold > # their default values for initialization of more > # class instances. > # > > HTH, > Larry Bates > Syscon, Inc. > > > "Dan Perl" wrote in message > news:sHGYc.93306$pTn.42032 at news01.bloor.is.net.cable.rogers.com... > > I will clarify something that was probably not clear enough in my initial > > posting. I am interested in instance attributes, but I am using the class > > attributes to provide a default, "null", value for the instance > attributes. > > Yes, the instance attributes only mask the class ones, but a class > attribute > > and an instance attribute can be used like this: > > class WorksForMe: > > attr=None # used just as a default value for the instance > > attribute self.attr > > def foo(self): > > self.attr=SomethingUseful( ) > > def bar(self): > > if self.attr: > > useIt(self.attr) > > else: > > ignoreIt(self.attr) > > This makes it safe for an instance of WorksForMe to invoke bar( ) even if > it > > never invoked foo( ). > > > > "Benjamin Niemann" wrote in message > > news:cgul4v$h1d$1 at online.de... > > > That's the way it is supposed to work. Instance attributes have to be > > > initialized via self.foo=..., usually in __init__() which in turn is > > > *STRONGLY* advised to class its parents __init__() - or you create > > > instance attributes 'on-the-fly' when they are used for the first time > > > (useful technique for mixin classes without constructor). Class > > > attributes are initialized once for the class and are shared between > > > instances. > > > > You are confirming the code I suggested but you don't share my view that > > such code is awkward. I think I I was actually conservative calling it > > awkward, I would rather call it unsafe. If I were a third-party library > > vendor, I would not be comfortable providing a mixin class that forces > users > > to either invoke the parent's __init__ in their constructors or to > > initialize the instance attributes on-the-fly. The latter would even be > > against the principles of encapsulation, users should not need to know > about > > the parent's attributes, especially because they may change in future > > releases. Both ways of restricting the use of the mixin class are unsafe > > because they are easy to be ignored by users. And it is not only the > users' > > fault if they do not follow the restrictions, it is also my fault to put > > such restrictions in the first place. > > > > I think this points to a weakness in Python as an OO language. I'm not > > trying to bash it, but my understanding is that Python is still evolving > in > > that respect and I think that this should be improved in the future. > Then, > > on the other hand, maybe I'm the only one feeling this way and there's not > > going to be a change. > > > > > "self.attr1=data" in Father.foo() doesn't "override" the Father.attr1 > > > attribute you defined before. It creates an instance attribute that > > > shadows Father.attr1! > > > Both attribute assignments in Father are OK - if you treat them as class > > > attributes. They won't become instance attributes by hidden magic. > > > > > > Dan Perl wrote: > > > > There is something with initializing mutable class attributes that I > am > > > > struggling with. I'll use an example to explain: > > > > class Father: > > > > attr1=None # this is OK > > > > attr2=[ ] # this is wrong > > > > def foo(self, data): > > > > self.attr1=data > > > > self.attr2.append(data) > > > > The initialization of attr1 is obviously OK, all instances of Father > > > > redefine it in the method foo. But the initialization of attr2 is > wrong > > > > because all the instances of Father end up sharing the same value. > > Maybe > > > > that is desired sometimes, but usually it is just a bug. > > > > > > > > So the only solution I see to this is to initialize attr2 in __init__: > > > > class Father: > > > > attr1=None > > > > def __init__(self): > > > > self.attr2=[ ] > > > > > > > > This is already awkward because there is such a difference between > attr1 > > and > > > > attr2. But moreover, I think this forces subclasses of Father to do > > > > something like this: > > > > class Child (Father): > > > > def __init__(self): > > > > Father.__init__(self) > > > > self.attr3=[ ] > > > > > > > > I find this even more awkward because many people will forget to do > it. > > > > Clearly, this is then a more general issue with __init__, but I think > it > > is > > > > accentuated by the fact that you HAVE TO HAVE __init__ in order to > > > > initialize attributes that are mutable. > > > > > > > > Is there something I don't know here and there is a better way to do > > this in > > > > Python? I would like to get a better solution or otherwise start a > > > > discussion. > > > > > > > > > From newsgroups at jhrothjr.com Sat Aug 7 07:01:55 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Sat, 7 Aug 2004 07:01:55 -0400 Subject: Prothon is switching to the .NET platform References: <000401c47b59$32539220$0d01a8c0@MarkVaio> <10h7lb21dhbuc12@news.supernews.com> <10h7rittck6ct75@news.supernews.com> Message-ID: <10h9dkm5ub5h1f2@news.supernews.com> "Peter Otten" <__peter__ at web.de> wrote in message news:cf1t0h$ond$03$1 at news.t-online.com... > John Roth wrote: > > > > > "Christopher T King" wrote in message > > news:Pine.LNX.4.44.0408061533250.25906-100000 at ccc8.wpi.edu... > >> On Fri, 6 Aug 2004, John Roth wrote: > >> > >> > I think it's possible to do prototypes within Python by > >> > overriding the __getattribute__() magic method. It still > >> > wouldn't be very pretty, but it should be able to do > >> > everything except override the magic methods (those > >> > seem to have to be in the class object for new style > >> > classes). > >> [snip] > > > > What I was thinking of was more along the lines of: > > > > class ProtoBaseClass(object): > > def __getattribute__(self, attr): > > # call object.__getattribute__(self, __dict__) > > # find requested attribute > > Wouldn't that part be implied if you used __getattr__() instead of > __getattribute()? > > > # if not found, loop through back pointer chain > > # if it's not a function, return the attribute > > # if it is a function, wrap it in a method object and return it. > > This means that an object sees all changes in its prototypes until > explicitly assigned an attribute. Is this intentional? (real question, I'm > not familiar with prototyped languages) Actually, __getattribute__ sees all attribute requests, __getattr__ only sees requests where the attribute isn't found. The reason for using __getattribute__ is that there are (I think) serious problems with attempting to execute functions that weren't originally defined in the base class or a subclass of the base class. In other words, if the result is a function, there's more work that needs to be done, and __getattr__ doesn't allow a hook to do it on the way out. The attempt from 2000 I referred to attempted to get around this by using a callable instance together with a lambda. Unfortunately, it didn't work when I tried it, and as I said, after looking at the code I don't think it ever worked. The workaround for the function problem might work, though. [snip] > > Peter > From mh at dreadnok.pixar.com Wed Aug 4 14:16:18 2004 From: mh at dreadnok.pixar.com (Mark Harrison) Date: Wed, 04 Aug 2004 18:16:18 GMT Subject: guide to introspecting python? References: Message-ID: Peter Hansen wrote: > Isn't the "inspect" standard module exactly what you need? Yes it is... thanks! From kristian_zoerhoff at sbcglobal.net Fri Aug 13 09:46:39 2004 From: kristian_zoerhoff at sbcglobal.net (Kristian M Zoerhoff) Date: Fri, 13 Aug 2004 13:46:39 GMT Subject: Python and Weather.com In-Reply-To: References: <6491b0ab.0408121917.5103b770@posting.google.com> Message-ID: <3D3Tc.4$yj3.1006@newssvr28.news.prodigy.com> Paul, That's a pretty slick little script; another great contribution to the community! -- Kristian From luismg at gmx.net Mon Aug 2 10:48:13 2004 From: luismg at gmx.net (Neuruss) Date: 2 Aug 2004 07:48:13 -0700 Subject: Starkiller? Message-ID: <278de0e.0408020648.6d187aff@posting.google.com> Does anyone have news about Starkiller? From imbosol at aerojockey.com Thu Aug 12 19:11:17 2004 From: imbosol at aerojockey.com (Carl Banks) Date: 12 Aug 2004 16:11:17 -0700 Subject: A decorator syntax not yet mentioned (I think!) References: <60dfb6f6.0408111846.615ee9eb@posting.google.com> <3YWdnYxLf--ObofcRVn-pw@powergate.ca> <411ba1db$1@nntp.zianet.com> Message-ID: <60dfb6f6.0408121511.10912a2f@posting.google.com> Mark Bottjer wrote in message news:<411ba1db$1 at nntp.zianet.com>... > With this > syntax, though, the decorate block changes how the def statement is > handled, even though they are at the same indentation level. That's a problem only if you think of decorate and def as separate statements. If, as with if...else and try...except, you think of decorate...def as a single statement, then there is no problem. -- CARL BANKS From sbabbitt at commspeed.net Fri Aug 27 17:11:09 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Fri, 27 Aug 2004 14:11:09 -0700 Subject: my first class: Args References: Message-ID: <1093641585.312667@news.commspeed.net> Looks just beautiful, I always leave docstrings out because of laziness. As for quotes you don't need to put "" if you have nothing to say and python lets you use 'single', "double", or even """the 'magnificent' triple "quote" """ in code. Tom From peter at engcorp.com Mon Aug 30 16:15:44 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 30 Aug 2004 16:15:44 -0400 Subject: Search for AVI file? In-Reply-To: References: Message-ID: John Doe wrote: > I realise that this is not really a python question, but python's the > only language I'd be comfortable trying to deal with this. > > What I need is to search a drive and find all the AVI format files > that are NOT listed with the AVI extension. I'm looking over an old > drive of mine from an old computer. I know the files were renamed > with the wrong extension, but I know that they were originally AVI > files. Can python do this for me? Any hints? Anybody have a link to > something that would already do this? I appreciate any help. Have you looked for and found information about the AVI file format? Google can help you with that. You should easily be able to use Python to read the first X bytes of a given file and check the signature to see if it's likely an AVI file. I'm sure there are exceptions and new versions and such things, but if you have only a bunch of "old" AVI files, it's quite possible they are all detectable by doing something like checking that bytes 0 through 3 are 'RIFF' and bytes 8 through 10 are 'AVI' (that info from a few handy sites on the AVI format). Basically you could just open the file and do a .read(10) and compare the result using slices, e.g. data[0:4] == 'RIFF' and data[8:11] == 'AVI'. -Peter From http Fri Aug 27 19:38:21 2004 From: http (Paul Rubin) Date: 27 Aug 2004 16:38:21 -0700 Subject: Alex Martelli: Welcome back! References: <1gj70sk.1o4cuwepco564N%aleaxit@yahoo.com> Message-ID: <7xfz68jgnm.fsf@ruckus.brouhaha.com> aleaxit at yahoo.com (Alex Martelli) writes: > Heh, thanks. BTW, anybody interested in the readings we choose for our > marriage (me and Anna, who's also going to be my coeditor for the Python > Cookbook Second Edition) can have a look at http://www.aleax.it/mar.html Hey, congratulations! From gerrit.muller at embeddedsystems.nl Wed Aug 18 08:30:19 2004 From: gerrit.muller at embeddedsystems.nl (Gerrit Muller) Date: Wed, 18 Aug 2004 14:30:19 +0200 Subject: age of Python programmers In-Reply-To: References: Message-ID: Most Python programmers I know are 40+. I am myself 47 (born in december 1956). regards Gerrit P.S., how many teeners are still programming? Most teeners I know build websites, but they don't program. -- Gaudi systems architecting: From adurdin at gmail.com Wed Aug 25 08:19:40 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Wed, 25 Aug 2004 22:19:40 +1000 Subject: iterators: class vs generator In-Reply-To: References: Message-ID: <59e9fd3a040825051978250f04@mail.gmail.com> On Wed, 25 Aug 2004 11:24:41 GMT, Michael Hudson wrote: > > Here's a better illustration: > > >>> def iterable_via_generator(): > .... yield "one" > .... raise Exception() > .... yield "two" > .... > >>> i = iterable_via_generator() > >>> i.next() > 'one' > >>> i.next() > Traceback (most recent call last): > File "", line 1, in ? > File "", line 3, in iterable_via_generator > Exception > >>> i.next() > Traceback (most recent call last): > File "", line 1, in ? > StopIteration This is correct behaviour according to PEP 255: """ If an unhandled exception-- including, but not limited to, StopIteration --is raised by, or passes through, a generator function, then the exception is passed on to the caller in the usual way, and subsequent attempts to resume the generator function raise StopIteration. In other words, an unhandled exception terminates a generator's useful life. """ From peter at engcorp.com Mon Aug 23 10:27:01 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 23 Aug 2004 10:27:01 -0400 Subject: Has anyone implemented BASIC in Python? In-Reply-To: <7xoel26w2n.fsf@ruckus.brouhaha.com> References: <2oo13eFcj548U1@uni-berlin.de> <69cbbef2.0408210857.79439c35@posting.google.com> <7x657c8jmn.fsf@ruckus.brouhaha.com> <7xoel26w2n.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Peter Hansen writes: > >>>Dunno about Logo but I did Forth just out of general perversity. >>>I suppose I could post it. >> >>Please do! > > http://www.nightsong.com/phr/python/forth.py Thank you, Paul. Several others wrote to check if you had sent anything to me privately, so there must be interest. :-) (My interest stems from two areas: simple curiosity and the possibility of using Forth as a "scripting" language for some embedded systems at some point, and the thought that a Python-based Forth could be used to allow PC-side test-driven development. Mostly I have the same curiosity that led you to write it in the first place, but either less time or more laziness. ;-) -Peter From ialbert at mailblocks.com Sun Aug 15 22:02:00 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Sun, 15 Aug 2004 22:02:00 -0400 Subject: Python secure? In-Reply-To: <41200f06$0$65568$a1866201@newsreader.visi.com> References: <6o75v1-p92.ln1@home.rogerbinns.com> <412009f1$0$8090$a1866201@newsreader.visi.com> <41200f06$0$65568$a1866201@newsreader.visi.com> Message-ID: Grant Edwards wrote: > I've read up a bit, and I looks like I was wrong. The mere act > of creating a derived work is an infringement of copyright. > The derived work doesn't have to be distributed for an > infringment to have taken place. Title 17 says > (2) to prepare derivative works based upon the copyrighted work; Is a decompiled source code a 'derivate' work? I always felt that meaning of 'derivative' is creating a piece a work that is either very similar to or incorporates large sections of an other piece of work. The mere fact of using a binary file as the input to a program does not mean that the output of this program is a 'derivative work' of the binary file. I think the answer lies not in the copyright law but in the license that was set by the program owner. If they forbid decompilation that's their right to do so. Istvan. From ajsiegel at optonline.com Sun Aug 22 10:57:47 2004 From: ajsiegel at optonline.com (Arthur) Date: Sun, 22 Aug 2004 14:57:47 GMT Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? References: Message-ID: On Sun, 22 Aug 2004 08:07:53 -0500, Doug Holton wrote: >Paul McGuire wrote: >> Total voters: 55 >> Of all of the votes cast, J2 >> received 48%, C1 received 18%. No other option received more than 10% of >> any votes. > >I vote 3 times for C1. So just my one vote raises C1 to 20%. I think >you need to do an online poll so you get more people than just those who >have been discussing the decorator keyword here this past week. I got >over 250 votes for C1 just last week vs. the 22 who voted for J2 here. >During this 2nd poll people were confused about whether they could vote >for A1 or not, and some people said many of the options on the wiki page >were not allowed anymore. > I think it should also be noted in the report of the voting results that the a vote for "no new syntax at this time" was specifically outlawed. As a side point: It seems ironic to me that in a group devoted to an appreciation of Python, and its advocacy - it is often those who reject the notion that the language has the kinds of glaring weaknesses that require some fundamental change ot it, that form the opposition to an "establishment" that has become convinced quite otherwise. I sometimes wish those folks were more candid about its deficiencies before I started my study of it back in 1.5.2 days. Art From fperez528 at yahoo.com Tue Aug 3 13:14:29 2004 From: fperez528 at yahoo.com (Fernando Perez) Date: Tue, 03 Aug 2004 11:14:29 -0600 Subject: Re_: Best way to run ipython inside of emacs shell? References: <4d642979.0408022332.4380ad23@posting.google.com> Message-ID: Yaroslav Bulatov wrote: >> Equis Uno wrote: >> >> > I use meta-x shell to start a shell and then once I see a shell >> > prompt I enter the python command and I get a well-behaved python >> > shell inside of emacs. >> > >> > I'm trying to figure out the best way to run ipython inside of emacs. > > I had the same problem. It has to do with ipython.el not finding the > IPython executable. > > To fix it, open ipython.el, and replace line > (when (executable-find "ipython") > with > (when (executable-find "ipython.bat") > > Next, add file ipython.bat to your path containing something like the > following: > C:\Python23\python.exe "C:\Program Files\IPython\IPython_shell.py" > > Unfortunately it doesn't seem to work right on windows. The prompts > are missing so it's almost unusable. Are you having this problem with the emacs support stuff currently available from the ipython site? There's a special python-mode.el in there which is different from the default one shipped with emacs (because the maintainers have ignored Alex Schmolck's patches for a long time). That might help (or not, I have no way of testing under windows, though I know it works ok in unix). Best, f From rschroev_nospam_ml at fastmail.fm Sat Aug 28 03:47:13 2004 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Sat, 28 Aug 2004 07:47:13 GMT Subject: allowing braces around suites In-Reply-To: <1r3c28ejis.fsf@rovereto.ifi.uio.no> References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> <87hdqok9i6.fsf@sinken.local.csis.hku.hk> <1rfz68ely9.fsf@rovereto.ifi.uio.no> <876574k7du.fsf@sinken.local.csis.hku.hk> <1r3c28ejis.fsf@rovereto.ifi.uio.no> Message-ID: <5MWXc.228027$ht5.11749427@phobos.telenet-ops.be> Kjetil Torgrim Homme wrote: > [Isaac To]: > >> When Python is concerned and Emacs is not, Python only sees there >> is indentation, and only indentation, to define the suites. And >> it is also what people will perceive when they stare at the code. >> There is nothing to be inconsistent with it. > > > how long do you have to stare before spotting the bug? Just the time needed to read the code. > db.update_name(person) > if is_student(person): > db.update_courses(person) > db.commit() > > only students have their names updated. I wonder why. No offense, but I wonder why you have a problem with this code. IMO the indentation makes perfectly clear what's happening. -- "Codito ergo sum" Roel Schroeven From mark at prothon.org Sun Aug 8 18:11:59 2004 From: mark at prothon.org (Mark Hahn) Date: Sun, 8 Aug 2004 15:11:59 -0700 Subject: Acquiring Prothon libraries [Was: Prothon is switching to the .NET platform] References: <000401c47b59$32539220$0d01a8c0@MarkVaio> <11uq0duazp1vy.1g2zjz8xyfosl.dlg@40tude.net> Message-ID: <1brh56r9w6713$.114chhbp8m6id$.dlg@40tude.net> On Sun, 8 Aug 2004 22:35:43 +0200, Mikl?s wrote: > Isn't it possible to automate or semi-automate the conversion of the Python > libraries somehow? > There must be a sensible mapping of class-based code to prototype-based > code.. It's not classes versus prototypes. When I looked at running CPython's libraries with Prothon earlier this year it didn't look good. The Python libraries were too tightly wrapped around the Python language. The CPython VM was not written to support multiple languages as the CLR is. Python extensions expect to be able to have any and all of Python available at all times. The best I could do would be to have the CPython interpreter running embedded inside my Prothon interpreter and bridging calls from Prothon over to Python. This would not be efficient as it would require both VMs to run side by side. There would also be the overhead of translating between the two. Native threads would not be supported. I pretty much gave up on the idea. From reinhold-birkenfeld-nospam at wolke7.net Fri Aug 20 14:22:57 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Fri, 20 Aug 2004 20:22:57 +0200 Subject: How to clean python interpreter's environment? In-Reply-To: References: Message-ID: <2omtogFck37uU1@uni-berlin.de> Peter Hansen wrote: > Rafal Kleger-Rudomin wrote: >> I'm looking for a command to reset interpreter's environment i.e. unload >> all modules, delete variables etc. > > If you're in the interactive interpreter, you should use > the following command: ^Z (on Windows), or ^D (Linux). > > (Translation: there's no existing command that does what > you want. Maybe describing your reason for wanting this will > let people suggest alternative solutions.) What about something like this: def clear(keep=("__builtins__", "clear")): keeps = {} for name, value in globals().iteritems(): if name in keep: keeps[name] = value globals().clear() for name, value in keeps.iteritems(): globals()[name] = value Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From martin.vonloewis at hpi.uni-potsdam.de Tue Aug 10 12:33:00 2004 From: martin.vonloewis at hpi.uni-potsdam.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 10 Aug 2004 18:33:00 +0200 Subject: [Python-Dev] RELEASED Python 2.4, alpha 2 In-Reply-To: <4115D88F.8020802@v.loewis.de> References: <411231C8.3020308@interlink.com.au> <4113429a$0$26993$9b622d9e@news.freenet.de> <41137960.6050400@v.loewis.de> <4113dddd$0$12507$9b622d9e@news.freenet.de> <4115D88F.8020802@v.loewis.de> Message-ID: <4118F8BC.1080504@hpi.uni-potsdam.de> Martin v. L?wis wrote: > Yes, saw that. I'm not faulting you though - I do believe that the > behaviour in this case should be improved somehow. Ok, I have tried to reproduce this, and *now* I'm faulting you :-) I thought that there was a special "restricted user" with less-than- reasonable permissions. I usually have XP Pro in a domain only, so I don't get to see this user interface. I have tried this out, and found that a "restricted account" is just one where the user belongs to the "Users" group (instead of belonging to the "Power Users" group). Such a user can, by default, write to its own registry, and install the MSI as planned (i.e. Privileged is false). Closing #1004837. Regards, Martin From indigo at bitglue.com Mon Aug 23 15:04:04 2004 From: indigo at bitglue.com (Phil Frost) Date: Mon, 23 Aug 2004 15:04:04 -0400 Subject: Standard graph API? In-Reply-To: References: Message-ID: <20040823190404.GA21259@unununium.org> +1 for standard graph API! I don't have a "high-end" use for it, but I did write a program which graphs the revision history of a software repository. It would have been nice to have most of that code in a library, and if such a library existed, it would probably implement operations I was too lazy to implement, such as coloring. On Mon, Aug 23, 2004 at 06:43:35PM +0000, wes weston wrote: > Magnus Lie Hetland wrote: > >Is there any interest in a (hypothetical) standard graph API (with > >'graph' meaning a network, consisting of nodes and edges)? Yes, we > >have the standard ways of implementing graphs through (e.g.) dicts > >mapping nodes to neighbor-sets, but if one wants a graph that's > >implemented in some other way, this may not be the most convenient (or > >abstract) interface to emulate. It might be nice to have the kind of > >polymorphic freedom that one has with, e.g, with the DB-API. One could > >always develop factories or adaptors (such as for PyProtocols) to/from > >the dict-of-sets version... > > > >So, any interest? Or am I just a lone nut in wanting this? > > > Magnus, > A know I'd appreciate it. It could be used to configure > neural nets and logic networks; where this api would make > it easy to build an abstraction then "compile" it into a > faster representation for execution - or just run the > tree/graph in "interpreted" mode. > I don't think it would get a lot of use, but the use > would be high end. > wes > > -- > http://mail.python.org/mailman/listinfo/python-list From grante at visi.com Thu Aug 26 22:08:29 2004 From: grante at visi.com (Grant Edwards) Date: 27 Aug 2004 02:08:29 GMT Subject: A newbie in need.... References: <9c3edc58.0408261609.6640e400@posting.google.com> <412e91cc$0$62953$a1866201@newsreader.visi.com> Message-ID: <412e979d$0$65612$a1866201@newsreader.visi.com> On 2004-08-27, Grant Edwards wrote: >> Besides "curses" or "ncurses", is there a python module that >> will create a graph? > > I never knew that [n]curses did graphing (and I've used it > quite a bit). > > I use the Gnuplot module when I need to create a graph: > > http://gnuplot-py.sourceforge.net/ That's assuming you mean graph in the "plot of some data or a function" sense of the word. If you mean graph in the CS "nodes and edges" sense, Gnuplot doesn't do that. But neither does [n]curses, so I'm still a bit confused. :/ -- Grant Edwards grante Yow! I LIKE Aisle 7a. at visi.com From h.b.furuseth at usit.uio.no Sun Aug 22 13:03:00 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 22 Aug 2004 19:03:00 +0200 Subject: Proposal: require 7-bit source str's References: Message-ID: Peter Otten wrote: > Hallvard B Furuseth wrote: >>>>> The long-term goal would be unicode throughout, IMHO. >>>> >>>> Whose long-term goal for what? For things like Internet communication, >>>> fine. But there are lot of less 'global' applications where other >>>> character encodings make more sense. > > More sense? I doubt that. What does make sense is an api that abstracts from > the encoding. If the application knows which encoding it is so it can convert at all, and is 'big enough' to bother with encoding back and forth, and the encoding doesn't already provide what one needs such abstraction to do. > You can then reduce the points where data in limited i. e. > non-unicode encodings is imported/exported as the adoption of unicode grows > without affecting the core of your app. IMHO chr(ord("a") - 32) is inferior > to "a".upper() even in an all-ascii environment. If you mean 'limited' to some other character set than Unicode, that's not much use if the appliation is designed for something which has that 'limited' character set/encoding anyway. >>> Here we disagree. Showing the right image for a character should be >>> the job of the OS and should safely work cross-platform. >> >> Yes. What of it? > > I don't understand the question. I explained that in the next paragraph: >> Programs that show text still need to know which character set the >> source text has, so it can pass the OS the text it expects, or send a >> charset directive to the OS, or whatever. If you disagree with that, is that because you think of Unicode as The One True Character Set which everything can assume is in use if not otherwise specified? That's a long way from the world I'm living in. Besides, even if you have 'everything is Unicode', that still doesn't necessarily mean UTF-8. It could be UCS-4, or whatever. Unicode or no, displaying a character does involve telling the OS what encoding is in use. Or not telling it and trusting the application to handle it, which is again what's being done outside the Unicode world. >>> Why shouldn't I be able to store a file with a greek or chinese name? >> >> If you want an OS that allows that, get an OS which allows that. > > That was not the point. I was trying to say that the usefulness of a > standard grows with its adoption. And the thing about standards is that there are so many of them to choose from. Enforcing a standard somewhere in an environment where that is not the standard is not useful. Try the standard of driving on the right side of the road in a country where everyone else drives on the left side. Standards are supposed to serve us, it's not we who are supposed to server standards. >>> I wasn't able to quote Martin's >>> surname correctly for the Python-URL. That's a mess that should be >>> cleaned up once per OS rather than once per user. I don't see how that >>> can happen without unicode (only). Even NASA blunders when they have to >>> deal with meters and inches. >> >> Yes, there are many non-'global' applications too where Unicode is >> desirable. What of it? > > I don't understand the question. You claimed one non-global application where Unicode would have been good, as an argument that there are no non-global application where Unicode would not be good. >> Just because you want Unicode, why shouldn't I be allowed to use >> other charcater encodings in cases where they are more practical? > > Again, my contention is that once the use of unicode has reached the tipping > point you will encounter no cases where other encodings are more practical. So because you are fond of Unicode, you want to force a quick transition on everyone else and leave us to deal with the troubles of the transition, even in cases where things worked perfectly fine without Unicode. But I'm pretty sure that "tipping point" where no cases of non-Unicode is no practical is pretty close to 100% usage of Unicode around the world. >> For example, if one uses character set ns_4551-1 - ASCII with {|}[\] >> replaced with ??????, sorting by simple byte ordering will sort text >> correctly. Unicode text _can't_ be sorted correctly, because of >> characters like '?': Swedish '?' should match Norwegian '?' and sort >> with that, while German '?' should not match '?' and sorts with 'o'. > > Why not sort depending on the locale instead of ordinal values of the > bytes/characters? I'm in Norway. Both Swedes and Germans are foreigners. >>>> In any case, a language's both short-term and long-term goals should be >>>> to support current programming, not programming like it 'should be done' >>>> some day in the future. > > At some point you have to ask yourself whether the dirty tricks that work > depending on the country you live in, its current orthography and the > current state of your favourite programming language do save you some time > at so many places in your program that one centralized api that does it > right is more efficient even today. Just that you are fond of Unicode and think that's the Right Solution to everything, doesn't make other ways of doing things a dirty trick. As for dirty tricks, that's exactly what such premature standardization leads to, and one reason I don't like it. Like Perl and Emacs which have decided that if they don't know which character set is in use, then it's the character set of the current locale (if they can deduce it) - even though they have no idea if the data they are processing have anything to do with the current locale. I wrote a long rant addressed to the wrong person about that recently; please read article in the 'PEP 263 status check' thread. >>> If I were to add a switch to Python's >>> string handling it would be "all-unicode". >> >> Meaning what? > > All strings are unicode by default. If you need byte sequences instead of > character sequences you would have to provide a b-prefixed string. I've been wondering about something like that myself, but it still requires the program to be told which character set is in use so it can convert back and forth between that and Unicode. To get that right, Python would need to tag I/O streams and other stuff with their character set/encoding. And either Python would have to guess when it didn't know (like looking at the locale's name), or if it didn't programmers would guess to get rid of the annoyance of encoding exceptions cropping up everywhere. Then at a later date we'd have to clean up all the code with the bogus guesses, so the problem would really just have been transformed to another problem... -- Hallvard From kjetilho at yksi.ifi.uio.no Fri Aug 27 21:20:13 2004 From: kjetilho at yksi.ifi.uio.no (Kjetil Torgrim Homme) Date: Sat, 28 Aug 2004 03:20:13 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> <87hdqok9i6.fsf@sinken.local.csis.hku.hk> <1rfz68ely9.fsf@rovereto.ifi.uio.no> <876574k7du.fsf@sinken.local.csis.hku.hk> <1r3c28ejis.fsf@rovereto.ifi.uio.no> Message-ID: <1rllg0cb3m.fsf@rovereto.ifi.uio.no> [Paul McGuire]: > > As far as Python goes, I think bracelessness is one of its > defining features; if some day braces were to get included in > Python a la C or Java, then it will cease to be Python. I find this attitude a little defensive. Python has much more to offer than just strict indentation. although it's probably the feature you notice first, it's not enough to make Python a superior language. after all, code in _any_ language written by a professional will have strict indentation. so it's just syntax. the true strengths of Python include its exception system, its class model and instrospection. it's a very flexible language, you can construct classes on the fly, implement your own private attributes etc. etc. combine this with a comprehensive library for doing many common tasks, and you'll see the strength of Python, a strength no other scripting language offers. (I have to point out that my braces suggestion is _not_ a la C or Java, since strict indentation is still required for every line of code in the program.) -- Kjetil T. From aaronb at jhcs.co.uk Mon Aug 9 15:32:36 2004 From: aaronb at jhcs.co.uk (Aaron Barclay) Date: Mon, 09 Aug 2004 20:32:36 +0100 Subject: os.system prob Message-ID: <4117D154.9040300@jhcs.co.uk> Hello, I am trying to send some commands via os.system but am getting tripped up by it stripping out the quote marks. I have: program = "dcop klipper klipper setClipboardContents " fileOut = '"test = FileOut(0, "/bobbleheads/shots/bh112_01/roto_neck/ramin/renders/test", "Auto");"' The fileOut string must be enclosed with "'s and also contains several "'s. So I put them togeter command = program + fileOut os.system(command) My clipboard then contains test = FileOut(0, /bobbleheads/shots/bh112_01/roto_neck/ramin/renders/test, Auto); all of the " have been stripped out. I need it to contain "test = FileOut(0, "/bobbleheads/shots/bh112_01/roto_neck/ramin/renders/test", "Auto");" any ideas?? ps - this may only work under KDE. If there are python specific commands to put things in the clip board I can't find them?? Thanks in advance. From sholden at flexal.cs.usyd.edu.au Sat Aug 7 08:28:58 2004 From: sholden at flexal.cs.usyd.edu.au (Sam Holden) Date: 7 Aug 2004 12:28:58 GMT Subject: Paul Graham on Python hackers References: Message-ID: On Sat, 07 Aug 2004 12:51:17 +0200, Zoltan Sekeres wrote: > On Fri, 06 Aug 2004 22:23:59 -0700, ellisjb wrote: >> (In all seriousness I think python and java have a lot more in common than >> python and perl.) > > This a flamebait, right? Otherwise I would be interested in the features > which make Python similar to Java (shudder). Magical @ symbols? :) -- Sam Holden From listserver at tdw.net Fri Aug 20 14:11:38 2004 From: listserver at tdw.net (Tim Williams) Date: Fri, 20 Aug 2004 19:11:38 +0100 Subject: Removing Email attachments References: <3A81C87DC164034AA4E2DDFE11D258E3022E14@exchange.hqamor.amorhq.net> Message-ID: <024e01c486e1$235604e0$506b81c2@twilliams> On Thu, 19 Aug 2004 15:17:11 +0100, Tim Williams wrote: > > I need to take an email with none or more attachments, remove attachments > with certain file extensions and then send the remaining email onwards. > > The problem is that I can't find out how to remove single attachements, (I > can add new ones and/or remove all) . > > Am I missing something, or do I have to create a new email object from the > remaining bits of the old one ? > > (I *have* googled) > > TIA Easier than I thought :-) here's a successful test I tried with the surrounding code removed. It needs needs a bit of error handling in real use, but not much. emailobj = email.message_from_string(message_string) def removeAttach(emailobj): if not emailobj.is_multipart(): return new_payload = [] removed = [] old_payload = emailobj.get_payload() ext_list = ['ade', 'adp', 'pp', 'asx'] for x in range(len(old_payload)): filename = old_payload[x].get_filename() if filename: ext = filename.split('.')[-1].lower() if not filename or not ext in ext_list : new_payload.append(old_payload[x]) else: removed.append(filename) if removed: emailobj.set_payload(new_payload) From martindemello at yahoo.com Wed Aug 25 15:30:14 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Wed, 25 Aug 2004 19:30:14 GMT Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> Message-ID: Dave Opstad wrote: > > But isn't the fact that the list is modified in place incidental to the > fact of sorting? One is an implementation detail, and the other is the > semantic meaning you're trying to express. Nope, especially since objects are passed by reference. > In my opinion, it would make more sense to have: > > [1, 3, 4, 2].sort() return [1, 2, 3, 4] > (1, 3, 4, 2).sort() return (1, 2, 3, 4) > '1342'.sort() return '1234' > > and so on. As it is, we have sort working on lists but not on immutable > sequences, which is inconvenient at times. This again would be a difference between sort() and sorted(). My main point is that returning None is pretty useless - it 'wastes' the return value, and doesn't allow method chaining. Returning self allows you to either use or discard the return value depending on whether you're interested in it, whereas using None doesn't give you any choice. martin From atterdan at yahoo.com Tue Aug 31 23:55:36 2004 From: atterdan at yahoo.com (John Doe) Date: Wed, 01 Sep 2004 03:55:36 GMT Subject: mbox mail handling Message-ID: I'm looking for some help to: access a /var/spool/mail/userbox, which should have 5 or more messages. parse each message into mhlib.Message format. So I can pull docs and pictures out of each mail message. Anybody got a suggestion, two or three? From kfarmer at thuban.org Mon Aug 23 18:52:33 2004 From: kfarmer at thuban.org (Keith Farmer) Date: 23 Aug 2004 15:52:33 -0700 Subject: advice for perl expert wanting to learn python References: Message-ID: <6d668d6.0408231452.44e2d14f@posting.google.com> David Fraser wrote in message news:... > Zeljko Vrba wrote: > > And most important thing, how does Python deal with database connectivity? > > Is there a single API (akin to DBI) for connecting to databases? > I have used Oracle, SQLServer and Access via ADO - try adodpapi.sf.net > which is a wrapper for ADO to the Python DB-API. > But note that you may well not be able to use any of this database stuff > from IronPython Assuming you find yourself working with .NET -- as you would with IronPython -- I would expect it to have access to the stock database namespaces under whatever environment you're in: under MS's implementation of .NET, System.Data.* (same under Mono?). This would be the most likely line, since there's a lot of prior work in .NET that targets that namespace, including UI controls. For documentation, search for "ADO.NET". It's actually a pretty good framework, and doesn't require a database connection to make use of it (ie, you want an in-memory database, but don't need persistent storage). I don't know what Jim's planning to do with the Python db api, but between the two, I'd personally use ADO.NET when available. I'd suggest the IronPython email list (www.ironpython.org) for more information. From h.b.furuseth at usit.uio.no Tue Aug 31 18:01:29 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 01 Sep 2004 00:01:29 +0200 Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Paul Morrow wrote: >Hallvard B Furuseth wrote: >>Paul Morrow wrote: >>> >>>I believe that we should think of assignments to __xxx__ attributes as >>>not being part of the function's body, but instead part of its >>>declaration, just as we do with its docstring. >>> >>> def circum(diameter): >>> """This describe's foo.""" >>> __author__ = 'Paul Morrow' >>> __version__ = '0.1' >>> __features__ = synchronized, memoized >> >> >> I really, really don't like this idea. Assignment in Python has quite >> enough pitfalls already. Please don't make it worse. If it looks like >> an assignment to a local variable, it should be an assignment to a local >> variable. > > Actually, these look like assignments to local *magic* variables. > There's the difference. No, that's not the difference. It's still different from how magic variables behave in all other places. (Class bodies, module bodies, object attributes). The difference is that magic variables in this particular localtion is actually parsed differently from use of variables other places, so the '=' operator (and what other operators?) means something else. > The double underscores before and after each name loudly proclaims > that these variables are not like 'normal' variables. They're special > in some way. No other magic variables are that special. They all behave normally _as variables_. Other parts of Python react to them being set or reset, the very variable assigments are quite normal. Except for the name mangling of __*__ instance variables, but that is a lot smaller exception than changing the namespace of the assignment operator and the time at which that operator is executed. >> If we are going to invent a syntax for declaring function >> attributes inside the function, why confuse the issue by making it look >> like it does something else? > > Because 1) adding new syntax should be resisted as much as possible > (IMO), If one can extend old syntax in an intuitive way, it's fine to reuse old syntax. When you extend old syntax to mean something counterintuitive, it's far better to find a new syntax. And while it may seem intuitive to you, you may have noticed that it seems counterintuitive to a lot of others. > and 2) this style has parallels in both class definitions and > module definitions. It parallels them as long as you don't think of how it works. Once you do think of how it works, it's completely different. And you get a lot of subtle differences to confuse the issue. > Compare this class statement with the function def > above. > > class Oval(Circle): > """This describe's Oval.""" > __author__ = 'Paul Morrow' > __version__ = '0.1' > __metaclass__ = M Yes, I can compare that. It's fine in a class body, which is executed when the class definition is executed. When I see it in a function definition, I see a strange use of the assignment operator, which is normally a 'run-time' operator, in a place where it not being executed at run-time. You keep displaying such examples as if they should make your point self-evident. Already several people have pointed out that they don't see it at self-evident. That might give you a clue that it isn't self-evident. >> It's true that it makes it look more like what __*__ attribute >> assignment in class bodies does, but the simple fact is that class >> bodies are executed when the class statement is executed, and function >> bodies are not executed when the def statement is executed. Now you >> want part of the function bodies to be executed at def time, and part at >> call time. > > Maybe we just need to be clear as to which lines under the def statement > constitute the function's /body/. That's perfectly clear without your change. Your change is confusing the issue, by also using an operator which one (well, at least many of us - not you, obviously) expects to be executed in the function body. > The function's docstring gets > assigned during processing of the def statement, therefore the docstring > is apparently not part of the function body; The function's doc string doesn't look like a statement, and even if it one thinks it is one (which documentation handling somehow picks out specially) it would be a no-op inside the function, so there is nothing confusing about it. BTW, I was all for having the function body extend further down - my first decorator choice (before J2) would have been the def foo(...): ...decorators and doc string... some_keyword: ...body... syntax. Like you point out about __*__ assigments it stands out, but it's even clearer, but it doesn't look like it would normally dosomething else, so the uninitiated will have far less reason to wonder what kind of voodoo is going on to make it do what it does. > So why not have assignments to __xxx__ > variables also be part of the function's declaration. Because it looks confusing. > The distinctive appearance of these names helps remind us that they > have special semantics. And if we use another syntax, we won't need to be reminded about anything, and there is nothing to be confused about. >> __*__ assigments in class bodies can look a little confusing if you >> don't think of how class declarations work, but it's perfectly simple >> once you think of how they do work: (...) > > Perhaps its just my experience with declarative programming languages, > but I prefer thinking of __xxx__ assignments in a class as setting > 'properties' of the class. (...) I prefer to try to think a bit like the language I'm using does. At least for me it makes it far easier to keep things straight. -- Hallvard From aleaxit at yahoo.com Sat Aug 28 05:52:09 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 28 Aug 2004 11:52:09 +0200 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <7xzn4gwgea.fsf@ruckus.brouhaha.com> <1gj7a1o.1a5d2q410jsn2kN%aleaxit@yahoo.com> <7xisb4xnh5.fsf@ruckus.brouhaha.com> <1gj7c1a.tfdm14p3hclcN%aleaxit@yahoo.com> <7xd61benm9.fsf@ruckus.brouhaha.com> <1gj82n3.1ylkr3nierngmN%aleaxit@yahoo.com> Message-ID: <1gj8848.1bouuroizku25N%aleaxit@yahoo.com> Benjamin Niemann wrote: ... > Isn't the purpose of signatures that the importing program can trust the > module? If it's implemented as you suggest, an attacker could just > inject path to an unsigned module into PYTHONPATH to fool a program. How If the attacker is able to alter sys.path then it does not matter whether zipfiles are even considered -- the attacker could simply position a .pyc file early on the path. > about something like > > require_signature('mymodule') > import mymodule This could be made to work, but only if _every_ module was so checked before importing it; otherwise, even just one unchecked module could easily subvert __import__ or other aspects of the import hook mechanism. So, if you're considering this approach, it makes more sense to switch on module checking globally in an early phase of Python's startup (because Python starts importing modules pretty early indeed). New conventions will also be needed for signature of .py, .pyc, .pyo, and .so (or other binary DLLoid files containing Python extensions). It appears to me that this is a project of orders of magnitude more work than the original idea, which didn't assume the attacker could freely alter sys.path, and protected only against altered or replaced zipfiles specifically -- presumably files that have been legitimately placed on the path by authorized agents. > > or > > import mymodule > verify_module(mymodule) Too late:'import mymodule' runs code in mymodule, shutting the barn door after mymodule has tramped all over your system is little use. > > Another question is, where to place (require|verify)_signature() (that > could also take a CA key (or list of) as optional argument to only allow > modules signed by this CA). It must not be imported from an untrusted > module. > The whole signing thing probably make only sense, if python and it's > stdlib can be trusted (=signed). The stdlib Python (.pyc) parts could be moved into a .jar (signed) just as easily as into a .zip (unsigned). The EXE and DLL's involved may be quite a problem, though, since for those you're in the hands of the operating system -- what could Python itself possibly do to stop an altered Python.Exe from running?! > > Or am I missing other useful applications of signed archives? Remote distribution of code. My program's startup checks if an updated version of foobar.jar purports to be available, and if so downloads it and places it where the previous version used to be. Admittedly, in this case, checking once and for all right after the download might work better than checking after each and every import. (Not sure why but this reminds me of the old 'end to end approach' issue;-). Unfortunately, Python currently doesn't have a working 'sandbox' mechanism where code might run in a resricted way if it hadn't passed all needed checks. This lack, among other things, may certainly lessen the usefulness of checks performed at (or, rather, just before) import time. Alex From arambo314 at hotmail.com Tue Aug 17 12:30:21 2004 From: arambo314 at hotmail.com (Arthur Rambo) Date: 17 Aug 2004 09:30:21 -0700 Subject: Best programming language References: <873c2ndizt.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Message-ID: <533e1e03.0408170830.1b73dc3@posting.google.com> There is no such thing as a "best programming language" of course. It depends on your goals. But yes, Ruby, Python and Scheme are very good at many things, and especially (as mentioned recently by Paul Graham) at hacking and doing conceptually complex things (as most dynamic languages). Arthur > Roman Suzi writes: > > > On Mon, 16 Aug 2004, lopex wrote: > > > > >Roman Suzi wrote: > > > > > >> ;-) > > >> > > >> Just type into google > > >> "best programming language" > > >> and press (I am lucky) > > > > > >Ruby ? > > > > This probably indicates that Python in not well enough described as "best" > > for certain domains while Ruby isn't as humble ;-) > > > > > the best language is of course Scheme > > Klaus Schilling From CarolCarrot at sofsof.net Tue Aug 17 19:05:41 2004 From: CarolCarrot at sofsof.net (Carol Carrot) Date: Tue, 17 Aug 2004 17:05:41 -0600 Subject: mailman mailing list program References: Message-ID: weekly summary! Wahoo!!!! "Nick Vargish" wrote in message news:m3u0v1y4g2.fsf at tanelorn.bandersnatch.org... > "Carol Carrot" writes: > > > now what is +1 QOTW.supposed to mean? > > Someone just voted for (+1) your statement as a Quote of the Week, > which appears at the start of the weekly summary... > > Nick > > -- > # sigmask || 0.2 || 20030107 || public domain || feed this to a python > print reduce(lambda x,y:x+chr(ord(y)-1),' Ojdl!Wbshjti!=obwAcboefstobudi/psh?') From paolo_veronelli at yahoo.it Thu Aug 12 17:47:48 2004 From: paolo_veronelli at yahoo.it (paolo veronelli) Date: Thu, 12 Aug 2004 23:47:48 +0200 Subject: PEP318 In-Reply-To: References: <20040812090056.00001e31@titan> <7ttmh0t8c3cogtbhhnp1ohqu8b51pda461@4ax.com> Message-ID: On Thu, 12 Aug 2004 14:29:07 -0700, David Eppstein wrote: > In article , > Arthur wrote: > >> >Also, it's not in the Zen of Python, but maybe declarative is better >> >than imperative? >> >> Starting now, I guess. ;) > > Well, I think starting with list comprehensions in place of imperative > append-loops. I don't think there is a clear similarity,in fact I don't have any declarative feeling when I use list comprehension,for me it's a shortcut. With decorators before defs I have a new feeling,but not the good declarative one I have with haskell (which would be nice to melt with). I'm not erudite enough to explain it anyway. Paolino -- ....lotta dura per la verdura From wweston at att.net Sun Aug 22 23:53:15 2004 From: wweston at att.net (wes weston) Date: Mon, 23 Aug 2004 03:53:15 GMT Subject: Making different things equal In-Reply-To: References: Message-ID: M. Clift wrote: > Hi Wes, > > Thanks for looking at this! I appreciate your effort. > > The system works very well, but I want it to see Bob as being the same thing > as Mary. So for example it won't give [Bob, whoever, Mary] as that would be > the same as [Mary, whoever, Mary] or [Bob, whoever, Bob]. > > M > > M, >>> list = ['Bob', 'whoever', 'Mary'] >>> synonyms = ['Bob', 'Mary'] >>> if synonyms[0] in list and synonyms[1] in list: ... print "synonyms" ... synonyms >>> >>> list.remove(synonyms[1]) >>> list ['Bob', 'whoever'] >>> wes From eurleif at ecritters.biz Thu Aug 19 23:04:32 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Thu, 19 Aug 2004 23:04:32 -0400 Subject: html templates In-Reply-To: References: Message-ID: <2ol7s0Fbn8qoU1@uni-berlin.de> Ajay wrote: > i am looking for a framework to create a fast dynamic website. between > using Cheetah and HTMLTemplate which would you recommend? I'm using Cheetah for a project, and I love it. I've never tried HTMLTemplate, though. From Ian.Sparks at etrials.com Wed Aug 18 14:58:55 2004 From: Ian.Sparks at etrials.com (Ian Sparks) Date: Wed, 18 Aug 2004 14:58:55 -0400 Subject: age of Python programmers Message-ID: <41A1CBC76FDECC42B67946519C6677A901915288@pippin.int.etrials.com> > Started programming at about 7 with BBC BASIC IV Ah.. BBC BASIC. What a great machine the old Beeb was. Shame we didn't have python back then, imagine how different life could have been! > -----Original Message----- > From: simo [mailto:simoninusa2001 at yahoo.co.uk] > Sent: Wednesday, August 18, 2004 2:52 PM > To: python-list at python.org > Subject: Re: age of Python programmers > > > 26, been Python'ing for 2 years or so. > > Started programming at about 7 with BBC BASIC IV > -- > http://mail.python.org/mailman/listinfo/python-list > From aranders at insightbb.com Sat Aug 7 13:51:22 2004 From: aranders at insightbb.com (Alan Anderson) Date: 7 Aug 2004 10:51:22 -0700 Subject: RELEASED Python 2.4, alpha 2 References: <411231C8.3020308@interlink.com.au> <2-SdnZCwNs1SwI_cRVn-uQ@powergate.ca> <53449fcb.0408062139.7dbbeb4d@posting.google.com> Message-ID: <53449fcb.0408070951.3f3fae62@posting.google.com> aranders at insightbb.com (Alan Anderson) wrote: > Pardon me for jumping in,... (And pardon me for using a hotel-provided wireless network which was malfunctioning badly last night, causing it to tell me repeatedly that the connection failed when my post had actually gone through. DopDaq qul yIchenmoH QobDI' ghu'.) From deetsNOSPAM at web.de Mon Aug 30 09:44:38 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Mon, 30 Aug 2004 15:44:38 +0200 Subject: Getting other file permissions References: Message-ID: Florian Lindner wrote: > Hello, > on a Unix System I want to get the file permissions for other. How to get > this? Is os.stat("file").st_mode the right way? How to interpret the > output? man 2 stat -- Regards, Diez B. Roggisch From h.b.furuseth at usit.uio.no Mon Aug 2 15:10:00 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 02 Aug 2004 21:10:00 +0200 Subject: __coerce__ vs. new-style classes References: <10gstrc1n27m8e8@news.supernews.com> Message-ID: John Roth wrote: >"Hallvard B Furuseth" wrote in message >news:HBF.20040802t150 at bombur.uio.no... >> Why do new-style classes disable __coerce__()? >> It seems cumbersome to have to write a whole set of methods (e.g. >> __add__, __radd__, etc.) to get the same effect. Is there some way to >> automatically generate those methods, or are we simply not supposed to >> do coercion for some reason? > > I'm mildly confused by your example. __coerce__() > converts the arguements to a common type, and then > presumably requests that type to do the operation. That > type might not be one of the two original types! > > It's not the same thing as the __op__, __rop__ > pair. That simply allows the right object to do the > operation if the left object can't. Yes: >>> class DeferredIntType: ... def __init__(self, fetch, *args, **kwargs): ... def _fetch(): ... v = long(fetch(*args, **kwargs)) ... self.value = lambda: v ... return v ... self.value = _fetch ... def __long__(self): return self.value() ... def __int__(self): return int(self.value()) ... def __str__(self): return str(self.value()) ... def __coerce__(self, other): ... if isinstance(other, (int, long)): ... return type(other)(self.value()), other ... >>> DeferredIntType(len, 'foobar') + 3 9 Can't add two of them without __add__ & co, but can do just about everything else just by writing four small methods. If I do include __add__ & co, they won't all have to coerce the arguments 'by hand', or worry about what to do if they don't know how to add the type of argument they received. Without __coerce__, what should __add__(self, other) do if it doesn't know how to add the arguments, but the other argument might know how? It can't just call other.__radd__(self): That might give up and call __add__ again. In some cases it might help to call coerce() by hand, but I note the ref manual says 'In Python 3.0, coercion will not be supported.'. > The notion of type coercion makes a great deal of sense > in languages such as C, where you have 8 integer types > and 3 float types, but abstracting it out as a separate > operation makes very little sense in Python, where you > have 3 numeric types (int, long and float) and two string > types (normal and unicode). The overhead of doing > coercion as a separate operation simply doesn't make > a lot of sense. Well, I was thinking of types like the above, which emulate numeric types. The case which got me started was one which emulates the DECIMAL (or NUMERIC) SQL type in PgSQL.py. > At least, that's the way I understand it. Section 3.3.8 > (Coercion Rules) of the 2.3 Language Reference gives > the official reasons for moving away from doing coercion > as part of operations. It simply got to complex to > document properly. I noticed that; I hadn't realized it was the argument for disabling coercion completey. -- Hallvard From narshe at gmail.com Sun Aug 1 17:01:03 2004 From: narshe at gmail.com (Josh Close) Date: Sun, 1 Aug 2004 16:01:03 -0500 Subject: language/distro preferences In-Reply-To: References: Message-ID: <4a0cafe2040801140119fdf0ea@mail.gmail.com> Yes, PHP is very annoying that way. -Josh On Sun, 01 Aug 2004 13:42:45 +0200, Pierre-Fr?d?ric Caillaud wrote: > > I use Gentoo. Their portage system is really, really good. Being able to > download and install programs and all their dependencies, using my > compilation options... that makes life so much simpler... > > And about PHP, I hate it. The language is so weak. Nothing is OO. The > libraries are inconsistentand everything is in a big mess, due to the > absence of namespaces. > > I guess this is best illustrated by the following example : > > Python #1: > if char in string: > do stuff > > if item in array: > do stuff > > Python #2: > print mystuff.getsomestuff().getsomeattribute().getname().capitalize() > > PHP #1: > Um, which of the 50 string functions should I use ? (lookup help). > Um, I don't remember, should I put the haystack or the needle first ? It > depends on which function you choose. > Um, does it return false, O, -1, or null on failure ? (It depends on > which function you choose) > Um, what's the function name for an array ? is it find_array or > array_find or in_array or array_has_key ? mmm... what if the key is a > string... is it a different function... mmm > > PHP #2 : > $temp = $mystuff->getsomestuff(); > $temp = $temp->getsomeattribute(); > echo strtocap or somthing( $temp->getname(); ) > > You get it ? > > > > On Fri, 30 Jul 2004 10:15:14 -0500, Josh Close wrote: > > > I saw a question in a PHP list about the differences between php and > > perl, and what the advantages between the two are, but I think I was > > the only person that mentioned anything about python in the > > discussion. > > > > This makes me wonder what the python group things about these other > > languages. > > > > Python vs. Perl. vs. PHP vs. C# (and other .NET languages) vs. Java > > vs. C vs. C++ vs. whatever other language you can think of. > > > > I think python is the king of command line. It's way faster than PHP. > > It's OO and has exceptions which perl doesn't, and PHP supports very > > poorly. > > > > I won't touch Perl with a 10 ft. pole anymore. No need. > > > > PHP I still use for web. Mod_python isn't the easiest language to > > write fast web pages in. > > > > I think Java is just terrible. Very very slow. It has a nice size > > library, but I really don't care :P. > > > > C and C++ are cool, but take a lot longer to develop in. > > > > I actually like C# quite a bit. I think it's good for windows use and > > asp.net. I've seen all the ranting about how much everyone hate's it, > > so I won't say any more. > > > > This brings up the question about linux distributions. Which one and > > why? I use Gentoo and I think there is nothing better. It's way more > > configurable than any other distro. Portage is by far the best package > > management system out there. Gentoo makes administration life so much > > easier. When I've used redhat in the past (not by choice), I've had to > > install most programs by hand because I either couldn't find a stupid > > rpm for it, or there wasn't a new enough version rpm available. Yes, > > they install instantly, but they are not as up to date or > > configurable. I've used suse a little and didn't like it. If I were to > > try any other distro, it would probably be linux from scratch. Gentoo > > has made my life so much better. I could go on and on..... but I > > won't. > > > > Just curious what the python world uses and why. > > > > -Josh > > -- > http://mail.python.org/mailman/listinfo/python-list > From shalabh at cafepy.com Fri Aug 6 18:25:52 2004 From: shalabh at cafepy.com (Shalabh Chaturvedi) Date: Fri, 06 Aug 2004 15:25:52 -0700 Subject: Decorator syntax In-Reply-To: References: <788E231C269961418F38D3E360D1652526CA1A@tndefr-ws00021.tenovis.corp.lan> Message-ID: Christopher T King wrote: > On Thu, 5 Aug 2004, Istvan Albert wrote: > > >>The disagreement is caused by trying to achieve a lot of different >>things with one feature. >> >>Thus the solution that is emerging is to cram everything in >>front of the function definition. > > > Agreed! Exactly! Most of what people seem to want from decorators are > a way to specify function types, do type checking, and give functions > attributes / metadata. As I've said before, these are seperable problems > and should be treated as such. What little left over that can > benefit from general-purpose decoraters will likely not be enough to form > a major use case. > I'd disagree and say Python gets it power from using simple constructs that can be reused in different ways rather than a different construct for each special case. I'd rather look at one place to find everything that's munging a function rather than three different places. -- Shalabh From sholden at holdenweb.com Tue Aug 31 09:16:02 2004 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 31 Aug 2004 09:16:02 -0400 Subject: has_method In-Reply-To: References: Message-ID: <41347A12.6020203@holdenweb.com> Gandalf wrote: > > Hi All! > > Does anyone knows how to tell if an object has a method with a given > name? How can I access that method? > > For attributes, it is easy: > > class A(object): > a = 12 > b = 'Python' > > a = A() > a.__dict__.has_key('a') # True > a.__dict__.has_key('b') # True > a.__dict__.has_key('c') # False > > But it won't work for methods. Thanks in advance. > > Laci 2.0 > > Well, one way is try/except: try: a.someMethod(arg1, arg2) except AttributeError: print "Aarrgghh!" regards Steve From ville at spammers.com Thu Aug 5 17:15:21 2004 From: ville at spammers.com (Ville Vainio) Date: 06 Aug 2004 00:15:21 +0300 Subject: Decorator syntax References: <788E231C269961418F38D3E360D1652526CA1A@tndefr-ws00021.tenovis.corp.lan> Message-ID: >>>>> "Istvan" == Istvan Albert writes: Istvan> And that's the problem. The example and motivation in Istvan> PEP318 are both vague and misleading. The disagreement is Istvan> caused by trying to achieve a lot of different things with Istvan> one feature. Having a separate feature for all the desirable functonality would be pure madness. Having maximum functionality with minimum features is good IMO. -- Ville Vainio http://tinyurl.com/2prnb From nospam at nospam.com Thu Aug 12 18:01:16 2004 From: nospam at nospam.com (3c273) Date: Thu, 12 Aug 2004 15:01:16 -0700 Subject: Pyhton Interpreter Startup time References: Message-ID: "Aahz" wrote in message news:cfgc7t$8fb$1 at panix1.panix.com... > In article , > Christopher T King wrote: *snip* > > > >You can then run the compiled version using 'python my_script.pyc' > >('python my_script.py' will ignore the compiled version). > > That's a Bad Idea. *snip* Hello, I'm pretty new to Python and programming in general but I have done this before. Why is this a bad idea? Also (maybe not the right place to ask, but...), I was thinking of driving up to BayPiggies because I am interested in tonights discussion but it's a long drive and I'm afraid it would be way over my head. Do you get a lot of newbie participants? Thanks for your input. Louis From rho at see.signature.invalid Tue Aug 3 23:02:21 2004 From: rho at see.signature.invalid (Nigel Rowe) Date: Wed, 04 Aug 2004 13:02:21 +1000 Subject: Overhead of (was Reasoning behind) nested scope References: Message-ID: <10h0kducrd2fod3@news.supernews.com> Peter Otten wrote: > Andy Baker wrote: > >> (On a side note is there any way to call a nested function from outside >> the parent? I was kind of expecting nested functions to be addressable >> through dot notation like methods are but I can see why that wouldn't be >> quite right. This might be a better question for the tutor list...) > > When you are nesting functions, you don't get one function sitting inside > another function. Instead, the function creation code of the "inner" > function is executed every time to the effect that you get a new inner > function every time you call the outer one: > >>>> def make(): > ... def f(): return "shoobidoo" > ... return f > ... >>>> f1 = make() >>>> f2 = make() >>>> f1(), f2() > ('shoobidoo', 'shoobidoo') >>>> f1 is f2 > False > > You wouldn't do that in cases like the above, when you get nothing in > return for the extra overhead, but somtimes nesting is useful - because of > the change in the scoping rules you now get readonly-closures: > >>>> def make(s): > ... def f(): return s > ... return f > ... >>>> f1 = make("now") >>>> f2 = make("what") >>>> f1(), f2() > ('now', 'what') > > Peter What work is actually done when the 'nested function creation code of the "inner" function' is executed? Given a quick test:- def outer(): def inner(): pass return inner b1 = outer() b2 = outer() attrs=[a for a in dir(b1) if not a.startswith('_')] for a, a1, a2 in zip(attrs, [getattr(b1,a) for a in attrs], [getattr(b2,a) for a in attrs]): print a, a1 is a2 func_closure True func_code True func_defaults True func_dict True func_doc True func_globals True func_name True it appears that all the components of the inner function are the same, which just leaves the binding of the code object to 'inner'. Am I missing something, or is the overhead no worse than, say, foo=self.foo, where self.foo is a method? -- Nigel Rowe A pox upon the spammers that make me write my address like.. rho (snail) swiftdsl (stop) com (stop) au From avaeq at avaeq.nl Thu Aug 19 06:04:15 2004 From: avaeq at avaeq.nl (avaeq) Date: Thu, 19 Aug 2004 10:04:15 +0000 (UTC) Subject: age of Python programmers References: Message-ID: Turning 20 in 2 weeks. My first steps in programming were with basic on a 286 machine my dad got me. That didn't really do it for me, so I got myself a Turbo Pascal book. Much later (when we finally got internet) I learned more, started with PHP to build websites (which i still do, for some money to finance my expensive student-life). Then I started to learn Perl, but never got far with that one, because I discovered Python half a year ago. Learned the basics in a day, programmed an IRC-bot that very same day. I love python, and I'm certainly going to continue learning it (: -- avaeq From nzanella at cs.mun.ca Fri Aug 20 13:48:47 2004 From: nzanella at cs.mun.ca (Neil Zanella) Date: 20 Aug 2004 10:48:47 -0700 Subject: PEP 318: Can't we all just get along? References: Message-ID: Paul Morrow wrote in message news:... > Roy Smith wrote: > > > > I never quite understood the point of static methods inside classes. > > When would you ever need to do that, as opposed to just a function in a > > module? In Java's "everything is part of a class" philosophy, it makes > > sense, but in Python? > > It gives us another means of managing namespaces. Rather than having to > create a top-level function in the current (or some other) module, we > can group it with other related functions as a method in a class. This is one reason for using staticmethod. However, as I pointed out, there is another even better reason. It allows you to use the polymorphism feature (as in C++ virtual functions) on class objects without having to create class instances (as would be necessary in C++). For instance, you can have a superclass with 20 staticmethods with default behavior, and 40 subclasses each ovrriding 5 of these staticmethods on average and using the default for the rest. To summarize, here are the two reasons to use staticmethod: 1. You want to group a bunch of functions together. However, as it happens such functions are not useful outside of a given class, so you use staticmethod to place them where they belong. Perhaps you do not have enough such functions to warrant their placement inside a module of its own. 2. You need to use inheritance and polymorphism but you don't need instances, or perhaps you simply need instance independent polymorphism at the class level. Now if anyone wishes to add to the list, you're more than welcome. Regards, Neil From anthonybaxter at gmail.com Sat Aug 28 04:11:46 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 28 Aug 2004 18:11:46 +1000 Subject: Question about references/copies In-Reply-To: References: Message-ID: On Sat, 28 Aug 2004 09:52:36 +0200, Henning Kage wrote: > I'm using Python only for some months now and I'm wondering, whether such > assignments as above are creating bitwise copies of an object or just > recieve a reference. That means I wanted to know, wheter Python in general > differs between references and copies: It's all references. If you want a copy, use the copy module. > class someclass: > def __init__( self, otherobject): > self.someattribute = otherobject > > And my second question is, whether I should use a cast in such cases or > not (I know, a cast isn't mandatory here...) A cast? Python has no static typing, so I'm unsure how or why you'd do a cast. From David.Vaughan at Gifford.UK.com Fri Aug 20 07:48:41 2004 From: David.Vaughan at Gifford.UK.com (David Vaughan) Date: Fri, 20 Aug 2004 12:48:41 +0100 Subject: Alternative decorator syntax decision Message-ID: My vote is: J2 J2 F (but, again, maybe a different keyword for J2?) David Vaughan From ptmcg at austin.rr._bogus_.com Sat Aug 21 15:38:31 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Sat, 21 Aug 2004 19:38:31 GMT Subject: Parsing C header files with python References: <873c2gzftf.fsf@emit.demon.co.uk> Message-ID: "Ian McConnell" wrote in message news:873c2gzftf.fsf at emit.demon.co.uk... > I've got a header file which lists a whole load of C functions of the form > > int func1(float *arr, int len, double arg1); > int func2(float **arr, float *arr2, int len, double arg1, double arg2); > > It's a numerical library so all functions return an int and accept varying > combinations of float pointers, ints and doubles. > If regexp's give you pause, try this pyparsing example. It makes heavy use of setting results names, so that the parsed tokens can be easily retrieved from the results as if they were named attributes. Download pyparsing at http://pyparsing.sourceforge.net. -- Paul ------------------------ from pyparsing import * testdata = """ int func1(float *arr, int len, double arg1); int func2(float **arr, float *arr2, int len, double arg1, double arg2); """ ident = Word(alphas, alphanums + "_") vartype = Combine( oneOf("float double int") + Optional(Word("*")), adjacent = False) arglist = delimitedList( Group(vartype.setResultsName("type") + ident.setResultsName("name")) ) functionCall = Literal("int") + ident.setResultsName("name") + \ "(" + arglist.setResultsName("args") + ")" + ";" for fn,s,e in functionCall.scanString(testdata): print fn.name for a in fn.args: print " -", a.type, a.name ------------------------ gives the following output: func1 - float* arr - int len - double arg1 func2 - float** arr - float* arr2 - int len - double arg1 - double arg2 From h.b.furuseth at usit.uio.no Fri Aug 6 06:09:44 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 06 Aug 2004 12:09:44 +0200 Subject: Proposal: require 7-bit source str's References: <4112AC7B.1060508@v.loewis.de> <411343D7.3020604@v.loewis.de> <411353A3.8090502@v.loewis.de> Message-ID: Martin v. L?wis wrote: >Hallvard B Furuseth wrote: >>>The coding declaration was only acceptable because >>>- a statement would have to go before the doc string, in >>> which case it would not have been a docstring anymore, and >> >> >> Hmm... > > You misunderstood. I was talking about the module docstring > > "Written by Martin v. L?wis" So if the file has -*- coding: iso-8859-1 -*-, how does that doc string look to someone using a iso-8859-2 locale? I would think such doc strings should be u"""...""" strings. (After the help function is fixed:-) > directive encoding "utf-8" > "Written by Martin v. L?wis" > > Here, the string is not a docstring anymore, because it is > not the first expression in the module. Just like a str7bit directive, in whatever form, would not catch the missing u in front of the doc string. >> Still, how about 'directive str7bit', 'directive -W::str7bitWarning' or >> something? > > See PEP 244. I would have liked a directive statement, but the PEP was > rejected (in favour of __future__ imports, at that time). > > A future import might work, except that this is a commitment that > the future comes some day, which, for str7bit, would not be the case: > there will *always* be a possibility to put non-ASCII bytes into 8-bit > strings Yup. > (of course, requiring that people use escape sequences for > them might be acceptable). Argh! Please, no. > In any case, you probably have to write a PEP for this. I will. -- Hallvard From davidf at sjsoft.com Fri Aug 20 10:39:45 2004 From: davidf at sjsoft.com (David Fraser) Date: Fri, 20 Aug 2004 16:39:45 +0200 Subject: Newbie to XML in Python In-Reply-To: References: Message-ID: Jens Thiede wrote: > XML in Python doesn't seem easy or intuitive. All I need to do, is to > interpret a small piece of XML in which I store data for the contents of > an autorun menu. What is the quickest/most effective way to do this? > > What should I use for this; SAX or DOM - and which parser of ether one, > or niether (if there is a third option)? > > What are your views, > > Jens. Hi Jens I use elementtree for this. If you want have a look at ooswitchlang in the translate.sourceforge.net cvs - src/translate/tools directory :-) David From paolo_veronelli at yahoo.it Fri Aug 6 06:18:12 2004 From: paolo_veronelli at yahoo.it (paolo veronelli) Date: Fri, 06 Aug 2004 12:18:12 +0200 Subject: RELEASED Python 2.4, alpha 2 In-Reply-To: References: <411231C8.3020308@interlink.com.au> Message-ID: On Fri, 6 Aug 2004 02:04:34 +1000, Anthony Baxter wrote: >> This is a bad joke after all the strong perplexities showed about its >> decorators solution. >> I vote against the "@decorator before function" solution. > > Please feel free to actually provide reasons for not liking @decorators. > > Also - if you think you don't like it - please _try_ _it_ _out_ first. My vote which is nothing really important is only for syntax . 1) I don't want strange looking operators: This is one why I use python like all: readability.Use a keyword like decorated (are they decorations or this is an unfortunate word?) 2) I like things in the right places: What is doing that thing before the def. Def keyword is not only there for the interpreter,is there also for me.Eventually how would I change my editor folding engine ??? Python is nice for tired of uglynesses programmers.I use it for personal meditation ,spending a lot of time in making the code beautiful for my eyes,and when I teach it everybody agrees about the thoughts ,hardly asking what's this symbol or that construct? Linearity is a must for human written code,the only thing will make it reusable by them. -- ....lotta dura per la verdura From anthonybaxter at gmail.com Sat Aug 28 02:29:33 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 28 Aug 2004 16:29:33 +1000 Subject: allowing braces around suites In-Reply-To: References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> Message-ID: On Sat, 28 Aug 2004 02:07:43 GMT, Paul McGuire wrote: > "Kjetil Torgrim Homme" wrote in message > news:mailman.2551.1093656430.5135.python-list at python.org... > > I'll write a PEP, but it will have to wait until next week. thank you > > for your feedback! > > > Kjetil - > > I hate to see you waste the effort. I don't think it's a waste of effort. Once a PEP has been written and rejected, future discussions on the subject can be pointed at the PEP. From robey at slash_dev_slash_random.org Wed Aug 18 17:48:26 2004 From: robey at slash_dev_slash_random.org (Robey Holderith) Date: Wed, 18 Aug 2004 16:48:26 -0500 Subject: Embedding Python in Python References: Message-ID: On Wed, 18 Aug 2004 15:27:50 -0400, Phil Frost wrote: > No. An easy way to escape that is to start one's code with > 'del __builtins__', then python will add the default __builtins__ back > to the namespace. Restricting what arbitrary code can do has been > discussed many, many times, and it seems there is no way to do it short > of reimplementing a python interpretor. Out of curiosity I tried the following in 2.3.4 #------Begin Code import random globalDict = {'__builtins__':random} localDict = {} execfile("test2.py", globalDict, localDict) print globalDict print localDict localDict['move']() #------- End Code Where test2.py looked like this: #---------Begin Code print __builtins__ try: del __builtins__ print 'del worked' except: pass try: exec('del __builtins__') print('exec del worked') except: pass try: import sys print 'Import Worked' except: pass try: f = file('out.tmp','w') f.write('asdfasdf') f.close() print 'File Access Worked' except: pass seed() def move(): print __builtins__ #------ End Code I sure it has a crack in in somewhere, but it doesn't seem to be del __builtins__ . -Robey From DeepBleu at DeepBleu.org Sat Aug 28 09:50:01 2004 From: DeepBleu at DeepBleu.org (DeepBleu) Date: Sat, 28 Aug 2004 13:50:01 GMT Subject: Iteration over Lists and Strings References: Message-ID: Thanks all. From enjoylife_95135 at hotmail.com Sun Aug 15 14:06:46 2004 From: enjoylife_95135 at hotmail.com (enjoylife_95135) Date: 15 Aug 2004 11:06:46 -0700 Subject: compiling python 2.3.4 with command line editing References: <864c2cd6.0408141845.3f50a3d5@posting.google.com> <411f37bf$0$13058$9b622d9e@news.freenet.de> Message-ID: <864c2cd6.0408151006.135826b6@posting.google.com> Got it. As it turned out, I needed the readline-dev package *and* the termcap-dev package. But command-line history works now, and I am warm and happy. Thanks! S "Martin v. L?wis" wrote in message news:<411f37bf$0$13058$9b622d9e at news.freenet.de>... > enjoylife_95135 wrote: > > I need to upgrade, so I downloaded and compiled Python 2.3.4. Very > > cool, spiffy etc, but the interpreter doesn't allow for command line > > editing, i.e. I can't type and go to the previous command. > > > > How do I enable that? > > Make sure the readline module is built. For that, you need to install > the readline header files, which are probably in the readline-dev > package. > > Regards, > Martin From python.noob at gmx.de Fri Aug 6 06:26:32 2004 From: python.noob at gmx.de (Steffen) Date: Fri, 06 Aug 2004 12:26:32 +0200 Subject: (no subject) Message-ID: Hi there, my problem: i have a directory, where several python modules (classes) are stored. The names of these modules arent known before runtime. Now i want to parse the Directory and create an instance of each class. I tried to handle this with new.instance() and new.clasobj() but this didnt really work for me. Any Ideas ? From elbertlev at hotmail.com Sun Aug 22 18:27:07 2004 From: elbertlev at hotmail.com (Elbert Lev) Date: 22 Aug 2004 15:27:07 -0700 Subject: 2 GB files Message-ID: <9418be08.0408221427.182a4d30@posting.google.com> >From postings to this group and other resources I understood that the only way to make Python programs to work correctly with files lager then 2 GB is building Python interpreter with some "magic spell" defines. For me this is ABSOLUTELY unacceptable (Not the building, but distributing and installing on dozens of computers in my organisation). Then every time we switch to a new release of Python this has to be repeated over and over! I believe, that automatic 64 bit support (large files) can and should be included in standard library (on platforms which support this feature). From David.Vaughan at Gifford.UK.com Fri Aug 13 12:09:18 2004 From: David.Vaughan at Gifford.UK.com (David Vaughan) Date: Fri, 13 Aug 2004 17:09:18 +0100 Subject: decorator syntax polling suggestion Message-ID: Steven Bethard wrote: > What I'm really interested in here is trying to build a consensus among the > dissatisfied people. If you scan the list right now, you can see that there > are a hundred people going in a hundred directions. Sounds like what we need is a transferable multiple vote system - see http://www.wordiq.com/definition/Coombs%27_method That way, the poll-winner was voted either for or against by each person who cared about it. This would firstly present a fun Python project writing on the on-line voting form and results-processor (any volunteers?), and would also keep everyone amused while they work out how the voting works and then how to rank all the proposals, giving my inbox a welcome respite :-) David P.S. FWIW, I'm a J2 person - very elegant. David Vaughan Structural Analyst for Gifford _____ GIFFORD AND PARTNERS LTD Carlton House, Ringwood Road, Woodlands, Southampton, SO40 7HT, UNITED KINGDOM Tel: +44 (0)23 8081 7500 Fax: +44 (0)23 8081 7600 Email: David.Vaughan at gifford.uk.com Web: http://www.gifford.uk.com _____ This e-mail and any files transmitted with it are intended solely for the use of the individual or entity to whom they are addressed and may be confidential. If you are not the intended recipient or the person responsible for delivering the e-mail to the intended recipient, be advised that you have received this e-mail in error and that any use, dissemination, forwarding, printing or copying of this e-mail is strictly prohibited. From lbates at swamisoft.com Fri Aug 6 17:07:56 2004 From: lbates at swamisoft.com (Larry Bates) Date: Fri, 6 Aug 2004 16:07:56 -0500 Subject: Extending python. References: Message-ID: Is the C that you wish to call located in a .DLL? If so, I can possibly help. Larry Bates Syscon, Inc. "Grzegorz Dostatni" wrote in message news:Pine.LNX.4.44.0408061307140.8941-100000 at e5-05.ee.ualberta.ca... > > Followup. > > Thanks, I'll re-read this again. > > Small change. I've managed to extend python with a small module (just > using the .o file) under Linux. It appears that my problems are a bit more > windows centric. Anyone willing and able to help me with that? > > Greg > > "In theory, there is no difference between theory and practice. > But, in practice, there is." > - Jan L.A. van de Snepscheut > > > On Fri, 6 Aug 2004, Batista, Facundo wrote: > > > Maybe this will help you: > > > > http://www.python.org/doc/faq/extending.html > > > > . Facundo > > > > #- -----Mensaje original----- > > #- De: Grzegorz Dostatni [mailto:grzegorz at ee.ualberta.ca] > > #- Enviado el: Viernes, 06 de Agosto de 2004 13:35 > > #- Para: python-list at python.org > > #- Asunto: Extending python. > > #- > > #- > > #- > > #- Cheers. > > #- > > #- More questions. > > #- Let's say I'm trying to extend python with a c module. That > > #- module cannot > > #- be dynamically loaded (for reasons outside my control). I > > #- have to create a > > #- custom python executable (or more likely custom python library). > > #- How would I do that? Is there documentation on that > > #- somewhere? Most of > > #- what I've seen was for dynamic loading. > > #- > > #- 2nd Step: > > #- Let's say I'm doing it under windows, using Visual Studio. Is there > > #- anything I have to be aware of? > > #- > > #- 3rd Step: > > #- Let's say I don't have the source available. I do have the > > #- object files, > > #- the resulting libraries and the header files though. > > #- > > #- Greg > > #- > > #- "The optimist proclaims that we live in the best of all > > #- possible worlds, > > #- and the pessimist fears this is true." > > #- - James Branch Cabell > > #- > > #- > > #- -- > > #- http://mail.python.org/mailman/listinfo/python-list > > #- > > > From anthonybaxter at gmail.com Mon Aug 23 00:03:55 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Mon, 23 Aug 2004 14:03:55 +1000 Subject: J2 proposal: keyword In-Reply-To: References: Message-ID: On Mon, 23 Aug 2004 00:23:32 +0100 (BST), Michael Sparks wrote: > I discovered this after replacing "decorate" with "using" and > rerunning the test suite... Incidentally the syntax also allows > code like this: > > using: > staticmethod synchronised memoise deprecated > def: foo(bar): > "This function foos bars all day long" > pass The pie-decorator syntax was modified shortly after a2 to require one decorator per line. I think for readability's sake, this was a good call, and would urge you to do this in any new syntax. From jjl at pobox.com Wed Aug 11 19:00:40 2004 From: jjl at pobox.com (John J. Lee) Date: 12 Aug 2004 00:00:40 +0100 Subject: loading message thingy References: Message-ID: <87657pqnzb.fsf@pobox.com> "Larry Bates" writes: [...] > Note: Your final code will have syntax highlighting [...] What? John From unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom Sat Aug 7 16:52:56 2004 From: unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom (Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.) Date: Sat, 7 Aug 2004 22:52:56 +0200 Subject: Compiling disutil modules on Windows References: Message-ID: Hi ! Look the message "Building Python 2.4 extensions with the Microsoft Toolkit Compiler" from 17 jul 2004 It's interesting... From h.b.furuseth at usit.uio.no Sun Aug 8 07:30:24 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 08 Aug 2004 13:30:24 +0200 Subject: PEP 263 status check References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> <10h5hgvpafm8a64@news.supernews.com> <41133C76.8040302@v.loewis.de> <10h6rklt3fa1690@news.supernews.com> <41137799.70808@v.loewis.de> <10h724r20kkeqb2@news.supernews.com> <10h7u8m9qknh76e@news.supernews.com> Message-ID: I wrote: >John Roth wrote: >> Rudeness objection to your characteization. > > Sorry, I guess that was a bit over the top. I've just gotten so fed > up with bad charset handling, including over-standardization, over the > years. And as you point out, I misunderstood the scope of your > suggestion. But you have been saying that people should always use > Unicode, and things like that. Sorry again, I seem to have confused you with Peter. I should have gotten a clue when you said "if you want your source to be utf-8, you need to accept the consequences". Not exactly the words of a True Believer in Unicode:-) -- Hallvard From reinhold-birkenfeld-nospam at wolke7.net Wed Aug 11 03:29:26 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Wed, 11 Aug 2004 09:29:26 +0200 Subject: Yet another decorator proposal In-Reply-To: References: Message-ID: <2ntvn1F4mgskU1@uni-berlin.de> Marco Aschwanden wrote: > Here is yet another decorator proposal: > > def sumSequencesLengths(var1, var2): > """Computes something very important. > > __decorators__: > staticmethod I think this is not a great idea, for several reasons: - Decorators are inside the function. I'm not generally against that, but I agree that decorators are something important that, e.g., should not be folded away. - Decorators are "hidden" in a string. This is almost as ugly as the meta-constructs some other languages have, hiding vital information in comments. - The indentation, if it is a crucial part of your proposal, is not clear. Remember that docstrings are strings, and as such have no notion of the current indentation of the function block. Sorry, but if decorators should go into the body, I'm sure they will take such a form: def SomeFunction(param): meta: staticmethod Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From bryanjugglercryptographer at yahoo.com Wed Aug 11 20:36:59 2004 From: bryanjugglercryptographer at yahoo.com (Bryan Olson) Date: 11 Aug 2004 17:36:59 -0700 Subject: rsa implementation question References: <1092200894.4119a9beb1978@www-mail.usyd.edu.au> <5GkSc.124$O72.121@newssvr14.news.prodigy.com> Message-ID: <1a517b5.0408111636.200f675f@posting.google.com> Heiko Wundram wrote: > Am Mittwoch, 11. August 2004 10:21 schrieb Bryan Olson: > > I agree with about half of Heiko Wundram's response. > > Well, with what don't you agree? ;) Well, since you asked: |> RSA (Rivest-Shamir-Adleman encryption) never works in |> "blocks", as there is no notion of blocks in public key |> cryptography, there's only the notion of doing an operation |> on plaintext modulo a large prime n. There is a notion of blocks in many public-key ciphers, including RSA. The modulus n in RSA is composite, not prime. The "only the notion" statement implies that integer modular arithmetic is the only base for public-key cryptography, which is not true. > Anyway, I've not read anywhere that for signing a message it is > discredited to use RSA decrypt with private key, encrypt with > public key. Try the book you cited, section 11.2.3, Note 11.10, Example 11.11, and Remark 11.12. http://www.cacr.math.uwaterloo.ca/hac/ Subsequent to the publishing of HAC, the 'redundancy function' they describe in Section 11.3.5 'ISO/IEC 9796 formatting', fell to a series of attacks, first by J. S. Coron, D. Naccache and J. Stern, then improved and extended by D. Coppersmith, S. Halevi and C. Jutla, and several following works. The other redundancy function they describe is the one for which I presented Python code (for the SHA-1 usage). Don't use it without the hash function. There are now more trustworthy padding methods for RSA signing and encryption, based on the "Exact Security" and "OAEP" papers of Bellare and Rogaway, with arguably interesting follow-ups by Victor Shoup. > Basically, what I always implemented is something like (pseudocode): Don't do that, even for encryption. See Bleichenbacher's attacks on RSA encrpytion: http://www.bell-labs.com/user/bleichen/bib.html [...] > So much for what I always did. I really don't know whether this is some form > of secure way to go, but at least no cryptography book I read has ever > discouraged the use of random padding while encrypting data which is much > shorter than the "block size" of a public-key crypto algorithm (esp. for > RSA). Then I'm guessing I won't see you at Crypto 04 next week ;) -- --Bryan From abra9823 at mail.usyd.edu.au Wed Aug 11 03:17:15 2004 From: abra9823 at mail.usyd.edu.au (Ajay Brar) Date: Wed, 11 Aug 2004 17:17:15 +1000 Subject: rsa implementation question In-Reply-To: <200408110852.57937.heikowu@ceosg.de> References: <1092200894.4119a9beb1978@www-mail.usyd.edu.au> <200408110852.57937.heikowu@ceosg.de> Message-ID: <4119C7FB.1050808@mail.usyd.edu.au> thanks i am using RSa for signing documents and hence decrypting and then encrypting to verify? what i was rather trying to get at was what if the plaintext is too large? if the plaintext is greater than (log2 n)/8, would you just throw an error or would you break the plaintext in parts. the reason i am asking this is because i am timing the sign operations using the pcrypto package. the time is constant relative to the size of the plaintext (as you would expect) but at a certain point there is an increase in the time taken to sign. this corresponds to a very large plaintext. that is why i was wondering about the block thing. Heiko Wundram wrote: >Am Mittwoch, 11. August 2004 07:08 schrieb Ajay: > > >>just like to know how the RSA implementation in the pcrypto package works. >>Does it operate in blocks, if yes, what is the size of the blocks? >> >> > >RSA (Rivest-Shamir-Adleman encryption) never works in "blocks", as there is no >notion of blocks in public key cryptography, there's only the notion of doing >an operation on plaintext modulo a large prime n. > >Now, you could call (log2 n)/8 the block size in bytes of RSA for a certain >encryption prime, but I'd never talk of block sizes with RSA, as normally you >don't use RSA (or public-key cryptography in general) to encrypt plaintext a >block at a time, but rather to encrypt a random string of bytes [len(s) <= >(log2 n)/8 for the modulo prime of the algorithm], which is used as the key >for a normal symmetric encryption algorithm, to which you feed the blocks. > >Thus, the receiver (and also the sender) only has to make one expensive >calculation (retrieving the key from the encrypted RSA packet), whereas >decrypting the cyphertext (or encrypting it) is done using a symmetric >cypher, which has the advantage of being much faster to compute than a >public-key cypher. > >Anyway, if you're interested in how symmetric and/or public-key cryptography >work, read up on: > >http://www.cacr.math.uwaterloo.ca/hac/ > >especially chapters 7 and 8. > >Heiko. > > -- Ajay Brar CS Honours 2004 Smart Internet Technology Research Group http://www.it.usyd.edu.au/~abrar1 From tjreedy at udel.edu Tue Aug 24 01:49:49 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 24 Aug 2004 01:49:49 -0400 Subject: Overriding logical operators? References: <59e9fd3a04082022392b749256@mail.gmail.com> <2ovvrmFcu6r6U1@uni-berlin.de> Message-ID: "Greg Ewing" wrote in message news:2ovvrmFcu6r6U1 at uni-berlin.de... > Terry Reedy wrote: > > I think > > we need a special term in Python also, such as 'pseudo-op' or 'syntax > > operator' to flag 'and' and 'or' as importantly different from regular > > operators. > > They're really control structures, like 'if' and 'while'. > The fact that they happen to look a bit like operators is > purely coincidental... Ok, I'll think of them as 'control words' for now. tjr From john at grulic.org.ar Thu Aug 19 09:54:32 2004 From: john at grulic.org.ar (John Lenton) Date: Thu, 19 Aug 2004 10:54:32 -0300 Subject: speed In-Reply-To: References: Message-ID: <20040819135432.GD3185@grulic.org.ar> On Thu, Aug 19, 2004 at 03:37:26PM +0200, Peter Kleiweg wrote: > > I implemented a lexer in Pylly and compared it to the version I > had written in Flex. Processing 219062 lines took 0.9 seconds in > C (from Flex), and 5 minutes 54 second in Python (from Pylly), a > ratio of 393 to 1. > > Is this normal for Python, or does Flex produce better parsers > than Pylly? I have been looking at the code produced by Flex to > see if I could translate it to Python automaticly. But it has a > lot of goto statements, and I haven't figured out how to > translate those to Python efficiently. flex has an option to generate code without the gotos... -- John Lenton (john at grulic.org.ar) -- Random fortune: Don't read everything you believe. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From michele.simionato at gmail.com Thu Aug 5 06:45:15 2004 From: michele.simionato at gmail.com (Michele Simionato) Date: 5 Aug 2004 03:45:15 -0700 Subject: Confused about pep 318 References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: <4edc17eb.0408050245.49c046e2@posting.google.com> Skip Montanaro wrote in message news:... > There was a lot of discussion on python-dev, but none very recently (last > month or so). Guido indicated there that he brought up the topic at > EuroPython in his keynote talk and entertained discussion from the floor. > Based upon that discussion he decided to go with the @-decorator syntax. > Since EuroPython most/all the discussion went on in private email or on > irc. I think it would be nice if this conversation was summarized in the > PEP, but that will have to come from one of the participants. > > Skip I think the way the decision came up was absolutely unfair to the PEP proponents and to the Python community at large. This disturb me more than the syntax itself (which I don't like, but this not the point). I agree that Guido is the Dictator For Life, but he is supposed to be Benevolent! I-will-never-submit-a-PEP-ly, Michele Simionato From peter at semantico.com Wed Aug 18 10:52:33 2004 From: peter at semantico.com (Peter Hickman) Date: Wed, 18 Aug 2004 15:52:33 +0100 Subject: How big can a Python program be? In-Reply-To: <903b3fba.0408180619.4d41027e@posting.google.com> References: <903b3fba.0408170333.49ce3944@posting.google.com> <412204d5$1$28243$afc38c87@news.easynet.co.uk> <903b3fba.0408180619.4d41027e@posting.google.com> Message-ID: <41236d32$0$8717$afc38c87@news.easynet.co.uk> vronskij at post.sk wrote: > Peter Hickman wrote in message news:<412204d5$1$28243$afc38c87 at news.easynet.co.uk>... >>Are you suggesting that a solo programmer wrote a multi million line C++ >>program? If not then what has this to do with 'How many lines can one handle?' > > No way. This was just another question. One programmer told me that > he > can roughly handle max 10 000 lines in C language. I was curious > about Python. I always hear that Python can be used on larger projects > than e.j. PERL because it is Object Oriented and cleanly designed. > What is a larger project? Mumbers revail more. The problem is that some languages are much more verbose than others, thus a 100 line python program might require 2,000 lines of C or 700 lines of C++ (I'm just making up numbers here). What then counts is the programmers ability to read the source and summarise (oh, that's just creating back orders if we are out of stock). The more verbose the language the more likely they will have a problem comprehending the intent of the code. Imagine trying to comprehend a C program against its assembly equivalent. C is easier to read than assembly and Python is easier to read than C. I suppose languages have a conciseness metric but I would not know how to measure it. On the other hand APL is very short by just as hard to read. Perl is used on some very large projects! The 75,000 lines I mentioned was Perl and I would not count that as a large project. >>The application I am currently working on has 75,000 lines across some 600 >>files. > > This is probably team work. It's helpful for me to know figures. When > you start a project it is useful to know the limitations of a > language. Visual Basic is reported to fail on larger projects. It was created by a team for sure but when an upgrade or fix is required then only one programmer is looking at the whole of the code so they have to handle the entire codebase. A well designed codebase / object hierarchy helps here. As to Basic, the non VB sort, I have worked on financial systems that were written in Vax Basic that were many 1,000s of lines long. The language is not the problem. With VB the problem is that you never really got to work with the code, the IDE was always in the way and the IDE only existed at the program level and not the project. From pm_mon at yahoo.com Tue Aug 31 16:28:20 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Tue, 31 Aug 2004 16:28:20 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Steven Bethard wrote: > Paul Morrow yahoo.com> writes: > >>The assignments to __xxx__ variables (immediately following the >>docstring, if present) would occur in the namespace of the object >>(function/method) being defined. The assignments would not cause them >>to change namespaces. > > > > What you're suggesting is that given: > > def f1(): > __author__ = 'Steve' > > and > > def f2(): > author = 'Steve' > > in f1, the assignment to __author__ occurs in the function's namespace, but in > f2, the assignment to author occurs in the local namespace. Clearly then, the > __xxx__ format (if at the beginning of a function) changes the namespace to > which an assignment applies. How is this not causing assignments to change > namespaces? > def f3(): """I am a docstring.""" __author__ = 'Steve' y = 10 When the interpreter processes a function def, it places the name of the function and its docstring into the namespace of the function being defined. So instead of stopping at the docstring, it would look ahead to see if there were any subsequent " __xxx__ = " statements, and if so, would evaluate them in the same namespace [*]. After the def was finished, the function's namespace would include not only its name and docstring, but an attribute for each __xxx__ assignment as well. Later, when the function is executed, its local, global, and built-in namespaces would be exactly what they are now, except that its local namespace would not include any __xxx__ assignments processed when the def statement was executed. So in f3 above, its local namespace would include 'y' only. Paul [*] The namespace of the function being defined; the same place it put the function's name and docstring. From cjw at sympatico.ca Sat Aug 7 09:32:55 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Sat, 07 Aug 2004 09:32:55 -0400 Subject: Plotting histograms, scatter plots in Python In-Reply-To: References: Message-ID: <7S4Rc.49729$Vm1.1245341@news20.bellglobal.com> Paramjit Oberoi wrote: >>What is the easiest way to generate some plots and graphs in Python ? > > > Pychart: > http://www.hpl.hp.com/personal/Yasushi_Saito/pychart/ The charts look good, but the source code links fail. Colin W. From simoninusa2001 at yahoo.co.uk Fri Aug 13 22:53:40 2004 From: simoninusa2001 at yahoo.co.uk (simo) Date: 13 Aug 2004 19:53:40 -0700 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: <30260531.0408131853.18ec2446@posting.google.com> I'm a Perl programmer at heart - well that and PHP, plus the odd dabbling in C/C++/C# etc. Anyway, the thought of indentation instead of curly braces really put me off to start with, but I tried it, and as soon as I started to write larger programs, it became apparent what a good system it was, plus it forces readable code on you (you wouldn't believe how many PHP programmers I know who don't indent properly). I find when using C# that you really need a big monitor/resolution and an IDE to provide code-folding/split window/brace-matching etc; otherwise you can't find your way around the source, not so with Python - you just need a text editor that can do proper tabbing. Now I write all my desktop apps in Python - I haven't really converted from Perl/PHP for web stuff yet, as the Python DBI is confusing (or confused?!) too many libraries, no standard..... From pm_mon at yahoo.com Sat Aug 21 14:31:15 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sat, 21 Aug 2004 14:31:15 -0400 Subject: __metaclass__ and __author__ are already decorators In-Reply-To: <4127813F.9020707@yahoo.it> References: <4127813F.9020707@yahoo.it> Message-ID: Paolo Veronelli wrote: > > > Paul Morrow wrote: > >> Thinking about decorators, and looking at what we are already doing in >> our Python code, it seems that __metaclass__, __author__, __version__, >> etc. are all examples of decorators. So we already have a decorator >> syntax. What is the compelling reason to invent a new one? And if we >> do, what's to become of the old one? > > > You are right ,if some __xxx__ (only __metaclass__ for now?) class > attributes have deep meanings (not only a syntactical > one(__lt__,__getitem__,....)) ,and many people suggest not to use them > (probably there is something about a non pythonicity of __metaclass__ > in this behaviour) then it would be very nice to match this deepness > against the decorator one ,at least using @ > before class definitions if it's the case.... > > > Thanks for pointing out another unpythonicity. Paolino > Is that what I did? Isn't assigning values to __xxx__ attributes pythonic? I see it all over the place. pydoc uses it. It's how we declare metaclasses. It's how we enable special operators and special behavior. It's how we specify meta information (author, version, credits, etc.). The @ on the other hand... From JSmuts at clover.co.za Wed Aug 25 09:15:58 2004 From: JSmuts at clover.co.za (Jaco Smuts) Date: Wed, 25 Aug 2004 15:15:58 +0200 Subject: Just a quick one In-Reply-To: Message-ID: Hello M >From the python tutorial: "Another useful data type built into Python is the dictionary. Dictionaries are sometimes found in other languages as ``associative memories'' or ``associative arrays''. Unlike sequences, which are indexed by a range of numbers, dictionaries are indexed by keys, which can be any immutable type; strings and numbers can always be keys. Tuples can be used as keys if they contain only strings, numbers, or tuples; if a tuple contains any mutable object either directly or indirectly, it cannot be used as a key. You can't use lists as keys, since lists can be modified in place using their append() and extend() methods, as well as slice and indexed assignments. " I understand this to mean that your code will not work becuase you are using a list (mutable) as a key sounds as though it will work if you change ['Bob','One'] to ('Bob', 'One') I have not tested it, but I suspect that will work jaco "M. Clift" Sent by: python-list-bounces+jsmuts=clover.co.za at python.org 08/25/2004 03:06 PM To: python-list at python.org cc: Subject: Just a quick one Hi, Just a quick one. I'm trying to call [Bob','One'] with this, but I keep getting 'unhashable'. I've tried various ' " and [ and can't get the thing to work. Any offers? Thanks, M from random import * Name_Number = xrange(int(raw_input("Choose number of Names (1-20)? "))) state = [None,None] nextName = {['Bob','One']:['Rita','Sue'],\ 'Rita':['Mary','Sue',['Bob','One']],\ 'Sue':['Rita','Mary',['Bob','One']],\ 'Mary':['Sue','Rita']} Name_List = [] tmp = choice((['Bob','One'],'Rita','Sue','Mary')) for x in Name_Number: print state while tmp in state[0:2]: tmp = choice(nextName[Name_List[-1]]) print tmp, ", ", print print "Name ",x+1," is ", tmp Name_List.append(tmp) state[x%2] = tmp print Name_List -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan at eischet.com Fri Aug 6 13:51:55 2004 From: stefan at eischet.com (Stefan Eischet) Date: Fri, 6 Aug 2004 19:51:55 +0200 Subject: Killing children In-Reply-To: <87smb0w4ln.fsf@debian.laymusic.org> References: <87smb0w4ln.fsf@debian.laymusic.org> Message-ID: <4E0D6359-E7D1-11D8-BDA6-000A95857E5C@eischet.com> Hi Laura, what a terrible subject line! ;-) I sometimes use os.system with pskill from http://www.sysinternals.com/ntw2k/freeware/pskill.shtml - this should do what you want. I do get my pid from some spawn-variant, IIRC. This should be more reliable than killing by name or parsing ps output (since you might kill the wrong process if there are multiple processes with the same name). What exactly doesn't work with your spawning? Could you post the spawn call you're using? Cheers, Stefan On 06.08.2004, at 19:36, Laura Conrad wrote: > > I'm writing an application that has to spawn some processes and then > kill them later. It doesn't need to talk or listen to them while > they're running, but there are stop and start buttons and the stop > button should stop everything that gets started by the start button. > > There are lots of ways to do this on Linux, but this project has to > run under cygwin. So far, the only thing I've gotten to work at all > under cygwin is doing an 'os.system' to start the process and then > parsing the "ps" output and using os.kill on the processes that ps > finds. This is unsatisfactory in a number of ways. > > I have been unable to get os.spawnl to start the processes correctly. > I was using pexpect, which worked fine with test programs, but not > with the actual processes that need to be spawned. I did a little bit > of playing with the "process" module but didn't get it working right. > > Does anyone have a better idea? > -- > Laura (mailto:lconrad at laymusic.org , http://www.laymusic.org/ ) > (617) 661-8097 fax: (501) 641-5011 > 233 Broadway, Cambridge, MA 02139 > > > -- > http://mail.python.org/mailman/listinfo/python-list > > // stefan at eischet.com // From max at alcyone.com Sun Aug 8 02:52:24 2004 From: max at alcyone.com (Erik Max Francis) Date: Sat, 07 Aug 2004 23:52:24 -0700 Subject: elements of decorator syntax suggestions References: <4edc17eb.0408062125.231f7bef@posting.google.com> <41155C33.37EEB397@alcyone.com> <4edc17eb.0408072041.7bfe9eff@posting.google.com> Message-ID: <4115CDA8.1A8AD51D@alcyone.com> Michele Simionato wrote: > 1. @ is already used in Leo and ipython, "|" is not. It's also used in EmPy, but you don't see me complaining. > 2. "|" stands visually more than other characters. @ sure takes up more visual space and is easier to spot in text than |, which is precisely why I used it in EmPy as the token prefix (also because @ at the time is neither commonly used in English text or legal in Python, though the latter will be changing). > 3. Many people have an irrational repulsion for "@" and "$". Evidently! -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ I have not yet begun to right! -- John Paul Jones From timr at probo.com Sun Aug 8 01:16:32 2004 From: timr at probo.com (Tim Roberts) Date: Sat, 07 Aug 2004 22:16:32 -0700 Subject: upper memory limit References: Message-ID: <3hdbh0d3af4gjbj6psec10nahls0u3nuu3@4ax.com> Leandro wrote: >There is an upper memory limit in Python? >I have 2GB RAM and 2 processors Xeon 2.4 - (Windows XP), but I just can use >1.2G of memory, after this python crashes. >Does someone know if python has some memory limit? You might be surprised to learn that the amount of memory available to a single process is (almost) completely unrelated to the amount of physical memory in the machine. Windows is a virtual memory system. A single process in Windows is limited to 2GB of address space. Part of that is occupied by the Python executable, your DLLs, and the system DLLs. 1.2GB seems a litle low, but it is not entirely unreasonable. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From nzanella at cs.mun.ca Wed Aug 18 17:42:03 2004 From: nzanella at cs.mun.ca (Neil Zanella) Date: 18 Aug 2004 14:42:03 -0700 Subject: static class methods and data members Message-ID: Hello, I would like to know whether it is possible to define static class methods and data members in Python (similar to the way it can be done in C++ or Java). These do not seem to be mentioned in "Learning Python" by Mark Lutz and David Ascher. It seems like they are a relatively new feature... It seems to me that any truly OO programming language should support these so I'm sure that Python is no exception, but how can these be defined/implemented in Python? Currently I have Python version 2.3 installed on my system. Thanks, Neil From aleaxit at yahoo.com Fri Aug 27 02:35:43 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 27 Aug 2004 08:35:43 +0200 Subject: Proposal for removing self References: <1gj4sup.hrowbz1bzo06mN%aleaxit@yahoo.com> Message-ID: <1gj64fr.1xs0h091e7wr9oN%aleaxit@yahoo.com> Ravi Teja Bhupatiraju wrote: ... > Aren't you being a bit touchy Alex? Now I am glad that I did not > mention my wish list on properties and DBC :-). However, your post has > been quite informative. So I can live with that. Exactly: far from being "touchy", I have been constructive. Coming back to c.l.py after months of absence, and finding that, as usual, instead of trying to use Python to best effect, people with mediocre Python mastery keep trying to change Python (generally trying to break some of the best aspects of it, because they don't understand enough Python to see why they're good) was of course depressing -- I'm proud of myself for reacting constructively rather than lashing out or going away again at once. > I wish I could rise up to your challenge and do all that stuff. > Regretfully, my Python skills don't extend to metaclasses and > especially "byte code hacking". Maybe you will explain those in your > next edition of the cookbook :-). Bytecodehacks are implementation-specific, and specific to one version of Python (they wouldn't apply to Jython, IronPython, ...), so I'm not going to write about them -- and you don't need to master them to try out one of the changes you want, the __private__ idea. Metaclasses are quite another issue: they are, even conceptually, absolutely fundamental to understanding Python's object model, and if you do not understand the object model, your knowledge of Python is shallow -- FAR too shallow for you to _sensibly_ propose changes to Python, in my opinion. So I did cover metaclasses in "Python in a Nutshell" as well as in dedicated presentations (you can find the presentations' PDFs on the usual site, www.strakt.com) and I will probably select a few metaclass recipes for the second edition of the Cookbook. > That said, I only could find one set of docs that could be called a > on metaclasses. Those were by David Mertz and Michele > Simionato. I could not get through them. I took comfort in the > statement "Metaclasses are deeper magic than 99% of users should ever > worry about" from the document. I am still looking for something I can > understand. At least 99% of users should not propose changes to Python. Many of them would be well served by undersanding metaclasses, even if they never need to write custom metaclasses -- they shouldn't _worry_ about them, since there's nothing to worry about, but understanding and worrying are different things. Which is why I cover metaclasses in books, articles, posts (use google groups to look for my post that mention metaclass, there were quite a few), and presentations. Alex From jjl at pobox.com Fri Aug 27 15:05:08 2004 From: jjl at pobox.com (John J. Lee) Date: 27 Aug 2004 20:05:08 +0100 Subject: cookie References: Message-ID: <87fz68v1uj.fsf@pobox.com> Ajay writes: > Quoting "John J. Lee" : > > Ajay writes: [...] > > > i am printing a simple cookie, but instead of printing > > > um=name:blah&access:admin&exp:2312390.909 > > > > > > its printing > > > um="name:blah&access:admin&exp:2312390.909" > > > > > > why the quotes? > > > > Why not? > > > > I don't see how they'd cause any harm. > > > they dont cause any harm, except for a an extra statement removing those > quotes when i read the cookie, parse it and authenticate the session. > the question is - is that normal cookie behaviour? > cookie["test"]="blah" > print cookie > > prints test=blah and not test="blah" > so why the quotes when i do the same thing, but use a variable instead of a > string literal? You've lost me, but on the basis of a very quick test, the Cookie module preserves quotes across the parse->output cycle: >>> import Cookie >>> c = Cookie.SimpleCookie() >>> c.load('foo=bar') >>> print c Set-Cookie: foo=bar; >>> c.load('foo="bar"') >>> print c Set-Cookie: foo="bar"; >>> That seems sensible behaviour to me, since quotes around cookie values are significant for Netscape cookies (ie. regular, vanilla, internet cookies). I can categorically state that using a variable name instead of a string literal will make no difference whatsoever. I think you're actually confused about Python syntax rather than the workings of the Cookie module. Try reading the Python language tutorial at www.python.org. John From Jeffrey at Fro.man Fri Aug 20 20:29:35 2004 From: Jeffrey at Fro.man (Jeffrey Froman) Date: Fri, 20 Aug 2004 17:29:35 -0700 Subject: decorator J4 - any objections? References: Message-ID: Jim Jewett wrote: > def func(arg1, arg2) > @version("Added in 2.4") > @returns(None) > as: > """Docstring could be here, or in decorator part above""" > # body goes here I like this better than the current proposal because it reads from top to bottom, and flows like a typical conditional. Before function writing the decorators whereas like reads this. Jeffrey From vincent at visualtrans.de Wed Aug 25 15:04:48 2004 From: vincent at visualtrans.de (vincent wehren) Date: Wed, 25 Aug 2004 21:04:48 +0200 Subject: Begginer question about py install In-Reply-To: References: Message-ID: Player wrote: > Also PyWin32 the latest version or build, will not install with the latest > version of python, it requires 2.2 version of python, while the latest v of > python is 2.3. :( > > M.B > > You probably just grabbed the wrong version. Note that build numbers are now the same for all, but for Python 2.3.x you need: http://prdownloads.sourceforge.net/pywin32/pywin32-202.win32-py2.3.exe?download HTH, -- Vincent Wehren From peter at engcorp.com Fri Aug 6 08:33:25 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 06 Aug 2004 08:33:25 -0400 Subject: Trimming a string In-Reply-To: References: <10gsmuieo65du5d@news.supernews.com> <10gsotqjc2qrl54@news.supernews.com> Message-ID: David Fraser wrote: > Double Dumbass on You wrote: >> "wes weston" wrote: >>> >>> x = "0100755" >>> >>> print x[4:] >>> 755 >>> Reading the tutorial is really time well spent. >> >> Do you feel better about yourself for having posted a smug, >> shithead-type answer, troll?? > > Actually your answer was a bit ruder than his And in fact, Wes' response was not in the least bit rude, but rather quite helpful in two important ways: giving the actual answer, and giving advice on how to find answers to similar questions in the future. Braindamagedness notwithstanding, Double Dumbass (appropriately named?) needs to learn to cope with his situation in life and reading the tutorial repeatedly, even, if necessary each time before posting a question, would be a better approach than insulting those who try to help. -Peter From n/a Wed Aug 25 15:11:56 2004 From: n/a (ADE) Date: Wed, 25 Aug 2004 12:11:56 -0700 Subject: Am I on the right path References: Message-ID: <10ipp5jbau4hb06@corp.supernews.com> Nope just a project I wouldn't know how to create a virus worm or spambot I am just learning how to program in python But thanks for your concern as I can see the potential of something like this "Cyrille Lavigne" wrote in message news:cginhf$5ff at odak26.prod.google.com... > Are you trying to make a virus, worm or other spambot? > ___ > Cyrille Lavigne > From simoninusa2001 at yahoo.co.uk Thu Aug 26 14:45:12 2004 From: simoninusa2001 at yahoo.co.uk (Simon John) Date: 26 Aug 2004 11:45:12 -0700 Subject: Mysql in Python? Message-ID: Probably the only thing keeping me with database coding in PHP instead of Python is that it's so unclear what should be used for what! It's a similar thing for templating systems - there's too much choice, and nothing has really become "the standard". I never thought I'd complain about too much choice! Also, PostgreSQL seems to be better supported than MySQL, although good luck finding a web host with PostgreSQL *and* mod_python! I guess anything that uses the DB-API 2 should be used, but MySQLdb says it's out-of-date! There's a list of modules at http://python.org/topics/database/modules.html From jhefferon at smcvt.edu Mon Aug 2 10:53:40 2004 From: jhefferon at smcvt.edu (Jim Hefferon) Date: 2 Aug 2004 07:53:40 -0700 Subject: Module for converting XML to Python object(s)? References: Message-ID: <545cb8c2.0408020653.283b643@posting.google.com> "Robert Oschler" wrote in message news:... > Has anybody seen a Python module that will take an XML document (not a > colossal one), and convert it to a Python nested class object? Perhaps http://www.rexx.com/~dkuhlman/gnosis_generateds.html would help? Jim From cdunscombe at yahoo.com Tue Aug 31 03:57:32 2004 From: cdunscombe at yahoo.com (Chris) Date: 31 Aug 2004 00:57:32 -0700 Subject: Distributing Python applications - McMillan Installer question References: Message-ID: <6f89f4fe.0408302357.26a4c584@posting.google.com> Thanks Simon and Eric for your answers looks like I'll be supplying byte code for *nix but I'll use one of the "freezers" for Windows as Windows users tend to like installation etc. to be as simple as possible. Chris "Simon John" wrote in message news:... > I've built Installer programs on SUSE 9.1 and RedHat9, and they kinda > work across the two platforms - the RH9 one also works on Fedora C1 > (but not RH7.3), and the SUSE one works on Linspire 4.5..... > > I'd say cx_Freeze is not much difference either, except it seems > cleaner than the import hook used in MMI. > > But as far as building on Linux and running on HPUX, no chance, you > might consider Jython/IronPython for that level of portability (or just > supplying source). > > Your other option is using a packing system like Apt, RPM, SunPKG etc. > and bundling Python and all dependencies with your program source (or > hoping that the user already has Python installed). > > The whole *nix distribution issue is very complicated. Even the C++ > guys using Qt at work here have huge issues getting code to work across > HPUX/AIX/Linux/Solaris. From simoninusa2001 at yahoo.co.uk Tue Aug 31 23:32:18 2004 From: simoninusa2001 at yahoo.co.uk (Simon John) Date: 31 Aug 2004 20:32:18 -0700 Subject: XML documentation stinks - help? Message-ID: I'm sure this must be a PEP, but could someone look at the PyXML documentation? I'm trying to evaluate XML on Python (to eventually use it with XML-RPC) as apposed to Perl. The problem is, I can't find a simple demo or documentation that just says how to create a parser object, and call the start/char/end event handlers. With Perl's XML::Parser, it's that simple, you overload a start/char/end handler that gets called for every element, then you just create a hash of the data or whatever you want. Most of the sites I Googled don't even exist anymore or have either incomplete documentation, out-of-date documentation, or have way over-complex examples that don't even explain why their importing modules or what they're doing. Maybe I'm missing something, but even comp.lang.python.* seems to have no topics on XML in the past 3 years or so - has XML been deprecated and I've not heard about it yet?! ;o) I never thought I'd see something that is easy to do in Perl, but seemingly impossible to do in Python, I guess Perl is optimised for text parsing.... From atterdan at yahoo.com Fri Aug 27 14:50:00 2004 From: atterdan at yahoo.com (John Doe) Date: Fri, 27 Aug 2004 18:50:00 GMT Subject: how to change a factory use of rfc822.Message to mhlib.Message Message-ID: I've never used a factory and would like to get some help. The class mailbox.UnixMailbox has a defination for a factory. __init__(self, fp, factory=) where fp is a file pointer. I don't want to use rfc822.Message. I'd like to use mhlib.Message instead. rfc822.Message requires: __init__(self, fp, seekable=1) mhlib.Message requires: __init__(self, f, n, fp=None) where f think the is a folder name. I've seen '.' used. (The documentation is very unclear here). And 'n' is the seekable. How do I call mailbox.UnixMailbox( fp ... ) with mhlib.Message? Thanks From scobloke2 at infotop.co.uk Tue Aug 31 15:30:38 2004 From: scobloke2 at infotop.co.uk (Ian Wilson) Date: Tue, 31 Aug 2004 19:30:38 +0000 (UTC) Subject: Xah Lee's Unixism In-Reply-To: References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4dyXc.25792$Ot3.22106@twister.nyc.rr.com> <878yc0ucyl.fsf@thalassa.informatimago.com> <20040827135423.154$1T@newsreader.com> Message-ID: David Schwartz wrote: > 'unixism' has nothing to do with *using* UNIX. ... > only those people who use UNIXes are affected by 'unixism' Sorry, I don't see how an activity can be affected by something that has nothing to do with that activity. Are you suggesting that Unix users don't have to deal with unixism? If that were so, why would Xah Lee have such a bee in his bonnet about it? [2] Xah Lee says "unix should mean unixism, the way things are done in unix platform" [1] Xah Lee also says "the unix shells ... is one giant unpurgeable shit pile arose from ad hoc hacks of unixism." [2] It seems legit to wonder why he chooses to place his web-pages amongst shit piles. [1] The world unix should mean unixism, that is, the way things are done in unix platform, their culture, their hacking attitude, their social attitude, their preferences, their people, their tools, their languages, their ps grep config make shebang tartall gunzip README manifesto et cetera. http://www.xahlee.org/UnixResource_dir/freebooks.html [2] By the way, the unix shells and environment variable and ways, is quite a fucked up one. It is amazing to see its stupidities alluded as an advance for some language design argument. The whole morbidity of the prospect to place an executable script as any program name in any path with the fucked up ways to search for programs to execute and the fucked up way to determine whether it is a program by the fucked up permission bits system is one giant unpurgeable shit pile arose from ad hoc hacks of unixism. http://www.xahlee.org/Writ_dir/comp_lang_lisp/124.txt All hail! From aleaxit at yahoo.com Fri Aug 27 02:45:43 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 27 Aug 2004 08:45:43 +0200 Subject: Static properties References: <1gj5e8n.xujsah4chw0gN%aleaxit@yahoo.com> Message-ID: <1gj657x.8jtu0f1hovhhvN%aleaxit@yahoo.com> Bengt Richter wrote: ... > >> Is it possible to define "static properties" in a class? > > > >Yes, but only by defining a custom metaclass to be the type of that > >class. Properties are defined in the type, not in the instance; so, for > >a class itself to have properties, the class's type, commonly known as > >its metaclass, must be the one defining them. > > Um, UIAM a property is just a peculiar descriptor, which you can define > without resorting to metaclass magic. See below ... Hmmm -- I think we're talking somewhat at cross-purposes between property, the built-in type, and the effect it has (that accessing an attribute runs some code). I was focusing on the formed, but you're quite right regarding the latter. > >if you want to be able to get at property curdir on INSTANCES of Path as > >you normally would for a staticmethod, yet with property syntax, I think > >you need to get a bit more clever than this... descriptors don't get > >looked up two metalevels up, only one... > > > But you only need one: If you don't use property, but "get a bit more clever" by defining a custom descriptor as you have, yes: > > >>> class Path(object): > ... class curdir(object): > ... def __get__(self, inst, cls): return os.getcwd() > ... curdir = curdir() Nice. Unfortunately it doesn't extend to data properties, those with a __set__ method: >>> class Path(object): ... class foo(object): ... def __get__(*a): return 'gotten' ... def __set__(*a): print 'setten' ... foo = foo() ... >>> p=Path() >>> p.foo 'gotten' >>> p.foo=23 setten >>> p.foo 'gotten' >>> Path.foo 'gotten' >>> Path.foo = 23 >>> Path.foo 23 >>> I think (I hope I'm wrong) that to catch 'Path.foo = something' you do have to use a custom metaclass (not 'metaclass magic', nothing in the least magical about it). But if you're simply willing to trust users to just never assign to Path.foo -- you don't need for such assignments to cause an error nor for them to cause any specific action -- a simple custom descriptor may indeed suffice. Alex From davidf at sjsoft.com Fri Aug 6 08:43:04 2004 From: davidf at sjsoft.com (David Fraser) Date: Fri, 06 Aug 2004 14:43:04 +0200 Subject: @decorators In-Reply-To: References: Message-ID: daishi wrote: > For what it's worth: > > As far as I know, the proposed @decorator syntax will be the first > time that two logical lines of python with the same indentation will > not be independent of one another. Previously, when looking at: > > some_python(code) > and_some_more = stuff > > there was no need to look at the the first line in order to know what > the second line meant/did (and vice versa). It would seem that the > cases when there are effects across multiple logical lines is captured > in compound statements: > > """ > Compound statements contain (groups of) other statements; they affect > or control the execution of those other statements in some way. > """ -Python Reference Manual > > My understanding of decorators is that they fit this definition. > One thing that I am not entirely clear about is whether decorators > are intended to be a compound statement themselves, or whether they > are meant to simply be extensions of current compound statements > such as function definition (and class definitions?) > > In either case, however, it seems that the following should apply: > > """ > Each clause header begins with a uniquely identifying keyword and ends > with a colon. A suite ... can be one or more indented statements on > subsequent lines. > """ -Python Reference Manual > > In the first case where decorators form their own compound statement, > this would seem to imply the basic layout of: > > @decorator: > def foo(): > pass > > (Whether that uniquely identifying keyword for decorators happens to > be spelled '@' is not important to me.) > > In the second case where decorators are simply extensions of current > compound statements, the current wording of the Python Reference > Manual would seem to imply that for function definition the clause > header must begin with 'def'. I.e., the decorator should not come > before the def, and certainly not on a separate line. Beyond this, > however, for me it is not particularly important whether the > decorator comes before/after the function name/argument list, and > how it is delimited. > > I guess the basic point that I am trying to make is that what I find > important is consistency with the basic visual layout of code promised > (IMHO) by python. I believe that this promise is violated by the > currently proposed decorator scheme. > > d > > PS: Although I believe the current view of the implementors is to view > decorators as an extension to function definition, I believe that the > separate compound statement view is fairly rich. As others have noted, > it can make identical decorations simpler: > > @static,synchronized: > def foo(): > pass > def bar(): > pass I like this idea. What about using the list syntax instead of the @ syntax: [decorator]: def foo(): pass [static, synchronized]: def foo(): pass def bar(): pass [static, synchronized, types(int, int), returns(None) ]: def foo(): pass This would then take away the argument against a valid list before a def being valid python but not previously having any effect... Or for good measure you could add a keyword: declare [static, synchronized, types(int, int), returns(None)]: def foo(): pass def bar(): pass Now that looks pretty neat David From martin at v.loewis.de Mon Aug 2 10:10:17 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 02 Aug 2004 16:10:17 +0200 Subject: Codecs for ISO 8859-11 (Thai) and 8859-16 (Romanian) In-Reply-To: References: <410c2827$0$24830$9b622d9e@news.freenet.de> <410D7AB5.9040100@v.loewis.de> Message-ID: <410E4B49.7030805@v.loewis.de> Peter Jacobi wrote: > a) ISO 8859-n vs ISO-8859-n > If the information at > http://en.wikipedia.org/wiki/ISO_8859-1#ISO_8859-1_vs_ISO-8859-1 > is correct, Python 8859-n > codecs do implement the ISO standard charsets ISO 8859-n > in the specialized IANA forms ISO-8859-n (and in agreement > with the Unicode mapping files). So any difficult C0/C1 > wording in the original ISO standard can be disregarded. I see. According to RFC 1345, this is definitely the case for ISO-8859-1. ISO-8859-16 is not defined in an RFC, but in http://www.iana.org/assignments/charset-reg/ISO-8859-16 This is a confusing document, as it both refers to ISO/IEC 8859-16:2001 (no control characters), and the Unicode character map (with control characters). We might interpret this as a mistake, and assume that it was intended to include control characters (as all the other ISO-8859-n). For ISO-8859-11, the situation is even more confusing, as that is no registered IANA character set, according to http://www.iana.org/assignments/character-sets Therefore, it would be a protocol violation (strictly speaking) if one would use iso-8859-11 in, say, a MIME charset= header. Regards, Martin From antonmuhin at rambler.ru Thu Aug 26 10:20:23 2004 From: antonmuhin at rambler.ru (anton muhin) Date: Thu, 26 Aug 2004 18:20:23 +0400 Subject: Fun transformation problem In-Reply-To: References: Message-ID: <2p69vfFh7vf6U1@uni-berlin.de> Dale Strickland-Clark wrote: > A guy in the office has come up with this interesting transformation > problem. We have a solution but I'm sure there's a neater, more 'pythonic' > approach. > > I thought this might appeal to some here: > > I want a function to convert a list of tuples into a hierarchy of > dictionaries. Let me first demonstrate with an example: > > >>>>lstA = [(1, 2, 3), (1, 3, 4), (2, 5, 6)] >>>>dctA = fncA(lstA) >>>>print dctA > > {1: {2: 3, 3: 4}, 2: {5: 6}} > > > I essentially want the definition to fncA. Here is another example: > > >>>>lstA = [(1, 2, 3, 4) ,(3, 4, 5, 6), (3, 4, 6, 7), (3, 4, 6, 8), (3, 4, > > 5, 1), (3, 4, 7, 9)] > >>>>dctA = fncA(lstA) >>>>print dctA > > {1: {2: {3: 4}}, 3: {4: {5: 1, 6: 8, 7: 9}}} > > > Each tuple in the original list must be unique after the last value is > excluded (since these values are used to form the "hierarchical key". > > I have written a function, which seems to work but looks very cumbersome. > Could anyone point me to a simpler solution? > > > > Dale Strickland-Clark > Riverhall Systems The following: def transform(l): d = {} for t in l: c = d for e in t[:-2]: c = c.setdefault(e, {}) c[t[-2]] = t[-1] return d seems clear enough for me. with the best regards, anton. From peter at engcorp.com Thu Aug 26 01:37:30 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 26 Aug 2004 01:37:30 -0400 Subject: Why return None? In-Reply-To: References: Message-ID: Martin DeMello wrote: > It seems to be a fairly common pattern for an object-modifying method to > return None - however, this is often quite inconvenient. ... > this is actually getting in my way a lot when scripting Blender - for > instance, I can't say move(Vector([a,b,c]).normalize()), I have to do > a = Vector([a,b,c]) > a.normalize() > move(a) By the way, the second version is much more readable than the first, so perhaps there is a secondary reason for this "return None" thing in addition to the more important one... -Peter From lbates at swamisoft.com Mon Aug 2 18:27:44 2004 From: lbates at swamisoft.com (Larry Bates) Date: Mon, 2 Aug 2004 17:27:44 -0500 Subject: parsing tar-style dates References: Message-ID: There is a PEP on this located here: http://shattered.teched.net/www.python.org/peps/pep-0321.html FYI, Larry Bates Syscon, Inc. "Daniel M. Drucker" wrote in message news:e940a049.0408021411.e206d97 at posting.google.com... > Is there any way to parse tar-style dates like "tomorrow" or "next > wednesday" in python, other than doing a system call to date > --date="string" and then parsing its output? > > Daniel Drucker > ddrucker at gmail.com From wweston at att.net Wed Aug 18 12:35:50 2004 From: wweston at att.net (wes weston) Date: Wed, 18 Aug 2004 16:35:50 GMT Subject: age of Python programmers In-Reply-To: References: <41237124.4060600@chamonix.reportlab.co.uk> Message-ID: Thomas Heller wrote: > Robin Becker writes: > > >>Lucas Raab wrote: >> >> >>>One thing I've always kind of wondered is what is the average age of a >>>Python programmer?? What age groups use Python?? Something to think >>>about.... >>> >> >>57, used to build my own logic using gas discharge tubes :) > > > 48, but my first logic was build using 24V relays. Thomas, I guess I did about 100 projects with 24v relays. This was mostly in the oil and gas industry or emergency power. wes From webraviteja at yahoo.com Fri Aug 27 05:00:29 2004 From: webraviteja at yahoo.com (Ravi Teja Bhupatiraju) Date: 27 Aug 2004 02:00:29 -0700 Subject: Proposal for removing self References: Message-ID: "Sean Ross" wrote in message news:... > "Ravi Teja Bhupatiraju" wrote in message > > __readonly__ would be another nicety. > > Well, you could use this for __readonly__ (though I named it 'readable()'): > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/157768 > > or if you want to use meta-classes (and this recipe does use __readonly__): > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/197965 > > There are many similar implementations floating around. > > As for removing self: > http://starship.python.net/crew/mwh/hacks/selfless.py > > Enjoy, > Sean Thanks Sean. This is interesting code. I should really learn about metaclasses. From pm_mon at yahoo.com Sat Aug 14 09:35:48 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sat, 14 Aug 2004 09:35:48 -0400 Subject: Decorators: an outsider's perspective In-Reply-To: <9ADC3170-EDAF-11D8-9F63-000A95B336F2@snowtide.com> References: <9ADC3170-EDAF-11D8-9F63-000A95B336F2@snowtide.com> Message-ID: Chas Emerick wrote: [...snip...] > > The first time I saw this, I almost fell out of my chair: > > def blah (args): > ....[insert 50/100/200 lines here] > blah = staticmethod(blah) > me too. [...snip...] > > So, when I see: > > @staticmethod > def blah (args): > ....[insert 100 lines] > > I say, YES! [...snip...] I say, NO! And I wonder why we feel a need to explicitly (and superflously) 'declare' something that is already clearly evident in the code (when recommended coding practices are followed). class Foo: def blah(a, b): # this is clearly a static method pass def blah(self, a, b): # this is clearly an instance method pass def blah(klass, a, b): # this is clearly a class method pass Python was built (successfully) on the assumption that obvious interpretations of the code obviate the need for declarations. Why wouldn't we continue with that mindset? Paul From sbabbitt at commspeed.net Tue Aug 24 22:34:09 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Tue, 24 Aug 2004 19:34:09 -0700 Subject: python line editor References: <6c283161.0408241511.625ea118@posting.google.com> Message-ID: <1093401744.541364@news.commspeed.net> I'm having a hard time understanding your question, what exactly would > /sFoo > :i"Bar" > :wq > do to a file, do you have a GUI available? Have a look at sys.argv() and glob.glob() in the standard libraries they might help. Tom From harry.g.george at boeing.com Wed Aug 4 13:11:37 2004 From: harry.g.george at boeing.com (Harry George) Date: Wed, 4 Aug 2004 17:11:37 GMT Subject: Python CGI question/issue References: <8697475.0408040823.4cb6fbac@posting.google.com> Message-ID: candrade at gmail.com (Carlos Andrade) writes: > I have a working python script that takes in content from a form, > cleans it up, adds html formatting and then places it into my > index.html page on my server. When I had index.html set up as : > -rw-rw-r-- 1 carlos wheel 3517 Aug 4 09:51 index.html > I could not write back to the file, > Traceback (most recent call last): > File "/usr/local/www/cgi-bin/bob.py", line 24, in ? > file=open("../data/index.html","w") > IOError: [Errno 13] Permission denied: '../data/index.html' > [Wed Aug 4 09:50:47 2004] [error] [client X.X.X.X] Premature end of > script headers: /usr/local/www/cgi-bin/bob.py > > and I though well shoot okay I need to make index.html -rw-rw-rw-, > when then made me a little paranoid. Is there a more simpler way to > make it possible for me to write back to index.html? The cgi is running as whatever the webserver is set for, probably "nobody". So it doesn't matter that you personally own the file. The cgi can only edit the file if "nobody" can do so. Changing files on a website can be done many ways. They have little to do with python per se, though they can be done with python. 1. For fairly simple tasks, why not rewrite the app as a batch job, run it as you in a sandbox, and then copy the resulting html file to the web-visible docs dir. That way you can control the permissions in the copy process. If it is a remote site, and you need ftp, consider ftpmirror.py and similar tools. 2. You have almost described a Content Mgmt System (CMS), and something like zope plone might do what you want. Or for ad hoc editing you consider a wiki (e.g., moinmoin). 3. webdav is the official mechanism for web editing. I haven't tried it personally. 4. There is an apache module for changing user and group during a cgi. It comes with all kinds of dire warnings. 5. If you can run your own webserver, it can be run as you, and thus can control those files. Better would be to make a totally new userid just for this task. 6. You could run your own web service, e.g., via Twisted. As with a std webserver, it is better to have a separate userid for the task. -- harry.g.george at boeing.com 6-6M21 BCA CompArch Design Engineering Phone: (425) 342-0007 From davidf at sjsoft.com Fri Aug 6 04:47:57 2004 From: davidf at sjsoft.com (David Fraser) Date: Fri, 06 Aug 2004 10:47:57 +0200 Subject: Trimming a string In-Reply-To: <10gsotqjc2qrl54@news.supernews.com> References: <10gsmuieo65du5d@news.supernews.com> <10gsotqjc2qrl54@news.supernews.com> Message-ID: Actually your answer was a bit ruder than his Double Dumbass on You wrote: > Do you feel better about yourself for having posted a smug, shithead-type > answer, troll?? > > As a matter of fact, I was in a near fatal car wreck about 7 years ago. > Suffered some brain damage. Now, I can't remember minute details such as > that which I asked. I have read the python documentation numerous times. > Sometimes, I just need a simple answer to a simple question, you simple > *********. > > ***************, it will be time well spent for you. > > "wes weston" wrote in message > news:ektPc.165630$OB3.11201 at bgtnsc05-news.ops.worldnet.att.net... > >>Double Dumbass on You wrote: >> >>>I have a string that is 7 characters and represents file mode in > > UNIX/LINUX > >>>from rpm: >>> >>>0100755 >>> >>>I don't care about the 0100 portion, I am only interested in the file >>>permissions portion which is 755. How can I get three characters from > > the > >>>string starting at the right? ( -OR- strip 4 characters from the > > left? ) > >>> >>DD, >> >> >>> x = "0100755" >> >>> print x[4:] >>755 >> >> Reading the tutorial is really time well spent. >>wes >> > > > From ialbert at mailblocks.com Thu Aug 19 15:07:07 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Thu, 19 Aug 2004 15:07:07 -0400 Subject: My only complaint about Python In-Reply-To: References: Message-ID: Dominic wrote: > I have successfully built libpython23.a using > implib.exe provided with the free Borland C/C++ command line > compiler package. > Once this is done, cygwin-gcc can be used to create > _native_ windows modules. > If someone is interested I'll try to collect the > necessary commands and flags from my Makefiles. I'm interested. You should even make your copy of libpython23.a downloadable too. Istvan, From abra9823 at mail.usyd.edu.au Thu Aug 26 21:16:42 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Fri, 27 Aug 2004 11:16:42 +1000 Subject: cookie In-Reply-To: References: Message-ID: <1093569402.412e8b7a706ec@www-mail.usyd.edu.au> they dont cause any harm, except for a an extra statement removing those quotes when i read the cookie, parse it and authenticate the session. the question is - is that normal cookie behaviour? cookie["test"]="blah" print cookie prints test=blah and not test="blah" so why the quotes when i do the same thing, but use a variable instead of a string literal? cheers Quoting "John J. Lee" : > Ajay writes: > > > hi! > > > > i am printing a simple cookie, but instead of printing > > um=name:blah&access:admin&exp:2312390.909 > > > > its printing > > um="name:blah&access:admin&exp:2312390.909" > > > > why the quotes? > > Why not? > > I don't see how they'd cause any harm. > > > John > -- > http://mail.python.org/mailman/listinfo/python-list > ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From pm_mon at yahoo.com Wed Aug 25 07:39:10 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Wed, 25 Aug 2004 07:39:10 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: Message-ID: Anthony Baxter wrote: > On Tue, 24 Aug 2004 12:29:38 -0400, Paul Morrow wrote: > >>....that they warrant an entirely new syntax? It seems that they are >>very similar in a very significant way --- they alter the default >>behavior of something. IMO, it's not a stretch to say that they >>'parallel' metaclasses; that they are to functions/methods what >>metaclasses are to classes. So why don't they share a similar syntax? > > > No. Function decorators are to functions as class decorators are to classes. > Maybe, if they ever show up. But until then metaclasses are the closest thing. > Class decorators are not in 2.4, because you can do most things you'd > do with a class decorator by using a metaclass, but in a completely > different way. In my opinion, class decorators _should_ be in 2.4, > because they're a much saner way to handle many things that require a > metaclass today. > I'd like to see a compelling example of Class decorators. Something that justifies using them instead of metaclasses. > They don't "alter the default behaviour". A metaclass allows the user > to specify an object that builds classes in a new way. A decorator > allows the user to specify a way to transform the already built > function (or class, for class decorators). > If you want to think about them that way, go ahead. But it's easier (and I believe just as valid) to think about them in terms of altering the default behavior of an object. For example... class Foo: __metaclass__ = M # comment out for default behavior When I use a metaclass, I don't want to "specify an object that builds classes in a new way". That's an awkward way to think about it. I want to change the behavior of *my* class. Period. Likewise, when I use a decorator, say 'memoized', on my function, I most definitely *do not* want to think about what's going on under the hood --- that my function is first created, then 'transformed' by the memoized decorator. No. I want to think that my function simply has the 'memoized' feature and let the system worry about the details of making that happen. From zathras at thwackety.com Sun Aug 22 10:01:39 2004 From: zathras at thwackety.com (Michael Sparks) Date: Sun, 22 Aug 2004 15:01:39 +0100 Subject: [PATCH] RE: J2 decorator grammar References: Message-ID: <4128ac0f$0$79299$ed2619ec@ptn-nntp-reader02.plus.net> Anthony Baxter wrote: > On Sun, 22 Aug 2004 11:05:35 +0100 (BST), Michael Sparks > wrote: >> >> >> On Sun, 22 Aug 2004, Anthony Baxter wrote: >> > On Sun, 22 Aug 2004 01:41:58 +0100 (BST), Michael Sparks wrote >> > > The patch can be found here: >> > > * http://thwackety.com/decorator_syntax_J2.patch >> > >> > Good to see. There's a few more bits than this that need to be >> > done, though - see http://www.python.org/sf/979728 for the original >> > @decorator patch, this should show you what else needs to be >> > changed. >> >> Many thanks for the pointer. I'll try and make sure I cover all the >> bases, but I suspect I'll miss something, but I'll try not to :) > > Well, in the comments for that patch, I listed all of the files changed by > the @syntax - that at least gives you a 'to-do list' to work through. That's what I'm doing - I'm also working through the patch itself to see what needs changing. So far my changes include: * Doc/lib/libfuncs.tex - Changed examples from @ format to decorate: format * Doc/ref/ref7.tex - changed Function Definitions production rules to match the change in syntax. - Changed example to use the change in syntax. * Lib/compiler/transformer.py - Modified to handle the new syntax * Lib/test/test_parser.py - Changed tests for old syntax to check new form * Lib/test/tokenize_tests.txt - changed @staticmethod to J2 format * Lib/test/output/test_tokenize - Changed to match the changed test file * Modules/parsermodule.c - Changed to support new Grammar * Lib/test/pyclbr_input.py - Changed from @ syntax to decorate: syntax * Lib/test/test_decorators.py - changed all "decorate" functions to decorate_ and all @ usages to "decorate:" syntax. Stuff I've not changed after checking: * Doc/lib/asttable.tex - Can't see any necessary changes * Lib/compiler/pycodegen.py - Can't see any necessary changes * Lib/compiler/symbols.py - Can't see any necessary changes * Tools/compiler/ast.txt - Can't see any necessary changes * Tools/compiler/astgen.py - Can't see any necessary changes * Tools/compiler/regrtest.py - No changes * I can't see whether ast.py should/should not be changed and if it should, *how* it should be changed, as a result I've left well alone. Current Issues (which I want to resolve before posting to SF): * Keyword clash with test suite is bad - suggest change to "using" to limit clash with existing user code as far as possible. (Also "def decorate python" shows *lots* of results on google, which is the other reason :) * Patch is against the vanilla 2.4a2 download from python.org, does this need changing to being a patch against the current CVS head? (I suspect the answer to this is "yes") It should be done sometime this afternoon though. (Bulk of the time taken up is on re-running the test suite unsuprisingly) > Once you've got what you think is the complete set, create a patch and > post it to SF. Will do. Best Regards, Michael. From pete at shinners.org Thu Aug 19 10:54:35 2004 From: pete at shinners.org (Pete Shinners) Date: Thu, 19 Aug 2004 07:54:35 -0700 Subject: Platform independent way to play an mp3 file In-Reply-To: <41239EAB.903@geochemsource.com> References: <31575A892FF6D1118F5800600846864D01AE29A3@intrepid> <41239EAB.903@geochemsource.com> Message-ID: Gandalf wrote: > Oh, okay. That's fine. At least I can tell something to my bosses. :-D > But what about FreeBSD? You can go with pygame, but it comes with a bit of overhead for simply playing MP3 audio. I'll also warn you that the decoder it depends on isn't spectacular, it won't parse files with ID3V2 tags might be your biggest problem. import pygame pygame.mixer.init() pygame.mixer.music.load("music.mp3") pygame.mixer.music.play(-1) #loop infinitely #music will play indefinitely until program ends From alanmk at hotmail.com Tue Aug 3 09:11:22 2004 From: alanmk at hotmail.com (Alan Kennedy) Date: Tue, 03 Aug 2004 14:11:22 +0100 Subject: socket.sendall(), non-blocking sockets, and multi-threaded socket sending In-Reply-To: References: Message-ID: <410F8EFA.8010207@hotmail.com> [Tim Black] > My application requires sending a large piece (~2MB) of data to > several devices on a network via TCP sockets. I have experimented with > different methods for doing this and this has raised some questions > about the implementation of Python sockets. > > (both methods use blocking sockets) > > Method 1: Calls socket.sendall(data) for each device in sequence, all > in a single thread. > > Method 2: Each socket has its own thread that calls > socket.send(datachunk) iteratively until all data is sent. > > So Method 1 sends all data to device1, then send all data to device2, > etc... until all data is sent to all devices. Method 2 sends chunks of > data to all devices in parallel. What I am seeing is that Method 1 is > faster than Method 2. Given that the bottleneck is the actual sending > of data on the sockets and not some latency in processing the message > at the other end, this result makes sense to me. Method 2 involves > sending the data in smaller chunks, whereas with Method 1 the > chunksize is selected by the TCP/IP stack implementation, which is > probably more efficient. Also, Method 2 entails context switching > between the send threads. > > It turns out that using Method 1, all sendall() calls return > immediately. I am assuming at this point that my app is in the hands > of the TCP/IP stack implementation on my machine (win32-XP). Can > anyone explain what happens inside sendall() for Win32? > > Also, I would like to get advice and opinions on what is the most > efficient way to broadcast data to several devices on a network. I'd love to have enough time to get into discussing your findings about sockets. But unfortunately, I don't :-( But I did want to point out a module that you may not have come across that makes the job of distributing information peer-to-peer over LANs very easy: the spread module. I highly recommend that you take a look over it: it could save you a lot of wheel-reinvention. http://www.python.org/other/spread/ HTH, -- alan kennedy ------------------------------------------------------ check http headers here: http://xhaus.com/headers email alan: http://xhaus.com/contact/alan From fumanchu at amor.org Mon Aug 23 21:46:19 2004 From: fumanchu at amor.org (Robert Brewer) Date: Mon, 23 Aug 2004 18:46:19 -0700 Subject: newbie: confused with example in Learning Python 2nd Edition: cananyone give a hint Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E4B@exchange.hqamor.amorhq.net> Porky Pig Jr wrote: > Here is an example of Stack class which got me totally confused: > > >>> class Stack: > ... def __init__(self, data): > ... self._data = list(data) > ... self.push = data.append > ... self.pop = data.pop > ... > > What I don't understand: we take the 'data' input (a list), and copy > it to semi-private instance attribute _data. Something like this: > > >>> mystack = Stack([1,2,3]) > >>> dir(mystack) > ['__doc__', '__init__', '__module__', '_data', 'pop', 'push'] > >>> mystack._data > [1, 2, 3] > > So: why defitions of self.push and self.pop are defined as > 'data.append' rather than '_data.append', etc. What makes me yet more > confused: the whole thing works just fine, and yet I can't figure out > in which attribute we store the results of pushes and where pops are > coming from. > Like I push '4' on a stack: > > >>> mystack.push(4) > > and yet this does not affect _data (obviously): > >>> mystack._data > [1, 2, 3] > > and yet '4' is stored *somewhere*, since pop() produces the right > result: > > >>> mystack.pop() > 4 > >>> > > Where is that hidden instance attribute and how can I access it? Seems > like very simple definition, and yet there is something tricky about > it. Hint: Python doesn't have variables like other languages do. The line: self._data = list(data) does not make a copy of "data". Instead, it binds a new name (self._data) to the same object which the name "data" refers to. FuManChu From curzio.basso at unibas.ch Wed Aug 11 03:56:52 2004 From: curzio.basso at unibas.ch (Curzio Basso) Date: Wed, 11 Aug 2004 09:56:52 +0200 Subject: how to dispatch objects depending on their class In-Reply-To: <21064255.0408102235.331f5f49@posting.google.com> References: <4118dd4a$1@maser.urz.unibas.ch> <21064255.0408102235.331f5f49@posting.google.com> Message-ID: <4119d149$1@maser.urz.unibas.ch> Peter Abel wrote: > At my opinion you try to do something outside a class which should > be a basic task of OOP. Why not let the instances do their class-specific > things: I know that this situation would be typically handled by putting the logic in the class hierarchy, but as I wrote I don't want this. In fact, as cmedcoff at hotmail.com pointed out, at the end what I want to implement is a visitor pattern (maybe I should have simply mentioned this). In C++ then the right implementations are chosen at compile time because of the function overloading, but in Python I have to find a different way to implement this. cheers, curzio From fumanchu at amor.org Tue Aug 24 00:11:53 2004 From: fumanchu at amor.org (Robert Brewer) Date: Mon, 23 Aug 2004 21:11:53 -0700 Subject: profiler Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E4D@exchange.hqamor.amorhq.net> grv575 wrote: > I have some speed-critical loops involving numarray arrays and need to > see which part is taking all the time. Is there a seperate profiling > tool or how do you go about profiling everything (broken down by > module/function) in an interpreted language like python? The Standard Library has a module named "hotshot" which you might want to take a look at: http://docs.python.org/lib/module-hotshot.html ...which is a replacement for the older "profile" module: http://docs.python.org/lib/module-profile.html HTH, FuManChu From plucker-dev-admin at rubberchicken.org Sun Aug 22 09:11:03 2004 From: plucker-dev-admin at rubberchicken.org (plucker-dev-admin at rubberchicken.org) Date: Sun, 22 Aug 2004 23:11:03 +1000 Subject: Your message to plucker-dev awaits moderator approval Message-ID: <20040822131103.17450.16922.Mailman@ike.inomial.com> Your mail to 'plucker-dev' with the subject Stolen document Is being held until the list moderator can review it for approval. The reason it is being held: Post by non-member to a members-only list Either the message will get posted to the list, or you will receive notification of the moderator's decision. From martindemello at yahoo.com Sat Aug 21 16:29:13 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Sat, 21 Aug 2004 20:29:13 GMT Subject: serial iteration over several lists Message-ID: Within Blender, I have access to a list of Objects, each Object containing a list of Meshes and each Mesh a list of Faces. I'd like to implement a face iterator, with both a next() and a prev() method, such that if I go off the end of a face list, it goes to the first face in the next mesh, similarly for going off the end of the last mesh in an object, and similarly for the prev() iterator. In other words, I want to simulate appending all the faces into one long list, but without the overhead of actually creating the list. I can think of several ways to do it, but they all feel like solutions 'translated' from some other language - is there a nice pythonic way to do this? martin From dougfort at dougfort.com Sun Aug 22 09:37:53 2004 From: dougfort at dougfort.com (Doug Fort) Date: Sun, 22 Aug 2004 13:37:53 GMT Subject: request for logging SyslogHandler help Message-ID: Hi, Perhaps this is as much a Unix question as a Python question. I really like the Python logging module, and I've used it extensively, with good results. Now I have a requirement to add a SysLogHandler, and it's just not working. It looks like the socket is connecting, but nothing comes out on the log. (Fedora Core 2 /var/log/messages) The simplest of many configurations I have tried is included below. A FileHandler in the same config file works fine. Does anyone have experience in this area? Do I need a special format or something? [handler_syslog] class=handlers.SysLogHandler level=NOTSET formatter=verboseformat args=() -- Doug Fort, Consulting Programmer http://www.dougfort.com From richardjones at optushome.com.au Tue Aug 31 18:50:24 2004 From: richardjones at optushome.com.au (richard) Date: Wed, 01 Sep 2004 08:50:24 +1000 Subject: PyPI References: Message-ID: <413500b0$0$8893$afc38c87@news.optusnet.com.au> p.kosina wrote: > I tried to make a registration on www.python.org/PyPI, but no email > confirmation received. Is it working? Is anyone responsible for that here? Please use the "Get help" link under "Contact Us" in the PyPI sidebar. Richard From nicksjacobson at yahoo.com Sun Aug 22 02:38:55 2004 From: nicksjacobson at yahoo.com (Nick Jacobson) Date: 21 Aug 2004 23:38:55 -0700 Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? References: Message-ID: > > Please start giving some thought to what the 'decorate' keyword should be. > If we can get/keep this selection to a manageable list, then we should have > another multivote some time next week. > > -- Paul How about 'predef'? --Nick From cckk_lin at yahoo.ie Mon Aug 30 04:23:36 2004 From: cckk_lin at yahoo.ie (Lin Jingxian) Date: Mon, 30 Aug 2004 16:23:36 +0800 Subject: use win32 COM in python Message-ID: hi, I have a C++ implemented COM server that give out a method like: int read(unsigned char* buf, int lenth), How can I use this method from python? what is the signature? or anyone can tell me how should I design the COM interface so I can use python to read a chunk of bytes from a C++ implemented COM server. thanks. From elbertlev at hotmail.com Thu Aug 5 15:13:57 2004 From: elbertlev at hotmail.com (Elbert Lev) Date: 5 Aug 2004 12:13:57 -0700 Subject: ODBC bug Message-ID: <9418be08.0408051113.2551257b@posting.google.com> # W2K MSSQL-2000 import dbi, odbc myconn = odbc.odbc('DSN=db; UID=sa; PWD=') mycursor = myconn.cursor() mycursor.execute("SELECT ID, PWD FROM TABLE") rs = mycursor.fetchall() for ID, PWD in rs: upd = "UPDATE TABLE SET PWD = \'%s\' WHERE ID = %u" % \ (encode(PWD), ID) mycursor.execute(upd) myconn.commit() #This script updates (encodes) passwords in the database, #but does this rather slowly if the the recordset contains 2000 records. To speedup I decided to concatenate upd strings and execute it: mycursor.execute("SELECT ID, PWD FROM TABLE") rs = mycursor.fetchall() updlst = [] for ID, PASSWORD in rs: upd = "UPDATE TABLE SET PWD = \'%s\' WHERE ID = %u" % \ (encode(PWD), ID) updlst.append(upd) upd = " ".join(updlst) mycursor.execute(upd) myconn.commit() #This one works much faster, but if the joined upd string is longer then about 40K ONLY THE FIRST 40K are actually executed. The rest is IGNORED. No exceptions and execute() returnes 1. From aahz at pythoncraft.com Wed Aug 18 18:07:05 2004 From: aahz at pythoncraft.com (Aahz) Date: 18 Aug 2004 18:07:05 -0400 Subject: age of Python programmers References: Message-ID: In article , Ville Vainio wrote: > >I'm also optimistic about retiring with Python, because *everyone* is >going to retire with Python in 2044 :-). 2038 -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From Michael.J.Fromberger at Clothing.Dartmouth.EDU Wed Aug 18 10:11:47 2004 From: Michael.J.Fromberger at Clothing.Dartmouth.EDU (Michael J. Fromberger) Date: Wed, 18 Aug 2004 10:11:47 -0400 Subject: PEP 318: Can't we all just get along? References: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: In article , Paul Morrow wrote: > Dan Sommers wrote: > > I don't understand how assigning semantic significance to a > > "recommended coding practice" is Pythonic. > > > > In the face of ambiguity, refuse to guess. > > > > Explicit is better than implicit. > > Good conventions prevent ambiguity. > > class Foo: > def method1(self, a, b): pass # clearly an instance method > def method2(cls, a, b): pass # clearly a class method > def method3(a, b): pass # clearly a static method I think this is a terrible idea. What you are proposing is essentially that Python should assign special meaning to the identifiers "self" and "cls" when they appear as the first variable in a method definition inside a class. I am having a hard time thinking of anything LESS in the spirit of Python, short of writing in unstructured BASIC. Good conventions do not prevent ambiguity, they merely help alleviate its effects. And a "convention" that is enforced by the translator is no longer a convention, but a rule of the language. > When declarations conflict with conventions, it makes us wonder what the > author really intended. > > def staticmethod setX(self, x): > self.x = x I find this at least as easy to understand as the current idiom: def setX(self, x): self.x = x setX = staticmethod(setX) > You're right, this thread is about decorators, not about more > opportunities for dynamic typing. Actually, as I read it, this thread is about getting back to the original question PEP-318 was intended to answer, rather than all the other cruft that the "decorators" idea has become laden with. -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From in.aqua.scribis at nl.invalid Sun Aug 29 14:06:34 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Sun, 29 Aug 2004 20:06:34 +0200 Subject: regex into str In-Reply-To: References: Message-ID: Diez B. Roggisch schreef: > Jeff Epler wrote: > > > This is intended to be impossible. > > > > Even if you could assign to str.__div__ (and this is very deliberately and > > specifically disallowed) you would end up disappointed, because strings > > are immutable. That means there's nowhere to store "the last match", > > no way to mutate the string with the "/=" operator, and also that the > > interpreter is free to use the same storage for two equal strings. > > Another reason for not allowing this is that modifying builtins can lead to > severe bugs, as other libs might rely on certain functionality. If you > change that, things start getting very weird.... Programming causes bugs. That's not a reason to disallow programming. -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From imbosol at aerojockey.com Fri Aug 13 19:43:34 2004 From: imbosol at aerojockey.com (Carl Banks) Date: 13 Aug 2004 16:43:34 -0700 Subject: PEP-0318 References: <41122FC2.1080608@interlink.com.au><4114152f@nntp.zianet.com> <411a5cee$1@nntp.zianet.com> <411a9a7f$1@nntp.zianet.com> <411ac17f@nntp.zianet.com> Message-ID: <60dfb6f6.0408131543.1e0075f0@posting.google.com> Mark Bottjer wrote in message news:<411ac17f at nntp.zianet.com>... > Fredrik Lundh wrote: > > Mark Bottjer wrote: > >> Fredrik Lundh wrote: > >>>calling a function with an argument? that's a pretty common > >>>operation, if you're asking me > >> > >>Indeed it is. And that fact bears on this conversion how? > > > > that's what a decorator does, of course. > > No it isn't. A decorator queues a function to be called, on something > not yet defined, after that something gets defined. Gee, so does the statement "map(function,[1,2,3])" just-sayin-ly yr's, -- CARL BANKS From gherron at islandtraining.com Fri Aug 20 12:35:50 2004 From: gherron at islandtraining.com (Gary Herron) Date: Fri, 20 Aug 2004 09:35:50 -0700 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: <200408200935.51189.gherron@islandtraining.com> My vote: J2 J2 and J2 because it puts everything in the correct position (meaning in the same position as the pie syntax), but still *LOOKS* like python. Keyword could remain "decorate", but I'd be fid just about anything acceptable. Gary Herron From stefan at eischet.com Wed Aug 11 12:47:20 2004 From: stefan at eischet.com (Stefan Eischet) Date: Wed, 11 Aug 2004 18:47:20 +0200 Subject: Rather than decorators, how about sections? In-Reply-To: References: Message-ID: <1C74C038-EBB6-11D8-8889-000A95857E5C@eischet.com> Hi, do we really need this stuff just to say "staticmethod" and "classmethod"? How about: class Foo(object): def baz(): print "Static Method" def bar(self): print "Method" def spam(Foo): print "Class Method" Notice that the "normal" method, as usual, contains "self" as a first argument, while the static method does not. This would probably require making "self" a keyword; perhaps someone with more knowledge about Python internals could comment on this? Is anyone using another first parameter, e.g. "this"? I'm not sure about the class method syntax, though; better ideas anyone? I'm not saying you shouldn't have your pie-or-whatever decorators for other purposes, but I think that the above would be sufficient to solve the original problem of staticmethod/classmethod just as well. Someone recently said that, as a new feature, decorators should look new. I'd say that especially the rusty old feature of static methods should *not* have a new look. Cheers, Stefan On 11.08.2004, at 17:38, Paul Morrow wrote: > I like many am not wild about the operator. I also don't think > that the decorator syntax should be so directly attached to the > method, since what we're trying to do is to say something about the > *relationship between* a method and a class (e.g. "method m is a > staticmethod of class C"). > > So if we are going to extend the Python grammar to support this sort > of thing (which I believe is a good idea), my preference would be to > introduce named sections within a class definition, such as... > > class Foo(object): > staticmethods: > def baz(a,b): > print "I'm a static method." > def bez(c,d): > print "I'm a static method too." > > classmethods: > def biz(klass): > print "I'm a class method." > > > def __init__(self): > print "We all know what I am." > > > -- > http://mail.python.org/mailman/listinfo/python-list > > // stefan at eischet.com // From dyoo at hkn.eecs.berkeley.edu Mon Aug 16 20:47:27 2004 From: dyoo at hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 17 Aug 2004 00:47:27 +0000 (UTC) Subject: Python / scheme implement References: <8kcUc.216223$pC2.10693727@phobos.telenet-ops.be> Message-ID: Vent d'Est - East Wind wrote: : Can somebody tell me what s exactly the difference beetween scheme and : python languages : i m thiking to learn one of them but i m not sure wich one : somebody told me python is better and have much library : somebody told me scheme is much smarter and have nice structure Hello! What programming language experience do you already have? If you're looking for Scheme learning resources, you may want to look at the PLT web site: http://www.plt-scheme.org/ In particular, the Scheme folks have written a few books for learning the language; the link above has an online version of "How to Design Programs", which is an excellent book. Another great book whose implementation language is Scheme is "The Structure And Interpretation of Computer Programs": http://mitpress.mit.edu/sicp/ On the Python side, you may want to look at: http://www.python.org/topics/learn/ If you are a beginner to programming, visit: http://www.python.org/topics/learn/non-prog.html which includes links to introductory programming tutorials. : i also see a project about a scheme/python implementation : here is the url : http://plt-spy.sourceforge.net/home.html : i m not sure what s really but seems cool if someone know more about it : or have some concrete exemple it can be more understable If you are interested in the other direction, I have a weak Scheme interpreter that's written in Python: http://hkn.eecs.berkeley.edu/~dyoo/python/pyscheme/ It's not perfect (and frankly, is a little outdated!), but it's a proof-of-concept that one language can model the other. Personally, I like both languages, so my advice would be to look at them both. (But perhaps not at the same time... *grin*) Good luck to you! From fred at acme.com Mon Aug 9 19:26:46 2004 From: fred at acme.com (Fred) Date: Tue, 10 Aug 2004 01:26:46 +0200 Subject: VB-like GUI designer? References: <278de0e.0408090935.6d758a5d@posting.google.com> <30260531.0408091506.294cec8a@posting.google.com> Message-ID: On 9 Aug 2004 16:06:01 -0700, simoninusa2001 at yahoo.co.uk (simo) wrote: >py2exe is the best program for [pseudo] compiling your Python app, and >bundling all the necessary DLLs etc. together on Windows. I've used >py2exe with PyQt/wxPython sucessfully OK, I'll give it a closer look then. I don't care about decompiling, but simply to find a way to easily deploy Python + wxWidgets + our app on bare Windows hosts. >InnoSetup is an excellant installation package program that can take >the output of py2exe (or whatever) and make a Setup.exe, it's not MSI >mind you, but is free Yup, it's a nice app. I prefer to use NSIS because it has a scripting language, though. >IMHO a *machine code* compiler is what is really holding pack Python >adoption on the desktop by a lot of companies I read somewhere that the very roots of Python (being a dynamic language?) make it difficult to write a compiler that outputs machine code. But then, it seems pretty easy to call DLLs from Python, so I'll just write the number crunching parts in PowerBasic if Python proves to be too slow for this kind of thing. >You could wait for IronPython (or MS Visual Python.NET as it will >probably become!) if you want a standalone binary..... But then, I was investigating whether there's an alternative to VB to write GUI apps in Windows as easily and productively, so am a bit reluctant to go the .Net way :-) Thx a lot Fred. From chakari at acsalaska.net Mon Aug 23 16:46:55 2004 From: chakari at acsalaska.net (akbowbender) Date: 23 Aug 2004 13:46:55 -0700 Subject: Can't run program on Eclipse 3 w/pydev 0.4.2 Message-ID: <99bb88dc.0408231246.580a0f73@posting.google.com> I am trying to run a Python program with the above setup, but I get an exception error during launch; Error within Debug UI. This happens on Windows 2000 and on my Linux system. Has anyone run into this, and if so, found a fix? From tundra at tundraware.com Sat Aug 21 15:29:53 2004 From: tundra at tundraware.com (Tim Daneliuk) Date: 21 Aug 2004 15:29:53 EDT Subject: My only complaint about Python In-Reply-To: <874qmxj81k.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> References: <874qmxj81k.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Message-ID: 510046470588-0001 at t-online.de wrote: > Tim Daneliuk writes: > > >>Istvan Albert wrote: >> >>>In all fairness this is more the problem with Microsoft than >>>python. If they had a free fully-featured compiler then Python >>>would be compiled with that. >> >> >>They do. MSC/C++ is now available at NO cost: >> > > > no cost is not the same as free > > Klaus Schilling "No Cost" is _exactly_ the same thing as "Free". It is not the same thing as "Open Source". The debate is foolish in any case. If I use an GPLed compiler, even with the Lesser License, I have constraints placed upon what I may or may not do with the derivative work. If I use a commercial compiler, I do not have access to the source code _for the compiler_, but (usually) there are no constraints placed upon what I may do with the derivative work. This whole mentality of "it must be 'free' or it's bad" is very silly and at odds with how the world actually operates (aka Reality). I use both freely available open source tools and commercial tools (that I've paid for and licensed legitimately). Each has a place. One is not inherently better than another. The "freeness" of a particular product is only one of a number of dimensions I examine when making tool choices for myself or my clients. "Open Source" is often irrelevant to people - how many people actually want to examine and modify the guts of compiler? Far more important than the cost of acquistion is the _cost of ownership_. This is influenced by a lot of things: 1) Training 2) Maintenance 3) Stability/Quality 4) Documentation 5) 3rd-Party support IOW, I couldn't care less if something is "free", "freely available", "open source", "closed source", or "commercial" software. I care about whether it solves the problem at hand in a time- and cost-effective manner. Unfortunately, Stallman and his ilk - for all their many contributions to our field - have polluted the discussion with their hare-brained political notions, naive ideas about intellectual property, and incessant whining that everyone _else_ should "share" they way they define the term. I tire of it as you may be able to tell from this short rant ... Pax ... -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From olli at haluter.fromme.com Mon Aug 23 12:24:31 2004 From: olli at haluter.fromme.com (Oliver Fromme) Date: 23 Aug 2004 16:24:31 GMT Subject: Overriding logical operators? References: <04Aug21.160611edt.97252@mail.srv.cquest.utoronto.ca> Message-ID: <2ouk1vFf0ujnU1@uni-berlin.de> Andrew Durdin wrote: > On Sat, 21 Aug 2004 16:06:08 -0500, Chris Siebenmann > wrote: > > Conceptually, 'and' and 'or' (and 'not') don't operate on objects: > > they operate on truth values (generally derived from objects). > > But in Python, a "truth value" is an object: a bool object. Actually, that's not the whole truth. ;-) The logical operators on Python operate on arbitrary objects interpreted in a boolean context, but they're not restricted to bool objects. Furthermore, the "or" and "and" operators return the operand which has been evaluated last, which can be an arbitrary object (not neccessarily a bool object). Of course, the "not" operator always returns a real bool object (either True or False). For example, the expression ``"ugh" or 15'' evaluates to the string "ugh", and ``0 or []'' evaluates to an empty list. So, the logical operators have more built-in magic than just short-circuit evaluation. The details are in the Language Reference. Providing a clean facility to override them in Python would be very difficult, I guess. I suggest you simply define your own functions to do what you need to do, instead of overriding "or" and "and". If you only need to work with boolean values, you could derive your own bool class and override the "+" and "*" operators, of course. Best regards Oliver -- Oliver Fromme, Konrad-Celtis-Str. 72, 81369 Munich, Germany ``All that we see or seem is just a dream within a dream.'' (E. A. Poe) From remi at cherrypy.org Fri Aug 27 12:26:59 2004 From: remi at cherrypy.org (Remi Delon) Date: 27 Aug 2004 09:26:59 -0700 Subject: Web Application - User Management - RBAC References: Message-ID: <585c0de9.0408270826.4e4b5bf6@posting.google.com> > I would like to implement RBAC(Role Based Access Control) in the app. How would > one best go about that ? Well, CherryPy comes with a module called "CookieSessionAuthenticate" but it provides only 2 states: either a user is logged or he's not. If a user is logged in then you'll get automatically his username. You'll have to write your own code that checks the privileges that this user has and if he's allowed to do such and such action or not. It also depends on what level of precision you want the privileges to have (it could be at the URL level or at the individual function call level) ... But overall, it shouldn't be too hard to implement thanks to Python :-) Regards, Remi. From dfan at harmonixmusic.com Mon Aug 16 17:44:22 2004 From: dfan at harmonixmusic.com (Dan Schmidt) Date: 16 Aug 2004 17:44:22 -0400 Subject: Newbie question about file input References: <4120e398$0$65575$a1866201@newsreader.visi.com> Message-ID: Grant Edwards writes: | If you want to be particularly obtuse we can rely on the fact | that True evaluates to 1 and and False evaluates to 0, and just | sum up the boolean values returned by .startswith(). That only | takes one line (not counting the "import operator"): | | print reduce(operator.add,[l.startswith('[Event') for l in file('test.pgn','r')]) I'd just write something like print len( [ l for l in file( 'test.pgn') if l.startswith( '[Event' ) ] ) which actually looks clear enough to me that I might write it that way if I were writing this program. If anonymous functions weren't so ugly I might use print len( filter( lambda l: l.startswith( '[Event' ), file( 'test.pgn' ) ) ) instead, since I find the [ l for l ] idiom for filter kind of unappealing. Dan -- http://www.dfan.org From ajsiegel at optonline.com Mon Aug 23 10:25:06 2004 From: ajsiegel at optonline.com (Arthur) Date: Mon, 23 Aug 2004 14:25:06 GMT Subject: PEP318 References: <0I2D001ZDU03UQ@mta9.srv.hcvlny.cv.net> Message-ID: <1bvji0tt0inevmnfabefbbvjtunpsfub37@4ax.com> On Fri, 13 Aug 2004 13:30:57 +0200, Ronald Oussoren wrote: > >On 13-aug-04, at 13:17, Arthur wrote: > >> >>> On Thu, 12 Aug 2004 17:03:19 GMT, Arthur >>> wrote: >>>>> def foo (): >>>>> whatever >>>>> foo = decorator (foo) >>>>> >>>>> is that you have to type the word "foo" three times. >>>> >>>> Big f**king deal - all things considered. ;) >>> >>> When this name is a PyObjC name that might be 70 characters long, >>> it becomes a big deal. >> >> I had asked this before: >> >> Does >> >> def __f(something): >> dosomething >> >> the_name_I_really_want_to_call=transform(__f) >> >> work? >> >> It is not a destructive transform of __f, but why is that important? > >This requires additional input if you want to have the correct __name__ >attribute for the function. In your example 'transform' cannot no that >the result will be bound to 'the_name_I_really_want_to_call'. In >PyObjC I use the __name__ to deduce information about the function >(such as the Objective-C name for the function). > >Another problem is that you only know the "real" name for the function >some time after the function definition. if __name__ were writeable, aren't both problems solved? def __f(): __name__ = "the_name_I'm_stuck with" # we know the name the_name_I'm_stuck with=transfrom(__f) We are down to one extra cut and paste of "the_name_I'm_stuck with" Art > >> >> What else am I missing? >> >> I thought I read the PyObjC folks saying that they saw use cases for a >> decorator syntax for their project - to be sure - but that was >> (mis)interpreted as meaning that they saw it as important for their >> project, >> which they don't. >> >> I could be wrong in my interpretation here. > >Decorators would make live a lot easier for us, but not having >decorators won't kill PyObjC. > >I would like to have decorators, but not at every cost. The >@decorator-before-def proposal looks sane. > >Ronald From npat at efault.net Sat Aug 14 18:32:57 2004 From: npat at efault.net (Nick Patavalis) Date: Sat, 14 Aug 2004 22:32:57 +0000 (UTC) Subject: Generators versus Coroutines References: Message-ID: On 2004-08-14, Michael Sparks wrote: > On 14 Aug 2004, Timothy Fitz wrote: > >> It seems to me that in python, generators are not truly coroutines. > > Assuming you mean there isn't available a default scheduler for them, or > there isn't pre-emption built-in I agree. If you mean something else, I'm > curious as to what you think is missing. (I've also been using generators > as co-routines for sometime for various reasons) > I may be mistaken, as it has been some time since I've last dealt with coroutines, but aren't you supposed to be able to do this with real coroutines? def baz(): ... for i in range(10): yield i ... def bar(): ... baz() ... def foo(): ... bar() ... c = coroutine(foo) c.run() And when baz() yields, you're thrown back to the point where c.run() was called. How is this possible with generators? /npat From ziller at gmail.com Mon Aug 23 23:19:39 2004 From: ziller at gmail.com (ziller) Date: 23 Aug 2004 20:19:39 -0700 Subject: % format strings References: <144d0df.0408231455.6b664466@posting.google.com> <412A76A7.4C87D17C@alcyone.com> Message-ID: <537ea4cd.0408231919.4ada3ca1@posting.google.com> Erik Max Francis wrote in message news:<412A76A7.4C87D17C at alcyone.com>... > grv575 wrote: > > > Is > > there a way to specify the precision length for floating points in C > > format strings? > > Yes, it looks the same as in Python. Python got the notation from C. I meant to say how does it translate the *. Python lets you use a variable to specify the length of precision. int f_length = 5; float fl = 3.5 printf("%.*f", f_length, fl); doesn't compile. From eurleif at ecritters.biz Sun Aug 22 21:44:17 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sun, 22 Aug 2004 21:44:17 -0400 Subject: Logical lines of code counter Message-ID: <2ot090Fe5442U1@uni-berlin.de> I got bored with working on larger projects and wrote a little script/module for counting logical (not physical) lines of Python code in a file or directory. It uses ASTs generated by compiler.parse instead of text manipulation functions, so it isn't incredibly fast, but the speed is good enough to be usable for me. If you want to take a look, the file is at . I don't really care about how people license their modifications (and the GPL is longer than the script itself), so it's licensed under the MIT License. I'm sure there are a few bugs (AST nodes I forgot to count?), and I'd appreciate being emailed if anyone finds one. From peter.maas at mplusr.de Tue Aug 17 03:05:44 2004 From: peter.maas at mplusr.de (Peter Maas) Date: Tue, 17 Aug 2004 09:05:44 +0200 Subject: python packages cross references In-Reply-To: References: Message-ID: Roman Yakovenko schrieb: > Hi. I need help( or solution :-) ). > Problem: my project has 3 packages > prj > +------A > +------B > +------Utils > > The question is: what is the right way to use functionality from > Utils in A and B packages ? Look at Python Tutorial Packages (6.4). You can make a prj package and use intra-package references (6.4.2) for A, B and Utils. Mit freundlichen Gruessen, Peter Maas -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- From python.noob at gmx.de Fri Aug 6 06:30:19 2004 From: python.noob at gmx.de (Steffen Schoen) Date: Fri, 06 Aug 2004 12:30:19 +0200 Subject: Dynamic Class Creation Message-ID: (maybe it works better with Subject ;)) Hi there, my problem: i have a directory, where several python modules (classes) are stored. The names of these modules arent known before runtime. Now i want to parse the Directory and create an instance of each class. I tried to handle this with new.instance() and new.clasobj() but this didnt really work for me. Any Ideas ? From shalabh at cafepy.com Wed Aug 11 18:15:28 2004 From: shalabh at cafepy.com (Shalabh Chaturvedi) Date: Wed, 11 Aug 2004 15:15:28 -0700 Subject: remaining decorator syntax options In-Reply-To: References: Message-ID: Steven Bethard wrote: > Shalabh Chaturvedi wrote in message news:... > >>Btw, I think your summary of the current state is good. However I feel a >>new keyword has been pretty much ruled out as well. > > > Can you refer me to some pages that made you feel this way? GvR said > that he "won't rule it out just because of the new keyword": > > http://mail.python.org/pipermail/python-dev/2004-August/047001.html > > I also haven't seen any arguments against keywords that said anything > but basically "introducing a new keyword might break existing code". > Not that this isn't a valid argument, but as Python has gone through a > similar process recently for 'yield', I'd feel more like keywords were > ruled out if I heard some other arguments. > > Steve You're right - it hasn't been entirely ruled out. I just got the feeling reading python-dev that new keywords are shunned unless very convincing reasons are found. Guido's words, from the post you mention: "this is a softening of my position on new keywords". So I doubt a keyword will be picked for decorators, but let's see. Shalabh From http Fri Aug 13 17:39:56 2004 From: http (Paul Rubin) Date: 13 Aug 2004 14:39:56 -0700 Subject: How to sort records in file References: <81a41dd.0408131122.21180d0d@posting.google.com> Message-ID: <7xllgipvir.fsf@ruckus.brouhaha.com> export at hope.cz (Lad) writes: > What is the best( easiest)way how to sort a file? > I have a file where each record consists of 3 fields( 3 words) and I > would like to sort records by the first field( word)in each record. If you're using Linux, the simplest way is with the "sort" command: sort infile -o outfile This will sort files of basically unlimited size, as long as you have enough disk space. The files don't have to fit in memory. Since you're posting on c.l.py, maybe you're really asking how to read the file in sorted order in a Python program: import os sorted = os.popen("sort infile") runs the sort command in an external process. Finally, there's a built-in sorting operation on lists: def compare(a, b): def key(line): return line.split()[0] return cmp(key(a), key(b)) lines = open("infile").readlines() lines.sort(compare) but that requires reading the whole file into memory, etc. From bokr at oz.net Sun Aug 15 14:51:25 2004 From: bokr at oz.net (Bengt Richter) Date: 15 Aug 2004 18:51:25 GMT Subject: Decorators: an outsider's perspective References: <20040814153534.8AC171E4007@bag.python.org> Message-ID: On Sun, 15 Aug 2004 13:43:30 -0400, Paul Morrow wrote: >Istvan Albert wrote: > >> Paul Morrow wrote: >> >> >>> That reminds me of how I once thought about using indentation as a >>> means of denoting code blocks. How idiotic I thought that was. Now I >>> realize the elegance, beauty, 'genius' in that. >> >> >> I disagree. In C (Perl, Java etc) we would do three things, >> write braces, indent and put the semi-colon. In python we replaced >> these three, with a single (the most obvious) one the indentation. >> > >And that's the genius there. Guido (I believe he's the one that came up >with it) realized that those other symbols were unnecessary. The >identation was enough to convey the author's intention. Now of course >this wouldn't have been a very good idea if we (developers as a whole) >used wildly different indentation styles. But we didn't/don't. There's >a conventional way of showing program structure thru indentation that >the majority of us have always used (subordinate code gets indented). > >As Python developers, we have a convention on how we name the first >formal parameter of instance methods too. If you write a method that >follows that convention (uses 'self' as the name of its first parm), >then you don't need to do anything further to inform your readers that >it's an instance method. > > >>> Why don't we all just acknowledge that we are doing this? Why don't >>> we all just admit that a well written instance method uses 'self' as >>> its first argument. And well written static or class methods (as well as >> >> >> If so then, the logically equivalent solution would be to pass self >> as an implicit parameter, say a named parameter self with a default >> reference to itself. I'm not suggesting this behavior, I only point out >> what I think follows from the first example. The end goal is to >> simplify the behavior not overload it and thus add >> further meaning to it. >> > >No, if self was passed implicitly, then you'ld be back in the situation >of having to specify (with additional syntax) which methods are instance >methods. Less is more. Python proves that. > >> I do agree with Chas Emerick in that encoding special behavior in >> variable names is a fragile solution. >> > >Define fragile. If you mean, easy to break, I don't see it. There >would be only one way to define an instance method: name its first >parameter 'self'. There would be only one way to define a class method: >name its first parameter 'klass' or 'cls' (or some other synoynm that we >can all vote on). All other methods would be static methods. > >How is that fragile? > In a narrow context such as distinguishing between methods, classmethods, and staticmethods, ISTM not so fragile. OTOH, generalize the concept too much and you get 'hungarian' naming rules as a way of controlling processing. Perhaps that is what Chas and Istvan were worrying about. I think I pretty much agree with you (Paul), except that I think the test for 'self' (and analogously 'cls') should be a name.startswith(...) test. There are a few nested-scope cases where it is necessary to distinguish two simultaneous and distinct 'self'-parameter bindings, and you need distinct names to avoid shadowing the outer with the inner. No time to look for the example I'm thinking of, but I'm sure you can create one (if Peter Otten doesn't beat you to it ;-) Regards, Bengt Richter From bac at OCF.Berkeley.EDU Mon Aug 9 18:01:29 2004 From: bac at OCF.Berkeley.EDU (Brett C.) Date: Mon, 09 Aug 2004 15:01:29 -0700 Subject: Popular Python projects with lots of pure Python code Message-ID: <4117F439.40805@ocf.berkeley.edu> For my thesis (once the bloody thing stops throwing bugs at me) I am going to need to collect stats on the frequency that atomic types in local variables are applied to various opcodes and methods. That means that I need something to collect stats off of. So I am trying to come up with a list of projects I can use to get my stats from. the stdlib is a no-brainer. Also plan to use Docutils. But beyond those most of the big Python projects I can think of have a ton of C code which is of no use to me. I don't need to be able to run it, just going to be compiling to .py files. Any suggestions? -Brett From http Mon Aug 23 03:57:56 2004 From: http (Paul Rubin) Date: 23 Aug 2004 00:57:56 -0700 Subject: Has anyone implemented BASIC in Python? References: <2oo13eFcj548U1@uni-berlin.de> <2ot30hFeek8nU1@uni-berlin.de> <9h0ji0lvc0be65nuvcugaa3vsq5mcl3ck8@4ax.com> <2otkvkFe7p8oU1@uni-berlin.de> Message-ID: <7xeklyjngb.fsf@ruckus.brouhaha.com> Leif K-Brooks writes: > Is there a (virtual) book you would recommend reading to learn about > writing them? A course isn't really possibly for me, so I'm hoping > that isn't the only option. Structure and Interpretation of Computer Programs, by Abelson and Sussman. Not the easiest book in the world, but by the time you finish it, you'll really understand some things. Full text available from: http://mitpress.mit.edu/sicp/ From fumanchu at amor.org Fri Aug 20 23:25:10 2004 From: fumanchu at amor.org (Robert Brewer) Date: Fri, 20 Aug 2004 20:25:10 -0700 Subject: J2 decorator grammar Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E1A@exchange.hqamor.amorhq.net> Michael Sparks wrote: > decorator: dotted_name [ '(' [arglist] ')' ] > funcdef: ['decorate' ':' NEWLINE INDENT decorators DEDENT ] 'def' NAME parameters ':' suite Would you consider this instead? decorator_suite: expression_stmt | NEWLINE INDENT expression_stmt+ DEDENT funcdef: ['decorate' ':' decorator_suite] 'def' NAME parameters ':' suite Also, where's the most recent copy of your implementation? Robert Brewer MIS Amor Ministries fumanchu at amor.org From max at alcyone.com Thu Aug 5 17:33:43 2004 From: max at alcyone.com (Erik Max Francis) Date: Thu, 05 Aug 2004 14:33:43 -0700 Subject: Quixote vs. Preppy References: <1779534897.20040805105519@MailBlocks.com> Message-ID: <4112A7B7.E30B8764@alcyone.com> Bruce Eckel wrote: > I'm looking for something "closer to Python" to develop certain types > of web systems (rather than going away, forgetting, then coming back > and struggling with the Z-shaped learning curve for anything more than > trivial things in Zope). Based on the Quixote presentation at Pycon, > that looks quite interesting ("web development as if you were a Python > programmer"), but someone also suggested Preppy from Reportlabs: > http://www.reportlab.org/preppy.html > > Can anyone compare/contrast these? Thanks. If all you want is a templating system (Preppy is more of a templating system, not a Web framework), there's also EmPy: http://www.alcyone.com/software/empy/ -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ No need to tell me lies / Am I losing you -- Chante Moore From dalcolmo at vh-s.de Thu Aug 12 03:00:56 2004 From: dalcolmo at vh-s.de (Josef Dalcolmo) Date: Thu, 12 Aug 2004 09:00:56 +0200 Subject: PEP318 References: Message-ID: <20040812090056.00001e31@titan> Hello, I just would like to add my vote against using '@' in the Python language. I use Leo (the intelligent folding editor written in Python), which makes heavy use of @ and using the same character in Python might create some incompatibilities. I don't think @ looks good in ANY context and I don't want Python to start looking as ugly as some other languages. (Though I like how in Oberon - which is ugly otherwise because of its use of uppercase keywords - a variable is declared public by marking it with a '*', like in var*). On many non-English keyboards it isn't exactly simple to type an '@', but since decorators aren't going to be used everywhere, I guess this is a weak point. - Josef From nothanks at nothere.com Wed Aug 25 21:37:27 2004 From: nothanks at nothere.com (Emiliano Molina) Date: Thu, 26 Aug 2004 01:37:27 GMT Subject: Subclassing built-in types In-Reply-To: References: Message-ID: Delaney, Timothy C (Timothy) wrote: > I see a useful reply from Fredrik right there ... > > Tim Delaney Sorry, I don't see any replies to my original post at all. Maybe a server problem. From Scott.Daniels at Acm.Org Sat Aug 28 11:13:56 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 28 Aug 2004 08:13:56 -0700 Subject: Call for signatories for J2 In-Reply-To: References: Message-ID: <4130a2b2$1@nntp0.pdx.net> Peter Otten wrote: > For J2 > > Peter Otten > > Though I don't like "using". > I think it would be great fun to add this to the document index under "J2" as well as the keyword finally decied upon (which begins to look like "using". We all know in great detail what a "J2" is, but in five years it will be great folklore. -Scott David Daniels Scott.Daniels at Acm.Org From dieter at handshake.de Sun Aug 22 13:22:22 2004 From: dieter at handshake.de (Dieter Maurer) Date: 22 Aug 2004 19:22:22 +0200 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> <7x4qmv6cwo.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin writes on 21 Aug 2004 20:59:35 -0700: > ... > Well, whenever I want to write a mainstream application and think of > using Python, my first reaction is that Python is too slow... Maybe, you should drain your reactions :-) About 18 months ago, I proposed to implement an SGML/XML based content management system in Zope/Python because the company went bankrupt that had offered a similar C++ based system we were relying upon. Many of my colleagues objected because they thought Python were too slow. The Zope/Python CMS is now almost ready -- it is much faster than its C++ counterpart. Not because Python is faster than C++ but because a Python application is far easier to tailor and to tweak for efficiency than a C++ one (and because we avoided known design flaws in the C++ system). Dieter From asif at go-away-spammer.com Tue Aug 24 16:58:25 2004 From: asif at go-away-spammer.com (Player) Date: Tue, 24 Aug 2004 21:58:25 +0100 Subject: Begginers questions on different distributions of py Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all Decided to try and teach myself Python again for my 1st language, after having a look at perl again and a few others and finally deciding that if I was ever going to fully teach myself a language it would be Python that would be the one I could adapt to the quickest and easiest. = Basically meaning the syntax seems to really settle well in my brain, more so than any of the other languages :) Anyway first things first, I bought The Python Cookbook for a RW reference and something python related to read in the rw and bounce ideas from. Then I cam to wanting a download of the language, and I had the choice of two distros, Activestates ActivePython and the Python websites original Python distribution. My question is this really, what is the python websites original Python distribution missing that ActiveStates has. And also vice versa - seen as how the Activestates distribution is lagging behind the python websites distribution by a release or two. ActivePython = ActivePython-2.3.2-232-win32-ix86.msi size = 16,687KB Python webiste distribution = Python-2.3.4.exe size = 9,658 KB So what's missing out of the Python distro that is in Activestates distro? And vice versa the other way? :) Thanks in advance M.B - -- ************* The Imagination may be compared to Adam's dream- he awoke and found it truth. John Keats. ************* -----BEGIN PGP SIGNATURE----- Version: PGP 8.0 iQA/AwUBQSur7y/z2sM4qf2WEQIPXQCfbvwCNHslPX9wweIInkCawSrhXSUAoM/m Jym2NIJ/g2Y31xLHLYNUqbm2 =lBN6 -----END PGP SIGNATURE----- From secchi at sssup.it Fri Aug 13 06:52:53 2004 From: secchi at sssup.it (Angelo Secchi) Date: Fri, 13 Aug 2004 12:52:53 +0200 Subject: Blocking the execution of a script Message-ID: <20040813125253.46fcfd86.secchi@sssup.it> Hi, I would like Python to interrupt the execution of a script in case an if condition turns out to be TRUE. What is the proper way to do that? Thanks, a. -- ======================================================== Angelo Secchi PGP Key ID:EA280337 ======================================================== Current Position: Graduate Fellow Scuola Superiore S.Anna Piazza Martiri della Liberta' 33, Pisa, 56127 Italy ph.: +39 050 883365 email: secchi at sssup.it www.sssup.it/~secchi/ ======================================================== -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From nhodgson at bigpond.net.au Thu Aug 12 23:53:05 2004 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Fri, 13 Aug 2004 03:53:05 GMT Subject: A decorator syntax not yet mentioned (I think!) References: Message-ID: Peter Hansen: > paolo veronelli wrote: > > > This 'old' method doesn't allow to prepone it,I think a statement was > > the way to allow this ,but why impone it? > > Sorry, that's not English, and I'm afraid I can't infer what > you mean by "prepone" and "impone"... I thought it was an inversion of "postpone" by someone that thought English was more regular than it is. Trying to differentiate the three decorator positions relative to "def": before, in, and after. Neil From tim.peters at gmail.com Fri Aug 20 15:19:01 2004 From: tim.peters at gmail.com (Tim Peters) Date: Fri, 20 Aug 2004 15:19:01 -0400 Subject: My only complaint about Python In-Reply-To: References: Message-ID: <1f7befae04082012197a6e4c08@mail.gmail.com> [Darren Dale] ... >>> Will the BDFL ever split with Visual Studio? [Tim Peters] >> We should be clear here that this isn't Guido's decision. What you >> get on Windows is what you get on all other platforms in this respect: >> you get what volunteers show up to produce, year after year after >> year. So you get a fine Cygwin port from Jason Tishler, seemingly >> toiling all alone, and you get contributions from at least four >> developers who do use Visual Studio. [Darren] > I meant no disrespect to the developers. Didn't think you did. I'm just saying (a) the BDFL is irrelevant to this particular issue; and, (b) you get what other people give. If nobody with a long-term commitment to a specific Visual Studio alternative appears, then #b rules. > ... > This comes back to the heart of the matter. How do you get volunteers > who dont have access to VS to get involved with Python development? Very few Python contributors have access to VS, but it doesn't matter since most aren't running on Windows either. Even on Windows, VS is usually irrelevant to whether somene can pitch in on reviewing bugs and patches, improving the standard libraries, improving the docs, helping on the newsgroup and mailing lists, keeping python.org healthy, etc. I think it's more of a cultural thing, that Windows users typically have a lower contribution rate than users on other platforms (whether it's C code or anything else). I mentioned Cygwin before, and you can certainly develop C extension modules, for Python, on Windows, using that. Other responders have their own favored VS alternatives. "A problem" is that there's more than one VS alternative! That fragments the relatively-small-anyway community of people who need a VS alternative on Windows. > I think the suggestions here were right on, give Python the ability to > support MinGW out of the box. That's a wish. If it's to be granted, someone has to volunteer to do the work initially, and keep it working as the years go by. Don't expect that one of the current contributors will do so (they're swamped already). IOW, it's not a matter of convincing someone it's a good idea, it's a matter of someone volunteering to do actual, real work. > I thought that a compiler could even be included in a version of the Windows > distribution, but maybe that is taking it too far. That one won't happen -- most Windows Python users don't even know C, and download size is still an issue for many. Even people who want to work on core Python development on Windows using VS need to work from a source tarball instead, or from a CVS checkout. From lars at gustaebel.de Wed Aug 18 05:01:48 2004 From: lars at gustaebel.de (Lars Gustaebel) Date: Wed, 18 Aug 2004 11:01:48 +0200 Subject: can tarfile maintain directory structure? References: Message-ID: On Tue, 17 Aug 2004 21:06:45 -0500, Jeff Epler wrote: > You can use os.walk (or os.path.walk for older versions of Python) to > recurse a directory tree. Here's a simple script to use tarfile and > os.walk: > [snip] Far too complicated... tarfile.py is rather high-level: import tarfile tar = tarfile.open(filename, "w:gz") tar.add(directory) tar.close() The add() method is recursive by default. More information and examples here: http://docs.python.org/lib/module-tarfile.html -- Lars Gust?bel lars at gustaebel.de From info at sgtinfo.com Tue Aug 24 10:23:18 2004 From: info at sgtinfo.com (Gina Clemmer (SGT, Inc.)) Date: Tue, 24 Aug 2004 07:23:18 -0700 Subject: Oklahoma City Demographic Analysis Workshops (September 9th and 10th, 2004) Message-ID: <20040824052555.EDD3C1E4006@bag.python.org> Oklahoma City Demographic Analysis Workshop Announcement- One Day Workshop When: September 9th and 10th, 2004 - 9:00 am to 4:00 pm (One Day Workshop) Where: New Horizons Computer Training Center, 50 Penn Place, 1900 NW Expressway, Suite R305 Oklahoma City, Oklahoma 73118 Fee: $225 w/credit card at time of registration, $249 for check or purchase order Register Now Register online at www.sgtinfo.com or call us at 877.241.6576. The Oklahoma City Demographic Analysis Workshop will teach you to extract, query, download, analyze, and map Census demographic data for OKC and surrounding communities. (Note: Participants may substitute their own community in exercises-all techniques are directly transferable to other communities). Such data can provide grant writers, social researchers and community planners with powerful tools for analyzing community changes. This is a streamlined, ?hands on? workshop where each participant works on their own computer throughout the day. This workshop also provides an introduction to Geographic Information Systems (GIS) which includes a discussion of GIS trends and common uses, where to easily obtain mapping files, a demonstration of the map browser ArcExplorer (included with your materials), hands on practice making basic maps online and suggestions for making effective maps. See a detailed description Materials include: A comprehensive workbook that includes the workshop presentation, exercises, reference materials and a valuable Demographic Data Resource CD. This CD includes useful GIS tools such as ArcExplorer and several shapefiles for all communities in the United States. Materials also include a 60 day trial version of ArcView 8.3, a leading GIS software. Also included is the 2003 US Statistical Abstract which includes an extensive selection of statistics for the United States, with selected data for states, metropolitan areas and cities. This workshop will: Teach you to extract, query, download, analyze, map and present 2000-1990 Census of Population and Housing and 2003 American Community Survey data that includes Poverty, Race/Ethnicity, Age, Housing, Language and Transportation; Teach you to construct a Local Community Change Profile. The Profile is comprised of key demographic variables and customized for OKC and a Census tract within OKC (participants may also substitute their own community); Teach you analytical, demographic and spatial analysis techniques including commonly used mathematical formulas to transform raw data into compelling information; Teach you about Census geography including common problems such as working with non-Census boundaries, analyzing change over time despite boundary changes and how to use new mapping functionality recently built in to American Factfinder; Provide you with exceptional materials that you can use immediately to assist with social research and analysis. Former Workshop Participants' Comments: View Other Participants' Comments Oklahoma University, Research and Evaluation Center (2003) "Very helpful update on the new technology available from the census bureau and the thematic maps are extremely important and very much under utilized." Oklahoma University, Institute For Public Affairs (2003) "Thanks very much. I wasn't sure this would be beneficial but it exceeded my expectations in every way. This was an excellent use of my time!" City of Edmond, Oklahoma (2003) "Very informative. Every city planner and grant writer should attend this class." Oklahoma Department of Human Services (2003) "Beneficial, Enjoyable and learned new demographic census processes and the materials were very helpful." SmartGirl Technologies is a social research company located in Portland, Oregon. For more information about the workshop, who we are and what we do, check out our website at www.sgtinfo.com. If do not want to receive further announcements, click here and simply send us a blank email. We will immediately take you off of the announcement list. You may also reply to this email with the word "delete" in the subject line. Note: Under no circumstance will we share your email with any other party or person. -------------- next part -------------- An HTML attachment was scrubbed... URL: From anthonybaxter at gmail.com Thu Aug 26 10:53:51 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 27 Aug 2004 00:53:51 +1000 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: On Thu, 26 Aug 2004 14:40:18 GMT, Arthur wrote: > >IMO, to change it inside of a function def should be (but isn't) as easy > >as... > > > > >>> def foo(): > > ... """ I am foo """ > > ... __doc__ = __doc__ + 'indeed' > > > >Paul > > Yes. Not only do I follow, but I think we came to exactly the same > place, from very different directions, and coming from what I sense is > very different backgrounds. > > Its just that I don't think many others seem to find that as > interesting as I happen to. Not so much that, as running out of ways to restate myself. The proposed syntax above still requires magic handling of double-under variables in a function, and a new namespace. I can't see how you can think that this is a _good_ thing. From enrique.palomo at xgs-spain.com Wed Aug 18 03:48:32 2004 From: enrique.palomo at xgs-spain.com (enrique) Date: Wed, 18 Aug 2004 09:48:32 +0200 Subject: need help before... Message-ID: Hello all, before i begin to code an application i would like to hear from the python masters. The application must be a dispatcher with a windows-like interface. Mainly: A file is received in a folder (a) That file is moved to another folder (b) The files in b folder must be modified by a script Once modified, moved to a different folder (c) All the files in c folder must be sent via ftp to another machine. All, must be automatic. For the interface i thought using wxpython&boa, where an user can see the files and their states. Im a newbie, but i think i must use processes or threads...am i wrong?? Any help will be welcomed. Thanks **AVISO DE CONFIDENCIALIDAD** La informaci?n contenida en este mensaje y archivos es privada y confidencial estando dirigida solamente al destinatario. Si Ud. ha recibido esta informaci?n por error, por favor, proceda a su inmediata destrucci?n. Cualquier opini?n o punto de vista contenido en este mensaje corresponde al remitente y necesariamente no representa la opini?n del GRUPO XEROX. **CONFIDENTIAL HEADER** This email and any files are private and confidential and intended solely for the use of the addressee(s). If you have received this e-mail in error please delete it immediately. Any views or opinions presented in this e-mail are solely those of the sender and do not necessarily represent those of XEROX GROUP. From shalabh at cafepy.com Wed Aug 25 17:25:19 2004 From: shalabh at cafepy.com (Shalabh Chaturvedi) Date: Wed, 25 Aug 2004 14:25:19 -0700 Subject: Enumerate object is destroyed by casting? In-Reply-To: References: Message-ID: Nick Jacobson wrote: > Casting an 'enumerate' object destroys it?? Is that supposed to > happen, or is it a bug? > > > For example: > a = ['a', 'b', 'c'] > e = enumerate(a) > print dict(e) > print dict(e) > > > Result: > {0: 'a', 1: 'b', 2: 'c'} > {} This is not casting (there is no casting in Python). It is creating a new dict from an iterable. enumerate(a) creates an iterable that runs over the items *once*. After that there is nothing left to return. HTH, Shalabh From iketo2 at netscape.net Sat Aug 28 12:12:51 2004 From: iketo2 at netscape.net (Isaac To) Date: 29 Aug 2004 00:12:51 +0800 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1ry8k0d2az.fsf@rovereto.ifi.uio.no> <87acwgvy51.fsf@sinken.local.csis.hku.hk> <2pb36dFibuj3U1@uni-berlin.de> <41309d32$0$65611$a1866201@newsreader.visi.com> <1gj8pg5.1e6z0kiprvfxuN%aleaxit@yahoo.com> Message-ID: <87acwfutq4.fsf@sinken.local.csis.hku.hk> >>>>> "Alex" == Alex Martelli writes: Alex> list(a, b, c) instead of [a, b, c] would not be horribly Alex> heavy syntax, I think. On the other hand, [b*b for b in c] is too sweet to lose as well. :) Regards, Isaac. From brian at sweetapp.com Mon Aug 16 05:47:10 2004 From: brian at sweetapp.com (Brian Quinlan) Date: Mon, 16 Aug 2004 11:47:10 +0200 Subject: C++ app calling python script repeatedly In-Reply-To: <41207a1c$0$29872$79c14f64@nan-newsreader-05.noos.net> References: <41207a1c$0$29872$79c14f64@nan-newsreader-05.noos.net> Message-ID: <4120829E.70803@sweetapp.com> nik wrote: > How could I solve this? Can the user run a python program alongside my > C++ app, and the app call a method on the users program? I.e. can the > script I call be part of a global process in some way? Or, are there > other ways to go about this? > > nik You might want to think about how you would do this if the entire application were written in Python. It sounds like "theScript.py" is a module that provides some sort of service to the rest of your application. So you would probably be best to import it once and then call a function in that module every time that you need to. Cheers, Brian From claird at lairds.us Tue Aug 31 15:08:04 2004 From: claird at lairds.us (Cameron Laird) Date: Tue, 31 Aug 2004 19:08:04 GMT Subject: Size of a remote URL References: <41336331$0$65608$a1866201@newsreader.visi.com> Message-ID: <6fse02-qu6.ln1@lairds.us> In article <41336331$0$65608$a1866201 at newsreader.visi.com>, Grant Edwards wrote: >On 2004-08-30, Justin wrote: > >> I want to track the download of files in a progress bar. I asume I >> need the final size to do that so I can compare it to the current size >> on disk. > >Correct. > >> Le tme know if you know anything > >I know lots of things. :) > >But, if the server doesn't tell you the content length in the >HTTP headers, there's nothing you can do. . . . I'll reinforce Grant's message: there are quite a few Web addresses whose server begins delivery of content before it, the server, has yet calculated the whole "page", much less its size. Your require- ment, as stated, is simply not possible in full generality. From ajsiegel at optonline.com Fri Aug 27 19:53:25 2004 From: ajsiegel at optonline.com (Arthur) Date: Fri, 27 Aug 2004 23:53:25 GMT Subject: Call for signatories for J2 References: Message-ID: On Fri, 27 Aug 2004 09:30:32 -0700, "Robert Brewer" wrote: >Anthony Baxter wrote: >> Note that Robert has sent the completed proposal to python-dev, >> and in fine Python tradition, buggered off for the weekend. >> So I'm not entirely sure it's worthwhile posting more >> for/against messages now. > >I'll continue to collect them, and post updates on Monday. So feel free. > Against. With some commitment. I have not read the J2 psper, but think it might in essence be covered as a potential (good faith) counter-argument to it: That a certain sense of Python aesthetics asks for this functionality to be stripped of any aesthetic pretense. A little aside to the compiler Whereas 'using: staticmethod' might say something, 'using: MyTransform' says only that, and Python should not provide cover to this kind of non-expressiveness. We are looking to save some typing. Let's save typing. @ With that I consider that Python has maintained a sense of forthrightness, that will probably not allow me to escape my begrudging infatuation with it. With J2 ... well my adjustment period will be extended a bit.. Art From http Wed Aug 18 15:35:39 2004 From: http (Paul Rubin) Date: 18 Aug 2004 12:35:39 -0700 Subject: Embedding Python in Python References: <7xu0v0l2be.fsf@ruckus.brouhaha.com> Message-ID: <7x3c2kkzn8.fsf@ruckus.brouhaha.com> JCM writes: > If you're concerned about security, another possibility is to parse > the user's code and look for anything potentially dangerous. You'll > need to be aggressive, but I believe it's possible. For example, > disallow exec statements, the identifier "eval", any identifier of > __this__ form, import statements, etc. This is overly restrictive, > but it will provide security. By the time you're done with all that, you may as well design a new restricted language and interpret just that. Hint: e = vars()['__builtins__'].eval print e('2+2') Even Java keeps getting new holes found, and Python is not anywhere near Java when it comes to this kind of thing. From squirrel at WPI.EDU Tue Aug 3 12:18:36 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 3 Aug 2004 12:18:36 -0400 Subject: dislin interfaced with tkinter In-Reply-To: <34c9b4fa.0408030743.594417f9@posting.google.com> References: <34c9b4fa.0408030743.594417f9@posting.google.com> Message-ID: On 3 Aug 2004, eesun wrote: > I've downloaded the dislin package for the scientific plotting. And I > have already created the application window with Tkinter (menu, > canvas, status bar..). I want to integrate the Dislin plotting into > the Tkinter application. For ex: show the dislin result on the Tkinter > Canvas. Anyone can help? I don't know anything about dislin; scanning through its web site, it looks like a commercial C program. The only two ways I can think of to integrate something like this into a Tkinter (or any toolkit) application are: 1) If there's a way to pass dislin a window ID in which to draw (it doesn't look like it; its openwin() function uses internal IDs), you can create a Frame widget and pass the value returned by its .winfo_id() method to the library. 2) If you can find no better way, as a last resort you can have dislin write its output to an image file, and read the file using the Python Imaging Library (PIL), which is integrated very well into Tkinter (you can use its ImageTk class to create an image suitable for a Label, Canvas, or what-have-you). If your application isn't dependant on dislin and doesn't need 3D graphing capabilities, consider switching to matplotlib (http://matplotlib.sf.net/), which provieds the embedability you want. From b.niemann at betternet.de Wed Aug 25 06:19:29 2004 From: b.niemann at betternet.de (Benjamin Niemann) Date: Wed, 25 Aug 2004 12:19:29 +0200 Subject: urllib hangs In-Reply-To: <2p35phFg2vehU1@uni-berlin.de> References: <2p35phFg2vehU1@uni-berlin.de> Message-ID: Bernd Kaiser wrote: > I also would use a few Threads, they will speed up your script. He didn't mention any performance issues. Don't try to optimize for speed before you have a valid complaint about the program being to slow - especially if optimization involves threads! From sbabbitt at commspeed.net Tue Aug 24 22:49:06 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Tue, 24 Aug 2004 19:49:06 -0700 Subject: Begginers questions on different distributions of py References: Message-ID: <1093402641.581593@news.commspeed.net> Go with python.org and don't write just windows programs use a cross platform GUI like wxPython. Tom From rnichol_rrc at yahoo.com Sun Aug 22 16:44:57 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Sun, 22 Aug 2004 15:44:57 -0500 Subject: Python future performance and speed In-Reply-To: References: <278de0e.0408211605.426e5129@posting.google.com> <7x4qmv6cwo.fsf@ruckus.brouhaha.com> Message-ID: Sam Holden wrote: > After all python has been used as the scripting engine for a number of > commercial games - a domain that certainly cares about speed. Not the graphics though and that is where the speed is really needed. From steven.bethard at gmail.com Fri Aug 6 14:14:19 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Fri, 6 Aug 2004 11:14:19 -0700 Subject: elements of decorator syntax suggestions In-Reply-To: References: Message-ID: Anthony Baxter wrote: > An excellent list! If you don't mind, I might steal this format for the PEP. > It allows for a lot more alternatives to be covered off in a smaller space > (since many proposals are minor variations on an existing proposal, and > share the same problems). Please feel free to -- glad it was helpful. =) Thanks so much for all your work already! Steve -- You can wordify anything if you just verb it. - Bucky Katt, Get Fuzzy From drs at remove-to-send-mail-ecpsoftware.com Wed Aug 25 17:16:38 2004 From: drs at remove-to-send-mail-ecpsoftware.com (drs) Date: Wed, 25 Aug 2004 16:16:38 -0500 Subject: MSI Installer Problem: can't install 2.4a2 on new install of Win2kSP2 References: Message-ID: <412d0156$1_1@newspeer2.tds.net> "Richard Hanson" wrote in message news:vnipi0ldsgchqqiti1q19qtd5d70ju17p0 at 4ax.com... > Am I overlooking something simple...? How about SP3, or even 4? From max at alcyone.com Sun Aug 15 04:26:57 2004 From: max at alcyone.com (Erik Max Francis) Date: Sun, 15 Aug 2004 01:26:57 -0700 Subject: Is python ircbot.py slow? References: Message-ID: <411F1E51.265A3C04@alcyone.com> Dfenestr8 wrote: > I haven't really looked into how they bench mark these things, but as > far > as I know, python has always been considered a reasonably fast > scripting > language. Even back when the standarad server was a p450 it was > considered > fast enough. > > Now that most servers are 1.2Ghz +, surely speed isn't even an issue? Even on an incredibly slow machine, it would be unimportant. After all, why would one thing an IRC bot needs speed? An IRC bot is going to be tremendously I/O bound, it's barely doing any CPU computations. Your friend doesn't know what he's talking about. -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ I will always remember / This moment -- Sade From greg.lindstrom at novasyshealth.com Wed Aug 18 08:23:50 2004 From: greg.lindstrom at novasyshealth.com (Greg Lindstrom) Date: Wed, 18 Aug 2004 07:23:50 -0500 Subject: Access to Oracle Message-ID: <039d01c4851e$38241b60$054b12ac@D18SYX41> Greetings- I am running Python 2.3.3 on HP-UX and would like to access an Oracle 9i database. Looking through the vaults, I see 4 or 5 modules that might work and was wondering if anyone is currently hitting Oracle and what are you using. I get to build a new system from the ground up and the powers that be are allowing me to do it in Python. I'm quite happy. Thanks for your help, --greg Greg Lindstrom (501) 975-4859 NovaSys Health greg.lindstrom at novasyshealth.com "We are the music makers, and we are the dreamers of dreams" W.W. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This email and any attachments to it are privileged and confidential and are intended solely for use of the individual or entity to which they are addressed. If the reader of this message is not the intended recipient, any use, distribution, or copying of this communication, or disclosure of all or any part of its content to any other person, is strictly prohibited. If you have received this communication in error, please notify the sender by replying to this message and destroy this message and delete any copies held in your electronic files. Thank you. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From tjreedy at udel.edu Wed Aug 4 18:29:05 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 4 Aug 2004 18:29:05 -0400 Subject: help: Unit test fixture returning the same object References: <9895e897.0408031533.26720ba0@posting.google.com><9895e897.0408040851.21ac7caa@posting.google.com> Message-ID: "Peter Hansen" wrote in message news:ovednbdu0IcWh4zcRVn-vQ at powergate.ca... > Michael McCracken wrote: > > > So, I'm still surprised that id() would point to the same object every > > time, but I'm willing to believe it. > > Don't think of it using those words. Think of it as "the new > object is being created at the same address as the old object > was at, so it's likely the first object created since the old > one was destroyed", or something like that. At least that way > it's much easier to believe, much less of a coincidence, and > actually something that a number of people have encountered > over the years, though often with similar expressions of surprise > or disbelief. :-) Yes, yes. When an object is destroyed, its id is free for reuse, whatever the implementation. For an unambiguous example: >>> id([1]), id([2]) (9692456, 9692456) Terry J. Reedy From jack at performancedrivers.com Thu Aug 19 19:21:31 2004 From: jack at performancedrivers.com (Jack Diederich) Date: Thu, 19 Aug 2004 19:21:31 -0400 Subject: problem using C-bindings In-Reply-To: References: Message-ID: <20040819232131.GE23725@performancedrivers.com> On Fri, Aug 20, 2004 at 12:14:05AM +0200, eq wrote: > Am Thu, 19 Aug 2004 17:45:45 -0400 schrieb Jack Diederich: > > > On Thu, Aug 19, 2004 at 10:32:15PM +0200, eq wrote: > >> Hi, > >> > >> I'm trying to create a program(written in C) that does the following > >> things using embedded Python: > >> 1. Create a module(say, "MyModule") > >> 2. Create a class in that module(say, "MyClass") > >> 3. Create a function in that module(say, "MyFunction") > > [snip] > >> class_dict=PyDict_New(); > >> class_name=PyString_FromString("MyClass"); > >> class=PyClass_New(NULL,class_dict,class_name); > >> PyDict_SetItemString(module_dict,"MyClass",class); > > [snip] > > > > Take a look at Modules/xxsubtype.c in the source distribution. > > It is an example of how to subtype a builtin. xxmodule.c shows > > how to make a class from scratch. Both are out of date but a good > > sarting spot. > > > Hm, perhaps I over-complicated my problem: > I don't need a full python-class in pure C. I just need to create a > (python!) function(a dynamic one, not a static C function) and attach it > to an already existing python-class just by using C-calls. > I try to do this by compiling the function's code with: > > pyfunc_code=Py_CompileString(func_code,"",Py_file_input); > > where func_code could be something like "print 'hello'" and then I try to > make a function out of this by calling: > > pyfunc=PyFunction_New(pyfunc_code,dict); > > where dict is the global namespace for the function. > What I now want is to attach this function to the already created class > "MyClass". > In that case I would see how xxmodule.c exports methods in the xx_methods array and then in your python code have the class method call that exported method. import xxmodule class MyClass(object): def xxfunc(self, arg): return xxmodule.xxfunc(self.someval, arg) In practice I've never had a class that wasn't all python or all C but I have written small helper functions in C that are called from python. -Jack From nhodgson at bigpond.net.au Fri Aug 6 21:27:50 2004 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sat, 07 Aug 2004 01:27:50 GMT Subject: Proposal: require 7-bit source str's References: <4112AC7B.1060508@v.loewis.de> <411343D7.3020604@v.loewis.de> <411353A3.8090502@v.loewis.de> <4113759E.2070405@v.loewis.de> <4113E755.8060205@v.loewis.de> <41140349.6090202@v.loewis.de> Message-ID: Martin v. L?wis: > For some source encodings (namely the CJK ones), conversion to UTF-8 > is absolutely necessary even for proper lexical analysis, as the > byte that represents a backslash in ASCII might be the first byte > of a two-byte sequence. Do you have a link to such an encoding? I understand 0x5c, '\' is often displayed as a yen sign, but haven't seen it as the start byte of a multi byte character. Regarding the 's' string prefix in the proposal, adding more prefixes damages ease of understanding particularly when used in combination. There should be a very strong need before another is introduced: I'd really hate to be trying to work out the meaning of: r$tu"/Raw/ $interpolated, translated Unicode string" Neil From zathras at thwackety.com Sun Aug 22 07:35:18 2004 From: zathras at thwackety.com (Michael Sparks) Date: Sun, 22 Aug 2004 12:35:18 +0100 Subject: [PATCH] RE: J2 decorator grammar References: Message-ID: <412889c8$0$81159$ed2619ec@ptn-nntp-reader02.plus.net> Michael Sparks wrote: > On Sun, 22 Aug 2004, Anthony Baxter wrote: >> On Sun, 22 Aug 2004 01:41:58 +0100 (BST), Michael Sparks wrote >> > The patch can be found here: >> > * http://thwackety.com/decorator_syntax_J2.patch >> >> Good to see. There's a few more bits than this that need to be >> done, though - see http://www.python.org/sf/979728 for the original >> @decorator patch, this should show you what else needs to be >> changed. > > Many thanks for the pointer. I'll try and make sure I cover all the bases, > but I suspect I'll miss something, but I'll try not to :) One useful thing this has shown up is "decorate" clashes with the test suite for decorators since it contains: def funcattrs(**kwds): def decorate(func): func.__dict__.update(kwds) return func return decorate So some other keyword is definitely preferable. Currently I'm swayed heavily by arguments in favour of "using" since it doesn't make sense to have: using: staticmethod memoize funcattrs(author="Joe Blogs") Standing alone - it's pretty clear it *needs* something following. Whereas "declare" doesn't to a large extent. For example, the following reads as ambiguious (to someone new) class Foo: declare: author("Joe Bloggs") def bar(bla): pass To someone new does this mean Joe Bloggs wrote the method or class? The using version strikes me personally as clearer: class Foo: using: author("Joe Bloggs") def bar(bla): pass Also, I haven't seen a similar clash to decorate for "using" as yet. Checking google, I can't find anything that defines a function "using" (search terms: "def using" python ), but can find a variety projects (including Pyrex) that define a function called declare (search terms: "def declare" python). Michael. From abra9823 at mail.usyd.edu.au Wed Aug 4 09:33:19 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Wed, 4 Aug 2004 23:33:19 +1000 Subject: EOL - scanning single-quoted string In-Reply-To: <4110E3B3.8040709@geochemsource.com> References: <1091625659.4110e2bb6db73@www-mail.usyd.edu.au> <4110E3B3.8040709@geochemsource.com> Message-ID: <1091626399.4110e59f5dbc1@www-mail.usyd.edu.au> hi! i got the escape character bit, but i still get an error >>> str='/My Documents/um_ajay.xml' >>> re.subn('/', '\\', str) Traceback (most recent call last): File "", line 1, in ? File "c:\Python23\lib\sre.py", line 151, in subn return _compile(pattern, 0).subn(repl, string, count) File "c:\Python23\lib\sre.py", line 258, in _subx template = _compile_repl(template, pattern) File "c:\Python23\lib\sre.py", line 245, in _compile_repl raise error, v # invalid expression sre_constants.error: bogus escape (end of line) any ideas? cheers -- Ajay Brar, CS Honours 2004 Smart Internet Technology Research Group Quoting Gandalf : > > Hi Ajay! > > The problem is that you must represent the backslash as '\\'. This is > because a simple backslash opens an escape sequence. > For example: > > '\n' - this is new line > '\t' - this is TAB > '\\' - this is the backslash itself > > You should use this: > > re.subn('/', '\\', str) > > The other way is to use raw strings. You can read more about these > things here: > > http://docs.python.org/ref/strings.html > > Best, > > Laci 2.0 > > > > > Ajay wrote: > > >hi! > > > >I am developing an application for a pocket pc. > >i have a small gui which allows users to select files using a file > dialog > >box. however the file, selected is represented as '/My Documents/test' > >which when i try to open gives me an error. > >so what i would like to do is replace '/' by the windows '\' > >however when i try > >str='/My Documents/test' > >re.subn('/', '\', str) > > > >i get an error saying - SyntaxError: EOL while scanning single-quoted > >string > > > >how can i replace the slashes. > > > >thanks > > > >cheers > > > >-- > >Ajay Brar, > >CS Honours 2004 > >Smart Internet Technology Research Group > > > > > > > > > > > >---------------------------------------------------------------- > >This message was sent using IMP, the Internet Messaging Program. > > > > > > ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From casey at zope.com Tue Aug 10 11:27:39 2004 From: casey at zope.com (Casey Duncan) Date: Tue, 10 Aug 2004 11:27:39 -0400 Subject: how to dispatch objects depending on their class References: <4118dd4a$1@maser.urz.unibas.ch> Message-ID: <20040810112739.064a947f.casey@zope.com> It should not be a problem to use the actual class object as keys in the dict and the functions as values. No need to convert the class to strings. So why can't they be static methods of the classes exactly? That would be simpler, however the dict will work efficiently. -Casey On Tue, 10 Aug 2004 16:35:48 +0200 Curzio Basso wrote: > > Hi all. > > I have a couple of question regarding the following situation: > > class A(object): > def __init__(self): > pass > > class B(object): > def __init__(self): > A.__init__(self) > > def func(object): > if isinstance(object, A): > do_something_with_A(object) > elif isinstance(object, B): > do_something_with_B(object) > > Note that in my real problem I cannot move the logic of func to the > class A and B because I will have a hierarchy also for func. Then I > need a way to dispatch the object to the right function. I thought > about using a dictionary, like: > > FUNC = {"": do_something_with_A, > "": do_something_with_B} > > def func(object): > FUNC[type(object)](object) > > But: (1) I am not sure of what the type(object) function return. In > this case A and B are in the __main__ namespace (assuming this is how > is called), but if they are in a module; (2) I am not sure if it is > efficient; and finally (3): probably there is a better way to do it > (this is always a safe assumption). > > I hope my problem is clear, and excuse me if I am asking about > something that is common knowledge, but I don't even know what to > google for... > > thanks, curzio > -- > http://mail.python.org/mailman/listinfo/python-list > From Hate at Spam.com Mon Aug 30 23:15:12 2004 From: Hate at Spam.com (A.M) Date: Tue, 31 Aug 2004 03:15:12 GMT Subject: Intelisence Message-ID: <43SYc.121080$UTP.113615@twister01.bloor.is.net.cable.rogers.com> Hi, Is there any inelisence IDE (like visual studio) for python? Thanks, Alan From b.niemann at betternet.de Wed Aug 18 08:18:43 2004 From: b.niemann at betternet.de (Benjamin Niemann) Date: Wed, 18 Aug 2004 14:18:43 +0200 Subject: anonymous function? In-Reply-To: References: Message-ID: > t = threading.Timer(10.0, sendCheckCommand() ) This will *execute* sendCheckCommand at this point (what you mean by 'it works 1 time'), implicitly return None, which is passed to the Timer constructor, which in turn raises the mentioned exception. Omit the () to get a reference to the function. > I think this is an > anonymous (in Java it is) function and is really not meant to be a > "real" class function. I would prefer: t = threading.Timer(10.0, lambda: self.connection.message("CHECK")) or for compatibility with older python versions: t = threading.Timer(10.0, lambda s=self: s.connection.message("CHECK")) From mark_bottjer at hotmail.com Sun Aug 8 18:41:09 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Sun, 08 Aug 2004 18:41:09 -0400 Subject: @decorator syntax is sugar, but for what exactly? In-Reply-To: <4116239e$1@news.012.net.il> References: <4115b53a$1@nntp0.pdx.net> <4116239e$1@news.012.net.il> Message-ID: <4116ac05$1@nntp.zianet.com> Avner Ben wrote: > So, if the problem is to rid class definitions of bizarre function > calls, stuck in the middle of nowhere, that actually add to the > structure of the class (and which other OO languages solve by > legitimate syntax), I am dissapointed to observe that functuion > decorators do not do a complete job after all. While true, I find this less of a disappointment than you. There are two large differences between class/staticmethods and properties: methods act like functions, while properties act like variables; and properties have multiple associated code blocks (the getter and setter), while methods have only one. @decorator as designed applies only to functions, and is simply inappropriate for properties. Disappointing, perhaps, but not surprising--variables and functions *are* fundamentally different. > Talking about properties, I like the C# way of defining them, which > is straightforward and readable. The property begins like a method, > but has no argument list and includes a getter function with no > arguments and a setter function with one argument. Adapted to Python, > it would look something like: > > class hasProperty: > def __init__(self,aProperty='') > self.aProperty = aProperty > def AProperty: > def get(self): > return self.aProperty > def set(self,value): > self.aProperty = value > obj = hasProperty() > obj.AProperty = 'test' > print obj.AProperty I, personally, don't like the idea of overloading def in this way. To me, 'def' defines something that looks and acts like a function, just like 'class' defines something that looks and acts like a class, or 'while' defines something which looks and acts like a loop. AProperty is does not act like a function, so using def would be misleading. I agree, though, that the best way to handle properties is though some sort of extended syntax. After all, we already have *a* way of doing it, we just don't like how it looks. To fix this, we need to compress the various pieces (name, storage, getter, setter, etc.) into a single declarative construct. (In fact, this is a large part of my problem with the proposed @ syntax: it isn't part of the function it modifies, but rather some sort of odd prefix. OTOH, the prefix notation would work with variables as well as functions, which is not possible with an infix notation: @global; x=10. Whether or not this is actually of any benefit is left as an exercise for the reader.) I've thought for a while now that Python is skirting a breakthrough in how it treats statements. Python took a step in the right direction with generalizing iteration via generators, and I see utility in generalizing the idea of statements as well. In particular, what I'd like to see is the ability to define new *types* of statement. Consider again the classmethod, staticmethod, and property. If these were defined as extended statements, we could code them more naturally: class C: c = 'Hi there!' class_def cm( c, a, b): # class method return 'C(%r).cm( %r, %r) -> %r' % (id(c), a, b, c.c) static_def sm( a, b): # static method return 'C.sm( %r, %r) -> %r' % (a, b, a % b) def im( s, a, b): # instance method return 'C(%r).im( %r, %r) -> %r' % (id(s), a, b, (a % b) * self.a) def __init__( s, a): # constructor s.a.__init__( a) property a: def __init__( s, v): __set__( s, v) def __get__( s): print 'C(%r).a -> %r' % (s, s.__a) return a def __set__( s, v): print 'C(%r).a <- %r' % (s, v) a = v >>> o = C( 3.1415) C().a <- 3.1415 >>> o.cm( 2, 3) C().cm( 2, 3) -> 'Hi there!' >>> o.sm( 4, 5) C.sm( 4, 5) -> 4 >>> o.im( 6, 7) C().a -> 3.1415 C.im( 6, 7) -> 18.849 >>> o.a C().a -> 3.1415 3.1415 In the above, 'class' is as we know them. 'class_def' and 'static_def' are statements similar to 'def', but define a class method or static method, respectively. Finally, 'property' is a statement which defines a new property, and takes a code block expected to contain functions with predefined names. Each of these could be implemented natively, or the way we would do it manually today. Taking this to the extreme, all existing statement types (class, def, print, del, etc.) could be recast as these generalized statements. We could even allow subclassing of existing statements to modify their behavior (for example, class_def subclassing def to make the new function a class method). Strong Kung-Fu indeed. Scary, but strong. Obviously, creating new control constructs is not something we'd want to do every day, as it can be a great way to obfuscate code beyond all hope of understanding--but the same is true of meta-classes. Just because it *could* be abused doesn't mean that it would be. On the flip side, this doesn't address some of the more creative uses of decorators that people have been proposing. A new statement type, like class_def, effectively applies a fixed set of decorators (in the case of class_def, it applies only classmethod); if we want more variety, we still need decorators. They are independent ideas, even though they can overlap a bit. I have absolutely no idea as to *how* any of this would be accomplished, mind you, but it would be *terribly* nifty. -- Mark From unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom Wed Aug 25 16:15:45 2004 From: unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom (Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.) Date: Wed, 25 Aug 2004 22:15:45 +0200 Subject: Python + Erlang = Candygram References: Message-ID: Cool ! From greg at cosc.canterbury.ac.nz Wed Aug 25 23:14:48 2004 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Thu, 26 Aug 2004 15:14:48 +1200 Subject: On consensus decision-making (was Re: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WEDONE?) In-Reply-To: References: Message-ID: <2p52tbFh1eb5U1@uni-berlin.de> Peter Hansen wrote: > > Has anything really changed? Would it now be correct to say > that C1 has a serious chance of being accepted if someone would > just update the implementation to the state and quality (?) of > the other two? In a recent python-dev message, Guido said that, if it were the agreed-upon alternative, he would reconsider it. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From pm_mon at yahoo.com Fri Aug 27 18:39:51 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Fri, 27 Aug 2004 18:39:51 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Anthony Baxter wrote: > On Thu, 26 Aug 2004 16:09:42 -0400, Paul Morrow wrote: > >>Yes, it doesn't seem all that complex, although I'm not sure that >>everyone reading this understands them and their subtleties. The >>following is an excerpt from >>http://docs.python.org/tut/node11.html#SECTION0011200000000000000000 >> >>"A namespace is a mapping from names to objects. Most namespaces are >>currently implemented as Python dictionaries, but that's normally not >>noticeable in any way (except for performance), and it may change in the >>future. Examples of namespaces are: the set of built-in names (functions >>such as abs(), and built-in exception names); the global names in a >>module; and the local names in a function invocation. In a sense the set >>of attributes of an object also form a namespace." > > >>When I talk about namespaces, I include all of the above, including the >>sense mentioned in the last line. So an object's attributes constitute >>a namespace too. Therefore __doc__, being an attribute of the function >>object, is in the function object's /namespace/. And note that this is >>*not* a new namespace; it's been there all along. > > > "In a sense" is the bit you're missing here. You can't just hand-wave > and say that it's a namespace. It's *not* a namespace. If it was, you > could do any of these: > No I didn't miss it (I read that bit). In a sense, every object has it's own namespace. So that means that every class, every module, every function has a namespace (in a sense). The namespace (the mapping from names to objects) is stored in each object's special __dict__ attribute. Ok, and this is certainly apparent with classes. >>> class Foo: ... """docstring for Foo""" ... >>> Foo.__doc__ 'docstring for Foo' >>> Foo.__dict__.keys() ['__module__', '__doc__'] >>> And because of the parallels between the above class definition of Foo and the following function definition of baz, I would expect the same behavior. >>> def baz(): ... """docstring of baz""" ... >>> baz.__doc__ 'docstring of baz' >>> baz.__dict__.keys() [] Say what? Why didn't the Python system put baz's docstring into it's namespace (__dict__)? And where did it put it? I would like to understand the answers to these questions. Can you answer them (will you)? If not, can you please point me at something that documents what's going on here? Thanks. Paul From JBrouwersAtProphICyDotCom at no.spam.net Fri Aug 20 14:39:31 2004 From: JBrouwersAtProphICyDotCom at no.spam.net (Jean Brouwers) Date: Fri, 20 Aug 2004 18:39:31 GMT Subject: speed References: Message-ID: <200820041139338175%JBrouwersAtProphICyDotCom@no.spam.net> Another Python parser generator to look into is SimpleParse/mxTextTools We use it to parse and process large log files. In our case, a typical grammar contains over 250 productions and parsing a log file of 180 Klines (100 MB) takes approx 3 min. Processing the result from the parse step requires an additional 3 mins. This on a 2.4 GHz Xeon machine running RedHat 8. Obviously these figures are very grammar and application specific. Your milage may vary. /Jean Brouwers PS) A good reference is David Mertz' book "Text Processing in Python" or several articles on (t)his web page In article , Ayose wrote: > . From nytimes at swiftdsl.com.au Tue Aug 17 10:23:46 2004 From: nytimes at swiftdsl.com.au (huy) Date: Wed, 18 Aug 2004 00:23:46 +1000 Subject: SockerServer.TCPServer problem Message-ID: <4122147e$0$27220$61ce578d@news.syd.swiftdsl.com.au> Hi All, Can someone explain why this bit of code can't keep up with some java code which spawns about 200 (threads) simultaneous connections each sending about 10 mesgs each. I basically don't get the 2000 connections i expect on the python side. I end up with some number very close on different runs eg. 1989, 1972, 1992 etc. Any ideas ? Huy #!/usr/local/bin/python import socket import struct import time import SocketServer import thread from datetime import datetime import os import datetime import random LISTENING_PORT = 1600 cnt = 0 class PDAHandler(SocketServer.BaseRequestHandler): def handle(self): global cnt cnt += 1 s = self.request dlen = s.recv(4, socket.MSG_WAITALL) print "Received: ", dlen, cnt, " from ", s.getpeername() dataLen = struct.unpack("!i", dlen) data = s.recv(dataLen[0]) f = file("aaa/recv%02d.txt" % cnt, "w+") f.write(data) f.close() def start_servers(): msg_server = SocketServer.TCPServer(("", LISTENING_PORT), PDAHandler) msg_server.serve_forever() if __name__ == "__main__": start_servers() From gandalf at geochemsource.com Wed Aug 11 09:46:02 2004 From: gandalf at geochemsource.com (Gandalf) Date: Wed, 11 Aug 2004 15:46:02 +0200 Subject: Integers have docstring for int() In-Reply-To: <59e9fd3a04081105087366db98@mail.gmail.com> References: <59e9fd3a04081105087366db98@mail.gmail.com> Message-ID: <411A231A.4010303@geochemsource.com> > > >I accidentally discovered that all the basic types in Python have >docstrings that describe the functions to create them. For integers, >you get: > Acually, they are not functions. They are built-in types. For example, try this: Python 2.3.3 (#1, Mar 8 2004, 14:26:02) [GCC 3.3.3 [FreeBSD] 20031106] on freebsd5 Type "help", "copyright", "credits" or "license" for more information. >>> int >>> It is not a function but a type. I believe one of the most wanted changes in the language is about unfying built-in types and (new-style) classes. A built-in type is not a class. However, it is very similar. If you 'call' it, it acts as a constructor and creates an object of that type. It is the same with these: float,str,tuple,list,long,unicode and probably many others. >Similarly, (1.0).__doc__ gives the docstring for float(), "".__doc__ >gives it for str(), [].__doc__ gives it for list(), and {}.__doc__ >gives it for dict(). > >This seems a little unexpected to me; is there any particular reason >for this behaviour? > Of course. For example, the literal 1 is an integer object. Integer objects inherit all their methods and attributes from their base class. Acually, they are objects of built-in types but it is almost the same. I think that this is very cool. :-) Best, L 2.0 From robin at reportlab.com Wed Aug 11 13:54:42 2004 From: robin at reportlab.com (Robin Becker) Date: Wed, 11 Aug 2004 18:54:42 +0100 Subject: Python Decorators Voting Form In-Reply-To: References: Message-ID: <411A5D62.6020904@chamonix.reportlab.co.uk> Doug Holton wrote: > Here is a voting form where you can vote between 3 of the most popular > alternatives for the new Python decorator syntax: > http://wiki.wxpython.org/index.cgi/PythonDecoratorsPoll > > Please vote for which one you prefer the most, and feel free to leave > your comments as well. This is just to allow us to count up everyone's > preferences and maybe help narrow down the alternatives to only 1 or 2 > like Guido wants. > > I know it's not fair to only show 3 options, but these 3 appear to have > the most number of different people supporting them based on mailing > list traffic. If you like one option but want a different symbol (like > "|") or an additional keyword (like "using"), you can vote for it anyway > and leave your comment. surely a none of the above is also desirable and it's better to include all of the many syntaxes to avoid biassing the outcome. -- Robin Becker From in.aqua.scribis at nl.invalid Sat Aug 21 16:02:31 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Sat, 21 Aug 2004 22:02:31 +0200 Subject: backward compatibility? Message-ID: So how serious are plans to remove things from Python, like lambda and map and reduce? I am just starting out with Python and if there is a danger that the programs I write today won't work next year, I rather invest my time in another language. I might try Ruby, or stick with Perl. -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From lbates at swamisoft.com Mon Aug 9 18:45:52 2004 From: lbates at swamisoft.com (Larry Bates) Date: Mon, 9 Aug 2004 17:45:52 -0500 Subject: Popular Python projects with lots of pure Python code References: Message-ID: ReportLab? HTH, Larry Bates Syscon, Inc. "Brett C." wrote in message news:mailman.1418.1092088893.5135.python-list at python.org... > For my thesis (once the bloody thing stops throwing bugs at me) I am > going to need to collect stats on the frequency that atomic types in > local variables are applied to various opcodes and methods. That means > that I need something to collect stats off of. > > So I am trying to come up with a list of projects I can use to get my > stats from. the stdlib is a no-brainer. Also plan to use Docutils. > But beyond those most of the big Python projects I can think of have a > ton of C code which is of no use to me. I don't need to be able to run > it, just going to be compiling to .py files. > > Any suggestions? > > -Brett From graeme.longman at tangozebra.com Wed Aug 4 12:29:18 2004 From: graeme.longman at tangozebra.com (Graeme Longman) Date: Wed, 4 Aug 2004 17:29:18 +0100 Subject: How to force a single number to be a tuple In-Reply-To: Message-ID: Hi, Couldn't you say: >>> y = 2, >>> y (2,) Cheers. Graeme > -----Original Message----- > From: python-list-bounces+graeme.longman=tangozebra.com at python.org > [mailto:python-list-bounces+graeme.longman=tangozebra.com at python.org]On > Behalf Of Jinming Xu > Sent: 04 August 2004 17:26 > To: python-list at python.org > Subject: How to force a single number to be a tuple > > > Hi Folks, > > I have a number sequence, which is put into a tuple like this: > > y=2, 3.0, 4.5 > > I can manipulate the sequence as a tuple when it has more than 1 > number. But > when the sequence has only 1 number, like > > y=2 > > I have trouble to manipulate it as a tuple. I guess there must > be a way to > forece a single number to be a tuple. Could anyone please tell me that? > > Thanks, > > Jinming > > _________________________________________________________________ > FREE pop-up blocking with the new MSN Toolbar ? get it now! > http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/ > > -- > http://mail.python.org/mailman/listinfo/python-list > > ________________________________________________________________________ > This e-mail has been scanned for all viruses by Star Internet. The > service is powered by MessageLabs. For more information on a proactive > anti-virus service working around the clock, around the globe, visit: > http://www.star.net.uk > ________________________________________________________________________ > --- > Incoming mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.732 / Virus Database: 486 - Release Date: 29/07/2004 > --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.732 / Virus Database: 486 - Release Date: 29/07/2004 ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From dw-google.com at botanicus.net Mon Aug 30 01:32:17 2004 From: dw-google.com at botanicus.net (David M. Wilson) Date: 29 Aug 2004 22:32:17 -0700 Subject: Announcing PyCs, a new Python-like language on .Net References: Message-ID: <99dce321.0408292132.36ef381e@posting.google.com> Mark Hahn wrote in message news:... > Please join the PyCs team. The only effort involved is particpating in a > low-traffic, high-content, mailing list. You will be able to influence the > design of the latest and greatest dynamic language. Hi there. What are you trying to achieve? You have yet to complete Prothon or even stabilise it for long enough to let me get a good overview of it. Might I suggest you take a step back and actually think about what you are doing rather than just implementing whatever happens to be considered cool today. Also judging by what I've seen of Prothon and read here, neither of your proposed languages are either Python-like or related to this group. Might I suggest you sit down with a paper and a pen and work out what problem you are actually trying to solve, it is starting to get rather embarrassing to watch the antics here. At the very least could you spell check your postings before sending them. There are also much better forums to discuss language development on than comp.lang.python. Sorry for the flame, but you really need it. David. From peter at engcorp.com Fri Aug 6 13:36:11 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 06 Aug 2004 13:36:11 -0400 Subject: directory path access In-Reply-To: References: Message-ID: Yong Wang wrote: > In my memmory, there is a system command to display all directory paths the python program has accessed. > What is command format ? I only remember use sys.path.append or insert to add the path. Do you just mean this? import sys print sys.path Thats not a "command", per se, it's just displaying the current value of the internal path that Python uses to find modules for import. sys.path is a list, and that's why sys.path.append() is used to add to it. -Peter From benm at cyber.com.au Thu Aug 26 02:34:33 2004 From: benm at cyber.com.au (Ben McGinnes) Date: Thu, 26 Aug 2004 16:34:33 +1000 Subject: Idle problem In-Reply-To: <6haXc.183583$8_6.163380@attbi_s04>; from brent.hughes@comcast.net on Thu, Aug 26, 2004 at 12:37:23AM +0000 References: <6haXc.183583$8_6.163380@attbi_s04> Message-ID: <20040826163433.B7326@devious.adversary.org> Brent W. Hughes(brent.hughes at comcast.net)@Thu, Aug 26, 2004 at 12:37:23AM +0000: > Sometimes when I try to start up idle.py (by double-clicking on the icon), I > get the message: > Python subprocess socket error: Connection refused, retrying.... > It repeats the message a couple of times and then prints: > Connection to Idle failed, exiting. I just fired up Idle and it displayed the following message: **************************************************************** Personal firewall software may warn about the connection IDLE makes to its subprocess using this computer's internal loopback interface. This connection is not visible on any external interface and no data is sent to or received from the Internet. **************************************************************** Which means you could be running some firewall software locally which is not allowing Idle to open the sockets it requires. You should change this to allow all connections on the loopback. Regards, Ben -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 181 bytes Desc: not available URL: From ellisjb at my-deja.com Sun Aug 22 01:11:39 2004 From: ellisjb at my-deja.com (ellisjb at my-deja.com) Date: 21 Aug 2004 22:11:39 -0700 Subject: Python future performance and speed Message-ID: I was goint to post that the myth of "python isn't fast enough" has been pretty much dispelled in these enlightened times, but I guess I was too optimistic. :) -Jonathan Paul Rubin wrote: > Well, whenever I want to write a mainstream application and think of > using Python, my first reaction is that Python is too slow... From anne.wangnick at t-online.de Tue Aug 31 15:13:00 2004 From: anne.wangnick at t-online.de (Anne Wangnick) Date: Tue, 31 Aug 2004 21:13:00 +0200 Subject: Immutable sequence types lacking index() method Message-ID: Dear all, I don't get why the index() method is only defined for mutable sequence types. This is not what I expected. Shouldn't this be added in Python? Is there such a PEP already? Regards, Sebastian Wangnick From cemerick at snowtide.com Sat Aug 14 01:05:48 2004 From: cemerick at snowtide.com (Chas Emerick) Date: Sat, 14 Aug 2004 01:05:48 -0400 Subject: Decorators: an outsider's perspective Message-ID: <9ADC3170-EDAF-11D8-9F63-000A95B336F2@snowtide.com> I thought I'd finally break my lurker status here by passing along a comment I made in connection with this weblog post , one of many deriding the controversial feature of @decorators. Feel free to flame away, especially if the regulars here think I'm beating a dead horse :-): By no means am I an expert in Python (I get paid for writing Java, although my hobby projects have been in Lisp over the past few years), but this @decorator flap has made no sense to me at all. The best argument against the new syntax is that it will impede noobs (like myself, I suppose) from picking up the language. I think nothing could be further from the truth, for one reason: action-at-a-distance is *always* bad. The first time I saw this, I almost fell out of my chair: def blah (args): ....[insert 50/100/200 lines here] blah = staticmethod(blah) That's BAD. That, my friends, is tough to wrap one's mind around, for the exact reason that, unless one reads through an entire module, the critical staticmethod call might not even be seen. That's a pretty devestating blow to the ability of a noob (or hell, anyone for that matter) to learn what's going on in some code. So, when I see: @staticmethod def blah (args): ....[insert 100 lines] I say, YES! Sure, decorators can get complicated, as exemplified by some of the examples provided in the post. However, just because something is complicated, or even not the greatest approach in some cases, doesn't invalidate it. Take recursion: a concept and practice that noobs trip over almost as a rule, and an approach that is constantly abused and overused in inappropriate situations. However, that surely doesn't mean that recursion should be disallowed, or scorned even. It means it should be respected, taught well, and used when appropriate. Decorators surely fall into the same category. Regards, Chas Emerick From martin at v.loewis.de Mon Aug 9 16:59:16 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 09 Aug 2004 22:59:16 +0200 Subject: PEP 263 status check In-Reply-To: References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> Message-ID: <4117E5A4.9060106@v.loewis.de> Dieter Maurer wrote: > I hope, it will never come... Your hope will not be fulfilled. Some version of Python *will* require that all non-ASCII source code contains an encoding declarations. Read PEP 263, which has already been accepted. Regards, Martin From noone at here.com Sun Aug 15 10:10:07 2004 From: noone at here.com (Calvin) Date: Sun, 15 Aug 2004 15:10:07 +0100 Subject: Python secure? Message-ID: Hi to both of you, For some reason I can't seem to reply to the post, hence my posting this as a new topic Sorry I should have said I'm new to programming let alone Python. I wish to know whether Python is secure as an exe for a commercial product. i.e. can someone see your code more easily than in say using another language. We're not talking financial / security type software here just a basic windows app. Thanks From jeff at ccvcorp.com Fri Aug 20 15:47:05 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 20 Aug 2004 12:47:05 -0700 Subject: My only complaint about Python In-Reply-To: <87isbepaiy.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> References: <87isbepaiy.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Message-ID: <10icl8fn39skq3e@corp.supernews.com> 510046470588-0001 at t-online.de wrote: >flab ba writes: > > >>with the free Visual C++ Toolkit. Instructions are here: >> >> > >all humbug. Visual C++ is nowhere near free, it's all proprietary. > > That's free-as-in-beer, not Free-as-in-speech. It's a shame that, at least in English, the most natural word to use for each of these two different concepts just happens to be the same word. But such is the case. (I don't think it's practical to try to convince everyone, worldwide, to refer to it as 'gratis' and 'liberte'...) And given that it *is* the case, it would be much more pleasant if people could use the word for both of its meanings without being criticized by people who are philosophically devoted to only one of those meanings. Jeff Shannon Technician/Programmer Credit International From outpost at rumblefish.org Thu Aug 5 18:55:55 2004 From: outpost at rumblefish.org (Thomas D'Tak) Date: Fri, 06 Aug 2004 00:55:55 +0200 Subject: Python milestone releases Message-ID: Hi everybody! Recently, I am having more and more problems with the fact that my Python version is far ahead of the Python versions I have to write scripts for (CGI servers, LAN servers & clients etc. of customers, ISPs etc.). Sometimes, these Python versions reach back to Python 2.0. The question is now, how to handle this kind of problems? I do not want to complain here that Python is developing too fast; and I do not want to criticize Python's system of version numbers. But I want to ask for resp. suggest something like *official Python milestone releases*. (Please correct me if something like that does already exist and I am just not aware of it.) Official Python milestone release statements should discourage the use of older versions. Moreover, not each and every Python release should be a milestone release (clearly). Having milestone releases would make it easier to suggest to customers, ISPs etc. to install a new Python version (the mile- stone). Having milestones would put some pressure on them. (Well, that sounds quite negative: 'pressure'; but I think you know what I mean. Often, a server gets installed once and sees nothing else but security updates after that; getting a new version of a software package on such a server can be quite hard if you are not the admin resp. are not allowed to install your own version of the software package.) Another solution would be to stick to Python 2.0 forever -where 'forever' means the time span until the release of Python 3.0- (but I really do not like that idea :-) Having milestones (not too often) would also simplify a lot of other things; e.g. I would not have to study 'What's new in Python ...' each and every time I have to write scripts for an older version of Python. The 'older' version would simply be the last milestone and I would have to know about two Python versions only: the milestone and the most recent one. How do you handle the above kind of problems resp. what do you think about *official* Python milestones? Thanks in advance for your answers! Th. From tom at scoosh.com Wed Aug 18 17:49:05 2004 From: tom at scoosh.com (tom at scoosh.com) Date: Wed, 18 Aug 2004 22:49:05 +0100 Subject: 44t4t Message-ID: From export at hope.cz Tue Aug 17 12:04:19 2004 From: export at hope.cz (Lad) Date: 17 Aug 2004 09:04:19 -0700 Subject: News server(NNTP library) and Python References: <81a41dd.0408162307.3eb1ea36@posting.google.com> Message-ID: <81a41dd.0408170533.3dd46292@posting.google.com> Duncan Booth wrote in message news:... > export at hope.cz (Lad) wrote in > news:81a41dd.0408162307.3eb1ea36 at posting.google.com: > > > I have a program that can send posts to a news server.The problem is > > that I must find a free usenet(news) server that allows posting, which > > is not easy. For this reason I would like to make a modification in my > > program so that the program can act in a similar way how real news > > server, that is to spread the new posts to another news server. But I > > do not have much knowledge about the way how news server chooses > > another news server to send it's new posting. > > Can anybody give me a hint( idea)? > > If you are running on Windows and just want a news server for testing, get > hold of a copy of Hamster (http://tglsoft.de/), this will act as both news > server and news client and lets you set up your own local newsgroups. > > If you meant that you actually want a free news server to post to real > newsgroups, then sign up with news.individual.net. You have to agree to > some reasonable terms and conditions, but it is free. > > Real news-servers transfer news between each other by having a list of > servers to which they will forward news they have received, so to run a > real news server you need a peering agreement with an existing server, and > you aren't going to get that. What you can do though is to write a program > which works in the same sort of way as Hamster: i.e. it acts as a client to > one or more upstream news-servers while also acting as a server. This isn't > suitable for running a full news feed but works well when you have > comparatively few newsgroups. Thanks a lot for the explanation Lad From narshe at gmail.com Thu Aug 26 14:38:08 2004 From: narshe at gmail.com (Josh Close) Date: Thu, 26 Aug 2004 13:38:08 -0500 Subject: asynchat connection timeout Message-ID: <4a0cafe204082611381a96ef10@mail.gmail.com> I'm using asynchat and I'm getting an error error: (110, 'Connection timed out') This is ok, but how do I set what the timeout is? -Josh From ptmcg at austin.rr._bogus_.com Mon Aug 9 09:12:43 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 09 Aug 2004 13:12:43 GMT Subject: recursive list comprehension References: Message-ID: "SimonVC" wrote in message news:fa156589.0408090402.5ef3c40b at posting.google.com... > Is there a way to do this as a list comprehension? > > >>> def recu(alist, blist=[]): > ... if len(alist)==0: print blist > ... for i in range(len(alist)): > ... blist.append(alist.pop(i)) > ... recu(alist, blist) > ... alist.insert(i, blist.pop()) > > >>> recu(list("abc")) > ['a', 'b', 'c'] > ['a', 'c', 'b'] > ['b', 'a', 'c'] > ['b', 'c', 'a'] > ['c', 'a', 'b'] > ['c', 'b', 'a'] > > > Cheers > SimonVC > > keywords: python recursive permutations algorithm combination jumble Perhaps this cookbook recipe would be of help to you: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/204297 It describes how to access the current list comp from within the list comp itself. -- Paul From ialbert at mailblocks.com Sun Aug 15 11:42:51 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Sun, 15 Aug 2004 11:42:51 -0400 Subject: Python secure? In-Reply-To: References: Message-ID: Calvin wrote: > Sorry I should have said I'm new to programming let alone Python. I wish to > know whether Python is secure as an exe for a commercial product. i.e. can > someone see your code more easily than in say using another language. We're > not talking financial / security type software here just a basic windows > app. You have still not defined the problem properly. 1. do you mean how easy is to decompile your program: to recover source code from the executable one. 2. do you mean how easy is to extract/bypass some some essential (authentication, passwords) elements in your program? As for a comparison to other languages, both java and C# can be decompiled. Note that no method exists that would recreate the original source code exactly as you wrote it, it only creates a source code that will compile to the same executable, and, depending on the situation that source code could be hard to interpret. I might sound a little bit cynical here, but if you, as you state, are new to programming I can assure you that there will be quite a while until you produce a piece of software that will be worth the effort to decompile. This should be your least concern at this point. Istvan. From dperl at rogers.com Mon Aug 30 01:39:53 2004 From: dperl at rogers.com (Dan Perl) Date: Mon, 30 Aug 2004 05:39:53 GMT Subject: initializing mutable class attributes Message-ID: There is something with initializing mutable class attributes that I am struggling with. I'll use an example to explain: class Father: attr1=None # this is OK attr2=[ ] # this is wrong def foo(self, data): self.attr1=data self.attr2.append(data) The initialization of attr1 is obviously OK, all instances of Father redefine it in the method foo. But the initialization of attr2 is wrong because all the instances of Father end up sharing the same value. Maybe that is desired sometimes, but usually it is just a bug. So the only solution I see to this is to initialize attr2 in __init__: class Father: attr1=None def __init__(self): self.attr2=[ ] This is already awkward because there is such a difference between attr1 and attr2. But moreover, I think this forces subclasses of Father to do something like this: class Child (Father): def __init__(self): Father.__init__(self) self.attr3=[ ] I find this even more awkward because many people will forget to do it. Clearly, this is then a more general issue with __init__, but I think it is accentuated by the fact that you HAVE TO HAVE __init__ in order to initialize attributes that are mutable. Is there something I don't know here and there is a better way to do this in Python? I would like to get a better solution or otherwise start a discussion. From russblau at hotmail.com Mon Aug 16 10:34:25 2004 From: russblau at hotmail.com (Russell Blau) Date: Mon, 16 Aug 2004 10:34:25 -0400 Subject: random / lists References: Message-ID: <2obuvjF8q553U1@uni-berlin.de> "M. Clift" wrote in message news:cformj$vso$1 at newsg2.svr.pol.co.uk... > Hi Wes, > > Thanks for responding. > > What I want is a system that controls the direction in a generated list. If > the user selects a number a letter is choosen for each number from at random > from an array. That's fine and easy to do. The hard part is, is that no > letter can be repeated with only one letter interveining and the letters can > only follow each other under certain rules. > > These being : > 1. 'a' can be followed by any letter > 2. 'b' can only be followed by 'c' > 3. 'c' can be followed by 'a' or 'd' > 4 'd' can be followed by 'a' or 'c' > > Really it doesn't matter what these rules are for the time being it's just > working out a way to control the outcome of a list of unknown size. How about if you define a dictionary mapping each letter to a list of the letters that are allowed to follow it, then use random.choice() to pick one member of the list. For example, mapping = {'a': ['b', 'c', 'd'], 'b': ['c'], 'c': ['a', 'd'], 'd': ['a', 'c']} then after you added the last letter to l, you could just do allowed = mapping[l[-1]][:] # nneds to be a copy because it may get modified if l[-2] in allowed: # no letter can appear two out of three places allowed.remove[l[-2]] l.append(random.choice(allowed) Of course, this doesn't account for every case (like, it won't work if l is the empty list), and it may not satisfy all your desired rules, but it's a start. -- I don't actually read my hotmail account, but you can replace hotmail with excite if you really want to reach me. From mark_bottjer at hotmail.com Wed Aug 11 13:52:46 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Wed, 11 Aug 2004 13:52:46 -0400 Subject: PEP-0318 In-Reply-To: References: <41122FC2.1080608@interlink.com.au> <4114152f@nntp.zianet.com> <4116bc20$1@nntp.zianet.com> <6NCdncg4ssq28orcRVn-uQ@powergate.ca> Message-ID: <411a5cee$1@nntp.zianet.com> Arthur wrote: > And either intuitively, or consciously, he is doing something that > offsets it from something truly intergrated into the core of the > language. By breakling all of his own rules. But it *isn't* part of the core language. I think that's the whole point. @decorator does something that no other statement in Python does, so why should it *look* like a normal statement? Or are you suggesting that a keyword should be used instead of a symbol? I must not understand your argument. -- Mark From howard.stearns at charter.net Mon Aug 9 10:11:58 2004 From: howard.stearns at charter.net (Howard Stearns) Date: Mon, 09 Aug 2004 09:11:58 -0500 Subject: internal functions [Re: How do you feel ?] In-Reply-To: References: Message-ID: <4117862E.3000907@charter.net> Sorry. When I said "define a named function in a top-level assignment", I didn't just mean using a reference to a previously defined function (i.e., it's name), I meant actually defining the function in the assignment. If you haven't done this sort of thing for years, I could see it being hard to imagine why I would want to do this. After all, isn't the code clearer if we define the function with a name ahead of time? And doesn't the debugger work better with functions that have a name? Well, I agree with this for what might be called middle-ground uses. However, I do a lot of work with very simple cases and very complicated ones. In very simple cases, the code is more cluttered if I have to define the function separately. Now, when the function is simple, Python let's me define an anonymous function in the assignment. That's cool. But I also have cases where the assignment is simple, but maybe the function isn't. This came up for me when I tried to populate generic functions with methods. (See generic functions thread. Though it looks like decorators will soon help me out here...) In very complex cases, I lament the shear distance between the function definition and the one place in the code where it is referenced. (Again, maybe decorators will help. Cool.) Peter Hansen wrote: > Howard Stearns wrote: > >> The one thing I've found annoying is that I haven't yet discovered how >> to do whatever I want in lambda expressions. I have top-level >> assignments where I'd like create a function to use as the the value >> being assigned. I don't know how to define a named function in a >> top-level assignment, and a lambda won't allow me to use 'try' and >> other statements -- just expressions. Or am I looking at things wrong? > > > What do you mean by "top-level assignment"? If it's the same > meaning most Python programmers would give it, you just do this: > > def somefunc(): > pass > > topLevelName = somefunc > > There's your top-level assignment of a named function. Probably > not what you meant, but can you clarify please? > > -Peter From nk at ebox.gr Mon Aug 9 18:31:52 2004 From: nk at ebox.gr (Nikos Kouremenos) Date: Tue, 10 Aug 2004 01:31:52 +0300 Subject: VB-like GUI designer? In-Reply-To: References: Message-ID: Fred wrote: > Hi, > > I'm currently checking out Python as an alternative to VB.Net > to moving from VB, but can't find a GUI designer that is as good as > VB. > > I tried wxDesigner and wxGlade, but neither lets me move the widgets > around. I also tried Dialogblocks, but it seems to only handle C++ or > XRC, not Python. > > Is this all there is, or is there a gem I missed? > > Thank you > Fred. this is because of the way wxWidgets. If you can't get used to it, then you can always try PyQT (which I believe you will find more close to your designer needs). For Windows you need to buy a license though. PyGTK also won't do it for you (same as wxWidgets style). You can also parse the XML files that exist for every widget [XRC, .glade, and so on] Next time do a better 'web search'. Good Luck, Nikos From alf at merlin.fayauffre.org Thu Aug 19 04:35:53 2004 From: alf at merlin.fayauffre.org (Alexandre Fayolle) Date: Thu, 19 Aug 2004 08:35:53 +0000 (UTC) Subject: age of Python programmers References: Message-ID: Hi, Age 30. Started programming at 15 on an Atari 520STe, using GFA Basic... Been full time Python programmer for 4 years. -- Alexandre Fayolle LOGILAB, Paris (France). http://www.logilab.com http://www.logilab.fr http://www.logilab.org From joeschey at earthlink.net Wed Aug 25 15:54:30 2004 From: joeschey at earthlink.net (Joe S) Date: 25 Aug 2004 12:54:30 -0700 Subject: Dynamic command on Menu items? Message-ID: <2e3fe5bf.0408251154.74bc6243@posting.google.com> (Python newbie alert..only 1 week's experience) I want to create several menu items based upon a config file. In this config file are label, function and a parameter. I want to show label in the menu, then when it's chosen, call function with the given parameter. How can I do the correct equivalent of the following (which definitely doesn't work)? l='Zooks' f='func' p='Got Zooks' M.menu.add_command(label=l, command=lambda: f(p)) so that when I pick 'Zooks' from the menu, func gets called with 'Got Zooks'. Joe From peter at engcorp.com Wed Aug 4 23:05:10 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 04 Aug 2004 23:05:10 -0400 Subject: The term "Protocol" In-Reply-To: References: <1f7befae04080117515cbb0ca9@mail.gmail.com> <6910338109.20040801192523@ <393390620.20040804124623@MailBlocks.com> Message-ID: <38ednYb1NLx7PozcRVn-uA@powergate.ca> Bruce Eckel wrote: > Monday, August 2, 2004, 8:44:38 AM, Aahz wrote: >>Alex Martelli gave an excellent presentation on Design Patterns at OSCON, >>where he made the point that "interface" is roughly equivalent to syntax, >>whereas "protocol" is roughly equivalent to syntax plus semantics. In >>other words, computer langauges rarely (if ever -- although I suppose >>Eiffel comes close) enforce protocols in any meaningful way. > > But what would the syntax be in Python? -- there is none. Perhaps you > mean that in Java a protocol would be an interface plus agreed-upon > semantics, whereas in Python the protocol would be the agreed-upon > (e.g. "latent") interface plus the agreed-upon semantics. In a sense, > both the syntax and semantics would be latent; they would only be > exposed and tested during use, since there is no formalized way to > define them. > > In Python, of course, you could simply use a class with "pass" methods > everywhere to define a protocol. If there were some way to write > assertions about the protocol you could include those in the class. My reading of Alex' description seems to be the opposite. By definining protocol to include the semantics, you are basically ensuring that an implementation with "pass" would not be valid, except for a useless protocol that defined null semantics. But yes, what you say about the "latency" is true, and that's how Python works in many areas. You need decent automated tests to catch certain errors in Python, though tools like PyChecker can help with some of the ones that compilers will find in statically typed languages. -Peter From export at hope.cz Thu Aug 19 15:09:07 2004 From: export at hope.cz (Lad) Date: 19 Aug 2004 12:09:07 -0700 Subject: Py2Exe PROBLEM References: <81a41dd.0408190023.44d34c44@posting.google.com> <2tGdncgUvpKRD7ncRVn-oQ@powergate.ca> Message-ID: <81a41dd.0408191109.1fc98889@posting.google.com> Peter Hansen wrote in message news:<2tGdncgUvpKRD7ncRVn-oQ at powergate.ca>... > Lad wrote: > > > I try to make an exe file from my script with help of Py2exe but I am > > not successfull. > ... > > When compilation finishes I get: > > > > The following modules appear to be missing > > ['blackbox', 'timing', 'rgs.py'] > > > > Can you please help me how to solve the problem? > > If you explain what problem you are actually having. > > Are you assuming simply because of that warning message that > it didn't work? What happens when you try to run the resulting > .exe file? > > Note that py2exe will sometimes complain about modules that > are not actually required for the program to run. > > Also please explain what "blackbox" and "timing" are, if > they are part of the problem. > > Finally (and this might be the whole problem), you seem > to be using "import rgs.py" when you really meant to use > just "import rgs". You don't import Python modules using > the full filename of the source file... > > -Peter Dear Peter, Thank you for your help. Yes, I changed import rgs.py to import rgs but I still receive >>The following modules appear to be missing > > ['blackbox', 'timing', 'rgs.py'] When I try to start the exe file I get Traceback (most recent call last): File "rgs.pyc", line 561, in OnFileHistory File "pickle.pyc", line 1390, in load File "pickle.pyc", line 872, in load File "pickle.pyc", line 985, in load_string LookupError: unknown encoding: string-escape Can you please help again? Lad From jason at tishler.net Thu Aug 19 07:09:08 2004 From: jason at tishler.net (Jason Tishler) Date: Thu, 19 Aug 2004 07:09:08 -0400 Subject: IDLE under Cygwin doesn't show toolbar menu In-Reply-To: <56cfb0e3.0408181608.794fed82@posting.google.com> References: <56cfb0e3.0408181608.794fed82@posting.google.com> Message-ID: <20040819110908.GB77948@tishler.net> On Wed, Aug 18, 2004 at 06:05:25PM -0700, Porky Pig Jr wrote: > Just want to check if anyone else ever ran into this problem and what > was the workaround -- before I contact Cygwin folks. See the following: http://sf.net/tracker/?func=detail&atid=105470&aid=786827&group_id=5470 Any help debugging this problem would be greatly appreciated. Thanks, Jason -- PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6 From bokr at oz.net Sun Aug 22 01:27:59 2004 From: bokr at oz.net (Bengt Richter) Date: 22 Aug 2004 05:27:59 GMT Subject: J2 decorator grammar References: Message-ID: On Sat, 21 Aug 2004 17:22:43 -0700, "Robert Brewer" wrote: [...] >For that reason (and others), I plan not to promote any form of the word >"decorate". We can start having that conversation now if you want. ;) > What about just using def: deco1 deco2('with','parameters') any_expression_returning_a_callable_allowing_a_single_arg_call def foo(): pass also perhaps allowing def:deco1 def foo():pass grepping for def will then show easily what functions have "decorators" Regards, Bengt Richter From bh at intevation.de Thu Aug 26 14:19:49 2004 From: bh at intevation.de (Bernhard Herzog) Date: Thu, 26 Aug 2004 20:19:49 +0200 Subject: Call for signatories for J2 References: Message-ID: "Robert Brewer" writes: >> For > > Isn't *anyone* going to vote against? I'm against it. I don't find the arguments in favor of J2 convincing, and to my eyes the pie-syntax reads better. Also, I don't think "using" is a good choice for the keyword. A different keyword would not change my mind, though. Bernhard -- Intevation GmbH http://intevation.de/ Skencil http://sketch.sourceforge.net/ Thuban http://thuban.intevation.org/ From jerf at jerf.org Fri Aug 27 13:05:37 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Fri, 27 Aug 2004 17:05:37 GMT Subject: mixing statements into J2 References: Message-ID: On Thu, 26 Aug 2004 10:36:08 -0700, Robert Brewer wrote: > using: > if test: > memoize > else: > synchronize > classmethod > def foo(self, *args): > stuff(args) Others have pointed out the illegality of this, I would point out there is a legal way for those who may not realize it: if test: myDec = memoize else: myDec = syncronize using: myDec classmethod def foo(self, *args): stuff(*args) I quite frequently do this to create modules that adapt to the environment they are in... e.g., I don't require Zope support but if you have it I will dynamically derive a class from Persistant, or object otherwise: base = object try: import ZODB base = ZODB.Persistant except: # one of those rare cases where a bare except doesn't matter pass class Whatever(base): pass (I don't actually do this anywhere but I do the equivalent elsewhere in my code.) This is one of those things that keeps me from ever wanting to go back to C++; you shouldn't make a habit out of this but when you need it there is no substitute. From russblau at hotmail.com Mon Aug 30 09:11:06 2004 From: russblau at hotmail.com (Russell Blau) Date: Mon, 30 Aug 2004 09:11:06 -0400 Subject: IDLE does not start on WinXP References: Message-ID: <2pgnbbFkhertU1@uni-berlin.de> "George Carman" wrote in message news:mailman.2568.1093726031.5135.python-list at python.org... > Please excuse the following mailing, I do not have access to a news server > and cannot post to comp.lang.python. >>> python-list at python.org is comp.lang.python True > I recently installed Python 2.3.4 on WinXP. Command line interpreter works > fine but the IDLE GUI will not start. When run from a commandline I get the > following traceback. Both WinXP and McAfee firewalls are disabled. Any > suggestions would be appreciated. Since the traceback indicates that the error arose in a command related to socket communication, I think the first thing you should check is your firewall software. You should allow connections to 127.0.0.1 (the loopback to your own machine). (If you've installed XP Service Pack 2, you now have firewall software whether you knew it or not.) -- I don't actually read my hotmail account, but you can replace hotmail with excite if you really want to reach me. From h.b.furuseth at usit.uio.no Sat Aug 7 19:49:37 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 08 Aug 2004 01:49:37 +0200 Subject: Decorator syntax References: <38ednYT1NLz1P4zcRVn-uA@powergate.ca> <2njp58F1jj1dU1@uni-berlin.de> Message-ID: Yawar Amin wrote: > How about > > def foo(a, b, c): > foo.accepts = (int, int, list) > foo.author = 'Chris King' That already has a different meaning: Function foo sets those attributes on itself each time it is called. They should be set once, before the function is called. $ python2.3 >>> def foo(a, b, c): ... foo.accepts = (int, int, list) ... foo.author = 'Chris King' ... >>> foo.author Traceback (most recent call last): File "", line 1, in ? AttributeError: 'function' object has no attribute 'author' >>> foo(1,2,3) >>> foo.author 'Chris King' -- Hallvard From mb at muenster.de Fri Aug 20 10:39:05 2004 From: mb at muenster.de (Martin Bless) Date: Fri, 20 Aug 2004 14:39:05 GMT Subject: age of Python programmers References: Message-ID: <41260864.726953@news.muenster.de> ["Lucas Raab" ] >One thing I've always kind of wondered is what is the average age of a >Python programmer?? 49. Started 1974 punching cards for an IBM 1130 machine. A highlight: Fill a complete program with two interrupt routines into a single punch card. It would write something like "job defect" on the typewriter console. Just one card means: you can use just 80 words of code on that 16-bit machine. And since a column on a card only had 12 rows your could use only a special subset of availabe machine instructions. Then there came the TRS-80. I'm still proud of the way I stored my Z80 assembler routines in REM lines of a basic program. That way I could easily merge und bundle those "machine language" routines. Yes, I lived very much in the book with the ROM disassembly listing those days ;-) And I remember taking a (INTER-) LISP course. I liked it alot but never managed to be productive with LISP. Now I have what I need to have fun *and* accomplish useful things: Python! Many thanks to all who help developing this cool language! MB - Martin Bless From greg at cosc.canterbury.ac.nz Fri Aug 13 00:01:07 2004 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Fri, 13 Aug 2004 16:01:07 +1200 Subject: Popular Python projects with lots of pure Python code In-Reply-To: References: Message-ID: <2o2so3F68r28U1@uni-berlin.de> Brett C. wrote: > For my thesis (once the bloody thing stops throwing bugs at me) I am > going to need to collect stats on the frequency that atomic types in > local variables are applied to various opcodes and methods. That means > that I need something to collect stats off of. You're welcome to munge through the code of my 3 main Python projects: http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex http://www.cosc.canterbury.ac.nz/~greg/python/Plex http://www.cosc.canterbury.ac.nz/~greg/python_gui -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From cjw at sympatico.ca Mon Aug 16 10:24:50 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Mon, 16 Aug 2004 10:24:50 -0400 Subject: PEP 318 decorators are not Decorators In-Reply-To: References: Message-ID: Arien Malec wrote: > Skip Montanaro wrote in > news:mailman.1662.1092523102.5135.python-list at python.org: > > >> Arien> 3) Won't most programmers think GoF decorators before >> Arien> compiler syntax tree decorators? >> >> Skip> Not if they are unfamiliar with the GoF patterns (myself >> included). >> >> Arien> Google: [~62,000 : ~130 mentions of each sort of decorator] >> >> ... >> >>BFD.... The thing is, just because in a verbal Rohrschach >>test you think "GoF" when someone says "decorator" doesn't mean >>everybody else will (or should). > > > Clearly, Python can choose any name for the auto-function-transformation > syntax in question, but it's rather willfully confusing to choose a name > that's heavily identified with a profoundly different semantics that's > superficially similar in intent. > > Arien This is especially confusing as, in everyday english usage, to decorate is not the same as to transform. Perhaps "transform" could be consdered as an alternative. The Mad Hatter's response to Alice dealt with the root naming issue: "When I use a word," Humpty Dumpty said in rather a scornful tone. "It means just what I choose it to mean - neither more or less." "The question is," said Alice, "whether you can make words mean so many different things." "The question is," said Humpty Dumpty, "which is to be master - that's all." Colin W. From heikowu at ceosg.de Tue Aug 10 09:43:03 2004 From: heikowu at ceosg.de (Heiko Wundram) Date: Tue, 10 Aug 2004 15:43:03 +0200 Subject: decorators, function signature, and help() In-Reply-To: References: Message-ID: <200408101543.03300.heikowu@ceosg.de> Read up on the following article on python-dev: http://article.gmane.org/gmane.comp.python.devel/62057 HTH! Heiko. From rschroev_nospam_ml at fastmail.fm Fri Aug 27 04:01:14 2004 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Fri, 27 Aug 2004 08:01:14 GMT Subject: How to generically transform a list? In-Reply-To: References: Message-ID: Marco Aschwanden wrote: > > Thanks to all the hints which seem to prove that there is one and only > one sensible approach - though some (like me) needed a few more lines. > > It is just funny how easy horizontal slicing is made (list[:]) but how > "difficult" vertical slicing is. It is a common task and one does not > realize how often one does need vertical slicing. eg.: getting the keys > of dictionary is a vertical slicing, or turning a list into a dict > involves vertical slicing... > > Just out of pure curiosity: Is there a langue that allows vertical and > horizontal slicing and dicing with the same built-in pattern? You can do it (sorta) in Python: use zip to turn the columns into rows and vice-versa, apply the slicing, than zip back: >>> l = [['a', 1, 11, 'aa'], ['b', 2, 22, 'bb'], ['c', 3, 33, 'cc']] >>> zip(*(zip(*l)[2:0:-1])) [(11, 1), (22, 2), (33, 3)] Step-by-step to see what happens: >>> zip(*l) [('a', 'b', 'c'), (1, 2, 3), (11, 22, 33), ('aa', 'bb', 'cc')] >>> zip(*l)[2:0:-1] [(11, 22, 33), (1, 2, 3)] >>> zip(*(zip(*l)[2:0:-1])) [(11, 1), (22, 2), (33, 3)] -- "Codito ergo sum" Roel Schroeven From eddie at holyrood.ed.ac.uk Mon Aug 23 13:22:50 2004 From: eddie at holyrood.ed.ac.uk (Eddie Corns) Date: Mon, 23 Aug 2004 17:22:50 +0000 (UTC) Subject: telnet 'connection reset by peer' References: Message-ID: Donnal Walter writes: >On Windows XP I am able to connect to a remote telnet server from the >command prompt using: >telnet nnn.nnn.nnn.nnn 23 >where nnn.nnn.nnn.nnn is the IP address of the host. But using >telnetlib, this code returns the traceback that follows: >import telnetlib >host = 'nnn.nnn.nnn.nnn' >tn = telnetlib.Telnet(host, 23) >tn.read_until("Enter device name?") >Traceback (most recent call last): > File "C:\Python23\Lib\site-packages\mindwrapper\test\telnet.py", line >4, in ? > tn.read_until("Enter device name?") > File "C:\Python23\lib\telnetlib.py", line 316, in read_until > self.fill_rawq() > File "C:\Python23\lib\telnetlib.py", line 521, in fill_rawq > buf = self.sock.recv(50) >socket.error: (10054, 'Connection reset by peer') >Is there some parameter that I need to set in order to connect using the >telnetlib client? Thanks. No, that should work, to a reasonably conforming telnet server. Try doing tn.set_debuglevel(2) before the read_until() to see what's coming back. Does it happen instantly or is something timing out? Eddie From reinhold-birkenfeld-nospam at wolke7.net Thu Aug 12 10:41:36 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Thu, 12 Aug 2004 16:41:36 +0200 Subject: Yet another decorator proposal In-Reply-To: References: <2ntvn1F4mgskU1@uni-berlin.de> Message-ID: <2o1dcnF5s9itU1@uni-berlin.de> Marco Aschwanden wrote: > On Wed, 11 Aug 2004 10:55:40 -0400, Christopher T King > wrote: > >> Also, don't forget docstrings get thrown away when using python -OO. >> Great voodoo would be needed to prevent this from happening. > > > By now the compiler takes the first triple-quoted-string and sets it on > the object's __doc__-var. It doesn't really need to be triple-quoted, does it? Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From sjmaster at gmail.com Wed Aug 25 17:08:02 2004 From: sjmaster at gmail.com (SM) Date: 25 Aug 2004 14:08:02 -0700 Subject: Just a quick one References: Message-ID: <6542462a.0408251308.475b6c22@posting.google.com> "M. Clift" wrote in message news:... > Sorry, another question. How do I remove the brackets form the list? > Name_List.remove('(') doesn't work. The parentheses or brackets are not "in" the tuple or list. They are used in the representation of tuples or lists. The tuple ('Bob', 'Mary') consists of two objects, the string "Bob" and the string "Mary". But when we describe a tuple using the canonical notation, we put parentheses around the elements, and we put commas between them. Those are part of the representation, not part of the tuple. (Likewise, when I say 'the string "Bob" and the string "Mary"', the double quote marks around each name are not part of the string, they are part of how you represent a string.) If you want to remove parentheses and commas from printing a tuple, then don't print the whole tuple, but loop through it and print each element. From simonroses at granisla.com Mon Aug 9 18:16:05 2004 From: simonroses at granisla.com (Simon Roses Femerling) Date: Mon, 9 Aug 2004 16:16:05 -0600 Subject: ANNOUNCEMENT: Web Audit Library (WAL) 0.3 Message-ID: <001801c47e5e$78334cb0$a1a05b18@spectra> Dear python coders, Web Audit Library (Wal) is a python module that provides a powerful and easy API for writing web applications assessment tools, similar to what Libwhisker does for Perl. Wal comes from the need of such a library for python. Writing web security tools using Wal is very straightforward. Wal provides the following features send/receive/analyze HTTP 0.9/1.0/1.1, HTML parser, cookie support, anti-IDS, decoders/encoders and much more... Needs python 2.3 or later. http://www.roseslabs.com Enjoy!! SRF -----BEGIN PGP PUBLIC KEY BLOCK----- Version: PGP 8.0.3 - not licensed for commercial use: www.pgp.com mQGiBD+VawoRBADK9gT68zO1QDKr+ksNvQwdESqnidQBdNklieDvPbIjphXaSpdZ w15emkxL8txipCIkKCTPGqztSzGdD6CLmTiAca/+rHllTTbkGMrpgfqah5bv24ck 8j8Gz24m8BNWub1jCYa7xIS/oeShsT226JqS2y6pwUN3Pq8qVHiNHhON8wCg/1dk pjvizFBTLxljo7T8PDhS8dUEAIm4+pzt5Pe1/HEWwarcKfeUhV3PT7ZkIns+sk2G FmOqM2MLX/11L4G2ygqxRPv6fDc0mg99ls6pSDwKMRE071mKbBC19dGA5EZh/r4K qe4odZRU7Uhjg52qXReCyXVapCTZkF3UrFzJAt1YV2NthNgppJalJSqKKFFC3TG3 5C7yA/92gjg8DWV0bmzmKTDR+bJu4wxcNu5Wkfx5yippXdKW+ko39XNR6yOsXQaQ ZSmI4ctzYWTlYH4UecZShQRQu3HK6rgOhMqsDlMjc2LpbD4rFiaG5XkVXapwjkla 6bN3JoJIvJGH/MVJ6jZbCIDUGbgevNAPu2iQE4uRlwiHghMsWrQwU2ltb24gUm9z ZXMgRmVtZXJsaW5nICA8c2ltb25yb3Nlc0BncmFuaXNsYS5jb20+iQBXBBARAgAX BQI/lWsKBwsJCAcDAgoCGQEFGwMAAAAACgkQ/y05yClX8i2A+gCg7ZIjdnVTxCui mTL/SSdu+hOX2FkAn0MQz8aBdu2MbbSIShe/hSdpFfgluQINBD+VawoQCAD2Qle3 CH8IF3KiutapQvMF6PlTETlPtvFuuUs4INoBp1ajFOmPQFXz0AfGy0OplK33TGSG SfgMg71l6RfUodNQ+PVZX9x2Uk89PY3bzpnhV5JZzf24rnRPxfx2vIPFRzBhznzJ Zv8V+bv9kV7HAarTW56NoKVyOtQa8L9GAFgr5fSI/VhOSdvNILSd5JEHNmszbDgN RR0PfIizHHxbLY7288kjwEPwpVsYjY67VYy4XTjTNP18F1dDox0YbN4zISy1Kv88 4bEpQBgRjXyEpwpy1obEAxnIByl6ypUM2Zafq9AKUJsCRtMIPWakXUGfnHy9iUsi GSa6q6Jew1XpMgs7AAICCADa2AonSlMHAO4JyzwWhN5PUnBDu0vNw6beV0YEkWM/ HV3PO5BO2wllzGlb6vruQUhHjme9L/CRpKXmjokYpd1mqE+Bf40TmN/QBndiMRTe 3xv3uRfNJpfVjvSKhuT25kIA5ivkxnM+NvZ+uGO3T2kI/vVPHr5gxljbhBrZA4nA EuqNHaY5CGtRK4oke4ylp22vPhnDfaNQ/OrUCd81jGTddV5esOaHg8O3kbsbKsiZ SVL9/G4PddpCgW6n8uVU94lJjOj3CyL3kZmjE1zc55tEb4HluX/u121xHTR/6QSP +UvF3oLZ2+Ry/hjXJukgmeJMBiXcb8JIRwfUyZf4NNSyiQBMBBgRAgAMBQI/lWsK BRsMAAAAAAoJEP8tOcgpV/ItahgAn1YY0K2IhIm17knfL7CJbgW1pEMCAKDwc0oS aPeBBvzszp974970OsfWYQ== =2yIA -----END PGP PUBLIC KEY BLOCK----- -------------- next part -------------- An HTML attachment was scrubbed... URL: From bjg at network-theory.co.uk Tue Aug 17 13:02:12 2004 From: bjg at network-theory.co.uk (Brian Gough) Date: 17 Aug 2004 18:02:12 +0100 Subject: Problem with floating point precision References: Message-ID: <87n00titpn.fsf@network-theory.co.uk> j_mckitrick at bigfoot.com (j_mckitrick) writes: > I checked the docs, but found nothing about floating point issues. See the appendix "Floating Point Arithmetic: Issues and Limitations" in the Python Tutorial for a discussion of this topic. -- Brian Gough Network Theory Ltd, Publishing the Python Manuals --- http://www.network-theory.co.uk/ From rnd at onego.ru Thu Aug 19 11:58:13 2004 From: rnd at onego.ru (Roman Suzi) Date: Thu, 19 Aug 2004 19:58:13 +0400 (MSD) Subject: age of Python programmers In-Reply-To: <1a608e98.725b9b40.8235400@po-d.temple.edu> References: <1a608e98.725b9b40.8235400@po-d.temple.edu> Message-ID: On Thu, 19 Aug 2004 brianc at temple.edu wrote: >Now my question is... am I a programmer yet? or still just a >script kiddie? One knows when one becomes a programmer. Its almost the same feeling like mastering a bicycle or learning to swim. Script kiddies are those who use ready programs, maybe tweaking some constants in them. >I've started to use classes regularly, so does that make it a >yes? However, everything I've written this summer has been >take data-->do something to each record-->output data >That sounds like a script to me. Script is a programme. Making scripts is programming. >However, I've created totally self contained "scripts" that >does stuff in minutes that other "professional" software takes >days to do. > >I'm not talking pushing a few SQL statements around like I >used to, now it's taking millions of possible drug candidate >molecules, breaking into chemically similiar sets, computing >comparison matices, doing fuzzy logic to decide which is the >best and in the end making sure the entire thing can run on a >128 processor linux cluster. > >Am I a programmer yet? I felt that I am a programmer after one year starting learning Basic (it was at age 14, 7th form IIRC). Before it happened at each nontrivial task I had a feeling that it's a wall in front of me! But after the change happened, programming became a matter of knowing syntax. It became universal skill, not depending on a programming language. >The only class I've ever taken dealing with computers was 5 years ago on >using CSS to ease webpage design. Good programmers start as self-learners. Then they master and systemize theory and then practice alot. >Oi, sorry, tomarrow's my last day at this internship, I could >probably be knocking out 3-4 more python programs by then.=-) >Without Python, I wouldn't know where the hell I would be. > >Thank you all! >-Brian > Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3 From sharidas at zeomega.com Mon Aug 16 02:52:10 2004 From: sharidas at zeomega.com (Satchidanand Haridas) Date: Mon, 16 Aug 2004 12:22:10 +0530 Subject: reconstruct list and dictionary from file In-Reply-To: <20040816032354.55843.qmail@web53708.mail.yahoo.com> References: <20040816032354.55843.qmail@web53708.mail.yahoo.com> Message-ID: <4120599A.3030203@zeomega.com> Steve Perry wrote: >I have a serialized list and dictionary stored in a file, with the >following format: > >mydata: > color ["red" "green" "blue"] > origin [0.0 13.2 9.2] > datasource1 {server:"server1.domain" username:"client" >password:"secret"} > > > Is the above format the only way you want to store the serialized list? I ask because (and in case you aren't already aware of the 'execfile' method), if you can store 'mydata' in the form of legal Python expressions, you can use the 'execfile' method to create live objects out of the data-structures stored in the list. Regards, Satchit, >Is there any APIs to reconstruct the mydata object back with the list >and dictionary recreated in it? > >Thanks, > >Steve > > > >__________________________________ >Do you Yahoo!? >Read only the mail you want - Yahoo! Mail SpamGuard. >http://promotions.yahoo.com/new_mail > > From squirrel at WPI.EDU Tue Aug 10 13:33:48 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 10 Aug 2004 13:33:48 -0400 Subject: OO menu management In-Reply-To: References: Message-ID: On Tue, 10 Aug 2004, Egbert Bouwman wrote: > I still have for each menu button: > - a callback-name variable in the gui class > - a real callback method in the application class > and now a dictionary that links those two. > That dictionary is argument-passed to the gui. > > Additionally in the gui itself I have a nested list with for each button: > - the name of the menu button (MenuItem) itself > - the name of the sub-menu it belongs to > - the tekst on the button > - the sub-menu it may open > - the name of its callback ( > - the callback arguments I was doing the same thing in an app I was working on, only with a toolbox instead of menus, but... > It is quite complex, with a lot of correspondences that may go wrong. > So I wonder if my approach is the right one. What you're doing is a good way to make the menu system toolkit-independent. This is helpful if you plan to make your entire program toolkit-independent, i.e. you plan to include code for, say, Tkinter, wxPython, and PyQt. If that's your final aim, though, I'd suggest you rather look at AnyGui, which is a toolkit-independent toolkit (the sort of thing Python should ship with), and just hardcode menus using its menu widgets, rather than generalizing menus yourself. If you're not looking for a toolkit-independent program, but rather just one which you could easily rewrite the GUI code to work with another toolkit at some point in the future, you're probably better off just hardcoding the menus into the GUI portion of your program, since any change of toolkit will require a complete rewrite of that portion anyways. Hope this helps. From mj-usunto at tkb.pl Thu Aug 19 08:39:05 2004 From: mj-usunto at tkb.pl (Marcin Jurczuk) Date: Thu, 19 Aug 2004 12:39:05 +0000 (UTC) Subject: Deleting rows using PyDO from SkunkWeb Message-ID: Hello group. Could someone descripe how to delete many row at one time from MySQL database using SkunkWeb PyDO pacgage ?? Documentation is very short about that ... Assume that Base is class define like in PyDO doc, so Base.new(...) adds new row.. Documetation show ony delete() without any arguments. SQL query is like "DELETE FROM SESSIONS WHERE acc_time < '398984353'" Thanks for read this :-) -- Marcin Jurczuk, NIC-HDL: MJ1679-RIPE From ben at benlast.com Tue Aug 17 09:50:37 2004 From: ben at benlast.com (Ben Last) Date: Tue, 17 Aug 2004 14:50:37 +0100 Subject: How big can a Python program be? In-Reply-To: Message-ID: The last few of a list of wc's run on the Enthought Python 2.3.3 distribution. First element of the tuple is line count, second is module filename. I'm sure whole packages would be much bigger, but I was curious as to how big a typical module might get. (3244, '/cygdrive/c/Python23/Lib/site-packages/scipy/xplt/slice3.py') (3665, '/cygdrive/c/Python23/Lib/lib-tk/Tkinter.py') (3820, '/cygdrive/c/Python23/Lib/site-packages/scipy/stats/distributions.py') (4036, '/cygdrive/c/Python23/Lib/test/test_descr.py') (4362, '/cygdrive/c/Python23/Enthought/demos/wxPython/demo/throbImages.py') (4362, '/cygdrive/c/Python23/Lib/site-packages/wxPython/demo/throbImages.py') (4499, '/cygdrive/c/Python23/Lib/site-packages/win32/lib/win32con.py') (5373, '/cygdrive/c/Python23/Lib/site-packages/wxPython/demo/images.py') (5377, '/cygdrive/c/Python23/Enthought/demos/wxPython/demo/images.py') (7364, '/cygdrive/c/Python23/Lib/site-packages/wxPython/lib/maskededit.py') > -----Original Message----- > From: python-list-bounces+ben=benlast.com at python.org > [mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of > Christopher T King > Sent: 17 August 2004 14:13 > To: python-list at python.org > Subject: Re: How big can a Python program be? > > > On 17 Aug 2004 vronskij at post.sk wrote: > > > Suppose , you are a sole programmer (lonewolf). How many lines can one > > handle? > > $ wc -l my_current_big_project_that_is_very_far_from_being_complete/* > 2945 > > I'm sure others can do better than that. > > -- > http://mail.python.org/mailman/listinfo/python-list From rho at see.signature.invalid Thu Aug 5 03:17:17 2004 From: rho at see.signature.invalid (Nigel Rowe) Date: Thu, 05 Aug 2004 17:17:17 +1000 Subject: Overhead of (was Reasoning behind) nested scope References: <10h0kducrd2fod3@news.supernews.com> Message-ID: <10h3nntqrsfba9f@news.supernews.com> Peter Otten wrote: > Nigel Rowe wrote: > >> Peter Otten wrote: >> >>> Andy Baker wrote: >>> > >> What work is actually done when the >> 'nested function creation code of the "inner" function' >> is executed? < snip > > > In the example you get three extra instructions, LOAD_CONST, MAKE_FUNCTION > and STORE_FAST (and earn the slight benefit that inner is now a local > instead of a global). A constant code object is used, meaning compilation > takes place at most once when the module is loaded. There is a dedicated > op-code, so function creation should be faster than "normal" creation of a > class instance. > > Now this is all nice and dandy, but how do the two contenders perform? > > $ timeit.py -s"def inner(): pass" -s"def outer(): return inner" "outer()" > 1000000 loops, best of 3: 0.469 usec per loop > $ timeit.py -s"def outer():" -s" def inner(): pass" -s" return inner" > "outer()" > 1000000 loops, best of 3: 1.12 usec per loop > > i. e. nesting the two functions roughly doubles execution time. > However, creation of an inner function often will only take a small > fraction of the total time spent in the outer function - in the end it's > just a matter of style. > > I use inner functions only when they depend on the local context because I > think it nicely discriminates closures from helpers. I tend to omit > implicit parameters even for helper funtions, therefore nesting them would > gain me nothing. > > Peter Thanks Peter, I didn't know about timeit.py (it's now on my $PATH). I don't think I'm going to worry about the overhead (except in deeply nested loops). From some quick testing it looks like the overhead is about the same as 1.5 times a=b[10:20] # where b="the quick brown jox jumps over the lazy dog" and less than 1/2 of a=math.sin(0) So if the nested code is easier to read, in it goes. -- Nigel Rowe A pox upon the spammers that make me write my address like.. rho (snail) swiftdsl (stop) com (stop) au From grante at visi.com Mon Aug 9 01:52:23 2004 From: grante at visi.com (Grant Edwards) Date: 09 Aug 2004 05:52:23 GMT Subject: how many bytes in an int References: <9ACRc.1523$bJ2.9739@news1.mts.net> <4116f8ee$0$8076$a1866201@newsreader.visi.com> <41170cd1$0$8076$a1866201@newsreader.visi.com> Message-ID: <41171116$0$8079$a1866201@newsreader.visi.com> On 2004-08-09, Grant Edwards wrote: > The struct module is the only thing I know about. If you're > worried about the "C" types in the struct module changing > underneat you, you could do a pure Python implimentation of > "python-int" to/from DWORD. It's utterly trivial and shouldn't > take more than one or two lines of code. def toLittleEndianDWORD(i): return ''.join(map(chr,[x&0xff for x in [i,i>>8,i>>16,i>>24]])) def fromLittleEndianDWORD(s): return ord(s[0]) + (ord(s[1])<<8) + (ord(s[2])<<16) + (ord(s[3])<<24) -- Grant Edwards grante Yow! Well, O.K. I'll at compromise with my visi.com principles because of EXISTENTIAL DESPAIR! From newsgroups at jhrothjr.com Fri Aug 6 16:31:22 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 6 Aug 2004 16:31:22 -0400 Subject: @decorators References: <10h73e5kh1et536@news.supernews.com> <4113e5be@nntp.zianet.com> Message-ID: <10h7qlg5adbfj86@news.supernews.com> "Mark Bottjer" wrote in message news:4113e5be at nntp.zianet.com... > John Roth wrote: > > All of the existing packages (at least to my knowledge) use > > descriptors to wrap the necessary functions. They could be > > very easily reimplemented in terms of the decorator syntax. > > However, the decorator syntax brings no new functionality > > to the table; it's simply syntactic sugar for already existing > > functionality. > > Exactly. What's more, I don't think that decorators are really the ideal > way to express DBC, either. For one thing, pre and post conditions often > want access to at least the argument list, and often to the internal > variables of the definition. I don't think that this will be possible > with the decorators as proposed, since they are outside the scope of the > function. Since I wrote that, I managed to read the new, improved and rewritten PEP, and discovered that the new syntax doesn't allow parameters. So it can't be used as a replacement for the property() built-in function, and it therefore also can't be used for the DBC functionality. As delivered, it's strictly a replacement for the classmethod and staticmethod builtin functions (and any other module or builtins that take one parameter, of course.) Guido's stated reasoning was that he had "a bad feeling" about allowing more general expressions. So do I. >From what people are saying that's substantive (rather than syntactic) I think that there are a number of very different desires on the table, and it's not at all clear either what they are or how they combine. > Don't forget: if we make this too painful for the BDFL, he might just > drop the whole idea and tell us to live with what we've got. :) He's been through it before. Remember PEP 308? John Roth > > -- Mark From tjreedy at udel.edu Sat Aug 14 01:35:32 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Aug 2004 01:35:32 -0400 Subject: Flython References: Message-ID: "Dave Benjamin" wrote in message news:slrnchq8lg.q3d.ramen at lackingtalent.com... > I just want to say, for the record, that if anyone can successfully build a > Python compiler that can produce Flash bytecode, Knowing nothing about Flash bytecode, but knowing a bit about other Python to X projects, I wonder whether it might be more immediately feasible to either translate Python bytecode or generate Flash bytecode with an AST tree walker. tjr From nospam at nowhere.hu Sat Aug 7 19:21:31 2004 From: nospam at nowhere.hu (Miklós) Date: Sun, 8 Aug 2004 01:21:31 +0200 Subject: Going the PL/1 way References: Message-ID: "A.M. Kuchling" wrote in message news:rtqdnUmcD8bT0ojcRVn-gw at speakeasy.net... > > Free software projects are run by the people who actually contribute code. > If sorted() and reversed() were added, it's because Raymond Hettinger > actually wrote code to implement them, and GvR didn't dislike them. If > people who want decorators are willing to expend effort to implement them, > test them, conform to the coding standard, then they can be considered for > inclusion. So, if you want to see the GIL fixed, or performance > improvements made, you have to work on these problems. > > --amk So do you say "them and us", Python developers vs. users? I've always had the "we all"-feeling. Maybe that's over. I neither have the technical knowledge or the slightest inclination to wade through tons of C codes, I've been using Python because it's simple, clean and still very powerful. I am unhappy to see that Python becomes cryptic, complex but more powerful. Cheers, Mikl?s From tim.peters at gmail.com Mon Aug 23 13:57:15 2004 From: tim.peters at gmail.com (Tim Peters) Date: Mon, 23 Aug 2004 13:57:15 -0400 Subject: 100 % portable ? In-Reply-To: References: <2otm5mFed44hU1@uni-berlin.de> Message-ID: <1f7befae0408231057a376ac6@mail.gmail.com> [Bernd Kaiser] >> You can use os.environ["HOME"], this will return the user's home dir. [Dave Cook] > Doesn't work in win9x AFAIK. I do notice that some people are > starting to require XP for their apps. HOME isn't defined on my vanilla XP box. HOMEDRIVE and HOMEPATH are, though. From insert at spam.here Wed Aug 11 17:16:54 2004 From: insert at spam.here (Doug Holton) Date: Wed, 11 Aug 2004 16:16:54 -0500 Subject: The winner of the Python Decorator Poll is... Message-ID: George W Bush, as certified by Florida's election commission. Which decorator syntax do you like the most? See http://wiki.wxpython.org/index.cgi/PythonDecoratorsPoll A. @classmethod def foo(): (82) 14% C1. def foo() [classmethod]: (235) 41% E1. def foo(): @classmethod (260) 45% Total Votes: 577 People are about 6 to 1 against having the decorators come before the "def" keyword. From ajsiegel at optonline.com Mon Aug 9 19:52:12 2004 From: ajsiegel at optonline.com (Arthur) Date: Mon, 09 Aug 2004 23:52:12 GMT Subject: Purely emotional perspective References: <10hf3oaltbo7o74@corp.supernews.com> <10hg1hg1pidqs96@corp.supernews.com> Message-ID: > >I'm particularly worried about the proposals of using this as metadata >for things like author -- that seems to be begging for almost every >function to use half a dozen or more decorators (accepts, returns, >author, design date, last revision date, etc., etc.) which will (IMO) >seriously degrade code readability. (This syntax is okay for one or two >decorators, but more than that quickly becomes obfuscatory.) But isn't that so of any of the alternative syntaxes. Looks to me as if it is." Looks" as in "that is what my eyes tell me". Only more restriction on the use of decorators - which doesn't seem to be in the spirit of what decorators are about -or more support outside of the @decorator framework for the common cases mitigates this issue. Guido made the point today that at some point Python will have optional static typing, and at that point a class of anticipated common use cases for @decorator will be obsoleted. But that some point is Python3000, which is anybodies guess when. Perhaps Python is a bit pre-pubescent. and will need to endure a few ugly years - as many of us ourselves did. I, for one, turned out beautiful in the end. Art From ben at benlast.com Fri Aug 20 07:07:18 2004 From: ben at benlast.com (Ben Last) Date: Fri, 20 Aug 2004 12:07:18 +0100 Subject: Rita Sue and Bob too In-Reply-To: <4125D415.7040403@engcorp.com> Message-ID: > From: Peter Hansen [mailto:peter at engcorp.com] > Actually, that wasn't quite me who wrote those words... I merely > quoted them from the OP. Oops - my apologies. > (Ben, I don't think you need to post to both the python-list _and_ > the comp.lang.python newsgroup: they mirror each other already!) Hmmm - I wasn't aware that I was. I'm posting (and reading) via the python-list mailing list. I don't do USENET at all... b From jwkenne at attglobal.net Tue Aug 31 10:26:03 2004 From: jwkenne at attglobal.net (John W. Kennedy) Date: Tue, 31 Aug 2004 14:26:03 GMT Subject: Xah Lee's Unixism In-Reply-To: References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4PGdnfsOfdDPi63cRVn-tA@speakeasy.net> <41337FC9.8070902@hotmail.com> Message-ID: <%T%Yc.29567$Es2.11957889@news4.srv.hcvlny.cv.net> Andre Majorel wrote: > On 2004-08-31, Brian Inglis wrote: > >>On Tue, 31 Aug 2004 01:12:55 +0000 (UTC) in alt.folklore.computers, >>Andre Majorel wrote: >> >> >>>On 2004-08-30, Antony Sequeira wrote: >> >>>>Windows (MS) is not 'Unixism'? >>> >>>If by unixism, you mean any operating system that has a >>>hierarchical filesystem and byte stream files, yes. But that >>>would include quite a few other non-Unix operating systems, >>>including Mac OS 9, Prologue and probably everything else this >>>side of CP/M (DOS 1.x shall be deemed to be CP/M). >> >>DOS 2.x+ shall be deemed to be CP/M+! > > > Wasn't it in version 2 that they added directories and > Unix-style file handles ? Yes, and also a single-process pipe emulator. Ever since 2.0, MS has been trying to turn MS-DOS (later, Windows) into a Unix clone. -- John W. Kennedy "...when you're trying to build a house of cards, the last thing you should do is blow hard and wave your hands like a madman." -- Rupert Goodwins From evan at 4-am.com Mon Aug 23 13:45:26 2004 From: evan at 4-am.com (Evan Simpson) Date: Mon, 23 Aug 2004 12:45:26 -0500 Subject: clear content of 'printed' In-Reply-To: References: Message-ID: <412A2D36.7040904@4-am.com> Christian Otteneuer wrote: > I have the following problem: > I want to write a python script, that writes text into files. The text is > being "collected" in a for-loop, the code looks like this: > > for i in range(len(myList)): > id = myList[i] > print "some text" > container.writeToFile(id, printed) [...] > Is there a possibility to do clear the content of 'printed' in python? This question properly belongs in one of the Zope lists, since the regular Python folks have no idea what you're talking about. Thank goodness I spotted you, or wackiness would ensue ;-) "printed" is a magic variable implemented by the Script machinery, and is read-only. You need to drop print and use plain strings: for i in range(len(myList)): id = myList[i] txt = "some text" container.writeToFile(id, txt) Cheers, Evan @ 4-am From abra9823 at mail.usyd.edu.au Wed Aug 4 22:58:24 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Thu, 5 Aug 2004 12:58:24 +1000 Subject: cgi script headers - help In-Reply-To: <4111A0EB.6060609@fielden.com.au> References: <1091672967.41119b8746b79@www-mail.usyd.edu.au> <4111A0EB.6060609@fielden.com.au> Message-ID: <1091674704.4111a25085adc@www-mail.usyd.edu.au> nope that doesn't make a difference. php does it easily through header(), java does it through addHeader, why or how does Python do it? -- Ajay Brar, CS Honours 2004 Smart Internet Technology Research Group Quoting Rowdy : > Ajay wrote: > > > hi! > > > > i am generating a file on the fly and making a user download it. > > print "Content-Type: application/model\n\n" > > print "Content-Disposition: attachment; filename=modeldef3\n" > > print str > > > > i set the Content-Disposition to force a download dialog box and also > give > > the file a name. > > however when i view the headers sent by my script, i have only > > HTTP/1.1 200 OK > > Date: Thu, 05 Aug 2004 02:26:48 GMT > > Server: Apache/1.3.19 (Unix) > > Connection: close > > Content-Type: application/model > > > > why isn't the Content-Disposition header coming up? > > > > thanks > > > > cheers > > > > -- > > Ajay Brar, > > CS Honours 2004 > > Smart Internet Technology Research Group > > One guess would be the double \n at the end of the Content-Type line - > try removing one and see if that works. > > Rowdy > > ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From rynt at 9yahoo.com Thu Aug 26 10:07:43 2004 From: rynt at 9yahoo.com (R Baumann) Date: Thu, 26 Aug 2004 07:07:43 -0700 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: "Xah Lee" wrote in message news:7fe97cc4.0408251356.34f2102a at posting.google.com... > Larry Wall and Cults > (Lazyness, Impatience and Hubris) > 200012 > In this context --- This is the STUPIDEST thing I've ever heard. What a maroon! What a Trollup! RB From noone at here.com Mon Aug 16 10:54:14 2004 From: noone at here.com (M. Clift) Date: Mon, 16 Aug 2004 15:54:14 +0100 Subject: random / lists References: <2obuvjF8q553U1@uni-berlin.de> Message-ID: Hi Russell, That looks really good. It would seem to allow for a lot of control. Yet another example for me to learn from! As someone new to programming, I'm only just starting to realise that in code there is no one answer to a problem. Thanks, Malcolm From adurdin at gmail.com Mon Aug 23 00:09:30 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Mon, 23 Aug 2004 14:09:30 +1000 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: <59e9fd3a04082221092ad0fa45@mail.gmail.com> On Mon, 23 Aug 2004 00:05:35 -0400, Peter Hansen wrote: > > If there is someone motivated enough to implement C1, I > suggest that it isn't too late. If Guido is presented > with J2 with an implementation, but knows that C1 was > supported strongly as well and has an implementation > imminent, I'm guessing it would lead him to consider > @pie, J2, and C1 all together on their merits (in his > view) and make a decision, perhaps a pending decision > if he then favours C1. C1 was the original proposal; I understood that Guido had written an implementation some time ago. The python-dev archives might be useful in locating it. From chotty at freenet.de Tue Aug 24 12:04:52 2004 From: chotty at freenet.de (Christian Otteneuer) Date: Tue, 24 Aug 2004 18:04:52 +0200 Subject: clear content of 'printed' References: Message-ID: "Evan Simpson" wrote: > "printed" is a magic variable implemented by the Script machinery, and is > read-only. You need to drop print and use plain strings: > > for i in range(len(myList)): > id = myList[i] > txt = "some text" > container.writeToFile(id, txt) Thanks! That's the way I'll do it... From David.Flory at TheFlorys.org Mon Aug 16 12:40:52 2004 From: David.Flory at TheFlorys.org (David Flory) Date: Mon, 16 Aug 2004 12:40:52 -0400 Subject: Help with reading WinXP registry Message-ID: I am trying to write a short program to list the keys and values in a WinXP registry key. I have tried to use pyRegistry and get an error. My test code is: Import pyRegistry baseKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes" basereg = pyRegistry.open(baseKey) print basereg.getKeyNames() Which gives the error: Traceback (most recent call last): File "D:\bin\test_pyRegistry.py", line 5, in ? print basereg.getKeyNames() AttributeError: getKeyNames What am I doing wrong? Using basereg.getValueNames() works fine. Is there a better way to access the registry in a Win32 system? Tia, David From daniel at syrinx.net Fri Aug 13 16:22:53 2004 From: daniel at syrinx.net (Daniel Ellison) Date: Fri, 13 Aug 2004 16:22:53 -0400 Subject: Flython In-Reply-To: References: Message-ID: <2o4m5pF6apnoU3@uni-berlin.de> Dave Benjamin wrote: > I just want to say, for the record, that if anyone can successfully build a > Python compiler that can produce Flash bytecode, I will personally allow > you to throw *any number of pies* in my face, in as public of a ceremony as > you desire. Furthermore, I will match you 50/50 in the cost of the pies. > > Thank you, > Dave > Wow, that's one heavy challenge! Either Dave thinks it just can't be done, or he really, /really/ wants this compiler. Dan From rnd at onego.ru Thu Aug 12 14:08:32 2004 From: rnd at onego.ru (Roman Suzi) Date: Thu, 12 Aug 2004 22:08:32 +0400 (MSD) Subject: zero new keyword decorator Message-ID: After a week of reading decorator discussion my mind slowly turnes in the opposite direction: to find which syntaxes are absolutely unwanted. It seems that people like @ more than lambda, so this will never be in Python: def fun: dec1; dec2; dec3 lambda x, y: """ docs """ body Also our decorator discussion reminds me of Forth BUILD> DOES> words. That is, decorators and arglist are after-build and "does" part - after the ":". Why not? build fun(arg1, arg2): decor1; decor2 decor3 def: body else: (if everything went right) Or, if we want to catch errors in decorators, a special version: try def fun(arg1, arg2): decor1; decor2 decor3 def: body except: (if everything went wrong) finally: (anyway do this) Or, if we want to say function is needed for decorators and not the other way around: for: decor1 decor2 def fun(x, y): body What about exec: decor1 decor2 def fun(x, y): body Maybe this way we could get rid of '@': decor1, decor2(a), decor3 for def fun(x, y): body Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3 From paul at boddie.org.uk Thu Aug 19 05:23:17 2004 From: paul at boddie.org.uk (Paul Boddie) Date: 19 Aug 2004 02:23:17 -0700 Subject: favorite python web development tool? References: <10i4nttktcvltdd@corp.supernews.com> Message-ID: <5339b60d.0408190123.2a8adb87@posting.google.com> mike wrote in message news:<10i4nttktcvltdd at corp.supernews.com>... > hi all - > > > i'm fairly new to python, coming from a java servlet / velocity template > background. i'm looking for a good python web development tool, and > hope to find some suggestions here. Well, . Alternatively, you could take a look at the WebProgramming section [1] of the PythonInfo Wiki [2]. And if other respondents contributed their opinions to that resource, we wouldn't necessarily have the situation where people regard that resource as confusing whilst giving a parade of the frameworks every time someone asks how to do CGI with Python. > given my background, webware+cheetah feels comfortingly familiar, and > i'm leaning toward it. before i dive in, though, i'm wondering what you > experienced users think about it, compared to the other tools that are > out there. eg, does the python environment have strengths that are > better exploited with something other than a servlet-like model? I've heard that Webware plus Cheetah is a fairly equivalent combination to Java Servlet API plus Velocity, at least in style. I think it's widely accepted that if you're doing content management, you might be better served with something like Zope or a derivative such as Plone. If you look at the OriginalWebProgrammingClassification [3] on the Wiki, you'll get a better impression of what is available, in my opinion. That classification, combined with the PresentationTechnologies [4] page (now mysteriously delinked in some "tidying up" activity), is more concise and doesn't try and blind you with pseudo-science in the way that the main classification does: "Variable Insertion-Replacement Templating Applications (Pre-processors)" anyone? Paul [1] http://www.python.org/cgi-bin/moinmoin/WebProgramming [2] http://www.python.org/moin/FrontPage [3] http://www.python.org/cgi-bin/moinmoin/OriginalWebProgrammingClassification [4] http://www.python.org/cgi-bin/moinmoin/PresentationTechnologies From peter at engcorp.com Sun Aug 22 08:38:46 2004 From: peter at engcorp.com (Peter Hansen) Date: Sun, 22 Aug 2004 08:38:46 -0400 Subject: newsgroup for embeded/extend python ? In-Reply-To: References: Message-ID: skull wrote: > I wanna know is there any newsgoup(or forums through www) > specially for embeded/extend python? There is not enough traffic here on that topic to warrant a separate newsgroup yet, so here is the best place to post... -Peter From baggott2 at llnl.gov Tue Aug 3 22:13:23 2004 From: baggott2 at llnl.gov (Daniel Baggott) Date: Tue, 03 Aug 2004 19:13:23 -0700 Subject: MySQLdb 'server not initialized' Message-ID: <1091585603.5327.89.camel@goingto.llnl.gov> Hi, I'm seeking assistance in troubleshooting connecting to MySQL (4.0.20) using Python (2.3.4) and MySQLdb (1.0.0). When I attempt to make a connection, I get the following exception: _mysql_exceptions.InternalError: (-1, 'server not initialized') The database is definitely running as I can connect to it using the mysql client. Also, when I attempt to connect to MySQL from within Python, I don't see any messages in the MySQL logs (ie the .log and .err files in /usr/local/mysql/data/). Does anyone have any advice or suggestions as to how to figure out what's going wrong? Also, if there's a better forum for posting this question, please point me in the right direction. Thanks! Dan [baggott2 at goingto baggott2]$ python Python 2.3.4 (#1, Jul 26 2004, 15:14:49) [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-34)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import MySQLdb >>> c = MySQLdb.connect(host='localhost',user='gbd',passwd='xxxxxxx',db='zinc') Traceback (most recent call last): File "", line 1, in ? File "/usr/local/lib/python2.3/site-packages/MySQLdb/__init__.py", line 64, in Connect return apply(Connection, args, kwargs) File "/usr/local/lib/python2.3/site-packages/MySQLdb/connections.py", line 116, in __init__ self._make_connection(args, kwargs2) File "/usr/local/lib/python2.3/site-packages/MySQLdb/connections.py", line 41, in _make_connection apply(super(ConnectionBase, self).__init__, args, kwargs) _mysql_exceptions.InternalError: (-1, 'server not initialized') >>> [baggott2 at goingto baggott2]$ mysql -h localhost -u gbd -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 to server version: 4.0.20-standard-log Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> show databases; +----------+ | Database | +----------+ | zinc | +----------+ 1 row in set (0.00 sec) mysql> Bye [baggott2 at goingto baggott2]$ From rmkrauter at yahoo.com Wed Aug 18 00:49:39 2004 From: rmkrauter at yahoo.com (Rich Krauter) Date: Wed, 18 Aug 2004 00:49:39 -0400 Subject: Piping stdout to Python callable In-Reply-To: References: Message-ID: <4122DFE3.7060407@yahoo.com> Edward Diener wrote: > Antoon Pardon wrote: > >>Op 2004-08-17, Edward Diener schreef : >> >>>From within a function in my own module I need to take the output >>>from a Python module "A", which is sending data to stdout and which >>>can not be changed and which I need to invoke as a top-level module, >>>and pipe it into another function in my own module so that I can >>>read it from stdin. Is there an easy way to do this ? The only way I >>>can presently think to do this is through "system python A.py | >>>python MyOwnModule.py", which seems a bit laborious having to invoke >>>python.exe itself twice. Any other solution would be most welcome. >> >>What do you mean when you say you need to invoke it as a top-level >>module? Do you mean you can't import it at all or that importing it >>will startup the process of generating output immediatly? > > > I mean that it has a "if __name__ == '__main__' line and I need to trigger > it by calling 'python A.py'. > > >>What bothers you with twice invoking the interpreter? > > > Nothing practically. Just seems inelegant. > > >>In these days >>a program that is invoked multiples times will generally be only >>loaded once in memory. > > > Shared libraries may be loaded once in memory but python.exe itself gets > reloaded each time. > > >>Are threads an acceptable alternative? Does your MyOwnModule.py needs >>to write to stdout? > > > Threads are acceptable. MyOwnModule.py can do anything, depending on > parameters, but the idea is that a certain parameter tells it to read from > stdin on the other end of the pipe. > > I have implemented this via "os.system("python A.py | python MyOwnModule.py > parameters") and it works fine. I thought there might be a better, more > elegant way but since the above works without any problem I will stick to it > unless you can suggest anything better. BTW "A.py" can be any number of > types of modules which must be invoked by python.exe and writes it's results > to stdout. I am telling you this lest you suggest that I somehow import and > parse A.py in order to call directly into it rather than having python.exe > invoke it. While that might be possible, it would be a real programming > PITA. > > You could do something like this: $ cat A.py def test(arg): for i in range(1,5): print arg*i $ cat B.py import A import sys import StringIO sys.stdout = StringIO.StringIO() A.test(5) fileobj,sys.stdout = sys.stdout,sys.__stdout__ fileobj.seek(0) for line in fileobj: print line.strip() Worth the effort to change your code? Probably not. Kinda neat, though. Rich From Michael.J.Fromberger at Clothing.Dartmouth.EDU Thu Aug 19 17:31:32 2004 From: Michael.J.Fromberger at Clothing.Dartmouth.EDU (Michael J. Fromberger) Date: Thu, 19 Aug 2004 17:31:32 -0400 Subject: PEP 318: Can't we all just get along? References: <20040817181725194-0400@braeburn.themorgue.org> <10i9msuatli5p84@news.supernews.com> <10ia3aa8j6tbma5@news.supernews.com> Message-ID: In article <10ia3aa8j6tbma5 at news.supernews.com>, "John Roth" wrote: > "Michael J. Fromberger" wrote > in message news:Michael.J.Fromberger-D24476.14010119082004 at localhost... > > In article <10i9msuatli5p84 at news.supernews.com>, > > "John Roth" wrote: > > > > > In other words, forget the use cases. They're irrelevant. > > > > On this point, I strongly disagree. If you don't have a use case, there > > is no point whatsoever in arguing about the syntax of a feature. > > There is a use case. If you go back and read the original > post I was replying to, it contains the sentence: > > [begin quote] > I guess others had bigger plans for my proposal that I had planned. It > has turned into the "solution" to many problems: type checking (both > arguments and returned values), metaclasses, metadata, interfaces, > function attributes, etc.). > [end quote] Ah, I see. I misunderstood your intent. My apologies. Nevertheless, I think it's clear the Python community at large ought to have a clearer idea of exactly what the use cases ARE (and, more importantly, what they're not) before deciding on a syntax. It's not clear to me that there's consensus on purpose yet (as witness the wildly divergent ideas that have accumulated on the wiki, comp.lang.python, and python-dev). Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From peter at engcorp.com Tue Aug 10 17:30:14 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 10 Aug 2004 17:30:14 -0400 Subject: measuring 1/100th seconds, what function? In-Reply-To: References: Message-ID: Jonas K?lker wrote: > I'm doing a Rubik's Cube timer, so I need a function to measure 100ths of > a second. I've browsed through the library reference of python.org, but I > didn't find anything that struck me as 'the perfect fit'. Either it was > system dependent, or it was too grainy (lo-res), or... something else. It usually helps to specify what you looked at, and perhaps why you didn't think it was acceptable, to avoid us retracing your steps... > so, I need a function which satisfies (in order of importance): > > 1. It can be used to measure time in the range of up to approximately 1 > minute with an accuracy down to 100th-seconds (that's 60000~65536 > different values). Better accuracy is a bonus, longer time-frame is a > bigger bonus. > > 2. it must run on any version of windows upon which python 2.4 can run These two constraints cannot be met simultaneously, I believe. Windows98 does not provide adequate resolution in the timer. If you are willing to forego Win98 and use only the real Windows OSes, then I think you get roughly (?) 10ms resolution already with time.time(). Linux probably gives 1ms resolution or better in pretty much all cases with time.time(). -Peter From bart_nessux at hotmail.com Wed Aug 4 10:13:19 2004 From: bart_nessux at hotmail.com (Bart Nessux) Date: Wed, 04 Aug 2004 10:13:19 -0400 Subject: Perl's Crypt::PasswdMD5 In-Reply-To: References: Message-ID: Nicolas ?vrard wrote: > * Bart Nessux [15:39 04/08/04 CEST]: > >> Does Python have anything similar to Perl's Crypt::PasswdMD5??? >> >> I read about the crypt module... but it only does DES. Any plans to >> add md5 or other digests to it in the future? > > > http://www.python.org/doc/current/lib/module-md5.html > > Try to be lucky with google using this search string : "python md5" That's not comparable to Crypt::PasswdMD5 From aahz at pythoncraft.com Fri Aug 20 16:11:49 2004 From: aahz at pythoncraft.com (Aahz) Date: 20 Aug 2004 16:11:49 -0400 Subject: Alternative decorator syntax decision References: Message-ID: Vote: C1 C1 C1 -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From howard.stearns at charter.net Fri Aug 6 20:18:57 2004 From: howard.stearns at charter.net (Howard Stearns) Date: Fri, 06 Aug 2004 19:18:57 -0500 Subject: How do you feel ? In-Reply-To: References: Message-ID: <41141FF1.2030606@charter.net> I'm a dyed-in-the-wool Lisp programmer by history, but not for pay these days. I'm trying Python for a nights-and-weekends project. And every time I use it, I tell my wife (a technically savy non-programmer) that "hey, this Python stuff really isn't bad. It's.... well..., pretty good." Of course, the first thing I did was re-implement generic functions. But other than that, I'm must using the libraries. They're good. I'm having fun again! The one thing I've found annoying is that I haven't yet discovered how to do whatever I want in lambda expressions. I have top-level assignments where I'd like create a function to use as the the value being assigned. I don't know how to define a named function in a top-level assignment, and a lambda won't allow me to use 'try' and other statements -- just expressions. Or am I looking at things wrong? Sylvain Hellegouarch wrote: > Hi, > > A bit off topic. > > I just wondered what was your feeling when you were coding with Python. > I have beebn coding with different languages and the only that has given > me the will to invent or to be creative has been Python. Python allows > me not to focus on the complexity of the language itself. > > Of course, from time to time, I find something that is not clear to me > but indeed after a couple of research you find the information you were > looking for. > > I love that language and above all, I love using it. > > Sorry for this little spam but it is always good to acknowledge good > things and not only complaining when it doesn't work. > > Thanks the Python team. > - Sylvain > > From anthonybaxter at gmail.com Sun Aug 22 07:24:07 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sun, 22 Aug 2004 21:24:07 +1000 Subject: [PATCH] RE: J2 decorator grammar In-Reply-To: References: Message-ID: On Sun, 22 Aug 2004 11:05:35 +0100 (BST), Michael Sparks wrote: > > > On Sun, 22 Aug 2004, Anthony Baxter wrote: > > On Sun, 22 Aug 2004 01:41:58 +0100 (BST), Michael Sparks wrote > > > The patch can be found here: > > > * http://thwackety.com/decorator_syntax_J2.patch > > > > Good to see. There's a few more bits than this that need to be > > done, though - see http://www.python.org/sf/979728 for the original > > @decorator patch, this should show you what else needs to be > > changed. > > Many thanks for the pointer. I'll try and make sure I cover all the bases, > but I suspect I'll miss something, but I'll try not to :) Well, in the comments for that patch, I listed all of the files changed by the @syntax - that at least gives you a 'to-do list' to work through. Once you've got what you think is the complete set, create a patch and post it to SF. From bokr at oz.net Sun Aug 1 14:06:59 2004 From: bokr at oz.net (Bengt Richter) Date: 1 Aug 2004 18:06:59 GMT Subject: transforming a list into a string References: Message-ID: On Sun, 1 Aug 2004 11:00:32 +1000, Andrew Bennetts wrote: >On Sat, Jul 31, 2004 at 08:43:52PM -0400, Roy Smith wrote: >> Tim Peters wrote: >> > Note that Peter Otten previously posted a lovely O(N) >> > solution in this thread, although it may be too clever for some >> > tastes: >> > >> > >>> from itertools import izip >> > >>> items = ['1','2','7','8','12','13'] >> > >>> it = iter(items) >> > >>> ",".join(["{%s,%s}" % i for i in izip(it, it)]) >> > '{1,2},{7,8},{12,13}' >> >> Personally, I'm not a big fan of clever one-liners. They never seem >> like such a good idea 6 months from now when you're trying to figure out >> what you meant when you wrote it 6 months ago. > >It's a two-liner, not a one-liner (although it could be made into a >one-liner with enough contortions...). > Assuming items definition doesn't count in the line count, >>> items = ['1','2','7','8','12','13'] then one line seems to do it, not that obscurely (depending on your glasses ;-) >>> ",".join(["{%s,%s}"%(n(),n()) for n in [iter(items).next] for i in xrange(0,len(items),2)]) '{1,2},{7,8},{12,13}' >The only other way I could see to expand this solution would be to write it >as: > it = iter(items) > pairs = izip(it, it) > s = ",".join(["{%s,%s}" % i for i in pairs]) > >I don't know if three-liners meet your threshold for verbosity ;) > >Well, you could write it as: > > pairs = [] > it = iter(items): > while True: > try: > pair = it.next(), it.next() > except StopIteration: > break > pairs.append(pair) > s = ",".join(["{%s,%s}" % i for i in pairs]) > >But at that point, the scaffolding is large enough that it obscures the >purpose -- I definitely find this harder to read than the two-liner. > >I find Peter's original form easy to read -- if you understand how "izip(it, >it)" works (which is a very simple and elegant way to iterate over (it[n], >it[n+1]) pairs), the rest is very clear. Agreed. Regards, Bengt Richter From uj797 at victoria.tc.ca Wed Aug 18 03:49:21 2004 From: uj797 at victoria.tc.ca (Arthur T. Murray) Date: 17 Aug 2004 23:49:21 -0800 Subject: Mind.py References: Message-ID: <4122fbf1@news.victoria.tc.ca> Roman Suzi wrote on Tue, 17 Aug 2004: > [...] > New version (refactured) is available: > > http://python.onego.ru/mind/__init__.py > http://python.onego.ru/mind/aLife.py > http://python.onego.ru/mind/Security.py > [...] http://yaroslav.hopto.org/pubwiki/index.php/ai-python OT APTYPA! From pink at odahoda.de Tue Aug 24 13:53:10 2004 From: pink at odahoda.de (Benjamin Niemann) Date: Tue, 24 Aug 2004 19:53:10 +0200 Subject: Overlapping tests In-Reply-To: <8f6sv1-nj7.ln1@valpo.de> References: <8f6sv1-nj7.ln1@valpo.de> Message-ID: Mathias Waack wrote: > Hi, > > I have some time consuming tests which could (and should) run > simultaneously. Is there a way to achieve this behavior without > using (self-coded) threads? Unittest seems to be designed to run one > test after another, but not to run much tests at the same time. > > The only way I can see so far is to start all tests during setUp() > and wait for each test-job in a job specific test() method. If I understand you correctly, what you really want is one test that tests the simultaneous executing of multiple tasks - a slighty different formulation of your problem that suggest a totally different implementation ;) From BruceWhoHKL at gawab.com Wed Aug 18 21:59:30 2004 From: BruceWhoHKL at gawab.com (BruceKL WhoH) Date: Thu, 19 Aug 2004 09:59:30 +0800 Subject: metaclass ??? Message-ID: <20040819015844.8B5F11E4003@bag.python.org> Mike C. Fletcher: Thanks,I have downloaded your pdf and code. But I'm still confused. What I'm trying to do is : I want to make two class, they are just subtly different,for example class A: def f(self): print 'a' ...#other codes class B: def f(self): print 'b' ...#other codes all other codes are identical,just f is different. So can I use meta-class here? Or I should do this by another way? BTW,your pdf is quite nice,how do you make it? Beamer,pdfscreen, or PPT ? ======= 2004-08-18 21:58:11 Mike C. Fletcher wrote: ======= >BruceKL WhoH wrote: > >>Hi, >> I have just read David Mertz's Metaclass programming in Python,but I'm still confused. >>can someone show me an example to explain when metaclass is needed? >> >> >In large part this is the question that my PyCon presentation was trying >to explore. If you're interested, you can find the presentation and >sample code here: >http://www.vrplumber.com/programming/ > >> I think metaclass can be treated as a class factory,but how to specify the class generated? For example: >> >> >See particularly the metainitialisation.py sample code for the >presentation, which does approximately what I think you're trying to do >with your example. > >HTH, >Mike > >________________________________________________ > Mike C. Fletcher > Designer, VR Plumber, Coder > http://www.vrplumber.com > http://blog.vrplumber.com > >-- >http://mail.python.org/mailman/listinfo/python-list >. = = = = = = = = = = = = = = = = = = = = ????????BruceKL WhoH ????????BruceWhoHKL at gawab.com ??????????2004-08-19 From ajsiegel at optonline.com Mon Aug 23 13:00:39 2004 From: ajsiegel at optonline.com (Arthur) Date: Mon, 23 Aug 2004 17:00:39 GMT Subject: __name__ becoming read-write? References: Message-ID: <3b8ki0tlphodtt8ge8an274qp78ihp1i3n@4ax.com> On Tue, 24 Aug 2004 02:28:09 +1000, Anthony Baxter wrote: >On Mon, 23 Aug 2004 15:58:26 GMT, Arthur wrote: >> Of course I am curious as to why, and what would be involved, and >> wrong,. with merging the local variable and the actual name for these >> special syntax items. It would seem to have merit on its own terms. >> >> For example I had noticed to use string substition on a function doc I >> needed to assign to __doc__ outside the function. > >How would you envisage this working? Look at the following code: > >def foo(arg): > __doc__ = "bingle!" > if arg < 0: > __doc__ = "bangle!" > if arg > 0: > __doc__ = "bongle!" > >Now, _before_ this code is run, what's foo.__doc__ supposed to be set >to? Remember, at this point, the code has not been run. The local >__doc__ has no value at this point. > >Special casing __doc__ (or __name__) so that assignments to a local >like that inside a function assign magically to the function object is >bad magic. It leads to confusion and poor coding. In general, inside a >function, you don't have access to the function object itself[1] I see the point. But.. there is always a but. I'm thinking now a special sytnax item in the __form__ at the top of function that would: 1) put one on notice that the function is to be transformed (as in "see below"). 2) allow a name to be assigned to it, which will become the transform's __name__. Something in the general direction, I think, of where Paul Morrow's instincts were going. I like it. And have no idea whether it is feasible. Art From mwh at python.net Mon Aug 23 14:18:04 2004 From: mwh at python.net (Michael Hudson) Date: Mon, 23 Aug 2004 18:18:04 GMT Subject: Finding a class' superclasses References: Message-ID: Hallvard B Furuseth writes: > How do I find a class' immediate superclasses? > That is, given > class A: pass > class B(A): pass > class C(A): pass > class D(B, C): pass > I want a function foo where foo(D) or foo(D()) returns (B, C). > (Well, the order of the classes is not important.) D.__bases__? Cheers, mwh -- ... Windows proponents tell you that it will solve things that your Unix system people keep telling you are hard. The Unix people are right: they are hard, and Windows does not solve them, ... -- Tim Bradshaw, comp.lang.lisp From tdwdotnet at gmail.com Mon Aug 30 17:08:42 2004 From: tdwdotnet at gmail.com (Tim Williams (gmail)) Date: Mon, 30 Aug 2004 22:08:42 +0100 Subject: how to get size of email attachment In-Reply-To: <63b5e209.0408301105.58b9207a@posting.google.com> References: <63b5e209.0408301105.58b9207a@posting.google.com> Message-ID: <9afea2ac040830140866f46714@mail.gmail.com> On 30 Aug 2004 12:05:18 -0700, Joh wrote: > hello, > > i'm looking for a way to get total size of an email (with its attached > files) using library such as poplib, or ? > > can someone help me or give me an url from where to start ? thinking aloud and off the top of my head , you could try the email module (python docs) import email msg = email.message_from_file(xxx) (or email.message_from_string(xxx) ) then something like for part in msg.walk(): length = len(str(part)) fname = part.get_filename() or if msg.is_multipart( ): temp_payload = msg.get_payload() for x in range(len(temp_payload)): print temp_payload[x].get_content_type() print temp_payload[x].get_filename() print len(str(temp_payload[x])) Remember any size you get will be the size of the attachment whilst its encoded into a mime object, which won't be the same as the size of the file on disk. I'm not sure the above will work, but its in the right ball park, If you don't have any luck post back and I'll look into it next time I'm in the office and have python docs easily to hand. From hanser at club-internet.fr Mon Aug 16 14:33:05 2004 From: hanser at club-internet.fr (Pierre Hanser) Date: Mon, 16 Aug 2004 20:33:05 +0200 Subject: Python secure? In-Reply-To: <4120c3b8$0$8079$a1866201@newsreader.visi.com> References: <411ffef6$0$65603$a1866201@newsreader.visi.com> <4120c3b8$0$8079$a1866201@newsreader.visi.com> Message-ID: <4120fdcf$0$305$7a628cd7@news.club-internet.fr> Grant Edwards wrote: > On 2004-08-16, Roger Binns wrote: > >>Grant Edwards wrote: >> >>>I don't see how decompiling is a copyright violation. If I buy >>>a copy of a book, I'm pretty sure I can translate it into >>>another language if I want to form my own use. >> >>They need to use what they decompile for it to be a copyright >>violation. > > > IANAL, but it looks like under Title 17, the act of creating a > derived work is an infringement. It doesn't say the derived > work has to be used and/or distributed for it to be an > infringement. > some countries have such stupid regulations... From frithiof.jensen at die_spammer_die.ericsson.com Thu Aug 5 04:03:45 2004 From: frithiof.jensen at die_spammer_die.ericsson.com (Frithiof Andreas Jensen) Date: Thu, 5 Aug 2004 10:03:45 +0200 Subject: DB beginner help References: Message-ID: "Frithiof Andreas Jensen" wrote in message news:cesp5u$sha$1 at newstree.wise.edt.ericsson.se... BTW, the 's in the query string are wrong. From jdhunter at ace.bsd.uchicago.edu Thu Aug 26 22:39:06 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Thu, 26 Aug 2004 21:39:06 -0500 Subject: 3D geometry module? In-Reply-To: <412e0951$0$6157$db0fefd9@news.zen.co.uk> (Will McGugan's message of "Thu, 26 Aug 2004 17:01:20 +0100") References: <412e0951$0$6157$db0fefd9@news.zen.co.uk> Message-ID: >>>>> "Will" == Will McGugan writes: Will> Hi, Is there a general purpose 3D geometry module for Will> Python? I would like to be able to read / write 3D models Will> and perform per vertex / per face operations on them. Will> Failing that, are there vector / matrix / quaternion classes Will> I can make use of? VTK is absolutely astounding in depth, breadth and quality, and has a full python wrapper. For win32, the enthought edition of python has VTK built in. Can take years to wrap your head around, though, in my experience. It's that big. JDH From peter at engcorp.com Tue Aug 17 12:14:30 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 17 Aug 2004 12:14:30 -0400 Subject: Mind.py In-Reply-To: References: <41220b22@news.victoria.tc.ca> Message-ID: Roman Suzi wrote: > rsvp = 1000 > ... > time.sleep(rsvp/1000) # End of quasi-loop time-delay of rsvp-value milliseconds. Latent bug... someone will decide during maintenance to change that "rsvp" delay to, perhaps, a smaller value, resulting in no delay at all... -Peter From mike.ayers at tumbleweed.com Sun Aug 15 03:09:10 2004 From: mike.ayers at tumbleweed.com (Mike Ayers) Date: Sun, 15 Aug 2004 07:09:10 +0000 (UTC) Subject: Raw IP packets on Linux References: Message-ID: Mike Ayers tumbleweed.com> writes: > What am I getting wrong here? What address type does this socket expect? After further review, I find that AF_PACKET wants addresses that contain the interface and protocol number. You can also specify an ethernet address, but it will be ignored (in fact, you can only specify a subset of ethernet addresses, as the address argument is parsed as 's'). Quick summary: socket( AF_PACKET, SOCK_DGRAM ) is useless. Workaround: use socket( AF_PACKET, SOCK_RAW ) and create your own ethernet headers, which (provided you're using true ethernet, which most of us are), is just the 6 byte ethernet destination address followed by the 6 byte ethernet source address (.i.e your own), followed by 0x0800 (IP) in two bytes. Really pretty simple if you're already using raw sockets, eh? HTH, /|/|ike From peter at engcorp.com Mon Aug 9 14:07:07 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 09 Aug 2004 14:07:07 -0400 Subject: Purely emotional perspective In-Reply-To: References: <10hf3oaltbo7o74@corp.supernews.com> Message-ID: Heiko Wundram wrote: > Am Montag, 9. August 2004 18:03 schrieb Peter Hansen: > >>After a while, when everyone is used to decorators, it won't >>be important to have them way out front like that, and they >>could just as well, and perhaps more readably (at that time), >>be moved to after the def. > > I don't think this is true... Decorators are not simply "meta-data" that is > attached to a function, they change the functions behaviour. As such, they > create a different function than the one which is declared. > > Consider: > class x(object): > def y(some,arg): > @ somedecorator > > > Versus: > > class x(object): > @ somedecorator > def y(some,arg): > > > Now, say you folded out the body of x with some form of decent editor. In the > first example, @somedecorator disappears, as it is part of the function body, Actually, the first example could just as well have been this: def y(some, arg) @ somedecorator : But I can just hear the arguments against that, much as I like it. > in the second example, it stays in (and I wouldn't want an editor to fold out > the decorating statements for a function, and it would be kind'a hard to have > a sensible way for the editor to display the first few lines decorating the > function inside the function body while the function is folded out). I *would* like decorators to be folded, I think, if I were in the habit of using folding editors. But I'm fairly sure it wouldn't be hard to avoid folding @ lines that immediately follow the :, or for that matter that come just before it. The real issue here (not that it bothers me) is that a lot of editors are probably tied to the idea that the : comes right after the argument list or something, so they probably would have to be redone to handle pre-colon decorators. > The docstring of a function actually is only meta-data (in my taste), and thus > should remain inside the function definition. This argument makes no sense to me. Why should any meta-data be inside the function body? There should probably be one place where all meta-data is defined, and it should be used consistently for everything, docstrings included. (The pie-syntaxians are heading that way, it seems.) > When and how decorators do something to the method is unimportant to my taste > (they are executed after the function definition has been executed), but > visibly seeing that the decorator is being applied to the function is much > easier for the second syntax. To tell the truth, I think I prefer the current approach, where the function is clearly, explicitly decorated *after* it has been defined, and no new syntax is required. Python is clearly on a huge evolutionary surge and conservative views on the matter are definitely not winning out right now. And the usual argument (submit a patch!) doesn't really work when those who want to avoid many changes try it... I've been *not* submitting a patch on lots of changes to Python, but somehow it's never been accepted. ;-) -Peter From artur_spruce at yahoo.com Fri Aug 6 04:39:43 2004 From: artur_spruce at yahoo.com (AdSR) Date: 6 Aug 2004 01:39:43 -0700 Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) References: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> Message-ID: Istvan Albert wrote in message news:<6LWdnZCpvI7Ico_cRVn-hw at giganews.com>... > Paul McGuire wrote: > > > Please reconsider the "def f() [classmethod]:" construct. Instead of > > invoking a special punctuation character, it uses context and placement, > > with familiar old []'s, to infuse the declaration of a function with special > > characteristics. If this causes def lines to run longer than one line, > > perhaps the same rule that allows an unmatched "(" to carry over multiple > > lines without requiring "\" continuation markers could be used for unmatched > > "["s, as in: > > > > def f() [ staticmethod, > > synchronized, > > alphabetized, > > supersized, > > returns('d') ]: > > Well said! > > I have the feeling that this always was and still is > the favorite. By the way, does anybody remember the first proposed syntax? def f() as staticmethod, synchronized, alphabetized, \ supersized, returns('d'): pass Nowadays I'm more in favor of the list syntax, since in the future it could be dynamized by allowing list comprehension. Not that you can't achieve the same goal with static decorator list, using a decorator that iterates over that dynamic list of decorators that you want. Waking-up-the-dead-ly yours, AdSR From Michael.J.Fromberger at Clothing.Dartmouth.EDU Fri Aug 20 09:41:41 2004 From: Michael.J.Fromberger at Clothing.Dartmouth.EDU (Michael J. Fromberger) Date: Fri, 20 Aug 2004 09:41:41 -0400 Subject: Rita Sue and Bob too References: Message-ID: In article , "M. Clift" wrote: > Hi All, > > Can someone help. I promise I've looked how to do this but can't find a > way... > > Ok, to find one name is easy > > if 'Bob' in list: > print "They were found" > else: > print "They are not in list" > > But, how to I find a sequence in a list of unknown size? i.e. this sequence > in list of other names and replace it with three others? > > 'Rita','Sue','Bob' > > This is almost a nightly occurrence (my posting questions), but I am > learning : ) You've gotten several other answers, but I'd like to propose yet another one: def replace_sublist(L, S, T): """Replace each sublist of L equal to S with T. Also returns the resulting list.""" assert(len(S) == len(T)) for p in [ x for x in xrange(len(L)) if L[x] == S[0] and L[x : x + len(S)] == S ]: L[p : p + len(S)] = T return L In short, the list comprehension gives all the offsets in L where a copy of S can be found as a sublist. Now, if it happens that some of these positions overlap (e.g., L = [ 1, 1, 1 ] and S = [ 1, 1 ]), then the results will be strange. But as long as your matches do not overlap, this should work well. -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From davidf at sjsoft.com Thu Aug 19 12:33:03 2004 From: davidf at sjsoft.com (David Fraser) Date: Thu, 19 Aug 2004 18:33:03 +0200 Subject: My only complaint about Python In-Reply-To: References: Message-ID: Darren Dale wrote: > I love the language. I love the community. My only complaint is that > Python for Windows is built with Visual Studio. > > It is too difficult to build python, or a module, from source. This is > what open source is all about, isnt it? I even have a copy of visual > studio, and I still cant build modules from source, because my academic > copy is version 7. As a scientist funded by the NSF, I feel compelled to > do all my work using free software (I feel compelled to use free > software, regardless). And I feel compelled to contribute to the > scientific capabilities of my favorite programming language. But this > compiler issue is a big (and seemingly unnecessary) impediment. Will the > BDFL ever split with Visual Studio? I agree. I don't mind it being built with Visual Studio, but out of the box mingw compatibility would be cool... From shahpr at purdue.edu Mon Aug 9 14:04:45 2004 From: shahpr at purdue.edu (Pulin Shah) Date: 9 Aug 2004 11:04:45 -0700 Subject: windows service control manager problem Message-ID: Hi. I am wondering if anyone here can help me with a problem I am having. I have written an XMLRPCServer to run on WinXP. When I register and run the server, I cant get it to listen to a port. But if I just execute the server portion of the code, it does. Any idea why it doesnt work after registering it with the service control manager? From mark_bottjer at hotmail.com Sun Aug 8 19:49:51 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Sun, 08 Aug 2004 19:49:51 -0400 Subject: PEP-0318 In-Reply-To: References: <41122FC2.1080608@interlink.com.au> <4114152f@nntp.zianet.com> Message-ID: <4116bc20$1@nntp.zianet.com> Doug Holton wrote: > You have to click on the "UserPreferences" link on the top right of > the page and create an account (with a username like MarkBottjer and > a password). Then when you refresh the PythonDecorators page you will > be able to click an EditText link at the bottom of the page to edit > it. Thanks. > I noticed you posted the "@decorators at the top of function body" > idea right before I posted it here, too. See the "compromise?" > thread. This idea seems to have occurred to a few people independently. Another guy apparently beat me to posting it by a day or so. Here's hoping that someone with "cred" will see it and like it enough to promote it to GvR. -- Mark From jmeile at hotmail.com Tue Aug 10 16:50:27 2004 From: jmeile at hotmail.com (Josef Meile) Date: Tue, 10 Aug 2004 22:50:27 +0200 Subject: Python equivalent to a C trick In-Reply-To: <4119327f$1@pfaff2.ethz.ch> References: <1d7b6d0d.0408092255.1177908e@posting.google.com> <4119327f$1@pfaff2.ethz.ch> Message-ID: <41193351$1@pfaff2.ethz.ch> Josef Meile wrote: >>>> Example: >>>> printf( "you have %i %s", num_eggs, num_eggs > 1 ? "eggs" : "egg" ); >>> >>> >>> print "you have %i %s" % ( num_eggs, ("egg","eggs")[num_eggs>1] ) >> >> >> >> I would choose "!=" instead of ">" as the comparison operator. I >> think the >> accepted vernacular is: >> >> you have -2 eggs >> you have -1 eggs >> you have 0 eggs >> you have 1 egg >> you have 2 eggs >> you have 3 eggs >> you have 0.5 eggs > > No offense intended, but the negative and float cases don't make any > sense for me on this context. You can't have -2 eggs or 0.5 eggs. The > last case won't occure as well because the output is being parsed to > int, so, you will get "you have 0 egg", which is again false. This error > happens with both solutions (with > and with !=). Correction: The error happens only when using the ">" operator. With the "!=" doesn't happen. From mauriceling at acm.org Tue Aug 24 05:32:21 2004 From: mauriceling at acm.org (Maurice LING) Date: Tue, 24 Aug 2004 09:32:21 GMT Subject: using pexpect to control python Message-ID: <412b0b21$1@news.unimelb.edu.au> I know this might sounds wierd but I'm wondering if I can use pexpect or os.popen3 function to invoke and control python interpreter to make it act like a python interpreter in python? maurice From m.boeren at guidance.nl Fri Aug 20 04:25:33 2004 From: m.boeren at guidance.nl (Marc Boeren) Date: Fri, 20 Aug 2004 10:25:33 +0200 Subject: Alternative decorator syntax decision Message-ID: <0C77C7530EA52A4EBD1C47C80D1D291E17DE2A@sbs.GuidanceBV.local> > voting on _alternatives_ to A. If we're only voting on alternatives, I would change my vote (J2 J2 A2) to (J2 J2 J2). Cheerio, Marc. From bh at intevation.de Sat Aug 7 12:42:46 2004 From: bh at intevation.de (Bernhard Herzog) Date: Sat, 07 Aug 2004 18:42:46 +0200 Subject: @decorators References: <10h73e5kh1et536@news.supernews.com> <4113e5be@nntp.zianet.com> <10h7qlg5adbfj86@news.supernews.com> Message-ID: Tim Peters writes: > It does. What it says is "arbitrary expressions will not work", and I > would agree that's vague if you insisted it was . What it means > is that parameters are fine, but things like > > @list_of_decorators[index] This could be written legally as @list_of_decorators.__getitem__(1) Or one could use operator.getitem > @eatme and deco1 or deco2 @eval("eatme and deco1 or deco2") > @random.choice([deco1, deco2, deco3]) That one is already legal! Seems the restriction is somewhat pointless as it's easy to work around if one really wants to. Bernhard -- Intevation GmbH http://intevation.de/ Skencil http://sketch.sourceforge.net/ Thuban http://thuban.intevation.org/ From R.Brodie at rl.ac.uk Mon Aug 9 11:00:22 2004 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Mon, 9 Aug 2004 16:00:22 +0100 Subject: how many bytes in an int References: <9ACRc.1523$bJ2.9739@news1.mts.net> <4116f8ee$0$8076$a1866201@newsreader.visi.com> <41170cd1$0$8076$a1866201@newsreader.visi.com> <41171116$0$8079$a1866201@newsreader.visi.com> <41172C9A.2020301@jessikat.fsnet.co.uk> <41178bde$0$8077$a1866201@newsreader.visi.com> Message-ID: "Grant Edwards" wrote in message news:41178bde$0$8077$a1866201 at newsreader.visi.com... > Like the man said, "struct" doesn't convert to-from integers of > specified byte lengths. It does if you ask it to. From jess.austin at gmail.com Thu Aug 26 18:20:10 2004 From: jess.austin at gmail.com (Jess Austin) Date: 26 Aug 2004 15:20:10 -0700 Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Paul Morrow wrote in message news:... > Currently, you can change a doc string outside of a function, by > modifying the function's __doc__ attribute [snip] > IMO, to change it inside of a function def should be (but isn't) as easy > as... > > >>> def foo(): > ... """ I am foo """ > ... __doc__ = __doc__ + 'indeed' I'm not trying to be mean, but why not use a class for this? This is the whole point of "self" - provide a persistent, updateable namespace for an object. (Note: explicit use of self in Python is a GOOD THING!) An object that needs such a namespace should be a class. I'm not sure why or how a function could use this anyway - why not just set the docstring to " I am foo indeed" to start with? If what you're looking for is a "configured function", which contains some data (or metadata) that is set at the beginning of the function's lifecycle, to me that would be a closure, which could be written like this: def closure_maker(postfix): def foo(): """ I am foo """ pass foo.__doc__ += postfix return foo Or perhaps there is another application you had in mind, for which this wouln't be sufficient? Paul: I admit I'm a bit confused by your wanting a function to have access to its metadata, because I could have sworn that earlier in the thread you defined metadata as data about an object that that object would never use itself. I could be thinking of someone else though... later, Jess From fallen at leveltwo.com Mon Aug 23 19:21:20 2004 From: fallen at leveltwo.com (Fred Allen) Date: 23 Aug 2004 16:21:20 -0700 Subject: age of Python programmers References: Message-ID: <72976037.0408231521.4ef1af1d@posting.google.com> Jeremy Jones wrote in message news:... > Lucas Raab wrote: > > >One thing I've always kind of wondered is what is the average age of a > >Python programmer?? What age groups use Python?? Something to think > >about.... > > > Sigh...I have programmed professionally in many languages since 1956, the year I began with IBM 704 and 705 absolute(not quite assembler). I have been a Python enthusiast for several years now, Regrettably, I program little now, for my other company responsibilities forbid it. Moreover, I'll be seventy next year; I seem slightly less quick at coding than in my salad days...happily, I'm surrounded by others still in theirs. I hope that all laboring in the vineyards of ones and zeros gain as much joy from their careers as I have (and still do) from mine. Fred Allen From pythongnome at hotmail.com Wed Aug 18 08:20:31 2004 From: pythongnome at hotmail.com (Lucas Raab) Date: Wed, 18 Aug 2004 12:20:31 GMT Subject: age of Python programmers Message-ID: One thing I've always kind of wondered is what is the average age of a Python programmer?? What age groups use Python?? Something to think about.... From reinhold-birkenfeld-nospam at wolke7.net Fri Aug 13 06:18:54 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Fri, 13 Aug 2004 12:18:54 +0200 Subject: Why I love python. In-Reply-To: <411C8CD9.32F39C2@mega-nerd.com> References: <411C8CD9.32F39C2@mega-nerd.com> Message-ID: <2o3iboF662nfU1@uni-berlin.de> Erik de Castro Lopo wrote: > Nick Patavalis wrote: >> > > > >> Python needs drastic performance improvement if it is to scrap-off the >> "scripting language" stigma. The only way to get these improvements is >> making it possible for a python implementation to produce *efficient* >> *compiled* code. At the same time the dynamic-typing nature of the >> language is one of its most valuable characteristics. And this is one >> of the hardest problems when trying to write a decent python >> compiler. If you define a function like: >> >> def sum (a, b): >> return a + b >> >> How can the compiler know what code to produce? > > I know of at least one language which has solved this problem, Ocaml > > http://www.ocaml.org/ > > Its called type inferencing and since there is at least one working > implementation, it can't be THAT hard. Refer to the task "Typed Python" somewhere in the past if you want more information about Python and Type inferencing. Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From edreamleo at charter.net Thu Aug 5 13:47:45 2004 From: edreamleo at charter.net (Edward K. Ream) Date: Thu, 5 Aug 2004 12:47:45 -0500 Subject: Confused about pep 318 References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: <10h4sm63o4dnd5a@corp.supernews.com> > None of the decorator discussions _ever_ reached a conclusion. I find this oddly reassuring, in a sorta black-humorous way. At least we won't have to undo the previous agreement :-) > Would the bitching have been > seriously that much better if, half an hour before I committed the patch, > Guido had posted a note saying pretty much what I forwarded on from him? The issue is not about rights to commit code, the issues are whether a) the question was ever publicly discussed at all and b) whether any consensus was reached. Apparently, the answer to both questions is No. > Yes, it would have been nice if PEP-0318 was updated in advance of this. Not nice. Essential. It is fundamentally unfair to pretend to have discussed a proposal publicly that has always been grossly misrepresented in the one place one would naturally look to find information about it. Edward -------------------------------------------------------------------- Edward K. Ream email: edreamleo at charter.net Leo: Literate Editor with Outlines Leo: http://webpages.charter.net/edreamleo/front.html -------------------------------------------------------------------- From tim.hochberg at cox.net Tue Aug 10 15:38:01 2004 From: tim.hochberg at cox.net (Tim Hochberg) Date: Tue, 10 Aug 2004 12:38:01 -0700 Subject: PEP-318, billion-and-first syntax proposal Message-ID: As soon as one of these syntax discussions go on long enough, I start to think that, whatever the problem ,it should be solved by thunks (search python dev if you need to know what a thunk is) or something thunk-like. It's a personal weakness, I suppose. In that vein, here's my entry into the Great Decorator Debate 2004. def NAME as EXPRESSION: BLOCK BLOCK is executed in a separate namespace *before* EXPRESSION is evaluated. EXPRESSION is then evaluated in BLOCK's namespace. This is probably best illustrated with an example or three: class C: # The standard staticmethod example. It works reasonably well for this, but is # a bit wordier than some examples. It's clear what's happening though. def foo as staticmethod(body): def body(x, y): #... # This method generalized nicely to properties, which I like. def bar as property(getbar, setbar, None, doc): doc = "That crazy bar property!" def getbar(self): #.... def setbar(self, value): #.... # It's pretty good for the nasty long decorators and arg list case. def bar as OBJCDecorator("@#%$@#^", SomeOtherDecorator("asdfasf", body)): def body(a_long_argument_list, with_long_arg_name, _etc.): #.... This syntax is by no means perfect; it's a little wordy in the simple case for one thing. But it's more obvious what's happening in this syntax than in any of the others that I've seen which I think is a big plus. It also generalizes well to the hypothetical Python 3000 with optional type checking, since the signature can be placed on the user visible 'foo' instead of on the pre-transform body: def foo(int, int)->int as staticmethod(body): def body(x, y): #... Enjoy, -tim From luismg at gmx.net Mon Aug 23 21:45:15 2004 From: luismg at gmx.net (Neuruss) Date: 23 Aug 2004 18:45:15 -0700 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> <278de0e.0408220636.3ee25f9d@posting.google.com> <278de0e.0408221450.324e8178@posting.google.com> Message-ID: <278de0e.0408231745.69eb33a6@posting.google.com> > > That's true. If that's what you'd said in the first place, nobody would > > have argued with you. However, this is what you said: > > > > It seems there are quite a few projects aimed to improve Python's > > speed and, therefore, eliminate its main limitation for mainstream > > acceptance. > > Hey, cut the boy/girl some slack. I suspect what s/he meant to say was: > > It seems there are quite a few projects aimed to improve Python's > speed and, therefore, eliminate its main perceived limitation for > mainstream acceptance. At least someone who got it right!!! I thought this was the spanish inquisition... From jdhunter at ace.bsd.uchicago.edu Mon Aug 30 10:21:31 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Mon, 30 Aug 2004 09:21:31 -0500 Subject: why does this fail on python 2.2? Message-ID: I'm trying to understand why some code from a module I'm using is failing on 2.3 but working on 2.3. Here is the minimal example that replicates the problem class Results(object): __slots__ = ( "__doinit" ) def __new__(cls): retobj = object.__new__(cls) retobj.__doinit = True return retobj x = Results() On python2.2, this fails with mother:~/tmp> python2.2 test.py Traceback (most recent call last): File "test.py", line 8, in ? x = Results() File "test.py", line 5, in __new__ retobj.__doinit = True AttributeError: 'Results' object has no attribute '_Results__doinit' From me at privacy.net Thu Aug 12 15:40:31 2004 From: me at privacy.net (Dan Sommers) Date: 12 Aug 2004 15:40:31 -0400 Subject: Verbosity Check Style References: Message-ID: On Thu, 12 Aug 2004 11:23:49 -0400, wrote: > I would like to get people's views on the best way to implement > verbosity (or any command-line option) into python scripts. Use the logging module (new in 2.3). I think that verbosity equates to the INFO level. Regards, Dan -- Dan Sommers Never play leapfrog with a unicorn. From jeremy+plusnews at jeremysanders.net Thu Aug 26 05:08:46 2004 From: jeremy+plusnews at jeremysanders.net (Jeremy Sanders) Date: Thu, 26 Aug 2004 10:08:46 +0100 Subject: Best processor (i386) for Python performance? References: <789f72ac.0408251950.e85d23e@posting.google.com> <412d7e9d$0$26184$9b622d9e@news.freenet.de> Message-ID: On Thu, 26 Aug 2004 08:09:40 +0200, Martin v. L?wis wrote: > Python applications are often memory intensive, so a fast bus and a large > cache should help. Also, raw clock speed should help. Hyperthreading and > AMD64 are irrelevant (although for the latter, it would be interesting to > see how linux-x86 compares to linux-amd64 on the same machine for Python > performance). Yes - AMD64 could be relevant if Python gets a speed boost from the extra registers it has available. Jeremy From adurdin at gmail.com Sat Aug 21 18:07:56 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Sun, 22 Aug 2004 08:07:56 +1000 Subject: Overriding logical operators? In-Reply-To: <04Aug21.160611edt.97252@mail.srv.cquest.utoronto.ca> References: <04Aug21.160611edt.97252@mail.srv.cquest.utoronto.ca> Message-ID: <59e9fd3a040821150717a49723@mail.gmail.com> On Sat, 21 Aug 2004 16:06:08 -0500, Chris Siebenmann wrote: > > Conceptually, 'and' and 'or' (and 'not') don't operate on objects: > they operate on truth values (generally derived from objects). But in Python, a "truth value" is an object: a bool object. From mjackson at alumni.caltech.edu Wed Aug 18 10:08:36 2004 From: mjackson at alumni.caltech.edu (Mark Jackson) Date: 18 Aug 2004 14:08:36 GMT Subject: age of Python programmers References: Message-ID: "Lucas Raab" writes: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... 55. Wrote my first program at 16 (Fortran, punch cards). -- Mark Jackson - http://www.alumni.caltech.edu/~mjackson Fascism should more properly be called corporatism, since it is the merger of state and corporate power. - Benito Mussolini From simoninusa2001 at yahoo.co.uk Mon Aug 9 14:48:34 2004 From: simoninusa2001 at yahoo.co.uk (simo) Date: 9 Aug 2004 11:48:34 -0700 Subject: VB-like GUI designer? References: Message-ID: <30260531.0408091048.7011855f@posting.google.com> Fred wrote: [snip] > I tried wxDesigner and wxGlade, but neither lets me move the widgets > around. Dunno what you're smoking there man! > I also tried Dialogblocks, but it seems to only handle C++ or XRC, not Python. I don't know that one. > Is this all there is, or is there a gem I missed? Qt Designer (for use with PyQt though) or just hand-code the layout, it ain't that hard..... From dieter at handshake.de Fri Aug 13 16:00:33 2004 From: dieter at handshake.de (Dieter Maurer) Date: 13 Aug 2004 22:00:33 +0200 Subject: Importance of C# (was Re: IronPython-0.6 is now available!) References: <278de0e.0407281353.27b6a457@posting.google.com> <5dydnZSDZaARoZXcRVn-ug@powergate.ca> <1n5z28erh2m3u.dlg@baczek.net.invalid> <537ea4cd.0408070757.14790cfe@posting.google.com> <41155c78$0$4348$626a14ce@news.free.fr> <144d0df.0408092156.1455f2af@posting.google.com> Message-ID: grv575 at hotmail.com (grv575) writes on 9 Aug 2004 22:56:55 -0700: > ... > Really MI > causes more issues and confusion than it solves. I recently implemented a core SGML/XML based content management system within about 4 months. It heavily uses mixin classes: PropertyManagement, History, WorkflowSupport, Persistency, Skinnability, DOMSupport, Publishablity, Versionability, ... Whenever a class needs some elementary feature, it simply inherits the corresponding mixin class and (maybe) customizes (overrides) some adapter methods. Multiple inheritance is vital for this approach! While it would (of course) be possible to implement such a system with single inheritance (or even without inheritance), I guess that the code size would be about 6 times as large and it would have taken about twice as long: A class that now just adds a mixin class to its inheritance list would get littered with redefinitions for the mixin class's public API functions. Each redefinition would stupidly delegate to an embedded instance of the mixin class, thus it is not difficult. Nevertheless, it would clutter the code, make unnessary effort, add potential for trivial bugs. Dieter From nicksjacobson at yahoo.com Fri Aug 27 06:20:00 2004 From: nicksjacobson at yahoo.com (Nick Jacobson) Date: 27 Aug 2004 03:20:00 -0700 Subject: Call for signatories for J2 References: Message-ID: I'm not nuts about "using", but it's far better than "@" (as would be lots of other keywords). I vote FOR. --Nick Jacobson From newsgroups at jhrothjr.com Fri Aug 6 17:32:48 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 6 Aug 2004 17:32:48 -0400 Subject: PEP 263 status check References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> <10h5hgvpafm8a64@news.supernews.com> <41133C76.8040302@v.loewis.de> <10h6rklt3fa1690@news.supernews.com> <41137799.70808@v.loewis.de> <10h724r20kkeqb2@news.supernews.com> Message-ID: <10h7u8m9qknh76e@news.supernews.com> "Hallvard B Furuseth" wrote in message news:HBF.20040806qchc at bombur.uio.no... > An addition to Martin's reply: > > John Roth wrote: > >"Martin v. L?wis" wrote in message > >news:41137799.70808 at v.loewis.de... > >>John Roth wrote: > >> > >> To be more specific: In an UTF-8 source file, doing > >> > >> print "?" == "\xc3\xb6" > >> print "?"[0] == "\xc3" > >> > >> would print two times "True", and len("?") is 2. > >> OTOH, len(u"?")==1. > >> > >>> The point of this is that I don't think that either behavior > >>> is what one would expect. It's also an open invitation > >>> for someone to make an unchecked mistake! I think this > >>> may be Hallvard's underlying issue in the other thread. > >> > >> What would you expect instead? Do you think your expectation > >> is implementable? > > > > I'd expect that the compiler would reject anything that > > wasn't either in the 7-bit ascii subset, or else defined > > with a hex escape. > > Then you should also expect a lot of people to move to > another language - one whose designers live in the real > world instead of your Utopian Unicode world. Rudeness objection to your characteization. Please see my response to Martin - I'm talking only, and I repeat ONLY, about scripts that explicitly say they are encoded in utf-8. Nothing else. I've been in this business for close to 40 years, and I'm quite well aware of backwards compatibility issues and issues with breaking existing code. Programmers in general have a very strong, and let me repeat that, VERY STRONG assumption that an 8-bit string contains one byte per character unless there is a good reason to believe otherwise. This assumption is built into various places, including all of the string methods. The current design allows accidental inclusion of a character that is not in the 7bit ascii subset ***IN A PROGRAM THAT HAS A UTF-8 CHARACTER ENCODING DECLARATION*** to break that assumption without any kind of notice. That in turn will break all of the assumptions that the string module and string methods are based on. That in turn is likely to break lots of existing modules and cause a lot of debugging time that could be avoided by proper design. One of Python's strong points is that it's difficult to get into trouble unless you deliberately try (then it's quite easy, fortunately.) I'm not worried about this causing people to abandon Python. I'm more worried about the current situation causing enough grief that people will decided that utf-8 source code encoding isn't worth it. > And tell me why I shouldn't be allowed to work easily with raw > UTF-8 strings, if I do use coding:utf-8. First, there's nothing that's stopping you. All that my proposal will do is require you to do a one time conversion of any strings you put in the program as literals. It doesn't affect any other strings in any other way at any other time. I'll withdraw my objection if you can seriously assure me that working with raw utf-8 in 8-bit character string literals is what most programmers are going to do most of the time. I'm not going to accept the very common need of converting unicode strings to 8-bit strings so they can be written to disk or stored in a data base or whatnot (or reversing the conversion for reading.) That has nothing to do with the current issue - it's something that everyone who deals with unicode needs to do, regardless of the encoding of the source program. John Roth > > -- > Hallvard From Michael.J.Fromberger at Clothing.Dartmouth.EDU Wed Aug 18 17:49:23 2004 From: Michael.J.Fromberger at Clothing.Dartmouth.EDU (Michael J. Fromberger) Date: Wed, 18 Aug 2004 17:49:23 -0400 Subject: PEP 318: Can't we all just get along? References: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: In article , Paul Morrow wrote: > Michael J. Fromberger wrote: > > > In article , > > Paul Morrow wrote: > >> class Foo: > >> def method1(self, a, b): pass # clearly an instance method > >> def method2(cls, a, b): pass # clearly a class method > >> def method3(a, b): pass # clearly a static method > > > > I think this is a terrible idea. What you are proposing is essentially > > that Python should assign special meaning to the identifiers "self" and > > "cls" when they appear as the first variable in a method definition > > inside a class. I am having a hard time thinking of anything LESS in > > the spirit of Python, short of writing in unstructured BASIC. > > 'self' already has a special meaning to experienced Python developers, > by virtue of its role in the recommended coding practices. That's true: And note, that its special meaning is interpreted not by the Python translator, but by the Python programmer. It is my feeling that it should remain thus. > And if you ask experienced Python developers who understand the > difference between class, static, and instance methods, to guess what > kind of method this is... > > def foo(cls, a, b): pass > > ...I bet the majority would correctly guess "class". Well, given just that definition, the guess would be incorrect. The current release of Python would also require: def foo(cls, a, b): pass # As defined above foo = classmethod(foo) Otherwise, it would be an instance method, not a class method. I hope this illustrates why visual conventions are not always as obvious as they seem, and should not be cast into the concrete of implementation. > Right. So a convention becomes a rule. Sounds like a natural > evolution. And just like in natural evoluation, not all mutations are desirable. ;) > Declarations aren't needed when an obvious interpretation of the code > conveys the desired meaning. What about when the obvious interpretation of the code does NOT convey the desired meaning? -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From http Tue Aug 17 04:18:25 2004 From: http (Paul Rubin) Date: 17 Aug 2004 01:18:25 -0700 Subject: Generators versus Coroutines References: Message-ID: <7xoelanpny.fsf@ruckus.brouhaha.com> Michael Sparks writes: > Correct. I never claimed that doing this in "pure" python was possible - > largly because I think such a concept is pretty silly. > > After all, what is "pure" anyway? > * Is using a module that comes with python allowed? Yes > * If so is using a module written in C acceptable? Only if it comes with Python > * If so what if greenlets gets included at some point in time, do > modules included cease being "pure", or would greenlets be > redefined?. I don't understand. Something using greenlets is impure now but becomes pur eif greenlets gets included. > * Also if using a builtin module written in C is "pure" then why are > modules written in C not included not "pure"? Because "Python" is what you get when you install the Python distro, so anything included with the distro is Python no matter what language it's written in. Anything not included with the distro is only Python if it's written in Python. > * You might conclude then that "pure" python couldn't use > modules written in C whether included with the interpreter or not. No, pure includes C modules included with the interpreter. > * If you conclude that what about the python interpreter? That'ss > written in C, so *that's* not pure if you mean code that only using > python anywhere in the system. (if you allow the interpreter, why > not modules that come with it?) The modules that come with the interpreter are allowed and they count as pure. Put another way, pure means any module you can run after installing the Python distro, without having to run anything except the Python distro (i.e. no C compiler). Maybe someday the Python distro will include a C compiler. If that happens, then all C modules will become pure. Until then, only the C modules that are made available through the Python installation process count as pure. > IMO, the question is one of practicality. It is practical to use > generators to build concurrent systems - and it works pretty well. Not Python generators. Generators in other languages, maybe. > If that's not good enough it is practical to using concurrency > implementated as an extension to python. If that's not good enough, > it is practical to a different implementation of python. Or if > concurrency in a single thread isn't sufficient you can change to > threads or processes. No that's ridiculous. Switching between OS threads needs context switching in and out of the kernel. Coroutines are supposed to be more like function calls in terms of overhead. Simulating them with OS threads is like simulating register loads and stores with XML transactions over the internet. > I prefer "practical python" over "pure python" ;-) Practical python very often means you have a Python distro that someone else installed. Whatever it can run, you can run, and whatever it can't run, you can't run. You don't get a C compiler. That's why the concept of "pure Python" is meaningful and important. > And if you choose appropriate coding conventions every problem domain that > co-routines and continuations can solve, generators can be used with > almost equal effectiveness. No, not Python generators, they're amazingly useful, but they're much less powerful than first class continuations. From peter at engcorp.com Mon Aug 16 11:42:53 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 11:42:53 -0400 Subject: Newbie question about file input In-Reply-To: References: Message-ID: Aaron Deskins wrote: > My first attempt at the python script is: > > #! /usr/bin/env python > import string > import sys > zf=open('test.pgn','r') > # games is number of games > games = 0 > while 1: > line = zf.readline() > if line == '': > break > ls = line.split() > print ls[0] > if ls[0] == '[Event': > games+=1 > zf.close() > print games Small note: it would make your code more readable and thus easier to comment on if you followed convention and used four spaces for indentation. Your volunteer tutors thank you! :-) > I'm having problems when the script reads a blank line from the pgn > file. I get the following error message: > IndexError: list index out of range > The problem is that ls[0] does not exist when a blank line is read. What > would be the best way of fixing this? The "best" way might be just to check for and ignore blank lines prior to the rest of the code that might fail when you find one: while 1: line = zf.readline() if not line: break # more idiomatic, perhaps, than if line == '' # remove leading and trailing whitespace, including newline line = line.strip() if not line: continue # don't break, go back for another # from here on line is guaranteed not to be blank Another approach might be to use exceptions, though I wouldn't really recommend it here since the above is fairly idiomatic, I believe: while 1: # blah blah ls = line.split() try: if ls[0] == '[Event': # blah except IndexError: # blank line, so no first field, so continue continue You might also consider using "ls.startswith('[Event')" instead, as that avoids the need to split the line at all, but you're doing fine on your own so far. (Not that this will stop someone from posting a one-liner using the "re" module and len(findall()), but you can safely ignore them. ;-) -Peter From abra9823 at mail.usyd.edu.au Sat Aug 14 07:55:13 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Sat, 14 Aug 2004 21:55:13 +1000 Subject: python and XML resources Message-ID: <1092484513.411dfda120873@www-mail.usyd.edu.au> hi! does anyone know of good online resources on XML processing in Python. I am using the PyXML package and have read the introductory XML HOWTO. what i am looking for is a more detailed and comprehensive coverage of the entire package - all the classes and functions etc cheers ajay ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From db3l at fitlinxx.com Tue Aug 31 12:43:11 2004 From: db3l at fitlinxx.com (David Bolen) Date: 31 Aug 2004 12:43:11 -0400 Subject: MSI Installer Problem: can't install 2.4a2 on new install of Win2kSP2 References: <412d7dcd$0$26184$9b622d9e@news.freenet.de> <412e5452$0$24835$9b622d9e@news.freenet.de> <92uui05l49lurff1depfmvblq8esqllcpg@4ax.com> <412f8ebd$0$13030$9b622d9e@news.freenet.de> Message-ID: "Martin v. L?wis" writes: > b) if there is no \, python.exe must be on the PATH. So we look there, > and find one in C:\python23, and believe this is us. This logic is > flawed, as we should *first* look into the current directory (I > think) You'd probably need to conditionalize the use of the current directory on Windows, since on *nix, the current directory isn't automatically searched. Maybe the current implementation represents a bit of *nix heritage. -- David From scott.b.drummonds.nospam at intel.com Wed Aug 11 16:25:19 2004 From: scott.b.drummonds.nospam at intel.com (Scott Brady Drummonds) Date: Wed, 11 Aug 2004 13:25:19 -0700 Subject: 'break' Causes Execution of Procedure? References: Message-ID: "Peter Otten" <__peter__ at web.de> wrote in message news:cfdlfi$l2l$06$1 at news.t-online.com... > Unfortunately you seem to have picked the wrong snippets, which by the way > look made-up. The only error I see Yeah, that was a typo. I certainly would prefer to post real failing code as opposed to code snippits, but I needed a way of distilling the importat parts out of the program. Sorry for doing a bad job of that. > The "most basic" error would be a print statement producing > > > DEBUG: begin main procedure > > sitting in a second place where it doesn't belong and isn't expected. Right. You've got the idea. There's no reason why the print statement at the first line of main() should be executed after the break statement. It doesn't make sense. > > How is it possible that the call to 'break' is seemingly being replaced > > with a call to 'main'? > > Other than with a buggy C-extension that is not possible. What is equally more confounding is that I cannot duplicate this error with a small case I can post here. :( I'm still trying, though... Scott -- Remove .nospam from my e-mail address to mail me. From isaact at netscape.net Fri Aug 27 21:24:43 2004 From: isaact at netscape.net (Isaac To) Date: 28 Aug 2004 09:24:43 +0800 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> <87hdqok9i6.fsf@sinken.local.csis.hku.hk> <1rfz68ely9.fsf@rovereto.ifi.uio.no> <876574k7du.fsf@sinken.local.csis.hku.hk> <1r3c28ejis.fsf@rovereto.ifi.uio.no> Message-ID: <87fz68vyuc.fsf@sinken.local.csis.hku.hk> >>>>> "Kjetil" == Kjetil Torgrim Homme writes: Kjetil> how long do you have to stare before spotting the bug? At the first instant when I look at the code, something like within 2 seconds. Kjetil> db.update_name(person) Kjetil> if is_student(person): Kjetil> db.update_courses(person) Kjetil> db.commit() Kjetil> only students have their names updated. I wonder why. Kjetil> real world examples have taken hours or days. Perhaps because you don't know Python? Or because you are too accustomed to writing C with broken indentation? Regards, Isaac. From aisaac at american.edu Fri Aug 13 16:06:03 2004 From: aisaac at american.edu (Alan G Isaac) Date: Fri, 13 Aug 2004 16:06:03 -0400 Subject: ironic doctest bug? Message-ID: <10hq7lsguiqfj93@corp.supernews.com> > python doctest.py -v Running doctest.__doc__ Trying: [1, 2, 3].remove(42) Expecting: Traceback (most recent call last): File "", line 1, in ? ValueError: list.remove(x): x not in list ok Trying: x = 12 Expecting: nothing ok Trying: x Expecting: 12 ok Trying: if x == 13: print "yes" else: print "no" print "NO" print "NO!!!" Expecting: no NO NO!!! ok Trying: if "yes" == \ "y" + \ "es": # in the source code you'll see the doubled backslashes print 'yes' Expecting: yes ok Trying: assert "Easy!" Expecting: nothing ok Trying: import math Expecting: nothing ok Trying: math.floor(1.9) Expecting: 1.0 ok 0 of 8 examples failed in doctest.__doc__ Running doctest.DocTestSuite.__doc__ 0 of 0 examples failed in doctest.DocTestSuite.__doc__ Running doctest.DocTestTestFailure.__doc__ 0 of 0 examples failed in doctest.DocTestTestFailure.__doc__ Running doctest.Tester.__doc__ Trying: from doctest import Tester Expecting: nothing ok Trying: t = Tester(globs={'x': 42}, verbose=0) Expecting: nothing ok Trying: t.runstring(r''' >>> x = x * 2 >>> print x 42 ''', 'XYZ') Expecting: ***************************************************************** Failure in example: print x from line #2 of XYZ Expected: 42 Got: 84 (1, 2) ok Trying: t.runstring(">>> x = x * 2\n>>> print x\n84\n", 'example2') Expecting: (0, 2) ok Trying: t.summarize() Expecting: ***************************************************************** 1 items had failures: 1 of 2 in XYZ ***Test Failed*** 1 failures. (1, 4) ok Trying: t.summarize(verbose=1) Expecting: 1 items passed all tests: 2 tests in example2 ***************************************************************** 1 items had failures: 1 of 2 in XYZ 4 tests in 2 items. 3 passed and 1 failed. ***Test Failed*** 1 failures. (1, 4) ok 0 of 6 examples failed in doctest.Tester.__doc__ Running doctest.Tester._Tester__record_outcome.__doc__ 0 of 0 examples failed in doctest.Tester._Tester__record_outcome.__doc__ Running doctest.Tester._Tester__runone.__doc__ 0 of 0 examples failed in doctest.Tester._Tester__runone.__doc__ Running doctest.Tester.__init__.__doc__ 0 of 0 examples failed in doctest.Tester.__init__.__doc__ Running doctest.Tester.merge.__doc__ Trying: from doctest import Tester Expecting: nothing ok Trying: t1 = Tester(globs={}, verbose=0) Expecting: nothing ok Trying: t1.runstring(''' >>> x = 12 >>> print x 12 ''', "t1example") Expecting: (0, 2) ok Trying: t2 = Tester(globs={}, verbose=0) Expecting: nothing ok Trying: t2.runstring(''' >>> x = 13 >>> print x 13 ''', "t2example") Expecting: (0, 2) ok Trying: common = ">>> assert 1 + 2 == 3\n" Expecting: nothing ok Trying: t1.runstring(common, "common") Expecting: (0, 1) ok Trying: t2.runstring(common, "common") Expecting: (0, 1) ok Trying: t1.merge(t2) Expecting: *** Tester.merge: 'common' in both testers; summing outcomes. ok Trying: t1.summarize(1) Expecting: 3 items passed all tests: 2 tests in common 2 tests in t1example 2 tests in t2example 6 tests in 3 items. 6 passed and 0 failed. Test passed. (0, 6) ok 0 of 10 examples failed in doctest.Tester.merge.__doc__ Running doctest.Tester.run__test__.__doc__ 0 of 0 examples failed in doctest.Tester.run__test__.__doc__ Running doctest.Tester.rundict.__doc__ Trying: import new Expecting: nothing ok Trying: m1 = new.module('_m1') Expecting: nothing ok Trying: m2 = new.module('_m2') Expecting: nothing ok Trying: test_data = """ def _f(): '''>>> assert 1 == 1 ''' def g(): '''>>> assert 2 != 1 ''' class H: '''>>> assert 2 > 1 ''' def bar(self): '''>>> assert 1 < 2 ''' """ Expecting: nothing ok Trying: exec test_data in m1.__dict__ Expecting: nothing ok Trying: exec test_data in m2.__dict__ Expecting: nothing ok Trying: m1.__dict__.update({"f2": m2._f, "g2": m2.g, "h2": m2.H}) Expecting: nothing ok Trying: t = Tester(globs={}, verbose=0, isprivate=is_private) Expecting: nothing ok Trying: t.rundict(m1.__dict__, "rundict_test", m1) # _f, f2 and g2 and h2 skipped Expecting: (0, 3) ok Trying: t = Tester(globs={}, verbose=0) Expecting: nothing ok Trying: t.rundict(m1.__dict__, "rundict_test_pvt", m1) # Only f2, g2 and h2 skipped Expecting: (0, 4) ok Trying: t = Tester(globs={}, verbose=0) Expecting: nothing ok Trying: t.rundict(m1.__dict__, "rundict_test_pvt") # None are skipped. Expecting: (0, 8) ok Trying: testmod(m1, isprivate=is_private) Expecting: (0, 3) ***************************************************************** Failure in example: testmod(m1, isprivate=is_private) from line #55 of doctest.Tester.rundict Expected: (0, 3) Got: Running _m1.__doc__ 0 of 0 examples failed in _m1.__doc__ Running _m1.H.__doc__ Trying: assert 2 > 1 Expecting: nothing ok 0 of 1 examples failed in _m1.H.__doc__ Running _m1.H.bar.__doc__ Trying: assert 1 < 2 Expecting: nothing ok 0 of 1 examples failed in _m1.H.bar.__doc__ Running _m1.g.__doc__ Trying: assert 2 != 1 Expecting: nothing ok 0 of 1 examples failed in _m1.g.__doc__ 1 items had no tests: _m1 3 items passed all tests: 1 tests in _m1.H 1 tests in _m1.H.bar 1 tests in _m1.g 3 tests in 4 items. 3 passed and 0 failed. Test passed. (0, 3) 1 of 14 examples failed in doctest.Tester.rundict.__doc__ Running doctest.Tester.rundoc.__doc__ Trying: t = Tester(globs={}, verbose=0) Expecting: nothing ok Trying: def _f(): '''Trivial docstring example. >>> assert 2 == 2 ''' return 32 Expecting: nothing ok Trying: t.rundoc(_f) # expect 0 failures in 1 example Expecting: (0, 1) ok 0 of 3 examples failed in doctest.Tester.rundoc.__doc__ Running doctest.Tester.runstring.__doc__ Trying: t = Tester(globs={}, verbose=1) Expecting: nothing ok Trying: test = r''' # just an example >>> x = 1 + 2 >>> x 3 ''' Expecting: nothing ok Trying: t.runstring(test, "Example") Expecting: Running string Example Trying: x = 1 + 2 Expecting: nothing ok Trying: x Expecting: 3 ok 0 of 2 examples failed in string Example (0, 2) ok 0 of 3 examples failed in doctest.Tester.runstring.__doc__ Running doctest.Tester.summarize.__doc__ 0 of 0 examples failed in doctest.Tester.summarize.__doc__ Running doctest._SpoofOut.__doc__ 0 of 0 examples failed in doctest._SpoofOut.__doc__ Running doctest._SpoofOut.__init__.__doc__ 0 of 0 examples failed in doctest._SpoofOut.__init__.__doc__ Running doctest._SpoofOut.clear.__doc__ 0 of 0 examples failed in doctest._SpoofOut.clear.__doc__ Running doctest._SpoofOut.flush.__doc__ 0 of 0 examples failed in doctest._SpoofOut.flush.__doc__ Running doctest._SpoofOut.get.__doc__ 0 of 0 examples failed in doctest._SpoofOut.get.__doc__ Running doctest._SpoofOut.write.__doc__ 0 of 0 examples failed in doctest._SpoofOut.write.__doc__ Running doctest._TestClass.__doc__ Trying: _TestClass(13).get() + _TestClass(-12).get() Expecting: 1 ok Trying: hex(_TestClass(13).square().get()) Expecting: '0xa9' ok 0 of 2 examples failed in doctest._TestClass.__doc__ Running doctest._TestClass.__init__.__doc__ Trying: t = _TestClass(123) Expecting: nothing ok Trying: print t.get() Expecting: 123 ok 0 of 2 examples failed in doctest._TestClass.__init__.__doc__ Running doctest._TestClass.get.__doc__ Trying: x = _TestClass(-42) Expecting: nothing ok Trying: print x.get() Expecting: -42 ok 0 of 2 examples failed in doctest._TestClass.get.__doc__ Running doctest._TestClass.square.__doc__ Trying: _TestClass(13).square().get() Expecting: 169 ok 0 of 1 examples failed in doctest._TestClass.square.__doc__ Running doctest._expect.__doc__ 0 of 0 examples failed in doctest._expect.__doc__ Running doctest._extract_doctests.__doc__ 0 of 0 examples failed in doctest._extract_doctests.__doc__ Running doctest._extract_examples.__doc__ 0 of 0 examples failed in doctest._extract_examples.__doc__ Running doctest._extract_future_flags.__doc__ 0 of 0 examples failed in doctest._extract_future_flags.__doc__ Running doctest._find_tests.__doc__ 0 of 0 examples failed in doctest._find_tests.__doc__ Running doctest._from_module.__doc__ 0 of 0 examples failed in doctest._from_module.__doc__ Running doctest._get_doctest.__doc__ 0 of 0 examples failed in doctest._get_doctest.__doc__ Running doctest._normalize_module.__doc__ 0 of 0 examples failed in doctest._normalize_module.__doc__ Running doctest._run_examples.__doc__ 0 of 0 examples failed in doctest._run_examples.__doc__ Running doctest._run_examples_inner.__doc__ 0 of 0 examples failed in doctest._run_examples_inner.__doc__ Running doctest._tag_out.__doc__ 0 of 0 examples failed in doctest._tag_out.__doc__ Running doctest._test.__doc__ 0 of 0 examples failed in doctest._test.__doc__ Running doctest._utest.__doc__ 0 of 0 examples failed in doctest._utest.__doc__ Running doctest.debug.__doc__ 0 of 0 examples failed in doctest.debug.__doc__ Running doctest.is_private.__doc__ Trying: is_private("a.b", "my_func") Expecting: False ok Trying: is_private("____", "_my_func") Expecting: True ok Trying: is_private("someclass", "__init__") Expecting: False ok Trying: is_private("sometypo", "__init_") Expecting: True ok Trying: is_private("x.y.z", "_") Expecting: True ok Trying: is_private("_x.y.z", "__") Expecting: False ok Trying: is_private("", "") # senseless but consistent Expecting: False ok 0 of 7 examples failed in doctest.is_private.__doc__ Running doctest.run_docstring_examples.__doc__ 0 of 0 examples failed in doctest.run_docstring_examples.__doc__ Running doctest.testmod.__doc__ 0 of 0 examples failed in doctest.testmod.__doc__ Running doctest.testsource.__doc__ 0 of 0 examples failed in doctest.testsource.__doc__ Running doctest.__test__._TestClass.__doc__ Trying: _TestClass(13).get() + _TestClass(-12).get() Expecting: 1 ok Trying: hex(_TestClass(13).square().get()) Expecting: '0xa9' ok 0 of 2 examples failed in doctest.__test__._TestClass.__doc__ Running doctest.__test__._TestClass.__init__.__doc__ Trying: t = _TestClass(123) Expecting: nothing ok Trying: print t.get() Expecting: 123 ok 0 of 2 examples failed in doctest.__test__._TestClass.__init__.__doc__ Running doctest.__test__._TestClass.get.__doc__ Trying: x = _TestClass(-42) Expecting: nothing ok Trying: print x.get() Expecting: -42 ok 0 of 2 examples failed in doctest.__test__._TestClass.get.__doc__ Running doctest.__test__._TestClass.square.__doc__ Trying: _TestClass(13).square().get() Expecting: 169 ok 0 of 1 examples failed in doctest.__test__._TestClass.square.__doc__ Running string doctest.__test__.bool-int equivalence Trying: 4 == 4 Expecting: 1 ok Trying: 4 == 4 Expecting: True ok Trying: 4 > 4 Expecting: 0 ok Trying: 4 > 4 Expecting: False ok 0 of 4 examples failed in string doctest.__test__.bool-int equivalence Running string doctest.__test__.string Trying: x = 1; y = 2 Expecting: nothing ok Trying: x + y, x * y Expecting: (3, 2) ok 0 of 2 examples failed in string doctest.__test__.string 30 items had no tests: doctest.DocTestSuite doctest.DocTestTestFailure doctest.Tester._Tester__record_outcome doctest.Tester._Tester__runone doctest.Tester.__init__ doctest.Tester.run__test__ doctest.Tester.summarize doctest._SpoofOut doctest._SpoofOut.__init__ doctest._SpoofOut.clear doctest._SpoofOut.flush doctest._SpoofOut.get doctest._SpoofOut.write doctest._expect doctest._extract_doctests doctest._extract_examples doctest._extract_future_flags doctest._find_tests doctest._from_module doctest._get_doctest doctest._normalize_module doctest._run_examples doctest._run_examples_inner doctest._tag_out doctest._test doctest._utest doctest.debug doctest.run_docstring_examples doctest.testmod doctest.testsource 16 items passed all tests: 8 tests in doctest 6 tests in doctest.Tester 10 tests in doctest.Tester.merge 3 tests in doctest.Tester.rundoc 3 tests in doctest.Tester.runstring 2 tests in doctest._TestClass 2 tests in doctest._TestClass.__init__ 2 tests in doctest._TestClass.get 1 tests in doctest._TestClass.square 2 tests in doctest.__test__._TestClass 2 tests in doctest.__test__._TestClass.__init__ 2 tests in doctest.__test__._TestClass.get 1 tests in doctest.__test__._TestClass.square 4 tests in doctest.__test__.bool-int equivalence 2 tests in doctest.__test__.string 7 tests in doctest.is_private ***************************************************************** 1 items had failures: 1 of 14 in doctest.Tester.rundict 71 tests in 47 items. 70 passed and 1 failed. ***Test Failed*** 1 failures. From BruceEckel at MailBlocks.com Thu Aug 5 23:33:45 2004 From: BruceEckel at MailBlocks.com (Bruce Eckel) Date: Thu, 5 Aug 2004 21:33:45 -0600 Subject: Proposed improved decorator syntax In-Reply-To: <1091753696.4112d6e06ea9e@webmail.oregonstate.edu> References: <1091753696.4112d6e06ea9e@webmail.oregonstate.edu> <1091564446.20040805213345@MailBlocks.com> Message-ID: Thursday, August 5, 2004, 6:54:56 PM, barnesc at engr.orst.edu wrote: > Recognize that we're *really* trying to create function metadata. A more > flexible solution is to make a metadata dictionary be part of function and > class definitions. Then 'decorator' simply becomes one name among many > different metadata names. I have to say I find this argument compelling. I can't say whether the syntax works well, but if the fundamental problem is metadata, then solving that in a way that solves all aspects of metadata is desireable. That said, I observe that this seems to be a fairly new topic for many, including myself; I have some grasp of Java's metadata facility and less of C#'s (although I understand C#'s to be more limiting than Java's) and I have not read anything terribly in-depth about either. It reminds me of my first exposure to C++ templates many years ago -- it seemed like there was a lot more to it than meets the eye, but it took me years to really start to grasp what it was about (by understanding latent typing via python). One thing that has come up in Java is that metadata has been suggested for use in implementing a version of aspect-oriented programming, another feature I've been struggling to understand. The one thing about aspects that has occurred to me is that macros seem to be trying to solve a similar problem (changing code behavior across the code base), as do metaclasses. Same problem, very different approaches and degrees of effectiveness. Things like the implementation of 'synchronized' is more aspecty than it is metadata; it is implementing behavior changes rather than just attaching information to something (the original intent of metadata; in Java you must generally write additional code in order to add behavior based on a metadata tag). I suppose the question, then, is this: what is the true intent of decorators? Is it for code behavior change, or metadata, or both? If it is for code behavior change, how do I hook into that with my own code; if I wanted to implement, for example, logging upon entry and exit of a method (the classic AOP example) or to begin and end a transaction upon entry and exit of a method? For that matter, should we limit the syntax of decorators to always being at the beginning of a method? True aspects allow you to put a cutpoint at any point in a method; perhaps decorators shouldn't be restricted (even if we choose not to implement these ideas right away). These issues are tricky but they could be very powerful. And this conversation is sounding an awfully lot like some of the language design stuff that happened in the C++ committee. Some members decried this, saying that the committee should only be codifying existing features, but I think it was very necessary for these things to be tried, even if they didn't always work out. And I think we may be at a point where only experimentation will tell us what works and where this thing needs to go. No one has enough experience with it -- although some might argue that this is the reason we shouldn't put it in at all, I think that it means we need to try something out and iterate as we learn. I don't know if "experimental features" have been put into the language before, ones that actually exist in a release but have warnings on them that say "things may change as we learn more." But if not, it seems like this might be the time to start. I think we need something to express metadata and/or code behavior change and/or whatever it is that we're really trying to do, but I don't think we'll figure out what that is until we have something to experiment with -- and change. Bruce Eckel From aleaxit at yahoo.com Thu Aug 26 09:40:37 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 15:40:37 +0200 Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> <1gj4fb5.607xsc51izh8N%aleaxit@yahoo.com> <7pjXc.209955$M95.182424@pd7tw1no> Message-ID: <1gj4tyc.1b7j7n11jb35swN%aleaxit@yahoo.com> Martin DeMello wrote: > Alex Martelli wrote: > > Not leaving stylistic choice (which would lead to more than one obvious > > way to do it) is quite consonant with the Zen of Python. Of course one > > can't always reach what's preferable, but "your main point" which is > > presumably meant as a criticism of this design choice comes across as > > praise: the design choice follows the overall design's philosophy. > > I still feel the the One Obvious Way should have been to return self... When you design your own language, you get to impose in it what's obvious to _you_ -- or go the Perl way and try to squeeze in as many different ways to do every single task as possible so everybody's happy except those who can't stand bloated languages (who'll stick with Python;-). > > Guido doesn't like method chaining, so he made a design choice that did > > not allow method chaining, and did not give several equally obvious ways > > But that's pretty hard to argue with :) Indeed, it's not meant to be arguable-with;-). Personally I like method chaining, but it's clearly not the Python way, and I appreciate consistency and simplicity more than I appreciate picking and choosing details of my preferred style. Alex From aaronwmail-usenet at yahoo.com Mon Aug 9 09:44:37 2004 From: aaronwmail-usenet at yahoo.com (Aaron Watters) Date: 9 Aug 2004 06:44:37 -0700 Subject: Importance of C# (was Re: IronPython-0.6 is now available!) References: <278de0e.0407281353.27b6a457@posting.google.com> <5dydnZSDZaARoZXcRVn-ug@powergate.ca> Message-ID: Alan Kennedy wrote in message news:... > ....IMHO, Microsoft have always been masters of the 80/20 rule: making it > very simple for users to do 80% of what they want, but leaving them > bending over backwards to do the last 20%. Practicality beats purity. > > http://management.about.com/cs/generalmanagement/a/Pareto081202.htm > > But I think MS have done a much better job with the .Net CLR ( == java > the virtual machine) and C# ( ~= java the programming language ). They > hired lots of clever people, asked them to come up with something > java-like, but (better|simpler). The result is, IMHO, quite nice: I > felt pretty at home writing C# pretty quickly, mostly because of my > java experience.... I felt at home right away primarily because of my Python experience. As an exercise I wrote a bplustree implementation http://bplusdotnet.sourceforge.net in C#/.NET and translated it to java and python later. The java port was the most irritating primarily because java methods cannot return more than one "new" value (a real pain in the ***). Another java irritant was having to declare all the possible exceptions for all methods (I punted -- everything "throws Exception"). The python port was a tad bit simpler than the C# -- primarily in the derived classes -- but the speed and safety advantages of type checking in C# were great advantages. One of the cooler other things in C# is structs -- which means that C# can really conveniently be used for high performance numerics, whereas java can't imo. Here's hoping mono continues to improve... -- Aaron Watters === nothing exceeds like excess. From rogerb at rogerbinns.com Mon Aug 16 01:48:26 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Sun, 15 Aug 2004 22:48:26 -0700 Subject: Python secure? References: Message-ID: M. Clift wrote: > My reason for choosing Python was one, that it is free, so if my > efforts amount to nothing I haven't wasted money, two, that it is > supposed to be an easy language when compared to some others and > three, that my application when finished, probably wouldn't sell for > that much and not in any great quantities for me to gamble spending > something like ?1000 on Visual C / ++ this that and the other or > whatever. A simpler answer for you: The less lines of code you write, the easier it is for someone to recover how it works and the equivalent of your source code. This is true no matter what language is used. The less lines of code you write, the less bugs there will be and the less places for bugs to hide. The less lines of code you write, the sooner you will finish. The less lines of code you have to write in order to achieve some functionality, the sooner you will be able to ship your program. The less lines of code you have, the easier it is to make major changes such as moving to another platform, using different toolkits, databases etc Python will result in you writing less lines of code. C++/C will result in you writing more. Java is another planet where the Eclipse editor helps by writing some of the code :-) Since you are not a programmer, here is some friendly advice: - The LEAST of your issues is going to be people recovering your code. You will have the biggest problems in actually getting something that works correctly, especially in the real world. Try writing down exactly how you will test your program first. Details like what the input and output data will look like, values that are out of bounds, whatever users paste in from the clipboard, someone typing rapid random junk, input data far larger than you anticipated etc. - Your first program ever will be junk. After a few years, and even possibly months you will look back at it an be amazed. It will also be one of the most valuable learning experiences :-) - Unless you have a perfect specification written down, your first version will tend to get things wrong, but help give you an idea of what your code should be doing. This is called prototyping and it is best to do it in a way that allows the easiest changes to explore new ideas and delete the old ones. I would advise you to write your first program in Python. Once you have something that you know works, can be tested and you completely understand the problem and solution (as well as programming :-) then decide what to write the "proper" version in since you will be in a better position to make value judgements. Roger From nicksjacobson at yahoo.com Tue Aug 31 15:54:05 2004 From: nicksjacobson at yahoo.com (Nick Jacobson) Date: 31 Aug 2004 12:54:05 -0700 Subject: Give * operator "deep copy" Message-ID: This question is with regard to the * operator as used for sequence concatenation. There's the well-known gotcha: a = [[1, 2]] b = a*3 b[0][0] = 4 print b Result: [[4, 2], [4, 2], [4, 2]] When you wanted: [[4, 2], [1, 2], [1, 2]] My question is, since b = a*3 is equivalent to b = a + a + a, why not use deep copies of a? That is, let b = a*3 be equivalent to: b = copy.deepcopy(a) + copy.deepcopy(a) + copy.deepcopy(a) It seems much more likely that someone would want to create copies of an item, rather than inserting the same item several times into the list. If this has been previously discussed/documented, please point me to where I can read about it. Thanks! --Nick From peter at engcorp.com Thu Aug 26 08:50:15 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 26 Aug 2004 08:50:15 -0400 Subject: building errors with py2exe In-Reply-To: References: Message-ID: <5K-dnXUDa4QVQbDcRVn-sQ@powergate.ca> Intaek LIM wrote: > once i executed main.exe under 'dist', the result was, > Traceback : > File "main.py", line 1, in ? > AttributeError: 'module' object has no attribute 'auth' What does that line of code look like? What happens when you run the program normally, without using py2exe? -Peter From balaji at email.arizona.edu Wed Aug 11 19:11:46 2004 From: balaji at email.arizona.edu (Balaji) Date: 11 Aug 2004 16:11:46 -0700 Subject: ImportError: dynamic module does not define init function(initmymodule) Message-ID: <494182a9.0408111511.687d6371@posting.google.com> I have an c++ header file. //some_class.h #ifndef _SOME_CLASS_H_ #define _SOME_CLASS_H_ class SomeClass { public: int sqr(int a); }; #endif //_SOME_CLASS_H_ and I have an definition file some_class.C //some_class.C #include "some_class.h" int SomeClass::sqr(int a){ return a*a; } And I have an interface file %module mytest %{ #include "some_class.h" } %include "some_class.h" My question is when I try to import mytest in python it does import it but I'm not able to access the SomeClass.. Can anyone help.. Balaji When I try to conver this into python module by using SWIG I manage to import From aleaxit at yahoo.com Fri Aug 27 13:18:16 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 27 Aug 2004 19:18:16 +0200 Subject: Proposal for removing self In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022E90@exchange.hqamor.amorhq.net> References: <3A81C87DC164034AA4E2DDFE11D258E3022E90@exchange.hqamor.amorhq.net> Message-ID: <15B211FE-F84D-11D8-8631-000A95EFAE9E@yahoo.com> On 2004 Aug 27, at 15:16, Robert Brewer wrote: ... > So are we, Alex. :) I, for one, am glad you're back! I always find your > commentary illuminating and engaging. Thanks! I appreciate your kudos. I'll steel myself to killfile the bad guys rather than wasting my time repeating all the usual arguments and ending up leaving c.l.py!-) Alex From brett at python.org Thu Aug 26 01:31:46 2004 From: brett at python.org (Brett C.) Date: 25 Aug 2004 22:31:46 -0700 Subject: Best processor (i386) for Python performance? In-Reply-To: <789f72ac.0408251950.e85d23e@posting.google.com> Message-ID: In terms of multithreading, an I/O intensive app that is threaded can make use of dual procs. Otherwise threaded apps can't for technical reasons (GIL and such but don't need to get into those details). From kirk at eyegor.jobsluder.net Wed Aug 11 16:02:04 2004 From: kirk at eyegor.jobsluder.net (Kirk Job-Sluder) Date: Wed, 11 Aug 2004 20:02:04 GMT Subject: Paul Graham on Python hackers References: <3064b51d.0408090448.31806af5@posting.google.com> <3064b51d.0408100556.1962ba58@posting.google.com> <1a517b5.0408101058.686544b1@posting.google.com> Message-ID: On 2004-08-10, Bryan Olson wrote: > beliavsky at aol.com wrote: >> I don't know enough about functional programming (FP) to argue. David >> Mertz wrote some articles on FP in Python -- see >> http://www-106.ibm.com/developerworks/library/l-prog.html . > > If you've never looked at a real FP language, I recommend it. > Mertz is trying to convey the flavor of functional programming > to people who know Python. He doesn't suggest writing non- > trivial programs that way. He notes at the end, "I've found it > much easier to get a grasp of functional programming in the > language Haskell than in Lisp/Scheme." Ohh, just for the sake of comparison, I spent about 5 hours yesterday digging around in Haskell, frequently described as one of the more pure functional languages. Wow. Now that is different. I don't know if I'll ever use it because much of what I do involves gluing other programs together and I couldn't get an external command working in Haskell. But very different. From schiffo2000 at yahoo.com Tue Aug 31 08:27:04 2004 From: schiffo2000 at yahoo.com (Barry Schiffman) Date: Tue, 31 Aug 2004 05:27:04 -0700 (PDT) Subject: bad bsddb key/values on large data Message-ID: <20040831122704.91351.qmail@web51401.mail.yahoo.com> --- Skip Montanaro wrote: > From: Skip Montanaro > Date: Mon, 30 Aug 2004 21:45:28 -0500 > To: Barry Schiffman > CC: python-list at python.org > Subject: Re: bad bsddb key/values on large data > > > Barry> The largest one, about 200 megs, is > written, and can be read, and > Barry> the strings are correctly formatted -- > but the values attached to > Barry> the keys are wrong ... > > ... > > Barry> Can anyone tell me if there is such a > Python problem or a bsddb > Barry> problem? > > You didn't say what versions of Berkeley DB or > Python you are using. If you > are using Berkeley DB 1.85, problems are to be > expected. Upgrade to a later > version. > > Skip > My apologies, but I wrote this too soon. The chief suspect is an interaction between one of the hash keys and my code. The entire table is shifted ahead on the very first key, so the value for key_1 is saved under key_2, and then so and so forth. The shift stays constant at one step (so key_n contains the record for key_n-1). This only happens with one of the three files. In fact, the code is supposed to reject many of the records in the input, and does so without messing up the key/value pairs -- except for this one. However, I won't be able to check this out until tonight. Anyway, I think the versions are OK (though I'm not sure if the Sleepcat versions are the same as the Berkeley versions). I tried this twice under these setups Python 2.2.2, Sleepycat 3.3.11 on a PC with RH 7.3 Python 2.3.2, Sleepycat 3.2.9 on a PPC with YDL 2.3 Thanks much. Barry __________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - 100MB free storage! http://promotions.yahoo.com/new_mail From simonb at NOTTHISBIT.webone.com.au Fri Aug 27 05:21:50 2004 From: simonb at NOTTHISBIT.webone.com.au (Simon Burton) Date: Fri, 27 Aug 2004 10:21:50 +0100 Subject: 3D geometry module? References: <412e0951$0$6157$db0fefd9@news.zen.co.uk> Message-ID: On Thu, 26 Aug 2004 17:01:20 +0100, Will McGugan wrote: > Hi, > > Is there a general purpose 3D geometry module for Python? I would like to > be able to read / write 3D models and perform per vertex / per face > operations on them. > > Failing that, are there vector / matrix / quaternion classes I can make > use of? > cgkit has 3d/4d matrix/vector classes.. and it's fast, if you need that. Simon. From ialbert at mailblocks.com Tue Aug 17 18:20:24 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Tue, 17 Aug 2004 18:20:24 -0400 Subject: Databases: Getting values by column name In-Reply-To: References: Message-ID: Robert Ferber wrote: > I already know the stuff on that page, it's really slowing you down :-( Your response to Skip Montaro's post demonstrates that you zipped trough it without paying much attention to what he said, so I think slowing a bit down would actually help you here. As other pointed out you have everything you need, using dtuple.py at: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81252 or db_row at: http://opensource.theopalgroup.com/ Istvan. From evan at 4-am.com Mon Aug 23 13:54:33 2004 From: evan at 4-am.com (Evan Simpson) Date: Mon, 23 Aug 2004 12:54:33 -0500 Subject: J2 proposal: keyword In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022E26@exchange.hqamor.amorhq.net> References: <3A81C87DC164034AA4E2DDFE11D258E3022E26@exchange.hqamor.amorhq.net> Message-ID: Robert Brewer wrote: > III. Choosing a keyword Useless aside: If I had access to Guido's time machine, I would go back to the beginning of Python and brainwash Guido into prefixing all keywords-that-introduce-statements with the '@' character. Adding a new statement keyword would then be easy-peasy, Leo would have chosen a different character, and Python programs would all look like this: @using my_decorator @def f(x): @if you_think_this_is_ugly or is_silly: @print "I agree with you" Thank goodness I don't have access to it. Cheers, Evan @ 4-am From 5100-46470588-0001 at t-online.de Wed Aug 18 04:34:20 2004 From: 5100-46470588-0001 at t-online.de (5100-46470588-0001 at t-online.de) Date: 18 Aug 2004 10:34:20 +0200 Subject: favorite python web development tool? References: <10i4nttktcvltdd@corp.supernews.com> Message-ID: <87d61o26b7.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> mike writes: > > i'm fairly new to python, coming from a java servlet / velocity > template background. i'm looking for a good python web development > tool, and hope to find some suggestions here. ZOPE Klaus Schilling From mlh at eik.idi.ntnu.no Mon Aug 23 20:48:11 2004 From: mlh at eik.idi.ntnu.no (Magnus Lie Hetland) Date: Tue, 24 Aug 2004 00:48:11 GMT Subject: Debunking Art - fraudster with python AI engine? References: <4128f60b$1@news.unimelb.edu.au> Message-ID: <412a9047$1@news.unimelb.edu.au> In article <4128f60b$1 at news.unimelb.edu.au>, Nick wrote: >Hi, > >I recently went to an art exhibition, and one of the artists had an AI >engine projected onto a screen with a keyboard for visitors to type >questions in with. [snip] Are you sure it wasn't connected to a network (perhaps well hidden)? In that case the "AI engine" could just be another person sitting somewhere, snickering... (Turing test, anyone?) :) -- Magnus Lie Hetland "Canned Bread: The greatest thing since sliced http://hetland.org bread!" [from a can in Spongebob Squarepants] [ 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 rnichol_rrc at yahoo.com Mon Aug 9 14:00:58 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Mon, 09 Aug 2004 13:00:58 -0500 Subject: Mechwarrior Python Game In-Reply-To: References: Message-ID: <_YORc.1718$bJ2.10708@news1.mts.net> Jared wrote: > Has anybody played the Mechwarrior Miniatures game? I'm trying to > represent the game in python. First thing I need to do is make a > playing field. Mechs will move on the playing field based on inches > to scale in any direction. Any ideas? You could check out MegaMek (http://sourceforge.net/projects/megamek/) for some ideas (it's written in java, but the games are similar enough). A lot of people use PyGame (http://www.pygame.org/) for games. So, there might be a project already there that souce can help you. I know there is some games that use hex maps on the project page. Hope that helps. From ramen at lackingtalent.com Sun Aug 8 14:01:29 2004 From: ramen at lackingtalent.com (Dave Benjamin) Date: Sun, 08 Aug 2004 18:01:29 -0000 Subject: JPEG2000 support? References: <54ubt1-nrn.ln1@lairds.us> Message-ID: In article , Christopher T King wrote: > On Sun, 25 Jul 2004, Kyler Laird wrote: > >> I'm getting ready to build an application around a big JPEG2000 >> image but I haven't found any Python support for JPEG2000. >> >> I plan to just use an external call to JasPer to handle the >> conversion for now but I'd prefer to have a better integrated >> solution. Are any Python libraries likely to have support for >> it soon? My searches are yielding surprisingly little. > > PyMagick is a Python interface to the powerful, cross-platform ImageMagick > graphics package, which supports JPEG2000 through an external library. > So unlike something like PIL, you'd also need to install ImageMagick > (compiled with JPEG2000 support) and a JPEG2000 library, but it seems to > be very well integrated with Python, PIL, and numeric. Which PyMagick are you referring to? This one: http://starship.python.net/crew/zack/pymagick/ Or this one: http://pythonmagick.procoders.net/ Pros/cons of each? I've used the one at procoders, but I had problems with it conflicting with my standalone ImageMagick DLLs (on Windows, of course). I'm also a bit confused as to the real and practical difference between "ImageMagick" and "GraphicsMagick". Thanks, Dave -- .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:. "talking about music is like dancing about architecture." From ian at cottee.org Sat Aug 21 04:59:41 2004 From: ian at cottee.org (Ian J Cottee) Date: Sat, 21 Aug 2004 17:59:41 +0900 Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: Reid Nichol wrote: > Gerrit Muller wrote: > >> Roel Schroeven wrote: >> >>> Roel Schroeven wrote: >>> >>>> I spotted some errors in your list, added new entries, and made a >>>> histogram: http://roelschroeven.net/pythonages/ >>> >>> >>> >> Very cool. It might be good idea to add a date and time at the top, >> since new datapoint keep coming in? > > How about labels for the axes as well. > > >> and then a quantum leap towards Python. > > You're aware that a quantum leap means a extremely small leap, right? http://dictionary.reference.com/search?q=quantum%20leap A dramatic advance, especially in knowledge or method, as in Establishing a central bank represents a quantum leap in this small country's development. This term originated as quantum jump in the mid-1900s in physics, where it denotes a sudden change from one energy state to another within an atom. Within a decade it was transferred to other advances, not necessarily sudden but very important ones. Ian From greg at cosc.canterbury.ac.nz Mon Aug 2 01:11:32 2004 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Mon, 02 Aug 2004 17:11:32 +1200 Subject: (patch for Bash) try-block and exception In-Reply-To: <2n27jlFsb5njU1@uni-berlin.de> References: <2n27jlFsb5njU1@uni-berlin.de> Message-ID: <2n60o4Frnmp4U1@uni-berlin.de> William Park wrote: > try > echo a > raise 2 > echo b > done in > 0) echo okey ;; > 1) echo raised 1 ;; > 2) echo raised 2 ;; > *) echo really bad ;; > esac try...done...esac? What a delightfully eclectic combination of syntax. :-) Why doesn't it end with 'yrt'? -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From reinhold-birkenfeld-nospam at wolke7.net Thu Aug 12 16:42:49 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Thu, 12 Aug 2004 22:42:49 +0200 Subject: Decorator "platform" In-Reply-To: <87zn50nll4.fsf@pobox.com> References: <2nsoofF49frcU1@uni-berlin.de> <87zn50nll4.fsf@pobox.com> Message-ID: <2o22htF65snnU10@uni-berlin.de> John J. Lee wrote: > Reinhold Birkenfeld writes: > [...] >> What I have in mind is a sort of "decorator library" where everyone who >> has written a useful function of that kind can share it with others, > [...] > > God help us. <0.5 wink> God IS helping us, or we wouldn't use Python. Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From richardjones at optushome.com.au Wed Aug 4 17:50:23 2004 From: richardjones at optushome.com.au (richard) Date: Thu, 05 Aug 2004 07:50:23 +1000 Subject: Perl's Crypt::PasswdMD5 References: Message-ID: <41115a1f$0$15279$afc38c87@news.optusnet.com.au> Bart Nessux wrote: > Nicolas ?vrard wrote: >> * Bart Nessux [15:39 04/08/04 CEST]: >> >>> Does Python have anything similar to Perl's Crypt::PasswdMD5??? >>> >>> I read about the crypt module... but it only does DES. Any plans to >>> add md5 or other digests to it in the future? >> >> >> http://www.python.org/doc/current/lib/module-md5.html >> >> Try to be lucky with google using this search string : "python md5" > > That's not comparable to Crypt::PasswdMD5 Assume that we're not Perl programmers. Richard From anthonybaxter at gmail.com Fri Aug 27 13:40:28 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 28 Aug 2004 03:40:28 +1000 Subject: would be nice: import from archive In-Reply-To: <9%JXc.79851$pTn.63106@news01.bloor.is.net.cable.rogers.com> References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <9%JXc.79851$pTn.63106@news01.bloor.is.net.cable.rogers.com> Message-ID: On Fri, 27 Aug 2004 17:15:49 GMT, Dan Perl wrote: > My bad. Right after posting the message I found the 'Index of Python > Enhancement Proposals (PEPs)' > and there is PEP 273, 'Import Modules from Zip Archives', submitted by > James C. Ahlstrom. Thank you, Jim! And there are even two implementations > already. Note that the PEP is not up-to-date. zipimport "just works" in Python 2.3 and Python 2.4. In the following example, we use the -v flag to show where imports are coming from. bonanza% cat hello.py def hello(): print 'hello world' bonanza% zip hello.zip hello.py adding: hello.py (deflated 8%) bonanza% rm hello.py bonanza% python2.4 -v Python 2.4a2 (#3, Aug 24 2004, 01:25:51) [GCC 3.4.0 20040613 (Red Hat Linux 3.4.0-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. ... lots and lots of lines showing default imports snipped ... >>> import hello Traceback (most recent call last): File "", line 1, in ? ImportError: No module named hello >>> import sys >>> sys.path.append('hello.zip') >>> import hello # zipimport: found 1 names in hello.zip dlopen("/usr/local/lib/python2.4/lib-dynload/zlib.so", 2); import zlib # dynamically loaded from /usr/local/lib/python2.4/lib-dynload/zlib.so # zipimport: zlib available import hello # loaded from Zip hello.zip/hello.py >>> hello.hello() hello world At least on this box (linux) there's even a zip file on the default sys.path! Anthony From pythongnome at hotmail.com Wed Aug 18 19:57:19 2004 From: pythongnome at hotmail.com (Lucas Raab) Date: Wed, 18 Aug 2004 23:57:19 GMT Subject: age of Python programmers References: Message-ID: Quite a few of Python's community member's is 45+. That sort of surprised me. But don't get the impression that I thought everybody here was in their 20's and 30's. "Ville Vainio" wrote in message news:du7wtzwfb8b.fsf at lehtori.cc.tut.fi... > 27 years, 4 of them with awareness of how much the other languages I > have/had to work with suck. > > BTW, even though usenet might not really scale all that well for this > kind of thread, it's been delightful to see how so many are still > actively hacking at a respectable age. It really sets an example for > us younger ones, some of whom are possibly worried about how to > preserve the energy level of youth and whether they can still hack it > when they "grow up". > > I'm also optimistic about retiring with Python, because *everyone* is > going to retire with Python in 2044 :-). > > -- > Ville Vainio http://tinyurl.com/2prnb From porky_pig_jr at my-deja.com Wed Aug 18 20:08:59 2004 From: porky_pig_jr at my-deja.com (Porky Pig Jr) Date: 18 Aug 2004 17:08:59 -0700 Subject: IDLE under Cygwin doesn't show toolbar menu Message-ID: <56cfb0e3.0408181608.25371f2a@posting.google.com> Just downloaded and installed the latest Cygwin distribution which includes python 2.3.4. IDLE runs fine but for some reason the toolbar menu doesn't show up. Like, by default, it starts shell window, but no toolbar. If I type idle foobar.py it brings both shell and editor windows, but once again, no toolbar on either window -- which renders the edtior quite disfunctional. Just want to check if anyone else ever ran into this problem and what was the workaround -- before I contact Cygwin folks. TIA. From __peter__ at web.de Wed Aug 11 05:53:21 2004 From: __peter__ at web.de (Peter Otten) Date: Wed, 11 Aug 2004 11:53:21 +0200 Subject: how to dispatch objects depending on their class References: <4118dd4a$1@maser.urz.unibas.ch> <4119d60b@maser.urz.unibas.ch> Message-ID: Curzio Basso wrote: > Peter Otten wrote: > >> func_dict = {A: do_something_with_A, >> B: do_something_with_B} >> def func(obj): >> func_dict[obj.__class__](obj) > > ok. it tested and it works. thanks. > > now I have only to check if the Visitor Pattern is not more appropriate. I'd say the choice of the dispatch mechanism - dictionary lookup vs Duncan Booth's name-mangling - is independent of the question whether the visitor pattern applies. Duncan's setup would then become something like class VisitorMixin: def accept(self, visitor): visitor.dispatch[self.__class__](self) class Visitor: def __init__(self): self.dispatch = {A: self.visit_A, B: self.visit_B} def visit_A(self, a): pass def visit_B(self, b): pass Peter From paul at subsignal.org Mon Aug 23 05:42:33 2004 From: paul at subsignal.org (paul k) Date: Mon, 23 Aug 2004 11:42:33 +0200 Subject: python doesn't like my numbers In-Reply-To: References: <2osfspFdnjbcU1@uni-berlin.de> Message-ID: <2otsg8Fe7eo2U1@uni-berlin.de> Alan Kennedy wrote: > [paul k] > Answer 1: Use strings: that's really what telephone numbers should be Yea, should have done this in the first place... > > Answer 2: Use valid octal digits in your phone numbers. The digit '8' > cannot appear in base 8 numbers, only the digits 0-7. I can't change reality (yet) ;) thanks for all your comments Paul From mahesh at privacy.net Sun Aug 29 19:09:44 2004 From: mahesh at privacy.net (Mahesh Padmanabhan) Date: Sun, 29 Aug 2004 17:09:44 -0600 Subject: Generator expressions v/s list comprehensions References: <1gj8y77.6qshr41q531veN%aleaxit@yahoo.com> <87llfywooz.fsf@sinken.local.csis.hku.hk> Message-ID: In article <87llfywooz.fsf at sinken.local.csis.hku.hk>, Isaac To wrote: [snip] Thanks Isaac for providing such a detailed explanation. I understand now why generator expressions make more sense. I just wish that generator expressions had been designed into the language without going the way of list comprehension -> generator expressions. From cjw at sympatico.ca Sat Aug 21 22:08:02 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Sat, 21 Aug 2004 22:08:02 -0400 Subject: J2 decorator grammar In-Reply-To: References: Message-ID: <2eTVc.41891$Tr.2137366@news20.bellglobal.com> Michael Sparks wrote: > On Fri, 20 Aug 2004, Robert Brewer wrote: > ... > >>Did you ever fix the scope issue? > > > I've fixed the scoping issue. > > I'll clean up the changes I made to get a minimal patch against 2.4a2, and > then put it somewhere handy. Now that I've got a much clearer idea of how > the python source tree hangs together adding in the short form should be > relatively simple. > > The current patch uses "decorate" as the keyword. Changing that of course > is utterly trivial - it's also something I think *should* be changed. > > The reason for suggesting this change is for one simple reason - python > makes often use of the idiom "decorate-dosomething-undecorate" - eg in > sorting. Using decorate would probably clash heavily with people's code. > > The closest word that strikes me that has a similar meaning to > decorate, using and applying would be "decorating". If anyone has > a closer suggestion to a short single word meaning "decorate using", > it'd be great. Since the action on the function (or [perhaps class) is transformative rather than decorative, would transform be a more appropriate word? > Colin W. > >>Might it have something to do with: >>static void >>symtable_node(struct symtable *st, node *n) >>{ > > > It certainly did! Your suggested change was necessary, however it was > incomplete - the child to traverse also needed changing. (I really > should've thought of that sooner - of course it's no longer zero! :) > > ie this > >> symtable_node(st, CHILD(n, 0)); > > Becomes: > >> symtable_node(st, CHILD(n, 4)); > > > So THANK YOU for pointing out this part of the code :) > > Currently I have a file that looks like this, which is completely legal, > and does what you would expect for this syntax: > ---- > def memoise(f): > return f > > class Foo: > decorate: > staticmethod > def Hoo(who): > print "You", who > if 1: > decorate: > memoise > def Print(what): > print "Ya", what > > Print(who) > > Foo.Hoo("HOO!") > ---- > > No matter what syntax we end up with, all of these syntactic sugar changes > rely on the original decorator code, and I've been very pleasantly > suprised at just how clean (and well documented) the python source is for > a project of it's size. > > As I say I'll post the cleaned up patch later. > > Regards, > > > Michael. > > From twanger at bluetwanger.de Tue Aug 10 07:37:52 2004 From: twanger at bluetwanger.de (Markus Bertheau) Date: Tue, 10 Aug 2004 13:37:52 +0200 Subject: Multiple inheritance with a common base class Message-ID: <1092137872.2624.16.camel@dicaprio.akademie1.de> Hi, I don't quite get the paragraph in the docs about this. Here it is: "A well-known problem with multiple inheritance is a class derived from two classes that happen to have a common base class. While it is easy enough to figure out what happens in this case (the instance will have a single copy of ``instance variables'' or data attributes used by the common base class), it is not clear that these semantics are in any way useful." If it's so easy to figure out, what is a problem then? And what should the comment about usefulness suggest? Thanks -- Markus Bertheau From bitshadow at yahoo.com Thu Aug 12 20:05:34 2004 From: bitshadow at yahoo.com (Michael Scarlett) Date: 12 Aug 2004 17:05:34 -0700 Subject: Why I love python. Message-ID: There is an amazing article by paul graham about python, and an even better discussion about it on slashdot. The reason I point this out, is the more I read both articles, the more I realised how we would be mutilating the language with that god forsaken @ decorator. I don't know about the rest of you, but I learned python and fell in love with its syntax and simplicity. Python - just works. So please GVR. Don't complicate it. Leave it as is. Work on making it faster, not uglier. Work on - in some cases - better algorithms for certain modules, not for it to even closely resemble C or perl or god knows whateverotherlanguagethereisoutthere. Am i the only one with a visceral reaction to this thing??? paul Graham article: http://www.paulgraham.com/pypar.html Slashdot discussion: http://developers.slashdot.org/developers/04/08/12/1721239.shtml?tid=156&tid=218 From fuzzyman at gmail.com Tue Aug 24 07:37:14 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 24 Aug 2004 04:37:14 -0700 Subject: XMLObject - problem with recursive definitions References: <6f402501.0408222323.5fd81b2a@posting.google.com> Message-ID: <6f402501.0408240337.7a88e5d@posting.google.com> rzed wrote in message [snip..] > > > > > > > > > > ... but this was based on the latest XMLObject. Maybe it's been > patched in response to your message? Yeah - the new release 0.1.2 corrects the problem. It's the first XML library I've used. I'm using it for both reading and writing data structures as XML rather than a general XML parser...... but it's very easy to use. Regards, Fuzzy http://www.voidspace.org.uk/atlantibots/pythonutils.html From michele.simionato at gmail.com Tue Aug 10 10:07:04 2004 From: michele.simionato at gmail.com (Michele Simionato) Date: 10 Aug 2004 07:07:04 -0700 Subject: Importance of C# (was Re: IronPython-0.6 is now available!) References: <278de0e.0407281353.27b6a457@posting.google.com> <5dydnZSDZaARoZXcRVn-ug@powergate.ca> <1n5z28erh2m3u.dlg@baczek.net.invalid> <537ea4cd.0408070757.14790cfe@posting.google.com> <41155c78$0$4348$626a14ce@news.free.fr> <144d0df.0408092156.1455f2af@posting.google.com> <1o2ouxh30essi.1eewz4ary5xj3.dlg@40tude.net> Message-ID: <4edc17eb.0408100607.d620f9b@posting.google.com> Lawrence Oluyede wrote in message news:<1o2ouxh30essi.1eewz4ary5xj3.dlg at 40tude.net>... > In data 9 Aug 2004 22:56:55 -0700, grv575 ha scritto: > > > Really MI > > causes more issues and confusion than it solves. > > Do you know about Python new style classes and MRO? Even knowing about the MRO MI can be painful. Actually, after fighting with MI in Zope I am starting to hate it ... :-( Michele Simionato From chris.cavalaria at free.fr Fri Aug 20 20:26:42 2004 From: chris.cavalaria at free.fr (Christophe Cavalaria) Date: Sat, 21 Aug 2004 02:26:42 +0200 Subject: decorator J4 - any objections? References: Message-ID: <412696c2$0$22032$626a14ce@news.free.fr> Larry Bates wrote: > If docstring can be a special case of a triple quoted > string, I don't see why decorators couldn't be a special > case of a dictionary. > > def func(arg1, arg2): > {'version': 'Added in 2.4', > 'returns': None, > 'docstring': 'Docstring could be here, or in decorator part above'} > """Docstring could be here, or in decorator part above""" > > or perhaps: > > > def func(arg1, arg2): > # > # Similiar to class __dict__ > # > __decorators__=__{'version': 'Added in 2.4', > 'returns': None, > 'docstring': 'Docstring could be here, or in > decorator > part above'} > """Docstring could be here, or in decorator part above""" > > > I'm sure there is a reason, but it would seem to make > "Python"-sense to me. It would then be very extensible > for the meta-data that everyone seems to also want decorators > to support. Maybe because decorators aren't just function properties but functions that transform the function they receive in parameter. Therefore, that proposal doesn't solve the problem at hand. It's a bad solution. How would you do the staticmethod ou the memoize with that proposal ? From ptmcg at austin.rr._bogus_.com Fri Aug 13 09:14:20 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 13 Aug 2004 13:14:20 GMT Subject: Python and Weather.com References: <6491b0ab.0408121917.5103b770@posting.google.com> Message-ID: "Fazer" wrote in message news:6491b0ab.0408121917.5103b770 at posting.google.com... > Hello, > > I made a small python script that gives the current weather conditions > of a city that you give as an argument. Here's the basic function > behind it: > > I am really a beginnering when it comes to parsing XML but I just used > split to get the values I wanted. Any ideas how I can use proper XML > parsing techniques? > > Also, the weather degree is in celcius but I conver it to fahrenheit > as well. :-) > > Here's the code: > > # Get the weather for the city specified > def get_weather(city): > #city = city.replace(" ", "%20") > w = urllib.urlopen("http://xoap.weather.com/search/search?where=%s" % > city.replace(" ", "%20")).read() > # Check if there were matches > if not city.isalpha() or w.find("loc") < 0: > return "No matches found for city of " + city + "!" > > # If so, use the first search result and use it > city = w.split("", 1)[0].split("")[1] > # Get location id of the first city > locid = w.split("", 1)[0].split(" # Get weather readings > weather = urllib.urlopen("http://xoap.weather.com/weather/local/%s?cc=*&prod=xoap&par= xxx&key=xxx&unit=m" > % > locid).read() > # Get conditions > reading = weather.split("")[0].split("")[1] > # Get temperature > temp = weather.split("")[0].split("")[1] > if "N/A" in temp: > return "Error" > else: > temp = int(temp) > > return "Weather for %s is %s C / %s F and %s" % (city,temp,(temp * > 1.8) + 32,reading) > > > Hope it helps anyone out there. Please feel free to fix anything I > may have done wrong. Comments greatly appreciated! > > Thanks, > > Faizan S. Since you asked about other approaches to parsing, here is a pyparsing rendition of something very similar. I find it a little easier to follow (and update later) than code with many splits and index references with special number offsets. The pyparsing package includes a few other similar examples, such as one which extracts a list of NTP servers from NIST's web site. Download pyparsing at http://pyparsing.sourceforge.net . -- Paul ---------------------------- # getTemp.py # # Demonstration of the pyparsing module, doing a simple pattern match # from an HTML page retrieved using urllib # # Copyright 2004, by Paul McGuire # from pyparsing import Word, Literal, nums import urllib city = "Austin, TX" # define pattern to match within the HTML # temperature is given in a string of the form: #

    67°F
    (19°C) # we want to locate this string within the page, and extract # the values 67 and 19 makeInt = lambda s,l,t: int(t[0]) integer = Word(nums).setParseAction( makeInt ) currentTempPattern = \ "

    " + \ integer.setResultsName("F") + "°F
    (" + \ integer.setResultsName("C") + "°C)" # get current weather for given zip code noaaURL = "http://www.srh.noaa.gov/zipcity.php?inputstring=%s" % urllib.quote(city) weatherPage = urllib.urlopen( noaaURL ) weatherReport = weatherPage.read() weatherPage.close() # now use scanString to return a generator of matching patterns, and # invoke next() to get the first (and expected to be only) matching string try: temps,startloc,endloc = currentTempPattern.scanString( weatherReport ).next() except StopIteration: print "Could not extract temperature data from", noaaURL else: print "Current temp at %s is %d\xb0F (%d\xb0C)" % \ ( city, temps.F, temps.C ) ----------------------------------- Output (this morning): Current temp at Austin, TX is 66?F (19?C) From anthonybaxter at gmail.com Sun Aug 8 21:46:54 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Mon, 9 Aug 2004 11:46:54 +1000 Subject: PEP-0318 In-Reply-To: References: <41122FC2.1080608@interlink.com.au> <4114152f@nntp.zianet.com> <4116bc20$1@nntp.zianet.com> Message-ID: On Sun, 08 Aug 2004 21:39:05 -0400, Roy Smith wrote: > In article , > Anthony Baxter wrote: > > > def doc(docstring): > > def add_doc_string(func, docstring=docstring): > > func.__doc__ = docstring > > return func > > return add_doc_string > > I don't understand the "docstring=docstring" in the argument list for > add_doc_string. I suspect there's something subtle going on with scope > rules, but I don't see it. Oops, habit, from before Python had nested scopes. You don't need it these days. From mark_bottjer at hotmail.com Fri Aug 6 17:13:26 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Fri, 06 Aug 2004 17:13:26 -0400 Subject: @decorators In-Reply-To: <10h7qlg5adbfj86@news.supernews.com> References: <10h73e5kh1et536@news.supernews.com> <4113e5be@nntp.zianet.com> <10h7qlg5adbfj86@news.supernews.com> Message-ID: <4113f477$1@nntp.zianet.com> John Roth wrote: > Since I wrote that, I managed to read the new, improved > and rewritten PEP, and discovered that the new syntax > doesn't allow parameters. Sigh. My knowledge is SO last night... > So it can't be used as a replacement > for the property() built-in function, and it therefore also can't > be used for the DBC functionality. As delivered, it's strictly > a replacement for the classmethod and staticmethod > builtin functions (and any other module or builtins that > take one parameter, of course.) Right. But people are still chasing after parameterized decorators, which is why I included the example. Personally, I think that we will never have a "one size fits all" solution here, other than the one we *already* have. When doing something truly unusual, I see nothing wrong with using the existing (foo = bar(foo, baz)) syntax to do it. Syntactic sugar is about making common cases easier, not about providing everything for everyone. > Guido's stated reasoning was that he had "a bad feeling" > about allowing more general expressions. So do I. > From what people are saying that's substantive (rather > than syntactic) I think that there are a number of very > different desires on the table, and it's not at all clear > either what they are or how they combine. Agreed. Along the same lines, I read a post elsewhere which reminded us that we can always *relax* the restrictions later, once we understand what we actually want. Sage advise. > He's been through it before. Remember PEP 308? I try not to... :) -- Mark From Kyler at news.Lairds.org Thu Aug 19 23:09:10 2004 From: Kyler at news.Lairds.org (Kyler Laird) Date: Fri, 20 Aug 2004 03:09:10 GMT Subject: Merging pdf documents with Python References: Message-ID: <805gv1-cq1.ln1@lairds.us> "Daryl Middleton" writes: >Can python be used to merge pdf documents into a single pdf file so that I >do not have to manually insert each one. Thanks I was using a free version of PageCatcher (ReportLab) for awhile (after using PJscript and Ghostscript). My projects manipulate PDF submitted by hundreds of people so any incompatibility is likely to be a problem. ReportLab couldn't handle everything we got last year so I started searching again. I ended up with iText. http://itext.sourceforge.net/ It has been very solid. There was a problem once but it was quickly fixed. http://groups.google.com/groups?q=itext+kyler&hl=en&lr=&ie=UTF-8&selm=v8vqk1-0k5.ln1%40snout.lairds.org&rnum=3 I usually hate using Java but I don't mind using iText through Jython. When I use it from Zope I use os.system like this. command = 'java -cp /var/lib/zope/instance/default/Extensions/itext-paulo-130.jar com.lowagie.tools.concat_pdf ' + string.join(piece_names) + ' ' + result_name I'm quite happy with iText. I like that it's Free and well- maintained. Being usable from Jython is a real bonus. --kyler From alikakakhel3 at hotmail.com Tue Aug 17 20:32:20 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 17 Aug 2004 17:32:20 -0700 Subject: what wrong with this program? Message-ID: <8f17f4bc.0408171632.787eb6f8@posting.google.com> The following program is supposed to display a dropdown menu, however, it only shows the File and Help things. from Tkinter import * root = Tk() #create menu m = Menu(root) root.config(menu=m) filemenu = Menu(m) m.add_cascade(label="File", menu="filemenu") filemenu.add_command(label="New", command=callback) filemenu.add_separator() filemenu.add_command(label="Quit", command=callback) helpmenu = Menu(m) m.add_cascade(label="Help", menu="helpmenu") helpmenu.add_command(label="About...", command=callback) root.mainloop() please help fix this program. From pm_mon at yahoo.com Sat Aug 14 18:16:00 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sat, 14 Aug 2004 18:16:00 -0400 Subject: Decorators: an outsider's perspective In-Reply-To: <56cfb0e3.0408141404.1d0057b8@posting.google.com> References: <9ADC3170-EDAF-11D8-9F63-000A95B336F2@snowtide.com> <56cfb0e3.0408141404.1d0057b8@posting.google.com> Message-ID: Porky Pig Jr wrote: > Paul Morrow wrote in message > class Foo: > >> def blah(a, b): # this is clearly a static method >> pass >> >> def blah(self, a, b): # this is clearly an instance method >> pass >> >> def blah(klass, a, b): # this is clearly a class method >> pass >> >>Python was built (successfully) on the assumption that obvious >>interpretations of the code obviate the need for declarations. Why >>wouldn't we continue with that mindset? >> >>Paul > > > I don't think it's a good example. 'self' is a convention, not the > reserved word. Nothing can prevent anyone from using some other word. > Strictly speaking, the fact that the first parameter is called 'self' > does not imply anything. Ditto for 'klass' (or rather 'cls' which is > used by the number of references). Again, it's not a reserved word. > What if I've decided to use parameter name 'cls' in static function? > What if I've decided to use 'this' instead of 'self'? So - either we > need some mechanism to enforce the keywords 'self', 'cls', or -- we > back to square one: we need decorators. Not for this kind of thing we don't. The system could enforce the convention. Or the 'object' class could. See the thread here entitled antiDecorator metaclass for a demonstration of how this could be done. From lonetwin at gmail.com Fri Aug 20 05:31:08 2004 From: lonetwin at gmail.com (Steve) Date: Fri, 20 Aug 2004 15:01:08 +0530 Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: <5a309bd304082002311afcb6d@mail.gmail.com> Since this thread is certain to become something of a c.l.p lore, I'll do my bit ... Age: 26 I started out as a systems administrator, which required me to learn shell scripting, I soon became a scripting nut, parsing conf files, writing admin tools etc..., it didn't take me too long before I began aching for a more ^expressive^ language, looked at perl, but that appeared expressive only in the way slang is expressive for most teenagers. A programmer friend suggested python and it was then that I found the language that I could write script poetry in. Before I realized it, I was looking for python programmer jobs. Since I had decided to give up my System Admin. status for that of a programmer, I learned C and C++ (thanks to my python knowledge, I actually understood what I was supposed to be doing :)). Now I am a happy coder, working for a linux+python shop, doing almost 90% of my work in python. I guess the time has come for me to say this: 'A BIG THANK YOU' - to GvR and The Folks, for contributing to my state of happiness. Regards Steve From alienoid at is.lg.ua Tue Aug 3 18:42:33 2004 From: alienoid at is.lg.ua (Ruslan) Date: Wed, 04 Aug 2004 01:42:33 +0300 Subject: python + byte array Message-ID: <1091572953.7095.8.camel@dev.is.lg.ua> Hi, everybody. I use win32com package to call WinHTTP COM methods. One of them is 'Send'. I can pass string parameter to 'Send' method from python - it's OK, but to send binary data i need somehow pass in 'Send' method data of _byte array_ type(Visual Basic type). Does anybody know how to mimic that 'byte array' type of Visual Basic in Python (i need to pass big chunks of binary data in 'Send')? I tried struct.pack, but that doesn't seem to be an option. Thanks in advance. Your help is very appreciated. Best regards, Ruslan From luismg at gmx.net Sun Aug 22 10:36:37 2004 From: luismg at gmx.net (Neuruss) Date: 22 Aug 2004 07:36:37 -0700 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> Message-ID: <278de0e.0408220636.3ee25f9d@posting.google.com> > What makes you think speed is Python's primary limitation for mainstream > acceptance? Why would someone reject to use a language that is clean, very well designed, intuitive, expresive, flexible and a pleasure to use? Perhaps the fact that i is 100 times slower than c... From paolo.veronelli at yahoo.it Wed Aug 25 06:59:04 2004 From: paolo.veronelli at yahoo.it (Paolo Veronelli) Date: Wed, 25 Aug 2004 12:59:04 +0200 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: Message-ID: <412C70F8.6020501@yahoo.it> Steven Bethard wrote: > Paul Morrow yahoo.com> writes: >>So why don't they share a similar syntax? >> >> class Foo: >> """ This is the docstring for class Foo. """ >> __metaclass__ = M >> # body of class goes here >> >> >> def baz(): >> """ This is the docstring for function baz. """ >> __features__ = synchronized, memoized >> # body of function goes here. > > > > So the basic answer is that decorators are different from metaclasses because > the code inside the funcdef block is executed when the function is /called/, > while the code inside the classdef is executed when the class is /declared/. > This can be seen as an engine choice and IMO is very far from touching the syntax issue. Still I posted a question before: Is not time to put order in the possible uses of __xxx__ with a job on classifying them and stop looking for a better role for BDFL? Proposals: 1) Ban a "just because I'm free of doing it" use of them as settable/gettable attributes (in place of non special meanings attributes) (optional actually) 2)One or more builtin classes (interfaces) useful to build their significance,with a previous work on classifying possible levels of interpreter instructioning: a) Syntactical level: _1) (re)defining operators code _2) ...... b) Allocational level: __init__,__new__,__metaclass__ ....???? c) Decorational: ......... d) Globalish: __name__,.... d) Whatelsetional ...... Good meditation to all Paolino From tim.hochberg at ieee.org Thu Aug 26 14:15:38 2004 From: tim.hochberg at ieee.org (Tim Hochberg) Date: Thu, 26 Aug 2004 11:15:38 -0700 Subject: Call for signatories for J2 In-Reply-To: References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> Message-ID: Doug Holton wrote: > Tim Hochberg wrote: > >> I also have a weak preference for 'per' over 'using', FWIW. The >> shortness of 'per' is one virtue. Another is that, because it's >> slightly obscure, it may be easier to indoctrinate users that >> 'per...def' is the correct order, not 'def...per'. For me at least >> it's 'obvious' that if 'using...def' works then so should >> 'def...using', which of course it can't. The order is amenable to >> memorization, but I still anticipate more thinkos of this type from >> using than from per. On the downside, per may be extremely obscure to >> those that are neither native speakers of English or one of the >> romance languages. > > > Even in common English usage, "per" usually comes in the middle of a > phrase, not the beginning, like "miles per hour" or "Changes were made > to the manuscript per the author's instructions" (people would more > commonly use the phrase "according to" rather than "per" there). Per the author's instructions, changes were made. Changes were made per the author's instructions. Using only hand tools, we built the treehouse. We built the treehouse using only hand tools. Both of 'per' and 'using' (and most of the other keyword options that aren't really horrible) have a bias for being read backwards. My contention was that since 'per' is probably a bit less familiar it would be easier to beat the nonstandard order into ones head. > None of those uses bare any resemblance to how decorators affect > functions. I don't agree. Or at least I don't agree that: per: instructions def func(): ... Is any worse a model for what's going on than: using: functions def func(): ... Neither's great, both are suggestive of what's going on. Unless we use: use_the_following_functions_to_transform_the_subsequent_def It's going to be pretty hard to get something that's much more than suggestive. > "per:" by itself on a line is pretty much meaningless. > Looks more like you misspelled pre. If "pre:" was legal Python, I certainly wouldn't support 'per:'. While 'per' may in fact be too obscure, and that's legitimate point to argue, I'm not sure that arguing about how it reads out of context is all that relevant. Whatever keyword is chosen, I expect it to be fairly close to the subsequent def. > If people are liking Latin keywords for decorators now, why not "sic"? It's even vauger than per. I'll give it that. When I was young, I was too lazy to look it up, so I backronymed this into Spelling Intentionally Compromised. In retrospect, this probably fits the real usage better than the Latin, so no harm done. -rim From Andreas.Ames at tenovis.com Mon Aug 9 07:37:07 2004 From: Andreas.Ames at tenovis.com (Ames Andreas (MPA/DF)) Date: Mon, 9 Aug 2004 13:37:07 +0200 Subject: q about cgi.FieldStorage Message-ID: <788E231C269961418F38D3E360D1652526CA21@tndefr-ws00021.tenovis.corp.lan> Hi, Tim Roberts wrote: > Not in its raw form. The stream comes from Apache and evaporates as > it is read. If you need to raw data, just forget about > cgi.FieldStorage and read stdin directly. You can always copy it to > a temp file or StringIO and feed it back to the cgi module later. thanks for confirming this. The only problem I see with your suggestion, or rather with the implementation, is that the caller has seemingly no control over whether FieldStorage writes the input to disk once more or not. cheers, andreas From simoninusa2001 at yahoo.co.uk Tue Aug 10 18:52:05 2004 From: simoninusa2001 at yahoo.co.uk (simo) Date: 10 Aug 2004 15:52:05 -0700 Subject: wxPython & redirecting stderr References: Message-ID: <30260531.0408101452.76e424fa@posting.google.com> "flupke" wrote: > i'm developing an app in wxPython but when i have an error in the > wxPython code i've written, the app starts, an extra windows is > opened where the error messages are print and then it closes > again. Off course, this is to fast for the human eye to read :) > How can i avoid this and have the wxPython messages arrive at the > console just like the "normal" python error messages? As I recall it has something to do with how you call MainLoop - I think it's the 0 below, maybe you have 1 or nothing? app = MyApp(0) app.MainLoop() From rebelgeekz at hotmail.com Tue Aug 10 11:41:29 2004 From: rebelgeekz at hotmail.com (RebelGeekz) Date: 10 Aug 2004 08:41:29 -0700 Subject: Decorators proposal Message-ID: <19b62f17.0408100741.7f2712ac@posting.google.com> Just my humble opinion: def bar(low,high): meta: accepts(int,int) returns(float) #more code Use a metadata section, no need to introduce new messy symbols, or mangling our beloved visual cleanliness of python. Please, let common sense guide your passion. "When in doubt, copy python" ;-) From roy at panix.com Sun Aug 22 10:15:36 2004 From: roy at panix.com (Roy Smith) Date: Sun, 22 Aug 2004 10:15:36 -0400 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> Message-ID: In article , aahz at pythoncraft.com (Aahz) wrote: > In article <278de0e.0408211605.426e5129 at posting.google.com>, > Neuruss wrote: > > > >It seems there are quite a few projects aimed to improve Python's > >speed and, therefore, eliminate its main limitation for mainstream > >acceptance. > > What makes you think speed is Python's primary limitation for mainstream > acceptance? Speed is the primary limitation for mainstream acceptance of high level (aka scripting) languages in general. I can think of no reason why so much software is still written in languages like C++ other than performance (or at least, the perception of it). From grv575 at hotmail.com Tue Aug 3 21:53:47 2004 From: grv575 at hotmail.com (grv) Date: Wed, 4 Aug 2004 01:53:47 +0000 (UTC) Subject: Code density References: <95aa1afa.0406172240.651a443d@posting.google.com> Message-ID: <953AD96BBidtoken@128.91.2.239> michele.simionato at poste.it (Michele Simionato) wrote in <95aa1afa.0406172240.651a443d at posting.google.com>: >j_mckitrick at bigfoot.com (j_mckitrick) wrote in message >news:... >> Peter Hansen wrote in message > Blank lines are a >> readability tool as much as clear indentation is. >> > Depending on the definition of "sparingly", this may be the one >> > piece of Guido's advice that we've ever ignored... :-) >> >> I've found myself using even more blank lines in python than C++. But >> if you look at BitTorrent, for example, the author claims blank lines >> are a nuisance. He writes very dense code, but I wonder if it would >> be easily maintainable by anyone besides him. >> >> >> jonathon > >He also does not use docstrings. I think BitTorrent code is not >typical >in this respect. Look at the code in the standard library if you want >to see how the core Python developer write. Reading the modules >written by Tim Peters >is especially entertaining (lots of and LOL remarks ;) >I also would take them as examples when teaching clarity in coding. > > > Michele Simionato > Depends on your style really. A comment to the right of the piece of code or above it if it's describing more than 1 step, serves the same purpose as breaking atomic groups of code with whitespace. Plus then you have a concise comment which can be read much faster than figuring out 4-5 lines of python mentally. From dave at pythonapocrypha.com Mon Aug 30 14:10:08 2004 From: dave at pythonapocrypha.com (Dave Brueck) Date: Mon, 30 Aug 2004 12:10:08 -0600 Subject: Size of a remote URL In-Reply-To: References: Message-ID: <41336D80.2070501@pythonapocrypha.com> Justin wrote: > How does Internet Explorer and other browsers do it? I have tried > doing a Save As on multiple files that I know do not return a > content-length header and yet it still knows the size and creates a > progress bar? How about posting a URL? I'd be happy to try it out for you. Also note that IE is notorious for "lying" to the user about progress - on page loads for example, their progress bar often moves even after your net connection has gone down. Not sure if they're doing that on the file download progress bar, but it's something to be aware of. From peter.maas at mplusr.de Wed Aug 18 14:10:46 2004 From: peter.maas at mplusr.de (Peter Maas) Date: Wed, 18 Aug 2004 20:10:46 +0200 Subject: age of Python programmers In-Reply-To: References: Message-ID: Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? 48.16 -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- From reply.in.the.newsgroup at my.address.is.invalid Wed Aug 18 06:35:55 2004 From: reply.in.the.newsgroup at my.address.is.invalid (Rene Pijlman) Date: Wed, 18 Aug 2004 12:35:55 +0200 Subject: favorite python web development tool? References: <10i4nttktcvltdd@corp.supernews.com> Message-ID: mike: >i'm fairly new to python, coming from a java servlet / velocity template >background. i'm looking for a good python web development tool, and >hope to find some suggestions here. Webware hasn't been mentioned yet :-) -- Ren? Pijlman From srumbalski at copper.net Sun Aug 1 16:03:46 2004 From: srumbalski at copper.net (Steven Rumbalski) Date: Sun, 01 Aug 2004 16:03:46 -0400 Subject: transforming a list into a string References: Message-ID: <410d4bf1_1@newsfeed.slurp.net> Peter Otten wrote: Peter's solution: >>>> from itertools import izip >>>> items = ['1','2','7','8','12','13'] >>>> it = iter(items) >>>> ",".join(["{%s,%s}" % i for i in izip(it, it)]) > '{1,2},{7,8},{12,13}' My first thought was: >>> items = ['1','2','7','8','12','13'] >>> ",".join(["{%s,%s}" % i for i in zip(items[::2], items[1::2])]) ?'{1,2},{7,8},{12,13}' Two lines less, but it creates three unnecessary lists.??I?like Peter's better. --Steven Rumbalski From anthonybaxter at gmail.com Thu Aug 5 21:54:27 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 11:54:27 +1000 Subject: Python milestone releases In-Reply-To: References: Message-ID: On Fri, 06 Aug 2004 00:55:55 +0200, Thomas D'Tak wrote: > I do not want to complain here that Python is developing too > fast; and I do not want to criticize Python's system of version > numbers. But I want to ask for resp. suggest something like > *official Python milestone releases*. (Please correct me if > something like that does already exist and I am just not aware > of it.) > > Official Python milestone release statements should discourage > the use of older versions. Moreover, not each and every Python > release should be a milestone release (clearly). How exactly would this be different to our existing release process? In case it's not clear, the webpages for old versions of Python already state "This version is old, and you should use a newer version". Most bugfix releases, I try to put words in to encourage people to upgrade. I'm not sure how "2.3" isn't a milestone in any way that's meaningful. From graham__fawcett at hotmail.com Fri Aug 20 14:49:11 2004 From: graham__fawcett at hotmail.com (Graham Fawcett) Date: 20 Aug 2004 11:49:11 -0700 Subject: My only complaint about Python References: <2ol650Fbr791U1@uni-berlin.de> Message-ID: Greg Ewing wrote in message news:<2ol650Fbr791U1 at uni-berlin.de>... > David Fraser wrote: > > I agree. I don't mind it being built with Visual Studio, but out of the > > box mingw compatibility would be cool... > > As a step towards this, it would be useful if it were > distributed with the libpythonXX.a that mingw requires > already built. Then it would just be a matter of giving > the appropriate flag to setup.py when compiling a module. +1! Building libpythonXX.a isn't tremendously hard, but it's a pain. Given the simplicity of mingw's installation (and distutils' familiarity with it) this would definitely simplify extension building on win32. -- Graham From brett at python.org Tue Aug 10 14:26:06 2004 From: brett at python.org (Brett C.) Date: 10 Aug 2004 11:26:06 -0700 Subject: Popular Python projects with lots of pure Python code References: Message-ID: <8ab0589d.0408101026.2036a0ed@posting.google.com> "Brett C." wrote in message news: > Any suggestions? > Just a quick thanks to everyone who has responded. I truly appreciate the help on this! This is why the Python community is just so damn cool! And here are some quick answers to some questions that have come up in the thread... "Big" is relative; not looking for simple scripts, but otherwise I am open. No real minimum size or anything. The projects do not have to be devoid of C; just have enough Python code to warrant using. "Popular" is also relative. Since Python is not used here at my school (Cal Poly SLO), I wanted to also use my thesis as a slight PR piece within the department. Being able to list big, popular Python projects would help to show the legitimacy of the language to professors. Please suggest only open source projects. While I have no issue with proprietary projects personally I don't want to have to worry about what I can and cannot discuss in my thesis. I personally don't need any more web projects listed. Go for it if this thread just keeps going, but with the ones listed so far that is plenty. I would love to get a wide swath of projects so as to make sure my thesis can't be accused of not being representative of non-web projects. Something I should have mentioned in the OP is anything that has a benchmark is an uber-plus! I am going to end up having to benchmark some code that I did not gather stats on along with some that I did to try to show that this was all worth it. Already plan to use pystone and parrotbench. Anyway, here is the current list that I have going. Ignore the question marks; just means I have not decided whether I am definitely using it or not. ---------------- ----------------------------------- Projects for stat collection ----------------------------------- + Stdlib (w/o test) + Docutils + Twisted? + Zope? * Plone? + ReportLab? + wxPython? + BitTorrent? + SpamBayes? + Mailman? + SiGeFi ? + Plucker ? + Universal Feed Parser ? + Shtoom? + Divmod Quotient? + MoinMoin? + PIL? + PySNMP ? + scipy ? + Boa Constructor ? + PythonCard ? + OpenGLContext ? + PyTable ? ------------------ Benchmarks ------------------ + pystone + parrotbench From chrisks at NOSPAM.udel.edu Sat Aug 28 05:09:12 2004 From: chrisks at NOSPAM.udel.edu (Chris S.) Date: Sat, 28 Aug 2004 09:09:12 GMT Subject: Circular Import? Message-ID: Consider the sample case: ## a.py import d import b b.App() ## b.py from c import C B = 'B' class App(object):pass ## c.py from d import D class C(object):pass ## d.py from b import B D = 'D' Executing a.py will return: Traceback (most recent call last): File "a.py", line 1, in ? import d File "d.py", line 1, in ? from b import B File "b.py", line 1, in ? from c import C File "c.py", line 1, in ? from d import D ImportError: cannot import name D I'm assuming this is the result of the circular imports. This isn't a bug, right? Is there any way around it? From brett at python.org Wed Aug 25 18:41:51 2004 From: brett at python.org (Brett C.) Date: 25 Aug 2004 15:41:51 -0700 Subject: Proposal for removing self In-Reply-To: Message-ID: No thanks. This is a common suggestion and Guido has said it ain't going to happen. I personally like 'self' a lot because ambiguity from reading code goes away. It is easy to not see a '.' but not so for 'self.' . It also makes teaching OOP to people much easier since you don't need to explain why some variables and method calls are to the instance but other are not. "Explicit is better than implicit". From davidf at sjsoft.com Thu Aug 19 15:54:44 2004 From: davidf at sjsoft.com (David Fraser) Date: Thu, 19 Aug 2004 21:54:44 +0200 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: Paul McGuire wrote: > There are a number of messages on the python-dev mail list that indicate > that Guido is looking for some concensus to come from this list as to what > *one* alternative syntax for decorators we would like him to consider in > place of the @ syntax that is currently in 2.4a2. > > I think special thanks are due to: > - Anthony Baxter for his continuing efforts in this regard > - Steven Bethard for some of the clearest thinking and writing on this topic > - Michael Sparks for actually implementing one of the options > > We've all done our share of pitching and whining, but we need to settle on > *one* option for Guido to consider. > > (And let's not get wrapped up complaining about the "process" being followed > in this whole thing, personally I think it is quite poor. But let's play > with the cards we've been dealt, and at least make a collective proposal.) > > The significant alternatives have been listed on the Python wiki at > http://www.python.org/moin/PythonDecorators . > > Interested parties should also look at the comments in the python-dev > archive for the past month, at > http://mail.python.org/pipermail/python-dev/2004-August/thread.html . > > I would propose a multivote survey: each poster gets 3 votes among the > lettered choices on the Wiki page above. You can use all 3 for a single > option, or split them across 2 or 3 options if you are open to more than > one. > > I am not going to argue that this is scientific in any respect, but it > *should* allow the major 1 or 2 choices to bubble to the top. I have used > this process at work many times in the past when it was necessary for a > large group to set priorities among a large list of choices. > > My vote is: J2 J2 C1 > > By the way, once an option has been chosen, it *still* needs an > implementation for Guido to accept it. This puts some of the options way > ahead of the others, in my mind. > J2 L L I hope once the major 2 choices or so are clear that there is another discussion about how to select one David From della at toglimi.linux.it Wed Aug 4 07:51:56 2004 From: della at toglimi.linux.it (Matteo Dell'Amico) Date: Wed, 04 Aug 2004 11:51:56 GMT Subject: Does python support multi prototype. In-Reply-To: <2natmnFv86rjU1@uni-berlin.de> References: <2natmnFv86rjU1@uni-berlin.de> Message-ID: angel wrote: > Java and cpp support one function name multi function prototype. [...] > Does python support it? Not natively, but - if you really need them - there are modules that make them possible. Have a look at http://gnosis.cx/publish/programming/charming_python_b12.html , and maybe at http://codespeak.net/pypy/index.cgi?doc/objspace/multimethod.html too. -- Ciao, Matteo From gneuner2/ at comcast.net Fri Aug 27 00:50:58 2004 From: gneuner2/ at comcast.net (George Neuner) Date: Fri, 27 Aug 2004 00:50:58 -0400 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <10isgqrfbmnc26b@corp.supernews.com> Message-ID: <0cfti0hu2ps1l930fea0050vo76jeb2drh@4ax.com> On Thu, 26 Aug 2004 13:09:32 -0700, Jeff Shannon wrote: >The Cult did have an earlier incarnation as Southern Death Cult. And Blue Oyster Cult was originally Soft White Underbelly. George -- for email reply remove "/" from address From max at alcyone.com Sat Aug 7 18:48:19 2004 From: max at alcyone.com (Erik Max Francis) Date: Sat, 07 Aug 2004 15:48:19 -0700 Subject: elements of decorator syntax suggestions References: <4edc17eb.0408062125.231f7bef@posting.google.com> Message-ID: <41155C33.37EEB397@alcyone.com> Tim Peters wrote: > Overloading a unary prefix operator is out. As Anthony said, vertical > bar seemed to be the leading contender on python-dev Friday. You can > find tedious arguments there about most of the others that would go > for you. Why is | superior to @? | already has a meaning in Python, and it has nothing to do with decorators ... at least @ has the virtue of currently being unused in the language, and having the precedent of being used for a similar feature in Java. -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ Could it be / That we need loving to survive -- Neneh Cherry From peter at designtheory.org Wed Aug 4 15:39:29 2004 From: peter at designtheory.org (Peter Dobcsanyi) Date: 4 Aug 2004 19:39:29 GMT Subject: ANN: pynauty 0.1 - iso/automorphism for graphs Message-ID: Pynauty is a Python extension module to Brendan McKay's Nauty C procedures. The module provides Python classes to represent graphs and functions for isomorphism testing and computing automorphism groups of graphs. The graphs can be undirected or directed. They can contain loops but no multiple edges. There is always a vertex-coloring associated with them. Ordinary, that is not vertex-colored, graphs can be represented with all vertices having the same color. For download, documentation, installation instructions please visit: http://designtheory.org/software/pynauty/ -- , Peter Dobcsanyi From fuzzyman at gmail.com Fri Aug 27 07:05:59 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 27 Aug 2004 04:05:59 -0700 Subject: Is it a bug (or a feature)? References: Message-ID: <6f402501.0408270305.1c27faa4@posting.google.com> Roman Suzi wrote in message news:... > In Python2.3.4: > > >>> em = email.message_from_file(open('MAILMESSAGE')) > >>> for i in em: > ... print i > ... > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/lib/python2.3/email/Message.py", > line > 304, in __getitem__ > File "/usr/lib/python2.3/email/Message.py", > line > 370, in get > AttributeError: 'int' object has no attribute 'lower' > > However items() does work: > > >>> for i in em.items(): > ... print i > ... > ('Date', '24 Aug 2004 16:06:01 +0400') > ('From', 'Mail System Internal Data ') > ('Subject', "DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA") > ('Message-ID', '<1095549161 at mydomain.ru>') > ('X-IMAP', '1095527634 0000000005') > ('Status', 'RO') > > I can probably guess why this happens ('cause multiple fields with the > same names are possible), but .items() is broken by this... It needn't > be! > > > Sincerely yours, Roman A.Suzi It's very similar to a 'feature' in the urllib2 module. (Python 2.3.4) >>> from urllib2 import urlopen >>> a = urlopen('http://www.voidspace.org.uk') >>> print a >>> i = a.info() >>> for entry in i: print entry Traceback (most recent call last): File "", line 1, in -toplevel- for entry in i: print entry File "D:\PYTHON23\lib\rfc822.py", line 390, in __getitem__ return self.dict[name.lower()] AttributeError: 'int' object has no attribute 'lower' Regards, Fuzzy http://www.voidspace.org.uk/atlantibots/pythonutils.html From martindemello at yahoo.com Sun Aug 15 10:47:06 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Sun, 15 Aug 2004 14:47:06 GMT Subject: Control an external console program References: Message-ID: Alexander Stante wrote: > So my question is how do I control a command line tool? I want to Check out http://pexpect.sourceforge.net/ martin From peter at engcorp.com Mon Aug 30 12:48:13 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 30 Aug 2004 12:48:13 -0400 Subject: PHP Documentation In-Reply-To: References: <4133124f$0$281$4d4ebb8e@news.nl.uu.net> Message-ID: A.M. Kuchling wrote: > On Mon, 30 Aug 2004 09:30:39 -0400, > Peter Hansen wrote: > >>1) Thinking it's a good idea isn't enough if you want it: somebody >> has to implement it. It's been suggested before, so at this >> point the next step is for someone who likes the idea enough >> to just do it. > > Someone started doing it manually -- see > http://www.python.org/moin/PythonLibraryReference . I guess it might help to publicize it, such as via your posting. ;-) Since Lloyd did that on May 11 it appears nobody has modified any of the PythonLibraryReference pages. More precisely, nobody has appended any comments per the original instructions, though it's possible someone modified the text in violation of those instructions. Wikis can be useful for maintaining documentation, but so far I've seen it succeed only in very limited instances, and in this case without top level support (e.g. recognition by the official doc maintainers that this is now the master copy) I really doubt it will get far. Feel free, anyone, to prove me wrong. -Peter From michele.simionato at gmail.com Thu Aug 12 00:52:03 2004 From: michele.simionato at gmail.com (Michele Simionato) Date: 11 Aug 2004 21:52:03 -0700 Subject: The winner of the Python Decorator Poll is... References: Message-ID: <4edc17eb.0408112052.1bbd85b3@posting.google.com> Jack Diederich wrote in message news:... > On Wed, Aug 11, 2004 at 04:16:54PM -0500, Doug Holton wrote: > > George W Bush, as certified by Florida's election commission. > > > > > > Which decorator syntax do you like the most? See > > http://wiki.wxpython.org/index.cgi/PythonDecoratorsPoll > > A. @classmethod def foo(): (82) 14% > > C1. def foo() [classmethod]: (235) 41% > > E1. def foo(): @classmethod (260) 45% > > > > Total Votes: 577 > > > > People are about 6 to 1 against having the decorators come before the > > "def" keyword. > > Or people who don't like decorators before the def are six times as > likely to vote in the dissidents poll *wink* > > -Jack Indeed. Actually I did not vote since I like the current proposal (maybe I would like "|" more than "@") and I dislike all the alternatives, especially having decorators inside the def. So the poll is unavoidably biased. Happily, we are not in a democracy! Michele Simionato From rogerb at rogerbinns.com Sun Aug 15 02:29:13 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Sat, 14 Aug 2004 23:29:13 -0700 Subject: Python secure? References: Message-ID: <6fc3v1-4il.ln1@home.rogerbinns.com> Calvin wrote: > Could someone tell me just how secure Python is if compiled to an > exe? Is it more or less secure than using some other language? Tell us how you define secure if you want a meaningful answer. If you want a meaningless answer then Python is more secure than a Ferrari in some circumstances. Roger From Baykara43 at noroozbasket.com Sat Aug 21 10:58:03 2004 From: Baykara43 at noroozbasket.com (Baykara Mullins) Date: 21 Aug 2004 09:58:03 -0500 Subject: Interesting Message-ID: <412762fb@news01.argolink.net> Interesting newsgroup! Baykara Mullins Tel. +1 301 696 1549 Baykara at biogenesys.com Baykara at anyclue.com From pm_mon at yahoo.com Sat Aug 21 10:38:01 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sat, 21 Aug 2004 10:38:01 -0400 Subject: __metaclass__ and __author__ are already decorators Message-ID: Thinking about decorators, and looking at what we are already doing in our Python code, it seems that __metaclass__, __author__, __version__, etc. are all examples of decorators. So we already have a decorator syntax. What is the compelling reason to invent a new one? And if we do, what's to become of the old one? Here's my take on this. We have two kinds of decorators: those that are informational only (like __author__ and __version__), and those which have side-effects, i.e. those that actually *do* something (like __metaclass__). class Foo: """ This describes the Foo class as normal. """ __metaclass__ = M __author__ = 'Paul Morrow' __version__ = '0.1' __automethods__ = True def baz(self, a, b): """ This describes the baz method. """ __synchronized__ = True __returns__ = None __author__ = 'Neville Shunt' # body of baz goes here... There, that looks pretty clear and pythonic. Now how to define the decorators. def metaclass(decoratedClass, subType): """ This describes the 'metaclass' decorator. """ __decorator__ = True __version__ = '1.9' # perform the metaclass operation on decoratedClass def synchronized(decoratedFunc, trueOrFalse): """ This describes the 'synchronized' decorator. """ __decorator__ = True __author__ = 'Martin Curry' __version__ = '0.5' # perform the synchronized operation on decoratedClass def returns(decoratedFunc, *args): """Docstring for 'returns' decorator.""" __decorator__ = True # body of decorator goes here Each decorator function receives the class|function|method being decorated as the first parameter of the function (e.g. decoratedClass and decoratedFunc above). The remaining parameters are the values assigned to the __xxx__ variable in the definition of the decorated function. So, in the above example, when the 'returns' decorator function is called to decorate the 'baz' method, decoratedFunc would recieve the baz object and args[0] would be set to None (because of the statement "__returns__ = None" in the definition of baz). For a function to be used as a decorator function, it must be decorated as such, by setting its __decorator__ attribute to True. Does this handle enough of the decorator concerns? Paul From squirrel at WPI.EDU Tue Aug 3 15:57:02 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 3 Aug 2004 15:57:02 -0400 Subject: executing python programs as if they were on OS path (noob) In-Reply-To: References: Message-ID: On Tue, 3 Aug 2004, Darren Dale wrote: > > At least two options (assuming you're on Linux... you > > didn't specify your OS unfortunately): > > I am currently on windows. I didnt think it would matter, sorry I left > that out. You could probably still use Peter's second solution, but use a batch file instead of a shell script. From ake.ljungbert3 at comhem.se Fri Aug 27 15:35:27 2004 From: ake.ljungbert3 at comhem.se (ake) Date: 27 Aug 2004 12:35:27 -0700 Subject: Boa Constructor error References: <4712d252.0408260804.c69cfee@posting.google.com> Message-ID: <875af5e2.0408271135.7a19a30f@posting.google.com> Uwe Grauer wrote in message news:... > Parano wrote: > > Hi > > > > I have a recurrent error in Boa Constructor, especially when I try to > > activate code completion: a message box reads "UnicodeDecodeError: 'ascii' > > codec can't decode byte 0xaa in position 52: ordinal not in range(128)" > > I couldn't find any google resource on that error. > > > > I have Python 2.3.3 with Boa Construtor 0.3.1 on Mandrake Linux 10. > > wxPython is from wxPythonGTK-py2.3-2.5.2.7-RH9.i386.rpm > > I also tried wxPythonGTK2-py2.3-2.5.2.7-RH9.i386.rpm but had the same error. > > Those RPMs are from www.wxpython.org where it says that "install and use on > > my Mandrake 9.2 system without any troubles." > > > > Any tip on this? Thanks in advance > > Boa isn't ready for wxPython 2.5.x > Use wxPython 2.4.2.4 instead. > > Uwe Anyone know what's happening to Boa, there doesn't seem to have been a new version for over a year. ?ke From klachemin at home.com Wed Aug 18 16:06:51 2004 From: klachemin at home.com (Kamilche) Date: 18 Aug 2004 13:06:51 -0700 Subject: age of Python programmers References: Message-ID: <889cbba0.0408181206.1812881c@posting.google.com> 40. Old enough that Google wouldn't hire me, hehehehe. From me at privacy.net Sat Aug 14 15:22:30 2004 From: me at privacy.net (Richard Hanson) Date: Sat, 14 Aug 2004 12:22:30 -0700 Subject: [Decorators] Seen on pydev -- comments on such. Message-ID: Seen on news:gmane.comp.python.devel in message-IDs <16668.57809.362313.36355 at montanaro.dyndns.org> and <16669.7113.531528.462699 at montanaro.dyndns.org> [much material not-germane-to-my-comments has been clipped]: > def p_statement_expr: > staticmethod > grammarrule('statement : expression') > version("Added in 2.4") > deprecatedmethod > type_(None) > decorate (self, p): > """docstring here""" > print p[1] > > [...] > > * It doesn't put the cart before the horse by introducing the decorators > before the def. > > [...] > > * It doesn't add an extra level of indentation to the function body. > > [...] > > * It looks more like current Python block structure (at least to me) > than the @-syntax proposal. Allow me to expand just a bit on the bullet immediately above from Skip's list of pros for his proposal: * It looks like the standard "backwards-'F'" block shape which, for example, try-except, try-finally, and if-else already use. (I think this point had been mentioned, prior, and I apologize that I don't have that post at hand. Also, Skip is probably alluding to my very point.) I'm a relative newbie to Python (and only a hobbyist as I've been retired for almost two decades). I discovered Python only a few years ago. Like many, I don't have all that much time or energy or both to devote to active learning of Python, and how the herein quoted proposal fits my brain may mirror a not insignificant minority of the Python-using community. I hadn't even heard of the decorator concept (as Python renders it) until discussion about such cropped up on pydev (and here) over the last while (last year?) or so. I soon grokked what they were about. And -- I seemed to find no problem whatsoever with the 2.4a2 prefix @deco form. Yet, opposition from much-more-learned-than-me folks made me stop and think. When Guido himself recently opened the door just-a-crack (on pydev) to another decorator-form *if* the community could come up with *one* (he may have said two...?) alternative(s) which were persuasive to him, I sat up. While I trust the developers, and particularly Guido (I have no rational argument to support such religious veneration ), to resolve this in a fine manner, I would like to say the alternative quoted above fits my newbie-but-not-too-dumb :-) brain just as smoothly as the currently implemented, prefix @deco form. It may even be smoother for "newer" newbies. As I pondered the visual appearance of the above quoted "backwards-'F'" form of decorated functions, the common try-except, try-finally, and if-else block-forms came to mind, and I thought: No problem. Decorated functions (or, perhaps, decorated some other things) are just another one of the "backwards-'F'" visual wetware shape-templates (the other common Python shape-template being the "backwards-and-upside-down-'L'") for my brain to pattern-recognize. Therefore, for me, the backwards-F form is not a negative. (And better backwards-F forms may yet evolve.) I recognize, however, that other considerations may well still outweigh the "shape" argument. --- Having said all that, I'll add that I'm hardly qualified to comment at all on the Shape Of Things To Come :-), and I'll happily and gratefully use any decorator form (if I figure out Python well enough to use them ). I just couldn't resist throwing in my own thoughts on the topic (as it appears we're going for the All-Time Longest Topic Ever Award ). (I haven't learned the syntax, yet... :-) ) brain-oriented-visually-y'rs, Richard -- R Hanson [The mangled email addie below works.] sickolefartnewsguycom From fumanchu at amor.org Wed Aug 25 00:21:20 2004 From: fumanchu at amor.org (Robert Brewer) Date: Tue, 24 Aug 2004 21:21:20 -0700 Subject: Are decorators really that different from metaclasses... Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E64@exchange.hqamor.amorhq.net> Anthony Baxter wrote: > Class decorators are not in 2.4, because you can do most things you'd > do with a class decorator by using a metaclass, but in a completely > different way. In my opinion, class decorators _should_ be in 2.4, > because they're a much saner way to handle many things that require a > metaclass today. For various definitions of "should", I'd say at this point they should be in 2.5. Nothing's stopping that, AFAICT. Give function decorators a trial run and then try class decorators. I prefer that schedule even though I personally have use cases for class decorators and none for functions... Robert Brewer MIS Amor Ministries fumanchu at amor.org From rnd at onego.ru Mon Aug 23 06:18:25 2004 From: rnd at onego.ru (Roman Suzi) Date: Mon, 23 Aug 2004 14:18:25 +0400 (MSD) Subject: J2 proposal: keyword In-Reply-To: References: Message-ID: On Mon, 23 Aug 2004, Anthony Baxter wrote: >On Mon, 23 Aug 2004 01:36:31 -0700, David Pokorny > wrote: >> using: >> staticmethod synchronized memoize >> def bar(foo): >> "To colon or not to colon? Def is the question." >> pass This surprises me. And this doen't surprise: using: staticmethod; synchronized; memoize def bar(foo): "To colon or not to colon? Def is the question." pass Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3 From squirrel at WPI.EDU Tue Aug 17 15:06:12 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 17 Aug 2004 15:06:12 -0400 Subject: is it possible to create an object by its name in the run time In-Reply-To: References: <003d01c48407$45aeaf10$6400a8c0@offer> Message-ID: On Tue, 17 Aug 2004, Yang Zhang wrote: > I want to know if it is a build-in func(where can I look up?). If so, > ignore it otherwise I want to find out which module is it defined in. All functions and classes have a __module__ attribute which is set to the name of the module in which they were defined. > All I know is the name (which is a string), and all the modules that > this program have imported. If you first "import __main__", you can use getattr(__main__,"foo") to get the object named "foo" in the global namespace. > In the same way, I also need to process the class and methods call. I > wonder if it is possible? I will appreciate your help very much!! Here is a small snippet demonstrating the above: import __main__ from types import FunctionType, ClassType def which_module(name, where = __main__): try: obj = getattr(where, name) except AttributeError: obj = getattr(__builtins__, name) try: return obj.__module__ except AttributeError: if not isinstance(obj, (FunctionType, ClassType)): raise TypeError, "%s doesn't reference a function or class" % name return None print which_module('list') # --> '__builtin__' from math import sin print which_module('sin') # --> 'math' a = 6 print which_module('a') # --> TypeError Hope this helps. From heikowu at ceosg.de Sat Aug 7 05:53:26 2004 From: heikowu at ceosg.de (Heiko Wundram) Date: Sat, 7 Aug 2004 11:53:26 +0200 Subject: threads: not locking read-only objects In-Reply-To: <2niuanF1ee0tU1@uni-berlin.de> References: <2ni4b4F16u92U1@uni-berlin.de> <2niuanF1ee0tU1@uni-berlin.de> Message-ID: <200408071153.26443.heikowu@ceosg.de> Am Samstag, 7. August 2004 04:58 schrieb Jon Perez: > whoison['username']="timeoflogin" # to add someone new > > del whoison['username'] # to remove someone who's logged out > > Do the above count as atomic? Yup, both of them are atomic. But: If you use different dictionary keys than strings, you're in for a little surprise, as __hash__ing an object can cause Python to be called, which might be suspended by a thread switch. The dictionary object will still be in perfect order (it'll never be in an inconsistent state), but the key reference won't be in the dictionary yet. > for x in whoison: > print x,whoison[x] > > Looking at the read-only code though I just realized > something.... if a dictionary entry in 'whoison' is deleted > by the main thread while the 'for x in whoison' is executing > then what would happen? Now, this is something different. You can easily try what happens by doing the following: whoison = {"heiko":"at home","heiko2":"at work"} for x in whoison: print x, whoison[x] del whoison[x] Traceback (most recent call last): File "", line 1, in ? RuntimeError: dictionary changed size during iteration That's the same exception you'll get when another thread changes the python dict while you're iterating over it. What you might do: # The following makes a static copy of the keys of the dictionary. for x in whoison.keys(): try: val = whoison[x] except KeyError: continue print x, val Or just acquire a thread lock before processing the dictionary, which might actually be the easiest solution. ;) Heiko. From pm_mon at yahoo.com Fri Aug 13 23:53:44 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Fri, 13 Aug 2004 23:53:44 -0400 Subject: AntiDecorator metaclass In-Reply-To: References: Message-ID: Paul Morrow wrote: > One of the beautiful things about Python is its clear, minimal syntax. > So we must resist adding new syntax to the language, especially where > there is a reasonable alternative. > > I believe that Stefen Eischet's suggestion for automatically determining > a method's type (class/instance/static) from the name of its first > formal parameter is a reasonable alternative to any/all of the decorator > syntax proposals. > > Just as the Python system relies on indentation conventions to denote > the programmer's intended block structure, it could just as well rely on > parameter naming conventions to denote method types. And as long as > these conventions feel natural to the programmer, the language retains > its beauty. > > So here is a metaclass that illustrates (what I believe is) the > essential idea behind Stefen's suggestion. See the docstring and > footnotes for a description of what it does. > > ################################################################## > class AntiDecorator(type): > """ Metaclass that protests against decorator syntax :-) > > This metaclass infers a method's method type (instance, class, > or static) from the name of its first formal parameter, then > makes the necessary Python declaration. > > * If the 1st parm's name is 'self', then the method is > an instance method. > > * If the 1st parm's name is 'cls' or 'klass', then the > method is a class method. > > * All other methods are static methods. > > ------------------------------------------------- > The essence of this technique was suggested by > Stefan Eischet on the comp.lang.python newsgroup. > ------------------------------------------------- > > This is freeware, no warranties, etc... > > """ > __author__ = 'Paul Morrow ' > __credits__ = 'Stefen Eischet ' > __date__ = '13 Aug 04' > __version__ = '0.1' > > def __new__(cls, clsName, bases, dict): > import inspect, types > for fName in dict.keys(): > f = dict[fName] # 1. > if type(f) is types.FunctionType: # 2. > parmNames = inspect.getargspec(f)[0] # 3. > if parmNames: # 4. > if parmNames[0] in ('cls', 'klass'): # 5. > dict[fName] = classmethod(f) > elif parmNames[0] == 'self': # 6. > pass > else: # 7. > dict[fName] = staticmethod(f) > else: # 8. > dict[fName] = staticmethod(f) > return type.__new__(cls, clsName, bases, dict) > """Footnotes: > 1. Bind f to an attribute of the class (cls). > 2. Only work this magic on functions. > 3. Get the function's formal parameter names. > 4. If it has formal parameters, we'll use them > to determine what kind of function it is. > 5. It's a class method if its first formal > parameter is 'cls' or 'klass'. > 6. It's an instance method (default) if its first > formal parm is 'self' > 7. It's a static method if it's not a class method > or instance method. > 8. No formal parameters, so it's a static method. > """ > > class Object(object): > """ Uses AntiDecorator metaclass to infer method type. """ > __metaclass__ = AntiDecorator > > if __name__ == '__main__': > class Foo(Object): > def imethod(self, parm): > print "I'm an instance method: %s." % parm > def cmethod(cls, parm): > n = cls.__name__ > print "I'm a class method (of %s): %s." % (n, parm) > def smethod(parm): > print "I'm a static method: %s." % parm > > Foo().imethod('alpha') > Foo.smethod('beta') > Foo.cmethod('gamma') > ################################################################## > Rats! Please forgive my careless mispellings of Stefan's name. Pual From nicoe at no-log.org Wed Aug 18 21:31:37 2004 From: nicoe at no-log.org (Nicolas =?iso-8859-15?Q?=C9vrard?=) Date: Thu, 19 Aug 2004 03:31:37 +0200 Subject: singleton (newbie) In-Reply-To: References: Message-ID: <20040819013137.GD4092@smarties.nutellux.ath.cx> * Larry Bates [01:54 19/08/04 CEST]: >2) I continue to read on c.l.p. about staticmethods and > just don't understand why anyone would use them. This > is how I learned to write this in Python. It seems that > they are some sort of "carryover" from another language. > I'd be the first to admit I don't understand the appeal, > so maybe they can be useful. I've just never needed them. > If I need a static function, I just write it that way. > I don't make it the method of a class object. > >if you want x, y to be global across all instances of B: > >class B: > x = 0 > y = 1 > > def foo(self): > print self.x > > def bar(self): > print self.y > self.y+=1 > >if __name__ == "__main__": > b=B() > b.foo() > b.bar() > b.foo() > b.bar() > b.bar() It won't work. Different instances of B will have different values for y. -- (?> Nicolas ?vrard / ) Li?ge - Belgique ^^ From reinhold-birkenfeld-nospam at wolke7.net Sat Aug 28 05:56:36 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Sat, 28 Aug 2004 11:56:36 +0200 Subject: allowing braces around suites In-Reply-To: <87acwgvy51.fsf@sinken.local.csis.hku.hk> References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1ry8k0d2az.fsf@rovereto.ifi.uio.no> <87acwgvy51.fsf@sinken.local.csis.hku.hk> Message-ID: <2pb36dFibuj3U1@uni-berlin.de> Isaac To wrote: >>>>>> "Kjetil" == Kjetil Torgrim Homme writes: > > Kjetil> that's a hack, and IMHO not worthy of a Python program. > Kjetil> not even Perl has anything like that, AFAIK. > > Hm... hacks are not for Python?! We see every kind of hacks > everywhere in Python just like it is in Perl, like (2,) syntax, etc. Why would you call (2,) syntax a hack? If you like, you can call tuple([2]), but I would consider _this_ an ugly solution or a "hack". Reinhold -- [Windows ist wie] die Bahn: Man muss sich um nichts kuemmern, zahlt fuer jede Kleinigkeit einen Aufpreis, der Service ist mies, Fremde koennen jederzeit einsteigen, es ist unflexibel und zu allen anderen Verkehrs- mitteln inkompatibel. -- Florian Diesch in dcoulm From mahesh at privacy.net Sat Aug 28 16:09:34 2004 From: mahesh at privacy.net (Mahesh Padmanabhan) Date: Sat, 28 Aug 2004 14:09:34 -0600 Subject: Generator expressions v/s list comprehensions References: <1gj8y77.6qshr41q531veN%aleaxit@yahoo.com> Message-ID: In article <1gj8y77.6qshr41q531veN%aleaxit at yahoo.com>, aleaxit at yahoo.com (Alex Martelli) wrote: > Sure, and that limitation is: list comprehensions return lists. This > one "limitation" (together with Python's applicative order evaluation, > and you couldn't change THAT without breaking the whole caboodle of > existing programs!) implies everything else. Is returning a list really a limitation considering that lists can be transformed quite easily? What is "Python's applicative order evaluation" and how do generator expressions get around it? > Generator comprehensions are wonderful and there is no way Python list > comprehensions can provide the same features, since lists need to be > lists. Sure, list(e(x) for x in foo) IS just the same thing as [e(x) > for x in foo]. We'll remove the redundancy in 3.0 -- not earlier > because it will break backwards compatibility. The only sensible way I > can see right now for 3.0 to remove this redundancy is by removing list > comprehensions and leaving only generator comprehensions, btw. I am still not clear of the advantages of using generator expressions (other than less memory consumption) instead of list comprehension for any given class of problems. Can you cite concrete use cases where generator expressions would be preferred over list comprehension? Thanks, Mahesh From simoninusa2001 at yahoo.co.uk Thu Aug 12 12:29:20 2004 From: simoninusa2001 at yahoo.co.uk (simo) Date: 12 Aug 2004 09:29:20 -0700 Subject: Pyhton Interpreter Startup time References: Message-ID: <30260531.0408120829.27a536bc@posting.google.com> Neil Benn wrote in message news:... > Hello, > > I'm looking at a small app which would need a very quick > startup time for the Python interpreter. It doesn't do much (copying > and caching of files, no GUI) but I need the Python interpreter to start > up very quickly (<1 second on a Windows box). Is there a way to have a > 'stripped' down Python interpreter which can start up very quickly on a > windows box. This has been discussed before, there's definitely something "odd" about the Windows startup time in comparison to the UNIX "instant" startup. > Once thing I was thinking of was to use PyExe to make a > quick startup (does it compile down to C code, therefore not using the > Python interpreter at runtime?). Is this a possible solution? Nope, no compiling to C/machine code, just bytecode, and the interpreter is a DLL. > I observe that the second time I start python it starts up quicker > but I'm assuming that this is dependent on the environment and can't be > relied upon (or something like that). Yeah, I think that's something to do with Windows caching. I keep saying, we need a Python compiler..... From simoninusa2001 at yahoo.co.uk Thu Aug 12 22:47:42 2004 From: simoninusa2001 at yahoo.co.uk (simo) Date: 12 Aug 2004 19:47:42 -0700 Subject: VB-like GUI designer? References: <30260531.0408102005.5847b9c@posting.google.com> <3hpou1-09i.ln1@home.rogerbinns.com> <30260531.0408120944.5d9ea9f2@posting.google.com> <9ppsu1-fjs.ln1@home.rogerbinns.com> Message-ID: <30260531.0408121847.5b847d6@posting.google.com> "Roger Binns" wrote: > > So how are you generating this interpreter/bytecode archive? It > > basically sounds like the kind of thing py2exe does, but you've made > > an object file or something. How did you calculate the dependencies? > Slides 18 thru 23. On Windows I use py2exe, Linux I use cxFreeze > and Mac uses BundleBuilder. Thanks for the help, I've actually managed to get both cx_Freeze and MM Installer working! I think a lot of it has to do with the quality of the build environment - my RedHat9 box has a horribly hacked-together Python 2.3 distro with bits of RPMs, some compiled stuff and some dodgey symlinking, but the SUSE box has a proper apt-get'ed Python. I can build on the SUSE box and run on the RedHat box! I've written a [simpler than yours] shell script to freeze and then tar-up the distro, then I might try Solaris! I've still got a few things to iron out - like bluecurve.so warnings on RedHat, and linux-gate.so warnings on SUSE, then I've gotta go read your presentation before learning about RPMs! From tdelaney at avaya.com Wed Aug 4 19:01:02 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Thu, 5 Aug 2004 09:01:02 +1000 Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01C8C165@au3010avexu1.global.avaya.com> Christopher T King wrote: > On 4 Aug 2004, Nick Vargish wrote: > >> I just don't know where else to voice my opinion on this matter, but >> I absolutely hate the new decorator syntax. > > I wish PEPs had a method through which votes could be cast, for or > against the PEP (or parts of it), not unlike Bugzilla bugs. At least The last vote was an unmitigated disaster. And there appears to be no more agreement on the correct syntax for decorators. The difference is that decorator syntax will have significant benefits for a certain class of project. > democratic input. Either way, I really wish he would hold off on > decorators until there's a consensus on them, rather than forcing > them in amidst all the disagreements surrounding them. There are significant projects that will greatly benefit from decorator syntax - for example, PyObjC. Personally, I don't overly like the new syntax - I much preferred def func (args) [decorators] - and I would have preferred not to "waste" @ for them, but I can definitely live with the decision. Some usable decorator syntax is IMO more important than none. Besides, @ could possibly be reused for function attributes, meaning it's less "wasted" - there's also an obvious correlation in that both decorators and function attributes operate on the function object: @classmethod def func (args): @attr = 1 pass Tim Delaney From eurleif at ecritters.biz Wed Aug 25 02:45:52 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Wed, 25 Aug 2004 02:45:52 -0400 Subject: python raw strings? In-Reply-To: <412bc766$1@news.unimelb.edu.au> References: <412bc766$1@news.unimelb.edu.au> Message-ID: <2p2qlvFf8nuhU1@uni-berlin.de> Maurice LING wrote: > What are python raw strings and how are they different from regular > strings? First of all, a minor semantic correction. A string is not raw or non-raw; a string can be expressed using raw syntax, but it's just a different way of writing the same thing. Now, in Python, strings can be written with special sequences involving backslashes; for instance, "\n" means a line break instead of a backslash and an n. If you want a literal backslash followed by an n, you need to use two backslashes: "\\n". If you need to use a lot of backslashes, doubling them up can get very annoying. The raw string syntax fixes that: r"\n" is a backslash followed by an n, not a line break. > In PLY, "+" is "r'\+'" but "-" is "r'-'", why is there an extra "\" in > "+"? When to use the extra "\" and when not? I don't have any experience with PLY, but I'm guessing it uses regular expressions (http://python.org/doc/current/lib/re-syntax.html). In a regular expression, + means something special; if you don't want the special meaning, you need to put a backslash in front of it. The minus sign, on the other hand, has no special meaning in regular expressions (well, outside of character sets), so it can be used on its own with no backslash. From mwh at python.net Thu Aug 12 06:48:03 2004 From: mwh at python.net (Michael Hudson) Date: Thu, 12 Aug 2004 10:48:03 GMT Subject: The winner of the Python Decorator Poll is... References: <4edc17eb.0408112052.1bbd85b3@posting.google.com> Message-ID: Andrew Durdin writes: > On 11 Aug 2004 21:52:03 -0700, Michele Simionato > wrote: > > > > Indeed. Actually I did not vote since I like the current proposal (maybe > > I would like "|" more than "@") and I dislike all the alternatives, > > especially having decorators inside the def. > > Since you like the current proposal, why *didn't* you vote for it (it > was the first one)? I didn't vote in the poll (or indeed read the first thread about it) because I think polls are a very bad way of deciding things like this. Cheers, mwh -- For their next act, they'll no doubt be buying a firewall running under NT, which makes about as much sense as building a prison out of meringue. -- -:Tanuki:- -- http://home.xnet.com/~raven/Sysadmin/ASR.Quotes.html From pm_mon at yahoo.com Mon Aug 16 06:38:10 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Mon, 16 Aug 2004 06:38:10 -0400 Subject: AntiDecorator metaclass In-Reply-To: References: <411dfe05$0$6142$626a14ce@news.free.fr> Message-ID: Anthony Baxter wrote: > On Sat, 14 Aug 2004 08:15:43 -0400, Paul Morrow wrote: > >>No I don't want to say that. I want to say that decorators should keep >>their nose out of the classmethod/staticmethod business. > > > So what's the point of this, then? You say it's an "anti-decorator" metaclass. > It's not. It's simply a way to automagically invoke a couple of standard > decorators from a metaclass, based on people following a convention. > > It does little or nothing to address many of the other requirements for > decorators, is brittle (see my previous post on the subject) and relies on > something that is merely a convention, and deliberately so. > The class was named a little prematurely, but the point was to show that decorator syntax wasn't needed for static or class method declarations as simply following a convention does the job just fine. Just as it does for private and semi-private methods. Are we planning on keeping that convention? Or will we be phasing that out in favor of a method visibility decorator? > >>And it makes the problem space that >>decorators address smaller (as it becomes everything you want decorators >>to do minus the classmethod/staticmethod stuff), which might give rise >>to a better, less objectionable solution. > > > I fail to see how your hack, which merely removes two of the most trivial > examples of decorator use, addresses anything in the general case. > It doesn't, yet. Again, this is only targeting method types at the moment. > As far as a "better, less objectionable solution" - as I've said time and time > again, this subject has had 2+ years of discussion. Do you honestly > expect that 2 or 3 more weeks here or there is going to produce some > blinding flash of insight? I'd love it to be true, but really, I can't see it. We're about to do something to the language that will make it less readable and more intimidating. That's bad. So maybe if we limit the scope of what decorators need to do, they won't be used that often. And that would be good. From fuzzyman at gmail.com Wed Aug 18 08:57:59 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 18 Aug 2004 05:57:59 -0700 Subject: ClientCookie References: <6f402501.0408110018.1e4e5ca8@posting.google.com> <6f402501.0408120352.680496bc@posting.google.com> <87ekmcp13g.fsf@pobox.com> Message-ID: <6f402501.0408180457.70df82e3@posting.google.com> jjl at pobox.com (John J. Lee) wrote in message news:<87ekmcp13g.fsf at pobox.com>... > fuzzyman at gmail.com (Michael Foord) writes: > [...] > > Ok, I've got somewhere. > > I'm now using the 0.9 version and I found the debugging section in the > > docs. > > > > I'm using the example from the docs - but I'm pickling a list of the > > pickles rather than using the load and save methods (as the docs > > suggest) because I get an NotImplemented error for the save method (so > > what use is the load method ?). > > I suppose you're trying to use FileCookieJar. That's an abstract base > class. In other words, you're not supposed to use it directly. > You're supposed to use one of its subclasses, such as LWPCookieJar, > MSIECookieJar or MozillaCookieJar. The standard meaning of > NotImplementedError is not "oops, I haven't got round to that", but > rather "don't do that; use a subclass instead". No - I was following hte docs - which just shows CookieJar IIRC :-) Now that I'm using LWPCookieJar everything is wonderful and works fine... I'm nopw learning about cookies and authentication.... Many Thanks Fuzzyman http://www.voidspace.org.uk/atlantibots/pythonutils.html From dd55 at cornell.edu Tue Aug 24 19:51:11 2004 From: dd55 at cornell.edu (Darren Dale) Date: Tue, 24 Aug 2004 19:51:11 -0400 Subject: Book Recommendation In-Reply-To: References: Message-ID: Anthony Greene wrote: > I'm new to programming entirely, and I'm simply looking for some insight, > can you guys recommend some introductory documentation for me to read, and > what I read, and, do concurrently why reading the primary "book" ou guys > recommend. Thanks, and any advice is great appreciated. O'reilly's Learning Python was essential for me. I knew some Matlab already, but I think it would still be the right place to start. There is a lot of stuff on-line, but this book helped me get up to speed much more quickly. From dave.opstad at agfamonotype.com Wed Aug 18 10:41:50 2004 From: dave.opstad at agfamonotype.com (Dave Opstad) Date: Wed, 18 Aug 2004 07:41:50 -0700 Subject: age of Python programmers References: Message-ID: In article , "Lucas Raab" wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... I'm 50, and have been programming since LBJ was in the White House. Python is a real breath of fresh air, and I'm delighted that my employer is letting me use it for essentially all my work. Python fits my brain. Dave From chrisb at microgaming.com Mon Aug 23 15:50:43 2004 From: chrisb at microgaming.com (Chris Becke) Date: Mon, 23 Aug 2004 21:50:43 +0200 Subject: decompyle available anywhere? Message-ID: There used to be a module, decompyle, that decompiled .pyc files up to version 2.2 of python. Decompyle for 2.3 is now a paid for web service and the 2.2 decompyle seems to have been yanked. Is there some site out there still hosting it? Preferably a win32 version, but I guess beggars can't be choosers. Thanks Chris. From ptmcg at austin.rr._bogus_.com Fri Aug 13 21:51:55 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Sat, 14 Aug 2004 01:51:55 GMT Subject: Arranging a dependency tree References: <6ccff37a.0408111831.6eb25a4e@posting.google.com> Message-ID: <%eeTc.9526$MD.3509@fe1.texas.rr.com> "Kyle Root" wrote in message news:6ccff37a.0408111831.6eb25a4e at posting.google.com... > I'm working on a little practice program, but I've become stuck and am > now utterly confused :? > > I've created a jumble of python modules, in each one is a tuple that > goes something like, > > deps = ("file10","file7","file3"). > > And some have no dependencies at all. I have one file called "start", > and the whole thing makes a tree of dependencies as each file has deps > and their deps might have deps, and so on. What I'm trying to do is > "straighten" them or put them in order as if they were to be > installed. Basically I'm trying to replicate the way portage does it. > :) > > I've been thinking about this for a few days but I always get lost. > So far I have a has_deps(filename) function, and not much else. I get > stuck on the actual changing the files from the random jumble to a > into a nice orderly list of files. One problem that I can't > overcome is when I'm a couple of deps in and I finally get to the > files that don't require anything, I have no way of getting back to do > the parent file's other deps. (Does that make any sense?) > > Basically I was wondering if anyone had any tips or pointers, or knew > of any dependency resolving algorithms... > > Thanks, > Kyle Look into using pydot if you want to actually draw the trees/graphs. -- Paul From jepler at unpythonic.net Tue Aug 31 10:28:26 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 31 Aug 2004 09:28:26 -0500 Subject: Changing the decimal separator to a comma In-Reply-To: <46e5cff0.0408310612.6bb1a610@posting.google.com> References: <46e5cff0.0408310612.6bb1a610@posting.google.com> Message-ID: <20040831142826.GC7876@unpythonic.net> Nothing changes the way that %-formatting works. However, after calling locale.setlocale, locale.format should give you a proper localized number: >>> import locale >>> locale.setlocale(locale.LC_ALL,"de_DE") 'de_DE' >>> locale.format("%10.2f", 0.123) ' 0,12' >>> locale.format("%10.2f", 1234.567) ' 1234,57' >>> locale.format("%10.2f", 1234.567, grouping=True) ' 1.234,57' Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From alexis.roda at urv.es Mon Aug 23 05:48:19 2004 From: alexis.roda at urv.es (Alexis Roda) Date: Mon, 23 Aug 2004 11:48:19 +0200 Subject: esoteric question about dict keys (Re: age of Python programmers) In-Reply-To: <5a309bd30408200505375a0056@mail.gmail.com> References: <4125D015.9090204@urv.es> <5a309bd30408200505375a0056@mail.gmail.com> Message-ID: <4129BD63.6000909@urv.es> Steve wrote: >>If I write my own dictionary-like >>object, on wich the mutability of the keys is not a technical issue, is >>considered blasphemous the use of dicts as keys? For example, querying >>an SQL table can be partially modelled as a dictionary access: > My first intention when thinking on dicts as keys was to avoid problems when working with tables with compound primary keys: table[('value1', 'value2')] or it was table[('value2', 'value1')] ? table[{'pkey1':'value1', 'pkey2':'value2'}] is less error prone since it states what field a value is related to I've so obsessed with dicts that I've not realized that I can achieve the same with tuples: table[(('pkey1', 'value1'), ('pkey2', 'value2'))] although, as pointed by Adrew, a method with named parameters looks cleaner. > ...but the whole point of having keys is to uniquely identify a > record, so table[] should always return *one* uniquely keyed > object. in the case I perform an arbitrary query on the table, a tuple (of records) can be considered as *one* uniquely keyed object? Thanks Steve and Andrew -- //// (@ @) ----------------------------oOO----(_)----OOo-------------------------- <> Ojo por ojo y el mundo acabara ciego /\ Alexis Roda - Universitat Rovira i Virgili - Reus, Tarragona (Spain) ----------------------------------------------------------------------- From ayose.cazorla at hispalinux.es Thu Aug 19 07:40:26 2004 From: ayose.cazorla at hispalinux.es (Ayose) Date: Thu, 19 Aug 2004 12:40:26 +0100 Subject: multi-instance and classic singleton design patterns In-Reply-To: References: Message-ID: <20040819114025.GA11950@setepo.gotdns.org> On Wed, Aug 18, 2004 at 02:54:05PM -0700, Neil Zanella wrote: > > #include > > class B { > public: > B() { } > void foo() const { > std::cout << x << std::endl; > } > void bar() { > std::cout << y++ << std::endl; > } > private: > static const int x = 0; > static int y; > }; > > int B::y = 1; > > int main() { > B().foo(); > B().bar(); > B().foo(); > B().bar(); > B().bar(); > } Try with class B: x = 0 def foo(self): print B.x def bar(self): B.y += 1 print B.y B.y = 1 if __name__ == '__main__': B().foo() B().bar() B().foo() B().bar() B().bar() -- Ayose Cazorla Le?n Debian GNU/Linux - setepo From grv575 at hotmail.com Tue Aug 31 00:52:42 2004 From: grv575 at hotmail.com (grv575) Date: 30 Aug 2004 21:52:42 -0700 Subject: numarray speed question References: <953AD3D0Didtoken@128.91.2.239> <953C4DD4idtoken@128.91.2.239> <144d0df.0408070828.338f8c19@posting.google.com> <9540516Didtoken@128.91.2.239> <144d0df.0408251616.5758d6e7@posting.google.com> Message-ID: <144d0df.0408302052.6ec457c9@posting.google.com> Great that cleared up that discrepancy between the source and the code I'm translating to. I think I've tried all the libraries though, numarray.fft, numarray.fftpack, scipi's fft module. I've even got the install script for scipi to tell me it found fftw modules so I'm pretty sure it was using them, but I'm getting the same speeds for each module...and the code _should_ be about 10x faster (compared to C/fortran/etc.) They really should better document exactly how to get fast ffts up and running under these number packages. cookedm+news at physics.mcmaster.ca (David M. Cooke) wrote in message news:... > At some point, Tim Hochberg wrote: > > grv575 wrote: > > > > Is it possible to do single precision ffts in numarray or > >> no? > > > > I believe so, but I'm not sure off the top of my head. I recommend > > that you ask on numpy-discussion > > or peek at the > > implementation. It's possible that all FFTs are done double precision, > > but I don't think so. > > Looks like the numarray.fft package uses doubles. > > If you really need floats, SciPy wraps the single- and > double-precision versions of FFTW. (Although SciPy uses Numeric, not > numarray). > > Or, you can make your own version of numarray.fft using floats > (actually looks to relatively simple to do). From fumanchu at amor.org Thu Aug 26 11:11:53 2004 From: fumanchu at amor.org (Robert Brewer) Date: Thu, 26 Aug 2004 08:11:53 -0700 Subject: Call for signatories for J2 Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E7F@exchange.hqamor.amorhq.net> Paul McGuire wrote: > "12 @ $1.50" is shorthand for "12 at $1.50 per item" was what > I meant to say > before I was interrupted! > > "per" as a Latin word would help its adoption beyond English-speaking > regions. It's meaning as "by" is consistent with the > decorator notion that > foo() is modified _by_ the decorator methods before it is > fully defined. > > And Alex cites "per"s three-letter-ness, as a nice parallel to the > corresponding "def". I think I can mention that "per" has multiple advocates now (without alterting the document so much that we would need to re-sign). But that's about all I can do at this point. :/ Robert Brewer MIS Amor Ministries fumanchu at amor.org From brianc at temple.edu Tue Aug 31 13:50:24 2004 From: brianc at temple.edu (brianc at temple.edu) Date: Tue, 31 Aug 2004 13:50:24 -0400 Subject: Converting integers to english representation Message-ID: Hello All, I'm developing a system to parse and enumerate addresses. The current obstacle is numbered streets. Does anybody know of a module already written to convert integers to their english equivalents? Example: 1ST -> FIRST SECOND -> 2ND or even something like this: 1 -> ONE TWO -> 2 There's something similar in the dive into python book with roman numerals. http://diveintopython.org/unit_testing/index.html Anything towards that direction would greatly help and save me a lot of time then from starting from scratch. Thank you in advance. -Brian From aleaxit at yahoo.com Fri Aug 27 09:52:48 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 27 Aug 2004 15:52:48 +0200 Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> <1gj4fb5.607xsc51izh8N%aleaxit@yahoo.com> <7xllg25lkt.fsf@ruckus.brouhaha.com> <1gj4u3a.12ttba9fynd6uN%aleaxit@yahoo.com> <1gj5bp4.qhup8tldmvebN%aleaxit@yahoo.com> <7xk6vlgemp.fsf@ruckus.brouhaha.com> <1gj6eil.hgzr1l125qaomN%aleaxit@yahoo.com> Message-ID: <1gj6n23.vnzqrh1unc1qfN%aleaxit@yahoo.com> Antoon Pardon wrote: ... > > You think one way, GvR thinks another, and in Python GvR wins. Go > > design your own language where what you think matters. > > Why the fuss over the chosen decorator syntax if GvR > wins anyhow. Why don't you go tell all those people > arguing decorator syntax that they should design their own > language where what they think matters. Because in this case, specifically, the decision is explicitly considered "not definitive yet". Alpha versions get released _specifically_ to get community feedback, so a controversial innovation gets a chance to be changed if the community can so persuade Guido. I do not know if you're really unable to perceive this obvious difference, or are just trying to falsely convince others that you're as thick as that; in this like in many other cases in this thread, if you're pretending, then you're doing a good job of it, because you're quite close to convincing me that your perception _is_ truly as impeded as it would appear to be. > > If you think I shouldn't voice an opinion here because GvR > wins anyhow and my opinion won't matter fine. Just say so > from the beginning. Don't start with pretending that you > have good arguments that support the status quo because > all that matters is that GvR prefers it this way. > All good arguments in support are just a coincidence in > that case. I do think, and I have indeed "stated so from the beginning" (many years ago), that it's generally a waste of time and energy for people to come charging here criticizing Python's general design and demanding changes that won't happen anyway. There are forums essentialy devoted to debates and flamewars independenlty of their uselessness, and this newsgroup is not one of them. People with normal levels of perceptiveness can see the difference between such useless rants, on one side, and, on the other, several potentially useful kinds of discourse, that I, speaking personally, do indeed welcome. Trying to understand the design rationale for some aspect of the language is just fine, for example -- and that's because trying to understand any complicated artefact X is often well served by efforts to build a mental model of how X came to be as it is, quite apart from any interest in _changing_ X. You may not like the arguments I present, but I'm not just "pretending" that they're good, as you accuse me of doing: many people like them, as you can confirm for yourself by studying the google groups archives of my posts and of the responses to them over the years, checking out the reviews of my books, and so on. If you just don't like reading my prose, hey, fine, many others don't particularly care for it either (including Guido, mostly;-); I'll be content with being helpful to, and appreciated by, that substantial contingent of people who do like my writing. And so, inevitably, each and every time I return to c.l.py, I find some people who might be engaging in either kind of post -- the useful "trying to understand" kind, or the useless "criticizing what you cannot change" one -- and others who are clearly just flaming. And inevitably I end up repeating once again all the (IMHO) good arguments which (IMHO) show most criticisms to be badly conceived and most design decisions in Python to be consistent, useful, helpful and well-founded. Why? Because this is a _public_ forum, with many more readers than writers for most any thread. If these were private exchanges, I'd happily set my mail server to bounce any mail from people I know won't say anything useful or insightful, and good riddance. But since it's a public forum, there are likely to be readers out there who ARE honestly striving to understand, and if they see unanswered criticisms they may not have enough Python knowledge to see by themselves the obvious answers to those criticisms -- so, far too often, I provide those answers, as a service to those readers out there. I would much rather spend this time and energy doing something that's more fun and more useful, but it's psychologically difficult for me to see some situation that can obviously use some help on my part, and do nothing at all about it. Maybe one day I'll be psychologically able to use killfiles more consistently, whenever I notice some poster that I can reliably classify as a useless flamer, and let readers of that poster's tripe watch out for themselves. But still I find it less painful to just drop out of c.l.py altogether when I once again realize I just can't afford the time to show why every flawed analysis in the world IS flawed, why every false assertion in the world IS false, and so on -- and further realize that there will never be any shortage of people eager to post flawed analysis, false assertions, and so on, to any public forum. > >> I don't see that much difference in the frustration of having > >> to write: > >> > >> t = f(x) > >> v[t] = v[t] + 1 > > > > You're repeating (necessarily) the indexing operation, which may be > > unboundedly costly for a user-coded type. > > That repetion is just pythons inabilty to optimise. There being, in general, no necessary correlation whatsoever between the computations performed by __getitem__ and those performed by __setitem__, the repetition of the indexing operation is (in general) indeed inevitable here. Python does choose not to hoist constant subexpressions even in other cases, but here, unless one changed semantics very deeply and backwards-incompatibly, there's nothing to hoist. ((note carefully that I'm not claiming v[t] += 1 is inherently different...)) > > >> and the frustration of having to write > >> > >> lst = f(x) > >> lst.sort() > >> lst.reverse() > > > > Here, no operation is needlessly getting repeated. > > Yes there is, the operation to find lst from the local dictionary. > Although it wont be unboundedly costly. If you're thinking of a virtual machine based on a stack (which happens to be the case in the current Python), you can indeed imagine two repeated elementary operations, in current bytecode LOAD_FAST for name 'lst' and POP_TOP to ignore the result of each call -- they're extremely fast but do indeed get repeated. But that's an implementation detail based on using a stack-based virtual machine, and therefore irrelevant in terms of judging the _language_ (as opposed to its implementations). Using a register-based virtual machine, name 'lst' could obviously be left in a register after the first look-up -- no repetition at all is _inherently_ made necessary by this aspect of language design. > > Still, I'm much happier thinking of you busy designing your own > > wonderful language, than wasting your time and yours here, busy > > criticizing what you cannot change. > > If you don't want to waste time, just state from the beginning > that this is how GvR wanted it and people won't be able to > change it. > > You shouldn't start by arguing why the language as it is is as > it should because that will just prolong the discussion as > people will give counter arguments for what they think would > be better. If you know that, should people not be persuaded > by your arguments, you will resort to GvR autority and declare > the arguments a waste of time, you are better of puttings > GvR autority that can't be questioned on the table as soon > as possible. On the other hand, _reasonable_ readers (and there are some, as shown by the various feedback on my work that I have referred to in previous parts of this post) can benefit by a presentation of the _excellent_ reasons underlying Python's design, and such readers would be badly served if the flawed arguments and false assertions presented to justify some criticisms of Python were left unanswered. Alex From nicolas.wang at gmail.com Thu Aug 5 21:57:15 2004 From: nicolas.wang at gmail.com (Yu Wang) Date: 5 Aug 2004 18:57:15 -0700 Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) References: Message-ID: I'm not an active guy in the groups.But I do agree with Mike. If there is a vote. I'll vote for this reply. Please consider a more elegant way. Michael Ressler wrote in message news:... > On 2004-08-04, Delaney, Timothy C (Timothy) wrote: > > Christopher T King wrote: > > > >> On 4 Aug 2004, Nick Vargish wrote: > >> > >>> I just don't know where else to voice my opinion on this matter, but > >>> I absolutely hate the new decorator syntax. > > > > @classmethod > > def func (args): > > @attr = 1 > > pass > > I'm just a dumb user of Python - I don't even program for a living, so > there is no reason any of you should listen to me, but this @-syntax > thing makes Python look like Perl. The reason I learned Python was that > Perl looks like line noise to me, and I wanted a scripting language I > could read. Please don't wreck a beautiful, readable language with this > shortcut. Choose a word for it, not a symbol, please. > > Mike From jeff at ccvcorp.com Fri Aug 27 21:58:00 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 27 Aug 2004 18:58:00 -0700 Subject: allowing braces around suites In-Reply-To: <1rpt5ccbso.fsf@rovereto.ifi.uio.no> References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1ry8k0d2az.fsf@rovereto.ifi.uio.no> <10iv0kid2ig9ka6@corp.supernews.com> <1rpt5ccbso.fsf@rovereto.ifi.uio.no> Message-ID: <10ivpk9inpnh65@corp.supernews.com> Kjetil Torgrim Homme wrote: >[Jeff Shannon]: > > >> The irony of [this] being said in defense of adding braces (even >> optional ones) to Python is truly awe-inspiring. >> >> > >please provide an argument rather than engage in ad hominem attacks. > > One of the core concepts of Python philosophy is that of significant indentation being more reliable than braces to indicate program structure. The whole point of using indentation is that it's far more natural for the human eye and mind to grasp; when one sees code in which braces and indentation are used, but inconsistently, the natural inclination is to follow the indentation rather than the braces. The problem is that programmers have been trained for decades to use delimiters, because that's the way languages were designed, because earlier parsers had difficulty without them. But programmers have *also* used indentation the whole time, because they needed it so that *they* could understand their own code. The indentation is for the programmers, the braces are for the compiler. Well, parser technology has advanced to the point where hints like braces aren't needed, but many programmers are so accustomed to having them that they keep looking for excuses to keep them around. There are endless examples, as I said, of how inconsistently indented C code is far more confusing than braceless Python code. Now, admittedly, your proposal here won't allow braces and indentation to be inconsistent -- that'll throw a syntax error. But that means that you're encoding the same information in two ways, which is a waste of effort and a waste of mindspace. This isn't just providing more than one way to do it; this is providing two ways to do it, and insisting that even if you use the second you need to *also* use the first. That's like Amazon providing an online order form, but still insisting that you phone in your order before they'll deliver it. Now, what do you gain by adding braces? The ability of tools to better reindent code, supposedly. But I have to say, using block-indent and block-dedent commands, I've never had a difficult time with maintaining proper relative indentation of cut-and-pasted code blocks. I don't see the problem you're trying to solve, I'm not aware of it being a significant problem throughout Python's 10+ year history, and I honestly doubt that your "solution" would provide much significant benefit. So... you're proposing a significant change to the core language syntax, which violates a number of Python core design principles, in order to simplify the process for a tool to perform an infrequent task, which it's quite capable of doing in a slightly different way already. And yet, when someone else comments that the same lack-of-results can be accomplished with a currently legal (though pointless) bit of convention, you're worried that *they* are proposing something non-Pythonic? Note, also, that this is not an ad hominem attack. I say nothing about you personally -- my comments are based entirely on the proposal and argument that you put forward. I'm not calling you names or questioning your morals; I'm merely pointing out that your complaint about Jacek's response can be applied far more aptly to your own original post. Jeff Shannon Technician/Programmer Credit International (PS: I'm going to be away from the newsgroup for the weekend, so lack of an immediate response on my part shouldn't be taken to construe anything significant...) From peter at engcorp.com Thu Aug 12 00:28:18 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 12 Aug 2004 00:28:18 -0400 Subject: The winner of the Python Decorator Poll is... In-Reply-To: References: Message-ID: Doug Holton wrote: > Which decorator syntax do you like the most? See > http://wiki.wxpython.org/index.cgi/PythonDecoratorsPoll > A. @classmethod def foo(): (82) 14% > C1. def foo() [classmethod]: (235) 41% > E1. def foo(): @classmethod (260) 45% > > Total Votes: 577 > > People are about 6 to 1 against having the decorators come before the > "def" keyword. While I voted in that poll, and in fact voted for one of the two "after" methods (I forget which, doesn't matter), I want to point out the danger of extrapolating from the poll results to unsubstantiated claims such as the one you make. The poll results show that by a ratio of 6 to 1, people who voted prefer either of the second two options to the first one. Nothing more, nothing less. The poll didn't mention that it was a choice between before and after, and therefore you shouldn't make assumptions about what was in the minds of those voting. For example, had the "decorate:" option that recently evolved from discussion in this forum been present, I would have preferred it over any of the methods show above. That's because I'm not religious about the before or after thing so much as I am over the punctuation and Pythonic-style issues. The "decorate:" option is the closest fit with Python style, IMHO, even more so than list-after-def, and even the fact that it comes before the def doesn't bother me since the indented block structure feels very similar to other such constructs in Python. And I'm sure I'm not alone, but nobody's done a poll on it yet. ;-) -Peter From ptmcg at austin.rr._bogus_.com Wed Aug 25 08:43:00 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Wed, 25 Aug 2004 12:43:00 GMT Subject: Is it a bug (or a feature)? References: Message-ID: "Roman Suzi" wrote in message news:mailman.2348.1093434827.5135.python-list at python.org... > > In Python2.3.4: > > >>> em = email.message_from_file(open('MAILMESSAGE')) > >>> for i in em: > ... print i > ... > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/lib/python2.3/email/Message.py", > line > 304, in __getitem__ > File "/usr/lib/python2.3/email/Message.py", > line > 370, in get > AttributeError: 'int' object has no attribute 'lower' > > However items() does work: > > >>> for i in em.items(): > ... print i > ... > ('Date', '24 Aug 2004 16:06:01 +0400') > ('From', 'Mail System Internal Data ') > ('Subject', "DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA") > ('Message-ID', '<1095549161 at mydomain.ru>') > ('X-IMAP', '1095527634 0000000005') > ('Status', 'RO') > > I can probably guess why this happens ('cause multiple fields with the > same names are possible), but .items() is broken by this... It needn't > be! > > > Sincerely yours, Roman A.Suzi > -- > - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru - > Looks like a bug to me. Message.__getitem__() makes a call to Message.get(), assuming that the argument passed in is a key name (such as 'Date', 'From', etc. from your example). __getitem__ should first check to see if the input argument (named 'name', further indication that this method was written to expect only strings) is an integer or slice, and if so, just return self._headers[name]. -- Paul From davidf at sjsoft.com Tue Aug 24 05:05:18 2004 From: davidf at sjsoft.com (David Fraser) Date: Tue, 24 Aug 2004 11:05:18 +0200 Subject: apache configuration tool In-Reply-To: References: Message-ID: Stephan Diehl wrote: > Is there something similar to the PERL > Apache::Admin::Config module > out there that is written in Python? > > Stephan No idea what that module does. But I've got a module that might get include with mod_python that lets you make simple changes to an apache conf file David From squirrel at WPI.EDU Mon Aug 16 10:55:40 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Mon, 16 Aug 2004 10:55:40 -0400 Subject: Python indentation deters newbies? In-Reply-To: References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: On Mon, 16 Aug 2004, Peter Hansen wrote: > What I doubt is that many of those people are out there rejecting Python > just because it doesn't let them write god-awful unreadable code with > artistic or random indentation. Imagining ee cummings coding Python: import sys def main ( ) : myfile = open ( s y s . a r g v [ 1 ] ) myfile . write(' hello world ')myfile. c l o s e ()main() From Jeffrey at Fro.man Sun Aug 22 15:46:11 2004 From: Jeffrey at Fro.man (Jeffrey Froman) Date: Sun, 22 Aug 2004 12:46:11 -0700 Subject: Getting benifits of database transactions in an OO way? References: <2oq8pmFdd2nfU1@uni-berlin.de> Message-ID: Leif K-Brooks wrote: > I'm coding an application which makes extensive use of a PostgreSQL > database. To make code clearer, I'm wrapping various row types in > objects. You might want to take a look at http://sqlobject.org (transaction examples provided in the documentation as well.) Jeffrey From del at mjclift.freeserve.co.uk Fri Aug 13 00:33:24 2004 From: del at mjclift.freeserve.co.uk (Calvin79) Date: Fri, 13 Aug 2004 00:33:24 -0400 Subject: while and if Message-ID: Hi, I'm very new to python, but believe in learning from examples. So could someone please help me with this? I choose a number of 'things' I want Number = input("Number of things (1-8)? ") things = ['1', '2', '3', '4', '5', '6', '7',\ '8'] >From there I want to take at random a letter and do this n times depending on the number I gave. choice = choice('abcd') The final answer if say the number had been 5 to look something like; choice 1 = d choice 2 = c choice 3 = a choice 4 = d choice 5 = b etc... I can sort of see how to use the while loop for int but not to keep choosing from the list and lable it choice 1 etc... Thanks for any help, Calvin From fuzzyman at gmail.com Mon Aug 23 10:40:30 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 23 Aug 2004 07:40:30 -0700 Subject: ClientCookie References: <6f402501.0408110018.1e4e5ca8@posting.google.com> <6f402501.0408120352.680496bc@posting.google.com> <87ekmcp13g.fsf@pobox.com> <6f402501.0408180457.70df82e3@posting.google.com> <87llgbt2mh.fsf@pobox.com> Message-ID: <6f402501.0408230640.6d2527e4@posting.google.com> jjl at pobox.com (John J. Lee) wrote in message news:<87llgbt2mh.fsf at pobox.com>... > fuzzyman at gmail.com (Michael Foord) writes: > > jjl at pobox.com (John J. Lee) wrote in message news:<87ekmcp13g.fsf at pobox.com>... > [...] > > No - I was following hte docs - which just shows CookieJar IIRC :-) > > Now that I'm using LWPCookieJar everything is wonderful and works fine... > [...] > > Whoops, sorry. Where is this mistake in the docs? I don't see it. > > > John Right... I'm using the document that starts : ClientCookie Note: this page describes the 0.9.x development version. See here for the stable 0.4.x version. There is no mention of LWPCookieJar *anywhere* in the docs. In the debugging section it talks about using the load and save method and gives a specific example involving the straight CookieJar class....... : When you .save() to or .load()/.revert() from a file, single-session cookies will expire unless you explicitly request otherwise with the ignore_discard argument. This may be your problem if you find cookies are going away after saving and loading. import ClientCookie cookies = ClientCookie.CookieJar() opener = ClientCookie.build_opener(ClientCookie.HTTPCookieProcessor(cookies)) ClientCookie.install_opener(opener) r = ClientCookie.urlopen("http://foobar.com/") cookies.save("/some/file", ignore_discard=True, ignore_expires=True) These are the docs that came with my download............... LWPCookieJar - works fine.... but I'd never heard of it until you mentioned it. Regards, Fuzzy http://www.voidspace.org.uk/atlantibots/pythonutils.html From pink at odahoda.de Tue Aug 24 18:07:22 2004 From: pink at odahoda.de (Benjamin Niemann) Date: Wed, 25 Aug 2004 00:07:22 +0200 Subject: Macro expansion: intercept statement interpretation In-Reply-To: References: Message-ID: Benjamin Niemann wrote: > You could try to override __import__ to first parse the source for macro > definitions and do the expansions. Usage would then be: > > import DoMagicWithImportModule > import ModuleWithMacros > > (Your code wouldn't work, because python throws a SyntaxError long > before it even tries to execute 'import MyCustomMacroLib') > The code at http://docs.python.org/lib/examples-imp.html could be > extended to first read the contents of the module (after find_module) > and passes the expanded source (e.g. as a StringIO) to load_module. > > This has of course the problem (that many implementations of macro > expansion share) that line numbers in exception dumps have not much > relation to lines of the unexpanded code... If this actually works, a nice application could be rapid prototyping of syntax extensions to python ('import this module and you can test and see why my decorator syntax is better than yours' ;) From Michael.J.Fromberger at Clothing.Dartmouth.EDU Sat Aug 21 21:38:01 2004 From: Michael.J.Fromberger at Clothing.Dartmouth.EDU (Michael J. Fromberger) Date: Sat, 21 Aug 2004 21:38:01 -0400 Subject: Overriding logical operators? References: Message-ID: In article , Andrew Durdin wrote: > In Python, you can override the behaviour of most operators for a > class, by defining __add__, __gt__, and the other special object > methods. > > I noticed that, although there are special methods for most operators, > they are conspicuously absent for the logical "or" and "and". I'm > guessing that the reason for this is that these operators > short-circuit if their first operand answers the whole question? > > Would it be possible to allow overriding the logical operators, with > the caveat that overriding it would prevent short-circuiting? The implementation of "and" and "or" are special, as others have pointed out. However, you do have some control over how they behave for objects of user-defined classes. By overriding __nonzero_, you can define whatever truth value you like for instances of a user-defined class. See: http://docs.python.org/lib/truth.html This would not, in itself, "override" the behaviour of "and" and "or", in the sense that you were describing, but it would let you control the outcome for objects of your particular class. -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From gandalf at geochemsource.com Wed Aug 18 08:04:39 2004 From: gandalf at geochemsource.com (Gandalf) Date: Wed, 18 Aug 2004 14:04:39 +0200 Subject: Platform independent way to play an mp3 file In-Reply-To: <1w9xnslz5154j.1es2d7zxju1hl$.dlg@40tude.net> References: <1w9xnslz5154j.1es2d7zxju1hl$.dlg@40tude.net> Message-ID: <412345D7.80804@geochemsource.com> >>Does anyone know a platform independent way to play an mp3 file from Python? >>I believe the standard library cannot do this. >> >> > >http://pymedia.sf.net > >maybe this library can help you > > Oh yes, I know about this. But it seems it is working on Linux and Windows only. I have Solaris, FreeBSD and AS/400 clients too. :-( -------------- next part -------------- An HTML attachment was scrubbed... URL: From squirrel at WPI.EDU Mon Aug 2 20:36:33 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Mon, 2 Aug 2004 20:36:33 -0400 Subject: Microbenchmark: Summing over array of doubles In-Reply-To: <4d642979.0408021551.586e1d1f@posting.google.com> References: <4d642979.0407312049.7a8aecab@posting.google.com> <4d642979.0408021551.586e1d1f@posting.google.com> Message-ID: On 2 Aug 2004, Yaroslav Bulatov wrote: > You are right, how silly of me! Fixing the script now results in 130 > millis mean, 8.42 millis standard deviation, which is slower than > numarray (104, 2.6 respectively). I wonder why numarray gives faster > results on such a simple task? The reason is that your C loop uses array indexing, whereas numarray's increments the array pointer on each iteration through the loop an forgoes any indexing. Even though this translates into about same number of opcodes on x86, the latter is slightly faster because it skips the (implied) bitshift operation. Also don't forget to compile your C version with -O3, as this can make a big difference in that little loop (maybe not in your case though). In principle, for simple access patterns like summation, etc., numarray will always be faster than your "typical" C implementation, since its core vector functions were designed to be very efficient. Of course, an efficient C implementation will be as fast or faster, but you'd have to use those efficiency tricks in every vector operation you perform, which could be quite tedious without writing your own library. (The above generaliztion of course only applies to very large arrays.) Either way, your results are quite promising -- they show that Python with numarray is as good or better than C when it comes to vector processing applications, all while being easier to use. That's good publicity! From jdc at uwo.ca Fri Aug 20 12:25:30 2004 From: jdc at uwo.ca (Dan Christensen) Date: Fri, 20 Aug 2004 12:25:30 -0400 Subject: Alternative decorator syntax decision References: <10ia1a9jm9tkuca@corp.supernews.com> <84GdneSa3r-TR7jcRVn-tw@powergate.ca> Message-ID: <87wtztixol.fsf@uwo.ca> J2 J2 J2 From mark_bottjer at hotmail.com Fri Aug 6 16:19:18 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Fri, 06 Aug 2004 16:19:18 -0400 Subject: @decorators In-Reply-To: References: Message-ID: <4113e7c7@nntp.zianet.com> Roy Smith wrote: > I really dislike the proposed syntax, for two main reasons. First, I > don't like the idea of inventing new uses for punctuation (down that > road lies perl). Eh. After print >>, it doesn't seem so bad :). And I *like* the fact that it doesn't look like a normal statement, because it *isn't* a normal statement. This could also be accomplished with a keyword, but I've yet to hear one that makes sense in all usages. > Second, I don't like the idea that you're creating a > contextual block which violates (or at least ignores) the normal > indenting rules. Bingo! That is my biggest problem with this syntax. If it were just moved inside the function definition, like the docstring, I'd be *so* much happier... > I'm also wondering about doc strings. Doc strings are really metadata, > and if the idea of decorators is to build a uniform way to handle > metadata, it would be nice to see it somehow include docstrings. I'm not sure docstrings need to change. The do what they do pretty well (though I'd like to be able to parse them a bit more easily). @dec isn't just about metadata, though: its about *any* sort of modification to the default function object def creates. Metadata is one of the more common uses, to be sure, but by no means the only one. In short, I see no need to bring the docstring into this. -- Mark From insert at spam.here Thu Aug 26 13:30:07 2004 From: insert at spam.here (Doug Holton) Date: Thu, 26 Aug 2004 12:30:07 -0500 Subject: Call for signatories for J2 In-Reply-To: References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> Message-ID: Tim Hochberg wrote: > I also have a weak preference for 'per' over 'using', FWIW. The > shortness of 'per' is one virtue. Another is that, because it's slightly > obscure, it may be easier to indoctrinate users that 'per...def' is the > correct order, not 'def...per'. For me at least it's 'obvious' that if > 'using...def' works then so should 'def...using', which of course it > can't. The order is amenable to memorization, but I still anticipate > more thinkos of this type from using than from per. On the downside, per > may be extremely obscure to those that are neither native speakers of > English or one of the romance languages. Even in common English usage, "per" usually comes in the middle of a phrase, not the beginning, like "miles per hour" or "Changes were made to the manuscript per the author's instructions" (people would more commonly use the phrase "according to" rather than "per" there). None of those uses bare any resemblance to how decorators affect functions. "per:" by itself on a line is pretty much meaningless. Looks more like you misspelled pre. If people are liking Latin keywords for decorators now, why not "sic"? From Andreas.Ames at tenovis.com Thu Aug 5 08:59:30 2004 From: Andreas.Ames at tenovis.com (Ames Andreas (MPA/DF)) Date: Thu, 5 Aug 2004 14:59:30 +0200 Subject: Decorator syntax Message-ID: <788E231C269961418F38D3E360D1652526CA1A@tndefr-ws00021.tenovis.corp.lan> Hi, Michael Ekstrand wrote: > def(staticmethod) somemethod(self, args): > some code could you or someone else please enlighten me, as someone who wasn't following the decorator syntax discussion, why this syntax was ruled out? It still (after looking up some of the discussed alternatives) seems to be the most appropriate to me, esp. since core changes seem to be acceptable to get a useful decorator syntax. tia, andreas From roy at panix.com Tue Aug 17 10:03:14 2004 From: roy at panix.com (Roy Smith) Date: Tue, 17 Aug 2004 10:03:14 -0400 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> <+zOIBls/Kj3Q089yn@the-wire.com> <5353i0l2qgl7c4jgskb0f0j5rkpgsd6aul@4ax.com> Message-ID: In article <5353i0l2qgl7c4jgskb0f0j5rkpgsd6aul at 4ax.com>, Dennis Lee Bieber wrote: > On Mon, 16 Aug 2004 13:21:02 -0400, mwilson at the-wire.com (Mel Wilson) > declaimed the following in comp.lang.python: > > > Column 72 is the last one available for statment text, > > according to this IBM 888157 card here. > > > Well, at least I didn't extend into the "sequence number" > field... It's been some 26 years since I last created a FORTRAN layout > drum card. I remember when I first found out about drum cards. That was cool. And people thing language-sensitive editors are something new, huh? From dyoo at hkn.eecs.berkeley.edu Thu Aug 26 14:35:18 2004 From: dyoo at hkn.eecs.berkeley.edu (Daniel Yoo) Date: Thu, 26 Aug 2004 18:35:18 +0000 (UTC) Subject: How to generically transform a list? References: Message-ID: Marco Aschwanden wrote: : Suppose you have a list of lists: : theList = [['a',1,11,'aa'], ['b',2,22,'bb'],['c',3,33,'cc']] : I would like to have a GENERIC way how to turn this list of list into : another list of list. : - A user can choose which columns she wants : - A user can select the order of the columns It sounds like you want something like the 'cut' Unix command. Here's one way to do it. ### def cut(iterable, columns): """Selects columns from the iterable.""" for row in iter(iterable): yield(tuple([row[i] for i in columns])) ### For example: ### >>> l = [['1', '2', '3'], ... ['a', 'b', 'c'], ... ['ka', 'na', 'da']] >>> >>> for row in cut(l, (2, 0, 1)): print row ... ('3', '1', '2') ('c', 'a', 'b') ('da', 'ka', 'na') >>> >>> for row in cut(l, (2, 1)): print row ... ('3', '2') ('c', 'b') ('da', 'na') ### Hope this helps! From jeffrey at I.slack Tue Aug 10 00:10:47 2004 From: jeffrey at I.slack (Jeffrey Froman) Date: Mon, 09 Aug 2004 21:10:47 -0700 Subject: decorators as a special case of an @ operator? References: <87llgocrgq.fsf@uwo.ca> Message-ID: <10hgim7min4gg55@corp.supernews.com> Peter Hansen wrote: > I believe those of us who prefer to see the name first really > prefer to see something we might call the definition (and > "def" is well-named here) which includes a sign that we are > defining a function, very near the name, and preferably with > the argument list also very close (since it is generally quite > important to a reader) For me, it's much more about the visual association of related statements. Whitespace is critical for visual association in Python, and having decorators floating above a definition absolutely wrecks the whole top-down indentation scheme. I could learn to get used to the '@', because that really *is* just a decorator, but having referential statements ride on top of a function definition *breaks* the way python reads. So I like Dan's idea as far as that goes, but in the same way I can also live with def f(): @decorator1 @decorator2 Jeffrey From richie at entrian.com Wed Aug 25 12:13:58 2004 From: richie at entrian.com (Richie Hindle) Date: Wed, 25 Aug 2004 17:13:58 +0100 Subject: Desperately needing Help with 2 features of a program In-Reply-To: References: Message-ID: [Justin] > 1. Update the label on a radiobox rb.SetItemLabel(3, "Richie's stuff") > 2. Create a downlaod status progress bar. (I guess this has to be > threaded, many attempts led to endless erros about not using the > proper thread to interact with the GUI) That's more than a one-liner. 8-) The Wiki page at http://wiki.wxpython.org/index.cgi/LongRunningTasks talks about this kind of problem at length, and includes a couple of alternatives to using threads. When using threading in a GUI, the number one rule is that only the main thread can access the GUI. Worker threads that want to update the GUI must do so by posting events to the main thread. The way a typical wxPython program does this is by defining its own event class and using wxPostEvent to post instances of that event class to the main thread. -- Richie Hindle richie at entrian.com From f.geiger at vol.at Thu Aug 5 14:46:55 2004 From: f.geiger at vol.at (F. GEIGER) Date: Thu, 5 Aug 2004 20:46:55 +0200 Subject: MySQLdb select References: Message-ID: "Gerhard H?ring" schrieb im Newsbeitrag news:mailman.1008.1091284523.5135.python-list at python.org... > That's particularly BAD STYLE. It's best to keep to letting the DB-API > do the proper quoting for all parameters. Well, yes. So I tried this: >>> import MySQLdb as ms >>> con = ms.connect(db="isa",user="root") >>> cur = con.cursor() >>> cur.execute("select id from %s limit 10;", ("tagevents",)) Traceback (most recent call last): File "", line 1, in ? File "C:\PROGRA~1\Python23\lib\site-packages\MySQLdb\cursors.py", line 95, in execute return self._execute(query, args) File "C:\PROGRA~1\Python23\lib\site-packages\MySQLdb\cursors.py", line 114, in _execute self.errorhandler(self, exc, value) File "C:\PROGRA~1\Python23\lib\site-packages\MySQLdb\connections.py", line 33, in defaulterrorhandler raise errorclass, errorvalue _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''tagevents' limit 10' at line 1") >>> Hmm, despite the fact, that it is bad style, I tried: >>> cur.execute("select id from %s limit 10;" % "tagevents") 10L >>> and succeeded. Looks like MySQL doesn't like the quoting, MySQLdb seems to perform. Okay, as you shouted to me "BAD STYLE" I presume, it had to work, if I only did it right. So, what am I doing wrong? Or did I misconfig MySQL? Is MySQL 4.0 not yet supported? My environment: Win XP Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 to server version: 4.0.20a-nt MySQLdb 1.0.0 Kind regards Franz GEIGER "Gerhard H?ring" schrieb im Newsbeitrag news:mailman.1008.1091284523.5135.python-list at python.org... > F. GEIGER wrote: > > "John Fabiani" schrieb: > > > >>Hi, > >> I'm a newbie and I'm attempting to learn howto create a select statement. > >>When I use > >> > >>>>>string1='18 Tadlock Place' > >>>>>cursor.execute("SELECT * FROM mytest where address = %s",string1) > >> > >>All works as expected. But > >> > >>>>>numb=10 > >>>>>cursor.execute("SELECT * FROM mytest where clientID = %d",numb) > >> [...] raise errorclass, errorvalue > >>TypeError: int argument required > >> > > Then use %i for integers ;-) > > > I'm used to do that this way: > > > > cursor.execute("SELECT * FROM mytest where clientID = %d" % numb) > > That's particularly BAD STYLE. It's best to keep to letting the DB-API > do the proper quoting for all parameters. > > -- Gerhard From dalcolmo at vh-s.de Thu Aug 12 03:29:58 2004 From: dalcolmo at vh-s.de (Josef Dalcolmo) Date: Thu, 12 Aug 2004 09:29:58 +0200 Subject: Rather than decorators, how about sections? References: Message-ID: <20040812092958.000052e2@titan> May I point out that the term "static" comes from its use in a particular language and is used for two semantically different purposes. I don't think the word reveals the meaning very well. I strongly suggest to use a different term, that describes better what it does. some ideas: instance - class noninheritable - inheritable specific - generic this - all (self, var) - (-, var) - Josef From sbabbitt at commspeed.net Mon Aug 2 20:14:21 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Mon, 2 Aug 2004 17:14:21 -0700 Subject: transforming a list into a string References: Message-ID: <1091493038.723672@news.commspeed.net> "jblazi" wrote in message news:pan.2004.07.31.12.27.23.547000 at hotmail.com... > Let us assume I have a list like > > ['1','2','7','8','12','13] > > and would like to transoform it into the string > > '{1,2},{7,8},{12,13}' > > Which is the simplest way of achiebing this? (The list is in fact much > longer and I may have to cut the resulting strings into chunks of 100 or > so.) > > TIA, > > jb > Heres a one-liner, >>>items = ['1','2','7','8','12','13'] >>>[(items[x],items[x+1]) for x in range(0,len(items)-1,2)] [('1', '2'), ('7', '8'), ('12', '13')] Tom From b.niemann at betternet.de Tue Aug 31 08:19:58 2004 From: b.niemann at betternet.de (Benjamin Niemann) Date: Tue, 31 Aug 2004 14:19:58 +0200 Subject: txt2xls In-Reply-To: <4edc17eb.0408310401.6abf866c@posting.google.com> References: <4edc17eb.0408310401.6abf866c@posting.google.com> Message-ID: Perhaps this could help you: http://sourceforge.net/projects/pyxlwriter/ Michele Simionato wrote: > In would like to convert very simple text files into .xls > files and I need some help. > > Here is the format of a typical file: > > # begin table.txt > > This should go in the first row, > first column. > > This should go in the first row, > second column. > > ==== > > This should go in the second row, > first column. > > This should go in the second row, > second column. > > ==== > > This should go in the third row, > first column. > > This should go in the third row, > second column. > > # end table.txt > > "====" separates different rows, whereas different colums are separated > by an empty line. table.txt should be converted into a table.xls > file containing a 3x2 table like this: > > ================================ ================================ > This should go in the first row, This should go in the first row, > first column. second column. > -------------------------------- -------------------------------- > This should go in the second row, This should go in the second row, > first column. second column. > -------------------------------- -------------------------------- > This should go in the third row, This should go in the third row, > first column. second column. > ================================ ================================ > > I use OpenOffice on Linux, but I have no experience at all about the .xls > format, so I would welcome help/pointers and especially snippets of code ;) > TIA, > > Michele Simionato From ajsiegel at optonline.com Mon Aug 23 10:07:42 2004 From: ajsiegel at optonline.com (Arthur) Date: Mon, 23 Aug 2004 14:07:42 GMT Subject: __name__ becoming read-write? Message-ID: Did I hallucinate something about __name__ becoming read-write? Not in alpha2. Can't find the reference to this I thought I read - that it was concluded to be necessary in connection with PEP318. Better get my facts straight first.... But if true that would seem to solve the main objection to: the_horrible_name_I _need_to_call=transform(__f) And would mean that a byproduct of the PEP318 implementation would go 50% toward obviating the need for a PEP318 implementation. At least by one measure. But the whole thing might be a hallucination. Art From kosh at aesaeion.com Fri Aug 13 15:23:14 2004 From: kosh at aesaeion.com (kosh) Date: Fri, 13 Aug 2004 13:23:14 -0600 Subject: Why I love python. In-Reply-To: References: <2o4divF6one2U1@uni-berlin.de> Message-ID: <200408131323.14210.kosh@aesaeion.com> On Friday 13 August 2004 12:33 pm, Nick Patavalis wrote: > On 2004-08-13, Reinhold Birkenfeld > Yes, that's exactly what I meant. The only solution in such a case > would be for the environment to call the compiler at run time, and > compile classobj then. This means of course that in such cases the > compiler must be included in the "executable". > Why is there a need for a stand alone executable? At least on all the unixes whether something is executable is just determined by the executable bit on the file. I can execute a python program just as transparently as one in compiled c, c++, etc. I really don't see the point of that. Overall I would rather that there was more reliance on runtimes and that psyco was improved to the point that it was just part of python and could save its jited versions of code for reuse later. That way I can upgrade libraries, the runtime etc and as long as the system is still source compatible the application would still work and it would speed up as it ran as things where compiled to optimized code as needed. Overall I think that standalone binaries are bad long term. I would prefer source compatibility since that is more flexible long term. With a jit the code should run just as fast but it would make things like security update and updating pieces of the system simpler. > I believe this has been done in other dynamic languages. > > Typed-extensions, as you mention, would also help. > > /npat From shane.holloway at ieee.org Wed Aug 11 18:16:51 2004 From: shane.holloway at ieee.org (Shane Holloway (IEEE)) Date: Wed, 11 Aug 2004 16:16:51 -0600 Subject: Question In-Reply-To: <002b01c47fdd$bf0c2280$4e01a8c0@dagan> References: <002b01c47fdd$bf0c2280$4e01a8c0@dagan> Message-ID: <411A9AD3.2020401@ieee.org> Dag, If you want to execute python-type statements, then you will want to use eval(). However, if your input is limited to smaller expressions, you can parse the input into pieces and then interpret them. So, what I'm saying is that you need to provide more information. What subset of eval's functionality do you need? Regards, -Shane Holloway Dag Hansteen wrote: > I make a GUI calculator in wxPython. > How can I do the following without having to use eval?: > > def OnCalc(self, event): > try: > regnestykke = self.formel.GetValue() > svar = eval(regnestykke) > svar = str(svar) > self.answer.SetValue(svar) > except: > self.answer.SetValue("Error! Check Syntax!") > > """ > self.formel is defined as wxTextCtrl for the input from user to be > calculated > self.answer is defined as wxTextCtrl for the answer of the users input > """ From ajsiegel at optonline.com Thu Aug 26 09:00:41 2004 From: ajsiegel at optonline.com (Arthur) Date: Thu, 26 Aug 2004 13:00:41 GMT Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: On Thu, 26 Aug 2004 21:05:46 +1000, Anthony Baxter wrote: > >def foo(): > __name__ = '%s_banana'%(__name__) > I'm not sure what you are driving at here, but ... Aa a practical matter, wouldn't it be nice to be able to use string substitution on a docstring placed in its usual location under def foo(). That I need to place my __doc__ under the function can't be considered a good thing, or intutive thing. Sort of like having to do transformations after and under the function ;) Art From lbates at swamisoft.com Fri Aug 20 18:59:18 2004 From: lbates at swamisoft.com (Larry Bates) Date: Fri, 20 Aug 2004 17:59:18 -0500 Subject: decorator J4 - any objections? References: Message-ID: If docstring can be a special case of a triple quoted string, I don't see why decorators couldn't be a special case of a dictionary. def func(arg1, arg2): {'version': 'Added in 2.4', 'returns': None, 'docstring': 'Docstring could be here, or in decorator part above'} """Docstring could be here, or in decorator part above""" or perhaps: def func(arg1, arg2): # # Similiar to class __dict__ # __decorators__=__{'version': 'Added in 2.4', 'returns': None, 'docstring': 'Docstring could be here, or in decorator part above'} """Docstring could be here, or in decorator part above""" I'm sure there is a reason, but it would seem to make "Python"-sense to me. It would then be very extensible for the meta-data that everyone seems to also want decorators to support. "Jim Jewett" wrote in message news:cab22418.0408201006.16f163b2 at posting.google.com... > Guido has said that he is open to considering *one* alternative > decorator syntax. At the moment, (Phillip Eby's suggestion) J4 > > (section 5.21 J4) > > looks very good to me -- and it is the only alternative without negatives. > > def func(arg1, arg2) > @version("Added in 2.4") > @returns(None) > as: > """Docstring could be here, or in decorator part above""" > # body goes here > > (Note the lack of colon on the func line; adding it would be more > consistent and not hurt readability.) > > def func(arg1, arg2): > @version("Added in 2.4") > @returns(None) > as: > """Docstring could be here, or in decorator part above""" > # body goes here > > While I think this is the best solution so far, I realize that others > have often disagreed with me on this issue -- so I would appreciate > some feedback, particularly from those who don't like the J4 syntax. > > Disclosure: I like decorators on their own, but they are enough of > a special case that I worry about cluttering up the language as a > whole. J4 seems the best compromise to me, but I could also make > peace with Guido's current @proposal. > > -jJ From deetsNOSPAM at web.de Wed Aug 18 06:21:20 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Wed, 18 Aug 2004 12:21:20 +0200 Subject: Swing/Metalworks for Python References: <41224ea4$1@news.broadpark.no> Message-ID: Gisle Vanem wrote: > I was quite impressed by this toolkit in the latest Java SDK 1.5 > (not sure if it's new in this version or not). But are there any similar > toolkits for Python that allows switching Look & Feel and Themes > in the same way? qt - free for *nixes, commercially available for windows. And the best toolkit I've worked with. -- Regards, Diez B. Roggisch From cy.fbp.eryvtvne at ncbybtrglxn.pbz Fri Aug 27 04:04:10 2004 From: cy.fbp.eryvtvne at ncbybtrglxn.pbz (JZ) Date: Fri, 27 Aug 2004 10:04:10 +0200 Subject: Mysql in Python? References: Message-ID: <1a0o0u8an8yhn$.1aby5k5hmj67d.dlg@40tude.net> 26 Aug 2004 11:45:12 -0700, na comp.lang.python, Simon John napisa?(a): > Probably the only thing keeping me with database coding in PHP instead > of Python is that it's so unclear what should be used for what! Using PHP native database functions is a very bad idea. All experencied programmers use more abstract db wrappers like ADOdb (http://adodb.sourceforge.net/). There is ADOdb version for Python as well. Other pythonic modules are DB-API2 compatible so there is no such mess like PHP native functions. > It's a similar thing for templating systems - there's too much choice, > and nothing has really become "the standard". I never thought I'd > complain about too much choice! There is no PHP standard templating system. PHP itself is a template framework! (although no one experienced want to use its mixing php and html mess). Check ezPublish, Invision Board, phpBB or others bigger projects. No one keep with one, standard template framework. -- JZ From fuzzyman at gmail.com Wed Aug 25 03:10:26 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 25 Aug 2004 00:10:26 -0700 Subject: Python and C, looking for a C IDE References: <6f402501.0408240353.2a5b8a84@posting.google.com> Message-ID: <6f402501.0408242310.48e095c@posting.google.com> Ville Vainio wrote in message news:... > >>>>> "Michael" == Michael Foord writes: > > Michael> That aside - Pyrex looks the kiddie. Can anyone reccomend > Michael> a reasonable C IDE ? An 'IDE' would be nice, but an > Michael> editor might be sufficient. > > IDE isn't really necessary for C - OO/modular languages like Java/C++ > benefit more from IDEs. You might do better by just picking an editor > (e.g. something like Emacs or Jed) and putting the compilation > commands in a python script (or a bat file), or learn make. > > Then again, there is Eclipse, the IDE to end all IDEs. It supports > C/C++ too. Ahh... 'the one true IDE'... at last I've found it ;-) I think I've heard good things about eclipse. I might just use Ultraedit though (my favourite editor) and as you say investigate automating the compile cycle...... I probably *ought* to learn make, but I'd rather script it myself. Regards, Fuzzy http://www.voidspace.org.uk/atlantibots/pythonutils.html From aleaxit at yahoo.com Sat Aug 28 02:44:19 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 28 Aug 2004 08:44:19 +0200 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <1LMXc.67190$UTP.37420@twister01.bloor.is.net.cable.rogers.com> <1gj7a9r.g7ec5a1g89rj0N%aleaxit@yahoo.com> Message-ID: <1gj8026.1w7jkq6u3fiegN%aleaxit@yahoo.com> Dan Perl wrote: > I thought about submitting a recipe but I couldn't think of a way to use it > in a good code 'snippet'. I am using the zipimport feature now to save > several configuration files together in a zip file (so I can have many > configurations saved in a convenient format, better than a new directory for > each configuration). That would be more of an example for using multiple > configurations but, anyway, it doesn't make for a short, well-contained > example. Sorry, Alex. Alas! Your analysis seems spot-on and is pretty close to why I haven't done a zipimport recipe myself -- it's a very useful feature but it's not easy to think of a way to show it off in a recipe that's just how recipes should be -- short, self-contained, readable. We can still hope that somebody else does think of something... > > BTW, there are two books on Python that I keep on my Safari bookshelf: > 'Python Cookbook' and 'Learning Python'. So my jab was made will all the > respect I can muster. I am really looking forward to the second edition, > recipe on zipimport or not. I did take your friendly jab as just that, friendly and pleasant, and answered in just the same vein. (I do hope the reason the Nutshell isn't on your Safari bookshelf is that you have the paper copy always at hand, right?-) Alex From tim at vegeta.ath.cx Fri Aug 27 22:14:08 2004 From: tim at vegeta.ath.cx (Tim Hammerquist) Date: Sat, 28 Aug 2004 02:14:08 -0000 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <776e0325.0408260433.449660c8@posting.google.com> <412dfc1c$0$65599$a1866201@newsreader.visi.com> <86hdqpriww.fsf@blue.stonehenge.com> <412e199e$0$8076$a1866201@newsreader.visi.com> Message-ID: John Doherty wrote: > Grant Edwards wrote: > > Of course, but are they consistently indented using tabs or spaces? > > AND HOW MANY SPACES PER TAB STOP? You just reminded me of the infamous variable naming debate: - visualBasicStyle - javaStyle - perl_style - jumbledstyle /me ducks out as sparks fly.... Tim Hammerquist From dustin at jabberdust.com Sun Aug 8 00:15:04 2004 From: dustin at jabberdust.com (Dustin) Date: 7 Aug 2004 21:15:04 -0700 Subject: ThreadingTCPServer, asyncore and Client-to-Client communication Message-ID: <81efeef2.0408072015.60addf38@posting.google.com> I've been trying to create a "byte streaming server", it's basically a chat server, but I'd like to use it for transfering large amounts of data between two connected clients. Sounds simple enough, but I'm having a difficult time implementing it. If Client #1 connects, then that thread is consumed with listening for data from that client. If Client #2 connects, that client is on a different thread, and therefore I don't see how I can have data sent from Client #1 to be streamed down to Client #2. (and how can client process #1 accept data from client #2 because it's listening to client #1?) Obviously I'm missing something. I've looked at asyncore/asynchat, as well as ThreadingTCPServer... but there's something I'm missing. Is there a simple way to have an object listen over two ports, and what comes into one port will be sent down the another? Any advice, or a good swift kick in the right direction would be appreciated. Dustin From http Sat Aug 21 21:20:53 2004 From: http (Paul Rubin) Date: 21 Aug 2004 18:20:53 -0700 Subject: Getting benifits of database transactions in an OO way? References: <2oq8pmFdd2nfU1@uni-berlin.de> Message-ID: <7xk6vsklxm.fsf@ruckus.brouhaha.com> Leif K-Brooks writes: > import people > fred = people.find_by_name('Fred Flintstone') > barney = people.find_by_name('Barney Rubble') > fred.money -= 10 > barney.money += 10 > fred.save_data() > barney.save_data() > > Right now, the Person.save_data method also commits the current > database transaction. But that seems to remove the benifit of having a > database with transactions: If something dies between the call to > fred.save_data() and barney.save_data(), Fred's $10 will end up in a > black hole somewhere. You have to use transactions for that. E.g. import people this_transaction = people.begin_transaction() fred = this_transaction.find_by_name('Fred Flintstone') barney = this_transaction.find_by_name('Barney Rubble') fred.money -= 10 barney.money += 10 this_transaction.finish_transaction() From mark_bottjer at hotmail.com Fri Aug 6 19:32:59 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Fri, 06 Aug 2004 19:32:59 -0400 Subject: PEP-0318 In-Reply-To: References: <41122FC2.1080608@interlink.com.au> Message-ID: <4114152f@nntp.zianet.com> Skip Montanaro wrote: > Incorporation of all or part of > http://www.python.org/moin/PythonDecoratorsinto the PEP would also be > appreciated. Neat page. I would like to flesh out (5.D), though, as it is not quite just "(5.C) with pie syntax" like the document currently states: E. pie decorator at top of function body syntax def foo(arg1,arg2): @classmethod ... def bar(low,high): @accepts(int,int) @returns(float) ... * + Java-like, so not completely unknown to everyone. * + Makes the syntax obvious visually * + Will not be silently ignored * + Compile-time * + One decorator per line * + Separate from the def syntax (desired by some for making decoration stand out and keeping def the same) * + Consistent with how docstrings are used. * + Looks ok for simple or complex decorators * + Won't break simplistic code analyzers or grep for function def * + Solves line wrap problem with proposal (5.C) * + Shouldn't break in interactive shell * + Easily foldable, the decorations are all "in" the function. * + @ symbol makes syntax coloring easier than trying to identify normal syntactic elements (e.g., lists) in magic positions. * + @ symbol makes it obvious that the decoration is not a normal statement. * 0 Perhaps decorators should be allowed before or after the docstring. If you have to choose, I'd choose making it before the docstring. * 0 The @ character is often used (in other languages) to mean "attribute". For annotations, this is good. For more active decorators, it may not be so good. * 0 Could use @doc too as a docstring alternative * - Separate from the def syntax (undesired by some for simple decorators like classmethod/staticmethod) * - Ugly? * - Introduces a new character in the language * - The @ special character is used in IPython and Leo, though not in this context (right?) * - Punctuation-based syntax raises Perlfears. * - @staticmethod may look like staticmethod is not a defined variable, but a compile time option * - "Buried" after a potentially-long list of arguments, which can make them harder to spot. * - Lots of decorators will make it harder to find the start of the function implementation. Then again, so will a large docstring. I would also like to add a few points to (5.A): * + @ symbol makes syntax coloring easier than trying to identify normal syntactic elements (e.g., lists) in magic positions. * + @ symbol makes it obvious that the decoration is not a normal statement. * - Requires the programmer to keep track of a potentially-large number of stacked up decorators before even knowing what is being decorated. * - Because of no indentation, looks confusing when definitions are not separated by empty lines. But adding empty lines makes it hard to determine where the function definition truly starts. * - Cannot be folded easily, since an arbitrary number of "leader lines" should also be folded into the function. This will involve a lot of reverse scanning of the file. I would be happy to add these myself if someone would tell me how? -- Mark From fumanchu at amor.org Sun Aug 22 10:38:49 2004 From: fumanchu at amor.org (Robert Brewer) Date: Sun, 22 Aug 2004 07:38:49 -0700 Subject: J2 proposal: keyword Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E26@exchange.hqamor.amorhq.net> Just to put collected wisdom in one spot for now, here's what's in my draft: III. Choosing a keyword If a keyword is to be chosen over @ or other punctuation, the question remains, "which word should it be?" Many words have been proposed, and although we may recommend a small number here, it is more important that we establish guidelines for the selection of a keyword. The keyword: -Should not be used widely as an identifier in existing Python code. -Should be easy to remember when writing new code. -Should be easy to remember when reading existing code. -Should be easy to search for, in both docs and Google. -Should not be a word with a planned future. This rules out "with" and "as" (I should probably footnote this). -In this author's opinion (back me up here, people), it should not be a form of the word "decorate". The term "decorate" conflicts with two separate concepts: both the GoF Decorator pattern (which is a runtime wrapper, not a compile-time one), and with our own beloved "decorate-sort-undecorate" pattern (aka Schwartzian or Guttman-Rosler Transform). -Candidates for keywords have fallen into two or three camps, and emphasize different aspects of decorators: -Declarative: declare, predef, moddef -Transformative: transform, wrap, modify, mutate -Attributive/Annotative: amend, using, having -Directive: pragma, signify -Associative: helper, qualify, qual, meta -Cross-cutting: imbue, endow, bestow, embellish, extend, accum, glom, confer -Prepositions/Adverbs: using, through, per, via, by I had an ugly paragraph promoting 'declare' as a top candidate, but I've always liked 'using' (which many of you promoted within the past 24 hours). Maybe the above will produce further polarization among you. ;) Robert Brewer MIS Amor Ministries fumanchu at amor.org From dave at boost-consulting.com Wed Aug 25 15:24:35 2004 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 25 Aug 2004 15:24:35 -0400 Subject: Unpythonic Python References: <8a638f47.0408240034.653a92ff@posting.google.com> <8a638f47.0408240700.13c39f57@posting.google.com> Message-ID: Rob Williscroft writes: > David Abrahams wrote in news:uy8k31as1.fsf at boost-consulting.com in > comp.lang.python: > >> Rob Williscroft writes: >> >>> David Abrahams wrote in news:uzn4j2s38.fsf at boost-consulting.com in >>> comp.lang.python: >>> >>>>> That's not the problem. I can download the file reliably from >>>>> other machines. >>> >>> At the same time, using http ? >> >> I can download the file reliably using IE from my WinXP box. >> >> I can download the file reliably using urllib from Cygwin Python 2.3.2 >> >> The 2nd element returned by urlretrieve is > > Which version, the one that works or the one that doesn't ? > >> >> 'Date: Wed, 25 Aug 2004 14:50:17 GMT\r\nServer: Apache/2.0.40 (Red >> Hat Linux)\r\nLast-Modified: Wed, 25 Aug 20 2 GMT\r\nETag: The one that works. > Something is missing here: > > Last-Modified: Wed, 25 Aug 20 2 GMT > > Contrast: > > Wed, 25 Aug 2004 14:50:17 GMT Where did that come from, what do you think is missing, and why? >> "b63d5b-20ec84b-18057e80"\r\nAccept-Ranges: bytes\r\nContent-Length: >> 34523211\r\nContent-Type: n/x-bzip2\r\nConnection: close\r\n' > > 34 MB's ( I got 6 MB's ) It's 34MB. >>>> Trying again with Python 2.3 on Cygwin. >> >> As you can see from the above, it works. Is there a known urllib bug >> in earlier Pythons? > > Sorry I don't know, but I've seen the same truncation with no python, > and no unix. Argh. >>> Is it possible the file is being (re) uploaded (via cvs) during your >>> cron job's download, thus truncating your download ? >> >> I don't think so. > > Can you test wether or not this is happening ? I.e if you don't > get the full 34523211 bytes re-download and compare the above > Length, ETag and Last-Modified. > I did some tests, but didn't come up with anything conclusive. I set my cron job to start 3 hours later. We'll see. >>> Perhapse you should change to cvs: >>> >>> os.system( 'cvs ... ' ) >> >> The problem with that is that I want to capture the whole CVS >> history, not just today's state. > > I was suggesting you get the tarball via cvs, though presumably > sourceforge don't give you the option. No they don't. > http has the problem that > the server will just truncate the download if the source file > gets replaced. > >> >>> FWIW, I tried downlading with IE using the link above I got a >>> truncated 6 and bit MB's (16:15 BST (UTC +0100)). >> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >> >> Sorry, what does that mean? Did it show that message in a dialog, >> or...? >> > > No, I got a download complete, but the file was only 6 MB's, bzip2 -t > told me the file was truncated, the (16:15 ...) is the time I tried > downloading, BST = British Summer Time, though you wouldn't know it > from the weather :). > > Further I just ran: > > import urllib > > filename, headers = \ > urllib.urlretrieve( > 'http://cvs.sourceforge.net/cvstarballs/boost-cvsroot.tar.bz2', > 'boost-cvsroot.tar.bz2') > > print filename > > print headers > > boost-cvsroot.tar.bz2 > Date: Wed, 25 Aug 2004 16:53:20 GMT > Server: Apache/2.0.40 (Red Hat Linux) > Last-Modified: Wed, 25 Aug 2004 14:14:02 GMT > ETag: "b63d5b-20ec84b-18057e80" > Accept-Ranges: bytes > Content-Length: 34523211 > Content-Type: application/x-bzip2 > Connection: close > > The script ended at 17::59 BST, Note the difference bettween the two > times in the headers, suggesting the file was modified 1:45 min's > ago ~ the same time my attempted download with IE failed. That's odd! Your (failed) download modified the file being downloaded?? -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From graeme.longman at tangozebra.com Wed Aug 4 12:21:58 2004 From: graeme.longman at tangozebra.com (Graeme Longman) Date: Wed, 4 Aug 2004 17:21:58 +0100 Subject: Finding all time periods for a given interval within a date range Message-ID: Hi everyone, I was wondering if anyone has written some Python code which uses a start date and end date and a given interval (day, month or year) and outputs all the time periods for that range and interval. For example you may wish to find all the months between the dates '2004-02-14' and '2004-08-04'. You would maybe use a function where you pass in those starting and ending dates and the interval 'month' and you'd get back a list of those months. I guess you would need to year part of the date too, so ['2004-02', '2004-03', '2004-04', '2004-05', '2004-06', '2004-07', '2004-08']. If you had passed in 'day' as the interval then you would be given back a list of all the days in those months. This is pretty specific but I would appreciate anything similar or even a good pointing in the right direction of which modules to use. I've taken a look at 'time' and 'calendar' but all I could see what the 'calendar.calendar' function which would require quite a bit of string processing after getting the calendar strings. Thanks for any help :-) Graeme --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.732 / Virus Database: 486 - Release Date: 29/07/2004 ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From edreamleo at charter.net Wed Aug 4 16:42:19 2004 From: edreamleo at charter.net (Edward K. Ream) Date: Wed, 4 Aug 2004 15:42:19 -0500 Subject: Confused about pep 318 Message-ID: <10h2ihgb8c6fi97@corp.supernews.com> Hello all, First of all, my present state of mind re pep 318 is one of sheepish confusion. I suspect pep 318 will not affect Leo significantly, but I am most surprised that an apparently controversial feature is being added without a notice, say, in comp.lang.python.announce. I say sheepish, because everyone knows that one should make sure new proposals don't bite you. Still, I would have thought that there were other ways of keeping abreast of potentially major changes to Python besides reading py-dev... The following are some comments to recent posts on py-dev. I hope to convey by these remarks my sense of bewilderment. > There is little point in going over all the same arguments again and again. For this alpha release, no amount of arguing will change what has been committed. You really have to organize a public outcry if you want the syntax changed before 2.4. [Martin v. L?wis] I'd like to defer the question of a "public outcry" until later, hopefully much later. But I have no idea what the proposed syntax is(!!) In particular, there is no mention of '@' directly on the page http://www.python.org/peps/pep-0318.html Is there a summary of recent work? An announcement? Some indication of consensus? > > In general, I predict most Python code will continue to be blissfully unadorned with decorators. > Right. Outside the test suite, there are very few uses of classmethod, staticmethod and property in the standard library. GvR Hmm... I see nowhere in pep 318 any mention that the pep will affect the following section of the Reference manual: http://docs.python.org/ref/delimiters.html [quote] The following printing ASCII characters are not used in Python. Their occurrence outside string literals and comments is an unconditional error: @ $ ? [end quote] I would regard any change to this paragraph as a major change to Python, in spite of its innocent appearance. Indeed, this paragraph is an excellent "line in the sand" for other tools. To repeat, I suspect adding @ would not affect Leo significantly in any direct way, and a workaround would probably exist even if it did. However, this proposal probably would affect the noweb markup language on which Leo is (loosely) based. See http://www.eecs.harvard.edu/~nr/noweb/ BTW, a long while back I suggested that there was no reason for the parser to need colons after "if" statements, etc. The response was: true, but allowing colons to be elided would impact existing tools. So I gave up. Am I the first to suggest that allowing '@' characters in valid Python programs outside string literals and comments might negatively impact existing tools? > Sigh. This discussion is going around in pointless circles; we're *months* past that point. You're wasting your time (and mine). [GvR] I confess that I don't understand this remark at all. How has it happened that so many people are confused about this proposal? And if everything is so clear, why isn't the clarity reflected in pep 318 itself? http://www.python.org/peps/pep-0318.html talks about - Background - Design goals - Proposed syntax (no mention of @!) - Alternative proposals etc. Excuse me, but if everything is now set in stone, then this is an extraordinarily misleading document. > Sorry. I think you'd be wise to consider the months without consensus as evidence of a problem. [Jim Fulton] This is my present opinion as well. Summary I wish to disavow any knowledge, or any interest in, the wider issues of whether pep 318 is a good idea or not. My concern is exclusively with the following two issues: 1. IMO, allowing '@' in valid Python programs (outside string literals or comments) is a major change to the language that has significant potential to disrupt already existing tools. At the very least, some discussion of http://docs.python.org/ref/delimiters.html should be in pep 318. 2. pep 318 apparently does not reflect the present state of affairs, and afaik there has been no announcement of proposed changes on comp.lang.python.announce. This is disturbing. If anyone could clarify the present status of pep 318 I would be most grateful. I would prefer not to be told to read all the py-dev archives. If everything is now clear, where can I find out about it? Edward -------------------------------------------------------------------- Edward K. Ream email: edreamleo at charter.net Leo: Literate Editor with Outlines Leo: http://webpages.charter.net/edreamleo/front.html -------------------------------------------------------------------- From brett at python.org Tue Aug 24 22:51:43 2004 From: brett at python.org (Brett C.) Date: 24 Aug 2004 19:51:43 -0700 Subject: python-dev Summary for 2004-08-01 through 2004-08-15 References: Message-ID: <8ab0589d.0408241851.7b46f49c@posting.google.com> [SNIP - me going on about how I had wished Guido just pronounced on decorators and moved on] > "Well, then allow me to retort." > > Up until PyCon in June, Guido was publicly leaning toward a C1-flavor of > decorator syntax. Apparently, there was sufficient furor by some audience > members (not to quibble whether or not this group was in fact representative > of all Python users) that Guido dropped back from it. Sometime in June, > @decorator seemed to drop from the sky - it was not even one of the top 2 > that GvR had in his keynote presentation - and by late July, it was suddenly > to be found in the newly released 2.4a2. > The '@' syntax had pretty much been discussed the whole time. At the end of PyCON Guido had a chance to talk to some other developers toward the end of the conference that started to change his opinion. After the conference he stated that he was starting to strongly consider the '@' syntax, and this was all public. He then went to EuroPython. Audience was much more perceptive to '@' than other syntaxes. Some more contemplation on Guido's part, and that led to the '@' syntax. But even had there not been any public discussion on Guido's part, I still think it is fine that Guido didn't have a huge discussion before making his final decision. This is Guido's language and we all just happen to love it. > I guess my sin of omission was in not following python-dev directly, but > instead relying on the natural checks and balances that have produced the > beautiful Python language thus far. And the final check is Guido. =) > Despite the periodic reporting of > python-dev summaries (thank you! BTW), Welcome. > and the April and June summaries of > the decorator status, *not one* of these summaries announced the selection > of "@decorator" before it was checked in and released - making it a seeming > fait accompli. No report because I didn't officially know until people started to scream about it (I check my python-dev mail before python-checkins so I didn't even see the checkin before the flood of mail started). > Contrast with the announcement of 'Generator expressions are > in!' in your May summary, well in advance of the 2.4a release. > That's just because it was all resolved way back when. Had decorators been resolved earlier it also would have gotten mentioned earlier. People need to realize this is all alpha software, not beta. Everything can change and python-dev reserves the right to tweak stuff up to b1. > > At this point people should be hashing out which syntax alternative they > > want to present to Guido on comp.lang.python_. No more talking on > > python-dev, no more syntax proposals. The community should set a goal > > date (Sept. 1 seems good) and just choose a bloody alternative. Then > > when Guido makes his choice people accept it or just go to another > > language. No one had better voice their disappoint once Guido chooses > > his syntax or I will personally come beat you over with a stick for > > being a whiner. > > > > Um, where have you been? Sitting in my chair reading a lot of email. > It seemed to me that, instead of continued > wallowing in a chaos of syntax discussions, that we collectively *were* > working on "just choosing a bloody alternative." Not how it looked on python-dev. Story may have been that on c.l.py, but on my side it was a ton of back and forth and people proposing random syntaxes whenever an idea popped in their head. > I guess we've not been > wholly successful, as there are still *two* popular contenders, but one is > leading the other by more than 2-to-1, and a consensus measure shows an even > greater level of, if not acceptance, at least tolerance. c.l.py is a tough > herd of cats! Michael Sparks and Robert Brewer have voted in a measure > beyond simply posting Usenet votes, and have completed the steps for one of > the contenders to be considered by Guido. The absence of champions for the > other option may end up making the decision by default - too bad, actually. > And that's great. As I said, this was not reflected on python-dev *at all*. Robert sent an email today stating that he had a whole paper on the syntax he was supporting. He seems to be going about it the right way and honestly I hope his wins just for the fact that he has put the effort in. > > OK, that's out of my system. I feel better now. > > > > Well, good for you. I also subscribe to a "no whining" philosophy, but I > don't think it is unexpected nor unreasonable that the rapid selection, > implementation, and release of "@decorator" took many by (unpleasant) > surprise. > And am I the only one who has trouble reconciling your tirade > with your encouragement to "take a stance" (in the emphasized section at > top)? > Maybe. =) The tirade was not on taking a stand. It was at everybody fighting this out on python-dev even after Guido told people to go off and agree on a single syntax. python-dev is not the place to have the whole community duke it out over an alternative syntax. *That* was what the tirade was about. > We can agree to disagree - I'll plead guilty to being a miserable lurker who > up until recently was happy to rely on the wisdom of strangers - but allow > me to take at least a little umbrage at your tirade. > Sure, but I think you mistook me. But even if you didn't, no problem. -Brett From vronskij at post.sk Wed Aug 18 10:19:19 2004 From: vronskij at post.sk (vronskij at post.sk) Date: 18 Aug 2004 07:19:19 -0700 Subject: How big can a Python program be? References: <903b3fba.0408170333.49ce3944@posting.google.com> <412204d5$1$28243$afc38c87@news.easynet.co.uk> Message-ID: <903b3fba.0408180619.4d41027e@posting.google.com> Peter Hickman wrote in message news:<412204d5$1$28243$afc38c87 at news.easynet.co.uk>... > vronskij at post.sk wrote: > > Hi, > > > > A C program can be hundreds of thousands lines of code big. > > C++ millions. > > > > How about Python? > > > > Suppose , you are a sole programmer (lonewolf). How many lines can one handle? > > > > Thanks, > > > > > > jan bodnar > > Are you suggesting that a solo programmer wrote a multi million line C++ > program? If not then what has this to do with 'How many lines can one handle?' > > The application I am currently working on has 75,000 lines across some 600 > files. But I suspect that the line count is higher when you include the various > libraries. So I am handling 75,000 lines in some sense, is this what you mean? > Or are you talking about the number of lines per file (average 125) or perhaps > lines per method? Heh, > Are you suggesting that a solo programmer wrote a multi million line C++ > program? If not then what has this to do with 'How many lines can one handle?' No way. This was just another question. One programmer told me that he can roughly handle max 10 000 lines in C language. I was curious about Python. I always hear that Python can be used on larger projects than e.j. PERL because it is Object Oriented and cleanly designed. What is a larger project? Mumbers revail more. > The application I am currently working on has 75,000 lines across some 600 > files. This is probably team work. It's helpful for me to know figures. When you start a project it is useful to know the limitations of a language. Visual Basic is reported to fail on larger projects. From jbperez808 at wahoo.com Fri Aug 20 07:18:30 2004 From: jbperez808 at wahoo.com (Jon Perez) Date: Fri, 20 Aug 2004 19:18:30 +0800 Subject: Why isn't XUL more popular? In-Reply-To: <2om4a3Fc4p8rU1@uni-berlin.de> References: <2om4a3Fc4p8rU1@uni-berlin.de> Message-ID: <2om4gbFc4p8rU2@uni-berlin.de> Whoops... stray post from netscape.public.dev.xul... Jon Perez wrote: > I find DOM to be unnecessarily verbose. It looks very much like a > bloated design-by-a-committee rather than a lean, mean spec designed by a > few sharp minds. It takes way too many calls to do something simple > and the proper calls to use are non-obvious to a beginner. It is really > not that hard to imagine having a simpler API for manipulating XML. > > I have been doing extensive DOM work using Javascript for many years > now and while I'm quite deep into DOM (For example, I have developed a > technique to dynamically load/modify any part of a webpage from a remote > data source without reloading the entire page. A much tougher task than > you might think owing to Javascript/DOM API deficiencies and hence the need > for 'voodoo' techniques), I must say I have never grown to love this API. > > Among the many XML-manipulation libraries available for Python are two > or three DOM implentations. Despite my long experience with DOM under > Javascript, I shun the DOM ones and instead use Fredrik Lundh's way more > pythonic(*) ElementTree... waaaay easier to deal with. Too bad it or a > similar API is not available for doing DHTML. :-( > > > (*) 'pythonic' is roughly translated as meaning quick to learn (one > sitting), easy to use (e.g. small, easy-to-remember API) and powerful > at the same time. From gk_2345 at yahoo.com Sun Aug 15 14:47:12 2004 From: gk_2345 at yahoo.com (George Kinney) Date: Sun, 15 Aug 2004 14:47:12 -0400 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: wrote in message news:3064b51d.0408130615.3fc4a760 at posting.google.com... > I'm not saying that Python's use of indentation is bad, just that it > stops many programmers from trying it. I thought it was a bit odd years ago when I first saw it, but then I spent years writing code in ILE RPG. Which is a language where actual line position of opcodes/values, etc matters. Which is quite a bit more extreme than python's indented blocks. (Of course python has now been ported to OS/400, or i5/OS as its called this month, so I can use either. :) ) IBM did decide to produce a free-format version of RPG, which tosses the learned readability of veterans in the trash in the hopes of attracting some of these 'required-format-is-scary' programmers to the fold. Like this, and not the fact that the OS/400 platform is fairly obscure to most programmers, is the root cause of RPG programmers being hard to find. Personally, if the first comment out of a new hire's mouth was a gripe about how to format source code, I show them the door. If, a few months later, they gripe about the format because it causes a real, measurable problem, then I'll buy them a beer. :) From peter_jacobi at gmx.net Sun Aug 1 12:30:29 2004 From: peter_jacobi at gmx.net (Peter Jacobi) Date: 1 Aug 2004 09:30:29 -0700 Subject: Codecs for ISO 8859-11 (Thai) and 8859-16 (Romanian) References: <410c2827$0$24830$9b622d9e@news.freenet.de> Message-ID: Hi Martin, All, "Martin v. L?wis" wrote:> > The process is actually very easy. Anybody willing to contribute them > would have to upload them to SF (sf.net/projects/python). Perhaps I have just misunderstood your email. I read it this way (in my own words): Taking into account unanswered questions about ISO 8859-11 and TIS620, whoever wants to contribute, has to do provider further research, starting with, but not limited to, buying the ISO standard. The prospective contributor in addition has to provide support for this patch and answer all questions about the details involved. Sorry, this is in the moment out of scope for me. I have a patch, using information from a source which is reliable enough for my personal requirements, and now the patch is on USENET available for everyone who wants to investigate further. Regards, Peter Jacobi From dan at cgl.ucsf.edu Mon Aug 16 14:09:27 2004 From: dan at cgl.ucsf.edu (Dan Greenblatt) Date: Mon, 16 Aug 2004 11:09:27 -0700 Subject: passing the url of the current webpage to python script In-Reply-To: References: Message-ID: wonder wrote: > Hi, > > How can I pass the url of the current webpage link to a python script in > html? > > thanks > sam are you using a python script as a helper application? From squirrel at WPI.EDU Fri Aug 13 10:58:08 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Fri, 13 Aug 2004 10:58:08 -0400 Subject: Difference between readlines() and iterating on a file object? In-Reply-To: <411cd102$1@mail.hmgcc.gov.uk> References: <411cd102$1@mail.hmgcc.gov.uk> Message-ID: On Fri, 13 Aug 2004, Richard wrote: > Can anyone tell me what the difference is between > > for line in file.readlines( ): > > and > > for line in file: > > where file is a file object returned from an open( ) call? The first form slurps every line in the file into a list, and then goes through each item in the list in turn. The second form skips the middleman, and simply goes through each line of the file in turn (no interim list is created). In this context, file is acting as a generator. Because a list isn't created, this form is both faster and consumes less memory, overall making it much more efficient than .readlines(). > I thought that they did the same thing, but the code I am using it in has > this line called more than once on the same file object and the second time > it is ran gives different results for each. Assuming you don't prematurely exit the for loop or access the file in another manner while looping, both forms should give identical results. Otherwise... > What is the difference in implementation? Because first form slurps everything in at once, repeated calls to it (with no intervening seek()s) will always return an empty list, whether the for loop was stopped prematurely or not. On the other hand, since the second form only reads one line at a time (using file.next()), if the for loop is stopped prematurely (e.g. via break), subsequent invocations will pick up right where the previous one left off. Hope this helps. From fischerlaender at gmx.de Thu Aug 12 10:58:43 2004 From: fischerlaender at gmx.de (Stefan Fischerl?nder) Date: 12 Aug 2004 07:58:43 -0700 Subject: Developing a Tool Band for IE in Python Message-ID: After searching Google and Google Groups for several hours I did not find an answer to my question. Is Python suitable for developing a tool band (something like the Google Toolbar) to be placed in the Internet Explorer's rebar? Does anyone even have any tutorial or something similiar? Thank you very much. Stefan From jeffrey at I.slack Wed Aug 11 10:29:45 2004 From: jeffrey at I.slack (Jeffrey Froman) Date: Wed, 11 Aug 2004 07:29:45 -0700 Subject: Purely emotional perspective References: <10hf3oaltbo7o74@corp.supernews.com> Message-ID: <10hkbaq9c3m8750@corp.supernews.com> Michael J. Fromberger wrote: > Assuming?we?take?the?Zen?of > Python as a set of philosophical design goals for Python, I argue that > all the proposed uses of decorators so far fail the Zen on the following > axes:??Beauty,?Simplicity,?Sparseness,?Readability,?Special?Cases,?One > Obvious Way, and Difficulty of Explanation. Exactly so. Apparently for the people who design Python, however, this is not a philosophy but a joke (note that it's in the Humor section at python.org.) For me, however, it's not a joke. I choose python because it reflects choices I make for my life as a whole. To this end, I do still have recourse without having to abandon python yet: I will keep the Zen; I will boycott decorators. If it is true (as it has been asserted in this newsgroup and elsewhere) that the vast majority of python developers do not like decorators, then boycotting them will make them go away despite all efforts to introduce them. Avoid using them. Avoid (or "fix") code that uses them. Ultimately, what goes into python code is up to those of us who write the code. Jeffrey From jepler at unpythonic.net Tue Aug 17 21:56:47 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 17 Aug 2004 20:56:47 -0500 Subject: Why is SETUP_FINALLY uninterruptable[sic]? In-Reply-To: <2JmdnSiV4NZzGL_cRVn-pg@lmi.net> References: <2JmdnSiV4NZzGL_cRVn-pg@lmi.net> Message-ID: <20040818015647.GB5422@unpythonic.net> Well, it's not an answer per se, but this block of code was added at the same time as PyThreadState_SetAsyncExc, which is a C API to allow raising an exception from an arbitrary thread. http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Python/ceval.c#rev2.366 I suspect that this has something to do with code like l = some_lock() l.acquire() # MARK try: something with l held finally: l.release() If an asynchronous exception happens betwen l.acquire() and the SETUP_FINALLY opcode (at "MARK") , there's no guarantee that l.release() is executed. This state of affairs always existed with KeyboardInterrupt and/or signals, and it's hard to see how this fixes the problem if l.acquire() is Python code, but I think that's what's going on. The special magic is only applied to SETUP_FINALLY because try: except: isn't used for this kind of resource management. This is all guesswork, though. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From lopexx at autograf.pl Tue Aug 17 08:11:24 2004 From: lopexx at autograf.pl (lopex) Date: Tue, 17 Aug 2004 14:11:24 +0200 Subject: Best programming language In-Reply-To: References: <873c2ndizt.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Message-ID: Andrew Durdin wrote: > > The obvious answer, of course, is that on the newsgroup/mailing list > for language X, define "best programming language" to be X. It saves a > lot of combustion :) agreed Marcin Mielzynski From aleaxit at yahoo.com Sat Aug 28 11:44:43 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 28 Aug 2004 17:44:43 +0200 Subject: Question about references/copies References: <1gj870c.dzzhcpvby7ozN%aleaxit@yahoo.com> <1gj8k1n.1vm9nm4y4avw0N%aleaxit@yahoo.com> Message-ID: <1gj8o7s.1vq95rk32cmygN%aleaxit@yahoo.com> Arthur wrote: ... > >If you know what type obj is, say a list; or, if don't really care > >whether obj is (say) a list or a tuple or ... 'cause what you want is a > >list anyway, then the normal way to spell this is of course list(obj). > > Well there is a lot of divergence in practice, as I think you know. Sure, I did say I've seen [x for x in thelist] used. > And beyond that no real consensus on what is preferable, as far as I Hmmm -- I've never seen a debate trying to determine that consensus, actually. > have been able to determnine Though hearing Alex declare it as > preferable is the beginning of the formation of some consensus, one > hopes. You're very kind, but I've hardly ever been able to convince GvR of anything whatsoever;-) > >> and/or that the copy module > >> was something other than one of XXX importable moudles. > > > >Well, it's Python-coded, so it seems quite natural to me that it be a > >perfectly normal importable module. > > I understand, now, the problems with treating the copy module > otherwise than it is. But it is a strange duck - conceptually in the > middle of things, but with limited functional importance. I thought Yes, I see your point. Anna and I just co-wrote a Cookbook recipe about copying, so we ended up debating several such points and she also brought this one up, btw > only that Ray's idea of setting it off a bit, by mention in the > tutorial, had considerable merit. Yep, I see that it might. > I agree that dict(mydict) and list(mylist) - it that is what one saw > with consitentcy in practice - would go a long way. I'll try to > practice it, having gotten into the list[:] habit. myseq[:] has the advantage of being polymorphic over list, tuple, str, and array.array -- list(myseq) would produce a new list no matter what the type of myseq (it's more polymorphic too, which is generally fine but may perhaps hide problems if myseq is, say, a dict, unexpectedly turning it into a sequence of its keys in arbitrary hash order). I find that when people are copying a dubious-type sequence they're often happy with getting a list anyway (so they KNOW they can use list's wide variety of methods), the only trouble case being indeed list(somedict). > > And ... > > It was my understanding - perhaps wrong - that dict.copy() was an > add-on method to dict of non-ancient origin. How do I check? http://www.python.org/doc/versions.html pointers to all versions of docs since 1.4 which came out in 1996. to see that method copy was already in 1.5 (1998): http://www.python.org/doc/1.5/lib/node13.html#SECTION0031600000000000000 00 I can't see it in 1.4 so I assume it was introduced between '96 and '98. dict appeared in 2.2 (late 2001), see http://www.python.org/doc/2.2/lib/built-in-funcs.html > >> consider this entire area a significant wart. I think I am entitled to > >> consider it so. > > > >Given the apparent dearth of information in the matter, you may be > >right. I'll do my best to keep clarifying my viewpoint in my books... > > That would be excellant! Anna (my wife and coeditor), hearing from me a summary of this discussion, decided (and easily convinced me) that copying needs to be the first recipe in the book, and we have already written and committed it, so, unless we get a veto from David Ascher, the other coeditor, or from O'Reilly, that might help. The recipe as it currently stands shows copy.copy as the preferred way, with copy.deepcopy and calling the object's type as secondary ways for particular needs, and L[:] as well as [x for x in L] being specifically shown as wrong-headed approaches. (We'll see how that survives tech review etc;-). Alex From pje at telecommunity.com Fri Aug 27 17:39:22 2004 From: pje at telecommunity.com (Phillip J. Eby) Date: Fri, 27 Aug 2004 17:39:22 -0400 Subject: PEP 333: Python Web Server Gateway Interface v1.0 Message-ID: <5.1.1.6.0.20040827173839.02f9dec0@mail.telecommunity.com> PEP: 333 Title: Python Web Server Gateway Interface v1.0 Version: $Revision: 1.1 $ Last-Modified: $Date: 2004/08/27 17:30:09 $ Author: Phillip J. Eby Discussions-To: Python Web-SIG Status: Draft Type: Informational Content-Type: text/x-rst Created: 07-Dec-2003 Post-History: 07-Dec-2003, 08-Aug-2004, 20-Aug-2004, 27-Aug-2004 Abstract ======== This document specifies a proposed standard interface between web servers and Python web applications or frameworks, to promote web application portability across a variety of web servers. Rationale and Goals =================== Python currently boasts a wide variety of web application frameworks, such as Zope, Quixote, Webware, SkunkWeb, PSO, and Twisted Web -- to name just a few [1]_. This wide variety of choices can be a problem for new Python users, because generally speaking, their choice of web framework will limit their choice of usable web servers, and vice versa. By contrast, although Java has just as many web application frameworks available, Java's "servlet" API makes it possible for applications written with any Java web application framework to run in any web server that supports the servlet API. The availability and widespread use of such an API in web servers for Python -- whether those servers are written in Python (e.g. Medusa), embed Python (e.g. mod_python), or invoke Python via a gateway protocol (e.g. CGI, FastCGI, etc.) -- would separate choice of framework from choice of web server, freeing users to choose a pairing that suits them, while freeing framework and server developers to focus on their preferred area of specialization. This PEP, therefore, proposes a simple and universal interface between web servers and web applications or frameworks: the Python Web Server Gateway Interface (WSGI). But the mere existence of a WSGI spec does nothing to address the existing state of servers and frameworks for Python web applications. Server and framework authors and maintainers must actually implement WSGI for there to be any effect. However, since no existing servers or frameworks support WSGI, there is little immediate reward for an author who implements WSGI support. Thus, WSGI *must* be easy to implement, so that an author's initial investment in the interface can be reasonably low. Thus, simplicity of implementation on *both* the server and framework sides of the interface is absolutely critical to the utility of the WSGI interface, and is therefore the principal criterion for any design decisions. Note, however, that simplicity of implementation for a framework author is not the same thing as ease of use for a web application author. WSGI presents an absolutely "no frills" interface to the framework author, because bells and whistles like response objects and cookie handling would just get in the way of existing frameworks' handling of these issues. Again, the goal of WSGI is to facilitate easy interconnection of existing servers and applications or frameworks, not to create a new web framework. Note also that this goal precludes WSGI from requiring anything that is not already available in deployed versions of Python. Therefore, new standard library modules are not proposed or required by this specification, and nothing in WSGI requires a Python version greater than 2.2.2. (It would be a good idea, however, for future versions of Python to include support for this interface in web servers provided by the standard library.) In addition to ease of implementation for existing and future frameworks and servers, it should also be easy to create request preprocessors, response postprocessors, and other WSGI-based "middleware" components that look like an application to their containing server, while acting as a server for their contained applications. If middleware can be both simple and robust, and WSGI is widely available in servers and frameworks, it allows for the possibility of an entirely new kind of Python web application framework: one consisting of loosely-coupled WSGI middleware components. Indeed, existing framework authors may even choose to refactor their frameworks' existing services to be provided in this way, becoming more like libraries used with WSGI, and less like monolithic frameworks. This would then allow application developers to choose "best-of-breed" components for specific functionality, rather than having to commit to all the pros and cons of a single framework. Of course, as of this writing, that day is doubtless quite far off. In the meantime, it is a sufficient short-term goal for WSGI to enable the use of any framework with any server. Finally, it should be mentioned that the current version of WSGI does not prescribe any particular mechanism for "deploying" an application for use with a web server or server gateway. At the present time, this is necessarily implementation-defined by the server or gateway. After a sufficient number of servers and frameworks have implemented WSGI to provide field experience with varying deployment requirements, it may make sense to create another PEP, describing a deployment standard for WSGI servers and application frameworks. [Remainder truncated due to python-list posting size limit; please see: http://python.org/peps/pep-0333.html for remaining text.] From pwilkinson at videotron.ca Fri Aug 6 14:39:35 2004 From: pwilkinson at videotron.ca (Peter Wilkinson) Date: Fri, 06 Aug 2004 14:39:35 -0400 Subject: unicode to ascii converting In-Reply-To: <6.0.3.0.0.20040806141614.01b8fcb0@pop.videotron.ca> References: <1091815856.527127@news.commspeed.net> <6.0.3.0.0.20040806141614.01b8fcb0@pop.videotron.ca> Message-ID: <6.0.3.0.0.20040806143011.01b18528@pop.videotron.ca> I tried the function, actually this does not seem to work as I expected. What happens is that the character encoding seems to change in the following way: placing what is the equivalent of some return character after each character ... or when I view the file in excel there is a blank row in between between each row. Its very strange. back to the drawing board At 02:17 PM 8/6/2004, Peter Wilkinson wrote: >Thanks Tom B., > >I will try that for now .... > >It would be good to find out _why_ this happens in the first place. I will >keep do a little searching on this for a few days. > > >Peter W. > > >At 02:04 PM 8/6/2004, Tom B. wrote: > >>"Peter Wilkinson" wrote in message >>news:mailman.1296.1091813051.5135.python-list at python.org... >> > Hello tlistmembers, >> > >> > I am using the encoding function to convert unicode to ascii. At one point >> > this code was working just fine, however, now it has broken. >> > >> > I am reading a text file that has is in unicode (I am unsure of which >> > flavour or bit depth). as I read in the file one line at a time >> > (readlines()) it converts to ascii. Simple enough. At the same time I am >> > copressing to bz2 with the bz2 module but that works just fine. The code >> > is and error reported appears below. I am unsure what to do. >> > >> > I assume that because it is reporting that ordinal is not in range, that >> > something to do with the character width that I am reading? >> > >> > Peter W. >> > >> > def encode_file(file_path, encode_type, compress='N'): >> > """ >> > Changes encoding of file >> > """ >> > new_encode = encode_type >> > old_file_path = file_path + '.old' >> > new_file_path = file_path >> > os.rename(file_path,old_file_path) >> > file_in = file(old_file_path,'r') >> > >> > if compress == 'Y' or compress == 'y': >> > bz_file_path = file_path + '.bz2' >> > bz_file_out = bz2.BZ2File(bz_file_path, 'w') >> > for line in file_in.readlines(): >> > bz_file_out.write(line.encode(new_encode)) >> > bz_file_out.close() >> > >> > else: >> > file_out = file(file_path,'w') >> > for line in file_in.readlines(): >> > file_out.write(line.encode(new_encode)) >> > file_out.close() >> > >> > file_in.close() >> > os.remove(old_file_path) >> > >> > ERROR Reported: >> > >> > Parsing >> > >>X:\GenomeQuebec_repository\microarray\HIS\M15K\Step_1_repository\HISH0224.tx >>t >> > Traceback (most recent call last): >> > File "C:\Program Files\ActiveState Komodo 2.5\callkomodo\kdb.py", line >> > 433, in _do_start >> > self.kdb.run(code_ob, locals, locals) >> > File "C:\Python23\lib\bdb.py", line 350, in run >> > exec cmd in globals, locals >> > File "C:\Python23\Lib\site-packages\xBio\Scripts\unicodeToAscii.py", >> > line 158, in ? >> > main() >> > File "C:\Python23\Lib\site-packages\xBio\Scripts\unicodeToAscii.py", >> > line 75, in main >> > encode_file(fileToProcess, options.encode, 'Y') >> > File "C:\Python23\Lib\site-packages\xBio\Scripts\unicodeToAscii.py", >> > line 144, in encode_file >> > bz_file_out.write(line.encode(new_encode)) >> > UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: >> > ordinal not in range(128) >> > >>I've encountered this problem before and the solution I've come up with a >>fix that works but is probably not the best, >> >>def is_ord (strng): >> new_text = '' >> for i in strng: >> if ord(i) > 127: >> new_text = new_text + '' >> else: >> new_text = new_text + i >> return new_text >> >>#Then just, >> >>text_from_file = is_ord(text_from_file) >> >>Tom >> >> >>-- >>http://mail.python.org/mailman/listinfo/python-list > >-- >http://mail.python.org/mailman/listinfo/python-list From python-spam at berrs.net Thu Aug 26 10:34:05 2004 From: python-spam at berrs.net (Per Erik Stendahl) Date: Thu, 26 Aug 2004 16:34:05 +0200 Subject: Static properties Message-ID: <412DF4DD.4070302@berrs.net> Hello everyone, Is it possible to define "static properties" in a class? Example: I have a class, Path, that wraps a lot of os.* and os.path.* functions (and others), so I can write things like this: x = Path('/usr/local/some/file') if x.IsFile: contents = x.Read() ... Now, I would like to wrap os.getcwd(). I can do it like this: class Path: def CurrentDirectory(): return os.getcwd() CurrentDirectory = staticmethod(CurrentDirectory) pwd = Path.CurrentDirectory() Question: Can I make CurrentDirectory a property? Just adding CurrentDirectory = property(CurrentDirectory) after the staticmethod line didn't work, unsurprisingly. :-) Regards, Per Erik Stendahl From pm_mon at yahoo.com Thu Aug 19 06:35:18 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Thu, 19 Aug 2004 06:35:18 -0400 Subject: PEP 318: Can't we all just get along? In-Reply-To: References: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: Michael J. Fromberger wrote: > > Oh, I see it just fine -- but I still disagree with the idea of > including any such implicit magic in the language. > > In fact, I don't like some of the magic that is already there -- such > as, for instance, the automatic mangling of class members whose names > begin with a double underscore to get "private" semantics. But that, at > least, is easy to avoid, if one doesn't want to use it. > Unless of course you want a method to be private/semi-private. How do you feel about the way we can create/manipulate lists and dictionaries using special (magical) syntax? Why is that different (acceptable)? x = [10, 20, 30] is shorthand for what would be much more code in other languages. Is that syntax ok but def __iAmPrivate(): pass isn't? Why? From harry.g.george at boeing.com Thu Aug 26 10:11:19 2004 From: harry.g.george at boeing.com (Harry George) Date: Thu, 26 Aug 2004 14:11:19 GMT Subject: Dennis, Greg, Ian References: <1q8002-nal.ln1@suse.zobbo.org> Message-ID: "M. Clift" writes: > Hi to all of you, > > Well that's a lot of 'stuff' you gave me. Thankyou. > > I did understand that the brackets were not part of the list, but leaving > them that way (as tuples) I could see problems in trying to refer to them at > some stage. I was having no luck with what I was doing, ending up with just > being able to call the first item in each tuple. As I'm new to this, maybe I > don't actually need to do this in the long run for what I want, but for now > while I think that I do, these answers are exactly what I need. > > All the best, > > M > > Did anyone explain list "flattening"? That may be what you want. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/121294 -- harry.g.george at boeing.com 6-6M21 BCA CompArch Design Engineering Phone: (425) 342-0007 From paolo.veronelli at yahoo.it Sat Aug 21 15:02:02 2004 From: paolo.veronelli at yahoo.it (Paolo Veronelli) Date: Sat, 21 Aug 2004 21:02:02 +0200 Subject: __metaclass__ and __author__ are already decorators In-Reply-To: References: <4127813F.9020707@yahoo.it> Message-ID: <41279C2A.9060906@yahoo.it> Paul Morrow wrote: > Paolo Veronelli wrote: > >> >> >> Paul Morrow wrote: >> >>> Thinking about decorators, and looking at what we are already doing >>> in our Python code, it seems that __metaclass__, __author__, >>> __version__, etc. are all examples of decorators. So we already have >>> a decorator syntax. What is the compelling reason to invent a new >>> one? And if we do, what's to become of the old one? >> >> Thanks for pointing out another unpythonicity. Paolino >> > > Is that what I did? Isn't assigning values to __xxx__ attributes > pythonic? Really but instructing the interpreter with assigning to special attributes is not a well classified operation: __author__ & company are just settable/gettable (the don't instruct the interpreter) this is surface level. __getitem__ (in ex) instruct the intepreter on how to parse [] sintax (am I wrong?).So __lt__ and the alike :that's what I call a syntactic level.This is more or less well defined (and so pythonic):operators can be defined like this. __metaclass__ doesn't seem to be placed in the first two categories.It instruct the interpreter on a deeper level (in my vision),an actual level which I think is well related with decorator level.If I am right,this speciality of an only attribute makes it unpythonic.It has to be part of a class of attributes ,which would be nice to be populated just (at least) to make its instructing position clearer. I hope I could express something..... Regards Paolino From 510046470588-0001 at t-online.de Sat Aug 21 02:53:59 2004 From: 510046470588-0001 at t-online.de (510046470588-0001 at t-online.de) Date: 21 Aug 2004 08:53:59 +0200 Subject: My only complaint about Python References: Message-ID: <874qmxj81k.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Tim Daneliuk writes: > Istvan Albert wrote: > > In all fairness this is more the problem with Microsoft than > > python. If they had a free fully-featured compiler then Python > > would be compiled with that. > > > They do. MSC/C++ is now available at NO cost: > no cost is not the same as free Klaus Schilling From shannon at news.widomaker.com Tue Aug 31 11:35:59 2004 From: shannon at news.widomaker.com (Charles Shannon Hendrix) Date: Tue, 31 Aug 2004 11:35:59 -0400 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: ["Followup-To:" header set to alt.folklore.computers.] On 2004-08-26, Markus Wankus wrote: >>>I think you're getting confused with the Blue ?yster Cult. >>>Don't Fear the Reaper - great song. >> >> > > It was a great song, but it needed more cowbell... Well, there is always Witchunt by Rush... -- shannon "AT" widomaker.com -- ["Tara is grass, and behold how Troy lieth low--And even the English, perchance their hour will come!"] From natunika at gmx.de Tue Aug 17 06:15:04 2004 From: natunika at gmx.de (Silke) Date: 17 Aug 2004 03:15:04 -0700 Subject: serial and threads Message-ID: <39ba6e78.0408170215.3368be4e@posting.google.com> Hi all! I'm trying to write a program in python using the modules 'serialwin32' and 'thread' to create one thread that writes to a serial port and another one that reads from it at 'the same time'. My definitions are def NetworkToSerial(input): s.write(binascii.unhexlify(input)) print "SENT: %s" % input def SerialToNetwork(): result = s.read(1) print "RECEIVED:" print binascii.hexlify(result) and I call them with thread.start_new_thread(NetworkToSerial, (command,)) thread.start_new_thread(SerialToNetwork, ()) The first one seems to run fine, but for the second one I get the error message 'ClearCommError', 'the handle is invalid'. Does anyone have a clue whether maybe serialwin32 is not thread-compatible? Thanks for your help in advance! Silke From joewong at mango.cc Mon Aug 23 05:29:35 2004 From: joewong at mango.cc (Joe Wong) Date: Mon, 23 Aug 2004 17:29:35 +0800 Subject: import module on relative path. Message-ID: <051201c488f3$b4d624e0$7f00a8c0@scl01.siliconcreation.com> Hi, Can I do something similar to C include statement like include "../module/abc.h" in Python import statement? Regards, - Joe -------------- next part -------------- An HTML attachment was scrubbed... URL: From f.geiger at vol.at Fri Aug 6 06:01:50 2004 From: f.geiger at vol.at (F. GEIGER) Date: Fri, 6 Aug 2004 12:01:50 +0200 Subject: [py2exe.i18n] English works, German works, but not French. What do I miss? References: Message-ID: "Harald Massa" schrieb im Newsbeitrag news:Xns953D5E610BA51cpl19ghumspamgourmet at 195.20.224.116... > "F. GEIGER" wrote in news:cev7g9$3fm$1 at newshispeed.ch: > > > When I start a py2exe-ed application I get the error > > > > 'ascii' codec can't encode character u'\xe9' in position 10: ordinal > > not in range(128) > > > encodings: prepare to spend the night. > > First reading: > http://starship.python.net/crew/theller/moin.cgi/EncodingsAgain > > Second: > your error msg says that you are trying to encode sth. NOT ASCII to > ASCII... > > I guess: > your lokale site has another encoding configured > > > import sys > sys.getdefaultencoding() > > -- returns sth. like Latin-1 > > And the py2exed application does not read siteconfig.py, and so in the > running app sys.getdefaultencoding() would be some thing different. > > My approach to this is: > > in the beginning of the app I write: > > import sys > if hasattr(sys,"setdefaultencoding"): > sys.setdefaultencoding("latin-1") > > so ... when no site-config was run, I manually set my default encoding to > latin-1 > > works great (together with what I described within the wiki) Phew, that did it - works great. Thanx a lot, Harald! Cheers Franz GEIGER > > Harald From anthonybaxter at gmail.com Tue Aug 24 22:33:14 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Wed, 25 Aug 2004 12:33:14 +1000 Subject: J2 paper 0.2.1 In-Reply-To: References: <3A81C87DC164034AA4E2DDFE11D258E3022E55@exchange.hqamor.amorhq.net> Message-ID: On Tue, 24 Aug 2004 14:32:38 -0700, Tim Hochberg wrote: > Sadly I don't have any better ideas for a keyword. While I'm on the > topic, let me point out some of the other keywords mentioned in the > proposal that read poorly. "amend", "extend" and "qualify" all share a > common flaw that in normal usage the thing being amended/extended/etc > should follow the word. Thus the natural reading of: 'extend' is a method of list objects, and so can't be used. From michaels at rd.bbc.co.uk Tue Aug 24 12:05:57 2004 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Tue, 24 Aug 2004 17:05:57 +0100 Subject: python-dev Summary for 2004-08-01 through 2004-08-15 References: Message-ID: Robert Brewer wrote: > Anthony Baxter wrote: >> Brett Cannon wrote: ... >> > talking on python-dev, no more syntax proposals. The community >> > should set a goal date (Sept. 1 seems good) and just choose a >> > bloody alternative. ... >> Sept 1 is way, way, way too late. 2.4a3 is scheduled for September 2. >> I'd _hope_ that by the end of this week we can have the proposed >> alternative(s) presented to Guido - this gives him the weekend ... > Given the dearth of heated debate over the proposal, I expect to call > for signatories within the next 24 hours or so. I know Michael Sparks > is working on patching against CVS (instead of alpha 2), minor grammar > improvements, and such--not sure how far along that is or if he feels > it could wait for revisions after the decision is made...? The I have a patch working against current CVS, and all the tests bar one pass. (Specifically test_inspect) The following examples are now legal: using: author("JoeBloggs") Component(inboxes=["inbox","control"],outboxes=["outbox","signal"]) def myGenerator(self, max=10): "HypotheticalgeneratordecoratedwithnamedportsforIPC" for foo in xrange(0,10): self.send("outbox",foo) yield 1 self.send("signal",ProducerFinished()) yield 0 using: staticmethod def rhubarb(custard): print"Jelly",custard Order of evaluation of decorators is the same as for @pies and the short form (second version) only allows for just one decorator in that position. Still hunting down what's causing the inspect to not function as expected fail. (I'm pretty sure of where to look though :) Regards, Michael. -- Michael.Sparks at rd.bbc.co.uk British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From dave at boost-consulting.com Tue Aug 24 04:34:10 2004 From: dave at boost-consulting.com (David Abrahams) Date: 24 Aug 2004 01:34:10 -0700 Subject: Unpythonic Python Message-ID: <8a638f47.0408240034.653a92ff@posting.google.com> I started having some weird problems with Python recently; they're so weird that I can't begin to explain them. All I can do is describe the symptoms and hope someone else has a clue. So here goes: FreeBSD 4.2, Python 2.2.2. I have a nightly cron job that downloads the boost cvs tarball from SourceForge and bunzip2s it. For about a year everything worked with no problems. About a month ago the download started getting truncated with no error reported. Then bunzip2 reports corruption, of course. I took the salient part of the download script, and added a reporthook (undocumented in urllib, BTW) to the urlretrieve call: -- import urllib import os def dump(*args): print args #print 'downloading...' os.chdir('/tmp') urllib.urlretrieve('http://cvs.sourceforge.net/cvstarballs/boost-cvsroot.tar.bz2', 'boost-cvsroot.tar.bz2', dump) --- When a recent download was truncated, the last lines of the dump were: (1014, 8192, 34441987) (1015, 8192, 34441987) (1016, 8192, 34441987) (1017, 8192, 34441987) (1018, 8192, 34441987) (1019, 8192, 34441987) (1020, 8192, 34441987) (1021, 8192, 34441987) (1022, 8192, 34441987) (1023, 8192, 34441987) is 1023 a coincidence? Maybe; here's the tail of another failure: (2439, 8192, 34455413) (2440, 8192, 34455413) (2441, 8192, 34455413) (2442, 8192, 34455413) (2443, 8192, 34455413) (2444, 8192, 34455413) (2445, 8192, 34455413) (2446, 8192, 34455413) (2447, 8192, 34455413) (2448, 8192, 34455413) So I figured maybe we needed a newer version of Python. I asked my sysadmin at stlport.com to upgrade Python to the most recent release, and all of a sudden my incoming mail started looping (see below). I am classifying spam with SpamBayes and on my system the only way to get it sorted into IMAP folders after classification is to send it to myself. Only messages lacking an X-Spambayes-Classification get classified and sent back out, so I guess when Python was upgraded the classification stopped adding the headers? My sysadmin rolled Python back to 2.2.2 and the mail problems stopped. But I still have the truncated download problem. Any clues? Thanks in advance! -Dave -- From: Subject: Undeliverable mail: RE: What's wrong with this? To: Date: Mon, 23 Aug 2004 17:08:45 -0700 Failed to deliver to 'dave' mail loop: too many hops (too many 'Received:' header fields) Reporting-MTA: dns; stlport.com Original-Recipient: rfc822; Final-Recipient: system; Action: failed Status: 5.0.0 [3. text/rfc822-headers] Received: by stlport.com (CommuniGate Pro PIPE 4.2) with PIPE id 817189; Mon, 23 Aug 2004 17:08:45 -0700 Received: by stlport.com (CommuniGate Pro PIPE 4.2) with PIPE id 817183; Mon, 23 Aug 2004 17:08:26 -0700 Received: from [12.163.41.8] (HELO expressmail.office.meta) by stlport.com (CommuniGate Pro SMTP 4.2) with SMTP id 817122 for dave at boost-consulting.com; Mon, 23 Aug 2004 17:04:16 -0700 Received-SPF: error receiver=stlport.com; client-ip=12.163.41.8; envelope-from=agurtovoy at meta-comm.com Received: by expressmail.office.meta with Internet Mail Service (5.5.2653.19) id ; Mon, 23 Aug 2004 19:03:42 -0500 Message-ID: <838645D2D4A9A64ABD56D8C001F07E023533F9 at expressmail.office.meta> From: Aleksey Gurtovoy To: 'David Abrahams' Subject: RE: What's wrong with this? Date: Mon, 23 Aug 2004 19:03:42 -0500 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" From gj_carman at hotmail.com Sat Aug 28 17:03:13 2004 From: gj_carman at hotmail.com (Snake) Date: 28 Aug 2004 14:03:13 -0700 Subject: IDLE does not start on WinXP Message-ID: <2bc4a8b9.0408281303.4561e6eb@posting.google.com> I recently installed Python 2.3.4 on WinXP. The command line interpreter works fine, but the IDLE GUI will not start. I have both WinXP and McAfee firewalls disabled. When I run IDLE from a commandline I get the following traceback. Any suggestions would be appreciated. C:\Python23\Lib\idlelib>idle.py Traceback (most recent call last): File "C:\Python23\Lib\idlelib\idle.py", line 23, in ? idlelib.PyShell.main() File "C:\Python23\lib\idlelib\PyShell.py", line 1282, in main flist.pyshell = PyShell(flist) File "C:\Python23\lib\idlelib\PyShell.py", line 764, in __init__ self.interp.start_subprocess() File "C:\Python23\lib\idlelib\PyShell.py", line 364, in start_subprocess self.transfer_path() File "C:\Python23\lib\idlelib\PyShell.py", line 433, in transfer_path self.runcommand("""if 1: File "C:\Python23\lib\idlelib\PyShell.py", line 650, in runcommand self.rpcclt.remotequeue("exec", "runcode", (code,), {}) File "C:\Python23\lib\idlelib\rpc.py", line 214, in remotequeue return self.asyncreturn(seq) File "C:\Python23\lib\idlelib\rpc.py", line 238, in asyncreturn response = self.getresponse(seq, wait=0.05) File "C:\Python23\lib\idlelib\rpc.py", line 278, in getresponse response = self._getresponse(myseq, wait) File "C:\Python23\lib\idlelib\rpc.py", line 298, in _getresponse response = self.pollresponse(myseq, wait) File "C:\Python23\lib\idlelib\rpc.py", line 423, in pollresponse message = self.pollmessage(wait) File "C:\Python23\lib\idlelib\rpc.py", line 375, in pollmessage packet = self.pollpacket(wait) File "C:\Python23\lib\idlelib\rpc.py", line 347, in pollpacket if not self.ioready(wait): File "C:\Python23\lib\idlelib\rpc.py", line 337, in ioready r, w, x = select.select([self.sock.fileno()], [], [], wait) select.error: (10022, 'An invalid argument was supplied') From newsgroups at jhrothjr.com Thu Aug 5 11:46:05 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Thu, 5 Aug 2004 11:46:05 -0400 Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) References: <1646998998.20040804190026@MailBlocks.com> <10h34ivio5s2c21@news.supernews.com> <10h4c5iicgv7k74@news.supernews.com> Message-ID: <10h4lhutcuu6t41@news.supernews.com> "A.M. Kuchling" wrote in message news:jaWdnWcZkabb2Y_cRVn-vQ at speakeasy.net... > On Thu, 5 Aug 2004 09:06:01 -0400, > John Roth wrote: > > That was basically my comment about ctypes. AMK's > > blog entry referenced the ctype's documentation page, > > Heller's post (at > http://mail.python.org/pipermail/python-dev/2004-June/045139.html) wasn't > very informative, either; I assume ctypes needs to do 'func = > something_or_other(func)' as PyObjC does currently. I see; that's not very informative. What ctypes does is create a specialized object to represent a particular c function, variable, array or struct; then you use those objects as part of the interface when you call the c function you're going after. Possibly he's got something in mind to streamline the construction of the supporting objects for a given C API call. It does, however, seem like something that would be appropriate for function decorators. John Roth > > --amk From dan at hld.ca Tue Aug 17 22:29:04 2004 From: dan at hld.ca (Dan Cardamore) Date: 17 Aug 2004 19:29:04 -0700 Subject: Python and Weather.com References: <6491b0ab.0408121917.5103b770@posting.google.com> <411cc8e5$1_2@omega.dimensional.com> Message-ID: <2e8670bb.0408171829.1936046f@posting.google.com> mfuhr at fuhr.org (Michael Fuhr) wrote in message news:<411cc8e5$1_2 at omega.dimensional.com>... > faizans at gmail.com (Fazer) writes: > > > I made a small python script that gives the current weather conditions > > of a city that you give as an argument. > > You could also use pymetar. > > http://www.schwarzvogel.de/software-pymetar.shtml I wrote CurseTheWeather which has both an ncurses front end, and a python module that can give you access to the forecast data. The source is the same (xoap.weather.com). Check it out at (with screenshots for the ncurses gui): http://opensource.hld.ca/trac.cgi/wiki/CurseTheWeather If anyone is interested in writing wx/tk/gtk/windows/cocoa/other/guis then please let me know. The wx gui has been started. Dan From bart_nessux at hotmail.com Wed Aug 4 10:13:56 2004 From: bart_nessux at hotmail.com (Bart Nessux) Date: Wed, 04 Aug 2004 10:13:56 -0400 Subject: Perl's Crypt::PasswdMD5 In-Reply-To: References: Message-ID: Ajay wrote: > hi! > > the pycrypto package at http://www.amk.ca/python/code/crypto.html > has MD5 and a few other digests and other cryptography tools > > cheers > > -- > Ajay Brar, > CS Honours 2004 > Smart Internet Technology Research Group > > > Quoting Bart Nessux : > > >>Does Python have anything similar to Perl's Crypt::PasswdMD5??? >> >>I read about the crypt module... but it only does DES. Any plans to add >>md5 or other digests to it in the future? >> Thanks, I'll give it a try. From jzgoda at gazeta.usun.pl Sat Aug 7 15:37:08 2004 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Sat, 07 Aug 2004 21:37:08 +0200 Subject: Going the PL/1 way In-Reply-To: References: Message-ID: Mikl?s wrote: > Ok, seems like we have @decorators. It's a nice tribute to Intercal. But > I'd prefer #decorators. > > We have metaclasses for pleasure brain-melting. We have generators, > new-style classes and old-style classes. Lambdas are wonderful. > We do need real interfaces, not abused classes. Python still needs to have > inlined functions, macros and templates. Operator overloading is not enough, > one should be able to introduce new ones freely. There's a heavy demand for > terciary comparisons. Why don't we have a 'case' statement and 'do... repeat > ()'? > We cannot do without general closures, of course. Hm, automatic garbage > collection is sometimes fine but explicite memory allocation/deallocation is > really unavoidable for efficient programs. > Wait, pointers are a must! Static typing should have been introduced a long > time ago. You just cannot do without absolute address variables. > > Yes, I'm thorougly annoyed with creeping featurism. Man, you steal my thoughts! Most of features that made into Python after 2.1 are "just that", like "nobody has it, so we should" or "somebody has it, so we would too". The only thing I welcomed in 2.3 was some interpreter speedup, not new features. Is it really so much needed feature, that "clean, compact and readable" rule should be broken? Damn, to hell with decorators, noone I know even knows what it can be good for. Come on, guys, fix real problems like interpreter thread safety, improve performance, don't make us, "real-world software developers", screaming with every new release, please. -- Jarek Zgoda http://jpa.berlios.de/ From eurleif at ecritters.biz Sat Aug 21 20:56:30 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sat, 21 Aug 2004 20:56:30 -0400 Subject: __metaclass__ and __author__ are already decorators In-Reply-To: References: <2opgsoFd7807U1@uni-berlin.de> <2opp6gFdg3e7U1@uni-berlin.de> <2oq4keFd90euU1@uni-berlin.de> Message-ID: <2oq93oFdnrmoU1@uni-berlin.de> Paul Morrow wrote: > So when we define an __xxx__ attribute inside of a function, we are > trying to make a statement about the function --- we are not trying to > create a local variable. Therefore the Python system shouldn't create a > local variable in this case; it should create a function variable > instead (IMO). How do you think a newbie will react to magic behavior like that from the assignment operator based entirely on the name being assigned to? From tjreedy at udel.edu Fri Aug 13 16:27:30 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 13 Aug 2004 16:27:30 -0400 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: wrote in message news:3064b51d.0408130615.3fc4a760 at posting.google.com... > One of the most commmon reasons programmers cite for not trying Python I suspect that the main barrier is hearing or reading enough about Python to serious think about trying it. > is that indentation determines the program flow -- they think its weird. Giving that structured text (in English at least) routinely uses significant indentation (lists, outlines, block quotes) and that much algorithm pseudocode does the same (which was half the reason I called Python 'executable pseudocode'), I find it puzzling that so many find it 'weird' (if indeed that is true). > I wonder if there is a way to remove this initial barrier. Perhaps better explanation in the introductory materials might help. Do you have any suggestions? > Could an alternate source form be defined, 'Could' ? of course. And you are free to do so, and to write a preprocessor that converts the alternate form to standard Python, and even to distribute an intepreter that has it builtin, and even to promote FencePy as a 'Python variant for beginners' or as 'Transitional Python for the fence-bound'. > so that there are matching if-endif > and for-next constructs instead of significant indentation? If a block is too long to easily match indentation levels, I myself might add an unofficial '#end if xyz' (properly dedented) to help readers (including possibly myself in the future) visually and mentally close the block. The downside though is to make editing possibly slightly harder. > The alternate source form and the current form would result in exactly the > same .pyc file. What if the fences and indentation disagreed? > I'm not saying that Python's use of indentation is bad, I say that Python's use of indentation is good. > just that it stops many programmers from trying it. Perhaps. But it encourages others to try and adopt it and it is a key part of making Python code unusually readable, which was and is one of its main design goals. Terry J. Reedy From porky_pig_jr at my-deja.com Sat Aug 14 18:04:57 2004 From: porky_pig_jr at my-deja.com (Porky Pig Jr) Date: 14 Aug 2004 15:04:57 -0700 Subject: Decorators: an outsider's perspective References: <9ADC3170-EDAF-11D8-9F63-000A95B336F2@snowtide.com> Message-ID: <56cfb0e3.0408141404.1d0057b8@posting.google.com> Paul Morrow wrote in message > class Foo: > def blah(a, b): # this is clearly a static method > pass > > def blah(self, a, b): # this is clearly an instance method > pass > > def blah(klass, a, b): # this is clearly a class method > pass > > Python was built (successfully) on the assumption that obvious > interpretations of the code obviate the need for declarations. Why > wouldn't we continue with that mindset? > > Paul I don't think it's a good example. 'self' is a convention, not the reserved word. Nothing can prevent anyone from using some other word. Strictly speaking, the fact that the first parameter is called 'self' does not imply anything. Ditto for 'klass' (or rather 'cls' which is used by the number of references). Again, it's not a reserved word. What if I've decided to use parameter name 'cls' in static function? What if I've decided to use 'this' instead of 'self'? So - either we need some mechanism to enforce the keywords 'self', 'cls', or -- we back to square one: we need decorators. From pm_mon at yahoo.com Sat Aug 21 20:46:37 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sat, 21 Aug 2004 20:46:37 -0400 Subject: __metaclass__ and __author__ are already decorators In-Reply-To: <2oq4keFd90euU1@uni-berlin.de> References: <2opgsoFd7807U1@uni-berlin.de> <2opp6gFdg3e7U1@uni-berlin.de> <2oq4keFd90euU1@uni-berlin.de> Message-ID: Leif K-Brooks wrote: > Paul Morrow wrote: > >> And I don't agree that this would be assigning new 'meaning' to an old >> syntax. When a programmer creates a __xxx__ class attribute, he is >> not trying to create a normal 'class' attribute --- one the is >> inherited by instances of the class or that holds part of the 'state' >> of the class. Instead, he is trying to make a meta statement about the >> class (who wrote it, what happens during instance initialization, >> etc.). In that sense, the meaning associated with defining __xxx__ >> attributes would stay the same. > > > If we were talking about something like this: > > def foo(self): > pass > foo.__author__ = "Leif K-Brooks" > > then you would be correct. But when syntax normally used for assigning > to a variable magically assigns to an attribute if the variable name > starts and ends with "__", then it's an existing syntax (variable > assignment) being used for something new (attribute assignment). Why > should this: > > def foo(self): > bar = 42 > > mean anything different from this? > > def foo(self): > __bar__ = 42 Because the intent of the two assignments is quite different. Yes, their syntactic structure is similar, and what happens after they execute is similar, but the 'kind' of information the programmer is trying to represent is very different in the two cases. In the first example, the programmer intends for bar to be a local variable, used in some way by foo. In the second example, the programmer most definitely does *not* intend for __bar__ to be used by foo --- instead he is simply providing information *about* foo. This better illustrates the difference. def circumference(diameter): __author__ = 'Paul Morrow' __version__ = '0.1' pi = 3.14 return pi * diameter So when we define an __xxx__ attribute inside of a function, we are trying to make a statement about the function --- we are not trying to create a local variable. Therefore the Python system shouldn't create a local variable in this case; it should create a function variable instead (IMO). From nzanella at cs.mun.ca Thu Aug 19 19:38:14 2004 From: nzanella at cs.mun.ca (Neil Zanella) Date: 19 Aug 2004 16:38:14 -0700 Subject: PEP 318: Can't we all just get along? References: <20040817181725194-0400@braeburn.themorgue.org> Message-ID: Ville Vainio wrote in message news:... > >>>>> "Kevin" == Kevin Smith writes: > > Kevin> Bear with me, but I'd like to propose one more syntax that > Kevin> is simple, easy for newbies to understand, and nowhere near > Kevin> as powerful as the current PEP's syntax. However, it > Kevin> doesn't add incoherent, arbitrary syntax either. > > Kevin> def classmethod foo(x, y, z): > Kevin> pass > I don't even use static/classmethods, but I can imagine several > frameworks can use parametrized decorators to their advantage. Well, allow me to contribute my thoughts on staticmethod and classmethod: I am barely starting out with Python and my class objects are already loaded with so many foo = staticmethod(foo) statements. In other words these are very useful: they should be part of Python's syntax. Other than the above proposal, which I think is the most obvious thing that could be done, I would also like to contribute yet another syntax: class Foo: # stuff classmethods: # classmethods here staticmethods: # staticmethods here In the spirit of Python, this scheme would lead to even less typing on average than would be required with Kevin's solution, although I must admit that Kevin's solution was the very first thing that came to mind when I was looking for classmethods/staticmethods. staticmethods are very useful: you can pack related methods in a class and use them as getters for class objects which need not be differentiated among instances. It may even be, that due to python's class objects feature the user never cares to instantiate certain types of classes anyways. For instance, a class object with staticmethods can simply be used as a singleton object: very convenient, if it were not for this ugly staticmethod syntax. And you may ask, what are the advantages of using staticmethod inside a class as opposed to using plain methods? The answer to that question is polymorphism: Imagine a hierarchy of singleton classes derived from a base class with a common interface. The singleton class objects can then be processed polymorphically. Class objects, unlike class instances, are singletons by nature: what a convenient means of using singletons pythons offers us! class Person: def name(): return "Sorry, I'm just an abstract class." name = staticmethod(name) def favoMovie(): return "Monty Python's Flying Circus" favMovie = staticmethod(FavMovie) def favFood(): return "SPAM!" favFood = staticmethod(favFood) class JoeDoe(Person): def name(): return "Joe Doe" name = staticmethod(name) class JaneDoe(Person): def name(): return "Jane Doe" name = staticmethod(name) def favFood(): return "Eggs" favFood = staticmethod(FavFood) The other alternative is to attach methods to instances of a common class after they are created, which is also something that can be done in Python but not in most other languages. Note that the getters I have coded, in general may involve more complex logic than shown here, so that we really do need methods and not palin variables in such cases. Overall, allow me to say that OO stuff seems to be much more flexible in an interpreted environment such as Python than it is in compiled languages. Feedback welcome, Regards, Neil From http Sat Aug 21 23:59:35 2004 From: http (Paul Rubin) Date: 21 Aug 2004 20:59:35 -0700 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> Message-ID: <7x4qmv6cwo.fsf@ruckus.brouhaha.com> aahz at pythoncraft.com (Aahz) writes: > >It seems there are quite a few projects aimed to improve Python's > >speed and, therefore, eliminate its main limitation for mainstream > >acceptance. > > What makes you think speed is Python's primary limitation for mainstream > acceptance? Well, whenever I want to write a mainstream application and think of using Python, my first reaction is that Python is too slow... From pleaseSeeFooter at bottomOfEmail.com Sun Aug 1 05:18:04 2004 From: pleaseSeeFooter at bottomOfEmail.com (Eric Pederson) Date: Sun, 1 Aug 2004 01:18:04 -0800 Subject: flowcharting is automatic for Python via preprocessor Message-ID: <20040801011804.1002621623.pleaseSeeFooter@bottomOfEmail.com> "Rick Hilburger" wrote: > I have a program that > automatically draws a flow chart next to Python code so that you can see and > understand the flow among the lines of Python code. I use a slightly > different syntax for flow control than Python does, but the rest is regular > Python. I have numerous images to illustrate this. I think it would be a > new way to have code that is somewhat self-documenting. It could also help > Python be somewhat self-teaching, at least with respect to structured > control constructs and how they work. Neat idea! Perhaps this would be useful as a teaching tool for first year programming courses, helping students to visualize what the various statements do. Such things seem trivial once they are ingrained in one's thinking, but getting that initial comprehension may be more challenging than one remembers, and the flowchart just might help out. It does seem to add some visual complexity, however, which might not be an advantage for more experienced programmers... Eric Pederson http://www.songzilla.blogspot.com ::::::::::::::::::::::::::::::::::: domainNot="@something.com" domainIs=domainNot.replace("s","z") ePrefix="".join([chr(ord(x)+1) for x in "do"]) mailMeAt=ePrefix+domainIs ::::::::::::::::::::::::::::::::::: From jjl at pobox.com Tue Aug 10 16:50:54 2004 From: jjl at pobox.com (John J. Lee) Date: 10 Aug 2004 21:50:54 +0100 Subject: Exceptions as a Control Structure References: <411775aa$0$17867$626a14ce@news.free.fr> <41177b65$0$17857$626a14ce@news.free.fr> Message-ID: <87smauu381.fsf@pobox.com> [Peter Hansen] > Exceptions are also used by some as a mechanism for > returning information from subroutines, though it's > very likely the information will still be considered > "exceptional" in some way (think of it as an out-of-band > mechanism for returning special info). [Olivier Parisy] > Do you have some example of this in the standard library ? Not sure if this is what Peter had in mind, but grep for 'ValueError'. [Peter] > While some people object on stylistic grounds (or even > performance ones, in some cases) to such things, you > will likely find that exceptions are thrown around > by Python programmers more readily than you are used to. [Olivier Parisy] > That's what I wanted to know. OK. Control-structure-y uses (esp. within a single function) are much rarer than the ordinary use: a function signalling an exceptional condition to its callers. This ordinary use is certainly used more extensively in idiomatic Python code than is the case in many other languagesa. StopIteration is used a lot, I guess, but it's rare that you're actually concious of that fact. John From max at alcyone.com Fri Aug 13 19:35:34 2004 From: max at alcyone.com (Erik Max Francis) Date: Fri, 13 Aug 2004 16:35:34 -0700 Subject: !wtf ellipsis References: Message-ID: <411D5046.B5D16F02@alcyone.com> Christos TZOTZIOY Georgiou wrote: > Peter provided a link answering your questions. As a side note, I > have > used Ellipsis instead of None as a very handy last item put in queues > in > threaded programs (after all, "ellipsis" means "absence" or "lack" in > English :) Thus I avoid creating dummy classes to mark the end of > data... But as a sentinel, why would it be superior to None? -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ If you don't take chances, you can't do anything in life. -- Michael Spinks From jeff at ccvcorp.com Fri Aug 6 17:22:46 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 06 Aug 2004 14:22:46 -0700 Subject: Queue qsize = unreliable? In-Reply-To: References: Message-ID: <10h7tk82g3iiqe4@corp.supernews.com> Ames Andreas (MPA/DF) wrote: >Hi, > >Tim Peters wrote: > > > >>There's no use case I know of where knowing "the exact current size" >>is necessary, except inside the implementation of Queue (where it >>can know it, but at the expense of locking out all other threads for >>as long as it takes to compute the result). >> >> > >I've got one: If you have the special situation that there is only a >single consumer with potentially multiple suppliers (or similarly if >you have it the other way around), you could implement the consumer in >a non-blocking manner. Then it's not that important to get "the exact >current size" which would still be unreliable but it is important to >have a reliable empty method (or rather !empty() and full() are >reliable in this situation). I think Queue is reliable in this >respect but to get it additionally non-blocking you will have to roll >your own queue. > > No you don't. You simply execute a non-blocking get(), and be prepared to catch the Queue.Empty exception. Similarly, if you want a non-blocking producer, then you execute a non-blocking put() and catch the Queue.Full exception. That's really the only reliable way to tell whether the queue is empty or full, anyhow... Jeff Shannon Technician/Programmer Credit International From jack at performancedrivers.com Wed Aug 18 17:21:24 2004 From: jack at performancedrivers.com (Jack Diederich) Date: Wed, 18 Aug 2004 17:21:24 -0400 Subject: age of Python programmers In-Reply-To: <20040818211120.GA6522@unununium.org> References: <2ohpksF94tajU3@uni-berlin.de> <20040818211120.GA6522@unununium.org> Message-ID: <20040818212124.GA23725@performancedrivers.com> On Wed, Aug 18, 2004 at 05:11:20PM -0400, Phil Frost wrote: > I wonder what portion of > programmers these days have a real understanding of how the hardware > they manipulate works? From this thread so far it seems like such > knowledge is more common among Python programmers, which I find odd > since Python isn't exactly a low level language. Perhaps it's because no > one learns Python until becoming frustrated with 10 other languages? Or because the average age so far is well over 30; back then assembly was de rigueur and not much before that and you are physically flipping bits with a +12v probe (if you were lucky there was eight lights above the eight metal contacts). Until recently "computer science" was spelled "electrical engineering" and arguably before that "mechanical engineering". -Jack From npat at efault.net Mon Aug 16 15:19:44 2004 From: npat at efault.net (Nick Patavalis) Date: Mon, 16 Aug 2004 19:19:44 +0000 (UTC) Subject: Generators versus Coroutines References: Message-ID: On 2004-08-15, Michael Sparks wrote: > >> For me it would be *tremendously* usefull if one could yield across >> multiple levels of function calls. If this was supported, then most >> uses of O/S treads could be replaced by generators. > I didn't knew about Stackless or Greenlets. I will take a look at this, thanks! > > Indeed using the new decorator syntax you could probably simplify this to: > > def foobar(i): Yield(i) > > @generator > def g(n): > for i in range(n): > foobar(i) > Another excellent use for decorators! /npat From vinay_sajip at yahoo.co.uk Thu Aug 5 10:38:55 2004 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: 5 Aug 2004 07:38:55 -0700 Subject: logging / FileHandler References: Message-ID: <2e37dc1.0408050638.235af731@posting.google.com> > with the logging module, I am using the FileHandler formatter. > Is there a setting to stop the logger from putting the same message > more than once? So it would say: > > Message whatever > Repeated X times > If you really wanted this functionality, you could write your own handler derived from FileHandler. I assume you are not getting multiple messages because you added the same FileHandler multiple times? Vinay Sajip From Sibylle.Koczian at Bibliothek.Uni-Augsburg.de Thu Aug 5 08:09:23 2004 From: Sibylle.Koczian at Bibliothek.Uni-Augsburg.de (Sibylle Koczian) Date: Thu, 05 Aug 2004 14:09:23 +0200 Subject: MySQLdb select In-Reply-To: References: <9RPOc.2792$LI7.1058@newssvr27.news.prodigy.com> <21064255.0408020908.41357e52@posting.google.com> <2n9gmuFuhk8kU1@uni-berlin.de> <2nbn3pFv4865U1@uni-berlin.de> Message-ID: <2nembjF2dr7U1@uni-berlin.de> Dennis Lee Bieber schrieb: > > Except that the conversion function, .literal(), /does/ accept > a single item, a sequence (tuple OR list), or a mapping (dictionary). > The arguments are just passed through .execute(), which doesn't really > care one way or the other. > > Tediously, .execute() calls ._execute(), which has: > ... > try: > if args is None: > r = self._query(query) > else: > r = self._query(query % self.connection.literal(args)) > except TypeError, m: > ... > > Since .literal() accepts single objects (well, in truth, I'd > guess one would have to say that it is .escape() that processes the > arguments -- I can't say what that does, as it is likely in the binary > module. However, the actual forming of the final query string /is/ the > standard Python "string" % arg operator, which, in my experience, has > never complained about not being given a 1-tuple. > True. I had hopes that this might explain another riddle I couldn't solve: datefield is a database column of type date, and I execute two queries: a) SELECT * FROM mytable WHERE datefield = %s b) SELECT * FROM mytable WHERE datefield IN (%s, %s) case a): the parameter for %s can be a mx.DateTime object, a datetime.date object or the sort of DateTime object MySQLdb returns from another query; or it can be a string with format 'YYYY-MM-DD'. The results of the query are correct in every case. case b): the parameters must be strings of the form 'YYYY-MM-DD'. With all other sorts of parameters (DateTime objects, strings in other date formats) the query doesn't find anything. I tried this with different versions of MySQL, MySQLdb and Python, under Windows and Linux, always with the same results. Now I've looked at conn.literal(args) for a pair of DateTime objects and for a single one: >>> arg >>> arglist [, ] >>> conn.literal(arglist) ("'2004-07-29 00:00:00'", "'2004-07-07 00:00:00'") >>> conn.literal(arg) "'2004-06-18 00:00:00'" >>> s1 = 'SELECT * FROM fehllief WHERE fehltag IN (%s, %s)' >>> s1 % conn.literal(arglist) "SELECT * FROM fehllief WHERE fehltag IN ('2004-07-29 00:00:00', '2004-07-07 00:00:00')" >>> s2 = 'SELECT * FROM fehllief WHERE fehltag = %s' >>> s2 % conn.literal(arg) "SELECT * FROM fehllief WHERE fehltag = '2004-06-18 00:00:00'" >>> curs.execute(s1, arglist) 0L >>> curs.execute(s2, arg) 1L Why doesn't the query using IN find anything while the query using = does? The records are there, of course. Koczian From stephen at SPAM.theboulets.IS.BAD.net Sun Aug 29 10:45:02 2004 From: stephen at SPAM.theboulets.IS.BAD.net (Stephen Boulet) Date: Sun, 29 Aug 2004 09:45:02 -0500 Subject: Get all subdirs In-Reply-To: References: Message-ID: Florian Lindner wrote: > Hello, > how can I get all subdirectories of a given directory. os.listdir(dir) > doesn't differentiate between directories and files, os.walk seems to me a > bit overkill since it also descends in the subdirs. > Thx, > Florian I'm a fan of the path module: from path import path p = path("my_directory") l = [i.name for i in p.dirs()] Stephen From __peter__ at web.de Sat Aug 14 06:22:03 2004 From: __peter__ at web.de (Peter Otten) Date: Sat, 14 Aug 2004 12:22:03 +0200 Subject: Seperating CSV rows into new, seperate files References: Message-ID: TonyB wrote: > I've searched the group and need more information and guidance on this > issue I need to resolve next week. I work for the local school system > and I am working on a way to parse a CSV file of class lists from MS > Excel. It is a ~2MB file with all teachers and all their classes in > it. I thought I would use Python to do this since many people I know > tell me how great it is. The real sticking point is there are > duplicates of each teacher's classes embedded in the file (don't ask > why). I want to break up the source file into the seperate class > files without duplication and use the teachers name, coursecode and > section in the filename. > > Example Data: > Last Name First Name Grade Period Teacher Name > SMITH JOHN 8 1 JONES SALLY > > Student ID Course Code Course Title > 12345678 1234 ALGEBRA I > > Course Section Session > 1 0 > > > The course code and section number are the same in the duplicate > classes. The difference is that the session number changes. I'm > thinking that I will need to somehow iterate through the lines and > break the class when the course code changes and/or section change > (course codes can be the same but section numbers change with each > class). Then I have to monitor the session number to see if there is > a duplicate course code and section but a different session number > would indicate that the class is a duplicate. Essentially, the session > number will be 0, 1, or 2 for a total of three lists of the same > class. Hopefully that makes sense. Again don't ask why the data is > like this. > > My humble attempts have not been very successful. I've been trying > the csv modules to read the file but I am not sure how to procede > after that. > > Any guidance is greatly appreciated. >From the above I think you can use the (student id, course code, course section) tuple as the unique key when reading the data via the cvs module into a dictionary instead of a list. (For larger data you would need a database - the humble MS Access could have saved you from the trouble with duplicates in the first place, btw.) #untested STUDENT_ID = 5 COURSE_CODE = 6 COURSE_SECTION = 8 data = {} for row in csv.reader(instream): # you could do more processing here, # e. g. with nested course/student # dictionaries, but let's keep it simple data[row[STUDENT_ID], row[COURSE_CODE], row[COURSE_SECTION]] = row Subsequent sessions will then just overwrite data already in the dictionary. Note that you are throwing away some information as I am pretty sure (don't ask why :-) that the duplicates will not be completely identical. You can split this raw data into classes like so: #untested klasses = {} for row in data.values(): key = row[COURSE_CODE], row[COURSE_SECTION] if key in klasses: klasses[key].append(row) else: klasses[key] = [row] If you feel comfortable with (Python) classes you can make the dictionary values instances of a Row class that lets you access attributes by name, e. g. row.studentID instead of row[STUDENT_ID]. If these hints aren't sufficient to get you started it would help if you showed the code you already have to avoid duplicate effort. Peter PS: Who am I to talk about orthography, but it's "separate". From anthonybaxter at gmail.com Fri Aug 6 00:17:54 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 14:17:54 +1000 Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) In-Reply-To: References: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> Message-ID: The solution, if you don't like the syntax, is not voting. It's to propose an argument that Guido will accept, in favour of your preferred option. From della at toglimi.linux.it Tue Aug 17 14:52:37 2004 From: della at toglimi.linux.it (Matteo Dell'Amico) Date: Tue, 17 Aug 2004 18:52:37 GMT Subject: read input file a line as a list in python In-Reply-To: References: Message-ID: Yong Wang wrote: > Hi, All: > I need to read a input file as soucre to process data. Ideally > if I can read a line from input file as a list (coloumn separate by > white space), reorganize field in a line. Does python has this kind of > command ? > for example, I read a line has: > "IP MAC Date..." as a line from input file, How can I only get MAC ? > Thanks, > > Yong If I understood you correctly, this should do something like what you want: for line in file("filename"): ip, mac, date = line.split() print mac -- Ciao, Matteo From michael_mccracken at mac.com Tue Aug 3 19:33:26 2004 From: michael_mccracken at mac.com (Michael McCracken) Date: 3 Aug 2004 16:33:26 -0700 Subject: help: Unit test fixture returning the same object Message-ID: <9895e897.0408031533.26720ba0@posting.google.com> Hi, I have a problem with unittest.TestCase that I could really use some help with. I have a class File in module File. The important thing about File for this discussion is that it's simple - no pool of objects are involved, and subsequent invocations of File.File('filename') should return distinct objects (and indeed, they do on the command line). Also, __repr__ prints out the value of id(self) for File, so I can tell what's going on here.. I also have a suite of tests that test File in testFile.py Within, I have a TestCase subclass that looks like this: class FileReadingTestCase(unittest.TestCase): def setUp(self): self.testfilename = "filename" self.testfile = File.File(self.testfilename) print 'setup:', self.testfile def tearDown(self): print 'teardown:', self.testfile self.testfile.close() self.testfile = None print 'teardown:', self.testfile ... followed by a bunch of tests that use self.testfile. The problem is that in each test case, setUp and tearDown are called as expected according to the print statements, but they don't seem to have any effect after the first invocation. self.testfile is always the same instance as reported by id(). There are two strange things going on here: 1 - in tearDown(), self.testfile is indeed being set to None, but in the subsequent invocation of setUp(), self.testfile is pointing right back to the same object. 2 - Of course, you can't print the value of self.testfile in setUp() before it's assigned, that works as expected, but when calling the constructor for File, you get the same object with the same id. This doesn't happen in any other context, so I think there is something about the unittest framework (or just Python) that I don't understand. Does anyone have any insight? my python is 2.3, as distributed with Mac OS X 10.3 Thanks, -mike From ivoras at __geri.cc.fer.hr Thu Aug 5 13:11:11 2004 From: ivoras at __geri.cc.fer.hr (Ivan Voras) Date: Thu, 05 Aug 2004 19:11:11 +0200 Subject: psyco out of memory Message-ID: I have this simple *dumb* benchmark-like program: #import psyco #psyco.full() d = 0.0 for i in xrange(1000000000): d += i print d I though I'd use it to try out psyco, but no, when I enable the first two lines, python core-dumps: Fatal Python error: psyco: out of memory Abort (core dumped) Now this isn't a real-world application example, but it's certainly unexpected. Did psyco try to mimic range() and allocate 1G of integers? (I'm running python 2.3.4 on FreeBSD 5) -- What part of "Ph'nglui mglw'nath Cthulhu R'lyeh wgah'nagl fhtagn" don't you understand? From bh at intevation.de Fri Aug 13 11:23:39 2004 From: bh at intevation.de (Bernhard Herzog) Date: Fri, 13 Aug 2004 17:23:39 +0200 Subject: Idea for alternative use for @ References: <4L4Tc.6967$nu2.3787@fe2.texas.rr.com> Message-ID: "Paul McGuire" writes: > I thought it might be useful to include some sort of compiler directive like > a C++ pragma to represent this kind of compile-time meta information. And > it struck me that '@' would be an excellent marker for such a statement, > something like: > @tabsize 8 FWIW, that particular directive already exists. To set the tab width to 4 you can do either # :ts=4 or if you prefer emacs style: # tab-width:4 It's an undocumented (mis-)feature of CPython, though, IIRC. Bernhard -- Intevation GmbH http://intevation.de/ Skencil http://sketch.sourceforge.net/ Thuban http://thuban.intevation.org/ From heikowu at ceosg.de Tue Aug 10 08:49:07 2004 From: heikowu at ceosg.de (Heiko Wundram) Date: Tue, 10 Aug 2004 14:49:07 +0200 Subject: Best pattern/idiom In-Reply-To: <4edc17eb.0408092039.10958e11@posting.google.com> References: <4117c3d8$1@buckaroo.cs.rit.edu> <4edc17eb.0408092039.10958e11@posting.google.com> Message-ID: <200408101449.07108.heikowu@ceosg.de> Am Dienstag, 10. August 2004 06:39 schrieb Michele Simionato: > >>> import itertools > >>> def chop(it, n): > > ... tup = (iter(it),)*n > ... return itertools.izip(*tup) > ... > > >>> list(chop([1,2,3,4,5,6],3)) [(1, 2, 3), (4, 5, 6)] > >>> list(chop([1,2,3,4,5,6],2)) [(1, 2), (3, 4), (5, 6)] > >>> list(chop([1,2,3,4,5,6],1)) [(1,), (2,), (3,), (4,), (5,), (6,)] Problem being: >>> list(chop([1,2,3,4,5,6],4)) [(1, 2, 3, 4)] If you actually want to get back everything from iterator, better do something like: def ichop(it,n,rtype=list): it = iter(it) empty = False while not empty: retv = [] while not empty and len(retv) < n: try: retv.append(it.next()) except StopIteration: empty = True if retv: yield rtype(retv) >>> list(ichop([1,2,3,4,5,6],3)) [[1, 2, 3], [4, 5, 6]] >>> list(ichop([1,2,3,4,5,6],2)) [[1, 2], [3, 4], [5, 6]] >>> list(ichop([1,2,3,4,5,6],1)) [[1], [2], [3], [4], [5], [6]] >>> list(ichop([1,2,3,4,5,6],4,tuple)) [(1, 2, 3, 4), (5, 6)] >>> list(ichop([1,2,3,4,5,6],4)) [[1, 2, 3, 4], [5, 6]] Heiko. From franz.steinhaeusler at utanet.at Sat Aug 7 17:02:26 2004 From: franz.steinhaeusler at utanet.at (Franz Steinhäusler) Date: Sat, 07 Aug 2004 23:02:26 +0200 Subject: Killing children References: <87smb0w4ln.fsf@debian.laymusic.org> <87d624vxt2.fsf@debian.laymusic.org> Message-ID: <3kgah05savr9kek2r3fgqv56de5tn1edgl@4ax.com> On Fri, 06 Aug 2004 16:03:37 -0400, Laura Conrad wrote: > Stefan> Hi Laura, > Stefan> what a terrible subject line! ;-) > >I used to think that when I first started using UNIX in the mid 80's. >But I am now a hardened child-killer. As for the subject line; I thought at first glance, it was spam. strange kind of humor. SCNR -- Franz Steinhaeusler From rnichol_rrc at yahoo.com Thu Aug 26 14:09:31 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Thu, 26 Aug 2004 13:09:31 -0500 Subject: Larry Wall & Cults In-Reply-To: <412e0b7b.7894449@news.ecn.ab.ca> References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <412e0b7b.7894449@news.ecn.ab.ca> Message-ID: John Savard wrote: > They did, though, have to select from the German people those who > would operate the concentration camps. Which where the afraid ones or the ones that actually believed in him for one reason or another. Yes, some people didn't need brain-washing to believe him. I know it's a radical idea that some people are racist, but it true! > As for the masses, it was enough that they were afraid to try to do > anything to stop it. Perhaps you should look into the history books a little closer. There was this thing call the resistance in *all* the countries you know, not to mention the anti-nazi publications in the papers during his rise to power. And without those resistance fighters, the allies might have failed in there endeavour. Why did you even give an actual reply to this guy anyway? From b.niemann at betternet.de Mon Aug 16 05:41:35 2004 From: b.niemann at betternet.de (Benjamin Niemann) Date: Mon, 16 Aug 2004 11:41:35 +0200 Subject: Displaying images stored as binary in MySQL In-Reply-To: References: Message-ID: >>>How can this be done? Images are stored in a LONGBLOB field. When I >>>try to display them, it prints out the binary data as it is... >> >>Display where? On local screen, in a webbrowser? >>Assuming the first one, see post by Tom. >>Assuming the second one (you're writing a cgi,mod_python... program), >>did you set the content-type in the http header correctly? > > In a webbrowser... > this is my code... > > #!/usr/bin/python2.3 > > print 'Content-Type:image/jpeg\n\n' You must use '\r\n' to terminate header lines. I'm not really sure, but maybe there should also be a spacing between ':' and 'image/jpeg'... If you are using e.g. FireFox as a browser, you can user 'View Page Info' to see, if the browser correctly understands, what you are trying to tell it ('Type' should say 'image/jpeg'). > import blakHtml, sys > sys.stderr = sys.stdout > import MySQLdb > import urllib > import cgi > import time > prevPg=blakHtml.HTMLDocument() > newConnection=MySQLdb.connect(host='localhost', user='blaktyger', \ > passwd='linux4ever', db='photoFamille') > curseur=newConnection.cursor() > > sqlCmdFr="""SELECT * FROM photo""" > curseur.execute(sqlCmdFr) > resultats = curseur.fetchall() > p=0 > for val in resultats: > p=p+1 > #print '' THIS DOES NOT WORK > print val[5] > newConnection.close() > I know there is no HTML code but this is just a test... val[5] contains the raw image data (not a path), correct? Does 'photo' contains more than one image? Concatenating several images into one bytestream, is definitly not what you want. From squirrel at WPI.EDU Fri Aug 27 11:37:38 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Fri, 27 Aug 2004 11:37:38 -0400 Subject: Call for signatories for J2 In-Reply-To: References: Message-ID: I give a vote FOR this proposal. Good job putting this all together. - Chris King From steven.bethard at gmail.com Thu Aug 5 20:17:39 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: 5 Aug 2004 17:17:39 -0700 Subject: Decorator keyword Message-ID: I mentioned in a previous post that I'd much prefer some sort of keyword as a decorator indication than a character like @ (or the recently suggested |). A promising note on python-dev: http://mail.python.org/pipermail/python-dev/2004-August/047001.html > Perhaps this could be addressed by requiring "from __future__ import > decorators", for one release, just like was done for "yield". I > expect that this would be acceptable to the ObjC folks, too. It > wouldn't be my favorite, but I won't rule it out just because of the > new keyword (and yes, this is a softening of my position on new > keywords). > > --Guido van Rossum (home page: http://www.python.org/~guido/) I was just going to let this go because I thought it had been shut down, but as it seems to have been reopened, I'd love to see something like: with classmethod with returns(int) def func(*args, **kwds): return 1 Or if you don't like so many lines: with [classmethod, returns(int)] def func(*args, **kwds): return 1 Or perhaps, if you like to see the def by itself: def func(*args, **kwds) with [classmethod, returns(int)]: return 1 Really, I'd be much happier with any of these than any of the solely symbol-based versions. Neither [] alone after a function def or '@' before one reads clearly to me as an indicator of decoratorhood. I've always liked that Python tries to be human-readable (e.g. "for x in lst" reads almost like English). If at all possible, I'd like decorators to be the same way. In fact, while I've only used 'with' above (because it was non-'as' keyword suggestion in the wiki), I'd be just as happy (maybe happier) with 'decorate' or 'deco' or something along those lines that would read even easier. Steve From newsgroups at jhrothjr.com Fri Aug 6 09:05:57 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 6 Aug 2004 09:05:57 -0400 Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) References: <1646998998.20040804190026@MailBlocks.com> <10h34ivio5s2c21@news.supernews.com> <10h4c5iicgv7k74@news.supernews.com> Message-ID: <10h70hdbbuhpfa8@news.supernews.com> "Michael Hudson" wrote in message news:m3wu0csetn.fsf at pc150.maths.bris.ac.uk... > This reply was a touch more hostile that I was expecting; if I've hit > some nerve, sorry, if not, err, can you relax a bit? > > "John Roth" writes: > > > "Michael Hudson" wrote in message > > news:m3pt65g4hb.fsf at pc150.maths.bris.ac.uk... > > > > > Well, that would be because that's impossible :-) > > > > I wish you'd have told me that before I did it. As I said in > > a prior post, I had to put a general metadata facility into > > PyFIT, and it's working quite nicely, thank you. > > OK, poor choice of words. > > [snippity] > > > > What kind of metadata do you want? > > > > Type and other declaration information for any identifiers > > that will be referenced in the FIT tests. Other information > > includes things like precision for floating point numbers, > > strings that are accepted as "true" or "false" for booleans, > > the subtype for lists and tuples, references to custom > > type adapters and other stuff. > > So, you would like to write > > class Thiny(object): > @attribute(type=float, precision=3) > a = 1.23 > > ? > > I really don't see how you could make that work. attribute() could > return something that was called with the dictionary being inserted > into, the string 'a' and the value 1.23, but... ick. I don't think I > like that idea. What would you find helpful? Well, what I need here is very simple. If the FIT test contains a column labeled "a", then I need to find the type. If it's a float, I need to find the default precision for the compare. (Actually, float is a poor choice here - I fixed the need to have a precision by using the precision information in the text version of the float, but that's a different conversation.) What I'm doing right now is this: class fubar: _typeDict = {} _typeDict['a'] = "float" _typeDict['a.precision'] = 3 Note that I'm not defining 'a' on the class level. Whether or not I need a default value is a purely tactical decision that's orthogonal to the need for metadata in this application. A somewhat better (if whimsical) example of the need for structured metadata is: _typeDict['b'] = "boolean" _typeDict['b.false'] = "fubar" This makes the boolean type adapter accept the string 'fubar' as 'false'. (It doesn't make it print it that way, though.) Or a much more pedestrian example: _typeDict['d'] = "date" _typeDict['d.parse'] = "some %format string" _typeDict['d.print'] = 'some other %format string' The operands being, of course, something you can feed to the appropriate functions in the time or datetime modules. Notice that in all three cases I want to associate several pieces of metadata with an identifier in the class. I don't want to associate it with a particular object (although there are other applications that would want to do that, especially for functions). Also note that one of the two pieces of metadata is probably generally useful (the type). The other is highly specific to my application. John Roth > > Cheers, > mwh > > -- > ... but I'd rather not reinvent the wheel if I don't have to. On > the other hand, if the currently instantiated version of the wheel > consists of a square rock covered with moss, I might as well just > start fresh. -- Roy Smith, comp.lang.python From stefan at eischet.com Fri Aug 6 02:44:10 2004 From: stefan at eischet.com (Stefan Eischet) Date: Fri, 6 Aug 2004 08:44:10 +0200 Subject: tweaking @decorator syntax - yet another syntax In-Reply-To: <1091715445.9931.17.camel@mango.cmc.ec.gc.ca> References: <1091715445.9931.17.camel@mango.cmc.ec.gc.ca> Message-ID: <05C25635-E774-11D8-BDA6-000A95857E5C@eischet.com> Hi, I don't know if this particular syntax has been discussed already... please feel free to bash me if it was. ;-) How about using "is" after the def? class spam(object): def ni(self) is classmethod: # takes a decorator pass def foo(self) is (classmethod, synchronized): # or a tuple of decorators pass combination = (classmethod, strange, very_long_description, wraps_nicely, blah_blah) def bar(self) is spam.combination: # another tuple of decorators pass def bar2(self) is spam.combination: pass I think this is quite easy to read and, in comparison to other techniques, allows you to first define 'types' of decorated functions (like spam.combination or perhaps (Win32API, lives_in_a_dll,)). I have no idea if it can be easily implemented, though. Regarding the original post below, concerning decorated classes: superuseful = (gives_milk, mows_your_lawn, pays_your_rent) class foobar(spam) is superuseful: pass Just my 2 cents. Cheers, Stefan Eischet On 05.08.2004, at 16:17, John Marshall wrote: > On Thu, 2004-08-05 at 08:41, Sandy Norton wrote: >> On 4 Aug 2004, Christopher T King wrote: >> >>> Of course, I prefer the nested block idea better (either with a new >>> keyword or new syntax), but I don't see those (especially the syntax >>> one) >>> flying anytime soon. >> >> I know further discussion of this topic is feeling futile, but one >> can only hope. >> >>> Unless someone can come up with an idea everyone can agree on Real >>> Soon >>> Now, I think the whole idea should be dropped and wait until 3.0. >>> We'll >>> have plenty of time to argue about it then. >> >> Agreed. >> >>> Sorry about the long rant, but it felt good to get that all off my >>> chest. >> >> Please, we need more rants like yours. Now if they could somehow >> collectively become a 'public outcry' (-; >> >> I realize my hasty initial post didn't actually show the present 2.4 >> form, >> so I've included it and added your variations for the sake of >> comparison: >> > > With the current choice and the list of alternatives you gave, > two things struck me about the location of the decorators > in the current choice: > 1) They seem to be in the wrong place with respect to > what they are affecting. > 2) Can decorators easily be extended to apply to class > and module? > > Whether or not the @ or some other operator/keyword/etc. is > used, what is more easily understandable/readable? > ----- > class Klass: > def __init__(self, name): > self.name = name > > @staticmethod > def statmethod1(x): > return x > > @classmethod > def classmethod1(cls): > return cls > > @funcattrs(name='GvR', language='python') > @log(file='func.log') > def sayhello(self): > print 'hello python world' > ----- > or > ----- > class Klass: > def __init__(self, name): > self.name = name > > def statmethod1(x): > @staticmethod > > return x > > def classmethod1(cls): > @classmethod > > return cls > > def sayhello(self): > @funcattrs(name='GvR', language='python') > @log(file='func.log') > > print 'hello python world' > ----- > > If the decorators are metadata, that may be extended to affect > not only functions or methods, but classes, and modules(?), I would > think that wherever a variable or function call would go that > would affect the function, method, class, or module, is the > right place for a decorator. > > In the alternative above, it _may_ be that the decorators would > only be valid if they are located in specific locations, e.g., > before any non decorator (or comment, or __doc__ information) > statements. > > John > > -- > http://mail.python.org/mailman/listinfo/python-list > > // stefan at eischet.com // From ivan at ivan-herman.net Sat Aug 14 08:54:18 2004 From: ivan at ivan-herman.net (Ivan Herman) Date: Sat, 14 Aug 2004 14:54:18 +0200 Subject: python and XML resources In-Reply-To: References: Message-ID: <411e0b6e$0$94697$d5255a0c@news.wanadoo.nl> Essentially, PyXML implements the DOM specification of W3C. Once one understands the way the abstract IDL specfiication in W3C's DOM are mapped onto Python constructs, I think the simplest is to rely on the W3C documents, see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html I hope this helps Ivan Ajay wrote: > hi! > > does anyone know of good online resources on XML processing in Python. I am > using the PyXML package and have read the introductory XML HOWTO. > what i am looking for is a more detailed and comprehensive coverage of the > entire package - all the classes and functions etc > > cheers > ajay > > > > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. From richardjones at optushome.com.au Wed Aug 18 19:36:44 2004 From: richardjones at optushome.com.au (richard) Date: Thu, 19 Aug 2004 09:36:44 +1000 Subject: age of Python programmers References: Message-ID: <4123e80c$0$11790$afc38c87@news.optusnet.com.au> Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... 32, been using it for a decade. Richard From jaydonnell at yahoo.com Mon Aug 23 21:57:06 2004 From: jaydonnell at yahoo.com (Jay Donnell) Date: 23 Aug 2004 18:57:06 -0700 Subject: urllib hangs References: Message-ID: Don't you have something better to do with your time? I missed that last sentence because I was at work and trying to do a few things at once. From eric at enthought.com Mon Aug 16 13:42:11 2004 From: eric at enthought.com (eric jones) Date: Mon, 16 Aug 2004 12:42:11 -0500 Subject: ANN: Python/Scientific Job openings at Enthought Message-ID: <4120F1F3.4020006@enthought.com> Hey Folks, Enthought continues to grow, and we're hiring again. There are several positions open, and most of them involve python+scientific computing. A couple of the positions also involve support of SciPy. I'm very interested in finding a person for the "scientist" job posting that is both able to work well with our customers and also has the personality and interest to work with the SciPy community to help push the library forward. More information is available on our web site. http://www.enthought.com/careers.htm Our current development efforts are in the areas of electromagnetics, geophysics, and graphics (2D and 3D). If you have any questions, please feel free to contact me. Please forward the link to anyone you feel might be interested. thanks, eric From jerf at jerf.org Sun Aug 22 02:44:30 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Sun, 22 Aug 2004 06:44:30 GMT Subject: Alternative decorator syntax - keyword choice References: Message-ID: On Sat, 21 Aug 2004 21:51:09 -0700, Robert Brewer wrote: > I'd be most interested to hear arguments _against_ "declare", if there > are any. My first objection would be that decorators aren't "declarations"; that is one use but not the only one. The flip side is that I doubt that any one word will ever capture as a reasonable verb what they are doing, so I'm not sure this argument is meaningful, as it applies equally to all proposals, up to and including "decorate". ("Decoration" is the mechanism, but it is not always the result.) I'd have to say "transform" is probably the best candidate here; while not all uses of decorators are transforms (like attaching pieces of metadata), it at least brings to mind the correct implementation, which is the passing of the method through a function. "declare" brings to mind attaching a piece of data to the function or making a statement about the function to the compiler, without changing the underlying function. Ditto "apply". "decorate" brings either nothing to mind, or some vision of the Design Pattern which really isn't right. "as" seems to imply some sort of syntactic change, and only works AFAICS for staticmethod and classmethod. "as: author('Steve')" doesn't make much sense. To sum up, *all* keywords are insufficient, and I think there are only two choices, depending on the goal: "transform" to give a hint about what is really happening, or "decorate" on the grounds that there *is* no ready-made keyword and it is reasonbly easy to attach whatever Pythonic connotations to the word we choose; witness "generators". (Apologies if this has been mentioned before; I've been trying to keep up but I have failed.) From ellisjb at my-deja.com Sat Aug 7 01:23:59 2004 From: ellisjb at my-deja.com (ellisjb at my-deja.com) Date: 6 Aug 2004 22:23:59 -0700 Subject: Paul Graham on Python hackers In-Reply-To: <3064b51d.0408061127.32536826@posting.google.com> Message-ID: Yeah, but Graham goes on to lump perl in with python, so he clearly doesn't know what he's talking about. :) (In all seriousness I think python and java have a lot more in common than python and perl.) -Jonathan Original Message Follows: > Paul Graham's recent book "Hackers & Painters" may be interesting > readers for Python programmers. He likes flexible languages like > Python, although Lisp is his favorite. Here is a quote from his book, > also online at http://www.paulgraham.com/gh.html , where he contrasts > Python and Java programmers. He is opinionated :). > > "When you decide what infrastructure to use for a project, you're not > just making a technical decision. You're also making a social > decision, and this may be the more important of the two. For example, > if your company wants to write some software, it might seem a prudent > choice to write it in Java. But when you choose a language, you're > also choosing a community. The programmers you'll be able to hire to > work on a Java project won't be as smart as the ones you could get to > work on a project written in Python. [2] And the quality of your > hackers probably matters more than the language you choose. Though, > frankly, the fact that good hackers prefer Python to Java should tell > you something about the relative merits of those languages. From michael at stroeder.com Thu Aug 26 09:16:29 2004 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Thu, 26 Aug 2004 15:16:29 +0200 Subject: Converting hex string to an integer In-Reply-To: References: <412d9e18$0$22821$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: Peter Hansen wrote: > Rick Holbert wrote: > >> Derek Fountain wrote: >> >>> Given the character string "0x00A1B2C3" arriving at sys.argv[1] how do I >>> convert that to an integer which I can do some math on? >> >> i = eval(sys.argv[1]) > > That's dangerous advice to a newbie if not qualified carefully. > > Derek, "eval" could be the source of serious security problems > if you don't understand its power. Yes, eval() is risky! Try to get rid of eval() or you MUST protect each and every call to eval() with paranoid parameter checking! int(sys.argv[1],16) would be a better approach here... >>> int("0x00A1B2C3",16) 10597059 >>> int("__import_('os').system('rm -rf /')",16) Traceback (most recent call last): File "", line 1, in ? ValueError: invalid literal for int(): __import_('os').system('rm -rf /') >>> Ciao, Michael. From kjetilho at yksi.ifi.uio.no Fri Aug 27 21:05:11 2004 From: kjetilho at yksi.ifi.uio.no (Kjetil Torgrim Homme) Date: Sat, 28 Aug 2004 03:05:11 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1ry8k0d2az.fsf@rovereto.ifi.uio.no> <10iv0kid2ig9ka6@corp.supernews.com> Message-ID: <1rpt5ccbso.fsf@rovereto.ifi.uio.no> [Jeff Shannon]: > > The irony of [this] being said in defense of adding braces (even > optional ones) to Python is truly awe-inspiring. please provide an argument rather than engage in ad hominem attacks. -- Kjetil T. From max at alcyone.com Fri Aug 13 19:36:57 2004 From: max at alcyone.com (Erik Max Francis) Date: Fri, 13 Aug 2004 16:36:57 -0700 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: <411D5099.A524BA01@alcyone.com> Peter Hansen wrote: > I think you're right on both counts. For me, the adaptation > period was roughly ten seconds... Particularly with emacs mode. I didn't have to worry about indentation; my editor handled that for me. -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ If you don't take chances, you can't do anything in life. -- Michael Spinks From sridharinfinity at gmail.com Sun Aug 22 08:04:16 2004 From: sridharinfinity at gmail.com (Sridhar R) Date: 22 Aug 2004 05:04:16 -0700 Subject: Python future performance and speed In-Reply-To: Message-ID: Python is used in a fps Windows game called 'Blade of Darkness'. Except the core engine part (written in C/C++), everything else is written in Python-1.5.2 From bitshadow at yahoo.com Fri Aug 13 16:39:04 2004 From: bitshadow at yahoo.com (Michael Scarlett) Date: 13 Aug 2004 13:39:04 -0700 Subject: Why I love python. References: Message-ID: Anthony Baxter wrote in message news:... > On 12 Aug 2004 17:05:34 -0700, Michael Scarlett wrote: > > [ pie decorators ] > > Am i the only one with a > > visceral reaction to this thing??? > > So did you have a similar reaction on first hitting the indentation for > blocks? I know I dimly recall thinking that this was very strange and > horrible (dimly, because it was 1992 or 1993). one of the first books I read on python was Magnus lie Hetland's Practical python. http://hetland.org/writing/practical-python/ in the introduction he had a few quotes. "A C program is like a fast dance on a newly waxed floor by people carrying razors" "C++: hard to learn and built to stay that way" "Java is, in many ways, C++" "And now for something completely different....." the last was his intro to learning Python. When the trs-80 was out from radio shack, i used to code in basic on it. I lost interest in computers and only picked it up a few years ago. I investigated python and fell in love with the language. It's elegance, its simplicity (at least for the programmer) and its sheer delight to code in. I don't work in the IT field, and programming isn't my bread and butter. But just because its so fun, python brought me back into computers - i've created a a few websites with python on the back end, manipulated files and a few other projects for intellectual curiousity and for my day to day work and home life easier. As a result of learning and coding in python, I wanted to learn more about it, and so I turned to C, and am now actively learning it simply to learn how to integrate and build on pyton. I tolerate C's ugliness because i know the end result is a labour of love? when I can work with it and python. Silly maybe, but i'm going on emotion here, not logic. Python is simply fun to code in, and when its fun your more productive and excited to learn and tackle new problems cause your not bogged down in remebering how the increment(++) operator works for pointers in a particular function that supposed to dynamically allocate memory. terminating every statement with a ";" or manipulating fgets to discard the '\n'. yada yada yada..... The point is python just works. someone once said python is runable pseudocode. And it works, and works good at that. I couldn't agree more. I think and then I code. simple. addenum: i've had this article bookmarked for some time because once you read it, you have to wonder are they talking about python. because you realise python is there already. for those of you interested to read it and comment on it: http://archive.gamespy.com/legacy/articles/devweek_b.shtm thats my $0.02 From geoff at variosoft.com Sun Aug 8 05:18:42 2004 From: geoff at variosoft.com (Geoff Caplan) Date: Sun, 8 Aug 2004 10:18:42 +0100 Subject: Compiling disutil modules on Windows In-Reply-To: <13185971049.20040808082256@variosoft.com> References: <13185971049.20040808082256@variosoft.com> Message-ID: <694837405.20040808101842@variosoft.com> Hi folks, I have S?bastien Sauvage's example extension compiled and working. For the record, here is what I did, updated for Python 2.3. For the gory details, see: http://sebsauvage.net/python/mingw.html 1) Install MinGW - Go to http://www.mingw.org/download.shtml - Find the current version of MinGW. At the time of writing, this is MinGW-3.1.0-1.exe. It's around 14 megs. - Run the install - Rename the MinGW directory to gcc, if desired 2) Install SWIG - Go to http://sourceforge.net/project/showfiles.php?group_id=1645 You are looking for SWIGWIN. - rename the installed directory to Swig, if desired 3) Add gcc and Swig to your Autoexec.bat file This is normally found at C:\Autoexec.bat Mine looked like this: SET PATH=c:\gcc\bin;%PATH% SET PATH=c:\Swig;%PATH% I rebooted to activate these paths. If you knew Windoze better than I do, there is probably a more elegant way to do this. 4) Copy python23.dll to your Python libs directory Search C:\ for python23.dll. On Win2000, you will find it in c:\WINNT\system32\ Copy it to C:\Python23\libs\ 5) Compile a test extension ------------------------------------------ - Create the setup.py file (note the underscore on the extension name: this seems to be a requirement) # setup.py import distutils from distutils.core import setup, Extension setup(name = "Simple example from the SWIG website", version = "2.3", ext_modules = [Extension("_example", ["example.i","example.c"])]) ------------------------------------------ - Create the example.c file /* File : example.c */ #include double My_variable = 3.0; int fact(int n) { if (n <= 1) return 1; else return n*fact(n-1); } int my_mod(int x, int y) { return (x%y); } char *get_time() { time_t ltime; time(<ime); return ctime(<ime); ------------------------------------------ - Create the example.i file /* example.i */ %module example %{ /* Put header files here (optional) */ %} extern double My_variable; extern int fact(int n); extern int my_mod(int x, int y); extern char *get_time() ------------------------------------------ - Now launch your dos shell and cd to the directory containing your example files. - Run the command: python setup.py build -cmingw32 If all goes well, this will create a directory "build" in the same directory as your files. You will find your new dll "_example.pyd" under lib.win32 - Copy the dll to E:\Python23\DLLs\ 6) Run your test extension - Launch a Python shell and run: >>> import _example >>> _example.fact(5) 120 >>> _example.get_time() 'Sun Aug 08 10:09:25 2004\n' I tried renaming the extension without the leading underscore but this generates an error. I am new to Python: perhaps a SWIG guru could explain why the underscore is required, or if not required, how it can be avoided? Hope someone finds this useful... ------------------ Geoff Caplan Vario Software Ltd (+44) 121-515 1154 From noone at here.com Mon Aug 23 11:18:56 2004 From: noone at here.com (M. Clift) Date: Mon, 23 Aug 2004 16:18:56 +0100 Subject: Making different things equal References: Message-ID: Cheers Wes, That works a treat. Thanks, Malcolm From simoninusa2001 at yahoo.co.uk Sat Aug 7 05:42:16 2004 From: simoninusa2001 at yahoo.co.uk (simo) Date: 7 Aug 2004 02:42:16 -0700 Subject: Prothon is switching to the .NET platform References: <000401c47b59$32539220$0d01a8c0@MarkVaio> Message-ID: <30260531.0408070142.7e87a655@posting.google.com> Michel Claveau wrote: > I understand ; but, perso, I think : "it's a good new" (because it is a > certain guarantee of interworking). Yeah, I wasn't interested in Prothon until I saw this - it really didn't offer me anything to switch from Python, but maybe this does, although I expect I'll prefer IronPython, as it's "real" Python, not "kinda" Python.... Hey with any luck, @decorators won't be implemented in Prothon.NET ;-) From ptmcg at austin.rr._bogus_.com Sun Aug 22 18:27:43 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Sun, 22 Aug 2004 22:27:43 GMT Subject: Python is to C as letters are to words. References: Message-ID: "Gary Herron" wrote in message news:mailman.2164.1093201904.5135.python-list at python.org... > On Sunday 22 August 2004 11:55 am, r holland wrote: > > My nine word description of the python language. > > Huh ... Either you've got that backward, or I completely misunderstand > what you're trying to say? > > Maybe Gary meant "letters" like when I write a letter to my wife, it is composed of words, so words are building blocks which one uses to compose letters. ? :) Just kidding, it's a good intention. -- Paul (Just looking for a little levity on c.l.py today... Everyone is getting so *serious*!) From peter at engcorp.com Tue Aug 17 12:11:38 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 17 Aug 2004 12:11:38 -0400 Subject: serial and threads In-Reply-To: <39ba6e78.0408170554.4b6b46bf@posting.google.com> References: <39ba6e78.0408170215.59f5bfc0@posting.google.com> <39ba6e78.0408170554.4b6b46bf@posting.google.com> Message-ID: Silke wrote: > I already found a solution using 'threading' instead of 'thread' :-) Are you positive that is really a solution? If the original problem was truly because of a thread-safety issue, then it's most likely, I think, that it was a race condition and that it could very well re-appear in the future. The "threading" module is mostly just a higher level API on top of the "thread" module, so that change alone seems unlikely to solve the issue, unless there is code in serialwin32 specifically to do the proper locking when the threading module is used... -Peter From jjl at pobox.com Mon Aug 2 19:10:11 2004 From: jjl at pobox.com (John J. Lee) Date: 03 Aug 2004 00:10:11 +0100 Subject: Plethora of Pythons (was: Re: IronPython-0.6 is now available!) References: <278de0e.0407281353.27b6a457@posting.google.com> <4108710c@news0.ucc.uconn.edu> <30260531.0407290958.3c97aa70@posting.google.com> Message-ID: <87fz75uofg.fsf_-_@pobox.com> simoninusa2001 at yahoo.co.uk (simo) writes: > flacco wrote: > > > > IronPython is currently at a pre-alpha stage suitable for > > > experimentation but not for serious development work. > > Yeah, very pre-alpha from the few tests I did, but I'm very excited > about this, especially as it seems the Parrot guys have given up on > Python :-( [...] Hey, I just realised how many Python implementations there are now: Useful: CPython Jython Stackless psyco On their way: IronPython PyPy parrot? Starkiller? Not such a short list. Maybe standardisation committees are just round the corner. Oh joy. and a few close descendants, of course: Pyrex Prothon Boo Vyper (defunct) John From tismer at stackless.com Mon Aug 9 06:09:52 2004 From: tismer at stackless.com (Christian Tismer) Date: Mon, 09 Aug 2004 12:09:52 +0200 Subject: Going the PL/1 way In-Reply-To: References: Message-ID: <41174D70.2080601@stackless.com> Harald Massa wrote: > Mikl?s, > > >>>I do not understand at all what's that decorators thingy, but I know >>>that girls often put some deco into flats and it really looks cosy >>>after, so I assume that decorators are not on the dark side of the >>>source. > > >>The rest of the novelties in v2.4 are more or less fine with me, too. >>But IMHO decorators are exactly Dark Code Wader stuff. Basically it's >>about self-modifying code. Ooh, this is truely too much fear. Decorators are about modification of how code is understood, but not modification. [ If it were so, then I'd be probably much more interested :-) ] > I honestly ask that someone could explain to the less enlightened like me > what this decorator thingy really is. What does it make a correct step on > the path to enlightenment? Here a very short and very incomplete explainment of what a decorator is. FOr a more complete explanation, please refer to the PEP, or even wade through python-dev. I also just give one simple example, there are lots of other uses for decorators. But since probably more than 95 percent of Python code will not need decorators in the near future, just one example should be enough to just don't let you worry about what the Voodoo is. Something many Python programmers even don't know about are class methods and static methods. A static method is simply a method which is defined in a class, but that does not operate on self. The self variable is not supplied. A static method is not supposed to be a method of an instance. It is just sitting in a class for convenience, but behaves like an ordinary function. There is a more advanced concept: a class method. Instead of self or nothing, it always receives the class as first parameter. But please read the docstring of the classmethod function. We will stick with the simple static method, here. Until Python 2.3, it was necessary to "declare" a static method by calling the function staticmethod on it. Sample code: class MyClass(object): def func(arg1, arg2): return arg1 + arg2 func = classmethod(func) What can you see here? The "def func" lacks a self parameter. You want to call it with the two parameters arg1 and arg2, but without the extra line func = classmethod(func) you would get this result: Trying to call func via the class gives you >>> MyClass.func(2, 3) Traceback (most recent call last): File "", line 1, in ? TypeError: unbound method func() must be called with MyClass instance as first argument (got int instance instead) >>> Trying to call func via an instance also doesn't work: >>> inst = MyClass() >>> inst.func(2, 3) Traceback (most recent call last): File "", line 1, in ? TypeError: func() takes exactly 2 arguments (3 given) >>> Now, with the mentioned extra line, the function object is modified in a way that it understands that it is an ordinary function, and it works in both cases: >>> class MyClass(object): ... def func(arg1, arg2): ... return arg1 + arg2 ... func=staticmethod(func) ... >>> MyClass.func(2, 3) 5 >>> inst = MyClass() >>> inst.func(2, 3) 5 >>> --- now finally on the decorator issue --- What you have see is, that staticmethod has to be called *after* the function is defined. The modified function is assigned to the class as a post process. For very long functions, this can become cumbersome. Not only that you have to type the function name three times, you also have to scroll through the full function definition, possibly even through the rest of the whole class definition, to see whther the function is modified somehow. One of the purposes of decorators is now to overcome this problem, and to annotate the function earlier than at its end. There are many proposals how to do this, also with extended functionality. But I'll reduce the example to the currently proposed syntax: class MyClass(object): @classmethod def func(arg1, arg2): return arg1 + arg2 This is the basic idea what a decorator does: Make modifiers like classmethod into a prefix of a function. I know this description is incomplete, but I beg those who know better _not_ to respond and prove their knowledge. I wanted to give a simple idea. Corrections are welcome, of course. Everything else is documented in PEP318. ciao - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From urbushey at sas.upenn.edu Thu Aug 5 19:44:58 2004 From: urbushey at sas.upenn.edu (uri bushey) Date: Thu, 05 Aug 2004 17:44:58 -0600 Subject: Standalone Python Programs... Message-ID: I have a Python program that is built on an infrastructure of quite a few other programs, but I would like to create a standalone nonetheless. It doesn't necesarily have to be its own executable, although this is the most attractive option - it could just mean distributing the entire python distribution with it in an installer or something. However, here is what I have called in my python file: Tkinter, and multiple Pmw widgets WaveSurfer, called as a "Wsurf" widget, which is a great little program used for Spectrograms of wave files etc. It relies on Tcl/Tk and the SNACK library, which also have to be installed for my script to work. Can anyone help? I'm open to any option, py2xe, mcmillan's, or cx_freeze or whatever that program is, or even an installer that installs all of those programs. I'm vying for the most elegant solution. Thanks! --uri From skip at pobox.com Tue Aug 10 12:46:49 2004 From: skip at pobox.com (Skip Montanaro) Date: Tue, 10 Aug 2004 11:46:49 -0500 Subject: decorators vs GIL In-Reply-To: References: <8YudnZoJ4NdLEYjcRVn-jA@speakeasy.net> <0bidnfbR2_PZOIjcRVn-pA@giganews.com> Message-ID: <16664.64505.157539.635524@montanaro.dyndns.org> Anthony> As far as "fixing" the GIL - well, no-one on Python-Dev has Anthony> obviously found it to be a problem for them. I wouldn't state the case that strongly. There appear to be bigger fish for the python-dev gang to fry up to this point. Perhaps if more of us were scientific computation types the GIL would be seen as a more important barrier to be removed. That a fairly bright guy (Greg Stein) removed it once and found performance to be disappointing doesn't advocate strongly for removal of the GIL either. Skip From FBatista at uniFON.com.ar Mon Aug 30 13:45:55 2004 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Mon, 30 Aug 2004 14:45:55 -0300 Subject: about presicion Message-ID: [alikakakhel3 at hotmail.com] #- ok but where can i download deciaml? waht about gmpy? which #- is better? >From http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Lib/ Don't know gmpy, so I can't compare. But decimal will be in the standard library, so since Py2.4 you'll not need an external module. . Facundo From whereU at now.com Fri Aug 27 00:32:48 2004 From: whereU at now.com (Eric Pederson) Date: Thu, 26 Aug 2004 20:32:48 -0800 Subject: Larry Wall & Cults Message-ID: <20040826203248.1132322.whereU@now.com> Xah Lee wrote: > > > >> Did you know that throughout history there's this thing called cult? > > > >I think you're getting confused with the Blue ?yster Cult. > >Don't Fear the Reaper - great song. > > And then there's this crazy little thing called love... > -- I liked the "Cult's" highly cultural hit "Godzilla". Perhaps not the most high minded of their catalog, but the only one, to my knowledge, that both Larry and Guido sang on. re cults... In a rich area of the Silicon Valley, where the IPO lucky live, there is a pretty Dianetics school for the kids: what else do you need to know about the tech industry? ;-) Eric Pederson == people get so confused when I use triple quote strings in my normal correspondence! == http://www.songzilla.blogspot.com ::::::::::::::::::::::::::::::::::: domainNot="@something.com" domainIs=domainNot.replace("s","z") ePrefix="".join([chr(ord(x)+1) for x in "do"]) mailMeAt=ePrefix+domainIs ::::::::::::::::::::::::::::::::::: From ptmcg at austin.rr._bogus_.com Fri Aug 20 10:00:11 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 20 Aug 2004 14:00:11 GMT Subject: Alternative decorator syntax decision References: Message-ID: "Ville Vainio" wrote in message news:du7hdqyxezw.fsf at mozart.cc.tut.fi... > >>>>> "Paul" == Paul McGuire writes: > > Paul> (And let's hope we get at least as good a response as the "average age" > Paul> thread!) > > Not going to happen, with the words "alternative decorator syntax" in > the subject. No sensible person wants to see yet another wacky > alternative, and the subject promises as much. > > Hence, I won't vote yet because, at minimum, you need a better subject > line. > > Something like this needs to be announced somewhere (e.g. daily > python-url). > > -- > Ville Vainio http://tinyurl.com/2prnb Ville - I'm afraid I have to agree, the subject is a poor one. I noticed that yesterday as the responses were slow to come in. Something more on the order of "READ THIS - IT'S FREAKIN' IMPORTANT!" is surely warranted. I am still relatively new to Usenet, and surely not aware of how to update the subject of an existing post, otherwise I would have done so! But please don't abstain in voting over my poor judgment in titling this thread, the responses are starting to trickle in (there was already a cross-mention on python-dev). And I would not at all be offended if you posted an additional note with some more-appropriate subject, directing people to this process. Thanks, -- Paul From del at mjclift.freeserve.co.uk Fri Aug 13 01:19:35 2004 From: del at mjclift.freeserve.co.uk (Calvin79) Date: Fri, 13 Aug 2004 01:19:35 -0400 Subject: while and if References: Message-ID: <0bdd1a7f5df1e62a591f6f1be0cd7d0f@localhost.talkaboutprogramming.com> Thankyou Satchit, it works exactly as I wanted! Calvin From peter at engcorp.com Mon Aug 30 11:29:19 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 30 Aug 2004 11:29:19 -0400 Subject: use win32 COM in python In-Reply-To: References: Message-ID: (Sorry for mis-post... trying again.) Dave Brueck wrote: > Have a look at ctypes and/or win32com - they allow you to use COM (in ^^^^^^^^ Just to note: win32com is part of the "pywin32" package, formerly called win32all. > varying degrees) from Python, so what you're trying to do is probably > possible. Definitely.. both should work. There are also many examples out there of using such things for talking via COM, e.g. to automate Internet Explorer. -Peter From vjshield-widgets at yahoo.com Thu Aug 26 12:07:21 2004 From: vjshield-widgets at yahoo.com (vjshield-widgets at yahoo.com) Date: Thu, 26 Aug 2004 09:07:21 -0700 (PDT) Subject: Question on weightless threads and generators: Message-ID: <20040826160721.51148.qmail@web41313.mail.yahoo.com> I have a workerclass which takes in several parameters for initialization. This class would have a doWork function. Currently this function has a loop which does all the work and then returns. I have to extend the application to be able to support many different workerClass instances all executing at the same time. I was thinking of using generators to do this. I have the following questions on generators: 1. Can a generator function be inside a class 2. When you yield a generator, are all the instance variables of the class saved as well. 3. If I want to do n units of work for each call to the generator function, how do I pass the n to the generator function? class WorkerClass(): def __init__(self, someVariables): self.someVariables initializtionFunctionCalls() def workerFunction(self, numUnitsOfWork): count = 0 for i in timeUnits: application logic if count == numUnitsOfWork: yield None I'll then have a thread manager which will initialize all the worker classes and make calls to workerfunctions based ont he priority of each worker class. Will this work? From kollmann at telbiomed.at Fri Aug 13 06:04:49 2004 From: kollmann at telbiomed.at (Alexander Kollmann) Date: Fri, 13 Aug 2004 12:04:49 +0200 Subject: Recompiling cpp Message-ID: hi, i'm have no idea how to recompile a *.cpp for a certain python version. how can i do that ? i need the compiled pymat file for python 2.1. i have it compiled form for the version 2.2 and i have a cpp-file. regards alex From fumanchu at amor.org Mon Aug 23 10:32:15 2004 From: fumanchu at amor.org (Robert Brewer) Date: Mon, 23 Aug 2004 07:32:15 -0700 Subject: J2 paper 0.2.1 Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E39@exchange.hqamor.amorhq.net> Colin J. Williams wrote: > One nit picking comment on Robert Brewer's document: An > annotation is a > transformation of a function, as a change to the flow of control is. I'd like someone to analyze that further. "Transform", like the word "change", can mean almost anything in English. However, I find the use of the term in programs to generally mean either coerce/convert/cast between types, or some other mechanism whereby one object is supplied, and another object returned. That is, "transform" affects Being/"is" as opposed to Attribute/"has". However, neither your "gut feeling" nor mine about the issue is enough--we need a more rigorous heuristic to decide. Finding precedent would be a good start, if anyone wants to try. Robert Brewer MIS Amor Ministries fumanchu at amor.org From kjetilho at yksi.ifi.uio.no Sat Aug 28 05:47:31 2004 From: kjetilho at yksi.ifi.uio.no (Kjetil Torgrim Homme) Date: Sat, 28 Aug 2004 11:47:31 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1ry8k0d2az.fsf@rovereto.ifi.uio.no> <10iv0kid2ig9ka6@corp.supernews.com> <1rpt5ccbso.fsf@rovereto.ifi.uio.no> <10ivpk9inpnh65@corp.supernews.com> Message-ID: <1rd61bd26k.fsf@rovereto.ifi.uio.no> [Jeff Shannon]: > > Now, what do you gain by adding braces? The ability of tools to > better reindent code, supposedly. no, the ability of having wrongly indented code throw syntax errors. there are many workarounds for individual editors, but nothing to help eliminate this error class altogether. the many workarounds also lead to "more than one way to do it". the code I read can be using "#fi", "# end if", "# }", "pass" or nothing. sure, I can write a tool to enforce a single coding standard for my project, but external code will naturally not comply. that's why I think it would be good if Python decreed a single method of using both belts and braces. currently, I'm using the "nothing" style, and like it very much. my motivation is that a member of our development group religuously litters his code with "#fi" and "#done". rather than just tell him to stop it, I thought I'd explore the avenue of a compromise, since I myself would like to use braces in my code in some instances to improve the visual cue in "deep" (4-5) indentation blocks. (this can happen even if the function fits on the screen. splitting out the core of it is in some cases awkward.) > But I have to say, using block-indent and block-dedent commands, > I've never had a difficult time with maintaining proper relative > indentation of cut-and-pasted code blocks. I wouldn't say it's a frequent problem for me, it's happening me a couple of times per year, and some of my colleagues report likewise. but wasting perhaps a workday a year on such a silly issue is annoying. > I don't see the problem you're trying to solve, I'm not aware of > it being a significant problem throughout Python's 10+ year > history, and I honestly doubt that your "solution" would provide > much significant benefit. my hope is that my solution can be ignored by those who don't need it, and used by those who like it. > Note, also, that this is not an ad hominem attack. no, it was a long, well thought-out article. thank you. -- Kjetil T. From rkern at ucsd.edu Tue Aug 17 15:13:14 2004 From: rkern at ucsd.edu (Robert Kern) Date: Tue, 17 Aug 2004 14:13:14 -0500 Subject: Editors again In-Reply-To: References: Message-ID: ChrisH wrote: > Doesn't it cost around $3000 for a Qt license to run the program? He's describing a setup that uses Qt for X11 (which is released under the GPL) that just happens to run on Windows (or at least the X server runs on Windows). He is *not* using the Qt libraries that use native Windows drawing calls (which is only available under a proprietary license from Trolltech). -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From grante at visi.com Wed Aug 25 11:45:11 2004 From: grante at visi.com (Grant Edwards) Date: 25 Aug 2004 15:45:11 GMT Subject: Getting at the bits of a 32-bit integer References: <85b54e91.0408231552.75f85727@posting.google.com> <412a98f4$0$65569$a1866201@newsreader.visi.com> <412cb279$1@nntp0.pdx.net> Message-ID: <412cb407$0$62953$a1866201@newsreader.visi.com> On 2004-08-25, Scott David Daniels wrote: > Grant Edwards wrote: > >>... That's a bit, um, conceited. Somebody's got to twiddle all >> those low-level bits out there to provide the infrastructure >> that makes the world run. >> >> I'm one of those people, and I need to do bit-twiddling quite >> often while implimenting various communications protocols. > > If you are interested in such things, take a look at: > > http://members.dsl-only.net/~daniels/bits.html > > It lets you do things like look at bit-ranges of (int, long, float) > and find things like msb, lsb, particular bits (bit) and > extract bit ranges. That looks handy. The other thing that looks very useful is a module posted a few weeks back that impliments fixed-length numbers. In addition to manipulating individual bits, one often needs to do operations on binary, two's compliment numbers of known, fixed lengths. -- Grant Edwards grante Yow! Yes, Private at DOBERMAN!! visi.com From grante at visi.com Mon Aug 16 10:24:56 2004 From: grante at visi.com (Grant Edwards) Date: 16 Aug 2004 14:24:56 GMT Subject: Python secure? References: <411ffef6$0$65603$a1866201@newsreader.visi.com> Message-ID: <4120c3b8$0$8079$a1866201@newsreader.visi.com> On 2004-08-16, Roger Binns wrote: > Grant Edwards wrote: >> I don't see how decompiling is a copyright violation. If I buy >> a copy of a book, I'm pretty sure I can translate it into >> another language if I want to form my own use. > > They need to use what they decompile for it to be a copyright > violation. IANAL, but it looks like under Title 17, the act of creating a derived work is an infringement. It doesn't say the derived work has to be used and/or distributed for it to be an infringement. -- Grant Edwards grante Yow! NEWARK has been at REZONED!! DES MOINES has visi.com been REZONED!! From http Mon Aug 23 14:54:49 2004 From: http (Paul Rubin) Date: 23 Aug 2004 11:54:49 -0700 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> <7x4qmv6cwo.fsf@ruckus.brouhaha.com> <7x1xhz1173.fsf@ruckus.brouhaha.com> Message-ID: <7xfz6d8z2e.fsf@ruckus.brouhaha.com> Jeremy Sanders writes: > > Sometimes that happens. Other times it really is too slow, and I rewrite > > it in C. Other times Python is too bloated and I can't even consider > > using it; for example, in anything that users need to download without a > > big fuss. > > Most Linux distributions include python as standard, so the users only > need to download your script (which will probably be smaller than the > equivalent C code). IMO, mainstream applications are applications that are used by a big chunk of the general public. That can include server side applications (e.g. I'd consider Google web search to be a mainstream application) as well as stuff like MS Office. The server side stuff can of course run on Linux or anything else the implementers chose. But I wouldn't consider any Linux client side application to be mainstream. Much as I wish it were otherwise, there just aren't that many people running Linux on their home computers. From grante at visi.com Sat Aug 28 10:56:50 2004 From: grante at visi.com (Grant Edwards) Date: 28 Aug 2004 14:56:50 GMT Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1ry8k0d2az.fsf@rovereto.ifi.uio.no> <87acwgvy51.fsf@sinken.local.csis.hku.hk> <2pb36dFibuj3U1@uni-berlin.de> Message-ID: <41309d32$0$65611$a1866201@newsreader.visi.com> On 2004-08-28, Reinhold Birkenfeld wrote: > Isaac To wrote: >>>>>>> "Kjetil" == Kjetil Torgrim Homme writes: >> >> Kjetil> that's a hack, and IMHO not worthy of a Python program. >> Kjetil> not even Perl has anything like that, AFAIK. >> >> Hm... hacks are not for Python?! We see every kind of hacks >> everywhere in Python just like it is in Perl, like (2,) syntax, etc. > > Why would you call (2,) syntax a hack? Because so many people at first think that parens construct tuples the way square-brackets and curly-brackets construct lists. When in reality it's commas that construct tuples, but only in certain contexts because commas are used for about three other purposes as well. > If you like, you can call tuple([2]), but I would consider _this_ an > ugly solution or a "hack". I would call it the former. IMO, the only non-ugly, non-hack solution would be to have another set of delimters that are used as tuple-constructors so tha the syntax for a literal tuple, a literal list, and a literal dictionary are consistent. -- Grant Edwards grante Yow! AIEEEEE! I am having at an UNDULATING EXPERIENCE! visi.com From anthonybaxter at gmail.com Fri Aug 27 00:00:54 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 27 Aug 2004 14:00:54 +1000 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> Message-ID: On Thu, 26 Aug 2004 20:54:22 -0400, Paul Morrow wrote: > Anthony Baxter wrote: > Sure the interpreter uses __getitem__, but you use it too, right? I > mean, you don't need the interpreter to tell you whether instances of > the following class can act like a dictionary, do you? > > class Foo: > def __getitem__(self, x): pass Well, actually, no. The presence or absence of __getitem__ "tells" you nothing. It depends on the implementation. def __getitem__(self, key): raise AttributeError, '__getitem__' > No you don't. Nor do you need to pretend that you're the interpreter, > and simulate a call to an instance of Foo. That's because the mere > presence of def __getitem__ tells you what you need to know. In this > way, __getitem__ *does* serve as a declaration (of dictionary semantics) > [*] to you and anyone reading your code. No. It. Does. Not. "dictionary semantics" includes a hell of a lot more than a "__getitem__". And list-like objects _also_ include a __getitem__. > * But an implicit declaration of course. I guess the only way of > *explicitly* stating that instances of a class can act like dictionaries > is to have the class inherit from dict or UserDict. Or use Interfaces. Or put something in the docstring. > > class Foo: > > def __init__(self): > > self.d = dict(ape=False,spidermonkey=True) > > > > def getMonkey(self, key): > > return self.d[key] > > > > def __getattr__(self, name): > > if name == "__getitem__": > > return self.getMonkey > > else: > > raise AttributeError, name > > > > f = Foo() > > print f['ape'] > > print f['spidermonkey'] > > Now hold on just a minute. If I squint a little, I can still see > __getitem__ in there somewhere. As a *string*, buried away in the innards. So I make that string get loaded from another object, or from a database, or whatever. Your point is _wrong_. You cannot "declare" anything by simply the presence or absence of magic double-under methods. > Though I do believe that you are illustrating a good point; that you can > mangle your code badly enough that it no longer lends itself to a > declarative reading. And then, the only way for your poor reader to > figure out what the heck it's doing is for him/her to act like the > interpreter and walk through your code (or run it under the debugger). Or read the docstring for the class. Anthony, giving up. From roy at panix.com Mon Aug 16 21:50:23 2004 From: roy at panix.com (Roy Smith) Date: Mon, 16 Aug 2004 21:50:23 -0400 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> <41214271_1@127.0.0.1> <41215667$1_1@127.0.0.1> Message-ID: "beliavsky at aol.com" wrote: > Ok, here is something short but more realistic and IMO not "ugly". > > You may want to exit a nested loop when testing if a condition involving > several variables is met, such as searching for a zero of a multivariate > function. > > In Python you can print i,j,k and exit() when m == 0, but in a larger program > you may want more control. > > program xnest_loop > ! find a Pythagorean triple > n = 5 > ido: do i=1,n > do j=1,n > ij = i**2 + j**2 > do k=1,n > m = ij - k**2 > if (m == 0) exit ido > end do > end do > end do ido > if (m == 0) then > print*,i,j,k > else > print*,"no triple" > end if > end program xnest_loop That's easy (and relatively common). I'd factor out the loop you labled "ido:" into a separate function, and have your "exit ido" become a return statement. There's nothing Python-specific about that; I'd use the same refactoring strategy in C, Fortran, etc. I'm a big fan of small, easy to understand, functions. From blaktyger at hotmail.com Fri Aug 13 00:47:21 2004 From: blaktyger at hotmail.com (Blaktyger) Date: 12 Aug 2004 21:47:21 -0700 Subject: Displaying images stored as binary in MySQL Message-ID: How can this be done? Images are stored in a LONGBLOB field. When I try to display them, it prints out the binary data as it is... Thank you From fumanchu at amor.org Sun Aug 22 03:08:13 2004 From: fumanchu at amor.org (Robert Brewer) Date: Sun, 22 Aug 2004 00:08:13 -0700 Subject: J2 decorator grammar Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E24@exchange.hqamor.amorhq.net> Bengt Richter wrote: > On Sat, 21 Aug 2004 17:22:43 -0700, "Robert Brewer" > wrote: > [...] > >For that reason (and others), I plan not to promote any form > of the word > >"decorate". We can start having that conversation now if you want. ;) > > > What about just using > > def: > deco1 > deco2('with','parameters') > any_expression_returning_a_callable_allowing_a_single_arg_call > def foo(): > pass Guido mildly rejected it in April: http://mail.python.org/pipermail/python-dev/2004-April/043933.html In addition, it would probably be a significant rewrite of the patch Michael Sparks has written for the current proposal. Candidates which are not already keywords don't have that problem. ;) That really should've received its own letter designation on the wiki. :( Robert Brewer MIS Amor Ministries fumanchu at amor.org From ark at acm.org Mon Aug 23 11:47:20 2004 From: ark at acm.org (Andrew Koenig) Date: Mon, 23 Aug 2004 15:47:20 GMT Subject: Dynamic Scoping problem References: Message-ID: "Daniel Lemos Itaborai" wrote in message news:b8320fb9.0408230713.5f3d2d7a at posting.google.com... > I would like to first apologize my question, I just picked up Python > for a spin 4 days ago(loving it so far). I am having some trouble with > this... > > # myproblem.py > > x = 'wrong' > > def bluft(x) : x() > > def foo(): > x = 'right' > def bar(): > global x > print x > bluft(bar) > > # end myproblem.py > > > Is there a way to enforce scope resolution? When you write def foo(): x = 'right' ... you are defining a new variable, local to foo, named x. When you say "global x" inside bar, you are saying that you do not want that variable; you want the global one instead. If you want to assign 'right' to the global x, do it this way: def foo(): global x x = 'right' def bar(): print x bluft(bar) That said, I should point out that global variables are usually a bad idea. From b_r_maria at hotmail.com Thu Aug 19 01:10:14 2004 From: b_r_maria at hotmail.com (Burgel Rosa Maria Faehndrich) Date: Wed, 18 Aug 2004 19:10:14 -1000 Subject: Displaying ipa in python.exe Message-ID: <000501c485aa$cf9e2940$8c42ab80@grimes1> I am having some trouble properly displaying unicode characters in python.exe. When I try to run a script containing the following: print ur"\u0288" the window just flashes on and off, without giving the user the opportunity to input the data that is being asked for. When I try: print ur"\u0288".encode('utf-8') the window stays on, the user can input the data asked for, and a symbol is displayed, but it's not the symbol I want to see. No trouble at all when I run the same script in IDLE. What can I do to fix this? Is there a way of installing additional fonts in python.exe? Am I using the wrong encoding? Thanks, Maria -------------- next part -------------- An HTML attachment was scrubbed... URL: From franbarlow at mail.com Thu Aug 12 16:17:21 2004 From: franbarlow at mail.com (Fran) Date: 12 Aug 2004 13:17:21 -0700 Subject: Help understanding Scheme's syntax, procedures and calls References: <95f168b0.0408120120.31433dc7@posting.google.com> <411b577a$0$20523$afc38c87@news.easynet.co.uk> <411b7bdd$0$65612$a1866201@newsreader.visi.com> Message-ID: <95f168b0.0408121217.2b88ee25@posting.google.com> Grant Edwards wrote in message news:<411b7bdd$0$65612$a1866201 at newsreader.visi.com>... > On 2004-08-12, Peter Hickman wrote: > > > Is this someone's homework by any chance? > > According to the OP, it's part of a final exam. It's not a final exam (that won't come until October-November) but from an old exam paper. The girl's English isn't absolutely fluent and I'm looking for a simple way to explain the expressions and functions. FRAN From nehavrce at yahoo.co.in Mon Aug 9 00:33:48 2004 From: nehavrce at yahoo.co.in (=?iso-8859-1?q?neha=20agrawal?=) Date: Mon, 9 Aug 2004 05:33:48 +0100 (BST) Subject: help Message-ID: <20040809043348.94101.qmail@web8203.mail.in.yahoo.com> hello sir, i want to know what r advantages of using perl over python and tcl for network programming at tcp/ip layer. thanks ________________________________________________________________________ Yahoo! India Matrimony: Find your life partner online Go to: http://yahoo.shaadi.com/india-matrimony From johnfkeeling at yahoo.com Wed Aug 4 10:10:25 2004 From: johnfkeeling at yahoo.com (John Keeling) Date: 4 Aug 2004 07:10:25 -0700 Subject: Timing Difference: insert vs. append & reverse References: <35b736b9.0408020330.53b24ed3@posting.google.com> <1a517b5.0408031027.60554dfb@posting.google.com> Message-ID: <35b736b9.0408040610.2398b72d@posting.google.com> Clarification... Duncan Booth wrote in message > > True, but an array implementation can easily support amortized > > constant-time insert/delete at *either* end (without breaking > > constant-time indexing). The same trick of keeping extra space > > at the tail end can work at the head; it requires keeping one > > additional offset to show where the occupied cells start. > > > > If the OP had said he expected insert and append to be the same speed I > might buy that, but he expected insert to be faster than append. Actually, I never said that ... I said "I would have expected the insert operation to be faster than the combined append & reverse operations." The object of my test code was to fill out a list in the reverse order to which I had the list items available. I would have expected: tmp2 =[] for indx in xrange(10000): tmp2.insert(0, indx) to be faster than tmp1 =[] for indx in xrange(10000): tmp1.append(indx) tmp1.reverse() because the insert case does not require the reverse operation. This would be the case if the insert operated at (approximately) the same speed as the append, rather then the insert (at position 0) being 16-17 times slower than the append. I guess I somewhat expected it to be as Bryan Olson stated:"an array implementation can easily support amortized constant-time insert/delete at *either* end (without breaking constant-time indexing)." John From emschwar at pobox.com Wed Aug 25 18:46:35 2004 From: emschwar at pobox.com (Eric Schwartz) Date: Wed, 25 Aug 2004 16:46:35 -0600 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: xah at xahlee.org (Xah Lee) writes: > Did you know that throughout history there's this thing called cult? I had no idea. Good thing you're here to help us out. -=Eric -- Come to think of it, there are already a million monkeys on a million typewriters, and Usenet is NOTHING like Shakespeare. -- Blair Houghton. From news2 at mystrobl.de Sat Aug 7 06:36:08 2004 From: news2 at mystrobl.de (Wolfgang Strobl) Date: Sat, 07 Aug 2004 12:36:08 +0200 Subject: bugs at iter file() ? References: <10fc6kj98mkfef4@corp.supernews.com> Message-ID: "Terry Reedy" : >"Michael Geary" wrote in message >news:10fc6kj98mkfef4 at corp.supernews.com... >> Terry Reedy wrote: >> > To add to what Tim said: From the viewpoint of Windows in >> > its default mode, there are no remaining lines. ^Z is the end >> > of file and anything after that is accidental junk filling out the >> > remainder of the disk block. >> >> Just to clarify one point... Windows itself does not have "text" or "binary" >> files, and it does not treat ^Z in a file in any special way. There are no >> special characters in files. >Sorry, but ^Z has meant end-of-file I presume from the first version of >DOS, which I suspect copied the usage from something previous. Sorry, but Michael got it right. Windows itself does not have 'text' or 'binary' files or open modes. Have a look at CreateFile in the Platform SDK. You won't find anythink like _TEXT or _BINARY there. ^Z is a carryover from CP/M to DOS, which, like crlf<->lf translation, got some support in various libraries, for obvious reasons. It's not part of the Win32 API. >Example >(Microsoft Basic manual, 1989): "When input is redirected [from terminal to >a file], GW Basic continues to read from this source until a CTRL-Z is >detected." So what? BASICA is an application, just like bash or sendmail. >Perhaps the usage has dimmed in non-DOS-based Windows, so that >I should have said more carefully "from the viewpoint of DOS and perhaps >DOS-based Windows and partially in modern non-DOS-based Windows ...". >Still, in Windows XP, open a Command Prompt window and enter > >disk:\path> copy con: temp >abd^Zdef > >where ^Z is control-Z and you get a file with 3, not 7 characters. > >The Windows version of the Python interactive interpreter exits on ^Z >because that is, or at least was, standard behavior for interactive non-gui >DOS/Windows programs You mean like terminating a program using a single dot on a line is, or at least was, standard behaviour for interactive non-gui UNIX/Linux applications? :-) -- Thank you for observing all safety precautions From ben at benlast.com Wed Aug 18 08:11:17 2004 From: ben at benlast.com (Ben Last) Date: Wed, 18 Aug 2004 13:11:17 +0100 Subject: favorite python web development tool? In-Reply-To: <87d61o26b7.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Message-ID: Whilst not in any way whatsoever wishing to prompt or contribute to a BestWebEnvironment holy war: I'm currently approaching the end of a sizeable website development in Zope. I found it to be a very powerful environment which is *extremely* badly documented and requires a *significant* investment in learning time. I'm not new to Python, and that was very useful to me, since I ended up in the source code of the various Zope components many, many times. If you *are* new to Python, I would tentatively suggest that Zope is suitable only if your first development is not mission critical or subject to tight time pressure. I don't regret choosing Zope as far as suitability is concerned, but I do believe I underestimated how weak the documentation and support is, and how difficult it would be to work in. This is, I repeat, merely my subjective opinion. I have not undertaken a careful assessment of Zope vis-a-vis other environments, and the criteria by which I selected it were specific to the particular problem domain and company. regards ben > -----Original Message----- > From: python-list-bounces+ben=benlast.com at python.org > [mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of > 5100-46470588-0001 at t-online.de > Sent: 18 August 2004 09:34 > To: python-list at python.org > Subject: Re: favorite python web development tool? > > > mike writes: > > > > > > i'm fairly new to python, coming from a java servlet / velocity > > template background. i'm looking for a good python web development > > tool, and hope to find some suggestions here. > > > ZOPE > > Klaus Schilling > -- > http://mail.python.org/mailman/listinfo/python-list ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ From chrisks at NOSPAMudel.edu Fri Aug 6 21:38:39 2004 From: chrisks at NOSPAMudel.edu (Chris S.) Date: Sat, 07 Aug 2004 01:38:39 GMT Subject: Object Reference? In-Reply-To: References: Message-ID: Gandalf wrote: > Yes, Python figures out when to delete an object, based on its reference > count. But Python only counts the references. It keeps track of the > number of references for the object. It does not know where the > reference is located in memory. The short answer is that you cannot get > this information effectively. The gc module has methods that list an object's referrers and referents. Although you're correct in that we're unable to access the total number of references since duplicate references are not counted. For instance import gc a=[1,2,3] b=[a,a,a,a] print gc.get_referrers(a) would only print out one instance of b, even though it references 'a' four times. However, this only seems to apply for direct references, so the total number of references can be determined by scanning all referrers and counting the duplicate ids. From brian at nospam.com Mon Aug 23 12:08:37 2004 From: brian at nospam.com (Brian) Date: Mon, 23 Aug 2004 16:08:37 GMT Subject: Bug in string.lstrip? Message-ID: <9EoWc.58$A8.18@edtnps89> Hello - has anyone else had trouble with string.lstrip stripping too much? Here's what I get (Python 2.3.4): >>> import string >>> string.lstrip("test/one/two/a.b.c", "test/one/") 'wo/a.b.c' >>> string.lstrip("test/one/two/a.b.c", "test/one") 'wo/a.b.c' >>> string.lstrip("test/one/two/a.b.c", "test/one/tw") 'a.b.c' >>> Similar things happened with the strip() string method. Am I missing something, or should I file a bug report? Thanks, Brian From bj_666 at gmx.net Sat Aug 28 13:32:35 2004 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Sat, 28 Aug 2004 19:32:35 +0200 Subject: cookie References: <87fz68v1uj.fsf@pobox.com> Message-ID: In , Ajay wrote: > my question is >>>> import Cookie >>>> c = Cookie.SimpleCookie() >>>> c["test"]= "blah" >>>> print c > Set-Cookie: test=blah; >>>> c["test"] = "blah" + "testing" >>>> print c > Set-Cookie: test=blahtesting; >>>> str = "testing blah" >>>> c["test"] = str >>>> print c > Set-Cookie: test="testing blah"; > > why does the final print statement have the quotes. Note i haven't put > str='"testing blah"'. if i had done that i would understand the quotes > there. It's no difference if you bind the string to a name or assign it directly, it's the contents of the string: >>> import Cookie >>> c = Cookie.SimpleCookie() >>> c["test"] = "spaceless" >>> print c Set-Cookie: test=spaceless; >>> c["test"] = "not spaceless" >>> print c Set-Cookie: test="not spaceless"; Ciao, Marc 'BlackJack' Rintsch From anthonybaxter at gmail.com Fri Aug 13 12:24:03 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 14 Aug 2004 02:24:03 +1000 Subject: Python indentation deters newbies? In-Reply-To: <3064b51d.0408130615.3fc4a760@posting.google.com> References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: On 13 Aug 2004 07:15:14 -0700, beliavsky at aol.com wrote: > One of the most commmon reasons programmers cite for not trying Python > is that indentation determines the program flow -- they think its > weird. I think programmers who actually try Python adapt quickly and > do not find the indentation rules to be a problem. > > I wonder if there is a way to remove this initial barrier. Could an > alternate source form be defined, so that there are matching if-endif > and for-next constructs instead of significant indentation? The > alternate source form and the current form would result in exactly the > same .pyc file. Luckily, the time machine has already been used to implement this. At the end of an 'if' statement, you can put a "#endif". And in a for loop, you can put a "#endfor" at the end. The '#' is to indicate that it's not the preferred form. In all seriousness - people who bounce off Python because of the indentation are probably just not willing to learn a new language, or else they're incredibly bigoted towards whatever language (often C) that they're used to. Their loss. From ramen at lackingtalent.com Fri Aug 13 16:04:54 2004 From: ramen at lackingtalent.com (Dave Benjamin) Date: Fri, 13 Aug 2004 20:04:54 -0000 Subject: Flython Message-ID: I just want to say, for the record, that if anyone can successfully build a Python compiler that can produce Flash bytecode, I will personally allow you to throw *any number of pies* in my face, in as public of a ceremony as you desire. Furthermore, I will match you 50/50 in the cost of the pies. Thank you, Dave -- .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:. "talking about music is like dancing about architecture." From daniel at syrinx.net Wed Aug 18 09:38:48 2004 From: daniel at syrinx.net (Daniel Ellison) Date: Wed, 18 Aug 2004 09:38:48 -0400 Subject: Flython? In-Reply-To: References: Message-ID: <2oh4brFant89U1@uni-berlin.de> Ben Last wrote: > Oddly enough, I've just acquired a need (translation: had a requirement > dropped on me) for a certain amount of generation of Flash from Python. If > anyone's got any pointers to code, however non-project-grade, I'd be happy > to take a hack at cleaning it up and re-releasing it in return for the time > saved :) > > humbly yours > ben > > I don't know if this will help, but (/somewhere/) I've got Java code I wrote a while back which streams MP3s to a Flash client by chopping up the MP3 into Flash frames and sending them out one-by-one to the client, wrapped by a properly constructed swf file. It illustrates how to put together a swf file at the very lowest level. Let me know if you're interested and I'll put it on my site. Dan From cjankowski at hbr-inc.com Thu Aug 12 15:02:07 2004 From: cjankowski at hbr-inc.com (Chris Jankowski) Date: 12 Aug 2004 12:02:07 -0700 Subject: Errno 32 Broken pipe Message-ID: I am trying to print an image file to a network printer and getting the following error. This is a Windows based system, using a network printer. Any ideas. Error Message: cannot print image (exceptions.IOError:[Errno 32] Broken pipe) ************************************************************** Code: #! /usr/local/bin/python # # The Python Imaging Library. # $Id: //modules/pil/Scripts/pilprint.py#2 $ # # print image files to postscript printer # # History: # 0.1 96-04-20 fl Created # 0.2a1 96-10-04 fl Use draft mode when converting. # VERSION = "pilprint 0.2a1/96-10-04" import Image import PSDraw letter = ( 1.0*72, 1.0*72, 7.5*72, 10.0*72 ) def description(file, image): import os title = os.path.splitext(os.path.split(file)[1])[0] format = " (%dx%d " if image.format: format = " (" + image.format + " %dx%d " return title + format % image.size + image.mode + ")" import getopt, os, sys if len(sys.argv) == 1: print "PIL Print 0.2a1/96-10-04 -- print image files" print "Usage: pilprint files..." print "Options:" print " -c colour printer (default is monochrome)" print " -p print via lpr (default is stdout)" print " -P same as -p but use given printer" sys.exit(1) try: opt, argv = getopt.getopt(sys.argv[1:], "cdpP:") except getopt.error, v: print v sys.exit(1) printer = None # print to stdout monochrome = 1 # reduce file size for most common case for o, a in opt: if o == "-d": # debug: show available drivers Image.import_plugins() print Image.ID sys.exit(1) elif o == "-c": # colour printer monochrome = 0 elif o == "-p": # default printer channel printer = "lpr" elif o == "-P": # printer channel printer = "lpr -P%s" % v for file in argv: try: im = Image.open(file) title = description(file, im) if monochrome and im.mode not in ["1", "L"]: im.draft("L", im.size) im = im.convert("L") if printer: fp = win32pipe.popen(printer, "w") else: fp = sys.stdout ps = PSDraw.PSDraw(fp) ps.begin_document() ps.setfont("Helvetica-Narrow-Bold", 18) ps.text((letter[0], letter[3]+24), title) ps.setfont("Helvetica-Narrow-Bold", 8) ps.text((letter[0], letter[1]-30), VERSION) ps.image(letter, im) ps.end_document() except: print "cannot print image", print "(%s:%s)" % (sys.exc_type, sys.exc_value) **************************************************************** Thanks Chris J. From anthonybaxter at gmail.com Thu Aug 19 23:19:20 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 20 Aug 2004 13:19:20 +1000 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: On Thu, 19 Aug 2004 19:16:41 GMT, Paul McGuire wrote: > We've all done our share of pitching and whining, but we need to settle on > *one* option for Guido to consider. Also note that Python 2.4a3 is currently targetted at September 2. So there _is_ a time constraint. This is 4 weeks after a2. I considered the impact that this would have on the alternate decorators proposals, and decided that it didn't matter - the threads here and on python-dev have more or less hit a steady-state. From miko at nono.nevernever.net Sat Aug 21 11:36:31 2004 From: miko at nono.nevernever.net (Miko) Date: Sat, 21 Aug 2004 15:36:31 -0000 Subject: discover redirected url References: <10ieq4dscjutmb7@corp.supernews.com> Message-ID: <10ieqvc2b8va6c3@corp.supernews.com> i see it is import urllib urlf = urllib.urlopen("http://tinyurl.com/3apbd") print urlf.geturl() From mdrop1 at yahoo.com Mon Aug 30 04:00:13 2004 From: mdrop1 at yahoo.com (Message Drop Box) Date: 30 Aug 2004 01:00:13 -0700 Subject: The voodoo of zip(*someList) Message-ID: All, How (and why) does zip(*someList) work? >>> s = [[1, 2, 3], ['one', 'two', 'three'], ['I', 'II', 'III']] >>> zip(*s) [(1, 'one', 'I'), (2, 'two', 'II'), (3, 'three', 'III')] I've never seen the star '*' outside of function/method definitions and I've looked in the Python documentation without success. This syntax is voodoo to me at the moment. I'm stumped. Thanks, Stuart From zathras at thwackety.com Sun Aug 22 11:34:55 2004 From: zathras at thwackety.com (Michael Sparks) Date: Sun, 22 Aug 2004 16:34:55 +0100 Subject: [PATCH] RE: J2 decorator grammar References: <4128ac0f$0$79299$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <4128c1ea$0$81159$ed2619ec@ptn-nntp-reader02.plus.net> Michael Sparks wrote: > Anthony Baxter wrote: ... >> Well, in the comments for that patch, I listed all of the files changed >> by the @syntax - that at least gives you a 'to-do list' to work through. This was extremely useful BTW - thanks ! >> Once you've got what you think is the complete set, create a patch and >> post it to SF. > > Will do. The new patch can be found here: * http://www.python.org/sf/1013835 Issues with this patch are: * Uses "decorate" keyword rather than "using" (personal preference based on reading everyone's arguments in favour of it, and also based on googling for existing usage of alternatives...). * Doesn't support suggested short form * Is a patch against 2.4a2 not CVS head. * A bunch of tests are skipped on my machine so I haven't yet checked those for @pie decorators. As a result I'll be posting at least one update to this patch. It does however pass all the tests, include docs, and all the bits I think should've be updated are updated. (see the patch page above for details) Regards, Michael. From fumanchu at amor.org Sun Aug 22 14:07:00 2004 From: fumanchu at amor.org (Robert Brewer) Date: Sun, 22 Aug 2004 11:07:00 -0700 Subject: On consensus decision-making (was Re: Alternative decoratorsyntax - POLL RESULTS SO FAR - ARE WEDONE?) Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E29@exchange.hqamor.amorhq.net> Ville Vainio wrote: > So, to proceed building community consensus for J2, the community > needs to be asked whether they would block J2 (possibly with the > "using" keyword) in favor of another non- at pie syntax? Yes, but NOT YET. Wait for the proposal draft which I promise will be posted to c.l.p. by 9:00 A.M. GMT -08:00 (PST) Monday morning. Tell me concerns you (anyone) has with any part of it. Give me a small amount of time to rewrite. Read the rewrites. Comment. Read the final. Sign it for or against at that point. That's the best process, at this stage, for this proposal. If someone else wants to do the same for C1, I don't think Guido would be opposed to it--but someone has to step up and do the work, both the proposal and more importantly an implementation. Robert Brewer MIS Amor Ministries fumanchu at amor.org From peter at engcorp.com Thu Aug 12 08:51:47 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 12 Aug 2004 08:51:47 -0400 Subject: Print command In-Reply-To: <2nv6roF54f7iU1@uni-berlin.de> References: <2nv6roF54f7iU1@uni-berlin.de> Message-ID: "Russell Blau" wrote in message > Actually, I don't know the meaning of ``. > On some languages, it means "evaluate": Is it the same meaning in > Python? Why ask when you can do? : >>> `name` Traceback (most recent call last): File "", line 1, in ? NameError: name 'name' is not defined >>> name = 2 >>> `name` '2' From stephan.diehl at gmx.net Tue Aug 17 04:33:08 2004 From: stephan.diehl at gmx.net (Stephan Diehl) Date: Tue, 17 Aug 2004 10:33:08 +0200 Subject: apache configuration tool Message-ID: Is there something similar to the PERL Apache::Admin::Config module out there that is written in Python? Stephan From aahz at pythoncraft.com Tue Aug 17 16:25:51 2004 From: aahz at pythoncraft.com (Aahz) Date: 17 Aug 2004 16:25:51 -0400 Subject: Decorators: an outsider's perspective References: <20040814153534.8AC171E4007@bag.python.org> Message-ID: In article , Anthony Baxter wrote: > >I know that. When writing something as obviously taking the piss as my >comment, I don't think it's necessarily to include a smiley - that's >for the people who don't get humour, like Americans. No, no, no, Americans get humor just fine -- what they don't get is irony. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From pwilkinson at videotron.ca Mon Aug 9 10:31:33 2004 From: pwilkinson at videotron.ca (Peter Wilkinson) Date: Mon, 09 Aug 2004 10:31:33 -0400 Subject: unicode to ascii converting In-Reply-To: References: <1091815856.527127@news.commspeed.net> Message-ID: <6.0.3.0.0.20040809101700.01b60e58@pop.videotron.ca> Thanks for the help, I have got it working the problem was that I was not reading into the string as unicode. Peter At 04:22 AM 8/7/2004, Michel Claveau - abstraction m?ta-galactique non wrote: >Sorry ! > >The COMPLETE script is : > > # -*- coding: cp1252 -*- > aa = u"?" > aa.encode("ascii","ignore") > > > > > > >-- >http://mail.python.org/mailman/listinfo/python-list From fredrik at pythonware.com Wed Aug 11 18:27:12 2004 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 12 Aug 2004 00:27:12 +0200 Subject: PEP-0318 References: <41122FC2.1080608@interlink.com.au><4114152f@nntp.zianet.com> <4116bc20$1@nntp.zianet.com><6NCdncg4ssq28orcRVn-uQ@powergate.ca> <411a5cee$1@nntp.zianet.com> <411a9a7f$1@nntp.zianet.com> Message-ID: Mark Bottjer wrote: >> calling a function with an argument? that's a pretty common >> operation, if you're asking me > > Indeed it is. And that fact bears on this conversion how? that's what a decorator does, of course. what part of your own post did you not understand? From davebrok at soda.csua.berkeley.edu Wed Aug 25 21:42:57 2004 From: davebrok at soda.csua.berkeley.edu (David Pokorny) Date: Wed, 25 Aug 2004 18:42:57 -0700 Subject: Call for signatories for J2 References: Message-ID: Vote For. David From jepler at unpythonic.net Sat Aug 21 17:13:01 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Sat, 21 Aug 2004 16:13:01 -0500 Subject: zipfile module: problems with filename having non ascii characters In-Reply-To: <4127a6d7$0$4090$ba620e4c@news.skynet.be> References: <4127a6d7$0$4090$ba620e4c@news.skynet.be> Message-ID: <20040821211301.GD1458@unpythonic.net> Zip files don't have a way to define the encoding of filenames---names are just byte strings, and different utilities may interpret them in different ways. The only thing that seems to be defined is that '/' is the directory separator, and possibly that the filename can't contain '\0'. You can probably find the encoding that winzip uses with a little trial-and-error, and convert your filenames in your encoding to filenames in that encoding. This may depend on the language or region of the installed Windows, though. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From http Sat Aug 21 23:35:55 2004 From: http (Paul Rubin) Date: 21 Aug 2004 20:35:55 -0700 Subject: Getting benifits of database transactions in an OO way? References: <2oq8pmFdd2nfU1@uni-berlin.de> <7xk6vsklxm.fsf@ruckus.brouhaha.com> <2oqb54Fdj12nU1@uni-berlin.de> <7xu0uwlztw.fsf@ruckus.brouhaha.com> <2oqhlkFdi80eU1@uni-berlin.de> Message-ID: <7xfz6fhmjo.fsf@ruckus.brouhaha.com> Leif K-Brooks writes: > But then multiple row classes would have to create their own > connections, which would be bad for performance: > > import people > import companies > people_transaction = people.begin_transaction() > companies_transaction = companies.begin_transaction() You wouldn't do it that way. > I think I'll just require users of modules which handle data to commit > on their own. Not ideal, but it seems to be the best possible. You could take a look at how javabeans does it. From ramraviusa at hotmail.com Sat Aug 28 08:07:30 2004 From: ramraviusa at hotmail.com (Ram Ravi) Date: Sat, 28 Aug 2004 12:07:30 GMT Subject: code examples for Rick Hightower book "Python programming with Java Classes Message-ID: <6A_Xc.196740$8_6.121566@attbi_s04> I would like to get the SourceCode for Rick Hightower book "Python programming with Java Classes" (jython book). I went to rickhightower.com and got Connection refused message. Does somebody have the source code from earlier postings? Or a URL where it is available? Thanks From max at alcyone.com Mon Aug 23 20:25:36 2004 From: max at alcyone.com (Erik Max Francis) Date: Mon, 23 Aug 2004 17:25:36 -0700 Subject: Getting at the bits of a 32-bit integer References: <85b54e91.0408231552.75f85727@posting.google.com> Message-ID: <412A8B00.A81AA015@alcyone.com> Phil Frost wrote: > However, doing this sort of thing is rather nonpythonic. Python > abstracts the platform's representation of an integer. Integers in > Python arn't always 32 bits; they are actually the size of C's 'long' > type, which is to say you can find the size by looking at sys.maxint, > but it's more trouble than it's worth. You will also encounter > problems > if you change the highest bit: > > >>> 10 ^ (1 << 31) > __main__:1: FutureWarning: x< a long in Python 2.4 and up > -2147483638 > > Note that the error message isn't even accurate. This is probably a > good > indication that this isn't a common use case! > > So, short story: use a bool (True/False) So use a Python long instead! That way the size of the Python int is irrelevant. -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ It should therefore be difficult in a republic to declare war; but not to make peace. -- John Story From wweston at att.net Tue Aug 24 19:52:04 2004 From: wweston at att.net (wes weston) Date: Tue, 24 Aug 2004 23:52:04 GMT Subject: Newbie: Downloading a pushed file In-Reply-To: References: Message-ID: Josh wrote: > First, I'm new at this. > > Next, my question: I'm trying to write a script that downloads > requested files from a website. > > The site works, I think, as follows: > 1: Give the site a URL > 2: Site comes back with a 'waiting' message, then after some time > returns a bunch of download URL's > 3: If you open a window with the new download url _in the same browser > session_ then you get a new window which says things like 'processing' > for a while, and then pushes you a file, for lack of a better word. > It's sort of like when you go to sourceforge and click a download > mirror, and then after a few seconds you get a window pop up asking to > save the file. > > Now, so far I've managed, in an ugly manner I am sure, to get the > initial page, parse the download URL's, and I did this having pything > use an IE browser, as described in: > http://vsbabu.org/mt/archives/2003/06/13/ie_automation.html > > My problem is when I get to the download page, how do I tell ie to go > ahead and save the file it gets pushed? > > Another question would be how do I do it without IE .. I assume if I > keep the socket open and send the site some header, perhaps > HTTP_REFERER, then it will let me move on to the download pages, but I > havent even figured out how to re-read the socket after the initial page > refreshes (every re-read comes up blank, even though I know the page > should have sent me new data) > > Sorry for my probably poorly worded descriptions, and thanks for any help. > > -Josh -Josh View the page source. Maybe it will show a url or how to make one to get your files. Post the url here if you don't get where you are going. wes From tor.iver.wilhelmsen at broadpark.no Mon Aug 30 12:27:18 2004 From: tor.iver.wilhelmsen at broadpark.no (Tor Iver Wilhelmsen [TeamB]) Date: 30 Aug 2004 18:27:18 +0200 Subject: PHP Documentation References: <4133124f$0$281$4d4ebb8e@news.nl.uu.net> Message-ID: "Guyon Mor?e" writes: > any user can comment on any page in the docs. this results in a lot of > clarifications and examples for the subjects at hand. > > is it an idea to implement this in the python docs? Zope already does this as well. From rnd at onego.ru Tue Aug 17 11:59:58 2004 From: rnd at onego.ru (Roman Suzi) Date: Tue, 17 Aug 2004 19:59:58 +0400 (MSD) Subject: Mind.py In-Reply-To: <41220b22@news.victoria.tc.ca> References: <41220b22@news.victoria.tc.ca> Message-ID: Now it has persistant Memory. Hope it's not a crime ;-) -><------------------------------------------------------------------ #!/usr/bin/python # -*- mode: python -*- # $Id: aLife.py,v 1.1 2004/08/17 15:58:04 rnd Exp $ """ aLife() (artificial life) is the Robot AI Mind main loop. """ import sys, time, os, shelve from Security import Security from Sensorium import Sensorium from Emotion import Emotion from Think import Think from Volition import Volition from Motorium import Motorium from Voice import Voice class Mind: pass def TabulaRasa(): ms = shelve.open("mind", "c") ms['mind'] = Mind() ms.close() def RestoreMemory(): return shelve.open("mind", "c")['mind'] def SaveMemory(m): stored = shelve.open("mind", "c") stored['mind'] = m stored.close() rsvp = 1000 def aLife(): # ATM 27oct2002 or your ID & date. try: m = RestoreMemory() Security(m) # For human control and operation of the AI. Sensorium(m) # Audition other human-robot input senses. Emotion(m) # Quasi-physiological influence upon thought. Think(m) # Syntax and vocabulary of natural languages. Volition(m) # Contemplative selection of motor options. Motorium(m) # Robotic activation of motor initiatives. except: raise sys.exit(0) rjc = int((sys.argv[1:2] or ['0'])[0]) # If the AI has not met with misadventure, fyi = "aLife: calling itself t = %s rejuvenations = %i" % (time.strftime("%Y.%m.%d %H:%H:%S"), rjc) print fyi # Display the Voice:brain "For Your Information". Voice(m) time.sleep(rsvp/1000) # End of quasi-loop time-delay of rsvp-value milliseconds. sys.argv[1] = str(rjc + 1) SaveMemory(m) os.execv(sys.argv[0], sys.argv) # Call aLife again. # End of one pass through the aLife Mind that repeats itself. if __name__ == "__main__": if sys.argv[1] == '0': print "aLife: mind is born" TabulaRasa() aLife() # End of aLife.py From jdhunter at ace.bsd.uchicago.edu Wed Aug 11 09:32:47 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Wed, 11 Aug 2004 08:32:47 -0500 Subject: IronPython-0.6 is now available! In-Reply-To: ("Terry Reedy"'s message of "Tue, 10 Aug 2004 16:31:39 -0400") References: <278de0e.0407281353.27b6a457@posting.google.com> <278de0e.0408100515.5fd3740c@posting.google.com> Message-ID: >>>>> "Terry" == Terry Reedy writes: Terry> In any case, it is standard to do time-consuming numerical Terry> computation in Python with the quasi-standard numerical Terry> extensions. Unless and until the these are ported to .NET, Terry> such programs will not run. Even when they do, there is no Terry> reason to think that they will be significantly faster. As someone with *no* experience with .NET but with some python extension code I may one day find myself trying to port to IronPython, I wonder: does anyone have an idea of what is involved in porting a python extension module to IronPython / .NET. Any thoughts on how the use of extension building code interacts with this, eg boost::python, pycxx or SWIG? Thanks, John Hunter From redneck at lowtech.net Mon Aug 9 16:53:56 2004 From: redneck at lowtech.net (Robert) Date: Mon, 09 Aug 2004 20:53:56 GMT Subject: VB-like GUI designer? References: Message-ID: Detlev Offenbach wrote: > > Give "eric3" a try (http://www.die-offenbachs.de/detlev/eric3.html). > It is a complete Python IDE using Qt-Designer for GUI development and > Qt-Linguist for translating the GUI. > > Detlev I'll second that! Very well done. Wish I could program like that! -- Robert - slackware From Brian.Inglis at SystematicSW.Invalid Tue Aug 31 00:23:11 2004 From: Brian.Inglis at SystematicSW.Invalid (Brian Inglis) Date: Tue, 31 Aug 2004 04:23:11 GMT Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4PGdnfsOfdDPi63cRVn-tA@speakeasy.net> <41337FC9.8070902@hotmail.com> Message-ID: On Tue, 31 Aug 2004 01:12:55 +0000 (UTC) in alt.folklore.computers, Andre Majorel wrote: >On 2004-08-30, Antony Sequeira wrote: >> Windows (MS) is not 'Unixism'? > >If by unixism, you mean any operating system that has a >hierarchical filesystem and byte stream files, yes. But that >would include quite a few other non-Unix operating systems, >including Mac OS 9, Prologue and probably everything else this >side of CP/M (DOS 1.x shall be deemed to be CP/M). DOS 2.x+ shall be deemed to be CP/M+! -- Thanks. Take care, Brian Inglis Calgary, Alberta, Canada Brian.Inglis at CSi.com (Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]ca) fake address use address above to reply From sjdevnull at yahoo.com Mon Aug 9 10:31:57 2004 From: sjdevnull at yahoo.com (G. S. Hayes) Date: 9 Aug 2004 07:31:57 -0700 Subject: ThreadingTCPServer, asyncore and Client-to-Client communication References: <81efeef2.0408072015.60addf38@posting.google.com> Message-ID: <96c2e938.0408090631.3b8744a3@posting.google.com> dustin at jabberdust.com (Dustin) wrote in message news:<81efeef2.0408072015.60addf38 at posting.google.com>... > I've been trying to create a "byte streaming server", it's basically a > chat server, but I'd like to use it for transfering large amounts of > data between two connected clients. Sounds simple enough, but I'm > having a difficult time implementing it. investigate os.select; you don't even need multiple threads for this operation. From ajsiegel at optonline.com Sun Aug 22 13:52:26 2004 From: ajsiegel at optonline.com (Arthur) Date: Sun, 22 Aug 2004 17:52:26 GMT Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? References: Message-ID: <02mhi0prul0tnmt8jpcqhiiov2nvru6ctf@4ax.com> On 22 Aug 2004 19:27:59 +0300, Ville Vainio wrote: >>>>>> "Arthur" == Arthur writes: > > Arthur> It seems ironic to me that in a group devoted to an > Arthur> appreciation of Python, and its advocacy - it is often > Arthur> those who reject the notion that the language has the > Arthur> kinds of glaring weaknesses that require some fundamental > Arthur> change ot it, that form the opposition to an > Arthur> "establishment" that has become convinced quite otherwise. > >If you don't want improvements to the language, don't download the new >version. Keep on writing the code in the old style, and run foreign >code through a preprocessor that e.g. converts decorators to the old >non-syntax style. >If you really want a stagnant, non-evolving language, there are many >to choose from. I guess Python could also be forked to a special >ZombiePython edition, where heresy like a+=4 and list comprehensions >are unheard of. This reaction to my remarks is predictable. Ascribing to those remarks an extremism they do not intend. And then attacking that extreme position. Why did new style classes and attendant matters - the most sweeping re-architecture of the language probably since its inception - make it into the language without a near peep of controversy? And integer division cause an uproar? To me, the first seems evolutionary and truly seems to be Guido's inner gyroscope at work The second made its way to the top of the agenda in round-about ways, and seemed a near arbitrary point of focus. Since I've been around, the controversial issues are the ones that deserved their controversy - Python folks being a reasonable and intelligent lot. Art > > Arthur> I sometimes wish those folks were more candid about its > Arthur> deficiencies before I started my study of it back in 1.5.2 > Arthur> days. > >If Python was still like 1.5.2, 90% of the current community would be >running Ruby (assuming it would have evolved while Python had >stagnated). From mo.dor at fly.srk.fer.hr Tue Aug 3 03:39:46 2004 From: mo.dor at fly.srk.fer.hr (Zeljko Vrba) Date: Tue, 3 Aug 2004 07:39:46 +0000 (UTC) Subject: advice for perl expert wanting to learn python Message-ID: Now, why would I like to learn Python: because of IronPython port to CLR. Perl port to CLR doesn't seem to be coming soon. First Perl6 for Parrot has to be written, and then other backends.. What's the easiest way of learning python knowing perl? Is there somewhere a 'how-to' cookbook with parallel examples of frequent idioms in perl and python? And most important thing, how does Python deal with database connectivity? Is there a single API (akin to DBI) for connecting to databases? How does Python support the following databases: - Oracle - Postgres - MySQL - SQLServer (maybe using freetds?) - ODBC connectivity (connecting to MS Access) From lbates at swamisoft.com Mon Aug 30 11:13:44 2004 From: lbates at swamisoft.com (Larry Bates) Date: Mon, 30 Aug 2004 10:13:44 -0500 Subject: why does this fail on python 2.2? References: Message-ID: Because __slots__ and __new__ were added in 2.3. Larry Bates Syscon, Inc. "John Hunter" wrote in message news:mailman.2611.1093878644.5135.python-list at python.org... > > I'm trying to understand why some code from a module I'm using is > failing on 2.3 (sic) but working on 2.3. Here is the minimal example that > replicates the problem > > class Results(object): > __slots__ = ( "__doinit" ) > def __new__(cls): > retobj = object.__new__(cls) > retobj.__doinit = True > return retobj > > x = Results() > > On python2.2, this fails with > > mother:~/tmp> python2.2 test.py > Traceback (most recent call last): > File "test.py", line 8, in ? > x = Results() > File "test.py", line 5, in __new__ > retobj.__doinit = True > AttributeError: 'Results' object has no attribute '_Results__doinit' From rogerb at rogerbinns.com Sun Aug 15 17:41:26 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Sun, 15 Aug 2004 14:41:26 -0700 Subject: Python secure? References: Message-ID: Calvin wrote: > Sorry I should have said I'm new to programming let alone Python. I > wish to know whether Python is secure as an exe for a commercial > product. Yes. Anyone who recovers your "code" and/or uses it will be in violation of copyright and several other laws. That is legal protection no matter what languages or combination of languages you use. Roger From davidf at sjsoft.com Fri Aug 6 04:34:38 2004 From: davidf at sjsoft.com (David Fraser) Date: Fri, 06 Aug 2004 10:34:38 +0200 Subject: Sending Mail via Extended MAPI In-Reply-To: <87pt69uz53.fsf@pobox.com> References: <87llh18dqt.fsf@pobox.com> <87pt69uz53.fsf@pobox.com> Message-ID: John J. Lee wrote: > David Fraser writes: > >>John J. Lee wrote: > > [...] > >>>IIRC, there's a commercial COM server that wraps up Extended MAPI and >>>exposes a clone of the Simple MAPI interface. >> >>I think this must be Outlook Redemption ... > > Yeah, that rings a bell. From the name, I guess I misremeber the API > it exposes, though... > >>anyway we'll try and see >>if we can implement what we need without them :-) > > Rather you than me :-) > > John We have now discovered that pywin32 contains a win32com.mapi class which wraps extended MAPI! That plus some finding C++ code that actually manages to send mail via extended MAPI and we're nearly there ... Just need to work out how to construct a PyADRLIST for the PyIAddrBook.ResolveName function from that module which isn't clear from the docs or the source or anywhere else ... but that looks like the last hurdle. When its done we'll write it up as a Cookbook item or something Cheers David From dharding at gmail.com Wed Aug 18 22:53:31 2004 From: dharding at gmail.com (Daniel Harding) Date: 18 Aug 2004 19:53:31 -0700 Subject: age of Python programmers References: Message-ID: <7e8fc64.0408181853.2d9bebf8@posting.google.com> "Lucas Raab" wrote in message news:... > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... 25 here. Started programming at 13 with HyperCard on a Mac SE. Been through many languages since then and though the bulk of my employment is currently in C++, I use Python whenever I can for side projects and personal programming ever since I started digging into it about a year and a half ago. From fperez528 at yahoo.com Fri Aug 6 14:19:35 2004 From: fperez528 at yahoo.com (Fernando Perez) Date: Fri, 06 Aug 2004 12:19:35 -0600 Subject: Plotting histograms, scatter plots in Python References: Message-ID: Dr. Colombes wrote: > What is the easiest way to generate some plots and graphs in Python ? > > Specifically interested in simple histograms and scatter plots with > circles and regression lines. google('matplotlib') google('gnuplot.py') hth, f From jerf at jerf.org Tue Aug 31 13:49:30 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Tue, 31 Aug 2004 17:49:30 GMT Subject: Beginners question. References: Message-ID: On Tue, 31 Aug 2004 18:23:23 +0100, Player wrote: > mylist = [1, 2, ["three", "four"], "five"] > for item in mylist: > if item == type(list): > myitem = len(item) > print myitem > else: > print item General tip: Don't forget how much fun the interpreter is: Python 2.3.4 (#1, Jun 8 2004, 17:41:43) [GCC 3.3.3 20040217 (Gentoo Linux 3.3.3, propolice-3.3-7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> item = ["three", "four"] # since this is the one we wonder about >>> item == type(list) False >>> # Uh-oh, there's the problem, let's see if we can get a clue: ... >>> item ['three', 'four'] >>> type(list) >>> # Clearly, there's something wrong here; try Russell's solution: ... >>> type(item) >>> list >>> # Ah ha! ... >>> From ptmcg at austin.rr._bogus_.com Mon Aug 23 11:04:25 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 23 Aug 2004 15:04:25 GMT Subject: J2 paper 0.2.1 References: Message-ID: "Robert Brewer" wrote in message news:mailman.2201.1093271860.5135.python-list at python.org... Colin J. Williams wrote: > One nit picking comment on Robert Brewer's document: An > annotation is a > transformation of a function, as a change to the flow of control is. I'd like someone to analyze that further. "Transform", like the word "change", can mean almost anything in English. However, I find the use of the term in programs to generally mean either coerce/convert/cast between types, or some other mechanism whereby one object is supplied, and another object returned. That is, "transform" affects Being/"is" as opposed to Attribute/"has". (sorry about the double post - damned newsreader!) I saw this earlier and meant to comment on it. How does annotating a function transform it? Does adding a docstring or ascribing authorship change the function's behavior or logic? Do you mean "annotation" in the Java or C# sense? If so, I think you are correct. But I chalk this up to those languages' poor use of the term "annotation." I think Robert is using "annotation" in the more general conversational sense. If you interpret "transform" to mean "change in any way," well then it is hardly a meaningful term to use for categorizing types of changes. I read Robert's use of "transform" to mean specifically "change the logic/behavior/interface", whereas "annotation" refers to commentary, version, copyright, or other notational attributes. (I could contrive a very narrow example, in which code logic may branch depending upon the value of __version__, but this is a stretch. More likely, code in the *caller* may change depending on __version__, but then this would be a transformation of the *caller*.) I think Robert cites a useful test. Things like synchronize, memoize, staticmethod all extend the behavior of the embedded function, thereby transforming it to lock, cache results, or change interface, *AND* a different object is returned. However, annotations such as author, version, and copyright merely add attributes to the function, but do not need to return a new object. I would not include preconditions or postconditions or argument type checking into either of these groups by the way - while they do change behavior (by adding checking code), I think they are their own special case of "transform", that are specifically oriented to defining assertions to be met (without cluttering the code of the embedded function). Maybe instead of "transformational" they could be called "assertional." My $0.02, -- Paul From flupke at nonexistingdomain.com Tue Aug 10 12:07:56 2004 From: flupke at nonexistingdomain.com (flupke) Date: Tue, 10 Aug 2004 16:07:56 GMT Subject: wxPython & redirecting stderr Message-ID: Hi, i'm developing an app in wxPython but when i have an error in the wxPython code i've written, the app starts, an extra windows is opened where the error messages are print and then it closes again. Off course, this is to fast for the human eye to read :) How can i avoid this and have the wxPython messages arrive at the console just like the "normal" python error messages? Thanks, Benedict From ykingma at accessforall.nl Sat Aug 21 13:37:12 2004 From: ykingma at accessforall.nl (Ype Kingma) Date: Sat, 21 Aug 2004 19:37:12 +0200 Subject: Jython and super_reload? References: <412458a6$0$45379$e4fe514c@dreader19.news.xs4all.nl> Message-ID: <41278848$0$88491$e4fe514c@dreader15.news.xs4all.nl> Dave Benjamin wrote: > In article <412458a6$0$45379$e4fe514c at dreader19.news.xs4all.nl>, Ype Kingma wrote: >> >> This works for classes: >> >> http://www.jython.org/docs/jreload.html >> >> You can unload a module in Jython by removing it from sys.modules, >> and (off course) by removing all other references to it. >> >> To be sure about what happens you can tell the JVM to be verbose >> about garbage collection of Java classes, and explicitly call >> java.lang.System.gc() in some test scripts. > > Thanks for the link and the comments, but I don't think this is quite what > I'm trying to do here. I'm not trying to reload Java classes, I'm trying to > reload Python modules such that any instances of the old version of that > module's classes get updated to use the new methods. For instance: > > mymod.py > -------- > class A: > def test(self): > print 'hello' > > app > --- > import mymod > a = A() > a.test() > (output: 'hello') > > mymod.py > -------- > class A: > def test(self): > print 'goodbye' > > app > --- > reload(mymod) > a.test() > (output: still 'hello') > > # This is what I've been unable to accomplish: > from magic import super_reload > super_reload(mymod) > a.test() > (output: 'goodbye') > > Does that make sense? The end result is that I want to be able to modify > classes in a running application and have this affect all existing class > instances. This is important because I am working in an application server I don't think the Python language supports it. One could replace the module in sys.modules, but that does not remove the reference to the old module and its contents in existing instances. > environment where restarts are costly and time-consuming, and instances are > often kept in user sessions. Currently, any changes to a class require that > the session be reinitialized (ie. you have to log out and log back in), > which makes incremental testing and development awkward. You might solve the problem by convincing the users to reinstantiate their classes after replacing the module in sys.modules. Replacing the Python class of a Python instance is tricky (to say the least) because of Python's dynamic nature. And even without Python dynamics one can get into strange situations. When you convince the users to reinstantiate their classes, my guess is that sooner rather than later some of your users will manage to bring their sessions into an irreproducable (error) state because they forgot to replace some instances. In a Java JVM one can have multiple fully independent Jython system states by using different Java class loaders. This is safe, but it costs some memory. This has been done by others, please check the jython-user and jython-dev archives. Good luck, Ype From max at alcyone.com Mon Aug 9 14:10:06 2004 From: max at alcyone.com (Erik Max Francis) Date: Mon, 09 Aug 2004 11:10:06 -0700 Subject: Question References: Message-ID: <4117BDFE.8FC079D4@alcyone.com> Dag Hansteen wrote: > How do I this ? I have a string with a such expression and I want to > return the answer in a variable. Use eval, but use it wisely. -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ Consistency is the last refuge of the unimaginative. -- Oscar Wilde From bokr at oz.net Thu Aug 12 01:26:20 2004 From: bokr at oz.net (Bengt Richter) Date: 12 Aug 2004 05:26:20 GMT Subject: Static method object not callable References: Message-ID: On Thu, 12 Aug 2004 02:07:31 GMT, "Edward Diener" wrote: >Bengt Richter wrote: >> On Wed, 11 Aug 2004 02:40:07 GMT, "Edward Diener" >> wrote: >> >>> Paul Morrow wrote: >>>> Edward Diener wrote: >>>>> This simple code example gives me the message, "TypeError: >>>>> 'staticmethod' object is not callable". >>>>> >>>>> class X(object): >>>>> def Y(x): >>>>> print x >>>>> Y = staticmethod(Y) >>>>> ad = { 1 : Y } >>>>> def Z(self): >>>>> self.ad[1](3) >>>>> x = X() >>>>> x.Z() >>>>> print "Done." >>>>> >>>>> I know there must be a way to have a class attribute reference a >>>>> static method, and then call that static method through the >>>>> reference, so if anyone can correct this it would be appreciated. >> By 'reference' are you referring to the Y in ad? >>>>> >Yes. I understand now why it won't work but I think this is a limitation of >Python. Evidently, if I set up my class attribute 'ad' to be "ad = { 1 : >X.Y }", then calling static method X.Y through "self.ad[1](3)" would work. >But Python does not allow me to say 'X.Y' from within a class attribute of X >because X has not been fully defined as a class at that time. As one person >answered, I can say "X.ad = { 1 : X.Y }" after the definition of class X and >that works fine. But that is very kludgy to me, forcing me to wait until the >definition of X is finished in order to create my ad class attribute. > >I thank you very much for the explanation of _get_ and how static methods >work in Python. It still feels unnatural not to be able to reference a class >attribute of a class in another class attribute of the same class from >within the class definition. > > Ok, got a couple things done. Reward time = play with python a little ;-) Since ad is an attribute, you could give *it* some magic, if you wanted to get your effect. Taking a cue from staticmethod and property etc, we'll call it dienerize, and you use it to dienerize a dict class variable, analogous to method = staticmethod(method). Then dict values that are descriptors will be called to see what reading them as attributes would produce. Non-descriptor dict values just come through plain. I added a 2:'ordinary' example in the dict, and 3:Z to refer to an ordinary method, which is a function-valued class variable, but functions all have __get__ methods, so they become transformed when they are accessed as attributes (or the equivalent magic). I had do move the ad definition so the Z name reference was valid. I'm living with your capitalized method names through gritted teeth ;-) Also added X.W to help show some effects. Don't take this as gospel, it's the first time I tried this twist on a descriptor ;-) ----< diener.py >-------------------- #diener.py class dienerize(dict): def __getitem__(self, key): value = dict.__getitem__(self, key) if not hasattr(value, '__get__'): return value return value.__get__(*self.getargs) def __get__(self, *getargs): self.getargs = getargs return self # which should act like magic dict class X(object): def Y(x): print x Y = staticmethod(Y) def Z(self): self.ad[1](3) ad = { 1 : Y, 2: 'ordinary', 3: Z } ad = dienerize(ad) def W(self, *args): for i,arg in enumerate(args): self.ad[1]('arg %2s: %r'%(i,arg)) # use Y for printing ;-) x = X() x.Z() x.W(1,2,3) x.W(X.Y, X.__dict__['Y'], x.ad[2], X.ad[2]) x.W(X.ad, X.__dict__['ad'], x.ad[1], X.ad[1]) x.W(x.ad[1], x.ad[2], x.ad[3]) # note that 3:Z becomes bound x.W(x.ad[3],' ^--x.ad[3]',X.ad[3],' ^--X.ad[3]', x.__class__.__dict__['Z'], " ^--x.__class__.__dict__['Z']") print "Done." ------------------------------------- Running it: [22:18] C:\pywk\sovm>diener.py 3 arg 0: 1 arg 1: 2 arg 2: 3 arg 0: arg 1: arg 2: 'ordinary' arg 3: 'ordinary' arg 0: {1: , 2: 'ordinary', 3: } arg 1: {1: , 2: 'ordinary', 3: } arg 2: arg 3: arg 0: arg 1: 'ordinary' arg 2: > arg 0: > arg 1: ' ^--x.ad[3]' arg 2: arg 3: ' ^--X.ad[3]' arg 4: arg 5: " ^--x.__class__.__dict__['Z']" Done. Since you now know why the original "didn't work" I figure you will know why this one appears to ;-) Gotta go. Regards, Bengt Richter From anthonybaxter at gmail.com Fri Aug 13 02:43:05 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 13 Aug 2004 16:43:05 +1000 Subject: PEP318 In-Reply-To: References: <20040812090056.00001e31@titan> <7ttmh0t8c3cogtbhhnp1ohqu8b51pda461@4ax.com> Message-ID: On Thu, 12 Aug 2004 17:03:19 GMT, Arthur wrote: > >def foo (): > > whatever > >foo = decorator (foo) > > > >is that you have to type the word "foo" three times. > > Big f**king deal - all things considered. ;) When this name is a PyObjC name that might be 70 characters long, it becomes a big deal. From rnichol_rrc at yahoo.com Sun Aug 15 02:18:57 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Sun, 15 Aug 2004 01:18:57 -0500 Subject: Python secure? In-Reply-To: References: Message-ID: Calvin wrote: > Hi All, > > Could someone tell me just how secure Python is if compiled to an exe? Is it > more or less secure than using some other language? > > Thanks > > In my experience, the security of a product is due to the programmer and not the language. The language will only make it more or less prone to software flaws. Of which a secruity flaw is just an exploitable software flaw. Do your error checking and put in place *many* checks and balances and it'll all be fine. From david at fielden.com.au Wed Aug 4 22:52:27 2004 From: david at fielden.com.au (Rowdy) Date: Thu, 05 Aug 2004 12:52:27 +1000 Subject: cgi script headers - help In-Reply-To: <1091672967.41119b8746b79@www-mail.usyd.edu.au> References: <1091672967.41119b8746b79@www-mail.usyd.edu.au> Message-ID: <4111A0EB.6060609@fielden.com.au> Ajay wrote: > hi! > > i am generating a file on the fly and making a user download it. > print "Content-Type: application/model\n\n" > print "Content-Disposition: attachment; filename=modeldef3\n" > print str > > i set the Content-Disposition to force a download dialog box and also give > the file a name. > however when i view the headers sent by my script, i have only > HTTP/1.1 200 OK > Date: Thu, 05 Aug 2004 02:26:48 GMT > Server: Apache/1.3.19 (Unix) > Connection: close > Content-Type: application/model > > why isn't the Content-Disposition header coming up? > > thanks > > cheers > > -- > Ajay Brar, > CS Honours 2004 > Smart Internet Technology Research Group One guess would be the double \n at the end of the Content-Type line - try removing one and see if that works. Rowdy From peter at engcorp.com Wed Aug 4 23:08:28 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 04 Aug 2004 23:08:28 -0400 Subject: Does python support multi prototype. In-Reply-To: References: <2natmnFv86rjU1@uni-berlin.de> Message-ID: <38ednYH1NLwwOYzcRVn-uA@powergate.ca> Jorgen Grahn wrote: > Your code was kind of elegant, but kind of misses the point with > overloading, I think. At least, it's not anything I'd want to do in most > situations where overloading would have been nifty in C++. IMHO. Okay, fair enough. Would you be able to describe any situation in which you have found overloading to be useful in C++. (Note, not merely nifty, but useful?) In my experience, most of the cases where I used it in C++ were actually cases of poor design and should have been done differently, in hindsight. -Peter From aahz at pythoncraft.com Wed Aug 11 18:57:42 2004 From: aahz at pythoncraft.com (Aahz) Date: Wed, 11 Aug 2004 18:57:42 -0400 Subject: REMINDER: BayPIGgies: August 12, 7:30pm Message-ID: <20040811225742.GA16650@panix.com> The next meeting of BayPIGgies will be Thurs August 12 at 7:30pm. It will feature general discussion of programming and debugging GUI applications (Qt, Tkinter, wxPython, etc). BayPIGgies meetings are in Stanford, California. For more information and directions, see http://www.baypiggies.net/ Before the meeting, some people will meet at 6pm for dinner at Patxi's Pizza. Ducky Sherwood is handling that; please send RSVPs to ducky at osafoundation.org by 4pm Thurs. Discussion of dinner plans is handled on the BayPIGgies mailing list. Patxi's Pizza (next door to Jing Jing) http://www.patxispizza.com/ 441 Emerson Street Palo Alto, California 94301 650-473-9999 (Pizza takes 30-40 minutes to arrive after ordering; be sure to arrive on time or order ahead.) Advance notice: The September 9 meeting agenda has not been set. Please send e-mail to baypiggies at baypiggies.net if you want to make a presentation. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From bjg at network-theory.co.uk Fri Aug 27 04:56:19 2004 From: bjg at network-theory.co.uk (Brian Gough) Date: 27 Aug 2004 09:56:19 +0100 Subject: asynchat connection timeout References: Message-ID: <87y8k19cy4.fsf@network-theory.co.uk> Josh Close writes: > I'm using asynchat and I'm getting an error > > error: (110, 'Connection timed out') > > This is ok, but how do I set what the timeout is? It is built on the socket module, which has these methods: socket.getdefaulttimeout() -- get the default timeout value socket.setdefaulttimeout() -- set the default timeout value -- Brian Gough Network Theory Ltd, Publishing the Python Manuals --- http://www.network-theory.co.uk/python/ From __peter__ at web.de Sun Aug 29 03:01:17 2004 From: __peter__ at web.de (Peter Otten) Date: Sun, 29 Aug 2004 09:01:17 +0200 Subject: about presicion References: <8f17f4bc.0408281303.3cfb4199@posting.google.com> Message-ID: Peter Hansen wrote: > Ali wrote: > >> The decimal module comes with python 2.4? I have 2.3, :(, what do I do? > > The obvious answer is, well, obvious. The real question is > what's stopping you from upgrading? > > -Peter The module's docstring starts with "This is a Py2.3 implementation of decimal floating point arithmetic", so there is hope you can just drop it into your 2.3 instalation. Peter From pm_mon at yahoo.com Fri Aug 20 19:49:24 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Fri, 20 Aug 2004 19:49:24 -0400 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: Paul Morrow wrote: > def baz(a,b,c): > __synchronized__ = True > __accepts__ = (int,int,int) > __returns__ = int > __author__ = 'Fred Flintstone' > > return a + b + c > Sorry about the indentation screw-up on that return stmnt... From blaktyger at hotmail.com Fri Aug 13 20:26:58 2004 From: blaktyger at hotmail.com (Blaktyger) Date: 13 Aug 2004 17:26:58 -0700 Subject: Displaying images stored as binary in MySQL References: Message-ID: Benjamin Niemann wrote in message news:... > Blaktyger wrote: > > > How can this be done? Images are stored in a LONGBLOB field. When I > > try to display them, it prints out the binary data as it is... > Display where? On local screen, in a webbrowser? > Assuming the first one, see post by Tom. > Assuming the second one (you're writing a cgi,mod_python... program), > did you set the content-type in the http header correctly? In a webbrowser... this is my code... #!/usr/bin/python2.3 print 'Content-Type:image/jpeg\n\n' import blakHtml, sys sys.stderr = sys.stdout import MySQLdb import urllib import cgi import time prevPg=blakHtml.HTMLDocument() newConnection=MySQLdb.connect(host='localhost', user='blaktyger', \ passwd='linux4ever', db='photoFamille') curseur=newConnection.cursor() sqlCmdFr="""SELECT * FROM photo""" curseur.execute(sqlCmdFr) resultats = curseur.fetchall() p=0 for val in resultats: p=p+1 #print '' THIS DOES NOT WORK print val[5] newConnection.close() I know there is no HTML code but this is just a test... From stuart at stuartbishop.net Thu Aug 12 17:00:42 2004 From: stuart at stuartbishop.net (Stuart Bishop) Date: Thu, 12 Aug 2004 22:00:42 +0100 Subject: What happened to initd.org In-Reply-To: <411b24f9$0$15884$cc9e4d1f@news.dial.pipex.com> References: <411b24f9$0$15884$cc9e4d1f@news.dial.pipex.com> Message-ID: On 12/08/2004, at 9:06 AM, Vladimir Konrad wrote: > I am looking for psycopg (PostgreSQL adapted for Python) for Fedora > Core 2 > and the source web site (initd.org) is down second day in a row. > > Any idea what happened? Federico is traveling at the moment so there might not be anyone around to fix server problems. -- Stuart Bishop http://www.stuartbishop.net/ -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 193 bytes Desc: This is a digitally signed message part URL: From aranders at insightbb.com Sun Aug 8 23:56:52 2004 From: aranders at insightbb.com (Alan Anderson) Date: 8 Aug 2004 20:56:52 -0700 Subject: Klingon (was Re: RELEASED Python 2.4, alpha 2) References: <411231C8.3020308@interlink.com.au> <2-SdnZCwNs1SwI_cRVn-uQ@powergate.ca> <53449fcb.0408062138.68a1c196@posting.google.com> Message-ID: <53449fcb.0408081956.37a73abe@posting.google.com> Peter Hansen wrote: > Hmm... the last time I heard, which admittedly was several years ago, > there were only a couple of fluent Klingon speakers on the entire > planet, though thousands had attempted to learn it. And one of those > was the originator of the language. Maybe that data was incorrect, > or has changed? If you're correctly remembering what you heard, what you heard was incorrect. :-) The usual quote is from a 1996 issue of Wired magazine: "All the fluent Klingon speakers can comfortably go out to dinner together." That is arguably still the case, though the definition of "comfortably" would be up for interpretation. It would take a rather large table, and I would say that not everyone could easily participate in the same conversation merely because they'd be too far away from each other. (At the conference banquet last Wednesday, I noticed at one point that there were three separate Klingon conversations going on at the same time.) I might be able to count on my digits the number of people with whom I personally have had extended conversations in Klingon, but I definitely would have to remove my socks. And, ironically, the creator of the language is not one of the people I would consider fluent. > Perhaps as an Esperantist I have a pretty good idea of just how easy > to learn a language can be. But you're right that I have preconceptions > about Klingon. I'd be interested in stats on how many people really > do speak it fluently now. There are no official counts of who speaks Klingon at various levels of fluency. The Klingon Language Institute does offer certification testing, though not everyone who speaks Klingon has had both the desire and opportunity to take such a test. If you're still interested, I might be able to find out how many people have passed each "rank". -- Alan Anderson, professional programmer and amateur Klingonist proud member of the Klingon Language Institute since 1995 qo'mey poSmoH Hol -- language opens worlds -- http://www.kli.org/ From nicolas.ernotte at advalvas.be Fri Aug 20 11:56:10 2004 From: nicolas.ernotte at advalvas.be (Nicolas Ernotte) Date: Fri, 20 Aug 2004 17:56:10 +0200 Subject: Rita Sue and Bob too In-Reply-To: <4125ccff$0$62372$5fc3050@dreader2.news.tiscali.nl> References: <4125ccff$0$62372$5fc3050@dreader2.news.tiscali.nl> Message-ID: <3-6dnQgHms6BgrvcRVnysA@scarlet.biz> Gr?goire Dooms wrote: > This second piece of code searches list for the sequence > ['Rita','Sue','Bob'] in this order and without inserts. > It can be rewritten in a more pythonic way : > > for i in range(len(l)): > if l[i:i+3] == ['Rita','Sue','Bob']: > print 'They were found' > break > else: > print 'They were not in the list' D?cid?ment, le monde est petit ! Nicolas Ernotte, FSA12 ;-) From squirrel at WPI.EDU Fri Aug 6 09:02:17 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Fri, 6 Aug 2004 09:02:17 -0400 Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) In-Reply-To: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> References: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> Message-ID: On Thu, 5 Aug 2004, Istvan Albert wrote: > Ladies and Gents, start your engines and rally around > this syntax (if you prefer it of course) so that there > is evidence that it should be taken as a serious candidate. My vote goes to this. If we have to have decorators, this is how they should look. From tjreedy at udel.edu Sun Aug 15 15:57:30 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 15 Aug 2004 15:57:30 -0400 Subject: Python "decompyle" References: Message-ID: "David D?rrenmatt"
    wrote in message news:opscrrsaxt5kr1pg at news.swissonline.ch... > If I try to use decompyle (decompyle-2.3) for pyc-files < version 2.0, I > get an error with marshal_20 (ImportError: dynamic module does not define > init function (initmarshal_20) ). marshal_20 was compiled to a so-file > using gcc. > > Does anybody know where this error could come from and how to solve it? Your post suggests that your build does work for .pyc files >= version 2.0. Is this correct? Does the doc for decompyle say it should work for earlier versions? The creation of .pyc files is a CPython implementation detail and the format is version specific. So it is easy to imagine that dycompyle might give up or occasionally misfire with ancient .pycs. But maybe the answer lies elsewhere. Terry J. Reedy From anthonybaxter at gmail.com Fri Aug 13 03:19:47 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 13 Aug 2004 17:19:47 +1000 Subject: Yet another decorator proposal In-Reply-To: References: Message-ID: On Wed, 11 Aug 2004 08:06:33 +0200, Marco Aschwanden wrote: > > Here is yet another decorator proposal: > > def sumSequencesLengths(var1, var2): > """Computes something very important. > > __decorators__: > staticmethod > __parameters__: > var1=Sequences > var2=Sequences > __returns__: > int > """ Sorry - you're putting the decorators _inside_ the docstring? Why on earth would you want to do that? In the god-knows-how-many years we've had docstrings, we can't even agree on a common way to mark these up, let alone attaching magic to their meanings...! Note also that one of the advantages of adding decorators is that it offers a cleaner solution for things like SPARK that currently put parse rules inside a docstring. There's a bunch of other nasties like that - e.g. Zope originally used the presence or absence of a doc string to mean "public" or "private". Anthony From fumanchu at amor.org Thu Aug 26 12:48:50 2004 From: fumanchu at amor.org (Robert Brewer) Date: Thu, 26 Aug 2004 09:48:50 -0700 Subject: PEP 322 - alternate method names Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E84@exchange.hqamor.amorhq.net> AC wrote: > >From the PEP 322 page: > > "This PEP has been conditionally accepted for Py2.4. The condition > means that if the function is found to be useless, it can be removed > before Py2.4b1" > > Is there still hope at least for an alternative method name that is > not past tense? "reversed" doesn't have to be a past tense verb in English; it's more of an adjective, modifying its target. "X is a reversed sequence". > flip, transpose, invert, swap... The problem with using a "present tense verb" is that it implies that the original object is mutated. Robert Brewer MIS Amor Ministries fumanchu at amor.org From mark_bottjer at hotmail.com Thu Aug 12 16:32:48 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Thu, 12 Aug 2004 16:32:48 -0400 Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: References: <60dfb6f6.0408111846.615ee9eb@posting.google.com> <3YWdnYxLf--ObofcRVn-pw@powergate.ca> <411ba1db$1@nntp.zianet.com> Message-ID: <411bd3f0$1@nntp.zianet.com> Peter Hansen wrote: > Mark Bottjer wrote: >> With this >> syntax, though, the decorate block changes how the def statement is >> handled, even though they are at the same indentation level. > > Changes it how? The definition of this whole decorator idea has been > that it is equivalent to applying the decorator functions *after* the > def has completed, as in "func = decorator(func)". This does not > in any way changed how the def statement itself is handled. Except that the action happens magically after the def, even though the decorator is before it. To me, this has the appearance of changing the action of def. I'm trying to argue based on how it appears, rather than how we know it to be implemented. >> Put another way: applying what I know about how indentation is used >> elsewhere in Python to this syntax, I would expect the effect of the >> decorate statement to be limited to the statements indented under it. >> I would not expect it to affect the next statement at the same level >> except by the normal coupling of namespace (program state). > > You don't think of "if" and "else" as being related? When the > expression that is evaluated in the if is true, the "else" > is skipped over... I concede that this would seem to set precedent (in fact, most control statements have something like this). But in all those cases, all the blocks contain normal code, right? This would be the only one in which one of the blocks contained purely "declarative" statements. If the decorators were coded as function calls instead of function names, then I'd say it has parity with if/else, but they aren't. In any case, it seems that we might need to "agree to disagree" on this point. :) > @pie is even less like the rest of Python > (especially now with this weird "swallow newlines" hack to work > around the possibility that people might try to put multiple > @decorators on the same line). That *is* pretty odd. >> Of course, this argument also applies to the prefix @ syntax, but at >> least with that we have a funny character cluing us in to the special >> behavior. > > While here we have a nice explicit keyword "decorate:" which one > can easily find with a search in the documentation, as opposed to > trying to look up a symbol "@". I don't buy the argument that a > funny symbol is somehow going to help people who don't already know > what decorators are, any more than an explicit "decorate:" line > would. Either one says "this is different, go look up what it > means" to a newcomer. FWIW, I don't object to the keyword, I object to the indented block. I agree that newbies will need to look either up. My only real concern is that certain suggested syntaxes (mostly the list or tuple forms) look innocuous enough that newbies may not realize that they've hit something new. Everything past there seems more and more like simple preference. -- Mark From ville at spammers.com Sun Aug 22 15:13:24 2004 From: ville at spammers.com (Ville Vainio) Date: 22 Aug 2004 22:13:24 +0300 Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? References: <02mhi0prul0tnmt8jpcqhiiov2nvru6ctf@4ax.com> Message-ID: >>>>> "Arthur" == Arthur writes: >> If you really want a stagnant, non-evolving language, there are >> many to choose from. I guess Python could also be forked to a >> special ZombiePython edition, where heresy like a+=4 and list >> comprehensions are unheard of. Arthur> This reaction to my remarks is predictable. Arthur> Ascribing to those remarks an extremism they do not Arthur> intend. And then attacking that extreme position. That's possibly true. I hope you accept my apology for extrapolating your attitude more than is fair. Arthur> Since I've been around, the controversial issues are the Arthur> ones that deserved their controversy - Python folks being Arthur> a reasonable and intelligent lot. Perhaps - but I don't remember any controversial decision where an obviously wrong path was chosen. Most monstrosities were incoporated before I started to read c.l.py, though (`repr`, print>>) -- Ville Vainio http://tinyurl.com/2prnb From h.b.furuseth at usit.uio.no Mon Aug 30 12:33:46 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 30 Aug 2004 18:33:46 +0200 Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Paul Morrow wrote: > >>> def baz(): > ... """docstring of baz""" > ... > >>> baz.__doc__ > 'docstring of baz' > >>> baz.__dict__.keys() > [] > > Say what? Why didn't the Python system put baz's docstring into it's > namespace (__dict__)? And where did it put it? I'm fairly new to Python, but I think you are just using the wrong interface to access the namespace. __dict__ isn't necessarily something's namespace, even if it has a __dict__: >>> class C(object): __slots__ = 'hide' ... >>> class D(C): pass ... >>> o = D() >>> o.show, o.hide = 3, 5 >>> o.__dict__ {'show': 3} OTOH, >>> dir(o) ['__class__', '__delattr__', '__dict__', ... 'hide', 'show'] >>> getattr(o, 'hide') 5 >>> def foo(): """docstring""" ... >>> dir(foo) ['__call__', '__class__', '__delattr__', '__dict__', '__doc__', ...] >>> setattr(foo, '__doc__', "nope") >>> help(foo) Help on function foo in module __main__: foo() nope -- Hallvard From jepler at unpythonic.net Tue Aug 17 17:37:15 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 17 Aug 2004 16:37:15 -0500 Subject: flex: plex? In-Reply-To: References: Message-ID: <20040817213714.GA5422@unpythonic.net> If plex uses python regular expressions, you can use the zero-length lookahead assertion instead of flex's A/B syntax: "A(?=B)" Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From h.b.furuseth at usit.uio.no Mon Aug 9 10:33:22 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 09 Aug 2004 16:33:22 +0200 Subject: compromise? keywords for static/class, move decorators to top of function References: Message-ID: Larry Bates wrote: > Couldn't we use a dictionary construct like the one > used in classes to hold the dictionaries attributes. > I'm talking about __dict__ construct. > > def getratio(arg1, arg2): > __decorators__['getratio']={} # Maybe this is automatic? > (...) > I'm certain that I'm missing something very important, Yes: Decorators should be set before the function is called. Your code is executed after function is called. Or if you define some magic to avoid that, it still looks like it is. -- Hallvard From zanesdad at bellsouth.net Tue Aug 17 10:49:39 2004 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Tue, 17 Aug 2004 10:49:39 -0400 Subject: SockerServer.TCPServer problem In-Reply-To: <4122147e$0$27220$61ce578d@news.syd.swiftdsl.com.au> References: <4122147e$0$27220$61ce578d@news.syd.swiftdsl.com.au> Message-ID: <41221B03.5010007@bellsouth.net> huy wrote: > Hi All, > > Can someone explain why this bit of code can't keep up with some java > code which spawns about 200 (threads) simultaneous connections each > sending about 10 mesgs each. I basically don't get the 2000 > connections i expect on the python side. I end up with some number > very close on different runs eg. 1989, 1972, 1992 etc. (Sorry if I post this twice - I'm trying out a new mail client.) You may want to try using the ThreadingTCPServer class rather than TCPServer. Just change this line: > msg_server = SocketServer.TCPServer(("", LISTENING_PORT), PDAHandler) to this: msg_server = SocketServer.ThreadingTCPServer(("", LISTENING_PORT), PDAHandler) BTW - how are you tracking how many connections you have open with the Python server? It may be that the process accepts the connection, puts them into a queue to be handled, and waits for the deals with them as it can. Or is the 2000 the total number of connections that the 200 threads produce over the whole run (each making 10 connections)? Jeremy Jones From a9605473 at unet.univie.ac.at Wed Aug 4 05:48:01 2004 From: a9605473 at unet.univie.ac.at (Gaubitzer Erwin) Date: Wed, 04 Aug 2004 11:48:01 +0200 Subject: How to dynamically access Numeric subarrays References: Message-ID: Hi at last I found the solution myself It was my fault not to look at the Python basics. The indices in an array is a tuple! So I am able to create automatically such ones with standard operations like MyTuple = (0,0,2,slice(None),4) (look at how to do the slice) and also MyOtherTuple += MyTuple + (2,) or QuickTuple = (0,)*5 and inserting it into an array MyArrayWithIndices[MyTuple] Thanks to all for thinking about it Greetings Erwin From claird at lairds.us Tue Aug 24 09:08:12 2004 From: claird at lairds.us (Cameron Laird) Date: Tue, 24 Aug 2004 13:08:12 GMT Subject: using pexpect to control python References: <412b0b21$1@news.unimelb.edu.au> <412b14c2@duster.adelaide.on.net> Message-ID: In article <412b14c2 at duster.adelaide.on.net>, Adrian Casey wrote: >Maurice LING wrote: > >> I know this might sounds wierd but I'm wondering if I can use pexpect or >> os.popen3 function to invoke and control python interpreter to make it >> act like a python interpreter in python? >> >> maurice > >Yes, should be possible. I have used tcl expect to call other expect >scripts successfully in the past. You can use pexpect to control any >command-line tool. > >What are you trying to achieve? > That last is *always* an apt question. Don Libes invented Expect. Expect is a wonderful, wonderful thing; at the same time, its purpose is to mollify "programs with crappy interfaces" (his words), so it's dispensable and inherently sub-op- timal, in a sense I think we can make precise. The point here is that, whenever you're considering controlling a Python-based appli- cation PP with Expect (or pexpect or ...), you should first invest at least ten seconds analyzing whether you're better off re-doing PP's interface. From martindemello at yahoo.com Sat Aug 28 16:40:58 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Sat, 28 Aug 2004 20:40:58 GMT Subject: Generator expressions v/s list comprehensions References: <1gj8y77.6qshr41q531veN%aleaxit@yahoo.com> Message-ID: Mahesh Padmanabhan wrote: > > I am still not clear of the advantages of using generator expressions > (other than less memory consumption) instead of list comprehension for > any given class of problems. Can you cite concrete use cases where > generator expressions would be preferred over list comprehension? Here's a simple example linecount = sum(1 for line in file) linecount = sum([1 for line in file]) The former requires an in-memory list equal to the size of the file. Consigning "other than memory consumption" to a parenthetical remark misses its importance. martin From sandysj at juno.com Tue Aug 17 11:49:11 2004 From: sandysj at juno.com (Jeff Sandys) Date: Tue, 17 Aug 2004 15:49:11 GMT Subject: music resources References: Message-ID: <412228F7.914E3535@juno.com> KeyKit is the closest thing I have found to an executable language for music. The language is somewhat python like, I understand it is a variant of awk. Try some of the Tunetoys at Tim's website and download KeyKit. http://nosuch.com/tjt/index.html I would like to duplicate some of the KeyKit functionality into Python using pythonmidi as a starting point. Thanks, Jeff Sandys Elaine Jackson wrote: > > Is there such a thing as an executable language for music? ... From tim.peters at gmail.com Sat Aug 7 02:27:20 2004 From: tim.peters at gmail.com (Tim Peters) Date: Sat, 7 Aug 2004 02:27:20 -0400 Subject: [Python-Dev] RELEASED Python 2.4, alpha 2 In-Reply-To: <411274C0.4070300@v.loewis.de> References: <411231C8.3020308@interlink.com.au> <411241F5.3080602@v.loewis.de> <1f7befae040805103911610582@mail.gmail.com> <411274C0.4070300@v.loewis.de> Message-ID: <1f7befae04080623276089908e@mail.gmail.com> [Tim, tries the "upgrade" install for 2.4a2, notes that it's pretty slow] [Martin v. L?wis] > Yes. I should probably speed it up by changing the UI sequence number > of RemoveExistingApplications from 1510 to 1450. In case you wonder > what this means: It's obvious: you would add 3000, then cyclically permute the first 3 digits right one position. Tell me something I don't know . > Action 1500 is InstallInitialize; anything from then > on is under transaction control. This means that installer will roll > back the uninstall in case the subsequent install fails. This is > expensive, as it first moves all old files out of the place, then puts > the new ones in, then deletes the old ones. At 1450, the files would > be deleted immediately (I believe), at the cost of not being able to > undo the deinstallation if the installation later fails (e.g. by > user Cancel). I wouldn't do this; it's good that as much of the process as possible is transactional. I doubt it took longer overall than what I normally do (run a full uninstall of the old version, then install the new version). >> One glitch: I'm pretty sure I selected "install only for me" in the >> first screen. I wanted to go back to check, but it doesn't seem >> possible to go back to the first screen. > Yes. I don't know what to do about this: the screen sets ALLUSERS=1, > then performs FindRelatedProducts to find the old installation. If the > old installation was per-machine, we only find it if we commit to making > the new installation also per-machine. Except that in this case, I'm pretty sure my 2.4a1 installation was also "only for me". I could be wrong about that. > That decision cannot be taken back; the user would have to cancel and start > over. Which is an option, so that's cool. >> Anyway, the Python DLL ended up in a system directory, and that's "the >> glitch". I expected/wanted it to end up in my Python directory. > Ok. I will see whether I can reproduce that. I believe I later saw a checkin that intended to fix this, and, if so, that's cool too. I hereby nominate you as MSI-builder For Life . From mov_21h at yahoo.com Sun Aug 15 17:25:15 2004 From: mov_21h at yahoo.com (Bigbowser) Date: Sun, 15 Aug 2004 14:25:15 -0700 (PDT) Subject: Indentation Message-ID: <20040815212516.54857.qmail@web50010.mail.yahoo.com> Hi all, I've been using C++ for about a year now, and i decided to have a go at python but one thing i can't get used to is the indentation, especially as my functions become more and more nested .. this is probably a stupid question, but is there a way to 'hack' or get around this ? or would it require a large rewrite of the majority of the interpretter =/ Regards, Bigbowser __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From grante at visi.com Fri Aug 6 10:50:49 2004 From: grante at visi.com (Grant Edwards) Date: 06 Aug 2004 14:50:49 GMT Subject: Standalone Python Programs... References: <-aSdndbo7ry5E47cRVn-ig@comcast.com> Message-ID: <41139ac9$0$65604$a1866201@newsreader.visi.com> On 2004-08-06, Larry Bates wrote: >> I have a Python program that is built on an infrastructure of >> quite a few other programs, but I would like to create a >> standalone nonetheless. >> >> It doesn't necesarily have to be its own executable, although >> this is the most attractive option - it could just mean >> distributing the entire python distribution with it in an >> installer or something. That's a false dichotomy. There is a choice in-between a "stand-alone program" and "an entire Python distribution": Something like py2exe which creates a "distribution" containing only the things (dll's and compiled+compressed Python modules) needed by your application. Besides, expecting to create a stand-alone executable is pretty unrealistic these days. There are very, very few stand-alone Win32 programs any more (putty.exe is the only one I've seen in the past 5 years). Everything else in the Win32 world seems to need to have a set of files "installed" using an installer. > I've found that py2exe and Inno Setup Installeer to be a good > combination (for Windows). It isn't a single executable, but > then what modern program is any more. It doesn't require > distribution/installation of Python. I've used it to install > some pretty complex combinations (wxWindows, PIL, ReportLab, > etc.) with no problems. Inno Setup has proven to be flexible > enough to install everything that I've done so far. Same here. I've used py2exe + Inno Setup for a handfull of small wxPython applications and it's all worked quite nicely. > I can't speak to Linux installations because I have always > just used the Python installation already there. Yup. -- Grant Edwards grante Yow! I invented skydiving at in 1989! visi.com From aleaxit at yahoo.com Fri Aug 27 06:02:05 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 27 Aug 2004 12:02:05 +0200 Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> <1gj4fb5.607xsc51izh8N%aleaxit@yahoo.com> <7xllg25lkt.fsf@ruckus.brouhaha.com> <1gj4u3a.12ttba9fynd6uN%aleaxit@yahoo.com> <1gj5bp4.qhup8tldmvebN%aleaxit@yahoo.com> Message-ID: <1gj6cfv.nv3fziwoc81nN%aleaxit@yahoo.com> Antoon Pardon wrote: ... > > Yes you can, and in the general case get very different effects, e.g.: > > And what about > > a += b vs a.extend(b) I can go on repeating "in the general case [these constructs] get very different effects" just as long as you can keep proposing, as if they might be equivalent, constructs that just aren't so in the general case. Do I really need to point out that a.extend(b) doesn't work for tuples and strings, while a+=b works as polymorphically as feasible on all these types? It should be pretty obvious, I think. So, if you want to get an AttributeError exception when 'a' is a tuple or str, a.extend(b) is clearly the way to go -- if you want para-polymorphic behavior in those cases, a+=b. Isn't it obvious, too? > >>>> c=a=range(3) > >>>> b=range(2) > >>>> a+=b > >>>> c > > [0, 1, 2, 0, 1] > > > > versus: > > > >>>> c=a=range(3) > >>>> b=range(2) > >>>> a=a+b > >>>> c > > [0, 1, 2] > > I wouldn't say you get different effects in *general*. You get the > same effect if you use numbers or tuples or any other immutable > object. a+=b is defined to be: identical to a=a+b for immutable objects being bound to name 'a'; but not necessarily so for mutable objects -- mutable types get a chance to define __iadd__ and gain efficiency through in-place mutation for a+=b, while the semantics of a=a+b strictly forbid in-place mutation. *IN GENERAL*, the effects of a+=b and a=a+b may differ, though in specific cases ('a' being immutable, or of a mutable type which strangely chooses to define __add__ but not __iadd__) they may be identical. Like for a+b vs b+a: in general they may differ, but they won't differ if the types involved just happen to have commutative addition, of if a and b are equal or identical objects, i.e., in various special cases. "You get different effects *in general*" does not rule out that there may be special cases (immutable types for one issue, commutative-addition types for another, etc, etc) in which the effects do not differ. Indeed, if it was "always" true that you got different effects, it would be superfluous to add that "in general" qualifier. Therefore, I find your assertion that you "wouldn't say you get different effects in *general*" based on finding special cases in which the effects do not differ to be absurd and unsupportable. > > But let's be sensible: if 'it' is joining two strings which are bound to > > names b and c, b+c is the only OBVIOUS way to do it. Building a > > sequence whose items are b and c and calling ''.join on it is clearly an > > indirect and roundabout -- therefore NOT "the one obvious way"! -- to > > achieve a result. Proof: it's so unobvious, unusual, rarely used if > > ever, that you typed entirely wrong code for the purpose... > > That is just tradition. Suppose the "+" operator wouldn't have worked > on strings an concatenating would from the start been done by joining, > then that would have been the one obvious way to do it. In a hypothetical language without any + operator, but with both unary and binary - operators, the one "obvious" way to add two numbers a and b might indeed be to code: a - (-b). So what? In a language WITH a normal binary + operator, 'a - (-b)' is nothing like 'an obvious way'. > > Nobody ever even wished for there to never be two sequences of code with > > the same end-result. The idea (a target to strive for) is that out of > > all the (probably countable) sequences with that property, ONE stands > > out as so much simpler, clearer, more direct, more obvious, to make that > > sequence the ONE OBVIOUS way. > > And what if it are three sequences of code with the same end-result, > or four. From what number isn't it a problem any more if two sequences > of that length or more produce the same result. To add N integers that are bound to N separate identifiers, there are (quite obviously) N factorial "sequences of [the same] length" producing the same result. Is it "a problem"? I guess it may be considered a minor annoyance, but it would be absurd to try and do something against it, e.g. by arbitrary rules forbidding addition between variables except in alphabetical order. Practicality beats purity. > > > We can't always get even that, as a+b vs > > b+a show when a and b are bound to numbers, but we can sure get closer > > to it by respecting most of GvR's design decisions than by offering > > unfounded, hasty and badly reasoning critiques of them. > > I think that this goal of GvR is a bad one. I'm sure you're a better language designer than GvR, since you're qualified to critique, not just a specific design decision, but one of the pillars on which he based many of the design decisions that together made Python. Therefore, I earnestly urge you to stop wasting your time critiquing an inferiorly-designed language and go off and design your own, which will no doubt be immensely superior. Good bye; don't slam the door on the way out, please. > If someway of doing it > is usefull then I think it should be included and the fact that > it introduces more than one obvious way to do some things shouldn't > count for much. This is exactly Perl's philosophy, of course. > > Sure you shouldn't go the perl-way where things seemed to have > been introduced just for the sake of having more than obvious way > to do things. But eliminating possibilities (method chaining) > just because you don't like them and because they would create > more than one obvious way to do things, seems just as bad to > me. If a language should not eliminate possibilities because its designer does not like those possibilities, indeed if it's BAD for a language designer to omit from his language the possibilities he dislikes, what else should a language designer do then, except include every possibility that somebody somewhere MIGHT like? And that IS a far better description of Perl's philosophy than "just for the sake" quips (which are essentially that -- quips). > What I have herad about the decorators is that one of the > arguments in favor of decorators is, that you have to > give the name of the function only once, where tradionally > you have to repeat the function name and this can introduce > errors. > > But the same argument goes for allowing method chaining. > Without method chaining you have to repeat the name of > the object which can introduce errors. I've heard that argument in favour of augmented assignment operators such as += -- and there it makes sense, since the item you're operating on has unbounded complexity... mydict[foo].bar[23].zepp += 1 may indeed be better than repeating that horrid LHS (although "Demeter's Law" suggests that such multi-dotted usage is a bad idea in itself, one doesn't always structure code with proper assignment of responsibilities to objects and so forth...). For a plain name, particularly one which is just a local variable and therefore you can choose to be as simple as you wish, the argument makes no sense to me. If I need to call several operations on an object I'm quite likely to give that object a 'temporary alias' in a local name anyway, of course: target = mydict[foo].bar[23].zepp target.pop(xu1) target.sort() target.pop(xu3) target.reverse() target.pop(xu7) Doing just the same thing when I don't need intermediate access to the object between calls that mutate the object and currently return None is no hardship, just as it isn't when such access IS needed. Note that you couldn't do chaining here anyway, since pop mutates the object but also returns a significant value... > >> The difference between > >> > >> print somelist.sort() > >> > >> and > >> > >> somelist.sort() > >> print somelist > >> > >> > >> is IMO of the same order as the difference between > >> > >> > >> print a + b > >> > >> and > >> > >> r = a + b > >> print r > > > > For a sufficiently gross-grained comparison, sure. And so? In the > > second case, if you're not interested in having the value of a+b kept > > around for any subsequent use, then the first approach is the one > > obvious way; > > No it isn't because programs evolve. So you may think you don't > need the result later on, but that may change, so writing it > the second way, will making changes easier later on. Ridiculous. Keep around a+b, which for all we know here might be a million-items list!, by having a name bound to it, without ANY current need for that object, because some FUTURE version of your program may have different specs?! If specs change, refactoring the program written in the sensible way, the way that doesn't keep memory occupied to no good purpose, won't be any harder than refactoring the program that wastes megabytes by always keeping all intermediate results around "just in case". > > if you ARE, the second, because you've bound a name to it > > (which you might have avoided) so you can reuse it (if you have no > > interest in such reuse, it's not obvious why you've bound any name...). > > > > In the first case, fortunately the first approach is illegal, the second > > one is just fine. Were they exactly equivalent in effect neither would > > be the one obvious way for all reasonable observer -- some would hate > > the side effect in the first case, some would hate the idea of having > > two statements where one might suffice in the second case. > > So? I sometimes get the idea that people here can't cope with > differences in how people code. So any effort must be made > to force people to code in one specific way. When more than one person cooperates in writing a program, the group will work much better if there is no "code ownership" -- the lack of individualized, quirky style variations helps a lot. It's not imposible to 'cope with differences' in coding style within a team, but it's just one more roadblock erected to no good purpose. A language can help the team reach reasonably uniform coding style (by trying to avoid offering gratuitous variation which serves no real purpose), or it can hinder the team in that same goal (by showering gratuitous variation on them). > > Fortunately the first approach does NOT do the same thing as the second > > (it prints out None:-) so Python sticks to its design principles. Let > > me offer a private libation to whatever deities protect programmers, > > that Python was designed by GvR rather than by people able to propose > > analogies such as this last one without following through on all of > > their implications and seeing why this SHOWS Python is consistent in > > applying its own design principles! > > That these implications are important is just an implication on the > design principles. If someone doesn't think particular design principles > are that important, he doesn't care that if somethings is changed that > particulat design principle will be violated. Personnaly I'm not > that impressed with the design of python, it is a very usefull language Great, so, I repeat: go away and design your language, one that WILL impress you with its design. Here, you're just waiting your precious time and energy, as well of course as ours. > but having operators like '+=' which have a different kind of result > depending on whether you have a mutable or immutable object is IMO > not such a good design and I wonder what design principle inspired > them. Practicality beats purity: needing to polymorphically concatenate two sequences of any kind, without caring if one gets modified or not, is a reasonably frequent need and is quite well satisfied by += for example. Alex From theller at python.net Tue Aug 24 04:33:03 2004 From: theller at python.net (Thomas Heller) Date: Tue, 24 Aug 2004 10:33:03 +0200 Subject: fun with unicode files Message-ID: <6579x7eo.fsf@python.net> I want to use ConfigParser with both NT4-style .reg files, which are ascii (or ansi?) files, and XP-stype .reg files which seem to be UTF-16 encoded unicode-files (hope that's the correct terminology). [And yes, I have read the warning in the manual that ConfigParser doesn't interpret the value-type prefixes in the reg files] Here's the start of the method I wrote to detect the encoding and read the file: def _parse_regfile(self, filename): ifi = open(filename, "r") import codecs, StringIO if ifi.read(2) in (codecs.BOM_LE, codecs.BOM_BE): ifi.close() ifi = codecs.open(filename, "r", "utf-16") I wonder: do I really have to check for the BOM manually, or is there a Python function which does that? Continuing the code: # ConfigParser calls .readline(), but: # NotImplementedError: '.readline() is not implemented for UTF-16' # so we need to put the data into a StringIO instance. # Um, cStringIO doesn't handle unicode correctly, so we'll have # to use the slower StringIO ifi = StringIO.StringIO(ifi.read()) ifi.readline() # skip the first two lines ifi.readline() c = ConfigParser() c.readfp(ifi) return c Is there a better way to do this? Why doesn't the UTF-16 codec implement readline()? Thomas From squirrel at WPI.EDU Wed Aug 18 16:14:48 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Wed, 18 Aug 2004 16:14:48 -0400 Subject: age of Python programmers In-Reply-To: <10i7da3cu03eabb@corp.supernews.com> References: <10i7da3cu03eabb@corp.supernews.com> Message-ID: On Wed, 18 Aug 2004, Jeff Shannon wrote: > quickly moved on to Apple //e; <3 the Apple //e. My dad taught me how to program in BASIC on it when I was 6. The Beagle Bros. were like gods to me (anyone else remember them?). Would that Python could run on a //e ;) From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Thu Aug 19 14:32:21 2004 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Thu, 19 Aug 2004 20:32:21 +0200 Subject: age of Python programmers In-Reply-To: References: Message-ID: <4124f237$0$78283$e4fe514c@news.xs4all.nl> Alexandre Fayolle wrote: > Hi, > > Age 30. Started programming at 15 on an Atari 520STe, using GFA Basic... > Been full time Python programmer for 4 years. > GFA Basic! Hey, that brings back memories. I actually used it on the Amiga, there was a great port of it to AmidaDOS at the time. --Irmen From natunika at gmx.de Wed Aug 18 03:35:17 2004 From: natunika at gmx.de (Silke) Date: 18 Aug 2004 00:35:17 -0700 Subject: serial and threads References: <39ba6e78.0408170215.59f5bfc0@posting.google.com> <39ba6e78.0408170554.4b6b46bf@posting.google.com> Message-ID: <39ba6e78.0408172335.84c4eb8@posting.google.com> Hi Peter, I only verified this by checking it out. Here is the code import sys sys.path.append('c:\\python23\\lib\\site-packages\\serial') import thread #This module provides low-level primitives for working with multiple threads import threading #This module constructs higher-level threading interfaces on top of the lower level thread module. import serialwin32 #Python Serial Port Extension for Win32, Linux, BSD, Jython; serial driver for win32; see __init__.py import socket #Low-level networking interface import binascii #Convert between binary and ASCII def NetworkToSerial(input): s.write(binascii.unhexlify(input)) print "SENT: %s" % input # %s: if command is not string format to string def SerialToNetwork(): result = s.read(12) print "RECEIVED:" print binascii.hexlify(result) s = serialwin32.Serial () s.port = 0 #COM1 s.baudrate = 115200 s.databits = 8 s.timeout = None #None=wait forever; 0=return immediately on read; x = x seconds s.open() command = "0b02ff0512340000000255aa" sthread = threading.Thread(target=NetworkToSerial(command)) rthread = threading.Thread(target=SerialToNetwork) sthread.start() rthread.start() sthread.join(5) rthread.join(5) s.close() and it does exactly what I want it to do, so I guess it's ok... Thank you for your help! Bye Silke Peter Hansen wrote in message news:... > Silke wrote: > > I already found a solution using 'threading' instead of 'thread' :-) > > Are you positive that is really a solution? If the original > problem was truly because of a thread-safety issue, then it's > most likely, I think, that it was a race condition and that > it could very well re-appear in the future. > > The "threading" module is mostly just a higher level API on > top of the "thread" module, so that change alone seems unlikely > to solve the issue, unless there is code in serialwin32 specifically > to do the proper locking when the threading module is used... > > -Peter From reply.in.the.newsgroup at my.address.is.invalid Fri Aug 20 04:16:41 2004 From: reply.in.the.newsgroup at my.address.is.invalid (Rene Pijlman) Date: Fri, 20 Aug 2004 10:16:41 +0200 Subject: html templates References: Message-ID: Ajay: >i am looking for a framework to create a fast dynamic website. between >using Cheetah and HTMLTemplate which would you recommend? I've used Cheetah and it's great. I have no experience with HTMLTemplate though. >also quixote offers a session management API? how secure is this session >management? is it just a cookie on the client side? Feel lucky: http://www.google.com/search?q=quixote+session+management -- Ren? Pijlman From anthonybaxter at gmail.com Thu Aug 19 23:32:10 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 20 Aug 2004 13:32:10 +1000 Subject: static class methods and data members In-Reply-To: References: Message-ID: On 19 Aug 2004 12:23:03 -0700, Neil Zanella wrote: > The http://www.python.org/2.2.1/descrintro.html#staticmethods you mentioned > really does contain some of the information I was missing pertaining to > classmethod and staticmethod. This file is not part of the Python documentation. If there's specific bits from it you feel should be in the std documentation, open a SF doc bug and list the bits that are missing. Thanks, Anthony From timblack1 at yahoo.com Sat Aug 28 13:47:30 2004 From: timblack1 at yahoo.com (Tim) Date: 28 Aug 2004 10:47:30 -0700 Subject: How to set wxTextCtrl style to wxHSCROLL? References: <1093356734.77170@news.commspeed.net> Message-ID: Thank you! I couldn't get the wxTextCtrl style to change using the method you suggested, but I tried the StyledTextCtrl which works wonderfully! : ) It made the more complex functionality easier to implement all-around. Tim From uche at ogbuji.net Mon Aug 9 14:35:46 2004 From: uche at ogbuji.net (Uche Ogbuji) Date: 9 Aug 2004 11:35:46 -0700 Subject: read/write XML References: Message-ID: Torsten Mohr wrote in message news:... > Hi, > > i just took a look into the python documentation regarding XML. > XMLDOM look quite big, so i took another look at "minidom". > > So is minidom the preferred way to go to read an XML, handle > its data and also write XML? Depends on many other things. > In the example (13.7.2, SLideshow) the structure seems to be > read into a "dom", but to check its structure against some > criteria seems to be completely missing, e.g.: > > - only defined elements used > - at least one slide in the slideshow > - others ... > > How can i check a "dom" against these criteria? You can use DTD, RELAX NG or Schematron. For DTD use PyXML or libxml2. For RELAX NG, use 4Suite, XVIF stand-alone or libxml2. For Schematron use Scimitar or an XSLT Schematron implementation. We can offer more detailed answers if you ask more detailed questions. -- Uche Ogbuji Fourthought, Inc. http://uche.ogbuji.net http://4Suite.org http://fourthought.com Decomposition, Process, Recomposition - http://www.xml.com/pub/a/2004/07/28/py-xml.html Perspective on XML: Steady steps spell success with Google - http://www.adtmag.com/article.asp?id=9663 Managing XML libraries - http://www.adtmag.com/article.asp?id=9160 Commentary on "Objects. Encapsulation. XML?" - http://www.adtmag.com/article.asp?id=9090 Harold's Effective XML - http://www.ibm.com/developerworks/xml/library/x-think25.html A survey of XML standards - http://www-106.ibm.com/developerworks/xml/library/x-stand4/ From phanish.tubagere at hp.com Mon Aug 23 07:46:09 2004 From: phanish.tubagere at hp.com (Phanish) Date: 23 Aug 2004 04:46:09 -0700 Subject: python usage Message-ID: Hi, One of my customer wants me to use Python as a test scripting language. The architecture is as follows: An C++/Java UI obtains all required inputs from the user and then makes call to Python script which inturns calls c++ client stubs. These stubs are CORBA stubs which talk to a CORBA server residing some where in the network. I want to know as to whether it is feasible to use Python or just live with c++ for UI and stubs? Is it good to use Python for this purpose? What is the advantage? Thanks Phanish From newsgroups at jhrothjr.com Fri Aug 6 16:47:04 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 6 Aug 2004 16:47:04 -0400 Subject: Prothon is switching to the .NET platform References: <000401c47b59$32539220$0d01a8c0@MarkVaio> <10h7lb21dhbuc12@news.supernews.com> Message-ID: <10h7rittck6ct75@news.supernews.com> "Christopher T King" wrote in message news:Pine.LNX.4.44.0408061533250.25906-100000 at ccc8.wpi.edu... > On Fri, 6 Aug 2004, John Roth wrote: > > > I think it's possible to do prototypes within Python by > > overriding the __getattribute__() magic method. It still > > wouldn't be very pretty, but it should be able to do > > everything except override the magic methods (those > > seem to have to be in the class object for new style > > classes). > > Hm, I'd never thought of this before; something along the lines of: > > class derive(object): > def __init__(self,parent): > self.parent = parent > def __getattribute__(self,attr): > return getattr(self.parent,attr) > > myderivedobject = derive(myprototypeobject) > > would do the trick quite nicely I guess. I have one application that > could benefit quite nicely from prototypes; I'll see if I can't work this > in. Thanks for the enlightenment! What I was thinking of was more along the lines of: class ProtoBaseClass(object): def __getattribute__(self, attr): # call object.__getattribute__(self, __dict__) # find requested attribute # if not found, loop through back pointer chain # if it's not a function, return the attribute # if it is a function, wrap it in a method object and return it. def clone(self): # create new instance # insert back pointer to this instance return Then you can create a new instance simply by calling self.clone(). The only time you'd call the class itself is to get a new root instance, which might even be a singleton (making an easy way to get the root instance!). The place where this gets really ugly is inserting functions into the instances. They have to be created at the module level, and then inserted into the instance by a module level function (somewhat similar to the way classmethod, staticmethod and property work). I know someone said they did this sometime in 2000, for 1.5.2, but when I tried to make their code work yesterday it failed right away. A code inspection left me wondering how it could possibly have worked in the first place. I'd be quite interested in what you come up with. John Roth > From ajsiegel at optonline.com Wed Aug 25 20:40:24 2004 From: ajsiegel at optonline.com (Arthur) Date: Thu, 26 Aug 2004 00:40:24 GMT Subject: python-dev Summary for 2004-08-01 through 2004-08-15 References: <3l3pi0pgmgu0uir1ucnj0rlfo355c6i5cp@4ax.com> Message-ID: On Thu, 26 Aug 2004 03:54:53 +1000, Anthony Baxter wrote: >got an exceptionally good track record here. (I discount print >>, >which I still regard as horrible). Not only am I OK with print >> and use print >>, I am clueless in trying to identify the nerve it touches in those who view it with horror. Which gives you a clue - as to with whom you have been wasting your time. ;) Art From dale at riverhall.NOSPAM.co.uk Fri Aug 27 11:40:59 2004 From: dale at riverhall.NOSPAM.co.uk (Dale Strickland-Clak) Date: 27 Aug 2004 15:40:59 GMT Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> Message-ID: > what do you think? should I write a PEP? No. You should use Vim. There's some nice macros for Python. Works lovely. :-) -- Dale Strickland-Clark Riverhall Systems Ltd, www.riverhall.co.uk From olli at fromme.com Mon Aug 23 14:31:57 2004 From: olli at fromme.com (Oliver Fromme) Date: Mon, 23 Aug 2004 20:31:57 +0200 (CEST) Subject: J2 proposal: keyword In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022E40@exchange.hqamor.amorhq.net> from "Robert Brewer" at Aug 23, 2004 10:10:35 AM Message-ID: <200408231831.i7NIVvK8041784@haluter.fromme.com> Robert Brewer wrote: > Oliver Fromme wrote: > > Aren't decorators just functions that are applied to the > > function definition? Then how about "apply"? It's short > > (for those lazy typers), and it expresses exactly what > > happens. > > "apply" is already a builtin. Oops, you're right, of course. The fact that it was made obsolete by the extended call syntax made me forget about it. :-) So, FWIW, I think both "using" and "with" are fine, although both of those remind me of completely unrelated things. ("Using" as in the "print using" statement of certain ancient dialects of BASIC which was used for formatted output, as well as the "use" statement in perl to import a module. And "with" is used in several languages (e.g. PASCAL and ECMA/JavaScript) to denote a block of code that works on the contents of a structure without having to write the structure down each time -- a feature which I wouldn't dislike to have in Python either. ;-) Best regards Oliver -- Oliver Fromme, Konrad-Celtis-Str. 72, 81369 Munich, Germany ``All that we see or seem is just a dream within a dream.'' (E. A. Poe) From jzgoda at gazeta.usun.pl Tue Aug 31 15:11:57 2004 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Tue, 31 Aug 2004 19:11:57 +0000 (UTC) Subject: GUI Designer References: Message-ID: Doug Holton pisze: > On Windows, wxpython is the better GUI toolkit, but I don't use any of > the GUI builders for it. One of them is wxGlade (http://wxglade.sourceforge.net/). Works well. -- Jarek Zgoda http://jpa.berlios.de/ From in.aqua.scribis at nl.invalid Sat Aug 28 20:44:37 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Sun, 29 Aug 2004 02:44:37 +0200 Subject: regex into str In-Reply-To: References: Message-ID: I wrote: > I want to use regular expressions with less typing. Like this: > > A / 'b.(..)' # test for regex 'b...' in A > A[0] # get the last whole match > A[1] # get the first group in the last match I meant: A(0) A(1) While A[0] and A[1] should work like normal string indexing. -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html The Halloween Documents: http://www.opensource.org/halloween/ From skip at pobox.com Thu Aug 5 22:03:55 2004 From: skip at pobox.com (Skip Montanaro) Date: Thu, 5 Aug 2004 21:03:55 -0500 Subject: Confused about pep 318 In-Reply-To: References: <10h2ihgb8c6fi97@corp.supernews.com> <10h4s026oapbhf1@corp.supernews.com> Message-ID: <16658.59147.696173.22095@montanaro.dyndns.org> Michael> PEP 318 has a slightly sorry history. As far as I can Michael> remember, it was written as an attempt to promote a specific Michael> syntax proposal (the 'as' variant? Maybe, it's not really Michael> important). Since then it's been co-opted to be "The Michael> Decorators Pep" and received various rounds of rewrites, none Michael> of which have pleased everyone (surprised? with this topic). Michael> I belive it's fair to say that PEP 318 has *never* accurately Michael> reflected the state of play on this issue. Thank you. As one of the people who have rubbed PEP 318 around in the dirt a bit I think what you wrote about sums up its state. I realize that Guido discussed decorator syntax at EuroPython. A good take-away from that would have been for someone involved in those discussions to take an action item to update the PEP. Skip From was at math.harvard.edu Tue Aug 31 22:02:40 2004 From: was at math.harvard.edu (William Stein) Date: Tue, 31 Aug 2004 22:02:40 -0400 Subject: age of Python programmers References: <889cbba0.0408181206.1812881c@posting.google.com> Message-ID: <-sednbGJb4Wes6jcRVn-sA@comcast.com> nnes wrote: > JanC wrote in message > news:... >> Gerardo Herzig -Departamento de Proyectos Especiales e Internet- Facultad >> de Medicina schreef: >> > 30 years old. First program at 11 (Basic) on ZX Spectrum. >> /me too (now 30 & started with ZX Spectrum Basic at 11) > > count another one, me too now 30 years, started with ZX Spectrum Basic at > 11 Me as well; I'm 30 years old and I started programming BASIC on the TI-99/4A. -- William From jim.vickroy at noaa.gov Fri Aug 13 15:52:13 2004 From: jim.vickroy at noaa.gov (j vickroy) Date: Fri, 13 Aug 2004 13:52:13 -0600 Subject: logging package log_test3.py problem Message-ID: My system: MSW XP professional Python 2.3.3 logging package: 0.4.9.2 My problem: The log_test3.py script, provided with the logging package distribution, generates an unexpected message: No handlers could be found for logger "root" Here is the complete trace from running the log_test3.py script: ======================================== C:\projects\logging-0.4.9.2\test>log_test3.py Traceback (most recent call last): File "C:\Python23\Lib\site-packages\logging\config.py", line 111, in fileConfig h = apply(klass, args) File "C:\Python23\Lib\site-packages\logging\handlers.py", line 559, in __init__ self._welu.AddSourceToRegistry(appname, dllname, logtype) File "C:\Python23\Lib\site-packages\win32\lib\win32evtlogutil.py", line 35, in AddSourceToRegistry "SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s" % (eventLogType, appName)) error: (5, 'RegCreateKey', 'Access is denied.') --------------------------------------------------- -- Logging to root; messages appear on console only --------------------------------------------------- No handlers could be found for logger "root" ---------------------------------------------------------------------- -- Logging to log02; messages appear on console and in file python.log ---------------------------------------------------------------------- -------------------------------------------------------------------------- -- Logging to log02.log03; messages appear on console, in file python.log, -- and at logrecv.py tcp (if running. <= DEBUG messages will not appear). -------------------------------------------------------------------------- ----------------------------------------------------------------------- -- Logging to log02.log03.log04; messages appear only at logrecv.py udp -- (if running. <= INFO messages will not appear). ----------------------------------------------------------------------- -------------------------------------------------------------------- -- Logging to log02.log03.log04.log05.log06; messages appear at -- logrecv.py udp (if running. < CRITICAL messages will not appear). -------------------------------------------------------------------- -- All done. ======================================== I expect the Windows NT EventLog handler to fail since I am running under an account that does not have Windows Registry update privileges. However, I did not expect to see the message: No handlers could be found for logger "root" Also, I have not been able to get a demo script to work that uses logging.config.fileConfig with custom handlers I have written. Is this permissable? If so, how? Here is a sample error I'm seeing: NameError: name 'Details_Log' is not defined -- jv From ksenia at ksenia.nl Wed Aug 18 12:52:26 2004 From: ksenia at ksenia.nl (Ksenia Marasanova) Date: Wed, 18 Aug 2004 19:52:26 +0300 Subject: favorite python web development tool? In-Reply-To: <10i4nttktcvltdd@corp.supernews.com> References: <10i4nttktcvltdd@corp.supernews.com> Message-ID: > i'm fairly new to python, coming from a java servlet / velocity > template background. i'm looking for a good python web development > tool, and hope to find some suggestions here. You may find this url interesting: http://www.colorstudy.com/docs/shootout.html I use Quixote and for some projects also Quixote + HTMLTemplate (http://freespace.virgin.net/hamish.sanderson/htmltemplate.html) From nhodgson at bigpond.net.au Fri Aug 6 10:48:42 2004 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Fri, 06 Aug 2004 14:48:42 GMT Subject: @decorators References: Message-ID: daishi: > As far as I know, the proposed @decorator syntax will be the first > time that two logical lines of python with the same indentation will > not be independent of one another. Previously, when looking at: > > some_python(code) > and_some_more = stuff > > there was no need to look at the the first line in order to know what > the second line meant/did (and vice versa). Much of the time, consecutive lines with the same indentation are highly dependent with earlier lines modifying the behaviour of successor lines: global x x = 9 Neil From ajsiegel at optonline.com Sun Aug 15 20:50:12 2004 From: ajsiegel at optonline.com (Arthur) Date: Mon, 16 Aug 2004 00:50:12 GMT Subject: Anyone use VPython? References: <8f17f4bc.0408141932.46b7c405@posting.google.com> <69juh0dalfeu39fpvvvcb56ukovl0o1fsb@4ax.com> <8f17f4bc.0408151258.35874dbc@posting.google.com> Message-ID: On 15 Aug 2004 13:58:19 -0700, alikakakhel3 at hotmail.com (Ali) wrote: >Arthur wrote in message news:<69juh0dalfeu39fpvvvcb56ukovl0o1fsb at 4ax.com>... >> On 14 Aug 2004 20:32:49 -0700, alikakakhel3 at hotmail.com (Ali) wrote: >> >> >Anyone use VPython? >> >> Yes. > >ok then how yu make things move? Hmmm. Your questions are kind of general.. There are lots of different ways to get things to move. In the Hanoi demo, clicking the mouse button over a top ring and keeping it pressed while moving the mouse.. will move the ring. Most things in VPython have an attribute called "pos", representing its 3d coorinates Experiment from the IDLE prompt. IDLE 1.0.3 >>> from visual import * Visual 2004-07-22 >>> s=sphere(color=color.blue, pos=(2,2,2)) You will see a window with a blue sphere. Then: >>> s.pos=(0,2,2) The sphere's position in the window moved. Cool. Moving things in Vpython is usually a matter of having a porgram that changes things "pos", in reaction to something - a mouse click, the passage of seconds, etc. Help? Art From wweston at att.net Wed Aug 18 12:22:09 2004 From: wweston at att.net (wes weston) Date: Wed, 18 Aug 2004 16:22:09 GMT Subject: readlines() In-Reply-To: References: Message-ID: Yong Wang wrote: > Hi, > I use readlines() to read one data file. Python automatically parses the read contents > into a list of lines. When I used list[0] to print out the 1st line, it is ok. When I use > the list index 2 to print out the 2nd line , there is an error mesage. I only need one line of > input data file in the middle of the file. For example, I have data file like: > --------------------------------------------------------------------------- > Timestamp: Sat Aug 7 11:14:57 AM > Adapter Address: 00:60:08:2A:C9:5A > IP Address: 165.91.10.244 > Directory ID: 0675392c736079cfd81a55028df3cb43 > Domain Name: bdanwood.dsl.tamu.edu > DHCP/NIM Action: lease renewed > Comments: > --------------------------------------------------------------------------- > Timestamp: Sat Aug 7 11:15:56 PM > Adapter Address: 00:60:08:2A:C9:5A > IP Address: 165.91.10.244 > Directory ID: 0675392c736079cfd81a55028df3cb43 > Domain Name: bdanwood.dsl.tamu.edu > DHCP/NIM Action: lease renewed > Comments: > --------------------------------------------------------------------------- > > I have some codes: > ....... > for line in db1: > (ip, mac) = string.split(line) > print 'ip is ', ip > run = 'dhcpacct --ip=%s > tt1' > os.system(run) > getdata = open('tt1', 'r') > data = getdata.readlines() > print 'data[0] is', data[0] > print 'data[3] is', data[3] > getdata.close() > > When run the codes, I got: > data[0] is --------------------------------------------------------------------------- > > data[3] is > Traceback (innermost last): > File "com1", line 64, in ? > print 'data[3] is', data[3] > IndexError: list index out of range > > How can I fix it ? > > Thanks, > > Yong, In general, for debugging, why not use for i in range(len(data)): print 'data[',i,'] is',data[i] wes From eurleif at ecritters.biz Sat Aug 21 19:40:02 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sat, 21 Aug 2004 19:40:02 -0400 Subject: __metaclass__ and __author__ are already decorators In-Reply-To: References: <2opgsoFd7807U1@uni-berlin.de> <2opp6gFdg3e7U1@uni-berlin.de> Message-ID: <2oq4keFd90euU1@uni-berlin.de> Paul Morrow wrote: > And I don't agree that this would be assigning new 'meaning' to an old > syntax. When a programmer creates a __xxx__ class attribute, he is not > trying to create a normal 'class' attribute --- one the is inherited by > instances of the class or that holds part of the 'state' of the class. > Instead, he is trying to make a meta statement about the class (who > wrote it, what happens during instance initialization, etc.). In that > sense, the meaning associated with defining __xxx__ attributes would > stay the same. If we were talking about something like this: def foo(self): pass foo.__author__ = "Leif K-Brooks" then you would be correct. But when syntax normally used for assigning to a variable magically assigns to an attribute if the variable name starts and ends with "__", then it's an existing syntax (variable assignment) being used for something new (attribute assignment). Why should this: def foo(self): bar = 42 mean anything different from this? def foo(self): __bar__ = 42 From joshg at brainstorminternet.net Wed Aug 25 11:32:29 2004 From: joshg at brainstorminternet.net (Joshua Ginsberg) Date: Wed, 25 Aug 2004 09:32:29 -0600 Subject: Floating point weirdness Message-ID: <1093447949.29259.158.camel@localhost.localdomain> WTF, mate? >>> import sys >>> sys.version '2.3.3 (#1, May 7 2004, 10:31:40) \n[GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)]' >>> float('19.95') 19.949999999999999 >>> round(19.94999999999999999, 2) 19.949999999999999 >>> round(19.949, 1) 19.899999999999999 Why can't I just get 19.95? -jag -- Joshua Ginsberg Brainstorm Internet Network Operations From ajsiegel at optonline.com Sun Aug 22 12:08:44 2004 From: ajsiegel at optonline.com (Arthur) Date: Sun, 22 Aug 2004 16:08:44 GMT Subject: J2 proposal: keyword References: Message-ID: On Sun, 22 Aug 2004 07:38:49 -0700, "Robert Brewer" wrote: >-Candidates for keywords have fallen into two or three camps, and >emphasize different aspects of decorators: > >-Declarative: declare, predef, moddef >-Transformative: transform, wrap, modify, mutate >-Attributive/Annotative: amend, using, having >-Directive: pragma, signify >-Associative: helper, qualify, qual, meta >-Cross-cutting: imbue, endow, bestow, embellish, extend, accum, glom, >confer >-Prepositions/Adverbs: using, through, per, via, by There is only consensus as to what any of those words would mean, in context. Make happen: foo=whatever(foo) Some of us - at least one of us - find that a point with real significance. It cannot be said better than it is being said, is the point, And I think it is stretching things to an extreme to imply that the poll results reflect a concensus of the community in any direction. There is a more fundamental lack of consensus as to whether Guido should allow himself to be influenced by these kinds of polls. I do not have blind faith in Guido's instincts. I do think he is in a unique position to see the Big Picture of all the issues and forces at work. Being at the center of the storm. So in the end I might have ended up doing exactly what I have accused others of doing in other cases - reading into the @decorator syntax decision (assuming *some* syntax is a fait accompli) - finding it to be wise, for reasons perhaps beyond its intentions. Art From in.aqua.scribis at nl.invalid Fri Aug 20 15:12:15 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Fri, 20 Aug 2004 21:12:15 +0200 Subject: Fate of lambda, Functional Programming in Python... In-Reply-To: References: <412636D1.6070808@noaa.gov> Message-ID: Christopher A. Craig schreef: > Nobody is talking about removing the ability to pass functions, just > the actual "lambda" form. > > You can still build a GUI by doing > > def spam(stuff): > def eggs(parrot): > return 5+parrot > return eggs > > You just can't do > > def spam(stuff): > return lambda foo: 5+parrot What a silly idea to remove a much used core feature from a language. -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From jason at ghostdroppings.com Sat Aug 21 20:10:12 2004 From: jason at ghostdroppings.com (Jason) Date: Sat, 21 Aug 2004 20:10:12 -0400 Subject: sock.recv() in Windows Message-ID: Hi, When using the socket module in Python 2.3 for windows, I'm having problems using socket.recv(int). The function works fine on its own, but when I attempt to encapsulate the socket functions into a class method, my script just hangs with the Python DOS window open. My class method is simple: def getData(self, max_size=1024): return self.sock.recv(max_size) Why would an instance of this class cause python to hang in windows? (Yes, I know Windows sucks, but I'm looking for a slightly better resolution to the problem ;) Thanx, Jay From peter at engcorp.com Thu Aug 26 02:11:34 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 26 Aug 2004 02:11:34 -0400 Subject: Larry Wall & Cults In-Reply-To: References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: Robert wrote: > Isn't "Xah Lee" chinese for "Moron"? No, it's Esperanto (universal language) for "troll"... -Peter From martin at v.loewis.de Tue Aug 24 02:11:46 2004 From: martin at v.loewis.de (=?windows-1252?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 24 Aug 2004 08:11:46 +0200 Subject: Free software (Was: 2 GB files) In-Reply-To: <9418be08.0408231320.5fe3c40c@posting.google.com> References: <9418be08.0408221427.182a4d30@posting.google.com> <9418be08.0408221939.7003bd3c@posting.google.com> <9418be08.0408231320.5fe3c40c@posting.google.com> Message-ID: <412ADC22.8040209@v.loewis.de> Elbert Lev wrote: > Java and .NET are also free. > > Java run-time and development are free. > .NET run-time is free. While this is OT for the original thread, I can't really let this stand. It is true that Java and .NET are free of charge (although only for some uses), they are, unlike Python, not free software. You don't get the source code for them, and you are not allowed to modify it, and to redistribute it. See http://www.fsf.org/philosophy/free-sw.html Regards, Martin From just at xs4all.nl Mon Aug 30 02:32:43 2004 From: just at xs4all.nl (Just) Date: Mon, 30 Aug 2004 08:32:43 +0200 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <1LMXc.67190$UTP.37420@twister01.bloor.is.net.cable.rogers.com> <1gj7a9r.g7ec5a1g89rj0N%aleaxit@yahoo.com> Message-ID: In article , Jorge Godoy wrote: > Just writes: > > > But since .pyc's are always generated in the same directory as the .py > > files, where else would you expect them to be generated? > > At the directory where the zip archive is stored. How does that follow? The zip archive _itself_ is the "directory" where the .py files are, why would Python suddenly choose to write .pyc files one level up? And what about packages? It simply doesn't work that way. Just From beliavsky at aol.com Fri Aug 20 14:47:18 2004 From: beliavsky at aol.com (beliavsky at aol.com) Date: 20 Aug 2004 11:47:18 -0700 Subject: age of Python programmers References: Message-ID: <3064b51d.0408201047.40a9e9d8@posting.google.com> "Lucas Raab" wrote in message news:... > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... Related question -- at what age can Python be taught to a bright, motivated child? From spam at mouse-potato.com Sat Aug 28 02:41:30 2004 From: spam at mouse-potato.com (Pascal Bourguignon) Date: 28 Aug 2004 08:41:30 +0200 Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4PGdnfsOfdDPi63cRVn-tA@speakeasy.net> Message-ID: <878ybzsr1h.fsf@thalassa.informatimago.com> rpw3 at rpw3.org (Rob Warnock) writes: > Pascal Bourguignon wrote: > +--------------- > | $ telnet xahlee.org 80; > | Trying 208.186.130.4... > | Connected to xahlee.org. > | Escape character is '^]'. > | GET / HTTP/1.1 > | > | HTTP/1.1 400 Bad Request > | Date: Fri, 27 Aug 2004 01:35:52 GMT > | Server: Apache/2.0.50 (Fedora) > | ^^^^^^^^^^^^^^^^^^^^^^ > +--------------- > > So are you complaining about the fact that his hosting provider > preloaded RedHat Fedora with Apache 2.0 for him? [A lot of them do, > these days, 'cuz it's much cheaper than preloading RedHat Enterprise.] > > Or are you complaining about that perfectly correct error message > which pointed out that you omitted a required HTTP/1.1 header? ;-} ;-} Obviously, I'm complaining the contradiction between his opinion about unix about what I've underlined. And I take care to select my hosting providers not using MS-Windows (since I'm critical about MS-Windows). -- __Pascal Bourguignon__ http://www.informatimago.com/ Our enemies are innovative and resourceful, and so are we. They never stop thinking about new ways to harm our country and our people, and neither do we. From pinard at iro.umontreal.ca Tue Aug 17 20:10:56 2004 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Tue, 17 Aug 2004 20:10:56 -0400 Subject: can tarfile maintain directory structure? In-Reply-To: References: Message-ID: <20040818001056.GA20880@alcyon.progiciels-bpi.ca> [Jay Donnell] > Simply doing os.system('tar -czvf ' + fileName +'.tar.gz ' + > directory) works great on linux, but I need this script to work on > windows as well :( GNU tar, and surely others, have been ported to Windows. Check within the DJGPP and Cygwin projects. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From rkoenig at ginko.de Sat Aug 28 18:49:22 2004 From: rkoenig at ginko.de (Reinhard Koenig) Date: Sat, 28 Aug 2004 22:49:22 GMT Subject: How to avoid DOS name mangling under Windows 2000? Message-ID: <41310e2b$1@news.ginko.net> I'm working with Windows 2000 and Windows 2000 Server in a cmd window. When I invoke a python script without 'python' prefixed on the command line whose name does not obey the DOS 8.3 syntax the name is mangled under Windows 2000 but not under Windows 2000 Server in an error trace. Why? How can I receive an unmangled name under Windows 2000 without using "python ? I need it for a later import statement. Thanks Reinhard From firemoth at gmail.com Sun Aug 15 02:03:26 2004 From: firemoth at gmail.com (Timothy Fitz) Date: 14 Aug 2004 23:03:26 -0700 Subject: Generators versus Coroutines References: <972ec5bd.0408141032.385fe115@posting.google.com> Message-ID: <972ec5bd.0408142203.5a8d5d04@posting.google.com> Tim Peters wrote in message > > > Coroutines, in contrast, are like split functions where > > side effects are often as important or more important than return > > values. I am currently writing a real time strategy game where I have > > visual effects and use generators as coroutines which yield after > > processing a single frame of the effect. I can easily make an object > > rotate indefinitely with a scant four or five lines of code, all of > > which is in one place. So knowing that the difference between a > > generator and a coroutine is minor, I come (in a very roundabout way) > > to my issue. Why can I use "return" without an expression and it > > implicitly returns None > > If you explicitly intend to return None as a value, it's terrible > practice to spell that as > > return > > instead of as > > return None > > It's equally terrible practice to rely on that "falling off the end" > of a Python function returns None, when you expliclty intend to return > a None value. It was not that I want to explicitly return None, I specifically don't want to return anything, it's just that None happens to be the default for return so it seems like a convention to adhere to. > If you want a concept of yielding without delivering a value, that's > simply not a use case Python's generators intended to address. If you > wish, you can adhere to a *convention* that "yield None" (or "yield > False", or "yield 42", ...) means "I'm not really delivering a value". It's not a use case, but why not? And should it be? I know generators are semi-coroutines, but the fact is that their useage outside of value generation is just as useful and should be adressed as such. I do not see how accepting a plain yield would break anything at all. I have read the PEP, twice, and I don't see why it -wasn't- addressed. Seems to me to be a fairly large arbitrary decision. From luismg at gmx.net Tue Aug 10 23:29:12 2004 From: luismg at gmx.net (Neuruss) Date: 10 Aug 2004 20:29:12 -0700 Subject: IronPython-0.6 is now available! References: <278de0e.0407281353.27b6a457@posting.google.com> <278de0e.0408100515.5fd3740c@posting.google.com> Message-ID: <278de0e.0408101929.cc3d8c8@posting.google.com> > In any case, it is standard to do time-consuming numerical computation in > Python with the quasi-standard numerical extensions. Unless and until the > these are ported to .NET, such programs will not run. Even when they do, > there is no reason to think that they will be significantly faster. Well, I don't want to play the advocate of .NET, but I think that we have to take it with a very practical and pragmatic attitude. Today, if you want to code something very computational intensive, you have to resort to C for creating an extension. Many programers can do it. I can't, because I don't know C and really, I'm not interested in it. However, in a .NET environment, you can code your apps in IronPython (or whatever its name in the future) and when you need extra performance, you can code this parts in C#. Believe me, I'm just a newbie, but I can say that translating from Python to C# (if you already have the python prototype) is a matter of minutes. No extensions, no hassle...everything compatible and smooth. Sounds good, don't you think? From mwh at python.net Wed Aug 25 07:24:41 2004 From: mwh at python.net (Michael Hudson) Date: Wed, 25 Aug 2004 11:24:41 GMT Subject: iterators: class vs generator References: Message-ID: "Clark C. Evans" writes: > There is an interesting difference between how exceptions are handled > between iterators constructed from a class, and iterators constructed > from a generator. The following are "mostly equivalent": [...] > However, when exceptions are involved, behavior can be different: (It would have been nice if you'd explained what the differences were in your post, and given that you'd didn't if you'd made sure the examples were correct -- got a NameError for iterable...) Here's a better illustration: >>> def iterable_via_generator(): ... yield "one" ... raise Exception() ... yield "two" ... >>> i = iterable_via_generator() >>> i.next() 'one' >>> i.next() Traceback (most recent call last): File "", line 1, in ? File "", line 3, in iterable_via_generator Exception >>> i.next() Traceback (most recent call last): File "", line 1, in ? StopIteration I agree this is surprising. I am vaguely aware of some effort being put in to make generators "stick", i.e. this doesn't surprise me so much: >>> def g(): ... yield 1 ... return ... yield 2 ... >>> i = g() >>> i.next() 1 >>> i.next() Traceback (most recent call last): File "", line 1, in ? StopIteration >>> i.next() Traceback (most recent call last): File "", line 1, in ? StopIteration I'd guess the behaviour you've noticed is an unintended consequence of this. I'd also be willing to be persuaded that it's a bug, although others might disagree, dunno. File an issue, anyway? Cheers, mwh -- 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 davidf at sjsoft.com Fri Aug 20 10:22:59 2004 From: davidf at sjsoft.com (David Fraser) Date: Fri, 20 Aug 2004 16:22:59 +0200 Subject: Decorator keyword options In-Reply-To: <2CnVc.4606$Jn5.4384@fe1.texas.rr.com> References: <7knVc.4599$Jn5.3074@fe1.texas.rr.com> <2CnVc.4606$Jn5.4384@fe1.texas.rr.com> Message-ID: Paul McGuire wrote: > "David Fraser" wrote in message > news:cg509s$40m$1 at ctb-nnrp2.saix.net... > >>Good plan. If anyone likes "wrap" they could add it to the Wiki with >>something akin to the description of transform >> >>David > > David - > > I encourage you to do this for yourself, if you have time. I think this is > exactly the kind of thing Wiki was intended for - we are all empowered to > include items on that list. > > (If you do not see the "EditPage" option at the bottom of the page, select > the "Preferences" item on the left-side menu and enter your info. Once this > is done, you should be able to edit pages.) > OK you were right I was avoiding registering :-) ... done now David From peter at engcorp.com Mon Aug 16 00:45:22 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 00:45:22 -0400 Subject: Python indentation deters newbies? In-Reply-To: References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: Keith P. Boruff wrote: > beliavsky at aol.com wrote: > >> One of the most commmon reasons programmers cite for not trying Python >> is that indentation determines the program flow -- they think its >> weird. I think programmers who actually try Python adapt quickly and >> do not find the indentation rules to be a problem. > > Honestly, I'm still not too crazy about the indentation requirements of > the language myself, coming from a background of using all free form > languages. Did you really not indent your code in those languages consisntly anyway? -Peter From duncan.booth at invalid.invalid Tue Aug 10 08:38:22 2004 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 10 Aug 2004 12:38:22 GMT Subject: Multiple inheritance with a common base class References: <1092137872.2624.16.camel@dicaprio.akademie1.de> Message-ID: Markus Bertheau wrote in news:mailman.1439.1092140352.5135.python-list at python.org: > It outputs: > > CommonBase.no: 0 > CommonBase.no: 0 > > If there was only one copy of the common base class, I'd have expected > an output similar to > > CommonBase.no: 0 > CommonBase.no: 3 > > This renders multiple inheritance pretty useless for me. > > Can someone clear this all up and tell me how multiple inheritance is > supposed to work in python? Well of course it outputs 0 twice. That's because after LeafA initialised CommonBase, and set its value to 3 you then reinitialised it from LeafB and set the value back to 0. Do this instead: class CommonBase: def __init__(self): self.no = 0 def setNo(self, no): self.no = no class LeafA(CommonBase): def __init__(self): super(LeafA, self).__init__() print("LeafA:CommonBase.no: %i" % self.no) CommonBase.setNo(self, 3) class LeafB(CommonBase): def __init__(self): super(LeafB, self).__init__() print("LeafB:CommonBase.no: %i" % self.no) CommonBase.setNo(self, 4) class Multi(LeafA, LeafB): def __init__(self): super(Multi, self).__init__() m = Multi() Which gives you the output: LeafB:CommonBase.no: 0 LeafA:CommonBase.no: 4 Using super will ensure that you get a reliable chain of method calls. In this case it means that Multi.__init__ calls LeafA.__init__ which calls LeafB.__init__ which then calls CommonBase.__init__. Note that LeafA propogates the call to LeafB even though LeafA has no knowledge of the existence of LeafB. From peter at engcorp.com Wed Aug 18 21:04:14 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 18 Aug 2004 21:04:14 -0400 Subject: age of Python programmers In-Reply-To: References: <2ohpksF94tajU3@uni-berlin.de> Message-ID: Phil Frost wrote: > I never really thought programming was unpopular among young people, but > now that I think about it, the only person I've met in real life that > was a young programmer lives 1500km away, and we met on the internet, of > course. Most of the people with whom I went to grade school and high school didn't know any programmers either. (And I was a programmer at the time.) There's a reason the stereotypical geek is considered antisocial... -Peter From aleaxit at yahoo.com Sat Aug 28 15:03:58 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 28 Aug 2004 21:03:58 +0200 Subject: Generator expressions v/s list comprehensions References: Message-ID: <1gj8y77.6qshr41q531veN%aleaxit@yahoo.com> Mahesh Padmanabhan wrote: > Hi, > > When list comprehension was added to the language, I had a lot of > trouble understanding it but now that I am familiar with it, I am not > sure how I programmed in Python without it. Oh good. > > Now I see that generator expressions have been added to the language > with 2.4 and I question the need for it. I know that it allows for lazy > evaluation which speeds things up for larger lists but why was it > necessary to add it instead of improving list comprehension? > > Was there some sort of limitation that prevented list comprehension from > taking over the functionality that generator expressions provide? Sure, and that limitation is: list comprehensions return lists. This one "limitation" (together with Python's applicative order evaluation, and you couldn't change THAT without breaking the whole caboodle of existing programs!) implies everything else. > > I have always liked the fact that Python has limited capabilities for > having more than one way to do it and it seem to me that generator > expressions break that philosophy. It is similar to how you have to use > range or xrange depending on how large the range is. > > Can someone please explain the reasoning behind it? Generator comprehensions are wonderful and there is no way Python list comprehensions can provide the same features, since lists need to be lists. Sure, list(e(x) for x in foo) IS just the same thing as [e(x) for x in foo]. We'll remove the redundancy in 3.0 -- not earlier because it will break backwards compatibility. The only sensible way I can see right now for 3.0 to remove this redundancy is by removing list comprehensions and leaving only generator comprehensions, btw. Alex From joshg at brainstorminternet.net Tue Aug 24 18:30:13 2004 From: joshg at brainstorminternet.net (Joshua Ginsberg) Date: Tue, 24 Aug 2004 16:30:13 -0600 Subject: Inline Conditionals? In-Reply-To: References: <1093385974.29259.146.camel@localhost.localdomain> Message-ID: <1093386613.29259.151.camel@localhost.localdomain> Yeah... sorry with the bad example returning true or false... Try this example :-D -- def foo(x): return foo == 'bar' ? 'w00t' : 'l33t' -jag On Tue, 2004-08-24 at 16:28, Chris Cioffi wrote: > Um, try: > > def isNegative(x): > return x < 0 > > But for the general case, no. (Yes, there are many very creative > "solutions" but none are truly general.) > > Chris > > On Tue, 24 Aug 2004 16:19:34 -0600, Joshua Ginsberg > wrote: > > Is there any plan to include inline conditionals in Python? For example: > > > > def isNegative(x): > > return x < 0 ? True : False > > > > Thanks! > > > > -jag > > > > -- > > Joshua Ginsberg > > Brainstorm Internet Network Operations > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > -- Joshua Ginsberg Brainstorm Internet Network Operations From raims at dot.com Wed Aug 18 18:53:50 2004 From: raims at dot.com (Lawrence Oluyede) Date: Thu, 19 Aug 2004 00:53:50 +0200 Subject: apache 2 & python References: Message-ID: <1rnpy3lebwvfm$.1vyvvqybr6xgc$.dlg@40tude.net> In data Thu, 19 Aug 2004 00:42:26 +0200, Krzysztof Drozd ha scritto: > how to configure apache 2 to work with python or mod_python? Look at mod_python's howto guide: http://modpython.org/live/current/doc-html/installation.html -- Lawrence (l dot oluyede at virgilio dot it) "If the implementation is hard to explain, it's a bad idea." from The Zen of Python by Tim Peters From adonisv at DELETETHISTEXTearthlink.net Tue Aug 17 21:05:59 2004 From: adonisv at DELETETHISTEXTearthlink.net (Adonis) Date: Wed, 18 Aug 2004 01:05:59 GMT Subject: can tarfile maintain directory structure? References: Message-ID: "Jay Donnell" wrote in message news:a6fdfd6b.0408171508.65d670d0 at posting.google.com... > Is there a way to use the tarfile module to recursively compress the > contents of a directory and maintain the directory structure in the > tar archive? > > Simply doing os.system('tar -czvf ' + fileName +'.tar.gz ' + > directory) > works great on linux, but I need this script to work on windows as > well :( Starting from Python 2.3 there is a tarfile module in the stdlib http://docs.python.org/lib/module-tarfile.html Adonis From martin at v.loewis.de Sat Aug 7 05:26:07 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 07 Aug 2004 11:26:07 +0200 Subject: MSI Installer issues In-Reply-To: <1f7befae04080623276089908e@mail.gmail.com> References: <411231C8.3020308@interlink.com.au> <411241F5.3080602@v.loewis.de> <1f7befae040805103911610582@mail.gmail.com> <411274C0.4070300@v.loewis.de> <1f7befae04080623276089908e@mail.gmail.com> Message-ID: <4114A02F.7060906@v.loewis.de> Tim Peters wrote: >>Yes. I don't know what to do about this: the screen sets ALLUSERS=1, >>then performs FindRelatedProducts to find the old installation. If the >>old installation was per-machine, we only find it if we commit to making >>the new installation also per-machine. > > > Except that in this case, I'm pretty sure my 2.4a1 installation was > also "only for me". I could be wrong about that. Indeed. Upgrading from a per-user installation is easy, as the whole process starts with the assumption that it is going to be per-user. Only per-machine were previously not upgradable. > I believe I later saw a checkin that intended to fix this, and, if so, > that's cool too. I hereby nominate you as MSI-builder For Life > . Yes, and thanks :-) Part of my recent talking goes along with the hope that others become interested enough in MSI as a technology to be able to contribute, though. While I have your attention: you have commented that the installer logo needs attribution, during the installation process. Is this still the case, and what is the text I should use? Any other attribution that needs to be made? A colleague has commented that logo is too low-res, is ugly, and does not feature reptiles. Should we look for an update to the logo? Regards, Martin From anthonybaxter at gmail.com Fri Aug 6 12:31:57 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 7 Aug 2004 02:31:57 +1000 Subject: Buy a vote! (was Re: Poll - Vote here for "list-after-def" (was Decorator syntax)) In-Reply-To: References: Message-ID: On Fri, 06 Aug 2004 10:09:56 -0400, Peter Hansen wrote: > I suggest that everyone with an opinion on the matter visit the > page at http://www.python.org/psf/donations.html and make a donation, > preferably sized in relation to the strength of your opinion. (*) +1 > (*) I've just done so, since it seems like a more productive thing than > endless argument over the same issues. And this way at least there will > be money to pay Anthony to do the right thing. ;-) Hey, Guido's the one you need to be paying off. I'm just a grunt. From tim.leslie at gmail.com Mon Aug 23 01:01:02 2004 From: tim.leslie at gmail.com (Tim Leslie) Date: Mon, 23 Aug 2004 15:01:02 +1000 Subject: Logical lines of code counter In-Reply-To: <2ot78fFe1mneU1@uni-berlin.de> References: <2ot090Fe5442U1@uni-berlin.de> <2ot78fFe1mneU1@uni-berlin.de> Message-ID: On Sun, 22 Aug 2004 23:43:25 -0400, Leif K-Brooks wrote: > Tim Leslie wrote: > > > > http://www.logilab.org/projects/pylint > > Neat-looking tool, but not really usable for me. It counts physical > lines, not logical lines; it doesn't seem to have an option to > recursively scan all sub-directories and files in a directory; and it > refuses to process a file if some of the modules code wants to import > aren't importable, which is the case with mod_python code. > Ah ok, I guess that's quite a drawback. I've been keeping my eye out recently for software development tools like pylint/pychecker, so if you can find a tool which can provide better line count type statistics I'd be interested to hear about it. Cheers, Tim > > -- > http://mail.python.org/mailman/listinfo/python-list > From martin at v.loewis.de Thu Aug 5 13:56:16 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 05 Aug 2004 19:56:16 +0200 Subject: [Python-Dev] RELEASED Python 2.4, alpha 2 In-Reply-To: <1f7befae040805103911610582@mail.gmail.com> References: <411231C8.3020308@interlink.com.au> <411241F5.3080602@v.loewis.de> <1f7befae040805103911610582@mail.gmail.com> Message-ID: <411274C0.4070300@v.loewis.de> Tim Peters wrote: > I tried that, and it seemed to work well, although it took a while. Yes. I should probably speed it up by changing the UI sequence number of RemoveExistingApplications from 1510 to 1450. In case you wonder what this means: Action 1500 is InstallInitialize; anything from then on is under transaction control. This means that installer will roll back the uninstall in case the subsequent install fails. This is expensive, as it first moves all old files out of the place, then puts the new ones in, then deletes the old ones. At 1450, the files would be deleted immediately (I believe), at the cost of not being able to undo the deinstallation if the installation later fails (e.g. by user Cancel). > One glitch: I'm pretty sure I selected "install only for me" in the > first screen. I wanted to go back to check, but it doesn't seem > possible to go back to the first screen. Yes. I don't know what to do about this: the screen sets ALLUSERS=1, then performs FindRelatedProducts to find the old installation. If the old installation was per-machine, we only find it if we commit to making the new installation also per-machine. That decision cannot be taken back; the user would have to cancel and start over. > Anyway, the Python DLL ended > up in a system directory, and that's "the glitch". I expected/wanted > it to end up in my Python directory. Ok. I will see whether I can reproduce that. Regards, Martin From davidf at sjsoft.com Fri Aug 6 05:21:29 2004 From: davidf at sjsoft.com (David Fraser) Date: Fri, 06 Aug 2004 11:21:29 +0200 Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) In-Reply-To: References: <10h24oace15n97a@news.supernews.com> Message-ID: Ronald Oussoren wrote: > > On 4-aug-04, at 21:35, Nick Vargish wrote: > >> Ville Vainio writes: >> >>> This syntax is out there with backticks and print>>. >> >> >> I agree. >> >> I just don't know where else to voice my opinion on this matter, but I >> absolutely hate the new decorator syntax. Sorry, I just had to get >> that off my chest. > > > Why do you dislike it? > > Ronald > I think for the same reason as me! I dislike it because it introduces a new punctuation character as an operator for a relatively esoteric task. At least using a keyword instead of @ would be a good idea. Readability counts. David From roman.yakovenko at actimize.com Tue Aug 17 01:06:18 2004 From: roman.yakovenko at actimize.com (Roman Yakovenko) Date: Tue, 17 Aug 2004 08:06:18 +0300 Subject: python packages cross references Message-ID: <2D89F6C4A80FA547BF5D5B8FDDD04523060CBB@exchange.adrembi.com> Hi. I need help( or solution :-) ). Problem: my project has 3 packages prj +------A +------B +------Utils The question is: what is the right way to use functionality from Utils in A and B packages ? I know that after importing package I know it's location, but it doesn't help me in any module within package A or B. I can add full path to prj to sys.path but it seems to be the wrong way. May be I missed something? Thanks. Roman From wilberforce at gmail.com Wed Aug 25 01:05:39 2004 From: wilberforce at gmail.com (xtian) Date: 24 Aug 2004 22:05:39 -0700 Subject: Late binding eval()? Message-ID: Kevin Smith wrote: > I want to evaluate an expression using eval(), but I only want to supply > the variable values "on demand." For example, let's say that I want to > evaluate 'x+y'. Normally, I would create a dictionary containing 'x' > and 'y' with their corresponding values and pass it in as the globals or > locals. However, in my application, I'm getting an arbitrary expression > from the user. I thought that I could just create a dictionary-like > object and override __getitem__ to look up values in a database as they > were called for, but that didn't work. > This will work in 2.4, see: http://www.python.org/2.4/highlights.html "eval() now accepts any form of object that acts as a mapping as its argument for locals, rather than only accepting a dictionary. There's all sorts of new and shiny evil possible thanks to this little change." Sweet. From leor at bdsoft.com Sun Aug 29 23:30:42 2004 From: leor at bdsoft.com (Leor Zolman) Date: Mon, 30 Aug 2004 03:30:42 GMT Subject: simple compiled languages? References: <7xzn4fu188.fsf_-_@ruckus.brouhaha.com> <_1bYc.855$2s.374@twister.nyroc.rr.com> <7xbrguvfn6.fsf@ruckus.brouhaha.com> Message-ID: <5g75j051nu15gpmn67qkr22ufbkl328cg8@4ax.com> On Mon, 30 Aug 2004 02:03:10 GMT, "Paul McGuire" wrote: >"Leor Zolman" wrote in message >news:psv4j0p9inej073bta5m9r6ug4ko6iiojk at 4ax.com... > >> ...she then said she wanted to >> learn Python. I gave her the book and asked her to teach it to *me* after >> she figured it out ;-) >> -leor > >... so what did she say the next day? :) > I think right now she's back to reading her anime books, but when the time comes we may just have to learn Python together... ;-) -leor >-- Paul > From ajm at flonidan.dk Fri Aug 6 04:45:58 2004 From: ajm at flonidan.dk (Anders J. Munch) Date: Fri, 6 Aug 2004 10:45:58 +0200 Subject: Proposal: require 7-bit source str's References: <4112AC7B.1060508@v.loewis.de> Message-ID: <41134546$0$257$edfadb0f@dread14.news.tele.dk> "Hallvard B Furuseth" wrote: > Martin v. L?wis wrote: > > > Or, better yet, > > external checkers like pychecker could check for that. > > Well, I don't think that's better, but if it's rejected for Python > that'll be my next stop. I'm getting fed up with UnicodeDecodeError exceptions myself, so I've added a pychecker feature request for this on sourceforge. - Anders From mwh at python.net Fri Aug 6 07:29:32 2004 From: mwh at python.net (Michael Hudson) Date: Fri, 6 Aug 2004 11:29:32 GMT Subject: tkinter idle handler References: Message-ID: John Hunter writes: > Does tkinter have an idle handler analogous to pygtk's gtk.idle_add? I think it's after_idle, but that's very much a guess... > Normally I could find this myself on google, but googling for tkinter > idle turns up a few false positives . :-) Cheers, mwh -- I have a cat, so I know that when she digs her very sharp claws into my chest or stomach it's really a sign of affection, but I don't see any reason for programming languages to show affection with pain. -- Erik Naggum, comp.lang.lisp From rho at see.signature.invalid Fri Aug 20 10:50:53 2004 From: rho at see.signature.invalid (Nigel Rowe) Date: Sat, 21 Aug 2004 00:50:53 +1000 Subject: Alternative decorator syntax decision References: Message-ID: <10ic3udgs27q072@news.supernews.com> J2 J2 J1 -- Nigel Rowe A pox upon the spammers that make me write my address like.. rho (snail) swiftdsl (stop) com (stop) au From squirrel at WPI.EDU Tue Aug 3 16:31:28 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 3 Aug 2004 16:31:28 -0400 Subject: simple Thread question In-Reply-To: References: Message-ID: On Tue, 3 Aug 2004, Peter Hansen wrote: > Obviously this just depends on differing ideas of what it means to be > "friendly" to threads, but I find Python to be the most reliable and > easiest to use environment for multi-threaded applications that I've > ever used. Poor choice of words on my part... I didn't mean API wise (though I'm not a huge fan of threading), but rather implementation-wise (having the GIL and all). From simoninusa2001 at yahoo.co.uk Mon Aug 9 19:06:01 2004 From: simoninusa2001 at yahoo.co.uk (simo) Date: 9 Aug 2004 16:06:01 -0700 Subject: VB-like GUI designer? References: <278de0e.0408090935.6d758a5d@posting.google.com> Message-ID: <30260531.0408091506.294cec8a@posting.google.com> Fred wrote: > - And last, since we're on the subject of tools available to switch > from VB... is there a good compiler so as to distribute a GUI Python > built on either wxW or QT? > I've seen a bunch of tools like py2exe, freeze, pyPack, Psyco, > McMillan (RIP?), and distutils, so am a bit lost. Which would you > recommend? Ah, you may be stuck there! I noticed you mentionned customers, so presume you want this to be closed source? Well that doesn't really exist for Python, you have to distribute the .pyc or .pyo files, which are compiled to bytecode, but easy-ish to disassemble to source. py2exe is the best program for [pseudo] compiling your Python app, and bundling all the necessary DLLs etc. together on Windows. I've used py2exe with PyQt/wxPython sucessfully. It's what BitTorrent uses (I'm sure you've heard of the wxPython P2P app?) McMillan Installer is not as good as py2exe on Windows IMHO, but also works on Linux. Same goes for cx_Freeze. InnoSetup is an excellant installation package program that can take the output of py2exe (or whatever) and make a Setup.exe, it's not MSI mind you, but is free. IMHO a *machine code* compiler is what is really holding pack Python adoption on the desktop by a lot of companies, certainly the one I work for cannot take the risk of having it's software decompiled to source! Of course, for server-side stuff it's fine. You could wait for IronPython (or MS Visual Python.NET as it will probably become!) if you want a standalone binary..... From anthonybaxter at gmail.com Fri Aug 20 04:42:20 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 20 Aug 2004 18:42:20 +1000 Subject: Alternative decorator syntax decision In-Reply-To: <7x3c2iw9ig.fsf@ruckus.brouhaha.com> References: <7x3c2iw9ig.fsf@ruckus.brouhaha.com> Message-ID: On 20 Aug 2004 00:31:35 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > My conclusion: Python 2.4 should not have new decorator syntax. Stay > with the existing stuff, for now. This is not an option that is going to happen. The decorators thread has been discussed on python-dev for 2 1/2 years. The case for including them has been decided. The original decorators (classmethod, staticmethod) were introduced in Python 2.2, released late 2001. How long do you think we should wait? > Discussion and exploration should continue and the question should be > revisited for 2.5. For 2.4, extend the current kludgy (decorators > separated from the function) mechanism if needed to provide necessary > functionality, but deprecate any new such feature as soon as it's > introduced, with the explanation that it's exploratory. This is not the way Python works. "experimental" stuff doesn't stay experimental once the first beta release is out. I see no reason to change this - it increases the costs dramatically for companies who are using Python if they have to rewrite their code every second release. From zathras at thwackety.com Sat Aug 14 19:04:57 2004 From: zathras at thwackety.com (Michael Sparks) Date: Sun, 15 Aug 2004 00:04:57 +0100 (BST) Subject: Generators versus Coroutines In-Reply-To: Message-ID: On Sat, 14 Aug 2004, Nick Patavalis wrote: > > I may be mistaken, as it has been some time since I've last dealt with > coroutines, but aren't you supposed to be able to do this with real > coroutines? [example] > And when baz() yields, you're thrown back to the point where c.run() > was called. How is this possible with generators? I think it depends on which definition of "real" co-routines you've heard. Hence my question. Thanks for the answer :) Michael. From ajsiegel at optonline.com Fri Aug 6 20:27:34 2004 From: ajsiegel at optonline.com (Arthur) Date: Sat, 07 Aug 2004 00:27:34 GMT Subject: compromise? keywords for static/class, move decorators to top of function References: Message-ID: <0s68h093r0dnu53veqgor1u0blob0mp81h@4ax.com> On Fri, 6 Aug 2004 13:15:52 -0500, Michael Ekstrand wrote: >On Friday 06 August 2004 12:54, Doug Holton wrote: >> I propose (and others have) that built-in features have keyword >> support, like static and class methods. Also, I believe it is more >> readable if decorators, especially longer ones, are moved to the top >> of the function body, just like docstrings, instead of coming before >> the function is even declared. Whether you use @ or [] is still >> open. >> >> def classmethod getratio (arg1, arg2): >> @accepts(int,int) >> @returns(float) >> ... > >Ooh... I like, I like... > >This seems to be the most reasonable, readable proposition I've seen so >far. And I'd favor @ for this - it makes it clear that this is >"something different". It seems to me that Python is at its best when the naive approach, and the schooled approach, coalesce. I can only speak for the naive approach. And - within the context of Python as it is -the possiblity of requiring the placement of essential information related to defining a method amd its behavior somewhere outside the method's body would never occur to me. Doesn't readibility require that you have the ability to move in a direction down the page, and, if so, why am I getting information about a method prior to the existence of the method, before a proper introduction has been made, i.e. before I even know its name. In short, I would agree with both points, built-in support to disambiguate certain common cases from the case of something truly meta-like and implementation specific going down, and the balance in the method body. Just repeating a thought - but it seems unnatural to be introduced to lots of other information about something, before the normal forrmalities have been attended to. Name please. Art From heikowu at ceosg.de Thu Aug 5 12:35:42 2004 From: heikowu at ceosg.de (Heiko Wundram) Date: Thu, 5 Aug 2004 18:35:42 +0200 Subject: RELEASED Python 2.4, alpha 2 In-Reply-To: <2-SdnZCwNs1SwI_cRVn-uQ@powergate.ca> References: <411231C8.3020308@interlink.com.au> <2-SdnZCwNs1SwI_cRVn-uQ@powergate.ca> Message-ID: <200408051835.42558.heikowu@ceosg.de> As all people here seem to be bashing on the new syntax, I thought I might throw in a little different oppinion... At least for my eye, decorators look fine the way they are in 2.4a2. Am Donnerstag, 5. August 2004 18:18 schrieb Peter Hansen: > Yes, of course after using them for a while they will become more > readable, but there are people who have learned to speak Klingon as > well -- and that doesn't change the fact that Klingon is deliberately > very difficult to learn and awkward. I don't think comparing the @ syntax to Klingon is fair to the proposed syntax for decorators. Just think of the following: class someobject(object): @synchronized @classmethod def x(cls): pass If I were to translate this to english, I could read it as follows (note the order): Define a _class someobject_ which has a _synchronized_ _classmethod_ x. The @ signs don't disturb my eye, they only make it clear that this method is special. All other proposed syntaxes don't have this "shows up right away" feeling. I know there are problems with formatting tools (python-mode finds the syntax as stated difficult to grasp at the moment, listing functions doesn't work properly anymore), but I don't think a language is made by it's tools, but the tools are made for the language. And so, if the language evolves, it's only fair that the tools need to evolve too... Anyway, I'm +1 for keeping the syntax as is. It's fine for me. Heiko. From ludo at asiatica.org Sat Aug 28 20:01:35 2004 From: ludo at asiatica.org (Ludovico Magnocavallo) Date: Sun, 29 Aug 2004 02:01:35 +0200 Subject: Mysql in Python? In-Reply-To: References: Message-ID: <2pckmvFjlfvmU1@uni-berlin.de> Simon John wrote: > I got MySQLdb working with MySQL4, it's pretty similar to the PHP > implementation, although error handling isn't great (nor is > documentation!) What are you finding "not great" in MySQLdb's error handling? It implements the exceptions defined in the DB-API, which I find way better than PHP's mysql_errno() and friends: try: cursor.execute(some_statement) except MySQLdb.IntegrityError, e: # handle a specific error condition except MySQLdb.Error, e: # handle a generic error condition except MySQLdb.Warning, e: # handle warnings, if the cursor you're using raises them What can be simpler than that? Or do you prefer PHP's way, which gives you no direct, portable way of knowing what kind of error was returned by the DB: $result = mysql_query($statement, $connection); if (!$result) { $error = mysql_error(); $errno = mysql_errno(); // $error and $errno are mysql-specific } Ludo From adurdin at gmail.com Thu Aug 26 21:32:12 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Fri, 27 Aug 2004 11:32:12 +1000 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> Message-ID: <59e9fd3a04082618327b772ffd@mail.gmail.com> On Thu, 26 Aug 2004 20:54:22 -0400, Paul Morrow wrote: > > Sure the interpreter uses __getitem__, but you use it too, right? I > mean, you don't need the interpreter to tell you whether instances of > the following class can act like a dictionary, do you? > > class Foo: > def __getitem__(self, x): pass > > No you don't. Nor do you need to pretend that you're the interpreter, > and simulate a call to an instance of Foo. That's because the mere > presence of def __getitem__ tells you what you need to know. In this > way, __getitem__ *does* serve as a declaration (of dictionary semantics) > [*] to you and anyone reading your code. That's because the dictionary interface/protocol requires a __getitem__ method; there's no magical/technical reason why it should be called __getitem__ rather than, say, dict_get_item. As an example, the iterator protocol requires two methods: __iter__() and next() -- the second doesn't have the double underscores, yet still allows you to do: class Foo: def __iter__(self): return self def next(self): return 42 for v in Foo(): print v (yes, that's an infinite loop, but that's irrelevant). All the "magic" __X__ methods are just those methods required by certain built-in interfaces/protocols. And there's syntactic sugar to make them convenient. They don't affect the creation of the class at all, as you can (if necessary) add them in after the fact: >>> class Foo: ... pass ... >>> for i in Foo(): ... pass ... Traceback (most recent call last): File "", line 1, in ? TypeError: iteration over non-sequence >>> def bar(self): ... return self ... >>> def baz(self): ... raise StopIteration() ... >>> Foo.__iter__ = bar >>> Foo.next = baz >>> for i in Foo(): ... pass ... >>> From oziko at fusiondementes.com Tue Aug 17 11:34:18 2004 From: oziko at fusiondementes.com (oziko) Date: Tue, 17 Aug 2004 10:34:18 -0500 Subject: 'ascii' codec can't encode character u'\xf3' In-Reply-To: <20040817061745.GA4259@barbucha.martin.net> References: <4120F820.4000703@fusiondementes.com> <20040817061745.GA4259@barbucha.martin.net> Message-ID: <4122257A.4050707@fusiondementes.com> I solve the problem using print str.encode('iso-8859-1') Now I can print the tags with no aparent problem. But now whe I tried to insert that value into a PostgreSQL data base I get the same error. I create the PostgreSQL database with default Unicode with createdb -E UNICODE oggtest The data T am putting into de database si in the u'Perfeccion' format so I understand it is UNICODE, but I get the same error: Traceback (most recent call last): File "./ogg2sql.py", line 82, in ? db_cursor.execute(do) File "/usr/lib/python2.3/site-packages/pyPgSQL/PgSQL.py", line 3035, in execute _qstr = self.__unicodeConvert(_qstr) File "/usr/lib/python2.3/site-packages/pyPgSQL/PgSQL.py", line 2740, in __unicodeConvert return obj.encode(*self.conn.client_encoding) UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in position 102: ordinal not in range(128) my insert query is: tracks_insert_values =(unicode(coments['TITLE']),coments['TRACKNUMBER']) y also tried with: tracks_insert_values=(coments['TITLE'].encode('utf-8'),coments['TRACKNUMBER']) insert_query = '''insert into tracks(titulo,no_pista)values(%s %i)''' % tracks_insert_values Martin Slouf wrote: > i had similar errors: > > Traceback (most recent call last): > File "/home/martin/skripty/accounts.py", line 125, in ? > main(sys.argv) > File "/home/martin/skripty/accounts.py", line 119, in main > print_accounts(accounts, url_part) > File "/home/martin/skripty/accounts.py", line 94, in print_accounts > print str(i).encode("utf-8", "replace") > UnicodeEncodeError: 'ascii' codec can't encode characters in position > 151-152: ordinal not in range(128) > > - - - - > > the solution seems to be: > > 0. string is not in unicode encoding (assumption) > 1. before printing out, convert the string to unicode > 2. when printing, convert to whatever charset you like > > though i dont understand much why (ive solved it a minute ago :) the > code should be: > > str = "any nonunicode string" > print unicode(str).encode("iso-8859-2", "replace") > > comments: > > 1. why the string is not in unicode can have several reasons -- i guess: > - does ogg stores tags in unicode? > - you have parsed an xml file with encoding attribute set (that > is what i do) > - etc > > 2. "replace" parameter in encode causes non-printable chars to be > replaced with '?' (you can use "ignore" or strict", see your python > doc) > > 3. the above will work _only_ _if_ the 'str' encoding is "iso-8859-2" -- > a funny thing -- first line of code converts from unknown (but the > programmer must know it) to unicode and the second one converts it back > from unicode to unknown (now the programmer tells that secret to python > :) > > 4. i would like to know from any python expert whether/why/why not: > > * my assumptions are right > > * why is that behaviour? -- if you search google you get > thousands of errors like this -- with no proper solutions i must add > > * is there an easier portable way (no sitecustomize.py changes) > to do it > > * i was looking in site.py and there is deleted the > sys.setdefaultencoding() function, but from the comments i do > not know why -- you know it? why is user not allowed to change the > default encoding? it seems reasonable to me if he/she could do that. > > thx. > > m. > From esj at harvee.org Thu Aug 26 21:28:51 2004 From: esj at harvee.org (Eric S. Johansson) Date: Thu, 26 Aug 2004 21:28:51 -0400 Subject: key storage In-Reply-To: <1093569139.412e8a738462b@www-mail.usyd.edu.au> References: <1093569139.412e8a738462b@www-mail.usyd.edu.au> Message-ID: <412E8E53.20203@harvee.org> Ajay wrote: > hi! > i am building a web application. for client authentication, i am using > cookies which include the HMAC of the data. > the server also has a public/private key pair for signing and verifying > information. start here. This is a really good site for Web based authentication techniques. I've implemented the system and you are more than welcome to the code. It may need some disentangling from my CGI/form support/template environmentbut don't say you weren't warned. ;-) http://cookies.lcs.mit.edu/pubs/webauth.html let me know if I can help --- eric From squirrel at WPI.EDU Thu Aug 12 14:48:19 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 12 Aug 2004 14:48:19 -0400 Subject: NumArray array-indexing In-Reply-To: References: Message-ID: On Thu, 12 Aug 2004, Christopher T King wrote: > On 12 Aug 2004, Michael Drumheller wrote: > > > Basically, it seems to me that NumArray simply does not support > > the distinction between a column vector and a row vector. That > > is, if you have x=[1,2,3], then transpose(x) is a no-op. True? > > False. You have to supply numarray with a two-dimensional array in order > to perform a two-dimensional transpose: Where by "False" I meant "The first sentence is false, but the second sentence is true". Column vectors and row vectors must be represented as two-dimensional arrays; transpose() of a one-dimensional array is a no-op since all transpose() does (by default) is reverse the order of the axes. From peter.maas at mplusr.de Fri Aug 20 10:46:17 2004 From: peter.maas at mplusr.de (Peter Maas) Date: Fri, 20 Aug 2004 16:46:17 +0200 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: D2, D2, D2 With dotted decorators above docstring From michaels at rd.bbc.co.uk Thu Aug 12 07:33:04 2004 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Thu, 12 Aug 2004 12:33:04 +0100 Subject: A decorator syntax not yet mentioned (I think!) References: <60dfb6f6.0408111846.615ee9eb@posting.google.com> <3YWdnYxLf--ObofcRVn-pw@powergate.ca> Message-ID: Michael Sparks wrote: > Regarding J2 on http://www.python.org/moin/PythonDecorators ... > ... >> 5 Technical problems with the current grammar parser if a suite >> *starts* with an optional part. (Ending with an optional part, >> such as "else:" is OK, but starting with one is not.) > ... >> Item 6 is always the case for any new feature, so I doubt that's the >> real problem - the real problem here strikes me as item 5. >> >> I do wonder how difficult it would be to add though... > > It doesn't actually seem that difficult to modify the grammar to > handle this if the decorator block handles *only* decorators. I've > just tried modifying the Grammar/Grammar file to see how plausible > this is, and I can get python to build and parse it. (It bombs out > because I've not done any backend work, and this is the first time > I've touched the python compiler source) Done a bit more work and it certainly *is* caused by the backend logic not in step with the grammar change I made rather than it not building/parsing correctly. I've tried changing things to make this work, but at this exact instant I don't have the time to do this. (I might take another look this evening, it doesn't look *too* difficult to do) I've also changed the grammar rules again to make it a smaller change: --- Python-2.4a2/Grammar/Grammar 2004-08-02 07:09:53.000000000 +0100 +++ Python-2.4a2-MS/Grammar/Grammar 2004-08-12 12:12:11.567115840 +0100 @@ -28,9 +28,10 @@ file_input: (NEWLINE | stmt)* ENDMARKER eval_input: testlist NEWLINE* ENDMARKER -decorator: '@' dotted_name [ '(' [arglist] ')' ] +decorator: dotted_name [ '(' [arglist] ')' ] decorators: decorator ([NEWLINE] decorator)* NEWLINE -funcdef: [decorators] 'def' NAME parameters ':' suite +funcdef: ['decorate' ':' NEWLINE INDENT decorators DEDENT] 'def' NAME parameters ':' suite parameters: '(' [varargslist] ')' varargslist: (fpdef ['=' test] ',')* ('*' NAME [',' '**' NAME] | '**' NAME) | fpdef ['=' test] (',' fpdef ['=' test])* [','] fpdef: NAME | '(' fplist ')' This builds, and I've changed some of Python/compile.c to handle this: --- Python-2.4a2/Python/compile.c 2004-08-04 11:26:08.000000000 +0100 +++ Python-2.4a2-MS/Python/compile.c 2004-08-12 12:19:47.570792744 +0100 @@ -4043,13 +4043,13 @@ { /* decorator: '@' dotted_name [ '(' [arglist] ')' ] */ int nch = NCH(n); - assert(nch >= 2); - REQ(CHILD(n, 0), AT); - com_decorator_name(c, CHILD(n, 1)); + assert(nch >= 1); + // REQ(CHILD(n, 0), AT); + com_decorator_name(c, CHILD(n, 0)); if (nch > 2) { assert(nch == 4 || nch == 5); - REQ(CHILD(n, 2), LPAR); + REQ(CHILD(n, 1), LPAR); REQ(CHILD(n, nch - 1), RPAR); com_call_function(c, CHILD(n, 3)); } @@ -4083,11 +4083,14 @@ PyObject *co; int ndefs, ndecorators; REQ(n, funcdef); - /* -6 -5 -4 -3 -2 -1 + /* -6 -5 -4 -3 -2 -1 funcdef: [decorators] 'def' NAME parameters ':' suite */ + /* -7 -6 -5 -4 -3 -2 -1 + funcdef: ['decorate' ':' NEWLINE INDENT decorators DEDENT ] 'def' NAME parameters ':' suite */ + - if (NCH(n) == 6) - ndecorators = com_decorators(c, CHILD(n, 0)); + if (NCH(n) == 11) + ndecorators = com_decorators(c, CHILD(n, 4)); else ndecorators = 0; @@ -5823,9 +5826,9 @@ */ case decorator: if (TYPE(n) == decorator) { - /* decorator: '@' dotted_name [ '(' [arglist] ')' ] */ + /* decorator: dotted_name [ '(' [arglist] ')' ] */ node *name, *varname; - name = CHILD(n, 1); + name = CHILD(n, 0); REQ(name, dotted_name); varname = CHILD(name, 0); REQ(varname, NAME); However I'm now getting a new error instead (just before a controlled core dump): Fatal Python error: unknown scope for staticmethod in Foo(1) in ./foo.py symbols: {'hello2': 2, 'hello': 2} locals: {'hello2': 0, 'hello': 1} globals: {} Aborted (core dumped) Smoke test is this: --------- class Foo: decorate: staticmethod def hello(who): print "woo?", who def hello2(who): print "woo?", who Foo.hello("HOO") --------- I've got to put this aside for the moment, but I'll come back to it later. (I think this is actually pretty close to working though...) Michael. -- Michael.Sparks at rd.bbc.co.uk British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From twanger at bluetwanger.de Tue Aug 10 09:38:35 2004 From: twanger at bluetwanger.de (Markus Bertheau) Date: Tue, 10 Aug 2004 15:38:35 +0200 Subject: super and __init__ arguments (Was: Re: Multiple inheritance with a common base class) In-Reply-To: <1092142873.2624.43.camel@dicaprio.akademie1.de> References: <1092137872.2624.16.camel@dicaprio.akademie1.de> <1092142873.2624.43.camel@dicaprio.akademie1.de> Message-ID: <1092145114.2624.49.camel@dicaprio.akademie1.de> ? ???, 10.08.2004, ? 15:01, Markus Bertheau ?????: > That is what I needed to know. Thanks. It should probably be noted in > the paragraph about multiple inheritance. Now how do I make the following work: class CommonBase(object): def __init__(self, c): pass class LeafA(CommonBase): def __init__(self, c, a): super(LeafA, self).__init__(c) class LeafB(CommonBase): def __init__(self, c, b): super(LeafB, self).__init__(c) class Multi(LeafA, LeafB): def __init__(self, c, a, b): super(Multi, self).__init__(c, a, b) m = Multi(0, 1, 2) Thanks -- Markus Bertheau From roman.yakovenko at actimize.com Mon Aug 23 03:26:45 2004 From: roman.yakovenko at actimize.com (Roman Yakovenko) Date: Mon, 23 Aug 2004 10:26:45 +0300 Subject: 2 GB files Message-ID: <2D89F6C4A80FA547BF5D5B8FDDD045232539F1@exchange.adrembi.com> > Elbert Lev wrote: > > From postings to this group and other resources I > understood that the > > only way to make Python programs to work correctly with files lager > > then 2 GB is building Python interpreter with some "magic spell" > > defines. It is not true. Sometimes I am working with files 6G+. Python is my only way to look into those files. Roman From apardon at forel.vub.ac.be Fri Aug 27 11:03:02 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 27 Aug 2004 15:03:02 GMT Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> <1gj4fb5.607xsc51izh8N%aleaxit@yahoo.com> <7xllg25lkt.fsf@ruckus.brouhaha.com> <1gj4u3a.12ttba9fynd6uN%aleaxit@yahoo.com> <1gj5bp4.qhup8tldmvebN%aleaxit@yahoo.com> <7xk6vlgemp.fsf@ruckus.brouhaha.com> <1gj6eil.hgzr1l125qaomN%aleaxit@yahoo.com> <1gj6n23.vnzqrh1unc1qfN%aleaxit@yahoo.com> Message-ID: Op 2004-08-27, Alex Martelli schreef : > Antoon Pardon wrote: > ... >> >> If you think I shouldn't voice an opinion here because GvR >> wins anyhow and my opinion won't matter fine. Just say so >> from the beginning. Don't start with pretending that you >> have good arguments that support the status quo because >> all that matters is that GvR prefers it this way. >> All good arguments in support are just a coincidence in >> that case. > > I do think, and I have indeed "stated so from the beginning" (many years > ago), that it's generally a waste of time and energy for people to come > charging here criticizing Python's general design and demanding changes > that won't happen anyway. There are forums essentialy devoted to > debates and flamewars independenlty of their uselessness, and this > newsgroup is not one of them. I don't demand changes. I have my critisms of the language and think that some arguments used to defend the language are not well founded and when I see one of those I sometimes respond to it. That is all. I realise no language is perfect and I don't have the time to design the one true perfect language my self. In general I'm happy to program in python with the warts I think it has. I'll just see how it evolves and based on that evolution and the appearance of other languages will decide what language I will use in the future. I hope that someday a ternary operator will arive, but my choice of language will hardly depend on that and I won't ask for it except if ever that particulat PEP becomes activated again. But if someone argues there is no need for a ternary operator I'll probably respond. > People with normal levels of perceptiveness can see the difference > between such useless rants, on one side, and, on the other, several > potentially useful kinds of discourse, that I, speaking personally, do > indeed welcome. Trying to understand the design rationale for some > aspect of the language is just fine, for example -- and that's because > trying to understand any complicated artefact X is often well served by > efforts to build a mental model of how X came to be as it is, quite > apart from any interest in _changing_ X. You may not like the arguments > I present, but I'm not just "pretending" that they're good, as you > accuse me of doing: many people like them, as you can confirm for > yourself by studying the google groups archives of my posts and of the > responses to them over the years, checking out the reviews of my books, > and so on. The number of people that like your arguments is irrelevant to me. If I don't think it is a good argument chances are I will respond to it. > If you just don't like reading my prose, hey, fine, many > others don't particularly care for it either (including Guido, > mostly;-); I'll be content with being helpful to, and appreciated by, > that substantial contingent of people who do like my writing. > > And so, inevitably, each and every time I return to c.l.py, I find some > people who might be engaging in either kind of post -- the useful > "trying to understand" kind, or the useless "criticizing what you cannot > change" one -- and others who are clearly just flaming. The problem IMO is that often enough, when a usefull trying to understand article arrives, the answers are not limited to explaining what is going on, but often include some advocacy of why the choice made in python was the correct one. This invites people who are less happy with that particular choice to argue why that choice isn't so good as the first responder may have let to believe. Even if they don't particularly want the language to change. > And inevitably > I end up repeating once again all the (IMHO) good arguments which (IMHO) > show most criticisms to be badly conceived and most design decisions in > Python to be consistent, useful, helpful and well-founded. Why? > Because this is a _public_ forum, with many more readers than writers > for most any thread. If these were private exchanges, I'd happily set > my mail server to bounce any mail from people I know won't say anything > useful or insightful, and good riddance. But since it's a public forum, > there are likely to be readers out there who ARE honestly striving to > understand, and if they see unanswered criticisms they may not have > enough Python knowledge to see by themselves the obvious answers to > those criticisms -- so, far too often, I provide those answers, as a > service to those readers out there. Well the same work the other way around. There are those people who think that some of the choices that python made are not that consistent, usefull, helpfull and well-founded as some would like us to believe and that those things may be known too. >> >> I don't see that much difference in the frustration of having >> >> to write: >> >> >> >> t = f(x) >> >> v[t] = v[t] + 1 >> > >> > You're repeating (necessarily) the indexing operation, which may be >> > unboundedly costly for a user-coded type. >> >> That repetion is just pythons inabilty to optimise. > > There being, in general, no necessary correlation whatsoever between the > computations performed by __getitem__ and those performed by > __setitem__, Maybe that is the problem here. I think one could argue that a c++ approach here would have been better, where v[t] would result in an lvalue, from which a value could be extracted or that could be set to a value depending on which side of an assignment it was found. And no I'm not asking that python should be changed this way. -- Antoon Pardon From newsgroups at jhrothjr.com Fri Aug 6 22:25:56 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 6 Aug 2004 22:25:56 -0400 Subject: PEP 263 status check References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> <10h5hgvpafm8a64@news.supernews.com> <41133C76.8040302@v.loewis.de> <10h6rklt3fa1690@news.supernews.com> <41137799.70808@v.loewis.de> <10h724r20kkeqb2@news.supernews.com> <10h7u8m9qknh76e@news.supernews.com> <41140A61.3040600@v.loewis.de> Message-ID: <10h8feetapdnaa9@news.supernews.com> "Martin v. L?wis" wrote in message news:41140A61.3040600 at v.loewis.de... > John Roth wrote: > > I've > > been in this business for close to 40 years, and I'm > > quite well aware of backwards compatibility issues > > and issues with breaking existing code. > > > > Programmers in general have a very strong, and > > let me repeat that, VERY STRONG assumption > > that an 8-bit string contains one byte per character > > unless there is a good reason to believe otherwise. > > You clearly come from a Western business. In CJK > languages, people are very aware that characters can > have more than one byte. They consider UTF-8 as just > another multi-byte encoding, and used to consider it > as an encoding that Westerners made to complicate their > lifes. That attitude appears to be changing now, but > UTF-8 is not a clear winner in the worlds where we > Westerners would expect it to be a clear winner. I'm aware of that. > > The current design allows accidental inclusion of > > a character that is not in the 7bit ascii subset ***IN > > A PROGRAM THAT HAS A UTF-8 CHARACTER > > ENCODING DECLARATION*** to break that > > assumption without any kind of notice. > > This is a problem only for the Western world. In the > CJK languages, such programs were broken a long time > ago. I don't think Python needs to be so Americo-centric > as to protect American programmers from programming > mistakes. American != non East Asian. In fact, I would consider American programmers to be the least prone to making this kind of mistake simply because all standard characters are included in the US-Ascii subset. It's much more likely to be a European (or non North American) problem. Even when writing in English, people's names will have non-English characters, and they have a tendency to leak into literals. (Mexico considers themselves to be part of Central America, for some political reason.) > > That in > > turn will break all of the assumptions that the string > > module and string methods are based on. That in > > turn is likely to break lots of existing modules and > > cause a lot of debugging time that could be avoided > > by proper design. > > Indeed. If the program is currently not broken, why > are you changing the source encoding? If you are > trying to support multiple languages, a properly- > designed application would use gettext instead > of putting non-ASCII into source code. > > If you are writing a new application, and you > put non-ASCII into the source, in UTF-8, are you > not testing your application properly? > > > I'm not worried about this causing people to > > abandon Python. I'm more worried about the > > current situation causing enough grief that people > > will decided that utf-8 source code encoding isn't > > worth it. > > Again, this is what Hallvard's PEP is for. It > does not apply to UTF-8 only, but I see no reason > why UTF-8 needs to be singled out. > > > I'll withdraw my objection if you can seriously > > assure me that working with raw utf-8 in > > 8-bit character string literals is what most programmers > > are going to do most of the time. > > In what time scale? Near time, most people will use > other source encodings. In the medium term, I expect > Unix will switch to UTF-8 throughout, at which point > using UTF-8 byte strings will work on every Unix > system - the scripts, by nature, won't work on non-Unix > systems, anyway. In the long term, I expect all Python > strings will be Unicode strings, unless explicitly > declared as byte strings. I asked Hallvard this question, not you. It makes sense in the context of the statements of his I was responding to. Your answer does not make sense. Hallvard's objection was that he actually wanted to have non-ascii characters put into byte literals in their utf-8 encoded forms (at least as I understand it.) If I thought about it, I could undoubtedly come up with use cases where I would find this behavior useful. The presupposition behind my statement was that those use cases were overwhelmingly less likely than the standard uses of byte string literals where a utf-8 encoded "character" would be a problem. John Roth > > Regards, > Martin From anthonybaxter at gmail.com Sun Aug 22 02:32:55 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sun, 22 Aug 2004 16:32:55 +1000 Subject: backward compatibility? In-Reply-To: References: Message-ID: On 21 Aug 2004 23:42:32 -0400, Aahz wrote: > It's serious. OTOH, they'll stay in the language until Python 3.0 comes > out, and there's nobody forcing you to upgrade. The useful lifespan of > a Python version seems to be about three or four years (my company just > switched from Python 1.5.2 to Python 2.2, so we'll be two full versions > out of date by the end of the year). Note also that Python 3.0 (aka Python 3000) isn't even close to being started - I suspect we're at least 4 or 5 years from it happening. And there's still going to be at least a couple more major releases in the 2.x cycle before then. See PEP 3000 for the current collection of ideas for Python 3.0. Anthony From john at grulic.org.ar Fri Aug 27 17:43:00 2004 From: john at grulic.org.ar (John Lenton) Date: Fri, 27 Aug 2004 18:43:00 -0300 Subject: Fun transformation problem In-Reply-To: References: Message-ID: <20040827214300.GB9923@grulic.org.ar> On Fri, Aug 27, 2004 at 09:20:18AM +0000, Dale Strickland-Clak wrote: > Thanks to everyone for your replies. Very interesting. > > It is not too embarrasing to admit that these were better than we'd come > up with. > > My colleague will be getting to grips with a newsreader in the near future > and may be along later to express his own gratitude. FYI, that goofy dictionary thing you're building is called a 'trie'. -- John Lenton (john at grulic.org.ar) -- Random fortune: No one can guarantee the actions of another. -- Spock, "Day of the Dove", stardate unknown -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From sholden at flexal.cs.usyd.edu.au Sun Aug 22 01:12:37 2004 From: sholden at flexal.cs.usyd.edu.au (Sam Holden) Date: 22 Aug 2004 05:12:37 GMT Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> <7x4qmv6cwo.fsf@ruckus.brouhaha.com> Message-ID: On 21 Aug 2004 20:59:35 -0700, Paul Rubin <> wrote: > aahz at pythoncraft.com (Aahz) writes: >> >It seems there are quite a few projects aimed to improve Python's >> >speed and, therefore, eliminate its main limitation for mainstream >> >acceptance. >> >> What makes you think speed is Python's primary limitation for mainstream >> acceptance? > > Well, whenever I want to write a mainstream application and think of > using Python, my first reaction is that Python is too slow... That you have have an irrational first reaction is hardly the "main limitation" for python. After all python has been used as the scripting engine for a number of commercial games - a domain that certainly cares about speed. implies that a python script runs on every frame for at least one commercial game. -- Sam Holden From deetsNOSPAM at web.de Wed Aug 25 07:45:11 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Wed, 25 Aug 2004 13:45:11 +0200 Subject: module functions list Message-ID: Hi, this strikes me as a pretty basic question, but google didn't help, so I'm asking it here: How do I get a list of functions defined in a module in the module itself? Like this: --- module functions.py def foo(): return 1 def bar(): return 1 def all_functions(): return --- The application for this is that I want a bunch of predefined functions for a small expression interpreter of mine to be collected in one module and get them all without an explicit "registration" process. Any ideas? -- Regards, Diez B. Roggisch From mike at nospam.com Mon Aug 2 16:48:55 2004 From: mike at nospam.com (Mike Rovner) Date: Mon, 2 Aug 2004 13:48:55 -0700 Subject: How to clear previous console output? References: Message-ID: (For console output) Use \r. Example: for i in range(100): print '%s\r' % ' '*20, # clean up row print '%d%%' % i, # note ending with comma print Note that it works only in real console window, not in simulated one (like in WinIDE). That is cross-platform. HTH, Mike Newgene wrote: > I want to show the progress by print 1% to 100%. But I hope each > output will clear the previous output before print, so that I can see > a dynamic updated display of percentage, instead of print all From skip at pobox.com Tue Aug 17 10:22:48 2004 From: skip at pobox.com (Skip Montanaro) Date: Tue, 17 Aug 2004 09:22:48 -0500 Subject: Databases: Getting values by column name In-Reply-To: References: Message-ID: <16674.5304.561826.138823@montanaro.dyndns.org> Robert> http://www.devshed.com/c/a/Python/MySQL-Connectivity-With-Python/2/ Robert> only use database rows as sequences, ie as arrays with numerical Robert> index. This gives you loads of problems when using "select *" Robert> and also bad code readability when selecting specific columns. Robert> Is there a way to use them as dictionaries, ie with Robert> Index-Strings (=column names) as indexes? Yes, for MySQLdb import the MySQLdb.cursors module then set the cursorclass arg when you create a connection, like so: import MySQLdb import MySQLdb.cursors ... conn = MySQLdb.Connection(host=..., user=..., passwd=..., db=..., cursorclass=MySQLdb.cursors.DictCursorNW, ...) I think the reason this sort of behavior isn't spelled out in PEP 249 is because it varies too much from one database to another. Psycopg (a PostgreSQL adaptor) does it differently. Instead of specifying the cursor type when the connection is created, you instantiate a different cursor class: conn = psycopg.connect("...") ... cursor = conn.dictcursor() I imagine there are some databases that either don't support name-based retrieval very well (or at all), or make it difficult to get at. You might get a more solid response on the reasons for this omission from PEP 249 from the db-sig folks: http://www.python.org/sigs/db-sig/ Skip From sholden at flexal.cs.usyd.edu.au Sun Aug 22 17:46:54 2004 From: sholden at flexal.cs.usyd.edu.au (Sam Holden) Date: 22 Aug 2004 21:46:54 GMT Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> <7x4qmv6cwo.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 22 Aug 2004 15:44:57 -0500, Reid Nichol wrote: > Sam Holden wrote: >> After all python has been used as the scripting engine for a number of >> commercial games - a domain that certainly cares about speed. > Not the graphics though and that is where the speed is really needed. True. However, when you run a script for every frame of said graphics the script needs to run reasonably fast. And that has been done. Obviously python is not *fast*, it is however, "fast enough" for the vast majority of applications. I'd argue that for a significant number of the applications python is not fast enough for, it is possible to write a component in C (or C++ or whatever) with a python wrapper. Of course it's not that python is super fast, it's that hardware is very fast these days. Games have gone from Assembler engines and C game code to C (C++ even) engines and scripting language game code. Of course python cod ebeing so much quicker to develop than C code doesn't gain as much as machine's get faster during development :) -- Sam Holden From tdelaney at avaya.com Mon Aug 9 23:52:34 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Tue, 10 Aug 2004 13:52:34 +1000 Subject: Just Starting. Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01CF3D4A@au3010avexu1.global.avaya.com> James wrote: > Hello My name is James and I was wondering if any of you out there can > recommend a good book or link for beginners? http://www.python.org/ In the side menu, first link under "Documentation" is "Beginner's Guide" ... Tim Delaney From sbabbitt at commspeed.net Mon Aug 9 18:49:28 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Mon, 9 Aug 2004 15:49:28 -0700 Subject: file owner id References: Message-ID: <1092092176.544950@news.commspeed.net> "Ajay" wrote in message news:mailman.1380.1092042651.5135.python-list at python.org... > hi! > > i have an application that allows admin users to create template files, > which are stored on the server. > currently the file are created with the owner "nobody" > is it possibly to change the owner to be the same as the owner of the web > account? > if yes, are there any security risks with doing so - the script changes to > the web account's owner, creates the file and then changes back. > > thanks > > cheers > > -- > Ajay Brar, > not sure what operating system your on but if your worried about security you could create some sort of alias dictionary, ailiasdict = {'nobody':'cfcgf1234','sombodyimportant':'pi3.14159'} then encrypt it and store it to disk. you then create the file with the owner ailiasdict["nobody"]. Tom From ksenia at ksenia.nl Sun Aug 22 05:20:37 2004 From: ksenia at ksenia.nl (Ksenia Marasanova) Date: Sun, 22 Aug 2004 12:20:37 +0300 Subject: Global config option - import issues again..... In-Reply-To: References: Message-ID: <87781397-F41C-11D8-A0E5-000A957911BC@ksenia.nl> > How do people deal with swapping languages around at runtime? I personally didn't wrote any multi-language application yet, but I think gettext module is the way to do it: http://docs.python.org/lib/module-gettext.html This webmail application is a good example of using it: http://calarts.edu/~elaforge/mail/ . If you download it, take a look at i18n.py file. HTH Ksenia From rynt at 9yahoo.com Wed Aug 18 15:52:27 2004 From: rynt at 9yahoo.com (R Baumann) Date: Wed, 18 Aug 2004 12:52:27 -0700 Subject: age of Python programmers References: Message-ID: "Lucas Raab" wrote in message news:jQHUc.1529$2L3.505 at newsread3.news.atl.earthlink.net... > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... > I celebrate the 17th anniversary of my 39th birthday in September. ;-) Started programming in the US Air Force when I was 27. Assembler on a Univac 1050-II. Ruben From abra9823 at mail.usyd.edu.au Sat Aug 14 23:10:01 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Sun, 15 Aug 2004 13:10:01 +1000 Subject: import node into document Message-ID: <1092539401.411ed409ae40c@www-mail.usyd.edu.au> hi! I have two documents 'policy' and 'dataschema'. how can i add a node (say, noded) from 'dataschema' as a child to a particular node in 'policy' (say nodep) java has importNode, is there an equivalent function in Python. if not, how do i go about doing it? just doing nodep.appendChild(noded) throws an error saying they are of different documents doing noded.ownerDocument = nodep.ownerDocument also throws an error saying ownerDocument is a read-only object. how do i then do the import? thanks cheers ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From jcarlson at uci.edu Sat Aug 14 13:40:01 2004 From: jcarlson at uci.edu (Josiah Carlson) Date: Sat, 14 Aug 2004 10:40:01 -0700 Subject: [Python-Dev] def ... decorate In-Reply-To: References: <20040813135102.63CF.JCARLSON@uci.edu> Message-ID: <20040814000340.63DE.JCARLSON@uci.edu> > They are important. What I tried to say is that with decorators they sometime > change. It did not happen with plain def-statement. So resulting signature > must be in the docstring. Ahh, but you did: "Decorators could be destructive and change function completely, so it's pitiful signature doesn't mean much." Even when a signature changes, the signature is important both before and after. The person who is changing the signature must know the original, and the person who is using must know the changed. In both cases, the signature is important, although the second suffers from a lack of obvious visual documentation. This is why, "I believe that any decorator that destroys a signature willingly should be considered broken." > >> I always thought the natural order of definition is value to define first, > >> definition to follow it. > > > >I don't know where this came from, but it is what we already have. > >def fun(args): > > body > > Probably, it comes from the math culture. Even HTML reflects this order. > Most programming languages also stick to it. I meant in this discussion. You brought it up in the scope of decorating functions, but the vast majority of function definitions are standard function definitions, which all follow the (name, value) ordering. > >> lambda a mistake? lambda a mistake... -OX > > > >Yes, lambda a mistake: > >http://www.linuxjournal.com/article.php?sid=2959 > > Maybe it was mistake to call it "lambda" a in math. But is Windows > directories are called folders. Terminology tends to downgrade for laymen. If you read the article, it says that due to the scoping rules in Python at the time, it wasn't a naming problem, it was that the functionality shouldn't have been added. > My mind (and not only mine) is not static. Our discussion changed it. > The only way to proof a solution is good is by having two or more > opposite opinions. Ahh, you have given up on the J3 syntax. Great. > >I am not aware of decorators in other languages, but I have kept my nose > >out of most langauges developed since I discovered Python in 2000. > > This is limiting your experience. In the same period I learned Ocaml alittle > where function signatures are part of type. Ocaml intrest me because it has > an efficient compiler (on par with C) but much less typing/functionality > ratio. As I already know the languages that are important for what I do (C/C++, Lisp, Python, SML, Prolog, Mathematica), learning others is not a priority. Really, I should have stated myself more clearly in my original post that you quote; I've browsed through various language documentations over the last few years (Eiffel, Ocaml, Perl, Rexx, TCL, etc.), but none of them made me jump out with "wow, that's awesome" as Python did 4 years ago - which is why I haven't bothered to learn them. > >> Aren't decorators functional programming everyday feature, when > >> (in some programming languages) it is normal to define function as > >> a superposition of simpler ones? > > > >That is like saying that all programming is functional. Is prolog a > >functional programming language? No, it is a logic programming language, > >yet it is common in Prolog to see the following: > > > >my_and(a, b) = my_bool(a) and my_bool(b) > > Not sure hat you wanted to express, but I wanted to say that in FP > languages decorators do not require special syntax as they are just > normal expressions involving function transformations. Even non-functional languages can /look/ like functional languages, composing complex functions and algorithms from simple ones. Python's scoping and side-effects, I believe, keep it from being a functional language. > Well, LISP doesn't require special syntax for any feature . If you want to be technical, Python doesn't require special syntax for decoration, it just makes it more convenient. And yes, I forgot about Lisp. Thinking about it, most languages with a sort of object encapsulation ability allow decorations. While it would be a bit ugly, one could do function decoration with C++ and the lovely void*. > P.S. I feel tired by this discussion. And it is c.l.p one, > not python-dev. As we do not have enough ON TOPIC points > of disageement, I do not want to continue. Agreed. - Josiah From grante at visi.com Mon Aug 9 10:41:52 2004 From: grante at visi.com (Grant Edwards) Date: 09 Aug 2004 14:41:52 GMT Subject: how many bytes in an int References: <9ACRc.1523$bJ2.9739@news1.mts.net> <4116f8ee$0$8076$a1866201@newsreader.visi.com> <41170cd1$0$8076$a1866201@newsreader.visi.com> <41171116$0$8079$a1866201@newsreader.visi.com> <41172C9A.2020301@jessikat.fsnet.co.uk> <41178bde$0$8077$a1866201@newsreader.visi.com> Message-ID: <41178d30$0$8077$a1866201@newsreader.visi.com> On 2004-08-09, Grant Edwards wrote: >> I think struct is really needed. > > Like the man said, "struct" doesn't convert to-from integers > of specified byte lengths. All it has are the C types "int" > "long" "long long", etc. There is no portable way using > struct to request a 4-byte integer. I like the "calcsize" suggestion for "portablizing" the struct method. Once at program startup you figure out what struct formats you need for various lengths and Bob's your uncle. -- Grant Edwards grante Yow! FIRST, I'm covering at you with OLIVE OIL and visi.com PRUNE WHIP!! From http Sun Aug 29 03:36:53 2004 From: http (Paul Rubin) Date: 29 Aug 2004 00:36:53 -0700 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <7xzn4gwgea.fsf@ruckus.brouhaha.com> <1gj7a1o.1a5d2q410jsn2kN%aleaxit@yahoo.com> <7xisb4xnh5.fsf@ruckus.brouhaha.com> <1gj7c1a.tfdm14p3hclcN%aleaxit@yahoo.com> <7xd61benm9.fsf@ruckus.brouhaha.com> <1gj82n3.1ylkr3nierngmN%aleaxit@yahoo.com> <7xd61b8uh2.fsf@ruckus.brouhaha.com> <7x1xhqg3kb.fsf@ruckus.brouhaha.com> Message-ID: <7xr7pqe6p6.fsf@ruckus.brouhaha.com> "Terry Reedy" writes: > > I think it's better to extend the syntax, e.g. > > import x(a,b) => __import__('x', {'a':None, 'b':None}) > > import x(a=v1,b=v2)=> __import__('x', {'a':v1, 'b':v2}) > > Identifier(args) is currently a call of identifier with args and > overloading that syntax to mean somthing similar but different is, to me, > even uglier in a different sort of way. Ok, use brackets instead: import x[a,b]. Then it's just a matter of overloading the index operator on __import__. From ptmcg at austin.rr._bogus_.com Thu Aug 26 12:24:39 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Thu, 26 Aug 2004 16:24:39 GMT Subject: Call for signatories for J2 References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> Message-ID: "Michael Sparks" wrote in message news:cgkvtr$5l1$1 at nntp0.reith.bbc.co.uk... > Anthony Baxter wrote: > > > I suppose instead I could've had: > > def identity(actualFunc): > def decorate(func): > return actualFunc(func) > return decorate > > class Foo: > @staticmethod > @identity((memoise,esiomem)[x==1]) > def Hoo(Who, *args): > print "Yoo", Who > > Which is nicer, but still pretty hideous. I'd agree that the preceding > if statement approach is better than a conditional expression. > On the contrary, I think it likely that, in the event a module of standard decorators is eventually provided (I thought I heard something like this in some prior thread, perhaps on python-dev), that there will need to be some flavors of nullDecorator such as unchanged and disabled below (I think I have the decorator syntax down, if not I hope you get the idea): def unchanged(func): "This decorator doesn't add any behavior" return func def disabled(func): "This decorator disables the provided function, and does nothing" def emptyFunc(*args,**kargs): pass return emptyFunc # define this as equivalent to unchanged, for nice symmetry with disabled enabled = unchanged Now you could do something like: globalEnableFlag = True @( (disabled,enabled)[globalEnableFlag ] ) def specialFunctionFoo() pass or using: (disabled,enabled)[globalEnableFlag ] def specialFunctionFoo() pass -- Paul From Jared.Cohen at noaa.gov Thu Aug 19 13:06:56 2004 From: Jared.Cohen at noaa.gov (Jared Cohen) Date: Thu, 19 Aug 2004 13:06:56 -0400 Subject: Please help -- Tkinter Scale widget with DoubleVar is acting weird Message-ID: <4124DE30.9050205@noaa.gov> I tried your code, and the exact same problem happened. When I set the slider to certain values (for instance, 0.3), the callback would start to be invoked when I just moved the mouse over the slider without even clicking. -------------- next part -------------- An HTML attachment was scrubbed... URL: From merkosh at hadiko.de Fri Aug 13 12:36:11 2004 From: merkosh at hadiko.de (Uwe Mayer) Date: Fri, 13 Aug 2004 18:36:11 +0200 Subject: blocking file.readlines() needed Message-ID: Hi, I am looking for a way to make the call to a file objects readline() method blocking when there is no more data, until data is appended to the file, similar to the way $ tail -F works. However, file.readlines() aborts and returns an empty list. Any ideas? Thanks Ciao Uwe From heikowu at ceosg.de Thu Aug 5 12:51:08 2004 From: heikowu at ceosg.de (Heiko Wundram) Date: Thu, 5 Aug 2004 18:51:08 +0200 Subject: RELEASED Python 2.4, alpha 2 In-Reply-To: References: <411231C8.3020308@interlink.com.au> Message-ID: <200408051851.08457.heikowu@ceosg.de> Am Donnerstag, 5. August 2004 18:29 schrieb Christopher T King: > They purport to solve the problems of function type declaration > (class/static), function attributes, runtime type checking, and general > function mangling, when each of these (save general function mangling) > already have distinct solutions in nearly every other language. The first > three problems are currently implemented as hacks in Python that happen to > fall under the category of "general function mangling". Streamlining the > hack is not the answer. I don't think they try to solve all the things you state. Rather, it's only about general function mangling at compile time. Whatever you need to do for function mangling, that's up to you. And, at least for me, as I stated elsewhere, the syntax is just fine. I've tried it out yesterday, porting some code to 2.4a2 which used thread locks extensively, and just writing a little class InstanceSynchronizer() which is just a Class which defines __call__ (when decorating a function) and gets the first parameter from the function call to acquire an instance specific lock is certainly the right way to go. Think of the following: (old style) class x(object): def __init__(self): self.lock = threading.RLock() def synchronized_method(self): self.lock.acquire() try: finally: self.lock.release() That's just plain horrible compared to what @ decorators can do: class x(object): synchronized = InstanceSynchronizer() @synchronized def synchronized_method(self): Writing the InstanceSynchronizer is pretty easy too: class InstanceSynchronizer(object): def __init__(self): self._locks = {} self._refs = {} def _delete_ref(self,ref): del self._locks[self._refs[id(ref)][1]] del self._refs[id(ref)] def __call__(self,f): def fsyn(fself,*args,**kwargs): try: lock = self._locks[id(fself)] except KeyError: lock = threading.RLock() fselfref = weakref.ref(fself,self._delete_ref) self._locks[id(fself)] = lock self._refs[id(fselfref)] = (fselfref,id(fself)) lock.acquire() try: return f(fself,*args,**kwargs) finally: lock.release() return fsyn This little class takes care of everything needed for instance locks. Writing a class that takes care of class locks for functions (in case you need to update class data) is easy as pie too. class ClassSynchronizer(object): def __init__(self): self._lock = threading.RLock() def __call__(self,f): def fsyn(*args,**kwargs): self._lock.acquire() try: return f(*args,**kwargs) finally: self._lock.release() return fsyn Now, if you have these two utility classes at your disposal, you can do the following: class someobject(object): __instances__ = {} isynchronized = InstanceSynchronizer() csynchronized = ClassSynchronizer() @csynchronized def __init__(self): @isynchronized @csynchronized def do_something(self): @isynchronized def do_somethingelse(self): Now tell me that using decorators to do synchronization isn't a lot easier to read than the first (old) example is, and also less error-prone (resp. acquiring/releasing locks properly and without deadlocks). Heiko. From walter at livinglogic.de Thu Aug 12 12:20:04 2004 From: walter at livinglogic.de (=?ISO-8859-1?Q?Walter_D=F6rwald?=) Date: Thu, 12 Aug 2004 18:20:04 +0200 Subject: Python script to generate static site? In-Reply-To: References: Message-ID: <411B98B4.9020307@livinglogic.de> Fred wrote: > Hi, > > I'm sure there are a bunch of them, but googling just returned > full-fledged CMS that require a DBMS and generate dynamic pages. > > I'd just like a script that would > 1. look in a directory for articles in raw HTML, > 2. generate a cooked output for each page (ie. add header and footer, > CSS link in HEAD, etc.), > 3. regenerate the homepage with "Last modified" bit following each > article's title, > 4. ready to be uploaded by FTP to a web server that only handles > static web pages. > > Considering Python's wealth of libraries, it's most likely only a > couple hours' work, but since I'm pretty much a Python newbie... You could try XIST (http://www.livinglogic.de/Python/xist/). The source for this page can be found here: http://www.livinglogic.de/Python/xist/index.htmlxsc XIST supports Unicode, XHTML, SVG, XSL-FO, WML etc. Bye, Walter D?rwald From in.aqua.scribis at nl.invalid Thu Aug 19 11:11:42 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Thu, 19 Aug 2004 17:11:42 +0200 Subject: Tkinter In-Reply-To: <8e16829.0408190703.1c6845d7@posting.google.com> References: <8e16829.0408190703.1c6845d7@posting.google.com> Message-ID: Roland schreef: > Salut, > > > J'utilise LNUX RedHat 9.0 et je n'arrive pas ? utilser Tkinter > car ? chaque fois que j'essaye de faire executer un code dans lequel > j'ai import? le module Tkinter, j'obtient: > from tkinter import* > ImportError: No module named tkinter . > Je croyais que ce module ?tait int?gr? ? python. Indeed! >>> import tkinter Traceback (most recent call last): File "", line 1, in ? ImportError: No module named tkinter >>> import Tkinter >>> print Tkinter.__doc__ Wrapper functions for Tcl/Tk. More text omitted. -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From ptmcg at austin.rr._bogus_.com Thu Aug 12 06:24:46 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Thu, 12 Aug 2004 10:24:46 GMT Subject: A decorator syntax not yet mentioned (I think!) References: <60dfb6f6.0408111846.615ee9eb@posting.google.com> <3YWdnYxLf--ObofcRVn-pw@powergate.ca> Message-ID: "Michael Sparks" wrote in message news:cffbbu$amv$1 at nntp0.reith.bbc.co.uk... > Peter Hansen wrote: > > Carl Banks wrote: > >> One thing that's different is that, in all those cases, the second > >> block has a keyword that can't appear alone. You can't have an > >> except without a try, or an else without an if, but you could have a > >> def without a decorate. > ... > > is this an argument based on presumed difficulties in > > implementing the idea? > > Looking at the wiki it states (as negative points): > 1 New keyword > 2 Overkill for the simple case like classmethod > 3 Many people felt it was wrong use of an identation suite. > 4 Has the same problem as 5.A, in that the decorate block implicitly > affects the following def. This does not occur elsewhere in Python. > 5 Technical problems with the current grammar parser if a suite > *starts* with an optional part. (Ending with an optional part, such > as "else:" is OK, but starting with one is not.) > 6 No implementation currently exists. > > Item 6 is always the case for any new feature, so I doubt that's the > real problem - the real problem here strikes me as item 5. > > I do wonder how difficult it would be to add though... > Looking at the code, it appears that this is how the current '@' syntax is defined, that a funcdef is optionally preceded by a 'decorators' group, consisting of one or more 'decorator' (looking at both Grammar/Grammar and compile.c). So I think this 'technical problem' is just conjecture. (Should check with Anthony Baxter to confirm.) -- Paul From josephwinston at mac.com Wed Aug 25 09:32:21 2004 From: josephwinston at mac.com (Jody Winston) Date: Wed, 25 Aug 2004 13:32:21 GMT Subject: Late binding eval()? References: <20040824142636721-0400@braeburn.themorgue.org> Message-ID: Kevin Smith writes: > I want to evaluate an expression using eval(), but I only want to supply > the variable values "on demand." For example, let's say that I want to > evaluate 'x+y'. Normally, I would create a dictionary containing 'x' > and 'y' with their corresponding values and pass it in as the globals or > locals. However, in my application, I'm getting an arbitrary expression > from the user. I thought that I could just create a dictionary-like > object and override __getitem__ to look up values in a database as they > were called for, but that didn't work. > > Another way of doing this would be to parse the expression and find all > of the top-level variables. This could be a little tricky (i.e. [x for > x in mylist] would only require 'mylist' to be in the dictionary of > globals/locals. > > Does anyone have any ideas on how to do this? > Here's what I'm doing: #! /bin/env python import sys import os import tokenize import keyword import Numeric class ReadlineInterface(object): """Present an interface that mimics readline for tokenize.""" def __init__(self, source): """Construct the instance.""" self.source = source self.called = 0 def __call__(self): """Return the source if and only if we have not been called before.""" if self.called == 0: self.called = 1 return self.source else: return "" class Attribute(object): def __init__(self, name = None, value = 0): self.name = name self.value = value return def coerceToAttribute(value): """Returns value if value is an Attribute or an Attribute with the value set.""" if isinstance(value, Attribute): result = value else: result = Attribute() result.value = value return result coerceToAttribute = staticmethod(coerceToAttribute) def __add__(self, other): """Overloading of binary addition operator (self + other); returns a new BaseAttribute.""" o = Attribute.coerceToAttribute(other) result = Attribute() result.name = self.name result.value = self.value + o.value return result def __sub__(self, other): """Overloading of binary subtraction operator (self - other); returns a new Attribute.""" o = Attribute.coerceToAttribute(other) result = Attribute() result.name = self.name result.value = self.value - o.value return result class Equation(object): def __new__(cls, *p, **k): """Construct a new class and correctly set up the dispatching of properties in subclasses.""" self = object.__new__(cls, *p, **k) # Correctly set up the dispatching of properties in subclasses. cls.equation = property(cls.getEquation, doc = "The equation.") cls.created = property(cls.getCreated, doc = "The created variables.") cls.keywords = property(cls.getKeywords, doc = "The keywords variable.") cls.verbose = property(cls.getVerbose, cls.setVerbose, doc = "The attribute verbose. When set, the class prints more information.") return self def __init__(self, equation): """Construct the instance.""" self.__equation = equation self.__verbose = False self.__created = [] self.__keywords = keyword.kwlist + ['dir', 'len', 'int', 'float', 'repr', 'abs', 'long', 'complex', 'divmod', 'max', 'min', ] + dir(Numeric) return def createAttribute(self, name): """Build an attribute and save it's name.""" # # Return a zeroed but otherwise useless attribute # result = Attribute(name = name, value = 0) self.__created.append(name) return result def localSymbols(self): """Return the local symbols used by the equation.""" l = locals() # # Add some symbols that will persist # if not l.has_key("keywords"): l["keywords"] = self.keywords return l def createSymbols(self): """Determine by parsing the equation what attributes need to be created.""" interface = ReadlineInterface(self.equation) l = self.localSymbols() g = globals() k = self.keywords try: tokens = tokenize.generate_tokens(interface) except tokenize.TokenError, msg: raise TokenError(msg) lastType = None lastToken = None for (tokenType, token, start, end, line) in tokens: if self.verbose: print 'Equation.createSymbols: type = %s, token = %s, start = %s, end = %s, line = "%s"' % \ (tokenType, token, start, end, line) # if we are a name and the last thing that we saw was not an operator named "." if (tokenType == tokenize.NAME) and not (lastType == tokenize.OP and lastToken == "."): # if we have not been seen before if (not token in k) and (not token in l) and (not token in g): l[token] = self.createAttribute(token) lastType = tokenType lastToken = token return g, l def getEquation(self): """Return the equation.""" return self.__equation def getCreated(self): """Return the list of created attributes.""" return self.__created def getKeywords(self): """Return the list of words that are keywords.""" return self.__keywords def getVerbose(self): """Return the state of verbose.""" return self.__verbose def setVerbose(self, value): """Set the state of verbose.""" self.__verbose = value return def main(argv = None): if argv is None: argv = sys.argv userSuppliedEquation = "b.value = 1; c.value = 2;a = b + c" equ = Equation(userSuppliedEquation) g, l = equ.createSymbols() print "Created =", equ.created code = compile(userSuppliedEquation, '', 'exec') eval(code, g, l) print "a =", l['a'].value print "b =", l['b'].value print "c =", l['c'].value return if __name__ == "__main__": sys.exit(main() or 0) -- Jody Winston From gherzig at fmed.uba.ar Wed Aug 18 16:28:43 2004 From: gherzig at fmed.uba.ar (Gerardo Herzig -Departamento de Proyectos Especiales e Internet- Facultad de Medicina) Date: Wed, 18 Aug 2004 17:28:43 -0300 Subject: age of Python programmers In-Reply-To: <889cbba0.0408181206.1812881c@posting.google.com> References: <889cbba0.0408181206.1812881c@posting.google.com> Message-ID: <200408181728.43540.gherzig@fmed.uba.ar> 30 years old. First program at 11 (Basic) on ZX Spectrum. Still a stinky programer :P Gerardo From kenneth.m.mcdonald at sbcglobal.net Sat Aug 7 00:17:03 2004 From: kenneth.m.mcdonald at sbcglobal.net (Kenneth McDonald) Date: Sat, 07 Aug 2004 04:17:03 GMT Subject: How to initialize instances of subclass of 'str'? Message-ID: <060820042320172090%kenneth.m.mcdonald@sbcglobal.net> I'm attempting to create a subclass of 'str' that I can abitrarily initialize at creation time. As an illustration, this gives the flavor of what I'm trying to do: class AlwaysLower(str): def __init__(self, s): str.__init__(self, s.lower()) The idea is that an AlwaysLower instance should be a string which is always lowercase; AlwaysLower('A') -> 'a', AlwaysLower('b') -> 'b', etc. (Of course, the resultant instances are not _just_ strings, but since they are subclasses of str, they can be treated and viewed as strings, as I implicitly do above.) Unfortunately, the above code doesn't work; the resultant instance's string value is always s, i.e. the call to str.__init__ has no effect. I realize that I could write a function to do this, but there are other reasons I want to subclass str. I also realize I could have a function call AlwaysLower with a lowercase argument, but I find that inelegant. I've also tried messing around with __new__, but gotten only runtime exceptions for my troubles :-). At the moment, what's really stumping me isn't so much how to do this, but more the mechanism by which 's' is being used to initialize the string. It's not being passed by __init__, so how is it being passed? __new__? As I say, I couldn't get anywhere with that. Anyone know of good examples of how to subclass builtins? Thanks, Ken McDonald From martin at v.loewis.de Sat Aug 7 01:13:00 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 07 Aug 2004 07:13:00 +0200 Subject: Non-ASCII in identifiers In-Reply-To: References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de><10h5hgvpafm8a64@news.supernews.com> <41133C76.8040302@v.loewis.de><10h6rklt3fa1690@news.supernews.com> <41137799.70808@v.loewis.de><10h724r20kkeqb2@news.supernews.com> <4113D8DF.8080106@v.loewis.de> Message-ID: <411464DC.8060308@v.loewis.de> Terry Reedy wrote: > While sympathizing with this notion, I have hitherto opposed it on the > basis that this would lead to code that could only be read by people within > each language group. But, rereading your idea, I realize that this > objection would be overcome by a reader that displayed for each Unicode > char (codepoint?) not its native glyph but a roman transliteration. I personally consider this objection irrelevant. Yes, it is desirable that portable libraries use only pronouncable (in English) identifiers. However, that is no justification for the language to make a policy decision that all source code in the language needs to use pronouncable identifiers. Instead, the author of each piece of code needs to make a decision what kind of identifiers to use. Some people (e.g. children) don't care a bit if somebody 20km away can read their source code, let alone somebody 10000km away - those far-away people will never get to see the code in the first place. So I doubt there is much need for transliterating source code viewers. At the same time, it might be a fun project to do. > Some writing systems also have different number digits, which could also be > used natively and tranliterated. A Unicode Python could also use a set of > user codepoints as an alternate coding of keywords for almost complete > nativification. I believe the math symbols are pretty universal (but could > be educated if not). Now, this is different story. To implement this, the Python parser needs to be changed to contain locale information, and one carefully has to make an implementation so that the same code will run the same way independent on the locale in which it is executed. This requires that information about all locales is included in all installations, which is expensive to maintain. In addition, alternate keywords might not help so much, since real integration into the natural language would also require to change the order of identifiers and keywords - something that I consider unimplementable. Regards, Martin From rschroev_nospam_ml at fastmail.fm Wed Aug 18 11:32:37 2004 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Wed, 18 Aug 2004 15:32:37 GMT Subject: age of Python programmers In-Reply-To: References: Message-ID: Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... 29, but I don't know if I qualify for 'Python programmer'... I use C++ professionally, and use Python only for small scripts and for some small simple hobby-projects. -- "Codito ergo sum" Roel Schroeven From peter at engcorp.com Fri Aug 20 07:03:35 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 20 Aug 2004 07:03:35 -0400 Subject: Alternative decorator syntax decision In-Reply-To: References: <10ia1a9jm9tkuca@corp.supernews.com> Message-ID: <84GdneSa3r-TR7jcRVn-tw@powergate.ca> Peter Hansen wrote: > Jeff Shannon wrote: > >> My votes: J2 J2 E2 > > I second that. (J2 J2 E2) I believe that the result the direction this is taking is inevitable: a widely split vote with no consensus. I did think there was much more agreement about which one was the best alternative, warts and all, to @pie and which one was therefore the most likely to get any attention at all from Guido. I also thought people had a better grasp of which ones had already been *rejected* fairly conclusively. Don't people who are voting for the obscure ones understand that this is likely to result in a no-decision, and therefore a decision for @pie by default? I'd like to change my vote to J2 J2 J2. -Peter From peter at engcorp.com Wed Aug 18 21:02:07 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 18 Aug 2004 21:02:07 -0400 Subject: Newbie question about file input In-Reply-To: References: <4122328e$0$8079$a1866201@newsreader.visi.com> Message-ID: Aaron Deskins wrote: > Thanks for the info. I wasn't aware that "\n" is whitespace. I'm still a > programming beginner and learning everyday! Any other whitespace > characters I should know about? c:\>python >>> import string >>> string.whitespace '\t\n\x0b\x0c\r ' >>> len(string.whitespace) 6 That's ASCII TAB, LF, VT, FF, CR, and SPACE. -Peter From xtian at toysinabag.com Sun Aug 8 23:49:10 2004 From: xtian at toysinabag.com (xtian) Date: 8 Aug 2004 20:49:10 -0700 Subject: @decorator syntax is sugar, but for what exactly? References: <4115b53a$1@nntp0.pdx.net> <4116239e$1@news.012.net.il> Message-ID: Avner Ben wrote in message > The "property" call resembles both classmethod, staticmethod and > instancemethod, but cannot be eliminated using the new function > decorator syntax, because of its m:1 nature - one property binds > together a getter, a setter etc., where staticmethod etc. change the > status of one function in one way. > [snip] > Talking about properties, I like the C# way of defining them, which is > straightforward and readable. The property begins like a method, but has > no argument list and includes a getter function with no arguments and a > setter function with one argument. Adapted to Python, it would look > something like: > > class hasProperty: > def __init__(self,aProperty='') > self.aProperty = aProperty > def AProperty: > def get(self): > return self.aProperty > def set(self,value): > self.aProperty = value > obj = hasProperty() > obj.AProperty = 'test' > print obj.AProperty I'm not sure that this application of the new syntax is much worse than what you've got... (it *is* a bit hacky in that it's calling the function it's wrapping, but there you go). >>> def property_(f): return property(*f()) >>> class DecorationTest(object): def __init__(self): self._foo = 1 @property_ def foo(): def get(self): print "get" return self._foo def set(self, val): print "set" self._foo = val return get, set >>> t = DecorationTest() >>> t.foo get 1 >>> t.foo = 3 set >>> t.foo get 3 What do people think of something like this? Cheers, xtian From tjreedy at udel.edu Tue Aug 31 20:54:52 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 31 Aug 2004 20:54:52 -0400 Subject: Give * operator "deep copy" References: Message-ID: "Nick Jacobson" wrote in message news:f8097096.0408311154.ae06a5b at posting.google.com... > This question is with regard to the * operator as used for sequence > concatenation. * is specifically a repetition operator. And as you wrote, n*seq is a sequence operation and not specifically a list operation. Any sensible discussion of changing its semantics, even though completely hypothetical (since this will not happen for the foreseeable future), must be in the context of sequences, and not just lists. The purpose of n*seq is to compactly specify a repetitious sequence and do so in a way such that the interpreter can efficiently create the requested result. Here are two realistic examples: >>> 70*'-' # output separator '----------------------------------------------------------------------' >>> 20*[0] # initialized vector [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] > There's the well-known gotcha: The gotcha arises in the context of 'multiplying' a sequence containing a mutable sequence. It gotcha arises from the conjunction of three factors: 1. the desire to create a 2D structure with a shortcut operation intended to construct 1D sequences. 2. the mistake of ignoring identity as an important property for mutable objects and as a part of the definition of 'repetitious' for sequences of such objects 3. the mistake of taking 'container' too literally. Tuples and lists are like rosters, not rooms. A student can only be in one room (at a time) but can simultaneously be on the roster of multiples classes and clubs. If, for example, a student gets an honor, then every class and club 'containing' that student now 'contains' an honored member. What rosters actually contain are some sort of identifier for each student, not the students themselves. > a = [[1, 2]] > b = a*3 > b[0][0] = 4 > print b > > Result: > [[4, 2], [4, 2], [4, 2]] Because b is a repetition of the mutable content of a as requested. > When you wanted: > [[4, 2], [1, 2], [1, 2]] If one does not want object repetition (as opposed to value repetition), then one should not use the object repetition operator. Use a loop to create different lists instead. > My question is, since b = a*3 is equivalent to b = a + a + a, The equivalence is quite limited. 'n*a' is valid code. 'a+a+...+a n times' is not, so 'n*a' is result equivalent instead to an explicit loop or list comprehension. Furthermore, the sequential addition falls into the O(n*n) runtime trap, which the O(n) repetition operator is given to us to avoid. > why not use deep copies of a? You seem to be saying 'since multiplication is a handy and speedy shorthand for repeated addition, let us change it to mean to something else.' ?? > That is, let b = a*3 be equivalent to: > b = copy.deepcopy(a) + copy.deepcopy(a) + copy.deepcopy(a) Part of Python's design is to not create/copy objects unless explicitly requested. And certainly not deepcopies! > It seems much more likely that someone would want to create copies of > an item, rather than inserting the same item several times into the > list. For characters in a string, the distinction is not especially meaningful. For strings (in a non-string sequence), tuples, numbers, and other non-mutables, copies are a waste of time and space and reuse of one is exactly what one should want! Again, * is not just for lists, either as container or containee. > If this has been previously discussed/documented, please point me to > where I can read about it. The meaning of n*seq is documented in the ref manual. The buggy use of it comes up on the newsgroup fairly often. Try googling the group archives. Terry J. Reedy From ted at soleburymountain.com Mon Aug 23 20:18:40 2004 From: ted at soleburymountain.com (tdi) Date: 23 Aug 2004 17:18:40 -0700 Subject: How does a "script" differ from a "program" or "subroutine"? Message-ID: Ok, stupid question for the day. I'm reading the interview with Steve Moret and he says: "Once a lot of scripts started going in we knew there was no way we could back out of using Python." I'm just getting into Python and am wondering if I'm missing something or this is just a semantic issue. Thanks. -Ted From fumanchu at amor.org Sun Aug 22 00:51:09 2004 From: fumanchu at amor.org (Robert Brewer) Date: Sat, 21 Aug 2004 21:51:09 -0700 Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WEDONE? Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E22@exchange.hqamor.amorhq.net> Paul Rubin wrote: > "Paul McGuire" writes: > > Please start giving some thought to what the 'decorate' > keyword should be. > > Looks like "declare" to me ;-) I agree, for reasons which will become clear in the proposal draft. I'd be most interested to hear arguments _against_ "declare", if there are any. Robert Brewer MIS Amor Ministries fumanchu at amor.org From squirrel at WPI.EDU Tue Aug 3 09:58:46 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 3 Aug 2004 09:58:46 -0400 Subject: how do i do this - stream file In-Reply-To: References: Message-ID: On Tue, 3 Aug 2004, Ajay wrote: > I have the script to do the signing and pickle the signature into a file, > but how do i allow the user to download it? Instead of pickling it to a file, pickle it to a string (using dumps). Then you can change your script to a CGI script like the following: #!/usr/local/bin/python <-- replace this with the real location of Python on your server import sys from pickle import dumps mydata = dumps() sys.stdout.write('Content-type: application/x-pickle\n\n') sys.stdout.write(mydata) That first sys.stdout.write is all that's needed to make a basic CGI script: the Content-type line tells the web browser what type of information to expect (the MIME type). Then you can just send whatever data you like (this works with print statements too; but remember that they append a \n to your data). For normal web pages, the MIME type is text/html. The type application/x-pickle is just something I made up, since there is no MIME type corresponding to pickled data. You may even consider just sending the signature as text and use the standard MIME type text/plain. You should put your script in the cgi-bin/ directory on your web server, and set its executable bit if it's a Unix server. From prudek at bvx.cz Sat Aug 21 10:00:04 2004 From: prudek at bvx.cz (Milos Prudek) Date: Sat, 21 Aug 2004 16:00:04 +0200 Subject: popen child termination In-Reply-To: <20040821131250.GC1458@unpythonic.net> References: <412723B7.1080002@bvx.cz> <20040821131250.GC1458@unpythonic.net> Message-ID: <41275564.8000701@bvx.cz> No. I know I could use os.system(). My motivation was curiosity: why this does not work? I thought that popen is simply more powerful than system(), a superset of os.system() if you will. Thanks for explaining that I cannot achieve this with os.popen (2,3,4). -- Milos Prudek From cybermanxu at hotmail.com Wed Aug 25 12:59:49 2004 From: cybermanxu at hotmail.com (Jinming Xu) Date: Wed, 25 Aug 2004 11:59:49 -0500 Subject: counterpart for Python None in C++ side Message-ID: Hi Folks, Could any of you please teach me what's the counterpart of Python None in C++ side? Since I need to manipulate a Python None in C++. Thanks a lot, Jinming Xu _________________________________________________________________ On the road to retirement? Check out MSN Life Events for advice on how to get there! http://lifeevents.msn.com/category.aspx?cid=Retirement From cce at clarkevans.com Mon Aug 23 11:58:08 2004 From: cce at clarkevans.com (Clark C. Evans) Date: Mon, 23 Aug 2004 11:58:08 -0400 Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: <20040823155808.GA71531@prometheusresearch.com> Just about average I guess.... 35 very soon On Thu, Aug 19, 2004 at 10:35:53PM +0000, Roel Schroeven wrote: | number of datapoints: 94 | mean: 35.4 | standard deviation: 12.6 From jsmith at thebigwave.net Mon Aug 16 23:53:50 2004 From: jsmith at thebigwave.net (John Smith) Date: 16 Aug 2004 20:53:50 -0700 Subject: Using PyObject_CallObject on an Instantiated Class Message-ID: <616e5a5e.0408161953.2a07e9d7@posting.google.com> Greetings All, I have something similiar to this: Foo.py class Foo(object): def function(self): pass Bar.py class Bar(Foo): def function(self): self.variable = self.variable + 1 Bleen.py def GetBar(): package = __import__('Directory.Bar') module = getattr(package, 'Bar') classobj = getattr(module, 'Bar') return classobj() >From C++, I call PyObject* pBar = PyObject_CallMethod(pBleen, "GetBar"); // Not exactly but close enough Now, I'd like to save off some pointers to this instance of Bar.function so that I can call it without the lookup overhead of the PyObject_CallMethod (IE: using PyObject_CallObject) However, Anything that I try to do fails. >From python, foo.__dict__ is empty, and foo.__class__.__dict__ refers to the base class obviously. If I do the equivilant from C++ of: PyObject* sClass = PyString_FromString("__class__"); PyObject* pClass = PyObject_GetAttr(m_pObject, sClass); PyObject* sDict = PyString_FromString("__dict__"); m_pDictionary = PyObject_GetAttr(pClass, sDict); Then m_pDictionary shows as empty in PyDict_Next() (Probably because it is dictproxy) So given that I'd have a few thousand Bars() each in it's own C++ class that would like to have a PyObject* to function() that would contain it's own 'self.variable' how would I get the pointer to it so that I could call PyObject_CallObject on it? Thanks! -John From deetsNOSPAM at web.de Wed Aug 25 17:26:19 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Wed, 25 Aug 2004 23:26:19 +0200 Subject: Dynamic command on Menu items? References: <2e3fe5bf.0408251154.74bc6243@posting.google.com> Message-ID: You could do it like this (untested): class FunClosure: def __init__(self, f, args): self.f = f self.args = args def __call__(self): self.f(self.args) M.menu.add_command(label=l, command=FunClosure(f, [p])) -- Regards, Diez B. Roggisch From fperez528 at yahoo.com Thu Aug 12 17:04:07 2004 From: fperez528 at yahoo.com (Fernando Perez) Date: Thu, 12 Aug 2004 15:04:07 -0600 Subject: drop into the interpreter References: Message-ID: Hoang Do wrote: > is there a facility to inspect the run-time of a python script? > Essentially, it would execute a script to a set specific point and then drop > into the interpreter. Something like a "Stop" or "Break"? ipython has a mode designed specifically for this: http://ipython.scipy.org/doc/manual/node9.html Best, f From cmedcoff at hotmail.com Tue Aug 10 19:52:40 2004 From: cmedcoff at hotmail.com (cmedcoff at hotmail.com) Date: Tue, 10 Aug 2004 19:52:40 -0400 Subject: how to dispatch objects depending on their class References: <4118dd4a$1@maser.urz.unibas.ch> Message-ID: Visitor Pattern? From apavluck at gmail.com Mon Aug 23 08:27:08 2004 From: apavluck at gmail.com (Alex Pavluck) Date: 23 Aug 2004 05:27:08 -0700 Subject: training classes in Atlanta, GA? Message-ID: Does anyone know if there are training classes for a PYTHON beginner in Atlanta, GA? I need it to not be too expensive and after 5 or weekends! Thanks! Alex From ajsiegel at optonline.com Wed Aug 18 00:15:47 2004 From: ajsiegel at optonline.com (Arthur) Date: Wed, 18 Aug 2004 04:15:47 GMT Subject: Problem with floating point precision References: <10i4c1lrvd3rm9b@news.supernews.com> Message-ID: <9pl5i0hkelivuuv867igo343eqnghkd8tl@4ax.com> On Tue, 17 Aug 2004 12:19:50 -0400, "John Roth" wrote: >"j_mckitrick" wrote in message >news:ec6dce8b.0408170538.1f0211d2 at posting.google.com... >> I checked the docs, but found nothing about floating point issues. >> >> I am working on an app that deals with currency values, and only does >> addition and subtraction (no division). But I am starting to see >> values that should be the same failing a compare! What is the >> workaround or correct way to compare 2 floats? It worked fine for >> months, then suddenly starting acting odd. I might have upgraded >> Python somewhere in between, I can't recall. > >The basic issue here is that you shouldn't be using floats >for currency. Granted, lots of people do, but it will eventually >run into exactly the problem you're describing. > >The reason is that currency is best handled by some form of >arithmetic that works with discrete quantities, while floats are >intended to be used with continuous quantities (like scientific >and engineering measurements). > >There's a floating decimal package in 2.4 that is intended >to eventually (in 2.5 maybe?) be the base of a currency >package. However, that doesn't help today. @$#,###.## import decimal I believe wil be the syntax for getting at it ;) Art From arien_malec at yahoo.com.REMOVE Wed Aug 25 13:26:17 2004 From: arien_malec at yahoo.com.REMOVE (Arien Malec) Date: Wed, 25 Aug 2004 17:26:17 GMT Subject: PEP318: radical notion References: <412a4222$0$293$626a14ce@news.free.fr> Message-ID: Michael Sparks wrote in news:cgi4vh$4q7$1 at nntp0.reith.bbc.co.uk: > Arien Malec wrote: > ... >> Is there a valid use case that supports arbitrary magical >> non-metadata transformations of standalone functions? > > 2 use cases (in addition to others people have mentioned) I can think > of off the top of my head: > * Adding call tracing to specific functions without disturbing the > code. > * Wrapping generator functions so that they can recieve data in an > IPC manner. PEP318 = AOP by another name? I can think of a couple of workaround for the issue you raise: 1) Allow a "module metaclass" -- something that can intercept function defs at a module level, read metadata, and apply necessary transformations 2) Have a default class that standalone functions are static members of, which can have a default metaclass associated with it. I personally think that separating metadata from transformations is a much cleaner approach than using the transformation implementation for everything. Arien From h.b.furuseth at usit.uio.no Tue Aug 31 22:07:47 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 01 Sep 2004 04:07:47 +0200 Subject: string.maketrans().lower() Message-ID: I have a translation table from tr = string.maketrans(...) and want a table which produces the same characters lowercased. `tr.lower()' works - at least with Python 2.3 - but is that will that remain reliable? Or should I use something like this? string.maketrans("".join(map(chr, xrange(256))), "".join(map(chr, xrange(256))).translate(tr).lower()) BTW, is there a simpler way to write "".join(map(chr, xrange(256)))? -- Hallvard From ajsiegel at optonline.com Wed Aug 25 10:17:51 2004 From: ajsiegel at optonline.com (Arthur) Date: Wed, 25 Aug 2004 14:17:51 GMT Subject: Are decorators really that different from metaclasses... References: Message-ID: On Tue, 24 Aug 2004 23:38:28 -0400, Paul Morrow wrote: >Well, what I proposed there is more substantial than this, and requires >a more significant change to the Python system to accomodate. > Someone opined, I think in this thread, that the fact that the only current alternatives to "fix" the problem that alpha 2 syntax addresses are so so-so, by almost everybody's standards, indicates a deeper "bug" in Python. Athony seems to consider the current placement of the doc string a "bug". So there is at least *something* here. My sense is that you are trying to zero in on it, before Python commits itself to a workaround. It would be selling Guido short to think that we has not considered all this. On the other hand, he has not communicated much about it - so it is hard to know for sure. So I wish you luck in the digging. Art From bart_nessux at hotmail.com Thu Aug 19 21:52:33 2004 From: bart_nessux at hotmail.com (Bart Nessux) Date: Thu, 19 Aug 2004 21:52:33 -0400 Subject: stopping windows services Message-ID: Can Python be used to stop windows services? I'm writing a script to automaically remove some troublesome Symantec software, but before running the main removal script, I need to kill some services. Thanks, Bart From squirrel at WPI.EDU Tue Aug 10 16:28:51 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 10 Aug 2004 16:28:51 -0400 Subject: decorators vs GIL In-Reply-To: References: <0bidnfbR2_PZOIjcRVn-pA@giganews.com> Message-ID: On Tue, 10 Aug 2004, Daniel Dittmar wrote: > Christopher T King wrote: > > The real reason behind the GIL is that the Python interpreter is not > > re-entrant; it keeps internal state in a global structure > > Another reason is reference counting, which must be synchronized. Forgot about that; a global reference count lock might work well, but this could negatively impact performance in the case of things like argument tuples. Perhaps internal objects that are guaranteed to be thread-local can skip the reference-count-locking step, but I'm not sure how many (if any) objects can guarantee this. From jess.austin at gmail.com Fri Aug 27 20:35:33 2004 From: jess.austin at gmail.com (Jess Austin) Date: 27 Aug 2004 17:35:33 -0700 Subject: Are decorators really that different from metaclasses... References: <412D9F1E.6000809@yahoo.it> Message-ID: Paul Morrow wrote in message news:... > Nope, that was me alright. I don't want a function to have access to > it's metadata. Nothing's changed about that. I want to be able to > specify a function's metadata inside the function def, where it seems to > most appropriately belong. So you have: def foo(x): __meta_variable__ = 42 variable = 5 return dir() And you're volunteering to explain to a newbie, or even a nearly intermediate programmer like myself, why the list that is returned from this function contains 'x' and 'variable' but not '__meta_variable__'? I'm sorry, but this is unreadable and is a dramatic break from Python convention. A variable binding inside a block is available in that block and in contained blocks (method blocks aren't properly understood as being contained within the class block), after the statement setting the variable has executed. A variable defined inside a block is not available outside it without indexing through another binding created by an import or class statement. This makes Python code easy to read. You propose to turn this on its head for a particular class of variables defined within function blocks. No amount of reasoning or argumentation will justify such a maneuver. > Others seem to want to specify a function's metadata outside of the > function def, which just doesn't seem pythonic (IMO). If you really understood Python's scoping rules, you would know that this opinion is the opposite of the truth. Of all the current incarnations of function "metadata", only one may be set within the function, and that one is not set using a standard binding statement: >>> def bar(): ... """docstrings are the exception not the rule""" ... __meta_doc__ = """Please don't assume otherwise""" ... >>> dir(bar) ['__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__get__', '__getattribute__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name'] In the returned list, only '__doc__' was affected by characters in the function suite, and those characters did not comprise a binding statement within the function block. So in this respect '__doc__' is not an exception to the rules about name binding in function blocks either. I think you're getting confused via a false analogy between function blocks and class blocks. It's true that bindings set within a class block are accessible through class or instance objects. This stateful binding access is what is fundamental about classes, while operator-associated method names are sugar, or "magic" if you prefer. Function block binding statements are instructions for function _execution_, class block binding statements are instructions for class _creation_, and there's the difference. Any meta-meaning that the actual name used in a binding statement might have is purely incidental, in that the function or class is created in the same fashion whether a given name has a magic meaning or not. Certain multiple-underscore names do change the behavior of a class, but only one relatively hackish name (__metaclass__) changes how it is created. Class statements have to deal with creation because they have state, thus they must have an initial state. Functions do not have state, although the objects we use to access them (function or generator objects) from the _outside_ do. It seems hard to support pushing bindings with persistent state into the function block when it has never had this before. I appreciate your persistence in error; it has provided me with the opportunity to gain knowledge in an area about which I previously had only intuition. b-) In broader commentary, as I've said, pep318 isn't really about metadata. One reason is that metadata isn't that important. Data only needed by an outside system should be kept there. If any layer of code uses particular data, that layer should be responsible for maintaining such. Python already accomodates this more correct style of information management, and pep318 might increase this accomodation. yours, Jess From arien_malec at yahoo.com.REMOVE Fri Aug 13 12:38:32 2004 From: arien_malec at yahoo.com.REMOVE (Arien Malec) Date: Fri, 13 Aug 2004 16:38:32 GMT Subject: PEP 318 decorators are not Decorators References: Message-ID: "Daniel Dittmar" wrote in news:cfhsri$a1q$1 @news1.wdf.sap-ag.de: > Arien Malec wrote: >> decorator. One of the issues is that the Decorator pattern is more > > The term decorator as used in the current discussion comes from compiler > writing. You have a syntax 'tree' which gets 'decorated' with additional > attributes. 1) That's not mentioned in PEP 318 2) That's in disagreement with http://www.python.org/moin/PythonDecorators 3) Won't most programmers think GoF decorators before compiler syntax tree decorators? Arien From antoinemaillard at free.fr Mon Aug 2 05:34:55 2004 From: antoinemaillard at free.fr (Antoine Maillard) Date: Mon, 2 Aug 2004 11:34:55 +0200 Subject: building python extensions for windows : python23_d.lib file is missing Message-ID: <410e0b05$0$1895$636a15ce@news.free.fr> Hi We're looking to make our own python modules for windows Python 23. We use swig and Visual Studio C++ for making the dlls. But when trying to compile, it says it's been missing a "Python23_d.lib" file. According to the tutorial we did (http://www.geocities.com/foetsch/python/extending_python.htm#abstract), it's a problem with the fact we use the release version of python and not a d?bug version. But we don't know how to go through this (perhaps recompiling a debug version ... but we don't know how to do). Did someone get this problem and walk throug it ? Thanks for your help Antoine Maillard & Andr? Garenne From reinhold-birkenfeld-nospam at wolke7.net Fri Aug 13 03:29:00 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Fri, 13 Aug 2004 09:29:00 +0200 Subject: {SPAM?} Decorators? Why have a special construct to support a pattern? In-Reply-To: References: Message-ID: <2o38d8F6b1veU2@uni-berlin.de> Simon Wittber wrote: > Decorators... > > Why do we need a special construct to support a pattern? > > Do lots of people really use decorators that often? I think that with decorators available, their usage will greatly increase. With having to write foo = decorator(foo), I daresay nobody got the idea to write function-wrappers that function like this. Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From greg at cosc.canterbury.ac.nz Mon Aug 16 23:49:47 2004 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Tue, 17 Aug 2004 15:49:47 +1200 Subject: Wink-decorator? (Re: [OT] Keyboard layout, was Re: PEP318) In-Reply-To: <1092455506.274331@yasure> References: <1092455506.274331@yasure> Message-ID: <2oddirF9gl5iU1@uni-berlin.de> Donn Cave wrote: > Quoth Michael Hudson : > ... > | Huh? On *my* mac @ is shift-2 and # is option-3. > > What kind of keyboard has a key for @? Aha! Folks have been calling it a "pie" here, but maybe the @ in @decorator is secretly meant to represent a wink? That would explain a lot... -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From insert at spam.here Fri Aug 6 13:54:45 2004 From: insert at spam.here (Doug Holton) Date: Fri, 06 Aug 2004 12:54:45 -0500 Subject: compromise? keywords for static/class, move decorators to top of function Message-ID: First let me say please see the wiki page about python decorators if you haven't already: http://www.python.org/cgi-bin/moinmoin/PythonDecorators I propose (and others have) that built-in features have keyword support, like static and class methods. Also, I believe it is more readable if decorators, especially longer ones, are moved to the top of the function body, just like docstrings, instead of coming before the function is even declared. Whether you use @ or [] is still open. def classmethod getratio (arg1, arg2): @accepts(int,int) @returns(float) ... def classmethod getratio (arg1, arg2): [accepts(int,int), returns(float)] ... This has these advantages: the function declaration itself is still the first and most important thing, decorators are indented just like the body of the function so it is more clearly a part of the function. In the future though, if you add an "as" keyword for adapters, you could just say: def classmethod getratio (arg1 as int, arg2 as int) as float: ... contrast that simple example with this, which is kind of ugly: @accepts(int,int) @returns(float) @classmethod #has to be last in order? def getratio (arg1, arg2): ... From da_rosser at yahoo.com Mon Aug 2 11:27:35 2004 From: da_rosser at yahoo.com (Doug Rosser) Date: 2 Aug 2004 08:27:35 -0700 Subject: Mucking with the calling scripts namespace (For a good reason, honest!) Message-ID: I'm writing a fairly complicated test framework and keeping configuration data inside ini files that are parsed at runtime by the ConfigParser module. For example, there would be a section similar to the following [servers] server1:{'hostname':'alpha','os':'posix'} server2:{'hostname':'beta','os':'win'} [clients] client1:{'hostname':'ichi','os':'posix'} client2:{'hostname':'ni','os':'posix'} As I read the configuration file, I don't actually create instances, but use the data to check "what's out there" to make sure the physical network environment has the bits and pieces required to run a particular test. This is a sort of "go/no-go" resource check. Assuming that everything is correct with the physical network environment, I want my testers to be able to refer to these resources in their python scripts by the names in the ini file, like so: myTest.checkResources() # Read the config file and associate names with real # life instances server1.doSomething() # Note how I have cleverly saved myself from declaring # "server1" because the module myTest has inserted # it into the right namespace :-) Down to business: How do I write a module that can insert these names into the calling script's namespace at runtime? Is this even possible in Python? da rosser -- We are the music makers, and we are the dreamers of dreams -- From peter at engcorp.com Fri Aug 6 11:37:07 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 06 Aug 2004 11:37:07 -0400 Subject: [Newby question] List comprehension In-Reply-To: References: Message-ID: Hallvard B Furuseth wrote: > Eelco Hoekema wrote: > >>Batista, Facundo schreef: >>>Now, explain me why a list comprehension is better here. >> >>Are they better? Don't know. In Dive into Python, Mark Pilgrim states >>compared to list comprehensions, for loops are a waste of time. Not >>sure what he means by that, though. > > List comprehensions are faster. Time for the old refrain "Premature optimization is the root of all evil in programming." (Knuth) List comprehensions may be faster, but that is never a valid reason, in isolation, for choosing one construct over another. If (a) list comprehensions can't do this, or (b) one has to jump through hoops and make the construct completely unreadable to make it work, then list comprehensions are completely unsuited to the task at hand. A loop, on the other hand, works just fine and is very readable. Use a loop. -Peter From mharlow-dated-1093786836.bbea92 at grephead.com Thu Aug 26 10:11:58 2004 From: mharlow-dated-1093786836.bbea92 at grephead.com (matt okeson-harlow) Date: Thu, 26 Aug 2004 14:11:58 -0000 Subject: Am I on the right path References: Message-ID: On 2004-08-25, Batista, Facundo wrote: > [ADE] > > #- The program is supposed to randomly choose an ip address and > #- try and make a > #- conection on port 80 > > You can generate random IP like this, also: > >>>> import random >>>> '.'.join([str(random.randint(0,255)) for x in range(4)]) > '168.240.211.252' [snip] to keep from duplicating ips... import random def newip(): ip = '.'.join([str(random.randint(0,255)) for x in range(4)]) return ip oldip = {} for i in range(10): ip = newip() if not oldip.has_key(ip): print ip oldip[ip] = 1 -- matt okeson-harlow http://technomage.net From steven.bethard at gmail.com Tue Aug 31 04:53:59 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Tue, 31 Aug 2004 08:53:59 +0000 (UTC) Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Paul Morrow yahoo.com> writes: > Actually, these look like assignments to local *magic* variables. > There's the difference. The double underscores before and after each > name loudly proclaims that these variables are not like 'normal' > variables. They're special in some way. That's a Python convention. Note that you're asking for __xxx__ variables to be assignments to the function's attributes even though they're in the part of the function that gets executed when the function is *called*. Let's look at what examples of this behavior might look like for some different objects. # in the part of a function that is executed when the function gets called def f(): __author__ = 'Steve' # in the part of a class that is executed when the class gets called class S(object): def __new__(cls): __author__ = 'Steve' # in the part of an object that is executed when the object gets called class T(object): def __call__(self): __author__ = 'Steve' Note that the parallel I'm trying to draw here is that in each of these cases, the __author__ is assigned to in the part of the definition that gets executed when the object is *called*. Thus f(), S(), and T()() all execute the code block containing the __author__ assignment. Presumably you wouldn't want the __author__ statements to assign to the class or the object in the second two examples? Of course, what you really want is for these things to be assigned to in the part that gets executed when the object is *defined*. For a class, this is clearly: class S(object): __author__ = 'Steve' But what gets executed when a function is defined? Just the def statement, the binding of the function name to its body. To be consistent with classes then, your assignment to __author__ should be *in* the def statement. So what you're suggesting, basically, is that the def statement should be extended to include any __xxx__ assignments following the docstring. Extending the def statement is not unreasonable, but IMHO it should be clear that the extensions to the def statement are part of that statement. There's nothing in current Python semantics that would suggest that any assignments in a funcdef are part of the def statement. Note that even docstrings, which could be reasonably argued to be part of the function definition, cannot be included in the def statement by assignment: >>> def f(): ... __doc__ = "f" ... >>> print f.__doc__ None Certainly __xxx__ variables are special in some way. But are they special in the way you want them to be? AFAICT, *assignment* to __xxx__ variables is never what does the magic. The magic is done when the Python interpreter reads the *values* of those variables. The variables continue to exist in whatever namespace they were created in -- AFAICT, current Python __xxx__ variable assignments never cause __xxx__ variables to change namespace. I seems like you want to introduce a substantially new semantics to an already existing syntax. This creates ambiguity... Ambiguity bad. Bad, Ambiguitiy, bad! No biscuit! ;) Steve From guettli at thomas-guettler.de Thu Aug 19 10:08:34 2004 From: guettli at thomas-guettler.de (Thomas Guettler) Date: Thu, 19 Aug 2004 16:08:34 +0200 Subject: apache 2 & python References: Message-ID: Am Thu, 19 Aug 2004 00:42:26 +0200 schrieb Krzysztof Drozd: > how to configure apache 2 to work with python or mod_python? You can use SCGI: http://www.mems-exchange.org/software/scgi/ The docs says it is not well tested for apache2, but I had no problems, after I realized that you need to set "SetHandler scgi-handler". HTH, Thomas From greg at cosc.canterbury.ac.nz Tue Aug 24 00:52:05 2004 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Tue, 24 Aug 2004 16:52:05 +1200 Subject: Overriding logical operators? In-Reply-To: References: <59e9fd3a04082022392b749256@mail.gmail.com> Message-ID: <2ovvrmFcu6r6U1@uni-berlin.de> Terry Reedy wrote: > I think > we need a special term in Python also, such as 'pseudo-op' or 'syntax > operator' to flag 'and' and 'or' as importantly different from regular > operators. They're really control structures, like 'if' and 'while'. The fact that they happen to look a bit like operators is purely coincidental... -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From peter at engcorp.com Thu Aug 26 01:31:25 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 26 Aug 2004 01:31:25 -0400 Subject: Inline Conditionals? In-Reply-To: References: Message-ID: Joshua Ginsberg wrote: > Is there any plan to include inline conditionals in Python? For example: > > def isNegative(x): > return x < 0 ? True : False This is a FAQ: http://www.python.org/doc/faq/programming.html#is-there-an-equivalent-of-c-s-ternary-operator Newbies, please consider reading the several FAQs that you will find at http://www.python.org/doc/faq/ before posting questions which might be answered there (i.e. just about anything). -Peter From usenet at datahansa.com Mon Aug 2 07:32:54 2004 From: usenet at datahansa.com (Oleg Paraschenko) Date: 2 Aug 2004 04:32:54 -0700 Subject: Percentage matching of text References: <1678860800.20040730075239@MailBlocks.com> Message-ID: Hello Bruce, Bruce Eckel wrote in message news: > ... > What I'd like to do is find an algorithm that produces the results > of a text comparison as a percentage-match. > ... > Does anyone know of an algorithm or library that would do this? > Thanks in advance. > I suggest you to look at my software, GetReuse and its SDK: http://getreuse.com/ http://getreuse.com/sdk/ The formula for the calculation of the similarity is based on the scientific research. Any other "good" method of calculations should produce results that are equivalent in some terms to the GetReuse results. I have not wrote a paper yet; the formula is a improvement of the formula from http://www.cs.ucsb.edu/~mli/sid.ps . Unfortunately, I froze the project but the current code is tested and should work well. > Bruce Eckel > Bruce at EckelObjects.com Regards, Oleg From sholden at flexal.cs.usyd.edu.au Tue Aug 31 07:07:41 2004 From: sholden at flexal.cs.usyd.edu.au (Sam Holden) Date: 31 Aug 2004 11:07:41 GMT Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> <87hdqok9i6.fsf@sinken.local.csis.hku.hk> <1rfz68ely9.fsf@rovereto.ifi.uio.no> <876574k7du.fsf@sinken.local.csis.hku.hk> <1r3c28ejis.fsf@rovereto.ifi.uio.no> <1rllg0cb3m.fsf@rovereto.ifi.uio.no> <874qmovxna.fsf@sinken.local.csis.hku.hk> Message-ID: On 31 Aug 2004 10:33:07 GMT, Antoon Pardon wrote: > Op 2004-08-28, Isaac To schreef : >>>>>>> "Kjetil" == Kjetil Torgrim Homme writes: >> >> Kjetil> after all, code in _any_ language written by a >> Kjetil> professional will have strict indentation. so it's just >> Kjetil> syntax. >> >> No. In all other languages, people deal with *two* ways to find which >> statement is associated with an if/while/for/whatever statement and >> which is not: by looking at the indentation, and by looking at the >> braces. They normally look at the indentation, since it is the >> quicker way. But when they find something wrong, they look at the >> defining braces, sometimes deeply hidden in long expressions and >> statements combined into one line. In Python, we have *one and only >> one* way to find which statement is associated with an >> if/while/for/whatever statement, and this is the quicker way that >> people are used to. > > I doubt that. > > I used to limit myself to indentation to see which code belonged > to which control. But then I found myself witch controls that > were so nested it was hard to see to which if a particular > else suite belonged and I started to use end markers in comments > to make the structure more visible. Deep nesting is a bad sign in itself, regardless of how a language specifies block structure. Making the code readable by removing the unreadable nesting seems a far better solution than adding end markers. -- Sam Holden From sbabbitt at commspeed.net Mon Aug 9 18:17:07 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Mon, 9 Aug 2004 15:17:07 -0700 Subject: Best pattern/idiom References: <4117c3d8$1@buckaroo.cs.rit.edu> Message-ID: <1092090235.791348@news.commspeed.net> "Chris Connett" wrote in message news:4117c3d8$1 at buckaroo.cs.rit.edu... " [ lis[n:n+4] for n in range( 0, len( lis ), 4 ) ] > which seems very kludgy to me, since it uses a range and len, " range and len are kludgy only to non-python programers. Tom From anthonybaxter at gmail.com Fri Aug 20 04:35:50 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 20 Aug 2004 18:35:50 +1000 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: On Fri, 20 Aug 2004 03:37:12 -0400, Nicolas Fleury wrote: > - Not Pythonic. It's a line without a block (like try/finally) that > affects a following line of code. It breaks interactive shells. I've seen this mentioned a couple of times, but as far as I can see, it's really not true: >>> def noop(func): ... return func ... >>> def funcattr(**kwdict): ... def _deco(func, kwdict=kwdict): ... for k,v in kwdict.items(): ... setattr(func,k,v) ... return func ... return _deco ... >>> @noop ... @funcattr(foo=1,bar='bozo',bing=['b','o','n','g']) ... def testfunc(whatever): ... pass ... >>> print testfunc.foo 1 >>> print testfunc.bar bozo >>> print testfunc.bing ['b', 'o', 'n', 'g'] > [ snip - decorate block before def ] > This proposal has basically the advantages of @decorators with a more > Pythonic approach. The main drawback is that the decorate block doesn't > contain anything like normal statements, as with @decorators. > Implementation already exists. Note that the implementation, as far as I know, is not yet complete - it doesn't include the from __future__ stuff. I don't know much about that area of the implementation, so can't offer an opinion on how hard that is. The implementation also doesn't seem to have been submitted as a patch to SF. This needs to be done. > Proposal 2: > > def foo(a,b): > using staticmethod This form (decorators inside the block) has been pretty convincingly ruled out by Guido. I think the "last man standing" is the decorator-before-def form, I really doubt you're going to convince people that the form inside the function is workable. From squirrel at WPI.EDU Fri Aug 13 16:03:24 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Fri, 13 Aug 2004 16:03:24 -0400 Subject: Why I love python. In-Reply-To: References: Message-ID: On Fri, 13 Aug 2004, kosh wrote: > On Friday 13 August 2004 1:34 pm, Christopher T King wrote: > > On Fri, 13 Aug 2004, kosh wrote: > > > Why is there a need for a stand alone executable? At least on all the > > > unixes whether something is executable is just determined by the > > > executable bit on the file. > > > > Not if you don't have the interpreter installed. > > So install the runtime. If you want to run the .NET stuff you need to > have the the .NET CLR or Mono installed. If you want to run java apps > you need the jvm etc. And if you want to run Python scripts you need the Python interpreter installed. > Overall once a runtime is installed it makes distributing apps a lot > easier since the actual thing you need to send someone is tiny. Oftentimes users will only have one Python app. They'd much rather download a 2MB ZIP file and dump it somewhere, than download a 20MB Python distribution and install it somewhere, download XMB of extension modules needed by the app (e.g. PIL, numarray, to name a few), and then finally download and install your script. > Also at least on unixes I have not run into a box in about 6 years or so > that did not have python and perl installed so in practice I have not > run into that problem. And hence the lack of an executablization program for Unix. > Overall it would be better if there was an easy way on windows to get the > runtime installed since then you can send users far smaller files, smaller > updates and it makes it easier for people to patch their systems. True. I don't see that happening anytime soon, though. > I have seen more then a few cases where a bug like temp file creation > was found to be a problem in python and in some c code. However the > difference is that you can update the python runtime and all affected > python programs are fixed. The same is not true of the c versions. What? C programs use a runtime library, just the same as any other language. Google for "libc.so" or "msvcrt.dll" if you don't believe me. > One of them I have run into which is a pain is stuff like openssl. When that > gets updated it seems a whole bunch of programs have to be compiled to work > with it again. The change is source compatible but for whatever reason the > bug fix breaks binary compatibility on a number of apps. That sounds like an openssl-specific problem, perhaps relating to configuration issues. Since C libraries are linked dynamically, source compatibility inherently translates to binary compatibility, assuming functions were not moved to different libraries or rewritten as macros (or vice-versa). In a perfect world, all OSes would use proper package management systems, and single-executable programs would not be needed. Unfortunately, this isn't true. From reinhold-birkenfeld-nospam at wolke7.net Fri Aug 13 14:03:39 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Fri, 13 Aug 2004 20:03:39 +0200 Subject: Why I love python. In-Reply-To: References: <411C8CD9.32F39C2@mega-nerd.com> <411C93B2.2027B48B@alcyone.com> Message-ID: <2o4divF6one2U1@uni-berlin.de> Nick Patavalis wrote: > On 2004-08-13, Erik Max Francis wrote: >> Erik de Castro Lopo wrote: >>> >>> Its called type inferencing and since there is at least one working >>> implementation, it can't be THAT hard. >> >> That's actually the kind of thing that is planned for Python with >> Starkiller, however silly a project name that might be. >> > > Correct me if I'm wrong, but I thing that starkiller produces > optimized code (i.e. native code) only if it can unambiguously > inference the types a-priori, and there are cases (in a dymanically > typed language like python) where this is impossible. In these cases, > I believe, starkiller does nothing. Are there any plans for treating > such cases? And how? I think the dynamic nature does make it impossible to do anything in such cases at the first place. Consider: klass = raw_input() classobj = eval(klass + "()") print classobj.whatami A compiler can tell absolutely _nothing_ about the resulting class object since typing information is not contained in the program. One would have to tell the "compiler" explicitly which types the variable will be allowed to hold, such as: klass = raw_input() classobj as (FooObject, BarObject, BazInterface) = eval(klass + "()") print classobj.whatami But that requires "typed Python" extensions, and as such isn't pure type inferencing any more. Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From fortepianissimo at gmail.com Mon Aug 2 13:40:24 2004 From: fortepianissimo at gmail.com (fortepianissimo) Date: 2 Aug 2004 10:40:24 -0700 Subject: module timeit and variable scope Message-ID: <78aed1f3.0408020940.7630b894@posting.google.com> A couple questions about using timeit to record the CPU time consumed by an instance method: 1. What are the advantages of using timeit compared to using time.time() or time.clock()? (on Mac OS X) 2. How do I introduce a variable into the timeit.Timer? For example I have a class Foo: class Foo: def __init__ (self): # the following line didn't work because the scope is not # the calling function # self._timer = timeit.Timer(stmt='self.run(bar)') pass def someMethod (self, bar): print bar def run (self, bar): # call self.someMethod(bar) and record time using # self._timer pass and I want to record the CPU time consumed by someMethod in method run(), using the timer initialized in __init__(). The reason to set up the timer in __init__ is to avoid overhead of setting up the same timer time and time again in run(). Thank you. From http Fri Aug 20 14:44:00 2004 From: http (Paul Rubin) Date: 20 Aug 2004 11:44:00 -0700 Subject: decorator J4 - any objections? References: Message-ID: <7xbrh5hcpb.fsf@ruckus.brouhaha.com> JimJJewett at yahoo.com (Jim Jewett) writes: > (section 5.21 J4) > > looks very good to me -- and it is the only alternative without negatives. > > def func(arg1, arg2) > @version("Added in 2.4") > @returns(None) > as: > """Docstring could be here, or in decorator part above""" > # body goes here What was wrong with using . or - instead of @ ? Given that this is new syntax, just about any character could work. Or what about no special punctuation at all? Using @ makes me cringe somewhat. Also, why the need for the "as" keyword? What happens if it's just eliminated? I.e.: def func(arg1, arg2) @version("Added in 2.4") @returns(None): """Docstring could be here, or in decorator part above""" # body goes here From beliavsky at aol.com Mon Aug 9 08:48:05 2004 From: beliavsky at aol.com (beliavsky at aol.com) Date: 9 Aug 2004 05:48:05 -0700 Subject: Paul Graham on Python hackers References: Message-ID: <3064b51d.0408090448.31806af5@posting.google.com> Kirk Job-Sluder wrote in message news:... > In previous writings Graham tends to focus more on language fundamentals > rather than the scope of features or the process of compilation. Python > is closer to Java in that they are both strongly Object Oriented languages in > contrast to perl's OO framework that feels more bolted on than integral > to me. Python, unlike Java, does not force OOP upon you -- it can be treated as an imperative language. I think this is a plus especially when first learning the language or writing small programs. A Hello World program is just print "Hello, World" rather than class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); //Display the string. } } Python to me is a multi-paradigm language (imperative, OO, functional, generic), like C++ but interpreted and with dynamic typing. From kjetilho at yksi.ifi.uio.no Fri Aug 27 09:42:54 2004 From: kjetilho at yksi.ifi.uio.no (Kjetil Torgrim Homme) Date: Fri, 27 Aug 2004 15:42:54 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> <87hdqok9i6.fsf@sinken.local.csis.hku.hk> Message-ID: <1rfz68ely9.fsf@rovereto.ifi.uio.no> [Isaac To]: > > If the aim is simply to do a local change that is sufficient to > deal with the problem just in your computer, then the simplest > answer might be to use "pass": if your code contains > > if t1 == t2: > t1 = t3 > else: > t2 = t3 > pass > t = t2 > > and you tab at the last line, Emacs won't try to indent the t=t2 > line further to after the pass line where it is impossible to > execute. interesting idea, but Python won't discover inconsistencies. if only an Emacs solution is sought, a "# end" convention is preferable since it's more explicit. an explicit convention that Python recognises would be even better. > If you want something that is done globally and everybody will use > it... not a chance. I don't expect everybody to use it. miscellaneous projects where the developers are comfortable with it might want to add it to their coding standards. -- Kjetil T. From in.aqua.scribis at nl.invalid Tue Aug 17 19:39:43 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Wed, 18 Aug 2004 01:39:43 +0200 Subject: flex: plex? In-Reply-To: References: Message-ID: David M. Cooke schreef: > If you've been using Flex, you might want to check out FlexModule at > > which allows you to use Flex to generate a lexer callable from python. I have tried it. (Had to edit the Makefile by hand, because "make -f Makefile.pre.in boot" did not produce a valid Makefile, but I did manage to build and run the example.) The problem is, the Flex file (and Yacc file) is compiled into C, and then into a shared lib. This means I must use C code in the Flex file. What I want is something that lets me call arbitrary Python code from the lexer. Ideal would be to have a version of Flex that produces a Python file instead of a C file. I have kept looking, and I think I found what I was looking for: PyLly, which is part of PyGgy. http://www.lava.net/~newsham/pyggy/ -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From kosh at aesaeion.com Fri Aug 13 16:21:34 2004 From: kosh at aesaeion.com (kosh) Date: Fri, 13 Aug 2004 14:21:34 -0600 Subject: Why I love python. In-Reply-To: References: Message-ID: <200408131421.34307.kosh@aesaeion.com> On Friday 13 August 2004 2:19 pm, Nick Patavalis wrote: > On 2004-08-13, kosh wrote: > > Why is there a need for a stand alone executable? At least on all the > > unixes whether something is executable is just determined by the > > executable bit on the file. I can execute a python program just as > > transparently as one in compiled c, c++, etc. I really don't see the > > point of that. > > Perhaps you target system has no Python environment installed. And > perhaps it has no resources to have a complete python environment > installed (appart from the fact that it might not need one). Don't > think of your 2GHz / 512MB desktop. Think of your cell-phone. Cell phones should be cell phones not multifunction device that can run all kinds of apps, need virus scanners etc. I don't want my cell phone to run python, java, ruby, c# etc etc. I want it to just be a telephone and do that job well. Most of the modern cell phones are crap if you want all of that stuff get a pda and get a virus scanner for it. From apardon at forel.vub.ac.be Tue Aug 17 04:38:48 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 17 Aug 2004 08:38:48 GMT Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> <30260531.0408131853.18ec2446@posting.google.com> <3ke1i05c3cq93vhdmdigj3pudru9n99a4j@4ax.com> Message-ID: Op 2004-08-16, Peter Hansen schreef : > Richard Hanson wrote: >> For me, a not insignificant part of Python's genius *is* the >> indentation. When I used C and C++ I was a stickler (pedant? :-) >> ) for "proper" indentation -- which was a PITA. So -- I took to >> Python's indentation like a duck to water. > > That's been exactly my situation as well, which leads me to > theorize that those who react most strongly against Python's > syntactically significant indentation are those who were the > least consistent or, uh, "anal" about making sure their code > conformed to conventions. > > The corollary would be that those who already wrote code which > would have been accepted by a compiler which checked indentation, > are those who hardly blink when encountering Python, > other than to say "Of course!" as you did, and carry on writing > code just as they used to, with a mild feeling of dismay that > it never occurred to them before to question the supposed > value of braces or begin/end tags. I think both have their value. I still prefer modula2 style. No begin (*) tags as the block is automtically started by any compound statement so you only needed an end tag. My experience is that proper indentation end end tags makes for the best readabilty, better than either of them on their own. And mostly I add comments to the end tags to better see what control structures they end. (*) This is not strictly true, there is a begin tag but that was only used to start the body of a procedure or module, not for compound statements. -- Antoon Pardon From gohaku at earthlink.net Thu Aug 12 14:37:55 2004 From: gohaku at earthlink.net (gohaku) Date: Thu, 12 Aug 2004 14:37:55 -0400 Subject: Import command In-Reply-To: <20040812182143.8CC921589E@net.tamu.edu> References: <20040812182143.8CC921589E@net.tamu.edu> Message-ID: On Aug 12, 2004, at 2:21 PM, Yong Wang wrote: > When I run the codes, I get the following error though I have > inserted import snmpPP > sources path (/home/yong3/nd3/Modules): > > >> cisco werc-2950t-1 > sys path is ['', '/home/yong/nd3/Modules', > '/usr/local/lib/python1.5/', '/usr/local/lib/python1.5/plat-sunos5', > '/usr/local/lib/python1.5/lib-tk', > '/usr/local/lib/python1.5/lib-dynload'] > Traceback (innermost last): > File "cisco", line 10, in ? > import snmpPP > ImportError: ld.so.1: /usr/local/bin/python: fatal: relocation error: > file /usr/local/lib/libreadline.so: symbol tputs: referenced symbol > not found > How should I fix the import problem ? > Thanks a lot. > what is the filename of the script you are trying to run? I get the feeling there's a filename conflict in case your script's filename is snmpPP.py From mensanator at aol.com Wed Aug 18 16:17:44 2004 From: mensanator at aol.com (mensanator at aol.com) Date: 18 Aug 2004 13:17:44 -0700 Subject: age of Python programmers Message-ID: Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... 50. Python appreciation is probably proportional to age. I can't top the stories from the guys with the relays, but ... Saw an Apple ][ in a computer store in fall '77, but couldn't afford to buy one until Feb '78. In anticipation, I got the classic book "Basic BASIC" and learned BASIC on a GA SPC-16. My first real program was based on the card game "Nuclear War". Trouble was, it had to be played on a teletype. From ville at spammers.com Mon Aug 23 14:00:55 2004 From: ville at spammers.com (Ville Vainio) Date: 23 Aug 2004 21:00:55 +0300 Subject: J2 decorator grammar References: <2orckjFdtljaU1@uni-berlin.de> Message-ID: >>>>> "Francois" == Fran?ois Pinard writes: Francois> I'm not especially crusading for `with', but it has the Francois> advantage that it will likely become a keyword in some Francois> later version of Python, and likely also, will be used Francois> in `with SOMETHING:' and not barely as `with:'. Francois> Reserving a keyword is a lengthy process, like it was Francois> demonstrated by the progressive implementation of Francois> `yield'. So using `with' here would be a nice Francois> investment for the future in that regard. If that is an advantage rather than drawback (i.e. BDFL doesn't disagree w/ 'with' having a dual purpose), I'm all for 'with'. The less keywords we have, the better. -- Ville Vainio http://tinyurl.com/2prnb From fuzzyman at gmail.com Wed Aug 11 04:18:21 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 11 Aug 2004 01:18:21 -0700 Subject: ClientCookie Message-ID: <6f402501.0408110018.1e4e5ca8@posting.google.com> Has anyone used ClientCookie to store cookies ? I'm going to play around with 'pickling cookies' - but I wondered if anyone had any experience of this. (For session persistence in approx - my cgi proxy) Regards, Fuzzy http://www.voidspace.org.uk/atlantibots/pythonutils.html From CousinStanley at HotMail.Com Thu Aug 12 22:19:59 2004 From: CousinStanley at HotMail.Com (Cousin Stanley) Date: Thu, 12 Aug 2004 19:19:59 -0700 Subject: Pyhton Interpreter Startup time References: Message-ID: <2o2mijF62hrkU1@uni-berlin.de> | .... | This primitive test shows these results on a Windows XP machine | ( it won't work with Windows 98 | as it can't chain commands | on the command line like that, | but you could but it in a batch file ). | .... I stuck it in a .bat file under Win98_SE on the same dual-boot machine that I used for the Linux/Debian test .... Win98_SE .... Python 2.3 Enthought Edition Debian ...... Python 2.3.4 < K:\C\MinGWStudio\Samples\Time\Debug > Thu 08-12-2004 18:49:03.23 py_time Number of Seconds Since January 1, 1970 .... 1092361745 1092361746.75 The Linux/Debian number is only slightly quicker with Python 2.3.4 and probably given a larger number of tests, there might be no significant difference .... Number of seconds ......... 1092323003 Python .................... 1092323003.36 So, for an old 250 MHz machine, I seem to be loading Python OK for both Win98 & Linux .... -- Cousin Stanley Human Being Phoenix, Arizona From martin at v.loewis.de Thu Aug 19 02:17:32 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 19 Aug 2004 08:17:32 +0200 Subject: cant install from source on MSWindows In-Reply-To: References: Message-ID: <412445f3$0$198$9b622d9e@news.freenet.de> Darren Dale wrote: > I'm getting the old "need visual studio 6" error message. I have seen > advice to download the free compiler, I tried that and it didnt work. I > have an academic copy of VS.net, tried installing that, and still no > dice. Can somebody tell me how they have been able to get this working? > I would like to start contributing to my favorite plotting package, but > this is really tripping me up. Reportedly, you also can build extensions with Cygwin. Regards, Martin From pm_mon at yahoo.com Tue Aug 17 09:34:26 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Tue, 17 Aug 2004 09:34:26 -0400 Subject: Decorators: an outsider's perspective In-Reply-To: References: <20040814153534.8AC171E4007@bag.python.org> Message-ID: Anthony Baxter wrote: > On Mon, 16 Aug 2004 13:17:42 -0400, Paul Morrow wrote: > >>Q: What if I had a metaclass that would make any method private whose >>name started with two underbars (by, I dunno, mangling the name >>somehow)? Would you consider that a hack too? ;-) > > > Damn straight - that's awful. Why on earth would someone implement > that? > I expected a :-) after your comment (as the behavior I describe is already being performed by the Python system)... > > Sorry, burned out on decorators for now. > That's cool. From heikowu at ceosg.de Wed Aug 11 22:10:52 2004 From: heikowu at ceosg.de (Heiko Wundram) Date: Thu, 12 Aug 2004 04:10:52 +0200 Subject: rsa implementation question In-Reply-To: <1a517b5.0408111636.200f675f@posting.google.com> References: <1092200894.4119a9beb1978@www-mail.usyd.edu.au> <1a517b5.0408111636.200f675f@posting.google.com> Message-ID: <200408120410.52256.heikowu@ceosg.de> Am Donnerstag, 12. August 2004 02:36 schrieb Bryan Olson: > There is a notion of blocks in many public-key ciphers, > including RSA. The modulus n in RSA is composite, not prime. > The "only the notion" statement implies that integer modular > arithmetic is the only base for public-key cryptography, which > is not true. Pardon me, yeah, the modulus is composite, I should've rather said that most public key ciphers work in Z{n}. And I know that it's pretty easy to generalize ElGamal to work in other rings than Z, or take bucket public key cryptography for example. I know of others, but: have you ever seen an implementation or use case of some algorithm not working in Z{n}(*)? I have not, at least not when working with computers. > Try the book you cited, section 11.2.3, Note 11.10, Example > 11.11, and Remark 11.12. > > http://www.cacr.math.uwaterloo.ca/hac/ Yup, I read those, and yeah, I know what they are talking about, and yeah, that's not what I said. It's not about decrypting to sign, encrypting to verify, it's about the redundancy function. In case you use a proper hash function (I'm talking about identity with SHAing before signing), this attack blatantly fails, as it would mean that you'd have to find hash collisions. Even when I can easily find a m~ for which I have a valid signature m, finding a plaintext for m~ which is meaningful should be impossible, due to the hashing, for "long enough plaintext." And the example code I gave was not about leaving out hashing before putting it throught the identity function as "redundancy", it was exactly about reducing redundancy, which probably I was to stupid to explain correctly, but I'll try now. > Don't do that, even for encryption. See Bleichenbacher's > attacks on RSA encrpytion: > > http://www.bell-labs.com/user/bleichen/bib.html Link doesn't work... But anyway, look at the same book on page 288, (ii): "A pseudorandomly generated bitstring should be appended to the plaintext before encryption (this is also called salting)." That's exactly what my little example was trying to do: append a salt to the data which was being encrypted. First, this gives an internal structure to the data which is being encrypted/decrypted (and thus makes it easy to discard invalid values), as you just have to check that the two lowest bytes of the number coming out are <= keysize//8, and also assures that you don't lose information when for example you are encrypting "what is this?" with a 768 bit key, now when this number comes out of decryption, the string will have been "prepadded" with zeros, but as you know the actual length of the string (from the two lowest bytes), you can extract the string properly. Second, what this also achieves, is that you may encrypt the same plaintext for the same recipient multiple times without an eavesdropper seeing that the plaintext is identical (because of the salt), and Thirdly, the attack stated on the given page is also not successful (when encrypting to multiple recipients with the same encryption exponent, but this is certainly not true for most common situations I need cryptography in). So, pre/postpadding with salt is certainly not the wrong way to go for encryption. Now I'd really like to hear from you why this same argument doesn't go for signing. Because: 1) I generate a signature for a string "some string" with SHA. 2) I decrypt this hash, which is salted by the same standard salting algorithm I noted above with my private key to get the signature 3) I encrypt the signature to get the salted hash with my public key, which can easily be unsalted, and then checked for validity. Forging a valid signature would mean the following steps: 1) Find a pair of numbers (n,E(n)) for which E(n) has the lowest two bytes <= keysize//8. It's pretty easy to insert additional constraints here: for example, the string of randomized bits in E(n) has to have parity one to be accepted, this would make this step harder (but not all of the positions may be one, except when the bitstring is of length one, or something). 2) Now, find a pair from one of the pairs found in (1) which has a value which has correct length (sha digests are always 160 bits long), 3) Now, for this pair, find a message which corresponds to the hash value. If you complete these three steps (well, you'd only have to find one pair in step one and two, which should be hard enough), you'll have a faked signature. But not before this. I recon that step three is computationally infesible, and I also assume that finding a pair (n,E(n)) which first of all has the properties that I give to it (stated above), and also turns out to be a valid hash value for some string I want it to be is computationally infesible. But, as I stated above, even if step 1 is dead easy (by using the identify function here), what is the use if I can easily find a a proper signature for a certain hash value, if I have no plaintext for the hash value for which I have the signature? The problem being that I can't construct the signature from the hash value, but rather even when using identidy redundancy, I have to have the signature first, before constructing the hash value. At least that's what my professor taught me at univ, and with what I can agree. > Then I'm guessing I won't see you at Crypto 04 next week ;) No, you won't, I'm more or less a hobby cryptographer... And I guess I'm certainly not the smartest at this, but... I'd love to hear why you think the above argumentation is wrong, or direct me to a paper which explains why salting a signature with an equally simple algorithm I proposed to salt a string to encrypt won't make things "more secure" for signing also... Anyway, if you're up to some more explaining, feel free to contact me off-list... I'd be glad to learn... :-) Heiko. From me at privacy.net Thu Aug 26 20:56:07 2004 From: me at privacy.net (Richard Hanson) Date: Thu, 26 Aug 2004 17:56:07 -0700 Subject: MSI Installer Problem: can't install 2.4a2 on new install of Win2kSP2 References: <412d7dcd$0$26184$9b622d9e@news.freenet.de> <412e5452$0$24835$9b622d9e@news.freenet.de> Message-ID: Martin, I had just found a workaround for my immediate problem and was composing a post. Instead, I'll cut-and-paste as appropriate from that draft, interleaved herein. Martin v. L?wis wrote: >Richard Hanson wrote: >> (I have much to learn in writing concise posts, alas -- I appreciate >> your patience.) > >That is indeed the problem. I stopped reading after the first paragraph. >I'm still uncertain whether you are talking about the original problem >(failure to install the Python msi file), or about the second problem >(MSI file installs fine, but IDLE fails to work) in this message. Sorry. I see now that I provided too much background detail getting to the story -- and didn't write clearly enough, to boot. (As it were.) The problem: The "python-2.4a2.msi" file appeared to install, but the install was broken -- IDLE failed to work, and the console was mostly broken. Platform: Dual-booting Win98SE and Win2kSP2 on Fujitsu laptop -- primary OS is Win2k on the E: partition. >>[...] Surely, something I had previously installed in >> my own prior installation silently installed something needed for the >> Python 2.4a2 install *other than the MSI Installer 2.0* and is >> currently missing from my reinstall...? > >Why do you think so? Well, I admit I was clutching at straws. And ignorance and frustration were probably making me too reckless with unwarranted assertions. :-) Now, however, I have some new data (which has me even more confused): If I have a directory named "Python23" with *only* the immediate contents of "Lib" in it (no other files or directories nor any of Lib's sub-dirs) in a separate Win98 partition, then IDLE doesn't run. However, if I rename or move that dir inside another dir, then IDLE runs. I can move that subsetted Python23 dir back and forth between being hidden inside another dir and being in the root, without rebooting, and IDLE works or not, depending on the visibility of that very limited subset of the normal Python23 install directory. I've searched the registry for "Python23" and don't find any reference there. It's probably Just Another Windows Problem , but by now after fighting Windows installation problems for days -- my brain is mush. Further, I know virtually nothing about Python's guts. Perhaps my testing will help you or others ascertain if there even *is* a problem in general -- or, if there's just something wrong with my individual machine. For now, I will just uninstall Python from my Win98 partition. My apologies again, Martin, for my less-than-optimum posts. I do appreciate the busyness of the modern era, and I'm very grateful that folks like you are so willing to give of your valuable time. You have indeed helped by eliminating many blind alleys I could have gone down. Anyway, thanks much -- again. Best regards, Richard -- email works if unmunged: sickolefartnewsguycom From http Thu Aug 26 16:54:36 2004 From: http (Paul Rubin) Date: 26 Aug 2004 13:54:36 -0700 Subject: Call for signatories for J2 References: <1gj5cs7.wqxd1s1ec69umN%aleaxit@yahoo.com> Message-ID: <7xfz69oc1f.fsf@ruckus.brouhaha.com> aleaxit at yahoo.com (Alex Martelli) writes: > I think a keyword that's ALREADY a keyword has been almost ignored, > though people occasionally did mention it re decorators: 'as'. I'd love > to see 'as' used as THE decorator keyword. personally I'd prefer > 'def as classmethod foo(...):' > followed by How do you handle the other proposed uses of decorators, e.g. type declarations? def foo as int (a as string, b as int): ... seems pretty awful to me. From anthonybaxter at gmail.com Fri Aug 13 03:05:25 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 13 Aug 2004 17:05:25 +1000 Subject: decorator with ``` In-Reply-To: References: Message-ID: On Thu, 12 Aug 2004 13:32:28 +0400 (MSD), Roman Suzi wrote: > > One more crazy syntax before-def but which could be treated > more generally: > > ```""" Factory for new decorator syntaxes. > > Keeps all proposals in a list and will recombine > them at random if called without a spec. """ > staticmethod``` > def makeDecoratorSyntax(spec=None): -1. "Syntax should not look like grit". Note that my dislike of the backtick also led me to nag about stripping them from the stdlib. From adurdin at gmail.com Sun Aug 8 10:57:56 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Mon, 9 Aug 2004 00:57:56 +1000 Subject: @decorator syntax is sugar, but for what exactly? (decorator libraries). In-Reply-To: References: Message-ID: <59e9fd3a04080807571fbb3a4c@mail.gmail.com> On Sun, 08 Aug 2004 10:46:38 -0400, Roy Smith wrote: > In article , > > Wow, I'm glad I asked. That answer is quite surprising, and somewhat > disconcerting. Lot's of special cases going on here, which is bad. Well, I think I agree with the principle of limiting the expressions to dotted names. Some of the possibilities if you allow arbitrary expressions are pretty hairy: """ Things someone might want to do, ordered roughly from most reasonable to least reasonable ;) @foo().bar() @foo or bar @mydecorators['foo'] @lambda f: foo(f) or bar(f) """ (from http://mail.python.org/pipermail/python-dev/2004-August/046673.html) From Scott.Daniels at Acm.Org Thu Aug 5 13:37:28 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 05 Aug 2004 10:37:28 -0700 Subject: AVI I/O In-Reply-To: <41120e31$1@news.bezeqint.net> References: <41120e31$1@news.bezeqint.net> Message-ID: <411272ec$1@nntp0.pdx.net> ziaran wrote: > Hello, > > I want to use Python for Image proccessing. > I need the following capabilities: > > 1. To be able to read and WRITE an AVI file frame by frame. > 2. To be able to access each fram as a simple matrix. > > I tried to search for that in google but could not find something > intuitive and simple. > > The matrices part is important since iamge processing is done through > matrices manipulation. > > MATLAB is an example of a tool with scripting capabilities in which you > can do that in a simple way. > > Is Python adequate for that? > > Thanks, > Nir Python is, of course, up to the job. However, nobody I know has provided free access to something that "knows" how to generate the AVI format. The array formay part is probably best handled through numarray (which is quite happy with multi-dimensional arrays). PIL may also have some interesting things to get you going. So, the parts are mostly there. If you want the whole kit and kaboodle prepackaged for you, no luck. -Scott David Daniels Scott.Daniels at Acm.Org From zathras at thwackety.com Sat Aug 14 17:49:22 2004 From: zathras at thwackety.com (Michael Sparks) Date: Sat, 14 Aug 2004 22:49:22 +0100 (BST) Subject: Generators versus Coroutines In-Reply-To: <972ec5bd.0408141032.385fe115@posting.google.com> Message-ID: On 14 Aug 2004, Timothy Fitz wrote: > It seems to me that in python, generators are not truly coroutines. Assuming you mean there isn't available a default scheduler for them, or there isn't pre-emption built-in I agree. If you mean something else, I'm curious as to what you think is missing. (I've also been using generators as co-routines for sometime for various reasons) > Why can I use "return" without an expression and it implicitly > returns None but I can't do the same thing with "yield" ? I suspect it's one of two things: * A syntax for yield by itself as either not considered important or needed. * The ability to do a return with an implicit None value was considered a mistake, but one that can't be undone this late in the game. After all, the following works fine: * yield None Also given I think the most expected use case for generators is to lazily return a list, or to transform (or create) an iterator (eg a lexer), having simply "yield" by itself might've been considered sensible. That said, enforcing a return value is useful - even in the co-routine situation since I find it useful for sending back information to the scheduler. BTW, if you're looking at using generators as co-routines, you might want to look at Armin Rigo's "Greenlets" which whilst in the stackless python tree work fine with standard python. (check out the CVS tree, and just grab the greenlets directory - it built cleanly for me) As far as I can tell Armin is *really* good at producing things that confound, astound and speed up your code with minimal effort... I've found that by replacing usage of generators-as-co-routines with Greenlets that it speeds things up by a factor of about 2.5. YMMV. Incidentally the default mechanism for switching between greenlets is a switch() method which can take 0 arguments. Michael. From martin at v.loewis.de Sun Aug 15 06:15:28 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 15 Aug 2004 12:15:28 +0200 Subject: compiling python 2.3.4 with command line editing In-Reply-To: <864c2cd6.0408141845.3f50a3d5@posting.google.com> References: <864c2cd6.0408141845.3f50a3d5@posting.google.com> Message-ID: <411f37bf$0$13058$9b622d9e@news.freenet.de> enjoylife_95135 wrote: > I need to upgrade, so I downloaded and compiled Python 2.3.4. Very > cool, spiffy etc, but the interpreter doesn't allow for command line > editing, i.e. I can't type and go to the previous command. > > How do I enable that? Make sure the readline module is built. For that, you need to install the readline header files, which are probably in the readline-dev package. Regards, Martin From ptmcg at austin.rr._bogus_.com Fri Aug 6 10:49:43 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 06 Aug 2004 14:49:43 GMT Subject: Buy a vote! (was Re: Poll - Vote here for "list-after-def" (was Decorator syntax)) References: Message-ID: "Peter Hansen" wrote in message news:weadnfi70qOpDI7cRVn-qA at powergate.ca... > I suggest that everyone with an opinion on the matter visit the > page at http://www.python.org/psf/donations.html and make a donation, > preferably sized in relation to the strength of your opinion. (*) Done. From peter at engcorp.com Thu Aug 12 08:43:36 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 12 Aug 2004 08:43:36 -0400 Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: <2WFSc.12148$Nl1.3243@fe1.columbus.rr.com> References: <60dfb6f6.0408111846.615ee9eb@posting.google.com> <3YWdnYxLf--ObofcRVn-pw@powergate.ca> <2WFSc.12148$Nl1.3243@fe1.columbus.rr.com> Message-ID: Carl Banks wrote: > Well, the only thing is, whenever you see a def statement, you don't > know if it's decorated right away, so you have to expend one or two > extra ergs of energy to look above it and see if it is. Well, that argument could be used against any decorator syntax, (except those which completely obscure the def, and there would be obvious objections to such a syntax as well). Likewise, when you see a def, you don't know for sure right away if it has a body, or just a big doc string, or perhaps only a pass statement. Neither can you tell without looking in a module whether it has functions, classes, or just data. Or maybe just a bunch of comments, or many, many empty lines. You even have to turn on the computer before you can find the name of the file! Damn, you mean we actually have to look at the code to figure out what it does?! ;-) -Peter From paul.dubois at gmail.com Fri Aug 20 21:52:33 2004 From: paul.dubois at gmail.com (Paul Du Bois) Date: 20 Aug 2004 18:52:33 -0700 Subject: Alternative decorator syntax decision In-Reply-To: Message-ID: J2, J2, J2 And not that it matters for the vote, but I like J2 better than the pie syntax. The pie syntax is my second favorite. From peter at engcorp.com Tue Aug 24 00:50:33 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 24 Aug 2004 00:50:33 -0400 Subject: urllib hangs In-Reply-To: References: Message-ID: Jay Donnell wrote: > I found this link > http://www.timo-tasi.org/python/timeoutsocket.py > which I'm assuming is the most recent version of timeoutsocket.py > > It's very light on the explanatory side. Do I simply need drop this > file into the same directory as my script, import it, and set the > timeout??? At the risk of getting beaten up by you for the same reason you beat up Baalbek (which was, by the way, a wholly unjustified beating), have you actually looked at the comments in that module yet? It does say exactly what you need to do... (Feel free to beat me up, but note that it really does look like you aren't taken even a few minutes to help yourself out, so please consider not abusing those who are helping you, even if they are a little brusque in their replies...) -Peter From heikowu at ceosg.de Sun Aug 1 10:55:45 2004 From: heikowu at ceosg.de (Heiko Wundram) Date: Sun, 1 Aug 2004 16:55:45 +0200 Subject: Making a socket connection via a proxy server In-Reply-To: References: <8089854e.0407300433.4c09bce0@posting.google.com> Message-ID: <200408011655.45363.heikowu@ceosg.de> > Fuzzyman wrote: > > In a nutshell - the question I'm asking is, how do I make a socket > > conenction go via a proxy server ? > > All our internet traffic has to go through a proxy-server at location > > 'dav-serv:8080' and I need to make a socket connection through it. Am Freitag, 30. Juli 2004 18:51 schrieb Diez B. Roggisch: > Short answer: Its not possible. Longer answer: it is possible if you use DNAT on some router between the computer which opens the request and the destination machine. Check out squid transparent proxy howtos you can find on the net. The protocol will need HTTP/1.1 for this, though. Small example, which clarifies why this is possible: Computer 1 opens http (port 80) connection to computer 2. Router 1 sits in the middle, sees a port 80 connection is opened to some computer 2, and rewrites the incoming packet to have a new destination address/port (DNAT), namely proxy 1 with port 3128 (standard http-proxy port, at least for squid), and a new source address/port (SNAT), namely router 1 with some port. Proxy 1 gets the following (from router 1): GET /foo.html HTTP/1.1 Host: www.foo.com:80 Proxy 1 opens the connection to www.foo.com port 80 (now, the router sees that the connection comes from proxy, it must not do address rewriting), gets the result, and stores it locally. proxy 1 then sends the packets back to router 1 (because the proxy request seems to have come from router; if you leave out SNAT in the rewriting step, it'll seem to have come from the actual computer, and this is fine too, but then you have to be sure that the return packet also has to go through the router), and now router 1 does reverse DNAT and SNAT to return the packet to computer 1, which will see a source address of computer 2 and port 80 on the packet. computer 1 sees the result, and thinks it came from the outside machine, although through some SNAT/DNAT the packets actually originated from the proxy. This is basically it. If you want to implement this, as I said, read up on transparent proxy howtos for squid. Pretty much every proxy can be made to support this, as with HTTP/1.1 the Host: header is a required header, and thus the proxy can always extract the host which was queried from the request, even when it isn't passed as the others have suggested. On another note: I assumed you wanted to transparently relay/rewrite HTTP through the proxy. If you need to open some form of socket connection to the proxy which is not HTTP, the proxy protocol supports the method CONNECT, which will simply open up a socket connection which is relayed by the proxy. But: This cannot be made transparent, except by some deeper magic in the router. HTH! Heiko. From sholden at holdenweb.com Mon Aug 23 20:47:47 2004 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 24 Aug 2004 00:47:47 GMT Subject: Debunking Art - fraudster with python AI engine? References: <4128f60b$1@news.unimelb.edu.au> Message-ID: <412a902f$1@news.unimelb.edu.au> Nick wrote: > Hi, > > I recently went to an art exhibition, and one of the artists had an AI > engine projected onto a screen with a keyboard for visitors to type > questions in with. > > Curiously, I asked the artist if he had written the engine. He claimed > to have, but as far as I know, he has done no AI study, and only > started programming python some months ago. > > Naturally, I find it hard to believe he has picked up on natural > language processing and the other various skills required to write AI > engines in that time. My guess is he has a python AIML interpreter, > and he's found a default "brain" somewhere and tweaked it with some of > his own stuff in order to pass it off as his own. > > The engine could answer all the usual questions, like "what is the > meaning of life" (42), "what is your name", "how old are you" etc etc. > It was just a chatterbot, so ELIZA or a deriviative is marked off the > list. I am guessing probably an ALICE engine is behind it all. Does > anyone know any questions or commands one can issue the bot which > might identify it? It required all questions to start with a capital > letter, if thats any help. > > Cheers, > > Nick. > The artist wasn't, by any chance, called "Timothy", was he? regards Steve [ 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 alikakakhel3 at hotmail.com Wed Aug 18 17:49:54 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 18 Aug 2004 14:49:54 -0700 Subject: I would really like the code for a dome in vpython Message-ID: <8f17f4bc.0408181349.46c34b2@posting.google.com> Please anyone I would really like the code for makinga dome in vpython. I would like to be able to adjust he color, axis, radius, and pos. From benn at cenix-bioscience.com Fri Aug 13 03:52:52 2004 From: benn at cenix-bioscience.com (Neil Benn) Date: Fri, 13 Aug 2004 09:52:52 +0200 Subject: Pyhton Interpreter Startup time In-Reply-To: <411C7262.1000803@cenix-bioscience.com> References: <30260531.0408120829.27a536bc@posting.google.com> <411C7262.1000803@cenix-bioscience.com> Message-ID: <411C7354.6000808@cenix-bioscience.com> Neil Benn wrote: > > PYTHON_HOME=c:\program files\python23 > PATH=%PATH%;PYTHON_HOME > PATH=%PATH%;%PYTHON_HOME% Just in case someone mentions! -- Neil Benn Senior Automation Engineer Cenix BioScience BioInnovations Zentrum Tatzberg 47 D-01307 Dresden Germany Tel : +49 (0)351 4173 154 e-mail : benn at cenix-bioscience.com Cenix Website : http://www.cenix-bioscience.com From steven.bethard at gmail.com Wed Aug 25 00:08:47 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Wed, 25 Aug 2004 04:08:47 +0000 (UTC) Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> Message-ID: Paul Morrow yahoo.com> writes: > I believe that (virtually) all __xxx__ attributes have this metadata > aspect (semantics) to them. When a programmer says > > def foo(): > __author__ = 'Wilma Flintstone' > __version__ = '0.1' > > She does not intend for __author__ nor __version__ to be local variables > of foo, used somehow by foo in the calculation of its return value. To > her they are foo /metadata/ --- attributes of the foo object itself --- > as they contain information that *describes* foo. I assume you mean that this is what you'd like a programmer to intend? If I wrote that, I would intend (and expect) __author__ to be a local variable. I'm not saying that I couldn't be retrained. I'm just saying that right now, I would not expect it to be otherwise. > Likewise, when she defines __lt__, __getitem__, __init__, etc. as part > of a class, they will not typically be called by methods of the class or > users/consumers/clients of the class [*] the way that 'normal' > attributes will. They contain meta info that describes a deeper level > of class behavior. This seems a little misleading to me. The only reason these methods are special is because they override operators (something like "<", "[]", and "()" respectively). You could provide a class with /exactly/ the same functionality without ever implementing any of these methods. (Well, minus __init__, but that was a special case in your discussion too.) The only thing that implementing these methods does is allows your user to access these methods through an operator shorthand. A simple example: class Identity: def get(self, x): return x __getitem__ = get How is __getitem__ any more "metadata" then get is? They provide exactly the same functionality. The __getitem__ declaration just allows you to access the get method using "[...]". Are you trying to say that "metadata" is the same thing as "operator shortcut"? Steve From jeff at ccvcorp.com Fri Aug 20 17:04:07 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 20 Aug 2004 14:04:07 -0700 Subject: Alternative decorator syntax decision In-Reply-To: References: <3A81C87DC164034AA4E2DDFE11D258E3022E14@exchange.hqamor.amorhq.net> Message-ID: <10icpotqq293mb6@corp.supernews.com> Peter Hansen wrote: > Bernhard Herzog wrote: > >> Yes. But what if the majority of the community favors pies of J2? > > > Then it's a certainty that we'll hear at high volume from > that community when the time comes. Now is not their time. > (Or, to put it another way, they are quite capable of holding > their own vote... this is c.l.p, home of the daily syntax > vote!) I've been thinking of this as a primary election, rather than a general election. One party already has a strong incumbent candidate (@pies), the other party is now trying to decide which of many potential candidates they should run against the incumbent. Of course, the difference here is that, in the general election, only one vote will be cast, and that vote is GvR's... (Not sure how well this metaphor will carry over to all of the different election schemes used in the many countries represented here in c.l.py, but hopefully most of us are at least moderately familiar with the concept...) Jeff Shannon Technician/Programmer Credit International From artur_spruce at yahoo.com Sat Aug 7 05:20:08 2004 From: artur_spruce at yahoo.com (AdSR) Date: 7 Aug 2004 02:20:08 -0700 Subject: Importance of C# (was Re: IronPython-0.6 is now available!) References: <278de0e.0407281353.27b6a457@posting.google.com> <5dydnZSDZaARoZXcRVn-ug@powergate.ca> <9418be08.0407292114.129c856f@posting.google.com> Message-ID: Peter Hansen wrote in message news:... > > Language comparison is a hard thing: what happens when you > pick a test case that can be handled much more easily in > one language than in another? Do you pick a new test case, > or write inefficient code that no programmer experienced in that > language would actually write? I'm not sure of the answer... Well, for me the most interesting test would be to actually use all features available in each of the compared languages. So, if the standard distribution of a given language includes a library to do a task, use that library. If there is a syntax feature that makes things easier, use that too. And so on... I think this is far more useful in real life than just plain interpreter/compiled code speed comparison. I do mostly Java, PHP, and SQL for living. My projects often involve some obscure algorithms. I usually pick Python for prototyping those algorithms because the builtin collections and other features allow me to code faster, read more easily, and thus arrive at the right solution (or discard a wrong one) more quickly. Then I can rewrite that in the project's language using more primitive ways like I would otherwise, but I don't have to switch between thinking about algorithm and implementation details anymore. AdSR From DesertLinux at netscape.net Sat Aug 21 09:48:45 2004 From: DesertLinux at netscape.net (Byron) Date: Sat, 21 Aug 2004 13:48:45 GMT Subject: Files in unix and windows In-Reply-To: References: Message-ID: <1pIVc.8678$3O3.1751@newsread2.news.pas.earthlink.net> Hi Travis, You want to use forward slashes with your file names. Backslashes are used for special character commands, such as "/t" for , etc. For Windows: c:/aFolder/testDocument.txt For Unix / Linux /aFolder/testDocument.txt If you need a relative path, with no drive specified (for Windows), use: /aFolder/testDocument.txt Hope this helps, Byron --- Travis James Kleeburg wrote: > I am trying to copy files from one directory into another using > shutil.copy. I am having a problem getting a usable path using > os.path.abspath because it doesnt return a string with the extra > backslashes and i was wondering if there was a better system call to use? > I am also looking for a system call so there wont be a problem between windows and > unix. > > From mark_bottjer at hotmail.com Wed Aug 11 13:45:50 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Wed, 11 Aug 2004 13:45:50 -0400 Subject: PEP-0318 In-Reply-To: References: <41122FC2.1080608@interlink.com.au> <4114152f@nntp.zianet.com> <4116bc20$1@nntp.zianet.com> Message-ID: <411a5b4f$1@nntp.zianet.com> Andrew Durdin wrote: > I honestly believe that having docstrings where they are is better > than having them before the function signature; how many > function-commenting standards have you seen where the function name is > repeated in the first line of the comment so that you know what > function is being talked about when you start reading the comment? I'm torn on this one, frankly. I agree that having it before the function is very much putting the cart before the horse, and leads to redundancy to keep it all straight, but I also agree that having it inside the function muddies up the function implementation, and is not the first place one might think to look for such information. > This in conception is something like the following: > > def foo(bar, baz=None): > header: > """Frobulates bar, and calls baz if it is not None.""" > .decorate(decorator_func) > .attribute = "qux" > body: > pass I think that this has been proposed before, but was rejected for reasons I can't remember. But, as a guess, GvR's argument that one should not have to "look inside" a function to see what it is would apply. And FWIW, the body statement is probably unnecessary. All that really needs to be delineated is the header; everything that isn't header is by definition the body. Just my $0.02. -- Mark From tuure at laurinolli.net Fri Aug 6 18:55:04 2004 From: tuure at laurinolli.net (Tuure Laurinolli) Date: Sat, 07 Aug 2004 01:55:04 +0300 Subject: Decorator keyword In-Reply-To: References: Message-ID: David Fraser wrote: > Anthony Baxter wrote: > >> "with" is a non-starter - there's already other plans to use with for >> other >> things, at some distant point. Also, if we're to have a new keyword, it >> should be _much_ more obvious than 'with'. > > > Any pointers to info on other plans for with? > suggestions: declare > > declare classmethod > declare returns(int) > def func(*args, **kwds): > return 1 > > Other ideas would be "decorate", but this doesn't really seem to make > sense (perhaps suggesting that decorators isn't the best name for them > :-)) or "wrap" (because they literally wrap the function, but again that > doesn't seem intuitive. I was trying to find some keyword that would incorporate the name "decorator" somehow, but couldn't really find any (except decorate, of course), thus I don't think decorator is a good name for those things. I though "use" could be good, but the function won't really use the functions it's decorated with, rather thay are used to describe the function. Keyword "describe" would make the metafunctions "descriptors", although the verb-as-keyword approach doesn't really work because the quantifiers are between the predicate and the object(decorate with silver and gold this tree). Could the decorating expressions be inside the function-block? Could there be decorating blocks inside which the function blocks would reside? From siona at chiark.greenend.org.uk Thu Aug 12 09:06:02 2004 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 12 Aug 2004 14:06:02 +0100 (BST) Subject: [OT] Keyboard layout, was Re: PEP318 References: <20040812090056.00001e31@titan> Message-ID: Josef Dalcolmo wrote: > On many non-English keyboards it isn't exactly simple to type an '@' > [ ... ] As someone who's just started using a Mac for the first time(*), I'd like to add that it's not always plain-sailing on an English keyboard. (Yes, I know in terms of keystrokes it's no more difficult than on a PC, but it's not *marked*. And I have a great aversion to remapping keyboards so that they generate characters other than those on the keycaps.) (* ... for about fifteen years, when all I wanted it for was word processing) -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From ville at spammers.com Sat Aug 7 10:20:31 2004 From: ville at spammers.com (Ville Vainio) Date: 07 Aug 2004 17:20:31 +0300 Subject: Maybe, just maybe @decorator syntax is ok after all Message-ID: It might just be that @decorator might not be all that bad. When you look at code that uses it it's not that ugly after all. A lot of the furor about this is probably because it happened so quicly. The situation might have been different if we had seen a pronouncement a week before, in the vein of "I have chosen this syntax - it will go in to the next alpha". My chief worry was throwing away one of the few unused ascii symbols, but if we take a look at perl6, there is a lot of promising unicode symbols to choose from in the future ;-). Also, there is still @(), @#, @{} and others in the hypothetical event BDFL would like to use @ for future features like macros, ruby blocks or whatever. So I would vote +0 for @decorator if we were in the parallel universe where that mattered. Two days ago I was -10. -- Ville Vainio http://tinyurl.com/2prnb From ptmcg at austin.rr._bogus_.com Mon Aug 23 15:35:42 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 23 Aug 2004 19:35:42 GMT Subject: Standard graph API? References: Message-ID: "Magnus Lie Hetland" wrote in message news:slrncik8tm.4g.mlh at furu.idi.ntnu.no... > Is there any interest in a (hypothetical) standard graph API (with > 'graph' meaning a network, consisting of nodes and edges)? Yes, we > have the standard ways of implementing graphs through (e.g.) dicts > mapping nodes to neighbor-sets, but if one wants a graph that's > implemented in some other way, this may not be the most convenient (or > abstract) interface to emulate. It might be nice to have the kind of > polymorphic freedom that one has with, e.g, with the DB-API. One could > always develop factories or adaptors (such as for PyProtocols) to/from > the dict-of-sets version... > > So, any interest? Or am I just a lone nut in wanting this? > > -- > Magnus Lie Hetland "Canned Bread: The greatest thing since sliced > http://hetland.org bread!" [from a can in Spongebob Squarepants] Not sure if this falls under the category of an API, but it may be relevant to what you are doing. This is a Python API to the Graphviz DOT language: http://dkbza.org/pydot.html So I think this is evidence you are not alone. -- Paul From inigoserna at terra.es Wed Aug 25 16:54:12 2004 From: inigoserna at terra.es (=?ISO-8859-1?Q?I=F1igo?= Serna) Date: Wed, 25 Aug 2004 22:54:12 +0200 Subject: ANN: googlenews.py Message-ID: <1093467252.15882.15.camel@inigo.katxi.org> hi there, while half the world is watching Olympic Games and the other half is discussing about decorators, and as far as my good proposal ("#decorator" :) has been sadly ignored, I've spent last days writing googlenews.py [1], a simple python script to retrieve news from the http://news.google.com service. Supported feeds: es, fr, de, it, nz, au, in, ca, uk, us Can export to: rss2 xml and html files Requirements: - Python 2.3+ - BeautifulSoap (http://www.crummy.com/software/BeautifulSoup) I use it in a hourly cron script, building rss files which I read with liferea : [inigo at inigo inigo]$ cat /etc/cron.hourly/googlenews #!/bin/bash /home/devel/mine/googlenews/googlenews.py --rss-path=/tmp -w -q es /home/devel/mine/googlenews/googlenews.py -cnes --rss-path=/tmp -w -q nz exit 0 [inigo at inigo inigo]$ type "googlenews.py --help" for more info. Hope you like it, I?igo [1] http://inigo.katxi.org/devel/misc/googlenews.py [2] http://liferea.sourceforge.net -- I?igo Serna Katxijasotzaileak -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Esta parte del mensaje est? firmada digitalmente URL: From fredrik at pythonware.com Wed Aug 11 09:45:48 2004 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 11 Aug 2004 15:45:48 +0200 Subject: Capturing repeating group matches in regular expressions References: <4119F7B6.6090003@xtra.co.nz> <6C440902-EB9B-11D8-AAF7-000A9574CFD8@earthlink.net> Message-ID: "gohaku" wrote: > This is somewhat off-topic, but I am using finditer: > for m in re.finditer('([a-z]W)','aWbWcXdXeWfY'): > print m.groups() > #aW > #bW > #eW > I would like to compile the regex instead of using finditer. > How do I do this? finditer compiles the regex for you, of course, and caches the result. but if you really want to do it yourself, just do it: >>> p = re.compile("([a-z]W)") >>> p.finditer("aWbWcXdXeWfY") >>> for x in p.finditer("aWbWcXdXeWfY"): ... print x.groups() ... ('aW',) ('bW',) ('eW',) From crichton314 at btinternet.com Sun Aug 22 19:06:46 2004 From: crichton314 at btinternet.com (John Crichton) Date: 22 Aug 2004 16:06:46 -0700 Subject: J2 proposal: keyword References: Message-ID: <3b2846c4.0408221506.1c3e33d2@posting.google.com> Hi, +1, also, on "using". John From Steve.Coates at smiths-aerospace.com Mon Aug 16 11:08:12 2004 From: Steve.Coates at smiths-aerospace.com (Coates, Steve (ACHE)) Date: Mon, 16 Aug 2004 09:08:12 -0600 Subject: Why does this (very simple piece of) code does not work? Message-ID: <3082C9F9373DAD43918C64BAC1CF038C05A11D@cossmgmbx04.email.corp.tld> > -----Original Message----- > From: jblazi [mailto:jblazi at hotmail.com] > Sent: 16 August 2004 14:31 > To: python-list at python.org > Subject: Re: Why does this (very simple piece of) code does not work? > > > On Mon, 16 Aug 2004 14:16:21 +0100, Richard Brodie wrote: > > > You didn't say what platform you are on but if it's Windows, then > > colons aren't allowed in filenames. > > Yes. Now it seems, my age begins to tell, I did not used to > be so dumb... > Thx. > > jb > I sympathize. I'm fast approaching 40 and I'm sure I'm not half the engineer I used to be. I think I understand now why the career path tends towards management... Steve (Dribling in the corner) ****************************************** The information contained in, or attached to, this e-mail, may contain confidential information and is intended solely for the use of the individual or entity to whom they are addressed and may be subject to legal privilege. If you have received this e-mail in error you should notify the sender immediately by reply e-mail, delete the message from your system and notify your system manager. Please do not copy it for any purpose, or disclose its contents to any other person. The views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of the company. The recipient should check this e-mail and any attachments for the presence of viruses. The company accepts no liability for any damage caused, directly or indirectly, by any virus transmitted in this email. ****************************************** From guido at python.org Fri Aug 6 01:12:45 2004 From: guido at python.org (Guido van Rossum) Date: Thu, 05 Aug 2004 22:12:45 -0700 Subject: Prothon is switching to the .NET platform In-Reply-To: Your message of "Thu, 05 Aug 2004 19:00:49 PDT." <000401c47b59$32539220$0d01a8c0@MarkVaio> References: <000401c47b59$32539220$0d01a8c0@MarkVaio> Message-ID: <200408060512.i765CkN05946@guido.python.org> Hi Mark, It was a pleasure to meet you at VanPy, and I was sorry that I had to leave in the middle of your talk (I had a plane to catch and David had scared me about delays). I was pleasantly surprised in hearing your architecture for the Prothon engine -- it sounded like a fresh look at implementing a runtime for a Python-like language, and several features (like the locking strategy) sounded like I should be paying attention to them for the Python 3000 interpreter. So now I'm a bit disappointed to hear that you're giving all that up and switching to the CLR. I understand your desire to have a large library available (though most of that library will be class-based, which may require you to bring classes back in through the back door). But in practical terms, it makes Prothon a lot less accessible in the years to come. I recall that installing .NET on Windows took me half a day. Maybe it's gotten better, but I sure can't believe they've shrunk it. Mono gives you theoretical support on Linux, but it's even more of a questionable proposition to actually run it (and its set of supported runtime libraries has only a small intersection with what's available in .NET). Basically, telling people "here's my language, it's a 2 MB download, and oh, BTW, you also need to install the 200 MB runtime over there" isn't exactly encouraging people to play with your language. Even for apps written in Java this is a significant barrier -- I have several copies of Java on my hard drive because every significant application written in Java ends up needing a different JVM version. And the JVM I downloaded last year is probably too old to run this year's crop of bleeding edge Java apps. Availability of the CLR is a lot less than Java. I'm also surprised because you admit to being a poor language designer (although you picked a great example :-). I assumed this to mean that you're having more fun implementing the runtime. But if you're not doing it for the language design, and now you're giving up on the runtime, what's left? Hoping your website was hacked or it was practical joke, --Guido van Rossum (home page: http://www.python.org/~guido/) From http Sat Aug 21 13:51:28 2004 From: http (Paul Rubin) Date: 21 Aug 2004 10:51:28 -0700 Subject: Has anyone implemented BASIC in Python? References: <2oo13eFcj548U1@uni-berlin.de> <69cbbef2.0408210857.79439c35@posting.google.com> Message-ID: <7x657c8jmn.fsf@ruckus.brouhaha.com> has.temp2 at virgin.net (has) writes: > > Has anyone ever tried implementing a simple unstructured BASIC dialect > > in Python? I'm getting interested in language implementation, and > > looking at a reasonably simple example like that could be pretty > > interesting. > > Dunno about BASIC, but Ian Bicking has done Logo: > http://pylogo.sourceforge.net/ Dunno about Logo but I did Forth just out of general perversity. I suppose I could post it. From tjreedy at udel.edu Tue Aug 24 18:36:21 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 24 Aug 2004 18:36:21 -0400 Subject: J2 0-2-6 is available References: <3A81C87DC164034AA4E2DDFE11D258E3022E52@exchange.hqamor.amorhq.net> Message-ID: "Robert Brewer" wrote in message news:3A81C87DC164034AA4E2DDFE11D258E3022E52 at exchange.hqamor.amorhq.net... There's a semi-final version of the J2 proposal available: http://www.aminus.org/rbre/python/pydec.html I think we've heard all the nits by now, and any paragraphs which I felt were weak have been rewritten. Important changes since 0.2.1: 1) There's a new Conclusion. 2) At Guido's request, I removed "wiggle room" with an explicit statement in the intro: anything not addressed in the proposal defaults to the @pie implementation currently in CVS. There's a list of what is outside the scope of the proposal. 3) I softened the recommendation of the keyword "using" a smidgen (mostly downplaying argument III over the other two). 4) The number of proposed grammars is now one (there were two). If I had another 4 hours or so ;) I'd rewrite it in more direct language. Boy, is it academic in tone--my great weakness. Meh. At this time, I'd like to call for negative signatories. That is, if you believe the @pie syntax is better than suite-and-keyword, please drop me an email, either privately or on the list. I'd like your full name, and *some* indication of why you are rejecting it. One short sentence is enough, but if you want to write more, that's fine. I'll try to merge the rejection comments into a readable summary in that section of the document. Please don't sign it yet if you favor the proposal. I'd like a day to consider the rejection notices. I'm equally open to doing more rewriting to accomodate the blockers, or freezing it as it stands--it depends to a large extent on the responses I get from the detractors in the next 24 hours. If there are no reconsiderations, I'll call for positive signatories (those in favor) tomorrow. I think we have a good chance of success, where Guido can get a clear picture of the situation and make a balanced decision. Thanks again to those who suggested syntax, started polls, managed threads, wrote code (!) and commented on the draft. Robert Brewer MIS Amor Ministries fumanchu at amor.org -- http://mail.python.org/mailman/listinfo/python-list From fumanchu at amor.org Tue Aug 24 02:06:08 2004 From: fumanchu at amor.org (Robert Brewer) Date: Mon, 23 Aug 2004 23:06:08 -0700 Subject: On consensus decision-making (was Re: Alternative decoratorsyntax - POLL RESULTS SO FAR - ARE WEDONE?) Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E4F@exchange.hqamor.amorhq.net> Anthony Baxter wrote: > (Of course, there's also my cunning plot to use this particular issue > to get a couple more people involved in Python's development process - > we now have at least one person who's obviously a good person to write > up future PEPs, and another who's now delved into Python's innards in > a non-trivial way.... moohahaha) Funny, I was just thinking today about Brett, trying to hand off the summaries. But I concluded I'm 6 months to a year away from that in terms of being able to _accurately_ decipher the majority of pydev discussions. So your plot is working somewhat... ;) Robert Brewer MIS Amor Ministries fumanchu at amor.org From egbert.list at hccnet.nl Thu Aug 19 06:16:27 2004 From: egbert.list at hccnet.nl (Egbert Bouwman) Date: Thu, 19 Aug 2004 12:16:27 +0200 Subject: age of Python programmers In-Reply-To: References: <20040818174601.GA3863@mirk.lan> Message-ID: <20040819101627.GA1223@mirk.lan> On Thu, Aug 19, 2004 at 06:49:30AM +0100, Ben Last wrote: > I think the slowing down of the brain due to ageing is compensated for by > the increase in experience (one makes fewer of the same mistakes again) and > learning in how to learn :) I suppose you are right. It is our last resort. But I am constantly amazed, not only by the number of tools and the conceptual difficulty of these tools that the younger programmers seem to have mastered, but also by the wise lessons they derive from living with them. It was a bit of a surprise that my last teacher, Christopher King, is sub-twenty (which is very young). For the elder programmers Python is a godsend. More than any other language I have used, it helps you to manage complexity, and to think about your problem instead of the bytes. I think the main factors here are: - the syntax: indentation instead of braces in space. My programs look exactly like the pseudocode I used to write. - high-level constructs where you need them; for me one of them is the ease with which you transform sequences into files, and vice versa. - the simplicity of handling classes, objects, once you know the basics. Thanks to Python thinking with classes has become a way of life. It rescued me from the Fortran-PL/I-C-Perl noodle-soup. egbert -- Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991 ======================================================================== From aahz at pythoncraft.com Tue Aug 10 17:35:55 2004 From: aahz at pythoncraft.com (Aahz) Date: 10 Aug 2004 17:35:55 -0400 Subject: decorators vs GIL References: Message-ID: In article , Christopher T King wrote: > >The real reason behind the GIL is that the Python interpreter is not >re-entrant; it keeps internal state in a global structure which must be >switched out (and stored somewhere) on thread changes. The real solution >to this problem is to make the interpreter stateless, thus obviating the >need for the GIL entirely. I think this task would be much easier to do >in Stackless than in CPython, but I may be wrong. There's no "the" real reason. Another critical reason is that it's a design goal of CPython to be a useful glue language for C libraries. Many libraries use internal static variables.... Until a good API exists on all standard platforms for determining whether a library call needs a GIL around it, we can't seriously discuss removing the GIL. Currently, any library designed to work with Python's GIL can easily unlock the GIL while it's running "standalone" (no calls back into Python). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From jbors at mail.ru Wed Aug 18 17:48:31 2004 From: jbors at mail.ru (Dmitry Borisov) Date: Thu, 19 Aug 2004 01:48:31 +0400 Subject: Some weird benchmarking numbers Message-ID: Guys, Just get back to the shootout site and was redirected here: http://shootout.alioth.debian.org/index.php After I saw psyco having the same benchmarks as Python I tested that by myself and found those numbers to be totally odd. Here are the tests I've made so far: ( http://shootout.alioth.debian.org/bench/lists/ ) c:\bors>list.py 100 10000 Without psyco 5.00699996948 10000 With psyco 3.02399992943 ( http://shootout.alioth.debian.org/bench/sumcol/ ) c:\bors>sum.py 100000 4999950000 Without psyco 0.0999999046326 4999950000 With psyco 0.0599999427795 ( http://shootout.alioth.debian.org/bench/ary/ ) c:\bors>ary3.py 10000 1000 10000000 Without psyco 5.66899991035 1000 10000000 With psyco 1.1210000515 I'll try to contact those guys to have it corrected. Anyone volunteer to have other tests compiled ? Thanks, Dmitry/ From jmdeschamps at cvm.qc.ca Mon Aug 16 23:28:59 2004 From: jmdeschamps at cvm.qc.ca (jmdeschamps) Date: 16 Aug 2004 20:28:59 -0700 Subject: Flython? References: <411cbcb1$0$3894$4d4ebb8e@news.nl.uu.net> <30260531.0408131856.5ef3b0d3@posting.google.com> <2oc547F86br8U1@uni-berlin.de> Message-ID: <3d06fae9.0408161928.555b1539@posting.google.com> Daniel Ellison wrote in message news:<2oc547F86br8U1 at uni-berlin.de>... > Peter Hansen wrote: > > simo wrote: > > > >> There's a few libraries for making SVG files in PHP, so there may be > >> Python versions too, but if you want ActionScript then I guess you're > >> determined to go with Flash instead..... > > > > > > Well, SVG and ActionScript have very little, if anything, in > > common. On the other hand SVG has much overlap with the rest > > of the "Flash" system (taken as a nebulous whole), and when > > supplemented with Javascript, in systems that can handle that, > > it starts becoming somewhat similar in many ways. > > > > On the other hand, so far I haven't seen signs that SVG > > support has advanced enough to really be on par with the > > capabilities (mostly in terms of speed and simplicity) of > > the little bit of Flash/ActionScript that interests me. > > Not to mention the size and ubiquity of the browser plugin. > > > > > My personal goal with this (and I believe Dan's as well) > > is to be able to create GUI software using ActionScript > > to write (roughly) the "view" and "controller" portions, > > with the back end ("model") implemented elsewhere (i.e. > > on a server) with Python. > > Yes, I'd have to agree with that. The point isn't to get a free > replacement for the Flash authoring environment. I own a copy of Flash, > and know quite well how to use it: I've been using and programming Flash > since v4. No, we want a Pythonic way of producing Flash "swf" files, and > in doing so, simplifying (at least) the "view" considerably, and at the > same time creating a much more appropriate interface for web applications. > ... > > Dan Well, what about Ming ??? http://www.freenet.org.nz/python/ming I haven't been able to compile it from source for python 2.3, but maybe someone out there can . Jean-Marc PS I've asked for help on this topic a few times in this list - to no avail though, so I don't know if anyone as ever done it! From grv575 at hotmail.com Mon Aug 9 01:17:13 2004 From: grv575 at hotmail.com (grv) Date: Mon, 9 Aug 2004 05:17:13 +0000 (UTC) Subject: numarray speed question References: <953AD3D0Didtoken@128.91.2.239> <953C4DD4idtoken@128.91.2.239> <144d0df.0408070828.338f8c19@posting.google.com> Message-ID: <9540516Didtoken@128.91.2.239> cookedm+news at physics.mcmaster.ca (David M. Cooke) wrote in : >At some point, grv575 at hotmail.com (grv575) wrote: >> Heh. Try timing the example I gave (a += 5) using byteswapped vs. >> byteswap(). It's fairly fast to do the byteswap. If you go the >> interpretation way (byteswapped) then all subsequent array operations >> are at least an order of magnitude slower (5 million elements test >> example). > >You mean something like >a = arange(0, 5000000, type=Float64).byteswapped() >a += 5 > >vs. >a = arange(0, 5000000, type=Float64) >a.byteswap() >a += 5 > >? I get the same time for the a+=5 in each case -- and it's only twice >as slow as operating on a non-byteswapped version. Note that numarray >calls the ufunc add routine with non-byteswapped numbers; it takes a >block, orders it correctly, then adds 5 to that, does the byteswap on >the result, and stores that back. (You're not making a full copy of >the array; just a large enough section at a time to do useful work.) It must be using some sort of cache for the multiplication. Seems like on the first run it takes 6 seconds and subsequently .05 seconds for either version. >Maybe what you need is a package designed for *small* arrays ( < 1000). >Simple C wrappers; just C doubles and ints, no byteswap, non-aligned. >Maybe a fixed number of dimensions. Probably easy to throw something >together using Pyrex. Or, wrap blitz++ with boost::python. I'll check out Numeric first. Would rather have a drop-in solution (which hopefully will get more optimized in future releases) rather than hacking my own wrappers. Is it some purist mentality that's keeping numarray from dropping to C code for the time-critical routines? Or can a lot of the speed issues be attributed to the overhead of using objects for the library (numarray does seem more general)? From roy at panix.com Wed Aug 4 12:58:55 2004 From: roy at panix.com (Roy Smith) Date: Wed, 04 Aug 2004 12:58:55 -0400 Subject: help: Unit test fixture returning the same object References: <9895e897.0408031533.26720ba0@posting.google.com> <9895e897.0408040851.21ac7caa@posting.google.com> Message-ID: michael_mccracken at mac.com (Michael McCracken) wrote: > So, I'm still surprised that id() would point to the same object every > time, but I'm willing to believe it. However, I don't think that's the > only thing that's going on - the reason I noticed this in the first > place is that the setUp method was opening a file and populating some > lists in my File object, and those lists were accumulating objects > between test methods. My first guess would be that you're using class variables instead of instance variables, but you say: > I don't think I'm accidentally using class variables so I'm stumped. Can you post your code? From ajsiegel at optonline.com Mon Aug 23 19:17:25 2004 From: ajsiegel at optonline.com (Arthur) Date: Mon, 23 Aug 2004 23:17:25 GMT Subject: __name__ becoming read-write? References: <3b8ki0tlphodtt8ge8an274qp78ihp1i3n@4ax.com> Message-ID: On Tue, 24 Aug 2004 03:17:42 +1000, Anthony Baxter wrote: >On Mon, 23 Aug 2004 17:00:39 GMT, Arthur wrote: >> I see the point. >> >> But.. there is always a but. >> >> I'm thinking now a special sytnax item in the __form__ at the top of >> function that would: >> >> 1) put one on notice that the function is to be transformed (as in >> "see below"). >> >> 2) allow a name to be assigned to it, which will become the >> transform's __name__. > >This is a bad idea - code inside the function should be executed when >the function is executed. docstrings are a special-case (because >they're not actually code), Well - accepted that you identify this issue. I would be curious if you could see the sense of the apporach I am suggesting outside of this issue. > >def doc(str): > def endoculate(func, str=str): > func.__doc__ = str > return func > >def frobulate(metawhatsit): I am old enough - I think - to have been frobutaling metawhatsits since before you were born. But have not been, as it happens. So I recognize that my solution might be a bit frobulated -technically. A little fortipation is perhaps all it needs, though. >Paul Morrow's idea of special magic __foo__ inside the function is >deeply magical, and not likely to make any new users running across it >any happier. Well I still see - by far - that best fallback position as A1 (the alpha 2 implementation) - precisely because it implies black magic. At least to me. The least thing I want to see is sweeter, more embedded syntax for this stuff. So I am totally off the "how do we improve the syntax" bus. > "So wait, this stuff that _looks_ like code in a >function, isn't actually? what the hell?" The new syntax[1] for >decorators is at least very obvious that something _new_ is going on. I am thinking (and I think Paul is thinking) that we can say the same thing, succintly, in a manner that has precedence in the language Mine's a one-liner that does not totally relieve the magicians burden to be - somwhere down the line - a bit expressive Art From skip at pobox.com Sat Aug 14 18:38:15 2004 From: skip at pobox.com (Skip Montanaro) Date: Sat, 14 Aug 2004 17:38:15 -0500 Subject: PEP 318 decorators are not Decorators In-Reply-To: References: Message-ID: <16670.37975.895230.979290@montanaro.dyndns.org> Arien> 3) Won't most programmers think GoF decorators before Arien> compiler syntax tree decorators? Skip> Not if they are unfamiliar with the GoF patterns (myself included). Arien> Google: ... BFD. Sure, there are tons more application programmers in the world than compiler geeks, so Google returns many more hits for GoF-style decorators. So? The thing is, just because in a verbal Rohrschach test you think "GoF" when someone says "decorator" doesn't mean everybody else will (or should). Hell, when someone says "decorator" I usually think of "Queer Eye for the Straight Guy". now-where-were-my-fabric-swatches?-ly, y'rs, Skip From zathras at thwackety.com Sun Aug 22 19:23:32 2004 From: zathras at thwackety.com (Michael Sparks) Date: Mon, 23 Aug 2004 00:23:32 +0100 (BST) Subject: J2 proposal: keyword In-Reply-To: <7xwtzryql2.fsf@ruckus.brouhaha.com> Message-ID: On 22 Aug 2004, Paul Rubin wrote: > "Robert Brewer" writes: > > -Candidates for keywords have fallen into two or three camps, and > > emphasize different aspects of decorators: > > > > -Declarative: declare, predef, moddef > > -Transformative: transform, wrap, modify, mutate > > -Attributive/Annotative: amend, using, having > > -Directive: pragma, signify > > -Associative: helper, qualify, qual, meta > > -Cross-cutting: imbue, endow, bestow, embellish, extend, accum, glom, > > confer > > -Prepositions/Adverbs: using, through, per, via, by > > Not sure where these would go: prologue, preamble, preface > > How about something like "def_using"? How is def_using different from "using ... def ..." ? ;-) FWIW, I've spent a significant chunk of today after getting the patch for J2 working looking at what keywords clash and what doesn't. * decorate, transform and declare have clashes with several easy to find projects. This includes commonly used things like mailman & pyrex. * "using" appears to be used only by python itself in webbrowser.py in the get function as a single named parameter, however which I can't find any project using it. I discovered this after replacing "decorate" with "using" and rerunning the test suite... Incidentally the syntax also allows code like this: using: staticmethod synchronised memoise deprecated def: foo(bar): "This function foos bars all day long" pass Personally, I think that's quite nice. I've not posted the updated patch yet because I'm looking at the short/single line version. Projects I've grepped (and looked through the results) through include: wxPython, libxml2, SWIG, PyXML, ZODB4, distutils (as a standalone) egenix-mx, Redfoot RDF tools, PyLucene, dbxml libxslt, jabber-py, PyEgads, PyChecker, soappy m2crypto, epydoc, 4suite, Chandler At some point Zope and Twisted need checking as well. (I'd like to check most things, but those 2 strike me as important checks) On a more general note, I think when suggesting a new keyword how widely used a keyword is should be taken into account, which really needs to take into account how widely used projects are that use the keyword. At the end of the day, hopefully this helps Guido and everyone make a decision, and helps build consensus either in favour of keyword based (and a keyword), or towards the current @pie syntax. Regards, Michael. From sbabbitt at commspeed.net Thu Aug 26 21:43:39 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Thu, 26 Aug 2004 18:43:39 -0700 Subject: Newbie question on dictionary!!! References: <494182a9.0408261150.a4c767f@posting.google.com> Message-ID: <1093571530.913447@news.commspeed.net> "Balaji" wrote in message news:494182a9.0408261150.a4c767f at posting.google.com... > Hello everybody... > > I want to ask a simple question. > > Suppose I have an list say g=['a','b','c','d'] > > and I have an dictionary say k={'b':20,'a':10} > > Now I want to sort this dictionary on the basis of the list and if it > doesnt find any of the element in the list then I wud like to replace > it with zero.. > > so I would like to modify k into {'a':10,'b':20,'c':0,'d':0} > > I have tried all the built in associated with dict and lists but was > not able to come up with an solution... > > Can anyone help... Dictionaries are not sortable but you can easily access the values in an sorted order, list = ['a','b','d'] dict = {'a':123,'c':456,'b':789} newdict = {} l = dict.keys() + list l.sort() for i in l: if dict.has_key(i): newdict[i] = dict[i] else: newdict[i] = 0 dict = newdict That should do it, Tom print dict[i] Tom From martindemello at yahoo.com Thu Aug 26 07:00:19 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Thu, 26 Aug 2004 11:00:19 GMT Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> <1gj4fb5.607xsc51izh8N%aleaxit@yahoo.com> Message-ID: <7pjXc.209955$M95.182424@pd7tw1no> Alex Martelli wrote: > Not leaving stylistic choice (which would lead to more than one obvious > way to do it) is quite consonant with the Zen of Python. Of course one > can't always reach what's preferable, but "your main point" which is > presumably meant as a criticism of this design choice comes across as > praise: the design choice follows the overall design's philosophy. I still feel the the One Obvious Way should have been to return self... > Guido doesn't like method chaining, so he made a design choice that did > not allow method chaining, and did not give several equally obvious ways But that's pretty hard to argue with :) martin From maxwell at ldc.upenn.edu Tue Aug 31 19:29:04 2004 From: maxwell at ldc.upenn.edu (Mike Maxwell) Date: Tue, 31 Aug 2004 19:29:04 -0400 Subject: sys.stdin.readline() In-Reply-To: References: <367a4461.0408311221.30866c09@posting.google.com> Message-ID: Hallvard B Furuseth wrote: > Mike Maxwell wrote: >>When I invoke readline() in a for loop, why does it return a series of >>one-char strings, rather than the full line? >> >>>>>for sL in sys.stdin.readline(): print sL > > It does return a full line. *One* line. Then your loop iterates > over the characters in that line. LoL, thanks! > Try `for sL in sys.stdin.xreadlines(): print sL'. > Or in newer Pythons, simply `for sL in sys.stdin: print sL'. I think I saw that, but when I tried it, I got: /lib/python2.3/pydoc.py:250: DeprecationWarning: xreadlines is deprecated; use 'for line in file'. --which got me off on this dead end. What I was originally trying to do, is to implement a one-liner that would act something like 'sed', but applying to Unicode characters. An example would have a command that looked something like "s/u'\u0D0A'//" i.e. delete all instances of the Unicode char U+0D0A (which you can't do with 'sed', at least not the version that I'm using). The guy down the hall does these kinds of things with perl one-liners, but I have more dignity than to use perl... Unfortunately, it's looking more and more complex to do one-liners like this in Python. Am I overlooking s.t.? Mike Maxwell From steven.bethard at gmail.com Tue Aug 10 12:55:29 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: 10 Aug 2004 09:55:29 -0700 Subject: @decorator syntax is sugar, but for what exactly? (decorator libraries). References: Message-ID: Andrew Durdin wrote in message news:... > Well, I think I agree with the principle of limiting the expressions > to dotted names. Some of the possibilities if you allow arbitrary > expressions are pretty hairy: > > """ > Things someone might want to do, ordered roughly from most reasonable > to least reasonable ;) > @foo().bar() > @foo or bar > @mydecorators['foo'] > @lambda f: foo(f) or bar(f) > """ > (from http://mail.python.org/pipermail/python-dev/2004-August/046673.html) I don't remember who, but someone already mentioned that you can do all of these things with the limited syntax if you really want to, either with operator.* or eval: @eval("foo().bar()") @eval("foo or bar") @operator.getitem(mydecorators, 'foo') @eval("lambda f: foo(f) or bar(f)") There are probably ways to avoid some of the evals, but I haven't really thought too hard about it. Steve From max at alcyone.com Tue Aug 17 17:32:30 2004 From: max at alcyone.com (Erik Max Francis) Date: Tue, 17 Aug 2004 14:32:30 -0700 Subject: Mind.py References: <41220b22@news.victoria.tc.ca> Message-ID: <4122796E.9652CCAE@alcyone.com> "Arthur T. Murray" wrote: > Now, suppose that you wanted to write an AI in Python that would > implement your mind-model and allow it to grow, mutate, develop. > Here is one possible scenario. http://www.nothingisreal.com/mentifex -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ Can I be your friend / 'Till the end -- India Arie From anthonybaxter at gmail.com Sun Aug 22 12:44:59 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Mon, 23 Aug 2004 02:44:59 +1000 Subject: On consensus decision-making (was Re: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WEDONE?) In-Reply-To: References: Message-ID: On 22 Aug 2004 19:36:38 +0300, Ville Vainio wrote: > So, to proceed building community consensus for J2, the community > needs to be asked whether they would block J2 (possibly with the > "using" keyword) in favor of another non- at pie syntax? I'd phrase it more as "does anyone have any absolute show-stopper problems with this syntax?" Plenty of people will hate _any_ new syntax - often (based on the hate mail I've received) for no clearly articulated reasons. From zanesdad at bellsouth.net Tue Aug 31 18:56:06 2004 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Tue, 31 Aug 2004 18:56:06 -0400 Subject: Bandwidth Calculator In-Reply-To: <10j9plefkvdfq96@corp.supernews.com> References: <10j9plefkvdfq96@corp.supernews.com> Message-ID: <41350206.9010106@bellsouth.net> Maboroshi wrote: >Hi I was wondering if there was anyway of determing the use of Bandwidth on >a remote computer in python through the ip address > >Any Ideas Cheers > >Maboroshi > > > > If the remote computer responds to SNMP and has the MIB available to respond to a bandwidth query, you may want to try PySNMP: http://pysnmp.sourceforge.net/ I've never used it, so I can't attest to its functionality. Jeremy From alanmk at hotmail.com Sun Aug 8 10:40:10 2004 From: alanmk at hotmail.com (Alan Kennedy) Date: Sun, 08 Aug 2004 15:40:10 +0100 Subject: @decorator syntax is sugar, but for what exactly? (decorator libraries). In-Reply-To: References: Message-ID: [Anthony Baxter] > And no, you can't decorate lambda. That > would be an obscenity wrapped in a heresy and smacked with the > ugly stick. +1 QOTW >;-) -- alan kennedy ------------------------------------------------------ check http headers here: http://xhaus.com/headers email alan: http://xhaus.com/contact/alan From grante at visi.com Mon Aug 30 18:38:47 2004 From: grante at visi.com (Grant Edwards) Date: 30 Aug 2004 22:38:47 GMT Subject: "Content-Length" header References: <4133abbe$0$65600$a1866201@newsreader.visi.com> Message-ID: <4133ac77$0$65600$a1866201@newsreader.visi.com> On 2004-08-30, Grant Edwards wrote: > On 2004-08-30, Peter Kleiweg wrote: >> Justin schreef: >> >>> I found the answer. After about 3 hours of agonizing over it >>> it turned out to be CASE some webservers are CASE SENSITVE >>> about their urls and some are not. >> >> There are case-insensitive webservers? > > Sure. Most are. AFAIK, apache on Unix has always been case > sensitve. Doh. I obviously misread that... -- Grant Edwards grante Yow! VICARIOUSLY at experience some reason visi.com to LIVE!! From ialbert at mailblocks.com Wed Aug 18 16:28:59 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Wed, 18 Aug 2004 16:28:59 -0400 Subject: age of Python programmers In-Reply-To: References: Message-ID: 32, perl and java refugee From scobloke2 at infotop.co.uk Sat Aug 28 11:16:36 2004 From: scobloke2 at infotop.co.uk (Ian Wilson) Date: Sat, 28 Aug 2004 15:16:36 +0000 (UTC) Subject: Xah Lee's Unixism In-Reply-To: References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4dyXc.25792$Ot3.22106@twister.nyc.rr.com> <878yc0ucyl.fsf@thalassa.informatimago.com> <20040827135423.154$1T@newsreader.com> Message-ID: David Schwartz wrote: > wrote in message > news:20040827135423.154$1T at newsreader.com... > > >>"David Schwartz" wrote: > > >>> I don't follow you at all. I think you'll find the most useful, >>>meaningful complaints about, say, a Ford Explorer from the people who >>>drive one every day. > > >>And if they continue to drive one everyday, perhaps you would conclude >>that their complaints are insincere. > > > That's a load of crap. > > DS > > You're both right but ... Xah Lee: "I'm starting my own cult to exterminate morons on this earth. Two things are on the top of my agenda: Unixism and Perl." Pascal Bourguignon: Is more like Joe Blow: I'm going to exterminate all morons who drive a Ford Explorer. Fred Bloggs: But Joe, you drive a Ford Explorer! Rather than Joe Blow: Ford Explorers are a little bit expensive to service and the doors squeak after a couple of years. Fred Bloggs: Thanks for the tip Joe, I see you drive one, so you should know. From tjreedy at udel.edu Sun Aug 29 03:11:20 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 29 Aug 2004 03:11:20 -0400 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com><1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com><7xzn4gwgea.fsf@ruckus.brouhaha.com><1gj7a1o.1a5d2q410jsn2kN%aleaxit@yahoo.com><7xisb4xnh5.fsf@ruckus.brouhaha.com><1gj7c1a.tfdm14p3hclcN%aleaxit@yahoo.com><7xd61benm9.fsf@ruckus.brouhaha.com><1gj82n3.1ylkr3nierngmN%aleaxit@yahoo.com><7xd61b8uh2.fsf@ruckus.brouhaha.com> <7x1xhqg3kb.fsf@ruckus.brouhaha.com> Message-ID: "Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message news:7x1xhqg3kb.fsf at ruckus.brouhaha.com... > "Terry Reedy" writes: >> 'import x' is syntactic sugar for 'x = __import__('x')'. I do not see >> it >> as necessary that sugar for the common case need cover every possible >> case. >> So, how about giving __import__ had an optional param 'signed' defaulted >> to >> False, to allow signed =True or signed = CA? > > Man, that __import__ thing is ugly. Yes... but importing from signed zips is sufficiently rare and esoteric that I would not see surface ugliness that accompanies using current syntax as the most important consideration. > I think it's better to extend the syntax, e.g. > import x(a,b) => __import__('x', {'a':None, 'b':None}) > import x(a=v1,b=v2)=> __import__('x', {'a':v1, 'b':v2}) Identifier(args) is currently a call of identifier with args and overloading that syntax to mean somthing similar but different is, to me, even uglier in a different sort of way. Terry J. Reedy From sholden at flexal.cs.usyd.edu.au Mon Aug 16 01:06:37 2004 From: sholden at flexal.cs.usyd.edu.au (Sam Holden) Date: 16 Aug 2004 05:06:37 GMT Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> <30260531.0408131853.18ec2446@posting.google.com> Message-ID: On Mon, 16 Aug 2004 00:44:32 -0400, Peter Hansen wrote: > simo wrote: > >> I'm a Perl programmer at heart - well that and PHP, plus the odd >> dabbling in C/C++/C# etc. >> >> Anyway, the thought of indentation instead of curly braces really put >> me off to start with, > > Ah, good. Someone who was really there, instead of hearsay. > > Please, *why* did it put you off? > > Didn't you already indent your code consistently? > > Didn't you think that the removal of those braces would immediately > make the code more readable (fewer lines, fewer extra cruft to > distract the eye) and easier to type? > > I'm curious why more people don't have "neat!" as their very > first thought on encountering this, rather than "yuck!". Many moons ago when I first programmed in python I disliked the use of indentation instead of curly braces. Solely because I was (and still am) from the tab school of indentation but when copy-n-pasting sample code from an x-term or a web browser spaces would get inserted and the code wouldn't be valid. When writing code this isn't a real problem (since not much copy-n-paste happens), but when playing around with things and trying stuff out it makes things more painful than they need to be. Of course that's a problem with the tools and not with the language - a better editor would fix that as would "smarter" copy-n-paste. But it was annoying. The same thing crops up with Makefiles, but is even more annoying in that domain. -- Sam Holden From mefjr75 at hotmail.com Sun Aug 8 22:20:07 2004 From: mefjr75 at hotmail.com (M.E.Farmer) Date: 8 Aug 2004 19:20:07 -0700 Subject: Python source colorizer Message-ID: <18282ecb.0408081820.585a0f9c@posting.google.com> Hello c.l.py!, I have just finished this and decided to share. PySourceColor is a module to convert Python source into colored html. Yes it has been done before, but I like this better:) You can easily define your own colorscheme. example usage: # Highlight PySourceColor.py python PySourceColor.py or # Show help python PySourceColor.py -h ###################################################################### # PySourceColor # A hacked up version of the MoinMoin python parser that # was originally submitted / written by J?rgen Hermann to ASPN. # This does not create w3c valid html, but it works on every # browser i've tried so far.(I.E.,Mozilla/Firefox,Opera,wxHTML). # After experimenting with diffrent html vs CSS + html # I settled on plain old html because it works! # Too bad CSS is not supported everywhere yet. # Hacked by M.E.Farmer Jr. 2004 # Python license ###################################################################### import keyword, os, sys import cgi, string, cStringIO import token, tokenize, glob import getopt, webbrowser, time __title__ = 'PySourceColor' __version__ = "ver.1" __date__ = '2 August 2004' __author__ = "M.E.Farmer Jr." __credits__ = '''This was originally submitted / written by J?rgen Hermann to ASPN python recipes. I found it in 2003 and integrated it into an editor. Recent refactoring led me to seperate it. I decided to polish it up a little and release it in the hope it would be useful. Python license M.E.Farmer 2004 ''' # Testing raw and unicode strings # We do nothing with the value just look at colorizing _ = (r'raw',r'''raw''',r"raw",r"""raw""")##Raw test _ = (u'uni',u'''uni''',u"uni",u"""uni""")##Unicode test # Do not edit _DOUBLECOMMENT = token.NT_OFFSET + 1 _CLASS = token.NT_OFFSET + 2 _DEF = token.NT_OFFSET + 3 _TEXT = token.NT_OFFSET + 4 _KEYWORD = token.NT_OFFSET + 5 _SINGLEQUOTE = token.NT_OFFSET + 6 _DOUBLEQUOTE = token.NT_OFFSET + 7 _TRIPLESINGLEQUOTE = token.NT_OFFSET + 8 _TRIPLEDOUBLEQUOTE = token.NT_OFFSET + 9 _BACKGROUND = token.NT_OFFSET + 10 ###################################################################### # Edit colors and styles to taste # Create your own scheme, just copy one below , rename and edit. # Styles are optional: b = bold, i = italic, u = underline # Color is rgb hex and must be specified. sss#RRGGBB # Colorscheme names must start with an underscore: _MyColor ###################################################################### _Null = { token.ERRORTOKEN: '#FF8080',# no edit token.STRING: '#000000',# no edit _TEXT: '#000000',# no edit token.NAME: '#000000',# All Text token.NUMBER: 'b#000000',# 0->10 token.OP: 'b#000000',# ()<>=!.:;^>%, etc... tokenize.COMMENT: 'i#000000',# There are 2 types of comment _DOUBLECOMMENT: '#000000',## Like this _CLASS: 'bu#000000',# Class name _DEF: 'b#000000',# Def name _KEYWORD: 'b#000000',# Python keywords _SINGLEQUOTE: '#000000',# 'SINGLEQUOTE' _DOUBLEQUOTE: '#000000',# "DOUBLEQUOTE" _TRIPLESINGLEQUOTE: '#000000',# '''TRIPLESINGLEQUOTE''' _TRIPLEDOUBLEQUOTE: 'i#000000',# """TRIPLEDOUBLEQUOTE""" _BACKGROUND: '#FFFFFF',# Page background color } _Dark = { token.ERRORTOKEN: '#FF8080',# no edit token.STRING: '#FFFFFF',# no edit _TEXT: '#000000',# no edit token.NAME: '#ffffff',# All Text token.NUMBER: '#FF0000',# 0->10 token.OP: 'b#FAF785',# Operators ()<>=!.:;^>%, etc... tokenize.COMMENT: 'i#45FCA0',# There are 2 types of comment _DOUBLECOMMENT: '#A7C7A9',## Like this _CLASS: 'b#B599FD',# Class name _DEF: 'b#EBAE5C',# Def name _KEYWORD: 'b#8680FF',# Python keywords _SINGLEQUOTE: '#F8BAFE',# 'SINGLEQUOTE' _DOUBLEQUOTE: '#FF80C0',# "DOUBLEQUOTE" _TRIPLESINGLEQUOTE: '#FF9595',# '''TRIPLESINGLEQUOTE''' _TRIPLEDOUBLEQUOTE: '#B3FFFF',# """TRIPLEDOUBLEQUOTE""" _BACKGROUND: '#000000',# Page background color } _Lite = { token.ERRORTOKEN: '#FF8080',# no edit token.STRING: '#000000',# no edit _TEXT: '#000000',# no edit token.NAME: '#000000',# All Text token.NUMBER: '#FF2200',# 0->10 token.OP: 'b#303000',# Operators ()<>=!.:;^>%, etc... tokenize.COMMENT: '#007F00',# There are 2 types of comment _DOUBLECOMMENT: '#606060',## Like this _CLASS: '#0000FF',# Class name _DEF: 'b#BF9B00',# Def name _KEYWORD: 'b#0000AF',# Python keywords _SINGLEQUOTE: '#600080',# 'SINGLEQUOTE' _DOUBLEQUOTE: '#A0008A',# "DOUBLEQUOTE" _TRIPLESINGLEQUOTE: '#4488BB',# '''TRIPLESINGLEQUOTE''' _TRIPLEDOUBLEQUOTE: '#2299BB',# """TRIPLEDOUBLEQUOTE""" _BACKGROUND: '#FFFFFF',# Page background color } _Idle = { token.ERRORTOKEN: '#FF8080',# no edit token.STRING: '#000000',# no edit _TEXT: '#000000',# no edit token.NAME: '#000000',# All Text token.NUMBER: '#000000',# 0->10 token.OP: '#000000',# Operators ()<>=!.:;^>%, etc... tokenize.COMMENT: '#DD0000',# There are 2 types of comment _DOUBLECOMMENT: '#DD0000',## Like this _CLASS: '#0000FF',# Class name _DEF: '#0000FF',# Def name _KEYWORD: '#FF7700',# Python keywords _SINGLEQUOTE: '#00AA00',# 'SINGLEQUOTE' _DOUBLEQUOTE: '#00AA00',# "DOUBLEQUOTE" _TRIPLESINGLEQUOTE: '#00AA00',# '''TRIPLESINGLEQUOTE''' _TRIPLEDOUBLEQUOTE: '#00AA00',# """TRIPLEDOUBLEQUOTE""" _BACKGROUND: '#FFFFFF',# Page background color } _PythonWin = { token.ERRORTOKEN: '#FF8080',# no edit token.STRING: '#000000',# no edit _TEXT: '#000000',# no edit token.NAME: '#303030',# All Text token.NUMBER: '#008080',# 0->10 token.OP: '#000000',# ()<>=!.:;^>%, etc... tokenize.COMMENT: '#007F00',# There are 2 types of comment _DOUBLECOMMENT: '#7F7F7F',## Like this _CLASS: 'b#0000FF',# Class name _DEF: 'b#007F7F',# Def name _KEYWORD: 'b#000080',# Python keywords _SINGLEQUOTE: '#808000',# 'SINGLEQUOTE' _DOUBLEQUOTE: '#808000',# "DOUBLEQUOTE" _TRIPLESINGLEQUOTE: '#808000',# '''TRIPLESINGLEQUOTE''' _TRIPLEDOUBLEQUOTE: '#808000',# """TRIPLEDOUBLEQUOTE""" _BACKGROUND: '#FFFFFF',# Page background color } ################################################################################## def Usage(): print""" _______________________________________________________________________________ Example usage: # To colorize all .py,.pyw files in cwdir you can also use: . or _ python PySourceColor.py -i . # Using long options w/ = python PySourceColor.py --in=c:/myDir/my.py --out=c:/myDir --color=Lite --show # Using short options w/out = python PySourceColor.py -i c:/myDir/ -c Idle # Using any mix python PySourceColor.py --in _ -o=c:/myDir --show ------------------------------------------------------------------------------- This module is designed to colorize python source code. It is a hacked version of MoinMoin python parser recipe. -h or --help Display this help message. -i or --in Input file or dir. (Use any of these for the cwdir . , _ , this) -o or --out Optional, output dir for the colorized source default: output dir is input dir. -c or --color Optional. Null, Dark, Lite, Idle, Pythonwin, create your own! default: Dark -s or --show Optional, Show webpage after creation. default: no show _______________________________________________________________________________ """ def Main(): '''This code gathers the command line arguments and tries to do something reasonable with them ''' try: # try to get command line args opts, args = getopt.getopt(sys.argv[1:], "hsi:o:c:", ["help", "show", "input=", "out=", "color="]) except getopt.GetoptError: # on error print help information and exit: Usage() sys.exit(2) # init some names input = None output = None scheme = None # if we have args then process them for o, a in opts: if o in ("-h", "--help"): Usage() sys.exit() if o in ("-o", "--out"): output = a if o in ("-i", "--input"): input = a if input in('.','_'): input = os.getcwd() if o in ("-s", "--show"): show = 1 else: show = 0 if o in ("-c", "--color"): try: scheme = eval('_%s'%a) except: scheme = None if input == None: # if there was no input specified then we try to # parse ourselves and do it in diffrent flavors. WebIt(sys.argv[0], '/MyDir/null', _Null, 1) WebIt(sys.argv[0], '/MyDir/dark', _Dark, 1) WebIt(sys.argv[0], '/MyDir/lite', _Lite, 1) WebIt(sys.argv[0], '/MyDir/idle', _Idle, 1) WebIt(sys.argv[0], '/MyDir/pythonwin', _PythonWin, 1) else: # if there was at least an input given we can proceed WebAll(input, output, scheme, show) def WebAll(sourcePath, outdir=None, colors=None, show=0): ''' Converts all python source in the given directory to html ''' c=0 # If it is a filename then WebIt if not os.path.isdir(sourcePath): if os.path.isfile(sourcePath): c+=1 WebIt(sourcePath, outdir, colors, show) # If we pass in a dir we need to walkdir for files. # Then we need to colorize them with WebIt else: fileList = WalkDir(sourcePath) if fileList != None: for i in fileList: c+=1 WebIt(i, outdir, colors, show) print'Completed colorizing %s source files.'% str(c) def WebIt(sourcePath, outdir=None, colors=None, show=0): ''' Converts python source to html. ''' print" Converting %s into HTML" % sourcePath if colors == None: # Default colorscheme colors = _Dark # If no outdir is given we use the sourcePath if outdir == None: htmlPath = sourcePath + '.html' else: # If we do give an outdir, and it does # not exist , it will be created. if not os.path.isdir(outdir): os.makedirs(outdir) sourceName = os.path.basename(sourcePath) htmlPath = os.path.join(outdir,sourceName)+'.html' print " Output to %s"%htmlPath # Open the text and do the parsing. source = open(sourcePath).read() Parser(source, colors, sourcePath, open(htmlPath, 'wt')).format(None, None) if show: # load HTML page into the default web browser. # slower than os.startfile or os.system, but more universal try: webbrowser.open_new(htmlPath) except: pass return htmlPath def WalkDir(dir): '''Return a list of .py and .pyw files from a given directory. ''' # Get a list of files that match *.py* GLOB_PATTERN = os.path.join(dir, "*.[p][y]*") pathlist = glob.glob(GLOB_PATTERN) # Now filter out all but py and pyw filterlist = [x for x in pathlist if x.endswith('.py') or x.endswith('.pyw')] if filterlist != []: # if we have a list send it return filterlist else: return None class Parser: """ MoinMoin python parser heavily chopped :) """ def __init__(self, raw, colors, title, out = sys.stdout): ''' Store the source text. ''' self.raw = string.strip(string.expandtabs(raw)) self.out = out self.title = os.path.basename(title) self.ClassFlag = 0 self.DefFlag = 0 self.colors = colors # Name: Date stamp top self.header = 0 # Name: Date stamp bottom self.footer = 0 def format(self, formatter, form): ''' Parse and send the colored source. ''' # Store line offsets in self.lines self.lines = [0, 0] pos = 0 # Gather lines while 1: pos = string.find(self.raw, '\n', pos) + 1 if not pos: break self.lines.append(pos) self.lines.append(len(self.raw)) # Wrap text in a filelike object self.pos = 0 text = cStringIO.StringIO(self.raw) # Html start self.doPageStart() # Parse the source. ## Tokenize calls the __call__ ## function for each token till done. try: tokenize.tokenize(text.readline, self) except tokenize.TokenError, ex: msg = ex[0] line = ex[1][0] self.out.write("

    ERROR: %s

    %s\n" % ( msg, self.raw[self.lines[line]:])) # Html end self.doPageEnd() def __call__(self, toktype, toktext, (srow,scol), (erow,ecol), line): ''' Token handler. ''' style = '' # calculate new positions oldpos = self.pos newpos = self.lines[srow] + scol self.pos = newpos + len(toktext) # handle newlines if toktype in [token.NEWLINE, tokenize.NL]: self.out.write('\n') return # send the original whitespace, if needed if newpos > oldpos: self.out.write(self.raw[oldpos:newpos]) # skip indenting tokens if toktype in [token.INDENT, token.DEDENT]: self.pos = newpos return # map token type to a color group if token.LPAR <= toktype and toktype <= token.OP: toktype = token.OP elif toktype == token.NAME and keyword.iskeyword(toktext): toktype = _KEYWORD # If the keyword is class or def then we set a flag # the next word gets set to the class/def name color. if self.ClassFlag or self.DefFlag: # Sets the color if it was a class or def name if self.ClassFlag: toktype = _CLASS self.ClassFlag = 0 elif self.DefFlag: toktype = _DEF self.DefFlag = 0 else: # Sets a flag if it was a class or def # next token will be colored. if toktext =='class': self.ClassFlag = 1 elif toktext == 'def': self.DefFlag = 1 # Extended to seperate the diffrent string types.. # plus raw and unicode types if toktype == token.STRING: if (toktext[:3] == "'''") or ( toktext[:4] == "r'''") or ( toktext[:4] == "u'''"): toktype = _TRIPLESINGLEQUOTE elif (toktext[:3] == '"""') or ( toktext[:4] == 'r"""') or ( toktext[:4] == 'u"""'): toktype = _TRIPLEDOUBLEQUOTE elif (toktext[:1] == '"') or ( toktext[:2] == 'r"') or ( toktext[:2] == 'u"'): toktype = _DOUBLEQUOTE elif (toktext[:1] == "'") or ( toktext[:2] == "r'") or ( toktext[:2] == "u'"): toktype = _SINGLEQUOTE # Exetended to seperate the diffrent comment types elif toktype == tokenize.COMMENT: if toktext[:2] == "##": toktype = _DOUBLECOMMENT # Get the colors from the dictionary for the standard tokens color = self.colors.get(toktype, self.colors[_TEXT]) otherstart = '' otherend = '' splitpoint = color.find('#') tags = color[:splitpoint].lower() color = color[splitpoint:] # Check for styles and set them if needed..(b=bold, i=italics) if 'b' in tags: otherstart += '' otherend += '' if 'i' in tags: otherstart += '' otherend += '' if 'u' in tags: otherstart += '' otherend += '' # Error tokenizing ..red boxes if toktype == token.ERRORTOKEN: style = ' style="border: solid 1.5pt #FF0000;"' # send text self.out.write('%s' % (color, style, otherstart)) self.out.write(cgi.escape(toktext)) self.out.write('%s'% (otherend,)) return def doPageStart(self): self.out.write('%s\n'% (self.title)) self.out.write('\n'% (__title__,__version__,time.ctime())) self.out.write('\n') # Get background color and check for styles and ignore all but b,i,u color = self.colors.get(_BACKGROUND, self.colors[_TEXT]) color = color[color.find('#'):] if color[:1] != '#': self.out.write('\n') else: self.out.write('\n'% color) # Write a little info at the top. if self.header: self.doPageHeader() self.out.write('
    \n')
            #self.out.write('
    \n')
    
        def doPageHeader(self):
                color = self.colors.get(token.NAME, self.colors[_TEXT])
                color = color[color.find('#'):]
                self.out.write(' %s    %s\n'%
                                                (color, self.title, time.ctime()))
        def doPageFooter(self):
                color = self.colors.get(token.NAME, self.colors[_TEXT])
                color = color[color.find('#'):]
                self.out.write(' %s    %s\n'%
                                                  (color, self.title,time.ctime()))
        def doPageEnd(self):
            self.out.write('
    \n') # Write a little info at the bottom if self.footer: self.doPageFooter() # Write a little info in the web page source self.out.write('\n'% (__title__,__version__,time.ctime())) self.out.write('\n') if __name__ == '__main__': Main() From ivoras at __geri.cc.fer.hr Thu Aug 5 17:07:43 2004 From: ivoras at __geri.cc.fer.hr (Ivan Voras) Date: Thu, 05 Aug 2004 23:07:43 +0200 Subject: psyco out of memory In-Reply-To: References: Message-ID: Michael Hudson wrote: >>Fatal Python error: psyco: out of memory >>Abort (core dumped) > > > Hum. Are you using the ivm or the x86 backend? Don't know. How do I tell? > Also, you might have better luck just using range()... Tried it. Same thing. -- What part of "Ph'nglui mglw'nath Cthulhu R'lyeh wgah'nagl fhtagn" don't you understand? From martin at v.loewis.de Tue Aug 17 14:17:41 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 17 Aug 2004 20:17:41 +0200 Subject: 'ascii' codec can't encode character u'\xf3' In-Reply-To: References: <4120F820.4000703@fusiondementes.com> <4121A8DA.30802@v.loewis.de> Message-ID: <41224bc0$0$13029$9b622d9e@news.freenet.de> Martin Slouf wrote: >>- print a repr() of the unicode object instead of >> the unicode object itself. This will work on all >> terminals, and show hex escapes of non-ASCII characters. > > > just to make sure: > > override the object's __repr__(self) method to st. like: > > class my_string(string): > def __repr__(self) > tmp = unicode(self.attribute1 + " " + self.attribute2) > return tmp > > and use 'my_string' class without any worries instead of classical > string? No. Assume yyy is a Unicode object which potentially contains non-printable characters. Instead of doing print yyy do print repr(yyy) > my system is debian GNU/Linux stable, im using it for a very, very long > time, though i did not changed any terminal settings but the very > basics. My locales are properly set, im using LC_* environment > variables to set default locale to czech environment with ISO-8859-2 > charset. Terminal is capable of displaying 8bit charsets, im not sure > about unicode charsets -- never tried, never needed. I see. Could it be that you are using Python 2.1, then? Because in Python 2.3, printing Czech characters to the terminal should work just fine. Please do Python 2.3.4 (#2, Aug 5 2004, 09:33:45) [GCC 3.3.4 (Debian 1:3.3.4-7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.stdout.encoding 'ISO-8859-15' > if 0: > # Enable to support locale aware default string encodings. > import locale > loc = locale.getdefaultlocale() > if loc[1]: > encoding = loc[1] > > so i guess it is never done :( You don't need to change the default encoding. Instead, sys.stdout.encoding is used for printing to the terminal (in 2.3 and later). > did you yourself changed it? No. It will work out of the box. > well, if a piece of information like you gave to me was contained in > standard python documentation, probably there will be less > misunderstanding about this issue. What piece specifically are you referring to? It is all mentioned in the standard Python documentation. > #! /usr/bin/env python > # -*- coding: UTF-8 -*- > at the begginnig of my every script, the example above still has to > be converted -- because of the iso-8859-1 you use in "L?wis"? Yes, and no. Yes, it still has to be converted. UTF-8 is *not* Unicode; it is a byte encoding, and you cannot mix Unicode strings and byte strings. No, if I use UTF-8 in my source code, then "L?wis" will be encoded in UTF-8, not in ISO-8859-1. > can i ommit the conversion (ie. is it done automatically for me as if > i write > u"Martin v. " + unicode("L?wis", "ISO-8859-1") > )? You can, but you shouldn't. So I won't tell you how you could do that. > dont understand -- which library? The ODBC library, for example, or PyQt. Regards, Martin From tchur at optushome.com.au Tue Aug 3 17:01:05 2004 From: tchur at optushome.com.au (Tim Churches) Date: 04 Aug 2004 07:01:05 +1000 Subject: intersection of 2 strings In-Reply-To: References: Message-ID: <1091566865.1233.6.camel@emilio> On Tue, 2004-08-03 at 22:37, Antoine Logean wrote: > Hi, > > What is the easiest way to get the intersection of two strings in > python (a kind a "and" operator) ? > ex: > > string_1 = "the_car_of_my_fried_is_bigger_as_mine_but_my_girlfriend_is_more_beautifull" > > string_2 = > "my_girlfriend_is_more_beautifull_and_has_blue_eyes" > > and the intersection : > string_1 "and" string_2 = "my_girlfriend_is_more_beautifull" > > thanks for your help >From your example, I suspect that you really want to find the "longest common subsequence" of the two strings, rather than the intersection, because surely the first occurrences of "my" and "is" in string_1 also qualify for being in the the intersection set of string_1 and string_2. It is a bit hard to know what you mean by "intersection" when it is not clear whether you regard the strings as sets of characters or sets of words. There is a public domain implementation of an LCS algorithm by Yusuke Shinyama at http://www.unixuser.org/~euske/python/lcs.py - and it produces the result you are expecting from your test data. -- Tim C PGP/GnuPG Key 1024D/EAF993D0 available from keyservers everywhere or at http://members.optushome.com.au/tchur/pubkey.asc Key fingerprint = 8C22 BF76 33BA B3B5 1D5B EB37 7891 46A9 EAF9 93D0 From anthonybaxter at gmail.com Thu Aug 5 12:41:10 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 02:41:10 +1000 Subject: RELEASED Python 2.4, alpha 2 In-Reply-To: References: <411231C8.3020308@interlink.com.au> Message-ID: On Thu, 5 Aug 2004 12:29:51 -0400, Christopher T King wrote: > What does one do if a decorator raises an exception? def deco(func): raise TypeError @deco def foo(): print "hello" > If it's something > necessary to the functioning of the code (say, classmethod or > staticmethod), then all is as it should be. But what if it's not? What > if you're using a run-time type checking library, or a code optimizer, > that may not be installed? In that case you would most likely want to let > that decoration fail silently. Silently failing is completely non-pythonic. If you really wanted to handle a missing decorator, something like missingdec = lambda x:x would do this for you. > Decorators in general are the right solution for the wrong problem (as I > detailed in another thread). They are being introduced much too > prematurely, and have not been given time to be able to have been thought > through well enough. The @ syntax is the result of trying to shoehorn too > many solutions into one fix. Too prematurely?? staticmethod and classmethod were introduced in 2.2! PyObjC, ctypes, Jython and IronPython can all do with using them, as can rather a lot of other chunks of code. Anything that applies metadata to functions can use this - look at all the various places where people are putting stuff in docstrings as a current hack. > They purport to solve the problems of function type declaration > (class/static), function attributes, runtime type checking, and general > function mangling, when each of these (save general function mangling) > already have distinct solutions in nearly every other language. The first > three problems are currently implemented as hacks in Python that happen to > fall under the category of "general function mangling". Streamlining the > hack is not the answer. Or, alternately, they're another tool in the toolbox, along with metaclasses and the like. Anthony From cliechti at gmx.net Tue Aug 17 16:19:52 2004 From: cliechti at gmx.net (Chris Liechti) Date: Tue, 17 Aug 2004 20:19:52 +0000 (UTC) Subject: serial and threads References: <39ba6e78.0408170215.59f5bfc0@posting.google.com> Message-ID: natunika at gmx.de (Silke) wrote in news:39ba6e78.0408170215.59f5bfc0 at posting.google.com: > I'm trying to write a program in python using the modules > 'serialwin32' and 'thread' to create one thread that writes to a if you mean that serialwin32 from pyserial, then there is an example of a tcp<->serial gateway: http://cvs.sf.net/viewcvs.py/pyserial/pyserial/examples/tcp_serial_redirect .py?rev=1.2&view=auto (one line URL) i'd sugest to import "serial" and not the platform modules. that way you have protablity to other OS for free, and you speak in the same terms as the others do. chris -- Chris From rob at nospam.net Tue Aug 17 09:52:55 2004 From: rob at nospam.net (Robert Ferber) Date: Tue, 17 Aug 2004 15:52:55 +0200 Subject: Databases: Getting values by column name Message-ID: Hi, I can't find any good documentation about the Python-database module, all I found was this rudimentary (no examples, no references) piece here: http://www.python.org/peps/pep-0249.html Anyway, this and also this tutorial here: http://www.devshed.com/c/a/Python/MySQL-Connectivity-With-Python/2/ only use database rows as sequences, ie as arrays with numerical index. This gives you loads of problems when using "select *" and also bad code readability when selecting specific columns. Is there a way to use them as dictionaries, ie with Index-Strings (=column names) as indexes? BTW, is there any good searchable reference to Python's functions, with examples and cross-references to similar functions? Thanks a lot, Robert From della at toglimi.linux.it Fri Aug 20 04:26:27 2004 From: della at toglimi.linux.it (Matteo Dell'Amico) Date: Fri, 20 Aug 2004 08:26:27 GMT Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: I, J2 (I find "transform" a good choice for a keyword), H -- Ciao, Matteo From ajsiegel at optonline.com Mon Aug 30 13:01:49 2004 From: ajsiegel at optonline.com (Arthur) Date: Mon, 30 Aug 2004 17:01:49 GMT Subject: Call for signatories for J2 References: Message-ID: <14JYc.8263$6o3.4262@newsread2.news.atl.earthlink.net> "Robert Brewer" wrote in message news:mailman.2584.1093824257.5135.python-list at python.org... Arthur wrote: > Against. > > With some commitment. > > I have not read the J2 psper... >>Let me know when you have and I'll add your name to the list. I have, now. Nicely crafted. but I do think I had the info I needed to vote, from the discussion. And I am not arguing that J2 is not "better", in some sense. But I am concluding that the normal rules for better don't apply here. There is some other syntactical aim here that I wouldn't call "sugar". Once again, in the context of "decorators", we might need a new word to express what the intention is here. If a core argument in favor is to shortcut programmer input, I think it should be expressed as an unadorned shortcut. And think @ expresses the intent, in this respect more baldly and clearly. Put me as against. It should clinch it for you ;) ART From simoninusa2001 at yahoo.co.uk Sat Aug 21 17:27:56 2004 From: simoninusa2001 at yahoo.co.uk (Simon John) Date: 21 Aug 2004 14:27:56 -0700 Subject: Global config option - import issues again..... Message-ID: I have a program that consists of one main module and lots of small sub-modules. In the main module I open a text file and grep for a language setting, this language setting will then be used as the module name of a config file to import. E.g. "Language=en" means config_en.py is imported as config, "Language=fr" means config_fr.py is imported as config.... I manage this by executing a string of the language/import commmand such as: # execute string like "import config_en as config" global lang_import lang_import = "import config_" + language + " as config" exec lang_import Then the modules imported by the main module refer to config.CONSTANT The problem is, that lang_import cannot be seen outside of the main module, it's not truly global, so "exec lang_import" in the sub-modules doesn't work. I tried defining a method and importing that, but it doesn't work, e.g. # main module def lang(): import config_en as config # sub-module from main_module import lang; lang() Any ideas? Maybe some other way to import a module with a dynamic name.... From ken.beesley at xrce.xerox.com Sun Aug 22 11:37:33 2004 From: ken.beesley at xrce.xerox.com (Ken Beesley) Date: Sun, 22 Aug 2004 17:37:33 +0200 Subject: unicode name for \u000a In-Reply-To: <20040822141125.956A61E4007@bag.python.org> References: <20040822141125.956A61E4007@bag.python.org> Message-ID: <4128BDBD.1020807@xrce.xerox.com> > > >"Martin v. L?wis" writes: > > > >>No. is not a character name. The unicodedata.name function >>returns the official character name, so it MUST NOT return an alias >>(which rules out your second alternative). >> >> > <>Tor Iver Wilhemsen responds: > <>Then why not return None or the empty string instead of raising an > exception? Now that we understand that a number of Unicode characters do not have official names, the intended solution would seem to be the use of the optional second argument to unicodedata.name(unichr [, default]) "If no name is defined, default is returned." As in the following script, which reads a UTF-8 file and prints out the code point value and the name (if any) or "No Name". import sys, codecs, unicodedata fp = codecs.open(sys.argv[1], "r", "utf-8") ustr = fp.read() pos = 0 for char in ustr: print "%d %04x %s" % (pos, ord(char), unicodedata.name(char, "No Name")) pos += 1 From tdelaney at avaya.com Mon Aug 16 23:47:54 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Tue, 17 Aug 2004 13:47:54 +1000 Subject: Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01D58963@au3010avexu1.global.avaya.com> Peter Hansen wrote: >> In what ways would I get dorked if I use this website? > > 1. Please define "dorked" in this context. > > 2. What, if anything, does this have to do with Python. > > 3. Why do you think we might know anything about that site? My presumption is it's spam, and the web site is a trap. Tim Delaney From mwilson at the-wire.com Mon Aug 16 13:59:24 2004 From: mwilson at the-wire.com (Mel Wilson) Date: Mon, 16 Aug 2004 13:59:24 -0400 Subject: Decorator "platform" References: <2nsoofF49frcU1@uni-berlin.de> <87zn50nll4.fsf@pobox.com> <87hdr5mq5g.fsf@pobox.com> Message-ID: <8XPIBls/KPgf089yn@the-wire.com> In article <87hdr5mq5g.fsf at pobox.com>, jjl at pobox.com (John J. Lee) wrote: >I don't doubt the utility, on a case-by-case basis, of some of the >uses of decorators that people are devising, and will continue to >devise. I do fear that this is a pressure towards 'Babel-ization' of >the language. It starts to remind me of a kind of obfuscation, codable in, say, C++, where the visible text of the program is actually irrelevant, and all the real computing is done as side-effects of the constructors. >I don't honestly know whether that fear is justified -- [ ... ] Ditto. Regards. Mel. From reinhold-birkenfeld-nospam at wolke7.net Fri Aug 20 10:09:27 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Fri, 20 Aug 2004 16:09:27 +0200 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: <2omet9Fc2v4mU1@uni-berlin.de> Paul McGuire wrote: [Decorators] J2 J2 J2 Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From martin at v.loewis.de Sun Aug 8 03:38:55 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 08 Aug 2004 09:38:55 +0200 Subject: [Python-Dev] RELEASED Python 2.4, alpha 2 In-Reply-To: References: <411231C8.3020308@interlink.com.au> <4113429a$0$26993$9b622d9e@news.freenet.de> <41137960.6050400@v.loewis.de> <4113dddd$0$12507$9b622d9e@news.freenet.de> Message-ID: <4115D88F.8020802@v.loewis.de> vincent wehren wrote: > Yes. That makes sense. So I checked the registry with regedit. > "HKEY_CURRENT_USER\Software\Classes" seems - for whatever reason - to be > busted for this particular user. At least I can't open it manually with > regedit, so my tentative guess is the same applies to the installer. > Sorry I didn't check this first! Yes, saw that. I'm not faulting you though - I do believe that the behaviour in this case should be improved somehow. Regards, Martin From cookedm+news at physics.mcmaster.ca Sat Aug 21 20:22:05 2004 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Sat, 21 Aug 2004 20:22:05 -0400 Subject: Array of objects in numpy. References: <2olrdjFbgdd0U1@uni-berlin.de> Message-ID: At some point, Pepijn Kenter wrote: > Hi all. > > I'm new to python and want to use it for an assignment. > > I have succesfully implemented a galois field class including the _repr__, > __mul__, __div__, __add__ and __sub__ methods. including __r* variants too? > Basically a galois field is > an integer modulo a prime number. Now I want to make a matrix of these > galois field objects using the numpy library. Constructing, printing and > multiplying arrays of GF's works fine. However there are several functions > that give problems, most importantly: dot, repeat. > > I'm affraid I've forgotten my memmory stick with the code and error > messages :-(, so I have to keep my question general. I'm shooting in the dark here, as I presume you're using Numeric, as opposed to numarray. > If I recall correctly, > the repeat function complained that my GF object didn't have the > __getelem__ method implemented (IMO this should not be necessary), My guess is that you're using Numeric.repeat incorrectly. Note that for Numeric.repeat(a, repeats), a has to be array-like (more specifically, array(a) can work). > the dot function complained about an unsupported type. Don't know about that one. Maybe if you haven't added __rmul__ or __radd__ to your class. > I know this is not the > preffered way of asking for help on usenet but I'd like some feedback so I > can work this weekend on the problem. I can use the dot & repeat with > normal numpy arrays of floats, so I'm sure it is not due to my inexperience > with python. > > Does anybody have experience using object arrays in numpy? Should I be able > to get the dot & repeat function working, and what methods should my GF > object support? Or are there known problems and pitfalls? Have you tried numarray? The numarray.objects module handles object arrays. It's being actively worked on, as opposed to Numeric. -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From skip at pobox.com Wed Aug 11 10:55:32 2004 From: skip at pobox.com (Skip Montanaro) Date: Wed, 11 Aug 2004 09:55:32 -0500 Subject: @decorator syntax is sugar, but for what exactly? (decorator libraries). In-Reply-To: References: Message-ID: <16666.13156.467986.822287@montanaro.dyndns.org> >> Yes (using a class instead of a module simply for convenience): ... Art> Is it me, or this a chilling argument agaisnt where things are Art> going. I'm not sure what you're getting at. Nobody said a decorator's implementation had to be simple. It can, after all, perform pretty arbitrary transformations. Art> But when there is a lot less going on than meets the eye ... Again, I'm confused. Look at just the fib() definition: @martha.memoize def fib(n): assert n >= 0 print n if n <= 1: return 1 return n + fib(n-1) The decorator says the function will be memoized. That memoizing an arbitrary function's values using a dict isn't entirely straightforward shouldn't prevent people from being able to easily memoize functions whose outputs only depend on their inputs. By analogy, I use urllib.urlopen() all the time without completely understanding all the ins and outs of what it does. Perhaps the decorator would be better named "idempotent"? Or were you objecting to something else? Skip From heikowu at ceosg.de Wed Aug 11 13:20:58 2004 From: heikowu at ceosg.de (Heiko Wundram) Date: Wed, 11 Aug 2004 19:20:58 +0200 Subject: rsa implementation question In-Reply-To: <5GkSc.124$O72.121@newssvr14.news.prodigy.com> References: <1092200894.4119a9beb1978@www-mail.usyd.edu.au> <5GkSc.124$O72.121@newssvr14.news.prodigy.com> Message-ID: <200408111920.58037.heikowu@ceosg.de> Am Mittwoch, 11. August 2004 10:21 schrieb Bryan Olson: > I agree with about half of Heiko Wundram's response. Well, with what don't you agree? ;) Anyway, I've not read anywhere that for signing a message it is discredited to use RSA decrypt with private key, encrypt with public key. Basically, what I always implemented is something like (pseudocode): def pad_for_rsa_encrypt(data,algo,n): retv = [data] strlen = len(data) nlen = log2(n)/8 while strlen < nlen-3: data.append() nlen -= len() data.append(chr(algo)) data.append(struct.pack("!H",strlen)) return "".join(data) def unpad_after_rsa_decrypt(data,n): strlen = struct.unpack("!H",data[-2:]) nlen = log2(n)/8 if strlen > nlen-3: raise ValueError, "Invalid size of data in packet." return data[:strlen], ord(data[-3]) def sign(key,data): return key.decrypt(pad_for_rsa_encrypt(sha.new(data).digest(),0,key)) # 0 is for sha algorithm. def verify(key,data,sign): netsgn, algo = unpad_after_rsa_decrypt(key.encrypt(sign),key) if algo <> 0: raise ValueError, "Invalid digest used in packet." datasgn = sha.new(data).digest() return datasgn == netsgn Or something of the like... Anyway, what the deal about this algorithm is that the number of digits of the data used for encryption/decryption is not known in advance with high probability, only the last few digits might be known (length of plaintext encrypted and algorithm used), whereas if you use normal padding (with zeros), the problem domain is limited because only a certain number of positions of the plaintext (e.g. 160 bits when using a digest) actually contain data. This does not make some public-key algorithms weaker (ElGamal), but RSA has to cope with the fact that it doesn't do inherent randomization (so for equal data to sign and equal key, you'll get equal signatures, which is bad!) That's why I would advise you to go use ElGamal, which is much better in this respect, and is patent-free too (well RSA is too, but anyway, the ElGamal family of public-key ciphers always was). And, if you were using it to encrypt/decrypt a symmetric encryption key, you could also pad the algorithm used for encryption into the string, so that only the proper receiving end could get this last bit of info on the encryption method used (security by obscurity, but anyway). So much for what I always did. I really don't know whether this is some form of secure way to go, but at least no cryptography book I read has ever discouraged the use of random padding while encrypting data which is much shorter than the "block size" of a public-key crypto algorithm (esp. for RSA). Heiko. From adurdin at gmail.com Mon Aug 23 02:28:18 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Mon, 23 Aug 2004 16:28:18 +1000 Subject: J2 paper 0.2.1 In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022E36@exchange.hqamor.amorhq.net> References: <3A81C87DC164034AA4E2DDFE11D258E3022E36@exchange.hqamor.amorhq.net> Message-ID: <59e9fd3a04082223283d4c176e@mail.gmail.com> On Sun, 22 Aug 2004 22:19:31 -0700, Robert Brewer wrote: > The first draft of the J2 proposal is ready. You can read it here: > http://www.aminus.org/rbre/python/pydec.html A very nice job. Regarding the suggestion for "using" in Argument III: """ * It "reads correctly" in every use case. """ Can you include an example with the "using" keyword, so that the reader doesn't have to construct one himself to see how this might be so? e.g. using: memoize classmethod synchronize funcattrs(author="Guido Van Rossum") def foo(cls, *args): pass From fakeaddress at nowhere.org Sat Aug 7 02:50:05 2004 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 07 Aug 2004 06:50:05 GMT Subject: Timing Difference: insert vs. append & reverse In-Reply-To: References: <35b736b9.0408020330.53b24ed3@posting.google.com> <1a517b5.0408031027.60554dfb@posting.google.com> <1a517b5.0408041305.3927a6c8@posting.google.com> Message-ID: Tim Peters wrote: > I'm one of the handful of people who might actually "do > something" about this kind of issue, and I was telling you that I > won't. Your chances of seeing what you suggest are highly correlated > with finding someone who will "do something" . I don't know > whether Raymond Hettinger is interested in pursuing this further, but > if he isn't either (that's my guess), then the only realistic chance > is if you do the work yourself. Looking at the source, I'm worried. Append and pop[-1] are not really amortized O(1); at best they're commonly-average O(1). Alternating appends and pops at certain border values will call realloc for every operation. The pop-reallocs free the extra memory; if the allocator uses that memory for other requests, the following append will have to copy the entire list. > In the basic list type, yes, it's more valuable in Python to save the > 8 bytes. The speed of "left end" insert/remove is insignificant for > most Python apps, and is quite fast anyway for small lists. It's a > major concern for *some* Python apps, and the deque type serves those > better than fudging the list type could. The leave-it-to-realloc method seems to be an effort to save one word (either a pointer or a size) per list. With two more words, I think we could make operations on both ends amortized O(1). The only lists for which this would be a substantial portion are empty lists. Currently, empty lists require four words (type_pointer, refcount, size=0, item_pointer=NULL) plus malloc's bookkeeping. Any non-empty list additionally allocates space for at least 8 pointers, plus malloc's bookkeeping. -- --Bryan From saint_infidel at hotmail.com Wed Aug 25 16:16:52 2004 From: saint_infidel at hotmail.com (infidel) Date: 25 Aug 2004 13:16:52 -0700 Subject: Just a quick one References: Message-ID: <97841f5c.0408251216.5acb7524@posting.google.com> "M. Clift" wrote in message news:... > Hi Benjamin, > > Sorry, another question. How do I remove the brackets form the list? > Name_List.remove('(') doesn't work. The brackets or parentheses are not part of the list or tuple, they are part of the string representation of the list or tuple. If you want to turn the list ('Bob', 'Mary') into the string 'Bob, Mary', use: ', '.join(('Bob', 'Mary')) -infi From elainejackson7355 at home.com Tue Aug 17 00:01:01 2004 From: elainejackson7355 at home.com (Elaine Jackson) Date: Tue, 17 Aug 2004 04:01:01 GMT Subject: music resources References: Message-ID: <1qfUc.128080$gE.84239@pd7tw3no> Thanks for your suggestions. What I want to do with music is to learn it and play with it. Even an auditory equivalent of "MS Paint" would probably keep me busy for some time, since I'm essentially starting from zero. "Eric Pederson" wrote in message news:mailman.1769.1092710233.5135.python-list at python.org... > Elaine Jackson wrote: > > Is there such a thing as an executable language for music? If not, why > > not? And > > if yes, where can I find it? Naturally the ideal thing would be if > > such a > > language were implemented within python, but I would be willing to > > learn a > > lesser programming language if I had a reasonable assurance that it > > had what I'm > > looking for. There is some interesting stuff out there: Check out the Python sounds project: http://pythonsound.sourceforge.net/ Also, there is AthenaCL which I believe is both written in Python and Python scriptable, although I have not had time to play with it: http://www.download.com/AthenaCL/3000-2170-10204823.html I think there are also more routine libraries that just manipulate sound waves, etc. What do you want to do with music? (talk about an interesting data set!) Eric P. Eric Pederson http://www.songzilla.blogspot.com ::::::::::::::::::::::::::::::::::: domainNot="@something.com" domainIs=domainNot.replace("s","z") ePrefix="".join([chr(ord(x)+1) for x in "do"]) mailMeAt=ePrefix+domainIs ::::::::::::::::::::::::::::::::::: From __peter__ at web.de Fri Aug 20 04:28:32 2004 From: __peter__ at web.de (Peter Otten) Date: Fri, 20 Aug 2004 10:28:32 +0200 Subject: Alternative decorator syntax decision References: <7x3c2iw9ig.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > "Paul McGuire" writes: >> I would propose a multivote survey: each poster gets 3 votes among the >> lettered choices on the Wiki page above. You can use all 3 for a single >> option, or split them across 2 or 3 options if you are open to more than >> one. > > 1. My favorite variant was not in the list. I suggest that you add it. > 2. Any of the choices will have far reaching consequences that aren't > yet thought out very well. There is not yet enough experience > programming with the existing mechanisms (classmethods etc.) to > be sure what's really worthwhile. The PyObjC and (some?) Zope people say they need "fancy" decorators badly. Classmethods are comparatively straight-forward. > 3. There's not all that much discussion on the wiki of how other > languages do this stuff. I think Java and C# have been discussed on python-dev. Again you could share your experience. > 4. There's nowhere near consensus that any of the choices presented so > far are not plain horrible. > > My conclusion: Python 2.4 should not have new decorator syntax. Stay > with the existing stuff, for now. D'accord. The most promising way to achieve that is to collect arguments against the pie that can convince Guido and find a contender that has at least the same level of support in the community. On a side note, I think it strange that aesthetics are ruled out. Certainly neither the decorator suite nore the pies can be advertised as "executable pseudocode". > Discussion and exploration should continue and the question should be > revisited for 2.5. For 2.4, extend the current kludgy (decorators > separated from the function) mechanism if needed to provide necessary > functionality, but deprecate any new such feature as soon as it's > introduced, with the explanation that it's exploratory. Those who need decorators will adopt the included syntax even if it is not their favourite. I guess that unless technical problems appear yours will be an effective vote for the @decorator. Peter From porky_pig_jr at my-deja.com Thu Aug 19 16:26:17 2004 From: porky_pig_jr at my-deja.com (Porky Pig Jr) Date: 19 Aug 2004 13:26:17 -0700 Subject: IDLE under Cygwin - no toolbar menu. Any idea why? Message-ID: <56cfb0e3.0408191226.43caa96b@posting.google.com> A question for those using python under Cygwin. I've just installed the latest distribution with python 2.3.4. One problem I have is when I start IDLE, it doesn't show toolbar menu (either shell window or edit window). Does anyone know why and if there is a workaround? TIA. (I know I should probably ask Cygwin folks, but just want to check it here first) From robin at SPAMREMOVEjessikat.fsnet.co.uk Sat Aug 21 04:50:10 2004 From: robin at SPAMREMOVEjessikat.fsnet.co.uk (Robin Becker) Date: Sat, 21 Aug 2004 09:50:10 +0100 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: <41270CC2.7000105@jessikat.fsnet.co.uk> I vote B B B -- Robin Becker From zathras at thwackety.com Sat Aug 28 08:00:31 2004 From: zathras at thwackety.com (Michael Sparks) Date: Sat, 28 Aug 2004 13:00:31 +0100 (BST) Subject: allowing braces around suites In-Reply-To: <1rllg0cb3m.fsf@rovereto.ifi.uio.no> Message-ID: On Sat, 28 Aug 2004, Kjetil Torgrim Homme wrote: > after all, code in _any_ language written by a professional > will have strict indentation. Not all code is written by professional programmers. Not all professionals who write code are professional programmers - biologists, linguists, physicists spring to mind. Those groups are not interested in programming they are interested in solving problems. They do not care about syntax, they care about solutions. They care about sharing solutions. Do you share solutions using pseudocode, or what you actually used? With python you can do the latter, but it looks like the former. You can share that with non-technical people - they might not understand the details, but the lack of extraneous syntax will make this simpler, and they appreciate being treated as equals. For me, the lack of extraneous syntax and expecting the compiler to work harder to leave code cleaner is one of the things that makes python python. This actually means though that any tool that works with the syntax needs to work a bit harder, but for me, the benefits are huge. Contrast this approach with Perl's approach. (I really like perl as well BTW) In perl there is explicit annotation of almost everything as to what it means. You explicitly indicated scalars, arrays and hashes. If you need to derefence an object the most reliable way is to use very explicit syntax hooks. Similarly the braces are much more explicit than in a language like C they aren't optional for block statements. If you want _consistent_ semantics for all function calls, you have to use an & symbol and so on. This comes at cost however. The cost is that the large body of code written by non-professionals can be difficult to read, merge and encourages bad coding styles. (I've seen some very bad perl code from people who claim to be professionals as well :-( ) I've yet to see this to the same extent with python. It very naturally discourages bad coding styles whilst encouraging clean looking code - including from new users. For me, this is part of what makes python unique, and a large part of that in my eyes stems from making the work of tools harder. Optional braces, AND keeping fixed indentation is simply adding a crutch for poor tools. The solution isn't to change the language in my eyes, the solution is to produce better tools. After all, the following is legal syntax in python if you really want close markers: end = None for ch in "hello": if ch == "l": print "Rhubarb" end print ch, end Personally I think that's like macro abuse in C where I've seen people try to make C look like pascal, but it is valid - and it allows you to add a crutch for your tools without changing the language or affecting readability significantly. All in my opinion of course. As has been said though - please do write the PEP, I agree with the sentiment that this would be a good way of rejecting it permenently ;-) Best Regards, Michael. From dfan at harmonixmusic.com Sat Aug 21 12:02:46 2004 From: dfan at harmonixmusic.com (Dan Schmidt) Date: 21 Aug 2004 12:02:46 -0400 Subject: Fate of lambda, Functional Programming in Python... References: <412636D1.6070808@noaa.gov> <41265E67.A08409A6@juno.com> Message-ID: Jeff Sandys writes: | How about this use of lambda? | (from another post 'RE: How to sort this kind of list easily?' today) | | | Or if you want to sort only on your Id, use a lambda: | | l.sort(lambda x,y: cmp(x[0],y[0])) In 2.4, you actually don't need a lambda: l.sort( key = operator.itemgetter( 0 ) ) but I too would be very sad to see anonymous functions go away, although I find the current syntax pretty ugly. Dan -- http://www.dfan.org From fredrik at pythonware.com Wed Aug 11 14:08:15 2004 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 11 Aug 2004 20:08:15 +0200 Subject: PEP-0318 References: <41122FC2.1080608@interlink.com.au><4114152f@nntp.zianet.com> <4116bc20$1@nntp.zianet.com><6NCdncg4ssq28orcRVn-uQ@powergate.ca> <411a5cee$1@nntp.zianet.com> Message-ID: Mark Bottjer wrote: > But it *isn't* part of the core language. I think that's the whole point. @decorator does > something that no other statement in Python does calling a function with an argument? that's a pretty common operation, if you're asking me From egbert.list at hccnet.nl Tue Aug 10 11:37:30 2004 From: egbert.list at hccnet.nl (Egbert Bouwman) Date: Tue, 10 Aug 2004 17:37:30 +0200 Subject: OO menu management Message-ID: <20040810153730.GA2787@mirk.lan> I have difficulties in organizing my menus, especially in linking them to the underlying application logic. I try to follow the OO rules: the gui classes, in their own module gui.py, do the gui work, in my case with pygtk, and they know nothing about the application logic in app.py. So a button in the gui starts a callback that in realty is a method in app.py, and the name of that callback is given to the gui via an argument. That works well for a single button. With a menu system it is different, because there are so many buttons. I still have for each menu button: - a callback-name variable in the gui class - a real callback method in the application class and now a dictionary that links those two. That dictionary is argument-passed to the gui. Additionally in the gui itself I have a nested list with for each button: - the name of the menu button (MenuItem) itself - the name of the sub-menu it belongs to - the tekst on the button - the sub-menu it may open - the name of its callback ( - the callback arguments It is quite complex, with a lot of correspondences that may go wrong. So I wonder if my approach is the right one. Do I understand the OO approach well ? Should I relax the OO guidelines ? Is there something in python which may help, but which I have overlooked ? egbert -- Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991 ======================================================================== From jeff_news at lindholm.org Mon Aug 23 14:01:17 2004 From: jeff_news at lindholm.org (Jeff Lindholm) Date: Mon, 23 Aug 2004 18:01:17 GMT Subject: line shift? (baby steps 2) References: <6daa8765.0408230412.6db365d6@posting.google.com> <2oueokFe36qgU2@uni-berlin.de> Message-ID: > As a hint not pertaining to your actual problem: Use a dictionary to > store the values, like this: > > currencies = { "EUDK" : 7.47, "DKEU" : 0.13, (...) } > > Then you do not have to do if statements like this > > if currency_str == "DKEU": > result= amount_int* dkeu_currency > print amount_int, "Danish Crowns correspond to", result, "Euro." > > (...) > > You can directly use the input string as index into the dictionary: > > result = amount_int * currencies[currency_str] > print (...) > I was bored waiting on a compile so I hacked this up. It adds the \n and the Please enter conversion type line and uses the previous poster's comment on the using a dictionary. I added the conversion output text by makeing the value a list that is the conversion and the text to display for the answer (I made them shorter because I was lazy to type all the information). I also made the conversion from US to EU more in line with the EUUS because I used those for testing and the results were not coming out the same (course I am sure there is some slack in there somewhere for the bank taking its share of the proceeds :) ) Not sure if there is a slicker way to do the conversion/message - I am relatively new to Python as well, so my code still ends up looking like C++ lots of the time. import string currency = {"EUDK":(7.47,"? to DKK"), "DKEU":(0.13,"DKK to ?"), "USDK":(5.93, "$ to DKK"), "DKUS":(0.16, "DKK to $"), "EUUS":(1.19, "? to $"), "USEU":(0.84, "$ to ?")} while(1): currency_choice= raw_input("\nPlease enter conversion type or 'Exit': ") currency_str= str(currency_choice).upper() if currency_str == "EXIT": break if currency.has_key(currency_str): amount_int= input("Please type the amount you wish to convert: ") result = amount_int * currency[currency_str][0] print currency[currency_str][1], " ", amount_int, " = ", result else: print("Sorry. At the moment we only support DKK, Euro and Dollars." + "\n" \ "Type DKEU if you want convert from DKK to ?," + "\n" \ "EUDK if you want to convert from DKK to ?," + "\n" \ "DKUS if you want to convert from DKK to $," + "\n" \ "USDK if you want to convert from $ to DKK," + "\n" "EUUS if you want to convert from ? to $," + "\n"\ "and USEU if you want to convert from $ to ?") From noone at here.com Thu Aug 19 21:42:25 2004 From: noone at here.com (M. Clift) Date: Fri, 20 Aug 2004 02:42:25 +0100 Subject: Rita Sue and Bob too Message-ID: Hi All, Can someone help. I promise I've looked how to do this but can't find a way... Ok, to find one name is easy if 'Bob' in list: print "They were found" else: print "They are not in list" But, how to I find a sequence in a list of unknown size? i.e. this sequence in list of other names and replace it with three others? 'Rita','Sue','Bob' This is almost a nightly occurrence (my posting questions), but I am learning : ) From drumheller at alum.mit.edu Mon Aug 16 03:05:26 2004 From: drumheller at alum.mit.edu (Michael Drumheller) Date: 16 Aug 2004 00:05:26 -0700 Subject: NumArray array-indexing References: Message-ID: Christopher T King wrote in message news:... > On Thu, 12 Aug 2004, Christopher T King wrote: > > > On 12 Aug 2004, Michael Drumheller wrote: > > > > > Basically, it seems to me that NumArray simply does not support > > > the distinction between a column vector and a row vector. That > > > is, if you have x=[1,2,3], then transpose(x) is a no-op. True? > > > > False. You have to supply numarray with a two-dimensional array in order > > to perform a two-dimensional transpose: > > Where by "False" I meant "The first sentence is false, but the second > sentence is true". Column vectors and row vectors must be represented as > two-dimensional arrays; transpose() of a one-dimensional array is a no-op > since all transpose() does (by default) is reverse the order of the axes. I understand that, but I think it just goes to support my contention that NumArray does not support transposed vectors *from an array-indexing point of view.* Here is what I mean: As you pointed out in your previous message, you can get "the transpose of a row vector" if the "row vector" is actually a single-row matrix, i.e., >>> transpose([[1, 2, 3]]) array([[1], [2], [3]]) However, whereas [1, 2, 3] passed as an index-array will get you the second, third, and fourth rows of a rank-2 matrix, [[1,2,3]] will *not* do that. (It gets you some other weird thing that I can't remember.) That is, a single-row matrix may be the same thing as a row vector in a mathematical context, but it is not the same thing in an array-indexing context. Similarly, passing [[1], [2], [3]] as an index array doesn't get you anything remotely like the second third, and fourth columns. So it seems to me that array indexing can easily get you an arbitrary subset of rows, but not an arbitrary subset of columns. Would you agree? By the way: Thank you for your attention to my problem! Mike From anthonybaxter at gmail.com Fri Aug 6 01:46:18 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 15:46:18 +1000 Subject: Object Reference? In-Reply-To: References: Message-ID: On Fri, 06 Aug 2004 05:39:51 GMT, Chris S. wrote: > Naturally, I could just recursively parse all the data comparing every > element to every previously listed object, but is there a less obtrusive > method? Python figures out when to delete objects based on the remaining > references to an object. Is there a way to access this information to > automatically lookup these references? Any help is greatly appreciated. Use the "id()" of the objects? From paul at boddie.org.uk Mon Aug 23 04:17:07 2004 From: paul at boddie.org.uk (Paul Boddie) Date: 23 Aug 2004 01:17:07 -0700 Subject: My only complaint about Python References: Message-ID: <5339b60d.0408230017.655081d9@posting.google.com> "Ben Last" wrote in message news:... > > What's needed (in my extremely humble opinion) is a way to build what I need > to, using a compiler suite that I can go and get without having to spend any > money. Philosophy is fine, but I dislike having an FSF agenda pushed on me > as much as I dislike a Redmond agenda. I just want to get on with my job > (or in this case, pursue my own interests). Yes, I'm sure the FSF is right up there with Microsoft, considered just as notorious for its anticompetitive business practices, and I'm sure we've all found it really hard to buy PC systems without GNU software pre-installed. When people talk about the FSF agenda being pushed on them, you'd think they'd been asked to stare down Richard Stallman in some kind of "reality TV" contest whilst exotically-dressed kernel hackers scream for the humiliation of the loser. Perhaps you'd be equally enthusiastic for Python if it were made available in binary form at the discretion of Guido and his closest associates, but I'd imagine that by now in its history, if that had been so, it would be as popular as the various neat-but-proprietary languages of the early 1990s whose names only trigger the memories of those who could remember them when seen on old and archived Web sites. Paul From srumbalski at copper.net Mon Aug 23 23:27:18 2004 From: srumbalski at copper.net (Steven Rumbalski) Date: Mon, 23 Aug 2004 23:27:18 -0400 Subject: newbie: confused with example in Learning Python 2nd Edition: can anyone give a hint References: <56cfb0e3.0408231710.27d78703@posting.google.com> Message-ID: <412ab47c_5@newsfeed.slurp.net> Porky Pig Jr wrote: > Here is an example of Stack class which got me totally confused: > >>>> class Stack: > ... def __init__(self, data): > ... self._data = list(data) > ... self.push = data.append > ... self.pop = data.pop It should have confused you. It was wrong. >From the errata at http://www.oreilly.com/catalog/lpython2/errata/lpython2.confirmed: {457} class Stack: code; self.push and self.pop should both reference self._data, not just data So the corrected code should look like: >>> class Stack: ... def __init__(self, data): ... self._data = list(data) ... self.push = _data.append ... self.pop = _data.pop And now the class should act like you expect. Before it was modifying the list (data) it was passed in the constructor. Now it modifies its own copy (_data). By the way, a brief note on errata. IMO it is counter-productive to dwell on errata (although a quick skim doesn't hurt). Trying to notice each error distracts from understanding. Usually the brain glosses over the error and reads what was intended rather than what was said. From ptmcg at austin.rr._bogus_.com Sun Aug 22 10:36:37 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Sun, 22 Aug 2004 14:36:37 GMT Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? References: Message-ID: "Doug Holton" wrote in message news:t5idnRg0lMA7B7XcRVn-qA at comcast.com... > Paul McGuire wrote: > > Total voters: 55 > > Of all of the votes cast, J2 > > received 48%, C1 received 18%. No other option received more than 10% of > > any votes. > > I vote 3 times for C1. So just my one vote raises C1 to 20%. I think > you need to do an online poll so you get more people than just those who > have been discussing the decorator keyword here this past week. I got > over 250 votes for C1 just last week vs. the 22 who voted for J2 here. > During this 2nd poll people were confused about whether they could vote > for A1 or not, and some people said many of the options on the wiki page > were not allowed anymore. > > Just make a poll with J2 vs. C1 and see what you find. Doug - Robert Brewer advised against ending this c.l.py poll prematurely (which I thought *was* a form of "online poll"), and your posting reaffirms that suggestion. I've put you down for 3 votes for C1. But by my spreadsheet, adding 3 votes to C1 shifts the percentages to 46.7% for J2 and 19.2% for C1. And if you look at the consensus statistic, this doesn't significantly change the number of people expressing some support for either (73.2% of voters cast at least one vote for J2, 35.7% cast at least one for C1). Fewer than 3% of the votes were cast for A1, so I don't think this had a major effect on the overall distribution of the results. One of the main purposes of multivoting is to do just what you propose - to narrow a field of many choices down to just 2. It looks like this poll is very close to achieving that, and I really don't think this will change significantly over the next few days. One of the issues with a "one-person-one-vote" poll is that you don't get a sense of a voter's willingness to be open to multiple alternatives. When you are all done, all you have is "X% for A and Y% for B" - short of unanimity, I don't think this is much of a basis for consensus among an anonymous group. Even an 80/20 or 90/10 split just tells you that 10-20% of the voters will be overridden by the majority. (I get the feeling that there are some out there who are distrustful of this whole process, and short of a 100% return for one choice, will not concede that we have arrived at consensus. ) What I like about multivoting is that it allows people to express preferences, but also openness to alternatives. And consequently, I think the process is less divisive. But just to show how compelling these results are so far, imagine that *every* vote had been J2, J2, C1 or C1, C1, J2 The absolute results would have been a 66%/33% split, and the consensus vote would have been 50%/50%. What we got so far is 47/19 (which is even more lopsided than 66/33) and 73/35. Mark Twain said there are 3 types of lies: lies, damned lies, and statistics. I'm not trying to confuse the issue, I *am* trying to convey that I think there is more consensus here than a simple percentage would imply. -- Paul From rnichol_rrc at yahoo.com Fri Aug 20 20:37:44 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Fri, 20 Aug 2004 19:37:44 -0500 Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> <5_uVc.411$MR2.2033@news1.mts.net> Message-ID: > You might look at this, also from dictionary.reference.com: > > quantum leap > > A dramatic advance, especially in knowledge or method, as in > Establishing a central bank represents a quantum leap in this small > country's development. This term originated as quantum jump in the > mid-1900s in physics, where it denotes a sudden change from one energy > state to another within an atom. Within a decade it was transferred to > other advances, not necessarily sudden but very important ones. You're aware of how big an atom is right? And people don't typically suddenly change from one language to another. They'll tend to change gradually if only because the people at work won't like an inflection point with regards to such matters. It makes support hell. From sbabbitt at commspeed.net Sun Aug 29 10:28:36 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Sun, 29 Aug 2004 07:28:36 -0700 Subject: [PIL] about the difference between pudata and putpixel References: Message-ID: <1093790243.944480@news.commspeed.net> "Hillairet Julien" wrote in message news:pan.2004.08.29.10.54.40.204024 at nospam.com... > Hello, > > I don't understand how "putdata" from the PIL works : > > I've got a (N,N) matrix : "color" (an array from numarray lib.), where > (N,N) is the size of a image. > > The next code, give to each pixel of the image the color (an integer > 0~255) which is associate in the "color" matrix (an integer matrix, > 0~255). It works well, but it's a bit slow: > > for i in range(N): > for j in range(N): > im.putpixel((i,j), color[i][j]) > > Although, this code doesn't work: > > im.putdata(color) > > There is no error message, but the image's pixels stay black (0) ! (The > color matrix is not an 0-matrix !) > > > Is someone can explain me my misunderstanding of putdata ? > > > Thanks a lot, > > Julien Hillairet Check your picture mode. import Image import random pyimg = Image.new('RGB',(10,10)) ll = [] for i in range(100): ll.append((random.randint(1,255),random.randint(1,255),random.randint(1,255) )) # a tuple of RGB values pyimg.putdata(ll) pyimg.show() # drag open the pill view window to see (its not large enough) Tom From fumanchu at amor.org Tue Aug 24 15:09:13 2004 From: fumanchu at amor.org (Robert Brewer) Date: Tue, 24 Aug 2004 12:09:13 -0700 Subject: profiler Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E53@exchange.hqamor.amorhq.net> Brett C. wrote: > As of Python 2.4 you can also compile in support for C-level > profiling > into the interpreter (--enable-profiling). See the in-dev docs > (http://www.python.org/dev/doc/devel/) for details. Drool. Thanks for the news. Since the first Python optimization is often to stop calling Python functions (and inline instead), this'll be a big help. :) Robert Brewer MIS Amor Ministries fumanchu at amor.org From pete at shinners.org Thu Aug 26 00:41:46 2004 From: pete at shinners.org (Pete Shinners) Date: Wed, 25 Aug 2004 21:41:46 -0700 Subject: Best GUI- Python for children - pygame and blender32 In-Reply-To: References: Message-ID: Andr? Roberge wrote: > I am learning Python (which, as everyone know is the best language :-) > so that I can write a tutorial to teach my kids about computer > programming. The motivation for them will be to use Python to create > their own games using pygame and, eventually, blender3d. From what I > hear, their friends will be interested in that tutorial too. You'll want to wrap all of pygame up in a nice kid-friendly wrapper. I'd start with things like defining functions that get called when certain events happen. Learning programming you will not want them starting with the important parts of pygame, like handling event queues, managing dirty updates, and those details. Good luck with your plans, I recommend the pygame mailing list and irc chat if you get stuck on details. From anthonybaxter at gmail.com Thu Aug 26 11:54:48 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 27 Aug 2004 01:54:48 +1000 Subject: Call for signatories for J2 In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022E82@exchange.hqamor.amorhq.net> References: <3A81C87DC164034AA4E2DDFE11D258E3022E82@exchange.hqamor.amorhq.net> Message-ID: On Thu, 26 Aug 2004 08:35:15 -0700, Robert Brewer wrote: > > Can we insert conditional expressions in the decorator list ? > > Not with the current patch; however, that option may be allowed in the future. "In the future" means "post-2.4, when we have an idea of what people are doing with it". Right now, there's not a whole lot of use cases for more complex expressions in the decorator area, and there's more potential for horror. Guido made this call on a gut feeling, not on any technical grounds. His gut is usually good on this. > The order of operation would have to be reversed, I don't see why. > so *IF* Guido votes yes, > then you need to bring this up again immediately. God no. Please don't. Work with the syntax that's chosen, then we can revisit this for 2.5. From grante at visi.com Tue Aug 24 10:44:27 2004 From: grante at visi.com (Grant Edwards) Date: 24 Aug 2004 14:44:27 GMT Subject: Time-date as an integer References: Message-ID: <412b544b$0$68775$a1866201@newsreader.visi.com> On 2004-08-24, Charles Hixson wrote: > This is a concept, not a finished program, and an extract from a class > at that...so forgive any illegalities, but: > import datetime; > def calcNodeId(self): > t = datetime.utcnow() > val = t.year * 133920000000 + # 12 months > t.month * 11160000000 + # 31 days > t.hour * 3600000000 + # 60 minutes > t.minute * 60000000 + # 60 seconds > t.second * 1000000 + t.microsecond > if val <= self._dTime: > val = self._dTime + 1 > self._dTime = val > return val > > This is the best that I've been able to come up with in getting a > date-time as an integer. It feels like one of the time or date > libraries should have a better solution, but if so, I haven't found it. > Can anyone suggest a better approach? Don't forget about months with lengths other than 31. Don't forget about leap years. Don't forget that 2000 was a leap year but 1900 and 2100 aren't. Don't forget about leap-seconds. Don't forget about calendar discontinuities (which occurred at different places in different locales). -- Grant Edwards grante Yow! .. he dominates the at DECADENT SUBWAY SCENE. visi.com From tjreedy at udel.edu Thu Aug 5 15:51:26 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 5 Aug 2004 15:51:26 -0400 Subject: Confused about pep 318 References: <10h2ihgb8c6fi97@corp.supernews.com> <10h4sm63o4dnd5a@corp.supernews.com> Message-ID: > The issue is not about rights to commit code, the issues are whether > > a) the question was ever publicly discussed at all and Deorators have been discussed on PyDev at least since Jan 03. The @ syntax was introduced there in June04 with AB's post starting this thread: http://mail.python.org/pipermail/python-dev/2004-June/thread.html#45516 > b) whether any consensus was reached. My impression as a mostly lurker who sees no immediate personal use for decos is that there was a partial consensus on the desirability of something, but not on the syntax. The 'tie-breaking' procedure is Guido decides, and so, with 2.4 looming, he did, at least as an experiment. > > Yes, it would have been nice if PEP-0318 was updated in advance of this. > > Not nice. Essential. It is fundamentally unfair to pretend to have > discussed a proposal publicly that has always been grossly misrepresented in > the one place one would naturally look to find information about it. Perhaps in this case the PSF should have paid someone to keep it updated better. The problem I see is that most strong advocates of some deco syntax also had a favorite syntax and were not candidates writing an even-handed treatment of options. Terry J. Reedy From luismg at gmx.net Mon Aug 9 13:35:45 2004 From: luismg at gmx.net (Neuruss) Date: 9 Aug 2004 10:35:45 -0700 Subject: VB-like GUI designer? References: Message-ID: <278de0e.0408090935.6d758a5d@posting.google.com> Two options: 1) Boa Constructor: is the closest you can find to VB or Delphi. It's free and based on wxPython. 2) PythonCard: this is the asiest to learn and use by far. However, there are some widgets that are not implemented (no datagrid, for example). There is at least one commercial product, BlackAdder, but it didn't impress me at all (it's trial version is a little bit annoying, since it doesn't let you save your work and it seems to close every few minutes, so you never get anything done...). As for the two mentioned above, I can say that I love PythonCard. It's like a very intuitive and simple (very simple) VB, but as I said, it is not very complete at this moment. I tried Boa Constructor a couple of times, and it seemed to me a little bit difficult to understand how it works, but I didn't try hard enough.. From bockman at virgilio.it Wed Aug 25 13:35:37 2004 From: bockman at virgilio.it (Francesco Bochicchio) Date: Wed, 25 Aug 2004 17:35:37 GMT Subject: Call for signatories for J2 - In Favor References: Message-ID: Assuming that simple python users qualify, you can add my name in favor of your proposal. If people are using this thread for signing themselves, maybe it would be better to create subthreads for pro/against/indifferent, just to make counting more simple. Ciao --------------------------------- Francesco Bochicchio From newsgroups at jhrothjr.com Mon Aug 2 13:18:14 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Mon, 2 Aug 2004 13:18:14 -0400 Subject: __coerce__ vs. new-style classes References: Message-ID: <10gstrc1n27m8e8@news.supernews.com> "Hallvard B Furuseth" wrote in message news:HBF.20040802t150 at bombur.uio.no... > Why do new-style classes disable __coerce__()? > It seems cumbersome to have to write a whole set of methods (e.g. > __add__, __radd__, etc.) to get the same effect. Is there some way to > automatically generate those methods, or are we simply not supposed to > do coercion for some reason? I'm mildly confused by your example. __coerce__() converts the arguements to a common type, and then presumably requests that type to do the operation. That type might not be one of the two original types! It's not the same thing as the __op__, __rop__ pair. That simply allows the right object to do the operation if the left object can't. (Also see 3.3.8 of the language reference for an exception to that rule.) The notion of type coercion makes a great deal of sense in languages such as C, where you have 8 integer types and 3 float types, but abstracting it out as a separate operation makes very little sense in Python, where you have 3 numeric types (int, long and float) and two string types (normal and unicode). The overhead of doing coercion as a separate operation simply doesn't make a lot of sense. At least, that's the way I understand it. Section 3.3.8 (Coercion Rules) of the 2.3 Language Reference gives the official reasons for moving away from doing coercion as part of operations. It simply got to complex to document properly. I suppose if you have a use case for __coerce__ in a real world cluster of non-numeric types, you could get Guido to reconsider. John Roth > > -- > Hallvard From insert at spam.here Tue Aug 10 16:26:23 2004 From: insert at spam.here (Doug Holton) Date: Tue, 10 Aug 2004 15:26:23 -0500 Subject: Decorator "platform" In-Reply-To: <2nsoofF49frcU1@uni-berlin.de> References: <2nsoofF49frcU1@uni-berlin.de> Message-ID: Reinhold Birkenfeld wrote: > it would be a big advantage to > everyone following to have the different uses of decorators collected, > to serve as a starting point or a repository of what's possible. > > What I have in mind is a sort of "decorator library" where everyone who > has written a useful function of that kind can share it with others, > instead of only posting it here. As I don't know whether there will be a > "decorators" module in the stdlib, this would serve as a replacement > until decorators are a final language feature. > > How would one realise such a project? Maybe you could create a PythonDecoratorLibrary page at the Python wiki: http://www.python.org/moin/PythonDecoratorLibrary Click the UserPreferences link on the top right to register for an account to be able to edit pages there. And surround your python syntax with {{{ }}} so the formatting stays the same. Example: {{{ #!python @classmethod def foo (arg1, arg2): .... }}} From jesso1607 at rogers.com Thu Aug 19 10:37:53 2004 From: jesso1607 at rogers.com (JASON JESSO) Date: Thu, 19 Aug 2004 10:37:53 -0400 (EDT) Subject: newbie Message-ID: <20040819143753.63873.qmail@web88006.mail.re2.yahoo.com> I'm trying to add a mode to a mkdir program a got off the python cookbook. The error I get is: ./mkdir.py jason 0777 Traceback (most recent call last): File "./mkdir.py", line 31, in ? _mkdir( sys.argv[1], sys.argv[2] ) File "./mkdir.py", line 25, in _mkdir os.mkdir( newdir, mode ) TypeError: an integer is required When I convert the mode from a string to an octal with oct(int(sys.argv[2])) the permissions are all screwed up. Any help? #!/usr/bin/env python import sys, os def _mkdir( newdir, mode ): """works the way a good mkdir should :) - already exists, silently complete - regular file in the way, raise an exception - parent directory(ies) does not exist, make them as well """ if os.path.isdir( newdir ): pass elif os.path.isfile( newdir ): raise OSError("a file with the same name as the desired " \ "dir, '%s', already exists." % newdir) else: head, tail = os.path.split( newdir ) if head and not os.path.isdir( head ): _mkdir( head, mode ) if tail: if mode is None: os.mkdir( newdir ) else: os.mkdir( newdir, mode ) if __name__ == '__main__' : if len(sys.argv) < 3: _mkdir( sys.argv[1], None ) else: _mkdir( sys.argv[1], sys.argv[2] ) From duncan.booth at invalid.invalid Wed Aug 4 03:31:33 2004 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 4 Aug 2004 07:31:33 GMT Subject: Timing Difference: insert vs. append & reverse References: <35b736b9.0408020330.53b24ed3@posting.google.com> <1a517b5.0408031027.60554dfb@posting.google.com> Message-ID: bryanjugglercryptographer at yahoo.com (Bryan Olson) wrote in news:1a517b5.0408031027.60554dfb at posting.google.com: >> If you expected insert to be faster, perhaps you thought that Python >> used a linked-list implementation. It doesn't do this, because in >> practice (for most applications) a [array] based implementation gives >> better performance. > > True, but an array implementation can easily support amortized > constant-time insert/delete at *either* end (without breaking > constant-time indexing). The same trick of keeping extra space > at the tail end can work at the head; it requires keeping one > additional offset to show where the occupied cells start. > If the OP had said he expected insert and append to be the same speed I might buy that, but he expected insert to be faster than append. From alikakakhel3 at hotmail.com Wed Aug 18 17:14:43 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 18 Aug 2004 14:14:43 -0700 Subject: what wrong with this program? References: <8f17f4bc.0408171632.787eb6f8@posting.google.com> Message-ID: <8f17f4bc.0408181314.7626b69b@posting.google.com> Robert Kern wrote in message news:... > Ali wrote: > > > The following program is supposed to display a dropdown menu, however, > > it only shows the File and Help things. > > > > from Tkinter import * > > > > root = Tk() > > > > #create menu > > m = Menu(root) > > root.config(menu=m) > > > > filemenu = Menu(m) > > m.add_cascade(label="File", menu="filemenu") > > The menu= argument needs to be the object itself, not a string. > > See, e.g. > > http://www.pythonware.com/library/tkinter/introduction/x5819-patterns.htm ok I will try it out. Thanks for your help From franbarlow at mail.com Thu Aug 12 16:16:01 2004 From: franbarlow at mail.com (Fran) Date: 12 Aug 2004 13:16:01 -0700 Subject: Help understanding Scheme's syntax, procedures and calls References: <95f168b0.0408120120.31433dc7@posting.google.com> <411b577a$0$20523$afc38c87@news.easynet.co.uk> Message-ID: <95f168b0.0408121216.63efc297@posting.google.com> Peter Hickman wrote in message news:<411b577a$0$20523$afc38c87 at news.easynet.co.uk>... > Unfortunately it looks more like 'broken scheme'. > > Fran wrote: > > (define (this n) > > (if (=n 0) > > 0 > > (= n (this (- n 1))))) > > That looks fine, however: > > > (define (f1 a b) > > (if >b a) > > 0 > > (+ b (f1 a (+ b 1))))) > > Has 6 (s and 7 )s. I expect that the seconds line should read > (if (> b a) > > > (define (that n) > > (f1 n1) > > Again there is an imbalance in the ( and ), I think the second line should read > (f1 n 1)), note the space between then 'n' and the '1'. > > Is this someone's homework by any chance? Thanks for the help. It's not homework but from an old exam paper, but the girl's English isn't absolutely fluent and I'm looking for a simple way to explain the expressions and functions. FRAN From npat at efault.net Tue Aug 17 03:07:38 2004 From: npat at efault.net (Nick Patavalis) Date: Tue, 17 Aug 2004 07:07:38 +0000 (UTC) Subject: Why I love python. References: <7xk6vyczck.fsf@ruckus.brouhaha.com> Message-ID: On 2004-08-17, Paul Rubin <> wrote: > > Compilers for languages like Lisp and Smaltalk have dealt with this > for decades. They can either generate code that switches on the type > tags, or have dispatch tables in the objects that point to code for > operations like "+", or take advice or declarations from the > programmer about the arg types, among other possibilities. Any of > these approaches generates code that runs much faster than > interpreted code. > Yes, I know. Something like this was what I was thinking about. I would really love to see this technology brought to Python, or at least a discussion as to what additions would be required in the *language* in order for similar technologies to be easily applicable to future Pythonic environments. /npat From andy47 at halfcooked.com Thu Aug 5 15:29:40 2004 From: andy47 at halfcooked.com (Andy Todd) Date: Thu, 05 Aug 2004 20:29:40 +0100 Subject: MySQLdb select In-Reply-To: References: Message-ID: F. GEIGER wrote: > "Gerhard H?ring" schrieb im Newsbeitrag > news:mailman.1008.1091284523.5135.python-list at python.org... > > > >>That's particularly BAD STYLE. It's best to keep to letting the DB-API >>do the proper quoting for all parameters. > > > > Well, yes. > > So I tried this: > > >>>>import MySQLdb as ms >>>>con = ms.connect(db="isa",user="root") >>>>cur = con.cursor() >>>>cur.execute("select id from %s limit 10;", ("tagevents",)) > > Traceback (most recent call last): > File "", line 1, in ? > File "C:\PROGRA~1\Python23\lib\site-packages\MySQLdb\cursors.py", line 95, > in execute > return self._execute(query, args) > File "C:\PROGRA~1\Python23\lib\site-packages\MySQLdb\cursors.py", line > 114, in _execute > self.errorhandler(self, exc, value) > File "C:\PROGRA~1\Python23\lib\site-packages\MySQLdb\connections.py", line > 33, in defaulterrorhandler > raise errorclass, errorvalue > _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL > syntax. Check the manual that corresponds to > your MySQL server version for the right syntax to use near ''tagevents' > limit 10' at line 1") > > > Hmm, despite the fact, that it is bad style, I tried: > > >>>>cur.execute("select id from %s limit 10;" % "tagevents") > > 10L > > > and succeeded. > > Looks like MySQL doesn't like the quoting, MySQLdb seems to perform. > > Okay, as you shouted to me "BAD STYLE" I presume, it had to work, if I only > did it right. So, what am I doing wrong? Or did I misconfig MySQL? Is MySQL > 4.0 not yet supported? > > My environment: > > Win XP > > Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > > Welcome to the MySQL monitor. Commands end with ; or \g. > Your MySQL connection id is 7 to server version: 4.0.20a-nt > > MySQLdb 1.0.0 > > > Kind regards > Franz GEIGER > [snip] That's because MySQLdb will take care of converting the *parameters* in a SQL statement. These are (almost) always in the WHERE clause. What you are trying to do is generate the SQL statement dynamically - which you have to do yourself using string formatting as you have found out. It's a subtle but very important distinction. Processing a SQL statement is usually done in two parts; parsing and binding. Parsing is where the database engine figures out *where* to get the information requested in the statement (e.g. which files the rows from the tables are physically stored in), binding is when the parameter values you supply are used to figure out *what* to return. Regards, Andy -- -------------------------------------------------------------------------------- From the desk of Andrew J Todd esq - http://www.halfcooked.com/ From mwh at python.net Mon Aug 23 11:13:39 2004 From: mwh at python.net (Michael Hudson) Date: Mon, 23 Aug 2004 15:13:39 GMT Subject: Parsing Python code with a Python Program References: Message-ID: pgw writes: > Hello, > > I would like to pass strings to a Python > application and have them executed as though > they were lines of code. > > Is 'exec()' the function that I am looking for > and/or is there an example of this somewhere? Well, it's a statement, not a function, but yes, that's what you're looking for. Cheers, mwh -- Well, you pretty much need Microsoft stuff to get misbehaviours bad enough to actually tear the time-space continuum. Luckily for you, MS Internet Explorer is available for Solaris. -- Calle Dybedahl, alt.sysadmin.recovery From asif at go-away-spammer.com Wed Aug 25 11:29:04 2004 From: asif at go-away-spammer.com (Player) Date: Wed, 25 Aug 2004 16:29:04 +0100 Subject: A little curious about something.. Message-ID: Hell all once again :) I just installed Python after giving Activestates distribution of python a try for a few days, and I have come across something that strikes me as a little weird, to my beginners eye anyways. In Activestates distribution of python, Idle or Pythonwin whatever their version of Idle is, loaded fast and smoothly, and if I click-held the idle GUI and moved the GUI window to reposition it somewhere else of the screen, it moved fluidly and fast. However with the Idle version in python, the GUI and python it's self loads allot slower, and if I do the same click-hold to reposition the idle GUI window, it chugs and stutters across the screen as I move it, rather slowly and no were near as smoothly and fluidly as the Activestates version of the Idle GUI window. Why is this? is it something to do with the widget sets used?? M.B PS: It's deffinately not resources lacking on my pc either :0 My machine is a mosnter :) -- ************* The Imagination may be compared to Adam's dream- he awoke and found it truth. John Keats. ************* From eric_brunel at despammed.com Fri Aug 20 08:06:17 2004 From: eric_brunel at despammed.com (Eric Brunel) Date: Fri, 20 Aug 2004 14:06:17 +0200 Subject: Regular expression guaranteed to fail References: Message-ID: Des Small wrote: > I want to use sets and regular expressions to implement some > linguistic ideas. Representing sounds by symbols, and properties > (coronal or velar articulation; voicedness) by sets of symbols with > those properties, it is natural to then map these sets, and > intersections of them, to regular expressions to apply to strings. > > The question is, what regular expression should correspond to the > empty set? I've provisionally gone with "(?!.*)", i.e., the negation > of a look-ahead which matches anything. Is there an established idiom > for this, and is that it? And if there isn't, does this seem > reasonable? I also looked for a never-matching re just a few days ago and ended up with "^(?!$)$". It's certainly not more "standard" than yours, but I find it a wee tad more readable (for a regular expression, I mean...): it's quite clear that it requests a string start not followed by a string end and followed by a string end, which is guaranteed to never happen. Yours is a bit harder to explain. Mine may also be more efficient for very long strings, but I can be wrong here. See what other people think... -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From nid_oizo at yahoo.com_removethe_ Fri Aug 20 08:07:59 2004 From: nid_oizo at yahoo.com_removethe_ (Nicolas Fleury) Date: Fri, 20 Aug 2004 08:07:59 -0400 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: Anthony Baxter wrote: >>- Not Pythonic. It's a line without a block (like try/finally) that >>affects a following line of code. It breaks interactive shells. > > I've seen this mentioned a couple of times, but as far as I can see, > it's really not true: I just copied from Wiki honestly. > This form (decorators inside the block) has been pretty convincingly > ruled out by Guido. I think the "last man standing" is the decorator-before-def > form, I really doubt you're going to convince people that the form inside the > function is workable. I sadly discovered after my post it has been ruled out. I agree the "last man standing" is the decorator-before-def form. In fact, we should make a thread about only this proposal. Regards, Nicolas From squirrel at WPI.EDU Fri Aug 6 10:11:16 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Fri, 6 Aug 2004 10:11:16 -0400 Subject: [Newby question] List comprehension In-Reply-To: References: Message-ID: On Fri, 6 Aug 2004, Eelco Hoekema wrote: > [(root, filter(song, files)) for (root, dir, files) in > os.walk(os.path.abspath('.')) if filter(song, files)] > > Now, this will work. However, it seems kind of silly to call the filter > twice. Is there a way to keep this in one list comprehension, but with > just filtering once? You may do best to split this into two LCs: temp = [(root, filter(song,files)) for (root, dir, files) in os.walk(os.path.abspath('.'))] temp = [(root, songs) for (root, songs) in temp if songs] Or if you prefer, replace the latter with: temp = filter(temp, lambda x: x[1]) Or even, in 2.4: temp = filter(temp, itemgetter(1)) In 2.4, you will also be able to replace the first LC with a generator expression, saving a bit of both memory and processor time (the change would consist of replacing the brackets with parentheses). Hope this helps. From support at hotini.com Sun Aug 29 01:48:03 2004 From: support at hotini.com (Hotini.Com) Date: Sat, 28 Aug 2004 22:48:03 -0700 Subject: We got your message Message-ID: Hello and thank you for your message. We'll try to get back to you as soon as we can. --------------------------------------- www.Hotini.Com - The Hotini.Com Staff --------------------------------------- From peter at engcorp.com Wed Aug 18 11:55:58 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 18 Aug 2004 11:55:58 -0400 Subject: How big can a Python program be? In-Reply-To: <903b3fba.0408180655.6a23aede@posting.google.com> References: <903b3fba.0408170333.49ce3944@posting.google.com> <903b3fba.0408180655.6a23aede@posting.google.com> Message-ID: vronskij at post.sk wrote: >>What are you actually asking? What technical limitations, >>such as maximum line count per module, Python might have? > > Well this is maybe difficult to define. Programs reach some limit and > become unmanagable. This is one reason why we have OOP, UML etc. Yes, that's true. In this respect at least Python is fairly widely considered to have a leg up on much of the competition. One of the biggest reasons is that it makes the code much more maintainable (because of greater readability for one thing) than the same amount of code in many other languages would be. >>And more importantly than anything: why do you want to know >>such things? > > Simple. Can you make an ERP in Python? Or is Python limited to little > nice scripts or small programs with nice GUI? > We are thinking to start a huge project, which could be hundreds of > thousands of lines huge. I would finally know the answer, but it is > probably better to ask first... Ah, excellent... yes! No problems. In fact, I'm near certain there was someone around here one or two years ago talking about making a large ERP system in Python. Don't know who that was, or whether they might have shipped it yet... At my last place of employ, we used Python to develop a system that had something like 60,000 lines of code that we wrote, and which built on Zope (and, later, Twisted), which had I believe over 100,000 lines of code. And of course a line of Python code corresponds to quite a few lines of C code (one group's analysis says it's a 10:1 ratio: http://www.pythonology.com/success&story=wingide). Here are some other references for you: http://mail.python.org/pipermail/python-list/2004-August/233130.html http://www.pythonology.com/success http://www.mindview.net/WebLog/log-0036 (Bruce Eckel) This newsgroup's archives: http://groups.google.com/groups?q=large+projects+group%3Acomp.lang.python.* -Peter From jburns131 at adelphia.net Tue Aug 10 23:59:26 2004 From: jburns131 at adelphia.net (Jesse B.) Date: Tue, 10 Aug 2004 20:59:26 -0700 Subject: IDLE vs Command Line References: <8PidncxTb4muxITcRVn-oQ@adelphia.com> Message-ID: > Jesse B. wrote: > > I like to work with xemacs, so I've been coding modules with xemacs and > > running them using the dos prompt (using windows port of xemacs). Some > > scripts that work fine with IDLE don't work at the dos prompt. For example: > > > > import random > > > > for i in range(10): > > x = random.random() > > print x > > > > This simple script doesn't work if I use the command prompt, with this > > syntax: python random.py > > > > I am just wondering why that is. > > Because you have given the script the same name as the module you're > importing, so the script tries to import itself? That makes sense. From donn at drizzle.com Tue Aug 17 02:55:53 2004 From: donn at drizzle.com (Donn Cave) Date: Tue, 17 Aug 2004 06:55:53 -0000 Subject: music resources References: None Message-ID: <1092725752.70670@yasure> Quoth "Elaine Jackson" : | Is there such a thing as an executable language for music? If not, why not? An | if yes, where can I find it? Naturally the ideal thing would be if such a | language were implemented within python, but I would be willing to learn a | lesser programming language if I had a reasonable assurance that it had what I | looking for. I have, of course, googled for a solution, and I may have even | found it, but if so I didn't recognize it as such. Any pointers will be mucho | appreciado. There's Haskore, which you could probably find via the main Haskell site, http://www.haskell.org Don't know if it's what you're looking for, but though it isn't Python, don't worry that Haskell might be a lesser programming language. Here's an example from early in the tutorial: tune1 :: Music tune1 = let v = Volume 150 in c 8 hn [v] :+: e 8 hn [v] :+: g 8 hn [v] :+: c 9 hn [v] :+: a 8 hn [v] :+: c 9 qn [v] :+: a 8 qn [v] :+: g 8 dhn [v]:+: qnr I haven't ever tried to use Haskore, but I assume that in "c 8 hn [v]", "c 8" is the pitch, "hn" is "half note", and [v] is the first and only volume for the note. ':+:' is some function that binds these notes together in a tune. There is quite a bit of support for computer generation of tones, too. Donn Cave, donn at drizzle.com From ellisjb at my-deja.com Sat Aug 21 22:17:31 2004 From: ellisjb at my-deja.com (ellisjb at my-deja.com) Date: 21 Aug 2004 19:17:31 -0700 Subject: Getting benifits of database transactions in an OO way? Message-ID: Leif K-Brooks wrote: > How would begin_transaction() and finish_transaction() be implemented? > They couldn't be simple wrappers for PostgreSQL transaction handling, > since it's not very object-oriented (the whole connection has one > transaction at a time). You'll have to be more specific about why that is a problem for you, since your example doesn't make that clear. Is your application multithreaded? -Jonathan From ville at spammers.com Thu Aug 5 15:16:44 2004 From: ville at spammers.com (Ville Vainio) Date: 05 Aug 2004 22:16:44 +0300 Subject: Confused about pep 318 References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: >>>>> "Anthony" == Anthony Baxter writes: Anthony> On Thu, 05 Aug 2004 13:29:29 -0400, Peter Hansen wrote: >> I'll make another donation to PSF if the final decorator syntax >> does not Perlishly use arbitrary punctuation as the @ syntax >> does. Anthony> FFS. What exactly is "Perlish" about @? It's an unused Anthony> symbol. That's all. It's hardly arbitrary - Java, for Anthony> instance, already uses @ for the same thing. The problem with @ as I see it (FWIW, of course) is that the new syntax wastes @ for a minor feature. I wouldn't mind @[decorator], which would allow reserving stuff like @private (compiler / type inferrer / macro / whatever) for future extension of the language. And "def decorator func(args):" is even worse. Most interesting applications of decorators involve decorators with arguments... -- Ville Vainio http://tinyurl.com/2prnb From tzot at sil-tec.gr Sat Aug 21 14:40:44 2004 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 21 Aug 2004 21:40:44 +0300 Subject: Why are strings immutable? References: <10ieqt67kf3139c@news.supernews.com> Message-ID: On Sat, 21 Aug 2004 11:34:54 -0400, rumours say that "John Roth" might have written: [ strings are immutable because...] >That said, it would be useful to have a >string buffer object that could be changed. array.array('c') is a close substitute. -- TZOTZIOY, I speak England very best, "Tssss!" --Brad Pitt as Achilles in unprecedented Ancient Greek From reinhold-birkenfeld-nospam at wolke7.net Fri Aug 20 16:37:07 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Fri, 20 Aug 2004 22:37:07 +0200 Subject: Fate of lambda, Functional Programming in Python... In-Reply-To: <41265E67.A08409A6@juno.com> References: <412636D1.6070808@noaa.gov> <41265E67.A08409A6@juno.com> Message-ID: <2on5k1FcjmvdU1@uni-berlin.de> Jeff Sandys wrote: > | > > Hi,all > | > > I have a list like [(id,string),...],for example: > | > > > | > > [(1,'xxxxx'),(7,'ppppp'),(4,'gggggg'),...] > | > > > | > > I want to sort this list according to the id of each element. > | > > After sorting,the list will become: > | > > > | > > [(1,'xxxxx'),(4,'gggggg'),(7,'ppppp')...] > | > > | > list.sort sorts tuples by first argument, then second &c. If you > want > | > a custom sort order, look at the decorate-sort-undecorate pattern. > | > | Or if you want to sort only on your Id, use a lambda: > | l.sort(lambda x,y: cmp(x[0],y[0])) > | > | To force sorting on just the nth element of the tuples, replace 0 > with > | n in the above. > | > > I think that lambda should be unlimited and expanded. It already has > the > colon, block delimiter, so allow lambda to be a multistatement and > multiline > indented block! So in what point exactly is this different from a def(), then? Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From cjw at sympatico.ca Mon Aug 9 15:57:59 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Mon, 09 Aug 2004 15:57:59 -0400 Subject: What are decorators? In-Reply-To: References: Message-ID: <5HQRc.11056$Mq1.509571@news20.bellglobal.com> gohaku wrote: > Hi everyone, > The discussion on Python Decorators and "@" has piqued my interest on this > "feature?" in programming languages such as Python and Java. > can anybody what is the point in using Decorators? > The term decorator is a bit misleading. It does not decorate or adorn a function, class or method declaration, the declaration is transformed. There are cases where one might wish to change the behaviour of a function to, for example ensure that the arguments being passed in are of a certain class or that the object returned has given type. > The examples I have seen written in Python of this "Not Yet Implemented" > feature > are confusing to say the least and perplexes me as to its usefulness. > > Thanks in advance. > -gohaku > In a posting yerterday, Dan bishop wrote: > > If I understand correctly, they'd be useful for anything where you'd > now use the syntax > > function = decorator(function) > > In addition to @staticmethod, you could have decorators for > > (1) Memoization. Makes repeated function evaluation more efficient > without having to rewrite the function. > > class memoize(object): > def __init__(self, func): > self.__func = func > self.__results = {} > def __call__(self, *args): > if args not in self.__results: > self.__results[args] = self.__func(*args) > return self.__results[args] > > def fibonacci(n): > @memoize > if n in (0, 1): > return n > return fibonacci(n - 1) + fibonacci(n - 2) > > (2) Debugging uses, like: > > class printreturns(object): > "Behaves like f but prints its return values." > def __init__(self, f): > self.__f = f > def __call__(self, *args): > result = self.__f(*args) > if debug: > print 'f%r = %r' % (args, result) > return > def somefunc(x, y): > @printreturns > ... I found it helpful, I hope that you do. Colin W. From peter at engcorp.com Tue Aug 3 09:49:15 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 03 Aug 2004 09:49:15 -0400 Subject: Call for Grant Proposals In-Reply-To: References: <40fcaa90$0$27091$9b622d9e@news.freenet.de> <41097fed$1@news.unimelb.edu.au> <410DF640.4010307@acm.org> <410DF824.8070309@acm.org> Message-ID: Maurice Ling wrote: > Then it will means that some projects may not be able to apply for this > grant if it is the requirement of the project to be proprietary due to > business strategy. What you are saying is that all projects should be > open sourced but that may not be the case. Either that or you are > indiscriminately lobbying for the cause of open source irregards of > whether companies are ready for it or not, and then discriminating > against companies who are not ready for it yet. Although I support open > source development and had personally donated my work to Sourceforge and > Biopython project, I will think that it is tyrannic to assume all work > must be open sourced. "Tyrannic" is hardly an appropriate adjective to apply to this situation, either in letter or spirit. You are asking for money to be *given* to you here... it's a privilege, not a right. Anyway, I suspect I'm not alone (as one of the people who have made a donation, however small) in feeling very uncomfortable with the idea of much of that money being used to fund closed-source projects. -Peter From dgolding at sbcglobal.net Mon Aug 2 11:10:55 2004 From: dgolding at sbcglobal.net (Don Golding) Date: Mon, 02 Aug 2004 15:10:55 GMT Subject: Sound Capture-AI Mind/Developing AI References: <410ad3d1@news.victoria.tc.ca> Message-ID: <3QsPc.5559$AY5.1852@newssvr21.news.prodigy.com> I would be willing to "prime the pump" and supply my robot Whiskers, at cost ($250), to promote the development of AI in Forth. The robot uses Max Forth from New Micros. The Forth language was extended with new robot control words so you can use it as a mobile Forth language development platform. It supports Multitasking and has a three level intelligent architecture which I developed. Dr. Ken Butterfield of the Los Alamo National Laboratory helped with the development of the software. Sensors include: Four optical sensors with analog data registers, two whiskers, and individual motor current sensing. A microphone for sound recognition? and a speaker for sound "language?" generation. I was trying to develop an artificial creature for AI researchers to use as a platform to develop AI for robots. For more information: http://www.angelusresearch.com/Whiskers.htm http://www.angelusresearch.com/articles.htm http://www.angelusresearch.com/military/ I gave a presentation of this three level architecture to the senior staff and director of the robotics program at JPL in 1995. Eighteen months later, 3T, which is a clone of my system, was announced by JPL as the new standard for intelligent control and is in common use today. We have a software copyrights for both 2 level and 3 level intelligent control architectures for robots. Most of the robots entered into the Grand Challenge used the 2 level control operation. Life is fun, isn't it? Call me to discuss this offer: (714) 590-7877. Sorry Brad, kinda off topic, but interesting... Don "Arthur T. Murray" wrote in message news:410ad3d1 at news.victoria.tc.ca... > "Chris S." writes on Fri, 30 Jul 2004: > > > Arthur T. Murray wrote: > > > >> "Chris S." writes on Fri, 30 Jul 2004: > >> > >>> If you have "solved" AI (a claim I heavily discount), > >> > >> http://www.scn.org/~mentifex/theory5.html -- solved in *theory*. > > > > After reading over your javascript code, your > > implementation appears to be a mix between a > > knowledge base and a natural language parser. > ATM: > Yes, a *conceptualized* knowledge base (KB). > > > Unfortunately, it doesn't seem to have any general > > IO capabilities. This is a common pitfall to many amateur > > AI researchers. Language alone doesn't define knowledge. > > Ture. Language is nevertheless closely involved with thought. > > > Without a physical perception of the world, a computer > > will never "know" what 'soft', 'pain', or 'up' mean. > > I've often thought vision algorithms, speech synthesizers, > > NLPs, and such without a general form of processing > > and representing sensory data was like trying > > to run before we could walk. > > The sensorium is where we amateur mind-makers count on > help from the amateur robot-makers. They want a mind > for their robots; we want robots for our AI to live in. > > > > But if I were to recommend an improvement in your system, > > I would suggest you try coding it in Python (www.python.org). > > http://mind.sourceforge.net/python.html is a Python AI weblog. > > > Compared to Javascript, and especially Forth, Python > > is remarkably easy to learn. Python would allow you > > to represent your idea in an object-oriented framework, > > making it much easier for others to understand. > > Understanding the AI Mind is helped along considerably by > http://www.scn.org/~mentifex/jsaimind.html -- for MS IE 5: > > ____________ ____________ > AI4U textbook / \ / \ > User's Manual ( Motorium ) ( Security ) > Add your link \____________/ \____________/ > ____________ ____________ > / \ / Sensorium \ > ( Volition ) Listening... ( --> Audition ) > \____________/ \____________/ > ____________ ____________ > / \ / \ > ( Think ) ( Emotion ) > \____________/ \____________/ > > > It would also make persisting dynamic data much easier, > > so you wouldn't have to hard code so much of your lexicon. > > Only an initial, hit-the-ground-thinking lexicon is hard-coded. > The AI learns new words via the human-computer interaction (HCI). > > > Plus you should never run into any platform issues, since > > Python runs everywhere. Python's quickly becoming a serious > > tool for AI research. For instance, "AI: A Modern Approach" > > is currently offering both Lisp and Python source code for > > many of its examples. > > With heartfelt thanks to you for the analysis and advice, > > Arthur T. Murray From h.b.furuseth at usit.uio.no Sat Aug 7 20:51:12 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 08 Aug 2004 02:51:12 +0200 Subject: Proposed improved decorator syntax References: Message-ID: barnesc wrote: > class foo: > def introduceNewFeature(self, someArgument, anotherArgument): > .decorate = [synchronized] > .accepts = (int, int) > .author = 'Chris King' > pass # whatever I like it better than the current syntax, but I'm troubled by stuff after the ':' which is executed before the function. It _looks_ like it is executed inside the function. Also, the scoping is a bit strange: def bar(self, baz): .decorate = [baz] pass # whatever The decorator looks like it refers to the function parameter, but it doesn't: the parameter has no value when the decorator is set. Though I guess a simple fix in this case is simply to forbid decorators to use names that occur as function parameters. Rob Williscroft wrote: > But since we can have function's in function's and we already > have "special" member functions (__init__ etc): > > class Foo: > > def method( self ): > > def __decorate__( func ): > synchronized( func ) > > __accepts__ = (int, int) > __author__ = "whoever" > > pass Same problem, only worse. The def statements of special member functions are executed while the class body is executed, just like defs of normal functions. OTOH, your special functions inside functions must be executed once before the function is called. -- Hallvard From abra9823 at mail.usyd.edu.au Thu Aug 19 22:21:15 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Fri, 20 Aug 2004 12:21:15 +1000 Subject: html templates Message-ID: <1092968475.4125601b5c572@www-mail.usyd.edu.au> hi! i am looking for a framework to create a fast dynamic website. between using Cheetah and HTMLTemplate which would you recommend? also quixote offers a session management API? how secure is this session management? is it just a cookie on the client side? thanks cheers ajay ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From mark_bottjer at hotmail.com Wed Aug 11 14:05:40 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Wed, 11 Aug 2004 14:05:40 -0400 Subject: @decorator syntax is sugar, but for what exactly? In-Reply-To: <4117a6f7$1@news.012.net.il> References: <4115b53a$1@nntp0.pdx.net> <4116239e$1@news.012.net.il> <4116ac05$1@nntp.zianet.com> <4117a6f7$1@news.012.net.il> Message-ID: <411a5ff4$1@nntp.zianet.com> Avner Ben wrote: > Properties do not look like functions but are implemented as functions. > there is no requirement that a variable must hide behind a property, or > that it Must allow both read and write access. Agreed. I was providing what I thought might be a common case. The fact that properties can distill functionality into something that looks like a variable is partly why they're so powerful. >> [Ship] property a: >> def __init__( s, v): >> __set__( s, v) > > Why property constructor? Why not? It's as good a way as any to give a variable-backed property an initial value. Setting it directly would break the encapsulation of the property. > I recall reading somewhere That the Beta language allowed subclassing > anything Yep. Because Beta has no classes, but rather works on a prototype system. Everything is an object. The "class" of an object is the interface it supports at that particular time. To create a new object, clone an existing one, and modify it to taste. Seriously powerful. Seriously hard to keep track of. Neat language. -- Mark From litnsio2 at dreamwiz.com Thu Aug 26 08:26:38 2004 From: litnsio2 at dreamwiz.com (Intaek LIM) Date: 26 Aug 2004 05:26:38 -0700 Subject: building errors with py2exe Message-ID: i'd tried to build my work with py2exe. my work consisted of: D:\temp\main.py D:\temp\ui\__init__.py (contains __all__=['dlg','dlgevent'] D:\temp\ui\dlg.py D:\temp\ui\dlgevent.py D:\temp\mymod\__init__.py (contains __all__=['session','sessionevent'] D:\temp\mymod\auth.py D:\temp\mymod\session.py D:\temp\mymod\sessionevent.py i wrote build file like ths: #build.py from distutils.core import setup import py2exe setup(console=["main.py"]) then, i typed two commands as follows: D:\Temp>SET PYTHONPATH=D:\Temp D:\Temp>python build.py py2exe a bunch of files created under 'dist' and 'build' once i executed main.exe under 'dist', the result was, Traceback : File "main.py", line 1, in ? AttributeError: 'module' object has no attribute 'auth' in build log, py2exe only includes two __init__.py files and does not include anything else in the same folder. how do i solve this? Lim. From jzgoda at gazeta.usun.pl Sat Aug 7 17:46:51 2004 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Sat, 7 Aug 2004 21:46:51 +0000 (UTC) Subject: Going the PL/1 way References: Message-ID: Tim Peters pisze: >> You want to say "if you want any improvement, do it yourself"? Sure, >> it's much better than Java's JCP, but expect >> http://catb.org/~esr/jargon/html/F/fork.html if enough people will share >> the same annoyance and anger. > > I don't understand. If you believe that nobody is volunteering work > on things you want them to work on now (which may well be true, > although it's false that volunteers don't contribute work on thread > and performance issues already), how could merely forking Python make > such volunteers appear? Sorry, I am biased, we have "PLD Linux Distribution" in here in Poland, where forks are considered as "development model". ;) Generally, I see adding features a more desired attitude in developer's community than simple fixing problems and this is my point (and I think Miklos's too). >> I write some free software, but I never tell users "go fix it yourself". >> This is rude. > > Under the assumption that volunteers exist who want to work on what > you want them to work on, but that they've somehow managed to miss > Python's patch tracker, Michael was helpfully giving them the one clue > they still needed to make you happy . I didn't submit any patch to Python. I even don't know how to improve Python. I just use Python in my daily work and I go into the same problems as others get. -- Jarek Zgoda http://jpa.berlios.de/ From photos at conversent.net Fri Aug 6 19:14:16 2004 From: photos at conversent.net (S. David Rose) Date: Fri, 06 Aug 2004 23:14:16 GMT Subject: Python Win32 & TWAIN scanning? Message-ID: Hello everyone. I am very much enjoying learning python. I am fiddling with a project that I've decided to use on the Win32 platform. I'd like to be able to scan a document as a graphic and save it thru Python to a file. I believe that on Windows, all scanning is done thru the TWAIN interface. I'd like to use a USB scanner. I've googled for info. regarding Python, PIL, and scanners but haven't seen anything related to what I'm looking for. Can anyone out there 'bump' me in the right direction please? Thank you! Dave Rose From dd55 at cornell.edu Fri Aug 20 08:47:25 2004 From: dd55 at cornell.edu (Darren Dale) Date: Fri, 20 Aug 2004 08:47:25 -0400 Subject: My only complaint about Python In-Reply-To: <1uuai0l4k13g9gtv55fe7hh2c8io8grr3a@4ax.com> References: <1uuai0l4k13g9gtv55fe7hh2c8io8grr3a@4ax.com> Message-ID: Tim Roberts wrote: > Darren Dale wrote: > >>.... As a scientist funded by the NSF, I feel compelled to >>do all my work using free software (I feel compelled to use free >>software, regardless). > > > Then what on Earth are you doing with Windows? I am working on switching to Linux. I cant commit until I graduate in 6 months. From http Sat Aug 14 19:57:12 2004 From: http (Paul Rubin) Date: 14 Aug 2004 16:57:12 -0700 Subject: Generators versus Coroutines References: Message-ID: <7x7js1i887.fsf@ruckus.brouhaha.com> Michael Sparks writes: > > It seems to me that in python, generators are not truly coroutines. > > Assuming you mean there isn't available a default scheduler for them, or > there isn't pre-emption built-in I agree. If you mean something else, I'm > curious as to what you think is missing. (I've also been using generators > as co-routines for sometime for various reasons) You can't yield across multiple levels of function calls. That's why they're called "simple generators" instead of just "generators". From martin at v.loewis.de Thu Aug 5 10:19:33 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 05 Aug 2004 16:19:33 +0200 Subject: [Python-Dev] RELEASED Python 2.4, alpha 2 In-Reply-To: <411231C8.3020308@interlink.com.au> References: <411231C8.3020308@interlink.com.au> Message-ID: <411241F5.3080602@v.loewis.de> Anthony Baxter wrote: > Python 2.4a2 is an alpha release. We'd greatly appreciate it if you > could download it, kick the tires and let us know of any problems you > find, but it is not suitable for production usage. The Windows installer should support upgrading from a previous Python 2.4 installation. If you have previously installed 2.4a1, you may try this out; please report any problems you find. Regards, Martin From aleaxit at yahoo.com Thu Aug 26 17:09:00 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 23:09:00 +0200 Subject: Inline Conditionals? References: <1gj4rpq.1oyt89b14xvbdqN%aleaxit@yahoo.com> <1gj5bit.rt2tmzcznspxN%aleaxit@yahoo.com> <7xbrgxobts.fsf@ruckus.brouhaha.com> Message-ID: <1gj5eu6.11pmwsddky84nN%aleaxit@yahoo.com> Paul Rubin wrote: > aleaxit at yahoo.com (Alex Martelli) writes: > > aux = [] > > for x in Somelist: > > if x.property: > > aux.append(foo(x)) > > else > > aux.append(foo(x)) > > > > would be vastly more readable; "sparse is better than dense" and any LC > > is far too dense to be Pythonic here. > > Hmm, > > [ x.property ? foo(x) : bar(x) for x in Somelist ] > > doesn't seem too dense, unless you consider -every- LC to be too > dense, in which case why have them? I don't, but I do consider almost every application of ternary to result in too-dense code, which is why I'm ecstatic not to have them. > more readable and harder to get wrong, unlike your sparse example, > which has 'foo' on both branches of the conditional where you meant > 'foo' and 'bar'. ...as several people already noticed, proving the great readability of the sparse way of expressing oneself... Alex From mslimmer at csbuilders.net Mon Aug 16 02:44:44 2004 From: mslimmer at csbuilders.net (Max Slimmer) Date: Sun, 15 Aug 2004 23:44:44 -0700 Subject: ADOdbapi converting all data to strings In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022DFA@exchange.hqamor.amorhq.net> Message-ID: I guess I wasn't clear and only confused the question with date. The problem I have is that NUMERIC data time fields are being returned as strings. So if the database has a column declared as int or as float or number of any kind, when I do a select I get back the value as a unicode string and I want integers to be returned as integers and numbers with percision (decimal points) to be returned as float. Dates get returned as type datetime and that is great, it is the NUMERIC data types that are returned as strings which is the problem. > -----Original Message----- > From: Robert Brewer [mailto:fumanchu at amor.org] > Sent: Sunday, August 15, 2004 11:18 PM > To: max; python-list at python.org > Subject: RE: ADOdbapi converting all data to strings > > > max wrote: > > I am trying to access a foxpro database, using odbc all is well except > > that dates prior to 1970 are not returned as valid usable data, so > > would like to use ADO. When I select data containing numbers (long or > > float) they are converted and returned as unicode strings. Dates are > > returned as datetime.date which is great. Is there any way to change > > this behavior other than to explicitly change back all fields using > > cursor.description information. > > I *think* you're saying that you have a COM date (which is similar to a > float), and want a datetime.date. > > > import datetime > # 12/30/1899, the zero-Date for ADO = 693594 > zeroDate = datetime.date(1899, 12, 30).toordinal() > > def coerce_datetime(value): > return datetime.date.fromordinal(int(float(value)) + zeroDate) > > > COM times are more complicated. Inquire further if you need to handle > them. > > > Robert Brewer > MIS > Amor Ministries > fumamchu at amor.org > From brett at python.org Wed Aug 25 15:03:49 2004 From: brett at python.org (Brett C.) Date: 25 Aug 2004 12:03:49 -0700 Subject: python-dev Summary for 2004-08-01 through 2004-08-15 References: <3l3pi0pgmgu0uir1ucnj0rlfo355c6i5cp@4ax.com> Message-ID: <8ab0589d.0408251103.13ddda04@posting.google.com> Arthur wrote in message news:<3l3pi0pgmgu0uir1ucnj0rlfo355c6i5cp at 4ax.com>... > On Mon, 23 Aug 2004 21:50:48 -0700, Brett Cannon > wrote: > > > >But then Guido decided to make my life difficult by saying that if the > >community could come up with an agreed-upon alternative syntax to > >propose to him he would consider ripping out the '@' syntax; decorators > >have always been experimental and '@' was checked in so people had > >*something* to play with. This meant everyone and their mother started > >to propose both new and old syntaxes for decorators. This led to a > >record amount of email on python-dev (at least compared to what we have > >archives for; back to April 1999). > > > > >"In the old days, Guido would Pronounce, and we'd all bite our tongues > >(although not necessarily each his own). The less time Guido can make > >for Python, the more important becomes graceful capitulation." Tim said > >this and it makes me wish for the old days. People had *months* to > >comment on decorators and no one spoke up until something went into the > >language. Procrastination is not a virtue when it comes to major > >language evolution discussions. What was worse was when the emails > >started repeating themselves (which was pretty much from the get-go when > >this exploded). Seemed like people decided to start talking without > >doing some research. Granted the PEP was outdated and the wiki page was > >not up yet, but this stuff was covered in the Summaries before and you > >could have just Googled for the previous threads. > > Perhaps you could clarify your position a bit. I think the > "community" understands some fundamental difference between posting to > python-dev and to python-list. python-dev is meant for discussing details about Python's evolution. The idea is that pie-in-the-sky ideas get hashed out in the community (which c.l.py is the gateway), once it gets clarified and has community support it moves over to python-dev, it gets discussed there, and either gets accepted, canned, or revised and sent back out to the community for more refinement. Obviously this is not hard and fast, but in general that is how it is supposed to work. > If not Aahz is normally there to > remind them. > =) > Guido's "genius" extends to marketing, IMO. > > Having some sense of participation in the fate of Python, even if bit > hullicinatory, is fundamental to the development of its following. A > clasic form of guerilla marketing. Considering that the Python > markteing budget in $ is 0, I think it would be a mistake to have the > community believe that their only role is to read the release notes. > But the community shouldn't think that. Just read the developer intro (http://www.python.org/dev/dev_intro.html) and you can see how many mentions there are of the community in it. Participation is practically required for a PEP to even be considered being looked at, for instance. > > > >Personally, if I was Guido, I would have said that the community had > >their chance to speak up and they just didn't take it. > > I think you are inadvertently going somewhere dangerous here. A > significant part of the community finds that their first appropriate > opportunity to comment to be after some initial decision at python-dev > - the Senate. It then goes to the People. We the rowdy poeple then do > our rowdy thing. > > You see the point... > > I don't think you want to say to the People, either to crash the > Senate floor, or hold their peace, > Just to start off, I hope everyone realizes this is my opinion and in no way do I represent python-dev in any official way. Even with the Summaries I just happen to be dumb enough to do them so they just let me play in my little corner while I write up the history book. =) OK, with that disclaimer out of the way... That is the reverse order of things are supposed to be. It should go: the idea being put before the people, they let their collective voice be known, and then the Senate takes a look and has a vote. We try to use the community as a basic filter for feature ideas, python-dev hashes out the details. Trust me, you don't want python-dev involvement unless you want really nitty-gritty arguments over things as small as function names and stdlib coding style. It is not a party with Barry getting plastered on beer, Tim with a lady on each arm, and me getting stoned in a corner with the crack that Barry gave me earlier while Raymond is tweaking out on Speed I am sure people are going to be sick of my political system analogies, but my bachelors is in philosophy so it's how I think. =) Think of c.l.py as the general public. Its role is to come up with ideas and to voice its opinion on those ideas. python-dev is the advising committee to the BDFL. Its role is to take ideas from the community and to generate its own in terms of running PythonLand in terms of day-to-day details; it's Guido's cabinet. Guido, the dictator, holds absolute power and makes final decisions on things that the cabinet brings in front of him. It actually mirrors the US government fairly well sans the ability to overturn the dictator =) . Although it is in no way a direct, or even indirect democracy (then again it could be argued neither is the US with the amount of political passivity in the country). People live in PythonLand if they are happy but really have no direct vote unless the dictator gives it to them on some specific issue. And if people really don't like that they are free to leave although no one wants that to happen. Yes, we try to listen to what people want, but in the end we all rely on Guido's gut to lead us. And that is the order that things are supposed to flow. Public voices opinion on idea, cabinet fiddles, dictator decides. Usually it goes that way unless someone from the public skips dealing with the public forum and goes straight to the cabinet. If it is a small, simple idea that is fine, but if the idea has any form of complexity the person gets kicked out and told to talk to his fellow man first to see if they like the idea. And this is essentially how it went when decorators were first brought up. But then the public decided to throw a little mutiny over the dictator's decision. It's the first time I know of where the community came back to really snap at Guido for his decision (all other times has been people whining but eventually people said, "I wish you had not done that, but I will just deal with it and trust you"). I think everyone (community, python-dev, maybe even Guido) has learned some lessons from this whole experience. I just don't want people to suddenly get the impression that they can always just throw a little mutiny every time Guido makes a decision. Do that and he will just ignore what people want period and never even give people a chance to propose an alternative once it reaches python-dev. And I want people to realize my tirade was just that, a personal tirade. It was out of frustration and thus should be taken with a grain of salt. And that frustration came from the feeling that the Python community, which I love, seemed to suddenly form a mob, grab pitchforks and torches, and started screaming. And then they seemed to hold a public meeting with *everyone* proposing their idea and not completely listening to initial decisions. I truly hope that next time Guido makes a decision that people as a whole disagree with everyone involved can get together and discuss it calmly without flooding my inbox. =) -Brett From aranders at insightbb.com Sat Aug 7 02:06:30 2004 From: aranders at insightbb.com (Alan Anderson) Date: 6 Aug 2004 23:06:30 -0700 Subject: RELEASED Python 2.4, alpha 2 References: <411231C8.3020308@interlink.com.au> <2-SdnZCwNs1SwI_cRVn-uQ@powergate.ca> Message-ID: <53449fcb.0408062139.7dbbeb4d@posting.google.com> Peter Hansen wrote: > Yes, of course after using them for a while they will become more > readable, but there are people who have learned to speak Klingon as > well -- and that doesn't change the fact that Klingon is deliberately > very difficult to learn and awkward. Pardon me for jumping in, but I happen to be attending a conference on the Klingon language at the moment and I wanted to correct a misunderstanding. Yes, Klingon is deliberately "alien", being intentionally created to be unlike many natural languages in many ways. But it's actually rather easy to learn, and it's only "awkward" in a couple of minor ways (embedding comparatives in larger sentences, for example) -- *every* language has its awkward spots. Were Klingon a natural language, its regularity would be exceptional. This is just an anectodal data point that might let you know that what is difficult and awkward from your point of view could very well be simple and straightforward for others who don't share your preconceptions. -- Alan Anderson, professional programmer and amateur Klingonist proud member of the Klingon Language Institute since 1995 qo'mey poSmoH Hol -- language opens worlds -- http://www.kli.org/ From grante at visi.com Thu Aug 12 10:17:01 2004 From: grante at visi.com (Grant Edwards) Date: 12 Aug 2004 14:17:01 GMT Subject: Help understanding Scheme's syntax, procedures and calls References: <95f168b0.0408120120.31433dc7@posting.google.com> <411b577a$0$20523$afc38c87@news.easynet.co.uk> Message-ID: <411b7bdd$0$65612$a1866201@newsreader.visi.com> On 2004-08-12, Peter Hickman wrote: > Is this someone's homework by any chance? According to the OP, it's part of a final exam. -- Grant Edwards grante Yow! Yow! Those people at look exactly like Donnie visi.com and Marie Osmond!! From anthonybaxter at gmail.com Tue Aug 24 00:27:15 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Tue, 24 Aug 2004 14:27:15 +1000 Subject: __name__ becoming read-write? In-Reply-To: References: <3b8ki0tlphodtt8ge8an274qp78ihp1i3n@4ax.com> Message-ID: On Mon, 23 Aug 2004 23:17:25 GMT, Arthur wrote: > > "So wait, this stuff that _looks_ like code in a > >function, isn't actually? what the hell?" The new syntax[1] for > >decorators is at least very obvious that something _new_ is going on. > > I am thinking (and I think Paul is thinking) that we can say the same > thing, succintly, in a manner that has precedence in the language > > Mine's a one-liner that does not totally relieve the magicians burden > to be - somwhere down the line - a bit expressive I'm not _quite_ sure what it is you're asking for here, but it _seems_ like you want to have two different blocks inside a def - the first is the meta-block, which contains docstrings and other magic attributes, while the second is the actual code body? Is this correct? If this is the case, I think it's _possible_ that in the future we might see something like this, for typing purposes. Maybe. I'm not sure. But if we do, I can't see any point _at_ _all_ to signifying magic things with arbitrary words surrounded with __under__ meaning 'under is a decorator'. While Python does use __foo__, the list of values for foo that are meaningful is well described and documented. As to the specific detail about whether you can assign to a functions __name__ from inside the function - this will break a lot of tools that attempt to handle python code. How is an editor to find the method 'frobulate' in a .py file? Right now, it can be done with a pretty simple regexp. Even if one of the syntaxes for decorators that insert the decorators on the def line goes in, you can still do it with a more complex regexp. But something like this? class Frobozz: def frobulate(): meta: __name__ = defrobulate An IDE or editor that tries to find defrobulate is going to go insane. One final clarification - altering a method's __name__ does not change it's name in the class's __dict__. >>> class A: ... def foo(self): pass ... foo.__name__ = 'bar' ... >>> A().bar() Traceback (most recent call last): File "", line 1, in ? AttributeError: A instance has no attribute 'bar' >>> A().foo() >>> From duncan.booth at invalid.invalid Sun Aug 8 09:20:34 2004 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 8 Aug 2004 13:20:34 GMT Subject: @decorator syntax is sugar, but for what exactly? References: Message-ID: Dan Sommers wrote in news:m2u0vdj1bn.fsf at unique.fully.qualified.domain.name.yeah.right: > On Sun, 8 Aug 2004 18:24:58 +1000, > Anthony Baxter wrote: > >> In many cases, these new features actually lead to smaller, simpler >> code. I challenge _anyone_ to tell me that >> apply(func, args, kwargs) >> is better than >> func(*args, **kwargs) > > Okay, I will. The old way is better than the new way. > > Explicit is better than implicit, after all. > > Given your second example, is func the name of a function or an object > that references a function? Can I grep my source code to find a > function named func? (Okay, I'll find the variable named func, so at > least I'll have some clue as to what's going on.) Is there a "from > module import func" statement in sight? What happens when I look up > "func" in the Python documentation to see if it's a built in name? Why do you ask this about the second form only? func is a name that references a function in both cases. It doesn't matter whether that name was assigned directly with a def statement, or is the result of a subsequent binding. > > C did the same thing recently. > > Old C: (*f)( argument ); > > New C: f( argument ); > > With the old syntax, I knew immediately that f was a pointer to a > function and that the function to which it pointed was being called > indirectly. With the new one, I have to track down a definition or > declaration of f to see that. For 'recently' read 1987. In fact most C compilers probably implemented this feature before the ISO standard came out, but it was a feature of the first standardised version of C. I remember around that time being extremely glad that I could finally omit those extraneous parentheses. From heikowu at ceosg.de Mon Aug 9 14:51:12 2004 From: heikowu at ceosg.de (Heiko Wundram) Date: Mon, 9 Aug 2004 20:51:12 +0200 Subject: What are decorators? In-Reply-To: <200408092025.42519.heikowu@ceosg.de> References: <68BA7704-EA25-11D8-9BC6-000A9574CFD8@earthlink.net> <200408092025.42519.heikowu@ceosg.de> Message-ID: <200408092051.12507.heikowu@ceosg.de> I forgot to append the actual output from the two examples. The first example (func_spec) outputs: heiko at d168 ~ $ python2.4 test.py y's author and version: Heiko Wundram 0.1 z's author and version: Somebody else 0.2 Authors, and functions by authors: {'Somebody else': 1, 'Heiko Wundram': 1} Calling y. Calling z. heiko at d168 ~ $ And the second example (debugger) outputs: heiko at d168 ~ $ python2.4 test3.py ---- DEBUGGER STARTS HERE ---- Entering: y Arguments: (<__main__.x object at 0xb7bff2cc>,) Keyword arguments: {} Running function... Function returned: (42, 'the answer to everything') Leaving: y ---- DEBUGGER ENDS HERE ---- ---- DEBUGGER STARTS HERE ---- Entering: y Arguments: (<__main__.x object at 0xb7bff2cc>, True) Keyword arguments: {} Running function... Running function raised exception. Traceback (most recent call last): File "test3.py", line 14, in debugf retv = f(*args,**kwargs) File "test3.py", line 31, in y raise Exception, "We raise an exception here." Exception: We raise an exception here. Leaving: y ---- DEBUGGER ENDS HERE ---- Traceback (most recent call last): File "test3.py", line 39, in ? ob.y(True) File "test3.py", line 14, in debugf retv = f(*args,**kwargs) File "test3.py", line 31, in y raise Exception, "We raise an exception here." Exception: We raise an exception here. heiko at d168 ~ $ HTH! Heiko. From deetsNOSPAM at web.de Tue Aug 31 13:54:09 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Tue, 31 Aug 2004 19:54:09 +0200 Subject: python port References: Message-ID: Ajay wrote: > hi! > > if i am porting an existing python package to a different environment and > the package uses some C code, would the port only involve recompiling it > under the new envionment. for pocket pc's would recompiling using embedded > Visual c++ with the pocket pc sdk be enough? > or is there more to it? Depends your code - simple stuff might work, but systemcalls and the like may behave differently or not exist at all. -- Regards, Diez B. Roggisch From jeff at ccvcorp.com Thu Aug 12 16:02:09 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Thu, 12 Aug 2004 13:02:09 -0700 Subject: multiline snippets with triple quotes In-Reply-To: References: Message-ID: <10hnj4bjqojjh05@corp.supernews.com> Christoph Zwerschke wrote: >I sometimes use triple quotes in order to produce snippets of multiline >code, like that: > >if output == html: > snip = ''' > Hello, World >

    What's up?

    > ''' >else: > snip = 'Hello!' > > [...] >So, what would be the pythonic way to implement such multiline snippets? > > IIRC, sequential strings with only whitespace in between them are automatically concatenated. So the above could be equivalently written as: if output == html: snip = "\n" "Hello, World\n" "

    What's up?

    \n" "\n" else: snip = 'Hello!' This does have the disadvantage of requiring explicit newlines, however. Jeff Shannon Technician/Programmer Credit International From mcfletch at rogers.com Fri Aug 6 12:01:24 2004 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Fri, 06 Aug 2004 12:01:24 -0400 Subject: Queue qsize = unreliable? In-Reply-To: References: <1091805850.15192.12.camel@localhost> Message-ID: <4113AB54.1060307@rogers.com> Michael Hudson wrote: >"Mike C. Fletcher" writes: > > > >>Tim, of course, would know better, but that's always been my interpretation. >> >> > >Can I please quote this out of context? :-) > > Perfectly true statement, so why not :) . :) Mike ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From squirrel at WPI.EDU Mon Aug 16 11:33:41 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Mon, 16 Aug 2004 11:33:41 -0400 Subject: Newbie question about Tkinter In-Reply-To: References: Message-ID: On 16 Aug 2004, Andr? Roberge wrote: > The following program (Python 2.3, under Windows XP) > === > import Tkinter as Tk > A = Tk.Tk() > A.title("1") > A.mainloop() > B = Tk.Tk() > B.title("2") > B.mainloop() > === > opens window A and waits for it to be closed before opening window B. For the record, you should only use Tk() once in your program; besides being the main top-level window, it also instantiates Tk and the Tcl interpreter. If you want multiple top-level windows, use Tk() for the main one and Toplevel() for any additional ones. > However, the following opens both windows "simultaneously". I tought > it would give the same result as the one above... I am confused. > ==== > ==== > Anyone can explain or give a pointer to the answer. Calling .mainloop() on any widget enters the "main event loop", which waits for keyboard/mouse events and dispatches them accordingly. .mainloop() typically doesn't return until the main top-level window (A or B in this case) is destroyed. In the first example, you're calling A.mainloop() before creating B; hence A must be destroyed in order for A.mainloop() to exit. Try each of the above in the interactive interpreter to see exactly what's going on (Tk works beautifully in an interactive mode). Rewriting the above using Toplevel: import Tkinter as Tk A = Tk.Tk() A.title("1") B = Tk.Toplevel(A) B.title("2") A.mainloop() Passing A as an argument to Toplevel (to specify its master) is optional; if you don't, Tkinter will automatically pick A as its master. From reynirhs at mi.is Thu Aug 26 22:11:05 2004 From: reynirhs at mi.is (Reynir Stefánsson) Date: Fri, 27 Aug 2004 02:11:05 +0000 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: So spake R Baumann: > >"Xah Lee" wrote in message >news:7fe97cc4.0408251356.34f2102a at posting.google.com... >> Larry Wall and Cults >> (Lazyness, Impatience and Hubris) >> 200012 >> > > >In this context --- This is the STUPIDEST thing I've ever heard. What a >maroon! What a Trollup! Well, wasn't it lwall that said: "All language designers are arrogant. Comes with the territory."? -- Reynir Stef?nsson (reynirhs at mi.is) From nytimes at swiftdsl.com.au Tue Aug 17 10:10:54 2004 From: nytimes at swiftdsl.com.au (huy) Date: Wed, 18 Aug 2004 00:10:54 +1000 Subject: Best programming language In-Reply-To: References: Message-ID: <41221176$0$27222$61ce578d@news.syd.swiftdsl.com.au> Roman Suzi wrote: > ;-) > > Just type into google > "best programming language" > and press (I am lucky) > > > Sincerely yours, Roman Suzi Try typing "programming language" and press "I'm feeling lucky" Ahhh....that's more like it :-P Huy From spam_me_gently_with_a_chainsaw at yahoo.com Mon Aug 2 11:54:34 2004 From: spam_me_gently_with_a_chainsaw at yahoo.com (Double Dumbass on You) Date: Mon, 2 Aug 2004 08:54:34 -0700 Subject: Trimming a string References: <10gsmuieo65du5d@news.supernews.com> Message-ID: <10gsotqjc2qrl54@news.supernews.com> Do you feel better about yourself for having posted a smug, shithead-type answer, troll?? As a matter of fact, I was in a near fatal car wreck about 7 years ago. Suffered some brain damage. Now, I can't remember minute details such as that which I asked. I have read the python documentation numerous times. Sometimes, I just need a simple answer to a simple question, you simple cocksucker. GO FUCK YOURSELF, it will be time well spent for you. "wes weston" wrote in message news:ektPc.165630$OB3.11201 at bgtnsc05-news.ops.worldnet.att.net... > Double Dumbass on You wrote: > > I have a string that is 7 characters and represents file mode in UNIX/LINUX > > from rpm: > > > > 0100755 > > > > I don't care about the 0100 portion, I am only interested in the file > > permissions portion which is 755. How can I get three characters from the > > string starting at the right? ( -OR- strip 4 characters from the left? ) > > > > > DD, > > >>> x = "0100755" > >>> print x[4:] > 755 > > Reading the tutorial is really time well spent. > wes > From nospam at mega-nerd.com Fri Aug 13 09:18:48 2004 From: nospam at mega-nerd.com (Erik de Castro Lopo) Date: Fri, 13 Aug 2004 23:18:48 +1000 Subject: Why I love python. References: <411C8CD9.32F39C2@mega-nerd.com> Message-ID: <411CBFB8.22A08E9F@mega-nerd.com> Brian Quinlan wrote: > > You are comparing apples and oranges. Yes, Ocaml and Python are very different languages but ... > The programmer provides OCaml > with additional information that allows it to interfer the type. But Ocaml does have parametric polymorphism, ... > Looking at the example above, the OCaml equivalent would be: > > let sum x,y = x + y;; > > But this function would only work for integers because the * operator > only applies to integers. If you wanted to multipy floats then you > would write: > > let sum x,y = x +. y;; > > So there is no magic in OCaml, just a different way of providing type > information. Using ints and floats is a bad example because Ocaml has different operators for float and int. A better example might be a function to do the Python eqivalent of string.join (list_of_strings, ", ") Ie: (* The list version *) let rec comma_join lst = match lst with [] -> "" | hd :: [] -> hd | hd :: tl -> hd ^ ", " ^ (comma_join tl) ;; (* The array version, an example only. *) let comma_join ary = comma_join (Array.to_list ary) ;; Ocaml has no problem differentiating two functions with the same name by looking at how the function arguments are used and assuming the function is generic if insufficient information is available. Erik -- +-----------------------------------------------------------+ Erik de Castro Lopo nospam at mega-nerd.com (Yes it's valid) +-----------------------------------------------------------+ "One World, one Web, one Browser." - Microsoft promotion "Ein Volk, ein Reich, ein Fuhrer." - Adolf Hitler From python at elehack.net Tue Aug 3 17:23:09 2004 From: python at elehack.net (Michael Ekstrand) Date: Tue, 3 Aug 2004 16:23:09 -0500 Subject: Modern dead-tree Python resources Message-ID: <200408031623.09558.python@elehack.net> I'm sitting here looking at my copy of David Beazley's Python Essential Reference, which I find wonderful, but am lamenting that it only covers through Python 1.5.2. And I see that the 2nd edition covers through Python 2.1. Is there a good book that covers Python at least through 2.2 (including new-style classes, etc.)? I'm particularly looking for something with large appendices of reference material. (alternatively, if someone's publishing print versions of the Python documentation, that would possibly be of interest. I know I saw some for Python 1.5 or 1.6 in a used bookstore, but don't recall who published them.) TIA, Michael From abra9823 at mail.usyd.edu.au Tue Aug 3 11:17:53 2004 From: abra9823 at mail.usyd.edu.au (Ajay Brar) Date: Wed, 04 Aug 2004 01:17:53 +1000 Subject: Crypto.PublicKey.RSA.error: Plaintext too large Message-ID: <410FACA1.5050300@mail.usyd.edu.au> hi! I am getting an error - Crypto.PublicKey.RSA.error: Plaintext too large - when verifying the signature of a document. What i am doing is - the document and the signature are downloaded off the net, my verify script then connects to a server and obtains a public key. It then uses the public key to verify the signature. The whole thing works fine when i do the same thing in the interactive interpreter. Its only when i download the files and obtain the public key from the server and then verify, that i get the above error. any suggesstions...ideas??? cheers -- Ajay Brar CS Honours 2004 Smart Internet Technology Research Group http://www.it.usyd.edu.au/~abrar1 From rogerb at rogerbinns.com Tue Aug 10 00:32:37 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Mon, 9 Aug 2004 21:32:37 -0700 Subject: SQL Qeries via XMLRPC References: Message-ID: <3ovlu1-l6f.ln1@home.rogerbinns.com> Simon Wittber wrote: > The problem is, I have a tiny little nag in my mind about the use of > XMLRPC (and therefore HTTP) to implement this. > > Has anyone done this sort of thing before? > > Are there any problems with this strategy that I have not considered? Using XML-RPC is a great way of exposing services and data. You do however want the API exposed to be higher level rather than lower level (for example retrieve an entire record in one go rather than a field at a time). Using XML-RPC does not prevent also adding other service mechanisms such as SOAP, CORBA or whatever is flavour of next year. I would suggest looking at the Cookbook to get a feel for it, and also to see the limitations. For example XML-RPC doesn't support None and SOAP can't handle empty dictionaries. Note that using XML-RPC does not mean HTTP. The most common transport for XML-RPC is HTTP, but you can use it over anything. In one of my projects I use it over SSH (using the Paramiko library to do the SSH part) The existing standard Python library XML-RPC works well, but has the limitation that it doesn't fully support HTTP authentication and it uses one connection per request. The authentication issue can be solved by making authentication part of your exposed APIs, not the underlying XML-RPC transport. The one connection per request will presumably be solved in a future release of the Python library and generally is not an issue on a LAN. The great thing about using XML-RPC is the cross language portability. You can get bindings for any language. One of my projects was a web site with the front end done in PHP (Smarty) and the backend all being Python exposed via XML-RPC over HTTP. Roger From davZZZYYYXXXout at dial.pipex.com Wed Aug 4 11:26:18 2004 From: davZZZYYYXXXout at dial.pipex.com (davout) Date: Wed, 4 Aug 2004 16:26:18 +0100 Subject: newbie question: embedding Python into a C++ app and calling app functions Message-ID: <41110011$0$26988$cc9e4d1f@news.dial.pipex.com> I've a complete Python newbie so please forgive any dumb questions... I'm looking to embed python as a scripting language into my C++ application. The basic idea is to allow the app user to build custom scripts that join toegther various process steps that are represented by process related classes within my C++ app. How can I define this so that my C++ process related classes are available to a python script? From squirrel at WPI.EDU Thu Aug 5 16:07:46 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 5 Aug 2004 16:07:46 -0400 Subject: Decorator syntax In-Reply-To: References: <788E231C269961418F38D3E360D1652526CA1A@tndefr-ws00021.tenovis.corp.lan> Message-ID: On Thu, 5 Aug 2004, Istvan Albert wrote: > The disagreement is caused by trying to achieve a lot of different > things with one feature. > > Thus the solution that is emerging is to cram everything in > front of the function definition. Agreed! Exactly! Most of what people seem to want from decorators are a way to specify function types, do type checking, and give functions attributes / metadata. As I've said before, these are seperable problems and should be treated as such. What little left over that can benefit from general-purpose decoraters will likely not be enough to form a major use case. From squirrel at WPI.EDU Fri Aug 6 15:31:46 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Fri, 6 Aug 2004 15:31:46 -0400 Subject: threads: not locking read-only objects In-Reply-To: <2ni4b4F16u92U1@uni-berlin.de> References: <2ni4b4F16u92U1@uni-berlin.de> Message-ID: On Sat, 7 Aug 2004, Jon Perez wrote: > Is it safe to not put a lock on an object if it will always > be read-only in other threads and will only ever be written to > in just one and always the same one thread? Only if the writes are guaranteed to be atomic: if the object is ever temporarily left in an inconsistent state by the writer (due to a thread switch), the readers will read inconsistent data. If you are sure this can't happen, then yes, doing so is safe. From AntiVir at yalta.us Thu Aug 12 09:54:24 2004 From: AntiVir at yalta.us (AntiVir at yalta.us) Date: Thu, 12 Aug 2004 16:54:24 +0300 Subject: AntiVir ALERT [mail from: contact@bestsex.ru] Message-ID: <200408121354.i7CDsOWj007322@yalta.us> * * * * * * * * * * * * * * * AntiVir ALERT * * * * * * * * * * * * * * * ????????? ????????? ????? ? ??????????????, ??????? ????????? ????? ??????! ???????????: contact at bestsex.ru ???????? ??????: Worm/Mydoom.m ????? ?? ???? ?????????? ??????????. ? ?????????; ???????? ???????? ???.: +38(0654)271828 ????.: +38(0654)231094 web: www.yaltainfo.com email: support at yalta.us Mail-Info: --8<-- From: contact at bestsex.ru To: python-list at python.org Date: Thu, 12 Aug 2004 13:52:52 +0300 Subject: MAIL SYSTEM ERROR - RETURNED MAIL --8<-- This version of AntiVir is licensed for private and non-commercial use. -- AntiVir for UNIX Copyright (C) 1994-2003 by H+BEDV Datentechnik GmbH. All rights reserved. For more information see http://www.antivir.de/ or http://www.hbedv.com/ From miki.tebeka at zoran.com Mon Aug 16 13:49:03 2004 From: miki.tebeka at zoran.com (Miki Tebeka) Date: Mon, 16 Aug 2004 19:49:03 +0200 Subject: Help with reading WinXP registry In-Reply-To: References: Message-ID: <20040816174903.GK4072@zoran.com> Hello David, > Is there a better way to access the registry in a Win32 system? Try the _winreg module with the ...Ex functions. HTH. -- ------------------------------------------------------------------------ Miki Tebeka http://tebeka.spymac.net The only difference between children and adults is the price of the toys From tim.hochberg at ieee.org Fri Aug 20 19:12:30 2004 From: tim.hochberg at ieee.org (Tim Hochberg) Date: Fri, 20 Aug 2004 16:12:30 -0700 Subject: age of Python programmers In-Reply-To: <5_uVc.411$MR2.2033@news1.mts.net> References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> <5_uVc.411$MR2.2033@news1.mts.net> Message-ID: Reid Nichol wrote: > Tim Hochberg wrote: [SNIP] >> While quanta are typically very-very-very small, last I checked the >> key feature of quantum transitions is not that they're small, but that >> there are no intermediate steps. The object is in state A then it's in >> state B, but it's never halfway (or anywhere) between. Like most >> quantum stuff it's better not to think about that too closely. >> >> -tim >> > > Check the definition of the word. May I ask why? I assume you mean this (from another post): > from dictionary.reference.com: > The smallest amount of a physical quantity that can exist > independently, especially a discrete quantity of electromagnetic > radiation. I fail to see a signifigant conflict between this definition of quantum and what I wrote above about quantum transitions. I'll even go out on a limb and speculate that the origin of the term "quantum leap" is with quantum, probably atomic, transitions and refers to a change where there are no intermediate states and not "The smallest possible leap that can exist". [checks] You might look at this, also from dictionary.reference.com: quantum leap A dramatic advance, especially in knowledge or method, as in Establishing a central bank represents a quantum leap in this small country's development. This term originated as quantum jump in the mid-1900s in physics, where it denotes a sudden change from one energy state to another within an atom. Within a decade it was transferred to other advances, not necessarily sudden but very important ones. -tim From peter at engcorp.com Mon Aug 9 14:13:20 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 09 Aug 2004 14:13:20 -0400 Subject: What are decorators? In-Reply-To: References: Message-ID: gohaku wrote: > The discussion on Python Decorators and "@" has piqued my interest on this > "feature?" in programming languages such as Python and Java. > can anybody what is the point in using Decorators? In Python, at least, they seem to be syntactic sugar for the following, as the PEP clearly shows: def func(): pass func = decorator(func) That is equivalent to this with the new proposed syntax (and this is no doubt out of date because I wrote it more than two minutes ago): @decorator def func(): pass In other words, they are simply a function that takes a function and does something to or with it, returning a new function, or perhaps the old one, when it's done. The original use cases seem to have been staticmethod and classmethod. Python doesn't have special syntax for defining these, as for example Java does, so the idiom shown first above was developed, along with a staticmethod() or classmethod() "decorator" function which would modify the original non-static method so that it was now a static method. The folks using this decided they didn't like the fact that the modification came *after* the function definition, since it could be hard to notice it, and probably they didn't really like the feel of the whole thing, since it's sort of hackish and inelegant. If you don't need staticmethod (and the answer to the question "do I need staticmethod?" is "no"), then you don't really need decorators. :-) -Peter From peter at engcorp.com Fri Aug 6 08:08:12 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 06 Aug 2004 08:08:12 -0400 Subject: tweaking @decorator syntax - yet another syntax In-Reply-To: References: <1091715445.9931.17.camel@mango.cmc.ec.gc.ca> Message-ID: <8umdnWTWJtQw6Y7cRVn-uw@powergate.ca> Stefan Eischet wrote: > I don't know if this particular syntax has been discussed already... > please feel free to bash me if it was. ;-) Bash bash. > How about using "is" after the def? Read the PEP. Basically the same as the "as" variant. From thomas at it-snedkeren.BLACK_HOLE.dk Tue Aug 10 10:57:39 2004 From: thomas at it-snedkeren.BLACK_HOLE.dk (Thomas Lindgaard) Date: Tue, 10 Aug 2004 16:57:39 +0200 Subject: Komodo, debugging and multi-threading References: <9418be08.0408090542.37e9113@posting.google.com> Message-ID: On Mon, 09 Aug 2004 06:42:59 -0700, Elbert Lev wrote: > The only way of debugging multithreaded programs - print (or log). Dang! ... but thanks. -- Regards /Thomas From ptmcg at austin.rr._bogus_.com Sun Aug 22 20:45:51 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 23 Aug 2004 00:45:51 GMT Subject: Python is to C as letters are to words. References: Message-ID: <37bWc.9076$Jn5.4795@fe1.texas.rr.com> "Rene Pijlman" wrote in message news:n5bii0ho3p5iqon1pe4k06ebvt8rfk7kif at 4ax.com... > Paul McGuire: > >Maybe Gary meant "letters" like when I write a letter to my wife, > > Do you think he meant performance? How often do you write letters to your > wife, and how long does it take you? > > -- > Ren? Pijlman Let's leave "performance" out of this!! :) -- Paul From chris.cavalaria at free.fr Wed Aug 25 18:33:31 2004 From: chris.cavalaria at free.fr (Christophe Cavalaria) Date: Thu, 26 Aug 2004 00:33:31 +0200 Subject: PEP318: radical notion References: <412a4222$0$293$626a14ce@news.free.fr> <412bc7e6$0$4065$626a14ce@news.free.fr> Message-ID: <412d13bc$0$14159$636a15ce@news.free.fr> Arien Malec wrote: > Christophe Cavalaria wrote in > news:412bc7e6$0$4065$626a14ce at news.free.fr: > >> Arien Malec wrote: > >>> Is there a valid use case that supports arbitrary magical >>> non-metadata transformations of standalone functions? >> >> memoize for example. No metadata, only transformation, doesn't really >> apply to a member function in fact ( although it might be possible ? > > Classically, memoize is implemented as function composition, or as a true > GoF decorator. It's not clear (to me, at least) how much benefit the > syntactic sugar gets you. Ease of writing and reading aren't benefits for you ? >> Why is it that there are always some people who doesn't understand all >> the possibilities of decorators and so want to minimise their >> usefulness ? > > I dunno. Who are those people? My objection to PEP318 is that makes > something that's really powerful (arbitrary transformation) look like a > trivial declaration. If that's your objection, say it. I'm ok with that. But don't do that : people : we need generators for usage a, b, c you : here is a great syntax. It handles case a and b in such a beautiful way and it's much much better that some other proposal people : what about case c ? you : case what ? > In Common Lisp, for instance, a defmacro form hints > that powerful mojo is being performed; the same is not apparent in > PEP318. Well, if the @pie form isn't a clear way to say that something strange is going on, I don't know what is :) From indigo at bitglue.com Wed Aug 18 15:27:50 2004 From: indigo at bitglue.com (Phil Frost) Date: Wed, 18 Aug 2004 15:27:50 -0400 Subject: Embedding Python in Python In-Reply-To: References: Message-ID: <20040818192750.GA30372@unununium.org> No. An easy way to escape that is to start one's code with 'del __builtins__', then python will add the default __builtins__ back to the namespace. Restricting what arbitrary code can do has been discussed many, many times, and it seems there is no way to do it short of reimplementing a python interpretor. On Wed, Aug 18, 2004 at 02:56:04PM -0500, Robey Holderith wrote: > So using this (with a little additional reading) it looks like I > can do this: > > globalDict = {'__builtins__': } > exec(, globalDict) > > And that this will disallow both importing of new modules and direct > access to my namespace. It will however allow access to the > > Would this be secure? > > Paul, what's your take on this? > > -Robey > > On Wed, 18 Aug 2004 14:35:21 -0400, Phil Frost wrote: > > > You probably want something like this: > > > > globalDict = {} > > exec(stringOfPythonCodeFromUser, globalDict) > > > > globalDict is now the global namespace of whatever was in > > stringOfPythonCodeFromUser, so you can grab values from that and > > selectivly import them into your namespace. > > > > On Wed, Aug 18, 2004 at 02:26:00PM -0500, Robey Holderith wrote: > >> > >> Anyone know a good way to embed python within python? > >> > >> Now before you tell me that's silly, let me explain > >> what I'd like to do. > >> > >> I'd like to allow user-defined scriptable objects. I'd > >> like to give them access to modify pieces of my classes. > >> I'd like to disallow access to pretty much the rest of > >> the modules. > >> > >> Any ideas/examples? > >> > >> -Robey From ole_jensen Mon Aug 30 09:42:55 2004 From: ole_jensen (Ole Jensen) Date: Mon, 30 Aug 2004 15:42:55 +0200 Subject: Top Zope sites? References: Message-ID: <41332edb$0$214$14726298@news.sunsite.dk> "Robert Oschler" > Hello, > > Can someone give me the URL's of 2 or 3 top-notch sites built upon > Zope, so I can see what it's really all about? Its right on the Zope.org page: http://www.zope.org/Resources/ZopePowered/ Is it a phpNuke type thing? > How popular is it? > > Thanks. > > > From caleb1 at telkomsa.net Tue Aug 24 22:56:20 2004 From: caleb1 at telkomsa.net (Caleb Hattingh) Date: Tue, 24 Aug 2004 22:56:20 -0400 Subject: Macro expansion: intercept statement interpretation Message-ID: Hi Here is a script I want to be able to write (explanation appears after): *** start of script *** import MyCustomMacroLib # This does the magic I would like help for. # This is not python, but the module imported above # will use this block internally and prevent it # getting to the interpreter. defmacro MyMacro1: form = """for <#1> := <#2> to <#3> do begin <#4multiline> end""" subsituteWith = """for <#1> in range(<#2>,<#3>+1): <#4multiline>""" for i := 0 to 3 do begin # This is not python syntax, but the module print i # imported above makes it so that this print 'hello' # is first checked against defined macros end # and substitutions are made if syntax # matches """ Should give: 0 hello 1 hello 2 hello 3 hello """ *** end of script *** I want the module "MyCustomMacroLib" to set up something where I can have write code that checks each of the statements of this script, and does macro expansion before passing the result to the python interpreter. When the (undefined in python) "defmacro" statement is encountered, the module sets this up in memory as some kind of "macro" object, and as the remainder of the lines is parsed, a syntax check is made to see if a macro fits, and if so the expansion is performed and the result is passed to the interpreter/compiler. This particular (useless) example sets up a macro where loops can be written in objectpascal form. I actually have no particular need for this kind of functionality (I think?), but it looks cool!. I got interested after reading a couple of Paul Grahams essays about lisp. I also suspect there actually may be some real problem domains where extending the language syntax may be beneficial - I just cannot think of any right now :) I can figure out the minor practical details of things like handling indention, code objects and the like myself, but I don't know where to start to try and intercept statements before they get to the interpreter. Some of the docs I read today appear to indicate that there may also be differences in the way interactive interpreter and command-line execution deal with statements. I am lost in the python internals! Note that I could easily write a script that takes another script as an argument, preprocesses it, and evaluates the resulting list of python statments. I do however, prefer a drop-in module as shown above. Plus, I would also like to do this dynamically in the interpreter. Any ideas, or is this impossible? (gratuitous guru-bait) Thanks Caleb From usenet_spam at janc.invalid Wed Aug 18 18:29:57 2004 From: usenet_spam at janc.invalid (JanC) Date: Wed, 18 Aug 2004 22:29:57 GMT Subject: age of Python programmers References: <889cbba0.0408181206.1812881c@posting.google.com> Message-ID: Gerardo Herzig -Departamento de Proyectos Especiales e Internet- Facultad de Medicina schreef: > 30 years old. First program at 11 (Basic) on ZX Spectrum. /me too (now 30 & started with ZX Spectrum Basic at 11) -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From follower at gmail.com Tue Aug 17 12:13:33 2004 From: follower at gmail.com (Follower) Date: 17 Aug 2004 09:13:33 -0700 Subject: ANN: Python Decrypt PDF script -- builds on pdftools Message-ID: Hi, I wanted to extract the meta-data from an encrypted/protected PDF file and could not find any Python scripts to do this. So, I decided to write something myself, the result follows. This demonstration utility requires the `pdftools` files from but the decryption functions themselves should be usable with other Python PDF libraries. Documentation is marginal and all I can say is that worked on the three PDF files I tested it on... :-) --Phil. P.S. The usual Usenet-mangling warning applies--yeah, I know--I should put it up on a web site somewhere... :-) #!/usr/bin/python # # Decrypt PDF Info # # Decrypts PDF files and displays meta-data associated with them. (If the # file isn't encrypted the information is displayed as is.) # # The results are similar to xpdf's `pdfinfo` utility. # # It should be possible to decrypt all of the objects contained # in the PDF, but this only reads the Document Information Dictionary. # # (Note: All the PDF handling is provided by `pdftools`, this just adds # the ability to deal with encrypted PDF files.) # # Requires: # + pdftools # # # Based on: # + `pdfdecrypt.pl` # [PDFPL] # # Incorporates: # + RC4 from CipherSaber implementation by Ka-Ping Yee # # # References: # + [PDFE] # # Author: # follower at myrealbox.com (Standing on *many* shoulders...) # import sys import md5 import struct from pdftools import PDFdocument def arcfour(input, key): """ Perform the ARCFOUR (RC4) algorithm on a given input list of bytes with a key given as a list of bytes, and return the output as a list of bytes. (From CipherSaber implementation by Ka-Ping Yee ) """ i, j, state = 0, 0, range(256) for i in range(256): j = (j + state[i] + key[i % len(key)]) % 256 state[i], state[j] = state[j], state[i] i, j, output = 0, 0, [] for byte in input: i = (i + 1) % 256 j = (j + state[i]) % 256 state[i], state[j] = state[j], state[i] n = (state[i] + state[j]) % 256 output.append(byte ^ state[n]) return output _passwordPad = [ 0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41, 0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, 0x01, 0x08, 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80, 0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a] passwordPad = "".join([chr(b) for b in _passwordPad]) def calculateFileKey(fileId, ownerHash, userHash, permissions, userPassword = ""): """ Calculates the file key for the document as described in references (see [PDFE] and [PDFPL]). """ md = md5.new() md.update((userPassword + passwordPad)[:32]) md.update(ownerHash) md.update(struct.pack("" % sys.argv[0]) doc = PDFdocument(filename) try: fileKey = getFileKey(doc) except NotEncryptedException: fileKey = "" showDocumentInfo(doc, fileKey) From jeff at ccvcorp.com Tue Aug 31 14:45:05 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Tue, 31 Aug 2004 11:45:05 -0700 Subject: "Content-Length" header In-Reply-To: References: <96c2e938.0408302057.61df147b@posting.google.com> Message-ID: <10j9hmqq3gn8i43@corp.supernews.com> Peter Kleiweg wrote: >Jeremy Bowers schreef: > > > >>Both cases: 52 ^ 8: 53,459,728,531,456 (53 trillion) >> >> > >A bit less: 53 billion > > > >>One case : 26 ^ 8: 208,827,064,576 (208 billion) >> >> > >208 billiard > > Note that Jeremy Bowers' usage is standard American usage (billion = 10^9, trillion = 10^12). This is a difference between American English and British-style English. (I would presume, though I don't know directly, that Australia and New Zealand probably use the British style...) In America, "billiard" is only a funny variant on playing pool. ;) Jeff Shannon Technician/Programmer Credit International From skip at pobox.com Wed Aug 18 10:36:09 2004 From: skip at pobox.com (Skip Montanaro) Date: Wed, 18 Aug 2004 09:36:09 -0500 Subject: age of Python programmers In-Reply-To: References: Message-ID: <16675.26969.76427.714215@montanaro.dyndns.org> Christopher> I'm 19. The only other Python programmer I know personally Christopher> is 21. Congrats on discovering Python at 14; back then I Christopher> thought VB was a godsend. ;) Whippersnapper... At 14 I would have thought a computer was a godsend. ;-) (I'm 50, btw.) Skip From ramen at lackingtalent.com Fri Aug 27 14:57:20 2004 From: ramen at lackingtalent.com (Dave Benjamin) Date: Fri, 27 Aug 2004 18:57:20 -0000 Subject: Alex Martelli: Welcome back! References: <1gj70sk.1o4cuwepco564N%aleaxit@yahoo.com> Message-ID: In article <1gj70sk.1o4cuwepco564N%aleaxit at yahoo.com>, Alex Martelli wrote: > Batista, Facundo wrote: > >> [Dave Benjamin] >> >> #- Asunto: Alex Martelli: Welcome back! >> #- >> #- It's nice to see you around here again! >> >> +1 > > Heh, thanks. BTW, anybody interested in the readings we choose for our > marriage (me and Anna, who's also going to be my coeditor for the Python > Cookbook Second Edition) can have a look at http://www.aleax.it/mar.html Congratulations! May you give new meaning to "pair programming". =) > ... Pythonistas will find one of the poems, ahem, interesting. (Some > photos are at http://bonanna.multiply.com/photos/album/1 , but > mentioning them would be OT, since they're not Python-related;-). Yes, but Sir Peters omitted an important detail; is it: Over the toilet paper roll is better than under Or is it the opposite? When in the face of ambiguity... -- .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:. "talking about music is like dancing about architecture." From pinard at iro.umontreal.ca Sat Aug 28 08:18:23 2004 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Sat, 28 Aug 2004 08:18:23 -0400 Subject: Call for signatories for J2 Message-ID: <20040828121823.GA3983@titan.progiciels-bpi.ca> [Robert Brewer] > > I'll continue to collect them [...] I carefully reread the proposal, and definitely, count me as: FOR -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From insert at spam.here Mon Aug 9 18:10:00 2004 From: insert at spam.here (Doug Holton) Date: Mon, 09 Aug 2004 17:10:00 -0500 Subject: Python Decorators Voting Form Message-ID: Here is a voting form where you can vote between 3 of the most popular alternatives for the new Python decorator syntax: http://wiki.wxpython.org/index.cgi/PythonDecoratorsPoll Please vote for which one you prefer the most, and feel free to leave your comments as well. This is just to allow us to count up everyone's preferences and maybe help narrow down the alternatives to only 1 or 2 like Guido wants. I know it's not fair to only show 3 options, but these 3 appear to have the most number of different people supporting them based on mailing list traffic. If you like one option but want a different symbol (like "|") or an additional keyword (like "using"), you can vote for it anyway and leave your comment. From jtauber at jtauber.com Mon Aug 16 15:45:17 2004 From: jtauber at jtauber.com (James Tauber) Date: Tue, 17 Aug 2004 03:45:17 +0800 Subject: passing globals to imported module In-Reply-To: <18e7v1-o68.ln1@valpo.de> References: <18e7v1-o68.ln1@valpo.de> Message-ID: <1092685517.18905.202442161@webmail.messagingengine.com> On Mon, 16 Aug 2004 21:24:16 +0200, "Mathias Waack" said: > If you need the global _after_ the import you can just add in foo.py: > > bar.my_global = my_global > > Another solution would be to use a better design;) Well, changing the design was my first thought too :-) I just wondered whether there was a way to set the globals for the import module *before* top level code in the improted module is executed. I'm unclear what the second arg to __import__ actually affects. James -- James Tauber http://jtauber.com/ journeyman of some http://jtauber.com/blog/ From and-google at doxdesk.com Sun Aug 15 05:30:22 2004 From: and-google at doxdesk.com (Andrew Clover) Date: 15 Aug 2004 02:30:22 -0700 Subject: xml attributes question References: Message-ID: <2c60a528.0408150130.5bc3c1b2@posting.google.com> Ajay wrote: > attribs.keys() > [(None, u'ref')] > why? Namespace-aware DOM implementations index attributes by the localName *and* their namespaceURI. The 'ref' attribute isn't in a namespace (signified by 'None') so this should be part of the key to support eg. getAttributeNS efficiently. Don't rely on the Python-style dictionary methods like keys() when you are handling a NamedNodeMap. The Python DOM bindings do not guarantee that it exists, or what it returns if it does. 4DOM behaves differently to minidom as you can see; other implementations are different again. Further, the results of keys(), values() and items() are inconsistent even within single implementations. Sticking to the standard DOM methods, one could say: keys= [attribs.item(i).name for i in range(attribs.length)] -- Andrew Clover mailto:and at doxdesk.com http://www.doxdesk.com/ From imbosol at aerojockey.invalid Thu Aug 12 04:31:58 2004 From: imbosol at aerojockey.invalid (Carl Banks) Date: Thu, 12 Aug 2004 08:31:58 GMT Subject: A decorator syntax not yet mentioned (I think!) References: <60dfb6f6.0408111846.615ee9eb@posting.google.com> <3YWdnYxLf--ObofcRVn-pw@powergate.ca> Message-ID: <2WFSc.12148$Nl1.3243@fe1.columbus.rr.com> Peter Hansen wrote: > > > Carl Banks wrote: > >> steven.bethard at gmail.com (Steven Bethard) wrote in message news:... >> >>>I know there were complaints before about this sort of indentation, >>>but I couldn't find them in python-dev and the comments in the wiki >>>don't discuss this in any detail. Can anyone tell me why this >>>indentation syntax was dispreferred? Specifically, I'm interested in >>>why this is so drastically different from the other paired blocks: >>>if/elif/else, try/except, try/finally, etc. >> >> One thing that's different is that, in all those cases, the second >> block has a keyword that can't appear alone. You can't have an except >> without a try, or an else without an if, but you could have a def >> without a decorate. > > Is this merely a pedantic argument (not sure I use "pedantic" correctly) > or is this an argument based on presumed difficulties in implementing > the idea? Pedantic. > I ask because I'm not sure the issue matters to anyone writing > or reading the code. It certainly wouldn't bother me that > with if/else it's the first part that's required, while with > decorate/def it's the second part. Well, the only thing is, whenever you see a def statement, you don't know if it's decorated right away, so you have to expend one or two extra ergs of energy to look above it and see if it is. (And let's face it, with the dozens and dozens of decorators that will be applied to each and every function, it might be a couple screens up. :) To me, it's totally irrelevant. I think it would bother some other people, though. I've seen the very same argument used against a do...while statement. (The do...while statement didn't bother me either, although ideally I'd prefer do to replace try in try...finally.) -- CARL BANKS http://www.aerojockey.com/software "If you believe in yourself, drink your school, stay on drugs, and don't do milk, you can get work." -- Parody of Mr. T from a Robert Smigel Cartoon From pythongnome at hotmail.com Tue Aug 17 19:44:42 2004 From: pythongnome at hotmail.com (Lucas Raab) Date: Tue, 17 Aug 2004 23:44:42 GMT Subject: Flython References: Message-ID: Oh, Oh, it's magic!! You know!!!... "Dave Benjamin" wrote in message news:slrnci53hk.4hm.ramen at lackingtalent.com... > In article , Peter Hansen wrote: > > Dave Benjamin wrote: > > > >> I just want to say, for the record, that if anyone can successfully build a > >> Python compiler that can produce Flash bytecode, I will personally allow > >> you to throw *any number of pies* in my face, in as public of a ceremony as > >> you desire. Furthermore, I will match you 50/50 in the cost of the pies. > > > > Why on earth (unless it's the liking pies thing or the really wanting > > this to be done thing) would you say that? Flash bytecode is pretty > > straightforward, and Python's not magic. > > Because getting a pie (or twelve) in the face is a lot less work than > actually writing a parser and code generator. I have been writing > ActionScript for two years now, and I am so sick and tired of its lack of > useful data structures (like sets and dictionaries), god-awful > error-checking (any bad message results in the "undefined" value, which > accpets any message and returns the "undefined" value, and so on, until your > error surfaces someplace completely different from where it was caused), > lack of exceptions, lack of any standard for modularity... I could just go > on and on. I'm currently maintaining a 10,000 line ActionScript program, and > I would be so happy to rewrite it in Python right now. > > And Python *is* magic. =) > > > In any case, if this is a serious challenge, you'd better start > > identifying the constraints and minimum requirements, as I'm > > rather positive that it's possible to encode at least *one* > > Python statement (print) into Flash bytecode which would > > execute properly... shall I demonstrate for, say, one pie? > > Good point. I expect at least the full syntax as of Python 2.1, which means > list comps but no "yield" or metaclasses or any fancy stuff like that. > Perhaps one pie per Bagley's Shootout example, or maybe one pie per fully > exposed Flash API (MovieClip, LocalConnection, etc.). I'm open to > negotiation. > > But the irony here is that the amount of work that would go into a Python > port to SWF would be far greater than the amount of suffering I would endure > from a bunch of pies in the face. It's really on my side, because you do all > the work, and then I don't have to write ActionScript anymore. =) > > Best wishes, > Dave > > -- > .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:. > "talking about music is like dancing about architecture." From abra9823 at mail.usyd.edu.au Wed Aug 4 23:44:32 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Thu, 5 Aug 2004 13:44:32 +1000 Subject: cgi script headers - help In-Reply-To: <38ednYf1NLxPP4zcRVn-uA@powergate.ca> References: <38ednYf1NLxPP4zcRVn-uA@powergate.ca> Message-ID: <1091677472.4111ad20660e4@www-mail.usyd.edu.au> thanks...that was it -- Ajay Brar, CS Honours 2004 Smart Internet Technology Research Group Quoting Peter Hansen : > Ajay wrote: > > > hi! > > > > i am generating a file on the fly and making a user download it. > > print "Content-Type: application/model\n\n" > > print "Content-Disposition: attachment; filename=modeldef3\n" > > print str > > > > i set the Content-Disposition to force a download dialog box and also > give > > the file a name. > > however when i view the headers sent by my script, i have only > > HTTP/1.1 200 OK > > Date: Thu, 05 Aug 2004 02:26:48 GMT > > Server: Apache/1.3.19 (Unix) > > Connection: close > > Content-Type: application/model > > > > why isn't the Content-Disposition header coming up? > > Probably because the previous line was terminated with three (3) > newlines, thus marking the end of the header section... > > Note that print includes a newline normally, so including any > other newlines will result in at least a double newline, which > is the delimiter between header and body. > > -Peter > -- > http://mail.python.org/mailman/listinfo/python-list > ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From R.Brodie at rl.ac.uk Mon Aug 9 12:19:04 2004 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Mon, 9 Aug 2004 17:19:04 +0100 Subject: how many bytes in an int References: <9ACRc.1523$bJ2.9739@news1.mts.net> <4116f8ee$0$8076$a1866201@newsreader.visi.com> <41170cd1$0$8076$a1866201@newsreader.visi.com> <41171116$0$8079$a1866201@newsreader.visi.com> <41172C9A.2020301@jessikat.fsnet.co.uk> <41178bde$0$8077$a1866201@newsreader.visi.com> <41179cd2$0$8089$a1866201@newsreader.visi.com> Message-ID: "Grant Edwards" wrote in message news:41179cd2$0$8089$a1866201 at newsreader.visi.com... >By guessing formats and calculating sizes? Or is there a way to >ask for an N-byte integer that I missed? If you use '<' or '>' to force endianness you automatically get 'standard' sizes thrown in; or you can use '=' for native order. The standard sizes are specified in the struct module documentation. From dontreply at caramail.com Mon Aug 2 13:47:14 2004 From: dontreply at caramail.com (Cyrille Lavigne) Date: 2 Aug 2004 10:47:14 -0700 Subject: Concerning classes (Newb question) Message-ID: <6c8fb5be.0408020947.67ef58e@posting.google.com> Hi! I'm very new to the art of programming and I just learn OOP in python. I want to know why the following bit of code crash. Code: class Exemple: def __init__(self): self.list=[] self.var1=3 c=Exemple print c.list, c.var1 Thanks From ptmcg at austin.rr._bogus_.com Fri Aug 20 10:09:02 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 20 Aug 2004 14:09:02 GMT Subject: Decorator keyword options References: <7knVc.4599$Jn5.3074@fe1.texas.rr.com> Message-ID: <2CnVc.4606$Jn5.4384@fe1.texas.rr.com> "David Fraser" wrote in message news:cg509s$40m$1 at ctb-nnrp2.saix.net... > Good plan. If anyone likes "wrap" they could add it to the Wiki with > something akin to the description of transform > > David David - I encourage you to do this for yourself, if you have time. I think this is exactly the kind of thing Wiki was intended for - we are all empowered to include items on that list. (If you do not see the "EditPage" option at the bottom of the page, select the "Preferences" item on the left-side menu and enter your info. Once this is done, you should be able to edit pages.) -- Paul From peter at engcorp.com Fri Aug 6 09:52:20 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 06 Aug 2004 09:52:20 -0400 Subject: Unicode support In-Reply-To: References: Message-ID: Richy2004 wrote: > I've experienced problems when trying to load a text file encoded with > 2byte unicode characters. No matter what combination of the following > I try, I always get an error when > executing file.readline() > > file = open("file.txt", "r") > file = open("file.txt", "rb") > file = codecs.open("file.txt", "rb", "utf-16") > file = unicode(open("file.txt", "r"), "utf-16") > > Even more strangely it does work when used in the interactive > interpreter. > > Any ideas? Always post the actual traceback (cut and pasted from another window) when saying you are getting an error. That avoids lots of guessing on our part as to what is going on. -Peter From me at privacy.net Thu Aug 19 10:58:34 2004 From: me at privacy.net (Richard Hanson) Date: Thu, 19 Aug 2004 07:58:34 -0700 Subject: age of Python programmers References: Message-ID: <36f9i0tfu2agseuo052dfhm29lbai6lt28@4ax.com> Lucas Raab wrote: > [...] what is the average age of a Python programmer?? [...] Datapoint: 53 I'm fifty-three-years-old. Started programming in 1968 on IBM mainframes using FORTRAN IV -- and now I'm here, retired, and hanging out in this Python newsgroup... but-it-seems-like-*so*-many-more-years'ly y'rs, Richard -- R Hanson [The mangled email addie below works.] sickolefartnewsguycom From sbabbitt at commspeed.net Mon Aug 9 00:39:38 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Sun, 8 Aug 2004 21:39:38 -0700 Subject: Python source colorizer References: <18282ecb.0408081820.585a0f9c@posting.google.com> Message-ID: <1092026780.723719@news.commspeed.net> "M.E.Farmer" wrote in message news:18282ecb.0408081820.585a0f9c at posting.google.com... > Hello c.l.py!, > I have just finished this and decided to share. > PySourceColor is a module to convert Python source into colored html. > Yes it has been done before, but I like this better:) > You can easily define your own colorscheme. > example usage: > # Highlight PySourceColor.py > python PySourceColor.py > or > # Show help > python PySourceColor.py -h > > [code] Sweet, Tom From gerrit.muller at embeddedsystems.nl Fri Aug 20 04:51:00 2004 From: gerrit.muller at embeddedsystems.nl (Gerrit Muller) Date: Fri, 20 Aug 2004 10:51:00 +0200 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: I miss the option to _not_introduce decorators at all, at least at this moment. Reading the discussion and all different proposals, it is entirely clear for me that we don't know at the moment what the exact goal is that we desire. Despite the lack of goal we shoot all kinds of complicating and poorly readable options into the air. Be aware: once something is introduceed you will not be able to remove it again. Introduction is relatively easy, removal is nearly impossible. In absence of my real vote (delay, delay, do nothing), I vote: F F A1 regards, Gerrit -- Gaudi systems architecting: From apardon at forel.vub.ac.be Tue Aug 31 10:59:07 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 31 Aug 2004 14:59:07 GMT Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> <87hdqok9i6.fsf@sinken.local.csis.hku.hk> <1rfz68ely9.fsf@rovereto.ifi.uio.no> <876574k7du.fsf@sinken.local.csis.hku.hk> <1r3c28ejis.fsf@rovereto.ifi.uio.no> <1rllg0cb3m.fsf@rovereto.ifi.uio.no> <874qmovxna.fsf@sinken.local.csis.hku.hk> Message-ID: Op 2004-08-31, Sam Holden schreef : > On 31 Aug 2004 10:33:07 GMT, Antoon Pardon wrote: >> Op 2004-08-28, Isaac To schreef : >>>>>>>> "Kjetil" == Kjetil Torgrim Homme writes: >>> >>> Kjetil> after all, code in _any_ language written by a >>> Kjetil> professional will have strict indentation. so it's just >>> Kjetil> syntax. >>> >>> No. In all other languages, people deal with *two* ways to find which >>> statement is associated with an if/while/for/whatever statement and >>> which is not: by looking at the indentation, and by looking at the >>> braces. They normally look at the indentation, since it is the >>> quicker way. But when they find something wrong, they look at the >>> defining braces, sometimes deeply hidden in long expressions and >>> statements combined into one line. In Python, we have *one and only >>> one* way to find which statement is associated with an >>> if/while/for/whatever statement, and this is the quicker way that >>> people are used to. >> >> I doubt that. >> >> I used to limit myself to indentation to see which code belonged >> to which control. But then I found myself witch controls that >> were so nested it was hard to see to which if a particular >> else suite belonged and I started to use end markers in comments >> to make the structure more visible. > > Deep nesting is a bad sign in itself, Why? > regardless of how a language > specifies block structure. Making the code readable by removing > the unreadable nesting seems a far better solution than adding > end markers. The nesting reflects the structure of the algorithm. If an algorithm is best described by the nesting of a number of control structures then i don't see how you are going to remove that nesting. -- Antoon Pardon From peter at engcorp.com Tue Aug 17 08:40:30 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 17 Aug 2004 08:40:30 -0400 Subject: Python indentation deters newbies? In-Reply-To: References: <3064b51d.0408130615.3fc4a760@posting.google.com> <30260531.0408131853.18ec2446@posting.google.com> <412040f8$0$8087$a1866201@newsreader.visi.com> Message-ID: Antoon Pardon wrote: > How about: that is how my tongue and brain are wired. Sorry, such "explanations" are nothing more than restatements of the original claim in different words. They don't actually clarify the issue at all. That's why I called "I just don't" a cop-out. Anyway, this is far removed from the (to me) interesting question of why people apparently have negative reactions to Python's use of indentation. Some people have, in spite of your claims that it's not possible, managed to produce useful and interesting answers, and for that I thank them. Please carry on about how it's not possible to provide reasons for emotional reactions. The rest of the world will continue to flow on past. We now return to the regularly scheduled flame war... -Peter From jepler at unpythonic.net Fri Aug 20 08:07:12 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Fri, 20 Aug 2004 07:07:12 -0500 Subject: [Tkinter-discuss] Please help -- Tkinter Scale widget with DoubleVar is acting weird In-Reply-To: <4124C828.5080106@noaa.gov> References: <4124C828.5080106@noaa.gov> Message-ID: <20040820120712.GB24118@unpythonic.net> I do *not* see this behavior on fedora-release-2-4 (Fedora Core 2 Linux) python-2.3.3-6 tcl-8.4.5-7 tk-8.4.5-6 However, while dragging I can see a set to the same value multiple times. I suppose this happens when the mouse movement is too small to move one "resolution" unit. You could use a class which acts as a function wrapper to eliminate the redundant calls to "callback": class RedundancyEliminator: def __init__(self, var, callback): self.var = var self.callback = callback self.lastval = var.get() def __call__(self, *args): newval = var.get() if newval != self.lastval: self.lastval = newval return self.callback(*args) return None def callback(*args): print var.get() var.trace_variable("w", RedundancyEliminator(var, callback)) Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From roy at panix.com Sun Aug 22 12:10:32 2004 From: roy at panix.com (Roy Smith) Date: Sun, 22 Aug 2004 12:10:32 -0400 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> Message-ID: In article , Peter Hansen wrote: > Roy Smith wrote: > > > Speed is the primary limitation for mainstream acceptance of high level > > (aka scripting) languages in general. I can think of no reason why so > > much software is still written in languages like C++ other than > > performance (or at least, the perception of it). > > I'm glad you added that parenthetical comment, because I'm nearly > certain that it is *not* actual experience with Python, and > disappointment with its speed, that is the cause. I suspect that most decisions to use or not use any given technology are made long before any objective tests have been run. Perception is often more important than measurement. > it's quite certain > that the mainstream *has* accepted high level languages quite > fully. The last time I checked, Java and C++ (even C) were > widely considered to be high level languages. Has someone been > raising the bar while I wasn't looking? Yes, I think they have. I don't think a language that deals with memory management at the level that C and C++ do (explicit allocation and deallocation, pointers, etc) can be called high-level today. Even in the 1970's, when C first appeared, it wasn't considered particularly high level. There's a lot that I don't like about Java too, but at least it doesn't expose raw memory to the application logic, so I'll go along with Java being high level. At least for now. It's a moving target, and if you ask me again in 5 years, I'll probably give you a different answer. From robin at SPAMREMOVEjessikat.fsnet.co.uk Thu Aug 19 03:56:26 2004 From: robin at SPAMREMOVEjessikat.fsnet.co.uk (Robin Becker) Date: Thu, 19 Aug 2004 08:56:26 +0100 Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: <41245D2A.4020409@jessikat.fsnet.co.uk> Mark Jackson wrote: > Robin Becker writes: > >>Marius Bernklev wrote: > > >>>24. (anyone keeping count?) > > >>It's raining so I can't go home > > >>Martin Jackson 55 > > > Unless there's an elderly Martin out there as well, this should be > "Mark." > whoops -- Robin Becker From ivoras at __geri.cc.fer.hr Thu Aug 5 17:18:54 2004 From: ivoras at __geri.cc.fer.hr (Ivan Voras) Date: Thu, 05 Aug 2004 23:18:54 +0200 Subject: RELEASED Python 2.4, alpha 2 In-Reply-To: References: <411231C8.3020308@interlink.com.au> <2-SdnZCwNs1SwI_cRVn-uQ@powergate.ca> Message-ID: Heiko Wundram wrote: > > class someobject(object): > > @synchronized > @classmethod > def x(cls): > pass > > If I were to translate this to english, I could read it as follows (note the > order): > > Define a _class someobject_ which has a _synchronized_ _classmethod_ x. FWIW, I, for example, don't have a problem with the notion of decorators, but I think the above syntax is just plain ugly. Why not use: def @synchronized @classmethod x(self): pass ? Granted that the keywords are long-ish, but I stongly feel it's still less ugly than the topmost version. -- What part of "Ph'nglui mglw'nath Cthulhu R'lyeh wgah'nagl fhtagn" don't you understand? From exarkun at divmod.com Tue Aug 31 15:21:53 2004 From: exarkun at divmod.com (Jp Calderone) Date: Tue, 31 Aug 2004 15:21:53 -0400 Subject: Immutable sequence types lacking index() method In-Reply-To: References: Message-ID: <4134CFD1.9020904@divmod.com> Anne Wangnick wrote: > Dear all, > > I don't get why the index() method is only defined for mutable sequence > types. This is not what I expected. Shouldn't this be added in Python? Is > there such a PEP already? For all the *intended* uses of tuples, you should already know all the indexes you need to know. They are implicit in the use of a tuple as a data structure. If you do *not* know the index, you probably should be using a list instead. There have been numerous discussiong about what the *real* differences between tuples and lists are, both here and on python-dev. I recommend searching the archives if you are interested in the details. Jp From xnews2 at fredp.lautre.net Wed Aug 18 13:23:39 2004 From: xnews2 at fredp.lautre.net (Fred Pacquier) Date: 18 Aug 2004 17:23:39 GMT Subject: age of Python programmers References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: Robin Becker said : > It's raining so I can't go home One more datapoint (it's raining here too) : 44 (next week :-) -- YAFAP : http://www.multimania.com/fredp/ From peter at engcorp.com Mon Aug 9 11:41:08 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 09 Aug 2004 11:41:08 -0400 Subject: Maybe, just maybe @decorator syntax is ok after all In-Reply-To: References: <4116b725$1@nntp.zianet.com> Message-ID: Michael Ekstrand wrote: > Much of that can be accomplished stylistically in the way comments are > written (granted, that doesn't accomplish much for existing code that > doesn't follow such conventions). But, for example, in my C/C++ code, I > always have comments before my functions like so: > > /* > * FooClass::foo() > * > * Fooifies the FooClass instance > */ > int FooClass::foo(int parm1, char parm2, char *spam_name) > ... > > Much of the problem (in any language, then) goes away. You still run > into problems with existing code, though. But it brings other problems. There's a principle called DRY, for Don't Repeat Yourself, which comes from observations that *any* repetition will lead to maintenance problems and other difficulties, especially when refactoring code. And I can't count the number of times I've seen comments such as the above which were wrong, either through name changes or because of the inevitable cut-and-paste errors. At my last place of employment, we abolished all redundant comments, such as those containing the name of the function or module. The code got much shorter and cleaner. -Peter From squirrel at WPI.EDU Thu Aug 5 12:29:51 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 5 Aug 2004 12:29:51 -0400 Subject: RELEASED Python 2.4, alpha 2 In-Reply-To: References: <411231C8.3020308@interlink.com.au> Message-ID: On Fri, 6 Aug 2004, Anthony Baxter wrote: > Please feel free to actually provide reasons for not liking @decorators. or [decorators], or what have you: What does one do if a decorator raises an exception? If it's something necessary to the functioning of the code (say, classmethod or staticmethod), then all is as it should be. But what if it's not? What if you're using a run-time type checking library, or a code optimizer, that may not be installed? In that case you would most likely want to let that decoration fail silently. To get around this, you'd either have to rewrite that decorator and any above it in the chain as just normal decorations, or use some other weird hack. Decorators in general are the right solution for the wrong problem (as I detailed in another thread). They are being introduced much too prematurely, and have not been given time to be able to have been thought through well enough. The @ syntax is the result of trying to shoehorn too many solutions into one fix. They purport to solve the problems of function type declaration (class/static), function attributes, runtime type checking, and general function mangling, when each of these (save general function mangling) already have distinct solutions in nearly every other language. The first three problems are currently implemented as hacks in Python that happen to fall under the category of "general function mangling". Streamlining the hack is not the answer. From michaels at rd.bbc.co.uk Mon Aug 23 04:32:07 2004 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Mon, 23 Aug 2004 09:32:07 +0100 Subject: J2 proposal: keyword References: Message-ID: Anthony Baxter wrote: > On Mon, 23 Aug 2004 00:23:32 +0100 (BST), Michael Sparks > wrote: ... >> using: >> staticmethod synchronised memoise deprecated ... > The pie-decorator syntax was modified shortly after a2 to require > one decorator per line. I think for readability's sake, this was a > good call, and would urge you to do this in any new syntax. Fair enough, I was wondering why I hadn't seen any reference to this form, and this answers it - thanks ! Regards, Michael. -- Michael.Sparks at rd.bbc.co.uk British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From simoninusa2001 at yahoo.co.uk Tue Aug 31 12:39:13 2004 From: simoninusa2001 at yahoo.co.uk (Simon John) Date: 31 Aug 2004 09:39:13 -0700 Subject: mySQL access In-Reply-To: Message-ID: Yeah, I used the binary on Win2K Pro and it works fine connecting to a MySQL4 server running locally (with and without ADOdb). Come to think of it I also used it on XP Pro to connect to my Linux box..... From fuzzyman at gmail.com Tue Aug 24 03:19:38 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 24 Aug 2004 00:19:38 -0700 Subject: Weave - inline C Message-ID: <6f402501.0408232319.5967f0d@posting.google.com> Has anyone had success using weave with gcc for windows (standard windows distribution python)? I have my distutils setup to use gcc (via mingw32) - which it does fine. I've compiled and installed various modules with it. Weave itself installs fine, picking up the settings from distutils. However it has it's own version of distutils 'scipy_distutils' that it uses to compile the C it is given - which complains that it can't find msvcc.... The documentation included (which is actually for the 0.2 version) gives no hints and I wondered if anyone had any success in using it ? Regards, Fuzzy http://www.voidspace.org.uk/atlantibots/pythonutils.html From koko9991 at compuserve.de Sat Aug 14 05:33:51 2004 From: koko9991 at compuserve.de (Konrad Koller) Date: Sat, 14 Aug 2004 09:33:51 GMT Subject: PyQt(Qt): unexpected scrollbars in QCanvasView Message-ID: <411dcfd0.649442281@news.compuserve.de> For a card playing game I constructed a layout of 49 playing cards (size of each: x=71, y=96) which are arranged in a 7X7 matrix side by side. Accordingly the pysical size of the Canvas is x=71*7, y=96*7: in the main program: canvas=QCanvas(497,672) class Board(QCanvasView): def __init__(self,canvas,parent): QCanvasView.__init__(self,canvas,parent) but QCanvasView produces a layout with scrollbars in both directions. This is very annoying for the player because although the screen's size is more than appropriate for a total layout only some of the cards can be viewed without scrolling. The QScrollView documentation states that as default QScrollView shows a scrollbar when the content is too tall to fit and not else. What goes wrong? I am using PyQt 3.11 and Qt 3.3.1 under Linux. Thanks for any help. From peter at engcorp.com Mon Aug 16 01:18:05 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 01:18:05 -0400 Subject: Anyone use VPython? In-Reply-To: <8f17f4bc.0408141932.46b7c405@posting.google.com> References: <8f17f4bc.0408141932.46b7c405@posting.google.com> Message-ID: Ali wrote: > Anyone use VPython? Noting the question, the first two responses you got, and your subsequent question, I suggest you would benefit from reading this short essay before posting again: http://www.catb.org/~esr/faqs/smart-questions.html -Peter From tim.peters at gmail.com Sun Aug 1 20:51:15 2004 From: tim.peters at gmail.com (Tim Peters) Date: Sun, 1 Aug 2004 20:51:15 -0400 Subject: transforming a list into a string In-Reply-To: References: Message-ID: <1f7befae04080117515cbb0ca9@mail.gmail.com> [Christopher T King] > Ah, I see your point. But most functions that expect iterators use iter() > on them first (to iterize sequences), do they not? So long as iter() > supplies the necessary __getslice__ implementation, the world would be > happy. This situation would mirror the situation with list(): though a > user-defined sequence might not implement __getslice__ (and still be > usable as a list), the object returned by list() is guaranteed to. The difference is that list() creates a concrete list object from its argument, but there's no such thing as "a concrete iter object". Iteration is a protocol, not a type. iter(obj) invokes obj.__iter__(), and I don't know of any existing __iter__ implementation that returns an object that supports slicing. The only thing required of __iter__ is that it return an object that supports the iteration protocol (meaning an object that supports next() and __iter__() methods). So again, adding the ability to slice too would mean requiring more of __iter__ methods -- or changing the implementation of iter() to ignore __iter__ methods and make something up itself. It's A Visible Change no matter how you cut it. From joewong at mango.cc Tue Aug 24 01:48:49 2004 From: joewong at mango.cc (Joe Wong) Date: Tue, 24 Aug 2004 13:48:49 +0800 Subject: Is HTTPSConnection thread-safe? Message-ID: <07a401c4899e$07e54300$7f00a8c0@scl01.siliconcreation.com> No, I have HTTPSConnection object in each thread. It seems that the exception happens when all threads try to execute .request() method for the very first time at the sametime... - Joe > Hi, > I have a small program using HTTPSConnection to issue a POST on the > server. When multiple threads of the same program is running, I got > the error: > Exception in thread Thread-3: > Traceback (most recent call last): > File "C:\PYTHON23\lib\threading.py", line 436, in __bootstrap > self.run() > File "C:\PYTHON23\lib\threading.py", line 416, in run > self.__target(*self.__args, **self.__kwargs) > File "mcstest.py", line 27, in thread_func > conn.request("POST", CGI_PATH, params, headers) > File "c:\python23\lib\httplib.py", line 718, in request > self._send_request(method, url, body, headers) > File "c:\python23\lib\httplib.py", line 739, in _send_request > self.endheaders() > File "c:\python23\lib\httplib.py", line 712, in endheaders > self._send_output() > File "c:\python23\lib\httplib.py", line 597, in _send_output > self.send(msg) > File "c:\python23\lib\httplib.py", line 564, in send > self.connect() > File "c:\python23\lib\httplib.py", line 985, in connect > ssl = socket.ssl(sock, self.key_file, self.cert_file) > File "C:\Python23\lib\socket.py", line 73, in ssl > return _realssl(sock, keyfile, certfile) > sslerror: SSL_CTX_new error > in random order. Is there any fix / patches for this? > Regards, > - Joe Are you passing the same HTTPSConnection object to a bunch of threads? With just a cursory glance at the httplib module, it doesn't look like it is thread safe (meaning I saw no thread imports, no references to locks, etc.). If, for some reason, you feel it necessary to pass the same HTTPSConnection object to multiple threads, you will probably want to write a thread-safe wrapper for HTTPSConnection. I can't think why you would want to pass the same conn object to multiple threads rather than creating a new one per thread - unless you want to have one and only one persistent connection among all threads (using keepalives, I guess). -------------- next part -------------- An HTML attachment was scrubbed... URL: From sbabbitt at commspeed.net Fri Aug 27 01:10:58 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Thu, 26 Aug 2004 22:10:58 -0700 Subject: i can't run wxPython References: <88c4d3f.0408261841.297be57d@posting.google.com> Message-ID: <1093583969.343830@news.commspeed.net> I would try downloading a new copy of wx.Python there seems to be a glitch in your install. Tom From agriff at tin.it Mon Aug 16 03:10:03 2004 From: agriff at tin.it (Andrea Griffini) Date: Mon, 16 Aug 2004 07:10:03 GMT Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> <30260531.0408131853.18ec2446@posting.google.com> <412040f8$0$8087$a1866201@newsreader.visi.com> Message-ID: On Mon, 16 Aug 2004 01:41:52 -0400, Peter Hansen wrote: >For example, if 90% of people who have the "indentation rash" >had previous encounters with FORTRAN IV, then it ought to >be possible to make it obvious in the early documentation >(tutorial, intro page, etc) that Python is not FORTRAN and >doesn't suffer from the same limitations with respect to >indentation/whitespace significance as FORTRAN does. > >(Not that I think we'll really find this particular one >to be the biggie. But that roughly describes my purpose...) Not sure if this would help. I have to admit that at first the idea of whitespaces instead of braces generated a general repulsion. This probably due to FORTRAN or COBOL memories (note that I never did any real work with those languages... just high-school code snippets)... but the point is that this was just BEFORE reading any documentation on python. Before installing it and giving it a try the only source of knowledge was an earsay that whitespaces was important in python... and even if my memories of high-school are mostly really nices this triggered an immediate "oh-no!". There is no need to tell that now I'm just more than happy to use indentation... it really works beautifully and takes probably 5 minutes to forget braces for structure and see how they are indeed noise and not information. The only truly annoying thing is the hideous tab problem... I've personally banned tabs since when they become unreliable (i.e. when they lost their comfortable 8-spaces size: seems that someone didn't understand that making a tab meaning anything was indeed making tab mean nothing), but I'm still fighting with collegues that on VC++ insist on doing stupid things with tabs (like changing their size every couple of months and keeping the "use tabs" checkbox in the preferences dialog ... IMO basically because they can't see the logical distinction between tab size and indent size). Andrea From dyoo at hkn.eecs.berkeley.edu Sun Aug 29 02:09:50 2004 From: dyoo at hkn.eecs.berkeley.edu (Daniel Yoo) Date: Sun, 29 Aug 2004 06:09:50 +0000 (UTC) Subject: Python / scheme implement References: <8kcUc.216223$pC2.10693727@phobos.telenet-ops.be> <87brhagmm7.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Message-ID: 510046470588-0001 at t-online.de wrote: : Daniel Yoo writes: :> It's not perfect (and frankly, is a little outdated!), but it's a :> proof-of-concept that one language can model the other. : how does python model call-with-current-continuation? Hi Klaus, I'm not sure if you meant that question to be a challenge, but I'll take it up! *grin* The question is slightly off: there's nothing about Python in particular that prevents us from implementing call/cc. It does, however, take a bit of work: implementing call/cc involves a rewrite of the interpreter into a CPS form. It's actually not too bad, and I have now done this. As a nice side effect, we also get proper tail recursion! Hurrah! You can take a look at the updated code here: http://hkn.eecs.berkeley.edu/~dyoo/python/pyscheme/pyscheme-1.5pre.tar.gz For example: ;;;;;; volado:~/Documents/work/pyscheme/trunk/src dyoo$ python scheme.py Welcome to PyScheme! Type: (QUIT) to quit. [PyScheme] >>> (+ 1 (call/cc (lambda (k) (+ 2 (k 3))))) 4 ;;;;;; The improvements are due to ideas I stole from Shriram Krishnamurthi's "Programming Languages: Application and Interpretation": http://www.cs.brown.edu/~sk/Publications/Books/ProgLangs/ and Friedman, Wand, and Haynes "Essentials of Programming Languages": http://www.cs.indiana.edu/eip/eopl.html I'm psyched now: I think I finally understand continuations! *grin* I do have to fix a major bug with pair representation in pyscheme. But as soon as I get that outstanding fixed, I'll send a more formal announcement. Hope this helps! From james at logicalprogression.net Tue Aug 17 20:56:40 2004 From: james at logicalprogression.net (James Henderson) Date: Wed, 18 Aug 2004 01:56:40 +0100 Subject: strange problem with def in class In-Reply-To: <1092788477.995526@seven.kulnet.kuleuven.ac.be> References: <1092788477.995526@seven.kulnet.kuleuven.ac.be> Message-ID: <4122A948.3010805@logicalprogression.net> Johan wrote: > I don't get it: > I'm trying to write a "readfile" function which would replace some code from > a __init__ function: > > 1 import string > 2 class landdict: > 3 def __init__(self, file): > 4 # Laadt de dictionnary van landen. > 5 # Kijk in de actiefspel-file voor de file van waaruit je > moet laden. > 6 self.ld = {} > 7 f = open(file, "r") > 8 line = f.readline() > 9 if line[0] == "#": > 10 line = f.readline() > 11 while line != "": > 12 key = line[0:3] > 13 self.ld[key] = string.split(line[4:], ':') > 14 line = f.readline() > 15 print self.ld > > So I would like to replace the code from line 7 to line 14 with > > readfile(filename) > > while > > def readfile(filename) is another function in the class > > but I can't define this function.... when I call the function the > interpreter throws an exception of unknown function > what am I doing wrong? Hi Johan Other variables defined in a class are in a scope that cannot be accessed directly from within a method (Python newish nested scoping only works for functions inside functions). Personally I would move your readline() function outside the class to the module level. If you want to keep it in the class then either give it a self parameter or add "readline = staticmethod(readline)" after the definition of readline(). Then you can call it from within __init__() as self.readline(filename). HTH, James From deetsNOSPAM at web.de Tue Aug 3 11:46:51 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Tue, 03 Aug 2004 17:46:51 +0200 Subject: PyQT tutorial References: <410f8d35$0$31408$636a15ce@news.free.fr> Message-ID: <2n9qbdFug619U1@uni-berlin.de> Olivier Thiery wrote: > Do you know any good and fairly complete tutorial about PyQT, Eric and > QtDesigner ? The qt documentation itself. qt examples can usually translated more or less directly to pyqt. -- Regards, Diez B. Roggisch From steven.bethard at gmail.com Wed Aug 25 12:13:25 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Wed, 25 Aug 2004 16:13:25 +0000 (UTC) Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> Message-ID: Paul Morrow yahoo.com> writes: > Steven Bethard wrote: > > Are you trying to say that "metadata" is the same thing as "operator shortcut"? > > Not exactly, but it would include defining those. Ahh. Well I at least sort of see where you're going with this now, thanks. It's probably notable that I could write my example in two ways: class Identity: def get(self, x): return x __getitem__ = get class Identity: def __getitem__(self, x): return x get = __getitem__ I think I could agree that the use of things like __getitem__ can indicate some metadata about the class, but I'd note that that is not all they do. In the example here, __getitem__ defines a function that can be used like any other function. At the same time, because it's *named* __getitem__, we get some metadata about the function. Using the same logic, I should expect that in something like: def baz(): __foo__ = "bar" # body of baz __foo__ would be a string, and could be used like any other string. At the same time, because it was *named* __foo__, we would get some metadata about the string. So I guess my point is that, while the *name* might give us some metadata, I'm not convinced that the *use* is in any sense metadata. STeve From p_s_oberoi at hotmail.com Mon Aug 16 14:31:03 2004 From: p_s_oberoi at hotmail.com (Paramjit Oberoi) Date: Mon, 16 Aug 2004 13:31:03 -0500 Subject: ConfigParser options spanning more than one line References: Message-ID: > I'm using ConfigParser and I can't seem to get a config option to span > more than one line. >>> from ConfigParser import ConfigParser >>> from StringIO import StringIO >>> s = StringIO("[a]\n" ... "b = 123\n" ... " 456") >>> c=ConfigParser() >>> c.readfp(s) >>> c.get('a','b') '123\n456' In other words, any line with a leading whitespace is considered a continuation line, and the leading whitespace is stripped from the value (but the carriage return is left in). HTH, -param From aleaxit at yahoo.com Thu Aug 26 16:18:00 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 22:18:00 +0200 Subject: Inline Conditionals? References: <1gj4rpq.1oyt89b14xvbdqN%aleaxit@yahoo.com> Message-ID: <1gj5bit.rt2tmzcznspxN%aleaxit@yahoo.com> Antoon Pardon wrote: ... > When using list comprehension not having a ternary operator can be > a PITA. It is of course possible I miss something but how am I > supposed to do the following: > > [ x.property ? foo(x) : bar(x) for x in Somelist ] If you HAVE to use an LC by doctor's order, the above effect might be obtained by coding something like: [ (bar,foo)[bool(x.property)](x) for x in Somelist ] If your physician should relent and let you code normal Python, though, aux = [] for x in Somelist: if x.property: aux.append(foo(x)) else aux.append(foo(x)) would be vastly more readable; "sparse is better than dense" and any LC is far too dense to be Pythonic here. Alex From zathras at thwackety.com Fri Aug 20 16:16:59 2004 From: zathras at thwackety.com (Michael Sparks) Date: Fri, 20 Aug 2004 21:16:59 +0100 (BST) Subject: Decorator keyword options - brainstorming In-Reply-To: <2omsj9Fcej95U1@uni-berlin.de> Message-ID: On Fri, 20 Aug 2004, Reinhold Birkenfeld wrote: > David Vaughan wrote: > > Paul McGuire wrote: > > I don't know - it sounds fun. I vote: > > > > SpanishInquisition: > > staticmethod > > def foo(): > > pass > > But seriously, there must be something literally pythonic we could > > propose. > How about > pythonic: > staticmethod > def foo(): > pass > That's never work - for IronPython you'd have to change it: ironic: staticmethod def foo(): pass ;-) Michael. From bingham at cenix-bioscience.com Wed Aug 4 07:37:37 2004 From: bingham at cenix-bioscience.com (Aaron Bingham) Date: Wed, 04 Aug 2004 13:37:37 +0200 Subject: Barcode Layout Message-ID: <4110CA81.6060706@cenix-bioscience.com> Hello, We are dealing with barcodes a lot and we want to be able specify the layout of a barcode label in a device-independant way and then output to, e.g., a wxWindow, a PostScript file or a special-purpose barcode printer. We want to specify higher-level entities (e.g. barcode) in the layout directly. Backends will either output corresponding high-level printer commands (barcode printer) or construct the entities from lower-level primitives (wxWindows, PostScript). I've been looking at Piddle (http://piddle.sourceforge.net/) and it appears we could write a backend to support our barcode printer with extra methods for higher-level entities, but I'm reluctant committing to apparent abandonware. Does anyone have experience doing similar things with Piddle? Are there any plans to maintain/enhance/replace Piddle? Are there other packages I should look at? Thanks, -- -------------------------------------------------------------------- Aaron Bingham Application Developer Cenix BioScience GmbH -------------------------------------------------------------------- From CarolCarrot at sofsof.net Mon Aug 16 22:52:22 2004 From: CarolCarrot at sofsof.net (Carol Carrot) Date: Mon, 16 Aug 2004 20:52:22 -0600 Subject: http://www.freecrm.com Message-ID: In what ways would I get dorked if I use this website? From jumpthewall at gmail.com Wed Aug 11 19:36:08 2004 From: jumpthewall at gmail.com (Chris Patton) Date: 11 Aug 2004 16:36:08 -0700 Subject: PyJack Message-ID: <6fd8df7e.0408111536.79369258@posting.google.com> I just finished my first program (PyJack)! If you'll noticed, there are many ways inwich I can shorten the program (I really don't know all the python syntax.) Please post suggestions. code: # PYJACKv1 # This is a 'blackjack' program written in python. There are two os calls, that makes this program disqualified for 'operating system independency', but oh well. These calls only screen. Change accordingly import whrandom, os def scorer(score,playerdeck): b = 0 while b == 0: try: d = 0 while d < len(playerdeck): if score > 10 and 'A' in playerdeck: typevalues['A'] = 1 elif score <= 10 and 'A' in playerdeck: typevalues['A'] = 11 score += typevalues[playerdeck[d]] d = d + 1 b = 1 except KeyError: b = 0 return score a = 'y' b = 0 while a == 'y': # shuffle deck print "loading..." types = ['A','2','3','4','5','6','7','8','9','10','J','Q','K'] typevalues = {'A':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7 , '8':8,'9':9, '10':10, 'J':10, 'Q':10, 'K':10} left = [4,4,4,4,4,4,4,4,4,4,4,4,4] deck = [] decksize = 0 while decksize < 52: a = whrandom.randint(0,12) if left[a] > 0: left[a] = left[a] - 1 deck.append(types[a]) decksize = decksize + 1 elif left[a] == 0: pass os.system('cls') print # play? print "---*Black Jack*---" if b == 0: a = raw_input('\nWould you like to play? [y,n]') elif b > 0: a = raw_input('\nPlay again? [y,n]') while a not in ['y','n']: if b == 0: a = raw_input('\nWould you like to play? [y,n]') elif b > 0: a = raw_input('\nPlay again? [y,n]') if a == 'y': pass elif a == 'n': break # deal c = 0 humandeck = [] while c <= 1: humandeck.append(deck[0]) del deck[0] c = c + 1 compdeck = [] c = 0 while c <= 1: compdeck.append(deck[0]) del deck[0] c = c + 1 score = 0 compscore = 0 stay = 0 over = 0 compstay = 0 compover = 0 # playing the game score += scorer(score,humandeck) while over == 0 and stay == 0: move = 0 a = 0 printdeck = '' epd = compdeck[0]+' |?|' while a < len(humandeck): printdeck += humandeck[a]+' ' a += 1 os.system('clear') print '\n---*Black Jack*---' print '\n\n Dealer: '+epd print '\n Player: '+printdeck+'\n score='+str(score) # your turn if stay == 0 and over == 0: move = raw_input('\n hit stay \n\n <$>') while move not in ['a','b','hit','stay']: move = raw_input('\n ') elif stay > 0: pass if move in ['a','hit']: humandeck.append(deck[0]) del deck[0] elif move in ['b','stay']: stay = stay + 1 score = 0 score += scorer(score,humandeck) if score > 21: over = over + 1 printdeck = ' **OVER**' # Dealer's turn while 1: f = 0 f = scorer(compscore,compdeck) if f > 21: compover = 1 break if f > 15: break if f <= 15: try: compdeck += deck[0] del deck[0] except IndexError: pass epd = '' c = 0 while c < len(compdeck): epd += compdeck[c]+' ' c = c + 1 compscore = scorer(compscore,compdeck) # Winner? os.system('clear') print '\n---*Black Jack*---' print '\n\n Dealer: '+epd+'\n score='+str(compscore) print ' Player: '+printdeck+'\n score='+str(score) e = 0 if score > compscore and over == 0 and compover == 0: winner = 'Player' elif score == compscore and len(humandeck) < len(compdeck): winner = 'Player' elif compover > over: winner = 'Player' elif score < compscore and compover == 0 and over == 0: winner = 'Dealer' elif score == compscore and len(humandeck) > len(compdeck): winner = 'Dealer' elif compover < over: winner = 'Dealer' elif compover == over and score == compscore: print '\n\n TIE' e = 1 else: if over < compover: winner = 'Player' elif over > compover: winner = 'Dealer' else: winner = 'Dealer' if e == 0: print '\n\n The '+winner+' wins this round.' raw_input() a = 'y' b = 1 print '\nGood day.' From bh at intevation.de Fri Aug 20 12:58:29 2004 From: bh at intevation.de (Bernhard Herzog) Date: Fri, 20 Aug 2004 18:58:29 +0200 Subject: Alternative decorator syntax decision References: <3A81C87DC164034AA4E2DDFE11D258E3022E14@exchange.hqamor.amorhq.net> Message-ID: Steven Bethard writes: > It does look > like J2 is generally the preferred syntax so far At least of those who don't like the pie syntax at all. > I know that J2 is not everyone's favorite, but I'm hoping that we can > agree that, even if it's not our favorite, is a clear improvement over > @pie syntax. I don't know. If J2 gets the majority of the votes for an alternative, it might be a good idea to have a second vote just between the pie syntax and J2. I'd vote for pies. Bernhard -- Intevation GmbH http://intevation.de/ Skencil http://sketch.sourceforge.net/ Thuban http://thuban.intevation.org/ From dd55 at cornell.edu Tue Aug 3 17:06:24 2004 From: dd55 at cornell.edu (Darren Dale) Date: Tue, 03 Aug 2004 17:06:24 -0400 Subject: executing python programs as if they were on OS path (noob) In-Reply-To: References: Message-ID: Peter Hansen wrote: > Darren Dale wrote: > >>> At least two options (assuming you're on Linux... you >>> didn't specify your OS unfortunately): >>> >> >> I am currently on windows. I didnt think it would matter, sorry I left >> that out. > > > Ah, you tricked us by using forward slashes in the sample > path. :-) > I just wanted to pretend I was already a linux user... > On Windows, the best answer depends on *which* Windows you > are on... 98? XP? Other? > I'm on XP. From anthonybaxter at gmail.com Wed Aug 25 13:54:53 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Thu, 26 Aug 2004 03:54:53 +1000 Subject: python-dev Summary for 2004-08-01 through 2004-08-15 In-Reply-To: <3l3pi0pgmgu0uir1ucnj0rlfo355c6i5cp@4ax.com> References: <3l3pi0pgmgu0uir1ucnj0rlfo355c6i5cp@4ax.com> Message-ID: On Wed, 25 Aug 2004 13:22:33 GMT, Arthur wrote: > Perhaps you could clarify your position a bit. I think the > "community" understands some fundamental difference between posting to > python-dev and to python-list. If not Aahz is normally there to > remind them. > > Guido's "genius" extends to marketing, IMO. > > Having some sense of participation in the fate of Python, even if bit > hullicinatory, is fundamental to the development of its following. A > clasic form of guerilla marketing. Considering that the Python > markteing budget in $ is 0, I think it would be a mistake to have the > community believe that their only role is to read the release notes. I think Brett might have overstated his case a little - I can understand his frustration, though. The _overwhelming_ number of posts on the subject of decorators have evidently not bothered to make the slightest effort to read the past postings on the subject. Yes, part of this is that the PEP wasn't up to date before a2. But I see many of the same points being raised, again and again, without the poster having bothered to read the previous posts and the replies to them, often _in_ _the_ _same_ _thread_. Instead, there was a mass pile-on of folks jumping up and down and screaming[1] [1] I'm obviously not including everyone here. There's also been a large number of insightful and carefully thought out posts. _No-one_ is saying "we don't need to include the community". FFS, I'd point to the something around 120 posts I've made to c.l.py/python-list since a2 came out. However (and this is what I think Brett was trying to get at) at a certain point in any syntax discussion, it comes down to aesthetics, and a judgement call. And the person who _I_ trust to make the best judgement call on the subject of Python's aesthetics is Guido. He's got an exceptionally good track record here. (I discount print >>, which I still regard as horrible). Go back and read some of the earlier posts after a2 came out. In many, many cases they were full-on rants and raves, "how could Guido do this?" and the like. I'm _quite_ confident that in many/most cases, the people doing the ranting and raving had *not* bothered to download the alpha and actually *try* *the* *syntax* *out*. Instead, we got "ew! the @ symbol! That's perl!" or "decorators are stupid! No-one needs them!" Certainly, part of the reason many of my responses were strongly worded in the days after the a2 release was that it was obvious the posters were posting their immediate thoughts, as I said, without bothering to stop and try the syntax out, or think about the issues a little. I'm all for community involvement. I recognise that we could have done better in the days around the second alpha, and I've been trying *damn* hard to make that better. But I don't see much point getting community feedback if the feedback is unthinking abuse and uninformed ranting. It's a two way street. From reply2group at ndbbm.net Tue Aug 31 10:01:15 2004 From: reply2group at ndbbm.net (Active8) Date: Tue, 31 Aug 2004 10:01:15 -0400 Subject: Need help importing/installing reportlab module References: <1ezngypknj8ju.dlg@news.individual.net> <4133EF58.4050709@holdenweb.com> <1556ldg3h91o2.dlg@news.individual.net> <41346680.9070900@holdenweb.com> Message-ID: <1mu4yaug6x6al$.dlg@news.individual.net> On Tue, 31 Aug 2004 07:52:32 -0400, Steve Holden wrote: >> when I unzip, I get >> >> ..\ReportLab_1_19\reportlab-1_19 >> > Right, but this is because you chose to unzip INTO a directory you had > created called ReportLab_1_19. Actually, that's one of the context menu options winrar suggests - the name of the zip file. > If you look at the archive with WinZip or > similar, you'll see that it essentially bundles everything into a > reportlab-1_19 directory. That directory contains only two things: you > identify them in your next bit. Not sure what the "..\" is doing in your > path up there ... Sorry, should have been "." IOW I unzipped it into the dir it was saved in and let winrar create a dir named after the zip archive. > >> > Right. You are complicating things WAY beyond what they need to. > Something I am prone to do myself, so I feel a certain sympathy. As it says at your site, Python folks are nice - liked the success matrix bit, too :) i.e., the "...two ways into..." article linked from the home page. > > Delete everything you've done so far and unpack the archive into the > root directory on your D: drive. (or move what you have already, if you > feel confident doing that and you haven't messed about with the contents > of the package). This will create > > D:\reportlab-1_19\MANIFEST.txt > D:\reportlab-1_19\reportlab\__init__.py Done > > and a whole bunch of other stuff. What you are supposed to import is the > D:\reportlab-1_19\reportlab DIRECTORY: it's a package, as indicated by > the presence of the __init__.py file. > > So, having got this far, you now need to create a .pth file that Python > will find (the easiest way to ensure that is to create it in the same > directory as your python.exe interpreter binary). It doesn't matter what > it's called, as long as its name ends in ".pth". It needs to contain > just one line, which reads > > D:\reportlab-1_19 Done. Even tried D:\reportlab-1_19\reportlab after the above line failed - just in case. Erm... I just shut down and started python again and it reread the path file and works. Screw myself :( Recall I mentioned shutting it down once before? Maybe I didn't do that often enough. Wish I knew, cause this has been what I'd call a PITA compared to the last time I installed this package. > > This will indicate to the interpreter that it can look in that directory > for the reportlab package, and bingo, you are done. Mekes sense. Python finds what is now paths.pth in the same dir as its executable, etc. > > Note that if you install multiple packages you can add a line to the > same .pth file for each of the packages you want Python to find, but > that needn't concern you just now. Maybe not, but it'll save a post later. > [...] and I would encourage you to read the > description in the tutorial [Section 6.4 in my 2.3 documentation]. It > also doesn't really help that type(reportlab) is reported as 'module'>, adding to the potential for confusion, but once you have used > packages for a while it seems like a very natural way to bundle related > pieces of functionality. Agreed and duly noted. How can I forget after this? ;) But the userguide.pdf has bullets and paragraphs in that section and I'm sure you're not talking about graphics_reference.pdf. THe report lab site I downloaded from... sparse. I didn't see add'l docs there. >From 00readme.txt " If you don't see the pdf manual you expected or you wich to ensure an up to date copy run the script tools/genAll.py! " genALL.py is not in tools\, it's in docs\ - where the readme resides :) heh, heh... documentation's a bitch. test_pdfgen_general.py seems to work nicely. runAll.py throws no errors and compiles __init__.py, unittest.py, and utils.py. genAll.py threw a flurry of messages some WARNs some Errors. I tried to redirect win console errors to a file, but all those python errors don't make it there. The first wrning was that the Imaging Library was not available. Unable to import bitmaps. Maybe that means PIL? I dunno. I got graphics_reference.pdf out of the deal. Not sure if there should be more, but the 00readme says " Thid directory holds documentation. For end users, it should contain a number of PDF manuals. For people working with the source, this directory will be the destination for any manuals built. " > > Get back to the group again if you still can't import reportlab - it's > really worth the effort, honest! I use the o-s toolkit to do all my > invoicing. Is that part of reportlab or what? FYI, reportlab is used by a program called gerber2pdf by Joseph C Chavez. It converts the industry standard Gerber files from an electronic circuitboard layout package to pdfs. Kinda handy when you don't have a high $ photoplotter. -- Best Regards, Mike From dave at pythonapocrypha.com Fri Aug 13 17:47:19 2004 From: dave at pythonapocrypha.com (Dave Brueck) Date: Fri, 13 Aug 2004 15:47:19 -0600 Subject: Why I love python. In-Reply-To: References: Message-ID: <411D36E7.6030408@pythonapocrypha.com> Nick Patavalis wrote: > On 2004-08-13, Dave Brueck wrote: > >>Nick Patavalis wrote: >> >>>I also mentioned web-browsers, ray-tracers, circuit-simulators. I >>>could add word-processor, spreadsheets, video editing programs, and >>>GUI toolkits to the list. Are they still too exotic? >> >>No - but I still don't think they reflect anywhere near a majority of >>the development that goes on. > > > Yes, the majority of development goes on little *glue programs* that > take data from a database, and format is as XML/HTML, or aggregate and > analyze data stored in a database, and stuff like that. But for all > these to be possible a massive amount of *infrastructure* is > required. And this infrastructure cannot be created in Python. So you > don't say that Python isn't a glue language, but that the greatest > percentage of development that currently goes-on *is* glue-stuff > development Well, at my current company we've implemented web and file servers, cache log parsers, web applications, Windows desktop applications, Windows COM objects including web browser plugins, video splicers, and a host of tools, all in Python. These aren't "little glue programs" - they are just programs; normal programs we'd have to write in _some_ language and Python turned out to be the best fit. What's more, a whole heck of a lot of the functionality implemented in Python would most definitely fall under the category of infrastructure, not glue. > Put yourself in this position: Its a few years ago (say 1998 or 1999), > and no graphical web-browser exists for Linux. You are planning to > develop the "iso-standard" web-browser for this operating > system. Would you do it in Python? Remember that no HTML parsers > exist, no decent HTML renderers, the GUI toolkit is more or less > primitive, and the low-end desktops runs at about 200-something > MHz. You might argue "this is not the case today", but how can you > preclude that *similar* challenges do not occur today, or will not > occur in the future? This is so far removed from what I'm trying to say that I don't even know how to respond. I'm not arguing that at all. > 2004 again, and you decide to scrap and replace the age-old X11 window > system; do away with it and start from scratch. Build a moder > windowing system; 3D all over, fully network transparent, with widget > support on the server-side, fully object oriented interface, and so > on. How much of it would you be able to code in Python? Python is not the right tool for every job. There do exist cases where more performance is required than can be delivered. Having said that, the cases where it is too slow make up a small (and shrinking) portion of the total amount of development going on. As such, better performance is always welcome, but it won't benefit as many people and as much as other things can. IOW, anytime you say, "wouldn't it be great if Python were faster?" you can easily get everybody to respond, "sure!" - everybody's on board with you there. It's when you try to fit it into the list of priorities that you'll find that there are other things higher on the list. Higher because they provide more benefit overall and/or to the people who are interesting in helping out. To your specific question, I actually _would_ use Python for most of an X11 replacement system. Obviously low-level stuff would be handled by one of the existing 3D libraries out there (no need to reinvent the wheel there - the goal is to build a better window system, and we'd want a good hardware abstraction lay). I've seen a few proof-of-concepts with Pygame that lead me to believe that it's doable - their performance is already better than X11's performance for the first decade or so of its existence. > How much *more* would you rather be able to code in Python? You can't consider the benefit in isolation. You have to take into account the costs involved. -Dave From davebrok at soda.csua.berkeley.edu Tue Aug 24 15:03:45 2004 From: davebrok at soda.csua.berkeley.edu (David Pokorny) Date: Tue, 24 Aug 2004 12:03:45 -0700 Subject: J2 paper 0.2.1 References: Message-ID: Robert, I think the proposal is fantastic. Very thorough and positive. Choice of Keyword: +1 for 'using' Grammar: In another thread (J2 proposal: keyword), we came to some synthesis on allowing semicolons to separate decorators: "Nicolas Fleury" wrote in message news:KqlWc.54712$F85.1167861 at wagner.videotron.net... > Roman Suzi wrote: > > This surprises me. And this doen't surprise: > > > > using: > > staticmethod; synchronized; memoize > > def bar(foo): > > "To colon or not to colon? Def is the question." > > pass > > +1 > Nicolas This is a much better idea than what I had originally suggested, and there is some precedent, namely the simple_stmt form (from Grammar/Grammar). > simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE An argument against allowing this: it can lead to some mild abuse, namely > > using: > > staticmethod; synchronized; memoize; accepts(int,int); returns(int) > > def bar(foo,foo2): > > "To colon or not to colon? Def is the question." > > pass >From what I can tell, this is about as bad as it gets as for readability. I see two rebuttals to this example: A) accepts(...) and returns(...) are just stopgap measures for what may be the "optimal function prototype syntax" (I can hear the groans already). B) As a matter of philosophy, Python both creates the infrastructure to make readable programs and encourages good coding style that leads to readable programs but does not actually force you to write readable programs. I think disallowing the following > > using: > > staticmethod; synchronized; memoize > > returns(int); accepts(int,int) > > def bar(foo,foo2): > > "To colon or not to colon? Def is the question." > > pass would be an unjust fate for a decent compromise between readability and economy. --------------------------------------------------- One possible syntax, which mimics Grammar/Grammar: small_decorator: dotted_name [ '(' [arglist] ')' ] simple_decorator: small_decorator (';' small_decorator)* [';'] NEWLINE suite_of_decorators: simple_decorator | NEWLINE INDENT simple_decorator+ DEDENT funcdef: ['SpanishInquisition' ':' suite_of_decorators] 'def' NAME parameters ':'suite David From squirrel at WPI.EDU Thu Aug 12 14:40:30 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 12 Aug 2004 14:40:30 -0400 Subject: NumArray array-indexing In-Reply-To: References: Message-ID: On 12 Aug 2004, Michael Drumheller wrote: > I am new to NumArray and I wonder if someone can help me with > array-indexing. Here's the basic situation: Given a rank-2 array > (i.e., a matrix) it seems to be trivial, with array indexing, > to extract a subset of its *columns*. But it does not seem > to be trivial to extract a subset of its *rows*. You can do this using slices, like so: >>> from numarray import * >>> a = array([[1, 2], [3, 4]]) >>> a[:,1] array([2, 4]) ':' means 'take all values along this axis', just like how with standard Python lists it means 'take all values in the list'. > Basically, it seems to me that NumArray simply does not support > the distinction between a column vector and a row vector. That > is, if you have x=[1,2,3], then transpose(x) is a no-op. True? False. You have to supply numarray with a two-dimensional array in order to perform a two-dimensional transpose: >>> transpose([[1, 2, 3]]) array([[1], [2], [3]]) From justin__devine at hotmail.com Mon Aug 30 17:15:41 2004 From: justin__devine at hotmail.com (Justin) Date: 30 Aug 2004 14:15:41 -0700 Subject: "Content-Length" header In-Reply-To: Message-ID: URL open appears to not want to work unless its paramater is an actual string spelled out in quotes. Check out the output to this code. When I give urlopen objects instead of pre strings it doens't work correctly. print linklisttype for y in linklisttype: temp = urlopen(y) print temp temp2 = temp.info() print temp2 temp3 = temp2.getheader("Content-Length") print temp3 file_sizes.append(temp3) print file_sizes #This is the tuple with three urls in it, they all look correct to me ['http://www.ecs.soton.ac.uk/~harnad/temp/ariadne-rae.doc', 'http://www.ecs.soto n.ac.uk/~harnad/temp/ukparl.doc', 'http://www-admn.csun.edu/systech/techsupport/ procedures/2kcleanup.doc'] #here are the return values for y =0, didn't work > Date: Mon, 30 Aug 2004 21:10:50 GMT Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12 OpenSSL/0.9.6b DAV/ 1.0.3 PHP/4.3.2 mod_perl/1.26 Connection: close Content-Type: text/html; charset=iso-8859-1 None #same here > Date: Mon, 30 Aug 2004 21:10:53 GMT Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12 OpenSSL/0.9.6b DAV/ 1.0.3 PHP/4.3.2 mod_perl/1.26 Connection: close Content-Type: text/html; charset=iso-8859-1 None #this one worked though i don't know why. If I paste the URLs they all work > Server: NetWare-Enterprise-Web-Server/5.1 Date: Mon, 30 Aug 2004 21:10:53 GMT Content-type: application/msword Last-modified: Tue, 30 Apr 2002 22:50:08 GMT Content-length: 297984 Accept-ranges: bytes Connection: close 297984 [None, None, '297984'] From luismg at gmx.net Mon Aug 23 21:33:29 2004 From: luismg at gmx.net (Neuruss) Date: 23 Aug 2004 18:33:29 -0700 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> <278de0e.0408220636.3ee25f9d@posting.google.com> <278de0e.0408221450.324e8178@posting.google.com> Message-ID: <278de0e.0408231733.700685e7@posting.google.com> > >I love Python. It's an excellent, fun, clear, well designed language > >and it is fast enough for 90% of the cases. But you can't deny that > >for some problem domains, it is slow. Very slow. > > That's true. If that's what you'd said in the first place, nobody would > have argued with you... I already replied a similar comment in my previous post. > If you're going to make a claim that speed is Python's main limitation, > you'll need to provide evidence to support your assertion. Same as above. > >I didn't want to start a silly thread to discuss wether python is slow > >or not. It is. Period. > > Nope. Speed is relative. Is a car slow? Depends whether you're trying > to go five feet, five miles, fifty miles, five hundred miles, or five > thousand miles -- and it also depends on the alternatives available for > traversing that distance. Repeatedly claiming that Python is slow as an > absolute statement only shows your ignorance and unwillingness to listen > to other people. I got your point and I used those lines myself many times. I'm not making an absolute statement as though I'm a fundamentalist fanatic of speed. What I mean, is that it is widely known that scripting languages have a considerably lack of speed compared with static typed languages (I didn't discover anything new, and this is what I mean when I repeated the statement that python is not fast). Again, as I already explained, I'm not saying that other people's oppinion are wrong, when I used the word "nonsense" I wanted to say that the whole discussion is in which we were all involved is nonsense, because there's no use in discussing whether python is slow or not. This is a proven fact. Your arguments regarding the relativity of speed are correct and nobody is denying it. But I am talking about this little percentage of applications, that use to be the most relevant (usually) in enterprise environments or in commercial applications where high volumes of data are processed, as well as 3d programs, games, etc..). My point is: It is my humble oppinion (and I already acknowledged that I SHOULD HAVE USED THIS TERMS BEFORE), that this is the main reason that explains the little acceptance of Python in certain professional circles. Now, you can agree with me or not. In that case, your oppinion is welcome, but I don't need a moral lesson as to how I should address these topics. I guess I already said what I have to say about my oppinions. If I hurted someone I'm sorry! I hope that we can move on with this topic and you can stop dissecting my phrases looking for something new to disavow... > >All the other comments on this thread, regarding the main limitation > >for python's acceptance are true, but speed is critical, and this is > >were all efforts should be concentrated. > > That's nice. If that's your belief, what are you doing to work on this? Again, I already replied this. > >So my intention when I started this thread, was to learn more about > >these projects, read other oppinions, get some news, etc... I didn't > >mean to start a a nonsense discussion! > > Believe me, I'm sympathetic to the fact that English is not a comfortable > language for you. However, at this point, the problem appears to be a > thinking problem, not a language problem. You simply hold an opinion at > odds with the experience of many expert Python programmers, and it's one > that is almost guaranteed to start an argument. I don't know how to comment on this without being recursive. From graham__fawcett at hotmail.com Tue Aug 17 12:34:51 2004 From: graham__fawcett at hotmail.com (Graham Fawcett) Date: 17 Aug 2004 09:34:51 -0700 Subject: Flython? References: Message-ID: Peter Hansen wrote in message news:... > Just been looking at Flash and ActionScript... > > In the vein of Jython, I wonder what it would take to build > a Flython? (Lousy name, I know.) That would take Python > source, presumably a subset since some things couldn't be supported, > and compile it into ActionScript bytecode (aka the bytecode compiled > from ECMAScript source for the Macromedia Flash player environment). I've written some code (twice, I think) to generate SWF from Python. Didn't include ActionScript, but it's all there in the SWF spec, so it shouldn't be *too* hard to implement. My code was less than fast, and was highly specialized to do a few things that I was interested in (and ignored the rest). If there's interest, I'll dig it out, though it's far from project-grade code and is possibly broken. The toughest part was just grokking the SWF spec, and building some Pythonic primitives that can output SWF tags. Simply put, writing SWF from Python isn't rocket science. But of course, you want more than just that... > With that, it would be pretty easy to write applications which > have a Flash front end, but with pretty much all the logic > on front and back implemented in Python. A neat idea, definitely begging for a proof-of-concept. I look forward to testing it. ;-) There will be times when you want to make a GUI "flashier" than your framework will allow (unless you're planning to reimplement all of Flash). Perhaps you might want to use the framework to prototype something, and then knock the real thing out using Flash (perhaps importing the ActionScript from your framework). I'd encourage you to leave room in the design for the inclusion of non-native SWF components (i.e. ones built using something other than your framework) that could interact with your back-end (and, through it, with other client components). Dave Kuhlmann has done some interesting writing on generating Web applications from declarations (google for him, Quixote, and REST, and it should turn up). This might be useful, since your framework spans the client/server boundary (and perhaps you'd like to obscure that boundary just a little bit) and would be well suited to a declarative style (except for the scripting). Quixote suits REST quite well, it seems, and might be worth consideration as part of your back-end design. The last random snippet that comes to mind is that, on Win32, it's not hard to build a SWF viewer using wxPython (and the SWF plugin, of course). That might help with deployment where a browser really isn't suitable. I know I've said "your framework" half a dozen times, and there's no such animal, but I do hope that you or someone else picks up the trail on this and gives it a college try. It would be fun to use, I think. -- Graham From alexander.dejanovski at laposte.net Fri Aug 6 08:41:14 2004 From: alexander.dejanovski at laposte.net (Alexander DEJANOVSKI) Date: Fri, 06 Aug 2004 14:41:14 +0200 Subject: ANN : JyRetic EAI Server 1.0 released Message-ID: <6.1.1.1.2.20040806143428.03750b10@127.0.0.1> JyRetic 1.0 is now available after for Retic 1st birthday... The most important new feature is the integration of Tanuki Software's "Java Service Wrapper". It adds to Retic great restart-on-crash features. Other changes are : - New : Adaptor and parameter definitions are now stored to provide, among others, "restart" features. - Bug fix : Exceptions are now correctly raised on error in SQLSink. - New : SMTP Postprocessor - New : Jabber Postprocessor - New : SNMP Trap Appender (logger) - Various bug fixes and improvements I might have forgotten... Retic Administrator 1.32 is out too (Upgrade is highly recommended) Changes are : - Fix : Corrected bug on WSDL parsing during WS component creation - Fix : Corrected bug on estimated end time in execution tracking - New : New items in execution tracking popup menu => Open adaptor definition, Open params definition and restart - New : support for scheduling permanent adaptors Have fun !! ============================================================= WHAT IS RETIC ? Retic is an EAI Server. The aim is to permit applications to communicate, even if they don't speak the same language (which means transport protocols as well as data structures). This is done by building adaptors. An adaptor is composed of : - One source - Several pipes (process data transformations) - Several sinks (destination of data) - Several loggers (using log4j) - Preprocessors (executed only once before adaptor execution - for example => drop/create a table through a SQL query) - Postprocessors (executed only once after adaptor execution - for example => creation of an index on a table through a SQL query) It is written in Jython and works 100% fine with only Java 1.3+ installed (although some libs like cocoon.jar and poi-block.jar might only work on Java 1.4, delete them in case you can't upgrade) on your system (jython 2.1 is embedded in the releases). It provides connectivity with : JMS, HTTP, SOAP, UDDI, FTP, Xindice, JDBC, Jabber, SMTP and more... ============================================================= From yong at net.tamu.edu Tue Aug 17 14:40:32 2004 From: yong at net.tamu.edu (Yong Wang) Date: Tue, 17 Aug 2004 13:40:32 -0500 (CDT) Subject: read input file a line as a list in python Message-ID: <20040817184032.C3A411589B@net.tamu.edu> Hi, All: I need to read a input file as soucre to process data. Ideally if I can read a line from input file as a list (coloumn separate by white space), reorganize field in a line. Does python has this kind of command ? for example, I read a line has: "IP MAC Date..." as a line from input file, How can I only get MAC ? Thanks, Yong From ville at spammers.com Fri Aug 20 10:32:18 2004 From: ville at spammers.com (Ville Vainio) Date: 20 Aug 2004 17:32:18 +0300 Subject: Alternative decorator syntax decision References: <2omet9Fc2v4mU1@uni-berlin.de> Message-ID: H H J2 Yes, I like | decorate2 | decorate1(42, "hello") def f(x): return x+1 And I don't mind the pie syntax either anymore. -- Ville Vainio http://tinyurl.com/2prnb From reinhold-birkenfeld-nospam at wolke7.net Wed Aug 18 15:41:34 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Wed, 18 Aug 2004 21:41:34 +0200 Subject: age of Python programmers In-Reply-To: References: Message-ID: <2ohpksF94tajU3@uni-berlin.de> Gerrit Muller wrote: > Most Python programmers I know are 40+. I am myself 47 (born in december > 1956). > > regards Gerrit > > P.S., > > how many teeners are still programming? Most teeners I know build > websites, but they don't program. I certainly wouldn't call these shockingly horrible bunches of IE-tags thrown together with the intention of being regarded as "cool" a "website". Reinhold, rant rant -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From __peter__ at web.de Fri Aug 13 17:16:34 2004 From: __peter__ at web.de (Peter Otten) Date: Fri, 13 Aug 2004 23:16:34 +0200 Subject: How to sort records in file References: <81a41dd.0408131122.21180d0d@posting.google.com> <411d168e$0$65601$a1866201@newsreader.visi.com> Message-ID: Grant Edwards wrote: > On 2004-08-13, Lad wrote: > >> What is the best( easiest)way how to sort a file? > > $ man sort > > ;) > >> I have a file where each record consists of 3 fields( 3 words) >> and I would like to sort records by the first field( word)in >> each record. > > lines = file('myfilename').readlines() > lines.sort() > for l in lines: > print l, > Or lines = file('myfilename').readlines() lines = [(line.split(None, 1)[0], i, line) for (i, line) in enumerate(lines)] lines.sort() lines = [line for (_, _, line) in lines] for l in lines: print l, if you want to keep the order stable. Peter From cookedm+news at physics.mcmaster.ca Sun Aug 8 22:30:54 2004 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Sun, 08 Aug 2004 22:30:54 -0400 Subject: numarray speed question References: <953AD3D0Didtoken@128.91.2.239> <953C4DD4idtoken@128.91.2.239> <144d0df.0408070828.338f8c19@posting.google.com> Message-ID: At some point, grv575 at hotmail.com (grv575) wrote: >> What you *do* get with numarray is: >> >> 1) transparent handling of byteswapped, misaligned, discontiguous, >> type-mismatched data (say, from a memory-mapped file generated on a >> system with a different byte order as single-precision instead of >> double-precision). > > Heh. Try timing the example I gave (a += 5) using byteswapped vs. > byteswap(). It's fairly fast to do the byteswap. If you go the > interpretation way (byteswapped) then all subsequent array operations > are at least an order of magnitude slower (5 million elements test > example). You mean something like a = arange(0, 5000000, type=Float64).byteswapped() a += 5 vs. a = arange(0, 5000000, type=Float64) a.byteswap() a += 5 ? I get the same time for the a+=5 in each case -- and it's only twice as slow as operating on a non-byteswapped version. Note that numarray calls the ufunc add routine with non-byteswapped numbers; it takes a block, orders it correctly, then adds 5 to that, does the byteswap on the result, and stores that back. (You're not making a full copy of the array; just a large enough section at a time to do useful work.) >> If you need the best possible speed (after doing it in numarray and >> finding it isn't fast enough), you can write an extension module to >> do that bit in C, or look into scipy.weave for inlining C code, or into >> f2py for linking Fortran code to Python. > > Well re speed what really bothers me is the slowness in which numarray > is improving in this area. If I have to take 1000 FFT's over 32 > element arrays, then it's useless. I'll have to install both numarray > and numeric :/ Maybe what you need is a package designed for *small* arrays ( < 1000). Simple C wrappers; just C doubles and ints, no byteswap, non-aligned. Maybe a fixed number of dimensions. Probably easy to throw something together using Pyrex. Or, wrap blitz++ with boost::python. -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From npat at efault.net Fri Aug 13 14:33:31 2004 From: npat at efault.net (Nick Patavalis) Date: Fri, 13 Aug 2004 18:33:31 +0000 (UTC) Subject: Why I love python. References: <411C8CD9.32F39C2@mega-nerd.com> <411C93B2.2027B48B@alcyone.com> <2o4divF6one2U1@uni-berlin.de> Message-ID: On 2004-08-13, Reinhold Birkenfeld wrote: > > I think the dynamic nature does make it impossible to do anything in > such cases at the first place. Consider: > > klass = raw_input() > classobj = eval(klass + "()") > print classobj.whatami > Yes, that's exactly what I meant. The only solution in such a case would be for the environment to call the compiler at run time, and compile classobj then. This means of course that in such cases the compiler must be included in the "executable". I believe this has been done in other dynamic languages. Typed-extensions, as you mention, would also help. /npat From davidf at sjsoft.com Fri Aug 6 10:43:19 2004 From: davidf at sjsoft.com (David Fraser) Date: Fri, 06 Aug 2004 16:43:19 +0200 Subject: @decorators In-Reply-To: <10h6v76mm313cce@news.supernews.com> References: <10h6v76mm313cce@news.supernews.com> Message-ID: John Roth wrote: > "daishi" wrote in message > news:d22692a3.0408052233.3459c3fa at posting.google.com... > >>For what it's worth: >> >>As far as I know, the proposed @decorator syntax will be the first >>time that two logical lines of python with the same indentation will >>not be independent of one another. > > > Examples: > > try - except - finally > if - elif - else > while - else > I think he mean two consecutive lines of python code with the same indentation. David From daniel.dittmar at sap.com Fri Aug 13 04:07:15 2004 From: daniel.dittmar at sap.com (Daniel Dittmar) Date: Fri, 13 Aug 2004 10:07:15 +0200 Subject: PEP 318 decorators are not Decorators References: Message-ID: Arien Malec wrote: > decorator. One of the issues is that the Decorator pattern is more The term decorator as used in the current discussion comes from compiler writing. You have a syntax 'tree' which gets 'decorated' with additional attributes. Daniel From k.hauschildt at onlinemed.de Wed Aug 11 20:14:50 2004 From: k.hauschildt at onlinemed.de (Karsten Hauschildt) Date: Thu, 12 Aug 2004 02:14:50 +0200 Subject: Smart text parsing Message-ID: <000601c48001$63a4bdc0$7e31fbd9@name225q1ocg1y> Heeedewedemethies!!!!!!! -------------- next part -------------- An HTML attachment was scrubbed... URL: From Sibylle.Koczian at Bibliothek.Uni-Augsburg.de Tue Aug 17 04:19:27 2004 From: Sibylle.Koczian at Bibliothek.Uni-Augsburg.de (Sibylle Koczian) Date: Tue, 17 Aug 2004 10:19:27 +0200 Subject: Python indentation deters newbies? In-Reply-To: <56cfb0e3.0408142004.511a8a8e@posting.google.com> References: <3064b51d.0408130615.3fc4a760@posting.google.com> <56cfb0e3.0408142004.511a8a8e@posting.google.com> Message-ID: <2odtceF9itokU1@uni-berlin.de> Porky Pig Jr schrieb: > beliavsky at aol.com wrote in message news:<3064b51d.0408130615.3fc4a760 at posting.google.com>... > >>One of the most commmon reasons programmers cite for not trying Python >>is that indentation determines the program flow -- they think its >>weird. I think programmers who actually try Python adapt quickly and >>do not find the indentation rules to be a problem. >> > > > Not only it's *not a problem*. I've found it quite useful since it > forces you to keep the proper indentation. > I think indentation that's only there for human eyes, not for the compiler, can be the reason why you overlook your bugs: First version: if (condition) then statement-1; statement-2; ... Second version: if (condition) then statement-1; statement-1a; statement-2; ... This isn't Python but Pascal, but you probably wanted the compiler to do exactly what Python _will_ do: execute statement-1a if (and only if) condition is true. I've done this time and again and each time wondered about incorrect results. Of course this won't happen if you have to use braces or begin - end even for a single statement. But with Pascal or C/C++ that's not enforced. And those staircases of end end end (quite a short example) aren't really beautiful, or are they? Koczian From buzzard at urubu.freeserve.co.uk Mon Aug 23 22:10:16 2004 From: buzzard at urubu.freeserve.co.uk (Duncan Smith) Date: Tue, 24 Aug 2004 03:10:16 +0100 Subject: newbie: confused with example in Learning Python 2nd Edition: can anyone give a hint References: <56cfb0e3.0408231710.27d78703@posting.google.com> Message-ID: "Porky Pig Jr" wrote in message news:56cfb0e3.0408231710.27d78703 at posting.google.com... > Here is an example of Stack class which got me totally confused: > > >>> class Stack: > ... def __init__(self, data): > ... self._data = list(data) > ... self.push = data.append > ... self.pop = data.pop > ... > > What I don't understand: we take the 'data' input (a list), and copy > it to semi-private instance attribute _data. Something like this: > > >>> mystack = Stack([1,2,3]) > >>> dir(mystack) > ['__doc__', '__init__', '__module__', '_data', 'pop', 'push'] > >>> mystack._data > [1, 2, 3] > > So: why defitions of self.push and self.pop are defined as > 'data.append' rather than '_data.append', etc. What makes me yet more > confused: the whole thing works just fine, and yet I can't figure out > in which attribute we store the results of pushes and where pops are > coming from. > Like I push '4' on a stack: > > >>> mystack.push(4) > > and yet this does not affect _data (obviously): > >>> mystack._data > [1, 2, 3] > > and yet '4' is stored *somewhere*, since pop() produces the right > result: > > >>> mystack.pop() > 4 > >>> > > Where is that hidden instance attribute and how can I access it? Seems > like very simple definition, and yet there is something tricky about > it. > > TIA. >>> alist = [1,2,3] >>> mystack = Stack(alist) >>> mystack.push(4) >>> mystack._data [1, 2, 3] >>> alist [1, 2, 3, 4] Duncan From deetsNOSPAM at web.de Sun Aug 1 06:58:58 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Sun, 01 Aug 2004 12:58:58 +0200 Subject: PyQt - clear widget for redraw References: <410b4492@news.maxnet.co.nz> <410bf265@news.maxnet.co.nz> Message-ID: Peter wrote: > Thanks, that works fine. > I just started using pyqt yesterday, and having trouble finding a > reference - most Qt stuff is written for c++. The neat thing on pyqt is that usually you can directly translate c++ examples to python. So there is no need to have a separate documentation and other resources. The erase I looked up in the qt standard documentation. -- Regards, Diez B. Roggisch From mark_bottjer at hotmail.com Sun Aug 8 20:05:16 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Sun, 08 Aug 2004 20:05:16 -0400 Subject: Maybe, just maybe @decorator syntax is ok after all In-Reply-To: <4116b725$1@nntp.zianet.com> References: <4116b725$1@nntp.zianet.com> Message-ID: <4116bfbd$1@nntp.zianet.com> Mark Bottjer wrote: > AdSR wrote: > >> You know what, I'm starting to feel the same. Yesterday Anthony >> Baxter mentioned this URL: >> >> http://mail.python.org/pipermail/python-dev/2004-August/047112.html >> >> where GvR says: >> >> """ Given that the whole point of adding decorator syntax is to move >> the decorator from the end ("foo = staticmethod(foo)" after a >> 100-line body) to the front, where it is more in-your-face, it should >> IMO be moved all the way to the front. """ Now combine this with this message, which I just found: http://mail.python.org/pipermail/python-dev/2004-August/047279.html where GvR says: """In the discussion on decorators months ago, solutions involving special syntax inside the block were ruled out early on. Basically, you shouldn't have to peek inside the block to find out important external properties of the function. (Yes, I know that docstrings violate this principle. For the record, it would be better if they were prefix too; and a prefix decorator syntax will let us fix this in the future but introducing a "doc" decorator.)""" So the position of the decorators is not open to debate. :( -- Mark From jdhunter at ace.bsd.uchicago.edu Thu Aug 5 21:44:09 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Thu, 05 Aug 2004 20:44:09 -0500 Subject: tkinter idle handler Message-ID: Does tkinter have an idle handler analogous to pygtk's gtk.idle_add? Normally I could find this myself on google, but googling for tkinter idle turns up a few false positives . JDH From martin at v.loewis.de Thu Aug 5 06:56:29 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 05 Aug 2004 12:56:29 +0200 Subject: distutils frustration In-Reply-To: References: Message-ID: <4112125D.6060608@v.loewis.de> Michal Vitecek wrote: > please, prove me i'm wrong (i'd be happy to) :) Have a look at Fnorb's setup.py Regards, Martin From abra9823 at mail.usyd.edu.au Sat Aug 14 11:09:36 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Sun, 15 Aug 2004 01:09:36 +1000 Subject: importing node into document Message-ID: <1092496176.411e2b302e12a@www-mail.usyd.edu.au> hi! is there an equivalent for the Java document.importNode in Python what i am trying to do is to import a node from a different document into the current document and then append it one of the nodes in the current document tempNode.ownerDocument = node.ownerDocument #the above gives an error saying i am trying to modify a reda-only attribute #if i omit the statement, the statement below throws an error saying they #the nodes are from different document node.appendChild(tempNode) thanks cheers ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From bdelmee at advalvas.REMOVEME.be Wed Aug 18 17:43:24 2004 From: bdelmee at advalvas.REMOVEME.be (=?ISO-8859-1?Q?Bernard_Delm=E9e?=) Date: Wed, 18 Aug 2004 23:43:24 +0200 Subject: Access to Oracle In-Reply-To: References: Message-ID: <4123cdd9$0$8985$6c56d894@feed0.news.be.easynet.net> We are using python 2.3 with cx_oracle on HP-ux originally built againt 8i libraries, works fine to access our db upgraded to 9i2 http://www.computronix.com/utilities.shtml#Oracle From mithrandi at mithrandi.za.net Sat Aug 7 20:00:41 2004 From: mithrandi at mithrandi.za.net (Tristan Seligmann) Date: Sun, 8 Aug 2004 02:00:41 +0200 Subject: @decorator syntax is sugar, but for what exactly? In-Reply-To: References: Message-ID: <20040808000040.GA640@mithrandi.za.net> On Sat, Aug 07, 2004 at 23:50:47 +0000, Bengt Richter wrote: The code: > @limited_expression_producing_function > @another > def func(): pass > is equivalent to: def func(): pass func = limited_expression_producing_function(another(func)) -- mithrandi, i Ainil en-Balandor, a faer Ambar -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From fakeaddress at nowhere.org Sun Aug 8 00:59:48 2004 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sun, 08 Aug 2004 04:59:48 GMT Subject: How to force a single number to be a tuple In-Reply-To: References: <1a517b5.0408061329.429de7fc@posting.google.com> Message-ID: <8riRc.2334$mg2.1933@newssvr27.news.prodigy.com> Roy Smith wrote: > For those of us who went to school a while ago, and perhaps didn't pay > as much attention in math class as we should have, could you translate > "an element of the Cartesian product of zero or more domains" into > English? A domain is a set; it's used in the contexts like the domain of a function, where it means the values for which the function is defined. I see others have explained the Cartesian product. [...] > My Python code built up a list of the values and generated [1, 2, > "three", "four"]. My two friends recoiled violently at the idea that I > would put heterogeneous data types into a list. I passed it off as > simply being due to their poor unfortunate upbringing in the C++/STL > world of type bondage, while I was living in the carefree bohemian > Python world. I was shocked to discover some time later that Python was > not as bohemian as I thought, and the priests and elders would have been > as dismayed at my carefree mixing of data types in a list as my stodgy > C++ brethren were. Perhaps those priests and elders would be happier in ML or one of its followers. There's a lot to be said for uniform-type lists, but that's not Python's idea of lists. -- --Bryan From jtauber at jtauber.com Mon Aug 16 16:57:30 2004 From: jtauber at jtauber.com (James Tauber) Date: Tue, 17 Aug 2004 04:57:30 +0800 Subject: passing globals to imported module In-Reply-To: <10i252tsvv2lda4@corp.supernews.com> References: <10i252tsvv2lda4@corp.supernews.com> Message-ID: <1092689850.30883.202447032@webmail.messagingengine.com> Actually he liked that a lot. I think it's elegant too, although my preference is still for him to change his design. But thanks! On Mon, 16 Aug 2004 13:09:49 -0700, "Jeff Shannon" said: > James Tauber wrote: > > >Had a question from a colleague that I embarrassingly couldn't answer. > > > >He has a script, foo.py with a global. He wants to import bar.py and > >needs that global available in bar.py > > > > > > > > #### global.py > my_global = "Hello!" > > > #### foo.py > import global, bar > > print global.my_global > > > #### bar.py > import global > > print global.my_global > > ;) > > Jeff Shannon > Technician/Programmer > Credit International > > -- > http://mail.python.org/mailman/listinfo/python-list -- James Tauber http://jtauber.com/ journeyman of some http://jtauber.com/blog/ From rschroev_nospam_ml at fastmail.fm Sat Aug 28 09:00:59 2004 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Sat, 28 Aug 2004 13:00:59 GMT Subject: allowing braces around suites In-Reply-To: <1rhdqnd3rm.fsf@rovereto.ifi.uio.no> References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> <87hdqok9i6.fsf@sinken.local.csis.hku.hk> <1rfz68ely9.fsf@rovereto.ifi.uio.no> <876574k7du.fsf@sinken.local.csis.hku.hk> <1r3c28ejis.fsf@rovereto.ifi.uio.no> <5MWXc.228027$ht5.11749427@phobos.telenet-ops.be> <1rhdqnd3rm.fsf@rovereto.ifi.uio.no> Message-ID: Kjetil Torgrim Homme wrote: > [Roel Schroeven]: > >> Kjetil Torgrim Homme wrote: >> > how long do you have to stare before spotting the bug? >> >> Just the time needed to read the code. >> >> > db.update_name(person) >> > if is_student(person): >> > db.update_courses(person) >> > db.commit() >> > only students have their names updated. I wonder why. >> >> No offense, but I wonder why you have a problem with this >> code. IMO the indentation makes perfectly clear what's happening. > > > I don't think it is appropriate that I dump thousands of lines of code > here to illustrate the problem :-) > > when I provide four lines of code and tell you there's a bug, of > course you can spot it immediately. I immediately saw what the code does; at first I didn't know it was the bug you were referring to since I don't know what the code is supposed to do. Then I read 'only students have their data updated' as description of the bug, and only then I knew that the commit was incorrectly indented. > when it's part of a large system, > it's a bit harder. also consider that the db.commit() originally was > correctly placed by the programmer, and the wrong indentation was > introduced later by an editing glitch. In that case, I agree it can be harder. But IMO it gets harder with increasing code complexity, whether braces are used or not. I haven't yet seen very complex python programs, but I have seen C and C++ code with multiple nesting levels, and let me assure that it can sometimes be very difficult to spot errors. -- "Codito ergo sum" Roel Schroeven From yaoroland07 at yahoo.com Thu Aug 19 10:50:35 2004 From: yaoroland07 at yahoo.com (Roland) Date: 19 Aug 2004 07:50:35 -0700 Subject: Interface graphique pour python Message-ID: <8e16829.0408190650.3fa62d5e@posting.google.com> Bonjour, J'ai redhat 9.0 sur mon ordinateur. Et j'ai besoin d'une interface graphique de python pour cnstuire une application . J'ai cherch? mais en vain. Pourriez-vous m'indiquer une? Merci de bien vouloir m'aider. From drumheller at alum.mit.edu Thu Aug 12 13:58:29 2004 From: drumheller at alum.mit.edu (Michael Drumheller) Date: 12 Aug 2004 10:58:29 -0700 Subject: NumArray array-indexing Message-ID: (If you're not interested in NumArray, please skip this message.) I am new to NumArray and I wonder if someone can help me with array-indexing. Here's the basic situation: Given a rank-2 array (i.e., a matrix) it seems to be trivial, with array indexing, to extract a subset of its *columns*. But it does not seem to be trivial to extract a subset of its *rows*. The code snippet below describes the problem (if it really is a problem) in detail. Note that the "problem" has an obvious, quick solution via take(), but I wish it could be done with the much more compact method of array indexing. I hope my little snippet conveys what I'm after. Basically, it seems to me that NumArray simply does not support the distinction between a column vector and a row vector. That is, if you have x=[1,2,3], then transpose(x) is a no-op. True? (Note that doing x.shape=[3,1] does not do what I want; it produces an awkward object that does not have the desired effect from an array-indexing point of view.) Does this strike anyone else as a rather serious limitation for someone (like me) who would love to use Python/NumArray for my daily math instead of, say, Matlab? Thank you. Mike D. -----------------------cut here----------------------------- Demo snippet: from numarray import * x = array(range(1,10), type=None, shape=[3,3]) print "(A) Original 3x3 array:\n", x i = [1,2] print "(B) An index set:\n", i print "(C) 2nd and 3rd rows of x w/ take(x, i, 0):\n", take(x, i, 0) print "(D) 2nd and 3rd cols of x w/ take(x, i, 1):\n", take(x, i, 1) print "(E) 2nd and 3rd rows of x w/ x[i]:\n", x[i] print "(F) 2nd and 3rd rows of x w/ transpose(transpose(x)[i]):\n", transpose(transpose(x)[i]) print "(G) Wish x[transpose(i)] would work, but alas:\n", x[transpose(i)] It has this output: (A) Original 3x3 array: [[1 2 3] [4 5 6] [7 8 9]] (B) An index set: [1, 2] (C) 2nd and 3rd rows of x w/ take(x, i, 0): [[4 5 6] [7 8 9]] (D) 2nd and 3rd cols of x w/ take(x, i, 1): [[2 3] [5 6] [8 9]] (E) 2nd and 3rd rows of x w/ x[i]: [[4 5 6] [7 8 9]] (F) 2nd and 3rd rows of x w/ transpose(transpose(x)[i]): [[2 3] [5 6] [8 9]] (G) Wish x[transpose(i)] would work, but alas: [[4 5 6] [7 8 9]] From richie at entrian.com Fri Aug 27 06:22:00 2004 From: richie at entrian.com (Richie Hindle) Date: Fri, 27 Aug 2004 11:22:00 +0100 Subject: Specific request with code example (encapsulation) __init__ problems In-Reply-To: References: Message-ID: > Thanks I finally got it working. Big help. Glad to hear it! > What's the difference between SetLabel and SetItemLabel. Below is a > paste form the wx manual and it didn't contain that function Either you have an old version of the manual or you didn't read the whole entry for wxRadioBox::SetLabel. The wxWindows 2.5.1 manual says: > wxRadioBox::SetLabel > > [...] > > wxPython note: In place of a single overloaded method name, wxPython > implements the following methods: > > SetLabel(string) Sets the radiobox label. > SetItemLabel(n, string) Sets a label for a radio button. -- Richie Hindle richie at entrian.com From aleaxit at yahoo.com Fri Aug 27 06:02:07 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 27 Aug 2004 12:02:07 +0200 Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> <1gj4fb5.607xsc51izh8N%aleaxit@yahoo.com> <7xllg25lkt.fsf@ruckus.brouhaha.com> <1gj4u3a.12ttba9fynd6uN%aleaxit@yahoo.com> <1gj5bp4.qhup8tldmvebN%aleaxit@yahoo.com> <7xk6vlgemp.fsf@ruckus.brouhaha.com> Message-ID: <1gj6eil.hgzr1l125qaomN%aleaxit@yahoo.com> Antoon Pardon wrote: ... > Fine practicality beats purity, but then the proponents shouldn't > put that much weight on consistency, because practicality breaks > consistency. No: "but special cases aren't special enough to break the rules". No rule was broken by introducing += and friends. > In this case I think the practicality of method chaining beats > the purity of not allowing side-effects in print statements and > of having only one obvious way to do things. You think one way, GvR thinks another, and in Python GvR wins. Go design your own language where what you think matters. > I don't see that much difference in the frustration of having > to write: > > t = f(x) > v[t] = v[t] + 1 You're repeating (necessarily) the indexing operation, which may be unboundedly costly for a user-coded type. > and the frustration of having to write > > lst = f(x) > lst.sort() > lst.reverse() Here, no operation is needlessly getting repeated. If you don't see much difference between forcing people to code in a way that repeats potentially-costly operations, and forcing a style that doesn't imply such repetitions, I wonder how your language will look. Still, I'm much happier thinking of you busy designing your own wonderful language, than wasting your time and yours here, busy criticizing what you cannot change. Alex From paolo.veronelli at yahoo.it Fri Aug 20 10:47:52 2004 From: paolo.veronelli at yahoo.it (Paolino) Date: Fri, 20 Aug 2004 16:47:52 +0200 Subject: Alternative decorator syntax decision In-Reply-To: <1IqdnUtRpciSmrvcRVn-vQ@giganews.com> References: <1IqdnUtRpciSmrvcRVn-vQ@giganews.com> Message-ID: <41260F18.2000809@yahoo.it> Istvan Albert wrote: > Paolino wrote: > >> d2 d2 j2 >> >> Thanks for the piece of democracy > > > or more likely the 'illusion' of it. > IMO democracy stands in the will of helping people partecipate.Illusion of democracy relays on (among the rest) convincing not to do it..... Entropy leads us somewhere where we could easy define democracy in a pragmatic way.If python is not a well defined politically correct system,its users can still laugh about that while they ride the entropic wave. Paolino From luismg at gmx.net Mon Aug 2 18:39:05 2004 From: luismg at gmx.net (Neuruss) Date: 2 Aug 2004 15:39:05 -0700 Subject: Starkiller? References: <278de0e.0408020648.6d187aff@posting.google.com> Message-ID: <278de0e.0408021439.63c7c30@posting.google.com> I sent Michael an email by the end of June, and he replied that it would take a "a few weeks" because he was redoing some parts to make the code more comprehendable and mantainable. I just wonder how many weeks are "a few weeks" ;-) He was very kind to reply, but since I don't know Michael personally, I don't want to bother him with more questions... From justin__devine at hotmail.com Mon Aug 30 16:48:33 2004 From: justin__devine at hotmail.com (Justin) Date: 30 Aug 2004 13:48:33 -0700 Subject: Size of a remote URL In-Reply-To: Message-ID: Ok now I have what I consider to be a very odd problem. It appears my code will not work inside a for loop but will work outside of one. Check it out temp = urlopen("http://www.ecs.soton.ac.uk/~harnad/Temp/Ariadne-RAE.doc") print temp temp2 = temp.info() print temp2 temp3 = temp2.getheader("Content-Length") print temp3 for y in linklisttype: temp = urlopen(y) print temp temp2 = temp.info() print temp2 temp3 = temp2.getheader("Content-Length") print temp3 file_sizes.append(temp3) THIS IS THE CODE RETURNED IN THE CONSOLE. AS YOU CAN SEE the connection closes when the code is placed in a FOR loop. Does anybody have an understanding of why this happens? > Date: Mon, 30 Aug 2004 20:45:40 GMT Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12 OpenSSL/0.9.6b DAV/ 1.0.3 PHP/4.3.2 mod_perl/1.26 Last-Modified: Sun, 20 Apr 2003 15:19:42 GMT ETag: "f10f630-9a800-3ea2ba8e" Accept-Ranges: bytes Content-Length: 632832 Connection: close Content-Type: application/msword > Date: Mon, 30 Aug 2004 20:45:40 GMT Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12 OpenSSL/0.9.6b DAV/ 1.0.3 PHP/4.3.2 mod_perl/1.26 Connection: close Content-Type: text/html; charset=iso-8859-1 From deetsNOSPAM at web.de Sun Aug 29 13:53:38 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Sun, 29 Aug 2004 19:53:38 +0200 Subject: Enumerating Network Adapters References: <4131b09e$0$13683$636a15ce@news.free.fr> Message-ID: > I could process ipconfig or ifconfig outputs, but > this is OS-dependant and not very future-proof... This has been discussed quite a few times on this NG, search google groups. However IMHO there is no general system built-in way (AFAIK not even posix) for doing this, you'll end up parsing tool output anyway... -- Regards, Diez B. Roggisch From artur_spruce at yahoo.com Thu Aug 19 08:23:59 2004 From: artur_spruce at yahoo.com (AdSR) Date: 19 Aug 2004 05:23:59 -0700 Subject: IDLE under Cygwin doesn't show toolbar menu References: <56cfb0e3.0408181608.794fed82@posting.google.com> Message-ID: porky_pig_jr at my-deja.com (Porky Pig Jr) wrote in message news:<56cfb0e3.0408181608.794fed82 at posting.google.com>... > Just downloaded and installed the latest Cygwin distribution which > includes python 2.3.4. IDLE runs fine but for some reason the toolbar > menu doesn't show up. > Like, by default, it starts shell window, but no toolbar. If I type > > idle foobar.py > > it brings both shell and editor windows, but once again, no toolbar on > either window -- which renders the edtior quite disfunctional. > > Just want to check if anyone else ever ran into this problem and what > was the workaround -- before I contact Cygwin folks. > > TIA. I've seen this too. I believe this is a long-known problem with no solution so far. You could check that in the Python project bug list at http://sourceforge.net/projects/python - I think I saw it there. AdSR From skip at pobox.com Fri Aug 13 11:36:09 2004 From: skip at pobox.com (Skip Montanaro) Date: Fri, 13 Aug 2004 10:36:09 -0500 Subject: def ... decorate In-Reply-To: References: Message-ID: <16668.57321.308134.676624@montanaro.dyndns.org> >>>>> "Nick" == Nick Craig-Wood writes: Steven> decorate: Steven> grammarrule('statement : expression') Steven> versioninfo("Added in 2.4") Steven> deprecated Steven> typeinfo(None) Steven> def p_statement_expr(self, p): Steven> print p[1] Nick> as: Nick> staticmethod Nick> grammarrule('statement : expression') Nick> version("Added in 2.4") Nick> deprecatedmethod Nick> type_(None) Nick> def p_statement_expr(self, p): Nick> print p[1] How about def p_statement_expr: staticmethod grammarrule('statement : expression') version("Added in 2.4") deprecatedmethod type_(None) decorate (self, p): """docstring here""" print p[1] Read it something like "define a function named p_statement_expr using a bunch of functions to decorate the basic function". It solves a couple problems: 1. "def" introduces the function definition instead of an arbitrary number of @-expressions. 2. There is no extra indentation of the main body. 3. The name of the function is known early on. 4. "def"/"decorate" pair up visually much the same as "try"/"except" or "if"/"then", though they don't represent alternative blocks of code to be executed. On the minus side it introduces a vertical separation between the function name and parameter list and introduces a new keyword, "decorate". >From a parsing standpoint I think it will work. You'll see either a colon or a left paren after the function name to distinguish between the two types of function definition. I'm not sure if a token needs to be used to separate the various decorator functions or if requiring a newline and indentation is sufficient. Skip From joewong at mango.cc Sun Aug 15 22:38:27 2004 From: joewong at mango.cc (Joe Wong) Date: Mon, 16 Aug 2004 10:38:27 +0800 Subject: SSL TCP server error Message-ID: <006c01c4833a$1ccc4f30$7f00a8c0@scl01.siliconcreation.com> Hi, I tried to create a SSL TCP server using the ssl() function. It fails everytime with an exception: socket.sslerror: (1, 'error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol') I test the SSL support using HTTPSConnection and it works ok. So I assume it is a server side specific problem? I set both keyfile and certfile parameters to None on my test. Regards, - Joe -------------- next part -------------- An HTML attachment was scrubbed... URL: From davidf at sjsoft.com Fri Aug 20 09:38:03 2004 From: davidf at sjsoft.com (David Fraser) Date: Fri, 20 Aug 2004 15:38:03 +0200 Subject: My only complaint about Python In-Reply-To: References: Message-ID: Ames Andreas (MPA/DF) wrote: > Hi, > > Darren Dale wrote: > > >>I love the language. I love the community. My only complaint is that >>Python for Windows is built with Visual Studio. > > > You could look at http://www.python.org/sf/841454. It certainly needs > work though ... > > But its actually trying to do more than what he's asking. This patch is to *cross*-compile python with mingw, compiling it with mingw under windows should be easier. There was an email to python-list saying it was possible here: http://mail.python.org/pipermail/python-list/2004-June/225967.html But unfortunately few details were provided. I've emailed the author to ask him for them David From avner at skilldesign.com Mon Aug 9 13:25:48 2004 From: avner at skilldesign.com (Avner Ben) Date: Mon, 09 Aug 2004 19:25:48 +0200 Subject: @decorator syntax is sugar, but for what exactly? In-Reply-To: <4116ac05$1@nntp.zianet.com> References: <4115b53a$1@nntp0.pdx.net> <4116239e$1@news.012.net.il> <4116ac05$1@nntp.zianet.com> Message-ID: <4117a6f7$1@news.012.net.il> Mark Bottjer wrote: > [snip] > I, personally, don't like the idea of overloading def in this way. To > me, 'def' defines something that looks and acts like a function, just > like 'class' defines something that looks and acts like a class, or > 'while' defines something which looks and acts like a loop. AProperty is > does not act like a function, so using def would be misleading. Properties do not look like functions but are implemented as functions. there is no requirement that a variable must hide behind a property, or that it Must allow both read and write access. > [Ship] > property a: > def __init__( s, v): > __set__( s, v) Why property constructor? > Taking this to the extreme, all existing statement types (class, def, > print, del, etc.) could be recast as these generalized statements. We > could even allow subclassing of existing statements to modify their > behavior (for example, class_def subclassing def to make the new > function a class method). Strong Kung-Fu indeed. Scary, but strong. I recall reading somewhere That the Beta language allowed subclassing anything > Obviously, creating new control constructs is not something we'd want to > do every day, as it can be a great way to obfuscate code beyond all hope > of understanding--but the same is true of meta-classes. Just because it > *could* be abused doesn't mean that it would be. IMO creating New Control constructs is a great and Much needed idea. Avner. From iketo2 at netscape.net Fri Aug 27 21:39:54 2004 From: iketo2 at netscape.net (Isaac To) Date: 28 Aug 2004 09:39:54 +0800 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1ry8k0d2az.fsf@rovereto.ifi.uio.no> Message-ID: <87acwgvy51.fsf@sinken.local.csis.hku.hk> >>>>> "Kjetil" == Kjetil Torgrim Homme writes: Kjetil> that's a hack, and IMHO not worthy of a Python program. Kjetil> not even Perl has anything like that, AFAIK. Hm... hacks are not for Python?! We see every kind of hacks everywhere in Python just like it is in Perl, like (2,) syntax, etc. Some hacks are good, some are bad, and some are dependent on who is looking at it. I'm neutral on whether this particular hack is nice: if one get used to "pass", one can train onself psychologically that it means "I've got nothing else to do, pass to the upper level". It also doesn't conflict with the previous use of pass. I don't know how such logic works for others. At least, a pass statement in a non-empty suite won't be used otherwise, so you can use the convention to end suites safely---and in a way that need no change at all in the Python interpreter. And you can use it *now*, since it is implemented in the default Python mode of Emacs already. Regards, Isaac. From sholden at holdenweb.com Mon Aug 30 08:21:35 2004 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 30 Aug 2004 08:21:35 -0400 Subject: os.popen problem In-Reply-To: <173c23bb.0408282255.2f1be2ee@posting.google.com> References: <173c23bb.0408282255.2f1be2ee@posting.google.com> Message-ID: Matthew K Jensen wrote: > Ok, this might seem odd as to why I am doing this in this certain way, > but it's for a very specific purpose, and in so doing needs to be done > this way. I am writing code on a winbloze box like so: > > ----------- > import os > > vlvl = os.popen('copy con randomfilename','w') > vlvl.write('some stuff') > vlvl.write('some more stuff') > vlvl.write(chr(0)) > vlvl.close() > > ----------- > > At the next to last line, the command is supposed to complete and give > output which resembles "\t1 file(s) copied.\r\n". Appearantly this is > not happening. The last line just hangs there, doing nothing. Is there > something I am supposed to be doing, or is there some concept that has > either blown over the top of my head or just simply forgot? Any > feedback is helpful. > Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> >>> vlvl = os.popen('copy con randomfilename','w') >>> vlvl.write('some stuff') >>> vlvl.write('some more stuff') >>> vlvl.write(chr(0)) >>> vlvl.close() ;oisrulkejhlakjhlkjdh lkjhlkdjfhglkjdfghldkjh jhfljksdhldskjghldkjhgldkjgh ^Z 1 >>> ^Z C:\Documents and Settings\sholden>more randomfilename ;oisrulkejhlakjhlkjdh lkjhlkdjfhglkjdfghldkjh jhfljksdhldskjghldkjhgldkjgh Note that the "copy" command you start with the os.popen() call is specifically reading from the console, and NOT from the standard input. Thus everything you write "down the pipeline" disappears into a black hole. The copy process won't terminate until you send an EOF (CTRL/Z) on the console, and then the program will temrinate normally. regards Steve From tzot at sil-tec.gr Fri Aug 20 10:33:34 2004 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Fri, 20 Aug 2004 17:33:34 +0300 Subject: age of Python programmers References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: On Fri, 20 Aug 2004 10:23:16 +0200, rumours say that Gerrit Muller might have written: [snip] >The most >positive experiences were Sinclair QL-basic, [snip] I'll drink to that! PS If only IBM had initially chosen a Motorola CPU for their PC... -- TZOTZIOY, I speak England very best, "Tssss!" --Brad Pitt as Achilles in unprecedented Ancient Greek From http Sat Aug 28 21:01:40 2004 From: http (Paul Rubin) Date: 28 Aug 2004 18:01:40 -0700 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <7xzn4gwgea.fsf@ruckus.brouhaha.com> <1gj7a1o.1a5d2q410jsn2kN%aleaxit@yahoo.com> <7xisb4xnh5.fsf@ruckus.brouhaha.com> <1gj7c1a.tfdm14p3hclcN%aleaxit@yahoo.com> <7xd61benm9.fsf@ruckus.brouhaha.com> <1gj82n3.1ylkr3nierngmN%aleaxit@yahoo.com> <7xd61b8uh2.fsf@ruckus.brouhaha.com> Message-ID: <7x1xhqg3kb.fsf@ruckus.brouhaha.com> "Terry Reedy" writes: > 'import x' is syntactic sugar for 'x = __import__('x')'. I do not see it > as necessary that sugar for the common case need cover every possible case. > So, how about giving __import__ had an optional param 'signed' defaulted to > False, to allow signed =True or signed = CA? Man, that __import__ thing is ugly. I think it's better to extend the syntax, e.g. import x(a,b) => __import__('x', {'a':None, 'b':None}) import x(a=v1,b=v2)=> __import__('x', {'a':v1, 'b':v2}) so you could say import x(signed) or import x(signed, certfile='mycerts.pem') or whatever. From peter at engcorp.com Thu Aug 12 22:57:35 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 12 Aug 2004 22:57:35 -0400 Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: <10hnqqm8h7b3k89@corp.supernews.com> References: <60dfb6f6.0408111846.615ee9eb@posting.google.com> <3YWdnYxLf--ObofcRVn-pw@powergate.ca> <411ba1db$1@nntp.zianet.com> <411bd3f0$1@nntp.zianet.com> <10hnqqm8h7b3k89@corp.supernews.com> Message-ID: Jeff Shannon wrote: > Yes, this is personal preference, but it seems that it's a preference > shared by many people -- isn't Python supposed to fit my brain, rather > than forcing my brain into Python's shape? The fact that one can get > used to @pie-syntax doesn't mean it's intuitive. I think it is interesting to compare the two on that issue. Even some of the core folks talked about having to become used to the @pie syntax before they decided they didn't mind it. With decorate:, on the other hand, I don't think anyone except perhaps those who have forced their brains to fit it would feel that they have to become used to it. That, to me, says that decorate: is Pythonic, while @pie is clearly not. And I definitely agree with you that if the feature is so bizarre and shocking that it needs bizarre and shocking syntax, we're better off leaving it out of Python. At least for now, until we've had a cooling off period to reconsider whether there might not be a less bizarre and shocking way of doing all this. -Peter From skip at pobox.com Thu Aug 5 23:54:31 2004 From: skip at pobox.com (Skip Montanaro) Date: Thu, 5 Aug 2004 22:54:31 -0500 Subject: PEP-0318 In-Reply-To: <41122FC2.1080608@interlink.com.au> References: <41122FC2.1080608@interlink.com.au> Message-ID: <16659.247.791367.302786@montanaro.dyndns.org> Anthony> ... here's what I managed [to edit in PEP 318] before a tidal Anthony> wave of crap flowed in... I checked in Anthony's changes to PEP 318 (sent in private email) with very few modifications. I simply didn't have enough time to do more this evening. I didn't even have the time to read back through the entire document. Anybody else who feels like taking a whack at it, feel free. I'll be out of Internet reach over the weekend, so it's unlikely I'll be able to do anything more with it until next week. Context diffs against v 1.15 would be best on the off-chance I get inputs from multiple people. A SourceForge patch would be the best place to stick such things so other people can see where your changes are. Note that I'm not really interested in thirty-leven new syntax proposals. What would be helpful are pointers to other documents and concise summaries of some of the discussions on c.l.py and python-dev. Incorporation of all or part of http://www.python.org/moin/PythonDecorators into the PEP would also be appreciated. Try to write objectively. A PEP isn't Usenet. Note how I'm being optimistic that multiple people will contribute. Lots of people have worn out their keyboards on this subject, so I know the energy is out there. It just needs to be focused a bit. Thx, Skip From jjl at pobox.com Sat Aug 14 16:07:09 2004 From: jjl at pobox.com (John J. Lee) Date: 14 Aug 2004 21:07:09 +0100 Subject: The winner of the Python Decorator Poll is... References: <4edc17eb.0408112052.1bbd85b3@posting.google.com> <87acx0p0st.fsf@pobox.com> Message-ID: <87llghmqky.fsf@pobox.com> Doug Holton writes: > John J. Lee wrote: > > Of course. *easily* > > Er, yup. > > Can you try a non-troll response that involves a complete sentence? I didn't intend to troll. Sorry if I came across as rude! Taking my statements in reverse order, and expanding a little : 2. I don't question your simple arithmetic but... 1. Though you seem to think it ridiculously beyond the bounds of possibility, it's very far from obvious that there are not 400 people out there who read about this poll and supported the option that came last, but did not vote. It wouldn't surprise me in the least, in fact. Neither of us really has any evidence either way, which I why I felt like counterbalancing your glib assumption. I reject your prescriptive grammar, too, so there ;-) John From pm_mon at yahoo.com Tue Aug 31 17:12:41 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Tue, 31 Aug 2004 17:12:41 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Steven Bethard wrote: > I wrote: > >>What you're suggesting is that given: >> >>def f1(): >> __author__ = 'Steve' >> >>and >> >>def f2(): >> author = 'Steve' >> >>in f1, the assignment to __author__ occurs in the function's namespace, but >>in f2, the assignment to author occurs in the local namespace. Clearly >>then, the __xxx__ format (if at the beginning of a function) changes the >>namespace to which an assignment applies. > > > Note that the parallel for classes would be if, given: > > class F1: > __author__ = 'Steve' > > and > > class F2: > author = 'Steve' > > that the __author__ assignment in F1 occured in one namespace, while the > author assignment in F2 occured in another namespace. (Something like > __author__ only being available from the class object, while author was only > available from class instance objects.) Python could almost certainly be > treat __xxx__ variables to work this way, but it's not the way it works > *now*. This is why I say that you're introducing a totally new semantics to > __xxx__ assignments. > From the interpreter's or system programmer's point of view, you are absolutely correct. There would be a profoundly different thing going on under the covers. Specifically, __xxx__ assignments that appear at the top of function defs would no longer result in local variables. That is totally different than it is now, you're right. But I believe that from the application programmer's point of view, not much will change. That's because of the way (I believe) the majority of us view __xxx__ assignments (inside of functions) now. When we say def foo(): __author__ = 'Morrow' __version__ = '0.1' we don't care that __author__ and __version__ become local variables because foo is most likely not going to use them in its calculation. So we won't care if later they become something else (attributes of foo). The semantics of assigning to __author__ or __version__ is the same, in the eyes of the application programmer, whether the proposed changes are implemented or not. Paul From reinhold-birkenfeld-nospam at wolke7.net Mon Aug 23 10:56:56 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Mon, 23 Aug 2004 16:56:56 +0200 Subject: line shift? (baby steps 2) In-Reply-To: <6daa8765.0408230412.6db365d6@posting.google.com> References: <6daa8765.0408230412.6db365d6@posting.google.com> Message-ID: <2oueokFe36qgU2@uni-berlin.de> Artemisio wrote: > I have done a small currency calculator. It works and I'm very glad. > But...I'd like to have a line shift if user types a wrong choice. > Please, look at the code and output example down here: > > # -*- coding: ISO-8859-1 -*- > import string > > eudk_currency= 7.47 > dkeu_currency= 0.13 > usdk_currency= 5.93 > dkus_currency= 0.16 > euus_currency= 1.19 > useu_currency= 0.78 As a hint not pertaining to your actual problem: Use a dictionary to store the values, like this: currencies = { "EUDK" : 7.47, "DKEU" : 0.13, (...) } Then you do not have to do if statements like this if currency_str == "DKEU": result= amount_int* dkeu_currency print amount_int, "Danish Crowns correspond to", result, "Euro." (...) You can directly use the input string as index into the dictionary: result = amount_int * currencies[currency_str] print (...) Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From glc at well.com Sun Aug 15 09:46:56 2004 From: glc at well.com (Greg Chapman) Date: Sun, 15 Aug 2004 13:46:56 GMT Subject: Sublassing in C References: <11wahcesttqxl.dlg@news.kaarsemaker.net> Message-ID: On Sat, 14 Aug 2004 15:31:26 +0200, Dennis Kaarsemaker wrote: >I'm trying to create a subclass of Exception in C, but cant figure out >what to use as tp_base in the PyTypeObject struct. Can anybody give me >directions on where to look or maybe even an answer? Currently, exceptions have to be old-style classes, so you cannot create a subclass using the new type-based subclassing. Instead, you should use PyErr_NewException, which creates a new Exception subclass with the given name, base and attributes (despite the first sentence of the documentation, it returns a new subclass, not a new exception object). --- Greg Chapman From catcher at linuxmail.org Thu Aug 12 20:07:29 2004 From: catcher at linuxmail.org (Robert) Date: Thu, 12 Aug 2004 20:07:29 -0400 Subject: Why I love python. References: Message-ID: "Michael Scarlett" wrote in message news:ce6aaec0.0408121605.1f85ea25 at posting.google.com... > There is an amazing article by paul graham about python, and an even > better discussion about it on slashdot. The reason I point this out, > is the more I read both articles, the more I realised how we would be > mutilating the language with that god forsaken @ decorator. > I don't know about the rest of you, but I learned python and fell in > love with its syntax and simplicity. Python - just works. So please > GVR. Don't complicate it. Leave it as is. Work on making it faster, > not uglier. Work on - in some cases - better algorithms for certain > modules, not for it to even closely resemble C or perl or god knows > whateverotherlanguagethereisoutthere. Am i the only one with a > visceral reaction to this thing??? > Nope I have the same reaction. From squirrel at WPI.EDU Thu Aug 12 10:34:28 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 12 Aug 2004 10:34:28 -0400 Subject: decorator with keyword In-Reply-To: References: Message-ID: On Thu, 12 Aug 2004, Peter Otten wrote: > [decorator examples] +2 on this (can I give a +2?). It's not only pretty, but it addresses my gripe about decorators being used for too many purposes (by providing a clean way to supply function attributes). Additionally, by moving docstrings into the transform: block, this provides an easy way to document the generated function, rather than forcing decorators to preserve docstrings by copying the decoratee's docstring into the decorated function. The PythonDecorators wiki doesn't say Guido has specifically shot this style down, so it may yet have a chance. From jmeile at hotmail.com Tue Aug 24 12:17:06 2004 From: jmeile at hotmail.com (Josef Meile) Date: Tue, 24 Aug 2004 18:17:06 +0200 Subject: Time-date as an integer In-Reply-To: References: Message-ID: <412b67ef$1@pfaff2.ethz.ch> Charles Hixson wrote: > [...] > This is the best that I've been able to come up with in getting a > date-time as an integer. It feels like one of the time or date > libraries should have a better solution, but if so, I haven't found it. > Can anyone suggest a better approach? What's about epoch seconds? Here is a page where this approach is explained: http://pleac.sourceforge.net/pleac_python/datesandtimes.html Regards, Josef From aahz at pythoncraft.com Mon Aug 23 14:03:52 2004 From: aahz at pythoncraft.com (Aahz) Date: 23 Aug 2004 14:03:52 -0400 Subject: On consensus decision-making (was Re: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WEDONE?) References: Message-ID: In article , Peter Hansen wrote: > >The voting was merely to narrow down the choices. It seems pretty >clear there are now only three candidates in the running, the @pie >syntax plus J2 and C1. The latter doesn't yet have an implementation, >which is almost certainly its biggest disadvantage (and not that more >people voted for J2 than for it). According to a python-dev message from Michael Hudson, there's an old implementation of C1 (the *original* decorator implementation). ;-) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From apardon at forel.vub.ac.be Tue Aug 17 08:22:30 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 17 Aug 2004 12:22:30 GMT Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> <56cfb0e3.0408142004.511a8a8e@posting.google.com> <2odtceF9itokU1@uni-berlin.de> Message-ID: Op 2004-08-17, Sibylle Koczian schreef : > Porky Pig Jr schrieb: >> beliavsky at aol.com wrote in message news:<3064b51d.0408130615.3fc4a760 at posting.google.com>... >> >>>One of the most commmon reasons programmers cite for not trying Python >>>is that indentation determines the program flow -- they think its >>>weird. I think programmers who actually try Python adapt quickly and >>>do not find the indentation rules to be a problem. >>> >> >> >> Not only it's *not a problem*. I've found it quite useful since it >> forces you to keep the proper indentation. >> > I think indentation that's only there for human eyes, not for the > compiler, can be the reason why you overlook your bugs: > > First version: > > if (condition) then > statement-1; > statement-2; > ... > > Second version: > > if (condition) then > statement-1; > statement-1a; > statement-2; > ... > > This isn't Python but Pascal, but you probably wanted the compiler to do > exactly what Python _will_ do: execute statement-1a if (and only if) > condition is true. I've done this time and again and each time wondered > about incorrect results. > > Of course this won't happen if you have to use braces or begin - end > even for a single statement. But with Pascal or C/C++ that's not enforced. That is why I prefer modula2 style. > And those staircases of > > end > end > end > > (quite a short example) aren't really beautiful, or are they? Maybe not, but they do help readability in a whole lot of cases. -- Antoon Pardon From abra9823 at mail.usyd.edu.au Wed Aug 4 11:09:23 2004 From: abra9823 at mail.usyd.edu.au (Ajay Brar) Date: Thu, 05 Aug 2004 01:09:23 +1000 Subject: EOL - scanning single-quoted string In-Reply-To: References: <1091625659.4110e2bb6db73@www-mail.usyd.edu.au> <4110E3B3.8040709@geochemsource.com> Message-ID: <4110FC23.60509@mail.usyd.edu.au> Christopher T King wrote: >On Wed, 4 Aug 2004, Ajay wrote: > > > >>i got the escape character bit, but i still get an error >> >> >>>>>str='/My Documents/um_ajay.xml' >>>>>re.subn('/', '\\', str) >>>>> >>>>> > >Ah... regex quoting issues. The '\\' makes a single '\' appear in the >string, but being a regex, a single '\' in a string is again interpreted >as a backslash. You will either have to write '\\\\' or use a raw string, >r'\\'. Raw strings pass backslashes untouched, so you only need to >backslash it once for the regex. > >However, the best solution for your problem is not to use regexes, but to >use the os.path module: > > > >>>>from os.path import normpath, abspath >>>>str = '/My Documents/um_ajay.xml' >>>>normpath(str) >>>> >>>> >'\\My Documents\\um_ajay.xml' > > >>>>abspath(str) >>>> >>>> >'C:\\My Documents\\um_ajay.xml' > >normpath() 'tidies up' the path, a task which includes correcting path >seperators, amoung other things. abspath() does the same thing as >normpath(), but also resolves relative paths into absolute ones. Always >look to os.path when doing anything involving paths; it probably has the >function you want, and is portable across platforms. > > thanks. works well now -- Ajay Brar CS Honours 2004 Smart Internet Technology Research Group http://www.it.usyd.edu.au/~abrar1 From mark_bottjer at hotmail.com Fri Aug 6 19:19:40 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Fri, 06 Aug 2004 19:19:40 -0400 Subject: Decorator syntax In-Reply-To: References: Message-ID: <4114120d$1@nntp.zianet.com> Ames Andreas (MPA/DF) wrote: > Michael Ekstrand wrote: >>def(staticmethod) somemethod(self, args): >> some code > > could you or someone else please enlighten me, as someone who wasn't > following the decorator syntax discussion, why this syntax was ruled > out? I can give *a* reason, though it may have little to do with the actual reasoning used by the powers that be. :) Something similar was proposed way back when print>> was introduced. Some asked: "why not use 'print(f) arg, arg, ...' instead of this ugly print>>f hack?" The answer was simple: print is a statement, not a function, and statement names don't take arguments. def is also a statement (as is class). "Calling" it, as putting an argument list after it implies, makes no sense to me. I would be perfectly comfortable with this syntax if it were a function, but it just doesn't seem to fit with a statement. -- Mark From brianc at temple.edu Thu Aug 19 11:14:52 2004 From: brianc at temple.edu (brianc at temple.edu) Date: Thu, 19 Aug 2004 11:14:52 -0400 Subject: Merging pdf documents with Python Message-ID: <3db85202.725c82e0.81bf400@po-d.temple.edu> http://www.reportlab.org/ slight learning curve though... ---- Original message ---- >Date: Thu, 19 Aug 2004 11:08:13 -0400 >From: "Daryl Middleton" >Subject: Merging pdf documents with Python >To: > >Can python be used to merge pdf documents into a single pdf file so that I >do not have to manually insert each one. Thanks > >-- >http://mail.python.org/mailman/listinfo/python-list From listserver at tdw.net Thu Aug 19 10:17:11 2004 From: listserver at tdw.net (Tim Williams) Date: Thu, 19 Aug 2004 15:17:11 +0100 Subject: Removing Email attachments References: <20040819114025.GA11950@setepo.gotdns.org> Message-ID: <010a01c485f7$383e9ba0$506b81c2@twilliams> I need to take an email with none or more attachments, remove attachments with certain file extensions and then send the remaining email onwards. The problem is that I can't find out how to remove single attachements, (I can add new ones and/or remove all) . Am I missing something, or do I have to create a new email object from the remaining bits of the old one ? (I *have* googled) TIA From mattjensen at timetospare.net Tue Aug 31 01:32:58 2004 From: mattjensen at timetospare.net (Matthew K Jensen) Date: 30 Aug 2004 22:32:58 -0700 Subject: console window not disappearing with py2exe References: <173c23bb.0408301410.49b27fe4@posting.google.com> Message-ID: <173c23bb.0408302132.1105a6c3@posting.google.com> mattjensen at timetospare.net (Matthew K Jensen) wrote in message news:<173c23bb.0408301410.49b27fe4 at posting.google.com>... > In another one of my silly apps, I'm using 'windows=' in the setup > script. I can't get the darn console window do disappear. Since the > said app is going to be used with people that have less-than-average > knowledge in computers, it is imperative that this window goes away. I > tried sys.frozen = "windows_exe" and it doesn't work. I'm not sure > what to do. Please save me! > > -Matt K Jensen This is emberassing. I'm going to retract this in full because of an improperly configured setup script. It works now. I don't need anybody giving me advise on this one. Thanks if anybody read it :) -Matt K Jensen From nobody at nowhere.com Thu Aug 5 13:02:23 2004 From: nobody at nowhere.com (Yannick Turgeon) Date: Thu, 5 Aug 2004 13:02:23 -0400 Subject: Telnet session References: Message-ID: Hello Eddie, > What happens if set REMOVEJUNK to False? Same thing except. It does not remove, in that script, "good" output (textual). And the first symptom of the problem is not bad output but it's the fact that Telnet.read_until() is freezing after at a given moment, in our case on "echo bar7". Without a timeout, the function never return. It's certainly related to Windows. I'm cooked again! I have to interact with a windows program (not just send a command and get the ouput but instead (1) start a program, (2) send a commande, (3) get the result, (4) send another command based on the precedent result). I tryed first with popen3: no interaction possible if one of your command depends from a precedent program answer. Pexpect would do the job but it's not working on Windows. Telnet would do the job too, but it doesn't seem to work correctly on Windows. I just looked at Perl telnet lib... and I've got nausea, headache and urticaria! And I don't even know if it would work better, so... Thanks for your help. At least I know that my script would work fine on linux and it's probably Windows related. Yannick "Eddie Corns" wrote in message news:ceqe62$601$1 at scotsman.ed.ac.uk... > "Yannick Turgeon" writes: > > >Hello all, > > I don't see anything obviously wrong in the structure, a simpleminded > translation to linux worked as expected even with a command to generate a > recursive directory listing which, on my machine, is huge. > > What happens if set REMOVEJUNK to False?, I had to do that to see any output > but I don't know what Windows generates. I guess what you're trying to filter > out is ANSI control sequences but I suspect you may not have that right and > you're removing ALL output. > > A minor point, you only need to do the re.compile once, moving it outside the > function would be more efficient. > > Eddie From jussij at zeusedit.com Tue Aug 24 11:25:28 2004 From: jussij at zeusedit.com (Jussi Jumppanen) Date: Wed, 25 Aug 2004 01:25:28 +1000 Subject: Python and C, looking for a C IDE References: <6f402501.0408240353.2a5b8a84@posting.google.com> Message-ID: <412B5DE8.1BE3@zeusedit.com> Michael Foord wrote: > That aside - Pyrex looks the kiddie. Can anyone reccomend a reasonable > C IDE ? An 'IDE' would be nice, but an editor might be sufficient. Take a look at the Zeus for Windows programmers editor: http://www.zeusedit.com/lookmain.html Zeus supports Python, C/C++ and almost any other language. Some of the programming features include: + Code completion and intellisensing + Integrated class browser + Project/workspace management + Fully configurable syntax highlighting + Seamless FTP editing + Integrated version control using the Microsoft Source Code Control (SCC) interface, including CVS integration. + Quick Help context sensitive help engine + Fully scriptable using Python There is also a tutorial (see the Start Button, Programs, Zeus for Windows, Tutorials) that explains how to setup the Ming compiler and debugger (Windows ports of gcc and gdb) to work with Zeus. Jussi Jumppanen http://www.zeusedit.com From nholtz at docuweb.ca Fri Aug 20 12:50:26 2004 From: nholtz at docuweb.ca (Neal Holtz) Date: 20 Aug 2004 09:50:26 -0700 Subject: Rita Sue and Bob too References: Message-ID: <639f17f8.0408200850.5a4a5a96@posting.google.com> "Ben Last" wrote in message news:> > seqToFind = ['Rita','Sue','Bob'] > seqToReplace = ['A','B','C'] > seqToSearch = > ['Ben','Peter','Guido','Mark','David','Rita','Sue','Bob','Junk','Extra'] > ... > > That last block could also be written as: > > #s ends up with the resulting list > s = seqToSearch > s = > string.join(seqToSearch,joiner).replace(string.join(seqToFind,joiner),string > .join(seqToReplace,joiner)).split(joiner) > > But that's verging on the obfuscated :) Very perlish indeed. But the above fails if the first or last words in seqToFind are trailing or leading substrings of other words in seqToSearch. IE, if> seqToSearch = ['Ben','Peter','Guido','Mark','David','Rita','Sue','BobbyJoe','Junk','Extra'] So something that fails slightly less often: def repseq4( names, old, new ): s = '\003'; return ((s+s.join(names)+s).replace(s+s.join(old)+s,s+s.join(new)+s,1)).split(s)[1:-1] It turns out that this is actually faster than the more obvious methods (by about 25% (over Jeremy Jones' method) for a names list of 1000 names, replacing the middle 3). Sure is ugly, though. From ajsiegel at optonline.com Thu Aug 26 09:28:32 2004 From: ajsiegel at optonline.com (Arthur) Date: Thu, 26 Aug 2004 13:28:32 GMT Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: On Thu, 26 Aug 2004 13:00:41 GMT, Arthur wrote: >On Thu, 26 Aug 2004 21:05:46 +1000, Anthony Baxter > wrote: >> >>def foo(): >> __name__ = '%s_banana'%(__name__) >> > > >I'm not sure what you are driving at here, but ... > >Aa a practical matter, wouldn't it be nice to be able to use string >substitution on a docstring placed in its usual location under def >foo(). > >That I need to place my __doc__ under the function can't be considered >a good thing, or intutive thing. > >Sort of like having to do transformations after and under the function >;) > >Art But you can perhaps respond that with a2 the flexibility to put the doc string where you think it belongs, before and above the function (and I don't necessarily disagree, in that that it is always where I find myself putting #comments (though perhaps I am putting them there in particular to *distinguish* them from a docstring (where would I put comments if my docstring were above (perhaps below)))) - that you and I will be placing are docstrings differently can be seen both as a benefit *and as a cost*, of the a2 implmentation. Art From matt at pollenation.net Mon Aug 2 17:50:17 2004 From: matt at pollenation.net (Matt Goodall) Date: Mon, 02 Aug 2004 22:50:17 +0100 Subject: where is yaml ? In-Reply-To: <878ycxtfqg.fsf@blakie.riol> References: <878ycxtfqg.fsf@blakie.riol> Message-ID: <1091483418.13780.5.camel@debian> On Mon, 2004-08-02 at 23:03 +0200, Wilk wrote: > Hi, > > It seems that the link for python-yaml on the http://yaml.org main page > is loose (http://iron.cx/yaml) :-( Try http://www.pyyaml.org -- __ / \__ Matt Goodall, Pollenation Internet Ltd \__/ \ w: http://www.pollenation.net __/ \__/ e: matt at pollenation.net / \__/ \ t: +44 (0)113 2252500 \__/ \__/ / \ Any views expressed are my own and do not necessarily \__/ reflect the views of my employer. From anthonybaxter at gmail.com Mon Aug 16 01:01:11 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Mon, 16 Aug 2004 15:01:11 +1000 Subject: Decorators: an outsider's perspective In-Reply-To: References: <20040814153534.8AC171E4007@bag.python.org> Message-ID: On Sun, 15 Aug 2004 13:43:30 -0400, Paul Morrow wrote: > Define fragile. If you mean, easy to break, I don't see it. There > would be only one way to define an instance method: name its first > parameter 'self'. There would be only one way to define a class method: > name its first parameter 'klass' or 'cls' (or some other synoynm that we > can all vote on). All other methods would be static methods. > > How is that fragile? Python currently doesn't _care_ about the argument list, and the variable names in it. Adding this sort of behaviour is nasty. How, for instance, would you handle adding a method to a class at runtime? Do you poke into the newly added method to make sure you get it right? Do you not do this? What about for more complex decorators? Remember, staticmethod and classmethod are the trivial cases that this feature addresses. How do you handle the more complex ones? From mark_bottjer at hotmail.com Fri Aug 6 17:45:06 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Fri, 06 Aug 2004 17:45:06 -0400 Subject: @decorators In-Reply-To: <3PCdndlfSrERT47cRVn-hw@powergate.ca> References: <4113c488@nntp.zianet.com> <3PCdndlfSrERT47cRVn-hw@powergate.ca> Message-ID: <4113fbe3@nntp.zianet.com> Peter Hansen wrote: > Mark Bottjer wrote: > > Mark, would your example still be acceptable to you if someone wrote > it like this?: > >> def sillyFunction( a, b, c): >> """\ >> The silly function does nothing except get "decorated." classmethod >> determines the form of the first argument (class, object, or >> other). signature changes the call behavior, asserting the types >> passed to and returned from the function. Finally, transactional >> causes boilerplate code to be executed before and after the function >> body, ensuring that either all changes to database are applied, or >> none are. Seeing as this function does nothing, this is trivial :). >> """ >> @classmethod > > > # PLH 20040806112957: added new decorator here > >> # PLH 20040806130023: also changed last value @signature( >> None, a=int, b=float, c=dict) >> @transactional( database) >> pass FWIW, I considered adding this case, but thought the post was long enough already. And I knew someone would bring me to task on it in short order anyway. :) Of course it is still hard to read, but I personally find it easier than the prefix syntax for one main reason: the decorators are confined inside the function they modify. If the language were to state (for example) that all decorators are to appear between the def line and the optional docstring, than it becomes easy (easier, anyway) to parse, and for the programmer to navigate: find function def; start looking for meta stuff; stop looking at the first non-meta statement. No look-ahead is required, and no buffering for a declaration not yet started. > While I find merit in your idea, it's not entirely fair to discard > the @ syntax because it *can* be written the way you showed, but then > not to perform the same analysis on your own idea. I wasn't attempting to discard it. I was attempting to show a border case I had not seen discussed anywhere (as others have done with the def foo (ARGS) [DECS]: variants). To that end, I tried to show just how bad it could be. To make sure it had been considered was the sole intent. > To be entirely fair, I'm not sure that *any* of the proposed syntaxes > cannot be written in such a way that they get buggered up by intervening > whitespace and comments... nor should this be a sole reason for > discarding any one. Agreed. I *personally* find it easier to understand code with the decorators infixed than with them prefixed. To me, knowing that everything I want to know about a function is somewhere *in* that function, as opposed to somewhere *near* it, is quite a powerful aide to understanding. YMMV. -- Mark From aleaxit at yahoo.com Thu Aug 26 16:18:01 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 22:18:01 +0200 Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> <1gj4fb5.607xsc51izh8N%aleaxit@yahoo.com> <7xllg25lkt.fsf@ruckus.brouhaha.com> <1gj4u3a.12ttba9fynd6uN%aleaxit@yahoo.com> Message-ID: <1gj5bp4.qhup8tldmvebN%aleaxit@yahoo.com> Antoon Pardon wrote: ... > Then python has already deviated from the one obvious way to do it. Yep, ever since it let you code 2+3 and 3+2 with just the same effect -- which was from day one, and couldn't have been otherwise. _Preferably_ only one way, but as I said what's preferable can't always be achieved. Nevertheless, when for some task there _is_ one obvious way to do it, adding a feature whose main effect would be giving two alternative obvious ways to do it would be unPythonic. > I can do: > > a = a + b vs a += b. Yes you can, and in the general case get very different effects, e.g.: >>> c=a=range(3) >>> b=range(2) >>> a+=b >>> c [0, 1, 2, 0, 1] versus: >>> c=a=range(3) >>> b=range(2) >>> a=a+b >>> c [0, 1, 2] So, which one is the obvious way to do it depends on what 'it' is. In some cases it doesn't matter, just like b+a and a+b are going to have the same effect when a and b are numbers rather than sequences, and there's nothing Python can do to fight this -- practicality beats purity. If you're (when feasible) altering the object to which name 'a' is bound, a+=b is the obvious way to do it; if you're in any case rebinding name 'a' and letting the original object stand undisturbed, 'a=a+b' is the one obvious way to do THAT. Not all objects can be altered, so the first ones of these tasks isn't always going to be feasible, of course. > > or > > a = b + c vs a = ''.join(b,c) You should try out the code you post, otherwise you risk ending up with code in your face -- ''.join(b, c) will just raise an exception, which is a VERY different effect from what b + c will give in most cases. I'll be charitable and assume you meant ''.join((a, b)) or something like that. Again, it's only in one very special case that these two very different 'ways to do it' produce the same effect, just like in other different special cases 'a = b + c' and 'a = c + b' produce the same effect and there's nothing Python can do about it. But let's be sensible: if 'it' is joining two strings which are bound to names b and c, b+c is the only OBVIOUS way to do it. Building a sequence whose items are b and c and calling ''.join on it is clearly an indirect and roundabout -- therefore NOT "the one obvious way"! -- to achieve a result. Proof: it's so unobvious, unusual, rarely used if ever, that you typed entirely wrong code for the purpose... Nobody ever even wished for there to never be two sequences of code with the same end-result. The idea (a target to strive for) is that out of all the (probably countable) sequences with that property, ONE stands out as so much simpler, clearer, more direct, more obvious, to make that sequence the ONE OBVIOUS way. We can't always get even that, as a+b vs b+a show when a and b are bound to numbers, but we can sure get closer to it by respecting most of GvR's design decisions than by offering unfounded, hasty and badly reasoning critiques of them. > The difference between > > print somelist.sort() > > and > > somelist.sort() > print somelist > > > is IMO of the same order as the difference between > > > print a + b > > and > > r = a + b > print r For a sufficiently gross-grained comparison, sure. And so? In the second case, if you're not interested in having the value of a+b kept around for any subsequent use, then the first approach is the one obvious way; if you ARE, the second, because you've bound a name to it (which you might have avoided) so you can reuse it (if you have no interest in such reuse, it's not obvious why you've bound any name...). In the first case, fortunately the first approach is illegal, the second one is just fine. Were they exactly equivalent in effect neither would be the one obvious way for all reasonable observer -- some would hate the side effect in the first case, some would hate the idea of having two statements where one might suffice in the second case. Fortunately the first approach does NOT do the same thing as the second (it prints out None:-) so Python sticks to its design principles. Let me offer a private libation to whatever deities protect programmers, that Python was designed by GvR rather than by people able to propose analogies such as this last one without following through on all of their implications and seeing why this SHOWS Python is consistent in applying its own design principles! Alex From insert at spam.here Thu Aug 12 18:56:15 2004 From: insert at spam.here (Doug Holton) Date: Thu, 12 Aug 2004 17:56:15 -0500 Subject: Decorator "platform" In-Reply-To: <87zn50nll4.fsf@pobox.com> References: <2nsoofF49frcU1@uni-berlin.de> <87zn50nll4.fsf@pobox.com> Message-ID: John J. Lee wrote: > God help us. <0.5 wink> I'm seeing a pattern. You respond without reading. See http://www.python.org/cgi-bin/moinmoin/PythonDecoratorLibrary From FBatista at uniFON.com.ar Fri Aug 27 16:47:31 2004 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Fri, 27 Aug 2004 17:47:31 -0300 Subject: My IDLE editor wont work! Message-ID: [Dag Hansteen] # hi, I have a problem on my comp - I'm using win2000, and the IDLE editor won't open when I try to execute it. # I tried to uninstall the python versions(yes I had one older installed also) and reinstalled 2.3.4. That doesn't help. Execute it from the command line, to see the errors, and tell us. . Facundo -------------- next part -------------- An HTML attachment was scrubbed... URL: From pm_mon at yahoo.com Thu Aug 26 16:09:42 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Thu, 26 Aug 2004 16:09:42 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Anthony Baxter wrote: > On Thu, 26 Aug 2004 11:09:28 -0400, Paul Morrow wrote: > >>The function does *not* get a new namespace! Let me stress this point a >>little further. We would simply be moving __xxx__ variables *out of* >>the function's local variable namespace to where they belong, the >>namespace of the function itself --- /the same namespace that __doc__ >>lives in./ > > > There _is_ _no_ _such_ _namespace_. __doc__ is an attribute of the > function object. > > You are proposing to add one. How else is __doc__ = __doc__ + 'extra' to work? > > Please, please look into how python's namespaces work a bit more. This > isn't super-complex stuff, and the lovely thing about Python is that > it's _really_ easy to use introspection to see how these things work. Yes, it doesn't seem all that complex, although I'm not sure that everyone reading this understands them and their subtleties. The following is an excerpt from http://docs.python.org/tut/node11.html#SECTION0011200000000000000000 "A namespace is a mapping from names to objects. Most namespaces are currently implemented as Python dictionaries, but that's normally not noticeable in any way (except for performance), and it may change in the future. Examples of namespaces are: the set of built-in names (functions such as abs(), and built-in exception names); the global names in a module; and the local names in a function invocation. In a sense the set of attributes of an object also form a namespace." When I talk about namespaces, I include all of the above, including the sense mentioned in the last line. So an object's attributes constitute a namespace too. Therefore __doc__, being an attribute of the function object, is in the function object's /namespace/. And note that this is *not* a new namespace; it's been there all along. So now to answer your question about how is __doc__ = __doc__ + 'extra' going to work. It's simple. But first, we need to define a term. For the sake of this discussion, let's say that 1) specifying a docstring, and 2) assigning to a top-level [*] __xxx__ variable inside of a function def is making a *'declaration'*. So in the following function def, there are three declarations and one simple assignment. def foo(): """ I am a docstring. """ # declaration __doc__ = __doc__ + 'extra' # declaration __author__ = 'Morrow' # declaration pi = 3.14 # not a declaration Ok? Now declarations would *not* be like local variable definitions. Declarations would be executed in the namespace of the object being defined. "Declarations encountered during the execution of a def statement are executed in the namespace of the function or method object being defined." So in the above example, the three declarations would be executed in the namespace of the foo function object. They would *not* create local variables [**]. To help visualize this, the following would be exactly equivalent: def foo(): pi = 3.14 # not a declaration foo.__doc__ = """ I am a docstring. """ foo.__doc__ = foo.__doc__ + 'extra' foo.__author__ = 'Morrow' Paul * ie. not within a subordinate code block, such as a branch of an if statement. ** if the Python system was so modified. From duanek at chorus.net Thu Aug 19 07:43:34 2004 From: duanek at chorus.net (Duane Kaufman) Date: 19 Aug 2004 04:43:34 -0700 Subject: IDLE under Cygwin doesn't show toolbar menu References: <56cfb0e3.0408181608.794fed82@posting.google.com> Message-ID: <59023571.0408190343.19fb969@posting.google.com> Hi, I reported this behavior too quite a while back, but no 'easy' fix was available, though there is a 'work-around', of sorts. If you start idle without the server (-n option, I _think_) things work as expected. Duane porky_pig_jr at my-deja.com (Porky Pig Jr) wrote in message news:<56cfb0e3.0408181608.794fed82 at posting.google.com>... > Just downloaded and installed the latest Cygwin distribution which > includes python 2.3.4. IDLE runs fine but for some reason the toolbar > menu doesn't show up. > Like, by default, it starts shell window, but no toolbar. If I type > > idle foobar.py > > it brings both shell and editor windows, but once again, no toolbar on > either window -- which renders the edtior quite disfunctional. > > Just want to check if anyone else ever ran into this problem and what > was the workaround -- before I contact Cygwin folks. > > TIA. From apardon at forel.vub.ac.be Fri Aug 27 07:33:23 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 27 Aug 2004 11:33:23 GMT Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> <1gj4fb5.607xsc51izh8N%aleaxit@yahoo.com> <7xllg25lkt.fsf@ruckus.brouhaha.com> <1gj4u3a.12ttba9fynd6uN%aleaxit@yahoo.com> <1gj5bp4.qhup8tldmvebN%aleaxit@yahoo.com> <7xk6vlgemp.fsf@ruckus.brouhaha.com> <1gj6eil.hgzr1l125qaomN%aleaxit@yahoo.com> Message-ID: Op 2004-08-27, Alex Martelli schreef : > Antoon Pardon wrote: > ... >> Fine practicality beats purity, but then the proponents shouldn't >> put that much weight on consistency, because practicality breaks >> consistency. > > No: "but special cases aren't special enough to break the rules". No > rule was broken by introducing += and friends. > > >> In this case I think the practicality of method chaining beats >> the purity of not allowing side-effects in print statements and >> of having only one obvious way to do things. > > You think one way, GvR thinks another, and in Python GvR wins. Go > design your own language where what you think matters. Why the fuss over the chosen decorator syntax if GvR wins anyhow. Why don't you go tell all those people arguing decorator syntax that they should design their own language where what they think matters. If you think I shouldn't voice an opinion here because GvR wins anyhow and my opinion won't matter fine. Just say so from the beginning. Don't start with pretending that you have good arguments that support the status quo because all that matters is that GvR prefers it this way. All good arguments in support are just a coincidence in that case. >> I don't see that much difference in the frustration of having >> to write: >> >> t = f(x) >> v[t] = v[t] + 1 > > You're repeating (necessarily) the indexing operation, which may be > unboundedly costly for a user-coded type. That repetion is just pythons inabilty to optimise. >> and the frustration of having to write >> >> lst = f(x) >> lst.sort() >> lst.reverse() > > Here, no operation is needlessly getting repeated. Yes there is, the operation to find lst from the local dictionary. Although it wont be unboundedly costly. > If you don't see much difference between forcing people to code in a way > that repeats potentially-costly operations, > and forcing a style that > doesn't imply such repetitions, I wonder how your language will look. I'm sure that if I ever find the time to do so, you won't like it. > Still, I'm much happier thinking of you busy designing your own > wonderful language, than wasting your time and yours here, busy > criticizing what you cannot change. If you don't want to waste time, just state from the beginning that this is how GvR wanted it and people won't be able to change it. You shouldn't start by arguing why the language as it is is as it should because that will just prolong the discussion as people will give counter arguments for what they think would be better. If you know that, should people not be persuaded by your arguments, you will resort to GvR autority and declare the arguments a waste of time, you are better of puttings GvR autority that can't be questioned on the table as soon as possible. -- Antoon Pardon From peter at engcorp.com Fri Aug 20 07:21:03 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 20 Aug 2004 07:21:03 -0400 Subject: Feature Request: Current time in traceback In-Reply-To: References: Message-ID: Thomas Guettler wrote: > I think it would be good, if the current time > would be in the traceback. > > This would make it easier to read logfiles with > tracebacks of python scripts. > > I know that I can write a custom exception handler, > but why not make it the default? Two thoughts on why not: 1. Most loggers already write the timestamp before *anything* that is written, so this would be duplicated information. (Actually, I'm curious what logfile you have that *doesn't* have this info already.) 2. This is the first time I've heard anyone suggest that it's a common use case to actually want the traceback to contain a timestamp. I think normally tracebacks are examined immediately when a human is present. When they are logged and it might be important to know the time, see 1. -Peter From bdesth.quelquechose at free.quelquepart.fr Fri Aug 20 04:45:40 2004 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Fri, 20 Aug 2004 10:45:40 +0200 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: <4125b20e$0$29681$636a15ce@news.free.fr> Paul McGuire wrote: > There are a number of messages on the python-dev mail list that indicate > that Guido is looking for some concensus to come from this list as to what > *one* alternative syntax for decorators we would like him to consider in > place of the @ syntax that is currently in 2.4a2. > My vote is F, F and F. Bruno From indigo at bitglue.com Mon Aug 23 21:15:26 2004 From: indigo at bitglue.com (Phil Frost) Date: Mon, 23 Aug 2004 21:15:26 -0400 Subject: How does a "script" differ from a "program" or "subroutine"? In-Reply-To: References: Message-ID: <20040824011526.GC834@unununium.org> A subroutine is another name for "procedure", "function", or "method". They are made like this: def fu(): ... A program can contain any number of subroutines, along with classes, variables, etc. A script is just a program, but has the implication that it's a simple program for a simple task. On Mon, Aug 23, 2004 at 05:18:40PM -0700, tdi wrote: > Ok, stupid question for the day. I'm reading the interview with Steve > Moret and he says: "Once a lot of scripts started going in we knew > there was no way we could back out of using Python." > > I'm just getting into Python and am wondering if I'm missing something > or this is just a semantic issue. > > Thanks. > -Ted From martindemello at yahoo.com Fri Aug 20 06:35:51 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Fri, 20 Aug 2004 10:35:51 GMT Subject: Decorator alternatives: Newbie perspective Message-ID: As a very new newbie, I'm staying out of the decorator discussion; however, since there was a lot of talk about how readable the new syntax would be to newbies, I went over to the wiki page and took a look at all the proposed alternatives. The only one I found readable-at-a-glance was J4 - coming from a non-python background, it's a really attractive syntax, though it's the first place I've seen indentation without a : Anyway, I've got nothing invested in python as yet, so I'll happily learn whatever syntax gets adopted - I just thought the perspective would be helpful. martin From peter_jacobi at gmx.net Tue Aug 3 04:17:15 2004 From: peter_jacobi at gmx.net (Peter Jacobi) Date: 3 Aug 2004 01:17:15 -0700 Subject: More charset troubles (Re: Codecs for ISO 8859-11 (Thai) and 8859-16 (Romanian)) References: <410c2827$0$24830$9b622d9e@news.freenet.de> <410D7AB5.9040100@v.loewis.de> <410E4B49.7030805@v.loewis.de> Message-ID: Hi Martin, All, "Martin v. L?wis" wrote in message > Therefore, it would be a protocol violation (strictly speaking) > if one would use iso-8859-11 in, say, a MIME charset= header. Strictly speaking, there are some more dark corners to check. All ISO charsets should be, strictly speaking, qualified by year. And in fact there were some prominent changes, e.g. in 8859-7 (greek). What to do of them? Looking around: - the RFC references a fixed year old version - Unicode mapping files and libiconv track the newest version - IBM ICU4C provides all versions - Python (not by planning, I assume) has a "middle" version with some features of the old mapping table (no currency signs) and some features of the new (0xA1=0x2018, 0xA2=0x2019) Weird. Best Regards, Peter Jacobi From johng2001 at rediffmail.com Mon Aug 2 19:11:13 2004 From: johng2001 at rediffmail.com (John) Date: 2 Aug 2004 16:11:13 -0700 Subject: New to Python/Programming References: <10gsujk1og2gkbf@corp.supernews.com> Message-ID: Mark wrote in message news:<10gsujk1og2gkbf at corp.supernews.com>... > Hello. I am new to programming and Python and was wondering if someone > could help get me started. I picked Python to start learning to prgram > because of some things I have read about it (easy to learn, object > oriented, clear syntax, etc...). Can anyone assist in getting me > started with learning to program and Python? Recommended reading > material? Online tutorials? Recommended development tools (wxpython, > pythonwin, etc...)? I am a network admin by trade and have done little > programming except for the occasional script or router config. this is > something that has always interested me, but don't have the time to take > any formal classes. Thanks for the help. I really haven't read any books. All I used was online tutorials. Python probably the best teach your self documentation online compared to any languages I know. A LOT of good online docs included in ActivePython. PythonWin is a very good IDE. Lots of links here http://www.python.org/doc/Intros.html I listed some below that I am familiar with. I see that the number has grown since I last checked. So decide by yourself. Begin with Non-Programmers Tutorial For Python (ActivePython) How to Think Like a Computer Scientist (http://www.ibiblio.org/obp/thinkCSpy/) "Instant Python" (http://www.hetland.org/python/instant-python.php) looks like a good start Intermediate Python Tutorial (included in all Python distributions) Advanced Dive Into Python (ActivePython) From peter at engcorp.com Tue Aug 31 09:23:02 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 31 Aug 2004 09:23:02 -0400 Subject: has_method In-Reply-To: References: Message-ID: Gandalf wrote: > > Does anyone knows how to tell if an object has a method with a given > name? How can I access that method? > > For attributes, it is easy: > > class A(object): > a = 12 > b = 'Python' > > a = A() > a.__dict__.has_key('a') # True > a.__dict__.has_key('b') # True > a.__dict__.has_key('c') # False > > But it won't work for methods. Thanks in advance. Don't access __dict__ directly. In fact, most of the time the presence of the __ underscores is to warn you that you are doing something unusual... here's the better way: if callable(getattr(a, 'b')): print 'has a method called b' else: print 'no method called b' getattr(obj, name) retrieves the attribute, and callable() checks if it's a method (roughly speaking... not quite but good enough for your purposes I believe). Look in the docs for the __builtin__ module to learn about these and other such useful functions. http://docs.python.org/lib/built-in-funcs.html#built-in-funcs -Peter From ml at dynkin.com Tue Aug 10 03:22:51 2004 From: ml at dynkin.com (George Yoshida) Date: Tue, 10 Aug 2004 16:22:51 +0900 Subject: Python equivalent to a C trick In-Reply-To: <1d7b6d0d.0408092255.1177908e@posting.google.com> References: <1d7b6d0d.0408092255.1177908e@posting.google.com> Message-ID: Dan wrote: > Is there a python equivalent of this trick in C? > > Logic_Test ? True_Result : False_Result Logic_Test and True_Result or False_Result would be a Python counterpart. > Example: > printf( "you have %i %s", num_eggs, num_eggs > 1 ? "eggs" : "egg" ); So the exmaple is converted to: print "you have %d %s"%(num_eggs, (num_eggs > 1) and "eggs" or "egg") But be warned that if True_Result is evaluated as False(e.g. True_Result is an empty string), this doesn't work. If you don't know what object is considered False in Python, check the following document. * 2.3.1 Truth Value Testing http://docs.python.org/lib/truth.html -- George From http Sun Aug 22 14:21:39 2004 From: http (Paul Rubin) Date: 22 Aug 2004 11:21:39 -0700 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> <7xk6vsgh3i.fsf@ruckus.brouhaha.com> <278de0e.0408220642.3c2274a0@posting.google.com> Message-ID: <7x657b11ak.fsf@ruckus.brouhaha.com> luismg at gmx.net (Neuruss) writes: > That's a surprise! I didn't know about Lisp, so I did a quick search > in Google and I found this quote from CMUCL website: > > "a sophisticated native-code compiler which is capable of powerful > type inferences, and generates code competitive in speed with C > compilers." Heh, amazingly enough, the compiler subsystem of CMUCL also, by complete coincidence, happens to be called Python. > Has anyone tried to learn from this experience? Could this technology > be used with Python? I think Lisp compiler techniques can be used for Python, but some parts of Python semantics are messier to compile. That's no big surprise; Lisp semantics evolved over the years directly in response to the needs of Lisp compilers. I think Python will probably evolve the same way and I hope PyPy is deployable soon, since that will speed up compiler development a lot. I think we should consider a semi-moratorium til then on new language features that might affect compilation. > "There's another guy I'd also like to invite, a Lisp expert, if that's > ok with you. He's been interested in writing a Python compiler for a > while. I'll ask him if he wants to join, but he might not." > > What happened? I don't remember what that was about, but I can guess which guy I must have been thinking of. He's still around and used to read this newsgroup sometimes. From Andreas.Ames at tenovis.com Mon Aug 9 07:04:07 2004 From: Andreas.Ames at tenovis.com (Ames Andreas (MPA/DF)) Date: Mon, 9 Aug 2004 13:04:07 +0200 Subject: Queue qsize = unreliable? Message-ID: <788E231C269961418F38D3E360D1652526CA1F@tndefr-ws00021.tenovis.corp.lan> Hi, Jeff Shannon wrote: > No you don't. You simply execute a non-blocking get(), and be > prepared to catch the Queue.Empty exception. Similarly, if you want > a non-blocking producer, then you execute a non-blocking put() and > catch the Queue.Full exception. I've actually read the docs some time ago, but I've also read the source. I think the problem is here that "non-blocking" isn't very well defined. In the sense that the consumer won't wait until something gets available from an empty Queue you are absolutely right with calling Queue.get(False). But if you look at the source you will find that the first thing that's done in Queue.get() is aquiring a mutex/cv lock. That's potentially quite blocking as far as I am concerned. With CPython's assertions about atomicity of certain list operations it's possible to implement a lock free queue that is even usable for the single producer or single consumer case. That's not to say anything against the standard libraries Queue implementation because it presumably does the right thing for the general case. OTOH, a single thread within a select-loop (single producer/consumer) feeding a bunch of workers shouldn't be too exotic either. > That's really the only reliable way to tell whether the queue is > empty or full, anyhow... I don't understand why this is more reliable than what I described in my scenario. If, for example, you have a single consumer then: if !q.empty(): reliableCode() else unreliableCode() should be absolutely okay. cheers, andreas From artur_spruce at yahoo.com Wed Aug 25 04:22:47 2004 From: artur_spruce at yahoo.com (AdSR) Date: 25 Aug 2004 01:22:47 -0700 Subject: age of Python programmers References: Message-ID: "Lucas Raab" wrote in message news:... > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... 32 here. I discovered Python in early 2003 thanks to Bruce Eckel's mention of it in "Thinking in Java" (something like "becoming my favorite programming language"). No opportunity to use it as my main programming language so far but I use it for helper tools and for personal stuff. AdSR From Sibylle.Koczian at Bibliothek.Uni-Augsburg.de Tue Aug 10 07:39:07 2004 From: Sibylle.Koczian at Bibliothek.Uni-Augsburg.de (Sibylle Koczian) Date: Tue, 10 Aug 2004 13:39:07 +0200 Subject: MySQLdb select In-Reply-To: <2nh4i8Fpn24U1@uni-berlin.de> References: <9RPOc.2792$LI7.1058@newssvr27.news.prodigy.com> <21064255.0408020908.41357e52@posting.google.com> <2n9gmuFuhk8kU1@uni-berlin.de> <2nbn3pFv4865U1@uni-berlin.de> <2nembjF2dr7U1@uni-berlin.de> <2nh4i8Fpn24U1@uni-berlin.de> Message-ID: <2nrqerF3p1jhU1@uni-berlin.de> Sibylle Koczian schrieb: > Andy Todd schrieb: > >> It's a bug. I think it is a bug in MySQL. I'm using 4.0.18 on Debian >> and an interactive session shows the problem; >> [snip] >> Ta-da. Of course, this may have already been notified to MySQL AB, I'd >> check their web site (http://www.mysql.com) or try one of their >> mailing lists. >> > Will do. Thank you. I never thought of trying this directly in MySQL, > always took it for a problem between MySQL and Python. I'll check the > MySQL newsgroup first, as it's in German. > Not really a bug, possibly no very good design decision (not new with MySQL). From the manual: "13.1.3 Comparison Functions and Operators [snip] MySQL compares values using the following rules: [snip] * If one of the arguments is a TIMESTAMP or DATETIME column and the other argument is a constant, the constant is converted to a timestamp before the comparison is performed. This is done to be more ODBC-friendly. Note that the is not done for arguments in IN()! To be safe, always use complete datetime/date/time string when doing comparisons." If a date column is treated the same way, it's clear: "=" compares the date column with a timestamp with time part 0 and gets true; IN compares the date with a string containing '00:00:00' and gets false. Regards, Koczian From mcfletch at rogers.com Thu Aug 26 12:35:02 2004 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Thu, 26 Aug 2004 12:35:02 -0400 Subject: 3D geometry module? In-Reply-To: <412e0951$0$6157$db0fefd9@news.zen.co.uk> References: <412e0951$0$6157$db0fefd9@news.zen.co.uk> Message-ID: <412E1136.4060705@rogers.com> Will McGugan wrote: > Hi, > > Is there a general purpose 3D geometry module for Python? I would like > to be able to read / write 3D models and perform per vertex / per face > operations on them. Pivy gives you an Inventor mechanism for loading .iv and .wrl (VRML97) files, not sure how it handles exposing faces/points, but I'd imagine it's fairly straightforward. OpenGLContext will read/write VRML97 files, and (though it's not set up for it as an API feature) let you process the vertices/faces (there's code in there that will tessellate the faces, for instance, though you need an OpenGL context to do it), see the IndexedFaceSet implementation for example code. There is at least one module that loads 3DS files. You could use Blender's in-program scripting support for any format it supports. I think the U of Waterloo people have a .obj loader, but I'm not sure if it's open-source or not. Don't think anyone has a 3DSMax .ASC loader, (which would be really nice). > Failing that, are there vector / matrix / quaternion classes I can > make use of? I tend to use Numpy for vector and matrix. Both PyOpenGL and OpenGLContext have quaternion classes available, there's a few more in various other packages. Have fun, Mike ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From tzot at sil-tec.gr Mon Aug 16 07:44:45 2004 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Mon, 16 Aug 2004 14:44:45 +0300 Subject: Trouble with file.seek/file.tell on Win32? References: <16671.45400.965715.943437@enthought.hathway.com> <1f7befae04081512496c6f2727@mail.gmail.com> Message-ID: <0b71i094u1t1758o2q3d78vecqbbho2fe4@4ax.com> On Mon, 16 Aug 2004 14:12:54 +0300, rumours say that Christos "TZOTZIOY" Georgiou might have written: [snip correcting myself] >The string "hello\nthere\n" written to a *text* file, has: > >12 bytes on *nix >14 bytes on Windows/DOS >12 bytes on OS/X > In all cases, if you open the file as text and do a .readline(), you read a string of length 6; however, only in the Windows/DOS case, f.tell returns 7, not 6. -- TZOTZIOY, I speak England very best, "Tssss!" --Brad Pitt as Achilles in unprecedented Ancient Greek From olivier.boudevilleNOSPAM at online.fr Fri Aug 6 13:21:17 2004 From: olivier.boudevilleNOSPAM at online.fr (Olivier Boudeville) Date: Fri, 06 Aug 2004 19:21:17 +0200 Subject: Default list parameter issue In-Reply-To: References: Message-ID: Oh, thanks a lot Peter, I did not know about it and was totally stuck. IMHO, this 'feature' is counter-intuitive. Maybe it allows to write in some cases simplier or more efficient functions, but there are enough traps not to add more of them, with this kind of side-effects. I believed, with filter, list comprehension and so on, that python was making some steps towards 'functional programming' and declarative languages (sorry if the translations are not accurate). It would have led to more robust code. It is certainly not that way that recursive functions will be easy to write and understand (but it is just my opinion) ! I do not find/wish this behaviour is 'pythonic', but of course it is a matter of taste. Thanks again nevertheless, it helped me a lot ! Olivier. Peter Otten wrote: > Olivier Boudeville wrote: > > >>I do not understand why using an empty list as default parameter results >> in such a different behaviour. > > > You are not alone. > > http://www.python.org/doc/faq/general.html#why-are-default-values-shared-between-objects > > Peter From newsgroups at jhrothjr.com Thu Aug 12 21:42:58 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Thu, 12 Aug 2004 21:42:58 -0400 Subject: Why I love python. References: Message-ID: <10ho7626f5f3f74@news.supernews.com> "Nick Patavalis" wrote in message news:slrncho5aq.pfh.npat at gray.efault.net... > On 2004-08-13, Michael Scarlett wrote: > > Python needs drastic performance improvement if it is to scrap-off the > "scripting language" stigma. More performance would be helpful. There are a number of projects that are working toward that end, of which the most visible is the PyPy project. Jim Hughnin claims that he's getting substantial improvements with his port to the .Net framework, but see Fredrick Lundh's August 4 post on the subject. As far as I'm aware, the biggest current performance sink is function and method call overhead. Lookup for module and built-in level variables is also a significant time sink - and both module level and builtin identifiers are used quite frequently. Another thing to notice is the garbage collection algorithm. Python uses reference counting as the basic algorithm, which wasn't that bad a choice a decade ago. Today real garbage collection technology has outstripped it so that maintaining the reference counts is another time sink. The descriptor technology in new style classes is a stunning techincal achievement, but in the worst case it requires a full scan of the class hierarchy before the mechanism can decide if it's appropriate to insert an attribute into an instance or invoke a property. > The only way to get these improvements is > making it possible for a python implementation > to produce *efficient* *compiled* code. I think there are lots of people that would dispute you on that. Current Java environments run close to C++ performance due to the JIT compilers that are built into the runtimes. Current JIT technology doesn't require pre-declaration of variable types; it's perfectly happy to insert checks at appropriate points so that it can reuse code when the object types don't change (which they don't most of the time.) John Roth > Just my 2c > /npat > From maney at pobox.com Thu Aug 19 00:56:26 2004 From: maney at pobox.com (Martin Maney) Date: Thu, 19 Aug 2004 04:56:26 +0000 (UTC) Subject: Calling __init__ for all mixins References: Message-ID: Shalabh Chaturvedi wrote: > The new-style super mechanism might indeed solve your problem. In the > snippet that you mention, super(NewStyleOnly, self).__init__() would > only call A.__init__(). But A.__init__ should itself have a super call > of the form: > def __init__(self): > super(A, self).__init__() # A's super call > Now *that* will call B.__init__(), which should itself have a super call I will be dipped in shit. So let me see... super(this_here_class, self) can and will resolve to a class that is not in any sane meaning of the word a super class of this_here_class, but rather a co-base of it? This is either brilliant or pure crack. I'll have to ponder it for a good long while. > http://www.python.org/2.2.3/descrintro.html#cooperation Brilliant. Crack. Brilliant. Crack. ... Luminiferous Aether! Was this chosen specifically to confuse anyone familiar with OO terminology as used in other languages? > Any class wanting to participate in this technique must be new-style. Which brings me back to the original motivation: any nice tricks for doing this without NewSpeek classes? Maybe in a year or so I can get all the production machines upgraded; for now, I have to write to the subset that works across 2.1, 2.2, and, mostly just as a nod to that future so far, 2.3 (I frankly haven't the time to do much worrying about 2.4 yet, and don't expect to any time soon. It would be nice to have only one or two machines to take care of and enough free time to keep up to date with every release.) -- Remember the refrain: We always build on the past; the past always tries to stop us. Freedom is about stopping the past, but we have lost that ideal. -- Lawrence Lessig From ggg at zzz.it Sat Aug 7 09:51:56 2004 From: ggg at zzz.it (deelan) Date: Sat, 07 Aug 2004 15:51:56 +0200 Subject: Python Win32 & TWAIN scanning? In-Reply-To: References: Message-ID: S. David Rose wrote: > Hello everyone. > I am very much enjoying learning python. I am fiddling with a project > that I've decided to use on the Win32 platform. I'd like to be able to > scan a document as a graphic and save it thru Python to a file. I believe > that on Windows, all scanning is done thru the TWAIN interface. I'd like > to use a USB scanner. I've googled for info. regarding Python, PIL, and > scanners but haven't seen anything related to what I'm looking for. Can > anyone out there 'bump' me in the right direction please? let's try again with google: hope this helps. cheers, deelan. -- From ajsiegel at optonline.com Thu Aug 12 13:03:19 2004 From: ajsiegel at optonline.com (Arthur) Date: Thu, 12 Aug 2004 17:03:19 GMT Subject: PEP318 References: <20040812090056.00001e31@titan> <7ttmh0t8c3cogtbhhnp1ohqu8b51pda461@4ax.com> Message-ID: On Thu, 12 Aug 2004 12:33:50 -0400, Roy Smith wrote: >Arthur wrote: >> I must say that after days of waffling, and I think an honest effort >> to accept where things were going, I woke this morning hating >> @decorator. >> >> The existing syntax for this kind of transformation is, in fact, >> exactly what one would expect: >> >> foo=staticmathed(foo). >> >> That is the universal langauge for transformations. And when we try >> to explain to anybody what it is that @decorator means, we go back to >> the pseudo code that is in fact the existing syntax. > >I'm with Arthur. Yes and no. I am contendingt that that staus quo (pre 2.4 alpha2), all things considered, is the best we are going to do, realistically. Within the framwork of Python as it is, and without making changes to Python as it is out of proportion to the need that is being addressed. I certainly thing that @decorator is a chnage out of proportion to the need being addressed. But you are proposing a non-starter, which implicitly rejects the status quo. And proposes other changes out of proportion to the need being addressed. > >One of the objections to: > >def foo (): > whatever >foo = decorator (foo) > >is that you have to type the word "foo" three times. Big f**king deal - all things considered. ;) Art From David Thu Aug 19 23:11:05 2004 From: David (David) Date: Thu, 19 Aug 2004 21:11:05 -0600 Subject: stopping windows services References: Message-ID: Get WService from http://starship.python.net/crew/mhammond. Then, for example: import WService import time listener = WService.WService("Network Associates McShield") listener.status(1) if listener.status(0) != 'STOPPED': print "Stopping Network Associates McShield..." listener.stop() time.sleep(5) listener.status(1) On Thu, 19 Aug 2004 21:52:33 -0400, Bart Nessux wrote: >Can Python be used to stop windows services? I'm writing a script to >automaically remove some troublesome Symantec software, but before >running the main removal script, I need to kill some services. > >Thanks, >Bart From pythos Sat Aug 21 14:59:36 2004 From: pythos (pythos) Date: Sat, 21 Aug 2004 14:59:36 -0400 Subject: Question about importing modules Message-ID: Newbie at python (but not programming) here... I have a program that has "import os" at the top, and then later a call to utime() is made. The python interpreter says "name 'utime' is not defined". But if I change "utime(...)" to "os.utime(...)" then it works fine. Perhaps I am expecting the "import os" statement to work the same way as "import .*" does in Java. So is it the case that if I write "import os" in python, then I still need to write "os.utime(...)"? Or is there something else wrong? Thanks. From len-1 at telus.net Tue Aug 17 12:08:48 2004 From: len-1 at telus.net (Lenard Lindstrom) Date: Tue, 17 Aug 2004 16:08:48 GMT Subject: Generators versus Coroutines References: <7x7js1i887.fsf@ruckus.brouhaha.com> <972ec5bd.0408152037.c50bcee@posting.google.com> Message-ID: Nick Patavalis writes: > On 2004-08-16, Lenard Lindstrom wrote: > > > > As for doing it in Python, coroutines can be implemented using > > threads. > > > > But threads cost! And how much they cost depends on the operating > system. Coroutines cost close to nothing, and are O/S independent. The > only reason to use O/S threads is if you need preemption, and if you > want to cater for parallel execution. > I do not consider using threads to implement coroutines a practical solution. It was alluded to in a posting by Tim Peters giving his take on generators, coroutines and continuations. The case he mentioned was more than likely a demonstration or example than an actual production module. Lenard Lindstrom From cappy2112 at yahoo.com Thu Aug 26 18:37:39 2004 From: cappy2112 at yahoo.com (Tony C) Date: 26 Aug 2004 15:37:39 -0700 Subject: ASPN Python cookbook in a chm References: Message-ID: <8d3e714e.0408261437.3b53c413@posting.google.com> dody wrote in message news:... > ASPN Python cookbook in a .chm file > =================================== > > last updated: 25 August 2004 > > http://miaw.tcom.ou.edu/~dody/aspnpython.chm Thanks a lot !!! This should be included in the next Python distribution! Would you mind posting the script tha mde the CHM file ? (unless you did it in Perl) :-) From ptmcg at austin.rr._bogus_.com Mon Aug 16 03:05:28 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 16 Aug 2004 07:05:28 GMT Subject: Generators versus Coroutines References: <972ec5bd.0408141032.385fe115@posting.google.com> <972ec5bd.0408152033.19fdcba4@posting.google.com> Message-ID: "Timothy Fitz" wrote in message news:972ec5bd.0408152033.19fdcba4 at posting.google.com... > Dominic wrote in message news:... > > > values. I am currently writing a real time strategy game where I have > > I have written a simple 2D-real-time vehicle simulator in Python > > (+ graphics library Allegro), using chained generators > > which works well enough. > > > > If your game is more ambitious, spend some time designing > > a good architecture and specify your components' interfaces. > > Then you could generate your code-skeleton from that; > > simple generators should be sufficient to implement > > your methods which are then driven by your architectures > > "execution model". > > > > ciao, > > Dominic > > It really was never an issue of "Python can't handle this." it was > more of an issue of "Python should more openly support this." I am > championing generators because they make programming SO much easier in > cases, and people really just don't use them outside if list > generation, which saddens me. Have you looked at SimPy? This is a discrete event simulation package in pure Python, using generators in simulation objects to implement the objects' behavior, while managing state, blocking on waits between objects, etc. I think this may be more in the realm you are thinking, beyond simple "list generation." -- Paul From adurdin at gmail.com Tue Aug 31 21:47:14 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Wed, 1 Sep 2004 11:47:14 +1000 Subject: has_method In-Reply-To: <41347BC1.5020407@geochemsource.com> References: <41347BC1.5020407@geochemsource.com> Message-ID: <59e9fd3a04083118476031cbcc@mail.gmail.com> From: Gandalf You are right - I only used dir() interactively. I have the answer, how to check. But how can I access that method? I would like to call it by name. :-) Use the getattr() builtin: class Foo: def mymeth(self): print "This is mymeth happening" methname = 'mymeth' foo = Foo() try: meth = getattr(foo, methname) except AttributeError: print "Method", methname, "does not exist." else: meth() From gumuz at NO_looze_SPAM.net Mon Aug 30 07:41:02 2004 From: gumuz at NO_looze_SPAM.net (Guyon Morée) Date: Mon, 30 Aug 2004 13:41:02 +0200 Subject: PHP Documentation Message-ID: <4133124f$0$281$4d4ebb8e@news.nl.uu.net> hi, I've been working with PHP lately and what I found is that the docs are awesome, as is the python are python docs btw. but one thing that I really like about theirs is the doc-commenting system it has. any user can comment on any page in the docs. this results in a lot of clarifications and examples for the subjects at hand. is it an idea to implement this in the python docs? i believe it's a good idea what are your thoughts? From miki.tebeka at zoran.com Mon Aug 23 05:09:01 2004 From: miki.tebeka at zoran.com (Miki Tebeka) Date: Mon, 23 Aug 2004 11:09:01 +0200 Subject: C language processing. In-Reply-To: <845db307.0408210122.70bfd408@posting.google.com> References: <845db307.0408210122.70bfd408@posting.google.com> Message-ID: <20040823090901.GH1948@zoran.com> Hello stephen, > I'm looking for a python module that would allow me to take an input > file written in 'c' and modify the contents to allow me to, for > example, add arguments to functions, insert macros at specific > locations etc. I have no formal education in computer science , but, > what I believe I'm looking for is somesort of parser (or lexer?). > > So far, I found a bunch of pasers (SimpleParse and SPARK) but these > seem to be quite generic -non-language specifc. I was hoping that the > 'c' langauge was sufficiently well known to be supported natively, > meaning that I would't need to enter the grammar rules into the > parser. > > Does anybody know of a way of doing this in python? (Or, for that > matter, with Perl, as I would be learning either language to carry > this out.) There an ANSI C parser that comes with PLY (http://systems.cs.uchicago.edu/ply/). There is also a mini_c compiler somewhere that is based on PLY. HTH. -- ------------------------------------------------------------------------ Miki Tebeka http://tebeka.spymac.net The only difference between children and adults is the price of the toys From jjl at pobox.com Sun Aug 22 11:06:09 2004 From: jjl at pobox.com (John J. Lee) Date: 22 Aug 2004 16:06:09 +0100 Subject: backward compatibility? References: Message-ID: <87eklz6wm6.fsf@pobox.com> Peter Kleiweg writes: > So how serious are plans to remove things from Python, like > lambda and map and reduce? I am just starting out with Python > and if there is a danger that the programs I write today won't > work next year, I rather invest my time in another language. I > might try Ruby, or stick with Perl. Won't happen until Python 3.0. When / if 3.0 comes out (more than five years away), I'm sure people will continue to maintain 2.x for a long time after that. John From steven.bethard at gmail.com Thu Aug 19 13:30:57 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: 19 Aug 2004 10:30:57 -0700 Subject: inverse of izip References: <41245B48.3020000@zeomega.com> Message-ID: Satchidanand Haridas wrote in message news:... > Could you expand on what you mean by exhaust the iterators too early? > > The reason I ask is that the * operator is applied to > ((1,1),(2,2),....(9,9)). The operation of the > itertools.izip(range10(),range10()) is completed before the * operation > is applied. And the iter() simply converts the result of the inverse > izip operation into an iterator. I hope the above was not too > confusing. :-) Yeah, the difference is a little subtle here. What we have before you use the * operator is an iterator that will yield (1,1) then (2,2) up to (9,9). Note that we don't actually have the tuple ((1,1),(2,2),....(9,9)) yet, just an iterator that will produce the same elements. If your list is very large and you don't want to keep it all in memory at once, it's crucial that we have the iterator here, not the tuple. When you use the * operator, Python converts the iterable following the * into the argument list of the function. This means that if you're using an iterable, it reads all of the elements of the iterable into memory at once. That's why my range10 iterators printed "exhausted" after the * application -- all their elements had been read into memory. Again, if your list is very large, this is a bad thing because you now have all the elements of the list in memory at the same time. My other solution (well, Peter Otten's correction of my solution) never has the whole list in memory at the same time -- each time enumerate generates a tuple and it's index, each of the iterators returned by starzip generates their appropriate items.[*] Steve [*] Of course, if you exhaust one of the iterators before the others, itertools.tee's implicit cache will actually store all the elements, so starzip would really only be efficient if you wanted to iterate through the sub-iterators in lockstep. This means you'd probably want to itertools.izip them back together at some point, but being able to starzip them means you can wrap the individual iterators with extra functionality if necessary. From http Sun Aug 22 14:23:44 2004 From: http (Paul Rubin) Date: 22 Aug 2004 11:23:44 -0700 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> <7x4qmv6cwo.fsf@ruckus.brouhaha.com> Message-ID: <7x1xhz1173.fsf@ruckus.brouhaha.com> Grant Edwards writes: > And I presume you're pleasantly surprised when you run your program and find > out it's not too slow? Sometimes that happens. Other times it really is too slow, and I rewrite it in C. Other times Python is too bloated and I can't even consider using it; for example, in anything that users need to download without a big fuss. From fumanchu at amor.org Wed Aug 25 20:33:04 2004 From: fumanchu at amor.org (Robert Brewer) Date: Wed, 25 Aug 2004 17:33:04 -0700 Subject: Call for signatories for J2 Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E7D@exchange.hqamor.amorhq.net> eltronic wrote: > please count as for the J2 proposal of yesterday. > please list as anon, email withheld. > or better yet email mangled, as this and > other lists promise to mangle but they never do. > here comes another 100 spams and virus as a result of this post. No email addresses (except my own) are going on the proposal. I'll put you down as "eltronic", if that's OK. > include time for objections to any word picked. > note, many are on vacation or only sporadically > even read c.l.py and less frequently py-dev. > a python-announce post woulden't be a bad idea. Not enough time, sorry. I'll have to settle for the Southern hemisphere votes, where it's currently Winter. ;) > @deco is a syntax that will be tolerated, but, > how can so many negatives be a positive? > presumable we will be able to try/except > if no def found, I have seen no mention of this. > will there be a specific Exception? No need, since it's a compile-time behavior, not runtime. Robert Brewer MIS Amor Ministries fumanchu at amor.org From mwh at python.net Fri Aug 6 09:28:37 2004 From: mwh at python.net (Michael Hudson) Date: Fri, 6 Aug 2004 13:28:37 GMT Subject: Confused about pep 318 References: <10h2ihgb8c6fi97@corp.supernews.com> <411304AB.F53A5275@alcyone.com> <10h710cds2i4s18@news.supernews.com> Message-ID: "John Roth" writes: > "Erik Max Francis" wrote in message > news:411304AB.F53A5275 at alcyone.com... > > > Given how things are looking so far with the reaction to the decorator > > syntax, I'd say U+2639 might be more appropriate ... > > Chuckle! > > For those who haven't looked it up, it's a "sad face" > smiley (a frowney?) >>> unicodedata.name(u'\u2639') 'WHITE FROWNING FACE' I like the unicodedata module :-) Cheers, mwh -- The ability to quote is a serviceable substitute for wit. -- W. Somerset Maugham From peter.schwalm at epost.de Tue Aug 24 15:26:01 2004 From: peter.schwalm at epost.de (Peter Schwalm) Date: 24 Aug 2004 12:26:01 -0700 Subject: age of Python programmers References: <20040819231139.D039A1E4003@bag.python.org> Message-ID: <5cf809e9.0408241126.6e3fdd5b@posting.google.com> Hi Andrea, I'm 50 and have with Cobol, C, C++, Rexx, and others for over 20 years. My experiences with seasoned programmers were often like yours ("make" - what's that?). And to be honest, I myself am not really fit in usenet. But like I have always taken the time to study. Since 2 1/2 years I work with Python and try to do in Python whatever is possible. If things are not possible in Python, the reasons are usually political in nature. Peter Schwalm From spam at mouse-potato.com Fri Aug 27 05:50:26 2004 From: spam at mouse-potato.com (Pascal Bourguignon) Date: 27 Aug 2004 11:50:26 +0200 Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4dyXc.25792$Ot3.22106@twister.nyc.rr.com> Message-ID: <878yc0ucyl.fsf@thalassa.informatimago.com> Kenny Tilton writes: > >>What you mean with Unixism? > > repeated accidents. Such a tool would > > first chop off the user's brain, molding > > a mass of brainless imbeciles and > > microcephalic charlatans the likes of > > Larry Wall and Linus Torvald jolly > > Server: Apache/2.0.50 (Fedora) > > ^^^^^^^^^^^^^^^^^^^^^^ > > So you like my approach, which is to condemn things they have never used? > > :) No, that of no more using things that you condemn. -- __Pascal Bourguignon__ http://www.informatimago.com/ Our enemies are innovative and resourceful, and so are we. They never stop thinking about new ways to harm our country and our people, and neither do we. From wilson_tam at yahoo.com Tue Aug 24 04:06:43 2004 From: wilson_tam at yahoo.com (Willy) Date: 24 Aug 2004 01:06:43 -0700 Subject: How to debug Twisted application? Message-ID: <94059dac.0408240006.46c3f8fa@posting.google.com> Hi, I just started learning twisted and hit a big problem. How do I debug my twisted server? I wrote a test tcp server called 'tcpserver.py' using twisted.application method. I start to debug it with 'twisted -b -y tcpserver.py'. Server doesn't stop at any break point I set with the 'break' command at the (Pdb) prompt. I also tried to add 'pdb.set_trace()' into my source code. This time, debug session stops at the right place. But I can't see any SOURCE. I did a '(Pdb) next'... same, not source listed. But the counter of the line advance as normal: (Pdb) n > (337)setStatus() (Pdb) n > (338)setStatus() (Pdb) n > (340)setStatus() Can anyone help? Thanks in advance. Wil From ken.beesley at xrce.xerox.com Sat Aug 21 15:24:04 2004 From: ken.beesley at xrce.xerox.com (Ken Beesley) Date: Sat, 21 Aug 2004 21:24:04 +0200 Subject: unicodedata name for \u000a Message-ID: <4127A154.9080605@xrce.xerox.com> Newbie question: on unicodedata.name If I do import unicodedata unicodedata.name(u"a") or unicodedata.name(u"\u0061") I get 'LATIN SMALL LETTER A" as expected; but when I follow that with unicodedata.name(u"\u000a") I get Traceback (most recent call last): File "", line 1, in ? ValueError: no such name There is, of course, a Unicode name for \u000a, which is 'LINE FEED' or perhaps 'LINE FEED (A)'. Is there a gap in unicodedata? or in my understanding? Thanks, Ken From mike at nospam.com Wed Aug 18 16:36:34 2004 From: mike at nospam.com (Mike Rovner) Date: Wed, 18 Aug 2004 13:36:34 -0700 Subject: age of Python programmers References: <889cbba0.0408181206.1812881c@posting.google.com> Message-ID: Kamilche wrote: > 40. Old enough that Google wouldn't hire me, hehehehe. They hired a friend of mine and he is 44. I'm 41. Fall in love with Python since 1999. That's how I came to it (best viewing in fixed font): -> pdp11 asm -> forth / -> mumps -> clarion -> vba / focal -> basic -> fortran -> c -> c++ \ \ -> pl/1 -> tcl -> perl -> python \ \ -> ibm360 asm -> prolog -> lisp Mike From hyeshik at gmail.com Sat Aug 7 06:31:35 2004 From: hyeshik at gmail.com (Hye-Shik Chang) Date: Sat, 7 Aug 2004 19:31:35 +0900 Subject: Unicode support In-Reply-To: References: Message-ID: <4f0b69dc04080703311bd25269@mail.gmail.com> On 6 Aug 2004 07:57:44 -0700, Richy2004 wrote: > code: > import sys,codecs > file = codecs.open("accountmgr_words_arb.txt", "r", "utf-16") > print (file.readline()) > > output: > File "./test.py", line 5, in ? > print (file.readline()) > File "C:\Python23\lib\codecs.py", line 384, in readline > return self.reader.readline(size) > File "c:\Python23\lib\encodings\utf_16.py", line 57, in readline > raise NotImplementedError, '.readline() is not implemented for > UTF-16' > NotImplementedError: .readline() is not implemented for UTF-16 > UTF-16 readline is being supported by CJKCodecs 1.1. :) >>> import codecs >>> codecs.open("u16test", "r", "cjkcodecs.utf-16") >>> _.readline() u'\u25ce \ud30c\uc774\uc36c(Python)\uc740 \ubc30\uc6b0\uae30 \uc27d\uace0, \uac15\ub825\ud55c \ud504\ub85c\uadf8\ub798\ubc0d \uc5b8\uc5b4\uc785\ub2c8\ub2e4. \ud30c\uc774\uc36c\uc740\n' Hye-Shik From anthonybaxter at gmail.com Tue Aug 24 09:41:57 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Tue, 24 Aug 2004 23:41:57 +1000 Subject: __name__ becoming read-write? In-Reply-To: <8cdmi0dipgk5192li1p8mm2n1hls2hs7rl@4ax.com> References: <3b8ki0tlphodtt8ge8an274qp78ihp1i3n@4ax.com> <8cdmi0dipgk5192li1p8mm2n1hls2hs7rl@4ax.com> Message-ID: On Tue, 24 Aug 2004 13:09:56 GMT, Arthur wrote: > All I think I am looking for is proportionality. The solution should > be proportional to the problem. The current syntax is expressive in > the way that, I thought, was always considered to be fundamental to > the concept of Pythonic. See, I think decorators _are_ proportional to the problem. I think one thing is that decorators are a nice language feature that will allow for a large number of new approaches - things that wouldn't necessarily have been considered before now. > 1) the placement of the transformative code under the function - > leading to a purely hypothetical problem - I am not aware of any > reports of acutal issues arising - of a reader missing important > information related to the function. Aside from anything else, it's ugly and hard to read code - you have to flick to the bottom of the function to see what transforms might, or might not, have been done. > 2) burdensome amounts of typing when dealing with long function names. It's not just a matter of typing, it's a matter of elegance. The current syntax was always a placeholder until we figured out what, if anything, needed to be added. > If Python needs to apologize for being itself in the limited > circumstances that give rise to these conditions, perhaps it can be > done with a bit more - I don't know - dignity. Which would involve > recognizing the issues as minor annoyances, and providing some limited > relief. Again, I think you're misunderstanding the point of decorators. They're a more generally useful feature, and I think people will be far more likely to use them once they're a little more prominent. Not everyone, sure, but those who can use it will find them incredibly useful. The classic "synchronized()" decorator is one obvious example. I think I've mentioned descriptors before in a similar context - 90+% of Python programmers don't (knowingly) use them, but those who need them find them incredibly powerful. And they can then write libraries that use these, and other people can then use those libraries. > And in those cases where the developer's editor's cut and paste > facility are on the fritz and they are dealing with 70 letter function > names, you have given them a writeable __name__ attribute as another > weapon to solve their issue. A couple of people have latched onto the writable __name__ thing, without understanding some very basic problems with it - by itself, it's not particularly useful. If you modify __name__, it does _nothing_ apart from alter the name of the function that appears in tracebacks. It's only when combined with decorators that it becomes useful, imho. From nhodgson at bigpond.net.au Fri Aug 20 06:41:48 2004 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Fri, 20 Aug 2004 10:41:48 GMT Subject: Alternative decorator syntax decision References: <7x3c2iw9ig.fsf@ruckus.brouhaha.com> Message-ID: Peter Otten: > I think Java and C# have been discussed on python-dev. Again you could share > your experience. @Java http://www.jcp.org/aboutJava/communityprocess/review/jsr175/ ///@XDoclet was a forerunner that hid the @s inside doc comments http://xdoclet.sourceforge.net/xdoclet/index.html [C# attributes] can be user defined but are static pieces of metadata. http://msdn.microsoft.com/library/en-us/csspec/html/vclrfcsharpspec_17.asp The "eXtensible C#" language extends this to allow compile time actions. http://www.resolvecorp.com/products.aspx Visual C++ attributes are not currently user definable but can inject code into the output object files. Attributes can only be defined by Microsoft who have not documented the interface between the compiler and the attribute provider DLLs. Microsoft have been promising user defined attributes for a few years now. "Ronald Laeremans attributes" is a good google key. http://msdn.microsoft.com/library/en-us/vcattrib/html/vcrefattributesreference.asp Microsoft IDL has had a hard coded set of attributes using the [] before definition syntax for about 15 years http://msdn.microsoft.com/library/en-us/midl/midl/idl_attributes.asp Neil From nomail at nomail.nomail Mon Aug 16 13:54:53 2004 From: nomail at nomail.nomail (Dominic) Date: Mon, 16 Aug 2004 19:54:53 +0200 Subject: Generators versus Coroutines In-Reply-To: References: <7x7js1i887.fsf@ruckus.brouhaha.com> Message-ID: > actual recursive C call of the interpreter. So to have a yield span more > than one python function would require saving and restoring part of the > actual C stack - coroutines at the C level - or a rewrite of the interpreter > to not make the recursive C calls as in Stackless Python. Well, it works as long as you rewind the stack before it overflows ;-) Ciao, Dominic From anthony_barker at hotmail.com Mon Aug 23 13:53:01 2004 From: anthony_barker at hotmail.com (Anthony_Barker) Date: 23 Aug 2004 10:53:01 -0700 Subject: favorite python web development tool? References: <10i4nttktcvltdd@corp.supernews.com> <899f842.0408180922.38a834e9@posting.google.com> Message-ID: <899f842.0408230953.49b2ed96@posting.google.com> > > Have a look at mod_python 3.1 - I've found performance very good. I > > benchmarked it against a commercial oversized J2EE app server and for > > non complex app found it faster. It includes session handling and a > > basic template system. However, you can use whichever templating > > language you like with it. Cheetah is nice > > Hi Anthony, > > Did you compare it to SCGI, too? > http://www.mems-exchange.org/software/scgi/ > > Thomas No didn't test scgi. I mod_python found it slightly faster than mod_php and hugely faster than zope and lotus domino. Didn't test scgi. Prefer to stick to the official apache project thinking that it will be around longer. scgi does less than mod_python, so it may be quicker - you should test it out. From peter at designtheory.org Mon Aug 9 12:54:49 2004 From: peter at designtheory.org (Peter Dobcsanyi) Date: 9 Aug 2004 16:54:49 GMT Subject: Module for converting XML to Python object(s)? References: Message-ID: Robert Oschler wrote: > Has anybody seen a Python module that will take an XML document (not a > colossal one), and convert it to a Python nested class object? I'm I have something similar implemented in the "ext-rep" module of the "pydesign" package. Here is an excerpt from the documentation: XTree is a class to create and manipulate a labeled rooted tree data structure whose underlying raw data structure is a tree whose nodes are tuples of the structure: (node_name, {dictionary of attributes}, [list of children]) The dictionary of attributes represents the label associated with the node. This raw tree is not accessed directly, however, but through the XTree object's interface. XTree, in fact, is a lazy recursive wrapper around the raw structure and hides the implementation details. From the user's point of view, the internal nodes of the tree presented this way are of the XTree type. The leaves of the tree are either childless XTree objects or some particular Python data types. Currently, the following Python data types can be used for leaves: integer, floating point, string, list of integers. The module is specialized to a particular highly structured XML document, but it should not be difficult to modify it for your needs. The user can read the whole XML document in one step or alternatively as a "stream" of sub XTree-s. In fact, I have found this streaming Reader (parser + converter) solution so useful that I am planning to make the module into a general parameterizable module. You can find documentation and the package at: http://designtheory.org/software/pydesign/ -- , Peter Dobcsanyi From ajsiegel at optonline.com Mon Aug 30 15:58:24 2004 From: ajsiegel at optonline.com (Arthur) Date: Mon, 30 Aug 2004 19:58:24 GMT Subject: Call for signatories for J2 References: <14JYc.8263$6o3.4262@newsread2.news.atl.earthlink.net> Message-ID: "Peter Hansen" wrote in message news:VPSdnRsGq9ImH67cRVn-vg at powergate.ca... > Arthur wrote: > > There is some other syntactical aim here that I wouldn't call "sugar". Once > > again, in the context of "decorators", we might need a new word to express > > what the intention is here. > > > > If a core argument in favor is to shortcut programmer input, I think it > > should be expressed as an unadorned shortcut. And think @ expresses the > > intent, in this respect more baldly and clearly. > > It looked a whole awful lot to me like the driving force behind > the decorator syntax was not to shortcut programmer input, but > to move the decorator up to a more prominent position than it > occupied with the existing syntax (i.e. after the function, > possibly even after lots of other functions, and thus somewhat > hidden from the reader). > > Shortcutting programmer input has, as far as I can tell, never > been a goal of Python syntax except, perhaps, the += form when > applied merely to primitives... > I guess it is a matter of which parts of the discussion one heard louder. Certainly there was a lot of comments from some of the folks much interested in seeing this syntax about the PITA of typing: some_long_name=foo(some_long_name) This issue is undeniably real. The readibility issue is purely theoretical. I am not aware of anyone reporting real isses in real practice. So I guess I took the shortcut issue as the more real of the issues. @ sort of spells macro - in lay terms, at least. And in my mind that is closer to what we are looking at. If we are going for aesthetics, and readibility - we are on the wrong course in any casew, IMO. Art From caleb1 at telkomsa.net Wed Aug 25 22:51:54 2004 From: caleb1 at telkomsa.net (Caleb Hattingh) Date: Wed, 25 Aug 2004 22:51:54 -0400 Subject: Macro expansion: intercept statement interpretation References: Message-ID: On Wed, 25 Aug 2004 00:07:22 +0200, Benjamin Niemann wrote: > ... > If this actually works, a nice application could be rapid prototyping of > syntax extensions to python ('import this module and you can test and > see why my decorator syntax is better than yours' ;) Well spotted! I didn't think of that. The ongoing decorator thread could have had some real-world testing being done. Also, the kind of macro expansion I want to play around could avoid the need for decorators to be added to the language in the first place... From jeff_news at lindholm.org Thu Aug 26 16:38:22 2004 From: jeff_news at lindholm.org (Jeff Lindholm) Date: Thu, 26 Aug 2004 20:38:22 GMT Subject: Newbie question on dictionary!!! References: <494182a9.0408261150.a4c767f@posting.google.com> Message-ID: <2TrXc.5428$ZC7.2685@newssvr19.news.prodigy.com> > I want to ask a simple question. > > Suppose I have an list say g=['a','b','c','d'] > > and I have an dictionary say k={'b':20,'a':10} > > Now I want to sort this dictionary on the basis of the list and if it > doesnt find any of the element in the list then I wud like to replace > it with zero.. > > so I would like to modify k into {'a':10,'b':20,'c':0,'d':0} > > I have tried all the built in associated with dict and lists but was > not able to come up with an solution... > > Can anyone help... Here is a simple thing I was playing with today, that does some of what you want. You could use it for a simple starting point. def countletters(s): ret = {} for c in s: ret[c] = ret.get(c, 0) + 1 return ret if __name__ == "__main__": #ret = countletters("this is only a test of the emergency broadcast system, had this been an actual emergency you would have been told where to tune your radio") ret = countletters(['a','b','b','c']) li = ret.items() li.sort() print "\n\n",li,"\n\n" From elbertlev at hotmail.com Wed Aug 18 15:31:36 2004 From: elbertlev at hotmail.com (Elbert Lev) Date: 18 Aug 2004 12:31:36 -0700 Subject: age of Python programmers References: Message-ID: <9418be08.0408181131.748a3228@posting.google.com> 55 and ticking. First program at 15 in machine code and tape. From maarten at remove_this_ws.tn.tudelft.nl Wed Aug 25 07:57:06 2004 From: maarten at remove_this_ws.tn.tudelft.nl (Maarten van Reeuwijk) Date: Wed, 25 Aug 2004 13:57:06 +0200 Subject: Scipy install Message-ID: I am trying to install scipy on an SGI Altix 3700 system, but I cannot convince the distutils installer that BLAS and LAPACK are already there and that I don't need ATLAS because everything's optimized already. I tried modifying the site.cfg to tell where the libraries are located: ... [lapack] library_dirs = /usr/local/opt/scs_beta/lib lapack_libs = scs [lapack_src] # src_dirs = .. [blas] library_dirs = /usr/local/opt/scs_beta/lib blas_libs = scs ... The installer complains that it cannot locate the sources, but I only want scipy to use the libraries. Any ideas on how to fix this? TIA, Maarten -- =================================================================== Maarten van Reeuwijk Thermal and Fluids Sciences Phd student dept. of Multiscale Physics www.ws.tn.tudelft.nl Delft University of Technology From jdc at uwo.ca Mon Aug 9 10:32:21 2004 From: jdc at uwo.ca (Dan Christensen) Date: Mon, 09 Aug 2004 10:32:21 -0400 Subject: decorators as a special case of an @ operator? References: Message-ID: <87llgocrgq.fsf@uwo.ca> I wonder what people think of the following crazy idea, which has two parts. 1) Allow anonymous multi-line functions. For definiteness, I'll use the following syntax, but lambda or something else could be used too: f = def (a,b,c): d = a*b return d + c 2) Define a *binary* operator @ which is just a shorthand for function application: f @ x = f(x) Note that f(x) is sometimes pronounced "f at x", so @ is a reasonable symbol to use. But it could also be something else. This @ is not associative; make the rule that it associates from right to left, so g @ f @ x = g(f(x)) Presto, you have decorators: f = decorator1 @ decorator2 @ def (a,b,c): d = a*b return d + c And the function name is at the top, like some people prefer. Notes: - Multi-line anonymous functions are something that have been requested a lot already. - With 1) alone, you already can do: f = decorator1( decorator2( def (a,b,c): d = a*b return d + c )) The sole purpose of @ is to avoid all the closing parens. - To avoid trailing backslashes, the parser would have to automatically continue to the next line when a line ends in @. - Since g @ f @ x = g(f(x)), @ is a bit like function composition, usually written as a small circle, again suggesting that @ is a reasonable symbol. (But note that g @ f = g(f) which is not the same as g composed with f...) - This @ could be useful in other contexts to avoid deeply nested parentheses. - If x is a tuple, f @ *x could mean f(*x), which allows @ to be used with functions of several arguments. (Not very relevant here.) Dan From ialbert at mailblocks.com Fri Aug 20 09:52:15 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Fri, 20 Aug 2004 09:52:15 -0400 Subject: Alternative decorator syntax decision In-Reply-To: <3b2846c4.0408200541.5d925216@posting.google.com> References: <3b2846c4.0408200541.5d925216@posting.google.com> Message-ID: John Crichton wrote: > Surely any English language keyword that gives a meaningful hint as to > its purpose within a program has to be more readable than an arbitrary > '@' symbol? so what is more 'readable' x[1:10] or x[from 1 to 10 ] From roccomoretti at hotpop.com Tue Aug 24 12:45:36 2004 From: roccomoretti at hotpop.com (Rocco Moretti) Date: Tue, 24 Aug 2004 11:45:36 -0500 Subject: function taking scalar or list argument In-Reply-To: <412a2bce$1_1@127.0.0.1> References: <412a2bce$1_1@127.0.0.1> Message-ID: beliavsky at aol.com wrote: > I can define a function that transforms either a scalar or each element in > a list as follows: > > def twice(x): > try: > return map(twice,x) > except: > return 2*x > > print twice(3) # 6 > print twice([1,4,9]) # [2,8,18] > > Is this good style? I intend to define many functions like this and want > to use the right method. Thanks. In addition to those options already mentioned, here's another alternative. def twice(*args): retval = [2*x for x in args] if len(retval) == 1: return retval[0] else: return retval print twice() # [] print twice(3) # 6 print twice([1,4,9]) # [1, 4, 9, 1, 4, 9] #BUT ... print twice(*[1,4,9]) # [2,8,18] # Note '*' -^ print twice(1,4,9) # [2,8,18] # No '[]' --^----^ You can even omit the if ... else, if you don't mind getting a singleton list for the one-parameter case. (i.e. twice(3) == [6]) From peter at engcorp.com Thu Aug 5 14:32:48 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 05 Aug 2004 14:32:48 -0400 Subject: Confused about pep 318 In-Reply-To: References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: Anthony Baxter wrote: > On Thu, 05 Aug 2004 13:29:29 -0400, Peter Hansen wrote: > >>I'll make another donation to PSF if the final decorator syntax >>does not Perlishly use arbitrary punctuation as the @ syntax does. > > FFS. What exactly is "Perlish" about @? It's an unused symbol. That's all. > It's hardly arbitrary - Java, for instance, already uses @ for the same thing. And Java chose it based on what precedent? Basing a choice on someone else's arbitrary choice makes something only ever so slightly less arbitrary. Python doesn't need to select syntax from other languages. Python leads, it doesn't follow. Until now. :-( -Peter From imbaczek-nospam at poczta.fm.cut-from-here.no-spam.info Fri Aug 20 17:26:50 2004 From: imbaczek-nospam at poczta.fm.cut-from-here.no-spam.info (Marek =?iso-8859-2?Q?Baczy=F1ski?=) Date: Fri, 20 Aug 2004 23:26:50 +0200 Subject: Fate of lambda, Functional Programming in Python... References: <412636D1.6070808@noaa.gov> <41265E67.A08409A6@juno.com> <2on5k1FcjmvdU1@uni-berlin.de> Message-ID: <4dxun9nvgeaz.dlg@baczek.net.invalid> Dnia Fri, 20 Aug 2004 22:37:07 +0200, Reinhold Birkenfeld napisa?(a): > Jeff Sandys wrote: >> I think that lambda should be unlimited and expanded. It already has >> the >> colon, block delimiter, so allow lambda to be a multistatement and >> multiline >> indented block! > > So in what point exactly is this different from a def(), then? 1) Lambda is anonymous. 2) Lambda evaluates to a function (or rather can be used as an expression.) Try this without lambda: [lambda x, y: x+y, lambda x, y: x*y, ... (etc.)] I don't say it's impossible, but largely superfluous. (Note that this *particular* case can be (better) solved by operator.*.) -- Marek Baczy?ski :: UIN 57114871 :: GG 161671 :: JID imbaczek at jabber.gda.pl He who knows best best knows how little he knows. -- Thomas Jefferson From amdescombes at qualicontrol.com Wed Aug 18 07:27:12 2004 From: amdescombes at qualicontrol.com (AMD) Date: Wed, 18 Aug 2004 13:27:12 +0200 Subject: Is it possible to write a DLL using python In-Reply-To: References: Message-ID: Actually what I need to do is write a DLL which exports a single stdCall method named Execute which receives an IDispatch interface to the caller as its only parameter: Here is the equivalent Delphi declaration of the method I need to export : procedure Execute(caller IDispatch); stdcall; I will take a look at Pyrex and Py2Exe and see if they can help me. Regards, Andre > Not directly, but yes, using libpython. Essentially you write your > python code and then a thin C wrapper over it that does datatype and > calling convention conversion. Since this is not a pleasant task for > many people, you might take a look at Pyrex, which does this quite > nicely. Generally Pyrex is considered as a way to wrap C code for use > but Python, but it works just as well the other way. > > On Tue, Aug 17, 2004 at 03:44:50PM +0200, AMD wrote: > >>Hi, >> >>I need to write a Win32 DLL and I would like to use Python instead of >>VB, C++ or Delphi. Is this possible? >> >>Thank you, >> >>Andre M. Descombes From jjl at pobox.com Sat Aug 28 15:25:02 2004 From: jjl at pobox.com (John J. Lee) Date: 28 Aug 2004 20:25:02 +0100 Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> <1gj4fb5.607xsc51izh8N%aleaxit@yahoo.com> <7xllg25lkt.fsf@ruckus.brouhaha.com> <1gj4u3a.12ttba9fynd6uN%aleaxit@yahoo.com> <1gj5bp4.qhup8tldmvebN%aleaxit@yahoo.com> <7xk6vlgemp.fsf@ruckus.brouhaha.com> <1gj6eil.hgzr1l125qaomN%aleaxit@yahoo.com> <1gj6n23.vnzqrh1unc1qfN%aleaxit@yahoo.com> Message-ID: <873c275alt.fsf@pobox.com> aleaxit at yahoo.com (Alex Martelli) writes: [...] > Maybe one day I'll be psychologically able to use killfiles more > consistently, whenever I notice some poster that I can reliably classify > as a useless flamer, and let readers of that poster's tripe watch out > for themselves. But still I find it less painful to just drop out of > c.l.py altogether when I once again realize I just can't afford the time > to show why every flawed analysis in the world IS flawed, why every > false assertion in the world IS false, and so on -- and further realize > that there will never be any shortage of people eager to post flawed > analysis, false assertions, and so on, to any public forum. [...] It can be amusing, in a sadistic sort of way, to watch you attempt to nail to the floor every protruding flabby piece of argument, no matter how peripheral or repetitious. It's not *always* as edifying as other ways you could spend your time, though... But I do see the temptation :-/ John From luismg at gmx.net Mon Aug 16 19:37:37 2004 From: luismg at gmx.net (Neuruss) Date: 16 Aug 2004 16:37:37 -0700 Subject: Newbie 1st program References: Message-ID: <278de0e.0408161537.61ab1301@posting.google.com> Just a question: How did you make the installer package? From FBatista at uniFON.com.ar Fri Aug 27 12:09:41 2004 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Fri, 27 Aug 2004 13:09:41 -0300 Subject: Alex Martelli: Welcome back! Message-ID: [Dave Benjamin] #- Asunto: Alex Martelli: Welcome back! #- #- It's nice to see you around here again! +1 . Facundo From z at b.com Fri Aug 27 17:55:36 2004 From: z at b.com (JZ) Date: Fri, 27 Aug 2004 23:55:36 +0200 Subject: Mysql in Python? References: Message-ID: Dnia 27 Aug 2004 10:56:13 -0700, Simon John napisa?(a): > And the ADOdb page says that to use it with MySQL, you have to install > the mysql-python (MySQLdb) module, so doesn't really help here, as we > haven't even got that far! But what's the real problem? Everyone knows MySQLdb is the main MySQL module for Python... -- JZ From wilkSPAM at OUTflibuste.net Thu Aug 19 17:24:54 2004 From: wilkSPAM at OUTflibuste.net (Wilk) Date: Thu, 19 Aug 2004 23:24:54 +0200 Subject: age of Python programmers References: Message-ID: <87u0uystw9.fsf@blakie.riol> "Lucas Raab" writes: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... 35, i began when i was 11 on Apple ][+ in 6502 assembly langage, then C, Windev, PHP, Java and now I'm happy to can use only python since somes years :-) -- Wilk - http://flibuste.net From dyoo at hkn.eecs.berkeley.edu Wed Aug 25 13:39:23 2004 From: dyoo at hkn.eecs.berkeley.edu (Daniel Yoo) Date: Wed, 25 Aug 2004 17:39:23 +0000 (UTC) Subject: counterpart for Python None in C++ side References: Message-ID: Jinming Xu wrote: : Hi Folks, : Could any of you please teach me what's the counterpart of Python None in : C++ side? Since I need to manipulate a Python None in C++. There's a separate Py_None object that's accessible from the Python/C API: http://docs.python.org/api/noneObject.html Is this what you're looking for? From adurdin at gmail.com Thu Aug 19 20:09:32 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Fri, 20 Aug 2004 10:09:32 +1000 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: <59e9fd3a04081917094e0e1d5e@mail.gmail.com> As for me? J2, C1, um.... er... J2. From harry.g.george at boeing.com Wed Aug 18 13:08:53 2004 From: harry.g.george at boeing.com (Harry George) Date: Wed, 18 Aug 2004 17:08:53 GMT Subject: age of Python programmers References: Message-ID: mjackson at alumni.caltech.edu (Mark Jackson) writes: > "Lucas Raab" writes: > > One thing I've always kind of wondered is what is the average age of a > > Python programmer?? What age groups use Python?? Something to think > > about.... > > 55. Wrote my first program at 16 (Fortran, punch cards). > > -- > Mark Jackson - http://www.alumni.caltech.edu/~mjackson > Fascism should more properly be called corporatism, since it > is the merger of state and corporate power. > - Benito Mussolini > > Finally, someone in my cohort :-). 52. Also wrote first program at 16, FORTRAN, on punch cards. Many, many languages later found python and bliss. In the middle of a world of meetings, project planning, and other project managering a few hours coding restores a sense of hope. (BTW, nice signature quote. See http://www.seanet.com/~hgg9140/ for related materials.) -- harry.g.george at boeing.com 6-6M21 BCA CompArch Design Engineering Phone: (425) 342-0007 From michael at foord.net Mon Aug 2 02:43:59 2004 From: michael at foord.net (Fuzzyman) Date: 1 Aug 2004 23:43:59 -0700 Subject: Making a socket connection via a proxy server References: <8089854e.0407300433.4c09bce0@posting.google.com> <_yvOc.5828$Z14.7072@news.indigo.ie> Message-ID: <8089854e.0408012243.cbe32a7@posting.google.com> [snip..] > > > It looks like the CONNECT and GET requests are just implemented using > > simple socket commands. (I say simple because there isn't a lot of > > code - I'm not familiar with the actual behaviour of sockets, but it > > doesn't look too complicated). > > > > What I need to do is rewrite the soc.connect(host_port) line in the > > following example so that it connects *via* my proxy-server. (which it > > doesn't by default). > > > > I think the current format of host_port is a tuple : (host_domain, > > port_no) > > > > Below is a summary of the GET command (I've inlined all the method > > calls - this example starts from the do_GET method) : > > > > soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > > soc.connect(host_port) > > What is the value of host_port at this point? It *should* be the > address of your external access proxy, i.e. dav-serv:8080 > > > soc.send("%s %s %s\r\n" % ( > > self.command, > > urlparse.urlunparse(('', '', path, params, query, '')), > > self.request_version)) > > And you're not sending an absoluteURI: this should be amended to > contain the server details of the the server that is finally going to > service the request. For the python.org example above, this code would be > > soc.send("%s %s %s\r\n" % ( > self.command, > urlparse.urlunparse(('http', 'www.python.org:80', path, params, > query, '')), > self.request_version)) > > though of course, these values should be made available to you by > TinyHTTPProxy. Taking a brief look at the code, these values should > available through the variables "scm" and "netloc". So your outgoing > connection code from TinyHTTPProxy should look something like this > > soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > soc.connect( ('dav-serv', 8080) ) > soc.send("%s %s %s\r\n" % ( > self.command, > urlparse.urlunparse((scm, netloc, path, params, query, '')), > self.request_version)) > > HTH, Thanks to all of you who replied. I think I uderstand enough to have a go - I need to make the connection to the proxy and the request for the absolute URI. That at least gives me something to go at and it shouldn't be too hard. Many Thanks for your help. Fuzzyman http://www.voidspace.org.uk/atlantibots/pythonutils.html From dave at pythonapocrypha.com Mon Aug 30 10:31:20 2004 From: dave at pythonapocrypha.com (Dave Brueck) Date: Mon, 30 Aug 2004 08:31:20 -0600 Subject: use win32 COM in python In-Reply-To: References: Message-ID: <41333A38.5030104@pythonapocrypha.com> Lin Jingxian wrote: > hi, > I have a C++ implemented COM server that give out a method like: int > read(unsigned char* buf, int lenth), How can I use this method from python? > what is the signature? Have a look at ctypes and/or win32com - they allow you to use COM (in varying degrees) from Python, so what you're trying to do is probably possible. -Dave From wweston at att.net Thu Aug 19 11:46:12 2004 From: wweston at att.net (wes weston) Date: Thu, 19 Aug 2004 15:46:12 GMT Subject: newbie In-Reply-To: References: Message-ID: <8X3Vc.478164$Gx4.116973@bgtnsc04-news.ops.worldnet.att.net> JASON JESSO wrote: > I'm trying to add a mode to a mkdir program a got off > the python cookbook. > > The error I get is: > ./mkdir.py jason 0777 > Traceback (most recent call last): > File "./mkdir.py", line 31, in ? > _mkdir( sys.argv[1], sys.argv[2] ) > File "./mkdir.py", line 25, in _mkdir > os.mkdir( newdir, mode ) > TypeError: an integer is required > > When I convert the mode from a string to an octal with > oct(int(sys.argv[2])) the permissions are all screwed > up. > > Any help? > > #!/usr/bin/env python > > import sys, os > > def _mkdir( newdir, mode ): > """works the way a good mkdir should :) > - already exists, silently complete > - regular file in the way, raise an exception > - parent directory(ies) does not exist, make > them as well > """ > if os.path.isdir( newdir ): > pass > elif os.path.isfile( newdir ): > raise OSError("a file with the same name as > the desired " \ > "dir, '%s', already exists." % > newdir) > else: > head, tail = os.path.split( newdir ) > if head and not os.path.isdir( head ): > _mkdir( head, mode ) > > if tail: > if mode is None: > os.mkdir( newdir ) > else: > os.mkdir( newdir, mode ) > > if __name__ == '__main__' : > if len(sys.argv) < 3: > _mkdir( sys.argv[1], None ) > else: > _mkdir( sys.argv[1], sys.argv[2] ) > jason, Your first instinct in direct problems like this should be to get in the python interactive interpreter and play around. Python 2.3.3 (#1, Mar 11 2004, 22:02:41) [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-20)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> perm = "0777" >>> oct(int(perm)) '01411' >>> Note you still need to import. >>> print math.pi Traceback (most recent call last): File "", line 1, in ? NameError: name 'math' is not defined >>> import math >>> print math.pi 3.14159265359 >>> wes From anthonybaxter at gmail.com Thu Aug 26 03:43:35 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Thu, 26 Aug 2004 17:43:35 +1000 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> Message-ID: On Wed, 25 Aug 2004 07:20:17 -0400, Paul Morrow wrote: > Not exactly, but it would include defining those. One way to think > about metadata is that it includes all information *about* an object, > but no information *used by* the object. See, for me, metadata is data about an object that is defined explicitly as about the object. You can look at an object, and say "Aha! It supports __getitem__, __iter__ and __len__, and is therefore likely to be a sequence type object." This is not metadata - this is something you've determined by looking at the object. __getitem__ and friends *are* used by the object, and so can't be considered metadata. I'd even say that __metaclass__ is not metadata in any sense of the word, because it's *fundamental* to the class's workings. Something like Zope3's Interfaces, which allow you to specify the Interfaces that an object or class implements, are closer to metadata, but note that even there, we've gone from an initial API of: class Foo: __implements__ = ( IFoo, ) to class Foo: implements(IFoo) ... moving away from the double-under form to a more readable and useful form. The new form allows for far more powerful and useful behaviour, such as inheritence of interfaces from base classes. Twisted has also moved from using the former style to the latter. These are two _very_ large bodies of code, with a lot of very clueful people working on them - and they found that the magic double-under name was inferior to an explicit call syntax. > If we were to have a conversation about this conversation, then we would > be having a "meta-conversation." /metadata/ is data that describes > data. metadata for a function would be data that describes the > function; data *about* the function as opposed to data *used by* the > function. For example: > > def circumference(diameter): > """ This is a docstring. It's metadata for this function. """ > __author__ = 'Paul Morrow' # more metadata > pi = 3.14 # not metadata > return pi * diameter There are a small number of double-under names that are used for metadata - most of them are automatically inserted by Python automatically. The overwhelming number of double-under names are not metadata in any way. From xslom03 at vse.cz Wed Aug 18 02:23:41 2004 From: xslom03 at vse.cz (Martin Slouf) Date: Wed, 18 Aug 2004 08:23:41 +0200 Subject: 'ascii' codec can't encode character u'\xf3' In-Reply-To: <41224bc0$0$13029$9b622d9e@news.freenet.de> References: <4120F820.4000703@fusiondementes.com> <4121A8DA.30802@v.loewis.de> <41224bc0$0$13029$9b622d9e@news.freenet.de> Message-ID: <20040818062341.GB3482@barbucha.martin.net> ok, thanks for your time while answering my questions. my python is Python 2.3.3 (#1, May 1 2004, 16:13:07) [GCC 3.2.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.stdout.encoding 'ISO-8859-2' so im fine with it -- just a strange thing that it has used ascii, if sys default is ISO-8859-2. on the other hand: no matter now -- im 'overencoded' -- and i will explicitly call conversion function from now on in my python scripts (those are not programs :) to ensure myself everything is fine i see that the solution i came with was quite right, though i didnt much understand it. now i know how it works and im satisfied. thanks to all of you. martin. On Tue, Aug 17, 2004 at 08:17:41PM +0200, "Martin v. L?wis" wrote: > Martin Slouf wrote: > >>- print a repr() of the unicode object instead of > >> the unicode object itself. This will work on all > >> terminals, and show hex escapes of non-ASCII characters. > > > > > >just to make sure: > > > >override the object's __repr__(self) method to st. like: > > > >class my_string(string): > > def __repr__(self) > > tmp = unicode(self.attribute1 + " " + self.attribute2) > > return tmp > > > >and use 'my_string' class without any worries instead of classical > >string? > > No. Assume yyy is a Unicode object which potentially contains > non-printable characters. Instead of doing > > print yyy > > do > > print repr(yyy) > > >my system is debian GNU/Linux stable, im using it for a very, very long > >time, though i did not changed any terminal settings but the very > >basics. My locales are properly set, im using LC_* environment > >variables to set default locale to czech environment with ISO-8859-2 > >charset. Terminal is capable of displaying 8bit charsets, im not sure > >about unicode charsets -- never tried, never needed. > > I see. Could it be that you are using Python 2.1, then? Because in > Python 2.3, printing Czech characters to the terminal should work > just fine. Please do > > Python 2.3.4 (#2, Aug 5 2004, 09:33:45) > [GCC 3.3.4 (Debian 1:3.3.4-7)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import sys > >>> sys.stdout.encoding > 'ISO-8859-15' > > >if 0: > > # Enable to support locale aware default string encodings. > > import locale > > loc = locale.getdefaultlocale() > > if loc[1]: > > encoding = loc[1] > > > >so i guess it is never done :( > > You don't need to change the default encoding. Instead, > sys.stdout.encoding is used for printing to the terminal (in 2.3 and > later). > > >did you yourself changed it? > > No. It will work out of the box. > > >well, if a piece of information like you gave to me was contained in > >standard python documentation, probably there will be less > >misunderstanding about this issue. > > What piece specifically are you referring to? It is all mentioned > in the standard Python documentation. > > >#! /usr/bin/env python > ># -*- coding: UTF-8 -*- > >at the begginnig of my every script, the example above still has to > >be converted -- because of the iso-8859-1 you use in "L?wis"? > > Yes, and no. Yes, it still has to be converted. UTF-8 is *not* > Unicode; it is a byte encoding, and you cannot mix Unicode > strings and byte strings. No, if I use UTF-8 in my source code, > then "L?wis" will be encoded in UTF-8, not in ISO-8859-1. > > >can i ommit the conversion (ie. is it done automatically for me as if > >i write > >u"Martin v. " + unicode("L?wis", "ISO-8859-1") > >)? > > You can, but you shouldn't. So I won't tell you how you could do that. > > >dont understand -- which library? > > The ODBC library, for example, or PyQt. > > Regards, > Martin > -- > http://mail.python.org/mailman/listinfo/python-list From HOELTLNS01/HOELTL/DE%HOELTL at hoeltl.com Tue Aug 24 13:06:46 2004 From: HOELTLNS01/HOELTL/DE%HOELTL at hoeltl.com (HOELTLNS01/HOELTL/DE%HOELTL at hoeltl.com) Date: Tue, 24 Aug 2004 19:06:46 +0200 Subject: Bericht an Absender Message-ID: Ereignisinformation:- Datenbank: e:/lotus/domino/data/mail.box Urheber: python-list at python.org Empf?nger: franzberger at hoeltl.com Betreff: Mail Delivery (failure franzberger at hoeltl.com) Datum/Zeit: 24.08.2004 19:06:42 Die an franzberger at hoeltl.com gesendete Nachricht wurde isoliert, da sie gesperrten Inhalt enth?lt. Message sent to franzberger at hoeltl.com was quarantined because it contained banned content. Our email system does not accept the following attachment:BAS, BAT, CAB, COM, CMD, EXE, GIF, JS, MSI, PIF, SCR, VBE, VBS, WBS, WCS, WSF, WSH........... From xslom03 at vse.cz Tue Aug 17 02:17:45 2004 From: xslom03 at vse.cz (Martin Slouf) Date: Tue, 17 Aug 2004 08:17:45 +0200 Subject: 'ascii' codec can't encode character u'\xf3' In-Reply-To: <4120F820.4000703@fusiondementes.com> References: <4120F820.4000703@fusiondementes.com> Message-ID: <20040817061745.GA4259@barbucha.martin.net> i had similar errors: Traceback (most recent call last): File "/home/martin/skripty/accounts.py", line 125, in ? main(sys.argv) File "/home/martin/skripty/accounts.py", line 119, in main print_accounts(accounts, url_part) File "/home/martin/skripty/accounts.py", line 94, in print_accounts print str(i).encode("utf-8", "replace") UnicodeEncodeError: 'ascii' codec can't encode characters in position 151-152: ordinal not in range(128) - - - - the solution seems to be: 0. string is not in unicode encoding (assumption) 1. before printing out, convert the string to unicode 2. when printing, convert to whatever charset you like though i dont understand much why (ive solved it a minute ago :) the code should be: str = "any nonunicode string" print unicode(str).encode("iso-8859-2", "replace") comments: 1. why the string is not in unicode can have several reasons -- i guess: - does ogg stores tags in unicode? - you have parsed an xml file with encoding attribute set (that is what i do) - etc 2. "replace" parameter in encode causes non-printable chars to be replaced with '?' (you can use "ignore" or strict", see your python doc) 3. the above will work _only_ _if_ the 'str' encoding is "iso-8859-2" -- a funny thing -- first line of code converts from unknown (but the programmer must know it) to unicode and the second one converts it back from unicode to unknown (now the programmer tells that secret to python :) 4. i would like to know from any python expert whether/why/why not: * my assumptions are right * why is that behaviour? -- if you search google you get thousands of errors like this -- with no proper solutions i must add * is there an easier portable way (no sitecustomize.py changes) to do it * i was looking in site.py and there is deleted the sys.setdefaultencoding() function, but from the comments i do not know why -- you know it? why is user not allowed to change the default encoding? it seems reasonable to me if he/she could do that. thx. m. From deetsNOSPAM at web.de Wed Aug 25 09:08:10 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Wed, 25 Aug 2004 15:08:10 +0200 Subject: module functions list References: Message-ID: > sys.modules[__name__] Ahh, that did it. Thanks. So far I don't care for classes vs. functions, but the introspect tip will eventually come to use one day... -- Regards, Diez B. Roggisch From fumanchu at amor.org Mon Aug 23 14:07:45 2004 From: fumanchu at amor.org (Robert Brewer) Date: Mon, 23 Aug 2004 11:07:45 -0700 Subject: function taking scalar or list argument Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E45@exchange.hqamor.amorhq.net> beliavsky wrote: > I can define a function that transforms either a scalar or > each element in > a list as follows: > > def twice(x): > try: > return map(twice,x) > except: > return 2*x > > print twice(3) # 6 > print twice([1,4,9]) # [2,8,18] > > Is this good style? If you mention that behavior in a docstring, it's acceptable. Robert Brewer MIS Amor Ministries fumanchu at amor.org From grante at visi.com Mon Aug 30 17:50:41 2004 From: grante at visi.com (Grant Edwards) Date: 30 Aug 2004 21:50:41 GMT Subject: Size of a remote URL References: <4133a024$0$8090$a1866201@newsreader.visi.com> Message-ID: <4133a131$0$8090$a1866201@newsreader.visi.com> On 2004-08-30, Grant Edwards wrote: > On 2004-08-30, Justin wrote: > > [...] > > Here's one of your problems: And here are the solutions to several of your other problems: http://www.catb.org/~esr/faqs/smart-questions.html -- Grant Edwards grante Yow! Is this "BOOZE"? at visi.com From fumanchu at amor.org Mon Aug 23 18:11:35 2004 From: fumanchu at amor.org (Robert Brewer) Date: Mon, 23 Aug 2004 15:11:35 -0700 Subject: key words instead of predef Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E4A@exchange.hqamor.amorhq.net> I wrote: > I expect to add another paragraph or two based on alternate keywords > which people support (vocally *and* technically). I would say > all of the "*def" candidates could work. In the interest of > generating more content for that paragraph ;) here's the devil's > advocate view of predef: > > 1) It's not a word. But then "def" isn't either. > 2) If it is a word, it's a verb. Dependent suite keywords tend to be > adverbial. Perhaps there's a more adverbial word which means, "set up > these items for later processing". Unfortunately for English, > this form > of "predef" would be "predefining". Some synonym of > "prepare", perhaps? > > I'll think about it some more. How about "fix"? From OneLook (serious connotations): verb: make ready or suitable or equip in advance for a particular purpose or for some use, event, etc (Example: "I was fixing to leave town after I paid the hotel bill") verb: set or place definitely (Example: "Let's fix the date for the party!") verb: make fixed, stable or stationary (Example: "Let's fix the picture to the frame") verb: cause to be firmly attached (Example: "She fixed her gaze on the man") verb: put (something somewhere) firmly (Example: "Fix your eyes on this spot") noun: the act of putting something in working order again verb: restore by replacing a part or putting together what is torn or broken verb: decide upon or fix definitely (Example: "Fix the variables") and now the hilarious connotations (: noun: an exemption granted after influence (e.g., money) is brought to bear (Example: "Collusion resulted in tax fixes for gamblers") noun: something craved, especially an intravenous injection of a narcotic drug (Example: "She needed a fix of chocolate") noun: informal terms for a difficult situation (Example: "He got into a terrible fix") verb: kill, preserve, and harden (tissue) in order to prepare for microscopic study verb: take vengeance on or get even (Example: "That'll fix him good!") verb: make infertile roflmao, Robert Brewer MIS Amor Ministries fumanchu at amor.org From tchur at optushome.com.au Sun Aug 22 15:51:12 2004 From: tchur at optushome.com.au (Tim Churches) Date: 23 Aug 2004 05:51:12 +1000 Subject: Python future performance and speed In-Reply-To: References: <278de0e.0408211605.426e5129@posting.google.com> <7x4qmv6cwo.fsf@ruckus.brouhaha.com> Message-ID: <1093204272.1267.21.camel@emilio> On Mon, 2004-08-23 at 00:24, Roy Smith wrote: > Tim Churches wrote: > > As a population health epidemiologist whose stock-in-trade is > > manipulation and analysis of large health data sets, I have to say that > > Python's run-time speed is almost always much faster than I would have > > expected from such a dynamic language, but also almost always much > > slower than I would like, especially when compared to widely-used (but > > vastly expensive and sprawling) data manipulation environments such as > > SAS system (see http://www.sas.com) which is the "industry standard" in > > my particular field. > > It should not be surprising at all that a general-purpose tool will be > beaten by a domain-specific tool in that domain. SAS, as you say, is > designed to munch huge numeric data sets. That is its only reason for > existing, and it's got 20 or 30 years of development effort behind it to > make it do that one task as fast as possible. Sure, and as a programming environment SAS is both primitive (eg still has no way to easily create user-defined functions in its main language, and is forced to rely on macros instead) and confusing (since it needs five or six distinct sub-languages to cope with both special-purpose and general-purpose programming tasks eg uses Java called from its own PL/1 and Fortran-influenced "data step" language to do many things - yuck!) when compared to Python. However, none of that is a reason for not to wish that Python were faster than it is in some circumstances - mostly when doing dumb stuff like iterating over a file. That's why Psyco and increasingly Pyrex are so valuable, and why the fruits of the Starkiller and Pypy projects are so eagerly anticipated. -- Tim C PGP/GnuPG Key 1024D/EAF993D0 available from keyservers everywhere or at http://members.optushome.com.au/tchur/pubkey.asc Key fingerprint = 8C22 BF76 33BA B3B5 1D5B EB37 7891 46A9 EAF9 93D0 From paddy3118 at netscape.net Sun Aug 22 01:41:18 2004 From: paddy3118 at netscape.net (Paddy McCarthy) Date: 21 Aug 2004 22:41:18 -0700 Subject: Parsing C header files with python References: <873c2gzftf.fsf@emit.demon.co.uk> Message-ID: <2ae25c6b.0408212141.42f85717@posting.google.com> Ian McConnell wrote in message news:<873c2gzftf.fsf at emit.demon.co.uk>... > I've got a header file which lists a whole load of C functions of the form > > int func1(float *arr, int len, double arg1); > int func2(float **arr, float *arr2, int len, double arg1, double arg2); > > It's a numerical library so all functions return an int and accept varying > combinations of float pointers, ints and doubles. > > What's the easiest way breaking down this header file into a list of > functions and their argument using python? Is there something that will > parse this (Perhaps a protoize.py) ? I don't want (or understand!) a full C > parser, just this simple case. > <> > > Thanks, > Ian Would this suffice: >>> import re >>> import pprint >>> hdr=''' int func1(float *arr, int len, double arg1); int func2(float **arr, float *arr2, int len, double arg1, double arg2); ''' >>> print hdr int func1(float *arr, int len, double arg1); int func2(float **arr, float *arr2, int len, double arg1, double arg2); >>> func2args = {} >>> for line in hdr.split('\n'): line = [word for word in re.split(r'[\s,;()]+', line) if word] if len(line)>2:func2args[line[1]] = line[2:] >>> pprint.pprint(func2args) {'func1': ['float', '*arr', 'int', 'len', 'double', 'arg1'], 'func2': ['float', '**arr', 'float', '*arr2', 'int', 'len', 'double', 'arg1', 'double', 'arg2']} >>> From adurdin at gmail.com Fri Aug 27 23:38:26 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Sat, 28 Aug 2004 13:38:26 +1000 Subject: Iteration over Lists and Strings In-Reply-To: References: Message-ID: <59e9fd3a04082720387bebee63@mail.gmail.com> On Sat, 28 Aug 2004 03:22:48 GMT, DeepBleu wrote: > What is going on? Can someone clarify this to me? And how can I ensure > that the iteration produces the absolute index number **without** doing > something like: > >>a = 'abba' > >>k = len(a) > >>for m in range(0, k): > >> print a[m], m The index() method looks up the first index of the given object in the list/sequence. What you want is to use the enumerate() builtin: >>>a = 'abba' >>>for i, c in enumerate(a): ... print c, i ... a 0 b 1 b 2 a 3 From ben at benlast.com Sat Aug 21 05:47:18 2004 From: ben at benlast.com (Ben Last) Date: Sat, 21 Aug 2004 10:47:18 +0100 Subject: Why are strings immutable? In-Reply-To: Message-ID: > From: Brent W. Hughes > I kind of hate to have to convert a string into a list, manipulate it, and > then convert it back into a string. Why not make strings mutable? There are a whole host of good reasons, mostly to do with the way data types are seen from a Python point of view. However, if you're converting strings to lists and back, you're probably using recipes from another language (such as C, perhaps?) where there are more Pythonesque equivalents. Take a look at all the string methods for starters; they operate on the contents of a string and return the modified result. It's common to stack them up, as in: myString.strip().lower().split() It's sometimes useful to remember that you can iterate over a string character by characters (technically, in substrings one character long): >>>for x in "abc": ... print x a b c What is it you're trying to do? b From kveretennicov at yahoo.com Mon Aug 16 14:08:16 2004 From: kveretennicov at yahoo.com (Konstantin Veretennicov) Date: 16 Aug 2004 11:08:16 -0700 Subject: Best programming language References: Message-ID: <5155aad2.0408161008.40c57262@posting.google.com> Roman Suzi wrote in message news:... > ;-) > > Just type into google > "best programming language" > and press (I am lucky) > > > Sincerely yours, Roman Suzi Just type in "programming language" and look at #1 ;-) - kv From ramen at lackingtalent.com Fri Aug 27 17:31:31 2004 From: ramen at lackingtalent.com (Dave Benjamin) Date: Fri, 27 Aug 2004 21:31:31 -0000 Subject: Alex Martelli: Welcome back! References: Message-ID: In article , Michael Sparks wrote: > On Fri, 27 Aug 2004, Dave Benjamin wrote: > >> It's nice to see you around here again! > > It certainly is - and back with a BANG :-) Yeah, no doubt. =) -- .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:. "talking about music is like dancing about architecture." From paul at boddie.org.uk Tue Aug 17 06:32:06 2004 From: paul at boddie.org.uk (Paul Boddie) Date: 17 Aug 2004 03:32:06 -0700 Subject: music resources References: Message-ID: <5339b60d.0408170232.38465612@posting.google.com> "Elaine Jackson" wrote in message news:... > Is there such a thing as an executable language for music? If not, why not? > And if yes, where can I find it? Naturally the ideal thing would be if such a > language were implemented within python, but I would be willing to learn a > lesser programming language if I had a reasonable assurance that it had what > I'm looking for. I have, of course, googled for a solution, and I may have > even found it, but if so I didn't recognize it as such. Any pointers will be > mucho appreciado. Once upon a time there was a programming language called AMPLE, which supposedly resembled Forth or was at least a stack-oriented language, that could be used to compose music with certain 8-bit hardware. I searched for "AMPLE music composition" on Google and found this link: http://www.colinfraser.com/m5000/m5000.htm I can imagine that Python together with the Python Midi Package... http://www.mxm.dk/products/public/pythonmidi ...could be used to produce similar kinds of compositions. The most significant issues for me are generally related to getting my sound system to function in a decent fashion, but it would be interesting to look at this in more depth. Paul From donnal at donnal.net Mon Aug 23 13:39:47 2004 From: donnal at donnal.net (Donnal Walter) Date: Mon, 23 Aug 2004 12:39:47 -0500 Subject: telnet 'connection reset by peer' In-Reply-To: References: Message-ID: Eddie Corns wrote: > Donnal Walter writes: > > >>On Windows XP I am able to connect to a remote telnet server from the >>command prompt using: > > >>telnet nnn.nnn.nnn.nnn 23 > > >>where nnn.nnn.nnn.nnn is the IP address of the host. But using >>telnetlib, this code returns the traceback that follows: > > >>import telnetlib >>host = 'nnn.nnn.nnn.nnn' >>tn = telnetlib.Telnet(host, 23) >>tn.read_until("Enter device name?") > > > >>Traceback (most recent call last): >> File "C:\Python23\Lib\site-packages\mindwrapper\test\telnet.py", line >>4, in ? >> tn.read_until("Enter device name?") >> File "C:\Python23\lib\telnetlib.py", line 316, in read_until >> self.fill_rawq() >> File "C:\Python23\lib\telnetlib.py", line 521, in fill_rawq >> buf = self.sock.recv(50) >>socket.error: (10054, 'Connection reset by peer') > > >>Is there some parameter that I need to set in order to connect using the >>telnetlib client? Thanks. > > > No, that should work, to a reasonably conforming telnet server. Try doing > tn.set_debuglevel(2) before the read_until() to see what's coming back. Telnet(nnn.nn.nnn.nnn,23): recv '\xff\xfb\x03\xff\xfd\x03\xff\xfb\x01\xff\xfd\x1 7\xff\xfb\x00\xff\xfd\x00' Telnet(nnn.nn.nnn.nnn,23): IAC WILL 3 Telnet(nnn.nn.nnn.nnn,23): IAC DO 3 Telnet(nnn.nn.nnn.nnn,23): IAC WILL 1 Telnet(nnn.nn.nnn.nnn,23): IAC DO 23 Telnet(nnn.nn.nnn.nnn,23): IAC WILL 0 Telnet(nnn.nn.nnn.nnn,23): IAC DO 0 Traceback (most recent call last): File "C:\Python23\Lib\site-packages\mindwrapper\test\telnet.py", line 5, in ? tn.read_until("Enter device name?") File "C:\Python23\lib\telnetlib.py", line 316, in read_until self.fill_rawq() File "C:\Python23\lib\telnetlib.py", line 521, in fill_rawq buf = self.sock.recv(50) socket.error: (10054, 'Connection reset by peer') Thank you for the suggestion. Can you help me interpret the feedback? > Does it happen instantly or is something timing out? No, it always happens instantly. Thanks. Donnal Walter Arkansas Children's Hospital From jeff_news at lindholm.org Tue Aug 24 14:17:26 2004 From: jeff_news at lindholm.org (Jeff Lindholm) Date: Tue, 24 Aug 2004 18:17:26 GMT Subject: Time-date as an integer References: Message-ID: import datetime; def calcNodeId(self): t = datetime.utcnow() val = ( (t.toordinal() * 24 * 60 * 60) + (t.hour * 60 * 60) + (t.minute * 60) + t.second ) * 1000000 if val <= self._dTime: val = self._dTime + 1 self._dTime = val return val This should hadle your leap years. You will of course loose leap seconds, but I honestly not sure where you get those..... "Charles Hixson" wrote in message news:mailman.2271.1093328889.5135.python-list at python.org... > This is a concept, not a finished program, and an extract from a class at > that...so forgive any illegalities, but: > import datetime; > def calcNodeId(self): > t = datetime.utcnow() > val = t.year * 133920000000 + # 12 months > t.month * 11160000000 + # 31 days > t.hour * 3600000000 + # 60 minutes > t.minute * 60000000 + # 60 seconds > t.second * 1000000 + t.microsecond > if val <= self._dTime: > val = self._dTime + 1 > self._dTime = val > return val > > This is the best that I've been able to come up with in getting a > date-time as an integer. It feels like one of the time or date libraries > should have a better solution, but if so, I haven't found it. Can anyone > suggest a better approach? From theller at python.net Fri Aug 27 10:38:07 2004 From: theller at python.net (Thomas Heller) Date: Fri, 27 Aug 2004 16:38:07 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> Message-ID: Aaron Bingham writes: > Wolfram Kraus wrote: > >> Kjetil Torgrim Homme wrote: >> [...] >> >>> how can Emacs tell? if I press TAB and thus ask Emacs to re-indent >>> the line, that's what it will do. arguably, the correct fix is to >>> disable the "clever" re-indentation code of Emacs since it's too easy >>> to fool it, but this makes coding more awkward in other cases. it >>> also doesn't solve cut-n-paste errors. >> >> You can use C-c < or C-c > in Emacs to (de-)indent regions. > > Or C-M-\ to re-indent the region "correctly" with respect to its > context. This works far more reliably the using TAB to re-indent > single lines. How do you enter that on a german keyboard? Thomas From aleaxit at yahoo.com Sat Aug 28 12:05:23 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 28 Aug 2004 18:05:23 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1ry8k0d2az.fsf@rovereto.ifi.uio.no> <87acwgvy51.fsf@sinken.local.csis.hku.hk> <2pb36dFibuj3U1@uni-berlin.de> <41309d32$0$65611$a1866201@newsreader.visi.com> Message-ID: <1gj8pg5.1e6z0kiprvfxuN%aleaxit@yahoo.com> Grant Edwards wrote: ... > IMO, the only non-ugly, non-hack solution would be to have > another set of delimters that are used as tuple-constructors so > tha the syntax for a literal tuple, a literal list, and a > literal dictionary are consistent. I think that a hypothetical greenfield-designed language similar to Python might do without literal tuples, lists, and dictionaries, just like Python today does without literal sets (in 2.4 where they're a built-in type). It would make some constructs more verbose, specifically using words instead of punctuation, but I think that, overall, that is reasonably Pythonic. list(a, b, c) instead of [a, b, c] would not be horribly heavy syntax, I think. You can already use list() instead of [] -- just as dict() instead of {} -- and I think sometimes that's more readable, even having both choices. tuple would work like list. dict isn't quite so obvious, except where the keys are constant strings that happen to be identifiers in which case, even today, dict(a=1,b=2,c=3) is fine. But I'm sure fine solutions could be identified, as, also, for the issue of how to differentiate from list(x) meaning [x] and list(x) meaning the same as [foo for foo in x] -- for example list(*x) would also mean the latter, so maybe that's the solution for this. I think 'commas makes tuples when the commas don't mean anything else' should stay, though, because somedict[x, y] or a,b=b,a depend on that, and I find them just too sweet to lose!-) This of course is all pretty hypothetical, just like the idea of introducing a new set of delimiters -- won't happen in Python, not even in 3.0. Just musing about some details of language design. Alex From 510046470588-0001 at t-online.de Wed Aug 18 11:09:57 2004 From: 510046470588-0001 at t-online.de (510046470588-0001 at t-online.de) Date: 18 Aug 2004 17:09:57 +0200 Subject: How big can a Python program be? References: <903b3fba.0408170333.49ce3944@posting.google.com> <412204d5$1$28243$afc38c87@news.easynet.co.uk> <903b3fba.0408180619.4d41027e@posting.google.com> Message-ID: <874qn01nzu.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> vronskij at post.sk writes: > No way. This was just another question. One programmer told me that > he > can roughly handle max 10 000 lines in C language. I was curious > about Python. I always hear that Python can be used on larger projects > than e.j. PERL because it is Object Oriented and cleanly designed. > What is a larger project? Mumbers revail more. > in scheme I may handle 1000 times more code than in any infix language Klaus Schilling From antispam Mon Aug 30 21:08:06 2004 From: antispam (Andrew) Date: Mon, 30 Aug 2004 18:08:06 -0700 Subject: Disabling Javascript and Other Features Message-ID: <10j7jrqp25n9s78@corp.supernews.com> Hi I would like to build an application that will let me turn off and on all javascript and other features in my Internet Explorer web browser I understand this would probably be done by manipulating the registery is this correct If so what registery entries would I have to look at or is there another way and would I be using the winreg module to do this or is there others that I would need sorry not really 100% python question so any help is appreciated Cheers Andrew From sharidas at zeomega.com Fri Aug 13 01:46:21 2004 From: sharidas at zeomega.com (Satchidanand Haridas) Date: Fri, 13 Aug 2004 11:16:21 +0530 Subject: while and if In-Reply-To: References: Message-ID: <411C55AD.8030100@zeomega.com> Calvin79 wrote: >Hi Satchit, > >Can I also ask how could I stop two of the same letters being given i.e. >aa or dd and also how would I stop the same letter being repeated with >only one space between i.e. a b a or c a c > >Thanks, > >Calvin > > > Hi, You will have to maintain the previous two states to prevent the letters repeating within the next two choices. The code below will do something like that. I don't know if it is the best solution: import random things = xrange(int(raw_input("choose no of things (1-8)? "))) state = [None,None] for x in things: tmp = random.choice('abcd') print state while tmp in state[0:2]: tmp = random.choice('abcd') print "choice ",x+1," is ", tmp state[x%2] = tmp Regards, Satchit From jeff at ccvcorp.com Fri Aug 6 22:46:23 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 06 Aug 2004 19:46:23 -0700 Subject: Logging with multiple loggers/handlers In-Reply-To: <2e37dc1.0408060108.3f3a27dd@posting.google.com> References: <10em3kass56nq9b@corp.supernews.com> <10ep21af0c9kv4c@corp.supernews.com> <2e37dc1.0408060108.3f3a27dd@posting.google.com> Message-ID: <10h8gj0jdh55q50@corp.supernews.com> Vinay Sajip wrote: >>While it's fairly likely that my interpretation of the docs is not >>something that many people will come up with, I think it might be >>worthwhile to expand the example sections to actually show how to use >>multiple heirarchical loggers. Had there been an example to follow, I >>certainly wouldn't have made this mistake. >> >> > >The example in http://www.red-dove.com/python_logging.html#config does >show in bold the items used by the configuration API, and says that >the others are just used by the GUI configurator. Perhaps "channel" >was the wrong name to use for a private element in the configurator, >but it's done now. > > May I suggest changing the wording of the getLogger() docs? I think that simply adding a few words to a single sentence will clarify things considerably. - Here, "name" is synonymous with "channel name". + Here, "name" is synonymous with "fully qualified channel name". Jeff Shannon Technician/Programmer Credit International From vijay_srr at yahoo.com Mon Aug 30 02:46:08 2004 From: vijay_srr at yahoo.com (Vijay Sankar) Date: Mon, 30 Aug 2004 12:16:08 +0530 Subject: Problems running coverage.py Message-ID: Hi, I am using coverage.py to check the code coverage for some of my Python scripts. For a particular script which uses 'exit' calls, I am getting the following error when I invoke the script with the -x option for coverage. Error in sys.exitfunc: Traceback (most recent call last): File "D:\Python23\lib\atexit.py", line 20, in _run_exitfuncs func(*targs, **kargs) File "D:\Python23\Lib\site-packages\coverage.py", line 207, in save cache = open(self.cache, 'wb') TypeError: an integer is required Looks like coverage.py is not able to record the coverage data on calling exit. Does anybody know how to solve this? Thanks, Vijay From agriff at tin.it Sat Aug 21 10:03:56 2004 From: agriff at tin.it (Andrea Griffini) Date: Sat, 21 Aug 2004 14:03:56 GMT Subject: My only complaint about Python References: <874qmxj81k.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Message-ID: <3flei0t87s2qpsunb94mrbfb5fc4nplnsl@4ax.com> On 21 Aug 2004 08:53:59 +0200, 510046470588-0001 at t-online.de wrote: >> They do. MSC/C++ is now available at NO cost: >> > >no cost is not the same as free Do you mean that there are limitations about legal use of VC toolkit 2003 for building a python interpreter or that you actually need to see the source code of the C compiler to build python ? Andrea From rattan at cps.cmich.edu Thu Aug 26 01:23:46 2004 From: rattan at cps.cmich.edu (Ishwar Rattan) Date: 25 Aug 2004 22:23:46 -0700 Subject: Proposal for removing self References: Message-ID: <938a4680.0408252123.4d71432e@posting.google.com> "Brett C." wrote in message news:... > No thanks. This is a common suggestion and Guido has said it ain't > going to happen. I personally like 'self' a lot because ambiguity from > reading code goes away. It is easy to not see a '.' but not so for > 'self.' . It also makes teaching OOP to people much easier since you > don't need to explain why some variables and method calls are to the > instance but other are not. "Explicit is better than implicit". I concur for keeping self intact, it does provide clarity in code writing and reading. -ishwar From sakesun at boonthavorn.com Thu Aug 19 22:43:29 2004 From: sakesun at boonthavorn.com (Sakesun Roykiattisak) Date: Fri, 20 Aug 2004 09:43:29 +0700 Subject: age of Python programmers In-Reply-To: <20040819231139.D039A1E4003@bag.python.org> References: <20040819231139.D039A1E4003@bag.python.org> Message-ID: <41256551.7040301@boonthavorn.com> I'm 28. Have been using python for just one year. I was first introduced to programming when I'm in 11 with 6502 machine (Apple II and Oric-I) So far I have 2 epiphany in my programming life. The first time is when I finished chapther 3 of the Design Patterns book. The second time is when I finished my first non-trivial python program. BTW, The histrogram suggest that python is not being used as the first programming language as much as it should be. > > I spotted some errors in your list, added new entries, and made a > histogram: http://roelschroeven.net/pythonages/ > From jbperez808 at wahoo.com Fri Aug 6 22:58:09 2004 From: jbperez808 at wahoo.com (Jon Perez) Date: Sat, 07 Aug 2004 10:58:09 +0800 Subject: threads: not locking read-only objects In-Reply-To: References: <2ni4b4F16u92U1@uni-berlin.de> Message-ID: <2niuanF1ee0tU1@uni-berlin.de> Hmmm... here's what's going on. I have a dictionary of logged in users called 'whoison' that's updated in the main thread (and only in the main thread) with a: whoison['username']="timeoflogin" # to add someone new and del whoison['username'] # to remove someone who's logged out Do the above count as atomic? The worker threads do the following read-only operation: for x in whoison: print x,whoison[x] Looking at the read-only code though I just realized something.... if a dictionary entry in 'whoison' is deleted by the main thread while the 'for x in whoison' is executing then what would happen? Looks like I'm going to need a lock after all even for the read-only operations...? Christopher T King wrote: > On Sat, 7 Aug 2004, Jon Perez wrote: > > >>Is it safe to not put a lock on an object if it will always >>be read-only in other threads and will only ever be written to >>in just one and always the same one thread? > > > Only if the writes are guaranteed to be atomic: if the object is ever > temporarily left in an inconsistent state by the writer (due to a thread > switch), the readers will read inconsistent data. If you are sure this > can't happen, then yes, doing so is safe. > From glc at well.com Sun Aug 15 09:44:13 2004 From: glc at well.com (Greg Chapman) Date: Sun, 15 Aug 2004 13:44:13 GMT Subject: Problems with PyGILState_Ensure () and PyGILState_Release () References: Message-ID: <5upuh0hivs0mfg2bu6ceu73o9jsivuql2i@4ax.com> On Fri, 13 Aug 2004 13:49:09 +0200, "Mathias Mamsch" wrote: >Hi all, > >i am writing a python extension in c++. In the extension a c++ thread >calls back into python. I did it like this: > >---- c++ code ---- >PyGILState_STATE gstate; >gstate = PyGILState_Ensure (); > >... do some work ... >// call the python callback (Func) >result = PyEval_CallObject(Func, arglist); >... so some cleanup ... > >PyGILState_Release (gstate); >return >----------------- > >the callback is executed properly, but the PyGILState_Release gives me the >following error: >"Fatal Python error: PyThreadState_Delete: tstate is still current" > >What can be wrong here? Any suggestions? >In my understanding this error should not occur ... Is this a known bug >maybe? I am using Python 2.4a1 under windows. > >Thanks in advance, Mathias Mamsch > > Looking at the code for PyGILState_Release (in pystate.c), it looks like what must be happening is a disagreement between tcur->gilstate_counter and oldstate (tcur is the current thread state and oldstate is the parameter passed in). Specifically, you appear to be passing in something other than PyGILState_UNLOCKED (so PyEval_ReleaseThread is not called, leaving tcur as still the current thread), but tcur->gilstate_counter is decremented to 0, causing the attempt to free tcur. So it looks like the cause could be either 1) something writing to gstate (in your code above) between the calls to PyGILState_Ensure and PyGILState_Release, or 2) something making an extra call to PyGILState_Release (i.e., one not matched by a call to PyGILState_Ensure). Could your code be doing either of those things? --- Greg Chapman From nav+posts at bandersnatch.org Wed Aug 4 15:35:35 2004 From: nav+posts at bandersnatch.org (Nick Vargish) Date: 04 Aug 2004 15:35:35 -0400 Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) References: <10h24oace15n97a@news.supernews.com> Message-ID: Ville Vainio writes: > This syntax is out there with backticks and print>>. I agree. I just don't know where else to voice my opinion on this matter, but I absolutely hate the new decorator syntax. Sorry, I just had to get that off my chest. Nick -- # sigmask || 0.2 || 20030107 || public domain || feed this to a python print reduce(lambda x,y:x+chr(ord(y)-1),' Ojdl!Wbshjti!=obwAcboefstobudi/psh?') From claird at lairds.us Sun Aug 22 15:08:03 2004 From: claird at lairds.us (Cameron Laird) Date: Sun, 22 Aug 2004 19:08:03 GMT Subject: 100 % portable ? References: Message-ID: In article , Sridhar R wrote: . . . >Tk looks ugly in linux. Gtk is also good, but rendering is sluggish in . . . Yes and no. Default Tk settings look Motify, which is indeed old- fashioned. However, there are several initializations running around to make Linux Tk look, among other things, like Windows; I gather many people like that look. From ptmcg at austin.rr._bogus_.com Mon Aug 23 10:38:41 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 23 Aug 2004 14:38:41 GMT Subject: J2 paper 0.2.1 References: Message-ID: Beautiful work - where do I sign? (as a supporter, of course) -- Paul From nhodgson at bigpond.net.au Thu Aug 26 19:56:30 2004 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Thu, 26 Aug 2004 23:56:30 GMT Subject: Call for signatories for J2 References: Message-ID: Robert Brewer: > Isn't *anyone* going to vote against? Or at least formally abstain? > _Somebody_ out there must disagree strongly with this. I suppose I should abstain since I haven't been able to generate enough enthusiasm for or against J2. I have opinions about the option but they haven't really coalesced into a position. My preference was for list before def due to its familiarity from IDL but have some appreciation for other options. Neil From peter at engcorp.com Thu Aug 19 15:37:46 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 19 Aug 2004 15:37:46 -0400 Subject: Py2Exe PROBLEM In-Reply-To: <81a41dd.0408191109.1fc98889@posting.google.com> References: <81a41dd.0408190023.44d34c44@posting.google.com> <2tGdncgUvpKRD7ncRVn-oQ@powergate.ca> <81a41dd.0408191109.1fc98889@posting.google.com> Message-ID: <-MOdnSCcH4eNnLjcRVn-vg@powergate.ca> Lad wrote: > Peter Hansen wrote in message news:<2tGdncgUvpKRD7ncRVn-oQ at powergate.ca>... >>Also please explain what "blackbox" and "timing" are, if >>they are part of the problem. >> > Yes, I changed import rgs.py to import rgs but I still receive > >>The following modules appear to be missing > >>>['blackbox', 'timing', 'rgs.py'] Again, what are "blackbox" and "timing"? Just two modules which rgs.py imports, or something else entirely? > When I try to start the exe file I get > > Traceback (most recent call last): > File "rgs.pyc", line 561, in OnFileHistory > > File "pickle.pyc", line 1390, in load > File "pickle.pyc", line 872, in load > File "pickle.pyc", line 985, in load_string > LookupError: unknown encoding: string-escape > > Can you please help again? Somebody will generally help, whether me or others... The above actually looks like you might not be using the right version of something. Try running the same version of python that you used to generate the py2exe'd file and type the following in it: >>> r'tes\t'.decode('string-escape') (Yes, just as I did there... complete with r and \t ) Does it give the same error? If it does, then you probably don't have Python 2.3 installed... In any case, if you can't figure it out, post the version of Python and py2exe that you are using. Also make sure you have fully tested the application *before* running py2exe on it, so you'll know whether the problem involves py2exe or not. Note that based on what you are showing, there is now nothing wrong with your py2exe setup: it generated a .exe and you can run it. The fact that it is failing points to a different problem, not py2exe. -Peter From robhboyd at yahoo.com Wed Aug 18 12:27:55 2004 From: robhboyd at yahoo.com (Robert Boyd) Date: Wed, 18 Aug 2004 09:27:55 -0700 (PDT) Subject: age of Python programmers In-Reply-To: Message-ID: <20040818162755.54502.qmail@web14102.mail.yahoo.com> 40. But I'm a late-comer to programming (my 'back in the day' can't compete with other 40 yo programmers). So maybe I could say I'm more like 25. ;) --- Lucas Raab wrote: > One thing I've always kind of wondered is what is > the average age of a > Python programmer?? What age groups use Python?? > Something to think > about.... > > > -- > http://mail.python.org/mailman/listinfo/python-list > __________________________________ Do you Yahoo!? Yahoo! Mail - 50x more storage than other providers! http://promotions.yahoo.com/new_mail From DesertLinux at netscape.net Tue Aug 24 20:35:57 2004 From: DesertLinux at netscape.net (Byron) Date: Wed, 25 Aug 2004 00:35:57 GMT Subject: Book Recommendation In-Reply-To: References: Message-ID: Darren Kirby wrote: > I have found that "How to Think like a Computer Scientist: Python" > (http://ibiblio.org/obp/thinkCS/python/english/) is a very good resource. The > book tries to explain basic programming concepts common to all languages > using Python. "How to Think like a Computer Scientist: Python Programming" is an excellent, FREE book and I would highly that you check it out. I learned Python this way and would sincerely recommend that you check it out also. You can download it for free at: http://www.greenteapress.com Byron --- From rogerb at rogerbinns.com Wed Aug 25 18:55:57 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Wed, 25 Aug 2004 15:55:57 -0700 Subject: Proposal for removing self References: Message-ID: Brent W. Hughes wrote: > When doing object-oriented stuff, it bothers me to have to type > "self" so many times. I propose that Python allow the programmer to > optionally type ".variable" instead of "self.variable" to mean the > same thing. Of course, the interpreter would have to be more careful > about detecting floats that begin with just a period as in ".5". > What are your thoughts? When I started doing Python, it annoyed me. Now many years later I definitely wouldn't change it. Guido has very good taste! Roger From tjreedy at udel.edu Fri Aug 13 16:32:24 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 13 Aug 2004 16:32:24 -0400 Subject: secret message hidden in an image References: <411cd06a$0$3888$4d4ebb8e@news.nl.uu.net> Message-ID: "Guyon Mor?e" wrote in message news:411cd06a$0$3888$4d4ebb8e at news.nl.uu.net... > hi, i wrote a little script which can 'hide' a piece of text in an image > using python and PIL > > i wrote about it on my blog, if you like to read it go to: > > http://gumuz.looze.net/blogger/2004/08/message-in-image.html For those who don't know, this is called steganography. An interesting challenge is to embed a message in a way that is both hard to detect and that survives lossy compression, as with .jpgs. Terry J. Reedy From tdelaney at avaya.com Tue Aug 10 18:24:35 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Wed, 11 Aug 2004 08:24:35 +1000 Subject: Multiple inheritance with a common base class Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01CF3F82@au3010avexu1.global.avaya.com> Markus Bertheau wrote: >> Using super will ensure that you get a reliable chain of method >> calls. In this case it means that Multi.__init__ calls >> LeafA.__init__ which calls LeafB.__init__ which then calls >> CommonBase.__init__. Note that LeafA propogates the call to LeafB >> even though LeafA has no knowledge of the existence of LeafB. > > That is what I needed to know. Thanks. It should probably be noted in > the paragraph about multiple inheritance. You may also wish to look at my "improved autosuper" recipe in the cookbook. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286195 I've actually got a Pyrex version as well now that's about twice as fast - I really need to put this somewhere for download ... Tim Delaney From roy at panix.com Fri Aug 13 11:47:07 2004 From: roy at panix.com (Roy Smith) Date: Fri, 13 Aug 2004 11:47:07 -0400 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: In article , Dennis Lee Bieber wrote: > On 13 Aug 2004 07:15:14 -0700, beliavsky at aol.com declaimed the following > in comp.lang.python: > > > One of the most commmon reasons programmers cite for not trying Python > > is that indentation determines the program flow -- they think its > > weird. I think programmers who actually try Python adapt quickly and > > do not find the indentation rules to be a problem. > > > Teach them FORTRAN-IV... > > A source line is limited to 80 characters > Statements start in column 7 > Statements end in column 72 (or was it 71) > Columns 73 (72) through 80 can be used for an option sequence > number > If a statement is too long for one line, you put a continuation > mark character (any character can be used) in column 6 of the next line, > then continue with the statement > Put a "C" in column 1 to start a comment line In some versions, a "D" in column 1 indicated a debug line, which was conditionally included depending on some external compile flag. But, you have to remember that in those days, CPU time was an expensive and scarce resource, and languages were designed to be easy for the computer to process. The thought of making the machine do something that a person could do themselves was absurd. From bh at intevation.de Sat Aug 21 12:44:10 2004 From: bh at intevation.de (Bernhard Herzog) Date: Sat, 21 Aug 2004 18:44:10 +0200 Subject: Fate of lambda, Functional Programming in Python... References: <412636D1.6070808@noaa.gov> <41265E67.A08409A6@juno.com> Message-ID: Jeff Sandys writes: > How about this use of lambda? > (from another post 'RE: How to sort this kind of list easily?' today) [...] > | Or if you want to sort only on your Id, use a lambda: > | l.sort(lambda x,y: cmp(x[0],y[0])) @l.sort def sort_on_zeroth(x, y): return cmp(x[0], y[0]) Gives a whole new meaning to decorate-sort-undecorate ;-) Bernhard -- Intevation GmbH http://intevation.de/ Skencil http://sketch.sourceforge.net/ Thuban http://thuban.intevation.org/ From jess.austin at gmail.com Wed Aug 25 16:48:34 2004 From: jess.austin at gmail.com (Jess Austin) Date: 25 Aug 2004 13:48:34 -0700 Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> Message-ID: Paul Morrow wrote in message news:... > > Not exactly, but it would include defining those. One way to think > about metadata is that it includes all information *about* an object, > but no information *used by* the object. > > If we were to have a conversation about this conversation, then we would > be having a "meta-conversation." /metadata/ is data that describes > data. metadata for a function would be data that describes the > function; data *about* the function as opposed to data *used by* the > function. For example: Here I think you're making an unwarranted assumption. There is currently nothing stopping an object from using information about itself to do its job. And this is sometimes a useful freedom. As an example, you might have subclasses whose only real purpose is to keep track of their class and metadata, and have all functionality provided by their superclass: class supe(object): """this docstring is rarely frobnosticated""" def do_something_based_on_metadata(): frobnosticate(self.__doc__) class sub1(supe): """I am sub1""" class sub2(supe): """I am sub2""" Something like this could often be considered premature objectification, but I've used it successfully. Also, you'll notice that these are classes rather than simple functions - I admit I've never had a need to think about function metadata before. However, I know that many people have a specific view of metadata and don't really see how decorators fit in. To be frank, I think pep318 shoehorned in metadata to pretend that there was a wider application area for decoration than there really is. The current quite minimal support for metadata is sufficient for 99% of metadata use cases. My example has worked in Python for some time. I know that decorators would allow different behaviors to be arbitrarily assigned to various pieces of metadata, but that doesn't seem like a big win for code maintainability. If anyone decided to support pep318 based solely on a love of metadata, he made a mistake. I'm intrigued by decorators anyway, and in no small part because it seems that they should be able to completely replace metaclasses, which are themselves totally unrelated to metadata. In fact, that's what at first prompted me to read a thread with the title, "Are decorators really that different from metaclasses..." Class decorators wouldn't be so different from metaclasses, but J2 or even @pie are much better syntaxes than the current metaclass syntax. In another post in this thread Anthony Baxter said they were different. I'll respond directly to that post. later, Jess From thats at it.com Sat Aug 7 21:10:32 2004 From: thats at it.com (Baalbek) Date: Sun, 08 Aug 2004 03:10:32 +0200 Subject: Paul Graham on Python hackers In-Reply-To: <3064b51d.0408061127.32536826@posting.google.com> References: <3064b51d.0408061127.32536826@posting.google.com> Message-ID: beliavsky at aol.com wrote: > also choosing a community. The programmers you'll be able to hire to > work on a Java project won't be as smart as the ones you could get to > work on a project written in Python. [2] And the quality of your I prefer Java and Python alike, I simply love those two languages..... So, am I smart, or not as smart? What a stupid assertion to make; this Paul Graham has just proven himself to be an ass......... QXX From squirrel at WPI.EDU Tue Aug 17 12:22:33 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 17 Aug 2004 12:22:33 -0400 Subject: News server(NNTP library) and Python In-Reply-To: References: <81a41dd.0408162307.3eb1ea36@posting.google.com> Message-ID: On 17 Aug 2004, Duncan Booth wrote: > If you meant that you actually want a free news server to post to real > newsgroups, then sign up with news.individual.net. You have to agree to > some reasonable terms and conditions, but it is free. Also check to see if your ISP provides one; for example, my ISP, Charter, provides a news server at news.charter.net (though it is not available to non-subscribers, of course). From squirrel at WPI.EDU Thu Aug 5 15:09:48 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 5 Aug 2004 15:09:48 -0400 Subject: RELEASED Python 2.4, alpha 2 In-Reply-To: References: <411231C8.3020308@interlink.com.au> Message-ID: On Thu, 5 Aug 2004, David Eppstein wrote: > Let me get this straight: you're envisioning a situation in which you > want to decorate a function, the decorator might fail, and if it does > you want to do something else (perhaps including not decorating it at > all), but with the same function body? Correct. > If so, that's easy: > > def my_robust_decorator(func): > try: > return decorator_that_might_fail(func) > except: > return something_else > > @my_robust_decorator > def func(args...): > .... Well, you've found a good solution. I stand corrected. From squirrel at WPI.EDU Tue Aug 17 10:16:09 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 17 Aug 2004 10:16:09 -0400 Subject: Newbie question about file input In-Reply-To: References: Message-ID: On Tue, 17 Aug 2004, Aaron Deskins wrote: > Also, what exactly is stored when a blank line is read by the > readline command? A zero, blank, or what??? readline() always includes the '\n' that terminates the line, so any 'blank' line that is read will be returned as a simply '\n'. The only time readline() won't return a line terminated with '\n' is if the last line of the file isn't terminated with '\n' (common on Windows), in which context a blank line is meaningless. From ksenia at ksenia.nl Fri Aug 20 03:03:30 2004 From: ksenia at ksenia.nl (Ksenia Marasanova) Date: Fri, 20 Aug 2004 10:03:30 +0300 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: <0AAE767D-F277-11D8-968C-000A957911BC@ksenia.nl> J2 J2 A1 Ksenia From cjw at sympatico.ca Wed Aug 25 21:43:53 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Wed, 25 Aug 2004 21:43:53 -0400 Subject: Call for signatories for J2 In-Reply-To: References: Message-ID: For J2, this is better than 2.4.2a version, but there are more Pythonic ways. Colin W. From abra9823 at mail.usyd.edu.au Mon Aug 30 23:23:21 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Tue, 31 Aug 2004 13:23:21 +1000 Subject: python and visual c++ 3.0 Message-ID: <1093922601.4133ef29882f5@www-mail.usyd.edu.au> hi! Has anyone written applications which have Python interacting with embedded visual c++ 3.0? i am writing an application for pocket pc2002 and there are a few functions i need which are not provided by the python release for pocket pc. so i am thinking of writing a few modules in embedded visual c++ 3.0 and wrapping Python code around it. is that possible? has anyone done it before? i would love to hear any ideas and suggestions thanks cheers ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From graeme.matthew at contrado.com.au Tue Aug 31 01:16:45 2004 From: graeme.matthew at contrado.com.au (Graeme Matthew) Date: Tue, 31 Aug 2004 15:16:45 +1000 Subject: xmlrpclib Message-ID: <413409c3$0$22823$5a62ac22@per-qv1-newsreader-01.iinet.net.au> G'day everyone Just wanted to know if anyone knows if xmlrpclib is scalable i.e can handle many / asynchronous calls. Any help or advice is appreciated Cheers Graeme From gandalf at geochemsource.com Wed Aug 4 03:27:50 2004 From: gandalf at geochemsource.com (Gandalf) Date: Wed, 04 Aug 2004 09:27:50 +0200 Subject: converting to string In-Reply-To: <41108A2E.7030507@mail.usyd.edu.au> References: <41108A2E.7030507@mail.usyd.edu.au> Message-ID: <41108FF6.1060300@geochemsource.com> Ajay Brar wrote: > hi! > > how do i go about converting a Python object or tuple to a string. > i am currently doing > import cPickle as pickle > str = pickle.dumps(obj) > > is that efficient? is that the best way to do it? Yes. You did not tell what the items in the tuple can be so I guess this is the most efficient. For special cases you can find a more efficient solution.For example, for tuples of integers, you can write a C extension that allocates a big string and copies every int object into 4 bytes in the string. That would be more efficient. Regards, Laci 2.0 From tor.iver.wilhelmsen at broadpark.no Thu Aug 5 16:23:23 2004 From: tor.iver.wilhelmsen at broadpark.no (Tor Iver Wilhelmsen) Date: 05 Aug 2004 22:23:23 +0200 Subject: Confused about pep 318 References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: Peter Hansen writes: > And Java chose it based on what precedent? It's own: It follows from their existing use in JavaDoc tags. Already, some preprocessors (like one for DBC) used "custom" tags using this syntax, though still inside JavaDoc comment blocks. Other extensions, like Microsoft's J/Direct used for their deviating Java VM, also used the syntax. The new Java2SE 5.0 / JRE 1.5.0 annotations syntax puts them around where their C# equivalent metadata mechanism is. E.g. J2SE 5.0: @ImplementsRequirement("B2") public void adjustPrices(ArrayList prices) { //... } C# 2.0 (for the generics): [ImplementsRequirement("B2")] public void AdjustPrices(ArrayList prices) { // ... } From jepler at unpythonic.net Wed Aug 4 20:07:27 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 4 Aug 2004 19:07:27 -0500 Subject: Perl's Crypt::PasswdMD5 In-Reply-To: <41110D6D.4000901@divmod.com> References: <41110D6D.4000901@divmod.com> Message-ID: <20040805000726.GC30066@unpythonic.net> On Wed, Aug 04, 2004 at 12:23:09PM -0400, Jp Calderone wrote: > >>> import crypt > >>> crypt.crypt('foo bar', '$1$salt') > '$1$salt$LAwA5cAKtcsGTJGx.bMTC1' Support for MD5 passwords is a GNU extension (according to my manpage for crypt(3). Python directly calls the platform's crypt(), so if your system's crypt is extended, Python will benefit from it. Whether this helps the OP, I dunno. I glanced at the Perl module he mentioned. It looks pretty dull. You could implement it in Python using the md5 module pretty quickly, assuming you had some test vectors to test against. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From BruceWhoHKL at gawab.com Fri Aug 20 05:03:51 2004 From: BruceWhoHKL at gawab.com (BruceKL WhoH) Date: Fri, 20 Aug 2004 17:03:51 +0800 Subject: How to sort this kind of list easily? Message-ID: <20040820092940.9FAF61E4003@bag.python.org> Hi,all I have a list like [(id,string),...],for example: [(1,'xxxxx'),(7,'ppppp'),(4,'gggggg'),...] I want to sort this list according to the id of each element. After sorting,the list will become: [(1,'xxxxx'),(4,'gggggg'),(7,'ppppp')...] Is there any library for such things, Just like STL for C++? I just want to find a convenient way to do things like this. ????????BruceKL WhoH ????????BruceWhoHKL at gawab.com ??????????2004-08-20 From rnichol_rrc at yahoo.com Fri Aug 20 18:33:15 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Fri, 20 Aug 2004 17:33:15 -0500 Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: <5_uVc.411$MR2.2033@news1.mts.net> Tim Hochberg wrote: > Reid Nichol wrote: > >> Gerrit Muller wrote: >> >>> Roel Schroeven wrote: >>> >>>> Roel Schroeven wrote: >>>> >>>>> I spotted some errors in your list, added new entries, and made a >>>>> histogram: http://roelschroeven.net/pythonages/ >>>> >>>> >>>> >>>> >>> Very cool. It might be good idea to add a date and time at the top, >>> since new datapoint keep coming in? >> >> >> How about labels for the axes as well. >> >> >>> and then a quantum leap towards Python. >> >> >> You're aware that a quantum leap means a extremely small leap, right? > > > While quanta are typically very-very-very small, last I checked the key > feature of quantum transitions is not that they're small, but that there > are no intermediate steps. The object is in state A then it's in state > B, but it's never halfway (or anywhere) between. Like most quantum stuff > it's better not to think about that too closely. > > -tim > Check the definition of the word. From aleaxit at yahoo.com Thu Aug 26 17:01:48 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 23:01:48 +0200 Subject: How to generically transform a list? References: Message-ID: <1gj5dj8.h2rve86s8rihN%aleaxit@yahoo.com> Marco Aschwanden wrote: > Suppose you have a list of lists: > > theList = [['a',1,11,'aa'], ['b',2,22,'bb'],['c',3,33,'cc']] > > I would like to have a GENERIC way how to turn this list of list into > another list of list. > - A user can choose which columns she wants > - A user can select the order of the columns > > For example: > The user wants columns: 1,2 > The user wants it to be ordered: 2,1 def GENERIC(list_of_lists, user_wants): return [ [row[x] for x in user_wants] for row in list_of_lists ] example use: print GENERIC(theList, (2, 1)) emits [[11, 1], [22, 2], [33, 3]] > I am sure there must be a rather elegant generic approach, which is > lurking somewhere to be realeased. Funny enough, just this afternoon I was editing a "reordering lists of lists" recipe for the cookbook's 2nd edition (at the mall, on my iBook, sitting at a cafe, drinking Schweppes Orange and smoking, while my wife and co-editor Anna did the grocery shopping -- later she was at the cafe while I went shopping at the pharmacy, evening things out;-), and exactly this one came up -- the original author suggested a hardcoded approach and I widened it up to just this GENERIC function (with a better name, to be sure, but you insisted;-). Which is why I still have it topmost in my mind right now (judging from your post's timestamp you posted just as I was working on this very recipe, funny coincidence). It's one candidate for the 'shortcuts' chapter and there's more stuff slated for that chapter that we can possibly choose for publication, but it's interesting info for me that this specific task IS interesting to somebody -- thanks!-) Alex From PeterAbel at gmx.net Thu Aug 12 07:27:18 2004 From: PeterAbel at gmx.net (Peter Abel) Date: 12 Aug 2004 04:27:18 -0700 Subject: Integers have docstring for int() References: <59e9fd3a04081105087366db98@mail.gmail.com> <16666.13564.527138.202013@montanaro.dyndns.org> Message-ID: <21064255.0408120327.4092144c@posting.google.com> Christian Tismer wrote in message news:... > Skip Montanaro wrote: > > > Andrew> I accidentally discovered that all the basic types in Python > > Andrew> have docstrings that describe the functions to create them. For > > Andrew> integers, you get: > > ... > > > > Andrew> This seems a little unexpected to me; is there any particular > > Andrew> reason for this behaviour? > > > > Why should this be unexpected? If you execute > > > > print int.__doc__ > > > > you get its docstring. Since the __doc__ attribute is attached to the class > > it will be found when the search starts at an instance of the class as well. > > Sure, this is why. But I can understand the feeling a little > bit, because the docstring describes what a __call__ to the > type object does, although the instance is not even callable. > > This may origin in the fact, that int and str have been just > functions a short while back, and the docstrings mainly describe > that function call. The docs are less representative > for int being the whole class. One would perhaps expect > a short description of what an int can do. > On the other hand, int() perceived as a function still needs > its documentation as it is now. > > Like we have the __call__ attribute of a type, which describes > the call of the *instance*, and this differs completely from > how the type is called, would it make sense to change the > __doc__ lookup of types vs. instances in some way? > > The current doc strings would probably better fit into int.__new__ > or int.__init__, while the class __doc__ might talk about instances. > (although I even think no documentation would be better than > the existing docs in the case of strings and ints, which > show up in some object browsers, and you really don't want to > read long musings about strings while inspecting a string value > in the PythonWin debugger). > > ciao - chris The following seems to be unaccustomed, but it's good Python: >>> class myInt(int): ... """Instance of myInt""" ... def __init__(self,val): ... self=int(val) ... >>> i=myInt(10) >>> type(i) >>> i.__doc__ 'Instance of myInt' >>> print myInt.__doc__ Instance of myInt >>> j=2 >>> print j.__doc__ int(x[, base]) -> integer Convert a string or number to an integer, if possible. A floating point argument will be truncated towards zero (this does not include a string representation of a floating point number!) When converting a string, use the optional base. It is an error to supply a base when converting a non-string. >>> type(j) >>> j+i 12 >>> At my knowledge, since Python 2.1?? or 2.2?? basic types are like or are classes where you can inherit from. So their behavior is class-like. Regards Peter From squirrel at WPI.EDU Wed Aug 4 14:07:24 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Wed, 4 Aug 2004 14:07:24 -0400 Subject: tweaking @decorator syntax In-Reply-To: References: Message-ID: (warning, long rant follows) On 4 Aug 2004, Sandy Norton wrote: > Perhaps, you can eliminate the '@' alltogether: I was thinking the same thing, only using a keyword in place of '@' rather than dropping it entirely: decorate classmethod, somethingelse: def somefunc(self): pass I haven't seen this, or any of your proposals previously mentioned anywhere (which doesn't mean they haven't been considered and rejected, since the @ syntax was kept a good secret until it made it into 2.4a2). Another proposal was to use a 'using' keyword like this: using: classmethod somethingelse def somefunc(self): pass But this was shot down because (from PEP 318): The function definition is not nested within the using: block making it impossible to tell which objects following the block will be decorated. Okay then. Your & my syntaxes fix this problem nicely. Nesting the function definition within the using: block suggests nesting of namespaces that doesn't exist. The name foo would actually exist at the same scope as the using: block. This arguments seems to apply to our syntaxes, but... it turns out it's not an argument at all! 'if' doesn't nest namespaces. Neither does 'for', 'try', 'while', etc. Only function and class definitions nest namespaces; I wouldn't expect anything else to. Finally, it would require the introduction of a new keyword. This would apply to my idea, but frankly, I don't see how introducing a new keyword in order to introduce a MAJOR language feature is any different that introducing the butt-ugly '@' syntax, save that it may cause conflicts with older code, in which case we should save decorators for 3.0 (which IMAO should be the case anyways). I'd like to continue this thread by suggesting another idea, side-stepping a backwards-incompatible syntax change: def somefunc(self): [classmethod, somethingelse] pass This has the following advantages: 1) No new syntax or keywords. 2) No nesting issues. 3) Follows a previous precedent (docstrings). 4) Implementable in pure Python for great backwards-compatibility (http://users.wpi.edu/~squirrel/temp/decorate.py for a proof-of-concept) 5) Near the top of the function, so it is quite visible, but below the function name, so it doesn't take attention away from what's important. And the following disadvantages: 1) No new keyword/syntax means looking at it and saying "what's that?" 2) Will run without immediate error in older Pythons, possibly causing hard-to-track-down bugs. 3) Guido won't like it. Of course, I prefer the nested block idea better (either with a new keyword or new syntax), but I don't see those (especially the syntax one) flying anytime soon. Unless someone can come up with an idea everyone can agree on Real Soon Now, I think the whole idea should be dropped and wait until 3.0. We'll have plenty of time to argue about it then. Sorry about the long rant, but it felt good to get that all off my chest. From kylotan at hotmail.com Sun Aug 29 10:37:37 2004 From: kylotan at hotmail.com (Kylotan) Date: 29 Aug 2004 07:37:37 -0700 Subject: [PIL] about the difference between pudata and putpixel References: Message-ID: <153fa67.0408290637.54a7cbc7@posting.google.com> Hillairet Julien wrote in message news:... > Although, this code doesn't work: > > im.putdata(color) > > There is no error message, but the image's pixels stay black (0) ! (The > color matrix is not an 0-matrix !) > > Is someone can explain me my misunderstanding of putdata ? I think the misunderstanding is of numarray. I'm guessing that iterating through a 2D array returns individual rows rather than individual elements. I've never used numarray before but from looking at the documentation, you could try this: im.putdata(color.ravel()) or im.putdata(ravel(color)) -- Ben Sizer From gbig005 at auckland.ac.nz Thu Aug 19 14:39:16 2004 From: gbig005 at auckland.ac.nz (Geoff Biggs) Date: Fri, 20 Aug 2004 06:39:16 +1200 Subject: Problems with adding a new built-in data type Message-ID: Evening all, I'm trying to add a new built-in number data type to Python with its own syntax, so I'm working directly with the interpreter rather than creating my own extension module (side note: I've appended something extra to the version thing in the Makefile - I doubt this is relevant to the problem but it's probably best you have all the info). The complex data type is similar to what I'm trying to do so I've been following that as an example. I've successfully extended the tokenizer and the parsenumber() function in compile.c to do what I want and written the data type in my two new files Objects/mynewobject.c and Include/mynewobject.h. I've included mynewobject.h in Python.h and added the two files to the Makefile. However, when I tried to run the code by typing in the syntax to produce my data type, Python suffers a segmentation fault. I traced this to an attempt to get the hash of a null pointer when adding the new instance of my type after parsenumber() was called. For completeness, here's the backtrace: Program received signal SIGSEGV, Segmentation fault. 0x08080e9a in PyObject_Hash (v=0x81486c0) at Objects/object.c:1162 1162 if (tp->tp_hash != NULL) (gdb) bt #0 0x08080e9a in PyObject_Hash (v=0x81486c0) at Objects/object.c:1162 #1 0x0808e199 in tuplehash (v=0x40324574) at Objects/tupleobject.c:244 #2 0x08080eae in PyObject_Hash (v=0x40324574) at Objects/object.c:1163 #3 0x0807b46c in PyDict_GetItem (op=0x40319c14, key=0x40324574) at Objects/dictobject.c:492 #4 0x080c72c7 in com_add (c=0xbfffed60, list=0x40326114, dict=0x40319c14, v=0x40326290) at Python/compile.c:975 #5 0x080c74ac in com_addconst (c=0xbfffed60, v=0x40326290) at Python/compile.c:1001 #6 0x080c90e3 in com_atom (c=0xbfffed60, n=0x4028d500) at Python/compile.c:1689 The crash appears to be caused because while v exists, v's members are all 0 and so tp becomes 0 when it is made equal to v->ob_type and you get a NULL pointer exception. As far as I can tell, this v is the second object in the tuple created in com_add() and is supposed to be the type of the object being added to the dictionary in a tuple. Not knowing why it was coming out as zero, I did some more poking around (been doing a lot of that over the past 5 days...) and found that there is a file called bltinmodule.c with a bunch of lines, one of which mentions the complex data type that I am using as a guide: SETBUILTIN("complex", &PyComplex_Type); So I made one of these for mynewobject and added it. I figured from this bit of code that the reason I was getting NULL pointer exceptions was because my type hadn't been initialised in some way and that this would do it. But here's the problem: despite trying for longer than I've slept in the past week, I can't get it to work. With that line in the Python interpreter segfaults as soon as it starts (while trying to import the os module) and so it can't even finish compiling the extension modules. If I comment out the SETBUILTIN line I added it will compile fine but then I go back to the first problem. I have structured my object identically to the complex object as far as I can tell, which works. So the question is, what's broken? What have I missed when adding a new builtin? (This mess is all happening on Linux tillinshir 2.6.7-gentoo-r11-gb #1 Wed Aug 4 11:13:14 NZST 2004 i686 mobile AMD Athlon(tm) XP 2000+ AuthenticAMD GNU/Linux, if that matters.) Thanks in advance, Geoff Biggs From stefan at eischet.com Thu Aug 12 16:53:00 2004 From: stefan at eischet.com (Stefan Eischet) Date: Thu, 12 Aug 2004 22:53:00 +0200 Subject: Decorator "platform" In-Reply-To: <2o22htF65snnU10@uni-berlin.de> References: <2nsoofF49frcU1@uni-berlin.de> <87zn50nll4.fsf@pobox.com> <2o22htF65snnU10@uni-berlin.de> Message-ID: <98A72F3C-ECA1-11D8-899A-000A95857E5C@eischet.com> On 12.08.2004, at 22:42, Reinhold Birkenfeld wrote: > John J. Lee wrote: >> Reinhold Birkenfeld writes: >> [...] >>> What I have in mind is a sort of "decorator library" where everyone >>> who >>> has written a useful function of that kind can share it with others, >> [...] >> >> God help us. <0.5 wink> > > God IS helping us, or we wouldn't use Python. If there's a god, is there also a MDFH (malevolent dictator from hell) trying to "enhance" Python? ;-) // stefan at eischet.com // From sridharinfinity at gmail.com Sun Aug 22 07:50:20 2004 From: sridharinfinity at gmail.com (Sridhar R) Date: 22 Aug 2004 04:50:20 -0700 Subject: 100 % portable ? In-Reply-To: Message-ID: Use the standard python library (not OS specific ones) functions. For GUI, better use Tk. That should make your program portable across the platforms where python runs. Tk looks ugly in linux. Gtk is also good, but rendering is sluggish in windows. From steven.bethard at gmail.com Fri Aug 20 02:09:36 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: 19 Aug 2004 23:09:36 -0700 Subject: *expression and iterables Message-ID: So I was looking at the Python 3.0 wiki (http://www.python.org/moin/Python3_2e0) and noticed that one of the major changes would be that builtin classes and functions would take and return iterators instead of lists. Along these same lines, I'm wondering if we could also add the feature that a *expression parameter produces an iterable instead of a tuple. Right now, using the *expression syntax with an iterable causes that iterable to be consumed at the time of the function call, e.g.: >>> def rangegen(n): ... for i in range(n): ... yield i ... print "exhausted" ... >>> def f(*args): ... print "f" ... for arg in args: ... print arg ... >>> f(*rangegen(3)) exhausted f 0 1 2 It would be nice if the iterable was only consumed as necessary, e.g.: >>> f(*rangegen(3)) f 0 1 2 exhausted This would mean that izip(*izip(x)) would work without reading all the elements of izip(x) into memory. If I understand (http://docs.python.org/ref/calls.html) correctly, parameter values are filled with the following sequence: * use values from positional arguments * use values from *expression argument * use values from keyword arguments * use values from **expression argument So either the *expression iterable gets run to completion, fills some parameter values, and the sequence proceeds as normal, or it runs until all parameter values are filled, and then it's passed in as the *args parameter. Doesn't seem too unreasonable... Is this implementable? If so, it seems desirable -- is it something that could be added to the Python 3.0 wiki? (I'd love it now, of course, but it's backwards incompatible =) Steve P.S. I didn't add it to the wiki myself because it sorta seemed like that wiki was intended only for the goals GvR had already suggested. From bjg at network-theory.co.uk Wed Aug 4 05:56:48 2004 From: bjg at network-theory.co.uk (Brian Gough) Date: 04 Aug 2004 10:56:48 +0100 Subject: Modern dead-tree Python resources References: Message-ID: <87ekmnrztr.fsf@network-theory.co.uk> Michael Ekstrand writes: > Is there a good book that covers Python at least through 2.2 > ..... if someone's publishing print versions of the Python > documentation, that would possibly be of interest.... Hello, I publish printed editions of the Python Documentation (and other free software manuals too). The versions are all fairly recent (2.2 & 2.3). See the following urls for details. http://www.network-theory.co.uk/python/manual/ (Tutorial v2.2.2) http://www.network-theory.co.uk/python/language/ (Language Reference v2.3) The discounted price on Amazon is about $14 for each book. Incidentally, $1 of the price is donated to the Python Software Foundation for each copy sold. -- Brian Gough Network Theory Ltd, Publishing the Python Manuals --- http://www.network-theory.co.uk/ From roy at panix.com Sat Aug 7 09:38:13 2004 From: roy at panix.com (Roy Smith) Date: Sat, 07 Aug 2004 09:38:13 -0400 Subject: How to force a single number to be a tuple References: <1a517b5.0408061329.429de7fc@posting.google.com> Message-ID: In article , Dennis Lee Bieber wrote: > On Fri, 06 Aug 2004 18:15:13 -0400, Roy Smith declaimed > the following in comp.lang.python: > > > For those of us who went to school a while ago, and perhaps didn't pay > > as much attention in math class as we should have, could you translate > > "an element of the Cartesian product of zero or more domains" into > > English? > > > It's more the terminology of relation database theory. Might > have derived from some esoteric set theory in match, but for the most > part relational database theory terms map to "common" terms as: > > relation table > tuple row (record) > domain column > > An unrestricted Cartesian product basically pairs up each entry > of "domain A" with each entry of "domain B" Ah. The cross-product. It's amazing how so many fields of study use the same concepts but invent new names for things to obfuscate everything :-) From grante at visi.com Mon Aug 16 00:08:30 2004 From: grante at visi.com (Grant Edwards) Date: 16 Aug 2004 04:08:30 GMT Subject: Python secure? References: <6o75v1-p92.ln1@home.rogerbinns.com> <412009f1$0$8090$a1866201@newsreader.visi.com> <41200f06$0$65568$a1866201@newsreader.visi.com> Message-ID: <4120333e$0$8076$a1866201@newsreader.visi.com> On 2004-08-16, Istvan Albert wrote: >> I've read up a bit, and I looks like I was wrong. The mere >> act of creating a derived work is an infringement of >> copyright. The derived work doesn't have to be distributed for >> an infringment to have taken place. Title 17 says > >> (2) to prepare derivative works based upon the copyrighted work; > > Is a decompiled source code a 'derivate' work? > > I always felt that meaning of 'derivative' is creating a piece > a work that is either very similar to or incorporates large > sections of an other piece of work. > > The mere fact of using a binary file as the input to a program > does not mean that the output of this program is a 'derivative > work' of the binary file. Cite? Under US law, a work translated into a different language is a derived work. That sounds like de-compiling to me. I don't see anywhere where it says the translation can't be done by a computer program. http://www.copyright.gov/circs/circ14.html#examples If I take an 80x86 binary program I use under license from the copyright holder and translate it into SPARC instructions without the copyright holder's permission, can I copyright the result as my own work? Your argument seems to be that I can. > I think the answer lies not in the copyright law but in the > license that was set by the program owner. If they forbid > decompilation that's their right to do so. Perhaps that's true (in some jurisdictions), but we were discussing copyright law. -- Grant Edwards grante Yow! -- I have seen the at FUN -- visi.com From mudd at vex.net Sun Aug 8 22:18:45 2004 From: mudd at vex.net (mudd at vex.net) Date: Sun, 8 Aug 2004 22:18:45 -0400 (EDT) Subject: decorators vs GIL In-Reply-To: <96c2e938.0408081605.706f8ec7@posting.google.com> References: <96c2e938.0408081605.706f8ec7@posting.google.com> Message-ID: <45337.24.233.156.35.1092017925.squirrel@webmail.vex.net> > That's not to say there aren't limited problem domains where threads > are the right answer, but as a general construct they're wildly > overused. I'm frankly glad that Python doesn't encourage more of the > same. > Is there anything else that Python doesn't do well that we should appreciate? From jdhunter at ace.bsd.uchicago.edu Mon Aug 30 10:36:36 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Mon, 30 Aug 2004 09:36:36 -0500 Subject: why does this fail on python 2.2? In-Reply-To: ("Larry Bates"'s message of "Mon, 30 Aug 2004 10:13:44 -0500") References: Message-ID: >>>>> "Larry" == Larry Bates writes: Larry> Because __slots__ and __new__ were added in 2.3. Larry I don't think so http://python.org/2.2.3/descrintro.html From newgene at bigfoot.com Tue Aug 3 08:29:35 2004 From: newgene at bigfoot.com (Newgene) Date: 3 Aug 2004 05:29:35 -0700 Subject: How to clear previous console output? Message-ID: Thank you for all your advice. I have it work now. Cl From h.b.furuseth at usit.uio.no Wed Aug 4 04:14:14 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 04 Aug 2004 10:14:14 +0200 Subject: automatic delegation References: Message-ID: Yermat wrote: >Hallvard B Furuseth wrote: >> Is it possible to write a metaclass or something so that >> with a class definition not much larger than this: >> >> class foo: >> def __init__(self, val): self.val = val >> >> operations on a foo instance f will be applied to f.val? >> E.g. str(f) -> f.__str__() -> f.val.__str__(). > > Here a simple example : > > class proxy(object): > def __init__(self, obj): > self.obj = obj > > def __getattr__(self, key): > if key in self.__dict__: > return self.__dict__[key] > else: > return getattr(self.obj, key) I tried __getattr__ before I posted, but it doesn't work: >>> int(proxy(5)) Traceback (most recent call last): File "", line 1, in ? TypeError: int() argument must be a string or a number However, the example in the Cookbook works. Thanks, Ville. Turns out the above example also works if one one removes 'object' and makes it and old-style class: >>> int(proxy(5)) 5 >>> str(proxy(5)) '5' Seems that with new-style classes, __getattr__ only works for instance variables, while for old-style classes, it also works for class variables like __int__ and __str__. But I can't see anything in the documentation which says so? > You can also look at: > http://www.python.org/cgi-bin/moinmoin/ProxyProgramming That example doesn't work at all. The initialization of self._subject in __init__() breaks because of the definition of __setattr__. -- Hallvard From alf at merlin.fayauffre.org Thu Aug 26 04:32:09 2004 From: alf at merlin.fayauffre.org (Alexandre Fayolle) Date: Thu, 26 Aug 2004 08:32:09 +0000 (UTC) Subject: Converting hex string to an integer References: <412d9e18$0$22821$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: Le 26-08-2004, Derek Fountain a ?crit?: > Given the character string "0x00A1B2C3" arriving at sys.argv[1] how do I > convert that to an integer which I can do some math on? >>> s = "0x00A1B2C3" >>> int(s, 16) 10597059 -- Alexandre Fayolle LOGILAB, Paris (France). http://www.logilab.com http://www.logilab.fr http://www.logilab.org From deetsNOSPAM at web.de Wed Aug 25 11:51:32 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Wed, 25 Aug 2004 17:51:32 +0200 Subject: Desperately needing Help with 2 features of a program References: Message-ID: Hi, Asking people to download your program and simply add features is a little bit too much I fear.... Read this: http://www.catb.org/~esr/faqs/smart-questions.html And then post why and where your concrete attempts fail. Thats much more likely to get answers. -- Regards, Diez B. Roggisch From bmbeck at gmail.com Sun Aug 22 02:57:28 2004 From: bmbeck at gmail.com (Brandon) Date: 21 Aug 2004 23:57:28 -0700 Subject: serial iteration over several lists References: Message-ID: <1b5c4527.0408212257.5c9c18b4@posting.google.com> How about this: >>> import itertools >>> def mesh_flatten(meshes): ... return itertools.chain(*meshes) ... >>> meshes = [ ... ["face1", "face2", "face3"], ... ["face4", "face5", "face6"], ... ["face7", "face8", "face9"], ... ["face10", "face11", "face12", "face13"], ... ] >>> >>> list(mesh_flatten(meshes)) ['face1', 'face2', 'face3', 'face4', 'face5', 'face6', 'face7', 'face8', 'face9', 'face10', 'face11', 'face12', 'face13'] Martin DeMello wrote in message news:... > Within Blender, I have access to a list of Objects, each Object > containing a list of Meshes and each Mesh a list of Faces. I'd like to > implement a face iterator, with both a next() and a prev() method, such > that if I go off the end of a face list, it goes to the first face in > the next mesh, similarly for going off the end of the last mesh in an > object, and similarly for the prev() iterator. > > In other words, I want to simulate appending all the faces into one long > list, but without the overhead of actually creating the list. I can > think of several ways to do it, but they all feel like solutions > 'translated' from some other language - is there a nice pythonic way to > do this? > > martin From mwh at python.net Sat Aug 7 17:01:17 2004 From: mwh at python.net (Michael Hudson) Date: Sat, 7 Aug 2004 21:01:17 GMT Subject: Going the PL/1 way References: Message-ID: Istvan Albert writes: > Mikl?s wrote: > > > > Yes, this was exactly my point. Performance and GIL. Those are problems. > > And problems must be solved. After that add features... if they are really > > needed. > > nah, > > first we need to attend to pressing needs, such as replacing > > my_list.reverse() > for item in my_list: > ... > > with the incomparably more pythonic: > > for item in reversed(my_list): > ... > > and at the same time, we need to replace the ridiculous: > > my_list.sort() > for item in my_list: > ... > > with: > > for item in my_list.sorted(): > ... > > note the consistency in 'sort' and 'reverse' and the lack of > that in the usage of sorted and reversed. Which you've made up: sorted is a builtin in 2.4. By all means carp about the new features, but -- particularly if you're going to be sarcastic about it -- please get it right. Cheers, mwh -- 7. It is easier to write an incorrect program than understand a correct one. -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html From P at draigBrady.com Tue Aug 3 09:48:00 2004 From: P at draigBrady.com (P at draigBrady.com) Date: Tue, 03 Aug 2004 14:48:00 +0100 Subject: Python and Glade-2 In-Reply-To: References: Message-ID: Dave Cook wrote: > In article , Dave Cook wrote: > > >>Here's a more up to date list of tutorials: > > > Woops... > > http://www.pygtk.org/articles.html > > Dave Cook I've a tutorial with a couple of example apps here: http://www.pixelbeat.org/talks/pygtk -- P?draig Brady - http://www.pixelbeat.org -- From abra9823 at mail.usyd.edu.au Wed Aug 4 08:20:38 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Wed, 4 Aug 2004 22:20:38 +1000 Subject: tkinter button command Message-ID: <1091622038.4110d496aeb96@www-mail.usyd.edu.au> hi! if i set two buttons to call the same function when they are pressed, is there any way, within the function of knowing which button invoked it. cheers -- Ajay Brar, CS Honours 2004 Smart Internet Technology Research Group ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From ialbert at mailblocks.com Mon Aug 23 15:46:47 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Mon, 23 Aug 2004 15:46:47 -0400 Subject: Standard graph API? In-Reply-To: References: Message-ID: Magnus Lie Hetland wrote: > So, any interest? Or am I just a lone nut in wanting this? I have often needed to use simple graph concepts and wrote a bunch of code, then at some point I have started to unify it and (slowly) put together a consistent model. When my research brings me back to graphs I'll try to finish it. http://www.personal.psu.edu/staff/i/u/iua1/python/graphlib/html/ I do have a lot functionality working, you can associate arbitrary data with the nodes and edges, bfs, dfs, topological sort,graph generation, David Epstein's python dijkstra algorithm, graphviz visualization. Istvan. From martin at v.loewis.de Sun Aug 22 04:39:23 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 22 Aug 2004 10:39:23 +0200 Subject: zipfile module: problems with filename having non ascii characters In-Reply-To: <41284ac0$0$3551$ba620e4c@news.skynet.be> References: <4127a6d7$0$4090$ba620e4c@news.skynet.be> <41284ac0$0$3551$ba620e4c@news.skynet.be> Message-ID: <41285BBB.1050800@v.loewis.de> vincent_delft at yahoo.com wrote: > That limitation is only valid for zip files ? It appears that WinZip and other tools interpret the file names in a zipfile in CP437. So to properly put non-ASCII file names into a zipfile, you need to convert them into CP437. If the file name contains a character which is not available in CP437, you cannot save the file in a zipfile (without renaming it). Not really a Unicode problem, but rather a problem that Unicode tries to solve. > Is there an another "compression tool" that don't have such limitation > (tgz? , bz2? , ???? tar, traditionally, is also unaware of character sets. Single Unix 3 (and I believe also earlier) ended the tar wars with the introduction of the pax utility, which does allow for specification of a character set in a pax file; among the supported character sets are ISO-8859-n, and UTF-8. J?rg Schilling's star(1) also uses UTF-8 for file names. On the non-tar side of the world, WinRAR supports Unicode in archives. For compatibility, they also put a non-Unicode name into the archive, but the Unicode name, if present, is meant to take precedence. Regards, Martin From paul.bissex at gmail.com Mon Aug 30 16:40:21 2004 From: paul.bissex at gmail.com (Paul Bissex) Date: Mon, 30 Aug 2004 16:40:21 -0400 Subject: "Content-Length" header In-Reply-To: References: Message-ID: <10015231040830134058f9bef6@mail.gmail.com> On 30 Aug 2004 13:28:50 -0700, Justin wrote: > Ok I have now discovered the oddest problem ever. Check this out it > seems that the same code that works outside of a for loop doesn't work > in one check it out. Even though the first entry in the list > linklisttype is the same exact URL. > > (THIS WORKS) > > temp = > urlopen("http://www.ecs.soton.ac.uk/~harnad/Temp/Ariadne-RAE.doc") > print temp > temp2 = temp.info() > print temp2 > temp3 = temp2.getheader("Content-Length") > print temp3 > > (THIS DOESN't) > for y in linklisttype: > x = y > temp = urlopen(x) > print temp > temp2 = temp.info() > print temp2 > temp3 = temp2.getheader("Content-Length") > print temp3 I am assuming that your mail client or something else between you and us has borked the indentation. If so, I think your problem lies outside the code you posted. If I run that code, properly indented and preceded by linklisttype = ['http://www.ecs.soton.ac.uk/~harnad/Temp/Ariadne-RAE.doc'] then I get identical output from the two. pb -- paul bissex, e-scribe.com -- database-driven web development 413.585.8095 69.55.225.29 01061-0847 72?39'71"W 42?19'42"N From quadric at primenet.com Mon Aug 30 17:12:32 2004 From: quadric at primenet.com (quadric at primenet.com) Date: Mon, 30 Aug 2004 14:12:32 -0700 Subject: Is it possible to embed PythonWin Message-ID: <5.1.1.6.2.20040830140812.00acce58@pop.primenet.com> Hi, I am just getting into PythonWin. I need my application that has Python embedded within it to communicate with an Excel spreadsheet. I have done this manually with PythonWin. All works well. How can I get my application to communicate via PythonWin with the Excel spreadsheet in an automated way? Can PythonWin be embedded? Is it a matter of importing certain modules from within plain Python and calling certain methods to initialize the COM interface..etc....?? Any help would be appreciated. From noone at here.com Wed Aug 25 20:00:50 2004 From: noone at here.com (M. Clift) Date: Thu, 26 Aug 2004 01:00:50 +0100 Subject: Just a quick one References: Message-ID: Hi SM and Phil , Thankyou both for your help. M From rnd at onego.ru Thu Aug 26 07:44:21 2004 From: rnd at onego.ru (Roman Suzi) Date: Thu, 26 Aug 2004 15:44:21 +0400 (MSD) Subject: Call for signatories for J2 In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022E6F@exchange.hqamor.amorhq.net> References: <3A81C87DC164034AA4E2DDFE11D258E3022E6F@exchange.hqamor.amorhq.net> Message-ID: > Please read the proposal carefully before signing. In particular, > carefully read the statement (for, against, or abstaining) to which you > are signing your name; each is explicit and means exactly what it says. The J2 proposal. For addition to: http://www.aminus.org/rbre/python/pydec.html My unconditional vote is: ----------------------------- "FOR" Roman Suzi rnd at onego.ru ----------------------------- Remarks: we hardly find better keyword for decorators and I'd also liked to be able to delimite decorators with ";" as normal statements. From stuffduff at cox.net Thu Aug 5 09:48:48 2004 From: stuffduff at cox.net (Sean) Date: 5 Aug 2004 06:48:48 -0700 Subject: ZServerSSL and Certificates Message-ID: <3222fe00.0408050548.43b5f0fd@posting.google.com> Hi, I have been able to get ZServerSSL to work with the demo certs, and with some self generated. However I'm really not clear on certificates in general, and we're about to try it with real certs from a real CA. What I'd like to find is some really clear documentation on ZServerSSL. What I have had to do is to try and interpret between the general SSL certificate information sites and the ZServerSSL package. What I did this last go-around was to snag CA.pl and visit https://www.entrust.com/freecerts/ag_server_req.cfm Step 3 requires a server certificate request (PKCS#10 request) Here's what I did: # openssl -des3 -out privatekey 1024 # ./CA.pl -newreq Which gave me newreq.pem, so I cut the text between the markers and pasted it into the box, and submitted it. Then I get two files back from the web site. I believe that the first is the server cert, the second a ca cert. So I take privatekey.pem and the ca cert and combine them into a single file called ca.pem. Then I: # ./CA.pl -sign # openssl rsa < newreq.pem > newkey.pem and I combine the server cert and newkey.pem and call it server.pem. I stop & restart the server, I get no errors from ZServerSSL. However, when I try and access the site I get: Microsoft IE6 first shows a request for a cert to use, I click OK to bypass it then a warning dialog that the ca is not trusted. Mozilla diaplays a panel warning that there are three potential problems. In either case if I ignore the warnings I get a secure connection. I need to understand what I'm doing wrong here. Please enlighten me! From theller at python.net Tue Aug 24 15:08:10 2004 From: theller at python.net (Thomas Heller) Date: Tue, 24 Aug 2004 21:08:10 +0200 Subject: fun with unicode files References: <6579x7eo.fsf@python.net> Message-ID: "Roger Binns" writes: > Thomas Heller wrote: >> I wonder: do I really have to check for the BOM manually, or is there a >> Python function which does that? > > It should be part of the standard library IMHO. > > Here is my own more complete implementation: > > http://www.bitpim.org/pyxr/c/projects/bitpim/common.py.html#0286 > Ah, thanks. It looks like I basically got it right, although your solution is really more complete. Thomas From tjreedy at udel.edu Tue Aug 24 18:18:56 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 24 Aug 2004 18:18:56 -0400 Subject: Debunking Art - fraudster with python AI engine? References: <4128f60b$1@news.unimelb.edu.au> <412b8a01$1@news.unimelb.edu.au> Message-ID: "Tom B." wrote in message news:412b8a01$1 at news.unimelb.edu.au... > "Nick" wrote in message > news:4128f60b$1 at news.unimelb.edu.au... > > Curiously, I asked the artist if he had written the engine. He claimed > > to have, but as far as I know, he has done no AI study, and only > > started programming python some months ago. > Python is all about getting the proper module and using it. Do you believe > those that use wxPython or Tk to be frauds. Do people who use wxPython (a gui *engine*) claim to have written it? It is possible the the artist misunderstood the question and only meant to say that he had written the application on top of the engine. But I was not there. Terry J. Reedy From squirrel at WPI.EDU Wed Aug 11 11:31:47 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Wed, 11 Aug 2004 11:31:47 -0400 Subject: How to get rid of "hex/oct constants > sys.maxint" warning? In-Reply-To: <411a3402$0$65564$a1866201@newsreader.visi.com> References: <411a3402$0$65564$a1866201@newsreader.visi.com> Message-ID: On 11 Aug 2004, Grant Edwards wrote: > How _do_ I get rid of the warning? Is there a way to tell > Python that the constant isn't an integer, it's just a bit > pattern? The best way is to tell Python to silence the warning: >>> 0xc0047a80 FutureWarning >>> import warnings >>> warnings.simplefilter('ignore',FutureWarning) >>> 0xc0047a80 -1073448320 fcntl() doesn't really care what it gets, so long as it can convert it to a 32-bit value, something it can't do with a long integer. In 2.3, 0xc0047a80 returns a negative integer, which is acceptable to fcntl(). In 2.4, it's going to return a long integer -- presumably fcntl() will also be able to accept long integers. From rnichol_rrc at yahoo.com Sun Aug 15 16:17:27 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Sun, 15 Aug 2004 15:17:27 -0500 Subject: Python secure? In-Reply-To: References: Message-ID: Calvin wrote: > Hi to both of you, > > For some reason I can't seem to reply to the post, hence my posting this as > a new topic > > Sorry I should have said I'm new to programming let alone Python. I wish to > know whether Python is secure as an exe for a commercial product. i.e. can > someone see your code more easily than in say using another language. We're > not talking financial / security type software here just a basic windows > app. > > Thanks > > Distribute the compiled objects and not the source. Use py2exe and get a binary to distribute. But then again if some really wants your code they can get it. This is the same with anything, once something leaves your hands you don't have any control over it anymore. If you are new to programming then something should be mentioned. Python just like *any other language* has its strengths and weaknesses. One must choose a language for a project based on the projects requirements and not really what they like. So, for the project you have in mind C or Lisp or something else may be far more appropriate to code in. That being said, Python is a great language to learn in. Many of the bad habits, like poor indentation, aren't an issue in Python as if you poorly indent you get errors (logical or otherwise). You can also learn structured and object oriented programming and design all in one neat little package. At this point I'd say learn with Python (you'll be glad you did) and then revisit the project you have in mind later when you have a better idea of its actually requirements. From http Mon Aug 16 19:51:18 2004 From: http (Paul Rubin) Date: 16 Aug 2004 16:51:18 -0700 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> <41214271_1@127.0.0.1> Message-ID: <7xoelamykp.fsf@ruckus.brouhaha.com> "beliavsky at aol.com" writes: > Thanks. My code did not correctly illustrate breaking out of more than one > level of loop. How would the following code be translated to Python? > It is silly of course, but real-world situations where you want to exit a > nested loop are not that rare. They're really not all that common. > ido: do i=1,n > jdo: do j=1,n > if (i+j > n) exit ido > ... Well, you could do it with try/raise, like try: for i in xrange(1,n+1): for j in xrange(1, n+1): if i+j > n: raise 'foo' ... except 'foo': ... but more normally you'd just say for i in xrange(1,n+1): for j in xrange(1, n-i+1): ... From b.niemann at betternet.de Fri Aug 13 09:27:27 2004 From: b.niemann at betternet.de (Benjamin Niemann) Date: Fri, 13 Aug 2004 15:27:27 +0200 Subject: Flython? In-Reply-To: References: Message-ID: Christopher T King wrote: > On Thu, 12 Aug 2004, Peter Hansen wrote: > > >>In the vein of Jython, I wonder what it would take to build >>a Flython? (Lousy name, I know.) That would take Python >>source, presumably a subset since some things couldn't be supported, >>and compile it into ActionScript bytecode (aka the bytecode compiled >>from ECMAScript source for the Macromedia Flash player environment). > > > I don't know much about ActionScript bytecode, but I think a general > Python -> ECMAScript translator wouldn't be too hard (presuming a Python > subset is acceptable). ECMAScript variables are untyped, so that should > ease translation some. Sounds like my weekend project! > Probably more than a weekend project, but if you do it, I'd be very, very happy! I'm just working on a rather complex Flashproject (simulator for a digital camera) and I have more than enough reasons to curse Flash & ActionScript. The thought how wonderful it would be, if I could use Python for the logic just popped up in my head a few days ago... From bingham at cenix-bioscience.com Fri Aug 27 09:32:11 2004 From: bingham at cenix-bioscience.com (Aaron Bingham) Date: Fri, 27 Aug 2004 15:32:11 +0200 Subject: allowing braces around suites In-Reply-To: References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> Message-ID: <412F37DB.70009@cenix-bioscience.com> Wolfram Kraus wrote: > Kjetil Torgrim Homme wrote: > [...] > >> how can Emacs tell? if I press TAB and thus ask Emacs to re-indent >> the line, that's what it will do. arguably, the correct fix is to >> disable the "clever" re-indentation code of Emacs since it's too easy >> to fool it, but this makes coding more awkward in other cases. it >> also doesn't solve cut-n-paste errors. > > You can use C-c < or C-c > in Emacs to (de-)indent regions. Or C-M-\ to re-indent the region "correctly" with respect to its context. This works far more reliably the using TAB to re-indent single lines. -- -------------------------------------------------------------------- Aaron Bingham Application Developer Cenix BioScience GmbH -------------------------------------------------------------------- From gohaku at earthlink.net Mon Aug 9 12:58:59 2004 From: gohaku at earthlink.net (gohaku) Date: Mon, 9 Aug 2004 12:58:59 -0400 Subject: What are decorators? Message-ID: <68BA7704-EA25-11D8-9BC6-000A9574CFD8@earthlink.net> Hi everyone, The discussion on Python Decorators and "@" has piqued my interest on this "feature?" in programming languages such as Python and Java. can anybody what is the point in using Decorators? The examples I have seen written in Python of this "Not Yet Implemented" feature are confusing to say the least and perplexes me as to its usefulness. Thanks in advance. -gohaku From joh12005 at yahoo.fr Mon Aug 30 15:05:18 2004 From: joh12005 at yahoo.fr (Joh) Date: 30 Aug 2004 12:05:18 -0700 Subject: how to get size of email attachment Message-ID: <63b5e209.0408301105.58b9207a@posting.google.com> hello, i'm looking for a way to get total size of an email (with its attached files) using library such as poplib, or ? can someone help me or give me an url from where to start ? thx From justin__devine at hotmail.com Mon Aug 30 13:43:21 2004 From: justin__devine at hotmail.com (Justin) Date: 30 Aug 2004 10:43:21 -0700 Subject: Size of a remote URL In-Reply-To: Message-ID: Ok. I believe you are correct. I have observed the two MODES of the download dialog box. HOWEVER there are still some instances in which Internet Explorer knows the size of something that my code cannot determine. So now I have this conclusion: The instances where I cannot get the size but a browser can must exist because I am not asking the server the right question. Perhaps "Content-Length" is not included in the default headers, but the server will provide this header if it is asked too? Maybe I need to ask for that header more specifically? Also do you know of a simpler method than urlopen? I am unsure if urlopen actually reads the file all the way through once. If so this is a huge waste of resources for me and I will try to incorporate this code directly into my download funciton so that as each file is downloaded its size is passed to the dialog box. Let me know what you think. Thanks -Justin let me past my simple code: file_sizes = [] for y in linklisttype: w = urlopen(y) z = w.info() x = z.getheader("Content-Length") file_sizes.append(x) From adurdin at gmail.com Mon Aug 23 08:34:02 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Mon, 23 Aug 2004 22:34:02 +1000 Subject: line shift? (baby steps 2) In-Reply-To: <6daa8765.0408230412.6db365d6@posting.google.com> References: <6daa8765.0408230412.6db365d6@posting.google.com> Message-ID: <59e9fd3a0408230534c68ef7d@mail.gmail.com> On 23 Aug 2004 05:12:30 -0700, Artemisio wrote: > I have done a small currency calculator. It works and I'm very glad. > But...I'd like to have a line shift if user types a wrong choice. A simple "print" with no arguments should display the blank line you want: while currency_str != "EUDK" and currency_str != "DKEU" and currency_str != "USDK" and currency_str != "DKUS"\ and currency_str != "EUUS" and currency_str!= "USEU": print currency_choice= raw_input("Sorry. At the moment we only support DKK, Euro and Dollars." + "\n" \ "Type DKEU if you want convert from DKK to ?," + "\n" \ "EUDK if you want to convert from DKK to ?," + "\n" \ "DKUS if you want to convert from DKK to $," + "\n" \ "USDK if you want to convert from $ to DKK," + "\n" "EUUS if you want to convert from ? to $," + "\n"\ "and USEU if you want to convert from $ to ?: ") currency_str= str(currency_choice).upper() Or you can add an extra "\n" at the beginning of your "Sorry" string. From del at mjclift.freeserve.co.uk Fri Aug 6 20:25:17 2004 From: del at mjclift.freeserve.co.uk (Calvin79) Date: Fri, 06 Aug 2004 20:25:17 -0400 Subject: random from an array References: <2sqdnezun4kImoncRVn-qg@powergate.ca> Message-ID: Thanyou! Peter Calvin From peter at engcorp.com Thu Aug 5 13:29:29 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 05 Aug 2004 13:29:29 -0400 Subject: Confused about pep 318 In-Reply-To: References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: Anthony Baxter wrote: > But, suprise, Python's > a volunteer effort. No-one's paying me to do this, or Guido, or anyone else. > If someone wants to offer to pay me, or someone else, to actually do all this, > *great*. I'll make another donation to PSF if the final decorator syntax does not Perlishly use arbitrary punctuation as the @ syntax does. -Peter From lbates at swamisoft.com Tue Aug 3 10:03:21 2004 From: lbates at swamisoft.com (Larry Bates) Date: Tue, 3 Aug 2004 09:03:21 -0500 Subject: how do i do this - stream file References: Message-ID: Actually this can happen automatically. If the user's machine doesn't have a file association for the file extension of the file that they click on the browser automatically displays a open/save dialog for them when they click on the hyperlink. If they have an association defined on their machine, for the extension it launches the application when they click the hyperlink. On Windows this behavior is configurable. They can always right click on hyperlink and choose save instead. HTH, Larry Bates Syscon, Inc. "Ajay" wrote in message news:mailman.1083.1091521022.5135.python-list at python.org... > hi! > > How do i create and stream a file? > On a webpage i have a link to a file. Next to it i would like link, which, > when pressed, runs a script that calculates the signature of the file, > pickles the signature to a file and then gives a dialog box asking the > user whether they would like to save the file or open it. > > I have the script to do the signing and pickle the signature into a file, > but how do i allow the user to download it? > > thanks > > cheers > > -- > Ajay Brar, > > > > > > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. From tjreedy at udel.edu Mon Aug 16 13:49:20 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Aug 2004 13:49:20 -0400 Subject: Python secure? References: <2xXTc.3775$bJ2.24876@news1.mts.net> Message-ID: "Peter Hansen" wrote in message news:NIydnd-skK0q173cRVn-ow at powergate.ca... > Reid Nichol wrote: > > > Terry Reedy wrote: > > > >> ... compiled C can be terribly insecure relative to > >> Python. C has dangerous functions like strcpy() which, if used with > >> external input, can make a program subject to buffer overrun exploits > >> that > >> can do explosive damage. > > > > But this doesn't make C an insecure language. No language is either > > secure nor insecure. It's what the programer does with it that matters. Yes, and in a later sentence, I said something about smarter programmers and code check policies. Indeed, by the mid-1980s, I knew that giving control of copying to the block copied, by copying until the block contained a null byte, could be dangerous. But somewhere around 2000, Microsoft shipped product that did exactly that with data taken off the Internet. > New definition for the purposes of this discussion: > > "secure language": a programming language which, by virtue of > its structure, libraries, syntax, runtime, or other features > supports and tends to encourage the creation of software which > doesn't have gross security holes". Viz. "Python" > > "unsecure language": a programming language which, by virtue > of its structure, primitive libraries, awkward syntax, non- > existent runtime, or other limitations tends to encourage > and lead to the creation of software with gross security > holes". Viz. "C" Thanks, Peter, for explaining what I meant better than I could have. In particular, as I said, buffer overruns are easily possible in C and impossible, as far as I know, in pure Python. Furthermore, I believe that this is an intentional part of the design of each language, which make intentionally different tradeoffs between safety and speed. > A given programmer will be more likely to create safe and > secure software using Python than with C, thereby making > C the less secure... Especially if a programmer is rewarded for faster code -- which one write by copying dangerously -- and pushing the hidden costs off onto customers. Terry J. Reedy From ellisjb at my-deja.com Wed Aug 25 09:16:33 2004 From: ellisjb at my-deja.com (ellisjb at my-deja.com) Date: 25 Aug 2004 06:16:33 -0700 Subject: kill/cancel a started thread In-Reply-To: <2p31fvFfb10tU1@uni-berlin.de> Message-ID: You need to have your thread check for some condition that signals it to exit. E.g., stopnicely in the following class (subclass and provide an action method to do something useful): class StoppableThread(threading.Thread): def __init__(self, **kwds): threading.Thread.__init__(self, **kwds) self.keepgoing = True def stopnicely(self): self.keepgoing = False def run(self): while self.keepgoing: time.sleep(1) self.action() print "Thread " + self.getName() + " has stopped" -Jonathan From mwh at python.net Thu Aug 5 14:35:52 2004 From: mwh at python.net (Michael Hudson) Date: Thu, 5 Aug 2004 18:35:52 GMT Subject: Confused about pep 318 References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: Peter Hansen writes: > Python doesn't need to select syntax from other languages. Python > leads, it doesn't follow. Until now. :-( Say what? Cheers, mwh -- 8. A programming language is low level when its programs require attention to the irrelevant. -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html From maxwell at ldc.upenn.edu Tue Aug 31 16:21:37 2004 From: maxwell at ldc.upenn.edu (Mike Maxwell) Date: 31 Aug 2004 13:21:37 -0700 Subject: sys.stdin.readline() Message-ID: <367a4461.0408311221.30866c09@posting.google.com> When I invoke readline() in a for loop, why does it return a series of one-char strings, rather than the full line? >>> for sL in sys.stdin.readline(): print sL ... abc a b c (I typed in 'abc', and the loop printed out 'a\nb\nc\n') I.e. how can I make readline() wait for the newline before returning a value? 'readline()' seems to be acting exactly like 'read()' here. ('readlines()' works fine in this context, except that it waits for eof; I'd really rather iterate over lines in stdin as they come in) From dave at pythonapocrypha.com Wed Aug 18 09:49:15 2004 From: dave at pythonapocrypha.com (Dave Brueck) Date: Wed, 18 Aug 2004 07:49:15 -0600 Subject: Access to Oracle In-Reply-To: <039d01c4851e$38241b60$054b12ac@D18SYX41> References: <039d01c4851e$38241b60$054b12ac@D18SYX41> Message-ID: <41235E5B.4030806@pythonapocrypha.com> Greg Lindstrom wrote: > Greetings- > > I am running Python 2.3.3 on HP-UX and would like to access an Oracle 9i > database. Looking through the vaults, I see 4 or 5 modules that might work > and was wondering if anyone is currently hitting Oracle and what are you > using. I get to build a new system from the ground up and the powers that > be are allowing me to do it in Python. I'm quite happy. Hi Greg, We recently migrated to PostgreSQL, but up until then we'd been using Oracle 9i. All of our Python DB access was via DCOracle2 on a Linux box - don't know if it works on HPUX but it worked well for us. -Dave From jeff at ccvcorp.com Thu Aug 26 16:35:56 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Thu, 26 Aug 2004 13:35:56 -0700 Subject: Call for signatories for J2 In-Reply-To: References: Message-ID: <10isicb60g4qoc2@corp.supernews.com> Robert Brewer wrote: >The J2 proposal is as complete as it will ever be. > >http://www.aminus.org/rbre/python/pydec.html > > > I'll sign in favor of this proposal. Jeff Shannon Technician/Programmer Credit International From barnesc at engr.orst.edu Thu Aug 5 20:54:56 2004 From: barnesc at engr.orst.edu (barnesc at engr.orst.edu) Date: Thu, 5 Aug 2004 17:54:56 -0700 Subject: Proposed improved decorator syntax Message-ID: <1091753696.4112d6e06ea9e@webmail.oregonstate.edu> I'm revising my vote. Thanks for the responses. I vote against: class foo: @synchronized @types("o,i,i") @author('Chris King') def introduceNewFeature(self, someArgument, anotherArgument): pass # whatever Pros: - Allows arbitrary functions to be applied as decorators. Cons: - Places decorator metadata before the function (in contrast with docstrings). - Hides function name. - @ symbols are ugly. - @ symbols are a particular hack for creating function metadata. - More such hacks may be needed in the future. - @ can be used to store metadata, but in a convoluted way: @name('Value') works, if function 'name' is defined (imports must be used for large projects); however the metadata name actually stored may be different than 'name' (ie no symmetry, no ease of use). - @ will be used for metadata, if no other solution is provided. Recognize that we're *really* trying to create function metadata. A more flexible solution is to make a metadata dictionary be part of function and class definitions. Then 'decorator' simply becomes one name among many different metadata names. I vote for: --------------------------------------------------------------------- Proposed Syntax --------------------------------------------------------------------- class foo: def introduceNewFeature(self, someArgument, anotherArgument): .decorate = [synchronized] .accepts = (int, int) .author = 'Chris King' pass # whatever Use introduceNewFeature.__meta__ to access the metadata dict. The .accepts meta-datum calls isinstance() for each argument. Use 'object' for arguments that can be any type. Pros: - Readable. - No ugly @ symbols. - Metadata is placed after the function name. - .decorate is semantically superior to @. - Similar to existing Python syntax (equals sign and dots). - Allows metadata to be created and read (symmetrically, easily). - Allows arbitrary functions to be applied as decorators. - Code is ordered correctly (function declaration before docstring and metadata). Cons: - Name conflicts between builtin metadata names (eg 'decorate') and user metadata names (eg 'decorate'). Solutions to Name Conflicts: - Name conflicts are a small problem if the set of Python special metadata names is kept small and well documented (eg '.decorate' and '.accepts' can be documented as 'metadata keywords', to be avoided). - The paranoid can prefix metadata names with underscores. - Alternatively, .__decorate__ and .__accepts__ can be used. - Alternatively, {'decorate': [synchronized], 'accepts': (int, int)} can be used as the first line of metadata, which is interpreted as a 'Python special metadata dict'. --------------------------------------------------------------------- Conclusion --------------------------------------------------------------------- Either attack the full problem of metadata, or don't. @ is a hack. @ looks ugly. @ is a particular solution for the general problem domain of metadata. @ is not clear to the uninitiated. @ is counter-intuitively present before the docstring. @name('Value') is can be used to store metadata, but lacks ease of use and symmetry. Finally, @ does not appear to follow the tradition of Python. It is a very specialized extension statement, and at least deserves a descriptive identifier in the code like 'decorate'. Please don't stay silent on this issue. Speak out! We should really have a public vote. I doubt the @ sign will be approved if 99% of Python users oppose it. - Connelly From pm_mon at yahoo.com Tue Aug 24 18:59:56 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Tue, 24 Aug 2004 18:59:56 -0400 Subject: Alternative decorator syntax decision In-Reply-To: References: <4126982d$0$22032$626a14ce@news.free.fr> Message-ID: <412BC86C.9070501@yahoo.com> Jess Austin wrote: > Paul Morrow wrote in message news:... > >>>By what kind of black magic would setting the property __synchronized__ to >>>True would make that function synchronized ? And how can I define my own >>>decorators then ? >> >>There would be two kinds of decorators. Those that are simply >>informative (like __author__ or __version__), and those that have >>side-effects (like __metaclass__, __synchronized__, __automethods__, >>etc.). Those with side-effects would be implemented as special functions... >> >> def synchronized(func, trueOrFalse): >> __decorator__ = True >> __author__ = 'Billy Batson' >> __version__ = '0.1' >> # >> # perform the synchronized operation on func... >> # > > > How would the parser know the difference between informative function > variables like "__author__" and your special side-affecting function > variables? > In this proposal, the "side-effecting" functions would all be decorated with "__decorator__ = True". So the interpreter would tell the difference that way: for any given attribute __xxx__, if no function exists with the name xxx and which also defined __decorator__ = True, then xxx would be considered informational only. Whether or not this idea has merit, it is too different than what is seriously being considered to have a chance of being adopted. However there is a compromise that is much more consistent with the current decorator proposals yet doesn't require any new syntax. The idea is that we mirror the __metaclass_ syntax, and introduce a new magic variable __features__ which takes as its value a tuple of decorators... def foo(): """ This is a docstring. """ __features__ = synchronized, returns(None) # function body goes here The decorators would be located/resolved/applied as in the popular proposals. From npat at efault.net Mon Aug 16 14:26:32 2004 From: npat at efault.net (Nick Patavalis) Date: Mon, 16 Aug 2004 18:26:32 +0000 (UTC) Subject: ConfigParser options spanning more than one line References: Message-ID: On 2004-08-16, Josh Close wrote: > I'm using ConfigParser and I can't seem to get a config option to span > more than one line. > > [MyConfig] > var = blah blah blah\ > blah continued > > Putting the '\' doesn't work > > Is there a way to do that? Or do I have to deal with having a huge > long string all on one line? Simply do: [MyConfig] var = blah blah blah blah continued without the '\'. Indentation continues the line. /npat From eq at eq.homelinux.org Thu Aug 19 18:14:05 2004 From: eq at eq.homelinux.org (eq) Date: Fri, 20 Aug 2004 00:14:05 +0200 Subject: problem using C-bindings References: Message-ID: Am Thu, 19 Aug 2004 17:45:45 -0400 schrieb Jack Diederich: > On Thu, Aug 19, 2004 at 10:32:15PM +0200, eq wrote: >> Hi, >> >> I'm trying to create a program(written in C) that does the following >> things using embedded Python: >> 1. Create a module(say, "MyModule") >> 2. Create a class in that module(say, "MyClass") >> 3. Create a function in that module(say, "MyFunction") > [snip] >> class_dict=PyDict_New(); >> class_name=PyString_FromString("MyClass"); >> class=PyClass_New(NULL,class_dict,class_name); >> PyDict_SetItemString(module_dict,"MyClass",class); > [snip] > > Take a look at Modules/xxsubtype.c in the source distribution. > It is an example of how to subtype a builtin. xxmodule.c shows > how to make a class from scratch. Both are out of date but a good > sarting spot. > Hm, perhaps I over-complicated my problem: I don't need a full python-class in pure C. I just need to create a (python!) function(a dynamic one, not a static C function) and attach it to an already existing python-class just by using C-calls. I try to do this by compiling the function's code with: pyfunc_code=Py_CompileString(func_code,"",Py_file_input); where func_code could be something like "print 'hello'" and then I try to make a function out of this by calling: pyfunc=PyFunction_New(pyfunc_code,dict); where dict is the global namespace for the function. What I now want is to attach this function to the already created class "MyClass". > You could also give Pyrex a try, it makes it easier to write just > a hot function or two of a class in C. I like it to prototype C versions > of hotspot functions (but then do the final version 'by hand'). > > -Jack From pm_mon at yahoo.com Fri Aug 20 05:45:11 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Fri, 20 Aug 2004 05:45:11 -0400 Subject: PEP 318: Can't we all just get along? In-Reply-To: References: Message-ID: Roy Smith wrote: > > I never quite understood the point of static methods inside classes. > When would you ever need to do that, as opposed to just a function in a > module? In Java's "everything is part of a class" philosophy, it makes > sense, but in Python? It gives us another means of managing namespaces. Rather than having to create a top-level function in the current (or some other) module, we can group it with other related functions as a method in a class. From roy at panix.com Fri Aug 6 19:46:32 2004 From: roy at panix.com (Roy Smith) Date: Fri, 06 Aug 2004 19:46:32 -0400 Subject: PEP-0318 References: <41122FC2.1080608@interlink.com.au> <4114152f@nntp.zianet.com> Message-ID: Mark Bottjer wrote: > E. pie decorator at top of function body syntax > > def foo(arg1,arg2): > @classmethod > ... > > def bar(low,high): > @accepts(int,int) > @returns(float) > ... > [...] > * 0 Perhaps decorators should be allowed before or after the > docstring. If you have to choose, I'd choose making it before > the docstring. It's a pretty arbitrary decision (i.e. I can't see any strong arguments one way or the other) which means it's the kind of thing which is likely to not be remembered. I think I'm with you, decorators come first, then the docstring. But pick one and stick with it, so everybody does it the same way. > * - Lots of decorators will make it harder to find the start of the > function implementation. Then again, so will a large docstring. Do people anticipate having lots of decorators for a given function? From sbabbitt at commspeed.net Fri Aug 27 19:31:49 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Fri, 27 Aug 2004 16:31:49 -0700 Subject: Dynamic languages References: <278de0e.0408271349.26762174@posting.google.com> Message-ID: <1093650026.763899@news.commspeed.net> "Neuruss" wrote in message news:278de0e.0408271349.26762174 at posting.google.com... > I've been reading an article published in E-Week entitled "Microsoft > Lures Open-Source Programmer", which contains a definition for dynamic > languages as follows: > > "Dynamic programming languages enable programs to change their > structure as they run." > > I wonder if this definition is correct. > Can we define dynamic languages this way? > > http://www.eweek.com/article2/0,1759,1636906,00.asp I doubt that this is what they mean but a dynamic language is a language that is still evolving (Python) as opposed to a dead language (COBOL). They probably are referring to programs that can add and remove components during runtime. Tom From roy at panix.com Sun Aug 8 21:39:05 2004 From: roy at panix.com (Roy Smith) Date: Sun, 08 Aug 2004 21:39:05 -0400 Subject: PEP-0318 References: <41122FC2.1080608@interlink.com.au> <4114152f@nntp.zianet.com> <4116bc20$1@nntp.zianet.com> Message-ID: In article , Anthony Baxter wrote: > def doc(docstring): > def add_doc_string(func, docstring=docstring): > func.__doc__ = docstring > return func > return add_doc_string I don't understand the "docstring=docstring" in the argument list for add_doc_string. I suspect there's something subtle going on with scope rules, but I don't see it. From max at alcyone.com Mon Aug 2 13:50:55 2004 From: max at alcyone.com (Erik Max Francis) Date: Mon, 02 Aug 2004 10:50:55 -0700 Subject: Concerning classes (Newb question) References: <6c8fb5be.0408020947.67ef58e@posting.google.com> Message-ID: <410E7EFF.EEAEA4F2@alcyone.com> Cyrille Lavigne wrote: > I'm very new to the art of programming and I just learn OOP > in python. I want to know why the following bit of code crash. > Code: > class Exemple: > def __init__(self): > self.list=[] > self.var1=3 > > c=Exemple > print c.list, c.var1 You're binding c to the class, not an instance. To create a new instance, call the class: c = Exemple() -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ Everything's gonna be all right / Everything's gonna be okay -- Sweetbox From klappnase at web.de Sat Aug 7 07:34:50 2004 From: klappnase at web.de (klappnase) Date: 7 Aug 2004 04:34:50 -0700 Subject: Tkinter, Simple Table References: Message-ID: ellisjb at my-deja.com wrote in message news:... > Tkinter doesn't do tables very well... The closest thing I can think > of to what you want is the multilistbox recipe in the python cookbook, > but that's not going to handle multiple lines per 'cell' IIANM. > > -Jonathan > > Torsten Mohr wrote: > > Hi everybody, > > > > i'd like to have a small python script that creates a > > table (like in Excel) and where i can enter multiline > > text in the tables cells. > > > > Can anybody give me a hint where to look? > > > > Does TList do what i want? THe description looked good, > > but i didn't find an example for it. > > > > > > Regards, > > Torsten. Maybe Tktable is what you want (), I never tried it, but it sounds promising and it seems like there's a python wrapper included. Michael From max at alcyone.com Mon Aug 16 19:57:51 2004 From: max at alcyone.com (Erik Max Francis) Date: Mon, 16 Aug 2004 16:57:51 -0700 Subject: music resources References: Message-ID: <412149FF.A3FF732A@alcyone.com> Elaine Jackson wrote: > Is there such a thing as an executable language for music? If not, why > not? And > if yes, where can I find it? Naturally the ideal thing would be if > such a > language were implemented within python, but I would be willing to > learn a > lesser programming language if I had a reasonable assurance that it > had what I'm > looking for. I have, of course, googled for a solution, and I may have > even > found it, but if so I didn't recognize it as such. Any pointers will > be mucho > appreciado. I have a module which can allow you to construct notes, chords, and represent them on a keyboard, but it needs to be cleaned up and doesn't have any sound output (i.e., you can type in the chord symbol and it will show you the fingering on a keyboard). What kind of language were you actually looking for? -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ No need to tell her there's a world out there / She knows / She just doesn't seem worried at all -- Nik Kershaw From unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom Mon Aug 2 04:00:59 2004 From: unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom (Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.) Date: Mon, 2 Aug 2004 10:00:59 +0200 Subject: python tutes on win32 References: <1ZmdnZw7k-WA0ZDcRVn-rg@adelphia.com> Message-ID: Perhaps : http://www.geocities.com/tutenatura/ From webraviteja at yahoo.com Thu Aug 26 17:15:16 2004 From: webraviteja at yahoo.com (Ravi Teja Bhupatiraju) Date: 26 Aug 2004 14:15:16 -0700 Subject: Proposal for removing self References: <1gj4sup.hrowbz1bzo06mN%aleaxit@yahoo.com> Message-ID: aleaxit at yahoo.com (Alex Martelli) wrote in message news:<1gj4sup.hrowbz1bzo06mN%aleaxit at yahoo.com>... > Ravi Teja Bhupatiraju wrote: > ... > > > > class FooBar: > > __public__ = [Name, Age] > > def setName(name): > > Name = name > > > > Go ahead: learn about metaclasses and bytecode hacking and write your > custom metaclass to perform this. Except for the little detail that > you'll never get away with not quoting 'Name' and 'Age' in the > __public__ assignment, the rest is reasonably easy to perform. Publish > your metaclass and start campaigning for it. > > As long as you're just yakking about it ain't gonna happen -- become a > metaclass and bytecode expert and you can implement this in Python, or > convince somebody who is such an expert, for which the implementation > should be the job of a couple days tops. > > > > While I am complaining, a few other peeves ... > > > > Another thing is I dislike is having to use __ for *every* private > > variable. For *me* __private__ at the top of the class definition code > > would be more elegant. __readonly__ would be another nicety. > > That's an even easier job for a custom metaclass with very modest amount > of byecode hacking. I suggest you start with this one, really truly > VERY easy. In fact you could probably do it without any actual hacking > on the bytecode itself, just rewriting a few tables of strings in the > code objects of the functions that are the methods of the class. > > One impossible task (THAT would require hacking the Python parser and > changing things very deeply) as I already mentioned would be the form > you want for the assignment to __public__ (or similarly to > __private__etc). Those names are undefined (or worse defined globally) > and to teach Python (and human readers!) that for that one speclal case > of assignment to __public__ (or __private__), THAT one case only, > COMPLETELY different rules apply than ANYWHERE else in Python, well, > it's just as difficult as it is absurd. > > I suggest you tackle the 'look ma no quotes!' task last, after > everything else is working, because that one detail is going to take far > longer than everything else put together, even if you're learning about > metaclasses and bytecodes from scratch. > > > > Introducing the above attributes into the language would not likely > > break any existing Python code. > > If this peculiar behavior is limited to classes whose metaclass is your > custom RaviSpecial, "not likely" becomes "absolutely impossible", a > great enhancement. One more reason to implement this in a metaclass. > > > Just my 2c. > > Well make it three cents and do an implementation, if you really care. > Otherwise, it's just words... > > > Alex Aren't you being a bit touchy Alex? Now I am glad that I did not mention my wish list on properties and DBC :-). However, your post has been quite informative. So I can live with that. I wish I could rise up to your challenge and do all that stuff. Regretfully, my Python skills don't extend to metaclasses and especially "byte code hacking". Maybe you will explain those in your next edition of the cookbook :-). That said, I only could find one set of docs that could be called a on metaclasses. Those were by David Mertz and Michele Simionato. I could not get through them. I took comfort in the statement "Metaclasses are deeper magic than 99% of users should ever worry about" from the document. I am still looking for something I can understand. From nobody at nowhere.com Mon Aug 9 16:13:42 2004 From: nobody at nowhere.com (Fred) Date: Mon, 09 Aug 2004 22:13:42 +0200 Subject: VB-like GUI designer? References: <278de0e.0408090935.6d758a5d@posting.google.com> <4117c80d$0$3158$626a14ce@news.free.fr> Message-ID: On Mon, 09 Aug 2004 21:05:14 +0200, Olivier Thiery wrote: >I'm afraid it's wrong: Boa does include a (pretty usable) GUI builder, >although it (oddly) better works on windows than linux. It handles even >sizers. Thx for the tip. Digging deeper, I figured out how to get a GUI designer window. For newbies: In the Palette, select the New tab, click on the 5th icon which says wxApp, which generates two source files in the Editor window: wxApp1 and wxFrame1. Select wxFrame1, then select File > Frame Designer, and create objects by selecting widgets in the Palette window. >Wrong again: the last official release is 0.2.3 (see sf.net), but you can >search google for a more recent downloadable 0.2.8 tgz. OK, too bad it's not mentionned in the News section on their project page. I'll check it out. It can be downloaded here: http://boa-constructor.sourceforge.net/files/boa-constructor-0.2.8-snapshot.tgz Thx Fred. From in.aqua.scribis at nl.invalid Sat Aug 28 16:49:37 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Sat, 28 Aug 2004 22:49:37 +0200 Subject: my first class: Args In-Reply-To: <4130cf9d@nntp0.pdx.net> References: <4130cf9d@nntp0.pdx.net> Message-ID: Thanks for your comments. Especially the thing about using try/except is very useful. I knew about it, but just didn't "see" I could use it. Something I have to get used to. More comments below. Scott David Daniels wrote: > > def __iter__(self): > > "iterator set-up" > ^^ useless docstring -- presume the reader knows python > > if self._argc == 0 and sys.stdin.isatty(): > > self.usage() > > if self._argc == 0: > > self.infile = '' > > self._stdin = 1 > > self._in = sys.stdin > > else: > > self.infile = self._argv.pop(0) > > self._argc -= 1 > > self._stdin = 0 > > self._in = open(self.infile, 'r') > > return self > ^^ > try: > self.infile = self._argv.pop(0) > except IndexError: > if sys.stdin.isatty(): > self.usage() # Doesn't return > else: > self.infile = '' > self._stdin = True > self._in = sys.stdin > else: > self._stdin = False > self._in = open(self.infile, 'r') > return self This is the only instance I didn't follow your recommendation to use try/except. It is a binary choice: do we use files given on the command line or stdin? Neither is more natural than the other. Also, it splits up lines of code that belong together. Here is my re-write: def __iter__(self): "iterator: set-up" if self._argv: self.infile = self._argv.pop(0) self._in = open(self.infile, 'r') self._stdin = False else: if sys.stdin.isatty(): self.usage() # Doesn't return self.infile = '' self._in = sys.stdin self._stdin = True return self The exceptional case is there be no input, and the simplest test here seems to be a simple if-statement. > > return self.next() > ^^ Loop rather than recur unless you have a good reason. Your solution looks much better. > > if __name__ == '__main__': > > ... > ^^ also nicer to be able to test from included version: > > def demo(): > ... > > if __name__ == '__main__': > demo() That doesn't seem very useful. It depends on command line arguments. If they are missing, it does a sys.exit(), probably not what you want unless you run the module stand-alone. -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From jaydonnell at yahoo.com Tue Aug 24 14:06:37 2004 From: jaydonnell at yahoo.com (Jay Donnell) Date: 24 Aug 2004 11:06:37 -0700 Subject: urllib hangs References: Message-ID: > have you actually looked at the comments in that > module yet? It does say exactly what you need to do... I don't understand the inner workings of the socket or timeoutsocket modules. On it's face it doesn't make sense that importing timeoutsocket would magically override the behaviour of socket without me doing anything else to the socket module. This appears to be what happens, but it certainly isn't clear to someone that doesn't know how it works. Here is what timeoutsocket says, "After this module has been imported, all socket creation goes through this shim. ". After reading this I was unsure if I needed to install timeoutsocket.py into the base python distro because, again, it seems odd that simply dropping timeoutsocket.py into my cwd and importing it will override the behaviour of the socket module. This didn't say "exactly what I need to do". It assumed a few things that seemed odd to me. How does timeoutsocket.py " insert a shim into the socket module."? What does that mean??? It wasn't clear! In the time it took you and the other guy to criticize me you could have simply said, "yeah, just drop it into your cwd and import it". P.S. - I really do appreciate the help that Benjamin gave. Here is what timeoutsocket says. -------------------------------------------------------------------------- "This module enables a timeout mechanism on all TCP connections. After this module has been imported, all socket creation goes through this shim. As a result, every TCP connection will support a timeout. The beauty of this method is that it immediately and transparently enables the entire python library to support timeouts on TCP sockets. As an example, if you wanted to SMTP connections to have a 20 second timeout: import timeoutsocket import smtplib timeoutsocket.setDefaultSocketTimeout(20) The timeout applies to the socket functions that normally block on execution: read, write, connect, and accept. If any of these operations exceeds the specified timeout, the exception Timeout will be raised. --------------------------------------------------------------------- From rnichol_rrc at yahoo.com Mon Aug 9 01:04:04 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Mon, 09 Aug 2004 00:04:04 -0500 Subject: how many bytes in an int In-Reply-To: <4116f8ee$0$8076$a1866201@newsreader.visi.com> References: <9ACRc.1523$bJ2.9739@news1.mts.net> <4116f8ee$0$8076$a1866201@newsreader.visi.com> Message-ID: Grant Edwards wrote: > On 2004-08-09, Reid Nichol wrote: > > >> I was wondering if I could control how many bytes are in an int and >>the byte order. In C/C++ I can use int32 but how do I do this in >>python? How can I control byte order? > > > I suspect you want to use the "struct" module -- but it's a > guess, since you haven't really said what it is you're trying > to accomplish. > I'm thinking of writing a movie file encoder (probably avi). So, I need to output DWORD (lookup revealed its a 4-byte int) to a binary file. Therefore I need to know whether this can be done in python or not, which will tell me whether I'll try to do it or not. But, since the 64-bit archecture is out, short, long, etc may change there meanings quite soon. From what I've read in the struct module docs I can only tell it that it's a short, long, etc. but not whether it's exactly a 4-byte int. Is there a way to do this? From alberto.mantovaniNOSPAM at bologna.marelli.it Wed Aug 18 09:03:09 2004 From: alberto.mantovaniNOSPAM at bologna.marelli.it (Alberto) Date: Wed, 18 Aug 2004 13:03:09 GMT Subject: get windows process Message-ID: <412352e4.25110247@news.marelli.it> Hi, someone has an idea how to get Window process from python script? I mean that listed in the "Task Manager Windows". thanks Alberto From rob at nospam.net Tue Aug 17 19:12:22 2004 From: rob at nospam.net (Robert Ferber) Date: Wed, 18 Aug 2004 01:12:22 +0200 Subject: Databases: Getting values by column name References: Message-ID: Istvan Albert wrote: > Robert Ferber wrote: > > >> I already know the stuff on that page, it's really slowing you down :-( > > Your response to Skip Montaro's post demonstrates that > you zipped trough it without paying much attention to what > he said, so I think slowing a bit down would actually help > you here. I am already looking for that solution for several days already, I'm quite a bit frustrated by now, sorry for my inpoliteness. However Skip's solution almost works, at least the import statements and the connect statement with cursorclass=MySQLdb.cursors.DictCursorNW don't report an error. > As other pointed out you have everything you need, using dtuple.py at: > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81252 Of course I looked at that webpage, but if I'm not mistaken, mx.ODBC.Windows is only available on Windows which makes it useless for me, I can not find a ODBC Package for my Linux distribution and the webpage doesn't give the slightest hint what the package name is (which probably would make searching for it too easy) or where to get it. My distribution (SUSE) comes with dozens of Python-packages, but none have "mx" or "odbc" in their name. So after wasting another 20 minutes I discarded that webpage as useless and responded to the only post that looked promising which was Skip's. > or db_row at: > > http://opensource.theopalgroup.com/ http://opensource.theopalgroup.com/files/ADOdb.html Purpose: Python DB-API 2.0 interface to Microsoft ADO objects Compatibility: Python 2.0 Requires: Python Win32 extensions, ADO 2.5+, mx.DateTime Revision: Version 0.10 - Alpha quality code I didn't know that the Python-community was infested by so much Microsoft-only code. Both of your hints seem to be Win-only. And it's "Alpha quality". Robert From sbabbitt at commspeed.net Thu Aug 26 21:43:52 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Thu, 26 Aug 2004 18:43:52 -0700 Subject: Newbie question on dictionary!!! References: <494182a9.0408261150.a4c767f@posting.google.com> Message-ID: <1093571542.701929@news.commspeed.net> "Balaji" wrote in message news:494182a9.0408261150.a4c767f at posting.google.com... > Hello everybody... > > I want to ask a simple question. > > Suppose I have an list say g=['a','b','c','d'] > > and I have an dictionary say k={'b':20,'a':10} > > Now I want to sort this dictionary on the basis of the list and if it > doesnt find any of the element in the list then I wud like to replace > it with zero.. > > so I would like to modify k into {'a':10,'b':20,'c':0,'d':0} > > I have tried all the built in associated with dict and lists but was > not able to come up with an solution... > > Can anyone help... Dictionaries are not sortable but you can easily access the values in an sorted order, list = ['a','b','d'] dict = {'a':123,'c':456,'b':789} newdict = {} l = dict.keys() + list l.sort() for i in l: if dict.has_key(i): newdict[i] = dict[i] else: newdict[i] = 0 dict = newdict That should do it, Tom print dict[i] Tom From __peter__ at web.de Tue Aug 10 08:38:42 2004 From: __peter__ at web.de (Peter Otten) Date: Tue, 10 Aug 2004 14:38:42 +0200 Subject: Multiple inheritance with a common base class References: <1092137872.2624.16.camel@dicaprio.akademie1.de> Message-ID: Markus Bertheau wrote: > ? ???, 10.08.2004, ? 13:37, Markus Bertheau ?????: > > Also I observe that the instance will in fact _not_ have a single copy > of the data attributes used by the common base class. The following > example demonstrates this: > > class CommonBase: > def __init__(self): > self.no = 0 > def setNo(self, no): > self.no = no > > class LeafA(CommonBase): > def __init__(self): > CommonBase.__init__(self) > print("CommonBase.no: %i" % self.no) > CommonBase.setNo(self, 3) > > class LeafB(CommonBase): > def __init__(self): > CommonBase.__init__(self) > print("CommonBase.no: %i" % self.no) > CommonBase.setNo(self, 4) > > class Multi(LeafA, LeafB): > def __init__(self): > LeafA.__init__(self) insert print self.no to verify that at this point self.no is indeed 3. LeafB.__init__() then calls CommonBase.__init__() which in turn sets self.no to 0 again. > LeafB.__init__(self) > > m = Multi() > > It outputs: > > CommonBase.no: 0 > CommonBase.no: 0 > > If there was only one copy of the common base class, I'd have expected > an output similar to > > CommonBase.no: 0 > CommonBase.no: 3 > > This renders multiple inheritance pretty useless for me. > > Can someone clear this all up and tell me how multiple inheritance is > supposed to work in python? Remember that __init__() is just a method like any other that will be called automaticallly after the instance is created - not a constructor. If you call it explicitly it will be executed no matter where you are in your program. If you want to ensure that all methods with the same name are executed once across an inheritance hierarchy, have a look at super(). If you know some C++ it might help to regard all python base classes as virtual. http://www.python.org/2.2.2/descrintro.html http://www.python.org/2.3/mro.html might also interest you - as a bonus, the latter has some nice ascii-art :-) Peter From a.neudecker at uni-bonn.de Mon Aug 9 09:29:17 2004 From: a.neudecker at uni-bonn.de (Andreas Neudecker) Date: Mon, 09 Aug 2004 15:29:17 +0200 Subject: Find out the file name of a module from inside the module? Message-ID: Hi. I know you can read the filename of a program as sys.argv[0]. But what about modules? Is there a similar way to find out the file name of a module (called by some other module or program) from inside this module? Kind regards Andreas From sylvain.thenault at nospam.logilab.fr Mon Aug 16 04:25:22 2004 From: sylvain.thenault at nospam.logilab.fr (Sylvain Thenault) Date: Mon, 16 Aug 2004 10:25:22 +0200 Subject: xml attributes question References: Message-ID: On Sun, 15 Aug 2004 12:25:58 +1000, Ajay wrote: > hi! > > i am trying to print the keys of a NamedNodeMap which contains the > attributes of a element. > for the element, > CatalogExample > > i expect > attribs = plist[0].attributes > attribs.keys() > to print "ref" #plist[0] is the data element shown above It however prints > the following > [(None, u'ref')] > > why? because of xml namespaces. Any xml element / attribute is fully caracterized by it's name and the namespace it belongs to. None is used to represent the empty namespace. With the following element : ... your sample code would have printed : [(u'mynamespace', u'ref')] -- Sylvain Th?nault LOGILAB, Paris (France). http://www.logilab.com http://www.logilab.fr http://www.logilab.org From lbates at swamisoft.com Fri Aug 27 10:00:55 2004 From: lbates at swamisoft.com (Larry Bates) Date: Fri, 27 Aug 2004 09:00:55 -0500 Subject: A newbie in need.... References: <9c3edc58.0408261609.6640e400@posting.google.com> Message-ID: Reportlab (www.reportlab.org) has a good graphics package (Reportlab Graphics). HTH, Larry Bates Syscon, Inc. "Chris Patton" wrote in message news:9c3edc58.0408261609.6640e400 at posting.google.com... > Hey everybody. I'm trying to make a program that requires a 2D field > to run. Besides "curses" or "ncurses", is there a python module that > will create a graph? > > --Thanks for the help! From ndeskins at ecn.purdue.edu Wed Aug 18 11:43:37 2004 From: ndeskins at ecn.purdue.edu (Aaron Deskins) Date: Wed, 18 Aug 2004 10:43:37 -0500 Subject: Newbie question about file input In-Reply-To: <4122328e$0$8079$a1866201@newsreader.visi.com> References: <4122328e$0$8079$a1866201@newsreader.visi.com> Message-ID: Grant Edwards wrote: > I don't understand the question. Perhaps I should have been more specific. What does python store when you read a blank line? Nothing? A null variable? A '\n'? How about this: import string import sys zf=open(sys.argv[1],'r') it = 0 while 1: line = zf.readline() print line rs = line.split() print rs if rs[0]== '[Event': it+=1 print it if not line: break zf.close() This fails when it tries the "if rs[0]== '[Event':" statement. rs[0] doesn't exist (or is blank?) for a blank line in my input file. Another code: import string import sys zf=open(sys.argv[1],'r') it = 0 while 1: line = zf.readline() it+=1 if not line: break zf.close() print it This only ends when the end of file is reached. Why not when a blank line is read? How does python treat the variable line (after a readline) differently after a blank line or the last line of the file? -- Aaron Deskins Graduate Student Chemical Engineering Purdue University From jmeile at hotmail.com Thu Aug 5 12:38:55 2004 From: jmeile at hotmail.com (Josef Meile) Date: Thu, 05 Aug 2004 18:38:55 +0200 Subject: ZServerSSL and Certificates In-Reply-To: <3222fe00.0408050548.43b5f0fd@posting.google.com> References: <3222fe00.0408050548.43b5f0fd@posting.google.com> Message-ID: <4112611e$1@pfaff2.ethz.ch> Hi Sean, > Hi, > > I have been able to get ZServerSSL to work with the demo certs, and > with some self generated. However I'm really not clear on > certificates in general, and we're about to try it with real certs > from a real CA. I'm not a guru either, but I guess I know what your problem is. By the way, if I were you, I would try to use apache+mod_ssl+mod_rewrite instead of m2crypto. I have heard apache is faster than the later and you won't have ZServer exposed to the world. If you want more info about this, search the zope mailing list on list.zope.org. > What I did this last go-around was to snag CA.pl and visit > https://www.entrust.com/freecerts/ag_server_req.cfm I haven't tried it, but it looks good. > So I take privatekey.pem and the ca cert and combine them into a > single file called ca.pem. > > Then I: > > # ./CA.pl -sign > # openssl rsa < newreq.pem > newkey.pem > > and I combine the server cert and newkey.pem and call it server.pem. I think more or less that's why I did. > However, when I try and access the site I get: > > Microsoft IE6 first shows a request for a cert to use, I click OK to > bypass it then a warning dialog that the ca is not trusted. > > Mozilla diaplays a panel warning that there are three potential > problems. > > In either case if I ignore the warnings I get a secure connection. > > I need to understand what I'm doing wrong here. Perhaps the Common Name (CA) of your cert isn't the same as the url of your website. Check this on the cert properties on the certificate manager of Mozilla. Other problem could be that "entrust.com" isn't listed as Trusted Root Certification Authority (Look on the certificate manager of mozila or IE). I only found "entrust.net". I guess the certificates generated by this website aren't intended for business. I think that if you want your certificate to be sign by some well known CA, you have to pay. Anyway, the warning is not bad. It depends on your needs. Regards, Josef From unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom Fri Aug 6 13:12:11 2004 From: unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom (Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.) Date: Fri, 6 Aug 2004 19:12:11 +0200 Subject: Prothon is switching to the .NET platform References: <000401c47b59$32539220$0d01a8c0@MarkVaio> Message-ID: Hi ! I understand ; but, perso, I think : "it's a good new" (because it is a certain guarantee of interworking). I will await the dotnet version, for to test prothon. Michel Claveau From zanesdad at bellsouth.net Fri Aug 20 10:36:49 2004 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Fri, 20 Aug 2004 10:36:49 -0400 Subject: Newbie to XML in Python In-Reply-To: References: Message-ID: <41260C81.4020401@bellsouth.net> Jens Thiede wrote: > XML in Python doesn't seem easy or intuitive. All I need to do, is to > interpret a small piece of XML in which I store data for the contents > of an autorun menu. What is the quickest/most effective way to do this? > > What should I use for this; SAX or DOM - and which parser of ether > one, or niether (if there is a third option)? > > What are your views, > > Jens. depends.... I've had a lot of success parsing smallish XML files with DOM. The thing I like about DOM is that you are the one walking through the XML as you see fit by getting child nodes and attributes and blah blah blah. With SAX (which I've not used much), you setup handlers, the methods of which get called when tags are hit, which pretty much forces you to setup a state machine to keep track of where you are in the document. I looked into xpath, but wasn't able to quickly figure out how to update attributes, but looked great just for querying an XML file. I don't know the format of the autorun file you mentioned, but if it's small and all you need to do is query it, you may want to expand your sights to include xpath. Jeremy From lopexx at autograf.pl Thu Aug 19 05:37:49 2004 From: lopexx at autograf.pl (lopex) Date: Thu, 19 Aug 2004 11:37:49 +0200 Subject: Best programming language In-Reply-To: <2oik8pFaqm1qU1@uni-berlin.de> References: <5155aad2.0408161008.40c57262@posting.google.com> <2oik8pFaqm1qU1@uni-berlin.de> Message-ID: Greg Ewing wrote: > Ravi Teja Bhupatiraju wrote: > >> Just type programming and Python is second. First is C. > > > From which the conclusion is obvious: While C can > be used for programming, it doesn't deserve to > be called a language. :-) > So python is built on top of something that is not a language at all ? Marcin Mielzynski From noone at here.com Thu Aug 19 13:49:59 2004 From: noone at here.com (M. Clift) Date: Thu, 19 Aug 2004 18:49:59 +0100 Subject: get last two in a length of unknown length? References: Message-ID: Cheers Phil : ) From dd55 at cornell.edu Fri Aug 20 09:47:06 2004 From: dd55 at cornell.edu (Darren Dale) Date: Fri, 20 Aug 2004 09:47:06 -0400 Subject: My only complaint about Python In-Reply-To: References: Message-ID: I'm going to be out of touch for a few days... sorry to leave this while its still being discussed. From iketo2 at netscape.net Sun Aug 29 00:30:52 2004 From: iketo2 at netscape.net (Isaac To) Date: 29 Aug 2004 12:30:52 +0800 Subject: Generator expressions v/s list comprehensions References: <1gj8y77.6qshr41q531veN%aleaxit@yahoo.com> Message-ID: <87llfywooz.fsf@sinken.local.csis.hku.hk> >>>>> "Mahesh" == Mahesh Padmanabhan writes: Mahesh> Is returning a list really a limitation considering that Mahesh> lists can be transformed quite easily? Yes. (1) You lose your memory, and (2) you can't use whatever you get outside after the list comprehension hidden loop when evaluating it. Let's have some examples. You lose you memory because you have to generate a whole list, which might be unnecessary because your processing eventually don't need it. It is the same as the difference between range() and xrange(). E.g., you might write for a in [x*x for x in range(100000)]: print a you have to wait until you generate the 100k list, and at that time you start printing out x*x for each of the values. The middle-ground for a in [x*x for x in xrange(100000)]: print a save half the memory, but still needs to generate the 100k list, and you have to wait a long time before you print the first result. Once you get generator expression, you can say for a in (x*x for x in xrange(100000)): print a and it will do the same thing, except that you don't need to wait at the beginning, and at no instant there is a 100000 element list sitting in memory. [N.B.: Of course, in this simple example you'll instead write for x in xrange(100000): print x*x but sometimes things are not as easy, e.g., what you'd do if you have to pass the abstraction "x*x in xrange(100000)" into a function as a function argument?] Now let's turn to the second point: with list comprehension, the evaluation of an element happens after the evaluation of previous elements, but before the previous elements are being used. At times this makes things hard to achieve or even impossible (and at that time you have to throw up your hands and write a generator function instead). E.g., suppose you have this: import time hash = {} def process1(x): for i in xrange(1, 11): hash[x * i] = 1 def process2(x): for i in xrange(2, 12): hash[x * i] = 1 if time.time() % 2: process = process1 else: process = process2 Now you have a loop, which you want a neater way to rewrite: for x in xrange(1000): if not hash.has_key(x): process(x * x) in such a way that you don't need to let others specify the exact loop to run. Intuitively you'd like to write a list comprehension to do that. So you'd like to write for y in [x*x for x in xrange(1000) if not hash.has_key(x)]: process(y) and let others pass the list into the function. But this makes hash.hash_key(x) to be called when none of the process(y) is called, so it breaks completely. With generator expression, you write: for y in (x*x for x in xrange(1000) if not hash.has_key(x)): process(y) which do the trick. Note that now "x*x for x in xrange(1000) if not hash.has_key(x)" is an object, and you can move it out of the function, ask somebody else to pass it to you---which you can't do in the original for loop. I.e., now you can say def func(gen): for x in gen: process(x) and let somebody call func(x*x for x in xrange(1000 if not hash.has_key(x))) Without generator expression, to achieve this you must code a generator function. So generator expression helps you to write simple generators. Regards, Isaac. From calidusdk at hotmail.com Sat Aug 21 13:55:40 2004 From: calidusdk at hotmail.com (Artemisio) Date: 21 Aug 2004 10:55:40 -0700 Subject: ZeroDivisionError: float division (baby steps) References: <6daa8765.0408191133.2f2e22e3@posting.google.com> Message-ID: <6daa8765.0408210955.2d2efc39@posting.google.com> danb_83 at yahoo.com (Dan Bishop) wrote in message news:... > calidusdk at hotmail.com (Artemisio) wrote in message news:<6daa8765.0408191133.2f2e22e3 at posting.google.com>... > > I am a non programmer who just started with Python. So far I love it. > > > > I would appreciate if you could help me fix this error I get taking this > > exercise: > > > > count= 0 > > As other posters have mentioned, the problem is with your indentation. > But I can't resist giving advice. > > First of all, I recommend starting every file with the line "from > __future__ import division". You will then no longer need to worry as > much about writing things like > > > sum= 0.0 > > because you'll get the same division results from "sum=0". (If you > really want integer division, use the // operator.) > > > number= 1 > > print "Enter 0 to exit the loop" > > > > while number != 0 : > > number= input("Enter a number: ") > > > > count= count + 1 # [indentation corrected] > > sum= sum + number # [indentation corrected] > > > > count= count -1 > > Instead of using sentinel values, it's possible to put the loop > condition in the middle of the loop, like this: > > print "Enter 0 to exit the loop" > > while True: # loop "forever" > number = input("Enter a number: ") > if number == 0: # condition for exiting the loop > break > count += 1 > sum += number > > Note that count no longer needs to be decremented by 1 at the end, > because if you enter 0, it doesn't get incremented. > > Also note that assignments of the form x=x+y can be abbreviated as > x+=y, so you don't have to write the left-hand side twice. The > benefit will be more noticeable for statements like > > verboseName[complicated + index + calculation].verboseAttribute += 1 > > > print "The average is: ", sum / count > > #the error is in the above line > > Often, the real error is long before the line that gives you the error > message. > > But you might want to modify this line to deal with the situation that > count == 0. > > if count == 0: > print "You didn't enter any numbers!" > else: > print "The average is: ", sum / count Thank you very much, Dan! When one is a total beginner every bit of advice is most welcome. As I write I am having a closer look to your tips. From __peter__ at web.de Sat Aug 14 12:06:01 2004 From: __peter__ at web.de (Peter Otten) Date: Sat, 14 Aug 2004 18:06:01 +0200 Subject: IronPython-0.6 is now available! References: <278de0e.0407281353.27b6a457@posting.google.com> <278de0e.0408100515.5fd3740c@posting.google.com> <278de0e.0408101929.cc3d8c8@posting.google.com> Message-ID: Neuruss wrote: > performance, you can code this parts in C#. Believe me, I'm just a > newbie, but I can say that translating from Python to C# (if you > already have the python prototype) is a matter of minutes. No > extensions, no hassle...everything compatible and smooth. I that were true, no translation should be needed and no benefits of such a translation be expected. But then I'm just a skeptic, don't believe me. Try it. Peter From raims at dot.com Wed Aug 18 18:20:44 2004 From: raims at dot.com (Lawrence Oluyede) Date: Thu, 19 Aug 2004 00:20:44 +0200 Subject: static class methods and data members References: Message-ID: <1n74wzbu8718i$.pqq3qsfy7bdn$.dlg@40tude.net> In data 18 Aug 2004 14:41:46 -0700, Neil Zanella ha scritto: > It seems to me that > any truly OO programming language should support these so I'm sure that Python > is no exception, but how can these be defined/implemented in Python? Currently > I have Python version 2.3 installed on my system. Why are you sure? I've used static methods two or three times in Python, anyway you can gain something similar with the aid of staticmethod http://www.python.org/2.2.1/descrintro.html#staticmethods -- Lawrence (l dot oluyede at virgilio dot it) "If the implementation is hard to explain, it's a bad idea." from The Zen of Python by Tim Peters From mark_bottjer at hotmail.com Wed Aug 11 13:33:11 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Wed, 11 Aug 2004 13:33:11 -0400 Subject: @decorators In-Reply-To: References: <10h73e5kh1et536@news.supernews.com> <4113e5be@nntp.zianet.com> Message-ID: <411a5858$1@nntp.zianet.com> Mark 'Kamikaze' Hughes wrote: > You can already do pre- and post-conditions without new syntax: > > import types > def intdiv(a, b): > # preconditions > assert type(a) == types.IntType > assert type(b) == types.IntType > assert b != 0 > rc = None > try: > # body > rc = a // b; return rc > finally: > # postconditions > assert type(rc) == types.IntType > > If assignment was an expression, that return would be a little nicer, > but it's acceptable. Sorry, but to me this is ugly. The preconditions aren't so bad (in fact, much of my code has just such lines in it), but that postcondition block is awful. It looks arbitrary, hides the real "meat" of the function, and requires the construction of an exception frame when one shouldn't really be needed. It works, certainly, but I think we'll have to "agree to disagree" about how acceptable this syntax is. :) > Mark Bottjer > wrote on Fri, 06 Aug 2004 16:10:37 -0400: > >> Exactly. What's more, I don't think that decorators are really the >> ideal way to express DBC, either. For one thing, pre and post >> conditions often want access to at least the argument list, and often >> to the internal variables of the definition. I don't think that this >> will be possible with the decorators as proposed, since they are >> outside the scope of the function. After more thought, I think that it might be possible using decorators and subfunctions. Shouldn't the following be workable? import types @pre_and_post def intdiv(a, b): def __pre(): assert type(a) == types.IntType assert type(b) == types.IntType assert b != 0 def __post(): assert type(rc) == types.IntType return a // b Where pre_and_post effectively wraps intdiv with the statement sequence: intdiv.__pre() try: return intdiv( *args) finally: intdiv.__post() This is functionally equivalent to your example (it even still requires the try/finally). But I suggest that this version is more understandable because it breaks the code up by what it does: __pre collects all the preconditions, __post collects all the postconditions, and the body is left alone. Theoretically, we could even globally enable or disable DBC by having pre_and_post switch on some global variable, which would not be possible with the conditions coded inline. I'm not savvy enough with Python internals to code this up myself, but I'm sure someone out there either can, or can tell me why it won't work. -- Mark From brent.hughes at comcast.net Fri Aug 20 23:26:00 2004 From: brent.hughes at comcast.net (Brent W. Hughes) Date: Sat, 21 Aug 2004 03:26:00 GMT Subject: Why are strings immutable? Message-ID: I kind of hate to have to convert a string into a list, manipulate it, and then convert it back into a string. Why not make strings mutable? From sbabbitt at commspeed.net Fri Aug 6 09:43:39 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Fri, 6 Aug 2004 06:43:39 -0700 Subject: [Newby question] List comprehension References: Message-ID: <1091800212.120448@news.commspeed.net> "Eelco Hoekema" wrote in message news:pan.2004.08.06.13.22.50.75041 at xs4all.nl... > > I'm trying to get a list of tuples, with each tuple consisting of a > directory, and a list of files. I only want a tuple if and only if the > filtered list of files is not empty. And, i want the list of files in the > tuples to be filtered. For this, i came up with the following code: > > > > # song filter: will return true if the file seems to be an mp3 file. > # (may not be the best way to do this) > def song(f): > (name, ext) = os.path.splitext(f) > return ext.lower() == '.mp3' > > # list comprehension walking through a directory tree > [(root, filter(song, files)) for (root, dir, files) in os.walk(os.path.abspath('.')) if filter(song, files)] > > > > > Now, this will work. However, it seems kind of silly to call the filter > twice. Is there a way to keep this in one list comprehension, but with > just filtering once? > > eelco > > How about, fltres = filter(song, files) [(root, fltres ) for (root, dir, files) in os.walk(os.path.abspath('.')) if fltres] Tom From siona at chiark.greenend.org.uk Thu Aug 26 11:06:00 2004 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 26 Aug 2004 16:06:00 +0100 (BST) Subject: Proposal for removing self References: <412ddf8d$0$275$edfadb0f@dread12.news.tele.dk> Message-ID: Max M wrote: >You don't have to use self. You could simply use underscore '_' instead. When I started using Python for developing my own bits and pieces I got into the habit of using 'I' instead of 'self'. Means pretty much the same thing, stands out better in code, takes up less space on a line, and is two keystrokes shorter. ... >But other Python programmers will hate you for it ;-) ... And then stopped when I got the job of maintaining other people's Python code and writing stuff that other people would have to use, if not actively maintain. Going back to look at C++ code (whoever wrote it) makes me realise how helpful it is to have an explicit marker as to what's belongs to a class and what doesn't. And before anyone mentions Hungarian notation, (a) is 'self.' *really* that much more of an imposition over 'm_'? and (b) it's not useful for distinguishing methods from functions. -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From joachim at ee.ucla.edu Sat Aug 14 17:32:51 2004 From: joachim at ee.ucla.edu (Joachim Dahl) Date: Sat, 14 Aug 2004 14:32:51 -0700 Subject: extending the builtin array class from C Message-ID: I would like to inherit the builtin array class and write som extension methods in C. Other people have suggested that I use numarray for that, but all I want is a simple continuous C array of doubles, and a way to access the array directly from some C extension methods. I thought it would be possible to change the "xxsubtype.c" to accomodate my needs, but when it comes to actually defining the "array" class I am a bit lost. There are no header files, so how do I define the "array type? The init method for the spamdict type of xxsubtype.c module looks something like: static int spamdict_init(spamdictobject *self, PyObject *args, PyObject *kwds) { if (PyDict_Type.tp_init((PyObject *)self, args, kwds) < 0) return -1; self->state = 0; return 0; } How would I replace the PyDict_Type with an array type? Or is it not possible to extend all builtin classes from C? Thanks, Joachim From jbors at mail.ru Wed Aug 18 02:46:02 2004 From: jbors at mail.ru (Dmitry Borisov) Date: Tue, 17 Aug 2004 23:46:02 -0700 Subject: mp3 fft with python References: <4122B41F.1020303@colorado.edu> Message-ID: <002401c484ef$0b91a100$0200a8c0@amr.corp.intel.com> From: "Garett Shulman" Sent: Tuesday, August 17, 2004 6:42 PM Subject: mp3 fft with python > Hello, I would like to do a fft on an mp3 in python. I beleive I have > all of the fft stuff straight in my mind but am not sure of the best way > to get the sample data into a python array. I ran accross a web site a > while back which suggested using sox to convert a wav file into a raw > sample file and then open the raw file with python. However, I did not > bookmark this site when I came accross it and cannot seem to find it > now. If anyone has any suggestions as to a good way to get sample data > out of an mp3 and into a python array for an fft I would greatly > appreciate your suggestions. Thanks a lot. -Garett Not sure if it'll work for you. But here it is: SAMPLES= 500 BANDS= 20 NUM_FREQS= 256 import pymedia.audio.acodec as acodec import pymedia.audio.sound as sound dec= acodec.Decoder( 'mp3' ) analyzer= sound.SpectrAnalyzer( 1, SAMPLES, NUM_FREQS ) ... s= f.read( 20000 ) while len( s ): r= dec.decode( s ) if len( r.data ): # Get fft info as bands bands= analyzer.asBands( BANDS, s ) freqs= analyzer.asFrequencies( s ) ... http://pymedia.sourceforge.net You may need to take a look at the examples/sound_viz.py in the source tarball. Dmitry/ From jblazi at hotmail.com Mon Aug 16 09:03:51 2004 From: jblazi at hotmail.com (jblazi) Date: Mon, 16 Aug 2004 15:03:51 +0200 Subject: Why does this (very simple piece of) code does not work? Message-ID: import os L = os.listdir('.') for x in L: print '!'+x+'!'+x[0] if x != 'rename.py': y = 'Kapustin (Hamelin): '+x os.rename(x,y) I get Traceback (most recent call last): File "", line 9, in ? OSError: [Errno 22] Invalid argument TIA, jb From gohaku at earthlink.net Wed Aug 11 09:36:17 2004 From: gohaku at earthlink.net (gohaku) Date: Wed, 11 Aug 2004 09:36:17 -0400 Subject: Capturing repeating group matches in regular expressions In-Reply-To: <4119F7B6.6090003@xtra.co.nz> References: <4119F7B6.6090003@xtra.co.nz> Message-ID: <6C440902-EB9B-11D8-AAF7-000A9574CFD8@earthlink.net> On Aug 11, 2004, at 6:40 AM, James Collier wrote: > To illustrate, what I want is: > > >>> re1 = re.compile("([a-z]W)([a-z]X)+([a-z]Y)"); > >>> mo1 = re.match("aWbXcXdXeXfY"); > problem with re.match, used re1.match > >>> print mo1.groupsButNotAsWeKnowIt() > ('aW','bX','cX','dX','eX','fY') > > instead of > > >>> print mo1.groups() > ("aW", "eX", "fY") > > ... which captures only the last match from the second group. This is somewhat off-topic, but I am using finditer: for m in re.finditer('([a-z]W)','aWbWcXdXeWfY'): print m.groups() #aW #bW #eW I would like to compile the regex instead of using finditer. How do I do this? Thank you. -gohaku From stnchris at xmission.com Fri Aug 13 18:56:17 2004 From: stnchris at xmission.com (Steve Christensen) Date: Fri, 13 Aug 2004 22:56:17 +0000 (UTC) Subject: Flython References: <2o4m5pF6apnoU3@uni-berlin.de> Message-ID: In article <2o4m5pF6apnoU3 at uni-berlin.de>, Daniel Ellison wrote: > Dave Benjamin wrote: > >> I just want to say, for the record, that if anyone can successfully build a >> Python compiler that can produce Flash bytecode, I will personally allow >> you to throw *any number of pies* in my face, in as public of a ceremony as >> you desire. Furthermore, I will match you 50/50 in the cost of the pies. > > Wow, that's one heavy challenge! Either Dave thinks it just can't be > done, or he really, /really/ wants this compiler. Or, he really likes pie. -Steve From simoninusa2001 at yahoo.co.uk Mon Aug 16 12:02:19 2004 From: simoninusa2001 at yahoo.co.uk (simo) Date: 16 Aug 2004 09:02:19 -0700 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> <30260531.0408131853.18ec2446@posting.google.com> Message-ID: <30260531.0408160802.75cae33f@posting.google.com> Peter Hansen wrote: [snip] > > I'm a Perl programmer at heart - well that and PHP, plus the odd > > dabbling in C/C++/C# etc. > > Anyway, the thought of indentation instead of curly braces really put > > me off to start with, > Ah, good. Someone who was really there, instead of hearsay. Hehe, thought that said "heresy" for a moment! ;o) > Please, *why* did it put you off? I really don't know, just opposition to change, I'm ashamed to say! I just couldn't think how you would enclose areas of code without braces - until you've seen some properly indented Python source, it is hard to visualise. > Didn't you already indent your code consistently? Yes, personally, but sometimes it's hard when you're working on code that has been used by 3 other people with different indentation habits and even different editors - for example, one chap here uses two spaces to ident, whereas I've always used 4, nothing like coding standards eh?! > Didn't you think that the removal of those braces would immediately > make the code more readable (fewer lines, fewer extra cruft to > distract the eye) and easier to type? The removal of things like $ @ % { etc. appealed to me (then those fsckers went and put @decorators into 2.4!) > I'm curious why more people don't have "neat!" as their very > first thought on encountering this, rather than "yuck!". Possibly unfathomable, all I can say is it's opposition to change (practically every other language does the braces thing) and also it's hard to visualise until you see a big chunk of Python code - a "Hello World!" doesn't really show the benefit of removing all that junk. I have a C++ programer friend who thinks Python is a joke and is not OOP as it doesn't have proper encapsulation, can you imagine getting him to lose his braces? (wow that came out wrong!) From apardon at forel.vub.ac.be Tue Aug 31 08:14:33 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 31 Aug 2004 12:14:33 GMT Subject: Generator expressions v/s list comprehensions References: <1gj8y77.6qshr41q531veN%aleaxit@yahoo.com> Message-ID: Op 2004-08-28, Alex Martelli schreef : > Mahesh Padmanabhan wrote: > >> Hi, >> >> When list comprehension was added to the language, I had a lot of >> trouble understanding it but now that I am familiar with it, I am not >> sure how I programmed in Python without it. > > Oh good. > >> >> Now I see that generator expressions have been added to the language >> with 2.4 and I question the need for it. I know that it allows for lazy >> evaluation which speeds things up for larger lists but why was it >> necessary to add it instead of improving list comprehension? >> >> Was there some sort of limitation that prevented list comprehension from >> taking over the functionality that generator expressions provide? > > Sure, and that limitation is: list comprehensions return lists. This > one "limitation" (together with Python's applicative order evaluation, > and you couldn't change THAT without breaking the whole caboodle of > existing programs!) implies everything else. > >> >> I have always liked the fact that Python has limited capabilities for >> having more than one way to do it and it seem to me that generator >> expressions break that philosophy. It is similar to how you have to use >> range or xrange depending on how large the range is. >> >> Can someone please explain the reasoning behind it? > > Generator comprehensions are wonderful and there is no way Python list > comprehensions can provide the same features, since lists need to be > lists. Sure, list(e(x) for x in foo) IS just the same thing as [e(x) > for x in foo]. We'll remove the redundancy in 3.0 -- not earlier > because it will break backwards compatibility. The only sensible way I > can see right now for 3.0 to remove this redundancy is by removing list > comprehensions and leaving only generator comprehensions, btw. The one problem I have with generator comprehensions is that, because list comprhension came first they look like tuple comprehensions. In order to avoid this same kind of confusion with new comers I think it would be best if generator comprehensions are explained first and that list comprehension is just syntax sugar for list(genexp) -- Antoon Pardon From luser at aol.com Tue Aug 17 15:41:11 2004 From: luser at aol.com (duke0uke) Date: Tue, 17 Aug 2004 12:41:11 -0700 Subject: Numarray: Using sum() within functions In-Reply-To: References: <10hsvoka533ci3c@corp.supernews.com> Message-ID: <10i4nqnslvfqi7f@corp.supernews.com> Christopher T King wrote: > On Sat, 14 Aug 2004, Jim Cser wrote: > > >>I have a function to generate a multi-dimensional array, which then >>gets summed over one axis. The problem is that the dimensions >>are large, and I run out of memory when I create the entire array, >>so I'm trying to do the sum *within* the function. >> >>Example-- variables x,y,z,t; dimensions numX, numY, numZ, numT; >>functions f1(x,y,z,t), f2(y,z,t); want to calculate f1*f2 and >>sum over t to get out[x,y,z]. > Cobbling together a number of suggestions, what finally worked was-- def f3(x, y, z, t_range=arange(numT)): tempval = 0.* x for t in t_range: tempval += f1(x,y,z,t) + f2(y,z,t) return tempval out = fromfunction(f3,(numX,numY,numZ,1)) I couldn't quite get sum() to work inside the function, but this is definitely good enough for now. Thanks to all for your help. -Jim Cser From josh at work.com Tue Aug 3 16:32:22 2004 From: josh at work.com (JCM) Date: Tue, 3 Aug 2004 20:32:22 +0000 (UTC) Subject: simple Thread question References: Message-ID: You should override the run method, but call thread.start() to kick the execution off in a separate thread. If you call thread.run(), you're just running your code in the same thread. adeger wrote: > Having trouble with my first forays into threads. Basically, the > threads don't seem to be working in parallel (or you might say are > blocking). I've boiled my problems to the following short code block > and ensuing output. Seems like the output should be all interleaved > and of course it's not. Running Python 2.2 from ActiveState on > Windows XP (also doesn't work on Windows 2000). > Thanks in advance! > adeger > #==================================================== > import threading > class TestThr(threading.Thread): > def __init__(self): > threading.Thread.__init__(self) > def run(self, name): > import time > for i in range(1,11): > print 'thread ', name, ' instance ', str(i) > time.sleep(1) > threads = [] > for inst in ('a', 'b', 'c'): > thread = TestThr() > thread.run(inst) > threads.append(thread) > # output below > thread a instance 1 > thread a instance 2 > thread a instance 3 > thread a instance 4 > thread a instance 5 > thread a instance 6 > thread a instance 7 > thread a instance 8 > thread a instance 9 > thread a instance 10 > thread b instance 1 > thread b instance 2 > thread b instance 3 > thread b instance 4 > thread b instance 5 > thread b instance 6 > thread b instance 7 > thread b instance 8 > thread b instance 9 > thread b instance 10 > thread c instance 1 > thread c instance 2 > thread c instance 3 > thread c instance 4 > thread c instance 5 > thread c instance 6 > thread c instance 7 > thread c instance 8 > thread c instance 9 > thread c instance 10 From cjankowski at hbr-inc.com Wed Aug 11 19:18:51 2004 From: cjankowski at hbr-inc.com (Chris Jankowski) Date: 11 Aug 2004 16:18:51 -0700 Subject: Pilprint References: Message-ID: "Fredrik Lundh" wrote in message news:... > Chris Jankowski wrote: > > >I am a newbie to the world of Python and trying to print some > > images(.tif). I have installed the PIL Library and can use the some > > of the fuctions like: m.format, im.size, im.mode without any problem. > > When I try to use the Tools like pilprint and pilfile, I can't seem to > > get them to work. Any help would be greatly appreciated. > > > > Examples: > >>>> pilfile *.tif > > Traceback ( File "", line 1 > > pilfile *.tif > > > >>>> pilprint 'c:/chris.TIF' > > Traceback ( File "", line 1 > > pilprint 'c:/chris.TIF' > > ^ > > SyntaxError: invalid syntax > > pilprint (etc) are programs, not Python statements. you're supposed > to run them from the standard command line, not Python's interactive > prompt. > > depending on your operating system, and how things are set up, some > of these should work: > > pilprint.py c:/chris.tif > python pilprint.py c:/chris.tif > pilprint c:/chris.tif > > Thanks, I got it to run, but now I have a Broken Pipe Error. Any ideas? We are using a network printer. Would that have anything to do with it? Also, I got an error message about not supporting group 4, when I tried it with a .tif image, are they supported? From Scott.Daniels at Acm.Org Sun Aug 22 20:29:21 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 22 Aug 2004 17:29:21 -0700 Subject: problem using C-bindings In-Reply-To: References: Message-ID: <41293c23$1@nntp0.pdx.net> eq wrote: > Am Thu, 19 Aug 2004 17:45:45 -0400 schrieb Jack Diederich: > > >>On Thu, Aug 19, 2004 at 10:32:15PM +0200, eq wrote: >> >>>Hi, >>> >>>I'm trying to create a program(written in C) that does the following >>>things using embedded Python: >>>1. Create a module(say, "MyModule") >>>2. Create a class in that module(say, "MyClass") >>>3. Create a function in that module(say, "MyFunction") >> >>[snip] >> >>> class_dict=PyDict_New(); >>> class_name=PyString_FromString("MyClass"); >>> class=PyClass_New(NULL,class_dict,class_name); >>> PyDict_SetItemString(module_dict,"MyClass",class); >> >>[snip] >> >>Take a look at Modules/xxsubtype.c in the source distribution. >>It is an example of how to subtype a builtin. xxmodule.c shows >>how to make a class from scratch. Both are out of date but a good >>sarting spot. >> > > Hm, perhaps I over-complicated my problem: > I don't need a full python-class in pure C. I just need to create a > (python!) function(a dynamic one, not a static C function) and attach it > to an already existing python-class just by using C-calls. You've already managed this. The error message is telling you it has no place to put "self". > I try to do this by compiling the function's code with: > > pyfunc_code=Py_CompileString(func_code,"",Py_file_input); > > where func_code could be something like "print 'hello'" and then I try to > make a function out of this by calling: > > pyfunc=PyFunction_New(pyfunc_code,dict); > > where dict is the global namespace for the function. > What I now want is to attach this function to the already created class > "MyClass". You should call "staticmethod" on your pyfunc before putting it into the class. The error message you got before: TypeError: ?() takes no arguments (1 given) indicates that you had defined a 0-arg function and were calling it with one arg. That arg was the "self" arg. You could do the moral equivalent of: MyClass.MyFunction = staticmethod(MyClass.MyFunction) after the code you have now. Alternatively you could pull staticmethod from __builtins__ and "apply" it yourself before storing in attachFunc. Just guessing from "funcobject.h", but I'll bet you could also change attachFunc as follows void attachFunc(PyObject* class, PyObject* dict, char* func_code, char* name) { PyObject* pyfunc_code; PyObject* pyfunc; pyfunc_code=Py_CompileString(func_code,"",Py_file_input); pyfunc=PyFunction_New(pyfunc_code,dict); pyfunc=PyStaticMethod_New(pyfunc); PyObject_SetAttrString(class,name,pyfunc); } You do know you need to do much more error checkig here, don't you? Untested (my mail machine and my C machine are different). int attachFunc(PyObject* class, PyObject* dict, char* func_code, char* name) { PyObject* pyfunc_code = NULL; PyObject* pyfunc = NULL; PyObject* pyfunc_static = NULL; int result = -1; /* 0 for success */ pyfunc_code = Py_CompileString(func_code, "", Py_file_input); if (pyfunc_code) { pyfunc = PyFunction_New(pyfunc_code, dict); if (pyfunc) { pyfunc_static = PyStaticMethod_New(pyfunc); result = PyObject_SetAttrString(class, name, pyfunc); } Py_XDECREF(pyfunc_static); Py_XDECREF(pyfunc); Py_XDECREF(pyfunc_code); return result; } -Scott David Daniels Scott.Daniels at Acm.Org From steven.bethard at gmail.com Fri Aug 20 13:26:09 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Fri, 20 Aug 2004 17:26:09 +0000 (UTC) Subject: Alternative decorator syntax decision References: <3A81C87DC164034AA4E2DDFE11D258E3022E14@exchange.hqamor.amorhq.net> Message-ID: Bernhard Herzog intevation.de> writes: > > It does look > > like J2 is generally the preferred syntax so far > > At least of those who don't like the pie syntax at all. Yes, this is what I intended. Sorry if it wasn't clear. > I don't know. If J2 gets the majority of the votes for an alternative, > it might be a good idea to have a second vote just between the pie > syntax and J2. I'd vote for pies. I would advise against this. GvR has said from the beginning that he doesn't want to see a vote -- he wants to see convincing proposals and a more or less unified community support. He's also said that he'd be willing to consider adding two syntaxes for a while if we could really agree on a single alternative syntax. So while the vote for non- at pie syntaxes seems to have been useful for focusing our discussions for an alternative proposal, I can't see what use a vote between J2 and @pie would do. Perhaps I've missed something here though, so I'm open to an explanation... Steve From grante at visi.com Thu Aug 26 11:00:39 2004 From: grante at visi.com (Grant Edwards) Date: 26 Aug 2004 15:00:39 GMT Subject: Best processor (i386) for Python performance? References: Message-ID: <412dfb17$0$65599$a1866201@newsreader.visi.com> On 2004-08-26, Brett C. wrote: > In terms of multithreading, an I/O intensive app that is > threaded can make use of dual procs. Otherwise threaded apps > can't for technical reasons (GIL and such but don't need to > get into those details). That's rather dissappointing. If I write a multi-threaded app in C it can utilize multiple processors, but the same app in Python can't? Not that I _have_ any SMP machines... -- Grant Edwards grante Yow! I Know A Joke!! at visi.com From http Mon Aug 30 04:23:16 2004 From: http (Paul Rubin) Date: 30 Aug 2004 01:23:16 -0700 Subject: Generator expressions v/s list comprehensions References: <1gj8y77.6qshr41q531veN%aleaxit@yahoo.com> <87llfywooz.fsf@sinken.local.csis.hku.hk> <1gjbs1e.assxlxlud1m0N%aleaxit@yahoo.com> Message-ID: <7xbrgtrq4r.fsf@ruckus.brouhaha.com> aleaxit at yahoo.com (Alex Martelli) writes: > It would sure be nice if Python had been born back from day one with all > the neat features it has taken years to develop -- that way we wouldn't > have any issues that are there just because of backwards compatibility. > > Unfortunately, this wish is totally unrealistic -- obviously people do > come up with cool ideas such as the iterator protocol, and generators, > after the language has been around for a while. And yet a lot of the unrealisticness comes directly from the Python culture. Maybe it took a while to think up the iterator protocol, but what about nested scopes? What about the += operator? How about the sorted() method on lists? One could go on and on with more examples like that. These things exist in other languages and had been requested in Python for years before they got accepted. And every time some little thing gets added changing the language, that creates a new mini-dialect that users have to remember for a while and then forget. The result is "version fatigue"; one gets bleary trying to remember what's in the language this week. Those features are in other languages for a reason, and there's been enough experience using them (in those languages) that their desirability for Python should never have seriously been in question. So it would have been better to include them from the beginning, instead of through separate episodes of prolonged agony for each one. From grante at visi.com Sun Aug 22 13:28:41 2004 From: grante at visi.com (Grant Edwards) Date: 22 Aug 2004 17:28:41 GMT Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> <7x4qmv6cwo.fsf@ruckus.brouhaha.com> Message-ID: On 2004-08-22, Paul Rubin <> wrote: > aahz at pythoncraft.com (Aahz) writes: >> >It seems there are quite a few projects aimed to improve Python's >> >speed and, therefore, eliminate its main limitation for mainstream >> >acceptance. >> >> What makes you think speed is Python's primary limitation for mainstream >> acceptance? > > Well, whenever I want to write a mainstream application and think of > using Python, my first reaction is that Python is too slow... And I presume you're pleasantly surprised when you run your program and find out it's not too slow? -- Grant Edwards grante Yow! Did you move a lot at of KOREAN STEAK KNIVES this visi.com trip, Dingy? From anthonybaxter at gmail.com Thu Aug 5 12:04:34 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 02:04:34 +1000 Subject: RELEASED Python 2.4, alpha 2 In-Reply-To: References: <411231C8.3020308@interlink.com.au> Message-ID: > This is a bad joke after all the strong perplexities showed about its > decorators solution. > I vote against the "@decorator before function" solution. Please feel free to actually provide reasons for not liking @decorators. Also - if you think you don't like it - please _try_ _it_ _out_ first. Anthony From Domoran at yahoo.de Mon Aug 16 13:00:08 2004 From: Domoran at yahoo.de (Mathias Mamsch) Date: Mon, 16 Aug 2004 19:00:08 +0200 Subject: Problems with PyGILState_Ensure () and PyGILState_Release () References: <5upuh0hivs0mfg2bu6ceu73o9jsivuql2i@4ax.com> Message-ID: Hi Greg, thanks for your answer ... I really need help with this, because till now I found no solution to my problem ... I always get FatalErrors, Deadslocks, or protection faults ... I created some example code for what I want to accomplish. I have a single thread which calls some C-Function which should call back into python. To your questions: no nowhere in *my* code ReleaseThread is called and I dont write to gstate either ... I dont understand the thread handling of python completely... Any ideas where - besides the Python docs - I can find some information about that ? Thanks Mathias Mamsch here is some example code which produces my problem. hope it helps to understand it ... ----------- #include "python.h" #include #include using namespace std; #define GETLOCK PyGILState_STATE gstate; \ gstate = PyGILState_Ensure (); #define RELEASELOCK PyGILState_Release (gstate); static DWORD Tid; static int CHandleFunction () { GETLOCK // here will I callback to python ... cout << "Hello" << endl; RELEASELOCK return 0; } static PyMethodDef SpamMethods[] = { {NULL, NULL, 0, NULL} /* Sentinel */ }; // some C Thread which calls the Handler ... DWORD __stdcall WCThread (LPVOID lpThreadParameter) { while (1) { CHandleFunction(); Sleep(500); } } PyMODINIT_FUNC initkdll(void) { Py_InitModule("kdll", SpamMethods); // Create some C++ Thread for testing purposes CreateThread(NULL,0,WCThread,NULL,0,&Tid); } From osuchw at ecn.ab.ca Wed Aug 4 14:02:43 2004 From: osuchw at ecn.ab.ca (Waldemar Osuch) Date: Wed, 04 Aug 2004 18:02:43 GMT Subject: Finding all time periods for a given interval within a date range In-Reply-To: References: Message-ID: <7x9Qc.11245$M95.6881@pd7tw1no> Graeme Longman wrote: > Hi everyone, > > I was wondering if anyone has written some Python code which uses a start > date and end date and a given interval (day, month or year) and outputs all > the time periods for that range and interval. > > For example you may wish to find all the months between the dates > '2004-02-14' and '2004-08-04'. You would maybe use a function where you pass > in those starting and ending dates and the interval 'month' and you'd get > back a list of those months. I guess you would need to year part of the date > too, so ['2004-02', '2004-03', '2004-04', '2004-05', '2004-06', '2004-07', > '2004-08']. If you had passed in 'day' as the interval then you would be > given back a list of all the days in those months. Try using dateutil module by Gustavo Niemeyer found at: https://moin.conectiva.com.br/DateUtil from datetime import date from dateutil.rrule import * d1 = date(2004,2,14) d2 = date(2004,8,4) for d in rrule(MONTHLY, d1, until=d2): print d.year, d.month 2004 2 2004 3 2004 4 2004 5 2004 6 2004 7 Substitute MONTHLY with DAILY in the rrule and you will get list of days Waldek From cole at tuininga.org Tue Aug 24 10:19:22 2004 From: cole at tuininga.org (Cole Tuininga) Date: Tue, 24 Aug 2004 10:19:22 -0400 Subject: setdefault threadsafe? Message-ID: Quick question for y'all - is a dict's setdefault call threadsafe? In other words, if I have code like the following: tmp = someObj() result = dictname.setdefault( key, tmp ) is it going to behave "correctly" in a threaded environment? Thanks in advance. -Cole Tuininga From mark_bottjer at hotmail.com Thu Aug 12 12:59:07 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Thu, 12 Aug 2004 12:59:07 -0400 Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: References: <60dfb6f6.0408111846.615ee9eb@posting.google.com> <3YWdnYxLf--ObofcRVn-pw@powergate.ca> Message-ID: <411ba1db$1@nntp.zianet.com> Michael Sparks wrote: > Looking at the wiki it states (as negative points): > 1 New keyword > 2 Overkill for the simple case like classmethod > 3 Many people felt it was wrong use of an identation suite. > 4 Has the same problem as 5.A, in that the decorate block implicitly > affects the following def. This does not occur elsewhere in Python. > 5 Technical problems with the current grammar parser if a suite > *starts* with an optional part. (Ending with an optional part, such > as "else:" is OK, but starting with one is not.) > 6 No implementation currently exists. [snip] > Item 3 is opinion, but I don't know where the arguments are leading to > that point, so I'll just take that at face value. The contention was that indentation is used to indicate the effective scope in other contexts: e.g., def changes how the statements *indented under it* are handled (they are packed into a code object instead of executed immediately), but doesn't change how the next statement at the same indentation level is handled (the statement result may change, due to coupling via common data, but the statement itself is handled exactly as it would be were the previous statement not present). With this syntax, though, the decorate block changes how the def statement is handled, even though they are at the same indentation level. Put another way: applying what I know about how indentation is used elsewhere in Python to this syntax, I would expect the effect of the decorate statement to be limited to the statements indented under it. I would not expect it to affect the next statement at the same level except by the normal coupling of namespace (program state). Of course, this argument also applies to the prefix @ syntax, but at least with that we have a funny character cluing us in to the special behavior. > Regarding 4, it strikes me that this isn't the case (unless it strictly > means "block"!). It meant strictly "block". :) > An import at the beginning of a block changes the > meaning of [the rest of] a block. Yes, by means of changing the program state--specifically, the namespace used to resolve identifiers. The decorate block changes the meaning of only the *next* statement by means of changing the parser (not program) state. I see them as quite different. YMMV. > Similarly a class statement changes the meaning of > the defs immediately following it. It affects the meaning of the defs indented under it. The only way it affects anything after it is by the modifications it makes to the namespace. Again, the statements at the same indentation level are coupled only via namespace, not parser state. The statements in indented suites are coupled via parser state, but that coupling is made obvious via the indentation. > I'd agree that it's not ideal, but > the argument that code preceding the def isn't allowed because it > changes the meaning of the def doesn't make sense to me - that's what > the @ syntax does. Indeed, and that partially why I like the '@' symbol (or possibly a meta keyword). If we're going to add something which completely disregards the existing indentation/coupling idioms, then it should have an obvious visual trigger. -- Mark From fumanchu at amor.org Tue Aug 24 17:46:48 2004 From: fumanchu at amor.org (Robert Brewer) Date: Tue, 24 Aug 2004 14:46:48 -0700 Subject: J2 paper 0.2.1 Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E59@exchange.hqamor.amorhq.net> Tim Hochberg wrote: > I agree with Paul that the choice of keyword *is* important. A > misleading keyword is worse than cryptic punctuation. The keyword is > lying, while the punctuation is merely silent. That helps clarify nicely. > I also agree that predef reads poorly. I presume it's meant to imply > something like preample or header, but I read it as predefine, which > makes me think of some sort of evil forward declaration, not a > decorator. It also just feels wrong to me, not that that carries much > weight. You mean decorators *aren't* evil forward declarations? >;) > Sadly I don't have any better ideas for a keyword. While I'm on the > topic, let me point out some of the other keywords mentioned in the > proposal that read poorly. "amend", "extend" and "qualify" > all share a > common flaw that in normal usage the thing being amended/extended/etc > should follow the word. Thus the natural reading of: > > amend: > foo > def bar(): > ... > > is somewhere between "huh?" and "clearly bar is used to amend foo." Any proposal to winnow down the list is eagerly accepted. :) I admit I hadn't studied some of those in detail. If there are no disagreements, I'll remove amend and extend. In addition, I'd like to remove confer, preamble, preface, and prologue, since nobody has supported them other than the OP. This would leave: by, having, helper, meta, per, predef, qualify, through, using, via The important thing to note is that these are examples of a principle, not recommendations. I'll be more explicit about that in the doc. Thanks for your comments! Robert Brewer MIS Amor Ministries fumanchu at amor.org From matt.price at utoronto.ca Tue Aug 10 11:44:57 2004 From: matt.price at utoronto.ca (Matt Price) Date: Tue, 10 Aug 2004 11:44:57 -0400 Subject: cgi script: get the url of this page In-Reply-To: References: Message-ID: <20040810154457.GA28075@utoronto.ca> On Tue, Aug 10, 2004 at 12:43:03AM +0200, Peter van Kampen wrote: > > is there a standard trick to get the url of the current page in a cgi > > import os > > script = os.environ["SCRIPT_FILENAME"] great, thanks for the hint. tho I think "script_filename" gives the file name, not the internet url -- for that REQUEST_URI seems to be better. This is great, thanks! > > script, or the url from which form data has been passed?? I want to > > Hmm. You can try HTTP_REFERER but it depends on several things (browser, > server, cgi-implementation etc.) wether this reports something useful or > not. It is probably more reliably to check REMOTE_ADDR if that would provide > enough information. hmm, REMOTE_ADDR doesn't seem to show up mosto f the time; HTTP_REFERRER works great, though, long as the fom isn't sent to the page it came from... thanks much! matt > > Hth, > > PterK > ------------------------------------------- Matt Price matt.price at utoronto.ca History Department, University of Toronto (416) 978-2094 -------------------------------------------- From bingham at cenix-bioscience.com Fri Aug 27 02:58:03 2004 From: bingham at cenix-bioscience.com (Aaron Bingham) Date: Fri, 27 Aug 2004 08:58:03 +0200 Subject: Python MySQL API and date data type In-Reply-To: <20040826203840.411F81589B@net.tamu.edu> References: <20040826203840.411F81589B@net.tamu.edu> Message-ID: <412EDB7B.3010506@cenix-bioscience.com> Yong Wang wrote: >>Hi: >> We have a database system. In the database, we have an >>attribute called date0, which contains date data (format: >>i. e. 2004-08-12). I wrote a script to fetch the data >>in a specified time period: >>for exaplme: >>date1 = raw_input('start date ') >>date2 = raw_input('end date ') >> >>ie. date1 = '2004-08-12' >> date2 = '2004-08-20' >>run = ('SELECT * FROM account WHERE (date0 >= date1) and (date0 <= date2)') >>data = dbh[runn] >>..... >> >> You are getting database columns and Python variables confused. I am not familiar with MySQLdb in particular, so I may have a couple details wrong, but you probably meant something like this: data = db.query('SELECT * FROM account WHERE (date0 >= %s) and (date0 <= %s)', (date1, date2)) This will substitute the *values* of the Python variables date1 and date2 into the query for you. Regards, -- -------------------------------------------------------------------- Aaron Bingham Application Developer Cenix BioScience GmbH -------------------------------------------------------------------- From eurleif at ecritters.biz Sat Aug 21 19:55:29 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sat, 21 Aug 2004 19:55:29 -0400 Subject: Validating SGML parser? In-Reply-To: References: Message-ID: <2oq5h5Fd6190U1@uni-berlin.de> Benjamin Niemann wrote: > does anyone know of a validating SGML parser in python (like > xmlproc.xmlval does for XML)? Goal is to validation HTML against the > DTD, similar to validator.w3.org, not all SGML obscurities are required. There are plenty of command-line tools for that. Why not use one of them through Python? From pm_mon at yahoo.com Fri Aug 20 19:44:50 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Fri, 20 Aug 2004 19:44:50 -0400 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: Note: This is *not* about implicit method typing... :-) Although I haven't seen it discussed anywhere, we already have a decorator syntax (of sorts) that we use to annotate functions and classes. The " __var__ = " business. Have we decided that it is woefully insufficient? I know that there is a preference for the decorators to appear outside of the function def, but putting that aside, this 'style' of decorating already has a precendent in python, so it is probably as pythonic as you can get... class Foo: __metaclass__ = M __automethods__ = True __author__ = 'Paul Morrow' __version__ = '0.1' def baz(a,b,c): __synchronized__ = True __accepts__ = (int,int,int) __returns__ = int __author__ = 'Fred Flintstone' return a + b + c What is the burning desire to abandon this style? Paul From gneuner2/ at comcast.net Fri Aug 27 01:00:33 2004 From: gneuner2/ at comcast.net (George Neuner) Date: Fri, 27 Aug 2004 01:00:33 -0400 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: On 25 Aug 2004 14:56:06 -0700, xah at xahlee.org (Xah Lee) wrote: > > Unixism > "Isms", in my opinion, are not good. A person should not believe in an "ism". He should believe in himself. Ferris Bueller -- for email reply remove "/" from address From aleaxit at yahoo.com Sat Aug 28 04:45:25 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 28 Aug 2004 10:45:25 +0200 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <7xzn4gwgea.fsf@ruckus.brouhaha.com> <1gj7a1o.1a5d2q410jsn2kN%aleaxit@yahoo.com> <7xisb4xnh5.fsf@ruckus.brouhaha.com> <1gj7c1a.tfdm14p3hclcN%aleaxit@yahoo.com> <7xd61benm9.fsf@ruckus.brouhaha.com> <1gj82n3.1ylkr3nierngmN%aleaxit@yahoo.com> <7x4qmnvgcu.fsf@ruckus.brouhaha.com> <7xvff3u0za.fsf@ruckus.brouhaha.com> Message-ID: <1gj85gi.ghiv3b1f8fhv7N%aleaxit@yahoo.com> Paul Rubin wrote: > Paul Rubin writes: > > > Side question, does module zipfile already have the code to allow > > > reading such signed files? > > > > I think jar files are just zip files containing an extra file (called > > "manifest") that has signatures in it. So you can import from a jar > > as if it were a zip. > > But to add to that, if module zipfile is going to eventually expect > jar files to be signed, the first patch needed is that if it doesn't > have code to actually check the signatures, it should refuse to load > jar files. Presumably that would be an optional argument on the ZipFile constructor specifying what to do about signatures -- defaulting to 'ignore' for backwards compatibility, I guess, but possibly 'strict' or 'optional' or something. > > I guess I better check into what Java does about this. It's been a > while since I've used Java, but I seem to remember that signing is not > mandatory. OK, but it might make for a nice optional feature anyway. Alex From pm_mon at yahoo.com Thu Aug 19 07:52:38 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Thu, 19 Aug 2004 07:52:38 -0400 Subject: PEP 318: Can't we all just get along? In-Reply-To: References: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: Anthony Baxter wrote: > On Thu, 19 Aug 2004 06:35:18 -0400, Paul Morrow wrote: > >>Unless of course you want a method to be private/semi-private. How do >>you feel about the way we can create/manipulate lists and dictionaries >>using special (magical) syntax? Why is that different (acceptable)? > > > Look, name-mangling is horrid, and I don't think anyone's defending it. But > at the same time, "name mangling is there" is not an argument for extending > the horror to a whole new level. > > Name mangling only occurs when you create a method with two leading > underscores, and no trailing ones. Your proposal would hit _every_ _single_ > 'def'. It's nasty, it's unpythonic, and there's approximately _zero_ chance of > it ever going into the language. Having said that, it's perfectly feasible to do > it with a metaclass, and if you want to use it in your code, please, feel free. > > Anthony You didn't follow that one with a smiley either... :-) From sholden at holdenweb.com Mon Aug 30 20:12:37 2004 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 30 Aug 2004 20:12:37 -0400 Subject: Dynamic languages In-Reply-To: <278de0e.0408271349.26762174@posting.google.com> References: <278de0e.0408271349.26762174@posting.google.com> Message-ID: <4133C275.5010200@holdenweb.com> Neuruss wrote: > I've been reading an article published in E-Week entitled "Microsoft > Lures Open-Source Programmer", which contains a definition for dynamic > languages as follows: > > "Dynamic programming languages enable programs to change their > structure as they run." > > I wonder if this definition is correct. > Can we define dynamic languages this way? > > http://www.eweek.com/article2/0,1759,1636906,00.asp Well, look at the source - it's journalism, and it's not meant to be strictly accurate, merely sufficiently informative for the mostly-uninformed. I don't imagine e-Week would be interested in printing a retraction should you find agreement on a definition in this group (which I suspect is rather unlikely). regards Steve From steve551979 at hotmail.com Sat Aug 14 00:29:55 2004 From: steve551979 at hotmail.com (Steve) Date: 13 Aug 2004 21:29:55 -0700 Subject: reading shell output in parallel Message-ID: Hi, I'm pretty new to python. I am trying to write a simple application that can read the stdout output from a command in linux. I've tried using x = commands.getstatusoutput() but this only gives back the output in x after finished executing. I would like to read the contents as it is being shown on the screen and then send parts of this info over a simple client/server setup. I have the client/server part set up already. Can anyone suggest a simple way to do this? Thanks for your help, I appreciate it. Steve From moma at example.net Sat Aug 14 15:29:22 2004 From: moma at example.net (moma) Date: Sat, 14 Aug 2004 21:29:22 +0200 Subject: Practical examples In-Reply-To: References: Message-ID: Bigbowser wrote: > hi all, > > I'm new to python, and have read through > http://www.ibiblio.org/obp/thinkCSpy/ , and now I'm > looking for some simple programs to have a read > through and other more in-depth tutorials to have a > look at. > > Regards, > Bigbowser > http://www.python.org/doc/current/tut/tut.html -> http://www.python-eggs.org/links.html http://wxpython.org (GUI programs) Google for "python and (examples or samples)" // moma http://www.futuredesktop.org/how2burn.html#mirrors From dontreply at caramail.com Wed Aug 25 14:58:55 2004 From: dontreply at caramail.com (Cyrille Lavigne) Date: 25 Aug 2004 11:58:55 -0700 Subject: Am I on the right path In-Reply-To: <10ipj908b7p2099@corp.supernews.com> Message-ID: Are you trying to make a virus, worm or other spambot? ___ Cyrille Lavigne From alikakakhel3 at hotmail.com Sun Aug 29 19:52:29 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 29 Aug 2004 16:52:29 -0700 Subject: about presicion References: <20040829041630.28913.00001771@mb-m26.aol.com> Message-ID: <8f17f4bc.0408291552.67e3553e@posting.google.com> So the decimal module is in 2.4 but not 2.3? Also I am not geting the 2.4 version because it seems that it is still in alpha. From mark.hellewell at gmail.com Wed Aug 25 08:17:53 2004 From: mark.hellewell at gmail.com (mark hellewell) Date: Wed, 25 Aug 2004 13:17:53 +0100 Subject: module functions list In-Reply-To: References: Message-ID: Hi, You could use a list comprehension coupled with a filter: functionList = [function for function in dir(objectName) \ if callable(getattr(objectName,function))] mark On Wed, 25 Aug 2004 13:45:11 +0200, Diez B. Roggisch wrote: > Hi, > > this strikes me as a pretty basic question, but google didn't help, so I'm > asking it here: > > How do I get a list of functions defined in a module in the module itself? > Like this: > > --- module functions.py > def foo(): > return 1 > > def bar(): > return 1 > > def all_functions(): > return > > --- > > The application for this is that I want a bunch of predefined functions for > a small expression interpreter of mine to be collected in one module and > get them all without an explicit "registration" process. > > Any ideas? > > -- > Regards, > > Diez B. Roggisch > -- > http://mail.python.org/mailman/listinfo/python-list From bokr at oz.net Tue Aug 31 17:36:09 2004 From: bokr at oz.net (Bengt Richter) Date: 31 Aug 2004 21:36:09 GMT Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: On Tue, 31 Aug 2004 09:25:43 -0400, Paul Morrow wrote: >Paul Morrow wrote: >> >> But why speculate. Let's see if this is really going to be unclear in >> practice. Ask someone who has never seen Python before which are the >> local variables in the following def. >> >> def circumference(diameter): >> """Calculate the diameter of a circle.""" >> __author__ = 'Paul Morrow' >> __version__ = '0.1' >> pi = 3.14 >> return pi * diameter >> >> > >And while you're at it, ask them which lines get executed at function >definition time, and which get executed when the function is called. > IMO you will have better luck promoting your functionality if you make your proposed magic syntactically distinct using something other than underscores, which are just name characters in any legal name that matches [a-zA-Z_][a-zA-Z0-9_]* I think your magic becomes more interesting if we separate the two issues of referring to attributes of the current object and doing it at def-time as opposed to normal execution time (i.e., call-time for function body code), and get some orthogonal general primitives going ;-) To make things simple, let's say '$' means the current object, and let's say that we use '..' in various ways to indicate execution or evaluation at def-time. E.g., prefixed to an assignment '=' it would mean do the binding (and evaluation of the whole right hand side) at def-time. Thus your example becomes def circumference(diameter): """Calculate the diameter of a circle.""" $.author ..= 'Paul Morrow' $.version ..= '0.1' pi = 3.14 return pi * diameter But notice that the assignment of pi is a wasteful repeated action for every call. If instead if we wrote (additionally illustrating constant folding effect): pi ..= 3.14 # or __import__('math').pi for better accuracy ;-) mask7 ..= 2**7-1 # net binding as if mask7=127 the effect would be a def-time pre-binding of pi and mask7, visible locally as if def circumference(diameter, pi=3.14, mask7=2**7-1): # etc but without using the default arg hack. Of course, a default local arg name binding is refreshed to the original rhs at every call, so even if you set pi=0.0 it will appear as 3.14 next time. Unlike if you used $.pi ..= 3.14 and then set $.pi=0.0 -- that would be preset once and rebindings would persist. $.xxx would also provide good opportunity for optimizing access, and the $ attribute name space would be a handy substitute for a mutable closure object named something other than '$'. BTW, another interesting thing would be if the function class were modified so that it would recognize descriptors when attributes of its instances. This would make assignments of properties sticky unless they had a self-deleting method. E.g., def foo(): $.prop ..= property(lambda self: 'hi from %s.prop'%self.__name__) would mean foo.prop would return 'hi from foo.prop' and foo.prop = 123 would raise an exception. Or the function class could be made subclassable. BTW, an expression should also be able to have a def-time-evaluated term, without the rest being def-time, e.g., def area(r): return ..(__import__('math').pi)*r*r Note also what you could do with a mutable when you don't need the default arg hack: def pow10(x): cache ..={} try: return cache[x] except KeyError: return cache.setdefault(x, 10**x) In classes, if there is a classvar ..= something, the resulting code for the class definition should theoretically not have the assignment as byte codes when the class body executes, but the binding should be visible as-if. I don't know if there's an efficient way to do that. Seems like it would have to be pre-bound in the class dict (that gets passed to a metaclass if there is one), but I guess a fresh copy would be needed. So that would wind up way more expensive than just a plain class-def-time assignment. Hm, probably easiest just not to allow it. Inside methods, of course, ..= would be fine. Method def-times are when the class body executes (unless they are later added, in which case the ..= applies wherever the function/method was defined and its def executed. Too many ideas in one post? Ok, enough lunch fun. Regards, Bengt Richter From ville at spammers.com Sun Aug 22 12:27:59 2004 From: ville at spammers.com (Ville Vainio) Date: 22 Aug 2004 19:27:59 +0300 Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? References: Message-ID: >>>>> "Arthur" == Arthur writes: Arthur> It seems ironic to me that in a group devoted to an Arthur> appreciation of Python, and its advocacy - it is often Arthur> those who reject the notion that the language has the Arthur> kinds of glaring weaknesses that require some fundamental Arthur> change ot it, that form the opposition to an Arthur> "establishment" that has become convinced quite otherwise. If you don't want improvements to the language, don't download the new version. Keep on writing the code in the old style, and run foreign code through a preprocessor that e.g. converts decorators to the old non-syntax style. If you really want a stagnant, non-evolving language, there are many to choose from. I guess Python could also be forked to a special ZombiePython edition, where heresy like a+=4 and list comprehensions are unheard of. Arthur> I sometimes wish those folks were more candid about its Arthur> deficiencies before I started my study of it back in 1.5.2 Arthur> days. If Python was still like 1.5.2, 90% of the current community would be running Ruby (assuming it would have evolved while Python had stagnated). -- Ville Vainio http://tinyurl.com/2prnb From jepler at unpythonic.net Wed Aug 4 21:19:59 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 4 Aug 2004 20:19:59 -0500 Subject: bsddb In-Reply-To: <1091668087.41118877a493a@www-mail.usyd.edu.au> References: <41110FDB.9080307@mail.usyd.edu.au> <411185C7.2020705@bitglue.com> <1091668087.41118877a493a@www-mail.usyd.edu.au> Message-ID: <20040805011959.GA31600@unpythonic.net> The bsddb module is in the Python source tree. It's called Modules/bsddbmodule.c. Copying a .lib or .dll file from a Windows machine doesn't have a chance of working (for reasons I'm sure you understand). If it wasn't built by whoever packaged this distribution for CE, you'll need a CE development environment, the bsddb library, and the the Python source tree. Probably very few people would be able to advise you in how to set it up. So, best of luck. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From anthonybaxter at gmail.com Tue Aug 24 22:26:37 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Wed, 25 Aug 2004 12:26:37 +1000 Subject: J2 0-2-6 is available In-Reply-To: References: <3A81C87DC164034AA4E2DDFE11D258E3022E52@exchange.hqamor.amorhq.net> Message-ID: On Wed, 25 Aug 2004 01:59:02 +0000 (UTC), Steven Bethard wrote: > Actually, there's an interesting argument that the "with" for decorators and > the "with" above can be thought of in similar terms: Not similar enough to justify re-using the keyword, in my opinion. Python's done really well in not using the same keyword to mean different things in different contexts. From __peter__ at web.de Thu Aug 12 05:17:15 2004 From: __peter__ at web.de (Peter Otten) Date: Thu, 12 Aug 2004 11:17:15 +0200 Subject: decorator with keyword Message-ID: I'm sure they have been mentioned somewhere but here are some more advantages of a decorator keyword (I use "transform"): - The docstring can be moved to the top of the decorator suite. - Simple attributes that don't affect the function's operation directly can be written in the "natural" name = value form. - Though I expect them to be rare like they are in classes today, statements like if __debug__: decorateForDebugging would be possible. A docstring and a single decorator - the common case: transform: """ Factory for new decorator syntaxes. Keeps all proposals in a list and will recombine them at random if called without a spec. """ staticmethod def makeDecoratorSyntax(spec=None): raise NotImplementedException() The same with a pie: @staticmethod def makeDecoratorSyntax(spec=None): """ Factory for new decorator syntaxes. Keeps all proposals in a list and will recombine them at random if called without a spec. """ raise NotImplementedException() I'd say no clear winner here. Now a heavily decorated function: transform: """This method blah, blah. It supports the following arguments: - longArgumentOne -- a string giving ... - longArgumentTwo -- a number giving ... blah, blah. """ author = "BDFL" status = "experimental" grammar = "'@' dotted_name [ '(' [arglist] ')' ]" staticmethod def longMethodNameForEffect(longArgumentOne=None, longArgumentTwo=42): if longArgumentOne is None: longArgumentOne = setDefault(longArgumentTwo) for line in longArgumentOne: if not isBogus(line): print line The same with pies: @funcattrs(author="BDFL", status="experimental", grammar="'@' dotted_name [ '(' [arglist] ')' ]") @staticmethod def longMethodNameForEffect(longArgumentOne=None, longArgumentTwo=42): """This method blah, blah. It supports the following arguments: - longArgumentOne -- a string giving ... - longArgumentTwo -- a number giving ... blah, blah. """ if longArgumentOne is None: longArgumentOne = setDefault(longArgumentTwo) for line in longArgumentOne: if not isBogus(line): print line A long docstring can indeed tear apart signature and implementation. For the sake of completeness, a plain old function: def filter(cond, seq): """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.""" if cond is None: cond = bool return [item for item in seq if cond(item)] transform: """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.""" def filter(cond, seq): if cond is None: cond = bool return [item for item in seq if cond(item)] "transform" looks a bit pathetic for a docstring, but otherwise I'd say the grouping might even be slighly clearer. Note how the function signature is duplicated in the docstring taken from 2.3's filter() - that helps a lot for long decoration suites. The decoration suite would generate a list of (name, value) tuples which are applied to the function like so trafos = [("__doc__", "This method..."), ("author", "BDFL"), ..., (None, staticmethod)] trafos.reverse() for name, value in trafos: if name: setattr(func, name, value) else: func = value(func) I think I would even prefer something like the above over the current classdict passed to metaclasses, i. e. ordering information and "unnamed attributes" could be useful in classes, too. Peter From psXdaXsilva at esotericaX.ptX Fri Aug 20 21:03:15 2004 From: psXdaXsilva at esotericaX.ptX (Paulo da Silva) Date: Sat, 21 Aug 2004 02:03:15 +0100 Subject: "Socket" files? In-Reply-To: <4126824a$0$566$e4fe514c@news.xs4all.nl> References: <1093035812.83612@jubilee.esoterica.pt> <4126824a$0$566$e4fe514c@news.xs4all.nl> Message-ID: <1093050493.502706@jubilee.esoterica.pt> Irmen de Jong wrote: > Marcos Dione wrote: > ... > > mkfifo creates fifo nodes, not "socket"-type files. > I think Unix domain sockets are what the OP means... > Which are created by using the AF_UNIX socket type: > > from socket import * > sock=socket(AF_UNIX,SOCK_STREAM) > sock.bind("/tmp/mysocket") ... This seems more logical. Besides there is also a "file" type "fifo" where I was using mkfifo. I'll give it a try. Unfortunately I began to upgrade my Gentoo Linux and I am busy now. Thank you. From indigo at bitglue.com Tue Aug 17 14:48:03 2004 From: indigo at bitglue.com (Phil Frost) Date: Tue, 17 Aug 2004 14:48:03 -0400 Subject: read input file a line as a list in python In-Reply-To: <20040817184032.C3A411589B@net.tamu.edu> References: <20040817184032.C3A411589B@net.tamu.edu> Message-ID: <20040817184803.GB31097@unununium.org> pydoc string.split pydoc file pydoc sre On Tue, Aug 17, 2004 at 01:40:32PM -0500, Yong Wang wrote: > Hi, All: > I need to read a input file as soucre to process data. Ideally > if I can read a line from input file as a list (coloumn separate by > white space), reorganize field in a line. Does python has this kind of > command ? > for example, I read a line has: > "IP MAC Date..." as a line from input file, How can I only get MAC ? > Thanks, > > Yong From davidf at sjsoft.com Fri Aug 6 05:53:29 2004 From: davidf at sjsoft.com (David Fraser) Date: Fri, 06 Aug 2004 11:53:29 +0200 Subject: Decorator keyword In-Reply-To: References: Message-ID: Anthony Baxter wrote: > On 5 Aug 2004 17:17:39 -0700, Steven Bethard wrote: > >>I was just going to let this go because I thought it had been shut >>down, but as it seems to have been reopened, I'd love to see something >>like: >> >>with classmethod >>with returns(int) >>def func(*args, **kwds): >> return 1 > > > "with" is a non-starter - there's already other plans to use with for other > things, at some distant point. Also, if we're to have a new keyword, it > should be _much_ more obvious than 'with'. Any pointers to info on other plans for with? suggestions: declare declare classmethod declare returns(int) def func(*args, **kwds): return 1 Other ideas would be "decorate", but this doesn't really seem to make sense (perhaps suggesting that decorators isn't the best name for them :-)) or "wrap" (because they literally wrap the function, but again that doesn't seem intuitive. David From po-yung.liu at pandora.be Mon Aug 16 21:05:41 2004 From: po-yung.liu at pandora.be (Vent d'Est - East Wind) Date: Tue, 17 Aug 2004 01:05:41 GMT Subject: Python / scheme implement In-Reply-To: References: <8kcUc.216223$pC2.10693727@phobos.telenet-ops.be> Message-ID: Daniel Yoo wrote: > Vent d'Est - East Wind wrote: > : Can somebody tell me what s exactly the difference beetween scheme and > : python languages > > : i m thiking to learn one of them but i m not sure wich one > > : somebody told me python is better and have much library > : somebody told me scheme is much smarter and have nice structure > > Hello! > > > What programming language experience do you already have? > beginner i like script-fu and python-fu in gimp but it s not the only soft to do i m think to write a network gui soft i have some problem with scheme on my debian Running the PLT installer... ./bin/mzscheme: relocation error: ./bin/mzscheme: symbol __libc_stack_end, version GLIBC_2.1 not defined in file ld-linux.so.2 with link time reference Error: PLT installer failed. i installed one on my windows and work fine but i dont want to stay to long on windows because too buggy too unstable and to virus and i begin learn linux it s quite cool > > If you're looking for Scheme learning resources, you may want to look > at the PLT web site: > > http://www.plt-scheme.org/ yeah i saw it thankx > > In particular, the Scheme folks have written a few books for learning > the language; the link above has an online version of "How to Design > Programs", which is an excellent book. Another great book whose > implementation language is Scheme is "The Structure And Interpretation > of Computer Programs": > > http://mitpress.mit.edu/sicp/ > > i see some free ebook in html format but seems difficult i think to begin with these book if i do scheme Little Schemer and Seasonned Scheme from Mit press unfortunatly still not free edition so i will surely buy on amazon.com > > On the Python side, you may want to look at: > > http://www.python.org/topics/learn/ > > If you are a beginner to programming, visit: > > http://www.python.org/topics/learn/non-prog.html > > which includes links to introductory programming tutorials. > > > > : i also see a project about a scheme/python implementation > : here is the url > : http://plt-spy.sourceforge.net/home.html > : i m not sure what s really but seems cool if someone know more about it > : or have some concrete exemple it can be more understable > > If you are interested in the other direction, I have a weak Scheme > interpreter that's written in Python: > > http://hkn.eecs.berkeley.edu/~dyoo/python/pyscheme/ > > It's not perfect (and frankly, is a little outdated!), but it's a > proof-of-concept that one language can model the other. > your soft seems very intersting but i m too beginner for understand it good in fact but in future can be cool > > Personally, I like both languages, so my advice would be to look at > them both. (But perhaps not at the same time... *grin*) > it s also why i cant choice ok i choice to learn them both if not same times wich ones first ?? > > Good luck to you! THANKXX for your precious advis i m gratefull to your hint From amk at amk.ca Tue Aug 3 10:09:50 2004 From: amk at amk.ca (A.M. Kuchling) Date: Tue, 03 Aug 2004 09:09:50 -0500 Subject: advice for perl expert wanting to learn python References: Message-ID: On Tue, 3 Aug 2004 07:39:46 +0000 (UTC), Zeljko Vrba wrote: > What's the easiest way of learning python knowing perl? Is there somewhere > a 'how-to' cookbook with parallel examples of frequent idioms in perl and > python? Jak Kirman wrote one around 1996. I've just put a copy in the Python wiki at http://www.python.org/moin/PerlPhrasebook . --amk From fumanchu at amor.org Wed Aug 25 01:58:29 2004 From: fumanchu at amor.org (Robert Brewer) Date: Tue, 24 Aug 2004 22:58:29 -0700 Subject: J2 hard-line on "using" Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E67@exchange.hqamor.amorhq.net> Paul Moore wrote: > ...I *can* defend an argument that the proposal must > take a stance on the keyword proposed. The existence of people (me, > as an example :-)) whose vote would be changed by the choice of a > keyword implies that not taking a stance leaves those people with no > basis for making their decision. As I see it, there are two camps to whom we need to be "fair" in this: 1) Those who would reject the syntax if it used an ugly word, and 2) Those who would've preferred Guido to pick an alternative keyword rather than reject the whole proposal, when it's technically trivial to change. Group #2 is why I was taking a "soft stand" on the keyword issue (and I'm it's leading advocate). In addition, when I wrote the first draft there wasn't much of a consensus over acceptable keyword(s)--there is more of one now for "using". But honestly, I can't find a heuristic for selecting one group to disappoint over the other. So I'm going to pay attention to pressure from another quarter to resolve this. I left a lot of things open from the beginning, in order to let Guido have more freedom. He's explained to me that that isn't a good idea. So I'm making the proposal fit the existing implementation more closely. This means the following changes: 1) I took out the phrase in the intro about "separating concerns", and "partial change is better than none". Guido's a smart cookie, and can decide to separate them if he so chooses. 2) I struck the paragraph at the end of Argument III (keyword choice) completely, where it talked about the keyword choice being "less important", an "independent choice" and "easy to change". 3) I changed "recommend keywords" to "recommend a keyword" throughout. This matches the phrasing of the other arguments, where we "recommend a suite", for example. As I said, these are due to Guido's leanings, not anyone else's. But they tie in nicely; the upshot for Group #1 is that the stance on keyword choice is now much more hard-line. Paul, does that settle your issue with the keywords? Robert Brewer MIS Amor Ministries fumanchu at amor.org From pm_mon at yahoo.com Wed Aug 11 11:38:06 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Wed, 11 Aug 2004 11:38:06 -0400 Subject: Rather than decorators, how about sections? Message-ID: I like many am not wild about the operator. I also don't think that the decorator syntax should be so directly attached to the method, since what we're trying to do is to say something about the *relationship between* a method and a class (e.g. "method m is a staticmethod of class C"). So if we are going to extend the Python grammar to support this sort of thing (which I believe is a good idea), my preference would be to introduce named sections within a class definition, such as... class Foo(object): staticmethods: def baz(a,b): print "I'm a static method." def bez(c,d): print "I'm a static method too." classmethods: def biz(klass): print "I'm a class method." def __init__(self): print "We all know what I am." From roy at panix.com Sun Aug 8 10:46:38 2004 From: roy at panix.com (Roy Smith) Date: Sun, 08 Aug 2004 10:46:38 -0400 Subject: @decorator syntax is sugar, but for what exactly? (decorator libraries). References: Message-ID: In article , Andrew Durdin wrote: > On Sun, 08 Aug 2004 10:19:19 -0400, Roy Smith wrote: > > > > The key question is whether the decorator mechanism would allow such a > > thing? All of the examples I've seen have the decorator defined right > > before it's used, and having a simple name. I'm guessing that the real > > syntax is @, and that any expression that evaluations to a > > callable object is kosher after the "@"? > > There was some discussion about this on python-dev, and the BDFL's > conclusion was that arbitrary expressions were not allowed, but only > dotted names (with optional parentheses), i.e.: > > @decorator > @module_or_object.decorator > @func_returning_decorator(args) > @module_or_object.func_returning_decorator(args) > > (With presumably multiple dotted levels allowed, e.g. module.object.decorator) > > See http://www.python.org/dev/doc/devel/ref/function.html for the > grammar definition. Wow, I'm glad I asked. That answer is quite surprising, and somewhat disconcerting. Lot's of special cases going on here, which is bad. BTW, I don't understand one of the examples in the grammar. It says: > If there are multiple decorators, they are applied in reverse order. For > example, the following code: > > @f1 > @f2 > def func(): pass > > is equivalent to: > > def func(): pass > func = f2(f1(func)) I don't see what that's described as "reverse order". To my eye, they're applied in the order they're specified. First you apply f1, then you apply f2. The code above is the same as: func = f1 (func) func = f2 (func) Reverse order to me would imply: func = f1(f2(func)) -or- func = f2 (func) func = f1 (func) i.e. you apply the last one first, as if you had pushed the decorators onto a stack and processed them by popping the stack. I'm not arguing that the semantics should be changed, but that using the phrase "reverse order" to describe the semantics is confusing. From ronaldoussoren at mac.com Thu Aug 5 15:48:09 2004 From: ronaldoussoren at mac.com (Ronald Oussoren) Date: Thu, 5 Aug 2004 21:48:09 +0200 Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) In-Reply-To: References: <10h24oace15n97a@news.supernews.com> Message-ID: <60FC5412-E718-11D8-89DE-000D93AD379E@mac.com> On 4-aug-04, at 21:35, Nick Vargish wrote: > Ville Vainio writes: > >> This syntax is out there with backticks and print>>. > > I agree. > > I just don't know where else to voice my opinion on this matter, but I > absolutely hate the new decorator syntax. Sorry, I just had to get > that off my chest. Why do you dislike it? Ronald From jzgoda at gazeta.usun.pl Fri Aug 20 14:53:10 2004 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Fri, 20 Aug 2004 18:53:10 +0000 (UTC) Subject: age of Python programmers References: <3064b51d.0408201047.40a9e9d8@posting.google.com> Message-ID: beliavsky at aol.com pisze: >> One thing I've always kind of wondered is what is the average age of a >> Python programmer?? What age groups use Python?? Something to think >> about.... > > Related question -- at what age can Python be taught to a bright, motivated child? My daughter is 3 months old and I can be authoritative -- it's too early. Although she's bright and motivated, of course. ;) -- Jarek Zgoda http://jpa.berlios.de/ From martin at v.loewis.de Thu Aug 12 16:11:15 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 12 Aug 2004 22:11:15 +0200 Subject: drop into the interpreter In-Reply-To: References: Message-ID: <411bceda$0$169$9b622d9e@news.freenet.de> Hoang Do wrote: > is there a facility to inspect the run-time of a python script? > Essentially, it would execute a script to a set specific point and then drop > into the interpreter. Something like a "Stop" or "Break"? Not exactly that, but code.InteractiveConsole comes *very* close. Regards, Martin From grante at visi.com Tue Aug 10 17:44:33 2004 From: grante at visi.com (Grant Edwards) Date: 10 Aug 2004 21:44:33 GMT Subject: measuring 1/100th seconds, what function? References: Message-ID: <411941c1$0$8080$a1866201@newsreader.visi.com> On 2004-08-10, Jonas K?lker wrote: > I'm sorry for asking about such a triviality, but hey, if I > can't get it by RTFM, TFM is buggy ;) Remember to submit a patch when you figure out how to fix the bug. -- Grant Edwards grante Yow! .. One FISHWICH at coming up!! visi.com From narshe at gmail.com Thu Aug 5 14:37:15 2004 From: narshe at gmail.com (Josh Close) Date: Thu, 5 Aug 2004 13:37:15 -0500 Subject: DB-API 2.0 question Message-ID: <4a0cafe2040805113741dc6b8d@mail.gmail.com> I'm using sybase and get this error when running two inserts in a row. Process 88 generated fatal exception c0000005 EXCEPTION_ACCESS_VIOLATION. SQL Server is terminating this process. All I'm doing is conn = connect(host, user, pass, db) cursor = conn.cursor() cursor.execute(update query here) cursor.execute(update query here) Do I need to put a commit() in there or something? I guess I'm not really familiar with how DB-API 2.0 works. I would think upon a second execute, the first would be committed already. -Josh From richie at entrian.com Thu Aug 26 04:29:27 2004 From: richie at entrian.com (Richie Hindle) Date: Thu, 26 Aug 2004 09:29:27 +0100 Subject: using windows defaults for executing/examining files In-Reply-To: References: Message-ID: <0l7ri0titul13msvf1r7u18150sn1976lj@4ax.com> [Micah] > Using wxPython, is there any way to get the icon associated with a file? I > want to be able to display the icon, then when it's double clicked, it > executes the file (using os.startfile ) Yes, wxMimeTypesManager. In the wxPython demo: wxPython Overview / More Windows/Controls / MimeTypesManager. -- Richie Hindle richie at entrian.com From tdelaney at avaya.com Tue Aug 17 03:15:06 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Tue, 17 Aug 2004 17:15:06 +1000 Subject: Why I love python. Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01D58A3A@au3010avexu1.global.avaya.com> Nick Patavalis wrote: > On 2004-08-17, Paul Rubin <> wrote: >> >> Compilers for languages like Lisp and Smaltalk have dealt with this >> for decades. They can either generate code that switches on the type >> tags, or have dispatch tables in the objects that point to code for >> operations like "+", or take advice or declarations from the >> programmer about the arg types, among other possibilities. Any of >> these approaches generates code that runs much faster than >> interpreted code. >> > > Yes, I know. Something like this was what I was thinking about. I > would really love to see this technology brought to Python, or at > least a discussion as to what additions would be required in the > *language* in order for similar technologies to be easily applicable > to future Pythonic environments. http://www.python.org/sigs/types-sig/ (retired) Tim Delaney From sbabbitt at commspeed.net Thu Aug 26 21:54:23 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Thu, 26 Aug 2004 18:54:23 -0700 Subject: tarfile's tar.extractfile() file-like object incompatible with pickle.load()? References: <3e6d6c21.0408261043.264c3a2d@posting.google.com> Message-ID: <1093572562.971353@news.commspeed.net> "Matt Doucleff" wrote in message news:3e6d6c21.0408261043.264c3a2d at posting.google.com... > Hi everyone! I must be doing something wrong here :) I have a > tarball that contains a single file whose contents are a pickled > object. I would like to unpickle the object directly from the tarball > using the file-like object provided by extractfile(). Attempts to do > this result in EOFError. However if I first extract to a temporary > file, then unpickle from there, it works. The below code reproduces > the problem (on my machine at least). I'm running Python 2.3.4, > manually installed on Debian Woody (original python removed). Thanks! > > This sample code creates (and then removes) files in the tmp directory > and in the current working directory. > > # demonstrates extractfile/unpickle failure (bug?) > > # pickle a dict to a temp file > # create tar file, add temp file to it, close tar file > # open tar file for reading > # obtain file-like object for pickled file using extractfile() > # attempt to unpickle dict from file-like object > # fails with EOFError exception > > import tarfile > import pickle > import tempfile > import os > > if __name__ == '__main__': > try: > hashtopickle = { 'a' : 1, 'b' : 2 } > > # pickle to temp file > (fd, tmpfilename) = tempfile.mkstemp() > tmpfile = os.fdopen(fd, 'w') > pickle.dump(hashtopickle, tmpfile) > tmpfile.close() > > # create tar; add temp file > tar = tarfile.open('tarpickle.tar', 'w') > tar.add(tmpfilename, 'pickledhash') > tar.close() > > # remove temp file > os.remove(tmpfilename) > > # open tarfile for reading, get filelike > tar = tarfile.open('tarpickle.tar', 'r') > filelike = tar.extractfile('pickledhash') > > # fails > hashcopy = pickle.load(filelike) > > finally: > # cleanup > os.remove('tarpickle.tar') Maby you should, import StringIO hashcopy = pickle.load(StringIO.StringIO(filelike)) but im not sure, Tom From kowald at molgen.mpg.de Sun Aug 15 05:30:27 2004 From: kowald at molgen.mpg.de (kowald at molgen.mpg.de) Date: Sun, 15 Aug 2004 11:30:27 +0200 Subject: Tkinter buttons with image ? Message-ID: <1092562227.411f2d339b7e2@imp.molgen.mpg.de> Hi everybody, I'm just getting into Tkinter and try to create a button that displays an image instead of text. I do something like: >tmp = PhotoImage(file='start.gif') >buttonStart = Button(frameWb,image=tmp,command=root.quit) The button now displays a blank (grey) area of the size of the image, but as I said, it is blank :-(. Any idea what I'm doing wrong ? I'm using Python2.3 Many thanks, Axel From tzot at sil-tec.gr Sat Aug 21 14:32:56 2004 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 21 Aug 2004 21:32:56 +0300 Subject: decorator J4 - any objections? References: <7o3di0pt7o7e6cu3q3cbkls3g5asnn9n3u@4ax.com> <7x4qmx735u.fsf@ruckus.brouhaha.com> Message-ID: On 20 Aug 2004 17:20:13 -0700, rumours say that Paul Rubin might have written: >Christos "TZOTZIOY" Georgiou writes: >> Why type decorators as a dictionary if you are not going to produce a >> dictionary? Cause if you produce a dictionary, the order of the >> decorators is no longer guaranteed. > >Does that matter? Try the following in 2.4a2: >>> from test.test_decorators import memoize >>> class A: @memoize @staticmethod def add1(a,b): return a+b @staticmethod @memoize def add2(a,b): return a+b >>> A.add1(1,2) >>> A.add2(1,2) -- TZOTZIOY, I speak England very best, "Tssss!" --Brad Pitt as Achilles in unprecedented Ancient Greek From abra9823 at mail.usyd.edu.au Tue Aug 3 18:28:55 2004 From: abra9823 at mail.usyd.edu.au (Ajay Brar) Date: Wed, 04 Aug 2004 08:28:55 +1000 Subject: Crypto.PublicKey.RSA.error: Plaintext too large In-Reply-To: References: Message-ID: <411011A7.8020301@mail.usyd.edu.au> Peter Hansen wrote: > Ajay Brar wrote: > >> I am getting an error - Crypto.PublicKey.RSA.error: Plaintext too >> large - when verifying the signature of a document. >> What i am doing is - the document and the signature are downloaded >> off the net, my verify script then connects to a server and obtains a >> public key. It then uses the public key to verify the signature. >> The whole thing works fine when i do the same thing in the >> interactive interpreter. Its only when i download the files and >> obtain the public key from the server and then verify, that i get the >> above error. >> >> any suggesstions...ideas??? > > > Carriage Return/Line Feed problems? Or trailing newline problems? thats what i am going to investigate now. But even if there were trailing newline or carriage return characters, shouldn't the verify return false instead of giving the error. cheers > > -Peter -- Ajay Brar CS Honours 2004 Smart Internet Technology Research Group http://www.it.usyd.edu.au/~abrar1 From geoff at variosoft.com Tue Aug 10 17:56:53 2004 From: geoff at variosoft.com (Geoff Caplan) Date: Tue, 10 Aug 2004 22:56:53 +0100 Subject: VB-like GUI designer? In-Reply-To: References: Message-ID: <121223110195.20040810225653@variosoft.com> Hi folks, FP> Geoff Caplan said : >> Check out VisualWx. FP> Out of curiosity, how did you come across it ? This sort of topic pops up FP> every month or so on this group, and I'd never seen it mentioned before, FP> although it seems the project has been going on for a while already... That's the wonder of Google! ------------------ Geoff Caplan Vario Software Ltd (+44) 121-515 1154 From deetsNOSPAM at web.de Mon Aug 30 16:59:59 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Mon, 30 Aug 2004 22:59:59 +0200 Subject: Size of a remote URL References: Message-ID: First of all: post working code, not some snipplet that clearly isn't capable of running due to syntactic and semantic errors. This is what I made of your code: from urllib2 import * linklisttype = ["http://www.ecs.soton.ac.uk/~harnad/Temp/Ariadne-RAE.doc"] * 4 file_sizes = [] for y in linklisttype: temp = urlopen(y) print temp temp2 = temp.info() print temp2 temp3 = temp2.getheader("Content-Length") print temp3 file_sizes.append(temp3) print file_sizes This is the result: 632832 > Date: Mon, 30 Aug 2004 20:57:49 GMT Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12 OpenSSL/0.9.6b DAV/1.0.3 PHP/4.3.2 mod_perl/1.26 Last-Modified: Sun, 20 Apr 2003 15:19:42 GMT ETag: "f10f630-9a800-3ea2ba8e" Accept-Ranges: bytes Content-Length: 632832 Connection: close Content-Type: application/msword 632832 ['632832', '632832', '632832', '632832'] Works perfect. -- Regards, Diez B. Roggisch From h.b.furuseth at usit.uio.no Sun Aug 22 14:07:51 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 22 Aug 2004 20:07:51 +0200 Subject: Regular expression guaranteed to fail References: Message-ID: Eric Brunel wrote: > I also looked for a never-matching re just a few days ago and ended up > with "^(?!$)$". It's certainly not more "standard" than yours, but I > find it a wee tad more readable (for a regular expression, I mean...): I think e.g. r'\Zx' and r'x\A' are more readable. In particular the latter, but perhaps that causes Python to locate every 'x' in the string and then check if the string starts at the next character... -- Hallvard From http Fri Aug 27 17:47:18 2004 From: http (Paul Rubin) Date: 27 Aug 2004 14:47:18 -0700 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <7xzn4gwgea.fsf@ruckus.brouhaha.com> <1gj7a1o.1a5d2q410jsn2kN%aleaxit@yahoo.com> Message-ID: <7xisb4xnh5.fsf@ruckus.brouhaha.com> aleaxit at yahoo.com (Alex Martelli) writes: > I know of no reason to forbid support for such "signing", no. If you > want to offer a patch to zipimport to let it support whatever signing, > encryption, or other devilry appeals to you, this is definitely the > right moment if you hope to see it happen in Python 2.4. I think the simplest is to just have zipimport understand jar files and their signatures. There's enough supporting infrastructure needed that getting it in 2.4 is probably asking a bit much, though. > If you mean patching zipimport to _forbid_ importing from any zipfile > whatsoever, including a plain vanilla one, I think it's too late for > THAT for Python 2.4 If signing is supported, then there has to be a way to reject imports whose signatures don't verify. It could be a runtime option or something, I guess. How does zipimport work anyway? I don't see it in the library doc index for 2.3. From rnichol_rrc at yahoo.com Sat Aug 14 01:58:09 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Sat, 14 Aug 2004 00:58:09 -0500 Subject: reading shell output in parallel In-Reply-To: References: Message-ID: Steve wrote: > Hi, > > I'm pretty new to python. I am trying to write a simple application > that can read the stdout output from a command in linux. I've tried > using x = commands.getstatusoutput() but this only gives back the > output in x after finished executing. I would like to read the > contents as it is being shown on the screen and then send parts of > this info over a simple client/server setup. I have the client/server > part set up already. > > Can anyone suggest a simple way to do this? > > Thanks for your help, I appreciate it. > > Steve One last thought before my zzzz. For you, you would probably want something like: import popen2 cmd_stream = popen2.Popen3(cmd, 1) while (cmd_stream.poll() == 1): for line in cmd_stream.childerr.readlines(): #process for line in cmd_stream.childerr.read_lines(): #clean up remaining lines not process already To do it in parallel. I'd be interested to know if the above will actually work ;) At any rate it'll get you started. From ben at benlast.com Mon Aug 16 15:06:06 2004 From: ben at benlast.com (Ben Last) Date: Mon, 16 Aug 2004 20:06:06 +0100 Subject: Flython? In-Reply-To: Message-ID: > From: python-list-bounces+ben=benlast.com at python.org > [mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of Mike > Rovner > OTOH, Flash bytecode is proprientary and may change "without > notice", SVG is > an open standard. Client machines spped is also tend to increase. Not denying the open nature of SVG, but the Flash bytecode format is effectively fixed by the huge installed base of browsers that have the Flash controls that shipped with earlier versions of IE. Not all of them have upgraded by any means (I'm told by a Flash-authoring friend of mine). Plus the use of older Flash content on sites that haven't upgraded has forced backwards compatibility on all recent updates to Flash. We now return you to your regularly scheduled programme of Python chat :) b From peufeu at free.fr Mon Aug 23 06:26:17 2004 From: peufeu at free.fr (=?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?=) Date: Mon, 23 Aug 2004 12:26:17 +0200 Subject: html templates References: Message-ID: I tried Cheetah and found it to be a bit slow. Maybe it has too many features. The template language is great, though. For speed, I'd recommend mod_python + psyco > Ajay: >> i am looking for a framework to create a fast dynamic website. between >> using Cheetah and HTMLTemplate which would you recommend? > > I've used Cheetah and it's great. I have no experience with HTMLTemplate > though. > >> also quixote offers a session management API? how secure is this session >> management? is it just a cookie on the client side? > > Feel lucky: > http://www.google.com/search?q=quixote+session+management > From eppstein at ics.uci.edu Thu Aug 5 14:45:15 2004 From: eppstein at ics.uci.edu (David Eppstein) Date: Thu, 05 Aug 2004 11:45:15 -0700 Subject: RELEASED Python 2.4, alpha 2 References: <411231C8.3020308@interlink.com.au> Message-ID: In article , Christopher T King wrote: > On Thu, 5 Aug 2004, David Eppstein wrote: > > > If this is an actual possibility, there's nothing preventing you from > > wrapping a decorated def inside a try-except block. > > And then being forced to duplicate the function definition. The way > around this is, of course, to decorate manually, but then your decorators > are segmented (some at the top of the function, some at the bottom). Let me get this straight: you're envisioning a situation in which you want to decorate a function, the decorator might fail, and if it does you want to do something else (perhaps including not decorating it at all), but with the same function body? If so, that's easy: def my_robust_decorator(func): try: return decorator_that_might_fail(func) except: return something_else @my_robust_decorator def func(args...): .... So what's the problem? -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ From richardlee2061 at yahoo.com Mon Aug 16 03:13:43 2004 From: richardlee2061 at yahoo.com (Steve Perry) Date: Mon, 16 Aug 2004 00:13:43 -0700 (PDT) Subject: reconstruct list and dictionary from file In-Reply-To: <4120599A.3030203@zeomega.com> Message-ID: <20040816071343.47983.qmail@web53702.mail.yahoo.com> Thanks for the reply. I noticed the execfile method, but unfortunately, the file format is predetermined. Any soultions? - thanks! Steve > Steve Perry wrote: > > >I have a serialized list and dictionary stored in a file, with the > >following format: > > > >mydata: > > color ["red" "green" "blue"] > > origin [0.0 13.2 9.2] > > datasource1 {server:"server1.domain" username:"client" > >password:"secret"} > > > > > > > Is the above format the only way you want to store the serialized > list? > I ask because (and in case > you aren't already aware of the 'execfile' method), if you can store > 'mydata' in the form of legal Python expressions, > you can use the 'execfile' method to create live objects out of the > data-structures stored in the list. > > Regards, > Satchit, > __________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - 100MB free storage! http://promotions.yahoo.com/new_mail From jnc at ecs.soton.ac.uk Wed Aug 11 08:56:06 2004 From: jnc at ecs.soton.ac.uk (John Carter) Date: Wed, 11 Aug 2004 13:56:06 +0100 Subject: remaining decorator syntax options References: Message-ID: >*** List notation > >Assuming a pre-def, non-indented decorator, here are the remaining >list notations: > >(1) > dec1 > dec2 > dec3 > >(2) > [dec1, dec2, dec3] > >(3) > dec1, dec2, dec3 > >I believe that version 3 was vetoed because it makes it too hard to >break lists of decorators across lines. GvR's preference is >definitely for 1, but that may be influenced by his decision for the >indicator. I have a feeling that how long the indicator is directly >affects which of (1) or (2) is preferred. Compare: > >@dec1 >@dec2 >@dec3 > >vs. > >@[dec1, dec2, dec3] > >and > >using dec1 >using dec2 >using dec3 > >vs. > >using [dec1, dec2, dec3] > If one must have a new keyword, i.e. usin, then how about following the syntax of the rest of python's control structures. using: dec1 dec2 dec3 def func(): pass An alternative syntax I thought of, which dosnt use a new key word was def func() with [dec1, dec2, dec3]: pass 'with' has the same sort of association feeling as 'using' This is probably ruled out of court as being after the fnction name. It does have the merit of generating a syntax error in 2.3 John Carter From elainejackson7355 at home.com Sat Aug 14 23:03:55 2004 From: elainejackson7355 at home.com (Elaine Jackson) Date: Sun, 15 Aug 2004 03:03:55 GMT Subject: Practical examples References: Message-ID: I've been teaching myself python as well, and everything I've written that I consider useful and/or instructive can be downloaded from my webpage at http://www.geocities.com/sean_mcilroy.html. Take a peek if you like, and feel free to ask questions if you have any. Peace "Bigbowser" wrote in message news:mailman.1656.1092498793.5135.python-list at python.org... | hi all, | | I'm new to python, and have read through | http://www.ibiblio.org/obp/thinkCSpy/ , and now I'm | looking for some simple programs to have a read | through and other more in-depth tutorials to have a | look at. | | Regards, | Bigbowser | | __________________________________________________ | Do You Yahoo!? | Tired of spam? Yahoo! Mail has the best spam protection around | http://mail.yahoo.com From webraviteja at yahoo.com Wed Aug 25 03:01:20 2004 From: webraviteja at yahoo.com (Ravi Teja Bhupatiraju) Date: 25 Aug 2004 00:01:20 -0700 Subject: Begginers questions on different distributions of py References: Message-ID: "Player" wrote in message news:... > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hello all > > Decided to try and teach myself Python again for my 1st language, after > having a look at perl again and a few others and finally deciding that if I > was ever going to fully teach myself a language it would be Python that > would be the one I could adapt to the quickest and easiest. = Basically > meaning the syntax seems to really settle well in my brain, more so than any > of the other languages :) > > Anyway first things first, I bought The Python Cookbook for a RW reference > and something python related to read in the rw and bounce ideas from. > > Then I cam to wanting a download of the language, and I had the choice of > two distros, Activestates ActivePython and the Python websites original > Python distribution. > > My question is this really, what is the python websites original Python > distribution missing that ActiveStates has. > And also vice versa - seen as how the Activestates distribution is lagging > behind the python websites distribution by a release or two. > ActivePython = ActivePython-2.3.2-232-win32-ix86.msi size = 16,687KB > Python webiste distribution = Python-2.3.4.exe size = 9,658 KB > > So what's missing out of the Python distro that is in Activestates distro? > And vice versa the other way? > :) > > Thanks in advance > M.B You should be OK with either. Personally I prefer the ActiveState's distribution. Active Python = Python + win32all + slightly more documentation. My previous reason for using ActivePython was that it had docs in HTML help which was easier to search on. If I recall correctly, the standard distribution now has the docs in HTML help too. I also prefer Pythonwin (included in win32all) to IDLE and like it set as my default Python editor (though I end up using SciTE for most part). As you can see, these are all minor preferences and you should be fine with either. There is nothing in ActivePython that you cannot install or get for free later. From DesertLinux at netscape.net Wed Aug 18 15:48:57 2004 From: DesertLinux at netscape.net (Byron) Date: Wed, 18 Aug 2004 19:48:57 GMT Subject: age of Python programmers In-Reply-To: References: Message-ID: 28 years old. I have been using Python for one year. Mostly work with VB6, but now have a new favorite. Byron --- Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... > > From adonisv at DELETETHISTEXTearthlink.net Tue Aug 24 19:22:27 2004 From: adonisv at DELETETHISTEXTearthlink.net (Adonis) Date: Tue, 24 Aug 2004 23:22:27 GMT Subject: Inline Conditionals? References: Message-ID: "Joshua Ginsberg" wrote in message news:mailman.2307.1093385983.5135.python-list at python.org... > Is there any plan to include inline conditionals in Python? For example: > > def isNegative(x): > return x < 0 ? True : False > > Thanks! > > -jag > > -- > Joshua Ginsberg > Brainstorm Internet Network Operations > How about something like: >>> def iif(condition, true=True, false=False): ... if condition: ... return true ... return false ... >>> iif('foo' == 'bar', 'w00t', 'l33t') 'l33t' >>> iif('bar' == 'bar', 'w00t', 'l33t') 'w00t' >>> iif('bar' == 'bar') True >>> iif('foo' == 'bar') False >>> Hope this helps. Adonis From peter at engcorp.com Fri Aug 6 15:49:49 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 06 Aug 2004 15:49:49 -0400 Subject: Killing children In-Reply-To: <87hdrgvzr4.fsf@debian.laymusic.org> References: <87smb0w4ln.fsf@debian.laymusic.org> <87hdrgvzr4.fsf@debian.laymusic.org> Message-ID: Laura Conrad wrote: >>>>>>"Peter" == Peter Hansen writes: > > > Peter> on Win32''' > Peter> import win32api > > Peter> It requires win32api, and I don't know how that all will work with > Peter> cygwin (which I don't use). > > win32api doesn't seem to be there on cygwin. Nor on regular Python, until you download it. It's in a separate package, formerly called win32all, now called pywin32... -Peter From anthonybaxter at gmail.com Fri Aug 6 04:43:55 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 18:43:55 +1000 Subject: Python milestone releases In-Reply-To: <4113406D.1@v.loewis.de> References: <4113406D.1@v.loewis.de> Message-ID: On Fri, 06 Aug 2004 10:25:17 +0200, "Martin v. L?wis" wrote: > The Python Business Forum once tried to attack the problem > by planning to release a "Python-in-a-tie" release. This > release would be maintained essentially forever, and they > wanted PythonLabs to commit that this release is not > superceded by another release for atleast a year. Python > 2.2 was chosen as the basis, and indeed, it lived for 18 > months without a successor. Today, 2.2 is not maintained > anymore by the "usual" maintainers, which have moved towards > 2.3 and 2.4. Nobody has taken over maintenance of 2.2, > from which I conclude there is really no need for ongoing > maintenance of old releases. My approach is that I'm happy to manage releases like so: Python 2.x Python 2.x.1 Python 2.x.2 .... Python 2.(x+1) Python 2.x.n -- one last release of the old branch Python 2.(x+1).1 .... That is, only one branch "under maintenance" at a time. I thought about maintaining 2.2 for longer, but really could see no reason to do so. It increases the workload of committers, who now might have to backport to two separate branches as well as the trunk. Having said that, if someone else wants to step forward and continue to maintain 2.3 past 2.3.5 (which is the last release of 2.3 I plan to do), they're more than welcome to do so. From peter at engcorp.com Mon Aug 9 09:50:25 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 09 Aug 2004 09:50:25 -0400 Subject: Exceptions as a Control Structure In-Reply-To: <41177b65$0$17857$626a14ce@news.free.fr> References: <411775aa$0$17867$626a14ce@news.free.fr> <41177b65$0$17857$626a14ce@news.free.fr> Message-ID: Olivier Parisy wrote: > Peter Hansen wrote: >> Exceptions are also used by some as a mechanism for >> returning information from subroutines, though it's >> very likely the information will still be considered >> "exceptional" in some way (think of it as an out-of-band >> mechanism for returning special info). > > Do you have some example of this in the standard library ? It's easy to check for yourself, you have the source. ;-) I searched for "(Exception" in the lib/*.py files, since this code is likely to occur when someone subclasses the top-level exception class. There's an example similar to what I was describing in inspect.py, using an EndOfBlock exception. The Queue module has Full and Empty exceptions that are a good example. By far the most occurrences of custom exceptions are to define specialized ones denoting error conditions, however. I suspect the usage I described is more common outside the standard library, in part because code where it would be useful is more likely to occur in higher level code. -Peter From peter at engcorp.com Mon Aug 16 11:43:51 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 11:43:51 -0400 Subject: Python indentation deters newbies? In-Reply-To: References: <3064b51d.0408130615.3fc4a760@posting.google.com> <56cfb0e3.0408142004.511a8a8e@posting.google.com> <5hbvh0hnngn8sotqkgav3o1mvs61n039e5@4ax.com> Message-ID: Richard Hanson wrote: > [Re Python's indentation -- "Neat!" or "Yuck!"] > > For the record, my first reaction to *braces* years ago, was: > "Yuck!" That was my reaction as well, but my sister really needed them as her teeth weren't straight at all. -Peter From fumanchu at amor.org Sun Aug 29 19:58:40 2004 From: fumanchu at amor.org (Robert Brewer) Date: Sun, 29 Aug 2004 16:58:40 -0700 Subject: Call for signatories for J2 Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E92@exchange.hqamor.amorhq.net> Arthur wrote: > Against. > > With some commitment. > > I have not read the J2 psper... Let me know when you have and I'll add your name to the list. Robert Brewer MIS Amor Ministries fumanchu at amor.org From ptmcg at austin.rr._bogus_.com Wed Aug 18 22:52:47 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Thu, 19 Aug 2004 02:52:47 GMT Subject: get last two in a length of unknown length? References: Message-ID: <3CUUc.794$v86.759@fe2.texas.rr.com> "M. Clift" wrote in message news:cg1494$lvr$1 at news7.svr.pol.co.uk... > Hi All, > > I have a list of varying length. Would someone know the way to get the last > two values for this? I can see how this is done with a list that I know the > length of, but not one thats generated by user input. > > Thanks for any help > Use negative index values to count backwards from the end of a list or tuple. x = [ 0, 1, 2, 3, 4] x[-1] gives 4 x[-2] gives 3 x[-2:] gives [3,4] <- this is called "slice" notation You will find *many* more interesting and fun facts in the Python Tutorial. -- Paul From cjw at sympatico.ca Sun Aug 22 11:01:58 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Sun, 22 Aug 2004 11:01:58 -0400 Subject: Alternative decorator syntax - keyword choice In-Reply-To: References: Message-ID: Jeremy Bowers wrote: > On Sat, 21 Aug 2004 21:51:09 -0700, Robert Brewer wrote: > >>I'd be most interested to hear arguments _against_ "declare", if there >>are any. > > > My first objection would be that decorators aren't "declarations"; that is > one use but not the only one. > Another is that the word doesn't give a clue as to what is happening. > The flip side is that I doubt that any one word will ever capture as a > reasonable verb what they are doing, so I'm not sure this argument is > meaningful, as it applies equally to all proposals, up to and including > "decorate". ("Decoration" is the mechanism, but it is not always the > result.) > > I'd have to say "transform" is probably the best candidate here; while not > all uses of decorators are transforms (like attaching pieces of metadata), > it at least brings to mind the correct implementation, which is the > passing of the method through a function. > > "declare" brings to mind attaching a piece of data to the function or > making a statement about the function to the compiler, without changing > the underlying function. Ditto "apply". > > "decorate" brings either nothing to mind, or some vision of the Design > Pattern which really isn't right. > > "as" seems to imply some sort of syntactic change, and only works AFAICS > for staticmethod and classmethod. "as: author('Steve')" doesn't make much > sense. > > To sum up, *all* keywords are insufficient, and I think there are only two > choices, depending on the goal: "transform" to give a hint about what is > really happening, or "decorate" on the grounds that there *is* no > ready-made keyword and it is reasonbly easy to attach whatever Pythonic > connotations to the word we choose; witness "generators". > > > (Apologies if this has been mentioned before; I've been trying to keep up > but I have failed.) The overall effect of implementing PEP 318 is transformative rather than decorative. Thus, "transform" is a better choice. It could be argued that even "author('Steve')" is a transformation, in that it could well amend an existing notation. Three issues which have not been discussed much are: 1. the purpose of the docstring in J2 preceding the funcdef. It it to describe the transformers or the function? 2. the placement of the extra code relative to the funcdef. (incidentally, I don't find docstring in the Python grammar) It seems to me that the reading flow would be better if it were to follow the funcdef, so that the funcbody would become funcbody ::= [[newstuff] body]. 3. whether the PEP 318 processes are to apply to classes as well as functions. Colin W. From wweston at att.net Mon Aug 2 15:44:06 2004 From: wweston at att.net (wes weston) Date: Mon, 02 Aug 2004 19:44:06 GMT Subject: Trimming a string In-Reply-To: <10gsotqjc2qrl54@news.supernews.com> References: <10gsmuieo65du5d@news.supernews.com> <10gsotqjc2qrl54@news.supernews.com> Message-ID: Double Dumbass on You wrote: > Do you feel better about yourself for having posted a smug, shithead-type > answer, troll?? > > As a matter of fact, I was in a near fatal car wreck about 7 years ago. > Suffered some brain damage. Now, I can't remember minute details such as > that which I asked. I have read the python documentation numerous times. > Sometimes, I just need a simple answer to a simple question, you simple > cocksucker. > > GO FUCK YOURSELF, it will be time well spent for you. > > "wes weston" wrote in message > news:ektPc.165630$OB3.11201 at bgtnsc05-news.ops.worldnet.att.net... > >>Double Dumbass on You wrote: >> >>>I have a string that is 7 characters and represents file mode in > > UNIX/LINUX > >>>from rpm: >>> >>>0100755 >>> >>>I don't care about the 0100 portion, I am only interested in the file >>>permissions portion which is 755. How can I get three characters from > > the > >>>string starting at the right? ( -OR- strip 4 characters from the > > left? ) > >>> >>DD, >> >> >>> x = "0100755" >> >>> print x[4:] >>755 >> >> Reading the tutorial is really time well spent. >>wes >> > > > DD, I didn't mean to offend you; was trying to help. Here's the tutorial section on slicing where word is "HelpA". http://www.python.org/doc/2.3.4/tut/node5.html#SECTION005120000000000000000 -------------------------------------------------------------------------------- Strings can be subscripted (indexed); like in C, the first character of a string has subscript (index) 0. There is no separate character type; a character is simply a string of size one. Like in Icon, substrings can be specified with the slice notation: two indices separated by a colon. >>> word[4] 'A' >>> word[0:2] 'He' >>> word[2:4] 'lp' Slice indices have useful defaults; an omitted first index defaults to zero, an omitted second index defaults to the size of the string being sliced. >>> word[:2] # The first two characters 'He' >>> word[2:] # All but the first two characters 'lpA' From fred at acme.com Sat Aug 21 00:42:50 2004 From: fred at acme.com (Fred) Date: Sat, 21 Aug 2004 06:42:50 +0200 Subject: [newbie] Strange behavior of the re module References: <2ejdi01btug5iskb4ipjpj7eaprd8i7vgm@4ax.com> <4126CFCC.8000609@zephyrfalcon.org> Message-ID: On Sat, 21 Aug 2004 00:30:04 -0400, Hans Nowak wrote: >To use a non-escaping backslash in a string literal, use a double backslash: > > stuff = "\\colortbl\\red0\\n0" > >or a raw string: > > stuff = r"\colortbl\red0\n0" Thx Hans for the prompt answer. I'll have to use the second form since I can't modify the content of the HTML pages I'm looping through... but no matter which option I use (either r or R), Python is still not happy: --------------------------------------- import re #NOK stuff=r"\colortbl\red0\gn0" #NOK stuff=R"\colortbl\red0\gn0" template = "BLA" template = re.sub('BLA', stuff, template) --------------------------------------- Traceback (most recent call last): File "C:\test.py", line 9, in ? template = re.sub('BLA', stuff, template) File "G:\Python23\lib\sre.py", line 143, in sub return _compile(pattern, 0).sub(repl, string, count) File "G:\Python23\lib\sre.py", line 257, in _subx template = _compile_repl(template, pattern) File "G:\Python23\lib\sre.py", line 244, in _compile_repl raise error, v # invalid expression sre_constants.error: bad group name Maybe the r/R prefix is not available in ActivePython? Thanks Fred. From apardon at forel.vub.ac.be Thu Aug 19 03:38:11 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 19 Aug 2004 07:38:11 GMT Subject: Piping stdout to Python callable References: Message-ID: Op 2004-08-19, Edward Diener schreef : > Antoon Pardon wrote: >> >> Then I fear there is no other solution. As far as I understand, you >> can't redirect standard output on a per thread basis, (at least not >> in python.) That means that if you redirect stdout of the A.py module >> to go into a pipe, the stdout of MyOwnModule.py will go into the >> same pipe. I don't think you want that. > > Just wanted to write that someone else pointed out to me os.popen("python > A.py") and that did work well as an alternative to using os.system(etc.) . > Nonetheless thanks for your help. I mentioned this so that you would know > also know about it yourself if you hadn't encountered it. I know about popen, but that didn't seem to resolve your concern. Working with popen will result in launching a second interpreter. Since one of your mayor concerns about your own solution was having two interpreters running, I didn't thought popen was a viable solution. -- Antoon Pardon From askari at addressNonValide.com Mon Aug 30 10:56:21 2004 From: askari at addressNonValide.com (Askari) Date: Mon, 30 Aug 2004 14:56:21 GMT Subject: Canvas scrolling - scrollBar become "disabled" on change in canvas References: Message-ID: Eric Brunel wrote in news:cgumjb$bnr$1 at news-reader3.wanadoo.fr: > Askari wrote: >> Hi, >> I do a "perso"widget where have two scrolls (one vertical, one >> horizontal) for a canvas. >> When, the first time, I added widget in the canvas, the scroll >> self-ajust and when I move scrollbar, the surface's canvas "moved". > > Well... It shouldn't... The only way to make the scrollable area > larger is by using theCanvas.configure(scrollregion=(x1, y1, x2, y2)); > adding items into the canvas should have no effect at all on it... > >> But when I deleted >> (.destroy) this first widgets and that a added other widget, the >> scrollBar become disabled (ajust for no scroll on the canvas). >> What/where is the problem? > > Can you please post some (simple) code that shows this behaviour? > Without a clear idea about what you're doing, it will be quite > difficult to help you... > >> I use basic widget (scrollBar, Canvas, Frame, etc.) from library's >> Tkinter (and python 2.3.4 on WinXp Pro (sp1)) >> >> Askari I try self.cv.config(scrollregion=self.cv.bbox(ALL)) but, not success. But I find that when I resize a parent's canvas or when I move the "view" on canvas (e.g. the other scrollBar not disabled), the anormal scrollBar become normal... so, I fix my problem with this lines : self.cv.yview('moveto', '1') self.cv.yview('moveto', '0') It's a stupid fix, but it work! :-) Sorry, I can't send you some code because it's minimum (if I remove comments) 200 lines... and 100 if I wrap the not important code... Askari From irmen at -nospam-remove-this-xs4all.nl Fri Aug 20 18:59:18 2004 From: irmen at -nospam-remove-this-xs4all.nl (Irmen de Jong) Date: Sat, 21 Aug 2004 00:59:18 +0200 Subject: "Socket" files? In-Reply-To: References: <1093035812.83612@jubilee.esoterica.pt> Message-ID: <4126824a$0$566$e4fe514c@news.xs4all.nl> Marcos Dione wrote: > On Fri, Aug 20, 2004 at 09:58:43PM +0100, Paulo da Silva wrote: > >>How are those "files" of type "socket", whose name >>begins with "=", created? How can I create them with >>python? > > > they don't start w/ =; that's just ls being verbose. try 'ls -1'. > > you can create them with os.mkfifo. see lib doc, section 6.1.4. mkfifo creates fifo nodes, not "socket"-type files. I think Unix domain sockets are what the OP means... Which are created by using the AF_UNIX socket type: from socket import * sock=socket(AF_UNIX,SOCK_STREAM) sock.bind("/tmp/mysocket") BTW, my ls lists them in pink, with a '=' at *the end*. That's on Mandrake 10. --Irmen From peter at engcorp.com Fri Aug 6 14:48:43 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 06 Aug 2004 14:48:43 -0400 Subject: @decorators In-Reply-To: <4113c488@nntp.zianet.com> References: <4113c488@nntp.zianet.com> Message-ID: <3PCdndlfSrERT47cRVn-hw@powergate.ca> Mark Bottjer wrote: Mark, would your example still be acceptable to you if someone wrote it like this?: > def sillyFunction( a, b, c): > """\ > The silly function does nothing except get "decorated." classmethod > determines the form of the first argument (class, object, or > other). signature changes the call behavior, asserting the types > passed to and returned from the function. Finally, transactional > causes boilerplate code to be executed before and after the function > body, ensuring that either all changes to database are applied, or > none are. Seeing as this function does nothing, this is trivial :). > """ > @classmethod > # PLH 20040806112957: added new decorator here > # PLH 20040806130023: also changed last value > @signature( None, a=int, b=float, c=dict) > @transactional( database) > pass While I find merit in your idea, it's not entirely fair to discard the @ syntax because it *can* be written the way you showed, but then not to perform the same analysis on your own idea. To be entirely fair, I'm not sure that *any* of the proposed syntaxes cannot be written in such a way that they get buggered up by intervening whitespace and comments... nor should this be a sole reason for discarding any one. -Peter From arambo314 at hotmail.com Mon Aug 23 19:45:30 2004 From: arambo314 at hotmail.com (Arthur Rambo) Date: 23 Aug 2004 16:45:30 -0700 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> Message-ID: <533e1e03.0408231545.cf59270@posting.google.com> OK guys. Now that you've debated at length of the first question addressed by Neuruss (Python limitations for mainstream acceptance), why not come back to the other aspects addressed: - dynamic languages getting closer to static languages in terms of speed - the future of Psyco, Pypy, Starkiller, Ironpython and other similar projects. What do you think? I'm sure many of us are interested in those issues (didn't the widely respected Jim Hugunin mainly advertise IronPython through its relative speed to C Python? Cf. the page title and first item on http://ironpython.com). Whatever the reasons for which making Python faster is desirable or not, it represents a very interesting technical challenge. Do you think those projects will succeed? Which other techniques do you see as promising? Arthur > It seems there are quite a few projects aimed to improve Python's > speed and, therefore, eliminate its main limitation for mainstream > acceptance. > I just wonder what do you all think? > Will Python (and dynamic languages in general) be someday close to > compiled languages speed? > What will be the future of Psyco, Pypy, Starkiller, Ironpython and all > the other projects currently on development? From fumanchu at amor.org Sat Aug 7 02:07:37 2004 From: fumanchu at amor.org (Robert Brewer) Date: Fri, 6 Aug 2004 23:07:37 -0700 Subject: threads: not locking read-only objects Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022DE6@exchange.hqamor.amorhq.net> Jon Perez wrote: > Hmmm... here's what's going on. I have a dictionary of > logged in users called 'whoison' that's updated in the main > thread (and only in the main thread) with a: > > whoison['username']="timeoflogin" # to add someone new > > and > > del whoison['username'] # to remove someone who's logged out > > > Do the above count as atomic? Yes; however, that's not enough in your case. :) > The worker threads do the following read-only operation: > > for x in whoison: > print x,whoison[x] > > Looking at the read-only code though I just realized > something.... if a dictionary entry in 'whoison' is deleted > by the main thread while the 'for x in whoison' is executing > then what would happen? You get an exception: >>> import threading >>> whoison = dict.fromkeys(xrange(100000)) >>> def iterate(): ... for a in xrange(1000): ... for x in whoison: ... 42 ... print "Done" ... >>> threading.Thread(None, iterate).start() >>> del whoison[333] >>> Exception in thread Thread-11: Traceback (most recent call last): File "C:\Python23\lib\threading.py", line 436, in __bootstrap self.run() File "C:\Python23\lib\threading.py", line 416, in run self.__target(*self.__args, **self.__kwargs) File "", line 3, in iterate RuntimeError: dictionary changed size during iteration > Looks like I'm going to need a lock after all even for the > read-only operations...? Yup. Or use some other trick, like: for k in whoison.keys(): v = whoison.get(k) print k, v ...which iterates over a copy of the keys instead of the keys themselves. Other, more complicated techniques exist. You'll soon understand why many gurus declare concurrency to be one of the recurring "hard problems" of programming. ;) Robert Brewer MIS Amor Ministries fumanchu at amor.org From pm_mon at yahoo.com Mon Aug 16 06:20:18 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Mon, 16 Aug 2004 06:20:18 -0400 Subject: Decorators: an outsider's perspective In-Reply-To: References: <20040814153534.8AC171E4007@bag.python.org> Message-ID: Anthony Baxter wrote: > On Sun, 15 Aug 2004 13:43:30 -0400, Paul Morrow wrote: > >>Define fragile. If you mean, easy to break, I don't see it. There >>would be only one way to define an instance method: name its first >>parameter 'self'. There would be only one way to define a class method: >>name its first parameter 'klass' or 'cls' (or some other synoynm that we >>can all vote on). All other methods would be static methods. >> >>How is that fragile? > > > Python currently doesn't _care_ about the argument list, and the variable > names in it. > One thought is, to preserve backwards compatability, this special behavior would only be invoked for subclasses of the new Object class. > Adding this sort of behaviour is nasty. How, for instance, would you handle > adding a method to a class at runtime? Do you poke into the newly added > method to make sure you get it right? Do you not do this? > Same rules apply. The Python system would dynamically determine the method's type when you add it (at runtime), so you'd need to make sure that the first parm name is correct in advance. > What about for more complex decorators? Remember, staticmethod and > classmethod are the trivial cases that this feature addresses. How do you > handle the more complex ones? The point is that method type declarations are not needed, so decorators wouldn't be concerned with this. Take them off the list of things decorators can do. From daniel at dittmar.net Tue Aug 10 16:12:27 2004 From: daniel at dittmar.net (Daniel Dittmar) Date: Tue, 10 Aug 2004 22:12:27 +0200 Subject: decorators vs GIL In-Reply-To: References: <0bidnfbR2_PZOIjcRVn-pA@giganews.com> Message-ID: Christopher T King wrote: > The real reason behind the GIL is that the Python interpreter is not > re-entrant; it keeps internal state in a global structure which must be > switched out (and stored somewhere) on thread changes. The real solution > to this problem is to make the interpreter stateless, thus obviating the > need for the GIL entirely. I think this task would be much easier to do > in Stackless than in CPython, but I may be wrong. Another reason is reference counting, which must be synchronized. Daniel From asqui at hotmail.com Tue Aug 17 07:09:06 2004 From: asqui at hotmail.com (asqui) Date: 17 Aug 2004 04:09:06 -0700 Subject: Case sensitivity bug in ConfigParser? Message-ID: <20568caa.0408170309.33db2d31@posting.google.com> [Apologies if this posted twice... google groups timed out on the form POST] (Assume an instantiated ConfigParser, c, with a loaded file) >>> c.get("DEFAULT", "foo", False, {"foo": "Bar"}) 'Bar' >>> c.get("DEFAULT", "Foo", False, {"Foo": "Bar"}) Traceback (most recent call last): File "", line 1, in ? c.get("DEFAULT", "Foo", False, {"Foo": "Bar"}) File "C:\Python23\lib\ConfigParser.py", line 513, in get raise NoOptionError(option, section) NoOptionError: No option 'foo' in section: 'DEFAULT' The offending code appears to be as follows (in ConfigParser.py): def get(self, section, option): opt = self.optionxform(option) if section not in self._sections: if section != DEFAULTSECT: raise NoSectionError(section) if opt in self._defaults: return self._defaults[opt] else: raise NoOptionError(option, section) elif opt in self._sections[section]: return self._sections[section][opt] elif opt in self._defaults: return self._defaults[opt] else: raise NoOptionError(option, section) It uses optionxform on the supplied option, but not on the one in the defaults dictionary. If you're going to impose a transform then you have to do it consistently, imho... >>> c.get("DEFAULT", "Foo", False, {"foo": "Bar"}) 'Bar' The supplied "Foo" gets transformed to "foo" and matches the one in the defaults dictionary. Seems a bit counterintuitive to expect that you supply any defaults as pre-transformed according to your specified optionxform. I'm not sure if this is also a problem when reading a file, but there seems to be a related post about this (with no replies!) dating back to 2000 http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=8suc1f%24mf9%241%40nnrp1.deja.com I don't have time to look into it now but I'd guess this problem was resolved in the more obvious location (when reading a file) but patching of the defaults dictionary case was omitted. asqui From __peter__ at web.de Thu Aug 5 08:45:27 2004 From: __peter__ at web.de (Peter Otten) Date: Thu, 05 Aug 2004 14:45:27 +0200 Subject: Scope Problem References: Message-ID: Nickolay Kolev wrote: Python doesn't support tail recursion; your algorithm is not only inefficient but incorrect. The number of allowed recursion levels is significantly below the maximum number of list entries. >>> import sys >>> sys.setrecursionlimit(10) # reduced for demonstration purposes >>> def index(seq, value, n=0): ... try: ... if seq[n] == value: ... return n ... else: ... return index(seq, value, n+1) ... except IndexError: ... return -1 ... >>> index(range(5), "a") -1 >>> index(range(10), "a") Traceback (most recent call last): File "", line 1, in ? File "", line 6, in index File "", line 6, in index File "", line 6, in index File "", line 6, in index File "", line 6, in index File "", line 6, in index File "", line 6, in index File "", line 6, in index File "", line 6, in index RuntimeError: maximum recursion depth exceeded The def f(value=None): if value is None: # set real default idiom is only needed for mutable default values. > @Irmen > @Daniel I see finally someone is embracing the decorator style slated for 2.4 :-) Peter From gabriel.cooper at mediapulse.com Mon Aug 16 10:13:06 2004 From: gabriel.cooper at mediapulse.com (Gabriel Cooper) Date: Mon, 16 Aug 2004 10:13:06 -0400 Subject: Practical examples In-Reply-To: References: Message-ID: <4120C0F2.202@mediapulse.com> Elaine Jackson wrote: >I've been teaching myself python as well, and everything I've written that I >consider useful and/or instructive can be downloaded from my webpage at >http://www.geocities.com/sean_mcilroy.html. Take a peek if you like, and feel >free to ask questions if you have any. > > Link should have been: http://www.geocities.com/sean_mcilroy/ or specifically: http://www.geocities.com/sean_mcilroy/python.zip From krm152 at yahoo.com Wed Aug 25 21:54:36 2004 From: krm152 at yahoo.com (Ken Moore) Date: 25 Aug 2004 18:54:36 -0700 Subject: age of Python programmers References: <20040819231139.D039A1E4003@bag.python.org> <5cf809e9.0408241126.6e3fdd5b@posting.google.com> Message-ID: <8ecda57b.0408251754.14ed27b9@posting.google.com> Hi all, I'll be 64 8/28 and started life wiring boards for 402/419/407 and other EAM equipment. Started programming 'real' computers starting with an IBM 1401 Card system with 4k characters of memory using 1401 SPS (Symbolic Programming System) the assembler of the day. Graduated to an IBM 360/30 with 3 2311 disk drives and COBOL and learned from bitter experience why 'alter... goto' should be banished from existence (I think its been obsoleted in current COBOL versions). Went on from there to large mainframes and lots of IBM assembler, CICS, and more COBOL. Dabbled with RPG and FARGO and probably a couple of languages I've completely forgotten about. Had a z80 machine custom built for me in 1977 by ByteShop East in NYC and fooled around with GW Basic. Discovered C in the early eighties and loved it. Graduated to RadioShack TRS 80 model III's (it actually had a decent COBOL compiler which I fooled around with and a great C compiler made by Mix) and Atari 800 (anyone remember Atari's Deep Blue C C compiler?) Dabbled in Java for awhile when it came out and off and on thru release 1.2. Fooled around with Perl and totally spurned Python (indentation for statement grouping, YUCKKK!). Couple of years later, wanted to do some GUI's fast, and 'lo and behold'... PYTHON to the rescue. I've been learning and using it now for about a 1/2 year and love it! BTW anybody know what SPOOL stands for? I do. Once won a magazine subscription extension for answering that question... No, you don't win anything if you answer correctly :) Oh well, so much for reminiscing peter.schwalm at epost.de (Peter Schwalm) wrote in message news:<5cf809e9.0408241126.6e3fdd5b at posting.google.com>... > Hi Andrea, > > I'm 50 and have with Cobol, C, C++, Rexx, and others for over 20 > years. My experiences with seasoned programmers were often like yours > ("make" - what's that?). And to be honest, I myself am not really fit > in usenet. But like I have always taken the time to study. > > Since 2 1/2 years I work with Python and try to do in Python whatever > is possible. If things are not possible in Python, the reasons are > usually political in nature. > > Peter Schwalm From michele.simionato at gmail.com Tue Aug 31 08:01:20 2004 From: michele.simionato at gmail.com (Michele Simionato) Date: 31 Aug 2004 05:01:20 -0700 Subject: txt2xls Message-ID: <4edc17eb.0408310401.6abf866c@posting.google.com> In would like to convert very simple text files into .xls files and I need some help. Here is the format of a typical file: # begin table.txt This should go in the first row, first column. This should go in the first row, second column. ==== This should go in the second row, first column. This should go in the second row, second column. ==== This should go in the third row, first column. This should go in the third row, second column. # end table.txt "====" separates different rows, whereas different colums are separated by an empty line. table.txt should be converted into a table.xls file containing a 3x2 table like this: ================================ ================================ This should go in the first row, This should go in the first row, first column. second column. -------------------------------- -------------------------------- This should go in the second row, This should go in the second row, first column. second column. -------------------------------- -------------------------------- This should go in the third row, This should go in the third row, first column. second column. ================================ ================================ I use OpenOffice on Linux, but I have no experience at all about the .xls format, so I would welcome help/pointers and especially snippets of code ;) TIA, Michele Simionato From eurleif at ecritters.biz Sun Aug 22 18:52:50 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sun, 22 Aug 2004 18:52:50 -0400 Subject: python doesn't like my numbers In-Reply-To: <2osfspFdnjbcU1@uni-berlin.de> References: <2osfspFdnjbcU1@uni-berlin.de> Message-ID: <2osm7nFe3t34U1@uni-berlin.de> paul k wrote: > is there any way to convince python not to take my (phone)numbers > starting with zero as octals? > > >>> int(088) > File "", line 1 > int(088) > ^ > SyntaxError: invalid token Why do they have to start with zeros in your source code? The fact that you're passing the number through int() makes me guess that you're actually talking about input of some kind which you'll pass through int(). If that's the case, they will be strings, and the problem will go away: >>> int('088') 88 From Florian.Lindner at xgm.de Mon Aug 30 07:11:32 2004 From: Florian.Lindner at xgm.de (Florian Lindner) Date: Mon, 30 Aug 2004 13:11:32 +0200 Subject: Getting other file permissions Message-ID: Hello, on a Unix System I want to get the file permissions for other. How to get this? Is os.stat("file").st_mode the right way? How to interpret the output? Thx, Florian From jedwardrm at yahoo.co.uk Mon Aug 2 17:13:58 2004 From: jedwardrm at yahoo.co.uk (Jed R. Mallen) Date: 2 Aug 2004 14:13:58 -0700 Subject: python tutes on win32 References: <1ZmdnZw7k-WA0ZDcRVn-rg@adelphia.com> Message-ID: "Robert" wrote in message news:<1ZmdnZw7k-WA0ZDcRVn-rg at adelphia.com>... > I looked up "tute" in the dictionary. No such word, so I must assume the > answer is no. I am sure a nice Google search or even a search on the Python > web site would help you a lot. My bad. Sorry, I meant tutorial. I did Google for it but I was looking for a recommended tutorial as I was just starting up Python. Thanks anyway. From jdc at uwo.ca Thu Aug 12 12:31:14 2004 From: jdc at uwo.ca (Dan Christensen) Date: Thu, 12 Aug 2004 12:31:14 -0400 Subject: measuring 1/100th seconds, what function? References: Message-ID: <87657ojp2l.fsf@uwo.ca> Roy Smith writes: > Tim Peters wrote: >> Note that on a box connected to a network time-correction >> service, time.time can appear to "run backwards" briefly at >> unpredictable times. > > This will never happen if you're running NTP. NTP does gradual > adjustments to the clock rate to ensure that the system clock is always > monotonically increasing. ntp only works well if your clock rate is very consistent. On all of the laptops I've used, I get frequent adjustments: Aug 6 20:30:45 localhost ntpd[911]: time reset -0.472600 s Aug 5 22:04:57 localhost ntpd[919]: time reset +0.670974 s Aug 5 22:34:06 localhost ntpd[919]: time reset +0.884625 s Aug 5 23:13:54 localhost ntpd[919]: time reset -0.376758 s I don't see any reason in principle ntp couldn't allow a greater offset between the local machine and the servers, and use gradual adjustments in this case. But it doesn't. Dan From greg.lindstrom at novasyshealth.com Tue Aug 31 11:39:53 2004 From: greg.lindstrom at novasyshealth.com (Greg Lindstrom) Date: Tue, 31 Aug 2004 10:39:53 -0500 Subject: mySQL access Message-ID: <026301c48f70$c2eae6a0$054b12ac@D18SYX41> Hello- I'd like to connect to a mySQL database from Python 2.3 on Windows XP. I've read up on the mySQLdb module, but do not have Microsoft Visual Studio for the C++ compile part of the exercise. Am I hosed? Or is there a way do this without having to have VS? Thanks, --greg Greg Lindstrom (501) 975-4859 NovaSys Health greg.lindstrom at novasyshealth.com "We are the music makers, and we are the dreamers of dreams" W.W. From gumuz at NO_looze_SPAM.net Fri Aug 13 09:06:17 2004 From: gumuz at NO_looze_SPAM.net (Guyon Morée) Date: Fri, 13 Aug 2004 15:06:17 +0200 Subject: Flython? References: Message-ID: <411cbcb1$0$3894$4d4ebb8e@news.nl.uu.net> You can also write your objects in python and expose them as xml-rpc/soap. Then use them from flash... "Peter Hansen" wrote in message news:BeudnTybEKkXXIbcRVn-hQ at powergate.ca... > Just been looking at Flash and ActionScript... > > In the vein of Jython, I wonder what it would take to build > a Flython? (Lousy name, I know.) That would take Python > source, presumably a subset since some things couldn't be supported, > and compile it into ActionScript bytecode (aka the bytecode compiled > from ECMAScript source for the Macromedia Flash player environment). > > With that, it would be pretty easy to write applications which > have a Flash front end, but with pretty much all the logic > on front and back implemented in Python. > > There doesn't seem to be any mention of such an idea on > the web yet. A search turns up only part of a thread > where Cameron Laird asked about marrying Flash and Python > and I replied with a reference to use of Flash in > Twisted's LivePage... > (http://groups.google.ca/groups?selm=vpdqlca3vkvp5c%40corp.supernews.com) > > -Peter From cjw at sympatico.ca Sat Aug 7 22:35:35 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Sat, 07 Aug 2004 22:35:35 -0400 Subject: Decorators In-Reply-To: References: <%A8Rc.50217$Vm1.1280580@news20.bellglobal.com> Message-ID: Roy Smith wrote: > "Colin J. Williams" wrote: > >>It seems desirable that we choose words which are as close as possible >>to their everyday usage. > > > On the other hand, it's desirable to pick words which have established > meanings in computer science too. The concept of a "decorator" is > pretty well established. The term has been used in GUI frameworks for > 10 or 15 years, and more recently has been enshrined in various pattern > collections. I guess that it depends partly on whether the majority of Python users consider themselves to be computer scientists. Colin W. From d-hanst at online.no Sat Aug 28 05:17:45 2004 From: d-hanst at online.no (Dag Hansteen) Date: Sat, 28 Aug 2004 11:17:45 +0200 Subject: My IDLE editor wont work! References: Message-ID: <009b01c48cdf$e1c92cf0$4e01a8c0@dagan> RE: My IDLE editor wont work!Hi Facundo! This is the error I get: "Traceback (most recent call last): File "C:\PYTHON23\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "C:\Python23\Lib\idlelib\idle.py", line 23, in ? idlelib.PyShell.main() File "C:\Python23\lib\idlelib\PyShell.py", line 1274, in main root = Tk(className="Idle") File "C:\Python23\lib\lib-tk\Tkinter.py", line 1564, in __init__ self.tk = _tkinter.create(screenName, baseName, className) TclError: Can't find a usable init.tcl in the following directories: {c:\ruby\tcl\lib\tcl8.3} {c:\ruby\tcl\lib\tcl8.3} c:/ruby/tcl/lib/tcl8.4 C:/PYTHON23/lib/tcl8.4 C:/lib/tcl8.4 C:/library c:/ruby/tcl/lib/tcl8.3/init.tcl: version conflict for package "Tcl": have 8.4, need 8.3 version conflict for package "Tcl": have 8.4, need 8.3 while executing "package require -exact Tcl 8.3" (file "c:/ruby/tcl/lib/tcl8.3/init.tcl" line 19) invoked from within "source c:/ruby/tcl/lib/tcl8.3/init.tcl" ("uplevel" body line 1) invoked from within "uplevel #0 [list source $tclfile]" c:/ruby/tcl/lib/tcl8.3/init.tcl: version conflict for package "Tcl": have 8.4, need 8.3 version conflict for package "Tcl": have 8.4, need 8.3 while executing "package require -exact Tcl 8.3" (file "c:/ruby/tcl/lib/tcl8.3/init.tcl" line 19) invoked from within "source c:/ruby/tcl/lib/tcl8.3/init.tcl" ("uplevel" body line 1) invoked from within "uplevel #0 [list source $tclfile]" This probably means that Tcl wasn't installed properly." ----- Original Message ----- From: Batista, Facundo To: Python-List (E-mail) Sent: Friday, August 27, 2004 10:47 PM Subject: RE: My IDLE editor wont work! [Dag Hansteen] # hi, I have a problem on my comp - I'm using win2000, and the IDLE editor won't open when I try to execute it. # I tried to uninstall the python versions(yes I had one older installed also) and reinstalled 2.3.4. That doesn't help. Execute it from the command line, to see the errors, and tell us. . Facundo ------------------------------------------------------------------------------ -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From bokr at oz.net Sat Aug 28 22:17:59 2004 From: bokr at oz.net (Bengt Richter) Date: 29 Aug 2004 02:17:59 GMT Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: On Sat, 28 Aug 2004 08:45:20 -0400, Paul Morrow wrote: [...] > >Cool! Thanks! Now I need to ponder why a function's docstring needs a >different implementation than a class's docstring (i.e. why not just >make it a straigtforward attribute of the function object). > Disclaimer: I am just speculating from appearances accessible interactively, so don't take this as developer's documention of internals. I'm just reading between the lines, trying to recognize the underlying ideas ;-) So, depending on your idea of 'straightforward' ISTM docstrings do look like 'straightforward' attributes in the way they behave: >>> def func(): ... 'func docstring' ... >>> class CNew(object): ... 'CNew docstring' ... >>> class COld: ... 'COld docstring' ... >>> func.__doc__, CNew.__doc__, COld.__doc__ ('func docstring', 'CNew docstring', 'COld docstring') But you were wondering about different _implementation_ of class and function docstrings. But implementation is a layered thing that evolves, even while surface behavior stays the same. So your question comes down to how implementation differs for getting the three __doc__ attributes in the last tuple above. As far as the language is concerned, writing func.__doc__ is no different than x.y -- we don't know what func is bound to, and we don't know whether __doc__ is an object attribute or a method in the object's class or a method somewhere in the chain of base classes, or whether func is a class and __doc__ is a class variable, etc. So we have to look into how and when those differences are discovered and have their effect. Ok, focusing on x.y, what do we need to find out? It looks like the __getattribute__ method (or its C behavioural equivalent) is the key to getting x's y attribute. So where do we find __getattribute__? Well, it's a method, and methods would be found in x's class dict, and if not there, it would be looked for in the chain of base classes. But how do we find x's class dict? x.__class__.__dict__ doesn't work if x happens to be an old style class. So type(x) serves now as the logical equivalent of x.__class__ : >>> for t in map(type, [func, CNew, CNew(), COld, COld()]): print t ... >>> for t in map(lambda o: type(type(o).__dict__), [func, CNew, CNew(), COld, COld()]): print t ... In every case we have a dict proxy, that we can now look for attributes in, so we can look for __getattribute__: >>> for t in map(lambda o:type(o).__dict__.get('__getattribute__'),[func,CNew,CNew(),COld,COld()]): print t ... None Kind of interesting. Now if we let the the attribute chase continue for CNew vs CNew(): >>> type(CNew).__getattribute__ >>> type(CNew()).__getattribute__ IOW, it looks like the None got replaced by object.__getattribute__ found in the base class of class CNew(object) for CNew() (since there was no override defined in CNew) but for CNew itself, the search started in type(CNew), so found type.__getattribute__ If we look in a thing's __dict__ we are apparently avoiding the attribute chase, but if we look via thing.__dict__ we are using the __dict__ attribute to get the __dict__, so to allow us to see what __dict__ is without attribute processing, we have to do thing.__dict__['__dict__'] or thing.__dict__.get('__dict__'). We can then look at what kind of thing that is: >>> for ob in [func,CNew,CNew(),COld,COld()]: ... print type(ob).__dict__.get('__dict__') ... None None What kinds of things are these? >>> for ob in [func,CNew,CNew(),COld,COld()]: ... print type(type(ob).__dict__.get('__dict__')) ... Looks to me like a mechanism to unify access to attributes at a particular infrastructure level, being used in this case to deal with a bunch of things that can act like dictionaries, but which might have very different implementations and limitations. E.g., IWT you could make dictionaries lazily implemented for objects whose .__dict__'s are almost always empty, and just create them on first need. Even if they start with standard name content, one could imagine creating a full dict only on update. But those are optimization games. Bottom line, comparing implementation of __doc__ in functions and new style classes to answer your question, they don't seem that different. I.e., both seem to be implemented via descriptor/property-like things: >>> type(func).__dict__['__doc__'] >>> type(func).__dict__['__doc__'].__get__ >>> type(func).__dict__['__doc__'].__get__(func) 'func docstring' >>> type(CNew).__dict__['__doc__'] >>> type(CNew).__dict__['__doc__'].__get__ >>> type(CNew).__dict__['__doc__'].__get__(CNew) 'CNew docstring' Note that old style classes and objects don't use a __doc__ descriptor: >>> type(COld) >>> type(type(COld).__dict__['__doc__']) I.e., the above is the actual doc string of classobj, not a descriptor >>> type(COld) >>> type(COld).__dict__['__doc__'] 'classobj(name, bases, dict)\n\nCreate a class object. The name must be a string; the second ar gument\na tuple of classes, and the third a dictionary.' (Of course, normally it is not retrieved this way). vs. >>> type(CNew) >>> type(CNew).__dict__['__doc__'] >>> type(type(CNew).__dict__['__doc__']) So there is a difference between func and old-style-class docstring implementations. Were you using old style classes for your question? I don't know why I did this... Regards, Bengt Richter From jdc at uwo.ca Mon Aug 9 12:44:03 2004 From: jdc at uwo.ca (Dan Christensen) Date: Mon, 09 Aug 2004 12:44:03 -0400 Subject: decorators as a special case of an @ operator? References: <87llgocrgq.fsf@uwo.ca> Message-ID: <87d620cld8.fsf@uwo.ca> Peter Hansen writes: > Dan Christensen wrote: > >> I wonder what people think of the following crazy idea, which has two >> parts. >> 1) Allow anonymous multi-line functions. For definiteness, I'll use >> the following syntax, but lambda or something else could be used >> too: >> f = def (a,b,c): >> d = a*b >> return d + c > > I think this is identical to the following code, isn't it? > > def f(a, b, c): > d = a * b > return d + c Yes. The anonymity is used below. > [...] >> Presto, you have decorators: >> f = decorator1 @ >> decorator2 @ >> def (a,b,c): >> d = a*b >> return d + c >> And the function name is at the top, like some people prefer. > > I think if we asked them, they would clarify that it is not > the name *alone* which is important, but the *definition*. Yes, I also feel that way. Having the function name first isn't the real merit of my proposal. The merit (if there is any!) is that you get a syntax much like the proposed @decorator syntax as a special case of changes that feel more pythonesque (at least to me). - anonymous functions are useful in their own right - @ is just a new binary operator, which reduces punctuation (parentheses) It also allows a form such as f = staticmethod @ def (a,b,c): d = a * b return d + c which is fairly compact, although a little heavy on the punctuation. >> - To avoid trailing backslashes, the parser would have to >> automatically continue to the next line when a line ends in @. > > Sounds like another special case, as I'm not sure Python does > this for anything right now except when there are matched > opening and closing symbols. That's true. Is there any reason that python doesn't automatically continue all incomplete binary operators, allowing x = a_very_long_expression + another_long_expression ? ---- An alternate proposal for 2): if the parser finds f x where f is callable, interpret this as f(x). Then the examples become f = decorator1 \ decorator2 \ def (a,b,c): d = a*b return d + c and f = staticmethod def (a,b,c): d = a * b return d + c But I guess this would introduce some ambiguity into the parser. Right? Dan From jepler at unpythonic.net Mon Aug 2 22:34:47 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Mon, 2 Aug 2004 21:34:47 -0500 Subject: file IO In-Reply-To: References: Message-ID: <20040803023447.GB22636@unpythonic.net> Are you using Windows? That would mean the answer is almost certainly "something to do with carriage returns and binary vs text mode". The lack of a trailing newline on the last line of your example can also make for additional trouble (though my tests on unix, with stdio, mmap, and StringIO didn't ever give me a 4-byte file, windows might give you the file "a\r\nb" when viewed in binary format, "a\nb" when viewed in text format) I doubt that the mmap module's readline knows whether the file was opened in universal text mode---that's a pure Python invention, while mmap takes a file descriptor. On Unix, I don't find that a "while" loop with mmap.readline is any faster than a "for" loop over a file: [45426 lines, 409305 bytes] $ timeit -s "..." "readspeed.read_stdio('/usr/share/dict/words')" 10 loops, best of 3: 34.9 msec per loop $ timeit -s "..." "readspeed.read_mmap('/usr/share/dict/words')" 10 loops, best of 3: 107 msec per loop [363416 lines, 3274440 bytes] $ time python -c "import readspeed; readspeed.read_stdio('biggerfile.txt')" real 0.372s user 0.331s sys 0.031s $ time python -c "import readspeed; readspeed.read_mmap('biggerfile.txt')" real 1.080s user 1.013s sys 0.021s [2907328 lines, 26195520 bytes] $ time python -c "import readspeed; readspeed.read_stdio('biggerfile.txt')" real 2.603s user 2.308s sys 0.157s $ time python -c "import readspeed; readspeed.read_mmap('biggerfile.txt')" real 8.514s user 7.893s sys 0.153s I didn't have any "bigger-than-RAM text files" around to test. Testing "biggerfile.txt" with mode "rU" gives real 3.110s, so there is some penalty from using universal newlines. ------------------------------------------------------------------------ # readspeed.py from mmap import mmap, PROT_READ import itertools, os def consume(iterable): for j in iterable: pass def read_stdio(filename): f = open(filename) # open(filename, "rU") is slightly slower consume(f) def read_mmap(filename): f = open(filename) fd = f.fileno() m = mmap(fd, os.fstat(fd).st_size, prot=PROT_READ) while 1: if not m.readline(): break ------------------------------------------------------------------------ -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From michaels at rd.bbc.co.uk Thu Aug 26 06:29:24 2004 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Thu, 26 Aug 2004 11:29:24 +0100 Subject: Call for signatories for J2 References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> Message-ID: Alex Martelli wrote: ... > I wish we'd use a better keyword than 'using' which would have a > bazillion other possible and useful future interpretations. Of the > possible keywords mentioned on the site, several (by, per, through, > via) appear better to me, and I'd particularly love the three-letter > ones as they'd align well with 'def' -- my own preference would be > 'per'. > > However, I suspect it's too late to submit J2 with anything but > 'using' and I'd rather have J2 with 'using' than the pie-before-def > thingy, so, here's my "tactical" FOR vote:-). It might (or might not) be too late but just as a check I checked to see if "per" is used by any projects listed in the proposal. (I was checking Twisted and Zope for "using" so decided to do "per" as well) The irony here is that just like "using" the only project that I could find out of those list on the proposal, Twisted and Zope X3 using "per" is python itself. Specifically Idle uses it internally as a shorthand for "percolator". Changing the patch to work with "per" would be simple, and I don't know if Guido reads this group (I suspect not?), but for the record "using" and "per" appear to have the same risk level to existing code - ie very low. "per"'s risk level might be marginally lower because it's only used in idle's guts, whereas "using" is used in webbrowser's get method as a sole named parameter. Whilst I can't find anything using the latter, it's certainly more likely than someone relying on the guts of a project to remain unchanging. Best regards, Michael. -- Michael.Sparks at rd.bbc.co.uk British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From lconrad at laymusic.org Fri Aug 6 15:21:35 2004 From: lconrad at laymusic.org (Laura Conrad) Date: Fri, 06 Aug 2004 15:21:35 -0400 Subject: Killing children References: <87smb0w4ln.fsf@debian.laymusic.org> Message-ID: <87hdrgvzr4.fsf@debian.laymusic.org> >>>>> "Peter" == Peter Hansen writes: Peter> on Win32''' Peter> import win32api Peter> It requires win32api, and I don't know how that all will work with Peter> cygwin (which I don't use). win32api doesn't seem to be there on cygwin. -- Laura (mailto:lconrad at laymusic.org , http://www.laymusic.org/ ) (617) 661-8097 fax: (501) 641-5011 233 Broadway, Cambridge, MA 02139 From grante at visi.com Sun Aug 15 21:33:58 2004 From: grante at visi.com (Grant Edwards) Date: 16 Aug 2004 01:33:58 GMT Subject: Python secure? References: <6o75v1-p92.ln1@home.rogerbinns.com> <412009f1$0$8090$a1866201@newsreader.visi.com> Message-ID: <41200f06$0$65568$a1866201@newsreader.visi.com> On 2004-08-16, Grant Edwards wrote: > Ah. Nobody said the decompiled code would be redistributed. > Distributing copies (decompiled or otherwised) is covered by > copyright law. Decompiling is not. I've read up a bit, and I looks like I was wrong. The mere act of creating a derived work is an infringement of copyright. The derived work doesn't have to be distributed for an infringment to have taken place. Title 17 says ? 106. Exclusive rights in copyrighted works Subject to sections 107 through 122, the owner of copyright under this title has the exclusive rights to do and to authorize any of the following: (1) to reproduce the copyrighted work in copies or phonorecords; (2) to prepare derivative works based upon the copyrighted work; The "fair use" provisions for computer programs (?117) do not cover de-compiling or reverse-engineering. -- Grant Edwards grante Yow! PARDON me, am I at speaking ENGLISH? visi.com From peter at engcorp.com Mon Aug 16 21:50:30 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 21:50:30 -0400 Subject: No validation routine for an os.path In-Reply-To: References: Message-ID: Edward Diener wrote: > Try as I might I can not find a routine in os.path which validates whether > or not a path is syntactically valid, either as a directory or as a file. > This is surprising since, although I know this is OS dependent, Python has > many other classes and functions which will work properly depending on what > OS they are currently running under. Is there such a path validation routine > in any of the libraries distributed with Python or in any other 3rd party > Python libraries ? I don't really think so, and the last time this sort of thing was discussed, I believe the conclusion was that it's not actually possible to do such a thing in all cases anyway, unless you are willing to actually attempt to create the file or directory during the validation. One reason I recall being given is that even on a given OS, different file systems may support different sets of characters for filenames. For example, a CDROM might disallow certain characters which the standard file system allows, or a networked device (e.g. NFS, or Samba) might allow a wider range of possibilities than the permitted names on a hard drive. In the end, this is somewhat like validating email addresses. Until you actually try and succeed (or fail) to send the message, you cannot verify whether an address is "valid" for many definitions of valid. -Peter From peter at engcorp.com Fri Aug 6 11:44:39 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 06 Aug 2004 11:44:39 -0400 Subject: Queue qsize = unreliable? In-Reply-To: References: Message-ID: James R. Saker Jr. wrote: > I see per pydoc that Queue.Queue()'s .qsize is allegedly unreliable: > > | qsize(self) > | Return the approximate size of the queue (not reliable!). > > Any thoughts on why this is unreliable (and more curiously, why it would > be put in there as an unreliable function?) Rather than roll my own > threaded fifo class, it would seem prudent to use Python's built-in > Queue but the warning signs on a rather necessary function seem curious. (Why do you think this function is necessary? It's probably rare to really need it, except perhaps during debugging... ) Anyway, the reason it's called "unreliable", though the term "inaccurate" might be more correct, is because while you are getting the size of the queue, it might be updated such that the new size is one or more fewer or larger than the value that is about to be returned to you. In effect, the value is guaranteed accurate only for the precise instant in time, now passed, that it was determined, but by the time the calling routine actually sees the value the size could be anything. Note also the latest docs at docs.python.org, which state the case a little more clearly. """Return the approximate size of the queue. Because of multithreading semantics, this number is not reliable. """ -Peter From tjreedy at udel.edu Thu Aug 5 15:18:37 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 5 Aug 2004 15:18:37 -0400 Subject: Confused about pep 318 References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: "Christopher T King" wrote in message news:Pine.LNX.4.44.0408051249050.10473-100000 at ccc6.wpi.edu... > On Fri, 6 Aug 2004, Anthony Baxter wrote: > > > http://mail.python.org/pipermail/python-dev/2004-June/thread.html#45516 > > was over a month earlier. > > That thread reaches no consensus, To me this is evasion. >Steven Bethard wrote: >> Wow, this one really feels like it was slipped in while no one was looking. You wrote: >That's because it was. ... >There had previously been no public discussions about it. You (agreeing with Steven) made a false accusation of something like dastardliness. Just admit your mistake and move on. I happen to sympathize with some of you concerns and suggestions, but not with needless bashing of volunteers. >other than, in his sole post in the thread, Guido stating >"I would love to see an implementation of this idea." Hence, I was not surprised to see it in an alpha as an experimental feature which might or might not stay. Terry J. Reedy From ark at acm.org Fri Aug 27 11:32:44 2004 From: ark at acm.org (Andrew Koenig) Date: Fri, 27 Aug 2004 15:32:44 GMT Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> Message-ID: "Kjetil Torgrim Homme" wrote in message news:1r3c28g6o9.fsf at rovereto.ifi.uio.no... > my suggestion is to allow braces to mark the suites. Python is still > strictly enforcing indentation, in fact, in some ways it's stricter > then before. The following code is legal today: def foo(x): print x x = 3 if x == 3: { foo(x) : 42 } Are you proposing to change the meaning of this code? From ben at transversal.com Fri Aug 20 04:14:47 2004 From: ben at transversal.com (Ben) Date: Fri, 20 Aug 2004 09:14:47 +0100 Subject: Alternative decorator syntax decision References: Message-ID: <4125b2f7$0$2408$afc38c87@news.easynet.co.uk> My vote: C1 C1 E1 Note it would have been C1 C1 A but I am voting on _alternatives_ to A. I think this is what you want? Ben From Ian.Sparks at etrials.com Wed Aug 18 11:28:21 2004 From: Ian.Sparks at etrials.com (Ian Sparks) Date: Wed, 18 Aug 2004 11:28:21 -0400 Subject: age of Python programmers Message-ID: <41A1CBC76FDECC42B67946519C6677A901915286@pippin.int.etrials.com> > One thing I've always kind of wondered is what is the average age of a > Python programmer?? 34. 22 years a programmer. Sheesh, I should be better at it. Actually, python helps me a lot in that regard since it separates the problem from the solution so well. I work in C# also and all that typing obfuscates the problem being solved. > -----Original Message----- > From: Lucas Raab [mailto:pythongnome at hotmail.com] > Sent: Wednesday, August 18, 2004 8:21 AM > To: python-list at python.org > Subject: age of Python programmers > > > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... > > > -- > http://mail.python.org/mailman/listinfo/python-list > From ruses at users.ch Sat Aug 21 06:48:46 2004 From: ruses at users.ch (=?ISO-8859-1?Q?=22Elveto=2C_artiste-ing=E9nieur_en_n=E9motech?= =?ISO-8859-1?Q?nique=22?=) Date: Sat, 21 Aug 2004 12:48:46 +0200 Subject: Fate of lambda, Functional Programming in Python... References: <20040820163629.8DD4F1E401A@bag.python.org> Message-ID: <4127288E.3060101@users.ch> Chas Emerick wrote: > In a comment off a post on lambda-the-ultimate, I noticed this little > offhand remark: > > '''IIRC GvR is going to kill the various lambda, map,filter & reduce > leaving just generator expressions/list comprehension.''' The real reason is political neutrality. lambda & al revealed to provide just too much access to Guido's famed time machine, when python 1.5.2 itself manifested blind patriotism after 9/11, eg >>> filter(lambda W : W not in 'ILLITERATE','BULLSHIT') 'BUSH' From news at woody.datatailors.com Mon Aug 9 11:11:18 2004 From: news at woody.datatailors.com (Peter van Kampen) Date: Mon, 9 Aug 2004 17:11:18 +0200 Subject: Apache web server and CGI References: <81a41dd.0408090447.7f27a092@posting.google.com> Message-ID: In article <81a41dd.0408090447.7f27a092 at posting.google.com>, Lad wrote: > How can I set up Apache web server to use Python for CGI processing( for file *.py). > Thanks for help > Lad I will assume you have cgi working in apache in cgi-bin. I will also assume that you want to use it on *NIX. You didn't tell and I don't know how to do it on windows ;-) The simplest thing that should work is sth like this: Create a file: test.py --------------------------------------- #!/usr/bin/env python print "Content-Type: text/html" print print """ Hello Lad! """ ---------------------------------------- Now do: chmod 755 test.py And then go there with a browser: lynx http:/localhost/cgi-bin/test.py Hth, PterK -- Peter van Kampen pterk -- at -- datatailors.com From ialbert at mailblocks.com Mon Aug 2 10:07:14 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Mon, 02 Aug 2004 10:07:14 -0400 Subject: Timing Difference: insert vs. append & reverse In-Reply-To: <35b736b9.0408020330.53b24ed3@posting.google.com> References: <35b736b9.0408020330.53b24ed3@posting.google.com> Message-ID: John Keeling wrote: > I tried the test program below. My interest is to examine timing > differences between insert vs. append & reverse for a list. But what you are measuring is the difference between one particular insert (where the index is 0) and the combination of two other builtin operators that (in this particular case) have the same effect. While your observation makes a good point, in the end we should pleased not surprised when we find ways to speed up these specific cases. Istvan. From http Sat Aug 28 04:16:07 2004 From: http (Paul Rubin) Date: 28 Aug 2004 01:16:07 -0700 Subject: OT: simple compiled languages? Message-ID: <7xzn4fu188.fsf_-_@ruckus.brouhaha.com> I'm wondering what other languages clpy'ers are familiar with, that have simple implmentations with compilers. I'm asking out of general interest, not for a specific application. Usually, discussions of small languages revolve around interpreters so I'm asking specifically about languages with compilers. Qualifications: - Simple compact implementation, not too many LOC and not too many machine resources needed. Example: Ron Cain's Small-C and its descendants. Tiny CC (www.tinycc.org) is pushing the complexity limits for what I have in mind. - Real compiler, must generate real machine code (not threaded code or byte code or asm macros) that's not too horrible, but needn't make serious optimizing attempts. Compiler should at least in principle be retargetable to multiple cpu's. Load-and-go operation (i.e. no external assembler needed) is highly desirable. - Real language with datatypes and semantics, not a fancy assembler or FORTH. Static or dynamic typing are both fine. Fancy parsing is not required, e.g. Lisp-like syntax is fine. - Preferably self hosting, i.e. the compiler should be able to compile itself, once you've gotten a running instance of the compiler somehow. Among other things, this helps establish that the language is actually useable. Ideas? From pete at shinners.org Thu Aug 26 10:57:28 2004 From: pete at shinners.org (Pete Shinners) Date: Thu, 26 Aug 2004 07:57:28 -0700 Subject: Static properties In-Reply-To: <412DF4DD.4070302@berrs.net> References: <412DF4DD.4070302@berrs.net> Message-ID: Per Erik Stendahl wrote: > Is it possible to define "static properties" in a class? Variables defined at the class object level are what you consider "static" in C++. One thing that can trip people up is that these static attributes can be referenced from both the Class object and any Instance objects. But assignment to the static attribute can only happen on the Class object, otherwise the Instance will "shadow" the static attribute. A simple class can demonstrate... class Example(object): alpha = 1 beta = 2 def __init__(self): Example.cappa = Example.alpha + self.beta self.theta = 4 x = Example() Example.alpha == x.alpha #both are 1 x.beta = 42 Example.beta != x.beta #now each have their own 'beta' Example.theta #AttributeError From alberto.mantovaniNOSPAM at bologna.marelli.it Wed Aug 18 04:16:07 2004 From: alberto.mantovaniNOSPAM at bologna.marelli.it (Alberto) Date: Wed, 18 Aug 2004 08:16:07 GMT Subject: Conoscere i processi presenti in windows Message-ID: <41230f6a.7833266@news.marelli.it> ciao, volevo chiedere se esistono API che permettono dal Python di: - conoscere quali processi sono presenti in windows ad un certo momento? - terminare un processo ? grazie Alberto From agriff at tin.it Mon Aug 23 02:28:07 2004 From: agriff at tin.it (Andrea Griffini) Date: Mon, 23 Aug 2004 06:28:07 GMT Subject: Has anyone implemented BASIC in Python? References: <2oo13eFcj548U1@uni-berlin.de> <2ot30hFeek8nU1@uni-berlin.de> Message-ID: <9h0ji0lvc0be65nuvcugaa3vsq5mcl3ck8@4ax.com> On Sun, 22 Aug 2004 22:30:55 -0400, Leif K-Brooks wrote: >Andrea Griffini wrote: >> I've no idea why you think that an unstructured language would >> be a good starting point. > >There's no stack to deal with, and generally less possible expressions >to worry about. You're probably right about doing an expression parser >first, though; I will. Thanks for the advice. I resorted to use two explicit stacks; one for FORs and one for GOSUBs. There is no stack for expression evaluation because python stack is used indirectly instead (expressions are evaluated directly from the parse tree). Both of the explicit stacks could have been dropped by considering a structured approach with functions instead of the concept of just GOSUB-RETURN. GOSUB-RETURN requires an explicit stack because it's a runtime concept; not a parse-time concept. So it's not only uglier to use... it's also harder to write. Writing an interpreter that executes directly a parse tree of a structured language program is IMO *easier* than writing an interpreter for an unstructured language program. That's why I think that starting from BASIC is not a good idea. Things are different if we're talking about the VM approach, but that's IMO something that should come later. >> Anyway I found the idea of a BASIC interpreter in python intriguing, >> so I wrote one this weekend. I wrote it for my egoistic fun, so >> I'm not sure if it would be useful for you (or anyone else). > >Whoa, that's your idea of a weekend project? I'm speechless. Writing parsers, interpreters and compilers is a lot simpler than many do think. Of course the evil is in the details and getting something that comes even just close to (just for example ;-) ) python is a *LOT* harder. I have "The dragon" book, and I saw that the part dedicated to recursive descent parsers is incredibly small. No wonder that writing compilers and interpreters is considered such a difficult task... IMO the shift-reduce approach is just *too* abstract (at least too abstract for *ME*, that is ;-) ). Note also that working without any requirement (i.e. creating requirements on the fly) and without any timeline (i.e. doing whatever you think it would be nice to do) and without any (pointy-haired) boss or (annoying) user is a lot easier. I actually even think that the percentage of time I spent coding the tic-tac-toe example in BASIC is not so small... >I really appreciate the example, and I'll try my best to understand it. >Did you use a parser generator or anything like that, or is it purely >hand-coded? I never use yacc/lex, I just prefer hand-coding the parsers. I never felt as pressing the problem of the speed of parsing (I've read that this is one main superiority of shift-reduce parsers). An hand-coded recursive descent parser is in my opinion very easy to write... and very easy to maintain. In the years I just found myself using tables for binary operators to avoid repeating annoying code for just different precedence levels or grouping; so I normally end up have just one function for parsing "terms" (literals, varables, function calls, parenthesized expressions and unary operators calls) and one for parsing "expressions" that handles all binary operators and that accepts the precedence level as a parameter. Statements normally get their separate handcoded parsing function (and this implies a lot of freedom about the syntax, including making parsing dependent on the *meaning* of a symbol). Also it's very easy to provide meaningful error messages. For starting I would suggest however coding a separate function at least for every precedence level (i.e. one for mul/div, one for add/sub etc.... with lower precedence ones that call higher precedence ones and with the highest "term" one that calls the lowest "expr" for example for parenthesized subexpressions). Andrea From npat at efault.net Sat Aug 14 17:09:48 2004 From: npat at efault.net (Nick Patavalis) Date: Sat, 14 Aug 2004 21:09:48 +0000 (UTC) Subject: Why I love python. In-Reply-To: References: Message-ID: On 2004-08-13 Dave Brueck wrote: > > Having said that, the cases where it is too slow make up a small > (and shrinking) portion of the total amount of development going > on. As such, better performance is always welcome, but it won't > benefit as many people and as much as other things can. IOW, anytime > you say, "wouldn't it be great if Python were faster?" you can > easily get everybody to respond, "sure!" - everybody's on board with > you there. It's when you try to fit it into the list of priorities > that you'll find that there are other things higher on the > list. Higher because they provide more benefit overall and/or to the > people who are interesting in helping out > I believe there is no point to continue our little "fight", or we risk becoming repetive and boring. Our arguments have, I think, become clear, and only time will tell who was right and who was wrong; if after-all the is a "right" and a "wrong" side in this argument. So lets drop it here, and wish the best for the language we both enjoy programming in. /npat From jeff at ccvcorp.com Fri Aug 20 15:03:54 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 20 Aug 2004 12:03:54 -0700 Subject: PEP 318: Can't we all just get along? In-Reply-To: References: Message-ID: <10icinga8b34n9e@corp.supernews.com> Neil Zanella wrote: >To summarize, here are the two reasons to use staticmethod: > >1. You want to group a bunch of functions together. However, as it happens > such functions are not useful outside of a given class, so you use > staticmethod to place them where they belong. Perhaps you do not > have enough such functions to warrant their placement inside a > module of its own. > >2. You need to use inheritance and polymorphism but you don't need instances, > or perhaps you simply need instance independent polymorphism at the class > level. > > It seems to me that the most common case for staticmethod is when you have a function which does not rely directly on the attributes of an existing class/instance, but which *conceptually* belongs with that class. For example, in wxPython, the wxImage class needs to have handlers for various filetypes installed before one can create wxImage instances from files of that type. You can't use a normal method, obviously, because you need to install these handlers before you have an instance to call a method on. You can implement them as a totally independent function (and wxPython used to do this), using a naming convention to indicate the relatedness. But really, the best way to do this is as a staticmethod on the wxImage class. It can be called before any instances are created, and it paves the way for creating such instances. (Both of your examples seem set on the idea of classes which contain *only* staticmethods; I would submit that this is an extremely unusual case, though perhaps not without some utility.) Jeff Shannon Technician/Programmer Credit International From eddie at holyrood.ed.ac.uk Wed Aug 11 12:20:17 2004 From: eddie at holyrood.ed.ac.uk (Eddie Corns) Date: Wed, 11 Aug 2004 16:20:17 +0000 (UTC) Subject: loading message thingy References: Message-ID: Robbie writes: >Even though this is not very important it would be nice to get working. >Basically all I want to do is continuously write to the same line. >So I could have a little rotating text thing showing that the script is >working or display data ie, kb downloaded so far... >ATM I am just calling a clear screen every pass with a little nap, nasty. >Something along these lines: >for i in range(1000): > print "Loading... %s" % file_size > os.system("clear") > sleep(0.5) >I also tried something with \r but that never quite worked... >Also it would be nice to be able to change more than one line so I could >have 4 threads open downloading something with 4 lines each stating the >current status of each thread... > In the old days we all used to know all the ANSI control sequences off by heart. Nowadays you have it easy with curses and the like. Not sure if curses can be used to just use as many lines as you need rather than the whole screen. Perhaps it's over the top but you 0nly need to do it once. The \r trick is the most common though, maybe you should try to get that working. Then squeeze all statuses onto 1 line eg: File 1 File 2 File 3 File 4 23% 45% 100% 0%\r 24% etc. Eddie From fakeaddress at nowhere.org Fri Aug 6 04:35:20 2004 From: fakeaddress at nowhere.org (Bryan Olson) Date: Fri, 06 Aug 2004 08:35:20 GMT Subject: Timing Difference: insert vs. append & reverse In-Reply-To: References: <35b736b9.0408020330.53b24ed3@posting.google.com> <1a517b5.0408031027.60554dfb@posting.google.com> <1a517b5.0408041305.3927a6c8@posting.google.com> Message-ID: Tim Peters wrote: > [Bryan Olson, on complicating the list object again, and 2.4's deque type] > >>But it breaks (efficient) indexing. Since we can have it all >>like Perl, why not? > > > As I said, the best Perl can do is O(1) amortized. In fact, as both of us said. > If you follow the link you gave last time and read to the bottom > following the other links, you'll find that Perl lists had > quadratic-time behavior under the steady-state queue pattern for a > long time. That was eventually fixed -- or so they say. Small > details are both tricky and vital. Agreed. But those Perl wizards, misguided as they may be, are pretty sharp. > 2.4's deque implementation is > obviously immune to "bad" patterns, steady-state queue or otherwise. > > Most immediately damning, adding another member to the list struct (to > keep track of the "low bound") would increase the size of every list > object by 8 bytes, on 32-bit boxes. Python lists are easy to spell, > use and access, and some Python apps use millions of small lists. > They wouldn't appreciate the RAM hit for a mostly-useless feature. > Most Perl programmers seem to be so confused by Perl lists that they > only use them when they have to, to shift function arguments in and > out <0.6 wink>. We must know different Perl programmers. > That's a use case for lists Python doesn't have at > all. > > You can pursue it if you want to, but with the 2.4 deque type I have > no interest in messing more with the list type. I'm talking about facilities and their implementations, not people. True, when I pointed out that Perl nails this one, I was kinda' thinking the comparison might motivate Pythoners to pursue the same enhancement. It was certainly *not* meant to deride anyone who contributed to implementing Python. Is Tim the superior Pythoner? Duh. Does Python rock? Sure. Is saving four-or-eight bytes more or less valuable than providing efficient insert at both ends? With all due respect to Python and the people who implemented it, Perl kicks on this one. -- --Bryan From xscottgjunk at yahoo.com Fri Aug 20 06:10:14 2004 From: xscottgjunk at yahoo.com (Scott Gilbert) Date: 20 Aug 2004 03:10:14 -0700 Subject: Alternative decorator syntax decision References: Message-ID: <79b2b0bb.0408200210.d2016c0@posting.google.com> C1 C1 C1 From pcm1778 at yahoo.com Wed Aug 11 19:58:53 2004 From: pcm1778 at yahoo.com (pcm1778) Date: Wed, 11 Aug 2004 23:58:53 -0000 Subject: Immediate Job: Python/PHP Developer Message-ID: We have an immediate opportunity for Python/PHP Developer in Bay Area, CA Duration: 3 months(extendable) Qualified candidate must have strong experience in Python. Experienced in Perl/PHP is strongly desired. UNIX and HTML skills required Total IT Exp: 5+ years Other skills: Javascript, CSS Please respond to payal at stecs.com with a detailed updated resume and contact information ASAP. Thanks, Payal Mehta Placement Recruiter SearchTech Solutions 307 Orchard City Dr., Suite 300 Campbell, CA 95008 Office (408) 540.1800 Ext. 231 payal at stecs.com www.stecs.com http://www.stecs.com/jobposts/index.html - visit this link to see our most recent job opportunities From davebrok at soda.csua.berkeley.edu Sun Aug 29 02:38:11 2004 From: davebrok at soda.csua.berkeley.edu (David Pokorny) Date: Sat, 28 Aug 2004 23:38:11 -0700 Subject: Announcing PyCs, a new Python-like language on .Net References: Message-ID: <6qKdnRPPZ6Cn56zcRVn-oQ@lmi.net> WARNING: unfair stab coming. "Mark Hahn" wrote in message news:mailman.2572.1093751093.5135.python- XP-like > low-traffic, high-content, mailing list. You will be able to influence the > design of the latest and greatest dynamic language. I'm resisting the urge to compare programming languages to women... or wine. If we were living about 40 years ago, "ideal societies" a.k.a. hippie communes might get thrown in this list. David From insert at spam.here Tue Aug 24 22:22:21 2004 From: insert at spam.here (Doug Holton) Date: Tue, 24 Aug 2004 21:22:21 -0500 Subject: J2 0-2-6 is available In-Reply-To: References: Message-ID: Robert Brewer wrote: > Steven Bethard wrote: > >>Actually, there's an interesting argument that the "with" for >>decorators and >>the "with" above can be thought of in similar terms: >> >>http://mail.python.org/pipermail/python-list/2004-August/235993.html >> >>I don't know if I agree with it, but I think I'm at least >>convinced they don't >>have to mean *completely* different things. > > > FYI, I'm linking to that in the next document version later tonight. > Your example from the mailing list (copied below) doesn't make sense if you mix and match the beginning period, and it is bizaar to have "with:" mean "affects a future function" while "with x:" means "within the x namespace", something very different. I would not recommend using the same keyword for two entirely different transformations, one which solely affects functions defined in the future and the other which is a regular code block but without having to repeat the same prefix (like self) over and over. with: classmethod .author = "Fran?ois Pinard" def foo(cls): pass def bar(): pass with bar: staticmethod .version = "0.2.4" So if I say: with self: init .version = 3 Is that supposed to mean: init(self) self.version = 3? So not using a period suddenly means "pass the previous or future defined variable or function to me and I'll do something to it now or in the future"? From iketo2 at netscape.net Fri Aug 27 10:01:01 2004 From: iketo2 at netscape.net (Isaac To) Date: 27 Aug 2004 22:01:01 +0800 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> <87hdqok9i6.fsf@sinken.local.csis.hku.hk> <1rfz68ely9.fsf@rovereto.ifi.uio.no> Message-ID: <876574k7du.fsf@sinken.local.csis.hku.hk> >>>>> "Kjetil" == Kjetil Torgrim Homme writes: >> and you tab at the last line, Emacs won't try to indent the >> t=t2 line further to after the pass line where it is >> impossible to execute. ^^^^^^^^^^^^^^^^^^^^^ At the second glance this statement is false. If you have a statement after "pass" it actually will execute after the pass statement which does nothing. So this is purely a convention of Emacs, making use of a pattern that is never useful in programs anyway. (If you have such pass statement and the next statement is in the same suite, you simply would delete the pass statement.) The "return" statement also has the same effect. Kjetil> interesting idea, but Python won't discover Kjetil> inconsistencies. It's a Emacs convention, so it is of course the burden of Emacs to detect inconsistency, i.e., a change of indentation is not indicated by a "pass", "return", or a statement ending with ":" and perhaps some comments after it. I imagine that it would be a very simple regular expression to write if you really want to do it. When Python is concerned and Emacs is not, Python only sees there is indentation, and only indentation, to define the suites. And it is also what people will perceive when they stare at the code. There is nothing to be inconsistent with it. Regards, Isaac. From amk at amk.ca Mon Aug 30 11:29:34 2004 From: amk at amk.ca (A.M. Kuchling) Date: Mon, 30 Aug 2004 10:29:34 -0500 Subject: PHP Documentation References: <4133124f$0$281$4d4ebb8e@news.nl.uu.net> Message-ID: On Mon, 30 Aug 2004 09:30:39 -0400, Peter Hansen wrote: > 1) Thinking it's a good idea isn't enough if you want it: somebody > has to implement it. It's been suggested before, so at this > point the next step is for someone who likes the idea enough > to just do it. Someone started doing it manually -- see http://www.python.org/moin/PythonLibraryReference . --amk From gotcha at bubblenet.be Fri Aug 27 04:02:29 2004 From: gotcha at bubblenet.be (Godefroid Chapelle) Date: 27 Aug 2004 01:02:29 -0700 Subject: Alternative decorator syntax decision References: Message-ID: <3242df70.0408270002.55fb66c0@posting.google.com> Hi all, It might be too late to send a vote... I'd understand this easily. So do not take the time to tell me I am too late ;-) C2 C2 C2 Godefroid Chapelle aka __gotcha From bryanjugglercryptographer at yahoo.com Mon Aug 16 20:08:39 2004 From: bryanjugglercryptographer at yahoo.com (Bryan Olson) Date: 16 Aug 2004 17:08:39 -0700 Subject: Generators versus Coroutines References: Message-ID: <1a517b5.0408161608.46c2023c@posting.google.com> Michael Sparks: > On Sun, 15 Aug 2004, Nick Patavalis wrote: > ... > > For me it would be *tremendously* usefull if one could yield across > > multiple levels of function calls. If this was supported, then most > > uses of O/S treads could be replaced by generators. > > You can do this already if you use Armin Rigo's Greenlets which, whilst > included in Stackless appear to work perfectly fine with standard python. > (I've only tested with 2.3 FWIW) Correct me if I'm wrong: Greenlets use a c-language extension to do the routine switching; implementing the same in pure Python is infeasable. Generators rock, but they have a shadow of the power of co-routines. Continuations are more powerful still. -- --Bryan From eldiener at earthlink.net Wed Aug 18 20:56:50 2004 From: eldiener at earthlink.net (Edward Diener) Date: Thu, 19 Aug 2004 00:56:50 GMT Subject: Piping stdout to Python callable References: Message-ID: Antoon Pardon wrote: > Op 2004-08-18, Edward Diener schreef : >> Antoon Pardon wrote: >>> Op 2004-08-17, Edward Diener schreef : >>>> From within a function in my own module I need to take the output >>>> from a Python module "A", which is sending data to stdout and which >>>> can not be changed and which I need to invoke as a top-level >>>> module, and pipe it into another function in my own module so that >>>> I can read it from stdin. Is there an easy way to do this ? The >>>> only way I can presently think to do this is through "system >>>> python A.py | python MyOwnModule.py", which seems a bit laborious >>>> having to invoke python.exe itself twice. Any other solution would >>>> be most welcome. >>> >>> What do you mean when you say you need to invoke it as a top-level >>> module? Do you mean you can't import it at all or that importing it >>> will startup the process of generating output immediatly? >> >> I mean that it has a "if __name__ == '__main__' line and I need to >> trigger it by calling 'python A.py'. > >>> >>> What bothers you with twice invoking the interpreter? >> >> Nothing practically. Just seems inelegant. >> >>> In these days >>> a program that is invoked multiples times will generally be only >>> loaded once in memory. >> >> Shared libraries may be loaded once in memory but python.exe itself >> gets reloaded each time. > > That depends on the O.S. It is possible the O.S. notices that an > invoked program is already loaded en uses the same code-segment > in memory for following invocations. > >>> Are threads an acceptable alternative? Does your MyOwnModule.py >>> needs to write to stdout? >> >> Threads are acceptable. MyOwnModule.py can do anything, depending on >> parameters, but the idea is that a certain parameter tells it to >> read from stdin on the other end of the pipe. > > Then I fear there is no other solution. As far as I understand, you > can't redirect standard output on a per thread basis, (at least not > in python.) That means that if you redirect stdout of the A.py module > to go into a pipe, the stdout of MyOwnModule.py will go into the > same pipe. I don't think you want that. Just wanted to write that someone else pointed out to me os.popen("python A.py") and that did work well as an alternative to using os.system(etc.) . Nonetheless thanks for your help. I mentioned this so that you would know also know about it yourself if you hadn't encountered it. From shalabh at cafepy.com Mon Aug 30 22:49:28 2004 From: shalabh at cafepy.com (Shalabh Chaturvedi) Date: Mon, 30 Aug 2004 19:49:28 -0700 Subject: why does this fail on python 2.2? In-Reply-To: References: Message-ID: <4133E738.20304@cafepy.com> John Hunter wrote: > I'm trying to understand why some code from a module I'm using is > failing on 2.3 but working on 2.3. Here is the minimal example that > replicates the problem > > class Results(object): > __slots__ = ( "__doinit" ) > def __new__(cls): > retobj = object.__new__(cls) > retobj.__doinit = True > return retobj > > x = Results() > > On python2.2, this fails with > > mother:~/tmp> python2.2 test.py > Traceback (most recent call last): > File "test.py", line 8, in ? > x = Results() > File "test.py", line 5, in __new__ > retobj.__doinit = True > AttributeError: 'Results' object has no attribute '_Results__doinit' Since mangling slots was a feature added in 2.3: http://sourceforge.net/tracker/index.php?func=detail&aid=569257&group_id=5470&atid=105470 http://sourceforge.net/tracker/index.php?func=detail&aid=671439&group_id=5470&atid=105470 Looking for keyword __slots__ and closed issues in the sf tracker led me to the above. -- Shalabh From jjl at pobox.com Wed Aug 25 14:38:33 2004 From: jjl at pobox.com (John J. Lee) Date: 25 Aug 2004 19:38:33 +0100 Subject: python-dev Summary for 2004-08-01 through 2004-08-15 References: Message-ID: <87y8k35ahi.fsf@pobox.com> Richie Hindle writes: > [Istvan] > > what does: > > > > > It is not to be used in the stdlib ever. > > > > mean in this context? > > As I understand it, it means that no standard library code should take > advantage of the fact that repeated s1 += s2 operations are fast in CPython > 2.4. Instead, it should use the ''.join() idiom. [...] The stdlib already *does* take advantage of the patch. It began taking advantage of it the instant the code was committed, because, for example, httplib.HTTPResponse_read_chunked() uses string concatenation. believe-it-or-not-ly y'rs, John From ajsiegel at optonline.net Wed Aug 11 15:00:38 2004 From: ajsiegel at optonline.net (ajsiegel at optonline.net) Date: Wed, 11 Aug 2004 15:00:38 -0400 Subject: PEP318 Message-ID: <1acd9271ace724.1ace7241acd927@optonline.net> Arthur wrote: >> And either intuitively, or consciously, he is doing something that >> offsets it from something truly intergrated into the core of the >> language. By breakling all of his own rules. >But it *isn't* part of the core language. I think that's the whole >point. @decorator does something that no other statement in Python does, >so why should it *look* like a normal statement? Or are you suggesting >that a keyword should be used instead of a symbol? >I must not understand your argument. I'm not making an argument. I'm speculating. The design goals of PEP318 include: """ make it obvious what is happening; at the very least it should be obvious that new users can safely ignore it when writing their own code """ I'm supportive (I guess) of that design goal, but I guess I am speculating that the actual decision as to the syntax might have been different had this not have been among the design goals. And that a lot of the discussion regarding the syntax seems to not take consideration of this particular design goal and how it might have impacted Gudio's decision. Art From martin at v.loewis.de Fri Aug 27 01:49:24 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 27 Aug 2004 07:49:24 +0200 Subject: MSI Installer Problem: can't install 2.4a2 on new install of Win2kSP2 In-Reply-To: References: <412d7dcd$0$26184$9b622d9e@news.freenet.de> <412e5452$0$24835$9b622d9e@news.freenet.de> Message-ID: <412ecb64$0$24800$9b622d9e@news.freenet.de> Richard Hanson wrote: > If I have a directory named "Python23" with *only* the immediate > contents of "Lib" in it (no other files or directories nor any of > Lib's sub-dirs) in a separate Win98 partition, then IDLE doesn't run. > However, if I rename or move that dir inside another dir, then IDLE > runs. I can move that subsetted Python23 dir back and forth between > being hidden inside another dir and being in the root, without > rebooting, and IDLE works or not, depending on the visibility of that > very limited subset of the normal Python23 install directory. Could it be that you have an environment variable PYTHONHOME or PYTHONPATH set? As for the console being mostly broken: what precisely does that mean? If you run cmd.exe, and start c:\python24\python.exe, what happens? What happens if you add a -v option to python.exe? Regards, Martin From peter at engcorp.com Fri Aug 13 08:18:40 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 13 Aug 2004 08:18:40 -0400 Subject: decorator syntax polling suggestion In-Reply-To: References: <411BF3FC.71051A6F@alcyone.com> Message-ID: <2YidnSIOKuQ8LIHcRVn-qw@powergate.ca> Anthony Baxter wrote: > On Thu, 12 Aug 2004 23:12:56 -0400, Peter Hansen wrote: > >>On the other, if there are people who are dissatisfied with >>@pie, they can vote, use the results to help them focus >>their energies on the most likely alternate candidate(s), >>and finally present a united front saying "uh, @pie >>sucks, and we have a wide consensus that syntax XXXX >>would be much better for these reasons..." > > But then you end up with the opposite problem - a pile of > people say "we want this one" (say, list-before-def), it's > implemented, then all the people who prefer pie-decorators > start jumping up and down. Why on earth would it be *implemented* before we rationally faced that phase of the debate? Nobody that I know is silly enough to think that we should immediately rip out @pie if there's an alternative that lots of people like better, since it's pretty obvious there are people who like (and have invested significant mindshare in getting used to) @pie. No, this phase doesn't involve the @pie-ists... it's a reasonable discussion amonst those who don't like it. Someone asked us to do that. Now we're doing it, so don't complain. When, or if, we reach a consensus, then we start to involve the @pie folks but until then it's not their argument. > I don't think there's as wide a concensus as I keep hearing > about. Where have you heard there *was* a consensus? I don't recall seeing such a thing, though I've raised the question of whether it exists yet. > The people who hate pie-decorators post a _lot_ - > most people seem to either not care, or else post once or > twice and then disappear. I think I'm about the only person > posting in any volume to c.l.py in favour of the syntax, and > even then, my liking of it is also driven by a dislike of the > other proposed syntaxes. Well, for the record then (and in spite of my "not their argument" rant above), could you please provide your opinion and reasons on the "decorate:" syntax? To be completely honest about it, I haven't seen very many negative comments about it. In fact, almost none, and that's why I was starting to think there *might* be a consensus forming, which is why I started asking. -Peter From squirrel at WPI.EDU Mon Aug 16 11:58:17 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Mon, 16 Aug 2004 11:58:17 -0400 Subject: Newbie question about file input In-Reply-To: References: Message-ID: On Mon, 16 Aug 2004, Christopher T King wrote: > The not-so-immediate fix would be to skip the blank line check Oops, I didn't see you were using the blank line check to check for EOF (as Ben pointed out); forget I said that. Do what he said instead. On Mon, 16 Aug 2004, Peter Hansen wrote: > (Not that this will stop someone from posting a one-liner using the "re" > module and len(findall()), but you can safely ignore them. ;-) It was hard, but I was able to restrain myself ;) From james.black at NOSPAM.luxurysubs.org Mon Aug 9 23:50:04 2004 From: james.black at NOSPAM.luxurysubs.org (James) Date: Mon, 9 Aug 2004 21:50:04 -0600 Subject: Just Starting. Message-ID: Hello My name is James and I was wondering if any of you out there can recommend a good book or link for beginners? Thanks James From noone at here.com Wed Aug 25 23:06:33 2004 From: noone at here.com (M. Clift) Date: Thu, 26 Aug 2004 04:06:33 +0100 Subject: Just a quick one References: Message-ID: Hi All, At the risk of looking stupid would someone mind showing me how this is done in this case. I can't remove the brackets from (('Bob', 'Mary'), ('Spam', 'chips')) to give(('Bob', 'Mary', 'Spam', 'chips')) . From what Phil and Sm said I thought it would be easy. I've tried using list( ). I've had a go at referencing the individual elements... Anyone? Thanks M From unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom Tue Aug 3 19:25:29 2004 From: unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom (Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.) Date: Wed, 4 Aug 2004 01:25:29 +0200 Subject: python + byte array References: Message-ID: Hi ! But COM's string parameters are in Unicode, not bytes array. And win32Com convert auto strings parameters in Unicode. Ruslan : see, also, cTypes From dontreply at caramail.com Thu Aug 19 22:10:34 2004 From: dontreply at caramail.com (Cyrille Lavigne) Date: 19 Aug 2004 19:10:34 -0700 Subject: Rita Sue and Bob too In-Reply-To: Message-ID: If you dont want them in order you should do: >if "Rita" and "Sue" and "Bob" in list: > print "They were found" >else: > print "They are not in the list" Otherwise: >c,a=0,0 >while c if list[c]=="Rita": > if list[c+1]=="Sue": > if list[c+2]=="Bob": > print "They were found" > a=1 > c=c+1 >if a!=1: > print "they are not in the list" but I'm sure there is a better way of doing this. From cito at online.de Fri Aug 13 00:50:05 2004 From: cito at online.de (Christoph Zwerschke) Date: Fri, 13 Aug 2004 06:50:05 +0200 Subject: multiline snippets with triple quotes References: <10hnj4bjqojjh05@corp.supernews.com> Message-ID: > IIRC, sequential strings with only whitespace in between them are > automatically concatenated. Yes, but you have to add either brackets around everything or backslashes at the line ends, otherwise the lines are not kept together. > This does have the disadvantage of requiring explicit newlines, however. Yes, plus you need to escape the double quotes. These three disadvantages are why I wanted to use triple quotes. Chris From maxwell at ldc.upenn.edu Tue Aug 31 16:22:31 2004 From: maxwell at ldc.upenn.edu (Mike Maxwell) Date: Tue, 31 Aug 2004 16:22:31 -0400 Subject: -c input In-Reply-To: References: <367a4461.0408311151.59b61f54@posting.google.com> Message-ID: Steven Bethard wrote: > Semicolons are only allowed with simple statements, not compound statements: > > http://docs.python.org/ref/compound.html Aargh, I'm getting perl envy... > Note that the '\' characters cause unix to include the newline in the string, > instead of reading it as the command terminator. I don't know how to do this > in Windows. Yes, I tried this, but it doesn't seem to work inside (Gnu) makefiles, either (at least I can't see how to do it). Thanks for the answers, even if they weren't what I was hoping for :-). Mike Maxwell From rnd at onego.ru Thu Aug 12 05:32:28 2004 From: rnd at onego.ru (Roman Suzi) Date: Thu, 12 Aug 2004 13:32:28 +0400 (MSD) Subject: decorator with ``` Message-ID: One more crazy syntax before-def but which could be treated more generally: ```""" Factory for new decorator syntaxes. Keeps all proposals in a list and will recombine them at random if called without a spec. """ staticmethod``` def makeDecoratorSyntax(spec=None): raise NotImplementedException() New execution block type (in addition to exec, eval and interactive) could be added to allow needed behaviour. Less-decorated are also fine: ```staticmethod``` def makeDecoratorSyntax(spec=None): raise NotImplementedException() Several block could also concatewnate: ```staticmethod``` ```decor2``` def makeDecoratorSyntax(spec=None): raise NotImplementedException() Or use ; to put them into one line: ```staticmethod; decor2``` def makeDecoratorSyntax(spec=None): raise NotImplementedException() Of course, the same could be put AFTER def, like docstring. Sincerely yours, Roman A.Suzi -- - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru - From pf_moore at yahoo.co.uk Fri Aug 27 14:17:24 2004 From: pf_moore at yahoo.co.uk (Paul Moore) Date: Fri, 27 Aug 2004 19:17:24 +0100 Subject: Sound file manipulation in Python References: <1093570115.70672@news.commspeed.net> Message-ID: "Tom B." writes: > I would try the Snack toolkit at http://www.speech.kth.se/snack/ Looks good, but more focused on manipulation and playback. I couldn't see any handling of tags/metadata. > Supported sound file formats: WAV, AU, AIFF, MP3, CSL, SD, SMP, and > NIST/Sphere No Ogg or FLAC :-( I'll keep it in mind, though. Paul. -- "Bother," said the Borg, "We've assimilated Pooh." From michele.simionato at gmail.com Sun Aug 8 00:41:08 2004 From: michele.simionato at gmail.com (Michele Simionato) Date: 7 Aug 2004 21:41:08 -0700 Subject: elements of decorator syntax suggestions References: <4edc17eb.0408062125.231f7bef@posting.google.com> <41155C33.37EEB397@alcyone.com> Message-ID: <4edc17eb.0408072041.7bfe9eff@posting.google.com> Erik Max Francis wrote in message news:<41155C33.37EEB397 at alcyone.com>... > Tim Peters wrote: > > > Overloading a unary prefix operator is out. As Anthony said, vertical > > bar seemed to be the leading contender on python-dev Friday. You can > > find tedious arguments there about most of the others that would go > > for you. > > Why is | superior to @? | already has a meaning in Python, and it has > nothing to do with decorators ... at least @ has the virtue of currently > being unused in the language, and having the precedent of being used for > a similar feature in Java. 1. @ is already used in Leo and ipython, "|" is not. 2. "|" stands visually more than other characters. 3. Many people have an irrational repulsion for "@" and "$". Michele Simionato From joshway_without_spam at myway.com Wed Aug 18 16:33:09 2004 From: joshway_without_spam at myway.com (JCM) Date: Wed, 18 Aug 2004 20:33:09 +0000 (UTC) Subject: Embedding Python in Python References: <7xu0v0l2be.fsf@ruckus.brouhaha.com> <7x3c2kkzn8.fsf@ruckus.brouhaha.com> Message-ID: Robey Holderith wrote: > On Wed, 18 Aug 2004 19:44:47 +0000, JCM wrote: ... >> I don't think it's as difficult as you think. Your snippet of code >> would be rejected by the rules I suggested. You'd also want to >> prohibit other builtins like compile, execfile, input, reload, vars, >> etc. > I'm going to have to agree with Paul on this one. I do not feel up to > the task of thinking of every possible variant of malicious code. There > are far too many ways of writing the exact same thing. I think it would > be much easier to write my own interpreter. Well it certainly isn't easier to write your own interpreter if you're talking about the effort you'd need to put into it. And I'm not convinced it's that tricky to come up with a set of syntax rules to decide whether a piece of code is simple/safe enough to run. It basically comes down to disallowing certain statements and certain identifiers. Of course you'll end up rejecting a lot of code that isn't malicious. If you're interested enough, I'll try to throw a safety-checker together. You'd have to be pretty interested though (I'm lazy). From grv575 at hotmail.com Tue Aug 3 20:42:38 2004 From: grv575 at hotmail.com (grv) Date: Wed, 4 Aug 2004 00:42:38 +0000 (UTC) Subject: numarray speed question Message-ID: <953AD3D0Didtoken@128.91.2.239> So it is supposed to be very fast to have an array of say 5 million integers stored in a binary file and do a = numarray.fromfile('filename', (2, 2, 2)) numarray.add(a, 9, a) but how is that faster than reading the entire file into memory and then having a for loop in C: (loop over range) { *p++ += 9 } or is that essentially what's going on? From M.Waack at gmx.de Mon Aug 16 15:24:16 2004 From: M.Waack at gmx.de (Mathias Waack) Date: Mon, 16 Aug 2004 21:24:16 +0200 Subject: passing globals to imported module References: Message-ID: <18e7v1-o68.ln1@valpo.de> James Tauber wrote: > > Had a question from a colleague that I embarrassingly couldn't > answer. > > He has a script, foo.py with a global. He wants to import bar.py > and needs that global available in bar.py Note that "global" in python means global in the current module. > The following obviously doesn't work: > > # foo.py > my_global = "hello" > print globals().keys() > import bar > > > # bar.py > print globals().keys() If you need the global _after_ the import you can just add in foo.py: bar.my_global = my_global Another solution would be to use a better design;) Mathias From austynjay at yahoo.com Mon Aug 16 12:35:31 2004 From: austynjay at yahoo.com (Austyn Bontrager) Date: Mon, 16 Aug 2004 16:35:31 GMT Subject: Best pattern/idiom In-Reply-To: <4117c3d8$1@buckaroo.cs.rit.edu> References: <4117c3d8$1@buckaroo.cs.rit.edu> Message-ID: You might be interested in the numarray package http://www.stsci.edu/resources/software_hardware/numarray >>> A = numarray.array([1,2,3,4]) >>> B = numarray.reshape(A, (2,2)) >>> B array([[1 2] [3 4]]) From peter.maas at mplusr.de Thu Aug 26 10:11:38 2004 From: peter.maas at mplusr.de (Peter Maas) Date: Thu, 26 Aug 2004 16:11:38 +0200 Subject: Larry Wall & Cults In-Reply-To: References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: norman werner schrieb: > Peter Hansen wrote in message news:... > >>Robert wrote: >> >> >>>Isn't "Xah Lee" chinese for "Moron"? >> >>No, it's Esperanto (universal language) for "troll"... >> >>-Peter > > > Bonvolu ne s:ercu pri nekonatoj aferoj. "Xah Lee" certe - pro manko de > Ikso - ne estas esperanto. Kaj via s:erco nur s:tulta estas. > > > Norman > tradukita: > You certainly have not the slightest idea about esperanto. So please > dont't emberass yourself. And back to topic(?): "Xah lee" is not > esperanto. I've only taken a superficial look to Esperanto but your "tradukita" seems to be a very loose translation. What does the Kaj ... phrase mean? "You are dumb", "Your joke is dumb", ...? Mit freundlichen Gruessen, Peter Maas -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- From peter at engcorp.com Mon Aug 16 11:34:40 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 11:34:40 -0400 Subject: Python indentation deters newbies? In-Reply-To: <3ke1i05c3cq93vhdmdigj3pudru9n99a4j@4ax.com> References: <3064b51d.0408130615.3fc4a760@posting.google.com> <30260531.0408131853.18ec2446@posting.google.com> <3ke1i05c3cq93vhdmdigj3pudru9n99a4j@4ax.com> Message-ID: Richard Hanson wrote: > For me, a not insignificant part of Python's genius *is* the > indentation. When I used C and C++ I was a stickler (pedant? :-) > ) for "proper" indentation -- which was a PITA. So -- I took to > Python's indentation like a duck to water. That's been exactly my situation as well, which leads me to theorize that those who react most strongly against Python's syntactically significant indentation are those who were the least consistent or, uh, "anal" about making sure their code conformed to conventions. The corollary would be that those who already wrote code which would have been accepted by a compiler which checked indentation, are those who hardly blink when encountering Python, other than to say "Of course!" as you did, and carry on writing code just as they used to, with a mild feeling of dismay that it never occurred to them before to question the supposed value of braces or begin/end tags. -Peter From spam_me_gently_with_a_chainsaw at yahoo.com Mon Aug 2 11:54:45 2004 From: spam_me_gently_with_a_chainsaw at yahoo.com (Double Dumbass on You) Date: Mon, 2 Aug 2004 08:54:45 -0700 Subject: Trimming a string References: <410B7277.3000609@mail.usyd.edu.au> <410E48BD.9060202@comcast.net> Message-ID: <10gsou5onaqjo5f@news.supernews.com> Thanks for the tip. "Tim Williams" wrote in message news:mailman.1055.1091461210.5135.python-list at python.org... > >I have a string that is 7 characters and represents file mode in UNIX/LINUX > from rpm: > > >0100755 > > >I don't care about the 0100 portion, I am only interested in the file > >permissions portion which is 755. How can I get three characters from the > >string starting at the right? ( -OR- strip 4 characters from the left? ) > > > > >>> str = "0100755" > >>> str1 = str[4:] > >>> print str1 > 755 > >>> str2 = str[-3:] > >>> print str2 > 755 > >>> From outpost at rumblefish.org Fri Aug 13 07:00:56 2004 From: outpost at rumblefish.org (Thomas D'Tak) Date: Fri, 13 Aug 2004 13:00:56 +0200 Subject: Why can't pickle dump this instance? References: Message-ID: On Thu, 12 Aug 2004 22:46:27 -0700, Jane Austine wrote: > class A: > def __init__(self,tick): > if tick: > self.foo=self.bar > else: > self.foo=self.bur > def bar(self): > print 'bar' > def bur(self): > print 'bur' > > import pickle > pickle.dumps(A()) > > running this script results in "TypeError: can't pickle function objects" > > Why does this happen? and what can I do? Running this script should actually result in TypeError: __init__() takes exactly 2 arguments (1 given) because you did not write def __init__(self, tick=None): But coming back to your original problem, have a look at the following code: def bar(): print 'bar' def bur(): print 'bur' class A: def __init__(self,tick=None): if tick: self.foo=bar else: self.foo=bur import pickle pickle.dumps(A()) The above will do what you want. Have a look at the Python Library Reference's 3.14.4 What can be pickled and unpickled? http://www.python.org/doc/2.3.4/lib/node65.html to see, why this works while the other script does not. HTH, Th. From hamilcar at tld.always.invalid Tue Aug 10 13:31:17 2004 From: hamilcar at tld.always.invalid (Hamilcar Barca) Date: Tue, 10 Aug 2004 11:31:17 -0600 Subject: How do I get IDLE on Suse Linux 9.x? References: <0G1Sc.149588$fv.89578@fe2.columbus.rr.com> Message-ID: <20040810133117.710$MS@news.newsreader.com> In article <0G1Sc.149588$fv.89578 at fe2.columbus.rr.com> (Tue, 10 Aug 2004 10:44:12 +0000), michael wrote: > I tried to run / search for IDLE which I thought was a standard install on > any python installation but it is not present. Under Debian Linux, the standard Python distribution is broken up into several packages -- which I found very confusing at first). Debian has an "idle-python2.3" package. > My question is this: Should I just use a text editor and go without IDLE? I've installed IDLE but never used it. > Is there another IDE standard on Linux? You mean besides Emacs? > Do I need to download something to get IDLE? I don't know SuSE but you do to use the standard Debian distributions of Python. From noone at here.com Fri Aug 20 08:06:49 2004 From: noone at here.com (M. Clift) Date: Fri, 20 Aug 2004 13:06:49 +0100 Subject: Rita Sue and Bob too References: Message-ID: To everyone who has posted a reply on this, I must really say thankyou. It's like having my own teacher in the room! Because of you lot I'm learning at a far quicker pace than tutorials alone. I've never felt the need to post something like this to other forums etc... while I worked out what multimedia/actionscript/language could do what I want (apart from saying thanks ; ), but this group is without doubt the friendliest and most helpful of all so far. Hats off gentlemen! M From peter at engcorp.com Tue Aug 3 21:29:19 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 03 Aug 2004 21:29:19 -0400 Subject: help: Unit test fixture returning the same object In-Reply-To: <9895e897.0408031533.26720ba0@posting.google.com> References: <9895e897.0408031533.26720ba0@posting.google.com> Message-ID: Michael McCracken wrote: > The problem is that in each test case, setUp and tearDown are called > as expected according to the print statements, but they don't seem to > have any effect after the first invocation. self.testfile is always > the same instance as reported by id(). What Roy said... but to prove it to yourself, if you need to, just implement a little class-variable-based counter in the File __init__ method to show that you are getting different objects each time. (That is, increment a global counter each time you go through __init__, and store the current count in the instance, to be retrieved and shown when you are printing the ids() for the objects.) -Peter From peter at engcorp.com Tue Aug 17 10:23:02 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 17 Aug 2004 10:23:02 -0400 Subject: How big can a Python program be? In-Reply-To: References: Message-ID: Ben Last wrote: > Hmmm... are all the resulting code objects kept forever, or are those that > are no longer required subject to garbage collection? Roughly, nothing is kept forever. I think even interned strings are now freed when no longer referenced. It certainly seems possible to structure a program such that you could feed more data to it, have it treat that data as code, compiling it, executing it, and discarding it when no longer required. I guess it becomes more of a philosophical question whether the program is the little loader that you created to do this, or the endless stream of data which gets treated as code. We're not used to seeing programs as indefinitely sized... we'd probably say something like the program is only that code which is memory resident at any given time. In any case, the difficulty with writing infinitely sized programs is that your day to day productivity, relative to the size of the task at hand, is always zero... -Peter From martin at v.loewis.de Sun Aug 22 05:52:26 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 22 Aug 2004 11:52:26 +0200 Subject: unicodedata name for \u000a In-Reply-To: References: Message-ID: <41286cdb$0$12440$9b622d9e@news.freenet.de> Ken Beesley wrote: > OK. I see that for 000A there is not now an official Unicode name in > 4.0, and that "LINE FEED (LF)" is an alias. Such an alias, shown in > uppercase letters, indicates that it _was_ the name of the character in > The Unicode Standard, Version 1.0. See The Unicode Standard 4.0, p. 415 > ("Aliases"). This seems odd. One intuitively assumes that any defined > Unicode character has a Unicode name. Indeed, this intuition is wrong. Other Unicode characters that don't have names are: - surrogates (U+D800..U+DFFF); it is debatable whether these are characters, though - private use characters (U+E000..U+F8FF, U+F0000..U+FFFFD, U+10000..U+10FFFD). Regards, Martin From michele.simionato at gmail.com Thu Aug 5 10:32:15 2004 From: michele.simionato at gmail.com (Michele Simionato) Date: 5 Aug 2004 07:32:15 -0700 Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) References: Message-ID: <4edc17eb.0408050632.58747082@posting.google.com> "Delaney, Timothy C (Timothy)" wrote in message news:... > Personally, I don't overly like the new syntax - I much preferred def > func (args) [decorators] - and I would have preferred not to "waste" @ > for them, but I can definitely live with the decision. Some usable > decorator syntax is IMO more important than none. This also my opinion, more or less. It is just the "@" which is ugly. Why not to overload (once more) the colon and write: :classmethod def func (cls, *args, **kw): pass ? Only half serious ... Michele Simionato From fredrik at pythonware.com Wed Aug 11 07:57:45 2004 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 11 Aug 2004 13:57:45 +0200 Subject: Image References: <76655b52.0408101216.4c227052@posting.google.com> Message-ID: Sheldon wrote: > im = Image.fromstring('I', (81,81),array) > gives the valueError: data not enough... > > The tutorial on Image leaves a lot to be desired. the same can be said about your ability to cut and paste: the error message is "not enough image data" and means exactly what it says. (in other words, the "array" variable contains less than 81*81*4 bytes) are you running this on Windows? if so, you need to specify that the file contains binary data when you open it: f = open(filename, "wb") # open for writing f = open(filename, "rb") # open for reading see http://docs.python.org/lib/built-in-funcs.html#l2h-25 for more details. From jonaskoelker at yahoo.com Tue Aug 10 17:16:01 2004 From: jonaskoelker at yahoo.com (=?iso-8859-1?q?Jonas_K=F6lker?=) Date: Tue, 10 Aug 2004 23:16:01 +0200 Subject: measuring 1/100th seconds, what function? Message-ID: Hello. I'm doing a Rubik's Cube timer, so I need a function to measure 100ths of a second. I've browsed through the library reference of python.org, but I didn't find anything that struck me as 'the perfect fit'. Either it was system dependent, or it was too grainy (lo-res), or... something else. so, I need a function which satisfies (in order of importance): 1. It can be used to measure time in the range of up to approximately 1 minute with an accuracy down to 100th-seconds (that's 60000~65536 different values). Better accuracy is a bonus, longer time-frame is a bigger bonus. 2. it must run on any version of windows upon which python 2.4 can run (target systems), and run on my system (debian/sarge) __ without the need for changing the code dependent of environment; any supported non-Linux/non-windows sytem is a bonus, other supported Linuxes (sp?) is a bigger bonus (however, I don't expect that it will _not_ work dependent of distroes) I'm sorry for asking about such a triviality, but hey, if I can't get it by RTFM, TFM is buggy ;) Jonas K?lker From pythongnome at hotmail.com Wed Aug 18 19:51:16 2004 From: pythongnome at hotmail.com (Lucas Raab) Date: Wed, 18 Aug 2004 23:51:16 GMT Subject: age of Python programmers References: <2ohhqhFa1qgmU1@uni-berlin.de> Message-ID: Yeah, I did a non-closable window number on a friend on mine. Needless to say he was quite annoyed. "Leif K-Brooks" wrote in message news:2ohhqhFa1qgmU1 at uni-berlin.de... > Lucas Raab wrote: > > One thing I've always kind of wondered is what is the average age of a > > Python programmer?? What age groups use Python?? Something to think > > about.... > > I'm 13, I'll be 14 in 89 days. I started doing somewhat real programming > at around 11; I had done silly things in a VB-like language for Mac OS > before then, mostly "viruses" that displayed a full-screen window with > no close button, but hadn't written any code. From dlp at itasoftware.com Fri Aug 20 09:38:44 2004 From: dlp at itasoftware.com (Dan Pierson) Date: 20 Aug 2004 06:38:44 -0700 Subject: Alternative decorator syntax decision References: Message-ID: <2b5834f8.0408200538.67b76d3a@posting.google.com> J2 J2 J2 From npat at efault.net Fri Aug 13 08:47:54 2004 From: npat at efault.net (Nick Patavalis) Date: Fri, 13 Aug 2004 12:47:54 +0000 (UTC) Subject: Why I love python. References: <411C8CD9.32F39C2@mega-nerd.com> <411C93B2.2027B48B@alcyone.com> Message-ID: On 2004-08-13, Erik Max Francis wrote: > Erik de Castro Lopo wrote: >> >> Its called type inferencing and since there is at least one working >> implementation, it can't be THAT hard. > > That's actually the kind of thing that is planned for Python with > Starkiller, however silly a project name that might be. > Correct me if I'm wrong, but I thing that starkiller produces optimized code (i.e. native code) only if it can unambiguously inference the types a-priori, and there are cases (in a dymanically typed language like python) where this is impossible. In these cases, I believe, starkiller does nothing. Are there any plans for treating such cases? And how? /npat From me at privacy.net Mon Aug 16 11:10:30 2004 From: me at privacy.net (Richard Hanson) Date: Mon, 16 Aug 2004 08:10:30 -0700 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> <30260531.0408131853.18ec2446@posting.google.com> Message-ID: <3ke1i05c3cq93vhdmdigj3pudru9n99a4j@4ax.com> [Peter Hansen wrote:] >simo wrote: > >> I'm a Perl programmer at heart - well that and PHP, plus the odd >> dabbling in C/C++/C# etc. >> >> Anyway, the thought of indentation instead of curly braces really put >> me off to start with, > >Ah, good. Someone who was really there, instead of hearsay. > > [...] > >I'm curious why more people don't have "neat!" as their very >first thought on encountering this, rather than "yuck!". [farther down-thread Peter Hansen wrote:] >For example, if 90% of people who have the "indentation rash" >had previous encounters with FORTRAN IV, then it ought to >be possible to make it obvious in the early documentation >(tutorial, intro page, etc) that Python is not FORTRAN and >doesn't suffer from the same limitations with respect to >indentation/whitespace significance as FORTRAN does. Not sure if I'm an unqualified newbie, but I'm a relative Python newbie. When I first encountered Python's indentation, my reaction was: "Of course!" -- in a seriously head-slapping way. Neat! -- is putting my reaction mildly. :-) I went on to learn more Python, and now I'm almost a Python zealot. :-) However, as I mentioned above, I may not qualify as a newbie in the context of this discussion. I started out programming on IBM 1410s and related mainframes way back in 1968 by punching programs into stacks of IBM (Hollerith) cards. The first language we learned in our, first-in-the-district (Portland, Oregon), high-school "computer" course *was* FORTRAN IV -- laboriously keypunched into those cards where different columns had different meanings. (I don't quite remember all the details. I still have boxes of my rubber-banded-together stacks of cards around, somewhere, but I'm too lazy to go look for them, now. ) In any event, I went on to learn React (a PL/1 variant), miscellaneous BASICs, various desktop and handheld HP calculator languages, HP71B Basic (very advanced -- had NaN, Inf, and such), Forth, C, C++, Smalltalk, newer Fortrans, and so on until finally hitting upon Python several years ago. For me, a not insignificant part of Python's genius *is* the indentation. When I used C and C++ I was a stickler (pedant? :-) ) for "proper" indentation -- which was a PITA. So -- I took to Python's indentation like a duck to water. That all said, I don't know if my story is the type of story a typical Python newbie would present, but since this thread has been going on for several day, I thought I'd add another datapoint. :-) ole-dinosaur-ly y'rs, Richard -- R Hanson [The mangled email addie below works.] sickolefartnewsguycom From ian at cottee.org Wed Aug 25 22:43:41 2004 From: ian at cottee.org (Ian J Cottee) Date: Thu, 26 Aug 2004 11:43:41 +0900 Subject: Idle problem In-Reply-To: <6haXc.183583$8_6.163380@attbi_s04> References: <6haXc.183583$8_6.163380@attbi_s04> Message-ID: Brent W. Hughes wrote: > Sometimes when I try to start up idle.py (by double-clicking on the icon), I > get the message: > Python subprocess socket error: Connection refused, retrying.... > It repeats the message a couple of times and then prints: > Connection to Idle failed, exiting. > > Any idea what's going on? http://aspn.activestate.com/ASPN/Mail/Message/python-dev/1748187 Doesn't offer any conclusions but might point you in the right direction. Ian From export at hope.cz Tue Aug 10 03:06:50 2004 From: export at hope.cz (Lad) Date: 10 Aug 2004 00:06:50 -0700 Subject: Apache web server and CGI References: <81a41dd.0408090447.7f27a092@posting.google.com> <10hf2ugjngver5e@corp.supernews.com> Message-ID: <81a41dd.0408092306.264beed@posting.google.com> Jeffrey Froman wrote in message news:<10hf2ugjngver5e at corp.supernews.com>... > Lad wrote: > > > How can I set up Apache web server to use Python for CGI processing( for > > file *.py). Thanks for help > > A simple method would be to include the line: > > AddHandler cgi-script .py > > in your httpd.conf. This should work fine so long as your .py files start > with a proper invocation of the python interpreter (i.e., > #!/usr/bin/python). You might also want to look at mod_python > (http://www.modpython.org/). > > Jeffrey Thank you Jeffrey and Peter for help. I added AddHandler cgi-script .py to httpd.conf I also tried to run the test script as Peter suggested but the Apache says( in error log) [Tue Aug 10 08:51:32 2004] [error] [client 127.0.0.1] (2)No such file or directory: script not found or unable to stat: c:/program files/apache group/apache/cgi-bintest.py The name of script is test.py and is in cgi-bin (Apache subdirectory). I tried to run the script from IE browser with the command http://localhost/cgi-bin/test.py but without success. I use XP home edition. Apache runs without problem as I could check it by inserting http://localhost/ BTW, how can I set up a different directory for cgi scripts? For example I would like to have all my scripts in C:\Scripts\MyScripts Thank you for help LAd From peter at engcorp.com Thu Aug 12 13:36:32 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 12 Aug 2004 13:36:32 -0400 Subject: Pyhton Interpreter Startup time In-Reply-To: <30260531.0408120829.27a536bc@posting.google.com> References: <30260531.0408120829.27a536bc@posting.google.com> Message-ID: simo wrote: > Neil Benn wrote in message news:... >> I'm looking at a small app which would need a very quick >>startup time for the Python interpreter. It doesn't do much (copying >>and caching of files, no GUI) but I need the Python interpreter to start >>up very quickly (<1 second on a Windows box). Is there a way to have a >>'stripped' down Python interpreter which can start up very quickly on a >>windows box. > > This has been discussed before, there's definitely something "odd" > about the Windows startup time in comparison to the UNIX "instant" > startup. Discussed, but not to a satisfactory conclusion I think. The fact that some of us have near instantaneous startup times, consistently (whether immediately after reboot or not) on Windows, even with older machines, suggests strongly that those who do not have something *wrong* with their system. I don't recall the OP in the last thread that discussed this ever coming back to report on exactly what OS and CPU etc. he was using, and whether network issues might be involved, etc, so until someone can prove otherwise, I think it's safe to assume that anyone with a slow startup on Windows has a misconfiguration or is doing something wrong. -Peter From just at xs4all.nl Sun Aug 29 16:21:07 2004 From: just at xs4all.nl (Just) Date: Sun, 29 Aug 2004 22:21:07 +0200 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <1LMXc.67190$UTP.37420@twister01.bloor.is.net.cable.rogers.com> <1gj7a9r.g7ec5a1g89rj0N%aleaxit@yahoo.com> Message-ID: In article , Jorge Godoy wrote: > Just writes: > > > The zipimport module will never write to the zip archive, so for most > > efficient imports, you have to store .pyc data in there yourself. > > zipimport is mostly meant as a repackaging tool, and typical zip files > > only contain .pyc files. > > They aren't created even outside of the zip archive, this is what I > meant ;-) But since .pyc's are always generated in the same directory as the .py files, where else would you expect them to be generated? Just From skip at pobox.com Wed Aug 4 18:22:48 2004 From: skip at pobox.com (Skip Montanaro) Date: Wed, 4 Aug 2004 17:22:48 -0500 Subject: Confused about pep 318 In-Reply-To: <10h2ihgb8c6fi97@corp.supernews.com> References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: <16657.25016.75424.143284@montanaro.dyndns.org> Edward> But I have no idea what the proposed syntax is(!!) In Edward> particular, there is no mention of '@' directly on the page Edward> http://www.python.org/peps/pep-0318.html Anthony Baxter said yesterday on python-dev he was going to attend to that shortly. As in many other software efforts, the code has moved along a bit faster than the documentation (after all, what's more fun to do?). I believe the only significant differences from a pure functional documentation standpoint to apply to the PEP are the syntax and the issue of decorated classes (I don't think support for decorated classes will make it). By way of parallel examples here's how the new syntax corresponds to the syntax I used in the last revision of the PEP: #1 from the PEP: Given this function: def onexit(f): import atexit atexit.register(f) return f the new syntax will be: @onexit def func(): ... #4 from the PEP: Given these functions: def accepts(*types): def check_accepts(f): assert len(types) == f.func_code.co_argcount def new_f(*args, **kwds): for (a, t) in zip(args, types): assert isinstance(a, t), \ "arg %r does not match %s" % (a,t) return f(*args, **kwds) return new_f return check_accepts def returns(rtype): def check_returns(f): def new_f(*args, **kwds): result = f(*args, **kwds) assert isinstance(result, rtype), \ "return value %r does not match %s" % (result,rtype) return result return new_f return check_returns the new syntax will be: @accepts(int, (int,float)) @returns((int,float)) def func(arg1, arg2): return arg1 * arg2 I believe the order of application of the above decorators would be like so: func = accepts(int, (int, float))(returns((int, float))(func) Edward> I confess that I don't understand this remark at all. How has Edward> it happened that so many people are confused about this Edward> proposal? And if everything is so clear, why isn't the clarity Edward> reflected in pep 318 itself? There was a lot of discussion on python-dev, but none very recently (last month or so). Guido indicated there that he brought up the topic at EuroPython in his keynote talk and entertained discussion from the floor. Based upon that discussion he decided to go with the @-decorator syntax. Since EuroPython most/all the discussion went on in private email or on irc. I think it would be nice if this conversation was summarized in the PEP, but that will have to come from one of the participants. Skip From pm_mon at yahoo.com Sat Aug 21 17:29:04 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sat, 21 Aug 2004 17:29:04 -0400 Subject: __metaclass__ and __author__ are already decorators In-Reply-To: <41279C2A.9060906@yahoo.it> References: <4127813F.9020707@yahoo.it> <41279C2A.9060906@yahoo.it> Message-ID: Paolo Veronelli wrote: > > > Paul Morrow wrote: > >> Paolo Veronelli wrote: >> >>> >>> >>> Paul Morrow wrote: >>> >>>> Thinking about decorators, and looking at what we are already doing >>>> in our Python code, it seems that __metaclass__, __author__, >>>> __version__, etc. are all examples of decorators. So we already >>>> have a decorator syntax. What is the compelling reason to invent a >>>> new one? And if we do, what's to become of the old one? > > >>> >>> Thanks for pointing out another unpythonicity. Paolino >>> >> >> Is that what I did? Isn't assigning values to __xxx__ attributes >> pythonic? > > > Really but instructing the interpreter with assigning to special > attributes is not a well classified operation: > > __author__ & company are just settable/gettable (the don't instruct the > interpreter) this is surface level. > > __getitem__ (in ex) instruct the intepreter on how to parse [] sintax > (am I wrong?).So __lt__ and the alike :that's what I call a syntactic > level.This is more or less well defined (and so pythonic):operators can > be defined like this. > > __metaclass__ doesn't seem to be placed in the first two categories.It > instruct the interpreter on a deeper level (in my vision),an actual > level which I think is well related with decorator level.If I am > right,this speciality of an only attribute makes it unpythonic.It has to > be part of a class > of attributes ,which would be nice to be populated just (at least) to > make its instructing position clearer. And this would give us more attributes in that (__metaclass__) category. But there mere existence of one such attribute makes similar things pythonic, I believe. __author__, __getitem__, and __metaclass__ may be at different 'levels' as you put it, but they are all in the same specification 'dimension' --- the meta information dimension. And this is the same dimension that decorators exist in. From apardon at forel.vub.ac.be Tue Aug 31 03:46:45 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 31 Aug 2004 07:46:45 GMT Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> <1gj4fb5.607xsc51izh8N%aleaxit@yahoo.com> <7xllg25lkt.fsf@ruckus.brouhaha.com> <1gj4u3a.12ttba9fynd6uN%aleaxit@yahoo.com> <1gj5bp4.qhup8tldmvebN%aleaxit@yahoo.com> <1gj6cfv.nv3fziwoc81nN%aleaxit@yahoo.com> <1gj6pih.6lolffzvm5ucN%aleaxit@yahoo.com> Message-ID: Op 2004-08-27, Alex Martelli schreef : > Antoon Pardon wrote: > ... >> > It should be pretty obvious, I think. So, if you want to >> > get an AttributeError exception when 'a' is a tuple or str, a.extend(b) >> > is clearly the way to go -- if you want para-polymorphic behavior in >> > those cases, a+=b. Isn't it obvious, too? >> >> No it isn't obvious. No design is so stupid that you can't find >> an example for it's use. That you have found a specific use >> here doesn't say anything. > > I can silently suffer MOST spelling mistakes, but please, PLEASE do not > write "it's" where you mean "its", or viceversa: it's the most horrible > thing you can do to the poor, old, long-suffering English language, and > it makes me physically ill. Particularly in a paragraph as content-free > as this one of yours that I've just quoted, where you're really saying > nothing at all, you could AT LEAST make an attempt to respect the rules > of English, if not of logic and common sense. > > On to the substance: your assertion is absurd. You say it isn't obvious > that a.extend(b) will raise an exception if a is bound to a str or > tuple, yet it patently IS obvious, given that str and tuple do not have > a method named 'extend'. That is a non sequitur, the fact that something is a given, doesn't make that something obvious. I dare say that if you have two parts of equal code, one that uses += and the other that uses extend, it will not be obvious to the reader that you want to first code to work only with lists and the other with strings and tupples too. He can probably figure it out but IMO it is not the most clear way to make that disticntion. > Whether that's stupid or clever is a > completely different issue, and one which doesn't make your "No it isn't > obvious" assertion any closer to sanity one way or another. IMO, obvious means, that it is the first thing that comes to mind when someone reads the code. IMO it is not obvious in that sense. -- Antoon Pardon From beliavsky at 127.0.0.1 Mon Aug 23 13:39:26 2004 From: beliavsky at 127.0.0.1 (beliavsky@aol.com) Date: 23 Aug 2004 12:39:26 -0500 Subject: function taking scalar or list argument Message-ID: <412a2bce$1_1@127.0.0.1> I can define a function that transforms either a scalar or each element in a list as follows: def twice(x): try: return map(twice,x) except: return 2*x print twice(3) # 6 print twice([1,4,9]) # [2,8,18] Is this good style? I intend to define many functions like this and want to use the right method. Thanks. ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--- From knowlj at hotmail.com Tue Aug 10 11:41:34 2004 From: knowlj at hotmail.com (Jared) Date: 10 Aug 2004 08:41:34 -0700 Subject: Mechwarrior Python Game References: Message-ID: Thanks for your help Pete and Reid. I'll let you know what I come up with. From fumanchu at amor.org Wed Aug 25 10:14:51 2004 From: fumanchu at amor.org (Robert Brewer) Date: Wed, 25 Aug 2004 07:14:51 -0700 Subject: Python future performance and speed Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E69@exchange.hqamor.amorhq.net> Jacek Generowicz wrote: > Peter Hansen writes: > > > The last time I checked, Java and C++ (even C) were widely > > considered to be high level languages. > > The fact many people hold an erroneous belief, does not make said > belief any less erroneous. > > > Has someone been raising the bar while I wasn't looking? > > The developers of all the truly high-level languages ? > > There was a time when assembler was high-level. Someday, even Python will be a low-level language. ;) Robert Brewer MIS Amor Ministries fumanchu at amor.org From asif at go-away-spammer.com Wed Aug 25 12:45:24 2004 From: asif at go-away-spammer.com (Player) Date: Wed, 25 Aug 2004 17:45:24 +0100 Subject: Begginers questions on different distributions of py References: <412cafd6$1@nntp0.pdx.net> Message-ID: Firstly, it was my fist time using sourceforge, and I did what any beginner would do, I dl the fist or rather top most entry in the list of available packages for win32 build 202, doing so while thinking that the msot current version was goign to be the one at top most position. As it so happens, that was wrong, and I can now see clearly that there are 3 entries for builds of win32 relating to python builds 2.2, 2.3, and 2.4; that wasn't clear when I first visited the dl page. I happen to think they make a rather simple process, an over complicated matter at sourceforge; which is down to their page not being very beginner friendly. Any-ways enough of that, I did manage to get what I wanted after viewing the page again -after reading your curt & rude reply-. and as a result I owe you thanks for pointing out my error. TY However... Homework? Like I didn't already have a good look through some webpages via a google search. Repeating of my question? Hardly, I simply added it into another post I happened to send out on another matter, it seemed wise to add it to that post also. Posts in news groups get lost FAST! in the multitude of posts coming after themselves. I have found that it is wise to renew questions/posts on a regular basis. As to the flavour of your reply,,,well all I am going to say to that is... I am sooo not going to rise to the bait. M.B From pm_mon at yahoo.com Tue Aug 31 08:47:38 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Tue, 31 Aug 2004 08:47:38 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: <20040830024246.GA2159@unpythonic.net> References: <20040830024246.GA2159@unpythonic.net> Message-ID: The big impact of this proposal is that __xxx__ variables defined immediately following the docstring (if present) would cease to become local variables. This of course has the possiblity of breaking existing code. But I don't believe that developers routinely use such names for local variables, so I don't believe that there will actually be much broken code should this change be implemented. Jeff Epler wrote: > In your proposed model, what does the following code do? > def f(): > __var__ = 3 > return __var__ > f.__var__ += 1 > print f() > Only assignments to __xxx__ variables at the very start of a function def would have this special semantics. So your return statement would be referencing a name (__var__) that doesn't exist in the function's local variable namespace. Easier to accept if we use a more likely variable name for the magic variable. def f(): __version__ = 3 return __version__ f.__version__ += 1 print f() > What about any of the following: > def g(): > if True: > __var__ = 4 > print g.__var__ > __var__ = 4 # creates a local variable because # the assignment isn't at top # of function def. But probably # should generate a warning for # giving a magic name to a local # variable. > x = 3 > def h(x): > __var__ = x*x > return x*x > print h(2), h.__var__ > In __var__ = x*x, x is not in the function's namespace (it's a local variable), so x is undefined. Easier to visualize if we make it __version__ = x*x Same basic idea for your other examples. > > def p(): > import os as __os__ > __os__ would be a local variable (since this is not a simple assignment, i.e. using an equal sign). __os__ is not a good name for a local variable, so interpretor should probably generate a warning. > def q(): # BUG x doesn't get the proper metaclass in 2.3! > class __metaclass__(type): pass > class x: pass > # assert x's metaclass is __metaclass__ > This would do whatever it does now. Paul From fumanchu at amor.org Mon Aug 23 10:44:46 2004 From: fumanchu at amor.org (Robert Brewer) Date: Mon, 23 Aug 2004 07:44:46 -0700 Subject: J2 paper 0.2.1 Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E3B@exchange.hqamor.amorhq.net> How the @#$%^& did your name get in the "From" header on _my_ email, Paul? You've got your chocolate in my peanut butter. Funky. Robert Brewer MIS Amor Ministries fumanchu at amor.org > -----Original Message----- > From: python-list-bounces+fumanchu=amor.org at python.org > [mailto:python-list-bounces+fumanchu=amor.org at python.org] On > Behalf Of Paul McGuire > Sent: Monday, August 23, 2004 7:40 AM > To: python-list at python.org > Subject: Re: J2 paper 0.2.1 > > > "Robert Brewer" wrote in message > news:mailman.2201.1093271860.5135.python-list at python.org... > Colin J. Williams wrote: > > One nit picking comment on Robert Brewer's document: An > > annotation is a > > transformation of a function, as a change to the flow of control is. > > I'd like someone to analyze that further. "Transform", like the word > "change", can mean almost anything in English. However, I find the use > of the term in programs to generally mean either coerce/convert/cast > between types, or some other mechanism whereby one object is supplied, > and another object returned. That is, "transform" affects > Being/"is" as > opposed to Attribute/"has". > > However, neither your "gut feeling" nor mine about the issue is > enough--we need a more rigorous heuristic to decide. Finding precedent > would be a good start, if anyone wants to try. > > > Robert Brewer > MIS > Amor Ministries > fumanchu at amor.org > > > -- > http://mail.python.org/mailman/listinfo/python-list > From stephen.thorne at gmail.com Sun Aug 29 18:59:17 2004 From: stephen.thorne at gmail.com (Stephen Thorne) Date: 29 Aug 2004 15:59:17 -0700 Subject: Implementations of Multi-Methods and Tail Call Elimination (Or how I stopped worrying and learned to love decorators) Message-ID: <3e8ca5c8.0408291459.6570c936@posting.google.com> Decorators have been getting lots of air-time at the moment, but only really the syntax. After a short discussion on irc the other night I decided to download python2.4 from experimental and write out some truely worthy decorator hacks. I implemented multimethods as a warm-up, and then implemented tail call elimination. Presented here is a brief synopsis of both, and then the implementations. http://thorne.id.au/users/stephen/scripts/multimethods.py http://thorne.id.au/users/stephen/scripts/tailcall.py Multimethods come first, because I wrote them first. I don't really like the implemetation - I'm sure it can be improved. I especially dislike having to use the @staticmethod decorator, and having to have the functions in alphabetical order. class fact(MultiMethod): @when(lambda x:x==0) @takes(int) @staticmethod def a(x): return 1 @when(lambda x:x>0) @takes(int) @staticmethod def b(x): return x * fact(x-1) @staticmethod def c(x): raise ValueError("Invalid argument to fact()") fact = fact() Okay. Lots of sugar required to do it, but look! its a multimethod! fact(10.1) raises an error, fact(0) == 1 and fact(5) == 120. The implementation looks like this: def takes(*arg, **kwargs): def _(f): def check(*x, **xs): def test(a,b): return b is None or isinstance(a,b) if len([True for (a,b) in zip(x, arg) if not test(a,b)]): raise NextMethodException() if len([True for (a,b) in kwargs.keys() if not test(xs.get(b,None),lb)]): raise NextMethodException() return f(*x, **xs) return check return _ def when(f): def _(d): def check(x): if not f(x): raise NextMethodException() return d(x) return check return _ class NextMethodException(Exception): pass class MultiMethod: def __call__(self, *arg, **kwargs): for i in dir(self): if i[0] == '_': continue try: return getattr(self, i)(*arg, **kwargs) except NextMethodException: pass Okay, thats multimethods. I really don't like the implementation all that much, I'm sure there's a better way to do it than using exceptions like that. Suggestions? Next is tail call elimination. This is an example usage: from tailcall import tail, call, eliminate import operator @eliminate def fact(n): if n == 0: return 1 return tail(operator.mul, n, call(n-1)) fact(10000) is a really larger number by the way. Now the implementation: class call(object): def __init__(self, *x): self.x = x class tail(object): def __init__(self, op, args=[]): self.op = op self.x = list(args) self.value = None self.parent = None def evaluate(self): top = current = self while not current is None: if len([True for elem in current.x if type(elem) in (call, tail)]): for n,elem in enumerate(current.x): if type(elem) is tail and elem.value: elem = current.x[n] = elem.value elif type(elem) == call: elem = current.x[n] = self.op(*elem.x) elif type(elem) == tail: elem.parent = current current = elem else: result = current.op(*current.x) if type(result) in (tail,call): result.parent = current current = result else: current.value = result current = current.parent if current is top: return result Big ugly loop. Before you try, it doesn't work on ackerman's. Patches accepted. Comments? Improvements? Suggestions? Flames? Regards, Stephen Thorne. From squirrel at WPI.EDU Thu Aug 5 15:42:41 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 5 Aug 2004 15:42:41 -0400 Subject: Confused about pep 318 In-Reply-To: References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: On Thu, 5 Aug 2004, Terry Reedy wrote: > "Christopher T King" wrote in message > news:Pine.LNX.4.44.0408051249050.10473-100000 at ccc6.wpi.edu... > > That thread reaches no consensus, > > To me this is evasion. Well, it is. > >That's because it was. ... > >There had previously been no public discussions about it. > > You (agreeing with Steven) made a false accusation of something like > dastardliness. Just admit your mistake and move on. (More evasion:) +10 points for using the word "dastardliness" in a sentence. +10 more for using it legitimately in a post on a computer language mailing list. > >other than, in his sole post in the thread, Guido stating > >"I would love to see an implementation of this idea." > > Hence, I was not surprised to see it in an alpha as an experimental feature > which might or might not stay. Indeed, I was comforted by a recent post of Guido's in python-dev: When I let Anthony check it in for 2.4a2, the plan was to see how it fares in a2 and a3, and possibly take it out in 2.4b1. I was afraid that going in so close to 2.4b1, @ was in for good, but knowing they may yet come out is good. From martindemello at yahoo.com Tue Aug 24 02:45:16 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Tue, 24 Aug 2004 06:45:16 GMT Subject: functional library Message-ID: <0uBWc.191260$M95.165005@pd7tw1no> Is there any 'standard' library of functional extensions to python? Basically stuff beyond the built in filter, map and reduce - e.g. find, partition, any, all, etc. martin From yong at net.tamu.edu Wed Aug 4 15:30:01 2004 From: yong at net.tamu.edu (Yong Wang) Date: Wed, 4 Aug 2004 14:30:01 -0500 (CDT) Subject: Compiled C++ and Mysql codes run in python cgi script Message-ID: <20040804193001.F39F31589B@net.tamu.edu> Hi, All: We have a network management system written in C++, MysQL, and Hp SNMP. It works in Solaris command line. When I wrote a similar python codes which call compiled C++ and mysql codes in solaris command line, the comipled codes work fine in wraped python file. When I change the python codes to web interface in python CGI script, I got message that "Can't connect to local MySQL server through socket '/tmp/mysql.sock'" How can I fix this problem because we want to migrate solaris command line system to web access system ? The easiest way for me is directly to call compiled C++ and mysql codes (excutable) in python CGI scripts, then post the run results in website. Thank you very much in advance and I am looking forward to your reply. Yong From anthonybaxter at gmail.com Fri Aug 6 12:23:55 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 7 Aug 2004 02:23:55 +1000 Subject: RELEASED Python 2.4, alpha 2 In-Reply-To: <8umdnWXWJtRm7o7cRVn-uw@powergate.ca> References: <411231C8.3020308@interlink.com.au> <2-SdnZCwNs1SwI_cRVn-uQ@powergate.ca> <8umdnWXWJtRm7o7cRVn-uw@powergate.ca> Message-ID: On Fri, 06 Aug 2004 08:05:15 -0400, Peter Hansen wrote: > I don't think the decorator names are ever keywords. They are > just arbitrary names bound to stuff... I suspect you would find > people writing code like this instead: > > sync = synchronized > cm = classmethod > > def @sync @cm x(self): > pass > > (I'm not saying whether that's a good thing, just pointing it out.) I'm happy to say that I think this looks horrible ;) From Mr.KK at gmx.de Fri Aug 20 08:36:01 2004 From: Mr.KK at gmx.de (Kolja Kube) Date: Fri, 20 Aug 2004 14:36:01 +0200 Subject: My only complaint about Python Message-ID: <4125F031.3050508@gmx.de> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 |> >> with the free Visual C++ Toolkit. Instructions are here: |> all humbug. Visual C++ is nowhere near free, it's all proprietary. |> |> Klaus Schilling It is free, but only free as in "free beer". Kolja Kube -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFBJfAxXzCVA/eyqwkRAoXcAJ9Oq/x7dboPWgo+4FRzMe9h9AxLTgCfW29M gEhbS/tnsEgcJ2JPo1HHdUo= =nt+U -----END PGP SIGNATURE----- From jerf at jerf.org Mon Aug 30 00:49:40 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Mon, 30 Aug 2004 04:49:40 GMT Subject: regex into str References: Message-ID: On Sun, 29 Aug 2004 12:58:57 +0200, Peter Kleiweg wrote: > That is not relevant. What matters is that a += 'b' does what it > is supposed to do. If you want to be that way, then fine. No, it doesn't do what it is "supposed" to do, in the context you are discussing. It does not add a "b" to the original string, it creates a new string containing the original contents plus the new contents. Let me refresh your memory: You are arguing that you should be able to apply a division operator to a string to apply a regex to it. When people told you it was impossible, because strings were immutable, you said that a += "b" did what you wanted. In context, this was clearly a claim that strings are mutable, although that is a translation of your claim from what you said here: This works: a += 'x' So this should too: a /= 'x' which was in reply to > Even if you could assign to str.__div__ (and this is very deliberately and > specifically disallowed) you would end up disappointed, because strings > are immutable. That means there's nowhere to store "the last match", > no way to mutate the string with the "/=" operator, and also that the > interpreter is free to use the same storage for two equal strings. Therefore, I say again: Your example does not do what you are implicitly claiming it does. Therefore it is not a counter example to Jeff Epler's (correct) claim. So when you say above "This works:", I'm saying, no, it doesn't, not in the sense you were replying to Jeff. It is not mutating the string originally referenced by a, you still can't do that, and your attempted counterpoint has no force, no meaning. (Any other putative meaning you would claim it had after the fact would simply be a non-sequitor, in context.) Any successful attempt to mutate a string (in pure Python) would constitute a serious bug in Python. (Any successful mutation by a C extension would constitute a major, Python-breaking bug in that extension.) From anthonybaxter at gmail.com Tue Aug 24 11:26:30 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Wed, 25 Aug 2004 01:26:30 +1000 Subject: __name__ becoming read-write? In-Reply-To: <7rhmi0d7cdg9r6ljvilgkep30tckl24nai@4ax.com> References: <3b8ki0tlphodtt8ge8an274qp78ihp1i3n@4ax.com> <8cdmi0dipgk5192li1p8mm2n1hls2hs7rl@4ax.com> <7rhmi0d7cdg9r6ljvilgkep30tckl24nai@4ax.com> Message-ID: On Tue, 24 Aug 2004 14:00:35 GMT, Arthur wrote: > But all at a cost. I would be comforted to hear you say something > about the costs you perceive. If you present it is all just a win, > it becomes too easy to challenge your assessment. So easy, that even > someone like myself can pull it off, at least to an extent - and at > least in my own judgement. _Any_ new feature has a cost - whether it is in the additional training needed, the potential for truly horrendous hacks, the backwards-incompatibility, or whatever else. The additional training issue: One of my internal measures for evaluating new decorator syntax options is that it be *obvious* that "this is something new". The various ideas of "doing something wacky with a list" or "a magic 'decorate()' function" fail this test, for me. They're not obviously doing something new. Following on from that, the new feature should be explainable in the context of existing knowledge. The before-def decorator syntax is easily explainable in this context. It might be that new python programmers might not realise that a function or a method is just an object, like any other, and can be treated just like any other object - passed as an argument to a function, or whatever. If they've come from a particularly limited language before Python, there might be a bit of mental dissonance before they realise this, but they will realise it eventually. And this is a good thing to realise - once you "get" that everything's an object, you're on the path to understanding Python well (I'd add as a footnote the understanding of what a "variable name" actually means usually follows soon after this). The potential for truly horrendous hacks: This is a given, and is the case for any new feature, particularly one like decorators (or metaclasses, or descriptors, or ...). The potential for nasty and clever hacks isn't a new thing - take, for instance the "Don Beaudry hook" introduced for metaclasses way back in Python 1.5. Jim Fulton took this small hole and drove a large truck called ExtensionClass through it, leading to the brain-warping of Acquisition. Or the current Zope3 Interfaces package, which uses a truly nasty sys._getframe() hack. But in both those cases, end users of the features don't have to care about the underlying nastiness, they can just use the new features. Will people write unpleasant decorator functions? Sure. But the same people probably write hideously complex __del__ methods on every object, and don't understand why cyclic GC then doesn't work for them, or why their destructors aren't being called reliably. Hell, look at the recent: class Argh(random.choice(dict,list)): .... thing posted by someone (mwh? I forget) The backward incompatibility: I regard this as a non-issue. For starters, pretty much *every* major release of Python has had some new feature that wasn't backwards compatible. For example, generator expressions were also added to 2.4. They will cause a SyntaxError in Python 2.3 and earlier. And I would guess that genexprs will be used far far more often than decorators in most codebases. If backwards compatibility *is* an issue, note that there's a couple of solutions here. For starters, there's the maintenance releases of the previous release. I'm being a complete pain-in-the-arse with stopping any new features creeping into those releases, for *damn* good reason. I'm trying to make sure that people can get the benefits of bug fixes, without having their entire codebase break. And once 2.4 final ships, I'll be cutting what I plan to be the last of the 2.3 series, and moving on to 2.4.1. If you really, really want to keep using 2.3, and this is a problem for you (because you want the continuing stream of bugfixes), I'm happy to help bring someone up to speed so that they can take on 2.3.6 and onwards. (As should be obvious, I'm using "you" in the general sense here). From peter at engcorp.com Fri Aug 6 12:53:14 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 06 Aug 2004 12:53:14 -0400 Subject: Finding a function name In-Reply-To: References: <788E231C269961418F38D3E360D1652526CA1E@tndefr-ws00021.tenovis.corp.lan> Message-ID: Tim Williams wrote: > [ 1 step up from Newbie ] > > How can I find a function's name from within the function? Did you try Google yet? http://groups.google.com/groups?q=group%3Acomp.lang.python+find+function+name -Peter From nid_oizo at yahoo.com_removethe_ Sat Aug 21 10:34:13 2004 From: nid_oizo at yahoo.com_removethe_ (Nicolas Fleury) Date: Sat, 21 Aug 2004 10:34:13 -0400 Subject: decorator J4 - any objections? In-Reply-To: References: <10id2djglri8o15@corp.supernews.com> Message-ID: Martin DeMello wrote: > Perhaps J2 but with proposal L to call the decorator declaration > something other than "decorate" - 'using' is the best I've seen so far, > though it's still not perfect. Or another idea - how about inverting the > meaning of 'as', and changing the form of the decorator declarations > slightly? > > as: > classmethod > memoised > accepting (int, int) > returning (float) > def foo(bar, baz): But Guido already said he wanted to keep as for other meanings. Regards, Nicolas From ptmcg at austin.rr._bogus_.com Thu Aug 26 05:39:30 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Thu, 26 Aug 2004 09:39:30 GMT Subject: Call for signatories for J2 References: Message-ID: > (Interestingly, @ and 'per' are similar in that "12 @ $ > > ahem! "12 @ $1.50" is shorthand for "12 at $1.50 per item" was what I meant to say before I was interrupted! "per" as a Latin word would help its adoption beyond English-speaking regions. It's meaning as "by" is consistent with the decorator notion that foo() is modified _by_ the decorator methods before it is fully defined. And Alex cites "per"s three-letter-ness, as a nice parallel to the corresponding "def". -- Paul (now I'm really through) From yong at net.tamu.edu Thu Aug 5 11:54:47 2004 From: yong at net.tamu.edu (Yong Wang) Date: Thu, 5 Aug 2004 10:54:47 -0500 (CDT) Subject: Python cgi script Message-ID: <20040805155448.408C6158CC@net.tamu.edu> Hi, All: I try to write a CGI script to post network traffic routing info in the web page. I have successfully obtained traffic info from wraped python with C++ and MYSQL and SNMP code and output to a file. I need read a file which contain traffic info and post to web. In CGI script, I use: file=open('/apps/www/htdocs/internal/nd/output1', 'r') flag=0 while not flag aLine = file.readline() if aLine != "": print aLine print '\n' else: flag = 1 file.close() print "" print "" The output from print statement above in web can display, but no line separation between different lines. How can I preserve the orginal line format of the input file (space within a line and space between lines)? Thank you very much for your help in advance. I am looking forward to receiving your reply. Yong From anthonybaxter at gmail.com Thu Aug 5 13:30:52 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 03:30:52 +1000 Subject: bdist_rpm problems, and my work around. In-Reply-To: References: Message-ID: On 05 Aug 2004 10:22:43 -0700, zirpu xunre pelxu wrote: > > python setup.py bdist_rpm > > [...] > > # eventually complains about the extra -debuginfo package. This is fixed in 2.4alpha, and the fix will also be in 2.3.5. Anthony From peter at engcorp.com Mon Aug 16 18:06:33 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 18:06:33 -0400 Subject: Python indentation deters newbies? In-Reply-To: <3064b51d.0408161354.618056ef@posting.google.com> References: <3064b51d.0408130615.3fc4a760@posting.google.com> <3064b51d.0408161354.618056ef@posting.google.com> Message-ID: <59Odna2DCNZ2srzcRVn-hQ@powergate.ca> beliavsky at aol.com wrote: > Peter Hansen wrote in message news:... >>So did you indent your code such that consecutive lines were >>not indented to the same identation level even when they were >>conceptually, logically, *algorithmically* part of the same >>block? > > I think you are getting a little religious about indentation. You bet I am. :-) Always have been... > I mostly indent Python the way I'd indent Fortran, but there are some > inflexibilities in Python: > > (1) I use a blank line to separate functions. I don't like being > forced to indent every line within the body of a function. Hmm... without an example, I'm not sure what you suggest. On the face of it, not having every line indented would strike me immediately as a serious formatting error that is highly likely to affect the readability of the code. > (2) Nested loops can *sometimes* be thought of as a single loop and > indented that way. I don't think the indentation > > do i=1,n > do j=1,n > do k=1,n > x(i,j,k) = some_func(i,j,k) > end do > end do > end do > > is necessarily bad. I do! It doesn't show the structure of the code clearly enough. If there are three loops, there should be three levels of nesting so that the eye is immediately drawn to it and the mind can say "aha... possible area for code improvement, look more closely". Without the indentation, the eye will skip right over that when scanning lots of text. Probably other reasons too, but suffice to say that I'd immediately reformat that in any code someone in my group wrote. > (3) Having a labelled end-of-loop statement lets you exit the desired > number of nested loops in a clean way. In the following Fortran code > you can exit any of the nested loops. How would you simulate this > control flow in Python? > > ido: do i=1,n > ! some code > if (foo) exit ido ! exit outer loop > jdo: do j=1,n > ! some code > if (boo) exit jdo ! exit middle loop > do k=1,n > ! some code > if (goo) exit ! exit inner loop > end do > end do jdo > end do ido Why with a custom exception, obviously. But what does that have to do with indentation? -Peter From walter at livinglogic.de Thu Aug 26 07:15:29 2004 From: walter at livinglogic.de (=?ISO-8859-1?Q?Walter_D=F6rwald?=) Date: Thu, 26 Aug 2004 13:15:29 +0200 Subject: Call for signatories for J2 In-Reply-To: <3b2846c4.0408260237.182e749d@posting.google.com> References: <3b2846c4.0408260237.182e749d@posting.google.com> Message-ID: <412DC651.6030102@livinglogic.de> Using decorators for docstrings would look much better with the J2 proposal: using: """ ... """ def foo(bar): ... instead of @doc(""" ... """) def foo(bar): ... (Of course this requires special support for a bare string inside the using suite) And folding would really be helpful with long docstrings. Consider this a vote for the J2 proposal. Bye, Walter D?rwald From parano at gmail.com Thu Aug 26 12:04:07 2004 From: parano at gmail.com (Parano) Date: 26 Aug 2004 09:04:07 -0700 Subject: Boa Constructor error Message-ID: <4712d252.0408260804.c69cfee@posting.google.com> Hi I have a recurrent error in Boa Constructor, especially when I try to activate code completion: a message box reads "UnicodeDecodeError: 'ascii' codec can't decode byte 0xaa in position 52: ordinal not in range(128)" I couldn't find any google resource on that error. I have Python 2.3.3 with Boa Construtor 0.3.1 on Mandrake Linux 10. wxPython is from wxPythonGTK-py2.3-2.5.2.7-RH9.i386.rpm I also tried wxPythonGTK2-py2.3-2.5.2.7-RH9.i386.rpm but had the same error. Those RPMs are from www.wxpython.org where it says that "install and use on my Mandrake 9.2 system without any troubles." Any tip on this? Thanks in advance From __peter__ at web.de Sun Aug 22 12:00:54 2004 From: __peter__ at web.de (Peter Otten) Date: Sun, 22 Aug 2004 18:00:54 +0200 Subject: unicodedata name for \u000a References: <412869bf$0$24814$9b622d9e@news.freenet.de> Message-ID: Tor Iver Wilhelmsen wrote: > "Martin v. L?wis" writes: > >> No. is not a character name. The unicodedata.name function >> returns the official character name, so it MUST NOT return an alias >> (which rules out your second alternative). > > Then why not return None or the empty string instead of raising an > exception? What's wrong with >>> import unicodedata >>> unicodedata.name(u"\u000a", "my default value") 'my default value' Peter From cmkleffner at gmx.de Wed Aug 18 03:36:53 2004 From: cmkleffner at gmx.de (cmkl) Date: 18 Aug 2004 00:36:53 -0700 Subject: drop into the interpreter References: Message-ID: <3b091a1c.0408172336.2883bc91@posting.google.com> "Hoang Do" wrote in message news:... > is there a facility to inspect the run-time of a python script? > Essentially, it would execute a script to a set specific point and then drop > into the interpreter. Something like a "Stop" or "Break"? > > Hoang Do > hoang at jotsite.com You can use my recipe from the Python Cookbook: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/285214 import the code object called prompt: from prompt import prompt and 'break' your code at any location with: exec prompt The control flow of your program breaks at this location and pops up a interpreter which is operating the current scope of your program. With CTRL-D you can continue with your program. example: (prompttest.py) ======================== if __name__=='__main__': from prompt import prompt def my_func(): exec prompt # exec prompt inside a function class prompt_test: def test_method(self): self.dummy = 'dummy' exec prompt # exec prompt inside a method # 1: exec prompt inside a method prompt_test().test_method() # 2: exec prompt inside a function my_func() # 3: exec prompt inside the modules global scope exec prompt example session: ================ python prompttest.py prompt in test_method() at prompttest.py:10 - continue with CTRL-D >>> dir() # we are in a methods scope ['_prompt', 'self'] >>> print self # and the instance is ... <__main__.prompt_test instance at 0x008DFEB8> >>> self.black = 'adder' # add an attribute to the instance >>> self.__class__.adder = 'black' # add an attribute to the class >>> dir(self) ['__doc__', '__module__', 'adder', 'black', 'dummy', 'test_method'] >>> for i in (1,2): # test a multiline command ... print i ... 1 2 >>> dir() # btw: the '_prompt' object will be deleted later on ['_prompt', 'i', 'self'] >>> ^D --- continue ---- prompt in my_func() at prompttest.py:5 - continue with CTRL-D >>> dir() # nothing interesting in this fuctions scope ['_prompt'] >>> globals().keys() # a little bit more in globals() ['prompt', '__builtins__', '__file__', 'prompt_test', 'my_func', '__name__', '__doc__'] >>> monty = 'python' # this would vanish at the end of the function >>> ^D --- continue ---- prompt in __main__ at prompttest.py:19 - continue with CTRL-D >>> dir() # no python anymore - or was it monty? ['__builtins__', '__doc__', '__file__', '__name__', '_prompt', 'my_func', 'prompt', 'prompt_test'] >>> dir(prompt_test) # our adder attribute is still there ['__doc__', '__module__', 'adder', 'test_method'] >>> print prompt_test().adder # and adder is still black ... black >>> ^D --- continue ---- From rogerb at rogerbinns.com Tue Aug 31 03:03:32 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Tue, 31 Aug 2004 00:03:32 -0700 Subject: xmlrpclib References: <413409c3$0$22823$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <2hkd02-v7v.ln1@home.rogerbinns.com> Graeme Matthew wrote: > Just wanted to know if anyone knows if xmlrpclib is scalable i.e can > handle many / asynchronous calls. You should specify what goal it is you are trying to achieve. For example it isn't clear if you are talking about the server end or the client end. Additionally you haven't said how far apart the client and server are. (Same machine? Same LAN? Same continent?) xmlrpc is not asynchronous. It is a request/response model. Each request gets exactly one response. There is no method for sending data outside of that. For example the server end can't send random event messages without the client end polling for them. And what do you mean by handle? Is that a speed question, a reliability question, a size of data structures question? Lastly the current Python xmlrpc implementation, both client and server end makes one network connection per request/response pair and then closes it. Roger From pm_mon at yahoo.com Fri Aug 20 22:22:42 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Fri, 20 Aug 2004 22:22:42 -0400 Subject: decorator J4 - any objections? In-Reply-To: <7xacwpb5wq.fsf@ruckus.brouhaha.com> References: <7xacwpb5wq.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Jeffrey Froman writes: > >>> def func(arg1, arg2) >>> @version("Added in 2.4") >>> @returns(None) >>> as: >>> """Docstring could be here, or in decorator part above""" >>> # body goes here >> >>I like this better than the current proposal because it reads from top to >>bottom, and flows like a typical conditional. >> >>Before function writing the decorators whereas like reads this. > > > J4 is my favorite of the enumerated proposals I remember, so I'll > "vote" for it, but I still think something better should be possible. It seems to me that we've had decorators all along (if we expand the definition a little), for example __metaclass__ sure looks like a class decorator. So how about... def func(arg1, arg2): """Docstring goes here, as normal.""" __version__ = 'Added in 2.4' __returns__ = None # function body goes here def returns(func, *args): """Docstring for 'returns' decorator.""" __decorator__ = True # body of decorator goes here From noone at here.com Mon Aug 16 09:43:36 2004 From: noone at here.com (M. Clift) Date: Mon, 16 Aug 2004 14:43:36 +0100 Subject: random / lists References: Message-ID: Hi Wes, Thankyou. I'll now go away and experiment with how to use it as I've just started with python, but I should be able to learn a lot with this. It would seem to be exactly what I was after. : ) Malcolm From indigo at bitglue.com Tue Aug 24 18:53:35 2004 From: indigo at bitglue.com (Phil Frost) Date: Tue, 24 Aug 2004 18:53:35 -0400 Subject: string concatenation optimizations [from python-dev Summary] In-Reply-To: <412AC928.7000603@ocf.berkeley.edu> References: <412AC928.7000603@ocf.berkeley.edu> Message-ID: <20040824225335.GA6118@unununium.org> Has adding a stringish object that supports efficient slicing, concatenation, and mutation been considered? The C++ STL rope comes to mind. Essentially what I have in mind is a type that's a list of byte arrays. The value is defined as the concatenation of these arrays. This would allow efficient implementations of things such as s[31:35] = 'replacing a small substring with a larger one' I think a reasonable implementation could be done using existing python types, and if it's useful, an opmitized C implementation could be done. This sort of thing is already on my stack of things to find on google, write, or get someone else to write, just need the time. So what do you think? Useful idea? Does this already exist? On Mon, Aug 23, 2004 at 09:50:48PM -0700, Brett Cannon wrote: > python-dev Summary for 2004-08-01 through 2004-08-15 > > [snip] > > ------------------------------------------------------------------------------------- > Changing the Big-O complexity for something in the language is now a > language feature > ------------------------------------------------------------------------------------- > language evolution > > Armin Rigo came up with a way to have string concatenation in a loop > (think ``for thing in iter_of_strings: concat_str += thing``) not be a > quadratic algorithm thanks to some trickery for ``a = a + b`` and ``a += > b`` conditions for strings. The hope was to remove the (commonly > considered) wart of having ``"".join(iter_of_strings)`` be the suggested > way to concatenate a bunch of strings. > > But Guido didn't like the patch. His reasoning was that changing > something that led to a change in the Big-O complexity of certain > algorithms would inherently hurt other implementations of Python when > people would start to code specifically for that performance gain. For > instance, having Jython be able to pull this trick off is, I believe, > near impossible. So, in order to make sure changes like this are > considered before applying them, Guido instated a new rule that > "implementation features that affect not just the running speed but the > O() rate for certain algorithms should be considered language features, > because any implementation will be required to implement them in order > to ensure code portability" between implementations of Python. > > In the end, though, this went in with a warning that the speed > performance is not portable. It is not to be used in the stdlib ever. > > Contributing threads: > - `Optimized string concatenation > `__ > - `PEP 0008 confusion - here it is, but don't use it? > `__ > > [snip] From zathras at thwackety.com Mon Aug 23 10:05:27 2004 From: zathras at thwackety.com (Michael Sparks) Date: Mon, 23 Aug 2004 15:05:27 +0100 (BST) Subject: [PATCH] RE: J2 decorator grammar In-Reply-To: <4128d2f1$0$54951$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: On Sun, 22 Aug 2004, Michael Sparks wrote: > Anthony Baxter wrote: > > > On Sun, 22 Aug 2004 15:01:39 +0100, Michael Sparks > > wrote: > >> It should be done sometime this afternoon though. (Bulk of the time taken > >> up is on re-running the test suite unsuprisingly) > > > > One quick point - make sure you run the _full_ test suite (-uall arg > > to regrtest, > > or 'make testall'), otherwise things like the compiler tests won't get > > run. > > Hmm... Didn't know about that version... Running that now and the following > 2 tests fail: > * test_bsddb3 > * test_ossaudiodev > > However, these fail for me when using a vanilla 2.4a2 so whilst not ideal > these failures (probably) aren't due to my changes. > > Everything else passes. > > My next steps are this: > * Change keyword Done. For ease of changing until I do the patch against the CVS tree I'm using the token "SpanishInquisition" since it's simple to search and replace. I intend to put "using" in it's place when put on SF. > * Do short/simple/single line form 80% Done. Grammar used is this: decorator: dotted_name [ '(' [arglist] ')' ] NEWLINE decorators: decorator+ funcdef: ['SpanishInquisition' ':' (decorator |NEWLINE INDENT decorators DEDENT) ] 'def' NAME parameters ':'suite This is a bit ugly IMO, but it does the task required at present. > * Produce patch for CVS version. In progress. Michael. From curzio.basso at unibas.ch Wed Aug 11 04:05:10 2004 From: curzio.basso at unibas.ch (Curzio Basso) Date: Wed, 11 Aug 2004 10:05:10 +0200 Subject: how to dispatch objects depending on their class In-Reply-To: References: <4118dd4a$1@maser.urz.unibas.ch> Message-ID: <4119d33c$1@maser.urz.unibas.ch> cmedcoff at hotmail.com wrote: > Visitor Pattern? Actually, I thought what I was describing was a visitor pattern but I am probably wrong. Is it correct that in the visitor pattern the dispatching would be delegated to the classes, like with: class A(object): def __init__(self): pass def accept(self, visitor) visitor.do_something_with_A(self) class B(A): def __init__(self): A.__init__(self) def accept(self, visitor) visitor.do_something_with_B(self) class Visitor(object): def __init__(self): pass def do_something_with_A(self, object): pass def do_something_with_B(self, object): pass Then I would call a = A() b = B() v = Visitor() a.accept(v) b.accept(v) Is this correct? thanks, curzio From ben at benlast.com Thu Aug 19 11:12:57 2004 From: ben at benlast.com (Ben Last) Date: Thu, 19 Aug 2004 16:12:57 +0100 Subject: Interface graphique pour python In-Reply-To: <8e16829.0408190650.3fa62d5e@posting.google.com> Message-ID: Pas de probleme :) http://www.python.org/cgi-bin/moinmoin/DevelopmentTools Odd how learning one language (Spanish) pushes another (French) out of your head. :( b > -----Original Message----- > From: python-list-bounces+ben=benlast.com at python.org > [mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of > Roland > Sent: 19 August 2004 15:51 > To: python-list at python.org > Subject: Interface graphique pour python > > > Bonjour, > > J'ai redhat 9.0 sur mon ordinateur. Et j'ai besoin d'une interface > graphique de python pour cnstuire une application . J'ai cherch? mais > en vain. Pourriez-vous m'indiquer une? > > Merci de bien vouloir m'aider. > -- > http://mail.python.org/mailman/listinfo/python-list From pythongnome at hotmail.com Wed Aug 18 19:58:29 2004 From: pythongnome at hotmail.com (Lucas Raab) Date: Wed, 18 Aug 2004 23:58:29 GMT Subject: age of Python programmers References: Message-ID: Somebody should set up a website with a poll-type thing to enter your age and see other peoples ages. "Lucas Raab" wrote in message news:jQHUc.1529$2L3.505 at newsread3.news.atl.earthlink.net... > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... > > From bokr at oz.net Mon Aug 9 20:26:48 2004 From: bokr at oz.net (Bengt Richter) Date: 10 Aug 2004 00:26:48 GMT Subject: Purely emotional perspective References: <10hf3oaltbo7o74@corp.supernews.com> <10hg1hg1pidqs96@corp.supernews.com> Message-ID: On Mon, 09 Aug 2004 19:49:38 -0400, Peter Hansen wrote: >Jeff Shannon wrote: > >> Personally, I'm seeing more and more usefulness in decorators as the >> discussion progresses, and I'm seeing more reasons why the most obvious >> alternatives to the currently proposed syntax are not optimal. But I >> still find the current syntax to be *extremely* (painfully) >> uncomfortable -- this sort of prefix syntax is unlike anything else *I* >> can think of in Python. > If the '@' or '|' were a composite glyph instead, and moved a little (to the other end of the function expression), the "prefix" aspect would look more like the function call that it is sugar for, e.g., using '(:' deco1(: deco2(: def foo(): pass # ':):)' closing "parens" not required Thus the order is also plain, i.e., foo = deco1(deco2(foo))) Or if the colon in '(:' messes up tools, maybe '(%' or '(=' ? ... or '(-;' ? *<8^P >That's precisely my feeling at this point as well. Oddly >enough, I think with the slight change to use | instead of >@ (or perhaps even Barry's preferred =) it would be easier to >swallow. Fundamentally though it is things like the strangeness >of these lines that are somehow "bound" to the following (next) >function definition, yet have no connection to it other than >coming at the same indentation level. (At least the | syntax >does feel like it has a visual "link" to the following def.) > >And the reversed order of application (non-intuitive, I feel). Does (: as above help? > >And the restriction to dotted names instead of arbitrary expressions, >making it feel even more weird and non-Pythonic (and that in spite >of the workarounds that have been shown for perhaps all cases >anyway). Yes. With (: it could be legal as a special function-calling expression trailer and would call whatever any preceding expression yielded (and obviously fail if it wasn't callable). > >And other subtleties. > >> I'm particularly worried about the proposals of using this as metadata >> for things like author -- that seems to be begging for almost every >> function to use half a dozen or more decorators (accepts, returns, >> author, design date, last revision date, etc., etc.) which will (IMO) >> seriously degrade code readability. (This syntax is okay for one or two >> decorators, but more than that quickly becomes obfuscatory.) > Some of that sounds like rfc822 stuff ... >This paragraph also seemed worth leaving in. :-) > I'm still wondering what aegis decorators will eventually "unify" under, and with what ;-) Orthogonality beats special-casing IMO ;-) Regards, Bengt Richter From ajsiegel at optonline.com Sat Aug 7 23:10:18 2004 From: ajsiegel at optonline.com (Arthur) Date: Sun, 08 Aug 2004 03:10:18 GMT Subject: Decorators References: <%A8Rc.50217$Vm1.1280580@news20.bellglobal.com> Message-ID: On Sat, 07 Aug 2004 18:40:47 -0400, Roy Smith wrote: >"Colin J. Williams" wrote: >> It seems desirable that we choose words which are as close as possible >> to their everyday usage. > >On the other hand, it's desirable to pick words which have established >meanings in computer science too. The concept of a "decorator" is >pretty well established. The term has been used in GUI frameworks for >10 or 15 years, and more recently has been enshrined in various pattern >collections. My one line answer to the question of what it is I like about Python is: """ It is literate without being effete. """ I can live with "decorator", because it is a word without a particular meaning to me (in this general realm), and I can fill in that blank by an understanding of what it means in concrete terms in Python. But it disturbs me (mildly) to see it justified by something like the Gang of Four reference or GUI framework stuff. I have no compelling reason to read the GOF material. But feel myself to be rarefied (by walking around kind of folks statndards) by understanding, broadly, the reference. I can think of numbers of folks I know who make a living in IT related work, and for whom I am confident the reference would draw a blank. . I've written (simple) GUIs and never heard the word decorator used in that context. This is getting to be pretty effete stuff for a language that strives to be for everybody. Or is that silliness finally off the table. . Standalone the issue of the justification of the word "decorator"wouldn't motivate me to comment. But then I just read something defending '@' because it evokes "prepocessor". Which also then justifies, I guess, its position relative to what it processes. But it also - is it not - the thingy that proceeds "aol.com" when writing to manny_man. I am a great believer in (motivated ) folks capacity to learn new things. And the existence of synonyms is not news to anyone. So no, nobody motivated to learn new things will be stopped in their tracks by @ in a new context (anymore than anyone motivated to learn new things things would - given an explanation - be stopped in their tracks by 1/2 = 0 ). But there is something a bit effete about a confident statement that '@' is consistent with prepended information by referencing its use (somewhere apparently) to hold prepocessor directives.. The less effete argument, it seems to me, is the opposite, The method is the addressee, the decorator the address. The @ therefore belongs between them - at the top of the body of the method. Not before it. Art From SSchukat at dspace.de Thu Aug 19 06:48:54 2004 From: SSchukat at dspace.de (Stefan Schukat) Date: Thu, 19 Aug 2004 11:48:54 +0100 Subject: age of Python programmers Message-ID: <84257D042AA7D411B3F700D0B7DB9B7C0723C001@PDC-DSPACE> Just somewhere in the middle with 33 and doing Python for 6,5 years and loving it. Stefan From rynt at 9yahoo.com Tue Aug 24 18:34:38 2004 From: rynt at 9yahoo.com (R Baumann) Date: Tue, 24 Aug 2004 15:34:38 -0700 Subject: Python and C, looking for a C IDE References: <6f402501.0408240353.2a5b8a84@posting.google.com> <412B5DE8.1BE3@zeusedit.com> Message-ID: "Jussi Jumppanen" wrote in message news:412B5DE8.1BE3 at zeusedit.com... > Michael Foord wrote: > > > That aside - Pyrex looks the kiddie. Can anyone reccomend a reasonable > > C IDE ? An 'IDE' would be nice, but an editor might be sufficient. > > Take a look at the Zeus for Windows programmers editor: > > http://www.zeusedit.com/lookmain.html > > Zeus supports Python, C/C++ and almost any other language. Some of > the programming features include: > > + Code completion and intellisensing > + Integrated class browser > + Project/workspace management > + Fully configurable syntax highlighting > + Seamless FTP editing > + Integrated version control using the Microsoft Source Code > Control (SCC) interface, including CVS integration. > + Quick Help context sensitive help engine > + Fully scriptable using Python > > There is also a tutorial (see the Start Button, Programs, Zeus for > Windows, Tutorials) that explains how to setup the Ming compiler > and debugger (Windows ports of gcc and gdb) to work with Zeus. > > Jussi Jumppanen > http://www.zeusedit.com Try Jedit. http://www.jedit.org/ While primarily written for Java(in Java), it has a plug-in for Jython, and supports C/C++ and a myriad of other languages. Ruben From jeff at ccvcorp.com Mon Aug 30 20:05:15 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Mon, 30 Aug 2004 17:05:15 -0700 Subject: Upgrading to 2.3 from 2.2, questions In-Reply-To: References: Message-ID: <10j7g4vsf5ef9c5@corp.supernews.com> Peter Hansen wrote: > Robert Oschler wrote: > >> - Do I need to uninstall 2.2 first? > > > I don't know if there's an official answer other than "yes". I don't > know if there's a safe answer other than "yes". I'm pretty sure that there should be no problems with having different versions of Python running side-by-side. I have had 2.0 and 2.1 on the same machine, and 2.1 and 2.2, with no problems at all. >> - I am running on Windows 2000 and I have several site-packages >> installed. >> These were installed using individual one-click installation programs >> (thank >> you module writers). Do I need to rerun each of the installations >> again, >> after I upgrade? Or, is there a directory or two I can simply copy >> over? > > > While it might work, it's not guaranteed. Extensions need to > be compiled for the specific version, while pure Python packages > will generally run as-is if you just copy them (generally they > are all in python/lib/site-packages). No guarantees again. As Peter says, any packages that contain C extension (.pyd) modules need to be compiled for the specific version of Python. You will need to download new versions of those packages. Packages that are pure Python *should* run just as well under the new version as the old version, providing that it doesn't trip over any of the possible backwards-compatibility issues (such problems are moderately unusual) -- however, if you copy from site-packages to site-packages, be sure to delete any .pyc files because those are probably *not* version-portable. You're probably better off re-running the installer, if it's still available. (Also, odds are good that there's a new version of those packages, and while you're upgrading Python is a good time to upgrade other things too, so you may want to go ahead and re-download those packages as well.) Jeff Shannon Technician/Programmer Credit International From aleaxit at yahoo.com Thu Aug 26 04:35:12 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 10:35:12 +0200 Subject: Why return None? References: <7x65762wba.fsf@ruckus.brouhaha.com> Message-ID: <1gj4fo8.wzxpddp8r49yN%aleaxit@yahoo.com> Paul Rubin wrote: > Peter Hansen writes: > > > instance, I can't say move(Vector([a,b,c]).normalize()), I have to do > > > a = Vector([a,b,c]) > > > a.normalize() > > > move(a) > > > > By the way, the second version is much more readable than the first, > > That's a matter of opinion. The lines are shorter but there are three > times as many of them. I think programmers ought to be able to make > their own choices about this. There are a lot of different styles > that are equally legitimate. But they're not equally Pythonic -- Python's philosophy is that there should be preferably only one obvious way to do it. It's a target, a goal, not something that can be actually reached in 100% of the cases, but it's an excellent idea. Alex From grante at visi.com Thu Aug 26 11:05:00 2004 From: grante at visi.com (Grant Edwards) Date: 26 Aug 2004 15:05:00 GMT Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <776e0325.0408260433.449660c8@posting.google.com> Message-ID: <412dfc1c$0$65599$a1866201@newsreader.visi.com> On 2004-08-26, Sara wrote: > Hey this ain't no CULT! Our creedo is simply: > > "Larry said it, I believe it, THAT settles it!" > > If you don't believe it just look at the reaction if any questions any > element of Perl design! Over here in c.l.python, it's more like "Guido said it, that settles it, but we're going to discuss it endlessly and and vote on it using six or seven different voting algorithms anyway. Then we'll argue about the voting algorithms." -- Grant Edwards grante Yow! I'm ZIPPY!! Are we at having FUN yet?? visi.com From dd55 at cornell.edu Sun Aug 8 14:35:52 2004 From: dd55 at cornell.edu (Darren Dale) Date: Sun, 08 Aug 2004 14:35:52 -0400 Subject: What is @ used for? Message-ID: I was looking through Pybliographer's source yesterday, and I dont recognize this syntax: version = "@version@" progname = "@package@" Presumably, this is reading values from somewhere. I havent seen '@' discussed in the python manuals or books, only IPython's magic functions. Maybe I'm not looking in the right place. Could anyone point me in the right direction? From anthony at pearsonkennedy.com Wed Aug 11 21:10:26 2004 From: anthony at pearsonkennedy.com (anthony at pearsonkennedy.com) Date: 11 Aug 2004 18:10:26 -0700 Subject: Python Developer needed Message-ID: <7c4bf12e.0408111710.20b567a@posting.google.com> Ottawa part-time opportunity that can be done remotely! PearsonKennedy is looking for an individual with the following skills: Python ZPT or equivalent Page Templating Web Development Java script Strong OOD XHTML CSS SQL Experience with transactional systems would be an asset If interested and meet the qualifications please send resume to anthony at pearsonkennedy.com From pm_mon at yahoo.com Fri Aug 20 08:35:24 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Fri, 20 Aug 2004 08:35:24 -0400 Subject: PEP 318: Can't we all just get along? In-Reply-To: References: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: Anthony Baxter wrote: > On Fri, 20 Aug 2004 05:57:42 -0400, Paul Morrow wrote: > >>I know you weren't Anthony (that was a joke). I understand that you >>don't like this idea, but that doesn't make it a _bad_ one. Numerous >>people have *not* effectively pointed out the problems with it (and >>neither have you, sir). > > > Err, what? Have you bothered to read the replies I sent to you? Yes of course I have. You can tell because I've replied to everything you've said, directly (as best I could) addressing your 'points'. Have you noticed my replies? Did you bother to read them? > This is _bad_ magic behaviour. Python does not care about argument lists > now, and adding this is icky. Python doesn't do this now. Check. You think that it's "icky". Check. > Your behaviour when _adding_ methods to classes is extremely undefined, > particularly in the presence of > descriptors. If you're talking about dynamically adding methods to classes (at runtime), we've discussed this in general. You have to have the first parm name correct before you add the method. But we haven't talked about descriptor issues yet, have we? What's the problem with them? > Explaining this to new users would be complex. We discussed this before too (didn't we?). It will be *less* complex for new users. Well, you tell me. Here's the only part of the classmethod documentation that would change (from http://docs.python.org/lib/built-in-funcs.html)... """ A class method receives the class as implicit first argument, just like an instance method receives the instance. To declare a class method, use this idiom: class C: def f(cls, arg1, arg2, ...): ... f = classmethod(f) """ ...it would be changed to (something like) this... """ A class method receives the class as its first argument 'cls', just like an instance method receives the instance as its first argument 'self'. To declare a class method, use this idiom: class C: def f(cls, arg1, arg2, ...): ... Note that the first argument of each class method must be named 'cls'. """ > It's a > messy interference in the way Python's OO builds classes and objects, > which is currently very clear and easy to follow[1]. We haven't discussed this, have we? What do you mean? > It's not explicit, but implicit. True. But then so is dynamic typing, a powerful feature of Python that differentiates it from languages like Java, C++. Therefore, you aren't saying enough here for that point to be valid. > How many ways do I have to spell this out? One valid spelling would be a good start. > > The only argument _for_ this that you've offered is that it's just like the > double-underscores. Oh my... Have you been reading *my* posts? If so, I must be doing a terrible job of communicating here (my apologies). Here are four reasons in favor of it. Rip them apart to your satisfaction. 1. It make formal a convention widely used by others and therefore would have an obvious interpretation to readers of your code. 2. It doesn't require as much typing as the current technique nor any proposed decorator technique. 3. It is less error prone (because it is WYSIWYG) than the current technique. 4. It is easier to understand than the current technique. > double-underscores. This is a losing argument (with me, anyway) as > I regard the double-underscore mangling as awful - that sort of "data > hiding" just ends up being a pain in the arse when you want to poke > with a class's internals. Python regards everyone as an adult in that > respect, unlike the "protecting you from yourself" C++ nightmare. In > addition, the double-underscore is just random magic that occurs when > a class is created, not subsequently: > > >>>>class A: > > ... __foo = 1 > ... > >>>>dir(A) > > ['_A__foo', '__doc__', '__module__'] > >>>>A.__bar = 2 >>>>dir(A) > > ['_A__foo', '__bar', '__doc__', '__module__'] > > for the same reasons, your idea would lead to inconsistencies. > That's an interesting point. The behavior you illustrate is apparently a Python bug wrt private attributes. If it was consistent... A.__bar = 2 would work, but a subsequent print A.__bar would generate an attribute error. But of course its easy to make Python work that way (as I show below). Likewise, I'm sure similar inconsistencies in 'my' (for lack of a better word --- I didn't actually come up with it) idea could be as easily resolved. ############################################################# class M(type): def __setattr__(metacls, attrName, value): if attrName.startswith('__'): attrName = '_%s%s' % (metacls.__name__, attrName) type.__setattr__(metacls, attrName, value) class A: __metaclass__ = M __foo = 1 print [x for x in dir(A) if x.startswith('_A')] # 1. A.__bar = 2 print [x for x in dir(A) if x.startswith('_A')] # 2. """Footnotes: 1. prints ['_A__foo'] 2. prints ['_A__bar', '_A__foo'] """ ############################################################# From serj307 at hotmail.com Wed Aug 11 22:27:29 2004 From: serj307 at hotmail.com (Serj K.) Date: 11 Aug 2004 19:27:29 -0700 Subject: problems with pysmb Message-ID: <45134507.0408111827.1b044e2a@posting.google.com> Hi, all. i'm having some problems with 'pysmb' module. What i'm trying to do is to get list of all available shares (servers) on local ethernet. The net is quite big, and there is no way to know to how many subnets (sub domains) it is divided. So, what's the best method to do this? After calling 'gethostbyname' with '__MSBROWSE__' I have the ip of master_browse. But to use the 'smb.SMB(remote_name, remote_host... )' I need to know the netBiosName of the host, which i don't know (and the reverse function, name based on ip, is not working, even 'nmblookup -T xx.xx.xx.xx is not working). The question is why smb.SMB() needs both the ip and netBIOSName? And if there is another way to do things? There has to be, 'couse programms like LinNeighborhood somehow manage to work. PS The problem probably is that I don't really understand the whole concept of netBIOS stuff. In this case can someone please point me to some brief intriduction? thanx in advance From davidf at sjsoft.com Thu Aug 19 06:06:43 2004 From: davidf at sjsoft.com (David Fraser) Date: Thu, 19 Aug 2004 12:06:43 +0200 Subject: Think you've got a new decorator syntax? In-Reply-To: References: Message-ID: Steven Bethard wrote: > You probably don't. ;) Here's a script that generates (almost) all of > the proposals so far. Don't worry, there's only 1224 that are both > not currently valid syntax and also easily greppable. ;) > > http://ucsu.colorado.edu/~bethard/py/decorators.py > > And the output (throwing away any syntaxes that were currently valid > or not easily greppable): > > http://ucsu.colorado.edu/~bethard/py/decorators-output.py > > Steve Excellent! I propose that we accept *ALL* of the syntaxes! Flexibility! David From peter at engcorp.com Mon Aug 9 15:28:13 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 09 Aug 2004 15:28:13 -0400 Subject: Best pattern/idiom In-Reply-To: <4117c3d8$1@buckaroo.cs.rit.edu> References: <4117c3d8$1@buckaroo.cs.rit.edu> Message-ID: Chris Connett wrote: > I was wondering if there were a well known pattern/idiom for breaking a > sequence into a list of lists, each n elements long, e.g. > > [0,1,2,3,4,5,6,7,8,9,10,11] -> [[0,1,2,3],[4,5,6,7],[8,9,10,11]] > > This comes up reasonably often in my work, and every time I re-think > about it, and come up with > [ lis[n:n+4] for n in range( 0, len( lis ), 4 ) ] > which seems very kludgy to me, since it uses a range and len, 2 mentions > of the list identifier and 2 literal 4's (which is the size I want to > break into this time). > > Is there a better way? Found from a Peter Otten post via Google Groups (searching for "islice list split"): >>> def chunks(s, size): ... for i in range(0, len(s), size): ... yield s[i:i+size] >>> s [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] >>> list(chunks(s, 4)) [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]] >>> list(chunks([], 4)) [] >>> list(chunks(s[:10], 4)) [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9]] Of course, this uses range and len as well, and two mentions of the identifier. A function would have let you avoid the duplicated literal 4, as this does also. Now, define "better". ;-) Some tasks have an inherent complexity that can't be shrunk below a certain size... -Peter From indigo at bitglue.com Mon Aug 23 21:13:48 2004 From: indigo at bitglue.com (Phil Frost) Date: Mon, 23 Aug 2004 21:13:48 -0400 Subject: Help with trapping an exception In-Reply-To: References: Message-ID: <20040824011348.GB834@unununium.org> Take a look at the traceback standard module to format exceptions nicely. Another thing you can do is this: try: {}['fu'] except Exception, x: print x That asigns the exception to x in the except block. All exceptions can be converted to strings which are usually short descriptions of the problem. One problem is KeyError, which converts to just the bad key, for example the above just prints "fu" which is less than helpful. Another catch of the above is that it will only catch subclasses of Exception, which is almost everything except a few like StopIteration or user classes that don't subclass Exception. On Mon, Aug 23, 2004 at 09:05:15PM -0400, pythos at bag.python.org wrote: > I have a piece of code like this: > > try: > some code > except: > print >> sys.stderr, "error: ", sys.exc_info() > > > When an exception is thrown from the code, what I see on the console is this: > > error: (, instance at 0x09752C50>, ) > > I had a lot of trouble figuring out what was causing the NameError. I finally > figured it out by removing the "try" and "except" statements so that my code > didn't catch any exceptions. When I did that, I saw the following on my > console: > > Traceback (most recent call last): > File "c:\Documents and Settings\xxxxx\rot.PspScript", line 79, in Do > os.path.walk(baseDirectory, ProcessDirectory, Environment) > File "c:\Program Files\xxxxxx\Python Libraries\lib\ntpath.py", line 318, in > walk > func(arg, top, names) > File "c:\Documents and Settings\xxxxx\rot.PspScript", line 36, in > ProcessDirectory > App.Do(Environment, 'FileOpen', { > NameError: global name 'Environment' is not defined > > > Now that was much more helpful. Once I knew that 'Environment' was not > defined, I easily figured out the problem. But I need to use "try" and > "except" to catch the exception, otherwise my program will end abruptly > without finishing. So how can I see the "NameError: global name 'Environment' > is not defined" message in the "except" section of my code? A call to > sys.exc_info() doesn't show it. Is there another function I can use? Thanks. From matt.price at utoronto.ca Mon Aug 9 14:48:54 2004 From: matt.price at utoronto.ca (Matt Price) Date: Mon, 9 Aug 2004 14:48:54 -0400 Subject: cgi script: get the url of this page Message-ID: <20040809184854.GA10092@utoronto.ca> A super simple question: is there a standard trick to get the url of the current page in a cgi script, or the url from which form data has been passed?? I want to embed the name of the current page in a form field for two reasons: (1) sometimes I want to send form data to the current page; (2) sometimes I want to know where the daa came from, so I can add that information to a database. thanks again, Matt ------------------------------------------- Matt Price matt.price at utoronto.ca History Department, University of Toronto (416) 978-2094 -------------------------------------------- From daniel.dittmar at sap.com Thu Aug 5 08:02:23 2004 From: daniel.dittmar at sap.com (Daniel Dittmar) Date: Thu, 5 Aug 2004 14:02:23 +0200 Subject: Scope Problem References: Message-ID: You are not returning the value of the recursive call self.linearSearch(value, index + 1). Hmm, implementing a linear search through recursion. Is your first language LISP? Daniel Nickolay Kolev wrote: > Hi all, > > I have set to implementing a few basic algorithms in Python serving a > twofold purpose: learning the algorithms and learning Python a little > better. > > I have however encountered a strange (for me anyway) scoping problem. > > Here is my implementation of linear search as a method in a class, > hence all the self's (self.sequence is the sorted sequence we are > searching in and value is, well, the value we are searching for): > > def linearSearch(self, value, index = None): > > if not index: > index = 0 > > try: > > if self.sequence[index] == value: > > return index > > else: > > self.linearSearch(value, index + 1) > > except IndexError: > > return -1 > > > My problem is that this method always returns None regardless of > whether the value was found or not. If I put print statements in > there, all the values and indices are printed correctly though. > Actually I have another parameter to this method called debug, if > this is set, the single comparison steps are printed to STDOUT > (omitted above to avoid clutter). > > What am I doing wrong? > > Many thanks in advance, > Nicky From ptmcg at austin.rr._bogus_.com Fri Aug 6 10:59:59 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 06 Aug 2004 14:59:59 GMT Subject: Decorator syntax References: <8d3e714e.0408051651.7c91a5c4@posting.google.com> Message-ID: "Tony C" wrote in message news:8d3e714e.0408051651.7c91a5c4 at posting.google.com... > > This is backwards compatible (Python <= 2.3 raise > > SyntaxError), and looks much nicer than @. > > "Almost" anything looks better than the @ syntax. > If @ gets implemented, there goes the whole easily-readable plug for > Python. > We might as all go learn Perl. > > While everyone is fussing around on the syntax of decorators, I think > they should change the name as well (although I don't have a > reasonable alternative yet). Decorator is the least program-like term > I've ever heard of. :) Talk to the Gang of Four about that. Decorator is straight out of the Design Patterns book. -- Paul From rattan at cps.cmich.edu Thu Aug 26 01:38:06 2004 From: rattan at cps.cmich.edu (Ishwar Rattan) Date: 25 Aug 2004 22:38:06 -0700 Subject: A question?? Message-ID: <938a4680.0408252138.1580ac93@posting.google.com> I thought that Python has no concept of reference/pointer (probably incorrect assumption). I saw the following piece of code: ... def run(program, *args): pid = os.fork() if not pid: os.execvp(program, (program,)+args) ... and call to run as run("pyhton", "a.py") What is the interpretation of *args (in def run(..)? Looks like a reference to me, so, how does one decide when to use a reference or not? Any pointers to info will be appreciated. -ishwar From kjetilho at yksi.ifi.uio.no Fri Aug 27 11:42:37 2004 From: kjetilho at yksi.ifi.uio.no (Kjetil Torgrim Homme) Date: Fri, 27 Aug 2004 17:42:37 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> Message-ID: <1ru0uod1ua.fsf@rovereto.ifi.uio.no> [Andrew Koenig]: > > [Kjetil Torgrim Homme]: > > my suggestion is to allow braces to mark the suites. Python is > > still strictly enforcing indentation, in fact, in some ways it's > > stricter then before. > > The following code is legal today: > > def foo(x): > print x > x = 3 > if x == 3: > { > foo(x) : 42 > } > > Are you proposing to change the meaning of this code? no, this code still works with my patch. the opening brace must be at the same level as the preceding statement. this is not a problem, since the insides of a literal dict can't be a valid Python expression and vice versa, so you'll get a syntax error even if the misplaced opening brace is mistakenly taken as the beginning of a dict by the Python parser. my current patch does have a problem as stated in my original message, but this is really just a proof-of-concept. a patch with no backwards compatibility problems can be prepared if there is interest. -- Kjetil T. From roy at panix.com Thu Aug 12 12:39:00 2004 From: roy at panix.com (Roy Smith) Date: Thu, 12 Aug 2004 12:39:00 -0400 Subject: measuring 1/100th seconds, what function? References: <87657ojp2l.fsf@uwo.ca> Message-ID: In article <87657ojp2l.fsf at uwo.ca>, Dan Christensen wrote: > Roy Smith writes: > > > Tim Peters wrote: > >> Note that on a box connected to a network time-correction > >> service, time.time can appear to "run backwards" briefly at > >> unpredictable times. > > > > This will never happen if you're running NTP. NTP does gradual > > adjustments to the clock rate to ensure that the system clock is always > > monotonically increasing. > > ntp only works well if your clock rate is very consistent. On all of > the laptops I've used, I get frequent adjustments: > > Aug 6 20:30:45 localhost ntpd[911]: time reset -0.472600 s > Aug 5 22:04:57 localhost ntpd[919]: time reset +0.670974 s > Aug 5 22:34:06 localhost ntpd[919]: time reset +0.884625 s > Aug 5 23:13:54 localhost ntpd[919]: time reset -0.376758 s > > I don't see any reason in principle ntp couldn't allow a greater > offset between the local machine and the servers, and use gradual > adjustments in this case. But it doesn't. > > Dan I stand corrected. Thank you. From cdunscombe at yahoo.com Thu Aug 26 12:23:08 2004 From: cdunscombe at yahoo.com (Chris) Date: 26 Aug 2004 09:23:08 -0700 Subject: Distributing Python applications - McMillan Installer question Message-ID: <6f89f4fe.0408260823.3b856a34@posting.google.com> I would like to be able to "package-up" a Python application on my development platform (Linux) so that it can be easily distributed and installed on Windows and UNIX e.g. HP-UX, AIX etc. I'd rather not use Python's disutils. I've looked at cx_Freeze but this requires a "base executable" to be available for each target platform i.e. I'd need to compile this base executable on the target platforms but I don't have access to them all. I've had a quick look at the McMillan installer and from what I've seen It's not clear to me whether this would do the job for me or not? An aswer to this or any other ideas on how else I might progress would be much appreciated. Thanks, Chris From zathras at thwackety.com Fri Aug 27 05:08:02 2004 From: zathras at thwackety.com (Michael Sparks) Date: Fri, 27 Aug 2004 10:08:02 +0100 (BST) Subject: Call for signatories for J2 In-Reply-To: Message-ID: On Fri, 27 Aug 2004, Anthony Baxter wrote: > On Thu, 26 Aug 2004 20:14:33 +0100, Michael Sparks > wrote: > ... > > 4 The feature might be ripped out ... > That's not the way Python works - we don't rip stuff out once it's > been in a final release. from __future__ is added so that people can > turn on a new feature gradually, without their code being instantly > broken. I was meaning before 2.4's final release. I realise that the likelyhood of this is about the same as Richard Stallman joining Microsoft as a patent advocate, but in a world of infinite possibilities ... ;-) Michael. From grzegorz at ee.ualberta.ca Fri Aug 6 13:08:38 2004 From: grzegorz at ee.ualberta.ca (Grzegorz Dostatni) Date: Fri, 6 Aug 2004 13:08:38 -0400 Subject: Extending python. In-Reply-To: References: Message-ID: Followup. Thanks, I'll re-read this again. Small change. I've managed to extend python with a small module (just using the .o file) under Linux. It appears that my problems are a bit more windows centric. Anyone willing and able to help me with that? Greg "In theory, there is no difference between theory and practice. But, in practice, there is." - Jan L.A. van de Snepscheut On Fri, 6 Aug 2004, Batista, Facundo wrote: > Maybe this will help you: > > http://www.python.org/doc/faq/extending.html > > . Facundo > > #- -----Mensaje original----- > #- De: Grzegorz Dostatni [mailto:grzegorz at ee.ualberta.ca] > #- Enviado el: Viernes, 06 de Agosto de 2004 13:35 > #- Para: python-list at python.org > #- Asunto: Extending python. > #- > #- > #- > #- Cheers. > #- > #- More questions. > #- Let's say I'm trying to extend python with a c module. That > #- module cannot > #- be dynamically loaded (for reasons outside my control). I > #- have to create a > #- custom python executable (or more likely custom python library). > #- How would I do that? Is there documentation on that > #- somewhere? Most of > #- what I've seen was for dynamic loading. > #- > #- 2nd Step: > #- Let's say I'm doing it under windows, using Visual Studio. Is there > #- anything I have to be aware of? > #- > #- 3rd Step: > #- Let's say I don't have the source available. I do have the > #- object files, > #- the resulting libraries and the header files though. > #- > #- Greg > #- > #- "The optimist proclaims that we live in the best of all > #- possible worlds, > #- and the pessimist fears this is true." > #- - James Branch Cabell > #- > #- > #- -- > #- http://mail.python.org/mailman/listinfo/python-list > #- > From mharlow-dated-1093699782.6a56ce at grephead.com Wed Aug 25 11:00:29 2004 From: mharlow-dated-1093699782.6a56ce at grephead.com (matt okeson-harlow) Date: Wed, 25 Aug 2004 15:00:29 -0000 Subject: MySQLdb on Solaris8, build errors Message-ID: i am getting errors trying to build MySQLdb on solaris 8, i have tried changing the libs, no joy, anyone have any ideas? Python 2.3.4 gcc -v Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/specs Configured with: ../configure --disable-nls --with-ld=/usr/ccs/bin/ld --with-as=/usr/ccs/bin/as Thread model: posix gcc version 3.2.2 i have tried both MySQLdb 1.0.0 and 1.1.1 output from mysql_config: --cflags [-I'/usr/local/include/mysql'] --libs [-L'/usr/local/lib/mysql' -lmysqlclient -lz -lcrypt -lgen -lsocket -lnsl -lm] --socket [/tmp/mysql.sock] --port [3306] --version [4.0.12] --libmysqld-libs [ -L'/usr/local/lib/mysql' -lmysqld -lpthread -lthread -lz -lcrypt -lgen -lsocket -lnsl -lm -lpthread -lthread -lrt] variables set are: mysqlclient=mysqlclient mysqlversion=4.0.12 mysqloptlibs=crypt z output from python setup.py build: running build running build_py running build_ext building '_mysql' extension creating build/temp.solaris-2.8-sun4u-2.3 gcc -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/include/mysql -I/usr/local/include/mysql -I/usr/local/mysql/include -I/usr/local/mysql/include/mysql -I/usr/local/include/python2.3 -c _mysql.c -o build/temp.solaris-2.8-sun4u-2.3/_mysql.o -fPIC gcc -shared build/temp.solaris-2.8-sun4u-2.3/_mysql.o -L/usr/lib/mysql -L/usr/local/lib/mysql -L/usr/local/mysql/lib -L/usr/local/mysql/lib/mysql -Wl,-R/usr/local/lib:/usr/openwin/lib:/usr/dt/lib -lmysqlclient -lcrypt -lz -lz -lcrypt -o build/lib.solaris-2.8-sun4u-2.3/_mysql.so Text relocation remains referenced against symbol offset in file 0x738 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x73c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x740 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x744 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x748 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x74c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x750 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x754 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x758 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x75c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x760 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x764 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x768 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x76c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0xab8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0xabc /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0xac0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0xac4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0xac8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0xacc /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0xad0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0xad4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0xad8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0xadc /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0x780 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) 0x784 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) 0x788 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) 0x78c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) 0x790 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) 0x794 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) 0x798 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) 0x79c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) 0x7a0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) 0x7a4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) 0x40 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) 0x4c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) 0x58 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) 0x64 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) 0x70 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) 0x7c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) 0x88 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) 0x94 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) 0xa0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) 0xac /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) memset 0x9a0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) memset 0xee0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) zcalloc 0x70 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) zcalloc 0x74 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) zcalloc 0x58 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) zcalloc 0x5c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) _tr_flush_block 0xfdc /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _tr_flush_block 0x1060 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _tr_flush_block 0x11e8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _tr_flush_block 0x155c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _tr_flush_block 0x1774 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _tr_flush_block 0x1a38 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _tr_flush_block 0x1cd0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _tr_flush_block 0x1ea4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) inflateInit2_ 0x998 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) inflateInit2_ 0x99c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) inflate_blocks_reset 0x204 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) inflate_blocks_reset 0x578 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) inflate_blocks_reset 0x894 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) inflate_blocks_reset 0x908 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) _tr_stored_block 0x8d4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _tr_stored_block 0x6c8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) free 0x40 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(zutil.o) .urem 0xac0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) .urem 0x34c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) .urem 0x14c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(adler32.o) .urem 0x15c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(adler32.o) .umul 0x1c10 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) .umul 0x1c44 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) .umul 0x1d58 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) inflate_codes_free 0x7a0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) inflate_codes_free 0xb5c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) inflate_codes_free 0xcf0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) .udiv 0x1ac /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) memcpy 0x36c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) memcpy 0x868 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) memcpy 0x924 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) memcpy 0x9dc /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) memcpy 0xd44 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) memcpy 0xe00 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) memcpy 0xe14 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) memcpy 0xe28 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) memcpy 0xe38 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) memcpy 0x10b4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) memcpy 0x1120 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) memcpy 0x1250 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) memcpy 0x15b0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) memcpy 0x17dc /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) memcpy 0x1aa4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) memcpy 0x1d1c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) memcpy 0x1f0c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) memcpy 0x2050 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) memcpy 0x211c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) memcpy 0x32c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) memcpy 0xd60 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) memcpy 0x88 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infutil.o) memcpy 0x114 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infutil.o) _dist_code 0x1424 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _dist_code 0x1428 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _dist_code 0x1444 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _dist_code 0x1448 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _dist_code 0x1670 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _dist_code 0x1674 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _dist_code 0x1b90 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _dist_code 0x1b94 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _dist_code 0x1bb0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _dist_code 0x1bb4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _dist_code 0x1d9c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _dist_code 0x1da4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _dist_code 0xa1c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) _dist_code 0xa20 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) _dist_code 0xa24 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) _dist_code 0xbac /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) _dist_code 0x1008 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) _dist_code 0x1024 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) _dist_code 0x1040 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) _dist_code 0x1050 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0x10 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(compress.o) 0x2c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(compress.o) 0x9c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(compress.o) 0xb4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(compress.o) deflateEnd 0x60 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(compress.o) deflateEnd 0x7c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(compress.o) deflateEnd 0xec /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(compress.o) deflateEnd 0x108 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(compress.o) deflateEnd 0x2bc /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) deflateEnd 0xea0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) deflateInit_ 0x34 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(compress.o) deflateInit_ 0xc0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(compress.o) deflate 0x48 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(compress.o) deflate 0xd4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(compress.o) deflate 0x5b4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) 0x10 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(uncompr.o) 0x24 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(uncompr.o) inflate 0x40 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(uncompr.o) inflateInit_ 0x2c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(uncompr.o) inflateEnd 0x58 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(uncompr.o) inflateEnd 0x74 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(uncompr.o) 0x1c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) 0x20 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) 0x52c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) 0x530 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) 0x574 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) 0x578 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) 0x734 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) 0x740 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) 0xeec /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) 0xefc /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) zcfree 0x90 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) zcfree 0x94 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) zcfree 0x7c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) zcfree 0x80 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) deflateReset 0x2a8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _tr_init 0x494 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _length_code 0x13c4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _length_code 0x13d8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _length_code 0x1b10 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _length_code 0x1b2c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) _length_code 0x8d0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) _length_code 0x8d4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) _length_code 0xffc /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) _length_code 0x1000 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) _tr_align 0x9b0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) adler32 0x32c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) adler32 0x20e4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) adler32 0x120 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) adler32 0x134 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) adler32 0x9e0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) z_errmsg 0x25c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) z_errmsg 0x26c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) z_errmsg 0x2b0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) z_errmsg 0x2b4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) z_errmsg 0x620 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) z_errmsg 0x640 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) z_errmsg 0x66c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) z_errmsg 0x670 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) z_errmsg 0x688 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) z_errmsg 0x9c8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) z_errmsg 0x9cc /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) z_errmsg 0xa78 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) z_errmsg 0x18 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(zutil.o) z_errmsg 0x1c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(zutil.o) deflateInit2_ 0x1f9c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(deflate.o) 0xedc /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0xee4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0xee8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0xeec /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0xef8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0xf04 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0x13c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0x140 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0x268 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0x26c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0x410 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0x414 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0x688 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0x68c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0x690 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0x698 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0x71c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0x720 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0x968 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0x96c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0x980 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0x984 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0xab8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0xabc /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0xad4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0xadc /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0x19c8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0x19d0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0x1dd0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0x1dd4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(trees.o) 0x0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(zutil.o) 0x8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(zutil.o) calloc 0x2c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(zutil.o) calloc 0x30 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(zutil.o) 0x288 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x290 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x2e8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x304 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x4d4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x4d8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x4f8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x500 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x520 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x524 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x6d8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x6dc /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x7bc /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x7cc /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) inflate_blocks_new 0x144 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) inflate_blocks_free 0x10c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) inflate_blocks_free 0x1a8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) inflate_blocks_free 0x974 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) inflate_blocks_sync_point 0xa78 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) inflate_blocks_sync_point 0xa7c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) inflate_blocks 0x544 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) inflate_set_dictionary 0xa28 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inflate.o) 0x40 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0x48 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0x1a8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0x1b8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0x2bc /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0x2d0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0x4f0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0x4f4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0x580 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0x584 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0x9d8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0x9e8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0xa38 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0xa48 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) inflate_mask 0x60c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) inflate_mask 0x610 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) inflate_mask 0x12c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) inflate_mask 0x160 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) inflate_mask 0x164 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) inflate_mask 0x290 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) inflate_mask 0x2c4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) inflate_mask 0x2c8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) inflate_mask 0x310 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) inflate_mask 0x344 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) inflate_mask 0x34c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) inflate_mask 0x3dc /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) inflate_mask 0x410 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) inflate_mask 0x414 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) inflate_mask 0x4c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inffast.o) inflate_mask 0x50 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inffast.o) inflate_mask 0xa4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inffast.o) inflate_mask 0xa8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inffast.o) inflate_mask 0x2b0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inffast.o) inflate_mask 0x2b4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inffast.o) inflate_flush 0x374 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) inflate_flush 0x808 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) inflate_flush 0xaa8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) inflate_flush 0x1fc /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) inflate_flush 0x4f8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) inflate_flush 0x60c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) inflate_flush 0x6d0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) inflate_codes 0x788 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) inflate_codes_new 0xd0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) inflate_codes_new 0x72c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) inflate_trees_bits 0x5c8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) inflate_trees_fixed 0xb8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) inflate_trees_dynamic 0x70c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infblock.o) 0x254 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x258 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x260 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x264 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x268 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x270 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x274 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x27c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x3c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x40 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x44 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x60 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x78 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x88 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x94 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x98 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0xa4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0xd0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0xd4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0xd8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x150 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x158 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x15c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x164 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x168 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x170 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x200 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x214 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x218 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x23c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x240 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inftrees.o) 0x44 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) 0x4c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) 0x1d8 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) 0x1e4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) 0x3a4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) 0x3b4 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) inflate_fast 0xc0 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(infcodes.o) 0x200 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inffast.o) 0x20c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inffast.o) 0x30c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inffast.o) 0x31c /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/../../../libz.a(inffast.o) ld: fatal: relocations remain against allocatable but non-writable sections collect2: ld returned 1 exit status error: command 'gcc' failed with exit status 1 -- matt okeson-harlow http://technomage.net From rnichol_rrc at yahoo.com Tue Aug 17 00:50:47 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Mon, 16 Aug 2004 23:50:47 -0500 Subject: Python secure? In-Reply-To: References: <2xXTc.3775$bJ2.24876@news1.mts.net> Message-ID: <38gUc.4022$bJ2.26922@news1.mts.net> Peter Hansen wrote: > Reid Nichol wrote: > >> And because some M$ employee did something sloppy it is an implication >> that C is bad. Hell, even strncpy can be dangerous. How many times >> do I have to say the responsibility is the programmers, *not* the >> language. > > > The *responsibility* is clearly the programmer's, but the *language* > tends to encourage or discourage certain kinds of programmer behaviour, > including the writing of secure code. > > Surely you wouldn't argue that all languages promote different > kinds of coding equally well, or even that the choice of language > has *no impact whatsoever* on how a programmer will code, or what > kinds of solutions he will attempt to use in his code? > > -Peter Here, this programmer made a rookie mistake. (S)he clearly had no business writing the code (s)he did. It isn't the languages fault, it's the programmers. In general, I believe that if the programmer is a poor programmer then they'll find a way to mess up no matter what language they use. The language will just state how big that mess up can/will be on average. But, if someone wants secure programming done and they charge a rookie to do it, they get what they deserve. If they want secure code and they hire an years guru (at the language) coder that knows nothing of writing *secure* code, they get what they deserve. The ability to write secure programs is a rare talent and those that need it, need to develop the ability to see this quality in there employees (or the ability to find them). This isn't something that anyone can pick up and learn, one must have something inside them that enables them to do it. And all that evidence that was spoken of merely supports the fact that it is a rare talent indeed. From fakeaddress at nowhere.org Sun Aug 8 00:21:16 2004 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sun, 08 Aug 2004 04:21:16 GMT Subject: How to force a single number to be a tuple In-Reply-To: References: <1a517b5.0408061329.429de7fc@posting.google.com> Message-ID: <0ThRc.1653$QJ3.1264@newssvr21.news.prodigy.com> Roy Smith wrote: > Dennis Lee Bieber >> An unrestricted Cartesian product basically pairs up each entry >> of "domain A" with each entry of "domain B" > > Ah. The cross-product. It's amazing how so many fields of study use > the same concepts but invent new names for things to obfuscate > everything :-) The Cartesian product is named for Ren? Descartes, father of analytic geometry. Though sometimes called the 'Cross product', the latter term is much more commonly associated with the vector cross-product, and that's what people will usually find if they try to look up or Google "cross-product". -- --Bryan From SBrunning at trisystems.co.uk Wed Aug 18 09:05:40 2004 From: SBrunning at trisystems.co.uk (SBrunning at trisystems.co.uk) Date: Wed, 18 Aug 2004 14:05:40 +0100 Subject: Platform independent way to play an mp3 file Message-ID: <31575A892FF6D1118F5800600846864D01AE29A3@intrepid> > From: Gandalf [mailto:gandalf at geochemsource.com] > > > Oh yes, I know about this. But it seems it is working on > Linux and Windows only. I have Solaris, FreeBSD and AS/400 > clients too. > :-( AS/400 clients? '400s don't have *any* sound support at all, so good luck with that one. ;-) Cheers, Simon B. simon at brunningonline.net http://www.brunningonline.net/simon/blog/ ----------------------------------------------------------------------- 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 dave at pythonapocrypha.com Thu Aug 26 14:33:57 2004 From: dave at pythonapocrypha.com (Dave Brueck) Date: Thu, 26 Aug 2004 12:33:57 -0600 Subject: Best processor (i386) for Python performance? In-Reply-To: References: <412dfb17$0$65599$a1866201@newsreader.visi.com> Message-ID: <412E2D15.3060600@pythonapocrypha.com> David Bolen wrote: > I don't doubt the performance gains, but I'd argue that if you are > seeing that sort of improvement, then you clearly don't have an I/O > bound program at all, but a compute bound one. Ugh, yes. Thanks for the correction! The application in question was an object layer in front of a database - it spent most of its time pickling and unpickling objects, so the bulk of the performance gains probably came from the database speeding up (it was on the same box). >>But then again very few of the projects I work on end up having CPU as >>the most scarce resource so the machines that do have multiple CPUs >>are that way because they are running oodles of other processes as >>well. > > This is an excellent point since even if the only advantage to the > extra CPUs was to free up more of a single CPU for a Python > application, you'd still see a net gain for that application when > running in its real world environment. Good call. Thanks, Dave From ken at perfect-image.com Tue Aug 3 18:38:25 2004 From: ken at perfect-image.com (Ken Godee) Date: Tue, 03 Aug 2004 15:38:25 -0700 Subject: PyQt - clear widget for redraw In-Reply-To: <410fad7d@news.maxnet.co.nz> References: <410b4492@news.maxnet.co.nz> <410bf265@news.maxnet.co.nz> <410d0699@news.maxnet.co.nz> <410fad7d@news.maxnet.co.nz> Message-ID: <411013E1.7080605@perfect-image.com> Peter wrote: > Yes - tried that, but gives incomplete draw / flicker. > > More details: > the idea is to provide a graphics demo of sort algorithms for my 13 year old > son. A number of lines of differring lengths are shown on the screen, and > you can watch as these are sorted, step by step. So you can see the > difference between bubble sort, ripple sort, etc. > Code copied below. > Improving the smoothness of the display is the main thing I'm after. > > def refresh(self): > self.LCDcount.display('%3d' % cComp) # update counters > self.LCDswap.display('%3d' % cSwap) > self.frame4.erase() # clear any old lines > p = QPainter(self.frame4) > mar = self.frame4.width()/100 # margin > vsp = 2 # vertical spacing > hrz = (self.frame4.width()-2*mar)/100 # horizontal scalar > p.setPen(QColor("black")) > for i in range(100): > p.drawLine(mar,mar+vsp*i,hrz*(l1[i]+1),mar+vsp*i) > p.setPen(QColor("blue")) > p.drawLine(mar,mar+vsp*b1-1,hrz*100,mar+vsp*b1-1) > p.drawLine(mar,mar+vsp*b2-1,hrz*100,mar+vsp*b2-1) > p.setPen(QColor("red")) > p.drawLine(mar,mar+vsp*r1+1,hrz*100,mar+vsp*r1+1) > p.drawLine(mar,mar+vsp*r2+1,hrz*100,mar+vsp*r2+1) > To me it would seem the problems lies in the refresh routine, you're erasing and then redrawing, a viewed object, this will cause it to flicker around, even worse if using sizers. There's probally a better way to do this, but when I've been faced with this type of problem here's what I would try and maybe it will help you or give you a different way to look at it. I'd create a clone of frame4, maybe frame5, only viewing one at a time. In my refresh routine I'd create some type of loop and alternate them using .hide() .show() and only do my drawing/erasing on the hidden object. I think anyway you do it, you should only draw/erase on a hidden object, you could also have frame4 and 5 be the same, but in the routine that calls refresh, .hide() 4, .show() 5, refresh then redraws 4, and on returning from refresh, .hide() 5, .show()4. Anyway I thing you get the idea. Just something I'd try. From anthonybaxter at gmail.com Fri Aug 13 02:49:53 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 13 Aug 2004 16:49:53 +1000 Subject: decorator syntax polling suggestion In-Reply-To: References: <411BF3FC.71051A6F@alcyone.com> Message-ID: On Thu, 12 Aug 2004 23:12:56 -0400, Peter Hansen wrote: > On the other, if there are people who are dissatisfied with > @pie, they can vote, use the results to help them focus > their energies on the most likely alternate candidate(s), > and finally present a united front saying "uh, @pie > sucks, and we have a wide consensus that syntax XXXX > would be much better for these reasons..." But then you end up with the opposite problem - a pile of people say "we want this one" (say, list-before-def), it's implemented, then all the people who prefer pie-decorators start jumping up and down. I don't think there's as wide a concensus as I keep hearing about. The people who hate pie-decorators post a _lot_ - most people seem to either not care, or else post once or twice and then disappear. I think I'm about the only person posting in any volume to c.l.py in favour of the syntax, and even then, my liking of it is also driven by a dislike of the other proposed syntaxes. Anthony From aleaxit at yahoo.com Thu Aug 26 17:01:48 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 23:01:48 +0200 Subject: Newbie question on dictionary!!! References: <494182a9.0408261150.a4c767f@posting.google.com> Message-ID: <1gj5d7h.w60mtvmxup0hN%aleaxit@yahoo.com> Balaji wrote: > Hello everybody... > > I want to ask a simple question. > > Suppose I have an list say g=['a','b','c','d'] > > and I have an dictionary say k={'b':20,'a':10} > > Now I want to sort this dictionary on the basis of the list and if it > doesnt find any of the element in the list then I wud like to replace > it with zero.. > > so I would like to modify k into {'a':10,'b':20,'c':0,'d':0} If you want to end up with a dictionary, the 'sorting' part is moot. Dictionaries use hashing -- NO order whatever, thus sorting just can't apply, can't have any sense nor meaning whatsoever in context... you might as well talk of coloring or flavouring or housetraining a dictionary as you might of sorting it. You can build the dictionary you require (but it will have no ordering whatsoever, being a dictionary) with dict([ (x, k.get(x, 0)) for x in g ]) (in Python 2.4 you may fruitfully omit those brackets). Alex From trentm at ActiveState.com Tue Aug 31 11:43:49 2004 From: trentm at ActiveState.com (Trent Mick) Date: Tue, 31 Aug 2004 08:43:49 -0700 Subject: Intelisence (and type inference) In-Reply-To: ; from ville@spammers.com on Tue, Aug 31, 2004 at 10:27:19AM +0300 References: <43SYc.121080$UTP.113615@twister01.bloor.is.net.cable.rogers.com> Message-ID: <20040831084349.H16807@ActiveState.com> [Ville Vainio wrote] > Yes, it's non-trivial, but why is it so hard? I mean, what's the > killer problem about type inference? I'm not talking about Starkiller > level type inference (which has to be just right, because the code is > actually executed) but the kind that would support IDEs for developers > that use python in a reasonably standard way: > > - Modules are imported from standard places Handling imports (and "from foo import *") and all variable assignments and customized sys.path's and all scoping rules and perhaps some basic flow analysis: if foo == 1: return else: return Basically it just adds up. The real problem is doing this efficiently for large libraries and for changing documents as the user types in the IDE. > - Ambiguous methods are annotated somehow (e.g decorators ;-). There is no agreement in the community on how to do that. Failing that, IDE authors are left with using one of the many suggestions out there (most involve marking up docstrings in certain ways) or coming up with their own. > In cases where a name can be bound to instances of multiple different > classes, suggest all the methods for completion: Yup, some of that is done. It is not impossible, but it _is_ hard. :) Trent -- Trent Mick TrentM at ActiveState.com From anthonybaxter at gmail.com Tue Aug 31 03:04:21 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Tue, 31 Aug 2004 17:04:21 +1000 Subject: how to get size of email attachment In-Reply-To: <9afea2ac040830140866f46714@mail.gmail.com> References: <63b5e209.0408301105.58b9207a@posting.google.com> <9afea2ac040830140866f46714@mail.gmail.com> Message-ID: On Mon, 30 Aug 2004 22:08:42 +0100, Tim Williams (gmail) wrote: > On 30 Aug 2004 12:05:18 -0700, Joh wrote: > > hello, > > > > i'm looking for a way to get total size of an email (with its attached > > files) using library such as poplib, or ? > > > > can someone help me or give me an url from where to start ? > > thinking aloud and off the top of my head , you could try the email > module (python docs) I put a recipe up on the Python cookbook for stripping out attachments from an email message - you could adapt that to measure the sizes of the attachments pretty easily. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/302086 From rnd at onego.ru Sat Aug 14 01:53:51 2004 From: rnd at onego.ru (Roman Suzi) Date: Sat, 14 Aug 2004 09:53:51 +0400 (MSD) Subject: [Python-Dev] def ... decorate In-Reply-To: <20040813135102.63CF.JCARLSON@uci.edu> References: <20040813104200.63C3.JCARLSON@uci.edu> <20040813135102.63CF.JCARLSON@uci.edu> Message-ID: (I am resending it to c.l.p because I think it belongs there) On Fri, 13 Aug 2004, Josiah Carlson wrote: >You must be joking. Just because a signature can change doesn't mean >that the signature is not important. > >I'll say it again, just in case you missed it the first time, the first >major use of decorators are going to be in PyObjC, WHICH USES DECORATORS >TO SPECIFY SIGNATURES. > >If you continue to claim that signatures are unimportant, I can't >imagine how this discussion could continue in any sort of a productive >fashion. They are important. What I tried to say is that with decorators they sometime change. It did not happen with plain def-statement. So resulting signature must be in the docstring. > >Generally, describing decoration in terms of a functional approach >is pointless, we already have a functional approach to decorations, >which is what we are trying to remove. ...intead of making definitions squeezable into expression ;-) as in this hypothetic example: f = decorate(def args: body ) >def f(args): > body >f = decorate(f) > >Again, replace @ if desired. > >> I always thought the natural order of definition is value to define first, >> definition to follow it. > >I don't know where this came from, but it is what we already have. >def fun(args): > body Probably, it comes from the math culture. Even HTML reflects this order. Most programming languages also stick to it. > >> lambda a mistake? lambda a mistake... -OX > >Yes, lambda a mistake: >http://www.linuxjournal.com/article.php?sid=2959 Maybe it was mistake to call it "lambda" a in math. But is Windows directories are called folders. Terminology tends to downgrade for laymen. >> >Seemingly in Guido's opinion, @s (or other symbols) were minimal. You >> >can have a humble (or not so humble) opinion, but unless you can >> >convince Guido and/or the community, it is not going to happen (I've >> >been bitten by this myself). >> >> I am pretty sure @-syntax will do it into Python 2.4 and I am also >> sure that nobody will remeber these discussions 1-2 years from now. > >If you are so sure, why continue arguing towards your "J3" syntax (which >is a variation on the syntax Skip proposed)? My mind (and not only mine) is not static. Our discussion changed it. The only way to proof a solution is good is by having two or more opposite opinions. >> I wonder WHAT Python looked like if it's community discussed >> EVERY syntax feature it had before 1.5.2. My feeling is Python >> still missed IF-THEN-ELSE... >You are moving off-topic. Just minor procedural note ;) >> GvR already decided on the syntax. His brain has already >> calculated all those millions of possibilities (moves), >> community response included. We have almost zero chance to >> find better syntax for decorators. >Considering that you were, earlier today, offering a different syntax, >this seems quite out of character for you. See note above. >I am not aware of decorators in other languages, but I have kept my nose >out of most langauges developed since I discovered Python in 2000. This is limiting your experience. In the same period I learned Ocaml alittle where function signatures are part of type. Ocaml intrest me because it has an efficient compiler (on par with C) but much less typing/functionality ratio. >> Aren't decorators functional programming everyday feature, when >> (in some programming languages) it is normal to define function as >> a superposition of simpler ones? > >That is like saying that all programming is functional. Is prolog a >functional programming language? No, it is a logic programming language, >yet it is common in Prolog to see the following: > >my_and(a, b) = my_bool(a) and my_bool(b) Not sure hat you wanted to express, but I wanted to say that in FP languages decorators do not require special syntax as they are just normal expressions involving function transformations. Well, LISP doesn't require special syntax for any feature . P.S. I feel tired by this discussion. And it is c.l.p one, not python-dev. As we do not have enough ON TOPIC points of disageement, I do not want to continue. Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3 From Scott.Daniels at Acm.Org Sat Aug 28 12:43:09 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 28 Aug 2004 09:43:09 -0700 Subject: What GCC version had defined? In-Reply-To: <412eca05$0$24800$9b622d9e@news.freenet.de> References: <412e39d1$1@nntp0.pdx.net> <412E55A9.9070400@v.loewis.de> <412e70d3$1@nntp0.pdx.net> <412eca05$0$24800$9b622d9e@news.freenet.de> Message-ID: <4130b79a$1@nntp0.pdx.net> Martin v. L?wis wrote: > Scott David Daniels wrote: > >> I'd like to change it to something like: >> ... >> #if _MSC_VER > 1200 >> #define HAVE_UINTPTR_T 1 >> #define HAVE_INTPTR_T 1 >> #endif >> ... >> #if GCC_VERSION >= 30100 >> #define HAVE_UINTPTR_T 1 >> #define HAVE_INTPTR_T 1 >> #endif >> ... >> which is arguably better even if not good enough. > That won't help at all. PC/pyconfig.h is used only > on Windows, not on Linux. On Linux, configure is run > to detect presence of things. Ah -- but my problem (which I was remiss in not describing well enough) is just that I cannot compile _at_ _all_ on the Windows box with minGW. I don't give a whit about except to try to make sure the proper definition happens. I'd like the following extension to compile for 2.4 (it won't now) with MinGW: #include static PyMethodDef xyzMethods[] = { {NULL, NULL, 0, NULL} /* Sentinel */ }; #if defined(PyMODINIT_FUNC) PyMODINIT_FUNC #else void #endif initxyz(void) { PyObject *module = Py_InitModule("xyz", xyzMethods); PyModule_AddStringConstant(module, "test", "value"); } The error is roughly: In file included from C:/python24/include/Python.h:55, from xyzmodule.c:1: C:/python24/include/pyport.h:69: parse error before "Py_uintptr_t" C:/python24/include/pyport.h:69: warning: type defaults to `int' in declaration of `Py_uintptr_t' C:/python24/include/pyport.h:69: warning: data definition has no type or storage class C:/python24/include/pyport.h:70: parse error before "Py_intptr_t" C:/python24/include/pyport.h:70: warning: type defaults to `int' in declaration of `Py_intptr_t' C:/python24/include/pyport.h:70: warning: data definition has no type or storage class error: command 'gcc' failed with exit status 1 That is, I don't even get to my _own_ broken code. >> #if _MSC_VER > 1200 >> #define HAVE_UINTPTR_T 1 >> Is there a better test I can do at compile time? > > Depends on what you want to test for. If it is > presence of stdint.h, you should test for > HAVE_STDINT_H. > > Regards, > Martin How is this as a change: From this: #ifdef MS_WIN32 ... /* VC 7.1 has them and VC 6.0 does not. VC 6.0 has a version number of 1200. If some compiler does not provide them, modify the #if appropriately. */ #if _MSC_VER != 1200 #define HAVE_UINTPTR_T 1 #define HAVE_INTPTR_T 1 #endif #endif To this: #ifdef MS_WIN32 ... /* VC 7.1 has them and VC 6.0 does not. VC 6.0 has a version number of 1200. If some compiler does not provide them, modify the #if appropriately. */ #if _MSC_VER > 1200 #define HAVE_UINTPTR_T 1 #define HAVE_INTPTR_T 1 #elif HAVE_STDINT_H #define HAVE_UINTPTR_T 1 #define HAVE_INTPTR_T 1 #endif #endif Or if HAVE_STDINT_H is defined under VC 7.1 (I cannot check that) perhaps the change should become: #ifdef MS_WIN32 ... #if HAVE_STDINT_H #define HAVE_UINTPTR_T 1 #define HAVE_INTPTR_T 1 #endif #endif In any case, thanks for the help so far. -Scott David Daniels Scott.Daniels at Acm.Org From david_brownell at hotmail.com Tue Aug 24 02:11:34 2004 From: david_brownell at hotmail.com (David Brownell) Date: 23 Aug 2004 23:11:34 -0700 Subject: py2exe, PyXML, and utf-16-be Error References: <67e04df1.0408230913.3c12f1a8@posting.google.com> Message-ID: <67e04df1.0408232211.2f8b7bcd@posting.google.com> Thanks, Thomas, that did the trick. From jjl at pobox.com Mon Aug 9 19:53:42 2004 From: jjl at pobox.com (John J. Lee) Date: 10 Aug 2004 00:53:42 +0100 Subject: Parsing broken HTML via Mozilla References: Message-ID: <87r7qflvg9.fsf@pobox.com> Walter D?rwald writes: [...] > way to get proper XML out of Mozilla? Calling mozilla on the > command line would be OK, but it would be better if I could > use Mozilla like a SAX parser. Is there any project that > provides this functionality? [...] PyXPCOM. Good luck compiling it. John From aleaxit at yahoo.com Sat Aug 28 02:44:18 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 28 Aug 2004 08:44:18 +0200 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <7xzn4gwgea.fsf@ruckus.brouhaha.com> <1gj7a1o.1a5d2q410jsn2kN%aleaxit@yahoo.com> <7xisb4xnh5.fsf@ruckus.brouhaha.com> Message-ID: <1gj7c1a.tfdm14p3hclcN%aleaxit@yahoo.com> Paul Rubin wrote: > aleaxit at yahoo.com (Alex Martelli) writes: > > I know of no reason to forbid support for such "signing", no. If you > > want to offer a patch to zipimport to let it support whatever signing, > > encryption, or other devilry appeals to you, this is definitely the > > right moment if you hope to see it happen in Python 2.4. > > I think the simplest is to just have zipimport understand jar files > and their signatures. There's enough supporting infrastructure needed > that getting it in 2.4 is probably asking a bit much, though. > > > If you mean patching zipimport to _forbid_ importing from any zipfile > > whatsoever, including a plain vanilla one, I think it's too late for > > THAT for Python 2.4 > > If signing is supported, then there has to be a way to reject imports > whose signatures don't verify. It could be a runtime option or > something, I guess. How does zipimport work anyway? I don't see it > in the library doc index for 2.3. While the overall way the new import hooks work is well documented in their PEP, zipimport is admittedly underdocumented. I suggest peeking at the Python source distribution, files: dist/src/Modules/zipimport.c dist/src/Lib/test/test_zipimport.py The excu^H^H^H^H reason for the documentation scarcity, you can read at the end of the docstring for zipimport...: """ It is usually not needed to use the zipimport module explicitly; it is used by the builtin import mechanism for sys.path items that are paths to Zip archives. """ Alex From squirrel at WPI.EDU Tue Aug 3 15:40:10 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 3 Aug 2004 15:40:10 -0400 Subject: executing python programs as if they were on OS path (noob) In-Reply-To: References: Message-ID: On Tue, 3 Aug 2004, Darren Dale wrote: > Is there a place to put python programs so I dont have to refer to the > absolute path everytime I want to call them? For example: > > if I am in /home/me and want to execute: > > python /home/me/python/export.py temp.dat > > what could I do so this will work: > > python export.py temp.dat The easiest way to do this is to make the script executable directly: 1) Add the line '#!/usr/bin/env python' or '#!/path/to/python' (usually /usr/bin/python or /usr/local/bin/python) to the top of your script, as for a shell script. 2) Set your script's executable bit using 'chmod a+x'. 3) Stick your script, or a link to it, in something touched by the PATH environment variable (such as /usr/local/bin) or, if you prefer, add your script's directory to PATH (with a line like 'export PATH=~/my/script/directory:$PATH' in your .bashrc file). Then you can execute your script just by specifying its name. From theller at python.net Thu Aug 12 11:27:33 2004 From: theller at python.net (Thomas Heller) Date: Thu, 12 Aug 2004 17:27:33 +0200 Subject: Developing a Tool Band for IE in Python References: Message-ID: <4qn8e5qy.fsf@python.net> fischerlaender at gmx.de (Stefan Fischerl?nder) writes: > After searching Google and Google Groups for several hours I did not > find an answer to my question. > > Is Python suitable for developing a tool band (something like the > Google Toolbar) to be placed in the Internet Explorer's rebar? Does > anyone even have any tutorial or something similiar? > > Thank you very much. > Stefan ctypes (0.9.0) recently got a toolband sample - although currently it's only an empty template displaying a button. Thomas From f.geiger at vol.at Fri Aug 6 02:16:28 2004 From: f.geiger at vol.at (F. GEIGER) Date: Fri, 6 Aug 2004 08:16:28 +0200 Subject: [py2exe.i18n] English works, German works, but not French. What do I miss? Message-ID: When I start a py2exe-ed application I get the error 'ascii' codec can't encode character u'\xe9' in position 10: ordinal not in range(128) This is how I run py2exe: setup.py py2exe -O1 --packages encodings This is how the .po-file looks like: # SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR ORGANIZATION # FIRST AUTHOR , YEAR. # msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "POT-Creation-Date: Sun Jul 18 13:44:27 2004\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=ISO8859-1\n" "Content-Transfer-Encoding: ISO8859-1\n" "Generated-By: pygettext.py 1.5\n" #: ..\..\..\MainFrame.py:97 msgid "Could not connect to database: %s. " msgstr "Impossible de se connecter ? la base de donn?es: %s. " etc. However, the English and German language versions works. The German version works since I added "--packages encodings" to the call to py2exe. I thought this would cover all Western European languages. What do I miss? Many thanks in advance Franz GEIGER P.S.: The language switch ing in my app is done this way: languageCode = Settings().value("GUI", "Language") _Logger.debug(thisName + "(): Settings say language is '%s'. " % languageCode) try: if "de" == languageCode: _Logger.debug(thisName + "(): Switch messages.mo to 'de'. ") gettext.translation('messages', 'Texts', languages=["de"], fallback=True).install(unicode) elif "fr" == languageCode: _Logger.debug(thisName + "(): Switch messages.mo to 'fr'. ") gettext.translation('messages', 'Texts', languages=["fr"], fallback=True).install(unicode) else: _Logger.debug(thisName + "(): Switch messages.mo to 'en'. ") gettext.translation('messages', 'Texts', languages=["en"], fallback=True).install(unicode) except Exception, e: _Logger.exception("An exception occurred: %s. " % e) From benn at cenix-bioscience.com Tue Aug 17 07:10:14 2004 From: benn at cenix-bioscience.com (Neil Benn) Date: Tue, 17 Aug 2004 13:10:14 +0200 Subject: serial and threads In-Reply-To: <39ba6e78.0408170215.59f5bfc0@posting.google.com> References: <39ba6e78.0408170215.59f5bfc0@posting.google.com> Message-ID: <4121E796.1040407@cenix-bioscience.com> Silke wrote: >Hi all! > >I'm trying to write a program in python using the modules >'serialwin32' and 'thread' to create one thread that writes to a > > > Hello, I've done a similar implementation, I always assume that - unless the documentation for a class specifically states that it is thread-safe then I assume it isn't. The way I get around the issue you have is to lock access to the serial object (s in your case). The way I get around this is to use the InWaiting method (or whatever the equivalent will be in your serial module) which will return how many bytes are waiting, then I can read that number of bytes from the serial port, store the information and release the lock on that port. : self.__objLock.acquire() try: intNoChars = self.__objSerialPort.inWaiting() if (intNoChars > 0): strReceivedString = self.__objSerialPort.read(intNoChars) self.newMessage(strReceivedString) self.__objLock.release() except: self.__objLock.release() raise Obviously you will also want to lock on all other access to the port, close, open, write, etc. P.S. Please don't start ranting about my use of Hungarian!! Cheers, Neil -- Neil Benn Senior Automation Engineer Cenix BioScience BioInnovations Zentrum Tatzberg 47 D-01307 Dresden Germany Tel : +49 (0)351 4173 154 e-mail : benn at cenix-bioscience.com Cenix Website : http://www.cenix-bioscience.com From cito at online.de Thu Aug 12 15:12:24 2004 From: cito at online.de (Christoph Zwerschke) Date: Thu, 12 Aug 2004 21:12:24 +0200 Subject: multiline snippets with triple quotes Message-ID: I sometimes use triple quotes in order to produce snippets of multiline code, like that: if output == html: snip = ''' Hello, World

    What's up?

    ''' else: snip = 'Hello!' This has the advantage that you don't need to care for inserting newlines and escaping quotes and is very readable. However, the triple quoted strings will also contain the indentation of the Python block. It would not really matter here, since whitespace is ignored in this case, but there could be situations where whitespace at the beginning of the lines would matter, and it simply makes no sense to carry over the identation in most cases. Of course, I could simply unindent the triple quoted snippets, but then the Python code starts to become unreadable, if you have many of such snippets in deeply indented blocks. And isn't bad indentation something that Python usually forbids "by force" even? So, what would be the pythonic way to implement such multiline snippets? Gtx Chris From bokr at oz.net Tue Aug 10 20:56:33 2004 From: bokr at oz.net (Bengt Richter) Date: 11 Aug 2004 00:56:33 GMT Subject: measuring 1/100th seconds, what function? References: Message-ID: On Tue, 10 Aug 2004 17:30:14 -0400, Peter Hansen wrote: >Jonas K?lker wrote: > >> I'm doing a Rubik's Cube timer, so I need a function to measure 100ths of >> a second. I've browsed through the library reference of python.org, but I >> didn't find anything that struck me as 'the perfect fit'. Either it was >> system dependent, or it was too grainy (lo-res), or... something else. > >It usually helps to specify what you looked at, and perhaps why you >didn't think it was acceptable, to avoid us retracing your steps... > >> so, I need a function which satisfies (in order of importance): >> >> 1. It can be used to measure time in the range of up to approximately 1 >> minute with an accuracy down to 100th-seconds (that's 60000~65536 >> different values). Better accuracy is a bonus, longer time-frame is a >> bigger bonus. >> >> 2. it must run on any version of windows upon which python 2.4 can run > >These two constraints cannot be met simultaneously, I believe. >Windows98 does not provide adequate resolution in the timer. > >If you are willing to forego Win98 and use only the real Windows OSes, >then I think you get roughly (?) 10ms resolution already with >time.time(). Linux probably gives 1ms resolution or better in pretty >much all cases with time.time(). > On windows I like to use time.clock() For NT4 with python 2.3.2 (yeah I ought to upgrade both ;-) >>> from time import time,clock >>> min(filter(None,[-(time()-time()) for i in xrange(100000)])) 0.0099999904632568359 >>> min(filter(None,[-(clock()-clock()) for i in xrange(100000)])) 5.8666657594130811e-006 IOW, time apparently gets the NT4 basic os time slice delta (10ms), whereas clock tries to get something better (and it's pretty good). The filter call is because time()-time() makes a lot of zeroes. clock() is fast enough not to require it. Not one zero in 100k, anyway. >>> min([-(clock()-clock()) for i in xrange(100000)]) 5.8666656741479528e-006 And that's not the minimum resolution of the timer clock() uses, it's near the minimum time between two readings you can get from python. Maybe some other loop mechanism can get two two samples faster and then subtract them. A game for someone ;-) Regards, Bengt Richter From newsgroups at jhrothjr.com Thu Aug 19 21:15:56 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Thu, 19 Aug 2004 21:15:56 -0400 Subject: PEP 318: Can't we all just get along? References: <20040817181725194-0400@braeburn.themorgue.org> <10i9msuatli5p84@news.supernews.com> <10ia3aa8j6tbma5@news.supernews.com> Message-ID: <10iak82as5fqk3d@news.supernews.com> "Michael J. Fromberger" wrote in message news:Michael.J.Fromberger-AE7E18.17313219082004 at localhost... > In article <10ia3aa8j6tbma5 at news.supernews.com>, > "John Roth" wrote: > > > "Michael J. Fromberger" wrote > > in message news:Michael.J.Fromberger-D24476.14010119082004 at localhost... > > > In article <10i9msuatli5p84 at news.supernews.com>, > > > "John Roth" wrote: > > > > > > > In other words, forget the use cases. They're irrelevant. > > > > > > On this point, I strongly disagree. If you don't have a use case, there > > > is no point whatsoever in arguing about the syntax of a feature. > > > > There is a use case. If you go back and read the original > > post I was replying to, it contains the sentence: > > > > [begin quote] > > I guess others had bigger plans for my proposal that I had planned. It > > has turned into the "solution" to many problems: type checking (both > > arguments and returned values), metaclasses, metadata, interfaces, > > function attributes, etc.). > > [end quote] > > Ah, I see. I misunderstood your intent. My apologies. > > Nevertheless, I think it's clear the Python community at large ought to > have a clearer idea of exactly what the use cases ARE (and, more > importantly, what they're not) before deciding on a syntax. It's not > clear to me that there's consensus on purpose yet (as witness the wildly > divergent ideas that have accumulated on the wiki, comp.lang.python, and > python-dev). I don't think they're particularly related. Functionally, whatever happens as the result of a decorator will be the return of an object which will be bound to the class or module (or serve as the input to another decorator, of course.) In most cases, this will either be the original input or a descriptor that has the original input as an attribute. This is a very generic mechanism of amazing simplicity. It can be put to as many uses as one wishes. There are currently implementations of just about everything that has been suggested, including Design by Contract, Aspects and several forms of type checking. The whole question of syntax is simply orthogonal. The current syntax works perfectly well; it's just very poor from an intention revealing standpoint. John Roth > > Cheers, > -M > > -- > Michael J. Fromberger | Lecturer, Dept. of Computer Science > http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From tim.hochberg at ieee.org Tue Aug 17 11:48:52 2004 From: tim.hochberg at ieee.org (Tim Hochberg) Date: Tue, 17 Aug 2004 08:48:52 -0700 Subject: Python indentation deters newbies? In-Reply-To: <10i2st1h94pqm2d@corp.supernews.com> References: <3064b51d.0408130615.3fc4a760@posting.google.com> <41214271_1@127.0.0.1> <41215667$1_1@127.0.0.1> <10i2st1h94pqm2d@corp.supernews.com> Message-ID: Jeff Shannon wrote: > beliavsky at aol.com wrote: > >> You may want to exit a nested loop when testing if a condition involving >> several variables is met, such as searching for a zero of a multivariate >> function. >> In Python you can print i,j,k and exit() when m == 0, but in a larger >> program >> you may want more control. >> >> > > In this case, I can see several Pythonic ways of doing this. > > One would be to use an exception. While exceptions are not considered > good control structures in other languages, they *are* considered > acceptable (and even desirable) in Python. > > Another way would be to wrap the nested loops inside a function, and > simply return the appropriate triple from that function as soon as you > find it. > > An improvement on that would be to replace your return statement with a > yield. Suddenly you've got a generator that'll find a whole series of > Pythagorean triples! > [SNIP perfectly good Pythag. triple generator] Just for fun, here's one that will spit out as many reduced pythagorean triples as you care to look at. -tim def gcd(a, b): # Euclidean alg. assert (b > 0) and (b > 0) if a < b: a, b = b, a while b: a, b = b, a % b return a def rptriples(): "generate reduced pythagorean triples" # Based on formulae from Mathworld, corrected by one from # planetMath. v = 1 while True: u = 1 + (v%2) # u must be opposite parity from v while u < v: if gcd(u,v) == 1: u2, v2 = u*u, v*v a, b, c = v2-u2, 2*u*v, u2+v2 if a > b: a, b = b, a yield a, b, c u += 2 v += 1 From nhodgson at bigpond.net.au Thu Aug 19 18:58:46 2004 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Thu, 19 Aug 2004 22:58:46 GMT Subject: SciTE as editor for Python: No print formatting under LINUX. References: <4124ad63.349803125@news.compuserve.de> Message-ID: Konrad Koller: > Under Windows print formatting (header, footer etc.) is OK. Under > LINUX it does not work. SciTEGlobal.properties state around line 352: > > # Printing - only works on Windows > > Why? How is print formatting determined under LINUX (PLAT_GTK)? On Windows, the same API is used for drawing to the screen and printer so SciTE performs printing itself. GTK+ doesn't provide a printing API so SciTE calls an external application, with the default being a2ps set by command.print.*=a2ps "$(FileNameExt)" Neil From tuanglen at hotmail.com Thu Aug 5 04:36:33 2004 From: tuanglen at hotmail.com (Tuang) Date: 5 Aug 2004 01:36:33 -0700 Subject: saving streaming audio to disk Message-ID: Given a URL for an MP3 audio stream, how could I write a little utility that would start the stream flowing, capture it to a disk file, and then disconnect from the stream? I'm imagining that, for example, if I save an hour-long chunk taken out of an MP3 audio stream, I would get an hour-long MP3 file on my hard drive. I'd prefer to use Python, but I'm not sure where to start. Thanks for any tips. From danb_83 at yahoo.com Sun Aug 8 03:42:09 2004 From: danb_83 at yahoo.com (Dan Bishop) Date: 8 Aug 2004 00:42:09 -0700 Subject: Mailing lists Message-ID: Has anyone here implemented a mailing list server in Python? From john at grulic.org.ar Mon Aug 30 16:31:57 2004 From: john at grulic.org.ar (John Lenton) Date: Mon, 30 Aug 2004 17:31:57 -0300 Subject: Search for AVI file? In-Reply-To: References: Message-ID: <20040830203157.GA10271@grulic.org.ar> On Mon, Aug 30, 2004 at 10:12:04PM +0200, Peter Kleiweg wrote: > John Doe schreef: > > > I realise that this is not really a python question, but python's the > > only language I'd be comfortable trying to deal with this. > > > > What I need is to search a drive and find all the AVI format files > > that are NOT listed with the AVI extension. I'm looking over an old > > drive of mine from an old computer. I know the files were renamed > > with the wrong extension, but I know that they were originally AVI > > files. Can python do this for me? Any hints? Anybody have a link to > > something that would already do this? I appreciate any help. > > Use walk() to find all files. Open each file and read in the > first 12 bytes. The last four of those 12 bytes should be > 'AVI ', if I'm not mistaken. Correct. According to file(1)'s database, there are two types of AVI: 0 string RIFF RIFF (little-endian) data [...] >8 string AVI\040 \b, AVI [...] 0 string RIFX RIFF (big-endian) data [...] >8 string AVI\040 \b, AVI (meaning that little-endian AVIs start with 'RIFFAVI ', whereas big-endian start with 'RIFXAVI '). HTH -- John Lenton (john at grulic.org.ar) -- Random fortune: BOFH excuse #10: hardware stress fractures -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From specmark at aol.com Wed Aug 4 12:41:36 2004 From: specmark at aol.com (expecthealth) Date: Wed, 04 Aug 2004 16:41:36 -0000 Subject: Data Warehouse Architect -- West Suburban Chicago Message-ID: JOB DESCRIPTION Data Warehouse Architect (Permanent, Full-Time) ______________________________________________________________________ _________ Position Description: The Data Warehouse Architect is responsible for design, specifications, development, testing and deployment for Oracle data warehouse functionality, reports, extracts and interfaces. Leads small teams of developers to achieve prioritized deliverables. Position Qualifications: (Education, experience and skill levels) ? BS/BA Degree in Computer Science or equivalent ? 2 to 5 years experience implementing Oracle data warehouse solutions ? Experience with the Oracle eBusiness Suite Application version 11i data model ? Experience working with Oracle TARs via Metalink ? Working knowledge of the function of the eBusiness Suite Applications version 11.i ? Strong working knowledge of Oracle Warehouse Builder (OWB), Oracle Reports and Oracle Discoverer reporting and developer tools. ? Strong working knowledge of PL/SQL ? User community contact requires communications skills Position Characteristics: ? Excellent verbal and written communications skills ? Proven problem-solving skills ? Ability to work on multiple tasks and assignments. ? Interact with configurators, DBAs, etc. on coordinated deliverables ? Ability to work with limited supervision ? Maintain appropriate documentation for all designs and development work ? Follow published development methodology and assist in refinements as appropriate ? Resolve Help Desk Tickets as necessary ? Share "on call" responsibilities for after-hours support as required ? Other duties as needed and or assigned SALARY RANGE: $80's, depending on background. Position located in the Western suburbs of Chicago Please forward resumes to: Bill Norris, Manager DIAMOND CONSULTING INC. 630-586-0000 x19 specmark at aol.com From fred at acme.com Sat Aug 21 11:10:09 2004 From: fred at acme.com (Fred) Date: Sat, 21 Aug 2004 17:10:09 +0200 Subject: [newbie] Strange behavior of the re module References: <2ejdi01btug5iskb4ipjpj7eaprd8i7vgm@4ax.com> <4126CFCC.8000609@zephyrfalcon.org> <86hei0prvp55iom91df23tffh04egefeig@4ax.com> Message-ID: <3toei056qnmk8nkesta47mncuh49asscht@4ax.com> On Sat, 21 Aug 2004 14:50:40 +0200, Fred wrote: >That did it :-) Thx a bunch. Mmmm... The above links and hints did teach more about the infamous "blackslash plague", but I'm still stuck because all the examples consider static strings, while I'm building it dynamically by extracting data from a web page through the re module: ---------------------------------------------- import sys import re #1. Extract stuff between BODY tags input = "c:\temp" body = re.search('(.*?)',input,re.IGNORECASE | re.DOTALL) if body: body = body.group(1) print "Body = " + body #2. Insert extracted stuff into template output = "here's the path: " output = re.sub('', body + "", output) print output ---------------------------------------------- I also tried running this before so that the problem would go away, but Python doesn't like it either: body = re.sub(r'\',r'\\',input) The script does run, but Fred. From adurdin at gmail.com Sat Aug 28 18:40:33 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Sun, 29 Aug 2004 08:40:33 +1000 Subject: allowing braces around suites In-Reply-To: <41310350$0$13687$636a15ce@news.free.fr> References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> <87hdqok9i6.fsf@sinken.local.csis.hku.hk> <1rfz68ely9.fsf@rovereto.ifi.uio.no> <876574k7du.fsf@sinken.local.csis.hku.hk> <1r3c28ejis.fsf@rovereto.ifi.uio.no> <41310350$0$13687$636a15ce@news.free.fr> Message-ID: <59e9fd3a0408281540472d6b45@mail.gmail.com> On Sun, 29 Aug 2004 00:12:32 +0200, Christophe Cavalaria wrote: > > Well, there are worse coding conventions than that. Remember that chaining > unbraced if and else if becomes ambiguous. Oh yes. I was bitten again by that just a couple of days ago. I had: if(sometest) do(this); else do(that); And needed another (separate) test for do(this), so naturally changed the code to be: if(sometest) if(othertest) do(this); else do(that); It made me wish I was writing the program in Python -- no silly braces to have to put in there :) From steven.bethard at gmail.com Fri Aug 20 12:52:50 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Fri, 20 Aug 2004 16:52:50 +0000 (UTC) Subject: Decorator keyword options - brainstorming References: <7knVc.4599$Jn5.3074@fe1.texas.rr.com> Message-ID: Michael Sparks rd.bbc.co.uk> writes: > One other thing that jumped out at me is that different syntaxes > probably work better using different keywords. (Partly why I've snipped > decorator syntaxes) Yeah, I noticed that pretty quickly too. It looks though, that, of the suggestions requiring a keyword, only the J syntaxes are getting substantial support. If it seems reasonable to others here, I think we should assume that when we're discussing keyword options here, we're aiming at keywords for the J syntaxes (and most probably J2). Steve From n/a Wed Aug 25 13:31:27 2004 From: n/a (ADE) Date: Wed, 25 Aug 2004 10:31:27 -0700 Subject: Am I on the right path Message-ID: <10ipj908b7p2099@corp.supernews.com> Hi everyone: I was just wondering if this code makes sense to anyone. And if I am writing it correctly, the program seems to keep crashing. I was also wondering if anyone had any pointers. The program is supposed to randomly choose an ip address and try and make a conection on port 80 Cheers to anyone who helps # GENERATE AND TRY AND CONNECT TO RANDOM IP ADDRESS import socket, struct, random RAND = random.random() PORT = 80 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # These two functions aren't mine def dottedQuadToNum(ip): "convert decimal dotted quad string to long integer" return struct.unpack('L',socket.inet_aton(ip))[0] def numToDottedQuad(n): "convert long int to dotted quad string" return socket.inet_ntoa(struct.pack('L',n)) # I Think I understand them HOST = dottedQuadToNum("24.207.19.240") RAND = random.randrange(HOST) HOST = numToDottedQuad(RAND) try: sock.connect((HOST, PORT)) print "connected to " + HOST + " on", print PORT sock.close() except: print "could not connect to " + HOST + " on", print PORT Cheers Thank You Andrew From jimcser at pacifier.com Mon Aug 16 13:01:55 2004 From: jimcser at pacifier.com (Jim Cser) Date: Mon, 16 Aug 2004 10:01:55 -0700 Subject: Numarray: Using sum() within functions In-Reply-To: <20040815142804.GA25402@unpythonic.net> References: <10hsvoka533ci3c@corp.supernews.com> <20040815142804.GA25402@unpythonic.net> Message-ID: <4120E883.8030805@pacifier.com> Jeff Epler wrote: > On Sat, Aug 14, 2004 at 02:07:30PM -0700, Jim Cser wrote: > >>Instead, I'm trying to do something like-- >>def f3(x,y,z): >> for t in range(numT): >> tempval = f1(x,y,z,t) * f2(y,z,t) >> >> outval = sum(tempval,axis = 3) >> return outval > > > Here, "tempval" takes on a series of values during the for loop, then > "sum" is used on value from the final iteration of the loop. > > Perhaps you want something like > def f3(x, y, z): > temps = [] > for t in range(numT): > temps.append(f1(...) * f(...)) > return sum(temps, axis=3) > > Jeff Thanks, that works, although someone gave me one that is faster: def f3(x,y,z): tempval = 0.*x for t in range(numT): tempval += f1(x,y,z,t) * f2(y,z,t) return tempval In either case, unfortunately, looping over t is extremely slow. Ideally, there would be a way to use fromfunction() with slices as arguments. -Jim From andrew.jewell at upm-kymmene.com Tue Aug 31 10:12:59 2004 From: andrew.jewell at upm-kymmene.com (andyj) Date: 31 Aug 2004 07:12:59 -0700 Subject: Changing the decimal separator to a comma Message-ID: <46e5cff0.0408310612.6bb1a610@posting.google.com> I've tried using the locale module to set the locale correctly, but all I get is "Error: unsupported locale setting". I'm not actually sure what the proper setting should be; I think it's "fi" for Finland, but this is what I get when I try (under py 2.2): >>> locale.setlocale(locale.LC_ALL,"fi") Traceback (most recent call last): File "", line 1, in ? File "/usr/python2.2.2/lib/locale.py", line 372, in setlocale return _setlocale(category, locale) locale.Error: locale setting not supported Under 2.3 the call succeeds but makes no difference to the decimal point (which should be a comma for Finland): >>> locale.setlocale(locale.LC_ALL,"fi") 'Finnish_Finland.1252' >>> 0.123 0.123 >>> "%10.2f" % 0.123 ' 0.12' The program I'm working on produces database records using a format string, and I'm currently manually tracking all the dp's and replacing them in a loop, just before writing the record to disk, but this is inefficient and inelegant. What I'd *like* to be able to do is specify that we want to use commas for dp's or adjust the locale settings accordingly, then just write the records directly from the format string... regards, -andyj From ian at cottee.org Thu Aug 26 01:24:52 2004 From: ian at cottee.org (Ian J Cottee) Date: Thu, 26 Aug 2004 14:24:52 +0900 Subject: Just a quick one In-Reply-To: References: Message-ID: <1q8002-nal.ln1@suse.zobbo.org> M. Clift wrote: > At the risk of looking stupid would someone mind showing me how this is done > in this case. I can't remove the brackets from (('Bob', 'Mary'), ('Spam', > 'chips')) to give(('Bob', 'Mary', 'Spam', 'chips')) . From what Phil and Sm > said I thought it would be easy. I've tried using list( ). I've had a go at > referencing the individual elements... Noodle around with IDLE (if using windows it should be in your python group). It's a great way to play with this stuff. >>> stuff = (('Bob', 'Mary'), ('Spam', 'chips')) Hmmm - what is stuff? >>> type(stuff) I see. How big is it? >>> len(stuff) 2 Ah ... so ... >>> stuff[0] ('Bob', 'Mary') >>> stuff[1] ('Spam', 'chips') So in that case >>> morestuff = stuff[0]+stuff[1] >>> morestuff ('Bob', 'Mary', 'Spam', 'chips') >>> type(morestuff) >>> evenmorestuff = list(morestuff) >>> evenmorestuff ['Bob', 'Mary', 'Spam', 'chips'] >>> type(evenmorestuff) Well - it got rid of your brackets. But was it what you wanted? Maybe you actually now want. >>> stringstuff = ', '.join(morestuff) >>> stringstuff 'Bob, Mary, Spam, chips' >>> type(stringstuff) Hmmm - getting quite stuff'y in here isn't it? :) Ian From fperez528 at yahoo.com Mon Aug 9 19:32:21 2004 From: fperez528 at yahoo.com (Fernando Perez) Date: Mon, 09 Aug 2004 17:32:21 -0600 Subject: Popular Python projects with lots of pure Python code References: Message-ID: Brett C. wrote: > For my thesis (once the bloody thing stops throwing bugs at me) I am > going to need to collect stats on the frequency that atomic types in > local variables are applied to various opcodes and methods. That means > that I need something to collect stats off of. > > So I am trying to come up with a list of projects I can use to get my > stats from. the stdlib is a no-brainer. Also plan to use Docutils. > But beyond those most of the big Python projects I can think of have a > ton of C code which is of no use to me. I don't need to be able to run > it, just going to be compiling to .py files. > > Any suggestions? well, scipy is not pure python (lots of fortran/C), but it does have a lot of python in it. Given that it's probably a decent representative of typical scientific code (and scientific use of python is growing fast, see scipy'04), it might be an interesting addition to your sample. Best, f From mauriceling at acm.org Wed Aug 25 00:55:52 2004 From: mauriceling at acm.org (Maurice LING) Date: Wed, 25 Aug 2004 04:55:52 GMT Subject: python raw strings? In-Reply-To: <412bc766$1@news.unimelb.edu.au> References: <412bc766$1@news.unimelb.edu.au> Message-ID: <412c1bd4$1@news.unimelb.edu.au> Thanks. I find http://www.amk.ca/python/howto/regex/ to be invaluable in understanding the concepts. maurice Maurice LING wrote: > I'm trying to toy around with PLY (python lex-yacc) by David Beazley > from University of Chicago and realized that the lex module uses python > raw strings. What are python raw strings and how are they different from > regular strings? I've tried to look up in the python documentation but > it just vaguely brushes through by saying that python raw strings are > prefixed with "r" or "R". > > In PLY, "+" is "r'\+'" but "-" is "r'-'", why is there an extra "\" in > "+"? When to use the extra "\" and when not? > > Can someone point me in the correct direction? > > Thanks > Maurice From peter at engcorp.com Tue Aug 17 22:25:14 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 17 Aug 2004 22:25:14 -0400 Subject: No validation routine for an os.path In-Reply-To: References: Message-ID: Edward Diener wrote: > Operating systems do have rules for what constitutes a valid file > specification and/or directory specification. Some even have API functions > which can be called to directly find out. True, but with dynamically loadable extensions to the OS, it seems unlikely that the builtin API for checking filename validity will necessarily handle a completely new filesystem that was created after the OS was released... > Peter Hansen wrote: >>In the end, this is somewhat like validating email addresses. Until >>you actually try and succeed (or fail) to send the message, you cannot >>verify whether an address is "valid" for many definitions of valid. > > I do not totally agree, especially as the OS will know whether something is > valid so it obviously has rules itself. Again, the OS might have rules, but they can't always apply to things that are not really part of the OS, as an add-on might be. I'm sure that in most cases the add-on would not be expanding the set of allowable characters, but it's certainly not unusual for the set to be narrowed. > BTW email addresses actually do have a format which > can be parsed ( RFC 822 originally ), although again it is complicated. I was careful to say "for many definitions of valid". Valid might be as trivial as checking whether it matches a particular format (though I think the term "legal" might be more usual there), but it could also mean "the address actually exists and can receive mail" in which case you really can't know for sure unless you try. In the end, however, I still think the answer to your query is an unfortunate "sorry, not available". -Peter From donnal at donnal.net Mon Aug 23 18:01:21 2004 From: donnal at donnal.net (Donnal Walter) Date: Mon, 23 Aug 2004 17:01:21 -0500 Subject: telnet 'connection reset by peer' In-Reply-To: References: Message-ID: Eddie Corns wrote: > Donnal Walter writes: > > >>Eddie Corns wrote: > > >>>Donnal Walter writes: >>> >>> >>> >>>>On Windows XP I am able to connect to a remote telnet server from the >>>>command prompt using: >>> >>> >>>>telnet nnn.nnn.nnn.nnn 23 >>> >>> >>>>where nnn.nnn.nnn.nnn is the IP address of the host. But using >>>>telnetlib, this code returns the traceback that follows: >>> >>> >>>>import telnetlib >>>>host = 'nnn.nnn.nnn.nnn' >>>>tn = telnetlib.Telnet(host, 23) >>>>tn.read_until("Enter device name?") >>> >>> >>> >>>>Traceback (most recent call last): >>>> File "C:\Python23\Lib\site-packages\mindwrapper\test\telnet.py", line >>>>4, in ? >>>> tn.read_until("Enter device name?") >>>> File "C:\Python23\lib\telnetlib.py", line 316, in read_until >>>> self.fill_rawq() >>>> File "C:\Python23\lib\telnetlib.py", line 521, in fill_rawq >>>> buf = self.sock.recv(50) >>>>socket.error: (10054, 'Connection reset by peer') >>> >>> >>>>Is there some parameter that I need to set in order to connect using the >>>>telnetlib client? Thanks. >>> >>> >>>No, that should work, to a reasonably conforming telnet server. Try doing >>>tn.set_debuglevel(2) before the read_until() to see what's coming back. > > >>Telnet(nnn.nn.nnn.nnn,23): recv >>'\xff\xfb\x03\xff\xfd\x03\xff\xfb\x01\xff\xfd\x1 >>7\xff\xfb\x00\xff\xfd\x00' >>Telnet(nnn.nn.nnn.nnn,23): IAC WILL 3 >>Telnet(nnn.nn.nnn.nnn,23): IAC DO 3 >>Telnet(nnn.nn.nnn.nnn,23): IAC WILL 1 >>Telnet(nnn.nn.nnn.nnn,23): IAC DO 23 >>Telnet(nnn.nn.nnn.nnn,23): IAC WILL 0 >>Telnet(nnn.nn.nnn.nnn,23): IAC DO 0 >>Traceback (most recent call last): >> File "C:\Python23\Lib\site-packages\mindwrapper\test\telnet.py", line >>5, in ? >> tn.read_until("Enter device name?") >> File "C:\Python23\lib\telnetlib.py", line 316, in read_until >> self.fill_rawq() >> File "C:\Python23\lib\telnetlib.py", line 521, in fill_rawq >> buf = self.sock.recv(50) >>socket.error: (10054, 'Connection reset by peer') > > >>Thank you for the suggestion. Can you help me interpret the feedback? > > > The IACs are commands embedded in the data stream. This page: > http://www.scit.wlv.ac.uk/~jphb/comms/telnet.html looks like a decent overview > of how telnet works. The purpose here is to negotiate what the capabilities > of the telnet session (eg echo). Looking at the code in telnetlib, it seems > to always send back DONT or WONT for every option (ie refuses to support or > use any option requested). It's possible the server is deciding that on this > basis it cannot proceed. There doesn't seem to be a single place where all > the telnet options are described so I don't know what 0,1,3,23 actually are. > This page might help: http://home.swipnet.se/cfmd/rfc/dir/telnet.html > You might try using the tn.set_option_negotiation_callback() method to send > your own negotiation messages back if you think that what it is asking for is > harmless (you could snoop on your windows session, eg with ethereal, to see > what windows is sending back). Thank you. Dealing with telnet at this low level is all new to me, so the urls and pointers were helpful. In particular, I downloaded ethereal (also new to me) and filtered the packets by ip address. This way I found that 0 is 'binary transmission', 1 is 'echo', 3 is 'suppress go ahead' and 23 is 'send location' (plus I learned how to send location). > It seems a bit drastic to behave this way but I suppose it depends on what the > server is trying to do. I wouldn't rule out it being a completely different > problem but nothing springs to mind. It may be easier to experiment with > options using a raw socket, copy the code in telnetlib. I still have not decided how I am going to tackle this. My first attempt is likely to be an option_negotiation_callback function as you suggested above. In any case, your suggestions have been most helpful. Thanks, again. Donnal Walter From fumanchu at amor.org Fri Aug 27 12:30:32 2004 From: fumanchu at amor.org (Robert Brewer) Date: Fri, 27 Aug 2004 09:30:32 -0700 Subject: Call for signatories for J2 Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3027BA2@exchange.hqamor.amorhq.net> Anthony Baxter wrote: > Note that Robert has sent the completed proposal to python-dev, > and in fine Python tradition, buggered off for the weekend. > So I'm not entirely sure it's worthwhile posting more > for/against messages now. I'll continue to collect them, and post updates on Monday. So feel free. Now, I'm *really* gone. Robert Brewer MIS Amor Ministries fumanchu at amor.org From anthonybaxter at gmail.com Fri Aug 20 06:38:05 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 20 Aug 2004 20:38:05 +1000 Subject: How to sort this kind of list easily? In-Reply-To: <20040820092940.9FAF61E4003@bag.python.org> References: <20040820092940.9FAF61E4003@bag.python.org> Message-ID: On Fri, 20 Aug 2004 17:03:51 +0800, BruceKL WhoH wrote: > Hi,all > I have a list like [(id,string),...],for example: > > [(1,'xxxxx'),(7,'ppppp'),(4,'gggggg'),...] > > I want to sort this list according to the id of each element. After sorting,the list will become: > > [(1,'xxxxx'),(4,'gggggg'),(7,'ppppp')...] >>> l=[(1,'xxxxx'),(7,'ppppp'),(4,'gggggg'),(2,'ffff'),(12,'hhhhh')] >>> l.sort() >>> print l [(1, 'xxxxx'), (2, 'ffff'), (4, 'gggggg'), (7, 'ppppp'), (12, 'hhhhh')] list.sort sorts tuples by first argument, then second &c. If you want a custom sort order, look at the decorate-sort-undecorate pattern. Anthony From iketo2 at netscape.net Sat Aug 28 23:20:10 2004 From: iketo2 at netscape.net (Isaac To) Date: 29 Aug 2004 11:20:10 +0800 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> <87hdqok9i6.fsf@sinken.local.csis.hku.hk> <1rfz68ely9.fsf@rovereto.ifi.uio.no> <876574k7du.fsf@sinken.local.csis.hku.hk> <1r3c28ejis.fsf@rovereto.ifi.uio.no> Message-ID: <87r7pqwryt.fsf@sinken.local.csis.hku.hk> >>>>> "Igor" == Igor V Rafienko writes: Igor> I am a bit curious, what are the arguments _against_ an Igor> explicit end-of-block marker? Does such a marker create any Igor> problems? (I know that it solves a couple, though). (1) it solves nothing unless it is universally used, (2) universally using explicit braces makes even simple functions long, and (3) long functions are bad because they are hard to comprehend (once you can't put a function into a single screen you lose a lot). I believe the net effect of adding explicit braces is much worse than what we have now. Regards, Isaac. From reply.in.the.newsgroup at my.address.is.invalid Sun Aug 22 19:32:21 2004 From: reply.in.the.newsgroup at my.address.is.invalid (Rene Pijlman) Date: Mon, 23 Aug 2004 01:32:21 +0200 Subject: Python is to C as letters are to words. References: Message-ID: Paul McGuire: >Maybe Gary meant "letters" like when I write a letter to my wife, Do you think he meant performance? How often do you write letters to your wife, and how long does it take you? -- Ren? Pijlman From stnchris at xmission.com Mon Aug 9 18:54:55 2004 From: stnchris at xmission.com (Steve Christensen) Date: Mon, 9 Aug 2004 22:54:55 +0000 (UTC) Subject: Percentage matching of text References: <1678860800.20040730075239@MailBlocks.com> Message-ID: In article , Bruce Eckel wrote: > > What I'd like to do is find an algorithm that produces the results of > a text comparison as a percentage-match. Thus I would be able to > assert that my test samples must match the control sample by at least > (for example) 83% for the test to pass. Clearly, this wouldn't be a > perfect test but it would help flag problems, which is primarily what > I need. > > Does anyone know of an algorithm or library that would do this? Thanks > in advance. > Have you come across the following yet? Levenshtein C extension module for Python: http://trific.ath.cx/resources/python/levenshtein/ And/or: http://hetland.org/python/distance.py -Steve From justin__devine at hotmail.com Mon Aug 30 15:21:06 2004 From: justin__devine at hotmail.com (Justin) Date: 30 Aug 2004 12:21:06 -0700 Subject: Size of a remote URL In-Reply-To: Message-ID: http://www.google.com/search?hl=en&lr=&ie=UTF-8&safe=off&output=search&num=5&q=temp+filetype%3Adoc Go to that URL. The first two search results do not return a Content-Length Header. Yet IE still knows how big they are somehow, whereas my code doesn't. I tried ethereal however the problem is I don't knwo how to read the packets correctly to udnerstand where the requests are. Thanks for the help.. [None, None, '297984', '31744', '23040'] My tuple ends up looking like that. The last three numbers are correct file sizes. From ivan at ivan-herman.net Sat Aug 14 09:27:08 2004 From: ivan at ivan-herman.net (Ivan Herman) Date: Sat, 14 Aug 2004 15:27:08 +0200 Subject: xml question In-Reply-To: References: Message-ID: <411e1322$0$190$cd19a363@news.wanadoo.nl> I think this is a bug in your python call. AFAIK, 'string.strip(str)' *returns a copy of a string with stripped whitespace*. Ie, it does not affect the original string, in this case the nodeValue... Ivan Ajay wrote: > hi! > > i am trying to remove all whitespace elements out of a document. > > my code is below > > def stripWhiteSpaces(doc): > whiteSpaces = xpath.Evaluate("//text()", doc.documentElement) > counter=0 > while(counter< len(whiteSpaces)): > str = whiteSpaces[counter].nodeValue > string.strip(str) > if len(str) == 0: > whiteSpaces[counter].parentNode.removeChild(whiteSpaces[counter]) > > counter += 1 > return doc > > however this isn't working. when i print out all the elements in the > document, i still get the whitespace text elements. > what am i doing wrong? > > thanks > > cheers > > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. From anthonybaxter at gmail.com Mon Aug 23 23:55:14 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Tue, 24 Aug 2004 13:55:14 +1000 Subject: [PATCH] RE: J2 decorator grammar In-Reply-To: <412a4c8f$0$65908$ed2619ec@ptn-nntp-reader01.plus.net> References: <412889c8$0$81159$ed2619ec@ptn-nntp-reader02.plus.net> <412a4c8f$0$65908$ed2619ec@ptn-nntp-reader01.plus.net> Message-ID: On Mon, 23 Aug 2004 20:37:49 +0100, Michael Sparks wrote: > I'm not going to impose anything (hence using SpanishInquisition for easy > search and replace), however personally I'm swayed by "using" right now the > most. (Ideally something like "decorate using" in a single clear word would > be good, but in all likelihood not realistic) "wallpaper" "curtains" "throw_cushions" ... From rogerb at rogerbinns.com Tue Aug 31 17:46:03 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Tue, 31 Aug 2004 14:46:03 -0700 Subject: xmlrpclib References: <413409c3$0$22823$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2hkd02-v7v.ln1@home.rogerbinns.com> <413462a1$0$5242$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: Graeme Matthew wrote: > What I am trying to establish is if the server is asynchronous i.e > multi-threaded i.e what happens when 2 requests hit the server at > once? That depends which server you use. The SimpleXMLRPCServer uses the standard Python SocketServer stuff, so you can do it in as many different ways as you want. > I am trying to find other people who have used it successfully as > most of my dev work is in python. I use xml-rpc, but instead of over HTTP, I actually do it over SSH (using the Paramiko library for the SSH). It works well for cross country/continent stuff. In another project I just use the default one request at a time handler in the Python xmlrpc server end. The client is in PHP running on the same machine. Roger From swheatley at gmail.com Wed Aug 25 13:30:04 2004 From: swheatley at gmail.com (Shawn Wheatley) Date: Wed, 25 Aug 2004 13:30:04 -0400 Subject: Best GUI- Python for children - pygame and blender32 In-Reply-To: References: Message-ID: You may want to try Wax (http://zephyrfalcon.org/labs/) It is a higher level GUI that sits on top of wxPython. This gives your children an easy entry into GUIs, and as they learn more, they can enhance existing programs they have written with more advanced wxPython features. Also, because it is built on wxPython, it should allow integration of PyGame. Sounds like a win-win situation. (Note: I haven't used Wax yet, so I cannot comment on stability. Hans Nowak keeps a weblog of progress at http://zephyrfalcon.org/weblog2/) Shawn On 25 Aug 2004 08:12:48 -0700, Andr? Roberge wrote: > Sorry about the cryptic subject line, but I wanted to capture the > essence of my message in a single line. > > I am learning Python (which, as everyone know is the best language :-) > so that I can write a tutorial to teach my kids about computer > programming. The motivation for them will be to use Python to create > their own games using pygame and, eventually, blender3d. From what I > hear, their friends will be interested in that tutorial too. When/if > I am satisfied with it, I'll make it publicly available (first in > French though - an English translation will have to wait). > > My approach is to use what I called JITT (just in time teaching :-) > i.e. introducing as few concepts as are needed in order to understand > the "next topic", leading to game creation as soon as possible. > > Seems to be working so far. > > I am now at the point of writing a "chapter" on GUIs. I've written a > few sections about Tkinter but I haven't shown them to my kids yet as > I am not convinced this is the best way to go; I've read enough about > anygui, pythoncard, pyui, easygui, not to mention wxpython, etc. to > instill doubts in my mind. I can't really afford to take the time to > learn enough about all of those to make an informed decision on my > own, decision that I could regret later on. As long as the chosen > GUI is as easy as possible to learn but "complete" enough (and fast > enough as an interface?) to do fun stuff with pygame (and, possibly, > blender3d, if a separate GUI is needed), I will be satisfied. > > Any advice would be much appreciated. > > Andr? Roberge > > PS As for the python survey, I'm 43 years old, started learning about > Python about a month ago, have done some programming in the past for > fun using Fortran, C, and java, but haven't done any serious > programming for years and it is not required at all for my day job. > -- > http://mail.python.org/mailman/listinfo/python-list > From donn at drizzle.com Fri Aug 13 23:51:47 2004 From: donn at drizzle.com (Donn Cave) Date: Sat, 14 Aug 2004 03:51:47 -0000 Subject: [OT] Keyboard layout, was Re: PEP318 References: Message-ID: <1092455506.274331@yasure> Quoth Michael Hudson : ... | Huh? On *my* mac @ is shift-2 and # is option-3. What kind of keyboard has a key for @? Donn Cave, donn at drizzle.com From mwh at python.net Tue Aug 3 08:42:32 2004 From: mwh at python.net (Michael Hudson) Date: Tue, 3 Aug 2004 12:42:32 GMT Subject: Importance of C# (was Re: IronPython-0.6 is now available!) References: <278de0e.0407281353.27b6a457@posting.google.com> <7u5tpvap1oh5.1h1v27kmjvf04$.dlg@40tude.net> Message-ID: "Edward Diener" writes: > Tor Iver Wilhelmsen wrote: > > Lawrence Oluyede writes: > > > >> Nesting classes is an unneeded complication, and AFAIK is not pure > >> MI. I think that the only "bare MI support" that Java does have are > >> MI of interfaces... > > > > There is nothing pure about MI. But that's a religious dicussion. > > Python handles it better than C++ at least. > > Why do you say that ? In other words, what in Python's implementation of MI > is superior to C++'s implementation of MI ? Cooperative super calls and the notion of an MRO are *vastly* superior to the horrors of C++. MI with classic classes in CPython kinda sucks in comparison. Cheers, mwh -- "I lacked the courage to investigate the weaknesses of the wicked, because I discovered they are the same as the weaknesses of the saintly." -- The Name Of The Rose, Umberto Eco From uj797 at victoria.tc.ca Tue Aug 17 10:41:54 2004 From: uj797 at victoria.tc.ca (Arthur T. Murray) Date: 17 Aug 2004 06:41:54 -0800 Subject: Mind.py Message-ID: <41220b22@news.victoria.tc.ca> Now, suppose that you wanted to write an AI in Python that would implement your mind-model and allow it to grow, mutate, develop. Here is one possible scenario. It would not be necessary to do all the work yourself. If we began coding a baby Mind.py and published the initial code out on the Web, other Python programmers might start adding to it and start specializing in the refinement of hotspots. http://mind.sourceforge.net/aisteps.html begins with a list of six modules (Security; Sensorium; Emotion; Think; Volition; Motorium) that could be roughed out as a looping chain as in http://mind.sourceforge.net/jsaimind.html -- the JavaScript AI. You or anyone else who disagreed with the choice or naming of the top-level mind-modules could simply web-publish a Mind.py with a different arrangement of mind-modules in Python. Non-global variables could be used, and each coder could web-publish a Table of Mind.py Variables for reference. Although it might seem trivial to web-publish only the initial chain-loop of the cycling mind-modules, one has to start coding AI somewhere, and there might be novice Python programmers who would learn Python by coding AI. [Uh oh; I just got the urge to post this plan on Usenet!] At a certain critical mass, the Python AI code might escape the purview of any single code-maintainer and speciate so widely, so wildly, that Python became the language of choice for all teaching of AI and all early AI implementations. I mean, what are the relative Web-saturations of Python and Perl? Recently on SlashDot or elsewhere I was reading that those who want a job learn Java, while those who want to code, use Python. The idea was that Python attracts those who write the best code. Anyway, once Mind.py code starts appearing on the Web, it may mutate. If not, "Survival of the fittest" sounds its death-knell. But results are not instant. Months or years may first go by. Since I do not know Python, I would keep working on the JavaScript AI, which I would eventually retro-port into the Mind.Forth AI. Now in news:comp.lang.python I will post much of the above text. Sincerely, Arthur T. Murray -- http://mind.sourceforge.net/python.html -- Python AI Weblog From dostatnig at yahoo.com Tue Aug 10 17:03:44 2004 From: dostatnig at yahoo.com (Grzegorz Dostatni) Date: Tue, 10 Aug 2004 15:03:44 -0600 Subject: PyQt + PygreSQL References: Message-ID: I don't know how to set it up using pygresql, but you can do it using qtsql module. Just make sure that qt was compiled with the postgresql support. If you need to use pygresql for some reason, you could always try to have multiple connections to the database from you code (one through qtsql module, another through qtsql). That will probably get very ugly very quickly. Greg On 10 Aug 2004 13:43:05 -0700, Neil Zanella wrote: > > I have the following question. When I instantiate QDataTable with C++ > I must ensure that a database connection is open, and then have no > problems, otherwise I will get popup widgets with errors. > > How can I properly set the default database connection and have > QDataTable find it using the combination of Python + PyQt + PyGreSQL? > > Thanks, > > Neil -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ From del at mjclift.freeserve.co.uk Fri Aug 13 02:21:42 2004 From: del at mjclift.freeserve.co.uk (Calvin79) Date: Fri, 13 Aug 2004 02:21:42 -0400 Subject: while and if References: Message-ID: <78e89de7f43dc55408bc9891b77d06cc@localhost.talkaboutprogramming.com> Hi Satchit, Thankyou for what you've already done, but would you mind if I ask one last thing and then I'll leave you alone? In it's present form the output is fine, but I think I might like to have it output in this format;['c', 'b', 'a', 'd']. It is probably the most basic of questions to ask, but heck I've only been at this python stuff a week... : ) Calvin From brett_gengler at yahoo.com Sat Aug 14 15:00:15 2004 From: brett_gengler at yahoo.com (Brett) Date: 14 Aug 2004 12:00:15 -0700 Subject: tkinter canvas bitmaps w/ xbm formated string data? Message-ID: <9578d4b.0408141100.6b88a7ab@posting.google.com> I'm trying to load a xbm formatted string as a bitmap and draw it to a canvas....I don't have any trouble with loading/displaying xbm files, it's when I've pre-created the xbm as a string I get a 'can't find your bitmap error' xbm_string = "#define arrow_width 1 #define arrow_height 16 static char arrow_bits[] = { 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01 };" a_bitmap = Tkinter.BitmapImage(data=xbm_string) print a_bitmap.width() #prints out 1 print a_bitmap.height() #print out 16 canvas.create_bitmap(100,100, bitmap=a_bitmap) #if I used bitmap="@line.xbm" with the exact same string as defined above, the xbm is displayed correctly. When the create_bitmap executes I get: File "C:\June 5th datamaster\colorlabel.py", line 360, in _createtext self.canvas.create_bitmap(100,100, bitmap=a_bitmap) File "", line 1, in create_bitmap File "C:\Python23\lib\lib-tk\Tkinter.py", line 2057, in create_bitmap return self._create('bitmap', args, kw) File "C:\Python23\lib\lib-tk\Tkinter.py", line 2049, in _create return getint(self.tk.call( TclError: bitmap "pyimage1" not defined ...I have a feeling that I somehow lost a reference to my bitmap object...I'm not sure what's happening. any ideas what could be wrong? Brett From outpost at rumblefish.org Fri Aug 6 10:53:09 2004 From: outpost at rumblefish.org (Thomas D'Tak) Date: Fri, 06 Aug 2004 16:53:09 +0200 Subject: Python milestone releases References: Message-ID: On Fri, 06 Aug 2004 11:54:27 +1000, Anthony Baxter wrote: > > I'm not sure how "2.3" isn't a milestone in any way that's meaningful. > For programmers, I agree. But for other people (server admins etc.), I think, the following would be important: - First of all, it should be mentioned somewhere (in a prominent place, such that even first-time visitors of python.org can find it easily). - Not every release should be a milestone release; milestones should not come more often than maybe every 2 years. (E.g. 2.0 and 2.3 would have been good candidates IMO.) And -even for programmers- the following could be important: - Some kind of support would be needed for the milestone releases, even after the release of other -non-milestone- Python versions; (e.g. bug fixes, backports of important new packages). Martin v. L?wis describes in his follow-up to my original posting, that some of the above did hold for Python 2.2. (But, actually, I was not aware of that.) Th. From kosh at aesaeion.com Fri Aug 13 16:20:00 2004 From: kosh at aesaeion.com (kosh) Date: Fri, 13 Aug 2004 14:20:00 -0600 Subject: Why I love python. In-Reply-To: References: Message-ID: <200408131420.00460.kosh@aesaeion.com> On Friday 13 August 2004 2:03 pm, Christopher T King wrote: > On Fri, 13 Aug 2004, kosh wrote: > > I have seen more then a few cases where a bug like temp file creation > > was found to be a problem in python and in some c code. However the > > difference is that you can update the python runtime and all affected > > python programs are fixed. The same is not true of the c versions. > > What? C programs use a runtime library, just the same as any other > language. Google for "libc.so" or "msvcrt.dll" if you don't believe me. > I do know that c programs can be dynamically linked and most of the time on unixes they seem to be. But it seems to be far too common that the library changes in some way that requires that the program be recompiled. I have seen it with both kde and gnome where just recompiling them with no changes to their code at all fixed library problems that where being reported. I have never seen that kind of thing in python. > > One of them I have run into which is a pain is stuff like openssl. When > > that gets updated it seems a whole bunch of programs have to be compiled > > to work with it again. The change is source compatible but for whatever > > reason the bug fix breaks binary compatibility on a number of apps. > > That sounds like an openssl-specific problem, perhaps relating to > configuration issues. Since C libraries are linked dynamically, source > compatibility inherently translates to binary compatibility, assuming > functions were not moved to different libraries or rewritten as macros (or > vice-versa). > I don't know why they break. I know that they do. > In a perfect world, all OSes would use proper package management systems, > and single-executable programs would not be needed. Unfortunately, this > isn't true. Well in my world everything is written for unixes and deployed on unixes and most of them are linux boxes which have good package systems. From daniel.dittmar at sap.com Tue Aug 10 12:09:54 2004 From: daniel.dittmar at sap.com (Daniel Dittmar) Date: Tue, 10 Aug 2004 18:09:54 +0200 Subject: Decorators proposal References: <19b62f17.0408100741.7f2712ac@posting.google.com> Message-ID: RebelGeekz wrote: > Just my humble opinion: > > def bar(low,high): > meta: > accepts(int,int) > returns(float) > #more code > > Use a metadata section, no need to introduce new messy symbols, or > mangling our beloved visual cleanliness of python. +1 This also allows to set function properties inside of the function def handler (match): meta: pattern = re.compile (...) equivalent to def handler (match): ... handler.pattern = re.compile (...) Daniel From FBatista at uniFON.com.ar Fri Aug 27 11:46:18 2004 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Fri, 27 Aug 2004 12:46:18 -0300 Subject: Call for signatories for J2 Message-ID: [Anthony Baxter] #- Note that Robert has sent the completed proposal to #- python-dev, and in #- fine Python tradition, buggered off for the weekend. So I'm not #- entirely sure it's worthwhile posting more for/against messages now. Yes, it's worthwile. He will add in any new signatories on Sunday night. . Facundo -------------- next part -------------- An HTML attachment was scrubbed... URL: From barnesc at onid.orst.edu Mon Aug 2 18:52:43 2004 From: barnesc at onid.orst.edu (barnesc at onid.orst.edu) Date: Mon, 2 Aug 2004 15:52:43 -0700 Subject: flowcharting is automatic for Python via preprocessor Message-ID: <1091487163.410ec5bb4da9f@webmail.oregonstate.edu> I like your idea. It is easy to get lost inside in eg a multiply nested if statement in a couple multiply nested for loops, inside a try block. Sometimes one can split such code into separate functions, and this makes the code cleaner. Sometimes not. However, the real issue is how the eye parses code. It's really inefficient to scan a whole page of code line by line to understand where loops, branches, continues, and breaks occur. I think your visual diagrams could help, if they are: 1. Semantically cleaner. IMO, there is too much detail in the flow diagrams. (See http://www.getcet.org/images/ex3.png). A minimal amount of detail is easier to parse with the eye. See http://oregonstate.edu/~barnesc/temp/flow.pdf for a cleaner example I came up with. This doesn't have arrows all over the place (and hence may not be a flow diagram), but it does help point out the relevant control structures. 2. Integrated into a code editor. I could see this being a new code editor fad, like collapsable functions and classes. It could be quite useful, if the amount of visual information is kept minimal, so that the coder is not distracted during coding. If the flow diagrams are not integrated into an editor, I don't think many coders will use them. Perhaps editors already do this. - Connelly From shimpeR3M0V3TH1S at esat.kuleuven.4NDTH1S.ac.be Tue Aug 17 08:42:42 2004 From: shimpeR3M0V3TH1S at esat.kuleuven.4NDTH1S.ac.be (Stefaan) Date: Tue, 17 Aug 2004 14:42:42 +0200 Subject: music resources In-Reply-To: References: Message-ID: <1092746565.680953@seven.kulnet.kuleuven.ac.be> You may want to look at http://www.linux-sound.org Have a look in the section software synthesis. It contains links to many audio synthesis and music composition projects. If you like JAVA, have a look here: http://jmusic.ci.qut.edu.au/ Greetings. Elaine Jackson wrote: > Is there such a thing as an executable language for music? If not, why not? And > if yes, where can I find it? Naturally the ideal thing would be if such a > language were implemented within python, but I would be willing to learn a > lesser programming language if I had a reasonable assurance that it had what I'm > looking for. I have, of course, googled for a solution, and I may have even > found it, but if so I didn't recognize it as such. Any pointers will be mucho > appreciado. > > Peace > > From python-url at phaseit.net Tue Aug 17 20:53:58 2004 From: python-url at phaseit.net (Peter Otten) Date: Wed, 18 Aug 2004 00:53:58 +0000 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 18) Message-ID: QOTW "Implementations are always preferred over rhetoric." - Robert Brewer "The programmers you'll be able to hire to work on a Java project won't be as smart as the ones you could get to work on a project written in Python." - Paul Graham http://www.paulgraham.com/gh.html Colin J. Williams shows Mizrandir how to subclass numarray's arrays. http://groups.google.com/groups?threadm=df3955c3.0408140908.1b9bfb63%40posting.google.com Hoang Do receives various suggestions how to drop into the interpreter from a running script. http://groups.google.com/groups?threadm=mailman.1679.1092569474.5135.python-list%40python.org Kyle Root asks for help arranging a dependency tree of Python modules and receives both theoretical background information on the problem and code implementing a "topological sort". http://groups.google.com/groups?threadm=6ccff37a.0408111831.6eb25a4e%40posting.google.com Timothy Fitz starts a discussion of the differences between Python's generators (an overwhelming success) and coroutines. http://groups.google.com/groups?threadm=972ec5bd.0408141032.385fe115%40posting.google.com Fazer learns that he has competition in the area of scripts that retrieve weather forecasts from the web. http://groups.google.com/groups?threadm=6491b0ab.0408121917.5103b770%40posting.google.com Coming from a C++ background, Olivier Parisy feels uneasy with the use of exceptions to control program flow in non-exceptional situations. Peter Hansen and several others tell him not to worry. http://groups.google.com/groups?threadm=411775aa%240%2417867%24626a14ce%40news.free.fr Roman Suzi has a clear vision of Python 3.0's design process in 2015. http://groups.google.com/groups?selm=mailman.1672.1092553249.5135.python-list%40python.org We resist all urges to say more about decorators or white space. ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous 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 newsgroup weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Brett Cannon continues the marvelous tradition established by Andrew Kuchling and Michael Hudson of intelligently summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Business Forum "further[s] the interests of companies that base their business on ... Python." http://www.python-in-business.org The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donate.html Cetus collects Python hyperlinks. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://aspn.activestate.com/ASPN/Cookbook/Python Among several Python-oriented RSS/RDF feeds available are http://www.python.org/channews.rdf http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi http://python.de/backend.php For more, see http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. *Py: the Journal of the Python Language* http://www.pyzine.com Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. From abra9823 at mail.usyd.edu.au Wed Aug 4 22:29:27 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Thu, 5 Aug 2004 12:29:27 +1000 Subject: cgi script headers - help Message-ID: <1091672967.41119b8746b79@www-mail.usyd.edu.au> hi! i am generating a file on the fly and making a user download it. print "Content-Type: application/model\n\n" print "Content-Disposition: attachment; filename=modeldef3\n" print str i set the Content-Disposition to force a download dialog box and also give the file a name. however when i view the headers sent by my script, i have only HTTP/1.1 200 OK Date: Thu, 05 Aug 2004 02:26:48 GMT Server: Apache/1.3.19 (Unix) Connection: close Content-Type: application/model why isn't the Content-Disposition header coming up? thanks cheers -- Ajay Brar, CS Honours 2004 Smart Internet Technology Research Group ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From srumbalski at copper.net Sat Aug 21 17:08:10 2004 From: srumbalski at copper.net (Steven Rumbalski) Date: Sat, 21 Aug 2004 17:08:10 -0400 Subject: age of Python programmers References: Message-ID: <4127b8ad_4@newsfeed.slurp.net> Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? I may as well get in on the game. I'm 31 and started programming when I was 26 in c++. I was intrigued by python, but was wooed by the marketability of java and learned it in 2000. I finally learned python in 2001 and have never looked back. Programming is a hobby for me--I wish it were more than that. I am a customer service rep in real life. Steven Rumbalski From franz04 at yahoo.fr Thu Aug 19 10:58:17 2004 From: franz04 at yahoo.fr (=?iso-8859-1?q?Francis=20Lavoie?=) Date: Thu, 19 Aug 2004 10:58:17 -0400 (EDT) Subject: age of Python programmers In-Reply-To: <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: <20040819145817.91134.qmail@web50107.mail.yahoo.com> 25 but still new to python. I'm a windows/linux system admin by profession/obligation, and then never developpe my programming skills very much since I'm out of school. I start using python a month ago, because I was suppose to build a php dynamic website (only news), but the client doesn't have php support. So my option was, asp or python. Now I have builded a client site cms lite program that update news by ftp. First I though it would be only a patching solution, but wow, now I can buil a full cms lite client application, that keep it very simple for user. After cleaning the code (well I was learning in the same time) and comment it, I think I'll opensource it somewhere. Python is amazing and it will start a new programming odyssey for me ;-) __________________________________________________________ L?che-vitrine ou l?che-?cran ? magasinage.yahoo.ca From rnichol_rrc at yahoo.com Sun Aug 22 18:02:09 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Sun, 22 Aug 2004 17:02:09 -0500 Subject: python doesn't like my numbers In-Reply-To: <2osfspFdnjbcU1@uni-berlin.de> References: <2osfspFdnjbcU1@uni-berlin.de> Message-ID: paul k wrote: > hi, > > is there any way to convince python not to take my (phone)numbers > starting with zero as octals? > > >>> int(088) > File "", line 1 > int(088) > ^ > SyntaxError: invalid token > > thanks > Paul int("088") From sbabbitt at commspeed.net Mon Aug 9 18:31:48 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Mon, 9 Aug 2004 15:31:48 -0700 Subject: VB-like GUI designer? References: Message-ID: <1092091116.31608@news.commspeed.net> "Fred" wrote in message news:bv2fh01mq7ug2v79s737tg06iehiph9158 at 4ax.com... > Hi, > > I'm currently checking out Python as an alternative to VB.Net > to moving from VB, but can't find a GUI designer that is as good as > VB. > > I tried wxDesigner and wxGlade, but neither lets me move the widgets > around. I also tried Dialogblocks, but it seems to only handle C++ or > XRC, not Python. > > Is this all there is, or is there a gem I missed? > > Thank you > Fred. wxPython has all you need, it is easy to use sizers but if your stuck on visual design use the XML resource editor. Tom From peter at engcorp.com Tue Aug 3 15:30:03 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 03 Aug 2004 15:30:03 -0400 Subject: executing python programs as if they were on OS path (noob) In-Reply-To: References: Message-ID: Darren Dale wrote: > Is there a place to put python programs so I dont have to refer to the > absolute path everytime I want to call them? For example: > > if I am in /home/me and want to execute: > > python /home/me/python/export.py temp.dat > > what could I do so this will work: > > python export.py temp.dat At least two options (assuming you're on Linux... you didn't specify your OS unfortunately): 1. Make the scripts executable (+x with chmod), make sure the folder they are in *is* in the OS path, and put in the following as the first line of the scripts: #!/usr/bin/env python 2. Make your own shell script which knows where to look for your Python files and execute that instead of "python". Call it "mypy" or something to make sure you don't mess up anything else in the system which wants the normal behaviour with "python". Note that with your example above, you don't have to use the full absolute path, as just "python python/export.py temp.dat" would work. -Peter From nid_oizo at yahoo.com_removethe_ Fri Aug 20 04:13:10 2004 From: nid_oizo at yahoo.com_removethe_ (Nicolas Fleury) Date: Fri, 20 Aug 2004 04:13:10 -0400 Subject: Alternative decorator syntax decision In-Reply-To: <7x3c2iw9ig.fsf@ruckus.brouhaha.com> References: <7x3c2iw9ig.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > 1. My favorite variant was not in the list. What is it? I added E4 before voting because it was not on the list;) Regards, Nicolas From gry at ll.mit.edu Thu Aug 26 12:46:25 2004 From: gry at ll.mit.edu (george young) Date: 26 Aug 2004 09:46:25 -0700 Subject: property puzzle Message-ID: <78b6a744.0408260846.5dc5a0cf@posting.google.com> [python 2.3.3, x86 linux, part of a substantial gtk/postgres app] I want a Run instance to have a Status instance which inherits from Observable. I want to be able to say: thisrun.status = 'planned' and have thisrun's _set_status do side-effects and then the status object's setter incorporate the new value as it's new state. But the setter functions never seem to get called. Am I using "property" wrong? class Observable: #("observer" software pattern) def __init__(self): self.observers = [] def register(self, func, *args, **kw): self.observers.append((func, args, kw)) def notify(self): for func, args, kw in self.observers: func(*args, **kw) class RunStatus(Observable): def __init__(self, val): Observable.__init__(self) self._value = val def set(self, newval): print 'RunStatus.set' self._value = newval self.notify() def get(self): print 'RunStatus.get' return self._value class Run: def __init__(self): self._status = RunStatus('planned') def _get_status(self): return self._status def _set_status(self, val): # do various things with val... self._status.set(val) status = property(_get_status, _set_status) if __name__ == '__main__': def stat_display(): print 'display to screen: r.status=', r.status r = Run() r.status.register(stat_display) #many registers in real app. r.status='hold' print 'status=', r.status print r._status.observers Status needs to be a real and persistant object so it's observers persist, but needs it's value changed simply, like r.status = 'something' [flames about using string values for what is semantically a six valued enum *are* welcome in a separate thread...] From martin at v.loewis.de Thu Aug 5 17:54:49 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 05 Aug 2004 23:54:49 +0200 Subject: Proposal: require 7-bit source str's In-Reply-To: References: Message-ID: <4112aca9$0$24859$9b622d9e@news.freenet.de> Peter Otten wrote: > Could > > # -*- coding: ascii -*- > > be sufficient? No. He still wants to allow non-ASCII in Unicode literals and comments. Regards, Martin From aleaxit at yahoo.com Thu Aug 26 17:01:49 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 23:01:49 +0200 Subject: Static properties References: Message-ID: <1gj5e8n.xujsah4chw0gN%aleaxit@yahoo.com> Per Erik Stendahl wrote: > Hello everyone, > > Is it possible to define "static properties" in a class? Yes, but only by defining a custom metaclass to be the type of that class. Properties are defined in the type, not in the instance; so, for a class itself to have properties, the class's type, commonly known as its metaclass, must be the one defining them. >>> class metaPath(type): ... def curdir(cls): return os.getcwd() ... curdir = property(curdir) ... >>> class Path: __metaclass__ = metaPath ... >>> print Path.curdir /Users/alex/cb/dblite/dblite_0.5 _However_...: >>> print Path().curdir Traceback (most recent call last): File "", line 1, in ? AttributeError: 'Path' object has no attribute 'curdir' >>> if you want to be able to get at property curdir on INSTANCES of Path as you normally would for a staticmethod, yet with property syntax, I think you need to get a bit more clever than this... descriptors don't get looked up two metalevels up, only one... Alex From martindemello at yahoo.com Thu Aug 26 05:54:35 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Thu, 26 Aug 2004 09:54:35 GMT Subject: Why return None? References: Message-ID: Peter Hansen wrote: > Martin DeMello wrote: > > > It seems to be a fairly common pattern for an object-modifying method to > > return None - however, this is often quite inconvenient. > ... > > this is actually getting in my way a lot when scripting Blender - for > > instance, I can't say move(Vector([a,b,c]).normalize()), I have to do > > a = Vector([a,b,c]) > > a.normalize() > > move(a) > > By the way, the second version is much more readable than > the first, so perhaps there is a secondary reason for this > "return None" thing in addition to the more important one... It depends on what you're doing - to me, the first is simply "the normalised vector (a,b,c)", inlined. It's a single concept, much like an inlined string is - would you want to do the following? a = "Hello " a = a + str(name) print a martin From danb_83 at yahoo.com Sat Aug 7 05:21:15 2004 From: danb_83 at yahoo.com (Dan Bishop) Date: 7 Aug 2004 02:21:15 -0700 Subject: How to force a single number to be a tuple References: <1a517b5.0408061329.429de7fc@posting.google.com> Message-ID: Roy Smith wrote in message news:... > bryanjugglercryptographer at yahoo.com (Bryan Olson) wrote: > > Python tuples overlap too much with lists, and differ from the > > functional/relational view in which a tuple is an element of the > > Cartesian product of zero or more domains. > > For those of us who went to school a while ago, and perhaps didn't pay > as much attention in math class as we should have, could you translate > "an element of the Cartesian product of zero or more domains" into > English? The Cartesian product of X and Y is the set [(x, y) for x in X for y in Y]. From cpl.19.ghum at spamgourmet.com Sun Aug 8 07:28:14 2004 From: cpl.19.ghum at spamgourmet.com (Harald Massa) Date: Sun, 8 Aug 2004 11:28:14 +0000 (UTC) Subject: Going the PL/1 way References: Message-ID: Mikl?s, >> I do not understand at all what's that decorators thingy, but I know >> that girls often put some deco into flats and it really looks cosy >> after, so I assume that decorators are not on the dark side of the >> source. > The rest of the novelties in v2.4 are more or less fine with me, too. > But IMHO decorators are exactly Dark Code Wader stuff. Basically it's > about self-modifying code. So you are suggesting that THE SOURCE it is strong with this young padawan? But I'm sure considered carefully the BDFL has before giving in, hasn't he? I honestly ask that someone could explain to the less enlightened like me what this decorator thingy really is. What does it make a correct step on the path to enlightenment? Harald From rogerb at rogerbinns.com Thu Aug 12 14:33:47 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Thu, 12 Aug 2004 11:33:47 -0700 Subject: VB-like GUI designer? References: <30260531.0408102005.5847b9c@posting.google.com> <3hpou1-09i.ln1@home.rogerbinns.com> <30260531.0408120944.5d9ea9f2@posting.google.com> Message-ID: <9ppsu1-fjs.ln1@home.rogerbinns.com> simo wrote: > So how are you generating this interpreter/bytecode archive? It > basically sounds like the kind of thing py2exe does, but you've made > an object file or something. How did you calculate the dependencies? It is all discussed in the presentation at http://bitpim.org/papers/baypiggies Slides 18 thru 23. On Windows I use py2exe, Linux I use cxFreeze and Mac uses BundleBuilder. > I'm heading off to your site to see if you have the build environment > in with the source ;o) It is. The simplest one is in the dotamatic source. Look for a file named makedist.py. A more complicated variant of makedist.py is in the BitPim source. http://cvs.sourceforge.net/viewcvs.py/dotamatic http://cvs.sourceforge.net/viewcvs.py/bitpim (I can't give longer links as SF CVS stuff is down at the moment). Roger From tdelaney at avaya.com Sun Aug 22 18:55:20 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Mon, 23 Aug 2004 08:55:20 +1000 Subject: Alternative decorator syntax decision Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01D59448@au3010avexu1.global.avaya.com> Delaney, Timothy C (Timothy) wrote: > Anyway, my vote is C1, C1, J2. Given how many people are being obstinate about their choice, I'm going to change my vote to: C1, C1, C1 ;) Tim Delaney From Ian.Preddy at Lorien.co.uk Wed Aug 25 12:44:22 2004 From: Ian.Preddy at Lorien.co.uk (Preddy, Ian) Date: Wed, 25 Aug 2004 17:44:22 +0100 Subject: Are you avail... Message-ID: <8C6F2C03232E7E4CA899EC669704958701273299@lonads02.lorien.co.uk> I am currently searching for a Python developer to fill the following requirement: Python Developer required to work for a major investment bank. Candidates must have recent commercial experience of Python development as well as Unix, Java, Windows NT / XP, Web Development (CGI or HTML), ClearCase and Perl. The successful candidate will be responsible for development of web based release process workflow software and enhancement of a development lifecycle bug fixing system. If this sounds of any interest please contact me at your earliest convenience. Kind Regards Ian Preddy Account Executive lorien resourcing ' 0207 654 1022(Direct Dial) ' 0207 654 1013 (Fax) * email Ian.Preddy at lorien.co.uk " Visit our web site : Lorien is a founder member of ATSCO ********************************************************************** The information contained in this email is confidential and is intended for the recipient only. If you have received it in error, please notify us immediately by reply email and then delete it from your system. Please do not copy it or use it for any purposes, or disclose its contents to any other person or store or copy this information in any medium. The views contained in this email are those of the author and not necessarily those of Lorien plc. Thank you for your co-operation. ********************************************************************** From anthonybaxter at gmail.com Fri Aug 20 15:45:51 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 21 Aug 2004 05:45:51 +1000 Subject: Fate of lambda, Functional Programming in Python... In-Reply-To: References: <20040820163629.8DD4F1E401A@bag.python.org> Message-ID: On Fri, 20 Aug 2004 12:50:02 -0400, Chas Emerick wrote: > In a comment off a post on lambda-the-ultimate, I noticed this little > offhand remark: > > '''IIRC GvR is going to kill the various lambda, map,filter & reduce > leaving just generator expressions/list comprehension.''' First point: lambda, map, filter and reduce won't go away before Python 3.0, at the very least. And, to be honest, I suspect map/filter/reduce are much more likely to die than lambda, as they can nearly always be expressed more clearly as listcomps or genexprs. Having said that, and donning my interpreting-Guido-hat, the major problem with lambda is the scoping issue. Nested scopes make this less of a problem. In addition, the name 'lambda' was a poor poor choice. From john at grulic.org.ar Thu Aug 19 10:39:36 2004 From: john at grulic.org.ar (John Lenton) Date: Thu, 19 Aug 2004 11:39:36 -0300 Subject: speed In-Reply-To: References: Message-ID: <20040819143936.GE3185@grulic.org.ar> On Thu, Aug 19, 2004 at 04:16:24PM +0200, Peter Kleiweg wrote: > John Lenton schreef: > > > > flex has an option to generate code without the gotos... > > I have the latest version. I can't find it, not as run time > option, not as build option. hmm! you're right... I wonder what lexer it was, then? I definitely have a weak ref to the option in my head, but the owner has been gc'ed :( -- John Lenton (john at grulic.org.ar) -- Random fortune: There was a phone call for you. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From IHateSpam at sapm123.com Tue Aug 31 11:37:14 2004 From: IHateSpam at sapm123.com (A.M) Date: Tue, 31 Aug 2004 11:37:14 -0400 Subject: GUI Designer Message-ID: Hi, Do we have any OpenSource GUI designer for Python ? Thanks, Alan From spam at mouse-potato.com Fri Aug 27 21:41:22 2004 From: spam at mouse-potato.com (Pascal Bourguignon) Date: 28 Aug 2004 03:41:22 +0200 Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4dyXc.25792$Ot3.22106@twister.nyc.rr.com> <878yc0ucyl.fsf@thalassa.informatimago.com> Message-ID: <87hdqorqd9.fsf@thalassa.informatimago.com> "David Schwartz" writes: > "Pascal Bourguignon" wrote in message > news:878yc0ucyl.fsf at thalassa.informatimago.com... > > > Kenny Tilton writes: > > >> >>What you mean with Unixism? > >> > repeated accidents. Such a tool would > >> > first chop off the user's brain, molding > >> > a mass of brainless imbeciles and > >> > microcephalic charlatans the likes of > >> > Larry Wall and Linus Torvald jolly > >> > Server: Apache/2.0.50 (Fedora) > >> > ^^^^^^^^^^^^^^^^^^^^^^ > >> > >> So you like my approach, which is to condemn things they have never used? > >> > >> :) > > > > No, that of no more using things that you condemn. > > I don't follow you at all. I think you'll find the most useful, > meaningful complaints about, say, a Ford Explorer from the people who drive > one every day. I'd expect to get these complaints indeed from people who drove it, but I'd be puzzled if they'd continued to drive it every day. -- __Pascal Bourguignon__ http://www.informatimago.com/ Our enemies are innovative and resourceful, and so are we. They never stop thinking about new ways to harm our country and our people, and neither do we. From __peter__ at web.de Fri Aug 6 11:02:43 2004 From: __peter__ at web.de (Peter Otten) Date: Fri, 06 Aug 2004 17:02:43 +0200 Subject: 'Using is not None, may not always work' References: Message-ID: Doug Fort wrote: > Since I installed 2.4a2 I've been getting a warning from pychecker: Using > is not None, may not always work'. I thought 'is not None' was the right > thing to do. I've had problems with 'if not x:', because some objects > return False in this context. This is harmless. Starting with 2.4a2 None is a constant: Python 2.3.3 (#1, Jan 3 2004, 13:57:08) [GCC 3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import dis >>> def f(): ... if x is None: pass ... >>> dis.dis(f) 2 0 LOAD_GLOBAL 0 (x) 3 LOAD_GLOBAL 1 (None) 6 COMPARE_OP 8 (is) 9 JUMP_IF_FALSE 4 (to 16) 12 POP_TOP 13 JUMP_FORWARD 1 (to 17) >> 16 POP_TOP >> 17 LOAD_CONST 0 (None) 20 RETURN_VALUE >>> Python 2.4a2 (#1, Aug 6 2004, 16:38:38) [GCC 3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. [python 2.4a2] >>> import dis >>> def f(): ... if x is None: pass ... >>> dis.dis(f) 2 0 LOAD_GLOBAL 0 (x) 3 LOAD_CONST 0 (None) 6 COMPARE_OP 8 (is) 9 JUMP_IF_FALSE 4 (to 16) 12 POP_TOP 13 JUMP_FORWARD 1 (to 17) >> 16 POP_TOP >> 17 LOAD_CONST 0 (None) 20 RETURN_VALUE When PyChecker sees the constant it supposes you are doing something like if x is "some string": pass which always had the LOAD_CONST op-code and is indeed dangerous. PyChecker needs to be fixed to special-case None for 2.4. Peter From anthonybaxter at gmail.com Thu Aug 26 10:57:36 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 27 Aug 2004 00:57:36 +1000 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> Message-ID: On Thu, 26 Aug 2004 09:50:43 -0400, Paul Morrow wrote: > Ok. Then let's jettison the baggage with the word metadata and just > call them 'magic attributes'. It doesn't matter. The essential point > about them is that they almost /never have 'local variable' semantics/. > They are attributes of the object being defined. That's the point I'm > trying to drive home here. When we define __xxx__ attributes, we are > not intending to create local variables. No. We are making declarations. Explain to me how __getitem__ is a declaration while getMonkey is not, assuming both are methods. The only magic attribute that fits your case of "magic attribute" is __metaclass__. The overwhelming number of double-under names are not magic attributes, or metadata, or whatever you want to call them. From jeffrey at I.slack Fri Aug 13 23:06:22 2004 From: jeffrey at I.slack (Jeffrey Froman) Date: Fri, 13 Aug 2004 20:06:22 -0700 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: Terry Reedy wrote: >> is that indentation determines the program flow -- they think its weird. > > Giving that structured text (in English at least) routinely uses > significant indentation (lists, outlines, block quotes) and that much > algorithm pseudocode does the same (which was half the reason I called > Python 'executable pseudocode'), I find it puzzling that so many find it > 'weird' (if indeed that is true). Me too, and in fact I don't believe that the people who complain about it really think it's weird either. It's just fashionable to dislike Python for that reason. If using indentation for program flow is so non-intuitive, then why do C programmers complain so much about other C programmers indentation, and spend so much energy "cleaning up" indentation to fit their own idea of how C code should look? I'd think since indentation was so "insignificant" that any C coder would happily accept any indentation style as their attention "naturally" separated significant elements between curly braces. Clearly, this is not the case though. Jeffrey From brian at rk-speed-rugby.dk Tue Aug 31 04:34:08 2004 From: brian at rk-speed-rugby.dk (Brian Elmegaard) Date: 31 Aug 2004 10:34:08 +0200 Subject: From python to LaTeX in emacs on windows References: Message-ID: Benjamin Niemann writes: Thank for the help. I solved the problem by specifying the cp1252 encoding for the python file by a magic comment and for the input data file. > When you read the filecontents in python, you'll have the "raw" byte > sequence, in this case it is the UTF-8 encoding of unicode text. But > you probably want a unicode string. Use "text = unicode(data, > 'utf-8')" where "data" is the filecontent you read. After processing > you probably want to write it back to a file. Before you do this, you > will have to convert the unicode string back to a byte sequence. Use > "data = text.encode('utf')". > This worked, but when I try to print text I get: UnicodeEncodeError: 'ascii' codec can't encode characters in position 9-10: ordinal not in range(128) Why is that? > Handling character encodings correctly *is* difficult. What makes it difficult? The OS, the editor, python, latex? -- Brian (remove the sport for mail) http://www.et.dtu.dk/staff/be From mike.ayers at tumbleweed.com Sun Aug 15 00:19:29 2004 From: mike.ayers at tumbleweed.com (Mike Ayers) Date: Sun, 15 Aug 2004 04:19:29 +0000 (UTC) Subject: Raw IP packets on Linux Message-ID: I am trying to compose raw IP packets on Linux, then send them out a chosen interface. So I do: sock = socket.socket( socket.AF_PACKET, socket.SOCK_DGRAM ) sock.bind(( '192.168.1.3' )) So far so good. I create a packet (pkt) which contains the complete IP datagram. ID is set to 0 to tell the kernel to stamp it for me. However, I am so far unable to send the packet (pretend ']' is '>'): ]]] sock.sendto( pkt, ('192.168.1.4', 0)) Traceback (most recent call last): File "", line 1, in ? socket.error: (19, 'No such device') What am I getting wrong here? What address type does this socket expect? Thanks, /|/|ike From casey at zope.com Thu Aug 5 13:32:53 2004 From: casey at zope.com (Casey Duncan) Date: Thu, 5 Aug 2004 13:32:53 -0400 Subject: RELEASED Python 2.4, alpha 2 References: <411231C8.3020308@interlink.com.au> <200408051851.08457.heikowu@ceosg.de> Message-ID: <20040805133253.70f83d66.casey@zope.com> On Thu, 5 Aug 2004 18:51:08 +0200 Heiko Wundram wrote: [..] > Think of the following: (old style) > > class x(object): > def __init__(self): > self.lock = threading.RLock() > > def synchronized_method(self): > self.lock.acquire() > try: > > finally: > self.lock.release() > > That's just plain horrible compared to what @ decorators can do: Seems clear to me. > > class x(object): > synchronized = InstanceSynchronizer() > > @synchronized > def synchronized_method(self): > > > Writing the InstanceSynchronizer is pretty easy too: > > class InstanceSynchronizer(object): > > def __init__(self): > self._locks = {} > self._refs = {} > > def _delete_ref(self,ref): > del self._locks[self._refs[id(ref)][1]] > del self._refs[id(ref)] > > def __call__(self,f): > def fsyn(fself,*args,**kwargs): > try: > lock = self._locks[id(fself)] > except KeyError: > lock = threading.RLock() > fselfref = weakref.ref(fself,self._delete_ref) > self._locks[id(fself)] = lock > self._refs[id(fselfref)] = (fselfref,id(fself)) > lock.acquire() > try: > return f(fself,*args,**kwargs) > finally: > lock.release() > return fsyn I will grant you that InstanceSynchronizer is reusable, but look at the volume of code here compared to the first example. I find the latter much more complex. Regardless, decorators don't really make this pattern possible, you could just as easily do this in 2.3: class x(object): synchronized = InstanceSynchronizer() def method(self): method = synchronized(method) The primary argument against this is that the rebinding is hidden down after the method body. I personally don't find that to be a problem, and the advantage is that it is neither a new concept nor a new syntax for people to learn and understand. It simply leverages what is already there and is nice and explicit. [..] > Now tell me that using decorators to do synchronization isn't a lot > easier to read than the first (old) example is, and also less > error-prone (resp. acquiring/releasing locks properly and without > deadlocks). I don't disagree that it is better and more general than your first example, however, a better and more general technique to do this already existed before the new decorator syntax. I just don't feel that the superficial gain of moving the declaration above the method definition is worth the added complexity to the language. -Casey From news at titanic.co.uk Mon Aug 2 15:11:20 2004 From: news at titanic.co.uk (Simon Faulkner) Date: Mon, 02 Aug 2004 20:11:20 +0100 Subject: Python executable on Windows Message-ID: <410e91ce$0$58816$5a6aecb4@news.aaisp.net.uk> Hi All, I've written a fair bit of simple Python for Linux and have been asked to write a program for win32. Is it possible to write a program and add the Python interpreter so that I just end up with a single .exe file for windows? I know that it will be large but it will be simple! TIA Simon From anthonybaxter at gmail.com Fri Aug 6 14:02:36 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 7 Aug 2004 04:02:36 +1000 Subject: elements of decorator syntax suggestions In-Reply-To: References: Message-ID: This is an excellent list! Thanks for doing it. I've made a couple of notes inline about the particular points. On 6 Aug 2004 10:19:21 -0700, Steven Bethard wrote: > I think one of the biggest reasons we're having such problems coming > to any agreement on decorator syntax is that each proposal makes a > number of syntax decisions, not just one. For decorators, I see the > following decisions that must be made: > > 1) Indicator > Proposals differ on how some sort of indicator of "decoratorhood" is > use. These include: > * none (e.g. just the list, as in the "list-after-def" suggestion) > * the '@' character > * a new keyword (with, using, decorate, etc.) This is the biggy, it seems. Current (as of a couple of hours ago) discussions on python-dev are discussing other alternatives instead of @, that will hopefully make it easier for IPython or Leo to cope for now (but note that in the future, some other use for @ might be found, so anyone relying on it at the moment might want to think about that). One current suggestion is to use the | character, instead. > 2) Location > Proposals also differ on exactly where the decorator declaration > should be made. These include: > * before def Short of someone producing a _very_ strong argument in favour of another form, this is almost certainly going to be the choice. > * between def and function name Breaks too many tools, as well as stupid humans who are used to seeing def functionname. > * between function name and argument list I'm not sure that this was ever popular, with anyone ;) > * between argument list and colon Guido's ruled this out (see previous posts, I put a link to his post outlining why. > * after colon (first line in body) A problem here is interaction with docstrings? > 3) List notation > As I understand it, it's already decided that any implementation of > decorators must allow for a list of decorators to be applied. So > proposals that might be accepted must explain how this can be done. > The options I've seen: > * one per line (as currently) There's some confusion as to how the one-per-line thing is ordered. I find it quite obvious, but I've been playing with this for a week now, so it might just be that I know the answer now. Simply - @decA @decB @decC def func(): is equivalent to func = decA(decB(decC(func))) > * commas only Too much ambiguity in the parsing, I suspect. > * current list syntax (or some similar variant) > 4) Indentation > Proposals also differ on whether or not decorators should introduce a > new block. What I've seen: > * no block > * block Guido pointed out that this would lead to the default indentation level for a decorated method being 3 tab stops. I also don't like it visually - I tried reformatting test_decorators using it, and it looked... strange. > I thought the summary above might put some things into perspective so > that when you're arguing for one syntax or another, you can argue > separately for the points that matter most to you. It might be that > we mostly agree on, say, the need for a keyword, or the block > indentation (though I'm certainly not holding my breath). But I'd > rather hear arguments for the different sections separately because, > to some degree, they're pretty much orthogonal. An excellent list! If you don't mind, I might steal this format for the PEP. It allows for a lot more alternatives to be covered off in a smaller space (since many proposals are minor variations on an existing proposal, and share the same problems). From __peter__ at web.de Wed Aug 11 13:36:50 2004 From: __peter__ at web.de (Peter Otten) Date: Wed, 11 Aug 2004 19:36:50 +0200 Subject: 'break' Causes Execution of Procedure? References: Message-ID: Scott Brady Drummonds wrote: > I have a bug in a script of several hundred lines of code that I cannot > figure out. I have attempted (unsuccessfully) to duplicate this problem > in > a smaller script that I can post here but have been unsuccessful. As > such, I'm posting code snippets here in the hopes that someone recognizes > a very basic mistake I've made and can straighten me out. Unfortunately you seem to have picked the wrong snippets, which by the way look made-up. The only error I see if key in skipList: ... should probably be if cycle in skipList: .... The "most basic" error would be a print statement producing > DEBUG: begin main procedure sitting in a second place where it doesn't belong and isn't expected. > How is it possible that the call to 'break' is seemingly being replaced > with a call to 'main'? Other than with a buggy C-extension that is not possible. Peter From reinhold-birkenfeld-nospam at wolke7.net Thu Aug 19 07:17:48 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Thu, 19 Aug 2004 13:17:48 +0200 Subject: Decorators: an outsider's perspective In-Reply-To: References: <20040814153534.8AC171E4007@bag.python.org> Message-ID: <2ojgfuFbc193U2@uni-berlin.de> Jack Diederich wrote: > The country results ended up with Germans having little sense of humor > (they thought everything was funny) to Canadians being the most picky. > Most "American" comedians are from Canada (SCTV, SNL) so that at least > jives with my personal experience. Well, I'm not digging up that old quote, am I? """ We're Germans and we use Unix. That's a combination of two demographic groups known to have no sense of humour whatsoever. """ (credits to Hanno Mueller) Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From news at NOwillmcguganSPAM.com Thu Aug 26 12:01:20 2004 From: news at NOwillmcguganSPAM.com (Will McGugan) Date: Thu, 26 Aug 2004 17:01:20 +0100 Subject: 3D geometry module? Message-ID: <412e0951$0$6157$db0fefd9@news.zen.co.uk> Hi, Is there a general purpose 3D geometry module for Python? I would like to be able to read / write 3D models and perform per vertex / per face operations on them. Failing that, are there vector / matrix / quaternion classes I can make use of? Thanks.. Will McGugan From jess.austin at gmail.com Sat Aug 28 08:49:05 2004 From: jess.austin at gmail.com (Jess Austin) Date: 28 Aug 2004 05:49:05 -0700 Subject: Are decorators really that different from metaclasses... References: <412D9F1E.6000809@yahoo.it> Message-ID: Paul Morrow wrote in message news:... > Jess Austin wrote: > > > So you have: > > > > def foo(x): > > __meta_variable__ = 42 > > variable = 5 > > return dir() > > > > And you're volunteering to explain to a newbie, or even a nearly > > intermediate programmer like myself, why the list that is returned > > from this function contains 'x' and 'variable' but not > > '__meta_variable__'? > > Sure. Magic attributes defined at the top level of a function (e.g. > your __meta_variable__) aren't intended to be local variables. You'll > see that as you start looking at more experienced programmer's code. > Therfore, they shouldn't be treated as local variables. For example, > suppose we changed your function a little... > > def foo(x): > __author__ = 'Jess Austin' > __version__ = '1.0' > variable = 5 > return dir() > > See the difference? I see that some of these variables have underscores and some don't. Why didn't you respond to my detailed explanation of how binding and scoping work in Python? Would it be worth my time to restate the explanation in simpler terms? > >>Others seem to want to specify a function's metadata outside of the > >>function def, which just doesn't seem pythonic (IMO). > > > > > > If you really understood Python's scoping rules, you would know that > > this opinion is the opposite of the truth. > > A decorator is a kind of meta information. So are docstrings. The > proposals I've been seeing (A1 and J2 in particular) declare decorators > and docstrings outside of the function def (not inside of the function def). I'll be more specific. "Others seem to want to specify a function's metadata outside of the function def": truth. "which just doesn't seem pythonic": opposite of truth. "(IMO)": apparently truth. Pythonic is a word with a meaning (in this newsgroup anyway), and modifying an object's namespace from outside _is_ pythonic: we've always been able to do so (at least since mid-1999 when I started using python) and we always will be able to do so. Your proposed arbitrary character-driven change to Python's conventional scoping rules would _not_ be pythonic. It may in fact be your opinion that such a change would be pythonic, but I correctly classified that opinion as the opposite of truth. > > Of all the current > > incarnations of function "metadata", only one may be set within the > > function, and that one is not set using a standard binding statement: > > > > True and True, provided that you believe that docstrings are the only > kind of function metadata. I believe though that attributes like > __author__ and __version__ above are also function metadata. Metadata is a programmer's convention, or perhaps in this case religious belief. I'm not certain what your precise convention is since you haven't explained it. You evidently expect all "experienced" programmers to know it and respect it. Apparently it has something to do with underscore characters. Python accomodates this particular convention, but it will never enforce it on the rest of us, and that is a GOOD THING. > > In broader commentary, as I've said, pep318 > > isn't really about metadata. One reason is that metadata isn't that > > important. > > By this you mean "in your opinion", right? Of course. The interesting thing about my opinions is that I've provided reasonable prima facie justification for them. Thoughtful interlocutors would respond to that justification. yours, Jess From sbabbitt at commspeed.net Sat Aug 28 11:22:41 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Sat, 28 Aug 2004 08:22:41 -0700 Subject: wxTheClipboard problem, IDLE vs PythonWin References: Message-ID: <1093707081.715504@news.commspeed.net> "Tim Rice" wrote in message news:bp-dnYrA8b_ttq3cRVn-hA at adelphia.com... > I have a need to write data to the Windows clipboard from a Python script. > I found a nice, simple solution @ > http://wiki.wxpython.org/index.cgi/ClipBoard. The problem is, I can only > get it to work from within the PythonWin and SPE IDE's. I get errors if I > try to run the exact same code from the command line or via IDLE's > interactive shell. I can't figure it out. Any ideas? Possibly something > missing from my PYTHONPATH environment variable? Idle is incompatible with wxPython, what I do when I work in Idle is just double click on the file to open it (don't use the run menu unless you have an error to look up). A programming tool I have found useful with wxPython is Leo (A literate programming tool) found at http://personalpages.tds.net/~edream/front.html Tom -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjl at pobox.com Thu Aug 26 15:40:23 2004 From: jjl at pobox.com (John J. Lee) Date: 26 Aug 2004 20:40:23 +0100 Subject: Inline Conditionals? References: <1gj4rpq.1oyt89b14xvbdqN%aleaxit@yahoo.com> Message-ID: aleaxit at yahoo.com (Alex Martelli) writes: [...] > Of course, absit iniuria verbis, one cannot make anything foolproof, > because fools are SO ingenious -- I've also seen lots of code like: > > if x < 0: > return True > else: > return False > > which is, si licet es, even _worse_ than the wished-for ternary use!-) [...] Argh. I looked at that, and had a sinking feeling. I just found about ten instances of that in my code! Strange that, though I was innoculated against the general case of this disease in the some years ago, I was apparently still entirely susceptible to this particular strain of it. John From rtw at freenet.co.uk Mon Aug 30 11:46:54 2004 From: rtw at freenet.co.uk (Rob Williscroft) Date: 30 Aug 2004 15:46:54 GMT Subject: why does this fail on python 2.2? References: Message-ID: John Hunter wrote in news:mailman.2611.1093878644.5135.python- list at python.org in comp.lang.python: > class Results(object): > __slots__ = ( "__doinit" ) > def __new__(cls): > AttributeError: 'Results' object has no attribute '_Results__doinit' > Its in the Traceback: __slots__ = [ '_Results__doinit' ] Rob. -- http://www.victim-prime.dsl.pipex.com/ From peter at engcorp.com Sat Aug 21 00:02:50 2004 From: peter at engcorp.com (Peter Hansen) Date: Sat, 21 Aug 2004 00:02:50 -0400 Subject: age of Python programmers In-Reply-To: References: Message-ID: Bryan wrote: > i'm 37... started programing on a TRS-80 Model I and III. i also did a > bit a programming on a VIC-20... brownie points for anyone who can > remember how many text characters there was in one row... 23! ... freakin' weird little machine that was... :-) > believe it or not, i can remember this :) > eventhough i'm not OLD like some of those on > this list, i did get to program BASIC with punch cards in my 8th grade > math class. -Peter From rajarshi at presidency.com Thu Aug 19 11:27:24 2004 From: rajarshi at presidency.com (Rajarshi Guha) Date: Thu, 19 Aug 2004 11:27:24 -0400 Subject: HTMLParser question Message-ID: Hi, I have some HTML that looks essentially consists of a series of
    's and each
    having one of two classes (tnt-question or tnt-answer). I'm using HTMLParser to handle the tags as: class MyHTMLParser(HTMLParser.HTMLParser): def handle_starttag(self, tag, attrs): if len(attrs) == 1: cls,whichcls = attrs[0] if whichcls == 'tnt-question': print self.get_starttag_text(), self.getpos() def handle_endtag(self, tag): pass def handle_data(self, data): print data if __name__ == '__main__': htmldata = string.join(open('tt.html','r').readlines()) parser = MyHTMLParser() parser.feed( htmldata ) However what I would like is that when the parser reaches some HTML like this:
    How do I add a user to a MySQL system?
    I should get back the data between the open and close tags. However the above code prints the text contained between all tags, not just the
    tags with the class='tnt-question'. Is there a way to call handle_data() when a specific tag is being handled? Placing a call to handle_data() in handle_starttag seems to be the way - but I';m not sure how to actually do it - what data should I pass to the call? Any pointers would be appreciated Thanks, Rajarshi From holbertr at dma.org Thu Aug 26 08:21:38 2004 From: holbertr at dma.org (Rick Holbert) Date: Thu, 26 Aug 2004 08:21:38 -0400 Subject: Converting hex string to an integer References: <412d9e18$0$22821$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: Derek Fountain wrote: > Given the character string "0x00A1B2C3" arriving at sys.argv[1] how do I > convert that to an integer which I can do some math on? i = eval(sys.argv[1]) From anthonybaxter at gmail.com Thu Aug 5 12:24:09 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 02:24:09 +1000 Subject: RELEASED Python 2.4, alpha 2 In-Reply-To: <2-SdnZCwNs1SwI_cRVn-uQ@powergate.ca> References: <411231C8.3020308@interlink.com.au> <2-SdnZCwNs1SwI_cRVn-uQ@powergate.ca> Message-ID: On Thu, 05 Aug 2004 12:18:22 -0400, Peter Hansen wrote: > Actually, I think many people *are* trying it out right now... > by reading the posts in this forum. Browsing a few examples in isolation is hardly the same thing as trying it out with real live coding. I did this, and found my initial "oh yuck" reaction ended up being "actually, this isn't too bad". From Michael.J.Fromberger at Clothing.Dartmouth.EDU Wed Aug 25 00:37:59 2004 From: Michael.J.Fromberger at Clothing.Dartmouth.EDU (Michael J. Fromberger) Date: Wed, 25 Aug 2004 00:37:59 -0400 Subject: Has anyone implemented BASIC in Python? References: <2oo13eFcj548U1@uni-berlin.de> <2ot30hFeek8nU1@uni-berlin.de> <9h0ji0lvc0be65nuvcugaa3vsq5mcl3ck8@4ax.com> <285ni0hmusfgqslj9gnhhimvanr2jh0be3@4ax.com> Message-ID: In article <285ni0hmusfgqslj9gnhhimvanr2jh0be3 at 4ax.com>, Andrea Griffini wrote: > On Mon, 23 Aug 2004 11:10:53 -0400, "Michael J. Fromberger" > wrote: > > >when you are dealing with a more complex general-purpose language, and > >one whose grammar needs to evolve over time, then I think a > >parser-generator is a much better solution by far. > > Like I said before may be it's me... but I see the grammar definition > and the sparse collection of C code snippets required to use yacc & > friends harder to understand than a recursive descending parser. Admittedly, YACC and Bison have a somewhat steep initial learning curve. However, in terms of long-term maintainability, that learning curve is well worth the trouble for non-trivial language projects. By combining the context-free grammar with associated semantic information (the so-called "sparse collection of C code snippets" you mention above), and allowing the tool to generate your parser code, you are much more likely to get a parser you can actually argue is correct. Correct code may not be fashionable, but it is certainly much more maintainable than incorrect code, or code whose correctness cannot easily be determined. The usual response: "It's worked fine so far!" does not cut much ice when you're writing something important, as I am sure you know! > for me, shift-reduce parser are beyond the ROI point. Ah, well. Suit yourself. :) In my opinion, that's equivalent to a builder saying, "Power tools do not have good return-on-investment over doing all our cutting, fitting, and joining using hand tools." But, perhaps if you only ever need to work with simple grammars, that might be true for your own needs. > >The chief trouble in maintaining a hand-written recursive descent parser > >is that the grammar for the input language is hidden inside the > >implementation. > > Normally the grammar is documented ALSO elsewhere in a very > human readable form. Of course -- but how do you know your human-readable documentation has any necessary correlation with the actions of the parser? With a hand coded parser, you basically have nothing but the author's hopeful assurance. Automatically generated parsers are generated directly from an EBNF analogue of the grammar (e.g., YACC input), which means you can be sure the parser matches the grammar, unless there's a bug in the parser generator, and the latter is S.E.P. And, heck, if you don't like bottom-up shift-reduce parsers of the LR(k) family, there are even parser-generators that generate top-down predictive parsers of various stripes (e.g., ANTLR), that are reputed to work well for many common tasks. > >Also, error-handling is tricky in recursive descent, because > >much of the parser's state is implicit in stack frames that must be > >correctly unwound when an error forces you to bail out. > > Here is an excerpt of a parser I wrote about a dozen years ago > in C. [...] > > case -RW_IF : > SkipToken(); > c=ParseExpr(); > if (!ParseError && NextIs(-RW_THEN)) > { t=ParseStat(); > if (!ParseError) > { if (CurToken==-RW_ELSE) > { SkipToken(); e=ParseStat(); } > else > e=NULL; > r=NewIf(c,t,e); > } > else > { Deref(t); Deref(c); } > } > else > Deref(c); > break; > > This is the case for parsing IF-THEN-ELSE statement. If you'll forgive me for being a bit harsh, I find this code practically unreadable. You've got at least three layers of nested error-handling here, just to make sure your dereferences all happen in the correct order. Having to explicitly check error codes like this, and manually handle memory, is PRECISELY the reason why I argued that error-handling is tricky in recursive descent. If you handed me this code and asked me to find a problem in it, I'd probably tear all my hair out. Does that mean you shouldn't use recursive descent? Of course not! The technique is clever, and has its place. But this example could have been so much nicer, even just using a table-driven top-down predictive parser, rather than an explicitly recursive one. > Of course this is just my personal view, based on the experience > I had on the few languages I implemented. For example I never > dared to write a parser for C++ Yeah. Well, C++ is pretty awful to parse, no matter WHAT type of algorithm you want to use. I won't dispute that at all. :) > PS: Ok ok ok... I'll give shift-reduce parser and their tools > another look. May be it's just my laziness that is showing up and > my brain that tries to find excuses for justifying it. I think that, in the long run, you will probably find your efforts well rewarded. I didn't intend to become the advocate for automatic parser generators, but I do think that someone just starting out should be aware that recursive descent is not always the best solution. -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From sholden at holdenweb.com Tue Aug 31 07:26:45 2004 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 31 Aug 2004 07:26:45 -0400 Subject: Live conversation between Python and an Excel spreadsheet In-Reply-To: References: Message-ID: <41346075.5040305@holdenweb.com> quadric at primenet.com wrote: > Hi, > I have an application that requires that Python initiate and mediate a > live and iterative conversation > between an external application (in which Python is embedded) and an > external Excel > spreadsheet. Python will have to pass info to the spreadsheet, > spreadsheet will make > calculations, Python will obtain results and pass back to application, > application will evaluate > results of spreadsheet calculations and create new set of data and > instructions, Python will pass > new data and instructions to spreadsheet, loop goes on 'n' times until > convergence to solution > or no solution. Python terminates conversation and returns control to > application until next > 'conversation'. > > If I had my choice (which I don't) I would re-code the spreadsheet in > Python, but that is not an > option in this case. > > Is there anyone on the list that has done this before and has an elegant > solution? If so, what Python modules should I look at? Are there any > good Python books out there that have > examples of this? > > I am experienced with Python and have some knowledge of COM objects etc.... > > Any help would be very much appreciated. > > Thanks > > Your best bet would be to interact with Excel as a COM object, as described in the excellent "Python Programming on Win32" by Robinson and Hammond. However, be aware that you'll probably end up ferreting around to find out about undocumented methods of Excel objects, as the docs are often far from complete. regards Steve From michaels at rd.bbc.co.uk Thu Aug 26 12:21:44 2004 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Thu, 26 Aug 2004 17:21:44 +0100 Subject: Call for signatories for J2 References: <412cf775$0$11496$ed2e19e4@ptn-nntp-reader04.plus.net> Message-ID: > Robert Brewer wrote: > ... >> The patch is nearly complete; > > Patch against current CVS passes all the tests* and has been uploaded > to SourceForge. I'm currently looking at how __future__ declarations > work. Patch against current CVS including __future__ statements/declarations has now been created, tested and uploaded to SourceForge. All tests pass. For those interested this means the full patch now allows: ---------------------- from __future__ import decorators def memoise(f): "dummy memoisation function" return f class Foo: using: staticmethod memoise def Hoo(Who, *args): print "Yoo", Who Foo.Hoo("HOO") ---------------------- For the __future__ work I followed the approach taken by generators/yield in 2.2 . Using decorators without an explicit import from __future__ results in a failure. On a slightly different topic, when I was looking at how __future__ statments work, I must admit when I saw the following, it made me smile: > python Python 2.3.3 (#1, Apr 6 2004, 01:47:39) [GCC 3.3.3 (SuSE Linux)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from __future__ import braces File "", line 1 SyntaxError: not a chance >>> Digging around the python source I must admit has been a pleasurable experience (especially when finding nuggets like this! :). Whether or not syntax J2 gets accepted or not, this has been fun - my compliments to the python-dev team :) Regards, Michael. -- Michael.Sparks at rd.bbc.co.uk British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From grv575 at hotmail.com Tue Aug 10 00:27:00 2004 From: grv575 at hotmail.com (grv575) Date: 9 Aug 2004 21:27:00 -0700 Subject: compiling with msvc7 References: <875af5e2.0408071735.4c1fdf89@posting.google.com> <4115da69$0$161$9b622d9e@news.freenet.de> Message-ID: <144d0df.0408092027.4f93f29a@posting.google.com> "Martin v. L?wis" wrote in message news:<4115da69$0$161$9b622d9e at news.freenet.de>... > ?ke wrote: > > I am trying to comile C code to python with weaver, using Microsoft > > Visual Studio .NET (which I think uses VS 7.0) but I get an error > > that Python is compiled with VS 6 and so doesn't work. > > > > Anyone knows a workaround for this ? > > Recompile Python, or buy VC6. > > Regards, > Martin garlic From jzgoda at gazeta.usun.pl Sat Aug 7 10:24:40 2004 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Sat, 7 Aug 2004 14:24:40 +0000 (UTC) Subject: Questions about parsing XML References: <%T4Rc.150$Iv.46@trndny03> Message-ID: Kyle Root pisze: >> libxml2 (http://www.xmlsoft.org/) has excellent support for XPath, F. >> Lundh's ElementTree also supports some XPath expressions, although it is >> built on expat and needs to parse whole XML document. > > Well I was going to use that, but I remember reading somewhere that > xmlib was depreciated or something, even if it has been do you still > recommend libxml2 over expat? Python's xmllib (regular expression based parser) is not the same software as libxml2 (GNOME XML library) ;). If you need full support for XPath, XPointer, XInclude or namespaces (see http://www.xml.com/pub/a/2004/06/30/py-xml.html) I recommend using libxml2. Some people say that some of its parsers are also faster than original J. Clark's expat (although not as easy to use as expat or expat-like SAX parser from libxml2). -- Jarek Zgoda http://jpa.berlios.de/ From crgre.znnf at hgvybt.qr Thu Aug 26 15:07:24 2004 From: crgre.znnf at hgvybt.qr (Peter Maas) Date: Thu, 26 Aug 2004 21:07:24 +0200 Subject: Larry Wall & Cults In-Reply-To: References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <412e0b7b.7894449@news.ecn.ab.ca> Message-ID: <2p6qomFi04b8U1@uni-berlin.de> Most of you are crossposting this thread to 5 newsgroups. Are you aware of this fact or are you just hitting reply? -- Peter Maas, Aachen, Germany, Tel +49-241-38200 e-mail crgre.znnf at hgvybt.qr From roy at panix.com Thu Aug 12 10:32:19 2004 From: roy at panix.com (Roy Smith) Date: Thu, 12 Aug 2004 10:32:19 -0400 Subject: [OT] Keyboard layout, was Re: PEP318 References: <20040812090056.00001e31@titan> Message-ID: Sion Arrowsmith wrote: > As someone who's just started using a Mac for the first time(*), > I'd like to add that it's not always plain-sailing on an English > keyboard. What's wrong with Mac keyboards? I've used a number of Mac keyboards over the past 15 or so years, and have found the variety of layouts to be no better or worse (or more or less standardized) than any other keyboards in general. I'm currently using a 12" PowerBook and other than finding the control key to be uncomfortably close to the space bar, I find it perfectly reasonable for programming and emacs-ing. > And I have a great > aversion to remapping keyboards so that they generate characters > other than those on the keycaps.) Yes, that's evil. I was just in the UK a couple of weeks ago and was using a semi-UK keyboard. As far as I could tell, the keycaps were labeled with the UK layout, but the codes they generated were US style. I touch-type, so as long as I ignored what was printed on the keycaps and just typed normally, everything was fine. But it's amazingly difficult to ignore the printed keycaps. From roy at panix.com Sun Aug 1 13:17:05 2004 From: roy at panix.com (Roy Smith) Date: Sun, 01 Aug 2004 13:17:05 -0400 Subject: Strange timing data for list.pop() Message-ID: In the recent "transforming a list into a string" thread, we've been discussing the fact that list.pop() is O(1), but list.pop(0) is O(n). I decided to do a little timing experiment. To be sure, I did verify experimentally the expected result, but along the way, I came upon an interesting artifact that I'm at a loss to explain. I used the following to generate some timing numbers for pop() on various sized lists: import time for power in range (20): i = 2 ** power list = [1] * i t0 = time.time () list.pop () t1 = time.time () t = t1 - t0 print i, t I know wall clock time isn't a good way to time things, but it was a first cut before I dove into the manual and found os.times(). The interesting thing is the data that I got with the above code: 1 7.70092010498e-05 2 6.91413879395e-06 4 5.96046447754e-06 8 5.00679016113e-06 16 5.00679016113e-06 32 5.00679016113e-06 64 5.00679016113e-06 128 5.00679016113e-06 256 4.05311584473e-06 512 5.00679016113e-06 1024 5.00679016113e-06 2048 5.96046447754e-06 4096 9.05990600586e-06 8192 9.05990600586e-06 16384 9.05990600586e-06 32768 1.4066696167e-05 65536 2.31266021729e-05 131072 3.09944152832e-05 262144 3.60012054443e-05 524288 3.38554382324e-05 I plotted the data. http://www.panix.com/~roy/pop-times.png An interesting shaped curve! I haven't done any curve fitting, but by eye it looks something like k - log (1/n). The data is quite repeatable, too. Admitting that clock time is a silly thing to be measuring here, anybody have any clue what might be causing this behavior? This is on an otherwise idle 768 Mbyte PowerBook running OSX-10.3.4 and Python 2.3.4. From tim.peters at gmail.com Wed Aug 4 17:38:45 2004 From: tim.peters at gmail.com (Tim Peters) Date: Wed, 4 Aug 2004 17:38:45 -0400 Subject: Timing Difference: insert vs. append & reverse In-Reply-To: <1a517b5.0408041305.3927a6c8@posting.google.com> References: <35b736b9.0408020330.53b24ed3@posting.google.com> <1a517b5.0408031027.60554dfb@posting.google.com> <1a517b5.0408041305.3927a6c8@posting.google.com> Message-ID: <1f7befae04080414386ded0eef@mail.gmail.com> [Bryan Olson] > Hmmm ... let me clarify what I'm selling: We can make lists > perform efficiently as double-ended queues without breaking > anything or perceptibly hurting anyone's efficiency. Until this > thread, I hadn't realized that Python's lists are much slower > than Perl's in important cases: > > http://perlmonks.thepen.com/17890.html > > Would this be a PEP-size change, or just a small fix? "Futile" is closer -- it's been debated to death repeatedly. Python 2.4 adds a deque type instead, with O(1) insert/remove at both ends, regardless of access pattern. That's O(1) per operation (not just amortized O(1) -- the deque type never needs to move entries). From wojciech_mula at poczta.null.onet.pl.invalid Tue Aug 31 17:47:54 2004 From: wojciech_mula at poczta.null.onet.pl.invalid (Wojciech Mula) Date: Tue, 31 Aug 2004 21:47:54 +0000 (UTC) Subject: Beeping the console References: Message-ID: Jeffrey Barish wrote: > What is the easiest way to beep the console from a Python program (i.e., > to do the same thing as echo -e \a)? import os import sys os.write(sys.stdout.fileno(), '\007') w. From markie at osafoundation.org Wed Aug 18 23:12:02 2004 From: markie at osafoundation.org (Mark Jaffe) Date: Wed, 18 Aug 2004 20:12:02 -0700 Subject: distutils help Message-ID: I am customizing a setup script and need to pass in some additional parameters specifying includes and libs. The build_ext lists some user variables such as "include-dirs" and "library-dirs" but I am unclear on how to access these within the setup.py. Are there any distutils gurus here? Mark Jaffe Chandler Build/Release Engineer OSAF From peter at engcorp.com Mon Aug 16 00:44:32 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 00:44:32 -0400 Subject: Python indentation deters newbies? In-Reply-To: <30260531.0408131853.18ec2446@posting.google.com> References: <3064b51d.0408130615.3fc4a760@posting.google.com> <30260531.0408131853.18ec2446@posting.google.com> Message-ID: simo wrote: > I'm a Perl programmer at heart - well that and PHP, plus the odd > dabbling in C/C++/C# etc. > > Anyway, the thought of indentation instead of curly braces really put > me off to start with, Ah, good. Someone who was really there, instead of hearsay. Please, *why* did it put you off? Didn't you already indent your code consistently? Didn't you think that the removal of those braces would immediately make the code more readable (fewer lines, fewer extra cruft to distract the eye) and easier to type? I'm curious why more people don't have "neat!" as their very first thought on encountering this, rather than "yuck!". -Peter From ben at benlast.com Mon Aug 16 08:40:53 2004 From: ben at benlast.com (Ben Last) Date: Mon, 16 Aug 2004 13:40:53 +0100 Subject: sys.stdin.read() replacement In-Reply-To: Message-ID: Re-reading the original question, I think that Benjamin's right (as all people called Ben tend to be, except me); the original poster was after a method of editing previous lines, and readline won't do that; it does single lines only. A curses-based console app would allow the editing of previous lines, but that's a whole order-of-magnitude shift in complexity (and I don't know of any curses modules for Windows). As a workaround - if the user is required to type in each line preceded by a number, then it'd be possible to just take the last version of a line. But that may not be possible. So; Unix solution - create a temporary filename (with os.tempnam() for example), spawn off an editor to edit it, and parse the resulting edited file when the edit session completes, like the Unix vipw command does. Windows equivalent - invoke notepad.exe as the editor. ben > -----Original Message----- > From: python-list-bounces+ben=benlast.com at python.org > [mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of > Benjamin Niemann > Sent: 16 August 2004 13:10 > To: python-list at python.org > Subject: Re: sys.stdin.read() replacement > > > not sure, if importing readline really gets the desired result (if I > understand the initial question correctly) > > suppose the following input: > > this is ym first line > > and another line > (oops there's a typo in the first line, user hits cursor up two > times, and corrects it) > > this is my first line > ... > > what the program will then reads is: > "this is ym first line" > "and another line" > "this is my first line" > ... > with no chance to see that the third line is supposed to replace line one. > Or is readline actually more powerful than I remember? > > > > import readline will work on Windows: > > a) if you're running the cygwin python, inside cygwin > > b) if you've installed a readline module; there are at least > two available. > > Excuse me for the self-referential answer, but about half and > hour before I > > read this, I wrote a blog entry all about readline modules, > with links to > > and comments about the Windows ones. The permalink is > > http://www.livejournal.com/users/benlast/16766.html or it's the > most recent > > entry at http://www.livejournal.com/users/benlast/ > > > > Karin: if you do import a readline, you can then use > sys.stdin.readline() to > > read a line of input, and you should get some sort of history > functionality > > (up-arrow, for example, will recall a previous line). > > > > regards > > b > > > > > >>-----Original Message----- > >>From: python-list-bounces+ben=benlast.com at python.org > >>[mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of > >>P at draigBrady.com > >>Sent: 16 August 2004 11:52 > >>To: python-list at python.org > >>Subject: Re: sys.stdin.read() replacement > >> > >> > >>Karin Lagesen wrote: > >> > >>>I am writing a small write-logfile script for use on the > >> > >>terminal. I have here > >> > >>>a section where the user should be able to type in several > >> > >>lines. I have solved > >> > >>>it so far by using sys.stdin.read(), which makes it possible to > >> > >>type in several > >> > >>>lines (separated by enter) and then terminate the session by > >> > >>typing ^D. This is > >> > >>>all very good. However, with this it is only possible to edit > >> > >>the line you are > >> > >>>in. If you spot an error further up in your text, you cannot > >> > >>get at it. Do any > >> > >>>of you know of a way I can do this? > >> > >> > >>import readline > >> > >>(I don't know if it works on windos) > >> > >>P?draig. > >>-- > >>http://mail.python.org/mailman/listinfo/python-list > > > > > -- > http://mail.python.org/mailman/listinfo/python-list From aahz at pythoncraft.com Fri Aug 27 19:41:42 2004 From: aahz at pythoncraft.com (Aahz) Date: 27 Aug 2004 19:41:42 -0400 Subject: age of Python programmers References: <20040819231139.D039A1E4003@bag.python.org> <5cf809e9.0408241126.6e3fdd5b@posting.google.com> <8ecda57b.0408251754.14ed27b9@posting.google.com> Message-ID: In article , Jonathan Daugherty wrote: > >Is it just me or are these posts getting off-topic? :) Assuming that I agreed with you, what would you want done? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From cjankowski at hbr-inc.com Wed Aug 11 10:53:59 2004 From: cjankowski at hbr-inc.com (Chris Jankowski) Date: 11 Aug 2004 07:53:59 -0700 Subject: Pilprint Message-ID: I am a newbie to the world of Python and trying to print some images(.tif). I have installed the PIL Library and can use the some of the fuctions like: m.format, im.size, im.mode without any problem. When I try to use the Tools like pilprint and pilfile, I can't seem to get them to work. Any help would be greatly appreciated. Examples: >>> pilfile *.tif Traceback ( File "", line 1 pilfile *.tif >>> pilprint 'c:/chris.TIF' Traceback ( File "", line 1 pilprint 'c:/chris.TIF' ^ SyntaxError: invalid syntax Thanks, Chris J. From cbrown at metservice.com Tue Aug 3 23:48:35 2004 From: cbrown at metservice.com (Colin Brown) Date: Wed, 4 Aug 2004 15:48:35 +1200 Subject: Module for converting XML to Python object(s)? References: Message-ID: <41105a9c$1@news.iconz.co.nz> "Robert Oschler" wrote in message news:otdPc.224$df.27 at bignews5.bellsouth.net... > Has anybody seen a Python module that will take an XML document (not a > colossal one), and convert it to a Python nested class object? Also pyRXP ref: http://www.reportlab.org/pyrxp.html Colin Brown PyNZ From robin at reportlab.com Wed Aug 25 12:58:17 2004 From: robin at reportlab.com (Robin Becker) Date: Wed, 25 Aug 2004 17:58:17 +0100 Subject: Alternative decorator syntax decision In-Reply-To: <412cc31c$1@news.012.net.il> References: <412cc31c$1@news.012.net.il> Message-ID: <412CC529.9060700@chamonix.reportlab.co.uk> Avner Ben wrote: > I believe putting the decorator list before the function header is > generally a bad design decision. While it may make parsing-related > sense, it violates Python's greatest asset: being executable pseudocode. > The way I see it, the latter quality means being able to look at the > code and see clearly and immediately what requirements from the real > world the code was written the serve. Functions and methods are major ..... except that these wrappers/transformers/decorators are able to do what they like to the code including turning methods into properties, changing the argument list etc etc etc. All the pain of self modifying code will be available :) as it already is, but with a new funky syntax to make it seem OK. I also don't like the def coming last, but if the thing isn't what you think it is the "here be dragons" is probably a good idea. -- Robin Becker From brianc at temple.edu Thu Aug 12 16:54:53 2004 From: brianc at temple.edu (brianc at temple.edu) Date: Thu, 12 Aug 2004 16:54:53 -0400 Subject: drop into the interpreter Message-ID: <2071f955.6ee078e1.8678300@po-d.temple.edu> Trick I use is to throw something into the point you want it to stop at that will raise an exception. Then run the script with the -i option. So "python -i script.py". Upon raising the exception it will return you an interpretter prompt. There's also a very good thread on Guido's blog about how to design main() functions so they're easily usable from the interpretter. http://www.artima.com/weblogs/viewpost.jsp?thread=4829 -Brian ---- Original message ---- >Date: Thu, 12 Aug 2004 22:11:15 +0200 >From: "Martin v. L?wis" >Subject: Re: drop into the interpreter >To: python-list at python.org > >Hoang Do wrote: >> is there a facility to inspect the run-time of a python script? >> Essentially, it would execute a script to a set specific point and then drop >> into the interpreter. Something like a "Stop" or "Break"? > >Not exactly that, but code.InteractiveConsole comes *very* close. > >Regards, >Martin >-- >http://mail.python.org/mailman/listinfo/python-list From sharidas at zeomega.com Thu Aug 19 06:01:33 2004 From: sharidas at zeomega.com (Satchidanand Haridas) Date: Thu, 19 Aug 2004 15:31:33 +0530 Subject: inverse of izip In-Reply-To: References: <41245B48.3020000@zeomega.com> Message-ID: <41247A7D.1040301@zeomega.com> Steven Bethard wrote: >Satchidanand Haridas zeomega.com> writes: > > >>How about using iter() to get another solution like the following: >> >> >>> starzip2 = lambda it: tuple([iter(x) for x in itertools.izip(*it)]) >> >> >>> l,m = starzip2(itertools.izip(range(10),range(10))) >> >> >>> l >> >> >>> m >> >> >> >>> list(l) >>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >> >>> list(m) >>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >> >> > > >Unfortunately, I think this exhausts the iterators too early because it >applies * to the iterator: > > > Could you expand on what you mean by exhaust the iterators too early? The reason I ask is that the * operator is applied to ((1,1),(2,2),....(9,9)). The operation of the itertools.izip(range10(),range10()) is completed before the * operation is applied. And the iter() simply converts the result of the inverse izip operation into an iterator. I hope the above was not too confusing. :-) I am trying to understand a little about the izip myself. Thanks. Satchit >>>>def range10(): >>>> >>>> >... for i in range(10): >... yield i >... print "exhausted" >... > > >>>>l,m = starzip2(itertools.izip(range10(),range10())) >>>> >>>> >exhausted > >I believe we only get one "exhausted" because as soon as one iterator is used >up with izip, the next iterator is discarded. But we are hitting "exhausted" >before we ever ask for an element from the starzip2 iterators, so it looks to >me like all the pairs from the first iterator are read into memory before the >second iterators are ever accessed... > >Steve > > Could you expand on what you mean by exhaust the iterators too early? The reason I ask is that the * operator is applied to the tuple ((1,1),(2,2),...(9,9)). Actually to the iterator which is called 10 times, each time returning (i,i) for 0<=0<10. When the iterator is called the 11th time, it prints "exhausted". So the operation of the itertools.izip(range10(),range10()) is completed and "exhausted" is printed before the * operation is applied. The iter() simply converts the result of the inverse izip operation which into an iterator. I hope the above was not too confusing. :-) I am trying to understand what goes on inside izip myself. Thanks. Regards, Satchit From news at woody.datatailors.com Tue Aug 10 07:39:18 2004 From: news at woody.datatailors.com (Peter van Kampen) Date: Tue, 10 Aug 2004 13:39:18 +0200 Subject: Apache web server and CGI References: <81a41dd.0408090447.7f27a092@posting.google.com> <10hf2ugjngver5e@corp.supernews.com> <81a41dd.0408092306.264beed@posting.google.com> Message-ID: In article <81a41dd.0408092306.264beed at posting.google.com>, Lad wrote: > [Tue Aug 10 08:51:32 2004] [error] [client 127.0.0.1] (2)No such file > or directory: script not found or unable to stat: c:/program > files/apache group/apache/cgi-bintest.py > > The name of script is test.py and is in cgi-bin (Apache subdirectory). In my experience cgi-bin is rarely just a subdir of apache's www-root. The name cgi-bin is in itself not some magical name that 'turns CGI on'. You have to configure it on your httpd.conf. Here's a relevant bit of mine: # # ScriptAlias: This controls which directories contain server scripts. # ScriptAliases are essentially the same as Aliases, except that # documents in the realname directory are treated as applications and # run by the server when requested rather than as documents sent to the client. # The same rules about trailing "/" apply to ScriptAlias directives as to # Alias. # ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ # # "/usr/lib/cgi-bin" could be changed to whatever your ScriptAliased # CGI directory exists, if you have that configured. # AllowOverride None Options ExecCGI Order allow,deny Allow from all Also just to be sure the first line of test.py should be sth like this on windows: #! c:\path\to\python.exe > BTW, how can I set up a different directory for cgi scripts? For > example I would like to have all my scripts in > C:\Scripts\MyScripts This is probably clear by now... Hth, PterK -- Peter van Kampen pterk -- at -- datatailors.com From jjl at pobox.com Thu Aug 19 14:16:22 2004 From: jjl at pobox.com (John J. Lee) Date: 19 Aug 2004 19:16:22 +0100 Subject: ClientCookie References: <6f402501.0408110018.1e4e5ca8@posting.google.com> <6f402501.0408120352.680496bc@posting.google.com> <87ekmcp13g.fsf@pobox.com> <6f402501.0408180457.70df82e3@posting.google.com> Message-ID: <87llgbt2mh.fsf@pobox.com> fuzzyman at gmail.com (Michael Foord) writes: > jjl at pobox.com (John J. Lee) wrote in message news:<87ekmcp13g.fsf at pobox.com>... [...] > No - I was following hte docs - which just shows CookieJar IIRC :-) > Now that I'm using LWPCookieJar everything is wonderful and works fine... [...] Whoops, sorry. Where is this mistake in the docs? I don't see it. John From grante at visi.com Sat Aug 28 11:05:40 2004 From: grante at visi.com (Grant Edwards) Date: 28 Aug 2004 15:05:40 GMT Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1ry8k0d2az.fsf@rovereto.ifi.uio.no> <87acwgvy51.fsf@sinken.local.csis.hku.hk> <2pb36dFibuj3U1@uni-berlin.de> <41309d32$0$65611$a1866201@newsreader.visi.com> Message-ID: <41309f44$0$65611$a1866201@newsreader.visi.com> On 2004-08-28, Grant Edwards wrote: >> Why would you call (2,) syntax a hack? > > Because so many people at first think that parens construct > tuples the way square-brackets and curly-brackets construct > lists. Um, that should have finished with "and curly-braces construct dictionaries." -- Grant Edwards grante Yow! Th' MIND is the Pizza at Palace of th' SOUL visi.com From sholden at holdenweb.com Tue Aug 31 07:52:32 2004 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 31 Aug 2004 07:52:32 -0400 Subject: Need help importing/installing reportlab module In-Reply-To: <1556ldg3h91o2.dlg@news.individual.net> References: <1ezngypknj8ju.dlg@news.individual.net> <4133EF58.4050709@holdenweb.com> <1556ldg3h91o2.dlg@news.individual.net> Message-ID: <41346680.9070900@holdenweb.com> Active8 wrote: > On Mon, 30 Aug 2004 23:24:08 -0400, Steve Holden wrote: > [...how to install ReportLab's open source code...] >> >>I'd be rather concerned that you can't find "reportlab" in the archive. >>Basically all it contains is a "reportlab" package directory with the >>code in it. > > That's what I see, just no .py or other files named reportlab. > Aha. The magic word is "package". See below. >>>If anyone can help me straighten this out, I'd really apppreciate >>>it. >>> >>>TIA >> >>Well if this doesn't fix it, please let me know. >> > > when I unzip, I get > > ..\ReportLab_1_19\reportlab-1_19 > Right, but this is because you chose to unzip INTO a directory you had created called ReportLab_1_19. If you look at the archive with WinZip or similar, you'll see that it essentially bundles everything into a reportlab-1_19 directory. That directory contains only two things: you identify them in your next bit. Not sure what the "..\" is doing in your path up there ... > which contains manifest.txt and the reportlab dir where the actual > python code is. I've tried putting both subdirs under d:\ and > changed the reportlab.pth path accordingly. I've changed the .pth > file from DOS to unix and back because I read somewhere that the > line termination char musst be just so - and I'm not even sure I got > that right, but there's a newline in there. I even tried it without > a newline. > Right. You are complicating things WAY beyond what they need to. Something I am prone to do myself, so I feel a certain sympathy. Delete everything you've done so far and unpack the archive into the root directory on your D: drive. (or move what you have already, if you feel confident doing that and you haven't messed about with the contents of the package). This will create D:\reportlab-1_19\MANIFEST.txt D:\reportlab-1_19\reportlab\__init__.py and a whole bunch of other stuff. What you are supposed to import is the D:\reportlab-1_19\reportlab DIRECTORY: it's a package, as indicated by the presence of the __init__.py file. So, having got this far, you now need to create a .pth file that Python will find (the easiest way to ensure that is to create it in the same directory as your python.exe interpreter binary). It doesn't matter what it's called, as long as its name ends in ".pth". It needs to contain just one line, which reads D:\reportlab-1_19 This will indicate to the interpreter that it can look in that directory for the reportlab package, and bingo, you are done. Note that if you install multiple packages you can add a line to the same .pth file for each of the packages you want Python to find, but that needn't concern you just now. > I've tried forward and backslashes. Also tried running > test_pdfgen_general.py from the command line and the python > interpreter - can't type "d:\report* because python doesn't like > colons - ..\report* - it doesn't like dots, either. But when I run > it from the windows command line, it says that in > > line 12 of test_pdfgen_general.py > > from reportlab.test import unittest > Import Error: no module named reportlab.test > If you can't import reportlab, what makes you think you'll be able to import one of its sub-packages? :^) > But I checked that test\ dir and unittest.py is there. If that's a > clue, I don't know what to make of it. > > I recall installing another module - maybe PIL. When I tried that > from x import y thing, I got an error, but the next instruction was > to just type import PIL or whatever, and that didn't throw any > errors. > > I'm pretty confused that it worked so well for you and isn't for me. > The instructions can't be simpler. > Basically you are just being confused by the extra directory level you've added, plus lack of knowledge about packages, which will be a bit confusing until you've seen one in action. I don't think it helps that packages aren't well-described in the mainstream documentation, and I would encourage you to read the description in the tutorial [Section 6.4 in my 2.3 documentation]. It also doesn't really help that type(reportlab) is reported as , adding to the potential for confusion, but once you have used packages for a while it seems like a very natural way to bundle related pieces of functionality. Get back to the group again if you still can't import reportlab - it's really worth the effort, honest! I use the o-s toolkit to do all my invoicing. regards Steve From jeff at ccvcorp.com Mon Aug 23 19:57:19 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Mon, 23 Aug 2004 16:57:19 -0700 Subject: function taking scalar or list argument In-Reply-To: <9ZCdnT9EuudK3bfcRVn-tA@comcast.com> References: <412a2bce$1_1@127.0.0.1> <9ZCdnT9EuudK3bfcRVn-tA@comcast.com> Message-ID: <10il11q5uqfg4ad@corp.supernews.com> Larry Bates wrote: >You may want to take a look at isinstance() function. > >def twice(x): > if isinstance(x, list): return map(twice, x) > if isinstance(x, (int, float, str)): return 2*x > return None > > Actually, I'd favor the try/except approach. It's entirely reasonable to think that, if this function might be passed either scalars or lists, it may also be passed a non-list-based sequence object. If you simply try using map(), then it'll work correctly for any object that follows the expected protocol, regardless of whether that object is (a subclass of) list. By explicitly demanding a list, you're needlessly limiting the usefulness of the function. Jeff Shannon Technician/Programmer Credit International From nospam at nowhere.hu Sat Aug 14 13:34:04 2004 From: nospam at nowhere.hu (Miklós) Date: Sat, 14 Aug 2004 19:34:04 +0200 Subject: Why I love python. References: Message-ID: "Michael Scarlett" wrote in message news:ce6aaec0.0408121605.1f85ea25 at posting.google.com... > There is an amazing article by paul graham about python, and an even > better discussion about it on slashdot. The reason I point this out, > is the more I read both articles, the more I realised how we would be > mutilating the language with that god forsaken @ decorator. > I don't know about the rest of you, but I learned python and fell in > love with its syntax and simplicity. Python - just works. So please > GVR. Don't complicate it. Leave it as is. Work on making it faster, > not uglier. Work on - in some cases - better algorithms for certain > modules, not for it to even closely resemble C or perl or god knows > whateverotherlanguagethereisoutthere. Am i the only one with a > visceral reaction to this thing??? This was precisely the motive behind my starting the thread "Going the PL1/1 way" I also worry about Python's healthy simplicity. Best regards, Mikl?s > > paul Graham article: http://www.paulgraham.com/pypar.html > > Slashdot discussion: > http://developers.slashdot.org/developers/04/08/12/1721239.shtml?tid=156&tid =218 From peter at engcorp.com Fri Aug 20 12:03:38 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 20 Aug 2004 12:03:38 -0400 Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: Tim Hochberg wrote: > Reid Nichol wrote: >> Gerrit Muller wrote: >>> and then a quantum leap towards Python. >> You're aware that a quantum leap means a extremely small leap, right? > > While quanta are typically very-very-very small, last I checked the key > feature of quantum transitions is not that they're small, but that there > are no intermediate steps. The object is in state A then it's in state > B, but it's never halfway (or anywhere) between. Like most quantum stuff > it's better not to think about that too closely. And at least some dictionaries give it as a synonym for "large" or "significant". (www.m-w.com for one) -Peter From vinay_sajip at yahoo.co.uk Fri Aug 6 05:08:14 2004 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: 6 Aug 2004 02:08:14 -0700 Subject: Logging with multiple loggers/handlers References: <10em3kass56nq9b@corp.supernews.com> <10ep21af0c9kv4c@corp.supernews.com> Message-ID: <2e37dc1.0408060108.3f3a27dd@posting.google.com> > Loggers are never instantiated directly. Instead, a module-level > function is used: > > def getLogger(name=None): ... > > If no name is specified, the root logger is returned. Otherwise, > if a logger with that name exists, it is returned. If not, a new > logger is initialized and returned. Here, "name" is synonymous > with "channel name". > > And the descriptions of the config file > (http://www.red-dove.com/python_logging.html#config): > > #The channel value indicates the lowest portion of the channel name > of the > #logger. For a logger called "a.b.c", this value would be "c". > > All of this combined to give me the impression that the name that's > passed to getLogger() should be the "lowest portion" channel name, > rather than the fully qualified name -- i.e., that I should be using > "log03" instead of "log02.log03". As it turns out, my impression was > wrong -- it's the fully qualified name that should be used. > While it's fairly likely that my interpretation of the docs is not > something that many people will come up with, I think it might be > worthwhile to expand the example sections to actually show how to use > multiple heirarchical loggers. Had there been an example to follow, I > certainly wouldn't have made this mistake. The example in http://www.red-dove.com/python_logging.html#config does show in bold the items used by the configuration API, and says that the others are just used by the GUI configurator. Perhaps "channel" was the wrong name to use for a private element in the configurator, but it's done now. From nospam at nowhere.hu Sun Aug 8 16:35:43 2004 From: nospam at nowhere.hu (Miklós) Date: Sun, 8 Aug 2004 22:35:43 +0200 Subject: Acquiring Prothon libraries [Was: Prothon is switching to the .NET platform] References: <000401c47b59$32539220$0d01a8c0@MarkVaio> <11uq0duazp1vy.1g2zjz8xyfosl.dlg@40tude.net> Message-ID: "Mark Hahn" wrote in message news:11uq0duazp1vy.1g2zjz8xyfosl.dlg at 40tude.net... > > Do you have any other ideas on how I could get a decent library in a decent > timeframe? Sorry to butt in, Mark, I don't know much about Prothon, etc. (Though I checked out the website several times and at least already downloaded a tarrball ;) ) Isn't it possible to automate or semi-automate the conversion of the Python libraries somehow? There must be a sensible mapping of class-based code to prototype-based code.. I agree with Guido that .NET is not your right path for the reasons he wrote. Best, Mikl?s > > Mark Hahn From alikakakhel3 at hotmail.com Wed Aug 18 18:02:15 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 18 Aug 2004 15:02:15 -0700 Subject: how to change the text in the title bar of the Tkinter windows References: <8f17f4bc.0408151822.1be2de2e@posting.google.com> <8f17f4bc.0408171417.456199d1@posting.google.com> <1d6cdae3.0408171904.7c625d81@posting.google.com> Message-ID: <8f17f4bc.0408181311.35e41fbb@posting.google.com> Thank you From jzgoda at gazeta.usun.pl Sat Aug 7 18:59:52 2004 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Sat, 7 Aug 2004 22:59:52 +0000 (UTC) Subject: elements of decorator syntax suggestions References: <4edc17eb.0408062125.231f7bef@posting.google.com> <41155C33.37EEB397@alcyone.com> Message-ID: Erik Max Francis pisze: >> Overloading a unary prefix operator is out. As Anthony said, vertical >> bar seemed to be the leading contender on python-dev Friday. You can >> find tedious arguments there about most of the others that would go >> for you. > > Why is | superior to @? | already has a meaning in Python, and it has > nothing to do with decorators ... at least @ has the virtue of currently > being unused in the language, and having the precedent of being used for > a similar feature in Java. Sure, use all characters, that are still not used. Fine. I propose "^". If this fails, please consider "~" and "`". Oh, and ";" is still not used in Python, what about some special meaning for that one? -- Jarek Zgoda http://jpa.berlios.de/ From abra9823 at mail.usyd.edu.au Sat Aug 14 23:43:32 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Sun, 15 Aug 2004 13:43:32 +1000 Subject: import node into document In-Reply-To: <1092539401.411ed409ae40c@www-mail.usyd.edu.au> References: <1092539401.411ed409ae40c@www-mail.usyd.edu.au> Message-ID: <1092541412.411edbe4cf51c@www-mail.usyd.edu.au> stupid me, importNode Quoting Ajay : > hi! > > I have two documents 'policy' and 'dataschema'. > how can i add a node (say, noded) from 'dataschema' as a child to a > particular node in 'policy' (say nodep) > java has importNode, is there an equivalent function in Python. if not, > how > do i go about doing it? > just doing nodep.appendChild(noded) throws an error saying they are of > different documents > doing noded.ownerDocument = nodep.ownerDocument also throws an error > saying > ownerDocument is a read-only object. > > how do i then do the import? > > thanks > > cheers > > > > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. > -- > http://mail.python.org/mailman/listinfo/python-list > ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From indigo at bitglue.com Mon Aug 2 12:50:54 2004 From: indigo at bitglue.com (Phil Frost) Date: Mon, 2 Aug 2004 12:50:54 -0400 Subject: Trimming a string In-Reply-To: <10gsotqjc2qrl54@news.supernews.com> References: <10gsmuieo65du5d@news.supernews.com> <10gsotqjc2qrl54@news.supernews.com> Message-ID: <20040802165054.GA18235@unununium.org> I couldn't agree more. The people on this list are total jerks and could use a real attitude adjustment. You might want to check out ; the user commuinity there is one of the smartest and most helpful. On Mon, Aug 02, 2004 at 08:54:34AM -0700, Double Dumbass on You wrote: > Do you feel better about yourself for having posted a smug, shithead-type > answer, troll?? > > As a matter of fact, I was in a near fatal car wreck about 7 years ago. > Suffered some brain damage. Now, I can't remember minute details such as > that which I asked. I have read the python documentation numerous times. > Sometimes, I just need a simple answer to a simple question, you simple > cocksucker. > > GO FUCK YOURSELF, it will be time well spent for you. > > "wes weston" wrote in message > news:ektPc.165630$OB3.11201 at bgtnsc05-news.ops.worldnet.att.net... > > Double Dumbass on You wrote: > > > I have a string that is 7 characters and represents file mode in > > > UNIX/LINUX from rpm: > > > > > > 0100755 > > > > > > I don't care about the 0100 portion, I am only interested in the > > > file permissions portion which is 755. How can I get three > > > characters from the string starting at the right? ( -OR- strip 4 > > > characters from the left? ) > > > > > > >>> x = "0100755" > > >>> print x[4:] > > 755 > > > > Reading the tutorial is really time well spent. > > > > wes From kleeburg at cs.ucdavis.edu Fri Aug 20 17:49:10 2004 From: kleeburg at cs.ucdavis.edu (Travis James Kleeburg) Date: Fri, 20 Aug 2004 14:49:10 -0700 Subject: Files in unix and windows Message-ID: I am trying to copy files from one directory into another using shutil.copy. I am having a problem getting a usable path using os.path.abspath because it doesnt return a string with the extra backslashes and i was wondering if there was a better system call to use? I am also looking for a system call so there wont be a problem between windows and unix. From cjw at sympatico.ca Sat Aug 21 08:59:13 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Sat, 21 Aug 2004 08:59:13 -0400 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: J2 C1 C1 Colin W. Paul McGuire wrote: [snip] From sross at connectmail.carleton.ca Thu Aug 12 07:58:53 2004 From: sross at connectmail.carleton.ca (Sean Ross) Date: Thu, 12 Aug 2004 07:58:53 -0400 Subject: decorator with ``` References: <0zISc.18837$a65.823987@news20.bellglobal.com> Message-ID: <%XISc.18841$a65.827046@news20.bellglobal.com> "Sean Ross" wrote in message news:0zISc.18837$a65.823987 at news20.bellglobal.com... [snip] > def makeDecoratorSyntax(spec=None): > ```""" Factory for new decorator syntaxes. > > Keeps all proposals in a list and will recombine > them at random if called without a spec. > """ > this = staticmethod(this) # <- transformation explicit > this.author = "somebody" # <- add attributes normally > ``` > raise NotImplementedException() [snip] It would work something like this: def triplebacktick(this, transform): this.doc = transform.doc return transform(this) def transform(f): """ Factory for new decorator syntaxes. Keeps all proposals in a list and will recombine them at random if called without a spec. """ f = staticmethod(f) f.author = "somebody" return f def makeDecoratorSyntax(spec=None): raise NotImplementedException() makeDecoratorSyntax = triplebacktick(makeDecoratorSyntax, transform) From jeff at ccvcorp.com Fri Aug 6 17:45:45 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 06 Aug 2004 14:45:45 -0700 Subject: elements of decorator syntax suggestions In-Reply-To: References: Message-ID: <10h7uvb5f5nee44@corp.supernews.com> Anthony Baxter wrote: >>3) List notation >>As I understand it, it's already decided that any implementation of >>decorators must allow for a list of decorators to be applied. So >>proposals that might be accepted must explain how this can be done. >>The options I've seen: >>* one per line (as currently) >> >> > >There's some confusion as to how the one-per-line thing is ordered. I find >it quite obvious, but I've been playing with this for a week now, so it might >just be that I know the answer now. Simply - > >@decA >@decB >@decC >def func(): > >is equivalent to > >func = decA(decB(decC(func))) > > > So one way of looking at this, then, is that the @ is (very loosely) semantically equivalent to an opening paren, with the closing paren being implied? This makes sense if one thinks of decorators as a wrapper function that contains the true function. It doesn't make quite so much sense when one is talking about decorators as meta_data_ which is attached to the function. Clearly, decorators *can* be used in either sense, and equally clearly people who want metadata _will_ use decorators for that purpose. But I suspect that at least part of the objection to the current syntax is that it doesn't fit with the model that would be expected for metadata, for which use-case function attributes seem a better fit. There's a fundamental difference between the decorator being a (possibly recursive) container for a function, and functions being a container for a set of associated data (which might be other callables), and that distinction hasn't been explicitly addressed so far as I've seen. (But note that I've only been reading discussions here, and haven't followed up on the py-dev archives.) (I *still* don't like the two-or-more-lines-per-def, but it does make decorators-before-def seem more reasonable.) Jeff Shannon Technician/Programmer Credit International From dialton3#NOSPAM.JJJJKIKK at virgilio.it Sun Aug 1 08:21:02 2004 From: dialton3#NOSPAM.JJJJKIKK at virgilio.it (Valentino Volonghi aka Dialtone) Date: Sun, 01 Aug 2004 14:21:02 +0200 Subject: IronPython-0.6 is now available! References: <278de0e.0407281353.27b6a457@posting.google.com> <4108c149$0$11038$626a14ce@news.free.fr> Message-ID: On Sat, 31 Jul 2004 13:37:35 +1000, Derek Thomson wrote: > So, why can't it just be basically: > > object.echo("hello network") > > ... as it is in CORBA and (other) XML-RPC and SOAP toolkits I've used. I don't think that calling: object.echo("hello network") instead of object.callRemote('echo', 'hello network') is making any difference at all... Actually the CORBA author is evalutaing twisted for his next needs (IIRC). Add this to the fact that doing callRemote() you are not moving any objects around, Perspective Broker let's you copy objects from the remote side to the client side and then you would be able to call object.echo('hello network') for instance. > I also have a problem with the insistence on the use of asynchronous > callbacks. In order to use the result of the RPC call later in the > main flow of my code, I have to somehow block in the main thread for > the the result to be returned from the server via the callback - this > is something that can be done for me, and is handled simply and > transparently in other RPC toolkits/mechanisms I've used. Clearly you do not know deferreds. Twisted won't wait for your response blocking the whole thread. It will just send the request and when the response comes back it will call your code for you. > I'll try to characterize this with a simple example. How would I write > something like this, where I have three distributed objects: > > i = an_object.get_value() > j = another_object.get_value() > k = yet_another_object.combine(i, j) > > ... and now finally use "k" in my code? You will use it in a callback. Obviously if you don't like callbacks you won't like twisted, but this doesn't make RPC with twisted primitive. I would say that you simply don't like the way you write code with twisted. > I could be missing something, but isn't that going to turn into a mess > of dependant callbacks in Twisted? Aren't I going to have to write a > whole lot of code that blocks until the results come back? I don't > mean this as a challenge or a judgement anything, I'd honestly like to > know - I would like to look further into Twisted but was pretty much > put off by this issue right from the start. Code won't block. You should read how deferreds work (note: they are not making your blocking code into non-blocking code, but they will be waiting in the background for an answer to a request, without blocking everything). BTW Twisted provides 2 different ways of making you blocking code non-blocking. You can use deferToThread, if you have a very long atomic operation (like querying a remote database), or you can divide your very-big-function into many different steps and call each other with reactor.callLater(0, nextStep) Which makes the call happen the next cicle in the reactor (so to allow the reactor to handle some requests in the meantime). Usually for third party modules with blocking logic the most used choice is deferToThread. But I suggest you reading the documentation from www.twistedmatrix.com which is a lot more helpful. HTH -- Valentino Volonghi aka Dialtone Linux User #310274, Proud Gentoo User Blog: http://vvolonghi.blogspot.com Home Page: http://xoomer.virgilio.it/dialtone/ From pink at odahoda.de Tue Aug 24 17:38:05 2004 From: pink at odahoda.de (Benjamin Niemann) Date: Tue, 24 Aug 2004 23:38:05 +0200 Subject: urllib hangs In-Reply-To: References: Message-ID: I don't know how it exactly works myself. But for dynamic languages like python it is part of the design that things can be changed on-the-fly: ###### foo.py # assume this module is part of the standard lib def A(): print "A called" def B(): A() # this could also be in another module # the effect would be the same ###### bar.py # this is an addon that modifies foo import foo origA = foo.A def newA(): print "before A" origA() print "after A" foo.A = newA ###### test.py import foo B() import bar B() ------------ It doesn't matter where the files are placed - once modules are found in a directory listed in os.path they are all 'equal'. This is a powerful feature (if you know how to use it correctly) and one thing that make dynamic languages dynamic. Once a module is imported, all imports result in a reference to the same module - if that one is modified, the modification will be visible everywhere where the module is imported (but this is not true for 'from foo import A', because this is a reference to the original function that cannot be changed by anyone once you get a hold of it). (My first try was to overwrite time.time(), hoping that time.ctime() would show a modified time. This didn't work, probably because both time() and ctime() make a call to a lower level function. A good example for not tampering with other peoples code unless you know how it works...) Ok, enough to explain, why you don't have to modify any file of the standard library in order to change its the behaviour. The author of timeoutsocket was in fact not clear about the location where the actual file has to be placed, probably because he assumed that everyone knows that it doesn't matter. Jay Donnell wrote: >>have you actually looked at the comments in that >>module yet? It does say exactly what you need to do... > > > I don't understand the inner workings of the socket or timeoutsocket > modules. On it's face it doesn't make sense that importing > timeoutsocket would magically override the behaviour of socket without > me doing anything else to the socket module. This appears to be what > happens, but it certainly isn't clear to someone that doesn't know how > it works. Here is what timeoutsocket says, "After this module > has been imported, all socket creation goes through this shim. ". > After reading this I was unsure if I needed to install > timeoutsocket.py into the base python distro because, again, it seems > odd that simply dropping timeoutsocket.py into my cwd and importing it > will override the behaviour of the socket module. This didn't say > "exactly what I need to do". It assumed a few things that seemed odd > to me. How does timeoutsocket.py " insert a shim into the socket > module."? What does that mean??? It wasn't clear! In the time it took > you and the other guy to criticize me you could have simply said, > "yeah, just drop it into your cwd and import it". > > P.S. - I really do appreciate the help that Benjamin gave. > > Here is what timeoutsocket says. > -------------------------------------------------------------------------- > "This module enables a timeout mechanism on all TCP connections. > After this module > has been imported, all socket creation goes through this shim. As a > result, every TCP connection will support a timeout. > > The beauty of this method is that it immediately and transparently > enables the entire python library to support timeouts on TCP sockets. > As an example, if you wanted to SMTP connections to have a 20 second > timeout: > > import timeoutsocket > import smtplib > timeoutsocket.setDefaultSocketTimeout(20) > > > The timeout applies to the socket functions that normally block on > execution: read, write, connect, and accept. If any of these > operations exceeds the specified timeout, the exception Timeout > will be raised. > --------------------------------------------------------------------- From michele.simionato at gmail.com Sat Aug 7 11:42:06 2004 From: michele.simionato at gmail.com (Michele Simionato) Date: 7 Aug 2004 08:42:06 -0700 Subject: decorators and multimethods References: <4edc17eb.0408062340.71ab270f@posting.google.com> Message-ID: <4edc17eb.0408070742.664fa9c0@posting.google.com> michele.simionato at gmail.com (Michele Simionato) wrote in message news:<4edc17eb.0408062340.71ab270f at posting.google.com>... Martin v. Lewis suggested an improvement, which involves adding the following method to the Generic_Function class: def addmethod(self, *types): "My own tiny modification to Stearns code" return lambda f: self.setdefault(types,f) The advantage is that methods definitions can go in any scope now and not only at the top level as in my original hack. My previous example read: foo = Generic_Function() @foo.addmethod(object, object, object) def _(call_next, x, y, z): return 'default' @foo.addmethod(int, int, int) def _(call_next, x, y, z): return 'all ints , ' + call_next(x, y, z) @foo.addmethod(object, object) def _(call_next, x, y): return 'just two' where I use "_" as a poor man anonymous function. I cannot reuse the name "foo" now, since @foo.addmethod(...) def foo(..): .... is really converted to def foo(..) ... foo=foo.addmethod(...)(foo) and this would correctly raise a "foo function has not attribute addmethod"! But in some sense this is better, since we avoid any confusion between the member functions and the generic function (which is implemented as a dictionary, BTW). Michele Simionato From mahesh at privacy.net Wed Aug 25 22:40:33 2004 From: mahesh at privacy.net (Mahesh Padmanabhan) Date: Wed, 25 Aug 2004 20:40:33 -0600 Subject: Call for signatories for J2 References: Message-ID: In article , "Robert Brewer" wrote: > The J2 proposal is as complete as it will ever be. > > http://www.aminus.org/rbre/python/pydec.html > > The patch is nearly complete; only the future declaration and some > document tweaks remain. It should be updated on SourceForge today or > tomorrow. > > This is a call for all who wish to sign the proposal, either for, > against, or abstaining. Please sign by either posting on > comp.lang.python (replying to this is fine), or sending email to > fumanchu at amor.org (for some of you reading this, here's a link: > mailto:fumanchu at amor.org). Please include your full name. If you reject > the proposal, please also include a short description of why you are > rejecting it. You will not receive a reply regarding the rejection or > description; it will be included for Guido's information purposes only. > > Please read the proposal carefully before signing. In particular, > carefully read the statement (for, against, or abstaining) to which you > are signing your name; each is explicit and means exactly what it says. > > Thanks again to those who have contributed in all forms. Hopefully, we > can put this decorator issue to rest soon and move on. > > > Robert Brewer > MIS > Amor Ministries > fumanchu at amor.org > > P.S. I'll be out of town from Friday morning to Sunday evening (U.S. > Pacific Time), so get your name in early. Given sufficient volume, I'll > promote this to Guido just before I leave; otherwise, I'll wait 'til > Sunday night to finish compiling names. I vote for J2. From mwh at python.net Thu Aug 19 09:34:49 2004 From: mwh at python.net (Michael Hudson) Date: Thu, 19 Aug 2004 13:34:49 GMT Subject: Generators versus Coroutines References: <7x7js1i887.fsf@ruckus.brouhaha.com> Message-ID: Nick Patavalis writes: > What!?! CPython uses the *C-stack* !!?!?! Is there a reason for this? It's easy enough to make Python calling Python not use the C stack. For all the zillion ways you can go Python -> some C -> Python, well, that's not so easy. One of the Python implementations advantages is it's relative transparency. Cheers, mwh -- > I wouldn't want to live without readline, but some of the > things it does call for the application of thumbscrews. -- me on python-dev From deetsNOSPAM at web.de Tue Aug 31 20:21:14 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Wed, 01 Sep 2004 02:21:14 +0200 Subject: file access in jythonc References: <9eabe547.0408210611.d5e54f7@posting.google.com> <9eabe547.0408301406.2543e691@posting.google.com> <9eabe547.0408311130.73beef80@posting.google.com> Message-ID: > So...are you saying it can be done? That is, a IE can access a local > file (assuming it's there, of course) using a jythonc product? > Question is -- HOW??? As I said - search google for JAVA APPLETS ACCESSING LOCAL FILES - then you can do that using jython. As a matter of fact, the whole process has to do with signing jars - nobody cares if these contain classes generated by javac, jikes, jythonc or carefully handwritten jvm bytecode.... -- Regards, Diez B. Roggisch From sbabbitt at commspeed.net Fri Aug 6 09:39:17 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Fri, 6 Aug 2004 06:39:17 -0700 Subject: Dynamic Class Creation References: Message-ID: <1091799955.309152@news.commspeed.net> "Steffen Schoen" wrote in message news:mailman.1266.1091788221.5135.python-list at python.org... > (maybe it works better with Subject ;)) > > Hi there, > my problem: i have a directory, where several python modules (classes) are > stored. > The names of these modules arent known before runtime. Now i want to parse > the Directory and create an instance of each class. I tried to handle this > with > new.instance() and new.clasobj() but this didnt really work for me. Any > Ideas ? You could try something like, >>>import os >>> import imp >>>import glob >>>modualnames = glob.glob('mydir\\*\\*.py') >>>classdict = {} >>>for i in modualnames: >>> flnm = file(i) >>> nm = os.path.splitext(os.path.basename(i))[0] >>> classdict[nm] = imp.load_module(nm ,flnm ,i,'') check out the imp module in the Global Module Index. Tom From jerf at jerf.org Sat Aug 21 23:13:45 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Sun, 22 Aug 2004 03:13:45 GMT Subject: Question about importing modules References: Message-ID: On Sat, 21 Aug 2004 14:59:36 -0400, pythos wrote: > Newbie at python (but not programming) here... > > I have a program that has "import os" at the top, and then later a call to > utime() is made. The python interpreter says "name 'utime' is not defined". > But if I change "utime(...)" to "os.utime(...)" then it works fine. Perhaps I > am expecting the "import os" statement to work the same way as "import > .*" does in Java. So is it the case that if I write "import os" > in python, then I still need to write "os.utime(...)"? Or is there something > else wrong? Thanks. Taking a slightly different tack than your other repliers which I think might be more educational in the long run, pop open a Python shell and do an "import os". That creates a "module" object in the current namespace which you can manipulate. Example: Python 2.3.4 (#1, Jun 8 2004, 17:41:43) [GCC 3.3.3 20040217 (Gentoo Linux 3.3.3, propolice-3.3-7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os >>> dir(os) ['EX_CANTCREAT', 'EX_CONFIG', 'EX_DATAERR', 'EX_IOERR', 'EX_NOHOST', 'EX_NOINPUT ', 'EX_NOPERM', 'EX_NOUSER', 'EX_OK', 'EX_OSERR', 'EX_OSFILE', 'EX_PROTOCOL', 'E X_SOFTWARE', 'EX_TEMPFAIL', 'EX_UNAVAILABLE', 'EX_USAGE', 'F_OK', 'NGROUPS_MAX', ... whole lotta other stuff ... 'stat', 'stat_float_times', 'stat_result', 'statvfs', 'statvfs_result', 'strerr or', 'symlink', 'sys', 'sysconf', 'sysconf_names', 'system', 'tcgetpgrp', 'tcset pgrp', 'tempnam', 'times', 'tmpfile', 'tmpnam', 'ttyname', 'umask', 'uname', 'un link', 'unsetenv', 'utime', 'wait', 'waitpid', 'walk', 'write'] "os" is an object that can be passed around like anything else. (Though I have yet to ever have need to pass around a module object I can imagine rare cases where it might be useful.) That's why you can also use "import" in a function, and the module object will be local to the function. (You can not use "from os import *" for various technical reasons, but that's usually not useful anyhow.) "from os import *" loads the "os" object, then walks it and loads its contents into your local namespace. This is a particularly bad idea for "os" because it has function names like "open", "path", "wait", "write", and a lot of other function names you're likely to collide with. It is rarely a good idea for code, though I will confess to sometimes using "from constants import *" in large programs, leaning on the ALL_CAPS convention to indicate "constantness". From jeff at ccvcorp.com Mon Aug 9 16:49:40 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Mon, 09 Aug 2004 13:49:40 -0700 Subject: Decorators In-Reply-To: References: <%A8Rc.50217$Vm1.1280580@news20.bellglobal.com> Message-ID: <10hfoqa9cj3e356@corp.supernews.com> Dan Bishop wrote: >"Colin J. Williams" wrote in message news:<%A8Rc.50217$Vm1.1280580 at news20.bellglobal.com>... > > >>Christopher T. King suggested that "we're trying to kill too many birds >>with one stone". >> >>http://groups.google.com/groups?q=stone+birds+group:comp.lang.python&hl=en&lr=&ie=UTF-8&selm=Pine.LNX.4.44.0408050856390.31290-100000%40ccc9.wpi.edu&rnum=1 >> >>He goes on to suggest three needs which decorators serve. Are these the >>only purposes which are envisaged for decorators? >> >> > >If I understand correctly, they'd be useful for anything where you'd >now use the syntax > >function = decorator(function) > > Many of the uses I'm seeing proposed for decorators would fit better into the current syntax: def func( ... ) pass dosomething(func) In other words, they're not specifically changing the behavior of the function, but they are using the (name and/or address of the) function in some other context. The modification of the function (or method) itself is an unnecessary side effect. Whether this distinction matters is obviously a purely aesthetic matter, since obviously the decorator can rebind the name to the original function object instead of a wrapping-function object. But still, it does suggest that this concept is indeed being put to multiple orthogonal purposes. Jeff Shannon Technician/Programmer Credit International From me at privacy.net Mon Aug 23 09:12:53 2004 From: me at privacy.net (Dan Sommers) Date: 23 Aug 2004 09:12:53 -0400 Subject: J2 proposal: keyword References: Message-ID: On Mon, 23 Aug 2004 01:36:31 -0700, "David Pokorny" wrote: > There must be some cognitive-visual thingamajig going on here because I find > using: > staticmethod synchronized memoize > def bar(foo): > "upends the established order of metasyntactic keywords" > pass > much more readable than > @staticmethod synchronized memoize > def bar(foo): > "upends the established order of metasyntactic keywords" > pass > [I think it has something to do with the traffic jam at the left margin.] I agree. That traffic jam seems to promote staticmethod to the sole decorator, and demote synchronized and memoize to sub-decorators of staticmethod. IMO, simply adding a space after the pie puts all three decorators "at the same level": @ staticmethod synchronized memoize That said, I'd prefer a keyword and a colon over that pie-thingy any day. Regards, Dan -- Dan Sommers Never play leapfrog with a unicorn. From beliavsky at aol.com Tue Aug 10 09:49:38 2004 From: beliavsky at aol.com (beliavsky at aol.com) Date: 10 Aug 2004 06:49:38 -0700 Subject: pro python paper References: <305aa162.0408091905.5bce8f9a@posting.google.com> Message-ID: <3064b51d.0408100549.213dad5@posting.google.com> ccdetail at gmail.com (ccdetail) wrote in message news:<305aa162.0408091905.5bce8f9a at posting.google.com>... > http://www.journyx.com/pdf/PythonAtAGlance.pdf > > the above paper is a response to some of our prospects complaints > > they were asking us why we use python > > thought you guys might be interested > > http://journyx.com/clf I think the paper exaggerates the virtues of Python relative to other languages, reducing the credibility of the authors. The paragraph in the Python myths section "It has no compiler to native code, which means Python programs run slower. True, it does not compile. That does not mean, however, that Python programs run slower. If you are tracking the speed of quarks or landing the space shuttle, you might want to write in Assembly or some other very low-level language. Other than that, a standard business application written in Python will run every bit as well as one written in any other language." pretends that the main alternative to Python is Assembly, or some other "very low-level language". Have the authors not heard of C++ (with the Standard Template Library) or Fortran 95 (with multidimensional arrays and associated intrinsic functions)? It is more honest and credible to admit that a Python program often is slower than one in a compiled language, but that reduced programming time in Python often outweighs this deficit. From mus at thamers.com Fri Aug 13 17:30:50 2004 From: mus at thamers.com (Mustafa Thamer) Date: 13 Aug 2004 14:30:50 -0700 Subject: can't reload with PEP 302 import hooks Message-ID: <541c9664.0408131330.3a536b29@posting.google.com> Hi, I'm using import hooks according to PEP 302, in order to load python files from a game PAK file. The game is C++ using embedded and extended Python (v2.33) and Boost. The importing works fine, but after modules are imported I can't reload them. I've tried 'reload(foo)' and 'PyImport_ReloadModule(pModPtr)', but both return 'ImportError: No module named foo'. Is it safe to assume that reload doesn't respect the import hook? That seems like a problem. Is there any work-around? thanks Here is my hook object code: class myImportHandler: def find_module(self, fullname, path=None): return self # returns the loader object def _get_code(self, fullname): # load code from game PAK if (fullname in sys.builtin_module_names): return False,None codeString = loadImportModule(fullname) # CALLING C++ FUNCTION bIsPackage = False # not using PACKAGES if len(codeString): codeString2 = codeString.replace('\\r\','\') code = compile(codeString2, fullname, 'exec') else: code=None return bIsPackage,code def normal_import(self, fullname): # for built-ins file,pathname,desc=imp.find_module(fullname) return imp.load_module(fullname,file,pathname,desc) def load_module(self, fullname): try: mod = sys.modules[fullname] # check if module is already loaded in sys.module? except KeyError: ispkg, code = self._get_code(fullname) if code==None: # failed importing from game PAK return self.normal_import(fullname) mod = imp.new_module(fullname) # create new module sys.modules[fullname] = mod mod.__file__ = '<%s>' % self.__class__.__name__ mod.__loader__ = self if ispkg: mod.__path__ = [] exec code in mod.__dict__ return mod From ed-no at spam-eepatents.com Fri Aug 13 13:33:47 2004 From: ed-no at spam-eepatents.com (Ed Suominen) Date: Fri, 13 Aug 2004 10:33:47 -0700 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: <-_2dnZbL1qv6ZoHcRVn-vw@centurytel.net> Dave Brueck wrote: > beliavsky at aol.com wrote: > >> One of the most commmon reasons programmers cite for not trying Python >> is that indentation determines the program flow -- they think its >> weird. > > Yes, that is commonly cited. From the programmer's perspective, > indentation implies program flow in nearly *all* modern languages. The > difference is that in Python the compiler believes you. > >> I think programmers who actually try Python adapt quickly and >> do not find the indentation rules to be a problem. > > Yep! Exactly true in my case: Day 1: "Wow, that's weird, but I guess I'll give it a try." Day 2: "Hey, this is cool, and the code looks a LOT cleaner without all of those braces strewn around." Day 3: "Of COURSE whitespace is part of the code. It's part of the source file, duh!" --- Ed Suominen Registered Patent Agent Open-Source Software Author (yes, both...) Web Site: http://www.eepatents.com From jepler at unpythonic.net Tue Aug 17 22:06:45 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 17 Aug 2004 21:06:45 -0500 Subject: can tarfile maintain directory structure? In-Reply-To: References: Message-ID: <20040818020645.GC5422@unpythonic.net> You can use os.walk (or os.path.walk for older versions of Python) to recurse a directory tree. Here's a simple script to use tarfile and os.walk: import tarfile, sys, os t = tarfile.TarFile(sys.argv[1], "w") for f in sys.argv[2:]: for dirpath, dirnames, filenames in os.walk(f): for f in filenames: f = os.path.join(dirpath, f) print "Adding", f t.add(f) t.close() Here's a sample session with it: * Creating a simple directory structure $ mkdir a $ touch a/file.txt $ mkdir a/subdir $ touch a/subdir/subfile.txt * Invoking the script $ python ~/mktar.py test.tar a Adding a/file.txt Adding a/subdir/subfile .txt * Checking on the results $ tar tvf test.tar -rw-rw-r-- jepler/jepler 0 2004-08-17 21:00:57 a/file.txt -rw-rw-r-- jepler/jepler 0 2004-08-17 21:01:03 a/subdir/subfile.txt I suspect that to get compressed output would involve use of gzip.open and the 3-argument TarFile constructor, something like import gzip g = gzip.open(sys.argv[1], "w") t = tarfile.TarFile(sys.argv[1], "w", g) ... indeed, this seems to work for me. $ python ~/mktargz.py test.tar.gz a Adding a/file.txt Adding a/subdir/subfile.txt $ file test.tar.gz test.tar.gz: gzip compressed data, was "test.tar", max compression Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From peter at engcorp.com Wed Aug 4 23:00:33 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 04 Aug 2004 23:00:33 -0400 Subject: cgi script headers - help In-Reply-To: References: Message-ID: <38ednYf1NLxPP4zcRVn-uA@powergate.ca> Ajay wrote: > hi! > > i am generating a file on the fly and making a user download it. > print "Content-Type: application/model\n\n" > print "Content-Disposition: attachment; filename=modeldef3\n" > print str > > i set the Content-Disposition to force a download dialog box and also give > the file a name. > however when i view the headers sent by my script, i have only > HTTP/1.1 200 OK > Date: Thu, 05 Aug 2004 02:26:48 GMT > Server: Apache/1.3.19 (Unix) > Connection: close > Content-Type: application/model > > why isn't the Content-Disposition header coming up? Probably because the previous line was terminated with three (3) newlines, thus marking the end of the header section... Note that print includes a newline normally, so including any other newlines will result in at least a double newline, which is the delimiter between header and body. -Peter From fumanchu at amor.org Mon Aug 23 01:19:31 2004 From: fumanchu at amor.org (Robert Brewer) Date: Sun, 22 Aug 2004 22:19:31 -0700 Subject: J2 paper 0.2.1 Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E36@exchange.hqamor.amorhq.net> The first draft of the J2 proposal is ready. You can read it here: http://www.aminus.org/rbre/python/pydec.html At this point, I am looking for comments regarding the proposal. Once I believe I have addressed a sufficient number of concerns, I will freeze the document and call for signatories, both for and against, then send it to Guido. Until that time, expect the draft to change multiple times each day (there's a meta tag with the version number if you care to check). In this thread, please do not introduce discussions regarding syntaxes other than J2 and A1. Limit your comments to the three arguments, literary critique, and praise for Mr. Sparks who is providing the implementation. Oh, and somebody let me know if you rampaging lot crush my little server. ;) Robert Brewer MIS Amor Ministries fumanchu at amor.org From tim.peters at gmail.com Sat Aug 14 16:24:54 2004 From: tim.peters at gmail.com (Tim Peters) Date: Sat, 14 Aug 2004 16:24:54 -0400 Subject: Generators versus Coroutines In-Reply-To: <972ec5bd.0408141032.385fe115@posting.google.com> References: <972ec5bd.0408141032.385fe115@posting.google.com> Message-ID: <1f7befae0408141324569d467e@mail.gmail.com> [Timothy Fitz] > It seems to me that in python, generators are not truly coroutines. Yes, formally speaking Python generators are semi-coroutines. > I do not understand why. Please read the PEP: http://www.python.org/peps/pep-0255.html > What I see is that generators are used almost exclusively for > generation of lists just-in-time. Side effects are frowned upon. Simple uses are naturally most common. > Coroutines, in contrast, are like split functions where > side effects are often as important or more important than return > values. I am currently writing a real time strategy game where I have > visual effects and use generators as coroutines which yield after > processing a single frame of the effect. I can easily make an object > rotate indefinitely with a scant four or five lines of code, all of > which is in one place. So knowing that the difference between a > generator and a coroutine is minor, I come (in a very roundabout way) > to my issue. Why can I use "return" without an expression and it > implicitly returns None If you explicitly intend to return None as a value, it's terrible practice to spell that as return instead of as return None It's equally terrible practice to rely on that "falling off the end" of a Python function returns None, when you expliclty intend to return a None value. Plain "return" is intended to be used in Python only when *conceptually* no value is being returned, as in "a subroutine" as opposed to "a function". The language doesn't enforce the latter distinction, but it's intended all the same. > but I can't do the same thing with "yield" ? It's the purpose of "yield" to deliver a value. There was no intent that it be possible to yield without delivering a value. If you want to deliver the value None, then say yield None If you want a concept of yielding without delivering a value, that's simply not a use case Python's generators intended to address. If you wish, you can adhere to a *convention* that "yield None" (or "yield False", or "yield 42", ...) means "I'm not really delivering a value". From bulatov at engr.orst.edu Tue Aug 3 03:33:00 2004 From: bulatov at engr.orst.edu (Yaroslav Bulatov) Date: 3 Aug 2004 00:33:00 -0700 Subject: Re_: Best way to run ipython inside of emacs shell? Message-ID: <4d642979.0408022332.4380ad23@posting.google.com> > Hi, > > Equis Uno wrote: > > > I use meta-x shell to start a shell and then once I see a shell > > prompt I enter the python command and I get a well-behaved python > > shell inside of emacs. > > > > I'm trying to figure out the best way to run ipython inside of emacs. I had the same problem. It has to do with ipython.el not finding the IPython executable. To fix it, open ipython.el, and replace line (when (executable-find "ipython") with (when (executable-find "ipython.bat") Next, add file ipython.bat to your path containing something like the following: C:\Python23\python.exe "C:\Program Files\IPython\IPython_shell.py" Unfortunately it doesn't seem to work right on windows. The prompts are missing so it's almost unusable. Yaroslav From nav+posts at bandersnatch.org Fri Aug 6 10:04:59 2004 From: nav+posts at bandersnatch.org (Nick Vargish) Date: 06 Aug 2004 10:04:59 -0400 Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) References: <10h24oace15n97a@news.supernews.com> Message-ID: Ronald Oussoren writes: > Why do you dislike it? It has a negative impact on readability. It's ugly. It modifies a declaration outside the declaration. It feels unpythonic. Of course these are subjective responses, and my weighting of the importance of these complaints may not match yours. From the comments in this newsgroup, I don't have the feeling that I'm alone in some or all of these criticisms. Nick -- # sigmask || 0.2 || 20030107 || public domain || feed this to a python print reduce(lambda x,y:x+chr(ord(y)-1),' Ojdl!Wbshjti!=obwAcboefstobudi/psh?') From PPNTWIMBXFFC at spammotel.com Thu Aug 26 10:37:30 2004 From: PPNTWIMBXFFC at spammotel.com (Marco Aschwanden) Date: Thu, 26 Aug 2004 16:37:30 +0200 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: > What does the Kaj ... phrase mean? > "You are dumb", "Your joke is dumb", ...? >> Bonvolu ne s:ercu pri nekonatoj aferoj. "Xah Lee" certe - pro manko de Please don't make jokes about unknown things. "Xah Lee" for certain - [for esperanto] failing to have the >> Ikso - ne estas esperanto. Kaj via s:erco nur s:tulta estas. letter 'y' - is not esperanto. And your joke is nothing but stupid. Saluton, Marco From ptmcg at austin.rr._bogus_.com Mon Aug 23 22:09:41 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Tue, 24 Aug 2004 02:09:41 GMT Subject: newbie: confused with example in Learning Python 2nd Edition:cananyone give a hint References: Message-ID: "Paul McGuire" wrote in message news:RdxWc.15249$v86.14245 at fe2.texas.rr.com... > "Robert Brewer" wrote in message > news:mailman.2254.1093312305.5135.python-list at python.org... > Porky Pig Jr wrote: > > > Hint: Python doesn't have variables like other languages do. The line: > > self._data = list(data) > > does not make a copy of "data". Instead, it binds a new name > (self._data) to the same object which the name "data" refers to. > > > FuManChu > ====================== > > Er? I thought list(data) called the list constructor to create a copy of > data, and bind the new list to self._data. That's why push and pop calls > update the internal _data list without changing the original list. > > -- Paul > > Well, this *is* a screwy example, and I question why this twisted thing is in a beginner text. I'm not even sure I really like the style anyway. Here is the original Stack class posted by the OP: >>> class Stack: ... def __init__(self, data): ... self._data = list(data) ... self.push = data.append ... self.pop = data.pop ... As it turns out, this stack does not even need the assignment statement to self._data at all. Here is a fuller console example: >>> class Stack: ... def __init__(self, data): ... self.push = data.append ... self.pop = data.pop ... >>> s = Stack([1,2,3]) >>> >>> s.push(4) >>> s.pop() 4 Where did the 4 get pushed to/popped from?! This Stack class doesn't have *any* member variable to store the list contents! In fact, the stack is stored in the input list - in this case, the temporary list literal [1,2,3]. This is a bit clearer if we pass in a variable instead of a literal list: >>> baselist = [1,2,3] >>> s = Stack(baselist) >>> s.push(4) >>> baselist [1, 2, 3, 4] I can't say I'm thrilled about this class that silently takes ownership of the input list. I suspect that the book example has a typo, and that the class should really read: >>> class Stack: ... def __init__(self, data): ... self._data = list(data) ... self.push = self._data.append ... self.pop = self._data.pop Now things are better behaved: >>> s = Stack(baselist) >>> baselist [1, 2, 3, 4] >>> s.pop() 4 >>> baselist [1, 2, 3, 4] >>> s._data [1, 2, 3] HTH, -- Paul From grante at visi.com Mon Aug 30 15:45:00 2004 From: grante at visi.com (Grant Edwards) Date: 30 Aug 2004 19:45:00 GMT Subject: Size of a remote URL References: Message-ID: <413383bc$0$65574$a1866201@newsreader.visi.com> On 2004-08-30, Justin wrote: > I tried ethereal however the problem is I don't knwo how to > read the packets correctly to udnerstand where the requests > are. Left click on any of the packets and select "follow TCP stream". It will show you a window containing requests in red and replys in blue (or vice versa, I forget). -- Grant Edwards grante Yow! I smell like a wet at reducing clinic on Columbus visi.com Day! From abra9823 at mail.usyd.edu.au Sat Aug 14 22:25:58 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Sun, 15 Aug 2004 12:25:58 +1000 Subject: xml attributes question Message-ID: <1092536758.411ec9b6cdacb@www-mail.usyd.edu.au> hi! i am trying to print the keys of a NamedNodeMap which contains the attributes of a element. for the element, CatalogExample i expect attribs = plist[0].attributes attribs.keys() to print "ref" #plist[0] is the data element shown above It however prints the following [(None, u'ref')] why? thanks cheers ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From alikakakhel3 at hotmail.com Fri Aug 20 22:16:50 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 20 Aug 2004 19:16:50 -0700 Subject: I would really like the code for a dome in vpython References: <8f17f4bc.0408181349.46c34b2@posting.google.com> Message-ID: <8f17f4bc.0408201816.13d537a6@posting.google.com> Arthur wrote in message news:... > On 18 Aug 2004 14:49:54 -0700, alikakakhel3 at hotmail.com (Ali) wrote: > > >Please anyone I would really like the code for makinga dome in > >vpython. I would like to be able to adjust he color, axis, radius, and > >pos. > > > You will lucky to find something readymade for VPython. > > This looks like it would be helpful for finding dome corrdinates, > which you can then use to plug-in to VPython: > > http://www.applied-synergetics.com/ashp/html/domes.html > > And Kirby is probably an excellent source of information in the area > of the intersection of domes/Python/VPython. He knows a good deal > about each of these things. > > I don't know whether he monitors this list. You might try posting to > edu-sig at python.org which I know he monitors, to see if he has > something to suggest. > > I might have some other suggestions if a understood what you were > trying to accomplish, and why. > > > Art I went to the link you gave but the link to download the software is broken. :( Please Help From joshway_without_spam at myway.com Wed Aug 18 15:44:47 2004 From: joshway_without_spam at myway.com (JCM) Date: Wed, 18 Aug 2004 19:44:47 +0000 (UTC) Subject: Embedding Python in Python References: <7xu0v0l2be.fsf@ruckus.brouhaha.com> <7x3c2kkzn8.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > JCM writes: >> If you're concerned about security, another possibility is to parse >> the user's code and look for anything potentially dangerous. You'll >> need to be aggressive, but I believe it's possible. For example, >> disallow exec statements, the identifier "eval", any identifier of >> __this__ form, import statements, etc. This is overly restrictive, >> but it will provide security. > By the time you're done with all that, you may as well design a new > restricted language and interpret just that. > Hint: > e = vars()['__builtins__'].eval > print e('2+2') > Even Java keeps getting new holes found, and Python is not anywhere > near Java when it comes to this kind of thing. I don't think it's as difficult as you think. Your snippet of code would be rejected by the rules I suggested. You'd also want to prohibit other builtins like compile, execfile, input, reload, vars, etc. From kyleroot at gmail.com Sat Aug 7 10:28:39 2004 From: kyleroot at gmail.com (Kyle Root) Date: Sat, 07 Aug 2004 14:28:39 GMT Subject: Questions about parsing XML In-Reply-To: References: <%T4Rc.150$Iv.46@trndny03> Message-ID: Jarek Zgoda wrote: > > Python's xmllib (regular expression based parser) is not the same > software as libxml2 (GNOME XML library) ;). > > If you need full support for XPath, XPointer, XInclude or namespaces > (see http://www.xml.com/pub/a/2004/06/30/py-xml.html) I recommend using > libxml2. Some people say that some of its parsers are also faster than > original J. Clark's expat (although not as easy to use as expat or > expat-like SAX parser from libxml2). > Okay thank you very much! I like libxml2's docs better than the Python Library Reference anyways. :D From rnichol_rrc at yahoo.com Tue Aug 24 02:07:01 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Tue, 24 Aug 2004 01:07:01 -0500 Subject: age of Python programmers In-Reply-To: References: <20040819231139.D039A1E4003@bag.python.org> Message-ID: Roel Schroeven wrote: > Sakesun Roykiattisak wrote: > >> BTW, The histrogram suggest that python is not being used as the first >> programming language as much as it should be. > > > Indeed. > > Also the relatively high number of older programmers (> 50) surprises > me. Personnaly I know only one programmer in that age group, all others > are less than 40 years old. Possibly the fraction of older programmers > is larger under Python programmers compared to other languages? Maybe > that shouldn't be surprising: wisdom comes with age, as they say. > Although I am suprisd at that high ages of a lot of the people here I'm not really suprised that the average is higher that would typically be expected as I've found that when I mention the word "newsgroup" to the other students when I was going to school (and even now with supposedly other graduates), they just give me a confused look. Perhaps it's just where I went to school though or where I hang out, but it can't all be coincidence. From grzegorz at ee.ualberta.ca Fri Aug 6 16:18:11 2004 From: grzegorz at ee.ualberta.ca (Grzegorz Dostatni) Date: Fri, 6 Aug 2004 16:18:11 -0400 Subject: Extending python. In-Reply-To: References: Message-ID: For license reasons I cannot link to the library dynamically. It has to be compiled into the python executable. I do have the source available for the libraries, but the logistics would be a lot easier if I could simply use the object files. Greg My programs use cvs, my mine uses pine. - Me On Fri, 6 Aug 2004, Larry Bates wrote: > Is the C that you wish to call located in a .DLL? > If so, I can possibly help. > > Larry Bates > Syscon, Inc. > > "Grzegorz Dostatni" wrote in message > news:Pine.LNX.4.44.0408061307140.8941-100000 at e5-05.ee.ualberta.ca... > > > > Followup. > > > > Thanks, I'll re-read this again. > > > > Small change. I've managed to extend python with a small module (just > > using the .o file) under Linux. It appears that my problems are a bit more > > windows centric. Anyone willing and able to help me with that? > > > > Greg > > > > "In theory, there is no difference between theory and practice. > > But, in practice, there is." > > - Jan L.A. van de Snepscheut > > > > > > On Fri, 6 Aug 2004, Batista, Facundo wrote: > > > > > Maybe this will help you: > > > > > > http://www.python.org/doc/faq/extending.html > > > > > > . Facundo > > > > > > #- -----Mensaje original----- > > > #- De: Grzegorz Dostatni [mailto:grzegorz at ee.ualberta.ca] > > > #- Enviado el: Viernes, 06 de Agosto de 2004 13:35 > > > #- Para: python-list at python.org > > > #- Asunto: Extending python. > > > #- > > > #- > > > #- > > > #- Cheers. > > > #- > > > #- More questions. > > > #- Let's say I'm trying to extend python with a c module. That > > > #- module cannot > > > #- be dynamically loaded (for reasons outside my control). I > > > #- have to create a > > > #- custom python executable (or more likely custom python library). > > > #- How would I do that? Is there documentation on that > > > #- somewhere? Most of > > > #- what I've seen was for dynamic loading. > > > #- > > > #- 2nd Step: > > > #- Let's say I'm doing it under windows, using Visual Studio. Is there > > > #- anything I have to be aware of? > > > #- > > > #- 3rd Step: > > > #- Let's say I don't have the source available. I do have the > > > #- object files, > > > #- the resulting libraries and the header files though. > > > #- > > > #- Greg > > > #- > > > #- "The optimist proclaims that we live in the best of all > > > #- possible worlds, > > > #- and the pessimist fears this is true." > > > #- - James Branch Cabell > > > #- > > > #- > > > #- -- > > > #- http://mail.python.org/mailman/listinfo/python-list > > > #- > > > > > > > > From max at theslimmers.net Sun Aug 15 04:35:48 2004 From: max at theslimmers.net (max) Date: 15 Aug 2004 01:35:48 -0700 Subject: ADOdbapi converting all data to strings Message-ID: <4f55e45a.0408150035.1298f0e9@posting.google.com> I am trying to access a foxpro database, using odbc all is well except that dates prior to 1970 are not returned as valid usable data, so would like to use ADO. When I select data containing numbers (long or float) they are converted and returned as unicode strings. Dates are returned as datetime.date which is great. Is there any way to change this behavior other than to explicitly change back all fields using cursor.description information. thanks, max From cjw at sympatico.ca Mon Aug 9 20:29:59 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Mon, 09 Aug 2004 20:29:59 -0400 Subject: Decorators In-Reply-To: <10hfoqa9cj3e356@corp.supernews.com> References: <%A8Rc.50217$Vm1.1280580@news20.bellglobal.com> <10hfoqa9cj3e356@corp.supernews.com> Message-ID: <3GURc.11274$Mq1.610387@news20.bellglobal.com> Jeff Shannon wrote: > Dan Bishop wrote: > >> "Colin J. Williams" wrote in message >> news:<%A8Rc.50217$Vm1.1280580 at news20.bellglobal.com>... >> >> >>> Christopher T. King suggested that "we're trying to kill too many >>> birds with one stone". >>> >>> http://groups.google.com/groups?q=stone+birds+group:comp.lang.python&hl=en&lr=&ie=UTF-8&selm=Pine.LNX.4.44.0408050856390.31290-100000%40ccc9.wpi.edu&rnum=1 >>> >>> >>> He goes on to suggest three needs which decorators serve. Are these >>> the only purposes which are envisaged for decorators? >>> >> >> >> If I understand correctly, they'd be useful for anything where you'd >> now use the syntax >> >> function = decorator(function) >> >> > > Many of the uses I'm seeing proposed for decorators would fit better > into the current syntax: > > def func( ... ) > pass > dosomething(func) > > In other words, they're not specifically changing the behavior of the > function, but they are using the (name and/or address of the) function > in some other context. The modification of the function (or method) > itself is an unnecessary side effect. It seems to me that PEP 318 is intended to be transformational, as in Dan Bishop's examples. The purpose is to flag the transformation at the head of the function declaration, ie. to give notice to the reader that the function is not what it seems to be. One of the issues is whether the flagging should occur before or after the function signature. I can see some merit in the flagging and feel that it better after the signature, where the function name is, in a sense known. Another issue is whether a single character or a keyword is used to flag the 'decorator'. One post suggested that the pie would be better used as a replacement for self. There is also the question of whether 'decorator', a term which is used in everyday langage as indicating adornment, is the best choice for a transformation. > Whether this distinction matters is obviously a purely aesthetic matter, > since obviously the decorator can rebind the name to the original > function object instead of a wrapping-function object. But still, it > does suggest that this concept is indeed being put to multiple > orthogonal purposes. > Jeff Shannon > Technician/Programmer > Credit International > Colin W. From gloonie at earthlink.net Sat Aug 14 15:51:25 2004 From: gloonie at earthlink.net (Glenn R Williams) Date: Sat, 14 Aug 2004 19:51:25 GMT Subject: shelve/bsddb broken in Python 2.3.3 (SuSe 9.1)? Message-ID: <13uTc.20255$nx2.9301@newsread2.news.atl.earthlink.net> Has anybody gotten shelve to work under SuSE 9.1? I have SuSe 9.1, Python 2.3.3.85, db 4.2.52, and bsddb3-4.2.4. When I try to create a shelve, I get errors galore, Here's the traceback: Traceback (most recent call last): File "", line 1, in -toplevel- d=shelve.open('mydbm',flag='c') File "/usr/lib/python2.3/shelve.py", line 231, in open return DbfilenameShelf(filename, flag, protocol, writeback, binary) File "/usr/lib/python2.3/shelve.py", line 212, in __init__ Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback, binary) File "/usr/lib/python2.3/anydbm.py", line 83, in open return mod.open(file, flag, mode) File "/usr/lib/python2.3/dbhash.py", line 16, in open return bsddb.hashopen(file, flag, mode) File "/usr/lib/python2.3/bsddb/__init__.py", line 192, in hashopen d.open(file, db.DB_HASH, flags, mode) DBError: (38, 'Function not implemented -- process-private: unable to initialize environment lock: Function not implemented')' TIA, Glenn -- Glenn R Williams From ptmcg at austin.rr._bogus_.com Thu Aug 5 18:32:16 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Thu, 05 Aug 2004 22:32:16 GMT Subject: Decorator syntax References: <38ednYT1NLz1P4zcRVn-uA@powergate.ca> Message-ID: "Andrew Bennetts" wrote in message news:mailman.1182.1091694251.5135.python-list at python.org... > On Thu, Aug 05, 2004 at 04:25:13AM +0000, Paul McGuire wrote: > [...] > > > > I fear that $, ^ and ~ are just around the corner. > > No need to fear: ^ and ~ are already there. > > >>> ~1 > -2 > >>> 1^2 > 3 > > -Andrew. > Ooops, duh! I guess I meant "$ and ?". As this discussion wears on (and on...), there are several comments to the effect of "let's save @ for something really important, and not waste it on decorators." Personally, I've enjoyed the clean look of Python source that isn't splattered with special @'s and $'s. I *don't* want to save @ for something important, I'd prefer to see it kept out of the syntax altogether, along with $. (Oddly, I don't find ? near as ugly, but I wouldn't suggest it as an alternative to @ as a decorator-introducer.) I don't see this as merely a personal style choice either, as in "if you don't like @'s, don't use @'s" - it seems to me that the emergence of a decorator syntax means that I'll at some point have to use them to replace the deprecated staticmethod and classmethod keywords. @ and $ evoke the old days of job control commands and all-caps coding in Cobol and FORTRAN - anyone care for code like: @SYNCHRONIZED DEF UPDATE_COUNT(SELF): SELF.COUNT = SELF.COUNT + 1 It seems to me that historically Python has eschewed using special characters in other cases. For instance, rather than mark instance methods of a class with some magic character (such as '>', say), they contain an explicit 'self' argument (whether this is good or ill is secondary - it IS what Python does). There is no special use of '^' as a shortcut for 'return' (as in Smalltalk's ubiquitous "^self") - one writes "return self". Please reconsider the "def f() [classmethod]:" construct. Instead of invoking a special punctuation character, it uses context and placement, with familiar old []'s, to infuse the declaration of a function with special characteristics. If this causes def lines to run longer than one line, perhaps the same rule that allows an unmatched "(" to carry over multiple lines without requiring "\" continuation markers could be used for unmatched "["s, as in: def f() [ staticmethod, synchronized, alphabetized, supersized, returns('d') ]: "If I'd wanted mucilage, I'dve ordered mucilage." - Humphrey Bogart, "All Through the Night" If I'd wanted to write in Java, I'dve written in Java. Keep Python Beautiful. -- Paul From adurdin at gmail.com Thu Aug 19 06:11:18 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Thu, 19 Aug 2004 20:11:18 +1000 Subject: age of Python programmers In-Reply-To: <4124724C.8040001@chamonix.reportlab.co.uk> References: <4124724C.8040001@chamonix.reportlab.co.uk> Message-ID: <59e9fd3a04081903113b368906@mail.gmail.com> On Thu, 19 Aug 2004 10:26:36 +0100, Robin Becker wrote: > > so far with a count of 74 the average is 35.72 Well, let me lower that just a tad: I'm 24. From http Thu Aug 26 17:12:28 2004 From: http (Paul Rubin) Date: 26 Aug 2004 14:12:28 -0700 Subject: Call for signatories for J2 References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> <7xoekx4wit.fsf@ruckus.brouhaha.com> <1gj5cs7.wqxd1s1ec69umN%aleaxit@yahoo.com> <7xfz69oc1f.fsf@ruckus.brouhaha.com> <1gj5eom.gbo9f512upip0N%aleaxit@yahoo.com> Message-ID: <7x1xhtd2o3.fsf@ruckus.brouhaha.com> aleaxit at yahoo.com (Alex Martelli) writes: > Type declarations make me cringe, but if I *had* to have them then 'b as > int' is the best syntax I could imagine for them offhand. b:int worked ok in Pascal. From M.Waack at gmx.de Wed Aug 25 13:19:06 2004 From: M.Waack at gmx.de (Mathias Waack) Date: Wed, 25 Aug 2004 19:19:06 +0200 Subject: Capturing exceptions? References: Message-ID: Dfenestr8 wrote: > What's the easiest way to capture the traceback from an exception, > and write it to a file? Ideally, I'd like to be able to do > something like: > >>try: >>main() >>except: >>write the traceback to a file Have a look at the traceback module. Mathias From ville at spammers.com Fri Aug 27 11:06:16 2004 From: ville at spammers.com (Ville Vainio) Date: 27 Aug 2004 18:06:16 +0300 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> Message-ID: >>>>> "Kjetil" == Kjetil Torgrim Homme writes: Kjetil> what do you think? should I write a PEP? No - you should see C:\Python23\Tools\Scripts\pindent.py (if you are on windos) or snatch the file from the source distribution. -- Ville Vainio http://tinyurl.com/2prnb From pm_mon at yahoo.com Thu Aug 19 09:33:35 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Thu, 19 Aug 2004 09:33:35 -0400 Subject: PEP 318: Can't we all just get along? In-Reply-To: References: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: Anthony Baxter wrote: > On Thu, 19 Aug 2004 06:35:18 -0400, Paul Morrow wrote: > >>Unless of course you want a method to be private/semi-private. How do >>you feel about the way we can create/manipulate lists and dictionaries >>using special (magical) syntax? Why is that different (acceptable)? > > > Look, name-mangling is horrid, and I don't think anyone's defending it. But > at the same time, "name mangling is there" is not an argument for extending > the horror to a whole new level. > I disagree. It's an effective name-hiding technique. Simple + Effective = Good. > Name mangling only occurs when you create a method with two leading > underscores, and no trailing ones. Your proposal would hit _every_ _single_ > 'def'. It's nasty, it's unpythonic, and there's approximately _zero_ chance of > it ever going into the language. Having said that, it's perfectly feasible to do > it with a metaclass, and if you want to use it in your code, please, feel free. > It's not unpythonic, if by that you mean that it's unlike other python formalisms. And it would *only* hit those defs that were attributes of classes derived from a new Object (capital 'O') class. From peter at engcorp.com Thu Aug 12 23:15:12 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 12 Aug 2004 23:15:12 -0400 Subject: decorator syntax polling suggestion In-Reply-To: References: Message-ID: Doug Holton wrote: > At the same time though, Guido has rejected all alternative syntaxes > that have been presented, so the decorators will likely stay as is. I believe until there is a "pronouncement", which hadn't happened the last time I checked, there is still the possibility that an alternate will be accepted. Guido has expressed his opinion on most of the alternative syntaxes, and it has been generally negative, but opinions can change. -Peter From peter at engcorp.com Tue Aug 3 17:30:47 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 03 Aug 2004 17:30:47 -0400 Subject: executing python programs as if they were on OS path (noob) In-Reply-To: References: Message-ID: Darren Dale wrote: > I'm on XP. Ah, then it's easy. If you've installed the standard distribution properly, it very likely is already set up so that merely typing the name of the Python script on the command line will search in the directories in PATH for the matching script, and execute it. In other words, just stop typing "python" in front of the script name! :-) And if you have the PATHEXT environment variable set up to contain ".py" then you won't even have to put .py on the end... -Peter From adonisv at DELETETHISTEXTearthlink.net Tue Aug 17 21:03:00 2004 From: adonisv at DELETETHISTEXTearthlink.net (Adonis) Date: Wed, 18 Aug 2004 01:03:00 GMT Subject: what is wrong with this program? References: <8f17f4bc.0408171623.4f055fb3@posting.google.com> Message-ID: <8VxUc.898$2L3.1@newsread3.news.atl.earthlink.net> "Ali" wrote in message news:8f17f4bc.0408171623.4f055fb3 at posting.google.com... > The following program is supposed to show a menu but it isnt showing > the drop down menus. It only shows the File and Help thing. > > from Tkinter import * > > def callback: > print "Alhumdulillah > > root = Tk() > > #create menu > > m = Menu(root) > root.config(menu=m) > > filemenu = add_cascade(label="File", menu="filemenu") > filemenu.add_command(label="New", command=callback) > filemenu.add_separator() > filemenu.add_command(label="Quit", command=callback) > > helpmenu = Menu(m) > m.add_cascade(label="Help", menu="helpmenu") > helpmenu.add_command(label="About", command=callback) > > root.mainloop() > > please help me fix it Here is a working version, just compare to above should be quite self explanitory, more help can be found on www.pythonware.com --- from Tkinter import * def callback(): print "Alhumdulillah" root = Tk() #create menu m = Menu(root) filemenu = Menu(m) filemenu.add_command(label="New", command=callback) filemenu.add_separator() filemenu.add_command(label="Quit", command=callback) m.add_cascade(label="File", menu=filemenu) helpmenu = Menu(m) helpmenu.add_command(label="About", command=callback) m.add_cascade(label="Help", menu=helpmenu) root.config(menu=m) root.mainloop() --- Hope this helps. Adonis From eddie at holyrood.ed.ac.uk Mon Aug 23 14:53:22 2004 From: eddie at holyrood.ed.ac.uk (Eddie Corns) Date: Mon, 23 Aug 2004 18:53:22 +0000 (UTC) Subject: telnet 'connection reset by peer' References: Message-ID: Donnal Walter writes: >Eddie Corns wrote: >> Donnal Walter writes: >> >> >>>On Windows XP I am able to connect to a remote telnet server from the >>>command prompt using: >> >> >>>telnet nnn.nnn.nnn.nnn 23 >> >> >>>where nnn.nnn.nnn.nnn is the IP address of the host. But using >>>telnetlib, this code returns the traceback that follows: >> >> >>>import telnetlib >>>host = 'nnn.nnn.nnn.nnn' >>>tn = telnetlib.Telnet(host, 23) >>>tn.read_until("Enter device name?") >> >> >> >>>Traceback (most recent call last): >>> File "C:\Python23\Lib\site-packages\mindwrapper\test\telnet.py", line >>>4, in ? >>> tn.read_until("Enter device name?") >>> File "C:\Python23\lib\telnetlib.py", line 316, in read_until >>> self.fill_rawq() >>> File "C:\Python23\lib\telnetlib.py", line 521, in fill_rawq >>> buf = self.sock.recv(50) >>>socket.error: (10054, 'Connection reset by peer') >> >> >>>Is there some parameter that I need to set in order to connect using the >>>telnetlib client? Thanks. >> >> >> No, that should work, to a reasonably conforming telnet server. Try doing >> tn.set_debuglevel(2) before the read_until() to see what's coming back. >Telnet(nnn.nn.nnn.nnn,23): recv >'\xff\xfb\x03\xff\xfd\x03\xff\xfb\x01\xff\xfd\x1 >7\xff\xfb\x00\xff\xfd\x00' >Telnet(nnn.nn.nnn.nnn,23): IAC WILL 3 >Telnet(nnn.nn.nnn.nnn,23): IAC DO 3 >Telnet(nnn.nn.nnn.nnn,23): IAC WILL 1 >Telnet(nnn.nn.nnn.nnn,23): IAC DO 23 >Telnet(nnn.nn.nnn.nnn,23): IAC WILL 0 >Telnet(nnn.nn.nnn.nnn,23): IAC DO 0 >Traceback (most recent call last): > File "C:\Python23\Lib\site-packages\mindwrapper\test\telnet.py", line >5, in ? > tn.read_until("Enter device name?") > File "C:\Python23\lib\telnetlib.py", line 316, in read_until > self.fill_rawq() > File "C:\Python23\lib\telnetlib.py", line 521, in fill_rawq > buf = self.sock.recv(50) >socket.error: (10054, 'Connection reset by peer') >Thank you for the suggestion. Can you help me interpret the feedback? The IACs are commands embedded in the data stream. This page: http://www.scit.wlv.ac.uk/~jphb/comms/telnet.html looks like a decent overview of how telnet works. The purpose here is to negotiate what the capabilities of the telnet session (eg echo). Looking at the code in telnetlib, it seems to always send back DONT or WONT for every option (ie refuses to support or use any option requested). It's possible the server is deciding that on this basis it cannot proceed. There doesn't seem to be a single place where all the telnet options are described so I don't know what 0,1,3,23 actually are. This page might help: http://home.swipnet.se/cfmd/rfc/dir/telnet.html You might try using the tn.set_option_negotiation_callback() method to send your own negotiation messages back if you think that what it is asking for is harmless (you could snoop on your windows session, eg with ethereal, to see what windows is sending back). It seems a bit drastic to behave this way but I suppose it depends on what the server is trying to do. I wouldn't rule out it being a completely different problem but nothing springs to mind. It may be easier to experiment with options using a raw socket, copy the code in telnetlib. HTH, Eddie From psXdaXsilva at esotericaX.ptX Fri Aug 20 20:58:41 2004 From: psXdaXsilva at esotericaX.ptX (Paulo da Silva) Date: Sat, 21 Aug 2004 01:58:41 +0100 Subject: "Socket" files? In-Reply-To: References: <1093035812.83612@jubilee.esoterica.pt> Message-ID: <1093050207.111029@iceman.esoterica.pt> Marcos Dione wrote: ... > > they don't start w/ =; that's just ls being verbose. try 'ls -1'. > > you can create them with os.mkfifo. see lib doc, section 6.1.4. This seems to work. At least ls gives the same result. Thank you. From aleaxit at yahoo.com Thu Aug 26 09:30:38 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 15:30:38 +0200 Subject: python-dev Summary for 2004-08-01 through 2004-08-15 References: <3l3pi0pgmgu0uir1ucnj0rlfo355c6i5cp@4ax.com> <8ab0589d.0408251103.13ddda04@posting.google.com> Message-ID: <1gj4tmz.1pbcdea1bux1ykN%aleaxit@yahoo.com> Brett C. wrote: > Obviously this is not hard and fast It _IS_ quite hard, but _definitely_ not fast...;-) Alex From andre.roberge at ns.sympatico.ca Mon Aug 16 10:15:22 2004 From: andre.roberge at ns.sympatico.ca (Andr? Roberge) Date: 16 Aug 2004 07:15:22 -0700 Subject: Newbie question about Tkinter Message-ID: The following program (Python 2.3, under Windows XP) === import Tkinter as Tk A = Tk.Tk() A.title("1") A.mainloop() B = Tk.Tk() B.title("2") B.mainloop() === opens window A and waits for it to be closed before opening window B. However, the following opens both windows "simultaneously". I tought it would give the same result as the one above... I am confused. ==== import Tkinter as Tk A = Tk.Tk() A.title("1") B = Tk.Tk() B.title("2") A.mainloop() B.mainloop() ==== Anyone can explain or give a pointer to the answer. Andr? From sizelji at insightbb.com Wed Aug 25 12:49:08 2004 From: sizelji at insightbb.com (Jim Sizelove) Date: Wed, 25 Aug 2004 16:49:08 GMT Subject: age of Python programmers In-Reply-To: References: Message-ID: <7q3Xc.66491$mD.7238@attbi_s02> > Lucas Raab wrote: > >> One thing I've always kind of wondered is what is the average age of a >> Python programmer?? What age groups use Python?? I just turned 38 a few days ago. Fell in love with programming in Basic on an Apple ][ when I was about 15. My interests went in other directions during college (Philosophy, Religion, Peace and Global Studies), and then other directions in my career (desktop publishing, metal machining for the automotive industry). I have gotten back into serious programming in the last five or six years, using VB in my work, but dabbling in C, C++, Lisp, Java, Perl. But Python has become my language of choice in the past several months. Jim Sizelove From python at elehack.net Mon Aug 9 11:17:16 2004 From: python at elehack.net (Michael Ekstrand) Date: Mon, 9 Aug 2004 10:17:16 -0500 Subject: Maybe, just maybe @decorator syntax is ok after all In-Reply-To: <4116b725$1@nntp.zianet.com> References: <4116b725$1@nntp.zianet.com> Message-ID: <200408091017.16253.python@elehack.net> On Sunday 08 August 2004 18:28, Mark Bottjer wrote: > Having all this stuff before the *name* of the thing being defined is > distracting. First tell me what it's *called*, then I'll decide if I > want to know more or not. Much of that can be accomplished stylistically in the way comments are written (granted, that doesn't accomplish much for existing code that doesn't follow such conventions). But, for example, in my C/C++ code, I always have comments before my functions like so: /* * FooClass::foo() * * Fooifies the FooClass instance */ int FooClass::foo(int parm1, char parm2, char *spam_name) ... Much of the problem (in any language, then) goes away. You still run into problems with existing code, though. -Michael From jsavard at excxn.aNOSPAMb.cdn.invalid Thu Aug 26 12:16:25 2004 From: jsavard at excxn.aNOSPAMb.cdn.invalid (John Savard) Date: Thu, 26 Aug 2004 16:16:25 GMT Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: <412e0b7b.7894449@news.ecn.ab.ca> On 25 Aug 2004 14:56:06 -0700, xah at xahlee.org (Xah Lee) wrote, in part: >Did you know that throughout history there's this thing called cult? We have heard of it. >Don't think that i'm citing from >some arcane books buried in libraries. These are real, and not >difficult to find in real life. Unlike the cult of Chthulhu, for example. >Big brother organizations, such as the FBI, is keen on these and >very interested in benefiting from social psychology themselves. They >are recorded in books too. Ever wonder why the library houses so many >cold volumes of paper? This is one contributing reason. You might be >interested to verify that sometimes. Ah, yes. If it weren't for the interest of the FBI in cults, our libraries would be much smaller, or they would emphasize warm audio and video recordings more. >Surely you have heard of Adolf Hitler >and his atrocities of genocide? Yes, you are rather safe in assuming that. >I must alert you, that a single person >couldn't commit such a crime. You see, even if you are superman, you >can only kill few at a time. Yes, despite claims at the Nuremberg trials, Hitler didn't run the concentration camps as a one-man operation. >You see, it is the people, people like >you and me, who commit the killings willingly, by Hitler's >teaching. You may say: "no, i won't ever do such stupid thing", well >because you are very ignorant about social psychology. It is precisely >innocent people like you and (not) me, who were lead by the radical >leaders of supreme brain-washing abilities. The innocent mob were >fervent in their leader's vision and beliefs to commit anything. They did, though, have to select from the German people those who would operate the concentration camps. As for the masses, it was enough that they were afraid to try to do anything to stop it. >How can we prevent heinous cults then? Stop bending truths. Education >and rationalism. I'm starting my own cult to exterminate morons on >this earth. Two things are on the top of my agenda: Unixism and Perl. You are not providing any validation for your claim that these things are so dangerous that the use of deadly force is justified or necessary. John Savard http://home.ecn.ab.ca/~jsavard/index.html From abra9823 at mail.usyd.edu.au Thu Aug 26 06:22:53 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Thu, 26 Aug 2004 20:22:53 +1000 Subject: cookie Message-ID: <1093515773.412db9fdf3b96@www-mail.usyd.edu.au> hi! i am printing a simple cookie, but instead of printing um=name:blah&access:admin&exp:2312390.909 its printing um="name:blah&access:admin&exp:2312390.909" why the quotes? i am creating the cookie as follows: data = "user:" + username + "&access:" + access + "&expiry:" + str(expTime) cookie_digest = hmac.new(key, data).digest() cookie = Cookie.SimpleCookie() cookie_data = data + "&digest:" + cookie_digest cookie["um_cookie"] = cookie_data cookie["um_cookie"]["path"] = "/~abrar1/hons/interface/admin/" print cookie thanks cheers ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From wweston at att.net Wed Aug 4 14:22:09 2004 From: wweston at att.net (wes weston) Date: Wed, 04 Aug 2004 18:22:09 GMT Subject: I got it! How to force a single number to be a tuple In-Reply-To: References: Message-ID: Jinming Xu wrote: > Sorry for the previous message. It's really a simple question and I have > solved it myself. > > Thanks, > > Jinming > > ------------------------------------------------------------------------ > Hi Folks, > > I have a number sequence, which is put into a tuple like this: > > y=2, 3.0, 4.5 > > I can manipulate the sequence as a tuple when it has more than 1 number. > But when the sequence has only 1 number, like > > y=2 > > I have trouble to manipulate it as a tuple. I guess there must be a way > to forece a single number to be a tuple. Could anyone please tell me that? > > Thanks, > > Jinming > > _________________________________________________________________ > Discover the best of the best at MSN Luxury Living. http://lexus.msn.com/ > Jinming, >>> t = (1) >>> t 1 >>> t = (1,) >>> t (1,) >>> wes From jacobsmail at postmark.net Mon Aug 23 19:52:07 2004 From: jacobsmail at postmark.net (Jacob H) Date: 23 Aug 2004 16:52:07 -0700 Subject: Getting at the bits of a 32-bit integer Message-ID: <85b54e91.0408231552.75f85727@posting.google.com> Hi there list, I'm a beginning programmer, so please correct me if any of the following assumptions are wrong. Suppose I have the decimal number 255. Since integers in Python are 32 bits, it would look like this in binary: 00000000 00000000 00000000 11111111 There are plenty of unused bits to the left of the number itself. If I wanted to use some of these bits as true/false flags, how would I go about it? In Python, how do I write code that gets at the leftmost byte, or the third bit from the left of the set of 32, or the rightmost byte plus the bit to its left, etc... Thanks in advance for any help on this. :) Jacob From ajsiegel at optonline.com Tue Aug 24 13:47:02 2004 From: ajsiegel at optonline.com (Arthur) Date: Tue, 24 Aug 2004 17:47:02 GMT Subject: __name__ becoming read-write? References: <3b8ki0tlphodtt8ge8an274qp78ihp1i3n@4ax.com> <8cdmi0dipgk5192li1p8mm2n1hls2hs7rl@4ax.com> <7rhmi0d7cdg9r6ljvilgkep30tckl24nai@4ax.com> Message-ID: <6qtmi09lkbult2glmatio8cchunoiu25pk@4ax.com> On Wed, 25 Aug 2004 01:26:30 +1000, Anthony Baxter wrote: >On Tue, 24 Aug 2004 14:00:35 GMT, Arthur wrote: >> But all at a cost. I would be comforted to hear you say something >> about the costs you perceive. If you present it is all just a win, >> it becomes too easy to challenge your assessment. So easy, that even >> someone like myself can pull it off, at least to an extent - and at >> least in my own judgement. > >_Any_ new feature has a cost - whether it is in the additional >training needed, the potential for truly horrendous hacks, the >backwards-incompatibility, or whatever else. I appreciate you taking the time to respond. > >The additional training issue: > One of my internal measures for evaluating new decorator syntax >options is that it be *obvious* that "this is something new". The >various ideas of "doing something wacky with a list" or "a magic >'decorate()' function" fail this test, for me. They're not obviously >doing something new. Or else, "this is something deep", and "we are violating the normal rules of expressiveness, and know it". One argument presented with some vehemence against the pre-alpha2 syntax and in support of the new approach is that the old represented unacceptable "action at a distance". But isn't that inherent in a transformation. A trivial sense of action at a distance might be solved with the new syntax. Replaced by a more profound sense of action at a distance. Knowing that *my* saying these kinds of things carries an implicit assertion that a non-technical impression is valid. Or worth hearing, anyway. The best precedence some of us find for all this is __metaclass__. It spells "deep", it spells "on guard, rolled my own", it spells "action at a distance" (where and what 'M' - the metaclass - is, is not something revelaed in the declaration itself) Again, that is a non-technical assessment. Python as language, in the more general sense of language. But none of this is where we are very far off from one another, anyway. >From the wioki list as it stands, I'm an A1 guy, after all. > Following on from that, the new feature should be explainable in >the context of existing knowledge. For someone like myself, __something__ would do much of the explaining in and of itself There would be something visceral I understood, before I understand anything else. But I will let Paul continue to try to carry this torch. It doesn't look like he is getting too far, too fast. I always need to consider the fact that there are technical issues I don't understand that override the the intuitive, and language, issues I beleive that I do. Certainly that seems to be your position on __something__ inside the fucntion def. It sounds to my ears unnecessarily, almost arbitrarily, purist. But in the end this is not something I am in a position to argue. >The before-def decorator syntax is Without going on, I would say that I don't think *you* understand some the depth of the problem here. There is actually not yet a way to talk about the mechanism which you are calling decorator syntax because of the fact that the lack of consensus runs that deep. Some feel it is a misnomer on technical grounds and others consider it a misnomer on the basis of being unexpressive and uninformative. To discuss "decorator syntax" is a concession. To meet on an even playing field, we can only discuss The Mechanism. Art From anthonybaxter at gmail.com Fri Aug 13 12:50:33 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 14 Aug 2004 02:50:33 +1000 Subject: Python indentation deters newbies? In-Reply-To: <_d6Tc.23589$Jp6.3458@newsread3.news.atl.earthlink.net> References: <3064b51d.0408130615.3fc4a760@posting.google.com> <_d6Tc.23589$Jp6.3458@newsread3.news.atl.earthlink.net> Message-ID: On Fri, 13 Aug 2004 16:44:42 GMT, CptPicard wrote: > I noticed too that, amazingly, a lot of programmers know about Perl but not > Python. A hell of a lot of the Perl programmers I know have never really programmed in anything else in the same area. If my choices were Perl, Pascal, or C, I'd probably choose Perl, too. Indeed, I did, for a while. "I chose something else". Anthony From squirrel at WPI.EDU Tue Aug 10 16:20:16 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 10 Aug 2004 16:20:16 -0400 Subject: Prothon is switching to the .NET platform In-Reply-To: <10hiaed6dj22283@news.supernews.com> References: <000401c47b59$32539220$0d01a8c0@MarkVaio> <10h7lb21dhbuc12@news.supernews.com> <10h7rittck6ct75@news.supernews.com> <10hiaed6dj22283@news.supernews.com> Message-ID: On Tue, 10 Aug 2004, John Roth wrote: > "Christopher T King" wrote in message > news:Pine.LNX.4.44.0408101527020.9982-100000 at ccc2.wpi.edu... > > On Fri, 6 Aug 2004, John Roth wrote: > > > > > The place where this gets really ugly is inserting functions > > > into the instances. They have to be created at the module > > > level, and then inserted into the instance by a module level > > > function (somewhat similar to the way classmethod, > > > staticmethod and property work). > > > > Oh, I wouldn't even attempt that until Python supported > > "def object.method():" syntax (like Prothon does). > > It actually works quite nicely. Oh, I know you can do it in standard Python, but like you say, it's ugly ;) > Your suggested syntax would be a definite plus, but I'm not holding my > breath until there are a number of people using some variety of > prototype package in Python. It's a classic chicken and egg problem. > > On the other hand, it could simply be waiting on someone writing a PEP > and giving some believable use cases for wanting to insert random > methods into instances. I thought there was already a PEP for it, but a quick scan reveals none. I know it's been brought up before, though. > I'm not familiar with your system, Basically, derive(foo) returns a new object whose __getattr__ references foo. A side effect of this is that you can subclass derive for great justice. > but there's no particular difficulty inserting methods into either a > class or an instance. You just have to know the correct way to wrap it. > > To put it into an instance, you have to wrap it in new.instancemethod. Some of us are just too darn lazy to do that ;) From kjetilho at yksi.ifi.uio.no Fri Aug 27 08:04:13 2004 From: kjetilho at yksi.ifi.uio.no (Kjetil Torgrim Homme) Date: Fri, 27 Aug 2004 14:04:13 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> Message-ID: <1rr7pseqiq.fsf@rovereto.ifi.uio.no> [Michael Sparks]: > > Kjetil Torgrim Homme wrote: > > what do you think? should I write a PEP? > > I suspect you might have a hard time getting anywhere with this ;) well, in the previous discussions I've read, the proponents of braces want them as an alternative to strict indentation. that's not the case here, so the code is still kept pythonic, IMO. -- Kjetil T. From anthonybaxter at gmail.com Mon Aug 16 11:24:19 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Tue, 17 Aug 2004 01:24:19 +1000 Subject: Decorators: an outsider's perspective In-Reply-To: References: <20040814153534.8AC171E4007@bag.python.org> Message-ID: On Mon, 16 Aug 2004 06:20:18 -0400, Paul Morrow wrote: > > Python currently doesn't _care_ about the argument list, and the variable > > names in it. > > > > One thought is, to preserve backwards compatability, this special > behavior would only be invoked for subclasses of the new Object class. How is this backwards compatible? If you'd introduced it at the same time as object, _maybe_ you could argue that. But this isn't the case here. > > Adding this sort of behaviour is nasty. How, for instance, would you handle > > adding a method to a class at runtime? Do you poke into the newly added > > method to make sure you get it right? Do you not do this? > Same rules apply. The Python system would dynamically determine the > method's type when you add it (at runtime), so you'd need to make sure > that the first parm name is correct in advance. Really. And how would you implement this special casing in a way that wasn't incredibly tricky to explain to users running across it? One of the great things about Python is that if you need to, or you want to, you can poke into the innards of the OO system and see how it works (particularly since descriptors were added). This adds Perl-like levels of OO-hackery. If that comment is unclear, I mean that when you poke into Perl's OO, it becomes very clear, very quickly, that it's a hack. > > What about for more complex decorators? Remember, staticmethod and > > classmethod are the trivial cases that this feature addresses. How do you > > handle the more complex ones? > The point is that method type declarations are not needed, so decorators > wouldn't be concerned with this. Take them off the list of things > decorators can do. Huh? You proposed a hack to specify class and static methods, using a custom meta-class that pokes at the argument list of a function, and suddenly you've removed the need for decorators for this? Please - feel free to use your metaclass in your own code, but don't think that this is in any way a solution that should be considered for "mainstream" python use. It's a hack - a neat hack and a nice example of some of the things metaclasses can do[1], but it's not a valid "solution" for the problem that decorators are meant to solve. Look, staticmethod and classmethod are a tiny tiny fraction of the things that decorator will be used for. Looking at a large amount of Python code I've got here, I can see three examples of classmethods (all alternate constructors) and no uses of staticmethod at all. Anthony ([1] and, I should note, one I was about to post until I saw your post ) From ajsiegel at optonline.com Mon Aug 23 11:36:06 2004 From: ajsiegel at optonline.com (Arthur) Date: Mon, 23 Aug 2004 15:36:06 GMT Subject: __name__ becoming read-write? References: Message-ID: <2e3ki01bk5eev1diculqn3ipa5e1b46fdt@4ax.com> On Mon, 23 Aug 2004 14:49:41 GMT, Michael Hudson wrote: >Arthur writes: > >> Did I hallucinate something about __name__ becoming read-write? > >For functions? No, you didn't hallucinate that. > >> Not in alpha2. > >Indeed. The changes were only checked in a couple of weeks ago. >They'll be in alpha3. Thanks for confirming I am not hullicinating. This time, anyway. My argument - obviously, I think - is that this as a stand-alone change does enough to ease the pain of the current syntax, and is in proportion to the problem. The fact that some of think we are way, way out of proportion with the direction now headed, having been previously established. Art From nid_oizo at yahoo.com_removethe_ Mon Aug 23 08:30:46 2004 From: nid_oizo at yahoo.com_removethe_ (Nicolas Fleury) Date: Mon, 23 Aug 2004 08:30:46 -0400 Subject: J2 proposal: keyword In-Reply-To: References: Message-ID: Roman Suzi wrote: > This surprises me. And this doen't surprise: > > using: > staticmethod; synchronized; memoize > def bar(foo): > "To colon or not to colon? Def is the question." > pass +1 Nicolas From jepler at unpythonic.net Sun Aug 8 16:32:19 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Sun, 8 Aug 2004 15:32:19 -0500 Subject: upper memory limit In-Reply-To: <20040806123420.20214.qmail@web10703.mail.yahoo.com> References: <20040806123420.20214.qmail@web10703.mail.yahoo.com> Message-ID: <20040808203218.GA6582@unpythonic.net> Not only does your OS have some per-process memory limit, but Python uses the C library's realloc() to increase the size of certain items, like lists. Memory fragmentation (after many allocate/free cycles) means that the largest block that can be allocated is almost always less than the total amount of free address space. Secondly, realloc() may temporarily require a larger amount of memory, because it can relocate a block. Even a reasonable implementation may temporarily require new_size + old_size + overhead. I've been told that the realloc implementation on windows always relocates a block. Below about 2GB, Python doesn't pose any relevant constraints on object size. However, Python uses "int" to store the "number of items in the variable part" of an object, which means that an item with a granularity of 1 byte (byte string) can't be longer than 2 gigabytes, and an item with granularity of 4 bytes (list object) can't contain more than 2 billion items. (but this would be an 8GB list object, bigger than the total address space of ILP32 machines like x86) Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From davidf at sjsoft.com Fri Aug 20 10:02:31 2004 From: davidf at sjsoft.com (David Fraser) Date: Fri, 20 Aug 2004 16:02:31 +0200 Subject: Decorator keyword options In-Reply-To: <7knVc.4599$Jn5.3074@fe1.texas.rr.com> References: <7knVc.4599$Jn5.3074@fe1.texas.rr.com> Message-ID: Paul McGuire wrote: > Thanks to everyone who has voted so far - please keep them coming! Lurkers, > this means you! > > In the interests of saving time, I propose that an additional thread start > soon, to determine choices for a decorator keyword, in the event that our > selected syntax requires one. Please visit the PythonDecorators Wiki page, > and navigate to section 6.1 Indicators (or follow this link > http://www.python.org/moin/PythonDecorators#head-61f608dbce6ba75b2317d7825d8529997f56fc9e ) > (not sure how reliable this is?) I have started numbering the options in > preparation for another voting thread, if you have other proposals, please > include them on this Wiki page, along with your +/0/- commentary. > Good plan. If anyone likes "wrap" they could add it to the Wiki with something akin to the description of transform David From duncan.booth at invalid.invalid Tue Aug 17 08:04:11 2004 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 17 Aug 2004 12:04:11 GMT Subject: Newbie 1st program References: Message-ID: nicksjacobson at yahoo.com (Nick Jacobson) wrote in news:f8097096.0408170233.5a40706d at posting.google.com: > Great job! Here's something to clean up the code a bit: > > You can change: > ><< >>> > > to: > ><< > ary = ["Restrict your search to a specific site", > "army.mil", "usmc.mil", "af.mil", "navy.mil", "uscg.mil", > "SYColeman.com", "l3com.com", "fedbizopps.gov", "defenselink.mil"] > d = dict(zip(range(10), ary)) > i = event.GetInt() > if i in range(10): > t2.Clear() > t2.SetValue(d[i]) > t2.SetEditable(bool(i)) >>> > Converting the list to a dict seems pointless. Likewise the weird range test seems a lot of effort to no gain, oh, and you got the sense of the SetEditable backwards: ary = ["Restrict your search to a specific site", "army.mil", "usmc.mil", "af.mil", "navy.mil", "uscg.mil", "SYColeman.com", "l3com.com", "fedbizopps.gov", "defenselink.mil"] i = event.GetInt() if 0 <= i < len(ary): t2.Clear() t2.SetValue(ary[i]) t2.SetEditable(i != 0) From mwh at python.net Fri Aug 27 08:20:03 2004 From: mwh at python.net (Michael Hudson) Date: Fri, 27 Aug 2004 12:20:03 GMT Subject: Converting hex string to an integer References: <412d9e18$0$22821$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: Peter Hansen writes: > Rick Holbert wrote: > > Derek Fountain wrote: > >>Given the character string "0x00A1B2C3" arriving at sys.argv[1] how do I > >>convert that to an integer which I can do some math on? > > i = eval(sys.argv[1]) > > That's dangerous advice to a newbie if not qualified carefully. > > Derek, "eval" could be the source of serious security problems > if you don't understand its power. Specifically it should > almost never be used for input that comes from a user or > via the command line. There is pretty much always another > and much better way to do the simple stuff like conversions > than to use eval. > > For example, imagine if a malicious could feed your program this: > > (on the Linux command line) > > $ myscript "__import_('os').system('rm -rf /')" Well, in this situation, he could just type $ rm -rf / But, yes. Cheers, mwh -- I'm not particularly fond of singing GSTQ because she stands for some things I don't, but it's not really worth letting politics getting in the way of a good bawling. -- Dan Sheppard, ucam.chat From __peter__ at web.de Mon Aug 30 10:35:03 2004 From: __peter__ at web.de (Peter Otten) Date: Mon, 30 Aug 2004 16:35:03 +0200 Subject: initializing mutable class attributes References: Message-ID: Dan Perl wrote: > something like this: > class Child (Father): > def __init__(self): > Father.__init__(self) > self.attr3=[ ] > > I find this even more awkward because many people will forget to do it. You have to call base-class-__init__() in every non-trivial inheritance scheme. Should you forget it, pychecker is always there to remind you class X: def __init__(self): self.x = 2 class Y(X): pass class Z(Y): def __init__(self): pass And here's what pychecker says: $ pychecker t1.py Processing t1... Warnings... t1.py:9: Base class (t1.Y) __init__() not called Clear enough. Peter From peter at semantico.com Fri Aug 13 08:56:13 2004 From: peter at semantico.com (Peter Hickman) Date: Fri, 13 Aug 2004 13:56:13 +0100 Subject: Help understanding Scheme's syntax, procedures and calls In-Reply-To: <95f168b0.0408121215.f89c842@posting.google.com> References: <95f168b0.0408120120.31433dc7@posting.google.com> <95f168b0.0408121215.f89c842@posting.google.com> Message-ID: <411cba6f$0$9687$afc38c87@news.easynet.co.uk> > Thanks for the help. It's not homework but from an old exam paper, but > the girl's English isn't absolutely fluent and I'm looking for a > simple way to explain the expressions and functions. If there are points to be won for brevity then the answer is 'two functions (one with a helper) to compute factorials' From grante at visi.com Thu Aug 26 13:10:54 2004 From: grante at visi.com (Grant Edwards) Date: 26 Aug 2004 17:10:54 GMT Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <776e0325.0408260433.449660c8@posting.google.com> <412dfc1c$0$65599$a1866201@newsreader.visi.com> <86hdqpriww.fsf@blue.stonehenge.com> Message-ID: <412e199e$0$8076$a1866201@newsreader.visi.com> On 2004-08-26, Randal L. Schwartz wrote: > *** post for FREE via your newsreader at post.newsfeed.com *** > >>>>>> "Grant" == Grant Edwards writes: > >Grant> "Guido said it, that settles it, but we're going to discuss >Grant> it endlessly and and vote on it using six or seven >Grant> different voting algorithms anyway. Then we'll argue about >Grant> the voting algorithms." > > Are the voting algorithms indented consistently? That's a > necessity, correct? Of course, but are they consistently indented using tabs or spaces? > Surely, they have significant whitespace. -- Grant Edwards grante Yow! Gee, I feel kind of at LIGHT in the head now, visi.com knowing I can't make my satellite dish PAYMENTS! From fredrik at pythonware.com Thu Aug 19 13:01:26 2004 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 19 Aug 2004 19:01:26 +0200 Subject: Please help -- Tkinter Scale widget with DoubleVar is acting weird References: <4124C828.5080106@noaa.gov> Message-ID: Jared Cohen wrote: > Hi all. I'm currently using a Tkinter Scale widget which uses a > DoubleVar as its control variable. I then use the "trace_variable('w', > callback)" method to invoke a callback whenever the DoubleVar changes. > > The problem is this: the callback is triggered when the slider moves (as > it should), but it's also triggered when I just HOVER the mouse over the > slider without clicking! Somehow or other, it must think that the > control variable is being changed, even though it isn't. I *think* that > this problem is related to the loss of precision that DoubleVars can > have, but I'm not really sure. Has anyone else experienced this problem? > How can I fix this? you could use a "command" callback instead of a traced variable: import sys, Tkinter, types root = Tkinter.Tk() def callback(value): print float(value) slider = Tkinter.Scale(root, from_ = 0.0, to = 1.0, resolution = 0.1, command = callback, orient = 'horizontal') slider.grid(sticky='ew') root.mainloop() (use slider.get() to get the current value from outside the callback, and slider.set(x) to set it). From unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom Sat Aug 7 03:58:07 2004 From: unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom (Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.) Date: Sat, 7 Aug 2004 09:58:07 +0200 Subject: unicode to ascii converting References: <1091815856.527127@news.commspeed.net> Message-ID: Hi ! Try : aa = u"?" aa.encode("ascii","ignore") From fuzzyman at gmail.com Thu Aug 26 03:08:59 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 26 Aug 2004 00:08:59 -0700 Subject: Weave - inline C References: <6f402501.0408232319.5967f0d@posting.google.com> Message-ID: <6f402501.0408252308.7ac81e97@posting.google.com> Robert Kern wrote in message news:... > Michael Foord wrote: > > Has anyone had success using weave with gcc for windows (standard > > windows distribution python)? > > > > I have my distutils setup to use gcc (via mingw32) - which it does > > fine. I've compiled and installed various modules with it. Weave > > itself installs fine, picking up the settings from distutils. > > > > However it has it's own version of distutils 'scipy_distutils' that it > > uses to compile the C it is given - which complains that it can't find > > msvcc.... The documentation included (which is actually for the 0.2 > > version) gives no hints and I wondered if anyone had any success in > > using it ? > > Use compiler='gcc' as a keyword argument for weave.inline(), etc. > That works fine on the tests I've done so far ! Thanks for your help. Fuzzy http://www.voidspace.org.uk/atlantibots/pythonutils.html > Yes, the documentation is fantastically out of date. > > > Regards, > > > > > > Fuzzy From __peter__ at web.de Tue Aug 3 13:59:54 2004 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Aug 2004 19:59:54 +0200 Subject: how to do proper subclassing? References: Message-ID: Jonas Koelker wrote: > Hello there. > > I'm new to this list (/me welcomes himself). > > anyways, I'm having doubts about how to subclass > properly. The big picture is that I want to handle > permutations. As we all know, two popular notation > forms exist: products of disjoint cycles ("(0 1 3)(2 > 4)") and 2*length matrices with the identity > permutation as the first line ([0 1 2 3 4] over [1 3 4 > 0 2]). I find the latter more appropriate, since it's > easy to store as a list (one can skip the first line, > assuming it's _always_ the identity). > > However, I want the permutation to act like a list, in > all those cases where I don't override the operations. > For example, assuming permfooation is the above > permutation [1 3 4 0 2], permfooation[1:3] should > return [3,4]. How is this done? Do I have to actually > implement a slice-mechanism in the permutation class? You already answered your question in the subject - you want a subclass of list: >>> class Perm(list): ... def __init__(self, n): ... list.__init__(self, range(n)) ... def __call__(self, i, k): ... self[i], self[k] = self[k], self[i] ... return self ... >>> p = Perm(5) >>> p [0, 1, 2, 3, 4] >>> p(0,4)(2,4)(0,1)(2,3)(1,2) [1, 3, 4, 0, 2] >>> p[1:2] [3] >>> p[1:3] [3, 4] Just in case you need it later, there is a special method for every operator, e. g. __getitem__() for obj[sliceOrIndex], __mul__() for multiplication etc. Write one for the class in question and it will grow the corresponding operation. In the above example I have made the class "callable" (i. e. its instances can behave like a function) by adding the __call__() method. By returning self I ensure that you can chain these calls. As you may know, this is not the way the list.sort() method behaves, so this is probably bad style for methods mutating the original instance. As to __getitem__(), I think the easiest way to see what happens inside is provided by the following snippet: >>> class C: ... def __getitem__(self, i): ... return i ... >>> C()[1] 1 >>> C()[1:2] slice(1, 2, None) >>> C()[1:2:3] slice(1, 2, 3) I. e. a typical minimal __getitem__() has to test whether it receives a slice or an integer using isinstance(). Peter From jerf at jerf.org Mon Aug 23 20:39:01 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Tue, 24 Aug 2004 00:39:01 GMT Subject: Why are strings immutable? References: Message-ID: On Mon, 23 Aug 2004 22:11:36 +0200, Hallvard B Furuseth wrote: > If you are doing a lot of that with the string, does it need to be a > single string? I've just speeded up a program significantly by changing > string_var = ... > string_var += ... > string_var += ... > ... > to > array_var = ['string'] > array_var.append(...) > array_var.append(...) > ... > result = "".join(array_var) > (Well, because of how the data was structured I actually used a dict which > was unpacked to a list comprehension which was joined to a string, but it > still speeded things up.) For PyDS, I contributed a class that does that and offers a += interface, so it is easy to drop in without too much conversion work. It is very simple. In general, you should not use this and you should do it "right" the first time, but for existing code this can be a convenient make-do. Replace your initial "myString = ''" with "myString = StringCollector()", and depending on how you use this you may not need to change the final use. Otherwise, call "str()" on your StringCollector. (Note the encoding in iadd; I just added the locale call without testing it, and you may want to switch it; PyDS actually uses its own system.) ----------------------------- import locale class StringCollector: def __init__(self, string='', encoding = None): self.buffer = StringIO() if string: self += string if encoding in None: self.encoding = locale.getpreferredencoding() else: self.encoding = encoding def __iadd__(self, other): if type(string) == types.UnicodeType: self.buffer.write(other.encode(self.encoding)) else: self.buffer.write(other) return self def __repr__(self): return '' def __str__(self): return self.buffer.getvalue() From dody at postaccesslite.com Wed Aug 25 07:13:06 2004 From: dody at postaccesslite.com (dody) Date: Wed, 25 Aug 2004 18:13:06 +0700 Subject: ASPN Python cookbook in a chm Message-ID: <10229674.20040825181306@postaccesslite.com> ASPN Python cookbook in a .chm file =================================== last updated: 25 August 2004 http://miaw.tcom.ou.edu/~dody/aspnpython.chm -- dody suria wijaya From pwilkinson at videotron.ca Mon Aug 9 10:39:53 2004 From: pwilkinson at videotron.ca (Peter Wilkinson) Date: Mon, 09 Aug 2004 10:39:53 -0400 Subject: upper memory limit In-Reply-To: <3hdbh0d3af4gjbj6psec10nahls0u3nuu3@4ax.com> References: <3hdbh0d3af4gjbj6psec10nahls0u3nuu3@4ax.com> Message-ID: <6.0.3.0.0.20040809103431.01b5fe30@pop.videotron.ca> Why do you say that single process is limited to 2 Gig? I believe that on windows a single process can run with to 32 bits addressed or 4 Gig of space. I have run R with over 2 Gig of memory. Why would python be limited to 2 Gig (including overhead)? I don't see that python should be any different. Peter At 01:16 AM 8/8/2004, Tim Roberts wrote: >Leandro wrote: > > >There is an upper memory limit in Python? > >I have 2GB RAM and 2 processors Xeon 2.4 - (Windows XP), but I just can use > >1.2G of memory, after this python crashes. > >Does someone know if python has some memory limit? > >You might be surprised to learn that the amount of memory available to a >single process is (almost) completely unrelated to the amount of physical >memory in the machine. Windows is a virtual memory system. > >A single process in Windows is limited to 2GB of address space. Part of >that is occupied by the Python executable, your DLLs, and the system DLLs. > >1.2GB seems a litle low, but it is not entirely unreasonable. >-- >- Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. >-- >http://mail.python.org/mailman/listinfo/python-list From barnesc at engr.orst.edu Tue Aug 10 03:46:21 2004 From: barnesc at engr.orst.edu (barnesc at engr.orst.edu) Date: Tue, 10 Aug 2004 00:46:21 -0700 Subject: Simple hashcash implementation Message-ID: <1092123981.41187d4d9aaeb@webmail.oregonstate.edu> Hi! Here's a simple hashcash implementation in Python. 28 lines of actual code. Can be reduced to 17 lines for instructional purposes, if you don't want clustering, and use xrange() instead of irange(). I tried to make this as simple and elegant as possible. Feel free to repost this code, if you can make the it more simple. I have made no attempt to optimize this code. # ---------------------------------------------- # hashcash.py: Hashcash implementation # ---------------------------------------------- """ Hashcash is a "proof of work." Example: >>> import sha >>> sha.new('denmark2890CF').hexdigest() '000000cf89643370c24e413ec0886ab92bd7f6e8' Here we have a 24-bit partial SHA collision against the zero string. This proves to us that someone took the prefix 'denmark', and tried about 2**24 different suffixes. Thus we know that someone has burnt around 2**24 CPU cycles on the prefix string 'denmark'. Usually, 'denmark' will be a unique challenge string, so old hashcash cannot be recycled. For speed, this library takes the hash of the string 'denmark' before doing the collision with the zero string. Otherwise, it is identical to the above example. Library examples: >>> import hashcash >>> hashcash.make_token('Denmark', 22) '59538D' >>> hashcash.verify_token('Denmark', '59538D') 22 >>> t = hashcash.make_cluster('Denmark', 18) >>> t 'BC48-D5A1-F8C2-27F0-9CC0-DD31-2F04-2052-835-FFF1-E319-0E91-A9D0-D359 -E996-70BA' >>> hashcash.verify_cluster('Denmark', t) 18 Note that make_token() takes wildly varying amounts of CPU time. The make_cluster() function concatenates 16 hashcash tokens to even out the amount of CPU time spent. """ import sha, math, itertools def trailing_zeros(n): """Number of trailing 0s in binary representation of integer n.""" if n <= 0: return 0 for i in itertools.count(0): if n & (1<= n: return token def verify_token(s, token): """Returns hashcash value of given token against basestring 's'.""" return trailing_zeros(hash(sha.new(s).digest() + token)) def make_cluster(s, n, charset='0123456789ABCDEF'): """Makes hashcash cluster of value 'n' against basestring 's'.""" return '-'.join([make_token(s+str(i),n-4,charset) for i in range(16)]) def verify_cluster(s, token): """Hashcash value of the given cluster against basestring 's'.""" T = token.split('-') return min([verify_token(s+str(i), T[i]) for i in range(len(T))])+\ int(math.log(len(T)) / math.log(2.0)) This document is in public domain (as are all of my past Usenet postings). - Connelly From tzot at sil-tec.gr Wed Aug 18 11:54:39 2004 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Wed, 18 Aug 2004 18:54:39 +0300 Subject: age of Python programmers References: Message-ID: On Wed, 18 Aug 2004 09:36:09 -0500, rumours say that Skip Montanaro might have written: > > Christopher> I'm 19. The only other Python programmer I know personally > Christopher> is 21. Congrats on discovering Python at 14; back then I > Christopher> thought VB was a godsend. ;) [skip] >Whippersnapper... At 14 I would have thought a computer was a godsend. ;-) > >(I'm 50, btw.) Perhaps when the timbot was 14, *everything* was godsent (or so the Bible describes things :) -- TZOTZIOY, I speak England very best, "Tssss!" --Brad Pitt as Achilles in unprecedented Ancient Greek From lopexx at autograf.pl Tue Aug 17 07:35:26 2004 From: lopexx at autograf.pl (lopex) Date: Tue, 17 Aug 2004 13:35:26 +0200 Subject: Best programming language In-Reply-To: <873c2ndizt.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> References: <873c2ndizt.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Message-ID: 510046470588-0001 at t-online.de wrote: > > the best language is of course Scheme > Another flamewar ? should I claim Ruby is.. ? Marcin Mielzynski From simoninusa2001 at yahoo.co.uk Thu Aug 19 17:38:39 2004 From: simoninusa2001 at yahoo.co.uk (simoninusa2001 at yahoo.co.uk) Date: 19 Aug 2004 14:38:39 -0700 Subject: ANN: pyxe Message-ID: Forgive me if this comes out odd, I'm testing the new http://groups-beta.google.com/group/comp.lang.python - it seems to encourage top-posting and quoting the entire previous thread (although I do seem to be able to cancel posts....) Anyway, what sets this app apart from py2exe (or cx_Freeze, BundleBuilder or McMillan Installer for that matter)? Ah, it seems that this builds the interpreter as an .exe isntead of the entire application, which is supplied in source .py form From zathras at thwackety.com Fri Aug 20 07:33:06 2004 From: zathras at thwackety.com (Michael Sparks) Date: Fri, 20 Aug 2004 12:33:06 +0100 (BST) Subject: Alternative decorator syntax decision In-Reply-To: Message-ID: On Fri, 20 Aug 2004, Paul McGuire wrote: > "Delaney, Timothy C (Timothy)" wrote in message > news:mailman.1989.1092960560.5135.python-list at python.org... > > I think a web page for tabulating votes would be better (see the > > response to the previous vote on 3 syntaxes). > > I couldn't agree more, Tim, but time is short. Time might be short, but don't forget timezone issues. Usenet takes time to propogate postings, etc. > BTW, where are all the votes for option "A"? Where are all the people who > hated it but now like it? I think one of the problems is the vote might be viewed as "which alternative to A1 do you like" rather than "which alternative, even including A1, do you like" - personally I'd be very interested to see the level of support for A1, _especially_ if it overwhelms support for any other syntax... Tallying the results of 22 votes now: > for i in `cat votes.txt |cut -d, -f1`; do echo $i; done|sort|uniq -c 4 A1 14 C1 2 C2 1 C4 2 D1 1 D2 2 E1 2 E2 1 E4 5 F 1 H 1 I 23 J2 3 K 4 L People who changed their votes from "J2 J2 A1" to "J2 J2 J2" I've included as "J2 J2 A1" based on the question above. Votes included minus email addresses below... Regards, Michael. Votes included above: J2 C1 J2, Andrew Durdin C2 C2 C1, Ayose C1 C1 E1, Ben F F F, Bruno Desthuilliers J2 L L, David Fraser C1 D1 K, Egbert Bouwman F F A1, Gerrit Muller C1 D1 E1, Greg Ewing C1 D2 J2, Greg Krohn J2 J2 E2, Jeff Shannon J2 J2 A1, Ksenia Marasanova J2 J2 A1, Marc Boeren I J2 H, Matteo Dell'Amico J2 J2 C1, Michael Sparks E4 J2 K, Nicolas Fleury J2 J2 C1, Paul McGuire J2 J2 E2, Peter Hansen J2 J2 K, Peter Otten C4 A1 J2, Roman Suzi C1 C1 C1, Scott Gilbert C1 C1 J2, Skip Montanaro J2 L L, Steven Bethard From flab at large.net Fri Aug 20 01:47:40 2004 From: flab at large.net (flab ba) Date: Thu, 19 Aug 2004 22:47:40 -0700 Subject: My only complaint about Python References: Message-ID: I use Python for mission-critical enterprise level stuff, and I have to say that on **Windows**, I'd rather it be compiled with MSVC, and not something like MingW or GCC. Under no circumstances would I put something in production if it was using Cygwin. There is nothing to stop you from compiling Python yourself with the free Visual C++ Toolkit. Instructions are here: http://www.vrplumber.com/programming/mstoolkit/index.html http://mail.python.org/pipermail/python-dev/2004-February/042595.html When the 2005 Toolkit comes out, I have a sneaky suspicion that the "Starter" pack will be good enough to compile Python - which will be very cheap (maybe even as low as $50). An important part of Python for Windows is Mark Hammond's Windows extensions - I wonder if these rely on a very "windows-savy" compiler like (Borland or VC++ ) -Flab On Thu, 19 Aug 2004 11:42:50 -0400, Darren Dale wrote: > I love the language. I love the community. My only complaint is that > Python for Windows is built with Visual Studio. > > It is too difficult to build python, or a module, from source. This is > what open source is all about, isnt it? I even have a copy of visual > studio, and I still cant build modules from source, because my academic > copy is version 7. As a scientist funded by the NSF, I feel compelled to > do all my work using free software (I feel compelled to use free > software, regardless). And I feel compelled to contribute to the > scientific capabilities of my favorite programming language. But this > compiler issue is a big (and seemingly unnecessary) impediment. Will the > BDFL ever split with Visual Studio? From skip at pobox.com Tue Aug 31 09:49:04 2004 From: skip at pobox.com (Skip Montanaro) Date: Tue, 31 Aug 2004 08:49:04 -0500 Subject: xmlrpclib In-Reply-To: <413462a1$0$5242$5a62ac22@per-qv1-newsreader-01.iinet.net.au> References: <413409c3$0$22823$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2hkd02-v7v.ln1@home.rogerbinns.com> <413462a1$0$5242$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <16692.33232.911647.298159@montanaro.dyndns.org> Graeme> What I am trying to establish is if the server is asynchronous Graeme> i.e multi-threaded i.e what happens when 2 requests hit the Graeme> server at once? You can write a multi-threaded server using xmlrpclib and SocketServer. I use one behind the Mojam and Musi-Cal websites. Mine happens to start a new thread for each request, but I suppose you could write one which uses a thread pool model. Skip From noreply at python.org Mon Aug 23 11:19:55 2004 From: noreply at python.org (Automatic Email Delivery Software) Date: Mon, 23 Aug 2004 20:49:55 +0530 Subject: Message could not be delivered Message-ID: <20040823160143.B23181E4002@bag.python.org> ------------------ Virus Warning Message (on mail1.sitel-india.com) message.zip is of type executable and is removed. --------------------------------------------------------- -------------- next part -------------- This Message was undeliverable due to the following reason: Your message was not delivered because the destination computer was not reachable within the allowed queue period. The amount of time a message is queued before it is returned depends on local configura- tion parameters. Most likely there is a network problem that prevented delivery, but it is also possible that the computer is turned off, or does not have a mail system running right now. Your message was not delivered within 5 days: Host 10.255.191.129 is not responding. The following recipients did not receive this message: Please reply to postmaster at python.org if you feel this message to be in error. -------------- next part -------------- ------------------ Virus Warning Message (on mail1.sitel-india.com) message.zip is removed from here because it is of type executable --------------------------------------------------------- From nir1408 at ziaran.org Thu Aug 5 06:36:57 2004 From: nir1408 at ziaran.org (ziaran) Date: Thu, 05 Aug 2004 13:36:57 +0300 Subject: AVI I/O In-Reply-To: References: Message-ID: <41120df2$1@news.bezeqint.net> Hello, I want to use Python for Image proccessing. I need the following capabilities: 1. To be able to read and WRITE an AVI file frame by frame. 2. To be able to access each fram as a simple matrix. I tried to search for that in google but could not find something intuitive and simple. The matrices part is important since iamge processing is done through matrices manipulation. MATLAB is an example of a tool with scripting capabilities in which you can do that in a simple way. Is Python adequate for that? Thanks, Nir From sjdevnull at yahoo.com Mon Aug 9 02:36:11 2004 From: sjdevnull at yahoo.com (G. S. Hayes) Date: 8 Aug 2004 23:36:11 -0700 Subject: decorators vs GIL References: <96c2e938.0408081605.706f8ec7@posting.google.com> Message-ID: <96c2e938.0408082236.7bcf3bf7@posting.google.com> mudd at vex.net wrote in message news:... > > That's not to say there aren't limited problem domains where threads > > are the right answer, but as a general construct they're wildly > > overused. I'm frankly glad that Python doesn't encourage more of the > > same. > > > > Is there anything else that Python doesn't do well that we should appreciate? That wasn't really the point; the point was more to argue against the viewpoint that work on language features like list comprehensions or decorators is somehow less important than working on removing the GIL. Obviously in an ideal world you could implement every idea that came along, but in the real world developers tend to work on problems that affect them--and if you have a bunch of developers who rarely run into problems with the GIL (because they're not often abusing threads) then it's just not going to be a very high priority. Rightly so, IMO, since it only affects a very small percentage of well-designed programs, so putting work into bigger problem areas (especially any language features that genuinely improve development speed and readability) gets a much higher payoff. I wouldn't be against removing the GIL if an approach was found that didn't adversely affect the common case; naive approaches to fine-grained locking are often really bad for general case behavior, but there are approaches that can mitigate this. But I would be against lobbying core language developers to take time off of other projects to work on this one; it's definitely more of a "scratch an itch" type problem` that can wait until someone feels motivated to do it than a "suck it up because the community needs it" kind of thing. From BruceWhoHKL at gawab.com Sun Aug 22 21:34:26 2004 From: BruceWhoHKL at gawab.com (BruceKL WhoH) Date: Mon, 23 Aug 2004 09:34:26 +0800 Subject: How to sort this kind of list easily? Message-ID: <20040823013337.48E811E4002@bag.python.org> Anthony Baxter: Oh,I didn't know that list.sort work like this. It's great. But what is decorate-sort-undecorate pattern ? Can you show me any helpful hints or hyperlinks? ======= 2004-08-20 18:38:05 Anthony Baxter wrote: ======= >On Fri, 20 Aug 2004 17:03:51 +0800, BruceKL WhoH wrote: >> Hi,all >> I have a list like [(id,string),...],for example: >> >> [(1,'xxxxx'),(7,'ppppp'),(4,'gggggg'),...] >> >> I want to sort this list according to the id of each element. After sorting,the list will become: >> >> [(1,'xxxxx'),(4,'gggggg'),(7,'ppppp')...] > > >>>> l=[(1,'xxxxx'),(7,'ppppp'),(4,'gggggg'),(2,'ffff'),(12,'hhhhh')] >>>> l.sort() >>>> print l >[(1, 'xxxxx'), (2, 'ffff'), (4, 'gggggg'), (7, 'ppppp'), (12, 'hhhhh')] > >list.sort sorts tuples by first argument, then second &c. If you want a >custom sort order, look at the decorate-sort-undecorate pattern. > >Anthony >-- >http://mail.python.org/mailman/listinfo/python-list >. = = = = = = = = = = = = = = = = = = = = ????????BruceKL WhoH ????????BruceWhoHKL at gawab.com ??????????2004-08-23 From ptmcg at austin.rr._bogus_.com Thu Aug 26 22:12:48 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 27 Aug 2004 02:12:48 GMT Subject: Is it a bug (or a feature)? References: Message-ID: "Anthony Baxter" wrote in message news:mailman.2373.1093455703.5135.python-list at python.org... > This looks like a bug. Please open a bug on SF, with the example code. I just opened this bug, it is number 1017329. -- Paul From peter at engcorp.com Fri Aug 6 20:36:39 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 06 Aug 2004 20:36:39 -0400 Subject: How do you feel ? In-Reply-To: References: Message-ID: Howard Stearns wrote: > The one thing I've found annoying is that I haven't yet discovered how > to do whatever I want in lambda expressions. I have top-level > assignments where I'd like create a function to use as the the value > being assigned. I don't know how to define a named function in a > top-level assignment, and a lambda won't allow me to use 'try' and other > statements -- just expressions. Or am I looking at things wrong? What do you mean by "top-level assignment"? If it's the same meaning most Python programmers would give it, you just do this: def somefunc(): pass topLevelName = somefunc There's your top-level assignment of a named function. Probably not what you meant, but can you clarify please? -Peter From maxm at mxm.dk Mon Aug 30 18:59:13 2004 From: maxm at mxm.dk (Max M) Date: Tue, 31 Aug 2004 00:59:13 +0200 Subject: "Content-Length" header In-Reply-To: References: Message-ID: <4133b0ee$0$191$edfadb0f@dread12.news.tele.dk> Diez B. Roggisch wrote: > Peter Kleiweg wrote: > >>Justin schreef: >> >>>I found the answer. After about 3 hours of agonizing over it it turned >>>out to be CASE >>>some webservers are CASE SENSITVE about their urls and some are not. >> >>There are case-insensitive webservers? Never knew that. > > Rumors are that they even created *whole OSes* in that fashion. I wonder if > that _might_ be the cause for the webservers beeing so nasty.... I came to think of case sensitivity holding semantic meaning in Python, and while I was initially against it, I came to the conclusion that it is a good idea. I guess the best argument is that it holds the same role as forced indenting. Programmes keep a consistent style for all programmers. We don't get programmes written in all/mixed caps. FOR I IN RANGE(100): PRINT i For J In Range(100): Print J for iterator in range(100): print ItErAtOr regards Max M From briangue at gmail.com Thu Aug 19 19:05:29 2004 From: briangue at gmail.com (Brian) Date: 19 Aug 2004 16:05:29 -0700 Subject: Merging pdf documents with Python References: Message-ID: Assuming you've got ghostscript installed on Unix or Windows: import os, sys for in_file in sys.argv[1:]: os.system("pdf2ps %s" % in_file) cat_cmd = 'cat ' for in_file in sys.argv[1:]: cat_cmd += in_file + ".ps " cat_cmd += "> all.ps" os.system("ps2pdf all.ps all.pdf") os.system("rm -f all.ps") for in_file in sys.argv[:1]: os.system("rm -f %i.ps" % in_file) "Daryl Middleton" wrote in message news:... > Can python be used to merge pdf documents into a single pdf file so that I > do not have to manually insert each one. Thanks From richardshea at fastmail.fm Tue Aug 3 09:01:42 2004 From: richardshea at fastmail.fm (Richard Shea) Date: 3 Aug 2004 06:01:42 -0700 Subject: python tutes on win32 References: <1ZmdnZw7k-WA0ZDcRVn-rg@adelphia.com> Message-ID: <282f826a.0408030501.352a9499@posting.google.com> [snip] > > Sorry, I meant tutorial. I did Google for it but I was looking for a > recommended tutorial as I was just starting up Python. > Can't think of a tutorial exclusively for Py/W32 but if you're really just starting (and on a W32 platform) I strongly recommend getting the documentation in Windows Help Format (CHM) - this is a very useful facility enabling searching and a slightly friendlier interface than the online documentation (which is still great I hasten to add). I've just gone looking for where to find that and I can't find it ! I can find other doco downloads but not that, can anyone else tell us where that is ? Also if you have some money to spare I would strongly recommend the O'Reilly book "Python Programming on Win32" by Mark Hammond and Andy Robinson. It's a very useful book although I have to say that if you're just starting you'll find lots to do before you need to start worrying about the bits which are specific to Win32. Make sure you have downloaded the Win32All package - look here http://starship.python.net/crew/mhammond/ (and while you're at it take a look at http://www.python.org/windows/ ) and then you'll have PythonWin as well as IDLE to run/edit your code in, as well as lots of other Win32 stuff which is useful. It occurs to me that you might be thinking of leaping straight into GUI programming using Python. If that's so you may have to discount some of what I've said about not needing to worry about platform differences. I've been using Python for just over a year but so far I haven't got into doing the GUI side of things. Finally somethign I only just found today myself, http://www.rexx.com/~dkuhlman/python_101/python_101.html - it's not Win32 specific but I think you'll find it useful. regards richard shea. From da_rosser at yahoo.com Wed Aug 4 14:45:00 2004 From: da_rosser at yahoo.com (Doug Rosser) Date: 4 Aug 2004 11:45:00 -0700 Subject: Modern dead-tree Python resources References: <411016d7_1@127.0.0.1> Message-ID: "beliavsky at aol.com" wrote in message news:<411016d7_1 at 127.0.0.1>... > Michael Ekstrand wrote: > > >Is there a good book that covers Python at least through 2.2 (including > > >new-style classes, etc.)? I'm particularly looking for something with > >large appendices of reference material. (alternatively, if someone's > >publishing print versions of the Python documentation, that would > >possibly be of interest. > > A good reference for Python 2.2 is "Python in a Nutshell", by Alex Martell. > Also good, and more pedagogical, is "Learning Python", 2nd. edition, by Lutz > and Ascher. O'Reilly published both books. > > > > ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- > http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups > ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--- Sadly, the second edition of Learning Python is so thorough, it isn't superb for -learning- python anymore. It is one helluva nice reference, though. da rosser From sholden at flexal.cs.usyd.edu.au Mon Aug 9 22:31:51 2004 From: sholden at flexal.cs.usyd.edu.au (Sam Holden) Date: 10 Aug 2004 02:31:51 GMT Subject: decorators vs GIL References: <96c2e938.0408081605.706f8ec7@posting.google.com> Message-ID: On Mon, 9 Aug 2004 20:34:36 +0000 (UTC), Jarek Zgoda wrote: > G. S. Hayes pisze: > >>> What really hurts is that I can't honestly tell Java programmers that >> >>> Python is a slam dunk compared to Java & the JVM. Java has no GIL, >> >> >> >> Java has drunk the threads Kool-Aid, and Java programmers are very >> likely to be thread-crazy because of the lack of a select equivalent >> (until recently) and the lack of good access to processes via fork or >> similar. Luckily, it's usually pretty easy to convince people of the >> benefits of NOT overusing threads once they've made that mistake once. > > Try GUI programming without using threads. Right this minute I'm writing a GUI program which creates a long lasting tcp connection, and at times less long lasting udp "connections". No threads. Well I guess one thread... :) -- Sam Holden From t-meyer at ihug.co.nz Wed Aug 18 22:58:05 2004 From: t-meyer at ihug.co.nz (Tony Meyer) Date: Thu, 19 Aug 2004 14:58:05 +1200 Subject: get last two in a length of unknown length? In-Reply-To: Message-ID: > I have a list of varying length. Would someone know the way > to get the last two values for this? I can see how this is > done with a list that I know the length of, but not one thats > generated by user input. One way is to use the length of the list in your calculation, e.g: >>> somelist = [1,2,3,4,5,6,] >>> somelist[len(somelist)-1] 6 >>> somelist[len(somelist)-2] 5 However, a much better and simpler way is to simply count backwards: >>> somelist = [1,2,3,4,5,6,] >>> somelist[-2:] [5, 6] =Tony Meyer From rganesan at myrealbox.com Thu Aug 19 07:41:33 2004 From: rganesan at myrealbox.com (Ganesan R) Date: 19 Aug 2004 17:11:33 +0530 Subject: age of Python programmers References: <4124724C.8040001@chamonix.reportlab.co.uk> <41248398$0$218$edfadb0f@dread12.news.tele.dk> Message-ID: >>>>> "Max" == Max M writes: > Robin Becker wrote: >> Lucas Raab wrote: >> >>> One thing I've always kind of wondered is what is the average age of a >>> Python programmer?? What age groups use Python?? Something to think >>> about.... >>> >> so far with a count of 74 the average is 35.72 > Up that a nudge with me: 39 Down a nudge with me :-). I am 32. Started with Basic on Spectrum 48K and a IBM PC Clone. Some Z80 assembly programming on the Spectrum. Then Fortran, Pascal and even (gasp!) COBOL. Moved on to C, C++ and Shell scripting. Found Perl along the way, was delighted with it. Did a bit of programming in Java. Dabbled occasionally in Tcl and recently C#. Found Python a couple of years back. Nowadays Python has mostly replaced Perl for my scripting needs, though I still fallback to plain old shell scripting occasionally. Ganesan From hbl at st-andrews.ac.uk Tue Aug 10 14:01:21 2004 From: hbl at st-andrews.ac.uk (Hamish Lawson) Date: 10 Aug 2004 11:01:21 -0700 Subject: Maybe, just maybe @decorator syntax is ok after all References: Message-ID: <2d0b37fc.0408100934.560d0e04@posting.google.com> artur_spruce at yahoo.com (AdSR) wrote: > bokr at oz.net (Bengt Richter) wrote in message news:... > > On 9 Aug 2004 07:07:54 -0700, artur_spruce at yahoo.com (AdSR) wrote: > > > > >So the order is reverse, which breaks my previous interpretation. Oh, well... > > > > > I think your example is not from the PEP. What "spec" are you citing? > > http://www.python.org/dev/doc/devel/ref/function.html That part of the reference manual says: """ If there are multiple decorators, they are applied in reverse order. For example, the following code: @f1 @f2 def func(): pass is equivalent to: def func(): pass func = f2(f1(func)) """ I believe that in the example the author may have got confused by the visual appearance of the expression f2(f1(func)). It's the order of *application* that is the key thing and this expression actually has f1 being applied first, rather than f2 as mandated by the "apply in reverse order" rule. The example should instead have given the equivalent expression as f1(f2(func)). Hamish Lawson From aleaxit at yahoo.com Fri Aug 27 02:55:35 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 27 Aug 2004 08:55:35 +0200 Subject: Proposal for removing self References: Message-ID: <1gj65zl.1cuz9ub5xyo3rN%aleaxit@yahoo.com> Delaney, Timothy C (Timothy) wrote: > Andrea Griffini wrote: > > > I remember Alex Martelli advocating in our italian newsgroup on > > C++ that C++ programmers should use "this->..." everywhere :-) > > I evangelise this here (mainly for Java code these days, but close > enough). Unfortunately, I don't seem to be able to convince anyone else While it's also a good idea in Java, it's not as compelling as in C++, because Java mostly lacks the complications due to C++'s templates and freestanding ("not inside a class") names (haven't looked at Java generics so I don't know if they got those complications back in;-). Alex From skip at pobox.com Fri Aug 13 10:47:17 2004 From: skip at pobox.com (Skip Montanaro) Date: Fri, 13 Aug 2004 09:47:17 -0500 Subject: Python indentation deters newbies? In-Reply-To: <3064b51d.0408130615.3fc4a760@posting.google.com> References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: <16668.54389.283204.883202@montanaro.dyndns.org> beliavsky> I wonder if there is a way to remove this initial beliavsky> barrier. Could an alternate source form be defined, so that beliavsky> there are matching if-endif and for-next constructs instead beliavsky> of significant indentation? Look at Tools/scripts/pindent.py in the standard distribution. Run it as a preprocessor over your code before running it. Skip From gyromagnetic at excite.com Fri Aug 20 17:07:52 2004 From: gyromagnetic at excite.com (Gyro Funch) Date: Fri, 20 Aug 2004 15:07:52 -0600 Subject: just ignore Guido's "rejections" [Re: Alternative decorator syntaxdecision] In-Reply-To: <10icpd98dsjcsf2@corp.supernews.com> References: <2uadnbqpMuI1krvcRVn-sg@comcast.com> <10icpd98dsjcsf2@corp.supernews.com> Message-ID: <41266828@news.ColoState.EDU> Jeff Shannon wrote: > Doug Holton wrote: > >> Anthony Baxter wrote: >> >>> On Fri, 20 Aug 2004 09:50:18 -0500, Doug Holton >>> wrote: >>> >>>> We can safely ignore Guido's "rejections" when deciding upon an >>>> alternative to agree upon. Many people felt his rejections of C1 (a >>>> longtime community favorite), E1 and other alternatives were wrong. >>>> http://mail.python.org/pipermail/python-dev/2004-August/048134.html >>> >>> >>> >>> Uh, what? No, you _can't_ ignore Guido's rejections - if you really >>> decide >>> that you must have a form he's objected to, you need a _damn_ strong >>> argument to back that up. A "longtime community favorite" doesn't mean >>> a thing - this is language design, not American Idol - that a lot of >>> people >>> like it makes no difference. >> >> >> >> Um, yes. The point is to determine what the *community* decides on, >> and *then* present that to Guido. You're just helpping confound this >> second vote even more. Some people aren't voting for what they think >> is best, but what they think Guido hasn't "rejected". That is >> ridiculous. You'll end up with a syntax that nobody really ever liked >> most, even Guido. > > > > On the other hand, if the community decides that the only thing they > prefer to @pie is something that Guido's already rejected... then we get > @pie. > I can vote for Superman for president all I want, and I can talk all my > friends into voting for him, but even if a majority of the country votes > for Superman, he's still not gonna be taking any inaugural oath. > Instead of voting for an impossible fantasy, it's much more sensible to > restrict myself to voting for people/options with *some* chance of success. > > Keep in mind here, that what we're trying to do is vote for something > for which we think we can create a convincing case that it's better than > @pie. And Guido is the only person for whom "convincing" is relevant. > If he's already rejected something, it will be *extremely* difficult to > convince him that his rejection was a mistake. I'd rather focus my > efforts where they're a little more likely to bear fruit. > > Jeff Shannon > Technician/Programmer > Credit International > From python-dev >>If the community can *agree* on >>> > something they can support, I will listen. > >> >> Even if it's []-after-args? If most people favor that over prefix @deco, sure, I'll give it another look. (It better come with an implementation though.) --Guido van Rossum (home page: http://www.python.org/~guido/) From hoang at jotsite.com Thu Aug 12 15:19:08 2004 From: hoang at jotsite.com (Hoang Do) Date: Thu, 12 Aug 2004 19:19:08 GMT Subject: drop into the interpreter Message-ID: is there a facility to inspect the run-time of a python script? Essentially, it would execute a script to a set specific point and then drop into the interpreter. Something like a "Stop" or "Break"? Hoang Do hoang at jotsite.com From steven.bethard at gmail.com Tue Aug 10 15:33:36 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: 10 Aug 2004 12:33:36 -0700 Subject: remaining decorator syntax options Message-ID: So here's the state of the decorator debate as I see it: *** Location GvR pretty strongly wants decorators before the function: http://mail.python.org/pipermail/python-dev/2004-August/047112.html http://mail.python.org/pipermail/python-dev/2004-August/047279.html The idea being that decorators and other function properties should not look like part of the function's code. I don't think there's much chance of swaying GvR on this count. *** Indentation Since location has been pretty much decided, I see three options here: (1) dec def f(): pass (2) dec def f(): pass (3) dec def f(): pass GvR definitely disliked the third version because it meant that class functions could all be at different indentation levels. The PEP suggests that the second version was disliked because it suggests that "using" is introducing a new scope (although arguments about if/else behavior seemed to counter this somewhat). There didn't seem to be any arguments that made version 2 drastically better than version 1 though, so it seems most likely that a BDFL pronouncement will give us version 1. *** List notation Assuming a pre-def, non-indented decorator, here are the remaining list notations: (1) dec1 dec2 dec3 (2) [dec1, dec2, dec3] (3) dec1, dec2, dec3 I believe that version 3 was vetoed because it makes it too hard to break lists of decorators across lines. GvR's preference is definitely for 1, but that may be influenced by his decision for the indicator. I have a feeling that how long the indicator is directly affects which of (1) or (2) is preferred. Compare: @dec1 @dec2 @dec3 vs. @[dec1, dec2, dec3] and using dec1 using dec2 using dec3 vs. using [dec1, dec2, dec3] It seems like with a single symbol character, the non-list syntax is much more concise, and probably clearer. However with a keyword syntax the list seems the better option. Which brings us, of course to the final section: *** Indicator The options seemed to be: (1) a symbol (@, |, etc.) (2) a keyword (using, decorate, etc.) (3) similar to function (4) no indicator Options (3) and (4) were ruled out because (given that we're already relegated to a before-def syntax) they are already valid syntax, and redefining them for decorators means changing the expected semantics of the statements. Option (1), with @, is GvR's favorite, and does have something of a Java backing. It has the substantial disadvantage that there is no particular reason (or even some sort of mnemonic) for which @ (or | for that matter) should mean "decorator". With option (2), we can choose a keyword that does suggest a decorator. Even "using", which is not an outstanding choice, is at least more intuitive than '@'. Option (2) does have the disadvantage that it requires introducing a new keyword, but this is not insurmountable -- it was done before for generators. And GvR even said that he would consider this option if there enough support for it. ---- So here's my suggestions: Let's leave the location and indentation arguments behind. We're not making much progress on them, and I don't think there's much chance of swaying GvR. Reiterating all the old arguments won't get us closer to a syntax we're happy with. I think once the indicator argument is decided, the list-structure decision will fall out of it. So I'd suggest that we put all our effort into the indicator discussions. If you have a good argument for why a keyword is better than a symbol, or why a symbol is better than a keyword, please voice them now. And remember that 'because it's prettier' or 'because it's uglier' are not aguments GvR will consider. We need strong arguments, that argue on the basis of readability or learnability or maintainability, etc. ... and my opinion: A keyword is much more Pythonic than a symbol: A well chosen keyword can suggest the meaning of the construction, e.g. "using ... def ..." suggests that the decorators are used as part of the definition of the function. A symbol like '@' or '|' cannot easily suggest the meaning in this manner. For this reason, a keyword makes both reading and learning Python decorator syntax easier. If you encounter "using ... def ..." and have to guess at it's meaning, your knowledge of English "using" can now be applied to guess the meaning of Python "using". This is not true of a symbol like '@' or '|'. (An additional argument might be that it will be at least /possible/ to Google "using", but impossible to do so for "@" or "|". This was one of the frustrating things about Perl for me -- if I didn't know what a symbol did, I couldn't Google it because it wasn't a word. Remember that if you don't know it's a decorator, you don't know to search for "decorate" ;) hoping-to-keep-this-dicussion-productive-ly-yrs, Steve From pm_mon at yahoo.com Sat Aug 14 17:56:37 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sat, 14 Aug 2004 17:56:37 -0400 Subject: Decorators: an outsider's perspective In-Reply-To: <2o7cipF7g74nU1@uni-berlin.de> References: <9ADC3170-EDAF-11D8-9F63-000A95B336F2@snowtide.com> <2o7cipF7g74nU1@uni-berlin.de> Message-ID: Leif K-Brooks wrote: > Paul Morrow wrote: > >> >> Python was built (successfully) on the assumption that obvious >> interpretations of the code obviate the need for declarations. Why >> wouldn't we continue with that mindset? > > > One of the principles of Python is also "explicit is better than > implicit". Your idea, though interesting, doesn't really seem to fit in > with that. I'm really not sure that those 'Zen' items were intended to be absolute guiding principles. For example, we don't (explicitly) declare variables. And I think that the way we indicate blocks of code (via indentation) has a somewhat implicit flavor to it as well (it might be arguably more explicit if we used curly braces or some such). I think that a more appropriate principle here would be something like 'clear is better than ambiguous'. Ideally, any given Python statement should have only one interpretation, shared by the Python system, the statement author, and anyone else who might someday read the statement. Unfortunately, because we have recommended practices that are widely used yet *not enforced by the Python system*, code that strays from the recommended style can confuse --- or even worse, mislead --- the reader. For example, if an experienced Python developer was reading someone's code and saw the following method... class Foo: def setX(self, x): self.x = x ... I doubt that they would consider the possibility that setX might be something other than an instance method of class Foo. Instead, I believe that they would most likely *assume* that the author followed the recommended coding conventions. But setX could be a static method or a class method, if the class later declared it as such. That's wonderfully flexible I know. But I think that we'd all be better off if we didn't have that particular freedom. From john at grulic.org.ar Tue Aug 31 19:21:35 2004 From: john at grulic.org.ar (John Lenton) Date: Tue, 31 Aug 2004 20:21:35 -0300 Subject: Beeping the console In-Reply-To: References: Message-ID: <20040831232135.GE7439@grulic.org.ar> On Tue, Aug 31, 2004 at 03:31:31PM -0600, Jeffrey Barish wrote: > What is the easiest way to beep the console from a Python program (i.e., > to do the same thing as echo -e \a)? perhaps not 'the easiest', but: if it's going to be running on a linux tty, con = file('/dev/tty', 'rw') fcntl.ioctl(con.fileno(), 0x4B30, # KDMKTONE, from linux/kd.h 1190000/2000 + (100 << 16)) will beep the speaker at 2kHz for 100 ticks. if it's going to be running on a console that knows how to beep, curses.wrapper(lambda dummy: curses.beep()) (this might actually be what you're wanting, but it's only slightly better than 'print "\a"'). me, I vote for os.system(conf.soundprog, conf.sounds.beep) :) -- John Lenton (john at grulic.org.ar) -- Random fortune: Q: Why did the programmer call his mother long distance? A: Because that was her name. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From ajsiegel at optonline.com Sun Aug 8 13:54:06 2004 From: ajsiegel at optonline.com (Arthur) Date: Sun, 08 Aug 2004 17:54:06 GMT Subject: Decorators References: <%A8Rc.50217$Vm1.1280580@news20.bellglobal.com> Message-ID: <90qch0t2bp02snqb6eeitt2ta5gigsk5rb@4ax.com> On 8 Aug 2004 04:16:09 -0700, danb_83 at yahoo.com (Dan Bishop) wrote: >Arthur wrote in message news:... >> On Sat, 07 Aug 2004 18:40:47 -0400, Roy Smith wrote: >... >> I am a great believer in (motivated ) folks capacity to learn new >> things. And the existence of synonyms is not news to anyone. So no, >> nobody motivated to learn new things will be stopped in their tracks >> by @ in a new context > >I agree. > >> (anymore than anyone motivated to learn new >> things things would - given an explanation - be stopped in their >> tracks by 1/2 = 0 ). > >I never had a problem with 1/2 == 0; I was already used to it from C, C++, and Java. > >But I did get stopped in my tracks the time a function that contained a line like > > mean = sum(seq) / len(seq) > >failed because the list happened not to contain any floats. Not to get off on it. But you should be aware that I am 100% in agreement with the good arguments related to the this issue, and 100% against the bad ones. ;) Art From zanesdad at bellsouth.net Mon Aug 23 08:53:55 2004 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Mon, 23 Aug 2004 08:53:55 -0400 Subject: training classes in Atlanta, GA? In-Reply-To: References: Message-ID: <4129E8E3.60400@bellsouth.net> Alex Pavluck wrote: >Does anyone know if there are training classes for a PYTHON beginner in >Atlanta, GA? I need it to not be too expensive and after 5 or >weekends! > >Thanks! > >Alex > > > I haven't found anything. I've thought about giving classes before (for beginner->intermediate) in the ATL area. If you're interested, perhaps we could work out a one-on-one class - or if others are interested, perhaps we could work out something more inclusive. Email me back directly if you're interested in discussing this a little. Jeremy Jones From roy at panix.com Fri Aug 6 18:15:13 2004 From: roy at panix.com (Roy Smith) Date: Fri, 06 Aug 2004 18:15:13 -0400 Subject: How to force a single number to be a tuple References: <1a517b5.0408061329.429de7fc@posting.google.com> Message-ID: bryanjugglercryptographer at yahoo.com (Bryan Olson) wrote: > Python tuples overlap too much with lists, and differ from the > functional/relational view in which a tuple is an element of the > Cartesian product of zero or more domains. For those of us who went to school a while ago, and perhaps didn't pay as much attention in math class as we should have, could you translate "an element of the Cartesian product of zero or more domains" into English? > What Python calls 'tuples' are really immutable lists. That's the way I've always thought of them. I know the cognoscenti will insist that tuples are anonymous structures of heterogeneous types and lists are ordered collections of homogenous data, but I don't buy the distinction. There's nothing in the language that makes me think homo vs. hetero for either. Maybe I'm being obstinate (my wife has certainly accused me of that on one more than one occasion), or maybe I just swing both ways when it comes to data containers, but that's the way I see it. I remember once having a white-board discussion with some C++ friends of mine where we were talking about writing code to parse things like: insert into foo values (1, 2, "three", "four"); My Python code built up a list of the values and generated [1, 2, "three", "four"]. My two friends recoiled violently at the idea that I would put heterogeneous data types into a list. I passed it off as simply being due to their poor unfortunate upbringing in the C++/STL world of type bondage, while I was living in the carefree bohemian Python world. I was shocked to discover some time later that Python was not as bohemian as I thought, and the priests and elders would have been as dismayed at my carefree mixing of data types in a list as my stodgy C++ brethren were. I personally think tuples should have used <> instead of (). It would have resolved a lot of notational ambiguity. From reinhold-birkenfeld-nospam at wolke7.net Tue Aug 10 16:24:27 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Tue, 10 Aug 2004 22:24:27 +0200 Subject: Decorator "platform" Message-ID: <2nsoofF49frcU1@uni-berlin.de> Hello, no, I won't start another @ discussion thread; just wondering: Everyone is up and starting with decorators, coding decorator functions, wrapper etc. Many of these ideas sound great, and it would be a big advantage to everyone following to have the different uses of decorators collected, to serve as a starting point or a repository of what's possible. What I have in mind is a sort of "decorator library" where everyone who has written a useful function of that kind can share it with others, instead of only posting it here. As I don't know whether there will be a "decorators" module in the stdlib, this would serve as a replacement until decorators are a final language feature. How would one realise such a project? Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From anthonybaxter at gmail.com Sun Aug 22 02:28:49 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sun, 22 Aug 2004 16:28:49 +1000 Subject: Python future performance and speed In-Reply-To: <7x4qmv6cwo.fsf@ruckus.brouhaha.com> References: <278de0e.0408211605.426e5129@posting.google.com> <7x4qmv6cwo.fsf@ruckus.brouhaha.com> Message-ID: On 21 Aug 2004 20:59:35 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > Well, whenever I want to write a mainstream application and think of > using Python, my first reaction is that Python is too slow... Too slow for what? I'm not being facetious here - what exactly are the bits of Python that are too slow? I used to think this as well, but see my PyCon paper from earlier this year. From mlh at furu.idi.ntnu.no Mon Aug 23 16:53:27 2004 From: mlh at furu.idi.ntnu.no (Magnus Lie Hetland) Date: Mon, 23 Aug 2004 20:53:27 +0000 (UTC) Subject: Standard graph API? References: Message-ID: In article , Paul Moore wrote: [snip] > If we had adaptation in Python (PEP 246) I'd suggest an > IGraph protocol, plus adapters for common implementation methods. This is exactly what I was thinking about -- one could use PyProtocols, for example. The (as of now quite hypothetical) standard would, however, not have to include such an interface; one could easily implement that (and adapters) based on the standard description. I'm thinking along the lines of an informational PEP. >In my personal graph library, I found that one of the nastiest issues >was writing suitably general DFS/BFS algorithms which had "hooks" at >relevant points Yes... I've been thinking about this -- it might be useful to allow some form of traversal (where you could supply your own queue object, for example, giving you bfs, dfs, dijkstra, prim, whatever) and have the traversal take the form of an iterator (similar to the Boost graph library). But if access to each node and its neighbors is available in the interface, such traversals wouldn't really have to be part of the standard API... -- Magnus Lie Hetland "Canned Bread: The greatest thing since sliced http://hetland.org bread!" [from a can in Spongebob Squarepants] From squirrel at WPI.EDU Thu Aug 5 09:45:40 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 5 Aug 2004 09:45:40 -0400 Subject: Decorator syntax In-Reply-To: References: <38ednYT1NLz1P4zcRVn-uA@powergate.ca> Message-ID: On Thu, 5 Aug 2004, Paul McGuire wrote: > remind me of when I lived in Maine. When I complained about how bad the > drivers were, inevitably the response was "we're not as bad as the drivers > in Massachusetts!" I believe that statement is universally true ;) I think much of the problem in coming up with a universally acceptable decorator solution is that we're trying to kill too many birds with one stone. I believe the decorator problem can be seperated into at least three distinct needs: 1) An easy, visually noticable way of declaring the type of a function, such as classmethod and staticmethod. This problem arose because classmethod and staticmethod weren't built in to the language. The foo = classmethod(foo) syntax is a backwards-compatible hack, not the best way to do things. For such a fundamental construct, we need language support. Languages with support for these things already have a clear, consice way of specifying these things: def classmethod foo(self): pass Why can't we do the same with Python? The syntax doesn't have to support user constructs (indeed, it shouldn't), and it doesn't have to support more than one decorator (indeed, with only classmethod and staticmethod to choose from, this doesn't even make sense). 2) An easy, visually unobtrusive way of declaring metadata. This is a problem we've encountered before. The solution was to make a string at the top of the function behave as metadata, rather than code. Perhaps something similar can be done with a dictionary: def foo(a,b,c): {accepts: (int,int,list), author: 'Chris King'} pass foo.__metadata__['accepts'] --> (int,int,list) Note that such a method is implementable in pure Python via some byte-code trickery, and can thusly be made backwards-compatible. Another (perhaps better) method of declaring metadata has been previously proposed, that of function attributes: def foo(a,b,c): .accepts = (int,int,list) .author = 'Chris King' but this proposal has also (sadly) been previously rejected, despite its elegance and similarity to proposed "with" blocks. 3) An easy, visually noticable, yet unobtrusive way of mangling functions: Doing such a thing, IMO, should not have syntax support. When functions are mangled in a user-defined way, it should look like this is happening. Why not make it convenient and wrap in up in a function: def foo(a,b,c): pass mutate(foo, make_my_function_awesome, partializer(5)) This has the advantage of being more general-purpose than syntax support: say make_my_function_awesome is not available, so a NameError is raised. The user can simply skip using that function in that case. Or the existence of make_my_function_awesome can be checked beforehand, and left out of the mutate call if it's not available. If syntax support is used, there's no way to try/except function manglers, save try/excepting the entire function defintion (and forcing multiple identical versions of the function to be defined). Quite ugly. So, to sum it up, let's look at what a totally pimped-out function might look like: def classmethod foo(self,a,b,c): """Returns a+b*c.""" {accepts: (int,int,int), author: 'Chris King'} return a+b*c mutate(foo, make_my_function_awesome, partializer(5)) Compare to the current state of affairs: @partializer(5) @make_my_function_awesome @author('Chris King') @accepts(int,int,int) @classmethod def foo(self,a,b,c): """Returns a+b*c.""" return a+b*c Judge for yourself. From fortepianissimo at gmail.com Mon Aug 2 16:44:38 2004 From: fortepianissimo at gmail.com (Fortepianissimo) Date: Mon, 2 Aug 2004 16:44:38 -0400 Subject: module timeit and variable scope In-Reply-To: References: Message-ID: <78aed1f304080213447cc8425d@mail.gmail.com> On Mon, 2 Aug 2004 16:30:44 -0400, brianc at temple.edu wrote: > >2. How do I introduce a variable into the timeit.Timer? For > example I > >have a class Foo: > >class Foo: > > def __init__ (self): > > # the following line didn't work because the scope is not > > # the calling function > > # self._timer = timeit.Timer(stmt='self.run(bar)') > > pass > > > > def someMethod (self, bar): > > print bar > > > > def run (self, bar): > > # call self.someMethod(bar) and record time using > > # self._timer > > pass > > > Just create an instance in the setup portion of the Timer. > t=timeit.Timer('foo.run()','from __main__ import Foo; foo=Foo()') > To just test __init__ of your class: > t=timeit.Timer('Foo()','from __main__ import Foo') > > Setup only runs once. But this will create a new instance inside the timer. Instead, I want to use an instance that is created *before* the timer is initialized. Something like this: --- CUT HERE --- import timeit class Foo: def __init__ (self): # won't work cuz self is alien to self.timer self.timer = timeit.Timer(stmt = 'f.aMethod()', setup = 'f = self') def aMethod (self): for i in range(10000): i *= 2 def run (self): self.timer.timeit() self.timer.print_exc() f = Foo() f.run() --- CUT HERE --- Any other suggestion? Thank you. From paolo_veronelli at yahoo.it Sat Aug 7 17:15:58 2004 From: paolo_veronelli at yahoo.it (paolo veronelli) Date: Sat, 07 Aug 2004 23:15:58 +0200 Subject: Decorator syntax In-Reply-To: References: <38ednYT1NLz1P4zcRVn-uA@powergate.ca> <2nkk3aF1ph3dU1@uni-berlin.de> Message-ID: On Sun, 8 Aug 2004 06:40:32 +1000, Anthony Baxter wrote: > On Sat, 07 Aug 2004 20:15:01 +0200, Reinhold Birkenfeld > wrote: >> But I fear that without a formal "voting" Python will go the pragmatic >> way - that is, keep @ as it's already implemented. > > As I've said (repeatedly) - this isn't a popularity contest. The point > is to > produce the best technical result. If you have a better solution, put > together > a case for it, and convince Guido wrong list for this > Please, please - download a2. Try the decorator syntax out (or look at > test_decorators, or the hopefully-finished-with-the-rewrite-soon PEP318 > (which I'll also post here) for examples. There is no need to use a new syntax to appriciate it,it's only a syntax we can read it. > Anthony If it has been simple to estabilish the use of the docstring (which I don't use waiting (in vain ?) for a literate python) now this story of decorators has nothing to do with a decoration of the language.It's like we must learn a new way of reading our favourite way of coding,and some of us don't understand why we must do it,as this feature is not for making new things. All in all:if it's only a new way of writing things they can already be written,it's very normal every typer/reader want to express his/her preference,mainly because wants to use it. Every language has a sensual side,Python (and Ruby eheh) beats them all and this battle shows the pride of loving it. Paolino -- ....lotta dura per la verdura From peter at engcorp.com Wed Aug 18 08:18:21 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 18 Aug 2004 08:18:21 -0400 Subject: favorite python web development tool? In-Reply-To: References: Message-ID: Ben Last wrote: > I'm currently approaching the end of a sizeable website development in Zope. > I found it to be a very powerful environment which is *extremely* badly > documented and requires a *significant* investment in learning time. I'm > not new to Python, and that was very useful to me, since I ended up in the > source code of the various Zope components many, many times. If you *are* > new to Python, I would tentatively suggest that Zope is suitable only if > your first development is not mission critical or subject to tight time > pressure. I don't regret choosing Zope as far as suitability is concerned, > but I do believe I underestimated how weak the documentation and support is, > and how difficult it would be to work in. > > This is, I repeat, merely my subjective opinion. Though it is one that others share, me included. I don't regret the time we spent using Zope, but we moved past the point where the investment (time, learning, etc) required to work with it was paid back by the gains. I will say that in our case we later concluded that Zope was not the best fit for the job at hand... but we weren't doing anything that could really be called "content management" so the fault might be more ours than Zope's. -Peter From jpmorichon at earthlink.net Fri Aug 6 04:07:16 2004 From: jpmorichon at earthlink.net (CptPicard) Date: Fri, 06 Aug 2004 08:07:16 GMT Subject: Need help on how to use Pymedia! References: Message-ID: "Dmitry Borisov" wrote in message news:mailman.1222.1091728885.5135.python-list at python.org... > From: "CptPicard" > Date: Thu, 05 Aug 2004 17:48:04 GMT > Subject: Re: Re[2]: Need help on how to use Pymedia! > > > > Here is the code which will give you what you need( from pycar ). It is > > modified to match what you need and therefore not tested.: > > > > > > f= open( , 'rb' ) > > > dec= acodec.Decoder( ) > > > s= f.read( 20000 ) > > > fr= dec.decode( s ) > > > # Hardcoding for mp3 IDv1 tags > > > if not dec.hasHeader() and == 'mp3': > > > f.seek( -128, 2 ) > > > dec= acodec.Decoder( 'mp3' ) > > > dec.decode( f.read( 128 ) ) > > > > > > print dec.getInfo() > > > > I appreciate your support. > > I understand that this is a piece of code specially written for fixing my > > problem but where could I find such example in pycar ? I looked for Decoder > > in the pycar source code (pymedia*-src) and found no match. > > > > Do you include support for tag IDv2 too ? > > Yes it is. > The code is located in pycar/audio/aplaylist.py class AudioFileList.getFileParams() Indeed! > The source for pycar is here: http://prdownloads.sourceforge.net/pymedia/pycar-1.0.0-pre2-src.zip > Dmitry/ > > From rkoenig at ginko.de Sat Aug 28 18:23:33 2004 From: rkoenig at ginko.de (Reinhard Koenig) Date: 28 Aug 2004 15:23:33 -0700 Subject: How to avoid DOS name mangling under Windows 2000 Message-ID: <5244802.0408281423.325a96e4@posting.google.com> I'm working with Windows 2000 and Windows 2000 Server in a cmd window. When I invoke a python script without 'python' prefixed on the command line whose name does not obey the DOS 8.3 syntax the name is mangled under Windows 2000 but not under Windows 2000 Server in an error trace. Why? How can I receive an unmangled name under Windows 2000 without using 'python '? I need it for a later import statement. Thanks Reinhard From zanesdad at bellsouth.net Thu Aug 26 11:25:32 2004 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Thu, 26 Aug 2004 11:25:32 -0400 Subject: Larry Wall & Cults In-Reply-To: <7fe97cc4.0408251356.34f2102a@posting.google.com> References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: <412E00EC.1060308@bellsouth.net> Xah Lee wrote: >Larry Wall and Cults >(Lazyness, Impatience and Hubris) >200012 > >Dear readers, > >Did you know that throughout history there's this thing called cult? >It is a very interesting phenomenon. I don't have time to expound and >teach, but will try to brief you. > > >How can we prevent heinous cults then? Stop bending truths. Education >and rationalism. I'm starting my own cult to exterminate morons on >this earth. Two things are on the top of my agenda: Unixism and Perl. > > Here's some entertaining "stuff" from his website. Couldn't find what he wants to replace UNIX with, though. i as a troll is rather special because i tend to put a final say on things, in contrast with one-liner trolls i myself despise. (In a sense i'm an anti-troll, untroll, or an atrocious atroll.) At first i balked at being branded a troll. Now i revel it. I as a troll is rather recent, beginning and getting worse about in 1998. I have been using online discussion medium since 1990. Perhaps one day i'll write "how i became a troll". It is bound to be a tragedy. --Xah Lee Unix advocating morons, computing professionals, and info suckers, get ready to be pissed off, but make yourself comfortable. Protocols, Resources, Mob rulez generic info on computing protocol specs and resources. SGML, XML, CSS, TCP/IP, DNS, RFC, Unicode, etc. In the computing industry, especially unix community, protocols becoming a stardard is not usually caused by technical excellency, but being commonly in use. Those in common use is usually a result of being free or non-proprietary, which more often than not is technically poor. Last week i bought a chain saw with a twisted handle. Perhaps i wasn't careful, but by accident it chopped one of my arm off, then i thought to myself "gosh, this is POWERFUL!". This seems to be the fashionable mode of thinking among the unixers or unixer-to-be, who would equate power and flexibility with rawness and complexity; disciplined by repeated accidents. Such a tool would first chop off the user's brain, molding a mass of brainless imbeciles and microcephalic charlatans the likes of Larry Wall and Linus Torvald jolly asses. --Xah Lee -------------- next part -------------- An HTML attachment was scrubbed... URL: From adurdin at gmail.com Fri Aug 27 08:11:42 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Fri, 27 Aug 2004 22:11:42 +1000 Subject: allowing braces around suites In-Reply-To: References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> Message-ID: <59e9fd3a040827051139582f3a@mail.gmail.com> On Fri, 27 Aug 2004 12:40:02 +0100, Michael Sparks wrote: > Kjetil Torgrim Homme wrote: > ... > > what do you think? should I write a PEP? The whole topic of explicit[*] end-of-block markers was brought up and discussed at great length in May 1994: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=9405061919.AA03028%40vicorp.com (I was looking at the old archives of c.l.py to try and find info on the origins of triple-quoted strings and docstrings, both of which were born around April 1994) Regardless of history, it looks to me like your problem could be better solved by modifying your emacs mode to consider whitespace more correctly -- AFAICT there is no reason why it should ever pick up the logging line in your example and indent it to the same level as the else: block. From p_s_oberoi at hotmail.com Mon Aug 23 17:02:49 2004 From: p_s_oberoi at hotmail.com (Paramjit Oberoi) Date: Mon, 23 Aug 2004 16:02:49 -0500 Subject: Standard graph API? References: Message-ID: On Mon, 23 Aug 2004 20:41:53 +0000, Magnus Lie Hetland wrote: > enough) I'm not talking about a standard *implementation*, just a > standard *API*, like the DB-API. This could easily cover all kinds of > strange beasts such as directed or undirected, weighted or unweighted > (etc.) graphs; multigraphs, chain graphs, hypergraphs, who knows. I believe the equivalent thing in the C++ world is the Boost Graph Library described here: http://www.boost.org/libs/graph/doc/table_of_contents.html http://www.awprofessional.com/bookstore/product.asp?isbn=0201729148 I tried using it once, and it was so horrendously complicated that I gave up. Some of the complexity came from having to abstract all the different kinds of graphs that were supported, but a lot of it was also a result of the static nature of C++. Still, it may be useful as a source of ideas and/or warning of problems. -param From davids at webmaster.com Fri Aug 27 13:33:09 2004 From: davids at webmaster.com (David Schwartz) Date: Fri, 27 Aug 2004 10:33:09 -0700 Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4dyXc.25792$Ot3.22106@twister.nyc.rr.com> <878yc0ucyl.fsf@thalassa.informatimago.com> Message-ID: "Pascal Bourguignon" wrote in message news:878yc0ucyl.fsf at thalassa.informatimago.com... > Kenny Tilton writes: >> >>What you mean with Unixism? >> > repeated accidents. Such a tool would >> > first chop off the user's brain, molding >> > a mass of brainless imbeciles and >> > microcephalic charlatans the likes of >> > Larry Wall and Linus Torvald jolly >> > Server: Apache/2.0.50 (Fedora) >> > ^^^^^^^^^^^^^^^^^^^^^^ >> >> So you like my approach, which is to condemn things they have never used? >> >> :) > > No, that of no more using things that you condemn. I don't follow you at all. I think you'll find the most useful, meaningful complaints about, say, a Ford Explorer from the people who drive one every day. DS From oriana.falco at thalesesec.com Wed Aug 25 12:02:40 2004 From: oriana.falco at thalesesec.com (Oriana) Date: 25 Aug 2004 09:02:40 -0700 Subject: Regular Expressions Message-ID: <808f000f.0408250802.8c303ea@posting.google.com> hi! I've been working with Python for about two months now but I just started learning about regular expressions. My question is the following. I have a source file that contains code and comments. A piece of the comments contains a revision history that I would like to erase completely from the file since I never update it and I don't use it anymore. The file looks something like /**************************************** * Some info * * More info * *---------------------------------------- * * Revision History: * * blah * blah * blah * *---------------------------------------- I would like to write some sort of regular expression to replace all the text from the first dotted line up to the first asterisk that it's followed either by another asterisk or by another *---- line.....please help, I don't know where to start!!! From harry.g.george at boeing.com Wed Aug 11 18:54:35 2004 From: harry.g.george at boeing.com (Harry George) Date: Wed, 11 Aug 2004 22:54:35 GMT Subject: Python script to generate static site? References: Message-ID: Fred writes: > Hi, > > I'm sure there are a bunch of them, but googling just returned > full-fledged CMS that require a DBMS and generate dynamic pages. > > I'd just like a script that would > 1. look in a directory for articles in raw HTML, > 2. generate a cooked output for each page (ie. add header and footer, > CSS link in HEAD, etc.), > 3. regenerate the homepage with "Last modified" bit following each > article's title, > 4. ready to be uploaded by FTP to a web server that only handles > static web pages. > > Considering Python's wealth of libraries, it's most likely only a > couple hours' work, but since I'm pretty much a Python newbie... > > Thank you > Fred. My Pdx package can do this: manual: http://www.seanet.com/~hgg9140/comp/pdx-1.6.1/doc/manual.html download: http://www.seanet.com/~hgg9140/comp/ You do a template, then do "=include_for html" for the basic datafile you want to wrap. Or write directly in Pdx (less verbose than raw html). -- harry.g.george at boeing.com 6-6M21 BCA CompArch Design Engineering Phone: (425) 342-0007 From vincent at visualtrans.de Sat Aug 7 14:12:14 2004 From: vincent at visualtrans.de (vincent wehren) Date: Sat, 07 Aug 2004 20:12:14 +0200 Subject: [Python-Dev] RELEASED Python 2.4, alpha 2 In-Reply-To: <4113dddd$0$12507$9b622d9e@news.freenet.de> References: <411231C8.3020308@interlink.com.au> <4113429a$0$26993$9b622d9e@news.freenet.de> <41137960.6050400@v.loewis.de> <4113dddd$0$12507$9b622d9e@news.freenet.de> Message-ID: Martin v. L?wis wrote: > vincent wehren wrote: > >> This is on Windows XP Professional. This is a plain vanilla "limited >> user" created via the user accounts tool in the control panel. > > > Ok. I will try that. > > There is a policy AlwaysInstallElevated, with which the administrator > can allow limited users to perform installations: > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/alwaysinstallelevated.asp > > > If the computer is in a domain, this policy can be controlled through > group policy. > > Regards, > Martin Martin, did you see my last remark in my previous post?: > > MSI does have the notion of unprivileged users, but those are the > ones that can't write to System32, the All Users profile, and > HKEY_LOCAL_MACHINE (i.e. non-Administrator, non-Power User users). > There is no provision (AFAICT) for user that can't write to their > own registry. Yes. That makes sense. So I checked the registry with regedit. "HKEY_CURRENT_USER\Software\Classes" seems - for whatever reason - to be busted for this particular user. At least I can't open it manually with regedit, so my tentative guess is the same applies to the installer. Sorry I didn't check this first! -- Vincent Wehren From JSmuts at clover.co.za Tue Aug 31 02:52:01 2004 From: JSmuts at clover.co.za (Jaco Smuts) Date: Tue, 31 Aug 2004 08:52:01 +0200 Subject: python and ssh, scp on windows Message-ID: Hello there The short version question: I am looking for information, resources sample code on using ssh and scp from a python program that will run on windows. The longer version: problem: My brother needs to update his website (hosted on a linux box) using scp. He currently uses putty, pscp (on win 2k). The problem comes in that the site is very large. Invariably his dial-up connection would disconnect before all the files has been uploaded. Unfortunately to our knowledge pscp does not have a resume mechanism when only some of the files has been uploaded. I thought I'd address this by creating a data structure resembling his site structure and files (to be pickled for persistence), this would give me the ability to - keep record of when a file has last been uploaded. Compare this to when the file has last been updated and upload only upload updated files - "restart" the upload should the connection fail before all files has been uploaded. I am considering simply calling pscp (putty secure copy) using popen2, or something to that vain. Are there any better ways. (This is intended to be a fairly simple script not a week project) I have looked at paramiko, but it uses termios, which would limit me to Unix's (just realised demo.py uses termios, so I might be wrong here.) I've also looked at pyssh, but it's been stuck for a very long time at version 0.2, does not support wrapping scp anymore and seems to have issues on windows. I suspect that twisted might provide me with a solution, but I don't really know twisted and this just seems like a bit of an overkill? If that is the way to go I am not closed to this thought, was just hoping for something a bit simpler Any idea's, code, suggestions would greatly be appreciated jaco -------------- next part -------------- An HTML attachment was scrubbed... URL: From aleaxit at yahoo.com Mon Aug 30 09:58:11 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 30 Aug 2004 15:58:11 +0200 Subject: initializing mutable class attributes References: Message-ID: <1gjc8cs.sqvo1v1fhabdjN%aleaxit@yahoo.com> Dan Perl wrote: > There is something with initializing mutable class attributes that I am > struggling with. I'll use an example to explain: > class Father: > attr1=None # this is OK > attr2=[ ] # this is wrong > def foo(self, data): > self.attr1=data > self.attr2.append(data) > The initialization of attr1 is obviously OK, all instances of Father > redefine it in the method foo. But the initialization of attr2 is wrong > because all the instances of Father end up sharing the same value. Maybe > that is desired sometimes, but usually it is just a bug. I disagree: good Python programmers often use mutable class attributes, and use them to good effect. I've done my share of Python teaching, consulting and mentoring, and I definitely do *not* think this usage "is desired sometimes but usually it is just a bug". > So the only solution I see to this is to initialize attr2 in __init__: > class Father: > attr1=None > def __init__(self): > self.attr2=[ ] This is the canonical way, sure. > This is already awkward because there is such a difference between attr1 and > attr2. One is a class attribute (which nobody forced you to have), the other is an instance attribute. If you want both to be instance attributes, initialize both in __init__ -- that's all there is to it. Don't use class attributes unless there's a reason for them to be class attributes, that seems like a good and sensible rule of thumb to me. > But moreover, I think this forces subclasses of Father to do > something like this: > class Child (Father): > def __init__(self): > Father.__init__(self) > self.attr3=[ ] Assuming an instance of Child needs to have both attributes attr2 and attr3, yes. > > I find this even more awkward because many people will forget to do it. Forget to do what -- call the parent class's __init__? Again, this is rare -- not as rare as the other "usually just a bug" you opined about, but not common. A class normally needs __init__ for a large number of purposes, of course, not just to assign mutable attributes to each instance, therefore people who learn subclassing do learn to call the parent class __init__ very early on, to avoid everything breaking. > Clearly, this is then a more general issue with __init__, but I think it is > accentuated by the fact that you HAVE TO HAVE __init__ in order to > initialize attributes that are mutable. Making __init__ more common means people are more likely to get used to it, and thus makes the bug of not calling a parent class's __init__ rarer, not "accentuated". > > Is there something I don't know here and there is a better way to do this in > Python? I would like to get a better solution or otherwise start a > discussion. There is no BETTER way, IMHO, than normal Python coding, which I believe is quite good -- but you appear to disagree, therefore it's hard for me to gauge what you may consider "better". There is definitely a DIFFERENT way -- coding a custom metaclass which will tweak the instantiation of all classes belonging to it, in order to insert some funky initialization of mutable attributes, and perhaps automate calls to superclasses' __init__ methods, and so on. Such automation is a ticklish issue, in the general case, so let's assume initializing mutable attributes is all we ever want to do. Then, for example...: import copy class metaImu(type): def __call__(cls, *a, **k): instance = type.__call__(cls, *a, **k) for sup in cls.mro(): muts = gerattr(sup, '__mutables__', ()) for mutname in muts: if hasattr(instance, mutname): continue mutvalue = muts[mutname] setattr(instance, mutname, copy.copy(mutvalue)) return instance class Father: __metaclass__ = metaImu __mutables__ = dict(attr1=None, attr2={}) class Child(Father): __mutables__ = dict(attr3=[]) I haven't tested this, but I believe it should behave as you appear to desire (assuming you want shallow rather than deep copying of the values, of course: I can't read your mind!). I specifically showed that you can use __mutables__ also for attributes which are in fact not mutable, since copy.copy should be innocuous (identity) on those, just in case you insist on having the same form for all such attributes. I have also assumed that an instance's __init__ may be allowed to set its own value for an attribute in __mutables__ and if it does so then that should be left alone. But of course you can play with all of these aspects at will. You could even have that __call__ method examine all attributes defined in the class (or any superclass) and force copies of them into instance attributes for all whose types are [[whatever criteria you like...]]. Alex From peter at engcorp.com Tue Aug 17 19:34:57 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 17 Aug 2004 19:34:57 -0400 Subject: Flython? In-Reply-To: References: Message-ID: <65adnQvUKIK_C7_cRVn-jQ@powergate.ca> Sandy Norton wrote: > Peter Hansen wrote: >>In the vein of Jython, I wonder what it would take to build >>a Flython? (Lousy name, I know.) That would take Python >>source, presumably a subset since some things couldn't be supported, >>and compile it into ActionScript bytecode (aka the bytecode compiled >>from ECMAScript source for the Macromedia Flash player environment). > > Have you looked at http://ming.sourceforge.net/ Briefly, but I'm not fully qualified to judge. I wrote this in another post that you might not yet have seen: """Ming appears to be in an extremely early form, and there are suggestions it's not very stable yet (and I think that word was used in the sense of "unreliable", not just "changing"). The script support appears to be "C-like, with a very limited feature set". Doesn't even allow function calls?! That can't be good. """ -Peter From bart_nessux at hotmail.com Thu Aug 12 22:42:15 2004 From: bart_nessux at hotmail.com (Bart Nessux) Date: Thu, 12 Aug 2004 22:42:15 -0400 Subject: Print Special Symbols in Tk GUI Message-ID: Using tkinter to create a Python version of Microsoft's winver. Works great... how can I print the copyright symbol (c) and the registered (R) symbol into the GUI? Thanks, Bart From pm_mon at yahoo.com Tue Aug 24 12:29:38 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Tue, 24 Aug 2004 12:29:38 -0400 Subject: Are decorators really that different from metaclasses... Message-ID: ...that they warrant an entirely new syntax? It seems that they are very similar in a very significant way --- they alter the default behavior of something. IMO, it's not a stretch to say that they 'parallel' metaclasses; that they are to functions/methods what metaclasses are to classes. So why don't they share a similar syntax? class Foo: """ This is the docstring for class Foo. """ __metaclass__ = M # body of class goes here def baz(): """ This is the docstring for function baz. """ __features__ = synchronized, memoized # body of function goes here. I personally find the above baz function aesthetically appealing. Does anyone else feel this way? For contrast, below is the same function written in the proposed A1 and J2 [*] syntaxes (respectively). @synchronized @memoized @doc(""" This is the docstring for function baz. """) def baz(): # body of function goes here. decorate: """ This is the docstring for function baz. """ synchronized memoized def baz(): # body of function goes here. * if J2 is accepted, the name 'decorate' may be replaced with some other keyword, but I believe that the structure of the syntax would stay the same. Paul From rschroev_nospam_ml at fastmail.fm Sat Aug 28 12:42:16 2004 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Sat, 28 Aug 2004 16:42:16 GMT Subject: allowing braces around suites In-Reply-To: <1r8ybzcs7v.fsf@rovereto.ifi.uio.no> References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> <87hdqok9i6.fsf@sinken.local.csis.hku.hk> <1rfz68ely9.fsf@rovereto.ifi.uio.no> <876574k7du.fsf@sinken.local.csis.hku.hk> <1r3c28ejis.fsf@rovereto.ifi.uio.no> <5MWXc.228027$ht5.11749427@phobos.telenet-ops.be> <1rhdqnd3rm.fsf@rovereto.ifi.uio.no> <1r8ybzcs7v.fsf@rovereto.ifi.uio.no> Message-ID: Kjetil Torgrim Homme wrote: > indeed, C or C++ is no better in this respect, quite the opposite IMO. > Paul McGuire illustrated the corresponding problem in C: > > db->update_name(person); > > if (is_student(person)) > log("update student %s", person->name); > db->update_courses(person); > db->commit(); Sorry, I meant "C or C++, even with consistent use of braces", implying that using braces IMO in general doesn't help spotting this kind of bugs. -- "Codito ergo sum" Roel Schroeven From michaels at rd.bbc.co.uk Fri Aug 27 04:37:10 2004 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Fri, 27 Aug 2004 09:37:10 +0100 Subject: mixing statements into J2 References: <3A81C87DC164034AA4E2DDFE11D258E3022E85@exchange.hqamor.amorhq.net> Message-ID: Anthony Baxter wrote: > On Thu, 26 Aug 2004 10:36:08 -0700, Robert Brewer wrote: >> using: >> if test: >> memoize >> else: >> synchronize >> classmethod >> def foo(self, *args): >> stuff(args) .. > The above _should_ generate a SyntaxError on the 'if'. With the current patch it does. Michael. -- Michael.Sparks at rd.bbc.co.uk British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From tim.peters at gmail.com Sat Aug 14 23:28:41 2004 From: tim.peters at gmail.com (Tim Peters) Date: Sat, 14 Aug 2004 23:28:41 -0400 Subject: ironic doctest bug? In-Reply-To: <10htcuj6374u5d@corp.supernews.com> References: <10hq7lsguiqfj93@corp.supernews.com> <10htcuj6374u5d@corp.supernews.com> Message-ID: <1f7befae04081420281617753e@mail.gmail.com> [Alan G Isaac] >> 1 items had failures: >> 1 of 14 in doctest.Tester.rundict >> 71 tests in 47 items. >> 70 passed and 1 failed. >> ***Test Failed*** 1 failures. > This was the punchline of course. > Am I overlooking something? Mostly just this: http://www.catb.org/~esr/faqs/smart-questions.html You didn't say which version of Python, or which OS, and didn't ask a specific question despite a long original post. Those points all conspired to make the post ignorable. My guess is that you're using some flavor of Python 2.3. Your original post contained the only relevant clue: > python doctest.py -v If you had run it without -v, my guess is that it would have passed. Looking at the output with -v identifies the failing test when running with -v. That's >>> testmod(m1, isprivate=is_private) in doctest.Tester.rundict's docstring. Looking at the other tests in the docstring shows that they all add verbose=0 to their testmod() call, and that this one was unique in not doing so. So someone was probably a teensy careless when they added this test. Change the test to >>> testmod(m1, isprivate=is_private, verbose=0) so it looks like the others, and then it passes with or without -v. It's too minor a bug to justify a new Python 2.3 release . The problem doesn't exist in Python CVS, so it won't happen in 2.4. From artur_spruce at yahoo.com Sun Aug 8 08:22:02 2004 From: artur_spruce at yahoo.com (AdSR) Date: 8 Aug 2004 05:22:02 -0700 Subject: Maybe, just maybe @decorator syntax is ok after all References: Message-ID: Ville Vainio wrote in message news:... > It might just be that @decorator might not be all that bad. When you > look at code that uses it it's not that ugly after all. You know what, I'm starting to feel the same. Yesterday Anthony Baxter mentioned this URL: http://mail.python.org/pipermail/python-dev/2004-August/047112.html where GvR says: """ Given that the whole point of adding decorator syntax is to move the decorator from the end ("foo = staticmethod(foo)" after a 100-line body) to the front, where it is more in-your-face, it should IMO be moved all the way to the front. """ And I had the sudden feeling that I finally got it. You see, for me, the @decorator syntax is a declaration - first thing that came to my mind was Pascal's "forward". So it says "take the def that follows and insert a (old style) decoration line in the code after it." Note that here the "def" is recursive - it may have other @decorators before it. I'm not sure I'm making myself clear; my understanding of it is more by feeling than by logic. So let's say that @decorator is like a preprocessor directive. If we have: @dec1 @dec2 def foo(): pass then after the first pass it becomes: @dec2 def foo(): pass foo = dec1(foo) and after the second: def foo(): pass foo = dec2(foo) foo = dec1(foo) BTW, this interpretation leaves some space for future manipulation of if/for/while/try statements. Speaking of loop statements, they have an optional else clause that isn't obvious either. It means "do this if there was no break-exit from the loop." Yet for me the obvious meaning would be "if there were no loop passes" - that is, the while condition was false on the first entry or the for list was empty. I think the word "finally" would be more to the point here (and it's a keyword anyway). I think having some obscurity in the language is inevitable. The present way of applying decorators (x = decor(x)) is equally cryptic to a newbie as the @decor syntax will be - first you have to know what a decorator is. There even aren't any decorators used in the standard lib - or at least grep doesn't show any static/classmethod rebindings. > My chief worry was throwing away one of the few unused ascii symbols, > but if we take a look at perl6, there is a lot of promising unicode > symbols to choose from in the future ;-). Also, there is still @(), > @#, @{} and others in the hypothetical event BDFL would like to use @ > for future features like macros, ruby blocks or whatever. And we still have ? and $, plus the backtick (`) that now is for repr, but in Python 3000 will hopefully be for "os.popen.read(); ...close()" like in bash for example, or something equally useful. > So I would vote +0 for @decorator if we were in the parallel universe > where that mattered. Two days ago I was -10. Same here. I'm opposed to dictatorship in general - I grew up behind the Iron Curtain - but the BDFL's decisions so far were mostly beneficial, so I'll live with whatever he decides (I'm not saying this as seriously as it sounds). AdSR From greg at cosc.canterbury.ac.nz Tue Aug 31 01:54:57 2004 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Tue, 31 Aug 2004 17:54:57 +1200 Subject: Xah Lee's Unixism In-Reply-To: References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4PGdnfsOfdDPi63cRVn-tA@speakeasy.net> <41337FC9.8070902@hotmail.com> Message-ID: <2pii5kFl6rr2U1@uni-berlin.de> Andre Majorel wrote: > If by unixism, you mean any operating system that has a > hierarchical filesystem and byte stream files, yes. But that > would include quite a few other non-Unix operating systems, > including Mac OS 9, Prologue and probably everything else this > side of CP/M (DOS 1.x shall be deemed to be CP/M). CP/M files weren't quite exactly streams of bytes. They were more like streams of 128-byte blocks (hence the kludge of using control-Z to mark the end of a text file). -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From ben at benlast.com Tue Aug 17 08:46:02 2004 From: ben at benlast.com (Ben Last) Date: Tue, 17 Aug 2004 13:46:02 +0100 Subject: how to display unicode in a Label in Tkinter In-Reply-To: Message-ID: Ali wrote: > > So how I write in Arabic? Eric answered: > There must be another simpler way, based on the standard encoding > used when > using Arabic characters. But I don't know this encoding, so I > cannot help you > much here. I also don't know how you can input these characters > in a computer > (especially in a source file, where the character flow is from > left to right) The easiest way I have found to have Unicode strings is not to embed them in the source at all, because every so often I'll find that I've passed my source through a Python editor or tool that doesn't grok encodings and all my embedded characters have been mangled. Instead, I write the Unicode strings in an editor (such as the humble Notepad) that supports saving UTF8 files, and save them that way, usually in a simple "keyword=value" format so that my Python code can open up the file, read in the strings, decode them from UTF-8 and there's your Unicode all available. To echo other comments, though, AFAIK, TkInter doesn't do non-Western languages very well, if at all. A contact of mine has reported more success with wxPython, but the projects I'm on now don't venture outside the Latin encodings, so I can't advise as to whether Arabic is supported. Having moaned somewhat there; I have to say that Python has about the sanest Unicode handling of any environment I've yet had to use in anger... I learned i18n in C on VAX/VMS systems, the hard way... regards ben From eurleif at ecritters.biz Mon Aug 23 00:08:16 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Mon, 23 Aug 2004 00:08:16 -0400 Subject: Getting benifits of database transactions in an OO way? In-Reply-To: References: <2oq8pmFdd2nfU1@uni-berlin.de> Message-ID: <2ot8mtFe30vqU1@uni-berlin.de> Jeffrey Froman wrote: > You might want to take a look at http://sqlobject.org (transaction examples > provided in the documentation as well.) Wow, nice. Thanks a lot for the link. From pythos Mon Aug 23 23:09:05 2004 From: pythos (pythos) Date: Mon, 23 Aug 2004 23:09:05 -0400 Subject: Help with trapping an exception References: Message-ID: On Mon, 23 Aug 2004 21:13:48 -0400, Phil Frost wrote: >Take a look at the traceback standard module to format exceptions >nicely. Ah, this looks like what I want. Although when I use either traceback.print_tb(sys.exc_info()[2]) or traceback.print_exc(), it only shows the most recent call in the traceback. This is what it shows: Traceback (most recent call last): File "C:\Documents and Settings\xxxxx\rot.PspScript", line 36, in ProcessDirectory App.Do(Environment, 'FileOpen', { Why doesn't it show everything, which would be: Traceback (most recent call last): File "c:\Documents and Settings\xxxxx\rot.PspScript", line 79, in Do os.path.walk(baseDirectory, ProcessDirectory, Environment) File "c:\Program Files\xxxxxx\Python Libraries\lib\ntpath.py", line 318, in walk func(arg, top, names) File "c:\Documents and Settings\xxxxx\rot.PspScript", line 36, in ProcessDirectory App.Do(Environment, 'FileOpen', { NameError: global name 'Environment' is not defined From aleaxit at yahoo.com Fri Aug 27 02:25:43 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 27 Aug 2004 08:25:43 +0200 Subject: Call for signatories for J2 References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> <7xoekx4wit.fsf@ruckus.brouhaha.com> <1gj5cs7.wqxd1s1ec69umN%aleaxit@yahoo.com> <7xfz69oc1f.fsf@ruckus.brouhaha.com> <1gj5eom.gbo9f512upip0N%aleaxit@yahoo.com> <7x1xhtd2o3.fsf@ruckus.brouhaha.com> Message-ID: <1gj63xf.qhd5o31s1o71jN%aleaxit@yahoo.com> Paul Rubin wrote: > aleaxit at yahoo.com (Alex Martelli) writes: > > Type declarations make me cringe, but if I *had* to have them then 'b as > > int' is the best syntax I could imagine for them offhand. > > b:int worked ok in Pascal. And "b as integer" works quite reasonably in Visual Basic -- I'm not a VB fan, by any means, but that particular tidbit of VB syntax sugar is (IMHO) quite good. A precedent for a dual use of AS, quite close to what we'd have here, is in SQL. "SELECT foo AS bar" is a local renaming, just like Python's "import foo as bar"; "CAST(foo AS integer)" is type coercion. Note that both SQL uses are good parallel for some of the 'overloads' of 'AS' in English;-). All in all, the argument that declarator syntax 'might' end up doing double use for typing purposes is hardly a strong deterrent to the use of keyword 'as' in declarator syntax. Alex From h.b.furuseth at usit.uio.no Fri Aug 6 16:35:42 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 06 Aug 2004 22:35:42 +0200 Subject: Proposal: require 7-bit source str's References: <4112AC7B.1060508@v.loewis.de> <411343D7.3020604@v.loewis.de> <411353A3.8090502@v.loewis.de> <4113759E.2070405@v.loewis.de> <4113E755.8060205@v.loewis.de> Message-ID: Martin v. L?wis wrote: >Hallvard B Furuseth wrote: >> That sounds like it could have a severe performance impact. However, >> maybe the compiler can set a flag if there are any such strings when it >> converts parsed strings from Unicode back to the file's encoding. > > Yes. Unfortunately, line information is gone by that time, so you can't > point to the place of the error anymore. True. One could recompile with a str7bit option to catch it earlier, or one could make str7bit a compiler directive - then the unidentified string will in practice be the doc string above the directive. >> I can't say I like the idea, though. It assumes Python retains the >> internal implementations of 'coding:' which is described in PEP 263: >> Convert the source code to Unicode, then convert string literals back >> to the source character set. > > It's a pretty safe assumption, though. It is the only reasonable > implementation strategy. I disagree: - For a number of source encodings (like utf-8:-) it should be easy to parse and charset-convert in the same step, and only convert selected parts of the source to Unicode. - I think the spec is buggy anyway. Converting to Unicode and back can change the string representation. But I'll file a separate bug report for that. >> Sure. I wasn't protesting against people using of escape sequences. >> I was protesting against requiring that people use them. > > But isn't that the idea of the str7bit feature? How else would you > put non-ASCII bytes into a string literal while simultaneously turning > on the 7-bit feature? Sorry, I thought you were speaking of promising a __future__ when all string literals are required to be 7-bit or u'' literals. To use non-ASCII str literals with the str7bit feature turned on: - insert a 'str7bit:False' declaration in the file, or - use the s'8-bit str literal' syntax I suggested. -- Hallvard From s.mail at westo.at Thu Aug 26 14:16:25 2004 From: s.mail at westo.at (Stefan Stolz) Date: Thu, 26 Aug 2004 20:16:25 +0200 Subject: Mysql in Python? References: <2p6m32Fh7o9oU1@uni-berlin.de> Message-ID: <2p6nnpFhoue1U1@uni-berlin.de> Jeremy Jones wrote: > I'm not sure, but I believe that MySQLdb is included in this project: > > http://sourceforge.net/projects/mysql-python > > (which appears to have been updated only a couple of months back, so > that's good news). Thank you, but i don`t understand why there is nothing implemented in Python? I was a little konfused after reading the doku of mysql-python, because there the author says its better to use MySQLdb ;-) ?!?! -- Gr?sse Stolz Stefan From p_s_oberoi at hotmail.com Sat Aug 7 10:53:31 2004 From: p_s_oberoi at hotmail.com (Paramjit Oberoi) Date: Sat, 07 Aug 2004 09:53:31 -0500 Subject: Plotting histograms, scatter plots in Python References: <7S4Rc.49729$Vm1.1245341@news20.bellglobal.com> Message-ID: >> Pychart: >> http://www.hpl.hp.com/personal/Yasushi_Saito/pychart/ > > The charts look good, but the source code links fail. I just tried downloading it, and they seem to work for me... From aleaxit at yahoo.com Fri Aug 27 14:07:43 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 27 Aug 2004 20:07:43 +0200 Subject: Alex Martelli: Welcome back! References: Message-ID: <1gj70s0.cc0xt0bs9aduN%aleaxit@yahoo.com> Dave Benjamin wrote: > It's nice to see you around here again! Thanks! Hope I can stay a while... Alex From elbertlev at hotmail.com Mon Aug 23 12:42:52 2004 From: elbertlev at hotmail.com (Elbert Lev) Date: 23 Aug 2004 09:42:52 -0700 Subject: 2 GB files References: Message-ID: <9418be08.0408230842.3484a321@posting.google.com> "Roman Yakovenko" wrote in message news:... > > Elbert Lev wrote: > > > From postings to this group and other resources I > understood that the > > > only way to make Python programs to work correctly with files lager > > > then 2 GB is building Python interpreter with some "magic spell" > > > defines. > > It is not true. Sometimes I am working with files 6G+. Python is my only > way to look into those files. > > Roman I'm terribly sorry. There was a "mix" of several versions. You are right it does autodetect. From Joe.Smith at inwap.com Sun Aug 29 07:05:32 2004 From: Joe.Smith at inwap.com (Joe Smith) Date: Sun, 29 Aug 2004 11:05:32 GMT Subject: Larry Wall & Cults In-Reply-To: <4130654c$0$19703$61fed72c@news.rcn.com> References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <776e0325.0408260433.449660c8@posting.google.com> <412dfc1c$0$65599$a1866201@newsreader.visi.com> <86hdqpriww.fsf@blue.stonehenge.com> <412e199e$0$8076$a1866201@newsreader.visi.com> <4130654c$0$19703$61fed72c@news.rcn.com> Message-ID: <0MiYc.109993$TI1.98802@attbi_s52> jmfbahciv at aol.com wrote: >>AND HOW MANY SPACES PER TAB STOP? > > Eight. Now talk about indenting skip returns...that one > required blood transfusions. [emoticon looks at list of n.g.] > I guess not many will understand. I understand. The style I used for PDP-10 macro assembly language was *) Indent two spaces for error return from subroutine or UUO (or jsys) *) Indent one space for instructions that skip or may skip. The other point of contention was what to put between the opcode and its arguments; space vs tab. I had some TECO macros that would undo the damage after pristine code had been munged by someone not conforming to style. :-) -Joe From cpl.19.ghum at spamgourmet.com Sun Aug 8 05:44:00 2004 From: cpl.19.ghum at spamgourmet.com (Harald Massa) Date: Sun, 8 Aug 2004 09:44:00 +0000 (UTC) Subject: Going the PL/1 way References: Message-ID: Ville, just to add some: > I guess this depends on the developer. I can't help lovin' stuff like > genexps that are coming in 2.4, yeah, I am really looking forward to them. List comprehensions are a so natural way to express some situations, and with the additional elegance of "not having to lock memory" it will be even more phantastic. Also ... the sets module, introduced with 2.3, I think. It is SO natural - many, many problems can be formulated within sets-algebra (find all customers who have X and Y ... just get the intersections of two sets). And with 2.4 sets will be a builtin, that shows me the commitment of the Python community that they will be supported for EVEN longer than the usual many years of a stdlib module. And: the decimals data type. When working in the financial industry, it is UNBELIEVABLE PHANTASTIC to finally get a feature that helped COBOL live THROUGH AGES. (while being the MOST UGLY chick on the block, COBOL allways had VERY WEALTHY boy friends - not being cool, but having a big car, big house...) - and now Python will be ONE OF THE FIRST really sexy chicks of programming languages that will have a DECIMAL type!! Than: datetime, introduced with 2.3. Yes, there was mx.datetime before. Who has read a DBAPI-Database-Driver? "try: import mx.datetime ... except: print some wired error" --- with datetime in the standard lib there is no longer a need to download additional modules just to print nice dates. GREAT!!! I do not understand at all what's that decorators thingy, but I know that girls often put some deco into flats and it really looks cosy after, so I assume that decorators are not on the dark side of the source. Maybe we should ask for a ternary decorator, because I learned that "ternary" and "decorator" triggers high emotions within the Python community. I often struggle with encodings - and in growing versions of Python you can see that also Python does sth. more with encodings - allowing unicode in more and more places, growing "string types" instead , putting Encoding-Tags within source code. That's a healty relationship with a language, I feel, when the language and me are struggling with the same problems. So: I am really looking forward to Python 2.4, decorated or not, I will take it. Harald From 1stpoint at zmailbox.net Wed Aug 4 10:28:44 2004 From: 1stpoint at zmailbox.net (1stpoint) Date: Wed, 04 Aug 2004 10:28:44 -0400 Subject: py2exe and os.popen References: <94737de0df0675e750e306af1ae2e475@localhost.talkaboutprogramming.com> Message-ID: <81bf1e736b63a30ce84eb7f6c7ddb29e@localhost.talkaboutprogramming.com> I figured it out. It wasn't os.popen afterall, I just forgot to include the .exe that I needed. From newsgroups at jhrothjr.com Thu Aug 12 21:26:15 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Thu, 12 Aug 2004 21:26:15 -0400 Subject: Rather than decorators, how about sections? References: <411C12D4.7010400@yahoo.com> Message-ID: <10ho66lhatd1e74@news.supernews.com> "Steve" wrote in message news:411C12D4.7010400 at yahoo.com... > > Is there a simple primer for static and class methods > and decorators and such that you can recommend? It's cleverly hidden on the Python documentation page, under "additional documentation." http://www.python.org/doc/newstyle.html At some point all of this should be integrated into the standard documentation, but that task has been hanging fire since 2.2. John Roth From jeff at ccvcorp.com Fri Aug 27 14:51:30 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 27 Aug 2004 11:51:30 -0700 Subject: allowing braces around suites In-Reply-To: <1ry8k0d2az.fsf@rovereto.ifi.uio.no> References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1ry8k0d2az.fsf@rovereto.ifi.uio.no> Message-ID: <10iv0kid2ig9ka6@corp.supernews.com> Kjetil Torgrim Homme wrote: >"pass" is a no-op, and should only be used when a suite is required, >but the suite should do nothing. you're proposing a convention saying > > ''if "pass" appears in a suite which also contains other > expressions, the "pass" signals the end of the suite'' > >that's a hack, and IMHO not worthy of a Python program. not even Perl >has anything like that, AFAIK. > > The irony of these being said in defense of adding braces (even optional ones) to Python is truly awe-inspiring. Jeff Shannon Technician/Programmer Credit International From JBrouwersAtProphICyDotCom at no.spam.net Thu Aug 26 18:35:42 2004 From: JBrouwersAtProphICyDotCom at no.spam.net (Jean Brouwers) Date: Thu, 26 Aug 2004 22:35:42 GMT Subject: property puzzle References: <78b6a744.0408260846.5dc5a0cf@posting.google.com> Message-ID: <260820041535594501%JBrouwersAtProphICyDotCom@no.spam.net> Also, property needs bound methods to get, set, and delete, like status = property(self._get_status, self._set_status) /Jean Brouwers In article <78b6a744.0408260846.5dc5a0cf at posting.google.com>, george young wrote: > [python 2.3.3, x86 linux, part of a substantial gtk/postgres app] > I want a Run instance to have a Status instance which inherits > from Observable. I want to be able to say: > > thisrun.status = 'planned' > > and have thisrun's _set_status do side-effects and then the status > object's setter incorporate the new value as it's new state. > But the setter functions never seem to get called. > Am I using "property" wrong? > > class Observable: #("observer" software pattern) > def __init__(self): > self.observers = [] > def register(self, func, *args, **kw): > self.observers.append((func, args, kw)) > def notify(self): > for func, args, kw in self.observers: func(*args, **kw) > > class RunStatus(Observable): > def __init__(self, val): > Observable.__init__(self) > self._value = val > def set(self, newval): > print 'RunStatus.set' > self._value = newval > self.notify() > def get(self): > print 'RunStatus.get' > return self._value > > class Run: > def __init__(self): > self._status = RunStatus('planned') > def _get_status(self): > return self._status > def _set_status(self, val): > # do various things with val... > self._status.set(val) > status = property(_get_status, _set_status) > > if __name__ == '__main__': > def stat_display(): > print 'display to screen: r.status=', r.status > r = Run() > r.status.register(stat_display) #many registers in real app. > r.status='hold' > print 'status=', r.status > print r._status.observers > > Status needs to be a real and persistant object so it's > observers persist, but needs it's value changed simply, like > r.status = 'something' > > [flames about using string values for what is semantically a > six valued enum *are* welcome in a separate thread...] From peter at engcorp.com Thu Aug 19 12:52:31 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 19 Aug 2004 12:52:31 -0400 Subject: Interface to win32 resources In-Reply-To: <2ojvrqFbj9ttU1@uni-berlin.de> References: <2ojvrqFbj9ttU1@uni-berlin.de> Message-ID: Paul Watson wrote: > I would rather use a module that comes with Python that to require the user > to install win32all. This would reduce complexity and possibly resistance > to using a Python application. If you use py2exe (or an equivalent), and for that matter use a proper installer-builder such as InnoSetup, then there will be no resistance to using a Python application merely because it requires some of the pywin32 (formerly win32all) stuff. Note you could also use ctypes (also not part of the core though) which is quite a bit smaller than pywin32. If you have a "real" application such that the users might actually resist using it for such a reason, there's no reason they even have to know it was done with Python. -Peter From mark_bottjer at hotmail.com Thu Aug 12 16:35:20 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Thu, 12 Aug 2004 16:35:20 -0400 Subject: wiki update: decorator syntax breakdown In-Reply-To: References: <411ac3cc$1@nntp.zianet.com> Message-ID: <411bd488$1@nntp.zianet.com> Steven Bethard wrote: > Mark Bottjer wrote in message news:<411ac3cc$1 at nntp.zianet.com>... >>class C: >> def c(self): >> meta: >> classmethod >> doc('This is a function!') >> pass > > > I think this would fall under: > Indicator: keyword: 'meta' > Location: post-def > List Notation: One per line > Indentation: Indent decorators only > > Right? I added 'meta' to the keyword section. I think so, yes. Thanks. -- Mark From spamtrap at dot-app.org Tue Aug 31 16:13:36 2004 From: spamtrap at dot-app.org (Sherm Pendley) Date: Tue, 31 Aug 2004 16:13:36 -0400 Subject: Xah Lee's Unixism In-Reply-To: References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4PGdnfsOfdDPi63cRVn-tA@speakeasy.net> <41337FC9.8070902@hotmail.com> <%T%Yc.29567$Es2.11957889@news4.srv.hcvlny.cv.net> <4134AC88.56452265@yahoo.com> Message-ID: <8KadnRWhvb1sRqncRVn-tg@adelphia.com> red floyd wrote: > Let the editor flame wars begin! Anyone else remember Blackbeard? sherm-- -- Cocoa programming in Perl: http://camelbones.sourceforge.net Hire me! My resume: http://www.dot-app.org From ptmcg at austin.rr._bogus_.com Thu Aug 26 09:50:39 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Thu, 26 Aug 2004 13:50:39 GMT Subject: Call for signatories for J2 References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> Message-ID: "Pierre-Fr?d?ric Caillaud" wrote in message news:opsdb950eb1v4ijd at musicbox... > > I'll vote for it. > Can we insert conditional expressions in the decorator list ? > > On 26 Aug 2004 15:00:05 +0300, Ville Vainio wrote: > > > I vote FOR on the J2 syntax. > > > Only in ternary operator format. :) From Andreas.Ames at tenovis.com Fri Aug 6 05:57:33 2004 From: Andreas.Ames at tenovis.com (Ames Andreas (MPA/DF)) Date: Fri, 6 Aug 2004 11:57:33 +0200 Subject: Decorator syntax Message-ID: <788E231C269961418F38D3E360D1652526CA1C@tndefr-ws00021.tenovis.corp.lan> Hi, thanks for your help. Terry Reedy wrote: > That particular syntax -- deco in parens and jammed up against was > never proposed. A similar syntax -- no parens and a space was. > Guide said a) he thought there would be parser issues and b) this > would cause problems with all support tools that assume that the > next name after def is the function name. I just found this style appropriate because it thus looks like a parameter to "def", which it, the decorator, somehow is, if I understand correctly. The same could be done to "class", but unfortunately not to (instance) variables(, because they have no keyword for declaration). I could even imagine class Test: def test1(self): self.i = "foo" and yes, I'm coming from a C/C++ background, if you haven't realized yet and, what's worse, I still like those :-). > Also, some of the major proponents want parameterized decorators and > multiple decorators, not just a different position for staticmethod > and classmethod. So I can't see a problem here. If I understand correctly, decorators are meant to be some sort of callables, so if you need parameters you can very easily use functors (just bear with my C++ heritage once again ;-) or however those classes with a __call__ method are called in python. That's exactly what I use functors regularly for. > For what its worth: 1) this issue and multiple alternatives has been > discussed since at least Jan 03. Since then, it has possibly taken > more devel time, and probably more Pydev postings than any single > other issue; 2) the PEP is broken and Guido knows it. We'll see if Then I can very well understand that almost everyone seems quite emotional about this thing. Sorry for beating a dead horse here, but I just wanted to insert my ? 0,02. cheers, andreas From insert at spam.here Fri Aug 20 16:09:54 2004 From: insert at spam.here (Doug Holton) Date: Fri, 20 Aug 2004 15:09:54 -0500 Subject: just ignore Guido's "rejections" [Re: Alternative decorator syntax decision] In-Reply-To: References: <2uadnbqpMuI1krvcRVn-sg@comcast.com> Message-ID: Anthony Baxter wrote: > On Fri, 20 Aug 2004 09:50:18 -0500, Doug Holton wrote: > >>We can safely ignore Guido's "rejections" when deciding upon an >>alternative to agree upon. Many people felt his rejections of C1 (a >>longtime community favorite), E1 and other alternatives were wrong. >>http://mail.python.org/pipermail/python-dev/2004-August/048134.html > > > Uh, what? No, you _can't_ ignore Guido's rejections - if you really decide > that you must have a form he's objected to, you need a _damn_ strong > argument to back that up. A "longtime community favorite" doesn't mean > a thing - this is language design, not American Idol - that a lot of people > like it makes no difference. Um, yes. The point is to determine what the *community* decides on, and *then* present that to Guido. You're just helpping confound this second vote even more. Some people aren't voting for what they think is best, but what they think Guido hasn't "rejected". That is ridiculous. You'll end up with a syntax that nobody really ever liked most, even Guido. From tim.hochberg at ieee.org Tue Aug 24 17:32:38 2004 From: tim.hochberg at ieee.org (Tim Hochberg) Date: Tue, 24 Aug 2004 14:32:38 -0700 Subject: J2 paper 0.2.1 In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022E55@exchange.hqamor.amorhq.net> References: <3A81C87DC164034AA4E2DDFE11D258E3022E55@exchange.hqamor.amorhq.net> Message-ID: Robert Brewer wrote: > First, thanks for the comments! > > Paul Moore wrote: > >>1. I differ on the "it doesn't matter what the keyword is" statement. >> On the contrary, my view could completely change depending on the >> keyword - I'd loathe "predef", whereas "using" is acceptable to me. >> Putting the proposal forward *without* an agreed keyword isn't >> (IMHO) fair to people who have this view. > > > I understand your emotion, now, but not your reasoning, and in the > absence of that, I can't generate a fix for the proposal. If you could > go into more detail *why* you would loathe predef, it would go a long > way toward allowing a stronger statement in the doc. I feel "using" has > positives, but I don't know what the negatives of "predef" are. Happy to > make it stronger if there's an argument in addition to passion. Without > a logical argument, such a position comes down to "it's ugly", which > Guido has specifically said he doesn't care about or want to hear. I agree with Paul that the choice of keyword *is* important. A misleading keyword is worse than cryptic punctuation. The keyword is lying, while the punctuation is merely silent. I also agree that predef reads poorly. I presume it's meant to imply something like preample or header, but I read it as predefine, which makes me think of some sort of evil forward declaration, not a decorator. It also just feels wrong to me, not that that carries much weight. Not that I'm wild about "using" either. It seems a legitimate gripe that 'def...using' reads slightly better than the proposed 'using..def' syntax, which is probably going to lead to some thinkos down the line. Still, even with those gripes "using" is marginally better than "@" Sadly I don't have any better ideas for a keyword. While I'm on the topic, let me point out some of the other keywords mentioned in the proposal that read poorly. "amend", "extend" and "qualify" all share a common flaw that in normal usage the thing being amended/extended/etc should follow the word. Thus the natural reading of: amend: foo def bar(): ... is somewhere between "huh?" and "clearly bar is used to amend foo." [CHOP] -tim P.S. I commend you on the proposal, it's quite good. From peter at engcorp.com Wed Aug 18 21:08:00 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 18 Aug 2004 21:08:00 -0400 Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: Aahz wrote: > In article <4123874C.8000304 at chamonix.reportlab.co.uk>, > Robin Becker wrote: > >>[...] > Not too many late-30s, I guess. I've been programming Python for six > years, started at nine years old with BASIC. Hi Aahz... I'll keep you company there. Started with APL, technically, but didn't have a clue what I was doing. Around eleven years old I think. Then BASIC etc. Python for about five years, but greatly saddened it wasn't for much longer (because of all the time wasted, especially on Java and C++). -Peter From anthonybaxter at gmail.com Tue Aug 17 09:28:49 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Tue, 17 Aug 2004 23:28:49 +1000 Subject: Decorators: an outsider's perspective In-Reply-To: References: <20040814153534.8AC171E4007@bag.python.org> Message-ID: On Mon, 16 Aug 2004 13:17:42 -0400, Paul Morrow wrote: > Q: What if I had a metaclass that would make any method private whose > name started with two underbars (by, I dunno, mangling the name > somehow)? Would you consider that a hack too? ;-) Damn straight - that's awful. Why on earth would someone implement that? Sorry, burned out on decorators for now. From python473 at yahoo.com Tue Aug 31 15:30:26 2004 From: python473 at yahoo.com (John Howard) Date: 31 Aug 2004 12:30:26 -0700 Subject: file access in jythonc References: <9eabe547.0408210611.d5e54f7@posting.google.com> <9eabe547.0408301406.2543e691@posting.google.com> Message-ID: <9eabe547.0408311130.73beef80@posting.google.com> "Diez B. Roggisch" wrote in message news:... > > I've looked up the references below and done several searches of > > filepermissions. It seems to me that for jythonc to have any use in > > development of "practical" products, programs have to be able to > > access local files easily. If not, then this, in my opinion, is going > > to be a MAJOR issue for jython!! I love the syntax and ease of > > programming in python, but if it cannot be used for useful programs, > > why bother?! BTW, how does java handle this? Is the same problem there > > also? > > Don't blame jython for things it hasn't to do with - as Alan said, java puts > restrictions on the things an applet can do. That restrictions can be > relaxed by signing the applet - go search google for stuff like java, > applet, signing, local, file, access. > > A common mistake for jython users is to think that there must be special > jython related documentation for their problems - but usually its not, for > the simple reason that there are tons of docs on java out there. Jython > docs only cover the differences. So go look for java solutions to your > problems, and then feel the joy of using java-classes with a language > without checked exceptions and what not that makes coding in java so ... > verbose. So...are you saying it can be done? That is, a IE can access a local file (assuming it's there, of course) using a jythonc product? Question is -- HOW??? From Scott.Daniels at Acm.Org Sun Aug 8 00:55:08 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 07 Aug 2004 21:55:08 -0700 Subject: @decorator syntax is sugar, but for what exactly? In-Reply-To: References: Message-ID: <4115b53a$1@nntp0.pdx.net> Robert wrote: > I have read a few Python blogs and not a one is taking the decorator syntax > in a good way. classmethod and staticmethod were introduced some time ago, to provide a mechanism for getting to such effects. At the time there was no clear syntax to use that "felt right." In the meantime people have used these features to good effect despite the clunky way you used them. At this point there would probably be a small riot (or at least a large whine) if these two were removed. When I first came to Python, I was delighted to see that Idle gave me function clues not only for the system code, but for the code _I_ wrote. Since it takes discipline to write comments that may never be read, it was delightful to finally see an immediate reward for doing a little documentation work -- I could help myself on my own utility functions. However, there are more and more uses of the docstring for things other than documentation. At this point, I see more and more docstring uses as "cybercrud" -- The only easy function annotation is the docstring so all ambitious program annotation schemes use it. There are good reasons for wanting to be able to annotate functions and methods, but precious few good reasons for polluting the document strings in order to do so. Decorators are a way out. I don't know about the syntax, it looked bad when I first saw it, but like some others, I welcome _almost_any_syntax_ for decorators. Not, so much, because I want to use decorators. I just want others to stop using docstrings for non-documentation purposes. In fact, I don't even really like the unittest convention of using method names to identify test methods -- I prefer a language where the what you call a thing does not affect how it works. > The Python of 1.5.2 simplicity will be long gone. Well, there was a lot to like even then, but I'd hate to give up what we now have -- you can do things in a much more functional style now, with nested scopes. Would you really like to go back to three-strikes and you are out symbol lookup? This language has changed at a good pace, and (quite surprisingly) slowly to a more consistent model (a major coup in language design). The aesthetic that has driven that change suggests that this might be the right syntax for declarators. I know I wouldn't have done nearly as well as Guido and gang at making language decisions. I certainly intend to take this alpha period as a time to experiment with decorators and see if the syntax grows on me; I suggest others do the same. Give it its best chance; you may become a fan. Several of the py-dev people claim they have already gone from distaste to support. -- -Scott David Daniels Scott.Daniels at Acm.Org From pm_mon at yahoo.com Thu Aug 26 11:09:28 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Thu, 26 Aug 2004 11:09:28 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Anthony Baxter wrote: > On Thu, 26 Aug 2004 14:40:18 GMT, Arthur wrote: > >>>IMO, to change it inside of a function def should be (but isn't) as easy >>>as... >>> >>> >>> def foo(): >>> ... """ I am foo """ >>> ... __doc__ = __doc__ + 'indeed' >>> >>>Paul >> >>Yes. Not only do I follow, but I think we came to exactly the same >>place, from very different directions, and coming from what I sense is >>very different backgrounds. >> >>Its just that I don't think many others seem to find that as >>interesting as I happen to. > > > Not so much that, as running out of ways to restate myself. The > proposed syntax above still requires magic handling of double-under > variables in a function, and a new namespace. I can't see how you can > think that this is a _good_ thing. The function does *not* get a new namespace! Let me stress this point a little further. We would simply be moving __xxx__ variables *out of* the function's local variable namespace to where they belong, the namespace of the function itself --- /the same namespace that __doc__ lives in./ As such, the function *body* would have no more access to __doc__ than it does now. Consider the following def foo(): """ foo's docstring """ __author__ = 'Paul Morrow' __version__ = '0.1' __features__ = memoized, synchronized # Above this line is the function's declaration section. # Below this line is where the function's body starts. var1 = 10 print __doc__ # error! __doc__ is not in local namespace print var1 # ok. Paul From rnd at onego.ru Fri Aug 20 04:34:41 2004 From: rnd at onego.ru (Roman Suzi) Date: Fri, 20 Aug 2004 12:34:41 +0400 (MSD) Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: My vote: C4 A1 J2 (Though, J2 with different keyword, not "decorate") Sincerely yours, Roman A.Suzi -- - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru - From grante at visi.com Fri Aug 13 10:23:45 2004 From: grante at visi.com (Grant Edwards) Date: 13 Aug 2004 14:23:45 GMT Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: <411ccef1$0$65606$a1866201@newsreader.visi.com> On 2004-08-13, beliavsky at aol.com wrote: > One of the most commmon reasons programmers cite for not > trying Python is that indentation determines the program flow > -- they think its weird. True. I thought it was weird when I read about it. I'm not so closed-minded that it prevented me from trying the language. > I think programmers who actually try Python adapt quickly and > do not find the indentation rules to be a problem. > > I wonder if there is a way to remove this initial barrier. Could an > alternate source form be defined, Please no!!! If you want a different language _use_ a different language. Don't mangle Python into something else. > so that there are matching if-endif and for-next constructs > instead of significant indentation? The alternate source form > and the current form would result in exactly the same .pyc > file. Sounds horrible. > I'm not saying that Python's use of indentation is bad, just > that it stops many programmers from trying it. Oh well. -- Grant Edwards grante Yow! We have DIFFERENT at amounts of HAIR -- visi.com From ptmcg at austin.rr._bogus_.com Fri Aug 27 22:07:43 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Sat, 28 Aug 2004 02:07:43 GMT Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> Message-ID: "Kjetil Torgrim Homme" wrote in message news:mailman.2551.1093656430.5135.python-list at python.org... > I'll write a PEP, but it will have to wait until next week. thank you > for your feedback! > Kjetil - I hate to see you waste the effort. If you look back through the archives, you'll see that some form of "let's add braces to Python" proposal comes up from the newcomer ranks every couple of months. Almost always, the proposal is combined with some comments about "my editor can't handle indenting and outdenting properly." Before you invest the time putting your case together, I strongly suggest you review the comments and responses that have already been put forth on this issue. And be sure that the Python community does not need to be educated about what "real world" code looks like. Please consider the possibility that bracelessness is one of the language features you need to come to grips with as part of "embracing" a new language. It will be great to see your energy and enthusiasm put forth to learning about and participating in discussions of new Python language features, instead of rehashing old news. -- Paul From news at grauer-online.de Tue Aug 31 07:44:42 2004 From: news at grauer-online.de (Uwe Grauer) Date: Tue, 31 Aug 2004 13:44:42 +0200 Subject: Boa Constructor error In-Reply-To: <875af5e2.0408271135.7a19a30f@posting.google.com> References: <4712d252.0408260804.c69cfee@posting.google.com> <875af5e2.0408271135.7a19a30f@posting.google.com> Message-ID: ake wrote: > Uwe Grauer wrote in message news:... > >>Parano wrote: >> >>>Hi >>> >>>I have a recurrent error in Boa Constructor, especially when I try to >>>activate code completion: a message box reads "UnicodeDecodeError: 'ascii' >>>codec can't decode byte 0xaa in position 52: ordinal not in range(128)" >>>I couldn't find any google resource on that error. >>> >>>I have Python 2.3.3 with Boa Construtor 0.3.1 on Mandrake Linux 10. >>>wxPython is from wxPythonGTK-py2.3-2.5.2.7-RH9.i386.rpm >>>I also tried wxPythonGTK2-py2.3-2.5.2.7-RH9.i386.rpm but had the same error. >>>Those RPMs are from www.wxpython.org where it says that "install and use on >>>my Mandrake 9.2 system without any troubles." >>> >>>Any tip on this? Thanks in advance >> >>Boa isn't ready for wxPython 2.5.x >>Use wxPython 2.4.2.4 instead. >> >>Uwe > > > Anyone know what's happening to Boa, there doesn't seem to have been a > new version for over a year. > > ?ke Not true, Boa 0.3 came just out. Boa 0.3.1 is in CVS now. Uwe From ptmcg at austin.rr._bogus_.com Wed Aug 18 11:15:51 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Wed, 18 Aug 2004 15:15:51 GMT Subject: age of Python programmers References: Message-ID: 45. The gory details can be found at http://c2.com/cgi/wiki/wiki?PaulMcGuire -- Paul From zathras at thwackety.com Fri Aug 20 14:37:11 2004 From: zathras at thwackety.com (Michael Sparks) Date: Fri, 20 Aug 2004 19:37:11 +0100 (BST) Subject: Alternative decorator syntax decision In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022E14@exchange.hqamor.amorhq.net> Message-ID: On Fri, 20 Aug 2004, Robert Brewer wrote: > Top-posting-to-help-quick-scanning: J2 J2 J2. > > To Paul, M. Sparks, et al: Since J2 is coming up frequently (and Guido > did not immediately reject it when asked), I'm going to follow through > and try to write a proposal this weekend for J2. I'll post it here for > feedback (and of course, wait for the 'final' count of votes) before > posting it on py-dev. That's very much appreciated - thank you. Aside from what keyword (which is more sugar than anything else), the question of ordering of semantics springs to mind. The current implementation is little more than syntactic sugar over the current decorator code. This means that the following three examples have the same meaning: @generator @staticmethod def tokenise(stream): for t in stream: Yield(t) decorate: generator staticmethod def tokenise(stream): for t in stream: Yield(t) def tokenise(stream): for t in stream: Yield(t) tokenise=generator(staticmethod(tokenise)) Unless it's been done to death for the more verbose option, it MIGHT be worth asking the question as to whether it might be more appropriate to have the following 3 meaning the same thing: @generator @staticmethod def tokenise(stream): for t in stream: Yield(t) decorate: staticmethod generator def tokenise(stream): for t in stream: Yield(t) def tokenise(stream): for t in stream: Yield(t) tokenise=generator(staticmethod(tokenise)) I say might for 2 reasons 1) looking at recent posts it looks like the current order has had a lot of thought going into it 2) recent discussion suggests this isn't trivial to get 100% right! I'll leave the decision as to whether to include that up to you. Once again thanks - I'll look at sorting out the (hopefully) minor scoping issue with the current implementation. Best Regards, Michael. From chrisdewinN0SPAM at yahoo.com.au Sun Aug 15 01:56:21 2004 From: chrisdewinN0SPAM at yahoo.com.au (Dfenestr8) Date: Sun, 15 Aug 2004 14:56:21 +0900 Subject: Is python ircbot.py slow? Message-ID: Hi. As a personal project, I'm scripting my own irc bots for my own chans on irc. It seems to me more fun than working out how to use an eggdrop. I'm using ircbot.py library, from the python-irclib package, by Joel Rosdahl. But, I was talking to a friend of mine who has experience with bots, and he says that python is way toooo slooow. I haven't really looked into how they bench mark these things, but as far as I know, python has always been considered a reasonably fast scripting language. Even back when the standarad server was a p450 it was considered fast enough. Now that most servers are 1.2Ghz +, surely speed isn't even an issue? From robin at SPAMREMOVEjessikat.fsnet.co.uk Thu Aug 19 20:37:07 2004 From: robin at SPAMREMOVEjessikat.fsnet.co.uk (Robin Becker) Date: Fri, 20 Aug 2004 01:37:07 +0100 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: <412547B3.4020801@jessikat.fsnet.co.uk> Paul McGuire wrote: > There are a number of messages on the python-dev mail list that indicate > that Guido is looking for some concensus to come from this list as to what > *one* alternative syntax for decorators we would like him to consider in > place of the @ syntax that is currently in 2.4a2. .... Is there any discussion about which versions are currently legal python in Python-2.x x<4? I deal with lot's of cross version maintainance issues and the very worst are where the syntax makes it illegal even to compile the files. I believe that B is legal and has implementations for earlier pythons available, but are others? -- Robin Becker From frithiof.jensen at die_spammer_die.ericsson.com Thu Aug 5 03:58:28 2004 From: frithiof.jensen at die_spammer_die.ericsson.com (Frithiof Andreas Jensen) Date: Thu, 5 Aug 2004 09:58:28 +0200 Subject: DB beginner help References: Message-ID: "Zeljko Vrba" wrote in message news:slrnch3ms4.7mn.mordor at fly.srk.fer.hr... > In Perl I always use question marks and have no trouble switching the > application between different databases. How do you guys do it in Python > (of course, without rewriting all queries?) Do your database work from a "connection" object and use a database-specific function to create that object. Most of the time that will work with several SQL databases. I use a class wrapper for the specific database that is given a connection object when the class is initialised. The wrapper hides the lameness of SQL in some obvious situations - f.ex calculating a running balance like a bank statement is easiest done by the application, but procedures will work also. I also think that a dicts are a good way to "paste" information into SQL query strings It goes sort of like: # open the stock database and insert the information. try: cursor = self.conn.cursor() cursor.execute( """ INSERT INTO stocks (ticker, exchange, stockName, stockDescription) VALUES ('%(Ticker)s', '%(Exchange)s', '%(stockName)s, '%(stockDescription)s) """ % colkey) except: log.error( """ Failed to create new Entry for %(Ticker)s, on %(Exchange)s' """ % colkey, exc_info=True) raise else: # account opened. self.commit(True) log.info('Entry Created for %(Ticker)s, on %(Exchange)s' % colkey) # done return None ..... Funny how every amateur programmer seem to dabble in stocks :-) The "connection" is the standardised way of representing a database as an object in Python. *How* to get the connection is database-dependent. You might also be bitten by the various interpretations of SQL in the underlying databases; Time/Date fields are always dubious, some databases only work with few data types, even Strings Only(!), and some corners of SQL like CHECK constraints (PySQLite) and even FOREIGN KEY constraints (Seen it on something, I discarded for that reason - GadFly?) may not be enforced! From rnichol_rrc at yahoo.com Fri Aug 20 18:31:48 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Fri, 20 Aug 2004 17:31:48 -0500 Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: Mark Jackson wrote: > Reid Nichol writes: > >>Gerrit Muller wrote: > > >>>and then a quantum leap towards Python. >> >>You're aware that a quantum leap means a extremely small leap, right? > > > Everything's relative - compared to the smallest possible change in the > classical continuum, a quantum leap is *huge*. > True, but this doesn't change the definition of the word. from dictionary.reference.com: The smallest amount of a physical quantity that can exist independently, especially a discrete quantity of electromagnetic radiation. From cookedm+news at physics.mcmaster.ca Sun Aug 22 17:20:32 2004 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Sun, 22 Aug 2004 17:20:32 -0400 Subject: 100 % portable ? References: Message-ID: At some point, Grant Edwards wrote: > On 2004-08-22, David M. Cooke wrote: > >> For Mac the preferred place files is ~/Documents, and for config files >> is in ~/Library//. > > Where to per-user config files go? ~ == $HOME, so that's per-user. -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From nospam at nowhere.hu Sun Aug 8 05:30:07 2004 From: nospam at nowhere.hu (Miklós) Date: Sun, 8 Aug 2004 11:30:07 +0200 Subject: Going the PL/1 way References: Message-ID: "Dominic" wrote in message news:cf4ms8$30v$1 at news.uni-kl.de... > > > Yes, I'm thorougly annoyed with creeping featurism. > Well, you need not use them in your own code. > Define and enforce a subset like it is common in ADA. I've got a faint idea that this "subset" approach greatly contributes to the unpopularity of Ada. Once a core feature is in place, you just cannot insulate yourself from that. > Some postings about @decorators remind me of that > old farmer who only eats stuff he knows already. And perhaps he might stay healthy longer than that young one who eats each and every new nutriment and colourful shiny berries. Cheers, Mikl?s > > > Ciao, > Dominic From tmj at jarmania.com Wed Aug 18 14:20:02 2004 From: tmj at jarmania.com (Tim Jarman) Date: Wed, 18 Aug 2004 19:20:02 +0100 Subject: age of Python programmers In-Reply-To: References: Message-ID: <38F3D6D2-F143-11D8-A699-000D9366BF6A@jarmania.com> 42 (well, you knew that would be answer, didn't you? ;) Tim J From reinhold-birkenfeld-nospam at wolke7.net Fri Aug 20 16:37:32 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Fri, 20 Aug 2004 22:37:32 +0200 Subject: Fate of lambda, Functional Programming in Python... In-Reply-To: References: <20040820163629.8DD4F1E401A@bag.python.org> Message-ID: <2on5kpFcjmvdU2@uni-berlin.de> Chas Emerick wrote: > In a comment off a post on lambda-the-ultimate, I noticed this little > offhand remark: > > '''IIRC GvR is going to kill the various lambda, map,filter & reduce > leaving just generator expressions/list comprehension.''' NO!!!!111eins Don't you think of the whole Python obfuscation lot? Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From b.niemann at betternet.de Tue Aug 10 04:23:03 2004 From: b.niemann at betternet.de (Benjamin Niemann) Date: Tue, 10 Aug 2004 10:23:03 +0200 Subject: session management In-Reply-To: References: Message-ID: A.M. Kuchling wrote: > On Sun, 08 Aug 2004 14:02:14 +1000, > Ajay Brar wrote: > >>question is what happens when the client does not log out? what if he >>simply leaves the website? i can put a timer on the cookie, but how do i >>cleanup the temp files. > > > You'd need to run a cron job that periodically cleans up sessions that > haven't been touched in the last 8 or 24 or whatever hours. He says, he has not direct access to the webserver - this will most likely ruleout cronjobs. Instead check with every Nth request for expired session files, just like PHP does: http://www.php.net/manual/en/ref.session.php c ya From xah at xahlee.org Wed Aug 25 17:56:06 2004 From: xah at xahlee.org (Xah Lee) Date: 25 Aug 2004 14:56:06 -0700 Subject: Larry Wall & Cults Message-ID: <7fe97cc4.0408251356.34f2102a@posting.google.com> Larry Wall and Cults (Lazyness, Impatience and Hubris) 200012 Dear readers, Did you know that throughout history there's this thing called cult? It is a very interesting phenomenon. I don't have time to expound and teach, but will try to brief you. These cults, are often lead by a single person. They form a group as small as a dozen to multinational octopuses (such as Scientology). Their creed varies from the mild in appearance (Dianetics) to appalling (flat earth, extraordinary life-after-death, impinging apocalypse scenarios, militant anti-government conspiracy, diabolism with human sacrifices ...). Don't think that i'm citing from some arcane books buried in libraries. These are real, and not difficult to find in real life. Some of these cult leaders, are so able to totally wash their member's brain, as to have them autonomously swear and volunteer to die for the cause of the cult. Occasionally, you'll even see mass suicide. You know, the world is not made completely of rubes. Somebody somewhere, will observe this phenomenon and study or report it as is. Big brother organizations, such as the FBI, is keen on these and very interested in benefiting from social psychology themselves. They are recorded in books too. Ever wonder why the library houses so many cold volumes of paper? This is one contributing reason. You might be interested to verify that sometimes. These brain-washing phenomenon, are not limited to fanatical life-and-death or otherwise dire beliefs. You see it work in all manners of human thought in the general sense. From culture formation to fashion to commercialism. Surely you have heard of Adolf Hitler and his atrocities of genocide? I must alert you, that a single person couldn't commit such a crime. You see, even if you are superman, you can only kill few at a time. You see, it is the people, people like you and me, who commit the killings willingly, by Hitler's teaching. You may say: "no, i won't ever do such stupid thing", well because you are very ignorant about social psychology. It is precisely innocent people like you and (not) me, who were lead by the radical leaders of supreme brain-washing abilities. The innocent mob were fervent in their leader's vision and beliefs to commit anything. You know the concept of war, right? We have two massive body of people committed to cut off other people's head or otherwise stick a knife in their bodies or bomb off an arm or leg. How did that happen? Well, it starts with patriotism for people like you and (not) me. Now, back to topic. In the computing world, there're also bad seeds with colorful creed taking innocent mobs forming cults. The three principal virtues of a programmer are Laziness, Impatience, and Hubris. Yes? How can we prevent heinous cults then? Stop bending truths. Education and rationalism. I'm starting my own cult to exterminate morons on this earth. Two things are on the top of my agenda: Unixism and Perl. -------- This post is archived at http://xahlee.org/UnixResource_dir/writ/larry_wall_n_cults.html Copyright 2000-2004 Xah Lee. Verbatim Reproduction for non-commercial purposes is hereby granted provided proper credit is given. Xah xah at xahlee.org http://xahlee.org/PageTwo_dir/more.html From webraviteja at yahoo.com Wed Aug 25 21:06:50 2004 From: webraviteja at yahoo.com (Ravi Teja Bhupatiraju) Date: 25 Aug 2004 18:06:50 -0700 Subject: Python Image Manipulation References: Message-ID: "Scott Brady Drummonds" wrote in message news:... > Can anyone recommend the easiest way of generating thumbnail images using a > Python library? I've seen that the Python Image Library (PIL) seems to do > this but it isn't installed on my available systems. I'd prefer to use > something distributed with Python, if possible, but will install the library > that makes this functionality easy as a second choice. > > Thanks! > Scott The easiest way is using PIL. There is sample code in the PIL documentation that you can use directly. From mogmios at mlug.missouri.edu Tue Aug 17 19:29:36 2004 From: mogmios at mlug.missouri.edu (Michael) Date: Tue, 17 Aug 2004 16:29:36 -0700 Subject: favorite python web development tool? In-Reply-To: References: <10i4nttktcvltdd@corp.supernews.com> Message-ID: <412294E0.2020007@mlug.missouri.edu> >> i'm fairly new to python, coming from a java servlet / velocity >> template background. i'm looking for a good python web development >> tool, and hope to find some suggestions here. > > > I've found mod_python + ZopePageTemplates (standalone) to be superb > solution to web application development. ZPT feels like a very natural > and maintainable way to separate business logic from presentation. Since > I've started using these two technologies, I've found my productivity > greatly increased. I like using mod_python and XML-RPC. Develop the logic as a backend and then use a frontend to talk to that backend and to do whatever input/output processing needs to be done to make it all into a web app. I like that the frontend can actually be written in other languages as the situation requires and that in fact it doesn't even need to be a web app at all. I've written MPXMLRPC backends with PHP web-based frontends and wxPython frontends both. Pretty sweet. -- Michael http://kavlon.org From jim_8421 at hotmail.com Sun Aug 1 18:23:16 2004 From: jim_8421 at hotmail.com (Jim) Date: 1 Aug 2004 15:23:16 -0700 Subject: popen4 poll problems Message-ID: Hi, I noticed with popen2.Popen4 class, sometimes the poll() method will keep returning -1 although the command has finished. However, when a read is done ( ex. p4instance.fromchild.read() ) and then a poll is done, poll() will return the process exit value. Why does this happen? perhaps I have to do some type of flush before doing poll? Thanks in advance Cheers, Jim From martin at v.loewis.de Thu Aug 5 17:49:07 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 05 Aug 2004 23:49:07 +0200 Subject: PEP 263 status check In-Reply-To: <10h58umglolefb8@news.supernews.com> References: <10h58umglolefb8@news.supernews.com> Message-ID: <4112AB53.6010701@v.loewis.de> John Roth wrote: > PEP 263 is marked finished in the PEP index, however > I haven't seen the specified Phase 2 in the list of changes > for 2.4 which is when I expected it. > > Did phase 2 get cancelled, or is it just not in the > changes document? Neither, nor. Although this hasn't been discussed widely, I personally believe it is too early yet to make lack of encoding declarations a syntax error. I'd like to reconsider the issue with Python 2.5. OTOH, not many people have commented either way: would you be outraged if a script that has given you a warning about missing encoding declarations for some time fails with a strict SyntaxError in 2.4? Has everybody already corrected their scripts? Regards, Martin From h.b.furuseth at usit.uio.no Sun Aug 8 06:08:25 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 08 Aug 2004 12:08:25 +0200 Subject: elements of decorator syntax suggestions References: <4edc17eb.0408062125.231f7bef@posting.google.com> <41155C33.37EEB397@alcyone.com> <4edc17eb.0408072041.7bfe9eff@posting.google.com> <4115CDA8.1A8AD51D@alcyone.com> Message-ID: Anthony Baxter wrote: >> @ sure takes up more visual space and is easier to spot in text than |, >> which is precisely why I used it in EmPy as the token prefix (also >> because @ at the time is neither commonly used in English text or legal >> in Python, though the latter will be changing). > > The far-more-obvious-in-code is my reason for preferring @ over |. In that respect I think '=' would be pretty good too. And possibly '!'. However, if (long-expression | more-expresson): |decorator-function(blah blah) def foo(): pass Could do the same with != and '==', but at least that's different from '!' and '='. One could write if bar(long_variable_name =value): =decorator-function(blah blah) def foo(): pass though that seems a bit contrived. -- Hallvard From eric_brunel at despammed.com Mon Aug 23 08:59:44 2004 From: eric_brunel at despammed.com (Eric Brunel) Date: Mon, 23 Aug 2004 14:59:44 +0200 Subject: comment utiliser python sous Fedora References: <8e16829.0408230412.cf13db4@posting.google.com> Message-ID: Roland wrote: > Salut , > > Je suis un debutant pour linux. Et j'ai actuellement RedHat > Fedora Core1 . Je voudrais developper une application (ie un logiciel > de gestion de Bibliotheque ) avec python mais j'ai des problemes: > > > - Premierement je n'ai aucune documentation sur l'usage de python sou > Fedora. Pourriez vous m'indiquer un endroit ou je peux t?l?charger un > cours ? ce sujet? > - Deuxiemement , mon python tourne sur le compilateur GCC et je sais > pas comment faire des interfaces graphiques tout comme on le fat avec > Tkinter dans certains cas. > Aidez moi s'il vous plait. > merci. Bonjour, Tout d'abord, il existe un newsgroup Python en fran?ais (fr.comp.lang.python) sur lequel il est pr?f?rable de poser les questions en fran?ais, le newsgroup comp.lang.python ?tant traditionnellement anglophone. Quant ? tes questions, je ne suis pas sur de les comprendre: Python est-il install? sur ta machine? Il n'y a pas de documentation sur "l'usage de python sous Fedora", simplement parce qu'il n'y a rien de sp?cifique sous cette plateforme: PAQJS, elle s'utilise comme n'importe quel Linux. Les seules instructions n?cessaires se trouvent dans le fichier README dans le r?pertoire racine de l'installation Python. Pour la deuxi?me question, je comprends encore moins: quel est le rapport entre le compilateur gcc et Tkinter? Python sous Linux est a priori toujours compil? avec gcc, et ?a n'empeche personne de faire du Tkinter. Quel est le probl?me exactement? -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From tjreedy at udel.edu Sun Aug 8 19:15:54 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 8 Aug 2004 19:15:54 -0400 Subject: elements of decorator syntax suggestions References: <4edc17eb.0408062125.231f7bef@posting.google.com><41155C33.37EEB397@alcyone.com><4edc17eb.0408072041.7bfe9eff@posting.google.com><4115CDA8.1A8AD51D@alcyone.com> Message-ID: "Anthony Baxter" wrote in message news:e69d3ed2040808012076f74273 at mail.gmail.com... > The other point that's been raised is that | looks similar to l and I > in a bunch of fonts, and I is a common prefix (for interfaces). With a mandatory space after the |, it should be much harder to see it as anything else, since anything else would be a syntax error. Both 1 deco and I deco are nonesense, so | deco should be visually interpreted as such. Terry J. Reedy From exarkun at divmod.com Wed Aug 11 01:37:44 2004 From: exarkun at divmod.com (Jp Calderone) Date: Wed, 11 Aug 2004 01:37:44 -0400 Subject: Static method object not callable In-Reply-To: References: Message-ID: <4119B0A8.6070900@divmod.com> Edward Diener wrote: > This simple code example gives me the message, "TypeError: 'staticmethod' > object is not callable". > > [snip] > > I know there must be a way to have a class attribute reference a static > method, and then call that static method through the reference, so if anyone > can correct this it would be appreciated. > class X(object): def Y(x): print x Y = staticmethod(Y) def Z(self): self.ad[1](3) X.ad = {1: X.Y} Jp From http Thu Aug 12 04:19:56 2004 From: http (Paul Rubin) Date: 12 Aug 2004 01:19:56 -0700 Subject: Arranging a dependency tree References: <6ccff37a.0408111831.6eb25a4e@posting.google.com> Message-ID: <7xr7qcepjn.fsf@ruckus.brouhaha.com> kyleroot at gmail.com (Kyle Root) writes: > I've created a jumble of python modules, in each one is a tuple that > goes something like, > > deps = ("file10","file7","file3"). > > And some have no dependencies at all. I have one file called "start", > and the whole thing makes a tree of dependencies as each file has deps > and their deps might have deps, and so on. What I'm trying to do is > "straighten" them or put them in order as if they were to be > installed. Basically I'm trying to replicate the way portage does it. :) Suppose that deps list is for file5. I'm reading your example to mean file5 depends on file10, file7, and file3, and not the other way around. As others have mentioned, what you want to do is called topological sorting. Since nobody's described the algorithm, it goes something like this: 1) Make a dictionary indexed by filename, whose entry deps[f] will be the set of files f depends on. In the above example, deps["file5"] = Set(["file10", "file7", "file3"]). You can also use a dict instead of a Set in the obvious way. 1) Make another dictionary indexed by filename, whose entry d[f] for filename f will be a list of the files that depend on f. For example, if the deps for file5 are ("file10","file7","file3"), then you'll put "file5" into d["file10"], d["file7"], and d["file3"]. You can straightforwardly build this dict when you scan the deps lists. 2) Also when you scan the deps lists, make a list U of all the files that don't depend on anything. 3. while U is not empty, do the following: choose an f from U output f remove f from U for g in d[f]: # for each file depending on f remove f from deps[g] if deps[g] is now empty, add g to U If there are no circular dependencies and if I haven't goofed up (it's late here), then the above scheme should output all the filenames in topologically sorted order, in running time linear in the # of filenames plus the # of dependencies. You can probably find a clearer explanation in any intro CS text with a chapter about graph algorithms. From jaydonnell at yahoo.com Tue Aug 17 19:08:42 2004 From: jaydonnell at yahoo.com (Jay Donnell) Date: 17 Aug 2004 16:08:42 -0700 Subject: can tarfile maintain directory structure? Message-ID: Is there a way to use the tarfile module to recursively compress the contents of a directory and maintain the directory structure in the tar archive? Simply doing os.system('tar -czvf ' + fileName +'.tar.gz ' + directory) works great on linux, but I need this script to work on windows as well :( From miko at nono.nevernever.net Sat Aug 21 11:21:54 2004 From: miko at nono.nevernever.net (Miko) Date: Sat, 21 Aug 2004 15:21:54 -0000 Subject: discover redirected url Message-ID: <10ieq4dscjutmb7@corp.supernews.com> how does one determine a redirected url? for example: http://tinyurl.com/3apbd is redirected to: http://www.cbsnews.com/stories/2004/03/18/sunday/main607191.shtml using httplib, i get a HTTPResponse object, but there is nothing in there that shows the redirection, including the msg member. is there a way to determine a redirected url using the standard Python libraries? From 510046470588-0001 at t-online.de Fri Aug 20 10:46:34 2004 From: 510046470588-0001 at t-online.de (510046470588-0001 at t-online.de) Date: 20 Aug 2004 16:46:34 +0200 Subject: My only complaint about Python References: Message-ID: <87acwpq33p.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Kolja Kube writes: > It is free, but only free as in "free beer". no , it's not free. free beer is a misnamer. it must be 'gratis', as already known by Stallman. Klaus Schilling From peter at engcorp.com Fri Aug 13 14:49:09 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 13 Aug 2004 14:49:09 -0400 Subject: Pyhton Interpreter Startup time In-Reply-To: References: <30260531.0408120829.27a536bc@posting.google.com> Message-ID: David Bolen wrote: > Peter Hansen writes: >>I think it's >>safe to assume that anyone with a slow startup on Windows >>has a misconfiguration or is doing something wrong. > > I don't think that's a safe assumption. For example, on a PIII-550 > box running NT that I use, the first time I start up Python after a > prolonged absence (typically through a night when a virus scan is run) > it can take several seconds to start. [...snip description of how it affects everything else too] > I also don't think there's much room for Python to be at fault at > least in my case - e.g., if anything it's system behavior and not > really local operations Python is performing. > > But I don't think it automatically implies that my Windows system is > misconfigured or that I'm doing something wrong. You're quite right. I should have added the qualification that if *other* software starts snappily, but Python does not, then it is safe to assume it's a misconfiguration or someone doing something wrong, whereas if all software starts slowly on that machine then it may just be a sucky machine. One assumes that those who are posting about Python starting very slowly and needing faster startup time are not just complaining indirectly about having slow machines in general. -Peter From squirrel at WPI.EDU Thu Aug 5 13:52:05 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 5 Aug 2004 13:52:05 -0400 Subject: RELEASED Python 2.4, alpha 2 In-Reply-To: References: <411231C8.3020308@interlink.com.au> Message-ID: On Thu, 5 Aug 2004, Christopher T King wrote: > On Thu, 5 Aug 2004, Heiko Wundram wrote: > > > Now tell me that using decorators to do synchronization isn't a lot easier to > > read than the first (old) example is, and also less error-prone (resp. > > acquiring/releasing locks properly and without deadlocks). > > I'll admit synchronization is a strong use case (since I don't believe it > justifies language support, like it has in Java), but I just think there's > a better way to go about things that no-one's thought of yet. Replying to myself here... Why would one necessarily use method synchronization in Python, since any well-designed Python function should be re-entrant (though I'm sure there is the rare exception)? It would seem that data access synchronization is all that's needed for most threaded applications, and the only way to apply that is through the try/finally construct, since Python does not (yet?) provide built-in data synchronization. Of course, sometimes all a function does is access a synchronized piece of data (especially in the case of accessor functions used to simulate synchronized data access), in which case method synchronization is equivalent to the synchronization of that piece of data, and decorators can be applied to the method as a whole. From peter.maas at mplusr.de Thu Aug 19 13:06:09 2004 From: peter.maas at mplusr.de (Peter Maas) Date: Thu, 19 Aug 2004 19:06:09 +0200 Subject: My only complaint about Python In-Reply-To: References: Message-ID: Istvan Albert schrieb: > In all fairness this is more the problem with Microsoft than > python. If they had a free fully-featured compiler then Python > would be compiled with that. Isn't the free Borland 5.5 compiler full featured? -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- From cemerick at snowtide.com Wed Aug 18 10:33:17 2004 From: cemerick at snowtide.com (Chas Emerick) Date: Wed, 18 Aug 2004 10:33:17 -0400 Subject: PEP 318: Can't we all just get along? In-Reply-To: <20040818130058.808391E400B@bag.python.org> References: <20040818130058.808391E400B@bag.python.org> Message-ID: <8BD53FBE-F123-11D8-9F63-000A95B336F2@snowtide.com> [...a lot of discussion about YA decorator syntax...] I have no particular qualms about the syntax proposed by the OP: def (callable)* blah (args): pass However, I do remember GvR mentioning on python-dev that he did not prefer such a syntax because it would break existing tools that currently rigidly expect a regular [def blah (args)] function definition. I did want to note that, aside from Paul's constant hope for implicitly typed functions based on their arguments (which we've already hashed to fine little bits :-), all this decorator debate is about some very minute syntax differences. I suppose if that view makes me insensitive to others' syntactic hangups, so be it... :-) - Chas Emerick From paul at prescod.net Tue Aug 17 06:13:00 2004 From: paul at prescod.net (Paul Prescod) Date: Tue, 17 Aug 2004 03:13:00 -0700 Subject: 'ascii' codec can't encode character u'\xf3' In-Reply-To: <20040817082127.GA5233@barbucha.martin.net> References: <4120F820.4000703@fusiondementes.com> <4121A8DA.30802@v.loewis.de> <20040817082127.GA5233@barbucha.martin.net> Message-ID: <4121DA2C.2080706@prescod.net> Martin Slouf wrote: > thank you for reply, great info! it helped me to better understand it; > but of course, some additional questions have risen. > > maybe some of those question/comments may seem stupid (ie. clear), but > im new to python and i want to assure myself i get it right; thx for > patience. > > >>There is an alternative, if the print is a debug print: >> >>- print a repr() of the unicode object instead of >> the unicode object itself. This will work on all >> terminals, and show hex escapes of non-ASCII characters. > > > just to make sure: > > override the object's __repr__(self) method to st. like: No, he means instead of: print foo print repr(foo) Paul Prescod From hans at zephyrfalcon.org Thu Aug 19 21:12:25 2004 From: hans at zephyrfalcon.org (Hans Nowak) Date: Thu, 19 Aug 2004 21:12:25 -0400 Subject: Mixing classes... In-Reply-To: References: Message-ID: <41254FF9.9040001@zephyrfalcon.org> Ivan Voras wrote: > Is this possible: > > class C1: > def somemethods(self): > """methods do stuff, create member variables""" > pass > > def f1(): > """function returns instances of C1, somewhat manipulated into > specific states""" > return C1() > > > class C2(C1): # C2 derives from C1 > def othermethods(self): > """new methods are introduced, but no new member variables (they > work on existing ones)""" > pass > > > > # So far, everything's ok. Now, i want to create instance of > # C1 using f1: > > c = f1() # could be equal to "c=C1()", but not always... > > # ... and somehow "add" or "overlay" the additional methods > # declared in C2 on the object "c". I tried this: > > c.othermethods=C2.othermethods > > c.othermethods() # fails here, is confused about what is 'self' > > > ####### > While this is probably considered "strange", and it's certainly not good > design style, I somehow feel it could be possible to do in python. Any > clues? Use new.instancemethod: >>> class C1: ... def somemethods(self): ... print 'somemethods' ... >>> def f1(): ... return C1() ... >>> class C2(C1): ... def othermethods(self): ... print 'othermethods' ... >>> c = f1() >>> c.somemethods() somemethods >>> import new >>> c.othermethods = new.instancemethod(C2.othermethods.im_func, c, c.__class__) >>> c.othermethods() othermethods HTH, -- Hans Nowak (hans at zephyrfalcon.org) http://zephyrfalcon.org/ From mrbrown200425 at yahoo.com Fri Aug 6 09:56:52 2004 From: mrbrown200425 at yahoo.com (Rob B) Date: 6 Aug 2004 06:56:52 -0700 Subject: import random error References: <7903bb89.0408051324.63ee1535@posting.google.com> Message-ID: <7903bb89.0408060556.2c332a28@posting.google.com> Thanks! Hard to believe I spent so long on that :) From kjetilho at yksi.ifi.uio.no Mon Aug 30 20:06:36 2004 From: kjetilho at yksi.ifi.uio.no (Kjetil Torgrim Homme) Date: Tue, 31 Aug 2004 02:06:36 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1ry8k0d2az.fsf@rovereto.ifi.uio.no> Message-ID: <1r1xhob27n.fsf@rovereto.ifi.uio.no> [Jacek Generowicz]: > > Kjetil Torgrim Homme writes: > > > ["pass"] should only be used when a suite is required, but the > > suite should do nothing. > > I'll have to take your word for it, that this is THE WAY. Oh, wait > a minute ... I don't take people's word for it, and I don't > subscribe to programming dogmas, partuclarly when they get in the > way of getting something useful done. Never mind, then. > [...] > I'm not presupposing any convention, I'm observing the current > state of the world and finding a working solution in it. You are > tilting at windmills. "I don't subscribe to programming dogmas", hmm? I guess "braces are unworthy of Python" isn't dogma, it's the Truth. > > and IMHO [abusing "pass" is] not worthy of a Python program. > > Whereas braces are worthy of a Python program. certainly. explicit is better than implicit, you know :-) thank you for your input, I will cover the "pass" hack in the PEP. -- Kjetil T. From curzio.basso at unibas.ch Wed Aug 11 04:09:53 2004 From: curzio.basso at unibas.ch (Curzio Basso) Date: Wed, 11 Aug 2004 10:09:53 +0200 Subject: how to dispatch objects depending on their class In-Reply-To: <4118faca$0$22911$636a15ce@news.free.fr> References: <4118dd4a$1@maser.urz.unibas.ch> <4118faca$0$22911$636a15ce@news.free.fr> Message-ID: <4119d457$1@maser.urz.unibas.ch> Bruno Desthuilliers wrote: > I saw something like a multi-methods implementation in Python somewhere, > this may interest you. > http://www-106.ibm.com/developerworks/linux/library/l-pydisp.html looks interesting. thanks for the link, I'll post some comment if I find it useful for my problem. cheers, curzio From RayOsborn at mac.com Tue Aug 3 19:48:44 2004 From: RayOsborn at mac.com (Ray O) Date: 3 Aug 2004 16:48:44 -0700 Subject: Disappearing objects in shelve Message-ID: I have read a number of threads relating to problems with shelve, but I couldn't find one directly related my experience, so I would appreciate some advice. The closest one ended with a recommendation to upgrade to Python 2.3, but that, unfortunately, is out of my control. The system I use runs Python 2.2.2, and whichdb gives dbhash. The problem only occurs when serializing class instances; lists don't seem to be affected. Every time I attempt to read the instance from the shelve file, it seems to delete it from the file even though I am not performing any write operations. Attempts to use flag='r' in the shelve.open generated error messages, as did restricting write permissions to the database. This is some example code. 'Editor.py' defines the class whose instance is stored in db["john"], etc. The file, "editors.db", originally contained keys "nick and "john". By the end, the file has been emptied. import shelve import Editor def main(): db = shelve.open("editors.db") value = db["john"] db.close() db=shelve.open("editors.db") print db.keys() db.close() db = shelve.open("editors.db") value = db["nick"] db.close() db=shelve.open("editors.db") print db.keys() db.close() main() >> import test [ 'john','nick'] ['nick'] I got the same result when I attempted a deep copy instead of the assignment to value. Anyone know what I'm missing? From cookedm+news at physics.mcmaster.ca Thu Aug 5 16:35:33 2004 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Thu, 05 Aug 2004 16:35:33 -0400 Subject: numarray speed question References: <953AD3D0Didtoken@128.91.2.239> <953C4DD4idtoken@128.91.2.239> Message-ID: At some point, grv575 at hotmail.com (grv) wrote: > squirrel at WPI.EDU (Christopher T King) wrote in > : > >>On Wed, 4 Aug 2004, grv wrote: >> >>> So it is supposed to be very fast to have an array of say 5 million >>> integers stored in a binary file and do >>> >>> a = numarray.fromfile('filename', (2, 2, 2)) >>> numarray.add(a, 9, a) >>> >>> but how is that faster than reading the entire file into memory and >>> then having a for loop in C: >>> (loop over range) { >>> *p++ += 9 } >>> >>> or is that essentially what's going on? >> >>That's essentially what's going on ;) The point of numarray isn't to be >>hyper-fast, but to be as fast as the equivalent C (or Fortran, or >>what-have-you) implementation. In many cases, it's faster, because >>numarray is designed with several speed hacks in mind, but it's nothing >>you can't do (without a little work) in C. >> > > Yes but see I'm interested in what speed hacks can actually be done to > improve the above code. I just don't see anything that can iterate and add > over that memory region faster. Well, numarray probably isn't faster for this case (adding a scalar to a vector). In fact, the relevant numarray code looks like this: static int add_Float64_vector_scalar(long niter, long ninargs, long noutargs, vo id **buffers, long *bsizes) { long i; Float64 *tin1 = (Float64 *) buffers[0]; Float64 tscalar = *(Float64 *) buffers[1]; Float64 *tout = (Float64 *) buffers[2]; for (i=0; i|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From rtw at freenet.co.uk Wed Aug 25 11:24:38 2004 From: rtw at freenet.co.uk (Rob Williscroft) Date: 25 Aug 2004 15:24:38 GMT Subject: Unpythonic Python References: <8a638f47.0408240034.653a92ff@posting.google.com> <8a638f47.0408240700.13c39f57@posting.google.com> Message-ID: David Abrahams wrote in news:uzn4j2s38.fsf at boost-consulting.com in comp.lang.python: >> That's not the problem. I can download the file reliably from other >> machines. At the same time, using http ? > > Actually it appears that urllib is having some problem on Unix, at > least the one from Python-2.2.x. This fails on Both FreeBSD and > Linux: > > urllib.urlretrieve( > 'http://cvs.sourceforge.net/cvstarballs/boost-cvsroot.tar.bz2', > 'boost-cvsroot.tar.bz2') > > Trying again with Python 2.3 on Cygwin. > Is it possible the file is being (re) uploaded (via cvs) during your cron job's download, thus truncating your download ? Perhapse you should change to cvs: os.system( 'cvs ... ' ) FWIW, I tried downlading with IE using the link above I got a truncated 6 and bit MB's (16:15 BST (UTC +0100)). Rob. -- http://www.victim-prime.dsl.pipex.com/ From python at rcn.com Thu Aug 26 01:31:34 2004 From: python at rcn.com (Raymond Hettinger) Date: 25 Aug 2004 22:31:34 -0700 Subject: Why return None? References: Message-ID: <5d83790c.0408252131.123cefb3@posting.google.com> Martin DeMello wrote in message news:... > It seems to be a fairly common pattern for an object-modifying method to > return None - however, this is often quite inconvenient. The FAQs provide a clue to Guido's thinking on this subject: http://www.python.org/doc/faq/general.html#why-doesn-t-list-sort-return-the-sorted-list Raymond Hettinger From littlejohn.75 at noos.fr Mon Aug 30 12:29:02 2004 From: littlejohn.75 at noos.fr (F. Petitjean) Date: 30 Aug 2004 16:29:02 GMT Subject: initializing mutable class attributes References: <1gjc8cs.sqvo1v1fhabdjN%aleaxit@yahoo.com> Message-ID: <413355ce$0$26999$626a14ce@news.free.fr> On Mon, 30 Aug 2004 15:39:54 GMT, Dan Perl wrote: > > "Alex Martelli" wrote in message > news:1gjc8cs.sqvo1v1fhabdjN%aleaxit at yahoo.com... > >> > So the only solution I see to this is to initialize attr2 in __init__: >> > class Father: >> > attr1=None >> > def __init__(self): >> > self.attr2=[ ] >> >> This is the canonical way, sure. >> Snip > > After seeing a few replies (yours, Benjamin Niemann's and Peter Otten's) to > my initial posting, I think I am getting the picture that there is a > conscious decision to keep the use of __init__ the way it is and just make > people learn it and learn it early enough. That's a valid approach and I'll > accept it. > Snip > > No one, including you, has given me a reason WHY __init__ is implemented > this way. I am not bashing you for that, I would just still like to hear > that 'WHY'. I'm sure that this implementation has some advantages. But, Explicit is better than implicit import this > > > Dan > PS: Does my last name attract the wrong kind of attention from people in > this newsgroup? It's really my name, it's not fake, BTW. My nick littlejohn is the direct translation of my last name and I'm far from big. So what ? :=) From dwelch91 at comcast.net Wed Aug 18 13:21:27 2004 From: dwelch91 at comcast.net (djw) Date: Wed, 18 Aug 2004 17:21:27 GMT Subject: PEP 318: Can't we all just get along? In-Reply-To: <41230713$0$20684$626a14ce@news.free.fr> References: <20040817181725194-0400@braeburn.themorgue.org> <41230713$0$20684$626a14ce@news.free.fr> Message-ID: Bruno Desthuilliers wrote: > Kevin Smith wrote: > >> For what it's worth, I wrote the original PEP 318. I probably wasn't >> qualified, but I just wanted a nice simple way to declare class >> methods without having to repeat the function name. After submitting >> it to BDFL for approval, more work was needed and the discussion of >> PEP 318 on python-dev increased rapidly. It was evident that I was in >> over my head, so I asked more someone more experienced to take over. >> I guess others had bigger plans for my proposal that I had planned. >> It has turned into the "solution" to many problems: type checking >> (both arguments and returned values), metaclasses, metadata, >> interfaces, function attributes, etc.). Unfortunately, in the >> process, this simple request for syntactical sugar has turned into a >> monstrosity. In my opinion, none of the proposed syntaxes really seem >> Pythonic. This PEP just seems to be trying to solve too many problems. >> >> Bear with me, but I'd like to propose one more syntax that is simple, >> easy for newbies to understand, and nowhere near as powerful as the >> current PEP's syntax. However, it doesn't add incoherent, arbitrary >> syntax either. >> >> def classmethod foo(x, y, z): >> pass >> >> That's it. One "decorator" that is a callable object that takes a >> method as it's only argument. No expressions, lists, tuples, etc. >> Just one callable object. > > > +2 for me. > > >> Ok, if you absolutely must have more than one. > > > def classmethod synchronized foo(x, y, z): > > pass > > No. If you want more than one, provide your own decorator, ie : > > def synchronizedClassmethod(method): > return synchronized(classmethod(method)) > > def synchronizedClassmethod foo(x, y, z): > pass > > My 2 eurocents > Bruno > +10 From tim.hochberg at ieee.org Thu Aug 5 17:59:43 2004 From: tim.hochberg at ieee.org (Tim Hochberg) Date: Thu, 05 Aug 2004 14:59:43 -0700 Subject: psyco out of memory In-Reply-To: References: Message-ID: Ivan Voras wrote: > Ivan Voras wrote: > >> (I'm running python 2.3.4 on FreeBSD 5) > > > Hmph. I tried on WinXP and it works. Maybe it's a platform-specific bug. > > (Still, I'm surprised how slow it is. The same "program" in Java takes > about 10sec, and here it's passed 5 minutes and I'm still waiting...) I believe that psyco only accelerates functions and methods. So, it's not going to do anything in the case you presented. This makes it particularly suprising that it broke. Try wrapping up your loop in a function. And with Psyco range is (or at least used to be) better. Like so: import psyco def f(): d = 0.0 for i in range(1000000000): d += i print d psyco.bind(f) f() That ran in about a minute here. Psyco won't speed up floating point operations near as much as integer ops at present, hence its speed deficit with respect to java. -tim From http Tue Aug 24 19:00:45 2004 From: http (Paul Rubin) Date: 24 Aug 2004 16:00:45 -0700 Subject: Has anyone implemented BASIC in Python? References: <2oo13eFcj548U1@uni-berlin.de> <2ot30hFeek8nU1@uni-berlin.de> <9h0ji0lvc0be65nuvcugaa3vsq5mcl3ck8@4ax.com> <285ni0hmusfgqslj9gnhhimvanr2jh0be3@4ax.com> Message-ID: <7xpt5gp2ea.fsf@ruckus.brouhaha.com> Andrea Griffini writes: > One could go *forever* by abstracting and generalizing and > formalizing, but there is a ROI point that must be considered, > and, for me, shift-reduce parser are beyond the ROI point. They are hard to code by hand, but the idea is normally you'd create them with a parser generator. From fred at acme.com Tue Aug 10 08:32:24 2004 From: fred at acme.com (Fred) Date: Tue, 10 Aug 2004 14:32:24 +0200 Subject: VB-like GUI designer? References: <278de0e.0408090935.6d758a5d@posting.google.com> <30260531.0408091506.294cec8a@posting.google.com> Message-ID: <6vfhh0dbpvucjd2qdc7g2v86h25vt4p4t0@4ax.com> On Tue, 10 Aug 2004 10:23:31 +0200, "Miki Tebeka" wrote: >Inno has a Pascal like scripting language which IMO is *way* easier than >NSIS assembly like language. Really? Was it added recently? I have to give it a shot :-) Thx Fred. From davidf at sjsoft.com Thu Aug 19 15:36:54 2004 From: davidf at sjsoft.com (David Fraser) Date: Thu, 19 Aug 2004 21:36:54 +0200 Subject: My only complaint about Python In-Reply-To: References: Message-ID: Istvan Albert wrote: > Darren Dale wrote: > >> I love the language. I love the community. My only complaint is that >> Python for Windows is built with Visual Studio. >> >> It is too difficult to build python, or a module, from source. > > > In all fairness this is more the problem with Microsoft than > python. If they had a free fully-featured compiler then Python > would be compiled with that. > > Microsoft seems to have made some half-hearted attempt in > this direction so that is promising. There's a difference between free and open source. I agree that having python compilable using a freely available open source compiler is important David From timrueAT at mindspringDOT.com Sat Aug 21 22:48:31 2004 From: timrueAT at mindspringDOT.com (threeseas) Date: Sun, 22 Aug 2004 02:48:31 GMT Subject: Mind.py In-Reply-To: <4127f9b1$1_2@news.athenanews.com> References: <41220b22@news.victoria.tc.ca> <4122796E.9652CCAE@alcyone.com> <4127CB0C.E4F49160@alcyone.com> <4127f9b1$1_2@news.athenanews.com> Message-ID: <3QTVc.30114$9Y6.6092@newsread1.news.pas.earthlink.net> Nick Chackowsky wrote: > Erik Max Francis wrote: > >> threeseas wrote: >> >> >>> Erik Max Francis wrote: >>> >>> >>>> "Arthur T. Murray" wrote: >>>> >>>> >>>>> Now, suppose that you wanted to write an AI in Python that would >>>>> implement your mind-model and allow it to grow, mutate, develop. >>>>> Here is one possible scenario. >>>> >>>> >>>> http://www.nothingisreal.com/mentifex >>> >>> >>> its a good thing we all use our minds alike, huh? >>> >>> Oh wait, so why doesn't Arthur slander or libel himself? >> >> >> >> It's like an epic battle between Racter and Eliza! >> > I was *wondering* why this sounded so familiar! This you? http://www.ratemyteachers.ca/ShowRatings.jsp?tid=47471 and lets not forget what Erik spend his time on.. http://www.crank.net/ ... shrug ... maybe that should be epic battle between Erik and Nick... this is a python programming language newsgroup. From webraviteja at yahoo.com Sun Aug 22 13:34:22 2004 From: webraviteja at yahoo.com (Ravi Teja Bhupatiraju) Date: 22 Aug 2004 10:34:22 -0700 Subject: Python future performance and speed References: Message-ID: "Sridhar R" wrote in message news:... > Python is used in a fps Windows game called 'Blade of Darkness'. > Except the core engine part (written in C/C++), everything else is > written in Python-1.5.2 Kingdom Under Fire (RTS + RPG) uses it in a similar way. From dave at pythonapocrypha.com Fri Aug 6 16:09:13 2004 From: dave at pythonapocrypha.com (Dave Brueck) Date: Fri, 06 Aug 2004 14:09:13 -0600 Subject: tweaking @decorator syntax In-Reply-To: <10h7ombdaruuae9@corp.supernews.com> References: <10h7ombdaruuae9@corp.supernews.com> Message-ID: <4113E569.4010400@pythonapocrypha.com> Jeff Shannon wrote: > Andrew Durdin wrote: > >> >> 5. In appearance it looks like a special kind of statement; and it is >> not at all obvious to me that it is rather a kind of attribute or >> modifier of the following function definition. I don't know of any >> other construction in Python that performs a similar, unmarked (i.e. >> non-explicit) modification of the following statement. So to me the >> @syntax comes across as extremely un-Pythonic (by that I mean >> radically inconsistent with the conventions of the rest of the >> language). For this same reason, I dislike all the proposed syntaxes >> which involve placing something before the "def" without a subsequent >> indented block. >> >> > > Ah, yes! Thank you for expressing the thing that's been really bugging > me about this syntax, but which I hadn't quite managed to put into > coherent words. I kept thinking that having all that stuff "stacked up" > above the function def looked horribly ugly, but I couldn't quite > express why... but I think you've hit on it exactly, there. > > The fact that it adds punctuation to an otherwise low-punctuation > language compounds matters, and I too would rather see a keyword than a > punctuation mark (though I do also understand the reluctance to add new > keywords). But really, it's the placement rather than the punctuation > that truly grates on my eyes. > > Hm, just as an experiment... > > def f(x,y): > '''tests two ints for equality > ''' > @accepts(int, int) > @returns(bool) > > return x == y > > > I still don't care for the @, but this looks much less jarring to me. > At very least, the decorators are much more clearly associated with the > particular function. Looks much less jarring for me, too. I think Andrew hit the nail on the head. -Dave From shalabh at cafepy.com Thu Aug 26 14:03:15 2004 From: shalabh at cafepy.com (Shalabh Chaturvedi) Date: Thu, 26 Aug 2004 11:03:15 -0700 Subject: Call for signatories for J2 In-Reply-To: References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> Message-ID: Doug Holton wrote: > Tim Hochberg wrote: > >> I also have a weak preference for 'per' over 'using', FWIW. The >> shortness of 'per' is one virtue. Another is that, because it's >> slightly obscure, it may be easier to indoctrinate users that >> 'per...def' is the correct order, not 'def...per'. For me at least >> it's 'obvious' that if 'using...def' works then so should >> 'def...using', which of course it can't. > > Even in common English usage, "per" usually comes in the middle of a > phrase, not the beginning, like "miles per hour" or "Changes were made > to the manuscript per the author's instructions" (people would more > commonly use the phrase "according to" rather than "per" there). > > None of those uses bare any resemblance to how decorators affect > functions. "per:" by itself on a line is pretty much meaningless. > Looks more like you misspelled pre. As per meaning #3 of the Merriam-Webster Online Dictionary [1], per also means 'according to'. In fact when I first saw the suggestion of 'per' I could immediately make sense of it in that context. I'm still debating whether to vote for or abstain, since I'm not that fond of 'using'. Cheers, Shalabh [1] http://m-w.com/cgi-bin/dictionary?book=Dictionary&va=per&x=0&y=0 From Holger.Joukl at LBBW.de Tue Aug 31 11:14:25 2004 From: Holger.Joukl at LBBW.de (Holger Joukl) Date: Tue, 31 Aug 2004 17:14:25 +0200 Subject: python 2 coercion Message-ID: Dear python list, What happens (on the C level) if the python interpreter executes a statement like if == None: ... Just a hint to the "entry point" would be great... What function/method is called for the two operands? I guess it is s.th. like PyObject_Compare or a type objects tp_compare method, but am a bit lost. Problem is I need to get an older number extension to work with python 2.3.4. It worked with 1.5.2, and everything still seems to work except for == comparison. I suspect that somewhere on the way some coercion is tried but does not work, but fail to see the steps that lead to this situation. Thanks, Holger Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene Empf?nger sind oder falls diese E-Mail irrt?mlich an Sie adressiert wurde, verst?ndigen Sie bitte den Absender sofort und l?schen Sie die E-Mail sodann. Das unerlaubte Kopieren sowie die unbefugte ?bermittlung sind nicht gestattet. Die Sicherheit von ?bermittlungen per E-Mail kann nicht garantiert werden. Falls Sie eine Best?tigung w?nschen, fordern Sie bitte den Inhalt der E-Mail als Hardcopy an. The contents of this e-mail are confidential. If you are not the named addressee or if this transmission has been addressed to you in error, please notify the sender immediately and then delete this e-mail. Any unauthorized copying and transmission is forbidden. E-Mail transmission cannot be guaranteed to be secure. If verification is required, please request a hard copy version. From donald.welch at hp.com Tue Aug 31 12:46:45 2004 From: donald.welch at hp.com (djw) Date: Tue, 31 Aug 2004 09:46:45 -0700 Subject: GUI Wizard: flow control? References: Message-ID: <4134ac26@usenet01.boi.hp.com> David Chan wrote: > Hi, > > I'm trying to use python to create GUI wizards, i.e. sequences of dialog > boxes with buttons. Since I want to re-use some of the > dialog boxes in different wizards, I want to have a main function which > calls each dialog box, much like this: > > def select_item(): > """runs GUI wizard to select item""" > > client = show_client_dialog() > job = show_job_dialog(client) > invoice, rate = show_invoice_dialog(job) > item = choose_item_dialog(invoice, rate) > return item > > This works fine until you want to implement the return to the previous dialog. Theoretically, what I'd really like is to > be able to jump backwards through the control flow, like this: > > class GoBack(Exception): pass > def select_item(): > """runs GUI wizard to select item - can go back = HERE > client = show_client_dialog() > > try: job = show_job_dialog(client) > except GoBack: back.goto() > back = HERE > > try: invoice, rate = show_invoice_dialog(job) > except GoBack: back.goto() > back = HERE > > try: item = show_item_dialog(invoice, rate) > except GoBack: back.goto() > > return item > > But I couldn't find a way of doing anything like that. You could do > something almost as unhorrible with nested breaks:' > > class GoBack(Exception): pass > def select_item(): > """runs GUI wizard to select item - can go CLIENT: while 1: > client = show_client_dialog() > > JOB: while 1: > try: job = show_job_dialog(client) > except GoBack: continue CLIENT > > INVOICE: while 1: > try: invoice, rate = show_invoice_dialog(job) > except GoBack: continue JOB > > try: item = show_item_dialog(invoice, rate) > except GoBack: continue INVOICE > break CLIENT > > Or you could do all the flow control manually in a "do_wizard" function > and make the caller create a horrible data structure instead of writing > readable code: > > calls = [ > {'meth': show_client_dialog, 'args': [], 'ret': ['client']}, > {'meth': show_job_dialog, 'args': ['client'], 'ret': ['job']}, > {'meth': show_invoice_dialog, 'args': ['job'], 'ret': ['invoice', > {'rate']}, 'meth': show_item_dialog, 'args': ['invoice', 'rate'], > {'ret': ['item']}, > ] # this just says: "client = show_client_dialog()", etc. > do_wizard(calls, locals()) > > > But this is too hideous to deploy, because I might have to remember what > it does in six months :-) > > Can anyone suggest something better, or should I abandon my goal of having > a main function which calls each dialog box? > > Many thanks, I always code this sort of situation up as a simple state machine. Each NEXT/BACK button controls the next state, each state being the display of a particular dialog. A state machine can be a good candidate for flow control that has to go "forwards" and "backwards". -Don From apardon at forel.vub.ac.be Thu Aug 12 10:57:43 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 12 Aug 2004 14:57:43 GMT Subject: [OT] Keyboard layout, was Re: PEP318 References: <20040812090056.00001e31@titan> Message-ID: Op 2004-08-12, Roy Smith schreef : > Sion Arrowsmith wrote: >> As someone who's just started using a Mac for the first time(*), >> I'd like to add that it's not always plain-sailing on an English >> keyboard. > > What's wrong with Mac keyboards? I've used a number of Mac keyboards > over the past 15 or so years, and have found the variety of layouts to > be no better or worse (or more or less standardized) than any other > keyboards in general. I'm currently using a 12" PowerBook and other > than finding the control key to be uncomfortably close to the space bar, > I find it perfectly reasonable for programming and emacs-ing. > >> And I have a great >> aversion to remapping keyboards so that they generate characters >> other than those on the keycaps.) > > Yes, that's evil. I was just in the UK a couple of weeks ago and was > using a semi-UK keyboard. As far as I could tell, the keycaps were > labeled with the UK layout, but the codes they generated were US style. > I touch-type, so as long as I ignored what was printed on the keycaps > and just typed normally, everything was fine. But it's amazingly > difficult to ignore the printed keycaps. It's not that difficult if you gain some experience with it. Half the keboards here are qwerty the other half is azerty. On all machines I have to work on with an azerty I have configured my account to treat the keyboard as if the keyboard is qwerty. After a little getting used to that works easier and faster than always adjusting to the keyboard of the specific computer. -- Antoon Pardon From twanger at bluetwanger.de Tue Aug 10 07:39:38 2004 From: twanger at bluetwanger.de (Markus Bertheau) Date: Tue, 10 Aug 2004 13:39:38 +0200 Subject: How do I get IDLE on Suse Linux 9.x? In-Reply-To: <0G1Sc.149588$fv.89578@fe2.columbus.rr.com> References: <0G1Sc.149588$fv.89578@fe2.columbus.rr.com> Message-ID: <1092137978.2624.18.camel@dicaprio.akademie1.de> ? ???, 10.08.2004, ? 12:44, michael ?????: > My question is this: Should I just use a text editor and go without IDLE? Is > there another IDE standard on Linux? Do I need to download something to get > IDLE? On Fedora I can start IDLE with python /usr/lib/python2.3/idlelib/idle.pyw -- Markus Bertheau From michele.simionato at gmail.com Thu Aug 12 11:16:32 2004 From: michele.simionato at gmail.com (Michele Simionato) Date: 12 Aug 2004 08:16:32 -0700 Subject: Help understanding Scheme's syntax, procedures and calls References: <95f168b0.0408120120.31433dc7@posting.google.com> Message-ID: <4edc17eb.0408120716.2bde3005@posting.google.com> franbarlow at mail.com (Fran) wrote in message news:<95f168b0.0408120120.31433dc7 at posting.google.com>... The right place where to ask this question is comp.lang.scheme. They are pretty gentle with newbies, so don't worry ;) Michele Simionato From anthonybaxter at gmail.com Mon Aug 23 05:03:03 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Mon, 23 Aug 2004 19:03:03 +1000 Subject: J2 proposal: keyword In-Reply-To: References: Message-ID: On Mon, 23 Aug 2004 01:36:31 -0700, David Pokorny wrote: > using: > staticmethod synchronized memoize > def bar(foo): > "To colon or not to colon? Def is the question." > pass > > is easy on the eye while > > using: > staticmethod > synchronized > memoize > def bar(foo): > "english teachers will call you on putting two colons in one sentence" > pass The problem is that using: staticmethod accepts(int, str) returns(str) published(True) def bar(count, input): return input * count looks worse (imo) than using: staticmethod accepts(int, str) returns(str) published(True) def bar(count, input): return input * count I suspect this sort of decorator usage (more complex decorators) will become more common over time, as new and interesting patterns are developed once 2.4 is final. (Guido's comment on the original @syntax being limited to one-per-line was that it was a "gut feeling" thing.) From andre.roberge at ns.sympatico.ca Wed Aug 25 11:12:48 2004 From: andre.roberge at ns.sympatico.ca (Andr? Roberge) Date: 25 Aug 2004 08:12:48 -0700 Subject: Best GUI- Python for children - pygame and blender32 Message-ID: Sorry about the cryptic subject line, but I wanted to capture the essence of my message in a single line. I am learning Python (which, as everyone know is the best language :-) so that I can write a tutorial to teach my kids about computer programming. The motivation for them will be to use Python to create their own games using pygame and, eventually, blender3d. From what I hear, their friends will be interested in that tutorial too. When/if I am satisfied with it, I'll make it publicly available (first in French though - an English translation will have to wait). My approach is to use what I called JITT (just in time teaching :-) i.e. introducing as few concepts as are needed in order to understand the "next topic", leading to game creation as soon as possible. Seems to be working so far. I am now at the point of writing a "chapter" on GUIs. I've written a few sections about Tkinter but I haven't shown them to my kids yet as I am not convinced this is the best way to go; I've read enough about anygui, pythoncard, pyui, easygui, not to mention wxpython, etc. to instill doubts in my mind. I can't really afford to take the time to learn enough about all of those to make an informed decision on my own, decision that I could regret later on. As long as the chosen GUI is as easy as possible to learn but "complete" enough (and fast enough as an interface?) to do fun stuff with pygame (and, possibly, blender3d, if a separate GUI is needed), I will be satisfied. Any advice would be much appreciated. Andr? Roberge PS As for the python survey, I'm 43 years old, started learning about Python about a month ago, have done some programming in the past for fun using Fortran, C, and java, but haven't done any serious programming for years and it is not required at all for my day job. From pm_mon at yahoo.com Thu Aug 19 09:24:06 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Thu, 19 Aug 2004 09:24:06 -0400 Subject: classmethods, staticmethods, and decorators Message-ID: Probably the best-loved features of Python are the shortcuts. The fact that you don't have to explicitly declare very much and that the language supports clear, shorthand syntax for frequently used operations... x = [1,2,3] y = r[2:9] def __foo(): That's the good stuff of Python. I believe that identifying staticmethods and classmethods is an operation that is (or will be) frequently used as compared to the other decorators. So it would be great if there was an obvious, shorthand way for doing that as well. Even better (IMO) would be a solution that didn't really add any new keywords to the language, but instead simply formalized widely-used coding conventions, as was done to denote code block boundaries. The use of indentation to identify code blocks is a wonderful example of Python shorthand. It works (some even call it 'genius') because it leverages a coding convention shared by a majority of programmers. A week or so ago on this forum, Stefan Eischet suggested that the type (static|class|instance) of a method should be inferred through examination of its first parameter. I agree with his assessment. The vast majority of instance methods I've seen all use 'self' as the first parameter. Likewise, most class methods use 'cls' or 'klass' as their first parameter. If we exploit these conventions, we end up with a simple, clear, obvious mechanism for denoting (this aspect of) a method's type. class Foo(Object): def m1(self, a, b): # this is an instance method of Foo pass def m2(cls, a, b): # this is a class method of Foo pass def m3(a, b): # this is a static method of Foo pass And for backwards compatibility, a special Object (capital 'O') class could work this magic so that old code didn't break. I know that this is odd. But then so are most of the great things about Python. Paul From me at privacy.net Sun Aug 1 10:53:07 2004 From: me at privacy.net (Duncan Booth) Date: 1 Aug 2004 14:53:07 GMT Subject: Microbenchmark: Summing over array of doubles References: <4d642979.0407312049.7a8aecab@posting.google.com> Message-ID: bulatov at engr.orst.edu (Yaroslav Bulatov) wrote in news:4d642979.0407312049.7a8aecab at posting.google.com: > I made an array of 10 million floats timed how long it takes to sum > the elements, here's what I got (millis): I just had a brief look at the code you posted. Are you not concerned about accuracy in any of your calculations? Summing a 10 million element array by simply accumulating each element into a running total is guaranteed to give a lousy result. Also, without running it I don't see how most of your Python examples work since you seem to call the timing function with the result of the calculation which doesn't make sense. From lbates at swamisoft.com Mon Aug 30 10:44:51 2004 From: lbates at swamisoft.com (Larry Bates) Date: Mon, 30 Aug 2004 09:44:51 -0500 Subject: Get Parent path value (bad design) Help References: Message-ID: I think what you want is: import os pathname=os.getcwd() parentpath=os.sep.join(pathname.split(os.sep)[:-1]) sys.path.append(parentpath) #append the path back to sys.path This is shorter and portable. HTH, Larry Bates Syscon, INc. "Golawala, Moiz M (GE Infrastructure)" wrote in message news:mailman.2601.1093875943.5135.python-list at python.org... Hi all, What I am trying to do is write some generic code where I can get the path of the parent directory. for example if current working directory is 'Z:\\dirA\\Parent\\Child' I want to get a string which up like 'Z:\\dirA\\Parent' Then I do a sys.path.append('Z:\\dirA\\Parent') The code I have written below does all this.. but I have a feeling there is a better way to do this.. Please can someone help me. import os import sys pathname = os.getcwd() pathString = '' pathList = pathname.split("\\") pathList.pop() # removes the child lastItem = pathList.pop() #remove to the parent, will be added back later. counter = 0 while counter != len(pathList): #build up the path with items in the list pathString = pathString + pathList[counter] + "\\\\" counter +=1 pathString = pathString + lastItem #add parent back to the built up path sys.path.append(pathString) #append the path back to sys.path Thanks, Moiz Golawala From ptmcg at austin.rr._bogus_.com Fri Aug 20 10:30:04 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 20 Aug 2004 14:30:04 GMT Subject: Alternative decorator syntax decision !! IMPORTANT THREAD !! References: Message-ID: "Ville Vainio" wrote in message news:du7vffdj38m.fsf_-_ at lehtori.cc.tut.fi... > >>>>> "Paul" == Paul McGuire writes: > > Paul> I'm afraid I have to agree, the subject is a poor one. I > Paul> noticed that yesterday as the responses were slow to come > Paul> in. Something more on the order of "READ THIS - IT'S > Paul> FREAKIN' IMPORTANT!" is surely warranted. > > Yup - for those just joining in, post somewhere in this thread, it > involves voting that all pythonistas know & love (along with the > associated grain of salt that goes with it here in > pythonland). Instructions in the root message. > > -- > Ville Vainio http://tinyurl.com/2prnb Will you vote now? :) From me at privacy.net Mon Aug 2 22:15:50 2004 From: me at privacy.net (Dan Sommers) Date: 02 Aug 2004 22:15:50 -0400 Subject: Class optimization at runtime References: Message-ID: On Mon, 2 Aug 2004 16:06:03 -0500, "Larry Bates" wrote: > Kind of hard to tell what you are trying to accomplish > but I'll try. Define the class with no if/else statements. > They only get parsed once. It is the "class instance" > creations that may get created millions of times. They > will be inside your logical structure. > class Foo: > def __init__(self): > # do stuff > class Bar: > def __init__(self): > # do stuff > if option: x=Foo() > else: x=Bar() Similarly: class FooWithOption: def __init__( self ): # whatever class FooWithoutOption: def __init__( self ): # whatever if option: Foo = FooWithOption else: Foo = FooWithoutOption x = Foo( ) Alternatively: module WithOption: class Foo: # whatever class Bar: # whatever module WithOutOption: class Foo: # whatever class Bar: # whatever if option: from WithOption import * else: from WithoutOption import * x = Foo( ) I guess it depends on how similar the with and without classes are as to which one will be easier to maintain. In either case, there's only one test and no additional overhead at class instantiation time. > HTH, > Larry Bates Regards, Dan -- Dan Sommers Never play leapfrog with a unicorn. From ake.ljungbert3 at comhem.se Tue Aug 10 18:56:32 2004 From: ake.ljungbert3 at comhem.se (?ke) Date: 10 Aug 2004 15:56:32 -0700 Subject: compiling with msvc7 References: <875af5e2.0408071735.4c1fdf89@posting.google.com> <4115da69$0$161$9b622d9e@news.freenet.de> <144d0df.0408092027.4f93f29a@posting.google.com> Message-ID: <875af5e2.0408101456.fb122b5@posting.google.com> grv575 at hotmail.com (grv575) wrote in message news:<144d0df.0408092027.4f93f29a at posting.google.com>... > "Martin v. L?wis" wrote in message news:<4115da69$0$161$9b622d9e at news.freenet.de>... > > ?ke wrote: > > > I am trying to comile C code to python with weaver, using Microsoft > > > Visual Studio .NET (which I think uses VS 7.0) but I get an error > > > that Python is compiled with VS 6 and so doesn't work. > > > > > > Anyone knows a workaround for this ? > > > > Recompile Python, or buy VC6. > > > > Regards, > > Martin > > garlic Well it's actually a very good compiler. You don't have to use .NET or anything like that, ordinary C++ code works very well. I tried devC++ but it just didn't work with graphics on Windows systems. ?ke From peter at engcorp.com Fri Aug 6 10:09:56 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 06 Aug 2004 10:09:56 -0400 Subject: Buy a vote! (was Re: Poll - Vote here for "list-after-def" (was Decorator syntax)) In-Reply-To: References: Message-ID: Delaney, Timothy C (Timothy) wrote: > Anthony Baxter wrote: > >>The solution, if you don't like the syntax, is not voting. It's to >>propose an argument that Guido will accept, in favour of your >>preferred option. > > I see this less as a vote, and more an attempt to reach a community > consensus - or at least a large enough one to lend weight to the many > arguments that have already been presented. I suggest that everyone with an opinion on the matter visit the page at http://www.python.org/psf/donations.html and make a donation, preferably sized in relation to the strength of your opinion. (*) Afterwards, we can just visit the updated list of donors and base the final decision on whether the Atecksan are higher up in the list than the Listecksan or not. (And if they are, we can still consider just banishing them all to Blefuscu, or make them wear high heels or use Perl or something.) > I will live with pie-syntax, but I won't be overly happy with it. I > would much prefer that list-after-def be accepted. Agreed. -Peter (*) I've just done so, since it seems like a more productive thing than endless argument over the same issues. And this way at least there will be money to pay Anthony to do the right thing. ;-) From shalabh at cafepy.com Fri Aug 27 14:52:09 2004 From: shalabh at cafepy.com (Shalabh Chaturvedi) Date: Fri, 27 Aug 2004 11:52:09 -0700 Subject: Class Friends In-Reply-To: <20040827081556.657c3fac.a@c.d> References: <20040827081556.657c3fac.a@c.d> Message-ID: Sean Don wrote: > Hello! > > Is it possible to make classes friends in Python? Not just possible - all Python classes are always friends with each other (something that rubs off Python programmers, I suppose :) Shalabh From anthonybaxter at gmail.com Tue Aug 17 10:55:50 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Wed, 18 Aug 2004 00:55:50 +1000 Subject: Decorators: an outsider's perspective In-Reply-To: References: <20040814153534.8AC171E4007@bag.python.org> Message-ID: On Tue, 17 Aug 2004 09:34:26 -0400, Paul Morrow wrote: > > Damn straight - that's awful. Why on earth would someone implement > > that? > > > > I expected a :-) after your comment (as the behavior I describe is > already being performed by the Python system)... I know that. When writing something as obviously taking the piss as my comment, I don't think it's necessarily to include a smiley - that's for the people who don't get humour, like Americans. Anthony From aleaxit at yahoo.com Mon Aug 30 04:07:39 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 30 Aug 2004 10:07:39 +0200 Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> <1gj8q2n.1fbrmbet624ssN%aleaxit@yahoo.com> Message-ID: <1gjbrlg.1efa44am6bcc0N%aleaxit@yahoo.com> Paul Morrow wrote: > Alex Martelli wrote: > > Paul Morrow wrote: > > ... > > > >>Cool! Thanks! Now I need to ponder why a function's docstring needs a > >>different implementation than a class's docstring (i.e. why not just > >>make it a straigtforward attribute of the function object). > > > > > > Historically, functions had docstrings before they had straightforward > > attributes. Maybe it could be that. > > > > > > Alex > > /* > I have stared at your reply for three or four minutes now. On the > surface, it seems that you are being genuinely helpful, and so I want to > reply "Thanks. Of course. That makes perfect sense." Heh, I think you've wasted a few minutes here. > > But then a lot of smart people say things that (on the surface) appear > honestly helpful but in reality are suggestions that the reader do more > research before asking questions that have such an obvious answer. Doing your own research is good, of course. But once you have, there's no harm checking your conclusions on mailing lists. Functions had a few _non_-straightforward attributes (such as func_doc AKA __doc__ -- and I don't recall which one came first) for a long time before they got straightforward (==implemented with a dict) ones, after all. > > I know that you're a smart person Mr. Martelli. So I flipped a coin to > decide which intreprtation of your reply to use, which came up tails, > indicating the 2nd one. > > Bahh. I prefer the superficial one (plz correct me if I'm wrong). > */ > > Thanks. That does make good sense. They've had no reason to simplify > the implementation for function docstrings, so "why fix it if it ain't > broke." Many object types have 'slots' ("non straightforward attributes") as well as possibly a per-instance dict in which they may keep other (straightforward) attributes. I see no reason why moving attributes from dedicated slots to a dictionary should be a simplification. Take attribute __name__: that's not in the dict for either functions or classes (in functions, it's also known as func_name). Why not? Alex From PPNTWIMBXFFC at spammotel.com Thu Aug 19 03:29:36 2004 From: PPNTWIMBXFFC at spammotel.com (Marco Aschwanden) Date: Thu, 19 Aug 2004 09:29:36 +0200 Subject: Editors again References: Message-ID: http://wingware.com/ - WingIde 2.0 has all you want. From iketo2 at netscape.net Fri Aug 27 09:15:13 2004 From: iketo2 at netscape.net (Isaac To) Date: 27 Aug 2004 21:15:13 +0800 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> Message-ID: <87hdqok9i6.fsf@sinken.local.csis.hku.hk> >>>>> "Kjetil" == Kjetil Torgrim Homme writes: Kjetil> how can Emacs tell? if I press TAB and thus ask Emacs to Kjetil> re-indent the line, that's what it will do. If the aim is simply to do a local change that is sufficient to deal with the problem just in your computer, then the simplest answer might be to use "pass": if your code contains if t1 == t2: t1 = t3 else: t2 = t3 pass t = t2 and you tab at the last line, Emacs won't try to indent the t=t2 line further to after the pass line where it is impossible to execute. If you want something that is done globally and everybody will use it... not a chance. Kjetil> arguably, the correct fix is to disable the "clever" Kjetil> re-indentation code of Emacs since it's too easy to fool Kjetil> it, but this makes coding more awkward in other cases. The indent-region command of Emacs (M-C-\) is really disabled in Python mode, I think it is done by nullifying the indent-region-function. Anyway, reindent makes sense only when the indentation does not constitute the meaning of a program and thus the editor can freely change it. If indentation does mean something, it doesn't make sense at all. Kjetil> it also doesn't solve cut-n-paste errors. Use C-c > and C-c < might work for you. Regards, Isaac. From apardon at forel.vub.ac.be Mon Aug 16 10:24:25 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 16 Aug 2004 14:24:25 GMT Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: Op 2004-08-16, Peter Hansen schreef : > Antoon Pardon wrote: > >> Op 2004-08-16, Peter Hansen schreef : >>>Did you really not indent your code in those languages consisntly >>>anyway? >> >> I can't answer for keith, but my answer is that it depends on >> what you consider consistent. >> >> My indentation was consistent with the structure of the algorithm. >> That is not necesarrily the same as the structure you implemeted >> that algorithm in. > > Huh? How does an algorithm have structure that affects > indentation? It sounds like you are talking about some kind > of artistic considerations here. Simple: not all languages provide the same control structures. So you have to use the control structures that are available to simulate the control structure you really want to use. >> I think that I should be the final judge of what is the most >> appropiate way to use indentation, not the compilor/interpreter, >> even if it agrees with me. > > So did you indent your code such that consecutive lines were > not indented to the same identation level even when they were > conceptually, logically, *algorithmically* part of the same > block? No, but although they were *algorithmically* not in the same block, due to lack of control-structures they had to be implemented as being in the same block. In a language as python, this would force IMO the indentation to be wrong. > I know there are such people out there. I even had to fire one > once, roughly because he had no concept of how his failure to > write his code with anything resembling consistent indentation > meant that it was unreadable to others. (At least, that was the > surface symptom which warned us of deeper problems.) What I > doubt is that many of those people are out there rejecting > Python just because it doesn't let them write god-awful unreadable > code with artistic or random indentation. I don't reject python. There is still no language I find perfect. I find python usefull and use it regularly, despite the details I don't like about it. I don't like the enforced indentation, even if I agree 99.99% of the time with the indentation python enforces. -- Antoon Pardon From martin at v.loewis.de Tue Aug 24 16:25:40 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 24 Aug 2004 22:25:40 +0200 Subject: fun with unicode files In-Reply-To: <6579x7eo.fsf@python.net> References: <6579x7eo.fsf@python.net> Message-ID: <412BA444.2010309@v.loewis.de> Thomas Heller wrote: > I wonder: do I really have to check for the BOM manually, or is there a > Python function which does that? If it can also be ASCII (or ansi?), then yes, you need to manually check for the BOM. This is because you need to make an explicit decision in the fallback case - Python cannot know whether it is ASCII if it is not UTF-16. For example, it might also be Latin-1 or UTF-8 if it is not UTF-16, or, say, iso-2022-jp. Regards, Martin From newsgroups at jhrothjr.com Fri Aug 6 09:13:58 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 6 Aug 2004 09:13:58 -0400 Subject: Confused about pep 318 References: <10h2ihgb8c6fi97@corp.supernews.com> <411304AB.F53A5275@alcyone.com> Message-ID: <10h710cds2i4s18@news.supernews.com> "Erik Max Francis" wrote in message news:411304AB.F53A5275 at alcyone.com... > Skip Montanaro wrote: > > > Bengt> I too am very much against wasting '@' on @decorator! > > > > We could just switch completely to Unicode. Then we'd have all sorts > > of > > punctuation characters available. How about > > > > # -*- coding: utf-8 -*- > > \xe2\x98\xbadecorator > > def f(): > > pass > > > > ? > > Given how things are looking so far with the reaction to the decorator > syntax, I'd say U+2639 might be more appropriate ... Chuckle! For those who haven't looked it up, it's a "sad face" smiley (a frowney?) John Roth > > -- > __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ > / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis > \__/ Drifting from woman-who-tries misconstrued / Shifting to > woman-wise -- Lamya From luismg at gmx.net Fri Aug 27 17:49:32 2004 From: luismg at gmx.net (Neuruss) Date: 27 Aug 2004 14:49:32 -0700 Subject: Dynamic languages Message-ID: <278de0e.0408271349.26762174@posting.google.com> I've been reading an article published in E-Week entitled "Microsoft Lures Open-Source Programmer", which contains a definition for dynamic languages as follows: "Dynamic programming languages enable programs to change their structure as they run." I wonder if this definition is correct. Can we define dynamic languages this way? http://www.eweek.com/article2/0,1759,1636906,00.asp From export at hope.cz Mon Aug 9 08:47:38 2004 From: export at hope.cz (Lad) Date: 9 Aug 2004 05:47:38 -0700 Subject: Apache web server and CGI Message-ID: <81a41dd.0408090447.7f27a092@posting.google.com> How can I set up Apache web server to use Python for CGI processing( for file *.py). Thanks for help Lad From zathras at thwackety.com Fri Aug 27 17:23:35 2004 From: zathras at thwackety.com (Michael Sparks) Date: Fri, 27 Aug 2004 22:23:35 +0100 (BST) Subject: Alex Martelli: Welcome back! In-Reply-To: Message-ID: On Fri, 27 Aug 2004, Dave Benjamin wrote: > It's nice to see you around here again! It certainly is - and back with a BANG :-) Michael. From jpmorichon at earthlink.net Thu Aug 5 11:43:25 2004 From: jpmorichon at earthlink.net (CptPicard) Date: Thu, 05 Aug 2004 15:43:25 GMT Subject: Need help on how to use Pymedia! References: Message-ID: Thank you for your help! "3c273" wrote in message news:cetiuv01vmi at enews4.newsguy.com... > > "CptPicard" wrote in message > news:AXgQc.508$nx2.344 at newsread2.news.atl.earthlink.net... > > Hi, > > I am currently trying to use pymedia so to get the following informations > > (author, song title, ...) from a mp3 file. > > The documentation I downloaded is quite limited : It gives some clues on > how > > to get that information (method getInfo() from pymedia.audio.acodec). > > However, it does not explain what has to be done prior to that call. > > I downloaded pycar but it did not help me. > > > > Could someone give me a more detailed documentation on pymedia or some > clues > > on how to get the information I need ? > > > > Thanks for your help > > > Hi, > I have never used pymedia but section 6.7 of the "Dive Into Python" tutorial > describes a class for getting mp3 file information. It is quite simple and > if I recall correctly, it worked perfectly when I tried it. HTH. > Louis > > From adurdin at gmail.com Sun Aug 22 19:29:03 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Mon, 23 Aug 2004 09:29:03 +1000 Subject: J2 proposal: keyword In-Reply-To: <3b2846c4.0408221506.1c3e33d2@posting.google.com> References: <3b2846c4.0408221506.1c3e33d2@posting.google.com> Message-ID: <59e9fd3a040822162957f4d986@mail.gmail.com> Certainly "using... def..." comes across very clearly to me. I think it the best of the proposed keywords. From lbates at swamisoft.com Fri Aug 20 18:48:40 2004 From: lbates at swamisoft.com (Larry Bates) Date: Fri, 20 Aug 2004 17:48:40 -0500 Subject: Install Python on win32 without modifying registry References: <2260b3c5.0408200600.4c0550c4@posting.google.com> Message-ID: Can you install any other programs on your computer that don't write anything to the registry? Microsoft programs sometimes make 100's of registry changes. You need registry entries to associate .PY programs with Python, etc. Not really sure why Python should be expected to do something that hardly any other modern program is expected to do. HTH, Larry Bates Syscon, Inc. "QyRoN" wrote in message news:2260b3c5.0408200600.4c0550c4 at posting.google.com... > Hi > > I need to install python-2.3 on my computer. The problem is that > python and many programs written in python (pythonwin for example) use > registry for storing parameters on python installation. Is there a way > to install without modifying the registry? From pete at fenelon.com Thu Aug 26 07:18:09 2004 From: pete at fenelon.com (Pete Fenelon) Date: Thu, 26 Aug 2004 12:18:09 +0100 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: In alt.folklore.computers Giles Todd wrote: > > That's OK. I've done it for you. Now, try investigating "Rambling > Sid Rumpo". > I need to fossick through me ganderbag and work out a way of mp3ing my taped collection of Rambling Syd's artefacts, me dearios. pete -- pete at fenelon.com "there's no room for enigmas in built-up areas" From prudek at bvx.cz Sat Aug 21 06:28:07 2004 From: prudek at bvx.cz (Milos Prudek) Date: Sat, 21 Aug 2004 12:28:07 +0200 Subject: popen child termination Message-ID: <412723B7.1080002@bvx.cz> How can I make popen (popen2, popen3) run and finish inside my program? Example: def Run(cmd): w,r,e = os.popen3(cmd) w.close() r.close() e.close() Run('touch ~/xxx') os.remove('~/xxx') The example above fails with this error message for os.remove: "No such file or directory: '~/xxx'" But when the os.remove line is deleted, the example correctly creates the xxx file. I feel that os.wait() deals with this but I do not understand how to use it to do what I want. -- Milos Prudek From http Mon Aug 23 05:13:48 2004 From: http (Paul Rubin) Date: 23 Aug 2004 02:13:48 -0700 Subject: J2 proposal: keyword References: Message-ID: <7x1xhyjjxv.fsf@ruckus.brouhaha.com> Anthony Baxter writes: > using: > staticmethod > accepts(int, str) > returns(str) > published(True) > def bar(count, input): > return input * count Semi-OT: since there's been all this noise about not wanting to separate the decorators too much from the function name, etc., why are "accepts" and "returns" decorators instead of having that stuff in the function def itself? E.g.: using: def bar:str(count:int, input:str): return input * count puts the info about the arg and return types where it belongs. It even looks a little bit Pascal-like. I don't know if that last part is good or bad ;-). From MAILsweeper at hibernian.ie Mon Aug 23 11:44:27 2004 From: MAILsweeper at hibernian.ie (MAILsweeper at hibernian.ie) Date: Mon, 23 Aug 2004 16:44:27 +0100 (BST) Subject: Mail sent to Hibernian has a virus !!! Message-ID: <20040823154310.BA8CF1E4002@bag.python.org> Mail sent to Hibernian was received with a computer virus infected attachment. The mail has been intercepted and did not reach the intended recipient. Sender please remove the virus from the message and resend the mail. From: python-list at python.org To: maria.mccabe at hibernian.ie Subject: Re: Notify Virus: Scenarios/Incoming/Content Scanner: Threat: 'W32/Netsky-P' detected by 'Sophos AV Interface for MIMEsweeper'. Scenarios/Incoming/Content Scanner: Threat: 'W32/Netsky-P' detected by 'Sophos AV Interface for MIMEsweeper'. Scenarios/Incoming/Restrict Attachments In: 'ItemLength.GE.0'. was blocked at Mon, 23 Aug 2004 16:42:26 +0100 From abra9823 at mail.usyd.edu.au Fri Aug 20 03:24:11 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Fri, 20 Aug 2004 17:24:11 +1000 Subject: html templates In-Reply-To: <23vai09725mmg69tg3ji8d0dpi1mgd7fak@4ax.com> References: <23vai09725mmg69tg3ji8d0dpi1mgd7fak@4ax.com> Message-ID: <1092986651.4125a71b73886@www-mail.usyd.edu.au> > >also quixote offers a session management API? how secure is this > session > >management? is it just a cookie on the client side? > > "Just" a cookie? How would you do session management more securely? well what i really meant is whether the data is just kept on the cookie or is a hash of the data (and some random string) also stored. or do you store the name of a tmp file on the cookie and the file itself contains the session data. i think i'll give cheetah a try cheers ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From pink at odahoda.de Tue Aug 24 18:00:18 2004 From: pink at odahoda.de (Benjamin Niemann) Date: Wed, 25 Aug 2004 00:00:18 +0200 Subject: Macro expansion: intercept statement interpretation In-Reply-To: References: Message-ID: You could try to override __import__ to first parse the source for macro definitions and do the expansions. Usage would then be: import DoMagicWithImportModule import ModuleWithMacros (Your code wouldn't work, because python throws a SyntaxError long before it even tries to execute 'import MyCustomMacroLib') The code at http://docs.python.org/lib/examples-imp.html could be extended to first read the contents of the module (after find_module) and passes the expanded source (e.g. as a StringIO) to load_module. This has of course the problem (that many implementations of macro expansion share) that line numbers in exception dumps have not much relation to lines of the unexpanded code... From v451v at yahoo.com Thu Aug 26 14:31:23 2004 From: v451v at yahoo.com (Jorl Shefner) Date: Thu, 26 Aug 2004 14:31:23 -0400 Subject: ANN matplotlib-0.60.2: python graphs and charts References: Message-ID: <2p6oiuFhgiaoU1@uni-berlin.de> In article , John Hunter wrote: > >>>>> "Lou" == Lou Pecora writes: > > Lou> Anyone have any experience running this on Mac OS X? What > Lou> does it take to get it up and running. I'm enticed. Will > Lou> check it out on my own, too, but any info welcome. Thanks. > > Hi Lou, > > In response to this thread on the mailing list > http://sourceforge.net/mailarchive/forum.php?thread_id=5124458&forum_id=33405 > I just made some changes to setupext.py (matplotlib's config script) > to accommodate the tk framework under OS X (borrowed from PIL's > setup.py). You can get the updated file from > http://matplotlib.sourceforge.net/setupext.py. > Good luck! > JDH This is great to hear and much appreciated! I had tried so many times (with several versions of matplotlib) get it running on OS X and always ended in frustration. Incidentally, I did recently manage to get it working (but only by installing the huge Scisoft binary bundle: http://www.stecf.org/macosxscisoft/) which finally got matplotlib up and running. After using now for a few weeks, I've been hugely impressed with the quality of the plots and its ease of use -- definitely worth all the trouble to get it installed. J.S. From cmedcoff at hotmail.com Thu Aug 5 11:06:49 2004 From: cmedcoff at hotmail.com (cmedcoff at hotmail.com) Date: Thu, 5 Aug 2004 11:06:49 -0400 Subject: Complex Object Support in SOAP Message-ID: I'm working with a Java (Axis) based Web Service that accepts and returns fairly complex object structures. Are there any Python libraries that supports clients for this type of a web service? I've not seen a Python Soap Library that generates proxies that might be used to create objects that need to be passed as parameters to such a web service. Any links, suggestions are appreciated. From indigo at bitglue.com Sun Aug 1 21:41:30 2004 From: indigo at bitglue.com (Phil Frost) Date: Sun, 1 Aug 2004 21:41:30 -0400 Subject: The term "Protocol" In-Reply-To: References: <1f7befae04080117515cbb0ca9@mail.gmail.com> <6910338109.20040801192523@MailBlocks.com> Message-ID: <20040802014130.GA1516@unununium.org> "Protocol" in python has no meaning beyond normal English. Specifically the iteration protocol says the iterable must have a __iter__ method which returns an object that has an __iter__ which returns self, and a next() method that returns the next thing in the thing being iterated. When there are no more things, next() raises StopIteration. All of this is a simple protocol defined by the python language. It doesn't introduce anything new to the language besides the protocol itself; __iter__ and next are regular methods and StopIteration is raised just as any other class can be raised as an exception. On Sun, Aug 01, 2004 at 07:25:23PM -0600, Bruce Eckel wrote: > Sunday, August 1, 2004, 6:51:15 PM, Tim Peters wrote: > > > Iteration is a protocol, not a type. > > I know the term "protocol" has been used to describe a language > feature in a number of languages, but since we have no official > "protocol" support in Python I'm interested in what "we" mean by this > term. I'm going to guess that a protocol is like an interface in Java, > except that it doesn't have a concrete definition anywhere, but it is > implied through convention and use. Thus a protocol is a "latent > interface." Am I close? I'd like to understand this term better. > > Bruce Eckel From ptmcg at austin.rr._bogus_.com Wed Aug 25 20:05:27 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Thu, 26 Aug 2004 00:05:27 GMT Subject: Call for signatories for J2 References: Message-ID: For. Paul McGuire From h.b.furuseth at usit.uio.no Sun Aug 8 06:30:46 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 08 Aug 2004 12:30:46 +0200 Subject: pep-318 questions Message-ID: ...and opinions:-) I don't understand some of the arguments in pep-318 (version 1.19), or what the current syntax has to do with some of the design goals mentioned there. Could someone explain? > Design Goals > > The new syntax should > (...) > make it obvious what is happening; at the very least it should be > obvious that new users can safely ignore it when writing their own > code Huh? The current no-keyword, no-indentation syntax seems as far removed from "obvious" as one could get for Python. As for obvious that new users need not use it, it seems pretty hard to _avoid_ meeting that goal. Is it just included for completeness, or does it mean something more than I see in the statement? > not make it more difficult to scan through code quickly. It should > still be easy to search for all definitions, a particular definition, > or the arguments that a function accepts The current syntax seems like the clear loser here too: No whitespace above the function name. Not too bad with a single decorator, but several is a problem. In fact, I think decorator- before-def scales very badly in this respect, at least the syntaxes without indentation. And the way people are coming up with uses for decorators, functions could end up with a lot of decorators. Quoting Arthur, "Doesn't readibility require that you have the ability to move in a direction down the page, and, if so, why am I getting information about a method prior to the existence of the method, before a proper introduction has been made, i.e. before I even know its name." Anyway, to me, decorator after the def's ':' seems like the clear winner on the "easy to scan" point, decorator before ':' might possibly be #2 (unsure here - it's "theoretically right" but some posted examples look ugly), and a statement with indentation in front of the def #3. (Could indent just the decorators like the 'using' suggestion in the PEP, see below.) > Alternate Proposals > using: > dec1 > dec2 > ... > def foo(arg1, arg2, ...): > pass > > The function definition is not nested within the using: block > making it impossible to tell which objects following the block > will be decorated. Huh? How is this different from telling which 'else:' is tied to an 'if:'? It does give the def statement a new syntax in that it can be the 2nd part of a compound statement. Is that what you mean - that people who do not know about decorators won't know they must read the 'using:' together with the 'def:'? If so, it seems to me that the cure is exactly the same as with the @ syntax: Don't put any whitespace between the decorator and the def. If you do put whitespace there, both syntaxes lose readers who do not know about decorators. And probably some readers who do, as well. > Nesting the function definition within the using: block suggests > nesting of namespaces that doesn't exist. Why, when try:, if:, for: and while: do not? True, this surprised me when I learned Python. But when I had learned it, I had learned it. > Finally, it would require the introduction of a new keyword. Actually, I'm wondering about that too. As far as I can see, if a statement starts with one word and a colon, then the word is a keyword. If so, it would not be ambiguous to allow 'using', 'else' and 'try' as variable names. And since they are immediately followed by the colon, the parser only needs one lookahead symbol to tell that they are keywords. Yet I do see that it might complicate the parser somewhat, and allow more bugs or more obscure error messages when someone forgets the colon. Anyway, '@using:' could be an alternative, even if it has an excess of special characters. Or __future__, of course. -- Hallvard From mjackson at alumni.caltech.edu Fri Aug 20 21:03:19 2004 From: mjackson at alumni.caltech.edu (Mark Jackson) Date: 21 Aug 2004 01:03:19 GMT Subject: age of Python programmers References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: Reid Nichol writes: > Mark Jackson wrote: > > Reid Nichol writes: > > > >>Gerrit Muller wrote: > > > > > >>>and then a quantum leap towards Python. > >> > >>You're aware that a quantum leap means a extremely small leap, right? > > > > > > Everything's relative - compared to the smallest possible change in the > > classical continuum, a quantum leap is *huge*. > > > > True, but this doesn't change the definition of the word. > > from dictionary.reference.com: > The smallest amount of a physical quantity that can exist independently, > especially a discrete quantity of electromagnetic radiation. and Reid Nichol writes elsewhere: > Check the definition of the word. and Reid Nichol writes elsewhere: > Peter Hansen wrote: > > And at least some dictionaries give it as a synonym for "large" > > or "significant". (www.m-w.com for one) > > > > -Peter > Such things are only the result of a misunderstanding of the word some > time ago. Even though it is wrong, it has become common use, thus the > incorrect definition definition(s). from which we conclude that "check the definition" means "check the definition in the dictionary *I* prefer". . . . but Tim Hochberg writes elsewhere: > You might look at this, also from dictionary.reference.com: > quantum leap > A dramatic advance, especially in knowledge or method, as in > Establishing a central bank represents a quantum leap in this small > country's development. This term originated as quantum jump in the > mid-1900s in physics, where it denotes a sudden change from one energy > state to another within an atom. Within a decade it was transferred to > other advances, not necessarily sudden but very important ones. from which we conclude that "check the definition" means "check the definition in the dictionary *I* prefer. . .AND stop reading before it contradicts the position I espouse." Look, given the use of "quantum" in quantum physics it's reasonable to expect the word to mean something small - but insisting it must do so is flat-out wrong. For one thing this isn't Gell-Mann appropriating a nonsense word - "quark" - from Joyce; "quantum" was a perfectly good English word before Planck applied it to black-body radiation. The OED has references going back to 1619 as a synonym for quantity. (It even has a use in pharmacology - "quant. suff!", famously chanted in Alfred Bester's /The Stars My Destination/, is an abbreviation of "quantum sufficit," roughly "as much as necessary.) -- Mark Jackson - http://www.alumni.caltech.edu/~mjackson Fascism should more properly be called corporatism, since it is the merger of state and corporate power. - Benito Mussolini From h.b.furuseth at usit.uio.no Tue Aug 31 11:29:34 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 31 Aug 2004 17:29:34 +0200 Subject: has_method (solution found) References: <41347BC1.5020407@geochemsource.com> Message-ID: Eric Brunel wrote: > def getmethod(obj, name): > meth = getattr(obj, name) Because he doesn't know if the method exists? He used has_key(), after all. Gandalf, you can use hasattr(obj, name) first, or you can use getattr(obj, name, None) (or some other default value than None). -- Hallvard From luismg at gmx.net Fri Aug 13 18:33:21 2004 From: luismg at gmx.net (Neuruss) Date: 13 Aug 2004 15:33:21 -0700 Subject: Pyhton Interpreter Startup time References: Message-ID: <278de0e.0408131433.55445f3f@posting.google.com> As far as I could see, the startup of python 2.3 is considerably slower than python 2.2. It is something that really annoyed me when I first installed Python 2.3 (and I did it in three different machines). If the startup time is critical for your application, I suggest using an older version of Python and, if possible, try to use Psyco to improve its performance. From karin.lagesen at labmed.uio.no Mon Aug 16 06:34:00 2004 From: karin.lagesen at labmed.uio.no (Karin Lagesen) Date: Mon, 16 Aug 2004 10:34:00 +0000 (UTC) Subject: sys.stdin.read() replacement Message-ID: I am writing a small write-logfile script for use on the terminal. I have here a section where the user should be able to type in several lines. I have solved it so far by using sys.stdin.read(), which makes it possible to type in several lines (separated by enter) and then terminate the session by typing ^D. This is all very good. However, with this it is only possible to edit the line you are in. If you spot an error further up in your text, you cannot get at it. Do any of you know of a way I can do this? Thanks, Karin -- Karin Lagesen, karin.lagesen at labmed.uio.no From bbands at yahoo.com Sat Aug 7 11:48:37 2004 From: bbands at yahoo.com (BBands) Date: 7 Aug 2004 08:48:37 -0700 Subject: Fuzzy Logic References: <79780d4f.0408010711.75df6f83@posting.google.com> Message-ID: <79780d4f.0408070748.78e56a2b@posting.google.com> bbands at yahoo.com (BBands) wrote in message news:<79780d4f.0408010711.75df6f83 at posting.google.com>... > Does anyone know of any fuzzy logic work done in Python? > > The only thing I have found is logic.py, which has gone missing from > the Vaults of Parnassus and the original site, > http://www.ourobourus.com/logic.py. > > --jab A couple of answers to my own question: http://sourceforge.net/projects/fuzzypy/ http://pyfuzzy.sourceforge.net/ Any other resources? --jab From gherron at islandtraining.com Sun Aug 22 15:11:38 2004 From: gherron at islandtraining.com (Gary Herron) Date: Sun, 22 Aug 2004 12:11:38 -0700 Subject: Python is to C as letters are to words. In-Reply-To: References: Message-ID: <200408221211.38133.gherron@islandtraining.com> On Sunday 22 August 2004 11:55 am, r holland wrote: > My nine word description of the python language. Huh ... Either you've got that backward, or I completely misunderstand what you're trying to say? From __peter__ at web.de Tue Aug 24 03:48:10 2004 From: __peter__ at web.de (Peter Otten) Date: Tue, 24 Aug 2004 09:48:10 +0200 Subject: Time-date as an integer References: Message-ID: Charles Hixson wrote: > This is a concept, not a finished program, and an extract from a class > at that...so forgive any illegalities, but: ...but not the funny whitespace. > import datetime; > def calcNodeId(self): > t = datetime.utcnow() > val = t.year * 133920000000 + # 12 months > t.month * 11160000000 + # 31 days > t.hour * 3600000000 + # 60 minutes > t.minute * 60000000 + # 60 seconds > t.second * 1000000 + t.microsecond > if val <= self._dTime: > val = self._dTime + 1 > self._dTime = val > return val > > This is the best that I've been able to come up with in getting a > date-time as an integer. It feels like one of the time or date > libraries should have a better solution, but if so, I haven't found it. > Can anyone suggest a better approach? Have you considered a more lightweight approach? >>> import itertools >>> class Tree: ... def __init__(self): ... self.calcNodeId = itertools.count().next ... >>> tree = Tree() >>> tree.calcNodeId() 0 >>> tree.calcNodeId() 1 >>> tree.calcNodeId() 2 >>> If you need the datetime information, just store the datetime, too. Peter From jeff at ccvcorp.com Thu Aug 26 16:49:12 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Thu, 26 Aug 2004 13:49:12 -0700 Subject: Newbie question on dictionary!!! In-Reply-To: <494182a9.0408261150.a4c767f@posting.google.com> References: <494182a9.0408261150.a4c767f@posting.google.com> Message-ID: <10isj57fbl4eb75@corp.supernews.com> Balaji wrote: >Hello everybody... > >I want to ask a simple question. > >Suppose I have an list say g=['a','b','c','d'] > >and I have an dictionary say k={'b':20,'a':10} > >Now I want to sort this dictionary on the basis of the list and if it >doesnt find any of the element in the list then I wud like to replace >it with zero.. > >so I would like to modify k into {'a':10,'b':20,'c':0,'d':0} > > Dictionaries don't maintain any particular sort order. (Or, technically, dictionaries are by definition sorted by the result of hash(value), which may not bear any resemblance to the sort order of value.) So, we can't get your dictionary sorted the way you want, but we *can* fill in the undefined keys. You want to use the dictionary method get(). It will return the value of a key, or a specified default value if that key isn't found. You can then assign the result of that back into the dictionary under the same key. for key in g: k[key] = k.get(key, 0) Jeff Shannon Technician/Programmer Credit International From sheldon.johnston at home.firstnet.se Tue Aug 10 16:16:14 2004 From: sheldon.johnston at home.firstnet.se (Sheldon) Date: 10 Aug 2004 13:16:14 -0700 Subject: Image Message-ID: <76655b52.0408101216.196f452b@posting.google.com> Hi, Does anyone know how to read an array back into python after writing it to a .dat file using tostring()? My method using Image results in a valueerror: data is not enough... x = open('file.dat') array = x.read() print array : results in unreadle garble while im = Image.fromstring('I', (81,81),array) gives the valueError: data not enough... The tutorial on Image leaves a lot to be desired. Any help or new ideas would be welcomed! thanks, Sheldon From newsgroups at jhrothjr.com Wed Aug 4 12:46:51 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Wed, 4 Aug 2004 12:46:51 -0400 Subject: PEP 318 - PyFIT comments Message-ID: <10h24oace15n97a@news.supernews.com> Decorator syntax seems to have been checked into 2.4b2. I'm not going to comment on the syntax other than to say that, when there isn't a real obvious syntax, someone has to make a decision, and this one should work. I was originally against it, on the basis that the only use cases I saw were the elimination of the staticmethod() and classmethod() builtin functions. I've used them, and they're not ideal, but something like decorators for that one use case seems to be going after a fly with a howitzer. Andrew Kuchling's comments here: http://www.amk.ca/diary/archives/cat_python.html#003255 and especially the comments he quotes from Jim Hugunin got me to thinking again about it. I can't quite see what Thomas Heller is getting at with ctypes, though. My current interest is in PyFIT. It's a Python port of Ward Cunningham's FIT acceptance testing program (fit.c2.com). I had to add a general metadata mechanism to it to make it work cleanly (the original port by Simon Michael tried to use RExec, which obviously no longer works as well as having major ambiguity problems.) There's an early release in the download section at http://www.xprogramming.com/software.htm The current releases are in the files section of the Extremeprogramming and the Fitnesse Yahoo mailing lists. When I looked at the metadata problem, I really wanted a mechanism that would allow me to attach metadata to any object in the class object. I can do that to function objects, but I also need to do it to properties and more general objects (such as strings and integers.) This doesn't, unfortunately, allow me to do that. John Roth From ville at spammers.com Wed Aug 18 16:21:56 2004 From: ville at spammers.com (Ville Vainio) Date: 18 Aug 2004 23:21:56 +0300 Subject: age of Python programmers References: Message-ID: 27 years, 4 of them with awareness of how much the other languages I have/had to work with suck. BTW, even though usenet might not really scale all that well for this kind of thread, it's been delightful to see how so many are still actively hacking at a respectable age. It really sets an example for us younger ones, some of whom are possibly worried about how to preserve the energy level of youth and whether they can still hack it when they "grow up". I'm also optimistic about retiring with Python, because *everyone* is going to retire with Python in 2044 :-). -- Ville Vainio http://tinyurl.com/2prnb From fuzzyman at gmail.com Fri Aug 27 06:49:49 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 27 Aug 2004 03:49:49 -0700 Subject: print question - character representation References: Message-ID: <6f402501.0408270249.56d48a41@posting.google.com> Ajay wrote in message news:... > hi! > > i am calculating a digest of some data (using hmac) and printing it to a > cookie. the problem is the hash may contain special characters. when these > are printed they get converted to \ representation. > later when i receive the cookie i recalculate the hmac and do a comparison > which returns false because of the conversion when writing to a cookie > > q - how do i stop the conversion from happening? if i cant then how can i > convert the hmac i recalculate on receiving the cookie to the same > representation as the one printed > > thanks > > cheers > > > One way is to use a binary to ascii conversion - like the binascii module. Regards, Fuzzy http://www.voidspace.org.uk/atlantibots/pythonutils.html From trentm at ActiveState.com Mon Aug 16 18:28:30 2004 From: trentm at ActiveState.com (Trent Mick) Date: Mon, 16 Aug 2004 15:28:30 -0700 Subject: Editors again In-Reply-To: ; from ivoras@__-geri.cc.fer.hr on Tue, Aug 17, 2004 at 12:18:52AM +0200 References: Message-ID: <20040816152830.C27169@ActiveState.com> [Ivan Voras wrote] > Are there any editors besides IDLE that can display doc-strings[*] in > popups? I tried SPE and DrPython, and while they are ok (better said > 'not horribly bad'), they don't seem to have that option. > > I'd like to see in an editor: > - code-completion in case of functions, member variables etc. > ("intelli-sense"? :) ) > - useful usage of doc-strings, maybe integrated python Help/Manual support > - MDI or similar style, with good navigation (this is why I don't like > IDLE) > > Actually, SPE is pretty close, but auto-completion seems to behave > 'funny' sometimes, and no doc-string support I can see... You could try Komodo. The recently released 3.0 has much better Python autocomplete/calltip support. (Note: I work on Komodo so I am biased.) http://www.activestate.com/Products/Komodo/ Cheers, Trent -- Trent Mick TrentM at ActiveState.com From python at rcn.com Tue Aug 31 18:34:30 2004 From: python at rcn.com (Raymond Hettinger) Date: 31 Aug 2004 15:34:30 -0700 Subject: Generator expressions v/s list comprehensions References: Message-ID: <5d83790c.0408311434.3cc38c24@posting.google.com> [Mahesh Padmanabhan] > Now I see that generator expressions have been added to the language > with 2.4 and I question the need for it. I know that it allows for lazy > evaluation which speeds things up for larger lists but why was it > necessary to add it instead of improving list comprehension? FWIW, we improved list comprehensions too. They run much faster now. Raymond From fuf at mageo.cz Thu Aug 5 06:50:42 2004 From: fuf at mageo.cz (Michal Vitecek) Date: Thu, 5 Aug 2004 12:50:42 +0200 Subject: distutils frustration Message-ID: <20040805105042.GB14544@foof.i3.cz> hello everyone, i've been trying to write a distutils setup.py to compile and install getdate module by Jeff MacDonald. unfortunately, it seems that distutils doesn't support either bison or running a custom Makefile. moreover and most importantly it doesn't look like it's easy to add a support for files with the '.y' extension. please, prove me i'm wrong (i'd be happy to) :) thank you, -- fuf (fuf at mageo.cz) From Scott.Daniels at Acm.Org Tue Aug 10 15:27:25 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 10 Aug 2004 12:27:25 -0700 Subject: Simple hashcash implementation In-Reply-To: References: Message-ID: <411923f1$1@nntp0.pdx.net> barnesc at engr.orst.edu wrote: > Here's a simple hashcash implementation in Python. > 28 lines of actual code.... Looks like you've spent a bit of time on this. If you do think it is generally useful, why not put it in the Python Cookbook? -Scott David Daniels Scott.Daniels at Acm.Org From abra9823 at mail.usyd.edu.au Tue Aug 3 22:32:49 2004 From: abra9823 at mail.usyd.edu.au (Ajay Brar) Date: Wed, 04 Aug 2004 12:32:49 +1000 Subject: Crypto.PublicKey.RSA.error: Plaintext too large In-Reply-To: References: Message-ID: <41104AD1.3080909@mail.usyd.edu.au> Peter Hansen wrote: > Ajay Brar wrote: > >> Peter Hansen wrote: >> >>> Ajay Brar wrote: >>> >>>> I am getting an error - Crypto.PublicKey.RSA.error: Plaintext too >>>> large - when verifying the signature of a document. ... >>> >>> >>> Carriage Return/Line Feed problems? Or trailing newline problems? >> >> >> thats what i am going to investigate now. But even if there were >> trailing newline or carriage return characters, shouldn't the verify >> return false instead of giving the error. > > > I couldn't say, not having used that particular API. What does > the documentation say it should do? Always return just True or > False? Does it not make reference to this type of error? > > -Peter the documentation says verify should return true or false. it will generate an error if plaintext is too large - which is not helping me much i have pinned the problem down to the signature itself and the way i am downloading it. what i do is when a user clicks on a signature link, i calculate the signature on the fly and then do print "Content-type: application\n" print signature i am using content-type application to force explorer to give the download dalog box (the application i am building will later be ported to a pocket pc). Microsoft on their website said to put the header "Content-disposition: attachment;filename=blah" to force dowload, but that didn't work - i am yet to find out what i am doing wrong? so any ideas on how i send the signature across and make the user download it? btw, are there other free Python cryptography packages? thanks cheers -- Ajay Brar CS Honours 2004 Smart Internet Technology Research Group http://www.it.usyd.edu.au/~abrar1 From jacek.generowicz at cern.ch Mon Aug 30 03:41:15 2004 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 30 Aug 2004 09:41:15 +0200 Subject: Class Friends References: <20040827081556.657c3fac.a@c.d> Message-ID: Jeremy Bowers writes: > In Python, there isn't much of an idea of "Private"; **** ALERT: Rantbot trigger activation 8986232 **** Rant title: Encapsulation and access restriction are orthogonal concepts. Rant variant: Python. Rant summary: The concept of privacy existis in Python. Please don't confuse privacy with access restriction. Python supports encapsulation. Please don't confuse encapsulation with access restriction. Encapsulation is data abtraction; access restriction is a pain in the arse. Rant body: > Some people would use "self.__x", to get the psuedo-private name > munging invoked. ... access restriction for the really dense. If the programmer is too dumb to figure out the name mangling scheme and work around it, then he (and the project he is working on) has some serious problems, to the extent that accessing private data when he shouldn't becomes but a drop in the ocean. From mark_bottjer at hotmail.com Fri Aug 6 17:01:42 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Fri, 06 Aug 2004 17:01:42 -0400 Subject: @decorators In-Reply-To: References: Message-ID: <4113f1b8$1@nntp.zianet.com> David Fraser wrote: > I like this idea. What about using the list syntax instead of the @ > syntax: > > [static, synchronized, types(int, int), returns(None) ]: > def foo(): > pass No, no, NO! Lists are value expressions: not statements, not declarators, and most certainly not suites!!! Sorry, just had to get that out of my system... :) Seriously, though, one problem I see is that this can get obfuscative really fast as the number or complexity of decorators grows: [static, synchronized, types(int, int), returns(None), yet, more, decorators, go, here, making(this), quite, the( (pain, to, read, past)) ]: def foo(): pass By the time I've read all of that, I've likely forgotten what it was I was looking for in the first place. Of course, the @ syntax as it stands has the same problem, but at least it doesn't introduce spurious indentation in the process. > This would then take away the argument against a valid list before a > def being valid python but not previously having any effect... Right. At the expense of a grammar that is nonsensical when viewed in the context of how those symbols work elsewhere in the language. Here we have a list (okay), containing a bunch of function names (okay), which get called via side-effect on something not explicitly indicated (er...), and starts a block of code (say what???). The (){}[] symbols all already *mean* something in python (often more than one thing, actually). The @ doesn't mean anything yet, so it is a perfect candidate for a completely new concept such as this. I just think that they put it in the wrong spot. > declare [static, synchronized, types(int, int), returns(None)]: > def foo(): > pass > def bar(): > pass People keep suggesting this one, and I just don't see it. Yes, it's shorter (marginally, sometimes). But is it really clearer? I don't think so. Now, instead of just having to look at the preceding few lines to figure out what decorators are being used, you have to look up an arbitrary number of lines. Not fun when one's functions start getting real-world sized. I understand the desire to reduce the redundancy, but even this small example shows a fundamental problem with this approach. In all but the most simple cases, most functions will end up with *different* sets of decorators. Case in point: both foo and bar above take (int, int) and return None. Such parity rarely survives in the wild. This leaves us with even more of a mess: declare [static, synchronized]: declare [returns(None)]: declare [types(int)]: def foo(a): pass declare [types(int, int)]: def bar(a, b): pass declare [returns(int)]: def baz(): pass I *shudder* to think of trying to sort this out when these functions contain real code. (FYI: None of this is directed at you, personally. Your post just happened to be the first post I found suggesting this kind of syntax.) -- Mark From jeffrey at I.slack Mon Aug 9 10:49:45 2004 From: jeffrey at I.slack (Jeffrey Froman) Date: Mon, 09 Aug 2004 07:49:45 -0700 Subject: Purely emotional perspective Message-ID: <10hf3oaltbo7o74@corp.supernews.com> I have only been using python for a few years, but I have loved it every step of the way. Each time a new version was released, it contained improvements that enhanced the readability and feel of simplicity (such as list comprehensions, substring in string, ...). And each such improvement delighted me even more, because this is exactly why I loved python in the first place. Now come decorators, introducing a non-alphabetic symbol (instead of say, a new keyword), and worst of all for readability, they come *before* the function declaration that they supposedly decorate. I understand that doing things this way has certain technical advantages, but this is the first time I (in my short history with python) have noticed readability being sacrificed for any reason. It makes me sad. I feel like my favorite organic food product decided to start using preservatives and fillers to save money. Jeffrey From grv575 at hotmail.com Tue Aug 31 00:56:26 2004 From: grv575 at hotmail.com (grv575) Date: 30 Aug 2004 21:56:26 -0700 Subject: profiler References: Message-ID: <144d0df.0408302056.3e5b0255@posting.google.com> does that flag just amount to adding -pg to the compile & link stages, or is there more to it than that global change? because I couldn't get python to generate a gmon.out output file using a version of python configured with the flag, but it did do so by just adding -pg to OPTS and LDPATH I think it was. But now it gives profiling output but gprof dies with: # gprof gmon.out gprof: gmon.out: not in a.out format Skip Montanaro wrote in message news:... > Brett> As of Python 2.4 you can also compile in support for C-level > Brett> profiling into the interpreter (--enable-profiling). See the > Brett> in-dev docs (http://www.python.org/dev/doc/devel/) for details. > > Ummm... That's a pretty high-level url. How about: > > http://www.python.org/dev/doc/devel/whatsnew/node11.html > > instead. Even though I was the guy that added the --enable-profiling flag > to configure it still took me a couple minutes to find the above url. > > Skip From ialbert at mailblocks.com Tue Aug 3 12:06:16 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Tue, 03 Aug 2004 12:06:16 -0400 Subject: dislin interfaced with tkinter In-Reply-To: <34c9b4fa.0408030743.594417f9@posting.google.com> References: <34c9b4fa.0408030743.594417f9@posting.google.com> Message-ID: eesun wrote: > I've downloaded the dislin package for the scientific plotting. And I > have already created the application window with Tkinter (menu, > canvas, status bar..). I want to integrate the Dislin plotting into > the Tkinter application. For ex: show the dislin result on the Tkinter > Canvas. Anyone can help? I believe that dislin plots trough its own graphical device that is independent of Tkinter thus cannot be integrated with it. You might want to try matplotlib, it has Tk backend http://matplotlib.sourceforge.net/ the nice folks there might be able to help you out. Istvan. From insert at spam.here Thu Aug 12 10:17:00 2004 From: insert at spam.here (Doug Holton) Date: Thu, 12 Aug 2004 09:17:00 -0500 Subject: The winner of the Python Decorator Poll is... In-Reply-To: <4edc17eb.0408112052.1bbd85b3@posting.google.com> References: <4edc17eb.0408112052.1bbd85b3@posting.google.com> Message-ID: Michele Simionato wrote: > Indeed. Actually I did not vote since I like the current proposal (maybe > I would like "|" more than "@") and I dislike all the alternatives, > especially having decorators inside the def. > > So the poll is unavoidably biased. Happily, we are not in a democracy! Do you think there are 400 people out there that read about the poll but didn't vote because they like the current proposal as it stands? That's what would have had to have happened for bias to completely invalidate the results. From mark_bottjer at hotmail.com Fri Aug 6 17:20:33 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Fri, 06 Aug 2004 17:20:33 -0400 Subject: @decorators In-Reply-To: References: <10h6v76mm313cce@news.supernews.com> Message-ID: <4113f622$1@nntp.zianet.com> David Fraser wrote: > John Roth wrote: > >> "daishi" wrote in message >> news:d22692a3.0408052233.3459c3fa at posting.google.com... >> >>> For what it's worth: >>> >>> As far as I know, the proposed @decorator syntax will be the first >>> time that two logical lines of python with the same indentation will >>> not be independent of one another. >> >> Examples: >> >> try - except - finally >> if - elif - else >> while - else > > I think he mean two consecutive lines of python code with the same > indentation. That's how I took it. From another angle, each of the clauses in try/except/finally et al start a suite (i.e., end in ':'); @dec does not. Except for the funny symbol, it looks just like any other statement--but it sure doesn't act like one. -- Mark From npat at efault.net Tue Aug 17 03:14:35 2004 From: npat at efault.net (Nick Patavalis) Date: Tue, 17 Aug 2004 07:14:35 +0000 (UTC) Subject: Why I love python. References: Message-ID: On 2004-08-17, Delaney, Timothy C (Timothy) wrote: > > No - it is a discussion about simplicity. Mobile phones were used as an > example of something simple becoming les and less simple, to which you > produced a denigrating response. > Sory if my response sounded denigrating. It was not my intention, honest. All I wanted to point-out was that these devices are complex, and there's no way arround it. They *do* require massive amounts of software to work efficiently, and whether this complexity is visible to the user (in the form of java-games, web-browsers, or whatever), or hidden internally and visible only to the developers is another issue. So even if your cell-phone has the simplest user-interface in the world, it still requires a lot of software to function, and this software has to be written in some programming language. /npat From peter at engcorp.com Sun Aug 22 11:20:42 2004 From: peter at engcorp.com (Peter Hansen) Date: Sun, 22 Aug 2004 11:20:42 -0400 Subject: Python future performance and speed In-Reply-To: References: <278de0e.0408211605.426e5129@posting.google.com> Message-ID: Roy Smith wrote: > Speed is the primary limitation for mainstream acceptance of high level > (aka scripting) languages in general. I can think of no reason why so > much software is still written in languages like C++ other than > performance (or at least, the perception of it). I'm glad you added that parenthetical comment, because I'm nearly certain that it is *not* actual experience with Python, and disappointment with its speed, that is the cause. Far more likely, it seems to me, is that the primary limitation for mainstream acceptance of scripting languages(*) in general is ignorance. More specifically, a lack of knowledge of their capabilities or ability to handle the job. I'm quite sure there are far more people out there doing C++ or Java work who have never *heard* of Python, than people who have heard of it and have the perception it is too slow for their work, though appropriate in other ways. -Peter * I limit this to scripting languages since it's quite certain that the mainstream *has* accepted high level languages quite fully. The last time I checked, Java and C++ (even C) were widely considered to be high level languages. Has someone been raising the bar while I wasn't looking? From mark_bottjer at hotmail.com Thu Aug 12 19:47:51 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Thu, 12 Aug 2004 19:47:51 -0400 Subject: Verbosity Check Style In-Reply-To: References: Message-ID: <411c01a8$1@nntp.zianet.com> Dan Sommers wrote: > On Thu, 12 Aug 2004 11:23:49 -0400, wrote: >>I would like to get people's views on the best way to implement >>verbosity (or any command-line option) into python scripts. > > Use the logging module (new in 2.3). I think that verbosity equates to > the INFO level. Not always. Many programs have multiple levels of informative verbosity, where each level exposes "more" information. Of course, the additional information can be viewed as DEBUG, but there can be multiple levels of that, too. Even if you want more than one level of verbosity, you can still use the logging module (or any other facility, for that matter). I use a Verbose class, which I pass an instance of to anything in my code which wants to log something. A simplified version would be: class Verbose: import sys as __sys def __init__(self, verbosity = 0, log = __sys.stderr): self.__vebosity = verbosity self.__log = log def __call__(self, verbosity, msg): if verbosity >= self.__verbosity: print >>self.__log, '*' * verbosity, msg if __name__ == '__main__': # Test import sys verbose = Verbose(4, sys.stdout) verbose(1, "Level one message.") verbose(3, "Level three message.") verbose(5, "Level five message.") Which gives the following output when imported: * Level one message. *** Level three message. The nice thing here is that, once you've got it in a class, you can subclass it. This allows you to add helper methods to make logging certain types of information easier, or to support different types of logger. You can even use it to switch at runtime between using the logger module, dumping straight to a stream, or both. I find it to be quite flexible. -- Mark From mwh at python.net Thu Aug 5 14:27:32 2004 From: mwh at python.net (Michael Hudson) Date: Thu, 5 Aug 2004 18:27:32 GMT Subject: Confused about pep 318 References: <10h2ihgb8c6fi97@corp.supernews.com> <10h4s026oapbhf1@corp.supernews.com> Message-ID: "Edward K. Ream" writes: > Indeed, pep 318 is grossly misleading; PEP 318 has a slightly sorry history. As far as I can remember, it was written as an attempt to promote a specific syntax proposal (the 'as' variant? Maybe, it's not really important). Since then it's been co-opted to be "The Decorators Pep" and received various rounds of rewrites, none of which have pleased everyone (surprised? with this topic). I belive it's fair to say that PEP 318 has *never* accurately reflected the state of play on this issue. This is unfortunate, yes. The idea that the process goes from pep to discussion back to pep to implementation is a nice one, but not really how it happens, for better or worse. Cheers, mwh -- 112. Computer Science is embarrassed by the computer. -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html From mikeb at mitre.org Wed Aug 18 15:50:21 2004 From: mikeb at mitre.org (Mike Brenner) Date: Wed, 18 Aug 2004 15:50:21 -0400 Subject: age of Python programmers Message-ID: <4123B2FD.72E8D730@mitre.org> I was born about 10,000 years ago and I used to program computers made of human beings who were aligned in tiers. The bottom tier counted the grains in the baskets. The next tier counted the baskets in the barn, then the number of brans in each country. From jjl at pobox.com Thu Aug 12 15:44:46 2004 From: jjl at pobox.com (John J. Lee) Date: 12 Aug 2004 20:44:46 +0100 Subject: ClientCookie References: <6f402501.0408110018.1e4e5ca8@posting.google.com> <87llglqp0l.fsf@pobox.com> <6f402501.0408120108.5a8f03ae@posting.google.com> Message-ID: <87zn50gmz5.fsf@pobox.com> fuzzyman at gmail.com (Michael Foord) writes: [...] > At the moment I can't get at the cookies at *all*. Can you see what > I'm doing wrong. > Here's my code (simplified) : [...] > cj = ClientCookie.CookieJar() > req = ClientCookie.Request(theurl, txdata, txheaders) > u = openfun(req) [...] It's not magic! You aren't using cj anywhere! John From kyleroot at gmail.com Sat Aug 7 10:08:37 2004 From: kyleroot at gmail.com (Kyle Root) Date: Sat, 07 Aug 2004 14:08:37 GMT Subject: Questions about parsing XML In-Reply-To: References: <%T4Rc.150$Iv.46@trndny03> Message-ID: Jarek Zgoda wrote: > > > libxml2 (http://www.xmlsoft.org/) has excellent support for XPath, F. > Lundh's ElementTree also supports some XPath expressions, although it is > built on expat and needs to parse whole XML document. > Well I was going to use that, but I remember reading somewhere that xmlib was depreciated or something, even if it has been do you still recommend libxml2 over expat? From justin__devine at hotmail.com Thu Aug 26 12:28:32 2004 From: justin__devine at hotmail.com (Justin) Date: 26 Aug 2004 09:28:32 -0700 Subject: Specific request with code example (encapsulation) __init__ problems In-Reply-To: Message-ID: Thanks I finally got it working. Big help. What's the difference between SetLabel and SetItemLabel. Below is a paste form the wx manual and it didn't contain that function, that's why was confused. It now works but maybe you can help me understand this better. Is SetItemLabel a generic function of wxControl or wxObject. Thanks again wxRadioBox::wxRadioBox wxRadioBox::~wxRadioBox wxRadioBox::Create wxRadioBox::Enable wxRadioBox::FindString wxRadioBox::GetCount wxRadioBox::GetLabel wxRadioBox::GetSelection wxRadioBox::GetStringSelection wxRadioBox::GetString wxRadioBox::Number wxRadioBox::SetLabel wxRadioBox::SetSelection wxRadioBox::SetStringSelection wxRadioBox::Show wxRadioBox::SetLabel void SetLabel(const wxString& label) Sets the radiobox label. void SetLabel(int n, const wxString& label) Sets a label for a radio button. Parameters label - The label to set. n - The zero-based button index. Richie Hindle wrote: > [Justin] > > my problem is now it appears that my widgets are completely > > encapsulated within this __init__ class and I cannot get at them. > > That's not true if you say "self.x = y", as you have done with self.rb in > your posted example. I don't know why your code doesn't work - you seem to > be doing the right thing, and if I modify your Gobblewx_7public_.py to match > your posted example then it all works. > > Here's what I did: I downloaded Gobblewx_7public_.py (a couple of days ago, > when you first mentioned it) changed 'rb' to 'self.rb' throughout the > Gmainpanel.__init__ function (lines 484-493), and added the line: > > self.rb.SetItemLabel(1, "test change") > > as the first line of the yousuredlg function (line 571). When I fill in the > form and hit "Download files", the label changes. > > Note that it's SetItemLabel, not SetLabel, which implies that you never > called your changelabel function, or you didn't look at the resulting > traceback... > > -- > Richie Hindle > richie at entrian.com From thomas.krueger at gmx.net Mon Aug 30 17:34:42 2004 From: thomas.krueger at gmx.net (Thomas =?ISO-8859-1?Q?Kr=FCger?=) Date: Mon, 30 Aug 2004 23:34:42 +0200 Subject: dtml-sendmail References: Message-ID: shashaank wrote: > --snip-- > Send email > > > mailfrom="sales at quietcare.info"> > Subject: Confirming your account. > > > > Sorry, we could not process your email. >

    :

    
    > 

    > > > --snip-- 1. Don't indent the lines of the mail. All header lines must not start with any whitespace character. 2. Using dtml syntax inside a dtml-tag will not work. 3. You need to define the mailhost. example: Subject: Some subject To: From: somebody at somedomain.net Some text! Thomas From anthonybaxter at gmail.com Mon Aug 23 13:17:42 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Tue, 24 Aug 2004 03:17:42 +1000 Subject: __name__ becoming read-write? In-Reply-To: <3b8ki0tlphodtt8ge8an274qp78ihp1i3n@4ax.com> References: <3b8ki0tlphodtt8ge8an274qp78ihp1i3n@4ax.com> Message-ID: On Mon, 23 Aug 2004 17:00:39 GMT, Arthur wrote: > I see the point. > > But.. there is always a but. > > I'm thinking now a special sytnax item in the __form__ at the top of > function that would: > > 1) put one on notice that the function is to be transformed (as in > "see below"). > > 2) allow a name to be assigned to it, which will become the > transform's __name__. This is a bad idea - code inside the function should be executed when the function is executed. docstrings are a special-case (because they're not actually code), but, to be honest, this whole discussion has made me deeply uncomfortable with where the docstrings sit at the moment. Once 2.4 is out, I know I'll probably start using something like: def doc(str): def endoculate(func, str=str): func.__doc__ = str return func @doc('''This function frobulates the meta-whatsit''') def frobulate(metawhatsit): ..... (insert final decorator syntax as required) Paul Morrow's idea of special magic __foo__ inside the function is deeply magical, and not likely to make any new users running across it any happier. "So wait, this stuff that _looks_ like code in a function, isn't actually? what the hell?" The new syntax[1] for decorators is at least very obvious that something _new_ is going on. This has been one of the things I've been using as an internal filter for various syntax proposals for decorators. It should _not_ look like some existing valid python that "just happens" to have a new effect. I'd also prefer that the syntax _not_ be valid python in pre-2.4, in case code accidently gets run under an old interpreter. The decorator usage I have planned will be very very ugly if the decorators _don't_ get applied to the function, for whatever reason. [1] whether @syntax, or block-before-def From ialbert at mailblocks.com Sat Aug 7 19:52:50 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Sat, 07 Aug 2004 19:52:50 -0400 Subject: Image manipulation library under a GPL-compatible license? In-Reply-To: <2nl3suF1vntdU1@uni-berlin.de> References: <2nl3suF1vntdU1@uni-berlin.de> Message-ID: Leif K-Brooks wrote: > I need to do some simple image editing (pretty much just scaling) in a > GPLed program. Unfortunatly, both of the Python libraries for image > editing that I found (gdmodule and PIL) are under the GPL-incompatible > original BSD license. Is there another library under a friendlier library? heh, GPL is a lot less "friendly" than the Python license. Here is the python license: "The gist of it is that Python is absolutely free, even for commercial use (including resale). There is no GNU-like "copyleft" restriction." http://www.python.org/doc/Copyright.html now what part of this is givin you trouble? Istvan. From jorgencederberg at hotmail.com Tue Aug 3 10:05:16 2004 From: jorgencederberg at hotmail.com (=?ISO-8859-1?Q?J=F8rgen_Cederberg?=) Date: Tue, 03 Aug 2004 16:05:16 +0200 Subject: intersection of 2 strings In-Reply-To: References: Message-ID: Antoine Logean wrote: > Hi, > > What is the easiest way to get the intersection of two strings in > python (a kind a "and" operator) ? > ex: > > string_1 = "the_car_of_my_fried_is_bigger_as_mine_but_my_girlfriend_is_more_beautifull" > > string_2 = > "my_girlfriend_is_more_beautifull_and_has_blue_eyes" > > and the intersection : > string_1 "and" string_2 = "my_girlfriend_is_more_beautifull" > > thanks for your help > > Antoine Hi difflib seems to appropiate, http://docs.python.org/lib/module-difflib.html and especially http://docs.python.org/lib/sequence-matcher.html Here is some code that works from difflib import SequenceMatcher s1 = "my_girlfriend_is_a_python" s2 = "my_girlfriend_is_more_beautifull" m = SequenceMatcher(None, s1, s2) print "Matches between: %s and %s" %(s1,s2) for match in m.get_matching_blocks(): i,j,n = match if n>1: # We don't want to match single chars. print s1[i:i+n] HTH Jorgen Cederberg From eurleif at ecritters.biz Fri Aug 27 03:46:47 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Fri, 27 Aug 2004 03:46:47 -0400 Subject: Call for signatories for J2 In-Reply-To: References: Message-ID: <2p86vlFhmko4U1@uni-berlin.de> Robert Brewer wrote: > This is a call for all who wish to sign the proposal, either for, > against, or abstaining. For. Leif K-Brooks. From JSmuts at clover.co.za Tue Aug 31 07:28:52 2004 From: JSmuts at clover.co.za (Jaco Smuts) Date: Tue, 31 Aug 2004 13:28:52 +0200 Subject: Python Usage Statistics In-Reply-To: Message-ID: Don't know about usage statistics, suspect it's not as great as I'd like it to be. I'm sure there's some data available on the average age of python programmers though anandpillai at letterboxes.org (Anand Pillai) Sent by: python-list-bounces+jsmuts=clover.co.za at python.org 08/31/2004 01:22 PM To: python-list at python.org cc: Subject: Python Usage Statistics Hi Folks (posting after a loooong time...) I have been contracted by an Indian publisher to author an introductory text book on Python. As a part of the introductory chapter, I thought it would be a good idea to present a number, a round-about figure on the approximate *actual* usage of Python out there in number of developers and/or installations. Scrounging the Web for such statistics is proving elusive. The PBF website seems to be the official place for these, but there also they just have listings of companies/instituitions using Python, not any numbers. Has anybody done an actual market survey anytime recently on Python usage in the software community? If so, where can I get access to this information? I would be more interested in the number of developers, both commercial/non-commercial who are doing development using Python. Since almost every Linux distro now a days contains Python by default, a number based on the installations could prove faulty. Have a nice day. -Anand -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From zathras at thwackety.com Sun Aug 22 12:47:28 2004 From: zathras at thwackety.com (Michael Sparks) Date: Sun, 22 Aug 2004 17:47:28 +0100 Subject: [PATCH] RE: J2 decorator grammar References: <4128ac0f$0$79299$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <4128d2f1$0$54951$ed2619ec@ptn-nntp-reader02.plus.net> Anthony Baxter wrote: > On Sun, 22 Aug 2004 15:01:39 +0100, Michael Sparks > wrote: >> It should be done sometime this afternoon though. (Bulk of the time taken >> up is on re-running the test suite unsuprisingly) > > One quick point - make sure you run the _full_ test suite (-uall arg > to regrtest, > or 'make testall'), otherwise things like the compiler tests won't get > run. Hmm... Didn't know about that version... Running that now and the following 2 tests fail: * test_bsddb3 * test_ossaudiodev However, these fail for me when using a vanilla 2.4a2 so whilst not ideal these failures (probably) aren't due to my changes. Everything else passes. My next steps are this: * Change keyword * Do short/simple/single line form * Produce patch for CVS version. Regards, Michael. From PeterAbel at gmx.net Tue Aug 3 17:48:34 2004 From: PeterAbel at gmx.net (Peter Abel) Date: 3 Aug 2004 14:48:34 -0700 Subject: intersection of 2 strings References: Message-ID: <21064255.0408031348.634de20f@posting.google.com> al at biolinux.ch (Antoine Logean) wrote in message news:... > Hi, > > What is the easiest way to get the intersection of two strings in > python (a kind a "and" operator) ? > ex: > > string_1 = "the_car_of_my_fried_is_bigger_as_mine_but_my_girlfriend_is_more_beautifull" > > string_2 = > "my_girlfriend_is_more_beautifull_and_has_blue_eyes" > > and the intersection : > string_1 "and" string_2 = "my_girlfriend_is_more_beautifull" > > thanks for your help > > Antoine If you take J?rgen Cederberg's solution you can inherit from str and create your own "&" operator. >>> class mystring(str): ... def __and__(self,other): ... m = SequenceMatcher(None, self, other) ... equals=[] ... for (i,j,n) in m.get_matching_blocks(): ... if n>1: ... equals.append(self[i:i+n]) ... return equals ... >>> s1=mystring(string_1) >>> s1 & string_2 ['my_girlfriend_is_more_beautifull'] Regrads Peter From cookedm+news at physics.mcmaster.ca Tue Aug 17 18:01:42 2004 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Tue, 17 Aug 2004 18:01:42 -0400 Subject: flex: plex? References: Message-ID: At some point, Peter Kleiweg wrote: > Hi, > > I am looking for a Python equivalent of Flex. After some > browsing, it seems that Plex is my best bet, but I would like to > hear suggestions before I dive in. > > I have been using Flex a lot in combination with C programming. > I never use Yacc (or Bison), though Flex and Yacc are supposed > to be used together. But I found Yacc too cumbersome, and > unnecessary. Yacc is about context-free grammars, nice if you > like to describe an input language as a set of context-free > rewrite rules. Flex is about finite-state automata, but can be > extended to push-down automata (equivalent to context-free > grammars) and beyond, as long as it stays deterministic. I found > this to be very productive. I prefer automata over rewrite rules. If you've been using Flex, you might want to check out FlexModule at which allows you to use Flex to generate a lexer callable from python. -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From davidf at sjsoft.com Thu Aug 19 15:35:46 2004 From: davidf at sjsoft.com (David Fraser) Date: Thu, 19 Aug 2004 21:35:46 +0200 Subject: Py2Exe PROBLEM In-Reply-To: <81a41dd.0408191109.1fc98889@posting.google.com> References: <81a41dd.0408190023.44d34c44@posting.google.com> <2tGdncgUvpKRD7ncRVn-oQ@powergate.ca> <81a41dd.0408191109.1fc98889@posting.google.com> Message-ID: Lad wrote: > Peter Hansen wrote in message news:<2tGdncgUvpKRD7ncRVn-oQ at powergate.ca>... > >>Lad wrote: >> >> >>>I try to make an exe file from my script with help of Py2exe but I am >>>not successfull. >> >> ... >> >>>When compilation finishes I get: >>> >>>The following modules appear to be missing >>>['blackbox', 'timing', 'rgs.py'] >>> >>>Can you please help me how to solve the problem? >> >>If you explain what problem you are actually having. >> >>Are you assuming simply because of that warning message that >>it didn't work? What happens when you try to run the resulting >>.exe file? >> >>Note that py2exe will sometimes complain about modules that >>are not actually required for the program to run. >> >>Also please explain what "blackbox" and "timing" are, if >>they are part of the problem. >> >>Finally (and this might be the whole problem), you seem >>to be using "import rgs.py" when you really meant to use >>just "import rgs". You don't import Python modules using >>the full filename of the source file... >> >>-Peter > > > Dear Peter, > Thank you for your help. > Yes, I changed import rgs.py to import rgs but I still receive > >>The following modules appear to be missing > >>>['blackbox', 'timing', 'rgs.py'] > > > When I try to start the exe file I get > > Traceback (most recent call last): > File "rgs.pyc", line 561, in OnFileHistory > > File "pickle.pyc", line 1390, in load > File "pickle.pyc", line 872, in load > File "pickle.pyc", line 985, in load_string > LookupError: unknown encoding: string-escape > > Can you please help again? > Lad You need to add "encodings" to the list of packages that you manually include (the option is called packages I think) - see the py2exe wiki David From anthonybaxter at gmail.com Thu Aug 5 14:02:47 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 04:02:47 +1000 Subject: Confused about pep 318 In-Reply-To: <10h4s026oapbhf1@corp.supernews.com> References: <10h2ihgb8c6fi97@corp.supernews.com> <10h4s026oapbhf1@corp.supernews.com> Message-ID: On Thu, 5 Aug 2004 12:35:57 -0500, Edward K. Ream wrote: > I could not disagree more. Pretending that discussions on py-dev and > SourceForge count as truly public discussions of pep 318 is most unwise. > pep 318 does not discuss '@' at all. People like me, with a strong interest > in how Python uses '@', would not naturally have known about the proposed > new syntax until the stuff hit the fan. Sorry, but if discussions on python-dev are not considered "public", what is? It's an open list, with publically available archives. Expecting the python-dev team to read all of comp.lang.python is foolish - most of us have very little spare time as it is. For instance, I usually only follow the list immediately after a release. I have no time to wade through the hundreds of posts a day on a regular basis. Indeed, I'm currently up way way too late at night to participate in this discussion, because the chances are I'll have no time tomorrow to do so. > Indeed, pep 318 is grossly misleading; reading it one gets the distinct > impression that the design is far from complete. It is my strong opinion > that _no_ public discussion of this new code has taken place, and none _can_ > take place until we see what it is exactly that is being proposed. See above. Exactly how is a public mailing list with an open subscription policy, no limitations on who can post, and with web searchable archives, not public. And if you think there hasn't been discussion on this matter, you obviously haven't even bothered to look at the archives. There has been a overwhelming amount of discussion on this. > This is > an issue of basic fairness and openness. I have complained loudly to the > [B]DFL. We shall see... Fariness and openness? This isn't a debating club! As far as fairness - well, after all the discussions were had, Guido made a judgment call. That's what he does. Python, thank the gods, is not designed by some system of voting and the like. To summarise: As I've stated already, I'm aware that PEP 318 needs an update. If no-one else gets it done before next week, I will have time to work on it again. If one of the people complaining about it wants to sit down and trawl the (literally) hundreds and hundreds of python-dev messages, spread over the last 2+ years, and extract the relevant posts, that would be excellent! If you're only going to sit and bitch about it, well, I can spend my time better trawling the archives. PEP 318 _will_ be updated and complete before 2.4 final is done - it's on my list as a blocker for the final. Ideally (and I plan for this) it will be done before a3. Anthony From in.aqua.scribis at nl.invalid Sun Aug 29 10:09:09 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Sun, 29 Aug 2004 16:09:09 +0200 Subject: Announcing PyCs, a new Python-like language on .Net In-Reply-To: <1093788608.645541@news.commspeed.net> References: <1093788608.645541@news.commspeed.net> Message-ID: Tom B. schreef: > > "Mark Hahn" wrote in message > news:mailman.2572.1093751093.5135.python-list at python.org... > > Please join the PyCs team. The only effort involved is particpating in a > > low-traffic, high-content, mailing list. You will be able to influence > the > > design of the latest and greatest dynamic language. > > > > -- Mark Hahn, http://pycs.org > > > > Python already does all the things that M*soft has tacked on in a kludgy > way, in a beautiful pythonic way. I have been using windows based machines > for a long time and in the language department (as well as others) M*soft > has been superceded by the open source community. Is there a real danger that MS will make its own version of Python, pushing it into the market, and we end up with a dominant version that only works with MS software? -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html The Halloween Documents: http://www.opensource.org/halloween/ From bokr at oz.net Mon Aug 9 12:09:33 2004 From: bokr at oz.net (Bengt Richter) Date: 9 Aug 2004 16:09:33 GMT Subject: Maybe, just maybe @decorator syntax is ok after all References: Message-ID: On 9 Aug 2004 07:07:54 -0700, artur_spruce at yahoo.com (AdSR) wrote: >artur_spruce at yahoo.com (AdSR) wrote in message news:... >> >> @dec1 >> @dec2 >> def foo(): >> pass >> >> >> >> and after the second: >> >> def foo(): >> pass >> >> foo = dec2(foo) >> >> foo = dec1(foo) > >The latter is equivalent to: > >def foo(): > pass >foo = dec1(dec2(foo)) > >But I've just noticed that the spec says: > >""" >@f1 >@f2 >def func(): pass > >is equivalent to: > >def func(): pass >func = f2(f1(func)) >""" > >So the order is reverse, which breaks my previous interpretation. Oh, well... > I think your example is not from the PEP. What "spec" are you citing? Note the order in the example cut and pasted from the current (Last-Modified: 2004/08/06 18:34:15) pep 318: ---- The current syntax for function decorators as implemented in Python 2.4a2 is: @dec2 @dec1 def func(arg1, arg2, ...): pass This is equivalent to: def func(arg1, arg2, ...): pass func = dec2(dec1(func)) ---- Regards, Bengt Richter From scott.b.drummonds.nospam at intel.com Wed Aug 11 16:29:21 2004 From: scott.b.drummonds.nospam at intel.com (Scott Brady Drummonds) Date: Wed, 11 Aug 2004 13:29:21 -0700 Subject: 'break' Causes Execution of Procedure? References: <10hkq3u54ht2h4e@corp.supernews.com> Message-ID: "Jeff Shannon" wrote in message news:10hkq3u54ht2h4e at corp.supernews.com... > I suspect that the answer is in the context of the for loop. Try > posting a bit more of the surrounding code. (For example, it's not at > all clear how your loop relates to the main() snippet that you posted...) Sorry. I know that it's better to post actual failing code is much better than snippets for exactly this reason. However, there is so much code that I believe to be superfluous to this problem that I really wanted to make the post simpler. To answer your question, the loop that I posted occurred in the main() loop. That is, calling 'break' inside this loop resulted in a call to the function that 'break' was called in (which happens to be main()). > Actually, I'm wondering why you catch the exception inside the loop, and > then exit the loop. If you wrapped that entire loop in the try/except, > then you wouldn't need to worry about using break -- an exception would > end the loop and *then* get dealt with. After reading your suggestion, I'm wondering why I caught the exception in the loop as opposed to outside of the loop. I changed the implementation as you suggested and my program is now working correctly. Of course, something tells me that I just covered up a bug as opposed to removing it. Scott -- Remove .nospam from my e-mail address to mail me. From peter at engcorp.com Tue Aug 31 14:36:52 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 31 Aug 2004 14:36:52 -0400 Subject: "Content-Length" header In-Reply-To: References: <96c2e938.0408302057.61df147b@posting.google.com> Message-ID: <0LadnRdAsPfbWKncRVn-ug@powergate.ca> Peter Kleiweg wrote: > Jeremy Bowers schreef: >>Both cases: 52 ^ 8: 53,459,728,531,456 (53 trillion) > > A bit less: 53 billion > >>One case : 26 ^ 8: 208,827,064,576 (208 billion) > > 208 billiard North American English says twelve zeroes is a trillion, and nine zeroes is a billion, and the word "billiard" refers to a game involving the use of a stick to hit a white ball into other balls on a table covered with green felt... (And I'm not sure "billiard" refers to numbers in any other form of English either, but certainly "milliard" exists in Britain and means a thousand million (nine zeroes).) -Peter From fuzzyman at gmail.com Mon Aug 23 03:23:35 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 23 Aug 2004 00:23:35 -0700 Subject: XMLObject - problem with recursive definitions Message-ID: <6f402501.0408222323.5fd81b2a@posting.google.com> I've been using the excellent XMLObject and have unfortunately come up against what *looks* to me like a bug - although it's very possible that the problem is mine !! I want to use XML object to create an XML structure that represents the contents of a directory structure. I call it a DirObj. Each DirObj needs a list node that can itself contaibn several more DirObj - effectively a 'recursive' definition. It looks something like this : class XMLDirObj(XMLObject): """An XMLObject version of a DirObj.""" attrs = ItemNode('DirAttributes') files = ListNode('XMLFileObj') dirs = ListNode('XMLDirObj') A DirAttributes object is an object representing the set of attributes of the directory, an XMLFileObj is an object representing the set of attributes of each file in the directory. Unfortunately when I use the toXml and then the (classmethod) fromXml it mangles the values. (on the read). I've written a small test script with the simplest possible recursive use of XMLObject and it doesn't appear to work. I wondered if this was actually a bug - or whether I was doing something wrong. My test script is below and from the sample output you'll see the error and the assert failure at the bottom. The first print is ok (toXml) - but then it reads it incorrectly (the second print). Ouput : Traceback (most recent call last): File "D:\Python Projects\dirwatcher\rec_test.py", line 67, in ? assert thestuff == thestuff2 AssertionError #################### """ rec_test.py Demonstrates that recursion fails using XMLObject :-( """ from XMLObject import * ######################################################################## class Thing(XMLObject): place = ItemNode('Anotherthing') anotherplace = ListNode('Thing') abit = CDATAttribute(optional=True) class Anotherthing(XMLObject): abit = CDATAttribute(optional=True) ######################################################################## # Test Function if __name__=='__main__': test1 = Thing() test1.abit = 'Hello My Friend' athing = Anotherthing() athing.abit = 'Yo' test1.place = athing test2 = Thing() test2.abit = 'Recursion Test' athing2 = Anotherthing() athing2.abit = 'Yo Again' test2.place = athing2 test1.anotherplace.append(test2) thestuff = test1.toXml() print thestuff testobj = Thing.fromXml(thestuff) thestuff2 = testobj.toXml() print print print thestuff2 assert thestuff == thestuff2 ##################################### If anyone can see what I've done wrong it would be much appreciated. (I've emailed the author - but as it's probably my fault I thought I'd post here as well). Regards, Fuzzy -- http://www.Voidspace.org.uk The Place where headspace meets cyberspace. Online resource site - covering science, technology, computing, cyberpunk, psychology, spirituality, fiction and more. --- http://www.Voidspace.org.uk/atlantibots/pythonutils.html Python utilities, modules and apps. Including Nanagram, Dirwatcher and more. --- http://www.fuchsiashockz.co.uk http://groups.yahoo.com/group/void-shockz --- Everyone has talent. What is rare is the courage to follow talent to the dark place where it leads. -Erica Jong Ambition is a poor excuse for not having sense enough to be lazy. -Milan Kundera From pm_mon at yahoo.com Mon Aug 30 07:35:50 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Mon, 30 Aug 2004 07:35:50 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Anthony Baxter wrote: > On Sun, 29 Aug 2004 13:34:52 -0400, Paul Morrow wrote: > >>>Have you seen a significant number of cases where a function uses >>>__xxx__ attributes as local variables? Have you seen any? > > > Locals, no. But builtins, yes. For instance, __import__. > > So your proposal suddently has to deal with looking up _only_ locals, > not globals or builtins. > > I have asked this indirectly, and Jeff Epler's asked it more > obviously, so, to restate it: > > Have you actually got a concrete, written down proposal? Have you > worked through how it might work, and what the impact on the language > might be? I was hoping that you'd sit down and do what Bengt Richter > did and posted to the newsgroup - worked out how this stuff works, > under the hood, so that you weren't just hand-waving. Oh well. Where would I put such a proposal? Post it here? And would it need to include an implementation? I'm new to the bowels of the Python system, plus I've got a big project due this time next week, so it would be next week before I could really dig into something like that. I guess I'm just a hand-waiver for now. Paul From h.b.furuseth at usit.uio.no Mon Aug 23 10:50:22 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 23 Aug 2004 16:50:22 +0200 Subject: __name__ becoming read-write? References: Message-ID: Arthur wrote: > Did I hallucinate something about __name__ becoming read-write? _Becoming_ read-write? When was it read-only? Python 1.5.2 (#1, Jul 14 2004, 20:34:28) [GCC 3.2.3] on sunos5 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> class foo: pass ... >>> foo.__name__ = 'bar' >>> foo.__module__ = 'baz' >>> foo -- Hallvard From peter at engcorp.com Thu Aug 26 02:18:44 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 26 Aug 2004 02:18:44 -0400 Subject: age of Python programmers In-Reply-To: References: <20040819231139.D039A1E4003@bag.python.org> <5cf809e9.0408241126.6e3fdd5b@posting.google.com> <8ecda57b.0408251754.14ed27b9@posting.google.com> Message-ID: Jonathan Daugherty wrote: > # Started programming 'real' computers starting ... > # win anything if you answer correctly :) > > Is it just me or are these posts getting off-topic? :) It's just you. :-) For myself, I'm finding the personal sharing fascinating, and keep seeing hints of myself (or at least my past) in others. What a cool bunch of geeks, eh? ;-) -Peter From peter at engcorp.com Thu Aug 26 02:17:19 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 26 Aug 2004 02:17:19 -0400 Subject: Best processor (i386) for Python performance? In-Reply-To: <789f72ac.0408251950.e85d23e@posting.google.com> References: <789f72ac.0408251950.e85d23e@posting.google.com> Message-ID: Tom Locke wrote: > I'd be grateful if anyone could provide insight into choosing a good > i386 processor for Python performance. > > Are any of the following of particular importance, or less relevant, > with respect to Python? > > Raw clock speed? > Cache size? > Bus speed? > Intel's Hyperthreading? > AMD's 64 bits? > > What about a dual processor? Can multithreaded Python take advantage > of this? Is it stable? I don't think anyone has yet studied this issue extensively. Please buy one of each and let us know which one was fastest. ;-) -Peter From ben at benlast.com Tue Aug 17 10:40:50 2004 From: ben at benlast.com (Ben Last) Date: Tue, 17 Aug 2004 15:40:50 +0100 Subject: How big can a Python program be? In-Reply-To: Message-ID: > From: python-list-bounces+ben=benlast.com at python.org > [mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of > Peter Hansen > In any case, the difficulty with writing infinitely sized > programs is that your day to day productivity, relative > to the size of the task at hand, is always zero... And the ratio of documentation to lines of code is always zero also :) On the other hand, if you work for somewhere that still believes lines-of-code-over-time is a good metric, you could be in for one heck of a bonus... b From ptmcg at austin.rr._bogus_.com Mon Aug 16 09:54:12 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 16 Aug 2004 13:54:12 GMT Subject: COM (DispatchEx) problem References: Message-ID: <803Uc.14565$MD.3310@fe1.texas.rr.com> "Leszek" wrote in message news:cfpqlu$nb6$1 at nemesis.news.tpi.pl... > Hi everybody ! > > I'm starting my script with: > > ie = win32com.client.DispatchEx("InternetExplorer.Application") > ie.Visible = 1 > ie.Navigate("http://www.chip.pl") > > while ie.Busy == True: > win32api.Sleep(1000) > > doc = ie.document > > then I make "submit" and new page opens. > but > > print doc.body.innerHtml > > gives the same Html code than before "submit". What is going on ? How to see > new document ? > > Thanks for any help. > > Leszek > If you are just trying to get at the HTML source for a given URL, use urllib or urllib2. Here's the code to get the HTML source for yahoo.com: import urllib serverListPage = urllib.urlopen( "http://www.yahoo.com" ) htmlSource = serverListPage.read() serverListPage.close() Bypasses the whole COM and IE mess, and it's portable, to boot! -- Paul From abra9823 at mail.usyd.edu.au Sat Aug 14 09:06:01 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Sat, 14 Aug 2004 23:06:01 +1000 Subject: xml question Message-ID: <1092488761.411e0e39ae122@www-mail.usyd.edu.au> hi! i am trying to remove all whitespace elements out of a document. my code is below def stripWhiteSpaces(doc): whiteSpaces = xpath.Evaluate("//text()", doc.documentElement) counter=0 while(counter< len(whiteSpaces)): str = whiteSpaces[counter].nodeValue string.strip(str) if len(str) == 0: whiteSpaces[counter].parentNode.removeChild(whiteSpaces[counter]) counter += 1 return doc however this isn't working. when i print out all the elements in the document, i still get the whitespace text elements. what am i doing wrong? thanks cheers ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From amartin at wpsnetwork.com Fri Aug 20 12:41:08 2004 From: amartin at wpsnetwork.com (Aurelio Martin Massoni) Date: Fri, 20 Aug 2004 18:41:08 +0200 Subject: pyXLWriter - simple example code ? In-Reply-To: <282f826a.0408192035.32687e48@posting.google.com> References: <282f826a.0408192035.32687e48@posting.google.com> Message-ID: <2omnt7FcdpspU1@uni-berlin.de> Richard Shea wrote: > Hi - Anyone out there who has a simple example using pyXLWriter > (http://sourceforge.net/projects/pyxlwriter/) they are willing to > share with the group ? > > I'm interested in creating a .XLS which has multiple sheets within the > workbook but I'm having real trouble getting started, I can create a > Worksheet but can't figure out how to save it. > > thanks > > richard shea. ######################################################################## import pyXLWriter wb = pyXLWriter.Workbook( 'test.xls' ) ws1 = wb.add_worksheet( 'First' ) ws2 = wb.add_worksheet( 'Second' ) ws1.write( "A1", "January" ) ws1.write( "A2", "February" ) ws1.write( "A3", "March" ) ws1.write( "B1", 1.25 ) ws1.write( "B2", 2.50 ) ws1.write( "B3", 1.80 ) wb.close() ######################################################################## Hope this helps Aurelio From mhuening at zedat.fu-berlin.de Tue Aug 17 03:51:56 2004 From: mhuening at zedat.fu-berlin.de (Matthias Huening) Date: 17 Aug 2004 07:51:56 GMT Subject: how to display unicode in a Label in Tkinter References: <8f17f4bc.0408151819.c06a79e@posting.google.com> <8f17f4bc.0408161437.2f557935@posting.google.com> Message-ID: alikakakhel3 at hotmail.com (Ali) wrote in news:8f17f4bc.0408161437.2f557935 at posting.google.com: > Eric Brunel wrote in message > news:... >> Ali wrote: >> > I was wondering how one would go about displaying unicode in a >> > Label object in a Tkinter window. I am trying to display text in >> > another language. Please help. >> >> Just put it in a Unicode string or in a raw string encoded in UTF-8 >> and you should be going: >> >> >>> from Tkinter import * >> >>> root = Tk() >> >>> s = '????: ?a marche!' >> >>> u = unicode(s, 'iso8859-1') >> >>> Label(root, text=u).pack() >> >> (The code above supposes your default encoding is iso8859-1, a.k.a >> latin-1; otherwise, you can do: s = '\xe0\xe9\xe8\xf9: \xe7a >> marche!') >> >> HTH > > So how I write in Arabic? For Arabic you'll probably use Unicode (in which case you can just use the text in Tkinter) or you'll have tekst encoded as 'iso8859-6'. Then you have to use something like: >>> u = unicode(s, 'iso8859-6') Hope this helps. Matthias From timr at probo.com Fri Aug 20 00:19:51 2004 From: timr at probo.com (Tim Roberts) Date: Thu, 19 Aug 2004 21:19:51 -0700 Subject: My only complaint about Python References: Message-ID: <1uuai0l4k13g9gtv55fe7hh2c8io8grr3a@4ax.com> Darren Dale wrote: > >.... As a scientist funded by the NSF, I feel compelled to >do all my work using free software (I feel compelled to use free >software, regardless). Then what on Earth are you doing with Windows? -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From evenprimes at gmail.com Fri Aug 6 15:18:54 2004 From: evenprimes at gmail.com (Chris Cioffi) Date: Fri, 6 Aug 2004 15:18:54 -0400 Subject: RELEASED Python 2.4, alpha 2 In-Reply-To: <200408051851.08457.heikowu@ceosg.de> References: <411231C8.3020308@interlink.com.au> <200408051851.08457.heikowu@ceosg.de> Message-ID: Thank you for this example Heiko. I wasn't really clear on what the blazes decorators were, let alone why different syntaxes were being suggested. Now that I'm at least registering on the clue-meter (just a little, mind) I think the propsed syntax is fine. It's only going to be used at the function definition level, and its form makes you pay attention that something odd is going on here. My first reaction was that Python was turning into Perl. Now I think it's good that the syntax is a little jarring and discordant. I think most people won't use function decorators very often so slapping us in the face when it does happen is the visual clue we need to pay closer attention. Chris On Thu, 5 Aug 2004 18:51:08 +0200, Heiko Wundram wrote: [snip] > > I don't think they try to solve all the things you state. Rather, it's only > about general function mangling at compile time. Whatever you need to do for > function mangling, that's up to you. > > And, at least for me, as I stated elsewhere, the syntax is just fine. I've > tried it out yesterday, porting some code to 2.4a2 which used thread locks > extensively, and just writing a little class InstanceSynchronizer() which is > just a Class which defines __call__ (when decorating a function) and gets the > first parameter from the function call to acquire an instance specific lock > is certainly the right way to go. [snip] -- Still searching for an even prime > 2! From jradclif at math.unl.edu Wed Aug 25 14:42:36 2004 From: jradclif at math.unl.edu (Jamie Radcliffe) Date: Wed, 25 Aug 2004 13:42:36 -0500 Subject: Call for signatories for J2 In-Reply-To: References: Message-ID: A newbie votes FOR. Jamie Radcliffe From ialbert at mailblocks.com Thu Aug 5 16:58:07 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Thu, 05 Aug 2004 16:58:07 -0400 Subject: Decorator syntax In-Reply-To: References: Message-ID: Mark 'Kamikaze' Hughes wrote: > class foo: > def introduceNewFeature(self, someArgument, anotherArgument): [synchronized, types="o,i,i"] > pass # whatever Those who need argument type-checking should go to Guido and talk to him about it. Piggybacking this in as decorators makes everybody lose. > 3) A large proportion of Python programmers are also Java programmers, > and won't object to the @-syntax. yay. love is in the air. Istvan. From del at mjclift.freeserve.co.uk Fri Aug 6 18:20:37 2004 From: del at mjclift.freeserve.co.uk (Calvin79) Date: Fri, 06 Aug 2004 18:20:37 -0400 Subject: random from an array Message-ID: Hi All, I've just started to try python so forgive the ignorance! I've been using this, or something like it; First = random.choice ('abc') answer = first print answer - no problems there. What I want to do, however, is take a random pick from something like the following; First = random.??? ("rna", "rnb", "rnc") - this of course "random.choice" doesn't work. Could some kind person help me out with the code? I know I'm trying to run before I can walk, but there you go... Thanks, Calvin From sbabbitt at commspeed.net Sun Aug 29 13:01:04 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Sun, 29 Aug 2004 10:01:04 -0700 Subject: os.walk: Get entire path References: Message-ID: <1093799393.448803@news.commspeed.net> "Florian Lindner" wrote in message news:cgssom$hu6$00$1 at news.t-online.com... > Hello, > when I'm walking through a file system hierarchy using os.walk, how can I > get the full path of a file or dir? normpath and abspath don't work. > Thx, > Florian I would use glob import glob glob.glob('c:\\images\\*\\*.jpg') yields all .jpg's in //images and sub directories with full path in a list. Tom From ben at benlast.com Mon Aug 16 07:38:20 2004 From: ben at benlast.com (Ben Last) Date: Mon, 16 Aug 2004 12:38:20 +0100 Subject: sys.stdin.read() replacement In-Reply-To: <412091C3.4000609@draigBrady.com> Message-ID: import readline will work on Windows: a) if you're running the cygwin python, inside cygwin b) if you've installed a readline module; there are at least two available. Excuse me for the self-referential answer, but about half and hour before I read this, I wrote a blog entry all about readline modules, with links to and comments about the Windows ones. The permalink is http://www.livejournal.com/users/benlast/16766.html or it's the most recent entry at http://www.livejournal.com/users/benlast/ Karin: if you do import a readline, you can then use sys.stdin.readline() to read a line of input, and you should get some sort of history functionality (up-arrow, for example, will recall a previous line). regards b > -----Original Message----- > From: python-list-bounces+ben=benlast.com at python.org > [mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of > P at draigBrady.com > Sent: 16 August 2004 11:52 > To: python-list at python.org > Subject: Re: sys.stdin.read() replacement > > > Karin Lagesen wrote: > > I am writing a small write-logfile script for use on the > terminal. I have here > > a section where the user should be able to type in several > lines. I have solved > > it so far by using sys.stdin.read(), which makes it possible to > type in several > > lines (separated by enter) and then terminate the session by > typing ^D. This is > > all very good. However, with this it is only possible to edit > the line you are > > in. If you spot an error further up in your text, you cannot > get at it. Do any > > of you know of a way I can do this? > > > import readline > > (I don't know if it works on windos) > > P?draig. > -- > http://mail.python.org/mailman/listinfo/python-list From rkern at ucsd.edu Mon Aug 2 14:52:35 2004 From: rkern at ucsd.edu (Robert Kern) Date: Mon, 02 Aug 2004 13:52:35 -0500 Subject: Starkiller? In-Reply-To: <278de0e.0408020648.6d187aff@posting.google.com> References: <278de0e.0408020648.6d187aff@posting.google.com> Message-ID: Neuruss wrote: > Does anyone have news about Starkiller? I met Michael Salib recently, and he said it will be available shortly (maybe a month or two? I forget). The runtime will be BSD licensed and the application itself will be GPL. -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From whereU at now.com Sat Aug 14 04:27:28 2004 From: whereU at now.com (Eric Pederson) Date: Sat, 14 Aug 2004 00:27:28 -0800 Subject: Python indentation deters newbies? Message-ID: <20040814002728.382239140.whereU@now.com> Dennis Lee Bieber wrote: > A source line is limited to 80 characters > Statements start in column 7 > Statements end in column 72 (or was it 71) > Columns 73 (72) through 80 can be used for an option sequence > number > If a statement is too long for one line, you put a continuation > mark character (any character can be used) in column 6 of the next line, > then continue with the statement > Put a "C" in column 1 to start a comment line > The target of GOTO, IF, and DO loops is identified by a numeric > label. > Labels are up to 5 digits long, located in columns 1 to 5 > > Oh, and within a statement, white space is ignored -- the > following are the same statement: > > circum = 2.0 * radius * PI > c irc um=2 . 0*r ad i u s*P I > > And one the following is an assignment, the other is the > beginning of a DO loop: > > do 10 i = 3. 14159 > do10i = 3,14159 Am I the only one who gets nostalgic from this? I mean them were the days, when code was really |in code| TIP: And if your VW won't start you take a business card and run it between the ignition points to clean them off. I always felt I should be able to visually scan the holes in the punch cards and instantly see the logic (and bugs...) And now, well, what the h____ is an object? Eric Pederson http://www.songzilla.blogspot.com ::::::::::::::::::::::::::::::::::: domainNot="@something.com" domainIs=domainNot.replace("s","z") ePrefix="".join([chr(ord(x)+1) for x in "do"]) mailMeAt=ePrefix+domainIs ::::::::::::::::::::::::::::::::::: From lbates at swamisoft.com Mon Aug 2 19:20:50 2004 From: lbates at swamisoft.com (Larry Bates) Date: Mon, 2 Aug 2004 18:20:50 -0500 Subject: flowcharting is automatic for Python via preprocessor References: Message-ID: Small changes eliminate the need for flow diagram (IMHO). def f(): """Demonstration of flow diagrams.""" for i in range(100): r=i % 3 if r == 2: print 'Remainder two, stopping loop' break if r == 1: if i < 10: print 'Less than ten' else: print 'Greater than ten' continue print 'Multiple of three' While I realize your example function was just that and example (because you could never even get to some of the branches because it exits when i=5). I see a lot of code with nested if/elif constructs that are unnecessary which add to the difficulty of "deciphering" what is going on. Larry Bates Syscon, Inc. wrote in message news:mailman.1069.1091487166.5135.python-list at python.org... > > I like your idea. > > It is easy to get lost inside in eg a multiply nested if statement in a couple > multiply nested for loops, inside a try block. > > Sometimes one can split such code into separate functions, and this makes the > code cleaner. Sometimes not. > > However, the real issue is how the eye parses code. > > It's really inefficient to scan a whole page of code line by line to understand > where loops, branches, continues, and breaks occur. > > I think your visual diagrams could help, if they are: > > 1. Semantically cleaner. > IMO, there is too much detail in the flow diagrams. > (See http://www.getcet.org/images/ex3.png). > > A minimal amount of detail is easier to parse with the eye. > > See http://oregonstate.edu/~barnesc/temp/flow.pdf for a cleaner > example I came up with. This doesn't have arrows all over the > place (and hence may not be a flow diagram), but it does help > point out the relevant control structures. > > 2. Integrated into a code editor. > > I could see this being a new code editor fad, like collapsable > functions and classes. > > It could be quite useful, if the amount of visual information > is kept minimal, so that the coder is not distracted during > coding. > > If the flow diagrams are not integrated into an editor, I don't > think many coders will use them. > > Perhaps editors already do this. > > - Connelly From robin at alldunn.com Sat Aug 14 04:30:19 2004 From: robin at alldunn.com (Robin Dunn) Date: Sat, 14 Aug 2004 01:30:19 -0700 Subject: ANN: wxPython 2.5.2.7 Message-ID: <411DCD9B.30108@alldunn.com> Announcing ---------- I'm pleased to announce the 2.5.2.7 release of wxPython, now available for download at http://wxpython.org/download.php or https://sourceforge.net/project/showfiles.php?group_id=10718&package_id=10559&release_id=260444 What is wxPython? ----------------- wxPython is a GUI toolkit for the Python programming language. It allows Python programmers to create programs with a robust, highly functional graphical user interface, simply and easily. It is implemented as a Python extension module that wraps the popular wxWidgets cross platform GUI library, which is written in C++. wxPython is a cross-platform toolkit. This means that the same program will usually run on multiple platforms without modifications. Currently supported platforms are 32-bit Microsoft Windows, most Linux or other Unix-like systems using GTK or GTK2, and Apple Macintosh OS X. Changes in 2.5.2.7 ------------------ The changes in this version are too numerous to list here, please see the following web sites for more details. If you are upgrading from a previous version then please do read the MigrationGuide fully before getting started as there are some backwards incompatible changes. http://wxpython.org/recentchanges.php http://wxpython.org/migrationguide.php New Docs -------- Also available with this release is a sneak peak at the work in progress for the new Python-specific reference documentation. While much of the content is not yet present, the docs are still usable, and in fact helpful since they already accurately document what classes and methods are present in wxPython and what the parameter names are. You can download a tarball containing the new docs by following the wxPythonNewDocs link on the download page, and it can also be accessed online at http://wxPython.org/docs/api/. -- Robin Dunn Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython! From __peter__ at web.de Sun Aug 15 05:58:41 2004 From: __peter__ at web.de (Peter Otten) Date: Sun, 15 Aug 2004 11:58:41 +0200 Subject: Tkinter buttons with image ? References: Message-ID: kowald at molgen.mpg.de wrote: > I'm just getting into Tkinter and try to create a button that displays an > image instead of text. I do something like: > >>tmp = PhotoImage(file='start.gif') >>buttonStart = Button(frameWb,image=tmp,command=root.quit) > > The button now displays a blank (grey) area of the size of the image, but > as I said, it is blank :-(. > > Any idea what I'm doing wrong ? Using the image in Tkinter will not keep it from being garbage-collected. You need to keep a reference to the image, either in a global variable or like so: buttonStart = Button(frameWb, image=tmp, command=root.quit) buttonStart.image = tmp Peter From mdrop1 at yahoo.com Mon Aug 30 19:55:10 2004 From: mdrop1 at yahoo.com (Message Drop Box) Date: 30 Aug 2004 16:55:10 -0700 Subject: The voodoo of zip(*someList) References: Message-ID: Thank you all very much. Jacek Generowicz wrote > > I've never seen the star '*' outside of function/method definitions > > It can also be used in function invocations, where it means pretty > much the reverse of what it means in function definitions. > > In a parameter list "*foo" means "collect remaining positional > arguments into a sequence (tuple) called 'foo'". In an argument list, > it means "take the sequence 'foo' and expand it into a set of > positional arguments". > > You can "reverse" the **kwds syntax in the same way too. > > > and I've looked in the Python documentation without success. > > Try page 39 of the Python Reference Manual. From aranders at insightbb.com Sat Aug 7 01:38:55 2004 From: aranders at insightbb.com (Alan Anderson) Date: 6 Aug 2004 22:38:55 -0700 Subject: RELEASED Python 2.4, alpha 2 References: <411231C8.3020308@interlink.com.au> <2-SdnZCwNs1SwI_cRVn-uQ@powergate.ca> Message-ID: <53449fcb.0408062138.68a1c196@posting.google.com> Peter Hansen wrote: > Yes, of course after using them for a while they will become more > readable, but there are people who have learned to speak Klingon as > well -- and that doesn't change the fact that Klingon is deliberately > very difficult to learn and awkward. Pardon me for jumping in, but I happen to be attending a conference on the Klingon language at the moment and I wanted to correct a misunderstanding. Yes, Klingon is deliberately "alien", being intentionally created to be unlike many natural languages in many ways. But it's actually rather easy to learn, and it's only "awkward" in a couple of minor ways (embedding comparatives in larger sentences, for example) -- *every* language has its awkward spots. Were Klingon a natural language, its regularity would be exceptional. This is just an anectodal data point that might let you know that what is difficult and awkward from your point of view could very well be simple and straightforward for others who don't share your preconceptions. -- Alan Anderson, professional programmer and amateur Klingonist proud member of the Klingon Language Institute since 1995 qo'mey poSmoH Hol -- language opens worlds -- http://www.kli.org/ From tjreedy at udel.edu Mon Aug 2 21:21:08 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 2 Aug 2004 21:21:08 -0400 Subject: IronPython-0.6 is now available! References: <278de0e.0407281353.27b6a457@posting.google.com> <410963E4.2040106@v.loewis.de> Message-ID: "Ely Stob" wrote in message news:b83c9f9c.0408021440.2001d7ad at posting.google.com... >I'm very much interested in why you insist that the CLR does not work >well for Python, in the face of an apparently solid existence proof, >in the form of IronPython, that that simply isn't the case. Does IronPython currently run the whole test suite as well as CPython on Windows? (Has anyone even tried?) I presume from the 0.6 designation that it might not, in which case the existence proof would not yet be solid. Has anyone independently verified J.H's timing claims? Terry J. Reedy From sakesun at boonthavorn.com Wed Aug 4 22:52:07 2004 From: sakesun at boonthavorn.com (Sakesun Roykiattisak) Date: Thu, 05 Aug 2004 09:52:07 +0700 Subject: Can decorator syntax do this ? (annotated results' names) Message-ID: <4111A0D7.9080602@boonthavorn.com> I have developed a framework to ease my database programming job, called "DescribedData Framework" which use inspection on function/method parameter-name to simplify my code. for example: -------- connection = dbi.connect('database-connection-string') cursor = connection.cursor() cursor.execute('select TITLE, NAME, AGE from PEOPLE') descdata = DescribedData(cursor.description, cursor.fetchall()) def show(TITLE, NAME, AGE): print '%s %s %s' % (TITLE, NAME, AGE) # print all records print 'Show all data' descdata.perform(show) # filter def teenage(AGE): return AGE <= 19 fdata = FilteredData(teenage, descdata) print 'Show teenages' fdata.perform(show) #sort def compare_age(AGE1, AGE2): return cmp(AGE1, AGE2) sdata = SortedData(compare_age, fdata) print 'Show sorted teenages' sdata.perform(show) -------- FilteredData & SortedData are handy decorators for DescribedData But when I implement more kind of decorators like "JoinedData", parameter-name inspection is no longer sufficient, function's *result-name* also have to be inspected. Currently, I use class instead of function, like this: -------- class ExtraNameJoiner(object): def join(self, NAME): return NAME.upper(), NAME.lower(), NAME.capitalize() def get_joining_description(self): return 'UPPER_NAME', 'LOWER_NAME', 'CAPITALIZED_NAME' joiner = ExtrasNameJoiner() jdata = JoinedData(joiner, sdata) # join extra fields def show_extra(NAME, UPPER_NAME, LOWER_NAME, CAPITALIZED_NAME): print '%s %s %s %s' % (NAME, UPPER_NAME, LOWER_NAME, CAPITALIZED_NAME) jdata.perform(show_extra) -------- The question is: Can the upcomming decorator-syntax be applied in this situation ? Can I do something like this : -------- @resultnames('UPPER_NAME', 'LOWER_NAME', 'CAPITALIZED_NAME') def join_extra_name(NAME): return NAME.upper(), NAME.lower(), NAME.capitalize() jdata = JoinedData(join_extra_name, sdata) -------- I stopped follow decorator-syntax discussion for a while, because it seems everlasting. But now look like it's settle, so I wonder how far can I go with this new feature ? From richardlee2061 at yahoo.com Sun Aug 15 23:23:54 2004 From: richardlee2061 at yahoo.com (Steve Perry) Date: Sun, 15 Aug 2004 20:23:54 -0700 (PDT) Subject: reconstruct list and dictionary from file Message-ID: <20040816032354.55843.qmail@web53708.mail.yahoo.com> I have a serialized list and dictionary stored in a file, with the following format: mydata: color ["red" "green" "blue"] origin [0.0 13.2 9.2] datasource1 {server:"server1.domain" username:"client" password:"secret"} Is there any APIs to reconstruct the mydata object back with the list and dictionary recreated in it? Thanks, Steve __________________________________ Do you Yahoo!? Read only the mail you want - Yahoo! Mail SpamGuard. http://promotions.yahoo.com/new_mail From python at rcn.com Sat Aug 28 05:09:04 2004 From: python at rcn.com (Raymond Hettinger) Date: 28 Aug 2004 02:09:04 -0700 Subject: Pure Python version of collections.deque() Message-ID: <5d83790c.0408280109.4e4bb672@posting.google.com> FWIW, I've posted a recipe for a pure python version of Py2.4's collections.deque(). It is a drop-in replacement and should work with Py2.0 and later: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/259179 Raymond Hettinger From cjw at sympatico.ca Sat Aug 21 08:39:39 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Sat, 21 Aug 2004 08:39:39 -0400 Subject: Alternative decorator syntax decision In-Reply-To: References: <7x3c2iw9ig.fsf@ruckus.brouhaha.com> Message-ID: Anthony Baxter wrote: > On 20 Aug 2004 00:31:35 -0700, Paul Rubin > <"http://phr.cx"@nospam.invalid> wrote: > >>My conclusion: Python 2.4 should not have new decorator syntax. Stay >>with the existing stuff, for now. > > > This is not an option that is going to happen. The decorators thread > has been discussed on python-dev for 2 1/2 years. The case for including > them has been decided. The original decorators (classmethod, staticmethod) > were introduced in Python 2.2, released late 2001. How long do you think > we should wait? > Another six months won't make much difference. The transform functionality is there now. PEP 318 formalizes things. Colin W. > >>Discussion and exploration should continue and the question should be >>revisited for 2.5. For 2.4, extend the current kludgy (decorators >>separated from the function) mechanism if needed to provide necessary >>functionality, but deprecate any new such feature as soon as it's >>introduced, with the explanation that it's exploratory. > > > This is not the way Python works. "experimental" stuff doesn't stay experimental > once the first beta release is out. I see no reason to change this - > it increases > the costs dramatically for companies who are using Python if they have to > rewrite their code every second release. From anthonybaxter at gmail.com Sun Aug 8 04:27:33 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sun, 8 Aug 2004 18:27:33 +1000 Subject: Proposed improved decorator syntax In-Reply-To: References: Message-ID: On 08 Aug 2004 02:51:12 +0200, Hallvard B Furuseth wrote: > barnesc wrote: > > class foo: > > def introduceNewFeature(self, someArgument, anotherArgument): > > .decorate = [synchronized] > > .accepts = (int, int) > > .author = 'Chris King' > > pass # whatever > > I like it better than the current syntax, but I'm troubled by stuff > after the ':' which is executed before the function. > It _looks_ like it is executed inside the function. This was Guido's reason for rejecting all forms that put the decorator syntax inside the function block. They're _not_ part of the function's code. From bryanjugglercryptographer at yahoo.com Wed Aug 4 17:05:17 2004 From: bryanjugglercryptographer at yahoo.com (Bryan Olson) Date: 4 Aug 2004 14:05:17 -0700 Subject: Timing Difference: insert vs. append & reverse References: <35b736b9.0408020330.53b24ed3@posting.google.com> <1a517b5.0408031027.60554dfb@posting.google.com> Message-ID: <1a517b5.0408041305.3927a6c8@posting.google.com> Duncan Booth wrote: > Bryan Olson: [Duncan Booth had written:] > >> If you expected insert to be faster, perhaps you thought that Python > >> used a linked-list implementation. It doesn't do this, because in > >> practice (for most applications) a [array] based implementation gives > >> better performance. > > > > True, but an array implementation can easily support amortized > > constant-time insert/delete at *either* end (without breaking > > constant-time indexing). The same trick of keeping extra space > > at the tail end can work at the head; it requires keeping one > > additional offset to show where the occupied cells start. > > If the OP had said he expected insert and append to be the same speed I > might buy that but [...] Hmmm ... let me clarify what I'm selling: We can make lists perform efficiently as double-ended queues without breaking anything or perceptibly hurting anyone's efficiency. Until this thread, I hadn't realized that Python's lists are much slower than Perl's in important cases: http://perlmonks.thepen.com/17890.html Would this be a PEP-size change, or just a small fix? -- --Bryan From aleaxit at yahoo.com Fri Aug 27 17:28:19 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 27 Aug 2004 23:28:19 +0200 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <1LMXc.67190$UTP.37420@twister01.bloor.is.net.cable.rogers.com> Message-ID: <1gj7a9r.g7ec5a1g89rj0N%aleaxit@yahoo.com> Dan Perl wrote: ... > Alright, alright! And given the fact that it was added only in 2.3, that > explains why I couldn't find any mention of the feature in 'Python > Cookbook', the 1st ed. I'm looking forward to seeing it mentioned in the > 2nd ed. ;-) If somebody submits a good recipe about it, I'll be overjoyed to add it (not sure what chapter -- 'files'? 'system administration'? 'programs about programs'? -- ah well, I'll find a spot!-). In the 2nd Edition of the _Nutshell_, when THAT comes (don't hold your breath!-), I'll write it up just like I will for all the new delights since 2.2 -- but for the Cookbook I'm supposed to use recipes that people do submit to the online cookbook site... OK, I and my co-editors _do_ perform a lot of editing and merging, and occasionally do add a recipe or three, but mostly it IS the book you all have written, with over a hundred authors covering the subjects THEY think matter... Alex From sholden at holdenweb.com Mon Aug 30 08:29:51 2004 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 30 Aug 2004 08:29:51 -0400 Subject: Announcing PyCs, a new Python-like language on .Net In-Reply-To: <99dce321.0408292132.36ef381e@posting.google.com> References: <99dce321.0408292132.36ef381e@posting.google.com> Message-ID: David M. Wilson wrote: > Mark Hahn wrote in message news:... > > >>Please join the PyCs team. The only effort involved is particpating in a >>low-traffic, high-content, mailing list. You will be able to influence the >>design of the latest and greatest dynamic language. > > > Hi there. What are you trying to achieve? You have yet to complete > Prothon or even stabilise it for long enough to let me get a good > overview of it. Might I suggest you take a step back and actually > think about what you are doing rather than just implementing whatever > happens to be considered cool today. > Hear, hear. > Also judging by what I've seen of Prothon and read here, neither of > your proposed languages are either Python-like or related to this > group. > Well, I guess you have to try and garner support wherever you can. > Might I suggest you sit down with a paper and a pen and work out what > problem you are actually trying to solve, it is starting to get rather > embarrassing to watch the antics here. At the very least could you > spell check your postings before sending them. > Yup. One could take an announcement like this from someone like, say. Jim Hugunin, who has a solid history of development of complete, working systems. The suggestion that this effort might lead to something that was "better" that Iron Python is ridiculous given that Prothon appears to be merely "sound and fury, signifying nothing". > There are also much better forums to discuss language development on > than comp.lang.python. Sorry for the flame, but you really need it. > It could have been a much worse flame and still justified. Mark should gratefully take your advice. regards Steve From ngps at netmemetic.com Sat Aug 7 11:50:51 2004 From: ngps at netmemetic.com (Ng Pheng Siong) Date: 7 Aug 2004 15:50:51 GMT Subject: Paul Graham on Python hackers References: <87k6wb4fwq.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Message-ID: According to <510046470588-0001 at t-online.de>: > whereas in that crap of Java, it's already hard to write a program > that does nothing. IIRC there was a stupid language shootout where the Java compiler noticed the benchmark's main loop was a no-op and optimised it away, producing a program that did nothing. So you do have the compiler to help you there. ;-) -- Ng Pheng Siong http://firewall.rulemaker.net -+- Cisco PIX & Netscreen Config Version Control http://sandbox.rulemaker.net/ngps -+- M2Crypto, ZServerSSL for Zope, Blog From rogerb at rogerbinns.com Tue Aug 10 16:57:46 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Tue, 10 Aug 2004 13:57:46 -0700 Subject: VB-like GUI designer? References: <4eghh0hlotu5thcc2bar0mn8l4nkog8nin@4ax.com> Message-ID: Fred wrote: > Thx, the slides are very educational :-) And if I Python provides a > high-quality grid object or makes it a snap to work with the > ComponentOne ActiveX we currently use, I'll be happy as a pig ... er > .. a snake in mud. wxPython does have a grid object that is pretty good. On Windows wxPython also has activeX integration. I would recommend you download and install wxPython. One of the items it installs is a demo that shows using every single widget and the code for doing it. That gives you a good idea of what it all looks like and how you do the coding. Roger From ere.lists at killozapHALLO.com.invalid Mon Aug 30 14:07:37 2004 From: ere.lists at killozapHALLO.com.invalid (Erling Ringen Elvsrud) Date: Mon, 30 Aug 2004 18:07:37 +0000 (UTC) Subject: Urllib2, problems with a webserver Message-ID: Hello, My aim is to write a small application to use free sms-sending services in a more convenient way than with a web-browser. I found: http://wwwsearch.sourceforge.net/mechanize/ (which resemples the perl variant). With mechanize I should manage to interact with the website through python, like supplying usernames, filling the message form, etc. All well so far, I have installed it and tested it locally, seems to work well. But this piece of code: ------------------------------------- from mechanize import Browser b = Browser() b.open("http://freesms.no:88/") assert b.viewing_html() print b.geturl() print b.title() ------------------------------------- Give me this error: Traceback (most recent call last): File "./sms_sender.py", line 11, in ? b.open("http://freesms.no:88/") File "/usr/lib/python2.3/site-packages/mechanize/_mechanize.py", line 106, in open def open(self, url, data=None): return self._open(url, data) File "/usr/lib/python2.3/site-packages/mechanize/_mechanize.py", line 133, in _open self._parse_html(self.response) File "/usr/lib/python2.3/site-packages/mechanize/_mechanize.py", line 464, in _parse_html for token in p.tags(*(self.urltags.keys()+["base"])): File "/usr/lib/python2.3/site-packages/pullparser.py", line 90, in iter_until_exception yield fn(*args, **kwds) File "/usr/lib/python2.3/site-packages/pullparser.py", line 194, in get_tag tok = self.get_token() File "/usr/lib/python2.3/site-packages/pullparser.py", line 177, in get_token self.feed(data) File "/usr/lib/python2.3/HTMLParser.py", line 108, in feed self.goahead(0) File "/usr/lib/python2.3/HTMLParser.py", line 148, in goahead k = self.parse_starttag(i) File "/usr/lib/python2.3/HTMLParser.py", line 239, in parse_starttag endpos = self.check_for_whole_start_tag(i) File "/usr/lib/python2.3/HTMLParser.py", line 314, in check_for_whole_start_tag self.error("malformed start tag") File "/usr/lib/python2.3/HTMLParser.py", line 115, in error raise HTMLParseError(message, self.getpos()) HTMLParser.HTMLParseError: malformed start tag, at line 2, column 1365 -------------------------------------- By commenting out line 314 of HTMLParser.py and adding "return" I manage to continue. And everything seems to work (albeit not tested much). This is ofcourse not an acceptable solution... How come I get this error? Can the server software be a issue? According to netcraft the server runs Microsoft-IIS/5.0 Thanks, Erling From tuure at laurinolli.net Sun Aug 29 18:17:58 2004 From: tuure at laurinolli.net (Tuure Laurinolli) Date: Mon, 30 Aug 2004 01:17:58 +0300 Subject: possible python bug here In-Reply-To: References: Message-ID: manuel wrote: > In the sample below, the foo function modify the b list, > but I think it should modify only c, not b! It work > correctly if if b is one dimension list instead two. > > def foo(aList): > print "use foo..." > aList[2][0] += .35 > aList[2][1] += .35 > aList[2][2] += .35 > > p = [2.5,2.5,2.5] Here you bind the name p to a list. > b = [p,p,p,p] Here you bind the name b to a list, which has four references to list p > > c=b[:] #c is a totally new list cloned from b, it's not an alias! Here you bind the name c to a list, which has four copies of the references to list p > > print "b = ",b[2] Here you print the third reference to p of list b > > foo(c) #The argument is c, not b! Why b is modified too? Here you modify the third reference to p of list c > > print "b = ", b[2]# after foo(c), the list b now is different! Here you print the third reference to p of list b, it's still just reference to list (originally bound to) p. Note that also the other references to the changed list (b[0:4], c[0:4], p) refer to the same changed list. From eurleif at ecritters.biz Mon Aug 23 03:37:38 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Mon, 23 Aug 2004 03:37:38 -0400 Subject: Has anyone implemented BASIC in Python? In-Reply-To: <9h0ji0lvc0be65nuvcugaa3vsq5mcl3ck8@4ax.com> References: <2oo13eFcj548U1@uni-berlin.de> <2ot30hFeek8nU1@uni-berlin.de> <9h0ji0lvc0be65nuvcugaa3vsq5mcl3ck8@4ax.com> Message-ID: <2otkvkFe7p8oU1@uni-berlin.de> Andrea Griffini wrote: > Writing an interpreter that executes directly a parse tree of > a structured language program is IMO *easier* than writing an > interpreter for an unstructured language program. > That's why I think that starting from BASIC is not a good idea. I see what you're saying now. I had entirely forgotten about GOSUB and FOR (I haven't used BASIC for a very long time, thank God), so I was thinking thinking about stackless code with IF and GOTO for flow control. Thanks a lot for the detailed replies, by the way; they've been very helpful. > Writing parsers, interpreters and compilers is a lot simpler than > many do think. Is there a (virtual) book you would recommend reading to learn about writing them? A course isn't really possibly for me, so I'm hoping that isn't the only option. From maney at pobox.com Wed Aug 18 11:05:57 2004 From: maney at pobox.com (Martin Maney) Date: Wed, 18 Aug 2004 15:05:57 +0000 (UTC) Subject: Calling __init__ for all mixins Message-ID: I've been to the cookbook (both forms, since they're sometimes usefully different), but that gave rise to more questions than answers. Heck, let me pull some of them up while I'm at it. Martelli gives the recipie (5.3 on paper) "Calling a Superclass __init__ Method if it Exists" where he seems to say that this: class NewStyleOnly(A, B, C): def __init__(self): super(NewStyleOnly, self).__init__() is the New Class Speak equivalent of class Classic(A, B, C): def __init__(self): for base in self.__class__.__bases__: if hasattr(base, '__init__'): base.__init__(self) but when I tried a simple test case (base classes just print a tracer when called), Martelli's NewStyleOnly only invoked A.__init__, as it was the first base class in the base list as written with an __init__ implemented. These seem to me to be very different. In the completely different category of things that make you scratch your head, online recipie 146462 suggests code that seems to be a candidate for best gratuitous use of 'continue'. Or is there some subtle reason to prefer for x in something: if somecondition: do_one_thing() else: continue do_the_other_thing() rather than the simpler and clearer for x in something: if somecondition: do_one_thing() do_the_other_thing() or maybe even push the condition up into a comprehension in the for statement. Yeah, it sometimes makes for long lines, but it also makes it perfectly clear that you aren't doing *anything* with the filtered elements. One thing I always thought C got stunningly right was its for construct. How better to summarize a loop than to give its initial conditions, loop invariant test, and fixup for next code all together inone place? Well, given that you don't have lists and manage to make the vast majority of loops be simple iterations over lists... :-) Yes, in retrospect maybe it would have been easier to have signed up for ASPN and pointed this out in a comment, but I prefer not to contribute to speedbumped sites like that both on principle, and as an expression of essential laziness, and because there's a better audience here anyway. Wait, that's three reasons... So the reason I was turning over these stones was that I'm working on a subsystem where I want to compose working classes using multiple mixin base classes to provide different implementations for separate parts of the interface. So far this is working quite nicely (1), but the business of calling all the mixins' __init__ functions is a bit of a nuisance. Unfortunately, the solutions I've found (aside from Martelli's NewStyleOnly which I'm sure was only accidentally implied to be a solution to this problem) all seem little is any better than the simple and obvious method of explicitly invoking each one. I'm not certain that I won't need to use that manual approach in the end, since the current draft has a couple of arguments to one mixin, and it's not clear I can eliminate them, but I would still be interested in any suggestions for nicer solutions to the MI __init__ problem. (1) the one nasty bit where a third mixin seems to want to provide a few elements of what are otherwise two different mixin categories can probably be subdued, if only by introducing the type of indirection sometimes called "Strategy", though it's been a standard trick since decades before design patterns were ever heard of. -- Man's mind, once stretched by a new idea, never regains its original dimensions. -- Oliver Wendell Holmes From aahz at pythoncraft.com Mon Aug 9 16:48:18 2004 From: aahz at pythoncraft.com (Aahz) Date: 9 Aug 2004 16:48:18 -0400 Subject: generating uuids / guids References: <2nhnrfF13jq0U1@uni-berlin.de> Message-ID: In article <2nhnrfF13jq0U1 at uni-berlin.de>, Jon Perez wrote: > >Is there a Python function that works on all platforms (not just Win32) >to generate such in the DCE / Microsoft format? > >If not present, this looks like it would be a very Pythonic addition >to the standard library. Sure it would. Best way to start is to create a stand-alone third-party library that implements the full DCE spec. Once it has proven its utility and stability, send a note to python-dev suggesting that it be added. Keep in mind that UUID generation is a somewhat complex and tricky business will likely require some kind of C library support (to get the MAC address, to check if there's already a system-level UUID/GUID generator present, to provide a "good" UUID if there's no network card, and so on). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From miki.tebeka at zoran.com Mon Aug 30 17:28:49 2004 From: miki.tebeka at zoran.com (Miki Tebeka) Date: Mon, 30 Aug 2004 23:28:49 +0200 Subject: os.walk: Get entire path In-Reply-To: References: Message-ID: <20040830212849.GI680@zoran.com> Hello Florian, > when I'm walking through a file system hierarchy using os.walk, how can I > get the full path of a file or dir? normpath and abspath don't work. from os.path import join, abspath from os import walk for root, dirs, files in walk("somedir"): for file in files: print abspath(join(root, file)) HTH. -- ------------------------------------------------------------------------ Miki Tebeka http://tebeka.spymac.net The only difference between children and adults is the price of the toys From stuffduff at cox.net Thu Aug 12 14:27:32 2004 From: stuffduff at cox.net (Sean) Date: 12 Aug 2004 11:27:32 -0700 Subject: ZServerSSL and Certificates References: <3222fe00.0408050548.43b5f0fd@posting.google.com> Message-ID: <3222fe00.0408121027.5d701b2b@posting.google.com> stuffduff at cox.net (Sean) wrote in message news:<3222fe00.0408050548.43b5f0fd at posting.google.com>... Thanks to all of those who helped! We've applied for our cert. I still have a lot of learning to do, but here's the summary: 1) Generate a new request/key pair # CA.pl -newreq 2) send newreq.pem to the website 3) get the server cert & save as server.pem 4) get the rsa private key # openssl rsa < newreq.pem > newkey.pem 5) append newkey.pem to server.pem 6) get the ca cert and save as ca.pem 7) copy ca.pem and server.pem to the ssl directory. So far so good! From mordor at fly.srk.fer.hr Thu Aug 5 03:02:28 2004 From: mordor at fly.srk.fer.hr (Zeljko Vrba) Date: Thu, 5 Aug 2004 07:02:28 +0000 (UTC) Subject: DB beginner help Message-ID: 1. Is there any HOW-TO documentation about DB API except PEP 249? 2. How are you supposed to write DB-driver independent code when each driver has its own, possibly different from any other, paramstyle ('qmark', 'numeric', etc..)? In Perl I always use question marks and have no trouble switching the application between different databases. How do you guys do it in Python (of course, without rewriting all queries?) From __peter__ at web.de Thu Aug 12 15:46:17 2004 From: __peter__ at web.de (Peter Otten) Date: Thu, 12 Aug 2004 21:46:17 +0200 Subject: zero new keyword decorator References: Message-ID: Roman Suzi wrote: > After a week of reading decorator discussion my mind slowly > turnes in the opposite direction: to find which syntaxes are absolutely > unwanted. Learn from Bengt Richter to keep a straight face while proposing something really odd. On the other hand - Guido could use his time machine to make these the syntax suggestions that were avoided by the pie. Speaking of which - why would he volunteer to take this pie straight into Python's face. We need another Dan Sugalski. Peter -- Then again, it's 5am in Finland and I'm still moderately drunk. -- Ville Vainio From __peter__ at web.de Sun Aug 29 03:47:49 2004 From: __peter__ at web.de (Peter Otten) Date: Sun, 29 Aug 2004 09:47:49 +0200 Subject: Proposal: require 7-bit source str's References: Message-ID: Hallvard B Furuseth wrote: > If you disagree with that, is that because you think of Unicode as The > One True Character Set which everything can assume is in use if not > otherwise specified? That's a long way from the world I'm living in. It's even worse. I think conceptually there is "One True Character Set" of which unicode is the closest approximation -- yes, I know that this position is "idealism" by its philosophical definition. > And the thing about standards is that there are so many of them to > choose from. Enforcing a standard somewhere in an environment where > that is not the standard is not useful. Try the standard of driving on > the right side of the road in a country where everyone else drives on > the left side. Standards are supposed to serve us, it's not we who are > supposed to server standards. If you go to GB from the continent it is clear that you have to switch lanes. You can still get it wrong but either completely or not at all. Now consider a road you can drive on in many directions, say 100, with two or three directions allowed simultaneously in one country. The best available method to find out the correct direction would be to drive a few kilometers and then get out of the car and look for damages in the car's body. If there are dents you had an accident, so either you or another car took the wrong lane... How is it that many drive faithfully then? The dominant car-make has a preference built-in. When they drive on the internet, everyone ignores the signs and just drives on the same lane as anybody else... By the way, I'm not "fond" of unicode, There may even be problems that cannot be solved in principle by a universal standard (like your sorting across three locales). I just think unicode would make a better default than what we have now and many apps that will break in the transition are broken now - you just didn't realize it. Peter From npat at efault.net Fri Aug 13 16:19:26 2004 From: npat at efault.net (Nick Patavalis) Date: Fri, 13 Aug 2004 20:19:26 +0000 (UTC) Subject: Why I love python. References: <2o4divF6one2U1@uni-berlin.de> Message-ID: On 2004-08-13, kosh wrote: > > Why is there a need for a stand alone executable? At least on all the unixes > whether something is executable is just determined by the executable bit on > the file. I can execute a python program just as transparently as one in > compiled c, c++, etc. I really don't see the point of that. > Perhaps you target system has no Python environment installed. And perhaps it has no resources to have a complete python environment installed (appart from the fact that it might not need one). Don't think of your 2GHz / 512MB desktop. Think of your cell-phone. From peter at engcorp.com Tue Aug 10 17:23:53 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 10 Aug 2004 17:23:53 -0400 Subject: remaining decorator syntax options In-Reply-To: References: Message-ID: Grzegorz Dostatni wrote: > > At the end of the day, I would look for precedents: > > Python: c/c++ Ruby > and & and > or | or > self.foo @foo > global $foo > > I am aware of the symbols python uses (#, %, **, &, |). With the > exception of #, I generally find a way to avoid them. Corrections to the above: C/C++ use && and || for "and" and "or". The single-char versions are operators used in mathematical expressions, and used identically in Python (and Ruby? or does it use words for both?). As for the "symbols" of Python: % ** & and | are all math operators, so they don't really apply here in the same way as other things do. Avoiding them would be senseless, given that when you need them, you need them, in the same way you wouldn't go around trying to avoid + or / either. # to introduce a comment is clearly in line with other languages that use symbols instead of words ("rem" from BASIC? Ugh...) but it is also a _very_ widely used convention at this point, and comes directly from Python's ancestry in system admin stuff. In the end, though, a new keyword would pretty much rock for this whole mess, especially if it were to immediate follow the function def's colon, and have it's own colon with an indented block following. -Peter From insert at spam.here Tue Aug 24 21:35:20 2004 From: insert at spam.here (Doug Holton) Date: Tue, 24 Aug 2004 20:35:20 -0500 Subject: J2 0-2-6 is available In-Reply-To: References: <3A81C87DC164034AA4E2DDFE11D258E3022E52@exchange.hqamor.amorhq.net> Message-ID: Neil Hodgson wrote: > I'd like to dissent on "using". To me, this code does not read well. > > using: > classmethod > def foo(cls): > pass > > foo *is* a class method, it is not *using* a class method. In C#, "using" > has too meanings: the first is to import a library and the second is to > acquire a resource which will be automatically released. Both of these are > seem reasonable as some thing (the object of the using clause) is being > used. It also will confuse people when we ever hit python 3 (see http://www.python.org/cgi-bin/moinmoin/Python3_2e0). We'll have a "with" (or similar keyword) that will work like this: with self: .property1 = True .init() "with" and "using" are way too similar, although they would be doing *completely* different things. This would also rule out other proposed generic keywords like: by, having, per, via, extend (extend means subclassing in most other languages)... but would leave as still suitable keywords like: meta, decorate, or predef (although predef is as meaningless to a python beginner as "def" is). From apardon at forel.vub.ac.be Tue Aug 17 08:05:14 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 17 Aug 2004 12:05:14 GMT Subject: Piping stdout to Python callable References: Message-ID: Op 2004-08-17, Edward Diener schreef : > From within a function in my own module I need to take the output from a > Python module "A", which is sending data to stdout and which can not be > changed and which I need to invoke as a top-level module, and pipe it into > another function in my own module so that I can read it from stdin. Is there > an easy way to do this ? The only way I can presently think to do this is > through "system python A.py | python MyOwnModule.py", which seems a bit > laborious having to invoke python.exe itself twice. Any other solution would > be most welcome. What do you mean when you say you need to invoke it as a top-level module? Do you mean you can't import it at all or that importing it will startup the process of generating output immediatly? What bothers you with twice invoking the interpreter? In these days a program that is invoked multiples times will generally be only loaded once in memory. Are threads an acceptable alternative? Does your MyOwnModule.py needs to write to stdout? -- Antoon Pardon From __peter__ at web.de Thu Aug 19 04:46:20 2004 From: __peter__ at web.de (Peter Otten) Date: Thu, 19 Aug 2004 10:46:20 +0200 Subject: inverse of izip References: Message-ID: Steven Bethard wrote: > Steven Bethard gmail.com> writes: >> What's the inverse of izip? Of course, I could use zip(*) or izip(*), >> e.g.: >> >> >>> zip(*itertools.izip(range(10), range(10))) >> [(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)] >> >>> x, y = itertools.izip(*itertools.izip(range(10), range(10))) >> >>> x, y >> ((0, 1, 2, 3, 4, 5, 6, 7, 8, 9), (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)) >> >> But then I get a pair of tuples, not a pair of iterators. Basically, >> I want to convert an iterator of tuples into a tuple of iterators. > > Sorry to respond to myself, but after playing around with itertools for a > while, this seems to work: > >>>> import itertools >>>> starzip = lambda iterables: ((tuple[i] for tuple in itr) for i, itr in > enumerate(itertools.tee(iterables))) >>>> starzip(itertools.izip(range(10), range(10))) > >>>> x, y = starzip(itertools.izip(range(10), range(10))) >>>> x > >>>> y > >>>> list(x) > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>>> list(y) > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > > Seems like a bit of work for the inverse of izip though so I'll wait to > see if > anyone else has a better solution. (Not to mention, it wouldn't be a > single line solution if I wasn't using 2.4...) Because Python supports function definitions you only have to do it once :-) However, your sample data is badly chosen. Unless I have made a typo repeating your demo, you are getting the same (last) sequence twice due to late binding of i. >>> import itertools as it >>> def starzip(iterables): ... return ((t[i] for t in itr) for (i, itr) in enumerate(it.tee(iterables))) ... >>> map(list, starzip(it.izip("123", "abc"))) [['1', '2', '3'], ['a', 'b', 'c']] >>> x, y = starzip(it.izip("123", "abc")) >>> list(x) ['a', 'b', 'c'] >>> list(y) ['a', 'b', 'c'] >>> Here's my fix. # requires Python 2.4 def cut(itr, index): # avoid late binding of index return (item[index] for item in itr) def starzip(tuples): a, b = it.tee(tuples) try: tuple_len = len(a.next()) except StopIteration: raise ValueError( "starzip() does not allow an empty sequence as argument") t = it.tee(b, tuple_len) return (cut(itr, index) for (index, itr) in enumerate(t)) a, b, c = starzip(it.izip("abc", [1,2,3], "xyz")) print a, b, c assert list(a) == list("abc") assert list(b) == [1, 2, 3] assert list(c) == list("xyz") Peter From sjdevnull at yahoo.com Mon Aug 9 22:25:02 2004 From: sjdevnull at yahoo.com (G. S. Hayes) Date: 9 Aug 2004 19:25:02 -0700 Subject: Parsing broken HTML via Mozilla References: Message-ID: <96c2e938.0408091825.19a04dd@posting.google.com> Walter Do:rwald wrote in message news:... > Hello all! Hi! > > I'm trying to parse broken HTML with several Python tools. > Unfortunately none of them work 100% reliable. What have you tried? I've been using Tidy with pretty good results; there's a Python wrapper called utidylib available at http://utidylib.berlios.de Make sure to use the "force output" option and it'll do a reasonable job of parsing fairly broken HTML and outputting either as plain HTML, XHTML, or several other formats (with lots of tweaky knobs available to tune the output if you want to). From jerf at jerf.org Sun Aug 29 01:54:55 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Sun, 29 Aug 2004 05:54:55 GMT Subject: regex into str References: Message-ID: On Sun, 29 Aug 2004 04:08:57 +0200, Peter Kleiweg wrote: > This works: > > a += 'x' In the sense you mean, no it doesn't. Python 2.3.4 (#1, Jun 8 2004, 17:41:43) [GCC 3.3.3 20040217 (Gentoo Linux 3.3.3, propolice-3.3-7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> a = 'a' >>> a 'a' >>> id(a) 1074037376 >>> a += 'b' >>> a 'ab' >>> id(a) 1074272448 Note the two different id numbers. 'a' and 'ab' are not the same string. > Is there a way to tell Python that '' should be something else > than str? No. From eppstein at ics.uci.edu Thu Aug 12 17:29:07 2004 From: eppstein at ics.uci.edu (David Eppstein) Date: Thu, 12 Aug 2004 14:29:07 -0700 Subject: PEP318 References: <20040812090056.00001e31@titan> <7ttmh0t8c3cogtbhhnp1ohqu8b51pda461@4ax.com> Message-ID: In article , Arthur wrote: > >Also, it's not in the Zen of Python, but maybe declarative is better > >than imperative? > > Starting now, I guess. ;) Well, I think starting with list comprehensions in place of imperative append-loops. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ From paul at boddie.org.uk Mon Aug 23 10:37:07 2004 From: paul at boddie.org.uk (Paul Boddie) Date: 23 Aug 2004 07:37:07 -0700 Subject: My only complaint about Python References: Message-ID: <5339b60d.0408230637.795a0b56@posting.google.com> "Ben Last" wrote in message news:... > [...] First of all, I apologise if I caused unnecessary offence. However, I don't quite see what relevance my brother has in this discussion. > I'm entirely content for Richard Stallman to continue his campaign, and also > entirely relaxed about Microsoft continuing theirs. Although you didn't explicitly equate the FSF agenda to the Microsoft agenda according to any particular criteria, I was merely pointing out that there is a big difference between them in nature, and that the Microsoft agenda has significant consequences not only in the ideological realm but also in ways which are generally regarded as being both serious and negative, have typically involved regulatory authorities and assorted legal proceedings, and are clearly concrete in the sense that paid-for speculation about the supposed negative effects of the GPL clearly are not. Now I know that I'm probably not even reading between the lines of your message here, so feel free to disregard this paragraph, but I think that there are various things that are still worth saying. It seems to be the big thing in various circles these days to pounce on people defending the FSF and declare them extremists or impractical ideologues - a perusal of any of the major news sites related to Linux or related technologies will yield numerous comments and contributions of that nature, and comp.lang.python hasn't exactly been spared this particular meme. Yet the FSF (including Mr Stallman) has not only significantly helped the Free Software (and open source) community get where it is today - it also provides a coherent framework for the management of software ownership and an ethical mechanism for licensing that software. Although this might seem uncool and an unnecessary distraction to those who are just grabbing "the good stuff for free", I think it should be the duty of software professionals to at least consider the various implications brought about by the software they choose to use and deploy. And is it good enough that your compiler or some hypothetical version of Python is a free binary made available at the discretion of your current favourite software company or even a restrictively-licensed source code edition from an enthusiastic researcher? Perhaps it is for now, but in the former case that company had better be generous in the long term (and not interested in moving in on your business), and in the latter case that researcher had better remain enthusiastic for years beyond the end of that research project of theirs. Paul From b.niemann at betternet.de Mon Aug 30 07:55:18 2004 From: b.niemann at betternet.de (Benjamin Niemann) Date: Mon, 30 Aug 2004 13:55:18 +0200 Subject: From python to LaTeX in emacs on windows In-Reply-To: References: Message-ID: Brian Elmegaard wrote: > Hi group > > I hope this is not a faq... > > I try to understand how to use the new way of specifying a files > encoding, but no matter what I do I get strange characters in the > output. > > I have a text file which I have generated in python by parsing some > html. > > In the file there is international characters like ? and ?. > I can see the file in emacs it is encoded as > mule-utf-8-dos > > I read the file into python as a string and suddenly the characters > when printed looks strange and consists of two characters. > > First problem: How do I avoid this? > > Second problem is that I make some string replacements and more in > the string to write a latex output file. When I open this file in > emacs the characters now are not the same? > > Second problem: How do I avoid this? When you read the filecontents in python, you'll have the "raw" byte sequence, in this case it is the UTF-8 encoding of unicode text. But you probably want a unicode string. Use "text = unicode(data, 'utf-8')" where "data" is the filecontent you read. After processing you probably want to write it back to a file. Before you do this, you will have to convert the unicode string back to a byte sequence. Use "data = text.encode('utf')". Handling character encodings correctly *is* difficult. It's no shame, if you don't get it right on the first attempt. From peter at engcorp.com Sat Aug 28 23:31:19 2004 From: peter at engcorp.com (Peter Hansen) Date: Sat, 28 Aug 2004 23:31:19 -0400 Subject: about presicion In-Reply-To: <8f17f4bc.0408281303.3cfb4199@posting.google.com> References: <8f17f4bc.0408281303.3cfb4199@posting.google.com> Message-ID: Ali wrote: > The decimal module comes with python 2.4? I have 2.3, :(, what do I do? The obvious answer is, well, obvious. The real question is what's stopping you from upgrading? -Peter From ptmcg at austin.rr._bogus_.com Sun Aug 22 09:13:34 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Sun, 22 Aug 2004 13:13:34 GMT Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WEDONE? References: Message-ID: <2_0Wc.8436$Jn5.1521@fe1.texas.rr.com> "Paolo Veronelli" wrote in message news:mailman.2146.1093172019.5135.python-list at python.org... > > > Some morphological images suggest me "through" can be a keyword as it > hide the verb filter which can be a little more general then others. > Anyway using a verb or a noun doesn't suggest the orthogonality of the > piece,so please consider adverbs as clever candidates. > > Paolino > > I always thought "through" was a preposition. So I googled for lists of prepositions, and found these other candidates (they are also shorter): per via -- Paul From M.Waack at gmx.de Tue Aug 24 12:20:23 2004 From: M.Waack at gmx.de (Mathias Waack) Date: Tue, 24 Aug 2004 18:20:23 +0200 Subject: Overlapping tests Message-ID: <8f6sv1-nj7.ln1@valpo.de> Hi, I have some time consuming tests which could (and should) run simultaneously. Is there a way to achieve this behavior without using (self-coded) threads? Unittest seems to be designed to run one test after another, but not to run much tests at the same time. The only way I can see so far is to start all tests during setUp() and wait for each test-job in a job specific test() method. Mathias From __peter__ at web.de Mon Aug 16 16:21:41 2004 From: __peter__ at web.de (Peter Otten) Date: Mon, 16 Aug 2004 22:21:41 +0200 Subject: passing globals to imported module References: Message-ID: James Tauber wrote: > He has a script, foo.py with a global. He wants to import bar.py and > needs that global available in bar.py He should _not_ consider the following hack: >>> import new, sys >>> bar = new.module("bar") >>> bar.my_global = "some value" >>> sys.modules["bar"] = bar >>> execfile("bar.py", bar.__dict__) bar ['__builtins__', '__name__', '__doc__', 'my_global'] some value >>> $ cat bar.py print __name__ print globals().keys() def demo(): print my_global demo() Peter From squirrel at WPI.EDU Tue Aug 3 16:05:40 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 3 Aug 2004 16:05:40 -0400 Subject: simple Thread question In-Reply-To: References: Message-ID: On 3 Aug 2004, adeger wrote: > Having trouble with my first forays into threads. Basically, the > threads don't seem to be working in parallel (or you might say are > blocking). I've boiled my problems to the following short code block > and ensuing output. Seems like the output should be all interleaved > and of course it's not. Running Python 2.2 from ActiveState on > Windows XP (also doesn't work on Windows 2000). The Python interpreter isn't too thread-friendly. Because it's not re-entrant, it has to make use of a Global Interpreter Lock in order to keep internal structures from getting mangled. This lock only allows one thread to access the interpreter at a time, and switches threads every hundred or so bytecodes. The likely cause of your problem is that your loops don't reach this switching threshold -- try using xrange(100) or higher. The GIL is released during blocking I/O (or other) operations, and C extensions can release the lock if they plan on doing lots of non-Python processing. Because of the former property, another thing you can try is inserting a time.sleep(.1) inside of each loop -- being a blocking I/O operation, this should cause the GIL to be released, and your threads will switch each time through the loop. Aside from the performance loss on parallel-processing machines, there is usually no reason to worry about the GIL in Python code: so long as you make proper use of the thread synchronization routines, everything will work as you intend it to. From pm_mon at yahoo.com Tue Aug 17 21:13:47 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Tue, 17 Aug 2004 21:13:47 -0400 Subject: PEP 318: Can't we all just get along? In-Reply-To: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> References: <20040817181725194-0400@braeburn.themorgue.org> <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: Peter Hansen wrote: > Paul Morrow wrote: > >> Kevin Smith wrote: >> >>> def classmethod foo(x, y, z): >>> pass >>> >>> That's it. One "decorator" that is a callable object that takes a >>> method as it's only argument. No expressions, lists, tuples, etc. >>> Just one callable object. >> >> >> Nope. That's using static declarations. We're a dynamically typed >> language as much as possible. Isn't there something that doesn't >> require any additional grammar words to identify classmethods and >> staticmethods? > > > It looks to me as though Kevin is not suggesting keywords, but > callables. In other words he would consider this valid, provided > my_own_decorator was a callable. > > def my_own_decorator foo(x, y, z): > pass > > > -Peter Oh, sorry, I wasn't reading that closely enough. Hmmmm... it's an interesting idea. It's not ugly... First though, I still believe that we should exploit existing conventions (recommended coding practices) as a way of getting 'free' declarations for class, static, and instance methods (e.g. methods whose first param is 'self' are instance methods, etc.). That feels very pythonic to me, just as we use naming conventions to distinguish public, private, and semi-private methods. But I think that, where we want to provide additional info about a method, and there are no conventions to take advantage of, Kevin's suggestion does have some appeal. Questions (for Kevin): 1. Would def deco1 foo(a, b, c): pass be the same as (just syntactic sugar for) def foo(a, b, c): pass foo = deco1(foo) or would it mean something else? 2. Would def deco1 deco2 foo(a, b, c): pass be the same as def foo(a, b, c): pass foo = deco1(deco2(foo)) or def foo(a, b, c): pass foo = deco2(deco1(foo)) 3. Would there be any restrictions on what a decorator could *do* to the method it was passed? e.g. Could it change: * the method's name (which could of course affect the method's visibility: public|private|semi-private)? * whether the method was a static, class, or instance method? * the method's signature (formal parameter names, parameter order, defaults values)? From cookedm+news at physics.mcmaster.ca Wed Aug 18 15:13:29 2004 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Wed, 18 Aug 2004 15:13:29 -0400 Subject: can tarfile maintain directory structure? References: Message-ID: At some point, jaydonnell at yahoo.com (Jay Donnell) wrote: >> import tarfile >> >> tar = tarfile.open(filename, "w:gz") >> tar.add(directory) >> tar.close() >> >> The add() method is recursive by default. More information and examples >> here: http://docs.python.org/lib/module-tarfile.html > > That doesn't maintain the directory structure. When you untar it all > the files are in the base directory (when I untar it on windows with > winzip). Winzip is probably broken? It works for me using GNU tar on Linux. -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From AntiVir at yalta.us Sun Aug 15 23:34:01 2004 From: AntiVir at yalta.us (AntiVir at yalta.us) Date: Mon, 16 Aug 2004 06:34:01 +0300 Subject: AntiVir ALERT [mail from: "MAILER-DAEMON" ] Message-ID: <200408160334.i7G3Y1K2024851@yalta.us> * * * * * * * * * * * * * * * AntiVir ALERT * * * * * * * * * * * * * * * ????????? ????????? ????? ? ??????????????, ??????? ????????? ????? ??????! ???????????: "MAILER-DAEMON" ???????? ??????: Worm/Mydoom.m ????? ?? ???? ?????????? ??????????. ? ?????????; ???????? ???????? ???.: +38(0654)271828 ????.: +38(0654)231094 web: www.yaltainfo.com email: support at yalta.us Mail-Info: --8<-- From: "MAILER-DAEMON" To: python-list at python.org Date: Mon, 16 Aug 2004 03:32:17 +0300 Subject: Delivery reports about your e-mail --8<-- This version of AntiVir is licensed for private and non-commercial use. -- AntiVir for UNIX Copyright (C) 1994-2003 by H+BEDV Datentechnik GmbH. All rights reserved. For more information see http://www.antivir.de/ or http://www.hbedv.com/ From peter at engcorp.com Tue Aug 3 16:19:35 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 03 Aug 2004 16:19:35 -0400 Subject: executing python programs as if they were on OS path (noob) In-Reply-To: References: Message-ID: Darren Dale wrote: >> At least two options (assuming you're on Linux... you >> didn't specify your OS unfortunately): >> > > I am currently on windows. I didnt think it would matter, sorry I left > that out. Ah, you tricked us by using forward slashes in the sample path. :-) On Windows, the best answer depends on *which* Windows you are on... 98? XP? Other? -Peter From __peter__ at web.de Tue Aug 31 09:33:13 2004 From: __peter__ at web.de (Peter Otten) Date: Tue, 31 Aug 2004 15:33:13 +0200 Subject: has_method References: <41347A12.6020203@holdenweb.com> Message-ID: Gandalf wrote: > But since I have my method name in a variable, it will be this way: > > methods = dir(self) > if methodname in methods: > cmd = "self." + methodname > method = eval(cmd) > > This is what I wanted to avoid - i.e. the use of eval. There must be an > easier and quicker way to do this. method = getattr(self, methodname, None) if method: method(arg1, arg2) Note that this may still fail if the attribute's value is not callable (and bool(method) True). Use try: method(arg1, arg2) except TypeError: pass to guard against that. Peter From newsgroups at jhrothjr.com Tue Aug 17 12:51:31 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Tue, 17 Aug 2004 12:51:31 -0400 Subject: 'ascii' codec can't encode character u'\xf3' References: <4120F820.4000703@fusiondementes.com> Message-ID: <10i4dt2gvu1th7f@news.supernews.com> "Martin Slouf" wrote in message news:mailman.1775.1092723467.5135.python-list at python.org... > i had similar errors: > > Traceback (most recent call last): > File "/home/martin/skripty/accounts.py", line 125, in ? > main(sys.argv) > File "/home/martin/skripty/accounts.py", line 119, in main > print_accounts(accounts, url_part) > File "/home/martin/skripty/accounts.py", line 94, in print_accounts > print str(i).encode("utf-8", "replace") > UnicodeEncodeError: 'ascii' codec can't encode characters in position > 151-152: ordinal not in range(128) > > - - - - > > the solution seems to be: > > 0. string is not in unicode encoding (assumption) > 1. before printing out, convert the string to unicode > 2. when printing, convert to whatever charset you like > > though i dont understand much why (ive solved it a minute ago :) the > code should be: > > str = "any nonunicode string" > print unicode(str).encode("iso-8859-2", "replace") I think the terminology is backwards. If you use a unicode string (that is, u"foo") that string will be in unicode. That's what Python does with unicode strings. However, it can't be read or written as such - it has to be decoded from something else (utf-8, iso-8859-2, whatever) after being read, and encoded to something (utf-8, iso-8859-1, whatever) to be written. A string on disk isn't in "unicode"; it's always in some encoded format, which is usually utf-8. Or it's in some single-byte format such as iso-8859-1. Or a far eastern multi-byte format. A string only winds up in unicode when it's comfortably ensconsed in a unicode string. > comments: > > 1. why the string is not in unicode can have several reasons -- i guess: > - does ogg stores tags in unicode? > - you have parsed an xml file with encoding attribute set (that > is what i do) > - etc > > 2. "replace" parameter in encode causes non-printable chars to be > replaced with '?' (you can use "ignore" or strict", see your python > doc) > > 3. the above will work _only_ _if_ the 'str' encoding is "iso-8859-2" -- > a funny thing -- first line of code converts from unknown (but the > programmer must know it) to unicode and the second one converts it back > from unicode to unknown (now the programmer tells that secret to python > :) Well, the encoding declaration tells Python what to do with unicode string literals that it finds in the Python source. It doesn't do anything else. > 4. i would like to know from any python expert whether/why/why not: > > * my assumptions are right As I said above, the terminology is backwards. "Pure" unicode only exists in unicode strings. Everything else is some encoded character set or other in regular single byte strings, ***including unicode encoded as utf-8.*** > * why is that behaviour? -- if you search google you get > thousands of errors like this -- with no proper solutions i must add There's a lot of confusion out there. Lots of people are under the impression that the encoding declaration somehow does something magical with unicode, when all, (and I need to emphasize that, ALL) it does is convert the source code to unicode in unicode literals using the specified decoding. Everything outside of unicode literals is treated as a stream of 8-bit bytes, regardless of the programmer's intentions. Before the encoding declaration, if you wanted to include unicode characters in your program you had to use an editor that encoded in utf-8 and put them in single byte strings, and then decode those strings into unicode strings. This was fairly error-prone since you could drop utf-8 encoded characters somewhere they didn't belong, causing very difficult to find bugs. > * is there an easier portable way (no sitecustomize.py changes) > to do it The best thing is to ignore the encoding declaration and write the program as if it wasn't there. On input you need to somehow determine the encoding of the data and then decode that into a unicode string; on output you need to do the reverse and encode the unicode string into a single byte string before writing it. You can simplify some of this by using the open function in the codecs module. That lets you declare the encoding on open so that the encoding and decoding happens transparently. > * i was looking in site.py and there is deleted the > sys.setdefaultencoding() function, but from the comments i do > not know why -- you know it? why is user not allowed to change the > default encoding? it seems reasonable to me if he/she could do that. That's someone else's answer. I'm not going to get into the politics behind that, other than to say that there are very serious release to release compatibility considerations here. John Roth > > thx. > > m. > From michael at elehack.net Tue Aug 10 10:29:54 2004 From: michael at elehack.net (Michael Ekstrand) Date: Tue, 10 Aug 2004 09:29:54 -0500 Subject: pro python paper In-Reply-To: <305aa162.0408091905.5bce8f9a@posting.google.com> References: <305aa162.0408091905.5bce8f9a@posting.google.com> Message-ID: <200408100929.54132.michael@elehack.net> On Monday 09 August 2004 22:05, ccdetail wrote: > http://www.journyx.com/pdf/PythonAtAGlance.pdf If the paper will be seeing a revision, one thing you might want to put in there. Google also uses Python extensively... it might be a worthy addition to your list of Python users, particularly given how much it is in the news of late. -Michael From tjreedy at udel.edu Thu Aug 5 14:47:58 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 5 Aug 2004 14:47:58 -0400 Subject: Decorator syntax References: <788E231C269961418F38D3E360D1652526CA1A@tndefr-ws00021.tenovis.corp.lan> Message-ID: > def(staticmethod) somemethod(self, args): > some code >could you or someone else please enlighten me, as someone who wasn't >following the decorator syntax discussion, why this syntax was ruled >out? That particular syntax -- deco in parens and jammed up against was never proposed. A similar syntax -- no parens and a space was. Guide said a) he thought there would be parser issues and b) this would cause problems with all support tools that assume that the next name after def is the function name. Also, some of the major proponents want parameterized decorators and multiple decorators, not just a different position for staticmethod and classmethod. So def staticmethod func... then becomes something like def [mydeco(a,b,a), attributes({'a':1,sayonara:'haha'}), staticumethod] func\ (longparamname, somemore): and it becomes difficult to find the function name, which is the most important thing, after all. For what its worth: 1) this issue and multiple alternatives has been discussed since at least Jan 03. Since then, it has possibly taken more devel time, and probably more Pydev postings than any single other issue; 2) the PEP is broken and Guido knows it. We'll see if someone volunteers to fix it. Terry J. Reedy From pm_mon at yahoo.com Wed Aug 11 16:10:11 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Wed, 11 Aug 2004 16:10:11 -0400 Subject: Rather than decorators, how about sections? In-Reply-To: References: <1C74C038-EBB6-11D8-8889-000A95857E5C@eischet.com> Message-ID: paolo veronelli wrote: > to understand where I was reading in the code .... now should I say > shame on you because you like self? Take it easy with words and have fun. I don't particularly like the name 'self', but that *is* the recommended name to use as the first argument to all instance methods. We are discouraged from using anything else, and rightly so. We want the readers of our code to feel at home, to see familiar conventions. From newsgroups at jhrothjr.com Thu Aug 19 12:55:24 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Thu, 19 Aug 2004 12:55:24 -0400 Subject: PEP 318: Can't we all just get along? References: <20040817181725194-0400@braeburn.themorgue.org> Message-ID: <10i9msuatli5p84@news.supernews.com> "Kevin Smith" wrote in message news:20040817181725194-0400 at braeburn.themorgue.org... > For what it's worth, I wrote the original PEP 318. I probably wasn't > qualified, but I just wanted a nice simple way to declare class methods > without having to repeat the function name. After submitting it to BDFL > for approval, more work was needed and the discussion of PEP 318 on > python-dev increased rapidly. It was evident that I was in over my head, > so I asked more someone more experienced to take over. > > I guess others had bigger plans for my proposal that I had planned. It > has turned into the "solution" to many problems: type checking (both > arguments and returned values), metaclasses, metadata, interfaces, > function attributes, etc.). Unfortunately, in the process, this simple > request for syntactical sugar has turned into a monstrosity. In my > opinion, none of the proposed syntaxes really seem Pythonic. This PEP > just seems to be trying to solve too many problems. I don't think that is the case. What is actually going on has to do with the mechanics of the classmethod and staticmethod functions. They wrap the actual function in a special purpose descriptor. The current approach is simply to allow running any wrapping function, not just classmethod and staticmethod. That is, in a very real sense, realistic because if they put in a special purpose hack for just those two descriptors, then you'd get a huge backlash from people who will still complain that it doesn't support, for example, properties. All the other stuff you're seeing isn't something that the proposal has to support explicitly. You can wrap a function in any kind of a descriptor you want. They are simply use cases, and IMHO, some of them are not very well founded. However, none of them involves one line of code more or less than the basic "allow any descriptor anyone cares to write as a wrapper" approach. The arguement is, and always has been, about syntax. Everyone agrees that the current situation is not ideal; putting the wrapping assignment statement after the method is a very poor way of declaring intent. In other words, forget the use cases. They're irrelevant. The sticking point on syntax has to be solved first. If it is, then I doubt if you're going to get a special purpose, just those two specific descriptors and no others, solution. I just don't see it happening. There is, by the way, one syntax that hasn't to my knowledge been proposed that is straightforward, natural, doesn't make it begin to look like line noise and is completely consistent with existing syntax. Just use the '.' operator on the name and be done with it. For example: def classmethod.fubar(self, widget, wadget, boff): pass I'm not seriously proposing it because I'd like to reserve that idea to be able to insert a method into an instance or existing class without either having to do an extra assignment, or having to pollute the module namespace in passing. John Roth > > -- > Kevin Smith > Kevin.Smith at sas.com From mfuhr at fuhr.org Fri Aug 27 08:59:24 2004 From: mfuhr at fuhr.org (Michael Fuhr) Date: 27 Aug 2004 06:59:24 -0600 Subject: DNS.DiscoverNameServer query References: Message-ID: <412f302c$1_2@omega.dimensional.com> "Tim Williams" writes: > How can I see which nameservers a DNS.DiscoverNameServera() finds? import DNS DNS.DiscoverNameServers() print DNS.defaults['server'] # or req = DNS.DnsRequest() print req.defaults['server'] -- Michael Fuhr http://www.fuhr.org/~mfuhr/ From skip at pobox.com Tue Aug 24 16:33:09 2004 From: skip at pobox.com (Skip Montanaro) Date: Tue, 24 Aug 2004 15:33:09 -0500 Subject: profiler In-Reply-To: References: Message-ID: <16683.42501.355979.586984@montanaro.dyndns.org> Brett> As of Python 2.4 you can also compile in support for C-level Brett> profiling into the interpreter (--enable-profiling). See the Brett> in-dev docs (http://www.python.org/dev/doc/devel/) for details. Ummm... That's a pretty high-level url. How about: http://www.python.org/dev/doc/devel/whatsnew/node11.html instead. Even though I was the guy that added the --enable-profiling flag to configure it still took me a couple minutes to find the above url. Skip From __peter__ at web.de Sat Aug 7 02:31:44 2004 From: __peter__ at web.de (Peter Otten) Date: Sat, 07 Aug 2004 08:31:44 +0200 Subject: Prothon is switching to the .NET platform References: <000401c47b59$32539220$0d01a8c0@MarkVaio> <10h7lb21dhbuc12@news.supernews.com> <10h7rittck6ct75@news.supernews.com> Message-ID: John Roth wrote: > > "Christopher T King" wrote in message > news:Pine.LNX.4.44.0408061533250.25906-100000 at ccc8.wpi.edu... >> On Fri, 6 Aug 2004, John Roth wrote: >> >> > I think it's possible to do prototypes within Python by >> > overriding the __getattribute__() magic method. It still >> > wouldn't be very pretty, but it should be able to do >> > everything except override the magic methods (those >> > seem to have to be in the class object for new style >> > classes). >> >> Hm, I'd never thought of this before; something along the lines of: >> >> class derive(object): >> def __init__(self,parent): >> self.parent = parent >> def __getattribute__(self,attr): >> return getattr(self.parent,attr) >> >> myderivedobject = derive(myprototypeobject) >> >> would do the trick quite nicely I guess. I have one application that >> could benefit quite nicely from prototypes; I'll see if I can't work this >> in. Thanks for the enlightenment! > > What I was thinking of was more along the lines of: > > class ProtoBaseClass(object): > def __getattribute__(self, attr): > # call object.__getattribute__(self, __dict__) > # find requested attribute Wouldn't that part be implied if you used __getattr__() instead of __getattribute()? > # if not found, loop through back pointer chain > # if it's not a function, return the attribute > # if it is a function, wrap it in a method object and return it. This means that an object sees all changes in its prototypes until explicitly assigned an attribute. Is this intentional? (real question, I'm not familiar with prototyped languages) > def clone(self): > # create new instance > # insert back pointer to this instance > return > > Then you can create a new instance simply by calling self.clone(). > The only time you'd call the class itself is to get a new root > instance, which might even be a singleton (making an easy > way to get the root instance!). > > The place where this gets really ugly is inserting functions > into the instances. They have to be created at the module > level, and then inserted into the instance by a module level > function (somewhat similar to the way classmethod, > staticmethod and property work). I haven't fully thought this through, but it might work along the lines of class Stop(object): # always raise AttributeError pass class ProtoBaseClass(object): parent = Stop() def __init__(self, parent=None): if parent is None: self.parent = self.parent else: self.parent = parent # __getattr__() # clone() and then to clone with new methods: class Cloned(ProtoBaseClass): parent = someInstance def method(self): pass c = Cloned() # parent should be someInstance, method() should work as expected. > I'd be quite interested in what you [Christopher] come up with. Me too. Peter From tjreedy at udel.edu Fri Aug 13 15:26:13 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 13 Aug 2004 15:26:13 -0400 Subject: Deep Black Magic in Python: please help References: <807692de.0408130310.6e3ed9db@posting.google.com> Message-ID: "Jan Burgy" wrote in message news:807692de.0408130310.6e3ed9db at posting.google.com... > return arg_dict["one"] + self.bar(arg_dict) > It shouldn't be all that hard. My problem is the lookup of 'self.bar'. In > the AST it looks something like > > CallFunc(Getattr(Name('self'), 'bar'), [Name('arg_dict')], None, None) > > How do I find the corresponding function? The lookup returns a bound method, whose structure is an implementation detail. Completely untested suggestion, possibly not correct or possible: Write an implementation-specific unwrap function. Then either augment the source code .... + unwrap(self.bar)(self, arg_dict) # self now an explict arg or the analysis code to do the unwrapping. For the latter, recognize Name('self') and replace the result of Getattr(Name('self'), 'bar') with unwrap(thereof) and, again, augment the arg list. Terry J. Reedy From martin at v.loewis.de Mon Aug 9 02:43:18 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 09 Aug 2004 08:43:18 +0200 Subject: how many bytes in an int In-Reply-To: References: <9ACRc.1523$bJ2.9739@news1.mts.net> <4116f8ee$0$8076$a1866201@newsreader.visi.com> Message-ID: <41171D06.6060507@v.loewis.de> Reid Nichol wrote: > I'm thinking of writing a movie file encoder (probably avi). So, I need > to output DWORD (lookup revealed its a 4-byte int) to a binary file. > Therefore I need to know whether this can be done in python or not, > which will tell me whether I'll try to do it or not. You looked up DWORD somewhat incorrectly. It is a four byte int in memory, but on disk, it is a little-endian byte string of four bytes. So you *do* need the struct module, because only that will give you byte strings (of course, Grant's formula also works) > But, since the 64-bit archecture is out, short, long, etc may change > there meanings quite soon. From what I've read in the struct module > docs I can only tell it that it's a short, long, etc. but not whether > it's exactly a 4-byte int. Is there a way to do this? As Grant says: use the struct module. Use struct.calcsize to find out how large an int is. If the size is too large, try a short. If the size is too small, try a long. If no type matches, take the next larger type, and drop the extra bytes. However, it does not actually need to be that difficult: "int" is 32-bit on all current systems, including all 64-bit systems (only long is 64-bits on some 64-bit systems). Regards, Martin From harry.g.george at boeing.com Thu Aug 19 12:03:59 2004 From: harry.g.george at boeing.com (Harry George) Date: Thu, 19 Aug 2004 16:03:59 GMT Subject: age of Python programmers References: <41237124.4060600@chamonix.reportlab.co.uk> Message-ID: Thomas Heller writes: > Robin Becker writes: > > > Lucas Raab wrote: > > > >> One thing I've always kind of wondered is what is the average age of a > >> Python programmer?? What age groups use Python?? Something to think > >> about.... > >> > > 57, used to build my own logic using gas discharge tubes :) > > 48, but my first logic was build using 24V relays. 52, and my first logic circuit was an inverter via a homemade relay run from a 6V battery. (Dad: "Interesting alarm system. Do you know you have invented a relay?" Me: "What's a relay?") -- harry.g.george at boeing.com 6-6M21 BCA CompArch Design Engineering Phone: (425) 342-0007 From chrisks at NOSPAMudel.edu Fri Aug 6 01:39:51 2004 From: chrisks at NOSPAMudel.edu (Chris S.) Date: Fri, 06 Aug 2004 05:39:51 GMT Subject: Object Reference? Message-ID: I'm trying to make a graphical editor and browser for Pickled files. One aspect I'm not sure about is how to detect multiple references to the same data. For instance, say I had the Pickled data: a=[1,2,3] b=[a,4,5] c=[b,6,7] d=[a,b,c] The idea is to allow the user to browse this data and indicate references. In this case, if 'a' was selected, the browser should show that 'b', 'c', and 'd' contain a reference to 'a'. Inversely, if 'c' were selected, it should indicate that it's first element just isn't a list, but a reference to a list defined elsewhere, namely 'b'. Naturally, I could just recursively parse all the data comparing every element to every previously listed object, but is there a less obtrusive method? Python figures out when to delete objects based on the remaining references to an object. Is there a way to access this information to automatically lookup these references? Any help is greatly appreciated. From ptmcg at austin.rr._bogus_.com Wed Aug 11 13:20:12 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Wed, 11 Aug 2004 17:20:12 GMT Subject: Rather than decorators, how about sections? References: Message-ID: "Paul Morrow" wrote in message news:mailman.1509.1092238688.5135.python-list at python.org... > I like many am not wild about the operator. I also don't think > that the decorator syntax should be so directly attached to the method, > since what we're trying to do is to say something about the > *relationship between* a method and a class (e.g. "method m is a > staticmethod of class C"). > > So if we are going to extend the Python grammar to support this sort of > thing (which I believe is a good idea), my preference would be to > introduce named sections within a class definition, such as... > > class Foo(object): > staticmethods: > def baz(a,b): > print "I'm a static method." > def bez(c,d): > print "I'm a static method too." > > classmethods: > def biz(klass): > print "I'm a class method." > > > def __init__(self): > print "We all know what I am." > This only addresses the "decoration" for declaring static and class methods. The decorator mechanism is intended to include much more than this simple class declaration feature. See http://www.python.org/cgi-bin/moinmoin/PythonDecoratorLibrary for the first application (memoize - a return value cacheing helper/decorator, to optimize access to repetitive or compute-intensive function calls, with NO changes needed to the function itself). Other decorator candidates I've seen mentioned are: - mutex lock/unlock wrapper - debugging/logging wrapper - pre-condition/post-condition assertion wrappers - input argument validation/typing wrapper - return value type validation wrapper For this degree of flexibility, you can't hard-wire in specific section names. -- Paul From peter at engcorp.com Mon Aug 30 17:38:55 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 30 Aug 2004 17:38:55 -0400 Subject: "Content-Length" header In-Reply-To: References: Message-ID: <4p6dnegTwNnsA67cRVn-tg@powergate.ca> Justin, maybe it would help you and us if you would take a moment to read this document: http://www.catb.org/~esr/faqs/smart-questions.html If you followed the advice therein, it would go a long way to helping you get better answers, faster. Justin wrote: > URL open appears to not want to work unless its paramater is an actual > string spelled out in quotes. Check out the output to this code. When > I give urlopen objects instead of pre strings it doens't work > correctly. What is a "pre string"? > #This is the tuple with three urls in it, they all look correct to me Actually, it's a list, not a tuple. That may sound picky, but it's sometimes critical to be precise about things. Maybe not in this case, but I can't be sure... > ['http://www.ecs.soton.ac.uk/~harnad/temp/ariadne-rae.doc', > 'http://www.ecs.soto > n.ac.uk/~harnad/temp/ukparl.doc', > 'http://www-admn.csun.edu/systech/techsupport/ > procedures/2kcleanup.doc'] What good is that though? You don't appear even to have assigned it to anything. Or it is likely you aren't cutting and pasting the *exact* code you are trying to run into the window when you create your messages. Please don't try retyping the lines as you post the message: you'll just miss out the critical stuff. Note also that the indentation is screwed up for many (or all?) of us, so that makes it extra hard to help you. At this point, I strongly recommend you spend some time playing around at the *interactive interpreter* prompt. You appear to be trying code-and-fix style programming in an area in which you don't have a lot of familiarity. Rather than editing your source file and running it at the console, open the Python interactive prompt (just type "python" at the console prompt) and start executing these commands manually, inspecting the results each step of the way and trying to figure out the problem yourself. This will do two main things. It will likely lead you to the source of the problem, which I assure you will seem simple and silly and, in hindsight, obvious. It will also equip you with a very useful and effective tool for figuring out such things for yourself in the future. Rest assured we've all been at this stage once, and all got past it... -Peter From cybermanxu at hotmail.com Wed Aug 25 15:22:13 2004 From: cybermanxu at hotmail.com (Jinming Xu) Date: Wed, 25 Aug 2004 14:22:13 -0500 Subject: counterpart for Python None in C++ side Message-ID: Hi Folks, Regarding my previous message concerning Python None, I now understand. We use it in most functions! Sorry to disturb you guys! Jinming Xu _________________________________________________________________ On the road to retirement? Check out MSN Life Events for advice on how to get there! http://lifeevents.msn.com/category.aspx?cid=Retirement From dbickett at gmail.com Sun Aug 1 21:59:58 2004 From: dbickett at gmail.com (Beeyah) Date: 1 Aug 2004 18:59:58 -0700 Subject: written improvement on ftplib.FTP(); relevant questions Message-ID: <1d6cdae3.0408011759.44a5790e@posting.google.com> in my inability to find a working ftp program for my mac, i decided to write one in python. i wrote a class (link at end of post) that inherited ftplib.FTP and made the process slightly less involved, but it brought up a few questions: using the sendcmd() method to do a simple "LIST" command returns an error explaining that a data connection could not be opened, just as if you connected to a ftp server using telnet. so, you use the method retrlines() with "LIST", and everything's fine. the whole module, in my opinion, seems like a piece of work. every method gives the appearance of a workaround. i get the impression it would be enormously easier to manipulate and comprehend if you simply wrote it on your own with sockets. so what i'm saying is i want to write my own ftp class, but i don't know how to handle the two seperate data/command sockets. i started to read the rfc, but i'm so sick of those things lately. if it isn't a simple explanation, could someone point me to an appropriate document, or the relevant page of the rfc, that will explain the process of the command connection versus the data connection in general programatic terms? I'd appreciate that. anyway, if anyone's interested, i'll link to the class i wrote. it uses a queue to store messages from the server and general program messages, with the intention of having a seperate thread to sit and interpret/output. in addition, the class is intentionally completely detached from the fate of the program, that way it could be more universal. with that in mind, when something fatal involving the connection has occured, it pushes a simple "exit" string to the queue -- one that could be changed to a numeric representation of an error message or whatever, to be "interpreted" so to speak. its right here: http://216.67.238.18/~bar/misc/BetterFTP.py Beeyah From Michael_Hobbs at archway.com Tue Aug 24 19:51:43 2004 From: Michael_Hobbs at archway.com (Hobbs, Michael) Date: Tue, 24 Aug 2004 18:51:43 -0500 Subject: Inline Conditionals? Message-ID: <9EB8573B0FE2D84288F0D1D73904322201F987E8@euler> Adonis wrote... > "Joshua Ginsberg" wrote in message > news:mailman.2307.1093385983.5135.python-list at python.org... > > Is there any plan to include inline conditionals in Python? > For example: > > > > def isNegative(x): > > return x < 0 ? True : False > > > > Thanks! > > > > -jag > > > > -- > > Joshua Ginsberg > > Brainstorm Internet Network Operations > > > > How about something like: > > >>> def iif(condition, true=True, false=False): > ... if condition: > ... return true > ... return false > ... > >>> iif('foo' == 'bar', 'w00t', 'l33t') > 'l33t' > >>> iif('bar' == 'bar', 'w00t', 'l33t') > 'w00t' > >>> iif('bar' == 'bar') > True > >>> iif('foo' == 'bar') > False > >>> Probably good enough, but not an exact replacement. For example, such a function wouldn't work well for this: >>> name = line is None ? None : line[4:] If you call iif() when line is None, you get an error: >>> name = iif(line is None, None, line[4:]) Traceback (most recent call last): File "", line 1, in ? TypeError: unsubscriptable object Because `line[4:]' is evaluated regardless if `line is None'. From heikowu at ceosg.de Wed Aug 11 17:50:50 2004 From: heikowu at ceosg.de (Heiko Wundram) Date: Wed, 11 Aug 2004 23:50:50 +0200 Subject: rsa implementation question In-Reply-To: <1092217625.4119eb1976a92@www-mail.usyd.edu.au> References: <1092200894.4119a9beb1978@www-mail.usyd.edu.au> <5GkSc.124$O72.121@newssvr14.news.prodigy.com> <1092217625.4119eb1976a92@www-mail.usyd.edu.au> Message-ID: <200408112350.50959.heikowu@ceosg.de> Am Mittwoch, 11. August 2004 11:47 schrieb Ajay: > > > i am using RSa for signing documents and hence decrypting and then > > > encrypting to verify? Oh, btw., if you're not necessarily bound to PyCrypto, you might give Cryptopia a try: http://www.heim-d.de/~heikowu/Crypto It's a wrapper for GMP (PyGMP) combined with an ElGamal and RSA encryption/decryption engine, and it's fast, faster than PyCrypto for large key sizes (because it uses GMP) and simpler to use (because everything that is returned from decrypt/encrypt is returned in classes which can easily be stored to string/loaded from string). I've only built it on Linux and Solaris, can't say if it'll build/work on Windows, although there is a port of GMP to Windows out there... Look at the examples if you need more info on how to use it. Heiko. From jerf at jerf.org Sat Aug 28 16:30:10 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Sat, 28 Aug 2004 20:30:10 GMT Subject: Testing automatically on import (was: Re: allowing braces around suites) References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1ry8k0d2az.fsf@rovereto.ifi.uio.no> <10iv0kid2ig9ka6@corp.supernews.com> <1rpt5ccbso.fsf@rovereto.ifi.uio.no> <10ivpk9inpnh65@corp.supernews.com> <1rd61bd26k.fsf@rovereto.ifi.uio.no> <1gj892g.1hlc8ar1po78b6N%aleaxit@yahoo.com> Message-ID: On Sat, 28 Aug 2004 12:15:24 +0200, Alex Martelli wrote: > Hmmm -- I'm thinking that the existing import hooks might be enough to > let one prototype this "automatic checking" functionality, not quite as > smoothly as a fully architected system maybe, but enough to get some > early adopters, shake out teething problems, build a constituency to > lobby for smoother integration in a future Python version... You know, I'm totally unexcited about the syntax stuff this thread is putatively about, but running automated testing over newly imported stuff sounds kind of useful, not just for development but deployment as well; "forcing" the users to run the tests once and report problems could be very useful in some contexts. I already tend to name my unit tests for file "x.py" as "tests/xTest.py"... Maybe something that looks for a __validate__ function taking no args in a module and runs it if the code was imported and newly compiled, combined with a few convenience functions for the common cases? I'm not *quite* familiar with the import hook stuff to knock this off right away. I tried prototyping it but got stuck on how to determine if a Python file already has an up-to-date .pyc file. (Although I guess there may be external dependencies... well in the interest of keeping it simple, deal with that later.) From nospam at here.com Wed Aug 18 16:32:43 2004 From: nospam at here.com (Richard Townsend) Date: Wed, 18 Aug 2004 21:32:43 +0100 Subject: can tarfile maintain directory structure? References: Message-ID: On Wed, 18 Aug 2004 15:13:29 -0400, David M. Cooke wrote: > > Winzip is probably broken? It works for me using GNU tar on Linux. There was a bug report relating to tarfile & WinZip: http://sourceforge.net/tracker/?group_id=5470&atid=105470&func=detail&aid=949052 Looks like it was closed today. regards, Richard From ny_r_marquez at yahoo.com Tue Aug 17 12:18:14 2004 From: ny_r_marquez at yahoo.com (R.Marquez) Date: 17 Aug 2004 09:18:14 -0700 Subject: Simple exceptions question References: Message-ID: <8a27e309.0408170624.51124c01@posting.google.com> Not sure if this is all you need, but have tried this? def main(): #define vars try: foo(a, b, c) except IndexError: traceback.print_exc() From abra9823 at mail.usyd.edu.au Tue Aug 3 04:13:28 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Tue, 3 Aug 2004 18:13:28 +1000 Subject: how do i do this - stream file Message-ID: <1091520808.410f49288f67d@www-mail.usyd.edu.au> hi! How do i create and stream a file? On a webpage i have a link to a file. Next to it i would like link, which, when pressed, runs a script that calculates the signature of the file, pickles the signature to a file and then gives a dialog box asking the user whether they would like to save the file or open it. I have the script to do the signing and pickle the signature into a file, but how do i allow the user to download it? thanks cheers -- Ajay Brar, ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From peter at engcorp.com Tue Aug 10 08:45:00 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 10 Aug 2004 08:45:00 -0400 Subject: Python equivalent to a C trick In-Reply-To: References: <1d7b6d0d.0408092255.1177908e@posting.google.com> Message-ID: <1ZqdnTY4J9DTXoXcRVn-rg@powergate.ca> Sam Holden wrote: > But I don't know if int(False)==0 and int(True)==1 are actually > guaranteed. And I wouldn't use it since it's ugly (IMHO). From the language ref at http://docs.python.org/ref/types.html#l2h-37 Booleans These represent the truth values False and True. The two objects representing the values False and True are the only Boolean objects. The Boolean type is a subtype of plain integers, and Boolean values behave like the values 0 and 1, respectively, in almost all contexts, the exception being that when converted to a string, the strings "False" or "True" are returned, respectively. So yes, it's fully guaranteed. From pwilkinson at videotron.ca Fri Aug 6 14:17:45 2004 From: pwilkinson at videotron.ca (Peter Wilkinson) Date: Fri, 06 Aug 2004 14:17:45 -0400 Subject: unicode to ascii converting In-Reply-To: <1091815856.527127@news.commspeed.net> References: <1091815856.527127@news.commspeed.net> Message-ID: <6.0.3.0.0.20040806141614.01b8fcb0@pop.videotron.ca> Thanks Tom B., I will try that for now .... It would be good to find out _why_ this happens in the first place. I will keep do a little searching on this for a few days. Peter W. At 02:04 PM 8/6/2004, Tom B. wrote: >"Peter Wilkinson" wrote in message >news:mailman.1296.1091813051.5135.python-list at python.org... > > Hello tlistmembers, > > > > I am using the encoding function to convert unicode to ascii. At one point > > this code was working just fine, however, now it has broken. > > > > I am reading a text file that has is in unicode (I am unsure of which > > flavour or bit depth). as I read in the file one line at a time > > (readlines()) it converts to ascii. Simple enough. At the same time I am > > copressing to bz2 with the bz2 module but that works just fine. The code > > is and error reported appears below. I am unsure what to do. > > > > I assume that because it is reporting that ordinal is not in range, that > > something to do with the character width that I am reading? > > > > Peter W. > > > > def encode_file(file_path, encode_type, compress='N'): > > """ > > Changes encoding of file > > """ > > new_encode = encode_type > > old_file_path = file_path + '.old' > > new_file_path = file_path > > os.rename(file_path,old_file_path) > > file_in = file(old_file_path,'r') > > > > if compress == 'Y' or compress == 'y': > > bz_file_path = file_path + '.bz2' > > bz_file_out = bz2.BZ2File(bz_file_path, 'w') > > for line in file_in.readlines(): > > bz_file_out.write(line.encode(new_encode)) > > bz_file_out.close() > > > > else: > > file_out = file(file_path,'w') > > for line in file_in.readlines(): > > file_out.write(line.encode(new_encode)) > > file_out.close() > > > > file_in.close() > > os.remove(old_file_path) > > > > ERROR Reported: > > > > Parsing > > >X:\GenomeQuebec_repository\microarray\HIS\M15K\Step_1_repository\HISH0224.tx >t > > Traceback (most recent call last): > > File "C:\Program Files\ActiveState Komodo 2.5\callkomodo\kdb.py", line > > 433, in _do_start > > self.kdb.run(code_ob, locals, locals) > > File "C:\Python23\lib\bdb.py", line 350, in run > > exec cmd in globals, locals > > File "C:\Python23\Lib\site-packages\xBio\Scripts\unicodeToAscii.py", > > line 158, in ? > > main() > > File "C:\Python23\Lib\site-packages\xBio\Scripts\unicodeToAscii.py", > > line 75, in main > > encode_file(fileToProcess, options.encode, 'Y') > > File "C:\Python23\Lib\site-packages\xBio\Scripts\unicodeToAscii.py", > > line 144, in encode_file > > bz_file_out.write(line.encode(new_encode)) > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: > > ordinal not in range(128) > > >I've encountered this problem before and the solution I've come up with a >fix that works but is probably not the best, > >def is_ord (strng): > new_text = '' > for i in strng: > if ord(i) > 127: > new_text = new_text + '' > else: > new_text = new_text + i > return new_text > >#Then just, > >text_from_file = is_ord(text_from_file) > >Tom > > >-- >http://mail.python.org/mailman/listinfo/python-list From jeff at ccvcorp.com Mon Aug 23 19:34:11 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Mon, 23 Aug 2004 16:34:11 -0700 Subject: Why are strings immutable? In-Reply-To: References: Message-ID: <10ikvme4ks3oda9@corp.supernews.com> Larry Bates wrote: >Your example: > >List = [ ] >for i in range(20000): > Word = DoSomeProcessing() > List.extend(list(Word)) >Str = ''.join(List) > > >will work as: > >words=[] >for i in xrange(20000): > word = DoSomeProcessing() > words.append(word) > >word_string = ' '.join(words) > > Or even (using a list comp): words = ' '.join( [DoSomeProcessing() for i in xrange(20000)] ) Though I have to wonder what you're doing with a 20,000 word string, built programmatically word-by-word. While I don't know what you're doing, here, the way you're building it seems to suggest to me that a list or dictionary may actually be a more natural way to handle your data. Jeff Shannon Technician/Programmer Credit International From mwh at python.net Mon Aug 16 07:51:17 2004 From: mwh at python.net (Michael Hudson) Date: Mon, 16 Aug 2004 11:51:17 GMT Subject: Flython References: Message-ID: Christopher T King writes: > On Sat, 14 Aug 2004, Terry Reedy wrote: > > > Knowing nothing about Flash bytecode, but knowing a bit about other Python > > to X projects, I wonder whether it might be more immediately feasible to > > either translate Python bytecode or generate Flash bytecode with an AST > > tree walker. > > We'll soon find out ;) > > (Unfortunately, AST trees don't match up exactly with Python grammar, so > I'm having to learn the format by trial-and-error. Not much fun. Is > there documentation on the AST forms anywhere?) Which AST are you talking about? Which version of Python, etc? However, the answer to the "documentation" plea is probably "no". Cheers, mwh -- Do I do everything in C++ and teach a course in advanced swearing? -- David Beazley at IPC8, on choosing a language for teaching From none at nowhere.null Sat Aug 7 11:45:39 2004 From: none at nowhere.null (Ivo) Date: Sat, 07 Aug 2004 15:45:39 GMT Subject: Tkinter "tab viewing" how-to? Message-ID: Hi All, I would implement a tab viewing (like mozilla) using the Tkinter toolkit. Does anyone know if is it possible and where i can find doc about? Thanks, Ivo From gohaku at earthlink.net Mon Aug 9 20:52:21 2004 From: gohaku at earthlink.net (gohaku) Date: Mon, 9 Aug 2004 20:52:21 -0400 Subject: @decorator syntax is sugar, but for what exactly? In-Reply-To: References: <4115b53a$1@nntp0.pdx.net> <4116239e$1@news.012.net.il> <4117a43b$1@news.012.net.il> Message-ID: <898217E4-EA67-11D8-9DC2-000A9574CFD8@earthlink.net> In case it has not been brought up before... @decorator reminds me too much of Perl arrays. From kamikaze at kuoi.asui.uidaho.edu Thu Aug 5 20:29:03 2004 From: kamikaze at kuoi.asui.uidaho.edu (Mark 'Kamikaze' Hughes) Date: 6 Aug 2004 00:29:03 GMT Subject: Decorator syntax References: Message-ID: Istvan Albert wrote on Thu, 05 Aug 2004 16:58:07 -0400: > Mark 'Kamikaze' Hughes wrote: >> class foo: >> def introduceNewFeature(self, someArgument, anotherArgument): [synchronized, types="o,i,i"] >> pass # whatever > Those who need argument type-checking should > go to Guido and talk to him about it. Piggybacking > this in as decorators makes everybody lose. They have talked to him about it. It's been talked to death. One of the major groups pushing for decorators are PyObjC users, who need it to make the interface vaguely tolerable. Also consider web services, which need metadata to access Python with anything but raw strings. That metadata can be stored in an XML file or something, but it's best if it's *right there* on the function def. This is not an in-Python type-checking mechanism, but a mechanism for attaching additional information to functions, mostly so they can interact with things that are not Python. >> 3) A large proportion of Python programmers are also Java programmers, >> and won't object to the @-syntax. > yay. love is in the air. I have no idea what you were trying to say there. --
    Mark Hughes "Virtues foster one another; so too, vices. Bad English kills trees, consumes energy, and befouls the Earth. Good English renews it." -The Underground Grammarian, v1n2 From pm_mon at yahoo.com Sat Aug 28 09:47:38 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sat, 28 Aug 2004 09:47:38 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412D9F1E.6000809@yahoo.it> Message-ID: Jess Austin wrote: > Paul Morrow wrote in message news:... > >>Jess Austin wrote: >> > Why didn't you respond to my detailed explanation of how binding and > scoping work in Python? Would it be worth my time to restate the > explanation in simpler terms? > > I was going to, but couldn't really find one main idea in there to respond to. It was a long paragraph full of lots and lots of complex ideas, where many sentences had multiple interpretations. It seemed as if, for almost every statement you made in that section, I would either 1) beg to differ, 2) reply that you were being imprecise in your assertions, or 3) just not understand what you were talking about and ask for you to explain what you meant. If you would clearly restate the point you're trying to make, I'll gladly try to respond to it. > >>>>Others seem to want to specify a function's metadata outside of the >>>>function def, which just doesn't seem pythonic (IMO). >>> >>> >>>If you really understood Python's scoping rules, you would know that >>>this opinion is the opposite of the truth. >> >>A decorator is a kind of meta information. So are docstrings. The >>proposals I've been seeing (A1 and J2 in particular) declare decorators >>and docstrings outside of the function def (not inside of the function def). > > > I'll be more specific. "Others seem to want to specify a function's > metadata outside of the function def": truth. "which just doesn't > seem pythonic": opposite of truth. "(IMO)": apparently truth. > Pythonic is a word with a meaning (in this newsgroup anyway), and > modifying an object's namespace from outside _is_ pythonic: Really? Can you show me an example of this? > we've > always been able to do so (at least since mid-1999 when I started > using python) and we always will be able to do so. Just because we *can* do it doesn't make it Pythonic. To be Pythonic, it must be beautiful (IMO). We can do lot's of things to an object from outside of it's definition that are not Pythonic (IMO). Directly updating it's __dict__ would be one example (IMO). > Your proposed > arbitrary character-driven change to Python's conventional scoping > rules would _not_ be pythonic. In your opinion. > It may in fact be your opinion that > such a change would be pythonic, but I correctly classified that > opinion as the opposite of truth. > I don't know what classifying an "opinion as the opposite of truth" means. Opinions are subjective assessments. > > >>>Of all the current >>>incarnations of function "metadata", only one may be set within the >>>function, and that one is not set using a standard binding statement: >>> >> >>True and True, provided that you believe that docstrings are the only >>kind of function metadata. I believe though that attributes like >>__author__ and __version__ above are also function metadata. > > > Metadata is a programmer's convention, or perhaps in this case > religious belief. What? Metadata is a convention? Metadata is a belief? > I'm not certain what your precise convention is > since you haven't explained it. I'm not suggesting a new coding convention. I'm suggesting that we continue to us magic (__xxx__) attributes for all magic behavior. > You evidently expect all > "experienced" programmers to know it and respect it. Apparently it > has something to do with underscore characters. Yes I do. Yes it does. Paul From peter at engcorp.com Thu Aug 12 13:32:32 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 12 Aug 2004 13:32:32 -0400 Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: References: Message-ID: paolo veronelli wrote: > On Wed, 11 Aug 2004 11:40:32 -0400, Peter Hansen wrote: > I think 'mutate' is better then 'decorate', and anyway I like to see > what is mutated and the possibility to explicitate it make possible > to move decorations from this position ,I put them where I like (at > least if I have to call them decorations) even in another file... > > so > > class Klass: > def meth0(x): > return x > mutate meth0: > staticmethod > > mutate Klass.meth0: > debugged > > reads good to me. This has the disadvantage of repeating the function name. I know you call it an advantage... but arguably the biggest part of the whole decorator "argument" revolves around whether or not it's critical to put the decorator right up above the "def" so that it can't be missed. If the method you describe above was deemed acceptable, then I think we'd be sticking with the current approach that just reads "func = decorate(func)". -Peter From peter at engcorp.com Mon Aug 23 15:06:09 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 23 Aug 2004 15:06:09 -0400 Subject: J2 proposal: keyword In-Reply-To: References: Message-ID: <7umdnWsYNds1orfcRVn-jA@powergate.ca> Oliver Fromme wrote: > So, FWIW, I think both "using" and "with" are fine, > although both of those remind me of completely unrelated > things. > > ("Using" as in the "print using" statement of certain > ancient dialects of BASIC which was used for formatted > output, as well as the "use" statement in perl to import > a module. I would call this a good precedent. Or at least I'd say that they choose the word well for that purpose, and our purpose here is very similar. (For those that don't recall this, I believe it was similar to if not exactly like the following, where it functions rather like a decorator in the sense of transforming the usual function in a certain way: PRINT USING '$###.##', total_dollars ) -Peter From bradtilley at usa.net Sun Aug 22 21:44:48 2004 From: bradtilley at usa.net (Brad Tilley) Date: Sun, 22 Aug 2004 21:44:48 -0400 Subject: 2 GB files In-Reply-To: References: <9418be08.0408221427.182a4d30@posting.google.com> Message-ID: David M. Cooke wrote: > At some point, "David Pokorny" wrote: > > >>"Elbert Lev" wrote in message >>news:9418be08.0408221427.182a4d30 at posting.google.com... >> >>>From postings to this group and other resources I understood that the >>>only way to make Python programs to work correctly with files lager >>>then 2 GB is building Python interpreter with some "magic spell" >>>defines. For me this is ABSOLUTELY unacceptable (Not the building, but >> >>Elbert: you might get a positive response if you rephrased your post. >> >>"Our corporation needs functionality ___. We would be happy to pay a >>contract consultant $n000 to come up with a solution that will work with a >>future trajectory of Python releases." >> >>Or you could pray to the OSS gods. > > > Or do better research, as it already has it. > > My python (from Debian) has large file support, for instance. Python's > configure script will use if it can find it. > > The OP doesn't mention what he's using that doesn't have large files > (OS, platform, python version...) Yeah, many older filesystems won't go over 2GB... remeber the 2GB partition limit in fat? From peter at engcorp.com Fri Aug 20 14:10:25 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 20 Aug 2004 14:10:25 -0400 Subject: How to clean python interpreter's environment? In-Reply-To: References: Message-ID: Rafal Kleger-Rudomin wrote: > I'm looking for a command to reset interpreter's environment i.e. unload > all modules, delete variables etc. If you're in the interactive interpreter, you should use the following command: ^Z (on Windows), or ^D (Linux). (Translation: there's no existing command that does what you want. Maybe describing your reason for wanting this will let people suggest alternative solutions.) -Peter From NAIGIMSESRIMAIL at gims.com Mon Aug 30 03:12:47 2004 From: NAIGIMSESRIMAIL at gims.com (GroupShield for Exchange (ESRIMAIL)) Date: Mon, 30 Aug 2004 09:12:47 +0200 Subject: ALERT - GroupShield ticket number OB38_1093849957_ESRIMAIL_3 was generated Message-ID: Action Taken: The message was blocked because of its subject. To: python-list at python.org From: aleaxit at yahoo.com Sent: -1156188416,29658720 Subject: Re: Testing automatically on import Attachment Details:- Attachment Name: N/A File: Infected.msg Infected? No Repaired? No Blocked? Yes Deleted? No Virus Name: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/ms-tnef Size: 1821 bytes Desc: not available URL: From http Sat Aug 28 22:31:41 2004 From: http (Paul Rubin) Date: 28 Aug 2004 19:31:41 -0700 Subject: simple compiled languages? References: <7xzn4fu188.fsf_-_@ruckus.brouhaha.com> <_1bYc.855$2s.374@twister.nyroc.rr.com> Message-ID: <7xbrguvfn6.fsf@ruckus.brouhaha.com> "Cy Edmunds" writes: > Turbo Pascal. I used to think it was great in 1983. :) Yeah, they never released the source code though. I should have added that as a qualification. BDS C was released, by the way, but it's written entirely in 8080 assembler. From bulliver at badcomputer.no-ip.com Tue Aug 24 20:01:42 2004 From: bulliver at badcomputer.no-ip.com (Darren Kirby) Date: Tue, 24 Aug 2004 17:01:42 -0700 Subject: Book Recommendation In-Reply-To: References: Message-ID: <200408241701.51019.bulliver@badcomputer.no-ip.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On August 24, 2004 4:37 pm, Anthony Greene wrote: > I'm new to programming entirely, and I'm simply looking for some insight, > can you guys recommend some introductory documentation for me to read, and > what I read, and, do concurrently why reading the primary "book" ou guys > recommend. Thanks, and any advice is great appreciated. I have found that "How to Think like a Computer Scientist: Python" (http://ibiblio.org/obp/thinkCS/python/english/) is a very good resource. The book tries to explain basic programming concepts common to all languages using Python. If you are looking for a particular function/statement/module etc then the official docs are invaluable (http://docs.python.org/). Start with the tutorial and go from there. As far as printed books, I have read "Learning Python" [O'Reilley] and "Practical Python" [Apress]. Both are very good. But the most valuable resource for learning Python: The interactive interpreter. - -- Part of the problem since 1976 http://badcomputer.no-ip.com "...the number of UNIX installations has grown to 10, with more expected..." - - Dennis Ritchie and Ken Thompson, June 1972 Public key: http://keyserver.linux.it/pks/lookup?op=index&search=bulliver -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFBK9btOrzWcOwL7mwRAuV9AJ48d5/uXWfVutSYMxDMxonbEnDv9QCfRV+T FQ+mey5KVfUXcmvrM/1+nsE= =9JyM -----END PGP SIGNATURE----- From mwh at python.net Fri Aug 6 07:46:26 2004 From: mwh at python.net (Michael Hudson) Date: Fri, 6 Aug 2004 11:46:26 GMT Subject: PEP 263 status check References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> <10h5hgvpafm8a64@news.supernews.com> <41133C76.8040302@v.loewis.de> <10h6rklt3fa1690@news.supernews.com> Message-ID: "John Roth" writes: > If I understand you correctly, if I put, say, a mixture of > Cyrillic, Hebrew, Arabic and Greek into a byte string > literal, at run time that character string will contain the > proper unicode at each character position? Uh, I seem to be making a habit of labelling things you suggest impossible :-) > Or are you trying to say that the character string will > contain the UTF-8 encoding of these characters; that > is, if I do a subscript, I will get one character of the > multi-byte encoding? This is what happens, indeed. Cheers, mwh -- 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 grante at visi.com Mon Aug 9 14:03:49 2004 From: grante at visi.com (Grant Edwards) Date: 09 Aug 2004 18:03:49 GMT Subject: how many bytes in an int References: <9ACRc.1523$bJ2.9739@news1.mts.net> <4116f8ee$0$8076$a1866201@newsreader.visi.com> <41170cd1$0$8076$a1866201@newsreader.visi.com> <41171116$0$8079$a1866201@newsreader.visi.com> <41172C9A.2020301@jessikat.fsnet.co.uk> <41178bde$0$8077$a1866201@newsreader.visi.com> <41179cd2$0$8089$a1866201@newsreader.visi.com> Message-ID: <4117bc85$0$65563$a1866201@newsreader.visi.com> On 2004-08-09, Richard Brodie wrote: >"Grant Edwards" wrote in message > >>By guessing formats and calculating sizes? Or is there a way to >>ask for an N-byte integer that I missed? > > If you use '<' or '>' to force endianness you automatically > get 'standard' sizes thrown in; or you can use '=' for native > order. The standard sizes are specified in the struct module > documentation. Doh! I don't know how many times I've read that without realizing what it meant. If you specify byte order explicitly you _do_ get guaranteed lengths. -- Grant Edwards grante Yow! ... I want FORTY-TWO at TRYNEL FLOATATION SYSTEMS visi.com installed withinSIX AND A HALF HOURS!!! From peter at engcorp.com Mon Aug 23 00:05:35 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 23 Aug 2004 00:05:35 -0400 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: Delaney, Timothy C (Timothy) wrote: > Delaney, Timothy C (Timothy) wrote: >>Anyway, my vote is C1, C1, J2. > Given how many people are being obstinate about their choice, I'm going > to change my vote to: > > C1, C1, C1 > > ;) (Deliberately ignoring the wink...) If there is someone motivated enough to implement C1, I suggest that it isn't too late. If Guido is presented with J2 with an implementation, but knows that C1 was supported strongly as well and has an implementation imminent, I'm guessing it would lead him to consider @pie, J2, and C1 all together on their merits (in his view) and make a decision, perhaps a pending decision if he then favours C1. Without an imminent implementation C1 is likely dead in the water, much as Timothy or Aahz or I or anyone else would really prefer it. -Peter From geoff at variosoft.com Sat Aug 7 16:44:48 2004 From: geoff at variosoft.com (Geoff Caplan) Date: Sat, 7 Aug 2004 21:44:48 +0100 Subject: Compiling disutil modules on Windows Message-ID: <7947683945.20040807214448@variosoft.com> Hi folks, Enjoying the process of picking up Python, but have come to an unexpected grinding halt. I am using the latest ActivePython release on Win2k. When I try to run python setup.py install on a disutil package, I get the error: "Python was built with version 6 of Visual Studio, and extensions need to be built with the same version of the compiler, but it isn't installed." Assuming this is correct, I find it mind-boggling that Active State have chosen to use an expensive and discontinued commercial compiler! I am aware that MS have released a free version of the latest Visual Studio 7 compiler. I have installed this but disutils doesn't recognise it. I can't find a free release of the MVC++ compiler: does such a thing exist? I assumed this would be a FAQ but can't find much in the archives. My knowledge of C compiling is close to zero, so I am stuck. Any advice would be much appreciated: this is a show-stopper. ------------------ Geoff Caplan Vario Software Ltd (+44) 121-515 1154 From belred1 at yahoo.com Fri Aug 20 23:51:40 2004 From: belred1 at yahoo.com (Bryan) Date: Sat, 21 Aug 2004 03:51:40 GMT Subject: age of Python programmers In-Reply-To: References: Message-ID: Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... > > i'm 37... started programing on a TRS-80 Model I and III. i also did a bit a programming on a VIC-20... brownie points for anyone who can remember how many text characters there was in one row... believe it or not, i can remember this :) eventhough i'm not OLD like some of those on this list, i did get to program BASIC with punch cards in my 8th grade math class. bryan From DesertLinux at netscape.net Thu Aug 26 11:11:43 2004 From: DesertLinux at netscape.net (Byron) Date: Thu, 26 Aug 2004 15:11:43 GMT Subject: Larry Wall & Cults In-Reply-To: References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: Rene Pijlman wrote: > What are you replacing Unix with? M$ Windows... lol Byron --- From fred at acme.com Sat Aug 21 16:26:48 2004 From: fred at acme.com (Fred) Date: Sat, 21 Aug 2004 22:26:48 +0200 Subject: [newbie] Strange behavior of the re module References: <2ejdi01btug5iskb4ipjpj7eaprd8i7vgm@4ax.com> <4126CFCC.8000609@zephyrfalcon.org> <86hei0prvp55iom91df23tffh04egefeig@4ax.com> <3toei056qnmk8nkesta47mncuh49asscht@4ax.com> Message-ID: On Sat, 21 Aug 2004 17:10:09 +0200, Fred wrote: >The script does run, but Guess I hit the Send button instead of Save ;-) OK, for those interested, here's some working code, although it's pretty slow (2mn30 when massaging a 200KB file on a P3 host): -------------------- #The goal is to read an HTML file, extract whatever's between and , read a template file, and insert what we extracted from the first document: import sys import re fp=open("./mydoc.html") input = fp.read() fp.close #Needed if the document contains any backslash input = input.replace('\\', '\\\\') body = re.search('(.*?)',input,re.IGNORECASE | re.DOTALL) if body: body = body.group(1) else: body = "no body section found" fp=open("./template.tpl") output = fp.read() fp.close body = body + "" output = re.sub('', body, output) fp=open("./mynewfile.html","w") fp.write(output) fp.close -------------------- Thx everyone for the hints Fred. From anthonybaxter at gmail.com Sat Aug 21 05:04:28 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 21 Aug 2004 19:04:28 +1000 Subject: just ignore Guido's "rejections" [Re: Alternative decorator syntax decision] In-Reply-To: References: <2uadnbqpMuI1krvcRVn-sg@comcast.com> Message-ID: On Fri, 20 Aug 2004 15:09:54 -0500, Doug Holton wrote: > > Uh, what? No, you _can't_ ignore Guido's rejections - if you really decide > > that you must have a form he's objected to, you need a _damn_ strong > > argument to back that up. A "longtime community favorite" doesn't mean > > a thing - this is language design, not American Idol - that a lot of people > > like it makes no difference. > > Um, yes. The point is to determine what the *community* decides on, and > *then* present that to Guido. You're just helpping confound this second > vote even more. Some people aren't voting for what they think is best, > but what they think Guido hasn't "rejected". That is ridiculous. > You'll end up with a syntax that nobody really ever liked most, even Guido. You're misinterpreting what I said - I said that "if you want a form he's rejected, you need _damn_ strong arguments to back it up". I was replying to someone saying that it's not necessary to pay attention to Guido's rejections of various forms, and pointing out that in fact you _do_ need to pay attention to them. If there's a community concensus for an already-rejected form, but no-one has bothered addressing the existing concerns, then it's something of a waste of time. I'm not _trying_ to "confound the vote". I'm trying to *help* the process. If that's not considered useful, I'm quite happy to just step away from the entire issue. From skip at pobox.com Tue Aug 24 12:20:59 2004 From: skip at pobox.com (Skip Montanaro) Date: Tue, 24 Aug 2004 11:20:59 -0500 Subject: Python is to C as letters are to words. In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022E2B@exchange.hqamor.amorhq.net> References: <3A81C87DC164034AA4E2DDFE11D258E3022E2B@exchange.hqamor.amorhq.net> Message-ID: <16683.27371.783890.782647@montanaro.dyndns.org> >> Subject: Python is to C as letters are to words. >> My nine word description of the python language. Robert> I'll give you the benefit of the doubt and assume you meant: Robert> "Python is to C as words are to letters." ... and then privately wonder how well you scored on your SATs. ;-) Skip From noone at here.com Sun Aug 15 19:28:22 2004 From: noone at here.com (M. Clift) Date: Mon, 16 Aug 2004 00:28:22 +0100 Subject: Python secure? References: Message-ID: Hi, Thanks for your replies. I know I have a long way to go until a produce anything that someone would want to see the source code for. I do, however have an idea that I would not want others to easily see the source code of. I just don't want to spend a couple of years developing something that is not to be open source and by choosing the wrong language have my efforts wasted. My reason for choosing Python was one, that it is free, so if my efforts amount to nothing I haven't wasted money, two, that it is supposed to be an easy language when compared to some others and three, that my application when finished, probably wouldn't sell for that much and not in any great quantities for me to gamble spending something like ?1000 on Visual C / ++ this that and the other or whatever. If others want to make software open source, I salute them. I don't wish to do this however. Of course anyone can gain access to the program with the right tools, I just don't want to hand it to them on a plate. One thing has come up and that is when I spoke of secure I presumed that compiled C source code software was secure and I was asking how did python compare to this. >From the posts, however, it appears that you people in the know (seasoned programmers) speak of the way the code is written / language as playing a large part in making it secure, as it can always be reverse engineered to some extent. I'm not too bothered by making the code difficult for anyone to understand, it's more that I want to make it harder in the first place and once it's compiled anyone who reverse engineers it (in most countries?) is breaking the law. Also without thinking earlier I hit the reply button instead of the reply to group on OE - sorry if anyone got unwanted post : ) Thanks From gandalf at geochemsource.com Wed Aug 4 12:36:02 2004 From: gandalf at geochemsource.com (Gandalf) Date: Wed, 04 Aug 2004 18:36:02 +0200 Subject: How to force a single number to be a tuple In-Reply-To: References: Message-ID: <41111072.5040606@geochemsource.com> >You're going to get a zillion responses to this one. > >The syntax is a bit funky: > >y = (2,) > Funky. However, very logical. You can also write: (1,2,3,4,) instead of (1,2,3,4) The syntax is very clear and logical. (As usual when working with python.) Try to add one comma for each element - that will do the stuff. Most of the languages are not so straightforward - they forbid the last comma. Python is the best. :-) From brianc at temple.edu Thu Aug 19 11:04:59 2004 From: brianc at temple.edu (brianc at temple.edu) Date: Thu, 19 Aug 2004 11:04:59 -0400 Subject: age of Python programmers Message-ID: <1a608e98.725b9b40.8235400@po-d.temple.edu> 20 on saturday...woo...party! -Started doing HTML for school projects in 9th grade. -Program my TI-82 (basic?) to help me cheat in classes. --Failed 10th grade and dropped out of high school. -Messed around hacking computer games for a year. --Worked at a non-profit doing menial labor. --Showed I had aptitude for research. -Started with Excel and Access(SQL), writing macro's in VB. -Couldn't handle large enough datasets, started using MySQL. -Started PHP and MySQL to enhance websites. -That didn't scale well enough for the large datasets I was using, started using ZOPE. (If you live in MD, check this out, I designed/wrote the entire thing: www.marylandlantax.org) -Fell in love with writing ZOPE Python scripts to handle logic. -Wrote python scripts for data manipulation as well then (a lot of MySQLdb module work) -Got an internship this summer in computational chemistry at a pharmaceutical company. (doing high throughput docking) --Use python for just about every project. --Before I came they were using csh and perl (so I've had to become familiar with them, yuck) to call proprietary software that often doesn't work as advertised. --Started to become a linux power user (awk, grep, sort, uniq, etc...) Now my question is... am I a programmer yet? or still just a script kiddie? I've started to use classes regularly, so does that make it a yes? However, everything I've written this summer has been take data-->do something to each record-->output data That sounds like a script to me. However, I've created totally self contained "scripts" that does stuff in minutes that other "professional" software takes days to do. I'm not talking pushing a few SQL statements around like I used to, now it's taking millions of possible drug candidate molecules, breaking into chemically similiar sets, computing comparison matices, doing fuzzy logic to decide which is the best and in the end making sure the entire thing can run on a 128 processor linux cluster. Am I a programmer yet? The only class I've ever taken dealing with computers was 5 years ago on using CSS to ease webpage design. Oi, sorry, tomarrow's my last day at this internship, I could probably be knocking out 3-4 more python programs by then.=-) Without Python, I wouldn't know where the hell I would be. Thank you all! -Brian ---- Original message ---- >Date: 19 Aug 2004 07:16:40 -0700 >From: steve at ferg.org (Stephen Ferg) >Subject: Re: age of Python programmers >To: python-list at python.org > >> Finally, someone in my cohort :-). 52. > >I'm 58. > >Started programming in 1979 -- 25 years ago. Cut my teeth on Pl/I. >Later COBOL, Pascal, Basic, Java. For a while I liked REXX very much, >but it just ran out of steam. > >Been programming in Python for about 4 years. > >Perhaps we have a two-hump demographic: youngsters in teens and >twenties, and old farts in 50's. >-- >http://mail.python.org/mailman/listinfo/python-list From sjdevnull at yahoo.com Tue Aug 31 00:57:02 2004 From: sjdevnull at yahoo.com (G. S. Hayes) Date: 30 Aug 2004 21:57:02 -0700 Subject: "Content-Length" header References: Message-ID: <96c2e938.0408302057.61df147b@posting.google.com> "Justin" wrote in message news:... > some webservers are CASE SENSITVE about their urls and some are not. > unfortunately in order to standardize another part of my program I was > converting all the urls to .lower() Ouch. Outside of the Windows world, most systems are case sensitive; with respect to web servers, you'll find that many of the big ones (e.g. Yahoo, Google) are. The lesson to take away from this for the future is to never alter any data without very good reason. By doing so, you're throwing away potentially useful information. That means don't take the trailing slash off of filenames, don't turn that "e with accent" into a plain e, etc. Certainly there are times to munge your data, but if there isn't pressing reason to do so you're almost always best off keeping it as pristine as possible--and often you want to store it in pristine form and only munge it at the very time you HAVE to. Something related to think about: if most users use only letters in their passwords, making the passwords case-insensitive potentially makes it take crackers HALF the time to crack a password by brute force. By making the passwords case-insensitive you've thrown away information. (though in practice, users who would use all letters are unlikely to use mixed case; the point still remains, though) From dd55 at cornell.edu Thu Aug 19 11:42:50 2004 From: dd55 at cornell.edu (Darren Dale) Date: Thu, 19 Aug 2004 11:42:50 -0400 Subject: My only complaint about Python Message-ID: I love the language. I love the community. My only complaint is that Python for Windows is built with Visual Studio. It is too difficult to build python, or a module, from source. This is what open source is all about, isnt it? I even have a copy of visual studio, and I still cant build modules from source, because my academic copy is version 7. As a scientist funded by the NSF, I feel compelled to do all my work using free software (I feel compelled to use free software, regardless). And I feel compelled to contribute to the scientific capabilities of my favorite programming language. But this compiler issue is a big (and seemingly unnecessary) impediment. Will the BDFL ever split with Visual Studio? From noone at here.com Thu Aug 19 22:27:40 2004 From: noone at here.com (M. Clift) Date: Fri, 20 Aug 2004 03:27:40 +0100 Subject: Rita Sue and Bob too References: <7x7jruwnyc.fsf@ruckus.brouhaha.com> Message-ID: Thankyou to all of you, and so quick. More for me to study : ) All the best, M From ronaldoussoren at mac.com Sun Aug 8 05:51:11 2004 From: ronaldoussoren at mac.com (Ronald Oussoren) Date: Sun, 8 Aug 2004 11:51:11 +0200 Subject: decorators vs GIL In-Reply-To: References: <8YudnZoJ4NdLEYjcRVn-jA@speakeasy.net> <0bidnfbR2_PZOIjcRVn-pA@giganews.com> Message-ID: <7AEBFBED-E920-11D8-828E-000A95C77748@mac.com> On 8-aug-04, at 10:16, Anthony Baxter wrote: > On Sun, 08 Aug 2004 00:00:25 -0400, Istvan Albert > wrote: >> Just because someone sits down and codes it does not mean it >> should be added to the language. Features are forever, you >> cannot just can't eliminate them in the next version. > > The discussion on decorators has been going on for over 2 years > on python-dev. There is a broad concensus that they're a useful > feature, and are not _just_ being added for PyObjC. I sure hope not :-) [*]. I just happened to dumb enough to volunteer a use-case for decorators in the last round of discussions, and somehow this got misunderstood :-( I do believe decorators are generally useful, as shown by various examples shown on python-dev. The also happen to make live easier for users of PyObjC. Ronald [*] I'm one of the primairy developers for PyObjC, don't interpreted this a "-1" for decorators. From egbert.list at hccnet.nl Tue Aug 3 10:11:18 2004 From: egbert.list at hccnet.nl (Egbert Bouwman) Date: Tue, 3 Aug 2004 16:11:18 +0200 Subject: PyGTK overload In-Reply-To: <20040802132353.GB3648@grulic.org.ar> References: <20040731091225.GA1365@mirk.lan> <20040802132353.GB3648@grulic.org.ar> Message-ID: <20040803141118.GA2382@mirk.lan> On Mon, Aug 02, 2004 at 10:23:53AM -0300, John Lenton wrote: > have you tried, e.g., 'help gtk.Window' from the interpreter, or > 'pydoc gtk.Window' from the commandline? > No, I didn't, and I wonder why. It is very, very useful. Thanks. egbert -- Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991 ======================================================================== From simoninusa2001 at yahoo.co.uk Sat Aug 21 23:23:39 2004 From: simoninusa2001 at yahoo.co.uk (Simon John) Date: 21 Aug 2004 20:23:39 -0700 Subject: Global config option - import issues again..... In-Reply-To: Message-ID: Argh, it's not going to work anyway, I did a quick hack job and py2exe only imports the config it was built with, and doesn't change it at runtime. I'll have to think of some other language file system - maybe processing a text file instead of a python module.....? From del at mjclift.freeserve.co.uk Fri Aug 13 12:14:17 2004 From: del at mjclift.freeserve.co.uk (Calvin79) Date: Fri, 13 Aug 2004 12:14:17 -0400 Subject: control direction of list Message-ID: <2f2afc89dae36a5a8b23a0f3e623a333@localhost.talkaboutprogramming.com> Hi All, I was given this in an earlier post by Satchit. import random things = xrange(int(raw_input("choose no of things (1-8)? "))) state = [None,None] l = [] for x in things: tmp = random.choice('abcd') print state while tmp in state[0:2]: tmp = random.choice('abcd') print "choice ",x+1," is ", tmp l.append(tmp) state[x%2] = tmp print 1 Could someone help in showing me how to control it like this? That if 'a' is choosen it can only be followed by say b or d, if 'd' is choosen it can only be followed by c or b etc... I can see how to do this after the list has been generated with if statements, but that is impractical. As it is at the moment it stop two of the same letters being given one after another or the same letter occurring with only one space interviening. Thanks, Calvin From mlh at furu.idi.ntnu.no Mon Aug 23 16:49:09 2004 From: mlh at furu.idi.ntnu.no (Magnus Lie Hetland) Date: Mon, 23 Aug 2004 20:49:09 +0000 (UTC) Subject: Standard graph API? References: Message-ID: In article , Robert Brewer wrote: >> Is there any interest in a (hypothetical) standard graph API (with >> 'graph' meaning a network, consisting of nodes and edges)? > >1) Yes! :) >2) Only if it's in C. That would be up to the implementer. I'm only talking about defining an API -- not the implementation. (Cf. the DB-API.) [snip] >3) It would have to accept arbitrary objects. No "make your class a >subclass of GraphNode" garbage. Of course. Signature-based polymorphism and protocols all the way :) -- Magnus Lie Hetland "Canned Bread: The greatest thing since sliced http://hetland.org bread!" [from a can in Spongebob Squarepants] From rpw3 at rpw3.org Sat Aug 28 01:21:22 2004 From: rpw3 at rpw3.org (Rob Warnock) Date: Sat, 28 Aug 2004 00:21:22 -0500 Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> Message-ID: <4PGdnfsOfdDPi63cRVn-tA@speakeasy.net> Pascal Bourguignon wrote: +--------------- | $ telnet xahlee.org 80; | Trying 208.186.130.4... | Connected to xahlee.org. | Escape character is '^]'. | GET / HTTP/1.1 | | HTTP/1.1 400 Bad Request | Date: Fri, 27 Aug 2004 01:35:52 GMT | Server: Apache/2.0.50 (Fedora) | ^^^^^^^^^^^^^^^^^^^^^^ +--------------- So are you complaining about the fact that his hosting provider preloaded RedHat Fedora with Apache 2.0 for him? [A lot of them do, these days, 'cuz it's much cheaper than preloading RedHat Enterprise.] Or are you complaining about that perfectly correct error message which pointed out that you omitted a required HTTP/1.1 header? ;-} ;-} % telnet xahlee.org 80 Trying 208.186.130.4... Connected to xahlee.org. Escape character is '^]'. GET / HTTP/1.1 Host: xahlee.org HTTP/1.1 200 OK Date: Sat, 28 Aug 2004 05:16:44 GMT Server: Apache/2.0.50 (Fedora) Last-Modified: Fri, 13 Aug 2004 10:36:38 GMT ETag: "c41bc-87b-a8715980" Accept-Ranges: bytes Content-Length: 2171 Connection: close Content-Type: text/html Xah's Homepage ...[trimmed]... % -Rob ----- Rob Warnock 627 26th Avenue San Mateo, CA 94403 (650)572-2607 From b.niemann at betternet.de Fri Aug 27 04:17:16 2004 From: b.niemann at betternet.de (Benjamin Niemann) Date: Fri, 27 Aug 2004 10:17:16 +0200 Subject: lambda ?? In-Reply-To: <6f402501.0408270000.31ad1455@posting.google.com> References: <6f402501.0408270000.31ad1455@posting.google.com> Message-ID: lambda returns the functions, thus can be used *in* an expression or function call, when a callable is required. This is often a useful shortcut. But according to another thread 'lambda' is one candidate for things that are dropped in a future version of Python... Michael Foord wrote: > I'm starting to read through the developer works article on Functional > Programming - http://www-106.ibm.com/developerworks/library/l-prog.html > > It starts by giving some basic examples using lambda. What I'm > wondering is what's the actual difference between these two forms ? > > pr = lambda s:s > *and* > def pr(s): > return s > > Both bind the name 'pr' to a function object that does the same thing > ?? I know that lambda functions can only be a single expression...... > > Is it just a basic example (and so in this case there is no > difference).. or am I missing something. (What's the point of an > 'anonymous' function... if you give a name to it !!). > > Regards, > > Fuzzy > > http://www.voidspace.org.uk/atlatnibots/pythonutils.html From sholden at flexal.cs.usyd.edu.au Sat Aug 14 06:22:56 2004 From: sholden at flexal.cs.usyd.edu.au (Sam Holden) Date: 14 Aug 2004 10:22:56 GMT Subject: PyQt(Qt): unexpected scrollbars in QCanvasView References: <411dcfd0.649442281@news.compuserve.de> Message-ID: On Sat, 14 Aug 2004 09:33:51 GMT, Konrad Koller wrote: > For a card playing game I constructed a layout of 49 playing cards > (size of each: x=71, y=96) which are arranged in a 7X7 matrix side by > side. Accordingly the pysical size of the Canvas is x=71*7, y=96*7: > > in the main program: > canvas=QCanvas(497,672) > > class Board(QCanvasView): > def __init__(self,canvas,parent): > QCanvasView.__init__(self,canvas,parent) > > but QCanvasView produces a layout with scrollbars in both directions. > This is very annoying for the player because although the screen's > size is more than appropriate for a total layout only some of the > cards can be viewed without scrolling. The QScrollView documentation > states that as default QScrollView shows a scrollbar when the content > is too tall to fit and not else. What goes wrong? > I am using PyQt 3.11 and Qt 3.3.1 under Linux. > Thanks for any help. I would guess it is using the viewable size with the scrollbars to determine whether scrollbars are needed, rather than the size without them. If you know the scrollbars aren't needed you can manually turn them off: self.setVScrollBarMode(QCanvasView.AlwaysOff) self.setHScrollBarMode(QCanvasView.AlwaysOff) -- Sam Holden From rkern at ucsd.edu Tue Aug 31 23:51:15 2004 From: rkern at ucsd.edu (Robert Kern) Date: Tue, 31 Aug 2004 20:51:15 -0700 Subject: XML documentation stinks - help? In-Reply-To: References: Message-ID: Simon John wrote: > I'm sure this must be a PEP, but could someone look at the PyXML > documentation? > > I'm trying to evaluate XML on Python (to eventually use it with > XML-RPC) as apposed to Perl. > > The problem is, I can't find a simple demo or documentation that just > says how to create a parser object, and call the start/char/end event > handlers. > > With Perl's XML::Parser, it's that simple, you overload a > start/char/end handler that gets called for every element, then you > just create a hash of the data or whatever you want. > > Most of the sites I Googled don't even exist anymore or have either > incomplete documentation, out-of-date documentation, or have way > over-complex examples that don't even explain why their importing > modules or what they're doing. Did the Python/XML HOWTO not meet your needs? http://pyxml.sourceforge.net/topics/howto/xml-howto.html Note Chapter 5 on the SAX API, which looks like what you describe. It seems to be fairly straightforward to me. -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From arien_malec at yahoo.com.REMOVE Fri Aug 20 12:13:26 2004 From: arien_malec at yahoo.com.REMOVE (Arien Malec) Date: Fri, 20 Aug 2004 16:13:26 GMT Subject: Alternative decorator syntax decision References: Message-ID: "Paul McGuire" wrote in news:wXfVc.4524$Jn5.3509 at fe1.texas.rr.com: > "Arien Malec" wrote in message > news:Xns954AB8327A955arienmalecyahoocom at 64.164.98.7... >> M, any keyword option using "transform" >> >> (I care more about semantics than syntax) > I can interpret "any keyword option using "transform"" to match J1, > J2, or L. C2, J2 But my metavote is: make the sematics really clear. Arien From domcio_ at poczta.onet.pl Mon Aug 9 11:03:04 2004 From: domcio_ at poczta.onet.pl (Leszek) Date: Mon, 9 Aug 2004 17:03:04 +0200 Subject: logging on https - question Message-ID: Hi! Does anybody knows how to log on https page ? . This page has no html code for "name" and "password" (it uses servlets). Bank of Warsaw I'm a client of that bank (so I have "name" and "password") and want to automate checking my account. I'm a starting programmer in python, and this problem is unfortunately too complicated for me. Please, help me. Leszek From artur_spruce at yahoo.com Tue Aug 10 09:22:48 2004 From: artur_spruce at yahoo.com (AdSR) Date: 10 Aug 2004 06:22:48 -0700 Subject: Importance of C# (was Re: IronPython-0.6 is now available!) References: <278de0e.0407281353.27b6a457@posting.google.com> <5dydnZSDZaARoZXcRVn-ug@powergate.ca> <9418be08.0407292114.129c856f@posting.google.com> Message-ID: artur_spruce at yahoo.com (AdSR) wrote in message news:... > > From another thread, with minor correction: > > An interesting comparison, if you want to check it for yourself, is > one between the unittest module and what is described on this page: > > http://www.gigamonkeys.com/book/practical-building-a-unit-test-framework.html > > Both approaches are based on commonly used features and coding style > of their respective languages. I think this is good example of how > language vs. language comparisons should be done. And I forgot about the correction: How comparisons *could* be done is what I meant. AdSR From stnchris at xmission.com Tue Aug 31 19:25:31 2004 From: stnchris at xmission.com (Steve Christensen) Date: Tue, 31 Aug 2004 23:25:31 +0000 (UTC) Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <7xzn4gwgea.fsf@ruckus.brouhaha.com> <1gj7a1o.1a5d2q410jsn2kN%aleaxit@yahoo.com> <7xisb4xnh5.fsf@ruckus.brouhaha.com> <1gj7c1a.tfdm14p3hclcN%aleaxit@yahoo.com> <7xd61benm9.fsf@ruckus.brouhaha.com> <1gj82n3.1ylkr3nierngmN%aleaxit@yahoo.com> <1gj8848.1bouuroizku25N%aleaxit@yahoo.com> Message-ID: In article <1gj8848.1bouuroizku25N%aleaxit at yahoo.com>, Alex Martelli wrote: > Benjamin Niemann wrote: > ... >> Isn't the purpose of signatures that the importing program can trust the >> module? If it's implemented as you suggest, an attacker could just >> inject path to an unsigned module into PYTHONPATH to fool a program. How > > If the attacker is able to alter sys.path then it does not matter > whether zipfiles are even considered -- the attacker could simply > position a .pyc file early on the path. > >> about something like >> >> require_signature('mymodule') >> import mymodule > > This could be made to work, but only if _every_ module was so checked > before importing it; otherwise, even just one unchecked module could > easily subvert __import__ or other aspects of the import hook mechanism. > > So, if you're considering this approach, it makes more sense to switch > on module checking globally in an early phase of Python's startup > (because Python starts importing modules pretty early indeed). New > conventions will also be needed for signature of .py, .pyc, .pyo, and > .so (or other binary DLLoid files containing Python extensions). It doesn't look like anyone has mentioned the Python Cryptography Toolkit in this thread yet. (I have no affiliation with said project) http://www.amk.ca/python/code/crypto.html http://www.amk.ca/python/writing/pycrypt/pycrypt.html : 7.2 Demo 2: secimp and sign secimp demonstrates an application of the Toolkit that may be useful if Python is being used as an extension language for mail and Web clients: secure importing of Python modules. To use it, run sign.py in a directory with several compiled Python files present. It will use the key in testkey.py to generate digital signatures for the compiled Python code, and save both the signature and the code in a file ending in ".pys". Then run python -i secimp.py, and import a file by using secimport. For example, if foo.pys was constructed, do secimport('foo'). The import should succeed. Now fire up Emacs or some other editor, and change a string in the code in foo.pys; you might try changing a letter in the name of a variable. When you run secimport('foo'), it should raise an exception reporting the failed signature. If you execute the statement __import__ = secimport, the secure import will be used by default for all future module imports. Alternatively, if you were creating a restricted execution environment using rexec.py, you could place secimport() in the restricted environment's namespace as the default import function. -Steve From peufeu at free.fr Thu Aug 26 07:53:25 2004 From: peufeu at free.fr (=?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?=) Date: Thu, 26 Aug 2004 13:53:25 +0200 Subject: Proposal for removing self References: <5d83790c.0408252119.3e7da2a7@posting.google.com> Message-ID: There was the "with" keyword : with self: .member = something .member2 = .member3 + .member4 etc... it is a bit more implicit because of the "with"... anyway. From justin__devine at hotmail.com Mon Aug 16 14:10:39 2004 From: justin__devine at hotmail.com (JDevine) Date: 16 Aug 2004 11:10:39 -0700 Subject: Newbie 1st program Message-ID: Hey. I just finished my first python program. In fact it is my first program program at all. I went from zero knowledge to the current state in about 6 weeks. Check it out at http://gobblewin.sourceforge.net I need help for the next stage of development, I am also sure I could use a lot of advice on structure etc. My #1 priority is adding a threaded status bar to track downloads to this program. if you think you can help out let me know. Thanks From psXdaXsilva at esotericaX.ptX Mon Aug 23 19:11:20 2004 From: psXdaXsilva at esotericaX.ptX (Paulo da Silva) Date: Tue, 24 Aug 2004 00:11:20 +0100 Subject: "Socket" files? In-Reply-To: <1093050493.502706@jubilee.esoterica.pt> References: <1093035812.83612@jubilee.esoterica.pt> <4126824a$0$566$e4fe514c@news.xs4all.nl> <1093050493.502706@jubilee.esoterica.pt> Message-ID: <1093302968.204485@iceman.esoterica.pt> Paulo da Silva wrote: > Irmen de Jong wrote: > >> Marcos Dione wrote: >> > ... > >> ... >> from socket import * >> sock=socket(AF_UNIX,SOCK_STREAM) >> sock.bind("/tmp/mysocket") > > ... > This seems more logical. Besides there is also a "file" type > "fifo" where I was using mkfifo. > > I'll give it a try. Unfortunately I began to upgrade my Gentoo > Linux and I am busy now. OK. It works! I'll use mkfifo for "fifo" type and this for "socket" type. BTW, don't I need to close "sock.close()"? I don't want to do anything with the socket except keeping it on disk. From sbabbitt at commspeed.net Tue Aug 24 14:33:41 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Tue, 24 Aug 2004 18:33:41 GMT Subject: Debunking Art - fraudster with python AI engine? References: <4128f60b$1@news.unimelb.edu.au> Message-ID: <412b8a01$1@news.unimelb.edu.au> "Nick" wrote in message news:4128f60b$1 at news.unimelb.edu.au... > Hi, > > I recently went to an art exhibition, and one of the artists had an AI > engine projected onto a screen with a keyboard for visitors to type > questions in with. > > Curiously, I asked the artist if he had written the engine. He claimed > to have, but as far as I know, he has done no AI study, and only > started programming python some months ago. > > Naturally, I find it hard to believe he has picked up on natural > language processing and the other various skills required to write AI > engines in that time. My guess is he has a python AIML interpreter, > and he's found a default "brain" somewhere and tweaked it with some of > his own stuff in order to pass it off as his own. > > The engine could answer all the usual questions, like "what is the > meaning of life" (42), "what is your name", "how old are you" etc etc. > It was just a chatterbot, so ELIZA or a deriviative is marked off the > list. I am guessing probably an ALICE engine is behind it all. Does > anyone know any questions or commands one can issue the bot which > might identify it? It required all questions to start with a capital > letter, if thats any help. > > Cheers, > > Nick. Python is all about getting the proper module and using it. Do you believe those that use wxPython or Tk to be frauds. Tom [ 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 shalabh at cafepy.com Thu Aug 26 20:02:32 2004 From: shalabh at cafepy.com (Shalabh Chaturvedi) Date: Thu, 26 Aug 2004 17:02:32 -0700 Subject: Static properties In-Reply-To: <412DF4DD.4070302@berrs.net> References: <412DF4DD.4070302@berrs.net> Message-ID: Per Erik Stendahl wrote: > Hello everyone, > > Is it possible to define "static properties" in a class? Yes and no, depending on what exactly you want :) > Example: > I have a class, Path, that wraps a lot of os.* and os.path.* functions > (and others), so I can write things like this: > > x = Path('/usr/local/some/file') > if x.IsFile: > contents = x.Read() > ... > > Now, I would like to wrap os.getcwd(). I can do it like this: > > class Path: > def CurrentDirectory(): > return os.getcwd() > CurrentDirectory = staticmethod(CurrentDirectory) > > pwd = Path.CurrentDirectory() > > Question: Can I make CurrentDirectory a property? Just adding > CurrentDirectory = property(CurrentDirectory) after the staticmethod > line didn't work, unsurprisingly. :-) If you use raw descriptors and not properties, you can make computed class attributes: class CurrentDirectoryDesc(object): def __get__(self, obj, cls=None): return os.getcwd() class Path(object): CurrentDirectory = CurrentDirectoryDesc() print Path.CurrentDirectory print Path().CurrentDirectory Note that: - the classes are derived from object - you cannot make a settable class attribute this way (you have to use a metaclass for that) - if you subsequently assign Path.CurrentDirectory, you will overwrite the descriptor HTH, Shalabh From jack at performancedrivers.com Fri Aug 13 10:38:43 2004 From: jack at performancedrivers.com (Jack Diederich) Date: Fri, 13 Aug 2004 10:38:43 -0400 Subject: {SPAM?} Decorators? Why have a special construct to support a pattern? In-Reply-To: <200408120846.i7C8kirv006828@redpill.digitalventures.com.au> References: <2WFSc.12148$Nl1.3243@fe1.columbus.rr.com> <200408120846.i7C8kirv006828@redpill.digitalventures.com.au> Message-ID: <20040813143843.GP23725@performancedrivers.com> On Thu, Aug 12, 2004 at 04:58:41PM +0800, Simon Wittber wrote: > Decorators... > > Why do we need a special construct to support a pattern? > > Do lots of people really use decorators that often? I've said it in other places, writing foo = mutate(foo) is boilerplate. I don't like boilerplate - it takes time and is an extra step to get wrong. It is also boilerplate somewhere far away from the original definition which means it can easilly be overlooked or forgotten. -Jack From John.Marshall at ec.gc.ca Fri Aug 6 14:25:52 2004 From: John.Marshall at ec.gc.ca (John Marshall) Date: 06 Aug 2004 18:25:52 +0000 Subject: elements of decorator syntax suggestions In-Reply-To: References: Message-ID: <1091816752.3439.33.camel@mango.cmc.ec.gc.ca> On Fri, 2004-08-06 at 17:19, Steven Bethard wrote: > I think one of the biggest reasons we're having such problems coming > to any agreement on decorator syntax is that each proposal makes a > number of syntax decisions, not just one. For decorators, I see the > following decisions that must be made: > > 1) Indicator > > 2) Location > > 3) List notation > > 4) Indentation I think you have done a good job identifying and isolating what the issues are regarding decorator options. I think another thing that should perhaps be made clearer (maybe for me only?) is to identify, in order of importance/signfigance, the relationship between decorators and the function: 1) is the function/method signature more important than the decorators (to the programmer)? 2) do the decorators belong or are affected by the function? 3) what other constructs in Python say/imply "look ahead for what I am about to affect/define"? I understand that designing programming languages is sometimes an art rather than a science (natural languages a chock full of exceptions to the rule). But if the priority of functions and decorators are established, then I think this would help. In response to my own questions above: 1) From my perspective, it seems that almost everybody would say that the function (class also) signature is more important than decorators. For example, how many people would say "I wonder where the classmethod function is?" Instead, people would say, "Where is my function xyz()". This seems to argue for the decorators following (somewhere) after the signature. Of course highlighting editors can help by marking off function names and parameters, but this argument only serves to confirm that the signature is the KEY thing programmers are interested in. Apart from aesthetics, which are subjective and could be debated endlessly, I cannot see how one could argue otherwise. 2) Perhaps I am not understanding fully. Can someone explain how decorators before the function logically belong outside of the function definition block if they are intended to affect the function? Are the decorators meant to affect something other than the function? It seems to me that in every other situation in Python (please correct me if I am wrong) blocks are the way we are able to identify what belongs to what (e.g., local variable to a function). The current decorator approach says to me, "I belong to the class" (if a class is involved), or "I belong to the module" (if no class is involved). 3) In a sense, this point is somewhat related to #2. Does Python support an implicit "I am doing something now, on something I haven't defined, but which is coming up next" anywhere else than the decorator before function construction? Even in classes, Python forces the use of self.xxx (explicit). Hope this contributes to the discussion. John From anthonybaxter at gmail.com Tue Aug 24 01:23:51 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Tue, 24 Aug 2004 15:23:51 +1000 Subject: On consensus decision-making (was Re: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WEDONE?) In-Reply-To: References: Message-ID: On Tue, 24 Aug 2004 00:43:38 -0400, Peter Hansen wrote: > Until very recently, there appeared to be a resounding "NO" > from the BDFL himself to any thought that C1 might ever > be accepted. It was rejected early and rather explicitly, > if I recall correctly. Yes. > Given that, it shouldn't be surprising in the least that no one > has put up their hand to do something which would appear to > be a waste of time. This simply means that any arguments in favour of this form would need to be strong, _and_ take into account (and refute) Guido's reasons for originally rejecting this form. > Has anything really changed? Would it now be correct to say > that C1 has a serious chance of being accepted if someone would > just update the implementation to the state and quality (?) of > the other two? I'm just confused that a lot of people seem to think that voting in favour of C1 would achieve anything. Without a decent set of arguments (such as the impressive piece Robert wrote on the J2 form), and an implementation, voting for a form such as C1 is *entirely* pointless. (Of course, there's also my cunning plot to use this particular issue to get a couple more people involved in Python's development process - we now have at least one person who's obviously a good person to write up future PEPs, and another who's now delved into Python's innards in a non-trivial way.... moohahaha) From squirrel at WPI.EDU Tue Aug 17 13:30:31 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 17 Aug 2004 13:30:31 -0400 Subject: Flython In-Reply-To: References: Message-ID: On Tue, 17 Aug 2004, Michael Hudson wrote: > You'll almost certainly have a better time using the output of > Lib/compiler/transformer.py. Oh, wow! I didn't even notice that compiler could do that. Thanks! These trees look much more manageable than the tuples parser spits out... time for a code rewrite! From jjl at pobox.com Thu Aug 12 16:32:55 2004 From: jjl at pobox.com (John J. Lee) Date: 12 Aug 2004 21:32:55 +0100 Subject: Decorator "platform" References: <2nsoofF49frcU1@uni-berlin.de> Message-ID: <87zn50nll4.fsf@pobox.com> Reinhold Birkenfeld writes: [...] > What I have in mind is a sort of "decorator library" where everyone who > has written a useful function of that kind can share it with others, [...] God help us. <0.5 wink> John From eesun at free.fr Tue Aug 3 11:43:45 2004 From: eesun at free.fr (eesun) Date: 3 Aug 2004 08:43:45 -0700 Subject: dislin interfaced with tkinter Message-ID: <34c9b4fa.0408030743.594417f9@posting.google.com> Hi, I've downloaded the dislin package for the scientific plotting. And I have already created the application window with Tkinter (menu, canvas, status bar..). I want to integrate the Dislin plotting into the Tkinter application. For ex: show the dislin result on the Tkinter Canvas. Anyone can help? thx From rubyguru at hotmail.com Wed Aug 4 15:11:08 2004 From: rubyguru at hotmail.com (Chris Dutton) Date: Wed, 04 Aug 2004 19:11:08 GMT Subject: Does python support multi prototype. In-Reply-To: References: <2natmnFv86rjU1@uni-berlin.de> Message-ID: Jorgen Grahn wrote: > On Wed, 04 Aug 2004 02:17:11 GMT, Chris Dutton wrote: > >>angel wrote: >>>Does python support it? >> >>No, but it doesn't have to. The type of a function's arguments are not >>statically limited. > > ... > > Yes, but that's not as elegant in cases where the arguments' types has to > trigger very different processing. I can even imagine situations where > foo(S) and a foo(T) do completely different things, and still 'foo' is the > best name for both of them. So use the existing control flow structures to decide which set of code to execute at runtime. It's certainly not going to be as efficient as a compiled language which can make the distinction at compile time, but it's easily as elegant a way of thinking about the problem. def foo(bar): if (isinstance(bar, int)): ... elif (isinstance(bar, str)): ... else ... Now, if only Python had a smart "switch" style construct like Ruby or Groovy, since "isinstance" hurts my eyes. :-) def foo(bar) case bar when Integer ... when String ... else ... end end From anthonybaxter at gmail.com Tue Aug 24 02:57:47 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Tue, 24 Aug 2004 16:57:47 +1000 Subject: On consensus decision-making (was Re: Alternative decoratorsyntax - POLL RESULTS SO FAR - ARE WEDONE?) In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022E4F@exchange.hqamor.amorhq.net> References: <3A81C87DC164034AA4E2DDFE11D258E3022E4F@exchange.hqamor.amorhq.net> Message-ID: On Mon, 23 Aug 2004 23:06:08 -0700, Robert Brewer wrote: > Funny, I was just thinking today about Brett, trying to hand off the > summaries. But I concluded I'm 6 months to a year away from that in > terms of being able to _accurately_ decipher the majority of pydev > discussions. So your plot is working somewhat... ;) You'd probably be suprised at how easy it is to pick up most things in python-dev. One nice thing about the sanity of CPython's implementation (e.g. the much-maligned GIL) is that it's remarkably easy to follow. In addition, if there's things you're unsure about, most python-devver's are amenable to answering emails saying "um, what does this mean?" I think Brett has admitted that doing the python-dev summaries has resulted in his brain now being full of details about Python's internals, which he didn't previously have. Of course, it's also reduced him to a trembling wreck of a man, but hey, nothing's free... From sbabbitt at commspeed.net Fri Aug 6 11:32:52 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Fri, 6 Aug 2004 08:32:52 -0700 Subject: Getting around the GIL with POSH References: <2nhgq0Fvu3qU1@uni-berlin.de> Message-ID: <1091806765.919780@news.commspeed.net> "Jon Perez" wrote in message news:2nhgq0Fvu3qU1 at uni-berlin.de... > POSH, found at poshmodule.sourceforge.net , lets you share > Python objects across processes like you would among threads > and not have to resort to IPC mechanisms. > > Because separate processes do not share the GIL, this allows > them to be scheduled on multiple CPUs. > > Is anyone out there using POSH and is it reliable enough for > production use? Any plans to incorporate it into the Python > distribution? You shoul have a look at Pyro (Python Remote Objects) at http://pyro.sourceforge.net/index.html "It is an advanced and powerful Distributed Object Technology system written entirely in Python" sounds like what you need. Tom From FBatista at uniFON.com.ar Fri Aug 27 09:00:06 2004 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Fri, 27 Aug 2004 10:00:06 -0300 Subject: about presicion Message-ID: [alikakakhel3 at hotmail.com] #- I was wondering if it was posible to get very good presicion. I mean #- like to the to the 100 th or more decimal place. if so how? In Python 2.4 you'll have the Decimal module: Python 2.4a2 (#55, Aug 5 2004, 11:42:43) [MSC v.1310 32 bit (Intel)] on win32 ... >>> import decimal >>> decimal.getcontext().prec=100 >>> d = decimal.Decimal(2) >>> d.sqrt() Decimal("1.41421356237309504880168872420969807856967187537694807317667973799 0732478462107038850387534327641573") Enjoy it. . Facundo From fumanchu at amor.org Fri Aug 27 09:16:37 2004 From: fumanchu at amor.org (Robert Brewer) Date: Fri, 27 Aug 2004 06:16:37 -0700 Subject: Proposal for removing self Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E90@exchange.hqamor.amorhq.net> Alex Martelli wrote: > Coming back > to c.l.py after months of absence, and finding that, as usual, instead > of trying to use Python to best effect, people with mediocre Python > mastery keep trying to change Python (generally trying to > break some of > the best aspects of it, because they don't understand enough Python to > see why they're good) was of course depressing -- I'm proud of myself > for reacting constructively rather than lashing out or going > away again at once. So are we, Alex. :) I, for one, am glad you're back! I always find your commentary illuminating and engaging. Robert Brewer MIS Amor Ministries fumanchu at amor.org From bbands at yahoo.com Sun Aug 1 11:11:52 2004 From: bbands at yahoo.com (BBands) Date: 1 Aug 2004 08:11:52 -0700 Subject: Fuzzy Logic Message-ID: <79780d4f.0408010711.75df6f83@posting.google.com> Does anyone know of any fuzzy logic work done in Python? The only thing I have found is logic.py, which has gone missing from the Vaults of Parnassus and the original site, http://www.ourobourus.com/logic.py. --jab From davidf at sjsoft.com Mon Aug 2 07:09:58 2004 From: davidf at sjsoft.com (David Fraser) Date: Mon, 02 Aug 2004 13:09:58 +0200 Subject: Sending Mail via Extended MAPI In-Reply-To: <87llh18dqt.fsf@pobox.com> References: <87llh18dqt.fsf@pobox.com> Message-ID: John J. Lee wrote: > David Fraser writes: > > >>Does anyone have an idea how to send mail via the win32 mapi >>extensions that come with pywin32? It's very easy using Simple MAPI, >>but unfortunately brings up dialog boxes inn various versions of >>Outlook with security patches etc. It doesn't seem obvious from any >>documentation and the spambayes classes (which are cited as a good > > [...] > > I think that's the idea. Microsoft's plan to is to make the API for > sending mail without user intervention so incredibly complicated and > pulverisingly dull that the even the virus authors can't be > bothered... > Which is of course a little frustrating :-) > IIRC, there's a commercial COM server that wraps up Extended MAPI and > exposes a clone of the Simple MAPI interface. I think this must be Outlook Redemption ... anyway we'll try and see if we can implement what we need without them :-) Thanks David From aleaxit at yahoo.com Fri Aug 27 06:52:02 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 27 Aug 2004 12:52:02 +0200 Subject: How to generically transform a list? References: Message-ID: <1gj6gwy.1bqwzd6zhg7k3N%aleaxit@yahoo.com> Roel Schroeven wrote: > Roel Schroeven wrote: > > >> Just out of pure curiosity: Is there a langue that allows vertical and > >> horizontal slicing and dicing with the same built-in pattern? > > > > > > You can do it (sorta) in Python: use zip to turn the columns into rows > > and vice-versa, apply the slicing, than zip back: > > > > >>> l = [['a', 1, 11, 'aa'], ['b', 2, 22, 'bb'], ['c', 3, 33, 'cc']] > > >>> zip(*(zip(*l)[2:0:-1])) > > [(11, 1), (22, 2), (33, 3)] > > You end up with a list of tuples instead of a list of lists though. ...so you map(list, zip(*(zip(*l)[2:0:-1]))) if you're really keen on this approach. Personally, I find it a disaster. Alex From davids at webmaster.com Sat Aug 28 00:50:11 2004 From: davids at webmaster.com (David Schwartz) Date: Fri, 27 Aug 2004 21:50:11 -0700 Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4dyXc.25792$Ot3.22106@twister.nyc.rr.com> <878yc0ucyl.fsf@thalassa.informatimago.com> <20040827135423.154$1T@newsreader.com> Message-ID: wrote in message news:20040827135423.154$1T at newsreader.com... > "David Schwartz" wrote: >> I don't follow you at all. I think you'll find the most useful, >> meaningful complaints about, say, a Ford Explorer from the people who >> drive one every day. > And if they continue to drive one everyday, perhaps you would conclude > that their complaints are insincere. That's a load of crap. DS From me at privacy.net Mon Aug 2 05:11:48 2004 From: me at privacy.net (Duncan Booth) Date: 2 Aug 2004 09:11:48 GMT Subject: Microbenchmark: Summing over array of doubles References: <4d642979.0407312049.7a8aecab@posting.google.com> Message-ID: Christopher T King wrote in news:Pine.LNX.4.44.0408011840050.21160-100000 at ccc4.wpi.edu: > On 1 Aug 2004, Duncan Booth wrote: > >> I just had a brief look at the code you posted. Are you not concerned >> about accuracy in any of your calculations? Summing a 10 million >> element array by simply accumulating each element into a running >> total is guaranteed to give a lousy result. > > Lousy or not, I believe that's how numarray is implemented internally, > so at least all the benchmarks are the same. If you want accuracy > summing that many numbers, you're going to have to do it in software > (likely by summing each mantissa bit individually and reconstructing > the float afterward), so it will be abysmally slow (obviously not what > the OP wants). > My point being that speed isn't everything. Most applications doing large floating point calculations should be concerned about accuracy, and how not to add up a large array of floating point numbers was one of the first things I was taught in computer science classes. The fastest way to sum 10 million numbers (albeit at some considerable loss of accuracy): return 0 The 'correct' way to sum a large array of floats is, of course, to calculate a lot of partial sums and sum them. For example, naively, we might say that to sum the array we sum the first half, sum the second half and add the results together. This definition being recursive ensures that if the inputs are all of a similar size then all the intermediate calculations involve summing similarly sized values. A more sophisticated technique might also try to handle the case where not all values are a similar size. If you are worried about speed, then calculating partial sums is also the way to go: the naive technique used by the original poster leaves no scope for parallel calculation. It should be possible to write a slightly more complex loop in the C version that runs a lot faster on systems that are capable of performing multiple floating point instructions in parallel. From peter at engcorp.com Tue Aug 31 08:32:58 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 31 Aug 2004 08:32:58 -0400 Subject: use win32 COM in python In-Reply-To: References: Message-ID: Lin Jingxian wrote: > thanks, Dave and Peter > I can use pythoncom, but since there isn't pointer in python (is it?), I > dont know how to call the : int read(unsigned char* buf, int length) method > in python.what unsigned char* buf should be represented in python?thanks > again. I think Miki's answer is probably on target for doing that from pythoncom. That is, don't, but use the Dispatch interface instead. From ctypes, however, you can create special objects which ctypes can use as pointer types. For example, byref(sometype) is roughly equivalent to "sometype * xxx" when using ctypes. -Peter From luismg at gmx.net Sun Aug 22 18:50:21 2004 From: luismg at gmx.net (Neuruss) Date: 22 Aug 2004 15:50:21 -0700 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> <278de0e.0408220636.3ee25f9d@posting.google.com> Message-ID: <278de0e.0408221450.324e8178@posting.google.com> > Statements like that serve only to demonstrate the narrowness of > thought of the writer. Excuse me? It seems that you're missing the point. There's nothing wrong with my way of thinking, which is not "narrow" at all. I love Python. It's an excellent, fun, clear, well designed language and it is fast enough for 90% of the cases. But you can't deny that for some problem domains, it is slow. Very slow. The fact that some programmers can resort to c to speed up parts of the code is not convincing to me. I don't like C, I like python, and I'd love to see it performing at much better speed. I didn't want to start a silly thread to discuss wether python is slow or not. It is. Period. But it doesn't mean that it is useles or bad. Again, I think Python rocks, but I want more, and as far as I know, many people want more. That's why I wanted to know more about all those exciting projects aimed to improve python's performance. I love to read comments from people like Armin Rigo, who says that Psyco is the first step for world dominance of python (I love that attitude!). Or people like Mike Salib, who says that Python will be faster than C/C++ in two years, thanks to research on type inference and compiler improvements. All the other comments on this thread, regarding the main limitation for python's acceptance are true, but speed is critical, and this is were all efforts should be concentrated. So my intention when I started this thread, was to learn more about these projects, read other oppinions, get some news, etc... I didn't mean to start a a nonsense discussion! From bokr at oz.net Fri Aug 6 14:58:00 2004 From: bokr at oz.net (Bengt Richter) Date: 6 Aug 2004 18:58:00 GMT Subject: Confused about pep 318 References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: On Thu, 5 Aug 2004 21:16:00 -0500, Skip Montanaro wrote: > > Bengt> I too am very much against wasting '@' on @decorator! > >We could just switch completely to Unicode. Then we'd have all sorts of >punctuation characters available. How about > > # -*- coding: utf-8 -*- > \xe2\x98\xbadecorator > def f(): > pass > >? Yes, but then plain ascii editors would have an obscurity problem. If you really want this context-sensitive function-stacking operator whose stack is popped and applied to the result of the next def until the stack is empty (is this effectively the rule?), why not just leave it ascii encoded ;-) :)decorator def f(): pass Hm, perhaps '@' could be the beginning of a hidden Forth syntax for python? ;-) BTW, can anything (blank lines, comments, assignment statements) come between the @decorator line and the function def? Can the decorator line be conditional? E.g., if __debug__: @add_my_debug_printouts def foo(x,y): return x+y BTW2, is @something a purely a prefixed extension of def syntax, or is it a dynamic, code-generating operator that really does stack functions to be used when the very next function-definition code (not the callable function code) executes? If so, is @(expression) acceptable? I.e., could you write (untested ;-) @(lambda f: (lambda *args,**kwargs: long(f(*args,**kwargs)))) instead of @force_long_result ? I don't guess so ;-) Could you use a module attribute expression? @mydecorators.force_long_result Why not? (I don't have a copy of 2.4 to play with (nor the time :-( ) But then, why an internal single anonymous stack to pop decorator functions from? Why not use a named function source, that a programmer can control? That has an API or protocol(usage?), so a programmer-defined object can override the functionality? But if you have a named stack object, it could as well have ordinary methods for stack access, and we wouldn't need a special stack-function-for-a-narrowly-defined-purpose operator spelled '@' ;-) (BTW, does '@' stack functions or function names, actually? I.e., does some_name have to be bound prior to the '@some_name' line? If names are stacked, is a dotted name permissible? Probably not, right ;-) You could define a stack object that would push args of __call__ so your syntax could be decorate = __builtins__.metafunctions.push # say you prefer 'decorate' as name ... decorate(accepts_ints, returns_longs) def foo(x,y): return long(x+y) or decorate(accepts_ints) decorate(returns_longs) def foo(x,y): return long(x+y) You'd just have to arrange for def to use metafunctions.pop (hence overridable, if you want to shadow the standard metafunctions object in builtins) to get decorator functions. Of course a user-friendly alias for metafunctions.push could also exist in builtins. That's just a matter of choosing a name ("at_sign" ;-) (See other post for other angles on using a builtin object (and associated class) -- though the idea mix is evolving, and there are no warranties express or implied against contradiction or for version compatibility among them ;-) I know I have thrown out too many ideas to make a forceful pitch for any one of them. I just want to illustrate that there may yet be unthought-of alternatives to '@' that are more object-oriented and general, with potentially not that different a syntax in actual use, I.e., AT(decorator) # assuming you like 'AT' as an alias vs @decorator My USD.02 Regards, Bengt Richter From mwh at python.net Sat Aug 7 10:09:32 2004 From: mwh at python.net (Michael Hudson) Date: Sat, 7 Aug 2004 14:09:32 GMT Subject: static python build? References: Message-ID: mudd at vex.net writes: > Yes, thanks!, it was easy. I just edited Modules/Setup as follows: > > (1) Changed the commented *shared* line to the *static* line (see below). > > (2) Uncommented the modules (math, time, array) that I wanted incorporated > into the static libpython.a library. > > (3) Added lines for a couple other modules (strop & _random) that > previously weren't listed in the Setup file. I'm a bit surprised strop wasn't in there. _random probably should be, too. File a bug on SF? Cheers, mwh -- glyph: you're evil, too washort: I try not the good kind of evil the other kind -- from Twisted.Quotes From martin at v.loewis.de Thu Aug 26 02:06:11 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 26 Aug 2004 08:06:11 +0200 Subject: MSI Installer Problem: can't install 2.4a2 on new install of Win2kSP2 In-Reply-To: References: Message-ID: <412d7dcd$0$26184$9b622d9e@news.freenet.de> Richard Hanson wrote: > This installation package cannot be installed by the > Windows Installer service. You must install a > Windows service pack that contains a newer version > of the Windows Installer service. The problem is what this message says: you need a newer version of Windows installer. > Also, isn't there the general feeling that Win2kSP2 is about as good > as Windows gets (got)? W2k itself is fine. However, W2k ships with Installer 1.1, W2kSP2 updates that to Installer 1.11, W2kSP3 to Installer 2.0. The Python MSI file requires Installer 2.0. http://www.python.org/2.4/ says # [...] double-click python-2.4a2.msi to find out if your machine # supports MSI. If it doesn't, you'll need to install Microsoft # Installer first. Many other packages (such as Word and Office) also # include MSI, so you may already have it on your system. If not, you # can download it freely from Microsoft for Windows 95, 98 and Me and # for Windows NT 4.0 and 2000 You can find the download links on that page. If it used to work before the reinstallation, you either had a different service pack installed before, or some other software you had installed did a silent installation of a new installer release (such as Office 2k). Regards, Martin From thats at it.com Mon Aug 23 19:46:40 2004 From: thats at it.com (Baalbek) Date: Tue, 24 Aug 2004 01:46:40 +0200 Subject: Python future performance and speed In-Reply-To: References: <278de0e.0408211605.426e5129@posting.google.com> <278de0e.0408220636.3ee25f9d@posting.google.com> <278de0e.0408221450.324e8178@posting.google.com> Message-ID: <2lvWc.2843$WW4.34157@news4.e.nsc.no> Aahz wrote: > In article <278de0e.0408221450.324e8178 at posting.google.com>, > Neuruss wrote: >>I didn't want to start a silly thread to discuss wether python is slow >>or not. It is. Period. > > > Nope. Speed is relative. Is a car slow? Depends whether you're trying > to go five feet, five miles, fifty miles, five hundred miles, or five > thousand miles -- and it also depends on the alternatives available for > traversing that distance. Repeatedly claiming that Python is slow as an > absolute statement only shows your ignorance and unwillingness to listen > to other people. Python on today's machines probably runs a lot faster than C programs did on machines 20 years ago (or even 10 years ago). Baalbek From davebrok at soda.csua.berkeley.edu Fri Aug 13 00:38:14 2004 From: davebrok at soda.csua.berkeley.edu (David Pokorny) Date: Thu, 12 Aug 2004 21:38:14 -0700 Subject: Fine thread control, Run only n bytecodes References: <7x7jsynifw.fsf@ruckus.brouhaha.com> Message-ID: "Paul Rubin" wrote in message news:7x7jsynifw.fsf at ruckus.brouhaha.com... > "David Pokorny" writes: > > I'd like to be able to take a function or other chunk of code (that someone > > else has written), run it for, say 50 byte codes, and then return control > > back to my program/controlling thread until my program/controlling thread > > indicates that it wants to run the next 50 bytes codes of the foreign > > program, etc... > > This subject has come up before. If you're trying to timeshare, I > don't think that's really going to help you. Some bytecodes can take > unbounded amounts of time to execute. As far as I know, the worst problem is with the likes of BUILD_LIST BUILD_TUPLE UNPACK_SEQUENCE ... For those who are interested, I've found the most promising solution so far: a Python metacircular VM (written in Python). http://www.codespeak.net/pipermail/pypy-dev/2003q1/000048.html From paolo_veronelli at yahoo.it Thu Aug 12 15:52:38 2004 From: paolo_veronelli at yahoo.it (paolo veronelli) Date: Thu, 12 Aug 2004 21:52:38 +0200 Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: References: Message-ID: On Thu, 12 Aug 2004 13:32:32 -0400, Peter Hansen wrote: > paolo veronelli wrote: > >> On Wed, 11 Aug 2004 11:40:32 -0400, Peter Hansen >> wrote: >> class Klass: >> def meth0(x): >> return x >> mutate meth0: >> staticmethod >> >> mutate Klass.meth0: >> debugged >> >> reads good to me. > > This has the disadvantage of repeating the function name. I know > you call it an advantage... but arguably the biggest part of > the whole decorator "argument" revolves around whether or not > it's critical to put the decorator right up above the "def" so > that it can't be missed. If the method you describe above was > deemed acceptable, then I think we'd be sticking with the > current approach that just reads "func = decorate(func)". This 'old' method doesn't allow to prepone it,I think a statement was the way to allow this ,but why impone it? class Klass: mutate meth0: staticmethod def meth0(x): return x is acceptable but accept everywhere statements like @staticmethod Klass.meth0 is the minimum on the pythonic way. Paolino -- ....lotta dura per la verdura From ajsiegel at optonline.com Mon Aug 16 11:54:13 2004 From: ajsiegel at optonline.com (Arthur) Date: Mon, 16 Aug 2004 15:54:13 GMT Subject: PEP 318 decorators are not Decorators References: Message-ID: On Sun, 15 Aug 2004 18:29:52 GMT, Arien Malec wrote: >Skip Montanaro wrote in >news:mailman.1662.1092523102.5135.python-list at python.org: > >> >> Arien> 3) Won't most programmers think GoF decorators before >> Arien> compiler syntax tree decorators? >> >> Skip> Not if they are unfamiliar with the GoF patterns (myself >> included). >> >> Arien> Google: [~62,000 : ~130 mentions of each sort of decorator] >> >> ... >> >> BFD.... The thing is, just because in a verbal Rohrschach >> test you think "GoF" when someone says "decorator" doesn't mean >> everybody else will (or should). Correct. I would think simply that "decorate" would be descriptive in its own right. As obscure as the GOF reference might be to some, the alternative references justifying the naming seem to be off the map in terms of obscurity. So let's assume a blank slate. And all we want is the word to be descriptive. And it seems to me the naming is in fact descriptive - but of the syntax, not the functionality. Which is OK, I guess, if we accept it as that. As there are already a number of compromises being made in the addition of this to the language, I just think of this as one more. > >Clearly, Python can choose any name for the auto-function-transformation >syntax in question, but it's rather willfully confusing to choose a name >that's heavily identified with a profoundly different semantics that's >superficially similar in intent. Again, a little different if we think of it as describing the syntax, not the functionality. Yes the ambiguity, I agree, is bad. And yes, I agree, willful, to an extent. Or at least willful to the extent that there is little interest in truly justifying the choice of terminology, and specifung whether we are referencing the syntax or the functionality in the choice of the terminology. This ambiguity is to the essence of decorators, maybe both as syntax and as functionailty. But it is not the first time I have issues with python-dev folks using ambiguity as gloss. Art From squirrel at WPI.EDU Sun Aug 1 19:54:58 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Sun, 1 Aug 2004 19:54:58 -0400 Subject: Microbenchmark: Summing over array of doubles In-Reply-To: <4d642979.0407312049.7a8aecab@posting.google.com> References: <4d642979.0407312049.7a8aecab@posting.google.com> Message-ID: On 31 Jul 2004, Yaroslav Bulatov wrote: > I'm doing intensive computation on arrays in Python, so if you have > suggestions on Python/C solutions that could push the envelope, please > let me know. If you're doing mostly vector calculations as opposed to summing, I've been doing some work on adding SIMD support to numarray, with pleasing results (around 2x speedups). I've also done some work adding local parallel processing support to numarray, with not-so-pleasing results (mostly due to Python overhead). Regarding your results: numarray should be just as fast as the -O2 C version. I was puzzled at first as to where the speed discrepancy came from, but the culprit is in the -O2 flag: gcc -O2 noticies that sum is never used, and thus removes the loop entirely. As a matter of fact, there isn't even any fadd instruction in the assembler output: call clock movl %eax, %esi movl $9999999, %ebx .L11: decl %ebx jns .L11 subl $16, %esp call clock As you can see, the 21ms you're seeing is the time spent counting down from 9,999,999 to 0. To obtain correct results, add a line such as 'printf("%f\n",sum);' after the main loop in the C version. This will force gcc to leave the actual calculation in place and give you accurate results. The above fix will likely render numarray faster than the C version. Using gcc -O3 rather than gcc -O2 will get fairer results, as this is what numarray uses. Is there any reason why in the Python/numarray version, you use Numeric's RandomArray rather than numarray.random_array? It shouldn't affect your results, but it would speed up initialization time a bit. There are a few inefficiences in the pytime module (mostly involving range() and *args/**kwargs), but I don't think they'll have too big of an impact on your results. Instead, I'd suggest running the numarray/Numeric tests using Psyco to remove much of the Python overhead. For completeness, I'd also suggest both running the Java version using a JIT compiler such as Kaffe, and compiling it natively using gcj (the latter should approach the speed of C). From mensanator at aol.com Mon Aug 30 13:05:52 2004 From: mensanator at aol.com (mensanator at aol.com) Date: 30 Aug 2004 10:05:52 -0700 Subject: about presicion In-Reply-To: <1gjc13i.rx89x319njqe2N%aleaxit@yahoo.com> Message-ID: Alex Martelli wrote: > Mensanator wrote: > > > >Subject: Re: about presicion > > >From: Peter Hansen peter at engcorp.com > > >Date: 8/28/04 10:31 PM Central Daylight Time > > >Message-id: > > > > > >Ali wrote: > > > > > >> The decimal module comes with python 2.4? I have 2.3, :(, what do I do? > > > > > >The obvious answer is, well, obvious. The real question is > > >what's stopping you from upgrading? > > > > I just tried it and found out it's not compatible with gmpy. > > By "it" do you mean Decimal, or Python 2.4 alpha 2? By "it", I meant gmpy 1.0 and Python 2.4. Trying to import the module says it can't use the Python23.dll. > I think gmpy should > build happily with the latter, I'm using the pre-built Windows binary distribution. I wouldn't know how to re-build it. I assume that when Python 2.4 is final, I newer compatible version of gmpy will become available. > and interoperate sensibly with Decimal > anyway -- as gmpy's author I'd be quite happy to fix gmpy if it's broken > in either respect. Were you aware that there is apparently a memory leak in the gmpy.divm() function? Calling it several million time caused my computer to run out of virtual memeory. Luckily, I was able to work around it using the gmpy.invert() which didn't consume any memory regardless of how many times it was called. > > > Of course, I wouldn't need gmpy to get big floats, but I > > would then lose all the math functions like linear congruence > > and modular inverse that my programs depend on. > > > > So I, for one, will have to wait for the rest of the world to > > catch up to 2.4. > > 2.4 is not currently recommended for production work (that's why it's in > Alpha -- very good for an alpha, but it's still not a final release). I don't do any production work. I'm just a hobbyist, so it's not a big deal. > But such support modules as gmpy need to get moving to support 2.4 in > order to be ready for it well before final release... > > > Alex From richardjones at optushome.com.au Mon Aug 23 00:52:42 2004 From: richardjones at optushome.com.au (richard) Date: Mon, 23 Aug 2004 14:52:42 +1000 Subject: Alternative decorator syntax decision References: Message-ID: <4129781a$0$30602$afc38c87@news.optusnet.com.au> FWIW J2 J2 J2 Richard From tom at scoosh.com Wed Aug 18 17:54:25 2004 From: tom at scoosh.com (tom at scoosh.com) Date: Wed, 18 Aug 2004 22:54:25 +0100 Subject: MSI Installer issues References: <411231C8.3020308@interlink.com.au> <411241F5.3080602@v.loewis.de> <1f7befae040805103911610582@mail.gmail.com> <411274C0.4070300@v.loewis.de> <1f7befae04080623276089908e@mail.gmail.com> <4114A02F.7060906@v.loewis.de> <2jpfh0dsv97dkvflmvnu2ac9h1c91i3721@4ax.com> Message-ID: "Richard Hanson" wrote in message news:2jpfh0dsv97dkvflmvnu2ac9h1c91i3721 at 4ax.com... > [NB: This post contains little of substance -- the gratitude is > real, however.] > > [Tim Peters wrote:] > > >[...] "low-res" may be a feature, as some > >people have very low screen resolution settings and very large fonts. > > My Fujitsu LifeBook P1120 (Win2k SP2) has a 1024x600 pixel screen > (and tweaked fonts to compensate for the rapidly worsening > lighting conditions coincidentally appearing just as I age > ). > > A common problem I run into is that the occasional dialog box is > too tall for the available screen real estate. > > (This problem is exacerbated by my preference to have the taskbar > not hide -- driving Windows is difficult enough without having a > not inconsiderable amount of third-party-apps sitting in my > systray helping to clue me in on just what-all-in-hell is going > on with this machine. This strategy sometimes even works. ) > > In any event, while the current (2.4a2) MSI installer's dialog > box is one of those too-tall ones, thankfully, Martin's MSI > installer dialog thoughtfully provides scrollbars to make dealing > with the problem much less onerous. > > Martin's too-tall-for-my-screen installer is the *only* too-tall > dialog I've encountered which *has* provided the scrollbars -- > including some from BIG_NUM-bucko corps. > > So, no particular point. I just wanted to say good job to all the > contributors -- thanks! > > -- Richard > > -- > R Hanson [The mangled email addie below works.] > sickolefartnewsguycom From squirrel at WPI.EDU Tue Aug 3 09:43:40 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 3 Aug 2004 09:43:40 -0400 Subject: How to dynamically access Numeric subarrays In-Reply-To: References: Message-ID: On Tue, 3 Aug 2004, Gaubitzer Erwin wrote: > So my questions to out there: > How can I extract a (Numeric Python) subarray whose indices > have to be built dynamically. The Numeric function take() might meet your needs: >>> from Numeric import * >>> a = array([[[1,2],[3,4]],[[5,6],[7,8]]]) >>> take(a,(0,),0) array([ [[1, 2], [3, 4]]]) >>> take(a,(1,),0) array([ [[5, 6], [7, 8]]]) >>> take(a,(0,),1) array([[ [1, 2]], [ [5, 6]]]) >>> take(a,(0,),2) array([[[1], [3]], [[5], [7]]]) The second argument specifies which indices to take, and the third argument specifies to which dimension to apply the indices. Note that take() returns an array of the same rank as that of its input; this may not be what you want. To obtain an array of one less dimension, you'll need to reshape it. A function like the following may be helpful: def takeslice(a,index,dimension): r = take(a,(index,),dimension) s = shape(r) return reshape(r,s[:dimension]+s[dimension+1:]) This will only accept single indexes to slice, rather than a tuple, but will return you an array of rank N-1 from that which it is passed: >>> takeslice(a,0,0) array([[1, 2], [3, 4]]) >>> takeslice(a,1,0) array([[5, 6], [7, 8]]) >>> takeslice(a,0,1) array([[1, 2], [5, 6]]) >>> takeslice(a,0,2) array([[1, 3], [5, 7]]) Also of tangential interest is the ... operator. This magic operator, given to a slice, means "replace me with however many : are needed to make this work". It won't necessarily help your situation, but it's a handy thing to know: >>> a[0,...] array([[1, 2], [3, 4]]) >>> a[1,...] array([[5, 6], [7, 8]]) >>> a[...,0] array([[1, 3], [5, 7]]) Hope this helps, and is understandable :) From "rff_rff\" at (remove)yahoo.it Tue Aug 31 06:58:23 2004 From: "rff_rff\" at (remove)yahoo.it (@(remove)yahoo.it) Date: Tue, 31 Aug 2004 10:58:23 GMT Subject: [IronPython] Jim Hugunin's web log. In-Reply-To: References: Message-ID: David Wilson ha scritto: > For anyone who is excited about IronPython and it's consequences, you > might find Jim Hugunin's web log to be of particular interest. I didn't > see an announcement for this anywhere so here it is: > nice to hear, thanks > Other random thoughts: my experiences of the Python community versus, > eg., the perl community make me believe that Pythonistas are generally > more accepting of commercial solutions than their open source weenie > perl counterparts (*duck*). I'm still unsure as to whether or not this > should be considered a Microsoft marketing strategy for making in-roads > into the "open source scripting market". Imo MS has always played with scripting languages. The Shares Source CLI used perl.exe in its build process (maybe it still does), and IIRC MS owns part of ActiveState. Plus, in a presentation of MSH/Monad/"the new cmd.exe" they mentioned it being 'as powerful as perl ,python or ruby'. From tjreedy at udel.edu Mon Aug 2 21:03:30 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 2 Aug 2004 21:03:30 -0400 Subject: Timing Difference: insert vs. append & reverse References: <35b736b9.0408020330.53b24ed3@posting.google.com> <35b736b9.0408021152.4c1ab752@posting.google.com> Message-ID: "John Keeling" wrote in message news:35b736b9.0408021152.4c1ab752 at posting.google.com... > expect. I've also noted an approximate two time difference between > "del list[index] and list.pop(index)". Here is one way to get some insight into such things: >>> def ldel(lisp, index): ... del lisp[index] ... >>> def lpop(lisp, index): ... return lisp.pop(index) ... >>> import dis >>> dis.dis(ldel) 0 SET_LINENO 1 3 SET_LINENO 2 6 LOAD_FAST 0 (lisp) 9 LOAD_FAST 1 (index) 12 DELETE_SUBSCR 13 LOAD_CONST 0 (None) 16 RETURN_VALUE >>> dis.dis(lpop) 0 SET_LINENO 1 3 SET_LINENO 2 6 LOAD_FAST 0 (lisp) 9 LOAD_ATTR 1 (pop) 12 LOAD_FAST 1 (index) 15 CALL_FUNCTION 1 18 RETURN_VALUE 19 LOAD_CONST 0 (None) 22 RETURN_VALUE You can be pretty sure that the specific opcode DELETE_SUBSCR (ipt) is faster than the generic CALL_FUNCTION, which will eventually call (I presume) the same C code. (The extra attribute lookup and load take some extra time too, but the call should be the main culprit). Terry J. Reedy From aleaxit at yahoo.com Sat Aug 28 05:32:39 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 28 Aug 2004 11:32:39 +0200 Subject: Question about references/copies References: Message-ID: <1gj870c.dzzhcpvby7ozN%aleaxit@yahoo.com> Henning Kage wrote: > I'm using Python only for some months now and I'm wondering, whether such > assignments as above "As above" _where_? > are creating bitwise copies of an object or just > recieve a reference. That means I wanted to know, wheter Python in general > differs between references and copies: > > class someclass: > def __init__( self, otherobject): > self.someattribute = otherobject Python makes no copy unless you explicitly ask for a copy -- what you get is always a reference. There are several ways to ask for copies -- the most general and powerful ones you'll find in standard library modules copy (both copy.copy and copy.deepcopy -- all other ways of asking for a copy, except copy.deepcopy, get shallow copies). The only area where one might have some doubt is _slicing_. When you code x=y[z:t] you're getting a (shallow) copy, if y belongs to any of the builtin types that implement slicing, BUT there are important third-party extensions whose types behave differently -- specifically, Numeric; if the type of y is Numeric.array, then x shares (some of) the data of y. So we can say that Python _allows_ third-party and user-coded types with slicing that works by data sharing, even though the preferred semantics of slicing is by (shallow) copy. > And my second question is, whether I should use a cast in such cases or > not (I know, a cast isn't mandatory here...) Python does not really have the concept of a cast. Something that looks like a cast to you is probably one of the ways to ask for a copy: for example, if x is a list, list(x) is a (shallow) copy of x -- if y is a dict, dict(y) is a (shallow) copy of y, and so on. If you take an argument X that is of any iterable type, and you need to perform local operations on the items of X (which will not risk altering the original value of X), it is quite common to start with something like: X = list(X) if X was already a list this makes a copy (so the original does not get altered); if X was, say, a tuple, an open file, a dict, a string, ..., in other words any bound iterable, this in any case ensures X is now a list with that iterable's items (be careful: some iterables change state when iterated upon -- if X was a file, that file object is now at end-of-file, and the caller may need, if feasible, to call its method seek to get that file back to the previous state, for example -- so the "will not risk altering" tidbit above does need qualification). So anyway you might now call such mutator methods on X as sort, reverse, extend, pop -- all the nice methods that list offers and other iterable types don't -- and in the end presumably return or store some result based on the suitably-mutated X. Another similar operation that you may do reasonably frequently as your familiarity with Python grows is to ensure you have an _iterator_ for a generically _iterable_ argument, and sometimes the best way is something like: X = iter(X) you don't get many methods in X this way (basically, only X.next...) but you do ensure that X "keeps state" that tracks its current iteration. Note a big difference here: if X is already an iterator, iter(X) will NOT make a copy -- it wll return a reference to X unchanged. An example generator using this technique: def interleave(X, Y): X = iter(X) Y = iter(Y) while True: yield X.next() yield Y.next() not necessarily the absolute best approach, but pretty clear -- and the calls to iter are indispensable here, in case X and/or Y as originally passed were iterABLES that are not iterATORS such as lists etc. Alex From manuelbastioniNOSPAM at tin.it Sun Aug 29 12:15:08 2004 From: manuelbastioniNOSPAM at tin.it (manuel) Date: Sun, 29 Aug 2004 16:15:08 GMT Subject: possible python bug here In-Reply-To: References: Message-ID: Peter Kleiweg wrote: > manuel schreef: >>c=b[:] #c is a totally new list cloned from b, it's not an alias! > > > No it isn't. You didn't make a deep copy. Oh..thank you very much! From beliavsky at aol.com Mon Aug 16 17:54:15 2004 From: beliavsky at aol.com (beliavsky at aol.com) Date: 16 Aug 2004 14:54:15 -0700 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: <3064b51d.0408161354.618056ef@posting.google.com> Peter Hansen wrote in message news:... > Antoon Pardon wrote: > > > Op 2004-08-16, Peter Hansen schreef : > >>Did you really not indent your code in those languages consisntly > >>anyway? > > > > I can't answer for keith, but my answer is that it depends on > > what you consider consistent. > > > > My indentation was consistent with the structure of the algorithm. > > That is not necesarrily the same as the structure you implemeted > > that algorithm in. > > Huh? How does an algorithm have structure that affects > indentation? It sounds like you are talking about some kind > of artistic considerations here. > > > I think that I should be the final judge of what is the most > > appropiate way to use indentation, not the compilor/interpreter, > > even if it agrees with me. > > So did you indent your code such that consecutive lines were > not indented to the same identation level even when they were > conceptually, logically, *algorithmically* part of the same > block? I think you are getting a little religious about indentation. I mostly indent Python the way I'd indent Fortran, but there are some inflexibilities in Python: (1) I use a blank line to separate functions. I don't like being forced to indent every line within the body of a function. (2) Nested loops can *sometimes* be thought of as a single loop and indented that way. I don't think the indentation do i=1,n do j=1,n do k=1,n x(i,j,k) = some_func(i,j,k) end do end do end do is necessarily bad. If there were other code between the do statements, I would indent each loop. (3) Having a labelled end-of-loop statement lets you exit the desired number of nested loops in a clean way. In the following Fortran code you can exit any of the nested loops. How would you simulate this control flow in Python? ido: do i=1,n ! some code if (foo) exit ido ! exit outer loop jdo: do j=1,n ! some code if (boo) exit jdo ! exit middle loop do k=1,n ! some code if (goo) exit ! exit inner loop end do end do jdo end do ido From h.b.furuseth at usit.uio.no Fri Aug 6 11:08:29 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 06 Aug 2004 17:08:29 +0200 Subject: [Newby question] List comprehension References: Message-ID: Eelco Hoekema wrote: > Batista, Facundo schreef: > >> Now, explain me why a list comprehension is better here. > > Are they better? Don't know. In Dive into Python, Mark Pilgrim states > compared to list comprehensions, for loops are a waste of time. Not > sure what he means by that, though. List comprehensions are faster. > I just like them, that's all. Well, in your example you could cheat and use the for statement as an assignment statement: [(root, songs) for (root, dir, files) in os.walk(os.path.abspath('.')) for songs in (filter(song, files),) if songs] However, if you like that sort of tricks, try Perl. Or submit a proposal to extend the list comprehension syntax: [(root, songs) for (root, dir, files) in os.walk(os.path.abspath('.')) with songs = filter(song, files) if songs] -- Hallvard From anthonybaxter at gmail.com Tue Aug 24 22:29:04 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Wed, 25 Aug 2004 12:29:04 +1000 Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? In-Reply-To: References: Message-ID: On 24 Aug 2004 13:53:58 -0700, Jess Austin wrote: > The natural short version of "decorate" would be "dec" and there is > sort of a natural parallelism with "def" there. I hesitate to > nominate it because it _feels_ like a word that at least ten people on > c.l.py will detest. 'dec' is also going to clash with a lot of code that uses that. That's going to be a problem with pretty much any short keyword. > Maybe "decor"? It isn't any longer than "class", and I think we can > predict it will be typed less than 1/10 as often. But this reasoning > could also excuse "decorate", so I'll stick with that. I'm also open > to any transitive verb that can be designated to mean _exactly_ what > "decorate" means now. decor is better - I can't find any uses of it in the Python code I just grepped over... From ajsiegel at optonline.com Mon Aug 16 09:28:53 2004 From: ajsiegel at optonline.com (Arthur) Date: Mon, 16 Aug 2004 13:28:53 GMT Subject: Anyone use VPython? References: <8f17f4bc.0408141932.46b7c405@posting.google.com> <69juh0dalfeu39fpvvvcb56ukovl0o1fsb@4ax.com> <8f17f4bc.0408151258.35874dbc@posting.google.com> Message-ID: <5nc1i0pi0rt4992sn2vl25ikicu6bq9j9i@4ax.com> On Mon, 16 Aug 2004 00:50:12 GMT, Arthur wrote: > >Experiment from the IDLE prompt. Oops. I forgot. I really did. What IDLE prompt? The VPython Windows distribution has the gaul to overwrite the conifig-main.def file in the idlelib directory changing the default behavior of IDLE on start-up to be a text editor, rather than an interactive prompt. This despite the fact that: a) The person responsible for configuring the distribution knows that the developers of IDLE =- specifically one GvR - made a clear statement as to wanting the prompt as the default start-up. b) The new IDLE has specifcally added the ability for user defined configuration of options without touching anything in the idlelib directory. c) This kind of overwrite of lib files, it seems to me, is bad form in any case. The fact that I think that the decision is also ridiculous, on its merits, being totally besides the point. The OP, depending on his profile, may in actual fact have no idea what I am talking about by referring to the IDLE interactive prompt - having downloaded VPython. I had made an issue of this - again - recently on edu-sig. To a resounding thud of reaction. But this little exhange proves at least, to myself, that I am attacking something real. Not just looking to pick a fight. Art From FBatista at uniFON.com.ar Mon Aug 9 16:23:23 2004 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Mon, 9 Aug 2004 17:23:23 -0300 Subject: Question Message-ID: [Dag Hansteen] #- >>> s = "2+2" #- >>> answer = int(str(s)) #- Traceback (most recent call last): #- File "", line 1, in ? #- answer = int(str(s)) #- ValueError: invalid literal for int(): 2+2 #- How do I this ? I have a string with a such expression and I want to return the answer in a variable. >>> s = "2+2" >>> r = eval(s) >>> r 4 >>> Be aware of potential malicious code that could get into the eval(). . Facundo From sbabbitt at commspeed.net Thu Aug 26 22:00:52 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Thu, 26 Aug 2004 19:00:52 -0700 Subject: tarfile's tar.extractfile() file-like object incompatible with pickle.load()? References: <3e6d6c21.0408261043.264c3a2d@posting.google.com> Message-ID: <1093572564.733113@news.commspeed.net> "Matt Doucleff" wrote in message news:3e6d6c21.0408261043.264c3a2d at posting.google.com... > Hi everyone! I must be doing something wrong here :) I have a > tarball that contains a single file whose contents are a pickled > object. I would like to unpickle the object directly from the tarball > using the file-like object provided by extractfile(). Attempts to do > this result in EOFError. However if I first extract to a temporary > file, then unpickle from there, it works. The below code reproduces > the problem (on my machine at least). I'm running Python 2.3.4, > manually installed on Debian Woody (original python removed). Thanks! > > This sample code creates (and then removes) files in the tmp directory > and in the current working directory. > > # demonstrates extractfile/unpickle failure (bug?) > > # pickle a dict to a temp file > # create tar file, add temp file to it, close tar file > # open tar file for reading > # obtain file-like object for pickled file using extractfile() > # attempt to unpickle dict from file-like object > # fails with EOFError exception > > import tarfile > import pickle > import tempfile > import os > > if __name__ == '__main__': > try: > hashtopickle = { 'a' : 1, 'b' : 2 } > > # pickle to temp file > (fd, tmpfilename) = tempfile.mkstemp() > tmpfile = os.fdopen(fd, 'w') > pickle.dump(hashtopickle, tmpfile) > tmpfile.close() > > # create tar; add temp file > tar = tarfile.open('tarpickle.tar', 'w') > tar.add(tmpfilename, 'pickledhash') > tar.close() > > # remove temp file > os.remove(tmpfilename) > > # open tarfile for reading, get filelike > tar = tarfile.open('tarpickle.tar', 'r') > filelike = tar.extractfile('pickledhash') > > # fails > hashcopy = pickle.load(filelike) > > finally: > # cleanup > os.remove('tarpickle.tar') It occurs to me that you need to do, hashcopy = pickle.loads(filelike) if filelike is a string. Tom P.S. have a look at pickle.dumps() From peufeu at free.fr Fri Aug 13 02:47:30 2004 From: peufeu at free.fr (=?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?=) Date: Fri, 13 Aug 2004 08:47:30 +0200 Subject: Yet another PEP318 References: <20040812090056.00001e31@titan> <7ttmh0t8c3cogtbhhnp1ohqu8b51pda461@4ax.com> Message-ID: Proposal : Make def an expression (always returns the function): # this one behaves as usual def funcname(params): function body # this one is new # it allows us to name a function (func.__name__ ?) and also use it in expressions variable = def funcname(params): function body # or variable = def (params): function body # or return def funcname(params): function body Now we could write : funcname = classmethod( def funcname( params ): body ) But it looks lispish and introduces a lot of confusing parentheses... Now, I propose (oops) a new operator, whatever name it has, which means "the value of the expression on the next line of code". Let's say this is a new use for "*" : a = function1( x,*,z ) function2( f,g,h ) This would be translated by the compiler as a = function1( x,function2( f,g,h ),z ) So we can have : funcname = decorator1(*) decorator2(*, other params) def funcname( params ): function body What do you think ? Yet another proposition : execute: funcname = classmethod( funcname ) after: def funcname(params): body On Thu, 12 Aug 2004 12:33:50 -0400, Roy Smith wrote: > Arthur wrote: >> I must say that after days of waffling, and I think an honest effort >> to accept where things were going, I woke this morning hating >> @decorator. >> >> The existing syntax for this kind of transformation is, in fact, >> exactly what one would expect: >> >> foo=staticmathed(foo). >> >> That is the universal langauge for transformations. And when we try >> to explain to anybody what it is that @decorator means, we go back to >> the pseudo code that is in fact the existing syntax. > > I'm with Arthur. > > I think the core problem is that the def statement is kind of wierd. It > does two different things. First, it creates a function body, then it > binds the function to a name. > > One of the objections to: > > def foo (): > whatever > foo = decorator (foo) > > is that you have to type the word "foo" three times. It's not so much > the effort of repeating the keystrokes, but the fact that it feels so > unfactored. The only reason you need to do this is because you have no > way of getting at the newly-generated function (what CS types would call > a "lambda form") before it's bound to the name. > > A solution to that is to factor out the function definition from the > name binding, so you would do something like: > > foo = def (): > whatever > > although by the time you do that, you might as well have just gotten rid > of def and used lambda() directly. If you wanted it to be a > static/class method, you would do: > > foo = staticmethod_def (): > whatever > > The other big objection to the current syntax is that it puts the > wrapper way down at the bottom of the function body, away from the name. > The above syntax solves that too. > > The big problem with the above is that it changes the semantics of the > def statement in a way which is incompatible with current usage, and > thus I would expect it's a complete non-starter. Not to mention > inventing new keywords. > > On the other hand, doing: > > def (staticmethod) foo (): > whatever > > (you can pick whatever bits of punctuation turn you on) seems like it > should work just fine. I think it achieves all the goals: > > 1) It puts the decorator before the function body. > > 2) It keeps the decorator right next to the function name. > > 3) It doesn't re-define any currently valid syntax. > > 4) It looks enough like current Python syntax that most add-on tools > should handle it just fine. > > 5) If you've got lots of decorators (I'm still not sure if people really > think this will happen in real life), it's easy enough to break it up > into multiple lines: > > def @decorator1 \ > @decorator2 \ > @decorator3 foo (a, b, c): > print a, b, c > > but I'm assuming that will be the exception, just like really long > argument lists are the exception. Define the order of application of > multiple decorators in whichever way floats your boat; I'm guessing > outside-in (i.e. the last one gets done first) makes the most sense. > > I suppose you could take this one step further and put the decorators > inside ()'s, so you'd have any of (as auto-indented by emacs): > > def (decorator) foo (a, b, c): > pass > > def (decorator1, decorator2, decorator3) foo (a, b, c): > pass > > def (decorator1, > decorator2, > decorator3) foo (a, b, c): > pass > > def (decorator1, > decorator2, > decorator3) foo (a, > b, > c): > pass > > with the last example being a bit ugly, but at least it seems to follow > the expected indenting rules. In any case, you'd only have to resort to > something like that if you had lots of decorators and lots of arguments, > and in that case, I suspect you might want to be refactoring things to > simplify it all anyway. > > I haven't done an exhaustive search of all the proposed syntaxen which > have come flying by here in the past week or so. My apologies if I've > accidentally duplicated somebody else's work here. > > In retrospect (this has been written in dribs and drabs over the past > several hours, as I've been called away repeatedly to do real work), I > see I started out by agreeing with Arthur that the current (i.e. pre > PEP-318) way of doing things is good enough, then managed to head off > into a different direction and suggest YADS (Yet Another Decorator > Syntax). Oh, well. > > I'm also not at all convinced that using decorators for things like doc > strings makes any sense at all. It's just the wrong tool. Docstrings > work just fine the way they are. If it ain't broke, don't fix it. > Which I guess brings me full-circle back to agreeing with Arthur :-) From peter at engcorp.com Thu Aug 12 22:53:42 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 12 Aug 2004 22:53:42 -0400 Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: <411bd3f0$1@nntp.zianet.com> References: <60dfb6f6.0408111846.615ee9eb@posting.google.com> <3YWdnYxLf--ObofcRVn-pw@powergate.ca> <411ba1db$1@nntp.zianet.com> <411bd3f0$1@nntp.zianet.com> Message-ID: Mark Bottjer wrote: > Peter Hansen wrote: > >> Mark Bottjer wrote: >>> With this >>> syntax, though, the decorate block changes how the def statement is >>> handled, even though they are at the same indentation level. >> >> Changes it how? The definition of this whole decorator idea has been >> that it is equivalent to applying the decorator functions *after* the >> def has completed, as in "func = decorator(func)". This does not >> in any way changed how the def statement itself is handled. > > Except that the action happens magically after the def, even though the > decorator is before it. To me, this has the appearance of changing the > action of def. I'm trying to argue based on how it appears, rather than > how we know it to be implemented. I understand that. What I don't understand is why you make this complaint about the indented form, when the non-indented form with @decorator has exactly the same issue! In all cases, pre-def is weird in that the declarative lines that decorate the function lead to action *after* the def is closed, whether the decorators are indented or not. -Peter From firemoth at gmail.com Mon Aug 16 00:33:31 2004 From: firemoth at gmail.com (Timothy Fitz) Date: 15 Aug 2004 21:33:31 -0700 Subject: Generators versus Coroutines References: <972ec5bd.0408141032.385fe115@posting.google.com> Message-ID: <972ec5bd.0408152033.19fdcba4@posting.google.com> Dominic wrote in message news:... > > values. I am currently writing a real time strategy game where I have > I have written a simple 2D-real-time vehicle simulator in Python > (+ graphics library Allegro), using chained generators > which works well enough. > > If your game is more ambitious, spend some time designing > a good architecture and specify your components' interfaces. > Then you could generate your code-skeleton from that; > simple generators should be sufficient to implement > your methods which are then driven by your architectures > "execution model". > > ciao, > Dominic It really was never an issue of "Python can't handle this." it was more of an issue of "Python should more openly support this." I am championing generators because they make programming SO much easier in cases, and people really just don't use them outside if list generation, which saddens me. From luismg at gmx.net Mon Aug 23 01:32:58 2004 From: luismg at gmx.net (Neuruss) Date: 22 Aug 2004 22:32:58 -0700 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> <278de0e.0408220636.3ee25f9d@posting.google.com> <278de0e.0408221450.324e8178@posting.google.com> Message-ID: <278de0e.0408222132.40828dd7@posting.google.com> Jeremy, I didn't attack anyone's religion or race. We are talking about a programing language...why are you so touchy? > as Python is an open-source and volunteer based this can be interpreted as > a command on how people should spend their freely offered time. Granted. Perhaps I should have started the phrase: "In my humble oppinion...". English is not my mother tongue, as you might have already guessed, so excuse me if I'm not sensitive enough... > (In other words, all of *what* efforts? Are you helping to speed up Python > at all, or is this just rather strongly worded "suggestions" to other > people? Not a friendly approach.) If you read again my previous post, you'll see that I already expressed my genuine admiration and gratitude for python's developers and that I think that the path they are taking for improving python is the correct one. As for what I'm doing to help python, I'm affraid nothing, Im sorry. I'm not a developer. Maybe I'm just helping by spreading the word that python is great... As far as I know, this forum is for all python users, not just developers. Now if you think I shouldn't participate here, please kindly let me know. > Referring to other people's opinions as "nonsense" is also not a path to a > productive discussion, especially when the prime criterion for > "nonsensicalness" seems to be "an opinion different then mine". I appreciate other people's oppinions, even when I disagree. I didn't say that other people's oppinions were nonsense, what I meant is that the whole discussion was getting nonsense, because there's no use in discussing wether python is slow or not. Now if you find this oppinion ofensive, I'm sorry. > If you don't understand why that is logically true, I > suggest thinking about it for a bit before replying yet again... With duly respect, I don't need you to teach me how and when I should express myself. Please don't get me wrong, I really find much of your writing reasonable, but the arrogant tenor of your educational suggestion is out of place. From dsavitsk at remove-andrespell-to-send-mail-YAH-HEW.com Wed Aug 11 01:33:08 2004 From: dsavitsk at remove-andrespell-to-send-mail-YAH-HEW.com (drs) Date: Wed, 11 Aug 2004 00:33:08 -0500 Subject: Pythonwin -- How to embed Trace Collector? Message-ID: <10hjbtqrtpkqqe6@corp.supernews.com> Does anyone know a quick and easy way to embed the Trace Collector from Pythonwin into a VB6 form? This would help tremendously with some debugging. Thanks, -d From tjreedy at udel.edu Mon Aug 2 20:22:23 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 2 Aug 2004 20:22:23 -0400 Subject: Concerning classes (Newb question) References: <6c8fb5be.0408020947.67ef58e@posting.google.com> Message-ID: "Cyrille Lavigne" wrote in message news:6c8fb5be.0408020947.67ef58e at posting.google.com... > Hi! > I'm very new to the art of programming and I just learn OOP > in python. I want to know why the following bit of code crash. In general, questions like this should include the error message and traceback. The error message usually tells you 'why' (if only you can understand ;-). tjr From peter at engcorp.com Tue Aug 3 17:31:46 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 03 Aug 2004 17:31:46 -0400 Subject: simple Thread question In-Reply-To: References: Message-ID: Christopher T King wrote: > On Tue, 3 Aug 2004, Peter Hansen wrote: > > >>Obviously this just depends on differing ideas of what it means to be >>"friendly" to threads, but I find Python to be the most reliable and >>easiest to use environment for multi-threaded applications that I've >>ever used. > > > Poor choice of words on my part... I didn't mean API wise (though I'm not > a huge fan of threading), but rather implementation-wise (having the GIL > and all). I realize that's what you meant, and I stick with my opinion that it is *exactly that* which makes Python a much better environment for all the threaded applications I've written than the other environments I've tried in the past. -Peter From peter at engcorp.com Mon Aug 16 23:11:39 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 23:11:39 -0400 Subject: Python secure? In-Reply-To: <4neUc.3991$bJ2.26560@news1.mts.net> References: <2xXTc.3775$bJ2.24876@news1.mts.net> <4neUc.3991$bJ2.26560@news1.mts.net> Message-ID: Reid Nichol wrote: > Peter Hansen wrote: > > A given programmer will be more likely to create safe and > > secure software using Python than with C, thereby making > > C the less secure... > > Quite frankly I find C a perfectly viable language to write secure code. You haven't really been programming for very long, I think. > It's only failing is that people don't understand how to use it before > they type (which isn't exactly a failing of the language itself, but of > the person using it). A perfect example of this is pointers. Ah pointers... wonderful pointers. The fact that in C it is sometimes necessary to resort to pointers pretty much illustrates the point (no pun intended). A pointer is a low-level detail of the machine architecture, and requiring a programmer to manipulate it properly is a *failing* of the language, not of the programmer. Pointers are difficult, and this can be shown either a priori or in the very large body of empirical evidence which has formed as a result. Your argument (and I don't intend to start a flame war about another religious area) is tantamount to saying that the only failing of guns is that people use them to kill other people... (That argument has merit, of course, but it sort of misses the whole point.) > If people > wouldn't rush, if they took there time to learn what's actually going > on, they wouldn't make those mistakes. Okay, fair enough... though still arguable. But let's look at reality: people do rush. People don't take the time to learn what's actually going on. And even when they do, they are only human, so sometimes they forget, or get confused, or just get in a hurry, or in spite of all their best efforts they still manage not to do it right. Expecting programmers to be perfect is unreasonable, and to achieve very secure code in C one must expect to have perfect programmers. > One cannot judge a language by it's ability to allow sloppyness. Whyever not? There's no inherent reason why one shouldn't do exactly that. Assembly, for example, is a terrible language from which to expect secure, readable, maintainable programs, largely because it is so low level that it is incredibly difficult for the programmer to keep everything straight, organized, and well-structured. Impossible to keep well-structured in fact, because it is inherently an unstructured language. > Quite frankly, I've seen some crap > Python code. It's the programmer NOT the language. Not quite: it's the programmer *and* the language. But for a given programmer, there are clear differences between two languages in terms of how readable the resulting code will be, not to mention how secure. > I hope others see your clear bias towards Python as I have (One need > only to look at your descriptions to see it.). As if I ever tried to hide it... :-) > Remember, there is no > one language that everything is good for. Python, C, C++, Lisp, etc all > have things that it is best to program in them. It all depends on the > projects requirements. All true... but we _were_ talking about requirements involving security and, for that, C is not as good as Python. I think your final statement is pretty close to agreeing with that, unless you really want to go back now and argue against yourself, that C is just as good as Python in that area, or perhaps even better... (in which case I'm quite curious what areas you think Python, C++, and Lisp excel in compared to C.) -Peter From jjl at pobox.com Thu Aug 26 16:40:00 2004 From: jjl at pobox.com (John J. Lee) Date: 26 Aug 2004 21:40:00 +0100 Subject: Missing _sre.pyd in 2.4a2 Windows installer? References: <1xhtg1xm.fsf@pobox.com> Message-ID: Tim Peters writes: > [John J. Lee] > > The subject line says it, really: I installed 2.4a2 using the MSI > > installer on python.org, and I appear to be missing this file: > > > > C:\Python24\DLLs\_sre.pyd > > That file doesn't exist in 2.4; the code it used to contain has been > folded into the core python24.dll (so _sre is builtin now, instead of > an extension module). > > > As a result, Python picks up the _sre.pyd from my 2.3 installation, > > That shouldn't be possible, since _sre is a builtin now. [...] Aha. In a puff of logic, the error has now vanished. Mysterious... Thankyou John From andymac at bullseye.apana.org.au Fri Aug 27 07:00:52 2004 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Fri, 27 Aug 2004 21:00:52 +1000 (EST) Subject: What GCC version had defined? In-Reply-To: <412ecb16$1@nntp0.pdx.net> References: <412e39d1$1@nntp0.pdx.net> <412E55A9.9070400@v.loewis.de> <412e70d3$1@nntp0.pdx.net> <412ecb16$1@nntp0.pdx.net> Message-ID: <20040827205158.I56987@bullseye.apana.org.au> On Thu, 26 Aug 2004, Scott David Daniels wrote: > The problem is, of course (Billy G is always a problem), that I am running > on Win2K, so I don't run configure.in. I have two copies of MinGW -- > one 2.95 (no stdint.h), and one 3.2.3 which does do stdint.h. > These were not set up when whoever built windows 2.3.4 did so -- he or > she did not know what was going to be on my disk after I downloaded and > installed python. In this context, stdint.h is not a part of gcc per se, but rather a part of the MinGW development environment - in the same way that a lot of other header files in MinGW's include directory are not part of the standard gcc distribution. If the module code in question can be built on Unixish platforms, ISTM you should protect your special MinGW'isms with an #ifdef WIN32, to avoid problems with Python installations built with configure. The question that I think you are trying to ask is "which version of MinGW introduced stdint.h", and then see if there's a define you can use... (I don't know of one, but then I've only used MinGW 1.1 which contains gcc 2.95). -- 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 me at privacy.net Sat Aug 7 09:21:20 2004 From: me at privacy.net (Dan Sommers) Date: 07 Aug 2004 09:21:20 -0400 Subject: Queue qsize = unreliable? References: Message-ID: On Sat, 07 Aug 2004 06:14:29 GMT, Dennis Lee Bieber wrote: > On Fri, 6 Aug 2004 11:53:11 -0400, Tim Peters > declaimed the following in comp.lang.python: >> >> James, why do you think they're necessary functions? If, e.g., you're > My birth-certificate lists "James" as a saint name, will you > accept my response >> worried about the queue getting "too big", pass a maximum size to the >> constructor, and then a producer thread trying to add to a full queue >> will block until a consumer thread takes an entry off the queue. >> Indeed, mediating mismatched processing rates is a prime use case for >> bounded queues. >> > I can see a potential use for wanting to know the approximate > size of a Queue. A thread dispatcher with leeway to create additional > processing threads whenever the Queue becomes full (I'm not quite sure > how one would handle removing threads later, unless one can Queue the > removal command). Something like (pseudo-Python): [ algorithm snipped ] AIUI, a Queue *can* return its approximate size, which would be almost good enough for that application. A full Queue raise an exception when you try to stuff more into it, and that would work just as well. OTOH, not reaching that point might also be nice. I can envision a naive algorithm thrashing if the Queue is close to the threshold and the producer and consumer threads are running at about the same rate, though. You'd end up with a slightly more interessting algorithm using high and low water marks rather than a single threshold; the (programming-language-neutral) details are left to the interested reader (and, I'm sure, contained in many a textbook). Regards, Dan -- Dan Sommers Never play leapfrog with a unicorn. From mauriceling at acm.org Tue Aug 24 18:45:29 2004 From: mauriceling at acm.org (Maurice LING) Date: Tue, 24 Aug 2004 22:45:29 GMT Subject: using pexpect to control python In-Reply-To: References: <412b0b21$1@news.unimelb.edu.au> <412b14c2@duster.adelaide.on.net> Message-ID: <412bc504$1@news.unimelb.edu.au> I suppose I'm actually still toying with the possibilities of what pexpect can do with python and the question comes up. Another thing which I'm thinking previously is how can I embed a python interpreter (not compiler) that does line by line interpretation and execution, in a python program? I realized that python's language services has a compile package that can be invoked to compile python source into python bytecodes but that's provided that the codes are in a file. Perhaps what I'm interested may be how to embed and use the interactive mode of python interpreter in a python program? Thanks Maurice > > That last is *always* an apt question. > > Don Libes invented Expect. Expect is a wonderful, wonderful thing; > at the same time, its purpose is to mollify "programs with crappy > interfaces" (his words), so it's dispensable and inherently sub-op- > timal, in a sense I think we can make precise. The point here is > that, whenever you're considering controlling a Python-based appli- > cation PP with Expect (or pexpect or ...), you should first invest > at least ten seconds analyzing whether you're better off re-doing > PP's interface. From nholtz at docuweb.ca Thu Aug 26 18:08:54 2004 From: nholtz at docuweb.ca (Neal Holtz) Date: 26 Aug 2004 15:08:54 -0700 Subject: How to generically transform a list? References: Message-ID: <639f17f8.0408261408.1a779ca0@posting.google.com> Marco Aschwanden wrote in message news:... > Suppose you have a list of lists: > > theList = [['a',1,11,'aa'], ['b',2,22,'bb'],['c',3,33,'cc']] > > I would like to have a GENERIC way how to turn this list of list into > another list of list. > - A user can choose which columns she wants > - A user can select the order of the columns > > For example: > The user wants columns: 1,2 > The user wants it to be ordered: 2,1 > > A non generic approach would maybe do the following: > > >>> theList = [['a',1,11,'aa'], ['b',2,22,'bb'],['c',3,33,'cc']] > >>> new_list = [[row[2], row[1]] for row in theList] > >>> new_list > [[11, 1], [22, 2], [33, 3]] > > I am sure there must be a rather elegant generic approach, which is > lurking somewhere to be realeased. > > Thanks for any hint in advance, > Marco theList = [['a',1,11,'aa'], ['b',2,22,'bb'],['c',3,33,'cc']] cols = [2,1] new_list = [[row[i] for i in cols] for row in theList] new_list [[11, 1], [22, 2], [33, 3]] ? From tmj at jarmania.com Wed Aug 18 10:36:41 2004 From: tmj at jarmania.com (Tim Jarman) Date: Wed, 18 Aug 2004 15:36:41 +0100 Subject: How big can a Python program be? In-Reply-To: <903b3fba.0408180619.4d41027e@posting.google.com> References: <903b3fba.0408170333.49ce3944@posting.google.com> <412204d5$1$28243$afc38c87@news.easynet.co.uk> <903b3fba.0408180619.4d41027e@posting.google.com> Message-ID: <05612924-F124-11D8-A921-000D9366BF6A@jarmania.com> On 18 Aug 2004, at 15:19, vronskij at post.sk wrote: > > No way. This was just another question. One programmer told me that > he > can roughly handle max 10 000 lines in C language. I was curious > about Python. I always hear that Python can be used on larger projects > than e.j. PERL because it is Object Oriented and cleanly designed. > What is a larger project? Mumbers revail more. Of course 10,000 lines of Python will usually encompass much more functionality than 10,000 lines of C, because Python is a higher-level language, so you need to be careful you're comparing like with like. I have never tried to write 10,000 lines of Perl, and would never do so unless (a) I was being paid an obscenely large amount of money for it and (b) I had a cast-iron guarantee that I would never have to look at it ever again. But a simple line-count is less revealing than actual project scope IMHO. What does this 10,000-line C program actually do? How much effort would it be to do that in Python? In a lot of cases, the answer will be that it is much less effort in Python, and fringe benefits of that are likely to include shorter and more legible code than you had in C. You might be able to do it in APL in far fewer lines, but as to effort and legibility... YMMV! Tim J From jerf at jerf.org Mon Aug 23 20:25:57 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Tue, 24 Aug 2004 00:25:57 GMT Subject: Standard graph API? References: Message-ID: On Mon, 23 Aug 2004 20:41:53 +0000, Magnus Lie Hetland wrote: > In article , Jeremy Bowers wrote: > [snip] > > As I tried to state in the original post (I probably wasn't clear enough) > I'm not talking about a standard *implementation*, just a standard *API*, > like the DB-API. This could easily cover all kinds of strange beasts such > as directed or undirected, weighted or unweighted (etc.) graphs; > multigraphs, chain graphs, hypergraphs, who knows. Point conceded about API and not a library, but I'm not sure that changes my point much. Your API is going to assume something about how edges are represented (which will conflict with somebody), *or* it will be so vague as to not have any particular advantage over the nothing we have now. And so on for most of the other dimensions. From sharidas at zeomega.com Fri Aug 13 02:46:28 2004 From: sharidas at zeomega.com (Satchidanand Haridas) Date: Fri, 13 Aug 2004 12:16:28 +0530 Subject: while and if In-Reply-To: <411C626C.4070208@zeomega.com> References: <78e89de7f43dc55408bc9891b77d06cc@localhost.talkaboutprogramming.com> <411C626C.4070208@zeomega.com> Message-ID: <411C63C4.3000302@zeomega.com> Hi, There was a formatting error in my last mail. In the code, the 'l.append(temp)' should appear on a new line. So: print "choice ",x+1," is ", tmp l.append(temp) Regards, Satchit ---- Satchidanand Haridas (sharidas at zeomega dot com) ZeOmega (www.zeomega.com) Open Minds' Open Solutions #20,Rajalakshmi Plaza, South End Road, Basavanagudi, Bangalore-560 004, India Satchidanand Haridas wrote: > > Calvin79 wrote: > >> Hi Satchit, >> >> Thankyou for what you've already done, but would you mind if I ask one >> last thing and then I'll leave you alone? >> >> In it's present form the output is fine, but I think I might like to >> have >> it output in this format;['c', 'b', 'a', 'd']. It is probably the most >> basic of questions to ask, but heck I've only been at this python >> stuff a >> week... : ) >> Calvin >> >> >> > Hi, > > Change the 'print' line to append to a list: > > > > import random > > things = xrange(int(raw_input("choose no of things (1-8)? "))) > > state = [None,None] > > l = [] # new line > > for x in things: > tmp = random.choice('abcd') > print state > while tmp in state[0:2]: > tmp = random.choice('abcd') > print "choice ",x+1," is ", tmp > l.append(tmp) # new line > state[x%2] = tmp > > print l # new line > > > > ---- > Satchidanand Haridas (sharidas at zeomega dot com) > > ZeOmega (www.zeomega.com) > Open Minds' Open Solutions > > #20,Rajalakshmi Plaza, > South End Road, > Basavanagudi, > Bangalore-560 004, India > > > From pm_mon at yahoo.com Wed Aug 11 15:10:22 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Wed, 11 Aug 2004 15:10:22 -0400 Subject: Rather than decorators, how about sections? In-Reply-To: References: Message-ID: Paul McGuire wrote: > This only addresses the "decoration" for declaring static and class methods. > The decorator mechanism is intended to include much more than this simple > class declaration feature. See > http://www.python.org/cgi-bin/moinmoin/PythonDecoratorLibrary for the first > application (memoize - a return value cacheing helper/decorator, to optimize > access to repetitive or compute-intensive function calls, with NO changes > needed to the function itself). Other decorator candidates I've seen > mentioned are: > - mutex lock/unlock wrapper > - debugging/logging wrapper > - pre-condition/post-condition assertion wrappers > - input argument validation/typing wrapper > - return value type validation wrapper > needed to the function itself). memoize is an example of something that probably should not be specified in the method definition. It's strictly a 'pragma' --- just a suggestion to the compiler on how it could speed up the function. That kind of 'decoration' (as well as some of the other examples you cited) is of a 2nd class nature in that it doesn't affect whether the program produces the correct result or not. Therefore, I would not want to have such statements comingled with the statements that truly are germane to the correct functioning of my code. They would only be a distraction, and are best relegated to some other place in the code-base (another file perhaps). That's kindof the thinking behind aspect oriented programming (AOP). A body of code should deal with only one aspect of the problem... From ajsiegel at optonline.com Thu Aug 26 11:23:25 2004 From: ajsiegel at optonline.com (Arthur) Date: Thu, 26 Aug 2004 15:23:25 GMT Subject: Are decorators really that different from metaclasses... References: <412D9F1E.6000809@yahoo.it> Message-ID: On Fri, 27 Aug 2004 00:53:51 +1000, Anthony Baxter wrote: >On Thu, 26 Aug 2004 14:40:18 GMT, Arthur wrote: >> >IMO, to change it inside of a function def should be (but isn't) as easy >> >as... >> > >> > >>> def foo(): >> > ... """ I am foo """ >> > ... __doc__ = __doc__ + 'indeed' >> > >> >Paul >> >> Yes. Not only do I follow, but I think we came to exactly the same >> place, from very different directions, and coming from what I sense is >> very different backgrounds. >> >> Its just that I don't think many others seem to find that as >> interesting as I happen to. > >Not so much that, as running out of ways to restate myself. The >proposed syntax above still requires magic handling of double-under >variables in a function, and a new namespace. I can't see how you can >think that this is a _good_ thing. Forgive me, that I am not necessarily able to grasp why it is necessarily a bad thing. or a badder thing than other things. But do not discount at all your advice that we are in pie-in-the-sky land. The weight of evidence - being the general lack of interest in this thread, being taken into account. But as I explained earlier, I was hoping some fortipation (or other mojo someone might provide) might make this come together some. Ain't to be if it ain't to be. Art From grante at visi.com Mon Aug 23 21:25:09 2004 From: grante at visi.com (Grant Edwards) Date: 24 Aug 2004 01:25:09 GMT Subject: Getting at the bits of a 32-bit integer References: <85b54e91.0408231552.75f85727@posting.google.com> Message-ID: <412a98f4$0$65569$a1866201@newsreader.visi.com> On 2004-08-24, Jeremy Bowers wrote: >>>> a = 1023 >>>> (a & 1024) >> 10 > 0 > > Obviously, you need better constants and stuff. > > However, I must challenge your need to do this in the first place. That's a bit, um, conceited. Somebody's got to twiddle all those low-level bits out there to provide the infrastructure that makes the world run. I'm one of those people, and I need to do bit-twiddling quite often while implimenting various communications protocols. > Python and bit twiddling generally don't go together; Says you. I say they go together quite well. Bit-twiddling in Python works great. It's a hell of a lot easier than doing it in C, and I've switched to Python for all my non-embedded bit-twiddling needs. > even if you are accessing a binary file or protocol you should > shuffle out as much to the struct (?) module as possible. Struct only works at the byte level. For bitfields within bytes, you've got to use the bitwise and/or/xor/shift operators just like you do in C. > If you want to track every bit and byte, Python is the wrong > language for you... So, what language do you think is better? It sure isn't C. I did bit-twiddling in C for 20 years, and doing it in Python is much easier. > and unless you are tracking many many millions of bits, this > is the wrong decade for it. I guess I plain don't understand that last clause. It seems to imply that if you _are_ tracking many millions of bits, this is the decade to do it in Python? I used C for many, many years for low-level stuff like tearing apart serial data streams, Ethernet frames, IP headers and suchlike, and I can assure you that it's far, far easier to do stuff like that in Python than in C. -- Grant Edwards grante Yow! Where's SANDY DUNCAN? at visi.com From olli at haluter.fromme.com Mon Aug 23 12:47:42 2004 From: olli at haluter.fromme.com (Oliver Fromme) Date: 23 Aug 2004 16:47:42 GMT Subject: J2 proposal: keyword References: Message-ID: <2ouldeFf0ujnU2@uni-berlin.de> Robert Brewer wrote: > III. Choosing a keyword > [...] > -Candidates for keywords have fallen into two or three camps, and > emphasize different aspects of decorators: > > -Declarative: declare, predef, moddef > -Transformative: transform, wrap, modify, mutate > -Attributive/Annotative: amend, using, having > -Directive: pragma, signify > -Associative: helper, qualify, qual, meta > -Cross-cutting: imbue, endow, bestow, embellish, extend, accum, glom, > confer > -Prepositions/Adverbs: using, through, per, via, by Aren't decorators just functions that are applied to the function definition? Then how about "apply"? It's short (for those lazy typers), and it expresses exactly what happens. apply: staticmethod memoize def foo (int): pass Best regards Oliver -- Oliver Fromme, Konrad-Celtis-Str. 72, 81369 Munich, Germany ``All that we see or seem is just a dream within a dream.'' (E. A. Poe) From fumanchu at amor.org Wed Aug 25 12:42:15 2004 From: fumanchu at amor.org (Robert Brewer) Date: Wed, 25 Aug 2004 09:42:15 -0700 Subject: Call for signatories for J2 Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E6F@exchange.hqamor.amorhq.net> The J2 proposal is as complete as it will ever be. http://www.aminus.org/rbre/python/pydec.html The patch is nearly complete; only the __future__ declaration and some document tweaks remain. It should be updated on SourceForge today or tomorrow. This is a call for all who wish to sign the proposal, either for, against, or abstaining. Please sign by either posting on comp.lang.python (replying to this is fine), or sending email to fumanchu at amor.org (for some of you reading this, here's a link: mailto:fumanchu at amor.org). Please include your full name. If you reject the proposal, please also include a _short_ description of why you are rejecting it. You will not receive a reply regarding the rejection or description; it will be included for Guido's information purposes only. Please read the proposal carefully before signing. In particular, carefully read the statement (for, against, or abstaining) to which you are signing your name; each is explicit and means exactly what it says. Thanks again to those who have contributed in all forms. Hopefully, we can put this decorator issue to rest soon and move on. Robert Brewer MIS Amor Ministries fumanchu at amor.org P.S. I'll be out of town from Friday morning to Sunday evening (U.S. Pacific Time), so get your name in early. Given sufficient volume, I'll promote this to Guido just before I leave; otherwise, I'll wait 'til Sunday night to finish compiling names. From nobody at nowhere.near.here Thu Aug 12 04:06:21 2004 From: nobody at nowhere.near.here (Vladimir Konrad) Date: Thu, 12 Aug 2004 09:06:21 +0100 Subject: What happened to initd.org Message-ID: <411b24f9$0$15884$cc9e4d1f@news.dial.pipex.com> I am looking for psycopg (PostgreSQL adapted for Python) for Fedora Core 2 and the source web site (initd.org) is down second day in a row. Any idea what happened? From CousinStanley at HotMail.Com Thu Aug 12 11:10:43 2004 From: CousinStanley at HotMail.Com (Cousin Stanley) Date: Thu, 12 Aug 2004 08:10:43 -0700 Subject: Pyhton Interpreter Startup time References: Message-ID: <2o1fbjF5rbsvU1@uni-berlin.de> Peter Hansen wrote .... > Neil Benn wrote: > >> I'm looking at a small app which would need a very quick >> startup time for the Python interpreter. It doesn't do much (copying >> and caching of files, no GUI) but I need the Python interpreter to start >> up very quickly (<1 second on a Windows box). > > What kind of machine do you have? > > On mine, Python starts up in about 0.06 seconds... > > This primitive test shows these results on a Windows XP machine > (it won't work with Windows 98 as it can't chain commands on the > command line like that, but you could but it in a batch file). > > c:\>echo. | time & python -c "import time; print time.time()" > The current time is: 8:59:59.67 > Enter the new time: > 1092315599.73 > > This is a fairly fast machine (Athlon 2500+) but I really > doubt slower machines would take much longer than 1 second > unless they are *really* old. > > -Peter This variation on Peter's timing is from a 5-year-old 250 MHz Compaq running Linux/Debian ... sk at cpq1 : ~/c $ ./gtod & python -c "import time ; print ' Python ....' , time.time()" [1] 1677 Number of seconds ......... 1092323003 Number of microseconds .... 194433 Time zone ................. 420 Daylight savings time ..... 0 Python .... 1092323003.36 -- Cousin Stanley Human Being Phoenix, Arizona From ialbert at mailblocks.com Fri Aug 20 15:24:30 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Fri, 20 Aug 2004 15:24:30 -0400 Subject: My only complaint about Python In-Reply-To: <86d61nay8v.fsf@stronzo.brainbot.com> References: <86d61nay8v.fsf@stronzo.brainbot.com> Message-ID: Ralf Schmitt wrote: > You can build modules using msys/mingw. Instructions can be found at > http://sebsauvage.net/python/mingw.html works out great! I didn't even need to do step 3 (tweaking distutils). thanks for the pointer. Istvan. From albalmer at att.net Thu Aug 26 11:58:00 2004 From: albalmer at att.net (Alan Balmer) Date: Thu, 26 Aug 2004 08:58:00 -0700 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <2a56f6a3.0408252257.4f1f92e@posting.google.com> Message-ID: On 25 Aug 2004 23:57:24 -0700, spam_depository2004 at yahoo.com (Johnny) wrote: >xah at xahlee.org (Xah Lee) wrote in message news:<7fe97cc4.0408251356.34f2102a at posting.google.com>... > >> How can we prevent heinous cults then? Stop bending truths. Education >> and rationalism. I'm starting my own cult to exterminate morons on >> this earth. Two things are on the top of my agenda: Unixism and Perl. > >I bet Larry Wall's life insurance premiums just skyrocketed. BTW, what >does this have to do with Lisp? We are more of a therapy and support >group than a cult. That's fortunate, since Xah Lee obviously needs those services. -- Al Balmer Balmer Consulting removebalmerconsultingthis at att.net From jaydonnell at yahoo.com Wed Aug 25 12:29:12 2004 From: jaydonnell at yahoo.com (Jay Donnell) Date: 25 Aug 2004 09:29:12 -0700 Subject: urllib hangs References: <2p35phFg2vehU1@uni-berlin.de> Message-ID: Performance isn't an issue with this script. It runs in the background from a cron job. It just needs to finish before the day is over which it easily does :) It currently runs through ~20,000 urls which it does in about 3 hours. It should be faster now that it times out. If I had used threads at first I probably wouldn't have noticed that it wasn't timing out on a few urls. Benjamin Niemann wrote in message news:... > Bernd Kaiser wrote: > > > I also would use a few Threads, they will speed up your script. > He didn't mention any performance issues. Don't try to optimize for > speed before you have a valid complaint about the program being to slow > - especially if optimization involves threads! From pink at odahoda.de Mon Aug 23 13:48:06 2004 From: pink at odahoda.de (Benjamin Niemann) Date: Mon, 23 Aug 2004 19:48:06 +0200 Subject: urllib hangs In-Reply-To: References: Message-ID: Jay Donnell wrote: > This is a basic version of my code > > for url in urls: > fp = urllib.urlopen(url) > lines = fp.readlines() > > #print lines > for line in lines: > #print line > if(reUrl.search(line)): > print 'found' > return 1 > else: > print 'not found' > return 0 > > this hangs occasionally for some certain url's. If I do a ctrl-c > (linux) it will move on to the next url. How can I get this to timeout > and move on to the next url. since 2.3 there's socket.setdefaulttimeout(), this should to the job: import socket socket.setdefaulttimeout(10) # throw socket.timeout exception after 10s, # default is to wait a infinitly (or at least a very, very long time...) For older python versions, ask google for timeoutsocket.py From skip at pobox.com Mon Aug 30 17:31:19 2004 From: skip at pobox.com (Skip Montanaro) Date: Mon, 30 Aug 2004 16:31:19 -0500 Subject: xml.dom.minidom - documentElement vs. childNodes In-Reply-To: References: Message-ID: <16691.40103.319598.899676@montanaro.dyndns.org> In response to: >> I'm getting somewhat painfully acquainted with xml.dom.minidom. What >> is the relationship between its documentElement attribute and its >> childNodes list? I thought XML documents consisted of a single, >> possibly compound, node. Why is a list of childNodes needed? Peter provided this interpreter session: >>> import xml.dom.minidom as md >>> dom = md.parseString("""""") >>> dom.childNodes [, ] So a document can have multiple nodes. It appears they can only have a single Element node though: >>> dom = md.parseString("""""") Traceback (most recent call last): File "", line 1, in ? File "/Users/skip/local/lib/python2.4/xml/dom/minidom.py", line 1925, in parseString return expatbuilder.parseString(string) File "/Users/skip/local/lib/python2.4/xml/dom/expatbuilder.py", line 940, in parseString return builder.parseString(string) File "/Users/skip/local/lib/python2.4/xml/dom/expatbuilder.py", line 223, in parseString parser.Parse(string, True) ExpatError: junk after document element: line 1, column 43 ... I guess the documentElement attribute of the dom refers to that lone Element node. Thanks, Skip From telcom_sage at yahoo.com Mon Aug 2 22:46:19 2004 From: telcom_sage at yahoo.com (Brian Leair) Date: 2 Aug 2004 19:46:19 -0700 Subject: Rebinding variable, despite global statement Message-ID: I am using "from MyModule import *", (yes, yes, I know) MyModule has a variable "g_my_var" at the "global" scope. In the code that performs the import, I have a function that has the statement "global g_my_var". Despite this, when I try to assign to g_my_var it appears I am rebound to a different object. Beyond philosophical arguments about not using a "global" variable, is there a real reason why I can't assign to the global "g_my_var". I'm using python 2.3.2. One workaround is to place getter/setters in MyModule, but I was still surprised by this behavior. ----------------------- MyModule.py ----------------------------- g_my_var = 142 def UtilityFunction (): print "Inside UtilityFunction", g_my_var print "Inside UtilityFunction Id is", id (g_my_var) return ----------------------- MyProgram.py ----------------------------- from MyModule import * def ProgramFunction (): global g_my_var UtilityFunction () print "In ProgramFunction", g_my_var print "In ProgramFunction Id is", id (g_my_var) print "Now assigning a value of 42 in ProgramFunction." g_my_var = 42 print "After assignment, in ProgramFunction", g_my_var print "After assignment, in ProgramFunction Id is", id (g_my_var) UtilityFunction () return print "Excuting Main Program" UtilityFunction () ProgramFunction () =============== Output ====================== Excuting Main Program Inside UtilityFunction 142 Inside UtilityFunction Id is 7625912 Inside UtilityFunction 142 Inside UtilityFunction Id is 7625912 In ProgramFunction 142 In ProgramFunction Id is 7625912 Now assigning a value of 42 in ProgramFunction. After assignment, in ProgramFunction 42 After assignment, in ProgramFunction Id is 8008553 Inside UtilityFunction 142 Inside UtilityFunction Id is 7625912 From peter at engcorp.com Mon Aug 9 19:39:27 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 09 Aug 2004 19:39:27 -0400 Subject: decorators as a special case of an @ operator? In-Reply-To: <87fz6wgkgl.fsf@uwo.ca> References: <87llgocrgq.fsf@uwo.ca> <87d620cld8.fsf@uwo.ca> <87fz6wgkgl.fsf@uwo.ca> Message-ID: <_OidnXjfbfmtloXcRVn-iA@powergate.ca> Dan Christensen wrote: > Peter Hansen writes: >>Very likely, as is usual with Python, to avoid implicitly >>assuming something that could well be wrong, thus failing >>in a possibly very hard to find way, without warning. >> >>x = a_very_long_expression + >>some_function_that_might_return_a_value() >> >>Now, was the first line a typo, with a missing extra value, >>or was it really intended to add the result of the function >>call on the second line? > > Good point. What if python did automatic continuation in this > situation only if the second line was further indented? I like. :-) Don't know if it's been considered, but given that it requires two distinct mistakes on the part of the programmer, one after the other, it would be hard to argue that it would happen often. The indentation part fits nicely with Python in general. By the way, you do know that instead of a backslash, lots of us use parentheses around multi-line expressions? It works fine, doesn't seem as ugly as \. -Peter From fumanchu at amor.org Wed Aug 4 17:19:48 2004 From: fumanchu at amor.org (Robert Brewer) Date: Wed, 4 Aug 2004 14:19:48 -0700 Subject: Finding all time periods for a given interval within a daterange Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022DDD@exchange.hqamor.amorhq.net> Tim Churches wrote: > On Thu, 2004-08-05 at 03:09, Robert Brewer wrote: > > Look at my 'recur' module and see if it fits your requirements: > > > > http://www.aminus.org/rbre/python/index.html > > > > Start with the Recurrence class and play with it--then dig > deeper if you > > need to. > > Robert, > > How is the above code licensed? Anything on that page is public domain. Use it as you see fit. Robert Brewer From ptmcg at austin.rr._bogus_.com Mon Aug 23 10:39:58 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 23 Aug 2004 14:39:58 GMT Subject: J2 paper 0.2.1 References: Message-ID: <2lnWc.9731$Jn5.5247@fe1.texas.rr.com> "Robert Brewer" wrote in message news:mailman.2201.1093271860.5135.python-list at python.org... Colin J. Williams wrote: > One nit picking comment on Robert Brewer's document: An > annotation is a > transformation of a function, as a change to the flow of control is. I'd like someone to analyze that further. "Transform", like the word "change", can mean almost anything in English. However, I find the use of the term in programs to generally mean either coerce/convert/cast between types, or some other mechanism whereby one object is supplied, and another object returned. That is, "transform" affects Being/"is" as opposed to Attribute/"has". However, neither your "gut feeling" nor mine about the issue is enough--we need a more rigorous heuristic to decide. Finding precedent would be a good start, if anyone wants to try. Robert Brewer MIS Amor Ministries fumanchu at amor.org From tzot at sil-tec.gr Sat Aug 21 15:38:57 2004 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 21 Aug 2004 22:38:57 +0300 Subject: unicodedata name for \u000a References: Message-ID: <049fi0hadn2ic7sv6bg4pn81tt0rbvcvhf@4ax.com> On Sat, 21 Aug 2004 21:24:04 +0200, rumours say that Ken Beesley might have written: [snip] >unicodedata.name(u"\u000a") > >I get > >Traceback (most recent call last): > File "", line 1, in ? >ValueError: no such name > >There is, of course, a Unicode name for \u000a, >which is 'LINE FEED' or perhaps 'LINE FEED (A)'. > >Is there a gap in unicodedata? or in my understanding? It seems that all control characters (u"\u0000" to u"\u001f") have no names in unicodedata. Don't know if this is an omission (ie bug) or intentional. -- TZOTZIOY, I speak England very best, "Tssss!" --Brad Pitt as Achilles in unprecedented Ancient Greek From peter at engcorp.com Thu Aug 12 23:12:56 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 12 Aug 2004 23:12:56 -0400 Subject: decorator syntax polling suggestion In-Reply-To: <411BF3FC.71051A6F@alcyone.com> References: <411BF3FC.71051A6F@alcyone.com> Message-ID: Erik Max Francis wrote: > So only people who are dissastisfied with the proposal are likely to > vote, and indeed that seems to be the case. That seems to be a perfect situation then. Why do we need votes from people who are happy with the @pie syntax? It's already in Python. On the other, if there are people who are dissatisfied with @pie, they can vote, use the results to help them focus their energies on the most likely alternate candidate(s), and finally present a united front saying "uh, @pie sucks, and we have a wide consensus that syntax XXXX would be much better for these reasons..." Wouldn't that make sense? -Peter From peter at engcorp.com Sun Aug 22 08:34:41 2004 From: peter at engcorp.com (Peter Hansen) Date: Sun, 22 Aug 2004 08:34:41 -0400 Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? In-Reply-To: <10igvr2d1hlgmc9@news.supernews.com> References: <10igvr2d1hlgmc9@news.supernews.com> Message-ID: John Roth wrote: > Now that I've had a chance to look at the syntax, you can count > me mildly in favor of J2. (I haven't voted yet.) It's an extra line, > but I think the explicitness outweighs the vertical space it > takes up. Although I'm not sure it was implemented this way, I believe there may be an intent to support the usual sort of one-line version as this (using an alternate keyword instead of "decorate" which now seems doomed): using: staticmethod def foo(bar, baz): pass That makes it no extra lines, but still explicit and Pythonic in nature. (Michael, was that how you implemented the latest?) -Peter From aahz at pythoncraft.com Wed Aug 18 19:30:56 2004 From: aahz at pythoncraft.com (Aahz) Date: 18 Aug 2004 19:30:56 -0400 Subject: age of Python programmers References: Message-ID: In article , Jarek Zgoda wrote: >Aahz pisze: > >>>I'm also optimistic about retiring with Python, because *everyone* is >>>going to retire with Python in 2044 :-). >> >> 2038 > >2036 What's special about 2036? (2038-1-19 is the 32-bit Unix date rollover point.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From Scott.Daniels at Acm.Org Fri Aug 6 10:15:38 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 06 Aug 2004 07:15:38 -0700 Subject: [Newby question] List comprehension In-Reply-To: References: Message-ID: <411395a6$1@nntp0.pdx.net> Batista, Facundo wrote: > [Eelco Hoekema] > #- def song(f): > #- (name, ext) = os.path.splitext(f) > #- return ext.lower() == '.mp3' > files = [] > for (root, dir, files) in os.walk(os.path.abspath('.')): > mp3files = filter(song, files) > if mp3files: > files.append((root, mp3files)) > Iwouldn't bother with the funny song construction: files = [] for root, dirs, files in os.walk(os.path.abspath('.')): mp3files = [name for name in files if name.lower().endswith('.mp3')] if mp3files: files.append((root, mp3files)) -- -Scott David Daniels Scott.Daniels at Acm.Org From ruses at users.ch Mon Aug 9 09:06:43 2004 From: ruses at users.ch (=?ISO-8859-1?Q?=22Elveto=2C_artiste-ing=E9nieur_en_n=E9motech?= =?ISO-8859-1?Q?nique=22?=) Date: Mon, 09 Aug 2004 15:06:43 +0200 Subject: Paul Graham on Python hackers References: <3064b51d.0408061127.32536826@posting.google.com> Message-ID: <411776E3.30800@users.ch> Bryan Olson wrote: > > Though he compares well, overall, to people who answer > rhetorical questions. > I disagree : the most intelligent answers, usually fit questions that look rhetorical in isolation. From mensanator at aol.com Tue Aug 31 12:36:11 2004 From: mensanator at aol.com (mensanator at aol.com) Date: 31 Aug 2004 09:36:11 -0700 Subject: about presicion Message-ID: Alex Martelli wrote: > mensanator at aol.com wrote: > ... > > > > I just tried it and found out it's not compatible with gmpy. > > > > > > By "it" do you mean Decimal, or Python 2.4 alpha 2? > > > > By "it", I meant gmpy 1.0 and Python 2.4. Trying to import the > > module says it can't use the Python23.dll. > > _Any_ binary extension Python module compiled for Python 2.3 cannot even > load (on Windows) with Python 2.4 -- this has always been true on > Windows between any two releases of Python and will presumably continue > to be so for the foreseeable future. What I meant was the OP can't compare Decimal and gmpy unless he has a version of gmpy that runs in 2.4. Or has a version of Decimal that runs in 2.3. > > This doesn't mean that Python 2.4 "is not compatible with gmpy" or > viceversa: it just means you obviously need to use a gmpy binary (pyd > file) compiled for the version of Python you're using. Just as it would > be the case for any other binary extension module whatsoever. I didn't mean it wasn't compatible. I meant you can't use the 2.3 version of gmpy in the 2.4 alpha that's currently available, so I can't experiment with 2.4 because all my interesting programs are dependant on gmpy. Not everyone is a professional software developer, some of us ignorant users need to be told that. > > Unfortunately, compiling any binary extension module on Windows for > Python 2.4 requires Microsoft's very latest C++ compiler -- I do not own > a copy, nor do I have any PC normally running Windows XP, which is > required to run that compiler. Until Pyhon 2.3, I made do with a > Windows 98 session running under win4lin on one of my Linux machines, > and good old Microsoft Visual C++ 6 -- but such limited resources are > not sufficient any longer to compile Python binary extension modules for > Python 2.4. Since in terms of income-making (as well as leisure;-) I > work by now only on MacOSX, Linux, and OpenBSD machines, I am not going > to buy a PC loaded with Microsoft software just to be able to donate > precompiled Python binary extension modules to Windows users. How feasible is it that the end user could compile it himself? Would the command line c compiler from the MS SDK suffice or do you have to purchase the full .NET package? Would the source files need a lot of tweaking? > > > > > I think gmpy should > > > build happily with the latter, > > > > I'm using the pre-built Windows binary distribution. I wouldn't > > know how to re-build it. I assume that when Python 2.4 is final, > > I newer compatible version of gmpy will become available. > > Not by magic -- I hope somebody out there owns all the needed Microsoft > software and is interested in compiling gmpy for Windows under Python > 2.4 and making it available, but it won't be me. Unfortunately, us ignorant end users depend on the magic that is supplied by others. But that doesn't mean we're unwilling to help. I had no clue that there won't be any more Windows gmpy updates unless someone volunteers to help. I've got an XP machine and given a choice between abandoning Python completely and getting a copy of the MS compiler... Of course, I realize that handing someone a box of wrenches doesn't make them a mechanic. But we always have this newsgroup. I would rather try and fail than see gmpy whither away from lack of interest. > > > > > and interoperate sensibly with Decimal > > > anyway -- as gmpy's author I'd be quite happy to fix gmpy if it's > > broken > > > in either respect. > > > > Were you aware that there is apparently a memory leak in the > > gmpy.divm() function? Calling it several million time caused my > > computer to run out of virtual memeory. Luckily, I was able to > > work around it using the gmpy.invert() which didn't consume any > > memory regardless of how many times it was called. > > No, I was not aware of that -- I'll look into it, thanks. > > > Alex From jeffbarish at starband.net Tue Aug 31 17:31:31 2004 From: jeffbarish at starband.net (Jeffrey Barish) Date: Tue, 31 Aug 2004 15:31:31 -0600 Subject: Beeping the console Message-ID: What is the easiest way to beep the console from a Python program (i.e., to do the same thing as echo -e \a)? -- Jeffrey Barish From pepijn.kenter at nospam.dlr.nl Mon Aug 23 04:32:14 2004 From: pepijn.kenter at nospam.dlr.nl (Pepijn Kenter) Date: Mon, 23 Aug 2004 10:32:14 +0200 Subject: Array of objects in numpy. References: <2olrdjFbgdd0U1@uni-berlin.de> Message-ID: <2oto8rFeivqmU1@uni-berlin.de> David M. Cooke wrote: > At some point, Pepijn Kenter wrote: > >> Hi all. >> >> I'm new to python and want to use it for an assignment. >> >> I have succesfully implemented a galois field class including the >> _repr__, __mul__, __div__, __add__ and __sub__ methods. > > including __r* variants too? > >> Basically a galois field is >> an integer modulo a prime number. Now I want to make a matrix of these >> galois field objects using the numpy library. Constructing, printing and >> multiplying arrays of GF's works fine. However there are several >> functions that give problems, most importantly: dot, repeat. >> >> I'm affraid I've forgotten my memmory stick with the code and error >> messages :-(, so I have to keep my question general. > > I'm shooting in the dark here, as I presume you're using Numeric, as > opposed to numarray. > >> If I recall correctly, >> the repeat function complained that my GF object didn't have the >> __getelem__ method implemented (IMO this should not be necessary), > > My guess is that you're using Numeric.repeat incorrectly. Note that for > Numeric.repeat(a, repeats), a has to be array-like (more specifically, > array(a) can work). > No, I'm using numarray. >> the dot function complained about an unsupported type. > > Don't know about that one. Maybe if you haven't added __rmul__ or > __radd__ to your class. > Thanks, I'll give it a try. Pepijn. From jonaskoelker at yahoo.com Fri Aug 13 08:54:24 2004 From: jonaskoelker at yahoo.com (=?iso-8859-1?q?Jonas_K=F6lker?=) Date: Fri, 13 Aug 2004 14:54:24 +0200 Subject: !wtf ellipsis Message-ID: so, I've read the manuals, done a few hacks, read the quick reference. however, one thing still eludes me: what (the hell) is Ellipsis? what's it good for? how do I use it; how does the interpreter use it? ... thanks everybody, Jonas K?lker ---- [ValueError: ASCII art sig block too ugly to live] From tedlandis at gmail.com Wed Aug 18 14:28:59 2004 From: tedlandis at gmail.com (Ted) Date: 18 Aug 2004 11:28:59 -0700 Subject: age of Python programmers References: Message-ID: <73151219.0408181028.64e51371@posting.google.com> "Lucas Raab" wrote in message news:... > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... 46... 1 year Python... 26 years pretty much everything else. I'd like to retire with Python, it's that good. From ville at spammers.com Sun Aug 22 16:06:29 2004 From: ville at spammers.com (Ville Vainio) Date: 22 Aug 2004 23:06:29 +0300 Subject: On consensus decision-making (was Re: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WEDONE?) References: Message-ID: >>>>> "Arthur" == Arthur writes: Arthur> On 22 Aug 2004 19:36:38 +0300, Ville Vainio Arthur> wrote: >> >> Obviously people who don't want any syntax at all should be ignored in >> the consensus building process... Arthur> I hate to contribute to a change in tone to what has been a pretty Arthur> civil controversy, all things considered, and Anthony's private hate Arthur> mail notwithstanding. Arthur> But that to me is a stupid remark. The reason to ignore "no syntax" proponents is the fact that the whole purpose of this excercise is to come up with an alternative syntax to @pie. Guido doesnt't need a consensus about whether we want a decorator syntax - he wants a consensus about an alternative syntax. What is going in is either @pie or the syntax proposed by the community. No syntax proposed by community -> @pie goes in, for better or worse. Arthur> I have heard implicit and explicit threats on python-dev Arthur> in the case no new syntax made it into 2.4 - assumedly by Arthur> people who *really* hate some extra typing. It is not Arthur> unreasonable to assume that vehemence is Threats? Isn't that a tad dramatic? Bottom line is - decorators are going in. Now it's just about syntax. You'll never need to use them in your own code. I never use backticks, which I think you can agree are a worse idea than many of the proposed decorator syntaxes put together. -- Ville Vainio http://tinyurl.com/2prnb From grv575 at hotmail.com Mon Aug 30 19:24:41 2004 From: grv575 at hotmail.com (grv575) Date: 30 Aug 2004 16:24:41 -0700 Subject: profiler References: Message-ID: <144d0df.0408301524.73a6827a@posting.google.com> OK but how do you use this newly built python binary? I tried just running the interpreter but didn't see a gmon.out file or whatever in my current directory on exit. (./configure --prefix=/usr --enable-profiling; make; make install is all that's needed right?) "Brett C." wrote in message news:... > As of Python 2.4 you can also compile in support for C-level profiling > into the interpreter (--enable-profiling). See the in-dev docs > (http://www.python.org/dev/doc/devel/) for details. From Michael.J.Fromberger at Clothing.Dartmouth.EDU Mon Aug 23 11:10:53 2004 From: Michael.J.Fromberger at Clothing.Dartmouth.EDU (Michael J. Fromberger) Date: Mon, 23 Aug 2004 11:10:53 -0400 Subject: Has anyone implemented BASIC in Python? References: <2oo13eFcj548U1@uni-berlin.de> <2ot30hFeek8nU1@uni-berlin.de> <9h0ji0lvc0be65nuvcugaa3vsq5mcl3ck8@4ax.com> Message-ID: In article <9h0ji0lvc0be65nuvcugaa3vsq5mcl3ck8 at 4ax.com>, Andrea Griffini wrote: > Writing parsers, interpreters and compilers is a lot simpler than > many do think. Of course the evil is in the details and getting > something that comes even just close to (just for example ;-) ) > python is a *LOT* harder. > > [...] > > I never use yacc/lex, I just prefer hand-coding the parsers. > > I never felt as pressing the problem of the speed of parsing > (I've read that this is one main superiority of shift-reduce > parsers). An hand-coded recursive descent parser is in my > opinion very easy to write... and very easy to maintain. For simple, single-purpose languages, I am inclined to agree that hand-written parsers are easy enough to write and maintain. However, when you are dealing with a more complex general-purpose language, and one whose grammar needs to evolve over time, then I think a parser-generator is a much better solution by far. The chief trouble in maintaining a hand-written recursive descent parser is that the grammar for the input language is hidden inside the implementation. The author of the code can usually pick it out, but over time, even the author may find it difficult (and yes, I am speaking from a certain degree of first-hand experience in this matter). In contrast, the grammars consumed by most parser-generators are explicitly written out as grammars, in the spirit (of not the form) of BNF notation. If you want to make a change to the grammar (and thereby, the parser), you can easily see how the changes will affect the rest of the language, and a new parser can be created quickly and easily, simply by re-running the parser generator. The only lines of code you need to touch are the places where your change affects the translation, and that is often quite minimal. Furthermore, naive implementation of recursive descent is fraught with a few subtle perils to trip the novice and the unwary. For instance, you must carefully avoid left-recursive productions, or your parser may not terminate. Also, error-handling is tricky in recursive descent, because much of the parser's state is implicit in stack frames that must be correctly unwound when an error forces you to bail out. If you're writing in a language (like Python) with good automatic memory management, the latter is less of an issue, but recursive descent parsers written in languages without automatic memory management, like C and C++, must contend mightily with this. Of course, there is no silver bullet, but the availability of good LR(1) and LALR(1) parser generators should not be discounted, even if the theory behind them seems to be slightly complicated, on the surface. Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From tzot at sil-tec.gr Wed Aug 18 11:52:26 2004 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Wed, 18 Aug 2004 18:52:26 +0300 Subject: age of Python programmers References: Message-ID: On Wed, 18 Aug 2004 08:34:08 -0400, rumours say that Jeremy Jones might have written: >Is this a marketing survey? > >age: 31 >marital status: married - have 1 wife >parental status: 2 children >canine status: have 1 dog >feline status: 1 cat >employment status: (very) thankfully have a (good) job >automobile status: 2 cars >sanity status: nearly none You forgot to give us address and credit card details. Thanks in advance for your reply. -- TZOTZIOY, I speak England very best, "Tssss!" --Brad Pitt as Achilles in unprecedented Ancient Greek From tjreedy at udel.edu Tue Aug 17 00:59:05 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 Aug 2004 00:59:05 -0400 Subject: Python secure? References: <2xXTc.3775$bJ2.24876@news1.mts.net> Message-ID: "Reid Nichol" wrote in message news:rzeUc.3995$bJ2.26585 at news1.mts.net... > And because some M$ employee did something sloppy it is an implication > that C is bad. You said that, not me. > I have to say the responsibility is the programmers, *not* the language. The fact that most road accidents are the responsibility of some driver does not change the fact that good highway engineering -- lane lines, guard rails, proper grading and sight around curves, and traffic lights, etc -- reduces the number of accidents. In any case, what I wrote was in the context of a beginning programmer asking if Python is secure -- in particular. as secure as compiled C. All the previous answers were in term of source code hiding and copyrights. I wrote to suggest that he also consider security in terms of ease of shooting oneself in the foot, and that in that regard, C is less secure rather than more secure. Despite your out-of-context sniping, I believe this suggestion to be appropriate and the statement to be correct. To put it another way, what I wrote was like advising a beginning driver to think twice before driving on a curvy mountain road lacking center lines and guard rails. > And what language is Python programmed in... oh yah, C. Perhaps people > shouldn't talk about how poorly secure C and then go off to how secure > Python is when Python is written in C. Houses built on sand... More out of context sniping, which I anticipated ... As we both said, C is safer in the hands of expert, experienced, careful programmers. People like you claim to be and people like Guido and Tim Peters. They program in C so we have less need to. And I am grateful for that. Terry J. Reedy From mwh at python.net Mon Aug 23 10:56:44 2004 From: mwh at python.net (Michael Hudson) Date: Mon, 23 Aug 2004 14:56:44 GMT Subject: Overriding logical operators? References: Message-ID: Andrew Durdin writes: > In Python, you can override the behaviour of most operators for a > class, by defining __add__, __gt__, and the other special object > methods. > > I noticed that, although there are special methods for most operators, > they are conspicuously absent for the logical "or" and "and". That's because they're not operators, they're flow control constructs. Well, maybe that's not a helpful answer, but it's one you haven't had yet :-) > Would it be possible to allow overriding the logical operators, with > the caveat that overriding it would prevent short-circuiting? I think this would be a foul abomination. But maybe that's just me. (I don't really approve of operator overloading either). Cheers, mwh -- Ability to type on a computer terminal is no guarantee of sanity, intelligence, or common sense. -- Gene Spafford's Axiom #2 of Usenet From me at privacy.net Mon Aug 16 15:18:44 2004 From: me at privacy.net (Tobias Pfeiffer) Date: 16 Aug 2004 19:18:44 GMT Subject: Stopping a socket.accept() method References: <2o9mlbF8ff8rU1@uni-berlin.de> Message-ID: <2ocfkjF8v1qeU1@uni-berlin.de> Hi! On 16 Aug 2004, Peter Hansen wrote: > Tobias Pfeiffer wrote: > > 2. You can use a non-blocking socket and select(), which > will allow a periodic wakeup to check a flag that is set > by whatever mechanism you want to tell the prog to stop. And how exactly do you propose to code this "non-blocking socket"? I've no idea how to realize that? Could you maybe give me a little example of how to work with socket.accept() and select()? Bye Tobias -- please send any mail to botedesschattens(at)web(dot)de From olivierthiery at free.fr Mon Aug 9 15:05:14 2004 From: olivierthiery at free.fr (Olivier Thiery) Date: Mon, 09 Aug 2004 21:05:14 +0200 Subject: VB-like GUI designer? References: <278de0e.0408090935.6d758a5d@posting.google.com> Message-ID: <4117c80d$0$3158$626a14ce@news.free.fr> Hello, > - Like wxGlade, Boa is based on wxWidgets, but doesn't seem to have a > GUI builder. You just add widgets to a list, and I assume you have to I'm afraid it's wrong: Boa does include a (pretty usable) GUI builder, although it (oddly) better works on windows than linux. It handles even sizers. > set the coordinates and properties through code only. Also, Boa hasn't > been updated since April 2003 Wrong again: the last official release is 0.2.3 (see sf.net), but you can search google for a more recent downloadable 0.2.8 tgz. Boa may seem difficult to understand at first, but the (short) doc is very useful. You have to read it carefully first, especially the tutorial. Olivier From ramen at lackingtalent.com Thu Aug 12 14:30:09 2004 From: ramen at lackingtalent.com (Dave Benjamin) Date: Thu, 12 Aug 2004 18:30:09 -0000 Subject: PEP-0318 References: <41122FC2.1080608@interlink.com.au> <4114152f@nntp.zianet.com> <411421bf@nntp.zianet.com> <10hianhqvg1qc8d@news.supernews.com> Message-ID: In article <10hianhqvg1qc8d at news.supernews.com>, John Roth wrote: > One additional use case for decorators: prototype object systems. > I've been experimenting with Hans Nowak's system, and I am now > quite looking forward to having a single decorator that will bind the > function into an instance. For example: > > @instancemethod(myinstance) > def go(self, wordList): > ---stuff--- > > The result is that the function gets wrapped by new.instancemethod > and bound into the instance that's bound to myinstance. One possible implementation of such: import new def instancemethod(obj): def decorate(func): setattr(obj, func.func_name, new.instancemethod(func, obj)) return func return decorate class Empty(object): pass o = Empty() o.a = 5 o.b = 6 @instancemethod(o) def a_plus_b(self): return self.a + self.b print o.a_plus_b() -- .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:. "talking about music is like dancing about architecture." From ben at benlast.com Thu Aug 19 01:49:30 2004 From: ben at benlast.com (Ben Last) Date: Thu, 19 Aug 2004 06:49:30 +0100 Subject: age of Python programmers In-Reply-To: <20040818174601.GA3863@mirk.lan> Message-ID: > From: python-list-bounces+ben=benlast.com at python.org > [mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of > 67. My impression is that it easier to learn python when you are younger. > egbert I think the slowing down of the brain due to ageing is compensated for by the increase in experience (one makes fewer of the same mistakes again) and learning in how to learn :) b From robey at slash_dev_slash_random.org Wed Aug 18 17:03:27 2004 From: robey at slash_dev_slash_random.org (Robey Holderith) Date: Wed, 18 Aug 2004 16:03:27 -0500 Subject: Embedding Python in Python References: <7xu0v0l2be.fsf@ruckus.brouhaha.com> <7x3c2kkzn8.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 18 Aug 2004 19:44:47 +0000, JCM wrote: > Paul Rubin wrote: >> JCM writes: >>> If you're concerned about security, another possibility is to parse >>> the user's code and look for anything potentially dangerous. You'll >>> need to be aggressive, but I believe it's possible. For example, >>> disallow exec statements, the identifier "eval", any identifier of >>> __this__ form, import statements, etc. This is overly restrictive, >>> but it will provide security. > >> By the time you're done with all that, you may as well design a new >> restricted language and interpret just that. > >> Hint: >> e = vars()['__builtins__'].eval >> print e('2+2') > >> Even Java keeps getting new holes found, and Python is not anywhere >> near Java when it comes to this kind of thing. > > I don't think it's as difficult as you think. Your snippet of code > would be rejected by the rules I suggested. You'd also want to > prohibit other builtins like compile, execfile, input, reload, vars, > etc. I'm going to have to agree with Paul on this one. I do not feel up to the task of thinking of every possible variant of malicious code. There are far too many ways of writing the exact same thing. I think it would be much easier to write my own interpreter. -Robey From franz04 at yahoo.fr Tue Aug 17 11:32:32 2004 From: franz04 at yahoo.fr (=?iso-8859-1?q?Francis=20Lavoie?=) Date: Tue, 17 Aug 2004 11:32:32 -0400 (EDT) Subject: problem when getting ftp file Message-ID: <20040817153232.70132.qmail@web50108.mail.yahoo.com> I'm new to python and I'm not sure if I use the ftplib class correctly. I made a programm to update a pseudo-dynamic site via ftp. The site is a static html that include files update by ftp. It create 2 files, and html and a .dat file, which hold a easier to manipulate data. first of all, when I start the application, it connect to ftp, and get the .dat files on the ftp server to stay up to date. Then modification are done to the local file, when the application receive a update request, it take the local file and update it to the server. The update work perfectly, but the part I get the file from ftp cause me some trouble. The client app is run on windows. To create the file and to read it, I use open("myfile.dat").write and readlines, there's no problem, but when I get a new file from ftp, the return line disapear and readlines take the all the file as one line. To write the new file in ftp I use : storlines("STOR", open("myfile.dat").read) And to get it I use : retrlines("RETR", open("myfile.dat").write) If someone can guide me where to look to find a solution, it will be appreciated. Thank you __________________________________________________________ L?che-vitrine ou l?che-?cran ? magasinage.yahoo.ca From norman.werner at student.uni-magdeburg.de Mon Aug 30 04:47:12 2004 From: norman.werner at student.uni-magdeburg.de (norman werner) Date: 30 Aug 2004 01:47:12 -0700 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: > Well, let's see how your clear your mind was today. > > Either it's a joke, in which case it is clear to all > that it doesn't really mean troll, or it's not a joke > in which case I obviously don't know Esperanto. > > I read it as an 'two-in-one'. A (not funny) joke about the troll and an infantile sideremark about eo spreading more half-truths. "universal language" - Whats that? What is a universal language ... Besides expressing basic wishes for food, attention or love. And where is/was the relation between the troll and eo? > Here are the facts: > > 1. It's a joke, as you surmised. > > 2. I know Esperanto. i read it _later_ . From youre joke it seemed more like you "heard of esperanto". So I hereby withdraw the accusation of stupidity - standing firm only on the not-funny-front. > Now can you perhaps see that your first comment in the poor > translation of your own Esperanto is invalid and offensive? Allright - it was not a translation - the error was to call it an translation. But since only a extremly small minority of readers could read both - it seemed ok for me to change not the basic-message but the way to express this message. E.g. I could not see the relevance for a non-eo-speaker of eo having a x or not. So i changed this in the "translation". > By the way, to those not fluent in both languages, what this > fellow really wrote was more along the lines of "Please do not > joke about things you don't know about. Xah Lee certainly -- > because Esperanto has no "x" -- is not Esperanto. And your > joke is merely stupid." Yep. > > If you're going to accuse me of stupidity, please at least > get your own translation and logic skills in working order > first. At least i was not the only who misunderstood you. And please; Since you elaborated on my "translation" - it's ok to criticize. But the same does not hold true for my logic-skill-malfunction - so either do not diagnose it or elaborate more on it. Norman From max at alcyone.com Fri Aug 13 02:41:29 2004 From: max at alcyone.com (Erik Max Francis) Date: Thu, 12 Aug 2004 23:41:29 -0700 Subject: decorator syntax polling suggestion References: <411BF3FC.71051A6F@alcyone.com> Message-ID: <411C6299.D5F71E12@alcyone.com> Peter Hansen wrote: > On the other, if there are people who are dissatisfied with > @pie, they can vote, use the results to help them focus > their energies on the most likely alternate candidate(s), > and finally present a united front saying "uh, @pie > sucks, and we have a wide consensus that syntax XXXX > would be much better for these reasons..." > > Wouldn't that make sense? Yes, that would probably make the poll results more closely match up with reality. The problem is, that isn't the purpose of the poll as stated. On the contrary, they are used the certainly biased results of the poll to show that the @decorator syntax is unwanted, which is highly suspect. -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ No man who needs a monument ever ought to have one. -- Nathaniel Hawthorne From Michael.J.Fromberger at Clothing.Dartmouth.EDU Thu Aug 19 10:09:42 2004 From: Michael.J.Fromberger at Clothing.Dartmouth.EDU (Michael J. Fromberger) Date: Thu, 19 Aug 2004 10:09:42 -0400 Subject: PEP 318: Can't we all just get along? References: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: In article , Paul Morrow wrote: > Michael J. Fromberger wrote: > > > > Oh, I see it just fine -- but I still disagree with the idea of > > including any such implicit magic in the language. > > > > In fact, I don't like some of the magic that is already there -- such > > as, for instance, the automatic mangling of class members whose names > > begin with a double underscore to get "private" semantics. But that, at > > least, is easy to avoid, if one doesn't want to use it. > > > > Unless of course you want a method to be private/semi-private. How do > you feel about the way we can create/manipulate lists and dictionaries > using special (magical) syntax? Why is that different (acceptable)? > > x = [10, 20, 30] > > is shorthand for what would be much more code in other languages. Is > that syntax ok but > > def __iAmPrivate(): pass > > isn't? Why? I'm glad you asked this question -- you have highlighted an important distinction we should all heed. In short: The special syntax for list construction (to use your example) is "explicit magic" rather than "implicit magic." Use of a square-bracketed tuple for list construction is almost completely orthogonal to other language features (modulo indexing), it correlates well to other familiar notations for lists, and it improves the readability of the code without obscuring anything. These are some key hallmarks of good syntax. By contrast, the special leading-double-underscore convention for class members and the idea to identify instance, static, or class methods based on the name of their first parameter, are not even a visibly syntactic change. Each of these ideas specially overloads the single most common programming-language operation -- interpretation of a variable name -- under particular circumstances. This technique is (as far as I know) nearly unprecedented in other languages, so it would be surprising to most programmers. Furthermore, I think it makes code less readable, by hiding important facts inside an implicit assumption about the content of non-keyword identifiers, which are otherwise never special. Many people respond to this by saying, "The programmer has to be careful anyway, so what is one more thing?" You could ask the same question about drivers and beer. Little distractions add up to big mistakes. Let me add that I do not intend to assert that all syntactic sugar is bad (even if, as Alan Perlis suggested, "syntactic sugar causes cancer of the semi-colon" :) However, the simple fact is, unless there is a really good reason, we shouldn't make programmers (i.e., ourselves) memorize more special cases. Going back to your example: There is an excellent case for a compact and orthogonal list construction notation. There is no good case for magically overloading non-keyword identifiers in certain contexts -- especially when there is a better and more explicit way to do it. Thank you for your good example, Paul. Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From godoy at ieee.org Mon Aug 16 18:29:01 2004 From: godoy at ieee.org (Jorge Godoy) Date: Mon, 16 Aug 2004 19:29:01 -0300 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> <3064b51d.0408161354.618056ef@posting.google.com> Message-ID: beliavsky at aol.com writes: > ido: do i=1,n > ! some code > if (foo) exit ido ! exit outer loop > jdo: do j=1,n > ! some code > if (boo) exit jdo ! exit middle loop > do k=1,n > ! some code > if (goo) exit ! exit inner loop > end do > end do jdo > end do ido Just an attempt and trying to keep it like your code. >>> n = 10 # Just needed to run this... >>> for i in xrange(1, n): ... print 'i =', i # some code... ... if (i == 5): break # exit outer loop ... for j in xrange(1, n): ... print 'j =', j # some code... ... if (j == 3): break # exit middle loop ... for k in xrange(1, n): ... print 'k =', k # some code... ... if (k == 2): break # exit inner loop i = 1 j = 1 k = 1 k = 2 j = 2 k = 1 k = 2 j = 3 i = 2 j = 1 k = 1 k = 2 j = 2 k = 1 k = 2 j = 3 i = 3 j = 1 k = 1 k = 2 j = 2 k = 1 k = 2 j = 3 i = 4 j = 1 k = 1 k = 2 j = 2 k = 1 k = 2 j = 3 i = 5 >>> By using "<=" one could have one more iteraction, if this is what is done with your original code. Be seeing you, -- Godoy. From ben at benlast.com Thu Aug 19 03:00:00 2004 From: ben at benlast.com (Ben Last) Date: Thu, 19 Aug 2004 08:00:00 +0100 Subject: Displaying ipa in python.exe In-Reply-To: <000501c485aa$cf9e2940$8c42ab80@grimes1> Message-ID: From: Burgel Rosa Maria Faehndrich >I am having some trouble properly displaying unicode characters in python.exe. >print ur"\u0288" >print ur"\u0288".encode('utf-8') You don't say what environment (operating system, window type, etc) you're running Python.exe under, though from the fact you say "python.exe" rather than "python" I'd guess Windows. Different versions of Windows have different levels of support for Unicode, but if IDLE displays what you want, I suspect you're on 2000/XP, which makes this more of a Windows question than a Python one, but here we go anyway... The Windows "console" (Start/Run.../cmd.exe) supports one "code page" at a time. Each code page interprets the 256 8-bit characters as a different set of symbols. None of them will support all Unicode characters. You can change the code page that a given console window is using via the CHCP command. CMD supports a "/U" switch, but that just controls the type of output to a file or pipe (/U makes it unicode, /A makes it ANSI). So, the short answer is that you cannot display arbitrary Unicode strings via the console. You can work out what code page the console is using, and try and encode Unicode to strings in that encoding (myString.encode("cp850") on my system here), but it may well not be able to show it. regards ben From bac at OCF.Berkeley.EDU Tue Aug 24 15:18:16 2004 From: bac at OCF.Berkeley.EDU (Brett C.) Date: Tue, 24 Aug 2004 12:18:16 -0700 Subject: profiler In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022E53@exchange.hqamor.amorhq.net> References: <3A81C87DC164034AA4E2DDFE11D258E3022E53@exchange.hqamor.amorhq.net> Message-ID: <412B9478.3090609@ocf.berkeley.edu> Robert Brewer wrote: > Brett C. wrote: > >>As of Python 2.4 you can also compile in support for C-level >>profiling >>into the interpreter (--enable-profiling). See the in-dev docs >>(http://www.python.org/dev/doc/devel/) for details. > > > Drool. Thanks for the news. Since the first Python optimization is often > to stop calling Python functions (and inline instead), this'll be a big > help. :) > See, 2.4 is not just about decorators. =) And Nick Bastin deserves a good chunk of the thanks for the profiling work he did to get this added (the power of PyCON sprints =) . -Brett From FBatista at uniFON.com.ar Thu Aug 19 10:43:59 2004 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Thu, 19 Aug 2004 11:43:59 -0300 Subject: newbie Message-ID: [JASON JESSO] #- The error I get is: #- ./mkdir.py jason 0777 #- Traceback (most recent call last): #- File "./mkdir.py", line 31, in ? #- _mkdir( sys.argv[1], sys.argv[2] ) #- File "./mkdir.py", line 25, in _mkdir #- os.mkdir( newdir, mode ) #- TypeError: an integer is required #- #- When I convert the mode from a string to an octal with #- oct(int(sys.argv[2])) the permissions are all screwed #- up. #- #- Any help? Always reduce the problem to it simplest form: >>> perm = "0777" >>> oct(int(perm)) '01411' Also always say what you receive, why you don't like it, and what you expect. And an useful "Subject" won't hurt. Regards, . Facundo From google at daishi.fastmail.fm Fri Aug 6 03:08:04 2004 From: google at daishi.fastmail.fm (daishi) Date: 6 Aug 2004 00:08:04 -0700 Subject: @decorators Message-ID: For what it's worth: As far as I know, the proposed @decorator syntax will be the first time that two logical lines of python with the same indentation will not be independent of one another. Previously, when looking at: some_python(code) and_some_more = stuff there was no need to look at the the first line in order to know what the second line meant/did (and vice versa). It would seem that the cases when there are effects across multiple logical lines is captured in compound statements: """ Compound statements contain (groups of) other statements; they affect or control the execution of those other statements in some way. """ -Python Reference Manual My understanding of decorators is that they fit this definition. One thing that I am not entirely clear about is whether decorators are intended to be a compound statement themselves, or whether they are meant to simply be extensions of current compound statements such as function definition (and class definitions?) In either case, however, it seems that the following should apply: """ Each clause header begins with a uniquely identifying keyword and ends with a colon. A suite ... can be one or more indented statements on subsequent lines. """ -Python Reference Manual In the first case where decorators form their own compound statement, this would seem to imply the basic layout of: @decorator: def foo(): pass (Whether that uniquely identifying keyword for decorators happens to be spelled '@' is not important to me.) In the second case where decorators are simply extensions of current compound statements, the current wording of the Python Reference Manual would seem to imply that for function definition the clause header must begin with 'def'. I.e., the decorator should not come before the def, and certainly not on a separate line. Beyond this, however, for me it is not particularly important whether the decorator comes before/after the function name/argument list, and how it is delimited. I guess the basic point that I am trying to make is that what I find important is consistency with the basic visual layout of code promised (IMHO) by python. I believe that this promise is violated by the currently proposed decorator scheme. d PS: Although I believe the current view of the implementors is to view decorators as an extension to function definition, I believe that the separate compound statement view is fairly rich. As others have noted, it can make identical decorations simpler: @static,synchronized: def foo(): pass def bar(): pass From aisaac at american.edu Thu Aug 12 12:22:06 2004 From: aisaac at american.edu (Alan G Isaac) Date: Thu, 12 Aug 2004 12:22:06 -0400 Subject: pretty print 2D arrays Message-ID: <10hn65v5eltr65d@corp.supernews.com> I figure someone must have done this nicely but I can't find it. I'd like structured printing of 2D arrays, where an entry of None or '' should be printed as whitespace. Something like: Inputs: 2D array, 1D array of fixed field widths, 1D array of format suggestions Effect: formatted print of the 2D array (or its transpose) Thanks, Alan Isaac From insert at spam.here Fri Aug 20 10:57:06 2004 From: insert at spam.here (Doug Holton) Date: Fri, 20 Aug 2004 09:57:06 -0500 Subject: Alternative decorator syntax decision In-Reply-To: References: <10ia1a9jm9tkuca@corp.supernews.com> <84GdneSa3r-TR7jcRVn-tw@powergate.ca> Message-ID: > Exactly. From this standpoint, the list on the wiki should be filtered > to something that > 1) doesn't have the declaration in the body of the function > 2) doesn't have the declaration following the parameters > > 1) rules out D1 D2 E1 E2 > 2) rules out C1 C2 C3 C4 E3 I don't think so. C1 was the clear community favorite for months and still has many supporters. And putting the decorator at the top of the function had many supporters in the poll last week. > With the voting going the way it currently is J2 is winning anyway, J2 is winning because it was actively discussed right here on this newsgroup this past week. When I did a poll last week, E1 had just been actively discussed and it gained a lot of support. Next week who knows what will be the current flavor? From pf_moore at yahoo.co.uk Thu Aug 26 17:24:33 2004 From: pf_moore at yahoo.co.uk (Paul Moore) Date: Thu, 26 Aug 2004 22:24:33 +0100 Subject: Sound file manipulation in Python Message-ID: Does anyone know of a Python library which handles sound file formats (MP3, Ogg, FLAC are the three I'm nost interested in). I'd like something that can manipulate "metadata" - stuff like artist, title, album tags. I'm not critically interested in format conversion, or playing sound files - I can handle that with other applications. I'm using Windows, and Python 2.3, if it matters (as it might for C extensions). I can manage with just reading the metadata, but ideally writing would be useful, too. Multiple libraries is OK, but I need something more than just MP3. If there's nothing available for Python, does anyone know of a good C library that could be wrapped? (Or used via ctypes, maybe). Thanks, Paul. -- Ooh, how Gothic. Barring the milk. From crichton314 at btinternet.com Mon Aug 23 07:03:12 2004 From: crichton314 at btinternet.com (John Crichton) Date: 23 Aug 2004 04:03:12 -0700 Subject: Jython/Python and javax.swing.* References: <2004082212534416807%birded@verizonnet> Message-ID: <3b2846c4.0408230303.5250ca5@posting.google.com> Sherrod Faulks wrote in message news:<2004082212534416807%birded at verizonnet>... > I'm using Jython and in the python script I do: > > from javax import swing > result = javax.swing.JOptionPane.showInputDialog(wC, cmd[8:],"Prompt > from " + client.serverName, JOptionPane.PLAIN_MESSAGE) > > wC is a JFrame, cmd is a String and client.serverName is a String. > It won't show the JOptionPane, why? Hi Sherrod, Having had a look at my last post after a nights sleep I'm not sure it was very clear... If you change your script to the following it should work: import javax.swing as swing result = swing.JOptionPane.showInputDialog(wC, cmd[8:],"Promptfrom " + client.serverName, swing.JOptionPane.PLAIN_MESSAGE) Cheers, John From ben at benlast.com Fri Aug 20 07:14:11 2004 From: ben at benlast.com (Ben Last) Date: Fri, 20 Aug 2004 12:14:11 +0100 Subject: How to sort this kind of list easily? In-Reply-To: Message-ID: > From: Anthony Baxter, in response to BruceKL WhoH > list.sort sorts tuples by first argument, then second &c. If you want a > custom sort order, look at the decorate-sort-undecorate pattern. Or if you want to sort only on your Id, use a lambda: l.sort(lambda x,y: cmp(x[0],y[0])) To force sorting on just the nth element of the tuples, replace 0 with n in the above. b From peter_jacobi at gmx.net Mon Aug 2 06:19:55 2004 From: peter_jacobi at gmx.net (Peter Jacobi) Date: 2 Aug 2004 03:19:55 -0700 Subject: Codecs for ISO 8859-11 (Thai) and 8859-16 (Romanian) References: <410c2827$0$24830$9b622d9e@news.freenet.de> <410D7AB5.9040100@v.loewis.de> Message-ID: I've added an entry in the RFE tracker at http://sf.net/projects/python Regarding the correctness doubts, I can provide these three points os far: a) ISO 8859-n vs ISO-8859-n If the information at http://en.wikipedia.org/wiki/ISO_8859-1#ISO_8859-1_vs_ISO-8859-1 is correct, Python 8859-n codecs do implement the ISO standard charsets ISO 8859-n in the specialized IANA forms ISO-8859-n (and in agreement with the Unicode mapping files). So any difficult C0/C1 wording in the original ISO standard can be disregarded. b) libiconv ISO 8859-11 The implementation by Bruno Haible in libiconv does agree with the Unicode mapping file: http://cvs.sourceforge.net/viewcvs.py/libiconv/libiconv/lib/ c) IBM ICU4C The implementation in ICU4C does agree with the Unicode mapping file: http://oss.software.ibm.com/cvs/icu/charset/data/ucm/ Regards, Peter Jacobi From __peter__ at web.de Thu Aug 12 05:30:17 2004 From: __peter__ at web.de (Peter Otten) Date: Thu, 12 Aug 2004 11:30:17 +0200 Subject: [OT] Keyboard layout, was Re: PEP318 References: <20040812090056.00001e31@titan> Message-ID: Josef Dalcolmo wrote: > On many non-English keyboards it isn't exactly simple to type an '@', but > since decorators aren't going to be used everywhere, I guess this is a > weak point. Let me add that temporarily switching to an American keyboard layout (*) for programming helps with all of the following chars: @\[]{}|`. Peter (*) clearly an obsession of mine From michaels at rd.bbc.co.uk Thu Aug 12 04:52:13 2004 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Thu, 12 Aug 2004 09:52:13 +0100 Subject: A decorator syntax not yet mentioned (I think!) References: <60dfb6f6.0408111846.615ee9eb@posting.google.com> <3YWdnYxLf--ObofcRVn-pw@powergate.ca> Message-ID: Peter Hansen wrote: > Carl Banks wrote: >> One thing that's different is that, in all those cases, the second >> block has a keyword that can't appear alone. You can't have an >> except without a try, or an else without an if, but you could have a >> def without a decorate. ... > is this an argument based on presumed difficulties in > implementing the idea? Looking at the wiki it states (as negative points): 1 New keyword 2 Overkill for the simple case like classmethod 3 Many people felt it was wrong use of an identation suite. 4 Has the same problem as 5.A, in that the decorate block implicitly affects the following def. This does not occur elsewhere in Python. 5 Technical problems with the current grammar parser if a suite *starts* with an optional part. (Ending with an optional part, such as "else:" is OK, but starting with one is not.) 6 No implementation currently exists. 1 isn't a huge issue if the syntax has significant benefits - but I suspect that they would have to be significant to warrant the change. (Guido says he's more relaxed about the idea, but that might me a relaxation to just "No" rather than "no way, no how, buzz off" kind of feeling :) As per the comment on the wiki regarding 2), I'm not convinced that: decorate: staticmethod def somefunction(some, args): """some multi line comment""" x=function(call) if x = ... ... etc... is worse than: def somefunction(some, args): """some multi line comment""" x=function(call) if x = ... ... etc... somefunction = staticmethod(somefunction) It *is* marginally longer than @staticmethod, but I don't think it's any worse ? On the positive side the "decorate" approach appears to me MUCH clearer in complex cases, which strikes me as more pythonic. I love perl and python about as much as each other, but for different reasons - with one of the things I like about python is that when code gets complex it generally stays readable. Item 3 is opinion, but I don't know where the arguments are leading to that point, so I'll just take that at face value. I'm not convinced, but hey :) Regarding 4, it strikes me that this isn't the case (unless it strictly means "block"!). An import at the beginning of a block changes the meaning of a block. Similarly a class statement changes the meaning of the defs immediately following it. I'd agree that it's not ideal, but the argument that code preceding the def isn't allowed because it changes the meaning of the def doesn't make sense to me - that's what the @ syntax does. Item 6 is always the case for any new feature, so I doubt that's the real problem - the real problem here strikes me as item 5. I do wonder how difficult it would be to add though... Michael. -- Michael.Sparks at rd.bbc.co.uk British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From ptmcg at austin.rr._bogus_.com Fri Aug 20 01:25:48 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 20 Aug 2004 05:25:48 GMT Subject: Alternative decorator syntax decision References: Message-ID: "Arien Malec" wrote in message news:Xns954AB8327A955arienmalecyahoocom at 64.164.98.7... > "Paul McGuire" wrote in > news:t07Vc.1179$v86.188 at fe2.texas.rr.com: > > > There are a number of messages on the python-dev mail list that > > indicate that Guido is looking for some concensus to come from this > > list as to what *one* alternative syntax for decorators > > M, any keyword option using "transform" > > (I care more about semantics than syntax) > > Arien I can interpret "any keyword option using "transform"" to match J1, J2, or L. Please narrow "any keyword option using "transform"" down to 2 specific choices, otherwise I can only tally your vote for "M". -- Paul From skip at pobox.com Mon Aug 30 22:45:28 2004 From: skip at pobox.com (Skip Montanaro) Date: Mon, 30 Aug 2004 21:45:28 -0500 Subject: bad bsddb key/values on large data In-Reply-To: <20040830222950.58737.qmail@web51407.mail.yahoo.com> References: <20040830222950.58737.qmail@web51407.mail.yahoo.com> Message-ID: <16691.58952.276250.971662@montanaro.dyndns.org> Barry> The largest one, about 200 megs, is written, and can be read, and Barry> the strings are correctly formatted -- but the values attached to Barry> the keys are wrong ... ... Barry> Can anyone tell me if there is such a Python problem or a bsddb Barry> problem? You didn't say what versions of Berkeley DB or Python you are using. If you are using Berkeley DB 1.85, problems are to be expected. Upgrade to a later version. Skip From jacek.generowicz at cern.ch Mon Aug 30 04:23:21 2004 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 30 Aug 2004 10:23:21 +0200 Subject: The voodoo of zip(*someList) References: Message-ID: mdrop1 at yahoo.com (Message Drop Box) writes: > How (and why) does zip(*someList) work? [...] > I've never seen the star '*' outside of function/method definitions It can also be used in function invocations, where it means pretty much the reverse of what it means in function definitions. In a parameter list "*foo" means "collect remaining positional arguments into a sequence (tuple) called 'foo'". In an argument list, it means "take the sequence 'foo' and expand it into a set of positional arguments". You can "reverse" the **kwds syntax in the same way too. > and I've looked in the Python documentation without success. Try page 39 of the Python Reference Manual. From pm_mon at yahoo.com Sat Aug 21 11:12:37 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sat, 21 Aug 2004 11:12:37 -0400 Subject: __metaclass__ and __author__ are already decorators In-Reply-To: References: Message-ID: Erratum: > > def synchronized(decoratedFunc, trueOrFalse): > """ This describes the 'synchronized' decorator. """ > __decorator__ = True > __author__ = 'Martin Curry' > __version__ = '0.5' > # perform the synchronized operation on decoratedClass > > should have been def synchronized(decoratedFunc, trueOrFalse): """ This describes the 'synchronized' decorator. """ __decorator__ = True __author__ = 'Martin Curry' __version__ = '0.5' # perform the synchronized operation on decoratedFunc From theller at python.net Wed Aug 18 07:51:13 2004 From: theller at python.net (Thomas Heller) Date: Wed, 18 Aug 2004 13:51:13 +0200 Subject: Overriding tp_getset attribute in subclasses Message-ID: I have a subclassable type implemented in C, which has a 'value' attribute implemented in the tp_getset slot. The type is named c_long. The value attribute accepts and returns integers. Now I want to derive a subclass 'BOOL' (in Python) from it, where the 'value' attribute should accept and return bool instances: from ctypes import c_long class BOOL(c_long): def _get_value(self): return bool(c_long.value.__get__(self)) # this also works: # return bool(super(BOOL, self).value) def _set_value(self, val): c_long.value.__set__(self, val) # this does not work: # super(BOOL, self).value = val value = property(_get_value, _set_value) I had expected the commented out super() calls to also do the work, but at least in the _set_value method it does not work: File "c:\sf\ctypes\win32\wintypes.py", line 37, in _set_value super(BOOL, self).value = val TypeError: 'super' object has only read-only attributes (assign to .value) The c_long.value.__get__ and c_long.value.__set__ variants work, but they look strange - is there a better way? Thanks, Thomas From CarolCarrot at sofsof.net Mon Aug 16 22:11:32 2004 From: CarolCarrot at sofsof.net (Carol Carrot) Date: Mon, 16 Aug 2004 20:11:32 -0600 Subject: mailman mailing list program References: Message-ID: Thank you ! How do I know if I won the QOTW? Ah well I can keep trying. "Daniel Yoo" wrote in message news:cfrlid$1f8c$1 at agate.berkeley.edu... > Carol Carrot wrote: > > [exhasperated Mailman rant cut] > > > Hi Carol, > > Your question isn't really related to Python: Python's just the > implementation language for Mailman. A better bet is to ask your > question on "Mailman Users": > > http://list.org/lists.html > > where you can get help from dozens of other long-suffering Mailman > administrators. > > > : I'm trying to get a header to get attached tot he email. it gets stripped > : from the email, whwere as the footer comes in as an attachment. > : all this is buried under "non-digest" options for some crazy reason. > > Having a header is dependent on how messages are delivered. In digest > mode, messages are bundled and delivered as a single message. Sending > the same header, over and over in the bulk-message, would not be a > good idea. > > So that's why there is a separate variable option that describes the > header for non-digest messages (msg_header), and one for digest > messages (digest_header). I guess it might make sense to have a > separate "Header/Footer" configuration menu, but that's a user > interface issue. > > > > : How do I get the header to work? > > Did you update the 'msg_header' variable? > > > Please continue your questions on the 'Mailman Users' mailing list; > you should get better help from them. > > > Good luck to you! From pm_mon at yahoo.com Wed Aug 25 19:49:23 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Wed, 25 Aug 2004 19:49:23 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> Message-ID: Paul Morrow wrote: > and therefore it's ok to make all assignments to __xxx__ attributes > inside of a function def create /function attributes/ rather than /local > variables/. In My Opinion. From sthota at gmail.com Mon Aug 30 16:45:56 2004 From: sthota at gmail.com (shashaank) Date: 30 Aug 2004 13:45:56 -0700 Subject: dtml-sendmail Message-ID: hello all. i am new to both dtml and zope. i have inherited a piece of dtml code that essentially perfoms sending email. --snip-- Send email Subject: Confirming your account. Sorry, we could not process your email.

    :

    
    	    

    --snip-- the syntax looks fine and i have configured "MailHost" to our internal mail server 192.168.1.8 but the emails do not seem to go through nor do i get the exception message. can any one tell me if am missing something fundamental over here. thanks a lot. From jtauber at jtauber.com Mon Aug 16 15:00:05 2004 From: jtauber at jtauber.com (James Tauber) Date: Tue, 17 Aug 2004 03:00:05 +0800 Subject: passing globals to imported module Message-ID: <1092682805.7812.202438687@webmail.messagingengine.com> Had a question from a colleague that I embarrassingly couldn't answer. He has a script, foo.py with a global. He wants to import bar.py and needs that global available in bar.py The following obviously doesn't work: # foo.py my_global = "hello" print globals().keys() import bar # bar.py print globals().keys() and results in: ['__builtins__', '__name__', '__doc__', 'my_global'] ['__builtins__', '__name__', '__file__', '__doc__'] I'm not sure how to reimplement __import__ to make the global available to the imported module. Any suggestions? James -- James Tauber http://jtauber.com/ journeyman of some http://jtauber.com/blog/ From loic.mahe at free.fr Fri Aug 20 11:49:50 2004 From: loic.mahe at free.fr (Lo?c Mah?) Date: 20 Aug 2004 08:49:50 -0700 Subject: Rita Sue and Bob too References: Message-ID: <27a5ac50.0408200749.a1fd32f@posting.google.com> Hello You can do it with list List Comprehensions: BigList = ['Jean', 'Eric', 'Remy', 'Anne', 'Denis', 'Alain', 'Armel', 'Louis'] SmallList = ['Eric', 'Denis', 'Georges', 'Jean'] if ( [x for x in SmallList if x in BigList] == SmallList ): print "They were found" else: print "They are not in list" [x for x in SmallList if x in BigList] evaluates to a list with common elements of SmallList and BigList Lo?c From fischerlaender at gmx.de Thu Aug 12 18:49:43 2004 From: fischerlaender at gmx.de (Stefan Fischerl?nder) Date: 12 Aug 2004 15:49:43 -0700 Subject: Developing a Tool Band for IE in Python References: <4qn8e5qy.fsf@python.net> Message-ID: > > Is Python suitable for developing a tool band (something like the > > Google Toolbar) to be placed in the Internet Explorer's rebar? Does > > anyone even have any tutorial or something similiar? > ctypes (0.9.0) recently got a toolband sample - although currently it's only an > empty template displaying a button. Wow, great. Just for anyone else interested: http://starship.python.net/crew/theller/ctypes/ The toolband example is here: ctypes-0.9.0/win32/com/samples/server/IExplorer Stefan From krzysiek at asi.pwr.wroc.pl Wed Aug 18 18:42:26 2004 From: krzysiek at asi.pwr.wroc.pl (Krzysztof Drozd) Date: Thu, 19 Aug 2004 00:42:26 +0200 Subject: apache 2 & python Message-ID: how to configure apache 2 to work with python or mod_python? krzysiek ps: sory,my english is't perfect :) From dperl at rogers.com Mon Aug 30 12:28:18 2004 From: dperl at rogers.com (Dan Perl) Date: Mon, 30 Aug 2004 16:28:18 GMT Subject: initializing mutable class attributes References: Message-ID: Thanks, Peter. pychecker detecting the wrong use makes the argument that there is no excuse for making the mistake of not calling the parent's __init__ in subclasses. I am regularly using pychecker on my code, but I never saw that warning because I did use __init__ correctly. But I did make the mistake once of using a class attribute with an empty dictionary to initialize an instance attribute just because I was doing the same thing with immutable attributes. Fortunately, I caught it soon enough and I will not make that mistake again. But it was kind of an embarrassing mistake and I learned my lesson only after that. Dan "Peter Otten" <__peter__ at web.de> wrote in message news:cgvdun$1mb$01$1 at news.t-online.com... > You have to call base-class-__init__() in every non-trivial inheritance > scheme. Should you forget it, pychecker is always there to remind you > [....] > And here's what pychecker says: > > $ pychecker t1.py > Processing t1... > > Warnings... > > t1.py:9: Base class (t1.Y) __init__() not called > > Clear enough. > > Peter > From 510046470588-0001 at t-online.de Fri Aug 20 02:51:33 2004 From: 510046470588-0001 at t-online.de (510046470588-0001 at t-online.de) Date: 20 Aug 2004 08:51:33 +0200 Subject: My only complaint about Python References: Message-ID: <87isbepaiy.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> flab ba writes: > > with the free Visual C++ Toolkit. Instructions are here: all humbug. Visual C++ is nowhere near free, it's all proprietary. Klaus Schilling From alikakakhel3 at hotmail.com Sat Aug 28 17:03:59 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 28 Aug 2004 14:03:59 -0700 Subject: about presicion References: Message-ID: <8f17f4bc.0408281303.3cfb4199@posting.google.com> "Batista, Facundo" wrote in message news:... > [alikakakhel3 at hotmail.com] > > > #- I was wondering if it was posible to get very good presicion. I mean > #- like to the to the 100 th or more decimal place. if so how? > > In Python 2.4 you'll have the Decimal module: > > > Python 2.4a2 (#55, Aug 5 2004, 11:42:43) [MSC v.1310 32 bit (Intel)] on > win32 > ... > >>> import decimal > >>> decimal.getcontext().prec=100 > >>> d = decimal.Decimal(2) > >>> d.sqrt() > Decimal("1.41421356237309504880168872420969807856967187537694807317667973799 > 0732478462107038850387534327641573") > > Enjoy it. > > . Facundo The decimal module comes with python 2.4? I have 2.3, :(, what do I do? From FBatista at uniFON.com.ar Tue Aug 31 09:12:36 2004 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Tue, 31 Aug 2004 10:12:36 -0300 Subject: has_method Message-ID: [Gandalf] #- Does anyone knows how to tell if an object has a method with a given #- name? How can I access that method? >>> class C: def mymeth(self): return >>> c = C() >>> dir(c) ['__doc__', '__module__', 'mymeth'] >>> c.mymeth > >>> . Facundo From rich.teer at rite-group.com Tue Aug 31 12:49:59 2004 From: rich.teer at rite-group.com (Rich Teer) Date: Tue, 31 Aug 2004 16:49:59 GMT Subject: Xah Lee's Unixism In-Reply-To: <%T%Yc.29567$Es2.11957889@news4.srv.hcvlny.cv.net> References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4PGdnfsOfdDPi63cRVn-tA@speakeasy.net> <41337FC9.8070902@hotmail.com> <%T%Yc.29567$Es2.11957889@news4.srv.hcvlny.cv.net> Message-ID: On Tue, 31 Aug 2004, John W. Kennedy wrote: > Yes, and also a single-process pipe emulator. Ever since 2.0, MS has > been trying to turn MS-DOS (later, Windows) into a Unix clone. ... And has failed miserably to do so. -- Rich Teer, SCNA, SCSA, author of "Solaris Systems Programming", published in August 2004. President, Rite Online Inc. Voice: +1 (250) 979-1638 URL: http://www.rite-group.com/rich From ralf at brainbot.com Thu Aug 19 12:28:16 2004 From: ralf at brainbot.com (Ralf Schmitt) Date: Thu, 19 Aug 2004 18:28:16 +0200 Subject: My only complaint about Python References: Message-ID: <86d61nay8v.fsf@stronzo.brainbot.com> Darren Dale writes: > I love the language. I love the community. My only complaint is that > Python for Windows is built with Visual Studio. > > It is too difficult to build python, or a module, from source. This is > what open source is all about, isnt it? I even have a copy of visual > studio, and I still cant build modules from source, because my > academic copy is version 7. As a scientist funded by the NSF, I feel > compelled to do all my work using free software (I feel compelled to > use free software, regardless). And I feel compelled to contribute to > the scientific capabilities of my favorite programming language. But > this compiler issue is a big (and seemingly unnecessary) > impediment. Will the BDFL ever split with Visual Studio? You can build modules using msys/mingw. Instructions can be found at http://sebsauvage.net/python/mingw.html -- brainbot technologies ag boppstrasse 64 . 55118 mainz . germany fon +49 6131 211639-1 . fax +49 6131 211639-2 http://brainbot.com/ mailto:ralf at brainbot.com From davecook at nowhere.net Thu Aug 5 06:12:06 2004 From: davecook at nowhere.net (David Cook) Date: Thu, 05 Aug 2004 10:12:06 GMT Subject: DB beginner help References: Message-ID: On 2004-08-05, Zeljko Vrba wrote: > 2. How are you supposed to write DB-driver independent code when each > driver has its own, possibly different from any other, paramstyle > ('qmark', 'numeric', etc..)? This recipe might help: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278612 I haven't tried it. > In Perl I always use question marks and have no trouble switching the > application between different databases. How do you guys do it in Python > (of course, without rewriting all queries?) pyformat is the most useful IMO, e.g. cursor.execute( "insert into foo (baz, quux) values (%(baz)s, %(quux)s)", {'parrot' : 'deceased', 'quux' : "O'Reilly", 'baz' : 1}) The values for 'baz' and 'quux' will be interpolated and quoted correctly, and 'parrot' will be ignored. A few adapters have a dictfetch method, but for those that don't, getting your data out in dict form is a two liner: fieldnames = [tup[0] for tup in cursor.description] dictrows = [dict(zip(fieldnames, row)) for row in cursor.fetchall()] Dave Cook From ville at spammers.com Sun Aug 22 04:29:25 2004 From: ville at spammers.com (Ville Vainio) Date: 22 Aug 2004 11:29:25 +0300 Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WEDONE? References: Message-ID: >>>>> "Robert" == Robert Brewer writes: Robert> I'd be most interested to hear arguments _against_ Robert> "declare", if there are any. Python will have optional type declarations in the future - having the word "declare" signify decoration might conflict with the terminology used for type declarations. Even if the type declarations didn't use the "declare" keyword in code (which is probably the case), there might still be some confusion regarding the documentation. -- Ville Vainio http://tinyurl.com/2prnb From http Fri Aug 27 04:21:38 2004 From: http (Paul Rubin) Date: 27 Aug 2004 01:21:38 -0700 Subject: lambda ?? References: <6f402501.0408270000.31ad1455@posting.google.com> Message-ID: <7xoekxgfe5.fsf@ruckus.brouhaha.com> fuzzyman at gmail.com (Michael Foord) writes: > It starts by giving some basic examples using lambda. What I'm > wondering is what's the actual difference between these two forms ? > > pr = lambda s:s > *and* > def pr(s): > return s They're the same. > Is it just a basic example (and so in this case there is no > difference).. or am I missing something. (What's the point of an > 'anonymous' function... if you give a name to it !!). It's like an anonymous expression. Look at the statement x = a + b * c That adds the expression 'a' to the expression 'b * c'. If Python didn't have anonymous expressions, you'd say something like temp = b * c x = a + temp Anonymous just means you can use it as an intermediate result without having to give it a name of its own. Example: def derivative(f, x): # find approximate value of f'(x) h = .0001 return (f(x+h) - f(x)) / h def square(x): return x*x print derivative(square, 3) # approximately 6 An anonymous function lets you do the same thing without having to create a named function (like a temporary variable): print derivative(lambda x: x*x, 3) # same thing Using a lot of lambdas can be like using a lot of complicated, deeply nested arithmetic expressions. You have to exercise some judgement to keep your code readable. But there's a school of thought that says lambda is a wart in Python and shouldn't be used. That's as silly as saying you should never say "a + b * c" and instead name every subexpression with a temp variable. From max at alcyone.com Thu Aug 12 19:26:24 2004 From: max at alcyone.com (Erik Max Francis) Date: Thu, 12 Aug 2004 16:26:24 -0700 Subject: decorator syntax polling suggestion References: Message-ID: <411BFCA0.CF885BEC@alcyone.com> Doug Holton wrote: > So if Guido does want to pay attention to the opinions of Python users > (and he doesn't have to), then changing the current syntax probably > wouldn't be an unpopular decision. The point is that even if Guido does want to pay attention to the opinions of Python users, the results of this particular poll may not be the best way to do it. -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ She's your moon, she's your sun / She could even be the one -- Nik Kershaw From ben at benlast.com Mon Aug 30 12:03:23 2004 From: ben at benlast.com (Ben Last) Date: Mon, 30 Aug 2004 17:03:23 +0100 Subject: PHP Documentation In-Reply-To: <3_CdnTrTktNkoK7cRVn-qw@comcast.com> Message-ID: > From Larry Bates > Zope has such a system in place for their docs. You can just ask > that the comments be hidden and they disappear. It does appear to > provide a way to make comments, add examples clarification that > "may" get included in the next version of the docs. The Zope system has a couple of drawbacks: Firstly, the comments are always downloaded as part of the web page; they're shown/hidden by JavaScript, and on the big pages that can be quite a slow process. That's not such a big deal, but the second drawback is that there's no way to edit a comment once made, so the pages have gradually filled up with junk remarks. Those who have the power to edit don't seem to. A Python docs Wiki sounds like an interesting idea; I'll certainly be taking a look at the one quoted. Offhand, does anyone know if the license on the Python Docs would allow them to be freely copied and used as the basis of a Wiki? b From ptmcg at austin.rr._bogus_.com Wed Aug 25 08:50:33 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Wed, 25 Aug 2004 12:50:33 GMT Subject: Is it a bug (or a feature)? References: Message-ID: Looking further at Message.py, __delitem__ has this same problem. When fixing this, should probably also add an __iter__ method, that would return iter(self._headers). -- Paul From brett at python.org Tue Aug 24 14:51:03 2004 From: brett at python.org (Brett C.) Date: 24 Aug 2004 11:51:03 -0700 Subject: profiler In-Reply-To: Message-ID: As of Python 2.4 you can also compile in support for C-level profiling into the interpreter (--enable-profiling). See the in-dev docs (http://www.python.org/dev/doc/devel/) for details. From mcfletch at rogers.com Wed Aug 18 10:15:36 2004 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Wed, 18 Aug 2004 10:15:36 -0400 Subject: age of Python programmers In-Reply-To: References: Message-ID: <41236488.5060200@rogers.com> Lucas Raab wrote: >One thing I've always kind of wondered is what is the average age of a >Python programmer?? What age groups use Python?? Something to think >about.... > > It's going to take a long time if we all just give single numbers. From what I've seen at PyCon and PyGTA (and I *suck* at guessing ages, btw), there is a large population lump in the late teens and early twenties among the Twisted developers. IIRC there was actually a PyCon survey that might have this information with *real* numbers. Theres a good little bump among the scientific and core-dev peoples for late forties and above (maybe those careers keep you flexible enough to try new things? Maybe the projects are experimental enough that using a "new" language isn't a problem?) Beyond those groups, I would guess the average is in the early thirties/late twenties, with most of the bulk from 25-ish through 33-ish. Of course, the "casual" Python programmer isn't likely to show up to *any* Python-related event, and there are likely more of them than those of us who've drunk the kool-aid. And as I mentioned before, I suck at guessing ages... It's so much more efficient to just make up the statistics. Mike ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From Majordomo at wolfram.com Wed Aug 11 05:01:01 2004 From: Majordomo at wolfram.com (Majordomo at wolfram.com) Date: Wed, 11 Aug 2004 04:01:01 -0500 Subject: Majordomo results: [PMX:VIRUS] Re: Proof of concept Message-ID: <200408110901.i7B911cE012665@mailhub.wolfram.com> -- >>>> This is a multi-part message in MIME format. **** Command 'this' not recognized. >>>> >>>> >>>> >>>> ------=_NextPart_000_0016----=_NextPart_000_0016 **** Command '------=_nextpart_000_0016----=_nextpart_000_0016' not recognized. >>>> Content-Type: text/plain; **** Command 'content-type:' not recognized. >>>> charset="Windows-1252" **** Command 'charset="windows-1252"' not recognized. >>>> Content-Transfer-Encoding: 7bit **** Command 'content-transfer-encoding:' not recognized. >>>> >>>> The sample is attached! **** Command 'the' not recognized. >>>> >>>> +++ Attachment: No Virus found **** Command '+++' not recognized. >>>> +++ MessageLabs AntiVirus - www.messagelabs.com **** Command '+++' not recognized. >>>> >>>> >>>> ------=_NextPart_000_0016----=_NextPart_000_0016 **** Command '------=_nextpart_000_0016----=_nextpart_000_0016' not recognized. >>>> Content-Type: text/plain; charset=UTF-8 **** Command 'content-type:' not recognized. >>>> Content-Transfer-Encoding: 8bit **** Command 'content-transfer-encoding:' not recognized. >>>> >>>> The original content of this message part has been replaced **** Command 'the' not recognized. >>>> by this text because it tested positive for the following **** Command 'by' not recognized. >>>> virus(es): **** Command 'virus(es):' not recognized. >>>> >>>> W32/Netsky-P, W32/Netsky-P **** Command 'w32/netsky-p,' not recognized. >>>> >>>> The original message has been quarantined pending further **** Command 'the' not recognized. >>>> action by the mail administrator. For further information **** Command 'action' not recognized. >>>> about the message and its delivery status, please contact **** Command 'about' not recognized. >>>> the undersigned, and include the full content of this **** Command 'the' not recognized. >>>> message. The identifier for this message is **** Command 'message.' not recognized. >>>> 'i7B90uaL012641'. **** Command ''i7b90ual012641'.' not recognized. >>>> >>>> This notification is being sent to you and any other **** Command 'this' not recognized. >>>> original envelope recipient(s). To avoid creating a **** Command 'original' not recognized. >>>> nuisance and to keep mail traffic under control, the **** Command 'nuisance' not recognized. >>>> original sender of the message has NOT been notified. **** Command 'original' not recognized. >>>> However, you may want to notify the sender at your **** Command 'however,' not recognized. >>>> discretion. **** Command 'discretion.' not recognized. >>>> >>>> >>>> The Management **** Command 'the' not recognized. >>>> PureMessage Admin **** Command 'puremessage' not recognized. >>>> >>>> ------=_NextPart_000_0016----=_NextPart_000_0016-- **** Command '------=_nextpart_000_0016----=_nextpart_000_0016--' not recognized. >>>> **** No valid commands found. **** Commands must be in message BODY, not in HEADER. **** Help for Majordomo at wolfram.com: This help message is being sent to you from the Majordomo mailing list management system at Majordomo at wolfram.com. This is version 1.94.5 of Majordomo. If you're familiar with mail servers, an advanced user's summary of Majordomo's commands appears at the end of this message. Majordomo is an automated system which allows users to subscribe and unsubscribe to mailing lists, and to retrieve files from list archives. You can interact with the Majordomo software by sending it commands in the body of mail messages addressed to "Majordomo at wolfram.com". Please do not put your commands on the subject line; Majordomo does not process commands in the subject line. You may put multiple Majordomo commands in the same mail message. Put each command on a line by itself. If you use a "signature block" at the end of your mail, Majordomo may mistakenly believe each line of your message is a command; you will then receive spurious error messages. To keep this from happening, either put a line starting with a hyphen ("-") before your signature, or put a line with just the word end on it in the same place. This will stop the Majordomo software from processing your signature as bad commands. Here are some of the things you can do using Majordomo: I. FINDING OUT WHICH LISTS ARE ON THIS SYSTEM To get a list of publicly-available mailing lists on this system, put the following line in the body of your mail message to Majordomo at wolfram.com: lists Each line will contain the name of a mailing list and a brief description of the list. To get more information about a particular list, use the "info" command, supplying the name of the list. For example, if the name of the list about which you wish information is "demo-list", you would put the line info demo-list in the body of the mail message. II. SUBSCRIBING TO A LIST Once you've determined that you wish to subscribe to one or more lists on this system, you can send commands to Majordomo to have it add you to the list, so you can begin receiving mailings. To receive list mail at the address from which you're sending your mail, simply say "subscribe" followed by the list's name: subscribe demo-list If for some reason you wish to have the mailings go to a different address (a friend's address, a specific other system on which you have an account, or an address which is more correct than the one that automatically appears in the "From:" header on the mail you send), you would add that address to the command. For instance, if you're sending a request from your work account, but wish to receive "demo-list" mail at your personal account (for which we will use "jqpublic at my-isp.com" as an example), you'd put the line subscribe demo-list jqpublic at my-isp.com in the mail message body. Based on configuration decisions made by the list owners, you may be added to the mailing list automatically. You may also receive notification that an authorization key is required for subscription. Another message will be sent to the address to be subscribed (which may or may not be the same as yours) containing the key, and directing the user to send a command found in that message back to Majordomo at wolfram.com. (This can be a bit of extra hassle, but it helps keep you from being swamped in extra email by someone who forged requests from your address.) You may also get a message that your subscription is being forwarded to the list owner for approval; some lists have waiting lists, or policies about who may subscribe. If your request is forwarded for approval, the list owner should contact you soon after your request. Upon subscribing, you should receive an introductory message, containing list policies and features. Save this message for future reference; it will also contain exact directions for unsubscribing. If you lose the intro mail and would like another copy of the policies, send this message to Majordomo at wolfram.com: intro demo-list (substituting, of course, the real name of your list for "demo-list"). III. UNSUBSCRIBING FROM MAILING LISTS Your original intro message contains the exact command which should be used to remove your address from the list. However, in most cases, you may simply send the command "unsubscribe" followed by the list name: unsubscribe demo-list (This command may fail if your provider has changed the way your address is shown in your mail.) To remove an address other than the one from which you're sending the request, give that address in the command: unsubscribe demo-list jqpublic at my-isp.com In either of these cases, you can tell Majordomo at wolfram.com to remove the address in question from all lists on this server by using "*" in place of the list name: unsubscribe * unsubscribe * jqpublic at my-isp.com IV. FINDING THE LISTS TO WHICH AN ADDRESS IS SUBSCRIBED To find the lists to which your address is subscribed, send this command in the body of a mail message to Majordomo at wolfram.com: which You can look for other addresses, or parts of an address, by specifying the text for which Majordomo should search. For instance, to find which users at my-isp.com are subscribed to which lists, you might send the command which my-isp.com Note that many list owners completely or fully disable the "which" command, considering it a privacy violation. V. FINDING OUT WHO'S SUBSCRIBED TO A LIST To get a list of the addresses on a particular list, you may use the "who" command, followed by the name of the list: who demo-list Note that many list owners allow only a list's subscribers to use the "who" command, or disable it completely, believing it to be a privacy violation. VI. RETRIEVING FILES FROM A LIST'S ARCHIVES Many list owners keep archives of files associated with a list. These may include: - back issues of the list - help files, user profiles, and other documents associated with the list - daily, monthly, or yearly archives for the list To find out if a list has any files associated with it, use the "index" command: index demo-list If you see files in which you're interested, you may retrieve them by using the "get" command and specifying the list name and archive filename. For instance, to retrieve the files called "profile.form" (presumably a form to fill out with your profile) and "demo-list.9611" (presumably the messages posted to the list in November 1996), you would put the lines get demo-list profile.form get demo-list demo-list.9611 in your mail to Majordomo at wolfram.com. VII. GETTING MORE HELP To contact a human site manager, send mail to Majordomo-Owner at wolfram.com. To contact the owner of a specific list, send mail to that list's approval address, which is formed by adding "-approval" to the user-name portion of the list's address. For instance, to contact the list owner for demo-list at wolfram.com, you would send mail to demo-list-approval at wolfram.com. To get another copy of this help message, send mail to Majordomo at wolfram.com with a line saying help in the message body. VIII. COMMAND SUMMARY FOR ADVANCED USERS In the description below items contained in []'s are optional. When providing the item, do not include the []'s around it. Items in angle brackets, such as
    , are meta-symbols that should be replaced by appropriate text without the angle brackets. It understands the following commands: subscribe [
    ] Subscribe yourself (or
    if specified) to the named . unsubscribe [
    ] Unsubscribe yourself (or
    if specified) from the named . "unsubscribe *" will remove you (or
    ) from all lists. This _may not_ work if you have subscribed using multiple addresses. get Get a file related to . index Return an index of files you can "get" for . which [
    ] Find out which lists you (or
    if specified) are on. who Find out who is on the named . info Retrieve the general introductory information for the named . intro Retrieve the introductory message sent to new users. Non-subscribers may not be able to retrieve this. lists Show the lists served by this Majordomo server. help Retrieve this message. end Stop processing commands (useful if your mailer adds a signature). Commands should be sent in the body of an email message to "Majordomo at wolfram.com". Multiple commands can be processed provided each occurs on a separate line. Commands in the "Subject:" line are NOT processed. If you have any questions or problems, please contact "Majordomo-Owner at wolfram.com". From dave at pythonapocrypha.com Thu Aug 26 11:49:22 2004 From: dave at pythonapocrypha.com (Dave Brueck) Date: Thu, 26 Aug 2004 09:49:22 -0600 Subject: Best processor (i386) for Python performance? In-Reply-To: <412dfb17$0$65599$a1866201@newsreader.visi.com> References: <412dfb17$0$65599$a1866201@newsreader.visi.com> Message-ID: <412E0682.5030408@pythonapocrypha.com> Grant Edwards wrote: > On 2004-08-26, Brett C. wrote: > > >>In terms of multithreading, an I/O intensive app that is >>threaded can make use of dual procs. Otherwise threaded apps >>can't for technical reasons (GIL and such but don't need to >>get into those details). > > > That's rather dissappointing. If I write a multi-threaded app > in C it can utilize multiple processors, but the same app in > Python can't? Depends on what the multithreaded app _does_. If multiple processors are present then Python will use them, but how well they get used depends on how much and for what reasons the GIL gets released. I/O is the most common reason, so adding another processor to an I/O bound program can give you a good performance boost (in our lab I've seen easily 75% improvement over a single proc box for a program that was very I/O bound, but I haven't measured it to see if it's closer to 75% or to 100% improvement). Another easy boost comes if your app already calls out to a GIL-releasing C function for CPU-intensive work, then adding a CPU can give similar speed boosts - we have only one such case and although there was noticable speedup in dual vs single processors, I never attempted to quantify it. And the normal restrictions on parallel computing apply - if whatever you're doing can't be done in parallel anyway, then adding a CPU isn't helpful. :) FWIW I haven't noticed a case where adding a CPU improved performance by *less* than ~25%, probably because the GIL gets released here and there for various operations anyway, and having an existing multithreaded app where multiple threads are CPU bound is somewhat uncommon. But then again very few of the projects I work on end up having CPU as the most scarce resource so the machines that do have multiple CPUs are that way because they are running oodles of other processes as well. -Dave From skip at pobox.com Fri Aug 13 13:30:33 2004 From: skip at pobox.com (Skip Montanaro) Date: Fri, 13 Aug 2004 12:30:33 -0500 Subject: PEP 318 decorators are not Decorators In-Reply-To: References: Message-ID: <16668.64185.454373.110884@montanaro.dyndns.org> 1) That's not mentioned in PEP 318 We can fix that. 2) That's in disagreement with http://www.python.org/moin/PythonDecorators That too (different authors, by the way). Arien> 3) Won't most programmers think GoF decorators before compiler Arien> syntax tree decorators? Not if they are unfamiliar with the GoF patterns (myself included). Skip From jfouhy at paradise.net.nz Mon Aug 2 18:46:36 2004 From: jfouhy at paradise.net.nz (John Fouhy) Date: 2 Aug 2004 15:46:36 -0700 Subject: Lambdas and variables References: Message-ID: James Henderson wrote in message news:... > I agree it's a gotcha. Interestingly you would have been forced to pass > x in as a default argument and avoided your problem until Python > introduced nested scopes in versions 2.1 and 2.2. You may find PEP 227 > on statically nested scopes illuminating: > > http://www.python.org/peps/pep-0227.html Heh. """ The proposed solution, in crude terms, implements the default argument approach automatically. The "root=root" argument can be omitted. """ Ok, I've got it now (famous last words). Thanks for your help :-) -- John. From zanesdad at bellsouth.net Thu Aug 26 14:05:58 2004 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Thu, 26 Aug 2004 14:05:58 -0400 Subject: Mysql in Python? In-Reply-To: <2p6m32Fh7o9oU1@uni-berlin.de> References: <2p6m32Fh7o9oU1@uni-berlin.de> Message-ID: <412E2686.7040209@bellsouth.net> Stefan Stolz wrote: >Hello, >i tried to find something about mysql in www.python.org, but found >nothing... >What can you recommend to use for getting and putting data from and into a >mysql database? >On my Suse 9.1 i found a rpm python-mysql. In the web i found the hk_classes >from www.knoda.org. This should do also such things. >Can you recommend something? What do you use? >Thank you very much for the info. > > I have used a MySQLdb module before. Here's a piece of code that I found lying around my home directory: import MySQLdb if __name__ == "__main__": db_conn = MySQLdb.connect(host='hostname',db='database_name',user='username',passwd='password') handle = db_conn.cursor() query = "SELECT * FROM foo" handle.execute(query) Results = handle.fetchall() print Results I'm not sure, but I believe that MySQLdb is included in this project: http://sourceforge.net/projects/mysql-python (which appears to have been updated only a couple of months back, so that's good news). From reinhold-birkenfeld-nospam at wolke7.net Thu Aug 26 13:24:54 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Thu, 26 Aug 2004 19:24:54 +0200 Subject: urllib hangs In-Reply-To: References: Message-ID: <2p6kgfFhgddeU2@uni-berlin.de> Jay Donnell wrote: > Apparently you don't know what exactly means ;) Apparently _you_ don't know how to quote... Reinhold -- [Windows ist wie] die Bahn: Man muss sich um nichts kuemmern, zahlt fuer jede Kleinigkeit einen Aufpreis, der Service ist mies, Fremde koennen jederzeit einsteigen, es ist unflexibel und zu allen anderen Verkehrs- mitteln inkompatibel. -- Florian Diesch in dcoulm From aleaxit at yahoo.com Fri Aug 27 17:08:19 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 27 Aug 2004 23:08:19 +0200 Subject: Alex Martelli: Welcome back! References: <1gj70s0.cc0xt0bs9aduN%aleaxit@yahoo.com> Message-ID: <1gj79a7.wv6it11nd8gjbN%aleaxit@yahoo.com> Dave Benjamin wrote: > In article <1gj70s0.cc0xt0bs9aduN%aleaxit at yahoo.com>, Alex Martelli wrote: > > Dave Benjamin wrote: > > > >> It's nice to see you around here again! > > > > Thanks! Hope I can stay a while... > > Did you leave in frustration or did you just get busy? I got too busy to follow c.l.py -- essentially because I keep having a hard time, psychologically, just killfiling the [f]lamers, the deuced people that come here to criticize Python and/or demand changes. This time around I'm gonna try -- I'm as busy as ever (the 2nd Edition of the Python Cookbook is at least as intense a project as the first was...), but if I can steel myself to use my killfile 100 times more than in the past, and still try to respond on some threads which might be interesting or useful. We'll see if it works! Alex From newsgroups at jhrothjr.com Sat Aug 7 07:26:58 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Sat, 7 Aug 2004 07:26:58 -0400 Subject: Further changes to source encodings (Was: PEP 263 status check) References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> <10h5hgvpafm8a64@news.supernews.com> <41133C76.8040302@v.loewis.de> <10h6rklt3fa1690@news.supernews.com> <41137799.70808@v.loewis.de> <10h724r20kkeqb2@news.supernews.com> <4113D8DF.8080106@v.loewis.de> <10h7tb8nn53ajbb@news.supernews.com> <4114070F.90507@v.loewis.de> <10h8f3md11sou81@news.supernews.com> <411462b5$0$27020$9b622d9e@news.freenet.de> Message-ID: <10h9f3kjlr8up8f@news.supernews.com> "Martin v. L?wis" wrote in message news:411462b5$0$27020$9b622d9e at news.freenet.de... > John Roth wrote: > > I don't believe I ever said that PEP 263 said there was > > a difference. If I gave you that impression, I will > > appologize if you can show me where it I did it. > > In <10h5hgvpafm8a64 at news.supernews.com>, titled > " PEP 263 status check", you write > > [quote] > My specific question there was how the code handles the > combination of UTF-8 as the encoding and a non-ascii > character in an 8-bit string literal. Is this an error? > [end quote] > > So I assumed you were all the time talking about how this > is implemented, and how you expected to be implemented, > and I assumed we agree that the implementation should > match the specification in PEP 263. Ah! While my assumption was that the code had been implemented correctly according to the specification, and that the specification leaves a trap for the unwary in one very significant (although also very narrow) case. > > As far as I'm concerned, what PEP 263 says is utterly > > irrelevant to the point I'm trying to make. > > Then I don't know what the point is you are trying to > make. It appears that you are now saying that Python > does not work the way it should work. IOW, you are > proposing that it be changed, right? This sounds like > another PEP. It could very well be another PEP. > > > 8-bit strings have a builtin assumption that one > > byte equals one character. > > Not at all. Some 8-bit strings don't denote characters > at all, and some 8-bit string, atleast in some regions > of the world, are deliberately using multi-byte character > encodings. In particular, UTF-8 is such an encoding. This is true, but it's also beside the point. Most *programmers* (other than ones that use single-language multi-byte encodings) make that assumption. If they didn't there wouldn't be a problem. Every tutorial I've ever seen on unicode spends a great deal of time at the beginning explaining the difference between bytes, characters, encodings and all that stuff. If this was common knowledge, why would the authors bother? They bother simply because it isn't common knowledge, at least in the sense that it's wired into developer's common coding intuitions and habits. > > The problem I have is that if you use utf-8 as the > > source encoding, you can suddenly drop multi-byte > > characters into an 8-bit string ***BY ACCIDENT***. > Ok. > > Now, my suggested solution of this problem was > > to require that 8-bit string literals in source that was > > encoded with UTF-8 be restricted to the 7-bit > > ascii subset. > > Ok. I disagree that this is desirable; if you really > want to see that happen, you should write a PEP. > > > The second possibility begs the question of what > > encoding to use, which is why I don't seriously > > propose it (although if I understand Hallvard's > > position correctly, that's essentially his proposal.) > > No. He proposes your third alternative (ban non-ASCII > characters in byte string literals), not just for UTF-8, > but for all encodings. Not for all files, though, but > only for selected files. Which is what I don't like about it. It adds complexity to the language and a feature that I don't think is really necessary (restricting string literals for single-byte encodings.) The other thing I don't like is that it still leaves the trap for the unwary which I'm discussing. > >>If > >>there is no encoding declaration whatsoever, Python will > >>assume that the source is us-ascii. > [...] > > The last sentence puzzles me. In 2.3, absent a declaration > > (and absent a parameter on the interpreter) Python assumes > > that the source is Latin-1, and phase 2 was to change > > this to the 7-bit ascii subset (US-Ascii). That was the > > original question at the start of this thread. I had assumed > > that change was to go into 2.4, your reply made it seem > > that it would go into 2.5 (maybe.) This statement makes > > it seem that it is the current state in 2.3. > > With "will assume", I actually meant future tense. Not > being a native speaker, I'm uncertain how to distinguish > this from the conditional form that you apparently understood. Ah. I understand now. I understood the final clause as a form of present tense. To make it a future I'd probably stick the word 'eventually' or 'in Release 2.5' in there: "will eventually assume" or "In Release 2.5, Python will assume..." > > Specifically, what would the Python 2.2 interpreter > > have done if I handed it a program encoded in utf-8? > > Was that a legitimate encoding? > > Yes, the Python interpeter would have processed it. > > print "Gr?? Gott" > > would have send the greeting to the terminal. I see your point here. It does round trip successfully. John Roth > > Regards, > Martin From dave at boost-consulting.com Wed Aug 25 11:45:50 2004 From: dave at boost-consulting.com (David Abrahams) Date: Wed, 25 Aug 2004 11:45:50 -0400 Subject: Unpythonic Python References: <8a638f47.0408240034.653a92ff@posting.google.com> <8a638f47.0408240700.13c39f57@posting.google.com> Message-ID: Rob Williscroft writes: > David Abrahams wrote in news:uzn4j2s38.fsf at boost-consulting.com in > comp.lang.python: > >>> That's not the problem. I can download the file reliably from other >>> machines. > > At the same time, using http ? I can download the file reliably using IE from my WinXP box. I can download the file reliably using urllib from Cygwin Python 2.3.2 The 2nd element returned by urlretrieve is 'Date: Wed, 25 Aug 2004 14:50:17 GMT\r\nServer: Apache/2.0.40 (Red Hat Linux)\r\nLast-Modified: Wed, 25 Aug 20 2 GMT\r\nETag: "b63d5b-20ec84b-18057e80"\r\nAccept-Ranges: bytes\r\nContent-Length: 34523211\r\nContent-Type: n/x-bzip2\r\nConnection: close\r\n' >> Actually it appears that urllib is having some problem on Unix, at >> least the one from Python-2.2.x. This fails on Both FreeBSD and >> Linux: >> >> urllib.urlretrieve( >> 'http://cvs.sourceforge.net/cvstarballs/boost-cvsroot.tar.bz2', >> 'boost-cvsroot.tar.bz2') >> >> Trying again with Python 2.3 on Cygwin. As you can see from the above, it works. Is there a known urllib bug in earlier Pythons? > Is it possible the file is being (re) uploaded (via cvs) during your > cron job's download, thus truncating your download ? I don't think so. > Perhapse you should change to cvs: > > os.system( 'cvs ... ' ) The problem with that is that I want to capture the whole CVS history, not just today's state. > FWIW, I tried downlading with IE using the link above I got a > truncated 6 and bit MB's (16:15 BST (UTC +0100)). ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Sorry, what does that mean? Did it show that message in a dialog, or...? -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From anthonybaxter at gmail.com Mon Aug 23 11:40:29 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Tue, 24 Aug 2004 01:40:29 +1000 Subject: __name__ becoming read-write? In-Reply-To: References: Message-ID: On Mon, 23 Aug 2004 14:07:42 GMT, Arthur wrote: > > > Did I hallucinate something about __name__ becoming read-write? > Better get my facts straight first.... > > But if true that would seem to solve the main objection to: > the_horrible_name_I _need_to_call=transform(__f) > And would mean that a byproduct of the PEP318 implementation would go > 50% toward obviating the need for a PEP318 implementation. At least > by one measure. No, it is now read-write, thanks to mwh. I think, though, that you're misunderstanding the difference between setting a local variable in the function, called '__name__', and setting the actual __name__ of the function object. >>> def foo(): pass ... >>> foo.__name__ = 'bar' >>> foo.__name__ 'bar' >>> def foo(): ... __name__ = 'bar' ... >>> foo.__name__ 'foo' >>> foo.func_code.co_names ('__name__',) From abra9823 at mail.usyd.edu.au Mon Aug 16 11:46:13 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Tue, 17 Aug 2004 01:46:13 +1000 Subject: help - attributes namespace - is this a bug in PyXML Message-ID: <1092671173.4120d6c5e7cdb@www-mail.usyd.edu.au> hi! for the XML if i getupto the "ACCESS" element and print its attribute name and value using if attribs != None and len(attribs) > 0: index = 0 while index < attribs.length: print "attribute ", index, ": ", attribs.item(index).nodeName, " has value: ", attribs.item(index).nodeValue index += 1 it prints ACCESS having the attribute "appel:connective" with the value "non-and" the statement attribs.getNamedItem("appel:connective") however returns None. now i think its substituting the namespace for appel but then how would you access the attribute, just 'connective' doesn't work, 'appel:connective' doesn't either and http://www.w3.org/2001/02/appelv1:connective doesn't work either. thanks cheers ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From eurleif at ecritters.biz Mon Aug 16 19:12:35 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Mon, 16 Aug 2004 19:12:35 -0400 Subject: 'ascii' codec can't encode character u'\xf3' In-Reply-To: References: Message-ID: <2oct5pF88jocU1@uni-berlin.de> oziko wrote: > So I do not understan why the script uses an ascii codec, Am I not using > Unicode coding? The strings use Unicode, but they have to be encoded somehow to be outputted. The default encoding is ASCII, which doesn't support all of those fancy Unicode characters. Figure out what encoding your terminal is expecting (probably utf-8) and encode all strings in that when they're outputted or set a default encoding. From nzanella at cs.mun.ca Tue Aug 10 16:43:05 2004 From: nzanella at cs.mun.ca (Neil Zanella) Date: 10 Aug 2004 13:43:05 -0700 Subject: PyQt + PygreSQL Message-ID: Hello, I am using the following with python: The PyQt python bindings: http://www.riverbankcomputing.co.uk/pyqt/ based on the Qt GUI Application Framework: http://www.trolletch.com/ as well as the PyGreSQL python bindings: http://www.pygresql.org/ based on the PostgreSQL database server: http://www.postgresql.org/ I have the following question. When I instantiate QDataTable with C++ I must ensure that a database connection is open, and then have no problems, otherwise I will get popup widgets with errors. How can I properly set the default database connection and have QDataTable find it using the combination of Python + PyQt + PyGreSQL? Thanks, Neil From no-mail-please at nospam.com Sun Aug 29 20:16:36 2004 From: no-mail-please at nospam.com (Robert Oschler) Date: Sun, 29 Aug 2004 20:16:36 -0400 Subject: Top Zope sites? Message-ID: Hello, I've been perusing a book on Zope I have, and I'm still not quite "getting it". Can someone give me the URL's of 2 or 3 top-notch sites built upon Zope, so I can see what it's really all about? Is it a phpNuke type thing? How popular is it? Thanks. From ggg at zzz.it Wed Aug 25 15:10:51 2004 From: ggg at zzz.it (deelan) Date: Wed, 25 Aug 2004 21:10:51 +0200 Subject: Python Image Manipulation In-Reply-To: References: Message-ID: Scott Brady Drummonds wrote: > Can anyone recommend the easiest way of generating thumbnail images using a > Python library? I've seen that the Python Image Library (PIL) seems to do > this but it isn't installed on my available systems. I'd prefer to use > something distributed with Python, if possible, but will install the library > that makes this functionality easy as a second choice. i'm not aware of python built-in functions to resize images, but with PIL is dead easy to make thumbnails, check: from "Python is Kung-Fu for the Web": import Image im = Image.open(filename) im.thumbnail((200, 200), Image.ANTIALIAS) im.save(thumbnail, "JPEG", quality = 80, optimize = 1) you can also feed to open() a file(-like) object, instead of a filename. HTH, deelan. From ptmcg at austin.rr._bogus_.com Tue Aug 10 19:23:07 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Tue, 10 Aug 2004 23:23:07 GMT Subject: Python equivalent to a C trick References: <1d7b6d0d.0408092255.1177908e@posting.google.com> <4119327f$1@pfaff2.ethz.ch> Message-ID: "Josef Meile" wrote in message news:4119327f$1 at pfaff2.ethz.ch... > >>>Example: > >>>printf( "you have %i %s", num_eggs, num_eggs > 1 ? "eggs" : "egg" ); > >> > >>print "you have %i %s" % ( num_eggs, ("egg","eggs")[num_eggs>1] ) > > > > > > I would choose "!=" instead of ">" as the comparison operator. I think the > > accepted vernacular is: > > > > you have -2 eggs > > you have -1 eggs > > you have 0 eggs > > you have 1 egg > > you have 2 eggs > > you have 3 eggs > > you have 0.5 eggs > No offense intended, but the negative and float cases don't make any > sense for me on this context. You can't have -2 eggs or 0.5 eggs. The > last case won't occure as well because the output is being parsed to > int, so, you will get "you have 0 egg", which is again false. This error > happens with both solutions (with > and with !=). > > Regards, > Josef No offense taken! :) The OP was looking for a general solution to ? : , then gave us the "you have n egg(s)" example. In the general case, the number for comparison isn't always an integer quantity such as eggs. It could be "dollar(s)"/"euro(s)"/"Swiss franc(s)"/"yen" (hmm, I guess "yen" isn't a problem...), or "ton(s) of salami", or "pound(s) of cement", or "degree(s) Celsius", or... Anyway, even though eggs are usually counted from 1 to n in integer steps, other quantities can easily be negative and/or continuous. Still the singular - in English, anyway - is usually used *only* when the quantity is 1. Fractional and zero amounts, even though less than 1, still most naturally use the plural form. You have 0.5 dollars You have gained 1 pound You increased temperature by 0 degrees You have -2 dollars (that is, you owe 2 dollars) My point (which I guess didn't come across too well) was that this is a typical coding and testing error, in which only positive integer values > 0 are assumed, because we often mentally equate "plural" with "more than 1". But whether you are working in an integer, real, positive-only, or all numbers context, testing with n != 1 should determine whether singular noun should be used. -- Paul From meldron at meldron.org Tue Aug 31 13:13:19 2004 From: meldron at meldron.org (Bernd Kaiser) Date: Tue, 31 Aug 2004 19:13:19 +0200 Subject: GUI Designer In-Reply-To: References: Message-ID: <2pjpqmFkrkn0U1@uni-berlin.de> A.M wrote: > Hi, > > Do we have any OpenSource GUI designer for Python ? > > Thanks, > Alan > > If you want to use wxPython, check out Boa Constructor(open and os independent). http://boa-constructor.sourceforge.net/ Regards, meldron From __peter__ at web.de Fri Aug 13 09:28:01 2004 From: __peter__ at web.de (Peter Otten) Date: Fri, 13 Aug 2004 15:28:01 +0200 Subject: !wtf ellipsis References: Message-ID: Jonas K?lker wrote: > what (the hell) is Ellipsis? > what's it good for? > how do I use it; how does the interpreter use it? Alex Martelli gave me the following explanation a while ago: http://groups.google.com/groups?selm=yQRrb.2233%249_.98207%40news1.tin.it Peter From steven.bethard at gmail.com Tue Aug 31 16:02:24 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Tue, 31 Aug 2004 20:02:24 +0000 (UTC) Subject: -c input References: <367a4461.0408311151.59b61f54@posting.google.com> Message-ID: Mike Maxwell ldc.upenn.edu> writes: > python -c "print 'hi'; for i in [1,2]: print i" > > gives me an invalid syntax error, with the carat pointing to the end > of the word 'for'. Semicolons are only allowed with simple statements, not compound statements: http://docs.python.org/ref/compound.html Note that: stmt_list ::= simple_stmt (";" simple_stmt)* [";"] So that you can only join simple statements with ";" characters. If you want to insert newlines, in unix, you can do this like: > python -c "print 'hi'\ ? for i in [1,2]:\ ? print i" hi 1 2 Note that the '\' characters cause unix to include the newline in the string, instead of reading it as the command terminator. I don't know how to do this in Windows. Steve From gohaku at earthlink.net Thu Aug 19 18:54:09 2004 From: gohaku at earthlink.net (gohaku) Date: Thu, 19 Aug 2004 18:54:09 -0400 Subject: ANN: pyxe In-Reply-To: <41250363.6193453@news.t-online.de> References: <41250363.6193453@news.t-online.de> Message-ID: On Aug 19, 2004, at 3:50 PM, Gerson Kurz wrote: > pyxe is a small executable that will run python scripts on a machine > that doesn't have Python installed. Example: You have the following > hello.py: > .... > Easy, eh? Requirements > > - On the developer machine, you must have python23 installed. > - On the target machine, no requirements. > - Tested on Windows NT and Windows 2000. You are on your own with > other systems (such as XP, 03 etc.) > > pyxe is free for any purpose whatsoever. > I doubt there's a version for Linux or better yet Mac OS X, is there? From tim.peters at gmail.com Sun Aug 1 18:59:42 2004 From: tim.peters at gmail.com (Tim Peters) Date: Sun, 1 Aug 2004 18:59:42 -0400 Subject: transforming a list into a string In-Reply-To: References: Message-ID: <1f7befae04080115595e5c154f@mail.gmail.com> [Christopher T King] > ... > Curious, why isn't slicing of generators defined, using islice(), so "it1 > = iter(items)[0::2]" is valid? The real question then is why iterators don't, because a generator-function returns a generator-iterator, and the latter supplies only the methods in the general iterator protocol (next() and __iter__()). That protocol was deliberately minimal, to make it easy for all kinds of objects to play along. islice() was invented long after. Now that islice() exists, it may indeed make sense to use it to give a meaning to slice notation applied to iterators. But doing so requires that iterators implement the appropriate type slots to "look like" they're also "sequences" (that's how dispatching for slice notation works), and that's a lot more to ask of objects. If only some iterators implement it (like generator-iterators), then the general interchangeability of iterable objects we enjoy today would be damaged too. From abra9823 at mail.usyd.edu.au Mon Aug 16 12:41:41 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Tue, 17 Aug 2004 02:41:41 +1000 Subject: help - attributes namespace - is this a bug in PyXML In-Reply-To: <1092671173.4120d6c5e7cdb@www-mail.usyd.edu.au> References: <1092671173.4120d6c5e7cdb@www-mail.usyd.edu.au> Message-ID: <1092674501.4120e3c5c48cf@www-mail.usyd.edu.au> also getAttribute("appel:connective") returns " ", ie it is not None but when i print it out thats what i get funnily getAttribute("appel:connective") for an element thats doesn't have the attribute "appel:connective" still passes the test if element.getAttribute("appel:connective") != None so how can i retrieve an attribute of type "appel:connective", ie, prefixed by the uri appel Quoting Ajay : > hi! > > for the XML > xmlns:p3p="http://www.w3.org/2000/12/p3pv1"> > > > > > > > > > if i getupto the "ACCESS" element and print its attribute name and value > using > if attribs != None and len(attribs) > 0: > index = 0 > while index < attribs.length: > print "attribute ", index, ": ", attribs.item(index).nodeName, " > has > value: ", attribs.item(index).nodeValue > index += 1 > > it prints ACCESS having the attribute "appel:connective" with the value > "non-and" > the statement attribs.getNamedItem("appel:connective") however returns > None. > now i think its substituting the namespace for appel but then how would > you > access the attribute, just 'connective' doesn't work, 'appel:connective' > doesn't either and http://www.w3.org/2001/02/appelv1:connective doesn't > work either. > > thanks > > cheers > > > > > > > > > > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. > -- > http://mail.python.org/mailman/listinfo/python-list > ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From squirrel at WPI.EDU Fri Aug 6 12:58:19 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Fri, 6 Aug 2004 12:58:19 -0400 Subject: Prothon is switching to the .NET platform In-Reply-To: References: <000401c47b59$32539220$0d01a8c0@MarkVaio> Message-ID: On Thu, 5 Aug 2004, Guido van Rossum wrote: > So now I'm a bit disappointed to hear that you're giving all that up > and switching to the CLR. Ack! I was looking forward to playing with and hacking on Prothon in the future (I'm a big fan of prototypes), but .Net is a big turnoff (especially coming from the Linux side of things). Is this happening primarily to provide immediately access to large code libraries? From paulpaterson at users.sourceforge.net Fri Aug 20 22:24:58 2004 From: paulpaterson at users.sourceforge.net (Paul Paterson) Date: Sat, 21 Aug 2004 02:24:58 GMT Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: <_nyVc.5408$Jn5.3295@fe1.texas.rr.com> My vote: J2 J3 C1 Is J2EE an option ; From stefan at eischet.com Fri Aug 6 12:51:02 2004 From: stefan at eischet.com (Stefan Eischet) Date: Fri, 6 Aug 2004 18:51:02 +0200 Subject: tweaking @decorator syntax - yet another syntax In-Reply-To: <8umdnWTWJtQw6Y7cRVn-uw@powergate.ca> References: <1091715445.9931.17.camel@mango.cmc.ec.gc.ca> <8umdnWTWJtQw6Y7cRVn-uw@powergate.ca> Message-ID: On 06.08.2004, at 14:08, Peter Hansen wrote: > Stefan Eischet wrote: > >> I don't know if this particular syntax has been discussed >> already... please feel free to bash me if it was. ;-) > > Bash bash. Okay, I was asking for it. ;-) I didn't have the time to read the PEP this morning, but I now have and still like the idea. For my personal taste, it's way better than the ugly @ thing and a bit more explicit than the "[]"-syntax. >> How about using "is" after the def? > > Read the PEP. Basically the same as the "as" variant. Basically, yes. IMO there are a few important differences, though. From the PEP: |Several other syntaxes have been proposed: |def func(arg1, arg2, ...) as dec1, dec2, ...: | pass | |The absence of brackets makes it cumbersome to break long lists of |decorators across multiple lines, and the keyword "as" doesn't have |the same meaning as its use in the import statement. Plenty of |alternatives to "as" [12] have been proposed. :-) This one has optional brackets, so the breaking problems go away. ;-) Just like the "[]" thing, this one should look familiar to Python programmers. Lists, to me, imply that the object can be changed. But tuples are constant, right? Or is it intended to be able to change the decoration at runtime? I personally also dislike the "[]"-syntax because its placement looks quite random to me. "is" is used in another way than usual, though, but I think it's very close to the english meaning of "is". Also from the PEP: |without the intermediate assignment to the variable func. The |decorators are near the function declaration. The @ sign makes |it clear that something new is going on here. "Something new" is exactly what I, personally, wouldn't like to see in Python. How long is it supposed to look "new"? They didn't introduce a new look or funky symbols for new style classes, for example. When people have seen enough of @, will they have to introduce even "newer" symbols? ;-) But regardless of which syntax they choose, I guess I'll get used to it sooner or later. Cheers, Stefan From martin at v.loewis.de Fri Aug 6 15:22:44 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 06 Aug 2004 21:22:44 +0200 Subject: Unicode support In-Reply-To: References: Message-ID: <4113DA84.7070203@v.loewis.de> Richy2004 wrote: > NotImplementedError: .readline() is not implemented for UTF-16 As it says: this is, unfortunately, not implemented. Use readlines instead. > print (file.read()) [...] > UnicodeEncodeError: 'charmap' codec can't encode characters in position > 0-2: character maps to The the .read works perfectly. Don't try to print it, though! You can only print when the terminal actually supports the characters, which your terminal doesn't. Try print repr(file.read()) instead. > print tokens[0] [...] > UnicodeEncodeError: 'charmap' codec can't encode characters in position > 0-2: character maps to Same issue: As Vincent explains, you can't print ARABIC LETTER NOON to your terminal, as your terminal simply cannot display that character. Regards, Martin From news at woody.datatailors.com Wed Aug 11 09:36:37 2004 From: news at woody.datatailors.com (Peter van Kampen) Date: Wed, 11 Aug 2004 15:36:37 +0200 Subject: Apache web server and CGI References: <81a41dd.0408090447.7f27a092@posting.google.com> <10hf2ugjngver5e@corp.supernews.com> <81a41dd.0408092306.264beed@posting.google.com> <81a41dd.0408101143.43fea836@posting.google.com> Message-ID: In article <81a41dd.0408101143.43fea836 at posting.google.com>, Lad wrote: >> >> >> AllowOverride None >> Options ExecCGI >> Order allow,deny >> Allow from all >> > Thanks Peter for help. Now I can run cgi scripts in default > c:/program files/apache group/apache/cgi-bin/ > directory. > The problem was that there was not last "/" > > But how can I forced the Apache to allowed to run scripts in a > different directory for example C:\Test\MyScripts\ I would guess you have something like the above in your httpd.conf ScriptAlias /cgi-bin/ c:/program files/apache group/apache/cgi-bin/ AllowOverride None Options ExecCGI Order allow,deny Allow from all Simply replace c:/program files/apache group/apache/cgi-bin/ with C:\Test\MyScripts Hth, PterK -- Peter van Kampen pterk -- at -- datatailors.com From davebrok at soda.csua.berkeley.edu Fri Aug 20 02:48:32 2004 From: davebrok at soda.csua.berkeley.edu (David Pokorny) Date: Thu, 19 Aug 2004 23:48:32 -0700 Subject: Why is SETUP_FINALLY uninterruptable[sic]? References: <2JmdnSiV4NZzGL_cRVn-pg@lmi.net> Message-ID: Thanks! This has been very illuminating. David From nospam at nowhere.hu Sat Aug 21 07:16:35 2004 From: nospam at nowhere.hu (Miklós) Date: Sat, 21 Aug 2004 13:16:35 +0200 Subject: Semantic troubles with the word "free" [Was: My only complaint about Python] References: <87isbepaiy.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> <10icl8fn39skq3e@corp.supernews.com> Message-ID: "Jeff Shannon" wrote in message news:10icl8fn39skq3e at corp.supernews.com... > 510046470588-0001 at t-online.de wrote: > >flab ba writes: > > > >all humbug. Visual C++ is nowhere near free, it's all proprietary. > > That's free-as-in-beer, not Free-as-in-speech. > > It's a shame that, at least in English, the most natural word to use for > each of these two different concepts just happens to be the same word. > But such is the case. (I don't think it's practical to try to convince > everyone, worldwide, to refer to it as 'gratis' and 'liberte'...) And > given that it *is* the case, it would be much more pleasant if people > could use the word for both of its meanings without being criticized by > people who are philosophically devoted to only one of those meanings. It makes me smile that you keep getting into such semantic troubles unless you express yourself in such a roundabout way. I think it would be a really wise thing to always use the word 'gratis' for 'free-as-in-beer'. Btw, my native language (Hungarian) avoids another serious semantic booby-trap in English, with the ambigous word "love"... But at least in c.l.p. this rarely makes confusion. ;) Mikl?s > > Jeff Shannon > Technician/Programmer > Credit International > From sbabbitt at commspeed.net Tue Aug 10 22:58:01 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Tue, 10 Aug 2004 19:58:01 -0700 Subject: IDLE vs Command Line References: <8PidncxTb4muxITcRVn-oQ@adelphia.com> Message-ID: <1092193503.54033@news.commspeed.net> "Jesse B." wrote in message news:8PidncxTb4muxITcRVn-oQ at adelphia.com... > I like to work with xemacs, so I've been coding modules with xemacs and > running them using the dos prompt (using windows port of xemacs). Some > scripts that work fine with IDLE don't work at the dos prompt. For example: > > import random > > for i in range(10): > x = random.random() > print x > > This simple script doesn't work if I use the command prompt, with this > syntax: python random.py > > I am just wondering why that is. > It is running the copy of random.py from the python lib not your random.py Tom P.S. it is not trying to import itself! From grv575 at hotmail.com Mon Aug 23 23:29:49 2004 From: grv575 at hotmail.com (grv575) Date: 23 Aug 2004 20:29:49 -0700 Subject: profiler Message-ID: <144d0df.0408231929.496b2e7d@posting.google.com> I have some speed-critical loops involving numarray arrays and need to see which part is taking all the time. Is there a seperate profiling tool or how do you go about profiling everything (broken down by module/function) in an interpreted language like python? From M.Waack at gmx.de Wed Aug 25 14:55:31 2004 From: M.Waack at gmx.de (Mathias Waack) Date: Wed, 25 Aug 2004 20:55:31 +0200 Subject: Capturing exceptions? References: Message-ID: <4u3vv1-vkg.ln1@valpo.de> Dfenestr8 wrote: > On Wed, 25 Aug 2004 19:19:06 +0200, Mathias Waack wrote: > >> Dfenestr8 wrote: >>> What's the easiest way to capture the traceback from an >>> exception, and write it to a file? Ideally, I'd like to be able >>> to do something like: >>> >>>>try: >>>>main() >>>>except: >>>>write the traceback to a file >> >> Have a look at the traceback module. >> >> Mathias > > I did. Thanx. But I'm afraid I don't understand it. import traceback try: raise Exception, "python is so cool;)" except: traceback.print_exc(None,file("exc.trc","w")) Does it that what you want? Mathias From jeff at ccvcorp.com Fri Aug 20 16:45:55 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 20 Aug 2004 13:45:55 -0700 Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: <10icompmccbgn62@corp.supernews.com> Tim Hochberg wrote: > Reid Nichol wrote: > >> You're aware that a quantum leap means a extremely small leap, right? > > > While quanta are typically very-very-very small, last I checked the > key feature of quantum transitions is not that they're small, but that > there are no intermediate steps. The object is in state A then it's in > state B, but it's never halfway (or anywhere) between. Like most > quantum stuff it's better not to think about that too closely. And let's note, here, that "quantum" is not by any means restricted to the domain of quantum-mechanical physics. It's true that, within that domain, quanta are almost always a very small amount. But, as Tim says, the important feature of a quantum is that it's the smallest possible change of a given measurement, and implies a discrete (rather than continuum) underpinning to that measurement. It just so happens that the most well-known and talked-about quantum domains are related to subatomic physics, where the quanta involved are indeed very very small; but there's no /a priori/ restriction of quanta to apply only in that field. Jeff Shannon Technician/Programmer Credit International From mov_21h at yahoo.com Wed Aug 18 19:16:40 2004 From: mov_21h at yahoo.com (Bigbowser) Date: Wed, 18 Aug 2004 16:16:40 -0700 (PDT) Subject: age of Python programmers In-Reply-To: <4123DD7C.2050703@wickedgrey.com> Message-ID: <20040818231640.8880.qmail@web50008.mail.yahoo.com> 15 ^^ been programming in python for about 2 weeks now, but i have prgrammed before in C and asm [ 16 + 32 bit :) ] I decided to choose python as my scripting language because i asked a friend wether to go for python or ruby, he reccommended python due to its user base and mass of addons, widgets etc.. So far so good :P --- "Eli Stevens (WG.c)" wrote: > Lucas Raab wrote: > > > One thing I've always kind of wondered is what is > the average age of a > > Python programmer? > > 25 here, Python newbie (less than a year, I think). > > I'm sad that nobody else in this thread has spoken > in hushed, reverent > tones about my gateway drug, LogoWriter. I was 10 > when my fifth grade > math class went to the school computer lab and made > the turtle crawl > around the screen. From there, QBasic, C++, > C-because-school-made-me, > Java-because-work-made-me, Python-to-save-me. ;) > > Handy tip: if you were anything like me, _don't_ go > back and try to read > your old code. I had variable names like "qwer" > "qwert" and "qwerty", > alongside classics like "a", "b" and "c." > > *Shudder* > Eli > > > -- > http://mail.python.org/mailman/listinfo/python-list > __________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - Send 10MB messages! http://promotions.yahoo.com/new_mail From ben at benlast.com Wed Aug 25 04:49:44 2004 From: ben at benlast.com (Ben Last) Date: Wed, 25 Aug 2004 09:49:44 +0100 Subject: using pexpect to control python In-Reply-To: <412bc504$1@news.unimelb.edu.au> Message-ID: > From Maurice LING > Another thing which I'm thinking previously is how can I embed a python > interpreter (not compiler) that does line by line interpretation and > execution, in a python program? I realized that python's language > services has a compile package that can be invoked to compile python > source into python bytecodes but that's provided that the codes are in a > file. Perhaps what I'm interested may be how to embed and use the > interactive mode of python interpreter in a python program? Sounds to me like you're doing the sort of thing that a Python shell written in python already does. The codeop package provides a CommandCompiler() class that will compile lines of Python from strings at runtime. The exec statement then executes the bytecode objects. The code.InteractiveInterpreter class shows how this can be used to build an interpreter shell. Take a look at http://quasi-shell.sourceforge.net/ (source freely available, naturally!) for more examples. Most of the stuff you want is in the QuasiInterpreter class that inherits heavily from code.InteractiveInterpreter. Although you say "interpreter (not compiler)", the compile()/exec() combination will work with individual lines (or rather, blocks), so don't think of it as full source compilation. That's not Pythonic :) regards ben From p at trick.lu Wed Aug 18 11:58:24 2004 From: p at trick.lu (Patrick Useldinger) Date: Wed, 18 Aug 2004 17:58:24 +0200 Subject: Conoscere i processi presenti in windows In-Reply-To: <41230f6a.7833266@news.marelli.it> References: <41230f6a.7833266@news.marelli.it> Message-ID: <41237ca0$1@news.vo.lu> Alberto wrote: > ciao, > volevo chiedere se esistono API che permettono dal Python di: > - conoscere quali processi sono presenti in windows ad un certo > momento? > - terminare un processo ? > > grazie > Alberto see "The Python for Windows Extentions" on http://starship.python.net/crew/mhammond/ -- Linux user # 359658 From peter at engcorp.com Thu Aug 12 00:40:48 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 12 Aug 2004 00:40:48 -0400 Subject: The winner of the Python Decorator Poll is... In-Reply-To: References: Message-ID: <5LKdnbxzt-9NaYfcRVn-tg@powergate.ca> Peter Hansen wrote: > The poll results show that by a ratio of 6 to 1, people > who voted prefer either of the second two options to the > first one. Nothing more, nothing less. I should have said "prefer *one* of the second two options", but it's not really germane to my point... From wilberforce at gmail.com Sun Aug 29 09:22:41 2004 From: wilberforce at gmail.com (xtian) Date: 29 Aug 2004 06:22:41 -0700 Subject: Get all subdirs Message-ID: Florian Lindner wrote: > Hello, > how can I get all subdirectories of a given directory. os.listdir(dir) > doesn't differentiate between directories and files, os.walk seems to me a > bit overkill since it also descends in the subdirs. > Thx, > Florian Use os.path.isdir(): >>> from os.path import isdir, join >>> d = "c:/downloads/python" >>> subdirs = [sub for sub in os.listdir(d) if isdir(join(d, sub))] >>> print subdirs ['adodbapi-2.0.1', 'pyblosxom', 'pygame', 'quasi_08'] Cheers, xtian From peufeu at free.fr Thu Aug 5 11:47:59 2004 From: peufeu at free.fr (=?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?=) Date: Thu, 05 Aug 2004 17:47:59 +0200 Subject: checking whether a var is empty or not References: Message-ID: > No, in PHP, you can find out if a variable exists using isset(). And > trying > to dereference an uninitialized variable will generate a warning if you > have > error reporting turned up all the way (error_reporting(E_ALL)). > WRONG !!!!! Example in this stupid language : one : "; var_dump(isset( $a )); $a = 1; echo "

    two : "; var_dump(isset( $a )); $a = null; echo "

    three : "; var_dump(isset( $a )); ?> Output : one : bool(false) two : bool(true) three : bool(false) Get it ? From anthonybaxter at gmail.com Thu Aug 5 22:07:08 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 12:07:08 +1000 Subject: Confused about pep 318 In-Reply-To: <10h4vhcfbsv6t30@corp.supernews.com> References: <10h2ihgb8c6fi97@corp.supernews.com><10h4s026oapbhf1@corp.supernews.com> <10h4vhcfbsv6t30@corp.supernews.com> Message-ID: On Thu, 5 Aug 2004 13:36:23 -0500, Edward K. Ream wrote: > To repeat: given that pep 318 is grossly misleading, I contend that no > proper discussion of it has ever taken place. Sorry, but if you actively > mislead the public, then the public _does_ have a right to complain. The > web is a huge place. Expecting people to track it without proper notice of > what is being discussed is patently unfair. "Actively mislead the public"? What the hell is that supposed to mean? Look, you keep insinuating that there was some sort of evil plot to slip this into Python. I can assure you that this is NOT true, and I'm getting more than a little bit fed up with this argument. This feature was put into a2 because Guido's judgment was that it was appropriate to do so. The whole _point_ of an alpha cycle is that we can try things out, and we don't have to be backwards compatible if it turns out to have been a bad decision. As I've stated, _repeatedly_, yes, it would have been better had the PEP been kept up to date. This didn't happen, but people are working on this. From rnichol_rrc at yahoo.com Fri Aug 20 11:22:10 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Fri, 20 Aug 2004 10:22:10 -0500 Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: Gerrit Muller wrote: > Roel Schroeven wrote: > >> Roel Schroeven wrote: >> >>> I spotted some errors in your list, added new entries, and made a >>> histogram: http://roelschroeven.net/pythonages/ >> >> > Very cool. It might be good idea to add a date and time at the top, > since new datapoint keep coming in? How about labels for the axes as well. > and then a quantum leap towards Python. You're aware that a quantum leap means a extremely small leap, right? From fuzzyman at gmail.com Wed Aug 25 02:58:30 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 24 Aug 2004 23:58:30 -0700 Subject: Weave - inline C References: <6f402501.0408232319.5967f0d@posting.google.com> Message-ID: <6f402501.0408242258.3142080@posting.google.com> Robert Kern wrote in message news:... > Michael Foord wrote: > > Has anyone had success using weave with gcc for windows (standard > > windows distribution python)? > > > > I have my distutils setup to use gcc (via mingw32) - which it does > > fine. I've compiled and installed various modules with it. Weave > > itself installs fine, picking up the settings from distutils. > > > > However it has it's own version of distutils 'scipy_distutils' that it > > uses to compile the C it is given - which complains that it can't find > > msvcc.... The documentation included (which is actually for the 0.2 > > version) gives no hints and I wondered if anyone had any success in > > using it ? > > Use compiler='gcc' as a keyword argument for weave.inline(), etc. > > Yes, the documentation is fantastically out of date. > Thanks very much. I'll try that when I get home tonight. Much appreciated. Fuzzy http://www.voidspace.org.uk/atlantibots/pythonutils.html From aleaxit at yahoo.com Thu Aug 26 09:00:37 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 15:00:37 +0200 Subject: internal functions [Re: How do you feel ?] References: <4117862E.3000907@charter.net> <412cace1$1@nntp0.pdx.net> Message-ID: <1gj4s1c.13ty3kj1g8i5wxN%aleaxit@yahoo.com> Scott David Daniels wrote: > Howard Stearns wrote: ... > > Sorry. When I said "define a named function in a top-level assignment", > > I didn't just mean using a reference to a previously defined function > > (i.e., it's name), I meant actually defining the function in the > > assignment. If you (Howard) mean horrors such as foo = lambda x: x + 23 the Pythonic way is def foo(x): return x + 23 with absolutely identical results. > > In very complex cases, I lament the shear distance between the function > > definition and the one place in the code where it is referenced. (Again, What distance? Put the def right before that 'one place in the code', zero distance. > >>> assignments where I'd like create a function to use as the the value > >>> being assigned. I don't know how to define a named function in a You sure do appear to ignore the equivalence between 'foo = lambda ...' and def foo( ...'. What do you think def _does_...? > Maybe this is what you mean: > > def dodef(val): > global globfunc > def globfunc(other): > return val, other > > This works just fine. It works, sort of, but each call to dodef steps right over the previous value of global globfunc, and I think that may lead to nasty bugs. I much prefer the style: def dodef(val): def anyfunc(other): return val, other return anyfunc and if the caller wants to assign this function to name 'foofunc', it's the caller's job to say foofunc = dodef(23) I think this is much more transparent and thus less error-prone. Alex From Andreas.Ames at tenovis.com Fri Aug 6 09:29:12 2004 From: Andreas.Ames at tenovis.com (Ames Andreas (MPA/DF)) Date: Fri, 6 Aug 2004 15:29:12 +0200 Subject: q about cgi.FieldStorage (was: And now to sth. completely different: Forget about decorators, think cgi.FieldStorage) Message-ID: <788E231C269961418F38D3E360D1652526CA1D@tndefr-ws00021.tenovis.corp.lan> Hi, sorry for following-up to myself. Some remarks: 1) Please excuse the bogus original message. I wrote it a minute before I knocked off work and I promise to never do so again :-) 2) What I really wanted to know was: FieldStorage writes what it reads from the stream that is given to its constructor's fp (or sys.stdin by default) to a temporary file only _in some cases_. My question was or rather should have been, if it was possible in any case to get what FieldStorage has read from its input stream either as a string or as a file. 3) After staring at FieldStorage's source code for some time now I seem to be sure that this isn't possible because the input stream is read to a local variable in some cases, i. e. when the request is url-encoded. cheers, andreas From artur_spruce at yahoo.com Sat Aug 14 16:35:06 2004 From: artur_spruce at yahoo.com (AdSR) Date: 14 Aug 2004 13:35:06 -0700 Subject: !wtf ellipsis References: Message-ID: Christos "TZOTZIOY" Georgiou wrote in message news:... > On Fri, 13 Aug 2004 14:54:24 +0200, rumours say that Jonas K?lker > might have written: > > >what (the hell) is Ellipsis? > >what's it good for? > > Peter provided a link answering your questions. As a side note, I have > used Ellipsis instead of None as a very handy last item put in queues in > threaded programs (after all, "ellipsis" means "absence" or "lack" in > English :) Thus I avoid creating dummy classes to mark the end of > data... It's funny, I always understood ellipsis ('...') as a kind of a wildcard or abbreviation mark, rather than absence mark. For example, you'd write: a[1], a[2], ..., a[N] which means "all values from a[1] to a[N]" or something like that. But then of course it's just a symbol... AdSR From pm_mon at yahoo.com Sat Aug 21 14:46:29 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sat, 21 Aug 2004 14:46:29 -0400 Subject: __metaclass__ and __author__ are already decorators In-Reply-To: <2opgsoFd7807U1@uni-berlin.de> References: <2opgsoFd7807U1@uni-berlin.de> Message-ID: Leif K-Brooks wrote: > Paul Morrow wrote: > >> Thinking about decorators, and looking at what we are already doing in >> our Python code, it seems that __metaclass__, __author__, __version__, >> etc. are all examples of decorators. So we already have a decorator >> syntax. What is the compelling reason to invent a new one? And if we >> do, what's to become of the old one? >> > > > I've thought about something along the lines of your suggestion before, > but it doesn't seem very Pythonic to assign special meaning to function > variables with special names to me. It's essentially a new syntax, but > disguised as an old syntax with an entirely different meaning. We just need to stop thinking of them as local function variables. Instead we should think of __xxx__ attributes as describing the function itself (i.e. as a decorator would), as I believe that is almost always the author's intention when he/she uses such names inside of a function/method definition. He wants to say something about the function (who wrote it, it's version, etc.), and is probably sad that it has the side-effect of creating a local variable. So it probably shouldn't have that side-effect anymore. It should create a function attribute instead (not to be confused with a local variable). For classes, it's much easier to accept this new way of looking at __xxx__ attributes because it's consistent with our intention behind them (as names for metadata rather than normal, inheritable class attributes). From __peter__ at web.de Sat Aug 21 06:40:27 2004 From: __peter__ at web.de (Peter Otten) Date: Sat, 21 Aug 2004 12:40:27 +0200 Subject: age of Python programmers References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: Reid Nichol wrote: >> and then a quantum leap towards Python. > You're aware that a quantum leap means a extremely small leap, right? (from a random walk through the internet) size [m] jumps [m] ratio man 2 8 4(*) grasshopper 2e-2 4e-1(*) 20 electron 2*3e-15 5e-11 (Bohr radius) 8000(*) (*) my calculation That's one small step for electricity, one giant leap for an electron... Based on the above evidence a 10m Python should jump 80 kilometers (50 miles), so beware... Peter From alikakakhel3 at hotmail.com Fri Aug 20 21:18:53 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 20 Aug 2004 18:18:53 -0700 Subject: I would really like the code for a dome in vpython References: <8f17f4bc.0408181349.46c34b2@posting.google.com> Message-ID: <8f17f4bc.0408201718.139fcfd8@posting.google.com> > I might have some other suggestions if a understood what you were > trying to accomplish, and why. I am just trying to make a dome in vpython. I am trying to render images of mosques that I am making. From grv575 at hotmail.com Tue Aug 24 21:54:24 2004 From: grv575 at hotmail.com (grv575) Date: 24 Aug 2004 18:54:24 -0700 Subject: Python and C, looking for a C IDE References: <6f402501.0408240353.2a5b8a84@posting.google.com> Message-ID: <144d0df.0408241754.6bac1a44@posting.google.com> C IDE? DevC++ is sweet. It's on sourceforge. Python IDEs -- winpython on windows, eric3 on linux is great. Also compile wxPython to get pyCrust (windows or linux). Really good code completion/call tips. From chris.cavalaria at free.fr Tue Aug 24 18:57:41 2004 From: chris.cavalaria at free.fr (Christophe Cavalaria) Date: Wed, 25 Aug 2004 00:57:41 +0200 Subject: PEP318: radical notion References: <412a4222$0$293$626a14ce@news.free.fr> Message-ID: <412bc7e6$0$4065$626a14ce@news.free.fr> Arien Malec wrote: > Christophe Cavalaria wrote in message > news:<412a4222$0$293$626a14ce at news.free.fr>... >> Arien Malec wrote: > >> > 1) Make PEP318 *only* implement problem (1). That is, create sematics >> > for defining and retrieving function/method/class metadata >> > 2) Create a new default metaclass that uses metadata for class/static >> > method definitions to perform the necessary class/staticmethod >> > transformations. Perhaps use this metaclass as default in 2.4 only via >> > a "from __future__ import foo". >> > 3) Leave any arbitrary transformations to be implemented via custom >> > metaclasses -- these metaclasses will have access to the custom >> > metadata to trigger method def transformations. > >> Unfortunately for you, you can use decorators on normal functions and not >> only on member functions. It rules out any metaclass based >> implementation. > > Is there a valid use case that supports arbitrary magical non-metadata > transformations of standalone functions? > > Arien memoize for example. No metadata, only transformation, doesn't really apply to a member function in fact ( although it might be possible ? Why is it that there are always some people who doesn't understand all the possibilities of decorators and so want to minimise their usefulness ? From me at privacy.net Sun Aug 8 14:19:30 2004 From: me at privacy.net (Dan Sommers) Date: 08 Aug 2004 14:19:30 -0400 Subject: Encryption between Python & PHP References: Message-ID: On Sun, 8 Aug 2004 16:37:33 +0100, Geoff Caplan wrote: > Dan, Not just me, thank goodness. The entire Python community. ;-) DS> I can't help much with your other questions, but I do know about this DS> one. By definition, blowfish is blowfish is blowfish. Any (properly DS> implemented) blowfish library will be compatible with another; if you DS> encode something with one library, you will be able to decode it with DS> the other. > Thanks for that. Looks like I should persist and track down the > problem. Perhaps something to do with the keys? When I try to > decrypt I am getting binary garbage out instead of an ascii string. > Any pointers about where to start looking would be welcome! I guess the usual pointers apply: Create the absolute smallest program that fails. Ask the vendors/authors of the library and/or programming language you're using. Post/Email the code, the input, the actual output, what you expected to be the output, and why you expected that output. I'm pretty sure that counterpane (blowfish' creator, IIRC) has test vectors, too. If you can encrypt *or* decrypt them, but not both, that points at one part of your application or another as well. Regards, Dan -- Dan Sommers Never play leapfrog with a unicorn. From bulatov at engr.orst.edu Mon Aug 2 19:51:46 2004 From: bulatov at engr.orst.edu (Yaroslav Bulatov) Date: 2 Aug 2004 16:51:46 -0700 Subject: Microbenchmark: Summing over array of doubles References: <4d642979.0407312049.7a8aecab@posting.google.com> Message-ID: <4d642979.0408021551.586e1d1f@posting.google.com> Christopher T King wrote in message news:... > On 31 Jul 2004, Yaroslav Bulatov wrote: > > > I'm doing intensive computation on arrays in Python, so if you have > > suggestions on Python/C solutions that could push the envelope, please > > let me know. > > If you're doing mostly vector calculations as opposed to summing, I've > been doing some work on adding SIMD support to numarray, with pleasing > results (around 2x speedups). I've also done some work adding local > parallel processing support to numarray, with not-so-pleasing results > (mostly due to Python overhead). > > Regarding your results: > > numarray should be just as fast as the -O2 C version. I was puzzled at > first as to where the speed discrepancy came from, but the culprit is in > the -O2 flag: gcc -O2 noticies that sum is never used, and thus removes > the loop entirely. As a matter of fact, there isn't even any fadd > instruction in the assembler output: > > call clock > movl %eax, %esi > movl $9999999, %ebx > .L11: > decl %ebx > jns .L11 > subl $16, %esp > call clock > > As you can see, the 21ms you're seeing is the time spent counting down > from 9,999,999 to 0. To obtain correct results, add a line such as > 'printf("%f\n",sum);' after the main loop in the C version. This will > force gcc to leave the actual calculation in place and give you accurate > results. > > The above fix will likely render numarray faster than the C version. > Using gcc -O3 rather than gcc -O2 will get fairer results, as this is what > numarray uses. You are right, how silly of me! Fixing the script now results in 130 millis mean, 8.42 millis standard deviation, which is slower than numarray (104, 2.6 respectively). I wonder why numarray gives faster results on such a simple task? > Is there any reason why in the Python/numarray version, you use > Numeric's RandomArray rather than numarray.random_array? It shouldn't > affect your results, but it would speed up initialization time a bit. There isn't a good reason, I simply didn't know about numarray.random_array > > There are a few inefficiences in the pytime module (mostly involving > range() and *args/**kwargs), but I don't think they'll have too big of an > impact on your results. Instead, I'd suggest running the numarray/Numeric > tests using Psyco to remove much of the Python overhead. > > For completeness, I'd also suggest both running the Java version using a > JIT compiler such as Kaffe, and compiling it natively using gcj (the > latter should approach the speed of C). From dperl at rogers.com Fri Aug 27 13:06:06 2004 From: dperl at rogers.com (Dan Perl) Date: Fri, 27 Aug 2004 17:06:06 GMT Subject: would be nice: import from archive Message-ID: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> Here is a python feature that I would like: to be able to import modules from an archive like the jar files in Java. Maybe a regular tar file? Maybe a python specific file type, let's call it a 'par' file? It would be useful in packaging an python library. Sure, there's always the python packages, but a single file instead of a whole directory tree would be more convenient. I am particularly interested because I am working on a framework/toolkit and I am using a configuration divided into several modules. It would be nice to be able to save configurations (combinations of several modules) into single archive files and then switch between configurations by pointing to one such archive file. I am quite new to python so I should ask first whether there is already something like that, although I did a search already. Or maybe such a feature has already been discussed somewhere? If this is an original idea, how can I propose it for future releases? Dan Perl (yes, I'm Mr. Perl, but I'm using Python, after all Perl is not my middle name, it's my last name) From squirrel at WPI.EDU Wed Aug 18 10:08:41 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Wed, 18 Aug 2004 10:08:41 -0400 Subject: Help passing variables. In-Reply-To: <8ff6f02e.0408180321.27b4cc39@posting.google.com> References: <8ff6f02e.0408180321.27b4cc39@posting.google.com> Message-ID: On 18 Aug 2004, aToaster wrote: > I started off by trying to make a simple calculator program and I > need to pass the calcTotal variable in and out of the ButtonHandler > function, how do I do this? The quick answer is that in buttonHandler_a(), you have to decalre calcTotal global; otherwise it will assume it's a local value: def buttonHandler_a(self, argument1, argument2): global calcTotal print "You have clicked :", argument2 calcTotal = calcTotal +argument1 print calcTotal The long answer is that anytime you think you need a global variable, you probably don't. The better way to go about this is to have calcTotal be a property of CalcApp ("self.calcTotal = 0" in CalcApp.__init__()). This way, CalcApp will be re-entrant, in the case that you ever need to instantiate more than one of CalcApp (something you probably wouldn't do with an application like that, but a good practice nonetheless). From ptmcg at austin.rr._bogus_.com Fri Aug 27 15:12:31 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 27 Aug 2004 19:12:31 GMT Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> <87hdqok9i6.fsf@sinken.local.csis.hku.hk> <1rfz68ely9.fsf@rovereto.ifi.uio.no> <876574k7du.fsf@sinken.local.csis.hku.hk> <1r3c28ejis.fsf@rovereto.ifi.uio.no> Message-ID: "Kjetil Torgrim Homme" wrote in message news:1r3c28ejis.fsf at rovereto.ifi.uio.no... > [Isaac To]: > > > > When Python is concerned and Emacs is not, Python only sees there > > is indentation, and only indentation, to define the suites. And > > it is also what people will perceive when they stare at the code. > > There is nothing to be inconsistent with it. > > how long do you have to stare before spotting the bug? > > db.update_name(person) > if is_student(person): > db.update_courses(person) > db.commit() > > only students have their names updated. I wonder why. > > real world examples have taken hours or days. > -- > Kjetil T. Here's a real-world C example, took us several weeks to track down - all the programmer did was add some debugging code: db->startTransaction(); db->update_name(person); if ( is_student(person) ) log("update student %s", person->name ); db->update_courses(person); -------------------------------------------page break----------------------------- db->commit(); Everybody has their courses updated whether students or not - why??? On the hardcopy, the update_courses() call was the last line on the page, which made it that much harder to spot. In fact, you can cite examples on this argument in either direction; it is more than a little condescending to preach that "in the real world, my way is the right way." As far as Python goes, I think bracelessness is one of its defining features; if some day braces were to get included in Python a la C or Java, then it will cease to be Python. -- Paul From reinhold-birkenfeld-nospam at wolke7.net Tue Aug 10 16:55:19 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Tue, 10 Aug 2004 22:55:19 +0200 Subject: Decorator "platform" In-Reply-To: References: <2nsoofF49frcU1@uni-berlin.de> Message-ID: <2nsqiaF4h52jU1@uni-berlin.de> Doug Holton wrote: > Reinhold Birkenfeld wrote: >> it would be a big advantage to >> everyone following to have the different uses of decorators collected, >> to serve as a starting point or a repository of what's possible. >> >> What I have in mind is a sort of "decorator library" where everyone who >> has written a useful function of that kind can share it with others, >> instead of only posting it here. As I don't know whether there will be a >> "decorators" module in the stdlib, this would serve as a replacement >> until decorators are a final language feature. >> >> How would one realise such a project? > > Maybe you could create a PythonDecoratorLibrary page at the Python wiki: > http://www.python.org/moin/PythonDecoratorLibrary [x] done. Thanks for the good idea! I hope you use this wikipage to publish your decorator solutions! Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From eurleif at ecritters.biz Sat Aug 21 16:24:59 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sat, 21 Aug 2004 16:24:59 -0400 Subject: __metaclass__ and __author__ are already decorators In-Reply-To: References: <2opgsoFd7807U1@uni-berlin.de> Message-ID: <2opp6gFdg3e7U1@uni-berlin.de> Paul Morrow wrote: > We just need to stop thinking of them as local function variables. > Instead we should think of __xxx__ attributes as describing the function > itself (i.e. as a decorator would), as I believe that is almost always > the author's intention when he/she uses such names inside of a > function/method definition. He wants to say something about the > function (who wrote it, it's version, etc.), and is probably sad that it > has the side-effect of creating a local variable. So it probably > shouldn't have that side-effect anymore. It should create a function > attribute instead (not to be confused with a local variable). Which is, like I said, assigning new meaning to an old syntax. That seems confusing to me; why not just create a new syntax? From ptmcg at austin.rr._bogus_.com Tue Aug 24 18:32:10 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Tue, 24 Aug 2004 22:32:10 GMT Subject: python-dev Summary for 2004-08-01 through 2004-08-15 References: Message-ID: "Brett Cannon" wrote in message news:mailman.2274.1093330945.5135.python-list at python.org... > python-dev Summary for 2004-08-01 through 2004-08-15 > ++++++++++++++++++++++++++++++++++++++++++++++++++++ > This is a summary of traffic on the `python-dev mailing list`_ from > August 01, 2004 through August 15, 2004. It is intended to inform the > wider Python community of on-going developments on the list. To comment > on anything mentioned here, just post to `comp.lang.python`_ (or email > python-list at python.org which is a gateway to the newsgroup) with a > subject line mentioning what you are discussing. < my emphasis> > All python-dev members > are interested in seeing ideas discussed by the community, so don't > hesitate to take a stance on something. > OK, tirade time. If you don't want to listen to me get up on my > soapbox, then just skip the rest of this... > > "In the old days, Guido would Pronounce, and we'd all bite our tongues > (although not necessarily each his own). The less time Guido can make > for Python, the more important becomes graceful capitulation." Tim said > this and it makes me wish for the old days. People had *months* to > comment on decorators and no one spoke up until something went into the > language. Procrastination is not a virtue when it comes to major > language evolution discussions. What was worse was when the emails > started repeating themselves (which was pretty much from the get-go when > this exploded). Seemed like people decided to start talking without > doing some research. Granted the PEP was outdated and the wiki page was > not up yet, but this stuff was covered in the Summaries before and you > could have just Googled for the previous threads. > > Personally, if I was Guido, I would have said that the community had > their chance to speak up and they just didn't take it. But Guido is a > nicer guy than that so people are getting a second chance with this. > Personally this came off a great case of the tyranny of the majority in > my eyes. There is a reason why Python is a dictatorship. > "Well, then allow me to retort." Up until PyCon in June, Guido was publicly leaning toward a C1-flavor of decorator syntax. Apparently, there was sufficient furor by some audience members (not to quibble whether or not this group was in fact representative of all Python users) that Guido dropped back from it. Sometime in June, @decorator seemed to drop from the sky - it was not even one of the top 2 that GvR had in his keynote presentation - and by late July, it was suddenly to be found in the newly released 2.4a2. I guess my sin of omission was in not following python-dev directly, but instead relying on the natural checks and balances that have produced the beautiful Python language thus far. Despite the periodic reporting of python-dev summaries (thank you! BTW), and the April and June summaries of the decorator status, *not one* of these summaries announced the selection of "@decorator" before it was checked in and released - making it a seeming fait accompli. Contrast with the announcement of 'Generator expressions are in!' in your May summary, well in advance of the 2.4a release. > At this point people should be hashing out which syntax alternative they > want to present to Guido on comp.lang.python_. No more talking on > python-dev, no more syntax proposals. The community should set a goal > date (Sept. 1 seems good) and just choose a bloody alternative. Then > when Guido makes his choice people accept it or just go to another > language. No one had better voice their disappoint once Guido chooses > his syntax or I will personally come beat you over with a stick for > being a whiner. > Um, where have you been? It seemed to me that, instead of continued wallowing in a chaos of syntax discussions, that we collectively *were* working on "just choosing a bloody alternative." I guess we've not been wholly successful, as there are still *two* popular contenders, but one is leading the other by more than 2-to-1, and a consensus measure shows an even greater level of, if not acceptance, at least tolerance. c.l.py is a tough herd of cats! Michael Sparks and Robert Brewer have voted in a measure beyond simply posting Usenet votes, and have completed the steps for one of the contenders to be considered by Guido. The absence of champions for the other option may end up making the decision by default - too bad, actually. > OK, that's out of my system. I feel better now. > Well, good for you. I also subscribe to a "no whining" philosophy, but I don't think it is unexpected nor unreasonable that the rapid selection, implementation, and release of "@decorator" took many by (unpleasant) surprise. And am I the only one who has trouble reconciling your tirade with your encouragement to "take a stance" (in the emphasized section at top)? We can agree to disagree - I'll plead guilty to being a miserable lurker who up until recently was happy to rely on the wisdom of strangers - but allow me to take at least a little umbrage at your tirade. -- Paul From michele.simionato at gmail.com Thu Aug 5 10:43:23 2004 From: michele.simionato at gmail.com (Michele Simionato) Date: 5 Aug 2004 07:43:23 -0700 Subject: Is this a case for metaclasses? References: <411207dd$0$7323$9b4e6d93@newsread2.arcor-online.net> Message-ID: <4edc17eb.0408050643.41f9040a@posting.google.com> Hartmut Goebel wrote in message news:<411207dd$0$7323$9b4e6d93 at newsread2.arcor-online.net>... > Hi, > > I'm currently implementing a tool for auto-generating webforms from a > desription file. The output should become a php-script, an asp-script, > zope-formulator or such. Each if it may (or may not) have javascript > additions. The output format should be defined ar runtime (php, > php+javascrip, asp, asp+javascript, etc.). > > Currently I have a fixed class hierarchy: > > generic : implements generic html widgets (input, radiobuttons) > php : "mixin" for adding php-specifi code to the widget, > eg. getting values from HTTP_POST_VARS/_POST > javascript : adds javascript scripts, eg. error checking > > Obviously this does not scale as soon as I add more mid-layers (asp, > psp, etc.). > > For me this sounds like I could benefit from using metaclasses here. > Before I start implementing such a beast, I want to be shure, there will > be a benefit. > > Any suggestions? Metaclasses are essentially syntactic sugar. You can do more or less everything without them. For instance you can use a poor man function to format your classes as you wish. Then, you have to apply the function to the every subclass by hand. If you use a metaclass, subclasses are automatically reformatted, instead. So, using a function means a bit more typing but greater expliciteness. Metaclasses are okay if you want to hide to your users the fact that something magic is going on. Michele Simionato From tor.iver.wilhelmsen at broadpark.no Wed Aug 4 04:00:22 2004 From: tor.iver.wilhelmsen at broadpark.no (Tor Iver Wilhelmsen) Date: 04 Aug 2004 10:00:22 +0200 Subject: Can somebody help me ? References: <9f6a3388.0408031923.11cfa62d@posting.google.com> Message-ID: patrick.schaeffler at siemens.com (Patrick) writes: > import win32com.client.dynamic > db1 = win32com.client.dynamic.Dispatch("Access.Application") As an aside: This looks like a good candidate for import aliasing import win32com.client.dynamic as com db1 = com.Dispatch("Access.Application") Unless you like to type a lot. :) From peter at engcorp.com Mon Aug 16 14:24:02 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 14:24:02 -0400 Subject: Newbie question about file input In-Reply-To: References: Message-ID: Ben Last wrote: >>Peter Hansen wrote: >>>Small note: it would make your code more readable and thus >>>easier to comment on if you followed convention and used four >>>spaces for indentation. Your volunteer tutors thank you! :-) > > Ah, now you're treading on holy war territory :) > ben "Two Spaces McGraw" last Perhaps, but it's inarguable that in the Python world, four spaces is overwhelmingly the most widely followed convention, not to mention the standard followed by the core library. -Peter From tim.peters at gmail.com Tue Aug 17 12:34:55 2004 From: tim.peters at gmail.com (Tim Peters) Date: Tue, 17 Aug 2004 12:34:55 -0400 Subject: Generators versus Coroutines In-Reply-To: References: <7x7js1i887.fsf@ruckus.brouhaha.com> <972ec5bd.0408152037.c50bcee@posting.google.com> Message-ID: <1f7befae040817093447023a6b@mail.gmail.com> [Lenard Lindstrom] > I do not consider using threads to implement coroutines a practical > solution. It depends on the app, but in general I agree. > It was alluded to in a posting by Tim Peters giving his take on generators, > coroutines and continuations. The case he mentioned was more than > likely a demonstration or example than an actual production module. Demo/threads/ in a Python source distribution contains thread-based implementations of coroutines and generators. They were certainly just demos, and PEP 255 even mentions the latter as a concrete example of why threads aren't a practical implementation technique for generators. From adurdin at gmail.com Sat Aug 21 09:46:56 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Sat, 21 Aug 2004 23:46:56 +1000 Subject: just ignore Guido's "rejections" [Re: Alternative decorator syntax decision] In-Reply-To: References: <2uadnbqpMuI1krvcRVn-sg@comcast.com> Message-ID: <59e9fd3a040821064633ab4894@mail.gmail.com> On Sat, 21 Aug 2004 19:04:28 +1000, Anthony Baxter wrote: > > You're misinterpreting what I said - I said that "if you want a form > he's rejected, > you need _damn_ strong arguments to back it up". I was replying to someone > saying that it's not necessary to pay attention to Guido's rejections of various > forms, and pointing out that in fact you _do_ need to pay attention to them. If > there's a community concensus for an already-rejected form, but no-one has > bothered addressing the existing concerns, then it's something of a waste of > time. I'm not trying to inflame this discussion, but that doesn't appear to tally with Guido's comments -- when discussing a community consensus regarding list-after-def, he asked if there was a consensus that his concerns with that syntax were incorrect, which suggests that he'd reconsider his concerns (though that may not change them). Additionally, two people (myself one) addressed his concerns point-by-point on python-dev, and Guido didn't respond, except to say that he doesn't want a hundred people arguing point-by point. >From all this and his other comments, I gather that Guido wants a community consensus on one syntax (with an implementation); he'll look at it (even if he previously rejected it), and the current @-decorators, and make a final decision on which will be kept From jess.austin at gmail.com Tue Aug 24 15:45:06 2004 From: jess.austin at gmail.com (Jess Austin) Date: 24 Aug 2004 12:45:06 -0700 Subject: Alternative decorator syntax decision References: Message-ID: hi, I vote: J2, J2, J2 and thus the split-vote mechanism is completely defeated. I don't think you can enforce 2nd-choice voting on a newsgroup. I find suite expansion to be far more pythonic than anything else we've come up with. Just to be clear, the following is J2: Nicolas Fleury wrote in message news:... > Proposal 1: > > decorate: staticmethod > def foo(a, b): > ... > > decorate: > accepts(int,int) > returns(float) > def bar(low, high): > ... > > other possible keywords: predef, from, as, with while this is E4, which I think has some traits that Guido has already vetoed in http://mail.python.org/pipermail/python-dev/2004-August/047279.html: > Proposal 2: > > def foo(a,b): > using staticmethod > ... > > def bar(low, high): > using accepts(int, int) > using returns(float) > > other possible keywords: decorate, transform, with, postdef, as [snip] > What keywords would you prefer? Do you see any that I have not listed? I like "decorate" much better than "transform", because "transform" encompasses more than the specific concept of decoration. If there is a concern that decoration is a larger concept than what is proposed in PEP 318, then I would consider some other, more specific verb. Verb it must be, though, as opposed to something adverbial or prepositional or even gerundy. It seems to have been made quite clear that decoration is a separate action from definition. If we use a word that isn't another transitive verb, that word will attach itself to "def" and the syntax will obscur the semantics. > Do you think there's an alternative that I should have listed, even > considering what have been ruled out by Guido? Solutions that are already or obviously will be rejected by Guido contribute to noise levels. b-) From ville at spammers.com Fri Aug 20 11:22:04 2004 From: ville at spammers.com (Ville Vainio) Date: 20 Aug 2004 18:22:04 +0300 Subject: voting method flawed? [Re: Alternative decorator syntax decision] References: Message-ID: >>>>> "Doug" == Doug Holton writes: Doug> I've heard of different voting methods like ranking your top Doug> choices, but I've never heard of this one. It appears that Doug> if someone is open minded about more than one option, their Doug> opinion counts *less* that someone who is doggedly Doug> determined about one particular syntax. They get three Doug> votes while you get one. That doesn't seem fair or the best Doug> way to determine a community favorite. I think it's less about finding a community favourite than just picking out one or two alternative approaches for Guido's consideration. The idea is to reduce the number of syntaxes to shoot down :-). -- Ville Vainio http://tinyurl.com/2prnb From newsgroups at jhrothjr.com Tue Aug 17 12:19:50 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Tue, 17 Aug 2004 12:19:50 -0400 Subject: Problem with floating point precision References: Message-ID: <10i4c1lrvd3rm9b@news.supernews.com> "j_mckitrick" wrote in message news:ec6dce8b.0408170538.1f0211d2 at posting.google.com... > I checked the docs, but found nothing about floating point issues. > > I am working on an app that deals with currency values, and only does > addition and subtraction (no division). But I am starting to see > values that should be the same failing a compare! What is the > workaround or correct way to compare 2 floats? It worked fine for > months, then suddenly starting acting odd. I might have upgraded > Python somewhere in between, I can't recall. The basic issue here is that you shouldn't be using floats for currency. Granted, lots of people do, but it will eventually run into exactly the problem you're describing. The reason is that currency is best handled by some form of arithmetic that works with discrete quantities, while floats are intended to be used with continuous quantities (like scientific and engineering measurements). There's a floating decimal package in 2.4 that is intended to eventually (in 2.5 maybe?) be the base of a currency package. However, that doesn't help today. What I'd do is create a currency class that uses plain old, boring ints as the base, with the necessary decimal point handling present behind the scene. John Roth > > jonathon From cookedm+news at physics.mcmaster.ca Sat Aug 14 16:38:33 2004 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Sat, 14 Aug 2004 16:38:33 -0400 Subject: Sublassing in C References: <11wahcesttqxl.dlg@news.kaarsemaker.net> Message-ID: At some point, Dennis Kaarsemaker wrote: > I'm trying to create a subclass of Exception in C, but cant figure out > what to use as tp_base in the PyTypeObject struct. Can anybody give me > directions on where to look or maybe even an answer? Have a look at Python/exceptions.c in the Python source; that's where all the subclasses of Exception (IndexError, etc.) are created. -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From peter at engcorp.com Mon Aug 16 17:33:59 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 17:33:59 -0400 Subject: Stopping a socket.accept() method In-Reply-To: <2ocfkjF8v1qeU1@uni-berlin.de> References: <2o9mlbF8ff8rU1@uni-berlin.de> <2ocfkjF8v1qeU1@uni-berlin.de> Message-ID: Tobias Pfeiffer wrote: > On 16 Aug 2004, Peter Hansen wrote: >>Tobias Pfeiffer wrote: >> >>2. You can use a non-blocking socket and select(), which >>will allow a periodic wakeup to check a flag that is set >>by whatever mechanism you want to tell the prog to stop. > > And how exactly do you propose to code this "non-blocking socket"? I've > no idea how to realize that? Could you maybe give me a little example of > how to work with socket.accept() and select()? Sure, but did you look for yourself? I'm pretty sure Google would turn up some good stuff for you if you tried with "Python non-blocking socket accept select" or some subset of that. If you look but can't find I'd be happy to help point you even more specifically in the right direction. (I suspect checking the documentation for the "select" module would help too.) -Peter From yaipa at yahoo.com Mon Aug 30 22:24:33 2004 From: yaipa at yahoo.com (yaipa h.) Date: 30 Aug 2004 19:24:33 -0700 Subject: [IronPython] Jim Hugunin's web log. References: <10j7bfr6o0nf7af@corp.supernews.com> Message-ID: <6e07b825.0408301824.60c3426b@posting.google.com> flacco wrote in message news:<10j7bfr6o0nf7af at corp.supernews.com>... > David Wilson wrote: > > Anti-trust conspiracy theories aside, if Microsoft adopts Python as a > > part of it's development toolset, the repercussions for Windows RAD and > > scripting are massive, not to mention the effects it would have on the > > average Python developer's wages and availability of work. > > why in the world would we want to put aside the concerns about microsoft > that we have, which you have "misnomered" under the umbrella term > "anti-trust conspiracy theories"? > > > > This is perhaps the first time where I have been glad to see Microsoft > > hijack something. Even if IronPython becomes a commercial offering, I'm > > still sold. > [...] > > My apologies for the poor terminology, this really isn't my department. > > Just got a feeling. :) > > are you in advertising by any chance? Hey, if Python can reuse the .net GUI builder... Cool. Give something, get something back. So it goes... Cheers, --Al From rschroev_nospam_ml at fastmail.fm Thu Aug 26 12:04:11 2004 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Thu, 26 Aug 2004 16:04:11 GMT Subject: Why return None? In-Reply-To: References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> <1gj4fb5.607xsc51izh8N%aleaxit@yahoo.com> <7xllg25lkt.fsf@ruckus.brouhaha.com> <1gj4u3a.12ttba9fynd6uN%aleaxit@yahoo.com> Message-ID: <%RnXc.226260$TH3.11043957@phobos.telenet-ops.be> Antoon Pardon wrote: >>If somelist.sort() returned the list there could not possibly be one >>obvious way to do it, since both >> >>print somelist.sort() >> >>and >> >>somelist.sort() >>print somelist > > > Then python has already deviated from the one obvious way to do it. > I can do: > > a = a + b vs a += b. > > or > > a = b + c vs a = ''.join(b,c) a = ''.join((b,c)) join doesn't join all it's arguments; it joins all elements from it's one argument, which should be a sequence. That's a detail though. > > The difference between > > print somelist.sort() > > and > > somelist.sort() > print somelist > > > is IMO of the same order as the difference between > > > print a + b > > and > > r = a + b > print r Not IMO. print somelist.sort() has a side-effect (somelist is sorted), which is not clearly visible if used that way. a + b doesn't have any side-effects. IMO, 'print somelist.sort()' is more equivalent to 'print a += b', which also doesn't work (fortunately). -- "Codito ergo sum" Roel Schroeven From deetsNOSPAM at web.de Mon Aug 30 16:49:52 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Mon, 30 Aug 2004 22:49:52 +0200 Subject: xml.dom.minidom - documentElement vs. childNodes References: Message-ID: Skip Montanaro wrote: > I'm getting somewhat painfully acquainted with xml.dom.minidom. What is > the relationship between its documentElement attribute and its childNodes > list? > I thought XML documents consisted of a single, possibly compound, node. > Why is a list of childNodes needed? Maybe for reasons of orthogonality? In java, the document class implements the node interface also. So it seems as if dom treats documents as special cases of nodes. -- Regards, Diez B. Roggisch From zathras at thwackety.com Sun Aug 22 06:05:35 2004 From: zathras at thwackety.com (Michael Sparks) Date: Sun, 22 Aug 2004 11:05:35 +0100 (BST) Subject: [PATCH] RE: J2 decorator grammar In-Reply-To: Message-ID: On Sun, 22 Aug 2004, Anthony Baxter wrote: > On Sun, 22 Aug 2004 01:41:58 +0100 (BST), Michael Sparks wrote > > The patch can be found here: > > * http://thwackety.com/decorator_syntax_J2.patch > > Good to see. There's a few more bits than this that need to be > done, though - see http://www.python.org/sf/979728 for the original > @decorator patch, this should show you what else needs to be > changed. Many thanks for the pointer. I'll try and make sure I cover all the bases, but I suspect I'll miss something, but I'll try not to :) Regards, Michael. From skip at pobox.com Wed Aug 18 22:58:52 2004 From: skip at pobox.com (Skip Montanaro) Date: Wed, 18 Aug 2004 21:58:52 -0500 Subject: get last two in a length of unknown length? In-Reply-To: References: Message-ID: <16676.5996.552462.843044@montanaro.dyndns.org> MC> I have a list of varying length. Would someone know the way to get MC> the last two values for this? mylist[-2:] Skip From nospam at example.com Thu Aug 26 04:27:08 2004 From: nospam at example.com (Derek Fountain) Date: Thu, 26 Aug 2004 16:27:08 +0800 Subject: Converting hex string to an integer Message-ID: <412d9e18$0$22821$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Given the character string "0x00A1B2C3" arriving at sys.argv[1] how do I convert that to an integer which I can do some math on? From marco at reimeika.ca Thu Aug 5 15:32:09 2004 From: marco at reimeika.ca (marco) Date: 05 Aug 2004 15:32:09 -0400 Subject: advice for perl expert wanting to learn python References: Message-ID: Zeljko Vrba writes: > What's the easiest way of learning python knowing perl? Is there somewhere > a 'how-to' cookbook with parallel examples of frequent idioms in perl and > python? There's this one: http://makeashorterlink.com/?P6C226BF8 but it's a bit dated (probably good for simple stuff, though)... Cheers, -- marco at reimeika.ca Gunnm: Broken Angel http://amv.reimeika.ca http://reimeika.ca/ http://photo.reimeika.ca From simoninusa2001 at yahoo.co.uk Tue Aug 17 12:24:35 2004 From: simoninusa2001 at yahoo.co.uk (simo) Date: 17 Aug 2004 09:24:35 -0700 Subject: Newbie 1st program References: <278de0e.0408161537.61ab1301@posting.google.com> Message-ID: <30260531.0408170824.3fd74108@posting.google.com> luismg at gmx.net (Neuruss) wrote: > Just a question: How did you make the installer package? It's the old favourite py2exe plus InnoSetup. Couple of hints: 1. make the image a GIF instead of BMP, it's better for portability and size 2. is it platform-specific, or have you just not been able to test on UNIX? you don't need the .pyw 3. to put the .ico into the .exe and get the WinXP look'n'feel, you can use this as your setup.py for py2exe: from distutils.core import setup import py2exe manifest = """ GobbleWin """ setup( windows = [ { "script": "Gobblewx.py", "icon_resources": [(1, "Gobble.ico")], "other_resources": [(24,1,manifest)] } ], ) From b.niemann at betternet.de Mon Aug 16 08:10:29 2004 From: b.niemann at betternet.de (Benjamin Niemann) Date: Mon, 16 Aug 2004 14:10:29 +0200 Subject: sys.stdin.read() replacement In-Reply-To: References: Message-ID: not sure, if importing readline really gets the desired result (if I understand the initial question correctly) suppose the following input: > this is ym first line > and another line (oops there's a typo in the first line, user hits cursor up two times, and corrects it) > this is my first line ... what the program will then reads is: "this is ym first line" "and another line" "this is my first line" ... with no chance to see that the third line is supposed to replace line one. Or is readline actually more powerful than I remember? > import readline will work on Windows: > a) if you're running the cygwin python, inside cygwin > b) if you've installed a readline module; there are at least two available. > Excuse me for the self-referential answer, but about half and hour before I > read this, I wrote a blog entry all about readline modules, with links to > and comments about the Windows ones. The permalink is > http://www.livejournal.com/users/benlast/16766.html or it's the most recent > entry at http://www.livejournal.com/users/benlast/ > > Karin: if you do import a readline, you can then use sys.stdin.readline() to > read a line of input, and you should get some sort of history functionality > (up-arrow, for example, will recall a previous line). > > regards > b > > >>-----Original Message----- >>From: python-list-bounces+ben=benlast.com at python.org >>[mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of >>P at draigBrady.com >>Sent: 16 August 2004 11:52 >>To: python-list at python.org >>Subject: Re: sys.stdin.read() replacement >> >> >>Karin Lagesen wrote: >> >>>I am writing a small write-logfile script for use on the >> >>terminal. I have here >> >>>a section where the user should be able to type in several >> >>lines. I have solved >> >>>it so far by using sys.stdin.read(), which makes it possible to >> >>type in several >> >>>lines (separated by enter) and then terminate the session by >> >>typing ^D. This is >> >>>all very good. However, with this it is only possible to edit >> >>the line you are >> >>>in. If you spot an error further up in your text, you cannot >> >>get at it. Do any >> >>>of you know of a way I can do this? >> >> >>import readline >> >>(I don't know if it works on windos) >> >>P?draig. >>-- >>http://mail.python.org/mailman/listinfo/python-list > > From me at privacy.net Wed Aug 25 20:27:05 2004 From: me at privacy.net (Richard Hanson) Date: Wed, 25 Aug 2004 17:27:05 -0700 Subject: MSI Installer Problem: can't install 2.4a2 on new install of Win2kSP2 References: Message-ID: <14bqi0tl2bhdh2hi5n02htu3c4id899ngq@4ax.com> Following up: After a couple of tries this afternoon, I managed to DL Python 2.3.4 and installed it -- Idle ran and seemed to be normal. (I thought I would do a quick "test" before posting so I did a "from test import testall" and got pages and pages of output from 2.3.4 -- about 257kB's worth. ) Anyway, Python 2.4a2 *still* does not install on my Fujitsu LifeBook P1120 with Win2kSP2 -- as described in my original post. So, still stumped. hard-to-count-the-ways-without-Decimal'ly y'rs, Richard -- email works if unmunged: sickolefartnewsguycom From ajsiegel at optonline.com Thu Aug 26 10:24:24 2004 From: ajsiegel at optonline.com (Arthur) Date: Thu, 26 Aug 2004 14:24:24 GMT Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: On Thu, 26 Aug 2004 07:07:43 -0700, "R Baumann" wrote: > >"Xah Lee" wrote in message >news:7fe97cc4.0408251356.34f2102a at posting.google.com... >> Larry Wall and Cults >> (Lazyness, Impatience and Hubris) >> 200012 >> > > >In this context --- This is the STUPIDEST thing I've ever heard. What a >maroon! What a Trollup! > His plane curve work is not far from some of my own obsessions. I knew of and admired his site. Didn't know he had other interests as well ;) Maybe an extreme me. All obsessions in moderation, is my motto. Art >RB > From skip at pobox.com Mon Aug 30 13:49:59 2004 From: skip at pobox.com (Skip Montanaro) Date: Mon, 30 Aug 2004 12:49:59 -0500 Subject: xml.dom.minidom - documentElement vs. childNodes Message-ID: <16691.26823.940531.90499@montanaro.dyndns.org> I'm getting somewhat painfully acquainted with xml.dom.minidom. What is the relationship between its documentElement attribute and its childNodes list? I thought XML documents consisted of a single, possibly compound, node. Why is a list of childNodes needed? Thx, Skip From newsgroups at jhrothjr.com Fri Aug 6 17:06:53 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 6 Aug 2004 17:06:53 -0400 Subject: PEP 263 status check References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> <10h5hgvpafm8a64@news.supernews.com> <41133C76.8040302@v.loewis.de> <10h6rklt3fa1690@news.supernews.com> <41137799.70808@v.loewis.de> <10h724r20kkeqb2@news.supernews.com> <4113D8DF.8080106@v.loewis.de> Message-ID: <10h7tb8nn53ajbb@news.supernews.com> "Martin v. L?wis" wrote in message news:4113D8DF.8080106 at v.loewis.de... > John Roth wrote: > >>What would you expect instead? Do you think your expectation > >>is implementable? > > > > > > I'd expect that the compiler would reject anything that > > wasn't either in the 7-bit ascii subset, or else defined > > with a hex escape. > > Are we still talking about PEP 263 here? If the entire source > code has to be in the 7-bit ASCII subset, then what is the point > of encoding declarations? Martin, I think you misinterpreted what I said at the beginning. I'm only, and I need to repeat this, ONLY dealing with the case where the encoding declaration specifically says that the script is in UTF-8. No other case. I'm going to deal with your response point by point, but I don't think most of this is really relevant. Your response only makes sense if you missed the point that I was talking about scripts that explicitly declared their encoding to be UTF-8, and no other scripts in no other circumstances. I didn't mean the entire source was in 7-bit ascii. What I meant was that if the encoding was utf-8 then the source for 8-bit string literals must be in 7-bit ascii. Nothing more. > If you were suggesting that anything except Unicode literals > should be in the 7-bit ASCII subset, then this is still > unacceptable: Comments should also be allowed to contain non-ASCII > characters, don't you agree? Of course. > If you think that only Unicode literals and comments should be > allowed to contain non-ASCII, I disagree: At some point, I'd > like to propose support for non-ASCII in identifiers. This would > allow people to make identifiers that represent words from their > native language, which is helpful for people who don't speak > English well. L:ikewise. I never thought otherwise; in fact I'd like to expand the availible operators to include the set operators as well as the logical operators and the "real" division operator (the one you learned in grade school - the dash with a dot above and below the line.) > If you think that only Unicod literals, comments, and identifiers > should be allowed non-ASCII: perhaps, but this is out of scope > of PEP 263, which *only* introduces encoding declarations, > and explains what they mean for all current constructs. > > > The reason for this is simply that wanting to put characters > > outside of the 7-bit ascii subset into a byte character string > > isn't portable. > > Define "is portable". With an encoding declaration, I can move > the source code from one machine to another, open it in an editor, > and have it display correctly. This was not portable without > encoding declarations (likewise for comments); with PEP 263, > such source code became portable. > Also, the run-time behaviour is fully predictable (which it > even was without PEP 263): At run-time, the string will have > exactly the same bytes that it does in the .py file. This > is fully portable. It's predictable, but as far as I'm concerned, that's not only useless behavior, it's counterproductive behavior. I find it difficult to imagine any case where the benefit of having normal character literals accidentally contain utf-8 multi-byte characters outweighs the pain of having it happen accidentally, and then figuring out why your program is giving you wierd behavior. I would grant that there are cases where you might want this behavior. I am pretty sure they are in the distinct minority. > > It just pushes the need for a character set > > (encoding) declaration down one level of recursion. > > It depends on the program. E.g. if the program was to generate > HTML files with an explicit HTTP-Equiv charset=iso-8859-1, > then the resulting program is absolutely, 100% portable. It's portable, but that's not the normal case. See above. > For messages directly output to a terminal, portability > might not be important. Portabiliity is less of an issue for me than the likelihood of making a mistake in coding a literal and then having to debug unexpected behavior when one byte no longer equals one character. > > There's already a way of doing this: use a unicode string, > > so it's not like we need two ways of doing it. > > Using a Unicode string might not work, because a library might > crash when confronted with a Unicode string. You are proposing > to break existing applications for no good reason, and with > no simple fix. There's no reason why you have to have a utf-8 encoding declaration. If you want your source to be utf-8, you need to accept the consequences. I fully expect Python to support the usual mixture of encodings until 3.0 at least. At that point, everything gets to be rewritten anyway. > > Now I will grant you that there is a need for representing > > the utf-8 encoding in a character string, but do we need > > to support that in the source text when it's much more > > likely that it's a programming mistake? > > But it isn't! People do put KOI-8R into source code, into > string literals, and it works perfectly fine for them. There > is no reason to arbitrarily break their code. > > > As far as implementation goes, it should have been done > > at the beginning. Prior to 2.3, there was no way of writing > > a program using the utf-8 encoding (I think - I might be > > wrong on that) > > You are wrong. You were always able to put UTF-8 into byte > strings, even at a time where UTF-8 was not yet an RFC > (say, in Python 1.1). Were you able to write your entire program in UTF-8? I think not. > > > so there were no programs out there that > > put non-ascii subset characters into byte strings. > > That is just not true. If it were true, there would be no > need to introduce a grace period in the PEP. However, > *many* scripts in the world use non-ASCII in string literals; > it was always possible (although the documentation was > wishy-washy on what it actually meant). > > > Today it's one more forward migration hurdle to jump over. > > I don't think it's a particularly large one, but I don't have > > any real world data at hand. > > Trust me: the outcry for banning non-ASCII from string literals > would be, by far, louder than the one for a proposed syntax > on decorators. That would break many production systems, CGI > scripts would suddenly stop working, GUIs would crash, etc. . > > Regards, > Martin From ptmcg at austin.rr._bogus_.com Mon Aug 23 21:54:57 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Tue, 24 Aug 2004 01:54:57 GMT Subject: newbie: confused with example in Learning Python 2nd Edition:cananyone give a hint References: Message-ID: "Robert Brewer" wrote in message news:mailman.2254.1093312305.5135.python-list at python.org... Porky Pig Jr wrote: Hint: Python doesn't have variables like other languages do. The line: self._data = list(data) does not make a copy of "data". Instead, it binds a new name (self._data) to the same object which the name "data" refers to. FuManChu ====================== Er? I thought list(data) called the list constructor to create a copy of data, and bind the new list to self._data. That's why push and pop calls update the internal _data list without changing the original list. -- Paul From theller at python.net Tue Aug 24 14:24:00 2004 From: theller at python.net (Thomas Heller) Date: Tue, 24 Aug 2004 20:24:00 +0200 Subject: Building basic dialog in Windows? References: Message-ID: Fred writes: > Hi, > > I'd like to turn a command-line script into a Windows GUI app > using the native widgets so as to reduce the size of the binary (ie. > no QT, wxWidgets, et al.) > > I came up with the following list of tools to access the Win32 API: > > - PythonWin (MFC) http://www.python.org/windows/pythonwin/ > - ctypes http://starship.python.net/crew/theller/ctypes/ > - EasyDialogs for Windows > http://www.averdevelopment.com/python/EasyDialogs.html > - DynWin http://www.nightmare.com/~rushing/dynwin/ > - sdk32 - Partial Python wrap of the Win32 Platform SDK > http://www.object-craft.com.au/projects/sdk32/ You've missed venster http://venster.sf.net/ > > Does someone have a sample on how to display an OK/Cancel dialog with > a label + progress bar? Should I look at other tools? I think pywin32 has what you need, the makepy utility displays such a progress dialog when creating python wrappers for large typelibraries. Thomas From esj at harvee.org Fri Aug 20 10:58:20 2004 From: esj at harvee.org (Eric S. Johansson) Date: Fri, 20 Aug 2004 10:58:20 -0400 Subject: forking smtpd Message-ID: I was working on a filter for postfix and instead of using the "fork a new python process on every message" route, I decided to use the SMTP interface instead and try forking after having started the Python process. obviously, I needed some way to receive and processed SMTP. smtpd.py works OK if you are willing to use single threaded one at a time filtering. Because filtering takes significant amounts of time, I decided to expand smtpd to support a forking server. I make no claims to the correctness or suitability of these modifications or even that I understood wtf was going on with asyncore/chat. it will also be interesting to see what improvements others have to suggest. But here's what I found: it was relatively easy to create a subclass (forkSMTPServer) and inside of the accept handler, I was able to fork off the child process and release the connection. I suspect that I haven't released the listen socket properly but I will look into that. I also copied the asyncore polling loop into SMTPServer and modified it to support forking and exit on the same signal as the rest of asyncore. the last change I added was a close method to SMTPChannel and process_close method SMTPServer. This is so one can detect when a channel has closed and do something about it such as ending a child process. so, in the end a forking smtp receiver looks like: class filter(smtpd.forkSMTPServer): def process_message(self, peer, mailfrom, rcpttos, data): sleep(5) log("postfix peer %s %s"%(peer)) log("postfix mail from %s"%(mailfrom)) log("postfix rcpt to %s"%(rcpttos)) # print "processing",self.parent_ID f = filter2(("localhost",40025)) try: #asyncore.loop(10) f.loop(10) print "exit from loop" except KeyboardInterrupt: pass except SystemExit: pass except Exception, error: print str(error) etype, value, tb = sys.exc_info() exception_strings = traceback.format_exception(etype, value, tb) for i in exception_strings: print(i, 1) line wrapped patches below: 270,274d269 < def close(self): < print "outside close" < asynchat.async_chat.close(self) < self.__server.process_close() < 321,385d315 < def process_close (self): < """override this abstract method to handle the close of SMTP channel. """ < pass < < def loop (self, timeout=30.0, use_poll=0, map=None): < global f < if map is None: < map=asyncore.socket_map < < if use_poll: < if hasattr (select, 'poll'): < poll_fun = asyncore.poll3 < else: < poll_fun = asyncore.poll2 < else: < poll_fun = asyncore.poll < < while map: < try: < status = os.waitpid(-1,os.WNOHANG) < print "timeout loop %s %s"% (self.parent_ID, str(status)) < except OSError, error: < if error[0] == 10: < status = (0,0) < else: < print self.parent_ID, error < < if status[0] == 0: < try: < poll_fun (timeout, map) < except asyncore.ExitNow: < return < < < class forkSMTPServer(SMTPServer): < < def __init__(self, address): < < self.parent_ID = None < SMTPServer.__init__(self, address,(0,0)) < self.mychannel = None < < def handle_accept(self): < conn, addr = self.accept() < self.parent_ID = os.fork() < if not self.parent_ID: < print >> DEBUGSTREAM, 'Incoming connection from %s' % repr(addr) < self.mychannel = SMTPChannel(self, conn, addr) < else: < # close off socket in parent and fake lack of connection < conn.close() < self.connected = 0 < print "child fork ID", self.parent_ID < < def process_close(self): < < print "process my very own close " < < # if we are a child process, we are done so exit < if not self.parent_ID: < print "exit stage left %s"% (self.parent_ID) < raise asyncore.ExitNow < < < -- Speech recognition in use. It makes mistakes, I correct most From aleaxit at yahoo.com Fri Aug 27 14:37:44 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 27 Aug 2004 20:37:44 +0200 Subject: Class Friends References: <20040827081556.657c3fac.a@c.d> Message-ID: <1gj72ft.z5skuq14uaiihN%aleaxit@yahoo.com> Anthony Baxter wrote: ... > I've considered a jihad to try and get uses of the double-under > mangling removed from the standard library. Maybe once 2.4 is out I'll > take this on. Count on my support on this: I consider it "something that looked like it would be a good idea at the time" (to me, too -- I'm not prescient either;-) but didn't really work as well as hoped. Alex From robin at alldunn.com Mon Aug 30 14:11:27 2004 From: robin at alldunn.com (Robin Dunn) Date: Mon, 30 Aug 2004 11:11:27 -0700 Subject: ANNOUNCE: wxPython 2.5.2.8 Message-ID: <41336DCF.60503@alldunn.com> Announcing ---------- I'm pleased to announce the 2.5.2.8 release of wxPython, now available for download at http://wxpython.org/download.php or https://sourceforge.net/project/showfiles.php?group_id=10718&package_id=10559&release_id=263903 What is wxPython? ----------------- wxPython is a GUI toolkit for the Python programming language. It allows Python programmers to create programs with a robust, highly functional graphical user interface, simply and easily. It is implemented as a Python extension module that wraps the popular wxWidgets cross platform GUI library, which is written in C++. wxPython is a cross-platform toolkit. This means that the same program will usually run on multiple platforms without modifications. Currently supported platforms are 32-bit Microsoft Windows, most Linux or other Unix-like systems using GTK or GTK2, and Apple Macintosh OS X. Changes in 2.5.2.8 ------------------ This is predominantly a bug-fix release. Changes include: * Fixed fatal error due to improper wrapping of wx.FSFile. * Fixed return type of EditableListBox.GetListCtrl * Give generic tree and list controls a DoGetBestSize so they play nicer with sizers when there is no minimal size. * Some tweaks in the demo and samples to correct layout, some flicker problems, and namespace use. * Add wx.Image.ConvertAlphaToMask * Minor corrections in wx.lib.dialogs * wx.FileHistory constructor now accepts the documented 2nd parameter. * Corrections for exceptions in the new ogl * Fixed XRCed to not use reparenting of windows to implement caching of property panels, since Reparent on wxMac is not implemented. * Add support for wxTAB_TRAVERSAL to the XRC handler for wxScrolledWindow. * Add support for all wxListBox styles to the XRC handler for wxCheckListBox. * Fix for wx.Listbook.DeleteAllPages to really delete everything. * wxGTK2 now supports alpha blended bitmap drawing * Made wx.grid.Grid play nicer with sizers. * etc. -- Robin Dunn Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython! From SBrunning at trisystems.co.uk Tue Aug 17 12:03:32 2004 From: SBrunning at trisystems.co.uk (SBrunning at trisystems.co.uk) Date: Tue, 17 Aug 2004 17:03:32 +0100 Subject: Problem with floating point precision Message-ID: <31575A892FF6D1118F5800600846864D01AE2992@intrepid> > From: j_mckitrick at bigfoot.com [mailto:j_mckitrick at bigfoot.com] > > I checked the docs, but found nothing about floating point issues. > > I am working on an app that deals with currency values, and only does > addition and subtraction (no division). But I am starting to see > values that should be the same failing a compare! What is the > workaround or correct way to compare 2 floats? It worked fine for > months, then suddenly starting acting odd. I might have upgraded > Python somewhere in between, I can't recall. http://www.brunningonline.net/simon/blog/archives/000710.html ;-) Cheers, Simon B. simon at brunningonline.net http://www.brunningonline.net/simon/blog/ ----------------------------------------------------------------------- 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 narshe at gmail.com Mon Aug 16 14:57:30 2004 From: narshe at gmail.com (Josh Close) Date: Mon, 16 Aug 2004 13:57:30 -0500 Subject: ConfigParser options spanning more than one line In-Reply-To: References: Message-ID: <4a0cafe2040816115718932a7d@mail.gmail.com> That works, I guess I'll just have to remove the \n from the variable then. -Josh On Mon, 16 Aug 2004 13:31:03 -0500, Paramjit Oberoi wrote: > > I'm using ConfigParser and I can't seem to get a config option to span > > more than one line. > > >>> from ConfigParser import ConfigParser > >>> from StringIO import StringIO > >>> s = StringIO("[a]\n" > .... "b = 123\n" > .... " 456") > >>> c=ConfigParser() > >>> c.readfp(s) > >>> c.get('a','b') > '123\n456' > > In other words, any line with a leading whitespace is considered a > continuation line, and the leading whitespace is stripped from the value > (but the carriage return is left in). > > HTH, > -param > > > -- > http://mail.python.org/mailman/listinfo/python-list > From simoninusa2001 at yahoo.co.uk Fri Aug 27 13:56:13 2004 From: simoninusa2001 at yahoo.co.uk (Simon John) Date: 27 Aug 2004 10:56:13 -0700 Subject: Mysql in Python? In-Reply-To: <7xsma9gfpr.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > > Using PHP native database functions is a very bad idea. All experencied > > programmers use more abstract db wrappers like ADOdb > > (http://adodb.sourceforge.net/). > Interesting. Every PHP app I've ever seen uses the native functions, > but I haven't looked at many fancy ones. Yeah, same here, I've always just used the Oracle or MySQL native functionality, and wouldn't call myself unexperienced! I've just never had the need for a database abstraction layer (it's always been clear-cut what database I will use, and stick with). > > There is no PHP standard templating system. PHP itself is a template > > framework! > I'm not sure what the distinction is supposed to be? PHP4 has it's own templating system (allowing repeatable blocks etc) things like Nuke are more advanced, like a CMS. I prefer the more basic functionality that I can control better myself, rather than having to work to a spec enforced by third-party software. And the ADOdb page says that to use it with MySQL, you have to install the mysql-python (MySQLdb) module, so doesn't really help here, as we haven't even got that far! From loic-dev at gmx.net Tue Aug 31 00:30:08 2004 From: loic-dev at gmx.net (Loic Domaigne) Date: Tue, 31 Aug 2004 06:30:08 +0200 Subject: Xah Lee's Unixism In-Reply-To: <87wtzgmd4p.fsf@thalassa.informatimago.com> References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4PGdnfsOfdDPi63cRVn-tA@speakeasy.net> <41337FC9.8070902@hotmail.com> <87wtzgmd4p.fsf@thalassa.informatimago.com> Message-ID: <2pid4pFl4d08U1@uni-berlin.de> >>Windows (MS) is not 'Unixism'? > > > It's VMS'ism ! Without all the security aspects, of course... Loic. From flupke at nonexistingdomain.com Thu Aug 19 08:46:59 2004 From: flupke at nonexistingdomain.com (flupke) Date: Thu, 19 Aug 2004 12:46:59 GMT Subject: timer problem Message-ID: <7j1Vc.218972$p67.10887223@phobos.telenet-ops.be> I have a timer in a program but the function it is supposed to call, is only executed once. To simplify searching what i have done wrong, i've made a small test app ================================ import threading def command(): print "TIMER CALLED" t = threading.Timer(2, command ) t.start() s = raw_input() t.cancel() ================================ Now, when i run it, it only prints TIMER CALLED once instead of every 2 seconds. What am i doing wrong? (Python 2.3.4 on Win2000) Thanks, Benedict From steven.bethard at gmail.com Thu Aug 19 04:07:31 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 19 Aug 2004 08:07:31 +0000 (UTC) Subject: inverse of izip References: <41245B48.3020000@zeomega.com> Message-ID: Satchidanand Haridas zeomega.com> writes: > How about using iter() to get another solution like the following: > > >>> starzip2 = lambda it: tuple([iter(x) for x in itertools.izip(*it)]) > > >>> l,m = starzip2(itertools.izip(range(10),range(10))) > > >>> l > > >>> m > > > >>> list(l) > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > >>> list(m) > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Unfortunately, I think this exhausts the iterators too early because it applies * to the iterator: >>> def range10(): ... for i in range(10): ... yield i ... print "exhausted" ... >>> l,m = starzip2(itertools.izip(range10(),range10())) exhausted I believe we only get one "exhausted" because as soon as one iterator is used up with izip, the next iterator is discarded. But we are hitting "exhausted" before we ever ask for an element from the starzip2 iterators, so it looks to me like all the pairs from the first iterator are read into memory before the second iterators are ever accessed... Steve From sbabbitt at commspeed.net Fri Aug 6 14:04:22 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Fri, 6 Aug 2004 11:04:22 -0700 Subject: unicode to ascii converting References: Message-ID: <1091815856.527127@news.commspeed.net> "Peter Wilkinson" wrote in message news:mailman.1296.1091813051.5135.python-list at python.org... > Hello tlistmembers, > > I am using the encoding function to convert unicode to ascii. At one point > this code was working just fine, however, now it has broken. > > I am reading a text file that has is in unicode (I am unsure of which > flavour or bit depth). as I read in the file one line at a time > (readlines()) it converts to ascii. Simple enough. At the same time I am > copressing to bz2 with the bz2 module but that works just fine. The code > is and error reported appears below. I am unsure what to do. > > I assume that because it is reporting that ordinal is not in range, that > something to do with the character width that I am reading? > > Peter W. > > def encode_file(file_path, encode_type, compress='N'): > """ > Changes encoding of file > """ > new_encode = encode_type > old_file_path = file_path + '.old' > new_file_path = file_path > os.rename(file_path,old_file_path) > file_in = file(old_file_path,'r') > > if compress == 'Y' or compress == 'y': > bz_file_path = file_path + '.bz2' > bz_file_out = bz2.BZ2File(bz_file_path, 'w') > for line in file_in.readlines(): > bz_file_out.write(line.encode(new_encode)) > bz_file_out.close() > > else: > file_out = file(file_path,'w') > for line in file_in.readlines(): > file_out.write(line.encode(new_encode)) > file_out.close() > > file_in.close() > os.remove(old_file_path) > > ERROR Reported: > > Parsing > X:\GenomeQuebec_repository\microarray\HIS\M15K\Step_1_repository\HISH0224.tx t > Traceback (most recent call last): > File "C:\Program Files\ActiveState Komodo 2.5\callkomodo\kdb.py", line > 433, in _do_start > self.kdb.run(code_ob, locals, locals) > File "C:\Python23\lib\bdb.py", line 350, in run > exec cmd in globals, locals > File "C:\Python23\Lib\site-packages\xBio\Scripts\unicodeToAscii.py", > line 158, in ? > main() > File "C:\Python23\Lib\site-packages\xBio\Scripts\unicodeToAscii.py", > line 75, in main > encode_file(fileToProcess, options.encode, 'Y') > File "C:\Python23\Lib\site-packages\xBio\Scripts\unicodeToAscii.py", > line 144, in encode_file > bz_file_out.write(line.encode(new_encode)) > UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: > ordinal not in range(128) > I've encountered this problem before and the solution I've come up with a fix that works but is probably not the best, def is_ord (strng): new_text = '' for i in strng: if ord(i) > 127: new_text = new_text + '' else: new_text = new_text + i return new_text #Then just, text_from_file = is_ord(text_from_file) Tom From ialbert at mailblocks.com Sat Aug 7 16:54:29 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Sat, 07 Aug 2004 16:54:29 -0400 Subject: Going the PL/1 way In-Reply-To: References: Message-ID: Mikl?s wrote: > Yes, this was exactly my point. Performance and GIL. Those are problems. > And problems must be solved. After that add features... if they are really > needed. nah, first we need to attend to pressing needs, such as replacing my_list.reverse() for item in my_list: ... with the incomparably more pythonic: for item in reversed(my_list): ... and at the same time, we need to replace the ridiculous: my_list.sort() for item in my_list: ... with: for item in my_list.sorted(): ... note the consistency in 'sort' and 'reverse' and the lack of that in the usage of sorted and reversed. Istvan. From jsaker at americanrelay.com Tue Aug 17 17:09:14 2004 From: jsaker at americanrelay.com (James R. Saker Jr.) Date: Tue, 17 Aug 2004 16:09:14 -0500 Subject: network server threading Message-ID: <1092776954.30276.27.camel@localhost> I've got a: "start server thread > Queue object, start server thread <> Queue object, start parsing client < Queue object" application that's got me puzzled. Probably an easy threads issue, but after digging thru Programming Python and Python Recipes sections on Threading class and running thru the examples, I'm still missing something. My Server/Server/Client app is a syslog collector app (syslog input in, zope control web interface to manage ala start/stop/status, and BEEPy out) - two servers and one client app that has got me somewhat puzzled per how to handle with threads. The app: 1. read in config file 2. launch a syslog server to listen on port 514, taking input and putting it into a database-persistent Queue (I'm using BDB's DB_QUEUE implemented in a class Logfile which I've created to allow me to: l = Logfile(db_filename, db_recsize) ## BSD DB's Queue has a fixed record length limitation which gets set by db.set_re_len and then l.push("Syslog data.....") l.push("More syslog data...") as well as l.pop(), l.hasrec() and l.size() methods to control the Queue. 3. runs a test message to see if I've launched the first server and am ready to do more work (this is where the second server and client will come in once I'm crawling along). The problem I run into is that I'm apparently not threading the syslog server and returning control to my app: class Syslogd(ThreadingUDPServer, InterruptibleServer): is based on: http://www.drbeat.li/pycgi/webutil.py/html?py=py/syslogd.py.txt with modifications to reference my Berkeley DB Queue, instead of displaying to sys.stdout.write. So far, so good - I'm logging and writing to the database (though it appears to be committing on the db.close() rather than writes, but that's another issue I'll have to deal with via the BSD DB C/Java docs since the Python docs on it's Queue method are limited - I've looked at ZODB for this as well). Here's where I get into trouble, and as mentioned at the beginning, is probably just a lack of me getting threads: if __name__ == '__main__': try: log = Logfile('syslog.db',255) # create BSD DB Queue object syslogd = Syslogd(log, timefmt='%H:%M:%S') #create syslog object syslogd.serve() #start serving syslog input on port print "This is a test" except KeyboardInterrupt: print "Closing queue database..." log.close() print "Operation canceled by user." I never get to the test print, as once I'm in syslog.serve(), I'm there until I quit. Maybe I'm missing the logic here completely - if I want to share access to Logfile between syslogd object and two other objects, am I on the wrong track? Eventually, after threading syslog.serve(), I need to do the same with the Zope HTTP service (which allows control to the application, much like HTTP to a Linksys router for status, configuration, start, stop functions), and also launching the BEEPy parsing of data from the Queue which gets passed onto a database upstream. Talking BEEP is a must due to the firewalls involved, so no distributed object approach will help here. A "syslogd in, dump to queue backed by database in case device gets shut off before it can parse and send, and a parse & send via BEEP engine" model. Maybe there's a better example out there of: 1. start server dumping to a shared object 2. start another server accessing a shared object 3. start a client processing the shared object model someone is aware of - ala Queue? Thanks much... Jamie "So much to learn, so little caffeine!" From ptmcg at austin.rr._bogus_.com Thu Aug 19 13:11:48 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Thu, 19 Aug 2004 17:11:48 GMT Subject: age of Python programmers References: <4124d4a4$1@nntp0.pdx.net> Message-ID: "Scott David Daniels" wrote in message news:4124d4a4$1 at nntp0.pdx.net... > Mike Brenner wrote: > > > I was born about 10,000 years ago and I used to > > program computers made of human beings who > > were aligned in tiers. The bottom tier counted > > the grains in the baskets. The next tier > > counted the baskets in the barn, then the > > number of brans in each country. > > > Don't laugh. I met a woman roughly my age (53 now) > whose mother was a programmer at los Alamos (or was > it Trinity?) -- she programmed rooms of people > running mechanical calculators (calculate this, if > a > b, pass your results right, otherwise, ...) > > Scott David Daniels > Scott.Daniels at Acm.Org This technique is also described in Neal Stephenson's book "Cryptonomicon". -- Paul From squirrel at WPI.EDU Sun Aug 1 20:05:33 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Sun, 1 Aug 2004 20:05:33 -0400 Subject: transforming a list into a string In-Reply-To: References: Message-ID: On Sun, 1 Aug 2004, Tim Peters wrote: > [Christopher T King] > > ... > > Curious, why isn't slicing of generators defined, using islice(), so "it1 > > = iter(items)[0::2]" is valid? > > If only some iterators implement it (like generator-iterators), then the > general interchangeability of iterable objects we enjoy today would be > damaged too. Ah, I see your point. But most functions that expect iterators use iter() on them first (to iterize sequences), do they not? So long as iter() supplies the necessary __getslice__ implementation, the world would be happy. This situation would mirror the situation with list(): though a user-defined sequence might not implement __getslice__ (and still be usable as a list), the object returned by list() is guaranteed to. From squirrel at WPI.EDU Thu Aug 5 12:44:02 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 5 Aug 2004 12:44:02 -0400 Subject: Python cgi script In-Reply-To: References: Message-ID: On Thu, 5 Aug 2004, Yong Wang wrote: > file=open('/apps/www/htdocs/internal/nd/output1', 'r') > flag=0 > while not flag > aLine = file.readline() > if aLine != "": > print aLine > print '\n' > else: > flag = 1 > file.close() > print "" > print "" > The output from print statement above in web can display, but no line > separation between different lines. How can I preserve the orginal line > format of the input file (space within a line and space between lines)? HTML generally ignores whitespace. You need to either append a break tag (
    ) to each line, or enclose the output in

    ...
    . Also don't forget to start the document with . A couple of other notes: file.readline() retains the line's newline terminator, and print adds one. Your code ends up printing 4 newlines per actual line. Just using 'print aLine,' should work (the trailing comma prevents print from adding a newline). Assuming you are using a relatively recent version of Python (2.2 or 2.3, not sure about 2.1), you can rewrite your loop using iteration over the file object: for aLine in file: print aLine, From della at toglimi.linux.it Mon Aug 16 09:15:31 2004 From: della at toglimi.linux.it (Matteo Dell'Amico) Date: Mon, 16 Aug 2004 13:15:31 GMT Subject: Why does this (very simple piece of) code does not work? In-Reply-To: References: Message-ID: jblazi wrote: > os.rename(x,y) > Traceback (most recent call last): > File "", line 9, in ? > OSError: [Errno 22] Invalid argument Works fine here (Linux). Maybe you're using a platform where you use invalid characters for the filename? -- Ciao, Matteo From fumanchu at amor.org Sat Aug 21 00:11:31 2004 From: fumanchu at amor.org (Robert Brewer) Date: Fri, 20 Aug 2004 21:11:31 -0700 Subject: J2 decorator grammar Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E1B@exchange.hqamor.amorhq.net> > Michael Sparks wrote: > > > decorator: dotted_name [ '(' [arglist] ')' ] > > funcdef: ['decorate' ':' NEWLINE INDENT decorators DEDENT ] > 'def' NAME > parameters ':' suite > > Would you consider this instead? > > decorator_suite: expression_stmt | NEWLINE INDENT expression_stmt+ > DEDENT > funcdef: ['decorate' ':' decorator_suite] 'def' NAME parameters ':' > suite Never mind on re-using 'expression_stmt'; it's easiest right now just to keep the com_decorator() approach. But it still might be nice to go with a new, explicit suite. It's more in line with the other compound_stmt grammars. In addition, it might help solve your scoping issue to handle. decorator: dotted_name [ '(' [arglist] ')' ] decorator_suite: decorator | NEWLINE INDENT decorator+ DEDENT funcdef: ['decorate' ':' decorator_suite] 'def' NAME parameters ':' suite Did you ever fix the scope issue? Might it have something to do with: static void symtable_node(struct symtable *st, node *n) { int i; loop: switch (TYPE(n)) { case funcdef: { char *func_name; if (NCH(n) == 6) symtable_node(st, CHILD(n, 0)); ..I would think changing "if (NCH(n) == 6)" to 11 for your existing grammar would "do the same thing" for J2 that this does for A1. Robert Brewer MIS Amor Ministries fumanchu at amor.org From mwh at python.net Wed Aug 25 07:03:10 2004 From: mwh at python.net (Michael Hudson) Date: Wed, 25 Aug 2004 11:03:10 GMT Subject: Why return None? References: Message-ID: Anthony Baxter writes: > On Wed, 25 Aug 2004 08:26:26 GMT, Martin DeMello > wrote: > > It seems to be a fairly common pattern for an object-modifying method to > > return None - however, this is often quite inconvenient. > > list.reverse() modifies the list in place. The python idiom is that > these don't return a reference to the modified list. Although note the > new list.sorted() method in 2.4... It's a builtin now (as is reversed). Cheers, mwh -- Back in the old days, software would grow until it could send and receive e-mail, but now that even the virusses are doing that, the fashion has changed, and now software evolves until it has venomous fangs, the better to do serious damage when it sucks. -- AdB, asr From fumanchu at amor.org Mon Aug 9 02:46:37 2004 From: fumanchu at amor.org (Robert Brewer) Date: Sun, 8 Aug 2004 23:46:37 -0700 Subject: profile stats interpretation Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022DE7@exchange.hqamor.amorhq.net> I've been working on optimizing some code (yes, it really needs it--it's too slow ;) -- decided to use hotshot. I'm assuming things about the output of hotshot.stats that I want to verify before I make decisions off of them. Here's an example of output I'm getting. I coded the same function 3 different ways--it's basically a type coercer. Each method results in different stats (for the same request): ncalls tottime percall cumtime percall filename:lineno(function) 17582 0.670 0.000 1.428 0.000 logic.py:133(coerce) ncalls tottime percall cumtime percall filename:lineno(function) 17582 0.509 0.000 1.829 0.000 logic.py:133(coerce) ncalls tottime percall cumtime percall filename:lineno(function) 17582 0.604 0.000 1.202 0.000 logic.py:133(coerce) The question is: which of these three should I keep? Is "tottime" the time of the code within coerce(), without regard to functions called from coerce()? If so, it seems method #2 is superior. Finally, why might #3 have a much lower cumtime but higher tottime than #2, given that I didn't change any other code? Hmmm. FWIW, here's the function. Method #1: def coerce(self, value, valuetype=None): if valuetype is None: valuetype = type(value) try: xform = self.processors[valuetype] except KeyError: xform = self.default_processor return xform(value) Method #2: def coerce(self, value, valuetype=None): if valuetype is None: valuetype = type(value) xform = self.processors.get(valuetype, self.default_processor) return xform(value) Method #3: def coerce(self, value, valuetype=None): if valuetype is None: valuetype = type(value) if valuetype in self.processors: xform = self.processors[valuetype] else: xform = self.default_processor return xform(value) Any advice would be appreciated. Robert Brewer MIS Amor Ministries fumanchu at amor.org From fumanchu at amor.org Sun Aug 22 01:12:59 2004 From: fumanchu at amor.org (Robert Brewer) Date: Sat, 21 Aug 2004 22:12:59 -0700 Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E23@exchange.hqamor.amorhq.net> Paul McGuire wrote: > Well, after 3 days of open polling, the number of additional > votes have > dropped off pretty dramatically. Here are the results so far: > > Total voters: 55 (with 3 votes each) Funny, I have 56. But I counted Paul Rubin (J4, None, None). ;) > However, the multivote format gives us some additional > information, over > conventional "one-person-one-vote" format. Of the 55 voters, > 75% cast at > least one vote for J2, while only 35% cast one or more votes > for C1. From > the standpoint of building concensus, I find this statistic > more compelling > than the raw vote count. It tells me that 3/4 of the voting > sample are at > least open to the option presented by J2, so that developing community > acceptance is more likely to happen more quickly with J2 than with C1. >8 > I do *not* think that Guido plans to have a run-off between the > chosen alternative and the @ syntax, nor that he would give much > credence to one if it were held Mostly true. He intimated today that he would like more confirmation that the J2 proposal has broad support among all developers, not just those thirsting for an alternative. Voting solely among alternatives doesn't supply that statistic, and Doug Holton's poll, although it included A1, used arbitrary "favorite candidates". Now that we are approaching a more consensus alternative, it might be best (AFTER the proposal is hashed out) to find a way to produce that statistic for him. Personally, I would favor a list of names over an anonymous poll. Two lists, actually--one of those who can support the J2 proposal, and those who reject it in favor of A1. Actually, I would favor him being completely swayed by the arguments in the proposal, but I won't hold my breath. ;) > But I think he *will* be pleased that among the babel of > syntax proposals that have been put forward, this fairly unstructured and > unorganized group will have come to closure and met his challenge, > and settled on *one* alternative option. Yup. If for no other reason, because he can then reject it forever. ;) > ...response rate now looks to be dropping off. I am skeptical > that additional time will significantly change the results. I think you should give it a Monday. End-of-week-only polls always fare poorly in turnout. The release of the proposal draft by Monday morning may also galvanize reaction on both sides. Robert Brewer MIS Amor Ministries fumanchu at amor.org From paddy3118 at netscape.net Sat Aug 21 03:32:04 2004 From: paddy3118 at netscape.net (Paddy McCarthy) Date: 21 Aug 2004 00:32:04 -0700 Subject: age of Python programmers References: Message-ID: <2ae25c6b.0408202332.c9db9af@posting.google.com> Hi, I'm 44, Male, Partnered for life to Maggie and have two sprogs Owen 7 and Guinan 9. I started Programming because at 15 I liked to go to the Trent Polly library where I learnt that High School kids had access to their DEC Mini. I snuck down to the teletypes and wrote my first programs in Basic. (I'm still bitter that the Computer was open to all schools but it seemed that only the High school new about it ;-) After that I learnt all about electrons, holes, migration, doping, (yawn) You can say I learnt much more about the hardware than was neccessary! Along the way I was a Pascal bigot but got over that once they standardised C, A C programmer, A C++ avoider,a forth dabbler, an AWK expert, A Cadence SKILL expert - (marry Lisp to optional infix notation and you end up with a very good language), Oh and I wrote my own interpreter (in C on an Acorn RiscPC), Over the years I have come to realise the one true editor is vi but you must include its clones, and you must also admit that other editors have their strong points. (apart from EMACS which is to be avoided :-) I also do perl and like a lot of people here - its for work only. Ideally I'd do most of my programming in AWK for small scripts, Python for as much as is comfortable, C when neccessary, SKILL for nostalgia, and others for unique capabilities, e.g. there is no constrained random-generation of integers in Python for it to be used in testing Digital ICs. I'm carefully monitoring the kids and as soon as they show that sparc of interest, I'll back off for fear of putting them off programming for life :-) Cheers, Pad. From corey.coughlin at attbi.com Wed Aug 18 17:05:12 2004 From: corey.coughlin at attbi.com (Corey Coughlin) Date: 18 Aug 2004 14:05:12 -0700 Subject: Databases: Getting values by column name References: Message-ID: Has anyone out there come up with a general purpose database table like object that someone could use as a front end for any generic database? It seems like something that could be useful to a lot of people. Generally, we have a number of data structures in the standard library, lists and dicts are built in while sets, queues, and arrays are available in the standard library, it seems like tables would be the next logical step. It would probably make those table-based computing people happy. And it would be a natural, python friendly front end to the db api. You'd probably need a record class with the ability to reference by position or column name, that wouldn't be too hard. Then a list-like container to hold the data, with some functions to reference records, sort on some criteria, select subsets, and so on. Is there a PEP out there for something like this already, or is there a feature argument going on, or is it just something nobody has gotten around to yet? From nick at no.spam.org Fri Aug 27 07:00:23 2004 From: nick at no.spam.org (Nick Efford) Date: Fri, 27 Aug 2004 12:00:23 +0100 Subject: Call for signatories for J2 References: Message-ID: On Wed, 25 Aug 2004 09:42:15 -0700, Robert Brewer wrote: > This is a call for all who wish to sign the proposal, either for, > against, or abstaining. FOR. I could live with @ but I'm warming to J2, and you've done some great work in presenting cogent arguments. I'm with Alex M. in favouring 'as' over 'using'. Nick Efford From martin at v.loewis.de Mon Aug 30 17:10:34 2004 From: martin at v.loewis.de (=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 30 Aug 2004 23:10:34 +0200 Subject: [IronPython] Jim Hugunin's web log. In-Reply-To: References: Message-ID: <413397CA.8090209@v.loewis.de> David Wilson wrote: > Other random thoughts: my experiences of the Python community versus, > eg., the perl community make me believe that Pythonistas are generally > more accepting of commercial solutions than their open source weenie > perl counterparts (*duck*). I don't think this is an accurate description. Instead, Python is not tied so much in Unix as Perl is (IMO). It is not Python's philosophy to make all platforms look alike, but rather to expose all features of a platform to the Python programmer - whether this is /dev/tty on Unix or the registry on Windows. For features where it makes sense, a common interface is established; other features are by nature restricted to a single platform. As a result of that philosophy, people are often tempted to port Python to "strange" platforms (be that Mac OS 9, BeOS, VMS, or the JVM). They then found that Python maintainers where open to changes resulting from these ports as long no harm was done to Python "proper" (laissez-faire); this continues to encourage people to experiment with the language, and with various platforms. Regards, Martin From peter at engcorp.com Mon Aug 30 16:06:26 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 30 Aug 2004 16:06:26 -0400 Subject: Size of a remote URL In-Reply-To: References: Message-ID: Justin wrote: > Ok so the problem is that my code is not requesting the headers > properly. I get back. Just that. I don't know what the difference is > between the IE request and mine > > \ Date: Mon, 30 Aug 2004 19:36:20 GMT > Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12 > OpenSSL/0.9.6b DAV/ > 1.0.3 PHP/4.3.2 mod_perl/1.26 > Connection: close > Content-Type: text/html; charset=iso-8859-1 > > > My code: > for y in linklisttype: > w = urlopen(y) > z = w.info() > x = z.getheader("Content-Length") > file_sizes.append(x) > Is there a better method for getting headers than urlopen? Better how? urlopen actually works when the Content-Length header is provided. If it doesn't, it's a bug in Python. Can you or can you not provide an instance of a URL which does not provide a Content-Length header using your above code when IE in fact appears to get the length? By the way, the above code works perfectly well when applied to the first URL you gave above. Have you got one where it doesn't? -Peter From nhodgson at bigpond.net.au Sat Aug 7 21:12:47 2004 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sun, 08 Aug 2004 01:12:47 GMT Subject: decorators vs GIL References: Message-ID: mudd at vex.net: > I'm guessing the GIL is beyond any of us. If it was easy, or even > possible, someone would have already eliminated it. Greg Stein did produce a free threading version of Python. http://python.tpnet.pl/contrib-09-Dec-1999/System/threading.README It performed much slower than GIL based Python, at something like 60% of the GIL version with one processor. This is the expected result when replacing a large scale lock with many finer grained locks: there is more locking overhead. It is possible that techniques can be found to reduce the free threading cost so it would be great for people to continue working on this. http://mail.python.org/pipermail/python-dev/2001-August/017099.html The barrier to keeping this code in standard Python as an option is the amount of maintenance effort it represents both for itself and its impact on the GIL version. Neil From mike at nospam.com Mon Aug 16 12:59:30 2004 From: mike at nospam.com (Mike Rovner) Date: Mon, 16 Aug 2004 09:59:30 -0700 Subject: Flython? References: <411cbcb1$0$3894$4d4ebb8e@news.nl.uu.net><30260531.0408131856.5ef3b0d3@posting.google.com> <2oc547F86br8U1@uni-berlin.de> Message-ID: Daniel Ellison wrote: > Peter Hansen wrote: >> to come. Flash has a compact bytecode, while SVG comes >> as XML. Need I say more? > > Nope! :) OTOH, Flash bytecode is proprientary and may change "without notice", SVG is an open standard. Client machines spped is also tend to increase. I wish bytecode format be published somewhere. ;) Mike From michaels at rd.bbc.co.uk Fri Aug 20 11:23:13 2004 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Fri, 20 Aug 2004 16:23:13 +0100 Subject: Decorator keyword options - brainstorming References: <7knVc.4599$Jn5.3074@fe1.texas.rr.com> Message-ID: Paul McGuire wrote: ... > Similarly, I feel our fixation on the "decorator" concept is > confounded by our own understanding that the entries in a list of > decorators such as: ... [ short list ] ... > will translate to: > foo = staticmethod(synchronize(memoize(foo))) > > in the current vernacular. > > But should we consider this implementation detail when coming up with > this name? Since they're a list of functions that will be applied to the function/method that follows, I personally think it's important. Whilst many decorators can be alluded to as a keyword, I don't think all decorators would be. Consider how you would describe the actions of this list, or how you would describe this list of actions: (taken from various sources) staticmethod generator grammarrule('statement : expression') versioninfo("Added in 2.4") deprecated typeinfo(None) author("joe bloggs") funcattrs(grammar="'@' dotted_name [ '(' [arglist] ')' ]", status="experimental", author="BDFL") > qualify: (or perhaps qual:) > property: (or perhaps prop:) > On an alternative path, does this have to be a real word? I confess > that "qual" strikes me in an interesting way, in that it could be > thought to represent either "qualifier" or "quality", and yet is > neither. Personally I'd prefer a full word, but neither def or elif are full words, so I doubt it _has_ to be, but I'd prefer something relevant to what is happening behind the scenes rather than something ambiguous :) > Or if "lambda" is used, why not some other Greek letter, such as "mu" > or "sigma". Because they're not really meaningful beyond a small number of people? > This clearly represents some "thinking out loud". Ditto. One other thing that jumped out at me is that different syntaxes probably work better using different keywords. (Partly why I've snipped decorator syntaxes) Michael. -- Michael.Sparks at rd.bbc.co.uk British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From grante at visi.com Mon Aug 30 17:34:50 2004 From: grante at visi.com (Grant Edwards) Date: 30 Aug 2004 21:34:50 GMT Subject: "Content-Length" header References: Message-ID: <41339d7a$0$8090$a1866201@newsreader.visi.com> On 2004-08-30, Justin wrote: > URL open appears to not want to work unless its paramater is an actual > string spelled out in quotes. Nonsense. > Check out the output to this code. When I give urlopen > objects instead of pre strings it doens't work correctly. Bullshit. > print linklisttype > > for y in linklisttype: > temp = urlopen(y) > print temp > temp2 = temp.info() > print temp2 > temp3 = temp2.getheader("Content-Length") > print temp3 > file_sizes.append(temp3) > > print file_sizes Again with the invalid snippets of code, eh? You're trying awfully hard to avoid getting helped. > #here are the return values for y =0, didn't work WTH is "y"? > [None, None, '297984'] Those look like correct results to me. I'll tell you _one_more_time_: use Ethereal. Here's the transaction for your first URL: GET /~harnad/temp/ariadne-rae.doc HTTP/1.0 Host: www.ecs.soton.ac.uk User-agent: Python-urllib/1.15 HTTP/1.1 404 Not Found Date: Mon, 30 Aug 2004 21:27:42 GMT Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12 OpenSSL/0.9.6b DAV/1.0.3 PHP/4.3.2 mod_perl/1.26 Connection: close Content-Type: text/html; charset=iso-8859-1 404 Not Found

    Not Found

    The requested URL /~harnad/temp/ariadne-rae.doc was not found on this server.


    Apache/1.3.27 Server at www.ecs.soton.ac.uk Port 80
    THERE IS NO CONTENT-LENGTH HEADER. What do you expect urllib to do? The second of your URLs is also a 404 error with no Content-length header. The third URL is valid and does return a content-length header: GET /systech/techsupport/procedures/2kcleanup.doc HTTP/1.0 Host: www-admn.csun.edu User-agent: Python-urllib/1.15 HTTP/1.1 200 OK Server: NetWare-Enterprise-Web-Server/5.1 Date: Mon, 30 Aug 2004 21:27:43 GMT Content-type: application/msword Last-modified: Tue, 30 Apr 2002 22:50:08 GMT Content-length: 297984 Accept-ranges: bytes Connection: close [binary crap elided] -- Grant Edwards grante Yow! Could I have a drug at overdose? visi.com From peter at engcorp.com Tue Aug 17 12:12:40 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 17 Aug 2004 12:12:40 -0400 Subject: Problem In-Reply-To: <81a41dd.0408170543.3eab590a@posting.google.com> References: <81a41dd.0408170543.3eab590a@posting.google.com> Message-ID: Lad wrote: > I have only one, > the following line in my program > > from _winreg import * > > When I run it from PythonWin program( under windows) > it works normally. > > But when I try to run it from command line ( console) like > python MyProgram.py > I will get the error > > from _winreg import * > ImportError: DLL load failed: The specified module could not be found. Can you cut and paste into another posting the full traceback, including the command you actually used to run the program? -Peter From porky_pig_jr at my-deja.com Sat Aug 14 18:09:00 2004 From: porky_pig_jr at my-deja.com (Porky Pig Jr) Date: 14 Aug 2004 15:09:00 -0700 Subject: decorators: what's wrong with 'def [decorator-list] function-name (arguments)' Message-ID: <56cfb0e3.0408141409.239bb893@posting.google.com> Lurking on this site, watching the discussion on decorators. Personally I like them inside the list. There were some arguments made that having the list before 'def', such as [static schmatic] def f1(): pass is bad because it breaks many things. But I can't find any references to what's wrong with def [static schmatic] f1(): pass Yes, it pushes the function name further from 'def', but then we don't need to use those abominable @@@@@. Any comments? TIA. From davids at webmaster.com Sun Aug 29 21:13:55 2004 From: davids at webmaster.com (David Schwartz) Date: Sun, 29 Aug 2004 18:13:55 -0700 Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4dyXc.25792$Ot3.22106@twister.nyc.rr.com> <878yc0ucyl.fsf@thalassa.informatimago.com> <20040827135423.154$1T@newsreader.com> Message-ID: "Ian Wilson" wrote in message news:cgq7ki$eg1$1 at hercules.btinternet.com... >>>> I don't follow you at all. I think you'll find the most useful, >>>>meaningful complaints about, say, a Ford Explorer from the people who >>>>drive one every day. >>>And if they continue to drive one everyday, perhaps you would conclude >>>that their complaints are insincere. >> That's a load of crap. > You're both right but ... > > Xah Lee: "I'm starting my own cult to exterminate morons on > this earth. Two things are on the top of my agenda: Unixism and Perl." > > Pascal Bourguignon: > > Is more like > > Joe Blow: I'm going to exterminate all morons who drive a Ford Explorer. > > Fred Bloggs: But Joe, you drive a Ford Explorer! The you're missing is that 'unixism' has nothing to do with *using* UNIX. > Rather than > > Joe Blow: Ford Explorers are a little bit expensive to service and the > doors squeak after a couple of years. > > Fred Bloggs: Thanks for the tip Joe, I see you drive one, so you should > know. The problem with 'unixism' is its affect on UNIX, and it would be logical that only those people who use UNIXes are affected by 'unixism' and concerned about it. DS From tim.peters at gmail.com Sun Aug 15 15:49:45 2004 From: tim.peters at gmail.com (Tim Peters) Date: Sun, 15 Aug 2004 15:49:45 -0400 Subject: Trouble with file.seek/file.tell on Win32? In-Reply-To: <16671.45400.965715.943437@enthought.hathway.com> References: <16671.45400.965715.943437@enthought.hathway.com> Message-ID: <1f7befae04081512496c6f2727@mail.gmail.com> [Prabhu Ramachandran] > I noticed peculiar behavior under Python-2.3.4 under Win32. When I > run something like this: > > f = open('t.txt', 'wb') > f.write('1\012'+'2\012'+'3\012') > f.close() > f = open('t.txt', 'r') Sorry, you're in trouble already. You can *tell* Windows that's a text file, but it doesn't contain native Windows text-file data (it has the wrong kind of line end for Windows). > f.readline() > pos = f.tell() > val = f.read(1) > f.seek(pos) > assert val == f.read(1) > > I get an assertion error at this point. Everything works fine if I > read the file with 'rb' instead of 'r'. Yes, then you're not lying to Windows about the kind of data it contains. > But I can almost swear that this used to work earlier. I suspect that > this behavior arises due to recent changes in fileobject.c (specifically, > v2.187) where universal newline support was removed. Nope. > Could someone please clarify if this is this a bug or not? I would > like to think that using tell and seek should work reliably enough for > text files. They do, provided they really are text files. Let's add more output to your program: f = open('t.txt', 'wb') if 1: f.write('1\012'+'2\012'+'3\012') else: f.write('1\r\n'+'2\r\n'+'3\r\n') f.close() f = open('t.txt', 'r') f.readline() pos = f.tell() print 'pos', pos val = f.read(1) print 'read', repr(val) f.seek(pos) val2 = f.read(1) print 'read', repr(val2) That displays this when I run it on Windows: pos 0 read '2' read '1' Now here's a C program on Windows: #include void main() { char buf[100]; long pos; FILE *f = fopen("t.txt", "wb"); fputs("1\n2\n3\n", f); fclose(f); f = fopen("t.txt", "r"); fgets(buf, sizeof(buf), f); pos = ftell(f); printf("pos %ld\n", pos); fread(buf, 1, 1, f); printf("read '%c'\n", buf[0]); fseek(f, pos, 0); fread(buf, 1, 1, f); printf("read '%c'\n", buf[0]); } And here's what that displays: pos 0 read '2' read '1' Same thing: the Python program has exactly the same behavior as the C program. If you change "if 1" to "if 0" in my rewritten version, it creates a legitimate Windows text file instead, and then the output changes: pos 3 read '2' read '2' Same thing if the C program is changed similarly. > The reason this is important for me is that I've been generating text > files (with gay abandon) for MayaVi (http://mayavi.sf.net) for three > years now. I always open the file using 'r'/'w' and not 'rb'/'wb'. > Everything used to work fine. I think you must be confusing something. Your program had the same behavior in 2.2.3 on Windows too, which is the oldest Python I have handy. It could have appeared to work by accident in some cases, though. ... > p.s. Please CC me in on replies. I'm not tracking c.l.py. Thanks. OK, done. From aleaxit at yahoo.com Sat Aug 28 07:18:34 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 28 Aug 2004 13:18:34 +0200 Subject: Question about references/copies References: Message-ID: <1gj8afj.rcaoglblmqwjN%aleaxit@yahoo.com> Terry Reedy wrote: > "Henning Kage" wrote in message > news:pan.2004.08.28.07.52.35.422774 at gmx.de... > > I'm using Python only for some months now and I'm wondering, whether such > > assignments as above are creating bitwise copies of an object or just > > recieve a reference. That means I wanted to know, wheter Python in > > general > > differs between references and copies: > > Better to think of Python this way: it has objects and bindings of objects > to one or more targets (names and slots of composite objects). Binding > statements (target = expression) always and only assign targets to objects. Yes, the binding per se never does anything more, if it is to a bare name (if it's to an indexing, a slicing, or an attribute reference aka a dotted name, things can become more interesting sometimes). And normally the expression itself makes no copies unless copies are specifically requested in it. Slicing though is the interesting part. Slicing always creates a new object (except that whole-object slicing of an immutable sliceable need not). But the interesting issue is with the TARGETS, the SLOTS, inside that new object. Are they the SAME slots as in the object being sliced? If said object is a list or instance of array.array -- no, the slots are new and separate ones. E.g., consider: >>> z = [] >>> a = [ z, z, 23 ] >>> sys.getrefcount(z) 4 >>> b = a[:] >>> sys.getrefcount(z) 6 Here, slicing does create three new slots, two of which are additional references to the same list object z refers to. However: >>> z = [] >>> a = Numeric.zeros((3,), 'O') >>> a[0]=a[1]=z >>> sys.getrefcount(z) 4 >>> b = a[:] >>> sys.getrefcount(z) 4 Here, slicing "shares" the SAME slots that 'a' already had, so there is no change in the reference count of the list object z refers to. Alex From rnd at onego.ru Thu Aug 19 00:09:49 2004 From: rnd at onego.ru (Roman Suzi) Date: Thu, 19 Aug 2004 08:09:49 +0400 (MSD) Subject: introspection? In-Reply-To: References: Message-ID: On Wed, 18 Aug 2004, Jim Benson wrote: I am using different approach to introspection of Python functions and methods (not all available info output, only name of the previously called function/method). I am not sure if this is better than getting sys._getframe() or not, at least it doesn't use undescore methods ;-) and "knowns" about all invocation history at once, could even show source code, etc. import traceback def Introspec(msg): print traceback.extract_stack()[-2][2] + ":", msg class AAA: def foo(self): Introspec("i'm running") def a(x): Introspec('i am running') aaa = AAA() aaa.foo() def b(x): Introspec('I am running') a(x) b(10) >On Wed, 18 Aug 2004, Troy Melhase wrote: > >> import sys >> def F(): >> print sys._getframe().f_code.co_name >> >>> F() >> F > >ooooh...thanks Troy! >indeed that works fine for getting the method name. > >Thanks to all...and apologies for taking the easy way out >by posting to this very helpful list rather than >doing more research with google (actually i did >do a search for 'python class method introspection' >before posting...i didn't look at all the returns). > >Thanks, > >Jim > > > > > Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3 From merlyn at stonehenge.com Thu Aug 26 11:57:51 2004 From: merlyn at stonehenge.com (Randal L. Schwartz) Date: 26 Aug 2004 08:57:51 -0700 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <776e0325.0408260433.449660c8@posting.google.com> <412dfc1c$0$65599$a1866201@newsreader.visi.com> Message-ID: <86hdqpriww.fsf@blue.stonehenge.com> *** post for FREE via your newsreader at post.newsfeed.com *** >>>>> "Grant" == Grant Edwards writes: Grant> "Guido said it, that settles it, but we're going to discuss Grant> it endlessly and and vote on it using six or seven Grant> different voting algorithms anyway. Then we'll argue about Grant> the voting algorithms." Are the voting algorithms indented consistently? That's a necessity, correct? Surely, they have significant whitespace. /me ducks back under his rock -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -----= Posted via Newsfeed.Com, Uncensored Usenet News =----- http://www.newsfeed.com - The #1 Newsgroup Service in the World! -----== 100,000 Groups! - 19 Servers! - Unlimited Download! =----- From flory at fdu.edu Sun Aug 15 19:23:37 2004 From: flory at fdu.edu (flory at fdu.edu) Date: Sun, 15 Aug 2004 19:23:37 -0400 Subject: pyRegistry AttributeError Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I just downloaded pyRegistry (the 2004-08-11 binary update, v1.0.3) and am having a problem. My test code is: =============== import pyRegistry baseKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes" basereg = pyRegistry.open(baseKey) print basereg.getValueNames() print basereg.getKeyNames() ============ Which returns ================= D:\bin>test_pyRegistry ('Drop Shadow', 'Flat Menus', 'SetupVersion', 'InstallTheme', 'InstallVisualStyle') Traceback (most recent call last): File "D:\bin\test_pyRegistry.py", line 5, in ? print basereg.getKeyNames() AttributeError: getKeyNames ============ It appears as though open() and getValueNames() both work fine while getKeyNames throws an error. I am running Python 2.3.4 on a WinXP machine. Any suggestions as to what I am doing wrong? Or, might there be a problem with pyRegistry? In advance, many thanks for any help. - -------------------------------------------------- David Flory -----BEGIN PGP SIGNATURE----- Version: PGP 8.1 Comment: 201-692-7064 iQA/AwUBQR/wMVe2/rcN3lp8EQKWOwCeKsHRzQ7Ag8Byt2lMf/bCIXExQKMAn3TI JM57jHKr1UKhDUZi83pF3RrS =bn4W -----END PGP SIGNATURE----- From gregor.jan at NOSPAMquick.cz Sun Aug 22 12:21:22 2004 From: gregor.jan at NOSPAMquick.cz (Jan Gregor) Date: Sun, 22 Aug 2004 18:21:22 +0200 Subject: python a jdbc References: <2004082022464216807%webstuff@fluidiccom> Message-ID: Because many things - wxWindows (java binding is poor and java gui's aren't good enough), slow startup of jython (in development time) ... In article <2004082022464216807%webstuff at fluidiccom>, J wrote: > On 2004-08-15 12:33:14 -0400, Jan Gregor said: > >> Is there some to use jdbc driver with python ? I thought about >> communication between java process and python throught sockets. Simple >> test worked fine. >> >> Jan > > Why not use jython if it is a java app that you want a hook a python > interpeter into the application. > From mjackson at alumni.caltech.edu Fri Aug 20 11:36:06 2004 From: mjackson at alumni.caltech.edu (Mark Jackson) Date: 20 Aug 2004 15:36:06 GMT Subject: age of Python programmers References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: Reid Nichol writes: > Gerrit Muller wrote: > > and then a quantum leap towards Python. > You're aware that a quantum leap means a extremely small leap, right? Everything's relative - compared to the smallest possible change in the classical continuum, a quantum leap is *huge*. -- Mark Jackson - http://www.alumni.caltech.edu/~mjackson Fascism should more properly be called corporatism, since it is the merger of state and corporate power. - Benito Mussolini From psXdaXsilva at esotericaX.ptX Fri Aug 20 16:58:43 2004 From: psXdaXsilva at esotericaX.ptX (Paulo da Silva) Date: Fri, 20 Aug 2004 21:58:43 +0100 Subject: "Socket" files? Message-ID: <1093035812.83612@jubilee.esoterica.pt> How are those "files" of type "socket", whose name begins with "=", created? How can I create them with python? Thanks. From ruflicks at yahoo.fr Sat Aug 28 09:43:45 2004 From: ruflicks at yahoo.fr (ruflicks) Date: 28 Aug 2004 06:43:45 -0700 Subject: Zope help system, password needed in windows Message-ID: Hi all, i may be flamed but did not find anything on that. I have zope 2.7 running on windows 98 and I really like it. Problem is when i use the zope help system I am asked to give a login and password to get access to some sections (python scripts API reference and zope API reference). I tried my standard admin login but hey it didn't work with that one. I am a python and zope nubee so i was thinking it could help me reading that doc. I would really appreciate it if someone could tell me what i missed. Best regards. From m.boeren at guidance.nl Thu Aug 19 06:13:33 2004 From: m.boeren at guidance.nl (Marc Boeren) Date: Thu, 19 Aug 2004 12:13:33 +0200 Subject: age of Python programmers Message-ID: <0C77C7530EA52A4EBD1C47C80D1D291E07F9ED@sbs.GuidanceBV.local> >>> howoldami() 34 >>> bye() Marc Boeren From peter at engcorp.com Tue Aug 17 08:35:50 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 17 Aug 2004 08:35:50 -0400 Subject: How big can a Python program be? In-Reply-To: <903b3fba.0408170333.49ce3944@posting.google.com> References: <903b3fba.0408170333.49ce3944@posting.google.com> Message-ID: vronskij at post.sk wrote: > A C program can be hundreds of thousands lines of code big. > C++ millions. > > How about Python? > > Suppose , you are a sole programmer (lonewolf). How many lines can one handle? What are you actually asking? What technical limitations, such as maximum line count per module, Python might have? Or how productive the average programmer can be in terms of lines of Python code produced per day? Or something else entirely? Note that lines of code is a pretty poor measure of productivity, especially if you just use an average statistic, because it's hard to judge whether those lines are bug-free or bug-ridden, and because there is an extremely wide variation in productivity between different programmers (one oft-published ratio is 30:1). And more importantly than anything: why do you want to know such things? This information is critical to providing you with a useful answer. -Peter From nid_oizo at yahoo.com_removethe_ Mon Aug 23 08:31:17 2004 From: nid_oizo at yahoo.com_removethe_ (Nicolas Fleury) Date: Mon, 23 Aug 2004 08:31:17 -0400 Subject: J2 proposal: keyword In-Reply-To: References: Message-ID: Robert Brewer wrote: > I had an ugly paragraph promoting 'declare' as a top candidate, but I've > always liked 'using' (which many of you promoted within the past 24 > hours). Maybe the above will produce further polarization among you. ;) +1 for using. Nicolas From rogerb at rogerbinns.com Mon Aug 16 01:24:34 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Sun, 15 Aug 2004 22:24:34 -0700 Subject: Python secure? References: <411ffef6$0$65603$a1866201@newsreader.visi.com> Message-ID: Grant Edwards wrote: > I don't see how decompiling is a copyright violation. If I buy > a copy of a book, I'm pretty sure I can translate it into > another language if I want to form my own use. They need to use what they decompile for it to be a copyright violation. Additionally every proprietary software license I have seen forbids decompilation and reverse engineering. > In some places (Europe?) > reverse-engineering is explicitly allowed by law. Only for the purposes of interoperability, and only if there is no other way. It is Article 6 of directive 91/250. Note that not only can you only do it for interoperability reasons, you can only do so if the interoperability information is not available, and you can only do it on the parts needed for interoperability. http://europa.eu.int/ISPO/legal/en/ipr/software/text.html#HD_NM_6 The whole directive is contained in that page. You are not allowed to do the decompilation on anything just because you feel like it. I have seen software license agreements that also state you must contact the vendor legal department if you intend to exercise the rights from article 6 above. > What other laws? The laws broken would depend on what you did with the decompiled code. They would be different based on whether you just read it, made a modified copy of the program, sold the code, sold modified versions, revealed trade secrets etc. Roger From JimJJewett at yahoo.com Fri Aug 20 14:06:00 2004 From: JimJJewett at yahoo.com (Jim Jewett) Date: 20 Aug 2004 11:06:00 -0700 Subject: decorator J4 - any objections? Message-ID: Guido has said that he is open to considering *one* alternative decorator syntax. At the moment, (Phillip Eby's suggestion) J4 (section 5.21 J4) looks very good to me -- and it is the only alternative without negatives. def func(arg1, arg2) @version("Added in 2.4") @returns(None) as: """Docstring could be here, or in decorator part above""" # body goes here (Note the lack of colon on the func line; adding it would be more consistent and not hurt readability.) def func(arg1, arg2): @version("Added in 2.4") @returns(None) as: """Docstring could be here, or in decorator part above""" # body goes here While I think this is the best solution so far, I realize that others have often disagreed with me on this issue -- so I would appreciate some feedback, particularly from those who don't like the J4 syntax. Disclosure: I like decorators on their own, but they are enough of a special case that I worry about cluttering up the language as a whole. J4 seems the best compromise to me, but I could also make peace with Guido's current @proposal. -jJ From pm_mon at yahoo.com Thu Aug 26 19:51:22 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Thu, 26 Aug 2004 19:51:22 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Jess Austin wrote: > Paul Morrow wrote in message news:... > >>Currently, you can change a doc string outside of a function, by >>modifying the function's __doc__ attribute > > > [snip] > > >>IMO, to change it inside of a function def should be (but isn't) as easy >>as... >> >> >>> def foo(): >> ... """ I am foo """ >> ... __doc__ = __doc__ + 'indeed' > > > I'm not trying to be mean, but why not use a class for this? This is a contrived example; we probably wouldn't do this in practice. But some of us would like to do something like this def foo(): __features__ = synchronized, memoized ...so that the function foo get's some special abilities from the 'decorators' (or whatever we end up calling them) assigned to the __features__ attribute. But before anyone is really going to accept that way of specifying a function's decorators, they need to be convinced that it's ok to think of __features__ as an attribute of the function foo (i.e. foo metadata), rather than a local variable. > Paul: I admit I'm a bit confused by your > wanting a function to have access to its metadata, because I could > have sworn that earlier in the thread you defined metadata as data > about an object that that object would never use itself. I could be > thinking of someone else though... > Nope, that was me alright. I don't want a function to have access to it's metadata. Nothing's changed about that. I want to be able to specify a function's metadata inside the function def, where it seems to most appropriately belong. Others seem to want to specify a function's metadata outside of the function def, which just doesn't seem pythonic (IMO). From jzgoda at gazeta.usun.pl Wed Aug 18 15:25:18 2004 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Wed, 18 Aug 2004 19:25:18 +0000 (UTC) Subject: age of Python programmers References: Message-ID: Lucas Raab pisze: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... Now it's 33 and still ticks. -- Jarek Zgoda http://jpa.berlios.de/ From tim.peters at gmail.com Sun Aug 29 11:17:11 2004 From: tim.peters at gmail.com (Tim Peters) Date: Sun, 29 Aug 2004 11:17:11 -0400 Subject: Get all subdirs In-Reply-To: References: Message-ID: <1f7befae0408290817d66e14e@mail.gmail.com> [Florian Lindner] > how can I get all subdirectories of a given directory. os.listdir(dir) > doesn't differentiate between directories and files, os.walk seems to me a > bit overkill since it also descends in the subdirs. os.walk() is a generator -- it doesn't descend into anything unless you resume it. That's the usual case, but you don't need to resume it. def subdirs(dir): "Return list of the subdirectories of dir." for root, dirs, files in os.walk(dir): return dirs works fine, or, perhaps more obscurely, def subdirs(dir): "Return list of the subdirectories of dir." return os.walk(dir).next()[1] From rnichol_rrc at yahoo.com Mon Aug 9 13:51:39 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Mon, 09 Aug 2004 12:51:39 -0500 Subject: how many bytes in an int In-Reply-To: <41171D06.6060507@v.loewis.de> References: <9ACRc.1523$bJ2.9739@news1.mts.net> <4116f8ee$0$8076$a1866201@newsreader.visi.com> <41171D06.6060507@v.loewis.de> Message-ID: Martin v. L?wis wrote: > As Grant says: use the struct module. Use struct.calcsize to find out > how large an int is. If the size is too large, try a short. If the size > is too small, try a long. If no type matches, take the next larger type, > and drop the extra bytes. > > However, it does not actually need to be that difficult: "int" is 32-bit > on all current systems, including all 64-bit systems (only long is > 64-bits on some 64-bit systems). > > Regards, > Martin Thanks to all who helped. This is my solution (maybe overkill) but I plan on adding read/write functions, etc (of course its just a first thought). It seems to work, so any feedback is appreciated. #!/usr/bin/env python from struct import * class FixedSizeInteger: def __init__(self, length_in_bytes, endianness='@'): self.fmt = '' self.endianness = endianness # find the length_in_bytes byte datatype for type in ['h', 'i', 'l', 'q']: if length_in_bytes == calcsize(type): self.fmt = endianness + type # should throw an exception here if self.fmt == '': print 'ERROR: type not found' def printFmt(self): print 'My format is ' + self.fmt if __name__ == '__main__': test = FixedSizeInteger(4) test.printFmt() From DeadWisdom at wisefool.net Thu Aug 26 14:05:00 2004 From: DeadWisdom at wisefool.net (DeadWisdom) Date: 26 Aug 2004 11:05:00 -0700 Subject: Help needed: Transition from SAS to PYTHON References: Message-ID: "Alex Pavluck" wrote in message news:... > Hello. I am trying to teach myself PYTHON because I am interested in > programming. I use SAS all day and I really like the way you can > highlight code and submit just that section or submit the entire > program without having to save it. Can you do this in PYTHON? Also, > does PYTHON (Windows) log errors? It would be helpful when I am > writting a program and I submit the code and it says that their is an > error to know WHERE! Once again this is another feature of SAS. Have > I just gotten too used to SAS or are there others out there that would > also like to have this functionality?? > > Please help! > > Alex I'll do what I can to help... Basically you have to learn a different paradigm of programming if you are coming from SAS. SAS is designed specially designed for statistical analysis (although, and I speak of devils here, I have heard that it is used for data manipulation). Whereas Python is much more command driven. Now Python itself does not have this sort of highlight and submit functionality, but neither does SAS, rather this was part of the program you used to develop your SAS. Python however, is interpreted and interactive, which means that you don't have to save a program that you write; and, yes; the syntax checker and compiler will tell you were the errors are. This will make more sense once you begin to understand Python a bit better and have some experience with it. I'd suggest picking up a beginning Python book that is easier for people who are learning programming. Search the archives of this newsgroup and I'm sure you can find sundry recommendation on books. And download ActivePython (http://www.activestate.com/Products/ActivePython/), which is a very good beginning. From mwh at python.net Thu Aug 5 14:29:05 2004 From: mwh at python.net (Michael Hudson) Date: Thu, 5 Aug 2004 18:29:05 GMT Subject: psyco out of memory References: Message-ID: Ivan Voras writes: > I have this simple *dumb* benchmark-like program: > > #import psyco > #psyco.full() > > d = 0.0 > for i in xrange(1000000000): > d += i > print d > > I though I'd use it to try out psyco, but no, when I enable the first > two lines, python core-dumps: > > Fatal Python error: psyco: out of memory > Abort (core dumped) Hum. Are you using the ivm or the x86 backend? Also, you might have better luck just using range()... Cheers, mwh -- ... but I guess there are some things that are so gross you just have to forget, or it'll destroy something within you. perl is the first such thing I have known. -- Erik Naggum, comp.lang.lisp From justin__devine at hotmail.com Wed Aug 25 11:30:23 2004 From: justin__devine at hotmail.com (JDevine) Date: 25 Aug 2004 08:30:23 -0700 Subject: Desperately needing Help with 2 features of a program Message-ID: Hey. I posted a info about a program I have written that uses google to get and download files by type and site. I need HELP!!! This program is finished except for 2 features which, having tried for two weeks to create I cannot. This is my first program EVER. I simply an stuck. Please help. I was allowed by my employer to experiment with programing / open source. I'd like to be able to deliver a complete program, (so I can possibly do more of it soon). Here are the two features I need to consider this program complete. This program uses wxPython. 1. Update the label on a radiobox 2. Create a downlaod status progress bar. (I guess this has to be threaded, many attempts led to endless erros about not using the proper thread to interact with the GUI) Find Source at http://gobblewin.sourceforge.net OR http://sourceforge.net/project/showfiles.php?group_id=116574&package_id=128018 From iboisver at yahoo.com Mon Aug 30 03:10:12 2004 From: iboisver at yahoo.com (Ian Boisvert) Date: 30 Aug 2004 00:10:12 -0700 Subject: PyInstance_New in C++ class factory Message-ID: I'm trying to use PyInstance_New inside of a class factory to create instances of a class that is defined in Python. I first process some Python script that contains my class definition using the following code: PyObject *codeobj, *module = NULL; codeobj = Py_CompileString(cscript, "Python script", Py_file_input); if (codeobj != NULL) { module = PyImport_ExecCodeModule("Python script", codeobj); if (module == NULL) raiseError(); } Py_DECREF(module); Py_DECREF(codeobj); The call to PyImport_ExecCodeModule executes a module-scope method that passes a class object back to the C++ code. I hold on to the class object after incrementing it's reference count and later use it to create instances of the class using the following code: // create an instance of the class PyObject *instance = PyInstance_New(classObject, NULL, NULL); if (instance == NULL) raiseError(); where classObject is the class object that was passed from my Python code back to C++. The first time that PyInstance_New is called it works fine. The second time it is called, it fails. I debugged the code as far as to see that on the second call, the call to __init__ returns NULL, whereas on the first call __init__ returns Py_None. The exception message seems to be bogus as it mentions another method in the class that is never called. Any suggestions as to why the second call to PyInstance_New doesn't work would be much appreciated. Thanks. Ian. From fred at acme.com Tue Aug 24 21:05:34 2004 From: fred at acme.com (Fred) Date: Wed, 25 Aug 2004 03:05:34 +0200 Subject: Building basic dialog in Windows? References: <873ni0l3t2opc1bcaqf6vmuusr0sqah4pg@4ax.com> Message-ID: On Tue, 24 Aug 2004 20:49:29 +0200, Fred wrote: >OK, I'll check it out. It seems like pywin32 is meant for C++ >developers who are already proficient with MFC, and the only >documentation is pretty much the scripts that comes with the software, >but I'll try to figure it out and extract what I need. After comparing the scripts under \Demo, here's how to display a basic dialog in Windows with PythonWin/PyWin32, with a label, and two pushbuttons, OK/Cancel. When you click on OK, the text of the label changes, and the OK button is disabled: from pywin.mfc import dialog import win32con dlgStatic = 130 dlgButton = 128 class Mydialog(dialog.Dialog): def OnInitDialog(self): rc = dialog.Dialog.OnInitDialog(self) return rc def OnOK(self): label=self.GetDlgItem(dlgStatic) label.SetWindowText("Text changed") button=self.GetDlgItem(win32con.IDOK) button.EnableWindow(0) def OnCancel(self): self.Cancel = 1 self._obj_.OnCancel() style = (win32con.DS_MODALFRAME | win32con.WS_POPUP | win32con.WS_VISIBLE | win32con.WS_CAPTION | win32con.WS_SYSMENU | win32con.DS_SETFONT) cs = win32con.WS_CHILD | win32con.WS_VISIBLE s = win32con.WS_TABSTOP | cs w = 184 h = 40 dlg = [["PyWin32",(0, 0, w, h), style, None, (8, "MS Sans Serif")],] dlg.append([dlgStatic, "Click on OK", dlgStatic, (7, 5, 69, 9), cs | win32con.SS_LEFT]) dlg.append([dlgButton, "OK", win32con.IDOK, (7, 20, 50, 14), s | win32con.BS_DEFPUSHBUTTON]) s = win32con.BS_PUSHBUTTON | s dlg.append([dlgButton, "Cancel", win32con.IDCANCEL, (124, 20, 50, 14), s]) d = Mydialog(dlg) d.DoModal() My .15E/.20$ Fred. From roy at panix.com Fri Aug 13 11:11:02 2004 From: roy at panix.com (Roy Smith) Date: Fri, 13 Aug 2004 11:11:02 -0400 Subject: Difference between readlines() and iterating on a file object? References: <411cd102$1@mail.hmgcc.gov.uk> Message-ID: Christopher T King wrote: > Assuming you don't prematurely exit the for loop or access the file in > another manner while looping, both forms should give identical results. > Otherwise... Well, there is a corner case if some external process is writing to the file while you're reading it. The "in file.readlines():" version will get a snapshot of the file at the time you read it, while the "in file:" version will do a sequence of reads over time. Not that I think this is what's going on in the OP's case, but it's something to be aware of. From in.aqua.scribis at nl.invalid Fri Aug 27 10:12:35 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Fri, 27 Aug 2004 16:12:35 +0200 Subject: my first class: Args Message-ID: I'm still new to Python. All my experience with OO programming is in a distant past with C++. Now I have written my first class in Python. The class behaves exactly as I want, but I would like to get comments about coding style. I'm especially unsure about how a class should be documented, what to put in, and where. When to use double quotes, and when single. For instance, the doc string at the top must be in double quotes, or else the pydoc search engine won't find the description. Any recommendation for other mark-up or meta-data I should include? I won't tell you what the class is about, because that should be clear from code documentation. If not, I have work to do. Here it is: # -*- coding: iso-8859-1 -*- """ Handling of arguments: options, arguments, file(s) content iterator For small scripts that: - read some command line options - read some command line positional arguments - iterate over all lines of some files given on the command line, or stdin if none given - give usage message if positional arguments are missing - give usage message if input files are missing and stdin is not redirected """ __author__ = 'Peter Kleiweg' __version__ = '0.1' __date__ = '2004/08/27' import os, sys, getopt class Args: """ Instance data: progname (string) -- name of program opt (dictionary) -- options with values infile (string) -- name of current file being processed lineno (int) -- line number of last line read in current file linesum (int) -- total of lines read """ def __init__(self, usage='Usage: %(progname)s [opt...] [file...]') : "init, usage string: embed program name as %(progname)s" self.progname = os.path.basename(sys.argv[0]) self.opt = {} self.infile = None self.lineno = 0 self.linesum = 0 self._argv = sys.argv[1:] self._argc = len(self._argv) self._usage = usage % {'progname': self.progname} def __iter__(self): "iterator set-up" if self._argc == 0 and sys.stdin.isatty(): self.usage() if self._argc == 0: self.infile = '' self._stdin = 1 self._in = sys.stdin else: self.infile = self._argv.pop(0) self._argc -= 1 self._stdin = 0 self._in = open(self.infile, 'r') return self def next(self): "iterator next" line = self._in.readline() if line: self.lineno += 1 self.linesum += 1 return line self.lineno = -1 self.infile = None if self._stdin: raise StopIteration self._in.close() if self._argc < 1: raise StopIteration self.lineno = 0 self.infile = self._argv.pop(0) self._argc -= 1 self._in = open(self.infile, 'r') return self.next() def warning(self, text): "print warning message to stderr, possibly with filename and lineno" if self.lineno > 0: print >> sys.stderr, '%s:%i: warning: %s' % (self.infile, self.lineno, text) else: print >> sys.stderr, '\nWarning %s: %s\n' % (self.progname, text) def error(self, text): "print error message to stderr, possibly with filename and lineno, and exit" if self.lineno > 0: print >> sys.stderr, '%s:%i: %s' % (self.infile, self.lineno, text) else: print >> sys.stderr, '\nError %s: %s\n' % (self.progname, text) sys.exit(1) def usage(self): "print usage message" print >> sys.stderr, '\n' + self._usage + '\n' sys.exit(1) def shift(self): "pop first of remaining arguments (shift)" if self._argc < 1: self.usage() self._argc -= 1 return self._argv.pop(0) def pop(self): "pop last of remaining arguments" if self._argc < 1: self.usage() self._argc -= 1 return self._argv.pop() def getopt(self, shortopts, longopts=[]): "get options and merge into dict 'opt'" options, self._argv = getopt.getopt(self._argv, shortopts, longopts) self.opt.update(dict(options)) self._argc = len(self._argv) if __name__ == '__main__': a = Args('Usage: %(progname)s [-a value] [-b value] [-c] word [file...]') a.opt['-a'] = 'option a' # set some default option values a.opt['-b'] = 'option b' # a.getopt('a:b:c') # get user supplied option values word = a.shift() # get the first of the remaining arguments # use a.pop() to get the last instead for line in a: # iterate over the contents of all remaining arguments (filenames) if a.lineno == 1: print 'starting new file:', a.infile a.warning(line.rstrip()) print 'Options:', a.opt print 'Word:', word print 'Total number of lines:', a.linesum print sys.argv # unchanged a.warning('warn 1') # print a warning a.error('error') # print an error message and exit a.warning('warn 2') # this won't show -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From ndeskins at ecn.purdue.edu Mon Aug 16 12:02:09 2004 From: ndeskins at ecn.purdue.edu (Aaron Deskins) Date: Mon, 16 Aug 2004 11:02:09 -0500 Subject: Newbie question about file input In-Reply-To: References: Message-ID: Thanks to all for the replies. I changed it and it works fine. Now my question- what is this convention on indentation? Should all indentations be 4 spaces in? Thanks again. Peter Hansen wrote: > > Small note: it would make your code more readable and thus > easier to comment on if you followed convention and used four > spaces for indentation. Your volunteer tutors thank you! :-) > -- Aaron Deskins Graduate Student Chemical Engineering Purdue University From Michael.J.Fromberger at Clothing.Dartmouth.EDU Tue Aug 24 15:15:30 2004 From: Michael.J.Fromberger at Clothing.Dartmouth.EDU (Michael J. Fromberger) Date: Tue, 24 Aug 2004 15:15:30 -0400 Subject: Printing date a file References: Message-ID: In article , Kory Wheatley wrote: > In Python how would you print the date in a file, I > have a logging program written in python and for each > new recorded added to the file, I would like to print > the > date, something like this below: > > 08/24/2004 or 08-24-2004 > import time print time.strftime("%m/%d/%Y or %m-%d-%Y") See also: http://www.python.org/doc/2.3.4/lib/module-time.html Cheers, -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From ktilton at nyc.rr.com Thu Aug 26 23:51:28 2004 From: ktilton at nyc.rr.com (Kenny Tilton) Date: Fri, 27 Aug 2004 03:51:28 GMT Subject: Xah Lee's Unixism In-Reply-To: <87hdqptl96.fsf_-_@thalassa.informatimago.com> References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> Message-ID: <4dyXc.25792$Ot3.22106@twister.nyc.rr.com> Pascal Bourguignon wrote: > otto.wyss at orpatec.ch (Otto Wyss) writes: > > >>Xah Lee wrote: >> >> >>>this earth. Two things are on the top of my agenda: Unixism and Perl. >>> >> >>What you mean with Unixism? > > > It's always funny to observe people's contradictions: > > > Last week i bought a chain saw with a > twisted handle. Perhaps i wasn't > careful, but by accident it chopped one > of my arm off, then i thought to myself > "gosh, this is POWERFUL!". This seems to > be the fashionable mode of thinking > among the unixers or unixer-to-be, who > would equate power and flexibility with > rawness and complexity; disciplined by > repeated accidents. Such a tool would > first chop off the user's brain, molding > a mass of brainless imbeciles and > microcephalic charlatans the likes of > Larry Wall and Linus Torvald jolly > asses. --Xah Lee > > > $ telnet xahlee.org 80; > Trying 208.186.130.4... > Connected to xahlee.org. > Escape character is '^]'. > GET / HTTP/1.1 > > HTTP/1.1 400 Bad Request > Date: Fri, 27 Aug 2004 01:35:52 GMT > Server: Apache/2.0.50 (Fedora) > ^^^^^^^^^^^^^^^^^^^^^^ So you like my approach, which is to condemn things they have never used? :) kenny -- Cells? Cello? Celtik?: http://www.common-lisp.net/project/cells/ Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film From drconrad at metaplay.com.au Thu Aug 12 04:58:41 2004 From: drconrad at metaplay.com.au (Simon Wittber) Date: Thu, 12 Aug 2004 16:58:41 +0800 Subject: {SPAM?} Decorators? Why have a special construct to support a pattern? In-Reply-To: <2WFSc.12148$Nl1.3243@fe1.columbus.rr.com> Message-ID: <200408120846.i7C8kirv006828@redpill.digitalventures.com.au> Decorators... Why do we need a special construct to support a pattern? Do lots of people really use decorators that often? Sw. From jzgoda at gazeta.usun.pl Wed Aug 18 18:52:22 2004 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Wed, 18 Aug 2004 22:52:22 +0000 (UTC) Subject: age of Python programmers References: Message-ID: Aahz pisze: >>I'm also optimistic about retiring with Python, because *everyone* is >>going to retire with Python in 2044 :-). > > 2038 2036 -- Jarek Zgoda http://jpa.berlios.de/ From davidf at sjsoft.com Fri Aug 6 07:18:38 2004 From: davidf at sjsoft.com (David Fraser) Date: Fri, 06 Aug 2004 13:18:38 +0200 Subject: advice for perl expert wanting to learn python In-Reply-To: References: Message-ID: Zeljko Vrba wrote: > Now, why would I like to learn Python: because of IronPython port to CLR. > Perl port to CLR doesn't seem to be coming soon. First Perl6 for Parrot has > to be written, and then other backends.. > > What's the easiest way of learning python knowing perl? Is there somewhere > a 'how-to' cookbook with parallel examples of frequent idioms in perl and > python? > > And most important thing, how does Python deal with database connectivity? > Is there a single API (akin to DBI) for connecting to databases? > > How does Python support the following databases: > - Oracle > - Postgres > - MySQL > - SQLServer (maybe using freetds?) > - ODBC connectivity (connecting to MS Access) > I have used Oracle, SQLServer and Access via ADO - try adodpapi.sf.net which is a wrapper for ADO to the Python DB-API. But note that you may well not be able to use any of this database stuff from IronPython David From http Tue Aug 24 23:03:57 2004 From: http (Paul Rubin) Date: 24 Aug 2004 20:03:57 -0700 Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? References: Message-ID: <7xvff79aw2.fsf@ruckus.brouhaha.com> Anthony Baxter writes: > 'dec' is also going to clash with a lot of code that uses that. That's going > to be a problem with pretty much any short keyword. I really am liking J2 less and less. Even @pie seems more natural. The best in my opinion is still J4 with no keyword. From godoy at ieee.org Wed Aug 18 16:26:19 2004 From: godoy at ieee.org (Jorge Godoy) Date: Wed, 18 Aug 2004 17:26:19 -0300 Subject: age of Python programmers References: Message-ID: Christos "TZOTZIOY" Georgiou writes: > On Wed, 18 Aug 2004 08:34:08 -0400, rumours say that Jeremy Jones > might have written: > >>Is this a marketing survey? >> >>age: 31 >>marital status: married - have 1 wife >>parental status: 2 children >>canine status: have 1 dog >>feline status: 1 cat >>employment status: (very) thankfully have a (good) job >>automobile status: 2 cars >>sanity status: nearly none > > You forgot to give us address and credit card details. Thanks in > advance for your reply. To save time, we also accept your computer's login and password. We can get all the details needed without bothering you. ;-) -- Godoy. From fumanchu at amor.org Wed Aug 18 01:36:56 2004 From: fumanchu at amor.org (Robert Brewer) Date: Tue, 17 Aug 2004 22:36:56 -0700 Subject: Finding all time periods for a given interval within a daterange Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E06@exchange.hqamor.amorhq.net> Tim Churches wrote: > > > On Thu, 2004-08-05 at 03:09, Robert Brewer wrote: > > > > Look at my 'recur' module and see if it fits your requirements: > > > > > > > > http://www.aminus.org/rbre/python/index.html > > > > > > > > Start with the Recurrence class and play with it--then dig > > > deeper if you > > > > need to. > > > > > > Robert, > > > > > > How is the above code licensed? > > > > Anything on that page is public domain. Use it as you see fit. > > Would you be so kind as it include a note in teh actual code > to that effect? Copyright > needs to be explicitly waived in most countries these days > (unlike previously when > copyright needed to be explicitly claimed). Tim (and anyone else who cares), Finally got around to it. All code on that page has now been placed in the public domain. HTH, Robert Brewer MIS Amor Ministries fumanchu at amor.org From squirrel at WPI.EDU Fri Aug 6 12:41:36 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Fri, 6 Aug 2004 12:41:36 -0400 Subject: Finding a function name In-Reply-To: References: <788E231C269961418F38D3E360D1652526CA1E@tndefr-ws00021.tenovis.corp.lan> Message-ID: On Fri, 6 Aug 2004, Tim Williams wrote: > How can I find a function's name from within the function? You can't (yet), in a top-level function at least. In an object's method, you can do this: class a(object): def foo(self): print self.foo.__name__ But that requires you to know the function's name to begin with ;) Going off on a tangent, this is a case where some sort of reverse function attributes would be of help: def foo(a,b,c): .someattr = "something" # <-- proposed function attribute, # assigned at compile time print .someattr, .__name__ # <-- proposed reverse function attribute, # accessed at runtime But right now there's no such thing in Python. From squirrel at WPI.EDU Mon Aug 16 10:46:57 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Mon, 16 Aug 2004 10:46:57 -0400 Subject: Flython In-Reply-To: References: Message-ID: On Mon, 16 Aug 2004, Michael Hudson wrote: > Christopher T King writes: > > > (Unfortunately, AST trees don't match up exactly with Python grammar, so > > I'm having to learn the format by trial-and-error. Not much fun. Is > > there documentation on the AST forms anywhere?) > > Which AST are you talking about? Whatever is spit out by parser.suite(). Things like grammar.txt's "statement" being represented symbol.stmt, and grammar.txt's stmt_list not existing at all in the AST trees (though most/all of the other _lists exist). > Which version of Python, etc? 2.3. I'm using http://docs.python.org/ref/grammar.txt as my grammar reference. > However, the answer to the "documentation" plea is probably "no". :( Is there at least some rationale why the AST trees don't match the grammar definitions? From peter at engcorp.com Mon Aug 16 12:33:54 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 12:33:54 -0400 Subject: Newbie question about file input In-Reply-To: References: Message-ID: Elcio Ferreira wrote: >>while 1: >> line = zf.readline() >> if not line: >> break > > > Newbie's question: > > Isn't it a strange way to do a loop? Create a loop with a foo > condition and use an if to break it? It's a little unusual compared to many other languages, but Python often tries to have only one obvious way to do something. Other languages have two or three or even more different ways to do 'while' style loops, while Python has only one. The downside, if you want to think of it as such, is that idioms like the above can seem a little "off". On the other hand, perhaps once you've coded Python for a while you will start to feel that the above is quite straightforward and flows from your fingers pretty easily, because you don't have to stop and think of _which_ of the available loops you should use. > ===== > line=zf.readline() > while line: > . . . > line=zf.readline() > ===== > > Isn't this code much more easy to understand? Perhaps... but less maintainable. Duplication is almost always a bad thing in programming, and the above is prone to various kinds of errors, especially if you or someone else goes back to change the code in the future. It is possible with Python to restructure things like the above to be both readable and maintainable, either by using classes or, more recently, with generators: def readlines(f): while 1: line = f.readline() if not line: break yield line then in the rest of your code you can just do this: for line in readlines(zf): # do something with line... Of course, the "file" object now allows this natively, so you don't even have to write the above, but the point is that if you don't like the "while 1:/test/break" idiom, there are alternatives. -Peter From reinhold-birkenfeld-nospam at wolke7.net Fri Aug 20 14:03:06 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Fri, 20 Aug 2004 20:03:06 +0200 Subject: Decorator keyword options - brainstorming In-Reply-To: References: Message-ID: <2omsj9Fcej95U1@uni-berlin.de> David Vaughan wrote: > Paul McGuire wrote: >> I'd say that something like "gerbil" should be right out! > > I don't know - it sounds fun. I vote: > > SpanishInquisition: > staticmethod > def foo(): > pass > > The guys at python-dev won't be expecting that one :) > But seriously, there must be something literally pythonic we could > propose. How about pythonic: staticmethod def foo(): pass ? Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From beliavsky at aol.com Wed Aug 4 08:47:18 2004 From: beliavsky at aol.com (beliavsky at aol.com) Date: 4 Aug 2004 05:47:18 -0700 Subject: Can somebody help me ? References: <9f6a3388.0408031923.11cfa62d@posting.google.com> Message-ID: <3064b51d.0408040447.767016f4@posting.google.com> patrick.schaeffler at siemens.com (Patrick) wrote in message news:<9f6a3388.0408031923.11cfa62d at posting.google.com>... > Hi, > > I managed to open a msaccess database with python. You can help us by using an informative title such as "Open MSAccess with Python?" instead of the generic "Can somebody help me?" From DesertLinux at netscape.net Sat Aug 21 09:49:57 2004 From: DesertLinux at netscape.net (Byron) Date: Sat, 21 Aug 2004 13:49:57 GMT Subject: Files in unix and windows In-Reply-To: <1pIVc.8678$3O3.1751@newsread2.news.pas.earthlink.net> References: <1pIVc.8678$3O3.1751@newsread2.news.pas.earthlink.net> Message-ID: <9qIVc.8680$3O3.3996@newsread2.news.pas.earthlink.net> Opps, correction. "\t" is for -- I had the slash going the wrong direction. Byron --- Byron wrote: > Hi Travis, > > You want to use forward slashes with your file names. Backslashes are > used for special character commands, such as "/t" for , etc. > > For Windows: > c:/aFolder/testDocument.txt > > For Unix / Linux > /aFolder/testDocument.txt > > If you need a relative path, with no drive specified (for Windows), > use: > /aFolder/testDocument.txt > > Hope this helps, > > Byron > --- > > > Travis James Kleeburg wrote: > >> I am trying to copy files from one directory into another using >> shutil.copy. I am having a problem getting a usable path using >> os.path.abspath because it doesnt return a string with the extra >> backslashes and i was wondering if there was a better system call to >> use? I am also looking for a system call so there wont be a problem >> between windows and unix. >> >> From skip at pobox.com Fri Aug 20 00:42:52 2004 From: skip at pobox.com (Skip Montanaro) Date: Thu, 19 Aug 2004 23:42:52 -0500 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: <16677.33100.737566.729771@montanaro.dyndns.org> Paul> I would propose a multivote survey: each poster gets 3 votes among Paul> the lettered choices on the Wiki page above. You can use all 3 Paul> for a single option, or split them across 2 or 3 options if you Paul> are open to more than one. C1 C1 J2 Skip From Scott.Daniels at Acm.Org Sat Aug 28 14:25:36 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 28 Aug 2004 11:25:36 -0700 Subject: my first class: Args In-Reply-To: References: Message-ID: <4130cf9d@nntp0.pdx.net> Peter Kleiweg wrote: > I'm still new to Python. All my experience with OO programming > is in a distant past with C++. Now I have written my first class > in Python. The class behaves exactly as I want, but I would like > to get comments about coding style. I like: "look at a coding standard (PEP 8), then vary for clarity." > ... when to use double quotes, and when single. I generally prefer single a lot of places since typefaces sometimes make it hard to tell the difference between a pair of singles and a double. Here is a lot of blue pencil. Don't consider that a rip of your code. Don't consider me correct, see each change and decide for yourself which way is clearer. One thing I use here several places is the "try and fail, don't ask permission" -- a pythonic style. > I won't tell you what the class is about, Ah, but everyone has a context in which they read code. > """ > Handling of arguments: options, arguments, file(s) content iterator ^^ Try "Demonstrate use of arguments..." (a verb helps). ... > class Args: > """ ^^ Here put a line about what the class is about: Source provision for numbered lines with (possibly) multiple inputs. ... > self._argv = sys.argv[1:] > self._argc = len(self._argv) ^^ I'd forego _argc altogether and use len(self._argv) where needed. > self._usage = usage % {'progname': self.progname} ^^ I'd wait to do this in the usage method -- no need for it normally self._usage = usage > def __iter__(self): > "iterator set-up" ^^ useless docstring -- presume the reader knows python > if self._argc == 0 and sys.stdin.isatty(): > self.usage() > if self._argc == 0: > self.infile = '' > self._stdin = 1 > self._in = sys.stdin > else: > self.infile = self._argv.pop(0) > self._argc -= 1 > self._stdin = 0 > self._in = open(self.infile, 'r') > return self ^^ try: self.infile = self._argv.pop(0) except IndexError: if sys.stdin.isatty(): self.usage() # Doesn't return else: self.infile = '' self._stdin = True self._in = sys.stdin else: self._stdin = False self._in = open(self.infile, 'r') return self > > def next(self): > "iterator next" ^^ again -- skip the comment unless you say more than the language does. Maybe: "get another line, possibly going to another file for it" > line = self._in.readline() > if line: > self.lineno += 1 > self.linesum += 1 > return line > self.lineno = -1 > self.infile = None > if self._stdin: > raise StopIteration > self._in.close() > if self._argc < 1: > raise StopIteration > self.lineno = 0 > self.infile = self._argv.pop(0) > self._argc -= 1 > self._in = open(self.infile, 'r') > return self.next() ^^ Loop rather than recur unless you have a good reason. while True: line = self._in.readline() if line: self.lineno += 1 self.linesum += 1 return line # Look for a source of more lines if self._stdin: assert not self._argv # stdin is not part of a list break self._in.close() try: self.infile = self._argv.pop(0) except IndexError: break # No more files self.lineno = 0 self._in = open(self.infile, 'r') self.lineno = -1 self.infile = None raise StopIteration > > def warning(self, text): > "print warning message to stderr, possibly with filename and lineno" > if self.lineno > 0: > print >> sys.stderr, '%s:%i: warning: %s' % (self.infile, self.lineno, text) > else: > print >> sys.stderr, '\nWarning %s: %s\n' % (self.progname, text) > ^^ these lines look a bit long. Consider: if self.lineno > 0: print >>sys.stderr, '%s:%i: warning: %s' % ( self.infile, self.lineno, text) else: print >>sys.stderr, '\nWarning %s: %s\n' % ( self.progname, text) or even consider: def error(self, text, fatal=True): if fatal: style = 'Error' else: style = 'Warning' if self.lineno > 0: print >>sys.stderr, '%s:%i: %s:' % ( self.infile, self.lineno, style), else: print >>sys.stderr, '\n%s %s:' % (style, self.progname), print >>sys.stderr, text if fatal: sys.exit(1) # or even: raise SystemExit Where warnings look like: obj.error(msg, fatal=False) > def usage(self): > "print usage message" > print >> sys.stderr, '\n' + self._usage + '\n' > sys.exit(1) ^^ As mentioned above: def usage(self): "print usage message and leave" print >> sys.stderr, print >> sys.stderr, self._usage % {'progname': self.progname} print >> sys.stderr, sys.exit(1) > > def shift(self): > "pop first of remaining arguments (shift)" > if self._argc < 1: > self.usage() > self._argc -= 1 > return self._argv.pop(0) ^^ becomes: def shift(self): "pop first of remaining arguments (shift)" try: return self._argv.pop(0) except IndexError: self.usage() > > def pop(self): > "pop last of remaining arguments" > if self._argc < 1: > self.usage() > self._argc -= 1 > return self._argv.pop() ^^ becomes: def pop(self): "pop last of remaining arguments" try: return self._argv.pop() except IndexError: self.usage() > def getopt(self, shortopts, longopts=[]): > "get options and merge into dict 'opt'" > options, self._argv = getopt.getopt(self._argv, shortopts, longopts) > self.opt.update(dict(options)) > self._argc = len(self._argv) ^^ As I've said, I'd drop this one > if __name__ == '__main__': > ... ^^ also nicer to be able to test from included version: def demo(): ... if __name__ == '__main__': demo() From johnfkeeling at yahoo.com Tue Aug 3 04:19:49 2004 From: johnfkeeling at yahoo.com (John Keeling) Date: 3 Aug 2004 01:19:49 -0700 Subject: Timing Difference: insert vs. append & reverse References: <35b736b9.0408020330.53b24ed3@posting.google.com> <35b736b9.0408021152.4c1ab752@posting.google.com> Message-ID: <35b736b9.0408030019.27f212d9@posting.google.com> It is so cool to be able to get the disassembly so easily.... thanks v. much Terry. Cheers, John > >>> import dis > >>> dis.dis(ldel) > 0 SET_LINENO 1 > > 3 SET_LINENO 2 > 6 LOAD_FAST 0 (lisp) > 9 LOAD_FAST 1 (index) > 12 DELETE_SUBSCR > 13 LOAD_CONST 0 (None) > 16 RETURN_VALUE From jjl at pobox.com Thu Aug 26 15:24:36 2004 From: jjl at pobox.com (John J. Lee) Date: 26 Aug 2004 20:24:36 +0100 Subject: waiting for html to load: a followup References: Message-ID: Josh writes: [...] > Anyway, I decided to forget IE and I am now trying to use urllib2 to > open up the page, read it, etc. My problem is the page has a built-in > refresh and I don't know how to have python re-read the page until > it's ready to hand over the links. > > An example of the page is: > http://edcw2ks23.cr.usgs.gov/Website/zipship/waiting.jsp?areaList=49.0,47.0,-122.0,-124.08&prodList=NED, Example, with some debugging turned on so you can see some of what's going on: import ClientCookie opener = ClientCookie.build_opener( ClientCookie.HTTPRefreshProcessor(max_time=None), ClientCookie.HTTPResponseDebugProcessor(), ClientCookie.HTTPRedirectDebugProcessor(), ) ClientCookie.getLogger("ClientCookie").setLevel(ClientCookie.DEBUG) r = opener.open('http://edcw2ks23.cr.usgs.gov/Website/zipship/waiting.jsp?areaList=49.0,47.0,-122.0,-124.08&prodList=NED,') f = open('out.html', 'w') f.write(r.read()) Don't mix ClientCookie and urllib2, BTW. John From otto.wyss at orpatec.ch Thu Aug 26 17:01:47 2004 From: otto.wyss at orpatec.ch (Otto Wyss) Date: Thu, 26 Aug 2004 23:01:47 +0200 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> Xah Lee wrote: > this earth. Two things are on the top of my agenda: Unixism and Perl. > What you mean with Unixism? O. Wyss -- How to enhance your code, see "http://freshmeat.net/projects/wxguide/" From steve at ferg.org Tue Aug 24 12:12:33 2004 From: steve at ferg.org (Stephen Ferg) Date: 24 Aug 2004 09:12:33 -0700 Subject: advice for perl expert wanting to learn python References: Message-ID: I'm surprised nobody mentioned Martin Brown's book "Perl to Python Migration". The reviews indicate that although it has a lot of typos it is useful. Also, cheap. You can get a used copy for $2.50 (plus shipping) from Amazon. http://www.amazon.com/exec/obidos/tg/detail/-/0201734885/qid=1093363660/sr=1-1/ref=sr_1_1/002-2726742-5722424?v=glance&s=books From heikowu at ceosg.de Tue Aug 10 08:34:39 2004 From: heikowu at ceosg.de (Heiko Wundram) Date: Tue, 10 Aug 2004 14:34:39 +0200 Subject: Multiple inheritance with a common base class In-Reply-To: <1092140345.2624.28.camel@dicaprio.akademie1.de> References: <1092137872.2624.16.camel@dicaprio.akademie1.de> <1092140345.2624.28.camel@dicaprio.akademie1.de> Message-ID: <200408101434.39622.heikowu@ceosg.de> Am Dienstag, 10. August 2004 14:19 schrieb Markus Bertheau: > ? ???, 10.08.2004, ? 13:37, Markus Bertheau ?????: > > Also I observe that the instance will in fact _not_ have a single copy > of the data attributes used by the common base class. The following > example demonstrates this: No, this example doesn't demonstrate this, rather, you can't read your code correctly... ;-) Let's look at the oder at which the commands are executed. class Multi(LeafA, LeafB): def __init__(self): LeafA.__init__(self) ---> Call into LeafA.__init__... class LeafA(CommonBase): def __init__(self): CommonBase.__init__(self) ---> Call into CommonBase.__init__ class CommonBase: def __init__(self): self.no = 0 ---> Set self.no to zero. print("CommonBase.no: %i" % self.no) ---> Print self.no (zero) CommonBase.setNo(self, 3) ---> Call into CommonBase.setNo class CommonBase: def setNo(self, no): self.no = no ---> Set self.no to three. LeafB.__init__(self) ---> Call into LeafB.__init__ class LeafB(CommonBase): def __init__(self): CommonBase.__init__(self) ---> Call into CommonBase.__init__ class CommonBase: def __init__(self): self.no = 0 ---> (Re)set self.no to zero. print("CommonBase.no: %i" % self.no) ---> Print self.no (zero) CommonBase.setNo(self, 4) ---> Call into CommonBase.setNo class CommonBase: def setNo(self, no): self.no = no ---> Set self.no to four Does this explain what is happening, and why multiple inheritence doesn't work as you expect it to (rather, you have to be real careful about it?). Heiko. From p_s_oberoi at hotmail.com Fri Aug 6 17:13:49 2004 From: p_s_oberoi at hotmail.com (Paramjit Oberoi) Date: Fri, 06 Aug 2004 16:13:49 -0500 Subject: Plotting histograms, scatter plots in Python References: Message-ID: > What is the easiest way to generate some plots and graphs in Python ? Pychart: http://www.hpl.hp.com/personal/Yasushi_Saito/pychart/ From lbates at swamisoft.com Thu Aug 19 12:41:17 2004 From: lbates at swamisoft.com (Larry Bates) Date: Thu, 19 Aug 2004 11:41:17 -0500 Subject: Merging pdf documents with Python References: Message-ID: ReportLab has a product (not free) called PageCatcher that provides this capability. I've used it in several projects and it works perfectly. HTH, Larry Bates Syscon, Inc. "Daryl Middleton" wrote in message news:mailman.1965.1092927979.5135.python-list at python.org... > Can python be used to merge pdf documents into a single pdf file so that I > do not have to manually insert each one. Thanks > From brianc at temple.edu Mon Aug 2 16:30:44 2004 From: brianc at temple.edu (brianc at temple.edu) Date: Mon, 2 Aug 2004 16:30:44 -0400 Subject: module timeit and variable scope Message-ID: >1. What are the advantages of using timeit compared to using >time.time() or time.clock()? (on Mac OS X) It's more accurate when timing very small bits of code. Though I don't know a thing about Max OS X. >2. How do I introduce a variable into the timeit.Timer? For example I >have a class Foo: Just create an instance in the setup portion of the Timer. t=timeit.Timer('foo.run()','from __main__ import Foo; foo=Foo()') To just test __init__ of your class: t=timeit.Timer('Foo()','from __main__ import Foo') Setup only runs once. -Brian ---- Original message ---- >Date: 2 Aug 2004 10:40:24 -0700 >From: fortepianissimo at gmail.com (fortepianissimo) >Subject: module timeit and variable scope >To: python-list at python.org > >A couple questions about using timeit to record the CPU time consumed >by an instance method: > > >2. How do I introduce a variable into the timeit.Timer? For example I >have a class Foo: > >class Foo: > def __init__ (self): > # the following line didn't work because the scope is not > # the calling function > # self._timer = timeit.Timer(stmt='self.run(bar)') > pass > > def someMethod (self, bar): > print bar > > def run (self, bar): > # call self.someMethod(bar) and record time using > # self._timer > pass > > >and I want to record the CPU time consumed by someMethod in method >run(), using the timer initialized in __init__(). The reason to set up >the timer in __init__ is to avoid overhead of setting up the same >timer time and time again in run(). > >Thank you. >-- >http://mail.python.org/mailman/listinfo/python-list From opengeometry at yahoo.ca Sun Aug 1 03:16:03 2004 From: opengeometry at yahoo.ca (William Park) Date: 1 Aug 2004 07:16:03 GMT Subject: (patch for Bash) try-block and exception References: <2n27jlFsb5njU1@uni-berlin.de> <2n2bapFs3oqbU1@uni-berlin.de> Message-ID: <2n3jliFrvv9dU1@uni-berlin.de> In Harry Putnam wrote: > William Park writes: > > >> Ref: > >> http://freshmeat.net/projects/bashdiff/ > >> help try > >> help raise > > This link doesn't appear to lead to a `download' option.. It's two step dance. first, http://freshmeat.net/projects/bashdiff/ then, http://home.eol.ca/~parkw/index.html#bash (homepage) then, http://home.eol.ca/~parkw/bash.diff Next feature I'll tackle is list comprehension. :-) -- William Park, Open Geometry Consulting, Toronto, Ontario, Canada From martin at v.loewis.de Sun Aug 22 11:15:20 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 22 Aug 2004 17:15:20 +0200 Subject: unicodedata name for \u000a In-Reply-To: References: <412869bf$0$24814$9b622d9e@news.freenet.de> Message-ID: <4128B888.9010400@v.loewis.de> Tor Iver Wilhelmsen wrote: > Then why not return None or the empty string instead of raising an > exception? Why does a dictionary lookup raise a KeyError instead of returning None or an empty exception? It's easy enough to add a function that does what you want: def name(c): try: return unicodedata.name except ValueError: return None Python reports failures through exceptions, not through special return values. It might have been an option initially to return None. Now, it cannot be changed for backwards compatibility. Regards, Martin From bhoel at web.de Wed Aug 18 16:44:50 2004 From: bhoel at web.de (Berthold Höllmann) Date: Wed, 18 Aug 2004 22:44:50 +0200 Subject: age of Python programmers References: <2ohr0nFakl4sU1@uni-berlin.de> Message-ID: Cousin Stanley writes: > On 2004-08-18, Lucas Raab wrote: > > | One thing I've always kind of wondered is what is the average age > | of a Python programmer ?? > | > | What age groups use Python ?? > | > | Something to think about.... > >>>> import time >>>> >>>> tup_lt = time.localtime() >>>> >>>> now_yr = tup_lt[ 0 ] >>>> now_mo = tup_lt[ 1 ] >>>> now_da = tup_lt[ 2 ] >>>> >>>> dob_yr = 1946 >>>> dob_mo = 8 >>>> dob_da = 9 >>>> >>>> dy = now_yr - dob_yr >>>> dm = now_mo - dob_mo >>>> dd = now_da - dob_da >>>> >>>> print '\n %d Years .... %d Months .... %d Days .... Old \n' % ( dy , dm , dd ) > > 58 Years .... 0 Months .... 9 Days .... Old > For me it's ... >>> dob_yr = 1966 >>> dob_mo = 8 >>> dob_da = 18 ... >>> print '\n %d Years .... %d Months .... %d Days .... Old \n' % ( dy , dm , dd ) 38 Years .... 0 Months .... 0 Days .... Old >>> Programming since more than 20 Years. UCSD Pascal on Apple //e and //c, FORTRAN, C, C++ and Python since more than 76 Years. Regards Berthold -- bhoel at web.de / http://starship.python.net/crew/bhoel/ From richardshea at fastmail.fm Fri Aug 20 04:23:43 2004 From: richardshea at fastmail.fm (Richard Shea) Date: 20 Aug 2004 01:23:43 -0700 Subject: pyXLWriter - cancel previous question Message-ID: <282f826a.0408200023.2eef965a@posting.google.com> Hi - After I posted "pyXLWriter - simple example code ?" I wrote to Evgeny Filatov (the writer of pyXLWriter) and he has very kindly pointed me in the right direction for examples etc (the Win32.zip download of pyXLWriter doesn't have the example code which the other download does). So feel free to post your examples, I'd be interested to see them but I've got what I needed to get me started. regards richard. From dyoo at hkn.eecs.berkeley.edu Mon Aug 16 21:38:01 2004 From: dyoo at hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 17 Aug 2004 01:38:01 +0000 (UTC) Subject: Why I love python. References: <411C8CD9.32F39C2@mega-nerd.com> Message-ID: :> Python needs drastic performance improvement if it is to scrap-off the :> "scripting language" stigma. The only way to get these improvements is :> making it possible for a python implementation to produce *efficient* :> *compiled* code. At the same time the dynamic-typing nature of the :> language is one of its most valuable characteristics. And this is one :> of the hardest problems when trying to write a decent python :> compiler. If you define a function like: :> :> def sum (a, b): :> return a + b :> :> How can the compiler know what code to produce? : I know of at least one language which has solved this problem, Ocaml I'm not quite sure if this is true. In contrast to Python, a lot of the type information in OCaml is attached to the operators. This is to make the type-inferencing work efficiently. For example, OCaml's addition operator is hardcoded to work with integers: (******) [dyoo at shoebox dyoo]$ ocaml Objective Caml version 3.07+2 # (+) ;; - : int -> int -> int = (******) and there's a separate operator for adding floats to floats: (*** OCaml ***) # ( +. );; - : float -> float -> float = (******) Python's dynamic lookup of module-level symbols also make things more difficult than in Ocaml. In OCaml, names that are bound stay bound: (*** OCaml ***) # let x = 42;; # let say_x () = print_endline (string_of_int x);; val say_x : unit -> unit = # say_x ();; 42 - : unit = () # let x = "hello";; val x : string = "hello" # say_x ();; 42 - : unit = () (******) Note, again, that the OCaml operators and functions are often themselves typed to make type-inference work. This may make things slightly verbose again. I could be wrong, but I couldn't find a simple, generic, "print" function that could print any value in OCaml. In this example, the say_x function keeps a record of all the name bindings from before, which is why it remembers the original binding for 'x'. This is just fundamentally different from the "late binding" approach using in Python: ### Python ### >>> x = 42 >>> def say_x(): ... print x ... >>> say_x() 42 >>> x = "hello" >>> say_x() hello ### So I'm not so sure that Python's current design makes type-inference easy. I'm pretty sure it's a little harder than just yanking out OCaml's type-inference engine and jury-rigging it into Python. *grin* From follower at gmail.com Thu Aug 12 23:46:06 2004 From: follower at gmail.com (Follower) Date: 12 Aug 2004 20:46:06 -0700 Subject: Python script to generate static site? References: Message-ID: <3c18c08f.0408121946.2a92f827@posting.google.com> I like PubTal because it produces static pages from Zope Page Templates (ZPT), which I like as an approach: Recent versions have intelligent FTP upload too. ZPT has a learning curve, but is quite nice (and scalable upwards to a fully dynamic solution in future if you need that). --Phil. From aleaxit at yahoo.com Thu Aug 26 03:15:43 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 09:15:43 +0200 Subject: Python Cookbook Second Edition call for submissions Message-ID: <1gj4cc5.5fx9u41j5hkpeN%aleaxit@yahoo.com> Greetings, fellow Pythonistas! We (Alex Martelli, David Ascher and Anna Martelli Ravenscroft) are in the process of selecting recipes for the Second Edition of the Python Cookbook. Please contribute your recipes (code and discussion), along with comments on and ratings of existing recipes, to the cookbook site, http://aspn.activestate.com/ASPN/Cookbook/Python , and do it *now*! The Python Cookbook is a collaborative collection of your contributions to Python lore, with code available for use and review at http://aspn.activestate.com/ASPN/Cookbook/Python . ActiveState and O'Reilly Media provide resources to publish selected recipes from this collection -- selected, edited, and organized into chapters, each of which starts with an essay by an expert in the chapter's topic -- into a book titled (duh!) "Python Cookbook". The First Edition of "Python Cookbook" appeared in 2002, is still in print (selling well), and has met with the kind of sales and review success you all deserved, as a unique book with over 200 recipes by over 100 authors on all sorts of topics relevant to Python versions from 1.5.2 to 2.2. Nevertheless, Python has grown in important ways since then, and deserves an encore: the Second Edition of "Python Cookbook" will appear in 2005 and will focus strictly on Python 2.3 and 2.4. Please contribute to the cookbook site *now* for your submissions to be considered for publication. We especially like recipes that include relevant discussion (not just code), and we're biased in favour of recipes "showing off" specific techniques in code snippets (rather than large, complete programs). Useful comments can also qualify you for the coveted "contributor" status. We're particularly interested in materials based on the new features of Python 2.4 -- Python 2.4 (alpha 2 at the time of this writing) is currently available for download at www.python.org, so, get going: download it, install it, try it out, and submit recipes based on it! As was done for the First Edition, contributors whose recipes and comments we use in the book will receive a complimentary copy of the Second Edition, and a portion of all royalties will go to the non-profit Python Software Foundation. As for the First Edition, recipes to be included in the Second Edition should be licensed under the modified Berkeley license, making them candidates for inclusion in a future Python distribution. Submission deadlines (for possible publication in the Second Edition): Materials based on Python 2.3: Saturday, September 4, 2004 Materials specific to Python 2.4: Saturday, September 25, 2004 Alex From rogerb at rogerbinns.com Mon Aug 16 01:31:44 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Sun, 15 Aug 2004 22:31:44 -0700 Subject: Python secure? References: <411ffef6$0$65603$a1866201@newsreader.visi.com> <41200b23$0$8090$a1866201@newsreader.visi.com> Message-ID: Roy Smith wrote: > The OP was asking if Python offered a way to prevent disclosure of his > source code. The statement was made that copyright laws would protect > him. Copyright laws are also the major prevention of disclosure. Additionally they are a basis of getting redress should there be a disclosure. Those laws also apply no matter what language and platform are used. > Protecting the code prevents theft. IP laws only give you a basis for > legal action after the code is stolen. Deliberately obfsucating the code (or just using C :-) will only stop rank amateurs. Your (valid) opinion is roughly the same as saying that your car alarm/security just needs to be better than the other cars parked around it in order to discourage people going after yours. The difference here is that software isn't interchangable. Someone who wants to break into the OP's software won't be stopped by obfuscation and decide to go after a word processor instead. And software doesn't require you to be physically local in the same way as real property theft requires. It is also not detectable that the code has been recovered, whereas your silverware disappearing is :-) Roger From kamikaze at kuoi.asui.uidaho.edu Mon Aug 2 15:22:36 2004 From: kamikaze at kuoi.asui.uidaho.edu (Mark 'Kamikaze' Hughes) Date: 2 Aug 2004 19:22:36 GMT Subject: Percentage matching of text References: <1678860800.20040730075239@MailBlocks.com> Message-ID: Bruce Eckel wrote on Fri, 30 Jul 2004 07:52:39 -0600: > Background: for the 4th edition of Thinking in Java, I'm trying to > once again improve the testing scheme for the examples in the book. I > want to verify that the output I show in the book is "reasonably > correct." I say "Reasonably" because a number of examples produce > random numbers or text or the time of day or in general things that do > not repeat themselves from one execution to the next. So, much of the > text will be the same between the "control sample" and the "test > sample," but some of it will be different. > > I will be using Python or Jython for the test framework. > > What I'd like to do is find an algorithm that produces the results of > a text comparison as a percentage-match. Thus I would be able to > assert that my test samples must match the control sample by at least > (for example) 83% for the test to pass. Clearly, this wouldn't be a > perfect test but it would help flag problems, which is primarily what > I need. > > Does anyone know of an algorithm or library that would do this? Thanks > in advance. Here's an outside-the-box solution: set the random number seed and use a fixed date in your tests. Now you can test fixed values, even though the application is "random". -- Mark Hughes "Virtues foster one another; so too, vices. Bad English kills trees, consumes energy, and befouls the Earth. Good English renews it." -The Underground Grammarian, v1n2 From amk at amk.ca Sat Aug 7 17:53:18 2004 From: amk at amk.ca (A.M. Kuchling) Date: Sat, 07 Aug 2004 16:53:18 -0500 Subject: Going the PL/1 way References: Message-ID: On Sat, 7 Aug 2004 22:20:31 +0200, Mikl?s wrote: > Yes, this was exactly my point. Performance and GIL. Those are problems. > And problems must be solved. Problems for who? I have no problems with Python's performance in my applications. I avoid threads because they're error-prone, so the GIL doesn't affect me. Free software projects are run by the people who actually contribute code. If sorted() and reversed() were added, it's because Raymond Hettinger actually wrote code to implement them, and GvR didn't dislike them. If people who want decorators are willing to expend effort to implement them, test them, conform to the coding standard, then they can be considered for inclusion. So, if you want to see the GIL fixed, or performance improvements made, you have to work on these problems. --amk From wweston at att.net Thu Aug 19 13:59:41 2004 From: wweston at att.net (wes weston) Date: Thu, 19 Aug 2004 17:59:41 GMT Subject: get last two in a length of unknown length? In-Reply-To: References: Message-ID: M. Clift wrote: > Hi All, > > I have a list of varying length. Would someone know the way to get the last > two values for this? I can see how this is done with a list that I know the > length of, but not one thats generated by user input. > > Thanks for any help > > M, Note this, maybe, unexpected behavior: >>> list=[1] >>> list[-2:] [1] >>> list = [] >>> list[-2:0] [] wes From jeff at ccvcorp.com Mon Aug 9 20:49:13 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Mon, 09 Aug 2004 17:49:13 -0700 Subject: @decorator syntax is sugar, but for what exactly? In-Reply-To: References: Message-ID: <10hg6rf5ck639cd@corp.supernews.com> Dan Sommers wrote: >>>On Sun, 8 Aug 2004 18:24:58 +1000, >>>Anthony Baxter wrote: >>> >>> >>> >>>>In many cases, these new features actually lead to smaller, simpler >>>>code. I challenge _anyone_ to tell me that >>>>apply(func, args, kwargs) >>>>is better than >>>>func(*args, **kwargs) >>>> >>>> >When I see f( x ), I think that f is a function bound by def (or an >extremely close relative, such as class or staticmethod), and that I can >grep for it somewhere, either in the source code or the library >reference. I also think, rightly or wrongly, that f *was* bound, >*before* I needed it, and *does not change over time*. > >When I see apply( f, x ), I think that f varies over time, and is some >sort of a callback or plugin or whatever, and is *not* the name of an >actual function bound by def. > Um, I think you're missing the point, here. The apply() has nothing to do with whether func() is bound by def or by assignment -- both cases given here are intended to allow the easy passing of variable argument lists to functions. In other words, you're thinking of calling a function through a function pointer, but what's actually being shown is passing a pointer to a parameter struct. The old style requires a separate function [apply()] to be called that dereferences the parameter struct and feeds parameters to the called function one-by-one, while the new style dereferences the parameter struct in-place. If you're going to compare this to any real C/C++ construct, it's much closer to the issue of (C) pass-by-pointer vs. (C++) pass-by-reference syntax, but even that's a really distant stretch. Jeff Shannon Technician/Programmer Credit International From bart_nessux at hotmail.com Wed Aug 4 09:39:33 2004 From: bart_nessux at hotmail.com (Bart Nessux) Date: Wed, 04 Aug 2004 09:39:33 -0400 Subject: Perl's Crypt::PasswdMD5 Message-ID: Does Python have anything similar to Perl's Crypt::PasswdMD5??? I read about the crypt module... but it only does DES. Any plans to add md5 or other digests to it in the future? From insert at spam.here Tue Aug 31 12:32:04 2004 From: insert at spam.here (Doug Holton) Date: Tue, 31 Aug 2004 11:32:04 -0500 Subject: GUI Designer In-Reply-To: References: Message-ID: A.M wrote: > Hi, > > Do we have any OpenSource GUI designer for Python ? It depends on whether you are running Windows or Linux/Mac, and what GUI toolkit you want to use (wxpython, qt, gtk, tkinter, windows.forms, etc.). If you are on Linux, a good GUI builder you might try is QT Designer. There is a Windows version, too, but you only use it for non-commercial development. See http://developers.coedit.net/QtKde On Windows, wxpython is the better GUI toolkit, but I don't use any of the GUI builders for it. If you want to check out bleeding edge stuff, see the IronPython (http://ironpython.com/) or boo (http://boo.codehaus.org/) languages for .NET and Mono. You can use the Windows.Forms or GTK# GUI toolkits. They still aren't well integrated with GUI builders (like Glade or Visual Studio) though. From JBrouwersAtProphICyDotCom at no.spam.net Sat Aug 7 21:50:42 2004 From: JBrouwersAtProphICyDotCom at no.spam.net (Jean Brouwers) Date: Sun, 08 Aug 2004 01:50:42 GMT Subject: Killing children References: <87smb0w4ln.fsf@debian.laymusic.org> <87d624vxt2.fsf@debian.laymusic.org> <87pt62vgk7.fsf@debian.laymusic.org> Message-ID: <070820041850214353%JBrouwersAtProphICyDotCom@no.spam.net> It looks like there is no space left to fork the subprocess and load/map the libraries the latter needs. Maybe there too many processes running already, simultaneously? /Jean Brouwers In article <87pt62vgk7.fsf at debian.laymusic.org>, Laura Conrad wrote: > Further adventures in infanticide. I've been spawning and killing > programs all day, in the course of testing and fixing other aspects of > the program. > > All of a sudden, although I haven't changed the spawn line at all, > only things farther along in the program, I get: > > C:\cygwin\bin\python2.3.exe (5684): *** unable to remap > C:\cygwin\bin\cygcrypto-0.9.7.dll to same address as parent(0x6B0000) != > 0x6C0000 > 4 [main] python 5468 sync_with_child: child 5684(0x710) died before > initialization with status code 0x1 > 681 [main] python 5468 sync_with_child: *** child state child loading dlls > Traceback (most recent call last): > File "testspawn.py", line 8, in ? > p = os.spawnl(os.P_NOWAIT, "/usr/bin/python", "python", 'run_rad7.py', > "/dev/ttyS8", "120", "0", "00560") > File "/usr/lib/python2.3/os.py", line 566, in spawnl > return spawnv(mode, file, args) > File "/usr/lib/python2.3/os.py", line 521, in spawnv > return _spawnvef(mode, file, args, None, execv) > File "/usr/lib/python2.3/os.py", line 489, in _spawnvef > pid = fork() > OSError: [Errno 11] Resource temporarily unavailable > > This is the same kind of error that caused me to stop using > pexpect.spawn. Does anyone know what's happening? rebooting does not > cause it to go away. The program I attempting to spawn from my python > program runs fine from the command line. From bokr at oz.net Wed Aug 11 15:25:29 2004 From: bokr at oz.net (Bengt Richter) Date: 11 Aug 2004 19:25:29 GMT Subject: deco_fun_expr(= vs. @deco_fun_expr Message-ID: Just wanted to make sure this got into python-dev as an alternative ;-) Example using post-fixed '(=' instead of prefixed '@': deco1(= decomodule.deco2(= def foo(): pass effect is same as with prefixed-@ syntax, i.e., foo = deco1(decomodule.deco2(foo)) (except either way there's no intermediate foo binding during evaluation, I gather?) Advantages: 1. currently illegal syntax, UIAM 2. lets callable-returning expression have unchanged grammar up to new (= trailer part 2. doesn't use up '@' or interfere with tools that use it 3. expresses calling in the proper nested way (inner before outer). No confusion about "backwards." 4. Leaves the door open to callable-calls operating on other code-block-derived arguments than from def and its suite (e.g. class and suite). Leaves door open for explicit =) end-of-block-arg mark if that should turn out useful for demarcation of otherwise ambiguous block endings, for some future use. Unfortunately vexing personal matters will demand priority attention for some time again :-( Bye for now. Regards, Bengt Richter From dbickett at gmail.com Fri Aug 20 21:09:01 2004 From: dbickett at gmail.com (Beeyah) Date: 20 Aug 2004 18:09:01 -0700 Subject: Fate of lambda, Functional Programming in Python... References: <412636D1.6070808@noaa.gov> Message-ID: <1d6cdae3.0408201709.6b4a4960@posting.google.com> com-nospam at ccraig.org (Christopher A. Craig) wrote in message news:... > "Jared Cohen" writes: > I can't think of a situation where you _really_ need the second (and > much more limited) form. Well, obviously the truth is you don't, however brevity tends to be a programmer's best friend (the other edge of the sword, of course, typically being the lack of readability.) The fact is that lambas aren't really difficult understand, but occasionally you have to linger on the line for a second or two longer to grasp what the programmer is saying (provided you know how lambdas work -- a simple feat) >From what I've seen, the argument always either starts or ends with the "it deters newbies" bandwagon, and I must say I don't agree. If anything it sparks their curiosity as to what the keyword does, and taking it out of the language would deter the demographic that banks on it. The other problem is how widely its used (a fact that's confirmed by the defense lambda's receiving,) a lot of applications would have to be changed and extended to accommodate the lack of our favorite one-liner ;\ Beeyah From DesertLinux at netscape.net Sat Aug 21 09:43:13 2004 From: DesertLinux at netscape.net (Byron) Date: Sat, 21 Aug 2004 13:43:13 GMT Subject: Why are strings immutable? In-Reply-To: References: Message-ID: Hi Brent, It is usually best to create a function in which you can 1) pass the string to 2) change it as needed 3) return the modified sting back to the original caller. Can you tell us a little more about what you are trying to accomplish? Byron --- Brent W. Hughes wrote: > I kind of hate to have to convert a string into a list, manipulate it, and > then convert it back into a string. Why not make strings mutable? From dave at pythonapocrypha.com Mon Aug 30 11:17:12 2004 From: dave at pythonapocrypha.com (Dave Brueck) Date: Mon, 30 Aug 2004 09:17:12 -0600 Subject: Size of a remote URL In-Reply-To: References: Message-ID: <413344F8.9060905@pythonapocrypha.com> Justin wrote: > I am attempting to create a tuple of file sizes from a list or URLs. > Unfortunately not all files are returned with a "Content-Length" > header. Does anybody knwo a more absolute or reliable way to get the > size of a remote file through its URL? Possibly a lower level http > request than simply reading the MIME headers? Thanks to anyone who has > a suggestion If the server won't tell you the size of the object, then the only other thing you can do is download the object yourself and compute its size - there's nothing else you can do. The size is often not reported if the content is being generated on the fly. Anyway, maybe there's another way to solve the problem you're working on - why do you need to know the sizes? -Dave From ramen at lackingtalent.com Wed Aug 4 01:52:32 2004 From: ramen at lackingtalent.com (Dave Benjamin) Date: Wed, 04 Aug 2004 05:52:32 -0000 Subject: checking whether a var is empty or not References: Message-ID: In article , Pierre-Fr?d?ric Caillaud wrote: > > This smells like PHP to me... > > if var is not None: > if var has not been assigned, it raises an exception. > if var has been assigned, it contains a value which can be None or > someting else. > > This is different from PHP where you can't know if a variable exists or > not, because a non-existent variable will contain null if you check it, > and putting null in a variable is like deleting it, but noone knows > because there's no way of checking if a variable really exists, etc. No, in PHP, you can find out if a variable exists using isset(). And trying to dereference an uninitialized variable will generate a warning if you have error reporting turned up all the way (error_reporting(E_ALL)). -- .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:. "When the country is confused and in chaos, information scientists appear." Librarian's Lao Tzu: http://www.geocities.com/onelibrarian.geo/lao_tzu.html From kyleroot at gmail.com Fri Aug 13 16:37:32 2004 From: kyleroot at gmail.com (Kyle Root) Date: Fri, 13 Aug 2004 20:37:32 GMT Subject: Arranging a dependency tree In-Reply-To: <7xr7qcepjn.fsf@ruckus.brouhaha.com> References: <6ccff37a.0408111831.6eb25a4e@posting.google.com> <7xr7qcepjn.fsf@ruckus.brouhaha.com> Message-ID: Well thank you all that helps very much, I should have this done soon :D And also thanks to Paul Foley who sent me tha topological sorter :) From __peter__ at web.de Wed Aug 11 09:08:52 2004 From: __peter__ at web.de (Peter Otten) Date: Wed, 11 Aug 2004 15:08:52 +0200 Subject: Executing bytecode from a string. References: Message-ID: Benjamin Scherrey wrote: > I'm curious as to how difficult it would be to take a string that contains > compiled bytecode, load it into memory, give it a function name then > execute that function. I'm thinking of a database that contains compiled > objects that I can load and execute. I'm also curious as to what level of > grainularity this would work - module, class, class method, function? > Anyone tried to do this before? Obviously dependencies are a consideration > but I'm more interested in the mechanics of this. Appreciate ideas & > pointers you might have... > > Ben Scherrey The following was written just for fun with no pretension that it will work in the "real world". I've only manipulated co_consts and co_code of my custom code object - you can investigate the other parameters one after another and replace them with something at your choice. The question that remains - how do you want to create the bytecode strings? If from actual functions, why not store their source code, if from codeobjects, why not marshal.dump()/load() them? Peter # get hold of the function and code types def f(): pass function = type(f) del f code = type(compile("def f(): pass", "noname", "exec")) template = compile("def f(): pass", "noname", "exec") def makeFunc(bytecode, consts): """ create a new function from a bytecode string and a consts tuple """ # instead of inventing all code-attributes ourselves # copy those we are not interested in from an existing template co = template codeobj = code(co.co_argcount, co.co_nlocals, co.co_stacksize, co.co_flags, bytecode, consts, co.co_names, co.co_varnames, co.co_filename, co.co_name, co.co_firstlineno, co.co_lnotab, co.co_freevars, co.co_cellvars) return function(codeobj, globals(), "f", None, None) # get hold of a valid bytecode string # (I could have pasted the string literal from the interpreter, # but I chose not to cheat :-) def prototype(): print "so what" bytecode = prototype.func_code.co_code # test what we have so far g = makeFunc(bytecode, consts=(None, "it takes more than the byte-code",)) h = makeFunc(bytecode, consts=(None, "to make a function")) g() h() From peter at engcorp.com Sat Aug 21 19:27:11 2004 From: peter at engcorp.com (Peter Hansen) Date: Sat, 21 Aug 2004 19:27:11 -0400 Subject: Question about importing modules In-Reply-To: References: Message-ID: pythos wrote: > Newbie at python (but not programming) here... > > I have a program that has "import os" at the top, and then later a call to > utime() is made. The python interpreter says "name 'utime' is not defined". > But if I change "utime(...)" to "os.utime(...)" then it works fine. Perhaps I > am expecting the "import os" statement to work the same way as "import > .*" does in Java. So is it the case that if I write "import os" > in python, then I still need to write "os.utime(...)"? Or is there something > else wrong? Thanks. The equivalent to the Java version might be "from os import *", but believe me, you do *not* want to do that, not most of the time in Python, and never with the "os" module. The usual approach is "import os" followed by "os.utime", as you discovered. "from os import utime" is also fine, though I think it's much more common to do the former than this one, at least with many or most of the builtin modules. -Peter From dd55 at cornell.edu Fri Aug 20 09:02:13 2004 From: dd55 at cornell.edu (Darren Dale) Date: Fri, 20 Aug 2004 09:02:13 -0400 Subject: My only complaint about Python In-Reply-To: References: Message-ID: Tim Peters wrote: > [Darren Dale[ > >>... >>Will the BDFL ever split with Visual Studio? > > > We should be clear here that this isn't Guido's decision. What you > get on Windows is what you get on all other platforms in this respect: > you get what volunteers show up to produce, year after year after > year. So you get a fine Cygwin port from Jason Tishler, seemingly > toiling all alone, and you get contributions from at least four > developers who do use Visual Studio. I meant no disrespect to the developers. > > I don't think that's an accident. Most open source jockeys who use > Windows do so because it's needed for their day job, and sticking with > an MS compiler is widely perceived in pointy-hair boss-land as the > safest course on Windows. And it is a first-class IDE, so there's no > pragmatic reason to wrestle with yet another system when the day job > ends. It takes real sweat to get comfortable with any C development > tool chain, and it takes years to become familiar wth each one's > maddening quirks. > > I expect that's why Guido still uses Visual Studio when he's running > on Windows (and know it's why I do), but he actually hasn't had > anything to do with the Windows Python releases for years. Things > Will Change when long-term volunteers show up and change them. This comes back to the heart of the matter. How do you get volunteers who dont have access to VS to get involved with Python development? I think the suggestions here were right on, give Python the ability to support MinGW out of the box. I thought that a compiler could even be included in a version of the Windows distribution, but maybe that is taking it too far. From wweston at att.net Wed Aug 18 11:23:23 2004 From: wweston at att.net (wes weston) Date: Wed, 18 Aug 2004 15:23:23 GMT Subject: age of Python programmers In-Reply-To: References: Message-ID: Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... > > 55. What a concept; built in lists, dictionaries, tuples, garbage collection, OO, automatic typing..... From fumanchu at amor.org Tue Aug 10 11:32:43 2004 From: fumanchu at amor.org (Robert Brewer) Date: Tue, 10 Aug 2004 08:32:43 -0700 Subject: profile stats interpretation Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022DEE@exchange.hqamor.amorhq.net> Peter Otten wrote: > Instead of > > > valuetype = type(value) > > valuetype = value.__class__ > > might work, too. Thanks! timeit says that's about %40 faster. I'll run it through the test suite. > > try: > > xform = self.processors[valuetype] > > except KeyError: > > xform = self.default_processor > > # assuming the normal type/value ratio the following > # line could drastically increase your hit rate. > self.processors[valuetype] = xform <:) I should have thought of that one. Now that I've hammered out the use cases (I know the limited set of types I should support), I could probably get rid of default_processor (and try: block) completely. > Once you have spotted a single slow function in heavy usage > you can resort > to a micro-optimization tool like timeit. A function is > "slow" when your > app spends a long time in it and the subroutine calls are > necessary and > cannot be optimized themselves. Then picking the variant with > the smallest > cumulated time should be a no-brainer. Right. Mostly? Might the cumtime include I/O, IPC and other processes whose times are unreliable? And have I mentioned lately that I love Python? :) Three lines of hotshot code dropped into the CGI request processor has gotten me a long way in the last couple of days. I found a particularly slow routine where I was calling the database 15 times more than I needed to... >:( Thanks for the comments! Robert Brewer MIS Amor Ministries fumanchu at amor.org From otto.wyss at orpatec.ch Thu Aug 26 22:05:00 2004 From: otto.wyss at orpatec.ch (Otto Wyss) Date: Fri, 27 Aug 2004 04:05:00 +0200 Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> Message-ID: <1gj5s4z.f922mx140xaiiN%otto.wyss@orpatec.ch> Pascal Bourguignon wrote: > > What you mean with Unixism? > > It's always funny to observe people's contradictions: > > > Last week i bought a chain saw with a > twisted handle. Perhaps i wasn't > careful, but by accident it chopped one > of my arm off, then i thought to myself > "gosh, this is POWERFUL!". This seems to > be the fashionable mode of thinking > among the unixers or unixer-to-be, who Thanks, for the clarification. For a none native English it's sometimes difficult to grasp the underlying meaning. And do I understand it right that Xah Lee _speaks_ against "Unixism" instead of producing code? Well then I may point at "wyoism", the cult of the code producer. ;-) O. Wyss -- How to enhance your code, see "http://freshmeat.net/projects/wxguide/" From newsgroups at jhrothjr.com Wed Aug 4 21:49:41 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Wed, 4 Aug 2004 21:49:41 -0400 Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) References: <1646998998.20040804190026@MailBlocks.com> Message-ID: <10h34ivio5s2c21@news.supernews.com> "Bruce Eckel" wrote in message news:mailman.1168.1091667628.5135.python-list at python.org... > I'll weigh in a little on this one. > > This is very similar to attributes/metadata in Java J2SE 5 and in C#. > The thing is, metadata is a little bit weird; it's intentionally > outside of the domain of the 'normal' programming language, because it > expresses things that you can't or shouldn't within the normal > programming language. So you _do_ need an escape mechanism. And it > also takes a little bit of getting used to; it's orthogonal to what > you normally think of as a language feature. But the potential for > metadata features, at least in Java, is very powerful. I'd be a lot happier if it was, in fact, a general metadata facility. Unfortunately, it only seems to work on functions (methods), and for what I'm working on I need metadata for properties and fields as well, that is, any identifier that you can bind an object to. That's not to say I can't use it for something. It looks like it might be very useful if I ever get around to writing an interactive fiction system in Python. It solves one significant problem in such a system - how to put a method into an instance cleanly. John Roth > > Bruce Eckel > > From paolo.veronelli at yahoo.it Sun Aug 22 09:57:03 2004 From: paolo.veronelli at yahoo.it (Paolo Veronelli) Date: Sun, 22 Aug 2004 15:57:03 +0200 Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WEDONE? In-Reply-To: <2_0Wc.8436$Jn5.1521@fe1.texas.rr.com> References: <2_0Wc.8436$Jn5.1521@fe1.texas.rr.com> Message-ID: <4128A62F.8070607@yahoo.it> Paul McGuire wrote: > "Paolo Veronelli" wrote in message > news:mailman.2146.1093172019.5135.python-list at python.org... > >> >>Some morphological images suggest me "through" can be a keyword as it >>hide the verb filter which can be a little more general then others. >>Anyway using a verb or a noun doesn't suggest the orthogonality of the >>piece,so please consider adverbs as clever candidates. >> >>Paolino >> >> > > > I always thought "through" was a preposition. Poor ignorant I am ;-[ >So I googled for lists of > prepositions, and found these other candidates (they are also shorter): > > per > via also "by" is a substitute for as > -- Paul > > From xavier_combelle at yahoo.fr Sun Aug 8 16:19:07 2004 From: xavier_combelle at yahoo.fr (Xavier Combelle) Date: Sun, 08 Aug 2004 22:19:07 +0200 Subject: decorators vs GIL In-Reply-To: References: <8YudnZoJ4NdLEYjcRVn-jA@speakeasy.net> <0bidnfbR2_PZOIjcRVn-pA@giganews.com> <41162234$0$32536$626a14ce@news.free.fr> Message-ID: <411689bd$0$25588$636a15ce@news.free.fr> Thank you for the address.this page is especially clear I am quite agree with you. Anthony Baxter wrote: >On Sun, 08 Aug 2004 14:57:12 +0200, Xavier Combelle > wrote: > > >>For information is there some internet resources to understand what >>exactly the GIL is about ? >> >> > >Plenty - try this google search: >http://www.google.com/search?q=site%3Adocs.python.org+GIL >for a couple of simple ones, but there's plenty more - google for >"python GIL" (or "python free-threading" for patches that were >written against Python 1.4 to remove the single lock. They ended >up slowing down Python significantly. > > That is not really surprizing, the GIL is a very simple and very efficient way to manage multithreading. After reading, I can't undersand that other interpreted languages don't do the same. The use of GIL make that interpreter work as a single thread process. >Note that much has been written about the GIL. Much of the stuff >I've seen has been from people who obviously don't understand >it, but fear it anyway. > > > Why fear it ? There is no really problems: from a performance point of view, it's a very light way to limit the overhead of mutltithreading.. From developper point of view, it seems to be just a constraint to write C code which access to Python. Moreover, just blocking IO, or code wich do a lot of computing seems to worry about it. For blocking IO, I wonder, if the main part si not used by the development team of python and for long computing task, a different heavy process seems be better design. I am certainly wrong, but I don't see where. >Anthony > > From anthonybaxter at gmail.com Thu Aug 26 11:25:01 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 27 Aug 2004 01:25:01 +1000 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> Message-ID: On Thu, 26 Aug 2004 11:15:46 -0400, Paul Morrow wrote: > __getitem__ is most certainly magical! Defining it 'declares' > (implicitly, but we'll ignore that governing zen rule for the moment) > that instances of the containing class have dictionary semantics (that > they can be used, in some degree, like dictionaries). That's magic. > That's meta. That's profoundly deeper than anything defining getMonkey > does. What? There is *nothing* that __getitem__ "declares". __getitem__ is used by the interpreter. When do make a call like: someobj[key] the interpreter turns that into someobj.__getitem__(key) That's all. I can make an object that acts like a dictionary _without_ using a __getitem__, watch: class Foo: def __init__(self): self.d = dict(ape=False,spidermonkey=True) def getMonkey(self, key): return self.d[key] def __getattr__(self, name): if name == "__getitem__": return self.getMonkey else: raise AttributeError, name f = Foo() print f['ape'] print f['spidermonkey'] From http Sat Aug 28 04:56:30 2004 From: http (Paul Rubin) Date: 28 Aug 2004 01:56:30 -0700 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <7xzn4gwgea.fsf@ruckus.brouhaha.com> <1gj7a1o.1a5d2q410jsn2kN%aleaxit@yahoo.com> <7xisb4xnh5.fsf@ruckus.brouhaha.com> <1gj7c1a.tfdm14p3hclcN%aleaxit@yahoo.com> <7xd61benm9.fsf@ruckus.brouhaha.com> <1gj82n3.1ylkr3nierngmN%aleaxit@yahoo.com> <7x4qmnvgcu.fsf@ruckus.brouhaha.com> <7xvff3u0za.fsf@ruckus.brouhaha.com> <1gj85gi.ghiv3b1f8fhv7N%aleaxit@yahoo.com> Message-ID: <7xacwfod35.fsf@ruckus.brouhaha.com> aleaxit at yahoo.com (Alex Martelli) writes: > > I guess I better check into what Java does about this. It's been a > > while since I've used Java, but I seem to remember that signing is not > > mandatory. > > OK, but it might make for a nice optional feature anyway. Well, in Java, jars are the only thing you can import from, and you need to be able to import from unsigned ones or else you have to sign them all the time. If we use a naming convention, then if you want an unsigned archive you can just name it .zip instead of .jar. But still, I better check. I do remember that in Javascript (which also used jar files under the Netscape browsers of the day), you could load code from unsigned jars and the code could do normal operations. But code that did "dangerous" operations wouldn't run unless it was loaded from a signed jar file. From peter at engcorp.com Mon Aug 30 20:17:30 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 30 Aug 2004 20:17:30 -0400 Subject: Upgrading to 2.3 from 2.2, questions In-Reply-To: <10j7g4vsf5ef9c5@corp.supernews.com> References: <10j7g4vsf5ef9c5@corp.supernews.com> Message-ID: Jeff Shannon wrote: > Peter Hansen wrote: >> Robert Oschler wrote: >>> - Do I need to uninstall 2.2 first? >> I don't know if there's an official answer other than "yes". I don't >> know if there's a safe answer other than "yes". > > I'm pretty sure that there should be no problems with having different > versions of Python running side-by-side. I have had 2.0 and 2.1 on the > same machine, and 2.1 and 2.2, with no problems at all. Robert is quite right that multiple versions can work together simultaneously. In fact, some of us have to do development which ensures compatibility with different versions by running automated tests under each of several installed copies of Python. (I took the OP's subject line "upgrading" to imply this wasn't what he wanted to do, but it is certainly feasible and simple.) > however, if you copy from site-packages to site-packages, be sure to > delete any .pyc files because those are probably *not* > version-portable. (If the .py files still exist, they will quietly be recompiled to .pyc files by the new version, so this shouldn't normally be a concern. If a given .py file is gone and only the .pyc file exists, I believe you should get a "RuntimeError - Bad Magic number in .pyc" message. As I mentioned above, we often alternate between versions of Python and rarely have to pay special attention to the .pyc files that are left in our application directories, and site-packages should be no different.) -Peter From bwm at acm.org Mon Aug 16 12:08:10 2004 From: bwm at acm.org (Bernhard Mulder) Date: Mon, 16 Aug 2004 16:08:10 GMT Subject: Generators versus Coroutines In-Reply-To: <7x7js1i887.fsf@ruckus.brouhaha.com> References: <7x7js1i887.fsf@ruckus.brouhaha.com> Message-ID: If you want, you can yield across multiple levels by converting functions into generators and calls into for loops. The following function illustrates this approach: def ack(m, n): if m == 0: yield n + 1 return if m > 0 and n == 0: for i in ack(m-1, 1): yield None yield i return if m > 0 and n > 0: for i in ack(m, n-1): yield None t = i for i in ack(m-1, t): yield None yield i return You call this function this way: for i in ack(2, 2): pass # now i contains the function value. Paul Rubin wrote: > Michael Sparks writes: > >>>It seems to me that in python, generators are not truly coroutines. >> >>Assuming you mean there isn't available a default scheduler for them, or >>there isn't pre-emption built-in I agree. If you mean something else, I'm >>curious as to what you think is missing. (I've also been using generators >>as co-routines for sometime for various reasons) > > > You can't yield across multiple levels of function calls. That's why > they're called "simple generators" instead of just "generators". From chrisb at microgaming.com Mon Aug 23 18:52:05 2004 From: chrisb at microgaming.com (Chris Becke) Date: Tue, 24 Aug 2004 00:52:05 +0200 Subject: decompyle available anywhere? References: Message-ID: Ha. Decompyle is written in python.This language gets better and better. Thanks a mil tho, thats grand. Chris. "Phil Frost" wrote in message news:mailman.2245.1093295324.5135.python-list at python.org... > http://www.freshports.org/devel/decompyle > > On Mon, Aug 23, 2004 at 09:50:43PM +0200, Chris Becke wrote: > > There used to be a module, decompyle, that decompiled .pyc files up to > > version 2.2 of python. Decompyle for 2.3 is now a paid for web service and > > the 2.2 decompyle seems to have been yanked. > > > > Is there some site out there still hosting it? Preferably a win32 version, > > but I guess beggars can't be choosers. > > > > Thanks > > > > Chris. From oziko at fusiondementes.com Mon Aug 16 11:46:26 2004 From: oziko at fusiondementes.com (oziko) Date: Mon, 16 Aug 2004 10:46:26 -0500 Subject: Reading ogg123 output with popen3 Message-ID: <4120D6D2.3060303@fusiondementes.com> Hi, I am trying to read ogg123's output with popen3: stin, sto, ste = os.popen3('ogg123 music.ogg') out=sto.readlines() The problem is I can not get any text from the output when I read ogg123's stdout, instead I can read some text from stderr with: out2=ste.readlines() Another problem is, qhen I read stderr, ogg123 breaks and I just get a little part og the output. So, my question is. What is the best form to get ogg123's output, so I can use it in an UI, to make a progress bas for example? From stefsmurf at hotmail.com Thu Aug 26 10:24:33 2004 From: stefsmurf at hotmail.com (Johnny Storm) Date: Thu, 26 Aug 2004 14:24:33 GMT Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: "Markus Wankus" wrote in message news:Q3lXc.22457$_H5.654259 at news20.bellglobal.com... > >>I think you're getting confused with the Blue ?yster Cult. > >>Don't Fear the Reaper - great song. > > > > > > It was a great song, but it needed more cowbell... > > Mark. Gotta have more cowbell. . . . Johnny From nobody at nowhere.com Tue Aug 24 14:06:58 2004 From: nobody at nowhere.com (Fred) Date: Tue, 24 Aug 2004 20:06:58 +0200 Subject: Building basic dialog in Windows? Message-ID: Hi, I'd like to turn a command-line script into a Windows GUI app using the native widgets so as to reduce the size of the binary (ie. no QT, wxWidgets, et al.) I came up with the following list of tools to access the Win32 API: - PythonWin (MFC) http://www.python.org/windows/pythonwin/ - ctypes http://starship.python.net/crew/theller/ctypes/ - EasyDialogs for Windows http://www.averdevelopment.com/python/EasyDialogs.html - DynWin http://www.nightmare.com/~rushing/dynwin/ - sdk32 - Partial Python wrap of the Win32 Platform SDK http://www.object-craft.com.au/projects/sdk32/ Does someone have a sample on how to display an OK/Cancel dialog with a label + progress bar? Should I look at other tools? Thank you Fred. From JSmuts at clover.co.za Wed Aug 18 09:52:11 2004 From: JSmuts at clover.co.za (Jaco Smuts) Date: Wed, 18 Aug 2004 15:52:11 +0200 Subject: age of Python programmers In-Reply-To: Message-ID: 33, yesterday. Most (5 I think) other python programmers I know are in their early 30's jaco Christopher T King Sent by: python-list-bounces+jsmuts=clover.co.za at python.org 08/18/2004 03:45 PM To: python-list at python.org cc: Subject: Re: age of Python programmers On Wed, 18 Aug 2004, Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... I'm 19. The only other Python programmer I know personally is 21. Congrats on discovering Python at 14; back then I thought VB was a godsend. ;) -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From rkern at ucsd.edu Sat Aug 21 17:49:47 2004 From: rkern at ucsd.edu (Robert Kern) Date: Sat, 21 Aug 2004 16:49:47 -0500 Subject: My only complaint about Python In-Reply-To: References: <874qmxj81k.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> <4127af18$0$22378$626a14ce@news.free.fr> Message-ID: Tim Daneliuk wrote: [snip] > It is "derivative" in the sense that the final binary may either contain > and/or depend upon library support shipped with the gcc compiler chain. Yes, the final binary *may* depend on any number of libraries either distributed with gcc or completely independent from gcc. The license of those libraries have an effect on your program. The license of gcc does not. gcc does not have to use glibc as the standard C library. For example, the cygwin distribution of gcc uses their own newlib (GPL+exception, I believe) and mingw uses Microsoft's MSVCRT. gcc can also target the native libc on other systems. Or, if you provide your own C runtime or do not need one, then there are no license problems. I repeat, it is the license of the libraries that affects your program, not the license of gcc. > IIRC (and this may have changed - I have not looked at it in some time), > even the Lesser GPL places some constraints about what you _must_ > distribute > (or be willing to provide) when you use their libs to produce a shipped > product. So can the licenses, proprietary or otherwise, of any other library any compiler might link to. -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From anthonybaxter at gmail.com Fri Aug 6 12:30:24 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 7 Aug 2004 02:30:24 +1000 Subject: Python milestone releases In-Reply-To: References: Message-ID: On Fri, 06 Aug 2004 16:53:09 +0200, Thomas D'Tak wrote: > - First of all, it should be mentioned somewhere (in a prominent place, > such that even first-time visitors of python.org can find it easily). So we'd have some major releases that are more major than others? Pass. > - Not every release should be a milestone release; > milestones should not come more often than maybe every 2 years. > (E.g. 2.0 and 2.3 would have been good candidates IMO.) See, I'd have said 2.1 and 2.3. 2.1 was the last release before the new objects went in. Note also that major releases are typically 12-18 months apart. Python 2.1, for instance, is now over three years old. > And -even for programmers- the following could be important: > > - Some kind of support would be needed for the milestone releases, > even after the release of other -non-milestone- Python versions; > (e.g. bug fixes, backports of important new packages). Volunteers to do this are more than welcome to do so, and I think that the python dev community would be more than happy to do what's needed to make this happen, if someone would offer to do it. I'm happy to help someone who wants to do this, and is willing to commit to doing this, to get up to speed. But please be aware that this is a non-trivial amount of work. I can say, that in my (current) role as release manager, I'm utterly uninterested in doing this. One maintenance branch, with the regular 6-monthly bugfix releases, is quite enough for me, thank you. From spamhole at gmx.at Wed Aug 25 15:50:05 2004 From: spamhole at gmx.at (Max) Date: Wed, 25 Aug 2004 21:50:05 +0200 Subject: Regular Expressions In-Reply-To: <808f000f.0408250802.8c303ea@posting.google.com> References: <808f000f.0408250802.8c303ea@posting.google.com> Message-ID: <200408252150.05834.spamhole@gmx.at> On Wednesday 25 August 2004 18:02, Oriana wrote: Hi, > I would like to write some sort of regular expression to replace all > the text from the first dotted line up to the first asterisk that it's > followed either by another asterisk or by another *---- > line.....please help, I don't know where to start!!! Below is some code that will search for the starting and ending *--- lines in a specified file and print the whole file with the *--- part being removed. Hope thats a start, Max #!/usr/bin/python import re f = file("somefile.c", "r") text = f.read() f.close() m = re.search("\*-*.*\*-*\n", text, re.DOTALL) if not m: print "nothing found" else: print text[:m.start(0)] + text[m.end(0):] From jjl at pobox.com Tue Aug 31 16:04:58 2004 From: jjl at pobox.com (John J. Lee) Date: 31 Aug 2004 21:04:58 +0100 Subject: Urllib2, problems with a webserver References: Message-ID: <87k6vfjcph.fsf@pobox.com> Erling Ringen Elvsrud writes: [...] > HTMLParser.HTMLParseError: malformed start tag, at line 2, column 1365 [...] > How come I get this error? [...] Bad HTML. (OK, I haven't actually looked at the HTML, but it's 100/1 that HTMLParser is at fault.) I hope eventually to rewrite mechanize to use htmllib.HTMLParser everywhere, and not use HTMLParser.HTMLParser. The former is less fussy. That just means rewriting pullparser to support both classes, I think. Not too hard (see ClientForm for how to do it -- why not write a patch?-). In the meantime, the best thing to do is to pre-process the HTML. Inconvenient, I know. Also a bit inconvenient is that the only way to do this ATM with mechanize is to write a tiny urllib2 handler class (.http_response() is the handler method you want, which only exists in the as-yet-unreleased Python 2.4, and in ClientCookie, which has a near-identical interface to urllib2; mechanize uses ClientCookie, not urllib2). See posts to the wwwsearch-general mailing lists for sample code. Don't mix urllib2 and ClientCookie, BTW (with the exception of classes that exist in urllib2 but not in ClientCookie: you can use those urllib2 classes with ClientCookie). HTH John From davidf at sjsoft.com Fri Aug 6 05:49:52 2004 From: davidf at sjsoft.com (David Fraser) Date: Fri, 06 Aug 2004 11:49:52 +0200 Subject: Python milestone releases In-Reply-To: <4113406D.1@v.loewis.de> References: <4113406D.1@v.loewis.de> Message-ID: Martin v. L?wis wrote: > Thomas D'Tak wrote: > >> The question is now, how to handle this kind of problems? > > > The Python Business Forum once tried to attack the problem > by planning to release a "Python-in-a-tie" release. This > release would be maintained essentially forever, and they > wanted PythonLabs to commit that this release is not > superceded by another release for atleast a year. Python > 2.2 was chosen as the basis, and indeed, it lived for 18 > months without a successor. Today, 2.2 is not maintained > anymore by the "usual" maintainers, which have moved towards > 2.3 and 2.4. Nobody has taken over maintenance of 2.2, > from which I conclude there is really no need for ongoing > maintenance of old releases. > > Now, if your partners are still running Python versions > too old for your software, the pressure to upgrade should > come from you, the one who needs the newer version. Python > supports side-by-side installation of multiple versions, > so this should cause no problem (except for the disk space, > of course). > > Regards, > Martin What may be easier in some situations is to have back-ported versions of new standard modules that will run with previous versions of Python. For example, Python 2.3 introduces the datetime module ; to require people to upgrade from Python 2.2 for a new module seems steep ... David From peufeu at free.fr Thu Aug 26 08:26:14 2004 From: peufeu at free.fr (=?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?=) Date: Thu, 26 Aug 2004 14:26:14 +0200 Subject: Call for signatories for J2 References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> Message-ID: I'll vote for it. Can we insert conditional expressions in the decorator list ? On 26 Aug 2004 15:00:05 +0300, Ville Vainio wrote: > I vote FOR on the J2 syntax. > From martin at v.loewis.de Sun Aug 1 19:20:21 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 02 Aug 2004 01:20:21 +0200 Subject: Codecs for ISO 8859-11 (Thai) and 8859-16 (Romanian) In-Reply-To: References: <410c2827$0$24830$9b622d9e@news.freenet.de> Message-ID: <410D7AB5.9040100@v.loewis.de> Peter Jacobi wrote: >>The process is actually very easy. Anybody willing to contribute them >>would have to upload them to SF (sf.net/projects/python). > > > Perhaps I have just misunderstood your email. I read it this way (in my own words): [snipped] No - this is indeed my view on the issue. However, this is a technical view; the *process* is completely independent, and very straight forward. Submit the patch to SF, and somebody (probably Marc-Andre Lemburg) will review it. The reviewer might ask questions or request further changes (such as adding documentation); then the patch gets accepted or rejected. I know that *I* would ask questions as to why the submitter thinks the patch is correct, and I would request that the submitter commits to maintaining the patch. If you are unwilling to make such a commitment, I can understand that - it just means that Python 2.4 might not have these codecs (and we haven't discussed the 8859-16 at all). Regards, Martin From anthonybaxter at gmail.com Mon Aug 23 23:53:09 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Tue, 24 Aug 2004 13:53:09 +1000 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 23) In-Reply-To: References: Message-ID: On Mon, 23 Aug 2004 20:08:07 GMT, Peter Otten wrote: > Thanks to the work of Michael Sparks building on previous efforts > by Mark Russell there is already a patch. Anthony Baxter, the > outspoken proponent of the pie syntax, helps with some useful hints, > too. > http://www.python.org/sf/1013835 ... just to correct the record - my efforts here have not been primarily aimed at defending the pie-syntax, but instead aimed at shaking out a decent response. I'm trying _very_ hard to make sure that any efforts to go back to Guido are "done right". After the horror of the ternary operators debacle, I'm trying to make sure that community involvement doesn't end up with a complete bum rap. As part of this, of course, I _have_ defended the pie-syntax, because it's the best I've seen so far. But if something better comes along, I'm happy to go with that. My major problems, btw, remaining with the J2 syntax are the choice of the new keyword seems an extremely problematic thing, and the simple case of a single decorator results in far more clutter. But these are purely subjective judgements. (Hell, this entire discussion is now pretty much based on subjective or aesthetic judgements). From donn at u.washington.edu Wed Aug 11 14:05:06 2004 From: donn at u.washington.edu (Donn Cave) Date: Wed, 11 Aug 2004 11:05:06 -0700 Subject: decorators vs GIL References: <96c2e938.0408091819.2cd7b50d@posting.google.com> <96c2e938.0408101428.1545fb26@posting.google.com> Message-ID: In article <96c2e938.0408101428.1545fb26 at posting.google.com>, sjdevnull at yahoo.com (G. S. Hayes) wrote: > mudd at vex.net wrote in message > news:... ... >> I'm really not concerned with how the threads are implemented in the >> thread library. I just don't want a language to prevent me from >> accessing the thread library. > > I agree, though I'd much rather use a language like Python that hides > the thread library than a language like Java that hides the much more > useful process library. May have missed some of the context here, I suspect there's a particular language that's preventing some particular type of access to the thread library, but the details seem to be missing. In more general terms, note that some languages implement threads on their own, rather than integrating with the OS thread system. That doesn't work for me, but for some applications it's said to be much more efficient and robust. Erlang is probably a good example, the great "microthreads" stackless add-on of yore probably a more interesting one. It would be interesting to get someone to revive microthreads, and someone else to restore the free threading patches, and then try both on the same compute intensive pure Python problem on a 4-way Xeon. Microthreads would of course be limited to one processor, but I wouldn't bet a dime on the outcome. Donn Cave, donn at u.washington.edu From pjn at ribbe.se Wed Aug 25 12:38:13 2004 From: pjn at ribbe.se (Jesper Ribbe) Date: Wed, 25 Aug 2004 18:38:13 +0200 Subject: Getting at the bits of a 32-bit integer In-Reply-To: <412cb407$0$62953$a1866201@newsreader.visi.com> References: <85b54e91.0408231552.75f85727@posting.google.com> <412a98f4$0$65569$a1866201@newsreader.visi.com> <412cb279$1@nntp0.pdx.net> <412cb407$0$62953$a1866201@newsreader.visi.com> Message-ID: <412CC075.3050303@ribbe.se> Grant Edwards wrote: > > > > That looks handy. > > The other thing that looks very useful is a module posted a few > weeks back that impliments fixed-length numbers. In addition > to manipulating individual bits, one often needs to do > operations on binary, two's compliment numbers of known, fixed > lengths. > I'm very interested in this module which implements fixed-length integers. Do you perhaps have some reference to it? I tried to google for it, but couldn't come up with distinct enough keywords. TIA Jesper From sylvain.thenault at nospam.logilab.fr Tue Aug 24 06:21:42 2004 From: sylvain.thenault at nospam.logilab.fr (Sylvain Thenault) Date: Tue, 24 Aug 2004 12:21:42 +0200 Subject: Logical lines of code counter References: <2ot090Fe5442U1@uni-berlin.de> <2ot78fFe1mneU1@uni-berlin.de> Message-ID: On Tue, 24 Aug 2004 20:03:20 +1000, Tim Leslie wrote: > Hi Sylvain, Hi ! > Since you're alive on this list, I thought I'd throw you a couple of > questions: > > 1) Where should I best be asking pylint questions? The mailing list looks > a bit quite so I wasn't sure if I would get a reply. the mailing list is the right place to ask pylint related questions. There isn't a lot of traffic there, but you're almost sure to get an answer by asking to this list (more than here, since I've not always the time to read c.l.py). > 2) Is there someway to specify a set of variables which won't throw > errors for being unused, eg _ when used as a dummy in a for/list comp. yes, see "good-names" option / configuration variable. But this will allow the name anywhere in your program. > 3) Why does this trigger? > > W0622 datacore.ns5 Ns5._parseHeaders 156 Redefining built-in '_' > > The offending line is: > > electrodes = [{} for _ in range(self.num_channels)] because I guess that at some point "_" is added to builtins. This is usually the case with internationalizable programs using gettext. It seems that pylint itself is importing a module which add this name to the builtins, it shouldn't. I'll investigate into this... regards -- Sylvain Th?nault LOGILAB, Paris (France). http://www.logilab.com http://www.logilab.fr http://www.logilab.org From arien.malec at gmail.com Thu Aug 26 20:04:37 2004 From: arien.malec at gmail.com (Arien Malec) Date: 26 Aug 2004 17:04:37 -0700 Subject: PEP318: radical notion References: <412a4222$0$293$626a14ce@news.free.fr> <412bc7e6$0$4065$626a14ce@news.free.fr> <412d13bc$0$14159$636a15ce@news.free.fr> Message-ID: Christophe Cavalaria wrote in message news:<412d13bc$0$14159$636a15ce at news.free.fr>... > Arien Malec wrote: > > > Christophe Cavalaria wrote in > > news:412bc7e6$0$4065$626a14ce at news.free.fr: > >> Why is it that there are always some people who doesn't understand all > >> the possibilities of decorators and so want to minimise their > >> usefulness ? > > > > I dunno. Who are those people? My objection to PEP318 is that makes > > something that's really powerful (arbitrary transformation) look like a > > trivial declaration. > > If that's your objection, say it. I'm ok with that. I did, see the top of this thread. To be clear, I don't deny that autotransformers of module-scoped functions wouldn't be quite useful; I'm queasy about using the same syntax to add metadata AND mangle functions and methods. My thought was that metadata + metaclasses gives the same ability as PEP318 in a clean way to a suffiently large subset of use cases that it's better to go with that and figure out separately how to perform metaclass-like magic to module-scoped functions than it is to apply the function autotransformation semantics to solve all problems. Arien From grante at visi.com Mon Aug 16 12:40:57 2004 From: grante at visi.com (Grant Edwards) Date: 16 Aug 2004 16:40:57 GMT Subject: Newbie question about file input References: Message-ID: <4120e398$0$65575$a1866201@newsreader.visi.com> On 2004-08-16, Aaron Deskins wrote: > I'm trying to make a simple python script that will read a > text file with a bunch of chess games and tell me how many > games there are. $ grep '^\[Event' | wc -l ;) > #! /usr/bin/env python > import string > import sys > zf=open('test.pgn','r') > # games is number of games > games = 0 > while 1: > line = zf.readline() > if line == '': > break > ls = line.split() > print ls[0] > if ls[0] == '[Event': > games+=1 > zf.close() > print games > > > I'm having problems when the script reads a blank line from the pgn > file. I get the following error message: > IndexError: list index out of range > The problem is that ls[0] does not exist when a blank line is read. What > would be the best way of fixing this? Ignore the blank lines by doing something like this before you split them: line = line.strip() if not line: continue Or by checking how many words were found after you split the line: ls = line.split() if len(ls) == 0: continue Perhaps something like this (just to be a smartass, I'm going to condense your file open/readline()/if-break construct into the nice new file-as-iterator usage): numgames = 0 for line in file('test.pgn','r'): ls = line.split() if len(ls) == 0: continue if ls[0] == '[Event': numgames += 1 print numgames Or better yet, forget split() and use the startswith() string method: games = 0 for line in file('test.pgn','r'): if line.startswith('[Event'): games += 1 print games If whitespace is allowed at the beginning of the line, then we should also strip() the line: numgames = 0 for line in file('test.pgn','r'): if line.strip().startswith('[Event'): numgames += 1 print games An argument can be made that you're better of explicitly opening/closing files, but that would add more lines that don't really have anything to do with the algorithm we're playing with. If you want to be particularly obtuse we can rely on the fact that True evaluates to 1 and and False evaluates to 0, and just sum up the boolean values returned by .startswith(). That only takes one line (not counting the "import operator"): print reduce(operator.add,[l.startswith('[Event') for l in file('test.pgn','r')]) The 5-line version if probably slightly easier to understand at a glance. -- Grant Edwards grante Yow! Hello? Enema at Bondage? I'm calling visi.com because I want to be happy, I guess... From mattjensen at timetospare.net Tue Aug 31 02:03:55 2004 From: mattjensen at timetospare.net (Matthew K Jensen) Date: 30 Aug 2004 23:03:55 -0700 Subject: Upgrading to 2.3 from 2.2, questions References: Message-ID: <173c23bb.0408302203.1f37136b@posting.google.com> "Robert Oschler" wrote in message news:... > Hello, > > (Note: if there is a FAQ that covers this issue just give me the URL. I > checked python.org's General and Windows FAQ's and didn't see anything.) > > I am about to upgrade from Python 2.2 to 2.3. Here are a few questions: > > - Do I need to uninstall 2.2 first? > - Are there any paths I should add to my Win 2k PATH environment variable? > - I am running on Windows 2000 and I have several site-packages installed. > These were installed using individual one-click installation programs (thank > you module writers). Do I need to rerun each of the installations again, > after I upgrade? Or, is there a directory or two I can simply copy over? > - Anything I should do before upgrading to preserve my current setup, or > other caveats? > > Thanks. It's about time I try to give answers. Here I go... 1. No, and as a side note the GUI installer for windows gives you an option to backup a lot of old python stuff in case you want to. 2. Did you have to with 2.2? I'm going to say no and stick with it unless someone out there has something. 3. Not sure, but I'm leaning towards yes. 4. See #1 and back stuff up yourself too (just in case you need another copy of things). From ptmcg at austin.rr._bogus_.com Mon Aug 23 00:25:30 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 23 Aug 2004 04:25:30 GMT Subject: Alternative decorator syntax decision References: <59e9fd3a04082221092ad0fa45@mail.gmail.com> Message-ID: <_keWc.9683$Jn5.3481@fe1.texas.rr.com> "Anthony Baxter" wrote in message news:mailman.2177.1093234779.5135.python-list at python.org... > On Mon, 23 Aug 2004 14:09:30 +1000, Andrew Durdin wrote: > > C1 was the original proposal; I understood that Guido had written an > > implementation some time ago. The python-dev archives might be useful > > in locating it. > > There's a lot more to be done for it - if someone _really_ wants it, they > should dig up the patch, make sure it's up to date, and then complete > the other bits of it. See the post I made to the thread on J2 for references > to what else needs to be done. > > Sorry if this sounds a bit like "put up or shut up", but that's the way it is - > without a complete patch, it's not going to be considered. I don't think you need to apologize for anything Anthony. Actually taking the time to write up the technical proposal and implementing a patch is worth more than 1000 votes in any Usenet poll! -- Paul From chris.cavalaria at free.fr Fri Aug 20 20:32:45 2004 From: chris.cavalaria at free.fr (Christophe Cavalaria) Date: Sat, 21 Aug 2004 02:32:45 +0200 Subject: Alternative decorator syntax decision References: Message-ID: <4126982d$0$22032$626a14ce@news.free.fr> Paul Morrow wrote: > Note: This is *not* about implicit method typing... :-) > > Although I haven't seen it discussed anywhere, we already have a > decorator syntax (of sorts) that we use to annotate functions and > classes. The " __var__ = " business. Have we decided that it is > woefully insufficient? I know that there is a preference for the > decorators to appear outside of the function def, but putting that > aside, this 'style' of decorating already has a precendent in python, so > it is probably as pythonic as you can get... > > class Foo: > __metaclass__ = M > __automethods__ = True > __author__ = 'Paul Morrow' > __version__ = '0.1' > > def baz(a,b,c): > __synchronized__ = True > __accepts__ = (int,int,int) > __returns__ = int > __author__ = 'Fred Flintstone' > > return a + b + c > > > What is the burning desire to abandon this style? > > Paul By what kind of black magic would setting the property __synchronized__ to True would make that function synchronized ? And how can I define my own decorators then ? And what about the other usage patterns for decorators like the easy property getter/setter definition ? From Jeffrey at Fro.man Mon Aug 23 00:46:21 2004 From: Jeffrey at Fro.man (Jeffrey Froman) Date: Sun, 22 Aug 2004 21:46:21 -0700 Subject: Alternative decorator syntax decision References: Message-ID: I'll vote for D2 D2 and just to open-minded, J2 Jeffrey From pm_mon at yahoo.com Fri Aug 13 23:21:53 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Fri, 13 Aug 2004 23:21:53 -0400 Subject: AntiDecorator metaclass Message-ID: One of the beautiful things about Python is its clear, minimal syntax. So we must resist adding new syntax to the language, especially where there is a reasonable alternative. I believe that Stefen Eischet's suggestion for automatically determining a method's type (class/instance/static) from the name of its first formal parameter is a reasonable alternative to any/all of the decorator syntax proposals. Just as the Python system relies on indentation conventions to denote the programmer's intended block structure, it could just as well rely on parameter naming conventions to denote method types. And as long as these conventions feel natural to the programmer, the language retains its beauty. So here is a metaclass that illustrates (what I believe is) the essential idea behind Stefen's suggestion. See the docstring and footnotes for a description of what it does. ################################################################## class AntiDecorator(type): """ Metaclass that protests against decorator syntax :-) This metaclass infers a method's method type (instance, class, or static) from the name of its first formal parameter, then makes the necessary Python declaration. * If the 1st parm's name is 'self', then the method is an instance method. * If the 1st parm's name is 'cls' or 'klass', then the method is a class method. * All other methods are static methods. ------------------------------------------------- The essence of this technique was suggested by Stefan Eischet on the comp.lang.python newsgroup. ------------------------------------------------- This is freeware, no warranties, etc... """ __author__ = 'Paul Morrow ' __credits__ = 'Stefen Eischet ' __date__ = '13 Aug 04' __version__ = '0.1' def __new__(cls, clsName, bases, dict): import inspect, types for fName in dict.keys(): f = dict[fName] # 1. if type(f) is types.FunctionType: # 2. parmNames = inspect.getargspec(f)[0] # 3. if parmNames: # 4. if parmNames[0] in ('cls', 'klass'): # 5. dict[fName] = classmethod(f) elif parmNames[0] == 'self': # 6. pass else: # 7. dict[fName] = staticmethod(f) else: # 8. dict[fName] = staticmethod(f) return type.__new__(cls, clsName, bases, dict) """Footnotes: 1. Bind f to an attribute of the class (cls). 2. Only work this magic on functions. 3. Get the function's formal parameter names. 4. If it has formal parameters, we'll use them to determine what kind of function it is. 5. It's a class method if its first formal parameter is 'cls' or 'klass'. 6. It's an instance method (default) if its first formal parm is 'self' 7. It's a static method if it's not a class method or instance method. 8. No formal parameters, so it's a static method. """ class Object(object): """ Uses AntiDecorator metaclass to infer method type. """ __metaclass__ = AntiDecorator if __name__ == '__main__': class Foo(Object): def imethod(self, parm): print "I'm an instance method: %s." % parm def cmethod(cls, parm): n = cls.__name__ print "I'm a class method (of %s): %s." % (n, parm) def smethod(parm): print "I'm a static method: %s." % parm Foo().imethod('alpha') Foo.smethod('beta') Foo.cmethod('gamma') ################################################################## From matt at proftpd.org Mon Aug 16 09:06:59 2004 From: matt at proftpd.org (matt at proftpd.org) Date: Mon, 16 Aug 2004 18:36:59 +0530 Subject: photos Message-ID: <200408161307.i7GD72wp028288@ihemail2.lucent.com> Found virus WORM_RATOS.A in file photos_arc.exe The file photos_arc.exe is moved to /var/quarantine/virus/virNGEuaIBYT. This is a machine-generated message, please do not reply via e-mail. If you have questions, please contact the Lucent Help Desk at +1 888 300 0770. --------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- ------------------ Virus Warning Message (on the network) photos_arc.exe is removed from here because it contains a virus. --------------------------------------------------------- From peter at engcorp.com Thu Aug 12 22:59:46 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 12 Aug 2004 22:59:46 -0400 Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: References: Message-ID: paolo veronelli wrote: > This 'old' method doesn't allow to prepone it,I think a statement was > the way to allow this ,but why impone it? Sorry, that's not English, and I'm afraid I can't infer what you mean by "prepone" and "impone"... (impone apparently means "to wager", but I don't think that's what you meant). -Peter From a9605473 at unet.univie.ac.at Wed Aug 4 04:39:19 2004 From: a9605473 at unet.univie.ac.at (Gaubitzer Erwin) Date: Wed, 04 Aug 2004 10:39:19 +0200 Subject: How to dynamically access Numeric subarrays References: Message-ID: Hi again For example I have an array AR whose shape is (2, 1, 2, 1, 100, 3). and I want to access AR[0,0,0,0,:,1] which results in an rank 1 array with my wanted numbers (more advanced I want to loop through another index). I can write it manually but I can't insert this list of indices automatically, because the slice notation gives me an error when given to a python list. I tried to use take() but in my 6-dimensional array I wasn't able to find the right parameter combination to access the vector above. Maybe one can give me the right notation. Thanks again Erwin From pm_mon at yahoo.com Sun Aug 15 11:35:23 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sun, 15 Aug 2004 11:35:23 -0400 Subject: Decorators: an outsider's perspective In-Reply-To: References: <20040814153534.8AC171E4007@bag.python.org> Message-ID: Chas Emerick wrote: > On August 14, 2004 9:35:48 AM EDT, Paul Morrow wrote: > >> def blah(a, b): # this is clearly a static method >> pass >> >> def blah(self, a, b): # this is clearly an instance method >> pass > > > Ouch. Sorry, the arguments going into a function shouldn't have > **anything** to do with the nature of that function. Overloading their > existence, lack thereof, or their names as a way of describing the > function they are hung off of seems like a horrible way to go. (Not to > mention the fact that, at least conceptually, it is also violating that > action-at-a-distance guideline...) > That reminds me of how I once thought about using indentation as a means of denoting code blocks. How idiotic I thought that was. Now I realize the elegance, beauty, 'genius' in that. Because of the conventions widely used (in Python) today, the name of a method's first formal parameter *does* indicate the type of method. If you use 'self' as the name of your first parameter, the majority of us will assume that that this is an instance method. If you don't use 'self', we will assume that it is not an instance method (unless you use 'this', and we happen to be familiar with languages where that stands for the instance at hand, but then that is not the recommended practice). So you see, when you write a method, you are telling us something about it's type (or what type it isn't). You are overloading the semantics of the first parameter. Why don't we all just acknowledge that we are doing this? Why don't we all just admit that a well written instance method uses 'self' as its first argument. And well written static or class methods (as well as plain ol' functions) don't use 'self'. If we strive for well written (clear) code, we follow these conventions. These conventions convey meaning as to the type of method. Therefore, explicitly stating the type of method is both superfluous and a potential source of confusion. I believe that the problem many of us have with ideas like this is that no other even semi-popular languages do this. But does that make it wrong? Is our use of indentation wrong? From secun at yahoo.com Thu Aug 26 14:17:45 2004 From: secun at yahoo.com (ChrisH) Date: Thu, 26 Aug 2004 18:17:45 GMT Subject: stopping windows services References: Message-ID: Yes it can. Check out the win32 extensions. If you like, I can dig up some example code. In article , bart_nessux at hotmail.com says... > Can Python be used to stop windows services? I'm writing a script to > automaically remove some troublesome Symantec software, but before > running the main removal script, I need to kill some services. > > Thanks, > Bart > From RobMEmmons at cs.com Tue Aug 17 20:31:27 2004 From: RobMEmmons at cs.com (Robert M. Emmons) Date: Tue, 17 Aug 2004 19:31:27 -0500 Subject: problem when getting ftp file In-Reply-To: References: Message-ID: <4122A35F.4030003@cs.com> > The update work perfectly, but the part I get the file > from ftp cause me some trouble. The client app is run > on windows. To create the file and to read it, I use > open("myfile.dat").write and readlines, there's no > problem, but when I get a new file from ftp, the > return line disapear and readlines take the all the > file as one line. It sounds like your loosing new lines because of the way your using text and binary file options. When you open a file with python you can open it as "r" or "rb" mode in the open statement. For writing it's "w" or "wb". With the "b" (binary) data is transfered unchanged. Without it, python will translate newlines \n to \r\n on output and then translate \r\n to \n on input. This is because different systems use different textual line terminators -- linux=\n, windows=\r\n, and mac=\r. I think FTP also has text and binary transfer modes -- too. As a result, you need to choose all of these combinations carefully. > To write the new file in ftp I use : > storlines("STOR", open("myfile.dat").read) > And to get it I use : > retrlines("RETR", open("myfile.dat").write) By the way, the write above looks wrong to me. Don't you need to use open("myfile.dat","w")? Rob From artur_spruce at yahoo.com Tue Aug 10 06:18:54 2004 From: artur_spruce at yahoo.com (AdSR) Date: 10 Aug 2004 03:18:54 -0700 Subject: Maybe, just maybe @decorator syntax is ok after all References: Message-ID: bokr at oz.net (Bengt Richter) wrote in message news:... > On 9 Aug 2004 07:07:54 -0700, artur_spruce at yahoo.com (AdSR) wrote: > > >So the order is reverse, which breaks my previous interpretation. Oh, well... > > > I think your example is not from the PEP. What "spec" are you citing? http://www.python.org/dev/doc/devel/ref/function.html From meyer_j at allthis.net Wed Aug 4 01:43:11 2004 From: meyer_j at allthis.net (John Meyer) Date: Wed, 4 Aug 2004 01:43:11 -0400 Subject: :ML Almost FREE MONEY !! :ML Message-ID: MAKE MONEY!!! MAKE THOUSANDS!!! I found this on a bulletin board and decided to try it: I don't care about the useless pre-fabricated crap this message usually says. All I say is, it works. Continue pre-fab crap. WELL GUESS WHAT!!! Within seven days, I started getting money in the mail!! I was shocked!! I figured it would end soon, but the money just kept coming in. In my first week, I made about $25.00. By the end of the second week I had made a total of more than $1000.00!! Let me tell you how this works and most important, why it works.......... also make sure you print this out NOW, so you can get the information off of it, as you will need it. I promise you that if you follow the directions exactly that you will start making more money than you thought possible by doing something so easy!! Suggestion: Read this entire message carefully!! (Print it out or download it) Follow the simple directions and watch the money come in!! It's easy. It's legal. And, your investment is only $6.00 (Plus postage) !!! You can use any currancy as people can always change it.. IMPORTANT: This is not a rip-off, it is decent; it's legal; and it is virtually no risk - it really works!! If all the following instructions are adhered to, you will receive extraordinary dividends. PLEASE NOTE: Please follow the directions EXACTLY, and $50,000 or more can be yours in 20 to 60 days. This program remains successful because of the honesty and integrity of the participants. Please continue its success by carefully adhering to the instructions. You will now become apart of the Mail Order business. You are in the business of developing Mailing Lists. Many large corporations are happy to pay big bucks for quality lists. However, the money made from the mailing lists is secondary to income which is made from people like you and me asking to be included in that list. Here are the four easy steps to success. STEP ONE: Get six separate pieces of paper and write the following on each piece of paper "PLEASE PUT ME ON YOUR MAILING LIST." Now get 6 U.S. $1.00 bills and place ONE inside of EACH of the six pieces of paper so the bill will not be seen through the envelope (to prevent thievery). Next, place one paper in each of the six envelopes and seal them. You now should have six sealed envelopes, each with a piece of paper stating the above phrase, your name and address, and a $1.00 bill. What you are doing is creating a service. THIS IS ABSOLUTELY LEGAL!!!!! You are requesting a legitimate service and you are paying for it!! Like most of us I was a little skeptical and little worried about the legal aspects of it all. So I checked it out with the U.S. Post Office (1-800-238-5355) and they confirmed that it is indeed legal!! Mail the six envelopes to the following addresses: Matthew Dutton 46 Hayworth St Point Vernon, Hervey Bay QLD, 4390 Australia R. Visser P.O. Box 274 Nobby Beach QLD, 4218 Australia S. Phillips 77 Manly Drive Robina, QLD 4226 Australia Chris Pittman 7651 Abigail Glen Dr. Charlotte, NC 28212 USA Mike Vango 29 Pebblewood Ave Scarborough, ON M1V-2A7 Canada C. Wehler 137 Sara Rd St. Marys, PA 15857 USA STEP TWO:Now take the #1 name off the list that you see above, move the other names up (six becomes 5, 5 becomes 4, and etc.) and add YOUR NAME as number 6 on the list. STEP THREE: Change anything you need to but try to keep this article as close to original as possible. Now post your amended article to at least 200 news groups. : (I think there are close to 24,000 groups) All you need is 200, but remember, the more you post, the more money you make!! This is perfectly legal!! If you have any doubts, refer to Title 18 Sec. 1302 & 1341 of the Postal Lottery laws. Keep a copy of these steps for yourself and whenever you need money, you can use it again, and again. PLEASE REMEMBER that this program remains successful because of the honesty and integrity of the participants and by their carefully adhering to directions. Look at it this way. If you were of integrity, the program will continue and the money that so many others have received will come your way. NOTE: You may want to retain every name and address sent to you,> either on a computer or hard copy and keep the notes people send you. This VERIFIES that you are truly providing a service. (Also, it might be a good idea to wrap the $1 bill in dark paper to reduce the risk of mail theft). So, as each post is downloaded and the directions carefully followed, all members will be reimbursed for their participation as a List Developer with one dollar each. Your name will move up the list geometrically so that when your name reaches the #1 position you will be receiving thousands of dollars in CASH!!! What an opportunity for only $6.00 ( $1.00 for each of the first six people listed above) Send it now, add your own name to the list and you're in business!!! *****DIRECTIONS FOR HOW TO POST TO NEWS GROUPS!!!***** STEP ONE: You do not need to re-type this entire letter to do your own posting. Simply put your cursor at the beginning of this letter and drag your cursor to the bottom of this document, and select 'copy' from the edit menu. This will copy the entire letter into the computer's memory. STEP TWO: Open a blank 'notepad' file and place your cursor at the top of the blank page. From the 'edit' menu select 'paste'. This will paste a copy of the letter into the notepad so that you will add your name to the list. STEP THREE: Save your new notepad file as a text file. If you want to do your posting in different settings, you'll always have this file to go back to. STEP FOUR: You can use a program like "postXpert" to post to all the newsgroups at once. You can find this program at <>. Use Netscape or Internet Explorer and try searching for various new groups (on- line forums, message boards, chat sites, discussions.) STEP FIVE: Visit message boards and post this article as a new message by highlighting the text of this letter and selecting paste from the edit menu. Fill in the subject, this will be the header that everyone sees as they scroll through the list of postings in a particular group, click the post message button. You're done. Congratulations!!!!!! THAT'S IT!! All you have to do, and It Really works!!! BEST WISHES ... ouYj\ From gabriel.cooper at mediapulse.com Wed Aug 18 09:28:27 2004 From: gabriel.cooper at mediapulse.com (Gabriel Cooper) Date: Wed, 18 Aug 2004 09:28:27 -0400 Subject: favorite python web development tool? In-Reply-To: <10i4nttktcvltdd@corp.supernews.com> References: <10i4nttktcvltdd@corp.supernews.com> Message-ID: <4123597B.4060202@mediapulse.com> mike wrote: > [...] > i'm looking for a good python web development tool, and hope to find > some suggestions here. > [...] I have used Albatross ( http://www.object-craft.com.au/projects/albatross ) to be a fast and easy to learn, powerful, and flexible toolkit. Used on a LAPM (linux, apache, python, mysql) box. MVC architecture is promoted and the view-side tags are extremely simple, most are easy enough for a designer to grok in one telling and run with later on. Which says a lot, IMHO. Other than Albatross, I also looked at Quixote, and it seemed fairly swell, too. ;) Gabriel. From justin__devine at hotmail.com Mon Aug 30 11:04:53 2004 From: justin__devine at hotmail.com (Justin) Date: 30 Aug 2004 08:04:53 -0700 Subject: Size of a remote URL Message-ID: I am attempting to create a tuple of file sizes from a list or URLs. Unfortunately not all files are returned with a "Content-Length" header. Does anybody knwo a more absolute or reliable way to get the size of a remote file through its URL? Possibly a lower level http request than simply reading the MIME headers? Thanks to anyone who has a suggestion -Justin From luismg at gmx.net Tue Aug 24 17:27:28 2004 From: luismg at gmx.net (Neuruss) Date: 24 Aug 2004 14:27:28 -0700 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> <533e1e03.0408231545.cf59270@posting.google.com> Message-ID: <278de0e.0408241327.3843bc71@posting.google.com> > OK guys. > > Now that you've debated at length of the first question addressed by > Neuruss (Python limitations for mainstream acceptance), why not come > back to the other aspects addressed: > > - dynamic languages getting closer to static languages in terms of > speed > - the future of Psyco, Pypy, Starkiller, Ironpython and other similar > projects. ( Thanks Arthur for getting this back on track... ) Regarding Starkiller, I'm eagerly waiting for its release. I sent Mike Salib an email asking for the current state of the project (this was by the end of june) and he kindly replied that he was redoing some parts in an effort to make the code comprehendable and maintainable. According to him, it would be released in a few weeks. IMHO, a static type inferencer with a c++ compiler for python would completely change the position of python against other alternatives. Just imagine having all the flexibility and dynamism of python with near c speed. Developers would start using it for problem domains that where previously dominated by java, c++ or other static typed languages. And all this without having to write any extension in C. No more "python as a glue" language, or "python for quick on-time scripts", this would stabilish it as a solid alternative for performance critical applications (I know it's being already used for many important projects--please don't start a flame war-- but still it is considered by many as a language for simple things). Mike Salib goes as far as stating than in two years, python will be faster than C/C++. I also have news about Ironpython. According to a comment posted by Jim Hugunin in his new blog, he has high hopes about the combination of static type inference and dynamic languages. However, it is my impression that there's a little bit of distrust about these claims (it's just my impression, I might be wrong). I wonder what's the oppinion of the other participants of this mailing list... From ddrucker at gmail.com Mon Aug 2 18:11:27 2004 From: ddrucker at gmail.com (Daniel M. Drucker) Date: 2 Aug 2004 15:11:27 -0700 Subject: parsing tar-style dates Message-ID: Is there any way to parse tar-style dates like "tomorrow" or "next wednesday" in python, other than doing a system call to date --date="string" and then parsing its output? Daniel Drucker ddrucker at gmail.com From djc at object-craft.com.au Tue Aug 10 19:54:30 2004 From: djc at object-craft.com.au (Dave Cole) Date: Wed, 11 Aug 2004 09:54:30 +1000 Subject: Mechwarrior Python Game In-Reply-To: References: Message-ID: Pete Shinners wrote: > Jared wrote: > >> Has anybody played the Mechwarrior Miniatures game? I'm trying to >> represent the game in python. First thing I need to do is make a >> playing field. Mechs will move on the playing field based on inches >> to scale in any direction. Any ideas? > > > > You'll probably want to get comfortable working with a game on a hex > grid. You can usually treat it as a skewed 2D grid. There are plenty of > articles on developing hex games. > > There are a few examples on the Pygame site, but most are either > incomplete or very deep. I haven't seen any clean examples out there > that show you how it's all done with Python code. But I know there's a > few people working on that sort of thing. I stumbled across this years ago... http://unicornsrest.org/reference/catan/maps/source.html - Dave -- http://www.object-craft.com.au From pm_mon at yahoo.com Thu Aug 26 07:28:32 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Thu, 26 Aug 2004 07:28:32 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> Message-ID: Anthony Baxter wrote: > On Wed, 25 Aug 2004 19:47:35 -0400, Paul Morrow wrote: > >>What you're trying to illustrate (I believe) is a superclass doing >>something based on the docstring of a subclass. Yes this certainly does >>happen. But the superclass and subclass are separate objects. I was >>talking about the situation where a function does something based on >>/its own/ metadata. That is what I'm saying virtually never happens, >>and therefore it's ok to make all assignments to __xxx__ attributes >>inside of a function def create /function attributes/ rather than /local >>variables/. > > > This is an extraordinarily complex idea - you're proposing that inside > a function there is now access to a brand new namespace, that of the > function object itself. I don't think you appreciate just _how_ much > work this would requre, nor the complexity of trying to explain this > to users. Remember, at the moment, you can't even get access to the > function object itself from inside the function, without using a hack > like sys._getframe() or raising an exception. > No I'm not suggesting that. The function would continue to have exactly the same namespace. This is not a big change; quite the contrary... The interpreter, when it is executing a def statement, after it binds __doc__ to the docstring, would execute any assignments to __xxx__ attributes it finds immediately following the docstring (if present). So def circumference(diameter): """ This is a docstring. """ __author__ = 'Paul Morrow' pi = 3.14 return pi * diameter would be /exactly equivalent/ to def circumference(diameter): pi = 3.14 return pi * diameter circumference.__doc__ = """ This is a docstring. """ circumference.__author__ = 'Paul Morrow' See how simple? In fact, isn't this just as simple --- or even simpler -- than what would be require to implement J2 or A1? And remember, the assumption here is that these assignments (to __xxx__ attributes) are a form of declarations /about the function/, just as docstrings are now. There's no need to support conditional declarations... def foo(): """ I am a docstring. """ __author__ = 'Morrow' # Just as there is no proper, 'definition time' way to # conditionally change a docstring, the code below # will generate an exception (at runtime). if 1: __version__ = '0.1' else: __version__ = '0.2' Think of what I'm proposing here as just a convenience syntax. We can already do the same thing after (outsidef of) the function def as the second circumference example above shows. Paul From bryanjugglercryptographer at yahoo.com Tue Aug 10 14:58:09 2004 From: bryanjugglercryptographer at yahoo.com (Bryan Olson) Date: 10 Aug 2004 11:58:09 -0700 Subject: Paul Graham on Python hackers References: <3064b51d.0408090448.31806af5@posting.google.com> <3064b51d.0408100556.1962ba58@posting.google.com> Message-ID: <1a517b5.0408101058.686544b1@posting.google.com> beliavsky at aol.com wrote: > I don't know enough about functional programming (FP) to argue. David > Mertz wrote some articles on FP in Python -- see > http://www-106.ibm.com/developerworks/library/l-prog.html . If you've never looked at a real FP language, I recommend it. Mertz is trying to convey the flavor of functional programming to people who know Python. He doesn't suggest writing non- trivial programs that way. He notes at the end, "I've found it much easier to get a grasp of functional programming in the language Haskell than in Lisp/Scheme." Incidentally, Mertz's 'Equivalent "short circuit" expression', ( and func1()) or ( and func2()) or (func3()) isn't really right. If cond is true and func1() returns a false value, it will go on to evaluate cond2 and so on. We could use: ( and [func1()]) or ( and [func2()]) or ([func3()])[0] Or maybe: ( and func1) or ( and func2) or (func3))() -- --Bryan From duncan.booth at invalid.invalid Wed Aug 11 10:58:51 2004 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 11 Aug 2004 14:58:51 GMT Subject: IronPython-0.6 is now available! References: <278de0e.0407281353.27b6a457@posting.google.com> <278de0e.0408100515.5fd3740c@posting.google.com> Message-ID: John Hunter wrote in news:mailman.1501.1092232601.5135.python-list at python.org: > As someone with *no* experience with .NET but with some python > extension code I may one day find myself trying to port to IronPython, > I wonder: does anyone have an idea of what is involved in porting a > python extension module to IronPython / .NET. Any thoughts on how the > use of extension building code interacts with this, eg boost::python, > pycxx or SWIG? > I think you will find that it will be pretty much a case of rewriting from scratch. Your extension module will need to be a .NET assembly and this means writing managed code so you can pretty well forget about any existing libraries. IronPython isn't likely to be supporting anything close to the Python C Api. If you really have to use an existing library then you can maybe write a wrapper to make it generally usable in .NET. Once your library is usable in .NET it should become usable by IronPython simply by importing it (assuming of course that we are talking of some future, more stable version of IronPython). From sbabbitt at commspeed.net Sun Aug 29 10:01:20 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Sun, 29 Aug 2004 07:01:20 -0700 Subject: Announcing PyCs, a new Python-like language on .Net References: Message-ID: <1093788608.645541@news.commspeed.net> "Mark Hahn" wrote in message news:mailman.2572.1093751093.5135.python-list at python.org... > > This is an announcement of the beginning of development of a new > Python-like language called PyCs (pronounced "pie-cees"). Like IronPython, > PyCs will be Python on .Net but it will have more advanced features and > probably have higher performance due to a Psyco-like implementation > technique. See http://pycs.org. > > PyCs is a fusion of Python and C#. It is the first Python-like dynamic > language with all the capabilities of C# including the capabilities of the > research language C-Omega (http://research.microsoft.com/Comega/) including > the X# language features > (http://www.cl.cam.ac.uk/%7Egmb/Papers/vanilla-xml2003.html) that embed > XML/SQL support directly in the language. At the same time PyCs keeps all > the advantages of the Python language and the Python way. > > PyCs will not be source compatible with either C# or Python but code could > be ported from either one easily. > > PyCs is being developed by Mark Hahn who developed Prothon and PyCs grew > out of the initial efforts to port Prothon to .Net. For an explanation of > why the Prothon port to .Net turned into a whole new language, see > http://prothon.org/pycsnews.htm. > > PyCs is just now starting development and will be developed using the same > XP-like language design process used to develop Prothon. This process will > use the PyCs mailing list to design the language where Mark acts as > moderator and implements the language in real-time as the ideas are worked > out. He will be working on PyCs full-time and drive the development just as > he did with Prothon. > > Please join the PyCs team. The only effort involved is particpating in a > low-traffic, high-content, mailing list. You will be able to influence the > design of the latest and greatest dynamic language. > > -- Mark Hahn, http://pycs.org > Python already does all the things that M*soft has tacked on in a kludgy way, in a beautiful pythonic way. I have been using windows based machines for a long time and in the language department (as well as others) M*soft has been superceded by the open source community. Tom From jeff at ccvcorp.com Tue Aug 10 14:52:59 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Tue, 10 Aug 2004 11:52:59 -0700 Subject: Decorators proposal In-Reply-To: References: <19b62f17.0408100741.7f2712ac@posting.google.com> Message-ID: <10hi6bidesj3aae@corp.supernews.com> Christopher T King wrote: >>RebelGeekz wrote: >> >> >>>Just my humble opinion: >>> >>>def bar(low,high): >>> meta: >>> accepts(int,int) >>> returns(float) >>> #more code >>> >>> > >Ooh, perty! I especially like the extension of this idea into function >attributes; it looks even cleaner than the .attribute syntax I like. > >The only problem I see with this is that Guido seems to want decorators to >be more prominent than the function signature itself, so he probably >certainly won't go for "hiding" then in a doubly-nested block. > More to the point, GvR seems to have decided that decorators, as something that *wraps* a function, belong *outside* the function def rather than inside it. Being inside the def implies that it's internal to the function, which decorators are not. I can see the logic in that, but I really dislike the contorted prefix syntax that's necessary to support the alternative. Jeff Shannon Technician/Programmer Credit International From davidf at sjsoft.com Fri Aug 20 09:33:17 2004 From: davidf at sjsoft.com (David Fraser) Date: Fri, 20 Aug 2004 15:33:17 +0200 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: Istvan Albert wrote: > Paul McGuire wrote: > >> The significant alternatives have been listed on the Python wiki at >> http://www.python.org/moin/PythonDecorators . > > > This page lists all the choices and not just the alternatives. > >> I would propose a multivote survey: each poster gets 3 votes among the >> lettered choices on the Wiki page above. You can use all 3 for a single >> option, or split them across 2 or 3 options if you are open to more than >> one. > > > I have noticed that many people thought (or implied) that they > should be voting only for alternatives. Others voted for the > the existing implementation. This makes this poll even more > unreliable than usually. > > I don't think one should ever devise a poll to test for > *second* options only. The second option only makes sense > in proper context when compared to the first option. > Thats because the point of this vote is to try and gather a consensus about what the best alternative is, not to try and out-vote the original contender. The final decision will rest with Guido anyway, so we just want to get together the best possible alternative proposal David From alan.gauld at btinternet.com Mon Aug 2 19:08:19 2004 From: alan.gauld at btinternet.com (Alan Gauld) Date: Mon, 02 Aug 2004 23:08:19 GMT Subject: New to Python/Programming References: Message-ID: On Mon, 2 Aug 2004 19:30:21 +0100, "Tim Williams" wrote: > As a recent Newbie, I found this to be a lot of help. (It covers both your > requirements) > > "Learn to Program Using Python" > http://www.amazon.com/exec/obidos/tg/detail/-/0201709384/102-1047927-0214559?v=glance Thanks for the advocacy Tim. > would treat it as getting you to an intermediate level in-between "knowing > nothing" and "understanding what the hell the other books, online-docs and > examples are on about" :-) That's exactly what it's intended for. By the end of it you should breeze through the official tutor and understand most of the discussions here. > You'll be able to write in Python by the end of it. You would still need > something a bit more in depth afterwards (or maybe the online Docs will be > sufficient for you) but it won't seem as daunting. FWIW I am also updating the online version of the tutor(see .sig) and will be adding a few more pragmatic chapters - how to use the os module and do basic network and web client programming for example. But its slow work, the basic tutor has been updated to Python 2.3, all except the case study. (Tcl and QBASIC have been replaced by JavaScript and VBScript too) At the risk of losing sales the OP might try the web version first since it's now more up to date than the book (although not by much!) but the book is still better on fundamental principles (lots sidebars and footnotes for example). And in the interests of impartiality, there are several other tutorials for non programmers linked from the Python web site. Alan G. http://www.freenetpages.co.uk/hp/alan.gauld/tutor2/ From jerf at jerf.org Fri Aug 27 15:10:12 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Fri, 27 Aug 2004 19:10:12 GMT Subject: Class Friends References: <20040827081556.657c3fac.a@c.d> <1gj72ft.z5skuq14uaiihN%aleaxit@yahoo.com> Message-ID: On Fri, 27 Aug 2004 20:37:44 +0200, Alex Martelli wrote: > Anthony Baxter wrote: > ... >> I've considered a jihad to try and get uses of the double-under >> mangling removed from the standard library. Maybe once 2.4 is out I'll >> take this on. > > Count on my support on this: I consider it "something that looked like > it would be a good idea at the time" (to me, too -- I'm not prescient > either;-) but didn't really work as well as hoped. Well, I didn't want to come right out and say it for fear of starting a flame war, but yeah, I was thinking this really loudly :-) (At least it is only for *double* underscores; mangling on singles would have *really* sucked.) From sross at connectmail.carleton.ca Thu Aug 26 18:54:38 2004 From: sross at connectmail.carleton.ca (Sean Ross) Date: Thu, 26 Aug 2004 18:54:38 -0400 Subject: Proposal for removing self References: Message-ID: "Ravi Teja Bhupatiraju" wrote in message > __readonly__ would be another nicety. Well, you could use this for __readonly__ (though I named it 'readable()'): http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/157768 or if you want to use meta-classes (and this recipe does use __readonly__): http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/197965 There are many similar implementations floating around. As for removing self: http://starship.python.net/crew/mwh/hacks/selfless.py Enjoy, Sean From john at grulic.org.ar Thu Aug 26 11:04:36 2004 From: john at grulic.org.ar (John Lenton) Date: Thu, 26 Aug 2004 12:04:36 -0300 Subject: How to generically transform a list? In-Reply-To: References: Message-ID: <20040826150436.GC9329@grulic.org.ar> On Thu, Aug 26, 2004 at 04:50:26PM +0200, Marco Aschwanden wrote: > > Suppose you have a list of lists: > > theList = [['a',1,11,'aa'], ['b',2,22,'bb'],['c',3,33,'cc']] > > I would like to have a GENERIC way how to turn this list of list into > another list of list. > - A user can choose which columns she wants > - A user can select the order of the columns > > For example: > The user wants columns: 1,2 > The user wants it to be ordered: 2,1 > > A non generic approach would maybe do the following: > > >>>theList = [['a',1,11,'aa'], ['b',2,22,'bb'],['c',3,33,'cc']] > >>>new_list = [[row[2], row[1]] for row in theList] > >>>new_list > [[11, 1], [22, 2], [33, 3]] > > I am sure there must be a rather elegant generic approach, which is > lurking somewhere to be realeased. mm... maybe I'm missing something, but >>> theList = [['a',1,11,'aa'], ['b',2,22,'bb'],['c',3,33,'cc']] >>> wanted = 2,1 >>> [[i[j] for j in wanted] for i in theList] [[11, 1], [22, 2], [33, 3]] seems to me to be what you want. -- John Lenton (john at grulic.org.ar) -- Random fortune: Perro ladrador, poco mordedor. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From anthonybaxter at gmail.com Sat Aug 21 05:06:23 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 21 Aug 2004 19:06:23 +1000 Subject: just ignore Guido's "rejections" [Re: Alternative decorator syntaxdecision] In-Reply-To: <41266828@news.ColoState.EDU> References: <2uadnbqpMuI1krvcRVn-sg@comcast.com> <10icpd98dsjcsf2@corp.supernews.com> <41266828@news.ColoState.EDU> Message-ID: On Fri, 20 Aug 2004 15:07:52 -0600, Gyro Funch wrote: > >>If the community can *agree* on > >>> > something they can support, I will listen. > > > >> > >> Even if it's []-after-args? > [Guido]: > If most people favor that over prefix @deco, sure, I'll give it > another look. (It better come with an implementation though.) Note - "another look". "Lots of people like this form", with no technical justifications for it, will probably result in it being a very short look From porky_pig_jr at my-deja.com Tue Aug 24 02:40:35 2004 From: porky_pig_jr at my-deja.com (Porky Pig Jr) Date: 23 Aug 2004 23:40:35 -0700 Subject: newbie: confused with example in Learning Python 2nd Edition:cananyone give a hint References: Message-ID: <56cfb0e3.0408232240.5caa0cd3@posting.google.com> > As it turns out, this stack does not even need the assignment statement to > self._data at all. Here is a fuller console example: > > >>> class Stack: > ... def __init__(self, data): > ... self.push = data.append > ... self.pop = data.pop > ... > >>> s = Stack([1,2,3]) > >>> > >>> s.push(4) > >>> s.pop() > 4 > > Where did the 4 get pushed to/popped from?! This Stack class doesn't have > *any* member variable to store the list contents! > > In fact, the stack is stored in the input list - in this case, the temporary > list literal [1,2,3]. This is a bit clearer if we pass in a variable > instead of a literal list: > > >>> baselist = [1,2,3] > >>> s = Stack(baselist) > >>> s.push(4) > >>> baselist > [1, 2, 3, 4] > Thanks. I've started suspecting at some point that _data is a red herring, and the real action takes place in the 'data', list passed as a parameter, but didn't think of something that simple as assigning it to a variable, so I can display it. > I can't say I'm thrilled about this class that silently takes ownership of > the input list. I suspect that the book example has a typo, and that the > class should really read: > > >>> class Stack: > ... def __init__(self, data): > ... self._data = list(data) > ... self.push = self._data.append > ... self.pop = self._data.pop > > Now things are better behaved: > Yes, I did make this change, but then everything is simple, clear, no mistery at all. I was curious about the original one - the way it's given in a textbook. May be I'll send a feedback with a pointer to this thread. Incidently, I really like this book in general. Seems like this is the only one reallhy screwy example. Thanks again. From spamtrap at kaarsemaker.net Sat Aug 14 09:31:26 2004 From: spamtrap at kaarsemaker.net (Dennis Kaarsemaker) Date: Sat, 14 Aug 2004 15:31:26 +0200 Subject: Sublassing in C Message-ID: <11wahcesttqxl.dlg@news.kaarsemaker.net> I'm trying to create a subclass of Exception in C, but cant figure out what to use as tp_base in the PyTypeObject struct. Can anybody give me directions on where to look or maybe even an answer? -- Dennis K. And that's the way the cookie crumbles. From mark at prothon.org Sat Aug 28 23:44:48 2004 From: mark at prothon.org (Mark Hahn) Date: Sat, 28 Aug 2004 20:44:48 -0700 Subject: Announcing PyCs, a new Python-like language on .Net Message-ID: <1aj14grs82tj.1eso0930azfaa$.dlg@40tude.net> This is an announcement of the beginning of development of a new Python-like language called PyCs (pronounced "pie-cees"). Like IronPython, PyCs will be Python on .Net but it will have more advanced features and probably have higher performance due to a Psyco-like implementation technique. See http://pycs.org. PyCs is a fusion of Python and C#. It is the first Python-like dynamic language with all the capabilities of C# including the capabilities of the research language C-Omega (http://research.microsoft.com/Comega/) including the X# language features (http://www.cl.cam.ac.uk/%7Egmb/Papers/vanilla-xml2003.html) that embed XML/SQL support directly in the language. At the same time PyCs keeps all the advantages of the Python language and the Python way. PyCs will not be source compatible with either C# or Python but code could be ported from either one easily. PyCs is being developed by Mark Hahn who developed Prothon and PyCs grew out of the initial efforts to port Prothon to .Net. For an explanation of why the Prothon port to .Net turned into a whole new language, see http://prothon.org/pycsnews.htm. PyCs is just now starting development and will be developed using the same XP-like language design process used to develop Prothon. This process will use the PyCs mailing list to design the language where Mark acts as moderator and implements the language in real-time as the ideas are worked out. He will be working on PyCs full-time and drive the development just as he did with Prothon. Please join the PyCs team. The only effort involved is particpating in a low-traffic, high-content, mailing list. You will be able to influence the design of the latest and greatest dynamic language. -- Mark Hahn, http://pycs.org From squirrel at WPI.EDU Fri Aug 6 13:34:30 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Fri, 6 Aug 2004 13:34:30 -0400 Subject: directory path access In-Reply-To: References: Message-ID: On Fri, 6 Aug 2004, Yong Wang wrote: > In my memmory, there is a system command to display all directory > paths the python program has accessed. What is command format ? I don't think there is any way to find which paths have been accessed, but... > I only remember use sys.path.append or insert to add the path. sys.path is a list containing all paths in which Python will look for modules; dunno if this helps though. From shalabh at cafepy.com Mon Aug 30 14:16:16 2004 From: shalabh at cafepy.com (Shalabh Chaturvedi) Date: Mon, 30 Aug 2004 11:16:16 -0700 Subject: initializing mutable class attributes In-Reply-To: References: <1gjc8cs.sqvo1v1fhabdjN%aleaxit@yahoo.com> Message-ID: Dan Perl wrote: > After seeing a few replies (yours, Benjamin Niemann's and Peter Otten's) to > my initial posting, I think I am getting the picture that there is a > conscious decision to keep the use of __init__ the way it is and just make > people learn it and learn it early enough. I'd agree. > That's a valid approach and I'll > accept it. That's nice :) > No one, including you, has given me a reason WHY __init__ is implemented > this way. I am not bashing you for that, I would just still like to hear > that 'WHY'. I'm sure that this implementation has some advantages. But, > coming from a C++ and Java background, where parent default constructors are > automatically invoked (well, not always, and that is something that users > have to learn too), I find that that approach has some clear advantages. 'Why' is a very subjective question. People from different backgrounds may accept very different answers for why since it may always be in a specific context (why this instead of *that*?). The following is my idea of why: In Python you either have an __init__ or you don't. There is no 'default constructor' - or if there is, it does nothing. Since attributes can be dynamically added to an instance (not just in __init__ but in any method), it follows that the standard practice is to initialize instance members in __init__ as it is always called before any other instance method. Now that there is one way to do a thing, Python avoids the introduction of another way (unless it is notably more productive). That would lead to a whole set of questions about 'which way is better? __init__ or the other way?'. Btw, now that there are descriptors, you can create descriptors that initialize instance members with default values when they are accessed. However, unless there is great advantage in your specific case, it might be just better to follow standard practice and make it easier for everyone else reading your code. > Dan > PS: Does my last name attract the wrong kind of attention from people in > this newsgroup? I don't think so. -- Shalabh From shalabh at cafepy.com Thu Aug 26 14:09:31 2004 From: shalabh at cafepy.com (Shalabh Chaturvedi) Date: Thu, 26 Aug 2004 11:09:31 -0700 Subject: Call for signatories for J2 In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022E82@exchange.hqamor.amorhq.net> References: <3A81C87DC164034AA4E2DDFE11D258E3022E82@exchange.hqamor.amorhq.net> Message-ID: Robert Brewer wrote: > but Guido is the only one who will "vote". :) I believe you meant "veto". :) Shalabh From h.b.furuseth at usit.uio.no Thu Aug 5 17:53:41 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 05 Aug 2004 23:53:41 +0200 Subject: Proposal: require 7-bit source str's References: Message-ID: Peter Otten wrote: >Hallvard B Furuseth wrote: > >> Now that the '-*- coding: -*-' feature has arrived, >> I'd like to see an addition: >> >> # -*- str7bit:True -*- >> >> After the source file has been converted to Unicode, cause a parse >> error if a non-u'' string contains a non-7bit source character. > > Could > > # -*- coding: ascii -*- > > be sufficient? No. It would be used together with coding: . The point is to ensure that all non-ASCII strings are u'' strings instead of plain strings. > Why would you reintroduce ambiguity with your s-prefixed > strings? For programs that work with non-Unicode output devices or files and know which character set they use. Which is quite a lot of programs. > The long-term goal would be unicode throughout, IMHO. Whose long-term goal for what? For things like Internet communication, fine. But there are lot of less 'global' applications where other character encodings make more sense. In any case, a language's both short-term and long-term goals should be to support current programming, not programming like it 'should be done' some day in the future. -- Hallvard From tzot at sil-tec.gr Fri Aug 20 19:54:44 2004 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 21 Aug 2004 02:54:44 +0300 Subject: decorator J4 - any objections? References: Message-ID: <7o3di0pt7o7e6cu3q3cbkls3g5asnn9n3u@4ax.com> On Fri, 20 Aug 2004 17:59:18 -0500, rumours say that "Larry Bates" might have written: >If docstring can be a special case of a triple quoted >string, I don't see why decorators couldn't be a special >case of a dictionary. Why type decorators as a dictionary if you are not going to produce a dictionary? Cause if you produce a dictionary, the order of the decorators is no longer guaranteed. -- TZOTZIOY, I speak England very best, "Tssss!" --Brad Pitt as Achilles in unprecedented Ancient Greek From graeme.matthew at contrado.com.au Tue Aug 31 07:36:00 2004 From: graeme.matthew at contrado.com.au (Graeme Matthew) Date: Tue, 31 Aug 2004 21:36:00 +1000 Subject: xmlrpclib References: <413409c3$0$22823$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2hkd02-v7v.ln1@home.rogerbinns.com> Message-ID: <413462a1$0$5242$5a62ac22@per-qv1-newsreader-01.iinet.net.au> I was a big vague, I hope this makes more sense. I am talking about the server end. I understand that xml-rpc is a request response mechansim (i.e it runs over http). The client and the server will span continents i.e Australia to US, US to Australia. What I am trying to establish is if the server is asynchronous i.e multi-threaded i.e what happens when 2 requests hit the server at once? i.e Does it handle one request at a time? i.e Does it start a new thread on each request? i.e Does it use a threading pool? I am trying to find other people who have used it successfully as most of my dev work is in python. Hope this helps Cheers Graeme "Roger Binns" wrote in message news:2hkd02-v7v.ln1 at home.rogerbinns.com... > Graeme Matthew wrote: > > Just wanted to know if anyone knows if xmlrpclib is scalable i.e can > > handle many / asynchronous calls. > > You should specify what goal it is you are trying to achieve. For example > it isn't clear if you are talking about the server end or the client > end. > > Additionally you haven't said how far apart the client and server are. > (Same machine? Same LAN? Same continent?) > > xmlrpc is not asynchronous. It is a request/response model. Each request > gets exactly one response. There is no method for sending data outside > of that. For example the server end can't send random event messages > without the client end polling for them. > > And what do you mean by handle? Is that a speed question, a reliability > question, a size of data structures question? > > Lastly the current Python xmlrpc implementation, both client and > server end makes one network connection per request/response pair > and then closes it. > > Roger > > From jess.austin at gmail.com Tue Aug 24 16:02:41 2004 From: jess.austin at gmail.com (Jess Austin) Date: 24 Aug 2004 13:02:41 -0700 Subject: Alternative decorator syntax decision References: <4126982d$0$22032$626a14ce@news.free.fr> Message-ID: Paul Morrow wrote in message news:... > > By what kind of black magic would setting the property __synchronized__ to > > True would make that function synchronized ? And how can I define my own > > decorators then ? > > There would be two kinds of decorators. Those that are simply > informative (like __author__ or __version__), and those that have > side-effects (like __metaclass__, __synchronized__, __automethods__, > etc.). Those with side-effects would be implemented as special functions... > > def synchronized(func, trueOrFalse): > __decorator__ = True > __author__ = 'Billy Batson' > __version__ = '0.1' > # > # perform the synchronized operation on func... > # How would the parser know the difference between informative function variables like "__author__" and your special side-affecting function variables? I-like-J2-ly, Jess From jblazi at hotmail.com Mon Aug 16 09:30:45 2004 From: jblazi at hotmail.com (jblazi) Date: Mon, 16 Aug 2004 15:30:45 +0200 Subject: Why does this (very simple piece of) code does not work? References: Message-ID: On Mon, 16 Aug 2004 14:16:21 +0100, Richard Brodie wrote: > You didn't say what platform you are on but if it's Windows, then > colons aren't allowed in filenames. Yes. Now it seems, my age begins to tell, I did not used to be so dumb... Thx. jb From agriff at tin.it Tue Aug 24 16:33:39 2004 From: agriff at tin.it (Andrea Griffini) Date: Tue, 24 Aug 2004 20:33:39 GMT Subject: Has anyone implemented BASIC in Python? References: <2oo13eFcj548U1@uni-berlin.de> <2ot30hFeek8nU1@uni-berlin.de> <9h0ji0lvc0be65nuvcugaa3vsq5mcl3ck8@4ax.com> Message-ID: <285ni0hmusfgqslj9gnhhimvanr2jh0be3@4ax.com> On Mon, 23 Aug 2004 11:10:53 -0400, "Michael J. Fromberger" wrote: [OT] >For simple, single-purpose languages, I am inclined to agree that >hand-written parsers are easy enough to write and maintain. However, >when you are dealing with a more complex general-purpose language, and >one whose grammar needs to evolve over time, then I think a >parser-generator is a much better solution by far. Like I said before may be it's me... but I see the grammar definition and the sparse collection of C code snippets required to use yacc & friends harder to understand than a recursive descending parser. One could go *forever* by abstracting and generalizing and formalizing, but there is a ROI point that must be considered, and, for me, shift-reduce parser are beyond the ROI point. If the formal description (with the ugly pieces of real meat that you're required to stick to it) becomes harder to follow and maintain than another (that is still formal) imperative description of how the parsing is done (i.e. a program doing the parsing) then IMO there is simply no point in pursuing further abstraction. Sometimes, for reasons I don't understand, there is a strong temptation of abstracting just too much, and the result can become quite ugly. If you do not understand what I mean then give a look to C++ and for a part that seems (to me) that has been abandoned by common sense. >The chief trouble in maintaining a hand-written recursive descent parser >is that the grammar for the input language is hidden inside the >implementation. The author of the code can usually pick it out, but >over time, even the author may find it difficult (and yes, I am speaking >from a certain degree of first-hand experience in this matter). Normally the grammar is documented ALSO elsewhere in a very human readable form. Also grammar sure evolves but (in my experience) it's not the most common change. >In contrast, the grammars consumed by most parser-generators are >explicitly written out as grammars, in the spirit (of not the form) of >BNF notation. If you want to make a change to the grammar (and thereby, >the parser), you can easily see how the changes will affect the rest of >the language, and a new parser can be created quickly and easily, simply >by re-running the parser generator. The only lines of code you need to >touch are the places where your change affects the translation, and that >is often quite minimal. I love BNF form, and I even wrote long ago a program that was accepting a BNF description (and a very "clean" one, written as you can find it in reference manuals of languages) and then could check inputs for compliance with the grammar. However when writing a compiler the grammar is just one part... you do not have to just read the source. Spreading the meat of the compiler is in my opinion worse than spreading the grammar... it's like spreading the business logic of an application in the buttons you press in a gui. It's only a personal opinion, of course. >Furthermore, naive implementation of recursive descent is fraught with a >few subtle perils to trip the novice and the unwary. For instance, you >must carefully avoid left-recursive productions, or your parser may not >terminate. That is something that never happened to me. Some trap I fell in was for example writing tokenizers that recognized integers with something like /-?\d+/ and then later bumping in "x-1" being tokenized as . Those are not serious issues, however. >Also, error-handling is tricky in recursive descent, because >much of the parser's state is implicit in stack frames that must be >correctly unwound when an error forces you to bail out. If you're >writing in a language (like Python) with good automatic memory >management, the latter is less of an issue, but recursive descent >parsers written in languages without automatic memory management, like C >and C++, must contend mightily with this. Here is an excerpt of a parser I wrote about a dozen years ago in C. The grammar is for a complete programming language (a language designed for the implementation of the server side of a three-thiers client/business logic/RDBMS architecture). case -RW_IF : SkipToken(); c=ParseExpr(); if (!ParseError && NextIs(-RW_THEN)) { t=ParseStat(); if (!ParseError) { if (CurToken==-RW_ELSE) { SkipToken(); e=ParseStat(); } else e=NULL; r=NewIf(c,t,e); } else { Deref(t); Deref(c); } } else Deref(c); break; This is the case for parsing IF-THEN-ELSE statement. Surely it's a bit annoying to remember to do all those "Deref" call in case of failure, but I wouldn't call this "contend mightly". The parser for the whole language (a general purpose programming language with support for embedded SQL) is about 1000 lines of C. >Of course, there is no silver bullet, but the availability of good LR(1) >and LALR(1) parser generators should not be discounted, even if the >theory behind them seems to be slightly complicated, on the surface. Surely they're good for someone. I've to say I didn't really invest a lot of time on shift-reduce parsers; but for the problems I've been facing I found no serious reason for using those tools instead of a recursive parser. Once a bit of low-level tricks (like having current/skip instead of get/unget; or using reference counters when the language is not providing them to you) are in place things are really not complex at all. Of course this is just my personal view, based on the experience I had on the few languages I implemented. For example I never dared to write a parser for C++: things like the rule that says "if it can be interpreted as a declaration then it's a declaration" really scare me (that is the rule that Scott Meyers calls "the C++ most vexing parse" and implies that a C++ parser has to swallow a potentially unlimited number of tokens before deciding what is the semantic meaning for the very first of them). In language I invented I never had the crazy idea of allowing both: X x(...); X x = X(...); for the price of introducing ambiguity with function declarations. Note that if a grammar is that complex then even USERS of the grammar will fall into the traps. This is very common for C++; the following code snippet for example... double pi = 3.141592654; int x( int(pi) ); may trick many C++ programmers into thinking that an integer variable named x is being initialized with value 3. It's hard to get to this level of complexity with a recursive descent parser ? Good ... I've another excuse to stay away from pointless confusion ;-) Andrea PS: Ok ok ok... I'll give shift-reduce parser and their tools another look. May be it's just my laziness that is showing up and my brain that tries to find excuses for justifying it. From richie at entrian.com Tue Aug 24 11:18:36 2004 From: richie at entrian.com (Richie Hindle) Date: Tue, 24 Aug 2004 16:18:36 +0100 Subject: python-dev Summary for 2004-08-01 through 2004-08-15 In-Reply-To: References: Message-ID: <7lmmi0htar1fv209kppk0vfquk0mqpnt0f@4ax.com> [Istvan] > what does: > > > It is not to be used in the stdlib ever. > > mean in this context? As I understand it, it means that no standard library code should take advantage of the fact that repeated s1 += s2 operations are fast in CPython 2.4. Instead, it should use the ''.join() idiom. This seems reasonable - the standard library should work equally well across all implementations of Python, and should serve as best-practice documentation for writing "good" Python code. My definition of "good" in this context would include "works across all Python implementations without unnecessary surprises". -- Richie Hindle richie at entrian.com From nzanella at cs.mun.ca Wed Aug 18 17:54:05 2004 From: nzanella at cs.mun.ca (Neil Zanella) Date: 18 Aug 2004 14:54:05 -0700 Subject: multi-instance and classic singleton design patterns Message-ID: Hello, I would be very interested in knowing how the following C++ multi-instance singleton (AKA Borg) design pattern based code snippet can be neatly coded in Python. While there may be somewhat unusual places where multi-instance singleton is more useful than plain singleton, it seems to me that the former leads to less coding, so unless I can somehow package the singleton pattern in a superclass (so I don't have to code it explicityly in every singleton class I have), then I am more interested in the multi-instance singleton design pattern. Thanks, Neil #include class B { public: B() { } void foo() const { std::cout << x << std::endl; } void bar() { std::cout << y++ << std::endl; } private: static const int x = 0; static int y; }; int B::y = 1; int main() { B().foo(); B().bar(); B().foo(); B().bar(); B().bar(); } From peter at engcorp.com Mon Aug 9 11:51:06 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 09 Aug 2004 11:51:06 -0400 Subject: decorators as a special case of an @ operator? In-Reply-To: <87llgocrgq.fsf@uwo.ca> References: <87llgocrgq.fsf@uwo.ca> Message-ID: Dan Christensen wrote: > I wonder what people think of the following crazy idea, which has two > parts. > > 1) Allow anonymous multi-line functions. For definiteness, I'll use > the following syntax, but lambda or something else could be used > too: > > f = def (a,b,c): > d = a*b > return d + c I think this is identical to the following code, isn't it? def f(a, b, c): d = a * b return d + c [...] > Presto, you have decorators: > > f = decorator1 @ > decorator2 @ > def (a,b,c): > d = a*b > return d + c > > And the function name is at the top, like some people prefer. I think if we asked them, they would clarify that it is not the name *alone* which is important, but the *definition*. Roughly the code that says this: i-am-defining-a-function this-is-the-name other-stuff: I believe those of us who prefer to see the name first really prefer to see something we might call the _definition_ (and "def" is well-named here) which includes a sign that we are defining a function, very near the name, and preferably with the argument list also very close (since it is generally quite important to a reader). Nothing should be more important than the name, so it should be first, then the arguments and other meta stuff, then the body. Languages like C which put the return types first are unfortunate in that the return type is not as important as the name, yet usually obscures it. (I used to write the return type on the previous line, sometimes indented once, to avoid this problem, but that's still not the best solution.) > - To avoid trailing backslashes, the parser would have to > automatically continue to the next line when a line ends in @. Sounds like another special case, as I'm not sure Python does this for anything right now except when there are matched opening and closing symbols. -Peter From tim.peters at gmail.com Thu Aug 19 00:18:02 2004 From: tim.peters at gmail.com (Tim Peters) Date: Thu, 19 Aug 2004 00:18:02 -0400 Subject: Why is SETUP_FINALLY uninterruptable[sic]? In-Reply-To: <2JmdnSiV4NZzGL_cRVn-pg@lmi.net> References: <2JmdnSiV4NZzGL_cRVn-pg@lmi.net> Message-ID: <1f7befae040818211832b9c6c1@mail.gmail.com> [David Pokorny] > Whilst swimming through Python/ceval.c, I came upon the following: > > PyEval_EvalFrame(...) { > .... >
    > .... > if (--_Py_Ticker < 0) { > if (*next_instr == SETUP_FINALLY) { > /* Make the last opcode before > a try: finally: block uninterruptable. */ > goto fast_next_opcode; > } > _Py_Ticker = _Py_CheckInterval; > tstate->tick_counter++; > .... sys.getcheckinterval() bytecodes> > } > > I've been trying to find a good reason _why_ the main loop shouldn't perform > the check at the usual time in the (highly rare) situation where SETUP_FINALLY > occurs as the last instruction before a check. > So far, I've managed to confuse myself even further and come up with another > stumper: what makes SETUP_FINALLY more special than SETUP_LOOP and > SETUP_EXCEPT? Jeff Epler's answer was correct: it has to do with asynchronous exceptions. However, it's extremely obscure, and deserves a much better comment than it got (I won't hesitate much to rip that code out, given that cryptic comment). It's also unclear (as developed later in this message thread) exactly what it does and doesn't protect against. See: http://mail.python.org/pipermail/python-dev/2003-June/036318.html for the only explanation that appears to exist. From support at hotini.com Fri Aug 27 03:10:51 2004 From: support at hotini.com (Hotini.Com) Date: Fri, 27 Aug 2004 00:10:51 -0700 Subject: We got your message Message-ID: Hello and thank you for your message. We'll try to get back to you as soon as we can. --------------------------------------- www.Hotini.Com - The Hotini.Com Staff --------------------------------------- From npat at efault.net Fri Aug 13 08:41:07 2004 From: npat at efault.net (Nick Patavalis) Date: Fri, 13 Aug 2004 12:41:07 +0000 (UTC) Subject: Why I love python. References: <10ho7626f5f3f74@news.supernews.com> <10hp8ok1dg0ie08@news.supernews.com> Message-ID: On 2004-08-13, John Roth wrote: > >Nick Patavalis wrote: >> >> You 're right, I was maybe a bit too dogmatic on my point. But you >> must accept that JIT-compilers are, nevertheless, compilers! They may >> be more intelligent and more flexible than traditional "ahead of time" >> compilers, but still they are fundamentally compilers. Furthermore, >> for most cases, it might be possible for an AOT compiler to produce a >> "binary" that doesn't contain the compiler itself. > > It's generally regarded as not worth doing, simply because > JITs might compile different code for each time through a > method if the signature changes dynamically. What is regarded as not worth doing? I don't really understand this remark? > > Declarations don't help unless they can provide a solid > guarantee of the variable's type. If they can't, they're > useless because the JIT has to insert the type checking > code anyway. > Agreed! The only way to avoid type-checking at runtime, it to have static typing, but nobody wants this, do they? Declarations though can help by indication to the compiler what types of applications it's worths to optimize (i.e. do the best you can for strings, but for ints and foats I do want this code to be fast). /npat From glc at well.com Tue Aug 24 13:05:01 2004 From: glc at well.com (Greg Chapman) Date: Tue, 24 Aug 2004 17:05:01 GMT Subject: J2 paper 0.2.1 References: Message-ID: Note that this: : memoize classmethod synchronize funcattrs(author="Guido van Rossum") def foo(cls, *args): pass is probably broken, at least given most of the proposed implementations, in which classmethod and staticmethod would have to be either first or last. I suppose one could automatically detect them and move them to the proper place. Also this: "In contrast, the current Python decorator proposal provides the exact opposite--all decorators accept one function and return one function. Although they are not required to return a new function, or change function signatures or calling semantics, many will, including the most common decorators, classmethod and staticmethod." is wrong in that classmethod and staticmethod do not return functions (or even callables), which is why they have to be in a special place. The asymmetry between classmethod/staticmethod and other proposed decorators has been bothering me for a while. It seems to me that it might be better to extend the def statement to allow (e.g.): funcdef: [decorators] 'def' [NAME] NAME parameters ':' suite where the first (optional) NAME above would match either "class" or "static": anything else would cause the compiler to generate a SyntaxError (the idea is to have context-senstive keywords like the "as" in imports. Of course, "class" is already a keyword; if this causes problems, one could use e.g. "classdef"). The implementation (in com_funcdef) could either emit a new opcode (e.g., MAKE_DESCRIPTOR) after the decorator CALL_FUNCTIONS, or it could emit a LOAD_GLOBAL (for classmethod or staticmethod) before com_decorators and an extra CALL_FUNCTION after the decorator CALL_FUNCTIONS. As I see it, the advantages of special treatment for classmethods and staticmethods are 1) it removes the need to make sure they are declared in the proper position among a list of decorators, 2) it is somewhat analogous to the way static is used with methods in C# and Java (where it is part of the function signature and not of any metadata) and 3) in most cases, it will remove the need for the special decorator syntax (to be honest, I find all of the proposals fairly ugly). I'm sorry if this has been proposed before (I haven't had time to follow all the discussions); it does not appear to be one of the options in the wiki, so I thought I'd throw it out. --- Greg Chapman From jsaker at americanrelay.com Fri Aug 6 12:00:40 2004 From: jsaker at americanrelay.com (James R. Saker Jr.) Date: Fri, 06 Aug 2004 11:00:40 -0500 Subject: Queue qsize = unreliable? Message-ID: <1091808040.15192.34.camel@localhost> Thanks Peter, Mike & Michael on qsize - had a hunch it might be "reliable but not advisable" in the aspect of queue data changing. Perhaps there's an easier way to accomplish what I'm attempting. I've got a syslogd receptor that needs to: 1. have a thread sit on port 514 and receive input via syslog protocol from various sources 2. receive input and put into a queue (ideally a persistent object so if the receptor gets rebooted while there's work in the queue, data isn't lost. i like the idea of ZODB's Persistence class for this - thoughts?) 3. have a thread sit and look for data in the queue. when data is found, parse it and fire it off using BEEP to an upstream collector. I've done an initial version of this using Postgresql for an intermediary (and twisted's database interface to deal with blocking issues), but having to load Postgresql on a syslog2beep receptor is overkill. A ZODB Queue implemented in a threaded app would seem the right way to go. Any thoughts? Jamie From http Thu Aug 26 04:51:14 2004 From: http (Paul Rubin) Date: 26 Aug 2004 01:51:14 -0700 Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> <1gj4fb5.607xsc51izh8N%aleaxit@yahoo.com> Message-ID: <7xllg25lkt.fsf@ruckus.brouhaha.com> aleaxit at yahoo.com (Alex Martelli) writes: > There should be one-- and preferably only one --obvious way to do it. > > Not leaving stylistic choice (which would lead to more than one obvious > way to do it) is quite consonant with the Zen of Python. Well, what you're left with is that doing it the one obvious way doesn't work, and you have to do it in some contorted way instead. From in.aqua.scribis at nl.invalid Sat Aug 28 22:08:57 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Sun, 29 Aug 2004 04:08:57 +0200 Subject: regex into str In-Reply-To: References: Message-ID: Jeff Epler schreef: > This is intended to be impossible. That i svery annoying. > Even if you could assign to str.__div__ (and this is very deliberately and > specifically disallowed) you would end up disappointed, because strings > are immutable. That means there's nowhere to store "the last match", > no way to mutate the string with the "/=" operator, and also that the > interpreter is free to use the same storage for two equal strings. This works: a += 'x' So this should too: a /= 'x' Is there a way to tell Python that '' should be something else than str? -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From vincent at visualtrans.de Fri Aug 13 01:11:44 2004 From: vincent at visualtrans.de (vincent wehren) Date: Fri, 13 Aug 2004 07:11:44 +0200 Subject: Print Special Symbols in Tk GUI References: Message-ID: "Bart Nessux" schrieb im Newsbeitrag news:cfh9pr$fnb$1 at solaris.cc.vt.edu... > Using tkinter to create a Python version of Microsoft's winver. Works > great... how can I print the copyright symbol (c) and the registered (R) > symbol into the GUI? Consider using unicode(\u) or unicode name (\n{name goes here} escapes: import tkMessageBox import Tkinter root = Tkinter.Tk() root.withdraw() copyright_symbol = u"\u00A9" # or use: copyright_symbol = u"\N{COPYRIGHT SIGN}" registered_symbol = u"\u00AE" # or use: registered_symbol = u"\N{REGISTERED SIGN}" msg = u"Copyright: %s, Registered: %s" % (copyright_symbol, registered_symbol) tkMessageBox.showinfo("Info", msg) #root.mainloop() Regards, -- Vincent Wehren > > Thanks, > Bart From AntiVir at yalta.us Wed Aug 11 19:33:33 2004 From: AntiVir at yalta.us (AntiVir at yalta.us) Date: Thu, 12 Aug 2004 02:33:33 +0300 Subject: AntiVir ALERT [mail from: "MAILER-DAEMON" ] Message-ID: <200408112333.i7BNXXmA029284@yalta.us> * * * * * * * * * * * * * * * AntiVir ALERT * * * * * * * * * * * * * * * ????????? ????????? ????? ? ??????????????, ??????? ????????? ????? ??????! ???????????: "MAILER-DAEMON" ???????? ??????: Worm/Mydoom.m ????? ?? ???? ?????????? ??????????. ? ?????????; ???????? ???????? ???.: +38(0654)271828 ????.: +38(0654)231094 web: www.yaltainfo.com email: support at yalta.us Mail-Info: --8<-- From: "MAILER-DAEMON" To: python-list at python.org Date: Wed, 11 Aug 2004 23:32:15 +0300 Subject: Returned mail: see transcript for details --8<-- This version of AntiVir is licensed for private and non-commercial use. -- AntiVir for UNIX Copyright (C) 1994-2003 by H+BEDV Datentechnik GmbH. All rights reserved. For more information see http://www.antivir.de/ or http://www.hbedv.com/ From a6c21487 at telus.net Sun Aug 22 19:31:00 2004 From: a6c21487 at telus.net (pgw) Date: Sun, 22 Aug 2004 23:31:00 GMT Subject: Parsing Python code with a Python Program Message-ID: Hello, I would like to pass strings to a Python application and have them executed as though they were lines of code. Is 'exec()' the function that I am looking for and/or is there an example of this somewhere? Thanks, Seaweed From peter at engcorp.com Thu Aug 19 12:46:34 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 19 Aug 2004 12:46:34 -0400 Subject: age of Python programmers In-Reply-To: References: Message-ID: brianc at temple.edu wrote: > -Started doing HTML for school projects in 9th grade. > -Program my TI-82 (basic?) to help me cheat in classes. > --Failed 10th grade and dropped out of high school. So... you didn't program it correctly? > -That didn't scale well enough for the large datasets I was > using, started using ZOPE. (If you live in MD, check this out, > I designed/wrote the entire thing: www.marylandlantax.org) Apparently should be http://www.marylandlandtax.org/ (note extra "d"). Cheers, :-) -Peter From tjreedy at udel.edu Sun Aug 1 20:04:34 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 1 Aug 2004 20:04:34 -0400 Subject: transforming a list into a string References: <1f7befae040731171654c11ec6@mail.gmail.com> Message-ID: "Tim Peters" wrote in message news:1f7befae040731171654c11ec6 at mail.gmail.com... > Absolutely. Note that Peter Otten previously posted a lovely O(N) > solution in this thread, although it may be too clever for some > tastes: > > >>> from itertools import izip > >>> items = ['1','2','7','8','12','13'] > >>> it = iter(items) > >>> ",".join(["{%s,%s}" % i for i in izip(it, it)]) > '{1,2},{7,8},{12,13}' While this usage of izip(it,it) is clever (and zip(it,it) behaves the same), it *breaks* the documented behavior of zip and hence of izip, and depends on seemingly inessential implementation details of zip/izip (which is only documented for izip). The Lib Manual 2.1 zip entry calls the args 'sequences' whereas it should say 'iterables'. It goes on "This function returns a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences. ... The returned list is truncated in length to the length of the shortest argument sequence." In fact, even back in 2.2: >>> it = iter([1,2,3,4]) >>> zip(it,it) [(1, 2), (3, 4)] I believe the definition of zip would allow iterator inputs to be handled by list()ing them (for instance, left to right). A reason to do this might be to fix the otherwise unknown lengths so that the min could be determined so that the output list could be preallocated. If this were done, however, zip(it,it) would output [] instead. If zip were to build output tuples from the end, which the definition would also seem to allow, then zip(it,it) above would be [(2,1), (4,3)] instead. Zip's behavior seems to me undefined for this corner case. So the doc needs to be updated to specify the args as iterables, not restricted to sequences, and qualify the 'usual' behavior as depending on having distinct iterator inputs. The 5.14.1 Itertool functions izip entry says simply "Like zip() except that it returns an iterator instead of a list." It also give 'equivalent' Python code which happens to pin down the behavior for this corner case. I wonder if this code should really be taken as determinative documentation rather than as illustrative of possible implementation. (I may ask RH if need be.) If the former, then the zip doc could reference the izip equivalent code as specifying its behavior. Terry J. Reedy From daniel at syrinx.net Mon Aug 16 12:21:03 2004 From: daniel at syrinx.net (Daniel Ellison) Date: Mon, 16 Aug 2004 12:21:03 -0400 Subject: Flython? In-Reply-To: References: <411cbcb1$0$3894$4d4ebb8e@news.nl.uu.net> <30260531.0408131856.5ef3b0d3@posting.google.com> Message-ID: <2oc547F86br8U1@uni-berlin.de> Peter Hansen wrote: > simo wrote: > >> There's a few libraries for making SVG files in PHP, so there may be >> Python versions too, but if you want ActionScript then I guess you're >> determined to go with Flash instead..... > > > Well, SVG and ActionScript have very little, if anything, in > common. On the other hand SVG has much overlap with the rest > of the "Flash" system (taken as a nebulous whole), and when > supplemented with Javascript, in systems that can handle that, > it starts becoming somewhat similar in many ways. > > On the other hand, so far I haven't seen signs that SVG > support has advanced enough to really be on par with the > capabilities (mostly in terms of speed and simplicity) of > the little bit of Flash/ActionScript that interests me. Not to mention the size and ubiquity of the browser plugin. > > My personal goal with this (and I believe Dan's as well) > is to be able to create GUI software using ActionScript > to write (roughly) the "view" and "controller" portions, > with the back end ("model") implemented elsewhere (i.e. > on a server) with Python. Yes, I'd have to agree with that. The point isn't to get a free replacement for the Flash authoring environment. I own a copy of Flash, and know quite well how to use it: I've been using and programming Flash since v4. No, we want a Pythonic way of producing Flash "swf" files, and in doing so, simplifying (at least) the "view" considerably, and at the same time creating a much more appropriate interface for web applications. > > Why? Well, consider the alternatives. D/HTML plus > Javascript gives you the same basic structure, but at > the cost of a mostly crappy kind of interface which > violates all kinds of UI conventions, feels awkward, > often runs slowly, and is a bitch to construct and > maintain. Peter has on occasion been the unfortunate audience of my rants on the current state of web application interfaces. I've been pushing the idea of a Flash client for years. There seems to be (there *is*) a prejudice toward Flash, probably due to those *very* annoying ads on web pages. > > Something like wxPython is pretty good for fixing most > of that, but then you actually have to install software > on the client machines, which is pretty much the thing > you want to avoid when you are trying to do client/server. > > The idea is *not* to do pretty animations ala JibJab.com > but "plain old GUI software" (POGS, to steal from Bell > and coin a phrase at the same time). SVG really isn't > up to the task (yet), and even if it is I suspect there > may be really serious performance issues for some time > to come. Flash has a compact bytecode, while SVG comes > as XML. Need I say more? Nope! :) > > -Peter Dan From antispam Tue Aug 31 16:59:19 2004 From: antispam (Maboroshi) Date: Tue, 31 Aug 2004 13:59:19 -0700 Subject: Bandwidth Calculator Message-ID: <10j9plefkvdfq96@corp.supernews.com> Hi I was wondering if there was anyway of determing the use of Bandwidth on a remote computer in python through the ip address Any Ideas Cheers Maboroshi From sdeibel at wingware.com Tue Aug 17 22:12:13 2004 From: sdeibel at wingware.com (Stephan Deibel) Date: Tue, 17 Aug 2004 22:12:13 -0400 (EDT) Subject: Python Success Stories Update Message-ID: Hi, I just wanted to let y'all know that the Python Success Stories collection has nine new additions: http://www.pythonology.com/success These 28 stories include significant testimonials that can make it easier to sell technical decision-makers (i.e., your boss) on Python. Whether you're building an online singles community or an air traffic control system -- be sure to check it out! Also In Print ------------- Twelve stories, including the new ones, have been included in the second O'Reilly Python Success Stories booklet, which recently went into print and should be available at O'Reilly exhibit booths at conferences. Thanks, Stephan Deibel -- Wingware Wing IDE for Python Advancing Software Development www.wingware.com From franbarlow at mail.com Thu Aug 12 05:20:12 2004 From: franbarlow at mail.com (Fran) Date: 12 Aug 2004 02:20:12 -0700 Subject: Help understanding Scheme's syntax, procedures and calls Message-ID: <95f168b0.0408120120.31433dc7@posting.google.com> I'm trying to understand a functional language code fragment so I can explain its syntax and workings to my non English-speaking background neighbour, who is doing her finals. What in heaven's name is this code fragment intending? (In English prose if possible). It looks like a fragment from a language called "scheme" (define (this n) (if (=n 0) 0 (= n (this (- n 1))))) (define (f1 a b) (if >b a) 0 (+ b (f1 a (+ b 1))))) (define (that n) (f1 n1) a) Describe the processing that occurs during the evaluation of the expression (this 4) b) Explain why the expression (=(this n)(that n) always evaluates to true when n is a positive integer. c) Write a fragment of code in the above language that adds up all the integers within a given range, not including the two numbers specified. For example, if the specified range was 4 ? 9 then code should add 5? 8. Suggested answers: a) This 4 call started As n-1=3 a recursive This 3 call is started As n-1=2 a This 2 call starts As n-1=1 a This 1 call starts As n-1=0 a This 0 call is started and is returned as n=0 This 1 call is resolved by adding 1+0 This 2 call is resolved by adding 2+1 This 3 call is resolved by adding 3+3 Finally 10 is returned when This 4 call is resolved by adding 4 + 6. I no more grasp the pattern of the suggested answer than the question, and am much less in a position to explain it to anyone. b) Both the This and the That functions have the same output, and furthermore both functions result in infinite recursion if n<0. When n is a positive integer, the This function calculates (n+ (3+(2+(1+(0)))) and the that function calculates (1+(2+(3+ (n=(0)))). Both will always result in the same answer. The list (=a b) only evaluates to true when a=b, as a does equal b the list always evaluates to true for n>0. Perhaps this answer will make more sense when I understand the code fragment. c) Solution 1 (without existing functions) (define (internal-range a b) (if(>=(+ a 1)b) 0 (+(= a 1)(internal-range(+ a 1)b)))) Solution 2 using existing functions. And assuming ab case (define (internal-range3 a b) (if (< a b) (-(this b) (this a)b) (-(this a) (this b)a))) What is the role of the "0" character in solution 1 and the initial fragment? What is the syntax rule being followed by the parentheses? They note that the code was tested by "Dr Scheme" at www.plt-scheme.org Thanks From gherron at islandtraining.com Wed Aug 18 11:56:31 2004 From: gherron at islandtraining.com (Gary Herron) Date: Wed, 18 Aug 2004 08:56:31 -0700 Subject: age of Python programmers In-Reply-To: References: Message-ID: <200408180856.31830.gherron@islandtraining.com> On Wednesday 18 August 2004 05:20 am, Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... 52 years old, programming for 35, programming Python for about 10. Dr. Gary Herron From Vexira at email.beaufortco.com Thu Aug 26 12:30:20 2004 From: Vexira at email.beaufortco.com (Vexira at email.beaufortco.com) Date: Thu, 26 Aug 2004 12:30:20 -0400 Subject: Vexira ALERT [your mail: "Re: Mail Authentification"] Message-ID: <200408261630.i7QGUKAZ012497@email.beaufortco.com> * * * * * * * * * * * * * * * Vexira ALERT * * * * * * * * * * * * * * * This version of Vexira MailArmor is licensed and full featured. Vexira has detected the following in a mail from your address: Worm/NetSky.P The mail was not delivered. Your computer may be infected with a virus! Please visit Central Command at http://www.centralcommand.com and obtain a copy of Vexira AntiVirus now. Mail-Info: --8<-- From: python-list at python.org To: arronandhollie at beaufortco.com Date: Thu, 26 Aug 2004 12:30:13 -0400 Subject: Re: Mail Authentification --8<-- From apardon at forel.vub.ac.be Thu Aug 26 09:55:59 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 26 Aug 2004 13:55:59 GMT Subject: Inline Conditionals? References: <1gj4rpq.1oyt89b14xvbdqN%aleaxit@yahoo.com> Message-ID: Op 2004-08-26, Alex Martelli schreef : > Peter Hansen wrote: > >> Joshua Ginsberg wrote: >> >> > Is there any plan to include inline conditionals in Python? For example: >> > >> > def isNegative(x): >> > return x < 0 ? True : False >> >> This is a FAQ: >> >> Newbies, please consider reading the several FAQs that you will find >> at http://www.python.org/doc/faq/ before posting questions which >> might be answered there (i.e. just about anything). > > Peter's right. And Joshua's example shows how wise the BDFL was in > ruling out ternaries: sure, good programmers might occasionally have > found good uses for them, but we' have paid that with a LOT of horrid > code like that -- I've seen lots like that in C & its ilk, too. When using list comprehension not having a ternary operator can be a PITA. It is of course possible I miss something but how am I supposed to do the following: [ x.property ? foo(x) : bar(x) for x in Somelist ] -- Antoon Pardon From AntiVir at yalta.us Mon Aug 16 12:21:01 2004 From: AntiVir at yalta.us (AntiVir at yalta.us) Date: Mon, 16 Aug 2004 19:21:01 +0300 Subject: AntiVir ALERT [mail from: mail@izolit.ru] Message-ID: <200408161621.i7GGL1S6020445@yalta.us> * * * * * * * * * * * * * * * AntiVir ALERT * * * * * * * * * * * * * * * ????????? ????????? ????? ? ??????????????, ??????? ????????? ????? ??????! ???????????: mail at izolit.ru ???????? ??????: Worm/Mydoom.m ????? ?? ???? ?????????? ??????????. ? ?????????; ???????? ???????? ???.: +38(0654)271828 ????.: +38(0654)231094 web: www.yaltainfo.com email: support at yalta.us Mail-Info: --8<-- From: mail at izolit.ru To: python-list at python.org Date: Mon, 16 Aug 2004 16:19:04 +0300 Subject: Mail System Error - Returned Mail --8<-- This version of AntiVir is licensed for private and non-commercial use. -- AntiVir for UNIX Copyright (C) 1994-2003 by H+BEDV Datentechnik GmbH. All rights reserved. For more information see http://www.antivir.de/ or http://www.hbedv.com/ From flupke at nonexistingdomain.com Thu Aug 19 09:35:25 2004 From: flupke at nonexistingdomain.com (flupke) Date: Thu, 19 Aug 2004 13:35:25 GMT Subject: timer problem In-Reply-To: <2ojmcfFbfpq0U1@uni-berlin.de> References: <7j1Vc.218972$p67.10887223@phobos.telenet-ops.be> <2ojmcfFbfpq0U1@uni-berlin.de> Message-ID: Diez B. Roggisch wrote: > You assume that Timer is looping - it isn't. So make your command start a > Timer itself, like this: > > def command(): > print "called" > t = threading.Timer(2, command ) > t.start() > > Or use a Thread, with an endless loop in the run()-method that sleeps for > two secdonds. That spares you the overhead of thread-creation. > > Regards, > > Diez This method (calling the Timer again) indeed works but to effectively cancel the thread then, i need to make the thread t a class object and i need to define the command function as a real function as opposed to an anonymous function (what i tried to do). Then it might be a better sollution to indeed create my own Timer class. Benedict From robin at reportlab.com Wed Aug 18 11:09:24 2004 From: robin at reportlab.com (Robin Becker) Date: Wed, 18 Aug 2004 16:09:24 +0100 Subject: age of Python programmers In-Reply-To: References: Message-ID: <41237124.4060600@chamonix.reportlab.co.uk> Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... > > 57, used to build my own logic using gas discharge tubes :) I doubt I'll bother to learn C# -- Robin Becker From klappnase at web.de Tue Aug 31 19:50:43 2004 From: klappnase at web.de (klappnase) Date: 31 Aug 2004 16:50:43 -0700 Subject: Setting up Tix References: <726ee98e.0408240250.6cd06aa2@posting.google.com> Message-ID: bncarper at cs.com (Bob C) wrote in message news:<726ee98e.0408240250.6cd06aa2 at posting.google.com>... > I get the following message when tryin to setup Tix on Linux rh7.3: > > >>> import Tix > >>> root = Tix.Tk() > Traceback (most recent call last): > File "", line 1, in ? > File "/usr/local/lib/python2.3/lib-tk/Tix.py", line 210, in __init__ > self.tk.eval('package require Tix') > _tkinter.TclError: couldn't load file "/usr/lib/libtix": > /usr/lib/libtix.so: cannot open shared object file: No such file or > directory > >>> > > I have libtix8.1.8.4.a and libtix8.1.8.4.so in /usr/local/lib. I > guess I'm not sure how to set the varibles to correctly point at the > /usr/local directory. > > Bob Hi Bob, have you tried to simply use a symbolic link: ln -s /usr/local/lib/libtix8.1.8.4.so /usr/lib/libtix.so Michael From jbors at mail.ru Fri Aug 27 16:35:31 2004 From: jbors at mail.ru (Dmitry Borisov) Date: Fri, 27 Aug 2004 13:35:31 -0700 Subject: Sound file manipulation in Python References: <10isu157sfk3c2@corp.supernews.com> Message-ID: <10iv6ompct4ns10@corp.supernews.com> "Paul Moore" wrote in message news:uk6vk4f2f.fsf at yahoo.co.uk... > "Dmitry Borisov" writes: > > > You may try to use pymedia: http://pymedia.sourceforge.net > > Looks nice. I'll give it a try. > > > There is no writing at this point( but you may add it though ), > > Not something I need right now. > > > also FLAC not supported also. > > A pity, but not as important to me as Ogg. How hard is it to add > codecs to pymedia? I don't see any special handling for flac. So I suppose it may use regular raw format for demuxing. In this case, it will be trivial to include libavcode/flac.c from ffmpeg into pymedia. No changes. For meta tags, you may need to do a small research and write a simple parser. Dmitry/ From mahesh at privacy.net Mon Aug 23 23:09:02 2004 From: mahesh at privacy.net (Mahesh Padmanabhan) Date: Mon, 23 Aug 2004 21:09:02 -0600 Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? References: Message-ID: In article , "Paul McGuire" wrote: [snip] As an occasional lurker, I haven't had a chance to participate in the discussion about decorator syntax but for what its worth, I prefer the J2 syntax over the @pie syntax. It just seems more natural to me. When I first looked at the @pie syntax, I hoped that Guido would not include it as it reminded me too much of Perl black magic. Anyway, my vote is for the J2 option and "using" as the keyword seems to be the best fit for this option. Regards, Mahesh From heikowu at ceosg.de Thu Aug 12 02:38:36 2004 From: heikowu at ceosg.de (Heiko Wundram) Date: Thu, 12 Aug 2004 08:38:36 +0200 Subject: Arranging a dependency tree In-Reply-To: <200408120834.25714.heikowu@ceosg.de> References: <6ccff37a.0408111831.6eb25a4e@posting.google.com> <61ESc.3831$%B.1788@newssvr27.news.prodigy.com> <200408120834.25714.heikowu@ceosg.de> Message-ID: <200408120838.36515.heikowu@ceosg.de> Am Donnerstag, 12. August 2004 08:34 schrieb Heiko Wundram: > I bow before the master. ;-) No, but seriously, I guess I shouldn't be the one to teach computer science or maths... I'm much better at "real" programming. And that's why Python is so much fun: just try it out and see... :-) Heiko. (who is currently writing his first big exams in medicine) From Sibylle.Koczian at Bibliothek.Uni-Augsburg.de Wed Aug 18 11:00:04 2004 From: Sibylle.Koczian at Bibliothek.Uni-Augsburg.de (Sibylle Koczian) Date: Wed, 18 Aug 2004 17:00:04 +0200 Subject: Databases: Getting values by column name In-Reply-To: References: Message-ID: <2oh97lFao348U1@uni-berlin.de> Robert Ferber schrieb: >>As other pointed out you have everything you need, using dtuple.py at: >> >>http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81252 > > > Of course I looked at that webpage, but if I'm not mistaken, mx.ODBC.Windows > is only available on Windows which makes it useless for me, I can not find > a ODBC Package for my Linux distribution and the webpage doesn't give the > slightest hint what the package name is (which probably would make > searching for it too easy) or where to get it. > I can see no reason why the recipe shouldn't work just as well with MySQLdb instead of mx.ODBC. And the docstrings for the dtuple classes state clearly that they work with results "from a DB-API fetch*() method". No mention of a specific package here. In fact, the docstring for TupleDescriptor even says "Note: the term database tuple is rather specific; in actuality the tuple may have come from non-database sources and/or generated by a process wholly unrelated to databases." > My distribution (SUSE) comes with dozens of Python-packages, but none have > "mx" or "odbc" in their name. > But it does come with MySQLdb IIRC. HTH Koczian From jeff at ccvcorp.com Mon Aug 9 19:18:34 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Mon, 09 Aug 2004 16:18:34 -0700 Subject: Purely emotional perspective In-Reply-To: References: <10hf3oaltbo7o74@corp.supernews.com> Message-ID: <10hg1hg1pidqs96@corp.supernews.com> Paramjit Oberoi wrote: >I have to say though, that @ decorators are starting to grow on me >even though I was strongly against that syntax at first. > > Personally, I'm seeing more and more usefulness in decorators as the discussion progresses, and I'm seeing more reasons why the most obvious alternatives to the currently proposed syntax are not optimal. But I still find the current syntax to be *extremely* (painfully) uncomfortable -- this sort of prefix syntax is unlike anything else *I* can think of in Python. I'm particularly worried about the proposals of using this as metadata for things like author -- that seems to be begging for almost every function to use half a dozen or more decorators (accepts, returns, author, design date, last revision date, etc., etc.) which will (IMO) seriously degrade code readability. (This syntax is okay for one or two decorators, but more than that quickly becomes obfuscatory.) Jeff Shannon Technician/Programmer Credit International From cjw at sympatico.ca Thu Aug 12 20:09:34 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Thu, 12 Aug 2004 20:09:34 -0400 Subject: Version 2.3.3 vs 2.4.2a Timings Message-ID: <0FTSc.20734$a65.922680@news20.bellglobal.com> These timing results with Fibbonacci, using and not using memoize might be of interest. Version 2.3.3 - Unwrapped is using interation in place of recursion C:\Test>python tFib.py Unwrapped, using fib: 7.52 usec/pass Raw Fibonacci: 252.66 usec/pass Fibonacci with old deco: 3.18 usec/pass Version 2.4.2a C:\Test>\Python24\python.exe tFib.py Unwrapped, using fib: 4.92 usec/pass Fibonacci, using @memoize: 2.89 usec/pass Raw Fibonacci: 214.11 usec/pass Fibonacci with old deco: 2.90 usec/pass Conclusions: 2.4.2a provides a significant speedup for these cases. The unwrapped approach is much better than recursive fibonacci, but not as good as with memoise. This is based on Dan Bishop's code. Colin W. From abra9823 at mail.usyd.edu.au Tue Aug 3 06:42:32 2004 From: abra9823 at mail.usyd.edu.au (Ajay Brar) Date: Tue, 03 Aug 2004 20:42:32 +1000 Subject: [XML-SIG] value error when parsing XML In-Reply-To: <200408030457.i734vuQ6058587@chilled.skew.org> References: <200408030457.i734vuQ6058587@chilled.skew.org> Message-ID: <410F6C18.10506@mail.usyd.edu.au> Mike Brown wrote: >Ajay Brar wrote: > > >>i get a value error when parsing an xml file. This is because it can't >>find the DTD - >>ValueError: unknown url type: ../um_xml/um.dtd >> >> From what i have discovered in the archives, this happens when your XML >>and DTD file are not in your current directory >>i have the directory structure >>home >> user - this is where i am running the script from >> um_xml- this is where the xml and dtd are >> >>can someone please tell me how i can workaround this problem. the script >>executes fine when the xml and dtd files are in user/. But i don't >>really want to put them there. >>any ideas? >> >> >> > >The "current directory" / "where you are running the script from" >has no bearing on the interpretation of URLs in the document (not >directly, anyway). > >If both files are in the same location, you only need to refer to the >DTD via the URL um.dtd (no add'l path info prepended to it). > > I have no additional path info prepended to the um.dtd my xml file goes - ..... like i said, earlier the dtd and the xml are in the same directory. the script that parses it is in a different directory. it all works fine if the dtd is in the same directory as the parsing script, but otherwise i get the Value Error. cheers ajay -- Ajay Brar CS Honours 2004 Smart Internet Technology Research Group http://www.it.usyd.edu.au/~abrar1 From cjw at sympatico.ca Thu Aug 26 11:07:03 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Thu, 26 Aug 2004 11:07:03 -0400 Subject: Alternative decorator syntax decision In-Reply-To: References: <412cc31c$1@news.012.net.il> Message-ID: Apologies! One response was more than enough. Colin J. Williams wrote: > > > Avner Ben wrote: > >> I believe putting the decorator list before the function header is >> generally a bad design decision. While it may make parsing-related >> sense, it violates Python's greatest asset: being executable >> pseudocode. The way I see it, the latter quality means being able to >> look at the code and see clearly and immediately what requirements >> from the real world the code was written the serve. Functions and >> methods are major code entities that are naturally expected to >> represent discrete functional requirements from the code, to this or >> that level of detail. I expect to learn from the method name, the >> class it is in and the list of arguments it takes, everything I need >> to know about the functional requirement it implements. If that is not >> enough, I will look at the docstring, if present. Everything else the >> method has to offer is conveniently hidden below. Decorators of the >> type discussed recently - with the exception of staticmethod and >> classmethod - are technical detail of the kind I would like to see >> hidden below. Putting them on top, prior to the what the method does >> (its name etc.) compromises the design quality of the code, reducing >> it to yet another abbreviation-based, self-centered technical >> scripting language. >> The one esception I saw was J2, which, although putting the decorators >> before the proper method header, uses indentation to state "this is an >> extra piece of technicality which you are free to ignore - the def is >> below." >> >> My vote: C2, E4, J2 >> >> Avner. > > Your expectation list makes sense to me. There is merit in having the > docstring before the 'decorator', i.e. E4 > > Colin W. > From grante at visi.com Mon Aug 30 17:46:12 2004 From: grante at visi.com (Grant Edwards) Date: 30 Aug 2004 21:46:12 GMT Subject: Size of a remote URL References: Message-ID: <4133a024$0$8090$a1866201@newsreader.visi.com> On 2004-08-30, Justin wrote: [...] Here's one of your problems: Your working code uses this URL: http://www.ecs.soton.ac.uk/~harnad/Temp/Ariadne-RAE.doc Your broken code uses this URL: http://www.ecs.soton.ac.uk/~harnad/temp/ariadne-rae.doc It doesn't matter whether it's inside a loop or outside a loop. It doesn't matter wither it's a literal or a reference to a list element: you've GOT TO SPELL THE URL CORRECTLY. Look at the two URLs carefully. Notice any differences between the one from your "working" code and the one from your "broken" code? -- Grant Edwards grante Yow! When you get your at PH.D. will you get able to visi.com work at BURGER KING? From simon.NO.dahlbacka.SPAM at abo.fi Thu Aug 12 14:32:19 2004 From: simon.NO.dahlbacka.SPAM at abo.fi (Simon Dahlbacka) Date: Thu, 12 Aug 2004 21:32:19 +0300 Subject: Keyword substitution in string References: Message-ID: <411bb7eb$1@newsflash.abo.fi> "Ondrej Krajicek" wrote in message news:I2CH9G.I09 at news.muni.cz... > > Hello, > > in my application, I want to do keyword substituion in > a string from a dictionary. The problem is indeed > easy to solve, but seems quite common to me, so I wonder > wheter there is already a function in Python which > does just that. > > I want to substitute values for keywords in strings, > the keywords and values are stored in a dictionary. > > Something like this: > > def subst(string, dict): > ... > > where: > > subst('Hello, !', {'key1': 'Python', 'key2': 'rules' }) > > gives: > > 'Hello, Python rules!' > > The keyword quoting style does not matter. Are you aware of: "Hello %(key1)s %(key2)s!" % {"key1":"Python", "key2":"rules"} ? From luismg at gmx.net Tue Aug 10 09:15:15 2004 From: luismg at gmx.net (Neuruss) Date: 10 Aug 2004 06:15:15 -0700 Subject: IronPython-0.6 is now available! References: <278de0e.0407281353.27b6a457@posting.google.com> Message-ID: <278de0e.0408100515.5fd3740c@posting.google.com> This is from Ironpython's website: "Integrated with the Common Language Runtime - IronPython code can easily use CLR libraries and Python classes can extend CLR classes." "Managed and verifiable - IronPython generates verifiable assemblies with no dependencies on native libraries that can run in environments which require verifiable managed code." "Optionally static - IronPython also supports static compilation of Python code to produce static executables (.exe's) that can be run directly or static libraries (.dll's) that can be called from other CLR languages including C#, VB, managed C++ and many more. Note: static compilation is only partially implemented in the 0.6 public release. This will need further development before being useful" So this should clear most of your concerns. The good thing about the future stable version of Ironpython, is that your code will be able to interoperate with code written in other .NET compliant languages, and its performance will be better than the standard implementation. Note that Jim Hugunin is now working for the CLR team, so he will have full access to the inner "secrets" of this technology to improve it and make it more suitable for scripting languages. What's more, there are some new features for the future version of the CLR that are specially suited for this purpose: lightweight code generation, for example. From shulmang at colorado.edu Tue Aug 17 21:42:55 2004 From: shulmang at colorado.edu (Garett Shulman) Date: Tue, 17 Aug 2004 19:42:55 -0600 Subject: mp3 fft with python Message-ID: <4122B41F.1020303@colorado.edu> Hello, I would like to do a fft on an mp3 in python. I beleive I have all of the fft stuff straight in my mind but am not sure of the best way to get the sample data into a python array. I ran accross a web site a while back which suggested using sox to convert a wav file into a raw sample file and then open the raw file with python. However, I did not bookmark this site when I came accross it and cannot seem to find it now. If anyone has any suggestions as to a good way to get sample data out of an mp3 and into a python array for an fft I would greatly appreciate your suggestions. Thanks a lot. -Garett From jaydonnell at yahoo.com Mon Aug 23 13:02:06 2004 From: jaydonnell at yahoo.com (Jay Donnell) Date: 23 Aug 2004 10:02:06 -0700 Subject: urllib hangs Message-ID: This is a basic version of my code for url in urls: fp = urllib.urlopen(url) lines = fp.readlines() #print lines for line in lines: #print line if(reUrl.search(line)): print 'found' return 1 else: print 'not found' return 0 this hangs occasionally for some certain url's. If I do a ctrl-c (linux) it will move on to the next url. How can I get this to timeout and move on to the next url. From davecook at nowhere.net Mon Aug 23 13:46:50 2004 From: davecook at nowhere.net (Dave Cook) Date: Mon, 23 Aug 2004 17:46:50 GMT Subject: 100 % portable ? References: <2otm5mFed44hU1@uni-berlin.de> Message-ID: In article <2otm5mFed44hU1 at uni-berlin.de>, Bernd Kaiser wrote: > You can use os.environ["HOME"], this will return the user's home dir. Doesn't work in win9x AFAIK. I do notice that some people are starting to require XP for their apps. Dave Cook From ajsiegel at optonline.com Sun Aug 22 15:27:51 2004 From: ajsiegel at optonline.com (Arthur) Date: Sun, 22 Aug 2004 19:27:51 GMT Subject: On consensus decision-making (was Re: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WEDONE?) References: Message-ID: On 22 Aug 2004 19:36:38 +0300, Ville Vainio wrote: > >Obviously people who don't want any syntax at all should be ignored in >the consensus building process... I hate to contribute to a change in tone to what has been a pretty civil controversy, all things considered, and Anthony's private hate mail notwithstanding. But that to me is a stupid remark. We have syntax. If we did not already have it, one could propose it like any other syntax being proposed. If concensus would form around that syntax (it won't , among other reasons because the rules of the game won't allow it) it's just consensus forming around a syntax. Which is what the exercise is supposed to be about. I have heard implicit and explicit threats on python-dev in the case no new syntax made it into 2.4 - assumedly by people who *really* hate some extra typing. It is not unreasonable to assume that vehemence is a good deal of what brought us here. I never made any threats about the non-acceptance of my non-Peps. Or anybody else's. I guess we - among other things - can all have our own sense of what makes a good citizen in PythonLand. Ours apparently diverge. Art From lbates at swamisoft.com Mon Aug 9 09:46:26 2004 From: lbates at swamisoft.com (Larry Bates) Date: Mon, 9 Aug 2004 08:46:26 -0500 Subject: Advanced printing using win32ui in python - help! References: Message-ID: You may not want the additional overhead, but this is pretty easy using wxPython (wxWindows Python package). The additional benefit (which may not be important to you) is that it is portable. HTH, Larry Bates Syscon, Inc. "Darcy Kahle" wrote in message news:XEUQc.48836$Vm1.1127573 at news20.bellglobal.com... > I am trying to do some advanced printing in python using the win32ui > module, and have run into an issue. I need to print a page landscape. > As I could not determine how to specify the orientation of the printing, > I arranged the graphic elements on the page the way it should be. When > I got to printing text, it went across the page, not down as I need it > to go. I tried to use the hDC.SetWorldTransform(0, -1, 1, 0, 0, 0) > command to rotate the print counterclockwise 90 degrees, but this > command was virtually ignored. The other solution that I can see > involves specifying that the page is in landscape mode, but as I > indicated earlier, I cannot determine how to accomplish this. The > command win32ui.CreatePrintDialog(1538).DoModal() presents the dialog > where the user can specify landscape mode, but it appears that the OK > button is not hooked up to a default callback. There is a PyCPrintInfo > object, which it looks like I can set this programmatically, and then > generate the printerDC object, but there is no documentation on how to > generate this. > > Can anyone recommend to me how I could either specify the page to be in > landscape mode, or rotate the text that is printing? Any assistance > that you can provide is greatly appreciated, and I am certain that there > are others out there that want to know how to do this as well. > > BTW, I am currently using WinXP and Python 2.3, but the solution should > be accessible via Win98 and up. I plan to use py2exe to run the final > product on other windows boxes. From richie at entrian.com Thu Aug 26 09:01:35 2004 From: richie at entrian.com (Richie Hindle) Date: Thu, 26 Aug 2004 14:01:35 +0100 Subject: Larry Wall & Cults In-Reply-To: <776e0325.0408260433.449660c8@posting.google.com> References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <776e0325.0408260433.449660c8@posting.google.com> Message-ID: [Sara] > just look at the reaction if any questions any element of Perl design! My one and only foray into comp.lang.perl was to ask about the rationale behind using regular expressions as the mechanism for untainting tainted data. Since regular expressions are so pervasive in Perl code, it seemed to me (as a Perl beginner) that it made it very easy to untaint without realising it. I never returned, and I'm grateful to the Python community for not being the Perl community. 8-) -- Richie Hindle richie at entrian.com From ptmcg at austin.rr._bogus_.com Fri Aug 20 18:34:30 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 20 Aug 2004 22:34:30 GMT Subject: Decorator keyword options - brainstorming References: <7knVc.4599$Jn5.3074@fe1.texas.rr.com> Message-ID: Some other ideas: imbue endow bestow embellish extend accum glom confer From eldiener at earthlink.net Mon Aug 16 20:04:23 2004 From: eldiener at earthlink.net (Edward Diener) Date: Tue, 17 Aug 2004 00:04:23 GMT Subject: Piping stdout to Python callable Message-ID: >From within a function in my own module I need to take the output from a Python module "A", which is sending data to stdout and which can not be changed and which I need to invoke as a top-level module, and pipe it into another function in my own module so that I can read it from stdin. Is there an easy way to do this ? The only way I can presently think to do this is through "system python A.py | python MyOwnModule.py", which seems a bit laborious having to invoke python.exe itself twice. Any other solution would be most welcome. From newsgroups at jhrothjr.com Thu Aug 5 17:17:03 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Thu, 5 Aug 2004 17:17:03 -0400 Subject: PEP 263 status check Message-ID: <10h58umglolefb8@news.supernews.com> PEP 263 is marked finished in the PEP index, however I haven't seen the specified Phase 2 in the list of changes for 2.4 which is when I expected it. Did phase 2 get cancelled, or is it just not in the changes document? John Roth From grante at visi.com Mon Aug 16 12:43:02 2004 From: grante at visi.com (Grant Edwards) Date: 16 Aug 2004 16:43:02 GMT Subject: Newbie question about file input References: Message-ID: <4120e416$0$65575$a1866201@newsreader.visi.com> On 2004-08-16, Elcio Ferreira wrote: >> while 1: >> line = zf.readline() >> if not line: >> break > > Newbie's question: > > Isn't it a strange way to do a loop? Create a loop with a foo > condition and use an if to break it? > >===== > line=zf.readline() > while line: > . . . > line=zf.readline() >===== > > Isn't this code much more easy to understand? I prefer this: for line in xf: .... -- Grant Edwards grante Yow! I'm rated PG-34!! at visi.com From anthonybaxter at gmail.com Sun Aug 22 12:50:35 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Mon, 23 Aug 2004 02:50:35 +1000 Subject: J2 proposal: keyword In-Reply-To: References: Message-ID: On Sun, 22 Aug 2004 16:08:44 GMT, Arthur wrote: > So in the end I might have ended up doing exactly what I have accused > others of doing in other cases - reading into the @decorator syntax > decision (assuming *some* syntax is a fait accompli) - finding it to > be wise, for reasons perhaps beyond its intentions. As someone else said at some point during the last two weeks of decorator discussions - we're all using a language that, by and large, is Guido's design. He's done a good job so far of producing something that's excellent - I trust him to produce a good result here. I hope the final decision ends up getting less vitriolic responses than the 2.4a2 release got. From squirrel at WPI.EDU Fri Aug 13 15:34:00 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Fri, 13 Aug 2004 15:34:00 -0400 Subject: Why I love python. In-Reply-To: References: <2o4divF6one2U1@uni-berlin.de> Message-ID: On Fri, 13 Aug 2004, kosh wrote: > Why is there a need for a stand alone executable? At least on all the unixes > whether something is executable is just determined by the executable bit on > the file. Not if you don't have the interpreter installed. > I can execute a python program just as transparently as one in > compiled c, c++, etc. I really don't see the point of that. Indeed, you can do that just as easily on Windows, too. The point of a stand-alone executable is not to make running the script easier, but to make distribution easier. Users don't need to install Python to run a Python script if it's a stand-alone executable. From __peter__ at web.de Thu Aug 5 16:44:30 2004 From: __peter__ at web.de (Peter Otten) Date: Thu, 05 Aug 2004 22:44:30 +0200 Subject: Proposal: require 7-bit source str's References: Message-ID: Hallvard B Furuseth wrote: > Now that the '-*- coding: -*-' feature has arrived, > I'd like to see an addition: > > # -*- str7bit:True -*- > > After the source file has been converted to Unicode, cause a parse > error if a non-u'' string contains a non-7bit source character. Could # -*- coding: ascii -*- be sufficient? Why would you reintroduce ambiguity with your s-prefixed strings? The long-term goal would be unicode throughout, IMHO. Peter From simoninusa2001 at yahoo.co.uk Fri Aug 27 18:21:44 2004 From: simoninusa2001 at yahoo.co.uk (Simon John) Date: 27 Aug 2004 15:21:44 -0700 Subject: Dynamic languages In-Reply-To: <278de0e.0408271349.26762174@posting.google.com> Message-ID: Yeah, I noticed that not quite right definition - I know I certainly can't change the behaviour of a running script (which has been compiled to .pyo/.pyc) by editting the .py source file..... From xing_zhimeng at yahoo.com Sat Aug 7 06:06:07 2004 From: xing_zhimeng at yahoo.com (xzm) Date: 7 Aug 2004 03:06:07 -0700 Subject: Extending python. References: Message-ID: I think you may create custom python exe... something like the following and just link against your module and python2x.lib. Of course, you still need to do the usual stuffs of wrapping around you own C code. Then you may just 'import xyz' in Python: #include "Python.h" #include "xyzmodule.h" int main(int argc, char **argv) { PyImport_AppendInittab("xyz", initxyz); return Py_Main(argc, argv); } Grzegorz Dostatni wrote in message news:... > Cheers. > > More questions. > Let's say I'm trying to extend python with a c module. That module cannot > be dynamically loaded (for reasons outside my control). I have to create a > custom python executable (or more likely custom python library). > How would I do that? Is there documentation on that somewhere? Most of > what I've seen was for dynamic loading. > > 2nd Step: > Let's say I'm doing it under windows, using Visual Studio. Is there > anything I have to be aware of? > > 3rd Step: > Let's say I don't have the source available. I do have the object files, > the resulting libraries and the header files though. > > Greg > > "The optimist proclaims that we live in the best of all possible worlds, > and the pessimist fears this is true." > - James Branch Cabell From ialbert at mailblocks.com Sun Aug 8 00:00:25 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Sun, 08 Aug 2004 00:00:25 -0400 Subject: decorators vs GIL In-Reply-To: <8YudnZoJ4NdLEYjcRVn-jA@speakeasy.net> References: <8YudnZoJ4NdLEYjcRVn-jA@speakeasy.net> Message-ID: <0bidnfbR2_PZOIjcRVn-pA@giganews.com> A.M. Kuchling wrote: > My basic point is that the features added to projects are those that people > are willing to actually work on. In the case of decorators, some people > wanted decorators, for the sake of PyObjC or ctypes or whatever, and Mark > Russell actually sat down and implemented it. (Because he uses PyObjC? I think one of the latent messages of this thread was that adding new "gratuitous" features to the core language is a bad thing. Just because someone sits down and codes it does not mean it should be added to the language. Features are forever, you cannot just can't eliminate them in the next version. Why putter around with banalities like sorted() and reversed() that only add to the cognitive overhead, break the consistency in dealing with lists yet save at most a line or two of coding? And what you imply here, that the fact of having decorators works for PyObjC was considered in the overall decision feels like putting the cart before the horse. Python is said to come with the batteries included, then that's where new features should go, to the battery level not into the wiring. Istvan. From listsub at wickedgrey.com Wed Aug 25 15:48:34 2004 From: listsub at wickedgrey.com (Eli Stevens (WG.c)) Date: Wed, 25 Aug 2004 12:48:34 -0700 Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? In-Reply-To: References: Message-ID: <412CED12.4080204@wickedgrey.com> Jess Austin wrote: > Another objection that has been raised about my current favorite, > "decorate", is that at 8 characters it's too long. 9 characters will > also be considered too long by a number of people. > > The natural short version of "decorate" would be "dec" and there is > sort of a natural parallelism with "def" there. I hesitate to > nominate it because it _feels_ like a word that at least ten people on > c.l.py will detest. > > Maybe "decor"? It isn't any longer than "class", and I think we can > predict it will be typed less than 1/10 as often. But this reasoning > could also excuse "decorate", so I'll stick with that. I'm also open > to any transitive verb that can be designated to mean _exactly_ what > "decorate" means now. J2 J2 F, but I'm a lurker and Python newbie, so... ;) I kind of like the keyword "alter", but I suspect that, like many other such words, it will conflict quite a bit with existing code. One of the issues that some have raised was the disconnect between the "using" and "def" lines. What about copying the pattern used by if/elif; something like (I like the first the best, I think it "reads well," while the second is the shortest and has a nice rhythm): alterdef: classmethod def foo(): pass decdef: classmethod def foo(): pass decoratedef: classmethod def foo(): pass Of course, this will mean that there would also be an "alterclass:" if classes need decorators (in this case, "decclass:" doesn't seem as nice, and reusing "alterdef:" is downright misleading). Just a thought, Eli From tjreedy at udel.edu Tue Aug 3 16:49:20 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 3 Aug 2004 16:49:20 -0400 Subject: Timing Difference: insert vs. append & reverse References: <35b736b9.0408020330.53b24ed3@posting.google.com> <35b736b9.0408021152.4c1ab752@posting.google.com> <35b736b9.0408030019.27f212d9@posting.google.com> Message-ID: "John Keeling" wrote in message news:35b736b9.0408030019.27f212d9 at posting.google.com... > It is so cool to be able to get the disassembly > so easily.... thanks v. much Terry. Since byte code is not (typically) written by hand, the symbolic names can be long enough to be mostly self-explanatory, rather than short and crytic. If any are not, for you, the Lib Manual dis module section has subsection with all codes explained. TJR From zathras at thwackety.com Thu Aug 5 09:14:21 2004 From: zathras at thwackety.com (Michael Sparks) Date: Thu, 5 Aug 2004 14:14:21 +0100 (BST) Subject: web resources to explain why Python is best? In-Reply-To: <9dqdnVTDTfC3vYzcRVn-iQ@centurytel.net> Message-ID: On Wed, 4 Aug 2004, Ed Suominen wrote: ... > How about my very own posting "Goodbye TCL" on comp.lang.tcl and the 114 > other articles in the thread it started? I read through that and the script you were talking about it in - a dictation system written in python sounds interesting, but the links to where you can download all seem bust - is it still available anywhere? TIA, Michael. From siona at chiark.greenend.org.uk Mon Aug 23 12:04:49 2004 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 23 Aug 2004 17:04:49 +0100 (BST) Subject: 100 % portable ? References: Message-ID: Roger Binns wrote: >My preferred toolkit is the wxPython wrapper around wxWidgets. >Wherever possible it uses native widgets. [ ... ] > >Just to give you some idea, in my 30,000 line program there are >5 tests to see what platform it is running on, specifically to >ensure appropriate defaults etc for the platform. Sounds about right to me -- I've got about 20,000 lines of application with six platform tests, five of which are to work around platform-specific infelicities in wx. -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From db3l at fitlinxx.com Thu Aug 19 15:12:35 2004 From: db3l at fitlinxx.com (David Bolen) Date: 19 Aug 2004 15:12:35 -0400 Subject: introspection? References: Message-ID: Roman Suzi writes: > I am using different approach to introspection of Python > functions and methods (not all available info output, > only name of the previously called function/method). > I am not sure if this is better than getting sys._getframe() > or not, at least it doesn't use undescore methods ;-) > and "knowns" about all invocation history at once, > could even show source code, etc. Note that for Python 2.1+ you can use the inspect module's "currentframe" method to obtain your current frame in lieu of sys._getframe(), if you prefer a more documented approach. I believe you should also be able to work your way back up the call chain using the f_back field within any given frame object if you want to. -- David From bdesth.quelquechose at free.quelquepart.fr Tue Aug 10 13:15:55 2004 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Tue, 10 Aug 2004 19:15:55 +0200 Subject: how to dispatch objects depending on their class In-Reply-To: <4118dd4a$1@maser.urz.unibas.ch> References: <4118dd4a$1@maser.urz.unibas.ch> Message-ID: <4118faca$0$22911$636a15ce@news.free.fr> Curzio Basso wrote: > > Hi all. > > I have a couple of question regarding the following situation: > > class A(object): > def __init__(self): > pass > > class B(object): > def __init__(self): > A.__init__(self) > > def func(object): > if isinstance(object, A): > do_something_with_A(object) > elif isinstance(object, B): > do_something_with_B(object) > > Note that in my real problem I cannot move the logic of func to the > class A and B because I will have a hierarchy also for func. Then I need > a way to dispatch the object to the right function. I saw something like a multi-methods implementation in Python somewhere, this may interest you. http://www-106.ibm.com/developerworks/linux/library/l-pydisp.html From Michael.J.Fromberger at Clothing.Dartmouth.EDU Thu Aug 19 14:01:01 2004 From: Michael.J.Fromberger at Clothing.Dartmouth.EDU (Michael J. Fromberger) Date: Thu, 19 Aug 2004 14:01:01 -0400 Subject: PEP 318: Can't we all just get along? References: <20040817181725194-0400@braeburn.themorgue.org> <10i9msuatli5p84@news.supernews.com> Message-ID: In article <10i9msuatli5p84 at news.supernews.com>, "John Roth" wrote: > "Kevin Smith" wrote in message > news:20040817181725194-0400 at braeburn.themorgue.org... > > For what it's worth, I wrote the original PEP 318. [...] > > > > In my opinion, none of the proposed syntaxes really seem Pythonic. > > This PEP just seems to be trying to solve too many problems. > > The arguement is, and always has been, about syntax. Everyone agrees > that the current situation is not ideal; putting the wrapping > assignment statement after the method is a very poor way of declaring > intent. I agree that the current situation is not ideal. However, I would also argue that many of the proposed replacements are even worse. Kevin Smith's latest proposal (cf. ) is, in my view, the most reasonable suggestion so far. > In other words, forget the use cases. They're irrelevant. On this point, I strongly disagree. If you don't have a use case, there is no point whatsoever in arguing about the syntax of a feature. Now, if you want to argue about general syntactic design principles, maybe that is an interesting topic -- but it is one level removed from what PEP-318 is all about, and therefore (in my opinion) not really germane to the present discussion. -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From jack at performancedrivers.com Wed Aug 11 17:33:03 2004 From: jack at performancedrivers.com (Jack Diederich) Date: Wed, 11 Aug 2004 17:33:03 -0400 Subject: The winner of the Python Decorator Poll is... In-Reply-To: References: Message-ID: <20040811213303.GI23725@performancedrivers.com> On Wed, Aug 11, 2004 at 04:16:54PM -0500, Doug Holton wrote: > George W Bush, as certified by Florida's election commission. > > > Which decorator syntax do you like the most? See > http://wiki.wxpython.org/index.cgi/PythonDecoratorsPoll > A. @classmethod def foo(): (82) 14% > C1. def foo() [classmethod]: (235) 41% > E1. def foo(): @classmethod (260) 45% > > Total Votes: 577 > > People are about 6 to 1 against having the decorators come before the > "def" keyword. Or people who don't like decorators before the def are six times as likely to vote in the dissidents poll *wink* -Jack From my.news.groups at noos.fr Mon Aug 16 05:10:49 2004 From: my.news.groups at noos.fr (nik) Date: Mon, 16 Aug 2004 11:10:49 +0200 Subject: C++ app calling python script repeatedly Message-ID: <41207a1c$0$29872$79c14f64@nan-newsreader-05.noos.net> hi, my C++ app has embedded the interpreter and calls a python script everytime it creates a certain data structure. This allows the user to put the structure into a database or files or whatever. For example; // Py_Initialize(); has been called earlier m_module = PyImport_AddModule("myModule"); // for example, this string is my data structure PyObject* theMessage = PyString_FromString("data"); PyModule_AddObject(my_module, "Message", theMessage); fp =fopen("theScript.py", "r"); PyRun_SimpleFile(fp, "theScript.py"); // Py_Finalize(); will be called when the C++ app exits I've just realised that calling the script repeatedly might not be the best thing, especially if the users script has a lot of initialisation to do, or needs to store variables in between calls to the script. How could I solve this? Can the user run a python program alongside my C++ app, and the app call a method on the users program? I.e. can the script I call be part of a global process in some way? Or, are there other ways to go about this? nik From tim.peters at gmail.com Mon Aug 9 13:42:31 2004 From: tim.peters at gmail.com (Tim Peters) Date: Mon, 9 Aug 2004 13:42:31 -0400 Subject: Queue qsize = unreliable? In-Reply-To: <788E231C269961418F38D3E360D1652526CA1F@tndefr-ws00021.tenovis.corp.lan> References: <788E231C269961418F38D3E360D1652526CA1F@tndefr-ws00021.tenovis.corp.lan> Message-ID: <1f7befae0408091042663a3810@mail.gmail.com> [Jeff Shannon] >> No you don't. You simply execute a non-blocking get(), and be >> prepared to catch the Queue.Empty exception. Similarly, if you want >> a non-blocking producer, then you execute a non-blocking put() and >> catch the Queue.Full exception. [Ames Andreas] > I've actually read the docs some time ago, but I've also read the > source. I think the problem is here that "non-blocking" isn't very > well defined. That's true, it isn't. > In the sense that the consumer won't wait until something gets > available from an empty Queue you are absolutely right with calling > Queue.get(False). But if you look at the source you will find that > the first thing that's done in Queue.get() is aquiring a mutex/cv > lock. That's potentially quite blocking as far as I am concerned. You must be looking at 2.4. The mutex is never held for longer than it takes to push or pop a single entry, so there is no pattern of calls that can force a non-blocking call to wait for an arbitrarily long time (assuming OS thread scheduling doesn't starve Python). That's one meaning of non-blocking. Before 2.4 it had a different meaning, one that never waited on a mutex for any reason in the non-blocking cases. But then a non-blocking get() could raise Empty not only if the queue *was* empty, but also if it simply couldn't get immediate ownership of a mutex in order to *tell* whether it was empty. That proved impossible to explain to users, who kept complaining about it (as if it actually mattered ...). > With CPython's assertions about atomicity of certain list operations > it's possible to implement a lock free queue that is even usable for > the single producer or single consumer case. That's not to say > anything against the standard libraries Queue implementation because > it presumably does the right thing for the general case. Yes, the Queue class makes no assumptions about how the queue is implemented concretely. Its base implementation (in 2.4) uses a deque, but it's intended that users be able to subclass Queue and use any concrete implementation. In order to support that, the base Queue guarantees that calls to implementation methods are serialized. From fuzzyman at gmail.com Sat Aug 28 03:51:24 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 28 Aug 2004 00:51:24 -0700 Subject: lambda ?? References: <6f402501.0408270000.31ad1455@posting.google.com> Message-ID: <6f402501.0408272351.22a45394@posting.google.com> Jan Gregor wrote in message news:... > Python is little bit limited in lambda functions. In lisp I use lambda > functions in functionals (something like a map or reduce in python) > as a wrapper for functions with more than one argument. > > Jan Thanks to those that answered. Looks like I need to elarn Lisp to getter a fuller understanding... right after I learn C. Hmmm... unfortunately it looks like Python 2.2 or 2.3 broke the 'closure' examples from the Charming Python 'Functional Programming' series. Looks like the Xoltar toolkit could do with an update. The article says that the nested scope rules of python 2.1 + mean that you don't need the toolkit to do closures.... but without the examples it's a little harder to follow. Maybe it's time for an update !! Anyway - I did get some interesting ideas. Regards, Fuzzy > [snip...] http://www.voidspace.org.uk/atlantibots/pythonutils.html From me at privacy.net Thu Aug 26 11:34:58 2004 From: me at privacy.net (Richard Hanson) Date: Thu, 26 Aug 2004 08:34:58 -0700 Subject: MSI Installer Problem: can't install 2.4a2 on new install of Win2kSP2 References: <412d7dcd$0$26184$9b622d9e@news.freenet.de> Message-ID: Martin, Thanks for replying. Still no go with the 2.4a2 install on my Fujitsu LifeBook P1120 with Win2kSP2. (I have much to learn in writing concise posts, alas -- I appreciate your patience.) Minding my own relative ignorance -- and your expertise -- with the MSI Installer, this morning I redownloaded the MSI Installer (filename: InstMsiW.exe, filesize: 1,822,848 bytes, version: 2.0.2600.2) from MS using the link on the Python 2.4 page as you suggest (and as I'd already done yesterday as noted in my original, somewhat dense post). Today, I get the same file from MS as yesterday. Just in case, though, I ran the new download from MS yet again, and it said: "Error: The specified service already exists." Martin v. L?wis wrote: >If it used to work before the reinstallation, you either had a different >service pack installed before, or some other software you had installed >did a silent installation of a new installer release (such as Office >2k). I'm at a loss, still. Surely, something I had previously installed in my own prior installation silently installed something needed for the Python 2.4a2 install *other than the MSI Installer 2.0* and is currently missing from my reinstall...? I'll keep working on it and will report back as a solution develops. Thanks again, Martin -- much appreciate your and all the other developer's selfless contributions. I'm going to try to redownload the Python install file (mine is filesize: 10,691,072 bytes) even though it "seems" fine -- as I'm running out of ideas. Meanwhile, I *do* have Python 2.3.4 to play... er... *work* with (but I sorely miss Decimal ). Best regards, Richard -- email works if unmunged: sickolefartnewsguycom From roy at panix.com Sat Aug 28 11:14:14 2004 From: roy at panix.com (Roy Smith) Date: Sat, 28 Aug 2004 11:14:14 -0400 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1ry8k0d2az.fsf@rovereto.ifi.uio.no> <87acwgvy51.fsf@sinken.local.csis.hku.hk> <2pb36dFibuj3U1@uni-berlin.de> <41309d32$0$65611$a1866201@newsreader.visi.com> Message-ID: In article <41309d32$0$65611$a1866201 at newsreader.visi.com>, Grant Edwards wrote: > Because so many people at first think that parens construct > tuples the way square-brackets and curly-brackets construct > lists. When in reality it's commas that construct tuples, but > only in certain contexts because commas are used for about > three other purposes as well. > [...] > IMO, the only non-ugly, non-hack solution would be to have > another set of delimters that are used as tuple-constructors so > that the syntax for a literal tuple, a literal list, and a > literal dictionary are consistent. I agree. It's even uglier that "," doesn't form a zero-length tuple. Thus you get: tuple0 = () tuple1 = 1, So, is it parens that form tuples, or commas? I guess There's More Than One Way To Do It :-) My personal choice would have been angle brackets, i.e. <1, 2, 3>. Then, <1> would have been a length-1 tuple with no ambiguity. tuple0 = <> tuple1 = <1> tuple2 = <1, 2> But it's way too late for that now. Maybe in P3K? From sandskyfly at hotmail.com Wed Aug 4 12:09:43 2004 From: sandskyfly at hotmail.com (Sandy Norton) Date: 4 Aug 2004 09:09:43 -0700 Subject: tweaking @decorator syntax Message-ID: If we are going to be stuck with @decorators for 2.4, then how about using blocks and indentation to elminate repetition and increase readability: Example 1 --------- class Klass: def __init__(self, name): self.name = name @staticmethod def statmethod1(x): return x def statmethod2(y): return y @classmethod def classmethod1(cls): return cls def classmethod2(cls): return cls @funcattrs(name='GvR', language='python') @log(file='func.log') def sayhello(self): print 'hello python world' def saygoodbye(self): print 'goodby python world' Example 2 --------- class Klass: def __init__(self, name): self.name = name @staticmethod: def statmethod1(x): return x def statmethod2(y): return y @classmethod: def classmethod1(cls): return cls def classmethod2(cls): return cls @funcattrs(name='GvR', language='python'), log(file='func.log'): def sayhello(self): print 'hello python world' def saygoodbye(self): print 'goodby python world' Perhaps, you can eliminate the '@' alltogether: Example 3 --------- class Klass: def __init__(self, name): self.name = name staticmethod: def statmethod1(x): return x def statmethod2(y): return y classmethod: def classmethod1(cls): return cls def classmethod2(cls): return cls funcattrs(name='GvR', language='python'), log(file='func.log'): def sayhello(self): print 'hello python world' def saygoodbye(self): print 'goodby python world' Sandy From shalabh at cafepy.com Thu Aug 19 15:56:55 2004 From: shalabh at cafepy.com (Shalabh Chaturvedi) Date: Thu, 19 Aug 2004 12:56:55 -0700 Subject: staticmethod problems In-Reply-To: References: Message-ID: Neil Zanella wrote: > Hello, > > Coming from C++ and Java, one of the surprising things about Python is that > not only class instances (AKA instance objects) but also classes themselves > are objects in Python. You'll soon be surprised again - at how you managed to live without this feature . > > This means that variabls such as x and y appearing inside class statements > in Python essentially behave like static class variables in other languages. > On the other hand a variable is specified as an instance variable as self.x > and self.y inside a class in Python. Unqualified variables appearing inside > the class are class variables and not instance variables. Yes, but unqualified variables appearing *inside methods* are not looked up in the class (or any other object). class C: x = 1 def f(self): # different ways to access the x above print self.x print self.__class__.x print C.x # incorrect way to access x (raises exception) print x # unqualified variables here have to be found # in specific namespaces like locals or globals etc. # note that self is a local. > So now what I would like to do, is access the static variable of a superclass > object from a subclass object from a static method in the subclass object. > > Here is what is not clear to me: > Why don't the commentd out lines below work? I was > expecting that a polymorphic search taking place when I > call Y.foo() would find both x and y, but this did not happen. > In particular, why does python force me to write something > like I write in foo3() to enforce the behavior I want in foo()? > > > Thanks, > > Neil > > #!/usr/bin/python > > class X: > x = 10 > > class Y(X): > y = 5 > def foo(): > print x + y > foo = staticmethod(foo) > def foo2(): > print X.x + y > foo2 = staticmethod(foo2) > def foo3(): > print X.x + Y.y > foo3= staticmethod(foo3) > > #Y.foo() # I was expecting the same behavior as below, > # with the value 15 printed. Why is this not > # working (and where can I find more about > # staticmethod)? Since x and y are not defined in the method, nor are globals or builtins. You always have to start with an object in one of these namespaces and work your way to the object you want. > #Y.foo2() # doesn't work either. Why? > > Y.foo3() # works You might want to try classmethod instead. When you're inside a staticmethod, you have no idea which class you're in. But classmethods get the class as the first argument. And so you can use somewhat similar to how self is used for instance methods. class X: x = 10 class Y(X): y = 5 def foo(cls): print cls is Y print cls.x + cls.y foo = classmethod(foo) HTH, Shalabh From steven.bethard at gmail.com Tue Aug 31 15:26:34 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Tue, 31 Aug 2004 19:26:34 +0000 (UTC) Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Paul Morrow yahoo.com> writes: > The assignments to __xxx__ variables (immediately following the > docstring, if present) would occur in the namespace of the object > (function/method) being defined. The assignments would not cause them > to change namespaces. What you're suggesting is that given: def f1(): __author__ = 'Steve' and def f2(): author = 'Steve' in f1, the assignment to __author__ occurs in the function's namespace, but in f2, the assignment to author occurs in the local namespace. Clearly then, the __xxx__ format (if at the beginning of a function) changes the namespace to which an assignment applies. How is this not causing assignments to change namespaces? Steve From PPNTWIMBXFFC at spammotel.com Thu Aug 26 11:03:11 2004 From: PPNTWIMBXFFC at spammotel.com (Marco Aschwanden) Date: Thu, 26 Aug 2004 17:03:11 +0200 Subject: How to generically transform a list? References: Message-ID: Here is a proposal, but I am sure, that there is a simpler way... there is too much appending: >>> the_list = [['a',1,11,'aa'], ['b',2,22,'bb'],['c',3,33,'cc']] >>> returnList = [2,1] # user wants col 2 first followed by col 1 >>> new_list = [] >>> for row in theList: ... list_row = [] ... for idx in returnList: ... list_row.append(row[idx]) ... new_list.append(list_row) ... >>> new_list [[11, 1], [22, 2], [33, 3]] From drumheller at alum.mit.edu Mon Aug 16 02:50:05 2004 From: drumheller at alum.mit.edu (Michael Drumheller) Date: 15 Aug 2004 23:50:05 -0700 Subject: NumArray array-indexing References: Message-ID: Christopher T King wrote in message news:... > On 12 Aug 2004, Michael Drumheller wrote: > > > I am new to NumArray and I wonder if someone can help me with > > array-indexing. Here's the basic situation: Given a rank-2 array > > (i.e., a matrix) it seems to be trivial, with array indexing, > > to extract a subset of its *columns*. But it does not seem > > to be trivial to extract a subset of its *rows*. > > You can do this using slices, like so: > > >>> from numarray import * > >>> a = array([[1, 2], [3, 4]]) > >>> a[:,1] > array([2, 4]) > > ':' means 'take all values along this axis', just like how with standard > Python lists it means 'take all values in the list'. But that just gets me *one* column. I was trying to extract an arbitrary subset of columns. Like I pointed out in the example code I gave, this is trivial get take(), but does not seem to be trivial with array indexing (and impossible with slicing). Mike From ajsiegel at optonline.com Tue Aug 24 10:00:35 2004 From: ajsiegel at optonline.com (Arthur) Date: Tue, 24 Aug 2004 14:00:35 GMT Subject: __name__ becoming read-write? References: <3b8ki0tlphodtt8ge8an274qp78ihp1i3n@4ax.com> <8cdmi0dipgk5192li1p8mm2n1hls2hs7rl@4ax.com> Message-ID: <7rhmi0d7cdg9r6ljvilgkep30tckl24nai@4ax.com> On Tue, 24 Aug 2004 23:41:57 +1000, Anthony Baxter wrote: >On Tue, 24 Aug 2004 13:09:56 GMT, Arthur wrote: >> All I think I am looking for is proportionality. The solution should >> be proportional to the problem. The current syntax is expressive in >> the way that, I thought, was always considered to be fundamental to >> the concept of Pythonic. > >See, I think decorators _are_ proportional to the problem. I think one >thing is that decorators are a nice language feature that will allow >for a large number of new approaches - things that wouldn't >necessarily have been considered before now. On the other hand, its just sugar - and nothing but. But yes, it will encourage new approaches. Decorator libraries. Modularization. Code reuse. I think I see some of the good. But all at a cost. I would be comforted to hear you say something about the costs you perceive. If you present it is all just a win, it becomes too easy to challenge your assessment. So easy, that even someone like myself can pull it off, at least to an extent - and at least in my own judgement. I reserve the right to be wrong in my overall assessment. But I have to doubt that I am wrong in stressing that none of this new power and possibility comes for free. Art From __peter__ at web.de Wed Aug 25 09:01:11 2004 From: __peter__ at web.de (Peter Otten) Date: Wed, 25 Aug 2004 15:01:11 +0200 Subject: module functions list References: Message-ID: Diez B. Roggisch wrote: > Hi, > >> You could use a list comprehension coupled with a filter: >> >> functionList = [function for function in dir(objectName) \ >> if callable(getattr(objectName,function))] Note that callable() will not filter out classes. If you want to exclude classes from your list, have a look at inspect.isfunction() or inspect.isroutine(). > That works if objectName is my module - but how do I get a reference to > the current module _inside_ my module? Thats the hart part (at least for > me ...) sys.modules[__name__] Peter From pm_mon at yahoo.com Sun Aug 29 12:32:05 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sun, 29 Aug 2004 12:32:05 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: <1gj8q2n.1fbrmbet624ssN%aleaxit@yahoo.com> References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Alex Martelli wrote: > Paul Morrow wrote: > ... > >>Cool! Thanks! Now I need to ponder why a function's docstring needs a >>different implementation than a class's docstring (i.e. why not just >>make it a straigtforward attribute of the function object). > > > Historically, functions had docstrings before they had straightforward > attributes. Maybe it could be that. > > > Alex /* I have stared at your reply for three or four minutes now. On the surface, it seems that you are being genuinely helpful, and so I want to reply "Thanks. Of course. That makes perfect sense." But then a lot of smart people say things that (on the surface) appear honestly helpful but in reality are suggestions that the reader do more research before asking questions that have such an obvious answer. I know that you're a smart person Mr. Martelli. So I flipped a coin to decide which intreprtation of your reply to use, which came up tails, indicating the 2nd one. Bahh. I prefer the superficial one (plz correct me if I'm wrong). */ Thanks. That does make good sense. They've had no reason to simplify the implementation for function docstrings, so "why fix it if it ain't broke." Paul From mjackson at alumni.caltech.edu Wed Aug 18 13:05:40 2004 From: mjackson at alumni.caltech.edu (Mark Jackson) Date: 18 Aug 2004 17:05:40 GMT Subject: age of Python programmers References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: Robin Becker writes: > Marius Bernklev wrote: > > 24. (anyone keeping count?) > It's raining so I can't go home > Martin Jackson 55 Unless there's an elderly Martin out there as well, this should be "Mark." -- Mark Jackson - http://www.alumni.caltech.edu/~mjackson Fascism should more properly be called corporatism, since it is the merger of state and corporate power. - Benito Mussolini From chrispatton at gmail.com Thu Aug 12 17:50:07 2004 From: chrispatton at gmail.com (Chris Patton) Date: 12 Aug 2004 14:50:07 -0700 Subject: PyJack References: <6fd8df7e.0408111536.79369258@posting.google.com> <7xisbpmdss.fsf@ruckus.brouhaha.com> Message-ID: <9c3edc58.0408121350.77003c7a@posting.google.com> Paul Rubin wrote in message news:<7xisbpmdss.fsf at ruckus.brouhaha.com>... > jumpthewall at gmail.com (Chris Patton) writes: > > import whrandom, os > > Use random rather than whrandom. whrandom is obsolete and deprecated. > If you're imagining a situation where players will bet real money on > the hands dealt by this program, you have to get even more serious > about the sources of randomness. > > > def scorer(score,playerdeck):... > > while d < len(playerdeck): > > if score > 10 and 'A' in playerdeck: > > typevalues['A'] = 1 > > This is pretty ugly, changing the contents of what's conceptually a > fixed table, depending on the player score. I think it's better to > just score the hand with A=1, then count the aces and adjust the score > accordingly. > > > while decksize < 52: > > a = whrandom.randint(0,12) > > if left[a] > 0: > > left[a] = left[a] - 1 > > deck.append(types[a]) > > decksize = decksize + 1 > > elif left[a] == 0: pass > > This is a horrendous method of shuffling the cards. When there's only > one card left to deal, it will take several tries to find it. See > the random.shuffle function for a direct way to shuffle. > > > humandeck = [] > > while c <= 1: > > humandeck.append(deck[0]) > > del deck[0] > > c = c + 1 > > > compdeck = [] > > c = 0 > > while c <= 1: > > compdeck.append(deck[0]) > > del deck[0] > > c = c + 1 > > > Move these to a function that deals one hand, and call it for > the player and the computer. > > > score = 0 > > compscore = 0 > > stay = 0 > > over = 0 > > compstay = 0 > > compover = 0 > > Maybe you want to think of using fewer variables, e.g. create class > instances for the two players. Right now you only handle a two-player > game (the human and the computer). What if you want to handle n players? Thanks for your analization, Paul. I'm getting to work on the code. IF you tried to run the code, you might have ran into a few bugs. If you noticed, that was very immature code. Thanks From wilkSPAM at OUTflibuste.net Tue Aug 3 04:41:25 2004 From: wilkSPAM at OUTflibuste.net (Wilk) Date: Tue, 03 Aug 2004 10:41:25 +0200 Subject: where is yaml ? References: <878ycxtfqg.fsf@blakie.riol> Message-ID: <87llgwbolm.fsf@blakie.riol> Matt Goodall writes: > On Mon, 2004-08-02 at 23:03 +0200, Wilk wrote: >> Hi, >> >> It seems that the link for python-yaml on the http://yaml.org main page >> is loose (http://iron.cx/yaml) :-( > > Try http://www.pyyaml.org Thanks, i was afraid to be alone using yaml ! -- Wilk - http://flibuste.net From follower at gmail.com Tue Aug 17 12:13:55 2004 From: follower at gmail.com (Follower) Date: 17 Aug 2004 09:13:55 -0700 Subject: ANN: Python Decrypt PDF script -- builds on pdftools Message-ID: Hi, I wanted to extract the meta-data from an encrypted/protected PDF file and could not find any Python scripts to do this. So, I decided to write something myself, the result follows. This demonstration utility requires the `pdftools` files from but the decryption functions themselves should be usable with other Python PDF libraries. Documentation is marginal and all I can say is that worked on the three PDF files I tested it on... :-) --Phil. P.S. The usual Usenet-mangling warning applies--yeah, I know--I should put it up on a web site somewhere... :-) #!/usr/bin/python # # Decrypt PDF Info # # Decrypts PDF files and displays meta-data associated with them. (If the # file isn't encrypted the information is displayed as is.) # # The results are similar to xpdf's `pdfinfo` utility. # # It should be possible to decrypt all of the objects contained # in the PDF, but this only reads the Document Information Dictionary. # # (Note: All the PDF handling is provided by `pdftools`, this just adds # the ability to deal with encrypted PDF files.) # # Requires: # + pdftools # # # Based on: # + `pdfdecrypt.pl` # [PDFPL] # # Incorporates: # + RC4 from CipherSaber implementation by Ka-Ping Yee # # # References: # + [PDFE] # # Author: # follower at myrealbox.com (Standing on *many* shoulders...) # import sys import md5 import struct from pdftools import PDFdocument def arcfour(input, key): """ Perform the ARCFOUR (RC4) algorithm on a given input list of bytes with a key given as a list of bytes, and return the output as a list of bytes. (From CipherSaber implementation by Ka-Ping Yee ) """ i, j, state = 0, 0, range(256) for i in range(256): j = (j + state[i] + key[i % len(key)]) % 256 state[i], state[j] = state[j], state[i] i, j, output = 0, 0, [] for byte in input: i = (i + 1) % 256 j = (j + state[i]) % 256 state[i], state[j] = state[j], state[i] n = (state[i] + state[j]) % 256 output.append(byte ^ state[n]) return output _passwordPad = [ 0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41, 0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, 0x01, 0x08, 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80, 0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a] passwordPad = "".join([chr(b) for b in _passwordPad]) def calculateFileKey(fileId, ownerHash, userHash, permissions, userPassword = ""): """ Calculates the file key for the document as described in references (see [PDFE] and [PDFPL]). """ md = md5.new() md.update((userPassword + passwordPad)[:32]) md.update(ownerHash) md.update(struct.pack("" % sys.argv[0]) doc = PDFdocument(filename) try: fileKey = getFileKey(doc) except NotEncryptedException: fileKey = "" showDocumentInfo(doc, fileKey) From ronaldoussoren at mac.com Fri Aug 13 07:58:32 2004 From: ronaldoussoren at mac.com (Ronald Oussoren) Date: Fri, 13 Aug 2004 13:58:32 +0200 Subject: [OT] Keyboard layout, was Re: PEP318 In-Reply-To: References: Message-ID: <196E3AA8-ED20-11D8-9E11-000D93AD379E@mac.com> On 13-aug-04, at 13:39, Michael Hudson wrote: > Sion Arrowsmith writes: > >> Roy Smith wrote: >>> Sion Arrowsmith wrote: >>>> As someone who's just started using a Mac for the first time(*), >>>> I'd like to add that it's not always plain-sailing on an English >>>> keyboard. >>> What's wrong with Mac keyboards? >> >> No @, hence tangential relevance to PEP318 (and a point against >> pies, before or after the def). Unless you can remember it's on >> option-3. > > Huh? On *my* mac @ is shift-2 and # is option-3. And I live > with the latter, and I type it far more often than anyone is ever > going to type @ for decorators... > > Now, if someone would like to fix \ in place for the purposes of > LaTeX, then you're really talking! Use a real keyboard? On my powerbook @ is shift-2, # is shift-3 and \ is near return and left-shift :-) Ronald From pink at odahoda.de Sat Aug 28 07:53:20 2004 From: pink at odahoda.de (Benjamin Niemann) Date: Sat, 28 Aug 2004 13:53:20 +0200 Subject: would be nice: import from archive In-Reply-To: <1gj8848.1bouuroizku25N%aleaxit@yahoo.com> References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <7xzn4gwgea.fsf@ruckus.brouhaha.com> <1gj7a1o.1a5d2q410jsn2kN%aleaxit@yahoo.com> <7xisb4xnh5.fsf@ruckus.brouhaha.com> <1gj7c1a.tfdm14p3hclcN%aleaxit@yahoo.com> <7xd61benm9.fsf@ruckus.brouhaha.com> <1gj82n3.1ylkr3nierngmN%aleaxit@yahoo.com> <1gj8848.1bouuroizku25N%aleaxit@yahoo.com> Message-ID: Alex Martelli wrote: > Benjamin Niemann wrote: > ... > >>Isn't the purpose of signatures that the importing program can trust the >>module? If it's implemented as you suggest, an attacker could just >>inject path to an unsigned module into PYTHONPATH to fool a program. How > > > If the attacker is able to alter sys.path then it does not matter > whether zipfiles are even considered -- the attacker could simply > position a .pyc file early on the path. > > >>about something like >> >>require_signature('mymodule') >>import mymodule > > > This could be made to work, but only if _every_ module was so checked > before importing it; otherwise, even just one unchecked module could > easily subvert __import__ or other aspects of the import hook mechanism. > > So, if you're considering this approach, it makes more sense to switch > on module checking globally in an early phase of Python's startup > (because Python starts importing modules pretty early indeed). New > conventions will also be needed for signature of .py, .pyc, .pyo, and > .so (or other binary DLLoid files containing Python extensions). > > It appears to me that this is a project of orders of magnitude more work > than the original idea, which didn't assume the attacker could freely > alter sys.path Mmmm, seems I missed this point... > , and protected only against altered or replaced zipfiles > specifically -- presumably files that have been legitimately placed on > the path by authorized agents. > > >>or >> >>import mymodule >>verify_module(mymodule) > > > Too late:'import mymodule' runs code in mymodule, shutting the barn door > after mymodule has tramped all over your system is little use. correct >>Another question is, where to place (require|verify)_signature() (that >>could also take a CA key (or list of) as optional argument to only allow >>modules signed by this CA). It must not be imported from an untrusted >>module. >>The whole signing thing probably make only sense, if python and it's >>stdlib can be trusted (=signed). > > > The stdlib Python (.pyc) parts could be moved into a .jar (signed) just > as easily as into a .zip (unsigned). The EXE and DLL's involved may be > quite a problem, though, since for those you're in the hands of the > operating system -- what could Python itself possibly do to stop an > altered Python.Exe from running?! A use-case that came to my mind was a suid program that wants to verify that everything that it imports is what it expects, specifically not to allow the non-root user to inject any malicious replacement modules. Doing this with module signatures is probably not the easiest way... >>Or am I missing other useful applications of signed archives? > > > Remote distribution of code. My program's startup checks if an updated > version of foobar.jar purports to be available, and if so downloads it > and places it where the previous version used to be. Admittedly, in > this case, checking once and for all right after the download might work > better than checking after each and every import. (Not sure why but > this reminds me of the old 'end to end approach' issue;-). Yes, this could be handled by a generic 'file-signature-verification' mechanism. No need to delay verification until import. > > Unfortunately, Python currently doesn't have a working 'sandbox' > mechanism where code might run in a resricted way if it hadn't passed > all needed checks. This lack, among other things, may certainly lessen > the usefulness of checks performed at (or, rather, just before) import > time. Yep. Python treats us as adults. But adults often have to deal with children and the environment should give adults some kind of authority and places where the kiddies can play without causing damage... ;) This is currently not the case for Python. > > > Alex From dperl at rogers.com Mon Aug 30 11:39:54 2004 From: dperl at rogers.com (Dan Perl) Date: Mon, 30 Aug 2004 15:39:54 GMT Subject: initializing mutable class attributes References: <1gjc8cs.sqvo1v1fhabdjN%aleaxit@yahoo.com> Message-ID: "Alex Martelli" wrote in message news:1gjc8cs.sqvo1v1fhabdjN%aleaxit at yahoo.com... > Dan Perl wrote: > > > There is something with initializing mutable class attributes that I am > > struggling with. I'll use an example to explain: > > class Father: > > attr1=None # this is OK > > attr2=[ ] # this is wrong > > def foo(self, data): > > self.attr1=data > > self.attr2.append(data) > > The initialization of attr1 is obviously OK, all instances of Father > > redefine it in the method foo. But the initialization of attr2 is wrong > > because all the instances of Father end up sharing the same value. Maybe > > that is desired sometimes, but usually it is just a bug. > > I disagree: good Python programmers often use mutable class attributes, > and use them to good effect. I've done my share of Python teaching, > consulting and mentoring, and I definitely do *not* think this usage "is > desired sometimes but usually it is just a bug". My mistake. I shouldn't have made that statement. I don't really know which case happens more often. Having said that, that is probably a mistake that many beginners make. Okay, I have no real way of knowing that either, but I think it's a good assumption. > > So the only solution I see to this is to initialize attr2 in __init__: > > class Father: > > attr1=None > > def __init__(self): > > self.attr2=[ ] > > This is the canonical way, sure. > > > > This is already awkward because there is such a difference between attr1 and > > attr2. > > One is a class attribute (which nobody forced you to have), the other is > an instance attribute. If you want both to be instance attributes, > initialize both in __init__ -- that's all there is to it. Don't use > class attributes unless there's a reason for them to be class > attributes, that seems like a good and sensible rule of thumb to me. I was using the class attribute as a default, "null", value for the instance attributes. That works just fine for immutable attributes and it allows me not to implement an __init__. > > But moreover, I think this forces subclasses of Father to do > > something like this: > > class Child (Father): > > def __init__(self): > > Father.__init__(self) > > self.attr3=[ ] > > Assuming an instance of Child needs to have both attributes attr2 and > attr3, yes. > > > > > I find this even more awkward because many people will forget to do it. > > Forget to do what -- call the parent class's __init__? Again, this is > rare -- not as rare as the other "usually just a bug" you opined about, > but not common. A class normally needs __init__ for a large number of > purposes, of course, not just to assign mutable attributes to each > instance, therefore people who learn subclassing do learn to call the > parent class __init__ very early on, to avoid everything breaking. > > > Clearly, this is then a more general issue with __init__, but I think it is > > accentuated by the fact that you HAVE TO HAVE __init__ in order to > > initialize attributes that are mutable. > > Making __init__ more common means people are more likely to get used to > it, and thus makes the bug of not calling a parent class's __init__ > rarer, not "accentuated". I'm leaving the rest of your reply out, but thanks for the suggestion of a metaclass, I'll look into it. After seeing a few replies (yours, Benjamin Niemann's and Peter Otten's) to my initial posting, I think I am getting the picture that there is a conscious decision to keep the use of __init__ the way it is and just make people learn it and learn it early enough. That's a valid approach and I'll accept it. I can also understand your frustration with people who are new to Python, like me, coming from a background in other OO languages, who are not yet comfortable with "the Python way" and feel that there is a "better way" and who suggest changing Python. But you also have to be reallistic and accept that there will always be people coming to Python from other languages and that the adjustment is rather difficult in some areas. You may just say 'Tough!', or you may help them to make that adjustment (I think you are doing that), or you may even accommodate them (you should at least consider that). No one, including you, has given me a reason WHY __init__ is implemented this way. I am not bashing you for that, I would just still like to hear that 'WHY'. I'm sure that this implementation has some advantages. But, coming from a C++ and Java background, where parent default constructors are automatically invoked (well, not always, and that is something that users have to learn too), I find that that approach has some clear advantages. Those are my 2 cents. Dan PS: Does my last name attract the wrong kind of attention from people in this newsgroup? It's really my name, it's not fake, BTW. From roman.yakovenko at actimize.com Tue Aug 17 04:08:44 2004 From: roman.yakovenko at actimize.com (Roman Yakovenko) Date: Tue, 17 Aug 2004 11:08:44 +0300 Subject: python packages cross references Message-ID: <2D89F6C4A80FA547BF5D5B8FDDD04523060CBC@exchange.adrembi.com> Peter Maas wrote: > Roman Yakovenko schrieb: > > Hi. I need help( or solution :-) ). > > Problem: my project has 3 packages > > prj > > +------A > > +------B > > +------Utils > > > > The question is: what is the right way to use functionality from > > Utils in A and B packages ? > > Look at Python Tutorial Packages (6.4). You can make a prj package > and use intra-package references (6.4.2) for A, B and Utils. > > Mit freundlichen Gruessen, > > Peter Maas May be I was not clear, but from module in package A I want to user functionality defined in module of package Utils "... When packages are structured into subpackage (as with the Sound package in the example), there's no shortcut to refer to submodules of sibling packages - the full name of the subpackage must be used. For example, if the module Sound.Filters.vocoder needs to use the echo module in the Sound.Effects package, it can use from Sound.Effects import echo. ... " It means that I should have prj in sys.path. ( Am I wrong here? ). So I ask is there is elegant solution? Thanks From davidf at sjsoft.com Fri Aug 20 09:12:52 2004 From: davidf at sjsoft.com (David Fraser) Date: Fri, 20 Aug 2004 15:12:52 +0200 Subject: Alternative decorator syntax decision In-Reply-To: <84GdneSa3r-TR7jcRVn-tw@powergate.ca> References: <10ia1a9jm9tkuca@corp.supernews.com> <84GdneSa3r-TR7jcRVn-tw@powergate.ca> Message-ID: Peter Hansen wrote: > Peter Hansen wrote: > >> Jeff Shannon wrote: >> >>> My votes: J2 J2 E2 >> >> >> I second that. (J2 J2 E2) > > > I believe that the result the direction this is taking is > inevitable: a widely split vote with no consensus. I did > think there was much more agreement about which one was the > best alternative, warts and all, to @pie and which one was > therefore the most likely to get any attention at all from > Guido. I also thought people had a better grasp of which > ones had already been *rejected* fairly conclusively. Exactly. From this standpoint, the list on the wiki should be filtered to something that 1) doesn't have the declaration in the body of the function 2) doesn't have the declaration following the parameters 1) rules out D1 D2 E1 E2 2) rules out C1 C2 C3 C4 E3 This leaves (with A left out as we're looking at alternatives) B F G H I J1 J2 J3 J4 K L M With the voting going the way it currently is J2 is winning anyway, the only current close competitor would be C1 or a variant, but I think it looks like J2 is going to be the one to form a concensus around. (Current ranking is J2=38, C1=18, C1+C2+C3+C4=25, next highest is F=6, out of 34 voters giving 102 votes). The other one I supported was L but that's more on the basis of if-we-have-to-have-it-this-way-at-least-make-it-a-keyword-not-a-punctuation-character which I guess could always be argued for if J2 doesn't get it. David From jerf at jerf.org Tue Aug 17 19:45:23 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Tue, 17 Aug 2004 23:45:23 GMT Subject: how to change the text in the title bar of the Tkinter windows References: <8f17f4bc.0408151822.1be2de2e@posting.google.com> <8f17f4bc.0408171417.456199d1@posting.google.com> Message-ID: On Tue, 17 Aug 2004 15:17:30 -0700, Ali wrote: > Um.... is this right? It is supposed to show a window with the > titlebar showing The Title. Did it work when you tried it? That is the answer to your question. (Why do you want to wait hours or days for some stranger to tell you what the copy of Python sitting in front of you will do with 4 lines of code?) From ville at spammers.com Sun Aug 22 12:12:35 2004 From: ville at spammers.com (Ville Vainio) Date: 22 Aug 2004 19:12:35 +0300 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> Message-ID: >>>>> "Roy" == Roy Smith writes: Roy> (aka scripting) languages in general. I can think of no Roy> reason why so much software is still written in languages Roy> like C++ other than performance (or at least, the perception Roy> of it). Inertia, ignorance. No need for virtual machine. Real time requirements and predictabilify (e.g. fine grained control of memory management). Large amount of legacy code. But most often it's still inertia and ignorance. Never underestimate the power of incompetence ;-). -- Ville Vainio http://tinyurl.com/2prnb From dperl at rogers.com Fri Aug 27 18:02:16 2004 From: dperl at rogers.com (Dan Perl) Date: Fri, 27 Aug 2004 22:02:16 GMT Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <1LMXc.67190$UTP.37420@twister01.bloor.is.net.cable.rogers.com> <1gj7a9r.g7ec5a1g89rj0N%aleaxit@yahoo.com> Message-ID: I thought about submitting a recipe but I couldn't think of a way to use it in a good code 'snippet'. I am using the zipimport feature now to save several configuration files together in a zip file (so I can have many configurations saved in a convenient format, better than a new directory for each configuration). That would be more of an example for using multiple configurations but, anyway, it doesn't make for a short, well-contained example. Sorry, Alex. BTW, there are two books on Python that I keep on my Safari bookshelf: 'Python Cookbook' and 'Learning Python'. So my jab was made will all the respect I can muster. I am really looking forward to the second edition, recipe on zipimport or not. Dan "Alex Martelli" wrote in message news:1gj7a9r.g7ec5a1g89rj0N%aleaxit at yahoo.com... > Dan Perl wrote: > ... > > Alright, alright! And given the fact that it was added only in 2.3, that > > explains why I couldn't find any mention of the feature in 'Python > > Cookbook', the 1st ed. I'm looking forward to seeing it mentioned in the > > 2nd ed. ;-) > > If somebody submits a good recipe about it, I'll be overjoyed to add it > (not sure what chapter -- 'files'? 'system administration'? 'programs > about programs'? -- ah well, I'll find a spot!-). > > In the 2nd Edition of the _Nutshell_, when THAT comes (don't hold your > breath!-), I'll write it up just like I will for all the new delights > since 2.2 -- but for the Cookbook I'm supposed to use recipes that > people do submit to the online cookbook site... OK, I and my co-editors > _do_ perform a lot of editing and merging, and occasionally do add a > recipe or three, but mostly it IS the book you all have written, with > over a hundred authors covering the subjects THEY think matter... > > > Alex From mwh at python.net Fri Aug 6 10:16:25 2004 From: mwh at python.net (Michael Hudson) Date: Fri, 6 Aug 2004 14:16:25 GMT Subject: 'Using is not None, may not always work' References: Message-ID: Heiko Wundram writes: > Am Freitag, 6. August 2004 15:15 schrieb Doug Fort: > > Since I installed 2.4a2 I've been getting a warning from pychecker: Using > > is not None, may not always work'. I thought 'is not None' was the right > > thing to do. I've had problems with 'if not x:', because some objects > > return False in this context. > > That's probably what pychecker warns you about: that you might get an object > in the respective context which evaluates to boolean false, but is not > None... Although I'd find this strange... Does seem an odd warning, seeing as when I write "x is not None" I'm generally avoiding the case of, e.g., x being the empty list. Cheers, mwh -- Well, you pretty much need Microsoft stuff to get misbehaviours bad enough to actually tear the time-space continuum. Luckily for you, MS Internet Explorer is available for Solaris. -- Calle Dybedahl, alt.sysadmin.recovery From apardon at forel.vub.ac.be Thu Aug 26 11:41:22 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 26 Aug 2004 15:41:22 GMT Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> <1gj4fb5.607xsc51izh8N%aleaxit@yahoo.com> <7xllg25lkt.fsf@ruckus.brouhaha.com> <1gj4u3a.12ttba9fynd6uN%aleaxit@yahoo.com> Message-ID: Op 2004-08-26, Alex Martelli schreef : > Paul Rubin wrote: > >> aleaxit at yahoo.com (Alex Martelli) writes: >> > There should be one-- and preferably only one --obvious way to do it. >> > >> > Not leaving stylistic choice (which would lead to more than one obvious >> > way to do it) is quite consonant with the Zen of Python. >> >> Well, what you're left with is that doing it the one obvious way >> doesn't work, and you have to do it in some contorted way instead. > > If somelist.sort() returned the list there could not possibly be one > obvious way to do it, since both > > print somelist.sort() > > and > > somelist.sort() > print somelist Then python has already deviated from the one obvious way to do it. I can do: a = a + b vs a += b. or a = b + c vs a = ''.join(b,c) The difference between print somelist.sort() and somelist.sort() print somelist is IMO of the same order as the difference between print a + b and r = a + b print r -- Antoon Pardon From jjl at pobox.com Tue Aug 10 16:08:58 2004 From: jjl at pobox.com (John J. Lee) Date: 10 Aug 2004 21:08:58 +0100 Subject: Fixing socket.makefile() References: <%N3Sc.24735$Z14.7608@news.indigo.ie> Message-ID: <87brhipxgl.fsf@pobox.com> Alan Kennedy writes: [...] > I also am interested in the answers, because I'm just coming to end of > my implementation of cpython 2.3 compatible socket, select and > asyncore modules for jython, i.e. asynchronous socket support, using > the new java.nio APIs in jdk1.4+. Hooray! [...] > P.S. To those who know I've working on this for *ages* now: apologies > (Hi Irmen :-) My finances have prevented me from spending too much > time working on this voluntary project. However, you may be encouraged > to know that I now have it passing most of the cpython 2.3 > test_socket.py unit tests (including the ones that use > select.select). It's only a matter of a month or two more now ..... Having Pyro running on both ends of Jython / CPython divide will be very handy. > Out of interest: Does anyone know if developing asynch-socket support > for jython is the sort of work that might fall under the auspices of > the PSF grant scheme? [...] I don't see why not. This sort of fundamental-but-undramatic stuff is really valuable. Maybe the PSF should look into funding research aimed at cloning Martin v. Loewis? Or, if he's really a bot, maybe he could be reimplemented using your new code, for superior scalability? John From steve at ferg.org Thu Aug 19 10:16:40 2004 From: steve at ferg.org (Stephen Ferg) Date: 19 Aug 2004 07:16:40 -0700 Subject: age of Python programmers References: Message-ID: > Finally, someone in my cohort :-). 52. I'm 58. Started programming in 1979 -- 25 years ago. Cut my teeth on Pl/I. Later COBOL, Pascal, Basic, Java. For a while I liked REXX very much, but it just ran out of steam. Been programming in Python for about 4 years. Perhaps we have a two-hump demographic: youngsters in teens and twenties, and old farts in 50's. From deetsNOSPAM at web.de Tue Aug 17 12:08:53 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Tue, 17 Aug 2004 18:08:53 +0200 Subject: 'ascii' codec can't encode character u'\xf3' References: <4120F820.4000703@fusiondementes.com> <20040817061745.GA4259@barbucha.martin.net> Message-ID: > So what do you need to solve your problem at hand? You need to know which > encoding the sql driver wants for transmitting strings - most probably > utf-8, so they can encode all possible characters. And thus you have to > encode tthe strings you pass beforehand, or set the default encoding > properly. Just saw that setting the encoding doesn't work - sorry for suggesting it. -- Regards, Diez B. Roggisch From peter at engcorp.com Mon Aug 30 20:22:44 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 30 Aug 2004 20:22:44 -0400 Subject: Dynamic languages In-Reply-To: <278de0e.0408271349.26762174@posting.google.com> References: <278de0e.0408271349.26762174@posting.google.com> Message-ID: Neuruss wrote: > "Dynamic programming languages enable programs to change their > structure as they run." > > I wonder if this definition is correct. > Can we define dynamic languages this way? > > http://www.eweek.com/article2/0,1759,1636906,00.asp As Steve Holden points out, in effect, "sure we can", if we're journalists. But another point I haven't seen raised is that one can certainly say that a dynamic programming language is one that, like Python, allows an object to have new attributes or methods added (or old ones removed) on-the-fly. That certainly should fit the definition of "changing their structure", by anyone's measure, and it doesn't involve confusing the issue with "dynamic typing", which is not necessarily the same thing. -Peter From fgrillo64 at yahoo.com Mon Aug 9 08:33:44 2004 From: fgrillo64 at yahoo.com (fgrillo64) Date: Mon, 09 Aug 2004 12:33:44 -0000 Subject: python and win32 dlls Message-ID: Hi guys, i need help from the comunity ; i wrote under Windows2000 os a dll having several symbols exported . Now i would like to call these symbols from a python program . Can anyone tell me how from a python module is possible to call the dll exported symbols ? thanks a lot , Francesco . From eddie at holyrood.ed.ac.uk Thu Aug 12 07:05:10 2004 From: eddie at holyrood.ed.ac.uk (Eddie Corns) Date: Thu, 12 Aug 2004 11:05:10 +0000 (UTC) Subject: Help understanding Scheme's syntax, procedures and calls References: <95f168b0.0408120120.31433dc7@posting.google.com> Message-ID: franbarlow at mail.com (Fran) writes: >I'm trying to understand a functional language code fragment so I can >explain its syntax and workings to my non English-speaking background >neighbour, who is doing her finals. >What in heaven's name is this code fragment intending? (In English >prose if possible). >It looks like a fragment from a language called "scheme" >(define (this n) > (if (=n 0) > 0 > (= n (this (- n 1))))) As given this is almost certainly wrong. The first problem is possibly just a transcription error in that (=n 0) should probably be (= n 0). The second one is the that the last line doesn't make sense. It looks like someone is confused about how if statements work. Since this looks suspiciously like homework I'm only giving a hint. If statements work like (if expr1 (expr to return if exp1 is true) (expr to return if exp1 is false)) Since each arm is an expression to evaluate it means you evaluate '=' as a function in the last line hence it returns a boolean, which is going to cause you grief after a short while. >(define (f1 a b) > (if >b a) > 0 > (+ b (f1 a (+ b 1))))) This is wrong syntactically (hint: the first expression for the if statement) The questions wouldn't make sense until you fixed the functions. There is a comp.lang.scheme incidentally. Eddie From eppstein at ics.uci.edu Wed Aug 4 19:18:46 2004 From: eppstein at ics.uci.edu (David Eppstein) Date: Wed, 04 Aug 2004 16:18:46 -0700 Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) References: Message-ID: In article , "Delaney, Timothy C (Timothy)" wrote: > Besides, @ could possibly be reused for function attributes, meaning > it's less "wasted" - there's also an obvious correlation in that both > decorators and function attributes operate on the function object: > > @classmethod > def func (args): > @attr = 1 > pass > > Tim Delaney Hey, an actual reason for the restricted syntax in the current decorator implementation: it makes it less likely that @decorators will conflict with potential other @syntaxes such as this @attribute one. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ From insert at spam.here Mon Aug 9 11:41:14 2004 From: insert at spam.here (Doug Holton) Date: Mon, 09 Aug 2004 10:41:14 -0500 Subject: VB-like GUI designer? In-Reply-To: References: Message-ID: Fred wrote: > Hi, > > I'm currently checking out Python as an alternative to VB.Net > to moving from VB, but can't find a GUI designer that is as good as > VB. > > I tried wxDesigner and wxGlade, but neither lets me move the widgets > around. I also tried Dialogblocks, but it seems to only handle C++ or > XRC, not Python. > > Is this all there is, or is there a gem I missed? > QT Designer, which you can use with PyQT and PyKDE (if on Linux), is probably most like the VB GUI builder. But it is not free if you want to develop Windows apps (you'd probably want to purchase the BlackAdder version: http://www.thekompany.com/products/blackadder/ ). But the best python GUI API on Windows is wxPython. Check out the demo.py that comes with it. I don't like any of the GUI designers for it, but I haven't really needed one. From aahz at pythoncraft.com Tue Aug 24 17:01:43 2004 From: aahz at pythoncraft.com (Aahz) Date: 24 Aug 2004 17:01:43 -0400 Subject: advice for perl expert wanting to learn python References: Message-ID: In article , Stephen Ferg wrote: > >I'm surprised nobody mentioned Martin Brown's book "Perl to Python >Migration". > >The reviews indicate that although it has a lot of typos it is useful. Well, that is not a review I would make. I think it's just a couple of notches better than "horrible" -- I believe any Perl programmer would be much better off with a regular Python book. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From tdelaney at avaya.com Tue Aug 24 17:58:44 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Wed, 25 Aug 2004 07:58:44 +1000 Subject: How does a "script" differ from a "program" or "subroutine"? Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01DCF4CE@au3010avexu1.global.avaya.com> tdi wrote: > Ok, stupid question for the day. I'm reading the interview with Steve > Moret and he says: "Once a lot of scripts started going in we knew > there was no way we could back out of using Python." > > I'm just getting into Python and am wondering if I'm missing something > or this is just a semantic issue. Lots of replies have focussed on "script" vs "program". However, Steve was talking about something else in Temple of Elemental Evil - applying scripts to objects and actions. In this context, a "script" is any piece of code tied to a particular object or action - for example, casting a spell results in a "script" being run. In this context, a script may be a function/subroutine, or a program, or whatever. In the case of ToEE each "script" was implemented as a python module. Tim Delaney From peter at engcorp.com Fri Aug 20 07:16:57 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 20 Aug 2004 07:16:57 -0400 Subject: Rita Sue and Bob too In-Reply-To: References: Message-ID: <4125DDA9.3080604@engcorp.com> Ben Last wrote: >>From: Peter Hansen [mailto:peter at engcorp.com] >>(Ben, I don't think you need to post to both the python-list _and_ >>the comp.lang.python newsgroup: they mirror each other already!) > > Hmmm - I wasn't aware that I was. I'm posting (and reading) via the > python-list mailing list. I don't do USENET at all... Oh, probably my bad. I know lots of people do that, yet I don't recall seeing both "python-list at python.org" and "comp.lang.python" in the list of replies before. After a bit of experimentation, I notice it does that only when I do "Reply All" -- as I did with the one above -- to a post that was sent to the mailing list... Normally I don't do Reply All so I hadn't seen this before. I suppose with proper message ids it shouldn't show up twice as my reply did, but for some reason they are different on the two messages so the mailing list and Usenet reply couldn't be matched up and both ended up getting posted. (This one was sent only to the list to avoid the problem.) -Peter From fumanchu at amor.org Sat Aug 21 20:22:43 2004 From: fumanchu at amor.org (Robert Brewer) Date: Sat, 21 Aug 2004 17:22:43 -0700 Subject: J2 decorator grammar Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E20@exchange.hqamor.amorhq.net> Michael Sparks wrote: > On Fri, 20 Aug 2004, Robert Brewer wrote: > ... > > Did you ever fix the scope issue? > > I've fixed the scoping issue. HOO-FREAKIN-RAY! :) Way to go! Now I feel we're a solid "go" for this alternate proposal. I'm about 60% done writing and should have something on c.l.p. by Monday morning. I'll send you an early draft tonight or tomorrow, if you like (Paul McGuire, do you want one as well?). I expect to have a couple of days of feedback and revisions from c.l.p., then probably a "call for signatories/detractors"--Guido asked for an assessment of the *whole* community's support for it, as opposed to just those who don't like A1. Not another poll--I'd rather have consensus. > The current patch uses "decorate" as the keyword. Changing > that of course > is utterly trivial - it's also something I think *should* be changed. A good-sized section of the proposal will address this, most likely recommending a keyword or two but not demanding them over others Guido may prefer. That's the one area that I think will remain mostly subjective, although I plan to lay out some boundaries. > The reason for suggesting this change is for one simple > reason - python > makes often use of the idiom "decorate-dosomething-undecorate" - eg in > sorting. Using decorate would probably clash heavily with > people's code. For that reason (and others), I plan not to promote any form of the word "decorate". We can start having that conversation now if you want. ;) > > Might it have something to do with: > > static void > > symtable_node(struct symtable *st, node *n) > > { > > It certainly did! Your suggested change was necessary, however it was > incomplete - the child to traverse also needed changing. (I really > should've thought of that sooner - of course it's no longer zero! :) Bah. I actually started typing a sentence mentioning that, but didn't, since I wasn't familiar enough with the compiler to say "it needs this, as well". Grr. THANK YOU for moving us from 80% to 100! Excellent timing. Robert Brewer MIS Amor Ministries fumanchu at amor.org P.S. And I just watched the newly-released 'director's cut' of "The Gathering" today. No Zathras yet, but at least I'm in the right universe. ;) From news at NOwillmcguganSPAM.com Mon Aug 23 12:19:23 2004 From: news at NOwillmcguganSPAM.com (Will McGugan) Date: Mon, 23 Aug 2004 17:19:23 +0100 Subject: Bug in string.lstrip? In-Reply-To: <9EoWc.58$A8.18@edtnps89> References: <9EoWc.58$A8.18@edtnps89> Message-ID: <412a190c$0$31795$db0fefd9@news.zen.co.uk> Brian wrote: > Hello - has anyone else had trouble with string.lstrip stripping too > much? Here's what I get (Python 2.3.4): > > >>> import string > >>> string.lstrip("test/one/two/a.b.c", "test/one/") > 'wo/a.b.c' > >>> string.lstrip("test/one/two/a.b.c", "test/one") > 'wo/a.b.c' > >>> string.lstrip("test/one/two/a.b.c", "test/one/tw") > 'a.b.c' > >>> > > Similar things happened with the strip() string method. Am I missing > something, or should I file a bug report? > > Thanks, > > > Brian I think lstrip() just removes the characters that are contained in the second string. The order of characters in the second string is irrelevant. For example.. >>> "abcdefg".lstrip("bac" ) 'defg' Your examples are correct because it removes a run of any of the characters contained in the seconds string. Perhaps someone can explain this better than I can. ;) Will McGugan From rnd at onego.ru Tue Aug 17 10:21:58 2004 From: rnd at onego.ru (Roman Suzi) Date: Tue, 17 Aug 2004 18:21:58 +0400 (MSD) Subject: Mind.py In-Reply-To: <41220b22@news.victoria.tc.ca> References: <41220b22@news.victoria.tc.ca> Message-ID: On Tue, 17 Aug 2004, Arthur T. Murray wrote: > Now, suppose that you wanted to write an AI in Python that would > implement your mind-model and allow it to grow, mutate, develop. > Here is one possible scenario. ... cross it with Tim Rue's autocoding and human race is obsolete. Sincerely yours, Roman A.Suzi -- - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru - From Andreas.Ames at tenovis.com Fri Aug 6 12:10:28 2004 From: Andreas.Ames at tenovis.com (Ames Andreas (MPA/DF)) Date: Fri, 6 Aug 2004 18:10:28 +0200 Subject: Queue qsize = unreliable? Message-ID: <788E231C269961418F38D3E360D1652526CA1E@tndefr-ws00021.tenovis.corp.lan> Hi, Tim Peters wrote: > There's no use case I know of where knowing "the exact current size" > is necessary, except inside the implementation of Queue (where it > can know it, but at the expense of locking out all other threads for > as long as it takes to compute the result). I've got one: If you have the special situation that there is only a single consumer with potentially multiple suppliers (or similarly if you have it the other way around), you could implement the consumer in a non-blocking manner. Then it's not that important to get "the exact current size" which would still be unreliable but it is important to have a reliable empty method (or rather !empty() and full() are reliable in this situation). I think Queue is reliable in this respect but to get it additionally non-blocking you will have to roll your own queue. cheers, andreas From bokr at oz.net Thu Aug 5 17:01:20 2004 From: bokr at oz.net (Bengt Richter) Date: 5 Aug 2004 21:01:20 GMT Subject: tweaking @decorator syntax References: Message-ID: On 05 Aug 2004 14:17:25 +0000, John Marshall wrote: >On Thu, 2004-08-05 at 08:41, Sandy Norton wrote: >> On 4 Aug 2004, Christopher T King wrote: >> >> > Of course, I prefer the nested block idea better (either with a new >> > keyword or new syntax), but I don't see those (especially the syntax one) >> > flying anytime soon. >> >> I know further discussion of this topic is feeling futile, but one can only hope. >> >> > Unless someone can come up with an idea everyone can agree on Real Soon >> > Now, I think the whole idea should be dropped and wait until 3.0. We'll >> > have plenty of time to argue about it then. >> >> Agreed. >> >> > Sorry about the long rant, but it felt good to get that all off my chest. >> >> Please, we need more rants like yours. Now if they could somehow >> collectively become a 'public outcry' (-; >> >> I realize my hasty initial post didn't actually show the present 2.4 form, >> so I've included it and added your variations for the sake of comparison: >> > >With the current choice and the list of alternatives you gave, >two things struck me about the location of the decorators >in the current choice: > 1) They seem to be in the wrong place with respect to > what they are affecting. > 2) Can decorators easily be extended to apply to class > and module? > >Whether or not the @ or some other operator/keyword/etc. is >used, what is more easily understandable/readable? >----- >class Klass: > def __init__(self, name): > self.name = name > > @staticmethod > def statmethod1(x): > return x > > @classmethod > def classmethod1(cls): > return cls > > @funcattrs(name='GvR', language='python') > @log(file='func.log') > def sayhello(self): > print 'hello python world' >----- >or >----- >class Klass: > def __init__(self, name): > self.name = name > > def statmethod1(x): > @staticmethod > > return x > > def classmethod1(cls): > @classmethod > > return cls > > def sayhello(self): > @funcattrs(name='GvR', language='python') > @log(file='func.log') > > print 'hello python world' >----- > >If the decorators are metadata, that may be extended to affect >not only functions or methods, but classes, and modules(?), I would >think that wherever a variable or function call would go that >would affect the function, method, class, or module, is the >right place for a decorator. > >In the alternative above, it _may_ be that the decorators would >only be valid if they are located in specific locations, e.g., >before any non decorator (or comment, or __doc__ information) >statements. > ISTM that this "decorating" business is a lot like what __metaclass__ does for classes -- i.e., right at the end of a definition, the system looks for a function to provide an optional extension of the definition process. In the case of @some_name, 'some_name' is looked up somewhere (where? locals(), nested scopes, globals(), globals()['__builtins__'].__dict__ ?) and the value is supposed to be an appropriate decorator function. I'm thinking of an alternative that doesn't seem to have been mentioned before, namely a built-in class and a standard instance of it, containing a namespace which would be used to find decorators, and which could be overridden and specialized etc. Thus @A @B def foo(): return whatever() might look like metafunctions.add(foo=(A, B)) # could precede def anywhere you like for coding clarity def foo(): return whatever() and python function definition internals would be modified a la class/__metaclass__ functionality to find A and B via metafunctions (best design TBD ;-) and call as now specified. Perhaps this could be unified with __metaclass__ and we could have, e.g., metafunctions.add(MyClass=type) # turn classic to new style Obviously you could define metafunctions to apply default decorators, e.g. metafunctions.setdefault(A,B,C) metafunctions.do_default_for('foo bar baz'.split()) def foo(): ... def bar(): ... etc. If you wanted to suppress metafunctions altogether, you could by convention shadow it with a local None, i.e., metafunctions = None ... del metafunctions # restore visibility of builtin Or if you wanted a local copy to mess with in a particular module or program, (it would probably not be good to allow .add easily to modify the builtin itself unless there was a way to restore it reliably) you could perhaps write metafunctions = __builtins__.metafunctions.copy() or you could define your own class class MyMetfun(Metafunctions): ... metafunctions = MyMetafun(...) metafunctions.my_handy_method(...) etc. The time of action might also be controlled in the future if someone finds it useful. I.e., the time for examples above is right at the end of the function or class definition. It might be interesting to be able to have metafunctions act at other times when certain things are recognized also. What about at the time of instantiation of an exception, e.g., to inject debugging info or whatever? if __debug__: metafunctions = __import__('mymagic').Magic() #?? metafunctions.add('MyException' ...) You might need some way of defining patterns to recognize besides a plain name string. Of course, instantiation of an exception is just a special case of instantiating a class, so we could have metafunctions decorating object instances too, without modifying the source of their classes. Hm, what about decorating module instances on import? This and other possibilities would make possible factoring code in new ways, I suspect, but as I just thought of it, I haven't really thought about it any further than you see here ;-) Some possibilities would probably be dangerous, cryptic, and inadvisable in most circumstances. We already have plenty of that. IMO the question is whether ordinary usage would help make for clearer and more powerful expressions of coding ideas, and perhaps introduce useful elements for thinking up those ideas. I'm not for "tweaking @decorator syntax" -- I'm for saving '@' for something worthier of its scarce-syntax-resource status. Regards, Bengt Richter From martindemello at yahoo.com Wed Aug 25 04:26:26 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Wed, 25 Aug 2004 08:26:26 GMT Subject: Why return None? Message-ID: It seems to be a fairly common pattern for an object-modifying method to return None - however, this is often quite inconvenient. For instance def f(lst1, lst2): g((lst1 + lst2).reverse()) # doesn't work! you need to say def f(lst1, lst2): a = lst1 + lst2 a.reverse() g(a) this is actually getting in my way a lot when scripting Blender - for instance, I can't say move(Vector([a,b,c]).normalize()), I have to do a = Vector([a,b,c]) a.normalize() move(a) but it seems to be recommended practice rather than a fault in the Blender API, since the standard list does it. Is there any drawback to returning self rather than None? martin c From sross at connectmail.carleton.ca Sat Aug 7 10:39:06 2004 From: sross at connectmail.carleton.ca (Sean Ross) Date: Sat, 7 Aug 2004 10:39:06 -0400 Subject: Decorator syntax References: <38ednYT1NLz1P4zcRVn-uA@powergate.ca><2njp58F1jj1dU1@uni-berlin.de> Message-ID: "Sean Ross" wrote in message news:O%4Rc.49731$Vm1.1246946 at news20.bellglobal.com... > def foo(a, b, c): > "foo can decorate itself, from the inside" > foo.decorate(abstract, synchronized, classmethod, > accepts=(int,int,int), author='Chris King') > ... > ... Actually, nevermind: foo's going to call decorate every time it's called. Not good. Also it doesn't work with multi|generic method schemes, nor with really_long_function_or_method_names(). From ptmcg at austin.rr._bogus_.com Sun Aug 29 22:03:10 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 30 Aug 2004 02:03:10 GMT Subject: simple compiled languages? References: <7xzn4fu188.fsf_-_@ruckus.brouhaha.com> <_1bYc.855$2s.374@twister.nyroc.rr.com> <7xbrguvfn6.fsf@ruckus.brouhaha.com> Message-ID: "Leor Zolman" wrote in message news:psv4j0p9inej073bta5m9r6ug4ko6iiojk at 4ax.com... > ...she then said she wanted to > learn Python. I gave her the book and asked her to teach it to *me* after > she figured it out ;-) > -leor ... so what did she say the next day? :) -- Paul From fumanchu at amor.org Thu Aug 26 18:03:16 2004 From: fumanchu at amor.org (Robert Brewer) Date: Thu, 26 Aug 2004 15:03:16 -0700 Subject: Call for signatories for J2 Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E8E@exchange.hqamor.amorhq.net> Tim Peters wrote: > [Robert Brewer] > > The J2 proposal is as complete as it will ever be. > > > > http://www.aminus.org/rbre/python/pydec.html > > Word to the wise: Guido will have to scroll down 5 pages in his > browser before he has any idea what "J2" might look like, at which > point it appears to start with the senseless: > > : > > He'll have to slog thru another 5 pages before seeing that "using" is > the specific suggestion being made. > > IOW, this is a truly wonderful presentation for people who have made > this debate their life's primary hobby, but someone looking for its > recommendation will probably give up before getting within 7 pages of > it. > > IOOW, start the page with a concrete J2-with-"using"-versus-pie > example -- put the conclusion first, followed by reams of supporting > argument. I'll do my best. Thanks! Robert Brewer MIS Amor Ministries fumanchu at amor.org From m_vddungen at yahoo.com Sat Aug 28 09:31:22 2004 From: m_vddungen at yahoo.com (Marcel van den Dungen) Date: 28 Aug 2004 06:31:22 -0700 Subject: Dynamic languages References: <278de0e.0408271349.26762174@posting.google.com> <1093650026.763899@news.commspeed.net> Message-ID: <98862c6.0408280531.6064d510@posting.google.com> "Tom B." wrote in message news:<1093650026.763899 at news.commspeed.net>... > I doubt that this is what they mean but a dynamic language is a language > that is still evolving (Python) as opposed to a dead language (COBOL). > > They probably are referring to programs that can add and remove components > during runtime. Dynamic refers to the typing of variables. In Python variables get a type dynamically when assigned a value. See also: http://www.artima.com/weblogs/viewpost.jsp?thread=4639 and several blog posting of Bruce Eckel on this subject: http://www.mindview.net/WebLog/ Marcel. From jacek.generowicz at cern.ch Fri Aug 27 10:35:42 2004 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 27 Aug 2004 16:35:42 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> Message-ID: Kjetil Torgrim Homme writes: > often when re-factoring code, I need to change the indent level of > some chunk of code. due to the lack of an end marker, my Emacs has > to use heuristics when re-indenting, You've lost me here. When you want to change the indent level of some chunk of Python code in Emacs, you highlight the chunk of code and hit C-c > or C-c <. I don't see any scope for heuristics here. > def appraise_insurance(rental_cars): > assert isinstance(rental_cars, (list, tuple)) > > for car in rental_cars: > { > if car.make == "Lamborghini": > car.insurance = 1000.00 > elif car.make == "Lada": > car.insurance = 50.00 > else: > car.insurance = 100.00 > } > logger.debug("Insurance values updated") > the single pair of braces is enough. there is now no risk of Emacs > including the debug line into the else branch unnoticed. How about for car in rental_cars: if car.make == "Lamborghini": car.insurance = 1000.00 elif car.make == "Lada": car.insurance = 50.00 else: car.insurance = 100.00 pass pass logger.debug("Insurance values updated") ? Hmm ... not pretty, but at least it doesn't PERLize the language. > what do you think? should I write a PEP? Yes please write a PEP. It will be formally rejected, thereby forming an excellent reference to which we might direct people who come up with similar ideas. From pm_mon at yahoo.com Tue Aug 10 21:57:58 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Tue, 10 Aug 2004 21:57:58 -0400 Subject: Static method object not callable In-Reply-To: References: Message-ID: Edward Diener wrote: > This simple code example gives me the message, "TypeError: 'staticmethod' > object is not callable". > > class X(object): > def Y(x): > print x > Y = staticmethod(Y) > ad = { 1 : Y } > def Z(self): > self.ad[1](3) > x = X() > x.Z() > print "Done." > > I know there must be a way to have a class attribute reference a static > method, and then call that static method through the reference, so if anyone > can correct this it would be appreciated. > > > Here are two alternatives. class X(object): def Y(x): print x Y = staticmethod(Y) ad = { 1 : 'Y' } def Z(self): getattr(self, self.ad[1])(3) x = X() x.Z() print "Done." class X(object): def Y(x): print x Y = staticmethod(Y) def __init__(self): self.ad = { 1 : self.Y } def Z(self): self.ad[1](3) x = X() x.Z() print "Done." From newsgroups at jhrothjr.com Sat Aug 21 09:22:18 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Sat, 21 Aug 2004 09:22:18 -0400 Subject: Fate of lambda, Functional Programming in Python... References: <412636D1.6070808@noaa.gov> <41265E67.A08409A6@juno.com> <2on5k1FcjmvdU1@uni-berlin.de> Message-ID: <10iej4bapn6rh04@news.supernews.com> "Reinhold Birkenfeld" wrote in message news:2on5k1FcjmvdU1 at uni-berlin.de... > Jeff Sandys wrote: > > > | > > Hi,all > > | > > I have a list like [(id,string),...],for example: > > | > > > > | > > [(1,'xxxxx'),(7,'ppppp'),(4,'gggggg'),...] > > | > > > > | > > I want to sort this list according to the id of each element. > > | > > After sorting,the list will become: > > | > > > > | > > [(1,'xxxxx'),(4,'gggggg'),(7,'ppppp')...] > > | > > > | > list.sort sorts tuples by first argument, then second &c. If you > > want > > | > a custom sort order, look at the decorate-sort-undecorate pattern. > > | > > | Or if you want to sort only on your Id, use a lambda: > > | l.sort(lambda x,y: cmp(x[0],y[0])) > > | > > | To force sorting on just the nth element of the tuples, replace 0 > > with > > | n in the above. > > | > > > > I think that lambda should be unlimited and expanded. It already has > > the > > colon, block delimiter, so allow lambda to be a multistatement and > > multiline > > indented block! > > So in what point exactly is this different from a def(), then? def() is a statement. It can't be used in an expression. That's the crux of the problem, and always has been the crux of the problem. John Roth > Reinhold From nobody at nowhere.com Mon Aug 9 16:13:46 2004 From: nobody at nowhere.com (Fred) Date: Mon, 09 Aug 2004 22:13:46 +0200 Subject: VB-like GUI designer? References: Message-ID: On Mon, 09 Aug 2004 20:20:27 +0200, Detlev Offenbach wrote: >Give "eric3" a try (http://www.die-offenbachs.de/detlev/eric3.html). It >is a complete Python IDE using Qt-Designer for GUI development and >Qt-Linguist for translating the GUI. Thx for the link :-) Fred. From steven.bethard at gmail.com Mon Aug 23 14:28:39 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Mon, 23 Aug 2004 18:28:39 +0000 (UTC) Subject: J2 decorator grammar References: <3A81C87DC164034AA4E2DDFE11D258E3022E41@exchange.hqamor.amorhq.net> Message-ID: Robert Brewer amor.org> writes: > with: > classmethod > .author = "Fran?ois Pinard" > def foo(cls): > pass > > def bar(): > pass > with bar: > staticmethod > .version = "0.2.4" > > with: > .name = "New Item" > thing = Item() > with thing: > .color = "red" The "with" syntax seems pretty reasonable for functions -- probably worth changing the proposal's: Should not be a word with a planned future. This rules out "with" and "as". to something like: Should not be a word with a planned future of different semantics. This rules out "as", and perhaps "with" (but see [link to this discussion]). I have to say that I'm not a big fan of the implicit object of "with" for anything but defs. "Explicit is better than implicit" being the rule, I don't see that we gain much by allowing implicit "with" objects for expressions in general -- the last example above is a little hard for me to read. However, because funcdefs and classdefs are not expressions, but still might be reasonable objects of a "with" clause, I can see that a special syntax for these cases might be merited. Just my two pfennings... Steve From peter at engcorp.com Thu Aug 12 23:03:39 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 12 Aug 2004 23:03:39 -0400 Subject: decorator with keyword In-Reply-To: <2o21foF65snnU2@uni-berlin.de> References: <2o21foF65snnU2@uni-berlin.de> Message-ID: Reinhold Birkenfeld wrote: > Peter Hansen wrote: >>The python-dev mailing list doesn't appear to have discussed this one >>yet, but given that much of the, uh, "chatter" that I detect there >>is about minor tweaking of the @pie syntax, I fear they are so not >>likely to pay much attention to new syntaxes and it might be too >>late to get much support for it amongst the core folks. (Guido >>referred to @pie as "the humble @decorator" yesterday...) > > I'm sure it would help if every supporter of this syntax started a > thread of his own on python-dev *wink* Glad you put the wink in... I doubt that would help the cause. The syntax should be presented there, perhaps, preferably by someone calm and reasonable (i.e. not me), but I think the most valuable thing is to continue discussion here until it's apparent (if that's going to happen) that there is a fairly wide consensus that decorate: (possibly with a different keyword) is far preferred to @pie... At least, I think that was roughly what was asked for of the masses, if the masses had anything to say about the matter. -Peter From anthonybaxter at gmail.com Mon Aug 23 05:24:02 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Mon, 23 Aug 2004 19:24:02 +1000 Subject: J2 proposal: keyword In-Reply-To: <7x1xhyjjxv.fsf@ruckus.brouhaha.com> References: <7x1xhyjjxv.fsf@ruckus.brouhaha.com> Message-ID: On 23 Aug 2004 02:13:48 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: > Semi-OT: since there's been all this noise about not wanting to > separate the decorators too much from the function name, etc., why are > "accepts" and "returns" decorators instead of having that stuff in > the function def itself? E.g.: At some point in the future, there probably will be a decent way to spell the (optional) typing of arguments. The 'accepts()' and 'returns()' decorators are really just strawmen for example's sake - if you like, you could use a more realistic example like 'applies(date(2004,5,1),date(2004,5,5))' or some such. From zanesdad at bellsouth.net Wed Aug 18 08:34:08 2004 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Wed, 18 Aug 2004 08:34:08 -0400 Subject: age of Python programmers In-Reply-To: References: Message-ID: <41234CC0.7030701@bellsouth.net> Lucas Raab wrote: >One thing I've always kind of wondered is what is the average age of a >Python programmer?? What age groups use Python?? Something to think >about.... > > > > Is this a marketing survey? age: 31 marital status: married - have 1 wife parental status: 2 children canine status: have 1 dog feline status: 1 cat employment status: (very) thankfully have a (good) job automobile status: 2 cars sanity status: nearly none Jeremy From anthonybaxter at gmail.com Thu Aug 19 06:37:02 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Thu, 19 Aug 2004 20:37:02 +1000 Subject: Decorators: an outsider's perspective In-Reply-To: References: <20040814153534.8AC171E4007@bag.python.org> Message-ID: On 17 Aug 2004 16:25:51 -0400, Aahz wrote: > No, no, no, Americans get humor just fine -- what they don't get is > irony. That'd be "something like iron"? From rschroev_nospam_ml at fastmail.fm Fri Aug 20 11:37:21 2004 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Fri, 20 Aug 2004 15:37:21 GMT Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: Reid Nichol wrote: > Gerrit Muller wrote: > >> Roel Schroeven wrote: >> >>> Roel Schroeven wrote: >>> >>>> I spotted some errors in your list, added new entries, and made a >>>> histogram: http://roelschroeven.net/pythonages/ >>> >>> >>> >> Very cool. It might be good idea to add a date and time at the top, >> since new datapoint keep coming in? > > How about labels for the axes as well. I thought it would be fairly obvious, but I added labels anyway. I'm not satisfied with there positioning though, and I don't know how to correct it (it's the first time ever I use matplotlib). -- "Codito ergo sum" Roel Schroeven From hodges7 at cox.net Sun Aug 15 16:38:04 2004 From: hodges7 at cox.net (Bill Hodges) Date: Sun, 15 Aug 2004 15:38:04 -0500 Subject: undefined symbol: PyUnicodeUCS4_FromUnicode In-Reply-To: <411c5b24$0$26992$9b622d9e@news.freenet.de> References: <411c5b24$0$26992$9b622d9e@news.freenet.de> Message-ID: Martin, Your dianosis is correct. I compiled tcl to include UCS4 and Python then compiled to UCS4 (nm revealed the difference). PyQt compiled fine, However, it still errors out the same way. For some reason PyQt needs to be told to include the UCS4 stuff in qt.so na d I cannot find the key. Do you have another suggestion. ---------------------------------------------------------- drt psyco installed and used Traceback (most recent call last): File "/usr/local/lib/python2.3/site-packages/drt/drt.py", line 40, in ? from qt import * ImportError: /usr/lib/python2.3/site-packages/qt.so: undefined symbol: PyUnicodeUCS4_FromUnicode Martin v. L?wis wrote: > Bill Hodges wrote: > >> output is: >> >> psyco installed and used >> Traceback (most recent call last): >> File "/usr/local/lib/python2.3/site-packages/drt/drt.py", line 40, in ? >> from qt import * >> ImportError: /usr/lib/python2.3/site-packages/qt.so: undefined symbol: >> PyUnicodeUCS4_FromUnicode >> >> Any pointers on how to resolve? > > > It appears that you have built qt.so for UCS-4, but the installed Python > is UCS-2. Do "nm -D /usr/bin/python2.3|grep UCS" to verify that. > > If so, make sure the pyconfig.h that you are using belongs to the > /usr/bin/python you are using. > > Regards, > Martin From claird at lairds.us Thu Aug 19 19:08:08 2004 From: claird at lairds.us (Cameron Laird) Date: Thu, 19 Aug 2004 23:08:08 GMT Subject: Merging pdf documents with Python References: <87hdqzt0sg.fsf@pobox.com> Message-ID: <04nfv1-n9v.ln1@lairds.us> In article <87hdqzt0sg.fsf at pobox.com>, John J. Lee wrote: > writes: >[...] >> >From: "Daryl Middleton" >[...] >> >Can python be used to merge pdf documents into a single pdf >> file so that I >[...] >> http://www.reportlab.org/ >[...] > >www.reportlab.org is ReportLab's open source site. > >The part of ReportLab's software that lets you concatenate, and >otherwise process, pre-existing PDF files (rather than making new PDF >files) is called PageCatcher. PageCatcher is not open source >software. > > >John I write in Python. I like ReportLab. HOWEVER, when I concatenate PDFs, I use pdcat. See for details. From alikakakhel3 at hotmail.com Tue Aug 17 20:23:28 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 17 Aug 2004 17:23:28 -0700 Subject: what is wrong with this program? Message-ID: <8f17f4bc.0408171623.4f055fb3@posting.google.com> The following program is supposed to show a menu but it isnt showing the drop down menus. It only shows the File and Help thing. from Tkinter import * def callback: print "Alhumdulillah root = Tk() #create menu m = Menu(root) root.config(menu=m) filemenu = add_cascade(label="File", menu="filemenu") filemenu.add_command(label="New", command=callback) filemenu.add_separator() filemenu.add_command(label="Quit", command=callback) helpmenu = Menu(m) m.add_cascade(label="Help", menu="helpmenu") helpmenu.add_command(label="About", command=callback) root.mainloop() please help me fix it From uche at ogbuji.net Mon Aug 9 10:37:23 2004 From: uche at ogbuji.net (Uche Ogbuji) Date: 9 Aug 2004 07:37:23 -0700 Subject: Module for converting XML to Python object(s)? References: <41105a9c$1@news.iconz.co.nz> Message-ID: "Colin Brown" wrote in message news:<41105a9c$1 at news.iconz.co.nz>... > "Robert Oschler" wrote in message > news:otdPc.224$df.27 at bignews5.bellsouth.net... > > Has anybody seen a Python module that will take an XML document (not a > > colossal one), and convert it to a Python nested class object? > > Also pyRXP ref: http://www.reportlab.org/pyrxp.html PyRXPU (the only useful part of PyRXP) is not really what the OP was asking for. It creates lists and dicts rather than actual element structures that can be accessed using the natural vocabulary from the XML (e.g. "print html.head.title"). -- Uche Ogbuji Fourthought, Inc. http://uche.ogbuji.net http://4Suite.org http://fourthought.com Perspective on XML: Steady steps spell success with Google - http://www.adtmag.com/article.asp?id=9663 Use XML namespaces with care - http://www-106.ibm.com/developerworks/xml/library/x-namcar.html Managing XML libraries - http://www.adtmag.com/article.asp?id=9160 Commentary on "Objects. Encapsulation. XML?" - http://www.adtmag.com/article.asp?id=9090 Harold's Effective XML - http://www.ibm.com/developerworks/xml/library/x-think25.html A survey of XML standards - http://www-106.ibm.com/developerworks/xml/library/x-stand4/ From martin at v.loewis.de Sun Aug 8 06:58:07 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 08 Aug 2004 12:58:07 +0200 Subject: @decorator syntax is sugar, but for what exactly? In-Reply-To: References: Message-ID: <4116073F.7020506@v.loewis.de> Anthony Baxter wrote: > The "Python of 1.5.2 simplicitly" is long, long gone. I don't agree that > newer Python's are somehow worse because new things have been > added. A short list: > > new style classes > foo(*arg, **kwarg) > iterators > generators > list comprehensions My favourite one: string methods. Regards, Martin From peter at designtheory.org Wed Aug 4 15:43:52 2004 From: peter at designtheory.org (Peter Dobcsanyi) Date: 4 Aug 2004 19:43:52 GMT Subject: pydesign 0.4 - combinatorial/statistical design computing Message-ID: The pydesign package is a collection of Python modules and applications to provide a computational framework for working with combinatorial and statistical designs. For download, documentation, installation instructions please visit: http://designtheory.org/software/pydesign/ -- , Peter Dobcsanyi From hamilcar at tld.always.invalid Tue Aug 10 13:31:18 2004 From: hamilcar at tld.always.invalid (Hamilcar Barca) Date: Tue, 10 Aug 2004 11:31:18 -0600 Subject: Exceptions as a Control Structure References: <411775aa$0$17867$626a14ce@news.free.fr> Message-ID: <20040810133118.154$yq@news.newsreader.com> In article <411775aa$0$17867$626a14ce at news.free.fr> (Mon, 09 Aug 2004 15:01:38 +0200), Olivier Parisy wrote: > I come from C++, where the use of exceptions as control > structures is frowned upon for efficiency reasons. In Bertrand Meyer's Eiffel, this is prohibited by the language design. Exceptions wouldn't have been my choice for this kind of control, but Dr. van Rossum is far more educated than I. > What is the Python canon on this topic ? Exceptions are a primary control structure. > Are exceptions considered as reasonable control structures, or is > StopIteration alone of its kind ? Yes. No. -- "It's not like IBM can support Linux the way they support the mainframe operating system. They don't write the code for it." -- Steve Ballmer. http://news.com.com/2008-1082-998297.html. 25 Apr 2003 From jess.austin at gmail.com Wed Aug 25 20:13:21 2004 From: jess.austin at gmail.com (Jess Austin) Date: 25 Aug 2004 17:13:21 -0700 Subject: Are decorators really that different from metaclasses... References: Message-ID: On Tue, 24 Aug 2004 12:29:38 -0400, Paul Morrow wrote: > > No. Function decorators are to functions as class decorators are to classes. > > Class decorators are not in 2.4, because you can do most things you'd > do with a class decorator by using a metaclass, but in a completely > different way. In my opinion, class decorators _should_ be in 2.4, > because they're a much saner way to handle many things that require a > metaclass today. So far we agree. > [snip] A metaclass allows the user > to specify an object that builds classes in a new way. A decorator > allows the user to specify a way to transform the already built > function (or class, for class decorators). This is effectively the same thing. When you call a class object, whether it is a classic class, new-style class, class with a metaclass, decorated class, or some legal combination of the preceding, it returns an object. You can't have too many expectations of that object, although typically it will have its __class__ variable set to the class object you called originally. Anything a metaclass can do to the objects it creates (which are typically classes), a decorator could do to objects (whether functions or classes) it decorates, if only by creating another object and returning it instead of the original object. I'm assuming that the function returned by the decorator must accept name, bases, dict as arguments just like a metaclass must. That returned function will perform in a more flexible manner since you can also pass arguments to the decorator to control its behavior - something you couldn't do with a metaclass. A factory and a filter are equivalent in the sense that once an object has squirted out the back end, they don't have access to it anymore. What differences are there? There could be a running-time difference, but who cares about class instantiation time? Object instantiation time is what matters. Also, an object the class of which has __metaclass__ set currently also has __metaclass__ set to the same thing. This seems like an ill-advised feature, through which presumably you could do odd and unmaintainable things, although these could also be done through __class__.__metaclass__. It's also an inaccurate feature - can a simple object be said to have a metaclass? To what would this be set for a class whose metaclass had a metaclass? Anthony Baxter wrote in message news:... > I forgot one other point I meant to add - think about when the body of > a class gets executed, vs when the body of a function gets executed. > The former is at compile time, the latter is when the function is > used. This is a difference between classes and functions. But maybe it could be "swept under the rug" in the following way. Code like this: using: metaclass_decorator(baz) class foo(bar): a = 1 def moo(self): pass could cause something similar to the following: foo = metaclass_decorator(baz)('foo', (,), {'a': 1, 'moo': , '__module__': '__main__'}) Granted, this is slightly different from what a function decorator does. But the difference probably won't be felt by those who use class decorators. Besides the mischief inherent in the introduction of another namespace floating around behind the __metaclass__ variable of normal objects, I don't see anything metaclasses can do that class decorators couldn't. Class decorators can be passed arguments to control what function they return (see "baz" above), but this doesn't seem like a major difference. So, no, I don't think that class decorators would be _that_ different from metaclasses. later, Jess From jblazi at hotmail.com Sun Aug 1 04:14:08 2004 From: jblazi at hotmail.com (jblazi) Date: Sun, 01 Aug 2004 10:14:08 +0200 Subject: transforming a list into a string References: Message-ID: Thx. Your solution is perfect for me as speed is not an issue here. jb From peter at engcorp.com Wed Aug 4 13:19:04 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 04 Aug 2004 13:19:04 -0400 Subject: help: Unit test fixture returning the same object In-Reply-To: <9895e897.0408040851.21ac7caa@posting.google.com> References: <9895e897.0408031533.26720ba0@posting.google.com> <9895e897.0408040851.21ac7caa@posting.google.com> Message-ID: Michael McCracken wrote: > So, I'm still surprised that id() would point to the same object every > time, but I'm willing to believe it. Don't think of it using those words. Think of it as "the new object is being created at the same address as the old object was at, so it's likely the first object created since the old one was destroyed", or something like that. At least that way it's much easier to believe, much less of a coincidence, and actually something that a number of people have encountered over the years, though often with similar expressions of surprise or disbelief. :-) -Peter From m.boeren at guidance.nl Fri Aug 20 03:33:22 2004 From: m.boeren at guidance.nl (Marc Boeren) Date: Fri, 20 Aug 2004 09:33:22 +0200 Subject: Alternative decorator syntax decision Message-ID: <0C77C7530EA52A4EBD1C47C80D1D291E17DE29@sbs.GuidanceBV.local> My vote: J2 J2 A2 My notes: J2 could do with a better keyword, I like decorate but 'moddef' may be better (modify def, pretty clear) A2 or A1 is about the same for me and could have been a single A option Cheerio, Marc. From pink at odahoda.de Thu Aug 19 16:05:48 2004 From: pink at odahoda.de (Benjamin Niemann) Date: Thu, 19 Aug 2004 22:05:48 +0200 Subject: ZeroDivisionError: float division (baby steps) In-Reply-To: <6daa8765.0408191133.2f2e22e3@posting.google.com> References: <6daa8765.0408191133.2f2e22e3@posting.google.com> Message-ID: Artemisio wrote: > I am a non programmer who just started with Python. So far I love it. > > I would appreciate if you could help me fix this error I get taking this exercise: > > count= 0 > sum= 0.0 > number= 1 > print "Enter 0 to exit the loop" > > while number != 0 : > number= input("Enter a number: ") > > count= count + 1 > sum= sum + number > > count= count -1 > print "The average is: ",sum/count > #the error is in the above line > > "ZeroDivisionError: float division" > > Thank you in advance, Len I think the two lines after input() should be indented as the belong to the while loop... From CarolCarrot at sofsof.net Mon Aug 16 15:52:27 2004 From: CarolCarrot at sofsof.net (Carol Carrot) Date: Mon, 16 Aug 2004 13:52:27 -0600 Subject: mailman mailing list program References: Message-ID: now what is +1 QOTW.supposed to mean? From spam at mouse-potato.com Mon Aug 30 19:15:18 2004 From: spam at mouse-potato.com (Pascal Bourguignon) Date: 31 Aug 2004 01:15:18 +0200 Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4PGdnfsOfdDPi63cRVn-tA@speakeasy.net> <41337FC9.8070902@hotmail.com> Message-ID: <87wtzgmd4p.fsf@thalassa.informatimago.com> Antony Sequeira writes: > Windows (MS) is not 'Unixism'? It's VMS'ism ! -- __Pascal Bourguignon__ http://www.informatimago.com/ Our enemies are innovative and resourceful, and so are we. They never stop thinking about new ways to harm our country and our people, and neither do we. From goden at simplified.com Sat Aug 21 11:51:40 2004 From: goden at simplified.com (Eugene Oden) Date: Sat, 21 Aug 2004 15:51:40 GMT Subject: C language processing. References: <845db307.0408210122.70bfd408@posting.google.com> Message-ID: stephen henry wrote: > Hi all, > > I'm looking for a python module that would allow me to take an input > file written in 'c' and modify the contents to allow me to, for > example, add arguments to functions, insert macros at specific > locations etc. I have no formal education in computer science , but, > what I believe I'm looking for is somesort of parser (or lexer?). > > So far, I found a bunch of pasers (SimpleParse and SPARK) but these > seem to be quite generic -non-language specifc. I was hoping that the > 'c' langauge was sufficiently well known to be supported natively, > meaning that I would't need to enter the grammar rules into the > parser. > > Does anybody know of a way of doing this in python? (Or, for that > matter, with Perl, as I would be learning either language to carry > this out.) > > Stephen Henry i've had some luck using pybison (http://www.freenet.org.nz/python/pybison/) using a freely available c grammar which is now included in the pybison distribution. it'll do the work of building a parse tree but you'll have to take it from there. later, gene From ramen at lackingtalent.com Fri Aug 27 14:48:30 2004 From: ramen at lackingtalent.com (Dave Benjamin) Date: Fri, 27 Aug 2004 18:48:30 -0000 Subject: Alex Martelli: Welcome back! References: <1gj70s0.cc0xt0bs9aduN%aleaxit@yahoo.com> Message-ID: In article <1gj70s0.cc0xt0bs9aduN%aleaxit at yahoo.com>, Alex Martelli wrote: > Dave Benjamin wrote: > >> It's nice to see you around here again! > > Thanks! Hope I can stay a while... Did you leave in frustration or did you just get busy? -- .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:. "talking about music is like dancing about architecture." From tdelaney at avaya.com Fri Aug 13 02:58:01 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Fri, 13 Aug 2004 16:58:01 +1000 Subject: Why I love python. Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01CF47CB@au3010avexu1.global.avaya.com> Anthony Baxter wrote: > On 12 Aug 2004 17:05:34 -0700, Michael Scarlett > wrote: >> [ pie decorators ] >> Am i the only one with a >> visceral reaction to this thing??? > > So did you have a similar reaction on first hitting the indentation > for blocks? I know I dimly recall thinking that this was very strange > and horrible (dimly, because it was 1992 or 1993). Personally, no. I loved them :) But that could be because it matched the indentation I enforced on my own code pretty much identically. Strangely enough, people had always commented on my "excessive use of whitespace" whilst at the same time commenting that my code was "the most readable they'd ever seen". And very few people seemed to link the two statements ... ;) But @decorators before the def at the same indentation level just doesn't work for me. Too much information to process at once - I have real problems finding the name of the function, even having set up syntax colouring to handle it. The name just gets lost in the noise. Tim Delaney From secun at yahoo.com Mon Aug 16 14:27:05 2004 From: secun at yahoo.com (ChrisH) Date: Mon, 16 Aug 2004 18:27:05 GMT Subject: Help with reading WinXP registry References: Message-ID: Here is an example. from _winreg import * print r"*** Reading from SOFTWARE\Microsoft\Windows\CurrentVersion\Run ***" aReg = ConnectRegistry(None,HKEY_LOCAL_MACHINE) aKey = OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run") for i in range(1024): try: n,v,t = EnumValue(aKey,i) print i, n, v, t except EnvironmentError: print "You have",i," tasks starting at logon..." break CloseKey(aKey) print r"*** Writing to SOFTWARE\Microsoft\Windows\CurrentVersion\Run ***" aKey = OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", 0, KEY_WRITE) try: SetValueEx(aKey,"MyNewKey",0, REG_SZ, r"c:\winnt\explorer.exe") except EnvironmentError: print "Encountered problems writing into the Registry..." CloseKey(aKey) CloseKey(aReg) In article , miki.tebeka at zoran.com says... > Hello David, > > > Is there a better way to access the registry in a Win32 system? > Try the _winreg module with the ...Ex functions. > > HTH. > -- > ------------------------------------------------------------------------ > Miki Tebeka > http://tebeka.spymac.net > The only difference between children and adults is the price of the toys > From olli at haluter.fromme.com Tue Aug 24 09:45:38 2004 From: olli at haluter.fromme.com (Oliver Fromme) Date: 24 Aug 2004 13:45:38 GMT Subject: How does a "script" differ from a "program" or "subroutine"? References: Message-ID: <2p0v42FfaqerU1@uni-berlin.de> tdi wrote: > Ok, stupid question for the day. I'm reading the interview with Steve > Moret and he says: "Once a lot of scripts started going in we knew > there was no way we could back out of using Python." > > I'm just getting into Python and am wondering if I'm missing something > or this is just a semantic issue. Historically, the term "script" means a batch job, i.e. a sequence of OS commands that are executed in an automated manner (as opposed to typing those commands interactively), with very limited possibilities of loops, conditionals and variables. DOS batch files (.BAT) are a typical example. The term "program" means complex processing instructions which implement algorithms in a particular programming language (which does not normally contain OS commands directly). With some languages, the differences become very small, and people tend to pay less attention to the distinction, so "scripts" and "programs" are used as synonyms. For example, some advanced UNIX shells (like the zsh) have features that support complex programming, such as various kinds of loops and conditionals, arrays, dictionaries etc. Python is more a programming language than a scripting language (more than Perl, at least), although you can very well use it for tasks which would typically be written in a scripting language. A subroutine is just another name for a procedure or a function, i.e. a piece of program code that performs a specific task, and which can be called from within the program (once or multiple times). You can define sub- routines in almost every language (both for programming and for scripting). Best regards Oliver -- Oliver Fromme, Konrad-Celtis-Str. 72, 81369 Munich, Germany ``All that we see or seem is just a dream within a dream.'' (E. A. Poe) From anthonybaxter at gmail.com Sun Aug 8 04:20:55 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sun, 8 Aug 2004 18:20:55 +1000 Subject: elements of decorator syntax suggestions In-Reply-To: <4115CDA8.1A8AD51D@alcyone.com> References: <4edc17eb.0408062125.231f7bef@posting.google.com> <41155C33.37EEB397@alcyone.com> <4edc17eb.0408072041.7bfe9eff@posting.google.com> <4115CDA8.1A8AD51D@alcyone.com> Message-ID: On Sat, 07 Aug 2004 23:52:24 -0700, Erik Max Francis wrote: > @ sure takes up more visual space and is easier to spot in text than |, > which is precisely why I used it in EmPy as the token prefix (also > because @ at the time is neither commonly used in English text or legal > in Python, though the latter will be changing). The far-more-obvious-in-code is my reason for preferring @ over |. The other point that's been raised is that | looks similar to l and I in a bunch of fonts, and I is a common prefix (for interfaces). From zathras at thwackety.com Tue Aug 17 04:08:35 2004 From: zathras at thwackety.com (Michael Sparks) Date: Tue, 17 Aug 2004 09:08:35 +0100 (BST) Subject: Generators versus Coroutines In-Reply-To: <1a517b5.0408161608.46c2023c@posting.google.com> Message-ID: On 16 Aug 2004, Bryan Olson wrote: > Michael Sparks: > > On Sun, 15 Aug 2004, Nick Patavalis wrote: > > ... > > > For me it would be *tremendously* usefull if one could yield across > > > multiple levels of function calls. If this was supported, then most > > > uses of O/S treads could be replaced by generators. > > > > You can do this already if you use Armin Rigo's Greenlets which, whilst > > included in Stackless appear to work perfectly fine with standard python. > > (I've only tested with 2.3 FWIW) > > Correct me if I'm wrong: Greenlets use a c-language extension to > do the routine switching; implementing the same in pure Python is > infeasable. Correct. I never claimed that doing this in "pure" python was possible - largly because I think such a concept is pretty silly. After all, what is "pure" anyway? * Is using a module that comes with python allowed? * If so is using a module written in C acceptable? * If so what if greenlets gets included at some point in time, do modules included cease being "pure", or would greenlets be redefined?. * Also if using a builtin module written in C is "pure" then why are modules written in C not included not "pure"? * You might conclude then that "pure" python couldn't use modules written in C whether included with the interpreter or not. * If you conclude that what about the python interpreter? That'ss written in C, so *that's* not pure if you mean code that only using python anywhere in the system. (if you allow the interpreter, why not modules that come with it?) You just end up (IMO) having contradictory arguments about purity if you go down that route. After all someone has proposed using threads as a pure implementation. Is *that* "pure"? Is the threading code written in python or C? (Looks like C on my system - but it's declared "pure" ;-) IMO, the question is one of practicality. It is practical to use generators to build concurrent systems - and it works pretty well. If that's not good enough it is practical to using concurrency implementated as an extension to python. If that's not good enough, it is practical to a different implementation of python. Or if concurrency in a single thread isn't sufficient you can change to threads or processes. I prefer "practical python" over "pure python" ;-) > Generators rock, but they have a shadow of the power of co-routines. > Continuations are more powerful still. And if you choose appropriate coding conventions every problem domain that co-routines and continuations can solve, generators can be used with almost equal effectiveness. Having written large amounts of code using generators to gain parallelism in a single thread I don't say that lightly. I've found their simplicity useful for limiting the complexity of the architecture. After all if any piece of software is use for any length of time maintainability comes before elegance. (unfortunately the two don't always go hand in hand) Teasingly, ;-) Michael From tim.peters at gmail.com Sat Aug 7 01:52:28 2004 From: tim.peters at gmail.com (Tim Peters) Date: Sat, 7 Aug 2004 01:52:28 -0400 Subject: elements of decorator syntax suggestions In-Reply-To: <4edc17eb.0408062125.231f7bef@posting.google.com> References: <4edc17eb.0408062125.231f7bef@posting.google.com> Message-ID: <1f7befae04080622522200e695@mail.gmail.com> [Michele Simionato] > What about "-" ? > > - syncronized That's already (pre-2.4) valid Python, so could change the meaning of existing code -- won't happen. > - classmethod > def f(cls, *args): > pass > > > Any punctuation already used in current Python > would go for me (., :, -, +, *, /, |, \, ^, etc. etc.) ! Overloading a unary prefix operator is out. As Anthony said, vertical bar seemed to be the leading contender on python-dev Friday. You can find tedious arguments there about most of the others that would go for you. From miki.tebeka at zoran.com Wed Aug 25 07:44:18 2004 From: miki.tebeka at zoran.com (Miki Tebeka) Date: Wed, 25 Aug 2004 13:44:18 +0200 Subject: 100 % portable ? In-Reply-To: <1f7befae0408231057a376ac6@mail.gmail.com> References: <2otm5mFed44hU1@uni-berlin.de> <1f7befae0408231057a376ac6@mail.gmail.com> Message-ID: <20040825114417.GR1948@zoran.com> Hello Tim, > [Bernd Kaiser] > >> You can use os.environ["HOME"], this will return the user's home dir. > > [Dave Cook] > > Doesn't work in win9x AFAIK. I do notice that some people are > > starting to require XP for their apps. > > HOME isn't defined on my vanilla XP box. HOMEDRIVE and HOMEPATH are, though. import user print user.home Bye. -- ------------------------------------------------------------------------ Miki Tebeka http://tebeka.spymac.net The only difference between children and adults is the price of the toys From LISTSERV at LISTS.NCTE.IE Tue Aug 31 05:31:37 2004 From: LISTSERV at LISTS.NCTE.IE (L-Soft list server at N.C.T.E. (1.8d)) Date: Tue, 31 Aug 2004 10:31:37 +0100 Subject: Message ("Your message dated Tue, 31 Aug 2004 10:29:34...") Message-ID: <0I3B008DD14P59@mail.ncte.ie> Your message dated Tue, 31 Aug 2004 10:29:34 +0100 with subject "Re: Your document" has been submitted to the moderator of the NEWS list: Se?n Dower . From calidusdk at hotmail.com Thu Aug 19 15:33:54 2004 From: calidusdk at hotmail.com (Artemisio) Date: 19 Aug 2004 12:33:54 -0700 Subject: ZeroDivisionError: float division (baby steps) Message-ID: <6daa8765.0408191133.2f2e22e3@posting.google.com> I am a non programmer who just started with Python. So far I love it. I would appreciate if you could help me fix this error I get taking this exercise: count= 0 sum= 0.0 number= 1 print "Enter 0 to exit the loop" while number != 0 : number= input("Enter a number: ") count= count + 1 sum= sum + number count= count -1 print "The average is: ",sum/count #the error is in the above line "ZeroDivisionError: float division" Thank you in advance, Len From curzio.basso at unibas.ch Wed Aug 11 04:12:33 2004 From: curzio.basso at unibas.ch (Curzio Basso) Date: Wed, 11 Aug 2004 10:12:33 +0200 Subject: how to dispatch objects depending on their class In-Reply-To: References: <4118dd4a$1@maser.urz.unibas.ch> Message-ID: <4119d4f7$1@maser.urz.unibas.ch> Casey Duncan wrote: > It should not be a problem to use the actual class object as keys in the > dict and the functions as values. No need to convert the class to > strings. Ops, did not think about that. But maybe the string is a more efficient key? > So why can't they be static methods of the classes exactly? That would > be simpler, however the dict will work efficiently. Well, as I wrote in the original post and in some reply, I want to keep the logic of this particular function separated from the class hierarchy. And as cmedcoff at hotmail.com suggested this could be a Visitor pattern. I'm looking on that. cheers, curzio From dave at pythonapocrypha.com Mon Aug 9 11:11:32 2004 From: dave at pythonapocrypha.com (Dave Brueck) Date: Mon, 09 Aug 2004 09:11:32 -0600 Subject: Queue qsize = unreliable? In-Reply-To: <788E231C269961418F38D3E360D1652526CA1F@tndefr-ws00021.tenovis.corp.lan> References: <788E231C269961418F38D3E360D1652526CA1F@tndefr-ws00021.tenovis.corp.lan> Message-ID: <41179424.5020806@pythonapocrypha.com> Ames Andreas (MPA/DF) wrote: > Jeff Shannon wrote: > >>No you don't. You simply execute a non-blocking get(), and be >>prepared to catch the Queue.Empty exception. Similarly, if you want >>a non-blocking producer, then you execute a non-blocking put() and >>catch the Queue.Full exception. > > I've actually read the docs some time ago, but I've also read the > source. I think the problem is here that "non-blocking" isn't very > well defined. I assume it means "non-blocking from the caller's perspective" (see below). > In the sense that the consumer won't wait until something gets > available from an empty Queue you are absolutely right with calling > Queue.get(False). But if you look at the source you will find that > the first thing that's done in Queue.get() is aquiring a mutex/cv > lock. That's potentially quite blocking as far as I am concerned. But is it blocking in any way that you (the caller) will likely notice? (probably not - the mutex is held for a relatively short period of time. Note also that the mutex that gets acquired is not the "main" mutex of the Queue.) > With CPython's assertions about atomicity of certain list operations > it's possible to implement a lock free queue that is even usable for > the single producer or single consumer case. If you have the single producer and/or single consumer case, you don't need a Queue at all - just use a built-in list (or in 2.4 a collections.deque object). >>That's really the only reliable way to tell whether the queue is >>empty or full, anyhow... > > > I don't understand why this is more reliable than what I described in > my scenario. If, for example, you have a single consumer then: > > if !q.empty(): > reliableCode() > else > unreliableCode() > > should be absolutely okay. It'd probably _work_, yes, but would it offer any real advantage? On that particular mutex, there's almost never any contention at all - *especially* in e.g. the single consumer case. And, even if there is some contention, it is acquired for an extremely short amount of time (relatively speaking) - which is why the caller is not likely to notice that any locking is going on under the covers. The cost of having both reliableCode and unreliableCode paths seems to outweigh any potential advantage IMO. -Dave From arien_malec at yahoo.com.REMOVE Mon Aug 23 14:12:57 2004 From: arien_malec at yahoo.com.REMOVE (Arien Malec) Date: Mon, 23 Aug 2004 18:12:57 GMT Subject: PEP318: radical notion Message-ID: Apologies for feeding the fire, when we are rallying around a consensus, but I've been concerned about the clash between syntax and semantics, and I've finally reached a mini-epiphany: The problem with PEP318 is that it is too powerful, and tries to do too much. It is a sledgehammer for attacking three problems: 1) Metadata, a la Java and C# 2) class & static method defs 3) Arbitrary post-definitional transformations of functions. (where 2 is a special frequent use case that's part of 3). We have ueber-powerful semantics (implementing 3), trying to solve problems with very different semantics (e.g., 1). OK, that's what I know. Here's a proprosal, that may or may not work, because my knowledge of metaclass programming is only sketchy: 1) Make PEP318 *only* implement problem (1). That is, create sematics for defining and retrieving function/method/class metadata 2) Create a new default metaclass that uses metadata for class/static method definitions to perform the necessary class/staticmethod transformations. Perhaps use this metaclass as default in 2.4 only via a "from __future__ import foo". 3) Leave any arbitrary transformations to be implemented via custom metaclasses -- these metaclasses will have access to the custom metadata to trigger method def transformations. Arien From jbors at mail.ru Thu Aug 5 14:01:23 2004 From: jbors at mail.ru (Dmitry Borisov) Date: Thu, 05 Aug 2004 22:01:23 +0400 Subject: Need help on how to use Pymedia! In-Reply-To: Message-ID: From: "CptPicard" Date: Thu, 05 Aug 2004 17:48:04 GMT Subject: Re: Re[2]: Need help on how to use Pymedia! > > Here is the code which will give you what you need( from pycar ). It is > modified to match what you need and therefore not tested.: > > > > f= open( , 'rb' ) > > dec= acodec.Decoder( ) > > s= f.read( 20000 ) > > fr= dec.decode( s ) > > # Hardcoding for mp3 IDv1 tags > > if not dec.hasHeader() and == 'mp3': > > f.seek( -128, 2 ) > > dec= acodec.Decoder( 'mp3' ) > > dec.decode( f.read( 128 ) ) > > > > print dec.getInfo() > > I appreciate your support. > I understand that this is a piece of code specially written for fixing my > problem but where could I find such example in pycar ? I looked for Decoder > in the pycar source code (pymedia*-src) and found no match. > > Do you include support for tag IDv2 too ? Yes it is. The code is located in pycar/audio/aplaylist.py class AudioFileList.getFileParams() The source for pycar is here: http://prdownloads.sourceforge.net/pymedia/pycar-1.0.0-pre2-src.zip Dmitry/ From roy at panix.com Fri Aug 6 08:19:43 2004 From: roy at panix.com (Roy Smith) Date: Fri, 06 Aug 2004 08:19:43 -0400 Subject: @decorators References: Message-ID: A few random comments: I really dislike the proposed syntax, for two main reasons. First, I don't like the idea of inventing new uses for punctuation (down that road lies perl). Second, I don't like the idea that you're creating a contextual block which violates (or at least ignores) the normal indenting rules. I just went to read pep-318 in its entirety, and discovered that the last modified date is only a few hours ago. People might want to go read the latest version. I'm also wondering about doc strings. Doc strings are really metadata, and if the idea of decorators is to build a uniform way to handle metadata, it would be nice to see it somehow include docstrings. There are clearly backward compatability issues to worry about, however. I'm also thinking about programming by contract. It seems like the pre- and post-condition assertions could also be thought of as meta-data. Some of the examples in the PEP hint at doing this, but don't address things contract inheritance. Has there been any discussion of this? Lastly, and perhaps most importantly, I'm rather distressed at the tone of some of the postings I've seen here over the past couple of days. Some of the sentiments I've seen expressed are downright rude, combative, and accusatory. These sorts of things are way out of line. Come on folks. It should be possible to express an opinion, even a strongly held one, without resorting to accusations of sinister plots or evil intent. I may not like the proposal, but at the same time I'm hugely appreciative of the hard work put in by the folks who proposed it, paid their own way to go to meetings where it was discussed, wrote the code, did the builds, etc, etc. They deserve accolades, not hostility. From rkern at ucsd.edu Tue Aug 24 12:36:00 2004 From: rkern at ucsd.edu (Robert Kern) Date: Tue, 24 Aug 2004 11:36:00 -0500 Subject: Weave - inline C In-Reply-To: <6f402501.0408232319.5967f0d@posting.google.com> References: <6f402501.0408232319.5967f0d@posting.google.com> Message-ID: Michael Foord wrote: > Has anyone had success using weave with gcc for windows (standard > windows distribution python)? > > I have my distutils setup to use gcc (via mingw32) - which it does > fine. I've compiled and installed various modules with it. Weave > itself installs fine, picking up the settings from distutils. > > However it has it's own version of distutils 'scipy_distutils' that it > uses to compile the C it is given - which complains that it can't find > msvcc.... The documentation included (which is actually for the 0.2 > version) gives no hints and I wondered if anyone had any success in > using it ? Use compiler='gcc' as a keyword argument for weave.inline(), etc. Yes, the documentation is fantastically out of date. > Regards, > > > Fuzzy -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From ben at benlast.com Mon Aug 16 07:34:00 2004 From: ben at benlast.com (Ben Last) Date: Mon, 16 Aug 2004 12:34:00 +0100 Subject: Best programming language In-Reply-To: Message-ID: Perhaps Pythonistas just hold this truth to be self-evident :) b > -----Original Message----- > From: python-list-bounces+ben=benlast.com at python.org > [mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of > Roman Suzi > Sent: 16 August 2004 10:56 > To: python-list at python.org > Subject: Re: Best programming language > This probably indicates that Python in not well enough described as "best" > for certain domains while Ruby isn't as humble ;-) From ramen at lackingtalent.com Wed Aug 25 20:26:23 2004 From: ramen at lackingtalent.com (Dave Benjamin) Date: Thu, 26 Aug 2004 00:26:23 -0000 Subject: Am I on the right path References: <10ipp5jbau4hb06@corp.supernews.com> Message-ID: In article <10ipp5jbau4hb06 at corp.supernews.com>, ADE wrote: > Nope just a project I wouldn't know how to create a virus worm or spambot > > I am just learning how to program in python > > But thanks for your concern as I can see the potential of something like > this Glad to see we're all so forward-thinking here. Remember, for your virus to work properly, you'll need to make sure it downloads and installs the Python language environment onto every host. PythonWin would be helpful too, assuming you're targetting Windows boxes. Good luck, Dave -- .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:. "talking about music is like dancing about architecture." From abra9823 at mail.usyd.edu.au Thu Aug 26 22:11:19 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Fri, 27 Aug 2004 12:11:19 +1000 Subject: key storage In-Reply-To: <412E8E53.20203@harvee.org> References: <1093569139.412e8a738462b@www-mail.usyd.edu.au> <412E8E53.20203@harvee.org> Message-ID: <1093572678.412e9847046d9@www-mail.usyd.edu.au> hi! i have already read the paper and am following the hints mentioned in the paper and also work in the same area mentioned in a couple of reports from the Open Web application security project. the MIT paper mentions including HMAC's in the cookie and so on. the question still is - how are the keys stored? HMAC's require a key, as do digital signatures. how are all these keys stored in a secure manner on the server? obviously they's be encrypted but then the key used for encrypting the above key - how is that stored? if you have implemented the system...can i ask you how you stored the keys? cheers Quoting "Eric S. Johansson" : > Ajay wrote: > > > hi! > > i am building a web application. for client authentication, i am using > > cookies which include the HMAC of the data. > > the server also has a public/private key pair for signing and > verifying > > information. > > start here. This is a really good site for Web based authentication > techniques. I've implemented the system and you are more than welcome > to the code. It may need some disentangling from my CGI/form > support/template environmentbut don't say you weren't warned. ;-) > > http://cookies.lcs.mit.edu/pubs/webauth.html > > let me know if I can help > > --- eric > > -- > http://mail.python.org/mailman/listinfo/python-list > ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From lbates at swamisoft.com Thu Aug 19 09:53:24 2004 From: lbates at swamisoft.com (Larry Bates) Date: Thu, 19 Aug 2004 08:53:24 -0500 Subject: singleton (newbie) References: Message-ID: Seems you are correct. I should have written: class B: x = 0 y = 1 def foo(self): print self.__class__.x def bar(self): print self.y self.__class__.y+=1 if __name__ == "__main__": b=B() b.foo() b.bar() b.foo() b.bar() b.bar() a=B() a.foo() a.bar() a.bar() Thanks for pointing this out. -Larry "Nicolas ?vrard" wrote in message news:mailman.1915.1092879132.5135.python-list at python.org... > * Larry Bates [01:54 19/08/04 CEST]: > >2) I continue to read on c.l.p. about staticmethods and > > just don't understand why anyone would use them. This > > is how I learned to write this in Python. It seems that > > they are some sort of "carryover" from another language. > > I'd be the first to admit I don't understand the appeal, > > so maybe they can be useful. I've just never needed them. > > If I need a static function, I just write it that way. > > I don't make it the method of a class object. > > > >if you want x, y to be global across all instances of B: > > > >class B: > > x = 0 > > y = 1 > > > > def foo(self): > > print self.x > > > > def bar(self): > > print self.y > > self.y+=1 > > > >if __name__ == "__main__": > > b=B() > > b.foo() > > b.bar() > > b.foo() > > b.bar() > > b.bar() > > It won't work. Different instances of B will have different values for > y. > > -- > (?> Nicolas ?vrard > / ) Li?ge - Belgique > ^^ From abra9823 at mail.usyd.edu.au Wed Aug 11 01:08:14 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Wed, 11 Aug 2004 15:08:14 +1000 Subject: rsa implementation question Message-ID: <1092200894.4119a9beb1978@www-mail.usyd.edu.au> hi! just like to know how the RSA implementation in the pcrypto package works. Does it operate in blocks, if yes, what is the size of the blocks? thanks cheers -- Ajay Brar, CS Honours 2004 Smart Internet Technology Research Group ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From atterdan at yahoo.com Wed Aug 11 15:57:43 2004 From: atterdan at yahoo.com (John Doe) Date: Wed, 11 Aug 2004 19:57:43 GMT Subject: using os.major Message-ID: Does anyone understand what a 'raw device number' is with respect os.major() and os.minor() Found in os-file-dir.html, section 6.1.4, os.major() description is: major(device) Extracts a device major number from a raw device number. New in version 2.3. The problem is, after searching I can only find two references to 'raw device number'. Naturally they are in os.major() and os.minor(). There seems to be something related to fileno, but that never returns the value I know is true. In particular, Linux /dev/fd0 is (2/0). Example: -------------------------------- >>> fd = open('/dev/fd0') >>> from os import major,minor >>> fd.fileno() 3 >>> major(fd.fileno()) 0 >>> minor(fd.fileno()) 3 >>> from os import popen3 [instd,outstd,errstd] = popen3( 'file /dev/fd0' ) >>> outstd.read() '/dev/fd0: block special (2/0)\n' As you can see, Major is 2, minor is 0. Which is also what ls -l /dev/fd0 reports. -------------------------------- I've written a function to parse up the 'file /dev/fd0' results, but I'd rather us the correct built in, or included modules, before writing my own. atterdan at yahoo.com From c0dec at gmx.de Sat Aug 28 03:52:36 2004 From: c0dec at gmx.de (Henning Kage) Date: Sat, 28 Aug 2004 09:52:36 +0200 Subject: Question about references/copies Message-ID: I'm using Python only for some months now and I'm wondering, whether such assignments as above are creating bitwise copies of an object or just recieve a reference. That means I wanted to know, wheter Python in general differs between references and copies: class someclass: def __init__( self, otherobject): self.someattribute = otherobject And my second question is, whether I should use a cast in such cases or not (I know, a cast isn't mandatory here...) Thanks a lot! From cookedm+news at physics.mcmaster.ca Sat Aug 21 22:50:26 2004 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Sat, 21 Aug 2004 22:50:26 -0400 Subject: speed References: Message-ID: At some point, Ayose wrote: > On Thu, Aug 19, 2004 at 03:37:26PM +0200, Peter Kleiweg wrote: >> >> I implemented a lexer in Pylly and compared it to the version I >> had written in Flex. Processing 219062 lines took 0.9 seconds in >> C (from Flex), and 5 minutes 54 second in Python (from Pylly), a >> ratio of 393 to 1. >> >> Is this normal for Python, or does Flex produce better parsers >> than Pylly? I have been looking at the code produced by Flex to >> see if I could translate it to Python automaticly. But it has a >> lot of goto statements, and I haven't figured out how to >> translate those to Python efficiently. >... > But, IMHO, if you has to process very big files, don't do it with > python. Instead, write a simple C-module, which uses your Flex parser > and creates python objects with that information. It should be trivial > if you have experience with the C API. :-) Or have a look at FlexModule at http://www.cs.utexas.edu/users/mcguire/software/fbmodule/ which makes it really simple without experience with the C API. -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From igorr at ifi.uio.no Sat Aug 28 18:00:12 2004 From: igorr at ifi.uio.no (Igor V. Rafienko) Date: 29 Aug 2004 00:00:12 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> <87hdqok9i6.fsf@sinken.local.csis.hku.hk> <1rfz68ely9.fsf@rovereto.ifi.uio.no> <876574k7du.fsf@sinken.local.csis.hku.hk> <1r3c28ejis.fsf@rovereto.ifi.uio.no> Message-ID: [ Paul McGuire ] [ ... ] > In fact, you can cite examples on this argument in either direction; I am a bit curious, what are the arguments _against_ an explicit end-of-block marker? Does such a marker create any problems? (I know that it solves a couple, though). As a side note -- my last employer had absolutely horrible coding conventions. No one liked them (developers and management included). However, everyone had to comply, and despite an occasional nastiness, the bug that you illustrated could not have happened in that environment, because _every_ if was required to have its body within braces. [ ... ] ivr -- My compiler compiled yours - Visual C++ .Net 2003 motto From eurleif at ecritters.biz Fri Aug 27 17:08:30 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Fri, 27 Aug 2004 17:08:30 -0400 Subject: allowing braces around suites In-Reply-To: References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> Message-ID: <2p9lv0Fift22U1@uni-berlin.de> Andrew Koenig wrote: > The following code is legal today: > > def foo(x): > print x > x = 3 > if x == 3: > { > foo(x) : 42 > } Gyaah, you almost gave me a heart attack there. Nicely done. From usenet_spam at janc.invalid Fri Aug 27 20:47:15 2004 From: usenet_spam at janc.invalid (JanC) Date: Sat, 28 Aug 2004 00:47:15 GMT Subject: Call for signatories for J2 References: Message-ID: Robert Brewer schreef: > Anthony Baxter wrote: >> Note that Robert has sent the completed proposal to python-dev, >> and in fine Python tradition, buggered off for the weekend. >> So I'm not entirely sure it's worthwhile posting more >> for/against messages now. > > I'll continue to collect them, and post updates on Monday. So feel free. FOR -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From jjl at pobox.com Thu Aug 12 16:39:48 2004 From: jjl at pobox.com (John J. Lee) Date: 12 Aug 2004 21:39:48 +0100 Subject: decorators vs GIL References: <96c2e938.0408091819.2cd7b50d@posting.google.com> <96c2e938.0408101428.1545fb26@posting.google.com> Message-ID: <87vffonl9n.fsf@pobox.com> sjdevnull at yahoo.com (G. S. Hayes) writes: [...] > No. I'm using alternative multiprocessing/event-driven programming > methods that are much less error prone (ie easier to program and > maintain) and easier to get good performance out of than using > threads. The core difference between threads and processes is that > threads share all their memory while processes have protected memory. > That difference _should_ be the deciding factor in whether you use > processes or threads in an application, although as I've said > throughout this thread two major platforms (Windows{see * below} and > Java) don't give you the tools to make that possible; thankfully, > Python does on OSes where it's possible. [...] ...although Java 1.4 does provide a select()-workalike -- see Alan Kennedy's recent post on implementing socket, select and asyncore for Jython. John From ben at benlast.com Tue Aug 17 09:54:55 2004 From: ben at benlast.com (Ben Last) Date: Tue, 17 Aug 2004 14:54:55 +0100 Subject: How big can a Python program be? In-Reply-To: Message-ID: Hmmm... are all the resulting code objects kept forever, or are those that are no longer required subject to garbage collection? If so, one could keep feeding expressions, such as x+y for random values of x & t, to the interpreter indefinitely :) Or, slightly more seriously, if completed code blocks are compiled to single code objects (as is done in a shell environment based on cmd.py) and then executed, one could keep feeding meaningful code segments to the interpreter indefinitely, as long as each is complete unto itself. Of course, each can process data "left" by the preceding ones, since they all execute within the same namespace. b > -----Original Message----- > From: python-list-bounces+ben=benlast.com at python.org > [mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of > Peter Hansen > Sent: 17 August 2004 14:46 > To: python-list at python.org > Subject: Re: How big can a Python program be? > > > Ben Last wrote: > > Unless I've misremembered, the Python interpreter executes > lines as they're > > entered, whether read from a file or typed in (with the exception that > > blocks of code made up of multiple lines are executed when the > last line is > > complete), so in theory, one could feed code to Python > indefinitely and it'd > > just keep going. > > You've misremembered. Python actually *compiles* the code prior > to executing it, turning it into bytecode. That means there is > definitely a limit on how much code can be handled, based if nothing > else on the memory in your PC. > > -Peter > -- > http://mail.python.org/mailman/listinfo/python-list From ramen at lackingtalent.com Fri Aug 27 12:02:08 2004 From: ramen at lackingtalent.com (Dave Benjamin) Date: Fri, 27 Aug 2004 16:02:08 -0000 Subject: Alex Martelli: Welcome back! Message-ID: It's nice to see you around here again! Dave From adurdin at gmail.com Wed Aug 11 08:13:00 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Wed, 11 Aug 2004 22:13:00 +1000 Subject: Getting the docstring of a property Message-ID: <59e9fd3a040811051326ced3b1@mail.gmail.com> How do you get the docstring of a property? Suppose I have the following: class Foo: def _prop_get(self): return 1 prop = property(_prop_get, doc="This is the docstring") foo = Foo() print foo.prop print foo.prop.__doc__ This will display "1", followed by the docstring for an integer (which is the docstring for the int() function). How can I get the property's docstring as defined in the property() function? From anthony_barker at hotmail.com Tue Aug 17 13:57:58 2004 From: anthony_barker at hotmail.com (Anthony_Barker) Date: 17 Aug 2004 10:57:58 -0700 Subject: Databases: Getting values by column name References: Message-ID: <899f842.0408170957.13719032@posting.google.com> what about db_rows? >>> cursor.execute('SELECT name, category FROM zoo;') >>> results = cursor.fetchall() >>> results [ ("Giraffe","mammal"), ("Dog","mammal") ] becomes: >>> cursor.execute('SELECT name, category FROM zoo;') # Make a class to store the resulting rows >>> R = IMetaRow(cursor.description) # Build the rows from the row class and each tuple returned from the cursor >>> results = [ R(row) for row in cursor.fetchall() ] >>> print results[1].fields.name, results[1]['category'] Unfortunately the http://opensource.theopalgroup.com/files/db_row-0.8.zip site seems to be down right now. I grabbed a copy (untested) from googles cache http://xminc.com/linux/db_rows.txt Anthony "Ben Last" wrote in message news:... > > From: python-list-bounces+ben=benlast.com at python.org > > [mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of > > Robert Ferber > > Anyway... > > only use database rows as sequences, ie as arrays with numerical index. > > This gives you loads of problems when using "select *" and also bad code > > readability when selecting specific columns. > > Is there a way to use them as dictionaries, ie with Index-Strings (=column > > names) as indexes? > The PEP describes the lowest-level database interface; usually you need to > wrap that with some application-aware code to get exactly what you need. > Anyway, the answer to your question is: Yes, if you're happy to write a > little extra Python. A cursor object, on which you've executed a SELECT, in > a PEP249-compliant module would normally have a "description" attribute; > this is a list of tuples, one per result column. The first element of each > tuple is the column name. So: > > conn = MySQLdb.connect(...) > cr = conn.cursor() > cr.execute("select * from myTable") > > #Look up the columns and get a list of their names, in order. This > #isn't necessary for the following code, it's here as an example. > cols = map(lambda x: x[0], cr.description)) > > #Build a list of dicts, one per row, with the values stored by column > names as keys. > #There are more elegant ways to do this; this is example code. > rows = [] > for raw_row in cr.fetchall(): > row = {} #start with an empty dict > for fieldIndex in range(len(cr.description)): > #Each description is a tuple with the first element > #being the field name. > row[description[fieldIndex][0]] = raw_row[fieldIndex] > rows.append(row) > cr.close() > > #Now "rows" is a sequence of dicts, one per row, with the values indexed > by column name. > > Just to be exact; the rows are returned as *tuples*, not arrays (at least in > MySQLdb; they might be lists in other database modules). Lists and tuples > are not necessarily the same as arrays in other languages, depending on > exactly how you define an array. > Various people (including me) have also written code to return each row as > an object that has the column values as attributes, so you can refer to them > as myRow.Column1 rather than myRow['Column1']. If you're interested, drop > me an email and I'll send you a module that can do that. It's part of the > Quasi shell (http://quasi-shell.sourceforge.net/ - gratuitous plug) which > has a lot of SQL handling built-in. > > regards > ben-who-spends-his-life-in-MySQLdb From fumanchu at amor.org Mon Aug 23 13:10:35 2004 From: fumanchu at amor.org (Robert Brewer) Date: Mon, 23 Aug 2004 10:10:35 -0700 Subject: J2 proposal: keyword Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E40@exchange.hqamor.amorhq.net> Oliver Fromme wrote: > Aren't decorators just functions that are applied to the > function definition? Then how about "apply"? It's short > (for those lazy typers), and it expresses exactly what > happens. "apply" is already a builtin. Robert Brewer MIS Amor Ministries fumanchu at amor.org From zanesdad at bellsouth.net Tue Aug 31 08:14:13 2004 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Tue, 31 Aug 2004 08:14:13 -0400 Subject: xmlrpclib In-Reply-To: <413462a1$0$5242$5a62ac22@per-qv1-newsreader-01.iinet.net.au> References: <413409c3$0$22823$5a62ac22@per-qv1-newsreader-01.iinet.net.au> <2hkd02-v7v.ln1@home.rogerbinns.com> <413462a1$0$5242$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: <41346B95.2060700@bellsouth.net> Graeme Matthew wrote: >I was a big vague, I hope this makes more sense. > >I am talking about the server end. > >I understand that xml-rpc is a request response mechansim (i.e it runs over >http). > >The client and the server will span continents i.e Australia to US, US to >Australia. >What I am trying to establish is if the server is asynchronous i.e >multi-threaded i.e what happens when 2 requests hit the server at once? > >i.e Does it handle one request at a time? > > This is the standard/unmodified behavior of the SimpleXMLRPCServer class. >i.e Does it start a new thread on each request? > > You have to write a little code to get it to do that. Here is an example snippet: class ThreadingXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer, SocketServer.ThreadingTCPServer): """Threaded XML-RPC server.""" def __init__(self, addr, requestHandler=SimpleXMLRPCServer.SimpleXMLRPCRequestHandler, logRequests=1): self.funcs = {} self.logRequests = logRequests self.instance = None SocketServer.ThreadingTCPServer.__init__(self, addr, requestHandler) if __name__ == "__main__": #server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000)) server = ThreadingXMLRPCServer(("", 8000)) server.register_instance(()) #server.register_introspection_functions() server.serve_forever() Whenever a request comes in, it is handled by a "process_request" method. The ThreadingTCPServer has overridden that method so that when a request comes in, it will spin off a new thread that executes a "process_request_thread" method. In the above piece of code, each incoming request will create a new thread. >i.e Does it use a threading pool? > > You could implement a thread pool if you like. Just look in the SimpleXMLRPCServer.py and SocketServer.py files and see what is going on in there, specifically in the SocketServer.py file around the ThreadingMixIn class. You could mimic that, create your own threadpool and when a request comes into "process_request", you could just hand it off to the thread pool. >I am trying to find other people who have used it successfully as most of my >dev work is in python. > > I'm using it now on a very small scale, but it's working great for me. Hope this helps. Jeremy >Hope this helps > >Cheers > >Graeme > > > >"Roger Binns" wrote in message >news:2hkd02-v7v.ln1 at home.rogerbinns.com... > > >>Graeme Matthew wrote: >> >> >>>Just wanted to know if anyone knows if xmlrpclib is scalable i.e can >>>handle many / asynchronous calls. >>> >>> >>You should specify what goal it is you are trying to achieve. For example >>it isn't clear if you are talking about the server end or the client >>end. >> >>Additionally you haven't said how far apart the client and server are. >>(Same machine? Same LAN? Same continent?) >> >>xmlrpc is not asynchronous. It is a request/response model. Each request >>gets exactly one response. There is no method for sending data outside >>of that. For example the server end can't send random event messages >>without the client end polling for them. >> >>And what do you mean by handle? Is that a speed question, a reliability >>question, a size of data structures question? >> >>Lastly the current Python xmlrpc implementation, both client and >>server end makes one network connection per request/response pair >>and then closes it. >> >>Roger >> >> >> >> > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From zathras at thwackety.com Tue Aug 31 06:52:55 2004 From: zathras at thwackety.com (Michael Sparks) Date: Tue, 31 Aug 2004 11:52:55 +0100 (BST) Subject: allowing braces around suites In-Reply-To: <1rsma49ge7.fsf@rovereto.ifi.uio.no> Message-ID: On Tue, 31 Aug 2004, Kjetil Torgrim Homme wrote: > [Michael Sparks]: > > > > The solution isn't to change the language in my eyes, the solution > > is to produce better tools. After all, the following is legal > > syntax in python if you really want close markers: > > > > end = None > > for ch in "hello": > > if ch == "l": > > print "Rhubarb" > > end > > print ch, > > end > > that's a really cool trick! I'm glad you like it :) I prefer your version however since it actually *does* something rather than lulling people into a false sense of security... :) (Still not sure I *like* either, but I prefer yours :) >I'm not saying this is useful, but it was fun to write :-) :) Best Regards, Michael. From sharidas at zeomega.com Fri Aug 20 00:55:44 2004 From: sharidas at zeomega.com (Satchidanand Haridas) Date: Fri, 20 Aug 2004 10:25:44 +0530 Subject: inverse of izip In-Reply-To: References: <41245B48.3020000@zeomega.com> Message-ID: <41258450.70108@zeomega.com> Hi Steve, Thanks for the explanation. I understand izip a little better now. Regards, Satchit Steven Bethard wrote: >Satchidanand Haridas wrote in message news:... > > >>Could you expand on what you mean by exhaust the iterators too early? >> >>The reason I ask is that the * operator is applied to >>((1,1),(2,2),....(9,9)). The operation of the >>itertools.izip(range10(),range10()) is completed before the * operation >>is applied. And the iter() simply converts the result of the inverse >>izip operation into an iterator. I hope the above was not too >>confusing. :-) >> >> > >Yeah, the difference is a little subtle here. What we have before you >use the * operator is an iterator that will yield (1,1) then (2,2) up >to (9,9). Note that we don't actually have the tuple >((1,1),(2,2),....(9,9)) yet, just an iterator that will produce the >same elements. If your list is very large and you don't want to keep >it all in memory at once, it's crucial that we have the iterator here, >not the tuple. > >When you use the * operator, Python converts the iterable following >the * into the argument list of the function. This means that if >you're using an iterable, it reads all of the elements of the iterable >into memory at once. That's why my range10 iterators printed >"exhausted" after the * application -- all their elements had been >read into memory. Again, if your list is very large, this is a bad >thing because you now have all the elements of the list in memory at >the same time. My other solution (well, Peter Otten's correction of >my solution) never has the whole list in memory at the same time -- >each time enumerate generates a tuple and it's index, each of the >iterators returned by starzip generates their appropriate items.[*] > >Steve > >[*] Of course, if you exhaust one of the iterators before the others, >itertools.tee's implicit cache will actually store all the elements, >so starzip would really only be efficient if you wanted to iterate >through the sub-iterators in lockstep. This means you'd probably want >to itertools.izip them back together at some point, but being able to >starzip them means you can wrap the individual iterators with extra >functionality if necessary. > > From xtian at toysinabag.com Tue Aug 10 19:39:47 2004 From: xtian at toysinabag.com (xtian) Date: 10 Aug 2004 16:39:47 -0700 Subject: @decorator syntax is sugar, but for what exactly? (decorator libraries). References: Message-ID: Skip Montanaro wrote in message news:... > > class martha: > memo = {} > > @staticmethod > def memoize(func): > if func not in martha.memo: > martha.memo[func] = {} > def _inner(*args, **kwds): > items = kwds.items() > items.sort() > items = tuple(items) > key = (args, items) > try: > val = martha.memo[key] > except KeyError: > val = func(*args, **kwds) > martha.memo[key] = val > return val > return _inner > > @martha.memoize > def fib(n): > assert n >= 0 > print n > if n <= 1: > return 1 > return n + fib(n-1) > > print fib(5) > print fib(4) > > Running that yields this output: > > 5 > 4 > 3 > 2 > 1 > 15 > 10 > > Skip Minor typo - I think the references to martha.memo[key] in _inner should be to martha.memo[func][key], enabling you to prevent different memoized functions' results from clashing when they were called with the same parameters. You can check this by adding another memoized function: @martha.memoize def fact(n): assert n >= 0 print n if n <= 1: return 1 return n * fact(n-1) print "fact(5) = %d" % fact(5) If you add that to the end of the file, it'll give the wrong answer without the change. Sorry Skip - obviously you know this, which is why you've got the martha.memo[func] = {} line there. I just thought it was worth pointing out in case someone put it into their toolkit and then got bit much later on when they memoized a second function that was called with the same arguments. It's a nice example of a useful decorator though - the syntax is definitely growing on me, especially in a syntax-highlighted editor where the def is more prominent because of colouring. Thanks, xtian From zathras at thwackety.com Mon Aug 23 15:37:49 2004 From: zathras at thwackety.com (Michael Sparks) Date: Mon, 23 Aug 2004 20:37:49 +0100 Subject: [PATCH] RE: J2 decorator grammar References: <412889c8$0$81159$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <412a4c8f$0$65908$ed2619ec@ptn-nntp-reader01.plus.net> Arien Malec wrote: > Michael Sparks wrote in > news:412889c8$0$81159$ed2619ec at ptn-nntp-reader02.plus.net: > >> So some other keyword is definitely preferable. Currently I'm swayed >> heavily by arguments in favour of "using" [...] > > "using" doesn't make the semantics clear. The naming for "decorators" > should be influenced not only by the basic use cases (in which the > function is annotated with metadata), but also the more edge-pushing use > cases, like classmethod, in which the semantics of the function are > changed. > > Me, I like: "transform:"... > > Arien For the patch I'm using SpanishInquisition since it'll make changing the keyword simpler. (Does mean I've got some odd code on my machine at the moment though :) I'm not going to impose anything (hence using SpanishInquisition for easy search and replace), however personally I'm swayed by "using" right now the most. (Ideally something like "decorate using" in a single clear word would be good, but in all likelihood not realistic) I agree that generally decorators transform the function, but I also note that many suggested decorators are declarative in nature so both "declare" and "transform" are incomplete, and potentially misleading. There's also the argument of namespace clashes. I haven't explicitly searched for projects with "transform" in use methods, packages, classes or variables, but I would be extremely surprised if I didn't find one. Similarly "declare" has problems since I did do a quick search and was able to find several projects including the excellent Pyrex project that uses that as a method. (Similarly for a bare "decorate" has a clash with mailman) Whilst it's acceptable to say "all new code should avoid keywords", picking a commonly used words which clash with widely deployed code strikes me as a bad thing *if* it can be avoided (very hard, but worth considering). The reason I say this is given the widespread deployment and use of mailman, breaking people's mailing list software (for example) simply because they upgraded python is an admin overhead worth avoiding *if* possible. When I did some checking for "using" I was rather suprised that out of a couple of dozen or so projects the only one I could find using it was python itself in one method (webbrowser.get) as a single named parameter, and I couldn't find a project using it. (I haven't checked Zope or twisted because I didn't have those to hand, it might be useful for someone to check these...) I agree as a result that whilst "using" doesn't make the semantics as clear as I'd (it offloads the semantics to the transforms/declarations associated), it is clear that it can't stand alone, and is less potentially misleading: transform: author("Joe Bloggs") Regarding another post I've seen by yourself I would argue that "using" falls into the "semantically neutral" camp, which I personally view as the best option here beyond using something much more verbose like "decorators". That itself doesn't really work very well with a single decorator (common case) since it just looks wrong due to being a plural. If you can find a word that captures the relative opposites of "declare" and "transform" in a single (short?) word I'd REALLY be interested. (especially if it doesn't clash with lots of existing code... :-/ ) Mind you if we all decided to call decorators "sheep" this plural vs non-plural issue would be resolved, and we'd all have something clear to search for: sheep: author("Joe Bloggs") Component(inboxes=["inbox","control"], outboxes=["outbox","signal"]) def myGenerator(self, max=10): "Hypothetical generator decorated with named ports for IPC" foo =0 while foo ;-) Michael. From jerf at jerf.org Tue Aug 24 19:42:02 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Tue, 24 Aug 2004 23:42:02 GMT Subject: python raw strings? References: <412bc766$1@news.unimelb.edu.au> Message-ID: On Tue, 24 Aug 2004 22:55:37 +0000, Maurice LING wrote: > I've tried to look up in the python documentation but > it just vaguely brushes through by saying that python raw strings are > prefixed with "r" or "R". > > Can someone point me in the correct direction? http://www.python.org/doc/2.3.4/ref/strings.html , last two paragraphs. From peter at engcorp.com Mon Aug 30 08:50:04 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 30 Aug 2004 08:50:04 -0400 Subject: Generator expressions v/s list comprehensions In-Reply-To: References: <1gj8y77.6qshr41q531veN%aleaxit@yahoo.com> Message-ID: <8fSdnXPuTtTjv67cRVn-ug@powergate.ca> A small correction: Martin DeMello wrote: > Here's a simple example > > linecount = sum(1 for line in file) > linecount = sum([1 for line in file]) > > The former requires an in-memory list equal to the size of the file. ^^^^^^ I think you meant "the latter"... > Consigning "other than memory consumption" to a parenthetical remark > misses its importance. -Peter From peter at engcorp.com Tue Aug 17 00:04:26 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 17 Aug 2004 00:04:26 -0400 Subject: Flython? In-Reply-To: <3d06fae9.0408161928.555b1539@posting.google.com> References: <411cbcb1$0$3894$4d4ebb8e@news.nl.uu.net> <30260531.0408131856.5ef3b0d3@posting.google.com> <2oc547F86br8U1@uni-berlin.de> <3d06fae9.0408161928.555b1539@posting.google.com> Message-ID: <6K-dnQw_4eFWHrzcRVn-vg@powergate.ca> jmdeschamps wrote: > Well, what about Ming ??? > http://www.freenet.org.nz/python/ming Not sure... Ming appears to be in an extremely early form, and there are suggestions it's not very stable yet (and I think that word was used in the sense of "unreliable", not just "changing"). The script support appears to be "C-like, with a very limited feature set". Doesn't even allow function calls?! That can't be good. Maybe improvements are on the roadmap. I'm not sure why they would have chosen to go with a C-like scripting language, however, instead of growing an ECMAScript language piece by piece. Or just adopting an existing component from some other project... maybe from spidermonkey or something. I really don't know. This stuff is not yet something I know much about. -Peter From newsgroups at jhrothjr.com Fri Aug 6 09:33:25 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 6 Aug 2004 09:33:25 -0400 Subject: PEP 263 status check References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> <10h5hgvpafm8a64@news.supernews.com> <41133C76.8040302@v.loewis.de> <10h6rklt3fa1690@news.supernews.com> <41137799.70808@v.loewis.de> Message-ID: <10h724r20kkeqb2@news.supernews.com> "Martin v. L?wis" wrote in message news:41137799.70808 at v.loewis.de... > John Roth wrote: > > Or are you trying to say that the character string will > > contain the UTF-8 encoding of these characters; that > > is, if I do a subscript, I will get one character of the > > multi-byte encoding? > > Michael is almost right: this is what happens. Except that > what you get, I wouldn't call a "character". Instead, it > is always a single byte - even if that byte is part of > a multi-byte character. > > Unfortunately, the things that constitute a byte string > are also called characters in the literature. > > To be more specific: In an UTF-8 source file, doing > > print "?" == "\xc3\xb6" > print "?"[0] == "\xc3" > > would print two times "True", and len("?") is 2. > OTOH, len(u"?")==1. > > > The point of this is that I don't think that either behavior > > is what one would expect. It's also an open invitation > > for someone to make an unchecked mistake! I think this > > may be Hallvard's underlying issue in the other thread. > > What would you expect instead? Do you think your expectation > is implementable? I'd expect that the compiler would reject anything that wasn't either in the 7-bit ascii subset, or else defined with a hex escape. The reason for this is simply that wanting to put characters outside of the 7-bit ascii subset into a byte character string isn't portable. It just pushes the need for a character set (encoding) declaration down one level of recursion. There's already a way of doing this: use a unicode string, so it's not like we need two ways of doing it. Now I will grant you that there is a need for representing the utf-8 encoding in a character string, but do we need to support that in the source text when it's much more likely that it's a programming mistake? As far as implementation goes, it should have been done at the beginning. Prior to 2.3, there was no way of writing a program using the utf-8 encoding (I think - I might be wrong on that) so there were no programs out there that put non-ascii subset characters into byte strings. Today it's one more forward migration hurdle to jump over. I don't think it's a particularly large one, but I don't have any real world data at hand. John Roth > > Regards, > Martin From geoff at variosoft.com Sun Aug 8 09:00:32 2004 From: geoff at variosoft.com (Geoff Caplan) Date: Sun, 8 Aug 2004 14:00:32 +0100 Subject: Encryption between Python & PHP Message-ID: <16518147514.20040808140032@variosoft.com> Hi folks, I am looking for a practical way of sending encrypted strings back and forth between a Python HTTP client on Windoze and an Apache/PHP server on Linux. I am looking for a simple, lightweight symmetrical solution using, say, blowfish: SSL would be a last resort as I suspect it will cause fairly major installation issues on the client. Encryption in PHP uses a wrapper around the mcrypt C library. There is a wrapper for mcrypt in Python, but I am having trouble getting it installed on Windows: I have contacted the author for help. Meanwhile, I do have SSLcrypto installed: this is a very neat and fast library. Is there any way for SSLcrypto on Python to talk to mcrypt on PHP? My first attempts have been unsuccessful. I have little crypto knowledge, and at first I though that something like blowfish was a standard and different libraries should be compatible. Now I suspect that internal implementation varies between libraries and you have to encrypt/decrypt with the same library. Can anyone enlighten me? ------------------ Geoff Caplan Vario Software Ltd (+44) 121-515 1154 From fuzzyman at gmail.com Wed Aug 25 03:17:24 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 25 Aug 2004 00:17:24 -0700 Subject: Python and C, looking for a C IDE References: <6f402501.0408240353.2a5b8a84@posting.google.com> <144d0df.0408241754.6bac1a44@posting.google.com> Message-ID: <6f402501.0408242317.57fd39f8@posting.google.com> grv575 at hotmail.com (grv575) wrote in message news:<144d0df.0408241754.6bac1a44 at posting.google.com>... > C IDE? DevC++ is sweet. It's on sourceforge. Python IDEs -- > winpython on windows, eric3 on linux is great. Also compile wxPython > to get pyCrust (windows or linux). Really good code completion/call > tips. Thanks. I've never got round to trying pyCrust... must give it a go. Regards, Fuzzy http://www.voidspace.org.uk/atlantibots/pythonutils.html From python at rcn.com Thu Aug 26 01:51:46 2004 From: python at rcn.com (Raymond Hettinger) Date: 25 Aug 2004 22:51:46 -0700 Subject: python-dev Summary for 2004-08-01 through 2004-08-15 References: <87y8k35ahi.fsf@pobox.com> Message-ID: <5d83790c.0408252151.134712ec@posting.google.com> jjl at pobox.com (John J. Lee) wrote in message news:<87y8k35ahi.fsf at pobox.com>... > Richie Hindle writes: > > > [Istvan] > > > what does: > > > > > > > It is not to be used in the stdlib ever. > > > > > > mean in this context? > > > > As I understand it, it means that no standard library code should take > > advantage of the fact that repeated s1 += s2 operations are fast in CPython > > 2.4. Instead, it should use the ''.join() idiom. > [...] > > The stdlib already *does* take advantage of the patch. > > It began taking advantage of it the instant the code was committed, > because, for example, httplib.HTTPResponse_read_chunked() uses string > concatenation. Yes, the standard library does benefit. The += style is occasionally used either out of necessity or for simplicity in some places. For the most part, whereever it really matters, ''.join() was always used. There are some places like the sre modules where the cost of building up small lists and joining them does not pay for itself. Also, I believe (but haven't checked recently) that some SAX code also uses += because the consecutive additions take place across calls and the string is expected to be available after each. In some places, there are just a small constant number of string adds that don't warrant using less straight-forward coding for speed. If you see a time critical section of library code that can profitably be converted to ''.join(), then please submit a patch. If it is not time sensitive, resist the temptation to optimize it. That guidance can also apply to non-library code. The purpose of the += optimization was to make it less disasterous when someone forgets to use ''.join(). Ideally, the experts will leaving their coding styles unchanged. Raymond From mahesh at privacy.net Sat Aug 28 14:19:55 2004 From: mahesh at privacy.net (Mahesh Padmanabhan) Date: Sat, 28 Aug 2004 12:19:55 -0600 Subject: Generator expressions v/s list comprehensions Message-ID: Hi, When list comprehension was added to the language, I had a lot of trouble understanding it but now that I am familiar with it, I am not sure how I programmed in Python without it. Now I see that generator expressions have been added to the language with 2.4 and I question the need for it. I know that it allows for lazy evaluation which speeds things up for larger lists but why was it necessary to add it instead of improving list comprehension? Was there some sort of limitation that prevented list comprehension from taking over the functionality that generator expressions provide? I have always liked the fact that Python has limited capabilities for having more than one way to do it and it seem to me that generator expressions break that philosophy. It is similar to how you have to use range or xrange depending on how large the range is. Can someone please explain the reasoning behind it? Thanks, Mahesh From lbates at swamisoft.com Mon Aug 2 17:06:03 2004 From: lbates at swamisoft.com (Larry Bates) Date: Mon, 2 Aug 2004 16:06:03 -0500 Subject: Class optimization at runtime References: Message-ID: Kind of hard to tell what you are trying to accomplish but I'll try. Define the class with no if/else statements. They only get parsed once. It is the "class instance" creations that may get created millions of times. They will be inside your logical structure. class Foo: def __init__(self): # do stuff class Bar: def __init__(self): # do stuff if option: x=Foo() else: x=Bar() HTH, Larry Bates wrote in message news:mailman.1061.1091479321.5135.python-list at python.org... > I would like to optimize my classes at run time. The question > is where to put my "if" statement. > -Inside __main__? > if option: > class Foo: > def __init__: > #do stuff > else: > class Foo: > def __init__: > #do other stuff > -Inside class definition? > class Foo: > if option: > def __init__: > #do stuff > else: > def __init__: > #do other stuff > -Inside each method definition? > class Foo: > def __init__: > if option: > #do stuff > else: > #do other stuff > > Class instances will be created millions of times and the > method's on them called even more so whatever brings the most > speed will be used. I fear that the more readable way to do it > is also the slowest. > > Thanks in advance, > -Brian From me at privacy.net Wed Aug 11 10:14:45 2004 From: me at privacy.net (Dan Sommers) Date: 11 Aug 2004 10:14:45 -0400 Subject: Python equivalent to a C trick References: <4119327f$1@pfaff2.ethz.ch> Message-ID: On Tue, 10 Aug 2004 23:23:07 GMT, "Paul McGuire" wrote: > You have 0.5 dollars > You have gained 1 pound > You increased temperature by 0 degrees > You have -2 dollars (that is, you owe 2 dollars) Don't forget this one: You have -1 egg. Regards, Dan -- Dan Sommers Never play leapfrog with a unicorn. From dd55 at cornell.edu Tue Aug 3 17:46:46 2004 From: dd55 at cornell.edu (Darren Dale) Date: Tue, 03 Aug 2004 17:46:46 -0400 Subject: executing python programs as if they were on OS path (noob) In-Reply-To: References: Message-ID: Peter Hansen wrote: > Darren Dale wrote: > >> I'm on XP. > > > Ah, then it's easy. > > If you've installed the standard distribution properly, it very likely > is already set up so that merely typing the name of the Python script > on the command line will search in the directories in PATH for the > matching script, and execute it. In other words, just stop typing > "python" in front of the script name! :-) > > And if you have the PATHEXT environment variable set up to contain > ".py" then you won't even have to put .py on the end... > > -Peter You know, I tried that the other day, and it didnt work. I think I know the reason: when the DOS terminal loads, PATH is read. I didn't restart the terminal after changing PATH. Thanks for your help. Its working now. From __peter__ at web.de Tue Aug 3 17:46:32 2004 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Aug 2004 23:46:32 +0200 Subject: Class optimization at runtime References: <10gvtipb5t0hl44@corp.supernews.com> Message-ID: Jeff Shannon wrote: > Or even better: > > if option: > import WithOption as FooModule > else: > import WithoutOption as FooModule > > x = FooModule.Foo( ) > > (I twitch every time I see 'from X import *' ...) That, and mixed-case module names -- and no, I'm not advertising all-uppercase here... Peter From martin at v.loewis.de Sun Aug 8 06:55:00 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 08 Aug 2004 12:55:00 +0200 Subject: Compiling disutil modules on Windows In-Reply-To: References: <13185971049.20040808082256@variosoft.com> Message-ID: <41160684.5010003@v.loewis.de> Geoff Caplan wrote: > I tried renaming the extension without the leading underscore but this > generates an error. I am new to Python: perhaps a SWIG guru could > explain why the underscore is required, or if not required, how it can > be avoided? I am not a SWIG guru, but I can explain why you cannot rename an extension DLL. Inside the DLL, there is an entry point function with a name similar to the DLL name. When the DLL is renamed, the entry point is not - but Python expects that the entry point then matches the DLL name. As for the SWIG issue - I believe swig also generates a Python module example.py which you are meant to use instead. Regards, Martin From mjackson at alumni.caltech.edu Fri Aug 13 13:10:32 2004 From: mjackson at alumni.caltech.edu (Mark Jackson) Date: 13 Aug 2004 17:10:32 GMT Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: Dave Brueck writes: > beliavsky at aol.com wrote: > > > One of the most commmon reasons programmers cite for not trying Python > > is that indentation determines the program flow -- they think its > > weird. > > Yes, that is commonly cited. From the programmer's perspective, > indentation implies program flow in nearly *all* modern languages. The > difference is that in Python the compiler believes you. > > > I think programmers who actually try Python adapt quickly and > > do not find the indentation rules to be a problem. > > Yep! > > > I wonder if there is a way to remove this initial barrier. > > I sure hope not... if someone can't accept that there might be value in > it being different than what they're used to (so much so that they're > unwilling even to give it a try), then the indentation is only the first > of many things that will give them problems. > > In that sense it's really useful - maybe it weeds out people who > wouldn't be happy in Python yet anyway <0.5 wink>. To this end, it's worth remembering that Eric Raymond has described indentation-based blocking as Python's /pons asinorum/: http://www.linuxjournal.com/article.php?sid=3882 -- Mark Jackson - http://www.alumni.caltech.edu/~mjackson Fascism should more properly be called corporatism, since it is the merger of state and corporate power. - Benito Mussolini From cjw at sympatico.ca Fri Aug 13 13:38:53 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Fri, 13 Aug 2004 13:38:53 -0400 Subject: Idea for alternative use for @ In-Reply-To: References: <4L4Tc.6967$nu2.3787@fe2.texas.rr.com> Message-ID: Bernhard Herzog wrote: > "Paul McGuire" writes: > > >>I thought it might be useful to include some sort of compiler directive like >>a C++ pragma to represent this kind of compile-time meta information. And >>it struck me that '@' would be an excellent marker for such a statement, >>something like: >>@tabsize 8 > > > FWIW, that particular directive already exists. To set the tab width to > 4 you can do either > > # :ts=4 > > or if you prefer emacs style: > > # tab-width:4 > > It's an undocumented (mis-)feature of CPython, though, IIRC. > > Bernhard > tabs are a pain. The recommended approach is to replace them with spaces. Colin W. From pythonista at sbcglobal.net Wed Aug 25 11:35:27 2004 From: pythonista at sbcglobal.net (Brian Almond) Date: 25 Aug 2004 08:35:27 -0700 Subject: age of Python programmers References: Message-ID: <411e4639.0408250735.2fff48bd@posting.google.com> "Lucas Raab" wrote in message news:... > One thing I've always kind of wondered is what is the average age of a > Python programmer?? 31 here. I started experimenting with code when I was pretty young. Started out on my father's IMSAI 8080 (which moved into my room when we got our first IBM PC :). Python got my attention around the time the DDJ issue came out with Guido & Larry Wall on the cover. From bart_nessux at hotmail.com Mon Aug 23 10:32:31 2004 From: bart_nessux at hotmail.com (Bart Nessux) Date: Mon, 23 Aug 2004 10:32:31 -0400 Subject: 2 GB files In-Reply-To: <9418be08.0408221939.7003bd3c@posting.google.com> References: <9418be08.0408221427.182a4d30@posting.google.com> <9418be08.0408221939.7003bd3c@posting.google.com> Message-ID: Elbert Lev wrote: >>Elbert: you might get a positive response if you rephrased your post. >> >>"Our corporation needs functionality ___. We would be happy to pay a >>contract consultant $n000 to come up with a solution that will work with a >>future trajectory of Python releases." >> >> >>David > > > David! > > I appreciated your sarcasm very much. > > I want to assure you that our corporation is perfectly able to hack > code not worse then others can. But reading the postings, which talk > about this issue I thought, that if this feature is "half" supported > and is widely requested, why not to explain why it is needed. > > IMHO the most attractive feature of Python is not its syntax, but the > library and the size of distribution. In fact, straight from the box > 8-9 MB distribution is sufficient to solve many everyday > programming/administration problems. This is good, but can be > improved. There are some needed pieces missing in standard > distribution and this is one of them. By the way I (almost) do not > care about the speed: it is reasonable right now, can be improved, by > proper data structure/algorithm selection and if one really needs > speed ? C is available. > > I suggest start discussing additions to the library. This will improve > the package and make it easier to administer. > > >>Or you could pray to the OSS gods. > > > All is about language acceptance. > > In my daily programming activities there are several alternatives to > Python, f.e. Java or .NET with their comprehensive libraries of > classes (much richer then Python's). And what stops me from using it? > The size of the distributive! I understand that adding too much will > result in an increase of the size of distribution, but something has > to be done. Having never used Java or .NET... how do they compare in size to Python? I've found that the standard Python download works for me in 95% of the tasks in Windows (sys admin tasks). But sometimes I need Hammond's win32 extensions, but only rarely. I've also used the pexpect module a lot... I wish that would be integrated into the main distro, but overall, I'm very pleased with the balance of bang for the buck... Oh, I forgot, Python is free. Perhaps the developers are willing to provide a refund to dissatisfied users ;) From squirrel at WPI.EDU Tue Aug 17 08:58:03 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 17 Aug 2004 08:58:03 -0400 Subject: music resources In-Reply-To: References: Message-ID: On Mon, 16 Aug 2004, Elaine Jackson wrote: > Is there such a thing as an executable language for music? Yes. Lilypond [http://www.lilypond.org/web/] is a music typesetting language that provides beautiful (i.e. much better than Finale or what-have-you) PDF/PS output, MIDI output, and HTML/info/what-have-you integration. > Naturally the ideal thing would be if such a language were implemented > within python, but I would be willing to learn a lesser programming > language if I had a reasonable assurance that it had what I'm looking > for. Lilypond is a mix of Scheme, TeX, and its own native language. Scheme certainly is not a 'lesser' language, while TeX is a very powerful macro language. Though you don't need to know either of them to write Lilypond programs, it helps to do advanced stuff. A short Lilypond snippet: e8 d c d e e e r | d d d r e g g r | e d c d e e e e | d d e d c4 r | where '|' is a barline, 8 and 4 are note lengths (which are inherited by subsequent notes), and r is a rest. From kraus at hagen-partner.de Fri Aug 27 09:02:28 2004 From: kraus at hagen-partner.de (Wolfram Kraus) Date: Fri, 27 Aug 2004 15:02:28 +0200 Subject: allowing braces around suites In-Reply-To: <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> Message-ID: Kjetil Torgrim Homme wrote: [...] >> Regardless of history, it looks to me like your problem could be >> better solved by modifying your emacs mode to consider whitespace >> more correctly -- AFAICT there is no reason why it should ever >> pick up the logging line in your example and indent it to the same >> level as the else: block. > > > how can Emacs tell? if I press TAB and thus ask Emacs to re-indent > the line, that's what it will do. arguably, the correct fix is to > disable the "clever" re-indentation code of Emacs since it's too easy > to fool it, but this makes coding more awkward in other cases. it > also doesn't solve cut-n-paste errors. You can use C-c < or C-c > in Emacs to (de-)indent regions. Wolfram From wweexxsseessssaa at shaw.ca Tue Aug 24 20:34:09 2004 From: wweexxsseessssaa at shaw.ca (John W. Hall) Date: Wed, 25 Aug 2004 00:34:09 GMT Subject: age of Python programmers References: Message-ID: 59 Is "the age of Python programmers" anything like "The Age of Aquarius"? (i.e. The Dawning of) -- John W Hall Cochrane, Alberta, Canada. "Helping People Prosper in the Information Age" From jpmorichon at earthlink.net Wed Aug 4 22:28:48 2004 From: jpmorichon at earthlink.net (CptPicard) Date: Thu, 05 Aug 2004 02:28:48 GMT Subject: Need help on how to use Pymedia! Message-ID: Hi, I am currently trying to use pymedia so to get the following informations (author, song title, ...) from a mp3 file. The documentation I downloaded is quite limited : It gives some clues on how to get that information (method getInfo() from pymedia.audio.acodec). However, it does not explain what has to be done prior to that call. I downloaded pycar but it did not help me. Could someone give me a more detailed documentation on pymedia or some clues on how to get the information I need ? Thanks for your help From anthonybaxter at gmail.com Thu Aug 5 12:43:41 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 02:43:41 +1000 Subject: RELEASED Python 2.4, alpha 2 In-Reply-To: References: <411231C8.3020308@interlink.com.au> Message-ID: On Fri, 6 Aug 2004 02:41:10 +1000, Anthony Baxter wrote: > On Thu, 5 Aug 2004 12:29:51 -0400, Christopher T King wrote: > > What does one do if a decorator raises an exception? > > def deco(func): > raise TypeError > > @deco > def foo(): > print "hello" Sigh. I missed this bit of cut-n-paste: Traceback (most recent call last): File "f.py", line 4, in ? @deco File "f.py", line 2, in deco raise TypeError TypeError From eurleif at ecritters.biz Sat Aug 21 23:22:35 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sat, 21 Aug 2004 23:22:35 -0400 Subject: Getting benifits of database transactions in an OO way? In-Reply-To: <7xu0uwlztw.fsf@ruckus.brouhaha.com> References: <2oq8pmFdd2nfU1@uni-berlin.de> <7xk6vsklxm.fsf@ruckus.brouhaha.com> <2oqb54Fdj12nU1@uni-berlin.de> <7xu0uwlztw.fsf@ruckus.brouhaha.com> Message-ID: <2oqhlkFdi80eU1@uni-berlin.de> Paul Rubin wrote: > Leif K-Brooks writes: > >>How woould begin_transaction() and finish_transaction() be >>implemented? They couldn't be simple wrappers for PostgreSQL >>transaction handling, since it's not very object-oriented (the whole >>connection has one transaction at a time). > > > Yes, if you want multiple concurrent transactions, you need separate > connections for them. But then multiple row classes would have to create their own connections, which would be bad for performance: import people import companies people_transaction = people.begin_transaction() companies_transaction = companies.begin_transaction() microsoft = companies_transaction.find_by_name('Microsoft') microsoft.patent_something_trivial() bill = people_transaction.find_by_name("Bill Gates") bill.money += 1000000 people_transaction.finish_transaction() companies_transaction.finish_transaction() I think I'll just require users of modules which handle data to commit on their own. Not ideal, but it seems to be the best possible. From fowlertrainer at anonym.hu Tue Aug 17 07:00:20 2004 From: fowlertrainer at anonym.hu (fowlertrainer at anonym.hu) Date: Tue, 17 Aug 2004 13:00:20 +0200 Subject: os popen problems in w98 Message-ID: <4121E544.1080200@anonym.hu> Hi ! I use this code section in my program: cho,chi=os.popen2(os.getcwd()+'/genlotto.py') genlotto=chi.read() genlotto=genlotto.strip()[1:-1] This code is working on wxp, and w2000. I use that code to load a subprogram's result. In Win98 it is hanged, and is nothing happened. Why ? What I do wrong ? Thanx for help: FT From tdelaney at avaya.com Fri Aug 6 01:10:58 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Fri, 6 Aug 2004 15:10:58 +1000 Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01C8C636@au3010avexu1.global.avaya.com> Anthony Baxter wrote: > The solution, if you don't like the syntax, is not voting. It's to > propose an argument that Guido will accept, in favour of your > preferred option. I see this less as a vote, and more an attempt to reach a community consensus - or at least a large enough one to lend weight to the many arguments that have already been presented. I will live with pie-syntax, but I won't be overly happy with it. I would much prefer that list-after-def be accepted. Tim Delaney From megalomaan at hotmail.com Tue Aug 17 20:21:17 2004 From: megalomaan at hotmail.com (Johan) Date: Wed, 18 Aug 2004 02:21:17 +0200 Subject: strange problem with def in class Message-ID: <1092788477.995526@seven.kulnet.kuleuven.ac.be> I don't get it: I'm trying to write a "readfile" function which would replace some code from a __init__ function: 1 import string 2 class landdict: 3 def __init__(self, file): 4 # Laadt de dictionnary van landen. 5 # Kijk in de actiefspel-file voor de file van waaruit je moet laden. 6 self.ld = {} 7 f = open(file, "r") 8 line = f.readline() 9 if line[0] == "#": 10 line = f.readline() 11 while line != "": 12 key = line[0:3] 13 self.ld[key] = string.split(line[4:], ':') 14 line = f.readline() 15 print self.ld So I would like to replace the code from line 7 to line 14 with readfile(filename) while def readfile(filename) is another function in the class but I can't define this function.... when I call the function the interpreter throws an exception of unknown function what am I doing wrong? -- ____________________________________________________ Johan Potums Vaartstraat 67 3000 Leuven johan.potums at student.kuleuven.ac.be --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.737 / Virus Database: 491 - Release Date: 11/08/2004 From finite.automaton at gmail.com Thu Aug 19 13:03:25 2004 From: finite.automaton at gmail.com (Lonnie Princehouse) Date: 19 Aug 2004 10:03:25 -0700 Subject: age of Python programmers References: Message-ID: <4b39d922.0408190903.2293b7bd@posting.google.com> Robbie wrote in message news:... > Man my english skills are bad, can Python fix those? ...working on a PEP to address this (hopefully will be implemented in Python 3.0) lol From joewong at mango.cc Thu Aug 12 05:15:46 2004 From: joewong at mango.cc (Joe Wong) Date: Thu, 12 Aug 2004 17:15:46 +0800 Subject: question on py2exe and DLL Message-ID: <0d4701c4804c$f428c940$7f00a8c0@scl01.siliconcreation.com> Hi, I have an application which is converted to binary using py2exe. How I can make a DLL (also written in python) that can be loaded by a py2exe converted application? In short, I have two .py files implement the same class and methods ( but internall, they are different ). In the script, I can simply change the import statement to use the .py file that I want but I don't know how to do it after it is py2exe packed.. Regards, - Joe -------------- next part -------------- An HTML attachment was scrubbed... URL: From anthonybaxter at gmail.com Fri Aug 6 06:21:13 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 20:21:13 +1000 Subject: Python milestone releases In-Reply-To: References: <4113406D.1@v.loewis.de> Message-ID: On Fri, 06 Aug 2004 11:49:52 +0200, David Fraser wrote: > What may be easier in some situations is to have back-ported versions of > new standard modules that will run with previous versions of Python. > For example, Python 2.3 introduces the datetime module ; to require > people to upgrade from Python 2.2 for a new module seems steep ... That happens sometimes - for instance, spambayes includes a version of the sets.py module for Python 2.2. But in general it's probably not going to happen unless someone steps forward to do it - there's very little advantage to me, for instance, in doing this, as I don't run 2.2 on anything. (2.3 was such a painless upgrade from 2.2 that I don't have a problem doing this). Note, though, that there is a pure-python version of the datetime module (it was the original version) so you're probably in luck. Assuming, of course, that it doesn't use any 2.3-isms. From RexStJames at gmail.com Thu Aug 19 11:38:43 2004 From: RexStJames at gmail.com (Rex) Date: 19 Aug 2004 08:38:43 -0700 Subject: age of Python programmers References: Message-ID: <98e5d78f.0408190738.23a2b53d@posting.google.com> "Lucas Raab" wrote in message news:... > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... Well, I happen to 17 right now. I've been using Python (my first (real) language!) for a couple years. I say 'real' because I did some "programming" of my TI-86 graphing calculator (syntax quite similar to BASIC) prior to that, but that hardly counts. Funny story: I taught a 4th grader how to program in Python. He decided he wanted to learn how to program a computer, so we sat down over about a week on an elementary school Mac. and I taught him about variables, strings, input/output, conditionals, and started talking about while loops. We had a great "guess the number the computer is thinking of..." game going by the end. (Too high... Too low... You win!) So, does he win the award for youngest Python programmer? From peter at engcorp.com Mon Aug 16 00:52:46 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 00:52:46 -0400 Subject: Flython In-Reply-To: References: Message-ID: Dave Benjamin wrote: > I just want to say, for the record, that if anyone can successfully build a > Python compiler that can produce Flash bytecode, I will personally allow > you to throw *any number of pies* in my face, in as public of a ceremony as > you desire. Furthermore, I will match you 50/50 in the cost of the pies. Why on earth (unless it's the liking pies thing or the really wanting this to be done thing) would you say that? Flash bytecode is pretty straightforward, and Python's not magic. In any case, if this is a serious challenge, you'd better start identifying the constraints and minimum requirements, as I'm rather positive that it's possible to encode at least *one* Python statement (print) into Flash bytecode which would execute properly... shall I demonstrate for, say, one pie? -Peter From andy47 at halfcooked.com Mon Aug 2 17:10:51 2004 From: andy47 at halfcooked.com (Andy Todd) Date: Mon, 02 Aug 2004 22:10:51 +0100 Subject: MySQLdb select In-Reply-To: <21064255.0408020908.41357e52@posting.google.com> References: <9RPOc.2792$LI7.1058@newssvr27.news.prodigy.com> <21064255.0408020908.41357e52@posting.google.com> Message-ID: Peter Abel wrote: > John Fabiani wrote in message news:<9RPOc.2792$LI7.1058 at newssvr27.news.prodigy.com>... > >>thanks that worked but I don't understand why. >>cursor.execute("SELECT * FROM mytest where address = %s",string1) >>above works but - following your suggestion: >>cursor.execute("SELECT * FROM mytest where address = %s" % string1) >>above does not work. So why did >> cursor.execute("SELECT * FROM mytest where clientID = %d" % numb) >>work??????????????? >>john >>F. GEIGER wrote: >> > > >>>>numb=10 >>>>"SELECT * FROM mytest where clientID = %d",numb > > ('SELECT * FROM mytest where clientID = %d', 10) > > The result of the above is a tuple, where the first value is a string > and the second one is an int. > So you call cursor.execute (..) with a two values. The first value is > 'SELECT * FROM mytest where clientID = %d' which raises the > exception because %d is never an int. > What you wanted to do is to call cursor.execute (..) with one parameter, > which is a string. So as ohers pointed out you have to use Python's > formatting features to get the desired string: > > >>>>"SELECT * FROM mytest where clientID = %d" % numb > > 'SELECT * FROM mytest where clientID = 10' > > Even if your first example works from the point of view of SQL > it wouldn't give you the results, you want. > > >>>>string1='18 Tadlock Place' >>>>"SELECT * FROM mytest where address = %s",string1 > > ('SELECT * FROM mytest where address = %s', '18 Tadlock Place') > > That means again, your'e calling cursor.execute (..) with two parameters > where the first one - again - is 'SELECT * FROM mytest where address = %s' > So youre SQL-result should be empty, cause you surely don't have an adress > with the value %s. > > So formatting it the right way and adding single quotmarks araound string1 > will give you the result you want: > > >>>>"SELECT * FROM mytest where address = '%s'" % string1 > > "SELECT * FROM mytest where address = '18 Tadlock Place'" > > > Regards Peter > > >>>"John Fabiani" ... [snip] Peter, Your first statement, explaining why the exception is raised, is correct. Your second statement is false. Worse, misleading and possibly dangerous. In the MySQLdb driver (as I stated in my response to the original poster) the %s simply acts as a marker in the SQL string to instruct the database module to place the next parameter in that part of the statement, thus >>> cursor.execute("SELECT * FROM mytest WHERE address=%s", string1) is a different statement to >>> cursor.execute("SELECT * FROM mytest WHERE address='%s'" % string1) The first one uses database parameter passing (and will cope with *any* type of object - although it will probably only work with strings, numbers and dates) whereas the second mucks about with the string before it is passed to the database module. You should always do the first. This allows the database module to handle type conversion, character encoding and a plethora of other nasty issues which you as the application programmer really, *really* don't want to know about. In databases where parameter binding is properly supported (for instance Oracle) using the first form will also make your code more efficient (removing the parsing overhead if you must know). The point to note here is that the MySQLdb database module uses %s not for string interpolation but for parameter passing. Other database modules use ? (for instance mxODBC) and others use named or numbered parameters (e.g. :param1 or :1). Not that it's vitally important, but the first statement I showed above is more correctly written as; >>> cursor.execute("SELECT * FROM mytest WHERE address=%s", (string1,)) Because the second argument to the 'execute' method is a tuple of parameter values to be substituted in the first argument - the SQL statement. Regards, Andy -- -------------------------------------------------------------------------------- From the desk of Andrew J Todd esq - http://www.halfcooked.com/ From aahz at pythoncraft.com Tue Aug 31 18:39:22 2004 From: aahz at pythoncraft.com (Aahz) Date: 31 Aug 2004 18:39:22 -0400 Subject: Python Usage Statistics References: Message-ID: In article , Anand Pillai wrote: > > I have been contracted by an Indian publisher to author an >introductory text book on Python. As a part of the introductory >chapter, I thought it would be a good idea to present a number, a >round-about figure on the approximate *actual* usage of Python out >there in number of developers and/or installations. This is extremely difficult; for example, Paint Shop Pro now uses Python as its macro language. How PSP users have become Python programmers? No idea. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From ramen at lackingtalent.com Tue Aug 17 20:36:57 2004 From: ramen at lackingtalent.com (Dave Benjamin) Date: Wed, 18 Aug 2004 00:36:57 -0000 Subject: Flython References: Message-ID: In article , Peter Hansen wrote: > Dave Benjamin wrote: >> I have been writing >> ActionScript for two years now, and I am so sick and tired of its lack of >> useful data structures (like sets and dictionaries), god-awful >> error-checking (any bad message results in the "undefined" value, which >> accpets any message and returns the "undefined" value, and so on, until your >> error surfaces someplace completely different from where it was caused), >> lack of exceptions, lack of any standard for modularity... I could just go >> on and on. I'm currently maintaining a 10,000 line ActionScript program, and >> I would be so happy to rewrite it in Python right now. >> >> And Python *is* magic. =) > > So Dan was right on both counts. :-) ('''Either Dave thinks it just > can't be done, or he really, /really/ wants this compiler.''') I'm sure it can be done. I just don't think *I* can do it. =) At least, I have very little experience in writing compilers or anything like that... > What version of the SWF format are you stuck writing to? It > appears that even SWF 5 supports Javascript-style "dictionaries" > by using attributes on an object. For example, "ActionEnumerate" > will let you iterate over all properties on an object ala the > Python "for k in dict". Flash MX, which is SWF 6 I think. It is true that you can (ab)use objects as dictionaries, but this has several unforunate consequences: - Keys must be strings. All objects will be toString()-ed. - Keys are case-insensitive (until SWF 7, I suppose). - Adding methods to the dictionary class. (to support .keys(), .values(), etc.) requires modification of the Object prototype, and thus the use of undocumented features (ASSetPropFlags) to hide these methods from "for ... in ..." loops. - There is no exception on a bad key, since there are no exceptions (pre MX 2004, anyway), so the only way to even get an error report is to use another undocumented feature, the "__resolve" method. - Implementing dictionaries as nested arrays, to get around the case insensitivity issue and string requirement for keys, has the most awful performance I've ever seen in any language. > As for exceptions, they were added in SWF 7, so I'm guessing you're > stuck somewhere prior to that. Your life must really suck. ;-) Well, I'm getting by. But there are so many times when I think "Wow... Python really got this right". You don't realize how many ways things can go wrong when you're spoiled by the good design decisions behind a language like Python. I've had this feeling many times over. > > Peter Hansen wrote: >> Good point. I expect at least the full syntax as of Python 2.1, which means >> list comps but no "yield" or metaclasses or any fancy stuff like that. >> Perhaps one pie per Bagley's Shootout example, or maybe one pie per fully >> exposed Flash API (MovieClip, LocalConnection, etc.). I'm open to >> negotiation. > > Gosh you set a high target. Much as I like the taste of pie > (Mmmmm... piiiiie), and that cold clammy feeling as it drips down > inside my shirt, I don't think I'll be accepting the challenge any > time soon. Not, at least, until I learn a lot more about compilers > than I currently know (hint, it involves the word "sweet" and "all"). See, I shouldn't have blown my cover. I could've at least gotten a "print" statement out of you before I opened my big mouth. > One thing that would help would be a little direction from > someone in the know as to how Jython handles things that are > simply not available in Java bytecode. For example, as far > as I know the main operators for basic primitive types in Java are > implemented with different bytecode instructions, while in > CPython things like "add" are implemented as a single bytecode > which happens to special case integers for performance, but > falls back to a dynamic lookup if the types being added are > not integers. Well, in ActionScript, and I'm guessing this applies even at the bytecode level, things are very weakly typed. Numbers are transparently coerced to Strings and back, all the time. There's a single "add" instruction that is used for Numbers and Strings, performing addition, concatenation, and coercion as necessary. At least, so it seems looking at the FLASM dump of my program. > That looks to me like a bit of a conundrum. To turn the Python > code into the appropriate Java bytecodes, wouldn't you have to > know the types of the data during compilation (as in static > data types)? But Python doesn't have that (yet), so how is > it done? Are all "adds" sent to some library routine which > is made available to all applications, and that routine then > handles the Python-style dynamic add operation? I like key lime, but not banana cream. Apple and rhubarb are good, too. > In some ways, I think the SWF bytecode is even closer to Python > than Java's bytecode is, but I'm pretty sure that I couldn't > begin to imagine how one would target either of them... I'm sure it is, since it was designed with a dynamically typed language in mind. They're similar though; they're both stack-based, and they both support some notion of objects at the bytecode level. Let me know when it's ready. Thanks. ;) Dave -- .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:. "talking about music is like dancing about architecture." From anthony_barker at hotmail.com Wed Aug 18 13:22:43 2004 From: anthony_barker at hotmail.com (Anthony_Barker) Date: 18 Aug 2004 10:22:43 -0700 Subject: favorite python web development tool? References: <10i4nttktcvltdd@corp.supernews.com> Message-ID: <899f842.0408180922.38a834e9@posting.google.com> > given my background, webware+cheetah feels comfortingly familiar, and > i'm leaning toward it. before i dive in, though, i'm wondering what you > experienced users think about it, compared to the other tools that are > out there. eg, does the python environment have strengths that are > better exploited with something other than a servlet-like model? Have a look at mod_python 3.1 - I've found performance very good. I benchmarked it against a commercial oversized J2EE app server and for non complex app found it faster. It includes session handling and a basic template system. However, you can use whichever templating language you like with it. Cheetah is nice Also have a look at SQL Object and db_rows http://www.sqlobject.org/ SQL object is worth checking out -SQLObject is an object-relational mapper. It allows you to translate RDBMS table rows into Python objects, and manipulate those objects to transparently manipulate the database. It allows you to use something like >>> p = animal.new(name="Giraffe", category="mammal") to create a new animal instead of >>> db.execute(("INSERT into animals (name, category) values %s, %s), "Giraffe", "mammal") a simpler alternative - db_rows http://opensource.theopalgroup.com/ (http://xminc.com/linux/db_rows.txt) Anthony http://xminc.com/linux/ From eurleif at ecritters.biz Sat Aug 14 16:58:21 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sat, 14 Aug 2004 16:58:21 -0400 Subject: Decorators: an outsider's perspective In-Reply-To: References: <9ADC3170-EDAF-11D8-9F63-000A95B336F2@snowtide.com> Message-ID: <2o7cipF7g74nU1@uni-berlin.de> Paul Morrow wrote: > > Python was built (successfully) on the assumption that obvious > interpretations of the code obviate the need for declarations. Why > wouldn't we continue with that mindset? One of the principles of Python is also "explicit is better than implicit". Your idea, though interesting, doesn't really seem to fit in with that. From evenprimes at gmail.com Thu Aug 26 12:02:30 2004 From: evenprimes at gmail.com (Chris Cioffi) Date: Thu, 26 Aug 2004 12:02:30 -0400 Subject: object.* In-Reply-To: References: Message-ID: For most objects I would think vars(object) is what you want. The dir() built in can help with methods as well. http://www.python.org/doc/2.3.4/lib/built-in-funcs.html As an aside: the Python docs are some of the best written docs around. Read them, love them, put a copy under your pillow. Cheers! Chris On 26 Aug 2004 08:41:25 -0700, DeadWisdom wrote: > I think there should be an ability in python to write something like > "object.*" which should return a dictionary object containing all the > members and their values for the given object. Maybe ".*" could be > treated as an operator. ::shrug:: > > Perhaps the functionality already exists in some other syntax; if so > please splain. > -- > http://mail.python.org/mailman/listinfo/python-list > -- Still searching for an even prime > 2! From dave at pythonapocrypha.com Mon Aug 16 15:34:48 2004 From: dave at pythonapocrypha.com (Dave Brueck) Date: Mon, 16 Aug 2004 13:34:48 -0600 Subject: mailman mailing list program In-Reply-To: References: Message-ID: <41210C58.7000608@pythonapocrypha.com> Carol Carrot wrote: > I've never seen a more complicated, verbose pile of hogwash than the > "deliverd by mailman" mailing list program. +1 QOTW. From reinhold-birkenfeld-nospam at wolke7.net Fri Aug 20 16:16:30 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Fri, 20 Aug 2004 22:16:30 +0200 Subject: Decorator keyword options - brainstorming In-Reply-To: References: Message-ID: <2on4dcFcqjcoU1@uni-berlin.de> Michael Sparks wrote: > On Fri, 20 Aug 2004, Reinhold Birkenfeld wrote: >> David Vaughan wrote: >> > Paul McGuire wrote: >> > I don't know - it sounds fun. I vote: >> > >> > SpanishInquisition: >> > staticmethod >> > def foo(): >> > pass >> > But seriously, there must be something literally pythonic we could >> > propose. >> How about >> pythonic: >> staticmethod >> def foo(): >> pass >> > > That's never work - for IronPython you'd have to change it: > > ironic: > staticmethod > def foo(): > pass Hm, just thinking about stackless: staticmethod def foo(): pass Reinhold... -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From fumanchu at amor.org Tue Aug 24 11:26:05 2004 From: fumanchu at amor.org (Robert Brewer) Date: Tue, 24 Aug 2004 08:26:05 -0700 Subject: python-dev Summary for 2004-08-01 through 2004-08-15 Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E50@exchange.hqamor.amorhq.net> Anthony Baxter wrote: > On Mon, 23 Aug 2004 21:50:48 -0700, Brett Cannon > wrote: > > At this point people should be hashing out which syntax > alternative they > > want to present to Guido on comp.lang.python_. No more talking on > > python-dev, no more syntax proposals. The community should > set a goal > > date (Sept. 1 seems good) and just choose a bloody alternative. > > One point I mentioned to Brett, but that he forgot to update (bad > summariser! no cookie for you!) is that Sept 1 is way, way, way too > late. 2.4a3 is scheduled for September 2. I'd _hope_ that by the end > of this week we can have the proposed alternative(s) presented to > Guido - this gives him the weekend and the start of next week to make > a decision. Given the dearth of heated debate over the proposal, I expect to call for signatories within the next 24 hours or so. I know Michael Sparks is working on patching against CVS (instead of alpha 2), minor grammar improvements, and such--not sure how far along that is or if he feels it could wait for revisions after the decision is made...? Robert Brewer MIS Amor Ministries fumanchu at amor.org From nhodgson at bigpond.net.au Sun Aug 1 20:09:46 2004 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Mon, 02 Aug 2004 00:09:46 GMT Subject: glob.glob unicode bug or feature References: <9418be08.0407310712.5ee65904@posting.google.com> Message-ID: Peter Otten: > Neil Hodgson wrote: > ... > > return glob1(type(dirname)(os.curdir), basename) > ... > I should have tried before posting. Now you point it out it seems I've > changed a piece of dead code. Or am I missing something ...again? It took quite a few examples for me to be convinced that the code is dead. "leve" has submitted a bug and "nnorwitz" a patch to the Python bug tracker and it works for me: def glob1(dirname, pattern): if not dirname: dirname = os.curdir + if isinstance(pattern, unicode): dirname = unicode(dirname) http://sourceforge.net/tracker/index.php?func=detail&aid=1001604&group_id=5470&atid=305470 Neil From db3l at fitlinxx.com Thu Aug 26 13:58:15 2004 From: db3l at fitlinxx.com (David Bolen) Date: 26 Aug 2004 13:58:15 -0400 Subject: Best processor (i386) for Python performance? References: <412dfb17$0$65599$a1866201@newsreader.visi.com> Message-ID: Dave Brueck writes: > Grant Edwards wrote: (...) > I/O is the most common reason, so adding another processor to an I/O > bound program can give you a good performance boost (in our lab I've > seen easily 75% improvement over a single proc box for a program that > was very I/O bound, but I haven't measured it to see if it's closer to > 75% or to 100% improvement). I don't doubt the performance gains, but I'd argue that if you are seeing that sort of improvement, then you clearly don't have an I/O bound program at all, but a compute bound one. By definition, an I/O bound program's performance is gated by the I/O operations, and not CPU usage, so adding more CPU shouldn't really change anything. After all, if your program is "very I/O bound" it means it is waiting on I/O virtually all of the time (and thus not executing any Python code using the CPU), so where would adding CPU time gain anything? I do think it can be tricky to determine just what case an application falls into (and many oscillate between I/O and CPU bound modes), and indeed a purely CPU bound Python application (if in Python code and not a well-behaving extension module) isn't going to be helped at all. But to see benefit from additional CPUs for a Python application, I believe you're really looking for a multithreaded application that is technically compute bound - certainly on a instant to instant basis if not overall - but which performs a lot of (or at least regular) I/O operations (or as you note, other extension calls which release the GIL). The good news is that I believe many applications do fall into this category, even if from the outside they might be considered I/O bound, if only because it doesn't take too much executing Python code to process the I/O responses to create a CPU bottleneck at a given instant. (...) > But then again very few of the projects I work on end up having CPU as > the most scarce resource so the machines that do have multiple CPUs > are that way because they are running oodles of other processes as > well. This is an excellent point since even if the only advantage to the extra CPUs was to free up more of a single CPU for a Python application, you'd still see a net gain for that application when running in its real world environment. -- David From maxm at mxm.dk Thu Aug 19 06:39:39 2004 From: maxm at mxm.dk (Max M) Date: Thu, 19 Aug 2004 12:39:39 +0200 Subject: age of Python programmers In-Reply-To: <4124724C.8040001@chamonix.reportlab.co.uk> References: <4124724C.8040001@chamonix.reportlab.co.uk> Message-ID: <41248398$0$218$edfadb0f@dread12.news.tele.dk> Robin Becker wrote: > Lucas Raab wrote: > >> One thing I've always kind of wondered is what is the average age of a >> Python programmer?? What age groups use Python?? Something to think >> about.... >> > so far with a count of 74 the average is 35.72 Up that a nudge with me: 39 regards Max M From sholden at holdenweb.com Mon Aug 30 23:24:08 2004 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 30 Aug 2004 23:24:08 -0400 Subject: Need help importing/installing reportlab module In-Reply-To: <1ezngypknj8ju.dlg@news.individual.net> References: <1ezngypknj8ju.dlg@news.individual.net> Message-ID: <4133EF58.4050709@holdenweb.com> Active8 wrote: > I did this once and can't remember how so I read the > reportlab user guid. It says to unzip the reportlab archive - this > is on w2k, BTW, with Python23 - to a directory and make a file > called reportlab.pth in the pythod dir. The only line in this file > is supposed to be the path to the reportlib dir. > When you unpack the ReportLab archive (I downloaded ReportLab_1_19.zip) it creates a reportlab-1_19 directory (in my case in the C:\Steve directory), with a reportlab subdirectory that is the package you want to import. My Python is installed in C:\Python23, so I created a C:\Python23\reportlab.pth file which contained the single line C:\Steve\reportlab-1_19 Lo! "import reportlab" now works, and you should be good to go. > Then I'm instructed to open the ... ok I'll close and reopen ... the > python cmd line interpreter and type > > import reportlab > > so I get > > Import Error: no module named reportlab > > not too surprizing since I can't find anything named reportlab in > the archive. I did basically the same thing to install PIL and that > worked. I did also download rl_win32_2_3 and move those .pyd files > to the pythod dll dir - I assume a pyd is a python dll - worked for > PIL. > I'd be rather concerned that you can't find "reportlab" in the archive. Basically all it contains is a "reportlab" package directory with the code in it. > If anyone can help me straighten this out, I'd really apppreciate > it. > > TIA Well if this doesn't fix it, please let me know. regards Steve [ReportLab's US rep] From arien_malec at yahoo.com.REMOVE Mon Aug 23 16:23:13 2004 From: arien_malec at yahoo.com.REMOVE (Arien Malec) Date: Mon, 23 Aug 2004 20:23:13 GMT Subject: PEP318: radical notion References: Message-ID: Peter Hansen wrote in news:CsmdnSKL1aVt3LfcRVn-vg at powergate.ca: > Arien Malec wrote: > >> Apologies for feeding the fire, when we are rallying around a >> consensus, but I've been concerned about the clash between syntax and >> semantics, and I've finally reached a mini-epiphany: >> >> The problem with PEP318 is that it is too powerful, and tries to do >> too much. It is a sledgehammer for attacking three problems: > [snip] > > I believe your mini-epiphany has been reached by several other people > in this forum and discussed at length, certainly not in exactly the > same words but surely in a very similar form. I haven't heard too much resolution about it. The discussion I've seen has been oriented mostly around syntax, partly around "this is ugly but Guido says it goes". I haven't heard the "it's really not ugly, and here's why" part of this. Arien Arien From roy at panix.com Sun Aug 22 10:50:32 2004 From: roy at panix.com (Roy Smith) Date: Sun, 22 Aug 2004 10:50:32 -0400 Subject: J2 proposal: keyword References: Message-ID: "Robert Brewer" wrote: > Just to put collected wisdom in one spot for now, here's what's in my > draft: > > > III. Choosing a keyword > > If a keyword is to be chosen over @ or other punctuation, the question > remains, "which word should it be?" Many words have been proposed, and > although we may recommend a small number here, it is more important that > we establish guidelines for the selection of a keyword. The keyword: > > -Should not be used widely as an identifier in existing Python code. > -Should be easy to remember when writing new code. > -Should be easy to remember when reading existing code. > -Should be easy to search for, in both docs and Google. > -Should not be a word with a planned future. This rules out "with" and > "as" (I should probably footnote this). > -In this author's opinion (back me up here, people), it should not be a > form of the word "decorate". The term "decorate" conflicts with two > separate concepts: both the GoF Decorator pattern (which is a runtime > wrapper, not a compile-time one), and with our own beloved > "decorate-sort-undecorate" pattern (aka Schwartzian or Guttman-Rosler > Transform). Putting on my "Slightly Silly Party" hat, may I suggest that "pie" meets all of those constraints :-) From reader at newsguy.com Sun Aug 1 00:10:03 2004 From: reader at newsguy.com (Harry Putnam) Date: Sat, 31 Jul 2004 23:10:03 -0500 Subject: (patch for Bash) try-block and exception References: <2n27jlFsb5njU1@uni-berlin.de> <2n2bapFs3oqbU1@uni-berlin.de> Message-ID: William Park writes: >> Ref: >> http://freshmeat.net/projects/bashdiff/ >> help try >> help raise This link doesn't appear to lead to a `download' option.. From jbperez808 at wahoo.com Fri Aug 6 10:01:10 2004 From: jbperez808 at wahoo.com (Jon Perez) Date: Fri, 06 Aug 2004 22:01:10 +0800 Subject: Getting around the GIL with POSH Message-ID: <2nhgq0Fvu3qU1@uni-berlin.de> POSH, found at poshmodule.sourceforge.net , lets you share Python objects across processes like you would among threads and not have to resort to IPC mechanisms. Because separate processes do not share the GIL, this allows them to be scheduled on multiple CPUs. Is anyone out there using POSH and is it reliable enough for production use? Any plans to incorporate it into the Python distribution? From vincent at visualtrans.de Wed Aug 25 13:19:27 2004 From: vincent at visualtrans.de (vincent wehren) Date: Wed, 25 Aug 2004 19:19:27 +0200 Subject: ASPN Python cookbook in a chm In-Reply-To: References: Message-ID: dody wrote: > ASPN Python cookbook in a .chm file > =================================== > > last updated: 25 August 2004 > > http://miaw.tcom.ou.edu/~dody/aspnpython.chm > > -- > dody suria wijaya > > Very cool! -- Vincent Wehren From asif at go-away-spammer.com Wed Aug 25 10:22:41 2004 From: asif at go-away-spammer.com (Player) Date: Wed, 25 Aug 2004 15:22:41 +0100 Subject: Begginer question about py install Message-ID: During my setup install of python, I came across an option stating... Compile python files to, .pyc I left it unchecked for now, should I of done otherwise?? As I am a begginer to this, I didn't no if it was a needed option to be checked or otherwise. I assume by compiling the python files to pyc they would run that little bit faster?? M.B -- ************* The Imagination may be compared to Adam's dream- he awoke and found it truth. John Keats. ************* From siona at chiark.greenend.org.uk Fri Aug 13 08:46:25 2004 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 13 Aug 2004 13:46:25 +0100 (BST) Subject: [OT] Keyboard layout, was Re: PEP318 References: Message-ID: Michael Hudson wrote: >Huh? On *my* mac @ is shift-2 and # is option-3. Er, sorry everyone, yes, I'm talking complete bollocks. Ignore me. -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From chris.cavalaria at free.fr Sat Aug 7 18:49:28 2004 From: chris.cavalaria at free.fr (Christophe Cavalaria) Date: Sun, 08 Aug 2004 00:49:28 +0200 Subject: Importance of C# (was Re: IronPython-0.6 is now available!) References: <278de0e.0407281353.27b6a457@posting.google.com> <5dydnZSDZaARoZXcRVn-ug@powergate.ca> <1n5z28erh2m3u.dlg@baczek.net.invalid> <537ea4cd.0408070757.14790cfe@posting.google.com> Message-ID: <41155c78$0$4348$626a14ce@news.free.fr> ziller wrote: >> After reading a tutorial on c#, I see immediately that it has all the >> features that I disliked in Java. >> >> 1) Everything is derived from "Object" > > Pure OO is supposed to be an advantage. Otherwise casting hacks have > to be used and understood. With real generics you don't need casting hack. >> 3) No multiple inheritance > > This has been covered to death. MI implementation is a nightmare. > I'm sure some design pattern would map any 'needed' MI solution to an > equivalent one using interfaces and SI. We have MI in Python and it works somewhat. And I'm sure SI isn't needed anyway. There must be some design patter mapping SI in assembler or even on a turing machine. >> I'm not sure about 2 others: >> >> 4) No serious generic programming support > > It'll be there for 2.0. And the implementation is superb (much like > Eiffel's generics) They aren't out yet and people are already complaining that they are too limited. So far, despite an horrible syntax and horrible error messages the C++ templates are still much more powerful than C# generics. And the best thing is that the constraint system you can find on boost.org for C++ templates is more powerful than the one you have in Eiffel either :D From ramen at lackingtalent.com Wed Aug 18 15:20:23 2004 From: ramen at lackingtalent.com (Dave Benjamin) Date: Wed, 18 Aug 2004 19:20:23 -0000 Subject: age of Python programmers References: Message-ID: In article , Peter Hansen wrote: > Lucas Raab wrote: >> One thing I've always kind of wondered is what is the average age of a >> Python programmer?? > > My average age has been increasing steadily for years. :-( LOL =) -- .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:. "talking about music is like dancing about architecture." From arien_malec at yahoo.com.REMOVE Thu Aug 12 22:56:34 2004 From: arien_malec at yahoo.com.REMOVE (Arien Malec) Date: Fri, 13 Aug 2004 02:56:34 GMT Subject: PEP 318 decorators are not Decorators Message-ID: I've been following the decorator debate with some interest, and it's taken me a reasonably long time to understand what is meant by a decorator. One of the issues is that the Decorator pattern is more like a Unix pipe than it is what PEP 318 calls a decorator. The classic decorator is run-time, rather than define time, and is non-destructive to the base function. The PEP 318 decorator is define time and is a destructive change to the base function. For instance, the GoF book makes it clear that decorators may be added or removed without affecting the underlying class. I personally think it's confusing to reuse the "Decorator" name for something that is not a classic decorator. I also agree with the many comments that the proposed syntax does not make it clear that what is going on is a destuctive transformation of the defined function. Arien From maxm at mxm.dk Thu Aug 26 09:03:03 2004 From: maxm at mxm.dk (Max M) Date: Thu, 26 Aug 2004 15:03:03 +0200 Subject: Proposal for removing self In-Reply-To: References: Message-ID: <412ddf8d$0$275$edfadb0f@dread12.news.tele.dk> Brent W. Hughes wrote: > When doing object-oriented stuff, it bothers me to have to type "self" so > many times. I propose that Python allow the programmer to optionally type > ".variable" instead of "self.variable" to mean the same thing. Of course, > the interpreter would have to be more careful about detecting floats that > begin with just a period as in ".5". What are your thoughts? You don't have to use self. You could simply use underscore '_' instead. class Person: def setName(_, name): _.name = name def getName(_): return _.name But other Python programmers will hate you for it ;-) If it is because you are using an attribute too many times inside a method, a better solution is to map it to a local variable. It also has the advantage of being faster. class SoftwareProjectEstimator: pi = 3.14 def guestimatePrice(self, hours, hour_price, developer_group_size): pi = self.pi guess = hours * pi guess *= pi * developer_group_size return guess * hour_price regards Max M From skip at pobox.com Tue Aug 10 12:17:14 2004 From: skip at pobox.com (Skip Montanaro) Date: Tue, 10 Aug 2004 11:17:14 -0500 Subject: PEP-0318 In-Reply-To: <411421bf@nntp.zianet.com> References: <41122FC2.1080608@interlink.com.au> <4114152f@nntp.zianet.com> <411421bf@nntp.zianet.com> Message-ID: <16664.62730.686198.168622@montanaro.dyndns.org> >> Do people anticipate having lots of decorators for a given function? Mark> The way they've been talking, it would appear so. Most of the lots-of-decorator examples were probably designed to make a competing decorator proposal look bad. ;-) In reality, I think the number of functions acquiring decorators will be fairly small unless you go whole hog for something like the accepts()/returns() example in PEP 318 or do lots of Objective C interfacing as Bob Ippolito expects to do. In places where decorators will be used, I suspect their number will typically be smaller than the number of parameters to the decorated functions. A quick scan of the standard library: find . -name '*.py' \ | xargs cat \ | egrep '^ *def .*\(.*\):$' \ | sed -e 's/.*(//' -e 's/).*//' \ | python -c 'import sys for l in sys.stdin: l = l.strip() if not l: print 0 else: print len(l.split()) ' | sort -n | uniq -c suggests that most functions have three or fewer parameters: 1096 0 8072 1 4024 2 1696 3 981 4 278 5 76 6 57 7 8 8 10 9 5 10 1 11 1 13 Even if you account for functions whose parameter lists span multiple lines I doubt that distribution will change very much. My guess is that use of decorators will be even more heavily weighted toward 0, even after a number of Python releases. Skip From rnd at onego.ru Tue Aug 17 11:47:01 2004 From: rnd at onego.ru (Roman Suzi) Date: Tue, 17 Aug 2004 19:47:01 +0400 (MSD) Subject: Mind.py In-Reply-To: <41220b22@news.victoria.tc.ca> References: <41220b22@news.victoria.tc.ca> Message-ID: This is non-threaded Mind in Python. I was having fun with this module as it already was out of control at this early stage of development: os.execv(sys.argv[0], sys.argv) it appears must have all args as a second arg, and I supposed that I must exclude sys.argv[0] from it. All other modules are like this: -><----------- Security.py def Security(m): pass -><----------- But they are needed to have something non-trivial. Rejuvenations are made as complete restarting the process. This is in case Mind changed some modules by itself ;-) Or even it's main module aLife.py ;-) Have fun. -><------------------------------------------------------------------ #!/usr/bin/python # -*- mode: python -*- # $Id:$ """ aLife() (artificial life) is the Robot AI Mind main loop. """ import sys, time, os from Security import Security from Sensorium import Sensorium from Emotion import Emotion from Think import Think from Volition import Volition from Motorium import Motorium from Voice import Voice class Mind: # Tabula rasa pass rsvp = 1000 def aLife(): # ATM 27oct2002 or your ID & date. try: m = Mind() # persistence to be added in future Security(m) # For human control and operation of the AI. Sensorium(m) # Audition other human-robot input senses. Emotion(m) # Quasi-physiological influence upon thought. Think(m) # Syntax and vocabulary of natural languages. Volition(m) # Contemplative selection of motor options. Motorium(m) # Robotic activation of motor initiatives. except: sys.exit(0) rjc = int((sys.argv[1:2] or ['0'])[0]) # If the AI has not met with misadventure, fyi = "aLife: calling itself t = %s rejuvenations = %i" % (time.strftime("%Y.%m.%d %H:%H:%S"), rjc) print fyi # Display the Voice:brain "For Your Information". Voice(m) time.sleep(rsvp/1000) # End of quasi-loop time-delay of rsvp-value milliseconds. sys.argv[1] = str(rjc + 1) os.execv(sys.argv[0], sys.argv) # Call aLife again. # End of one pass through the aLife Mind that repeats itself. if __name__ == "__main__": aLife() # End of aLife.py From sbabbitt at commspeed.net Fri Aug 6 10:20:08 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Fri, 6 Aug 2004 07:20:08 -0700 Subject: Python milestone releases References: Message-ID: <1091802401.773312@news.commspeed.net> "Thomas D'Tak" wrote in message news:pan.2004.08.05.22.55.55.192128 at rumblefish.org... > Hi everybody! > > Recently, I am having more and more problems with the fact that > my Python version is far ahead of the Python versions I have to > write scripts for (CGI servers, LAN servers & clients etc. of > customers, ISPs etc.). Sometimes, these Python versions reach > back to Python 2.0. > > The question is now, how to handle this kind of problems? > > I do not want to complain here that Python is developing too > fast; and I do not want to criticize Python's system of version > numbers. But I want to ask for resp. suggest something like > *official Python milestone releases*. (Please correct me if > something like that does already exist and I am just not aware > of it.) Anythin thats not a Beta is an *official Python milestone release*, Tom From shalabh at cafepy.com Tue Aug 10 17:04:34 2004 From: shalabh at cafepy.com (Shalabh Chaturvedi) Date: Tue, 10 Aug 2004 14:04:34 -0700 Subject: remaining decorator syntax options In-Reply-To: References: Message-ID: Steven Bethard wrote: ... > *** List notation > > Assuming a pre-def, non-indented decorator, here are the remaining > list notations: > > (1) > dec1 > dec2 > dec3 > > (2) > [dec1, dec2, dec3] > > (3) > dec1, dec2, dec3 > > I believe that version 3 was vetoed because it makes it too hard to > break lists of decorators across lines. GvR's preference is > definitely for 1, but that may be influenced by his decision for the > indicator. I have a feeling that how long the indicator is directly > affects which of (1) or (2) is preferred. Compare: > > @dec1 > @dec2 > @dec3 > > vs. > > @[dec1, dec2, dec3] > > and > > using dec1 > using dec2 > using dec3 > > vs. > > using [dec1, dec2, dec3] > > It seems like with a single symbol character, the non-list syntax is > much more concise, and probably clearer. However with a keyword > syntax the list seems the better option. For short single names, yes. But also compare @staticmethod @foo.moredecoration(a="hello",b="world") @foo.bar.baz() def myfunc(): vs. using [staticmethod ,foo.moredecoration(a="hello",b="world"), foo.bar.baz()] def myfunc(): (I find the first version clearer.) In some usability testing I did myself, I found that having one decorator per line increased usability because: 1. All decorators line up at the left directly above the function name. When you look at a function it's immediately visible how it is decorated - no scanning required. 2. Moving and deleting decorators around is easy (cutting-pasting entire lines is easier than parts of lines). 3. Adding decorators is easy (you just have to locate the start of a line, not somewhere in the middle). So I would not support multiple decorators per line. Btw, I think your summary of the current state is good. However I feel a new keyword has been pretty much ruled out as well. Since there are a number of supporters of GvR's pie-decorator syntax (myself being one of them), I doubt we will see anything else unless most of us @-supporters are swayed. So I am happy, unless we end up with the flagstaff syntax: |staticmethod |foo.moredecoration(a="hello",b="world") |foo.bar.baz() def myfunc(): pass In which case I am happier :) Cheers, Shalabh From shannon at news.widomaker.com Tue Aug 31 12:03:43 2004 From: shannon at news.widomaker.com (Charles Shannon Hendrix) Date: Tue, 31 Aug 2004 12:03:43 -0400 Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4dyXc.25792$Ot3.22106@twister.nyc.rr.com> <878yc0ucyl.fsf@thalassa.informatimago.com> <87hdqorqd9.fsf@thalassa.informatimago.com> Message-ID: ["Followup-To:" header set to alt.folklore.computers.] > I'd expect to get these complaints indeed from people who drove it, > but I'd be puzzled if they'd continued to drive it every day. Um... maybe it's paid for? I use things daily that I hate... I can't afford to replace them. Maybe if the people had no *plans* to replace the Explorer, or they turned around and bought yet another one, I could see your point. -- shannon "AT" widomaker.com -- [There is a limit to how stupid people really are -- just as there's a limit to the amount of hydrogen in the Universe. There's a lot, but there's a limit. -- Dave C. Barber on a.f.c. ] From pwilkinson at videotron.ca Wed Aug 18 10:28:28 2004 From: pwilkinson at videotron.ca (Peter Wilkinson) Date: Wed, 18 Aug 2004 10:28:28 -0400 Subject: age of Python programmers In-Reply-To: References: Message-ID: <6.0.3.0.0.20040818102735.01b3c268@pop.videotron.ca> 32 here ..... but my wife is 25 ;-) my effective age is 25. Peter At 08:20 AM 8/18/2004, Lucas Raab wrote: >One thing I've always kind of wondered is what is the average age of a >Python programmer?? What age groups use Python?? Something to think >about.... > > >-- >http://mail.python.org/mailman/listinfo/python-list From h.b.furuseth at usit.uio.no Fri Aug 6 03:06:33 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 06 Aug 2004 09:06:33 +0200 Subject: Proposal: require 7-bit source str's References: <4112AC7B.1060508@v.loewis.de> Message-ID: Martin v. L?wis wrote: >Hallvard B Furuseth wrote: >> Now that the '-*- coding: -*-' feature has arrived, >> I'd like to see an addition: >> >> # -*- str7bit:True -*- >> >> After the source file has been converted to Unicode, cause a parse >> error if a non-u'' string contains a non-7bit source character. >> >> It can be used to ensure that the source file doesn't contain national >> characters that the program will treat as characters in the current >> locale's character set instead of in the source file's character set. > > I doubt this helps as much as you'd like. You will need to change every > source file with that annotation. perl -i.bak -pe ' /\bstr7bit\b/ or s/^(\s*#.*?-\*-.*?coding[=:]\s*[\w.-]+)(?=[;\s])/$1;str7bit:True/ ' `find . -name '*.py' | xargs grep -l 'coding[=:]'` > While you are at it, you could just > as well check every source file directly. True at first pass, but if Python catches it, a file will stay clean once it has been cleaned up and marked as str7bit. That's particularly useful when several people are working on the source. A fix to your objection would be to instead warn about the offending strings _unless_ the file is marked with str7bit:False, but I figure that's a bit too drastic for the time being:-) > So if anything, I think this should be a global option. -W::str7bitWarning? Come to think of it, that would also make it possible for a Python program to reject add-ons (modules, execfile etc) which contain unmarked 8-bit strings. > Or, better yet, > external checkers like pychecker could check for that. Well, I don't think that's better, but if it's rejected for Python that'll be my next stop. -- Hallvard From cjw at sympatico.ca Tue Aug 24 14:25:38 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Tue, 24 Aug 2004 14:25:38 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: Message-ID: Paul Morrow wrote: > ...that they warrant an entirely new syntax? It seems that they are > very similar in a very significant way --- they alter the default > behavior of something. IMO, it's not a stretch to say that they > 'parallel' metaclasses; that they are to functions/methods what > metaclasses are to classes. So why don't they share a similar syntax? > > class Foo: > """ This is the docstring for class Foo. """ > __metaclass__ = M > # body of class goes here > > > def baz(): > """ This is the docstring for function baz. """ > __features__ = synchronized, memoized > # body of function goes here. > > > I personally find the above baz function aesthetically appealing. Does > anyone else feel this way? For contrast, below is the same function > written in the proposed A1 and J2 [*] syntaxes (respectively). > > > @synchronized > @memoized > @doc(""" This is the docstring for function baz. """) > def baz(): > # body of function goes here. > > > decorate: > """ This is the docstring for function baz. """ > synchronized > memoized > def baz(): > # body of function goes here. > > > * if J2 is accepted, the name 'decorate' may be replaced with some other > keyword, but I believe that the structure of the syntax would stay the > same. > > Paul > Robert Brewer provided an excellent review of the options now on the table, but he didn't explore the question of whether there is an existing structure on which these new operations, which are mainly transformations, can be based. http://www.aminus.org/rbre/python/pydec.html There seems to be an artificial deadline which is motivating the push to implement something, even though the effect can already be achieved, in a less desirable way, by placing the transformer aka decorator after the function body. I like the general thrust of this proposal - let's use existing structures if this is possible. The idea of putting the modifier __features__ after the thing named and given a signature also makes sense. Colin W. From mov_21h at yahoo.com Fri Aug 20 09:06:45 2004 From: mov_21h at yahoo.com (Bigbowser) Date: Fri, 20 Aug 2004 06:06:45 -0700 (PDT) Subject: sub-shell errors Message-ID: <20040820130645.20380.qmail@web50004.mail.yahoo.com> Hi all, I'm trying to create a sub shell environment ( i haven't really got a reason, its more of a test, although hopefully it will make life easier ;P ) but whenever i try to call the commands i've created i get : [ ice being the sub-shells name ] ICE> help Traceback (most recent call last): File "./console.py", line 27, in ? for cmd, callback in cmds: ValueError: too many values to unpack the code that is supposed to parse out the commands : ( all the commands are in a seperate file called commands.py, just for ease of maintance and readability ) ---begin---- import commands userInput = str() while(1): userInput == raw_input('ICE> ') cmds = { 'help' : commands.displayHelp, 'version' : commands.displayVersion, 'authors' : commands.displayAuthors, 'exit' : commands.exitIce} for cmd, callback in cmds: if userInput == cmd: callback() -----end------ I've tried several methods of going around this error, but none seem to work, the only other way i could do it is with a big series of if and elif statments .. but i don't reall want to for maintanance reasons .. :P if i print cmds ( the array that holds the commands ) : {'version': , 'exit': , 'help': , 'authors': } Thanks Bigbowser __________________________________ Do you Yahoo!? Yahoo! Mail Address AutoComplete - You start. We finish. http://promotions.yahoo.com/new_mail From pm_mon at yahoo.com Sun Aug 29 22:32:21 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sun, 29 Aug 2004 22:32:21 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: <7xllfx5u18.fsf@ruckus.brouhaha.com> References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: <413291B5.4000601@yahoo.com> Paul Rubin wrote: > Paul Morrow writes: > >>I believe that we should think of assignments to __xxx__ attributes as >>not being part of the function's body, but instead part of its >>declaration, just as we do with its docstring. >> >> def circum(diameter): >> """This describe's foo.""" >> __author__ = 'Paul Morrow' >> __version__ = '0.1' > > > That's fundamentally a pretty good idea, but conflicts with how we > currently use __xxx__ attributes: > > def fcn(self, x, y, r): > ... > > class circle(shape): > __init__ = fcn > > should work about the same way as > > class circle(shape): > def __init__(self, x, y, r): > ... # same function as fcn above I'm not seeing the conflict. Would you please say a few more words about that? Just so that I'm clear on what I'm saying, I believe that all assignment to __xxx__ variables (including assignments to __init__) should be executed at object 'defininition time' (i.e. when an object is defined), within the context (namespace) of the object being defined. So in your example [*], the '__init__ = fcn' statement would be executed when the interpreter processes the definition of your circle class (when it executes the class statement). When it is finished, circle.__init__ would be bound to your fcn function. Paul [*] If I'm reading it right --- in my newsreader, the class statement appears inside of the def fcn, but I'm assuming that wasn't your intention. From peter at engcorp.com Fri Aug 20 12:10:53 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 20 Aug 2004 12:10:53 -0400 Subject: Decorator keyword options - brainstorming In-Reply-To: References: Message-ID: David Vaughan wrote: > The guys at python-dev won't be expecting that one :) > But seriously, there must be something literally pythonic we could > propose. I believe that would be any of the options involving a simple sequence of callables, which would be applied in order from start to finish (just as any Python programmer would expect). This was shot down for various reasons pretty early on, whether in the "list-after-def" form or the others. I think the "decorate:" option (with alternative keyword if there's a better) is the second most Pythonic shown to date... Most of the others are far too convoluted, or use such an uncommon (to Python) style of syntax, that the term "Pythonic" cannot yet be applied to them... but maybe after it's in the language the definition of the term will change. ;-) -Peter From peter at engcorp.com Mon Aug 16 09:16:59 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 09:16:59 -0400 Subject: Why does this (very simple piece of) code does not work? In-Reply-To: References: Message-ID: jblazi wrote: > import os > > L = os.listdir('.') > > for x in L: > print '!'+x+'!'+x[0] > if x != 'rename.py': > y = 'Kapustin (Hamelin): '+x > os.rename(x,y) > > I get > > Traceback (most recent call last): > File "", line 9, in ? > OSError: [Errno 22] Invalid argument You didn't specify your OS, version of Python, etc, but perhaps we can guess why it doesn't work anyway. Have you tried executing the equivalent command manually, either from the command line or from, say, Explorer (assuming you're on Windows)? Can you rename any file to contain parentheses and colons on your OS? If not, there's your answer. -Peter From jepler at unpythonic.net Sun Aug 1 22:08:34 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Sun, 1 Aug 2004 21:08:34 -0500 Subject: Need Help Differentiating Bad Commands From Incomplete Commands In-Reply-To: <12e41195.0407300454.6561aa71@posting.google.com> References: <12e41195.0407300454.6561aa71@posting.google.com> Message-ID: <20040802020834.GA22603@unpythonic.net> You may want to look at the codeop module [http://docs.python.org/lib/module-codeop.html] >>> from codeop import compile_command >>> compile_command("a = 3") # Complete code ", line 1> >>> print compile_command("for x in range(10):") # incomplete code None >>> print compile_command("fer x in ronge(10):") # syntax error Traceback (most recent call last): [...] File "", line 1 fer x in ronge(10): ^ SyntaxError: invalid syntax Note that this can detect invalid syntax ("fer" instead of "for") but not undefined names (ronge instead of range)---that will only happen when the code is executed, and range isn't found in anywhere. Jeff PS _PyParser_Grammar is an internal symbol, so whoever wrote that FAQ should be given 20 lashes with a short piece of string -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From noone at here.com Sun Aug 15 00:57:06 2004 From: noone at here.com (Calvin) Date: Sun, 15 Aug 2004 05:57:06 +0100 Subject: Python secure? Message-ID: Hi All, Could someone tell me just how secure Python is if compiled to an exe? Is it more or less secure than using some other language? Thanks From jzgoda at gazeta.usun.pl Wed Aug 18 15:44:06 2004 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Wed, 18 Aug 2004 19:44:06 +0000 (UTC) Subject: Swing/Metalworks for Python References: <41224ea4$1@news.broadpark.no> Message-ID: Aquila Deus pisze: >> > I was quite impressed by this toolkit in the latest Java SDK 1.5 >> > (not sure if it's new in this version or not). But are there any similar >> > toolkits for Python that allows switching Look & Feel and Themes >> > in the same way? >> >> qt - free for *nixes, commercially available for windows. And the best >> toolkit I've worked with. > > There is a non-commercial version (3.1) that comes with a qt book. But there's no PyQt version available for it, so for us, Python programmers, it's really non-existent. You can still grab Qt-nc 2.3.0 from some servers, though. -- Jarek Zgoda http://jpa.berlios.de/ From anthonybaxter at gmail.com Tue Aug 24 04:09:55 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Tue, 24 Aug 2004 18:09:55 +1000 Subject: python-dev Summary for 2004-08-01 through 2004-08-15 In-Reply-To: <412AC928.7000603@ocf.berkeley.edu> References: <412AC928.7000603@ocf.berkeley.edu> Message-ID: On Mon, 23 Aug 2004 21:50:48 -0700, Brett Cannon wrote: > At this point people should be hashing out which syntax alternative they > want to present to Guido on comp.lang.python_. No more talking on > python-dev, no more syntax proposals. The community should set a goal > date (Sept. 1 seems good) and just choose a bloody alternative. One point I mentioned to Brett, but that he forgot to update (bad summariser! no cookie for you!) is that Sept 1 is way, way, way too late. 2.4a3 is scheduled for September 2. I'd _hope_ that by the end of this week we can have the proposed alternative(s) presented to Guido - this gives him the weekend and the start of next week to make a decision. From wweston at att.net Sun Aug 22 11:46:59 2004 From: wweston at att.net (wes weston) Date: Sun, 22 Aug 2004 15:46:59 GMT Subject: Making different things equal In-Reply-To: References: Message-ID: M. Clift wrote: > Hi All, > > Back again... > > This code works nicely giving a list of names with no name repeated at a > space of 3 i.e. you won't get 'Bob','Bob' or 'Bob','Sue','Bob'. > > What I'd like to do is add a condition to it which says that although the > names are different 'Bob' and 'Mary' are equal and so it won't generate > 'Bob', 'Rita','Mary' > > I've tried various ways to do it, but with no joy. Any help appreciated. > > Thanks, M > > > > from random import * > > Name_Number = xrange(int(raw_input("Choose number of Names (1-20)? "))) > > state = [None,None] > > nextName = {'Bob':['Rita','Sue'],\ > 'Rita':['Mary','Sue','Bob'],\ > 'Sue':['Rita','Mary','Bob'],\ > 'Mary':['Sue','Rita']} > > Name_List = [] > > tmp = choice(('Bob','Rita','Sue','Mary)) > > for x in Name_Number: > print state > while tmp in state[0:2]: > tmp = choice(nextName[Name_List[-1]]) > print tmp, ", ", > print > print "Name ",x+1," is ", tmp > Name_List.append(tmp) > state[x%2] = tmp > > print Name_List > > > > M, The debugging prints are changed, a tick after Mary is added so it will run, and a few comments are added. 'still can't figure out what you want to do. wes from random import * Name_Number = xrange(int(raw_input("Choose number of Names (1-20)? "))) state = [None,None] nextName = {'Bob':['Rita','Sue'],\ 'Rita':['Mary','Sue','Bob'],\ 'Sue':['Rita','Mary','Bob'],\ 'Mary':['Sue','Rita']} Name_List = [] tmp = choice(('Bob','Rita','Sue','Mary')) #after Mary ' missing for x in Name_Number: print 'state',state print 'tmp1',tmp while tmp in state[0:2]: #or for x in range(2): tmp = choice(nextName[Name_List[-1]]) print 'tmp2',tmp print "Name ",x+1," is ", tmp Name_List.append(tmp) state[x%2] = tmp print 'Name_List',Name_List From natunika at gmx.de Tue Aug 17 06:15:19 2004 From: natunika at gmx.de (Silke) Date: 17 Aug 2004 03:15:19 -0700 Subject: serial and threads Message-ID: <39ba6e78.0408170215.59f5bfc0@posting.google.com> Hi all! I'm trying to write a program in python using the modules 'serialwin32' and 'thread' to create one thread that writes to a serial port and another one that reads from it at 'the same time'. My definitions are def NetworkToSerial(input): s.write(binascii.unhexlify(input)) print "SENT: %s" % input def SerialToNetwork(): result = s.read(1) print "RECEIVED:" print binascii.hexlify(result) and I call them with thread.start_new_thread(NetworkToSerial, (command,)) thread.start_new_thread(SerialToNetwork, ()) The first one seems to run fine, but for the second one I get the error message 'ClearCommError', 'the handle is invalid'. Does anyone have a clue whether maybe serialwin32 is not thread-compatible? Thanks for your help in advance! Silke From eurleif at ecritters.biz Sat Aug 21 21:31:22 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sat, 21 Aug 2004 21:31:22 -0400 Subject: Getting benifits of database transactions in an OO way? In-Reply-To: <7xk6vsklxm.fsf@ruckus.brouhaha.com> References: <2oq8pmFdd2nfU1@uni-berlin.de> <7xk6vsklxm.fsf@ruckus.brouhaha.com> Message-ID: <2oqb54Fdj12nU1@uni-berlin.de> Paul Rubin wrote: > Leif K-Brooks writes: >>Right now, the Person.save_data method also commits the current >>database transaction. But that seems to remove the benifit of having a >>database with transactions: If something dies between the call to >>fred.save_data() and barney.save_data(), Fred's $10 will end up in a >>black hole somewhere. > > > You have to use transactions for that. E.g. > > import people > this_transaction = people.begin_transaction() > fred = this_transaction.find_by_name('Fred Flintstone') > barney = this_transaction.find_by_name('Barney Rubble') > fred.money -= 10 > barney.money += 10 > this_transaction.finish_transaction() How woould begin_transaction() and finish_transaction() be implemented? They couldn't be simple wrappers for PostgreSQL transaction handling, since it's not very object-oriented (the whole connection has one transaction at a time). From fred at acme.com Mon Aug 9 19:29:01 2004 From: fred at acme.com (Fred) Date: Tue, 10 Aug 2004 01:29:01 +0200 Subject: VB-like GUI designer? References: Message-ID: On Tue, 10 Aug 2004 01:31:52 +0300, Nikos Kouremenos wrote: >this is because of the way wxWidgets. If you can't get used to it, then >you can always try PyQT (which I believe you will find more close to >your designer needs) No problem. I just didn't know most of the GUI tools for Python use cross-platform widget sets like wxWidgets, so expected to just start playing without having to learn about this additional layer. Thx Fred. From cemerick at snowtide.com Sun Aug 15 21:27:27 2004 From: cemerick at snowtide.com (Chas Emerick) Date: Sun, 15 Aug 2004 21:27:27 -0400 Subject: Decorators: an outsider's perspective In-Reply-To: <20040815155532.9C77F1E400B@bag.python.org> References: <20040815155532.9C77F1E400B@bag.python.org> Message-ID: <6F7215C0-EF23-11D8-9F63-000A95B336F2@snowtide.com> On Aug 15, 2004, at 11:55 AM, Paul Morrow wrote: >> Ouch. Sorry, the arguments going into a function shouldn't have >> **anything** to do with the nature of that function. Overloading >> their existence, lack thereof, or their names as a way of describing >> the function they are hung off of seems like a horrible way to go. >> (Not to mention the fact that, at least conceptually, it is also >> violating that action-at-a-distance guideline...) > > That reminds me of how I once thought about using indentation as a > means of denoting code blocks. How idiotic I thought that was. Now I > realize the elegance, beauty, 'genius' in that. > > Because of the conventions widely used (in Python) today, the name of > a method's first formal parameter *does* indicate the type of method. > If you use 'self' as the name of your first parameter, the majority of > us will assume that that this is an instance method. If you don't use > 'self', we will assume that it is not an instance method (unless you > use 'this', and we happen to be familiar with languages where that > stands for the instance at hand, but then that is not the recommended > practice). So you see, when you write a method, you are telling us > something about it's type (or what type it isn't). You are > overloading the semantics of the first parameter. > > Why don't we all just acknowledge that we are doing this? Why don't > we all just admit that a well written instance method uses 'self' as > its first argument. And well written static or class methods (as well > as plain ol' functions) don't use 'self'. > > If we strive for well written (clear) code, we follow these > conventions. These conventions convey meaning as to the type of > method. Therefore, explicitly stating the type of method is both > superfluous and a potential source of confusion. > > I believe that the problem many of us have with ideas like this is > that no other even semi-popular languages do this. But does that make > it wrong? Is our use of indentation wrong? I think you have the direction of causation reversed here. Python programmers don't use 'self' as the first argument to indicate an instance method, they/we (again, I worry how much cred I have as a python programmer yet :-) use 'self' *because* a method is an instance method. I know you'd like the reverse to become a standard/convention...that's a respectable position, but not a particularly practical one since a soon-to-be-standard method for defining a function's type is on its way that just happens to be generalized enough to be useful in tons of other contexts. I think the source of my gut reaction to the proposal you've advanced (aside from the conceptual action-at-a-distance violation that I already cited) is my past experience with Hungarian notation, where the name of a variable indicates its type. The comparison isn't totally clean cut because of the special peculiarities of Hn, but I think the folly that it represents is a clear warning to stay away from taking type information based on naming conventions. I won't discuss the virtues or drawbacks of whitespace-as-structure, since that's been hacked to death 1433 times already. However, I will say that python's usage of whitespace kept me away from seriously trying it for almost a year. Now, that's absolutely my fault, and isn't representative of the technical ability of python. However, if continued rapid uptake of python by new users is important, I would suggest that using the success of whitespace-as-structure in 'the market' is not the greatest reference for a proposal. - Chas Emerick From theller at python.net Tue Aug 24 04:40:12 2004 From: theller at python.net (Thomas Heller) Date: Tue, 24 Aug 2004 10:40:12 +0200 Subject: Unpythonic Python References: <8a638f47.0408240034.653a92ff@posting.google.com> Message-ID: dave at boost-consulting.com (David Abrahams) writes: > I started having some weird problems with Python recently; they're so > weird that I can't begin to explain them. All I can do is describe > the symptoms and hope someone else has a clue. So here goes: > > FreeBSD 4.2, Python 2.2.2. > > I have a nightly cron job that downloads the boost cvs tarball from > SourceForge and bunzip2s it. For about a year everything worked with > no problems. About a month ago the download started getting truncated > with no error reported. There were some problems with anonymous CVS on sourceforge, which also affected the nightly CVS tarballs. Can it have to do with this? I also had problems downloading the CVS tarball for ctypes - but it seems now repaired. http://sourceforge.net/docman/display_doc.php?docid=2352&group_id=1#1093021394 > Then bunzip2 reports corruption, of course. Maybe you don't get a bz2 file, but a HTML error message instead? Only speculating, Thomas From quadric at primenet.com Mon Aug 30 12:57:24 2004 From: quadric at primenet.com (quadric at primenet.com) Date: Mon, 30 Aug 2004 09:57:24 -0700 Subject: Live conversation between Python and an Excel spreadsheet Message-ID: <5.1.1.6.2.20040830094558.03973758@pop.primenet.com> Hi, I have an application that requires that Python initiate and mediate a live and iterative conversation between an external application (in which Python is embedded) and an external Excel spreadsheet. Python will have to pass info to the spreadsheet, spreadsheet will make calculations, Python will obtain results and pass back to application, application will evaluate results of spreadsheet calculations and create new set of data and instructions, Python will pass new data and instructions to spreadsheet, loop goes on 'n' times until convergence to solution or no solution. Python terminates conversation and returns control to application until next 'conversation'. If I had my choice (which I don't) I would re-code the spreadsheet in Python, but that is not an option in this case. Is there anyone on the list that has done this before and has an elegant solution? If so, what Python modules should I look at? Are there any good Python books out there that have examples of this? I am experienced with Python and have some knowledge of COM objects etc.... Any help would be very much appreciated. Thanks From listsub at wickedgrey.com Wed Aug 18 18:51:40 2004 From: listsub at wickedgrey.com (Eli Stevens (WG.c)) Date: Wed, 18 Aug 2004 15:51:40 -0700 Subject: age of Python programmers In-Reply-To: References: Message-ID: <4123DD7C.2050703@wickedgrey.com> Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer? 25 here, Python newbie (less than a year, I think). I'm sad that nobody else in this thread has spoken in hushed, reverent tones about my gateway drug, LogoWriter. I was 10 when my fifth grade math class went to the school computer lab and made the turtle crawl around the screen. From there, QBasic, C++, C-because-school-made-me, Java-because-work-made-me, Python-to-save-me. ;) Handy tip: if you were anything like me, _don't_ go back and try to read your old code. I had variable names like "qwer" "qwert" and "qwerty", alongside classics like "a", "b" and "c." *Shudder* Eli From http Sat Aug 21 12:11:18 2004 From: http (Paul Rubin) Date: 21 Aug 2004 09:11:18 -0700 Subject: Generators versus Coroutines References: Message-ID: <7xbrh4zd21.fsf@ruckus.brouhaha.com> Bryan Olson writes: > > Your arguments in favour of co-routines for servers all hold (IME) for > > generators as well. There is _slight_ extra obfuscation, but nowhere near > > the level of change required for event processing. > > Ah, so it seems we agree that generators result in more obfuscation > than co-routines, but in your experience the difference is slight. > My experience is much different, and I was trying to illustrate why > that is, so readers wouldn't have to rely just on my say-so. There's another issue, which is I think Michael may be talking about a more powerful type of generator than the kind built into normal Python. But I'm not sure of that. From jeremy+plusnews at jeremysanders.net Mon Aug 23 05:45:28 2004 From: jeremy+plusnews at jeremysanders.net (Jeremy Sanders) Date: Mon, 23 Aug 2004 10:45:28 +0100 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> <7x4qmv6cwo.fsf@ruckus.brouhaha.com> <7x1xhz1173.fsf@ruckus.brouhaha.com> Message-ID: On Sun, 22 Aug 2004 11:23:44 -0700, Paul Rubin wrote: > Sometimes that happens. Other times it really is too slow, and I rewrite > it in C. Other times Python is too bloated and I can't even consider > using it; for example, in anything that users need to download without a > big fuss. Most Linux distributions include python as standard, so the users only need to download your script (which will probably be smaller than the equivalent C code). Jeremy From phil at riverbankcomputing.co.uk Sun Aug 1 14:32:10 2004 From: phil at riverbankcomputing.co.uk (Phil Thompson) Date: Sun, 1 Aug 2004 19:32:10 +0100 Subject: Noob question on PyQt and Qt In-Reply-To: <5m9qg0ds0g5c0k9tbgukm965au96rud6tm@4ax.com> References: <5m9qg0ds0g5c0k9tbgukm965au96rud6tm@4ax.com> Message-ID: <200408011932.10858.phil@riverbankcomputing.co.uk> On Sunday 01 August 2004 6:42 pm, dusty wrote: > I am learning Python and Qt designer (using eric3). I'm writing an app > using QCheckList and have succeeded in loading parent and children, > with checkboxes, with data from a file. I want to programmatically > check some boxes depending on the string from the list. > > This is the code that I use to create the checkbox's: > ~~~ > d = QCheckListItem(it, lstI[g:], QCheckListItem.CheckBox) > self.childlist1.append(d) > ~~~ > The first char in each line in 'lstI' determines if the checkbox > should be checked or not. > How do I change the checkbox to 'On' (checked) in Python code when the > checkbox is created? Use the setOn() method. Phil From rnd at onego.ru Tue Aug 17 15:30:11 2004 From: rnd at onego.ru (Roman Suzi) Date: Tue, 17 Aug 2004 23:30:11 +0400 (MSD) Subject: Mind.py In-Reply-To: References: <41220b22@news.victoria.tc.ca> Message-ID: On Tue, 17 Aug 2004, Peter Hansen wrote: >Roman Suzi wrote: > >> rsvp = 1000 >> >... >> time.sleep(rsvp/1000) # End of quasi-loop time-delay of rsvp-value milliseconds. > >Latent bug... someone will decide during maintenance to >change that "rsvp" delay to, perhaps, a smaller value, >resulting in no delay at all... Thank you! Corrected. New version (refactured) is available: http://python.onego.ru/mind/__init__.py http://python.onego.ru/mind/aLife.py http://python.onego.ru/mind/Security.py ... (no index yet :-( >-Peter Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3 From chris.irish at libertydistribution.com Thu Aug 19 14:35:07 2004 From: chris.irish at libertydistribution.com (Chris Irish) Date: Thu, 19 Aug 2004 11:35:07 -0700 Subject: Berkeley XML DB queries In-Reply-To: <40F6B2CD.1000905@dan-olsen.net> References: <40F6B2CD.1000905@dan-olsen.net> Message-ID: <4124F2DB.8060004@libertydistribution.com> Dan Olsen wrote: > I have an Berkeley XML DB in my current program. I can query the > database and get the results. However, I'm not quite sure what data > type the results are saved in. I am new to Python and Berkeley XML DB. > I can use the results in a for statement but I want to know how many > elements were returned to the result. Does anyone know how to do this? > > Dan what about type(results) #to get the type and len(results) #to get the length Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From gerrit.muller at embeddedsystems.nl Fri Aug 20 04:23:16 2004 From: gerrit.muller at embeddedsystems.nl (Gerrit Muller) Date: Fri, 20 Aug 2004 10:23:16 +0200 Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: Roel Schroeven wrote: > Roel Schroeven wrote: > >> I spotted some errors in your list, added new entries, and made a >> histogram: http://roelschroeven.net/pythonages/ > Very cool. It might be good idea to add a date and time at the top, since new datapoint keep coming in? regards Gerrit P.S., a lot of people added other intersting datapoints: when they started programming and other languages used. I started around the age of 14, with HP table top machines (polish notation). Programming languages: Assemblers, Fortran, *Basic, *Pascal, C, Objective-C, C++. The most positive experiences were Sinclair QL-basic, Turbo Pascal, Objective-C and then a quantum leap towards Python. -- Gaudi systems architecting: From jmeile at hotmail.com Mon Aug 23 05:33:20 2004 From: jmeile at hotmail.com (Josef Meile) Date: Mon, 23 Aug 2004 11:33:20 +0200 Subject: 2 GB files In-Reply-To: <9418be08.0408221427.182a4d30@posting.google.com> References: <9418be08.0408221427.182a4d30@posting.google.com> Message-ID: <4129b7ca$1@pfaff2.ethz.ch> Elbert Lev wrote: > From postings to this group and other resources I understood that the > only way to make Python programs to work correctly with files lager > then 2 GB is building Python interpreter with some "magic spell" > defines. For me this is ABSOLUTELY unacceptable (Not the building, but > distributing and installing on dozens of computers in my > organisation). Then every time we switch to a new release of Python > this has to be repeated over and over! It is necessary with old python versions like 2.1.3 (The one used by zope 2.6.x). Have you tried to install a newer version of python (ie: 2.3.4)? I think you haven't. It already supports autodetection of large file support. If it fails, it means that your system doesn't support large files (ie: on old versions of glibc it wasn't included). > > I believe, that automatic 64 bit support (large files) can and should > be included in standard library (on platforms which support this > feature). It's already there. From python473 at yahoo.com Sat Aug 28 16:15:10 2004 From: python473 at yahoo.com (John Howard) Date: 28 Aug 2004 13:15:10 -0700 Subject: file access in jythonc References: <9eabe547.0408210611.d5e54f7@posting.google.com> Message-ID: <9eabe547.0408281215.4da5ff84@posting.google.com> Alan Kennedy wrote in message news:... > [John Howard] > > I have the following in a jythonc program to be executed in a html > > file. > > > > f1 = open("filename","r") > > > > I get message about filePermission read error. Program compiles and > > jar file is created. Just the html code gives message. > > > > Any ideas? > > I am presuming that when you say "executed in a html file" you mean that > this code is to be embedded in a rendered html page as displayed in a > browser, such as mozilla or ie, which means that your code is an > "applet", and thus allowed to execute only in the "applet sandbox" > inside that browser. Which significantly restricts the access rights of > the applet to access system resources such as local files, for a range > of very good security reasons, described here > > http://java.sun.com/docs/books/tutorial/applet/overview/security.html > http://java.sun.com/docs/books/tutorial/security1.2/overview/ > > You can approach the problem by > > 1. Digitally signing your applet or jar file. > http://www.jguru.com/faq/view.jsp?EID=11475 > > 2. Configuring the your browser to permit file access to local files > (potentially opening a massive security hole in your browser). > http://www.developer.com/java/ent/article.php/630621 > > HTH, Yes, you are correct. I do want to execute in html page. I need read access only for a file that is already there from another source. It's unclear to me exactly where the filepermission code goes. In the jython program? I looked at my ie parameters and saw no place to change access to files. I did a search in altavista on FilePermission and it looks like a lot of others also have questions. Can this even be done with jythonc? It seems to me that being able to do so opens up many, many possibilities for useful code! From jerf at jerf.org Sat Aug 28 16:32:21 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Sat, 28 Aug 2004 20:32:21 GMT Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> Message-ID: On Sat, 28 Aug 2004 02:07:43 +0000, Paul McGuire wrote: > And be sure that the Python community > does not need to be educated about what "real world" code looks like. For evidence, see the recent thread on "average Python programmer age". While the newsgroup may not be represenatative, I am surprised to be as much of a yung'un as I am at 25. From Andreas.Ames at tenovis.com Fri Aug 20 09:09:41 2004 From: Andreas.Ames at tenovis.com (Ames Andreas (MPA/DF)) Date: Fri, 20 Aug 2004 15:09:41 +0200 Subject: My only complaint about Python Message-ID: <788E231C269961418F38D3E360D1652526CA2D@tndefr-ws00021.tenovis.corp.lan> Hi, Darren Dale wrote: > I love the language. I love the community. My only complaint is that > Python for Windows is built with Visual Studio. You could look at http://www.python.org/sf/841454. It certainly needs work though ... cheers, andreas From ville at spammers.com Tue Aug 31 11:56:18 2004 From: ville at spammers.com (Ville Vainio) Date: 31 Aug 2004 18:56:18 +0300 Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4PGdnfsOfdDPi63cRVn-tA@speakeasy.net> <41337FC9.8070902@hotmail.com> <%T%Yc.29567$Es2.11957889@news4.srv.hcvlny.cv.net> Message-ID: >>>>> "John" == John W Kennedy writes: John> Yes, and also a single-process pipe emulator. Ever since John> 2.0, MS has been trying to turn MS-DOS (later, Windows) into John> a Unix clone. With very little success. Notepad still only understands cr-lf line breaks, and / as path separator still screws up most of their cmd line programs (which think / is for command line options). Microsoft probably thought avoiding compatibility is a good idea, and have only lately started to have some regrets, visible as the release & future integration of SFU. Migrating ppl from Unix probably *is* easier when you are not doing your best to make interoperability as painful as possible. -- Ville Vainio http://tinyurl.com/2prnb From anthonybaxter at gmail.com Fri Aug 27 13:09:09 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 28 Aug 2004 03:09:09 +1000 Subject: Class Friends In-Reply-To: References: <20040827081556.657c3fac.a@c.d> Message-ID: On Fri, 27 Aug 2004 16:55:28 GMT, Jeremy Bowers wrote: > (Some people would use "self.__x", to get the psuedo-private name munging > invoked. My call is if the "security" isn't perfect there isn't much > point, as the language is already depending on the client programmer to > behave. I think Java can get good security but C++ is already effectively > as permissive as Python, it just makes the hoops harder.) Really, the double-under mangling is more about stopping a subclass from stomping on some internal detail of the base class. In general, though, I've found it to be a complete pain in the arse - there's been too many times where I've been using an external library and wanted to hook into the base class to fix something, and had to use the mangled name. I've considered a jihad to try and get uses of the double-under mangling removed from the standard library. Maybe once 2.4 is out I'll take this on. From AntiVir at yalta.us Mon Aug 16 05:21:41 2004 From: AntiVir at yalta.us (AntiVir at yalta.us) Date: Mon, 16 Aug 2004 12:21:41 +0300 Subject: AntiVir ALERT [mail from: "Returned mail" ] Message-ID: <200408160921.i7G9Lf7i030603@yalta.us> * * * * * * * * * * * * * * * AntiVir ALERT * * * * * * * * * * * * * * * ????????? ????????? ????? ? ??????????????, ??????? ????????? ????? ??????! ???????????: "Returned mail" ???????? ??????: Worm/Mydoom.m ????? ?? ???? ?????????? ??????????. ? ?????????; ???????? ???????? ???.: +38(0654)271828 ????.: +38(0654)231094 web: www.yaltainfo.com email: support at yalta.us Mail-Info: --8<-- From: "Returned mail" To: python-list at python.org Date: Mon, 16 Aug 2004 09:19:57 +0300 Subject: Returned mail: Data format error --8<-- This version of AntiVir is licensed for private and non-commercial use. -- AntiVir for UNIX Copyright (C) 1994-2003 by H+BEDV Datentechnik GmbH. All rights reserved. For more information see http://www.antivir.de/ or http://www.hbedv.com/ From sbabbitt at commspeed.net Tue Aug 3 15:19:34 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Tue, 3 Aug 2004 12:19:34 -0700 Subject: dislin interfaced with tkinter References: <34c9b4fa.0408030743.594417f9@posting.google.com> Message-ID: <1091561149.927180@news.commspeed.net> "eesun" wrote in message news:34c9b4fa.0408030743.594417f9 at posting.google.com... > Hi, > > I've downloaded the dislin package for the scientific plotting. And I > have already created the application window with Tkinter (menu, > canvas, status bar..). I want to integrate the Dislin plotting into > the Tkinter application. For ex: show the dislin result on the Tkinter > Canvas. Anyone can help? > > thx I haven't worked with Dislin/Tkinter but I have worked with Dislin/wxPython and what you can do is dump the Dislin output into a string buffer. A shade plot, def dis_img(self,zmat,m, n, zlo, zhi): char = '' max_bytes = 0 xray = range (n) yray = range (m) dislin.metafl ('VIRT') dislin.setpag ('da4l') #dislin.setfil (self.globdir) dislin.disini () dislin.pagera () dislin.hwfont () dislin.ax3len (1400, 1400,1400) dislin.autres(n, m) dislin.shdmod ('poly', 'contur') dislin.graf3 (0, n, 0, n/5, 0, m, 0, m/5, zlo, zhi, zlo, (zhi-zlo)/5) dislin.crvmat (zmat, n, m, 1, 1) dislin.title () char_buff = dislin.rbfpng(max_bytes) max_bytes = int(char_buff[1]) char_buff = dislin.rbfpng(max_bytes) char = char_buff[0] #char now contains a PNG image of the output. I use Python Imaging Library #and open like this self.Imagetest = Image.open(StringIO.StringIO(char)) dislin.disfin () Tom From ptmcg at austin.rr._bogus_.com Mon Aug 23 18:06:32 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 23 Aug 2004 22:06:32 GMT Subject: J2 proposal: keyword References: Message-ID: "Roy Smith" wrote in message news:roy-266C0E.10503222082004 at reader1.panix.com... > "Robert Brewer" wrote: > > > Just to put collected wisdom in one spot for now, here's what's in my > > draft: > > > > > > III. Choosing a keyword > > > > If a keyword is to be chosen over @ or other punctuation, the question > > remains, "which word should it be?" Many words have been proposed, and > > although we may recommend a small number here, it is more important that > > we establish guidelines for the selection of a keyword. The keyword: > > > > -Should not be used widely as an identifier in existing Python code. > > -Should be easy to remember when writing new code. > > -Should be easy to remember when reading existing code. > > -Should be easy to search for, in both docs and Google. > > -Should not be a word with a planned future. This rules out "with" and > > "as" (I should probably footnote this). > > -In this author's opinion (back me up here, people), it should not be a > > form of the word "decorate". The term "decorate" conflicts with two > > separate concepts: both the GoF Decorator pattern (which is a runtime > > wrapper, not a compile-time one), and with our own beloved > > "decorate-sort-undecorate" pattern (aka Schwartzian or Guttman-Rosler > > Transform). > > Putting on my "Slightly Silly Party" hat, may I suggest that "pie" meets > all of those constraints :-) ... with the exception of the assumed constraint that the keyword will be a *word*, and not some malodorous punctuation mark resembling a SNOTTY-FACED HEAP OF PARROT DROPPINGS!!! Oh, sorry, that was abuse... -- Paul From dw at botanicus.net Mon Aug 30 15:11:51 2004 From: dw at botanicus.net (David Wilson) Date: Mon, 30 Aug 2004 20:11:51 +0100 Subject: [IronPython] Jim Hugunin's web log. Message-ID: <41337BF7.6000804@botanicus.net> For anyone who is excited about IronPython and it's consequences, you might find Jim Hugunin's web log to be of particular interest. I didn't see an announcement for this anywhere so here it is: http://blogs.msdn.com/hugunin/ http://blogs.msdn.com/hugunin/Rss.aspx Anti-trust conspiracy theories aside, if Microsoft adopts Python as a part of it's development toolset, the repercussions for Windows RAD and scripting are massive, not to mention the effects it would have on the average Python developer's wages and availability of work. It would also greatly ease the need to advocate Python in places of employment, as a Microsoft adopted product, it couldn't be wrong(tm). This is perhaps the first time where I have been glad to see Microsoft hijack something. Even if IronPython becomes a commercial offering, I'm still sold. Other random thoughts: my experiences of the Python community versus, eg., the perl community make me believe that Pythonistas are generally more accepting of commercial solutions than their open source weenie perl counterparts (*duck*). I'm still unsure as to whether or not this should be considered a Microsoft marketing strategy for making in-roads into the "open source scripting market". My apologies for the poor terminology, this really isn't my department. Just got a feeling. :) David. From anthonybaxter at gmail.com Fri Aug 27 11:38:27 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 28 Aug 2004 01:38:27 +1000 Subject: Call for signatories for J2 In-Reply-To: References: Message-ID: Note that Robert has sent the completed proposal to python-dev, and in fine Python tradition, buggered off for the weekend. So I'm not entirely sure it's worthwhile posting more for/against messages now. From tjreedy at udel.edu Tue Aug 10 16:13:20 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 Aug 2004 16:13:20 -0400 Subject: tool to check whether formal and actual parameters have similarnames References: Message-ID: "Amir Michail" wrote in message news:cfa3hb$387 at odak26.prod.google.com... > def plot(x,y): ... > > plot( x1, y1 ) # ok > > plot( y1, x1 ) # not ok, Reversing args reflects plot about 45 degree line, which is a quite legitimate thing to do if that is what you want to do. Perhaps original coder got plot 'backwards' and editor want to reverse it without changes name throughout code. > but this is ok: plot (x=y1, y=x1) If *you* want to force yourself to jump thru hoops like this, go ahead, but don't expect anyone else to follow ;-) > Does this make any sense, even in a heuristic sense? Not really. I name things like age, weight, height, cholesteral_level with their proper names or abbreviations thereof. Your idea strikes me as an interesting brainstorm that on second thought would best be left behind. Terry J. Reedy From pm_mon at yahoo.com Sun Aug 29 13:30:49 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sun, 29 Aug 2004 13:30:49 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Anthony Baxter wrote: > On Sun, 29 Aug 2004 12:10:13 -0400, Paul Morrow wrote: > >>For example, in the following function def, the comments specify (what I >>believe is) the author's intention behind each assignment. >> >> def circu(diameter): >> """Info about circu.""" # defines circu.__doc__ >> __author__ = 'Paul Morrow' # defines circu.__author__ >> __features__ = memoized # defines circu.__features__ >> pi = 3.14 # local variable definition >> return pi * diameter > > > Not in any Python I know of. I look at that and I think "oo, local variables". > > That you have a different belief doesn't make it right - I remain > _extremely_ unconvinced. > > Anthony My belief doesn't make it right, that's true. But I think that a preponderance of supporting evidence does. Have you seen a significant number of cases where a function uses __xxx__ attributes as local variables? Have you seen any? Can you craft a function definition that uses __xxx__ attributes as local variables, where the majority of experienced Pythonistas would agree that the double underscores are warranted? Paul From connellybarnes at yahoo.com Wed Aug 4 21:42:48 2004 From: connellybarnes at yahoo.com (C. Barnes) Date: Wed, 4 Aug 2004 18:42:48 -0700 (PDT) Subject: Decorator syntax Message-ID: <20040805014249.45692.qmail@web14526.mail.yahoo.com> I vote for def f(): [synchronized, classmethod] (body of function) This is backwards compatible (Python <= 2.3 raise SyntaxError), and looks much nicer than @. The only problem is that you can't one-line a decorated function. You can't do that with the @ notation either, so it's not a big deal. - Connelly __________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - 100MB free storage! http://promotions.yahoo.com/new_mail From coward.anonymous at gmail.com Thu Aug 26 12:27:33 2004 From: coward.anonymous at gmail.com (AC) Date: Thu, 26 Aug 2004 09:27:33 -0700 Subject: PEP 322 - alternate method names Message-ID: <358cc8180408260927997c18d@mail.gmail.com> >From the PEP 322 page: "This PEP has been conditionally accepted for Py2.4. The condition means that if the function is found to be useless, it can be removed before Py2.4b1" Is there still hope at least for an alternative method name that is not past tense? flip, transpose, invert, swap... Introducing past tense method names seems to stray a bit with the beauty/elegance of the language. Maybe it's just inevitable that the more Python grows, the less clear the signal/noise ratio becomes as both significant but sometimes marginally advantagous features are added. From b.niemann at betternet.de Mon Aug 16 06:52:18 2004 From: b.niemann at betternet.de (Benjamin Niemann) Date: Mon, 16 Aug 2004 12:52:18 +0200 Subject: sys.stdin.read() replacement In-Reply-To: References: Message-ID: Karin Lagesen wrote: > I am writing a small write-logfile script for use on the terminal. I have here > a section where the user should be able to type in several lines. I have solved > it so far by using sys.stdin.read(), which makes it possible to type in several > lines (separated by enter) and then terminate the session by typing ^D. This is > all very good. However, with this it is only possible to edit the line you are > in. If you spot an error further up in your text, you cannot get at it. Do any > of you know of a way I can do this? The UNIX-ish way to do this, is invoking the user's prefered editor (as defined by the VISUAL or EDITOR environment variables) on a temporary file and read this file when the editor terminates. From urbushey at sas.upenn.edu Tue Aug 10 17:41:50 2004 From: urbushey at sas.upenn.edu (uri bushey) Date: Tue, 10 Aug 2004 15:41:50 -0600 Subject: Printing in Python Message-ID: So I have a tkinter based little program in Python that has a canvas loaded with a WaveSurfer (http://www.speech.kth.se/wavesurfer/) widget. I am trying to print the contents of the WaveSurfer canvas. Is there an easy way to do this in Python? Also, I can pretty easily use the WaveSurfer "print" function in my program, but taht only prints to a PostScript printer or prints out a PostScript file. I would like to automate the process of printing the PostScript file in a manner that is not terribly unwieldy and as transparent to the user as possible. Is this possible? Thanks! From peter at engcorp.com Mon Aug 16 14:30:07 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 14:30:07 -0400 Subject: Newbie 1st program In-Reply-To: References: Message-ID: JDevine wrote: > Hey. I just finished my first python program. In fact it is my first > program program at all. I went from zero knowledge to the current > state in about 6 weeks. Check it out at > http://gobblewin.sourceforge.net I need help for the next stage of > development, I am also sure I could use a lot of advice on structure > etc. My #1 priority is adding a threaded status bar to track > downloads to this program. if you think you can help out let me know. More people would take the time to visit that link if you took the time to describe something, *anything*, about what the program actually does and why we should bother looking. (Congratulations, though. After six weeks of programming I'm quite sure I wasn't capable of writing anything that would have been worth posting to Sourceforge, had it existed at the time.) -Peter From in.aqua.scribis at nl.invalid Mon Aug 30 17:41:52 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Mon, 30 Aug 2004 23:41:52 +0200 Subject: "Content-Length" header In-Reply-To: <41339d7a$0$8090$a1866201@newsreader.visi.com> References: <41339d7a$0$8090$a1866201@newsreader.visi.com> Message-ID: Grant Edwards schreef: > I'll tell you _one_more_time_: use Ethereal. Here's the > transaction for your first URL: > > GET /~harnad/temp/ariadne-rae.doc HTTP/1.0 > Host: www.ecs.soton.ac.uk > User-agent: Python-urllib/1.15 > > HTTP/1.1 404 Not Found > Date: Mon, 30 Aug 2004 21:27:42 GMT > Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12 > OpenSSL/0.9.6b DAV/1.0.3 PHP/4.3.2 mod_perl/1.26 > Connection: close > Content-Type: text/html; charset=iso-8859-1 > > > > 404 Not Found > >

    Not Found

    > The requested URL /~harnad/temp/ariadne-rae.doc was not found > on this server.

    >


    >
    Apache/1.3.27 Server at www.ecs.soton.ac.uk Port > 80
    > > > THERE IS NO CONTENT-LENGTH HEADER. What do you expect urllib > to do? That is because you made a typo. Use the correct url, and you do get content-length. WTH is Ethereal? -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From fakeaddress at nowhere.org Sat Aug 21 04:38:33 2004 From: fakeaddress at nowhere.org (Bryan Olson) Date: Sat, 21 Aug 2004 08:38:33 GMT Subject: Generators versus Coroutines In-Reply-To: References: Message-ID: Michael Sparks wrote: > Bryan Olson wrote: > ... >>Have you been badly bitten by an evil co-routine? > > You appear to misunderstand what I was saying. That could be. > I was not saying > co-routines are bad. I was saying that generators are, in my experience, > almost as effective. You responded to my note that Python's generators "have a shadow of the power of co-routines, by saying, "I've found their simplicity useful for limiting the complexity of the architecture." I assumed you were saying that limiting complexity was an advantage of Python's generators. Perhaps I had mis-read your meaning. My assumption there was re-enforced by your next sentence: "After all if any piece of software is use for any length of time maintainability comes before elegance." My "Have you been badly bitten" crack was based on my reading of your response, where I thought you disagreed my implication that co-routines support simpler code structures and thus make programs more maintainable. > This isn't attacking anything. It's saying that > generators really aren't as bad as it appears some people make out. > > As for network servers, it looks like the network server system based on > using generators to gain most of the benefits of co-routines I briefly > talked about (in one of the lightning talks) at EuroPython has been > blocked for release as open source :-( > > Your arguments in favour of co-routines for servers all hold (IME) for > generators as well. There is _slight_ extra obfuscation, but nowhere near > the level of change required for event processing. Ah, so it seems we agree that generators result in more obfuscation than co-routines, but in your experience the difference is slight. My experience is much different, and I was trying to illustrate why that is, so readers wouldn't have to rely just on my say-so. > NB. The reason I like generators is because they allow me to do > co-routine-type things in python with no addons. In this thread, Bernhard Mulder showed how to do "co-routine- type things" with Python generators, and to me the result looked much worse than with real co-routines. Do you have a much simpler general method? I do like the idea of "no addons", and that's why I'd like to see co-routines in Python. I'd like continuations even more, but the Python authorities seem to value easy C-integration too highly to allow that. -- --Bryan From fumanchu at amor.org Tue Aug 24 19:11:17 2004 From: fumanchu at amor.org (Robert Brewer) Date: Tue, 24 Aug 2004 16:11:17 -0700 Subject: Decorators: J2 and a relation to @ Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E5E@exchange.hqamor.amorhq.net> Shane Holloway wrote: > From the example in Section II, part 3 of > http://www.aminus.org/rbre/python/pydec.html consider the following > decorated function. > > @using([ > funcattrs(author="Guido van Rossum"), > memorize, > synchronize, > classmethod, > ]) > def foo(cls, *args): > pass > > > This looks an lot like the suite method proposed in J2 in the current > syntax of Python 2.4a2. All that would need to be added is a "using" > decorator method. I like the @ because it makes me take note > that the > following is special in terms of code execution.[*] > > What do you think? I think you've come to the same conclusion I did in the Conclusion of the J2 proposal: everyone agrees that decorators need to be distinct. It's up to Guido to decide "how distinct"...@ is more distinct and "using" less so. That's the big difference. Robert Brewer MIS Amor Ministries fumanchu at amor.org From insert at spam.here Thu Aug 12 19:22:53 2004 From: insert at spam.here (Doug Holton) Date: Thu, 12 Aug 2004 18:22:53 -0500 Subject: decorator syntax polling suggestion In-Reply-To: References: Message-ID: Steven Bethard wrote: > The poll, as stated, asked voters to vote for the syntax suggestion > they liked the /most/. Some of the conclusions people are trying to > draw from it are what syntaxes people liked the /least/. This is > probably not the right conclusion to be drawing from the poll that was > given. What the poll found is that when given a choice between the current decorator syntax and two specific alternatives, people overwhelmingly choose the two alternatives. So there are at least two specific alternative syntaxes out there (and of course probably more) that most people would prefer over the current one. So it is reasonable to conclude that most people do not think the current decorator syntax is the best option. Although that might seem obvious to some, that conclusion alone had not yet been clear based on mailing list traffic. So if Guido does want to pay attention to the opinions of Python users (and he doesn't have to), then changing the current syntax probably wouldn't be an unpopular decision. The question though, is what specific alternative syntax should it be? There are at least two other popular syntaxes and very likely many more, but Guido asked for help in narrowing them down to one or two or three specific proposals so he could decide. At the same time though, Guido has rejected all alternative syntaxes that have been presented, so the decorators will likely stay as is. In the long long long term, decorators will be less important anyway, if we get features like optional static typing that Guido has expressed support for (no need for accepts and requires decorators), anonymous code blocks, etc. From P at draigBrady.com Wed Aug 18 11:24:41 2004 From: P at draigBrady.com (P at draigBrady.com) Date: Wed, 18 Aug 2004 16:24:41 +0100 Subject: age of Python programmers In-Reply-To: References: Message-ID: <_wKUc.25195$Z14.7850@news.indigo.ie> Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... 30 -- P?draig Brady - http://www.pixelbeat.org -- From eurleif at ecritters.biz Sun Aug 22 23:43:25 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sun, 22 Aug 2004 23:43:25 -0400 Subject: Logical lines of code counter In-Reply-To: References: <2ot090Fe5442U1@uni-berlin.de> Message-ID: <2ot78fFe1mneU1@uni-berlin.de> Tim Leslie wrote: > On Sun, 22 Aug 2004 21:44:17 -0400, Leif K-Brooks wrote: > >>I got bored with working on larger projects and wrote a little >>script/module for counting logical (not physical) lines of Python code >>in a file or directory. > If you want something which can do this and so much more, have a look at pylint. > > http://www.logilab.org/projects/pylint Neat-looking tool, but not really usable for me. It counts physical lines, not logical lines; it doesn't seem to have an option to recursively scan all sub-directories and files in a directory; and it refuses to process a file if some of the modules code wants to import aren't importable, which is the case with mod_python code. From ramen at lackingtalent.com Tue Aug 17 18:44:52 2004 From: ramen at lackingtalent.com (Dave Benjamin) Date: Tue, 17 Aug 2004 22:44:52 -0000 Subject: Flython References: Message-ID: In article , Peter Hansen wrote: > Dave Benjamin wrote: > >> I just want to say, for the record, that if anyone can successfully build a >> Python compiler that can produce Flash bytecode, I will personally allow >> you to throw *any number of pies* in my face, in as public of a ceremony as >> you desire. Furthermore, I will match you 50/50 in the cost of the pies. > > Why on earth (unless it's the liking pies thing or the really wanting > this to be done thing) would you say that? Flash bytecode is pretty > straightforward, and Python's not magic. Because getting a pie (or twelve) in the face is a lot less work than actually writing a parser and code generator. I have been writing ActionScript for two years now, and I am so sick and tired of its lack of useful data structures (like sets and dictionaries), god-awful error-checking (any bad message results in the "undefined" value, which accpets any message and returns the "undefined" value, and so on, until your error surfaces someplace completely different from where it was caused), lack of exceptions, lack of any standard for modularity... I could just go on and on. I'm currently maintaining a 10,000 line ActionScript program, and I would be so happy to rewrite it in Python right now. And Python *is* magic. =) > In any case, if this is a serious challenge, you'd better start > identifying the constraints and minimum requirements, as I'm > rather positive that it's possible to encode at least *one* > Python statement (print) into Flash bytecode which would > execute properly... shall I demonstrate for, say, one pie? Good point. I expect at least the full syntax as of Python 2.1, which means list comps but no "yield" or metaclasses or any fancy stuff like that. Perhaps one pie per Bagley's Shootout example, or maybe one pie per fully exposed Flash API (MovieClip, LocalConnection, etc.). I'm open to negotiation. But the irony here is that the amount of work that would go into a Python port to SWF would be far greater than the amount of suffering I would endure from a bunch of pies in the face. It's really on my side, because you do all the work, and then I don't have to write ActionScript anymore. =) Best wishes, Dave -- .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:. "talking about music is like dancing about architecture." From ajsiegel at optonline.com Fri Aug 13 08:18:30 2004 From: ajsiegel at optonline.com (Arthur) Date: Fri, 13 Aug 2004 12:18:30 GMT Subject: PEP318 References: <0I2D001ZDU03UQ@mta9.srv.hcvlny.cv.net> Message-ID: <1gbph0lb8cdv2erob2mog5kffpcohgnv1s@4ax.com> On Fri, 13 Aug 2004 13:30:57 +0200, Ronald Oussoren wrote: > >Decorators would make live a lot easier for us, but not having >decorators won't kill PyObjC. > >I would like to have decorators, but not at every cost. The >@decorator-before-def proposal looks sane. Thanks for the clarification of your position. I *was* uncomfortable guessing at it. I try to look at it - that it will make life easier for certain important projects, and actually cost folks like me nothing. And the actual style of programming it promotes (not declarative per se, but passing around and returning functions) will probably give me (and others of similar profile) more exposure to concepts that are good to have one's mind around. And I am free to use the concepts, without the syntax - forego the sugar. But I can't seem to sustain that perspective. I think I've used this before - but I do hate to think of myself as one of the folks booing in the audience at Newport when Dylan plugged in his electric guitar for the first time. Perhaps I am. But it's not like I don't see the up side - I don't think. The fact is that I do - I think - and still wish it wasn't going down. Art > >Ronald From aisaac at american.edu Sat Aug 14 20:54:27 2004 From: aisaac at american.edu (Alan G Isaac) Date: Sat, 14 Aug 2004 20:54:27 -0400 Subject: ironic doctest bug? References: <10hq7lsguiqfj93@corp.supernews.com> Message-ID: <10htcuj6374u5d@corp.supernews.com> "Alan G Isaac" wrote in message news:10hq7lsguiqfj93 at corp.supernews.com... > 1 items had failures: > 1 of 14 in doctest.Tester.rundict > 71 tests in 47 items. > 70 passed and 1 failed. > ***Test Failed*** 1 failures. This was the punchline of course. Am I overlooking something? Thanks, Alan Isaac From listserver at tdw.net Wed Aug 11 09:08:14 2004 From: listserver at tdw.net (Tim Williams) Date: Wed, 11 Aug 2004 14:08:14 +0100 Subject: doing successive prints without space in between References: <200408110901.i7B911cE012665@mailhub.wolfram.com> <001401c47f88$17cf5500$ccbefea9@twilliams> Message-ID: <007301c47fa4$43224520$ccbefea9@twilliams> On Fri, 2 Jul 2004 20:59:39 GMT, Harry George wrote: > Jon Perez writes: > > > I'd like to print a series of successive periods as a > > progress status in a command line script using python. > > Unforutnately, if I do a series of successive > > > > print ".", > > > > I get a space in between. Is there any way to avoid > > this? > > This show up regularly and might be a FAQ. The print is trying to > help you out. If you want total control, go to the lower levels: > > wr=sys.stdout #redirect as desired > > def myprint(txt): > wr.write(txt) #raw print > wr.flush() #flush the dots as they occur > > for i in range(100): > do_something() > myprint('.') > > myprint('\n') Apologies for posting roughly the same solution in two posts :-) for i in range(100): do_something() print '\b.', :-) From ramen at lackingtalent.com Fri Aug 6 12:15:01 2004 From: ramen at lackingtalent.com (Dave Benjamin) Date: Fri, 06 Aug 2004 16:15:01 -0000 Subject: checking whether a var is empty or not References: Message-ID: In article , Pierre-Fr?d?ric Caillaud wrote: > >> No, in PHP, you can find out if a variable exists using isset(). And >> trying >> to dereference an uninitialized variable will generate a warning if you >> have >> error reporting turned up all the way (error_reporting(E_ALL)). > > WRONG !!!!! > Example in this stupid language : > > > echo "

    one : "; > var_dump(isset( $a )); > > $a = 1; > echo "

    two : "; > var_dump(isset( $a )); > > $a = null; > echo "

    three : "; > var_dump(isset( $a )); > > ?> > > Output : > > one : bool(false) > two : bool(true) > three : bool(false) > > Get it ? I stand corrected. That is rather stupid. Well, I try to use nulls sparingly and always initialize my variables, which may explain why in the five or so years I've been using PHP, I've never run into this problem. Likewise, I don't think I've ever had to use the corresponding idiom in Python: try: a except NameError: # ... At the very least, I'll be testing for a's existence in some namespace, so I'll be looking for an AttributeError. -- .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:. "When the country is confused and in chaos, information scientists appear." Librarian's Lao Tzu: http://www.geocities.com/onelibrarian.geo/lao_tzu.html From dietz at dls.net Fri Aug 27 08:30:53 2004 From: dietz at dls.net (Paul F. Dietz) Date: Fri, 27 Aug 2004 07:30:53 -0500 Subject: Larry Wall & Cults In-Reply-To: References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: Rich Teer wrote: > On Fri, 27 Aug 2004, Reynir Stef?nsson wrote: > > >>And then there's this crazy little thing called love... > > > Nah - that was Queen! When I was seventeen I drank some very good beer. I drank some very good beer I purchased with a fake ID. My name was Brian McGee. I stayed up listening to Queen. When I was seventeen. Paul (channeling Homer) From justin__devine at hotmail.com Thu Aug 19 10:47:08 2004 From: justin__devine at hotmail.com (justin__devine at hotmail.com) Date: 19 Aug 2004 07:47:08 -0700 Subject: refreshing a wxWidget Message-ID: I have a quick question here is my widget it is a Radiobox. rb = wx.RadioBox( self, -1, "Quick Sites", (10, 215), (425, 70), labellist, 5, wx.RA_SPECIFY_COLS ) self.rb = rb later on in the program I change labellist the question is I can't get the radiobox to refresh and display with the new values I have tried .Refresh() I have tried .Create() I have tried refreshing the panel in which i have created the radiobox. All no go... so does someone know the answer to this problem? Thanks alot An earlier version of the full code (without this feature) can be found at http://gobblewin.sourceforge.net or http://www.sourceforge.net/projects/gobblewin/ Thanks again. From duncan.booth at invalid.invalid Thu Aug 19 07:50:43 2004 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 19 Aug 2004 11:50:43 GMT Subject: Decorators: an outsider's perspective References: <20040814153534.8AC171E4007@bag.python.org> Message-ID: Anthony Baxter wrote in news:mailman.1946.1092911824.5135.python-list at python.org: > On 17 Aug 2004 16:25:51 -0400, Aahz wrote: >> No, no, no, Americans get humor just fine -- what they don't get is >> irony. > > That'd be "something like iron"? I remember one newsgroup deciding that all posts which included irony should be indicated with an appropriate emoticon, namely (Fe) From lbates at swamisoft.com Mon Aug 30 20:24:19 2004 From: lbates at swamisoft.com (Larry Bates) Date: Mon, 30 Aug 2004 19:24:19 -0500 Subject: console window not disappearing with py2exe References: <173c23bb.0408301410.49b27fe4@posting.google.com> Message-ID: Put -windows option on compile line: python setup.py py2exe --windows HTH, Larry Bates Syscon, Inc. "Matthew K Jensen" wrote in message news:173c23bb.0408301410.49b27fe4 at posting.google.com... > In another one of my silly apps, I'm using 'windows=' in the setup > script. I can't get the darn console window do disappear. Since the > said app is going to be used with people that have less-than-average > knowledge in computers, it is imperative that this window goes away. I > tried sys.frozen = "windows_exe" and it doesn't work. I'm not sure > what to do. Please save me! > > -Matt K Jensen From ovazquez at nospam.shaw.ca Tue Aug 17 19:02:00 2004 From: ovazquez at nospam.shaw.ca (Orlando Vazquez) Date: Tue, 17 Aug 2004 23:02:00 GMT Subject: favorite python web development tool? In-Reply-To: <10i4nttktcvltdd@corp.supernews.com> References: <10i4nttktcvltdd@corp.supernews.com> Message-ID: mike wrote: > hi all - > > > i'm fairly new to python, coming from a java servlet / velocity template > background. i'm looking for a good python web development tool, and > hope to find some suggestions here. I've found mod_python + ZopePageTemplates (standalone) to be superb solution to web application development. ZPT feels like a very natural and maintainable way to separate business logic from presentation. Since I've started using these two technologies, I've found my productivity greatly increased. http://www.modpython.org http://zpt.sourceforge.net/ Have fun and take care ;-) -- Orlando Vazquez Remove the obvious from my e-mail address to reply. From wilkSPAM at OUTflibuste.net Mon Aug 2 17:03:19 2004 From: wilkSPAM at OUTflibuste.net (Wilk) Date: Mon, 02 Aug 2004 23:03:19 +0200 Subject: where is yaml ? Message-ID: <878ycxtfqg.fsf@blakie.riol> Hi, It seems that the link for python-yaml on the http://yaml.org main page is loose (http://iron.cx/yaml) :-( Anybody knows what's append ? What do you use ? pure python-yaml or syck ? -- Wilk - http://flibuste.net From reinhold-birkenfeld-nospam at wolke7.net Sun Aug 22 17:14:31 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Sun, 22 Aug 2004 23:14:31 +0200 Subject: How to sort this kind of list easily? In-Reply-To: <4128ef9d$1@nntp0.pdx.net> References: <4128ef9d$1@nntp0.pdx.net> Message-ID: <2osggvFebhtbU2@uni-berlin.de> Scott David Daniels wrote: > Ben Last wrote: >>>From: Anthony Baxter, in response to BruceKL WhoH >>>list.sort sorts tuples by first argument, then second &c. If you want a >>>custom sort order, look at the decorate-sort-undecorate pattern. >> >> >> Or if you want to sort only on your Id, use a lambda: >> l.sort(lambda x,y: cmp(x[0],y[0])) >> >> To force sorting on just the nth element of the tuples, replace 0 with n in >> the above. >> >> b >> > If you are using 2.4 (now in beta), you could also do: > > lst.sort(key=lambda element:element[1]) _If_ you are using 2.4, better use: lst.sort(key=operator.itemgetter(1)) Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From catcher at linuxmail.org Sun Aug 1 16:01:33 2004 From: catcher at linuxmail.org (Robert) Date: Sun, 1 Aug 2004 16:01:33 -0400 Subject: python tutes on win32 References: Message-ID: <1ZmdnZw7k-WA0ZDcRVn-rg@adelphia.com> "Jed R. Mallen" wrote in message news:f6e0a56a.0408011144.12bde5ad at posting.google.com... > Hello, > > Can anyone point me to a nice tute on making python apps for win32? > > TIA I looked up "tute" in the dictionary. No such word, so I must assume the answer is no. I am sure a nice Google search or even a search on the Python web site would help you a lot. From ngps at netmemetic.com Thu Aug 5 11:32:08 2004 From: ngps at netmemetic.com (Ng Pheng Siong) Date: 5 Aug 2004 15:32:08 GMT Subject: ZServerSSL and Certificates References: <3222fe00.0408050548.43b5f0fd@posting.google.com> Message-ID: According to Sean : > However I'm really not clear on > certificates in general, and we're about to try it with real certs > from a real CA. Ahem, please read this sentence aloud to yourself. Does it sound like a good idea? > # openssl -des3 -out privatekey 1024 > # ./CA.pl -newreq You mean 'openssl rsa ...' Anyways it is a no-op, given your second command; i.e., 'CA.pl -newreq' generates a key pair. > So I take privatekey.pem and the ca cert and combine them into a > single file called ca.pem. Why? > # ./CA.pl -sign This _signs_ your certificate request. Given that you've already gotten your certificate request signed by a 3rd party CA, this step is superfluous. > # openssl rsa < newreq.pem > newkey.pem > and I combine the server cert and newkey.pem and call it server.pem. Yup this is fine provided your newreq.pem contains your private key. > Microsoft IE6 first shows a request for a cert to use, This sounds like the server is asking for a client cert. Have you configured your ZServerSSL to do so? I think the server doesn't do that by default. > I click OK to > bypass it then a warning dialog that the ca is not trusted. Is the 3rd party CA's cert installed into your IE6? > Mozilla diaplays a panel warning that there are three potential > problems. What are the error messages? > In either case if I ignore the warnings I get a secure connection. You get a HTTPS connection. You are connecting to a site (well, your own, in this case) which certificate's CA your browser does not trust. "Secure" is a loaded word. ;-) > I need to understand what I'm doing wrong here. Read up more on how X.509 certificates are structured and on how SSL uses them. Then go install one or more other SSL server products. Follow their instructions on installing certificates. Once you see how different software packages do the same things it should become clearer to you. Try Apache + mod_ssl or AOLserver, say. Don't choose one where you configure the stuff using Windows or web-based pointy-and-clicky interfaces - you won't learn much that way. HTH. -- Ng Pheng Siong http://firewall.rulemaker.net -+- Cisco PIX & Netscreen Config Version Control http://sandbox.rulemaker.net/ngps -+- M2Crypto, ZServerSSL for Zope, Blog From martin at v.loewis.de Mon Aug 2 06:33:48 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 02 Aug 2004 12:33:48 +0200 Subject: building python extensions for windows : python23_d.lib file is missing In-Reply-To: <410e0b05$0$1895$636a15ce@news.free.fr> References: <410e0b05$0$1895$636a15ce@news.free.fr> Message-ID: <410e1889$0$24804$9b622d9e@news.freenet.de> Antoine Maillard wrote: > But we don't know how to go through this (perhaps recompiling a debug > version ... but we don't know how to do). Yes, you need to compile a debug version. Download the Python source code, and follow the instructions in PCbuild/readme.txt. Alternatively: a) build a release version of your own code, not a debug version, or b) do not define _DEBUG in the debug version of your code Regards, Martin From anthonybaxter at gmail.com Sun Aug 8 04:05:41 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sun, 8 Aug 2004 18:05:41 +1000 Subject: Mailing lists In-Reply-To: References: Message-ID: On 8 Aug 2004 00:42:09 -0700, Dan Bishop wrote: > Has anyone here implemented a mailing list server in Python? Erm. mailman? It's probably the single most-used piece of mailing list software on the internet, and is in Python From deetsNOSPAM at web.de Wed Aug 25 08:45:38 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Wed, 25 Aug 2004 14:45:38 +0200 Subject: module functions list References: Message-ID: Hi, > You could use a list comprehension coupled with a filter: > > functionList = [function for function in dir(objectName) \ > if callable(getattr(objectName,function))] That works if objectName is my module - but how do I get a reference to the current module _inside_ my module? Thats the hart part (at least for me ...) -- Regards, Diez B. Roggisch From b.niemann at betternet.de Wed Aug 25 11:44:58 2004 From: b.niemann at betternet.de (Benjamin Niemann) Date: Wed, 25 Aug 2004 17:44:58 +0200 Subject: Floating point weirdness In-Reply-To: References: Message-ID: Joshua Ginsberg wrote: > WTF, mate? > > >>>>import sys >>>>sys.version > > '2.3.3 (#1, May 7 2004, 10:31:40) \n[GCC 3.3.3 20040412 (Red Hat Linux > 3.3.3-7)]' > >>>>float('19.95') > > 19.949999999999999 > >>>>round(19.94999999999999999, 2) > > 19.949999999999999 > >>>>round(19.949, 1) > > 19.899999999999999 > > Why can't I just get 19.95? floats are represented as 64 (or 128?) bit values and there's no value that exactly represents 19.95 or 19.9 (=round(19.949, 1)). The last example results in the closest value to 19.9, but not exactly. Python prints this value with maximum precision. If you want a string representation of a float with e.g. 2 digits precision, use "%.2f" % 19.949 From graham__fawcett at hotmail.com Tue Aug 17 12:34:36 2004 From: graham__fawcett at hotmail.com (Graham Fawcett) Date: 17 Aug 2004 09:34:36 -0700 Subject: Flython? References: Message-ID: Peter Hansen wrote in message news:... > Just been looking at Flash and ActionScript... > > In the vein of Jython, I wonder what it would take to build > a Flython? (Lousy name, I know.) That would take Python > source, presumably a subset since some things couldn't be supported, > and compile it into ActionScript bytecode (aka the bytecode compiled > from ECMAScript source for the Macromedia Flash player environment). I've written some code (twice, I think) to generate SWF from Python. Didn't include ActionScript, but it's all there in the SWF spec, so it shouldn't be *too* hard to implement. My code was less than fast, and was highly specialized to do a few things that I was interested in (and ignored the rest). If there's interest, I'll dig it out, though it's far from project-grade code and is possibly broken. The toughest part was just grokking the SWF spec, and building some Pythonic primitives that can output SWF tags. Simply put, writing SWF from Python isn't rocket science. But of course, you want more than just that... > With that, it would be pretty easy to write applications which > have a Flash front end, but with pretty much all the logic > on front and back implemented in Python. A neat idea, definitely begging for a proof-of-concept. I look forward to testing it. ;-) There will be times when you want to make a GUI "flashier" than your framework will allow (unless you're planning to reimplement all of Flash). Perhaps you might want to use the framework to prototype something, and then knock the real thing out using Flash (perhaps importing the ActionScript from your framework). I'd encourage you to leave room in the design for the inclusion of non-native SWF components (i.e. ones built using something other than your framework) that could interact with your back-end (and, through it, with other client components). Dave Kuhlmann has done some interesting writing on generating Web applications from declarations (google for him, Quixote, and REST, and it should turn up). This might be useful, since your framework spans the client/server boundary (and perhaps you'd like to obscure that boundary just a little bit) and would be well suited to a declarative style (except for the scripting). Quixote suits REST quite well, it seems, and might be worth consideration as part of your back-end design. The last random snippet that comes to mind is that, on Win32, it's not hard to build a SWF viewer using wxPython (and the SWF plugin, of course). That might help with deployment where a browser really isn't suitable. I know I've said "your framework" half a dozen times, and there's no such animal, but I do hope that you or someone else picks up the trail on this and gives it a college try. It would be fun to use, I think. -- Graham From Jon_Kinsey at Hotmail.com Thu Aug 5 04:30:43 2004 From: Jon_Kinsey at Hotmail.com (Jon Kinsey) Date: 5 Aug 2004 01:30:43 -0700 Subject: Embedding python Message-ID: I've embedded python in a program, am I right in thinking python has to be installed on a machine for my program to work? If so how can I find out if python is installed/what version is installed - programatically and cross platform. Jon From apardon at forel.vub.ac.be Wed Aug 18 03:36:58 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 18 Aug 2004 07:36:58 GMT Subject: Piping stdout to Python callable References: Message-ID: Op 2004-08-18, Edward Diener schreef : > Antoon Pardon wrote: >> Op 2004-08-17, Edward Diener schreef : >>> From within a function in my own module I need to take the output >>> from a Python module "A", which is sending data to stdout and which >>> can not be changed and which I need to invoke as a top-level module, >>> and pipe it into another function in my own module so that I can >>> read it from stdin. Is there an easy way to do this ? The only way I >>> can presently think to do this is through "system python A.py | >>> python MyOwnModule.py", which seems a bit laborious having to invoke >>> python.exe itself twice. Any other solution would be most welcome. >> >> What do you mean when you say you need to invoke it as a top-level >> module? Do you mean you can't import it at all or that importing it >> will startup the process of generating output immediatly? > > I mean that it has a "if __name__ == '__main__' line and I need to trigger > it by calling 'python A.py'. >> >> What bothers you with twice invoking the interpreter? > > Nothing practically. Just seems inelegant. > >> In these days >> a program that is invoked multiples times will generally be only >> loaded once in memory. > > Shared libraries may be loaded once in memory but python.exe itself gets > reloaded each time. That depends on the O.S. It is possible the O.S. notices that an invoked program is already loaded en uses the same code-segment in memory for following invocations. >> Are threads an acceptable alternative? Does your MyOwnModule.py needs >> to write to stdout? > > Threads are acceptable. MyOwnModule.py can do anything, depending on > parameters, but the idea is that a certain parameter tells it to read from > stdin on the other end of the pipe. Then I fear there is no other solution. As far as I understand, you can't redirect standard output on a per thread basis, (at least not in python.) That means that if you redirect stdout of the A.py module to go into a pipe, the stdout of MyOwnModule.py will go into the same pipe. I don't think you want that. -- Antoon Pardon From franz.steinhaeusler at utanet.at Wed Aug 18 09:57:20 2004 From: franz.steinhaeusler at utanet.at (Franz Steinhaeusler) Date: Wed, 18 Aug 2004 15:57:20 +0200 Subject: Editors again References: Message-ID: <5mn6i0dp9f25phlja2tu8r9f25454njii8@4ax.com> On Tue, 17 Aug 2004 00:18:52 +0200, Ivan Voras wrote: >Are there any editors besides IDLE that can display doc-strings[*] in >popups? I tried SPE and DrPython, and while they are ok (better said >'not horribly bad'), they don't seem to have that option. Did you took a closer look to DrPython? This feature is called CallTips in DrPython. It is realized as plugin and you can it download from the plugin section of downloads. > >I'd like to see in an editor: > - code-completion in case of functions, member variables etc. >("intelli-sense"? :) ) there is also a plugin "AutoComplete". > - useful usage of doc-strings, maybe integrated python Help/Manual support What do you mean exactly? > - MDI or similar style, with good navigation (this is why I don't like >IDLE) All open Documents can be easily reached through the notebook-tabs. HTH -- Franz Steinhaeusler From news at finseth.com Tue Aug 31 12:06:31 2004 From: news at finseth.com (Craig A. Finseth) Date: 31 Aug 2004 16:06:31 GMT Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <%T%Yc.29567$Es2.11957889@news4.srv.hcvlny.cv.net> Message-ID: <4134a207$0$65568$a1866201@newsreader.visi.com> In article , Ville Vainio wrote: >>>>>> "John" == John W Kennedy writes: > > John> Yes, and also a single-process pipe emulator. Ever since > John> 2.0, MS has been trying to turn MS-DOS (later, Windows) into > John> a Unix clone. > >With very little success. Notepad still only understands cr-lf line >breaks, and / as path separator still screws up most of their cmd line >programs (which think / is for command line options). > >Microsoft probably thought avoiding compatibility is a good idea, and >have only lately started to have some regrets, visible as the release ... Wrong. The / was chosen as the command line option separator because whoever wrote MSDOS was looking to CP/M, who modelled their commands after a PDP-11 operating system (RT-11?). Consider the "PIP" command. When they went to MS/DOS 2.0 and needed path separators, they found that "/" was already taken, so they used "\". But there was a hidden way to tell the command interpreter that it could use "-" for options. And in all systems starting with 2.0, the system calls have taken "/" and "\" interchangably. Craig, who wrote a lot of code for CP/M, MS-DOS 1* and Later.... From tundra at tundraware.com Fri Aug 20 16:39:53 2004 From: tundra at tundraware.com (Tim Daneliuk) Date: 20 Aug 2004 16:39:53 EDT Subject: My only complaint about Python In-Reply-To: References: Message-ID: Istvan Albert wrote: > Darren Dale wrote: > >> I love the language. I love the community. My only complaint is that >> Python for Windows is built with Visual Studio. >> >> It is too difficult to build python, or a module, from source. > > > In all fairness this is more the problem with Microsoft than > python. If they had a free fully-featured compiler then Python > would be compiled with that. They do. MSC/C++ is now available at NO cost: http://msdn.microsoft.com/visualc/vctoolkit2003/ ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From aleaxit at yahoo.com Mon Aug 30 09:25:02 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 30 Aug 2004 15:25:02 +0200 Subject: regex into str References: Message-ID: <1gjc7vj.1vhe7n7mu75glN%aleaxit@yahoo.com> Peter Kleiweg wrote: ... > > > Is there a way to tell Python that '' should be something else > > > than str? > > > > No. > > Bummer. I think you might be happier with Ruby -- beyond a number of trivia, the big difference between the two, from my POV, is that in Ruby you can alter built-ins, in Python you can't. Which is why I personally stick with Python, but to anyone who mostly likes Python but believes he would get better programs by modifying built-ins, I suggest Ruby. Alex From duncan.booth at invalid.invalid Fri Aug 13 11:01:01 2004 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 13 Aug 2004 15:01:01 GMT Subject: Difference between readlines() and iterating on a file object? References: <411cd102$1@mail.hmgcc.gov.uk> Message-ID: "Richard" wrote in news:411cd102$1 at mail.hmgcc.gov.uk: > Hi, > > Can anyone tell me what the difference is between > > for line in file.readlines( ): reads the entire file into memory and splits it up into a list of lines then iterates over the list. If you break from the loop, tough you've lost any lines that were read but you didn't handle. > > and > > for line in file: reads part of the file and strips off one line at a time. Never creates a list. Reads more only when it runs out of the block it read. If you break from the loop you can do another 'for line in file' and get the remaining lines. > > where file is a file object returned from an open( ) call? > From jmfbahciv at aol.com Sun Aug 29 05:55:33 2004 From: jmfbahciv at aol.com (jmfbahciv at aol.com) Date: Sun, 29 Aug 04 09:55:33 GMT Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <412e199e$0$8076$a1866201@newsreader.visi.com> <4130654c$0$19703$61fed72c@news.rcn.com> Message-ID: <4131babd$0$19722$61fed72c@news.rcn.com> In article , rpw3 at rpw3.org (Rob Warnock) wrote: >+--------------- >| jdoherty at nowhere.null.not (John Doherty) wrote: >| >AND HOW MANY SPACES PER TAB STOP? >| >| Eight. Now talk about indenting skip returns...that one >| required blood transfusions. [emoticon looks at list of n.g.] >| I guess not many will understand. >+--------------- > >You might be surprised, Barb. Quite a few of the comp.lang.lisp crew >are former PDP-10 geeks. ;-} Yep for Lisp, but Perl and Python? Everything after python is printing off my screen (I hate forms). > >And just to be sure *I'm* understanding what you're talking about, ;-} >did you mean the convention of the second line of the following snippet? Yep, but you have a bug. The MOVEI [emoticon scrolls down to look] heh... my reply form is non-porportional and now everything is wrong. That's why the hard and fast rule of 8 was used in PDP-10 land. > > foo: pushj p,ckperm > pjrst badprm ; user lacks privs, complain & return. > movei t0,cmdblk ; o.k. to proceed. > ... > >Indenting the non-skip return for a subroutine call was always pretty >clear to me. It was to the -20 types, too. The -10 types maintained that, if the human code reader didn't know the call had a skip return, he had no business looking at the code. Having the opcodes all line up left-justified made reading code quickly possible. > ..Where things got really muddled (and contentious!) was >when you had long skip chains of T{R,L}{Z,O,C,~}{N,E} instructions >in which whether a particular instruction was in the skipped-to or >non-skipped position depended dynamically on the flow of control >above it. [HAKMEM was chock-full of that kind of "efficient" code.] >In that case, it seemed more readable to simply not indent anything in >the skip chain, and put a scary comment warning about the tricky code. If you knew your biz, you didn't need the scary warning. Now consider a list of PUSHJs where each could have a skip, double-skip or triple-skip return. Depending on which way you're flowing through the code, each and every one could be indented and not-indented. /BAH Subtract a hundred and four for e-mail. From eppstein at ics.uci.edu Mon Aug 23 14:58:15 2004 From: eppstein at ics.uci.edu (David Eppstein) Date: Mon, 23 Aug 2004 11:58:15 -0700 Subject: Standard graph API? References: Message-ID: In article , mlh at furu.idi.ntnu.no (Magnus Lie Hetland) wrote: > Yes, we have the standard ways of implementing graphs through (e.g.) > dicts mapping nodes to neighbor-sets, but if one wants a graph that's > implemented in some other way, this may not be the most convenient > (or abstract) interface to emulate. Actually, my interpretation of this standard way is as a fairly abstract interface, rather than a specific instantiation such as dict-of-sets: Most of the time, I merely require that iter(G) produces a sequence of the vertices of graph G, and iter(G[v]) produces a sequence of neighbors of vertex v. I also sometimes use "v in G" and "w in G[v]" to test existence of vertices or edges. Pros and cons of this approach: - You can use a list instead of a set in the adjacency list part of the representation. This may be faster and more space efficient when the vertex degrees are small. - It's easy to create test graphs as code literals G1 = { 0: [1,2,5], 1: [0,5], 2: [0,3,4], 3: [2,4,5,6], 4: [2,3,5,6], 5: [0,1,3,4], 6: [3,4], } G2 = { 0: [2,5], 1: [3,8], 2: [0,3,5], 3: [1,2,6,8], 4: [7], 5: [0,2], 6: [3,8], 7: [4], 8: [1,3,6], } - Any indexable object can be a vertex. The vertex identities can be something meaningful to your program. On the other hand, that means (unless you know where your graph came from) you can't rely on the vertices being special vertex objects with nice properties and you can't use objects like None as flag values unless you're sure they won't be vertices. - It doesn't provide an abstract way of changing the graph (although that's relatively easy if G is e.g. a dict of sets) - It doesn't directly represent multigraphs - It doesn't directly represent undirected graphs (instead you have to replace an undirected edge by two directed edges and hope your callers don't give you a directed graph by mistake). - There isn't an explicit object representing an edge, although you can create one by using a tuple (v,w) or (for undirected edges) a set. This can be an advantage in terms of memory usage but a disadvantage in terms of number of object creations. Also it means that if you want to store information on the edges you have to use a dict indexed by the edge instead of attributes on an edge object (probably better style anyway since it prevents different algorithms on the same graph from colliding with each other's attributes). -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ From curzio.basso at unibas.ch Tue Aug 10 10:35:48 2004 From: curzio.basso at unibas.ch (Curzio Basso) Date: Tue, 10 Aug 2004 16:35:48 +0200 Subject: how to dispatch objects depending on their class Message-ID: <4118dd4a$1@maser.urz.unibas.ch> Hi all. I have a couple of question regarding the following situation: class A(object): def __init__(self): pass class B(object): def __init__(self): A.__init__(self) def func(object): if isinstance(object, A): do_something_with_A(object) elif isinstance(object, B): do_something_with_B(object) Note that in my real problem I cannot move the logic of func to the class A and B because I will have a hierarchy also for func. Then I need a way to dispatch the object to the right function. I thought about using a dictionary, like: FUNC = {"": do_something_with_A, "": do_something_with_B} def func(object): FUNC[type(object)](object) But: (1) I am not sure of what the type(object) function return. In this case A and B are in the __main__ namespace (assuming this is how is called), but if they are in a module; (2) I am not sure if it is efficient; and finally (3): probably there is a better way to do it (this is always a safe assumption). I hope my problem is clear, and excuse me if I am asking about something that is common knowledge, but I don't even know what to google for... thanks, curzio From http Sat Aug 21 23:29:51 2004 From: http (Paul Rubin) Date: 21 Aug 2004 20:29:51 -0700 Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? References: Message-ID: <7xoel3hmts.fsf@ruckus.brouhaha.com> "Paul McGuire" writes: > Please start giving some thought to what the 'decorate' keyword should be. Looks like "declare" to me ;-) From CousinStanley at HotMail.Com Sun Aug 15 14:40:44 2004 From: CousinStanley at HotMail.Com (Cousin Stanley) Date: Sun, 15 Aug 2004 11:40:44 -0700 Subject: Flython? References: <2o3ovjF6apnoU1@uni-berlin.de> <2o4555F6dms6U1@uni-berlin.de> Message-ID: <2o9op9F8a8ehU1@uni-berlin.de> Daniel Ellison wrote .... | .... | A flying python! | I can see the logo now... Peter Hansen wrote .... | But does it have anything to do with scripting | via ActionScript ? | | As far as I can see it is purely a GUI tool | for doing simple animations, and does not allow any scripting. Peter .... Like Dan Ellison, I was also would like to see a Flying Python and thought PowerBullet might provide a free and convenient mechanism to help realize that vision .... Apparently, a few others have also inquired about scripting capabilities in Powerbullet and a bit of searching at their on-line forum turned up the following replies from Mark Carter the author of Powerbullet .... Cousin Stanley Human Being Phoenix, Arizona --------------------------------------------------------------- Source ....... http://www.powerbullet.com/forum/viewtopic.php?t=243&highlight=actionscript Posted_By .... Mark Carter, { Powerbullet Author } Date ......... Sat Feb 07, 2004 3:30 am || .... || will actionscript work if I add it into the HTML code? || .... No. This is something for the future. Not so hard to support actionscript, I just haven't included it because PB is aimed at non-programmers. For navigation it's more likely I'll include just low level Flash jumps. Perhaps later it might be a good idea to put action scripts in the HTML - but they won't work now because I don't parse them. Not a bad idea though... let me think about it Source ....... http://www.powerbullet.com/forum/viewtopic.php?t=529 Date ......... Fri Apr 30, 2004 7:13 pm Next version, due for release in a fortnight, has capability to pass messages from the SWF movie to your web page. So you can create a JavaScript function on your page and call it from the Flash movie. You do this using the existing URL link mechanism for buttons or linked external SWF movies. There are standard commands that can be directed to Flash from JavaScript. See the Macromedia Flash site. Built-in commands that you can call from your web page http://www.macromedia.com/support/flash/publishexport/scriptingwithflash/scriptingwithflash_03.html Examples of calling (some quite silly) DHTML facilities http://www.flashkit.com/tutorials/Interactivity/Flash_J-Chris_Pe-584/index.php From BruceEckel at MailBlocks.com Wed Aug 4 14:46:23 2004 From: BruceEckel at MailBlocks.com (Bruce Eckel) Date: Wed, 4 Aug 2004 12:46:23 -0600 Subject: The term "Protocol" In-Reply-To: References: <1f7befae04080117515cbb0ca9@mail.gmail.com> <6910338109.20040801192523@ <393390620.20040804124623@MailBlocks.com> Message-ID: Monday, August 2, 2004, 8:44:38 AM, Aahz wrote: > Alex Martelli gave an excellent presentation on Design Patterns at OSCON, > where he made the point that "interface" is roughly equivalent to syntax, > whereas "protocol" is roughly equivalent to syntax plus semantics. In > other words, computer langauges rarely (if ever -- although I suppose > Eiffel comes close) enforce protocols in any meaningful way. But what would the syntax be in Python? -- there is none. Perhaps you mean that in Java a protocol would be an interface plus agreed-upon semantics, whereas in Python the protocol would be the agreed-upon (e.g. "latent") interface plus the agreed-upon semantics. In a sense, both the syntax and semantics would be latent; they would only be exposed and tested during use, since there is no formalized way to define them. In Python, of course, you could simply use a class with "pass" methods everywhere to define a protocol. If there were some way to write assertions about the protocol you could include those in the class. Bruce Eckel From __peter__ at web.de Tue Aug 3 07:17:14 2004 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Aug 2004 13:17:14 +0200 Subject: automatic delegation References: Message-ID: Hallvard B Furuseth wrote: > Is it possible to write a metaclass or something so that > with a class definition not much larger than this: > > class foo: > def __init__(self, val): self.val = val > > operations on a foo instance f will be applied to f.val? > E.g. str(f) -> f.__str__() -> f.val.__str__(). I tried in vain to solve your problem while improving my understanding of metaclasses. I have made an observation that might interest you, though: str(foo()) and foo.__str__(foo()) are not the same: >>> class Type(type): ... def __getattribute__(self, name): ... def tostr(self): ... return "so what" ... return tostr ... >>> class C: ... __metaclass__ = Type ... >>> print str(C()) <__main__.C object at 0x40296a8c> >>> print C.__str__(C()) so what >>> Care to explain, anyone? Peter From steven.bethard at gmail.com Mon Aug 23 23:40:14 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Tue, 24 Aug 2004 03:40:14 +0000 (UTC) Subject: function taking scalar or list argument References: <412a2bce$1_1@127.0.0.1> <9ZCdnT9EuudK3bfcRVn-tA@comcast.com> <10il11q5uqfg4ad@corp.supernews.com> Message-ID: Jeff Shannon ccvcorp.com> writes: > Actually, I'd favor the try/except approach. It's entirely reasonable > to think that, if this function might be passed either scalars or lists, > it may also be passed a non-list-based sequence object. If you simply > try using map(), then it'll work correctly for any object that follows > the expected protocol, regardless of whether that object is (a subclass > of) list. By explicitly demanding a list, you're needlessly limiting > the usefulness of the function. Well, you can always test for the protocol, e.g.: def twice(x): if hasattr(x, "__iter__"): return map(twice, x) else: return 2*x It just seems like a misuse of the construct to me to treat the most frequent case as an exceptional one. Note that the following solution (that doesn't recurse) wouldn't be unreasonable if you expected to pass mostly sequences to the function: def twice(x): try: return map(lambda x: 2*x, x) except TypeError: return 2*x The difference here is that we are now treating the sequence case as the simple case -- if we're dealing with a sequence, no exception handling is required. So if the sequence case is substantially more frequent, this would be a perfectly reasonable solution. (Note that the difference between this and the original solution is that this version does not recurse, so, unlike the original solution, this one will not throw an exception for every element in the sequence.) Steve From a at b.com Mon Aug 16 03:12:45 2004 From: a at b.com (wonder) Date: Mon, 16 Aug 2004 15:12:45 +0800 Subject: passing the url of the current webpage to python script Message-ID: Hi, How can I pass the url of the current webpage link to a python script in html? thanks sam From jeff_news at lindholm.org Mon Aug 23 14:08:09 2004 From: jeff_news at lindholm.org (Jeff Lindholm) Date: Mon, 23 Aug 2004 18:08:09 GMT Subject: python usage References: Message-ID: > Hi, One of my customer wants me to use Python as a test scripting > language. The architecture is as follows: An C++/Java UI obtains all > required inputs from the user and then makes call to Python script > which inturns calls c++ client stubs. These stubs are CORBA stubs > which talk to a CORBA server residing some where in the network. > I want to know as to whether it is feasible to use Python or just live > with c++ for UI and stubs? > Is it good to use Python for this purpose? What is the advantage? > Thanks > Phanish If all you are testing is the CORBA object, then go all Python, if you are using it to create a prototype or something, then use the language that is the final target. (if you can make the final target Python, great) There is no reason to try and find a reason to use Python (or any language), if you are only using it to say "Look I used Python here" then it is probably the wrong choice. Going from C++/Java UI to Python back to C++/Java why put Python in the middle? I would guess that C++/Java to CORBA would be better if C++/Java was the requirement. If Python is the requirement then Python to CORBA would be better. From noone at here.com Thu Aug 26 09:12:14 2004 From: noone at here.com (M. Clift) Date: Thu, 26 Aug 2004 14:12:14 +0100 Subject: Dennis, Greg, Ian References: <1q8002-nal.ln1@suse.zobbo.org> Message-ID: Hi to all of you, Well that's a lot of 'stuff' you gave me. Thankyou. I did understand that the brackets were not part of the list, but leaving them that way (as tuples) I could see problems in trying to refer to them at some stage. I was having no luck with what I was doing, ending up with just being able to call the first item in each tuple. As I'm new to this, maybe I don't actually need to do this in the long run for what I want, but for now while I think that I do, these answers are exactly what I need. All the best, M From noone at here.com Fri Aug 20 11:22:10 2004 From: noone at here.com (M. Clift) Date: Fri, 20 Aug 2004 16:22:10 +0100 Subject: Rita Sue and Bob too References: Message-ID: If I wasn't happy enough already with the examples/ideas you've all shown me, how about searching as previously, but where the middle name could be anything. i.e. 'Rita', 'anyname','Bob' M From h.b.furuseth at usit.uio.no Mon Aug 30 13:06:37 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 30 Aug 2004 19:06:37 +0200 Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Paul Morrow wrote: > I believe that we should think of assignments to __xxx__ attributes as > not being part of the function's body, but instead part of its > declaration, just as we do with its docstring. > > def circum(diameter): > """This describe's foo.""" > __author__ = 'Paul Morrow' > __version__ = '0.1' > __features__ = synchronized, memoized I really, really don't like this idea. Assignment in Python has quite enough pitfalls already. Please don't make it worse. If it looks like an assignment to a local variable, it should be an assignment to a local variable. If we are going to invent a syntax for declaring function attributes inside the function, why confuse the issue by making it look like it does something else? It's true that it makes it look more like what __*__ attribute assignment in class bodies does, but the simple fact is that class bodies are executed when the class statement is executed, and function bodies are not executed when the def statement is executed. Now you want part of the function bodies to be executed at def time, and part at call time. __*__ assigments in class bodies can look a little confusing if you don't think of how class declarations work, but it's perfectly simple once you think of how they do work: Execute the class body - no magic involved (as far as I know). Then pass the resulting __dict__ to the class creation machine - and _that_ recognizes __metaclass__, __slots__ and I don't know what else and does magic with them. Once you remember that, __*__ variables in both class bodies and function bodies do exactly what one would expect them to do. Stronger magic, like grabbing the doc string and putting it in __doc__, has its own syntax. -- Hallvard From keir at mooncode.com Wed Aug 25 12:18:54 2004 From: keir at mooncode.com (keirr) Date: 25 Aug 2004 09:18:54 -0700 Subject: Compiling a custom python library Message-ID: Henning Kage wrote: > I'm writing a small Python library with some generic classes and > interfaces, that can be used within other Python projects in our company. > Would it be a better solution to compile this library into a Python DLL > (and if so, how can it be done) or to distribute the "raw" sourcecode of > these classes etc.? What would be the best solution, so that other > programmers can easily integrate this library into their own programs? You might find distutils will work for you, read about it at http://www.python.org/sigs/distutils-sig/doc/ A 'dll' would work as well - but you loose cross platform support. Cheers, Keir Robinson. From pm_mon at yahoo.com Mon Aug 30 18:22:04 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Mon, 30 Aug 2004 18:22:04 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Hallvard B Furuseth wrote: > Paul Morrow wrote: > >>I believe that we should think of assignments to __xxx__ attributes as >>not being part of the function's body, but instead part of its >>declaration, just as we do with its docstring. >> >> def circum(diameter): >> """This describe's foo.""" >> __author__ = 'Paul Morrow' >> __version__ = '0.1' >> __features__ = synchronized, memoized > > > I really, really don't like this idea. Assignment in Python has quite > enough pitfalls already. Please don't make it worse. If it looks like > an assignment to a local variable, it should be an assignment to a local > variable. Actually, these look like assignments to local *magic* variables. There's the difference. The double underscores before and after each name loudly proclaims that these variables are not like 'normal' variables. They're special in some way. That's a Python convention. > If we are going to invent a syntax for declaring function > attributes inside the function, why confuse the issue by making it look > like it does something else? > Because 1) adding new syntax should be resisted as much as possible (IMO), and 2) this style has parallels in both class definitions and module definitions. Compare this class statement with the function def above. class Oval(Circle): """This describe's Oval.""" __author__ = 'Paul Morrow' __version__ = '0.1' __metaclass__ = M > It's true that it makes it look more like what __*__ attribute > assignment in class bodies does, but the simple fact is that class > bodies are executed when the class statement is executed, and function > bodies are not executed when the def statement is executed. Now you > want part of the function bodies to be executed at def time, and part at > call time. > Maybe we just need to be clear as to which lines under the def statement constitute the function's /body/. The function's docstring gets assigned during processing of the def statement, therefore the docstring is apparently not part of the function body; I think of it as part of the function's declaration. So why not have assignments to __xxx__ variables also be part of the function's declaration. The distinctive appearance of these names helps remind us that they have special semantics. And note that if __xxx__ variables/attributes inside of function defs *don't* have special semantics (i.e. if they are being used as normal local variables), then they are improperly named (in accordance with our naming conventions). > __*__ assigments in class bodies can look a little confusing if you > don't think of how class declarations work, but it's perfectly simple > once you think of how they do work: Execute the class body - no magic > involved (as far as I know). Then pass the resulting __dict__ to the > class creation machine - and _that_ recognizes __metaclass__, __slots__ > and I don't know what else and does magic with them. > > Once you remember that, __*__ variables in both class bodies and > function bodies do exactly what one would expect them to do. Stronger > magic, like grabbing the doc string and putting it in __doc__, has its > own syntax. > Perhaps its just my experience with declarative programming languages, but I prefer thinking of __xxx__ assignments in a class as setting 'properties' of the class. It's a higher level of abstraction than thinking in terms of the procedural mechanics of what happens under the hood. And the syntax used to set properties in classes/modules should be the same one used to set properties in functions and methods (IMO). Paul From jeff at ccvcorp.com Wed Aug 18 16:00:47 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Wed, 18 Aug 2004 13:00:47 -0700 Subject: age of Python programmers In-Reply-To: References: Message-ID: <10i7da3cu03eabb@corp.supernews.com> I'm 35, and have been programming off and on (more off than on) since I was about 11. First program was in Basic on a TRS-80, quickly moved on to Apple //e; didn't program at all in high school, took a "programming for engineers" course in college (Basic & Fortran), then after college decided to teach myself C. Another break of some years before I bought myself a (used) 386 PC, and resumed dabbling in C, then C++. At this point (about 8 years ago) I became hooked, and started devouring all the programming and software engineering/design books I could get from the library. Once my job started including coding (mostly [Pick] Basic & UHL, a proprietary [and horribly ugly & evil] scripting language), I decided to pick up Python (based largely on a Dr. Dobbs Journal Programmer of the Year award to Gvr, and the article about him and Python they published then) and never want to look back. :) Jeff Shannon Technician/Programmer Credit International From b.niemann at betternet.de Mon Aug 30 03:35:05 2004 From: b.niemann at betternet.de (Benjamin Niemann) Date: Mon, 30 Aug 2004 09:35:05 +0200 Subject: initializing mutable class attributes In-Reply-To: References: Message-ID: That's the way it is supposed to work. Instance attributes have to be initialized via self.foo=..., usually in __init__() which in turn is *STRONGLY* advised to class its parents __init__() - or you create instance attributes 'on-the-fly' when they are used for the first time (useful technique for mixin classes without constructor). Class attributes are initialized once for the class and are shared between instances. "self.attr1=data" in Father.foo() doesn't "override" the Father.attr1 attribute you defined before. It creates an instance attribute that shadows Father.attr1! Both attribute assignments in Father are OK - if you treat them as class attributes. They won't become instance attributes by hidden magic. Dan Perl wrote: > There is something with initializing mutable class attributes that I am > struggling with. I'll use an example to explain: > class Father: > attr1=None # this is OK > attr2=[ ] # this is wrong > def foo(self, data): > self.attr1=data > self.attr2.append(data) > The initialization of attr1 is obviously OK, all instances of Father > redefine it in the method foo. But the initialization of attr2 is wrong > because all the instances of Father end up sharing the same value. Maybe > that is desired sometimes, but usually it is just a bug. > > So the only solution I see to this is to initialize attr2 in __init__: > class Father: > attr1=None > def __init__(self): > self.attr2=[ ] > > This is already awkward because there is such a difference between attr1 and > attr2. But moreover, I think this forces subclasses of Father to do > something like this: > class Child (Father): > def __init__(self): > Father.__init__(self) > self.attr3=[ ] > > I find this even more awkward because many people will forget to do it. > Clearly, this is then a more general issue with __init__, but I think it is > accentuated by the fact that you HAVE TO HAVE __init__ in order to > initialize attributes that are mutable. > > Is there something I don't know here and there is a better way to do this in > Python? I would like to get a better solution or otherwise start a > discussion. From usenet_spam at janc.invalid Tue Aug 24 19:33:33 2004 From: usenet_spam at janc.invalid (JanC) Date: Tue, 24 Aug 2004 23:33:33 GMT Subject: On consensus decision-making (was Re: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WEDONE?) References: Message-ID: Anthony Baxter schreef: > (Of course, there's also my cunning plot to use this particular issue > to get a couple more people involved in Python's development process - > we now have at least one person who's obviously a good person to write > up future PEPs, and another who's now delved into Python's innards in > a non-trivial way.... moohahaha) As Guido told you to implement/include(?) the @-syntax, maybe that was also _his_ secret plot: the fact that so many people seem to hate it almost forced them to become Python core developers... ;-) -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From jepler at unpythonic.net Sun Aug 29 22:42:46 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Sun, 29 Aug 2004 21:42:46 -0500 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: Message-ID: <20040830024246.GA2159@unpythonic.net> In your proposed model, what does the following code do? def f(): __var__ = 3 return __var__ f.__var__ += 1 print f() What about any of the following: def g(): if True: __var__ = 4 print g.__var__ x = 3 def h(x): __var__ = x*x return x*x print h(2), h.__var__ def j(cls): def __radd__(self, other): return self.__add__(other) cls.__radd__ = __radd__ def k(x): __created__ = Date(1, 1, 2004) __expires__ = __created__ + Interval("1 year") def l(x): __now__ = time.time() return __now__ print l.__now__, l() x = 3 def m(): __x__ = x return __x__ x = 4 print m(), m.__x__ def n(f, a): __doc__ = gettext.gettext(f.__doc__) __author__ = a.replace("@", " AT ").replace(".", " DOT ") l = locals() del l['f'], l['d'], l['a'], l['l'] f.__dict__.__update__(l) def p(): import os as __os__ def q(): # BUG x doesn't get the proper metaclass in 2.3! class __metaclass__(type): pass class x: pass # assert x's metaclass is __metaclass__ I gave it a few minutes thought, and I can't figure out a simple rule that would *not* break code that happened to use __name__s as function locals (since this has been allowed in all the ten years I've written Python programs), would not add a new level of name lookup (lookup of unqualified name on function object), would not introduce confusion about when lines of code *in the function body* would be evaluated, would not require that assignment statements be treated differently from "def", "class", and "__import__" statements, etc, etc. If you clear some or all of these things up, and turn it into a complete proposal, wake me up. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From __peter__ at web.de Tue Aug 31 11:08:06 2004 From: __peter__ at web.de (Peter Otten) Date: Tue, 31 Aug 2004 17:08:06 +0200 Subject: Splitting a list References: <41A1CBC76FDECC42B67946519C6677A9018C2F6B@pippin.int.etrials.com> Message-ID: Jeff Epler wrote: > Here's my version as a generator function: > def split(it, elem): > l = [] > for i in it: > if i == elem: > yield l > l = [] > else: > l.append(i) > yield l > A clean algorithm, but it has one corner case that strikes me as counterintuitive: >>> list(split([], None)) [[]] I would prefer [], so I cross-checked with str.split(): >>> "".split() [] >>> "".split("x") [''] Strange. Is that by design or by accident? Peter From pje at telecommunity.com Sat Aug 14 15:02:30 2004 From: pje at telecommunity.com (Phillip J. Eby) Date: 14 Aug 2004 12:02:30 -0700 Subject: decorators and multimethods References: <4edc17eb.0408062340.71ab270f@posting.google.com> Message-ID: <25b5433d.0408141102.3c77560a@posting.google.com> michele.simionato at gmail.com (Michele Simionato) wrote in message news:<4edc17eb.0408062340.71ab270f at posting.google.com>... > > One trick is to use decorators to implement multimethods. A while ago > Howard Stearns posted here a recipe to implement generic functions > a.k.a multimethods. > > I have not studied his recipe, so don't ask me how it works. All I > did was to add an "addmethod" function and save his code in a module > called genericfunctions. > > Decorators allowed me to use the following syntax: > > # BEGIN generic functions in Python, example > # use code and examples from Howard Stearns > > from genericfunctions import Generic_Function, addmethod > > foo = Generic_Function() > > @addmethod(object, object, object) > def foo(_, x, y, z): > return 'default' > > @addmethod(int, int, int) > def foo(call_next, x, y, z): > return 'all ints , ' + call_next(x, y, z) > > @addmethod(object, object) > def foo( _, x, y): > return 'just two' FYI, there's another example of this approach available in PyProtocols CVS; see: http://www.eby-sarna.com/pipermail/peak/2004-July/001598.html It uses this syntax: from protocols.dispatch import when, next_method [when("True")] def foo(x,y,z): return "default" [when("x in int and y in int and z in int")] def foo(x,y,z): return "all ints, "+next_method(x,y,z) but will work with Python 2.2.2 and up. It also allows arbitrary expressions to be used to distinguish multimethod cases, not just type information, but still optimizes them to table lookups. It doesn't support variadic or default arguments yet, though. From donn at drizzle.com Sat Aug 21 23:15:27 2004 From: donn at drizzle.com (Donn Cave) Date: Sun, 22 Aug 2004 03:15:27 -0000 Subject: popen child termination References: Message-ID: <1093144525.282797@yasure> Quoth Milos Prudek : | How can I make popen (popen2, popen3) run and finish inside my program? | | Example: | | def Run(cmd): | w,r,e = os.popen3(cmd) | w.close() | r.close() | e.close() | Run('touch ~/xxx') | os.remove('~/xxx') | | The example above fails with this error message for os.remove: "No such | file or directory: '~/xxx'" | | But when the os.remove line is deleted, the example correctly creates | the xxx file. | | I feel that os.wait() deals with this but I do not understand how to use | it to do what I want. You're right, but you're going to have to back up a little and do the popen part a little different. popen() itself is simpler, because the wait() is built into the pclose(3) function that's called by the close() method. You will find that it returns exit status, except when exit status is 0 in which case it returns None. (Did that make sense? I hope not.) As for popen3(), you will need to instead create the Popen3 instance that popen3 creates. Then you can invoke its wait() method. There isn't any way to get there from just the file objects that popen3() returns. Donn Cave, donn at drizzle.com From shalabh at cafepy.com Fri Aug 6 18:41:06 2004 From: shalabh at cafepy.com (Shalabh Chaturvedi) Date: Fri, 06 Aug 2004 15:41:06 -0700 Subject: Confused about pep 318 In-Reply-To: References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: Peter Hansen wrote: > I'm also surprised that the choice which had the greatest public > support during the straw poll at PyCon isn't still under discussion, I doubt any of the following would have made it in Python had it followed the course of 'greatest public support': 1. Whitespace based blocks 2. Docstrings Looking back, I remember when I started out with Python I had a "Eeww, what's this!?" reaction to both of the above, very similar to what I initially felt for @-decorator. After using it in my code I find it's actually not bad at all. I'd prefer to use the '|' character for aesthetics but am happy with @ as well. Cheers, Shalabh From mwh at python.net Mon Aug 23 11:24:03 2004 From: mwh at python.net (Michael Hudson) Date: Mon, 23 Aug 2004 15:24:03 GMT Subject: __name__ becoming read-write? References: Message-ID: Hallvard B Furuseth writes: > Arthur wrote: > > > Did I hallucinate something about __name__ becoming read-write? > > _Becoming_ read-write? When was it read-only? When it was a function :-) Or a new style class in 2.2. Cheers, mwh -- I never disputed the Perl hacking skill of the Slashdot creators. My objections are to the editors' taste, the site's ugly visual design, and the Slashdot community's raging stupidity. -- http://www.cs.washington.edu/homes/klee/misc/slashdot.html#faq From jlbgnews at houseofdistraction.com Thu Aug 26 15:01:50 2004 From: jlbgnews at houseofdistraction.com (Jeff Bowden) Date: 26 Aug 2004 12:01:50 -0700 Subject: Making sgmlib more liberal Message-ID: <14b59724.0408261101.7cdb0ba5@posting.google.com> I've written a simple class derived from sgmllib.SGMLParser to extract text from html pages. So far it's worked pretty well except for a few cases where I get exceptions. I've managed to work around these problems by overriding parse_declaration. Since parse_declaration is preceded by the comment # Internal -- parse declaration (for use by subclasses). I am thinking my workaround might possibly stop working with future versions of sgmllib so I'm looking for a more correct alternative. Any suggestions? Here's my code: _endTag = re.compile(r'>') class SGML2TextParser(sgmllib.SGMLParser): def __init__(self, f, ignoretags=['script']): sgmllib.SGMLParser.__init__(self) self.f = f self.ignoretags = ignoretags self.tag = '' def handle_starttag(self, tag, attrs): self.tag = tag def handle_data(self, data): if self.tag not in self.ignoretags: self.f.write(data) def handle_charref(self, name): try: n = int(name) self.handle_data(unichr(n)) except ValueError: pass # DANGER: overriding internal function def parse_declaration(self, i): try: return sgmllib.SGMLParser.parse_declaration(self, i) except: match = _endTag.search(self.rawdata, i) return match and match.end(0) or -1 def extractText(html_text): s = StringIO.StringIO() x = SGML2TextParser(s) x.feed(html_text) return s.getvalue() From records2010 at yahoo.com Tue Aug 3 22:31:17 2004 From: records2010 at yahoo.com (Chris) Date: 3 Aug 2004 19:31:17 -0700 Subject: file IO References: Message-ID: <273c21f2.0408031831.9e50d70@posting.google.com> Jeff Epler wrote in message news:... > Are you using Windows? That would mean the answer is almost certainly > "something to do with carriage returns and binary vs text mode". The > lack of a trailing newline on the last line of your example can also > make for additional trouble (though my tests on unix, with stdio, mmap, > and StringIO didn't ever give me a 4-byte file, windows might give you > the file "a\r\nb" when viewed in binary format, "a\nb" when viewed in > text format) > > I doubt that the mmap module's readline knows whether the file was > opened in universal text mode---that's a pure Python invention, while > mmap takes a file descriptor. > > On Unix, I don't find that a "while" loop with mmap.readline is any > faster than a "for" loop over a file: > > [45426 lines, 409305 bytes] > $ timeit -s "..." "readspeed.read_stdio('/usr/share/dict/words')" > 10 loops, best of 3: 34.9 msec per loop > $ timeit -s "..." "readspeed.read_mmap('/usr/share/dict/words')" > 10 loops, best of 3: 107 msec per loop > > [363416 lines, 3274440 bytes] > $ time python -c "import readspeed; readspeed.read_stdio('biggerfile.txt')" > real 0.372s user 0.331s sys 0.031s > $ time python -c "import readspeed; readspeed.read_mmap('biggerfile.txt')" > real 1.080s user 1.013s sys 0.021s > > [2907328 lines, 26195520 bytes] > $ time python -c "import readspeed; readspeed.read_stdio('biggerfile.txt')" > real 2.603s user 2.308s sys 0.157s > $ time python -c "import readspeed; readspeed.read_mmap('biggerfile.txt')" > real 8.514s user 7.893s sys 0.153s > > I didn't have any "bigger-than-RAM text files" around to test. > > Testing "biggerfile.txt" with mode "rU" gives real 3.110s, so there is > some penalty from using universal newlines. > > ------------------------------------------------------------------------ > # readspeed.py > from mmap import mmap, PROT_READ > import itertools, os > > def consume(iterable): > for j in iterable: pass > > def read_stdio(filename): > f = open(filename) # open(filename, "rU") is slightly slower > consume(f) > > def read_mmap(filename): > f = open(filename) > fd = f.fileno() > m = mmap(fd, os.fstat(fd).st_size, prot=PROT_READ) > while 1: > if not m.readline(): break > ------------------------------------------------------------------------ > > -- I've come across this in C, now that I'm forced to work under XP (Thank you, Cygwin!) Open the file 'rb' or 'r+b' and you avoid the entire issue of newlines. From modify Mon Aug 2 21:39:46 2004 From: modify (Richard Hilburger) Date: Mon, 2 Aug 2004 18:39:46 -0700 Subject: flowcharting is automatic for Python via preprocessor References: Message-ID: As I read your comments, I found myself agreeing with each point. I feel that your analysis is quite good. I get the drift of your example at http://oregonstate.edu/~barnesc/temp/flow.pdf Well done. My detailed flow diagram is indeed "visually busy". After all, it shows every path leaving no room for misinterpretation. Your diagram method is like a shorthand version of my diagram method. Cleaner in appearance, but requiring more skill and experience to read it correctly. A tool such as the preprocessor I developed could easily have either a command-line flag or a user setting to let the user choose either detailed or less-detailed flow diagrams. Integration into a code editor is indeed a worthy goal, and if done well would very likely improve the appeal of any such methodology. I had thought of it, but decided to take an easier approach to test the water first. Do other editors do this? I don't know what is out there. Neil posted: http://www.eng.auburn.edu/grasp/index.html and I'll have to take a closer look at that. At first glance, it looks confusing and unappealing. wrote in message news:mailman.1069.1091487166.5135.python-list at python.org... > > I like your idea. > > It is easy to get lost inside in eg a multiply nested if statement in a couple > multiply nested for loops, inside a try block. > > Sometimes one can split such code into separate functions, and this makes the > code cleaner. Sometimes not. > > However, the real issue is how the eye parses code. > > It's really inefficient to scan a whole page of code line by line to understand > where loops, branches, continues, and breaks occur. > > I think your visual diagrams could help, if they are: > > 1. Semantically cleaner. > IMO, there is too much detail in the flow diagrams. > (See http://www.getcet.org/images/ex3.png). > > A minimal amount of detail is easier to parse with the eye. > > See http://oregonstate.edu/~barnesc/temp/flow.pdf for a cleaner > example I came up with. This doesn't have arrows all over the > place (and hence may not be a flow diagram), but it does help > point out the relevant control structures. > > 2. Integrated into a code editor. > > I could see this being a new code editor fad, like collapsable > functions and classes. > > It could be quite useful, if the amount of visual information > is kept minimal, so that the coder is not distracted during > coding. > > If the flow diagrams are not integrated into an editor, I don't > think many coders will use them. > > Perhaps editors already do this. > > - Connelly From martindemello at yahoo.com Wed Aug 25 06:27:51 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Wed, 25 Aug 2004 10:27:51 GMT Subject: Why return None? References: Message-ID: Anthony Baxter wrote: > On Wed, 25 Aug 2004 08:26:26 GMT, Martin DeMello > wrote: > > It seems to be a fairly common pattern for an object-modifying method to > > return None - however, this is often quite inconvenient. > > list.reverse() modifies the list in place. The python idiom is that > these don't return a reference to the modified list. Although note the Yes, but why? I mean, is there either an advantage to returning None or some inherent danger in returning self? martin From newsgroups at jhrothjr.com Wed Aug 11 08:38:38 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Wed, 11 Aug 2004 08:38:38 -0400 Subject: Executing bytecode from a string. References: Message-ID: <10hk4q68cie6815@news.supernews.com> "Benjamin Scherrey" wrote in message news:pan.2004.08.11.07.18.32.690395 at proteus-tech.com... > I'm curious as to how difficult it would be to take a string that contains > compiled bytecode, load it into memory, give it a function name then > execute that function. I'm thinking of a database that contains compiled > objects that I can load and execute. I'm also curious as to what level of > grainularity this would work - module, class, class method, function? > Anyone tried to do this before? Obviously dependencies are a consideration > but I'm more interested in the mechanics of this. Appreciate ideas & > pointers you might have... > > Ben Scherrey Look at the 'new' module. It's in the Library Reference under Python Runtime Services. You'll need to wrap the byte string with 'code', and then wrap that with 'function'. As someone else pointed out, there are a number of other parameters you'll need to supply, and some of them aren't at all obvious. You may find the disassembler (documented under Python language services) to be helpful in figuring some of them out. John Roth From irmen at -nospam-remove-this-xs4all.nl Thu Aug 5 08:06:47 2004 From: irmen at -nospam-remove-this-xs4all.nl (Irmen de Jong) Date: Thu, 05 Aug 2004 14:06:47 +0200 Subject: Scope Problem In-Reply-To: References: Message-ID: <411222d7$0$65124$e4fe514c@news.xs4all.nl> Nickolay Kolev wrote: > I have however encountered a strange (for me anyway) scoping problem. This has nothing to do with scoping. > Here is my implementation of linear search as a method in a class, hence > all the self's (self.sequence is the sorted sequence we are searching in > and value is, well, the value we are searching for): > > def linearSearch(self, value, index = None): > > if not index: > index = 0 > try: > if self.sequence[index] == value: > return index > else: > self.linearSearch(value, index + 1) In this line, you don't return a value from the recursive call. Change it to: return self.linearSearch(value, index + 1) > except IndexError: > return -1 The algorithm should now work, although it is very inefficient. Now, you're learning Python, so it's probably good to point out that a containment test is usually done like so: if value in sequence: ... If you want to have the index: idx = sequence.index(value) And for quick (much quicker than linear) search in a sorted sequence, have a look at the bisect module etc: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/54159 Good luck! --Irmen From no-mail-please at nospam.com Mon Aug 30 17:10:20 2004 From: no-mail-please at nospam.com (Robert Oschler) Date: Mon, 30 Aug 2004 17:10:20 -0400 Subject: Upgrading to 2.3 from 2.2, questions Message-ID: Hello, (Note: if there is a FAQ that covers this issue just give me the URL. I checked python.org's General and Windows FAQ's and didn't see anything.) I am about to upgrade from Python 2.2 to 2.3. Here are a few questions: - Do I need to uninstall 2.2 first? - Are there any paths I should add to my Win 2k PATH environment variable? - I am running on Windows 2000 and I have several site-packages installed. These were installed using individual one-click installation programs (thank you module writers). Do I need to rerun each of the installations again, after I upgrade? Or, is there a directory or two I can simply copy over? - Anything I should do before upgrading to preserve my current setup, or other caveats? Thanks. From walter at livinglogic.de Mon Aug 9 15:47:40 2004 From: walter at livinglogic.de (=?ISO-8859-15?Q?Walter_D=F6rwald?=) Date: Mon, 09 Aug 2004 21:47:40 +0200 Subject: Parsing broken HTML via Mozilla Message-ID: <4117D4DC.1030503@livinglogic.de> Hello all! I'm trying to parse broken HTML with several Python tools. Unfortunately none of them work 100% reliable. Problems are e.g. nested comments, bare "&" in URLs and "<" in text (e.g. "if foo < bar") etc. All of these pages can be displayed properly in a browser so why not reuse the parser in e.g. Mozilla? Is there any way to get proper XML out of Mozilla? Calling mozilla on the command line would be OK, but it would be better if I could use Mozilla like a SAX parser. Is there any project that provides this functionality? Bye, Walter D?rwald From abra9823 at mail.usyd.edu.au Fri Aug 27 02:41:06 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Fri, 27 Aug 2004 16:41:06 +1000 Subject: print question - character representation Message-ID: <1093588866.412ed78296d19@www-mail.usyd.edu.au> hi! i am calculating a digest of some data (using hmac) and printing it to a cookie. the problem is the hash may contain special characters. when these are printed they get converted to \ representation. later when i receive the cookie i recalculate the hmac and do a comparison which returns false because of the conversion when writing to a cookie q - how do i stop the conversion from happening? if i cant then how can i convert the hmac i recalculate on receiving the cookie to the same representation as the one printed thanks cheers ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From amk at amk.ca Thu Aug 5 10:29:26 2004 From: amk at amk.ca (A.M. Kuchling) Date: Thu, 05 Aug 2004 09:29:26 -0500 Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) References: <1646998998.20040804190026@MailBlocks.com> <10h34ivio5s2c21@news.supernews.com> <10h4c5iicgv7k74@news.supernews.com> Message-ID: On Thu, 5 Aug 2004 09:06:01 -0400, John Roth wrote: > That was basically my comment about ctypes. AMK's > blog entry referenced the ctype's documentation page, Heller's post (at http://mail.python.org/pipermail/python-dev/2004-June/045139.html) wasn't very informative, either; I assume ctypes needs to do 'func = something_or_other(func)' as PyObjC does currently. --amk From dave at pythonapocrypha.com Tue Aug 24 21:27:47 2004 From: dave at pythonapocrypha.com (Dave Brueck) Date: Tue, 24 Aug 2004 19:27:47 -0600 Subject: J2 0-2-6 is available In-Reply-To: References: <3A81C87DC164034AA4E2DDFE11D258E3022E52@exchange.hqamor.amorhq.net> Message-ID: <412BEB13.9050205@pythonapocrypha.com> Neil Hodgson wrote: > I'd like to dissent on "using". To me, this code does not read well. > > using: > classmethod > def foo(cls): > pass > > foo *is* a class method, it is not *using* a class method. I hadn't thought of it that way before - as 'foo' the one doing the using. Instead I read it as the programmer/language is using the decorators in the process of defining foo - they're sort of tools being used in the construction of the method. I'm +0 on 'using' as the keyword and -1 on most of the alternates. :) -Dave From mwh at python.net Tue Aug 17 12:50:36 2004 From: mwh at python.net (Michael Hudson) Date: Tue, 17 Aug 2004 16:50:36 GMT Subject: Flython References: Message-ID: Christopher T King writes: > On Mon, 16 Aug 2004, Michael Hudson wrote: > > > Christopher T King writes: > > > > > (Unfortunately, AST trees don't match up exactly with Python grammar, so > > > I'm having to learn the format by trial-and-error. Not much fun. Is > > > there documentation on the AST forms anywhere?) > > > > Which AST are you talking about? > > Whatever is spit out by parser.suite(). Ah. This isn't, in any sense, an ABSTRACT syntax tree, despite what bits and pieces of the documentation say, or at least used to say. You'll almost certainly have a better time using the output of Lib/compiler/transformer.py. > Things like grammar.txt's "statement" being represented symbol.stmt, > and grammar.txt's stmt_list not existing at all in the AST trees > (though most/all of the other _lists exist). As Terry said, grammar.txt is documentation only... > > Which version of Python, etc? > > 2.3. I'm using http://docs.python.org/ref/grammar.txt as my grammar > reference. Grammar/Grammar in the source is much more accurate, but really, you want to use compiler.transformer. compiler.transformer spits out classes defined in compiler.ast, which *claims* to be autogenerated from Tools/compiler/ast.txt, but I'm not sure if that's actually the case any more. Even without documentation, they are easier to work out than the raw output of the parser module. Cheers, mwh -- "Also, does the simple algorithm you used in Cyclops have a name?" "Not officially, but it answers to "hey, dumb-ass!" -- Neil Schemenauer and Tim Peters, 23 Feb 2001 From me at privacy.net Wed Aug 18 13:20:21 2004 From: me at privacy.net (Dan Sommers) Date: 18 Aug 2004 13:20:21 -0400 Subject: PEP 318: Can't we all just get along? References: Message-ID: On Wed, 18 Aug 2004 08:35:21 -0400, Paul Morrow wrote: > Dan Sommers wrote: >> In the face of ambiguity, refuse to guess. >> Explicit is better than implicit. > Good conventions prevent ambiguity. > class Foo: > def method1(self, a, b): pass # clearly an instance method > def method2(cls, a, b): pass # clearly a class method > def method3(a, b): pass # clearly a static method class Bar: def method4( _, b ): pass # clearly a method def method5( klass, b ): pass # clearly something else def method6( uovo, b ): pass # clearly an Italian program(mer) > When declarations conflict with conventions, it makes us wonder what > the author really intended. I agree completely. I have often noted that when a comment doesn't match the code, they are *both* wrong. If we wonder what the author intended, what should Python do? >> >> I think that the idea that started this thread is just right: >> > You're right, this thread is about decorators, not about more > opportunities for dynamic typing. I just wanted to remind us that > decorators are a lot like static typing, which isn't terribly > pythonic. I readily admit that my background is static typing: BASIC, FORTRAN, assembly, C, etc.; my (arguably na?ve) lisp and Python programs are devoid of most of the dynamic typing I see here on c.l.p. OTOH, does anyone want/need "dynamic decorators"? Is there a real use case for code like this? class C: def m( self ): pass m = decorate( m ) decorate = some_function c1 = C( ) decorate = another_function c2 = C( ) Regards, Dan -- Dan Sommers Never play leapfrog with a unicorn. From peufeu at free.fr Wed Aug 25 04:50:38 2004 From: peufeu at free.fr (=?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?=) Date: Wed, 25 Aug 2004 10:50:38 +0200 Subject: How big can a Python program be? References: <903b3fba.0408170333.49ce3944@posting.google.com> <903b3fba.0408180655.6a23aede@posting.google.com> Message-ID: Simple answer : If you don't do it in Python, it'll be twice as big. Think about the size of Python's library. What kind of projetc is it ? > Several of us have experience working with Python projects > which occupy hundreds of thousands of lines. From justin__devine at hotmail.com Tue Aug 10 10:42:57 2004 From: justin__devine at hotmail.com (JDevine) Date: 10 Aug 2004 07:42:57 -0700 Subject: Thread for a newbie Message-ID: Hi. I have just finished my first python program. Unfortunately threading has me stumped. I think this is mostly because the wx.thread example demo is very complex, with all the grahphics, graphs, and draw functions. I want to do something very simple. My program downloads files over HTTP, I want to instantiate a process dialog that tracks the download. I already have access to the expected size of each file through other functions in my program, I also assume an os.foo is capable of getting the current size as the file grows as it is downloaded. My issue is keeping the file downloading WHILE it is being tracked by the process dialog. Please help with any simple thread examples you might have, if this example includes a dialog even better. Thanks for any help you can provide. -Justin Justin__Devine at hotmail.com thanks From ptmcg at austin.rr._bogus_.com Fri Aug 13 11:03:28 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 13 Aug 2004 15:03:28 GMT Subject: Idea for alternative use for @ Message-ID: <4L4Tc.6967$nu2.3787@fe2.texas.rr.com> I was just reading over Mark Lutz's excellent article on OnLamp, titled "When Pythons Attack - Common Mistakes of Python Programmers" (http://www.onlamp.com/pub/a/python/2004/02/05/learn_python.html). One of the common pitfalls he cites is the mixing of spaces and tabs, and how this is not always reliable since tabs can be handled differently in different platforms and editors. I thought it might be useful to include some sort of compiler directive like a C++ pragma to represent this kind of compile-time meta information. And it struck me that '@' would be an excellent marker for such a statement, something like: @tabsize 8 It clearly marks the statement as some sort of non-Python information. It could be used for any number of compiler information items, such as module include paths, macro definitions, debug levels, command switches, version limitations (@min_version 2.3.4). I guess this still does not address the conflict with tools such as Leo that already use '@' for internal code markup purposes, tho. I know '$' is also available, but '@' just looks better to me for this purpose. -- Paul Vote for J2. Keep Python Beautiful. From mwh at python.net Thu Aug 12 07:08:59 2004 From: mwh at python.net (Michael Hudson) Date: Thu, 12 Aug 2004 11:08:59 GMT Subject: ImportError: dynamic module does not define init function(initmymodule) References: <494182a9.0408111511.687d6371@posting.google.com> Message-ID: balaji at email.arizona.edu (Balaji) writes: > I have an c++ header file. > > //some_class.h > > #ifndef _SOME_CLASS_H_ > #define _SOME_CLASS_H_ > > class SomeClass > { > public: > int sqr(int a); > }; > #endif //_SOME_CLASS_H_ > > and I have an definition file some_class.C > > //some_class.C > > #include "some_class.h" > > > int SomeClass::sqr(int a){ > return a*a; > } > And I have an interface file > %module mytest > %{ > #include "some_class.h" > } > %include "some_class.h" > > My question is when I try to import mytest in python it does import it > but I'm not able to access the SomeClass.. Does SWIG expect to be compiled using a C++ compiler (I don't know). I suspect you're falling victim to C++ name mangling, but I don't know enough about SWIG to tell you what to try instead. Cheers, mwh -- Programming languages should be designed not by piling feature on top of feature, but by removing the weaknesses and restrictions that make the additional features appear necessary. -- Revised(5) Report on the Algorithmic Language Scheme From john.burton at jbmail.com Thu Aug 19 18:44:10 2004 From: john.burton at jbmail.com (John Burton) Date: Thu, 19 Aug 2004 23:44:10 +0100 Subject: ANN: pyxe In-Reply-To: References: Message-ID: <41252d3a$0$58821$5a6aecb4@news.aaisp.net.uk> Simon John wrote: > Leave the .py off the end: > > pyxe /BUILD hello > Ah! That fixed it. From anthonybaxter at gmail.com Tue Aug 24 00:14:49 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Tue, 24 Aug 2004 14:14:49 +1000 Subject: On consensus decision-making (was Re: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WEDONE?) In-Reply-To: References: Message-ID: On Mon, 23 Aug 2004 15:13:15 -0400, Peter Hansen wrote: > Anyway, I suppose this means that the selection will be from > amongst A1, C1, and J2, each with an implementation, each with > a sizable number of proponents. Wish the man well. ;-) As I've posted a couple of times, the C1 implementation is old, and is not complete. There's a lot more work to be done on it to make sure that it covers anything. I've still seen no-one put up their hand to offer to finish it, which is a shame. From maxm at mxm.dk Mon Aug 30 07:00:14 2004 From: maxm at mxm.dk (Max M) Date: Mon, 30 Aug 2004 13:00:14 +0200 Subject: play a midi file from the interpreter? In-Reply-To: References: <95tYc.261224$J06.123492@pd7tw2no> <4132CFE1.20004@mxm.dk> Message-ID: <4133086d$0$299$edfadb0f@dread12.news.tele.dk> Elaine Jackson wrote: > Could you sketch me a useage example? I'm finding the documentation extremely > sparse. I've heard of 'pipes', but I don't actually know what they are. Basically you just pass popen a string that looks like one typed at the command prompt: # untested # (Eg. I don't know the name of your midi file player # so I call it playmidifile.exe) import os midifilename = 'c:/path/to/midifile.mid' result = os.popen('playmidifile.exe %s' % midifilename) print result From timh at zute.net Thu Aug 26 10:54:33 2004 From: timh at zute.net (Tim Hoffman) Date: Thu, 26 Aug 2004 22:54:33 +0800 Subject: Call for signatories for J2 In-Reply-To: References: Message-ID: <412df9ae$1@news.highway1.com.au> Big plus one from me for J2 over @ syntax Rgds Tim Hoffman From hoang at jotsite.com Wed Aug 18 16:17:13 2004 From: hoang at jotsite.com (Hoang Do) Date: Wed, 18 Aug 2004 20:17:13 GMT Subject: IronPython and collections access Message-ID: I have been able to access global functions and objects with IronPython. However the following attempt to access collections bombs: import System x = System.Collections.BitArray(4) x[0] The error message is: 'System.Collections.BitArray' object has no attribute '__getitem__'. This is the same error with any classes derived from CollectionsBase. Has anyone been able to access a collection successfully? Hoang Do http://jotsite.com From amk at amk.ca Wed Aug 4 02:58:55 2004 From: amk at amk.ca (A.M. Kuchling) Date: Wed, 04 Aug 2004 01:58:55 -0500 Subject: Quixote demo References: <5b42ae4.0407301634.2e72a8f8@posting.google.com> <5b42ae4.0407311512.b9928f6@posting.google.com> <5b42ae4.0408010341.76555c1@posting.google.com> Message-ID: <8o-dnda_obOyFI3cRVn-jQ@speakeasy.net> On 1 Aug 2004 04:41:49 -0700, Ernie wrote: > quixote, spyce, snakelets, webware, zope, twisted, etc? You don't > have to think or learn more than "one obvious way to do it" in Java or > PHP. When Pythonistas claim Python is indeed better for writing web Java is no simpler; http://www.manageability.org/blog/stuff/how-many-java-web-frameworks/view lists 54 different web frameworks for Java. PHP includes web processing as part of the core, yet googling for "PHP web framework" also turns up multiple projects. The claim that other languages are more unified than Python is not necessarily true. --amk From aahz at pythoncraft.com Wed Aug 18 10:35:12 2004 From: aahz at pythoncraft.com (Aahz) Date: 18 Aug 2004 10:35:12 -0400 Subject: PEP 318: Can't we all just get along? References: <20040817181725194-0400@braeburn.themorgue.org> Message-ID: In article <20040817181725194-0400 at braeburn.themorgue.org>, Kevin Smith wrote: > >Bear with me, but I'd like to propose one more syntax that is simple, >easy for newbies to understand, and nowhere near as powerful as the >current PEP's syntax. However, it doesn't add incoherent, arbitrary >syntax either. > >def classmethod foo(x, y, z): > pass You can't do ``grep "def foo"``; therefore, Guido rejected this. (It's a tiny bit more complicated than that, but that's the essence.) -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From squirrel at WPI.EDU Thu Aug 5 10:06:39 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 5 Aug 2004 10:06:39 -0400 Subject: Can decorator syntax do this ? (annotated results' names) In-Reply-To: References: Message-ID: On Thu, 5 Aug 2004, Sakesun Roykiattisak wrote: > I stopped follow decorator-syntax discussion for a while, because it > seems everlasting. > But now look like it's settle, so I wonder how far can I go with this > new feature ? Oh, you don't know how wrong you are ;) All Guido's allowance of the @ syntax into 2.4a2 did was reignite debate, with no end in sight (unless he pushes it through to 2.4 final, something I sincerely hope he doesn't). If I were you, I'd hold off on using decorators until they're in a stable branch, since there's a good chance they might disappear in 2.4a3. To answer your question, decorators allow for pretty much anything you can define a function to do; the code in your example will work, provided you provide a suitable definition for resultnames(): it must return a function that accepts a function and returns a (mangled version of that) function. From cemerick at snowtide.com Fri Aug 20 15:37:32 2004 From: cemerick at snowtide.com (Chas Emerick) Date: Fri, 20 Aug 2004 15:37:32 -0400 Subject: Fate of lambda, Functional Programming in Python... In-Reply-To: <20040820190538.4675C1E4003@bag.python.org> References: <20040820190538.4675C1E4003@bag.python.org> Message-ID: <6164B6FC-F2E0-11D8-97D4-000A95B336F2@snowtide.com> On Aug 20, 2004, at 3:05 PM, python-list-request at python.org wrote: > Nobody is talking about removing the ability to pass functions, just > the actual "lambda" form. > > You can still build a GUI by doing > > def spam(stuff): > def eggs(parrot): > return 5+parrot > return eggs > > You just can't do > > def spam(stuff): > return lambda foo: 5+parrot > > > I can't think of a situation where you _really_ need the second (and > much more limited) form. Well, there's a couple issues here. First, I'd rather see the ability to do a multiline lambda form. I'm still not clear on why that wasn't dropped in from the start. But even given the way things are now, lambdas are not just a slight reordering of syntax -- they're sometimes the only way to get things done quickly and cleanly. Especially in UI's and in certain simulation environments, being able to build up a function table of super-simple functions mapped to particular environment parameters is critical. Having to explicitly define these sorts of things is a huge pain. A good corollary to python lambdas seems to be anonymous classes in Java, especially in a Swing application (the ugly, very gimpy cousin of the lambda). If anonymous classes weren't available in Java, Swing would be even worse than it is already; python without lambdas would be a huge loss to the language IMO. And finally, with respect to the spirit of your final comment: just because you don't __need__ a more concise, clearer, and easier-to-use form doesn't mean that that form has no use, or that switching to a 'lesser' approach (at least within a restricted usage context) has no costs associated with it. I did find something about GvM's stance towards lambdas and FP in general, from http://www.amk.ca/python/writing/gvr-interview.html: > Sometimes I've been too quick in accepting contributions, and later > realized that it was a mistake. One example would be some of the > functional programming features, such as lambda functions. lambda is a > keyword that lets you create a small anonymous function; built-in > functions such as map, filter, and reduce run a function over a > sequence type, such as a list. > > In practice, it didn't turn out that well. Python only has two scopes: > local and global. This makes writing lambda functions painful, because > you often want to access variables in the scope where the lambda was > defined, but you can't because of the two scopes. There's a way around > this, but it's something of a kludge. Often it seems much easier in > Python to just use a for loop instead of messing around with lambda > functions. map and friends work well only when there's already a > built-in function that does what you want. This is really funny to me, because it seems like Guido is saying, essentially, "Python doesn't have proper closures, therefore lambdas form a temptation that can't really be fulfilled right now, therefore [given the current rumormill] we should get rid of lambdas." I suppose it would be silly to ask why the premise of this line of thought shouldn't be changed, instead of throwing the baby out with the bathwater. There's been plenty of discussions about closures and python, so I suppose there's no need to kill that topic again. -- Chas Emerick From darcykahle at sympatico.ca Fri Aug 6 19:39:34 2004 From: darcykahle at sympatico.ca (Darcy Kahle) Date: Fri, 06 Aug 2004 19:39:34 -0400 Subject: Advanced printing using win32ui in python - help! Message-ID: I am trying to do some advanced printing in python using the win32ui module, and have run into an issue. I need to print a page landscape. As I could not determine how to specify the orientation of the printing, I arranged the graphic elements on the page the way it should be. When I got to printing text, it went across the page, not down as I need it to go. I tried to use the hDC.SetWorldTransform(0, -1, 1, 0, 0, 0) command to rotate the print counterclockwise 90 degrees, but this command was virtually ignored. The other solution that I can see involves specifying that the page is in landscape mode, but as I indicated earlier, I cannot determine how to accomplish this. The command win32ui.CreatePrintDialog(1538).DoModal() presents the dialog where the user can specify landscape mode, but it appears that the OK button is not hooked up to a default callback. There is a PyCPrintInfo object, which it looks like I can set this programmatically, and then generate the printerDC object, but there is no documentation on how to generate this. Can anyone recommend to me how I could either specify the page to be in landscape mode, or rotate the text that is printing? Any assistance that you can provide is greatly appreciated, and I am certain that there are others out there that want to know how to do this as well. BTW, I am currently using WinXP and Python 2.3, but the solution should be accessible via Win98 and up. I plan to use py2exe to run the final product on other windows boxes. From ellisjb at my-deja.com Thu Aug 5 18:18:37 2004 From: ellisjb at my-deja.com (ellisjb at my-deja.com) Date: 5 Aug 2004 15:18:37 -0700 Subject: Quixote vs. Preppy In-Reply-To: Message-ID: A.M. Kuchling wrote: > On Thu, 5 Aug 2004 10:55:19 -0600, > Bruce Eckel wrote: > > programmer"), but someone also suggested Preppy from Reportlabs: > > http://www.reportlab.org/preppy.html > > Preppy looks like a templating library, not an arbitrary web framework Incidently, http://www.colorstudy.com/docs/shootout.html looks like a good summary of the major Python web frameworks. Unfortunately, it's not dated... anyone know? -Jonathan From roy at panix.com Thu Aug 12 12:33:50 2004 From: roy at panix.com (Roy Smith) Date: Thu, 12 Aug 2004 12:33:50 -0400 Subject: PEP318 References: <20040812090056.00001e31@titan> <7ttmh0t8c3cogtbhhnp1ohqu8b51pda461@4ax.com> Message-ID: Arthur wrote: > I must say that after days of waffling, and I think an honest effort > to accept where things were going, I woke this morning hating > @decorator. > > The existing syntax for this kind of transformation is, in fact, > exactly what one would expect: > > foo=staticmathed(foo). > > That is the universal langauge for transformations. And when we try > to explain to anybody what it is that @decorator means, we go back to > the pseudo code that is in fact the existing syntax. I'm with Arthur. I think the core problem is that the def statement is kind of wierd. It does two different things. First, it creates a function body, then it binds the function to a name. One of the objections to: def foo (): whatever foo = decorator (foo) is that you have to type the word "foo" three times. It's not so much the effort of repeating the keystrokes, but the fact that it feels so unfactored. The only reason you need to do this is because you have no way of getting at the newly-generated function (what CS types would call a "lambda form") before it's bound to the name. A solution to that is to factor out the function definition from the name binding, so you would do something like: foo = def (): whatever although by the time you do that, you might as well have just gotten rid of def and used lambda() directly. If you wanted it to be a static/class method, you would do: foo = staticmethod_def (): whatever The other big objection to the current syntax is that it puts the wrapper way down at the bottom of the function body, away from the name. The above syntax solves that too. The big problem with the above is that it changes the semantics of the def statement in a way which is incompatible with current usage, and thus I would expect it's a complete non-starter. Not to mention inventing new keywords. On the other hand, doing: def (staticmethod) foo (): whatever (you can pick whatever bits of punctuation turn you on) seems like it should work just fine. I think it achieves all the goals: 1) It puts the decorator before the function body. 2) It keeps the decorator right next to the function name. 3) It doesn't re-define any currently valid syntax. 4) It looks enough like current Python syntax that most add-on tools should handle it just fine. 5) If you've got lots of decorators (I'm still not sure if people really think this will happen in real life), it's easy enough to break it up into multiple lines: def @decorator1 \ @decorator2 \ @decorator3 foo (a, b, c): print a, b, c but I'm assuming that will be the exception, just like really long argument lists are the exception. Define the order of application of multiple decorators in whichever way floats your boat; I'm guessing outside-in (i.e. the last one gets done first) makes the most sense. I suppose you could take this one step further and put the decorators inside ()'s, so you'd have any of (as auto-indented by emacs): def (decorator) foo (a, b, c): pass def (decorator1, decorator2, decorator3) foo (a, b, c): pass def (decorator1, decorator2, decorator3) foo (a, b, c): pass def (decorator1, decorator2, decorator3) foo (a, b, c): pass with the last example being a bit ugly, but at least it seems to follow the expected indenting rules. In any case, you'd only have to resort to something like that if you had lots of decorators and lots of arguments, and in that case, I suspect you might want to be refactoring things to simplify it all anyway. I haven't done an exhaustive search of all the proposed syntaxen which have come flying by here in the past week or so. My apologies if I've accidentally duplicated somebody else's work here. In retrospect (this has been written in dribs and drabs over the past several hours, as I've been called away repeatedly to do real work), I see I started out by agreeing with Arthur that the current (i.e. pre PEP-318) way of doing things is good enough, then managed to head off into a different direction and suggest YADS (Yet Another Decorator Syntax). Oh, well. I'm also not at all convinced that using decorators for things like doc strings makes any sense at all. It's just the wrong tool. Docstrings work just fine the way they are. If it ain't broke, don't fix it. Which I guess brings me full-circle back to agreeing with Arthur :-) From db3l at fitlinxx.com Wed Aug 18 18:12:14 2004 From: db3l at fitlinxx.com (David Bolen) Date: 18 Aug 2004 18:12:14 -0400 Subject: Calling __init__ for all mixins References: Message-ID: Martin Maney writes: > I've been to the cookbook (both forms, since they're sometimes usefully > different), but that gave rise to more questions than answers. Heck, > let me pull some of them up while I'm at it. > > Martelli gives the recipie (5.3 on paper) "Calling a Superclass > __init__ Method if it Exists" where he seems to say that this: > > class NewStyleOnly(A, B, C): > def __init__(self): > super(NewStyleOnly, self).__init__() > > is the New Class Speak equivalent of > > class Classic(A, B, C): > def __init__(self): > for base in self.__class__.__bases__: > if hasattr(base, '__init__'): > base.__init__(self) > > but when I tried a simple test case (base classes just print a tracer > when called), Martelli's NewStyleOnly only invoked A.__init__, as it > was the first base class in the base list as written with an __init__ > implemented. These seem to me to be very different. Can you show your test code. I've found that you may need to ensure all of your classes are cooperating in their use of super(), as in the following: mro.py: class A(object): def __init__(self): print "A init" super(A,self).__init__() class B(object): def __init__(self): print "B init" super(B,self).__init__() class C(object): def __init__(self): print "C init" super(C,self).__init__() class Mix(A,B,C): def __init__(self): print "Mix init" super(Mix,self).__init__() Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import mro >>> mro.Mix() Mix init A init B init C init >>> The new style MRO approach will only work if all of your objects are new style classes and they all participate in the cooperative process through the use of super(). Also, the precise MRO used has changed between 2.2 and 2.3 but it shouldn't affect the above syntax. I do think it's easy to find yourself skipping the call to object's __init__ in classes since it doesn't necessarily do anything, but it's those other super calls that provide the chance to iterate through the inheritance hierarchy based on the initial call from the ultimate subclass. Guido has some info on the cooperative use of super in his 2.2 unification draft available at http://www.python.org/2.2.3/descrintro.html and more info on the MRO change is at http://www.python.org/2.3/mro.html. -- David From dave at pythonapocrypha.com Mon Aug 30 16:50:22 2004 From: dave at pythonapocrypha.com (Dave Brueck) Date: Mon, 30 Aug 2004 14:50:22 -0600 Subject: Enumerating Network Adapters In-Reply-To: <9418be08.0408301226.354c337a@posting.google.com> References: <4131b09e$0$13683$636a15ce@news.free.fr> <413257dd$0$26986$626a14ce@news.free.fr> <4qmkheha.fsf@python.net> <9418be08.0408301226.354c337a@posting.google.com> Message-ID: <4133930E.8090108@pythonapocrypha.com> Elbert Lev wrote: >>>It returned the least useful of my 3 IP addresses - my loopback >>>adapter - but didn't return my LAN and wireless IPs. > > > Interesting! I have Python installed on 10 W2K servers and I'm using > the same construct to get addresses. Works fine for me. WinXP Pro here - I wonder if that's the difference. -Dave From http Thu Aug 26 18:08:27 2004 From: http (Paul Rubin) Date: 26 Aug 2004 15:08:27 -0700 Subject: Call for signatories for J2 References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> <7xhdqp967k.fsf@ruckus.brouhaha.com> <412e3ba4$0$92817$ed2619ec@ptn-nntp-reader02.plus.net> <7xk6vloc3j.fsf@ruckus.brouhaha.com> <412e556a$0$93997$ed2e19e4@ptn-nntp-reader04.plus.net> Message-ID: <7xvff5o8mc.fsf@ruckus.brouhaha.com> Michael Sparks writes: > * Decorators incorporated via the __future__ mechanism > * A subset of people use them in earnest > * It's found that it would be useful to change the syntax whilst it's > still in the experimental __future__ phase. (As might've happened but > didn't with yield and generators) I thought __future__ isn't for experimental features, but rather, it's for definitely-accepted features that potentially break existing code, for example by adding new keywords or changing the meaning of something (the / division operator). The idea is for a release or two of the interpreter to signal a warning when an old program uses the new keyword. From olli at haluter.fromme.com Thu Aug 19 12:12:25 2004 From: olli at haluter.fromme.com (Oliver Fromme) Date: 19 Aug 2004 16:12:25 GMT Subject: speed References: Message-ID: <2ok1r9FbfebaU1@uni-berlin.de> Peter Kleiweg wrote: > I implemented a lexer in Pylly and compared it to the version I > had written in Flex. Processing 219062 lines took 0.9 seconds in > C (from Flex), and 5 minutes 54 second in Python (from Pylly), a > ratio of 393 to 1. > > Is this normal for Python, or does Flex produce better parsers > than Pylly? I have been looking at the code produced by Flex to > see if I could translate it to Python automaticly. But it has a > lot of goto statements, and I haven't figured out how to > translate those to Python efficiently. > > What are the average times used for text processing of Python > compared to C? I don't know Pylly, but I guess it generates a parser using a finite automaton -- just like lex/flex, except it handles every single character in Python, wheres lex/flex will lead to compiled C code. That would explain the speed difference. When I have to parse something in Python, I try to do that using things like string.split(), string.find(), the "re" module etc. Those things are written in C, therefore they are fast enough for most applications. There are also some modules for specialized cases, such as "ConfigParser" and "shlex". See the Python Library Reference. Best regards Oliver -- Oliver Fromme, Konrad-Celtis-Str. 72, 81369 Munich, Germany ``All that we see or seem is just a dream within a dream.'' (E. A. Poe) From bac at OCF.Berkeley.EDU Wed Aug 25 18:32:07 2004 From: bac at OCF.Berkeley.EDU (Brett Cannon) Date: Wed, 25 Aug 2004 15:32:07 -0700 Subject: python-dev Summary for 2004-08-01 through 2004-08-15 In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022E75@exchange.hqamor.amorhq.net> References: <3A81C87DC164034AA4E2DDFE11D258E3022E75@exchange.hqamor.amorhq.net> Message-ID: <412D1367.3060100@ocf.berkeley.edu> Robert Brewer wrote: > Brett C. wrote: > >>I just don't want people to suddenly get the impression that they can >>always just throw a little mutiny every time Guido makes a decision. >>Do that and he will just ignore what people want period and never even >>give people a chance to propose an alternative once it reaches >>python-dev. > > > Well said. > Thanks. Just glad I am not the only one who thought that. > >>And I want people to realize my tirade was just that, a personal >>tirade. It was out of frustration and thus should be taken with a >>grain of salt. > > > But that frustration is grounded in reality. > I thought so, but then people started to question whether I overstepped some bound or something. > >>And that frustration came from the feeling that the Python community, >>which I love, seemed to suddenly form a mob, grab pitchforks and >>torches, and started screaming. And then they seemed to hold a public >>meeting with *everyone* proposing their idea and not completely >>listening to initial decisions. > > > I attribute the breakdown-of-process to scale issues, and not much else. > The decorator debate had: > a) the largest body of dissenters I've ever seen for a new Python > feature, and > b) the largest volume of alternate proposals. > I would put it mostly in b) than a), but both are true. > Many new features have had a certain amount of tweaking to be done even > after Guido has pronounced. Each of these tweaks requires communication. > In the case of decorators, the volume of communication required was > simply too much for the medium of Usenet, which promotes short, > tangential discussions rather than systemic analysis. This is the > primary reason I felt a focused paper would benefit the process. > > One of my hopes is that, for large, complex community responses in the > future, someone else will do the same. This proposal sets a precedent > for those cases which overload the normal response process. However, it > should be made clear that _not every response warrants this format_. > That is basically the PEP process. And that is basically what you have written, Robert. That is a good route to go; a PEP that presents an alternative. Helps centralize information, makes a single person the main contact point to filter out background chatter, and solves world hunger. =) > In Brett's language, go ahead and hold "public meetings". But either > hire a Usenet police force or (much better) police yourselves--when the > debate begins to explode, form a task force and write a proposal or two. > I am *not* placing blame on anyone here, just pointing out that this is > the first time such a step was needed. We are all watching it play out > for the first time. Let's learn from it and apply those lessons next > time. > Totally agree. > Although I like J2, I'm not rabid about it (and despite the opinions of > the pundits, I do *not* have "too much free time"; far from it). People have been saying that? That's a shame. Just means you care enough to put the time into it. Anyone else could do what you are doing, you just happen to care. Not like any of us have loads of free time, we just make a decision on what to do with what little free time we do have. > I could > have written an equally-compelling paper on any of the alternatives. I > am far more dedicated to the "meta-outcome" of this proposal, that Guido > is presented with alternatives in a usable and effective fashion, than I > am in which option he selects. The "next level" of course, is whether > that goal is met and how to reproduce such a success (or avoid such a > failure) in the future. > And I personally thank you for it even if I prefer the '@' syntax. =) > >>I truly hope that next time Guido makes a decision that people as a >>whole disagree with everyone involved can get together and discuss it >>calmly without flooding my inbox. =) > > > Me too. This isn't a fundamentally hard problem, it simply happens to be > a management issue for a bunch of techies. Once in a while, Guido's > "cabinet" needs to manage people and process as much as it does source > code. As Python gains more of a following, this will occur more often. > But I don't want to play "Middle Management". =) But you are right. python-dev probably could have stood to put its collective foot down earlier about moving the discussion off-list. Live and learn. Trouble when we all don't work in the same room. -Brett From michele.simionato at gmail.com Thu Aug 26 03:12:08 2004 From: michele.simionato at gmail.com (Michele Simionato) Date: 26 Aug 2004 00:12:08 -0700 Subject: Call for signatories for J2 References: Message-ID: <4edc17eb.0408252312.745a6fea@posting.google.com> Uhm... the choice between @ and J2 is tough for me. "@" is somewhat less intrusive (I automatically ignore it, look at the function body and then go back at the decorator) whereas J2 focus too much the attention on the using clause. This is probably because it reminds me a try: except: block, where the attention is focused on the try: part. It is probably matter of time to get used to it. OTOH I think that J2 is more consistent with the rest of Python and it avoids the introduction of the pie sign which conflicts with Leo and IPython, so there are strong arguments in its favor. Conclusion: I would be happy both with "@" and J2 (or even with "|" instead of "@"). However, the work done by Robert Brewer and Micheal Sparks is impressive and deserve to be supported, so count me as a mild "FOR" ;) Michele Simionato From http Wed Aug 11 19:54:11 2004 From: http (Paul Rubin) Date: 11 Aug 2004 16:54:11 -0700 Subject: PyJack References: <6fd8df7e.0408111536.79369258@posting.google.com> Message-ID: <7xisbpmdss.fsf@ruckus.brouhaha.com> jumpthewall at gmail.com (Chris Patton) writes: > import whrandom, os Use random rather than whrandom. whrandom is obsolete and deprecated. If you're imagining a situation where players will bet real money on the hands dealt by this program, you have to get even more serious about the sources of randomness. > def scorer(score,playerdeck):... > while d < len(playerdeck): > if score > 10 and 'A' in playerdeck: > typevalues['A'] = 1 This is pretty ugly, changing the contents of what's conceptually a fixed table, depending on the player score. I think it's better to just score the hand with A=1, then count the aces and adjust the score accordingly. > while decksize < 52: > a = whrandom.randint(0,12) > if left[a] > 0: > left[a] = left[a] - 1 > deck.append(types[a]) > decksize = decksize + 1 > elif left[a] == 0: pass This is a horrendous method of shuffling the cards. When there's only one card left to deal, it will take several tries to find it. See the random.shuffle function for a direct way to shuffle. > humandeck = [] > while c <= 1: > humandeck.append(deck[0]) > del deck[0] > c = c + 1 > compdeck = [] > c = 0 > while c <= 1: > compdeck.append(deck[0]) > del deck[0] > c = c + 1 Move these to a function that deals one hand, and call it for the player and the computer. > score = 0 > compscore = 0 > stay = 0 > over = 0 > compstay = 0 > compover = 0 Maybe you want to think of using fewer variables, e.g. create class instances for the two players. Right now you only handle a two-player game (the human and the computer). What if you want to handle n players? From jbors at mail.ru Thu Aug 5 12:52:29 2004 From: jbors at mail.ru (Dmitry Borisov) Date: Thu, 05 Aug 2004 20:52:29 +0400 Subject: Need help on how to use Pymedia! In-Reply-To: Message-ID: > > Thank you for your help! > > "Lawrence Oluyede" wrote in message > news:3x8w4pqd3emo.15wp1jkrwkqua.dlg at 40tude.net... > > In data Thu, 05 Aug 2004 02:28:48 GMT, CptPicard ha scritto: > > > > > Could someone give me a more detailed documentation on pymedia or some > clues > > > on how to get the information I need ? > > > > AFAIK Pymedia cannot extract ID3 infos from MP3 (altough you can study by > > yourself the ID3 format a inspect the raw info of the file), anyway the > web > > is full of ID3 tools for python such as: > > http://id3-py.sourceforge.net/ Please use this mailing list to get support on pymedia: pymedia-users at lists.sourceforge.net It will make sure you get the quick response. The documentation is a little scarce at the moment and I'm working on the tutorial to compensate that. Here is the code which will give you what you need( from pycar ). It is modified to match what you need and therefore not tested.: f= open( , 'rb' ) dec= acodec.Decoder( ) s= f.read( 20000 ) fr= dec.decode( s ) # Hardcoding for mp3 IDv1 tags if not dec.hasHeader() and == 'mp3': f.seek( -128, 2 ) dec= acodec.Decoder( 'mp3' ) dec.decode( f.read( 128 ) ) print dec.getInfo() Hope this helps. Dmitry/ From brianc at temple.edu Fri Aug 13 09:08:25 2004 From: brianc at temple.edu (brianc at temple.edu) Date: Fri, 13 Aug 2004 09:08:25 -0400 Subject: !wtf ellipsis Message-ID: One thing I like to use it for is a dummy variable to pass into a loop. Say you want to find the lowest value in a list of numbers: l=[5,4,3,2,1] lowest_value=Ellipsis for i in l: if lowest_value > i: lowest_value=i Like a positive infinity. Though it would be nice to have a reciprocal negative infinity. -Brian ---- Original message ---- >Date: Fri, 13 Aug 2004 14:54:24 +0200 >From: Jonas K?lker >Subject: !wtf ellipsis >To: python-list at python.org > >so, I've read the manuals, done a few hacks, read the quick reference. >however, one thing still eludes me: > >what (the hell) is Ellipsis? >what's it good for? >how do I use it; how does the interpreter use it? > >... thanks everybody, > >Jonas K?lker > >---- >[ValueError: ASCII art sig block too ugly to live] > >-- >http://mail.python.org/mailman/listinfo/python-list From notarealaddress at notarealaddress.com Fri Aug 20 08:19:53 2004 From: notarealaddress at notarealaddress.com (djo) Date: Fri, 20 Aug 2004 08:19:53 -0400 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: J2 J2 L I like keywords instead of symbols. Although I've started thinking of the @ as "a" for "apply decorating function". I don't read python-dev, what that intentional? djo (lurker, using Python for image analysis software for electron microscopy) From peter at engcorp.com Mon Aug 23 15:15:53 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 23 Aug 2004 15:15:53 -0400 Subject: PEP318: radical notion In-Reply-To: References: Message-ID: Arien Malec wrote: > Apologies for feeding the fire, when we are rallying around a consensus, > but I've been concerned about the clash between syntax and semantics, and > I've finally reached a mini-epiphany: > > The problem with PEP318 is that it is too powerful, and tries to do too > much. It is a sledgehammer for attacking three problems: [snip] I believe your mini-epiphany has been reached by several other people in this forum and discussed at length, certainly not in exactly the same words but surely in a very similar form. If you've checked the archives and seen those discussions, but still feel you have something really original to contribute, I suggest contrasting your argument with those previous ones to demonstrate how it is different and worth further discussion at this point. If you don't, I expect many people will feel you are just rehashing something very late in the game and will mostly ignore your post. -Peter From siona at chiark.greenend.org.uk Tue Aug 24 09:33:44 2004 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 24 Aug 2004 14:33:44 +0100 (BST) Subject: 100 % portable ? References: Message-ID: <80k*UdTsq@news.chiark.greenend.org.uk> In article , Jorge Godoy wrote: >Sion Arrowsmith writes: >> I've got about 20,000 lines of >> application with six platform tests, five of which are to >> work around platform-specific infelicities in wx. >This sounds very interesting. > >Do any of you have those tests and workarounds publicly available? The tests are just a matter of checking sys.platform at the appropriate point -- since the target platforms ATM are only Windows and Linux a simple == "win32" or != "win32" depending on which requires special treatment (usually Linux/GTK) does the job. I really should stick at least some of this stuff on the wiki (http://wiki.wxpython.org/index.cgi/wxPython_20Platform_20Inconsistencies) -- for that matter, I should refine and bug-report the ones I haven't already. -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From martin at v.loewis.de Thu Aug 26 17:27:05 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 26 Aug 2004 23:27:05 +0200 Subject: What GCC version had defined? In-Reply-To: <412e39d1$1@nntp0.pdx.net> References: <412e39d1$1@nntp0.pdx.net> Message-ID: <412E55A9.9070400@v.loewis.de> Scott David Daniels wrote: > Does anyone know which version of GCC introduced stdint.h (and > thereby uintptr_t and intptr_t)? I'd like to get the conditionals > right. stdint.h is not part of GCC; it is part of libc6. You shouldn't do #ifdefs based on version numbers, but instead, you should do checks based on the features of the software, like autoconf does. Regards, Martin From tchur at optushome.com.au Sun Aug 22 00:49:05 2004 From: tchur at optushome.com.au (Tim Churches) Date: 22 Aug 2004 14:49:05 +1000 Subject: Python future performance and speed In-Reply-To: <7x4qmv6cwo.fsf@ruckus.brouhaha.com> References: <278de0e.0408211605.426e5129@posting.google.com> <7x4qmv6cwo.fsf@ruckus.brouhaha.com> Message-ID: <1093150145.1264.66.camel@emilio> On Sun, 2004-08-22 at 13:59, Paul Rubin wrote: > aahz at pythoncraft.com (Aahz) writes: > > >It seems there are quite a few projects aimed to improve Python's > > >speed and, therefore, eliminate its main limitation for mainstream > > >acceptance. > > > > What makes you think speed is Python's primary limitation for mainstream > > acceptance? > > Well, whenever I want to write a mainstream application and think of > using Python, my first reaction is that Python is too slow... As a population health epidemiologist whose stock-in-trade is manipulation and analysis of large health data sets, I have to say that Python's run-time speed is almost always much faster than I would have expected from such a dynamic language, but also almost always much slower than I would like, especially when compared to widely-used (but vastly expensive and sprawling) data manipulation environments such as SAS system (see http://www.sas.com) which is the "industry standard" in my particular field. However the speed of programme creation with Python is, in general, outstandingly swift, making it the environment of choice for one-off tasks. But for routinely-executed jobs which process large amounts of data, especially for jobs which can't be scheduled to run overnight, Python is much slower than I would like. Numpy is a godsend in situations in which it can be used, Psyco helps a lot, I am rapidly warming to Pyrex (if you'll pardon the pun), and I can't wait to try out Starkiller. But don't get me wrong: I love Python (which my better half refers to as "ang babaeng ahas" - the "snake woman" - who has firmly stolen my affections, or punningly, as "ang asawang sawa" - literally the "python spouse" but with connotations of "the clinging consort" - and I was recently much amused when a colleague revealed that she seriously, albeit momentarily, thought that her object-oriented, dynamic-language-phile programmer husband was having a torrid extra-marital affair when she discovered hundreds of email in his in-box referring to someone called Ruby). -- Tim C PGP/GnuPG Key 1024D/EAF993D0 available from keyservers everywhere or at http://members.optushome.com.au/tchur/pubkey.asc Key fingerprint = 8C22 BF76 33BA B3B5 1D5B EB37 7891 46A9 EAF9 93D0 From adurdin at gmail.com Sun Aug 8 22:44:12 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Mon, 9 Aug 2004 12:44:12 +1000 Subject: PEP-0318 In-Reply-To: References: <41122FC2.1080608@interlink.com.au> <4114152f@nntp.zianet.com> <4116bc20$1@nntp.zianet.com> Message-ID: <59e9fd3a0408081944410dd104@mail.gmail.com> On Mon, 9 Aug 2004 11:34:39 +1000, Anthony Baxter wrote: > > Guido has ruled out decorators at the top of function body, on the grounds > that it looks like something that would be executed as part of the function, > but isn't. FWIW, in the same thread he's noted that having docstrings where > they are is problematic in this respect. I honestly believe that having docstrings where they are is better than having them before the function signature; how many function-commenting standards have you seen where the function name is repeated in the first line of the comment so that you know what function is being talked about when you start reading the comment? The function signature should be first, and everything else to do with it following. What might be a better general solution would be to have a separate function header (containing docstrings, decorators, initial attributes, etc) and body. Those parts in the header would be parsed/executed only on function creation; the body being the part that is executed when the function is called. This in conception is something like the following: def foo(bar, baz=None): header: """Frobulates bar, and calls baz if it is not None.""" .decorate(decorator_func) .attribute = "qux" body: pass Note that I'm neither proposing such a thing for implementation in Python, nor suggesting that the above syntax would be particularly suitable :) -- I'm just trying to illustrate the idea that docstrings are better off after the signature. From http Fri Aug 13 13:49:06 2004 From: http (Paul Rubin) Date: 13 Aug 2004 10:49:06 -0700 Subject: def ... decorate References: <16668.57321.308134.676624@montanaro.dyndns.org> Message-ID: <7x3c2r7wtp.fsf@ruckus.brouhaha.com> Roman Suzi writes: > Bingo! > > Just replace decorate with "from" and the nice syntax is found: > > def f: > staticmethod > grammarrule('statement : expression') > version("Added in 2.4") > deprecatedmethod > type_(None) > from self, p: > """docstring here""" > print p[1] You can get rid of the keyword: > def f: > staticmethod > grammarrule('statement : expression') > version("Added in 2.4") > deprecatedmethod > type_(None) > (self, p): > """docstring here""" > print p[1] The syntax is if you see f without parentheses, what follows is decorators. The outdent before the arg list makes it obvious where the arg list is. From 123 at 456.com Thu Aug 12 10:33:34 2004 From: 123 at 456.com (Shankar KN) Date: Thu, 12 Aug 2004 20:03:34 +0530 Subject: Python Installation (Debug Build) Message-ID: Hi, I have a system where all my binaries (built in Debug mode) are deployed on Windows XP Professional. These are C++ DLLs that expose a Python interface using SWIG. I have installed Python 2.3.3 here. If I write Python scripts that make calls to the Interfaces exposed by the C++ DLLs I get the following error:- Fatal Python error: Interpreter not initialized (version mismatch?) However when the same binaries are built in Release mode, my calls work fine, Any clues as to how I could overcome this problem. From richardjones at optushome.com.au Tue Aug 10 03:59:11 2004 From: richardjones at optushome.com.au (richard) Date: Tue, 10 Aug 2004 17:59:11 +1000 Subject: Popular Python projects with lots of pure Python code References: <4117F439.40805@ocf.berkeley.edu> Message-ID: <41188050$0$18434$afc38c87@news.optusnet.com.au> Mike C. Fletcher wrote: > Brett C. wrote: >> So I am trying to come up with a list of projects I can use to get my >> stats from. the stdlib is a no-brainer. Also plan to use Docutils. >> But beyond those most of the big Python projects I can think of have a >> ton of C code which is of no use to me. I don't need to be able to >> run it, just going to be compiling to .py files. >> >> Any suggestions? Missed the OP, but there's a wiki page for this: http://www.python.org/cgi-bin/moinmoin/LargePythonProjects but it's obviously not been advertised well, as it's practically empty ;) Richard From mlh at furu.idi.ntnu.no Mon Aug 23 16:46:03 2004 From: mlh at furu.idi.ntnu.no (Magnus Lie Hetland) Date: Mon, 23 Aug 2004 20:46:03 +0000 (UTC) Subject: Standard graph API? References: Message-ID: In article , Istvan Albert wrote: [snip] >http://www.personal.psu.edu/staff/i/u/iua1/python/graphlib/html/ I've only looked at it briefly, but it looks quite nice indeed. -- Magnus Lie Hetland "Canned Bread: The greatest thing since sliced http://hetland.org bread!" [from a can in Spongebob Squarepants] From npat at efault.net Mon Aug 16 15:11:24 2004 From: npat at efault.net (Nick Patavalis) Date: Mon, 16 Aug 2004 19:11:24 +0000 (UTC) Subject: Generators versus Coroutines References: <7x7js1i887.fsf@ruckus.brouhaha.com> Message-ID: On 2004-08-15, Lenard Lindstrom wrote: > > Having followed the development of Prothon it is my understanding that > such a thing is not possible in CPython for two reasons. The first is > that the yield statement itself defines a function declaration as a > generator. Without a specific "gen" declarator keyword as in Prothon. > Oh, I see. Then I have to say, this is an unbelievable screw-up in the language specification. Being able to yield from within multiple function-call levels is essential for any non-trivial use of generators. Without this generators can only be used for simple stuff such as to creates lists dynamically. > The second reason is a python function call in CPython involves an > actual recursive C call of the interpreter. What!?! CPython uses the *C-stack* !!?!?! Is there a reason for this? I mean, for a weekend toy-project interpreter such an aproach would be understandable, but for the primary Python interpreter! There must be a reason I don't understand... /npat From __peter__ at web.de Wed Aug 4 16:32:08 2004 From: __peter__ at web.de (Peter Otten) Date: Wed, 04 Aug 2004 22:32:08 +0200 Subject: help: Unit test fixture returning the same object References: <9895e897.0408031533.26720ba0@posting.google.com> <9895e897.0408040851.21ac7caa@posting.google.com> Message-ID: Michael McCracken wrote: > I managed to fix my problem, but I don't understand why the fix works > yet, so I'm not quite satisfied. [...] > class Block: > def __init__(self, name, preds = [], succs = []): Heureka! Providing mutables as default values is a well-known pitfall. http://www.python.org/doc/faq/general.html#why-are-default-values-shared-between-objects The default values are evaluated only once, so you end up sharing predecessors and successors between all Block instances that are created without explicitly passing preds and succs. A minimal example: >>> def f(a, alist=[]): ... alist.append(a) ... print alist ... >>> f(1) [1] >>> f(2) [1, 2] >>> f(3) [1, 2, 3] The standard workaround is to initialize the would-be list with None like followed by a test in the function body: >>> def f(a, alist=None): ... if alist is None: alist = [] ... alist.append(a) ... print alist ... >>> f(1) [1] >>> f(2) [2] >>> alist = [] >>> f(1, alist) [1] >>> f(2, alist) [1, 2] Peter From m.boeren at guidance.nl Thu Aug 26 03:29:29 2004 From: m.boeren at guidance.nl (Marc Boeren) Date: Thu, 26 Aug 2004 09:29:29 +0200 Subject: Call for signatories for J2 Message-ID: <0C77C7530EA52A4EBD1C47C80D1D291E17DE44@sbs.GuidanceBV.local> > The J2 proposal is as complete as it will ever be. > This is a call for all who wish to sign the proposal, either for, > against, or abstaining. I'll sign FOR. Cheerio, Marc Boeren. From peter at engcorp.com Wed Aug 4 10:20:53 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 04 Aug 2004 10:20:53 -0400 Subject: Does python support multi prototype. In-Reply-To: References: <2natmnFv86rjU1@uni-berlin.de> Message-ID: Jorgen Grahn wrote: > Yes, but that's not as elegant in cases where the arguments' types has to > trigger very different processing. I can even imagine situations where > foo(S) and a foo(T) do completely different things, and still 'foo' is the > best name for both of them. > > I miss overloading in Python from time to time, but I can live without it. > It is, after all, closely tied to a type system which is desirable in C++ > and Java, but not in Python. (untested code, may be minor bugs) def _foo_S(arg): # do something with arg, which is an S def _foo_T(arg): # do something with arg, which is a T def _foo_whatever(arg): # do something with arg when it's a "whatever" # ad nauseum... def foo(arg): '''generic dispatcher for foo() function''' try: func = globals()['_foo_%s' % type(arg).__name__] except KeyError: raise TypeError('invalid type for function foo', arg) else: func(arg) If you _really_ miss it from time to time, then it's _really_ easy to add it so that it's available in a fairly elegant fashion when you do need it. The above won't handle old-style classes, but adding support for them would be pretty trivial too. (Just need to check for the case where the type is "instance" and use arg.__class__ instead of type(arg).) -Peter From peter at engcorp.com Fri Aug 6 08:05:15 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 06 Aug 2004 08:05:15 -0400 Subject: RELEASED Python 2.4, alpha 2 In-Reply-To: References: <411231C8.3020308@interlink.com.au> <2-SdnZCwNs1SwI_cRVn-uQ@powergate.ca> Message-ID: <8umdnWXWJtRm7o7cRVn-uw@powergate.ca> Ivan Voras wrote: > def @synchronized @classmethod x(self): > pass > > Granted that the keywords are long-ish, but I stongly feel it's still > less ugly than the topmost version. I don't think the decorator names are ever keywords. They are just arbitrary names bound to stuff... I suspect you would find people writing code like this instead: sync = synchronized cm = classmethod def @sync @cm x(self): pass (I'm not saying whether that's a good thing, just pointing it out.) -Peter From cemerick at snowtide.com Fri Aug 20 12:50:02 2004 From: cemerick at snowtide.com (Chas Emerick) Date: Fri, 20 Aug 2004 12:50:02 -0400 Subject: Fate of lambda, Functional Programming in Python... In-Reply-To: <20040820163629.8DD4F1E401A@bag.python.org> References: <20040820163629.8DD4F1E401A@bag.python.org> Message-ID: In a comment off a post on lambda-the-ultimate, I noticed this little offhand remark: '''IIRC GvR is going to kill the various lambda, map,filter & reduce leaving just generator expressions/list comprehension.''' If this is considered generally true (at least in the straight-from-the-rumor-mill sense) I'm hoping someone here can either provide the backstory on this or point me in the direction of related discussions on python-dev (it's **real** hard to do a search on that list's archives when one's main keywords are lambda, map, filter, etc...). I'm quite fond of lambda, and it seems to have plenty of uses aside from munging lists in connection with map calls (i.e. passing one-off comparators to cmp()). Of course, my first "real" programming language was lisp, so perhaps I'm biased. (You should see all the anonymous classes I throw off in Java!) Anyway -- back to your regularly scheduled decorator-discussion of the day. ;-) -- Chas Emerick From peter at engcorp.com Fri Aug 13 09:12:49 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 13 Aug 2004 09:12:49 -0400 Subject: Flython? In-Reply-To: <411cbcb1$0$3894$4d4ebb8e@news.nl.uu.net> References: <411cbcb1$0$3894$4d4ebb8e@news.nl.uu.net> Message-ID: Guyon Mor?e wrote: > You can also write your objects in python and expose them as xml-rpc/soap. > Then use them from flash... How would I do that without spending hundreds and hundreds of dollars on a development system for Flash anyway? -Peter From anthonybaxter at gmail.com Fri Aug 6 01:44:26 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 15:44:26 +1000 Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) In-Reply-To: <338366A6D2E2CA4C9DAEAE652E12A1DE01C8C636@au3010avexu1.global.avaya.com> References: <338366A6D2E2CA4C9DAEAE652E12A1DE01C8C636@au3010avexu1.global.avaya.com> Message-ID: On Fri, 6 Aug 2004 15:10:58 +1000, Delaney, Timothy C (Timothy) wrote: > I see this less as a vote, and more an attempt to reach a community > consensus - or at least a large enough one to lend weight to the many > arguments that have already been presented. > > I will live with pie-syntax, but I won't be overly happy with it. I > would much prefer that list-after-def be accepted. Note that Guido has ruled this form out, in a pretty strong way ("I really hate this"[1][2]) so if you want to change his mind, you'll need to come up with arguments as to why he's wrong. I'm not saying that this isn't possible, more that merely collecting a concensus vote isn't likely to do much. Strong technical arguments are much more likely to work. [1] http://mail.python.org/pipermail/python-dev/2004-March/043756.html [2] http://mail.python.org/pipermail/python-dev/2004-August/046672.html ... and a bunch of other posts in the archives. From bokr at oz.net Fri Aug 27 23:03:39 2004 From: bokr at oz.net (Bengt Richter) Date: 28 Aug 2004 03:03:39 GMT Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: On Fri, 27 Aug 2004 18:39:51 -0400, Paul Morrow wrote: >Anthony Baxter wrote: >> On Thu, 26 Aug 2004 16:09:42 -0400, Paul Morrow wrote: >> >>>Yes, it doesn't seem all that complex, although I'm not sure that >>>everyone reading this understands them and their subtleties. The >>>following is an excerpt from >>>http://docs.python.org/tut/node11.html#SECTION0011200000000000000000 >>> >>>"A namespace is a mapping from names to objects. Most namespaces are >>>currently implemented as Python dictionaries, but that's normally not >>>noticeable in any way (except for performance), and it may change in the >>>future. Examples of namespaces are: the set of built-in names (functions >>>such as abs(), and built-in exception names); the global names in a >>>module; and the local names in a function invocation. In a sense the set >>>of attributes of an object also form a namespace." >> >> >>>When I talk about namespaces, I include all of the above, including the >>>sense mentioned in the last line. So an object's attributes constitute >>>a namespace too. Therefore __doc__, being an attribute of the function >>>object, is in the function object's /namespace/. And note that this is >>>*not* a new namespace; it's been there all along. >> >> >> "In a sense" is the bit you're missing here. You can't just hand-wave >> and say that it's a namespace. It's *not* a namespace. If it was, you >> could do any of these: >> > >No I didn't miss it (I read that bit). In a sense, every object has >it's own namespace. So that means that every class, every module, every >function has a namespace (in a sense). The namespace (the mapping from >names to objects) is stored in each object's special __dict__ attribute. > >Ok, and this is certainly apparent with classes. > > >>> class Foo: > ... """docstring for Foo""" > ... > >>> Foo.__doc__ > 'docstring for Foo' > >>> Foo.__dict__.keys() > ['__module__', '__doc__'] > >>> > >And because of the parallels between the above class definition of Foo >and the following function definition of baz, I would expect the same >behavior. > > >>> def baz(): > ... """docstring of baz""" > ... > >>> baz.__doc__ > 'docstring of baz' > >>> baz.__dict__.keys() > [] > >Say what? Why didn't the Python system put baz's docstring into it's >namespace (__dict__)? And where did it put it? > >I would like to understand the answers to these questions. Can you >answer them (will you)? If not, can you please point me at something >that documents what's going on here? > >Thanks. > It looks to me like __doc__ is a descriptor (or c-code that acts like one) (i.e., like a property) of the function class: >>> def foo(): ... 'foo doc string' ... Find __doc__ in the class dict: >>> type(foo).__dict__['__doc__'] Check on its nature a little: >>> type(type(foo).__dict__['__doc__']) It should have a __get__ method >>> type(foo).__dict__['__doc__'].__get__ Call that with foo as object instance: >>> type(foo).__dict__['__doc__'].__get__(foo,None) 'foo doc string' Try writing the __doc__ property (check for __set__ first): >>> type(foo).__dict__['__doc__'].__set__ Do long version of foo.__doc__ = 'new docstring' >>> type(foo).__dict__['__doc__'].__set__(foo, 'new docstring') # foo.__doc__ = ... Look at it using the short spelling: >>> foo.__doc__ 'new docstring' And the long: >>> type(foo).__dict__['__doc__'].__get__(foo,None) 'new docstring' foo.func_doc seems to be implemented in a similar way: >>> type(foo).__dict__['func_doc'].__get__(foo,None) 'new docstring' >>> foo.func_doc 'new docstring' Even the dict of a function instance appears to be implemented as a property: >>> type(type(foo).__dict__['__dict__']) >>> type(foo).__dict__['__dict__'].__get__(foo,None) {} >>> foo.x=123 >>> type(foo).__dict__['__dict__'].__get__(foo,None) {'x': 123} Short spelling: >>> foo.__dict__ {'x': 123} I haven't been into the implementation code, but this interpretation of surface appearances seems to fit. Regards, Bengt Richter From godoy at ieee.org Mon Aug 16 20:11:08 2004 From: godoy at ieee.org (Jorge Godoy) Date: Mon, 16 Aug 2004 21:11:08 -0300 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> <41214271_1@127.0.0.1> Message-ID: "beliavsky at aol.com" writes: > Jorge Godoy wrote: > >>Just an attempt and trying to keep it like your code. > > Thanks. My code did not correctly illustrate breaking out of more than one > level of loop. How would the following code be translated to Python? For that I'd adopt either the use of exceptions or a flag. ;-) > It is silly of course, but real-world situations where you want to exit a > nested loop are not that rare. > > program xnest_loop > ! illustrate breaking a nested loop > integer :: i,j,k,n > n = 4 > ido: do i=1,n > jdo: do j=1,n > if (i+j > n) exit ido > do k=1,n > if (i+j-k < 0) exit jdo > print*,i,j,k > end do > end do jdo > end do ido > end program xnest_loop > > output: > 1 1 1 > 1 1 2 > 2 1 1 > 2 1 2 > 2 1 3 > 3 1 1 > 3 1 2 > 3 1 3 > 3 1 4 >>> n = 4 >>> for i in xrange(1, n): ... for j in xrange(1, n): ... if (i + j > n): exit ... for k in xrange(1, n): ... if ((i + j - k) < 0): ... to_exit = 1 ... break ... print i, '\t', j, '\t', k ... if to_exit: ... break ... 1 1 1 1 1 2 2 1 1 2 1 2 2 1 3 3 1 1 3 1 2 3 1 3 >>> Is your last line (3 1 4) correct? In the expression "3 + 1 - 4 < 0" it is true, so I think the line should be printed... Should it? (Does the loop run at least once before evaluating the expression?) I really haven't paid attention to your code, just "translated" it to the above python, with the same logic as the previous one. Using exceptions would give me a finer grained control, I think, but would require more lines of code. Be seeing you, -- Godoy. From pm_mon at yahoo.com Thu Aug 26 09:50:43 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Thu, 26 Aug 2004 09:50:43 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> Message-ID: Errata. Please change the paragraph... > > Ok. Then let's jettison the baggage with the word metaclass and just > call them 'magic attributes'. It doesn't matter. The essential point > about them is that they almost /never have 'local variable' semantics/. > They are attributes of the object being defined. That's the point I'm > trying to drive home here. When we use __xxx__ attributes, we are not > intending to create local variables. No. We are making declarations. > ...to... Ok. Then let's jettison the baggage with the word metadata and just call them 'magic attributes'. It doesn't matter. The essential point about them is that they almost /never have 'local variable' semantics/. They are attributes of the object being defined. That's the point I'm trying to drive home here. When we define __xxx__ attributes, we are not intending to create local variables. No. We are making declarations. Paul From cookedm+news at physics.mcmaster.ca Sun Aug 22 16:04:12 2004 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Sun, 22 Aug 2004 16:04:12 -0400 Subject: 100 % portable ? References: Message-ID: At some point, "Roger Binns" wrote: > Note that for some things you would want different code. For > example the default location to save files may be My Documents > on Windows and $HOME on Linux and Mac. Similarly you would > want to save configuration settings in the registry on Windows > and dot files on Linux and Mac. For Mac the preferred place files is ~/Documents, and for config files is in ~/Library//. -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From Ian.Sparks at etrials.com Wed Aug 25 18:18:53 2004 From: Ian.Sparks at etrials.com (Ian Sparks) Date: Wed, 25 Aug 2004 18:18:53 -0400 Subject: Proposal for removing self Message-ID: <41A1CBC76FDECC42B67946519C6677A9018C2F61@pippin.int.etrials.com> > begin with just a period as in ".5". What are your thoughts? If you want to cut the typing down further you don't have to use "self" you can use : class x: def __init__(s,val): s.val = val def display(s): print s.val That's only one more character than your "." and it doesn't require any changes to Python. Of course, you'd be breaking with the tradition of naming the instance as "self" but so would your magic "." method. If you find yourself typing "self" a lot you can also do : s = self s.doSomething() Sometimes python asks us to do things that are against our sensibilities (whitespace comes to mind) but once we try it for a while we find our knee-jerk reaction to change it was simply misplaced. Live with the language a bit, use it a bit, give python the chance to change you before you try to change python. Use python for a week or two more and see what I mean. > -----Original Message----- > From: Brent W. Hughes [mailto:brent.hughes at comcast.net] > Sent: Wednesday, August 25, 2004 6:01 PM > To: python-list at python.org > Subject: Proposal for removing self > > > When doing object-oriented stuff, it bothers me to have to > type "self" so > many times. I propose that Python allow the programmer to > optionally type > ".variable" instead of "self.variable" to mean the same > thing. Of course, > the interpreter would have to be more careful about detecting > floats that > begin with just a period as in ".5". What are your thoughts? > > > -- > http://mail.python.org/mailman/listinfo/python-list > From max at alcyone.com Sat Aug 14 19:05:19 2004 From: max at alcyone.com (Erik Max Francis) Date: Sat, 14 Aug 2004 16:05:19 -0700 Subject: !wtf ellipsis References: Message-ID: <411E9AAF.78EE96C6@alcyone.com> AdSR wrote: > It's funny, I always understood ellipsis ('...') as a kind of a > wildcard or abbreviation mark, rather than absence mark. For example, > you'd write: > > a[1], a[2], ..., a[N] > > which means "all values from a[1] to a[N]" or something like that. > > But then of course it's just a symbol... It's an indication that something was removed or abbreviated. In mathematics, it has the same meaning, but it's often used in the context of showing a pattern and then removing unnecessary elements (after the pattern is obvious), so it tends to get the implied meaning of "and so on." -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ Suffering is a journey which has an end. -- Matthew Fox From tdelaney at avaya.com Wed Aug 25 18:39:29 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Thu, 26 Aug 2004 08:39:29 +1000 Subject: Subclassing built-in types Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01DCF7F6@au3010avexu1.global.avaya.com> Emiliano Molina wrote: > Emiliano Molina wrote: > --- some stuff I was confused about --- >> Where can I find that documentation? I've looked through the manual >> but can't find anything relevant. Google searches bring up articles >> that talk about code as described in my first example but I can't >> find anything like the second. > > I received no answers to my post (not complaining) and I am curious as > to wether it was a silly question or if there was no answer because > what I wanted to know is not documented. I see a useful reply from Fredrik right there ... Tim Delaney From flupke at nonexistingdomain.com Wed Aug 18 07:40:58 2004 From: flupke at nonexistingdomain.com (flupke) Date: Wed, 18 Aug 2004 11:40:58 GMT Subject: anonymous function? Message-ID: Hi, i'm not sure what the exact type of function is called for what i'm trying to do but here goes: ------ code ----- def OnClick(self, event): ... elif ( id == ID_BUTTON_CHECK ): if __debug__: print " Check pushed" minutes = self.check_time.GetValue() t = None if ( self.check.GetLabel() == "check" ): if ( minutes != "" ): self.handleCommand("Check %s minutes\n" % str(minutes)) def sendCheckCommand(): self.connection.message("CHECK") t = threading.Timer(10.0, sendCheckCommand() ) t.start() printed self.updateGUI("CHECK_WITH_TIME") ------ code ----- The relevant code being the sendCheckCommand() function declared in the OnClick function. This code starts a timer that should execute self.connection.message("CHECK") every 30 seconds. I think this is an anonymous (in Java it is) function and is really not meant to be a "real" class function. But when i execute the code, it works 1 time but the second time it doesn't work anymore and i get this error: Exception in thread Thread-2: Traceback (most recent call last): File "C:\Python23\lib\threading.py", line 436, in __bootstrap self.run() File "C:\Python23\lib\threading.py", line 544, in run self.function(*self.args, **self.kwargs) TypeError: 'NoneType' object is not callable How can i accomplish this? Thanks Benedict From nomail at nospam.no Sat Aug 7 14:53:47 2004 From: nomail at nospam.no (Dominic) Date: Sat, 07 Aug 2004 20:53:47 +0200 Subject: Dynamic Class Creation In-Reply-To: References: Message-ID: I have written a module which creates classes dynamically, but some Python tools, e.g. PyChecker crash if they try to analyse the source. So be careful! Ciao, Dominic From frithiof.jensen at die_spammer_die.ericsson.com Thu Aug 19 04:36:22 2004 From: frithiof.jensen at die_spammer_die.ericsson.com (Frithiof Andreas Jensen) Date: Thu, 19 Aug 2004 10:36:22 +0200 Subject: age of Python programmers References: <2ohpksF94tajU3@uni-berlin.de> Message-ID: "Reinhold Birkenfeld" wrote in message news:2ohpksF94tajU3 at uni-berlin.de... > I certainly wouldn't call these shockingly horrible bunches of IE-tags > thrown together with the intention of being regarded as "cool" a "website". They are retro-sites; just like 70's apparel became fashion again, so will those sites!! My 10 year-old daughter should have a future well set out in web design given her liking of Purple backgrounds enriched with Pink, Yellow and Green text - sometimes adorned with the "Blink" attribute! muahahahahahhaaa From tom.harris at opdicom.com Thu Aug 5 20:22:38 2004 From: tom.harris at opdicom.com (Tom Harris) Date: Fri, 6 Aug 2004 10:22:38 +1000 Subject: Getting memory usage of Python objects Message-ID: <000101c47b4b$7b5afa20$38010a0a@projectlabhome.local> Greetings I have a script that runs for several hours on an XP box. During this time its memory usage grows to absurd amounts. I have checked the code and it's not obvious what is growing. Is there a way that I can access the memory usage of each object so that I could find out which one is too large? Regards TomH -------------- next part -------------- An HTML attachment was scrubbed... URL: From joshway_without_spam at myway.com Wed Aug 18 17:36:44 2004 From: joshway_without_spam at myway.com (JCM) Date: Wed, 18 Aug 2004 21:36:44 +0000 (UTC) Subject: Embedding Python in Python References: <7xu0v0l2be.fsf@ruckus.brouhaha.com> <7x3c2kkzn8.fsf@ruckus.brouhaha.com> Message-ID: Jack Diederich wrote: > On Wed, Aug 18, 2004 at 08:25:04PM +0000, JCM wrote: >> Jack Diederich wrote: >> > On Wed, Aug 18, 2004 at 07:44:47PM +0000, JCM wrote: >> ... >> >> I don't think it's as difficult as you think. Your snippet of code >> >> would be rejected by the rules I suggested. You'd also want to >> >> prohibit other builtins like compile, execfile, input, reload, vars, >> >> etc. >> >> >> > foo = "ev" + "al" >> > e = vars()['__builtins__'].__dict__[foo] >> > print e('2+2') >> >> Also would be rejected by my original set of rules (can't use >> __dict__). But I'd disallow vars too. > Google groups for this topic, it's been dead horse kicked. > You would have to eliminate getarr too and any C func that can > result in an infite loop. Infinite loops (and other resource use) are a different story, not addressed by source code inspection. I worked on a project which needed to run untrusted code, and we dealt with the infinite-loop situation by always running untrusted code on the main thread and signalling it if it took too long to execute (this worked on unix--I don't know what you'd do on Windows). I realize this could leave data in a bad state. Infinite loops are harder to deal with. From anthonybaxter at gmail.com Fri Aug 20 05:11:33 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 20 Aug 2004 19:11:33 +1000 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: On Fri, 20 Aug 2004 10:51:00 +0200, Gerrit Muller wrote: > I miss the option to _not_introduce decorators at all, at least at this > moment. That's because that's not an option that's on the table. Stating you don't want them won't achieve anything at all. From jason at injektilo.org Tue Aug 24 14:57:58 2004 From: jason at injektilo.org (Jason Diamond) Date: Tue, 24 Aug 2004 11:57:58 -0700 Subject: fun with unicode files In-Reply-To: References: <6579x7eo.fsf@python.net> Message-ID: Roger Binns wrote: > Here is my own more complete implementation: > > http://www.bitpim.org/pyxr/c/projects/bitpim/common.py.html#0286 When I do import encodings.utf_32 on Python 2.3.3, I get an ImportError. What verson of Python are you using where that works? I can't find any documentation of the encodings module in the Python Library Reference. Where can I read more about it? -- Jason From peter at engcorp.com Fri Aug 6 18:32:35 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 06 Aug 2004 18:32:35 -0400 Subject: Killing children In-Reply-To: <878ycsvuhq.fsf@debian.laymusic.org> References: <87smb0w4ln.fsf@debian.laymusic.org> <87d624vxt2.fsf@debian.laymusic.org> <2eidnefxXqX3co7cRVn-tA@powergate.ca> <878ycsvuhq.fsf@debian.laymusic.org> Message-ID: <2sqdne3un4mZmoncRVn-qg@powergate.ca> Laura Conrad wrote: >>>>>>"Peter" == Peter Hansen writes: > > > Peter> Laura Conrad wrote: > >> p = os.spawnl(os.P_NOWAIT, "/usr/bin/python", "python", "hobo.py", '/dev/ttyS0', 5) > >> print p > >> os.system("ps") > >> time.sleep(60) > >> os.system("kill %d" % p) > > Peter> This suggests that you believe the return value from os.spawnl() is > Peter> actually the PID. Unfortunately that doesn't appear to be the case > Peter> on Windows. See the note in the doc-string for my code sample from > Peter> the previous post (on Windows spawn* actually returns a "handle", > Peter> not the PID itself, and apparently turning the one into the other > Peter> is non-trivial). > > So you think os.kill(p) might be the way to kill it? But does anyone > know how to get it started right? Uh... maybe? I think I just got out of my depth here... is Python compiled specially for cygwin, or is it the standard Windows Python that is involved? If the latter, which I now doubt for some reason, then yes, os.kill() can kill things spawn with spawnl/v/p/whatever provided that you use the fake os.kill that I provided before, because os.kill doesn't normally exist on Windows. -Peter From avera at coes.org.pe Mon Aug 9 19:46:02 2004 From: avera at coes.org.pe (Alberto Vera) Date: Mon, 9 Aug 2004 18:46:02 -0500 Subject: ActiveConnection doesn't work ...? Message-ID: <000a01c47e6b$07fdf1e0$1603a8c0@pc22> Hello: I tried to use these lines: ---------------------------------------------------- import win32com.client conn = win32com.client.Dispatch('ADODB.Connection') Cmd1 = win32com.client.Dispatch('ADODB.Command') conn.ConnectionString = "Provider=...." conn.Open Cmd1.ActiveConnection = conn #Error!!! --------------------------------------------------- But, I got an error in: Cmd1.ActiveConnection = conn. Visual Basic can work with Cmd1.ActiveConnection. Is it possible in Python? Regards -------------- next part -------------- An HTML attachment was scrubbed... URL: From john at grulic.org.ar Tue Aug 31 17:24:42 2004 From: john at grulic.org.ar (John Lenton) Date: Tue, 31 Aug 2004 18:24:42 -0300 Subject: has_method In-Reply-To: <41347973.7080006@geochemsource.com> References: <41347973.7080006@geochemsource.com> Message-ID: <20040831212442.GC7439@grulic.org.ar> On Tue, Aug 31, 2004 at 03:13:23PM +0200, Gandalf wrote: > > Hi All! > > Does anyone knows how to tell if an object has a method with a given > name? How can I access that method? > > For attributes, it is easy: > > class A(object): > a = 12 > b = 'Python' > > a = A() > a.__dict__.has_key('a') # True > a.__dict__.has_key('b') # True > a.__dict__.has_key('c') # False > > But it won't work for methods. Thanks in advance. try this: method = getattr(a, 'a', None) if callable(method): method(args) also consider using getattr with a default, or just plain hasattr, instead of accessing the dict directly. Accessing __dict__ like that is a bad idea with few exceptions. -- John Lenton (john at grulic.org.ar) -- Random fortune: Writing is turning one's worst moments into money. -- J.P. Donleavy -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From elbertlev at hotmail.com Fri Aug 6 15:54:41 2004 From: elbertlev at hotmail.com (Elbert Lev) Date: 6 Aug 2004 12:54:41 -0700 Subject: Standalone Python Programs... References: <-aSdndbo7ry5E47cRVn-ig@comcast.com> <41139ac9$0$65604$a1866201@newsreader.visi.com> Message-ID: <9418be08.0408061154.2999a296@posting.google.com> > > I can't speak to Linux installations because I have always > > just used the Python installation already there. > > Yup. Instalation is there, but not the third party packages. From d+pylist at nospamplease.trit.org Thu Aug 12 01:03:07 2004 From: d+pylist at nospamplease.trit.org (Dima Dorfman) Date: Thu, 12 Aug 2004 05:03:07 +0000 Subject: using os.major In-Reply-To: References: Message-ID: <20040812050307.GC10478@trit.org> John Doe wrote: > Does anyone understand what a 'raw device number' is with respect > os.major() and os.minor() > [...] > There seems to be something related to fileno, but that never returns the > value I know is true. In particular, Linux /dev/fd0 is (2/0). The raw device number isn't the file descriptor number; it's the device ID, such as those returned by stat in the st_dev and st_rdev fields: >>> st = os.stat('/dev/fd/0') >>> os.major(st.st_rdev) 22 >>> os.minor(st.st_rdev) 0 The documentation for os.stat mentions st_rdev, but it doesn't call it the "raw" device number. The FreeBSD documentation is about evenly split on calling it the "raw device number" or the "device ID", but Posix uses the latter, and I think that makes more sense. There's nothing raw about this value; I think it's only "raw" compared to internal kernel structures, where a device could be a pointer to struct instead of an integer (it's certainly not more raw than st_dev, which has the same type). Dima. From evenprimes at gmail.com Tue Aug 3 10:24:15 2004 From: evenprimes at gmail.com (Chris Cioffi) Date: Tue, 3 Aug 2004 10:24:15 -0400 Subject: Reasoning behind nested scope In-Reply-To: <20040803112624.2CCBD1E4002@bag.python.org> References: <20040803112624.2CCBD1E4002@bag.python.org> Message-ID: Why would you want to do this? The whole point of a nested function, I thought, was to encapsulate some code in the surrounding function, usually to make the surrounding function clearer. If the nested function is of wider utility it should just be a module level function. (Possibly of the quasi private variety Python offers.) Chris On Tue, 3 Aug 2004 12:26:15 +0100, Andy Baker wrote: [snip] > (On a side note is there any way to call a nested function from outside the > parent? I was kind of expecting nested functions to be addressable through > dot notation like methods are but I can see why that wouldn't be quite > right. This might be a better question for the tutor list...) > > Andy Baker -- Still searching for an even prime > 2! From onurb at xiludom.gro Sun Aug 8 14:37:04 2004 From: onurb at xiludom.gro (bruno modulix) Date: Sun, 08 Aug 2004 20:37:04 +0200 Subject: Newbie Question about Python as a language In-Reply-To: References: <41095455$0$24067$626a14ce@news.free.fr> Message-ID: <41167466$0$32075$636a15ce@news.free.fr> Dave Brueck a ?crit : > bruno modulix wrote: > >> Dave Brueck a ?crit : >> >>> Dave Guenthner wrote: >>> >>>> Hello. I write a lot of small programs mostly in Visual Basic 6 or >>>> VBScript using WSH 5.6 for any number of purposes. I am curious on >>>> what Python does that say Java doesn't do? >> >> (snip) >> >>>> For example, I would >>>> definetly need some type if Visual Development Environment. >>> >>> If your development style _requires_ a visual dev environment then >>> Python may not be for you - it doesn't have IDEs as mature as e.g. >>> Microsoft Visual Studio. >> >> It does : >> http://www.activestate.com/Products/Visual_Python/ > > > Nope - that doesn't quite cut it. Granted, I may be misunderstanding > what the OP is asking for, but I assume that since he was using VB and > is asking about a *visual* development environment, he is probably > looking for the ability to visually build GUIs (and have tight > integration - auto-code generation for it and all). > AFAIK Visual Python doesn't have this - yeah it's a plugin for a more > mature IDE, but it doesn't enjoy the same level of support in that IDE > as e.g. C++. Other Python tools are getting there, but they aren't as > mature yet. > IDE and RAD are two distinct things IMHO (well, I may be a bit biased since I use Emacs as an IDE and mostly write CLI and Web apps...), so my answer was on the fact that you can use MS visual studio *IDE* with Python. Now for the RAD part, since the OP was also talking about WHS and Java, I did assume that he was not specifically looking for a RAD tool. But I may of course be plain wrong... If you're looking for RAD tools, there are : - BoaConstructor (? la Delphi), - PythonCard (? la HyperCard), - wxGlade (RAD only, no code editing or whatsoever) They all work with wxPython/wxWidget, which is a mature C++ free cross-platform (Windows/X11/MacOS X) GUI toolkit. HTH Bruno From grante at visi.com Wed Aug 25 13:04:41 2004 From: grante at visi.com (Grant Edwards) Date: 25 Aug 2004 17:04:41 GMT Subject: Getting at the bits of a 32-bit integer References: <85b54e91.0408231552.75f85727@posting.google.com> <412a98f4$0$65569$a1866201@newsreader.visi.com> <412cb279$1@nntp0.pdx.net> <412cb407$0$62953$a1866201@newsreader.visi.com> <412cc43d$0$8084$a1866201@newsreader.visi.com> Message-ID: <412cc6a9$0$8090$a1866201@newsreader.visi.com> On 2004-08-25, Grant Edwards wrote: >> I'm very interested in this module which implements fixed-length >> integers. Do you perhaps have some reference to it? I tried to google >> for it, but couldn't come up with distinct enough keywords. > > http://groups.google.com/groups?selm=m3pt6qpzan.fsf%40pc150.maths.bris.ac.uk&rnum=10 > > I think that automatic coercion of regular Python integer > values to fixed "Field" objects would make it simpler to use. Oops, I may have been thinking of this one: http://groups.google.com/groups?selm=ad052e5c.0407161348.42abb996%40posting.google.com&rnum=28 -- Grant Edwards grante Yow! ... he dominates the at DECADENT SUBWAY SCENE. visi.com From davidf at sjsoft.com Mon Aug 30 12:37:33 2004 From: davidf at sjsoft.com (David Fraser) Date: Mon, 30 Aug 2004 18:37:33 +0200 Subject: Installation of mod_python 3.1.3 on Apache 2.0.50 on Windows Me/Win2k In-Reply-To: <39cbe663.0408300749.2ef5bc81@posting.google.com> References: <39cbe663.0408290850.14452ab9@posting.google.com> <39cbe663.0408300749.2ef5bc81@posting.google.com> Message-ID: Piet wrote: > "Lucas Raab" wrote in message news:... > >>Why not post this to the mod_python mailing list?? > > The error looked like an error in some python installation scripts, so > it seemed to me more "pythonic" than "apachic". Anyways, thanks for > the hint. > Piet mod_python is a bridge between apache and python, so it contains both Python code and C code. the mod_python list is a good place to get help, I would recommend joining it Cheers David From kjetilho at yksi.ifi.uio.no Fri Aug 27 08:55:26 2004 From: kjetilho at yksi.ifi.uio.no (Kjetil Torgrim Homme) Date: Fri, 27 Aug 2004 14:55:26 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> Message-ID: <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> [Andrew Durdin]: > > The whole topic of explicit[*] end-of-block markers was brought up > and discussed at great length in May 1994: > > http://groups.google.com/groups?threadm=9405061919.AA03028%40vicorp.com thank you for the reference! I'm happy to see that Guido wasn't strictly opposed to such a feature 10 years ago. > Regardless of history, it looks to me like your problem could be > better solved by modifying your emacs mode to consider whitespace > more correctly -- AFAICT there is no reason why it should ever > pick up the logging line in your example and indent it to the same > level as the else: block. how can Emacs tell? if I press TAB and thus ask Emacs to re-indent the line, that's what it will do. arguably, the correct fix is to disable the "clever" re-indentation code of Emacs since it's too easy to fool it, but this makes coding more awkward in other cases. it also doesn't solve cut-n-paste errors. -- Kjetil T. From bulatov at engr.orst.edu Sun Aug 1 00:49:00 2004 From: bulatov at engr.orst.edu (Yaroslav Bulatov) Date: 31 Jul 2004 21:49:00 -0700 Subject: Microbenchmark: Summing over array of doubles Message-ID: <4d642979.0407312049.7a8aecab@posting.google.com> I made an array of 10 million floats timed how long it takes to sum the elements, here's what I got (millis): gcc -O2: 21 Python with numarray: 104 Python with Numeric: 302 java: 325 gcc: 348 Python with Psyco: 1317 Pure Python using sum: 2312 Pure Python: 5631 http://yaroslav.hopto.org/russianwiki/index.php/c-numeric-speed numarray takes over Numeric at about 1100 floats I'm doing intensive computation on arrays in Python, so if you have suggestions on Python/C solutions that could push the envelope, please let me know. Yaroslav From mwilson at the-wire.com Wed Aug 25 10:50:15 2004 From: mwilson at the-wire.com (Mel Wilson) Date: Wed, 25 Aug 2004 10:50:15 -0400 Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> Message-ID: In article , Dave Opstad wrote: >In article <412c6edb$0$258$edfadb0f at dread12.news.tele.dk>, > Max M wrote: >> That the sort() method returns a None is actually a pedagocical tool to >> tell the programmer that the list is modified in place. >> >> If it had returned the list the programmer would later be surprised to >> find that the list had been modified. It would seem like hard to find >> nasty side effect. The way it is now is very explicit and easy to find out. > >But isn't the fact that the list is modified in place incidental to the >fact of sorting? One is an implementation detail, and the other is the >semantic meaning you're trying to express. It's not incidental to the fact that the original list is "destroyed" by the sorting operation. Regards. Mel. From benevilent at optusnet.com.au Tue Aug 10 07:34:30 2004 From: benevilent at optusnet.com.au (benevilent at optusnet.com.au) Date: Tue, 10 Aug 2004 21:34:30 +1000 Subject: pickling extension types Message-ID: <20040810213430.409f8248.benevilent@optusnet.com.au> Hey, I am creating an extension type in C for Python, which I want it such that instances can be pickled. I basically want the functionality of the 'object' type such that subclasses of the type which I define, can define methods including __getstate__ which will get called on pickling/unpickling. To do this I need to define the __reduce__ method. The __reduce__ method in typeobject.c is exactly what I need for this task. Is there a way to reuse this without copy-pasting the code? Thanks, Laurie From Scott.Daniels at Acm.Org Wed Aug 25 11:31:32 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 25 Aug 2004 08:31:32 -0700 Subject: Getting at the bits of a 32-bit integer In-Reply-To: <412a98f4$0$65569$a1866201@newsreader.visi.com> References: <85b54e91.0408231552.75f85727@posting.google.com> <412a98f4$0$65569$a1866201@newsreader.visi.com> Message-ID: <412cb279$1@nntp0.pdx.net> Grant Edwards wrote: >... That's a bit, um, conceited. Somebody's got to twiddle all > those low-level bits out there to provide the infrastructure > that makes the world run. > > I'm one of those people, and I need to do bit-twiddling quite > often while implimenting various communications protocols. If you are interested in such things, take a look at: http://members.dsl-only.net/~daniels/bits.html It lets you do things like look at bit-ranges of (int, long, float) and find things like msb, lsb, particular bits (bit) and extract bit ranges. -Scott David Daniels Scott.Daniels at Acm.Org From vinay_sajip at yahoo.co.uk Tue Aug 24 10:12:17 2004 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: 24 Aug 2004 07:12:17 -0700 Subject: request for logging SyslogHandler help References: Message-ID: <2e37dc1.0408240612.2f24a17d@posting.google.com> > I really like the Python logging module, and I've used it extensively, > with good results. Now I have a requirement to add a SysLogHandler, and > it's just not working. It looks like the socket is connecting, but nothing > comes out on the log. (Fedora Core 2 /var/log/messages) > > The simplest of many configurations I have tried is included below. > A FileHandler in the same config file works fine. > > Does anyone have experience in this area? Do I need a special format or > something? > > [handler_syslog] > class=handlers.SysLogHandler > level=NOTSET > formatter=verboseformat > args=() Please check that the syslog destination is the local machine (localhost) and that it is configured to work through UDP, on the standard syslog port (514). Also, try with a short message format not containing newlines (I would guess that "verboseformat" might generate large messages). Best of luck, Vinay Sajip From news at nospamwillmcgugan.com Wed Aug 18 06:33:03 2004 From: news at nospamwillmcgugan.com (Will McGugan) Date: Wed, 18 Aug 2004 11:33:03 +0100 Subject: case insensitive comparison operator ? Message-ID: <41233060$0$198$db0fefd9@news.zen.co.uk> What is the best way to do a simple case insensitive comparison in Python? As far as I can tell, the only option is to do str1.lowercase() == str2.lowercase() (or uppercase). But that strikes me as quite verbose for such a common operation, and possibly inneficient since it would create and destroy 2 tempory objects. Perhaps there should be a dedicated function in the string object, or (+1) an operator? Apologies if I have missed something. I haven't done a great deal of work int Python yet. Will McGugan From anthonybaxter at gmail.com Mon Aug 23 13:03:55 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Tue, 24 Aug 2004 03:03:55 +1000 Subject: J2 proposal: keyword In-Reply-To: <2ouldeFf0ujnU2@uni-berlin.de> References: <2ouldeFf0ujnU2@uni-berlin.de> Message-ID: On 23 Aug 2004 16:47:42 GMT, Oliver Fromme wrote: > Aren't decorators just functions that are applied to the > function definition? Then how about "apply"? It's already the name of an (now deprecated) builtin. It won't becoming a keyword, I suspect ever. From martindemello at yahoo.com Tue Aug 3 02:01:29 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Tue, 03 Aug 2004 06:01:29 GMT Subject: Newbie: pywin problem References: Message-ID: Neil Hodgson wrote: > over the app and not be properly clipped. I'm not sure what you want to > achieve. If it is just opening another window within the environment from I have a C++/MFC app with an embedded python interpreter (pyacad to be precise: http://pyacad.sourceforge.net/), and I'm experimenting to see if I can open a python window as a child of the intellicad window. > code, calling something in the template would be better. The "Python > Programming on Win32" book gives an example of adding a new document type > and view to PythonWin. There is a mailing list for Win32 Python issues at > http://mail.python.org/mailman/listinfo/python-win32 Thanks, I'll sign up. martin From paolo.veronelli at yahoo.it Tue Aug 24 13:05:58 2004 From: paolo.veronelli at yahoo.it (Paolo Veronelli) Date: Tue, 24 Aug 2004 19:05:58 +0200 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: Message-ID: <412B7576.3040302@yahoo.it> Paul Morrow wrote: > ...that they warrant an entirely new syntax? It seems that they are > very similar in a very significant way --- they alter the default > behavior of something. IMO, it's not a stretch to say that they > 'parallel' metaclasses; that they are to functions/methods what > metaclasses are to classes. So why don't they share a similar syntax? > > class Foo: > """ This is the docstring for class Foo. """ > __metaclass__ = M > # body of class goes here > > > def baz(): > """ This is the docstring for function baz. """ > __features__ = synchronized, memoized > # body of function goes here. > > > I personally find the above baz function aesthetically appealing. Does > anyone else feel this way? > > Paul Obviously me,but it's possible doors are closed,too many heads try to solve something that I start to think show a "bug" in python architecture.I mean,does ruby need to throw up so much dust to add such a feature?Or it just allow people to "build" language syntaxes? Paolino From ben at benlast.com Wed Aug 18 02:31:47 2004 From: ben at benlast.com (Ben Last) Date: Wed, 18 Aug 2004 07:31:47 +0100 Subject: Flython? In-Reply-To: Message-ID: Oddly enough, I've just acquired a need (translation: had a requirement dropped on me) for a certain amount of generation of Flash from Python. If anyone's got any pointers to code, however non-project-grade, I'd be happy to take a hack at cleaning it up and re-releasing it in return for the time saved :) humbly yours ben > -----Original Message----- > From: python-list-bounces+ben=benlast.com at python.org > [mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of > Graham Fawcett > Sent: 17 August 2004 17:35 > To: python-list at python.org > Subject: Re: Flython? > I've written some code (twice, I think) to generate SWF from Python. > Didn't include ActionScript, but it's all there in the SWF spec, so it > shouldn't be *too* hard to implement. My code was less than fast, and > was highly specialized to do a few things that I was interested in > (and ignored the rest). If there's interest, I'll dig it out, though > it's far from project-grade code and is possibly broken. The toughest > part was just grokking the SWF spec, and building some Pythonic > primitives that can output SWF tags. Simply put, writing SWF from > Python isn't rocket science. But of course, you want more than just > that... ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ From robey at slash_dev_slash_random.org Wed Aug 18 15:56:04 2004 From: robey at slash_dev_slash_random.org (Robey Holderith) Date: Wed, 18 Aug 2004 14:56:04 -0500 Subject: Embedding Python in Python References: Message-ID: On Wed, 18 Aug 2004 14:35:21 -0400, Phil Frost wrote: > You probably want something like this: > > globalDict = {} > exec(stringOfPythonCodeFromUser, globalDict) > > globalDict is now the global namespace of whatever was in > stringOfPythonCodeFromUser, so you can grab values from that and > selectivly import them into your namespace. > So using this (with a little additional reading) it looks like I can do this: globalDict = {'__builtins__': } exec(, globalDict) And that this will disallow both importing of new modules and direct access to my namespace. It will however allow access to the Would this be secure? Paul, what's your take on this? -Robey > On Wed, Aug 18, 2004 at 02:26:00PM -0500, Robey Holderith wrote: >> >> Anyone know a good way to embed python within python? >> >> Now before you tell me that's silly, let me explain >> what I'd like to do. >> >> I'd like to allow user-defined scriptable objects. I'd >> like to give them access to modify pieces of my classes. >> I'd like to disallow access to pretty much the rest of >> the modules. >> >> Any ideas/examples? >> >> -Robey From ajsiegel at optonline.com Mon Aug 23 19:50:13 2004 From: ajsiegel at optonline.com (Arthur) Date: Mon, 23 Aug 2004 23:50:13 GMT Subject: PEP318: radical notion References: Message-ID: On Mon, 23 Aug 2004 18:12:57 GMT, Arien Malec wrote: > >The problem with PEP318 is that it is too powerful, and tries to do too >much. It is a sledgehammer for attacking three problems: > >1) Metadata, a la Java and C# >2) class & static method defs >3) Arbitrary post-definitional transformations of functions. The problem as you see it was, I think, was very well put forth by Chris King early in the game, and then promptly bypassed. Guido, as late as May or June, I think, suggested that no new syntax be added to 2.4. But then backed off that position, to the point that discussion about anything other than *which* new syntax to empower the sledgehammer, has become anti-social, or something. Perhaps Guido could not answer the question to himself, or anybody else, as to - no new syntax in 2.4, pending what. Folks a lot more qualified than myself have expressed an opinion that the reprecussions here are not likely to be pretty. And been booed off the stage, and considerately left the stage - it not being their problem in the end, in anycase. So it is my opinion the weight of discussion on python-list at this point does not accurately reflect the weight of sentiment on the issue. Most folks don't like being anti-social. I allow myself to be. Sometimes. Art > >Arien From dave.opstad at agfamonotype.com Wed Aug 25 10:30:53 2004 From: dave.opstad at agfamonotype.com (Dave Opstad) Date: Wed, 25 Aug 2004 07:30:53 -0700 Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> Message-ID: In article <412c6edb$0$258$edfadb0f at dread12.news.tele.dk>, Max M wrote: > It is a design philosophy. Explicit is better than implicit. > > what would you expect a_list.sort() to return? > > If it returns a list, you would expect it to be a sorted copy of the > list. Not the list itself. > > But for performance reasons the list is sorted in place. > > So if you modify the list in place, why should sort() then return the list? > > That the sort() method returns a None is actually a pedagocical tool to > tell the programmer that the list is modified in place. > > If it had returned the list the programmer would later be surprised to > find that the list had been modified. It would seem like hard to find > nasty side effect. The way it is now is very explicit and easy to find out. But isn't the fact that the list is modified in place incidental to the fact of sorting? One is an implementation detail, and the other is the semantic meaning you're trying to express. In my opinion, it would make more sense to have: [1, 3, 4, 2].sort() return [1, 2, 3, 4] (1, 3, 4, 2).sort() return (1, 2, 3, 4) '1342'.sort() return '1234' and so on. As it is, we have sort working on lists but not on immutable sequences, which is inconvenient at times. Just my tuppence. Dave From nospam at nowhere.hu Sat Aug 7 16:20:31 2004 From: nospam at nowhere.hu (Miklós) Date: Sat, 7 Aug 2004 22:20:31 +0200 Subject: Going the PL/1 way References: Message-ID: "Jarek Zgoda" wrote in message news:cf3b56$gt6$1 at nemesis.news.tpi.pl... > Mikl?s wrote: > > > Yes, I'm thorougly annoyed with creeping featurism. > > Man, you steal my thoughts! > > Most of features that made into Python after 2.1 are "just that", like > "nobody has it, so we should" or "somebody has it, so we would too". The > only thing I welcomed in 2.3 was some interpreter speedup, not new features. > > Is it really so much needed feature, that "clean, compact and readable" > rule should be broken? Damn, to hell with decorators, noone I know even > knows what it can be good for. > > Come on, guys, fix real problems like interpreter thread safety, improve > performance, don't make us, "real-world software developers", screaming > with every new release, please. > Yes, this was exactly my point. Performance and GIL. Those are problems. And problems must be solved. After that add features... if they are really needed. Mikl?s > -- > Jarek Zgoda > http://jpa.berlios.de/ From h.b.furuseth at usit.uio.no Fri Aug 6 06:52:37 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 06 Aug 2004 12:52:37 +0200 Subject: Proposal: require 7-bit source str's References: Message-ID: Peter Otten wrote: >Hallvard B Furuseth wrote: >>Peter Otten wrote: >>>Hallvard B Furuseth wrote: >>> >>> Why would you reintroduce ambiguity with your s-prefixed >>> strings? >> >> For programs that work with non-Unicode output devices or files and >> know which character set they use. Which is quite a lot of programs. > > I'd say a lot of programs work with non-unicode, but many don't know what > they are doing - i. e. you cannot move them into an environment with a > different encoding (if you do they won't notice). True, but for them it would probably be simpler to not use the str7bit declaration, or to explicitly declare str7bit:False for the entire file. >>> The long-term goal would be unicode throughout, IMHO. >> >> Whose long-term goal for what? For things like Internet communication, >> fine. But there are lot of less 'global' applications where other >> character encodings make more sense. > > Here we disagree. Showing the right image for a character should be > the job of the OS and should safely work cross-platform. Yes. What of it? Programs that show text still need to know which character set the source text has, so it can pass the OS the text it expects, or send a charset directive to the OS, or whatever. > Why shouldn't I be able to store a file with a greek or chinese name? If you want an OS that allows that, get an OS which allows that. > I wasn't able to quote Martin's > surname correctly for the Python-URL. That's a mess that should be cleaned > up once per OS rather than once per user. I don't see how that can happen > without unicode (only). Even NASA blunders when they have to deal with > meters and inches. Yes, there are many non-'global' applications too where Unicode is desirable. What of it? Just because you want Unicode, why shouldn't I be allowed to use other charcater encodings in cases where they are more practical? For example, if one uses character set ns_4551-1 - ASCII with {|}[\] replaced with ??????, sorting by simple byte ordering will sort text correctly. Unicode text _can't_ be sorted correctly, because of characters like '?': Swedish '?' should match Norwegian '?' and sort with that, while German '?' should not match '?' and sorts with 'o'. >> In any case, a language's both short-term and long-term goals should be >> to support current programming, not programming like it 'should be done' >> some day in the future. > > Well, Python's integers already work like they 'should be done'. And they can be used that way now. > I'm no > expert, but I think Java is closer to the 'real thing' concerning strings. I don't know Java. > Perl 6 is going for unicode, if only to overcome the limititations of their > operator set (they want the yen symbol as a zipping operator because it > looks like a zipper :-). I don't know Perl 6, but Perl 5 is an excellent example of how not do to this. So is Emacs' MULE, for that matter. I recently had to downgrade to perl5.004 when perl5.8 broke my programs. They worked fine until they were moved to a machine where someone had set up the locale to use UTF-8. Then Perl decided that my data, which has nothing at all to do with the locale, was Unicode data. I tried to insert 'use bytes', but that didn't work. It does seem to work in newer Perl versions, but it's not clear to me how many places I have to insert some magic to prevent that. Nor am I interested in finding out: I just don't trust the people who released such a piece of crap to leave my non-Unicode strings alone. In particular since _most_ of the strings are UTF-8, so I wonder if Perl might decide to do something 'friendly' with them. > You have to make compromises and I think an external checker would be > the way to go in your case. If I were to add a switch to Python's > string handling it would be "all-unicode". Meaning what? > But it may well be that I would curse it after the first real-world > use... -- Hallvard From vronskij at post.sk Fri Aug 20 04:36:01 2004 From: vronskij at post.sk (vronskij at post.sk) Date: 20 Aug 2004 01:36:01 -0700 Subject: age of Python programmers References: Message-ID: <903b3fba.0408200036.e3a1f6d@posting.google.com> > Me too, I started programming rather late, when I was 26 and I realised > that I will be unable to make (good) living as philosophy graduate, > specialized in medieval ethics (st. Thomas, Duns et al.). This makes me > "young software developer" still, as I program for 7 years effectively. > ;) Than you have something others might not have. A motivation ... jan bodnar From pm_mon at yahoo.com Thu Aug 26 09:31:55 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Thu, 26 Aug 2004 09:31:55 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Arthur wrote: > On Thu, 26 Aug 2004 21:05:46 +1000, Anthony Baxter > wrote: > >>def foo(): >> __name__ = '%s_banana'%(__name__) >> > > > > I'm not sure what you are driving at here, but ... > > Aa a practical matter, wouldn't it be nice to be able to use string > substitution on a docstring placed in its usual location under def > foo(). > > That I need to place my __doc__ under the function can't be considered > a good thing, or intutive thing. > > Sort of like having to do transformations after and under the function > ;) > > Art Currently, you can change a doc string outside of a function, by modifying the function's __doc__ attribute >>> def foo(): ... """ I am foo """ ... >>> foo.__doc__ ' I am foo ' >>> foo.__doc__ = foo.__doc__ + 'indeed' >>> foo.__doc__ ' I am foo indeed' >>> IMO, to change it inside of a function def should be (but isn't) as easy as... >>> def foo(): ... """ I am foo """ ... __doc__ = __doc__ + 'indeed' Paul From zathras at thwackety.com Thu Aug 26 17:04:47 2004 From: zathras at thwackety.com (Michael Sparks) Date: Thu, 26 Aug 2004 22:04:47 +0100 Subject: Call for signatories for J2 References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> <7xhdqp967k.fsf@ruckus.brouhaha.com> <412e3ba4$0$92817$ed2619ec@ptn-nntp-reader02.plus.net> <7xk6vloc3j.fsf@ruckus.brouhaha.com> Message-ID: <412e556a$0$93997$ed2e19e4@ptn-nntp-reader04.plus.net> Paul Rubin wrote: > Michael Sparks writes: >> It's very possible that we might end up with @pie syntax or nothing. (I >> suspect the latter is very unlikely, but it's still possible) > > I don't have a strong opinion of whether J2 is better than @pie or vice > versa. I dislike both. I'm aware of that - I was largely just stating that IMO based on everything I've read that there is more chance of @pie staying than decorators being removed. Given the "Zen of Python" epithet saying "In the face of ambiguity, refuse the temptation to guess." that to me *is* a strike against J2. (assuming that it describes Guido's philosophy well - something I don't know :) >> My personal initial reaction to the syntax was "ugh", followed by >> listening to arguments and deciding that I could live with @pie happily >> (I do like perl after all so I've not got a huge aversion to >> punctuation). > > My problem with @pie is that it doesn't get enough mileage out of the > @ character. I'd almost rather use @ as a keyword introducer, like # > in the prepreprocessor. And of course, @pie should be useable on > classes rather than just functions. So why not put forward an alternative proposal? (*) If the proposal is good someone might think "ooh, I like that", and implement it if you don't feel like implementing it yourself - much like happened with J2 - it was hardly my invention! :-) * If you have I must've missed it... sorry :-( > I think decorators can do things that metaclasses can't. Agreed, however in the absence of a decorators in the language people are very likely to use metaclasses in their place for many of the tasks. >> been used in earnest then IMHO option A1 should be chosen, via a >> __future__ import. Whilst I'm obviously in favour of J2, option A1 >> strikes me as by _far_ the simplest to write or provide tools to >> programmatically munge people's code if syntax does change. (Much >> like the tools to remove unnecessary __future__ statements) > > I really wouldn't worry too much about the effect on current syntax > tools. I wasn't really thinking of current syntax tools - I was thinking about a hypothetical situation: * Decorators incorporated via the __future__ mechanism * A subset of people use them in earnest * It's found that it would be useful to change the syntax whilst it's still in the experimental __future__ phase. (As might've happened but didn't with yield and generators) In this scenario if you choose J2 then it's much harder for people to build their own tools to change their code to the new syntax. (It can be done of course, but it is harder) If you choose A1 then this is simpler. (This is what I meant regarding the tool that remove unnecessary __future__ statements) Whether that situation matters to you depends on who you are :) > Changing Python's syntax will have longer-lasting consequences than > having to update some tools. Absolutely. Regards, Michael. From h.b.furuseth at usit.uio.no Sun Aug 22 17:26:42 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 22 Aug 2004 23:26:42 +0200 Subject: Proposal: require 7-bit source str's References: <412907C8.1090104@v.loewis.de> Message-ID: Martin v. L?wis wrote: >Hallvard B Furuseth wrote: >>>> For example, if one uses character set ns_4551-1 - ASCII with {|}[\] >>>> replaced with ??????, sorting by simple byte ordering will sort text >>>> correctly. Unicode text _can't_ be sorted correctly, because of >>>> characters like '?': Swedish '?' should match Norwegian '?' and sort >>>> with that, while German '?' should not match '?' and sorts with 'o'. >>> >>> Why not sort depending on the locale instead of ordinal values of the >>> bytes/characters? >> >> I'm in Norway. Both Swedes and Germans are foreigners. > > I agree with many things you said, but this example is bogus. If I > (as a German) use ns_4551-1, sorting is simple - and incorrect, because, > as you say, ? sorts with o in my language - yet the simple sorting of > ns_4551-1 doesn't. So sorting is *not* simple with ns_4551-1. Sorry, I seem to a left out a vital point here: I thought the correct - or rather, least incorrect - ns_4551-1 character for German ? was o, not ?. Then it works out. Oh well, one learns something every day. Time to check if there are other examples, or if I can forget it... Gotta try an easy one - would you also translate German ? to ? rather than a? > Likewise, sorting *is* possible with Unicode if you take the locale > into account. The order of character doesn't have to be the numerical > one, and, as you explain, it might even depend on the locale. So if > you want a Swedish collaction, use a Swedish locale; if you want a > German collation, use a German locale. And if I want to get both right, I need a sort_name field which is distinct from the display_name field. There you would be lowis, while the Swede T?rnquist would be t?rnquist. Or maybe lowis\tl?wis or something; a kind of private implementation of strxfrm(). -- Hallvard From f.dimmling at remove-this.snafu.de Mon Aug 30 05:21:58 2004 From: f.dimmling at remove-this.snafu.de (Friedrich Dimmling) Date: Mon, 30 Aug 2004 11:21:58 +0200 Subject: Newby pango problem Message-ID: <2pg9tfFjilreU1@uni-berlin.de> Hi, I would like to use pango.layout to display text in a pygtk2 project. However I could not manage to get the pango.layout object incorporated in my toplevel gtk.Window and have it displayed. If anyone could help me either with a minimal example like 'Hello World' displayed in italics in an pango.layout or the URL to a tutorial where I can find the relevant infos (the PyGtk tutorial seems not to contain it, unless I'm really blind) Friedrich From http Fri Aug 20 20:20:13 2004 From: http (Paul Rubin) Date: 20 Aug 2004 17:20:13 -0700 Subject: decorator J4 - any objections? References: <7o3di0pt7o7e6cu3q3cbkls3g5asnn9n3u@4ax.com> Message-ID: <7x4qmx735u.fsf@ruckus.brouhaha.com> Christos "TZOTZIOY" Georgiou writes: > Why type decorators as a dictionary if you are not going to produce a > dictionary? Cause if you produce a dictionary, the order of the > decorators is no longer guaranteed. Does that matter? From jeff at ccvcorp.com Thu Aug 19 14:49:01 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Thu, 19 Aug 2004 11:49:01 -0700 Subject: age of Python programmers In-Reply-To: References: <1a608e98.725b9b40.8235400@po-d.temple.edu> Message-ID: <10i9tfjp54ies80@corp.supernews.com> Roman Suzi wrote: >On Thu, 19 Aug 2004 brianc at temple.edu wrote: > > >>Am I a programmer yet? >> >> > >I felt that I am a programmer after one year starting learning Basic (it was >at age 14, 7th form IIRC). Before it happened at each nontrivial task I had a >feeling that it's a wall in front of me! But after the change happened, >programming became a matter of knowing syntax. It became universal skill, not >depending on a programming language. > > I think I first started to think of myself as a programmer, rather than as someone who knew a bit of one or two programming languages, when I was reading the Gang of Four patterns book. Many of the examples in that book were in Smalltalk, which I'd heard of but never seen before... and yet, I could (mostly) follow what was happening. That really brought home the point that it's the algorithm, not the language, that matters. (I *still* can't really follow most Perl code, though... ;P ) Jeff Shannon Technician/Programmer Credit International From nospamjynyl at yahoo.co.nz Sun Aug 1 15:02:31 2004 From: nospamjynyl at yahoo.co.nz (Peter) Date: Mon, 02 Aug 2004 07:02:31 +1200 Subject: PyQt - clear widget for redraw References: <410b4492@news.maxnet.co.nz> <410bf265@news.maxnet.co.nz> Message-ID: <410d0699@news.maxnet.co.nz> Diez B. Roggisch wrote: > Peter wrote: >> Thanks, that works fine. >> I just started using pyqt yesterday, and having trouble finding a >> reference - most Qt stuff is written for c++. > The neat thing on pyqt is that usually you can directly translate c++ > examples to python. So there is no need to have a separate documentation > and other resources. The erase I looked up in the qt standard > documentation. Thanks (and thanks to Jim for his response, too) What I'm drawing is a series of lines (like a horizontal bar chart) and it is updated several times a second. The problem is that it goes too fast. I tried the time.sleep() function, but then it doesn't draw properly. It seems to draw only part of the chart each time, and flickers. Is there some way to make the display smoother? TIA Peter From harald.koschinski at friatec.de Fri Aug 6 04:30:38 2004 From: harald.koschinski at friatec.de (Harald) Date: 6 Aug 2004 01:30:38 -0700 Subject: Pythondirector Message-ID: <45654bdb.0408060030.41f1e973@posting.google.com> Hi, pythondirector seems to be the loadbalancer I was looking for. It works and the balancingstrategie "leastconnsrr" is what I need. But there is a minor bug: The number of "open connection" is sometimes wrong so that the balancing becomes more and more wrong. Some Channels have a permanent number of open requests of 1 - other channels go to -1 (minus one) open requests. This happens after running for some hours. Is this a know bug or do I something wrong? regards Harald From hans at zephyrfalcon.org Sat Aug 7 16:49:46 2004 From: hans at zephyrfalcon.org (Hans Nowak) Date: Sat, 07 Aug 2004 16:49:46 -0400 Subject: Going the PL/1 way In-Reply-To: References: Message-ID: Jarek Zgoda wrote: > You want to say "if you want any improvement, do it yourself"? Sure, > it's much better than Java's JCP, but expect > http://catb.org/~esr/jargon/html/F/fork.html if enough people will share > the same annoyance and anger. I may hem and haw whenever a new feature is added that I consider redundant (as everybody reading my weblog knows well :-), but I would never support a fork. -- Hans Nowak (hans at zephyrfalcon.org) http://zephyrfalcon.org/ From peter at engcorp.com Sat Aug 21 14:06:35 2004 From: peter at engcorp.com (Peter Hansen) Date: Sat, 21 Aug 2004 14:06:35 -0400 Subject: Has anyone implemented BASIC in Python? In-Reply-To: <7x657c8jmn.fsf@ruckus.brouhaha.com> References: <2oo13eFcj548U1@uni-berlin.de> <69cbbef2.0408210857.79439c35@posting.google.com> <7x657c8jmn.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > has.temp2 at virgin.net (has) writes: > >>>Has anyone ever tried implementing a simple unstructured BASIC dialect >>>in Python? I'm getting interested in language implementation, and >>>looking at a reasonably simple example like that could be pretty >>>interesting. >> >>Dunno about BASIC, but Ian Bicking has done Logo: >>http://pylogo.sourceforge.net/ > > > Dunno about Logo but I did Forth just out of general perversity. > I suppose I could post it. Please do! From tiredofspam at anyaccount.com Sun Aug 1 01:59:34 2004 From: tiredofspam at anyaccount.com (Jim) Date: Sat, 31 Jul 2004 22:59:34 -0700 Subject: PyQt - clear widget for redraw References: <410b4492@news.maxnet.co.nz> <410bf265@news.maxnet.co.nz> Message-ID: Peter wrote: > Diez B. Roggisch wrote: >> >> Call erase on your widget. Or redraw a rectangle yourself. > > Thanks, that works fine. > I just started using pyqt yesterday, and having trouble finding a > reference - most Qt stuff is written for c++. > > Peter Boudewijn Rempt's book _GUI Programming with Python: QT Edition_ might be helpful. It's available online at: http://www.opendocspublishing.com/pyqt/ You can also post your questions at: PyKDE mailing list PyKDE at mats.imk.fraunhofer.de sign up for the list at: http://mats.imk.fraunhofer.de/mailman/listinfo/pykde There's also a PyQt wiki at: http://www.diotavelli.net/PyQtWiki (it's fairly new and a little light on content, but there's already some good stuff there). Jim From gregor.jan at NOSPAMquick.cz Fri Aug 27 05:09:59 2004 From: gregor.jan at NOSPAMquick.cz (Jan Gregor) Date: Fri, 27 Aug 2004 09:09:59 +0000 (UTC) Subject: lambda ?? References: <6f402501.0408270000.31ad1455@posting.google.com> Message-ID: Python is little bit limited in lambda functions. In lisp I use lambda functions in functionals (something like a map or reduce in python) as a wrapper for functions with more than one argument. Jan On 2004-08-27, Michael Foord wrote: > I'm starting to read through the developer works article on Functional > Programming - http://www-106.ibm.com/developerworks/library/l-prog.html > > It starts by giving some basic examples using lambda. What I'm > wondering is what's the actual difference between these two forms ? > > pr = lambda s:s > *and* > def pr(s): > return s > > Both bind the name 'pr' to a function object that does the same thing > ?? I know that lambda functions can only be a single expression...... > > Is it just a basic example (and so in this case there is no > difference).. or am I missing something. (What's the point of an > 'anonymous' function... if you give a name to it !!). > > Regards, > > Fuzzy > > http://www.voidspace.org.uk/atlatnibots/pythonutils.html From cjw at sympatico.ca Sat Aug 7 14:01:45 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Sat, 07 Aug 2004 14:01:45 -0400 Subject: Decorators Message-ID: <7O8Rc.50384$Vm1.1282981@news20.bellglobal.com> Christopher T. King suggested that "we're trying to kill too many birds with one stone". http://groups.google.com/groups?q=stone+birds+group:comp.lang.python&hl=en&lr=&ie=UTF-8&selm=Pine.LNX.4.44.0408050856390.31290-100000%40ccc9.wpi.edu&rnum=1 He goes on to suggest three needs which decorators serve. Are these the only purposes which are envisaged for decorators? Most of the discussion has focused on syntax. I would like to see some clarification of the purpose and meaning of a decoration. The latest version of PEP 318 has a Motivation section which talks of transforming a method or function. The possible purposes of the transformation are not so clear. The use of the term decorator is questionable. In everyday usage, to decorate is to furnish with adornments. In this sense, we could say that a docstring is a decorator, but is that true of a transformation. It seems desirable that we choose words which are as close as possible to their everyday usage. Example 4 in the PEP 318 illustrates the enforcement of function/method argument and return checking. Is it envisaged that the accepts and returns functions become part of __builtins__? The code seems to assume that the interpreter will divert the func arguments to accepts and the return object to returns. Is this correct? If so, how many trigger words are implemented? Some syntactic options are provided in: http://www.python.org/moin/PythonDecorators I am inclined to support option D. The decorator follows the function definition and is indented, indicating that the decorator qualifies the decorated and is, in a sense subordinate to it. It doesn't use @. Steve Bethard sets out the syntactic choices clearly: http://groups.google.com/groups?q=bethard+decorator&hl=en&lr=&ie=UTF-8&selm=d11dcfba.0408060919.10c7cdd6%40posting.google.com&rnum=1 My choices would be: Indicator: Keyword preferred, but not | (vertical bar), as it looks too much like 1 or l. Location: First line of the body. The decorators are subordinate to the signature and indented like the docstring. List notation: As ListType, with a line per entry. Indented: Yes, no block. Clearly, I don't fully understand PEP 318, but I wonder at times if decorators aren't a solution in search of a problem. Colin W. From mwh at python.net Mon Aug 23 11:31:52 2004 From: mwh at python.net (Michael Hudson) Date: Mon, 23 Aug 2004 15:31:52 GMT Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> <7x4qmv6cwo.fsf@ruckus.brouhaha.com> Message-ID: Anthony Baxter writes: > On 21 Aug 2004 20:59:35 -0700, Paul Rubin > <"http://phr.cx"@nospam.invalid> wrote: > > Well, whenever I want to write a mainstream application and think of > > using Python, my first reaction is that Python is too slow... > > Too slow for what? > > I'm not being facetious here - what exactly are the bits of Python that > are too slow? I used to think this as well, but see my PyCon paper from > earlier this year. Well, Python's pretty bad for things stuff like adaptive numerical methods (the point of "adaptive" is that you can't do lots of problems at once using numarray or similar, or at least I couldn't work out how when I was an undergraduate :-). Cheers, mwh -- But maybe I've just programmed in enough different languages to assume that they are, in fact, different. -- Tony J Ibbs explains why Python isn't Java on comp.lang.python From cygnus at cprogrammer.org Thu Aug 26 00:14:37 2004 From: cygnus at cprogrammer.org (Jonathan Daugherty) Date: Wed, 25 Aug 2004 21:14:37 -0700 Subject: age of Python programmers In-Reply-To: <8ecda57b.0408251754.14ed27b9@posting.google.com> References: <20040819231139.D039A1E4003@bag.python.org> <5cf809e9.0408241126.6e3fdd5b@posting.google.com> <8ecda57b.0408251754.14ed27b9@posting.google.com> Message-ID: <20040826041437.GA6784@vulcan.cprogrammer.org> # Started programming 'real' computers starting # with an IBM 1401 Card system with 4k characters of memory using 1401 # SPS (Symbolic Programming System) the assembler of the day. Graduated # to an IBM 360/30 with 3 2311 disk drives and COBOL and learned from # bitter experience why 'alter... goto' should be banished from # existence (I think its been obsoleted in current COBOL versions). Went # on from there to large mainframes and lots of IBM assembler, CICS, and # more COBOL. Dabbled with RPG and FARGO and probably a couple of # languages I've completely forgotten about. Had a z80 machine custom # built for me in 1977 by ByteShop East in NYC and fooled around with GW # Basic. Discovered C in the early eighties and loved it. Graduated to # RadioShack TRS 80 model III's (it actually had a decent COBOL compiler # which I fooled around with and a great C compiler made by Mix) and # Atari 800 (anyone remember Atari's Deep Blue C C compiler?) Dabbled # in Java for awhile when it came out and off and on thru release 1.2. # Fooled around with Perl and totally spurned Python (indentation for # statement grouping, YUCKKK!). Couple of years later, wanted to do some # GUI's fast, and 'lo and behold'... PYTHON to the rescue. I've been # learning and using it now for about a 1/2 year and love it! # BTW anybody know what SPOOL stands for? I do. Once won a magazine # subscription extension for answering that question... No, you don't # win anything if you answer correctly :) Is it just me or are these posts getting off-topic? :) -- Jonathan Daugherty http://www.cprogrammer.org From pm_mon at yahoo.com Wed Aug 11 16:27:21 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Wed, 11 Aug 2004 16:27:21 -0400 Subject: Rather than decorators, how about sections? In-Reply-To: References: <1C74C038-EBB6-11D8-8889-000A95857E5C@eischet.com> <411a6b9d$0$13688$636a15ce@news.free.fr> Message-ID: Christopher T King wrote: > On Wed, 11 Aug 2004, Paul Morrow wrote: > > >>Fine, instead of Foo (the name of the class), use the word klass. It's >>a popular name for the first parameter of a class method. > > > My code uses 'cls' for this purpose. I'm sure others stick with 'self'. > No matter what you pick, it will break something. > > To quote the Zen of Python: "Explicit is better than implicit." > Using 'self' to hold a class object or 'klass' (or 'cls') to hold an instance object can make for some suprising code... def foo(self): print "I'm a class method!" def baz(cls): print "I'm an instance method!" I imagine that the majority of us use 'self' in instance methods. There can't be more than a few argument names that are commonly used to hold class objects (klass, cls, ...) so maybe the compiler allows any one of the popular spellings in that position. If explicit truly was better than implicit, we wouldn't embrace dynamic typing as we do. We would declare everything. And this language wouldn't be any fun... From raims at dot.com Wed Aug 18 07:13:45 2004 From: raims at dot.com (Lawrence Oluyede) Date: Wed, 18 Aug 2004 13:13:45 +0200 Subject: Platform independent way to play an mp3 file References: Message-ID: <1w9xnslz5154j.1es2d7zxju1hl$.dlg@40tude.net> In data Wed, 18 Aug 2004 11:38:21 +0200, Gandalf ha scritto: > Does anyone know a platform independent way to play an mp3 file from Python? > I believe the standard library cannot do this. http://pymedia.sf.net maybe this library can help you -- Lawrence (l dot oluyede at virgilio dot it) "If the implementation is hard to explain, it's a bad idea." from The Zen of Python by Tim Peters From pm_mon at yahoo.com Tue Aug 31 09:25:43 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Tue, 31 Aug 2004 09:25:43 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Paul Morrow wrote: > > But why speculate. Let's see if this is really going to be unclear in > practice. Ask someone who has never seen Python before which are the > local variables in the following def. > > def circumference(diameter): > """Calculate the diameter of a circle.""" > __author__ = 'Paul Morrow' > __version__ = '0.1' > pi = 3.14 > return pi * diameter > > And while you're at it, ask them which lines get executed at function definition time, and which get executed when the function is called. Paul From roy at panix.com Sun Aug 8 10:19:19 2004 From: roy at panix.com (Roy Smith) Date: Sun, 08 Aug 2004 10:19:19 -0400 Subject: @decorator syntax is sugar, but for what exactly? (decorator libraries). References: Message-ID: In article , Anthony Baxter wrote: > > Speaking of libraries, Dan Bishop posted some interesting example of > > @memoize and @printreturns utility wrappers. This leads me to think > > that a good way to leverage the idea of decorators would be a module of > > common utility functions which could be used as decorators by anybody. > > I'll call the module martha (since it supplies things used for > > decorating). Does the proposed mechanism support something like (to use > > one of Dan's exmaples, written with two different syntaxen): > > That might happen, but it's unlikely for 2.4. Give people time to use the new > tools, find out what works well and not so well, and standardise those. I think you missed the gist of my question, which is probably my fault for wrapping it up (decorating it?) with a lot of other peripheral points. The key question is whether the decorator mechanism would allow such a thing? All of the examples I've seen have the decorator defined right before it's used, and having a simple name. I'm guessing that the real syntax is @, and that any expression that evaluations to a callable object is kosher after the "@"? So, any of the following would be syntactically correct: --------------------- import martha @martha.memoize def foo (x): return x --------------------- # don't know why you would want to do this, but I'm # exploring the edges of the envelope. def decorator1 (): pass def decorator2 (): pass decorators = [decorator1, decorator2] def getDecorator (i): return decorators [i] @decorators[0] @getDecorator (1) def myFunction (): pass --------------------- From peter at engcorp.com Fri Aug 20 12:32:39 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 20 Aug 2004 12:32:39 -0400 Subject: Rita Sue and Bob too In-Reply-To: References: Message-ID: <7tKdndVxj-WwurvcRVn-gA@powergate.ca> M. Clift wrote: > If I wasn't happy enough already with the examples/ideas you've all shown > me, how about searching as previously, but where the middle name could be > anything. i.e. 'Rita', 'anyname','Bob' How about this? (may need more test cases, and then perhaps fixes): class Anything: '''wildcard: matches anything''' pass def sliceCompare(left, right): '''compare left and right, returning True if equal (allows wildcard)''' if len(left) != len(right): return False else: for l, r in zip(left, right): if Anything in [l, r]: pass elif l != r: return False else: return True def sliceIndex(seq, sub, start=0): '''search starting at 'start' for sub in seq, return index of match or -1''' try: i = seq.index(sub[0], start) while i >= 0: if sliceCompare(seq[i:i+len(sub)], sub): return i i = seq.index(sub[0], i+1) except ValueError: pass return -1 def test(): case1 = ['Rita', 'Sue', 'Bob'] alist = 'Rita Mary Jane Bob Sue Carl Hans Rita Bob Sue'.split() assert sliceIndex([], case1) == -1 assert sliceIndex(alist, case1) == -1 alist = 'Rita Mary Jane Bob Rita Carl Bob Hans Rita Sue Bob Sue Rita Sue Bob'.split() assert sliceIndex(alist, case1) == 8 assert sliceIndex(alist, case1, 9) == 12 assert sliceIndex(alist, case1, 13) == -1 case2 = ['Rita', Anything, 'Bob'] assert sliceIndex(alist, case2) == 4 assert sliceIndex(alist, case2, 5) == 8 assert sliceIndex(alist, case2, 9) == 12 if __name__ == '__main__': test() From newsgroups at jhrothjr.com Sat Aug 21 11:34:54 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Sat, 21 Aug 2004 11:34:54 -0400 Subject: Why are strings immutable? References: Message-ID: <10ieqt67kf3139c@news.supernews.com> "Brent W. Hughes" wrote in message news:chzVc.288437$a24.71659 at attbi_s03... > I kind of hate to have to convert a string into a list, manipulate it, and > then convert it back into a string. Why not make strings mutable? Strings are immutable because they are "value objects". Consult any good, recent OO design text for what a value object is, and why it should be immutable. That said, it would be useful to have a string buffer object that could be changed. John Roth > > From grante at visi.com Mon Aug 9 11:48:34 2004 From: grante at visi.com (Grant Edwards) Date: 09 Aug 2004 15:48:34 GMT Subject: how many bytes in an int References: <9ACRc.1523$bJ2.9739@news1.mts.net> <4116f8ee$0$8076$a1866201@newsreader.visi.com> <41170cd1$0$8076$a1866201@newsreader.visi.com> <41171116$0$8079$a1866201@newsreader.visi.com> <41172C9A.2020301@jessikat.fsnet.co.uk> <41178bde$0$8077$a1866201@newsreader.visi.com> Message-ID: <41179cd2$0$8089$a1866201@newsreader.visi.com> On 2004-08-09, Richard Brodie wrote: > > "Grant Edwards" wrote in message > news:41178bde$0$8077$a1866201 at newsreader.visi.com... > >> Like the man said, "struct" doesn't convert to-from integers of >> specified byte lengths. > > It does if you ask it to. By guessing formats and calculating sizes? Or is there a way to ask for an N-byte integer that I missed? -- Grant Edwards grante Yow! .. this must be what at it's like to be a COLLEGE visi.com GRADUATE!! From __peter__ at web.de Sun Aug 1 14:14:15 2004 From: __peter__ at web.de (Peter Otten) Date: Sun, 01 Aug 2004 20:14:15 +0200 Subject: transforming a list into a string References: Message-ID: Roy Smith wrote: > I'm also not particularly happy about the choice of "it" as a variable > name. The "izip (it, it)" construct makes me think of Dr. Evil :-) Using "it" is just my convention (contradictio in adiecto :-) for iterators used in a pure algorithm rather than with a meaning determined by a concrete use case. It's similar to the traditional i in counting loops, having grown an additional "t" to disambiguate it. If you have a better name for the purpose, don't hesitate to tell me... > It's not the izip bit that bothers me in the original, it's the deeply > nested construct of > > ",".join(["{%s,%s}" % i for i in izip(it, it)]) > > There's too much going on in that one line to get your head around > easily. I suppose people who are really into functional programming > might find it understandable, but I find it rather obtuse. I don't think three levels can be called "deep nesting". In particular the "somestr".join() construct is so ubiquitous that your brain will "optimize" it away after reading a small amount of Python code. But I see my oneliner meets serious opposition. Well, sometimes a few self-explanatory names and a helper function can do wonders: import itertools def pairs(seq): it = iter(seq) return itertools.izip(it, it) coords = ['1','2','7','8','12','13'] points = [] for xy in pairs(coords): points.append("{%s, %s}" % xy) print ", ".join(points) That should be clear even to someone who has never heard of generators. Note that pairs() is only called once and therefore does not affect the speed of execution. Personally, I'd still go with the list comprehension instead of the above for-loop. By the way - expanding on Michele Simionato's chop(), http://mail.python.org/pipermail/python-list/2004-May/222673.html I've written a generalized version of pairs(): _missing = object() def ntuples(seq, N=2, filler=_missing): """ Yield a sequence in portions of N-tuples. >>> list(ntuples("abcdefg", 3)) [('a', 'b', 'c'), ('d', 'e', 'f')] >>> list(ntuples("abc", filler="x")) [('a', 'b'), ('c', 'x')] """ if filler is _missing: it = iter(seq) else: it = itertools.chain(iter(seq), itertools.repeat(filler, N-1)) iters = (it,) * N return itertools.izip(*iters) Enjoy :-) Peter From samuel.williams at gmail.com Mon Aug 23 17:04:36 2004 From: samuel.williams at gmail.com (sam) Date: 23 Aug 2004 14:04:36 -0700 Subject: jonpy uploading Message-ID: Anyone else have trouble with Jon's Python Modules and uploads? Looks like it gets into an infinite loop in class Entity's __init__ (mime.py). cgi, xitami, xp From abra9823 at mail.usyd.edu.au Wed Aug 4 22:05:39 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Thu, 5 Aug 2004 12:05:39 +1000 Subject: on the fly document generation Message-ID: <1091671539.411195f36b55f@www-mail.usyd.edu.au> hi! i generate a document on the fly and then print it from my script. to force the browser to show the 'save file' dialog rather than display the content in the browser, i have added the header Content-Type print "Content-Type: application\n" however when the save file dialog box comes up, it gives the script name (in this case sfile.cgi) as the filename. how can i change that to a different filename? print "Content-Type: application; name="test.xml\n" sorry its a little off-topic thanks cheers -- Ajay Brar, CS Honours 2004 Smart Internet Technology Research Group ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From gandalf at geochemsource.com Thu Aug 12 06:06:20 2004 From: gandalf at geochemsource.com (Gandalf) Date: Thu, 12 Aug 2004 12:06:20 +0200 Subject: Mod python with multipart Message-ID: <411B411C.5040905@geochemsource.com> Hi All! Does anyone know how to read the "multipart/form-data" posted by a form? I'm using mod_python 3.1 and Apache 2. I looked at the docs of the request object but there is no description on how to read multipart data. I also tried google with "modpython multipart" but there are only a few hits - I could not use them. I only need the multipart data as a string - I have already written the code that splits the data into fielts. Thanks in advance, Laci From zathras at thwackety.com Sat Aug 21 20:41:58 2004 From: zathras at thwackety.com (Michael Sparks) Date: Sun, 22 Aug 2004 01:41:58 +0100 (BST) Subject: [PATCH] RE: J2 decorator grammar In-Reply-To: Message-ID: On Sun, 22 Aug 2004, Michael Sparks wrote: > On Fri, 20 Aug 2004, Robert Brewer wrote: > ... > > Did you ever fix the scope issue? > > I've fixed the scoping issue. > > I'll clean up the changes I made to get a minimal patch against 2.4a2, and > then put it somewhere handy. The patch can be found here: * http://thwackety.com/decorator_syntax_J2.patch I'll add the simple/short form tomorrow. Regards, Michael. From dave at pythonapocrypha.com Mon Aug 9 13:56:20 2004 From: dave at pythonapocrypha.com (Dave Brueck) Date: Mon, 09 Aug 2004 11:56:20 -0600 Subject: Queue qsize = unreliable? In-Reply-To: <788E231C269961418F38D3E360D1652526CA22@tndefr-ws00021.tenovis.corp.lan> References: <788E231C269961418F38D3E360D1652526CA22@tndefr-ws00021.tenovis.corp.lan> Message-ID: <4117BAC4.7060804@pythonapocrypha.com> Ames Andreas (MPA/DF) wrote: > Dave Brueck wrote: >>But is it blocking in any way that you (the caller) will likely >>notice? (probably not - the mutex is held for a relatively short > > How I notice a blocking function? > > 1) As a programmer: I have to read the docs and unfortunately all too > often the code. What I meant was that the fact that a lock is being acquired in the module implementation doesn't really affect your code (or its performance in most cases) in practice. > 2) As a "caller": I'm wasting time when blocking without a reason. Not really because (1) the code would block only when more than one thread is accessing the lock at the same time, (2) there is a fairly small chance that more than one thread will be accessing that particular lock at the same time (especially in the scenarios you described earlier), and (3) even when there is contention for the lock it will be over a very brief period of time. >>>With CPython's assertions about atomicity of certain list >>>operations it's possible to implement a lock free queue that is >>>even usable for the single producer or single consumer case. >> >>If you have the single producer and/or single consumer case, you >>don't need a Queue at all - just use a built-in list (or in 2.4 a >>collections.deque object). > > I think I didn't make my point clear enough. The most important word > in the above paragraph was "usable", which means more to me than just > thread-safe. I'd be interested in a usable (i. e. non-polling) > implementation of a queue without any locks. What problem has the current implementation caused in your application? Or are you more concerned about what problem it may cause? In any case, why don't you just do something like: import Queue class MyQ(Queue.Queue): def NonBlockingIsEmpty(self): return len(self.queue) == 0 > I just included the "else" branch to make clear that only one of > empty's two possible outcomes is reliable. It makes much more sense > and it is much closer to my specific application to write: > > while !q.empty(): > doSomethingToTheWorkersOutput() > > When leaving this loop I'll go back to sleep on select. As I said earlier: if this is your use case you don't need a queue object - just use a built-in list: while workList: doSomethingToTheWorkersOutput() > As to the "extremely short amount of time (relatively speaking)": I'm > still very impressed by Dan Kegel's c10k paper. Yes, it is a good paper. BTW - are you really using select() as you mentioned above or is it some special implementation of select? (because if it's just an ordinary select then you're not going to be able to support that many connections anyway, and even if you could, using something else instead of select would give you much greater performance improvements than eliminating the Queue lock usage. > And following that > one I'm not so much concerned about the amount of time that a producer > may hold the lock (that time may very well be ignorable), when the > single consumer tries to acquire it, but much more about the fact that > it potentially needs at least *two* context switches per iteration > until the one thread that feeds all others and thus that all others > depend upon gets back to work. So is this actually causing you a problem in practice or is this closer to some premature optimization? No offense intended - I ask only because it seems very unlikely that this is going to be one of your major bottlenecks. Yes, you could end up with multiple context switches *in the worst case*, but you have to also consider (1) how likely the worst case scenario is to come up and (2) how that stacks up against other bottlenecks in terms of performance. If you're using the queues to pass around socket-level work (reading and writing bytes) then I can tell you right now that you're not going to get anywhere near the 10k connection limit with that approach on standard CPython - the overhead of the Queue itself is too high - so it'd be in your best interest to profile and work on the actual bottlenecks first. If you're instead using the queues to pass around application-level work ("run this DB query", "send this response to the client", etc), then it's highly unlikely that the mutex acquisition in Queue.get(False) will have any measurable impact in overall application performance because - so again the best bet is to profile to find current, real hotspots in the code. FWIW, Python _is_ a pretty good platform for developing relatively high-performance servers. I've found that, with not too much work, it's easy to have a clean implementation and still be on par with (and even beat) something like Apache both in terms of total throughput, connection response times, etc. BUT, if you want to approach very large numbers of connections you may want to base your implementation on Stackless Python and avoid normal Python threads (and Queues, and...) altogether. -Dave From edreamleo at charter.net Thu Aug 5 07:26:50 2004 From: edreamleo at charter.net (Edward K. Ream) Date: Thu, 5 Aug 2004 06:26:50 -0500 Subject: Decorator syntax References: <38ednYT1NLz1P4zcRVn-uA@powergate.ca> Message-ID: <10h46c0l0kol830@corp.supernews.com> > Anyway, check the past discussions before going back around > the same arguments yet again. And exactly how is one supposed to do this? I would have thought the pep would be the place to start, but pep 318 is actively misleading as to the state of the project. BTW, one of the design goals in pep 318 is "not needlessly complicate secondary support tools". I would classify Leo as one of those tools, and the '@' syntax threatens Leo directly, as I have said in the thread called "Confused about pep 318" Edward -------------------------------------------------------------------- Edward K. Ream email: edreamleo at charter.net Leo: Literate Editor with Outlines Leo: http://webpages.charter.net/edreamleo/front.html -------------------------------------------------------------------- From ml at dynkin.com Sun Aug 29 09:25:58 2004 From: ml at dynkin.com (George Yoshida) Date: Sun, 29 Aug 2004 22:25:58 +0900 Subject: Get all subdirs In-Reply-To: References: Message-ID: Florian Lindner wrote: > Hello, > how can I get all subdirectories of a given directory. os.listdir(dir) > doesn't differentiate between directories and files, os.walk seems to me a > bit overkill since it also descends in the subdirs. > Thx, > Florian What about testing return values of os.listdir with os.path.isdir? e.g., filter(os.path.isdir, os.listdir(dir)) or if you don't like high-order functions, [filename for filename in os.listdir(dir) if os.path.isdir(filename)] -- George From b.niemann at betternet.de Thu Aug 19 05:27:31 2004 From: b.niemann at betternet.de (Benjamin Niemann) Date: Thu, 19 Aug 2004 11:27:31 +0200 Subject: Embedding Python in Python In-Reply-To: References: Message-ID: Well it seems that this is impossible to do with the current Python. But it is a feature that would be important for certain applications. Actually I've been searching for this, too - and only found abandoned/deprecated modules. If you want to use the current Python interpreter to execute the code, you'd have to remove many language features, because they could provide a backdoor for malicous code. This could be done by defining a grammar for a subset of Python (perhaps with some semantic checks), and verify that the code satisfies the grammar before you feed it into eval(). This could either be easy (resulting in a small subset of Python that is probably too small for real use...), or difficult (resulting in a usable subset, but with a large amount of complex grammar rules - with at least one rule that introduces a security leak...). A good solution has to be implemented in the Python interpreter. Are there any plans for future versions of Python? I've seen the phrase "security initiative" on this list. Was that a "there is a ..." or "there should be a ..."? I couldn't find anything on the web (but didn't search very deep). My first idea: - extend the C-API (alternative to Py_Initialize??) for embedding Python to provide a 'stripped down' interpreter: no builtins with sideeffects (like open()...), ... I don't know anything about Pythons internals or embedding Python, so I can say, if this is easy or possible at all. - communication of the embedded script to the outside world (file or network I/O...) must be provided by the hosting application that is responsible for enforcing the desired security limitations. - wrap it into a Python module. Then you can start the isolated embedded Python from 'real' Python code. The interesting (and most difficult) thing is, which part of Pythons standard library relies on "dangerous" features. This could drastically reduce the usability of this approach (until you build your own 'secure' library). Using this model, the secure interpreter is running in the same process context as the unsecure host. A bug in python could result in unchecked access to resources of the host. For higher security a separate process should be started. From jsaker at americanrelay.com Fri Aug 6 11:24:10 2004 From: jsaker at americanrelay.com (James R. Saker Jr.) Date: Fri, 06 Aug 2004 10:24:10 -0500 Subject: Queue qsize = unreliable? Message-ID: <1091805850.15192.12.camel@localhost> I see per pydoc that Queue.Queue()'s .qsize is allegedly unreliable: | qsize(self) | Return the approximate size of the queue (not reliable!). Any thoughts on why this is unreliable (and more curiously, why it would be put in there as an unreliable function?) Rather than roll my own threaded fifo class, it would seem prudent to use Python's built-in Queue but the warning signs on a rather necessary function seem curious. Jamie From herbcle at en.com Thu Aug 19 21:43:43 2004 From: herbcle at en.com (Herb Schilling) Date: Thu, 19 Aug 2004 21:43:43 -0400 Subject: ANN: Python Decrypt PDF script -- builds on pdftools In-Reply-To: References: Message-ID: >Hi, > >I wanted to extract the meta-data from an encrypted/protected PDF file >and could not find any Python scripts to do this. So, I decided to >write something myself, the result follows. > >This demonstration utility requires the `pdftools` files from > but the >decryption functions themselves should be usable with other Python PDF >libraries. > >Documentation is marginal and all I can say is that worked on the >three PDF files I tested it on... :-) > >--Phil. > >P.S. The usual Usenet-mangling warning applies--yeah, I know--I should >put it up on a web site somewhere... :-) > >#!/usr/bin/python ># ># Decrypt PDF Info ># ># Decrypts PDF files and displays meta-data associated with them. (If >the ># file isn't encrypted the information is displayed as is.) ># ># The results are similar to xpdf's `pdfinfo` utility. ># ># It should be possible to decrypt all of the objects contained ># in the PDF, but this only reads the Document Information Dictionary. ># ># (Note: All the PDF handling is provided by `pdftools`, this just >adds ># the ability to deal with encrypted PDF files.) ># ># Requires: ># + pdftools ># ># ># Based on: ># + `pdfdecrypt.pl` ># >[PDFPL] ># ># Incorporates: ># + RC4 from CipherSaber implementation by Ka-Ping Yee > ># ># ># References: ># + > >[PDFE] ># ># Author: ># follower at myrealbox.com (Standing on *many* shoulders...) ># >import sys >import md5 >import struct > >from pdftools import PDFdocument > >def arcfour(input, key): > """ > Perform the ARCFOUR (RC4) algorithm on a given input list of bytes >with > a key given as a list of bytes, and return the output as a list of > bytes. > > (From CipherSaber implementation by Ka-Ping Yee > ) > """ > i, j, state = 0, 0, range(256) > for i in range(256): > j = (j + state[i] + key[i % len(key)]) % 256 > state[i], state[j] = state[j], state[i] > i, j, output = 0, 0, [] > for byte in input: > i = (i + 1) % 256 > j = (j + state[i]) % 256 > state[i], state[j] = state[j], state[i] > n = (state[i] + state[j]) % 256 > output.append(byte ^ state[n]) > return output > > >_passwordPad = [ > 0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41, > 0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, 0x01, 0x08, > 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80, > 0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a] > >passwordPad = "".join([chr(b) for b in _passwordPad]) > >def calculateFileKey(fileId, ownerHash, userHash, permissions, > userPassword = ""): > """ > Calculates the file key for the document as described in >references > (see [PDFE] and [PDFPL]). > """ > md = md5.new() > md.update((userPassword + passwordPad)[:32]) > md.update(ownerHash) > md.update(struct.pack(" md.update(fileId) > > fileKey = md.digest()[:5] > > return fileKey > > >def calculateObjectKey(fileKey, objectNumber, generationNumber): > """ > Calculates the key for the object as described in references > (see [PDFE] and [PDFPL]). > """ > md = md5.new() > md.update(fileKey) > md.update(struct.pack(" md.update(struct.pack(" objectKey = md.digest()[:10] > > return objectKey > > >class NotEncryptedException(Exception): > """ > The supplied PDF document is not encrypted. > """ > > >KEY_OWNER_HASH = 'O' >KEY_USER_HASH = 'U' >KEY_PERMISSIONS = 'P' > >def getFileKey(doc, userPassword = ""): > """ > Extracts the information required to calculate the file key > from the supplied PDF document. > > In most cases `userPassword` can be left empty. > """ > fileId = doc.trailer_dict['ID'][0] # Is the ID always repeated? > > try: > encryptDict = doc.dereference(doc.trailer_dict['Encrypt']) > except KeyError: > raise NotEncryptedException > # TODO: Check encryption version is ok. (filter/standard/v/1/r/2) > > ownerHash = encryptDict[KEY_OWNER_HASH] > userHash = encryptDict[KEY_USER_HASH] > # `permissions` should be "four-byte integer, LSB first." > permissions = encryptDict[KEY_PERMISSIONS] > > fileKey = calculateFileKey(fileId, ownerHash, userHash, >permissions, > userPassword) > > # Sanity check user password > assert(decrypt(userHash, fileKey) == passwordPad) > > return fileKey > > >def decrypt(text, key): > """ > Decrypts the supplied object (as a string) with the supplied key. > > Returns "plain text" form of object as a string. > """ > return "".join([chr(b) > for b in arcfour(map(ord, text), map(ord, key))]) > > >def showDocumentInfo(doc, fileKey): > """ > Displays the content of the (optionally encrypted) Document >Information > Dictionary for the supplied PDF document. > """ > infoDictRef = doc.trailer_dict['Info'] > objectNumber = infoDictRef.obj > generationNumber = infoDictRef.gen > > infoDict = doc.dereference(infoDictRef) > > objectKey = calculateObjectKey(fileKey, objectNumber, >generationNumber) > > for field, encryptedValue in infoDict.iteritems(): > if fileKey: > value = decrypt(encryptedValue, objectKey) > else: > value = encryptedValue > print "%s: %s" % (field, value) > > >if __name__ == "__main__": > try: > filename = sys.argv[1] > except IndexError: > raise SystemExit("Usage %s " % sys.argv[0]) > > doc = PDFdocument(filename) > > try: > fileKey = getFileKey(doc) > except NotEncryptedException: > fileKey = "" > > showDocumentInfo(doc, fileKey) -- Herb Schilling From 510046470588-0001 at t-online.de Tue Aug 17 09:09:43 2004 From: 510046470588-0001 at t-online.de (510046470588-0001 at t-online.de) Date: 17 Aug 2004 15:09:43 +0200 Subject: How big can a Python program be? References: <903b3fba.0408170333.49ce3944@posting.google.com> Message-ID: <87smalgbc8.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> vronskij at post.sk writes: > Hi, > > A C program can be hundreds of thousands lines of code big. > C++ millions. > > How about Python? > no limitation Klaus Schilling From chrisccc_3k at yahoo.com Mon Aug 9 14:35:01 2004 From: chrisccc_3k at yahoo.com (Chris Connett) Date: Mon, 09 Aug 2004 14:35:01 -0400 Subject: Best pattern/idiom Message-ID: <4117c3d8$1@buckaroo.cs.rit.edu> I was wondering if there were a well known pattern/idiom for breaking a sequence into a list of lists, each n elements long, e.g. [0,1,2,3,4,5,6,7,8,9,10,11] -> [[0,1,2,3],[4,5,6,7],[8,9,10,11]] This comes up reasonably often in my work, and every time I re-think about it, and come up with [ lis[n:n+4] for n in range( 0, len( lis ), 4 ) ] which seems very kludgy to me, since it uses a range and len, 2 mentions of the list identifier and 2 literal 4's (which is the size I want to break into this time). Is there a better way? From http Thu Aug 26 13:52:26 2004 From: http (Paul Rubin) Date: 26 Aug 2004 10:52:26 -0700 Subject: Call for signatories for J2 References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> Message-ID: <7xoekx4wit.fsf@ruckus.brouhaha.com> Doug Holton writes: > Even in common English usage, "per" usually comes in the middle of a > phrase, not the beginning, like "miles per hour" or "Changes were made > to the manuscript per the author's instructions" (people would more > commonly use the phrase "according to" rather than "per" there). It's also perfectly ok to say "Per the author's instructions, changes were made to the manuscript". From tjreedy at udel.edu Sat Aug 28 05:37:25 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 28 Aug 2004 05:37:25 -0400 Subject: Iteration over Lists and Strings References: Message-ID: "DeepBleu" wrote in message news:cUSXc.56768$xi6.42946 at fe2.texas.rr.com... > (expected result: When something does not act as expected, look in the manual or try the builtin help facility, which only takes seconds. >>> help(list.index) Help on method_descriptor: index(...) L.index(value) -> integer -- return index of first occurrence of value dir(object) will give you a list of attributes and methods. You can look up new ones the same way. In particular, dir(list) and dir(__builtins__). Terry J. Reedy From timr at probo.com Tue Aug 24 01:42:32 2004 From: timr at probo.com (Tim Roberts) Date: Mon, 23 Aug 2004 22:42:32 -0700 Subject: html templates References: Message-ID: Pierre-Fr?d?ric Caillaud wrote: > > I tried Cheetah and found it to be a bit slow. Maybe it has too many >features. The template language is great, though. There is some code in the WebWare wiki that demonstrates how to cache Cheetah templates, so they only get recompiled when they change. That can help performance on sites that rarely change. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From nothanks at nothere.com Thu Aug 26 18:32:21 2004 From: nothanks at nothere.com (Emiliano Molina) Date: Thu, 26 Aug 2004 22:32:21 GMT Subject: Subclassing built-in types In-Reply-To: References: Message-ID: Thank you, thats just what I needed. From python at elehack.net Mon Aug 9 11:50:26 2004 From: python at elehack.net (Michael Ekstrand) Date: Mon, 9 Aug 2004 10:50:26 -0500 Subject: Going the PL/1 way In-Reply-To: References: Message-ID: <200408091050.26226.python@elehack.net> On Saturday 07 August 2004 16:19, Jarek Zgoda wrote: > It is first time I felt it's "we and them" world, divided into > "Python developers" and "Python users". They want features. We want > stability and performance. Perhaps I am unique among Python users. But I've always welcomed the new features Python has introduced in recent times, especially the new-style class stuff in 2.3. Perhaps it is because my programing paradigm is intensely theoretical, with a lot of thought put towards purity of model. But it seems that the features the "Python developers" are adding increase Python's theoretical beauty, and hence make life easier for me as a user. Except for when I'm stuck needing to code for pre-2.3 Python. Or coding with Zope, where I feel that my hands are tied because I can't use some new features. -Michael From detlev at die-offenbachs.de Wed Aug 4 13:09:46 2004 From: detlev at die-offenbachs.de (Detlev Offenbach) Date: Wed, 04 Aug 2004 19:09:46 +0200 Subject: eric3 completion References: <953AD2389idtoken@128.91.2.239> Message-ID: grv wrote: > This is the only IDE that looks very useable on linux of everything > I've looked at (and not to start a dev environment war) but one thing > that is troublesome is the word completion. > > There is a user-contributed script to parse all the dll and py files to > make a list of functions & attributes for each namespace, but it > doesn't > pick up some things like file.seek() and datetime.today(). The script > complains that no source files found, yet other built-ins like open() > are > picked up. Any guidelines on how to get all the default stuff working > for code completion? Maybe the script has a bug. Could you check it and possibly fix it? Detlev -- Detlev Offenbach detlev at die-offenbachs.de From anthonybaxter at gmail.com Fri Aug 13 02:56:41 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 13 Aug 2004 16:56:41 +1000 Subject: The winner of the Python Decorator Poll is... In-Reply-To: <4edc17eb.0408112052.1bbd85b3@posting.google.com> References: <4edc17eb.0408112052.1bbd85b3@posting.google.com> Message-ID: On 11 Aug 2004 21:52:03 -0700, Michele Simionato wrote: > So the poll is unavoidably biased. Happily, we are not in a democracy! Hey, Python is a one-man-one-vote setup. And the name of the man with the vote is Guido. From ptmcg at austin.rr._bogus_.com Fri Aug 6 10:55:50 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 06 Aug 2004 14:55:50 GMT Subject: @decorators References: <1091800879.399791@news.commspeed.net> Message-ID: "Tom B." wrote in message news:1091800879.399791 at news.commspeed.net... > > "daishi" wrote in message > news:d22692a3.0408052233.3459c3fa at posting.google.com... > > For what it's worth: > > > > As far as I know, the proposed @decorator syntax will be the first > > time that two logical lines of python with the same indentation will > > not be independent of one another. Previously, when looking at: > > > > I think the @decorator syntax was invented by Microsoft to sabotage Python, > > Tom > > Heeey, let's keep it civil!!! From peter at engcorp.com Mon Aug 16 23:19:16 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 23:19:16 -0400 Subject: Python secure? In-Reply-To: References: <2xXTc.3775$bJ2.24876@news1.mts.net> Message-ID: Reid Nichol wrote: > And because some M$ employee did something sloppy it is an implication > that C is bad. Hell, even strncpy can be dangerous. How many times do > I have to say the responsibility is the programmers, *not* the language. The *responsibility* is clearly the programmer's, but the *language* tends to encourage or discourage certain kinds of programmer behaviour, including the writing of secure code. Surely you wouldn't argue that all languages promote different kinds of coding equally well, or even that the choice of language has *no impact whatsoever* on how a programmer will code, or what kinds of solutions he will attempt to use in his code? -Peter From me at privacy.net Mon Aug 9 13:00:56 2004 From: me at privacy.net (Dan Sommers) Date: 09 Aug 2004 13:00:56 -0400 Subject: Class optimization at runtime References: <78b6a744.0408090559.65560369@posting.google.com> Message-ID: On 9 Aug 2004 06:59:47 -0700, gry at ll.mit.edu (george young) wrote: > How about the pygtk style "require": > import pygtk > pygtk.require('2.0') > import gtk # uses state set by the "require" call. > This always seems a clean interface to me. Much safer and cleaner > than something peeking at a global (or environment) variable. Our mileage has varied. That one always seemed very unclean to me. In my mind, pygtk sits on top of gtk, and that interface requires gtk to look "up" to figure out what to do. Nothing inside gtk should depend on (or even know about) anything inside pygtk. Regards, Dan -- Dan Sommers Never play leapfrog with a unicorn. From newsgroups at jhrothjr.com Fri Aug 6 09:48:26 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 6 Aug 2004 09:48:26 -0400 Subject: @decorators References: Message-ID: <10h73e5kh1et536@news.supernews.com> "Roy Smith" wrote in message news:roy-B53A92.08194306082004 at reader1.panix.com... > A few random comments: > > > I'm also thinking about programming by contract. It seems like the pre- > and post-condition assertions could also be thought of as meta-data. > Some of the examples in the PEP hint at doing this, but don't address > things contract inheritance. Has there been any discussion of this? There are several DBC packages out there. I can't give you any pointers because I don't do things that way, but I've seen some rather enthusiastic comments. All of the existing packages (at least to my knowledge) use descriptors to wrap the necessary functions. They could be very easily reimplemented in terms of the decorator syntax. However, the decorator syntax brings no new functionality to the table; it's simply syntactic sugar for already existing functionality. It may, of course, improve readability, which is always desirable. > Lastly, and perhaps most importantly, I'm rather distressed at the tone > of some of the postings I've seen here over the past couple of days. > Some of the sentiments I've seen expressed are downright rude, > combative, and accusatory. These sorts of things are way out of line. Likewise. John Roth From beliavsky at aol.com Mon Aug 30 10:18:09 2004 From: beliavsky at aol.com (beliavsky at aol.com) Date: 30 Aug 2004 07:18:09 -0700 Subject: Help with Fortran output References: Message-ID: <3064b51d.0408300618.7b5fe129@posting.google.com> "Kumbale, Murali T." wrote in message news:... > I am new to Python and redirection etc. I created a simple COM object > in Visual FORTRAN called "disp.disp" that writes to the WINDOWS console. > I wrote a Python script which looks like the following > > import win32com.client > o = win32com.client.Dispatch("disp.disp") > o.SimpeAdd(5) > > SimpleAdd method takes the argument supplied (the number 5 in this case) > and adds 10 to it and then writes to FORTRAN standard output using > WRITE(6,...). This bombs as I don't know how to capture the FORTRAN > output written to WINDOWS console to Python console. Please help. I am ignorant of COM, but Fortran (or other) standard output can be captured by Python. If I compile the Fortran program write (6,*) "hi from Fortran" end to an executable 'foo.exe' and have a Python script 'xread.py' import sys text = sys.stdin.readline() print text then typing at the Windows command prompt 'foo.exe | python xread.py' gives the output hi from Fortran If this does not answer your question, your problem may be Fortran-specific -- consider posting to comp.lang.fortran or (even better) to the Intel Visual Fortran discusssion forum. From google at daishi.fastmail.fm Sat Aug 7 02:46:16 2004 From: google at daishi.fastmail.fm (daishi) Date: 6 Aug 2004 23:46:16 -0700 Subject: @decorators References: <10h6v76mm313cce@news.supernews.com> Message-ID: "Terry Reedy" wrote in message news:... > And the same examples apply: > > if like(atdeco): print 'hooray' > else: print 'boo' > > Terry J. Reedy I apologize if I've phrased things poorly/imprecisely, but in large part your example exemplifies the point that I was trying make in my previous message: decorators seem like they belong in or are themselves compound statements. The current proposed formatting seems to me like: else print 'boo' if like(atdeco): print 'hooray' From squirrel at WPI.EDU Thu Aug 5 13:28:50 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 5 Aug 2004 13:28:50 -0400 Subject: RELEASED Python 2.4, alpha 2 In-Reply-To: References: <411231C8.3020308@interlink.com.au> Message-ID: On Thu, 5 Aug 2004, Heiko Wundram wrote: > Now tell me that using decorators to do synchronization isn't a lot easier to > read than the first (old) example is, and also less error-prone (resp. > acquiring/releasing locks properly and without deadlocks). I'll admit synchronization is a strong use case (since I don't believe it justifies language support, like it has in Java), but I just think there's a better way to go about things that no-one's thought of yet. From squirrel at WPI.EDU Thu Aug 5 12:12:59 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 5 Aug 2004 12:12:59 -0400 Subject: Confused about pep 318 In-Reply-To: References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: On 5 Aug 2004, Steven Bethard wrote: > Wow, this one really feels like it was slipped in while no one was > looking. That's because it was. > While I don't go to Python conferences, I do occasionally > check python-dev, and I totally missed whatever thread introduced the > @ syntax. Scary... This is the post that started it all: http://mail.python.org/pipermail/python-dev/2004-August/046599.html Quote: The @decorator patch has been landed on the trunk, after getting the go-ahead from the BDFL. I'll update PEP-0318 with the final syntax in the next day or so. That's the first most people had heard of it. Guido had given Anthony Baxter the go-ahead in a private e-mail. There had previously been no public discussions about it. > Not a big fan of this syntax -- no intuitive reason why @ would mean > decorator -- but I presume this has already been complained about... It has, but the more people complaining, the better, if you're against it. From kjetilho at yksi.ifi.uio.no Fri Aug 27 07:29:58 2004 From: kjetilho at yksi.ifi.uio.no (Kjetil Torgrim Homme) Date: Fri, 27 Aug 2004 13:29:58 +0200 Subject: allowing braces around suites Message-ID: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> often when re-factoring code, I need to change the indent level of some chunk of code. due to the lack of an end marker, my Emacs has to use heuristics when re-indenting, and this will occasionally lead to mistakes. of course this is really _my_ fault, not Emacs', but it's annoying all the same. a colleague uses #fi, #yrt etc. to mark the end of blocks, but I don't find this satisfactory since neither Python nor Emacs has any knowledge of what the magic comment means. my suggestion is to allow braces to mark the suites. Python is still strictly enforcing indentation, in fact, in some ways it's stricter then before. code which uses braces and is wrongly re-indented will always cause a syntax error during compilation. code could look like this: def appraise_insurance(rental_cars): { assert isinstance(rental_cars, (list, tuple)) for car in rental_cars: { if car.make == "Lamborghini": { car.insurance = 1000.00 } elif car.make == "Lada": { car.insurance = 50.00 } else: { car.insurance = 100.00 } } logger.debug("Insurance values updated") } now, I don't suggest to write code like that, that has far too much air between actual codelines. I'd only add the braces where there is a risk re-indentation changing the meaning of the program, like this: def appraise_insurance(rental_cars): assert isinstance(rental_cars, (list, tuple)) for car in rental_cars: { if car.make == "Lamborghini": car.insurance = 1000.00 elif car.make == "Lada": car.insurance = 50.00 else: car.insurance = 100.00 } logger.debug("Insurance values updated") the single pair of braces is enough. there is now no risk of Emacs including the debug line into the else branch unnoticed. the patch to implement this is very simple and restricted to the tokenizer. as it stands, it requires the braces to be placed as in the above examples, you _can't_ write if True: { code } else { code } a single braces style improves readability and style consistency among software projects. my patch does allow two styles, though: to reduce line count you can put the else: on the same line as the closing brace. if True: { code } else: { code } in both styles, the braces line up and IMHO this makes it easier to identify where a medium sized block begins and ends. there can be no code after an opening brace, but it's a good place to put a comment, so in practice the number of added lines may not be so large. a small caveat: it breaks code which looks like this: def test_varargs1(self): """some text""" {}.has_key(0) this function is taken from Lib/test/test_call.py, but the doc string was added to make my patched Python reject it with a syntax error. the problem is that a brace at the same indent level as the line above will always mark the beginning of a new suite. I don't think such code is widespread, but would be interested in hearing contrary experiences. one fix for this issue is to have the parser tell the tokenizer whether "a suite may follow" when it asks for the next token, but I haven't persued writing such a patch. a patch relative to Python 2.4a2 is available at http://heim.ifi.uio.no/~kjetilho/hacks/braces-python-2.4a2.patch what do you think? should I write a PEP? -- Kjetil T. From steven.bethard at gmail.com Wed Aug 11 11:17:57 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: 11 Aug 2004 08:17:57 -0700 Subject: remaining decorator syntax options References: Message-ID: Shalabh Chaturvedi wrote in message news:... > @staticmethod > @foo.moredecoration(a="hello",b="world") > @foo.bar.baz() > def myfunc(): > > vs. > > using [staticmethod ,foo.moredecoration(a="hello",b="world"), foo.bar.baz()] > def myfunc(): > > (I find the first version clearer.) Yup. Though I think most people would write the second option something like: using [staticmethod, foo.moredecoration(a="hello",b="world"), foo.bar.baz()] def myfunc(): (with, of course, a hundred different tabulation options there, but you get the idea). My point was that with the keyword, you save a lot of keystrokes using the list if you have a large number of decorators, but with a single symbol, of course, using a list only adds keystrokes. You make some good points though, and I would be just as happy with: using staticmethod using foo.moredecoration(a="hello",b="world") using foo.bar.baz() def myfunc(): > Btw, I think your summary of the current state is good. However I feel a > new keyword has been pretty much ruled out as well. Can you refer me to some pages that made you feel this way? GvR said that he "won't rule it out just because of the new keyword": http://mail.python.org/pipermail/python-dev/2004-August/047001.html I also haven't seen any arguments against keywords that said anything but basically "introducing a new keyword might break existing code". Not that this isn't a valid argument, but as Python has gone through a similar process recently for 'yield', I'd feel more like keywords were ruled out if I heard some other arguments. Steve From max at alcyone.com Mon Aug 23 21:13:10 2004 From: max at alcyone.com (Erik Max Francis) Date: Mon, 23 Aug 2004 18:13:10 -0700 Subject: Getting at the bits of a 32-bit integer References: <85b54e91.0408231552.75f85727@posting.google.com> <412A8B00.A81AA015@alcyone.com> Message-ID: <412A9626.CB94955@alcyone.com> Phil Frost wrote: > Then you have paid the cost of a bool, and then some. If someone's interested in using a bitfield to store flags, they're obviously interested in more than one bool! Now you're talking about one long vs. a list and n bools. -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ Freedom is never voluntarily given by the oppressor. -- Dr. Martin Luther King, Jr. From rubyguru at hotmail.com Tue Aug 24 23:42:55 2004 From: rubyguru at hotmail.com (Chris Dutton) Date: Wed, 25 Aug 2004 03:42:55 GMT Subject: Inline Conditionals? In-Reply-To: References: Message-ID: <3VTWc.200749$M95.84528@pd7tw1no> Adonis wrote: > How about something like: > > >>>>def iif(condition, true=True, false=False): > > ... if condition: > ... return true > ... return false > ... Just a thought, but this would have unexpected results if used with function calls, if those function calls had side-effects, since both are evaluated, whereas the ternary operator in other languages only evaluates one of the possible expressions. From tim.peters at gmail.com Sat Aug 7 17:18:32 2004 From: tim.peters at gmail.com (Tim Peters) Date: Sat, 7 Aug 2004 17:18:32 -0400 Subject: Going the PL/1 way In-Reply-To: References: Message-ID: <1f7befae04080714183678907e@mail.gmail.com> [Jarek Zgoda] >>> Come on, guys, fix real problems like interpreter thread safety, >>> improve performance, don't make us, "real-world software >>> developers", screaming with every new release, please. [Michael Hudson] >> http://www.python.org/patches/ [Jarek] > You want to say "if you want any improvement, do it yourself"? Sure, > it's much better than Java's JCP, but expect > http://catb.org/~esr/jargon/html/F/fork.html if enough people will share > the same annoyance and anger. I don't understand. If you believe that nobody is volunteering work on things you want them to work on now (which may well be true, although it's false that volunteers don't contribute work on thread and performance issues already), how could merely forking Python make such volunteers appear? > I write some free software, but I never tell users "go fix it yourself". > This is rude. Under the assumption that volunteers exist who want to work on what you want them to work on, but that they've somehow managed to miss Python's patch tracker, Michael was helpfully giving them the one clue they still needed to make you happy . From mike at nospam.com Mon Aug 16 17:30:10 2004 From: mike at nospam.com (Mike Rovner) Date: Mon, 16 Aug 2004 14:30:10 -0700 Subject: Flython? References: <411cbcb1$0$3894$4d4ebb8e@news.nl.uu.net><30260531.0408131856.5ef3b0d3@posting.google.com> <2oc547F86br8U1@uni-berlin.de> <2oc7ufF86br8U2@uni-berlin.de> Message-ID: Daniel Ellison wrote: > Mike Rovner wrote: > The swf file format is proprietary, yes, but the spec is public; you > can download it from Macromedia's web site, as Peter did recently. Right. Thanks for the tip. Here is the link: http://www.macromedia.com/software/flash/open/licensing/fileformat/ (v7) Mike From peter at engcorp.com Tue Aug 3 19:03:12 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 03 Aug 2004 19:03:12 -0400 Subject: Crypto.PublicKey.RSA.error: Plaintext too large In-Reply-To: References: Message-ID: Ajay Brar wrote: > Peter Hansen wrote: >> Ajay Brar wrote: >>> I am getting an error - Crypto.PublicKey.RSA.error: Plaintext too >>> large - when verifying the signature of a document. ... >> >> Carriage Return/Line Feed problems? Or trailing newline problems? > > thats what i am going to investigate now. But even if there were > trailing newline or carriage return characters, shouldn't the verify > return false instead of giving the error. I couldn't say, not having used that particular API. What does the documentation say it should do? Always return just True or False? Does it not make reference to this type of error? -Peter From sholden at flexal.cs.usyd.edu.au Fri Aug 13 02:54:11 2004 From: sholden at flexal.cs.usyd.edu.au (Sam Holden) Date: 13 Aug 2004 06:54:11 GMT Subject: Why I love python. References: Message-ID: On Fri, 13 Aug 2004 16:35:58 +1000, Anthony Baxter wrote: > On Fri, 13 Aug 2004 01:11:54 +0000 (UTC), Nick Patavalis > wrote: >> > Don't complicate it. Leave it as is. Work on making it faster, not >> > uglier. >> >> Python needs drastic performance improvement if it is to scrap-off the >> "scripting language" stigma. > > I'm biased, having done a paper on this at the most recent PyCon, but > I firmly believe that much of the "Python is too slow" arguments can be > answered with "too slow for what?" See the pycon proceedings, but I've > been doing VoIP in Python, complete with audio mixing, and it's been > more than fast enough. I've also been doing rtp voice in python - on an iPAQ H3800... I'm using your rtp.py code (I'm not doing sip), so I can't take credit for it though :) I dont know if it's "more than fast enough", but it's "fast enough". -- Sam Holden From timothy.grant at gmail.com Thu Aug 26 19:49:27 2004 From: timothy.grant at gmail.com (Timothy Grant) Date: Thu, 26 Aug 2004 16:49:27 -0700 Subject: Sound file manipulation in Python In-Reply-To: References: Message-ID: On Thu, 26 Aug 2004 22:24:33 +0100, Paul Moore wrote: > Does anyone know of a Python library which handles sound file formats > (MP3, Ogg, FLAC are the three I'm nost interested in). I'd like > something that can manipulate "metadata" - stuff like artist, title, > album tags. I'm not critically interested in format conversion, or > playing sound files - I can handle that with other applications. > > I'm using Windows, and Python 2.3, if it matters (as it might for C > extensions). > > I can manage with just reading the metadata, but ideally writing > would be useful, too. Multiple libraries is OK, but I need something > more than just MP3. > > If there's nothing available for Python, does anyone know of a good C > library that could be wrapped? (Or used via ctypes, maybe). > > Thanks, > Paul. > -- > Ooh, how Gothic. Barring the milk. > -- > http://mail.python.org/mailman/listinfo/python-list > I'm playing with some of those things right now. You may want to look at mad and id3tag. I know there are several others that allow you to work with ID3 Tags. -- Stand Fast, tjg. From ivan at ivan-herman.net Sun Aug 15 07:28:22 2004 From: ivan at ivan-herman.net (Ivan Herman) Date: Sun, 15 Aug 2004 13:28:22 +0200 Subject: importing node into document In-Reply-To: References: Message-ID: <411f48c8$0$123$1b2cd167@news.wanadoo.nl> In terms of XML two documents represent two different 'worlds'; a Node also includes a reference to its own document, ie, you cannot easily mix/merge etc, nodes in different namespaces. This reference is read only. (As I already answered in one of your other messages, you should really consider looking at the original DOM specification. That clearly flags the 'ownderDocument' as 'readonly'!). What you have to do is (recursively) create a new node in your target document with the name of the original, then copy the attributes and (recursively) the children. Ivan Ajay wrote: > hi! > > is there an equivalent for the Java document.importNode in Python > what i am trying to do is to import a node from a different document into > the current document and then append it one of the nodes in the current > document > tempNode.ownerDocument = node.ownerDocument > #the above gives an error saying i am trying to modify a reda-only > attribute > #if i omit the statement, the statement below throws an error saying they > #the nodes are from different document > node.appendChild(tempNode) > > thanks > > cheers > > > > > > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. From adurdin at gmail.com Sat Aug 21 23:31:43 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Sun, 22 Aug 2004 13:31:43 +1000 Subject: Overriding logical operators? In-Reply-To: References: Message-ID: <59e9fd3a04082120316c23ebfb@mail.gmail.com> On Sat, 21 Aug 2004 21:38:01 -0400, Michael J. Fromberger wrote: > > The implementation of "and" and "or" are special, as others have pointed > out. However, you do have some control over how they behave for objects > of user-defined classes. By overriding __nonzero_, you can define > whatever truth value you like for instances of a user-defined class. I suppose now I ought to say why I need to to do more than that. I've got a situation where I want to construct an expression, but evaluate it later when I get more information. I came up with a "DelayedEval" class, the instances of which can have operations performed on them, but the result is not evaluated until a particular method is called. I'm currently overriding all the operators I can, so that these instances can be handled in a fairly normal fashion for the most part. For example: foo = DelayedEval() foo = (-foo + 15) * 3 foo_positive = (foo >= 0) print foo.evaluate(10) # prints 15 print foo.evaluate(20) # prints -15 print foo_positive.evaluate(10) # prints True print foo_positive.evaluate(20) # prints False In this situation, merely overriding the __nonzero__ method will not allow me to delay the evaluation of the logical boolean operators; to do that I need to be able to override them. The alternative solution that I can see to the issue is to use lambdas to create the expressions I need, and calling them to evaluate them, e.g.: foo = lambda v: (-v + 15) * 3 foo_positive = lambda v: (foo(v) >= 0) This will work, but having to manually chain the evaluation in this way is a little awkward. It also doesn't allow me to print the expressions. With the DelayedEval class, I can do this: print foo_positive # prints (((-(value) + 15) * 3) >= 0) From ramen at lackingtalent.com Wed Aug 4 12:08:36 2004 From: ramen at lackingtalent.com (Dave Benjamin) Date: Wed, 04 Aug 2004 16:08:36 -0000 Subject: checking whether a var is empty or not References: Message-ID: In article , Dave Cole wrote: > Dave Benjamin wrote: >> >> No, in PHP, you can find out if a variable exists using isset(). And trying >> to dereference an uninitialized variable will generate a warning if you have >> error reporting turned up all the way (error_reporting(E_ALL)). > > >>> def isset(var): > ... return var in globals() > ... > >>> print isset('var') > 0 > >>> var = 43 > >>> print isset('var') > 1 > > Not that I can see any good use for this :-). Not that there's *any* reason to do anything like this, *ever* ;) but... >>> import inspect >>> def isset(v): ... return v in globals() or v in inspect.currentframe().f_back.f_locals ... >>> isset('a') False >>> a = 5 >>> isset('a') True >>> def f(): ... b = 6 ... print isset('b') ... print isset('c') ... >>> f() True False >>> c = 42 >>> f() True True Verdict: Just catch the NameError, already! =) -- .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:. "When the country is confused and in chaos, information scientists appear." Librarian's Lao Tzu: http://www.geocities.com/onelibrarian.geo/lao_tzu.html From ThomasBartkus at Comcast.net Fri Aug 13 15:35:52 2004 From: ThomasBartkus at Comcast.net (Thomas Bartkus) Date: Fri, 13 Aug 2004 14:35:52 -0500 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: wrote in message news:3064b51d.0408130615.3fc4a760 at posting.google.com... > One of the most commmon reasons programmers cite for not trying Python > is that indentation determines the program flow -- they think its > weird. > I wonder if there is a way to remove this initial barrier. Why? Do we you really want to let just *anyone* in :-) When I explain this about Python and I start hearing that flak, I simply agree and suggest that Python is not for you. Some people should be *forbidden* to move outside of java or VB :-) Thomas Bartkus From peter at engcorp.com Sun Aug 22 08:37:44 2004 From: peter at engcorp.com (Peter Hansen) Date: Sun, 22 Aug 2004 08:37:44 -0400 Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WEDONE? In-Reply-To: References: Message-ID: Robert Brewer wrote: > Paul Rubin wrote: >>Looks like "declare" to me ;-) > > I agree, for reasons which will become clear in the proposal draft. > > I'd be most interested to hear arguments _against_ "declare", if there > are any. Somehow "declare" suggests to me a much stronger meaning than what these decorators are about. In other languages, you actually "declare" data types or functions. Decorators are not so significant, as they merely decorate the function to-be-defined. "using" seems best to me, largely because it is fairly non-specific (i.e. doesn't have strong connotations of one specific type of decoration, such as 'staticmethod' versus 'author' or some such) and because, as Francesco pointed out, it does seem to introduce a following required clause, where "decorate" and "declare" do not (though for different reasons). -Peter From tdelaney at avaya.com Wed Aug 4 00:11:23 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Wed, 4 Aug 2004 14:11:23 +1000 Subject: Can somebody help me ? Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01C8BFA3@au3010avexu1.global.avaya.com> http://www.catb.org/~esr/faqs/smart-questions.html#prune http://homepages.tesco.net/~J.deBoynePollard/FGA/questions-with-yes-or-n o-answers.html Tim Delaney From secun at yahoo.com Tue Aug 24 10:31:55 2004 From: secun at yahoo.com (ChrisH) Date: Tue, 24 Aug 2004 14:31:55 GMT Subject: Can't run program on Eclipse 3 w/pydev 0.4.2 References: <99bb88dc.0408231246.580a0f73@posting.google.com> Message-ID: The current release is 0.5.3. It will work with Eclipse 3. http://pydev.sourceforge.net/ In article <99bb88dc.0408231246.580a0f73 at posting.google.com>, chakari at acsalaska.net says... > I am trying to run a Python program with the above setup, but I get an > exception error during launch; Error within Debug UI. This happens on > Windows 2000 and on my Linux system. Has anyone run into this, and if > so, found a fix? > From rogerb at rogerbinns.com Wed Aug 11 17:31:41 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Wed, 11 Aug 2004 14:31:41 -0700 Subject: SQL Qeries via XMLRPC References: <3ovlu1-l6f.ln1@home.rogerbinns.com> Message-ID: Fredrik Lundh wrote: > it's fairly easy to plug in your own transports (just subclass > Transport, override as necessary, and pass an instance of your custom > transport > to the ServerProxy class). I did actually try for two weeks. In my case I wanted both the persistent connections, and also to work over HTTPS (I had to use m2crypto for the SSL not the stuff builtin to Python in order to deal with certificate issues). I had to give up in the end. The thread on "useless destructors" was particularly appropriate as a lot of the code was manually closing things and most of the work was to try and circumvent that. I ended up just using SSH (paramiko) which took me about two hours :-) Someone as illustrious as yourself may be able to fix it, but I do believe it will be harder than it initially appears :-) Roger From olivier.parisy at free.fr Sun Aug 29 06:31:57 2004 From: olivier.parisy at free.fr (Olivier Parisy) Date: Sun, 29 Aug 2004 12:31:57 +0200 Subject: Enumerating Network Adapters Message-ID: <4131b09e$0$13683$636a15ce@news.free.fr> Hi all, I'd like to get, in a portable way, a list of all network adapters on a local machine running some python code. socket.gethostname() does not seem enough, as it only returns one name ; I'd like to get all available IPs. I could process ipconfig or ifconfig outputs, but this is OS-dependant and not very future-proof... Best regards, Olivier Parisy. From aahz at pythoncraft.com Wed Aug 18 10:42:20 2004 From: aahz at pythoncraft.com (Aahz) Date: 18 Aug 2004 10:42:20 -0400 Subject: generating uuids / guids References: <2nhnrfF13jq0U1@uni-berlin.de> Message-ID: In article , Jonathan P. wrote: >aahz at pythoncraft.com (Aahz) wrote in message news:... >> >> Sure it would. Best way to start is to create a stand-alone third-party >> library that implements the full DCE spec. Once it has proven its >> utility and stability, send a note to python-dev suggesting that it be >> added. >> >> Keep in mind that UUID generation is a somewhat complex and tricky >> business will likely require some kind of C library support (to get the >> MAC address, to check if there's already a system-level UUID/GUID >> generator present, to provide a "good" UUID if there's no network card, >> and so on). > >Aren't there already uuid generation routines in both Linux and >Windows and wouldn't all that's needed be to wrap them in Python? Absolutely. However, I don't know if any of them are cross-platform, and if you have any intention of getting this into the standard library, it'll need to be readily available on any platform with an ANSI C compiler. Packaging is *NOT* trivial, and that's precisely why it's rare to see code added to the standard library until it has proven itself. If you can find a way to implement this in pure Python, that probably gives the biggest boost to the likelihood of getting into the standard library. Python 2.4 is too far along to add this; that gives you 12-18 months for working this into usable shape. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From jjl at pobox.com Thu Aug 12 15:42:33 2004 From: jjl at pobox.com (John J. Lee) Date: 12 Aug 2004 20:42:33 +0100 Subject: ClientCookie References: <6f402501.0408110018.1e4e5ca8@posting.google.com> <87acx1qo1z.fsf@pobox.com> <6f402501.0408120113.746639d4@posting.google.com> Message-ID: <874qn8i1na.fsf@pobox.com> fuzzyman at gmail.com (Michael Foord) writes: [...] > The program I'm writing is a CGI. I'd like to have *minimum* > dependencies. > The version of Python on the server is 2.2 (I have no control over > that) and having a dependence on CookieClient is enough for me. I > think I can only use BSDDBCookieJar if the server has the Berkely > Database installed ? Yes. > I'd like other people to be able to use my CGI on > a basic Python 2.2 install - so even if I have it on my server, I > don't want to be dependent on it. [...] The BSDDB-wrapper is a fairly standard Python std. lib. module for unix machines. I don't know what small-scale commercial CGI hosting companies offer ATM, though. John From aleaxit at yahoo.com Mon Aug 30 03:05:13 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 30 Aug 2004 09:05:13 +0200 Subject: If the string module is deprecated... References: Message-ID: <1gjabby.tbyc63wg8zdrN%aleaxit@yahoo.com> Paul McGuire wrote: > ... what will become of the module-level constants, such as uppercase, > digits, hexdigits, etc.? Will they become class-level constants of the str > class? That would seem the most natural solution, yes. Taking advantage of that change, it might be good to have in classes str (and unicode) only real constants, independent of locale, and move locale-dependent stuff to module locale. Other related issues were debated in the relatively recent past on python-dev -- e.g., if we have str.digits, how do we discourage beginners from (most likely incorrectly) testing 'if c in str.digits' where they should be coding 'if c.isdigit()' instead? Or do we? Or should we perhaps make str.digits (&c) instances of a funky black-magic subclass of str with a __contains__ method whose semantics are quite different from str's own implementation of that method? It is definitely true that beginners just love coding tests such as 'if c in str.digits' &c... they're doing so in droves today with string.digits... I don't recall a consensus being reached, which may be why nothing much has happened yet on this score. Alex From kosh at aesaeion.com Mon Aug 2 04:51:44 2004 From: kosh at aesaeion.com (kosh) Date: Mon, 2 Aug 2004 02:51:44 -0600 Subject: transforming a list into a string In-Reply-To: References: Message-ID: <200408020251.44520.kosh@aesaeion.com> On Saturday 31 July 2004 6:44 am, Peter Otten wrote: > jblazi wrote: > > Let us assume I have a list like > > > > ['1','2','7','8','12','13] > > > > and would like to transoform it into the string > > > > '{1,2},{7,8},{12,13}' > > > > Which is the simplest way of achiebing this? (The list is in fact much > > longer and I may have to cut the resulting strings into chunks of 100 or > > so.) > > > >>> from itertools import izip > >>> items = ['1','2','7','8','12','13'] > >>> it = iter(items) > >>> ",".join(["{%s,%s}" % i for i in izip(it, it)]) > > '{1,2},{7,8},{12,13}' > > > Peter This way also works I am not sure how it compares on large sets for memory usage, cpu time etc. items = ['1','2','7','8','12','13'] if len(items)%2 == 0: #the len check is to make sure that the length of the set is evenly #divisible by 2 output = "{%s,%s}" * (len(items)/2)% tuple(items) From paolo_veronelli at yahoo.it Fri Aug 13 07:25:35 2004 From: paolo_veronelli at yahoo.it (paolo veronelli) Date: Fri, 13 Aug 2004 13:25:35 +0200 Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: References: Message-ID: On Thu, 12 Aug 2004 22:59:46 -0400, Peter Hansen wrote: > paolo veronelli wrote: > >> This 'old' method doesn't allow to prepone it,I think a statement was >> the way to allow this ,but why impone it? > > Sorry, that's not English, and I'm afraid I can't infer what > you mean by "prepone" and "impone"... (impone apparently > means "to wager", but I don't think that's what you meant). This f=mutate(f) method doesn't allow to be stated before the def of f,I think a statement (in place of a function call) is the right way to allow a declaration on f before the def of f,but why put it before has to be an obligation ? If we don't specify the name of the function after the new keyword we are obliged to put the decoration statement in that place (right before the def). If python is not a democracy (I wouldn't shout it happy anyway),this doesn't mean there should be no freedom. Still awful I know ;-] Paolino -- ....lotta dura per la verdura From jerf at jerf.org Mon Aug 23 22:00:44 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Tue, 24 Aug 2004 02:00:44 GMT Subject: Getting at the bits of a 32-bit integer References: <85b54e91.0408231552.75f85727@posting.google.com> <412a98f4$0$65569$a1866201@newsreader.visi.com> Message-ID: On Tue, 24 Aug 2004 01:25:09 +0000, Grant Edwards wrote: >> However, I must challenge your need to do this in the first place. > > That's a bit, um, conceited. I said "challenge", not "deny". If you're new to Python and you are twiddling bits, the odds favor the new user falsely importing old paradigms from other languages, not needing to do the twiddling. Of course, in lieu of a problem specification, that's all we can say. I stand by my message. (And before you jump on this one, please understand that I use language precisely; unlike a lot of people, when I say "odds favor", I mean just that. It is not code for "not a chance in hell" or "absolutely".) From ziller at gmail.com Sat Aug 7 11:57:56 2004 From: ziller at gmail.com (ziller) Date: 7 Aug 2004 08:57:56 -0700 Subject: Importance of C# (was Re: IronPython-0.6 is now available!) References: <278de0e.0407281353.27b6a457@posting.google.com> <5dydnZSDZaARoZXcRVn-ug@powergate.ca> <1n5z28erh2m3u.dlg@baczek.net.invalid> Message-ID: <537ea4cd.0408070757.14790cfe@posting.google.com> > After reading a tutorial on c#, I see immediately that it has all the > features that I disliked in Java. > > 1) Everything is derived from "Object" Pure OO is supposed to be an advantage. Otherwise casting hacks have to be used and understood. > 2) Some things have value semantics, some have reference Like arrays having reference semantics? That's how memory is layed out in assembler, C, . This just shows how you need a little understanding of how the architecture works under the hood to really grasp why things are done a certain way in a language. It's intuitive and correct if you understand it properly (and there is no alternative if speed is a concern). > 3) No multiple inheritance This has been covered to death. MI implementation is a nightmare. I'm sure some design pattern would map any 'needed' MI solution to an equivalent one using interfaces and SI. > I'm not sure about 2 others: > > 4) No serious generic programming support It'll be there for 2.0. And the implementation is superb (much like Eiffel's generics) > 5) Only OO supported: Good. I didn't like OO originally either. But if you just look at it from the perspective of having another layer of abstraction then it does make lots of sense pragmatically (a good thing: sort of like modules->packages). Isn't it... From sjdevnull at yahoo.com Tue Aug 10 02:09:36 2004 From: sjdevnull at yahoo.com (G. S. Hayes) Date: 9 Aug 2004 23:09:36 -0700 Subject: decorators vs GIL References: <96c2e938.0408081605.706f8ec7@posting.google.com> <10hg5r1hr3g361a@corp.supernews.com> Message-ID: <96c2e938.0408092209.490d48c5@posting.google.com> Jeff Shannon wrote in message news:<10hg5r1hr3g361a at corp.supernews.com>... > Threads seem to only be essential when > long-running background tasks are involved. There's a large set of GUI > programs where this is not an issue. Threads aren't essential even there; processes are not only acceptable but preferrable in most cases. The rest of your post was spot-on, exactly the points I've been trying to convey. From peter at engcorp.com Wed Aug 25 09:45:55 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 25 Aug 2004 09:45:55 -0400 Subject: Python future performance and speed In-Reply-To: References: <278de0e.0408211605.426e5129@posting.google.com> Message-ID: Jacek Generowicz wrote: > Peter Hansen writes: >>The last time I checked, Java and C++ (even C) were widely >>considered to be high level languages. > The fact many people hold an erroneous belief, does not make said > belief any less erroneous. Though if you are the only one who holds the "correct" belief, and everyone else has the erroneous belief, it should suggest a possible direction for you to look in resolving the conflict. ;-) >>Has someone been raising the bar while I wasn't looking? > The developers of all the truly high-level languages ? > > There was a time when assembler was high-level. For those of us who still use assember from time to time, C is definitely still a high level language... -Peter From jepler at unpythonic.net Tue Aug 24 14:45:54 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 24 Aug 2004 13:45:54 -0500 Subject: Time-date as an integer In-Reply-To: <412ADFCB.5070902@earthlink.net> References: <412ADFCB.5070902@earthlink.net> Message-ID: <20040824184553.GB8826@unpythonic.net> datetime.utcnow() is implemented in terms of gettimeofday, for platforms that have it. So is time.time(). I suggest that you use def calcNodeId(self): return long(time.time() * 1e6) Note that on this system (a 2.4GHz desktop PC), I can write a Python program that calls time() close enough together to get the same timestamp twice, though calls to calcNodeId are consistently taking over 1usec. If you're relying on this method to give you unique identifiers on a system that will run a few years from now---or even a machine just 50% faster than this one, or after the next, faster version of Python is released--- with identifiers being generated at full tilt, you'll probably be disappointed. def main(): from time import time min_diff = 1 min_t = None for i in range(1000): t = time(), time() diff = t[1]-t[0] if diff < min_diff: min_t = t min_diff = diff print min_diff, min_t main() $ python mindiff.py 0.0 (1093372528.113651, 1093372528.113651) $ python mindiff2.py # version using calcNodeId 1 (1093372993811409L, 1093372993811410L) Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From roy at panix.com Sun Aug 15 20:54:53 2004 From: roy at panix.com (Roy Smith) Date: Sun, 15 Aug 2004 20:54:53 -0400 Subject: Python secure? References: <411ffef6$0$65603$a1866201@newsreader.visi.com> Message-ID: In article <411ffef6$0$65603$a1866201 at newsreader.visi.com>, Grant Edwards wrote: > On 2004-08-15, Roger Binns wrote: > > Calvin wrote: > >> Sorry I should have said I'm new to programming let alone Python. I > >> wish to know whether Python is secure as an exe for a commercial > >> product. > > > > Yes. Anyone who recovers your "code" and/or uses it will be in > > violation of copyright > > I don't see how decompiling is a copyright violation. If I buy > a copy of a book, I'm pretty sure I can translate it into > another language if I want to form my own use. > > Unless the license under which use of the program was granted > forbade de-compiling and reverse-engineering, I don't see why > decompiling is illegal. In some places (Europe?) > reverse-engineering is explicitly allowed by law. > > > > and several other laws. > > What other laws? > > > That is legal protection no matter what languages or > > combination of languages you use. It is illegal for you to walk in my front door when I'm not home, take my silverware, and leave with it. I am basing this statement on the laws applicable to where I live (New York City), but am reasonably sure it's pretty much the same in most places. That being true, it's still a good idea for me to lock the door when I leave the house. From crichton314 at btinternet.com Sun Aug 22 19:36:38 2004 From: crichton314 at btinternet.com (John Crichton) Date: 22 Aug 2004 16:36:38 -0700 Subject: Jython/Python and javax.swing.* References: <2004082212534416807%birded@verizonnet> Message-ID: <3b2846c4.0408221536.54bdf1e5@posting.google.com> Sherrod Faulks wrote in message news:<2004082212534416807%birded at verizonnet>... > I'm using Jython and in the python script I do: > > from javax import swing > result = javax.swing.JOptionPane.showInputDialog(wC, cmd[8:],"Prompt > from " + client.serverName, JOptionPane.PLAIN_MESSAGE) > > wC is a JFrame, cmd is a String and client.serverName is a String. > It won't show the JOptionPane, why? Hi Sherrod, Hope this helps. It's a bit longer than your script. (I've also changed 'client.serverName' to 'client_serverName' to make my script work - but this is only cosmetic and 'client.serverName' will work fine in your script assuming it resolves to a string.) import javax.swing.JOptionPane as JOptionPane import javax.swing.JFrame as JFrame wC = JFrame('jython') cmd = 'JythonJython' client_serverName = 'name' result = JOptionPane.showInputDialog(wC, cmd[8:],"Prompt from " + client_serverName, JOptionPane.PLAIN_MESSAGE) Best wishes, John From FBatista at uniFON.com.ar Fri Aug 6 12:24:10 2004 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Fri, 6 Aug 2004 13:24:10 -0300 Subject: Finding a function name Message-ID: [Tim Williams] #- How can I find a function's name from within the function? Use inspect.stack(). . Facundo From mattduke at ugcs.caltech.edu Thu Aug 26 14:43:10 2004 From: mattduke at ugcs.caltech.edu (Matt Doucleff) Date: 26 Aug 2004 11:43:10 -0700 Subject: tarfile's tar.extractfile() file-like object incompatible with pickle.load()? Message-ID: <3e6d6c21.0408261043.264c3a2d@posting.google.com> Hi everyone! I must be doing something wrong here :) I have a tarball that contains a single file whose contents are a pickled object. I would like to unpickle the object directly from the tarball using the file-like object provided by extractfile(). Attempts to do this result in EOFError. However if I first extract to a temporary file, then unpickle from there, it works. The below code reproduces the problem (on my machine at least). I'm running Python 2.3.4, manually installed on Debian Woody (original python removed). Thanks! This sample code creates (and then removes) files in the tmp directory and in the current working directory. # demonstrates extractfile/unpickle failure (bug?) # pickle a dict to a temp file # create tar file, add temp file to it, close tar file # open tar file for reading # obtain file-like object for pickled file using extractfile() # attempt to unpickle dict from file-like object # fails with EOFError exception import tarfile import pickle import tempfile import os if __name__ == '__main__': try: hashtopickle = { 'a' : 1, 'b' : 2 } # pickle to temp file (fd, tmpfilename) = tempfile.mkstemp() tmpfile = os.fdopen(fd, 'w') pickle.dump(hashtopickle, tmpfile) tmpfile.close() # create tar; add temp file tar = tarfile.open('tarpickle.tar', 'w') tar.add(tmpfilename, 'pickledhash') tar.close() # remove temp file os.remove(tmpfilename) # open tarfile for reading, get filelike tar = tarfile.open('tarpickle.tar', 'r') filelike = tar.extractfile('pickledhash') # fails hashcopy = pickle.load(filelike) finally: # cleanup os.remove('tarpickle.tar') From grante at visi.com Mon Aug 30 18:01:14 2004 From: grante at visi.com (Grant Edwards) Date: 30 Aug 2004 22:01:14 GMT Subject: "Content-Length" header References: <41339d7a$0$8090$a1866201@newsreader.visi.com> Message-ID: <4133a3aa$0$8090$a1866201@newsreader.visi.com> On 2004-08-30, Peter Kleiweg wrote: > Grant Edwards schreef: > >> I'll tell you _one_more_time_: use Ethereal. Here's the >> transaction for your first URL: >> >> GET /~harnad/temp/ariadne-rae.doc HTTP/1.0 >> Host: www.ecs.soton.ac.uk >> User-agent: Python-urllib/1.15 >> >> HTTP/1.1 404 Not Found >> Date: Mon, 30 Aug 2004 21:27:42 GMT >> Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12 >> OpenSSL/0.9.6b DAV/1.0.3 PHP/4.3.2 mod_perl/1.26 >> Connection: close >> Content-Type: text/html; charset=iso-8859-1 >> >> >> >> 404 Not Found >> >>

    Not Found

    >> The requested URL /~harnad/temp/ariadne-rae.doc was not found >> on this server.

    >>


    >>
    Apache/1.3.27 Server at www.ecs.soton.ac.uk Port >> 80
    >> >> >> THERE IS NO CONTENT-LENGTH HEADER. What do you expect urllib >> to do? > > That is because you made a typo. No, I didn't. I did a cut/paste to transfer his code into a file and run it. The OP's program is using invalid URLs. > Use the correct url, and you do get content-length. Tell that to the guy who wrote the friggin' program that contained the URLs. > WTH is Ethereal? www.ethereal.com -- Grant Edwards grante Yow! I want to TAKE IT at HOME and DRESS IT UP in visi.com HOT PANTS!! From rnichol_rrc at yahoo.com Sat Aug 14 01:44:48 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Sat, 14 Aug 2004 00:44:48 -0500 Subject: reading shell output in parallel In-Reply-To: References: Message-ID: Steve wrote: > Hi, > > I'm pretty new to python. I am trying to write a simple application > that can read the stdout output from a command in linux. I've tried > using x = commands.getstatusoutput() but this only gives back the > output in x after finished executing. I would like to read the > contents as it is being shown on the screen and then send parts of > this info over a simple client/server setup. I have the client/server > part set up already. > > Can anyone suggest a simple way to do this? > > Thanks for your help, I appreciate it. > > Steve http://docs.python.org/lib/os-newstreams.html popen2 module http://docs.python.org/lib/module-popen2.html import popen2 cmd_stream = popen2.Popen3(cmd, 1) return_code = cmd_stream.wait() for output in cmd_stream.childerr.readlines(): cmd_output += output You might just want to use popen2/3/4 instead of the class objects. It just depends on your specific needs. What is being printed may be from stdout and/or stderr. Experiment to see what's really coming from where. From nospam at nowhere.hu Sun Aug 8 10:14:09 2004 From: nospam at nowhere.hu (Miklós) Date: Sun, 8 Aug 2004 16:14:09 +0200 Subject: Going the PL/1 way References: Message-ID: "Dominic" wrote in message news:cf59f7$ips$1 at news.uni-kl.de... > > And perhaps he might stay healthy longer than that young one who eats each > > and every new nutriment and colourful shiny berries. > Yes, there is some truth in here. > I knew you were going to write that. ;-) Sure thing I wrote that. :-) > Nevertheless, I think Python has been > pretty feature complete and I am not > sure if @decorators are good or bad. Decorators, the way things are now, will IMHO actively entice people to abuse code. A flawed analogy is computed goto's. We all know by now that 'goto' is evil ;-) but computed goto's (albeit made code flow 'more powerful') only worsened reading the spaghetti code which results in the usage of goto's. > As far as I know they are part > of C# and Java (recently). > Maybe some experience and data > has been gathered by them. Dunno anything about C# but Java decorators are not that 'dynamic'. And IMHO this is a good thing in this case. Cheers, Mikl?s > > Ciao, > Dominic From __peter__ at web.de Tue Aug 24 02:23:11 2004 From: __peter__ at web.de (Peter Otten) Date: Tue, 24 Aug 2004 08:23:11 +0200 Subject: function taking scalar or list argument References: <412a2bce$1_1@127.0.0.1> <9ZCdnT9EuudK3bfcRVn-tA@comcast.com><10il11q5uqfg4ad@corp.supernews.com> Message-ID: Terry Reedy wrote: > > "Steven Bethard" wrote in message > news:loom.20040824T052140-517 at post.gmane.org... >> Well, you can always test for the protocol, e.g.: >> >> def twice(x): >> if hasattr(x, "__iter__"): >> return map(twice, x) > > In 2.2.1: >>>> hasattr([1,2,3], '__iter__') > 0 > so this does not seem to work as you seem to expect. hasattr(iter(x), > '__iter__') will. No it won't: [Python 2.2] >>> hasattr(iter(1), "__iter__") Traceback (most recent call last): File "", line 1, in ? TypeError: iteration over non-sequence Here the only reliable test for iterability is to just try it. Unfortunately, while in most cases you want to treat them as scalars, strings are iterables, too. In 2.3 Steven's proposal works: >>> hasattr(1, "__iter__") False >>> hasattr([], "__iter__") True Peter From kirk at eyegor.jobsluder.net Sun Aug 22 11:59:37 2004 From: kirk at eyegor.jobsluder.net (Kirk Job-Sluder) Date: Sun, 22 Aug 2004 15:59:37 GMT Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> Message-ID: On 2004-08-22, Peter Hansen wrote: > Roy Smith wrote: > >> Speed is the primary limitation for mainstream acceptance of high level >> (aka scripting) languages in general. > Far more likely, it seems to me, is that the primary limitation > for mainstream acceptance of scripting languages(*) in general > is ignorance. I think there are a few other reasons as well. I think that the general python policy of making things clear and obvious is incompatible with software business models that consider compilation and distribution of executables as a way to hide trade secrets. Another problem with interpreted languages is that the interpreter and libraries for might be moving targets. I've not specifically had any problems with python, but I have had problems with an update to R killing functionality for a library I was using. I've also have had problems with some Java applications depending on which JRE I might be running on a system. From tom at livelogix.com Wed Aug 25 23:50:31 2004 From: tom at livelogix.com (Tom Locke) Date: 25 Aug 2004 20:50:31 -0700 Subject: Best processor (i386) for Python performance? Message-ID: <789f72ac.0408251950.e85d23e@posting.google.com> Hi All, I'd be grateful if anyone could provide insight into choosing a good i386 processor for Python performance. Are any of the following of particular importance, or less relevant, with respect to Python? Raw clock speed? Cache size? Bus speed? Intel's Hyperthreading? AMD's 64 bits? What about a dual processor? Can multithreaded Python take advantage of this? Is it stable? Thanks very much, Tom. From martin at koekenberg.net Thu Aug 26 08:04:42 2004 From: martin at koekenberg.net (Martin Koekenberg) Date: Thu, 26 Aug 2004 14:04:42 +0200 Subject: TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' References: <3ptpi0h6i94l7c6raml10o4d3sml2e1etf@4ax.com> Message-ID: Ok mayby that is the solution. but.... How do I set this environmet variable ?? I don't have a lot of linux experience ;-) Thanks, Martin Koekenberg On 25 Aug 2004 15:54:58 -0700, "Brett C." wrote: >Set your environment 'CC' environment variable to gcc and it should go >away. From askari at addressNonValide.com Fri Aug 27 16:55:56 2004 From: askari at addressNonValide.com (Askari) Date: Fri, 27 Aug 2004 20:55:56 GMT Subject: Canvas scrolling - scrollBar become "disabled" on change in canvas Message-ID: Hi, I do a "perso"widget where have two scrolls (one vertical, one horizontal) for a canvas. When, the first time, I added widget in the canvas, the scroll self-ajust and when I move scrollbar, the surface's canvas "moved". But when I deleted (.destroy) this first widgets and that a added other widget, the scrollBar become disabled (ajust for no scroll on the canvas). What/where is the problem? I use basic widget (scrollBar, Canvas, Frame, etc.) from library's Tkinter (and python 2.3.4 on WinXp Pro (sp1)) Askari From aleaxit at yahoo.com Fri Aug 27 13:57:43 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 27 Aug 2004 19:57:43 +0200 Subject: about presicion References: Message-ID: <1gj70q3.1takqhh16igmy4N%aleaxit@yahoo.com> Batista, Facundo wrote: > [alikakakhel3 at hotmail.com] > > > #- I was wondering if it was posible to get very good presicion. I mean > #- like to the to the 100 th or more decimal place. if so how? > > In Python 2.4 you'll have the Decimal module: ...and that's surely the right choice if you want decimal arithmetic. If you want binary float arithmetic with ridiculous numbers of bits of precision, that's one of the GMP features wrapped by gmpy.sourceforce.net ... Alex From jburgy at hotmail.com Mon Aug 16 03:04:41 2004 From: jburgy at hotmail.com (Jan Burgy) Date: 16 Aug 2004 00:04:41 -0700 Subject: Deep Black Magic in Python: please help References: <807692de.0408130310.6e3ed9db@posting.google.com> Message-ID: <807692de.0408152304.283fc76a@posting.google.com> "Terry Reedy" wrote in message news:... > "Jan Burgy" wrote in message > news:807692de.0408130310.6e3ed9db at posting.google.com... > > return arg_dict["one"] + self.bar(arg_dict) > > > It shouldn't be all that hard. My problem is the lookup of 'self.bar'. In > > the AST it looks something like > > > > CallFunc(Getattr(Name('self'), 'bar'), [Name('arg_dict')], None, > None) > > > > How do I find the corresponding function? > > The lookup returns a bound method, whose structure is an implementation > detail. > > Completely untested suggestion, possibly not correct or possible: > > Write an implementation-specific unwrap function. Then either augment the > source code > > .... + unwrap(self.bar)(self, arg_dict) # self now an explict arg > > or the analysis code to do the unwrapping. For the latter, recognize > Name('self') and replace the result of Getattr(Name('self'), 'bar') with > unwrap(thereof) and, again, augment the arg list. > > Terry J. Reedy Hi Terry, Thank you very much for your suggestion. I am not sure how it would help though. What is preventing me now from already replacing the result of Getattr(Name('self'), 'bar') with what I need? That's precisely my problem however. Because Python is a dynamically typed language, I have no information about 'self' at compile-time. Short of saving context information while I am visiting the parse tree, I don't know how to tell what class I am in. Would-Meta-Classes-help-me-in-this-case-ly yours? Jan From calidusdk at hotmail.com Mon Aug 23 18:37:37 2004 From: calidusdk at hotmail.com (Artemisio) Date: 23 Aug 2004 15:37:37 -0700 Subject: line shift? (baby steps 2) References: <6daa8765.0408230412.6db365d6@posting.google.com> <2oueokFe36qgU2@uni-berlin.de> Message-ID: <6daa8765.0408231437.7c37130@posting.google.com> > I was bored waiting on a compile so I hacked this up. It adds the \n and the > Please enter conversion type line and uses the previous poster's comment on > the using a dictionary. > I added the conversion output text by makeing the value a list that is the > conversion and the text to display for the answer (I made them shorter > because I was lazy to type all the information). I also made the conversion > from US to EU more in line with the EUUS because I used those for testing > and the results were not coming out the same (course I am sure there is some > slack in there somewhere for the bank taking its share of the proceeds :) ) > Not sure if there is a slicker way to do the conversion/message - I am > relatively new to Python as well, so my code still ends up looking like C++ > lots of the time. > > import string > > currency = {"EUDK":(7.47,"? to DKK"), > "DKEU":(0.13,"DKK to ?"), > "USDK":(5.93, "$ to DKK"), > "DKUS":(0.16, "DKK to $"), > "EUUS":(1.19, "? to $"), > "USEU":(0.84, "$ to ?")} > > while(1): > currency_choice= raw_input("\nPlease enter conversion type or 'Exit': > ") > currency_str= str(currency_choice).upper() > > if currency_str == "EXIT": > break > if currency.has_key(currency_str): > amount_int= input("Please type the amount you wish to convert: ") > result = amount_int * currency[currency_str][0] > print currency[currency_str][1], " ", amount_int, " = ", result > else: > print("Sorry. At the moment we only support DKK, Euro and Dollars." > + "\n" \ > "Type DKEU if you want convert from DKK to ?," + "\n" \ > "EUDK if you want to convert from DKK to ?," + "\n" \ > "DKUS if you want to convert from DKK to $," + "\n" \ > "USDK if you want to convert from $ to DKK," + "\n" > "EUUS if you want to convert from ? to $," + "\n"\ > "and USEU if you want to convert from $ to ?") Thank you Jeff, that's classy! Also the exit function! Your hack will keep me busy for at least one hour and a half (hence the mentioned baby steps) Allow me a remark though: was the following output intended? "Please enter conversion type or 'Exit': euus Please type the amount you wish to convert: 99 ? to $ 99 = 117.81" I mean the last line. Or am I missing something? Thanx! From jmfbahciv at aol.com Sun Aug 29 06:15:01 2004 From: jmfbahciv at aol.com (jmfbahciv at aol.com) Date: Sun, 29 Aug 04 10:15:01 GMT Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4dyXc.25792$Ot3.22106@twister.nyc.rr.com> <878yc0ucyl.fsf@thalassa.informatimago.com> <20040827135423.154$1T@newsreader.com> <87llfzqmck.fsf@thalassa.informatimago.com> Message-ID: <4131bf4d$0$19722$61fed72c@news.rcn.com> In article <87llfzqmck.fsf at thalassa.informatimago.com>, Pascal Bourguignon wrote: >Ian Wilson writes: > >> David Schwartz wrote: >> >> > wrote in message >> > news:20040827135423.154$1T at newsreader.com... >> > >> >>"David Schwartz" wrote: >> > >> >>> I don't follow you at all. I think you'll find the most useful, >> >>>meaningful complaints about, say, a Ford Explorer from the people who >> >>>drive one every day. >> > >> >>And if they continue to drive one everyday, perhaps you would conclude >> >>that their complaints are insincere. >> > That's a load of crap. >> > DS >> > >> >> >> You're both right but ... >> >> Xah Lee: "I'm starting my own cult to exterminate morons on >> this earth. Two things are on the top of my agenda: Unixism and Perl." >> >> Pascal Bourguignon: >> >> >> Is more like >> >> Joe Blow: I'm going to exterminate all morons who drive a Ford Explorer. >> >> Fred Bloggs: But Joe, you drive a Ford Explorer! >> >> >> Rather than >> >> Joe Blow: Ford Explorers are a little bit expensive to service and the >> doors squeak after a couple of years. >> >> Fred Bloggs: Thanks for the tip Joe, I see you drive one, so you >> should know. > >Case closed. (And probably Xah has suicidal impulses). Nah, he's a Democrat of the Liberal flavor. /BAH Subtract a hundred and four for e-mail. From pm_mon at yahoo.com Sat Aug 14 10:21:00 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sat, 14 Aug 2004 10:21:00 -0400 Subject: Decorators: an outsider's perspective In-Reply-To: <411e1810$0$18621$626a14ce@news.free.fr> References: <9ADC3170-EDAF-11D8-9F63-000A95B336F2@snowtide.com> <411e1810$0$18621$626a14ce@news.free.fr> Message-ID: Christophe Cavalaria wrote: > You are guilty of attacking the specific example instead of the general > idea behind it. > Yes, sorry, but I'm in a pickle here. I want (we need) the general idea of decorators --- the realm of problems that decorators try to solve --- to be made smaller. They should not be used to declare a method's type (static|instance|class). Decorators may have some valid purpose, but this is not one of them. > Of course, it doesn't mean that I don't like your idea. In fact, it find it > elegant except the the "klass" word which is ugly. > Thanks, but it's not my idea (well, a tiny part maybe). The idea of inferring a method's type from the name of its first formal parameter was suggested by Stefan Eischet in another thread. From rschroev_nospam_ml at fastmail.fm Fri Aug 20 04:59:43 2004 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Fri, 20 Aug 2004 08:59:43 GMT Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: <34jVc.219716$n67.10885265@phobos.telenet-ops.be> Gerrit Muller wrote: > Roel Schroeven wrote: > >> Roel Schroeven wrote: >> >>> I spotted some errors in your list, added new entries, and made a >>> histogram: http://roelschroeven.net/pythonages/ >> >> > Very cool. It might be good idea to add a date and time at the top, > since new datapoint keep coming in? Done. Good idea indeed. -- "Codito ergo sum" Roel Schroeven From ajsiegel at optonline.com Mon Aug 9 09:10:20 2004 From: ajsiegel at optonline.com (Arthur) Date: Mon, 09 Aug 2004 13:10:20 GMT Subject: PEP-0318 References: <41122FC2.1080608@interlink.com.au> <4114152f@nntp.zianet.com> <4116bc20$1@nntp.zianet.com> <6NCdncg4ssq28orcRVn-uQ@powergate.ca> Message-ID: On Mon, 09 Aug 2004 08:33:45 -0400, Peter Hansen wrote: > >Therefore it will be before... the only important choice left >seems to be what bizarre and arbitrary punctuation symbol will >be chosen for the purpose. (To be fair, it's not "arbitrary" >any more: clearly the sole requirement for this is how loud >and in-your-face the decorator symbol will be. I don't know >when this sort of thing became considered good style for Python, >but this too is the new world order.) I guess at this point I am reading the siutation along the following lines: That Guido is is intuitively or consciosuly uncomfortable with the entire concept of decorators within the Python framework, while recognizing some need to accommodate a segment of the community with some special purpose fucntionality. And either intuitively, or consciously, he is doing something that offsets it from something truly intergrated into the core of the language. By breakling all of his own rules. Quirky design, to be sure. But, who knows, perhaps the best of the bad choices. > >-Peter From jbenson at lowell.edu Thu Aug 26 20:20:59 2004 From: jbenson at lowell.edu (Jim Benson) Date: Thu, 26 Aug 2004 17:20:59 -0700 (MST) Subject: A newbie in need.... In-Reply-To: <9c3edc58.0408261609.6640e400@posting.google.com> Message-ID: On 26 Aug 2004, Chris Patton wrote: > Hey everybody. I'm trying to make a program that requires a 2D field > to run. Besides "curses" or "ncurses", is there a python module that > will create a graph? > > --Thanks for the help! > matplotlib is a great python plotting package that might help you. ...sorry i haven't quite sorted out some upgrades i have done to my home system so i can't give you the exact link....google for it and you will find it. Good luck, Jim From amajorel at teezer.fr Tue Aug 31 14:21:20 2004 From: amajorel at teezer.fr (Andre Majorel) Date: Tue, 31 Aug 2004 18:21:20 +0000 (UTC) Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <%T%Yc.29567$Es2.11957889@news4.srv.hcvlny.cv.net> <4134a207$0$65568$a1866201@newsreader.visi.com> Message-ID: On 2004-08-31, Craig A Finseth wrote: > The / was chosen as the command line option separator because whoever > wrote MSDOS was looking to CP/M, who modelled their commands after a > PDP-11 operating system (RT-11?). Whoever = Tim Paterson, then working for Seattle Computer Products. Interesting historical stuff at http://www.patersontech.com/Dos/ -- Andr? Majorel Conscience is what hurts when everything else feels so good. From a at c.d Fri Aug 27 11:19:53 2004 From: a at c.d (Sean Don) Date: Fri, 27 Aug 2004 15:19:53 GMT Subject: Class Friends Message-ID: <20040827081556.657c3fac.a@c.d> Hello! Is it possible to make classes friends in Python? Or is it better to just stick to "Java style" .isThis, .getThat, .setThis style functions? I understand that classes are generally grouped logically into separate files anyway. So, this isn't always necessary. But I'm a perfectionist and was wondering if friendships were possible in Python. Thank you! sean_don4 at yahoo.com From npat at efault.net Tue Aug 17 02:29:39 2004 From: npat at efault.net (Nick Patavalis) Date: Tue, 17 Aug 2004 06:29:39 +0000 (UTC) Subject: Generators versus Coroutines References: <7x7js1i887.fsf@ruckus.brouhaha.com> <972ec5bd.0408152037.c50bcee@posting.google.com> Message-ID: On 2004-08-16, Lenard Lindstrom wrote: > > As for doing it in Python, coroutines can be implemented using > threads. > But threads cost! And how much they cost depends on the operating system. Coroutines cost close to nothing, and are O/S independent. The only reason to use O/S threads is if you need preemption, and if you want to cater for parallel execution. > Lenard Lindstrom > From jpmorichon at earthlink.net Thu Aug 12 00:52:16 2004 From: jpmorichon at earthlink.net (CptPicard) Date: Thu, 12 Aug 2004 04:52:16 GMT Subject: Print command References: <2nv6roF54f7iU1@uni-berlin.de> Message-ID: <4ICSc.22155$Jp6.11433@newsread3.news.atl.earthlink.net> "Russell Blau" wrote in message news:2nv6roF54f7iU1 at uni-berlin.de... > "CptPicard" wrote in message > news:WosSc.21396$Jp6.6141 at newsread3.news.atl.earthlink.net... > > I think that you should try: > > string.rjust('currentTotal',6) > > instead of: > > string.rjust(`currentTotal`,6) > > > > You may also do it this this way: > > 'currentTotal'.rjust(6) > > No, I think he really did want the "backwards" single quotation marks. They > *are* different, you know... > Actually, I don't know the meaning of ``. On some languages, it means "evaluate": Is it the same meaning in Python ? > > -- > I don't actually read my hotmail account, but you can replace hotmail with > excite if you really want to reach me. > > From flacco002 at spambadTwilight-systems.com Mon Aug 30 18:45:41 2004 From: flacco002 at spambadTwilight-systems.com (flacco) Date: Mon, 30 Aug 2004 18:45:41 -0400 Subject: [IronPython] Jim Hugunin's web log. In-Reply-To: References: Message-ID: <10j7bfr6o0nf7af@corp.supernews.com> David Wilson wrote: > Anti-trust conspiracy theories aside, if Microsoft adopts Python as a > part of it's development toolset, the repercussions for Windows RAD and > scripting are massive, not to mention the effects it would have on the > average Python developer's wages and availability of work. why in the world would we want to put aside the concerns about microsoft that we have, which you have "misnomered" under the umbrella term "anti-trust conspiracy theories"? > This is perhaps the first time where I have been glad to see Microsoft > hijack something. Even if IronPython becomes a commercial offering, I'm > still sold. [...] > My apologies for the poor terminology, this really isn't my department. > Just got a feeling. :) are you in advertising by any chance? From peter at engcorp.com Fri Aug 13 08:11:43 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 13 Aug 2004 08:11:43 -0400 Subject: Flython? In-Reply-To: <2o3ovjF6apnoU1@uni-berlin.de> References: <2o3ovjF6apnoU1@uni-berlin.de> Message-ID: Daniel Ellison wrote: > I *like* "Flython" as a name! :) A flying python! I can see the logo now... So does that mean we would have "Monty Flython's @Pie-ing Circus" if the @decorator debate is still going on by the time someone implements a Flash compiler for Python? From jepler at unpythonic.net Fri Aug 20 18:47:21 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Fri, 20 Aug 2004 17:47:21 -0500 Subject: esoteric question about dict keys (Re: age of Python programmers) In-Reply-To: <4125D015.9090204@urv.es> References: <4125D015.9090204@urv.es> Message-ID: <20040820224721.GA1260@unpythonic.net> There's no reason that the __getitem__ special method would not be permitted to take a dict argument. Many people will probably think that your use of Python's subscript operator is a strange one, mostly because x[i] returns a single element from x for lists, tuples, strings and dicts (the important built-in subscriptable types), but your syntax will probably return multiple rows. In fact, this may be a problem of internal consistency, because table[pkey_value] will presumably return a row object, not a sequence of rows (or am I wrong about that, and you'll get a sequence of 1 row in that case?) Here's a program that uses dicts as arguments to the subscript operator. "class Roda" takes a wordlist, and can either return the j'th word, or all words with exactly N copies of some letter(s). class Roda: def __init__(self, wordlist): self.wordlist = wordlist def __getitem__(self, item): if isinstance(item, int): return self.wordlist[item] n = len(item) return [word for word in self.wordlist if len( [None for (k, v) in item.items() if word.count(k) == v])==n] s = Roda(open("/usr/share/dict/words").read().split()) print s[{'a': 3}][:10] # first ten words with exactly 3 As print s[{'b': 2, 'c': 1}][:10] # first ten words with 2 Bs and 1 C another problem this made me think of is that I don't see how to expand this to "at least N", "at most N" or "from M to N" items, and likewise for the kinds of query constraints you'd like to make (and can make in SQL) Well, anyway, if this really makes a big difference in the ease of writing the code you need to write, and you're not too worried that someone else who might maintain your code in the future won't be able to understand it (documentation and comments would help here), then go right ahead. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From amk at amk.ca Thu Aug 5 17:38:22 2004 From: amk at amk.ca (A.M. Kuchling) Date: Thu, 05 Aug 2004 16:38:22 -0500 Subject: import random error References: <7903bb89.0408051324.63ee1535@posting.google.com> Message-ID: On 5 Aug 2004 14:24:57 -0700, Rob B wrote: > I have such a feeling that this is either a) because I don't know what > I'm doing or b) the python install is somehow strange. What is strange It's a common mistake; the 'import math' is importing your math.py, not Python's 'math' module. Rename your file to random-test.py or something else that doesn't conflict, and it should work. --amk From anthonybaxter at gmail.com Fri Aug 13 12:59:07 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 14 Aug 2004 02:59:07 +1000 Subject: def ... decorate In-Reply-To: References: <16668.57321.308134.676624@montanaro.dyndns.org> Message-ID: On Fri, 13 Aug 2004 20:55:39 +0400 (MSD), Roman Suzi wrote: > > Bingo! > > Just replace decorate with "from" and the nice syntax is found: > > def f: > staticmethod > grammarrule('statement : expression') > version("Added in 2.4") > deprecatedmethod > type_(None) > from self, p: > """docstring here""" > print p[1] I _really_ _really_ dislike re-using 'from' in this way. It's really confusing. I also don't like the way it's splitting the argument list out like that. It's a _big_ change from how things work today, and will break pretty much _every_ tool that works with Python source, and badly. For instance, I often end up doing some equivalent of "grep 'def funcname'" and like the fact that I get the start (at least) of the argument list. More often than not, I get the full argument list, which is what I was looking for in the first place. From mats at laplaza.org Sat Aug 7 02:35:18 2004 From: mats at laplaza.org (Mats Wichmann) Date: Sat, 07 Aug 2004 00:35:18 -0600 Subject: ANN: Dive Into Python published In-Reply-To: References: Message-ID: <6.0.0.22.1.20040807003217.03762c48@mail.laplaza.org> At 09:32 AM 8/4/2004, Mark Pilgrim wrote: >I am pleased to announce that my Python book "Dive Into Python" is now >available on paper, published by Apress and weighing in at 432 pages. Congrats, Mark. I was at LinuxWorld Expo this week and stopped by Apress and saw the book (sadly funds are tight so I didn't get a copy). They said the book had done extremely well so far although it wasn't currently their hottest book, their Plone book flew off the shelf (well, table) when they were at OSCON last week. This sounds like good stuff for Python books in general! From gregor.jan at NOSPAMquick.cz Thu Aug 12 06:56:27 2004 From: gregor.jan at NOSPAMquick.cz (Jan Gregor) Date: Thu, 12 Aug 2004 10:56:27 +0000 (UTC) Subject: jython and java exceptions References: <4_nSc.24773$Z14.7584@news.indigo.ie> Message-ID: All tests passed ok, but problem is still there. I didn't mentioned that mysql works fine. My system is debian, something between woody and testing version. At home I have similiar debian upgraded moved so far from potato to woody to sarge - same behaviour. Application runs from command line by 'jython TextConsole.py'. Jython is version 2.1, running on java 1.4.2_05 (at home 1.4.1). PostgreSQL (7.4.3) and jdbc driver (as jython) from debian testing distribution. Jan From jwkenne at attglobal.net Tue Aug 31 17:48:07 2004 From: jwkenne at attglobal.net (John W. Kennedy) Date: Tue, 31 Aug 2004 21:48:07 GMT Subject: Xah Lee's Unixism In-Reply-To: References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4PGdnfsOfdDPi63cRVn-tA@speakeasy.net> <41337FC9.8070902@hotmail.com> <%T%Yc.29567$Es2.11957889@news4.srv.hcvlny.cv.net> Message-ID: Rich Teer wrote: > On Tue, 31 Aug 2004, John W. Kennedy wrote: >>Yes, and also a single-process pipe emulator. Ever since 2.0, MS has >>been trying to turn MS-DOS (later, Windows) into a Unix clone. > .... And has failed miserably to do so. Not entirely. Porting GNU software and the like to MS-DOS and Windows could be a hell of a lot more difficult than it is. Try porting almost anything to, for example, the MVS (classic) environment (which is why MVS now also includes a Unix-wise alternate environment). -- John W. Kennedy "You can, if you wish, class all science-fiction together; but it is about as perceptive as classing the works of Ballantyne, Conrad and W. W. Jacobs together as the 'sea-story' and then criticizing _that_." -- C. S. Lewis. "An Experiment in Criticism" From ville at spammers.com Sat Aug 21 12:06:41 2004 From: ville at spammers.com (Ville Vainio) Date: 21 Aug 2004 19:06:41 +0300 Subject: Parsing C header files with python References: <873c2gzftf.fsf@emit.demon.co.uk> Message-ID: >>>>> "Ian" == Ian McConnell writes: Ian> I've got a header file which lists a whole load of C functions of the form Ian> int func1(float *arr, int len, double arg1); Ian> int func2(float **arr, float *arr2, int len, double arg1, double arg2); Ian> It's a numerical library so all functions return an int and Ian> accept varying combinations of float pointers, ints and Ian> doubles. Ian> What's the easiest way breaking down this header file into a Ian> list of functions and their argument using python? Is there Well, what comes immediately to mind (I might be overlooking something) is that the function name is immediately before '(', and arguments come after it separated by ','. Start with regexps and work from there... -- Ville Vainio http://tinyurl.com/2prnb From luismg at gmx.net Mon Aug 2 18:27:39 2004 From: luismg at gmx.net (Neuruss) Date: 2 Aug 2004 15:27:39 -0700 Subject: New to Python/Programming References: <10gsujk1og2gkbf@corp.supernews.com> Message-ID: <278de0e.0408021427.5b08fba8@posting.google.com> I was in the same situation a few months ago. I wanted to learn programming with a solid foundation of programming principles (OOP, etc) but with a language that could allow me to do it without unnecessary complications. Obviously, the choice was Python, so I can tell you what worked for me: 1) Starting from zero: I recommend Josh Cogliati's "Non-Programmers Tutorial For Python". It's a very easy to follow online tutorial that will teach you the basics, with exercises and all you need to get started. Although it is aimed to begginners, with the lessons learned you will have a very good knowledge of python basics and programming in general. Find it here: honors.montana.edu/~jjc/easytut/easytut/ I recommend taking the time to do the exercises and play a little bit after each lesson. They are very easy and simple, but take them seriously. 2) After getting comfortable, you will want to get into the object oriented side of programming. It's not hard, but it takes a mental shift to begin thinking in objects. I learn best by example, and the best one I found is Alan Gauld's online tutorial (there's a book also, but the online version was just what I needed to "see the light"). You can find it here: http://www.freenetpages.co.uk/hp/alan.gauld/ If you swallowed Josh Cogliati's tutorial, you wont find nothing new here for the basics, but there's a very good example of a banking application that will help you understand the object oriented paradigm. I think this is a very good example for teaching OOP and it shows you in a few lines all you need to know: classes, innheritance, etc.. After that, any other tutorial or book would be easy to follow. I recomend these books: - Lerning Python by Alan Lutz .This is the favorite of many people. It's very good but not nessesary the best, at least not for me. - Core Python programming by Wesley Chun. Another very good one. - Python Bible (don't remember the author..) - Python Visual Quickstart guide. Take this advice: Work with the online tutorials listed above. Take your time and follow them at your own pace, and use also the official python tutorial which comes with the IDLE (see the HELP menu). There's no need to buy books, because I sincerelly think that all you need is available online, but getting a book or two wont harm you... Once you reach the comfortability level, you can go to a bookstore and see briefly which style suits you best. All the books listed above are very good (and sorry for my english). Good luck and enjoy... Python is fun! Luis From rho at see.signature.invalid Thu Aug 26 07:58:03 2004 From: rho at see.signature.invalid (Nigel Rowe) Date: Thu, 26 Aug 2004 21:58:03 +1000 Subject: Call for signatories for J2 References: Message-ID: <10irk2ash04bpc6@news.supernews.com> For. -- Nigel Rowe A pox upon the spammers that make me write my address like.. rho (snail) swiftdsl (stop) com (stop) au From donn at drizzle.com Sat Aug 28 23:59:01 2004 From: donn at drizzle.com (Donn Cave) Date: Sun, 29 Aug 2004 03:59:01 -0000 Subject: Dynamic languages References: <278de0e.0408271349.26762174@posting.google.com> <1093650026.763899@news.commspeed.net> <98862c6.0408280531.6064d510@posting.google.com> Message-ID: <1093751939.767733@yasure> Quoth m_vddungen at yahoo.com (Marcel van den Dungen): ... | Dynamic refers to the typing of variables. In Python variables get a | type dynamically when assigned a value. | See also: http://www.artima.com/weblogs/viewpost.jsp?thread=4639 | and several blog posting of Bruce Eckel on this subject: | http://www.mindview.net/WebLog/ I imagine they may actually have been looking at some version of this: http://www.fact-index.com/d/dy/dynamic_programming_language.html which goes beyond static vs. dynamic typing in the sense they ordinarily seem to be used. I'm not sure they really put their finger on the main problem in the way of a Python compiler, but whatever. Donn Cave, donn at drizzle.com From anthonybol2 at netscape.net Sun Aug 15 16:45:15 2004 From: anthonybol2 at netscape.net (TonyB) Date: 15 Aug 2004 13:45:15 -0700 Subject: Seperating CSV rows into new, seperate files References: Message-ID: OK, With some off post help I was able to come up with this little ditty of a script but it still has one more problem. When I run the script it creates new files for each specific class. While talking through the logic with a friend, I realized that the gradebook software that will import the list will ignore duplicate rows. Not the best solution but I need it to work this week. In any case, it appears that the new files have some sort of additional line terminator that creates a blank row in the outputted file making the importing of the list impossible. This is based on the fact that when I try to open the new files in MS Excel, they have blank rows after each row of data. If I open them in a text editor such as Notepad, they look identical to the source file (which can be imported to the gradbook software). Is there a way to SEE the newline terminators? How can I use the csv.writer() to make sure there are no extra lines? My Script: ************************************** import csv TEACHER_NAME = 4 COURSE_TITLE = 9 COURSE_NUMBER = 8 SECTION = 10 # Open the input file and read the file to memory (may be too big a file? ~ 2MB?). reader = csv.reader(file("sample.csv")) def createFilename(teacher,title,number,section): ''' We need to remove spaces from the fields for better formatting of the file name ''' import re regex = re.compile('[^.A-Za-z0-9-_]') filename = '%s_%s_%s_section%s.txt' % (teacher, title, number, section) return regex.sub('_', filename) for row in reader: filename = createFilename(row[TEACHER_NAME], row[COURSE_TITLE], row[COURSE_NUMBER], row[SECTION]) fileobj = file(filename, 'a') newfile = csv.writer(fileobj) newfile.writerow(row) fileobj.close() ************************************** Thanks to those who have helped! Maik R?der wrote in message news:... > Hi TobyB, > > > Hi, > > I've searched the group and need more information and guidance on this > > issue I need to resolve next week. I work for the local school system > > and I am working on a way to parse a CSV file of class lists from MS > > Excel. It is a ~2MB file with all teachers and all their classes in > > it. I thought I would use Python to do this since many people I know > > tell me how great it is. > > Pyhton is a good choice for treating texts. > > > The real sticking point is there are > > duplicates of each teacher's classes embedded in the file (don't ask > > why). I want to break up the source file into the seperate class > > files without duplication and use the teachers name, coursecode and > > section in the filename. > > > > Example Data: > > Last Name First Name Grade Period Teacher Name > > SMITH JOHN 8 1 JONES SALLY > > > > Student ID Course Code Course Title > > 12345678 1234 ALGEBRA I > > > > Course Section Session > > 1 0 > > > > > > The course code and section number are the same in the duplicate > > classes. The difference is that the session number changes. I'm > > thinking that I will need to somehow iterate through the lines and > > break the class when the course code changes and/or section change > > (course codes can be the same but section numbers change with each > > class). Then I have to monitor the session number to see if there is > > a duplicate course code and section but a different session number > > would indicate that the class is a duplicate. Essentially, the session > > number will be 0, 1, or 2 for a total of three lists of the same > > class. Hopefully that makes sense. Again don't ask why the data is > > like this. > > > > My humble attempts have not been very successful. I've been trying > > the csv modules to read the file but I am not sure how to procede > > after that. > > > > Any guidance is greatly appreciated. > > Use Python lists and dictionaries. > > Best regards, > > Maik R?der From kirk at eyegor.jobsluder.net Mon Aug 9 10:20:53 2004 From: kirk at eyegor.jobsluder.net (Kirk Job-Sluder) Date: Mon, 09 Aug 2004 14:20:53 GMT Subject: Paul Graham on Python hackers References: <3064b51d.0408090448.31806af5@posting.google.com> Message-ID: On 2004-08-09, beliavsky at aol.com wrote: > Kirk Job-Sluder wrote in message news:... > >> In previous writings Graham tends to focus more on language fundamentals >> rather than the scope of features or the process of compilation. Python >> is closer to Java in that they are both strongly Object Oriented languages in >> contrast to perl's OO framework that feels more bolted on than integral >> to me. > > Python, unlike Java, does not force OOP upon you -- it can be treated > as an imperative language. I think this is a plus especially when > first learning the language or writing small programs. A Hello World > program is just > > print "Hello, World" However, and I see this as a pretty important distinction. Most things in python are objects. "Hello, World" in python is more than just a reference to a series of bytes terminated in a null. >>> "hello world".capitalize() 'Hello world' >>> "hello world".upper() 'HELLO WORLD' >>> "hello world".find('or') 7 > class HelloWorldApp { > public static void main(String[] args) { > System.out.println("Hello World!"); //Display the string. > } > } The differences here are trivial from what I can tell. What is happening here are three things: 1: the creation of a class boundary around the program. 2: the creation of a main function that runs when the program starts. 3: output of a string to STDOUT. Python does #1 and #2 implicitly unless given instructions to do something different: http://www.python.org/doc/current/lib/module-main.html #3 is provided by defining print as a built-in statement that masks writing to sys.stdout(). The magic of python is that its Object Orientation is so well-implemented that it takes away much of the pain and suffering imposed by Java, and even by C++. These code snippits just show that python is a high-level OO langugage as opposed to Java which is a lower level (middle level) OO language. Of course you can use OO languages to do imperative programming. (A fact greatly lamented by OO purists.) You can even do imperiative programming in java once you set up your main function. However, I've found that most languages are built in such a way to make one paradigm easier than another. The thought of OO programming in gnu lisp sends chills down my spine. OO programming in perl is doable but cumbersome. But as an example of what Graham was walking about, we need only look at the manpages for perl and python. The perlobj manpage says: First you need to understand what references are in Perl. See perlref for that. Second, if you still find the following reference work too complicated, a tutorial on object-oriented programming in Perl can be found in perltoot and perltootc. In contrast the python manpage simply says: Python is an interpreted, interactive, object-oriented programming lan- guage that combines remarkable power with very clear syntax. In perl5, objects are thin wrappers around references. Python just says, "I'm an object oriented language" and then goes on to tell you how to use the large numbers of available objects. -- KirK From harald.koschinski at friatec.de Tue Aug 10 10:00:16 2004 From: harald.koschinski at friatec.de (Harald Koschinski) Date: Tue, 10 Aug 2004 16:00:16 +0200 Subject: Pythondirector In-Reply-To: References: <45654bdb.0408060030.41f1e973@posting.google.com> Message-ID: <4118D4F0.9010909@friatec.de> >Don't know - I don't think I've seen that. The bugs I have seen in >this area are generally to do with switching between groups - any >current connections end up going into the new bucket, rather than >the old. I have a plan to fix this, involving a dictionary of open connections >and a 'zero out stats' button, but I've not had time to spend on fixing >it. > > > > Hi I tested first with "twisted" 1.3.0. In this configuration pydir seems to hang sporadical in a courious way (one Browser hangs - another is working) - so I changed to "asyncore" and this worked. Is twisted 1.3.0 recommended / can it be the reason for the hangers? Can "asyncore" be the reason for wrong calculated / really not closing connections ?? Harald From godoy at ieee.org Mon Aug 30 09:23:12 2004 From: godoy at ieee.org (Jorge Godoy) Date: Mon, 30 Aug 2004 10:23:12 -0300 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <1LMXc.67190$UTP.37420@twister01.bloor.is.net.cable.rogers.com> <1gj7a9r.g7ec5a1g89rj0N%aleaxit@yahoo.com> Message-ID: Just writes: > In article , Jorge Godoy > wrote: > >> Because the implementation that allowed to unzip the "directory" and >> find the files in there would also allow to place the '.pyc' in a >> different place such as the real directory where the zip file resides. >> >> Python didn't use to open zip files also, and now it does. I don't see >> nothing wrong with making it also writing the '.pyc' files. Do you? > > Yes, because it's conceptually inconsistent with how "regular" imports > work. So here, we have our thoughts taking two separate ways. I don't see too much inconsistency here. You do. :-) But, packaging the ".pyc" solves the problem... Just warning that they are not generated after the packing is a good advice to have. It wouldn't hurt anybody (and takes less time than we took talking about it here). Be seeing you, -- Godoy. From nomail at nospam.no Sat Aug 21 13:48:36 2004 From: nomail at nospam.no (Dominic) Date: Sat, 21 Aug 2004 19:48:36 +0200 Subject: age of Python programmers In-Reply-To: References: Message-ID: I am 25 years old and I use Python at least since version 1.5. I have started programming on the Atari 1024STFM with ST- and Omikron-Basic. Later on the PC I used: Power Basic|Quick Basic Turbo Pascal|Assembler Borland C/C++ Today I usually use Python and C (gcc,mingw). Ciao, Dominic From alan.gauld at btinternet.com Thu Aug 5 05:33:28 2004 From: alan.gauld at btinternet.com (Alan Gauld) Date: Thu, 05 Aug 2004 09:33:28 GMT Subject: curses References: Message-ID: <4nv3h0129nl4akfo59efqgpvd5fgfev6t5@4ax.com> On Thu, 05 Aug 2004 03:14:37 GMT, "Cecil H. Whitley" wrote: > second reading I found that curses is not supported on windows. It is under cygwin if that helps... Alan G Author of the Learn to Program website http://www.freenetpages.co.uk/hp/alan.gauld From thats at it.com Mon Aug 23 19:00:08 2004 From: thats at it.com (Baalbek) Date: Tue, 24 Aug 2004 01:00:08 +0200 Subject: urllib hangs In-Reply-To: References: Message-ID: Didn't he just say: "For older python versions, ask google for timeoutsocket.py"? Jay Donnell wrote: > Thanks, but I'm on python 2.2 and don't have the ability to upgrade it > on the server. How would I do this in 2.2? > > >>since 2.3 there's socket.setdefaulttimeout(), this should to the job: >> >>import socket >>socket.setdefaulttimeout(10) >># throw socket.timeout exception after 10s, >># default is to wait a infinitly (or at least a very, very long time...) >> >>For older python versions, ask google for timeoutsocket.py From David.Vaughan at Gifford.UK.com Wed Aug 4 06:20:20 2004 From: David.Vaughan at Gifford.UK.com (David Vaughan) Date: Wed, 4 Aug 2004 11:20:20 +0100 Subject: Subclassing file class Message-ID: I'm using v2.3, and trying to write to text files, but with a maximum line length. So, if a line is getting too long, a suitable ' ' character is replaced by a new line. I'm subclassing the file class, and, as long as I just use the write method, this works fine. But "print >>" doesn't behave as I want: class max_width_file(file): def write(self, txt): print "In max_width_file's write method." fout = max_width_file('foo.txt', 'w') print >> fout, 'bar' fout.close() bypasses my write method and prints 'bar' directly to the file. That isn't the behaviour I inferred from http://docs.python.org/ref/print.html How do I intercept "print >>"? Has anyone already implemented this? And should the documentation be changed? Any help very welcome. David David Vaughan Structural Analyst for Gifford GIFFORD AND PARTNERS LTD Carlton House, Ringwood Road, Woodlands, Southampton, SO40 7HT, UNITED KINGDOM Tel: +44 (0)23 8081 7500 Fax: +44 (0)23 8081 7600 Email: David.Vaughan at gifford.uk.com Web: http://www.gifford.uk.com This e-mail and any files transmitted with it are intended solely for the use of the individual or entity to whom they are addressed and may be confidential. If you are not the intended recipient or the person responsible for delivering the e-mail to the intended recipient, be advised that you have received this e-mail in error and that any use, dissemination, forwarding, printing or copying of this e-mail is strictly prohibited. From nomail at nospam.no Thu Aug 26 10:17:11 2004 From: nomail at nospam.no (Dominic) Date: Thu, 26 Aug 2004 16:17:11 +0200 Subject: ANN: Python + Erlang = Candygram In-Reply-To: References: Message-ID: Hi Michael, nice too see that you have also tried to bring some ideas from Erlang to Python ;-) My toy-example can be found at: http://groups.google.de/groups?q=erlang+group:comp.lang.python.*&hl=de&lr=&ie=UTF-8&group=comp.lang.python.*&selm=b6q3pj%24mp3%2403%241%40news.t-online.com&rnum=7 Ciao, Dominic From rschroev_nospam_ml at fastmail.fm Thu Aug 19 18:23:49 2004 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Thu, 19 Aug 2004 22:23:49 GMT Subject: age of Python programmers In-Reply-To: <4123874C.8000304@chamonix.reportlab.co.uk> References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: Robin Becker wrote: > Marius Bernklev wrote: > >> "Lucas Raab" writes: >> >> >>> One thing I've always kind of wondered is what is the average age of a >>> Python programmer?? What age groups use Python?? Something to think >>> about.... >> >> >> >> 24. (anyone keeping count?) >> > >> > It's raining so I can't go home Only Event Horizon on TV tonight... I spotted some errors in your list, added new entries, and made a histogram: http://roelschroeven.net/pythonages/ number of datapoints: 95 mean: 35.6 standard deviation: 12.7 Gerrit Muller 47 Lucas Raab 14 OKB (not okbackle) 20 Jeremy Jones 31 Ben Last 39 Neuruss 34 Tony Clarke 55 simo 26 Elbert Lev 55 Kamilche 40 Gerardo Herzig 30 JanC 30 Mike Rovner 41 Guyon Mor?e 21 Tom Brown 35 Will McGugan 30 Christopher T King 19 Skip Montanaro 50 Marcin Jurczuk 26 Reid Nichol 27 Egbert Bouwman 67 VSOFTSMITH 62 Mark Jackson 55 Harry George 52 Stephen Ferg 58 Scott David Daniels 53 Peter Wilkinson 32 oziko 24 Dave Opstad 50 Adonis 23 Jorge Godoy 25 Peter Hickman 43 Axel Steiner 22 Larry Bates 49 Robin Becker 57 Thomas Heller 48 Paul McQuire 45 wes weston 55 P at draigBrady.com 30 Ian Sparks 34 Roel Schroeven 29 Christos TZOTZIOY Georgiou 32 Gary Herron 52 Ksenia Marasanova 31 Marius Bernklev 24 Robert Boyd 40 Fred Pacquier 44 Jarek Zgoda 33 Leif K-Brooks 13 Peter Maas 48 Tim Jarman 42 Irmen de Jong 30 Ted 46 Roman Suzi 30 Dave Benjamin 25 Christian von Essen 18 Byron 28 R Baumann 55 Batista, Facundo 29 Jeff Shannon 35 Cousin Stanley 58 Berthold H?llmann 38 mensanator at aol.com 50 Ville Vainio 27 Istvan Albert 32 Andrea Griffini 38 Arthur Rambo 43 Beeyah 15 Eli Stevens (WG.c) 25 Bigbowser 15 Hemanth P.S. 32 richard 32 Marcos Eimil Pardo 28 Daniel Harding 25 Rod Haper 57 Bruno Desthuilliers 37 avaeq 19 Scott David Daniels 53 Alexandre Fayolle 30 Andrew Durdin 24 Max M 39 Ganesan R 32 Stefan Schukat 33 Robbie 18 Marc Boeren 34 Gerrit van Dyk 39 Oliver Fromme 33 Nicolas Evrard 27 vronskij at post.sk 25 Alan Kennedy 37 Francis Lavoie 25 Richard Hanson 53 brianc at temple.edu 20 Rex 17 Wilk 35 -- "Codito ergo sum" Roel Schroeven From aahz at pythoncraft.com Tue Aug 3 09:52:31 2004 From: aahz at pythoncraft.com (Aahz) Date: 3 Aug 2004 09:52:31 -0400 Subject: Call for Grant Proposals References: <40fcaa90$0$27091$9b622d9e@news.freenet.de> <410ED411.7090907@acm.org> <410ef314$1@news.unimelb.edu.au> Message-ID: Speaking as a PSF member who is or has been on some of the operating committees, but not a member of the PSF board or the grant committee: In article <410ef314$1 at news.unimelb.edu.au>, Maurice LING wrote: > >2. Will there be any form of intellectual property claims, including, >copyrights, trade marks, patents, on any form of work generated from the >PSF Grant by the Python Software Foundation (PSF) or any of its >associates? If so, what are the precise nature of it? This is important >as it may injure the research work and subsequently, the resultant >thesis and publications directing towards the award of my degree. There will be no claims by the PSF itself unless you assign your work; that follows more-or-less from choosing projects that are are Open Source. >3. On the website (http://www.python.org/psf/call-2004.html), it is >stated that the project of which the grant is granted for must be >completed by October 30, 2005. In event of failure to meet, what will be >the penalities? > >4. From Question 3, what constitutes partial failure or complete failure >of the project? We don't know. We're feeling our way into this. I suspect people would rather take a wait-and-see attitude until we actually have to deal with these issues. >5. From Question 4, it is stated on the website >(http://www.python.org/psf/call-2004.html) that a delivery plan is >essential in the proposal. How will delay in delivery affect the payment >plan and the grant on the whole? We're talking about US$40K in grants total; I expect that grants will simply be issued up-front for the most part. (The PSF's total monetary resources right now are around US$115K.) I'd expect that if a grant proposal ties payments to delivery targets, the penalty for missing delivery will be delay of the next grant payment. We're putting a certain amount of formalism into this because we have to; however, you'll be much better off if you think of this as "Python community money" that's being spread around to grease projects that are having trouble getting traction. There are basically two and only two criteria that really matter: * Will this project benefit a large portion of the Python community? * Will giving money to this project move it forward? Instead of asking general questions like this, why don't you simply tell us what your proposal is, and we'll help you refine it before you send it in to the grant committee? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From michael at stroeder.com Thu Aug 5 15:26:52 2004 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Thu, 05 Aug 2004 21:26:52 +0200 Subject: ZServerSSL and Certificates In-Reply-To: <3222fe00.0408050548.43b5f0fd@posting.google.com> References: <3222fe00.0408050548.43b5f0fd@posting.google.com> Message-ID: Sean wrote: > > So I take privatekey.pem and the ca cert and combine them into a > single file called ca.pem. Why? The server's private key has nothing to do with the CA certificate. > Then I: > > # ./CA.pl -sign > # openssl rsa < newreq.pem > newkey.pem Nope. You don't have to issue a new cert. > and I combine the server cert and newkey.pem and call it server.pem. You issued another server cert without need for doing so. > Microsoft IE6 first shows a request for a cert to use, I click OK to > bypass it then a warning dialog that the ca is not trusted. Yes. Since you installed your privately generated server cert instead of the server cert issued by the CA. Simply use the server cert you got back from the CA. Ciao, Michael. From ykingma at accessforall.nl Thu Aug 19 03:37:08 2004 From: ykingma at accessforall.nl (Ype Kingma) Date: Thu, 19 Aug 2004 09:37:08 +0200 Subject: Jython and super_reload? References: Message-ID: <412458a6$0$45379$e4fe514c@dreader19.news.xs4all.nl> Dave Benjamin wrote: > There have been several discussions here about how to write a reload() > function that works for classes as well as modules: > > http://groups.google.com groups?sourceid=mozclient&ie=utf-8&oe=utf-8&q=super_reload > > I have been trying to come up with a solution that works for Jython, and so > far nothing has worked. I was wondering if anyone has attempted or succeeded > in writing such a function for Jython. This works for classes: http://www.jython.org/docs/jreload.html You can unload a module in Jython by removing it from sys.modules, and (off course) by removing all other references to it. To be sure about what happens you can tell the JVM to be verbose about garbage collection of Java classes, and explicitly call java.lang.System.gc() in some test scripts. Ype From ctcgag at hotmail.com Fri Aug 27 13:54:23 2004 From: ctcgag at hotmail.com (ctcgag at hotmail.com) Date: 27 Aug 2004 17:54:23 GMT Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4dyXc.25792$Ot3.22106@twister.nyc.rr.com> <878yc0ucyl.fsf@thalassa.informatimago.com> Message-ID: <20040827135423.154$1T@newsreader.com> "David Schwartz" wrote: > "Pascal Bourguignon" wrote in message > news:878yc0ucyl.fsf at thalassa.informatimago.com... > > > Kenny Tilton writes: > > >> >>What you mean with Unixism? > >> > repeated accidents. Such a tool would > >> > first chop off the user's brain, molding > >> > a mass of brainless imbeciles and > >> > microcephalic charlatans the likes of > >> > Larry Wall and Linus Torvald jolly > >> > Server: Apache/2.0.50 (Fedora) > >> > ^^^^^^^^^^^^^^^^^^^^^^ > >> > >> So you like my approach, which is to condemn things they have never > >> used? > >> > >> :) > > > > No, that of no more using things that you condemn. > > I don't follow you at all. I think you'll find the most useful, > meaningful complaints about, say, a Ford Explorer from the people who > drive one every day. And if they continue to drive one everyday, perhaps you would conclude that their complaints are insincere. Xho -- -------------------- http://NewsReader.Com/ -------------------- Usenet Newsgroup Service $9.95/Month 30GB From kjetilho at yksi.ifi.uio.no Fri Aug 27 10:35:23 2004 From: kjetilho at yksi.ifi.uio.no (Kjetil Torgrim Homme) Date: Fri, 27 Aug 2004 16:35:23 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> <87hdqok9i6.fsf@sinken.local.csis.hku.hk> <1rfz68ely9.fsf@rovereto.ifi.uio.no> <876574k7du.fsf@sinken.local.csis.hku.hk> Message-ID: <1r3c28ejis.fsf@rovereto.ifi.uio.no> [Isaac To]: > > When Python is concerned and Emacs is not, Python only sees there > is indentation, and only indentation, to define the suites. And > it is also what people will perceive when they stare at the code. > There is nothing to be inconsistent with it. how long do you have to stare before spotting the bug? db.update_name(person) if is_student(person): db.update_courses(person) db.commit() only students have their names updated. I wonder why. real world examples have taken hours or days. -- Kjetil T. From schiffo2000 at yahoo.com Mon Aug 30 18:29:50 2004 From: schiffo2000 at yahoo.com (Barry Schiffman) Date: Mon, 30 Aug 2004 15:29:50 -0700 (PDT) Subject: bad bsddb key/values on large data Message-ID: <20040830222950.58737.qmail@web51407.mail.yahoo.com> I'm trying to build a bsddb hash database for an application, where it will be read-only. Actually, the app will use three similar databases. All appeared to be writen OK -- no errors -- and the two smaller ones of around 50 megs each are correct. The largest one, about 200 megs, is written, and can be read, and the strings are correctly formatted -- but the values attached to the keys are wrong -- as if values were overwritten when the hash gets large. In searching on Google and the mailing list, I saw one parenthetical remark about problems on large files, but I cannot find anything that directly addresses this problem. Can anyone tell me if there is such a Python problem or a bsddb problem? Thanks __________________________________ Do you Yahoo!? Yahoo! Mail is new and improved - Check it out! http://promotions.yahoo.com/new_mail From max at alcyone.com Wed Aug 25 18:38:52 2004 From: max at alcyone.com (Erik Max Francis) Date: Wed, 25 Aug 2004 15:38:52 -0700 Subject: Proposal for removing self References: Message-ID: <412D14FC.BDF40BAD@alcyone.com> "Batista, Facundo" wrote: > [Brent W. Hughes] > > #- When doing object-oriented stuff, it bothers me to have to > #- type "self" so > #- many times. I propose that Python allow the programmer to > #- optionally type > #- ".variable" instead of "self.variable" to mean the same > #- thing. Of course, > #- the interpreter would have to be more careful about > #- detecting floats that > #- begin with just a period as in ".5". What are your thoughts? > > I type less than read, so I prefer the code to be better readable than > writable. > > I'm -1 on your proposal. Furthermore, I believe there's been some talk as a prefixed dot being reserved for possible use in a "with" control structure at some point in the future. So using it to abbreviate self is definitely out. (Besides, this proposal is not new.) -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ You and I / We've seen it all / Chasing our hearts' desire -- The Russian and Florence, _Chess_ From listserver at tdw.net Wed Aug 11 05:45:50 2004 From: listserver at tdw.net (Tim Williams) Date: Wed, 11 Aug 2004 10:45:50 +0100 Subject: loading message thingy References: <200408110901.i7B911cE012665@mailhub.wolfram.com> Message-ID: <001401c47f88$17cf5500$ccbefea9@twilliams> "Robbie" wrote in message news:cfcndl$28em$1 at otis.netspace.net.au... > Basically all I want to do is continuously write to the same line. > So I could have a little rotating text thing showing that the script is > working or display data ie, kb downloaded so far... > > ATM I am just calling a clear screen every pass with a little nap, nasty. > '\b' is a backspace, so..... import sys,time chars = ['|', '\\', '-', '/'] out = sys.stdout def raw_print(txt): out.write("\b" + txt) out.flush() while 1: for x in range(len(chars)): raw_print(chars[x]) time.sleep(0.5) Save as a script and run it from your command prompt. >Also it would be nice to be able to change more than one line so I could >have 4 threads open downloading something with 4 lines each stating the >current status of each thread The code above should be able to handle this too with a small amount of modding , I'd use a simple queue to get the information back from the threads in an ordered and safe manner HTH From Sibylle.Koczian at Bibliothek.Uni-Augsburg.de Tue Aug 3 09:02:21 2004 From: Sibylle.Koczian at Bibliothek.Uni-Augsburg.de (Sibylle Koczian) Date: Tue, 03 Aug 2004 15:02:21 +0200 Subject: MySQLdb select In-Reply-To: References: <9RPOc.2792$LI7.1058@newssvr27.news.prodigy.com> <21064255.0408020908.41357e52@posting.google.com> Message-ID: <2n9gmuFuhk8kU1@uni-berlin.de> Andy Todd schrieb: > Not that it's vitally important, but the first statement I showed above > is more correctly written as; > > >>> cursor.execute("SELECT * FROM mytest WHERE address=%s", (string1,)) > > Because the second argument to the 'execute' method is a tuple of > parameter values to be substituted in the first argument - the SQL > statement. > I'm quite surprised that it works the other way - but it does. Could it be that previous versions of MySQLdb raised an exception with the other form cursor.execute("SELECT * FROM mytest WHERE address=%s", string1)? Regards, Koczian From paddy3118 at netscape.net Tue Aug 10 12:22:55 2004 From: paddy3118 at netscape.net (Paddy McCarthy) Date: 10 Aug 2004 09:22:55 -0700 Subject: Larry Walls 'Pythonesque Perl' Message-ID: <2ae25c6b.0408100822.49b3cce3@posting.google.com> I was looking at http://www.python.org/moin/PerlPhrasebook section 2.1.1, and was re-aquainted with a quote attributed to Larry Wall: "... You can program in a Pythonesque subset of Perl by restricting yourself to scalar variables and references. The main difference is that Perl doesn't do implicit dereferencing like Python does." You *don't* get closer to Python by restricting yourself to scalers holding references. Anyone who knows Perl but not Python would get totally the wrong idea by contemplating the quote. Cheers, Paddy. From miki.tebeka at zoran.com Mon Aug 30 17:19:56 2004 From: miki.tebeka at zoran.com (Miki Tebeka) Date: Mon, 30 Aug 2004 23:19:56 +0200 Subject: Get Parent path value (bad design) Help In-Reply-To: References: Message-ID: <20040830211956.GG680@zoran.com> Hello Moiz, > What I am trying to do is write some generic code where I can get the > path of the parent directory. for example if current working directory is > 'Z:\\dirA\\Parent\\Child' > > I want to get a string which up like 'Z:\\dirA\\Parent' > Then I do a sys.path.append('Z:\\dirA\\Parent') Just use os.path.dirname >>> from os.path import dirname >>> dirname(r"z:\dira\parent\child") 'z:\\dira\\parent' >>> HTH. -- ------------------------------------------------------------------------ Miki Tebeka http://tebeka.spymac.net The only difference between children and adults is the price of the toys From __peter__ at web.de Mon Aug 23 14:27:41 2004 From: __peter__ at web.de (Peter Otten) Date: Mon, 23 Aug 2004 20:27:41 +0200 Subject: function taking scalar or list argument References: <412a2bce$1_1@127.0.0.1> Message-ID: beliavsky at aol.com wrote: > > I can define a function that transforms either a scalar or each element in > a list as follows: > > def twice(x): > try: > return map(twice,x) > except: A bare except without the type of exception is always bad. > return 2*x > > print twice(3) # 6 > print twice([1,4,9]) # [2,8,18] > > Is this good style? I intend to define many functions like this and want > to use the right method. Thanks. I'd say you've just discovered a use case for a decorator: def scalarOrVector(f): def g(arg): try: return map(f, arg) # or map(g, arg) if you want to allow # nested sequences except TypeError: return f(arg) return g #@scalarOrVector def twice(a): return 2*a twice = scalarOrVector(twice) print twice(3) # 6 print twice([1,4,9]) # [2,8,18] Of course you will have to ensure that map(f, arg) _does_ throw an exception. Peter From therning at gforge.natlab.research.philips.com Wed Aug 11 04:20:24 2004 From: therning at gforge.natlab.research.philips.com (Magnus Therning) Date: Wed, 11 Aug 2004 08:20:24 +0000 (UTC) Subject: Is there something else but Automake? References: Message-ID: Miki Tebeka wrote: > Hello Magnus, > >> I am currently using Automake to make distributable tar-balls of my >> application. Is there something else (hopefully better) that I can >> use? > You might want to have a look at SCons (http://www.scons.org). Great > tool and written in Python, you can also use any Python code inside > the configuration files. Yes, I already know of SCons. There are quite a few things missing from it though since it is a build tool mostly, and a configuration tool to some extent, it explicitly isn't a distribution tool. I guess I'd have to do a bit of work myself in order to get it to behave the way I want it :-( /M -- ----------------------------------------------------------------------- Magnus Therning Philips Research Laboratories Eindhoven Phone: +31 40 2745179 (OpenPGP: 0x4FBB2C40) X-Windows: ...A mistake carried out to perfection. From h.b.furuseth at usit.uio.no Sat Aug 28 14:05:49 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 28 Aug 2004 20:05:49 +0200 Subject: pie-as-merely-syntax + decorator keyword Message-ID: I haven't managed to catch up with all the decorator articles, but: If we do get the pie syntax (or | or %% or whatever), is it too late to get '@ staticmethod' and not just '@staticmethod'? I've suggested it before, and I think others have too, but it seems to have gotten lost in all the other discussion. It's supposed to be a plus with the current pie syntax that the @ suggests something 'new' and non-obvious is going on. I don't see it. For one thing, it isn't going to remain new. When we get something more radically new, are we going to define it as '@$!!statement' to _really_ make it stand out? For another, it _isn't_ new. It's just new syntax for something old. All that is new is that there is a new type of _syntax_: A new way to express how statements affect each other; neither indentation nor program flow. It's not an _advantage_ of the pie syntax that it does this, compared with most other proposals. It's merely _necessary_ that it does it, since it does not use other visual cues like indentation. So if we get a pie, I think that's all the pie should mean: 'Abnormal Syntax Alert'. That could be a useful thing to have in the future, e.g. for compiler directives, and it doesn't mix up two completely different things: An entirely new kind of Python syntax, and statements that express normal execution of code. Then follow it with a keyword which says that this particular abnormal syntax applies decorators to the following function definition. Other 'pie-keywords' could be added later at need; there would be less worry about having used up an unused character. Like, oh I don't know, keywords that change the function they occur in so that it returns something else than its return statement says. Such a keyword would _really_ need to stand out. '@yield', for example:-) Or a keyword which 'gunzip's the rest of the source file before reading more of it. -- Hallvard From oriana.falco at thalesesec.com Fri Aug 27 11:03:21 2004 From: oriana.falco at thalesesec.com (Oriana) Date: 27 Aug 2004 08:03:21 -0700 Subject: Regular Expressions Message-ID: <808f000f.0408270703.27540e26@posting.google.com> hi! I am trying to do some replacements using regular expressions, but I'm not exactly sure how to do it. I need to replace all ocurrences of /****************************************** OR /* for /** ....meaning, any / (forward slash) followed by one or more asterisks needs to be replaced with /** ....how would I write a pieco of code to do this?? Please help! Thanks in advance... Ori From timrueAT at mindspringDOT.com Sat Aug 14 20:26:59 2004 From: timrueAT at mindspringDOT.com (threeseas) Date: Sun, 15 Aug 2004 00:26:59 GMT Subject: autocoding and the new MS book regarding software factories Message-ID: Because the project is done in python and in support of FOSS http://msdn.microsoft.com/architecture/overview/softwarefactories/default.aspx?pull=/library/en-us/dnmaj/html/aj3softfac.asp "According to the Standish Group [Sta94], businesses in the United States spend around $250 billion on software development each year on approximately 175,000 projects. Only 16 percent of these projects finish on schedule and within budget. Another 31 percent are cancelled, mainly due to quality problems, for losses of about $81 billion. Another 53 percent exceed their budgets by an average of 189 percent, for losses of about $59 billion. Projects reaching completion deliver an average of only 42 percent of the originally planned features." and text regarding industrialization (engineering).. Interesting how they use the same figures and refer to the same issue of industrialization as I covered 8 years ago on one of my first web pages. From http://threeseas.net/mind/vic-objective.html "PROBLEMS IMPORTANT TO SOLVE Attention Getting Points ------ FROM ------ COMDEX SPRING and WINDOWS WORLD 95 Power Panel - "What's Wrong with Software Development" ** In The U.S. Only ** $81 Billion = 31% of software development gets cancelled before complete $59 Billion = 53% of software development has cost over-runs of 189% 16% success - project success and failure ratio 61% customer requested features and functions make it in Maintenance and repair is where most of the U.S. dollars are going, instead of new, better, easier to use software. [snipped out some of my own observations from being there - see link *** Especially if you read http://www.theserverside.net/talks/library.tss#KeithShort ] ------ AND FROM ------ SCIENTIFIC AMERICAN - Sept. 1994 Article - "Software's Chronic Crisis" The article covers much the same ground as the above but with a focus and flavor of the magazine. The article also goes more into solution efforts with software development on large scale projects. But finding consistent solutions are still hard to come by. Mass-produced PC products makes up less than 10% of the $92.8 billion U.S. software market. Mary M. Shaw of Carnegie Mellon University, observes a parallel between chemical engineering evolution and software engineering evolution. However, this evolution has not made the connection between science and commercialization required to establish a consistent experimental foundation for professional software engineering. --------------------- They also refer to several other issues I have as well covered. Such as levels of abstraction.. http://www.threeseas.net/mind/KNMVIC.html I've posted about this and related issues before but now MS is talking along the same lines and I'm not supprised as I understand their longhorn and patent grab intent ... and have publicly stated these things if you just search the internet. I don't claim MS is in any way original, but we all know they take from others and claim ownership... http://weblogs.asp.net/jnadal/archive/2003/10/29/34413.aspx ---------- # re: Codename "MONAD" 10/31/2003 12:34 PM 3seas Ok, what to many fail to understand is the sum total and what it means, that MS is working towards. The Common Language Infrastructure (CLI #2) is a sum of most all programming concepts and datatypes then integrated into a non-conflicting package so that most any language can be translated into the Common Intermediate Language (CIL) and run on a run time engine. This unifies all programming languages. But also another part of .NET is that of Inter-Process Communications (IPC) and there is also direction towards standardized GUI functionality. Then Add in this Commandline Interface (CLI #1)... (CLI #1) + (GUI) + (IPC) = the three primary UIs which is like paint having three primary colors, for which you can create any color in the spectrum. Take away one and you greatly limit what you can do... ok.. using these three primary UIs in processing the (CLI #2) it becomes possible and probable that an autocoding environment can and will be developed. additionally by adding a voice to text interface to the CLI #1 you can achieve the ability of the end user/consumer to ask for a program to be created and the system will do it. by patenting it..... all your base will be owned by MS... do a google search in "autocoding" and be sure to set aside any arrogance and ignorance you may and probably do have. --------- The following information represents what is probably the best of what is available thru the Web on the subject of autocoding. (via google) HIRTS DARP Working Group on Autocoding, 18th, 19th April 2000 http://www.cs.york.ac.uk/hise/darp/pdf/autocoding.pdf (Brings up various issues which will help you focus in on what "autocoding" is and what some of the issues to solve, are.) The follow up to the above is: May 8th thru 10th, 2001 "DARP HIRTS Workshop" paper by Jakob Engblom: http://www.artes.uu.se/mobility/reports/hirts_report1.0.pdf (See pages 5-6 section 3.2.5 The Use of Tools in Aerospace) This link no longer works but.. available on paper http://www.artes.uu.se/mobility/reports/ In summary, Though autocoding is being used to some extent, it is a future hope, since in general it has a bug density which is an order of a magnititude lower than manual code. Point being is that this is leading edge stuff, an opportunity for OSS to shine. To help show why I believe OSS efforts can shine when it comes to such a project as Autocoding: QinetiQ - Analysis of the Impact of Open Source Software http://www.govtalk.gov.uk/interoperability/egif_document.asp?docnum=430 link changed I think to: http://www.govtalk.gov.uk/documents/QinetiQ_OSS_rep.pdf and From the Conference on the Public Domain, Nov. 9-11. 2001 at Duke Law School "Coase's Penguin, or, Linux and the Nature of the Firm" by Yochai Benkler: http://www.law.duke.edu/pd/papers/Coase%27s_Penguin.pdf Automating what was done manually requires the identification of, and ability to apply, the manual action set we use, but have the computer do it. A USPTO Published comment introducing these identified actions and suggestions of how they may be applied, including autocoding, is here: http://www.threeseas.net/mind/KNMVIC.html Now it seems that the core problem not only I but MS is running into is resistance from coders... http://it.slashdot.org/article.pl?sid=04/08/08/1724209&tid=185&tid=187&tid=8 and the page ratings of the MS link (first link in body of this post) and http://www.theserverside.net/discussions/thread.tss?thread_id=27697 Anyway, since there are those controlling python coders that don't like me.... thought I'd post this. And to the GNU group.... Sorry RMS, but software just ain't free untill anyone can easily create or cause the computer to create it for them... for FREE... And real software engineers that believe in the Free Software Foundation, FOSS, GPL, etc.. will understand this... From jepler at unpythonic.net Wed Aug 4 08:03:04 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 4 Aug 2004 07:03:04 -0500 Subject: Subclassing file class In-Reply-To: References: Message-ID: <20040804120304.GA30066@unpythonic.net> "print>>" uses the bytecode PRINT_ITEM_TO which uses PyFile_WriteString() which uses PyFile_Check() which returns True for your "fout", which leads directly to a call to fputs. Instead, PyFile_WriteString() should probably use PyFile_CheckExact() (which doesn't exist yet) before taking that branch of the code. I also notice that the return value of that fputs is not checked in that function! For now, you could use containment and delegation instead of subclassing, just like in Python before new-style classes. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From peter at engcorp.com Fri Aug 6 18:35:01 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 06 Aug 2004 18:35:01 -0400 Subject: random from an array In-Reply-To: References: Message-ID: <2sqdnezun4kImoncRVn-qg@powergate.ca> Calvin79 wrote: > I've just started to try python so forgive the ignorance! > > I've been using this, or something like it; > > First = random.choice ('abc') This works not because choice() takes a string, but because even though it takes a sequence, a string *is* a sequence (of bytes). > What I want to do, however, is take a random pick from something like the > following; > > First = random.??? ("rna", "rnb", "rnc") - this of course "random.choice" > doesn't work. Just use another sequence, either a tuple or a list: random.choice(("rna", "rnb", "rnc")) or random.choice(["rna", "rnb", "rnc"]) The latter is preferred for various mostly stylistic reasons... -Peter From eldiener at earthlink.net Mon Aug 16 20:08:18 2004 From: eldiener at earthlink.net (Edward Diener) Date: Tue, 17 Aug 2004 00:08:18 GMT Subject: No validation routine for an os.path Message-ID: Try as I might I can not find a routine in os.path which validates whether or not a path is syntactically valid, either as a directory or as a file. This is surprising since, although I know this is OS dependent, Python has many other classes and functions which will work properly depending on what OS they are currently running under. Is there such a path validation routine in any of the libraries distributed with Python or in any other 3rd party Python libraries ? From listserver at tdw.net Wed Aug 11 09:01:26 2004 From: listserver at tdw.net (Tim Williams) Date: Wed, 11 Aug 2004 14:01:26 +0100 Subject: loading message thingy References: <200408110901.i7B911cE012665@mailhub.wolfram.com> <001401c47f88$17cf5500$ccbefea9@twilliams> Message-ID: <006d01c47fa3$4fb6bfb0$ccbefea9@twilliams> ----- Original Message ----- From: "Tim Williams" > "Robbie" wrote in message > news:cfcndl$28em$1 at otis.netspace.net.au... > > > Basically all I want to do is continuously write to the same line. > > So I could have a little rotating text thing showing that the script is > > working or display data ie, kb downloaded so far... > > > > ATM I am just calling a clear screen every pass with a little nap, nasty. > > > > '\b' is a backspace, so..... > > import sys,time > > chars = ['|', '\\', '-', '/'] > out = sys.stdout > > def raw_print(txt): > out.write("\b" + txt) > out.flush() > > while 1: > for x in range(len(chars)): > raw_print(chars[x]) > time.sleep(0.5) Thinking about it, '\b' can cancel out the extra space at the end of a "print char," (with the comma on the end) so, this does the same thing .... import time chars = ['|', '\\', '-', '/'] while 1: for x in range(len(chars)): print "\b\b" + chars[x], time.sleep(0.5) From jeff_news at lindholm.org Tue Aug 24 14:41:20 2004 From: jeff_news at lindholm.org (Jeff Lindholm) Date: Tue, 24 Aug 2004 18:41:20 GMT Subject: line shift? (baby steps 2) References: <6daa8765.0408230412.6db365d6@posting.google.com> <2oueokFe36qgU2@uni-berlin.de> <6daa8765.0408231437.7c37130@posting.google.com> Message-ID: >> import string >> >> currency = {"EUDK":(7.47,"? to DKK"), >> "DKEU":(0.13,"DKK to ?"), >> "USDK":(5.93, "$ to DKK"), >> "DKUS":(0.16, "DKK to $"), >> "EUUS":(1.19, "? to $"), >> "USEU":(0.84, "$ to ?")} >> >> while(1): >> currency_choice= raw_input("\nPlease enter conversion type or >> 'Exit': >> ") >> currency_str= str(currency_choice).upper() >> >> if currency_str == "EXIT": >> break >> if currency.has_key(currency_str): >> amount_int= input("Please type the amount you wish to convert: ") >> result = amount_int * currency[currency_str][0] >> print currency[currency_str][1], " ", amount_int, " = ", result >> else: >> print("Sorry. At the moment we only support DKK, Euro and >> Dollars." >> + "\n" \ >> "Type DKEU if you want convert from DKK to ?," + "\n" \ >> "EUDK if you want to convert from DKK to ?," + "\n" \ >> "DKUS if you want to convert from DKK to $," + "\n" \ >> "USDK if you want to convert from $ to DKK," + "\n" >> "EUUS if you want to convert from ? to $," + "\n"\ >> "and USEU if you want to convert from $ to ?") > > > was the following output intended? > > "Please enter conversion type or 'Exit': euus > Please type the amount you wish to convert: 99 > ? to $ 99 = 117.81" > > I mean the last line. Or am I missing something? > Thanx! Yes the last line was meant to show the conversion type, just a simple remider for myself what I converted (in this case EU - designated ? - to US dollars - designated $) From nhodgson at bigpond.net.au Tue Aug 24 21:13:21 2004 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Wed, 25 Aug 2004 01:13:21 GMT Subject: J2 0-2-6 is available References: <3A81C87DC164034AA4E2DDFE11D258E3022E52@exchange.hqamor.amorhq.net> Message-ID: I'd like to dissent on "using". To me, this code does not read well. using: classmethod def foo(cls): pass foo *is* a class method, it is not *using* a class method. In C#, "using" has too meanings: the first is to import a library and the second is to acquire a resource which will be automatically released. Both of these are seem reasonable as some thing (the object of the using clause) is being used. "classmethod" is implemented as a transform that is applied to foo but implementation is the wrong thing to emphasise here: it is the intention that should be emphasised. The intention here is for foo to be a class method. Neil From peter at engcorp.com Fri Aug 20 07:07:18 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 20 Aug 2004 07:07:18 -0400 Subject: How to change a file's date/timestamp? In-Reply-To: References: Message-ID: <84Gdneea3r9xR7jcRVn-tw@powergate.ca> pythos wrote: > How do you change a file's last-modified date and timestamp in Python? utime(...) utime(path, (atime, utime)) utime(path, None) Set the access and modified time of the file to the given values. If the second form is used, set the access and modified times to the current time. This and many other functions are in the 'os' standard module, one of the few very very widely used and useful modules... you should read the online docs for it, along with "sys", and "time" at least, before doing any more coding. ;-) -Peter From adurdin at gmail.com Wed Aug 11 08:08:28 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Wed, 11 Aug 2004 22:08:28 +1000 Subject: Integers have docstring for int() Message-ID: <59e9fd3a04081105087366db98@mail.gmail.com> I accidentally discovered that all the basic types in Python have docstrings that describe the functions to create them. For integers, you get: >>> (1).__doc__ 'int(x[, base]) -> integer\n\nConvert a string or number to an integer, if possi ble. A floating point\nargument will be truncated towards zero (this does not i nclude a string\nrepresentation of a floating point number!) When converting a string, use\nthe optional base. It is an error to supply a base when converting a\nnon-string. If the argument is outside the integer range a long object\nwill be returned instead.' Similarly, (1.0).__doc__ gives the docstring for float(), "".__doc__ gives it for str(), [].__doc__ gives it for list(), and {}.__doc__ gives it for dict(). This seems a little unexpected to me; is there any particular reason for this behaviour? From nomail at nospam.no Sat Aug 7 14:50:59 2004 From: nomail at nospam.no (Dominic) Date: Sat, 07 Aug 2004 20:50:59 +0200 Subject: @decorators - module ? In-Reply-To: References: Message-ID: I do not know much about decorators yet, but how about a decorator module for default stuff e.g. synchronized etc.? Does this make sense? Ciao, Dominic From martin at v.loewis.de Mon Aug 2 10:14:04 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 02 Aug 2004 16:14:04 +0200 Subject: Sets Module Bug? In-Reply-To: References: Message-ID: <410e4c29$0$165$9b622d9e@news.freenet.de> > >>> Set((1,2,3)) [...] > How can a Set using a tuple or list be ok, but not a tuple of lists? I think you are confused by the syntax above. This expression constructs a Set object, and fills it with the members of the tuple. In no way does the Set "use" the tuple - once the Set is created, the tuple goes away. So you should have asked "How can a Set containing numbers be ok, but not a Set containing lists?", to which the other two posters gave the right answer. Regards, Martin From nospam at nowhere.hu Mon Aug 9 07:54:16 2004 From: nospam at nowhere.hu (Miklós) Date: Mon, 9 Aug 2004 13:54:16 +0200 Subject: Going the PL/1 way References: Message-ID: "Christian Tismer" wrote in message news:mailman.1381.1092046190.5135.python-list at python.org... > Ooh, this is truely too much fear. Decorators are about > modification of how code is understood, but not modification. > [ If it were so, then I'd be probably much more interested :-) ] [..snip..] > > Now, with the mentioned extra line, the function object is > modified in a way that it understands that it is an ordinary > function, and it works in both cases: > [..snip..] > What you have see is, that staticmethod has to be called *after* > the function is defined. The modified function is assigned to > the class as a post process. [..snip..] > to see whther the function is modified somehow. [..snip..] > This is the basic idea what a decorator does: > Make modifiers like classmethod into a prefix > of a function. Great, so it's still about code modification. With Python decorators, a method/function can be modified virtually in any way, outside its declaration. Sure you could override things before, too, but now this is a request for code abuse. Best, Mikl?s > -- > Christian Tismer :^) > Mission Impossible 5oftware : Have a break! Take a ride on Python's > Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ > 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ > work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 > PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 > whom do you want to sponsor today? http://www.stackless.com/ > From duncan.booth at invalid.invalid Wed Aug 11 05:08:58 2004 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 11 Aug 2004 09:08:58 GMT Subject: how to dispatch objects depending on their class References: <4118dd4a$1@maser.urz.unibas.ch> <4119d33c$1@maser.urz.unibas.ch> Message-ID: Curzio Basso wrote in news:4119d33c$1 at maser.urz.unibas.ch: > Is it correct that in the visitor pattern the dispatching would be > delegated to the classes, like with: > > Is this correct? > Roughly yes, but with a dynamic language like Python you can easily extract the implementation out into a mixin class rather than repeating what is essentially the same code everywhere. e.g. >>> class VisitorMixin: def accept(self, visitor): getattr(visitor, 'visit_' + self.__class__.__name__)(self) >>> class A(object, VisitorMixin): pass >>> class B(A): pass >>> class Visitor: def visit_A(self, object): print "Visiting an A", object def visit_B(self, object): print "Visiting a B", object >>> a = A() >>> b = B() >>> v = Visitor() >>> a.accept(v) Visiting an A <__main__.A object at 0x00A8BF10> >>> b.accept(v) Visiting a B <__main__.B object at 0x00A8B530> >>> In practice the accept function could be more complicated, e.g. visiting child objects or handling errors more intelligently. From insert at spam.here Tue Aug 17 22:21:45 2004 From: insert at spam.here (Doug Holton) Date: Tue, 17 Aug 2004 21:21:45 -0500 Subject: PEP 318: Can't we all just get along? In-Reply-To: References: <20040817181725194-0400@braeburn.themorgue.org> Message-ID: Michael J. Fromberger wrote: > In article <20040817181725194-0400 at braeburn.themorgue.org>, > Kevin Smith wrote: > >>Bear with me, but I'd like to propose one more syntax that is simple, >>easy for newbies to understand, and nowhere near as powerful as the >>current PEP's syntax. However, it doesn't add incoherent, arbitrary >>syntax either. >> >>def classmethod foo(x, y, z): >> pass >> >>That's it. One "decorator" that is a callable object that takes a >>method as it's only argument. No expressions, lists, tuples, etc. Just >>one callable object. Ok, if you absolutely must have more than one. >> >>def classmethod synchronized foo(x, y, z): >> pass >> >>Once again, no expressions. I know that this isn't going to solve >>everyone's type-checking, metadata, and function attribute problems, but >>let's face it, using this PEP for all of those things just creates ugly >>syntax. There must be more Pythonic ways to do those things in their >>own PEPs. > > > Kevin, > > +1 for this idea. I posted the same thing to python-dev (although it took a week for the post to appear) and some guy said -infinity or something smart like that. I think it is simpler to use keywords for classmethod and staticmethod at least. Those are builtin features of python, just like they are builtins for java (which has keywords for its builtins like static, abstract, interface, etc.). I propose this *in addition* to whatever decorator syntax we add. We shouldn't consider staticmethod and classmethod as decorators. From ajsiegel at optonline.com Wed Aug 18 19:39:48 2004 From: ajsiegel at optonline.com (Arthur) Date: Wed, 18 Aug 2004 23:39:48 GMT Subject: I would really like the code for a dome in vpython References: <8f17f4bc.0408181349.46c34b2@posting.google.com> Message-ID: On 18 Aug 2004 14:49:54 -0700, alikakakhel3 at hotmail.com (Ali) wrote: >Please anyone I would really like the code for makinga dome in >vpython. I would like to be able to adjust he color, axis, radius, and >pos. You will lucky to find something readymade for VPython. This looks like it would be helpful for finding dome corrdinates, which you can then use to plug-in to VPython: http://www.applied-synergetics.com/ashp/html/domes.html And Kirby is probably an excellent source of information in the area of the intersection of domes/Python/VPython. He knows a good deal about each of these things. I don't know whether he monitors this list. You might try posting to edu-sig at python.org which I know he monitors, to see if he has something to suggest. I might have some other suggestions if a understood what you were trying to accomplish, and why. Art From peter at engcorp.com Thu Aug 26 01:16:10 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 26 Aug 2004 01:16:10 -0400 Subject: urllib hangs In-Reply-To: References: Message-ID: Jay Donnell wrote: > I don't understand the inner workings of the socket or timeoutsocket > modules. On it's face it doesn't make sense that importing > timeoutsocket would magically override the behaviour of socket without > me doing anything else to the socket module. This appears to be what > happens, but it certainly isn't clear to someone that doesn't know how > it works. Here is what timeoutsocket says, "After this module > has been imported, all socket creation goes through this shim. ". > After reading this I was unsure if I needed to install > timeoutsocket.py into the base python distro because, again, it seems > odd that simply dropping timeoutsocket.py into my cwd and importing it > will override the behaviour of the socket module. This didn't say > "exactly what I need to do". Yes it does. It may seem odd, but it does in fact say something that is exactly what you should do. > It assumed a few things that seemed odd > to me. How does timeoutsocket.py " insert a shim into the socket > module."? What does that mean??? It wasn't clear! In the time it took > you and the other guy to criticize me you could have simply said, > "yeah, just drop it into your cwd and import it". Just because you disbelieved the words doesn't mean they aren't clear. Maybe it should say "do this... it works, really!". Would that have helped? Anyway, in the time it took us all to have this discussion, you could really easily have just tried it and seen for yourself that it did work. Python has a nice interactive interpreter prompt just for such things, and it's good to get in the habit of using it. > P.S. - I really do appreciate the help that Benjamin gave. And yet he says he didn't know how it worked either, but you believed him and not the comments in the code itself. I can see that despite anything any of us say about the inadequacy of the approach you took you are right and we're wrong. Carry on... -Peter From ville at spammers.com Mon Aug 30 09:36:52 2004 From: ville at spammers.com (Ville Vainio) Date: 30 Aug 2004 16:36:52 +0300 Subject: Announcing PyCs, a new Python-like language on .Net References: <99dce321.0408292132.36ef381e@posting.google.com> Message-ID: >>>>> "Steve" == Steve Holden writes: >> than comp.lang.python. Sorry for the flame, but you really need it. >> Steve> It could have been a much worse flame and still Steve> justified. Mark should gratefully take your advice. I dunno - Mark's general tone has been rather constructive, which is not really flameworthy. It might be more useful if he, say, integrated static typing from Boo to IronPython, but if someone is enthusiastically (gotta admire Mark's energy) hacking on something (anything) related to *Python codebase it can still be of interest to people here - and it can also improve the codebase in the process. -- Ville Vainio http://tinyurl.com/2prnb From chrish at debian.org Mon Aug 16 15:59:44 2004 From: chrish at debian.org (Christian Hudon) Date: Mon, 16 Aug 2004 15:59:44 -0400 Subject: __getattr__-like method for current module. Message-ID: <41211230.4080106@debian.org> Hi, I'd like to be able to trap lookups of attributes of the current module. Exactly like what __getattr__ does, but for modules. As an exmaple, I'd like to be able to do: File foo.py enable_magic() def foo(): undefined_function(1, 2) and then when I call foo.foo from somewhere else, the lookup of the undefined undefined_function symbol is trapped and I can (say) dynamically define and return a function. I know about the trick of defining a class instance that has a __getattr__ that does what you want and overwriting the entry for the module in sys.modules, but that only works when accessing that module from the outside. So in the example, my undefined_function call would have to be prefixed by the name of the magic module. I tried building a subclass of module and installing that before all the def and class in the module are executed. I tried injecting a __getattr__ method in the globals dict of the module. I tried a bunch of other things that I forgot... None of these work (or at least I couldn't make them work). Among other things, it seems that the module part of Python is quite a bit less dynamic than the rest of the language. (Although I'd be happy to be proved wrong.) Any way of doing what I want to do? Christian From http Fri Aug 6 14:48:40 2004 From: http (Paul Rubin) Date: 06 Aug 2004 11:48:40 -0700 Subject: generating uuids / guids References: <2nhnrfF13jq0U1@uni-berlin.de> Message-ID: <7x8ycs9k6v.fsf@ruckus.brouhaha.com> Jon Perez writes: > Is there a Python function that works on all platforms (not just Win32) > to generate such in the DCE / Microsoft format? > > If not present, this looks like it would be a very Pythonic addition > to the standard library. Why do you say that adding Windows GUID generation to non-Windows platforms would be Pythonic? Yeesh. From zanesdad at bellsouth.net Thu Aug 26 14:42:10 2004 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Thu, 26 Aug 2004 14:42:10 -0400 Subject: Mysql in Python? In-Reply-To: <2p6nnpFhoue1U1@uni-berlin.de> References: <2p6m32Fh7o9oU1@uni-berlin.de> <2p6nnpFhoue1U1@uni-berlin.de> Message-ID: <412E2F02.2050007@bellsouth.net> Stefan Stolz wrote: >Jeremy Jones wrote: > > > >>I'm not sure, but I believe that MySQLdb is included in this project: >> >>http://sourceforge.net/projects/mysql-python >> >>(which appears to have been updated only a couple of months back, so >>that's good news). >> >> >Thank you, but i don`t understand why there is nothing implemented in >Python? > >I was a little konfused after reading the doku of mysql-python, because >there the author says its better to use MySQLdb ;-) ?!?! > > So, are you wanting a pure Python module to connect to MySQL? I'm not sure there are any that exist. Jeremy From cemerick at snowtide.com Sun Aug 15 21:54:01 2004 From: cemerick at snowtide.com (Chas Emerick) Date: Sun, 15 Aug 2004 21:54:01 -0400 Subject: Decorators: an outsider's perspective In-Reply-To: <20040815185534.EFEDB1E400C@bag.python.org> References: <20040815185534.EFEDB1E400C@bag.python.org> Message-ID: <25000874-EF27-11D8-9F63-000A95B336F2@snowtide.com> On Aug 15, 2004, at 2:55 PM, Bengt Richter wrote: >> Define fragile. If you mean, easy to break, I don't see it. There >> would be only one way to define an instance method: name its first >> parameter 'self'. There would be only one way to define a class >> method: >> name its first parameter 'klass' or 'cls' (or some other synoynm that >> we >> can all vote on). All other methods would be static methods. >> >> How is that fragile? >> > In a narrow context such as distinguishing between methods, > classmethods, > and staticmethods, ISTM not so fragile. OTOH, generalize the concept > too much > and you get 'hungarian' naming rules as a way of controlling > processing. > Perhaps that is what Chas and Istvan were worrying about. Ach, that'll teach me to read all the digests in my mailbox before mailing to the list :-) Yes, that's one of the aspects of my worries in connection with this proposal. I wouldn't use 'fragile' to describe the nature of the proposal. 'Sneaky' is a better one, in that it would be far, far too easy for someone to inadvertently make a classmethod without intending to. The decorator approaches to changing a method's type as well as the old/current approach of func=staticmethod(func) are both superior in this respect, in that they require a distinct intention by the code's author. Another way of looking at this is that the use of an explicit self argument was chosen, one can surmise, as a way of making it completely clear what is going on in the context of a member function (i.e. better to write self.attr=x than just attr=x...I think this is mentioned in the python FAQ). It would run completely counter to that decision to now go back and start hanging implicit semantics off of arguments that were originally specified for clarity's sake. - Chas Emerick From fumanchu at amor.org Mon Aug 16 02:17:56 2004 From: fumanchu at amor.org (Robert Brewer) Date: Sun, 15 Aug 2004 23:17:56 -0700 Subject: ADOdbapi converting all data to strings Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022DFA@exchange.hqamor.amorhq.net> max wrote: > I am trying to access a foxpro database, using odbc all is well except > that dates prior to 1970 are not returned as valid usable data, so > would like to use ADO. When I select data containing numbers (long or > float) they are converted and returned as unicode strings. Dates are > returned as datetime.date which is great. Is there any way to change > this behavior other than to explicitly change back all fields using > cursor.description information. I *think* you're saying that you have a COM date (which is similar to a float), and want a datetime.date. import datetime # 12/30/1899, the zero-Date for ADO = 693594 zeroDate = datetime.date(1899, 12, 30).toordinal() def coerce_datetime(value): return datetime.date.fromordinal(int(float(value)) + zeroDate) COM times are more complicated. Inquire further if you need to handle them. Robert Brewer MIS Amor Ministries fumamchu at amor.org From hawk at slytherin.ds.psu.edu Fri Aug 27 10:45:20 2004 From: hawk at slytherin.ds.psu.edu (Dr. Richard E. Hawkins) Date: Fri, 27 Aug 2004 14:45:20 +0000 (UTC) Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <776e0325.0408260433.449660c8@posting.google.com> <412dfc1c$0$65599$a1866201@newsreader.visi.com> Message-ID: In article <412dfc1c$0$65599$a1866201 at newsreader.visi.com>, Grant Edwards wrote: >On 2004-08-26, Sara wrote: >> Hey this ain't no CULT! Our creedo is simply: >> "Larry said it, I believe it, THAT settles it!" >> If you don't believe it just look at the reaction if any questions any >> element of Perl design! >Over here in c.l.python, it's more like > "Guido said it, that settles it, but we're going to discuss > it endlessly and and vote on it using six or seven > different voting algorithms anyway. Then we'll argue about > the voting algorithms." Now I understand what happenend in the 2000 election: Al Gore, after inventing the internet, became a python programmer :) hawk -- Richard E. Hawkins, Asst. Prof. of Economics /"\ ASCII ribbon campaign dochawk at psu.edu 111 Hiller (814) 375-4846 \ / against HTML mail These opinions will not be those of X and postings. Penn State until it pays my retainer. / \ From stefan at eischet.com Sat Aug 7 07:14:31 2004 From: stefan at eischet.com (Stefan Eischet) Date: Sat, 7 Aug 2004 13:14:31 +0200 Subject: Killing children In-Reply-To: <87d624vxt2.fsf@debian.laymusic.org> References: <87smb0w4ln.fsf@debian.laymusic.org> <87d624vxt2.fsf@debian.laymusic.org> Message-ID: On 06.08.2004, at 22:03, Laura Conrad wrote: >>>>>> "Stefan" == Stefan Eischet writes: > > Stefan> I sometimes use os.system with pskill from > Stefan> http://www.sysinternals.com/ntw2k/freeware/pskill.shtml - > Stefan> this should do what you want. > > I don't see that it really saves me much over using the cygwin kill > command. Right. The program I use this in doesn't run on cygwin but on "normal" win32, so I have no kill command there. Another poster mentioned the possible difference between handles and pids, which I didn't notice in my case. I only feed the number returned from the spawn call into pskill, which just does the right thing. Stefan // stefan at eischet.com // From greg at cosc.canterbury.ac.nz Fri Aug 27 00:22:41 2004 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Fri, 27 Aug 2004 16:22:41 +1200 Subject: Call for signatories for J2 In-Reply-To: References: Message-ID: <2p7r8hFhfg99U1@uni-berlin.de> Robert Brewer wrote: > Isn't *anyone* going to vote against? Or at least formally abstain? > _Somebody_ out there must disagree strongly with this. Against. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From richie at entrian.com Fri Aug 20 08:54:18 2004 From: richie at entrian.com (Richie Hindle) Date: Fri, 20 Aug 2004 13:54:18 +0100 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: <2tsbi0ticv0fqq1df7u4m4ltme1ijdqf1k@4ax.com> > each poster gets 3 votes among the lettered choices on the Wiki page above. H I J2 Kudos to Paul for arranging this. I hope it works (for some value of 'works' that we can vote on later 8-) -- Richie Hindle richie at entrian.com From eurleif at ecritters.biz Sat Aug 21 20:51:12 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sat, 21 Aug 2004 20:51:12 -0400 Subject: Getting benifits of database transactions in an OO way? Message-ID: <2oq8pmFdd2nfU1@uni-berlin.de> I'm coding an application which makes extensive use of a PostgreSQL database. To make code clearer, I'm wrapping various row types in objects. Sample code would look something like this: import people fred = people.find_by_name('Fred Flintstone') barney = people.find_by_name('Barney Rubble') fred.money -= 10 barney.money += 10 fred.save_data() barney.save_data() Right now, the Person.save_data method also commits the current database transaction. But that seems to remove the benifit of having a database with transactions: If something dies between the call to fred.save_data() and barney.save_data(), Fred's $10 will end up in a black hole somewhere. Is the only option making Person.save_data not commit the transaction, and require calling code do so on its own? I don't really like the idea, since it removes the abstraction which allows the Person class to save data anywhere it chooses (not just in a database). From nothanks at nothere.com Wed Aug 25 18:28:06 2004 From: nothanks at nothere.com (Emiliano Molina) Date: Wed, 25 Aug 2004 22:28:06 GMT Subject: Subclassing built-in types In-Reply-To: References: Message-ID: Emiliano Molina wrote: --- some stuff I was confused about --- > Where can I find that documentation? I've looked through the manual but > can't find anything relevant. Google searches bring up articles that > talk about code as described in my first example but I can't find > anything like the second. I received no answers to my post (not complaining) and I am curious as to wether it was a silly question or if there was no answer because what I wanted to know is not documented. Thanks for your replies (if there are going to be any!) From in.aqua.scribis at nl.invalid Sun Aug 29 11:16:59 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Sun, 29 Aug 2004 17:16:59 +0200 Subject: possible python bug here In-Reply-To: References: Message-ID: manuel schreef: > In the sample below, the foo function modify the b list, > but I think it should modify only c, not b! It work > correctly if if b is one dimension list instead two. > > def foo(aList): > print "use foo..." > aList[2][0] += .35 > aList[2][1] += .35 > aList[2][2] += .35 > > p = [2.5,2.5,2.5] > b = [p,p,p,p] > > c=b[:] #c is a totally new list cloned from b, it's not an alias! No it isn't. You didn't make a deep copy. -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html The Halloween Documents: http://www.opensource.org/halloween/ From jzgoda at gazeta.usun.pl Fri Aug 27 16:12:51 2004 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Fri, 27 Aug 2004 20:12:51 +0000 (UTC) Subject: Class Friends References: <20040827081556.657c3fac.a@c.d> Message-ID: Shalabh Chaturvedi pisze: >> Is it possible to make classes friends in Python? > > Not just possible - all Python classes are always friends with each > other (something that rubs off Python programmers, I suppose :) That's why other call us "friendly people". -- Jarek Zgoda http://jpa.berlios.de/ From __peter__ at web.de Wed Aug 4 03:07:12 2004 From: __peter__ at web.de (Peter Otten) Date: Wed, 04 Aug 2004 09:07:12 +0200 Subject: Mucking with the calling scripts namespace (For a good reason, honest!) References: Message-ID: Christopher T King wrote: > setattr(). Something as simple as the following would suffice: > > class objifier(object): > def __init__(self,d): > self.__dict__ = d > > __main__ = objifier(globals()) Or something even simpler: import __main__ > Then you do stuff like: > >>>> __main__.b = 6 >>>> b > 6 >>>> b = 20 >>>> __main__.b > 20 >>>> getattr(__main__,"b") > 20 >>>> setattr(__main__,"b",6) >>>> b > 6 Peter From td.brown at verizon.net Wed Aug 18 08:56:04 2004 From: td.brown at verizon.net (Tom Brown) Date: Wed, 18 Aug 2004 05:56:04 -0700 Subject: age of Python programmers In-Reply-To: References: Message-ID: <200408180556.04044.td.brown@verizon.net> I am 35. -Tom On Wednesday 18 August 2004 05:20, Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... From h.b.furuseth at usit.uio.no Tue Aug 3 05:29:34 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 03 Aug 2004 11:29:34 +0200 Subject: automatic delegation Message-ID: Is it possible to write a metaclass or something so that with a class definition not much larger than this: class foo: def __init__(self, val): self.val = val operations on a foo instance f will be applied to f.val? E.g. str(f) -> f.__str__() -> f.val.__str__(). -- Hallvard From rnd at onego.ru Fri Aug 13 17:03:05 2004 From: rnd at onego.ru (Roman Suzi) Date: Sat, 14 Aug 2004 01:03:05 +0400 (MSD) Subject: Best programming language Message-ID: ;-) Just type into google "best programming language" and press (I am lucky) Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3 From in.aqua.scribis at nl.invalid Sun Aug 22 17:05:29 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Sun, 22 Aug 2004 23:05:29 +0200 Subject: python doesn't like my numbers In-Reply-To: <2osfspFdnjbcU1@uni-berlin.de> References: <2osfspFdnjbcU1@uni-berlin.de> Message-ID: paul k schreef: > hi, > > is there any way to convince python not to take my (phone)numbers > starting with zero as octals? > > >>> int(088) > File "", line 1 > int(088) > ^ > SyntaxError: invalid token What is the integer value of a phone number? -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From ialbert at mailblocks.com Thu Aug 5 22:39:19 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Thu, 05 Aug 2004 22:39:19 -0400 Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) Message-ID: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> Paul McGuire wrote: > Please reconsider the "def f() [classmethod]:" construct. Instead of > invoking a special punctuation character, it uses context and placement, > with familiar old []'s, to infuse the declaration of a function with special > characteristics. If this causes def lines to run longer than one line, > perhaps the same rule that allows an unmatched "(" to carry over multiple > lines without requiring "\" continuation markers could be used for unmatched > "["s, as in: > > def f() [ staticmethod, > synchronized, > alphabetized, > supersized, > returns('d') ]: Well said! Reading the posts here and in the python-dev I've counted the following votes for it (I'm sure that there were a lot more but it is awfully hard to keep up with the posts on the topic). Voting for the "list-after-def" syntax as shown above: Peter Hansen AdSR Paul McGuire m Phillip J. Eby pje at telecommunity.com C. Barnes Aahz aahz at pythoncraft.com Skip Montanaro skip at pobox.com Bill Janssen janssen at parc.com Istvan Albert ialbert at mailblocks.com I have the feeling that this always was and still is the favorite. Ladies and Gents, start your engines and rally around this syntax (if you prefer it of course) so that there is evidence that it should be taken as a serious candidate. Istvan. From chris.cavalaria at free.fr Wed Aug 11 19:34:57 2004 From: chris.cavalaria at free.fr (Christophe Cavalaria) Date: Thu, 12 Aug 2004 01:34:57 +0200 Subject: Rather than decorators, how about sections? References: <1C74C038-EBB6-11D8-8889-000A95857E5C@eischet.com> <411a6b9d$0$13688$636a15ce@news.free.fr> Message-ID: <411aad21$0$29662$636a15ce@news.free.fr> Stefan Eischet wrote: > Hi. > > On 11.08.2004, at 20:55, Christophe Cavalaria wrote: > >> Paul Morrow wrote: >> >>>> class Foo(object): >>>> def spam(Foo): >>>> print "Class Method" >> >> What is that ? It's ugly, it's a name alias and it'll be incredibly >> confusing when classmethods are inherited, which is exactly the most >> common >> use case for classmethods. > > Right, I don't even like it myself, but I still like it better than the > pie for daily work. > How about using "class" as a first parameter? Even uglier, I fear. How about cls ? > You cut the good part of my post, I think ;-) > >>> I like it! It's simple, clear, ... Why isn't this the hands-down best >>> solution? Why do we want to be more verbose than necessary? >> >> It isn't a solution. It only "resolves" the problem for staticmethod >> and >> classmethod which are only a very small part of what we do/want to do >> with >> decorators. > > And IMHO this is a part you should keep your ugly pies out of, because > they're suggesting that something special is going on, though it's just > a static method you're defining. > > I was only referring to static methods and class methods, and since I > don't see no use in decorators for my daily work (which does NOT mean > they won't help many people!), I won't argue about other uses. > > > If you really think it's necessary to have special syntax for caching > return values, for checking parameter types etc, you're welcome, even > if I personally doubt the usefullness of that stuff - you can still > cache results *in your method*, for example. Or will we decorate our > methods so much that they all resolve to a single "pass" instruction in > the body? Some pie decorator examples look like the function body, > stacked on top of the def line. *That* is ugly. ;-) > > > For common stuff like static methods, I do still think decorators are > overkill and the wrong way to go. It's true that decorators are a somewhat weird mean to define classmethods and staticmethods. But like I said, it's not the only use case for decorators. You can't just say : Here's a new syntax for decorators. Oh, by the way, it only works for staticmethod and classmethod but who uses the other decorators anyway ? >> - It'll break all existing classmethods > > I didn't say "get rid of the old way of doing def m(x); > m=classmethod(m);", so I don't think it would break any existing > classmethod. When @decorators are in 2.4, will classmethod() and > staticmethod() be removed at the same time? That would also break each > and every legacy classmethod, wouldn't it? No since @decorate is only a shortcut for the old syntax which was deemed unclear and at the wrong position :) Anyway, I don't think it's possible to implement that in the grammar, and even if it's possible, it'll be really tricky to handle both the old and the new syntax for classmethods at the same time. There will be some serious compiler magic going on then. >> - It'll break code that binds arbitrary functions as a member >> function. You >> can't do things like that anymore : >> >>>>> def f(s): >>>>> print "Hi, I'm function f" >>>>> class Klass: >>>>> doIt = f >>>>> Klass().doIt() > > Okay, this might break, depending on how all this gets implemented. I > wasn't even aware that this worked, perhaps because I'm usually > restricting myself to a *very* obvious subset of Python. (My general > rule is: I might be hit by a bus tomorrow, so a poor Java programmer > might need to learn to read my code very quickly. I try to never write > stuff that breaks this rule.) > How would you solve this problem with decorators, btw? > class Klass: > @stuff > doIt = f > ? Decorators don't solve that problem. I was just pointing at a current use case that would probably break with that new proposal for classmethods. > If there was a rule that assigned functions in the class body (doIt=f) > default to normal methods whatever their first arg is called, would > that be okay? After all, that is how it works right now. And there's even better : class Klass: pass Klass.doIt = f That one works too :) > Stefan > > // stefan at eischet.com // From eldiener at earthlink.net Wed Aug 11 22:07:31 2004 From: eldiener at earthlink.net (Edward Diener) Date: Thu, 12 Aug 2004 02:07:31 GMT Subject: Static method object not callable References: Message-ID: Bengt Richter wrote: > On Wed, 11 Aug 2004 02:40:07 GMT, "Edward Diener" > wrote: > >> Paul Morrow wrote: >>> Edward Diener wrote: >>>> This simple code example gives me the message, "TypeError: >>>> 'staticmethod' object is not callable". >>>> >>>> class X(object): >>>> def Y(x): >>>> print x >>>> Y = staticmethod(Y) >>>> ad = { 1 : Y } >>>> def Z(self): >>>> self.ad[1](3) >>>> x = X() >>>> x.Z() >>>> print "Done." >>>> >>>> I know there must be a way to have a class attribute reference a >>>> static method, and then call that static method through the >>>> reference, so if anyone can correct this it would be appreciated. > By 'reference' are you referring to the Y in ad? >>>> Yes. I understand now why it won't work but I think this is a limitation of Python. Evidently, if I set up my class attribute 'ad' to be "ad = { 1 : X.Y }", then calling static method X.Y through "self.ad[1](3)" would work. But Python does not allow me to say 'X.Y' from within a class attribute of X because X has not been fully defined as a class at that time. As one person answered, I can say "X.ad = { 1 : X.Y }" after the definition of class X and that works fine. But that is very kludgy to me, forcing me to wait until the definition of X is finished in order to create my ad class attribute. I thank you very much for the explanation of _get_ and how static methods work in Python. It still feels unnatural not to be able to reference a class attribute of a class in another class attribute of the same class from within the class definition. From lbates at swamisoft.com Wed Aug 25 13:29:28 2004 From: lbates at swamisoft.com (Larry Bates) Date: Wed, 25 Aug 2004 12:29:28 -0500 Subject: Capturing exceptions? References: Message-ID: You need to set up an exception hook function, register it with Python and have it write out the traceback information to your file. def excepthook(type, value, tb): # # This function allows the user to redefine what happens if the program # aborts due to an uncaught exception. # import traceback # # Get traceback lines and append the current session log # tblines=traceback.format_exception(type, value, tb) # # Insert code to write to file here # f=open('traceback.log', 'a') f.writelines(tblines) f.close() sys.exit(0) Then in main program # # Set the sys.excepthook so I can clean up properly if main program aborts # sys.excepthook=excepthook "Dfenestr8" wrote in message news:pan.2004.08.25.17.12.17.521438 at yahoo.com.au... > Hi. > > What's the easiest way to capture the traceback from an exception, and > write it to a file? Ideally, I'd like to be able to do something like: > > >try: > > main() > >except: > > write the traceback to a file From fumanchu at amor.org Mon Aug 23 23:02:08 2004 From: fumanchu at amor.org (Robert Brewer) Date: Mon, 23 Aug 2004 20:02:08 -0700 Subject: newbie: confused with example in Learning Python 2nd Edition:cananyone give a hint Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E4C@exchange.hqamor.amorhq.net> D'oh! That'll teach me to read too quickly. <:) > -----Original Message----- > From: python-list-bounces+fumanchu=amor.org at python.org > [mailto:python-list-bounces+fumanchu=amor.org at python.org] On > Behalf Of Paul Rubin > Sent: Monday, August 23, 2004 6:58 PM > To: python-list at python.org > Subject: Re: newbie: confused with example in Learning Python > 2nd Edition:cananyone give a hint > > > "Robert Brewer" writes: > > > So: why defitions of self.push and self.pop are defined as > > > 'data.append' rather than '_data.append', etc. > > It's an error. It should say _data.append. > > > Hint: Python doesn't have variables like other languages > do. The line: > > > > self._data = list(data) > > > > does not make a copy of "data". Instead, it binds a new name > > (self._data) to the same object which the name "data" refers to. > > The list function does make a copy. > > Python 2.3.4 (#1, Jul 24 2004, 19:45:58) > [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2 > Type "help", "copyright", "credits" or "license" for more > information. > >>> j=[9,8] > >>> a=list(j) > >>> a is j > False > >>> j.append(2) > >>> j > [9, 8, 2] > >>> a > [9, 8] > >>> > -- > http://mail.python.org/mailman/listinfo/python-list > From vivek.bhaskar at gmail.com Tue Aug 3 20:51:06 2004 From: vivek.bhaskar at gmail.com (Vivek) Date: 3 Aug 2004 17:51:06 -0700 Subject: SOAPpy and WSDL and basic authentication Message-ID: <82ae0630.0408031651.4f068f74@posting.google.com> Hi, Can anyone provide me with sample code that will allow me to use SOAPpy with a WSDL file using HTTP basic authentication? The only thing I've been able to find on the net is SOAPpy.URLopener. However, I am unclear what the relationship is between SOAPpy.URLopener and SOAPpy.WSDL is. Is it as straightforward as this? > from SOAPpy import WSDL > url = 'http://user:pass at www.server.com/path/to/wsdl' > ssClient = WSDL.proxy(url) > ssClient.Test() # assuming Test is a SOAP-Action Or do I need to use SOAPpy.URLopener like so? > from SOAPpy import WSDL > from SOAPpy import URLopener > url = 'http://user:pass at www.server.com/path/to/wsdl' > url1 = URLopener.URLopener(username='user',passwd='pass') > ssClient = WSDL.proxy(url1.open(url)) > ssClient.Test() # assumption as above Or do I need to do something completely different? All help is much appreicated. Vivek From chris.cavalaria at free.fr Sat Aug 28 18:12:32 2004 From: chris.cavalaria at free.fr (Christophe Cavalaria) Date: Sun, 29 Aug 2004 00:12:32 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> <87hdqok9i6.fsf@sinken.local.csis.hku.hk> <1rfz68ely9.fsf@rovereto.ifi.uio.no> <876574k7du.fsf@sinken.local.csis.hku.hk> <1r3c28ejis.fsf@rovereto.ifi.uio.no> Message-ID: <41310350$0$13687$636a15ce@news.free.fr> Igor V. Rafienko wrote: > [ Paul McGuire ] > > [ ... ] > >> In fact, you can cite examples on this argument in either direction; > > > I am a bit curious, what are the arguments _against_ an explicit > end-of-block marker? Does such a marker create any problems? (I know > that it solves a couple, though). It's unpythonic ? > As a side note -- my last employer had absolutely horrible coding > conventions. No one liked them (developers and management included). > However, everyone had to comply, and despite an occasional nastiness, > the bug that you illustrated could not have happened in that > environment, because _every_ if was required to have its body within > braces. Well, there are worse coding conventions than that. Remember that chaining unbraced if and else if becomes ambiguous. From anthonybaxter at gmail.com Thu Aug 26 10:44:17 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 27 Aug 2004 00:44:17 +1000 Subject: Call for signatories for J2 In-Reply-To: References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> Message-ID: On Thu, 26 Aug 2004 14:44:27 +0100, Michael Sparks wrote: > Using proposed J2: (tested) > class Foo: > using: > staticmethod > eval("(memoise,esiomem)[x==0]") > def Hoo(Who, *args): > print "Yoo", Who Why wouldn't you instead write this as: if x == 0: dec = esiomem else: dec = memoise @staticmethod @dec def Hoo(Who, *args): .... Don't use eval unless it's absolutely necessary, _please_. From ville at spammers.com Sun Aug 8 03:20:09 2004 From: ville at spammers.com (Ville Vainio) Date: 08 Aug 2004 10:20:09 +0300 Subject: Paul Graham on Python hackers References: <10hbik7nskhgn90@corp.supernews.com> Message-ID: >>>>> "Mike" == Michael Geary writes: zoltan> This a flamebait, right? Otherwise I would be interested zoltan> in the features which make Python similar to Java zoltan> (shudder). Mike> Ville Vainio: >> Abundant reference semantics. Of course this is true of all OOP Mike> What are "Abundant reference semantics"? References are used all over the language: MyClass o = GetObject(); MyClass o2 = o; // o2 will point to the name object This is much like in Python (being the optimal way of doing OOP after all), and in contrast to Perl and C++ that have special syntax for using references/pointers. -- Ville Vainio http://tinyurl.com/2prnb From djc at object-craft.com.au Tue Aug 24 00:02:22 2004 From: djc at object-craft.com.au (Dave Cole) Date: Tue, 24 Aug 2004 14:02:22 +1000 Subject: newbie: confused with example in Learning Python 2nd Edition: can anyone give a hint In-Reply-To: <412ab47c_5@newsfeed.slurp.net> References: <56cfb0e3.0408231710.27d78703@posting.google.com> <412ab47c_5@newsfeed.slurp.net> Message-ID: Steven Rumbalski wrote: > Porky Pig Jr wrote: > So the corrected code should look like: > >>>>class Stack: > > ... def __init__(self, data): > ... self._data = list(data) > ... self.push = _data.append > ... self.pop = _data.pop >>>class Stack: ... def __init__(self, data): ... self._data = list(data) ... self.push = self._data.append ... self.pop = self._data.pop -- http://www.object-craft.com.au From b.niemann at betternet.de Tue Aug 31 07:29:55 2004 From: b.niemann at betternet.de (Benjamin Niemann) Date: Tue, 31 Aug 2004 13:29:55 +0200 Subject: Python Usage Statistics In-Reply-To: References: Message-ID: Eric S. Raymond made a comparison of language usage for projects published on sourceforge and freshmeat for his book "The Art of Unix Programming": http://www.faqs.org/docs/artu/ch14s05.html#lang_usage Only covers opensource software and not uptodate anymore though. Anand Pillai wrote: > Hi Folks > > (posting after a loooong time...) > > I have been contracted by an Indian publisher to author an > introductory text book on Python. As a part of the introductory > chapter, I thought it would be a good idea to present a number, a > round-about figure on the approximate *actual* usage of Python out > there in number of developers and/or installations. > > Scrounging the Web for such statistics is proving elusive. The PBF > website seems to be the official place for these, but there also they > just have listings of companies/instituitions using Python, not any > numbers. > > Has anybody done an actual market survey anytime recently on > Python usage in the software community? If so, where can I get access > to this information? I would be more interested in the number of > developers, both commercial/non-commercial who are doing development > using Python. Since almost every Linux distro now a days contains > Python by default, a number based on the installations could prove > faulty. > > Have a nice day. > > -Anand From sbabbitt at commspeed.net Mon Aug 2 20:24:32 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Mon, 2 Aug 2004 17:24:32 -0700 Subject: transforming a list into a string References: Message-ID: <1091493039.363950@news.commspeed.net> "jblazi" wrote in message news:pan.2004.07.31.12.27.23.547000 at hotmail.com... > Let us assume I have a list like > > ['1','2','7','8','12','13] > > and would like to transoform it into the string > > '{1,2},{7,8},{12,13}' > > Which is the simplest way of achiebing this? (The list is in fact much > longer and I may have to cut the resulting strings into chunks of 100 or > so.) > > TIA, > > jb > Try,' >>>items = ['1','2','7','8','12','13'] >>>import string >>>string.join([('{'+str(items[x])+','+str(items[x+1])+'}') for x in range(0,len(items)-1,2)]) Tom From me at privacy.net Mon Aug 2 05:11:49 2004 From: me at privacy.net (Duncan Booth) Date: 2 Aug 2004 09:11:49 GMT Subject: transforming a list into a string References: Message-ID: Christopher T King wrote in news:Pine.LNX.4.44.0408011814020.21160-100000 at ccc4.wpi.edu: > On Sat, 31 Jul 2004, Tim Peters wrote: > >> Absolutely. Note that Peter Otten previously posted a lovely O(N) >> solution in this thread, although it may be too clever for some >> tastes: >> >> >>> from itertools import izip >> >>> items = ['1','2','7','8','12','13'] >> >>> it = iter(items) >> >>> ",".join(["{%s,%s}" % i for i in izip(it, it)]) >> '{1,2},{7,8},{12,13}' >> >>> > > A bit too clever for mine, mostly because neither izip() nor zip() is > guaranteed to process its arguments in a left-to-right order (although > there's no reason for them not to). You should read an earlier thread on this topic: http://groups.google.co.uk/groups?threadm=c91pft%24rl0%2404%241%40news.t-online.com I make exactly that point, that the order isn't guaranteed, and was refuted fairly convincingly by Peter Otten. The documentation says that izip is equivalent to a particular reference implementation. Any implementation which didn't preserve the left to right ordering wouldn't match the reference: Peter Otten wrote: >> Passing the same iterator multiple times to izip is a pretty neat >> idea, but I would still be happier if the documentation explicitly >> stated that it consumes its arguments left to right. > > From the itertools documentation: > > """ > izip(*iterables) > > Make an iterator that aggregates elements from each of the iterables. > Like zip() except that it returns an iterator instead of a list. Used > for lock-step iteration over several iterables at a time. Equivalent > to: > > def izip(*iterables): > iterables = map(iter, iterables) > while iterables: > result = [i.next() for i in iterables] > yield tuple(result) > """ > > I'd say the "Equivalent to [reference implementation]" statement > should meet your request. From elbertlev at hotmail.com Mon Aug 23 17:20:00 2004 From: elbertlev at hotmail.com (Elbert Lev) Date: 23 Aug 2004 14:20:00 -0700 Subject: 2 GB files References: <9418be08.0408221427.182a4d30@posting.google.com> <9418be08.0408221939.7003bd3c@posting.google.com> Message-ID: <9418be08.0408231320.5fe3c40c@posting.google.com> Bart Nessux wrote in message news:... > > I suggest start discussing additions to the library. This will improve > > the package and make it easier to administer. > > > > In my daily programming activities there are several alternatives to > > Python, f.e. Java or .NET with their comprehensive libraries of > > classes (much richer then Python's). And what stops me from using it? > > The size of the distributive! I understand that adding too much will > > result in an increase of the size of distribution, but something has > > to be done. > > Having never used Java or .NET... how do they compare in size to Python? > I've found that the standard Python download works for me in 95% of the > tasks in Windows (sys admin tasks). > Java and .NET are also free. Java run-time and development are free. .NET run-time is free. Java has a little bit better off-the-box library, then .NET, but is much harder to use in nonsuppervised fashion (CLASSPATH junk). Sizes: Java development 130MB, .NET development 110MB + 2GB+ for MSDN and VS (very good). Runtime: Java 32MB and up with options, .NET 18MB. These libraries are more universal (but lower level) then Python's. > But sometimes I need Hammond's win32 > extensions, but only rarely. I've also used the pexpect module a lot... > I wish that would be integrated into the main distro, but overall, I'm > very pleased with the balance of bang for the buck... For windows I consider this a part of standard distribution. Additions you are using depend on what you are douing most. > Oh, I forgot, Python is free. Perhaps the developers are willing to > provide a refund to dissatisfied users ;) They do not :( From crgre.znnf at hgvybt.qr Thu Aug 26 15:12:22 2004 From: crgre.znnf at hgvybt.qr (Peter Maas) Date: Thu, 26 Aug 2004 21:12:22 +0200 Subject: Larry Wall & Cults In-Reply-To: References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: <2p6r21Fho83oU1@uni-berlin.de> Marco Aschwanden schrieb: >> What does the Kaj ... phrase mean? >> "You are dumb", "Your joke is dumb", ...? [...] > letter 'y' - is not esperanto. And your joke is nothing but stupid. Thanks, Marco. Mit freundlichen Gruessen, Peter Maas -- Peter Maas, Aachen, Germany, Tel +49-241-38200 e-mail crgre.znnf at hgvybt.qr From elainejackson7355 at home.com Thu Aug 19 19:04:21 2004 From: elainejackson7355 at home.com (Elaine Jackson) Date: Thu, 19 Aug 2004 23:04:21 GMT Subject: Tkinter References: <8e16829.0408190703.1c6845d7@posting.google.com> Message-ID: Premierement: "Tkinter" (majuscule) Mais il est bien possible que le module n'est pas la (cherchez-le pour etre certain). En tout cas il est disponible sur Internet. HTH "Roland" wrote in message news:8e16829.0408190703.1c6845d7 at posting.google.com... | Salut, | | | J'utilise LNUX RedHat 9.0 et je n'arrive pas ? utilser Tkinter | car ? chaque fois que j'essaye de faire executer un code dans lequel | j'ai import? le module Tkinter, j'obtient: | from tkinter import* | ImportError: No module named tkinter . | Je croyais que ce module ?tait int?gr? ? python. | AIDEZ-MOI | Merci From dd55 at cornell.edu Fri Aug 20 09:19:16 2004 From: dd55 at cornell.edu (Darren Dale) Date: Fri, 20 Aug 2004 09:19:16 -0400 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: J2,J2,J2 From jbenson at lowell.edu Wed Aug 18 21:51:02 2004 From: jbenson at lowell.edu (Jim Benson) Date: Wed, 18 Aug 2004 18:51:02 -0700 (MST) Subject: introspection? In-Reply-To: <200408181736.13789.troy@gci.net> Message-ID: On Wed, 18 Aug 2004, Troy Melhase wrote: > import sys > def F(): > print sys._getframe().f_code.co_name > >>> F() > F ooooh...thanks Troy! indeed that works fine for getting the method name. Thanks to all...and apologies for taking the easy way out by posting to this very helpful list rather than doing more research with google (actually i did do a search for 'python class method introspection' before posting...i didn't look at all the returns). Thanks, Jim From quaggy at gmail.com Fri Aug 27 00:39:02 2004 From: quaggy at gmail.com (Jonathan Wright) Date: 26 Aug 2004 21:39:02 -0700 Subject: Fun transformation problem In-Reply-To: Message-ID: .def trans(paths): . tree = {} . for path in paths: . reduce(lambda branch,node: branch.setdefault(node,{}), path[:-2], tree)[path[-2]] = path[-1] . return tree Also seems to work. ;-) Jonathan. From jason at injektilo.org Sat Aug 21 21:08:27 2004 From: jason at injektilo.org (Jason Diamond) Date: Sat, 21 Aug 2004 18:08:27 -0700 Subject: Detecteing Unicode encodings In-Reply-To: References: Message-ID: Christos TZOTZIOY Georgiou wrote: > 2. wrap your file-like object in a custom object, which implements a > pushback method and its read method returns first from the push-back > buffer. If you read data that you shouldn't, push them back and give > your custom object to the StreamReader. Thanks for the suggestion. Instead of a pushback method, I added a peek method. Below is what I came up with. -- Jason class PeekableFile: def __init__(self, source): self.source = source self.buffer = None def peek(self, size): if self.buffer: n = len(self.buffer) if size > n: self.buffer += self.source.read(size - n) else: self.buffer = self.source.read(size) return self.buffer[:size] def read(self, size=-1): if self.buffer: if size >= 0: n = len(self.buffer) if size < n: s = self.buffer[:size] self.buffer = self.buffer[size:] elif size == n: s = self.buffer self.buffer = None else: s = self.buffer + self.source.read(size - n) self.buffer = None else: s = self.buffer + self.source.read() self.buffer = None else: s = self.source.read(size) return s def main(): import StringIO import unittest class PeekableFileTests(unittest.TestCase): def setUp(self): f = StringIO.StringIO('abc') self.pf = PeekableFile(f) def testPeek0(self): self.failUnlessEqual(self.pf.peek(0), '') def testPeek1(self): self.failUnlessEqual(self.pf.peek(1), 'a') def testPeek1Read1(self): self.failUnlessEqual(self.pf.peek(1), 'a') self.failUnlessEqual(self.pf.read(1), 'a') def testPeek1Read2(self): self.failUnlessEqual(self.pf.peek(1), 'a') self.failUnlessEqual(self.pf.read(2), 'ab') def testPeek1ReadAll(self): self.failUnlessEqual(self.pf.peek(1), 'a') self.failUnlessEqual(self.pf.read(), 'abc') def testPeek1Read1Read1(self): self.failUnlessEqual(self.pf.peek(1), 'a') self.failUnlessEqual(self.pf.read(1), 'a') self.failUnlessEqual(self.pf.read(1), 'b') def testPeek1Read1ReadAll(self): self.failUnlessEqual(self.pf.peek(1), 'a') self.failUnlessEqual(self.pf.read(1), 'a') self.failUnlessEqual(self.pf.read(), 'bc') def testPeek1Peek1(self): self.failUnlessEqual(self.pf.peek(1), 'a') self.failUnlessEqual(self.pf.peek(1), 'a') def testPeek1Peek2(self): self.failUnlessEqual(self.pf.peek(1), 'a') self.failUnlessEqual(self.pf.peek(2), 'ab') def testPeek2Peek1(self): self.failUnlessEqual(self.pf.peek(2), 'ab') self.failUnlessEqual(self.pf.peek(1), 'a') def testPeek2Read1Peek1(self): self.failUnlessEqual(self.pf.peek(2), 'ab') self.failUnlessEqual(self.pf.read(1), 'a') self.failUnlessEqual(self.pf.peek(1), 'b') def testRead0(self): self.failUnlessEqual(self.pf.read(0), '') def testRead1(self): self.failUnlessEqual(self.pf.read(1), 'a') def testReadAll(self): self.failUnlessEqual(self.pf.read(), 'abc') def testRead1Peek1(self): self.failUnlessEqual(self.pf.read(1), 'a') self.failUnlessEqual(self.pf.peek(1), 'b') def testReadAllPeek1(self): self.failUnlessEqual(self.pf.read(), 'abc') self.failUnlessEqual(self.pf.peek(1), '') unittest.TextTestRunner().run(unittest.makeSuite(PeekableFileTests)) if __name__ == '__main__': main() From no_replies at fake_email_address.invalid Sun Aug 1 17:42:14 2004 From: no_replies at fake_email_address.invalid (Robert Oschler) Date: Sun, 1 Aug 2004 17:42:14 -0400 Subject: Module for converting XML to Python object(s)? Message-ID: Has anybody seen a Python module that will take an XML document (not a colossal one), and convert it to a Python nested class object? I'm basically looking for something that would allow me to parse an XML document (not tokenize it like SAX or make it into an XPath accessible DOM object like others), directly into a nested Python object so I could access everything through Python class attribute references. Thanks. -- Robert From rschroev_nospam_ml at fastmail.fm Mon Aug 23 14:18:50 2004 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Mon, 23 Aug 2004 18:18:50 GMT Subject: age of Python programmers In-Reply-To: References: <20040819231139.D039A1E4003@bag.python.org> Message-ID: Sakesun Roykiattisak wrote: > BTW, The histrogram suggest that python is not being used as the first > programming language as much as it should be. Indeed. Also the relatively high number of older programmers (> 50) surprises me. Personnaly I know only one programmer in that age group, all others are less than 40 years old. Possibly the fraction of older programmers is larger under Python programmers compared to other languages? Maybe that shouldn't be surprising: wisdom comes with age, as they say. -- "Codito ergo sum" Roel Schroeven From deetsNOSPAM at web.de Wed Aug 25 15:46:55 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Wed, 25 Aug 2004 21:46:55 +0200 Subject: authentication service for unix Message-ID: Hi, this is not so much a python question, but as my app is developed in python, I'll ask anway. I'm looking for a method to authenticate users for a corba application server, running under linux. I want to be able to authenticate users that are valid unix users. Having role/group information would be nice later on. Currently I use PAM, but thats not so good as I have to run the process as root - but for obvious reasons I don't especially like that idea. Any ideas? May ladp of any use here? Saslauthd seems to look good, but so far I haven't found a binding. -- Regards, Diez B. Roggisch From jacek.generowicz at cern.ch Wed Aug 25 04:41:20 2004 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 25 Aug 2004 10:41:20 +0200 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> Message-ID: Peter Hansen writes: > The last time I checked, Java and C++ (even C) were widely > considered to be high level languages. The fact many people hold an erroneous belief, does not make said belief any less erroneous. > Has someone been raising the bar while I wasn't looking? The developers of all the truly high-level languages ? There was a time when assembler was high-level. From Michael.J.Fromberger at Clothing.Dartmouth.EDU Tue Aug 31 10:19:39 2004 From: Michael.J.Fromberger at Clothing.Dartmouth.EDU (Michael J. Fromberger) Date: Tue, 31 Aug 2004 10:19:39 -0400 Subject: Splitting a list References: Message-ID: In article , "Ian Sparks" wrote: > string.split() is very useful, but what if I want to split a list of integers > on some element value? > > e.g. : > > >> l = [1,2,3,-1,4,5,-1,8,9] > >> l.split(-1) > >> [[1,2,3],[4,5],[8,9]] > > Here's my hideous first pass : > > >> [[int(z) for z in x.split(',') if z] for x in ','.join([str(a) for a in > >> l]).split('-1')] > >> [[1, 2, 3], [4, 5], [8, 9]] > > When I see code like that I just know I've missed something obvious.... How about this? def split_list(L, brk): last = -1 out = [] for pos in [ x for (x, y) in enumerate(L) if y == brk ]: out.append(L[last + 1 : pos]) last = pos out.append(L[last + 1:]) return out -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From ville at spammers.com Sat Aug 7 09:43:58 2004 From: ville at spammers.com (Ville Vainio) Date: 07 Aug 2004 16:43:58 +0300 Subject: Paul Graham on Python hackers References: Message-ID: >>>>> "zoltan" == Zoltan Sekeres writes: zoltan> On Fri, 06 Aug 2004 22:23:59 -0700, ellisjb wrote: >> (In all seriousness I think python and java have a lot more in >> common than python and perl.) zoltan> This a flamebait, right? Otherwise I would be interested zoltan> in the features which make Python similar to Java zoltan> (shudder). Abundant reference semantics. Of course this is true of all OOP language, and Java doesn't go all the way with it either, but it's the most popular language that does it. It is also the first OOP language that does it that I tried, and I totally digged Java for a while before meeting Python and other languages that do it, and realized Java is still yet another static-typing-done-wrong low level language. -- Ville Vainio http://tinyurl.com/2prnb From robin at reportlab.com Thu Aug 19 05:26:36 2004 From: robin at reportlab.com (Robin Becker) Date: Thu, 19 Aug 2004 10:26:36 +0100 Subject: age of Python programmers In-Reply-To: References: Message-ID: <4124724C.8040001@chamonix.reportlab.co.uk> Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... > > so far with a count of 74 the average is 35.72 -- Robin Becker From olivier.parisy at free.fr Sun Aug 29 18:25:33 2004 From: olivier.parisy at free.fr (Olivier Parisy) Date: Mon, 30 Aug 2004 00:25:33 +0200 Subject: Enumerating Network Adapters In-Reply-To: References: <4131b09e$0$13683$636a15ce@news.free.fr> Message-ID: <413257dd$0$26986$626a14ce@news.free.fr> Diez B. Roggisch wrote: > This has been discussed quite a few times on this NG, search google groups. > However IMHO there is no general system built-in way (AFAIK not even posix) > for doing this, you'll end up parsing tool output anyway... I should have done this first, my mistake... But actually, a previously posted message suggests a portable way to get the platform IPs. Citing John Abel : > socket.gethostbyaddr( socket.gethostname() ) will return all the > details that you need to know. For example, the output of that > command on my machine is : > > ('hallows', [], ['101.101.101.102', '10.253.1.118']) Are there some pitfalls I'm not aware of ? Thanks, Olivier Parisy. From squirrel at WPI.EDU Wed Aug 4 14:45:50 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Wed, 4 Aug 2004 14:45:50 -0400 Subject: intermittent smtp module problems (with sendmail) in python 2.2.1 In-Reply-To: References: Message-ID: On 4 Aug 2004, Karl Ehr wrote: > I have written the following simple program to monitor a single URL, > and notify me via email whenever this URL changes. Intermittently, > I raise the following exception: > > smtplib.SMTPServerDisconnected: Connection unexpectedly closed This is probably happening because of a timeout on the SMTP server. Try moving this line: > server = smtplib.SMTP('localhost') # server to relay smtp through for To right in front of where you use it: > server.set_debuglevel(1) > server.sendmail(sourceAddress, emailAddress, message) > server.quit() the SMTP() constructor doesn't just set up a connection (and open it on .sendmail()); it opens the connection when it's called and leaves it open until you call .quit() (or delete the object). From kyle at lakeofburningfire.org Fri Aug 27 22:05:43 2004 From: kyle at lakeofburningfire.org (Kyle Yancey) Date: Sat, 28 Aug 2004 02:05:43 GMT Subject: Zope 2.7.2 win32 - Sessions not working Message-ID: I've scratched my chin over this for the longest time. I think I'm going to need some help. I'm creating a web app with zope. It has a typical user login based on email and password. A ZSql method is called to look up the customers unique id. That id is then assigned to their session cookie so I can allow to them to go to an account page where they can change their preferences. Unfortunately, zope sessions just don't seem to be working at all. I know something is being assigned, because Transient Object Container session_data says that it contains 8 items even though I only tried to set one. Any help would be appreciated. request = container.REQUEST response = request.RESPONSE session = request.SESSION html_page = """ """ if session.has_key('id'): return html_page if request.REQUEST_METHOD == 'POST': rec = context.Sql.get_user_id(email = email, password = password) if rec: cust_id = rec.dictionaries()[0]['cust_id'] session.set('id', cust_id) return html_page From geoff at variosoft.com Mon Aug 9 19:58:15 2004 From: geoff at variosoft.com (Geoff Caplan) Date: Tue, 10 Aug 2004 00:58:15 +0100 Subject: Compiling disutil modules on Windows In-Reply-To: <7947683945.20040807214448@variosoft.com> References: <7947683945.20040807214448@variosoft.com> Message-ID: <81144000832.20040810005815@variosoft.com> Hi folks, I now have mingw working, but some of the packages I want to try are only distributed in disutils format. I can't figure out a way to get these packages to use the mingw compiler. Is this possible, or do I really have to shell out $$ to microsoft to get these installed? ------------------ Geoff Caplan Vario Software Ltd (+44) 121-515 1154 From zathras at thwackety.com Wed Aug 25 16:11:36 2004 From: zathras at thwackety.com (Michael Sparks) Date: Wed, 25 Aug 2004 21:11:36 +0100 Subject: Call for signatories for J2 References: Message-ID: <412cf775$0$11496$ed2e19e4@ptn-nntp-reader04.plus.net> Robert Brewer wrote: ... > The patch is nearly complete; Patch against current CVS passes all the tests* and has been uploaded to SourceForge. I'm currently looking at how __future__ declarations work, and that will be the next step, but based on useful feedback this looks relatively simple to do. * Well, put another way, the only tests that fail are those that fail with an unmodified CVS tree. > This is a call for all who wish to sign the proposal, either for, > against, or abstaining. Please sign by either posting on > comp.lang.python (replying to this is fine), Please consider this a vote FOR - I doubt that'll surprise however ;-) Regards, Michael. From natunika at gmx.de Tue Aug 17 12:06:15 2004 From: natunika at gmx.de (Silke) Date: 17 Aug 2004 09:06:15 -0700 Subject: serial and threads References: <39ba6e78.0408170215.59f5bfc0@posting.google.com> Message-ID: <39ba6e78.0408170554.4b6b46bf@posting.google.com> Hi again, I already found a solution using 'threading' instead of 'thread' :-) Ciao, Silke natunika at gmx.de (Silke) wrote in message news:<39ba6e78.0408170215.59f5bfc0 at posting.google.com>... > Hi all! > > I'm trying to write a program in python using the modules > 'serialwin32' and 'thread' to create one thread that writes to a > serial port and another one that reads from it at 'the same time'. My > definitions are > > def NetworkToSerial(input): > s.write(binascii.unhexlify(input)) > print "SENT: %s" % input > > def SerialToNetwork(): > result = s.read(1) > print "RECEIVED:" > print binascii.hexlify(result) > > and I call them with > > thread.start_new_thread(NetworkToSerial, (command,)) > thread.start_new_thread(SerialToNetwork, ()) > > The first one seems to run fine, but for the second one I get the > error message 'ClearCommError', 'the handle is invalid'. > > Does anyone have a clue whether maybe serialwin32 is not > thread-compatible? > > Thanks for your help in advance! > > Silke From martin at v.loewis.de Sun Aug 8 03:46:53 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 08 Aug 2004 09:46:53 +0200 Subject: compiling with msvc7 In-Reply-To: <875af5e2.0408071735.4c1fdf89@posting.google.com> References: <875af5e2.0408071735.4c1fdf89@posting.google.com> Message-ID: <4115da69$0$161$9b622d9e@news.freenet.de> ?ke wrote: > I am trying to comile C code to python with weaver, using Microsoft > Visual Studio .NET (which I think uses VS 7.0) but I get an error > that Python is compiled with VS 6 and so doesn't work. > > Anyone knows a workaround for this ? Recompile Python, or buy VC6. Regards, Martin From kjetilho at yksi.ifi.uio.no Mon Aug 30 22:43:12 2004 From: kjetilho at yksi.ifi.uio.no (Kjetil Torgrim Homme) Date: Tue, 31 Aug 2004 04:43:12 +0200 Subject: allowing braces around suites References: Message-ID: <1rsma49ge7.fsf@rovereto.ifi.uio.no> [Michael Sparks]: > > The solution isn't to change the language in my eyes, the solution > is to produce better tools. After all, the following is legal > syntax in python if you really want close markers: > > end = None > for ch in "hello": > if ch == "l": > print "Rhubarb" > end > print ch, > end that's a really cool trick! perhaps a little prettier than the established "# end if", but like the comment it has no effect on Python's own code validation, so it's strictly not much of an improvement. but it inspired me to beget this evil hack: 1 from block_end import end 2 3 def test(): 4 if True: 5 print 'hello world' 6 end('if') 7 end('def') 8 9 test() when you run this code, you'll get the error message: block_end.IndentationError: Missing if on line 5, end on line 6 the module does _very_ rudimentary parsing of the source code and only flags errors during run-time. I'm not saying this is useful, but it was fun to write :-) since the module is just shy of hundred lines, I'm not including it here. please refer to this URL if you're interested in looking at the implementation. http://heim.ifi.uio.no/~kjetilho/hacks/block_end.py -- Kjetil T. From aranders at insightbb.com Sat Aug 7 01:40:22 2004 From: aranders at insightbb.com (Alan Anderson) Date: 6 Aug 2004 22:40:22 -0700 Subject: RELEASED Python 2.4, alpha 2 References: <411231C8.3020308@interlink.com.au> <2-SdnZCwNs1SwI_cRVn-uQ@powergate.ca> Message-ID: <53449fcb.0408062140.181fd30d@posting.google.com> Peter Hansen wrote: > Yes, of course after using them for a while they will become more > readable, but there are people who have learned to speak Klingon as > well -- and that doesn't change the fact that Klingon is deliberately > very difficult to learn and awkward. Pardon me for jumping in, but I happen to be attending a conference on the Klingon language at the moment and I wanted to correct a misunderstanding. Yes, Klingon is deliberately "alien", being intentionally created to be unlike many natural languages in many ways. But it's actually rather easy to learn, and it's only "awkward" in a couple of minor ways (embedding comparatives in larger sentences, for example) -- *every* language has its awkward spots. Were Klingon a natural language, its regularity would be exceptional. This is just an anectodal data point that might let you know that what is difficult and awkward from your point of view could very well be simple and straightforward for others who don't share your preconceptions. -- Alan Anderson, professional programmer and amateur Klingonist proud member of the Klingon Language Institute since 1995 qo'mey poSmoH Hol -- language opens worlds -- http://www.kli.org/ From ted at soleburymountain.com Tue Aug 24 18:50:21 2004 From: ted at soleburymountain.com (tdi) Date: 24 Aug 2004 15:50:21 -0700 Subject: How does a "script" differ from a "program" or "subroutine"? In-Reply-To: Message-ID: aha! That makes sense. That's what I was looking for. I hadn't expected this simple query to generate so many replies. Thanks to all for helping to clarify this point. -Ted From apardon at forel.vub.ac.be Fri Aug 27 05:42:08 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 27 Aug 2004 09:42:08 GMT Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> <1gj4fb5.607xsc51izh8N%aleaxit@yahoo.com> <7xllg25lkt.fsf@ruckus.brouhaha.com> <1gj4u3a.12ttba9fynd6uN%aleaxit@yahoo.com> <1gj5bp4.qhup8tldmvebN%aleaxit@yahoo.com> <7xk6vlgemp.fsf@ruckus.brouhaha.com> Message-ID: Op 2004-08-27, Paul Rubin schreef <>: > Antoon Pardon writes: >> but having operators like '+=' which have a different kind of result >> depending on whether you have a mutable or immutable object is IMO >> not such a good design and I wonder what design principle inspired them. > > += was added to Python fairly recently (in 2.0, I think) and there was > a lot of agonizing about whether to add it. It was one of those > things like the ?: construction. On the one hand there was the > abstract objection you raise. On the other hand there were lots of > users frustrated at being unable to say v[f(x)] += 1 instead of having > to call f twice or introduce a temp variable or something. > Eventually, practicality beat purity. Fine practicality beats purity, but then the proponents shouldn't put that much weight on consistency, because practicality breaks consistency. In this case I think the practicality of method chaining beats the purity of not allowing side-effects in print statements and of having only one obvious way to do things. I don't see that much difference in the frustration of having to write: t = f(x) v[t] = v[t] + 1 and the frustration of having to write lst = f(x) lst.sort() lst.reverse() -- Antoon Pardon From ptmcg at austin.rr._bogus_.com Sun Aug 22 11:01:27 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Sun, 22 Aug 2004 15:01:27 GMT Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? References: Message-ID: "Arthur" wrote in message news:ifchi0hqmhpag5umuukest5v4f2e73hjud at 4ax.com... > On Sun, 22 Aug 2004 08:07:53 -0500, Doug Holton > wrote: > > >Paul McGuire wrote: > >> Total voters: 55 > >> Of all of the votes cast, J2 > >> received 48%, C1 received 18%. No other option received more than 10% of > >> any votes. > > > >I vote 3 times for C1. So just my one vote raises C1 to 20%. I think > >you need to do an online poll so you get more people than just those who > >have been discussing the decorator keyword here this past week. I got > >over 250 votes for C1 just last week vs. the 22 who voted for J2 here. > >During this 2nd poll people were confused about whether they could vote > >for A1 or not, and some people said many of the options on the wiki page > >were not allowed anymore. > > > > I think it should also be noted in the report of the voting results > that the a vote for "no new syntax at this time" was specifically > outlawed. > > As a side point: > > It seems ironic to me that in a group devoted to an appreciation of > Python, and its advocacy - it is often those who reject the notion > that the language has the kinds of glaring weaknesses that require > some fundamental change ot it, that form the opposition to an > "establishment" that has become convinced quite otherwise. > > I sometimes wish those folks were more candid about its deficiencies > before I started my study of it back in 1.5.2 days. > > Art From noone at here.com Sun Aug 22 12:18:51 2004 From: noone at here.com (M. Clift) Date: Sun, 22 Aug 2004 17:18:51 +0100 Subject: Making different things equal References: Message-ID: Hi Wes, Thanks for looking at this! I appreciate your effort. The system works very well, but I want it to see Bob as being the same thing as Mary. So for example it won't give [Bob, whoever, Mary] as that would be the same as [Mary, whoever, Mary] or [Bob, whoever, Bob]. M From PPNTWIMBXFFC at spammotel.com Fri Aug 27 03:00:26 2004 From: PPNTWIMBXFFC at spammotel.com (Marco Aschwanden) Date: Fri, 27 Aug 2004 09:00:26 +0200 Subject: How to generically transform a list? References: Message-ID: Thanks to all the hints which seem to prove that there is one and only one sensible approach - though some (like me) needed a few more lines. It is just funny how easy horizontal slicing is made (list[:]) but how "difficult" vertical slicing is. It is a common task and one does not realize how often one does need vertical slicing. eg.: getting the keys of dictionary is a vertical slicing, or turning a list into a dict involves vertical slicing... Just out of pure curiosity: Is there a langue that allows vertical and horizontal slicing and dicing with the same built-in pattern? Regards, Marco (Eagerly awaiting the cookbook's second edition) From ajsiegel at optonline.net Wed Aug 11 11:25:59 2004 From: ajsiegel at optonline.net (ajsiegel at optonline.net) Date: Wed, 11 Aug 2004 11:25:59 -0400 Subject: @decorator syntax is sugar, but for what exactly? (decorator libraries). Message-ID: <1b42a711b44f53.1b44f531b42a71@optonline.net> > >> Yes (using a class instead of a module simply for convenience): > ... > > Art> Is it me, or this a chilling argument agaisnt where > things are > Art> going. > > I'm not sure what you're getting at. Nobody said a decorator's > implementation had to be simple. It can, after all, perform pretty > arbitrary transformations. I guess, as a reading experience, I find enough dissonance to lose motivation to make the effort to follow the flow. Purely subjective. I offer this as a barometric reading from the point of view of a certain segment of the Python reading public. Understanding that part of what I am up against is unavoidable complexity in he code, and following would not be child's play to me, in any case. Something though puts it beyond my cognative -what, interest. > > Art> But when there is a lot less going on than meets the eye ... > > Again, I'm confused. Look at just the fib() definition: > > @martha.memoize > def fib(n): > assert n >= 0 > print n > if n <= 1: > return 1 > return n + fib(n-1) > > The decorator says the function will be memoized. That memoizing an > arbitrary function's values using a dict isn't entirely > straightforwardshouldn't prevent people from being able to easily > memoize functions whose > outputs only depend on their inputs. By analogy, I use > urllib.urlopen() all > the time without completely understanding all the ins and outs of > what it > does. > > Perhaps the decorator would be better named "idempotent"? > > Or were you objecting to something else? Well, I one hand I understand decorators to be syntatical sugar for existing Python functionality, and on the other I hear talk of the building of decorator libraries based on the introduction of decorators, as if we were talking about a new classs of functionality. Certainly the introduction of decorators seems to be encouraging a new style of programming. That style might be have advantages. And it might in fact be good for someone exactly like myself, to be exposed to more of it. But it does seem to me readibility will be a casualty. And I fear decorator libraries working to make Python ingrown. Art From peter at engcorp.com Mon Aug 16 01:25:27 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 01:25:27 -0400 Subject: Stopping a socket.accept() method In-Reply-To: <2o9mlbF8ff8rU1@uni-berlin.de> References: <2o9mlbF8ff8rU1@uni-berlin.de> Message-ID: Tobias Pfeiffer wrote: > I am writing a network game where the server runs in a console window. > The person who has opened the server shall be able to stop the process of > accepting new clients. By now, I am handling that like this: > > while 1: > try: > bla = socket.accept() > except KeyboardInterrupt: > break > socket.shutdown(2) > > So the user can Ctrl+C and no more clients will be accepted. > Unfortunately, this doesn't work in Windows. So how can I give the user > the ability to quit the loop interactively? Any ideas? Several options. 1. Ctrl-Break will work if it's a console program and Ctrl-C doesn't. 2. You can use a non-blocking socket and select(), which will allow a periodic wakeup to check a flag that is set by whatever mechanism you want to tell the prog to stop. 3. Have another thread, which can detect the request to stop, open a connection to the server thread's socket so that it will wake up... then it can check a flag and terminate as in 2. -Peter From gerson.kurz at t-online.de Thu Aug 19 15:50:26 2004 From: gerson.kurz at t-online.de (Gerson Kurz) Date: Thu, 19 Aug 2004 19:50:26 GMT Subject: ANN: pyxe Message-ID: <41250363.6193453@news.t-online.de> pyxe is a small executable that will run python scripts on a machine that doesn't have Python installed. Example: You have the following hello.py: def main(): print "Hello, World" You can create a binary distribution using pyxe /build hello This will create a directory ./hello which contains all you need. Copy all files to a host system and run the app using pyxe hello That's it. Note that your app must define a def main(): which is the main procedure to start from pyxe. There is one known restriction, sys.argv[] doesn't get properly setup in pyxe environment. You can fix this yourself: import sys try: import cfrompy sys.argv = cfrompy.GetSysArgv() except ImportError: assert sys.argv Easy, eh? Requirements - On the developer machine, you must have python23 installed. - On the target machine, no requirements. - Tested on Windows NT and Windows 2000. You are on your own with other systems (such as XP, 03 etc.) pyxe is free for any purpose whatsoever. Download: http://p-nand-q.com/python/pyxe.zip includes the full sourcecode and a sample app in Python which actually is the "SimpleHTTPServer" webserver ;) Enjoy Homepage = this mail in fancy tags: http://p-nand-q.com/python/pyxe.html From mwh at python.net Fri Aug 6 07:09:40 2004 From: mwh at python.net (Michael Hudson) Date: Fri, 6 Aug 2004 11:09:40 GMT Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) References: <1646998998.20040804190026@MailBlocks.com> <10h34ivio5s2c21@news.supernews.com> <10h4c5iicgv7k74@news.supernews.com> Message-ID: This reply was a touch more hostile that I was expecting; if I've hit some nerve, sorry, if not, err, can you relax a bit? "John Roth" writes: > "Michael Hudson" wrote in message > news:m3pt65g4hb.fsf at pc150.maths.bris.ac.uk... > > > Well, that would be because that's impossible :-) > > I wish you'd have told me that before I did it. As I said in > a prior post, I had to put a general metadata facility into > PyFIT, and it's working quite nicely, thank you. OK, poor choice of words. [snippity] > > What kind of metadata do you want? > > Type and other declaration information for any identifiers > that will be referenced in the FIT tests. Other information > includes things like precision for floating point numbers, > strings that are accepted as "true" or "false" for booleans, > the subtype for lists and tuples, references to custom > type adapters and other stuff. So, you would like to write class Thiny(object): @attribute(type=float, precision=3) a = 1.23 ? I really don't see how you could make that work. attribute() could return something that was called with the dictionary being inserted into, the string 'a' and the value 1.23, but... ick. I don't think I like that idea. What would you find helpful? Cheers, mwh -- ... but I'd rather not reinvent the wheel if I don't have to. On the other hand, if the currently instantiated version of the wheel consists of a square rock covered with moss, I might as well just start fresh. -- Roy Smith, comp.lang.python From mwilson at the-wire.com Fri Aug 20 07:32:18 2004 From: mwilson at the-wire.com (Mel Wilson) Date: Fri, 20 Aug 2004 07:32:18 -0400 Subject: esoteric question about dict keys References: Message-ID: In article , Alexis Roda wrote: >Now the question. In "normal" dicts its not possible to use dictionaries >(nor other kinds of mutable objects) as keys, if I undersand correctly >this is a technical requirement. If I write my own dictionary-like >object, on wich the mutability of the keys is not a technical issue, is >considered blasphemous the use of dicts as keys? For example, querying >an SQL table can be partially modelled as a dictionary access: As I understand it, you can use any object as a key if you give it a __hash__ method and an __eq__ or __cmp__ method. The problem with a mutable object as a dictionary key is that it could change in value after it had been registered as a key, and then you would no longer find the associated data "where you left it". You'd have to somehow present another key with a hash the same as the original hash, and which compared equal to the key value after mutation. Regards. Mel. From tdelaney at avaya.com Thu Aug 26 19:51:44 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Fri, 27 Aug 2004 09:51:44 +1000 Subject: Proposal for removing self Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01DCFB9C@au3010avexu1.global.avaya.com> Andrea Griffini wrote: > I remember Alex Martelli advocating in our italian newsgroup on > C++ that C++ programmers should use "this->..." everywhere :-) I evangelise this here (mainly for Java code these days, but close enough). Unfortunately, I don't seem to be able to convince anyone else :( Tim Delaney From news at outbacklinux.com Tue Aug 24 06:13:22 2004 From: news at outbacklinux.com (Adrian Casey) Date: Tue, 24 Aug 2004 19:43:22 +0930 Subject: using pexpect to control python References: <412b0b21$1@news.unimelb.edu.au> Message-ID: <412b14c2@duster.adelaide.on.net> Maurice LING wrote: > I know this might sounds wierd but I'm wondering if I can use pexpect or > os.popen3 function to invoke and control python interpreter to make it > act like a python interpreter in python? > > maurice Yes, should be possible. I have used tcl expect to call other expect scripts successfully in the past. You can use pexpect to control any command-line tool. What are you trying to achieve? From indrek.kruusa at tuleriit.ee Fri Aug 6 18:42:56 2004 From: indrek.kruusa at tuleriit.ee (Indrek Kruusa) Date: Sat, 07 Aug 2004 01:42:56 +0300 Subject: Importance of C# (was Re: IronPython-0.6 is now available!) In-Reply-To: <9418be08.0407292114.129c856f@posting.google.com> References: <278de0e.0407281353.27b6a457@posting.google.com> <5dydnZSDZaARoZXcRVn-ug@powergate.ca> <9418be08.0407292114.129c856f@posting.google.com> Message-ID: <41140970.1050208@tuleriit.ee> Elbert Lev wrote: >C# IS a good language and .NET is a very good environment. Recently I >had to write a little program. "one of a kind", "throw away". It took >2.5 hours to finish the proto. Worked fine, but would requere night to >run. Had to rewrite in... C++ or C#. Having the proto in Python, C# >program was written almost as fast as Python's one. The run finishhed >in 1 hour. > > A little comparison of C#, perl and python here (Speed test in menu): http://www.tuleriit.ee/progs/ rgds, Indrek From alanmk at hotmail.com Thu Aug 12 09:00:40 2004 From: alanmk at hotmail.com (Alan Kennedy) Date: Thu, 12 Aug 2004 14:00:40 +0100 Subject: jython and java exceptions In-Reply-To: References: <4_nSc.24773$Z14.7584@news.indigo.ie> Message-ID: [Jan Gregor] > All tests passed ok, but problem is still there. I didn't mentioned that > mysql works fine. > > My system is debian, something between woody and testing version. At > home I have similiar debian upgraded moved so far from potato to woody > to sarge - same behaviour. > > Application runs from command line by 'jython TextConsole.py'. Jython is > version 2.1, running on java 1.4.2_05 (at home 1.4.1). PostgreSQL > (7.4.3) and jdbc driver (as jython) from debian testing distribution. I have one more thing to suggest, and that only applies if you are "embedding", i.e. calling jython created classes from java, as opposed to calling java classes from jython. If you are embedding, then you are initializing the jython runtime yourself, as opposed to having jython do that for you. In these cases, names of java packages are not always picked up from the jython package cache (although the class definitions are picked up if the jar is present on the classpath). Try adding a line like this to the top of your jython module import sys ; sys.add_package('com.sybase.jdbc2.jdbc') This can also be done outside jython, in the java embedding environment, through a PySystemState object, as described here http://sourceforge.net/mailarchive/forum.php?thread_id=3747282&forum_id=5586 If that doesn't help, I'm afraid I'll be too busy for the next few days to help out, though there are other people here who might be able to contribute. The day I've been waiting for for 7 years has finally arrived: proof that the US retail milk supply is contaminated with a bacterium known as Mycobacterium avium subspecies paratuberculosis. I expect to be very busy with this, especially if the US media reacts to the story the same way that the British and Irish media did. If you see an article on paratuberculosis and Crohn's Disease in the media in the next few days, you'll be happy to know that python is an essential part of the management of two of the main related web sites: www.crohns.org and www.paratuberculosis.org More info on paratuberculosis in US retail food from http://www.johnes.org/newsfiles/109216471862392.html my-world-is-tumbling-ly y'rs -- alan kennedy ------------------------------------------------------ email alan: http://xhaus.com/contact/alan From max at alcyone.com Thu Aug 12 18:49:32 2004 From: max at alcyone.com (Erik Max Francis) Date: Thu, 12 Aug 2004 15:49:32 -0700 Subject: decorator syntax polling suggestion References: Message-ID: <411BF3FC.71051A6F@alcyone.com> Steven Bethard wrote: > The poll, as stated, asked voters to vote for the syntax suggestion > they liked the /most/. Some of the conclusions people are trying to > draw from it are what syntaxes people liked the /least/. This is > probably not the right conclusion to be drawing from the poll that was > given. That's certainly true (after all, the one with the fewest votes could actually be everyone's _second_ favorite choice!), but I don't think it's the most serious problem with the accuracy of the poll. The problem is that since it's an unofficial poll, and it's not clear that Guido will give much credence to it at all, there is really no incentive for people who are happy, or at least satisfied, with the current decorator syntax to vote in order to express their approval. Now, that's probably true in an official vote as well, but it's probably much more strongly the case here, where there's not even any good indication that the poll will be paid attention to, and it hasn't been commissioned by any entity actually in charge of making the final decision. So only people who are dissastisfied with the proposal are likely to vote, and indeed that seems to be the case. Furthermore, perhaps the only case where the results of the poll might raise eyebrows would be if there were a landslide, so to speak, but a landslide is going to be far more indicative of the poll being horribly biased, rather than it showing any real intentions of the community (and I'd certainly claim that based on the initial reactions of people to the decorator syntax -- lots of people expressed their support; they've just been drowned out by proposal after proposal after proposal). -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ My long is strong enough, you know / Strong enough to let you go -- Xscape From twanger at bluetwanger.de Tue Aug 10 09:01:18 2004 From: twanger at bluetwanger.de (Markus Bertheau) Date: Tue, 10 Aug 2004 15:01:18 +0200 Subject: Multiple inheritance with a common base class In-Reply-To: References: <1092137872.2624.16.camel@dicaprio.akademie1.de> Message-ID: <1092142873.2624.43.camel@dicaprio.akademie1.de> ? ???, 10.08.2004, ? 14:38, Duncan Booth ?????: > Well of course it outputs 0 twice. That's because after LeafA initialised > CommonBase, and set its value to 3 you then reinitialised it from LeafB and > set the value back to 0. Thanks for the explanation, Heiko too. > Using super will ensure that you get a reliable chain of method calls. In > this case it means that Multi.__init__ calls LeafA.__init__ which calls > LeafB.__init__ which then calls CommonBase.__init__. Note that LeafA > propogates the call to LeafB even though LeafA has no knowledge of the > existence of LeafB. That is what I needed to know. Thanks. It should probably be noted in the paragraph about multiple inheritance. (CommonBase has to be a new style class for python <= 2.3) Thanks -- Markus Bertheau From enjoylife_95135 at hotmail.com Sat Aug 14 22:45:50 2004 From: enjoylife_95135 at hotmail.com (enjoylife_95135) Date: 14 Aug 2004 19:45:50 -0700 Subject: compiling python 2.3.4 with command line editing Message-ID: <864c2cd6.0408141845.3f50a3d5@posting.google.com> Hi, I'm running RH9 on my laptop. It comes with the Python 2.2.2 RPM. Its cool because when I run the interpreter, I can use command line history. I need to upgrade, so I downloaded and compiled Python 2.3.4. Very cool, spiffy etc, but the interpreter doesn't allow for command line editing, i.e. I can't type and go to the previous command. How do I enable that? Thanks! S From mcfletch at rogers.com Fri Aug 6 11:33:05 2004 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Fri, 06 Aug 2004 11:33:05 -0400 Subject: Queue qsize = unreliable? In-Reply-To: <1091805850.15192.12.camel@localhost> References: <1091805850.15192.12.camel@localhost> Message-ID: <4113A4B1.6040900@rogers.com> James R. Saker Jr. wrote: >I see per pydoc that Queue.Queue()'s .qsize is allegedly unreliable: > > | qsize(self) > | Return the approximate size of the queue (not reliable!). > >Any thoughts on why this is unreliable (and more curiously, why it would >be put in there as an unreliable function?) Rather than roll my own >threaded fifo class, it would seem prudent to use Python's built-in >Queue but the warning signs on a rather necessary function seem curious. > > I would imagine that there is the potential for an item to be added or consumed during the running of the qsize method, or between the completion of the running of the qsize method and the op-codes which deal with the result. That is, what you're getting is the size of the queue from a few milliseconds ago, which may have *no* relationship to the current size. It is "unreliable" in the sense that you shouldn't do something like "if q.qsize(): q.pop()" if you will fail when q.pop() blocks with an empty queue. It's useful in cases where you're trying to see how large a large queue is, but it's not something you want to be mucking about with to try to create new low-level thread-safe primitives. Tim, of course, would know better, but that's always been my interpretation. Have fun, Mike ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From tim.hochberg at ieee.org Thu Aug 26 12:54:51 2004 From: tim.hochberg at ieee.org (Tim Hochberg) Date: Thu, 26 Aug 2004 09:54:51 -0700 Subject: Call for signatories for J2 In-Reply-To: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> Message-ID: Alex Martelli wrote: > Robert Brewer wrote: > > >>This is a call for all who wish to sign the proposal, either for, >>against, or abstaining. Please sign by either posting on >>comp.lang.python (replying to this is fine), or sending email to For. I also have a weak preference for 'per' over 'using', FWIW. The shortness of 'per' is one virtue. Another is that, because it's slightly obscure, it may be easier to indoctrinate users that 'per...def' is the correct order, not 'def...per'. For me at least it's 'obvious' that if 'using...def' works then so should 'def...using', which of course it can't. The order is amenable to memorization, but I still anticipate more thinkos of this type from using than from per. On the downside, per may be extremely obscure to those that are neither native speakers of English or one of the romance languages. -tim > For. > > I wish we'd use a better keyword than 'using' which would have a > bazillion other possible and useful future interpretations. Of the > possible keywords mentioned on the site, several (by, per, through, via) > appear better to me, and I'd particularly love the three-letter ones as > they'd align well with 'def' -- my own preference would be 'per'. > > However, I suspect it's too late to submit J2 with anything but 'using' > and I'd rather have J2 with 'using' than the pie-before-def thingy, so, > here's my "tactical" FOR vote:-). > > > Alex From koko9991 at compuserve.de Sun Aug 22 05:00:27 2004 From: koko9991 at compuserve.de (Konrad Koller) Date: Sun, 22 Aug 2004 09:00:27 GMT Subject: SciTE as editor for Python: No print formatting under LINUX. References: <4124ad63.349803125@news.compuserve.de> Message-ID: <41285ca5.591276625@news.compuserve.de> How is print formatting determined under LINUX (PLAT_GTK)? Neil wrote: > On Windows, the same API is used for drawing to the screen and printer so >SciTE performs printing itself. GTK+ doesn't provide a printing API so SciTE >calls an external application, with the default being a2ps set by >command.print.*=a2ps "$(FileNameExt)" > Thank you very much for your valuable hint. I could try to add appropriate options to a2ps, but to fulfill my formatting demands I prefer to write a short Python program for printing (only for Linux). Nevertheless SciTE remains my favorite tool for developments with Python. Cheers Konrad > From eppstein at ics.uci.edu Thu Aug 12 13:35:02 2004 From: eppstein at ics.uci.edu (David Eppstein) Date: Thu, 12 Aug 2004 10:35:02 -0700 Subject: PEP318 References: <20040812090056.00001e31@titan> <7ttmh0t8c3cogtbhhnp1ohqu8b51pda461@4ax.com> Message-ID: In article <7ttmh0t8c3cogtbhhnp1ohqu8b51pda461 at 4ax.com>, Arthur wrote: > foo=staticmathed(foo). > > That is the universal langauge for transformations. And when we try > to explain to anybody what it is that @decorator means, we go back to > the pseudo code that is in fact the existing syntax. > > I guess I am mystified what it is that is perceived to have been > gained ... by moving magic outside the function block to the top of a > function in lieu of expressive code outside the function block at the > bottom of the function. Not having to write the function name three times? If it's just foo, that would be one thing, but have you seen the PyObjC examples? Also, it's not in the Zen of Python, but maybe declarative is better than imperative? -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ From nzanella at cs.mun.ca Wed Aug 18 18:13:42 2004 From: nzanella at cs.mun.ca (Neil Zanella) Date: 18 Aug 2004 15:13:42 -0700 Subject: _Re: singleton (newbie) Message-ID: Hello, Is this the correct way to code multi-instance singleton in Python? It seems to do the trick for me but I appreciate any criticism as I am somewhat new to Python. Thanks, Neil #!/usr/bin/python class B: x = 0 y = 1 def foo(): print B.x foo = staticmethod(foo) def bar(): print B.y; B.y += 1 bar = staticmethod(bar) if __name__ == "__main__": B.foo() B.bar() B.foo() B.bar() B.bar() From peter at engcorp.com Tue Aug 24 00:54:50 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 24 Aug 2004 00:54:50 -0400 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 23) In-Reply-To: References: Message-ID: Anthony Baxter wrote: > (Hell, this entire discussion is now > pretty much based on subjective or aesthetic judgements). Excellent! If that's true, it really has reached the stage where it's ready for the BDFL's pronouncement. Having the slaves do all the hard work and having the BDFL only have to weigh the subjective and aesthetic issues is probably exactly how the process should work, and should still result in a Python that is a consistent and coherent whole. ** -Peter ** Words like "slaves" and any phrasing above that might seem offensive should be interpreted entirely in a light- hearted manner for purposes of this posting. :-) From squirrel at WPI.EDU Wed Aug 4 14:54:53 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Wed, 4 Aug 2004 14:54:53 -0400 Subject: Mucking with the calling scripts namespace (For a good reason, honest!) In-Reply-To: References: Message-ID: On 4 Aug 2004, Doug Rosser wrote: > To add the references I'm looking for, I'm going to do something like: > > for server in myTest.servers: > exec server.iniLabel +"="+ server in globaldict > > The code hasn't been debugged...caveat emptor... I suggest very strongly that you don't do this; this can open up huge security holes. Say 'server.iniLabel' is equal to 'import os; os.system('rm -rf /'); foo': Danger Can Happen! Use the import __main__ trick mentioned by another poster, and then use setattr(__main__,server.iniLabel,server) to inject the values into the __main__ namespace. But beware! This could cause bugs, too (if server.iniLabel is the same as the name of a builtin or one of your functions). A dictionary (as you are considering) is the safest way to go. From olivier.parisy at free.fr Mon Aug 9 09:26:05 2004 From: olivier.parisy at free.fr (Olivier Parisy) Date: Mon, 09 Aug 2004 15:26:05 +0200 Subject: Exceptions as a Control Structure In-Reply-To: References: <411775aa$0$17867$626a14ce@news.free.fr> Message-ID: <41177b65$0$17857$626a14ce@news.free.fr> Peter Hansen wrote: > In Python, very little is frowned upon solely for efficiency > reasons. There are some examples, including using += > repeatedly to grow a string, and some fields where efficiency > is of course critical, but in Python one almost always looks > for the most pragmatic approach (which is often the most > elegant, too, for some people's definition of elegant) > rather than obsessing about speed. I understand this. That's one of the reasons I am learning Python (I am more interested in improving my development time than my programs' execution time). >> Are exceptions >> considered as reasonable control structures, or is >> StopIteration alone of its kind ? > > > Catching an exception is considered a reasonable approach > to flow control for various problems. One, for example, > is in deeply nested loops, where rather than going out of > one's way to avoid exceptions in favour of a flag and lots > of awkward testing, one just raises a custom exception > (or perhaps a standard one) and catches it outside the > loops. OK. Definitely not something I'd do in C++. > Exceptions are also used by some as a mechanism for > returning information from subroutines, though it's > very likely the information will still be considered > "exceptional" in some way (think of it as an out-of-band > mechanism for returning special info). Do you have some example of this in the standard library ? > While some people object on stylistic grounds (or even > performance ones, in some cases) to such things, you > will likely find that exceptions are thrown around > by Python programmers more readily than you are used to. That's what I wanted to know. OK. > Note also that in many cases other than algorithmic > complexity, what you have learned about efficiency in > C++ should be considered suspect info when it comes > to Python. Function calls, for example, are much more > expensive in Python than in C++ because of the time > required to set up the call frame. Exceptions, on the > other hand, are as I recall much more efficient. So I suppose I just won't concern myself with efficiency questions and concentrate on prope style, then. > Some Google Group searches in c.l.p would probably > lead to many past discussions of these things. I must admit I probably didn't do my homework... BTW, thanks for your reactivity ! Regards, Olivier. From martindemello at yahoo.com Wed Aug 25 08:37:46 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Wed, 25 Aug 2004 12:37:46 GMT Subject: Why return None? References: Message-ID: Dan Sommers wrote: > If list.sort returned the sorted list, how many lists would there be > after this code executed? > > original_list = a_function_that_returns_a_list( ) > sorted_list = original_list.sort( ) One - sorted_list would be a reference to the (now sorted) original list. The newbie problem could be solved by having and versions of each destructive method - i.e. list.sort() to sort the list in-place and return it, and list.sorted() to return a new, sorted list, and experienced users could chain methods and all that other good stuff. martin From albalmer at att.net Mon Aug 30 13:15:42 2004 From: albalmer at att.net (Alan Balmer) Date: Mon, 30 Aug 2004 10:15:42 -0700 Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4dyXc.25792$Ot3.22106@twister.nyc.rr.com> <878yc0ucyl.fsf@thalassa.informatimago.com> <87hdqorqd9.fsf@thalassa.informatimago.com> Message-ID: On 28 Aug 2004 03:41:22 +0200, Pascal Bourguignon wrote: >> I don't follow you at all. I think you'll find the most useful, >> meaningful complaints about, say, a Ford Explorer from the people who drive >> one every day. > >I'd expect to get these complaints indeed from people who drove it, >but I'd be puzzled if they'd continued to drive it every day. Not me. I'd just assume that they couldn't afford to switch vehicles whenever they had a complaint. -- Al Balmer Balmer Consulting removebalmerconsultingthis at att.net From a at b.com Wed Aug 18 03:10:59 2004 From: a at b.com (wonder) Date: Wed, 18 Aug 2004 15:10:59 +0800 Subject: Retrieve current webpage url. Message-ID: Dan Greenblatt wrote: > wonder wrote: > >> Hi, >> >> How can I pass the url of the current webpage link to a python script in html? >> >> thanks >> sam > > > are you using a python script as a helper application? yeah, sort of. I m building a html page that will call a python script by passing it the current URL of the webpage. The html page will be opened by any web user with any web browser. thanks sam From peter at engcorp.com Wed Aug 4 08:01:05 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 04 Aug 2004 08:01:05 -0400 Subject: converting to string In-Reply-To: References: <41108A2E.7030507@mail.usyd.edu.au> Message-ID: Gandalf wrote: > Ajay Brar wrote: >> how do i go about converting a Python object or tuple to a string. > > For special cases you can find a more efficient solution.For example, > for tuples of integers, > you can write a C extension that allocates a big string and copies every > int object into 4 bytes > in the string. That would be more efficient. A C extension? You mean like this? : >>> s = (1, 55, 109, 2000, 65535) >>> import struct >>> struct.pack('%si' % len(s), *s) '\x01\x00\x00\x007\x00\x00\x00m\x00\x00\x00\xd0\x07\x00\x00\xff\xff\x00\x00' -Peter From cookedm+news at physics.mcmaster.ca Mon Aug 23 17:53:34 2004 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Mon, 23 Aug 2004 17:53:34 -0400 Subject: 100 % portable ? References: Message-ID: At some point, Vent d'Est - East Wind wrote: >> http://dotamatic.sf.net >> http://bitpim.org >> Both are open source so you can see for yourself. Both use the >> clipboard, do printing, have online help, are distributed so >> that the user doesn't need Python on their machine already etc. >> Roger > > i see your website , but i see for mac os x you using cocoa interfacing > i don't understand isnt WXpython from WXwindow and have in all system > same apparence ? > > same for linux i see a like kde 2 interfacing using > > seems each you use each interface of each system > (and not just one for every system) > > is that only using wxpython or add some other graphic toolkit port and > using cocoa , kde interface ? I think you've missed the point of wxWidgets/wxPython: it uses native widgets on each platform. On OS X, it uses Aqua widgets; on Linux, QT or GTK, on Windows, native Windows widgets. So, you're not going to get the same appearence on different platforms (which is a good thing; I don't want to use something that looks like Windows on a Mac). -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From peufeu at free.fr Mon Aug 2 12:04:50 2004 From: peufeu at free.fr (=?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?=) Date: Mon, 02 Aug 2004 18:04:50 +0200 Subject: Strange timing data for list.pop() References: Message-ID: > Of course it was a bad experimental setup. I didn't measure what I set > out to measure. But, I did measure something interesting, and I'm > trying to figure out what it was. That's how some great scientific discoveries were made ;) From Symantec_AntiVirus_for_SMTP_Gateways at nlmof.navy.mil Wed Aug 11 04:37:29 2004 From: Symantec_AntiVirus_for_SMTP_Gateways at nlmof.navy.mil (Symantec_AntiVirus_for_SMTP_Gateways at nlmof.navy.mil) Date: Wed, 11 Aug 2004 08:37:29 GMT Subject: Content violation Message-ID: <20040811083736.6C9D01E4002@bag.python.org> Content violation found in email message. From: python-list at python.org To: dougherty at nlmof.navy.mil File(s): message.scr Matching filename: *.scr From artur_spruce at yahoo.com Sat Aug 7 05:58:07 2004 From: artur_spruce at yahoo.com (AdSR) Date: 7 Aug 2004 02:58:07 -0700 Subject: How do you feel ? References: Message-ID: Sylvain Hellegouarch wrote: > Hi, > > A bit off topic. Not at all, in my view. > I just wondered what was your feeling when you were coding with Python. > I have beebn coding with different languages and the only that has given > me the will to invent or to be creative has been Python. Python allows > me not to focus on the complexity of the language itself. It's a lot of fun, rewarding, often giving instant gratification. I can do some pretty complex stuff (at least from my point of view) in short time, do it right and complete. I did some programming for fun in C++ and Java, but only very simple tasks, worse and not really better. It's useful. I can do helper tools that I could live without but that make my (professional or private) life easier. It's interesting. I can learn new (to me) programming concepts, like function currying. I tried to learn Perl, and after one useful script done in five days, never got back to it. I tried Common Lisp, but online tutorials are very basic, and online reference is hard to navigate; I still don't know what "#" and "," mean. I tried Smalltalk and loved it - it's approach to OO complements Python's in a very cool way - but I'd need something better integrated with the system than Squeak is. I repeat, above all, it's a lot of fun. > Of course, from time to time, I find something that is not clear to me > but indeed after a couple of research you find the information you were > looking for. Yeah, sometimes you have to dig for it, like I had for the way to do multiple keystroke bindings in Tkinter for the DiacriticalEditor (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286155; shameless self-advertisement), but chances are you'll find it or someone on c.l.py will tell you. > I love that language and above all, I love using it. Same here. > Sorry for this little spam but it is always good to acknowledge good > things and not only complaining when it doesn't work. Like I said, it's no spam at all. > Thanks the Python team. Same from me, AdSR From mwilson at the-wire.com Sat Aug 7 18:40:48 2004 From: mwilson at the-wire.com (Mel Wilson) Date: Sat, 07 Aug 2004 18:40:48 -0400 Subject: an Image References: <18282ecb.0407282040.231e5766@posting.google.com> Message-ID: In article <18282ecb.0407282040.231e5766 at posting.google.com>, mefjr75 at hotmail.com (M.E.Farmer) wrote: >justin__devine at hotmail.com (JDevine) wrote in message news:... >> I am going through the painfull process of learning wxPython. Sincer >> there is nearly no documentation, I am learning from the demos. >> Unfortunately, I have realized these demos do some specialized >> importing and that all the imports are not applicable. Specifially, >> All I want to do now is insert a bmp I have drawn into a windows >> application. The image clases from the demos are completely >> unexplanatory about how to do this. The "images" module that is >> imported has custom functions for calling a specific set of images >> such as GetTest2Bitmap, which does not help me at all. Please help me >> understand this. >Maybe this will help you. > ># SimpleImage ver 1.0 ># by M.E.Farmer Jr. 2003 ># Utilizes the new wx namespace ># usage: python SimpleImage.py image.jpg >[ ... ] > pix = wx.Image(sys.argv[1], wx.BITMAP_TYPE_ANY).ConvertToBitmap() >[ ... ] > st = wx.StaticBitmap(frame, -1, pix, pos=(1,1), > size=wx.Size(pix.GetWidth(),pix.GetHeight())) You can also with a little more difficulty write straight to the window.. Below is a fragment from __init__ of a wx.Frame descendant. (It's straight from working code but I haven't tested it independently.) w, h = self.GetClientSizeTuple() bmp = wx.EmptyBitmap (w, h) mdc = wx.MemoryDC() if bmp.LoadFile ("sweeper.bmp", wx.BITMAP_TYPE_BMP): mdc.SelectObject (bmp) wx.ClientDC (self).Blit (0,0, w,h, mdc, 0,0) The complication with such techniques is that you need to coordinate a lot of different objects.. Frame, Bitmap, DC.. and look up the separate documentation on those guys.. to get any work done. Also not shown is the paint routine that replays that Blit operation after an EVT_PAINT. Just for what it's worth because I was just working on this. Regards. Mel. From anthonybaxter at gmail.com Mon Aug 23 11:22:39 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Tue, 24 Aug 2004 01:22:39 +1000 Subject: [PATCH] RE: J2 decorator grammar In-Reply-To: References: Message-ID: On Mon, 23 Aug 2004 15:05:27 +0100 (BST), Michael Sparks wrote: > On Sun, 22 Aug 2004, Michael Sparks wrote: > > 2 tests fail: > > * test_bsddb3 > > * test_ossaudiodev Don't worry about either of these - they fail on all sorts of random platforms, unfortunately. (bsddb in particularly seems to be particularly finicky to get right) > > * Produce patch for CVS version. > In progress. Good to hear. Of course, this is all part of the fiendish plot to create more people familiar with the innards of Python - you too can be a developer! On a related note, I've not seen anyone step forward to do the same work for any of the C varieties. If you[1] think that this is a serious contender, then you need to step forward and do the work - a lack of an implementation is almost certainly going to mean that it won't be considered. See this thread for pointers to the SF entry that lists the files changed for the @syntax - this is a good cheat-sheet for implementation. This patch should be created against current-CVS. [1] "you" is addressed in general, not to Michael Anthony From mensanator at aol.compost Sun Aug 29 04:16:30 2004 From: mensanator at aol.compost (Mensanator) Date: 29 Aug 2004 08:16:30 GMT Subject: about presicion References: Message-ID: <20040829041630.28913.00001771@mb-m26.aol.com> >Subject: Re: about presicion >From: Peter Hansen peter at engcorp.com >Date: 8/28/04 10:31 PM Central Daylight Time >Message-id: > >Ali wrote: > >> The decimal module comes with python 2.4? I have 2.3, :(, what do I do? > >The obvious answer is, well, obvious. The real question is >what's stopping you from upgrading? I just tried it and found out it's not compatible with gmpy. Of course, I wouldn't need gmpy to get big floats, but I would then lose all the math functions like linear congruence and modular inverse that my programs depend on. So I, for one, will have to wait for the rest of the world to catch up to 2.4. > >-Peter -- Mensanator Ace of Clubs From paolo.veronelli at yahoo.it Sat Aug 21 13:07:11 2004 From: paolo.veronelli at yahoo.it (Paolo Veronelli) Date: Sat, 21 Aug 2004 19:07:11 +0200 Subject: __metaclass__ and __author__ are already decorators In-Reply-To: References: Message-ID: <4127813F.9020707@yahoo.it> Paul Morrow wrote: > Thinking about decorators, and looking at what we are already doing in > our Python code, it seems that __metaclass__, __author__, __version__, > etc. are all examples of decorators. So we already have a decorator > syntax. What is the compelling reason to invent a new one? And if we > do, what's to become of the old one? You are right ,if some __xxx__ (only __metaclass__ for now?) class attributes have deep meanings (not only a syntactical one(__lt__,__getitem__,....)) ,and many people suggest not to use them (probably there is something about a non pythonicity of __metaclass__ in this behaviour) then it would be very nice to match this deepness against the decorator one ,at least using @ before class definitions if it's the case.... Thanks for pointing out another unpythonicity. Paolino From jerf at jerf.org Tue Aug 24 16:11:26 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Tue, 24 Aug 2004 20:11:26 GMT Subject: Late binding eval()? References: <20040824142636721-0400@braeburn.themorgue.org> Message-ID: On Tue, 24 Aug 2004 18:25:54 +0000, Kevin Smith wrote: > However, in my application, I'm getting an arbitrary expression > from the user. How arbitrary? Using the various parsing packages, it is easy to set up a math calculator with any features you want, for instance, if you just mean "arbitrary math". If you're worried about security, this is really the only safe way to do it. If you aren't worried about security... then I don't know enough about what you are doing to have any other suggestions, but I would point out in the general case even the Python interpeter can't guess in advance what variables will be used, thanks to the magic of "getattr" and friends. From pm_mon at yahoo.com Sun Aug 29 20:28:30 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sun, 29 Aug 2004 20:28:30 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Steven Bethard wrote: > Paul Morrow yahoo.com> writes: > >>Have you seen a significant number of cases where a function uses >>__xxx__ names for local variables? Have you seen any? > > > Are there any examples currently of functions that use __xxx__ names in their > body at all? I haven't seen this, but I haven't really looked... > > STeve > I've seen some that define a few of the pydoc variables (__author__, __version__, etc), although pydoc doesn't recognizes them there. I remember reading a whitepaper on a web templating framework that made use of them too, where each function corresponded to an html tag and the __xxx__ variables controlled caching (memoizing), which database tables were involved, etc. For classes and modules of course you'll see more examples of __xxx__ variables describing meta aspects of the class/module (__metaclass__, __future__, etc.), so it seems consistent that they could describe meta aspects of functions too. From http Sat Aug 21 21:35:23 2004 From: http (Paul Rubin) Date: 21 Aug 2004 18:35:23 -0700 Subject: Getting benifits of database transactions in an OO way? References: <2oq8pmFdd2nfU1@uni-berlin.de> <7xk6vsklxm.fsf@ruckus.brouhaha.com> <2oqb54Fdj12nU1@uni-berlin.de> Message-ID: <7xu0uwlztw.fsf@ruckus.brouhaha.com> Leif K-Brooks writes: > How woould begin_transaction() and finish_transaction() be > implemented? They couldn't be simple wrappers for PostgreSQL > transaction handling, since it's not very object-oriented (the whole > connection has one transaction at a time). Yes, if you want multiple concurrent transactions, you need separate connections for them. From agriff at tin.it Wed Aug 18 16:35:58 2004 From: agriff at tin.it (Andrea Griffini) Date: Wed, 18 Aug 2004 20:35:58 GMT Subject: age of Python programmers References: Message-ID: <24f7i09bosogkov5lgmiehlun3l5oi01lf@4ax.com> On Wed, 18 Aug 2004 12:20:31 GMT, "Lucas Raab" wrote: 38. Started around 15 with assembler (6502) I'm very new to python, but so far I really like it. Andrea From jaydonnell at yahoo.com Thu Aug 26 12:28:21 2004 From: jaydonnell at yahoo.com (Jay Donnell) Date: 26 Aug 2004 09:28:21 -0700 Subject: urllib hangs References: Message-ID: Apparently you don't know what exactly means ;) From fumanchu at amor.org Sun Aug 22 13:56:06 2004 From: fumanchu at amor.org (Robert Brewer) Date: Sun, 22 Aug 2004 10:56:06 -0700 Subject: On consensus decision-making (was Re: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WEDONE?) Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E28@exchange.hqamor.amorhq.net> Peter Hansen wrote: > I suspect many of the J2 and C1 people would actually not "block" > a decision to go with either one versus @pie. I'm not sure > how many people would like to block @pie or either or both of > the other two options. In the end, we already know that the > final decision is (thankfully) made by the BDFL based on his > own good judgement, so voting becomes less and less valuable > at this stage. (In consensus building, a "block" basically says > that someone would refuse to support the community decision, > while 100% consensus means no one blocks the decision even > though some people may not feel it reflects their first choice.) Well said. FWIW, I have a "signatories" section on the proposal, both for and against. More tomorrow. Robert Brewer MIS Amor Ministries fumanchu at amor.org From jzgoda at gazeta.usun.pl Sat Aug 7 18:44:04 2004 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Sat, 7 Aug 2004 22:44:04 +0000 (UTC) Subject: Decorators References: <%A8Rc.50217$Vm1.1280580@news20.bellglobal.com> Message-ID: Roy Smith pisze: >> It seems desirable that we choose words which are as close as possible >> to their everyday usage. > > On the other hand, it's desirable to pick words which have established > meanings in computer science too. The concept of a "decorator" is > pretty well established. The term has been used in GUI frameworks for > 10 or 15 years, and more recently has been enshrined in various pattern > collections. In GUI frameworks it was used for other things IIRC. Also "decorator pattern" in GOF means something different. -- Jarek Zgoda http://jpa.berlios.de/ From mark at deverter.net Wed Aug 18 12:10:18 2004 From: mark at deverter.net (md) Date: Wed, 18 Aug 2004 16:10:18 GMT Subject: readlines() In-Reply-To: References: Message-ID: I am not sure which name is designating your source text (db1 or getdata ?). If it is 'getdata' then you will need to iterate over the file object to grab all of the lines. Try this: for line in db1: (ip, mac) = string.split(line) print 'ip is ', ip run = 'dhcpacct --ip=%s > tt1' os.system(run) getdata = open('tt1', 'r') data=[] for line in getdata.readlines(): data.append(line) print 'data[0] is', data[0] print 'data[3] is', data[3] getdata.close() Hope this helps, Mark d. Yong Wang wrote: > Hi, > I use readlines() to read one data file. Python automatically parses the read contents > into a list of lines. When I used list[0] to print out the 1st line, it is ok. When I use > the list index 2 to print out the 2nd line , there is an error mesage. I only need one line of > input data file in the middle of the file. For example, I have data file like: > --------------------------------------------------------------------------- > Timestamp: Sat Aug 7 11:14:57 AM > Adapter Address: 00:60:08:2A:C9:5A > IP Address: 165.91.10.244 > Directory ID: 0675392c736079cfd81a55028df3cb43 > Domain Name: bdanwood.dsl.tamu.edu > DHCP/NIM Action: lease renewed > Comments: > --------------------------------------------------------------------------- > Timestamp: Sat Aug 7 11:15:56 PM > Adapter Address: 00:60:08:2A:C9:5A > IP Address: 165.91.10.244 > Directory ID: 0675392c736079cfd81a55028df3cb43 > Domain Name: bdanwood.dsl.tamu.edu > DHCP/NIM Action: lease renewed > Comments: > --------------------------------------------------------------------------- > > I have some codes: > ....... > for line in db1: > (ip, mac) = string.split(line) > print 'ip is ', ip > run = 'dhcpacct --ip=%s > tt1' > os.system(run) > getdata = open('tt1', 'r') > data = getdata.readlines() > print 'data[0] is', data[0] > print 'data[3] is', data[3] > getdata.close() > > When run the codes, I got: > data[0] is --------------------------------------------------------------------------- > > data[3] is > Traceback (innermost last): > File "com1", line 64, in ? > print 'data[3] is', data[3] > IndexError: list index out of range > > How can I fix it ? > > Thanks, > > From mwh at python.net Fri Aug 13 07:39:54 2004 From: mwh at python.net (Michael Hudson) Date: Fri, 13 Aug 2004 11:39:54 GMT Subject: [OT] Keyboard layout, was Re: PEP318 References: Message-ID: Sion Arrowsmith writes: > Roy Smith wrote: > >Sion Arrowsmith wrote: > >> As someone who's just started using a Mac for the first time(*), > >> I'd like to add that it's not always plain-sailing on an English > >> keyboard. > >What's wrong with Mac keyboards? > > No @, hence tangential relevance to PEP318 (and a point against > pies, before or after the def). Unless you can remember it's on > option-3. Huh? On *my* mac @ is shift-2 and # is option-3. And I live with the latter, and I type it far more often than anyone is ever going to type @ for decorators... Now, if someone would like to fix \ in place for the purposes of LaTeX, then you're really talking! Cheers, mwh -- I recompiled XFree 4.2 with gcc 3.2-beta-from-cvs with -O42 and -march-pentium4-800Mhz and I am sure that the MOUSE CURSOR is moving 5 % FASTER! -- from Twisted.Quotes From peter at engcorp.com Mon Aug 16 01:04:11 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 01:04:11 -0400 Subject: Flython? In-Reply-To: <30260531.0408131856.5ef3b0d3@posting.google.com> References: <411cbcb1$0$3894$4d4ebb8e@news.nl.uu.net> <30260531.0408131856.5ef3b0d3@posting.google.com> Message-ID: simo wrote: > There's a few libraries for making SVG files in PHP, so there may be > Python versions too, but if you want ActionScript then I guess you're > determined to go with Flash instead..... Well, SVG and ActionScript have very little, if anything, in common. On the other hand SVG has much overlap with the rest of the "Flash" system (taken as a nebulous whole), and when supplemented with Javascript, in systems that can handle that, it starts becoming somewhat similar in many ways. On the other hand, so far I haven't seen signs that SVG support has advanced enough to really be on par with the capabilities (mostly in terms of speed and simplicity) of the little bit of Flash/ActionScript that interests me. My personal goal with this (and I believe Dan's as well) is to be able to create GUI software using ActionScript to write (roughly) the "view" and "controller" portions, with the back end ("model") implemented elsewhere (i.e. on a server) with Python. Why? Well, consider the alternatives. D/HTML plus Javascript gives you the same basic structure, but at the cost of a mostly crappy kind of interface which violates all kinds of UI conventions, feels awkward, often runs slowly, and is a bitch to construct and maintain. Something like wxPython is pretty good for fixing most of that, but then you actually have to install software on the client machines, which is pretty much the thing you want to avoid when you are trying to do client/server. The idea is *not* to do pretty animations ala JibJab.com but "plain old GUI software" (POGS, to steal from Bell and coin a phrase at the same time). SVG really isn't up to the task (yet), and even if it is I suspect there may be really serious performance issues for some time to come. Flash has a compact bytecode, while SVG comes as XML. Need I say more? -Peter From uche at ogbuji.net Mon Aug 9 13:53:55 2004 From: uche at ogbuji.net (Uche Ogbuji) Date: 9 Aug 2004 10:53:55 -0700 Subject: processing XHTML1.1 documents with xml.sax References: Message-ID: webworldL at yahoo.com wrote in message news:... > Has anybody had any luck processing XHTML1.1 documents with xml.sax? > Whenever I try it, python loads the W3C DTD from the top, then crashes > saying that there's an error in the external DTD. > All I need to do is rip through a bunch of XHTML documents and extract > some data, does anybody know a quick way to do this without sax making > outgoing network connections and fussing with DTDs? > > BTW, the code to reproduce the error if anybody cares: > below is a document 'hello.html' produced by the W3C's Amaya: > > > "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> > > > > Hello World > > > > >

    hello world!

    > > > > and the script: > > import xml.sax.handler > xml.sax.parse("hello.html", > xml.sax.handler.ContentHandler() > ) > > the error: > > SAXParseException: > http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-framework-1.mod:89:0: > error in processing external entity reference > > will be thrown. Ouch. I took a brief look at this and expat has a problem here. I should note that there are few more hairy stress tests of DTD conformance than XHTMLMOD (the basis of XHTML 1.1). Using the most recent expat, 1.95.8, something weird happens: [uogbuji at borgia xmlwf]$ xmlwf -p ~/foo.xhtml /home/uogbuji/http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd: No such file or directory /home/uogbuji/foo.xhtml:3:52: error in processing external entity reference It's a little confused about the fact that http:// starts a URL. I tried as much fiddling as I had time to, but I think there's little recourse but for you to submit a bug report to the expat project: http://sourceforge.net/tracker/?group_id=10127&atid=110127 And change your DTD to use XHTML 1.0 (which *does* work with expat) rather than 1.1 Good luck. -- Uche Ogbuji Fourthought, Inc. http://uche.ogbuji.net http://4Suite.org http://fourthought.com Decomposition, Process, Recomposition - http://www.xml.com/pub/a/2004/07/28/py-xml.html Perspective on XML: Steady steps spell success with Google - http://www.adtmag.com/article.asp?id=9663 Managing XML libraries - http://www.adtmag.com/article.asp?id=9160 Commentary on "Objects. Encapsulation. XML?" - http://www.adtmag.com/article.asp?id=9090 Harold's Effective XML - http://www.ibm.com/developerworks/xml/library/x-think25.html A survey of XML standards - http://www-106.ibm.com/developerworks/xml/library/x-stand4/ From rnichol_rrc at yahoo.com Mon Aug 16 01:23:49 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Mon, 16 Aug 2004 00:23:49 -0500 Subject: Python secure? In-Reply-To: References: Message-ID: <2xXTc.3775$bJ2.24876@news1.mts.net> Terry Reedy wrote: > ... compiled C can be terribly insecure relative to > Python. C has dangerous functions like strcpy() which, if used with > external input, can make a program subject to buffer overrun exploits that > can do explosive damage. But this doesn't make C an insecure language. No language is either secure nor insecure. It's what the programer does with it that matters. From chris.cavalaria at free.fr Mon Aug 23 15:14:42 2004 From: chris.cavalaria at free.fr (Christophe Cavalaria) Date: Mon, 23 Aug 2004 21:14:42 +0200 Subject: PEP318: radical notion References: Message-ID: <412a4222$0$293$626a14ce@news.free.fr> Arien Malec wrote: > Apologies for feeding the fire, when we are rallying around a consensus, > but I've been concerned about the clash between syntax and semantics, and > I've finally reached a mini-epiphany: > > The problem with PEP318 is that it is too powerful, and tries to do too > much. It is a sledgehammer for attacking three problems: > > 1) Metadata, a la Java and C# > 2) class & static method defs > 3) Arbitrary post-definitional transformations of functions. > > (where 2 is a special frequent use case that's part of 3). > > We have ueber-powerful semantics (implementing 3), trying to solve > problems with very different semantics (e.g., 1). > > OK, that's what I know. Here's a proprosal, that may or may not work, > because my knowledge of metaclass programming is only sketchy: > > 1) Make PEP318 *only* implement problem (1). That is, create sematics for > defining and retrieving function/method/class metadata > 2) Create a new default metaclass that uses metadata for class/static > method definitions to perform the necessary class/staticmethod > transformations. Perhaps use this metaclass as default in 2.4 only via a > "from __future__ import foo". > 3) Leave any arbitrary transformations to be implemented via custom > metaclasses -- these metaclasses will have access to the custom metadata > to trigger method def transformations. > > Arien Unfortunately for you, you can use decorators on normal functions and not only on member functions. It rules out any metaclass based implementation. From erik at heneryd.com Thu Aug 12 06:57:51 2004 From: erik at heneryd.com (Erik Heneryd) Date: Thu, 12 Aug 2004 12:57:51 +0200 Subject: Capturing repeating group matches in regular expressions In-Reply-To: <20040811235834.45616.qmail@cyberdyne.co.mars> References: <20040811235834.45616.qmail@cyberdyne.co.mars> Message-ID: <411B4D2F.50606@heneryd.com> James Collier wrote: > Michael Hudson [ mwh at python.net ] writes: > > >>James Collier writes: >> >> >>>Is it possible to capture the results of repeating group matches in >>>the python regular expression module? >> >>Not easily; there's a small dicussion on python-dev at the moment >>about this. Erik Heneryd hacked up something that might be useful: >> >>http://mail.python.org/pipermail/python-dev/attachments/20040810/a5e602ab/structmatch.py >> Should be added that this is a hack in the true sense of the word. I wouldn't use it for anything other than for what it was written - experimenting. Erik From __peter__ at web.de Fri Aug 6 12:39:35 2004 From: __peter__ at web.de (Peter Otten) Date: Fri, 06 Aug 2004 18:39:35 +0200 Subject: Default list parameter issue References: Message-ID: Olivier Boudeville wrote: > I do not understand why using an empty list as default parameter results > in such a different behaviour. You are not alone. http://www.python.org/doc/faq/general.html#why-are-default-values-shared-between-objects Peter From peter at engcorp.com Thu Aug 26 08:42:59 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 26 Aug 2004 08:42:59 -0400 Subject: Converting hex string to an integer In-Reply-To: References: <412d9e18$0$22821$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: Rick Holbert wrote: > Derek Fountain wrote: >>Given the character string "0x00A1B2C3" arriving at sys.argv[1] how do I >>convert that to an integer which I can do some math on? > > i = eval(sys.argv[1]) That's dangerous advice to a newbie if not qualified carefully. Derek, "eval" could be the source of serious security problems if you don't understand its power. Specifically it should almost never be used for input that comes from a user or via the command line. There is pretty much always another and much better way to do the simple stuff like conversions than to use eval. For example, imagine if a malicious could feed your program this: (on the Linux command line) $ myscript "__import_('os').system('rm -rf /')" or the Windows version: C:\> myscript "__import_('os').system('deltree /y c:\*.*')" Bye-bye filesystem... (don't run these examples!) -Peter From a at b.com Mon Aug 16 21:55:36 2004 From: a at b.com (wonder) Date: Tue, 17 Aug 2004 09:55:36 +0800 Subject: passing the url of the current webpage to python script In-Reply-To: References: Message-ID: Dan Greenblatt wrote: > wonder wrote: > >> Hi, >> >> How can I pass the url of the current webpage link to a python script >> in html? >> >> thanks >> sam > > are you using a python script as a helper application? yeah, sort of. I m building a html page that will call a python script by passing it the current URL of the webpage. The html page will be opened by any web user with any web browser. thanks sam From ellisjb at my-deja.com Mon Aug 23 17:23:38 2004 From: ellisjb at my-deja.com (ellisjb at my-deja.com) Date: 23 Aug 2004 14:23:38 -0700 Subject: Py2Exe and Threading In-Reply-To: <81a41dd.0408231216.6f919ff4@posting.google.com> Message-ID: Lad wrote: > Does anyone use Py2exe for a script that uses threading modul. > In have a main thread and another in which I use smtplib to send email > while the main thread is running. > Under Python it works well but after compilation into exe it hangs( > freezes) in the thread where I send email with smtplib. Sounds like you have a race condition that for whatever reason you're lucky enough not to hit during interpretation. Use appropriate locks; I use py2exe on an application that uses many threads and have no problems. -Jonathan From h.b.furuseth at usit.uio.no Mon Aug 30 15:31:10 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 30 Aug 2004 21:31:10 +0200 Subject: TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' References: Message-ID: [Brett C.] > Set your environment 'CC' environment variable to gcc and it should go > away. [Martin Koekenberg] How do I set this environmet variable ?? I don't have a lot of linux experience ;-) [Brett C.] > For Bourne-style shells (BASH, ZSH, etc.) ``export CC=gcc`` will do it > for the current shell (won't save it for future use, that requires > setting it in your shell's config file. Nitpick: That works for bash and zsh - and therefore for Martin, since he uses Linux - but not for plain non-Linux Bourne 'sh'. The portable Bourne way is CC=gcc; export CC > For CSH style I think it is ``setenv CC gcc`` but I am not sure. That's right. And the standard way which works for both Bourne and CSH style, but for just one command at a time (in this case ./configure), is env CC=gcc ./configure -- Hallvard From russblau at hotmail.com Wed Aug 25 09:16:00 2004 From: russblau at hotmail.com (Russell Blau) Date: Wed, 25 Aug 2004 09:16:00 -0400 Subject: Just a quick one References: Message-ID: <2p3hogFel3j8U1@uni-berlin.de> "M. Clift" wrote in message news:cgi2qq$rvp$1 at news6.svr.pol.co.uk... > Hi, > > Just a quick one. I'm trying to call [Bob','One'] with this, but I keep > getting 'unhashable'. I've tried various ' " and [ and can't get the thing > to work. Any offers? ... > nextName = {['Bob','One']:['Rita','Sue'],\ > 'Rita':['Mary','Sue',['Bob','One']],\ > 'Sue':['Rita','Mary',['Bob','One']],\ > 'Mary':['Sue','Rita']} ['Bob', 'One'] is a list. You can't use a list as a dictionary key, because it is 'unhashable'. Try ('Bob', 'One'), which is a tuple, instead. See http://www.python.org/doc/current/tut/node7.html#SECTION007400000000000000000 (the first paragraph in 5.4). -- I don't actually read my hotmail account, but you can replace hotmail with excite if you really want to reach me. From gerrit.muller at embeddedsystems.nl Mon Aug 23 02:30:09 2004 From: gerrit.muller at embeddedsystems.nl (Gerrit Muller) Date: Mon, 23 Aug 2004 08:30:09 +0200 Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: Gerrit Muller wrote: >P.S., >> >> a lot of people added other intersting datapoints: when they started >> programming and other languages used. I started around the age of 14, >> with HP table top machines (polish notation). Programming languages: >> Assemblers, Fortran, *Basic, *Pascal, C, Objective-C, C++. The most >> positive experiences were Sinclair QL-basic, Turbo Pascal, Objective-C >> and then a quantum leap towards Python. >> I forgot to mention Java, this must be Freudian mistake Gerrit -- Gaudi systems architecting: From news at titanic.co.uk Mon Aug 2 15:19:07 2004 From: news at titanic.co.uk (Simon Faulkner) Date: Mon, 02 Aug 2004 20:19:07 +0100 Subject: Python executable on Windows In-Reply-To: <410e91ce$0$58816$5a6aecb4@news.aaisp.net.uk> References: <410e91ce$0$58816$5a6aecb4@news.aaisp.net.uk> Message-ID: <410e93a1$0$58815$5a6aecb4@news.aaisp.net.uk> Simon Faulkner wrote: > Hi All, > > I've written a fair bit of simple Python for Linux and have been asked > to write a program for win32. > > Is it possible to write a program and add the Python interpreter so that > I just end up with a single .exe file for windows? > > I know that it will be large but it will be simple! > > TIA > > Simon I guess py2exe as in the thread above! Doh... Is it easy? S From tjreedy at udel.edu Sun Aug 15 23:10:30 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 15 Aug 2004 23:10:30 -0400 Subject: Python secure? References: Message-ID: "M. Clift" wrote in message news:cforh6$qiv$1 at newsg3.svr.pol.co.uk... > One thing has come up and that is when I spoke of secure > I presumed that compiled C source code software was secure > and I was asking how did python compare to this. I understand that you mean 'secure' in a personal sense of 'protecting my source code'. But I do want to mention that in a social sense of 'not taking down the Internet', compiled C can be terribly insecure relative to Python. C has dangerous functions like strcpy() which, if used with external input, can make a program subject to buffer overrun exploits that can do explosive damage. Hence the Blaster worm of Feb (?) 2003. If Microsoft had written SQL Server in Python (or employed better programmers and/or security checks), I believe it could not have happened. One lesson is that understanding the actual behavior of a C program may require knowing and understanding the exact run time memory layout of code and data, including 'hidden' items like each call frame's return address pointer, added by the compiler rather than the programmer. Virus and worm writers understand this; many C programmers seem not to. Python programs are much easier to understand. So your choice of language may partly depend on which kind of security is most important to you -- which is what I believe others said in the beginning. Terry J. Reedy From aleaxit at yahoo.com Thu Aug 26 17:08:58 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 23:08:58 +0200 Subject: Call for signatories for J2 References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> <7xoekx4wit.fsf@ruckus.brouhaha.com> <1gj5cs7.wqxd1s1ec69umN%aleaxit@yahoo.com> <7xfz69oc1f.fsf@ruckus.brouhaha.com> Message-ID: <1gj5eom.gbo9f512upip0N%aleaxit@yahoo.com> Paul Rubin wrote: > aleaxit at yahoo.com (Alex Martelli) writes: > > I think a keyword that's ALREADY a keyword has been almost ignored, > > though people occasionally did mention it re decorators: 'as'. I'd love > > to see 'as' used as THE decorator keyword. personally I'd prefer > > 'def as classmethod foo(...):' > > followed by > > How do you handle the other proposed uses of decorators, e.g. type > declarations? > > def foo as int (a as string, b as int): > ... > > seems pretty awful to me. Type declarations make me cringe, but if I *had* to have them then 'b as int' is the best syntax I could imagine for them offhand. Alex From martindemello at yahoo.com Sat Aug 21 06:37:29 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Sat, 21 Aug 2004 10:37:29 GMT Subject: decorator J4 - any objections? References: <10id2djglri8o15@corp.supernews.com> Message-ID: Jeff Shannon wrote: > > In fact, the biggest problem that I can see with the J4 syntax is its > close similarity to all of the decorator-inside-def variations. Since > GvR has spoken strongly against putting decorators in that location, it > seems to me to be a waste of effort to advocate for that. Now, perhaps > having that outdented keyword to indicate the function-body start > *might* make a difference with him... but I would expect that it won't. The advantage J4 has over J2 is that "def function as " reads much better than "decorate def function " - expected from English syntax is 'decorate def function with '. Perhaps J2 but with proposal L to call the decorator declaration something other than "decorate" - 'using' is the best I've seen so far, though it's still not perfect. Or another idea - how about inverting the meaning of 'as', and changing the form of the decorator declarations slightly? as: classmethod memoised accepting (int, int) returning (float) def foo(bar, baz): . . . martin martin From pm_mon at yahoo.com Tue Aug 31 08:20:53 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Tue, 31 Aug 2004 08:20:53 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Steven Bethard wrote: > Paul Morrow yahoo.com> writes: > >>Actually, these look like assignments to local *magic* variables. >>There's the difference. The double underscores before and after each >>name loudly proclaims that these variables are not like 'normal' >>variables. They're special in some way. That's a Python convention. > > > Note that you're asking for __xxx__ variables to be assignments to the > function's attributes even though they're in the part of the function that > gets executed when the function is *called*. Let's look at what examples of > this behavior might look like for some different objects. > > # in the part of a function that is executed when the function gets called > def f(): > __author__ = 'Steve' > > # in the part of a class that is executed when the class gets called > class S(object): > def __new__(cls): > __author__ = 'Steve' > > # in the part of an object that is executed when the object gets called > class T(object): > def __call__(self): > __author__ = 'Steve' > > Note that the parallel I'm trying to draw here is that in each of these cases, > the __author__ is assigned to in the part of the definition that gets executed > when the object is *called*. Thus f(), S(), and T()() all execute the code > block containing the __author__ assignment. Presumably you wouldn't want the > __author__ statements to assign to the class or the object in the second two > examples? > In all of your examples, the __author__ assignments apply to the object being defined. In the first example, that's the function f. In the second example that's the method __new__, and the method __call__ in the 3rd example. Note that this is true, /even in today's Python/. Your intention behind each __author__ definition in your examples is *not* to create a local variable. Your function/method (most likely) is not going to use __author__ when it executes. Instead you are adding to the definition of the function/method. What I'm wondering is whether we can stop thinking of assignments to magic attributes that immediately follow the docstring (if present) as something that gets executed when the function is called. I think that we can. I think that --- because of the names of these variables (author, version, features) --- they will obviously and intuitively be associated with the function's definition, not it's execution. That's a point a lot of us have been forgetting here. These variables don't sound like something the function would use in it's calculation. So that, plus the fact that they are specially decorated (leading and trailing underscores), plus the fact that they immediately follow the docstring categorize them as part of the function's definition, not execution. But why speculate. Let's see if this is really going to be unclear in practice. Ask someone who has never seen Python before which are the local variables in the following def. def circumference(diameter): """Calculate the diameter of a circle.""" __author__ = 'Paul Morrow' __version__ = '0.1' pi = 3.14 return pi * diameter > Of course, what you really want is for these things to be assigned to in the > part that gets executed when the object is *defined*. For a class, this is > clearly: > > class S(object): > __author__ = 'Steve' > > But what gets executed when a function is defined? Just the def statement, > the binding of the function name to its body. And the binding of the __doc__ variable, if a docstring is present. > To be consistent with classes > then, your assignment to __author__ should be *in* the def statement. So what > you're suggesting, basically, is that the def statement should be extended to > include any __xxx__ assignments following the docstring. > Yes. > Extending the def statement is not unreasonable, but IMHO it should be clear > that the extensions to the def statement are part of that statement. There's > nothing in current Python semantics that would suggest that any assignments in > a funcdef are part of the def statement. Note that even docstrings, which > could be reasonably argued to be part of the function definition, cannot be > included in the def statement by assignment: > > >>>>def f(): > > ... __doc__ = "f" > ... > >>>>print f.__doc__ > > None > > Certainly __xxx__ variables are special in some way. But are they special in > the way you want them to be? Not yet, /formally/. But /in practice/ this is how they are used (to make meta statements about the thing being defined). There's no need for a new syntax here. We don't need more words in our language, or anything that makes our code less readable [*]. [*] Have you seen the decorator proposals? > AFAICT, *assignment* to __xxx__ variables is > never what does the magic. The magic is done when the Python interpreter > reads the *values* of those variables. The variables continue to exist in > whatever namespace they were created in -- AFAICT, current Python __xxx__ > variable assignments never cause __xxx__ variables to change namespace. > The assignments to __xxx__ variables (immediately following the docstring, if present) would occur in the namespace of the object (function/method) being defined. The assignments would not cause them to change namespaces. > I seems like you want to introduce a substantially new semantics to an already > existing syntax. This creates ambiguity... Ambiguity bad. Bad, Ambiguitiy, > bad! No biscuit! ;) > I maintain that the author's intention behind these assignments is what we should focus on. When we define a __xxx__ variable inside of a function def, we are (most likely) making a meta statement about the function. We are not defining a local variable to be used later in the execution of the function. So this proposal would not be changing the meaning of the __xxx__ assignments in practice. It would merely be formalizing them. Paul From alikakakhel3 at hotmail.com Fri Aug 20 21:15:54 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 20 Aug 2004 18:15:54 -0700 Subject: how to display unicode in a Label in Tkinter References: Message-ID: <8f17f4bc.0408201715.73d0aaf9@posting.google.com> I dont think I am following. Could you possibly give the code and add commments to explain? From chris.cavalaria at free.fr Sat Aug 21 16:22:47 2004 From: chris.cavalaria at free.fr (Christophe Cavalaria) Date: Sat, 21 Aug 2004 22:22:47 +0200 Subject: My only complaint about Python References: <874qmxj81k.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Message-ID: <4127af18$0$22378$626a14ce@news.free.fr> Tim Daneliuk wrote: > 510046470588-0001 at t-online.de wrote: >> Tim Daneliuk writes: >> >> >>>Istvan Albert wrote: >>> >>>>In all fairness this is more the problem with Microsoft than >>>>python. If they had a free fully-featured compiler then Python >>>>would be compiled with that. >>> >>> >>>They do. MSC/C++ is now available at NO cost: >>> >> >> >> no cost is not the same as free >> >> Klaus Schilling > > > > "No Cost" is _exactly_ the same thing as "Free". It is not the same > thing as "Open Source". > > The debate is foolish in any case. If I use an GPLed compiler, even with > the Lesser License, I have constraints placed upon what I may or may > not do with the derivative work. If I use a commercial compiler, I do > not have access to the source code _for the compiler_, but (usually) > there are no constraints placed upon what I may do with the derivative > work. This is wrong on so many levels : - gcc is GPL software and you don't have to GPL the source code of the programs you compile with it. Doing so would place a restriction on the user of the software which is exactly what the GPL is trying to prevent. Using gcc to compile source code isn't creating a derivative work of gcc ! - if you modify the gcc source code and thus create a derivative work, you don't have to distribute the changes, unless you distribute the new gcc version. - with a commercial closed source compiler, you can't do any derivative of the compiler at all and thus you have less freedom than with a GPL compiler. If you can't see the difference between using a software and creating a derivative work of that software ... From jfabiani at yolo.com Wed Aug 4 19:13:20 2004 From: jfabiani at yolo.com (John Fabiani) Date: Wed, 04 Aug 2004 23:13:20 GMT Subject: eric3 completion References: <953AD2389idtoken@128.91.2.239> Message-ID: John Fabiani wrote: Feeling dumb - it's part of the uer perferences duh! John From martin.clausen at get2net.dk Thu Aug 26 09:13:24 2004 From: martin.clausen at get2net.dk (Martin) Date: Thu, 26 Aug 2004 13:13:24 +0000 (UTC) Subject: Web Application - User Management - RBAC Message-ID: I am putting together a simple web-app for construction of standard documents. Basically the app will present a form for inputting the variable content / overriding standard text and send back a complete .doc / .swx. The motivation for using a web app instead of templates is that I have found templates too brittle, and I would like to store the variable/overriding data in an SQL backend. I would like to implement RBAC(Role Based Access Control) in the app. How would one best go about that ? is there any code available(classes/frameworks) ? would one render pages and thereby options based on role or guard methods(i.e. call some kind of access control object and raise exceptions if an action is not allowed for the role, or perhaps derive all objects from an object that automatically handles such checks when a method is called ?) or some other approach ? I have looked at Webwares UserKit but it is apparently incomplete and frankly I can't figure out how it works. I am planning to use CherryPy as a framework, but would be open to another approach. Regards, Martin From danb_83 at yahoo.com Sun Aug 8 07:16:09 2004 From: danb_83 at yahoo.com (Dan Bishop) Date: 8 Aug 2004 04:16:09 -0700 Subject: Decorators References: <%A8Rc.50217$Vm1.1280580@news20.bellglobal.com> Message-ID: Arthur wrote in message news:... > On Sat, 07 Aug 2004 18:40:47 -0400, Roy Smith wrote: ... > I am a great believer in (motivated ) folks capacity to learn new > things. And the existence of synonyms is not news to anyone. So no, > nobody motivated to learn new things will be stopped in their tracks > by @ in a new context I agree. > (anymore than anyone motivated to learn new > things things would - given an explanation - be stopped in their > tracks by 1/2 = 0 ). I never had a problem with 1/2 == 0; I was already used to it from C, C++, and Java. But I did get stopped in my tracks the time a function that contained a line like mean = sum(seq) / len(seq) failed because the list happened not to contain any floats. From nick at craig-wood.com Fri Aug 13 01:43:56 2004 From: nick at craig-wood.com (Nick Craig-Wood) Date: 13 Aug 2004 05:43:56 GMT Subject: A decorator syntax not yet mentioned (I think!) References: Message-ID: Steven Bethard wrote: > decorate: > grammarrule('statement : expression') > versioninfo("Added in 2.4") > deprecated > typeinfo(None) > def p_statement_expr(self, p): > print p[1] Has anyone considered overloading one of the existing keywords... "as" comes to mind as it immediately suggests a naming scheme for the decorators, "as" "noun" "noun" "noun", eg as: staticmethod grammarrule('statement : expression') version("Added in 2.4") deprecatedmethod type_(None) def p_statement_expr(self, p): print p[1] ( Actually "as" doesn't appear to be a keyword anyway! ) -- Nick Craig-Wood -- http://www.craig-wood.com/nick From peter at engcorp.com Sat Aug 28 23:25:08 2004 From: peter at engcorp.com (Peter Hansen) Date: Sat, 28 Aug 2004 23:25:08 -0400 Subject: Converting hex string to an integer In-Reply-To: References: <412d9e18$0$22821$5a62ac22@per-qv1-newsreader-01.iinet.net.au> Message-ID: Michael Hudson wrote: > Peter Hansen writes: > > >>Rick Holbert wrote: >> >>>Derek Fountain wrote: >>> >>>>Given the character string "0x00A1B2C3" arriving at sys.argv[1] how do I >>>>convert that to an integer which I can do some math on? >>> >>>i = eval(sys.argv[1]) >> >>That's dangerous advice to a newbie if not qualified carefully. >> >>Derek, "eval" could be the source of serious security problems >>if you don't understand its power. Specifically it should >>almost never be used for input that comes from a user or >>via the command line. There is pretty much always another >>and much better way to do the simple stuff like conversions >>than to use eval. >> >>For example, imagine if a malicious could feed your program this: >> >>(on the Linux command line) >> >> $ myscript "__import_('os').system('rm -rf /')" > > Well, in this situation, he could just type > > $ rm -rf / > > But, yes. He could if he were on the same system, but it's quite possible that sys.argv[1] in this particular program is actually coming from a remote system in some manner (web?). But, yes. :-) -Peter From squirrel at WPI.EDU Wed Aug 11 10:55:40 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Wed, 11 Aug 2004 10:55:40 -0400 Subject: Yet another decorator proposal In-Reply-To: <2ntvn1F4mgskU1@uni-berlin.de> References: <2ntvn1F4mgskU1@uni-berlin.de> Message-ID: On Wed, 11 Aug 2004, Reinhold Birkenfeld wrote: > - Decorators are "hidden" in a string. This is almost as ugly as the > meta-constructs some other languages have, hiding vital information in > comments. Also, don't forget docstrings get thrown away when using python -OO. Great voodoo would be needed to prevent this from happening. From rschroev_nospam_ml at fastmail.fm Sat Aug 21 04:37:31 2004 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Sat, 21 Aug 2004 08:37:31 GMT Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: John Hunter wrote: >>>>>>"Roel" == Roel Schroeven writes: > > > Roel> I thought it would be fairly obvious, but I added labels > Roel> anyway. I'm not satisfied with there positioning though, and > Roel> I don't know how to correct it (it's the first time ever I > Roel> use matplotlib). > > How would you like them to be different? They look pretty good to > me.... :-) Hm, it seems to be better now, after some unrelated changes. Yesterday 'Age' was positioned too high, almost on the same height as the numbers indicating the age. -- "Codito ergo sum" Roel Schroeven From jimcser at pacifier.com Sat Aug 14 17:07:30 2004 From: jimcser at pacifier.com (Jim Cser) Date: Sat, 14 Aug 2004 14:07:30 -0700 Subject: Numarray: Using sum() within functions Message-ID: <10hsvoka533ci3c@corp.supernews.com> Hello- I have a function to generate a multi-dimensional array, which then gets summed over one axis. The problem is that the dimensions are large, and I run out of memory when I create the entire array, so I'm trying to do the sum *within* the function. Example-- variables x,y,z,t; dimensions numX, numY, numZ, numT; functions f1(x,y,z,t), f2(y,z,t); want to calculate f1*f2 and sum over t to get out[x,y,z]. With loops, I could do it like-- out = zeros((numX,numY,numZ)) for x in range(numX): for y in range(numY): for z in range(numZ): for t in range(numT): tempval = f1(x,y,z,t) * f2(y,z,t) out[x,y,z] = out[x,y,z] + tempval With numarray, if I had enough memory, I could just do-- temp1 = fromfunction(f1,(numX,numY,numZ,numT)) temp2 = resize(fromfunction(f2,(numY,numZ,numT)),(numX,numY,numZ,numT)) out = sum(temp1 * temp2, axis = 3) Instead, I'm trying to do something like-- def f3(x,y,z): for t in range(numT): tempval = f1(x,y,z,t) * f2(y,z,t) outval = sum(tempval,axis = 3) return outval out = fromfunction(f3,(numX,numY,numZ)) I've been trying various slicing and indexing, but I can't seem to get that *extra* dimension within the 3-D function. I've scoured the documentation and list archives, but haven't found exactly what I need. Any suggestions? Am I stuck with generating the entire 4-D array? Thanks in advance, Jim Cser From ben at benlast.com Mon Aug 16 11:50:07 2004 From: ben at benlast.com (Ben Last) Date: Mon, 16 Aug 2004 16:50:07 +0100 Subject: Newbie question about file input In-Reply-To: Message-ID: Just the sort of problem to muse over whilst having a cup of tea :) > Basically every game starts with the [Event "..."] header and then the > information about the game is given. An entirely blank line signals the end of file (from the Python documentation on readline(): "An empty string is returned only when EOF is encountered immediately". Otherwise the string will end with a newline (probably "\n"). Try your loop as: while 1: line = zf.readline() #If line is entirely empty, exit the loop; we've met EOF if not line: break #Strip any whitespace and split the line. A line that contains #only whitespace will result in an empty list being returned from #split, so test for that. ls = line.strip().split() if ls and ls[0] == "[Event": games += 1 zf.close() On the other hand, I'm guessing that the reason you're splitting the line is to look at the first word. There are alternative ways to do this: if line.startswith("[Event"): or if line.find("[Event") >= 0: Either would cope with the line being empty, or containing just whitespace. Ok, so if all you want to do is to count the number of games, you can count the number of lines that contain "[Event...": #Simple way zf=open('test.pgn','r') count = 0 for line in zf.readlines(): if line.startswith("[Event"): count = count + 1 zf.close() Or: #More exotic way, using a list comprehension zf=open('test.pgn','r') count = len([x for x in zf.readlines() if x.strip().startswith("[Event")]) zf.close() That's gratuitously clever, though :) regards b > My first attempt at the python script is: > > #! /usr/bin/env python > import string > import sys > zf=open('test.pgn','r') > # games is number of games > games = 0 > while 1: > line = zf.readline() > if line == '': > break > ls = line.split() > print ls[0] > if ls[0] == '[Event': > games+=1 > zf.close() > print games > > > I'm having problems when the script reads a blank line from the pgn > file. I get the following error message: > IndexError: list index out of range > The problem is that ls[0] does not exist when a blank line is read. What > would be the best way of fixing this? > > > > > > -- > Aaron Deskins > Graduate Student > Chemical Engineering > Purdue University > -- > http://mail.python.org/mailman/listinfo/python-list From eurleif at ecritters.biz Sun Aug 22 00:26:48 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sun, 22 Aug 2004 00:26:48 -0400 Subject: Getting benifits of database transactions in an OO way? In-Reply-To: <7xfz6fhmjo.fsf@ruckus.brouhaha.com> References: <2oq8pmFdd2nfU1@uni-berlin.de> <7xk6vsklxm.fsf@ruckus.brouhaha.com> <2oqb54Fdj12nU1@uni-berlin.de> <7xu0uwlztw.fsf@ruckus.brouhaha.com> <2oqhlkFdi80eU1@uni-berlin.de> <7xfz6fhmjo.fsf@ruckus.brouhaha.com> Message-ID: <2oqle1Fd83upU1@uni-berlin.de> Paul Rubin wrote: > Leif K-Brooks writes: >>import people >>import companies >>people_transaction = people.begin_transaction() >>companies_transaction = companies.begin_transaction() > > > You wouldn't do it that way. How would I do it? If you have the time, I'd really appreciate a simplified example of how you'd write the "people" module. > You could take a look at how javabeans does it. I've tried Googling for "javabeans", but it's kind of like Googling for the word "the". Is there an example of Javabeans you would recommend looking at? From dbickett at gmail.com Thu Aug 26 16:11:31 2004 From: dbickett at gmail.com (Beeyah) Date: 26 Aug 2004 13:11:31 -0700 Subject: Call for signatories for J2 References: Message-ID: <1d6cdae3.0408261211.79bd0b41@posting.google.com> For. Daniel Bickett. From jzgoda at gazeta.usun.pl Fri Aug 13 17:04:27 2004 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Fri, 13 Aug 2004 21:04:27 +0000 (UTC) Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: Thomas Bartkus pisze: > > One of the most commmon reasons programmers cite for not trying Python > > is that indentation determines the program flow -- they think its > > weird. > > > I wonder if there is a way to remove this initial barrier. > > Why? Do we you really want to let just *anyone* in :-) > > When I explain this about Python and I start hearing that flak, I simply > agree and suggest that Python is not for you. > > Some people should be *forbidden* to move outside of java or VB :-) Most of newly-addicted to Python says that forced intendation is something that makes Python programs easier to read and understand. But you are right, some people should never go outside of (insert your most hated programming language here, in my case ObjectPascal). -- Jarek Zgoda http://jpa.berlios.de/ From steven.bethard at gmail.com Fri Aug 13 14:13:48 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Fri, 13 Aug 2004 18:13:48 +0000 (UTC) Subject: decorator syntax polling suggestion References: Message-ID: David Vaughan Gifford.UK.com> writes: > Sounds like what we need is a transferable multiple vote system - see > http://www.wordiq.com/definition/Coombs%27_method > That way, the poll-winner was voted either for or against by each person > who > cared about it. Hmm... Actually, I think Approval Voting (http://www.wordiq.com/definition/Approval_voting) might be more appropriate. They say that "Approval Voting would lead to the election of "compromise candidates" disliked by few, and liked by few", which I figure is about as good as we can get here. ;) STeve From olivier.parisy at free.fr Mon Aug 9 09:01:38 2004 From: olivier.parisy at free.fr (Olivier Parisy) Date: Mon, 09 Aug 2004 15:01:38 +0200 Subject: Exceptions as a Control Structure Message-ID: <411775aa$0$17867$626a14ce@news.free.fr> Hi all, I am new to Python (I just finished Guido's tutorial). I was very surprised to learn there that the StopIteration is used to end for loops in a standard iterator setting. I come from C++, where the use of exceptions as control structures is frowned upon for efficiency reasons. What is the Python canon on this topic ? Are exceptions considered as reasonable control structures, or is StopIteration alone of its kind ? Regards, Olivier. From sbabbitt at commspeed.net Thu Aug 26 21:20:04 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Thu, 26 Aug 2004 18:20:04 -0700 Subject: Sound file manipulation in Python References: Message-ID: <1093570115.70672@news.commspeed.net> "Paul Moore" wrote in message news:uu0upzj72.fsf at yahoo.co.uk... > Does anyone know of a Python library which handles sound file formats > (MP3, Ogg, FLAC are the three I'm nost interested in). I'd like > something that can manipulate "metadata" - stuff like artist, title, > album tags. I'm not critically interested in format conversion, or > playing sound files - I can handle that with other applications. > > I'm using Windows, and Python 2.3, if it matters (as it might for C > extensions). > > I can manage with just reading the metadata, but ideally writing > would be useful, too. Multiple libraries is OK, but I need something > more than just MP3. > > If there's nothing available for Python, does anyone know of a good C > library that could be wrapped? (Or used via ctypes, maybe). > > Thanks, > Paul. > -- > Ooh, how Gothic. Barring the milk. I would try the Snack toolkit at http://www.speech.kth.se/snack/ Highlights High level sound objects, with flexible storage management and streaming support. Multiple simultaneous playback and recording threads (system dependent). All audio data handled as floating point internally for fast and accurate computations. Multi-platform, same scripts usable on Windows 95/98/NT/2K/XP, Linux, Macintosh, Sun Solaris, HP-UX, FreeBSD, NetBSD, and SGI IRIX. Script compilation tool included, for easy deployment using stand-alone executables. Filters which can be used to process sound objects or during playback for on-the-fly operation. Visualization with waveforms, spectrograms, and spectrum sections. Postscript support. Real-time visualization/spectrum analysis. Web enabled, possible to run scripts embedded in web pages through the use of the Tcl plug-in. Extensible, new commands, filters, and sound file formats can be added using the Snack C-library. Lots of examples included as well as a skeleton C-extension. Supported sound file formats: WAV, AU, AIFF, MP3, CSL, SD, SMP, and NIST/Sphere Tom From brett at python.org Wed Aug 25 18:54:58 2004 From: brett at python.org (Brett C.) Date: 25 Aug 2004 15:54:58 -0700 Subject: TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' In-Reply-To: <3ptpi0h6i94l7c6raml10o4d3sml2e1etf@4ax.com> Message-ID: Set your environment 'CC' environment variable to gcc and it should go away. From tim.leslie at gmail.com Tue Aug 24 06:03:20 2004 From: tim.leslie at gmail.com (Tim Leslie) Date: Tue, 24 Aug 2004 20:03:20 +1000 Subject: Logical lines of code counter In-Reply-To: References: <2ot090Fe5442U1@uni-berlin.de> <2ot78fFe1mneU1@uni-berlin.de> Message-ID: Hi Sylvain, Since you're alive on this list, I thought I'd throw you a couple of questions: 1) Where should I best be asking pylint questions? The mailing list looks a bit quite so I wasn't sure if I would get a reply. 2) Is there someway to specify a set of variables which won't throw errors for being unused, eg _ when used as a dummy in a for/list comp. 3) Why does this trigger? W0622 datacore.ns5 Ns5._parseHeaders 156 Redefining built-in '_' The offending line is: electrodes = [{} for _ in range(self.num_channels)] Cheers Tim On Tue, 24 Aug 2004 10:34:16 +0200, Sylvain Thenault wrote: > > > On Sun, 22 Aug 2004 23:43:25 -0400, Leif K-Brooks wrote: > > > Tim Leslie wrote: > >> On Sun, 22 Aug 2004 21:44:17 -0400, Leif K-Brooks > >> wrote: > >> > >>>I got bored with working on larger projects and wrote a little > >>>script/module for counting logical (not physical) lines of Python code > >>>in a file or directory. > >> If you want something which can do this and so much more, have a look at > >> pylint. > >> > >> http://www.logilab.org/projects/pylint > > > > Neat-looking tool, but not really usable for me. It counts physical lines, > > not logical lines; it doesn't seem to have an option to recursively scan > > all sub-directories and files in a directory; and it refuses to process a > > file if some of the modules code wants to import aren't importable, which > > is the case with mod_python code. > > pylint counts both physical lines and logical lines, but all collected > values are not displayed in reports. You should easily add a new report to > display some additional information if you need it. Well, it lacks some > documentation but the code is quite clean and I would be happy to help. > > It's also possible to recursivly scan for all python modules in a > given package ("pylint mypackage"). The problem with failing import is the > most annoying one. I plan to fix it, one day ;) > > -- > Sylvain Th?nault LOGILAB, Paris (France). > > http://www.logilab.com http://www.logilab.fr http://www.logilab.org > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > From webraviteja at yahoo.com Wed Aug 25 03:14:51 2004 From: webraviteja at yahoo.com (Ravi Teja Bhupatiraju) Date: 25 Aug 2004 00:14:51 -0700 Subject: age of Python programmers References: Message-ID: "Lucas Raab" wrote in message news:... > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... 27. Started at 15 (with a rather late acquired TRS-80). From hans at zephyrfalcon.org Fri Aug 20 21:52:44 2004 From: hans at zephyrfalcon.org (Hans Nowak) Date: Fri, 20 Aug 2004 21:52:44 -0400 Subject: Fate of lambda, Functional Programming in Python... In-Reply-To: References: <20040820163629.8DD4F1E401A@bag.python.org> Message-ID: <4126AAEC.7080304@zephyrfalcon.org> Anthony Baxter wrote: > First point: lambda, map, filter and reduce won't go away before Python 3.0, > at the very least. And, to be honest, I suspect map/filter/reduce are much more > likely to die than lambda, as they can nearly always be expressed more clearly > as listcomps or genexprs. People often lump reduce in with the rest, but there's really no easy way to express a reduce with list comprehensions. That said, for Python 3.0, these functions would probably be better off in a separate module with functional constructs, rather than disappearing entirely... -- Hans Nowak (hans at zephyrfalcon.org) http://zephyrfalcon.org/ From fakeaddress at nowhere.org Thu Aug 12 02:08:28 2004 From: fakeaddress at nowhere.org (Bryan Olson) Date: Thu, 12 Aug 2004 06:08:28 GMT Subject: Arranging a dependency tree In-Reply-To: <6ccff37a.0408111831.6eb25a4e@posting.google.com> References: <6ccff37a.0408111831.6eb25a4e@posting.google.com> Message-ID: Kyle Root wrote: > I've created a jumble of python modules, in each one is a tuple that > goes something like, > > deps = ("file10","file7","file3"). > > And some have no dependencies at all. I have one file called "start", > and the whole thing makes a tree of dependencies as each file has deps > and their deps might have deps, and so on. What I'm trying to do is > "straighten" them or put them in order as if they were to be > installed. Basically I'm trying to replicate the way portage does it. > :) [...] > Basically I was wondering if anyone had any tips or pointers, or knew > of any dependency resolving algorithms... This may be too abstract to help, but I guess it couldn't hurt... 'Depends' is a binary relation (a set of pairs) where (a, b) is an element of Depends if and only if b is in a's "deps" list/tuple. If you want an ordering in which each module follows the modules on which it depends, you want a 'topological sort' based on the depends relation. If you want to find all the modules on which a module depends, you want the 'transitive closure' of the depends relation. If you want to know if the dependencies can or cannot possibly work, look up the work of Bertrand Meyer and his Eiffel team on possibly-circular dependencies. -- --Bryan From Michael.J.Fromberger at Clothing.Dartmouth.EDU Fri Aug 13 10:10:01 2004 From: Michael.J.Fromberger at Clothing.Dartmouth.EDU (Michael J. Fromberger) Date: Fri, 13 Aug 2004 10:10:01 -0400 Subject: Why I love python. References: Message-ID: In article , Nick Patavalis wrote: > > At this moment Python is an excelent *glue* language for stuff written > in low-level laguages. It is also an exelent prototyping language. It > has a long way to go before becomming a true "production" language (in > the sense outlined above). Most of this way has to do with Python > *implementations* and not with Python-the-Language. But it seems that > there are some steps that must be taken by the language itself in > order to open the road to efficient implementations. Let me play the Devil's advocate for a moment here. Why is it important to write an entire program in a single language (e.g., Python), versus using a hybrid approach? If you can use Python at all, that means your platform already has good support for a C compiler, so there is no reason not to use C extensions if you really need performance. Now, perhaps you'll argue that C extensions are not as portable as Python ones. And yet, portability failures usually arise from differences in how you access hardware (e.g., graphics cards, audio hardware, input devices) or operating system API's, and those differences are going to crop up in Python as well. If you are going to have to write system-specific code anyway, and assuming you are very concerned about "high performance," you might as well just provide multiple C extensions to accommodate the difference, and let the Python glue code remain the same. By this view, I would argue that Python is a much better "production" language than many other languages currently being used in that role. It is no harder to write extensions for Python than to write native methods for Java (and, I would argue, easier for several common cases). Furthermore, Python can be stripped down and imbedded without too much pain, so that the developer is not forced to maintain a single monolithic code-base for their entire application in Python, simply to take advantage of a few of its powerful features. In short, I would argue that Python's ability to play nicely in a multipe-language development project is actually a sign of its maturity as a production tool. More cool languages are killed by their lack of ability to interface nicely with other cool languages, than all other reasons combined. -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From michael at foord.net Mon Aug 2 08:44:03 2004 From: michael at foord.net (Fuzzyman) Date: 2 Aug 2004 05:44:03 -0700 Subject: Making a socket connection via a proxy server References: <8089854e.0407300433.4c09bce0@posting.google.com> Message-ID: <8089854e.0408020444.4ee1eef2@posting.google.com> [snip..] > On another note: I assumed you wanted to transparently relay/rewrite HTTP > through the proxy. If you need to open some form of socket connection to the > proxy which is not HTTP, the proxy protocol supports the method CONNECT, > which will simply open up a socket connection which is relayed by the proxy. > But: This cannot be made transparent, except by some deeper magic in the > router. > > HTH! > > Heiko. Thanks for your help. It's only http that I'll be relayign and I only need it to be transparent to the user - I'm not using this for anonymity. I don't yet understand the detail of what you've said, but I am following hte resources you've suggested and now have enough to get to the next stage of my work. Thanks Fuzzyman http://www.voidspace.org.uk/atlantibots/pythonutils.html From __peter__ at web.de Thu Aug 19 14:55:45 2004 From: __peter__ at web.de (Peter Otten) Date: Thu, 19 Aug 2004 20:55:45 +0200 Subject: inverse of izip References: Message-ID: Steven Bethard wrote: > Peter Otten <__peter__ at web.de> wrote in message > news:... >> However, your sample data is badly chosen. Unless I have made a typo >> repeating your demo, you are getting the same (last) sequence twice due >> to late binding of i. >> > [snip] >> >>> map(list, starzip(it.izip("123", "abc"))) >> [['1', '2', '3'], ['a', 'b', 'c']] >> >>> x, y = starzip(it.izip("123", "abc")) >> >>> list(x) >> ['a', 'b', 'c'] >> >>> list(y) >> ['a', 'b', 'c'] >> >>> > > I knew there was something funny about binding in generators, but I > couldn't remember what... Could you explain why 'map(list, ...)' > works, but 'x, y = ...' doesn't? I read the PEP, but I'm still not > clear on this point. Maybe the following example can illustrate what I think is going on: import itertools as it def starzip(iterables): return ((t[i] for t in itr) for (i, itr) in enumerate(it.tee(iterables))) # the order of calls equivalent to map(list, starzip(...)) s = starzip(it.izip("abc", "123")) x = s.next() # the local variable i in starzip() shared by x and y # is now 0 print x.next(), print x.next(), print x.next() y = s.next() # i is now 1, but because no further calls to x.next() # will occur it doesn't matter print y.next(), print y.next(), print y.next() s = starzip(it.izip("abc", "123")) x = s.next() # i is 0 y = s.next() # i is 1 # both x an y yield t[1] print x.next(), print x.next(), print x.next() print y.next(), print y.next(), print y.next() You can model the nested generator expressions' behaviour with the following function - which I think is much clearer. def starzip(iterables): def inner(itr): for t in itr: yield t[i] for (i, itr) in enumerate(it.tee(iterables)): yield inner(itr) Note how itr is passed explicitly, i. e. it is not affected by later rebindings in startzip() whereas i is looked up in inner()'s surrounding namespace at every yield. Peter From jeff at ccvcorp.com Mon Aug 9 20:31:55 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Mon, 09 Aug 2004 17:31:55 -0700 Subject: decorators vs GIL In-Reply-To: References: <96c2e938.0408081605.706f8ec7@posting.google.com> Message-ID: <10hg5r1hr3g361a@corp.supernews.com> Jarek Zgoda wrote: >G. S. Hayes pisze: > > > >>>What really hurts is that I can't honestly tell Java programmers that >>> >>> >>>Python is a slam dunk compared to Java & the JVM. Java has no GIL, >>> >>> >> >>Java has drunk the threads Kool-Aid, and Java programmers are very >>likely to be thread-crazy because of the lack of a select equivalent >>(until recently) and the lack of good access to processes via fork or >>similar. Luckily, it's usually pretty easy to convince people of the >>benefits of NOT overusing threads once they've made that mistake once. >> >> > >Try GUI programming without using threads. > > I've done this plenty of times. Threads seem to only be essential when long-running background tasks are involved. There's a large set of GUI programs where this is not an issue. I've also never had GIL problems with multithreaded GUI apps. Then again, I'm not writing for multiprocessor machines. As I understand it, the GIL only becomes a real "problem" in the case of a multiprocessor machine running multithreaded code, and the "problem" is only that you get less-than-optimal efficiency. I would submit that the vast majority of Python applications run on single-processor machines, and that for many of the apps that *are* run on SMP it's not essential to run at theoretical-optimum efficiency. Multithreaded, multiprocessor applications where peak efficiency is necessary, threads can't be replaced by processes, and the use of C extensions (which don't suffer from GIL issues) is impractical make up a rather small section of the Python usage-base, and it's only those applications that see significant negative impacts from the GIL. Yes, it'd be great if the GIL wasn't necessary, but if eliminating it makes *my* single-proc, single-thread apps run significantly slower then the change is a net loss. Jeff Shannon Technician/Programmer Credit International From mwh at python.net Mon Aug 23 11:13:04 2004 From: mwh at python.net (Michael Hudson) Date: Mon, 23 Aug 2004 15:13:04 GMT Subject: 2 GB files References: <9418be08.0408221427.182a4d30@posting.google.com> Message-ID: elbertlev at hotmail.com (Elbert Lev) writes: > From postings to this group and other resources I understood that the > only way to make Python programs to work correctly with files lager > then 2 GB is building Python interpreter with some "magic spell" > defines. For me this is ABSOLUTELY unacceptable (Not the building, but > distributing and installing on dozens of computers in my > organisation). Then every time we switch to a new release of Python > this has to be repeated over and over! Did this post drop through a time warp from 2001? :-) You might want to check your facts more carefully before getting so angry. Cheers, mwh -- Java sucks. [...] Java on TV set top boxes will suck so hard it might well inhale people from off their sofa until their heads get wedged in the card slots. --- Jon Rabone, ucam.chat From dbickett at gmail.com Tue Aug 10 17:34:11 2004 From: dbickett at gmail.com (Beeyah) Date: 10 Aug 2004 14:34:11 -0700 Subject: Thread for a newbie References: Message-ID: <1d6cdae3.0408101334.30fac960@posting.google.com> justin__devine at hotmail.com (JDevine) wrote in message news:... > Hi. I have just finished my first python program. Unfortunately > threading has me stumped. I think this is mostly because the > wx.thread example demo is very complex, with all the grahphics, > graphs, and draw functions. I want to do something very simple. My > program downloads files over HTTP, I want to instantiate a process > dialog that tracks the download. I already have access to the > expected size of each file through other functions in my program, I > also assume an os.foo is capable of getting the current size as the > file grows as it is downloaded. My issue is keeping the file > downloading WHILE it is being tracked by the process dialog. Please > help with any simple thread examples you might have, if this example > includes a dialog even better. > Thanks for any help you can provide. > > -Justin > Justin__Devine at hotmail.com thanks import threading # not thread # to make your thread, # inherit the thread.Threading class, then # override the __init__ and run methods to define # what your thread is actually going to do, like so: class MyNewThread( threading.Thread ): def __init__( self , argument ): # generally speaking, the first argument of every # method should be self. in __init__'s case, the # following arguments are the values passed into the # thread upon creation, like so: # handle = MyNewThread( 1 ) # in this case, this will define the var 'argument' as '1' # to make these values accessible to the other methods, # make it an attribute of self self.arg = argument # at the end of init you should always call the following: thread.Threading.__init__( self ) def run( self ): # this function is called once you call MyNewThread.start() # once run() terminates, the thread goes with it. so just # define what you want your thread to do in this function. print repr( self.arg ) + " foo bar" # noteably useless handle = MyNewThread( 2832 ) handle.start() # now the thread's run() method is running Its important to note that, with the exception of the Queue object, manipulating an object by the hands of multiple threads is dangerous, and isn't recommended. if i messed something up someone correct me, thanks. Beeyah From cookedm+news at physics.mcmaster.ca Wed Aug 18 15:08:21 2004 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Wed, 18 Aug 2004 15:08:21 -0400 Subject: favorite python web development tool? References: <10i4nttktcvltdd@corp.supernews.com> Message-ID: At some point, Ksenia Marasanova wrote: >> i'm fairly new to python, coming from a java servlet / velocity >> template background. i'm looking for a good python web development >> tool, and hope to find some suggestions here. > > You may find this url interesting: > http://www.colorstudy.com/docs/shootout.html > > I use Quixote and for some projects also Quixote + HTMLTemplate > (http://freespace.virgin.net/hamish.sanderson/htmltemplate.html) I'll second Quixote and HTMLTemplate. Quixote gives a nice framework (handling requests, URL mapping, etc.), and HTMLTemplate does the separation of presentation and content. -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From dperl at rogers.com Tue Aug 31 23:53:40 2004 From: dperl at rogers.com (Dan Perl) Date: Wed, 01 Sep 2004 03:53:40 GMT Subject: initializing mutable class attributes References: <1gjc8cs.sqvo1v1fhabdjN%aleaxit@yahoo.com> <1gje9dn.r6jpetyroi0N%aleaxit@yahoo.com> Message-ID: <8JbZc.140699$UTP.23045@twister01.bloor.is.net.cable.rogers.com> "Alex Martelli" wrote in message news:1gje9dn.r6jpetyroi0N%aleaxit at yahoo.com... > ............ > > No one, including you, has given me a reason WHY __init__ is implemented > > this way. I am not bashing you for that, I would just still like to hear > > that 'WHY'. I'm sure that this implementation has some advantages. But, > > coming from a C++ and Java background, where parent default constructors are > > automatically invoked (well, not always, and that is something that users > > have to learn too), I find that that approach has some clear advantages. > > In this like in many other details, Python chooses simplicity and > clarity against automatic, black-magic, "behind the scenes" approaches. > "Explicit is better than implicit" is one part of the Zen of Python that > speaks to this -- at a python interactive prompt do > import this > to read it all. The automatic invocation of default constructors when > they exist, what you have to do instead to get different constructors > for parent classes, etc etc, are all complications. When classes are > designed to execute responsibilities it's not unusual that they can't > really have a useful no-arguments constructor -- and when they don't > have such a constructor, C++'s and Java's rules are nothing BUT overhead > and conceptual complication. In C++ one often works around the burden > of contraints on constructor calls via "two-phase constructors" -- a > default constructor that does not really leave the instance in a usable > state, just to bypass the darn rules you find "have some clear > advantages", and then a normal member function that really does the job > of initialization and has the enormous advantage that YOU decide when > and with what arguments to call it, without all the darn rules in the > way, explicitly. Well, in Python the constructor, __init__, is under > you control in exactly this way -- less complication, more simplicity, > more transparency, fewer rules to learn, and far fewer instances of the > "two-phase constructor" pattern (not zero, mind you -- just 99% fewer). This is the kind of answer I was hoping for. Actually, I was prepared to see a suggestion for solving the problem in a different way and there were a couple of them, even if the people suggesting them were themselves advising to prefer the original solution. When learning something, I need to understand the 'WHY' behind a design decision like that, when clearly there are alternatives. I will not be satisfied with an explanation of "that's the Python way and you just have to learn it". The explanation of choosing "explicit" instead of "implicit" makes sense and helps me in better understanding Python. I have to mention though that I do not accept "explicit is better than implicit" as an absolute truth. [That's like when someone told me once with pride: "I always design bottom-up."] Applying a principle like that CONSISTENTLY in the design of a language can make a very good language. On the other hand, I can imagine there can be very good languages, with their own uses and advantages, if the reverse principle were consistently used. You may see in another message I posted in this thread that I ended up giving an answer to my own question (the 'WHY' question). Here is my reason for that 'WHY'. Python does not have method overloading (and I am ok with that, because it comes with the dynamic typing), so you cannot have a default constructor and a non-default one at the same time. C++ and Java have overloading and then can also mandate a default constructor for a parent class, even if it's empty because you actually use only a non-default constructor for that class. Python cannot request that you also implement a default __init__ when you need a non-default one. There would be the possibility of adding another special method, but there's already __init__ and __new__, so that would be too confusing. I don't know whether that was an actual reason for the design even if it is definitely an obstacle. But the principle of "explicit instead of implicit" (I'll think of it that way) will help me to understand also other aspects of Python. And thank you for that. Dan From catcher at linuxmail.org Sat Aug 7 20:24:45 2004 From: catcher at linuxmail.org (Robert) Date: Sat, 7 Aug 2004 20:24:45 -0400 Subject: @decorator syntax is sugar, but for what exactly? References: Message-ID: I have read a few Python blogs and not a one is taking the decorator syntax in a good way. The Python of 1.5.2 simplicity will be long gone. From yk.suse at bullier.org Thu Aug 26 15:43:17 2004 From: yk.suse at bullier.org (Yann.K) Date: Thu, 26 Aug 2004 21:43:17 +0200 Subject: Mysql in Python? References: <2p6m32Fh7o9oU1@uni-berlin.de> <2p6nnpFhoue1U1@uni-berlin.de> Message-ID: Jeremy Jones wrote: >>I was a little konfused after reading the doku of mysql-python, because >>there the author says its better to use MySQLdb ;-) ?!?! > So, are you wanting a pure Python module to connect to MySQL? I'm not > sure there are any that exist. 10 seconds with google and maybe some leads: http://www.hk8.org/old_web/linux/sql/ch11_01.htm http://mysql.mirror.nedlinux.nl/downloads/python.html http://linux.maruhn.com/sec/mysql-python.html http://linux.com.hk/docs/mysql/manual_Clients.html#IDX2125 HTH. -- Yann.K From martin at v.loewis.de Thu Aug 26 17:12:45 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 26 Aug 2004 23:12:45 +0200 Subject: Best processor (i386) for Python performance? In-Reply-To: References: <789f72ac.0408251950.e85d23e@posting.google.com> <412d7e9d$0$26184$9b622d9e@news.freenet.de> Message-ID: <412E524D.3080800@v.loewis.de> Jeremy Sanders wrote: > Yes - AMD64 could be relevant if Python gets a speed boost from the extra > registers it has available. Yes, could be. OTOH, it is 64 bits, so it could also see a slow down because of the larger amounts of memory that needs to be moved for pointers and longs. Regards, Martin From ptmcg at austin.rr._bogus_.com Tue Aug 10 14:54:46 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Tue, 10 Aug 2004 18:54:46 GMT Subject: Python equivalent to a C trick References: <1d7b6d0d.0408092255.1177908e@posting.google.com> Message-ID: "Sam Holden" wrote in message news:slrnchgsml.8e4.sholden at flexal.cs.usyd.edu.au... > On 9 Aug 2004 23:55:08 -0700, Dan wrote: > > Is there a python equivalent of this trick in C? > > > > Logic_Test ? True_Result : False_Result > > > > Example: > > printf( "you have %i %s", num_eggs, num_eggs > 1 ? "eggs" : "egg" ); > > print "you have %i %s" % ( num_eggs, ("egg","eggs")[num_eggs>1] ) I would choose "!=" instead of ">" as the comparison operator. I think the accepted vernacular is: you have -2 eggs you have -1 eggs you have 0 eggs you have 1 egg you have 2 eggs you have 3 eggs you have 0.5 eggs ... -- Paul From peter.maas at mplusr.de Mon Aug 23 08:42:29 2004 From: peter.maas at mplusr.de (Peter Maas) Date: Mon, 23 Aug 2004 14:42:29 +0200 Subject: python usage In-Reply-To: References: Message-ID: Phanish schrieb: > Hi, One of my customer wants me to use Python as a test scripting > language. The architecture is as follows: An C++/Java UI obtains all > required inputs from the user and then makes call to Python script > which inturns calls c++ client stubs. These stubs are CORBA stubs > which talk to a CORBA server residing some where in the network. > I want to know as to whether it is feasible to use Python or just live > with c++ for UI and stubs? I would leave the UI untouched and implement the script and the CORBA stubs in Python. The advantage is that Python code requires less typing and is easier and more flexible as C++ code. It makes testing your ideas faster. But if you will be comfortable with Python is up to you. Try and see. -- ------------------------------------------------------------------- Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') ------------------------------------------------------------------- From olivierthiery at free.fr Tue Aug 3 09:15:44 2004 From: olivierthiery at free.fr (Olivier Thiery) Date: Tue, 03 Aug 2004 15:15:44 +0200 Subject: PyQT tutorial Message-ID: <410f8d35$0$31408$636a15ce@news.free.fr> Hello, Do you know any good and fairly complete tutorial about PyQT, Eric and QtDesigner ? Thank you, Olivier From Vincent.Raaijmakers at ge.com Wed Aug 4 10:53:10 2004 From: Vincent.Raaijmakers at ge.com (Raaijmakers, Vincent (GE Infrastructure)) Date: Wed, 4 Aug 2004 09:53:10 -0500 Subject: MySQLdb select Message-ID: <971323274247EB44B9A01D0A3B424C850B3EC650@FTWMLVEM02.e2k.ad.ge.com> Thanks, this worked! Vincent -----Original Message----- From: python-list-bounces+vincent.raaijmakers=ge.com at python.org [mailto:python-list-bounces+vincent.raaijmakers=ge.com at python.org]On Behalf Of Gerhard H?ring Sent: Monday, August 02, 2004 6:14 PM To: python-list at python.org Subject: Re: MySQLdb select Raaijmakers, Vincent (GE Infrastructure) wrote: > I'm so glad that this issue is raised here. > Can someone help me in this thread explaining me how to use multiple parameters. > Jaco helped me already a lot and perhaps someone in this thread can give me the final answer: > > My table contains a blob and a bigint for storing images. The table name is also a variable, so the query looks like: > SQL = "INSERT INTO %s (number, image) VALUES (%s, %s)" > > Well, I get a mysql exception if the execution looks like: > cursor.execute(SQL, (tableName, aValue, jpgImage)) > > The execution only works when I fill out the data until the blob value is a 'left over' as a %s: > Yes, this looks ugly.. but it works... > > SQL = "INSERT INTO %s (number, image) VALUES (%s," % (tableName, aValue) ## table name and number > SQL += "%s)" ## left over... only the image > cursor.execute(SQL, jpgImage) > > Can someone explain this to me? While the DB-API way of passing parameters was neatly explained in other posts in this thread, there are still some places where you need to construct SQL manually, like in your case, where you dynamically insert the name of the table into your SQL string. A proper way to solve this task is to do it in two steps (untested code): SQL = INSERT INTO %s (number, image) VALUES %%s, %%s" % tableName cursor.execute(SQL, (aValue, jpgImage)) Note that the first line only inserts the table name into the SQL string. Because we want to still have 'VALUES %s, %s' in the SQL string after applying the % operator, we escape the percent signs with an additional percent sign. Then, in the second line, you can let the DB-API do all the real passing of query parameters for you. -- Gerhard -- http://mail.python.org/mailman/listinfo/python-list From tim.peters at gmail.com Mon Aug 2 20:10:53 2004 From: tim.peters at gmail.com (Tim Peters) Date: Mon, 2 Aug 2004 20:10:53 -0400 Subject: Call for Grant Proposals In-Reply-To: <410ED411.7090907@acm.org> References: <40fcaa90$0$27091$9b622d9e@news.freenet.de> <41097fed$1@news.unimelb.edu.au> <410DF640.4010307@acm.org> <410DF824.8070309@acm.org> <410ED411.7090907@acm.org> Message-ID: <1f7befae0408021710dbb23c7@mail.gmail.com> [Maurice Ling, wants to know whether PSF grants require funded work to be open-sourced, etc] While I'm a PSF Director, I'm not on the Grants Committee and don't speak for them. I'll just note that since the PSF is a public charity (under US tax law), there are a lot of rules the PSF has to comply with when distributing its funds. I expect that answering your questions will require paying a lawyer to spell out what's possible. I don't know what they'll say. In general, the PSF is required to act in the public interest. That said, the PSF doesn't have a ton of money, and there will almost certainly be more worthy requests for funding than there are funds to pass out. Proposals will therefore compete. If I were on the Grants Committee, whether a proposal would benefit the public at large would be a major consideration for me. IOW, I think it's predictable-- and appropriate --that proposals to fund open-source work will "score points" for that reason alone. From alexis.roda at urv.es Fri Aug 20 06:19:01 2004 From: alexis.roda at urv.es (Alexis Roda) Date: Fri, 20 Aug 2004 12:19:01 +0200 Subject: esoteric question about dict keys (Re: age of Python programmers) Message-ID: <4125D015.9090204@urv.es> This is my first message to the list, so I'll present myself and add my contribution to the "age of python programmes" thread. My name is Alexis Roda, I'm 36 - 7/365 years old, I started programming with python two years ago, mainly because I started playing with zope. At first I was a reluctant Perl converted, although initially I hated python (well, I hated zope wich make me hate python) now I'm in love with both python and zope. I started programming at 15 with a Casio calculator (a kind of assembler), then an Amstrad CPC464 (Basic), a Macintosh Plus (Pascal, C, Lisp, assembler) and finally come to the PC/Linux world (assembler, C, C++, Perl, bash scripting, elisp and python). Now the question. In "normal" dicts its not possible to use dictionaries (nor other kinds of mutable objects) as keys, if I undersand correctly this is a technical requirement. If I write my own dictionary-like object, on wich the mutability of the keys is not a technical issue, is considered blasphemous the use of dicts as keys? For example, querying an SQL table can be partially modelled as a dictionary access: table[pkey_value] gives a record for this primary key table[{'somefield':somevalue}] returns all the records where somefield=somevalue or is preferable to define a query() method for these uses and restrict __getitem__ to mutable objects for the sake of consistency? TIA -- //// (@ @) ----------------------------oOO----(_)----OOo-------------------------- <> Ojo por ojo y el mundo acabara ciego /\ Alexis Roda - Universitat Rovira i Virgili - Reus, Tarragona (Spain) ----------------------------------------------------------------------- From sbabbitt at commspeed.net Sat Aug 28 10:22:24 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Sat, 28 Aug 2004 07:22:24 -0700 Subject: Dynamic languages References: <278de0e.0408271349.26762174@posting.google.com> <1093650026.763899@news.commspeed.net> <98862c6.0408280531.6064d510@posting.google.com> Message-ID: <1093703465.236222@news.commspeed.net> "Marcel van den Dungen" wrote in message news:98862c6.0408280531.6064d510 at posting.google.com... > "Tom B." wrote in message news:<1093650026.763899 at news.commspeed.net>... > > I doubt that this is what they mean but a dynamic language is a language > > that is still evolving (Python) as opposed to a dead language (COBOL). > > > > They probably are referring to programs that can add and remove components > > during runtime. > > Dynamic refers to the typing of variables. In Python variables get a > type dynamically when assigned a value. > See also: http://www.artima.com/weblogs/viewpost.jsp?thread=4639 > and several blog posting of Bruce Eckel on this subject: > http://www.mindview.net/WebLog/ > > Marcel. Those languages are called dynamically typed languages, this implies that there is a statically typed language, which there is. All languages are dynamic, this slang is bad computer science. There is no such thing as a static computer language. Tom From ben at benlast.com Wed Aug 18 02:41:45 2004 From: ben at benlast.com (Ben Last) Date: Wed, 18 Aug 2004 07:41:45 +0100 Subject: Databases: Getting values by column name In-Reply-To: <899f842.0408170957.13719032@posting.google.com> Message-ID: > From: python-list-bounces+ben=benlast.com at python.org > [mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of > Anthony_Barker > what about db_rows? An excellent suggestion, as were the points about MySQLdb's DictCursors; I thought it appropriate to try and show that the database API in *general* does include what's needed (i.e., the cursor.description attribute). I suspect this particular wheel has been reinvented many times :) Something I noted, but forgot to mention (and which is worth mentioning for anyone who googles their way into this thread in the future) is that non-column selects (such as SELECT COUNT(*) or SHOW TABLES or DESCRIBE) return descriptions whose field names may or may not be what you expect (for example, a SHOW TABLES returns a field name "Tables_in_x" where x is the name of the database). b ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ From steven.bethard at gmail.com Thu Aug 19 03:04:45 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 19 Aug 2004 01:04:45 -0600 Subject: inverse of izip In-Reply-To: <41244ABC.5020704@zeomega.com> References: <41244ABC.5020704@zeomega.com> Message-ID: On Thu, 19 Aug 2004 12:07:48 +0530, Satchidanand Haridas wrote: > > >>> a = itertools.izip(*itertools.izip(range(10),range(10))) > >>> a > > > >>>a.next() > (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) > >>> a.next() > (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) > >>> a.next() I'm assuming you popped this one off without actually reading my email. No worries - it happens some times. You'll note however, that this is exactly what I said didn't work: Steven Bethard wrote: >>>>x, y = itertools.izip(*itertools.izip(range(10), range(10))) >>>>x, y >((0, 1, 2, 3, 4, 5, 6, 7, 8, 9), (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)) > >But then I get a pair of tuples, not a pair of iterators. Basically, >I want to convert an iterator of tuples into a tuple of iterators. I want the elements returned by the itertools.izip object to be iterators, not tuples or lists. Steve -- You can wordify anything if you just verb it. - Bucky Katt, Get Fuzzy From com-nospam at ccraig.org Tue Aug 10 12:42:08 2004 From: com-nospam at ccraig.org (Christopher A. Craig) Date: 10 Aug 2004 12:42:08 -0400 Subject: Secure storage for passwords for admin scripts? References: Message-ID: mksql at yahoo.com (Max) writes: > I have a collection of system admin scripts (on Win 2k) that I would > like to automate the execution of. However, some of them require the > use of logins with admin rights, and would therefore prefer not to > store the IDs in the clear text of the source. If memory serves > correctly, the "compiled" .pyc files do not provide much security in > this area. > > Are there are recommended methods for supplying scripts with login > information in a secure fashion? You cannot store passwords in a secure fashion and extract them automatically. If there is an algorithm for extracting them (and worse the algorithm is in the script) then they aren't secure. -- Christopher A. Craig "The problem with X is that it's overadequate" Dennis Ritchie From donn at u.washington.edu Tue Aug 17 12:41:43 2004 From: donn at u.washington.edu (Donn Cave) Date: Tue, 17 Aug 2004 09:41:43 -0700 Subject: music resources References: <1qfUc.128080$gE.84239@pd7tw3no> Message-ID: In article <1qfUc.128080$gE.84239 at pd7tw3no>, "Elaine Jackson" wrote: > Thanks for your suggestions. What I want to do with music is to learn it and > play with it. Even an auditory equivalent of "MS Paint" would probably keep > me > busy for some time, since I'm essentially starting from zero. I think I'd recommend a ukelele, really. Music happens in a different part of the brain, and I think you're better off starting right there and moving on to the symbols and tables later. It isn't just pop science, there's really something to it - I know when I'm playing something that leaves my mouth free, people try to talk to me, and I can look at them and understand at some level, but there's no way I can get the words together for a response, because that part of my brain is taking a break for the moment. Never tried to think about computer programming in that state, but I'm rather sure it would be useless. It's hardly short of a crime that masses of young people come out of the school system every year with the ability to render a tune from sheet music like a player piano but with barely any personal sense of music, just because we only know how to start there and teach them to see a note, play a note. I have never actually played a ukelele, it's just an inexpensive and approachable instrument capable of playing several notes at once and with strong rhythmic potential (cf. its close relative the Brazilian cavaquinho for more on that perspective.) Donn Cave, donn at u.washington.edu From FBatista at uniFON.com.ar Wed Aug 25 11:36:24 2004 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Wed, 25 Aug 2004 12:36:24 -0300 Subject: Floating point weirdness Message-ID: [Joshua Ginsberg] #- >>> float('19.95') #- 19.949999999999999 #- >>> round(19.94999999999999999, 2) #- 19.949999999999999 #- >>> round(19.949, 1) #- 19.899999999999999 #- #- Why can't I just get 19.95? >From the Python FAQs: http://www.python.org/doc/faq/general.html#why-are-floating-point-calculatio ns-so-inaccurate You maybe want to use Decimal (will be available in Py2.4). If you want theory about this, you should consider reading the PEP 327: http://www.python.org/peps/pep-0327.html Regards, . Facundo From newsgroups at jhrothjr.com Fri Aug 6 07:42:23 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 6 Aug 2004 07:42:23 -0400 Subject: PEP 263 status check References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> <10h5hgvpafm8a64@news.supernews.com> <41133C76.8040302@v.loewis.de> Message-ID: <10h6rklt3fa1690@news.supernews.com> "Martin v. L?wis" wrote in message news:41133C76.8040302 at v.loewis.de... > John Roth wrote: > > My specific question there was how the code handles the > > combination of UTF-8 as the encoding and a non-ascii > > character in an 8-bit string literal. Is this an error? The > > PEP does not say so. If it isn't, what encoding will > > it use to translate from unicode back to an 8-bit > > encoding? > > UTF-8 is not in any way special wrt. the PEP. That's what I thought. > Notice that > UTF-8 is *not* Unicode - it is an encoding of Unicode, just > like ISO-8559-1 or us-ascii (although the latter two only > encode a subset of Unicode). I disagree, but I think this is a definitional issue. > Yes, the byte string literals > will be converted back to an "8-bit encoding", but the 8-bit > encoding will be UTF-8! IOW, byte string literals are always > converted back to the source encoding before execution. If I understand you correctly, if I put, say, a mixture of Cyrillic, Hebrew, Arabic and Greek into a byte string literal, at run time that character string will contain the proper unicode at each character position? Or are you trying to say that the character string will contain the UTF-8 encoding of these characters; that is, if I do a subscript, I will get one character of the multi-byte encoding? The point of this is that I don't think that either behavior is what one would expect. It's also an open invitation for someone to make an unchecked mistake! I think this may be Hallvard's underlying issue in the other thread. > Regards, > Martin John Roth From fakeaddress at nowhere.org Tue Aug 10 22:48:43 2004 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 11 Aug 2004 02:48:43 GMT Subject: Fixing socket.makefile() In-Reply-To: References: Message-ID: Donn Cave wrote: [...] > I don't get this. Has socket.py changed this much since 2.2? > The readline I'm looking at says self._sock.recv(self._rbufsize), > so you would only get this behavior if you specified a buffer > size of 1 or less, and read() does the same - so you could do > this to yourself, but not specially just with readline. Hi Donn; yes, looks like I got confused on that one. > At any rate, I think it would put this in better perspective > to recall that pipes, terminals and in general any "slow" > device has the same issues, and that they work out the same > in Python as in the original C, with socket file descriptors > in place of socket objects and stdio file pointers in place > of file objects. And it gets worse. I've seen layered handlers with buffers of buffers of buffers. > It's definitely a problem, and some kind of solution might be > well received, but it needs to be portable (so forget MSG_PEEK > unless you're really confident that it will be supported on > every platform that now supports sockets to some useful degree), Hold on ... Gooogle...Google...Google... Well, support for MSG_PEEK seems to be universal except for a couple reported bugs and versions of BeOS without BONE (BeOS Network Environment). I've never used BeOS, but apparently BeOS'ers are used to the idea that they need BONE to get network stuff working. Actually testing against the wide range of platforms is beyond my own capabilities. > and it would be nice to apply to the problem in general and > not just sockets. Agreed, but for now I'd like to call that out-of-scope. I came upon this particular problem when writing an HTTP/1.1 thingy. The socket module works well, but I found the higher-level library classes not-so-useful. > I think the root of the problem really is that > select() doesn't look at process buffers in fileobject instances, > and it can't be made to do that because that information isn't > available from the stdio file pointer underneath the fileobject. > So, you need a replacement for fileobject, to start with. Really we want a general, portable, extensible event-handler. It should to be unified with all the asynchronous things, such as socket/file activity, thread locks and semaphore, and GUI event loops. -- --Bryan From jpmorichon at earthlink.net Fri Aug 13 13:16:29 2004 From: jpmorichon at earthlink.net (CptPicard) Date: Fri, 13 Aug 2004 17:16:29 GMT Subject: blocking file.readlines() needed References: Message-ID: Geoff Howland has written a script, LogReader.py, that should give you some hints on how to do your "tail -f". http://unixnaut.com/skills/Languages/python/ Using google, I also found some talks about that. Here is one of the solution that I found : import sys,os import time from Tkinter import * from ScrolledText import ScrolledText class LogViewer(Frame): def __init__(self, parent, filename): Frame.__init__(self,parent) self.filename = filename self.file = open(filename, 'r') self.text = ScrolledText(parent) self.text.pack(fill=BOTH) data = self.file.read() self.size = len(data) self.text.insert(END, data) self.after(100, self.poll) def poll(self): if os.path.getsize(self.filename) > self.size: data = self.file.read() self.size = self.size + len(data) self.text.insert(END, data) self.after(100,self.poll) if __name__ == "__main__": root = Tk() viewer = LogViewer(root, sys.argv[1]) viewer.mainloop() "Uwe Mayer" wrote in message news:cfiqlr$3a8$1 at news2.rz.uni-karlsruhe.de... > Hi, > > I am looking for a way to make the call to a file objects readline() method > blocking when there is no more data, until data is appended to the file, > similar to the way > > $ tail -F > > works. > > However, file.readlines() aborts and returns an empty list. > > Any ideas? > > Thanks > Ciao > Uwe > From steven.bethard at gmail.com Thu Aug 12 16:52:02 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: 12 Aug 2004 13:52:02 -0700 Subject: decorator syntax polling suggestion Message-ID: The poll, as stated, asked voters to vote for the syntax suggestion they liked the /most/. Some of the conclusions people are trying to draw from it are what syntaxes people liked the /least/. This is probably not the right conclusion to be drawing from the poll that was given. It is, however, the kind of conclusion I think we'd like to draw. I'm not sure we're going to agree fully on a single "best" proposal, but it would help to get rid of any proposals that are overwhelmingly dispreferred. So I suggest a new poll of which syntax suggestions people like the /least/. I know that GvR is not interested in polls (and probably rightfully so), so I suggest this only as a means of directing our discussion -- if an overwhelming majority dislikes a certain option, we can stop discussing it, and focus on the remaining options. I think it's also important not to limit the options so much. I didn't vote at the last one because I didn't like any of the options. I'd actually propose 4 different polls, based on the syntax breakdown in the wiki: Indicator: * keyword * symbol * function * none Location: * pre-def * on same line, preceding def * between def and function name * between function name and argument list * between argument list and colon * at beginning of function body List notation: * one per line * commas only * as list * as tuple Indentation: * indent decorators and def * indent only decorators * none I think it should be pretty easy for us to throw out some of these options pretty quickly. (For example, I haven't seen much support for "Location: between function name and argument list".) Does this seem like a better polling strategy? If so, can someone post such polls somewhere? Steve From agriff at tin.it Thu Aug 26 02:05:53 2004 From: agriff at tin.it (Andrea Griffini) Date: Thu, 26 Aug 2004 06:05:53 GMT Subject: Proposal for removing self References: <938a4680.0408252123.4d71432e@posting.google.com> Message-ID: On 25 Aug 2004 22:23:46 -0700, rattan at cps.cmich.edu (Ishwar Rattan) wrote: >I concur for keeping self intact, it does provide clarity in code writing >and reading. I remember Alex Martelli advocating in our italian newsgroup on C++ that C++ programmers should use "this->..." everywhere :-) Seemed crazy to me at that time, but now after giving a try to python I've to say that self-consciousness isn't bad. Andrea From anthonybaxter at gmail.com Fri Aug 13 03:21:38 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 13 Aug 2004 17:21:38 +1000 Subject: Why I love python. In-Reply-To: References: Message-ID: On 13 Aug 2004 06:54:11 GMT, Sam Holden wrote: > I've also been doing rtp voice in python - on an iPAQ H3800... I'm using > your rtp.py code (I'm not doing sip), so I can't take credit for it > though :) > > I dont know if it's "more than fast enough", but it's "fast enough". Neat! Well, on that sort of extremely limited hardware, it's not suprising that it's more of a struggle. Someone else got the full shtoom working on WinCE or similar. From martin at v.loewis.de Fri Aug 6 05:47:15 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 06 Aug 2004 11:47:15 +0200 Subject: Proposal: require 7-bit source str's In-Reply-To: References: <4112AC7B.1060508@v.loewis.de> <411343D7.3020604@v.loewis.de> Message-ID: <411353A3.8090502@v.loewis.de> Hallvard B Furuseth wrote: >>The coding declaration was only acceptable because >>- a statement would have to go before the doc string, in >> which case it would not have been a docstring anymore, and > > > Hmm... You misunderstood. I was talking about the module docstring "Written by Martin v. L?wis" directive encoding "utf-8" Here, the declaration comes after the first non-ASCII character, which does not work. directive encoding "utf-8" "Written by Martin v. L?wis" Here, the string is not a docstring anymore, because it is not the first expression in the module. > >>> help(bar) > Traceback (most recent call last): > ... > UnicodeEncodeError: 'ascii' codec can't encode character '\uf8' > in position 59: ordinal not in range(128) That's a bug in the help function. > Even if the doc string is written in English, it may still need to > use non-English names. Certainly. This is why the encoding declaration can't be a statement. > Still, how about 'directive str7bit', 'directive -W::str7bitWarning' or > something? See PEP 244. I would have liked a directive statement, but the PEP was rejected (in favour of __future__ imports, at that time). A future import might work, except that this is a commitment that the future comes some day, which, for str7bit, would not be the case: there will *always* be a possibility to put non-ASCII bytes into 8-bit strings (of course, requiring that people use escape sequences for them might be acceptable). In any case, you probably have to write a PEP for this. Regards, Martin From miki.tebeka at zoran.com Tue Aug 10 08:55:59 2004 From: miki.tebeka at zoran.com (Miki Tebeka) Date: Tue, 10 Aug 2004 14:55:59 +0200 Subject: Is there something else but Automake? In-Reply-To: References: Message-ID: <20040810125559.GC2636@zoran.com> Hello Magnus, > I am currently using Automake to make distributable tar-balls of my > application. Is there something else (hopefully better) that I can use? You might want to have a look at SCons (http://www.scons.org). Great tool and written in Python, you can also use any Python code inside the configuration files. Bye. -- ------------------------------------------------------------------------ Miki Tebeka http://tebeka.spymac.net The only difference between children and adults is the price of the toys From pythongnome at hotmail.com Sun Aug 29 19:25:09 2004 From: pythongnome at hotmail.com (Lucas Raab) Date: Sun, 29 Aug 2004 23:25:09 GMT Subject: Installation of mod_python 3.1.3 on Apache 2.0.50 on Windows Me/Win2k References: <39cbe663.0408290850.14452ab9@posting.google.com> Message-ID: Why not post this to the mod_python mailing list?? "Piet" wrote in message news:39cbe663.0408290850.14452ab9 at posting.google.com... > Hi there, > I cannot install mod_python v3.1.3 on either Win2k/ActivePython 2.3.2 > or WinMe/Python 2.3.4. When I run the Windows installer, I get the > following error message: > Traceback (most recent call last): > File "C:\Programme\Python23\Scripts\win32_postinstall.py", line 86, > in ? > apachediroptions = getApacheDirOptions() > File "C:\Programme\Python23\Scripts\win32_postinstall.py", line 45, > in getApacheDirOptions > apachekey = regkey(win32con.HKEY_LOCAL_MACHINE, > "Software").childkey("Apache Group").childkey("Apache") > File "C:\Programme\Python23\Scripts\win32_postinstall.py", line 34, > in childkey > return regkey(self.key, subkeyname) > File "C:\Programme\Python23\Scripts\win32_postinstall.py", line 32, > in __init__ > self.key = win32api.RegOpenKey(parent, subkeyname) > pywintypes.error: (2, 'RegOpenKeyEx', 'Das System kann die angegebene > Datei nicht finden.') > Exception exceptions.AttributeError: "regkey instance has no attribute > 'key'" in 0x00CF1440>> ignored > *** run_installscript: internal error 0xFFFFFFFF *** > I checked the registry and found that the key mentioned in the error > message does indeed not exist. Is this a failure in my apache > configuration/installation or is the installation package of > mod_python incorrect? Are there any experiences with the > abovementioned configuration? > Thanx in advance > Peter From chrisdewinN0SPAM at yahoo.com.au Wed Aug 25 15:46:00 2004 From: chrisdewinN0SPAM at yahoo.com.au (Dfenestr8) Date: Thu, 26 Aug 2004 04:46:00 +0900 Subject: Capturing exceptions? References: <4u3vv1-vkg.ln1@valpo.de> Message-ID: On Wed, 25 Aug 2004 20:55:31 +0200, Mathias Waack wrote: >> On Wed, 25 Aug 2004 19:19:06 +0200, Mathias Waack wrote: >> >>> Dfenestr8 wrote: >>>> What's the easiest way to capture the traceback from an exception, and >>>> write it to a file? Ideally, I'd like to be able to do something like: >>>> >>>>>try: >>>>>main() >>>>>except: >>>>>write the traceback to a file >>> >>> Have a look at the traceback module. >>> >>> Mathias >> >> I did. Thanx. But I'm afraid I don't understand it. > > import traceback > try: raise Exception, "python is so cool;)" except: > traceback.print_exc(None,file("exc.trc","w")) > > Does it that what you want? > > Mathias yep. Should do. Thanx. PS: Still would like to know what kind of parameter that other method wants. From artur_spruce at yahoo.com Mon Aug 9 11:59:37 2004 From: artur_spruce at yahoo.com (AdSR) Date: 9 Aug 2004 08:59:37 -0700 Subject: How do you feel ? References: Message-ID: artur_spruce at yahoo.com (AdSR) wrote in message news:... > > I tried Common Lisp, but > online tutorials are very basic, and online reference is hard to > navigate; I still don't know what "#" and "," mean. > A short update after a few nice people sent me some helpful info: Common Lisp is an impressively powerful language, but I still prefer Python's straightforwardness and its more practical (think re, xml, Tkinter modules) standard library. It fits my brain and my job better. An interesting comparison, if you want to check it for yourself, is one between the unittest module and what is described on this page: http://www.gigamonkeys.com/book/practical-building-a-unit-test-framework.html Both approaches are based on commonly used features and coding style of their respective languages. I think this is good example of how language vs. language comparisons should be done. AdSR From duncan.booth at invalid.invalid Thu Aug 19 11:08:36 2004 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 19 Aug 2004 15:08:36 GMT Subject: age of Python programmers References: Message-ID: "Lucas Raab" wrote in news:jQHUc.1529$2L3.505 at newsread3.news.atl.earthlink.net: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? My average age is 21. My actual age is rather more. From anthonybaxter at gmail.com Mon Aug 23 13:08:12 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Tue, 24 Aug 2004 03:08:12 +1000 Subject: J2 proposal: keyword In-Reply-To: <20040823165129.GC8036@titan.progiciels-bpi.ca> References: <3A81C87DC164034AA4E2DDFE11D258E3022E26@exchange.hqamor.amorhq.net> <20040823165129.GC8036@titan.progiciels-bpi.ca> Message-ID: On Mon, 23 Aug 2004 12:51:29 -0400, Fran?ois Pinard wrote: > [Robert Brewer] > > > III. Choosing a keyword > > > If a keyword is to be chosen over @ or other punctuation, the question > > remains, "which word should it be?" [...] The keyword [...] should not > > be a word with a planned future. This rules out "with" and "as" > > All the contrary, being a word with a planned future may be an advantage, as > long as using that word makes enough sense in itself, and given the syntax we > use have no chance of clashing with the planned syntax. > > This might rule out "as" because not meaningful enough, but "with" might > be pertinent enough for being used -- yet I'm not fully sure. The word > "using" is surely not bad either :-), but would be yet another keyword. Guido already has plans for 'with'. Using it in decorators would cause confusion and ambiguity, e.g. with foo: .baz = 1 .banana(monkey=True) def someentirelyunrelatedfunction(args): .... with: frobozulate mangle(totally=True) def decoratedfunction(arg): .... Guido's already ruled out using 'as' in the context of decorators, and I agree - don't overload keywords (or even, in the case of 'as', not-really-keywords). In addition, 'as' already has plenty of other meanings in, for instance, SQL, that are entirely unlike the meaning envisaged here. From jpmorichon at earthlink.net Thu Aug 5 11:43:24 2004 From: jpmorichon at earthlink.net (CptPicard) Date: Thu, 05 Aug 2004 15:43:24 GMT Subject: Need help on how to use Pymedia! References: <3x8w4pqd3emo.15wp1jkrwkqua.dlg@40tude.net> Message-ID: Thank you for your help! "Lawrence Oluyede" wrote in message news:3x8w4pqd3emo.15wp1jkrwkqua.dlg at 40tude.net... > In data Thu, 05 Aug 2004 02:28:48 GMT, CptPicard ha scritto: > > > Could someone give me a more detailed documentation on pymedia or some clues > > on how to get the information I need ? > > AFAIK Pymedia cannot extract ID3 infos from MP3 (altough you can study by > yourself the ID3 format a inspect the raw info of the file), anyway the web > is full of ID3 tools for python such as: > http://id3-py.sourceforge.net/ > > bye! > > -- > Lawrence (l dot oluyede at virgilio dot it) > "In IE we trust" From PeterAbel at gmx.net Mon Aug 2 13:08:19 2004 From: PeterAbel at gmx.net (Peter Abel) Date: 2 Aug 2004 10:08:19 -0700 Subject: MySQLdb select References: <9RPOc.2792$LI7.1058@newssvr27.news.prodigy.com> Message-ID: <21064255.0408020908.41357e52@posting.google.com> John Fabiani wrote in message news:<9RPOc.2792$LI7.1058 at newssvr27.news.prodigy.com>... > thanks that worked but I don't understand why. > cursor.execute("SELECT * FROM mytest where address = %s",string1) > above works but - following your suggestion: > cursor.execute("SELECT * FROM mytest where address = %s" % string1) > above does not work. So why did > cursor.execute("SELECT * FROM mytest where clientID = %d" % numb) > work??????????????? > john > F. GEIGER wrote: > >>> numb=10 >>> "SELECT * FROM mytest where clientID = %d",numb ('SELECT * FROM mytest where clientID = %d', 10) The result of the above is a tuple, where the first value is a string and the second one is an int. So you call cursor.execute (..) with a two values. The first value is 'SELECT * FROM mytest where clientID = %d' which raises the exception because %d is never an int. What you wanted to do is to call cursor.execute (..) with one parameter, which is a string. So as ohers pointed out you have to use Python's formatting features to get the desired string: >>> "SELECT * FROM mytest where clientID = %d" % numb 'SELECT * FROM mytest where clientID = 10' Even if your first example works from the point of view of SQL it wouldn't give you the results, you want. >>> string1='18 Tadlock Place' >>> "SELECT * FROM mytest where address = %s",string1 ('SELECT * FROM mytest where address = %s', '18 Tadlock Place') That means again, your'e calling cursor.execute (..) with two parameters where the first one - again - is 'SELECT * FROM mytest where address = %s' So youre SQL-result should be empty, cause you surely don't have an adress with the value %s. So formatting it the right way and adding single quotmarks araound string1 will give you the result you want: >>> "SELECT * FROM mytest where address = '%s'" % string1 "SELECT * FROM mytest where address = '18 Tadlock Place'" >>> Regards Peter > > > > "John Fabiani" ... [snip] From squirrel at WPI.EDU Thu Aug 5 13:12:40 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 5 Aug 2004 13:12:40 -0400 Subject: RELEASED Python 2.4, alpha 2 In-Reply-To: References: <411231C8.3020308@interlink.com.au> Message-ID: On Fri, 6 Aug 2004, Anthony Baxter wrote: > On Thu, 5 Aug 2004 12:29:51 -0400, Christopher T King wrote: > > What does one do if a decorator raises an exception? > > def deco(func): > raise TypeError > > @deco > def foo(): > print "hello" Yes yes yes, I /know/ they are /able/ to raise exceptions. My point was about handling them in a clean, concise way. > Silently failing is completely non-pythonic. Then let's say you want to print a warning, "Warning, type checking not installed!" > If you really wanted to handle a missing decorator, something like > missingdec = lambda x:x would do this for you. Ick. That doesn't fix the general case (though I admit it wouldn't come up too often). > > Decorators in general are the right solution for the wrong problem (as I > > detailed in another thread). They are being introduced much too > > prematurely, and have not been given time to be able to have been thought > > through well enough. The @ syntax is the result of trying to shoehorn too > > many solutions into one fix. > > Too prematurely?? staticmethod and classmethod were introduced in 2.2! I'm referring to the syntax, not the decorators themselves. > PyObjC, ctypes, Jython and IronPython can all do with using them, as can > rather a lot of other chunks of code. Anything that applies metadata to > functions can use this - look at all the various places where people are > putting stuff in docstrings as a current hack. Anything that applies metadata to functions can use function attributes much more effictively. They're cleaner, more to the point, and are likely to have much less backlash than @. Example of a previous function attribute proposal: def foo(a,b,c): .accepts = (int,int,int) .returns = str pass > Or, alternately, they're another tool in the toolbox, along with > metaclasses and the like. It just so happens I'm not a big fan of metaclasses, either ;) From kylotan at hotmail.com Wed Aug 18 20:37:23 2004 From: kylotan at hotmail.com (Kylotan) Date: 18 Aug 2004 17:37:23 -0700 Subject: firefox extension References: <41230bcc$0$3897$4d4ebb8e@news.nl.uu.net> Message-ID: <153fa67.0408181504.283551f4@posting.google.com> "Guyon Mor?e" wrote in message news:<41230bcc$0$3897$4d4ebb8e at news.nl.uu.net>... > is it possible to create a firefox extension in python? I believe Firefox extensions are coded in Javascript. Download one and take a look (they're zip files, basically). -- Ben Sizer. From wweston at att.net Sun Aug 15 23:40:59 2004 From: wweston at att.net (wes weston) Date: Mon, 16 Aug 2004 03:40:59 GMT Subject: random / lists In-Reply-To: References: Message-ID: M. Clift wrote: > Hi Wes, > > Thanks for responding. > > What I want is a system that controls the direction in a generated list. If > the user selects a number a letter is choosen for each number from at random > from an array. That's fine and easy to do. The hard part is, is that no > letter can be repeated with only one letter interveining and the letters can > only follow each other under certain rules. > > These being : > 1. 'a' can be followed by any letter > 2. 'b' can only be followed by 'c' > 3. 'c' can be followed by 'a' or 'd' > 4 'd' can be followed by 'a' or 'c' > > Really it doesn't matter what these rules are for the time being it's just > working out a way to control the outcome of a list of unknown size. I've > experimented with lists of say up to 10 long using ' if ' statements for > each number and different array depending upon the previous letter, but as > you can imagine it is no good for larger lists as the code just goes on and > on : ). Rather than I have done before, whereby I said if letter 3 == 'a' > then letter 4 = choice(bcd) is it possible to say if previous letter equals > whatever then this letter equals whatever? > > Wes, if you recieved an email direct to you address I'm sorry. I must > be tierd, as for some reaon I've been hitting the reply button all night > instead of the reply to group! > > Thanks > > Clift, I think in your loop you need to have a variable, call it previousLetter, to test the latest letter against. previousLetter = None for x in range(someNum): newLetter = someSelection() if not previousLetter or someTestOk( previousLetter, newLetter ): doYourStuff() previousLetter = newLetter You might need this in your test: >>> ord("c") 99 to test if a character follows and by how much. wes wes From Brian.Inglis at SystematicSW.Invalid Sun Aug 29 02:58:30 2004 From: Brian.Inglis at SystematicSW.Invalid (Brian Inglis) Date: Sun, 29 Aug 2004 06:58:30 GMT Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: <25u2j0d9bfulqljo6d2jbls2v52l1jk3sd@4ax.com> On Sat, 28 Aug 2004 20:59:08 -0700 in alt.folklore.computers, Mac wrote: >On Wed, 25 Aug 2004 14:56:06 -0700, Xah Lee wrote: > >> Larry Wall and Cults >> (Lazyness, Impatience and Hubris) >> 200012 >> Surely you have heard of Adolf Hitler >> and his atrocities of genocide? I must alert you, that a single person >> couldn't commit such a crime. > >Wow, Godwin's law invoked on the first post of the thread. Not quite, no comparison was made; see: http://groups.google.com/groups?as_umsgid=1991Oct22.140831.23313%40eff.org -- Thanks. Take care, Brian Inglis Calgary, Alberta, Canada Brian.Inglis at CSi.com (Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]ca) fake address use address above to reply From DrColombes at yahoo.com Tue Aug 10 12:03:00 2004 From: DrColombes at yahoo.com (Dr. Colombes) Date: 10 Aug 2004 09:03:00 -0700 Subject: Plotting histograms, scatter plots in Python References: Message-ID: John, Peter et al: Thanks very much for your useful tips on MathPlotLib. I've begun using MatPlotLib and I like it. Others suggested GnuPlot, which I hope to try sometime in the future. Thanks all. This is a good example of very useful information exchanged over an Internet newsgroup. Dr. Colombes John Hunter wrote in message news:... > >>>>> "Colombes" == Colombes writes: > > Colombes> What is the easiest way to generate some plots and > Colombes> graphs in Python ? Specifically interested in simple > Colombes> histograms and scatter plots with circles and regression > Colombes> lines. > > Here's a little example of a histogram and regression plot using > matplotlib - looks easy enough to me! Output image at > http://nitace.bsd.uchicago.edu:8080/files/share/demo.png > > from matplotlib.matlab import * > > x = randn(10000) # some gaussian noise > > subplot(211) # a subplot > hist(x, 100) # make a histogram > grid(True) # make an axes grid > ylabel('histogram') > > # now do the regression... > x = arange(0.0, 2.0, 0.05) > y = 2+ 3*x + 0.2*randn(len(x)) # y is a linear function of x + nse > > # the bestfit line from polyfit > m,b = polyfit(x,y,1) # a line is 1st order polynomial... > > # plot the data with blue circles and the best fit with a thick > # solid black line > subplot(212) > plot(x, y, 'bo', x, m*x+b, '-k', linewidth=2) > ylabel('regression') > grid(True) > > # save the image to hardcopy > savefig('demo') > show() From martin at v.loewis.de Wed Aug 4 01:12:41 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 04 Aug 2004 07:12:41 +0200 Subject: Call for Grant Proposals In-Reply-To: <41097fed$1@news.unimelb.edu.au> References: <40fcaa90$0$27091$9b622d9e@news.freenet.de> <41097fed$1@news.unimelb.edu.au> Message-ID: <41107049.9000502@v.loewis.de> Maurice LING wrote: > I have a few questions to ask about this grant and I've emailed this to > psf-grant at python.org but had no replies yet. Maybe someone authoritative > from PSF can help me out in this or anyone can put in some comments. For some reason, I did not get your message there - although I see it is in the psf-grants archives. I don't know how that happened - my apologies. > 1. Is there a requirement to release the deliverables, including, > software, source codes, specifications and documentation, to the general > public using any of the Open Source Initiative (OSI) approved open > source licences? Not necessarily. There is no requirement that the deliverables are source code; if they aren't, OSI rules obviously don't apply. > 2. Will there be any form of intellectual property claims, including, > copyrights, trade marks, patents, on any form of work generated from the > PSF Grant by the Python Software Foundation (PSF) or any of its > associates? If so, what are the precise nature of it? Not necessarily. Applicants can, of course, assign their copyright to the PSF, but we can certainly fund projects which don't. If you plan to file patents on the results, it would be good to point that out in the proposal. > 3. On the website (http://www.python.org/psf/call-2004.html), it is > stated that the project of which the grant is granted for must be > completed by October 30, 2005. In event of failure to meet, what will be > the penalities? This should be explained in the delivery and payment plans that you submit. It would be a good idea if partial results were available at some point, and partial payments were made after delivery of the partial results. > 4. From Question 3, what constitutes partial failure or complete failure > of the project? Non-delivery of deliverables. > 5. From Question 4, it is stated on the website > (http://www.python.org/psf/call-2004.html) that a delivery plan is > essential in the proposal. How will delay in delivery affect the payment > plan and the grant on the whole? You should also include a payment plan. We will not only evaluate the delivery plan, but also the payment plan, and take the likelyhood and the cost of failure into account when evaluating the project. > 6. Can the PSF Grant be used to generate proprietary work and yet, > furthering the development of Python, Python-related technology, and > educational resources? An example of such is the development of a > proprietary Integrated Development Environment (IDE). In principle, yes. As Tim explains, proposals will compete with each other. We will try to evaluate how much the project serves the public, and in particular the Python community. Regards, Martin From amk at amk.ca Mon Aug 9 11:04:45 2004 From: amk at amk.ca (A.M. Kuchling) Date: Mon, 09 Aug 2004 10:04:45 -0500 Subject: session management References: Message-ID: On Sun, 08 Aug 2004 14:02:14 +1000, Ajay Brar wrote: > question is what happens when the client does not log out? what if he > simply leaves the website? i can put a timer on the cookie, but how do i > cleanup the temp files. You'd need to run a cron job that periodically cleans up sessions that haven't been touched in the last 8 or 24 or whatever hours. > also, is there some python package that already does this and does not > require any configuration on the webserver (i dont have access to config > the webserver). Most web frameworks have support for sessions; for example, Quixote's support is described at http://www.mems-exchange.org/software/quixote/doc/session-mgmt.html . --amk From nico at logilab.fr Tue Aug 24 09:22:39 2004 From: nico at logilab.fr (Nicolas Chauvat) Date: Tue, 24 Aug 2004 13:22:39 +0000 (UTC) Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? References: Message-ID: Hi, Le 22-08-2004, Paul McGuire a ?crit?: > Well, after 3 days of open polling, the number of additional votes have > dropped off pretty dramatically. Here are the results so far: > > Total voters: 55 (with 3 votes each) Here is my vote, in case it can still be included. C2 C2 J2 Concerning the choice of the keyword, I'd vote *against* decorate and for something like predef (J2), with (C2, J2), using (C2). Concerning the @-thingy, it's the worst proposal I have ever heard concerning Python. Sounds too cryptic to be true... must be a joke. I'd like to add that the EuroPython poll was clearly in favor of *not* using the @thing in front of functions and that this poll results also said that people would rather not include the "decorator" feature in the next release than include it as described. Last but not least, the best option would IMHO not to implement so-called decorators without thinking seriously about what they are supposed to do exactly, as title 7 says at http://www.python.org/moin/PythonDecorators In other words "it's getting urgent to wait". -- Nicolas Chauvat logilab.fr - services en informatique avanc?e et gestion de connaissances From alikakakhel3 at hotmail.com Mon Aug 16 18:32:14 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 16 Aug 2004 15:32:14 -0700 Subject: Anyone use VPython? References: <8f17f4bc.0408141932.46b7c405@posting.google.com> Message-ID: <8f17f4bc.0408161432.7d2d1082@posting.google.com> Thank you all for your help. From pm_mon at yahoo.com Mon Aug 16 20:58:47 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Mon, 16 Aug 2004 20:58:47 -0400 Subject: Decorators: an outsider's perspective In-Reply-To: References: <20040816022635.C24B71E4005@bag.python.org> Message-ID: Chas Emerick wrote: > > On Aug 15, 2004, at 10:26 PM, Paul Morrow wrote: > >> As for the Hungarian notation, I agree that in its most abused state, >> it can be a real mess for all sorts of reasons. However in Python we >> do use a very lightweight form of that in the way we identify private >> and semi-private methods. > > > Ugh. I know, and it's one of the little things about python that I am > not so fond of. It has the feel of something that GvM did in one of the > earliest python scripts that just ended up catching on with a wider > audience. It screams 'accident', not 'designed'. Please, no more of that. > Actually, that is another good idea (IMO), borrowed from other languages, and therefore familiar to many veteran developers. It's a simple rule to remember, so I much prefer that convention to having to declare (with a separate word) the visibility of a method. From Scott.Daniels at Acm.Org Wed Aug 25 11:20:20 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 25 Aug 2004 08:20:20 -0700 Subject: Begginers questions on different distributions of py In-Reply-To: References: Message-ID: <412cafd6$1@nntp0.pdx.net> Player wrote: > I decided to try the original Python version, but alas, pywin32 the latest > version or build, requires python 2.2 to install, were as the latest v of > Python is a 2.3 :( > > M.B Not really true. the win32 extensions are now on sourceforge. The most recent (build 202) is available for python major versions 2.2, 2.3, and 2.4. http://sourceforge.net/projects/pywin32/ Do a little homework with Google before asking, and certainly the delay between this question and your later repeating of it is too small. -Scott David Daniels Scott.Daniels at Acm.Org From vronskij at post.sk Thu Aug 19 07:55:35 2004 From: vronskij at post.sk (vronskij at post.sk) Date: 19 Aug 2004 04:55:35 -0700 Subject: age of Python programmers References: Message-ID: <903b3fba.0408190355.38d07555@posting.google.com> I am 25. 2 years flirting with Python. Started programming when I was about 8 years old. Basic and Assemblear. High school Pascal. University C. Now C++ and Python. Teenage programmers fading away. I think that you are at the height of your skills in 30's. jan bodnar From avner at skilldesign.com Mon Aug 9 17:52:46 2004 From: avner at skilldesign.com (Avner Ben) Date: Mon, 09 Aug 2004 23:52:46 +0200 Subject: @decorator syntax is sugar, but for what exactly? In-Reply-To: <4117a43b$1@news.012.net.il> References: <4115b53a$1@nntp0.pdx.net> <4116239e$1@news.012.net.il> <4117a43b$1@news.012.net.il> Message-ID: <4117e58a$1@news.012.net.il> Avner Ben wrote: > > Where has the property Without Underscore come from? > OK, I see now, it's the built in property(). > Avner. From jjl at pobox.com Thu Aug 26 15:28:49 2004 From: jjl at pobox.com (John J. Lee) Date: 26 Aug 2004 20:28:49 +0100 Subject: cookie References: Message-ID: Ajay writes: > hi! > > i am printing a simple cookie, but instead of printing > um=name:blah&access:admin&exp:2312390.909 > > its printing > um="name:blah&access:admin&exp:2312390.909" > > why the quotes? Why not? I don't see how they'd cause any harm. John From robin at reportlab.com Wed Aug 11 13:27:07 2004 From: robin at reportlab.com (Robin Becker) Date: Wed, 11 Aug 2004 18:27:07 +0100 Subject: staticmethod vs metaclass Message-ID: <411A56EB.2080902@chamonix.reportlab.co.uk> A colleague wanted to initialize his class __new__ and tried code resembling this #######################1 class Metaclass (type): def __init__(cls, name, bases, *args, **kwargs): super(Metaclass, cls).__init__(cls, name, bases, *args, **kwargs) print 'cls=',cls, cls.__new cls.__new__ = staticmethod(cls.__new) def __new(self,cls,*args): print 'new(',self,cls,args,')' return object.__new__(cls,*args) class A: __metaclass__ = Metaclass def __init__(cls,*args): print '__init__(',cls,args,')' A(3,4,5) ####################### cls= > new( (3, 4, 5) ) __init__( <__main__.A object at 0x008D0AB0> (3, 4, 5) ) ####################### We wanted to eliminate the extra self argument in the constructed class __new__ so tried #######################2 class Metaclass (type): def __init__(cls, name, bases, *args, **kwargs): super(Metaclass, cls).__init__(cls, name, bases, *args, **kwargs) print 'cls=',cls, cls.__new cls.__new__ = staticmethod(staticmethod(cls.__new)) def __new(cls,*args): print 'new(',cls,args,')' return object.__new__(cls,*args) class A: __metaclass__ = Metaclass def __init__(cls,*args): print '__init__(',cls,args,')' A(3,4,5) ####################### cls= > Traceback (most recent call last): File "mmm.py", line 15, in ? A(3,4,5) TypeError: 'staticmethod' object is not callable ####################### A bit puzzling, but after thought we found both the following do what we want with the __new__ argument signature. #######################3 class Metaclass (type): def __init__(cls, name, bases, *args, **kwargs): super(Metaclass, cls).__init__(cls, name, bases, *args, **kwargs) print 'cls=',cls, cls.__new cls.__new__ = staticmethod(cls.__new) def __new(cls,*args): print 'new(',cls,args,')' return object.__new__(cls,*args) __new = staticmethod(__new) class A: __metaclass__ = Metaclass def __init__(cls,*args): print '__init__(',cls,args,')' A(3,4,5) ####################### cls= new( (3, 4, 5) ) __init__( <__main__.A object at 0x008D0C10> (3, 4, 5) ) ####################### #######################4 class Metaclass (type): def __init__(cls, name, bases, *args, **kwargs): super(Metaclass, cls).__init__(cls, name, bases, *args, **kwargs) print 'cls=',cls, cls.__new cls.__new__ = cls.__new def __new(cls,*args): print 'new(',cls,args,')' return object.__new__(cls,*args) __new = staticmethod(staticmethod(__new)) class A: __metaclass__ = Metaclass def __init__(cls,*args): print '__init__(',cls,args,')' A(3,4,5) ####################### cls= new( (3, 4, 5) ) __init__( <__main__.A object at 0x008D0D90> (3, 4, 5) ) ####################### This does what we want in terms of the signature, but we aren't calling the correct super __new__, any ideas how we can do that? -- Robin Becker From jgrahn-nntq at algonet.se Sat Aug 7 03:52:51 2004 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: Sat, 7 Aug 2004 07:52:51 +0000 (UTC) Subject: Importance of C# References: <278de0e.0407281353.27b6a457@posting.google.com> <5dydnZSDZaARoZXcRVn-ug@powergate.ca> <1n5z28erh2m3u.dlg@baczek.net.invalid> <9418be08.0407300306.673d9951@posting.google.com> <410A4334.9080002@v.loewis.de> Message-ID: On 30 Jul 2004 13:48:02 GMT, Duncan Booth wrote: ... > BTW, elsewhere in this thread someone said that C++ doesn't fit well into > .Net framework so it is worth mentioning that vs2005 also includes > completely revamped support for C++. Naturally this is incompatible with > their earlier attempt, but it really is much improved. I suppose you mean "C++/CLI", which is a superset of ISO C++. Well, it adds a completely new object model to the language, new keywords and everything ... so the statement "C++ doesn't fit well into .Net framework" still applies, IMHO. /Jorgen -- // Jorgen Grahn Would You Let One Marry Your Sister?'' From shalabh at cafepy.com Wed Aug 18 17:58:14 2004 From: shalabh at cafepy.com (Shalabh Chaturvedi) Date: Wed, 18 Aug 2004 14:58:14 -0700 Subject: Calling __init__ for all mixins In-Reply-To: References: Message-ID: Martin Maney wrote: > I've been to the cookbook (both forms, since they're sometimes usefully > different), but that gave rise to more questions than answers. Heck, > let me pull some of them up while I'm at it. > > Martelli gives the recipie (5.3 on paper) "Calling a Superclass > __init__ Method if it Exists" where he seems to say that this: > > class NewStyleOnly(A, B, C): > def __init__(self): > super(NewStyleOnly, self).__init__() > > is the New Class Speak equivalent of > > class Classic(A, B, C): > def __init__(self): > for base in self.__class__.__bases__: > if hasattr(base, '__init__'): > base.__init__(self) > > but when I tried a simple test case (base classes just print a tracer > when called), Martelli's NewStyleOnly only invoked A.__init__, as it > was the first base class in the base list as written with an __init__ > implemented. These seem to me to be very different. > > So the reason I was turning over these stones was that I'm working on a > subsystem where I want to compose working classes using multiple mixin > base classes to provide different implementations for separate parts of > the interface. So far this is working quite nicely (1), but the > business of calling all the mixins' __init__ functions is a bit of a > nuisance. Unfortunately, the solutions I've found (aside from > Martelli's NewStyleOnly which I'm sure was only accidentally implied to > be a solution to this problem) all seem little is any better than the > simple and obvious method of explicitly invoking each one. I'm not > certain that I won't need to use that manual approach in the end, since > the current draft has a couple of arguments to one mixin, and it's not > clear I can eliminate them, but I would still be interested in any > suggestions for nicer solutions to the MI __init__ problem. The new-style super mechanism might indeed solve your problem. In the snippet that you mention, super(NewStyleOnly, self).__init__() would only call A.__init__(). But A.__init__ should itself have a super call of the form: def __init__(self): super(A, self).__init__() # A's super call Now *that* will call B.__init__(), which should itself have a super call of the form - you guessed it: def __init__(self): super(B, self).__init__() Which will call C.__init__(). And so on. Also note that super() will work correctly in the case you had a class: class AnotherClass(A, C): def __init__(self): super(NewStyleOnly, self).__init__() In this case, A's super call would call C.__init__(). Nice, huh? This is the cooperative super call technique explained in the following places: http://www.python.org/2.2.3/descrintro.html#cooperation http://www.cafepy.com/articles/python_attributes_and_methods/ch02.html Any class wanting to participate in this technique must be new-style. Cheers, Shalabh From pinard at iro.umontreal.ca Mon Aug 23 12:38:39 2004 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Mon, 23 Aug 2004 12:38:39 -0400 Subject: Decorator keyword options In-Reply-To: <7knVc.4599$Jn5.3074@fe1.texas.rr.com> References: <7knVc.4599$Jn5.3074@fe1.texas.rr.com> Message-ID: <20040823163838.GA8036@titan.progiciels-bpi.ca> [Paul McGuire] > Thanks to everyone who has voted so far - please keep them coming! Lurkers, > this means you! OK! Here is my vote: J2 J2 J2 It might look like not much nuanced, but the nuances I had disappeared after the reduction of plausible winners, as shown with the current tallies. My vote is merely to strengthen statistics a little more. :-) -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From nir1408 at ziaran.org Thu Aug 5 06:38:00 2004 From: nir1408 at ziaran.org (ziaran) Date: Thu, 05 Aug 2004 13:38:00 +0300 Subject: AVI I/O Message-ID: <41120e31$1@news.bezeqint.net> Hello, I want to use Python for Image proccessing. I need the following capabilities: 1. To be able to read and WRITE an AVI file frame by frame. 2. To be able to access each fram as a simple matrix. I tried to search for that in google but could not find something intuitive and simple. The matrices part is important since iamge processing is done through matrices manipulation. MATLAB is an example of a tool with scripting capabilities in which you can do that in a simple way. Is Python adequate for that? Thanks, Nir From danb_83 at yahoo.com Sat Aug 7 22:26:57 2004 From: danb_83 at yahoo.com (Dan Bishop) Date: 7 Aug 2004 19:26:57 -0700 Subject: Decorators References: <%A8Rc.50217$Vm1.1280580@news20.bellglobal.com> Message-ID: "Colin J. Williams" wrote in message news:<%A8Rc.50217$Vm1.1280580 at news20.bellglobal.com>... > Christopher T. King suggested that "we're trying to kill too many birds > with one stone". > > http://groups.google.com/groups?q=stone+birds+group:comp.lang.python&hl=en&lr=&ie=UTF-8&selm=Pine.LNX.4.44.0408050856390.31290-100000%40ccc9.wpi.edu&rnum=1 > > He goes on to suggest three needs which decorators serve. Are these the > only purposes which are envisaged for decorators? If I understand correctly, they'd be useful for anything where you'd now use the syntax function = decorator(function) In addition to @staticmethod, you could have decorators for (1) Memoization. Makes repeated function evaluation more efficient without having to rewrite the function. class memoize(object): def __init__(self, func): self.__func = func self.__results = {} def __call__(self, *args): if args not in self.__results: self.__results[args] = self.__func(*args) return self.__results[args] def fibonacci(n): @memoize if n in (0, 1): return n return fibonacci(n - 1) + fibonacci(n - 2) (2) Debugging uses, like: class printreturns(object): "Behaves like f but prints its return values." def __init__(self, f): self.__f = f def __call__(self, *args): result = self.__f(*args) if debug: print 'f%r = %r' % (args, result) return def somefunc(x, y): @printreturns ... From vincent at visualtrans.de Fri Aug 6 13:16:49 2004 From: vincent at visualtrans.de (vincent wehren) Date: Fri, 06 Aug 2004 19:16:49 +0200 Subject: Unicode support In-Reply-To: References: Message-ID: Richy2004 wrote: > code: > import sys,codecs > file = codecs.open("accountmgr_words_arb.txt", "r", "utf-16") > print (file.readline()) > > output: > File "./test.py", line 5, in ? > print (file.readline()) > File "C:\Python23\lib\codecs.py", line 384, in readline > return self.reader.readline(size) > File "c:\Python23\lib\encodings\utf_16.py", line 57, in readline > raise NotImplementedError, '.readline() is not implemented for > UTF-16' > NotImplementedError: .readline() is not implemented for UTF-16 > > ====================================================== > code: > import sys, codecs > file = codecs.open("accountmgr_words_arb.txt", "r", "utf-16") > print (file.read()) > > output: > Traceback (most recent call last): > File "./test.py", line 5, in ? > print (file.read()) > File "c:\Python23\lib\encodings\cp850.py", line 18, in encode > return codecs.charmap_encode(input,errors,encoding_map) > UnicodeEncodeError: 'charmap' codec can't encode characters in position > 0-2: character maps to > > ====================================================== > code: > import sys, codecs > file = codecs.open("accountmgr_words_arb.txt", "rb", "utf-16") > lines = file.readlines() > print lines > this works !, output: > [u'\u0646\u0648\u0639 \u062d\u0633\u0627\u0628 \u062c\u062f\u064a\u062f > \u0645\u062e\u062a\u0627\u0631.\r\n'] You understand this is just one line, and not multiple lines? Just checking. The reason why it works is that you are getting a representation of the list. > line = lines[0] > tokens = line.split("\\u") This line doesn't make sense. Do you want to split up the line into a list of individual characters as in: >> tokens = list(lines[0]) >> print tokens [u'\u0646', u'\u0648', u'\u0639', u'\u062d', u'\u0633', u'\u0627', u'\u0628', u'\u062c', u'\u062f', u'\u064a', u'\u062f', u'\u0645', u'\u062e', u'\u062a', u'\u0627', u'\u0631', u'.', u'\r', u'\n'] > print tokens[0] > > I get this: :( > Traceback (most recent call last): > File "./test.py", line 8, in ? > print tokens[0] > File "c:\Python23\lib\encodings\cp850.py", line 18, in encode > return codecs.charmap_encode(input,errors,encoding_map) > UnicodeEncodeError: 'charmap' codec can't encode characters in position > 0-2: character maps to Anyway, you are trying to print to the console window. AFAIK, Python 2.3 guesses the console encoding, which in your case is cp850.py, and uses it as single- byte encoding to encode your unicode characters before writing them to stdout. Unfortunately, you cannot print which I believe are Arabic characters to a CP850 encoded console (as a matter of fact, you can't print any of the so-called 'complex scripts' to any windows console, but that is a different matter). If you run the same script in a lets say, IDLE you won't have that problem. In other words, if you need to print these characters, you have to either print them as unicode characters to a unicode-savy output, or encode them in an appropriate single-byte encoding (e.g. "cp1256") and output them to an output window that nows how to deal with it. -- Vincent Wehren > > Thanks, > Richard > From a.neudecker at uni-bonn.de Mon Aug 9 11:21:56 2004 From: a.neudecker at uni-bonn.de (Andreas Neudecker) Date: Mon, 09 Aug 2004 17:21:56 +0200 Subject: Find out the file name of a module from inside the module? In-Reply-To: References: Message-ID: Danke, Christian! Hat mir sehr geholfen! :-) Gru? Andreas Christian Tismer schrieb: > Andreas Neudecker wrote: > >> Hi. >> >> I know you can read the filename of a program as sys.argv[0]. But what >> about modules? Is there a similar way to find out the file name of a >> module (called by some other module or program) from inside this module? > > > If your modules knows that it is a module, it can inspect its > __file__ attribute. > You can find out whether you have been imported by testing > whether there is a __file__ attribute, otherwise you are > probably executed, and there is no name available. > > try: > fname = __file__ > except NameError: > fname = "?" > > In cases where you absolutely need a file name, and if you know > that you are also used as a module, you can of course import > yourself, in order to get the file name. This implies the need > to know your module name, which doesn't make things so much better: > > # assuming this is MyModule > import MyModule > fname = MyModule.__file__ > del MyModule > > Or even shorter: > > from MyModule import __file__ as fname > > ciao - chris From bockman at virgilio.it Sun Aug 22 06:34:13 2004 From: bockman at virgilio.it (Francesco Bochicchio) Date: Sun, 22 Aug 2004 10:34:13 GMT Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? References: Message-ID: On Sun, 22 Aug 2004 02:53:09 +0000, Paul McGuire wrote: > Please start giving some thought to what the 'decorate' keyword should be. > If we can get/keep this selection to a manageable list, then we should have > another multivote some time next week. > If you are still open to lurkers suggestions, I'm partial to syntax that can be read like common language (this is one reason why I like Python and I mildly dislike the @ sintax). Therefore I would like to suggest to use in J2 keywords like 'using' or 'with', which also hint to the fact that this is only the first part of a declaration suite that will be continued by the 'def' statement. Ciao ------- FB From artur_spruce at yahoo.com Tue Aug 10 18:46:18 2004 From: artur_spruce at yahoo.com (AdSR) Date: 10 Aug 2004 15:46:18 -0700 Subject: pep-318 questions References: Message-ID: Skip Montanaro wrote in message news:... > > I think Guido pronounced on this over the weekend. He stated that > decorators don't belong indented with the code, even at the beginning. In > fact, he commented that in retrospect he feels that doc strings belong > outside the function as well. (Of course, that would present a practical > conflict between a module's doc string and that of the first executable code > in the module file should it happen to be a function definition. But I > digress...) The nice thing about the @decor syntax is that it might be easy to extend it to @"""Docstring""" - "decorate" a function (or class) with the docstring if the decorator expression is a string literal instead of an expression. I prefer in-body docstrings though. While function decorators should be well visible - they may do important changes to function's behavior - the docstring is of secondary importance, only needed when we don't know/remember what the function/class does (and hence should also fold easily in a folding editor). > > Nobody has so far been able to come up with a single keyword that seems to > connote "this is a decorator function that is to be applied to the next > function definition". And '@' does good job of it - it stands out well. Plus, it's a decorated 'a' in many fonts :) AdSR From just at xs4all.nl Mon Aug 30 09:03:58 2004 From: just at xs4all.nl (Just) Date: Mon, 30 Aug 2004 15:03:58 +0200 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <1LMXc.67190$UTP.37420@twister01.bloor.is.net.cable.rogers.com> <1gj7a9r.g7ec5a1g89rj0N%aleaxit@yahoo.com> Message-ID: In article , Jorge Godoy wrote: > > How does that follow? The zip archive _itself_ is the "directory" where > > the .py files are, why would Python suddenly choose to write .pyc files > > one level up? And what about packages? It simply doesn't work that way. > > Because the implementation that allowed to unzip the "directory" and > find the files in there would also allow to place the '.pyc' in a > different place such as the real directory where the zip file resides. > > Python didn't use to open zip files also, and now it does. I don't see > nothing wrong with making it also writing the '.pyc' files. Do you? Yes, because it's conceptually inconsistent with how "regular" imports work. Just From fuzzyman at gmail.com Mon Aug 23 09:22:33 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 23 Aug 2004 06:22:33 -0700 Subject: XMLObject - problem with recursive definitions References: <6f402501.0408222323.5fd81b2a@posting.google.com> Message-ID: <6f402501.0408230522.7172314b@posting.google.com> Apparently this has already been fixed - and a new release will be made in the next couple of days with this fixed.... I'm just surprised it wasn't my fault :-) Fuzzy fuzzyman at gmail.com (Michael Foord) wrote in message news:<6f402501.0408222323.5fd81b2a at posting.google.com>... > I've been using the excellent XMLObject and have unfortunately come up > against what *looks* to me like a bug - although it's very possible > that the problem is mine !! > > I want to use XML object to create an XML structure that represents > the contents of a directory structure. I call it a DirObj. Each DirObj > needs a list node that can itself contaibn several more DirObj - > effectively a 'recursive' definition. > > It looks something like this : > > class XMLDirObj(XMLObject): > """An XMLObject version of a DirObj.""" > attrs = ItemNode('DirAttributes') > files = ListNode('XMLFileObj') > dirs = ListNode('XMLDirObj') > > A DirAttributes object is an object representing the set of attributes > of the directory, an XMLFileObj is an object representing the set of > attributes of each file in the directory. Unfortunately when I use the > toXml and then the (classmethod) fromXml it mangles the values. (on > the read). > > I've written a small test script with the simplest possible recursive > use of XMLObject and it doesn't appear to work. I wondered if this was > actually a bug - or whether I was doing something wrong. My test > script is below and from the sample output you'll see the error and > the assert failure at the bottom. The first print is ok (toXml) - but > then it reads it incorrectly (the second print). > > Ouput : > > > > > > > > > > > > > > > > > > Traceback (most recent call last): > File "D:\Python Projects\dirwatcher\rec_test.py", line 67, in ? > assert thestuff == thestuff2 > AssertionError > > > #################### > > > """ > rec_test.py > > Demonstrates that recursion fails using XMLObject > > :-( > > """ > > > from XMLObject import * > > > ######################################################################## > > > class Thing(XMLObject): > place = ItemNode('Anotherthing') > anotherplace = ListNode('Thing') > abit = CDATAttribute(optional=True) > > class Anotherthing(XMLObject): > abit = CDATAttribute(optional=True) > > > ######################################################################## > # Test Function > > if __name__=='__main__': > test1 = Thing() > test1.abit = 'Hello My Friend' > athing = Anotherthing() > athing.abit = 'Yo' > test1.place = athing > > test2 = Thing() > test2.abit = 'Recursion Test' > athing2 = Anotherthing() > athing2.abit = 'Yo Again' > test2.place = athing2 > > test1.anotherplace.append(test2) > > thestuff = test1.toXml() > print thestuff > > testobj = Thing.fromXml(thestuff) > thestuff2 = testobj.toXml() > > print > print > print thestuff2 > > assert thestuff == thestuff2 > ##################################### > > If anyone can see what I've done wrong it would be much appreciated. > (I've emailed the author - but as it's probably my fault I thought I'd > post here as well). > > > Regards, > > Fuzzy > > > > > -- > > http://www.Voidspace.org.uk > The Place where headspace meets cyberspace. Online resource site - > covering science, technology, computing, cyberpunk, psychology, > spirituality, fiction and more. > > --- > http://www.Voidspace.org.uk/atlantibots/pythonutils.html > Python utilities, modules and apps. > Including Nanagram, Dirwatcher and more. > --- > http://www.fuchsiashockz.co.uk > http://groups.yahoo.com/group/void-shockz > --- > > Everyone has talent. What is rare is the courage to follow talent > to the dark place where it leads. -Erica Jong > Ambition is a poor excuse for not having sense enough to be lazy. > -Milan Kundera From ville at spammers.com Tue Aug 3 06:06:59 2004 From: ville at spammers.com (Ville Vainio) Date: 03 Aug 2004 13:06:59 +0300 Subject: automatic delegation References: Message-ID: >>>>> "h.b.furuseth" == Hallvard B Furuseth writes: h.b.furuseth> Is it possible to write a metaclass or something so that h.b.furuseth> with a class definition not much larger than this: h.b.furuseth> class foo: h.b.furuseth> def __init__(self, val): self.val = val h.b.furuseth> operations on a foo instance f will be applied to f.val? h.b.furuseth> E.g. str(f) -> f.__str__() -> f.val.__str__(). http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52295 -- Ville Vainio http://tinyurl.com/2prnb From mcfletch at rogers.com Mon Aug 23 14:27:48 2004 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Mon, 23 Aug 2004 14:27:48 -0400 Subject: 100 % portable ? In-Reply-To: <1f7befae0408231057a376ac6@mail.gmail.com> References: <2otm5mFed44hU1@uni-berlin.de> <1f7befae0408231057a376ac6@mail.gmail.com> Message-ID: <412A3724.70400@rogers.com> Tim Peters wrote: >[Bernd Kaiser] > > >>>You can use os.environ["HOME"], this will return the user's home dir. >>> >>> See this old thread: http://groups.google.ca/groups?threadm=mailman.1140.1075749926.12720.python-list%40python.org The OpenGLContext code should work for Win98, 2K, and XP, maybe for Win95 and NT too, but I don't have them for testing. Enjoy, Mike ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From 1stpoint at zmailbox.net Mon Aug 2 15:01:15 2004 From: 1stpoint at zmailbox.net (1stpoint) Date: Mon, 02 Aug 2004 15:01:15 -0400 Subject: py2exe and os.popen Message-ID: <94737de0df0675e750e306af1ae2e475@localhost.talkaboutprogramming.com> After several attempts at solving this problem I thought I would ask the gurus. I wrote a python/wxPython application that calls os.popen to get information from another executable. Basically this is a cute GUI app to front end a commercial product. The app works fine when I run it as a .py or .pyw application. But after I build it to a .exe with py2exe and run it, it does not work. I put a print statement after the 1st os.popen call: for line in os.popen(c,'rb').readlines(): self.components.Project.items+=[line.rstrip()] print 'items=',self.components.Project.item Is this due to a stdin issue with win32? From mauriceling at acm.org Mon Aug 2 19:53:53 2004 From: mauriceling at acm.org (Maurice Ling) Date: Tue, 03 Aug 2004 09:53:53 +1000 Subject: Call for Grant Proposals In-Reply-To: References: <40fcaa90$0$27091$9b622d9e@news.freenet.de> <41097fed$1@news.unimelb.edu.au> <410DF640.4010307@acm.org> <410DF824.8070309@acm.org> Message-ID: <410ED411.7090907@acm.org> Anthony Baxter wrote: >>I do agree that open source != hobbyist and I can hear screams already. >>What I'm trying to say is that the wordings of this call for proposal on >>the webpage is probably alright for hobbyist projects but can't face the >>scrutiny of the corporate world. >> >> > >I'm really not sure what you mean. Plenty of people in "the corporate world" >do open source. Plenty of people in "the corporate world" make money from >open source. > No doubt that people are making money from open source but equivalently, the same people may be making money from closed source. I'm arguing that the wordings of this grant is not clear, to the point that we do not know if this grant is applicable to us. >If the terms for the grants are that the project be open source, >how is this a problem? > Then it will means that some projects may not be able to apply for this grant if it is the requirement of the project to be proprietary due to business strategy. What you are saying is that all projects should be open sourced but that may not be the case. Either that or you are indiscriminately lobbying for the cause of open source irregards of whether companies are ready for it or not, and then discriminating against companies who are not ready for it yet. Although I support open source development and had personally donated my work to Sourceforge and Biopython project, I will think that it is tyrannic to assume all work must be open sourced. >It simply means that the person or organisation who >applies for the grants has to factor that element into their calculations. > > Without knowing the elements, how am I going to convince anyone on that? I'm not omnipotent. >Any company in 2004 who is still working in a mode that open source is >some strange thing that isn't used 'in the real world' is probably slow-moving >roadkill. > > > As mentioned above, parts of the work by my organization had been donated to public cause, including Biopython project and large public institutions like NCBI. Even the Online Mendelian Inheritance of Animals (OMIA) database was initially developed by people in my organization. As far as I know, some work precipitating to masters degrees had been made open sourced. So, please refrain from making harsh conclusions. Having said that, there is always a rubber-stamping process before an open sourced decision is made. But the wordings and inexactness of this call for grant proposal makes it hard for me even to get to convince my people that we should put in an application, not mentioning the rubber-stamping. Cheers Maurice -------------- next part -------------- A non-text attachment was scrubbed... Name: mauriceling.vcf Type: text/x-vcard Size: 155 bytes Desc: not available URL: From lbates at swamisoft.com Mon Aug 9 09:19:30 2004 From: lbates at swamisoft.com (Larry Bates) Date: Mon, 9 Aug 2004 08:19:30 -0500 Subject: python and win32 dlls References: Message-ID: Another solution that I wrote and have used extensively: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146847 Larry Bates Syscon, Inc. "fgrillo64" wrote in message news:mailman.1386.1092054829.5135.python-list at python.org... > Hi guys, > i need help from the comunity ; i wrote under Windows2000 os a dll > having several symbols exported . > Now i would like to call these symbols from a python program . > Can anyone tell me how from a python module is possible to call > the dll exported symbols ? > thanks a lot , Francesco . > From roeder at berg.net Sat Aug 14 10:00:29 2004 From: roeder at berg.net (=?ISO-8859-1?Q?Maik_R=F6der?=) Date: Sat, 14 Aug 2004 16:00:29 +0200 Subject: Seperating CSV rows into new, seperate files In-Reply-To: References: Message-ID: <411E1AFD.20006@berg.net> Hi TobyB, > Hi, > I've searched the group and need more information and guidance on this > issue I need to resolve next week. I work for the local school system > and I am working on a way to parse a CSV file of class lists from MS > Excel. It is a ~2MB file with all teachers and all their classes in > it. I thought I would use Python to do this since many people I know > tell me how great it is. Pyhton is a good choice for treating texts. > The real sticking point is there are > duplicates of each teacher's classes embedded in the file (don't ask > why). I want to break up the source file into the seperate class > files without duplication and use the teachers name, coursecode and > section in the filename. > > Example Data: > Last Name First Name Grade Period Teacher Name > SMITH JOHN 8 1 JONES SALLY > > Student ID Course Code Course Title > 12345678 1234 ALGEBRA I > > Course Section Session > 1 0 > > > The course code and section number are the same in the duplicate > classes. The difference is that the session number changes. I'm > thinking that I will need to somehow iterate through the lines and > break the class when the course code changes and/or section change > (course codes can be the same but section numbers change with each > class). Then I have to monitor the session number to see if there is > a duplicate course code and section but a different session number > would indicate that the class is a duplicate. Essentially, the session > number will be 0, 1, or 2 for a total of three lists of the same > class. Hopefully that makes sense. Again don't ask why the data is > like this. > > My humble attempts have not been very successful. I've been trying > the csv modules to read the file but I am not sure how to procede > after that. > > Any guidance is greatly appreciated. Use Python lists and dictionaries. Best regards, Maik R?der From jbors at mail.ru Thu Aug 26 19:54:08 2004 From: jbors at mail.ru (Dmitry Borisov) Date: Thu, 26 Aug 2004 16:54:08 -0700 Subject: Sound file manipulation in Python References: Message-ID: <10isu157sfk3c2@corp.supernews.com> "Paul Moore" wrote in message news:uu0upzj72.fsf at yahoo.co.uk... > Does anyone know of a Python library which handles sound file formats > (MP3, Ogg, FLAC are the three I'm nost interested in). I'd like > something that can manipulate "metadata" - stuff like artist, title, > album tags. I'm not critically interested in format conversion, or > playing sound files - I can handle that with other applications. > > I'm using Windows, and Python 2.3, if it matters (as it might for C > extensions). > > I can manage with just reading the metadata, but ideally writing > would be useful, too. Multiple libraries is OK, but I need something > more than just MP3. > > If there's nothing available for Python, does anyone know of a good C > library that could be wrapped? (Or used via ctypes, maybe). > You may try to use pymedia: http://pymedia.sourceforge.net There is no writing at this point( but you may add it though ), also FLAC not supported also. If you need writing you may need to use ffmpeg/libavformat for that... Dmitry/ From theller at python.net Wed Aug 18 12:43:09 2004 From: theller at python.net (Thomas Heller) Date: Wed, 18 Aug 2004 18:43:09 +0200 Subject: age of Python programmers References: <41237124.4060600@chamonix.reportlab.co.uk> <41238374.3060105@chamonix.reportlab.co.uk> Message-ID: Robin Becker writes: > Thomas Heller wrote: > >> Robin Becker writes: >> >>>Lucas Raab wrote: >>> >>> >>>>One thing I've always kind of wondered is what is the average age of a >>>>Python programmer?? What age groups use Python?? Something to think >>>>about.... >>>> >>> >>>57, used to build my own logic using gas discharge tubes :) >> 48, but my first logic was build using 24V relays. > > yea I also did stuff with relays and strowger telephone switches, far > more exciting than billions of fet transistors simulating an electric > fire :) Maybe. My ring counter with 12 relays or so ran at a frequency of about 5 Hertz, after a week of drilling and soldering, nowadays I could desing ring counters running at hundreds or maybe even thousends of MHz, use a 1.7 V supply, only by entering some VHDL code (*) at the computer, compiling and downloading it to an FPGA. But the FPGA doesn't make the same noise ;-) (*) I have still to try Jan Decaluwe's (sp?) MyHDL to create the ringcounter, or even more complicated things, with Python. From ramen at lackingtalent.com Thu Aug 19 11:35:25 2004 From: ramen at lackingtalent.com (Dave Benjamin) Date: Thu, 19 Aug 2004 15:35:25 -0000 Subject: Jython and super_reload? References: <412458a6$0$45379$e4fe514c@dreader19.news.xs4all.nl> Message-ID: In article <412458a6$0$45379$e4fe514c at dreader19.news.xs4all.nl>, Ype Kingma wrote: > > This works for classes: > > http://www.jython.org/docs/jreload.html > > You can unload a module in Jython by removing it from sys.modules, > and (off course) by removing all other references to it. > > To be sure about what happens you can tell the JVM to be verbose > about garbage collection of Java classes, and explicitly call > java.lang.System.gc() in some test scripts. Thanks for the link and the comments, but I don't think this is quite what I'm trying to do here. I'm not trying to reload Java classes, I'm trying to reload Python modules such that any instances of the old version of that module's classes get updated to use the new methods. For instance: mymod.py -------- class A: def test(self): print 'hello' app --- import mymod a = A() a.test() (output: 'hello') mymod.py -------- class A: def test(self): print 'goodbye' app --- reload(mymod) a.test() (output: still 'hello') # This is what I've been unable to accomplish: from magic import super_reload super_reload(mymod) a.test() (output: 'goodbye') Does that make sense? The end result is that I want to be able to modify classes in a running application and have this affect all existing class instances. This is important because I am working in an application server environment where restarts are costly and time-consuming, and instances are often kept in user sessions. Currently, any changes to a class require that the session be reinitialized (ie. you have to log out and log back in), which makes incremental testing and development awkward. Thanks! Dave -- .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:. "talking about music is like dancing about architecture." From jeff at ccvcorp.com Mon Aug 9 20:13:46 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Mon, 09 Aug 2004 17:13:46 -0700 Subject: Purely emotional perspective In-Reply-To: References: <10hf3oaltbo7o74@corp.supernews.com> <10hg1hg1pidqs96@corp.supernews.com> Message-ID: <10hg4p0988ocgf0@corp.supernews.com> Arthur wrote: >>I'm particularly worried about the proposals of using this as metadata >>for things like author -- that seems to be begging for almost every >>function to use half a dozen or more decorators (accepts, returns, >>author, design date, last revision date, etc., etc.) which will (IMO) >>seriously degrade code readability. (This syntax is okay for one or two >>decorators, but more than that quickly becomes obfuscatory.) >> >> > >But isn't that so of any of the alternative syntaxes. Looks to me as >if it is." Looks" as in "that is what my eyes tell me". > > Like I said, I can see the reasons why the alternatives are being rejected. But while I can see why those are being rejected, I'm not seeing this one as all that much better -- which suggests to *me* that maybe they should *all* be rejected. I understand that decorators are beneficial. I understand that "Now is better than never." But I can't help but *also* think that "...never is often better than *right* now." Sometimes *not* including a useful feature is better than including it in an ungainly or awkward way. (This seems, to my mind, to be especially true of features that are principally syntactic sugar, as it seems that @decorators are.) I know that this has been being discussed for a long time, and nobody's come up with a better syntax. But I remain unconvinced that the @-syntax is a significant enough improvement over the current (rebind-after-function-body) syntax to warrant a significant change in the way that Python code will be structured. (It seems, however, that GvR *is* convinced of that very thing, so all of this is just whistling in the wind...) Jeff Shannon Technician/Programmer Credit International From ndeskins at ecn.purdue.edu Tue Aug 17 09:50:31 2004 From: ndeskins at ecn.purdue.edu (Aaron Deskins) Date: Tue, 17 Aug 2004 08:50:31 -0500 Subject: Newbie question about file input In-Reply-To: References: Message-ID: Ok everyone, Thanks again for all the input. I rewrote the code and have included some more routines. Basically the program takes a pgn file with all the chess games and randomizes them and spits out a new pgn file. It is below. Hopefully I was able to get the spacing right. :) Also, what exactly is stored when a blank line is read by the readline command? A zero, blank, or what??? What is the difference between trying to read a non-existant line (i.e. a line at the end of the file) and a blank line (line with nothing on it)? Thanks again. pgn-rand.py: #! /usr/bin/env python import string import sys import random random.seed # Find number of games, it zf=open(sys.argv[1],'r') it = 0 while 1: line = zf.readline() if line.startswith("[Event"): it+=1 if not line: break zf.close() # Initialize order which has list of games a = 0 order = [1] while a < it-1: order.append(a+2) a+=1 # Randomize game list 4x a=0 while a < 4*it: one = random.randint(0,it-1) two = random.randint(0,it-1) temp = order[one] order[one]=order[two] order[two]=temp a+= 1 # Output to new pgn file in new order out=open(sys.argv[2],'w') a=0 while a < it: curr=0 zf=open(sys.argv[1],'r') while 1: line = zf.readline() if line.startswith("[Event"): curr+= 1 if order[a] == curr: out.write(line) if not line: break zf.close() a+=1 out.close() -- Aaron Deskins Graduate Student Chemical Engineering Purdue University From vwehren at home.nl Fri Aug 6 02:59:54 2004 From: vwehren at home.nl (Vincent Wehren) Date: Fri, 6 Aug 2004 08:59:54 +0200 Subject: PEP 263 status check References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> <10h5hgvpafm8a64@news.supernews.com> Message-ID: "John Roth" schrieb im Newsbeitrag news:10h5hgvpafm8a64 at news.supernews.com... | | "Martin v. L?wis" wrote in message | news:4112AB53.6010701 at v.loewis.de... | > John Roth wrote: | > > PEP 263 is marked finished in the PEP index, however | > > I haven't seen the specified Phase 2 in the list of changes | > > for 2.4 which is when I expected it. | > > | > > Did phase 2 get cancelled, or is it just not in the | > > changes document? | > | > Neither, nor. Although this hasn't been discussed widely, | > I personally believe it is too early yet to make lack of | > encoding declarations a syntax error. I'd like to | > reconsider the issue with Python 2.5. | > | > OTOH, not many people have commented either way: would you | > be outraged if a script that has given you a warning about | > missing encoding declarations for some time fails with a | > strict SyntaxError in 2.4? Has everybody already corrected | > their scripts? | | Well, I don't particularly have that problem because I don't | have a huge number of scripts and for the ones I do it would be | relatively simple to do a scan and update - or just run them | with the unit tests and see if they break! Here's another thought: the company I work for uses (embedded) Python as scripting language for their report writer (among other things). Users can add little scripts to their document templates which are used for printing database data. This means, there are literally hundreds of little Python scripts embeddeded within the document templates, which themselves are stored in whatever database is used as the backend. In such a case, "scan and update" when upgrading gets a little more complicated ;) | | In fact, I think that a scan and update program in the tools | directory might be a very good idea - just walk through a | Python library, scan and update everything that doesn't | have a declaration. | | The issue has popped in and out of my awareness a few | times, what brought it up this time was Hallvard's thread. | | My specific question there was how the code handles the | combination of UTF-8 as the encoding and a non-ascii | character in an 8-bit string literal. Is this an error? The | PEP does not say so. If it isn't, what encoding will | it use to translate from unicode back to an 8-bit | encoding? Isn't this covered by: "Embedding of differently encoded data is not allowed and will result in a decoding error during compilation of the Python source code." -- Vincent Wehren | | Another project for people who care about this | subject: tools. Of the half zillion editors, pretty printers | and so forth out there, how many check for the encoding | line and do the right thing with it? Which ones need to | be updated? | | John Roth | > | > Regards, | > Martin | | From aahz at pythoncraft.com Fri Aug 27 12:59:11 2004 From: aahz at pythoncraft.com (Aahz) Date: 27 Aug 2004 12:59:11 -0400 Subject: Call for signatories for J2 References: Message-ID: All right, with the caveat that I'd prefer C1, I'm voting FOR. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From ajsiegel at optonline.com Sat Aug 14 15:24:51 2004 From: ajsiegel at optonline.com (Arthur) Date: Sat, 14 Aug 2004 19:24:51 GMT Subject: PEP318 References: <20040812090056.00001e31@titan> <7ttmh0t8c3cogtbhhnp1ohqu8b51pda461@4ax.com> Message-ID: On Fri, 13 Aug 2004 16:43:05 +1000, Anthony Baxter wrote: >On Thu, 12 Aug 2004 17:03:19 GMT, Arthur wrote: >> >def foo (): >> > whatever >> >foo = decorator (foo) >> > >> >is that you have to type the word "foo" three times. >> >> Big f**king deal - all things considered. ;) > >When this name is a PyObjC name that might be 70 characters long, >it becomes a big deal. PyOdjC keeps being mentioned as the poster project for @decorator. Isn't it fair to note that projects where the naming of functions is outside the control of the developers are blue moon situations? The kind of constraint that might be expected to lead to some extra effort. Which the PyObjC developers seemed to be quite willing and able to face with some equanimity, in the absence of a native @decorator facility. Just a debating point, or at least an effort to neutralize, a bit, a statement that seems to be little more than a debating point. Art From franz.geiger at fh-vorarlberg.ac.at Fri Aug 6 03:52:35 2004 From: franz.geiger at fh-vorarlberg.ac.at (F. GEIGER) Date: Fri, 6 Aug 2004 09:52:35 +0200 Subject: [py2exe.i18n] English works, German works, but not French. What do I miss? References: Message-ID: <411338c4$0$11742$3b214f66@aconews.univie.ac.at> "Harald Massa" wrote in message news:Xns953D5E610BA51cpl19ghumspamgourmet at 195.20.224.116... > "F. GEIGER" wrote in news:cev7g9$3fm$1 at newshispeed.ch: > > > When I start a py2exe-ed application I get the error > > > > 'ascii' codec can't encode character u'\xe9' in position 10: ordinal > > not in range(128) > > > encodings: prepare to spend the night. > > First reading: > http://starship.python.net/crew/theller/moin.cgi/EncodingsAgain > > Second: > your error msg says that you are trying to encode sth. NOT ASCII to > ASCII... > > I guess: > your lokale site has another encoding configured > > > import sys > sys.getdefaultencoding() > > -- returns sth. like Latin-1 > > And the py2exed application does not read siteconfig.py, and so in the > running app sys.getdefaultencoding() would be some thing different. > > My approach to this is: > > in the beginning of the app I write: > > import sys > if hasattr(sys,"setdefaultencoding"): > sys.setdefaultencoding("latin-1") if hasattr() returns False, that means that site.py / sitecustomize.py has been exec'ed and has deleted the attr 'setdefaultencoding', right? i.e., import sys if hasattr(sys,"setdefaultencoding"): sys.setdefaultencoding("latin-1") else: pass # site.py did it already for us and everything should work > > so ... when no site-config was run, I manually set my default encoding to > latin-1 > > works great (together with what I described within the wiki) Thank you, Harald, as I am traveling right now, I'll be able to try this in the afternoon. > > Harald Kind regards Franz GEIGER From peter at engcorp.com Fri Aug 20 23:55:01 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 20 Aug 2004 23:55:01 -0400 Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: Reid Nichol wrote: > Peter Hansen wrote (about "quantum"): >> And at least some dictionaries give it as a synonym for "large" >> or "significant". (www.m-w.com for one) > > Such things are only the result of a misunderstanding of the word some > time ago. Even though it is wrong, it has become common use, thus the > incorrect definition definition(s). Whatever... the point is that you can be prescriptive or descriptive about the meanings of words... and *descriptively speaking*, it is used as "large" and at least one dictionary accurately notes that fact. Nobody really cares whether it results from a misunderstanding or mistake... if they did, Americans would properly use "fewer" in all those cases where they now use "less" incorrectly. -Peter From indigo at bitglue.com Wed Aug 18 14:35:21 2004 From: indigo at bitglue.com (Phil Frost) Date: Wed, 18 Aug 2004 14:35:21 -0400 Subject: Embedding Python in Python In-Reply-To: References: Message-ID: <20040818183521.GA25267@unununium.org> You probably want something like this: globalDict = {} exec(stringOfPythonCodeFromUser, globalDict) globalDict is now the global namespace of whatever was in stringOfPythonCodeFromUser, so you can grab values from that and selectivly import them into your namespace. On Wed, Aug 18, 2004 at 02:26:00PM -0500, Robey Holderith wrote: > > Anyone know a good way to embed python within python? > > Now before you tell me that's silly, let me explain > what I'd like to do. > > I'd like to allow user-defined scriptable objects. I'd > like to give them access to modify pieces of my classes. > I'd like to disallow access to pretty much the rest of > the modules. > > Any ideas/examples? > > -Robey From peter at engcorp.com Tue Aug 3 19:03:58 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 03 Aug 2004 19:03:58 -0400 Subject: python + byte array In-Reply-To: References: Message-ID: Ruslan wrote: > I use win32com package to call WinHTTP COM methods. > One of them is 'Send'. I can pass string parameter to 'Send' method from > python - it's OK, but to send binary data i need somehow pass in 'Send' > method data of _byte array_ type(Visual Basic type). Does anybody know > how to mimic that 'byte array' type of Visual Basic in Python (i need to > pass big chunks of binary data in 'Send')? > I tried struct.pack, but that doesn't seem to be an option. Strings are probably what you are looking for... in Python a string is basically an array of bytes. From tchur at optushome.com.au Tue Aug 17 16:46:58 2004 From: tchur at optushome.com.au (Tim Churches) Date: 18 Aug 2004 06:46:58 +1000 Subject: Plotting over MapPoint maps In-Reply-To: References: Message-ID: <1092775618.1249.7.camel@emilio> On Wed, 2004-08-18 at 02:29, Dr. Colombes wrote: > Can anyone offer pointers, suggestions on how to overlay coordinate > (Lat, Long)-based MatPlotLib graphics over a MapPoint map ? For geographic maps in Python, see Thuban and related projects at http://thuban.intevation.org/ No idea whether it is possible to display MapPoint maps (that's a proprietary Microsoft map format, isn't it?) in Thuban or overlay Matplotlib charts. You might want to look at R instead (see http://www.r-project.org) - it provides facilities to display rudimentary maps, charts and plots and raster images all in the same graphic. There are also several geostatistics modules available for it. You can drive R and send and receive data to/from it via RPy (http://rpy.sf.net). -- Tim C PGP/GnuPG Key 1024D/EAF993D0 available from keyservers everywhere or at http://members.optushome.com.au/tchur/pubkey.asc Key fingerprint = 8C22 BF76 33BA B3B5 1D5B EB37 7891 46A9 EAF9 93D0 From jeff at ccvcorp.com Thu Aug 12 19:40:28 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Thu, 12 Aug 2004 16:40:28 -0700 Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: <411bfa47$1@nntp.zianet.com> References: <60dfb6f6.0408111846.615ee9eb@posting.google.com> <3YWdnYxLf--ObofcRVn-pw@powergate.ca> <411ba1db$1@nntp.zianet.com> <411bd3f0$1@nntp.zianet.com> <10hnqqm8h7b3k89@corp.supernews.com> <411bfa47$1@nntp.zianet.com> Message-ID: <10hnvtn1184q773@corp.supernews.com> Mark Bottjer wrote: > Jeff Shannon wrote: > >> All the criticisms aimed at the decorate: syntax, ISTM, apply equally >> well to @pie syntax, except for the few that are based on indentation >> level. > > > Which are the only ones *I* was really trying to debate. :) > > BTW: "ISTM"? "... it seems to me ..." :) >> And on those, *I* at least feel that it'd be preferable to pattern >> decorators after existing language constructs, rather than >> deliberately breaking all the patterns that Python has established. > > > Again, agreed. It seems like we both agree that the @pie syntax > doesn't follow any extant pattern. Where we seem to differ is in our > opinions of how well the decorate: syntax follows those same patterns. Perhaps. (Though, before this post, I was getting the impression that you were in favor of @pies, which would imply a different aesthetic sense of the code as well; I'm willing to allow a bit more slack on breaking established patterns in order to avoid the sort of eyesore that @pie represents to me.) >> The fact that the feature is new doesn't mean that we need an entire >> new code-layout principle. The differences between class & def, on >> the one hand, and try/except & if/else on the other, don't seem to >> confuse people too much. I'd rather see the same layout principle >> applied in a different way than see an unprecedented and unfamiliar >> layout principle used in one or two special cases. > > > FWIW, I agree. That's why I like this option the best: > > class C: > def c(self): > meta: #declare, decorate, transform, fubar, whatever... > staticmethod > doc('Doc.') > pass > > IMHO, this form passes all the of the criteria we've been debating. The > only criterion it fails is that it is "inside" the function, but I don't > consider that too big an issue: once you know where to look for the > additional information, you'll look there. Where-ever that may be. I'd be happiest with this option, too. But it seems that GvR has already ruled out anything other than prefix syntax, so I'm not wasting my energy backing this. With prefix syntax as a given, I'd prefer to have the closest we can come to this form, which is to have the meta (or decorate, or whatever) block immediately preceding the def. Though I must say, I don't see how putting a meta: block inside the function is any less a violation of established patterns than having it outside the function. You seem to be implying that you think it's fine inside, but an abomination outside. I'm saying that this sort of block structure is (IMO) the most pythonic way to do this, and while I'd like it inside I don't particularly care if it's outside, and that in any case it's far less of an abomination that @pies are. :) Jeff Shannon Technician/Programmer Credit International From rho at see.signature.invalid Mon Aug 23 05:52:09 2004 From: rho at see.signature.invalid (Nigel Rowe) Date: Mon, 23 Aug 2004 19:52:09 +1000 Subject: J2 paper 0.2.1 References: Message-ID: <10ijfibd8qo84b5@news.supernews.com> Robert Brewer wrote: > The first draft of the J2 proposal is ready. You can read it here: > http://www.aminus.org/rbre/python/pydec.html > > At this point, I am looking for comments regarding the proposal. Once I > believe I have addressed a sufficient number of concerns, I will freeze > the document and call for signatories, both for and against, then send > it to Guido. Until that time, expect the draft to change multiple times > each day (there's a meta tag with the version number if you care to > check). > > In this thread, please do not introduce discussions regarding syntaxes > other than J2 and A1. Limit your comments to the three arguments, > literary critique, and praise for Mr. Sparks who is providing the > implementation. Oh, and somebody let me know if you rampaging lot crush > my little server. ;) > > > Robert Brewer > MIS > Amor Ministries > fumanchu at amor.org It's a *very* minor nit (which just indicates how much basic agreement I have with the document overall), but, could the list of example keywords be put in alphabetical order? Ie: predef, prologue, preamble, preface, helper, amend, using, having, qualify, extend, confer, meta, through, per, via, by becomes amend, by, confer, extend, having, helper, meta, per, preamble, predef, preface, prologue, qualify, through, using, via -- Nigel Rowe A pox upon the spammers that make me write my address like.. rho (snail) swiftdsl (stop) com (stop) au From http Sat Aug 28 04:04:01 2004 From: http (Paul Rubin) Date: 28 Aug 2004 01:04:01 -0700 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <7xzn4gwgea.fsf@ruckus.brouhaha.com> <1gj7a1o.1a5d2q410jsn2kN%aleaxit@yahoo.com> <7xisb4xnh5.fsf@ruckus.brouhaha.com> <1gj7c1a.tfdm14p3hclcN%aleaxit@yahoo.com> <7xd61benm9.fsf@ruckus.brouhaha.com> <1gj82n3.1ylkr3nierngmN%aleaxit@yahoo.com> Message-ID: <7x4qmnvgcu.fsf@ruckus.brouhaha.com> aleaxit at yahoo.com (Alex Martelli) writes: > Would it make sense to rely on a naming convention instead? > I.e. foo.zip would be unsigned but bar.jar would have to be signed > or else no go. This would have the advantage of allowing > substantial granularity in controlling this. I think this is reasonable, except what does the import statement look like? Do you say something like "import frob from bar.jar"? > Side question, does module zipfile already have the code to allow > reading such signed files? I think jar files are just zip files containing an extra file (called "manifest") that has signatures in it. So you can import from a jar as if it were a zip. From siona at chiark.greenend.org.uk Wed Aug 18 10:28:14 2004 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 18 Aug 2004 15:28:14 +0100 (BST) Subject: Access to Oracle References: Message-ID: Greg Lindstrom wrote: >I am running Python 2.3.3 on HP-UX and would like to access an Oracle 9i >database. Looking through the vaults, I see 4 or 5 modules that might work >and was wondering if anyone is currently hitting Oracle and what are you >using. We're using cx_Oracle, primarily for Oracle 8i on Solaris but we also target W2K. Testing with 9i should currently be in progress, and I've had no problems reported so far.... -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From fumanchu at amor.org Tue Aug 24 00:52:26 2004 From: fumanchu at amor.org (Robert Brewer) Date: Mon, 23 Aug 2004 21:52:26 -0700 Subject: On consensus decision-making (was Re: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WEDONE?) Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E4E@exchange.hqamor.amorhq.net> Peter Hansen wrote: > Has anything really changed? Would it now be correct to say > that C1 has a serious chance of being accepted if someone would > just update the implementation to the state and quality (?) of > the other two? As serious as any other, I suppose: http://article.gmane.org/gmane.comp.python.devel/63137 Robert Brewer MIS Amor Ministries fumanchu at amor.org From sholden at holdenweb.com Mon Aug 30 08:11:37 2004 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 30 Aug 2004 08:11:37 -0400 Subject: os.walk: Get entire path In-Reply-To: <1093799393.448803@news.commspeed.net> References: <1093799393.448803@news.commspeed.net> Message-ID: Tom B. wrote: > "Florian Lindner" wrote in message > news:cgssom$hu6$00$1 at news.t-online.com... > >>Hello, >>when I'm walking through a file system hierarchy using os.walk, how can I >>get the full path of a file or dir? normpath and abspath don't work. >>Thx, >>Florian > > > I would use glob > > import glob > > glob.glob('c:\\images\\*\\*.jpg') > > yields all .jpg's in //images and sub directories with full path in a list. No, it doesn't. If the directory hierarchy is more thane one level deep you won't see those files, and neither (I believe without verifying) will you see files from the top-level directory itself. regards Steve From norman.werner at student.uni-magdeburg.de Fri Aug 27 03:31:57 2004 From: norman.werner at student.uni-magdeburg.de (norman werner) Date: 27 Aug 2004 00:31:57 -0700 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: Albert Reiner wrote in message news:... > ["Michiel Borkent" , Thu, 26 Aug 2004 13:35:38 +0200]: > > LISP and Esperanto: my favorite languages. > > Ankaux miaj - krom, eble, ankaux la Haskella. > > Stranga koncentrigxo de verdlingvanoj cxe cll, cxu ne? > > Albert. estas koncentrig:o. Ambau: lingvoj estas elektata de inteligentaj homoj :) Espereble mi ne g:ustas - ne mi s:atas induktitan konkludon pri homaro. Norman From kyleroot at gmail.com Wed Aug 11 22:31:34 2004 From: kyleroot at gmail.com (Kyle Root) Date: 11 Aug 2004 19:31:34 -0700 Subject: Arranging a dependency tree Message-ID: <6ccff37a.0408111831.6eb25a4e@posting.google.com> I'm working on a little practice program, but I've become stuck and am now utterly confused :? I've created a jumble of python modules, in each one is a tuple that goes something like, deps = ("file10","file7","file3"). And some have no dependencies at all. I have one file called "start", and the whole thing makes a tree of dependencies as each file has deps and their deps might have deps, and so on. What I'm trying to do is "straighten" them or put them in order as if they were to be installed. Basically I'm trying to replicate the way portage does it. :) I've been thinking about this for a few days but I always get lost. So far I have a has_deps(filename) function, and not much else. I get stuck on the actual changing the files from the random jumble to a into a nice orderly list of files. One problem that I can't overcome is when I'm a couple of deps in and I finally get to the files that don't require anything, I have no way of getting back to do the parent file's other deps. (Does that make any sense?) Basically I was wondering if anyone had any tips or pointers, or knew of any dependency resolving algorithms... Thanks, Kyle From asif at go-away-spammer.com Wed Aug 25 10:29:44 2004 From: asif at go-away-spammer.com (Player) Date: Wed, 25 Aug 2004 15:29:44 +0100 Subject: Begginers questions on different distributions of py References: Message-ID: I decided to try the original Python version, but alas, pywin32 the latest version or build, requires python 2.2 to install, were as the latest v of Python is a 2.3 :( M.B From russblau at hotmail.com Tue Aug 31 13:38:02 2004 From: russblau at hotmail.com (Russell Blau) Date: Tue, 31 Aug 2004 13:38:02 -0400 Subject: Beginners question. References: Message-ID: <2pjrbnFkpdrvU1@uni-berlin.de> "Player" wrote in message news:ch2c6b$5ap$1 at newsg1.svr.pol.co.uk... > Firstly I just wanted to see if I could get the length out of those elements > that were list type. > I no thats not exactly what the exercise asks for, but I thought I would > start there. > However I am stuck and cant figure out why my code is doing what it's doing. > My code is as follows.... > > mylist = [1, 2, ["three", "four"], "five"] > for item in mylist: > if item == type(list): The "if" statement above is always false (well, at least for any list you are likely to encounter in real life), because you are looking to see if the item is equal to "type(list)" which is a type object. I think you meant: if type(item) == list: That's why your len() statement was never being reached. > myitem = len(item) > print myitem > else: > print item > -- I don't actually read my hotmail account, but you can replace hotmail with excite if you really want to reach me. From mark_bottjer at hotmail.com Fri Aug 13 16:48:34 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Fri, 13 Aug 2004 16:48:34 -0400 Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: References: <60dfb6f6.0408111846.615ee9eb@posting.google.com> <3YWdnYxLf--ObofcRVn-pw@powergate.ca> <411ba1db$1@nntp.zianet.com> <411bd3f0$1@nntp.zianet.com> Message-ID: <411d2923$1@nntp.zianet.com> Peter Hansen wrote: > Mark Bottjer wrote: > >> Peter Hansen wrote: >> >>> Mark Bottjer wrote: >>> >>>> With this >>>> syntax, though, the decorate block changes how the def statement is >>>> handled, even though they are at the same indentation level. >>> >>> Changes it how? The definition of this whole decorator idea has been >>> that it is equivalent to applying the decorator functions *after* the >>> def has completed, as in "func = decorator(func)". This does not >>> in any way changed how the def statement itself is handled. >> >> Except that the action happens magically after the def, even though >> the decorator is before it. To me, this has the appearance of changing >> the action of def. I'm trying to argue based on how it appears, rather >> than how we know it to be implemented. > > I understand that. What I don't understand is why you make > this complaint about the indented form, when the non-indented > form with @decorator has exactly the same issue! In all > cases, pre-def is weird in that the declarative lines that > decorate the function lead to action *after* the def is > closed, whether the decorators are indented or not. I *do* have the same complaint about the @decorator form. *All* the prefix forms have this problem. That's why I don't like them as much as the "top of function block" forms; at least with those we have the already-established pattern of docstrings to help us understand what is going on. The "in-statement with def" forms are the cleanest conceptually, but just don't seem to code up well. My point was only that I find the indented block of decorators to be less intuitive than the (ugly, but to me more obvious) flush-left list of @decorators. If we're going to be stuck with a prefix form, I like @dec better than decorate: (though "meta dec" would be fine as well). I think GvR's point about not having to look inside the function to determine its specification is nice in theory, but we're already used to doing exactly that. Changing it now just adds confusion. -- Mark From aleaxit at yahoo.com Thu Aug 26 04:59:31 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 10:59:31 +0200 Subject: Call for signatories for J2 References: Message-ID: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> Robert Brewer wrote: > This is a call for all who wish to sign the proposal, either for, > against, or abstaining. Please sign by either posting on > comp.lang.python (replying to this is fine), or sending email to For. I wish we'd use a better keyword than 'using' which would have a bazillion other possible and useful future interpretations. Of the possible keywords mentioned on the site, several (by, per, through, via) appear better to me, and I'd particularly love the three-letter ones as they'd align well with 'def' -- my own preference would be 'per'. However, I suspect it's too late to submit J2 with anything but 'using' and I'd rather have J2 with 'using' than the pie-before-def thingy, so, here's my "tactical" FOR vote:-). Alex From peter at engcorp.com Fri Aug 6 13:44:59 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 06 Aug 2004 13:44:59 -0400 Subject: elements of decorator syntax suggestions In-Reply-To: References: Message-ID: Steven Bethard wrote: > So in summary > -> yay keywords! > -> before def or before colon, and > -> whatever list notation and indentation floats your boat Good post, Steven, and I agree with all your own opinions on the matter as expressed above. Note one addition item that most of us are glossing over in the debate for/against the pie (@) syntax. Order of operation. @ syntax has reversed order from the list-after-def. I think the order should be readily apparent from the syntax, and I think the list syntax does provide that benefit over the @ syntax. I think I'd like a "decorate" keyword (or equivalent), *before* the definition to avoid the problems with obscuration, and a mandatory list of some kind that clearly shows the order. Something like, but not necessarily exactly the same as, this: from __future__ import decoration decorate [ foo, bar, bletch(spam='baz') ] def func(): ... The only problem is that it still has the defect of @ wherein the decorate doesn't seem to "bind" to the function def very well, especially if blank lines are allowed etc. I'm unclear on what I think it best... but then I don't mind the current approach much at all, where you just stick the stuff after the entire function block, so who cares about my opinion? ;-) -Peter From jacek.generowicz at cern.ch Wed Aug 25 05:32:03 2004 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 25 Aug 2004 11:32:03 +0200 Subject: Shell used by os.system Message-ID: Is there a way of specifying the shell in which os.system commands are executed[1]? Is there a way of specifying what startup scripts should be read? [1] On systems where this makes sense, of course. From jedwardrm at yahoo.co.uk Sun Aug 1 15:44:14 2004 From: jedwardrm at yahoo.co.uk (Jed R. Mallen) Date: 1 Aug 2004 12:44:14 -0700 Subject: python tutes on win32 Message-ID: Hello, Can anyone point me to a nice tute on making python apps for win32? TIA From me at privacy.net Mon Aug 9 17:39:03 2004 From: me at privacy.net (Richard Hanson) Date: Mon, 09 Aug 2004 14:39:03 -0700 Subject: MSI Installer issues References: <411231C8.3020308@interlink.com.au> <411241F5.3080602@v.loewis.de> <1f7befae040805103911610582@mail.gmail.com> <411274C0.4070300@v.loewis.de> <1f7befae04080623276089908e@mail.gmail.com> <4114A02F.7060906@v.loewis.de> Message-ID: <2jpfh0dsv97dkvflmvnu2ac9h1c91i3721@4ax.com> [NB: This post contains little of substance -- the gratitude is real, however.] [Tim Peters wrote:] >[...] "low-res" may be a feature, as some >people have very low screen resolution settings and very large fonts. My Fujitsu LifeBook P1120 (Win2k SP2) has a 1024x600 pixel screen (and tweaked fonts to compensate for the rapidly worsening lighting conditions coincidentally appearing just as I age ). A common problem I run into is that the occasional dialog box is too tall for the available screen real estate. (This problem is exacerbated by my preference to have the taskbar not hide -- driving Windows is difficult enough without having a not inconsiderable amount of third-party-apps sitting in my systray helping to clue me in on just what-all-in-hell is going on with this machine. This strategy sometimes even works. ) In any event, while the current (2.4a2) MSI installer's dialog box is one of those too-tall ones, thankfully, Martin's MSI installer dialog thoughtfully provides scrollbars to make dealing with the problem much less onerous. Martin's too-tall-for-my-screen installer is the *only* too-tall dialog I've encountered which *has* provided the scrollbars -- including some from BIG_NUM-bucko corps. So, no particular point. I just wanted to say good job to all the contributors -- thanks! -- Richard -- R Hanson [The mangled email addie below works.] sickolefartnewsguycom From h.b.furuseth at usit.uio.no Mon Aug 23 14:09:52 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 23 Aug 2004 20:09:52 +0200 Subject: Finding a class' superclasses Message-ID: How do I find a class' immediate superclasses? That is, given class A: pass class B(A): pass class C(A): pass class D(B, C): pass I want a function foo where foo(D) or foo(D()) returns (B, C). (Well, the order of the classes is not important.) -- Hallvard From steven.bethard at gmail.com Mon Aug 23 14:41:10 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Mon, 23 Aug 2004 18:41:10 +0000 (UTC) Subject: function taking scalar or list argument References: <412a2bce$1_1@127.0.0.1> Message-ID: beliavsky aol.com 127.0.0.1> writes: > def twice(x): > try: > return map(twice,x) > except: > return 2*x > [snip] > Is this good style? First a general comment about catching exceptions -- you should probably write your try-except block as: try: ... except TypeError: ... Better to only catch the exceptions that your call to map will throw. But to really answer your question, I would probably avoid this style. It means for every number you double (whether an element of a list, or an element alone), you'll throw and catch an exception. This needlessly complicates the simple case. Exception handling is intended to deal with "exceptional" cases, cases which should be relatively infrequent. And while Python's exception handling is pretty efficient, it's still not particularly cheap to catch exceptions. You would probably be better with: def twice(x): if isinstance(x, list): return map(twice, x) else: return 2*x In this case, instead of incurring the cost of a thrown and caught exception for each number, you incur only the cost of a isinstance test. You also avoid treating the common case as the exceptional one. Steve P.S. In reality, I probably wouldn't write a method like this, instead relying on the caller to call map for themselves if necessary. The caller is much more likely to know the type of the object they want to double anyway, so they may not even need to use the isinstance test. From zathras at thwackety.com Sat Aug 21 20:20:16 2004 From: zathras at thwackety.com (Michael Sparks) Date: Sun, 22 Aug 2004 01:20:16 +0100 (BST) Subject: J2 decorator grammar In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022E1B@exchange.hqamor.amorhq.net> Message-ID: On Fri, 20 Aug 2004, Robert Brewer wrote: ... > Did you ever fix the scope issue? I've fixed the scoping issue. I'll clean up the changes I made to get a minimal patch against 2.4a2, and then put it somewhere handy. Now that I've got a much clearer idea of how the python source tree hangs together adding in the short form should be relatively simple. The current patch uses "decorate" as the keyword. Changing that of course is utterly trivial - it's also something I think *should* be changed. The reason for suggesting this change is for one simple reason - python makes often use of the idiom "decorate-dosomething-undecorate" - eg in sorting. Using decorate would probably clash heavily with people's code. The closest word that strikes me that has a similar meaning to decorate, using and applying would be "decorating". If anyone has a closer suggestion to a short single word meaning "decorate using", it'd be great. > Might it have something to do with: > static void > symtable_node(struct symtable *st, node *n) > { It certainly did! Your suggested change was necessary, however it was incomplete - the child to traverse also needed changing. (I really should've thought of that sooner - of course it's no longer zero! :) ie this > symtable_node(st, CHILD(n, 0)); Becomes: > symtable_node(st, CHILD(n, 4)); So THANK YOU for pointing out this part of the code :) Currently I have a file that looks like this, which is completely legal, and does what you would expect for this syntax: ---- def memoise(f): return f class Foo: decorate: staticmethod def Hoo(who): print "You", who if 1: decorate: memoise def Print(what): print "Ya", what Print(who) Foo.Hoo("HOO!") ---- No matter what syntax we end up with, all of these syntactic sugar changes rely on the original decorator code, and I've been very pleasantly suprised at just how clean (and well documented) the python source is for a project of it's size. As I say I'll post the cleaned up patch later. Regards, Michael. From fred at acme.com Mon Aug 23 20:26:05 2004 From: fred at acme.com (Fred) Date: Tue, 24 Aug 2004 02:26:05 +0200 Subject: [newbie] Strange behavior of the re module References: <2ejdi01btug5iskb4ipjpj7eaprd8i7vgm@4ax.com> <86hei0prvp55iom91df23tffh04egefeig@4ax.com> <3toei056qnmk8nkesta47mncuh49asscht@4ax.com> Message-ID: On 23 Aug 2004 16:58:00 +0100 (BST), Sion Arrowsmith wrote: >Here's another hint: string.replace() is a lot faster than re.sub(), >and doesn't require any extra escaping of the replacement string. Indeed. The replacing line on the same 200KB document takes over 2:30mn using re.sub() but... less than a secod with output.replace(). Thx a bunch for the tip :-) Fred. From jacob at cd.chalmers.se Tue Aug 10 14:42:12 2004 From: jacob at cd.chalmers.se (Jacob Hallen) Date: 10 Aug 2004 18:42:12 GMT Subject: decorators vs GIL References: <0bidnfbR2_PZOIjcRVn-pA@giganews.com> Message-ID: In article , Skip Montanaro wrote: > > Anthony> As far as "fixing" the GIL - well, no-one on Python-Dev has > Anthony> obviously found it to be a problem for them. > >I wouldn't state the case that strongly. There appear to be bigger fish for >the python-dev gang to fry up to this point. Perhaps if more of us were >scientific computation types the GIL would be seen as a more important >barrier to be removed. That a fairly bright guy (Greg Stein) removed it >once and found performance to be disappointing doesn't advocate strongly for >removal of the GIL either. > >Skip So, what we really want to do is to remove the GIL, and keep it. Ignoring trivialities like practical implementation, we can do this, since the moment we start running our program, we will be able to find out if we are running in an environment were we have access to multiple processors (and if the program has the ability to use them (at least most of the time)). If we can use multi-processing, we invoke a Python interpreter with fine grained locking, otherwise we stick with the GIL. It is not really reasonable to have 2 different sets of source code to maintain the 2 versions of the interpreter, but it might be possible to make an abstraction of the locking that allows the source code to compile into 2 different interpreters with different locking strategies. Practical implementation would probably be a very big project. Especially in the case of the standard Python implementation. Jacob Hall?n -- From lbates at swamisoft.com Tue Aug 24 16:04:38 2004 From: lbates at swamisoft.com (Larry Bates) Date: Tue, 24 Aug 2004 15:04:38 -0500 Subject: Building basic dialog in Windows? References: Message-ID: <3tGdnSTFgOnIArbcRVn-pQ@comcast.com> Here's a class for Windows progress bar: # # Progress bar control example # # PyCProgressCtrl encapsulates the MFC CProgressCtrl class. To use it, # you: # # - Create the control with win32ui.CreateProgressCtrl() # - Create the control window with PyCProgressCtrl.CreateWindow() # - Initialize the range if you want it to be other than (0, 100) using # PyCProgressCtrl.SetRange() # - Either: # - Set the step size with PyCProgressCtrl.SetStep(), and # - Increment using PyCProgressCtrl.StepIt() # or: # - Set the amount completed using PyCProgressCtrl.SetPos() # # Example and progress bar code courtesy of KDL Technologies, Ltd., Hong Kong SAR, China. # from pywin.mfc import dialog import win32ui import win32con import time def MakeDlgTemplate(): style = (win32con.DS_MODALFRAME | win32con.WS_POPUP | win32con.WS_VISIBLE | win32con.WS_CAPTION | win32con.WS_SYSMENU | win32con.DS_SETFONT) cs = (win32con.WS_CHILD | win32con.WS_VISIBLE) w = 215 h = 36 dlg = [["Progress bar", (0, 0, w, h), style, None, (8, "MS Sans Serif")], ] return dlg class TestDialog(dialog.Dialog): def OnInitDialog(self): rc = dialog.Dialog.OnInitDialog(self) self.pbar = win32ui.CreateProgressCtrl() self.pbar.CreateWindow (win32con.WS_CHILD | win32con.WS_VISIBLE, (10, 10, 310, 24), self, 1001) return rc def demo(): d = TestDialog (MakeDlgTemplate()) d.CreateWindow () for i in xrange(100): d.pbar.SetPos(i) time.sleep(0.1) d.OnCancel() if __name__=='__main__': demo() Here's some code for a file dialog box that I stripped from an application that asks user to select an export file from TimePilot payroll application (the files are always called TimePilot.mdb): import win32ui import win32con #--------------------------------------------------------------------------- ---- # Display a file dialog box that allows the user to browse to the TimePilot.mdb # file that they wish to export. #--------------------------------------------------------------------------- ---- timepilotdatapath="C:\TimePilot" f=win32ui.CreateFileDialog(1, None, "TimePilot.mdb", 0, 'TimePilot databases|TimePilot.mdb||') f.SetOFNInitialDir(timepilotdatapath) f.SetOFNTitle("Timepilot Extracted Data") result=f.DoModal() if result == win32con.IDCANCEL: emsg="Cancel button pressed during TimePilot.mdb file selection, aborting" sys.exit(emsg) mdb_path=f.GetPathName() HTH, Larry Bates Syscon, Inc. "Fred" wrote in message news:bp0ni09fofpahse8uoa4l3hdmq5lmi61rr at 4ax.com... > Hi, > > I'd like to turn a command-line script into a Windows GUI app > using the native widgets so as to reduce the size of the binary (ie. > no QT, wxWidgets, et al.) > > I came up with the following list of tools to access the Win32 API: > > - PythonWin (MFC) http://www.python.org/windows/pythonwin/ > - ctypes http://starship.python.net/crew/theller/ctypes/ > - EasyDialogs for Windows > http://www.averdevelopment.com/python/EasyDialogs.html > - DynWin http://www.nightmare.com/~rushing/dynwin/ > - sdk32 - Partial Python wrap of the Win32 Platform SDK > http://www.object-craft.com.au/projects/sdk32/ > > Does someone have a sample on how to display an OK/Cancel dialog with > a label + progress bar? Should I look at other tools? > > Thank you > Fred. From anandpillai at letterboxes.org Tue Aug 31 07:22:54 2004 From: anandpillai at letterboxes.org (Anand Pillai) Date: 31 Aug 2004 04:22:54 -0700 Subject: Python Usage Statistics Message-ID: Hi Folks (posting after a loooong time...) I have been contracted by an Indian publisher to author an introductory text book on Python. As a part of the introductory chapter, I thought it would be a good idea to present a number, a round-about figure on the approximate *actual* usage of Python out there in number of developers and/or installations. Scrounging the Web for such statistics is proving elusive. The PBF website seems to be the official place for these, but there also they just have listings of companies/instituitions using Python, not any numbers. Has anybody done an actual market survey anytime recently on Python usage in the software community? If so, where can I get access to this information? I would be more interested in the number of developers, both commercial/non-commercial who are doing development using Python. Since almost every Linux distro now a days contains Python by default, a number based on the installations could prove faulty. Have a nice day. -Anand From tdelaney at avaya.com Sun Aug 15 22:15:16 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Mon, 16 Aug 2004 12:15:16 +1000 Subject: autocoding and the new MS book regarding software factories Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01CF49AC@au3010avexu1.global.avaya.com> Hey all! It's time for the semi-regular Tim Rue sighting! With a new email address to beat the killfiles (or more likely these days, spambayes). Where's that 'Delete As Spam' button gone ...? Tim Delaney From frank at chagford.com Fri Aug 6 03:31:39 2004 From: frank at chagford.com (Frank Millman) Date: 6 Aug 2004 00:31:39 -0700 Subject: Obscure bug in pyPgSQL Message-ID: <246a4e07.0408052331.2cdd7e92@posting.google.com> Hi all Below is the text of a message I was about to send in connection with an obscure problem. I have now almost got to the bottom of it, and am fairly confident that it is a bug in pyPgSQL. I hope this is the correct place to report such bugs. If not, please advise the correct forum. I have left the original message intact as it provides important information. At the bottom, I have recorded the new information that I have discovered. ------------------------------------------------------------------------------- Here is an obscure problem. I am not sure if I can explain the symptoms properly, but I will do my best. I have a Linux box (RH9) and an MSW box (W2K Pro) networked to each other. Both are running Python 2.3.3. Linux is the server. It is running PostgreSQL, which listens on port 5432. It is also running a socket server program that I have written using socket.socket(), listening on port 6543. I am using pyPgSQL to connect to the database. MSW is the client. From time to time it sends messages to my socket server. Messages are strings consisting of a single digit identifier, followed by a cPickle'd tuple containing various data fields. The client uses cPickle.dumps to prepare the string before sending, and the server uses cPickle.loads to unpickle it after receiving. Most times it works perfectly, but in one particular situation the server terminates with an error. The error is consistent - it always gives the same error resulting from the same message. However, I do not think it is caused by the message itself, as exactly the same message is sent in different circumstances without generating an error. The traceback is as follows - File "./chag_server.py", line 190, in ? dat = cPickle.loads(data[1:]) File "/usr/local/lib/python2.3/site-packages/pyPgSQL/libpq/__init__.py", line 43, in _I8 return PgInt8(value) NameError: ("global name 'PgInt8' is not defined", , ('17',)) The error occurs at the point of unpickling - I have moved this around, and it always fails at this point. A typical example of the tuple being unpickled is (2,'Ar',17,1) - it is all normal strings and integers. I have no idea why pyPgSQL is involved at all - I am certainly not invoking it directly. In fact the error comes from my server program, and that does not even import pyPgSQL. Here are the relevant lines from pyPgSQL/libpq/__init__.py - from libpq import * from libpq import __version__ HAVE_LONG_LONG_SUPPORT = dir().count('PgInt8') == 1 #---------------------------------------------------------------+ # Add support to pickle the following pyPgSQL objects: | # PgInt2, PgInt8, PgBoolean | #---------------------------------------------------------------+ def _B(value): return PgBoolean(value) def _I2(value): return PgInt2(value) def _I8(value): return PgInt8(value) Somehow pyPgSQL is responding to my unpickling command, and raising an error because PgInt8 is not defined. Here is another fact, which may provide a clue or may add confusion. If I run exactly the same program from the Linux box, using it as the client as well as the server, the error does not appear. I connect via the external IP address, not via 127.0.0.1, so I would have thought it would behave the same, but it does not. ------------------------------------------------------------------------------- Ok, here is the reason. I mentioned above that a typical tuple consists of (2,'Ar',17,1). I have found that under some circumstances the 3rd element is of type 'long' instead of type 'int', and this is what generates the error. Whether it is a long or an int is determined by pyPgSQL itself. It is a column value, where the column is of type 'serial', which means that PostgreSQL will generate a next number if the row is being inserted. If the row exists, the column value is returned along with all the other columns, and is returned as type int. If the row does not exist, I insert it, and then to retrieve the id generated, I have the following piece of code - cur = db.cursor() cur.execute("select currval('%s_%s_Seq')" % (tableid,columnid) ) rowid = cur.fetchone()[0] In this case, rowid contains the correct value, but is of type long. So this raises various questions - Why is PgInt8 not defined? Why does pyPgSQL affect my server program, which does not import any of pyPgSQL? Why does the error only occur when I connect from a remote machine? Now that I have identified the problem, I can work around it, so this has become a matter of correctness rather than a matter of urgency. For those that have read this far, thanks for your patience. Frank Millman From amichail at gmail.com Tue Aug 10 05:12:11 2004 From: amichail at gmail.com (Amir Michail) Date: 10 Aug 2004 02:12:11 -0700 Subject: tool to check whether formal and actual parameters have similar names Message-ID: Hi, I was wondering if there is a tool that will perform some heuristic checking of actual and formal parameters to warn about likely errors. Such a tool could check that formal and actual parameters have similar names. For example: def plot(x,y): ... plot( x1, y1 ) # ok plot( y1, x1 ) # not ok, but this is ok: plot (x=y1, y=x1) plot (1, y) # not ok, but this is ok: plot(x=1, y) We can take this further: avg = x1 + x2 plot( avg, y) # ok since avg gets name x from x1, x2 Does this make any sense, even in a heuristic sense? Does such a tool already exist? Would it be useful? Amir From steven.bethard at gmail.com Sun Aug 29 15:54:39 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Sun, 29 Aug 2004 19:54:39 +0000 (UTC) Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Paul Morrow yahoo.com> writes: > Have you seen a significant number of cases where a function uses > __xxx__ names for local variables? Have you seen any? Are there any examples currently of functions that use __xxx__ names in their body at all? I haven't seen this, but I haven't really looked... STeve From itaborai83 at yahoo.com.br Mon Aug 23 11:13:02 2004 From: itaborai83 at yahoo.com.br (Daniel Lemos Itaborai) Date: 23 Aug 2004 08:13:02 -0700 Subject: Dynamic Scoping problem Message-ID: I would like to first apologize my question, I just picked up Python for a spin 4 days ago(loving it so far). I am having some trouble with this... # myproblem.py x = 'wrong' def bluft(x) : x() def foo(): x = 'right' def bar(): global x print x bluft(bar) # end myproblem.py Is there a way to enforce scope resolution? Thanks for the patience, Daniel Lemos Itaborai From qyron_spam at safe-mail.net Fri Aug 20 10:00:31 2004 From: qyron_spam at safe-mail.net (QyRoN) Date: 20 Aug 2004 07:00:31 -0700 Subject: Install Python on win32 without modifying registry Message-ID: <2260b3c5.0408200600.4c0550c4@posting.google.com> Hi I need to install python-2.3 on my computer. The problem is that python and many programs written in python (pythonwin for example) use registry for storing parameters on python installation. Is there a way to install without modifying the registry? From bryanjugglercryptographer at yahoo.com Tue Aug 17 14:25:38 2004 From: bryanjugglercryptographer at yahoo.com (Bryan Olson) Date: 17 Aug 2004 11:25:38 -0700 Subject: Generators versus Coroutines References: Message-ID: <1a517b5.0408170923.48f6d964@posting.google.com> Michael wrote: > Bryan Olson wrote: > > Correct me if I'm wrong: Greenlets use a c-language extension to > > do the routine switching; implementing the same in pure Python is > > infeasable. > > Correct. I never claimed that doing this in "pure" python was possible - > largly because I think such a concept is pretty silly. > > After all, what is "pure" anyway? > * Is using a module that comes with python allowed? Most importantly: it means I can write in Python and run it with no more than the standard Python distribution, on any of the many platforms with reasonable support. > IMO, the question is one of practicality. It is practical to use > generators to build concurrent systems - and it works pretty well. I've seen servers that rock written with explicit event handling, threads, processes, and occasionally co-routines. Where are the great generator-based servers? > > Generators rock, but they have a shadow of the power of co-routines. > > Continuations are more powerful still. > > And if you choose appropriate coding conventions every problem domain that > co-routines and continuations can solve, generators can be used with > almost equal effectiveness. > > Having written large amounts of code using generators to gain parallelism > in a single thread I don't say that lightly. I've found their simplicity > useful for limiting the complexity of the architecture. Have you been badly bitten by an evil co-routine? They blow away generators on exactly the criteria you name. Look at the specs of most client-server protocols; they're defined in terms of the interaction of just the two parties. With co-routines (or threads or processes), I can implement a single line of control that handles just one client, then support many clients just by changing the loop that accepts connections, and adding yields within the I/O calls (plus maybe locking of the rare shared data). -- --Bryan From peter at engcorp.com Tue Aug 31 08:33:53 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 31 Aug 2004 08:33:53 -0400 Subject: use win32 COM in python In-Reply-To: References: Message-ID: Peter Hansen wrote: > From ctypes, however, you can create special objects which ctypes can > use as pointer types. For example, byref(sometype) is roughly > equivalent to "sometype * xxx" when using ctypes. Oh, and I should mention that there is a dedicated mailing list for ctypes so, after you have experimented a bit and read the docs yourself, you should probably direct ctypes questions there instead of here, for greatest effect. -Peter From robin at SPAMREMOVEjessikat.fsnet.co.uk Thu Aug 26 03:44:39 2004 From: robin at SPAMREMOVEjessikat.fsnet.co.uk (Robin Becker) Date: Thu, 26 Aug 2004 08:44:39 +0100 Subject: age of Python programmers In-Reply-To: References: <20040819231139.D039A1E4003@bag.python.org> <5cf809e9.0408241126.6e3fdd5b@posting.google.com> <8ecda57b.0408251754.14ed27b9@posting.google.com> Message-ID: <412D94E7.4020405@jessikat.fsnet.co.uk> Jonathan Daugherty wrote: ..... > Is it just me or are these posts getting off-topic? :) > makes a change, better than endless discussion of poorly designed changes to the core language anyhow :) -- Robin Becker From lbates at swamisoft.com Mon Aug 30 10:47:25 2004 From: lbates at swamisoft.com (Larry Bates) Date: Mon, 30 Aug 2004 09:47:25 -0500 Subject: PHP Documentation References: <4133124f$0$281$4d4ebb8e@news.nl.uu.net> <1gjc9sk.e6c0cwnxjvs5N%aleaxit@yahoo.com> Message-ID: <3_CdnTrTktNkoK7cRVn-qw@comcast.com> Zope has such a system in place for their docs. You can just ask that the comments be hidden and they disappear. It does appear to provide a way to make comments, add examples clarification that "may" get included in the next version of the docs. Larry Bates Syscon, Inc. "Alex Martelli" wrote in message news:1gjc9sk.e6c0cwnxjvs5N%aleaxit at yahoo.com... > Peter Hansen wrote: > ... > > 2) Many people think that the noise created by lots of user > > comments would far outweigh the value of the good comments > > that might be hidden somewhere within. > > As long as it's possible to request a view or download of the docs > without the comments, I don't see how this could be a problem -- if you > want to see the docs with comments you can, if not, you're no worse off > than today. With the kind of threshold-setting and ratings for various > commenters that (e.g.) slashdot uses, you could also set up your > preferences to see _some_ of the comments but not all. > > In theory any wiki page could be "defaced" by one nasty minded vandal, > in practice most wikis seem to work decently well -- maybe people react > positively to being trusted. If comments (and posters thereof, > eventually) can be rated, existing comments edited or removed only by > authorized personnel, etc, etc, I suspect it would work. No doubt the > needed infrastructure already exists on the widely appreciated PHP doc > pages, it remains to be seen whether we're humble enough to just copy it > wholesale or if the prospect of running PHP code in a key supporting > role for Python is just too embarassing;-). > > > Alex From greg at cosc.canterbury.ac.nz Wed Aug 25 23:36:39 2004 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Thu, 26 Aug 2004 15:36:39 +1200 Subject: How does a "script" differ from a "program" or "subroutine"? In-Reply-To: <56cfb0e3.0408232247.2df68078@posting.google.com> References: <56cfb0e3.0408232247.2df68078@posting.google.com> Message-ID: <2p5469Fh01dgU1@uni-berlin.de> Porky Pig Jr wrote: > Phil Frost wrote in message news:... > >> A script is just a program, but has the implication that it's a simple >> program for a simple task. > > I think the major implication is not that it's simple but it's written > in some 'interpreted' (rather than compiled) language. To my way of thinking, a "script" is a canned sequence of commands for something that one normally uses interactively. On that basis, python "scripts" aren't really scripts, they're programs -- because the Python interpreter isn't normally used interactively, except for trying things out during programming. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From ken.beesley at xrce.xerox.com Sun Aug 22 05:39:53 2004 From: ken.beesley at xrce.xerox.com (Ken Beesley) Date: Sun, 22 Aug 2004 11:39:53 +0200 Subject: unicodedata name for \u000a Message-ID: <412869E9.5070405@xrce.xerox.com> Ken Beesley schreef: >> >> There is, of course, a Unicode name for \u000a, > > Peter Kleiweg wrote: No, there isn't. Check http://www.unicode.org/charts/PDF/U0000.pdf OK. I see that for 000A there is not now an official Unicode name in 4.0, and that "LINE FEED (LF)" is an alias. Such an alias, shown in uppercase letters, indicates that it _was_ the name of the character in The Unicode Standard, Version 1.0. See The Unicode Standard 4.0, p. 415 ("Aliases"). This seems odd. One intuitively assumes that any defined Unicode character has a Unicode name. From alex_stante at yahoo.de Sun Aug 15 10:39:50 2004 From: alex_stante at yahoo.de (Alexander Stante) Date: 15 Aug 2004 07:39:50 -0700 Subject: Control an external console program Message-ID: Hi, I know Python since about 3 days or so and I like it very much :-) I am currently tying to control an external console driven program but I have encountered some problems while trying to do so. Suppose I will try to control a program like a ftp command line client. At first I wrote something like: import popen2 fin, fout = popen2.popen2("ftp") print "Out: " + fin.readline() I expected to get an output like "Out: ftp>" but I got not nothing. I think the reason is that readline() reads a line till it encountered a "\n" or EOF, but nothing of both happen because the ftp client just wrote the prompt and is now waiting for input, or not? Therefore I thought, ok I just write an "\n" to fout and because the ftp client will echo it I can read a line with readline() and get the prompt. But it doesn't work either. Now I started asking myself if it just work this way at all. Instead of just writing a "\n" to fout I wrote "help\n" and read a line from fin and this time I got the first line of the output from the help command *yeeha* :-) Unfortunately any successive read from fin does not work. I can only read the first line the help command issued, not the 5 or 6 following the first line. So my question is how do I control a command line tool? I want to interactively control a command line tool, so I will issue some commands need the output from the tool and act acording to it. I guess readline() is not the answer because if there is no line to read present it just waits. Can anyone give me some hints for writing such a program? How is the python command line tool integrated in the many IDE's around? I guess they have the same problem, or not? Bye Alex From deetsNOSPAM at web.de Tue Aug 3 09:13:37 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Tue, 03 Aug 2004 15:13:37 +0200 Subject: how do i do this - stream file References: Message-ID: <2n9hc2Fuo4olU1@uni-berlin.de> > How do i create and stream a file? > On a webpage i have a link to a file. Next to it i would like link, which, > when pressed, runs a script that calculates the signature of the file, > pickles the signature to a file and then gives a dialog box asking the > user whether they would like to save the file or open it. > > I have the script to do the signing and pickle the signature into a file, > but how do i allow the user to download it? You'll need a webserver - there exist simple http-servers in the standard modules, you can use twisted or one of the plethorea of web-serving-solutions that exist for python, like (on particular order nor a complete list) quixote, zope, mod_python and so on.... -- Regards, Diez B. Roggisch From gregor.jan at NOSPAMquick.cz Sun Aug 15 12:33:14 2004 From: gregor.jan at NOSPAMquick.cz (Jan Gregor) Date: Sun, 15 Aug 2004 18:33:14 +0200 Subject: python a jdbc Message-ID: Is there some to use jdbc driver with python ? I thought about communication between java process and python throught sockets. Simple test worked fine. Jan From peufeu at free.fr Sun Aug 1 07:42:45 2004 From: peufeu at free.fr (=?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?=) Date: Sun, 01 Aug 2004 13:42:45 +0200 Subject: language/distro preferences References: Message-ID: I use Gentoo. Their portage system is really, really good. Being able to download and install programs and all their dependencies, using my compilation options... that makes life so much simpler... And about PHP, I hate it. The language is so weak. Nothing is OO. The libraries are inconsistentand everything is in a big mess, due to the absence of namespaces. I guess this is best illustrated by the following example : Python #1: if char in string: do stuff if item in array: do stuff Python #2: print mystuff.getsomestuff().getsomeattribute().getname().capitalize() PHP #1: Um, which of the 50 string functions should I use ? (lookup help). Um, I don't remember, should I put the haystack or the needle first ? It depends on which function you choose. Um, does it return false, O, -1, or null on failure ? (It depends on which function you choose) Um, what's the function name for an array ? is it find_array or array_find or in_array or array_has_key ? mmm... what if the key is a string... is it a different function... mmm PHP #2 : $temp = $mystuff->getsomestuff(); $temp = $temp->getsomeattribute(); echo strtocap or somthing( $temp->getname(); ) You get it ? On Fri, 30 Jul 2004 10:15:14 -0500, Josh Close wrote: > I saw a question in a PHP list about the differences between php and > perl, and what the advantages between the two are, but I think I was > the only person that mentioned anything about python in the > discussion. > > This makes me wonder what the python group things about these other > languages. > > Python vs. Perl. vs. PHP vs. C# (and other .NET languages) vs. Java > vs. C vs. C++ vs. whatever other language you can think of. > > I think python is the king of command line. It's way faster than PHP. > It's OO and has exceptions which perl doesn't, and PHP supports very > poorly. > > I won't touch Perl with a 10 ft. pole anymore. No need. > > PHP I still use for web. Mod_python isn't the easiest language to > write fast web pages in. > > I think Java is just terrible. Very very slow. It has a nice size > library, but I really don't care :P. > > C and C++ are cool, but take a lot longer to develop in. > > I actually like C# quite a bit. I think it's good for windows use and > asp.net. I've seen all the ranting about how much everyone hate's it, > so I won't say any more. > > This brings up the question about linux distributions. Which one and > why? I use Gentoo and I think there is nothing better. It's way more > configurable than any other distro. Portage is by far the best package > management system out there. Gentoo makes administration life so much > easier. When I've used redhat in the past (not by choice), I've had to > install most programs by hand because I either couldn't find a stupid > rpm for it, or there wasn't a new enough version rpm available. Yes, > they install instantly, but they are not as up to date or > configurable. I've used suse a little and didn't like it. If I were to > try any other distro, it would probably be linux from scratch. Gentoo > has made my life so much better. I could go on and on..... but I > won't. > > Just curious what the python world uses and why. > > -Josh From brent.hughes at comcast.net Wed Aug 25 20:37:23 2004 From: brent.hughes at comcast.net (Brent W. Hughes) Date: Thu, 26 Aug 2004 00:37:23 GMT Subject: Idle problem Message-ID: <6haXc.183583$8_6.163380@attbi_s04> Sometimes when I try to start up idle.py (by double-clicking on the icon), I get the message: Python subprocess socket error: Connection refused, retrying.... It repeats the message a couple of times and then prints: Connection to Idle failed, exiting. Any idea what's going on? From markus_wankusGETRIDOFALLCAPS at hotmail.com Thu Aug 26 08:53:58 2004 From: markus_wankusGETRIDOFALLCAPS at hotmail.com (Markus Wankus) Date: Thu, 26 Aug 2004 08:53:58 -0400 Subject: Larry Wall & Cults In-Reply-To: References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: >>I think you're getting confused with the Blue ?yster Cult. >>Don't Fear the Reaper - great song. > > It was a great song, but it needed more cowbell... Mark. From me at privacy.net Mon Aug 16 11:33:23 2004 From: me at privacy.net (Richard Hanson) Date: Mon, 16 Aug 2004 08:33:23 -0700 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> <56cfb0e3.0408142004.511a8a8e@posting.google.com> <5hbvh0hnngn8sotqkgav3o1mvs61n039e5@4ax.com> Message-ID: [Re Python's indentation -- "Neat!" or "Yuck!"] For the record, my first reaction to *braces* years ago, was: "Yuck!" ;-) stirring-the-pot-ly y'rs, Richard -- R Hanson [The mangled email addie below works.] sickolefartnewsguycom From meldron at meldron.org Mon Aug 23 03:55:49 2004 From: meldron at meldron.org (Bernd Kaiser) Date: Mon, 23 Aug 2004 09:55:49 +0200 Subject: 100 % portable ? In-Reply-To: References: Message-ID: <2otm5mFed44hU1@uni-berlin.de> You can use os.environ["HOME"], this will return the user's home dir. Roger Binns wrote: > Note that for some things you would want different code. For > example the default location to save files may be My Documents > on Windows and $HOME on Linux and Mac. Similarly you would > want to save configuration settings in the registry on Windows > and dot files on Linux and Mac. From indigo at bitglue.com Mon Aug 23 20:15:08 2004 From: indigo at bitglue.com (Phil Frost) Date: Mon, 23 Aug 2004 20:15:08 -0400 Subject: Getting at the bits of a 32-bit integer In-Reply-To: <85b54e91.0408231552.75f85727@posting.google.com> References: <85b54e91.0408231552.75f85727@posting.google.com> Message-ID: <20040824001508.GB24354@unununium.org> If you really want to do that, you can use the bitwise "and" and "or" operators to unset/set bits, respectivly. For example, if you want to set bit 9, that's 0x0100, or 0000 0001 0000 0000 in binary. The integer 'i' with bit 9 unset is 'i & ~0x0100' (~ is the one's complement or bitwise not operator; it inverts all the bits), and 'i | 0x0100' is 'i' with bit 9 set. You can also use the bitwise exclusive or "^" to toggle a bit, like 'i ^ 0x0100'. However, doing this sort of thing is rather nonpythonic. Python abstracts the platform's representation of an integer. Integers in Python arn't always 32 bits; they are actually the size of C's 'long' type, which is to say you can find the size by looking at sys.maxint, but it's more trouble than it's worth. You will also encounter problems if you change the highest bit: >>> 10 ^ (1 << 31) __main__:1: FutureWarning: x< Hi there list, > > I'm a beginning programmer, so please correct me if any of the > following assumptions are wrong. > > Suppose I have the decimal number 255. Since integers in Python are 32 > bits, it would look like this in binary: > > 00000000 00000000 00000000 11111111 > > There are plenty of unused bits to the left of the number itself. If I > wanted to use some of these bits as true/false flags, how would I go > about it? In Python, how do I write code that gets at the leftmost > byte, or the third bit from the left of the set of 32, or the > rightmost byte plus the bit to its left, etc... > > Thanks in advance for any help on this. :) From ajsiegel at optonline.com Thu Aug 26 08:34:16 2004 From: ajsiegel at optonline.com (Arthur) Date: Thu, 26 Aug 2004 12:34:16 GMT Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> Message-ID: On Thu, 26 Aug 2004 17:31:16 +1000, Anthony Baxter wrote: >On Wed, 25 Aug 2004 19:47:35 -0400, Paul Morrow wrote: >> What you're trying to illustrate (I believe) is a superclass doing >> something based on the docstring of a subclass. Yes this certainly does >> happen. But the superclass and subclass are separate objects. I was >> talking about the situation where a function does something based on >> /its own/ metadata. That is what I'm saying virtually never happens, >> and therefore it's ok to make all assignments to __xxx__ attributes >> inside of a function def create /function attributes/ rather than /local >> variables/. > >This is an extraordinarily complex idea - you're proposing that inside >a function there is now access to a brand new namespace, that of the >function object itself. I don't think you appreciate just _how_ much >work this would requre, nor the complexity of trying to explain this >to users. Remember, at the moment, you can't even get access to the >function object itself from inside the function, without using a hack >like sys._getframe() or raising an exception. > >Putting aside nested scopes for the moment, there are three namespaces >that are used in Python - local, module level global, and builtins. >You're proposing that there is a new namespace, that of the function >object, and that it only be used by accessing any local variable that >starts or ends with two underscores. At the moment, the scoping rules >for Python are _extremely_ simple. Do you really want to add something >like this, that looks like a hack, smells like a hack, and who's >implementation would be a hack? I know I don't want to see something >like this. Though I am learning stuff by trying to keep up with this conversation - I should probably stay out of it, directly. But, as I publically demonstrated in my confusion about __name__ ...to someone educated from within Python, mostly by chucking out code, rather than reading documentation - that __name__ accessed from within the function body is something totally different from __name__ accessed from outside of it, was not what I think the language taught me to expect. I might have intuited that to expect otherwise would be "magic", but thought, somehow, that the __xxx__ implied the availability of that kind of magic. In other words, it would have surprised me less to have been right than to have benn wrong. Though I have learned not to be shocked about being wrong ;) And can understand the possiblity that others with other backgrounds might be surprised if I had been right. Does """ Namespaces are one honking great idea -- let's do more of those! """ come into play here at all? Art From jeff at ccvcorp.com Wed Aug 11 18:02:09 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Wed, 11 Aug 2004 15:02:09 -0700 Subject: 'break' Causes Execution of Procedure? In-Reply-To: References: <10hkq3u54ht2h4e@corp.supernews.com> Message-ID: <10hl5q9p2m53g59@corp.supernews.com> Scott Brady Drummonds wrote: >After reading your suggestion, I'm wondering why I caught the exception in >the loop as opposed to outside of the loop. I changed the implementation as >you suggested and my program is now working correctly. Of course, something >tells me that I just covered up a bug as opposed to removing it. > > Probably you're right about that. Better to use your original code to figure out what's going wrong, than to proceed with changed code that might not fix the problem. Once you've found the bug, *then* you can switch to catching the exception outside of the loop. ;) If your main() function has so much code, then try breaking that down into several smaller functions. It's almost certain that you can break a large function into several logical "sections"; if you make each of those sections into a separate function, it'll probably be easier to isolate the specific problem. As an example, you could probably isolate that for loop within a subfunction -- def ProcessCycleMap(cycleMap, keys, skipList): for cycle in keys: .... You may also want to go through your code and verify that you don't have anyplace that mixes tabs and spaces, which can lead to invisibly mismatched indentation. It may be that the compiler sees your code structure a bit differently than you do... (Best procedure here is to simply run tabnanny.py over your code.) Jeff Shannon Technician/Programmer Credit International From JSmuts at clover.co.za Mon Aug 2 02:57:16 2004 From: JSmuts at clover.co.za (Jaco Smuts) Date: Mon, 2 Aug 2004 08:57:16 +0200 Subject: MySQLdb select In-Reply-To: <410BAE49.7000000@ghaering.de> Message-ID: Gerhard That's sounds like great advice, not sure I've seen documentation on how to do this though? Could you maybe provide us with a sample on how to do this. thanks a lot jaco Gerhard H?ring Sent by: python-list-bounces+jsmuts=clover.co.za at python.org 07/31/2004 04:35 PM To: python-list at python.org cc: Subject: Re: MySQLdb select F. GEIGER wrote: That's particularly BAD STYLE. It's best to keep to letting the DB-API do the proper quoting for all parameters. -- Gerhard -- http://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From iketo2 at netscape.net Sat Aug 14 12:13:37 2004 From: iketo2 at netscape.net (Isaac To) Date: 15 Aug 2004 00:13:37 +0800 Subject: Regular Expressions References: Message-ID: <874qn53dfy.fsf@sinken.local.csis.hku.hk> >>>>> "Jens" == Jens Thiede writes: Jens> What is the easiest way to generate a list that contains all Jens> the remnants of re.findall (the inverse of the following). You mean, complement? Jens> re.split doesn't seem to work quite well Why? >>> obj=re.compile(r'.*?', re.S|re.I) >>> obj.split('defabc\n defghi jkl\nmno\nabchaha') ['def', 'ghi jkl\nmno\n', 'haha'] >>> obj.findall('defabc\n defghi jkl\nmno\nabchaha') ['abc\n def', 'abc'] >>> obj=re.compile(r'.*', re.S|re.I) >>> obj.split('defabc\n defghi jkl\nmno\nabchaha') ['def', 'haha'] >>> obj.findall('defabc\n defghi jkl\nmno\nabchaha') ['abc\n defghi jkl\nmno\nabc'] Looks like it is doing the job, right? Regards, Isaac. From thomas.krueger at gmx.net Tue Aug 31 06:40:02 2004 From: thomas.krueger at gmx.net (Thomas =?ISO-8859-1?Q?Kr=FCger?=) Date: Tue, 31 Aug 2004 12:40:02 +0200 Subject: invalid token problem ? References: <5db3bf00.0408310133.39de601c@posting.google.com> Message-ID: tag wrote: > Can anyone please explain why I am getting the error ? What am I > missing ?? Well the answer is already given: > xml.sax._exceptions.SAXParseException: :21:56: not well-formed Your XML is not well-formed. All quotation marks in CDATA fields (outside of a tag) must be quoted to ". You XML should be: ="Actual Asset mix "&text($C$46,"dd-mmm-yyyy") Thomas From anthonybaxter at gmail.com Fri Aug 13 02:37:54 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 13 Aug 2004 16:37:54 +1000 Subject: Why I love python. In-Reply-To: References: Message-ID: On 12 Aug 2004 17:05:34 -0700, Michael Scarlett wrote: > [ pie decorators ] > Am i the only one with a > visceral reaction to this thing??? So did you have a similar reaction on first hitting the indentation for blocks? I know I dimly recall thinking that this was very strange and horrible (dimly, because it was 1992 or 1993). From tjreedy at udel.edu Tue Aug 10 16:31:39 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 10 Aug 2004 16:31:39 -0400 Subject: IronPython-0.6 is now available! References: <278de0e.0407281353.27b6a457@posting.google.com> <278de0e.0408100515.5fd3740c@posting.google.com> Message-ID: > The good thing about the future stable version of Ironpython, is that > your code will be able to interoperate with code written in other .NET > compliant languages, and its performance will be better than the > standard implementation. These are, of course, predictions, not facts. As to performance: IP ran some features faster and some slower. It is possible the the features tested are a biased sample. It will be interesting to see the final result. In any case, it is standard to do time-consuming numerical computation in Python with the quasi-standard numerical extensions. Unless and until the these are ported to .NET, such programs will not run. Even when they do, there is no reason to think that they will be significantly faster. So some programs may benefit, other may not. Terry J. Reedy From bh at intevation.de Thu Aug 12 11:10:46 2004 From: bh at intevation.de (Bernhard Herzog) Date: Thu, 12 Aug 2004 17:10:46 +0200 Subject: decorator with ``` References: Message-ID: Roman Suzi writes: > ```staticmethod``` > def makeDecoratorSyntax(spec=None): > raise NotImplementedException() That's already legal Python, although it's not very useful: >>> ```staticmethod``` '\'""\'' >>> def makeDecoratorSyntax(spec=None): ... raise NotImplementedException() ... >>> Bernhard -- Intevation GmbH http://intevation.de/ Skencil http://sketch.sourceforge.net/ Thuban http://thuban.intevation.org/ From a at b.com Tue Aug 17 10:11:45 2004 From: a at b.com (wonder) Date: Tue, 17 Aug 2004 22:11:45 +0800 Subject: passing the url of the current webpage to python script Message-ID: Dan Greenblatt wrote: > wonder wrote: > >> Hi, >> >> How can I pass the url of the current webpage link to a python script in html? >> >> thanks >> sam > > > are you using a python script as a helper application? yeah, sort of. I m building a html page that will call a python script by passing it the current URL of the webpage. The html page will be opened by any web user with any web browser. thanks sam From anthonybaxter at gmail.com Tue Aug 24 04:17:59 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Tue, 24 Aug 2004 18:17:59 +1000 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 23) In-Reply-To: References: Message-ID: On Tue, 24 Aug 2004 09:14:05 +0200, Peter Otten <__peter__ at web.de> wrote: > The fraction of your posts I have read went from (I'm sharpening) > "What crap are you proposing as an alternative to '@'? Guido won't listen > anyway" to "If you want it, at least get it right" > I liked that and that's why you are in the Python-URL. That's probably a way of reading it - although I think my original "Guido won't listen" were more probably "Guido doesn't care about people voting that they hate a syntax". Dictators are like that. And yes, some of my posts could probably be interpreted as "what crap is this?" On the other hand, I've been really quite impressed how much useful effort has been channelled out what were initially quite rabid posts (on both sides ) into a useful result (the J2 paper, the J2 implementation). It speaks positively about the python community that this was done, and done, by and large, without much participation from any of the existing python developers[1]. Regardless of what result comes out of this, I think that this has been a good thing - as I think I commented earlier in this thread, after the mega-horror of the ternary operators meltdown, it's good to see from the point of view of community involvement in the language. [1] I don't count my snarking as a particularly useful form of participation - more a combination of trying to keep people honest and my normal contrariness. From t-meyer at ihug.co.nz Tue Aug 10 03:05:52 2004 From: t-meyer at ihug.co.nz (Tony Meyer) Date: Tue, 10 Aug 2004 19:05:52 +1200 Subject: Python equivalent to a C trick In-Reply-To: Message-ID: > Is there a python equivalent of this trick in C? > > Logic_Test ? True_Result : False_Result Happily , no. See: =Tony Meyer From lconrad at laymusic.org Fri Aug 6 17:15:13 2004 From: lconrad at laymusic.org (Laura Conrad) Date: Fri, 06 Aug 2004 17:15:13 -0400 Subject: Killing children References: <87smb0w4ln.fsf@debian.laymusic.org> <87d624vxt2.fsf@debian.laymusic.org> <2eidnefxXqX3co7cRVn-tA@powergate.ca> Message-ID: <878ycsvuhq.fsf@debian.laymusic.org> >>>>> "Peter" == Peter Hansen writes: Peter> Laura Conrad wrote: >> p = os.spawnl(os.P_NOWAIT, "/usr/bin/python", "python", "hobo.py", '/dev/ttyS0', 5) >> print p >> os.system("ps") >> time.sleep(60) >> os.system("kill %d" % p) Peter> This suggests that you believe the return value from os.spawnl() is Peter> actually the PID. Unfortunately that doesn't appear to be the case Peter> on Windows. See the note in the doc-string for my code sample from Peter> the previous post (on Windows spawn* actually returns a "handle", Peter> not the PID itself, and apparently turning the one into the other Peter> is non-trivial). So you think os.kill(p) might be the way to kill it? But does anyone know how to get it started right? -- Laura (mailto:lconrad at laymusic.org , http://www.laymusic.org/ ) (617) 661-8097 fax: (501) 641-5011 233 Broadway, Cambridge, MA 02139 From sandysj at juno.com Thu Aug 26 17:00:14 2004 From: sandysj at juno.com (Jeff Sandys) Date: Thu, 26 Aug 2004 21:00:14 GMT Subject: Best GUI- Python for children - pygame and blender32 References: Message-ID: <412E4F5E.6C836AF3@juno.com> I made the mistake of trying to teach computer programming with the goal of writing a game, and ended up alienating all the students. First, the students who were serious about learning about programming, to use the computer as a tool, never returned after they learned we were going to write a game. All that was left were students with low attention spans, who played Doom, and wanted to make their own Doom game. They weren't interested in something simple like starting with Pong or Hunt the Wampus. I would advise teaching programming as a serious craft that can also be fun. Most programmers believe that programming is the greatest game of all. Take a look at Georgia Tech's Intro to Media Computing, a CS class for non-majors. The first project is to use a blue screen background to put a picture of themselves in another picture. It is just a few lines of code but they learn about data, functions, loops and the if statement. The JIT approach is used in this class. http://coweb.cc.gatech.edu/mediaComp-plan If you are serious about 3D I would use VPython for dynamic images and POVRay for static 3D. Check out Kirby Urner's stuff: http://www.4dsolutions.net/ocn/oop.html For a 2d GUI, wxpython works cleanly on most all platforms, but it isn't easy. If you want 2d GUI I would focus on web and html generation, most kids know a little html. Pygame is a nice cross platform package, but again it is not easy. If students could write a Pygame in a few weeks of classtime the Pygame site would be full of games. Check out Sean Riley's _Game Programmign with Python_ or this site: http://childsplay.sourceforge.net If you really want games I would look at David Ahl's old Basic computer games books. These are text terminal type of games like 'hunt the wampus' that are fun and teach the basic organization of programming and games, and are do-able! If you have a web server these games could be ported to python to run on the web, your school will never forgive you. My approach will be that of a guild with apprentices, journeymen and masters. I'll teach the apprentices the basics, they'll work in pairs. Once they have a good understanding of Python, they will bea journeyman who pairs with a master. The master can write complete programs with very little outside help. They'll get their projects from a list the teachers make, or can work on their own project. The completed projects will be posted on a webserver where anyone can download them. Popular projects will be converted into web applications. I'm trying to get the teachers or school to pay for the projects so that we can reward the students. What age group are you working with? I'm working as a volunteer in an after school 7th and 8th grade programming club. I do incourage you to continue working on your tutorial and share your progress on the Python edu-sig: http://www.python.org/sigs/edu-sig/ Thanks, Jeff Sandys Andr? Roberge wrote: > ... > I am learning Python (which, as everyone know is the best language :-) > so that I can write a tutorial to teach my kids about computer > programming. The motivation for them will be to use Python to create > their own games using pygame and, eventually, blender3d. From d-hanst at online.no Wed Aug 11 15:59:43 2004 From: d-hanst at online.no (Dag Hansteen) Date: Wed, 11 Aug 2004 21:59:43 +0200 Subject: Question Message-ID: <002b01c47fdd$bf0c2280$4e01a8c0@dagan> I make a GUI calculator in wxPython. How can I do the following without having to use eval?: def OnCalc(self, event): try: regnestykke = self.formel.GetValue() svar = eval(regnestykke) svar = str(svar) self.answer.SetValue(svar) except: self.answer.SetValue("Error! Check Syntax!") """ self.formel is defined as wxTextCtrl for the input from user to be calculated self.answer is defined as wxTextCtrl for the answer of the users input """ "Thomas Kr?ger" skrev i melding news:cf8ehd$kuk$03$1 at news.t-online.com... > Dag Hansteen wrote: > > >>>> s = "2+2" > >>>> answer = int(str(s)) > > Traceback (most recent call last): > > File "", line 1, in ? > > answer = int(str(s)) > > ValueError: invalid literal for int(): 2+2 > > > > How do I this ? I have a string with a such expression and I want to > > return the answer in a variable. > > eval('2+2') > -> 4 > > Thomas > > -- > http://mail.python.org/mailman/listinfo/python-list > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From robin at SPAMREMOVEjessikat.fsnet.co.uk Wed Aug 18 03:51:31 2004 From: robin at SPAMREMOVEjessikat.fsnet.co.uk (Robin Becker) Date: Wed, 18 Aug 2004 08:51:31 +0100 Subject: Is it possible to write a DLL using python In-Reply-To: <2e363c08.0408171234.5ceaf1c7@posting.google.com> References: <2e363c08.0408171234.5ceaf1c7@posting.google.com> Message-ID: <41230A83.9050302@jessikat.fsnet.co.uk> Paul Miller wrote: > AMD wrote in message news:... > > >>I need to write a Win32 DLL and I would like to use Python instead of >>VB, C++ or Delphi. Is this possible? > > > No. It is possible to interface to and from Python via other > languages, but since Python does not create native code, you cannot > create a DLL with it. This is not strictly true. At work I have made DLLs which encapsulate the base python code and then link themselves to a specialized version of Python (to avoid clashes with any other python). At the extreme we made a Darwin shared library which encapsulated our application code and the whole of python. I made use(misuse probably) of the freeze tool to accomplish this latter. The result was a single binary .so with a simple interface that used python internally. Python doesn't make this easy (the startup is fairly complex), but it is possible. -- Robin Becker From apardon at forel.vub.ac.be Tue Aug 31 06:33:07 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 31 Aug 2004 10:33:07 GMT Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> <87hdqok9i6.fsf@sinken.local.csis.hku.hk> <1rfz68ely9.fsf@rovereto.ifi.uio.no> <876574k7du.fsf@sinken.local.csis.hku.hk> <1r3c28ejis.fsf@rovereto.ifi.uio.no> <1rllg0cb3m.fsf@rovereto.ifi.uio.no> <874qmovxna.fsf@sinken.local.csis.hku.hk> Message-ID: Op 2004-08-28, Isaac To schreef : >>>>>> "Kjetil" == Kjetil Torgrim Homme writes: > > Kjetil> I find this attitude a little defensive. Python has much > Kjetil> more to offer than just strict indentation. although it's > Kjetil> probably the feature you notice first, it's not enough to > Kjetil> make Python a superior language. > > For me, it is *the* feature that make it stands out from the scripting > crowd. There are other things nice in Python, but as long as there is > one big enough killing feature, people will use the language enough to > add others. > > Kjetil> after all, code in _any_ language written by a > Kjetil> professional will have strict indentation. so it's just > Kjetil> syntax. > > No. In all other languages, people deal with *two* ways to find which > statement is associated with an if/while/for/whatever statement and > which is not: by looking at the indentation, and by looking at the > braces. They normally look at the indentation, since it is the > quicker way. But when they find something wrong, they look at the > defining braces, sometimes deeply hidden in long expressions and > statements combined into one line. In Python, we have *one and only > one* way to find which statement is associated with an > if/while/for/whatever statement, and this is the quicker way that > people are used to. I doubt that. I used to limit myself to indentation to see which code belonged to which control. But then I found myself witch controls that were so nested it was hard to see to which if a particular else suite belonged and I started to use end markers in comments to make the structure more visible. > This single feature reduces the amount of bugs > that you would introduce when editing and modifying code. Yes it does, but so does a language that enforces endmarkers. > More > importantly, this single feature allows you to be much less stressed > when editing code. IME the use of end markers helps too. -- Antoon Pardon From pje at telecommunity.com Wed Aug 4 22:14:41 2004 From: pje at telecommunity.com (Phillip J. Eby) Date: Wed, 04 Aug 2004 22:14:41 -0400 Subject: PyProtocols 0.9.3 Final Message-ID: <5.1.1.6.0.20040804221232.0225d770@mail.telecommunity.com> As there were no further bugs reported for PyProtocols 0.9.3rc2, PyProtocols 0.9.3 final is now available for download. There are no practical changes from rc2, except for file and documentation revision numbers and dates. What is PyProtocols? -------------------- PyProtocols is an extended implementation of PEP 246, adding a new "declaration API" that lets you easily define your own interfaces and adapters, and declare what adapters should be used to adapt what types, objects, or interfaces. Using PyProtocols, you can easily make flexible frameworks that you or other developers can extend without needing to modify the base framework. PyProtocols interfaces can interoperate with those of Twisted and Zope, or can be used entirely standalone. PyProtocols may be used, modified, and distributed under the same terms and conditions as Python or Zope. What's new in version 0.9.3? (Highlights) -------------------------------------------- * Adapter factories can now accept just one argument, the way Twisted and Zope adapters do. * Interface and protocol objects can be called, as a shortcut for 'adapt()' (as Zope and Twisted interfaces do) * You can now more easily install PyProtocols without a C compiler, using the '--without-speedups' option to 'setup.py' (see the README.txt file for details.) * Numerous other bug fixes and enhancements - see CHANGES.txt for details. IMPORTANT: If you are upgrading from a previous version of PyProtocols, please read UPGRADING.txt for important information. Certain rarely-used features have been deprecated, and others have changed slightly. Most users should not experience any problems (except perhaps for DeprecationWarnings), but please be sure to verify this before you upgrade any production code from 0.9.2 to 0.9.3. PyProtocols Resources --------------------- * Upgrading to PyProtocols 0.9.3 (and a look ahead to 1.0) http://peak.telecommunity.com/protocol_api/UPGRADING.txt.html * Detailed Changes for all releases: http://peak.telecommunity.com/protocol_api/CHANGES.txt.html * Release notes, installation instructions, and browsable API docs: http://peak.telecommunity.com/protocol_api/ * Source and Binary Releases: http://peak.telecommunity.com/dist/ * Reference Manual (HTML): http://peak.telecommunity.com/protocol_ref/module-protocols.html * Reference Manual (PDF): http://peak.telecommunity.com/protocol_ref.pdf * Browsable CVS Repository: http://cvs.eby-sarna.com/PyProtocols/ From FBatista at uniFON.com.ar Fri Aug 6 14:36:22 2004 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Fri, 6 Aug 2004 15:36:22 -0300 Subject: Extending python. Message-ID: Maybe this will help you: http://www.python.org/doc/faq/extending.html . Facundo #- -----Mensaje original----- #- De: Grzegorz Dostatni [mailto:grzegorz at ee.ualberta.ca] #- Enviado el: Viernes, 06 de Agosto de 2004 13:35 #- Para: python-list at python.org #- Asunto: Extending python. #- #- #- #- Cheers. #- #- More questions. #- Let's say I'm trying to extend python with a c module. That #- module cannot #- be dynamically loaded (for reasons outside my control). I #- have to create a #- custom python executable (or more likely custom python library). #- How would I do that? Is there documentation on that #- somewhere? Most of #- what I've seen was for dynamic loading. #- #- 2nd Step: #- Let's say I'm doing it under windows, using Visual Studio. Is there #- anything I have to be aware of? #- #- 3rd Step: #- Let's say I don't have the source available. I do have the #- object files, #- the resulting libraries and the header files though. #- #- Greg #- #- "The optimist proclaims that we live in the best of all #- possible worlds, #- and the pessimist fears this is true." #- - James Branch Cabell #- #- #- -- #- http://mail.python.org/mailman/listinfo/python-list #- From http Fri Aug 27 15:05:33 2004 From: http (Paul Rubin) Date: 27 Aug 2004 12:05:33 -0700 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> Message-ID: <7xzn4gwgea.fsf@ruckus.brouhaha.com> aleaxit at yahoo.com (Alex Martelli) writes: > > Here is a python feature that I would like: to be able to import modules > > from an archive like the jar files in Java. Maybe a regular tar file? > > Python 2.3 lets you import modules from a zipfile. The zip format is > better than tar when you just need to get one file from it, which is why > java's jar files are also basically zipfiles. Jar files are -signed- zip files. Is there some reason to not do that for Python? From rnd at onego.ru Fri Aug 13 12:55:39 2004 From: rnd at onego.ru (Roman Suzi) Date: Fri, 13 Aug 2004 20:55:39 +0400 (MSD) Subject: def ... decorate In-Reply-To: <16668.57321.308134.676624@montanaro.dyndns.org> References: <16668.57321.308134.676624@montanaro.dyndns.org> Message-ID: Bingo! Just replace decorate with "from" and the nice syntax is found: def f: staticmethod grammarrule('statement : expression') version("Added in 2.4") deprecatedmethod type_(None) from self, p: """docstring here""" print p[1] or special short variant for one-liners: def n staticmethod from (self, p): return p[1] (Though I wonder why not just n = staticmethod(lambda self, p: p[1]) ) (I've added details to the PythonDecorators wiki) On Fri, 13 Aug 2004, Skip Montanaro wrote: >>>>>> "Nick" == Nick Craig-Wood writes: > > Steven> decorate: > Steven> grammarrule('statement : expression') > Steven> versioninfo("Added in 2.4") > Steven> deprecated > Steven> typeinfo(None) > Steven> def p_statement_expr(self, p): > Steven> print p[1] > > Nick> as: > Nick> staticmethod > Nick> grammarrule('statement : expression') > Nick> version("Added in 2.4") > Nick> deprecatedmethod > Nick> type_(None) > Nick> def p_statement_expr(self, p): > Nick> print p[1] > >How about > > def p_statement_expr: > staticmethod > grammarrule('statement : expression') > version("Added in 2.4") > deprecatedmethod > type_(None) > decorate (self, p): > """docstring here""" > print p[1] > >Read it something like "define a function named p_statement_expr using a >bunch of functions to decorate the basic function". > >It solves a couple problems: > >1. "def" introduces the function definition instead of an arbitrary number > of @-expressions. > >2. There is no extra indentation of the main body. > >3. The name of the function is known early on. > >4. "def"/"decorate" pair up visually much the same as "try"/"except" or > "if"/"then", though they don't represent alternative blocks of code to be > executed. > >On the minus side it introduces a vertical separation between the function >name and parameter list and introduces a new keyword, "decorate". > >>From a parsing standpoint I think it will work. You'll see either a colon >or a left paren after the function name to distinguish between the two types >of function definition. I'm not sure if a token needs to be used to >separate the various decorator functions or if requiring a newline and >indentation is sufficient. > >Skip > Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3 From mauriceling at acm.org Mon Aug 2 22:06:16 2004 From: mauriceling at acm.org (Maurice LING) Date: Tue, 03 Aug 2004 02:06:16 GMT Subject: Call for Grant Proposals In-Reply-To: References: <40fcaa90$0$27091$9b622d9e@news.freenet.de> <41097fed$1@news.unimelb.edu.au> <410DF640.4010307@acm.org> <410DF824.8070309@acm.org> <410ED411.7090907@acm.org> Message-ID: <410ef314$1@news.unimelb.edu.au> Hi, At the same time, there are other questions besides an issue with open source or close source development. These 4 questions in my original email are probably more important to me, personally... 2. Will there be any form of intellectual property claims, including, copyrights, trade marks, patents, on any form of work generated from the PSF Grant by the Python Software Foundation (PSF) or any of its associates? If so, what are the precise nature of it? This is important as it may injure the research work and subsequently, the resultant thesis and publications directing towards the award of my degree. 3. On the website (http://www.python.org/psf/call-2004.html), it is stated that the project of which the grant is granted for must be completed by October 30, 2005. In event of failure to meet, what will be the penalities? 4. From Question 3, what constitutes partial failure or complete failure of the project? 5. From Question 4, it is stated on the website (http://www.python.org/psf/call-2004.html) that a delivery plan is essential in the proposal. How will delay in delivery affect the payment plan and the grant on the whole? The answers to these questions are something that the grant committee can answer now as it involves internal policy. As for Question 2, I cannot be in a project that will take up my time and cannot be directed towards the award of my degree. The next 3 questions deal closely with my lab's financial budgetting and without any answers to these questions, I can be in dire straits when things doesn't go as planned. Maurice Tim Peters wrote: > [Maurice Ling, wants to know whether PSF grants require funded work to be > open-sourced, etc] > > While I'm a PSF Director, I'm not on the Grants Committee and don't > speak for them. > > I'll just note that since the PSF is a public charity (under US tax > law), there are a lot of rules the PSF has to comply with when > distributing its funds. I expect that answering your questions will > require paying a lawyer to spell out what's possible. I don't know > what they'll say. In general, the PSF is required to act in the > public interest. > > That said, the PSF doesn't have a ton of money, and there will almost > certainly be more worthy requests for funding than there are funds to > pass out. Proposals will therefore compete. If I were on the Grants > Committee, whether a proposal would benefit the public at large would > be a major consideration for me. IOW, I think it's predictable-- and > appropriate --that proposals to fund open-source work will "score > points" for that reason alone. -- Maurice Han Tong LING, BSc(Hons)(Biochem), AdvDipComp, SN Doctor of Philosophy (Science) Candidate, The University of Melbourne mobile: +61 4 22781753 +65 96669233 mailing address: Department of Zoology, The University of Melbourne Royal Parade, Parkville, Victoria 3010, Australia residential address: 9/41 Dover Street Flemington, Victoria 3031, Australia email: mauriceling at acm.org resume: http://maurice.vodien.com/maurice_resume.pdf www: http://www.geocities.com/beldin79/ The information contained in this message, including its attachment(s), is CONFIDENTIAL and solely intended to its addressee(s) only. The content of this message, including its attachment(s), may be subjected to copyright and privacy laws. If you have received this email in error, please let me know by returning this email, and then destroy all copies. "I cannot discover anyone knows enough to say definitely what is and what is not possible" -Henry Ford "The difference between the impossible and the possible lies in a person's determination" -Tommy Charles Lasorda From narshe at gmail.com Mon Aug 16 12:33:54 2004 From: narshe at gmail.com (Josh Close) Date: Mon, 16 Aug 2004 11:33:54 -0500 Subject: ConfigParser options spanning more than one line Message-ID: <4a0cafe204081609334d234877@mail.gmail.com> I'm using ConfigParser and I can't seem to get a config option to span more than one line. [MyConfig] var = blah blah blah\ blah continued Putting the '\' doesn't work Is there a way to do that? Or do I have to deal with having a huge long string all on one line? -Josh From arambo314 at hotmail.com Mon Aug 16 13:20:06 2004 From: arambo314 at hotmail.com (Arthur Rambo) Date: 16 Aug 2004 10:20:06 -0700 Subject: Best programming language References: Message-ID: <533e1e03.0408160920.4c26c794@posting.google.com> Roman Suzi wrote in message news:... > ;-) > > Just type into google > "best programming language" > and press (I am lucky) > > > Sincerely yours, Roman Suzi Just type into google "agile programming language" and press (I am lucky) Arthur From fumanchu at amor.org Thu Aug 26 13:37:57 2004 From: fumanchu at amor.org (Robert Brewer) Date: Thu, 26 Aug 2004 10:37:57 -0700 Subject: Call for signatories for J2 Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E86@exchange.hqamor.amorhq.net> > For Isn't *anyone* going to vote against? Or at least formally abstain? _Somebody_ out there must disagree strongly with this. Robert Brewer MIS Amor Ministries fumanchu at amor.org From nobody at nowhere.com Mon Aug 9 16:13:50 2004 From: nobody at nowhere.com (Fred) Date: Mon, 09 Aug 2004 22:13:50 +0200 Subject: VB-like GUI designer? References: <30260531.0408091048.7011855f@posting.google.com> Message-ID: On 9 Aug 2004 11:48:34 -0700, simoninusa2001 at yahoo.co.uk (simo) wrote: >> I tried wxDesigner and wxGlade, but neither lets me move the widgets >> around. > >Dunno what you're smoking there man! OK, I figured it out. Note to newbies: Read up on wxWidgets before using those two tools, at least its concept of "sizers"... >Qt Designer (for use with PyQt though) or just hand-code the layout, >it ain't that hard..... Thx but... not thx. That reminds me too much of the Petzold-era Windows in C :-) Cheers Fred. From jepler at unpythonic.net Sun Aug 15 10:28:04 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Sun, 15 Aug 2004 09:28:04 -0500 Subject: Numarray: Using sum() within functions In-Reply-To: <10hsvoka533ci3c@corp.supernews.com> References: <10hsvoka533ci3c@corp.supernews.com> Message-ID: <20040815142804.GA25402@unpythonic.net> On Sat, Aug 14, 2004 at 02:07:30PM -0700, Jim Cser wrote: > Instead, I'm trying to do something like-- > def f3(x,y,z): > for t in range(numT): > tempval = f1(x,y,z,t) * f2(y,z,t) > > outval = sum(tempval,axis = 3) > return outval Here, "tempval" takes on a series of values during the for loop, then "sum" is used on value from the final iteration of the loop. Perhaps you want something like def f3(x, y, z): temps = [] for t in range(numT): temps.append(f1(...) * f(...)) return sum(temps, axis=3) Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From tzot at sil-tec.gr Sat Aug 21 15:35:55 2004 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 21 Aug 2004 22:35:55 +0300 Subject: Interesting References: <412762fb@news01.argolink.net> Message-ID: On 21 Aug 2004 09:58:03 -0500, rumours say that Baykara Mullins might have written: >Interesting newsgroup! Modest remark! -- TZOTZIOY, I speak England very best, "Tssss!" --Brad Pitt as Achilles in unprecedented Ancient Greek From strawman at NOSPAM-DELETE-THIS.astraw.com Tue Aug 10 22:57:45 2004 From: strawman at NOSPAM-DELETE-THIS.astraw.com (Andrew Straw) Date: Tue, 10 Aug 2004 19:57:45 -0700 Subject: floating point exception (SIGFPE weirdness) In-Reply-To: References: Message-ID: <41198B29.7090600@NOSPAM-DELETE-THIS.astraw.com> I figured out that the culprit is in the numarray.ieeespecial module, which my Python code imports. The lines (taken from ieeespecial.py) import numarray.numarrayall as _na plus_inf = inf = _na.array(1.0)/_na.array(0.0) are sufficient to cause the behavior in my original post. I shall follow this up on the numpy discussion list. Andrew Straw wrote: > I'm running into trouble when calling a 3rd party library (the Intel IPP > library to do some fast math on a P4 processor). This is on debian > linux 2.6.7 using python 2.3.4. > > I've been using Pyrex to wrap my calls to this C library into an > extension module, and a certain function call within my extension module > (to the C function ippiAddWeighted_8u32f_C1IR) will terminate my Python > program when called for the 2nd time, with the line "Floating point > exception" mysteriously appearing on the console. (Mysterious in part > because I can't redirect these words with piping stdout or stderr.) I > should note that this function calls not only the normal Pentium > floating-point machinery, but should also call the SSE and SSE2 > instruction sets. > > A few clues: > > 1) A trivial C program which makes the same function call repeatedly > with the same data is not terminated. > > 2) Running the python executable under gdb causes the program to > continue running without terminating. > > 3) The behavior (termination) is not changed after rebuilding Python > from source, compiling with --with-fpectl and building the fpectl > module, calling fpectl.turnoff_sigfpe(). > > I don't really understand what is happening, but I'd like my code to run > without terminating due to this floating point exception. My best guess > is that SIGFPE is being generated by the C function call, and Python > does not catch it so the OS terminates Python. If this is so, however, > I'm not sure why Python should be terminated and why my simple C program > is not. Furthermore, I don't understand why gdb doesn't see SIGFPE if > this is the case. > > I would be very grateful if someone could tell me how to keep my program > running! > > Cheers! > Andrew From dave at pythonapocrypha.com Wed Aug 25 10:06:44 2004 From: dave at pythonapocrypha.com (Dave Brueck) Date: Wed, 25 Aug 2004 08:06:44 -0600 Subject: is this thread safe? In-Reply-To: <090f01c489c2$3beb3eb0$7f00a8c0@scl01.siliconcreation.com> References: <090f01c489c2$3beb3eb0$7f00a8c0@scl01.siliconcreation.com> Message-ID: <412C9CF4.10600@pythonapocrypha.com> Joe Wong wrote: > I have a variable that need to be incremented by 1 as follow: > > v += 1 > > Is this threadsafe? Do I need to put a lock around this? No[1], yes[2]. -Dave [1] A context switch could happen between adding and saving the value: >>> import dis >>> def inc(): ... global v ... v += 1 ... >>> dis.dis(inc) 3 0 LOAD_GLOBAL 0 (v) 3 LOAD_CONST 1 (1) 6 INPLACE_ADD 7 STORE_GLOBAL 0 (v) 10 LOAD_CONST 0 (None) 13 RETURN_VALUE [2] Without locking, you get incorrect results: import threading, time ADD_COUNT = 1000000 THREAD_COUNT = 3 v = 0 def Worker(): global v for i in xrange(ADD_COUNT): v += 1 threads = [] for i in range(THREAD_COUNT): t = threading.Thread(target=Worker) threads.append(t) t.start() for thread in threads: thread.join() assert v == ADD_COUNT * THREAD_COUNT, v From h.b.furuseth at usit.uio.no Tue Aug 31 18:23:13 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 01 Sep 2004 00:23:13 +0200 Subject: Are decorators really that different from metaclasses... References: <20040830024246.GA2159@unpythonic.net> Message-ID: Paul Morrow wrote: >Jeff Epler wrote: >> In your proposed model, what does the following code do? >> def f(): >> __var__ = 3 >> return __var__ >> f.__var__ += 1 >> print f() >> > > Only assignments to __xxx__ variables at the very start of a function > def would have this special semantics. So your return statement would > be referencing a name (__var__) that doesn't exist in the function's > local variable namespace. No, that would silently return a surprising result if __var__ existed in the global namespace. Better make it a syntax error or something. -- Hallvard From fuzzyman at gmail.com Wed Aug 25 08:35:23 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 25 Aug 2004 05:35:23 -0700 Subject: Python and C, looking for a C IDE References: <6f402501.0408240353.2a5b8a84@posting.google.com> <0h1ni0hjqggrk2atp7ao31a6l1dn2ctobk@4ax.com> Message-ID: <6f402501.0408250435.348fd3a5@posting.google.com> Fred wrote in message news:<0h1ni0hjqggrk2atp7ao31a6l1dn2ctobk at 4ax.com>... > On 24 Aug 2004 04:53:13 -0700, fuzzyman at gmail.com (Michael Foord) > wrote: > >I'm looking to learn C to move some 'speed sensitive' code from C to > >python. I'm partly doign this as an exercise to learn a static > >language to help broaden my programming skills - so please don't jump > >on the bandwagon and tell me I'd be better placed to put my efforts > >into optimising my python code !! > > ... or you could take a look at writing this speed-sensitive part in > PowerBasic. The speed and size of C, without the hassles :-) > > http://www.powerbasic.com/products/pbdll32/ > > I haven't yet looked at how to compile a DLL in PowerBasic and call it > from Python, but it's on my to-do list. > Fred. Hmm... commercial, non cross platform... not for me - sorry. I'd quite like to learn C anyway. Probably tackle lisp after that - which is also (generally) a lot faster than python.... Regards, Fuzzball http://www.voidspace.org.uk/atlantibots/pythonutils.html From aleaxit at yahoo.com Tue Aug 31 07:04:14 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Tue, 31 Aug 2004 13:04:14 +0200 Subject: Generator expressions v/s list comprehensions References: <1gj8y77.6qshr41q531veN%aleaxit@yahoo.com> <87llfywooz.fsf@sinken.local.csis.hku.hk> <1gjbs1e.assxlxlud1m0N%aleaxit@yahoo.com> Message-ID: <1gjdvx3.tjc3nb1266bpkN%aleaxit@yahoo.com> Michael J. Fromberger wrote: ... > > Unfortunately, this wish is totally unrealistic -- obviously people do > > come up with cool ideas such as the iterator protocol, and generators, > > after the language has been around for a while. > > All the cool features Python has adopted existed a long time before they > made their way into Python itself. Almost all, not all. As I repeatedly explained, for example, generator comprehensions are not quite like anything in other languages (though you can surely find _similarities_, of course). > Frankly, I think if the Lisp world had managed to build the same > friendly and welcoming community Python seems to have, it would have > taken over the world a quarter-century ago. I think most people's reaction to (==against) Lisp's parentheses and prefix syntax is more intense than that to Python's significant whitespace, which appears quite natural to most non-programmers even though many programmers inured to block delimiters do react strongly against it. It's hard enough for Python to keep its community welcoming and friendly when you hear some clueless dweeb rant against indendation for the thousandth time, I think the Lisp community would have had to be made up of saints to be still friendly and welcoming after a _million_ newcomers raised their whining against parentheses. Alex From cappy2112 at yahoo.com Thu Aug 5 20:51:18 2004 From: cappy2112 at yahoo.com (Tony C) Date: 5 Aug 2004 17:51:18 -0700 Subject: Decorator syntax References: Message-ID: <8d3e714e.0408051651.7c91a5c4@posting.google.com> > This is backwards compatible (Python <= 2.3 raise > SyntaxError), and looks much nicer than @. "Almost" anything looks better than the @ syntax. If @ gets implemented, there goes the whole easily-readable plug for Python. We might as all go learn Perl. While everyone is fussing around on the syntax of decorators, I think they should change the name as well (although I don't have a reasonable alternative yet). Decorator is the least program-like term I've ever heard of. :) From josh at chatgris.com Tue Aug 3 22:08:36 2004 From: josh at chatgris.com (Joshua Moore-Oliva) Date: Tue, 3 Aug 2004 22:08:36 -0400 Subject: asyncore, asynchat and threads In-Reply-To: <7cKdnShvevY_3Y3cRVn-iA@powergate.ca> References: <7cKdnShvevY_3Y3cRVn-iA@powergate.ca> Message-ID: <200408032208.36821.josh@chatgris.com> > The usual approach is to use something along the lines of a separate > thread for the *work* rather than for the connection, or maybe a > thread pool, and communicate with those threads from the asynchat > thingies using Queue.Queues... > > I'm not sure we have enough information about what you really need > to say more. You've given lots of info about what you "would love > to do" but not enough about what you actually need to do. > > -Peter Ok, I will give more info, and also, you touched on a subject that I thought was impossible for my problem domain, but here goes. I have a very simple protocol setup as follows.. basically it is a method for retrieving data, however I must route data through a central connection to avoid database locking. A simplified version of my transaction looks like so.. '>' means data from the client, '<' means data from the server > BATCH_GET < 1 Right after the BATCH_GET I wait on a Queue object for data to send to the remote client. Depending on whether there is data available for this specific connection, this call could never return, but other connections could also be requesting data, and there could be data available to them. I currently do have a separate thread doing all the work, and it puts each threads data into a separate queue. The problem that I ran into with using a direct asyncore//asynchat interface is this... (hoping there is a way to work around it) consider the very likely possiblity that asynchat retrieves the line BATCH_GET, but there is no data to return. I have to not return any data until there is data to return for that specific connection. If there is some way to send data down a asynchat socket from another thread (thread-safely), or to somehow wake up an asynchat class, that would be great. The problem is that once BATCH_GET is received, unless i handle it there and then, no more events will be generated as the remote client will be waiting for a response. Hopefully this sufficiently answers your 'what I actually *need* to do' question ;) I don't want to flood the email with a lot of irrelevant info, so if you would like more infomation, ask away, but I think this covers the problem sufficiently... Joshua Moore-Oliva From wweston at att.net Wed Aug 11 11:57:44 2004 From: wweston at att.net (wes weston) Date: Wed, 11 Aug 2004 15:57:44 GMT Subject: Print command In-Reply-To: References: Message-ID: Yong Wang wrote: > Hi, All: > For unknow reasons, I often get compiler error in the print > statements. For example: I have following codes: > > if len(currentFiberCode) > 0 : > print string.ljust(expandFiberCode(currentFiberCode,buildingRoom),30), \ > string.rjust(`currentTotal`,6), \ > string.rjust(`currentAvailable`,11), \ > string.rjust(`sm_ava`,7), \ > string.rjust(`mm_ava`,6), \ > string.rjust(`sm_used`,9), \ > string.rjust(`mm_used`,9) > else: > print 'data exist in fiber database table' > > When I comiped all the codes, I got : > Compiling ./NetDBfiber.py ... > File "./NetDBfiber.py", line 1086 > string.rjust(`currentTotal`,6), \ > ^ > SyntaxError: invalid token > > > How can I fix the problems ? > Thanks a lot. > > Yong > Yong, Is there a trailing space after the \ ? Looks like it. wes From sbabbitt at commspeed.net Fri Aug 6 13:09:32 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Fri, 6 Aug 2004 10:09:32 -0700 Subject: @decorators References: <1091800879.399791@news.commspeed.net> Message-ID: <1091812567.782496@news.commspeed.net> "Paul McGuire" wrote in message news:WZMQc.2054$va2.1917 at fe1.texas.rr.com... > "Tom B." wrote in message > news:1091800879.399791 at news.commspeed.net... > > > > "daishi" wrote in message > > news:d22692a3.0408052233.3459c3fa at posting.google.com... > > > For what it's worth: > > > > > > As far as I know, the proposed @decorator syntax will be the first > > > time that two logical lines of python with the same indentation will > > > not be independent of one another. Previously, when looking at: > > > > > > > I think the @decorator syntax was invented by Microsoft to sabotage > Python, > > > > Tom > > > > > > Heeey, let's keep it civil!!! > Your right, I apologize, @decorator syntax will affect me with much less adversity than Microsoft. Tom From jbperez808 at wahoo.com Wed Aug 18 12:12:31 2004 From: jbperez808 at wahoo.com (Jon Perez) Date: Thu, 19 Aug 2004 00:12:31 +0800 Subject: favorite python web development tool? In-Reply-To: <10i4nttktcvltdd@corp.supernews.com> References: <10i4nttktcvltdd@corp.supernews.com> Message-ID: <2ohd02Fari42U1@uni-berlin.de> mike wrote: > hi all - > > > i'm fairly new to python, coming from a java servlet / velocity template > background. i'm looking for a good python web development tool, and > hope to find some suggestions here. > > given my background, webware+cheetah feels comfortingly familiar, and > i'm leaning toward it. before i dive in, though, i'm wondering what you > experienced users think about it, compared to the other tools that are > out there. eg, does the python environment have strengths that are > better exploited with something other than a servlet-like model? For those coming from a PHP/ASP/JSP background, Spyce will be the most readily familiar and it rocks for those who use this approach. I've never had a use for a templating solution but Spyce is also supposed to support Cheetah well. From Jared.Cohen at noaa.gov Thu Aug 19 15:35:54 2004 From: Jared.Cohen at noaa.gov (Jared Cohen) Date: Thu, 19 Aug 2004 15:35:54 -0400 Subject: Please help -- Tkinter Scale widget with DoubleVar is acting weird Message-ID: <4125011A.10505@noaa.gov> Can anyone help me with this please? -------------- next part -------------- An HTML attachment was scrubbed... URL: From roy at panix.com Mon Aug 9 09:16:28 2004 From: roy at panix.com (Roy Smith) Date: Mon, 09 Aug 2004 09:16:28 -0400 Subject: Exceptions as a Control Structure References: <411775aa$0$17867$626a14ce@news.free.fr> Message-ID: In article <411775aa$0$17867$626a14ce at news.free.fr>, Olivier Parisy wrote: > Hi all, > > I am new to Python (I just finished Guido's tutorial). > I was very surprised to learn there that the StopIteration > is used to end for loops in a standard iterator setting. > > I come from C++, where the use of exceptions as control > structures is frowned upon for efficiency reasons. > > What is the Python canon on this topic ? Are exceptions > considered as reasonable control structures, or is > StopIteration alone of its kind ? Lots of things you do in C++ are frowned upon in Python. Lots of things you do in Python are frowned upon in C++. Specifically, exceptions in C++ are generally considered fairly heavy-weight, but not so in Python. Here's another common python idiom that uses exceptions in a way which would probably horrify most C++ people: for key in sequence: try: foo = dictionary [key] except KeyError foo = "not found" instead of: for key in sequence: if dictionary.has_key (key): foo = dictionary [key] else foo = "not found" If you're reasonably sure that most of the keys will be found in the dictionary, it's probably faster to just try them all and handle the occasional exception than to test each key to see if it exists. From David.Vaughan at Gifford.UK.com Fri Aug 20 11:13:32 2004 From: David.Vaughan at Gifford.UK.com (David Vaughan) Date: Fri, 20 Aug 2004 16:13:32 +0100 Subject: Decorator keyword options - brainstorming Message-ID: Paul McGuire wrote: > I'd say that something like "gerbil" should be right out! I don't know - it sounds fun. I vote: SpanishInquisition: staticmethod def foo(): pass The guys at python-dev won't be expecting that one :) But seriously, there must be something literally pythonic we could propose. David Vaughan From grante at visi.com Mon Aug 30 18:35:42 2004 From: grante at visi.com (Grant Edwards) Date: 30 Aug 2004 22:35:42 GMT Subject: "Content-Length" header References: Message-ID: <4133abbe$0$65600$a1866201@newsreader.visi.com> On 2004-08-30, Peter Kleiweg wrote: > Justin schreef: > >> I found the answer. After about 3 hours of agonizing over it >> it turned out to be CASE some webservers are CASE SENSITVE >> about their urls and some are not. > > There are case-insensitive webservers? Sure. Most are. AFAIK, apache on Unix has always been case sensitve. -- Grant Edwards grante Yow! -- I love KATRINKA at because she drives a visi.com PONTIAC. We're going awaynow. I fed the cat. From aleaxit at yahoo.com Mon Aug 30 03:05:12 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 30 Aug 2004 09:05:12 +0200 Subject: Testing automatically on import References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1ry8k0d2az.fsf@rovereto.ifi.uio.no> <10iv0kid2ig9ka6@corp.supernews.com> <1rpt5ccbso.fsf@rovereto.ifi.uio.no> <10ivpk9inpnh65@corp.supernews.com> <1rd61bd26k.fsf@rovereto.ifi.uio.no> <1gj892g.1hlc8ar1po78b6N%aleaxit@yahoo.com> Message-ID: <1gja5sf.vbe56knfvu9sN%aleaxit@yahoo.com> Jeremy Bowers wrote: > On Sat, 28 Aug 2004 12:15:24 +0200, Alex Martelli wrote: > > > Hmmm -- I'm thinking that the existing import hooks might be enough to > > let one prototype this "automatic checking" functionality, not quite as > > smoothly as a fully architected system maybe, but enough to get some > > early adopters, shake out teething problems, build a constituency to > > lobby for smoother integration in a future Python version... > > You know, I'm totally unexcited about the syntax stuff this thread is > putatively about, Hmmm, yeah, it DID start out about braces, didn't it?-) > but running automated testing over newly imported stuff > sounds kind of useful, not just for development but deployment as well; > "forcing" the users to run the tests once and report problems could be > very useful in some contexts. I agree with you entirely. > I already tend to name my unit tests for file "x.py" as "tests/xTest.py"... I tend to use tests/test_x.py, myself, but here we're back to discussing syntax sugar again;-). > > Maybe something that looks for a __validate__ function taking no args in a > module and runs it if the code was imported and newly compiled, combined > with a few convenience functions for the common cases? > > I'm not *quite* familiar with the import hook stuff to knock this off > right away. I tried prototyping it but got stuck on how to determine if a > Python file already has an up-to-date .pyc file. (Although I guess there > may be external dependencies... well in the interest of keeping it simple, > deal with that later.) Hmmm, I could be wrong, but I think you have to check timestamps and 'magic' signatures yourself. Pity, because imp.load_module must also do that, but I don't think it makes this logic available separately. Still, I believe Demo/imputil/importers.py has all the code you need. Alex From agriff at tin.it Tue Aug 24 09:15:05 2004 From: agriff at tin.it (Andrea Griffini) Date: Tue, 24 Aug 2004 13:15:05 GMT Subject: age of Python programmers References: <20040819231139.D039A1E4003@bag.python.org> Message-ID: On Tue, 24 Aug 2004 01:07:01 -0500, Reid Nichol wrote: >Perhaps it's just >where I went to school though or where I hang out, but it can't all be >coincidence. IMO it's no coincidence. I think that *most* professional programmers are not regular readers of usenet newsgroups about the languages they use... not only that... IMO in the bigger part they don't actually know what usenet newsgroups are. And most didn't even read any book on the languages and tools they use unless that happened when they were still at school. I decided that for myself I'll always cut out enough time to keep studying. But many just go forever with what they learned when they were forced to because of an exam. I've personally lived totally absurd situations where experienced programmers were just spending a lot of time and energy (and were making a lot of mistakes) because they never heard about make tools. I'm NOT kidding. I've seen things you people wouldn't believe... ;-) MS Word macros taking ages and requiring superservers (yes... they were installing office purposely to superservers so that MS word could use that RAM to be able to load the file to convert) to do data conversions that someone knowing perl wouldn't even save the script for (but would just invoke perl with "-e"). This is no joke. I was consulted for help when the word macro stopped working complaining first about being unable to "undo" changes and then crashing ms word anyway after. Looks like keeping studying, observing and "learning" is considered "out" by many of my collegues. Andrea From lbates at swamisoft.com Fri Aug 6 16:50:26 2004 From: lbates at swamisoft.com (Larry Bates) Date: Fri, 6 Aug 2004 15:50:26 -0500 Subject: py2exe and pyOpenGL References: Message-ID: Just guessing: py2exe moves everything into local directory (or .zip file in latest version) which would modify the sys.path to only look there. I think you will need to modify the system path so it can find OpenGL directory. HTH, Larry Bats Syscon, Inc. "julia" wrote in message news:defcda14.0408060942.21cea29f at posting.google.com... > Hi, > > I'm having trouble turning a python program with pyOpenGL into an exe > with py2exe. I was wondering if you could help. > > Basically I have a setup.py like this: > > # setup.py > from distutils.core import setup > import py2exe > setup(console=["gltest.py"]) > # end setup.py > > (Note that my program gltest.py works just fine) > > And when I do: > > python setup.py py2exe --excludes=OpenGL > > There is an error message that says: > > The following modules appear to be missing > ['OpenGL.GL', 'OpenGL.GLUT', 'dotblas', etc.... > > But I figured this was OK because of the excludes. So then I put the > OpenGL dir into the dist directory and when I try to run the exe I get > an ImportError: > > No module named OpenGL.GL > > Any idea where I'm going wrong? > > Thanks so much for your time, > Julia From timrueAT at mindspringDOT.com Sat Aug 21 13:26:19 2004 From: timrueAT at mindspringDOT.com (threeseas) Date: Sat, 21 Aug 2004 17:26:19 GMT Subject: autocoding and the new MS book regarding software factories In-Reply-To: References: Message-ID: <%ALVc.29611$9Y6.14576@newsread1.news.pas.earthlink.net> Delaney, Timothy C (Timothy) wrote: > Hey all! It's time for the semi-regular Tim Rue sighting! With a new > email address to beat the killfiles (or more likely these days, > spambayes). > > Where's that 'Delete As Spam' button gone ...? > > Tim Delaney I realize it is beyond your comprehension, but nothing stays the same. Hardware changes, software changes, including OSs used, etc.. Why would I want to beat kill files? Fact is, I'd prefer all those who do not like me to use kill files for it would allow others to be better able to make their own determinations. Of course given the fact things change and this doesn't help with kill files, that only leaves the one thing many don't seem to have control over. Their own ability to apply the choice of their dislikes without trying to create some automated system to do it for them. In other words, nobody is forcing you to read my posts. And in fact I have had those who claim to have kill filed me but continue to respond to my posts in effort to get others to follow them. Is there python code to my project? YES does it work? Yes... programming language require some degree or depth of teh application of logic in order to use. But people, unlike a computer, are not forced to have any sort of foundation in logic. As your posts provides an example of. From ksokol at schipul.com Wed Aug 18 12:40:09 2004 From: ksokol at schipul.com (Kathryn) Date: 18 Aug 2004 09:40:09 -0700 Subject: ImportError...pdo and adodbapi References: <61cc2a0a.0407300932.7e97bbf2@posting.google.com> Message-ID: <61cc2a0a.0408180840.49f2480c@posting.google.com> ksokol at schipul.com (Kathryn) wrote in message news:<61cc2a0a.0407300932.7e97bbf2 at posting.google.com>... > Hey folks, > I read this board every day and now I need some help. > > I have a script that imports pdo and adodbapi...I have multiple > sys.path.appends to define the relevant paths on my local machine and > a server. > ex: > > import sys > #local > sys.path.append('C:\Python\adodbapi') > sys.path.append('C:\Python\pdo') > #server > sys.path.append('D:\Python\adodbapi') > sys.path.append('D:\Python\pdo') > > import pdo > import adodbapi > > > This setup works fine on the server, as well as my old local machine. > Just switched local machines, reinstalled Python, still works fine on > the server (as it should), but errors out when I run on my local > machine. Keep in mind the directory structure has not changed. > > Here's the error: > ImportError: No module named pdo > ImportError: No module named adodbapi > > Now, if I manually run the setup files for pdo and adodbapi, then run > my script, it works like a gem. > > Any insight? What am I missing? > > Thanks, > Kathryn ....As it turns out: > sys.path.append('C:/Python/adodbapi') > sys.path.append('C:/Python/pdo') > #server > sys.path.append('D:/Python/adodbapi') > sys.path.append('D:/Python/pdo') (change of / direction) works just fine. Who knows. :) From anthony at interlink.com.au Thu Aug 5 09:10:32 2004 From: anthony at interlink.com.au (Anthony Baxter) Date: Thu, 05 Aug 2004 23:10:32 +1000 Subject: RELEASED Python 2.4, alpha 2 Message-ID: <411231C8.3020308@interlink.com.au> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team and the Python community, I'm happy to announce the second alpha of Python 2.4. Python 2.4a2 is an alpha release. We'd greatly appreciate it if you could download it, kick the tires and let us know of any problems you find, but it is not suitable for production usage. ~ http://www.python.org/2.4 In this release we have new syntax for function decorators, a fix for failing imports so that they don't leave a broken module in sys.modules, a host of updated modules in the standard library (including optparse and doctest) and a large number of other bug fixes and improvements. See either the highlights, the What's New in Python 2.4, or the detailed NEWS file -- all available from the Python 2.4 webpage. There will probably be one more alpha in a few weeks before the first beta a few weeks after that. Please log any problems you have with this release in the SourceForge bug tracker (noting that you're using 2.4a2): ~ http://sourceforge.net/bugs/?group_id=5470 Enjoy the new release, Anthony Anthony Baxter anthony at python.org Python Release Manager (on behalf of the entire python-dev team) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFBEjHFDt3F8mpFyBYRAhgXAKCful63a7kAUcHnxFzCZSzq0bmZ7QCfZIqy t/PqaaLcdRL6IVUKPAWiytA= =pQNU -----END PGP SIGNATURE----- From abra9823 at mail.usyd.edu.au Sat Aug 28 00:38:14 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Sat, 28 Aug 2004 14:38:14 +1000 Subject: cookie In-Reply-To: <87fz68v1uj.fsf@pobox.com> References: <87fz68v1uj.fsf@pobox.com> Message-ID: <1093667894.41300c36c1f62@www-mail.usyd.edu.au> Quoting "John J. Lee" : > Ajay writes: > > Quoting "John J. Lee" : > > > Ajay writes: > [...] > > > > i am printing a simple cookie, but instead of printing > > > > um=name:blah&access:admin&exp:2312390.909 > > > > > > > > its printing > > > > um="name:blah&access:admin&exp:2312390.909" > > > > > > > > why the quotes? > > > > > > Why not? > > > > > > I don't see how they'd cause any harm. > > > > > they dont cause any harm, except for a an extra statement removing > those > > quotes when i read the cookie, parse it and authenticate the session. > > the question is - is that normal cookie behaviour? > > cookie["test"]="blah" > > print cookie > > > > prints test=blah and not test="blah" > > so why the quotes when i do the same thing, but use a variable instead > of a > > string literal? > > You've lost me, but on the basis of a very quick test, the Cookie > module preserves quotes across the parse->output cycle: > > >>> import Cookie > >>> c = Cookie.SimpleCookie() > >>> c.load('foo=bar') > >>> print c > Set-Cookie: foo=bar; > >>> c.load('foo="bar"') > >>> print c > Set-Cookie: foo="bar"; > >>> > > That seems sensible behaviour to me, since quotes around cookie values > are significant for Netscape cookies (ie. regular, vanilla, internet > cookies). > > I can categorically state that using a variable name instead of a > string literal will make no difference whatsoever. i believe you. i didn't think it would make a difference. and i agree that the Cookie module preserves quotes across the parse->output cycle my question is >>> import Cookie >>> c = Cookie.SimpleCookie() >>> c["test"]= "blah" >>> print c Set-Cookie: test=blah; >>> c["test"] = "blah" + "testing" >>> print c Set-Cookie: test=blahtesting; >>> str = "testing blah" >>> c["test"] = str >>> print c Set-Cookie: test="testing blah"; why does the final print statement have the quotes. Note i haven't put str='"testing blah"'. if i had done that i would understand the quotes there. >I think you're > actually confused about Python syntax rather than the workings of the > Cookie module. Try reading the Python language tutorial at > www.python.org. > yes i should probably read that :) it doesn't though mention anything about the above behaviour cheers > > John > -- > http://mail.python.org/mailman/listinfo/python-list > ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From raims at dot.com Sun Aug 1 18:18:29 2004 From: raims at dot.com (Lawrence Oluyede) Date: Mon, 2 Aug 2004 00:18:29 +0200 Subject: Default encoding References: Message-ID: <6skrrm2c0bf0.d84dubnajxgj.dlg@40tude.net> In data Mon, 02 Aug 2004 00:14:01 +0200, Florian Lindner ha scritto: > how can I get the default encoding of a python installation? import sys sys.getdefaultencoding() -- Lawrence (l dot oluyede at virgilio dot it) "In IE we trust" From jimmy at retzlaff.com Mon Aug 9 08:43:54 2004 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Mon, 9 Aug 2004 05:43:54 -0700 Subject: python and win32 dlls Message-ID: fgrillo64 wrote: > i need help from the comunity ; i wrote under Windows2000 os a dll > having several symbols exported . > Now i would like to call these symbols from a python program . > Can anyone tell me how from a python module is possible to call > the dll exported symbols ? http://starship.python.net/crew/theller/ctypes/ Jimmy From noone at here.com Wed Aug 25 09:06:32 2004 From: noone at here.com (M. Clift) Date: Wed, 25 Aug 2004 14:06:32 +0100 Subject: Just a quick one Message-ID: Hi, Just a quick one. I'm trying to call [Bob','One'] with this, but I keep getting 'unhashable'. I've tried various ' " and [ and can't get the thing to work. Any offers? Thanks, M from random import * Name_Number = xrange(int(raw_input("Choose number of Names (1-20)? "))) state = [None,None] nextName = {['Bob','One']:['Rita','Sue'],\ 'Rita':['Mary','Sue',['Bob','One']],\ 'Sue':['Rita','Mary',['Bob','One']],\ 'Mary':['Sue','Rita']} Name_List = [] tmp = choice((['Bob','One'],'Rita','Sue','Mary')) for x in Name_Number: print state while tmp in state[0:2]: tmp = choice(nextName[Name_List[-1]]) print tmp, ", ", print print "Name ",x+1," is ", tmp Name_List.append(tmp) state[x%2] = tmp print Name_List From kent at pondview.mv.com Thu Aug 26 16:47:20 2004 From: kent at pondview.mv.com (Kent Johnson) Date: 26 Aug 2004 13:47:20 -0700 Subject: How to generically transform a list? References: Message-ID: Your second method can easily be rewritten using list comprehensions: >>> the_list = [['a',1,11,'aa'], ['b',2,22,'bb'],['c',3,33,'cc']] >>> returnList = [2,1] >>> new_list = [ [row[i] for i in returnList] for row in the_list ] >>> new_list [[11, 1], [22, 2], [33, 3]] Kent From m.boeren at guidance.nl Wed Aug 11 08:31:54 2004 From: m.boeren at guidance.nl (Marc Boeren) Date: Wed, 11 Aug 2004 14:31:54 +0200 Subject: Getting the docstring of a property Message-ID: <0C77C7530EA52A4EBD1C47C80D1D291E07F9D8@sbs.GuidanceBV.local> > How do you get the docstring of a property? Suppose I have > the following: > > class Foo: > def _prop_get(self): > return 1 > prop = property(_prop_get, doc="This is the docstring") If I try that in the interactive interpreter, and then do help (I love help :) >>> help(Foo) Help on class Foo in module __main__: class Foo | Properties defined here: | | prop | This is the docstring | | = _prop_get(self) This means I can get at the docstring somehow, as help obviously can (and as I would have expected :-) The thing is: foo.prop is an integer, and you don't want the docstring of an integer, but of a property. This means that you need to look at the class-level docstring for prop, and not the instance-level docstring. Translated: try Foo.prop. >From the prompt: >>> Foo.prop.__doc__ 'This is the docstring' or, if you only have the instance at hand and don't know the class yet: >>> foo.__class__.prop.__doc__ 'This is the docstring' HTH, Mc! From primz at bigpond.com Sun Aug 22 15:37:52 2004 From: primz at bigpond.com (Nick) Date: Sun, 22 Aug 2004 19:37:52 GMT Subject: Debunking Art - fraudster with python AI engine? Message-ID: <4128f60b$1@news.unimelb.edu.au> Hi, I recently went to an art exhibition, and one of the artists had an AI engine projected onto a screen with a keyboard for visitors to type questions in with. Curiously, I asked the artist if he had written the engine. He claimed to have, but as far as I know, he has done no AI study, and only started programming python some months ago. Naturally, I find it hard to believe he has picked up on natural language processing and the other various skills required to write AI engines in that time. My guess is he has a python AIML interpreter, and he's found a default "brain" somewhere and tweaked it with some of his own stuff in order to pass it off as his own. The engine could answer all the usual questions, like "what is the meaning of life" (42), "what is your name", "how old are you" etc etc. It was just a chatterbot, so ELIZA or a deriviative is marked off the list. I am guessing probably an ALICE engine is behind it all. Does anyone know any questions or commands one can issue the bot which might identify it? It required all questions to start with a capital letter, if thats any help. Cheers, Nick. [ 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 fakeaddress at nowhere.org Thu Aug 12 01:22:21 2004 From: fakeaddress at nowhere.org (Bryan Olson) Date: Thu, 12 Aug 2004 05:22:21 GMT Subject: rsa implementation question In-Reply-To: References: <1092200894.4119a9beb1978@www-mail.usyd.edu.au> <1a517b5.0408111636.200f675f@posting.google.com> Message-ID: Hi Heiko. I didn't mean any offense by "I agree with about half of Heiko Wundram's response." This is what I do for a living, so I tend to sweat details and push points. Heiko Wundram wrote: > Am Donnerstag, 12. August 2004 02:36 schrieb Bryan Olson: > >>There is a notion of blocks in many public-key ciphers, >>including RSA. The modulus n in RSA is composite, not prime. >>The "only the notion" statement implies that integer modular >>arithmetic is the only base for public-key cryptography, which >>is not true. > > Pardon me, yeah, the modulus is composite, I should've rather said that most > public key ciphers work in Z{n}. And I know that it's pretty easy to > generalize ElGamal to work in other rings than Z, or take bucket public key > cryptography for example. I don't know what "bucket public key" cryptography is. Google finds no matches. Incidentally, ElGamal generalizes to groups; they don't have to be rings. (Generalizes in the sense that it can verify what it signs and decrypt what it encrypts; it's insecure in many groups/rings). > I know of others, but: have you ever seen an implementation or use case of > some algorithm not working in Z{n}(*)? I have not, at least not when working > with computers. Sure. I worked for several years for Certicom, the leader in elliptic-curve cryptography (ECC). ECC is efficient, deployed, and now part of the federal standard for digital signatures, FIPS 186-2 (and the draft of FIPS 186-3). >>Try the book you cited, section 11.2.3, Note 11.10, Example >>11.11, and Remark 11.12. >> >> http://www.cacr.math.uwaterloo.ca/hac/ > > Yup, I read those, and yeah, I know what they are talking about, and yeah, > that's not what I said. It's not about decrypting to sign, encrypting to > verify, it's about the redundancy function. Which decrypt-to-sign doesn't have. In particular, look at your code. HAC says, "Selection of an appropriate [redundancy function] is critical to the security of the system." That's a key place where your code falls down. > In case you use a proper hash > function (I'm talking about identity with SHAing before signing), > this attack blatantly fails, Actually, I was the one who wrote "Always hash and pad, for any size message," and included code that uses SHA-1. Your follow- up code didn't hash at all. Since the attack fails for the method I use, but works against yours, I don't see what you are arguing. > as it would mean that you'd have to find hash collisions. > Even when I can easily find a m~ for which I have a valid signature m, > finding a plaintext for m~ which is meaningful should be impossible, due to > the hashing, for "long enough plaintext." This one is subtle. If I read your pseudo-code correctly, and in the place of the message we assume a SHA-1 hash, then there are 160 bits of hash digest, 16-bits of length, and the rest of the bits are random. Assuming the currently-most-popular RSA key size, 1024 bits, the attacker has to control just 176 out of 1024 bits. The verifier can check those 176 bits, but 847 or 848 bits can be anything. I'm not sure off-hand how weak it is, but none of the currently- respected signature methods allow a single hash digest to have anywhere near 2^847 valid signatures in a 2^1024 signature space. > And the example code I gave was not about leaving out hashing before putting > it throught the identity function as "redundancy", it was exactly about > reducing redundancy, which probably I was to stupid to explain correctly, > but I'll try now. I can't read your mind. I only knew what your post said your code was about: "what I always implemented is something like [...]". The state-of-the art signature methods agree with you that some randomness is a good thing. The need for randomness in signatures is not yet well-understood; it's an assumption of the (relative) security proofs, but no one has yet proved it is necessary. >>Don't do that, even for encryption. See Bleichenbacher's >>attacks on RSA encryption: >> >> http://www.bell-labs.com/user/bleichen/bib.html > > > Link doesn't work... Hmm... works for me. Odd. Googling "Bleichenbacher" + "RSA" should find it. > But anyway, look at the same book on page 288, (ii): > > "A pseudorandomly generated bitstring should be appended to the plaintext > before encryption (this is also called salting)." > > That's exactly what my little example was trying to do: append a salt to the > data which was being encrypted. And that's why I didn't fault your example for lack of randomness. (Though technically the message and length could fill the block, and thus not allow any randomness. That would be a big mistake for encryption, and arguably a mistake for signatures.) If you have questions about these things, I suggest asking them on sci.crypt. My advice here is to use cryptosystems that experts have already vetted; do not roll your own variants. -- --Bryan From pink at odahoda.de Sat Aug 28 05:22:52 2004 From: pink at odahoda.de (Benjamin Niemann) Date: Sat, 28 Aug 2004 11:22:52 +0200 Subject: would be nice: import from archive In-Reply-To: <1gj82n3.1ylkr3nierngmN%aleaxit@yahoo.com> References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <7xzn4gwgea.fsf@ruckus.brouhaha.com> <1gj7a1o.1a5d2q410jsn2kN%aleaxit@yahoo.com> <7xisb4xnh5.fsf@ruckus.brouhaha.com> <1gj7c1a.tfdm14p3hclcN%aleaxit@yahoo.com> <7xd61benm9.fsf@ruckus.brouhaha.com> <1gj82n3.1ylkr3nierngmN%aleaxit@yahoo.com> Message-ID: Alex Martelli wrote: > Paul Rubin wrote: > > >>aleaxit at yahoo.com (Alex Martelli) writes: >> >>>While the overall way the new import hooks work is well documented in >>>their PEP, zipimport is admittedly underdocumented. I suggest peeking >> >>OK. I'll look at the PEP. I think adding signing is hairy enough >>that it should have its own round of discussion; should I see about >>editing the PEP to add something about signing? > > > I think that would be an excellent idea. If it was just about allowing > import from signed zipfiles it might not be needed, but how best to let > the user optionally DIS-allow imports from UN-signed files does appear > to be something requiring a little debate. An environment variable > would have the advantage of letting the disallowing work even for the > early imports that Python does before application code gets control, but > some people dislike relying on environment variables particularly for > security-related configuration tasks. Would it make sense to rely on a > naming convention instead? I.e. foo.zip would be unsigned but bar.jar > would have to be signed or else no go. This would have the advantage of > allowing substantial granularity in controlling this. Isn't the purpose of signatures that the importing program can trust the module? If it's implemented as you suggest, an attacker could just inject path to an unsigned module into PYTHONPATH to fool a program. How about something like require_signature('mymodule') import mymodule or import mymodule verify_module(mymodule) Another question is, where to place (require|verify)_signature() (that could also take a CA key (or list of) as optional argument to only allow modules signed by this CA). It must not be imported from an untrusted module. The whole signing thing probably make only sense, if python and it's stdlib can be trusted (=signed). Or am I missing other useful applications of signed archives? > > Side question, does module zipfile already have the code to allow > reading such signed files? Otherwise a first, uncontentious step, in > parallel with the PEP, might be a patch to add that ability to zipfile. > > > Alex > From greg at invalid.invalid Tue Aug 17 20:28:02 2004 From: greg at invalid.invalid (Greg Krohn) Date: Wed, 18 Aug 2004 00:28:02 GMT Subject: what is wrong with this program? In-Reply-To: <8f17f4bc.0408171623.4f055fb3@posting.google.com> References: <8f17f4bc.0408171623.4f055fb3@posting.google.com> Message-ID: Ali wrote: > The following program is supposed to show a menu but it isnt showing > the drop down menus. It only shows the File and Help thing. The code you posted doesn't even run. Copy and paste the *exact code* that you used, and maybe we can help. Greg From tim.leslie at gmail.com Thu Aug 26 11:56:59 2004 From: tim.leslie at gmail.com (Tim Leslie) Date: Fri, 27 Aug 2004 01:56:59 +1000 Subject: object.* In-Reply-To: References: Message-ID: An approximation of this functionality can be obtained using the built in dir() command. A quick example follows: >>> class C: ... def __init__(self): ... self.a = 1 ... self.b = 2 ... def f(self): ... return self.a + self.b ... >>> c = C() >>> dir(c) ['__doc__', '__init__', '__module__', 'a', 'b', 'f'] >>> ["c." + x for x in dir(c)] ['c.__doc__', 'c.__init__', 'c.__module__', 'c.a', 'c.b', 'c.f'] >>> map(eval, ["c." + x for x in dir(c)]) [None, >, '__main__', 1, 2, >] Cheers, Tim On 26 Aug 2004 08:41:25 -0700, DeadWisdom wrote: > I think there should be an ability in python to write something like > "object.*" which should return a dictionary object containing all the > members and their values for the given object. Maybe ".*" could be > treated as an operator. ::shrug:: > > Perhaps the functionality already exists in some other syntax; if so > please splain. > -- > http://mail.python.org/mailman/listinfo/python-list > From igouy at yahoo.com Tue Aug 3 12:23:31 2004 From: igouy at yahoo.com (Isaac Gouy) Date: 3 Aug 2004 09:23:31 -0700 Subject: The Great Computer Language Shootout (updated ) Message-ID: "The Great Computer Language Shootout" was mentioned a few months ago - note that the Shootout is active and welcoming contributions at: http://shootout.alioth.debian.org/ From M.Waack at gmx.de Wed Aug 25 16:51:30 2004 From: M.Waack at gmx.de (Mathias Waack) Date: Wed, 25 Aug 2004 22:51:30 +0200 Subject: authentication service for unix References: Message-ID: Diez B. Roggisch wrote: > Hi, > > this is not so much a python question, but as my app is developed > in python, I'll ask anway. > > I'm looking for a method to authenticate users for a corba > application server, running under linux. I want to be able to > authenticate users that are valid unix users. Having role/group > information would be nice later on. > > Currently I use PAM, but thats not so good as I have to run the > process as root - but for obvious reasons I don't especially like > that idea. Using PAM is definitively not the reason why your process must be run as root. What exactly are you doing? Mathias From fumanchu at amor.org Mon Aug 23 10:11:57 2004 From: fumanchu at amor.org (Robert Brewer) Date: Mon, 23 Aug 2004 07:11:57 -0700 Subject: J2 paper 0.2.1 Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E37@exchange.hqamor.amorhq.net> Andrew Durdin wrote: > On Sun, 22 Aug 2004 22:19:31 -0700, Robert Brewer > wrote: > > The first draft of the J2 proposal is ready. You can read it here: > > http://www.aminus.org/rbre/python/pydec.html > > A very nice job. Regarding the suggestion for "using" in Argument III: > > """ > * It "reads correctly" in every use case. > """ > > Can you include an example with the "using" keyword, so that the > reader doesn't have to construct one himself to see how this might be > so? > > e.g. > > using: > memoize > classmethod > synchronize > funcattrs(author="Guido Van Rossum") > def foo(cls, *args): > pass > -- Sure. I'll also use this opportunity to tell everyone that I may not answer every such suggestion on the list, if my answer consists of "OK". But rest assured, I'm reading every response. Robert Brewer MIS Amor Ministries fumanchu at amor.org From michaels at rd.bbc.co.uk Thu Aug 26 07:13:43 2004 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Thu, 26 Aug 2004 12:13:43 +0100 Subject: Best GUI- Python for children - pygame and blender32 References: Message-ID: Andr? Roberge wrote: > Sorry about the cryptic subject line, but I wanted to capture the > essence of my message in a single line. > > I am learning Python (which, as everyone know is the best language :-) > so that I can write a tutorial to teach my kids about computer > programming. Have you seen the LiveWires course? It's been running several years now and sounds like they've been successful. They use Tk and pygame for what it's worth. * http://www.livewires.org.uk/python/ Regards, Michael. -- Michael.Sparks at rd.bbc.co.uk British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From jdc at uwo.ca Mon Aug 9 15:50:02 2004 From: jdc at uwo.ca (Dan Christensen) Date: Mon, 09 Aug 2004 15:50:02 -0400 Subject: decorators as a special case of an @ operator? References: <87llgocrgq.fsf@uwo.ca> <87d620cld8.fsf@uwo.ca> Message-ID: <87fz6wgkgl.fsf@uwo.ca> Peter Hansen writes: > Dan Christensen wrote: >> Is there any reason that python doesn't automatically >> continue all incomplete binary operators, allowing >> x = a_very_long_expression + >> another_long_expression >> ? > > Very likely, as is usual with Python, to avoid implicitly > assuming something that could well be wrong, thus failing > in a possibly very hard to find way, without warning. > > x = a_very_long_expression + > some_function_that_might_return_a_value() > > Now, was the first line a typo, with a missing extra value, > or was it really intended to add the result of the function > call on the second line? Good point. What if python did automatic continuation in this situation only if the second line was further indented? This is ok: x = a_very_long_expression + some_function_that_might_return_a_value() This suggests the programmer forget to finish the first line: x = a_very_long_expression + some_function_that_might_return_a_value() I just dislike those backslash characters. And I'm always afraid there's hidden whitespace after them: >>> 1 + \ File "", line 1 1 + \ ^ SyntaxError: invalid token Thanks for your comments! Dan From d.mikesell at computer.org Wed Aug 11 13:00:32 2004 From: d.mikesell at computer.org (Dave Mikesell) Date: 11 Aug 2004 10:00:32 -0700 Subject: Ogre3d Python bindings (was Re: 3D Graphics Engines) Message-ID: >> You can have a look to Ogre: www.ogre3d.org. >> Python bindings may not be up to date, but they should be at the first >> official release (which should now happen in a not so far future). >On a brief inspection (bad, busy day) I couldn't see *either* python >binaries *or* prebuilt binaries at the site you pointed to. Looks like Ogre3d has "resurrected" their Python bindings as of late July: http://www.ogre3d.org/modules.php?op=modload&name=News&file=article&sid=261&mode=thread&order=0&thold=0 From gandalf at geochemsource.com Wed Aug 18 14:23:39 2004 From: gandalf at geochemsource.com (Gandalf) Date: Wed, 18 Aug 2004 20:23:39 +0200 Subject: Platform independent way to play an mp3 file In-Reply-To: <31575A892FF6D1118F5800600846864D01AE29A3@intrepid> References: <31575A892FF6D1118F5800600846864D01AE29A3@intrepid> Message-ID: <41239EAB.903@geochemsource.com> SBrunning at trisystems.co.uk wrote: >>From: Gandalf [mailto:gandalf at geochemsource.com] >> >> >>Oh yes, I know about this. But it seems it is working on >>Linux and Windows only. I have Solaris, FreeBSD and AS/400 >>clients too. >>:-( >> >> > >AS/400 clients? '400s don't have *any* sound support at all, so good luck >with that one. ;-) > Oh, okay. That's fine. At least I can tell something to my bosses. :-D But what about FreeBSD? > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From t_therkelsen at hotmail.com Mon Aug 9 18:47:52 2004 From: t_therkelsen at hotmail.com (Troels Therkelsen) Date: 09 Aug 2004 22:47:52 GMT Subject: Popular Python projects with lots of pure Python code References: Message-ID: In article , Brett C. wrote: > For my thesis (once the bloody thing stops throwing bugs at me) I am > going to need to collect stats on the frequency that atomic types in > local variables are applied to various opcodes and methods. That means > that I need something to collect stats off of. > > So I am trying to come up with a list of projects I can use to get my > stats from. the stdlib is a no-brainer. Also plan to use Docutils. > But beyond those most of the big Python projects I can think of have a > ton of C code which is of no use to me. I don't need to be able to run > it, just going to be compiling to .py files. > > Any suggestions? What about MoinMoin and Mailman? Those are fairly large-ish pure-python projects. If 100% pure python isn't a must, PIL might also be able to yield useful stats as all of the abstraction is done in python. Hope this helps, Troels Therkelsen From robey at slash_dev_slash_random.org Wed Aug 18 16:28:39 2004 From: robey at slash_dev_slash_random.org (Robey Holderith) Date: Wed, 18 Aug 2004 15:28:39 -0500 Subject: name of current program References: Message-ID: This should give you the script name. sys.argv[0] -Robey On Wed, 18 Aug 2004 14:27:39 -0500, Josh Close wrote: > This is a simple question, but I can't find the answer for some reason. > > How do I get the name of the current script/program that is running? > > -Josh From bh at intevation.de Fri Aug 6 14:31:04 2004 From: bh at intevation.de (Bernhard Herzog) Date: Fri, 06 Aug 2004 20:31:04 +0200 Subject: unicode to ascii converting References: <1091815856.527127@news.commspeed.net> Message-ID: Peter Wilkinson writes: > It would be good to find out _why_ this happens in the first place. I > will keep do a little searching on this for a few days. Most likely because you have characters in that file that are not in the ASCII character set. ASCII is after all only a very small subset of unicode. E.g. >>> u"?".encode("ascii") Traceback (most recent call last): File "", line 1, in ? UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 0: ordinal not in range(128) If it's OK to lose information, you could use the error argument to .encode like >>> u"?".encode("ascii", "ignore") '' or >>> u"?".encode("ascii", "replace") '?' Bernhard -- Intevation GmbH http://intevation.de/ Skencil http://sketch.sourceforge.net/ Thuban http://thuban.intevation.org/ From rnichol_rrc at yahoo.com Mon Aug 16 01:18:19 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Mon, 16 Aug 2004 00:18:19 -0500 Subject: Python secure? In-Reply-To: References: Message-ID: > My reason for choosing Python was one, that it is free, so if my efforts > amount to nothing I haven't wasted money, two, that it is supposed to be an > easy language when compared to some others and three, that my application > when finished, probably wouldn't sell for that much and not in any great > quantities for me to gamble spending something like ?1000 on Visual C / > ++ this that and the other or whatever. Free C/C++ compiler (win32) through: gcc/g++ on cygwin http://www.cygwin.com or with the ide Dev-C++ http://www.bloodshed.net/devcpp.html And of course any *NIX will come with gcc/g++ pre-installed. But learning C/C++ right off the bat makes for bad programming habits and loss of hair. I would still recommend getting down the basics of programming with Python and then moving onto C or C++ (especially if you are learning on your own). Of course that is if these languages suit your project better. From brianc at temple.edu Mon Aug 2 16:41:58 2004 From: brianc at temple.edu (brianc at temple.edu) Date: Mon, 2 Aug 2004 16:41:58 -0400 Subject: Class optimization at runtime Message-ID: I would like to optimize my classes at run time. The question is where to put my "if" statement. -Inside __main__? if option: class Foo: def __init__: #do stuff else: class Foo: def __init__: #do other stuff -Inside class definition? class Foo: if option: def __init__: #do stuff else: def __init__: #do other stuff -Inside each method definition? class Foo: def __init__: if option: #do stuff else: #do other stuff Class instances will be created millions of times and the method's on them called even more so whatever brings the most speed will be used. I fear that the more readable way to do it is also the slowest. Thanks in advance, -Brian From tdelaney at avaya.com Thu Aug 19 20:09:13 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Fri, 20 Aug 2004 10:09:13 +1000 Subject: Alternative decorator syntax decision Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01D591A7@au3010avexu1.global.avaya.com> Paul McGuire wrote: > I would propose a multivote survey: each poster gets 3 votes among the > lettered choices on the Wiki page above. You can use all 3 for a > single option, or split them across 2 or 3 options if you are open to > more than one. I think a web page for tabulating votes would be better (see the response to the previous vote on 3 syntaxes). I also think the top contenders as identified by Brett should be the only options in order to focus things (Guido is *not* going to accept anything with < 20% vote ;) Did Brett include J2 - if not, I think there's enough support to include it as well ... Anyway, my vote is C1, C1, J2. Tim Delaney From spam at mouse-potato.com Sat Aug 28 12:05:47 2004 From: spam at mouse-potato.com (Pascal Bourguignon) Date: 28 Aug 2004 18:05:47 +0200 Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4dyXc.25792$Ot3.22106@twister.nyc.rr.com> <878yc0ucyl.fsf@thalassa.informatimago.com> <20040827135423.154$1T@newsreader.com> Message-ID: <87llfzqmck.fsf@thalassa.informatimago.com> Ian Wilson writes: > David Schwartz wrote: > > > wrote in message > > news:20040827135423.154$1T at newsreader.com... > > > >>"David Schwartz" wrote: > > > >>> I don't follow you at all. I think you'll find the most useful, > >>>meaningful complaints about, say, a Ford Explorer from the people who > >>>drive one every day. > > > >>And if they continue to drive one everyday, perhaps you would conclude > >>that their complaints are insincere. > > That's a load of crap. > > DS > > > > > You're both right but ... > > Xah Lee: "I'm starting my own cult to exterminate morons on > this earth. Two things are on the top of my agenda: Unixism and Perl." > > Pascal Bourguignon: > > > Is more like > > Joe Blow: I'm going to exterminate all morons who drive a Ford Explorer. > > Fred Bloggs: But Joe, you drive a Ford Explorer! > > > Rather than > > Joe Blow: Ford Explorers are a little bit expensive to service and the > doors squeak after a couple of years. > > Fred Bloggs: Thanks for the tip Joe, I see you drive one, so you > should know. Case closed. (And probably Xah has suicidal impulses). -- __Pascal Bourguignon__ http://www.informatimago.com/ Our enemies are innovative and resourceful, and so are we. They never stop thinking about new ways to harm our country and our people, and neither do we. From pm_mon at yahoo.com Fri Aug 27 21:17:52 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Fri, 27 Aug 2004 21:17:52 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412D9F1E.6000809@yahoo.it> Message-ID: Jess Austin wrote: > Paul Morrow wrote in message news:... > >>Nope, that was me alright. I don't want a function to have access to >>it's metadata. Nothing's changed about that. I want to be able to >>specify a function's metadata inside the function def, where it seems to >>most appropriately belong. > > > So you have: > > def foo(x): > __meta_variable__ = 42 > variable = 5 > return dir() > > And you're volunteering to explain to a newbie, or even a nearly > intermediate programmer like myself, why the list that is returned > from this function contains 'x' and 'variable' but not > '__meta_variable__'? Sure. Magic attributes defined at the top level of a function (e.g. your __meta_variable__) aren't intended to be local variables. You'll see that as you start looking at more experienced programmer's code. Therfore, they shouldn't be treated as local variables. For example, suppose we changed your function a little... def foo(x): __author__ = 'Jess Austin' __version__ = '1.0' variable = 5 return dir() See the difference? > >>Others seem to want to specify a function's metadata outside of the >>function def, which just doesn't seem pythonic (IMO). > > > If you really understood Python's scoping rules, you would know that > this opinion is the opposite of the truth. A decorator is a kind of meta information. So are docstrings. The proposals I've been seeing (A1 and J2 in particular) declare decorators and docstrings outside of the function def (not inside of the function def). > Of all the current > incarnations of function "metadata", only one may be set within the > function, and that one is not set using a standard binding statement: > True and True, provided that you believe that docstrings are the only kind of function metadata. I believe though that attributes like __author__ and __version__ above are also function metadata. > In broader commentary, as I've said, pep318 > isn't really about metadata. One reason is that metadata isn't that > important. By this you mean "in your opinion", right? Paul From ville at spammers.com Sun Aug 22 12:36:38 2004 From: ville at spammers.com (Ville Vainio) Date: 22 Aug 2004 19:36:38 +0300 Subject: On consensus decision-making (was Re: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WEDONE?) References: Message-ID: >>>>> "Peter" == Peter Hansen writes: Peter> at this stage. (In consensus building, a "block" basically Peter> says that someone would refuse to support the community Peter> decision, while 100% consensus means no one blocks the Peter> decision even though some people may not feel it reflects Peter> their first choice.) So, to proceed building community consensus for J2, the community needs to be asked whether they would block J2 (possibly with the "using" keyword) in favor of another non- at pie syntax? Obviously people who don't want any syntax at all should be ignored in the consensus building process... -- Ville Vainio http://tinyurl.com/2prnb From robey at slash_dev_slash_random.org Wed Aug 18 18:05:40 2004 From: robey at slash_dev_slash_random.org (Robey Holderith) Date: Wed, 18 Aug 2004 17:05:40 -0500 Subject: Embedding Python in Python References: <7xu0v0l2be.fsf@ruckus.brouhaha.com> <7x3c2kkzn8.fsf@ruckus.brouhaha.com> Message-ID: On Wed, 18 Aug 2004 20:33:09 +0000, JCM wrote: > Robey Holderith wrote: >> On Wed, 18 Aug 2004 19:44:47 +0000, JCM wrote: > ... >>> I don't think it's as difficult as you think. Your snippet of code >>> would be rejected by the rules I suggested. You'd also want to >>> prohibit other builtins like compile, execfile, input, reload, vars, >>> etc. > >> I'm going to have to agree with Paul on this one. I do not feel up to >> the task of thinking of every possible variant of malicious code. There >> are far too many ways of writing the exact same thing. I think it would >> be much easier to write my own interpreter. > > Well it certainly isn't easier to write your own interpreter if you're > talking about the effort you'd need to put into it. And I'm not > convinced it's that tricky to come up with a set of syntax rules to > decide whether a piece of code is simple/safe enough to run. It > basically comes down to disallowing certain statements and certain > identifiers. Of course you'll end up rejecting a lot of code that > isn't malicious. > > If you're interested enough, I'll try to throw a safety-checker > together. You'd have to be pretty interested though (I'm lazy). Don't do it on my behalf. I started far too many projects doing something similar before I realized that the only effective way to do security was from the bottom up. The problem looks something like this (assuming each function has 10 places where it is implemented. Level | Malicious Variation Count ----------------------------------------- 0 | 10^0 1 | 10^1 2 | 10^2 x | 10^x Suffice to say that in simple code... it is doable. In a mature interpreter... near impossible. -Robey From ben at benlast.com Thu Aug 19 05:49:32 2004 From: ben at benlast.com (Ben Last) Date: Thu, 19 Aug 2004 10:49:32 +0100 Subject: favorite python web development tool? In-Reply-To: <5339b60d.0408190123.2a8adb87@posting.google.com> Message-ID: > From Paul Boddie > Well, . Alternatively, you could take > a look at the WebProgramming section [1] of the PythonInfo Wiki [2]. > And if other respondents contributed their opinions to that resource, > we wouldn't necessarily have the situation where people regard that > resource as confusing whilst giving a parade of the frameworks every > time someone asks how to do CGI with Python. No, we'd have a parade of screaming advocacy on the Wiki Page instead. :) But I guess anyone willing to edit one wiki might be willing to do another: http://c2.com/cgi/wiki?PythonLanguage b From roy at panix.com Mon Aug 9 19:19:34 2004 From: roy at panix.com (Roy Smith) Date: Mon, 09 Aug 2004 19:19:34 -0400 Subject: Popular Python projects with lots of pure Python code References: Message-ID: In article , "Brett C." wrote: > For my thesis (once the bloody thing stops throwing bugs at me) I am > going to need to collect stats on the frequency that atomic types in > local variables are applied to various opcodes and methods. That means > that I need something to collect stats off of. > > So I am trying to come up with a list of projects I can use to get my > stats from. the stdlib is a no-brainer. Also plan to use Docutils. > But beyond those most of the big Python projects I can think of have a > ton of C code which is of no use to me. I don't need to be able to run > it, just going to be compiling to .py files. > > Any suggestions? > > -Brett Ilya Etingof's PySNMP package is a pretty large collection of Python code. See http://pysnmp.sourceforge.net/ From alikakakhel3 at hotmail.com Thu Aug 26 18:34:43 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 26 Aug 2004 15:34:43 -0700 Subject: about presicion Message-ID: <8f17f4bc.0408261434.1a73e874@posting.google.com> I was wondering if it was posible to get very good presicion. I mean like to the to the 100 th or more decimal place. if so how? From benn at cenix-bioscience.com Fri Aug 13 03:48:50 2004 From: benn at cenix-bioscience.com (Neil Benn) Date: Fri, 13 Aug 2004 09:48:50 +0200 Subject: Pyhton Interpreter Startup time In-Reply-To: References: <30260531.0408120829.27a536bc@posting.google.com> Message-ID: <411C7262.1000803@cenix-bioscience.com> Peter Hansen wrote: > > I don't recall the OP in the last thread that discussed this > ever coming back to report on exactly what OS and CPU etc. > he was using, and whether network issues might be involved, > etc, so until someone can prove otherwise, I think it's > safe to assume that anyone with a slow startup on Windows > has a misconfiguration or is doing something wrong. > Hello, Hi, I'm the OP, my box is : WinXP Pro 2.4Gz Processor 256M RAM Python2.3 As I said the first load takes 5 seconds and the consecutive loads take fractions of a second - my assumption is that Windows is caching something which is not suitable for my needs as it is not predictable enough. There is no network issues involved in this, everything is running off the local hard drive. I've just this moment run python after the box having done some work and being asleep overnight and the startup time was about 2 seconds. I may be doing something wrong but the only configuration stuff I've done is to add into my environment variables : PYTHON_HOME=c:\program files\python23 PATH=%PATH%;PYTHON_HOME This is simply to allow me to switch between different python directories when I start to install different versions (I do the same with the JVM). If python can't start up quick on windows, that's fine, if I've got something miscofigured which can be fixed, that's fine too - I just need to know if there is a 'quick start up' mode but if there isn't then that's also fine. It's just info I need to design what will be a very simple app. Thanks, for your help. Cheers, Neil -- Neil Benn Senior Automation Engineer Cenix BioScience BioInnovations Zentrum Tatzberg 47 D-01307 Dresden Germany Tel : +49 (0)351 4173 154 e-mail : benn at cenix-bioscience.com Cenix Website : http://www.cenix-bioscience.com From chris at shiftzz.com Fri Aug 13 13:13:25 2004 From: chris at shiftzz.com (Chris C) Date: 13 Aug 2004 10:13:25 -0700 Subject: DIME Attachments Message-ID: I've been looking all around for any libraries or code for parsing dime attachments from Microsoft .NET Web Services. Any ideas? I am writing my client code on a linux box and calling SOAP web services on a windows box, which returns a DIME attachment. DIME doesn't appear to use the same boundaryies as a MIME message. Thanks for any ideas. Chris From theller at python.net Mon Aug 23 14:44:33 2004 From: theller at python.net (Thomas Heller) Date: Mon, 23 Aug 2004 20:44:33 +0200 Subject: py2exe, PyXML, and utf-16-be Error References: <67e04df1.0408230913.3c12f1a8@posting.google.com> Message-ID: david_brownell at hotmail.com (David Brownell) writes: > I am using the XMLValidateParser in the PyXML library > (xml.sax.sax2exts.XMLValParserFactory.make_parser). When I run my > script, everything works as expected. > > When I "compile" my script using py2exe, I get the following error > when running the exe: > > Traceback (most recent call last): > > File "xml\sax\sax2exts.pyc", line 13, in make_parser > File "xml\sax\saxexts.pyc", line 64, in make_parser > File "xml\sax\saxexts.pyc", line 42, in _create_parser > File "xml\sax\drivers2\drv_xmlproc.pyc", line 9, in ? > File "xml\parsers\xmlproc\xmlproc.pyc", line 14, in ? > File "xml\parsers\xmlproc\dtdparser.pyc", line 12, in ? > File "xml\parsers\xmlproc\xmlutils.pyc", line 43, in ? > LookupError: unknown encoding: utf-16-be > > While using py2exe, I specify "--packages xml". Is there something > else I need to specify to enable utf-16-be encoding? I would guess "--packages xml,encodings" should do the trick. Thomas From greg at cosc.canterbury.ac.nz Fri Aug 27 00:34:33 2004 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Fri, 27 Aug 2004 16:34:33 +1200 Subject: Call for signatories for J2 In-Reply-To: <412e3ba4$0$92817$ed2619ec@ptn-nntp-reader02.plus.net> References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> <7xhdqp967k.fsf@ruckus.brouhaha.com> <412e3ba4$0$92817$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: <2p7rurFhgglpU1@uni-berlin.de> Michael Sparks wrote: > I think I'd agree. However for many people outside of python-dev and those > who only dip into c.l.p, the @pie came as a big shock. It came as a shock to people *in* python-dev, too. It just appeared one day as a fait accompli, without any opportunity for discussion. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From tjreedy at udel.edu Fri Aug 6 17:27:59 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 6 Aug 2004 17:27:59 -0400 Subject: @decorators References: <10h6v76mm313cce@news.supernews.com> Message-ID: "David Fraser" wrote in message news:cf05e8$41d$2 at ctb-nnrp2.saix.net... > John Roth wrote: > > "daishi" wrote in message > > news:d22692a3.0408052233.3459c3fa at posting.google.com... > >>As far as I know, the proposed @decorator syntax will be the first > >>time that two logical lines of python with the same indentation will > >>not be independent of one another. > > Examples: > > > > try - except - finally > > if - elif - else > > while - else > > I think he mean two consecutive lines of python code with the same > indentation. And the same examples apply: if like(atdeco): print 'hooray' else: print 'boo' Terry J. Reedy From fumanchu at amor.org Sun Aug 22 14:58:21 2004 From: fumanchu at amor.org (Robert Brewer) Date: Sun, 22 Aug 2004 11:58:21 -0700 Subject: Python is to C as letters are to words. Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E2B@exchange.hqamor.amorhq.net> r holland wrote: > Subject: Python is to C as letters are to words. > > My nine word description of the python language. I'll give you the benefit of the doubt and assume you meant: "Python is to C as words are to letters." Good quote. Robert Brewer MIS Amor Ministries fumanchu at amor.org From noone at nowhere.com Wed Aug 4 13:53:45 2004 From: noone at nowhere.com (dusty) Date: Wed, 04 Aug 2004 17:53:45 GMT Subject: Question on coding QCheckListView (newbee) Message-ID: <5182h0pc4p12kbv2hnb2u2a35ee5l0mmq9@4ax.com> I have several years experience using Delphi writing apps in windoz (not professional) and now in a effort to completely remove windoz, I am trying to re-write my apps using Python, PyQt and Qt Designer. I am using a QCheckListView and have a need to read the text and level (parent or child) of a selected item. I am confused by the C code information in the QT help and have been unsuccessful in extracting this information. I would appreciate any help I can get with code examples. From __peter__ at web.de Thu Aug 19 10:55:47 2004 From: __peter__ at web.de (Peter Otten) Date: Thu, 19 Aug 2004 16:55:47 +0200 Subject: newbie References: Message-ID: JASON JESSO wrote: > I'm trying to add a mode to a mkdir program a got off > the python cookbook. > > The error I get is: > ./mkdir.py jason 0777 > Traceback (most recent call last): > File "./mkdir.py", line 31, in ? > _mkdir( sys.argv[1], sys.argv[2] ) > File "./mkdir.py", line 25, in _mkdir > os.mkdir( newdir, mode ) > TypeError: an integer is required > > When I convert the mode from a string to an octal with > oct(int(sys.argv[2])) the permissions are all screwed > up. oct() converts an integer to the octal _string_ representation - that's why python sees a string where an integer is required. Internally there is no such thing as a decimal or an octal integer. Therefore you just have to convert the octal string representation given on the command line to an integer. This is done like so: int(sys.argv[2], 8) Here the second parameter is the base (the default being, of course, 10). Peter From bokr at oz.net Sun Aug 1 18:24:52 2004 From: bokr at oz.net (Bengt Richter) Date: 1 Aug 2004 22:24:52 GMT Subject: slowdown with massive memory usage References: Message-ID: On 01 Aug 2004 22:08:14 +0200, Hallvard B Furuseth wrote: >Andrew MacIntyre wrote: >> On Sat, 30 Jul 2004, Hallvard B Furuseth wrote: >>> I have a program which starts by reading a lot of data into various >>> dicts. >>> >>> When I moved a function to create one such dict from near the beginning >>> of the program to a later time, that function slowed down by a factor >>> of 8-14: >> (...) >> >> Python 2.2 didn't use PyMalloc by default. This leaves Python at the >> mercy of the platform malloc()/realloc()/free(), and Python has found >> rough spots with nearly every platform's implementation of these - which >> is why PyMalloc was written. >> >> While it isn't certain that this is your problem, if you can rebuild your >> Python interpreter to include PyMalloc (--with-pymalloc I think), you can >> find out. > >Thanks. I'll check that when I get time. Until then, malloc gets the >blame until proven innocent, since profiling and test output turned out >nothing else that was different. (See my reply to Istvan.) > >> Be warned that there were some bugs in PyMalloc that were fixed before >> Python 2.3 was released (when PyMalloc became a default option); as far as >> I recall, these bugfixes were never backported to 2.2x. So I wouldn't >> recommend running a 2.2.3 PyMalloc enabled interpreter in production >> without seriously testing all your production code. > >If PyMalloc helps, I'll push for an upgrade to 2.3. Thanks again. > Speculating broadly here, but have you considered possible cache effects? I.e., instructions execute faster when they and their operands can be fetched from the CPU cache, and similarly L2 cache is faster than RAM. What is in the caches at any point depends on what has recently been executed, and how different memory areas map into the cache, and that will probably depend on where you have put things in your program and what order you call for its execution (the OS kernel may also affect the cache via interrupt service routines and/or multitasking etc, e.g., for downloading or playing music in the background (which I doubt you did) ;-) ). If you have multiple CPUs they do better if they don't work on each others' jobs too much, since a switch tends to mess up caching. I think some older kernels don't take that into account, but maybe that's all history by now. In a loop, typically the first time through will show cacheloading overhead, and the rest will benefit, with blips for interrupts or interpreter special effects such as extending an allocation pool or garbage collecting. These get washed out in big averages, or filtered out in best-of timings, but they can be seen if you create a graphic that shows every timing (e.g. a raster of dots colored by time if there's a lot of timings). (Of course you have to watch out that your data capture doesn't cause overhead that invalidates your results. It can be tricky.) Another effect that has shown up as mystery culprit in the past is CPU heating and consequent automatic slowing of the clock to prevent damage, but that doesn't seem that likely in this case. Another way you could lose time is if your code gets into a new relationship in time with some other code than yours. Just speculating in general here, but if you are processing data coming from a disk or other i/o that has some natural clumping to it in the OS, such as waiting for an interrupt that says the next cluster read is ready to fill buffers from, and for one arrangement of your code that happened just before you executed and the other way just after, then there would be a difference in interfering cache effects due to OS activity. Also, if you do a succession of i/o that can't physically happen back to back, then you should be able to gain by doing some computing in between. OS buffering and disk caches mitigate this, but you can empty or stuff them so they demand physical i/o, depending on your program. Moving such code would presumably have an effect on overall timing. Of course, if you are also doing multi-threaded stuff in your program, it's another ball game. My USD.02 Regards, Bengt Richter From rogerb at rogerbinns.com Sun Aug 1 19:34:05 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Sun, 1 Aug 2004 16:34:05 -0700 Subject: SFTP file transfer library References: Message-ID: <39b0u1-c8a.ln1@home.rogerbinns.com> Lothar Scholz wrote: > at the moment i have a program that uses FTP but some clients want to > use the FTP over SSH protocol. > > Is there a library that does this ? > And also where can i find the protocol specification. I never used SSH > very much and only know how to start a SSH shell from my windows > client. There is an excellent Python library named paramiko you can find at http://www.lag.net/~robey/paramiko/ As for the second part of your question, try this: http://www.google.com/search?q=ssh+protocol+specification Roger From cookedm+news at physics.mcmaster.ca Mon Aug 30 15:40:56 2004 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Mon, 30 Aug 2004 15:40:56 -0400 Subject: about presicion References: Message-ID: At some point, "Batista, Facundo" wrote: > [alikakakhel3 at hotmail.com] > > #- ok but where can i download deciaml? waht about gmpy? which > #- is better? > >>From http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Lib/ > > Don't know gmpy, so I can't compare. But decimal will be in the standard > library, so since Py2.4 you'll not need an external module. http://gmpy.sourceforge.net/ -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From michaels at rd.bbc.co.uk Thu Aug 12 06:25:27 2004 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Thu, 12 Aug 2004 11:25:27 +0100 Subject: A decorator syntax not yet mentioned (I think!) References: <60dfb6f6.0408111846.615ee9eb@posting.google.com> <3YWdnYxLf--ObofcRVn-pw@powergate.ca> Message-ID: Regarding J2 on http://www.python.org/moin/PythonDecorators ... ... > 5 Technical problems with the current grammar parser if a suite > *starts* with an optional part. (Ending with an optional part, > such as "else:" is OK, but starting with one is not.) ... > Item 6 is always the case for any new feature, so I doubt that's the > real problem - the real problem here strikes me as item 5. > > I do wonder how difficult it would be to add though... It doesn't actually seem that difficult to modify the grammar to handle this if the decorator block handles *only* decorators. I've just tried modifying the Grammar/Grammar file to see how plausible this is, and I can get python to build and parse it. (It bombs out because I've not done any backend work, and this is the first time I've touched the python compiler source) The change I made was this: --- Python-2.4a2/Grammar/Grammar 2004-08-02 07:09:53.000000000 +0100 +++ Python-2.4a2-MS/Grammar/Grammar 2004-08-12 11:05:04.085386128 +0100 @@ -27,10 +27,13 @@ single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE file_input: (NEWLINE | stmt)* ENDMARKER eval_input: testlist NEWLINE* ENDMARKER - -decorator: '@' dotted_name [ '(' [arglist] ')' ] +# decorator: '@' dotted_name [ '(' [arglist] ')' ] +# decorators: decorator ([NEWLINE] decorator)* NEWLINE +# funcdef: [decorators] 'def' NAME parameters ':' suite +decorator: dotted_name [ '(' [arglist] ')' ] decorators: decorator ([NEWLINE] decorator)* NEWLINE -funcdef: [decorators] 'def' NAME parameters ':' suite +decoratedfuncdef: 'decorate' ':' NEWLINE INDENT decorators DEDENT funcdef +funcdef: 'def' NAME parameters ':' suite parameters: '(' [varargslist] ')' varargslist: (fpdef ['=' test] ',')* ('*' NAME [',' '**' NAME] | '**' NAME) | fpdef ['=' test] (',' fpdef ['=' test])* [','] fpdef: NAME | '(' fplist ')' @@ -59,7 +62,7 @@ exec_stmt: 'exec' expr ['in' test [',' test]] assert_stmt: 'assert' test [',' test] -compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef +compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef| decoratedfuncdef | classdef if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] while_stmt: 'while' test ':' suite ['else' ':' suite] for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] This change seems to allow the following code to be parsed happily: class Foo: decorate: staticmethod def hello(who): print "woo?", who def hello2(who): print "woo?", who I say *seems* because I'm getting seg faults when I try and *run* the above, but the following produces an expected syntax error - _implying_ that the code above is parsed correctly... class ThisShouldBreak: decorate: staticmethod def hello(who): print "woo?", who def hello2(who): print "woo?", who def crashandburnhere(who) print "woo?", who (Backtrace from the seg faults seem to point at other stuff as well, but I don't know the python source well enough to say for certain! I suspect the reason is because I've yanked the leading "@" more than anything else) There is a restriction here - the contents of the decorate block must be limited to what you would get after an "@" - ie just declarations - it's not a "suite" (bunch of statements). Michael. -- Michael.Sparks at rd.bbc.co.uk British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From nzanella at cs.mun.ca Wed Aug 18 17:41:46 2004 From: nzanella at cs.mun.ca (Neil Zanella) Date: 18 Aug 2004 14:41:46 -0700 Subject: static class methods and data members Message-ID: Hello, I would like to know whether it is possible to define static class methods and data members in Python (similar to the way it can be done in C++ or Java). These do not seem to be mentioned in "Learning Python" by Mark Lutz and David Ascher. It seems like they are a relatively new feature... It seems to me that any truly OO programming language should support these so I'm sure that Python is no exception, but how can these be defined/implemented in Python? Currently I have Python version 2.3 installed on my system. Thanks, Neil From nothanks at nothere.com Wed Aug 25 03:21:29 2004 From: nothanks at nothere.com (Emiliano Molina) Date: Wed, 25 Aug 2004 07:21:29 GMT Subject: Subclassing built-in types Message-ID: Where can I find information on how to do this? Specifically I am concerned about something like: class NewList(list): def __init__(self): list.__init__(self) The above code does not allow the passing of a sequence to populate the NewList. I imagine that the correct way to do it is something like: class NewList(list): def __init__(self,seq): list.__init__(self,seq) but I can't find any documentation that describes what arguments list.__init__ may take. Where can I find that documentation? I've looked through the manual but can't find anything relevant. Google searches bring up articles that talk about code as described in my first example but I can't find anything like the second. From dperl at rogers.com Fri Aug 27 16:12:23 2004 From: dperl at rogers.com (Dan Perl) Date: Fri, 27 Aug 2004 20:12:23 GMT Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com><9%JXc.79851$pTn.63106@news01.bloor.is.net.cable.rogers.com> Message-ID: I am using 2.3 and I tried importing from a zip file in a script of my own and, yes, it works. I never used the -v flag before but it's great for debugging some problems. Thanks for mentioning it! Dan "Anthony Baxter" wrote in message news:mailman.2541.1093628460.5135.python-list at python.org... > Note that the PEP is not up-to-date. zipimport "just works" in Python > 2.3 and Python 2.4. In the following example, we use the -v flag to > show where imports are coming from. From m_vddungen at yahoo.com Fri Aug 6 16:34:29 2004 From: m_vddungen at yahoo.com (Marcel van den Dungen) Date: 6 Aug 2004 13:34:29 -0700 Subject: advice for perl expert wanting to learn python References: Message-ID: <98862c6.0408061234.5259c76a@posting.google.com> Zeljko Vrba wrote in message news:... > Now, why would I like to learn Python: because of IronPython port to CLR. > Perl port to CLR doesn't seem to be coming soon. First Perl6 for Parrot has > to be written, and then other backends.. > > What's the easiest way of learning python knowing perl? Is there somewhere > a 'how-to' cookbook with parallel examples of frequent idioms in perl and > python? > See the Perl/Python phrasebook: http://www.python.org/moin/PerlPhrasebook -- Marcel From amk at amk.ca Fri Aug 27 09:16:04 2004 From: amk at amk.ca (A.M. Kuchling) Date: Fri, 27 Aug 2004 08:16:04 -0500 Subject: Call for signatories for J2 References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> <7xhdqp967k.fsf@ruckus.brouhaha.com> <412e3ba4$0$92817$ed2619ec@ptn-nntp-reader02.plus.net> <2p7rurFhgglpU1@uni-berlin.de> Message-ID: On Fri, 27 Aug 2004 14:42:34 +1000, Anthony Baxter wrote: > I don't know what additional discussion on python-dev would have > accomplished. Almost no-one spoke up about the @syntax when I posted > the first note. A similar thing happened with the various cataloging efforts. A number of individuals wrote prototypes and asked for comments from the community, never getting any. Finally Richard Jones wrote PyPI, put it on python.org, and contributed the 'register' Distutils subcommand to the standard library; there was little outside input on all of this. Of course, the difference is that PyPI hasn't been controversial. But I think it does demonstrate that Python development is steered mostly by individuals, not by the vague wishes of the community. --amk From davidf at sjsoft.com Tue Aug 24 04:58:22 2004 From: davidf at sjsoft.com (David Fraser) Date: Tue, 24 Aug 2004 10:58:22 +0200 Subject: My only complaint about Python In-Reply-To: <3flei0t87s2qpsunb94mrbfb5fc4nplnsl@4ax.com> References: <874qmxj81k.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> <3flei0t87s2qpsunb94mrbfb5fc4nplnsl@4ax.com> Message-ID: Andrea Griffini wrote: > On 21 Aug 2004 08:53:59 +0200, 510046470588-0001 at t-online.de wrote: > > >>>They do. MSC/C++ is now available at NO cost: >>> >> >>no cost is not the same as free > > > Do you mean that there are limitations about legal use of > VC toolkit 2003 for building a python interpreter or that > you actually need to see the source code of the C compiler > to build python ? There are other benefits to open source compilers - in gcc's case, a specific advantage is that it can cross-compile from other operating systems. In certain circumstances that can be a big advantage David From pm_mon at yahoo.com Fri Aug 27 09:58:10 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Fri, 27 Aug 2004 09:58:10 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: <412F347E.4040602@sympatico.ca> References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> <412F347E.4040602@sympatico.ca> Message-ID: Colin J. Williams wrote: > > > Paul Morrow wrote: > [snip] > >> >> >> Yes, it doesn't seem all that complex, although I'm not sure that >> everyone reading this understands them and their subtleties. The >> following is an excerpt from >> http://docs.python.org/tut/node11.html#SECTION0011200000000000000000 >> >> "A namespace is a mapping from names to objects. Most namespaces are >> currently implemented as Python dictionaries, but that's normally not >> noticeable in any way (except for performance), and it may change in >> the future. Examples of namespaces are: the set of built-in names >> (functions such as abs(), and built-in exception names); the global >> names in a module; and the local names in a function invocation. In a >> sense the set of attributes of an object also form a namespace." >> >> When I talk about namespaces, I include all of the above, including >> the sense mentioned in the last line. So an object's attributes >> constitute a namespace too. Therefore __doc__, being an attribute of >> the function object, is in the function object's /namespace/. And >> note that this is *not* a new namespace; it's been there all along. >> > Could you elaborate on the last sentence please? Is the namespace not > created when the def ... line(s) is/are executed? > If Python waits until then, where does it put the docstring in the meantime? I haven't actually looked at the code [*], but it would make sense for the function's namespace to be created at the beginning of the def execution (so that it had a place for the __doc__ attribute when the docstring was encountered). * Oh Anthony will want to jump on that one :-) From martin at koekenberg.net Wed Aug 25 16:32:28 2004 From: martin at koekenberg.net (Martin Koekenberg) Date: Wed, 25 Aug 2004 22:32:28 +0200 Subject: TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' References: Message-ID: <3ptpi0h6i94l7c6raml10o4d3sml2e1etf@4ax.com> Hello Steve, That is not the problem. gcc-3.3.3-7 and gcc-c++-3.3.3-7 are installed. Greetings, Martin Koekenberg On Fri, 20 Aug 2004 14:12:50 +0530, Steve wrote: >Hi Martin, >> File "/usr/local/lib/python2.3/distutils/sysconfig.py", line 159, in >> customize_compiler >> cpp = cc + " -E" # not always >> TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' >> make: *** [build] Error 1 > >Judging by the error I'm guessing that you might not have a c or c++ >compiler installed. Run the following command to check if you have the >required rpms: > >rpm -q gcc >rpm -q gcc-c++ > >Install them if you they are missing and then rerun 'configure' and 'make'. > >HTH >Steve From Michael.J.Fromberger at Clothing.Dartmouth.EDU Tue Aug 10 11:19:07 2004 From: Michael.J.Fromberger at Clothing.Dartmouth.EDU (Michael J. Fromberger) Date: Tue, 10 Aug 2004 11:19:07 -0400 Subject: Purely emotional perspective References: <10hf3oaltbo7o74@corp.supernews.com> Message-ID: In article , Peter Hansen wrote: > > Python is clearly on a huge evolutionary surge and conservative views > on the matter are definitely not winning out right now. And the usual > argument (submit a patch!) doesn't really work when those who want to > avoid many changes try it... I've been *not* submitting a patch on > lots of changes to Python, but somehow it's never been accepted. ;-) I think you are right, Peter, about the pressure to change the nature of Python, and the resistance to conservatism about doing so. I have been following the explosion of discussion on this subject with some concern, because I think this whole "decorators" proposal is a misguided attempt to conflate several orthogonal goals under the aegis of a single new mechanism. I do not believe it is wise to aggregate the notations for descriptive meta-data (author, version number, etc.) with those of type-constraints, of method qualifiers, or any other such code-generation annotations. Much of the discussion has focused on the visual appearance of this new construct, but I think that's a red herring -- its problems run much deeper than that. Even assuming we can find a suitably harmonious notation for it, I remain unconvinced that "decorators" as currently specified deserve to be added to Python. Assuming we take the Zen of Python as a set of philosophical design goals for Python, I argue that all the proposed uses of decorators so far fail the Zen on the following axes: Beauty, Simplicity, Sparseness, Readability, Special Cases, One Obvious Way, and Difficulty of Explanation. The stated Motivation of PEP-318 is, essentially, to visually conjoin the translation of functions into class or static methods with the definition of the function itself. Oh, and by the way, maybe we could also use this for some other annotations we'll think up later -- but for now, that's pretty much it (http://www.python.org/peps/pep-0318.html). Do we really need this small change so badly that we're willing to open the door to every half-baked hunk of function and method meta-data somebody can imagine? Let's stop bickering about syntax for a moment, take a deep breath, and back up a pace. Does Python really need this? I say no: Even if we come up with a good syntax, I do not think decorators, as they are being described and implemented as we speak, are a good idea. Some of the ideas people want to use them for are reasonable, but I think we should be rational about it, and keep orthogonal concerns appropriately separated. -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From tdelaney at avaya.com Sun Aug 29 20:54:08 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Mon, 30 Aug 2004 10:54:08 +1000 Subject: allowing braces around suites Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01DCFF12@au3010avexu1.global.avaya.com> Igor V. Rafienko wrote: > As a side note -- my last employer had absolutely horrible coding > conventions. No one liked them (developers and management included). > However, everyone had to comply, and despite an occasional nastiness, > the bug that you illustrated could not have happened in that > environment, because _every_ if was required to have its body within > braces. In C/C++/Java, that's a sensible coding convention. I won't quibble that there may have been other ones in the coding standards that were bad, but that specific example is not. In Python, it's a non-issue. Tim Delaney From peter at engcorp.com Thu Aug 26 07:08:39 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 26 Aug 2004 07:08:39 -0400 Subject: Why return None? In-Reply-To: References: Message-ID: Martin DeMello wrote: > Peter Hansen wrote: >>By the way, the second version is much more readable than >>the first, so perhaps there is a secondary reason for this >>"return None" thing in addition to the more important one... > > It depends on what you're doing - to me, the first is simply "the > normalised vector (a,b,c)", inlined. It's a single concept, much like an > inlined string is - would you want to do the following? > a = "Hello " > a = a + str(name) > print a I'd want to do neither, often. If I had to do either, often, I would write a function which did the required operations and I'd call that instead. Then both it and the calling code are readable. But I suppose that's just me... maybe others would prefer to repeat things more. -Peter From edreamleo at charter.net Thu Aug 5 13:35:57 2004 From: edreamleo at charter.net (Edward K. Ream) Date: Thu, 5 Aug 2004 12:35:57 -0500 Subject: Confused about pep 318 References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: <10h4s026oapbhf1@corp.supernews.com> > > There had previously been no public discussions about it. > Nonsense. I could not disagree more. Pretending that discussions on py-dev and SourceForge count as truly public discussions of pep 318 is most unwise. pep 318 does not discuss '@' at all. People like me, with a strong interest in how Python uses '@', would not naturally have known about the proposed new syntax until the stuff hit the fan. Indeed, pep 318 is grossly misleading; reading it one gets the distinct impression that the design is far from complete. It is my strong opinion that _no_ public discussion of this new code has taken place, and none _can_ take place until we see what it is exactly that is being proposed. This is an issue of basic fairness and openness. I have complained loudly to the [B]DFL. We shall see... Edward -------------------------------------------------------------------- Edward K. Ream email: edreamleo at charter.net Leo: Literate Editor with Outlines Leo: http://webpages.charter.net/edreamleo/front.html -------------------------------------------------------------------- From crichton314 at btinternet.com Tue Aug 17 05:23:12 2004 From: crichton314 at btinternet.com (John Crichton) Date: 17 Aug 2004 02:23:12 -0700 Subject: music resources References: Message-ID: <3b2846c4.0408170123.631477b6@posting.google.com> "Elaine Jackson" wrote in message news:... > Is there such a thing as an executable language for music? If not, why not? And > if yes, where can I find it? Naturally the ideal thing would be if such a > language were implemented within python, but I would be willing to learn a > lesser programming language if I had a reasonable assurance that it had what I'm > looking for. I have, of course, googled for a solution, and I may have even > found it, but if so I didn't recognize it as such. Any pointers will be mucho > appreciado. > > Peace "I hope these links are of some use, Elaine: PMIDI: Python MIDI library for Windows http://www.python.org/pypi?:action=display&name=PMIDI&version=1.0 pySonic: FMOD for Python (pySonic is a Python wrapper around the high performance, cross platform FMOD sound library. You get all the benefits of the FMOD library, but in a Pythonic, object oriented package) http://www.python.org/pypi?:action=display&name=pySonic&version=0.3 You could also have a look at Java music projects (and access them through Jython) http://www.softsynth.com/links/java_music.html Best wishes, John" From ajsiegel at optonline.com Thu Aug 26 20:00:23 2004 From: ajsiegel at optonline.com (Arthur) Date: Fri, 27 Aug 2004 00:00:23 GMT Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: On 26 Aug 2004 15:20:10 -0700, jess.austin at gmail.com (Jess Austin) wrote: >Paul Morrow wrote in message news:... >> Currently, you can change a doc string outside of a function, by >> modifying the function's __doc__ attribute > >[snip] > >> IMO, to change it inside of a function def should be (but isn't) as easy >> as... >> >> >>> def foo(): >> ... """ I am foo """ >> ... __doc__ = __doc__ + 'indeed' > >I'm not trying to be mean, but why not use a class for this? I believe he was only being illustrative. My use case: (unless I'm being stupid) IDLE 1.0.3 >>>class foo: hint ="boo" def bar(self): "bar using %s" %hint pass >>> f=foo() >>> print f.bar.__doc__ None vs. >>> class foo: hint ="boo" def bar(self): pass bar.__doc__="bar using %s" %hint >>> f=foo() >>> print f.bar.__doc__ bar using boo But to me more important, in the context of the overall discussion, is in seeing some good connectedness between the problem of being forced outside and below the function to use string substitution on its docstring, and the limited range of options that seem to be available to try to solve the percieved syntax problems related to transformations (pre a2) being stuck outside and below. Is the apparent connectedness only skin deep? It's not making sense to me that is. Art From jeffrey at fro.man Sat Aug 14 13:45:21 2004 From: jeffrey at fro.man (Jeffrey Froman) Date: Sat, 14 Aug 2004 10:45:21 -0700 Subject: Practical examples References: Message-ID: Bigbowser wrote: > I'm new to python, and have read through > http://www.ibiblio.org/obp/thinkCSpy/ , and now I'm > looking for some simple programs to have a read > through and other more in-depth tutorials to have a > look at. Here's a nice site full of examples: http://aspn.activestate.com/ASPN/Python/Cookbook/ Jeffrey From mark_bottjer at hotmail.com Thu Aug 12 20:22:01 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Thu, 12 Aug 2004 20:22:01 -0400 Subject: Why I love python. In-Reply-To: References: Message-ID: <411c09aa$1@nntp.zianet.com> Michael Scarlett wrote: > I don't know about the rest of you, but I learned python and fell in > love with its syntax and simplicity. That's the funny thing about Python. It really isn't simple, but it sure seems like it is. There's tons of little niggling rules about scoping, inheritance, and what have you--but you can be blissfully ignorant of most of them and still get work done. That's pretty unique. I think that's why people are so concerned about @pie: it has the *potential* to be an obstacle early in the learning process, instead of after someone is already hooked. > Am i the only one with a visceral reaction to this thing??? Goodness, no! Why do you think we've all been pissing and moaning so much? -- Mark From 1stpoint at zmailbox.net Thu Aug 5 12:31:17 2004 From: 1stpoint at zmailbox.net (1stpoint) Date: Thu, 05 Aug 2004 12:31:17 -0400 Subject: Automated Address/Phone Lookup Message-ID: I have a requirement to take a flat file of name , state and county and perform a 'people search' returning the hits for each name. Has anyone developed a python 'bot' to do a phone lookup from the web and return the results? From rkern at ucsd.edu Tue Aug 17 21:47:15 2004 From: rkern at ucsd.edu (Robert Kern) Date: Tue, 17 Aug 2004 20:47:15 -0500 Subject: what wrong with this program? In-Reply-To: <8f17f4bc.0408171632.787eb6f8@posting.google.com> References: <8f17f4bc.0408171632.787eb6f8@posting.google.com> Message-ID: Ali wrote: > The following program is supposed to display a dropdown menu, however, > it only shows the File and Help things. > > from Tkinter import * > > root = Tk() > > #create menu > m = Menu(root) > root.config(menu=m) > > filemenu = Menu(m) > m.add_cascade(label="File", menu="filemenu") The menu= argument needs to be the object itself, not a string. See, e.g. http://www.pythonware.com/library/tkinter/introduction/x5819-patterns.htm -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From calidusdk at hotmail.com Mon Aug 23 15:13:52 2004 From: calidusdk at hotmail.com (Artemisio) Date: 23 Aug 2004 12:13:52 -0700 Subject: line shift? (baby steps 2) References: <6daa8765.0408230412.6db365d6@posting.google.com> <2oueokFe36qgU2@uni-berlin.de> Message-ID: <6daa8765.0408231113.2e4a43d1@posting.google.com> Reinhold Birkenfeld wrote in message news:<2oueokFe36qgU2 at uni-berlin.de>... > Artemisio wrote: > > I have done a small currency calculator. It works and I'm very glad. > > But...I'd like to have a line shift if user types a wrong choice. > > Please, look at the code and output example down here: > > > > # -*- coding: ISO-8859-1 -*- > > import string > > > > eudk_currency= 7.47 > > dkeu_currency= 0.13 > > usdk_currency= 5.93 > > dkus_currency= 0.16 > > euus_currency= 1.19 > > useu_currency= 0.78 > > As a hint not pertaining to your actual problem: Use a dictionary to > store the values, like this: > > currencies = { "EUDK" : 7.47, "DKEU" : 0.13, (...) } > > Then you do not have to do if statements like this > > if currency_str == "DKEU": > result= amount_int* dkeu_currency > print amount_int, "Danish Crowns correspond to", result, "Euro." > > (...) > > You can directly use the input string as index into the dictionary: > > result = amount_int * currencies[currency_str] > print (...) > > Reinhold Great! Thank you pals! I'll have a closer look to your suggestion Reinhold, it seems a slick way to do the same thing From justme at fakedomain.net Thu Aug 26 19:47:39 2004 From: justme at fakedomain.net (MPB) Date: Thu, 26 Aug 2004 23:47:39 GMT Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: Who let that idiot back in? On 25 Aug 2004 14:56:06 -0700, Xah Lee wrote: > Larry Wall and Cults > (Lazyness, Impatience and Hubris) ... > Xah > xah at xahlee.org > http://xahlee.org/PageTwo_dir/more.html From vincent_delft at yahoo.com Sun Aug 22 03:30:08 2004 From: vincent_delft at yahoo.com (vincent_delft at yahoo.com) Date: Sun, 22 Aug 2004 09:30:08 +0200 Subject: zipfile module: problems with filename having non ascii characters References: <4127a6d7$0$4090$ba620e4c@news.skynet.be> Message-ID: <41284ac0$0$3551$ba620e4c@news.skynet.be> Jeff Epler wrote: > Zip files don't have a way to define the encoding of filenames---names > are just byte strings, and different utilities may interpret them in > different ways. The only thing that seems to be defined is that '/' is > the directory separator, and possibly that the filename can't contain > '\0'. > Thanks, I've got the problem and replace all "\" to "/". > You can probably find the encoding that winzip uses with a little > trial-and-error, and convert your filenames in your encoding to > filenames in that encoding. This may depend on the language or region > of the installed Windows, though. > Thanks for the explanation. That limitation is only valid for zip files ? Is there an another "compression tool" that don't have such limitation (tgz? , bz2? , ???? From bokr at oz.net Fri Aug 6 16:19:56 2004 From: bokr at oz.net (Bengt Richter) Date: 6 Aug 2004 20:19:56 GMT Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) References: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> Message-ID: On Fri, 06 Aug 2004 08:24:47 -0400, Peter Hansen wrote: >Istvan Albert wrote: > >> Paul McGuire wrote: >> >> > Please reconsider the "def f() [classmethod]:" construct. >> > >> > def f() [ staticmethod, >> > synchronized, >> > alphabetized, >> > supersized, >> > returns('d') ]: > >Nobody has bothered to post an example with a long argument list, >thus ignoring the possibly valid claim in the PEP that this would >make the decorator list hard to see. Here goes: > > def someMethod(self, posArgOne, anotherArg, > fieldX=56, > x=5, y=7, z=9, > **kwargs) > [ > staticmethod, > synchronized, > alphabetized, > supersized, > returns('d') > ]: > >Okay, pretty much an abomination, but I'm not sure it's any worse than >the alternative with @: > > @staticmethod > @synchronized > @alphabetized > @supersized > @returns('d') > def someMethod(self, posArgOne, anotherArg, > fieldX=56, > x=5, y=7, z=9, > **kwargs): > >It *is*, however, fairly clear that the list of decorators becomes >harder to see. Without checking, it's definitely possible that the >decorator list in the first case is actually part of the argument list. > It seems to me that all the proposed syntaxes have in common the purpose of creating an ordered set of functions to be applied in order to the result of a def. Why not accept this and use a builtin object to hold the temporary function sequence? Thus you could have a method (or __call__) add one or more functions to the temporary set contained in the builtin object. Then the list of functions can be the argument list to a method of the builtin object instead of list syntax magically interpreted in list-after-def context, magically saving the sequence in a magic internal place (as opposed to programmer-known and overrideable). If you had a builtin object and a builtin userfriendly alias for a method that adds one or more decorators to its list (that gets used up at the end of the next def), then you could write (picking decorate as user-friendly ;-) decorate(staticmethod, synchronized, alphabetized, supersized) decorate(returns('d')) def someMethod(self, posArgOne, anotherArg, fieldX=56, x=5, y=7, z=9, **kwargs ): #I like it better here for multiline arg lists ;-) # ... def implementation would have to be modified to look for the builtin object and get the decorator functions from there. You could choose to look for a shadowing name binding starting with locals(), or you could only allow a shadowing starting at globals() I suppose, for speed. BTW, is @decorator thread-safe? I guess it would be something to be careful about in a really dynamic object-oriented implementation. >I don't care. I still prefer it to @, if nothing else because >it's much more intuitive to a Python programmer what order they >will be applied in. > '@x' as a spelling of __programmer_inaccessible_hidden_system_temp_list.append(x) # or is it 'x' ? seems not the best use of '@' to me. Regards, Bengt Richter From abra9823 at mail.usyd.edu.au Fri Aug 27 00:13:48 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Fri, 27 Aug 2004 14:13:48 +1000 Subject: key storage In-Reply-To: <7x7jrl9tmx.fsf@ruckus.brouhaha.com> References: <1093569139.412e8a738462b@www-mail.usyd.edu.au> <412E8E53.20203@harvee.org> <7x7jrl9tmx.fsf@ruckus.brouhaha.com> Message-ID: <1093580028.412eb4fca7eab@www-mail.usyd.edu.au> -- Ajay Brar, CS Honours 2004 Smart Internet Technology Research Group Quoting Paul Rubin <"http://phr.cx"@NOSPAM.invalid>: > Ajay writes: > > the MIT paper mentions including HMAC's in the cookie and so on. the > > question still is - how are the keys stored? HMAC's require a key, as > do > > digital signatures. how are all these keys stored in a secure manner > on > > the server? obviously they's be encrypted but then the key used for > > encrypting the above key - how is that stored? > > Well, just what are you trying to protect? Access to the application > and its data? What happens if you just put the key in a disk file? > If someone can get at it, can't they also get at the rest of the data, > so the key is no longer helping protect that data? Who are you trying > to keep the key secret from? > -- well i am really trying to restruct access to certain users. session management is done using a cookie, and the cookie includes a key hashed digest of the rest of the cookie data. so thats the first key. the second key is the private key used to sign documents which users can download from the site. so its basically access to the application that i am trying to protect. i dont intend to put the key in an unencrypted form on a file and leave it there - and hence my question. and the best answer so far has been some sort of proxy service activated using a passphrase which deciphers a passphrase encrypted file and reads keys from there. a second option may be a similar service which is started by an admin and reads keys from the file. the file can then be removed from the server and the keys stay in memory. my app can then request the keys from the proxy. ofcourse this then involves ensuring authroized access only to the proxy and whole new set of mechanisms to prevent unauthorized access to the proxy. any more suggestions are most welcome. cheers > http://mail.python.org/mailman/listinfo/python-list > ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From grv575 at hotmail.com Wed Aug 25 20:16:31 2004 From: grv575 at hotmail.com (grv575) Date: 25 Aug 2004 17:16:31 -0700 Subject: numarray speed question References: <953AD3D0Didtoken@128.91.2.239> <953C4DD4idtoken@128.91.2.239> <144d0df.0408070828.338f8c19@posting.google.com> <9540516Didtoken@128.91.2.239> Message-ID: <144d0df.0408251616.5758d6e7@posting.google.com> Is it true that python uses doubles for all it's internal floating point arithmetic even if you're using something like numarray's Complex32? Is it possible to do single precision ffts in numarray or no? cookedm+news at physics.mcmaster.ca (David M. Cooke) wrote in message news:... > At some point, grv575 at hotmail.com (grv) wrote: > > > cookedm+news at physics.mcmaster.ca (David M. Cooke) wrote in > > : > > > >>At some point, grv575 at hotmail.com (grv575) wrote: > > >>> Heh. Try timing the example I gave (a += 5) using byteswapped vs. > >>> byteswap(). It's fairly fast to do the byteswap. If you go the > >>> interpretation way (byteswapped) then all subsequent array operations > >>> are at least an order of magnitude slower (5 million elements test > >>> example). > >> > >>You mean something like > >>a = arange(0, 5000000, type=Float64).byteswapped() > >>a += 5 > >> > >>vs. > >>a = arange(0, 5000000, type=Float64) > >>a.byteswap() > >>a += 5 > >> > >>? I get the same time for the a+=5 in each case -- and it's only twice > >>as slow as operating on a non-byteswapped version. Note that numarray > >>calls the ufunc add routine with non-byteswapped numbers; it takes a > >>block, orders it correctly, then adds 5 to that, does the byteswap on > >>the result, and stores that back. (You're not making a full copy of > >>the array; just a large enough section at a time to do useful work.) > > > > It must be using some sort of cache for the multiplication. Seems like on > > the first run it takes 6 seconds and subsequently .05 seconds for either > > version. > > There is. The ufunc for the addition gets cached, so the first time > takes longer (but not that much???) > > >>Maybe what you need is a package designed for *small* arrays ( < 1000). > >>Simple C wrappers; just C doubles and ints, no byteswap, non-aligned. > >>Maybe a fixed number of dimensions. Probably easy to throw something > >>together using Pyrex. Or, wrap blitz++ with boost::python. > > > > I'll check out Numeric first. Would rather have a drop-in solution (which > > hopefully will get more optimized in future releases) rather than hacking > > my own wrappers. Is it some purist mentality that's keeping numarray from > > dropping to C code for the time-critical routines? Or can a lot of the > > speed issues be attributed to the overhead of using objects for the library > > (numarray does seem more general)? > > It's the object overhead in numarray. The developers moved stuff up to > Python, where it's more flexible to handle. Numeric is faster for > small arrays (say < 3000), but numarray is much better at large > arrays. I have some speed comparisions at > http://arbutus.mcmaster.ca/dmc/numpy/ > > I did a simple wrapper using Pyrex the other night for a vector of > doubles (it just does addition, so it's not much good :-) It's twice > as fast as Numeric, so I might give it a further try. From gohaku at earthlink.net Thu Aug 12 22:08:25 2004 From: gohaku at earthlink.net (gohaku) Date: Thu, 12 Aug 2004 22:08:25 -0400 Subject: multiline snippets with triple quotes In-Reply-To: References: Message-ID: On Aug 12, 2004, at 4:06 PM, Christopher T King wrote: > The textwrap.dedent() function is provided for just this purpose: > > from textwrap import dedent > > if output == html: > snip = dedent('''\ > > Hello, World >

    What's up?

    > ''') > else: > snip = 'Hello!' Can dedent capture indents or tabs also... I noticed that if I do the following: snip = '''blah blah ''' Tabs are included with snip. Is there a heredocs (don't know why it's called that) equivalent in Python? Thanks in advance. From news at nospamwillmcgugan.com Tue Aug 17 09:08:16 2004 From: news at nospamwillmcgugan.com (Will McGugan) Date: Tue, 17 Aug 2004 14:08:16 +0100 Subject: os popen problems in w98 In-Reply-To: References: Message-ID: <41220342$0$198$db0fefd9@news.zen.co.uk> fowlertrainer at anonym.hu wrote: > Hi ! > > I use this code section in my program: > > cho,chi=os.popen2(os.getcwd()+'/genlotto.py') > > genlotto=chi.read() > > genlotto=genlotto.strip()[1:-1] > > This code is working on wxp, and w2000. > I use that code to load a subprogram's result. > > In Win98 it is hanged, and is nothing happened. > > Why ? What I do wrong ? > > Thanx for help: > FT Just a guess, but I've noticed from C++ work that Win98 doesnt like the mixing of / and \ in urls. Try changing '/genlotto.py' to '\genlottor.py'. Will McGugan From swheatley at gmail.com Mon Aug 16 13:56:01 2004 From: swheatley at gmail.com (Shawn Wheatley) Date: Mon, 16 Aug 2004 13:56:01 -0400 Subject: Fwd: Flython? In-Reply-To: References: <411cbcb1$0$3894$4d4ebb8e@news.nl.uu.net> <30260531.0408131856.5ef3b0d3@posting.google.com> <2oc547F86br8U1@uni-berlin.de> Message-ID: On Mon, 16 Aug 2004 12:21:03 -0400, Daniel Ellison wrote: > Peter has on occasion been the unfortunate audience of my rants on the > current state of web application interfaces. I've been pushing the idea > of a Flash client for years. There seems to be (there *is*) a prejudice > toward Flash, probably due to those *very* annoying ads on web pages. [OT] Another rant that I hear frequently is the accessibility issue... older versions of Flash were very difficult to work with in terms of making your application accessible to handicapped users. From what I've heard, Flash MX and onward have fixed this problem. Anybody care to comment? Shawn From b.niemann at betternet.de Thu Aug 12 07:17:39 2004 From: b.niemann at betternet.de (Benjamin Niemann) Date: Thu, 12 Aug 2004 13:17:39 +0200 Subject: Mod python with multipart In-Reply-To: References: Message-ID: > Does anyone know how to read the "multipart/form-data" posted by a form? > I'm using mod_python 3.1 and Apache 2. > I looked at the docs of the request object but there is no description > on how to read multipart data. > I also tried google with "modpython multipart" but there are only a few > hits - I could not use them. this is a question for the mod_python ML, but anyway ;) I'm using data = cgi.FieldStorage(fp=req, headers=req.headers_in, keep_blank_values=True, environ={'REQUEST_METHOD':'POST'}) which works fine for me. Later I've seen that mod_python has it's own implementation of FieldStorage, but I have not tried it yet. From apavluck at gmail.com Wed Aug 25 22:42:00 2004 From: apavluck at gmail.com (Alex Pavluck) Date: 25 Aug 2004 19:42:00 -0700 Subject: Help needed: Transition from SAS to PYTHON Message-ID: Hello. I am trying to teach myself PYTHON because I am interested in programming. I use SAS all day and I really like the way you can highlight code and submit just that section or submit the entire program without having to save it. Can you do this in PYTHON? Also, does PYTHON (Windows) log errors? It would be helpful when I am writting a program and I submit the code and it says that their is an error to know WHERE! Once again this is another feature of SAS. Have I just gotten too used to SAS or are there others out there that would also like to have this functionality?? Please help! Alex From grante at visi.com Mon Aug 16 01:07:04 2004 From: grante at visi.com (Grant Edwards) Date: 16 Aug 2004 05:07:04 GMT Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> <30260531.0408131853.18ec2446@posting.google.com> Message-ID: <412040f8$0$8087$a1866201@newsreader.visi.com> On 2004-08-16, Peter Hansen wrote: > Please, *why* did it put you off? Dunno, it just did. It seems to me that you're asking for a rational explanation for an emotional response. It's like asking somebody "*why* don't you like pickled beets?" The answer you get is "I just don't." Perhaps they're just too different from what you're used to eating. Perhaps there's something bad in your past associated with beets. It doesn't really matter, since it's not a reasoned, rational reaction. > Didn't you already indent your code consistently? Sure. > Didn't you think that the removal of those braces would > immediately make the code more readable (fewer lines, fewer > extra cruft to distract the eye) and easier to type? Sure. > I'm curious why more people don't have "neat!" as their very > first thought on encountering this, rather than "yuck!". It's a good question, but based on my extensive background of 3 undergrad psych classes, I don't think you're going to get accurate answers from the people experiencing the reactions. I think my negative reaction was because my only previous encounters with intentation significance was with Fortan IV and with Makefiles. I find dealing with both of those unpleasant (though I've gotten used to Makefiles over a period of 20+ years, I still trip of the "tab" thing several times a month -- at least Gnu make is kind enough to tell you exactly what you did wrong). In my case, I desperately needed a way to fetch e-mails from MS-Outlook, and writing a Python program looked like my only shot. So I went ahead and tried it. Within a few hours, I discovered I liked Python way of indentation. Now, with the exception of the occasional shell script, I use Python for everything that's not embedded or in kernel space. -- Grant Edwards grante Yow! Dizzy, are we at "REAL PEOPLE" or "AMAZING visi.com ANIMALS"? From nospamjynyl at yahoo.co.nz Tue Aug 3 15:19:06 2004 From: nospamjynyl at yahoo.co.nz (Peter) Date: Wed, 04 Aug 2004 07:19:06 +1200 Subject: PyQt - clear widget for redraw References: <410b4492@news.maxnet.co.nz> <410bf265@news.maxnet.co.nz> <410d0699@news.maxnet.co.nz> Message-ID: <410fad7d@news.maxnet.co.nz> Diez B. Roggisch wrote: > Maybe it helps to put your sleep not in the drawing code, but between the > arrival of different data sets to draw, thus limiting the redraws to an > amount of lets say 10/s. Yes - tried that, but gives incomplete draw / flicker. > If you'd fill us in with some more details, the suggestions might be > better. And I think it would be worth asking these qustions on the PyKDE > list Jim has mentioned - I'm also there :) More details: the idea is to provide a graphics demo of sort algorithms for my 13 year old son. A number of lines of differring lengths are shown on the screen, and you can watch as these are sorted, step by step. So you can see the difference between bubble sort, ripple sort, etc. Code copied below. Improving the smoothness of the display is the main thing I'm after. Also, how can I write the counters to the form? It uses the LCD widget now, but there must be another way. TIA Peter -- sort1.py --- #!/usr/bin/python # # demo of sort algorithms, using PyQt import sys, random, time from qt import * from frmtest import frmTest class dlgForm(frmTest): def __init__(self, parent=None): frmTest.__init__(self, parent) self.connect(self.cmdQuit, SIGNAL("clicked()"),self, SLOT("close()")) self.connect(self.cmd2, SIGNAL("clicked()"), self.reshuffle) self.connect(self.cmdSort, SIGNAL("clicked()"), self.sort1) self.connect(self.cmdBubble, SIGNAL("clicked()"), self.bubble) self.connect(self.cmdRipple, SIGNAL("clicked()"), self.ripple) self.connect(self.cmdShell, SIGNAL("clicked()"), self.shells) self.refresh() def reshuffle(self): global cComp, cSwap, b1, b2, r1, r2 cComp, cSwap, b1, b2 = [0,0,0,len(l1)] random.shuffle(l1) self.refresh() def sort1(self): global cComp, cSwap, b1, b2, r1, r2 cComp, cSwap, b1, b2 = [0,0,0,len(l1)] l1.sort() self.refresh() def bubble(self): # simple bubble sort global cComp, cSwap, b1, b2, r1, r2 cComp, cSwap, b1, b2 = [0,0,0,len(l1)] b1 = 0 b2 = len(l1) for i in range(len(l1)): b2 = len(l1) - i for j in range(b2-1): cComp = cComp + 1 r1 = j r2 = j+1 if l1[r1] > l1[r2]: cSwap = cSwap + 1 l1[r1], l1[r2] = [l1[r2], l1[r1]] self.refresh() time.sleep(0.02) def ripple(self): global cComp, cSwap, b1, b2, r1, r2 cComp, cSwap, b1, b2 = [0,0,0,len(l1)] bDone =1 while bDone: bDone = 0 for j in range(b1,b2-1): cComp = cComp + 1 r1 = j r2 = j + 1 if l1[r1] > l1[r2]: cSwap = cSwap + 1 bDone = 1 l1[r1], l1[r2] = [l1[r2], l1[r1]] self.refresh() time.sleep(0.01) b2 = b2 - 1 for j in range(b2,b1,-1): cComp = cComp + 1 r1 = j - 1 r2 = j if l1[r1] > l1[r2]: cSwap = cSwap + 1 bDone = 1 l1[r1], l1[r2] = [l1[r2], l1[r1]] self.refresh() time.sleep(0.01) b1 = b1 + 1 self.refresh() def shells(self): global cComp, cSwap, b1, b2, r1, r2 cComp, cSwap, b1, b2 = [0,0, 0, len(l1)] bDone = 1 span = 64 while bDone: bDone = 0 for i in range(b1,b2-span): r1 = i r2 = i + span cComp = cComp + 1 if l1[r1] > l1[r2]: cSwap = cSwap + 1 bDone = 1 l1[r1], l1[r2] = [l1[r2], l1[r1]] self.refresh() time.sleep(0.01) if not bDone: # if no changes that sweep, exit break bDone = 0 if span > 1: span = int(span/2) for i in range(b2-1,b1+span,-1): r1 = i - span r2 = i cComp = cComp + 1 if l1[r1] > l1[r2]: cSwap = cSwap + 1 bDone = 1 l1[r1], l1[r2] = [l1[r2], l1[r1]] self.refresh() time.sleep(0.01) if span > 1: span = int(span/2) self.refresh() def refresh(self): self.LCDcount.display('%3d' % cComp) # update counters self.LCDswap.display('%3d' % cSwap) self.frame4.erase() # clear any old lines p = QPainter(self.frame4) mar = self.frame4.width()/100 # margin vsp = 2 # vertical spacing hrz = (self.frame4.width()-2*mar)/100 # horizontal scalar p.setPen(QColor("black")) for i in range(100): p.drawLine(mar,mar+vsp*i,hrz*(l1[i]+1),mar+vsp*i) p.setPen(QColor("blue")) p.drawLine(mar,mar+vsp*b1-1,hrz*100,mar+vsp*b1-1) p.drawLine(mar,mar+vsp*b2-1,hrz*100,mar+vsp*b2-1) p.setPen(QColor("red")) p.drawLine(mar,mar+vsp*r1+1,hrz*100,mar+vsp*r1+1) p.drawLine(mar,mar+vsp*r2+1,hrz*100,mar+vsp*r2+1) if __name__ == '__main__': l1 = range(100) # numbers 0 to 99 b1 = 0 # blue line 1 b2 = 100 # blue line 2 r1 = 1 # red line 1 r2 = 1 # red line 2 cComp = 0 # count of compares cSwap = 0 # count of swaps app = QApplication(sys.argv) QObject.connect(app, SIGNAL('lastWindowClosed()'), app, SLOT('quit()')) win = dlgForm() app.setMainWidget(win) win.show() app.exec_loop() ------------------------------------------------------- -------- frmtest.py -------------------------- # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'frmtest.ui' # # Created: Sun Aug 1 15:55:11 2004 # by: The PyQt User Interface Compiler (pyuic) 3.8 # # WARNING! All changes made in this file will be lost! from qt import * class frmTest(QMainWindow): def __init__(self,parent = None,name = None,fl = 0): QMainWindow.__init__(self,parent,name,fl) self.statusBar() if not name: self.setName("frmTest") self.setCentralWidget(QWidget(self,"qt_central_widget")) self.frame4 = QFrame(self.centralWidget(),"frame4") self.frame4.setGeometry(QRect(40,109,441,210)) self.frame4.setMinimumSize(QSize(440,210)) self.frame4.setFrameShape(QFrame.StyledPanel) self.frame4.setFrameShadow(QFrame.Raised) self.frame4.setMargin(1) self.cmd2 = QPushButton(self.centralWidget(),"cmd2") self.cmd2.setGeometry(QRect(210,330,100,50)) self.cmdSort = QPushButton(self.centralWidget(),"cmdSort") self.cmdSort.setGeometry(QRect(350,330,100,50)) self.cmdQuit = QPushButton(self.centralWidget(),"cmdQuit") self.cmdQuit.setGeometry(QRect(70,330,100,50)) self.txtHello = QLabel(self.centralWidget(),"txtHello") self.txtHello.setGeometry(QRect(50,20,450,76)) txtHello_font = QFont(self.txtHello.font()) txtHello_font.setPointSize(48) self.txtHello.setFont(txtHello_font) self.txtHello.setAlignment(QLabel.AlignCenter) self.cmdBubble = QPushButton(self.centralWidget(),"cmdBubble") self.cmdBubble.setGeometry(QRect(500,109,80,40)) self.cmdRipple = QPushButton(self.centralWidget(),"cmdRipple") self.cmdRipple.setGeometry(QRect(500,160,80,40)) self.cmdShell = QPushButton(self.centralWidget(),"cmdShell") self.cmdShell.setGeometry(QRect(500,210,80,40)) self.txtCopyright = QLabel(self.centralWidget(),"txtCopyright") self.txtCopyright.setGeometry(QRect(40,380,400,21)) self.LCDswap = QLCDNumber(self.centralWidget(),"LCDswap") self.LCDswap.setGeometry(QRect(490,370,91,31)) self.LCDswap.setSegmentStyle(QLCDNumber.Flat) self.LCDcount = QLCDNumber(self.centralWidget(),"LCDcount") self.LCDcount.setGeometry(QRect(490,329,91,31)) self.LCDcount.setMode(QLCDNumber.Dec) self.LCDcount.setSegmentStyle(QLCDNumber.Flat) self.languageChange() self.resize(QSize(603,438).expandedTo(self.minimumSizeHint())) self.clearWState(Qt.WState_Polished) def languageChange(self): self.setCaption(self.__tr("test form")) self.cmd2.setText(self.__tr("Reshuffle")) self.cmdSort.setText(self.__tr("Sort")) self.cmdQuit.setText(self.__tr("Quit")) self.txtHello.setText(self.__tr("Sort Demo")) self.cmdBubble.setText(self.__tr("Bubble")) self.cmdRipple.setText(self.__tr("Ripple")) self.cmdShell.setText(self.__tr("Shell")) self.txtCopyright.setText(self.__tr("Copyright 2004 GPL Peter")) def __tr(self,s,c = None): return qApp.translate("frmTest",s,c) --------------------------------------------------------- From newsgroups at jhrothjr.com Fri Aug 6 08:37:02 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 6 Aug 2004 08:37:02 -0400 Subject: Proposed improved decorator syntax References: <1091753696.4112d6e06ea9e@webmail.oregonstate.edu><1091564446.20040805213345@MailBlocks.com> Message-ID: <10h6ur4dp6ldu5b@news.supernews.com> "Bruce Eckel" wrote in message news:mailman.1248.1091763229.5135.python-list at python.org... > > Thursday, August 5, 2004, 6:54:56 PM, barnesc at engr.orst.edu wrote: > > > Recognize that we're *really* trying to create function metadata. A more > > flexible solution is to make a metadata dictionary be part of function and > > class definitions. Then 'decorator' simply becomes one name among many > > different metadata names. > > I have to say I find this argument compelling. I can't say whether the > syntax works well, but if the fundamental problem is metadata, then > solving that in a way that solves all aspects of metadata is > desireable. The trouble is that the original issue was not metadata. It was that a lot of people found the 'classmethod' and 'staticmethod' built-in functions both ugly and too easy to overlook. These functions (together with the 'property' built-in) in fact create new objects (descriptors) and return them; the original object becomes an attribute of the new object. In other words, it's somewhat similar to the decorator design pattern, hence the name. In these cases, it's not a matter of metadata. I suppose one could implement class and static methods in terms of metadata, but this would add another dictionary lookup to an already barouque function/method call process. One can also use this facility to insert metadata into the function object, but again it's simply syntax sugar for an already existing capability. > That said, I observe that this seems to be a fairly new topic for > many, including myself; I have some grasp of Java's metadata facility > and less of C#'s (although I understand C#'s to be more limiting than > Java's) and I have not read anything terribly in-depth about either. > It reminds me of my first exposure to C++ templates many years ago -- > it seemed like there was a lot more to it than meets the eye, but it > took me years to really start to grasp what it was about (by > understanding latent typing via python). There's actually a lot less to metadata than meets the eye. The basic fact about metadata is that it's data about the program that makes sense to outside tools that are processing the program. It may also make sense to routines within the program that deal with other parts of the program on a meta level - the typical user of the language's reflection facility. In other words, you have to know the tool a particular piece of metadata is directed toward in order to know what it means. On the other hand, there is a lot to creating a really useful metadata facility. I may want metadata for more than one tool in the same program, and I may also want metadata that is more structured than a simple key:value pair. I'm not all that familiar with the metadata facilities in either Java or C#, so I may be wrong by saying that the designers copped out of dealing with these issues. You can see the same issue in Python programs when you have various tools squabbling over who owns the docstrings. > One thing that has come up in Java is that metadata has been suggested > for use in implementing a version of aspect-oriented programming, > another feature I've been struggling to understand. The one thing > about aspects that has occurred to me is that macros seem to be trying > to solve a similar problem (changing code behavior across the code > base), as do metaclasses. Same problem, very different approaches and > degrees of effectiveness. Things like the implementation of > 'synchronized' is more aspecty than it is metadata; it is implementing > behavior changes rather than just attaching information to something > (the original intent of metadata; in Java you must generally write > additional code in order to add behavior based on a metadata tag). When someone wants a facility badly enough, there is a tendency to abuse other facilities to get it. This is why people seem to see "metadata" in the decorator proposal, and it's also why people seem to want to abuse anything in sight to get AOP functionality. > I suppose the question, then, is this: what is the true intent of > decorators? Is it for code behavior change, or metadata, or both? If > it is for code behavior change, how do I hook into that with my own > code; if I wanted to implement, for example, logging upon entry and > exit of a method (the classic AOP example) or to begin and end a > transaction upon entry and exit of a method? As I said above, the original intent was to provide syntax for the existing classmethod and staticmethod built-in functions. In other words it's a behavior change. There are a number of AOP packages out there. They're all based on descriptors, at least as far as I know. It would certainly be possible to re-implement them in terms of this syntax proposal, but it brings no new functionality to the table - it's just syntax sugar. > For that matter, should we limit the syntax of decorators to always > being at the beginning of a method? True aspects allow you to put a > cutpoint at any point in a method; perhaps decorators shouldn't be > restricted (even if we choose not to implement these ideas right > away). It depends on what you mean by a decorator. If you're talking about the function that is invoked by the syntax, think in terms of the already existing classmethod, staticmethod and property built-in functions. They are usually invoked when the class is being created (during import time), and result in a descriptor being bound to the identifier rather than the original function. The original function becomes a property of the descriptor. The descriptor is not invoked at the beginning of a method. A descriptor is invoked instead of the original method (a consequence of the descriptor being the object bound to the identifier rather than the original method). It can then invoke the original method at any place in its process it finds suitable, including completely ignoring it (probably a programming error!) > These issues are tricky but they could be very powerful. And this > conversation is sounding an awfully lot like some of the language > design stuff that happened in the C++ committee. Some members decried > this, saying that the committee should only be codifying existing > features, but I think it was very necessary for these things to be > tried, even if they didn't always work out. It's a lot less tricky than it seems. > And I think we may be at a point where only experimentation will tell > us what works and where this thing needs to go. No one has enough > experience with it -- although some might argue that this is the > reason we shouldn't put it in at all, I think that it means we need to > try something out and iterate as we learn. Descriptors (which is what this is based on) have been around since release 2.2. All this proposal does is provide syntax for creating and installing descriptors. There is nothing in this proposal that could not be accomplished by invoking module level functions after the original method has been defined. It is purely syntax sugar, containing a large number of empty calories. > Bruce Eckel From http Fri Aug 27 04:38:06 2004 From: http (Paul Rubin) Date: 27 Aug 2004 01:38:06 -0700 Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> <1gj4fb5.607xsc51izh8N%aleaxit@yahoo.com> <7xllg25lkt.fsf@ruckus.brouhaha.com> <1gj4u3a.12ttba9fynd6uN%aleaxit@yahoo.com> <1gj5bp4.qhup8tldmvebN%aleaxit@yahoo.com> Message-ID: <7xk6vlgemp.fsf@ruckus.brouhaha.com> Antoon Pardon writes: > but having operators like '+=' which have a different kind of result > depending on whether you have a mutable or immutable object is IMO > not such a good design and I wonder what design principle inspired them. += was added to Python fairly recently (in 2.0, I think) and there was a lot of agonizing about whether to add it. It was one of those things like the ?: construction. On the one hand there was the abstract objection you raise. On the other hand there were lots of users frustrated at being unable to say v[f(x)] += 1 instead of having to call f twice or introduce a temp variable or something. Eventually, practicality beat purity. From fakeaddress at nowhere.org Wed Aug 11 04:21:22 2004 From: fakeaddress at nowhere.org (Bryan Olson) Date: Wed, 11 Aug 2004 08:21:22 GMT Subject: rsa implementation question In-Reply-To: References: <1092200894.4119a9beb1978@www-mail.usyd.edu.au> <200408110852.57937.heikowu@ceosg.de> Message-ID: <5GkSc.124$O72.121@newssvr14.news.prodigy.com> Ajay Brar asked: > i am using RSa for signing documents and hence decrypting and then > encrypting to verify? Unfortunately yes, that seems to be what pycrypto is doing. The method is now discredited. > what i was rather trying to get at was what if the plaintext is too > large? Always hash and pad, for any size message. I suggest the SHA-1, hash function, which is in the Python standard library as "sha". Next you need a padding scheme that formats the message into a block suitable for the RSA private key operation. The signing method of PKCS#1 version 1.5 is the most popular RSA signature scheme, and when the payload is a hash digest it has no known serious weaknesses. The function encode_block_from_message, below, will hash a given message, then build and return a EMSA-PKCS1-v1_5 "Encoded Message" (EM) from it. The returned EM is suitable for signing with the pycrypto RSA sign function. I agree with about half of Heiko Wundram's response. # sha1_header_tuple is the prefix of the DER encoding of a: # sequene(sequence(oid, NULL), octet_string) # where the octet string has length 20, and completes the encoding. # sha1_header_tuple = (0x30, 0x21, 0x30, 0x9, 0x6, 0x5, 0x2b, 0xe, 0x3, 0x2, 0x1a, 0x5, 0x0, 0x4, 0x14) sha1_header = ''.join(map(chr, sha1_header_tuple)) def sha1_hash_and_encode(message): return sha1_header + sha.new(message).digest() def encode_block_from_message(message, intended_length): """Algorithm EMSA_PKCS1-v1_5 from PKCS 1 version 2 intended_length should be one octet less that modulus length """ der_encoding = sha1_hash_and_encode(message) assert intended_length >= len(der_encoding) + 10 pad_string = chr(0xFF) * (intended_length - len(der_encoding) - 2) result = chr(1) + pad_string + chr(0) + der_encoding return result -- --Bryan From zanesdad at bellsouth.net Fri Aug 20 07:34:00 2004 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Fri, 20 Aug 2004 07:34:00 -0400 Subject: Is HTTPSConnection thread-safe? In-Reply-To: <027501c48680$950cb3b0$7f00a8c0@scl01.siliconcreation.com> References: <027501c48680$950cb3b0$7f00a8c0@scl01.siliconcreation.com> Message-ID: <4125E1A8.5090805@bellsouth.net> Joe Wong wrote: > Hi, > I have a small program using HTTPSConnection to issue a POST on the > server. When multiple threads of the same program is running, I got > the error: > Exception in thread Thread-3: > Traceback (most recent call last): > File "C:\PYTHON23\lib\threading.py", line 436, in __bootstrap > self.run() > File "C:\PYTHON23\lib\threading.py", line 416, in run > self.__target(*self.__args, **self.__kwargs) > File "mcstest.py", line 27, in thread_func > conn.request("POST", CGI_PATH, params, headers) > File "c:\python23\lib\httplib.py", line 718, in request > self._send_request(method, url, body, headers) > File "c:\python23\lib\httplib.py", line 739, in _send_request > self.endheaders() > File "c:\python23\lib\httplib.py", line 712, in endheaders > self._send_output() > File "c:\python23\lib\httplib.py", line 597, in _send_output > self.send(msg) > File "c:\python23\lib\httplib.py", line 564, in send > self.connect() > File "c:\python23\lib\httplib.py", line 985, in connect > ssl = socket.ssl(sock, self.key_file, self.cert_file) > File "C:\Python23\lib\socket.py", line 73, in ssl > return _realssl(sock, keyfile, certfile) > sslerror: SSL_CTX_new error > in random order. Is there any fix / patches for this? > Regards, > - Joe Are you passing the same HTTPSConnection object to a bunch of threads? With just a cursory glance at the httplib module, it doesn't look like it is thread safe (meaning I saw no thread imports, no references to locks, etc.). If, for some reason, you feel it necessary to pass the same HTTPSConnection object to multiple threads, you will probably want to write a thread-safe wrapper for HTTPSConnection. I can't think why you would want to pass the same conn object to multiple threads rather than creating a new one per thread - unless you want to have one and only one persistent connection among all threads (using keepalives, I guess). Jeremy -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sun Aug 1 20:19:02 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 1 Aug 2004 20:19:02 -0400 Subject: Strange timing data for list.pop() References: Message-ID: "Roy Smith" wrote in message news:roy-57B296.13170501082004 at reader1.panix.com... > In the recent "transforming a list into a string" thread, we've been > discussing the fact that list.pop() is O(1), but list.pop(0) is O(n). I > decided to do a little timing experiment. To be sure, I did verify > experimentally the expected result, but along the way, I came upon an > interesting artifact that I'm at a loss to explain. > > I used the following to generate some timing numbers for pop() on > various sized lists: > > import time > for power in range (20): > i = 2 ** power > list = [1] * i > t0 = time.time () > list.pop () > t1 = time.time () > t = t1 - t0 > print i, t > > I know wall clock time isn't a good way to time things, but it was a > first cut before I dove into the manual and found os.times(). The > interesting thing is the data that I got with the above code: > > 1 7.70092010498e-05 > 2 6.91413879395e-06 > 4 5.96046447754e-06 > 8 5.00679016113e-06 > 16 5.00679016113e-06 > 32 5.00679016113e-06 > 64 5.00679016113e-06 > 128 5.00679016113e-06 > 256 4.05311584473e-06 > 512 5.00679016113e-06 > 1024 5.00679016113e-06 > 2048 5.96046447754e-06 > 4096 9.05990600586e-06 > 8192 9.05990600586e-06 > 16384 9.05990600586e-06 > 32768 1.4066696167e-05 > 65536 2.31266021729e-05 > 131072 3.09944152832e-05 > 262144 3.60012054443e-05 > 524288 3.38554382324e-05 > > I plotted the data. http://www.panix.com/~roy/pop-times.png This appears to be a fitted spline or somesuch rather than the data itself. Also, the data should better be plotted against power rather than 2**power. Then you would see a flat region across half the plot. > > An interesting shaped curve! I haven't done any curve fitting, but by > eye it looks something like k - log (1/n). The data is quite > repeatable, too. Admitting that clock time is a silly thing to be > measuring here, anybody have any clue what might be causing this > behavior? cache effect when you exceed 2**10? Terry J. Reedy From ramen at lackingtalent.com Tue Aug 17 20:40:06 2004 From: ramen at lackingtalent.com (Dave Benjamin) Date: Wed, 18 Aug 2004 00:40:06 -0000 Subject: Flython? References: <65adnQvUKIK_C7_cRVn-jQ@powergate.ca> Message-ID: In article <65adnQvUKIK_C7_cRVn-jQ at powergate.ca>, Peter Hansen wrote: > Sandy Norton wrote: > >> Peter Hansen wrote: >>>In the vein of Jython, I wonder what it would take to build >>>a Flython? (Lousy name, I know.) That would take Python >>>source, presumably a subset since some things couldn't be supported, >>>and compile it into ActionScript bytecode (aka the bytecode compiled >>>from ECMAScript source for the Macromedia Flash player environment). >> >> Have you looked at http://ming.sourceforge.net/ > > Briefly, but I'm not fully qualified to judge. I wrote this > in another post that you might not yet have seen: > > """Ming appears to be in an extremely early form, and there are > suggestions it's not very stable yet (and I think that word was used > in the sense of "unreliable", not just "changing"). > > The script support appears to be "C-like, with a very limited > feature set". Doesn't even allow function calls?! That > can't be good. > """ This was roughly my reaction as well. It seems like the project kind of stalled, and its support for ActionScript is very minimal. But it's a neat library for simple stuff, like rendering (non-interactive) vector graphics, and turning images into SWFs (which used to be necessary before Flash 6 added support for dynamic loading of JPEGs). I've actually used it from mod_python for this purpose before. -- .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:. "talking about music is like dancing about architecture." From fumanchu at amor.org Thu Aug 5 19:57:58 2004 From: fumanchu at amor.org (Robert Brewer) Date: Thu, 5 Aug 2004 16:57:58 -0700 Subject: how to force a list to be local? Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022DE4@exchange.hqamor.amorhq.net> Mark Harrison wrote: > In the following code, t1 does not modify b, while t2 seems to > modify b. What do I need to do in order to make b local in t2 > so that b.remove() does not modify the passed in list? > > def t1(a,b): > b = [] > > def t2(a,b): > b.remove(4) Short answer: make a copy of the list. def t2(a, b): b = b[:] b.remove(4) Robert Brewer MIS Amor Ministries fumanchu at amor.org From jzgoda at gazeta.usun.pl Sat Aug 7 17:19:05 2004 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Sat, 7 Aug 2004 21:19:05 +0000 (UTC) Subject: Going the PL/1 way References: Message-ID: Hans Nowak pisze: >> You want to say "if you want any improvement, do it yourself"? Sure, >> it's much better than Java's JCP, but expect >> http://catb.org/~esr/jargon/html/F/fork.html if enough people will share >> the same annoyance and anger. > > I may hem and haw whenever a new feature is added that I consider redundant (as > everybody reading my weblog knows well :-), but I would never support a fork. It is first time I felt it's "we and them" world, divided into "Python developers" and "Python users". They want features. We want stability and performance. I would rather use Ruby, than support a Python's fork. Moreover, I don't think the fork would ever happen. -- Jarek Zgoda http://jpa.berlios.de/ From michael_mccracken at mac.com Wed Aug 4 12:51:16 2004 From: michael_mccracken at mac.com (Michael McCracken) Date: 4 Aug 2004 09:51:16 -0700 Subject: help: Unit test fixture returning the same object References: <9895e897.0408031533.26720ba0@posting.google.com> Message-ID: <9895e897.0408040851.21ac7caa@posting.google.com> Peter Hansen wrote in message news:... > Michael McCracken wrote: > > > The problem is that in each test case, setUp and tearDown are called > > as expected according to the print statements, but they don't seem to > > have any effect after the first invocation. self.testfile is always > > the same instance as reported by id(). > > What Roy said... but to prove it to yourself, if you need to, > just implement a little class-variable-based counter in the > File __init__ method to show that you are getting different > objects each time. (That is, increment a global counter > each time you go through __init__, and store the current > count in the instance, to be retrieved and shown when you > are printing the ids() for the objects.) > > -Peter Thanks for the responses! I think I'm getting pretty close to the solution, but I'd appreciate some more help. So, I'm still surprised that id() would point to the same object every time, but I'm willing to believe it. However, I don't think that's the only thing that's going on - the reason I noticed this in the first place is that the setUp method was opening a file and populating some lists in my File object, and those lists were accumulating objects between test methods. The first test sees the File as it expects, while the second one sees a File with list member variables that have twice as many of each object it reads in, and so forth. That's why I was willing to believe that the same id() wasn't a fluke. I did try the global count idea, and I did get an increasing count, despite the same id oddity. So new instances seem to be getting created, with the same data structures. I don't think I'm accidentally using class variables, and that is the only thing I can think of. Any more tips? Thanks, -mike From rhaper at houston.rr.com Wed Aug 18 23:21:14 2004 From: rhaper at houston.rr.com (Rod Haper) Date: Thu, 19 Aug 2004 03:21:14 GMT Subject: age of Python programmers In-Reply-To: References: Message-ID: Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... Just turned 57 here and still coding strong although I've started to think of birthdays not in terms of a count up but rather as a count down towards retirement and freedom. I started programming back in 1966 on a Burroughs B5500 using ALGOL 60. A truly wonderful machine and programming language - far ahead of their time. I've always considered myself lucky to have started with a block structured language like ALGOL because of the good programming habits it engendered. I've worked with a lot of machines, languages, code and applications since those heady young days but for shear productivity nothing beats Python ... and besides it's just plain fun to use. I've been using Python for over eight years now. -- Rod From grante at visi.com Sun Aug 15 20:25:26 2004 From: grante at visi.com (Grant Edwards) Date: 16 Aug 2004 00:25:26 GMT Subject: Python secure? References: Message-ID: <411ffef6$0$65603$a1866201@newsreader.visi.com> On 2004-08-15, Roger Binns wrote: > Calvin wrote: >> Sorry I should have said I'm new to programming let alone Python. I >> wish to know whether Python is secure as an exe for a commercial >> product. > > Yes. Anyone who recovers your "code" and/or uses it will be in > violation of copyright I don't see how decompiling is a copyright violation. If I buy a copy of a book, I'm pretty sure I can translate it into another language if I want to form my own use. Unless the license under which use of the program was granted forbade de-compiling and reverse-engineering, I don't see why decompiling is illegal. In some places (Europe?) reverse-engineering is explicitly allowed by law. > and several other laws. What other laws? > That is legal protection no matter what languages or > combination of languages you use. -- Grant Edwards grante Yow! A GRAM?? A BRAM... A at GROOM... A BROOM... Oh, visi.com Yeh!! Wash the ROOM!! From michaels at rd.bbc.co.uk Wed Aug 11 12:18:47 2004 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Wed, 11 Aug 2004 17:18:47 +0100 Subject: A decorator syntax not yet mentioned (I think!) References: Message-ID: Peter Hansen wrote: > class Klass: > # init set > > decorate: > staticmethod > def meth0(x): > return x If it counts for anything, +1. This strikes me personally as a very nice alternative to the current suggestion. The idea of paired keywords is sufficiently common in python to strike me as another positive element. Using the examples on http://www.python.org/moin/PythonDecorators You gain something like: class C(object): decorate: staticmethod, funcattrs(grammar="'@' dotted_name [ '(' [arglist] ')' ]", status="experimental", author="BDFL") def longMethodNameForEffect(longArgumentOne=None, longArgumentTwo=42): """This method blah, blah. It supports the following arguments: - longArgumentOne -- a string giving ... - longArgumentTwo -- a number giving ... blah, blah. """ raise NotYetImplemented And: decorate: accepts(int,int) returns(float) def bar(low,high): pass Which strikes me as pretty good - the fact the method is a static method is still in your face. The decorate keyword suggests some voodoo happening you might want to be wary of. The only downside I can see is that it might not be 100% obvious that it relates to the following function to newcomers to python. The other really nice thing about it is it directly suggests that the following functions will be applied to the function. Taking a subset of a simple PLY type grammar from, you gain something like: class Calc(Parser): decorate: tokenrule(r'\d+') def t_NUMBER(self, t): t.value = int(t.value) return t decorate: tokenrule(r'\n+') def t_newline(self, t): t.lineno += t.value.count("\n") decorate: grammarrule('statement : NAME EQUALS expression') versioninfo("Added in 2.2") typeinfo(int) def p_statement_assign(self, p): names[p[1]] = p[3] decorate: grammarrule('statement : expression') versioninfo("Added in 2.4") deprecated typeinfo(None) def p_statement_expr(self, p): print p[1] decorate: grammarrule(""" expression : expression PLUS expression | expression MINUS expression | expression TIMES expression | expression DIVIDE expression | expression EXP expression """) versioninfo("Added in 2.4") typeinfo(int) def p_expression_binop(self, p): p[0] = func[p[2]](p[1],p[3]) decorate: grammarrule('expression : MINUS expression %prec UMINUS') versioninfo("Added in 1.5") typeinfo(int) def p_expression_uminus(self, p): p[0] = -p[2] decorate: grammarrule('expression : LPAREN expression RPAREN') versioninfo("Added in 1.1") typeinfo(int) def p_expression_group(self, p): p[0] = p[2] In a syntax highlighted editor that also looks *alot* cleaner than beforehand. IMO, it also looks slightly cleaner than the @version - for one very, very simple reason - if you have a very big decorator block, for whatever reason, the "def" stands out clearly so you can skim where the function starts - even without syntax highlighting. My initial reaction to @decorators was "ugh!". However I was coming to accept it as inevitable after reading the various arguments for/against various syntaxes. *This* syntax strikes me personally as having distinct advantages - largely for clarity of code, and solves the "where *DOES* the function start?" question with large decorator blocks. My tuppenceworth... (I really like this version) Michael. -- Michael.Sparks at rd.bbc.co.uk British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From aahz at pythoncraft.com Fri Aug 27 12:55:19 2004 From: aahz at pythoncraft.com (Aahz) Date: 27 Aug 2004 12:55:19 -0400 Subject: Call for signatories for J2 References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> Message-ID: In article <1gj4gzn.13gkzk49zvup2N%aleaxit at yahoo.com>, Alex Martelli wrote: >Robert Brewer wrote: >> >> This is a call for all who wish to sign the proposal, either for, >> against, or abstaining. Please sign by either posting on >> comp.lang.python (replying to this is fine), or sending email to > >For. > >I wish we'd use a better keyword than 'using' which would have a >bazillion other possible and useful future interpretations. Of the >possible keywords mentioned on the site, several (by, per, through, via) >appear better to me, and I'd particularly love the three-letter ones as >they'd align well with 'def' -- my own preference would be 'per'. -1 on ``per`` -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From z at b.com Fri Aug 27 14:07:40 2004 From: z at b.com (JZ) Date: Fri, 27 Aug 2004 20:07:40 +0200 Subject: Mysql in Python? References: <1a0o0u8an8yhn$.1aby5k5hmj67d.dlg@40tude.net> <7xsma9gfpr.fsf@ruckus.brouhaha.com> Message-ID: <1m51c42tp8am.3d5eas08z7bx$.dlg@40tude.net> Dnia 27 Aug 2004 01:14:40 -0700, Paul Rubin napisa?(a): >> There is no PHP standard templating system. PHP itself is a template >> framework! > > I'm not sure what the distinction is supposed to be? >From the beginning PHP was invented to be a template language (similar like today Smarty is a "template language" for today's php) First PHP was no object language at all. It's history was adding more and more functions, sessions, first poor object features etc, etc. -- JZ From christian at mvonessen.de Wed Aug 18 15:27:11 2004 From: christian at mvonessen.de (Christian von Essen) Date: Wed, 18 Aug 2004 21:27:11 +0200 Subject: age of Python programmers References: Message-ID: I'm 18 years old From jepler at unpythonic.net Fri Aug 20 08:15:30 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Fri, 20 Aug 2004 07:15:30 -0500 Subject: Tkinter In-Reply-To: <8e16829.0408190703.1c6845d7@posting.google.com> References: <8e16829.0408190703.1c6845d7@posting.google.com> Message-ID: <20040820121530.GA2252@unpythonic.net> You must install the RPM package "tkinter-2.2.2" Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From noone at here.com Sun Aug 15 19:31:15 2004 From: noone at here.com (M. Clift) Date: Mon, 16 Aug 2004 00:31:15 +0100 Subject: random / lists References: Message-ID: Hi Wes, Thanks for responding. What I want is a system that controls the direction in a generated list. If the user selects a number a letter is choosen for each number from at random from an array. That's fine and easy to do. The hard part is, is that no letter can be repeated with only one letter interveining and the letters can only follow each other under certain rules. These being : 1. 'a' can be followed by any letter 2. 'b' can only be followed by 'c' 3. 'c' can be followed by 'a' or 'd' 4 'd' can be followed by 'a' or 'c' Really it doesn't matter what these rules are for the time being it's just working out a way to control the outcome of a list of unknown size. I've experimented with lists of say up to 10 long using ' if ' statements for each number and different array depending upon the previous letter, but as you can imagine it is no good for larger lists as the code just goes on and on : ). Rather than I have done before, whereby I said if letter 3 == 'a' then letter 4 = choice(bcd) is it possible to say if previous letter equals whatever then this letter equals whatever? Wes, if you recieved an email direct to you address I'm sorry. I must be tierd, as for some reaon I've been hitting the reply button all night instead of the reply to group! Thanks From pythonista at sbcglobal.net Sun Aug 29 22:58:53 2004 From: pythonista at sbcglobal.net (Brian Almond) Date: 29 Aug 2004 19:58:53 -0700 Subject: Announcing PyCs, a new Python-like language on .Net References: <413170A2.1F1D1212@alcyone.com> Message-ID: <411e4639.0408291858.741eb8d8@posting.google.com> Erik Max Francis wrote in message news:<413170A2.1F1D1212 at alcyone.com>... > Mark Hahn wrote: > > > This is an announcement of the beginning of development of a new > > Python-like language called PyCs (pronounced "pie-cees"). Like > > IronPython, > > PyCs will be Python on .Net but it will have more advanced features > > and > > probably have higher performance due to a Psyco-like implementation > > technique. See http://pycs.org. > > Here we go again ... Is it time for an "intervention" yet? :) Still, I'm curious to see where this goes, although I hope this project doesn't generate a large amount of OT threads on c.l.py. From hanhwe_kim at yahoo.com Wed Aug 11 17:56:52 2004 From: hanhwe_kim at yahoo.com (Han Kim) Date: 11 Aug 2004 14:56:52 -0700 Subject: recommendations for CVS hosting service Message-ID: <64d85d64.0408111356.13959326@posting.google.com> Hello, I am looking for a commercial CVS hosting service for a mid-size software development project involving about 7 developers. A commercial service similar to the CVS service that sourceforge.net provides for open source code would be nice. On the web I have found: cornerhost.com/versionhost.com cvsdude.org csoft.net sourcehosting.com bug-track.com I also learned that pragmapool.com provides a Subversion hosting service. Has anyone had any good (or bad) experiences with any of these services? TIA, Han From DeepBleu at DeepBleu.org Fri Aug 27 23:22:48 2004 From: DeepBleu at DeepBleu.org (DeepBleu) Date: Sat, 28 Aug 2004 03:22:48 GMT Subject: Iteration over Lists and Strings Message-ID: I noticed the following: >>a = 'abba' >>for n in a: >> print n, a.index(n) a 0 b 1 b 1 a 0 (expected result: a 0 b 1 b 2 a 3) The same with lists: >>List = [1, 0 , 1] >>for n in List: >> print n, List.index(n) 1 0 0 1 1 0 (expected result: 1 0 0 1 1 2) What is going on? Can someone clarify this to me? And how can I ensure that the iteration produces the absolute index number **without** doing something like: >>a = 'abba' >>k = len(a) >>for m in range(0, k): >> print a[m], m a 0 b 1 b 2 a 3 Thanks - From bart_nessux at hotmail.com Fri Aug 13 07:59:58 2004 From: bart_nessux at hotmail.com (Bart Nessux) Date: Fri, 13 Aug 2004 07:59:58 -0400 Subject: Print Special Symbols in Tk GUI In-Reply-To: References: Message-ID: vincent wehren wrote: > "Bart Nessux" schrieb im Newsbeitrag > news:cfh9pr$fnb$1 at solaris.cc.vt.edu... > >>Using tkinter to create a Python version of Microsoft's winver. Works >>great... how can I print the copyright symbol (c) and the registered (R) >>symbol into the GUI? > > > Consider using unicode(\u) or unicode name (\n{name goes here} escapes: > > import tkMessageBox > import Tkinter > root = Tkinter.Tk() > root.withdraw() > copyright_symbol = u"\u00A9" > # or use: copyright_symbol = u"\N{COPYRIGHT SIGN}" > registered_symbol = u"\u00AE" > # or use: registered_symbol = u"\N{REGISTERED SIGN}" > msg = u"Copyright: %s, Registered: %s" % (copyright_symbol, > registered_symbol) > tkMessageBox.showinfo("Info", msg) > #root.mainloop() > > Regards, > -- > > Vincent Wehren Thanks Vincent... that works great. From ptmcg at austin.rr._bogus_.com Wed Aug 18 18:17:07 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Wed, 18 Aug 2004 22:17:07 GMT Subject: multi-instance and classic singleton design patterns References: Message-ID: "Neil Zanella" wrote in message news:b68d2f19.0408181354.43821bd9 at posting.google.com... > Hello, > > I would be very interested in knowing how the following C++ multi-instance > singleton (AKA Borg) design pattern based code snippet can be neatly coded > in Python. While there may be somewhat unusual places where multi-instance > singleton is more useful than plain singleton, it seems to me that the > former leads to less coding, so unless I can somehow package the > singleton pattern in a superclass (so I don't have to code it > explicityly in every singleton class I have), then I am more > interested in the multi-instance singleton design pattern. > > Thanks, > > Neil Neil - You may be new to the Python community, given that you are porting a C++ pattern to Python. There is a terrific resource for snippets of this kind in the Python Cookbook, to be found at http://aspn.activestate.com/ASPN/Cookbook/Python/ . You should find a *very* neat implementation of this pattern at the bottom of http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531 . -- Paul (You can also try googling for "python singleton borg" to find this and many other helpful suggestions and comments.) From mark_bottjer at hotmail.com Wed Aug 11 14:22:46 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Wed, 11 Aug 2004 14:22:46 -0400 Subject: Python equivalent to a C trick In-Reply-To: <1d7b6d0d.0408092255.1177908e@posting.google.com> References: <1d7b6d0d.0408092255.1177908e@posting.google.com> Message-ID: <411a63f6$1@nntp.zianet.com> Dan wrote: > Is there a python equivalent of this trick in C? > > Logic_Test ? True_Result : False_Result There's something close: Logic_Test and True_Result or False_Result print 'you have %i egg%s' % (num_eggs, (num_eggs != 1) and 's' or '') The main problem with this is that False_Result will get executed if Logic_Test is false *or* True_Result evaluates to false. Witness the following broken variation of the above: print 'you have %i egg%s' % (num_eggs, (num_eggs == 1) and '' or 's') So it's not perfect, but it is workable. And as a previous post indicated, this situation is not likely to change. :) -- Mark From ivoras at __-geri.cc.fer.hr Tue Aug 24 17:43:48 2004 From: ivoras at __-geri.cc.fer.hr (Ivan Voras) Date: Tue, 24 Aug 2004 23:43:48 +0200 Subject: Python SOAP? In-Reply-To: References: Message-ID: Nelson Minar wrote: > > There are two active SOAP projects I'm aware of - ZSI and SOAPpy. They > share a home: > http://pywebsvcs.sourceforge.net/ > I don't know if the specific HTTP cookie persistence you're asking for > has been implemented in either. For what it's worth, I wouldn't count Yes, those are the libraries that I described in my post - and are sadly lacking. :( > on that approach working reliably in many SOAP implementations. While it's not standard and could be considered 'dirty', I found many libraries support it. (Axis does, some c++ libraries I found do also, and I "heard" that's the way .NET services work also). From bokr at oz.net Thu Aug 5 17:13:50 2004 From: bokr at oz.net (Bengt Richter) Date: 5 Aug 2004 21:13:50 GMT Subject: Confused about pep 318 References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: On Wed, 4 Aug 2004 15:42:19 -0500, "Edward K. Ream" wrote: >Hello all, [... snip admirably restrained post ..] I too am very much against wasting '@' on @decorator! Please see my post in the "tweaking @decorator syntax" thread for a possible alternative that might also have some interesting room for inventive use. Regards, Bengt Richter From russblau at hotmail.com Thu Aug 5 17:37:12 2004 From: russblau at hotmail.com (Russell Blau) Date: Thu, 5 Aug 2004 17:37:12 -0400 Subject: import random error References: <7903bb89.0408051324.63ee1535@posting.google.com> Message-ID: <2nfnk9FcdrrU1@uni-berlin.de> "Rob B" wrote in message news:7903bb89.0408051324.63ee1535 at posting.google.com... > I am just starting to learn Python and was writing a simple script on > my machine (Mac OS X 10.3.4), but I can't seem to import the random > module: > > #!/usr/bin/env python > > import random > > Results in: > > Traceback (most recent call last): > File "./math.py", line 3, in ? > import random > File "/sw/lib/python2.3/random.py", line 42, in ? > from math import log as _log, exp as _exp, pi as _pi, e as _e > ImportError: cannot import name log > > I have such a feeling that this is either a) because I don't know what > I'm doing or b) the python install is somehow strange. What is strange > is that in interactive mode, import random works fine. Neither (a) nor (b). It is c) you have named your program "math.py" but "math" happens also to be the name of a module in the standard Python library, and the "random" module needs access to the "math" module. But when it searches the Python path for a module named "math" it comes upon your file first. Simple solution: call your program something else! (and make sure you delete math.py? from your working directory). -- I don't actually read my hotmail account, but you can replace hotmail with excite if you really want to reach me. From olli at haluter.fromme.com Thu Aug 19 07:32:46 2004 From: olli at haluter.fromme.com (Oliver Fromme) Date: 19 Aug 2004 11:32:46 GMT Subject: age of Python programmers References: Message-ID: <2ojheuFb9j2eU1@uni-berlin.de> Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... I'm 00100001b (or 021h ... or if you prefer decimal, it's 33 years). Although I feel more like 27, which is the age of my GF. :-) First learned to program in BASIC on an old Wang computer (with magnetic ring core memory, no "modern" RAM chips) and on a Commodore PET2001. I was 12 back then, I think. Then went through various other languages (including assembly on 65xx, 68xxx and x86), and I think that all of them suck, especially Perl and Java. As a matter of fact, I also think that Python sucks, but it sucks a lot less than all the others. Regards Oliver -- Oliver Fromme, Konrad-Celtis-Str. 72, 81369 Munich, Germany ``All that we see or seem is just a dream within a dream.'' (E. A. Poe) From jeff at ccvcorp.com Thu Aug 26 16:09:32 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Thu, 26 Aug 2004 13:09:32 -0700 Subject: Larry Wall & Cults In-Reply-To: References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: <10isgqrfbmnc26b@corp.supernews.com> Rich Teer wrote: >On Thu, 26 Aug 2004, Tor Iver Wilhelmsen wrote: > > > >>Rich Teer writes: >> >> >> >>>I think you're getting confused with the Blue ?yster Cult. >>> >>> >>Actually, there is also The Cult, a British band that lasted from >>1984-1995. >> >> > >I belive the Cult (She Sells Sanctuary, etc.) is another manfifestation >of the Blue ?yster Cult. > > No, the two are totally unrelated. (One was American (New York) and led by Eric Bloom, the other was British (London) and led by Ian Astbury.) However, The Cult did have an earlier incarnation as Southern Death Cult. Jeff Shannon Technician/Programmer Credit International From aahz at pythoncraft.com Fri Aug 20 20:29:08 2004 From: aahz at pythoncraft.com (Aahz) Date: 20 Aug 2004 20:29:08 -0400 Subject: decorator J4 - any objections? References: <7o3di0pt7o7e6cu3q3cbkls3g5asnn9n3u@4ax.com> <7x4qmx735u.fsf@ruckus.brouhaha.com> Message-ID: In article <7x4qmx735u.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: >Christos "TZOTZIOY" Georgiou writes: >> >> Why type decorators as a dictionary if you are not going to produce a >> dictionary? Cause if you produce a dictionary, the order of the >> decorators is no longer guaranteed. > >Does that matter? Yes. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From jepler at unpythonic.net Mon Aug 23 10:31:18 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Mon, 23 Aug 2004 09:31:18 -0500 Subject: [Tkinter-discuss] Please help -- Tkinter Scale widget with DoubleVar is acting weird In-Reply-To: <4124C828.5080106@noaa.gov> References: <4124C828.5080106@noaa.gov> Message-ID: <20040823143117.GF7899@unpythonic.net> I looked into this some more, and was able to reproduce the problem using tcl-8.3.5-88 redhat-release-9-3 I was then also able to demonstrate it on tcl/tk 8.5. I used this wish script: scale .s -variable v -resolution 0.1 -from 0 -to 1 trace variable v w changed proc changed {args} { global v; puts "v changed. new value: $v" } pack .s I set the scale value to 0.7. Now, by moving the cursor *between the slider and the trough*, I get the repeated message "v changed. new value: 0.7". (It's the movement between slider and trough, not just hovering, that made the redundant sets happen for me) This behavior doesn't seem to depend on the value of tcl_precision. It *looks* like the problem is in TkRoundToResolution(). It returns a slightly different value than the incoming value, so that the test "scalePtr->value == value" in tkUnixScale:TkpSetScaleValue() fails and it falls through to a Tcl_SetVar call. This is low-level stuff inside of tk. Like Fredrik suggested, your next step is to go to the tcl/tk community with your report, if it's important to you. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From mwh at python.net Wed Aug 11 11:39:51 2004 From: mwh at python.net (Michael Hudson) Date: Wed, 11 Aug 2004 15:39:51 GMT Subject: How to get rid of "hex/oct constants > sys.maxint" warning? References: <411a3402$0$65564$a1866201@newsreader.visi.com> Message-ID: Grant Edwards writes: > I'm getting tired of seeing meaningless warnings from my code, > but I can't figure out how to get rid of them: > > For example: > > fcntl.ioctl(fd,0xc0047a80,s) causes > > FutureWarning: hex/oct constants > sys.maxint will return > positive values in Python 2.4 and up > > Firstly, I have no idea what that error means in this context. > 0xc0047a80 isn't intended to be an integer (either positive or > negative): it's just a chunk of 32 bits. > > Googling the newsgroup came up with the suggestion that putting > an "L" on the end of the constant would eliminate the warning, > but it causes an error: > > fcntl.ioctl(fd,0xc0047a80L,s) causes > > OverflowError: long int too large to convert to int > > So, that doesn't work. > > How _do_ I get rid of the warning? Is there a way to tell > Python that the constant isn't an integer, it's just a bit > pattern? It's horrible, but ~int(~0xc0047a80L&0xFFFFFFFFL) will work. Cheers, mwh -- I love the way Microsoft follows standards. In much the same manner that fish follow migrating caribou. -- Paul Tomblin -- http://home.xnet.com/~raven/Sysadmin/ASR.Quotes.html From bokr at oz.net Sat Aug 21 18:15:25 2004 From: bokr at oz.net (Bengt Richter) Date: 21 Aug 2004 22:15:25 GMT Subject: My only complaint about Python References: Message-ID: On Fri, 20 Aug 2004 15:19:01 -0400, Tim Peters wrote: >[Darren Dale] >... >>>> Will the BDFL ever split with Visual Studio? > >[Tim Peters] >>> We should be clear here that this isn't Guido's decision. What you >>> get on Windows is what you get on all other platforms in this respect: >>> you get what volunteers show up to produce, year after year after >>> year. So you get a fine Cygwin port from Jason Tishler, seemingly >>> toiling all alone, and you get contributions from at least four >>> developers who do use Visual Studio. > >[Darren] >> I meant no disrespect to the developers. > >Didn't think you did. I'm just saying (a) the BDFL is irrelevant to >this particular issue; and, (b) you get what other people give. If >nobody with a long-term commitment to a specific Visual Studio >alternative appears, then #b rules. > >> ... >> This comes back to the heart of the matter. How do you get volunteers >> who dont have access to VS to get involved with Python development? > >Very few Python contributors have access to VS, but it doesn't matter >since most aren't running on Windows either. Even on Windows, VS is >usually irrelevant to whether somene can pitch in on reviewing bugs >and patches, improving the standard libraries, improving the docs, >helping on the newsgroup and mailing lists, keeping python.org >healthy, etc. I think it's more of a cultural thing, that Windows >users typically have a lower contribution rate than users on other >platforms (whether it's C code or anything else). > >I mentioned Cygwin before, and you can certainly develop C extension >modules, for Python, on Windows, using that. Other responders have >their own favored VS alternatives. "A problem" is that there's more >than one VS alternative! That fragments the relatively-small-anyway >community of people who need a VS alternative on Windows. > >> I think the suggestions here were right on, give Python the ability to >> support MinGW out of the box. > >That's a wish. If it's to be granted, someone has to volunteer to do >the work initially, and keep it working as the years go by. Don't >expect that one of the current contributors will do so (they're >swamped already). IOW, it's not a matter of convincing someone it's a >good idea, it's a matter of someone volunteering to do actual, real >work. > >> I thought that a compiler could even be included in a version of the Windows >> distribution, but maybe that is taking it too far. > >That one won't happen -- most Windows Python users don't even know C, >and download size is still an issue for many. Even people who want to >work on core Python development on Windows using VS need to work from >a source tarball instead, or from a CVS checkout. Has anyone considered treating a current binary windows cpython distro like 2.3 as a bootstrap, using a python script to control (e.g. via os and urllib etc) all the downloading and md5/pgp-sig checking and building necessary to create an msys/MinGW installation (as needed if not present) and then a python built from sources purely using msys/MinGW, with end result being a python installation ready to be used in parallel, or to be switched to as default? It might take hours to download and crunch, and it might need to be re-startable and be based on an evolving checkpointable config file of preferences etc, but why not? If someone then wanted to make a script repackaging the result as a binary installation, that would be handy too, and IWT some official versions of everything would wind up on python.org after a while. IMO a python script that created the whole thing from sources (well, ok, not including bootstrapping msys/MingGW totally from sources ;-) would be a useful DOCUMENT as well as a tool. IOW, spreading bot-knowledge can distribute the knowledge necessary to distributing the volunteer workload of maintaining and improving the thing. I'm thinking simple text UI control as necessary. Such a migration bootstrap script seems to me like it would have more robust survival prospects than an equivalent-end-result prebuilt binary distro made ad hoc by hand and contributed. Seems like someone must have thought of this before. I guess pieces exist as .bat or .cmd files, but I'd like to see the whole thing wrapped in a single flexible python script. Regards, Bengt Richter From Andreas.Ames at tenovis.com Fri Aug 20 09:49:44 2004 From: Andreas.Ames at tenovis.com (Ames Andreas (MPA/DF)) Date: Fri, 20 Aug 2004 15:49:44 +0200 Subject: My only complaint about Python Message-ID: <788E231C269961418F38D3E360D1652526CA2F@tndefr-ws00021.tenovis.corp.lan> Hi, David Fraser wrote: > But its actually trying to do more than what he's asking. This patch > is to *cross*-compile python with mingw, compiling it with mingw > under windows should be easier. You're right, it has no native support for mingw/msys (mostly cause of the lack of a robust autoconf toolchain; at least I don't know of one). But it should enable you to crosscompile from cygwin to mingw with auto* support, so you at least don't need another os/machine or something. > There was an email to python-list saying it was possible here: > http://mail.python.org/pipermail/python-list/2004-June/225967.html I've missed hat one, thanks. cheers, andreas From indigo at bitglue.com Wed Aug 4 20:56:39 2004 From: indigo at bitglue.com (Phil Frost) Date: Wed, 04 Aug 2004 20:56:39 -0400 Subject: bsddb In-Reply-To: <41110FDB.9080307@mail.usyd.edu.au> References: <41110FDB.9080307@mail.usyd.edu.au> Message-ID: <411185C7.2020705@bitglue.com> I'm guessing, but _bsddb is probably in Modules, called something like "bsddbmodule". It's common for a module written in Python to have a helper module written in C with the same name prefixed by an underscore. Ajay Brar wrote: > hi! > > when i do an import bsddb, it tries do do an import _bsddb > i looked around Python23\Lib but couldn't find any _bsddp file....or > am i totally on the wrong track. > the reason i am asking is, i am trying to port a Python app to a > pocket pc and python release for pocket pc does not have bsddb module. > > thanks > > cheers From bryanjugglercryptographer at yahoo.com Mon Aug 23 16:39:37 2004 From: bryanjugglercryptographer at yahoo.com (Bryan Olson) Date: 23 Aug 2004 13:39:37 -0700 Subject: Python future performance and speed References: Message-ID: <1a517b5.0408231239.49f98487@posting.google.com> ellisjb at my-deja.com wrote: > I was goint to post that the myth of "python isn't fast enough" > has been pretty much dispelled in these enlightened times, but I > guess I was too optimistic. :) Python is like hundreds of other programming languages in that it has a community of believers that decries the ignorance of others and dispells the myths of their language's disadvantages, to the general satisfaction of said community. -- --Bryan From export at hope.cz Fri Aug 20 09:28:05 2004 From: export at hope.cz (Lad) Date: 20 Aug 2004 06:28:05 -0700 Subject: Py2Exe PROBLEM References: <81a41dd.0408190023.44d34c44@posting.google.com> <2tGdncgUvpKRD7ncRVn-oQ@powergate.ca> <81a41dd.0408191109.1fc98889@posting.google.com> Message-ID: <81a41dd.0408200528.16b4dbd2@posting.google.com> > > > > Dear Peter, > > Thank you for your help. > > Yes, I changed import rgs.py to import rgs but I still receive > > >>The following modules appear to be missing > > >>>['blackbox', 'timing', 'rgs.py'] > > > > > > When I try to start the exe file I get > > > > Traceback (most recent call last): > > File "rgs.pyc", line 561, in OnFileHistory > > > > File "pickle.pyc", line 1390, in load > > File "pickle.pyc", line 872, in load > > File "pickle.pyc", line 985, in load_string > > LookupError: unknown encoding: string-escape > > > > Can you please help again? > > Lad > > You need to add "encodings" to the list of packages that you manually > include (the option is called packages I think) - see the py2exe wiki > > David Thank you Peter and David for your time to help. Now the script starts but still it does not run as good as under Python. In fact it gets stuck( hangs) and I do not know exactly where.Is there a method how to find out where it hanged? In my program I import the following modules: from _winreg import * from wxPython.wx import * import locale,base64,urllib2,shutil,os.path,timeoutsocket,fnmatch,zipfile,thread,random,mimetools,threading,urllib,string,urlparse,httplib, re,os,webbrowser,time,strptime,glob,pickle,smtplib,nntplib,ConfigParser,sys Is there any known problem with any of those moduls running with Py2exe? I use PythonWin 2.3.4 (#53, May 25 2004) WxPython 2.4.1.2 Thanks Lad. From peter at engcorp.com Mon Aug 16 01:48:38 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 01:48:38 -0400 Subject: Python secure? In-Reply-To: <2xXTc.3775$bJ2.24876@news1.mts.net> References: <2xXTc.3775$bJ2.24876@news1.mts.net> Message-ID: Reid Nichol wrote: > Terry Reedy wrote: > >> ... compiled C can be terribly insecure relative to >> Python. C has dangerous functions like strcpy() which, if used with >> external input, can make a program subject to buffer overrun exploits >> that >> can do explosive damage. > > But this doesn't make C an insecure language. No language is either > secure nor insecure. It's what the programer does with it that matters. New definition for the purposes of this discussion: "secure language": a programming language which, by virtue of its structure, libraries, syntax, runtime, or other features supports and tends to encourage the creation of software which doesn't have gross security holes". Viz. "Python" "unsecure language": a programming language which, by virtue of its structure, primitive libraries, awkward syntax, non- existent runtime, or other limitations tends to encourage and lead to the creation of software with gross security holes". Viz. "C" A given programmer will be more likely to create safe and secure software using Python than with C, thereby making C the less secure... -Peter From ptmcg at austin.rr._bogus_.com Thu Aug 19 15:16:41 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Thu, 19 Aug 2004 19:16:41 GMT Subject: Alternative decorator syntax decision Message-ID: There are a number of messages on the python-dev mail list that indicate that Guido is looking for some concensus to come from this list as to what *one* alternative syntax for decorators we would like him to consider in place of the @ syntax that is currently in 2.4a2. I think special thanks are due to: - Anthony Baxter for his continuing efforts in this regard - Steven Bethard for some of the clearest thinking and writing on this topic - Michael Sparks for actually implementing one of the options We've all done our share of pitching and whining, but we need to settle on *one* option for Guido to consider. (And let's not get wrapped up complaining about the "process" being followed in this whole thing, personally I think it is quite poor. But let's play with the cards we've been dealt, and at least make a collective proposal.) The significant alternatives have been listed on the Python wiki at http://www.python.org/moin/PythonDecorators . Interested parties should also look at the comments in the python-dev archive for the past month, at http://mail.python.org/pipermail/python-dev/2004-August/thread.html . I would propose a multivote survey: each poster gets 3 votes among the lettered choices on the Wiki page above. You can use all 3 for a single option, or split them across 2 or 3 options if you are open to more than one. I am not going to argue that this is scientific in any respect, but it *should* allow the major 1 or 2 choices to bubble to the top. I have used this process at work many times in the past when it was necessary for a large group to set priorities among a large list of choices. My vote is: J2 J2 C1 By the way, once an option has been chosen, it *still* needs an implementation for Guido to accept it. This puts some of the options way ahead of the others, in my mind. (And let's hope we get at least as good a response as the "average age" thread!) -- Paul From http Thu Aug 19 22:19:39 2004 From: http (Paul Rubin) Date: 19 Aug 2004 19:19:39 -0700 Subject: Rita Sue and Bob too References: Message-ID: <7x7jruwnyc.fsf@ruckus.brouhaha.com> "M. Clift" writes: > But, how to I find a sequence in a list of unknown size? i.e. this sequence > in list of other names and replace it with three others? > > 'Rita','Sue','Bob' > > This is almost a nightly occurrence (my posting questions), but I am > learning : ) You have to scan through the list and look for that sequence, e.g. for i in xrange(len(mylist) - 2): if mylist[i:i+3] == ['Rita','Sue','Bob']: print 'They were found' break There are fancier and more efficient ways to scan the list, but this is the basic idea. From richie at entrian.com Fri Aug 20 06:20:33 2004 From: richie at entrian.com (Richie Hindle) Date: Fri, 20 Aug 2004 11:20:33 +0100 Subject: age of Python programmers In-Reply-To: References: <4124d4a4$1@nntp0.pdx.net> Message-ID: [Mark, quoting "Surely You're Joking, Mr. Feynman!"] > Well, Mr. Frankel, who started this program, began to suffer from the > computer disease that anybody who works with computers now knows > about. [...] the /delight/ in being able to see how much you can do. I wonder, what is the average level of infection with this disease among Python programmers relative to the rest of the programming world? Is there a test for it? Number of cool but unfinished projects? Is there a cure? Do we want one? -- Richie Hindle richie at entrian.com From sholden at holdenweb.com Mon Aug 30 20:09:41 2004 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 30 Aug 2004 20:09:41 -0400 Subject: how to change a factory use of rfc822.Message to mhlib.Message In-Reply-To: References: Message-ID: <4133C1C5.8010609@holdenweb.com> John Doe wrote: > I've never used a factory and would like to get some help. > The class > mailbox.UnixMailbox has a defination for a factory. > > __init__(self, fp, factory=) > > where fp is a file pointer. > > I don't want to use rfc822.Message. I'd like to use mhlib.Message instead. > > rfc822.Message requires: > __init__(self, fp, seekable=1) > > mhlib.Message requires: > __init__(self, f, n, fp=None) > > where f think the is a folder name. I've seen '.' used. > (The documentation is very unclear here). And 'n' is the seekable. > > How do I call mailbox.UnixMailbox( fp ... ) with mhlib.Message? You'll need to write a "wrapper" class or function around mhlib.Message to make it look sufficiently similar to rfc822.Message. Then you provide the wrapper as the factory argument when you create your UnixMailbox. Clearly the __init__() signature of whatever factory you provide has to match that of rfc822.Message otherwise you'll get an error when the mailbox code tries to create a message instance. regards Steve From amajorel at teezer.fr Sat Aug 28 10:55:37 2004 From: amajorel at teezer.fr (Andre Majorel) Date: Sat, 28 Aug 2004 14:55:37 +0000 (UTC) Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4PGdnfsOfdDPi63cRVn-tA@speakeasy.net> Message-ID: On 2004-08-28, Rob Warnock wrote: > Pascal Bourguignon wrote: > +--------------- >| $ telnet xahlee.org 80; >| Trying 208.186.130.4... >| Connected to xahlee.org. >| Escape character is '^]'. >| GET / HTTP/1.1 >| >| HTTP/1.1 400 Bad Request >| Date: Fri, 27 Aug 2004 01:35:52 GMT >| Server: Apache/2.0.50 (Fedora) >| ^^^^^^^^^^^^^^^^^^^^^^ > +--------------- > > So are you complaining about the fact that his hosting provider > preloaded RedHat Fedora with Apache 2.0 for him? There is no shortage of Windows-based hosting companies, so why didn't he go there ? Whatever your opinions, it's best to put your money where your mouth is if you expect to be taken seriously. -- Andr? Majorel "See daddy ? All the keys are in alphabetical order now." From ben at benlast.com Tue Aug 17 11:46:28 2004 From: ben at benlast.com (Ben Last) Date: Tue, 17 Aug 2004 16:46:28 +0100 Subject: Newbie question about file input In-Reply-To: Message-ID: split() delimits on sequences of whitespace characters, not just spaces, so: >>>"\n".split() [] >>>"".split() [] >>> ...both give the same result; an empty list. >From the documentation: split( s[, sep[, maxsplit]]) Return a list of the words of the string s. If the optional second argument sep is absent or None, the words are separated by arbitrary strings of whitespace characters (space, tab, newline, return, formfeed). If the second argument sep is present and not None, it specifies a string to be used as the word separator. The returned list will then have one more item than the number of non-overlapping occurrences of the separator in the string. The optional third argument maxsplit defaults to 0. If it is nonzero, at most maxsplit number of splits occur, and the remainder of the string is returned as the final element of the list (thus, the list will have at most maxsplit+1 elements). regards b > -----Original Message----- > From: python-list-bounces+ben=benlast.com at python.org > [mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of > Aaron Deskins > Sent: 17 August 2004 16:08 > To: python-list at python.org > Subject: Re: Newbie question about file input > > > Christopher T King wrote: > > > On Tue, 17 Aug 2004, Aaron Deskins wrote: > > > > > >> Also, what exactly is stored when a blank line is read by the > >>readline command? A zero, blank, or what??? > > > > > > readline() always includes the '\n' that terminates the line, so any > > 'blank' line that is read will be returned as a simply '\n'. The only > > time readline() won't return a line terminated with '\n' is if the last > > line of the file isn't terminated with '\n' (common on > Windows), in which > > context a blank line is meaningless. > > > So why does a linesplit fail after the program reads a blank line (or a > '\n')? Is this simply because there's no way to assign the variable '\n' ? > > -- > Aaron Deskins > Graduate Student > Chemical Engineering > Purdue University > -- > http://mail.python.org/mailman/listinfo/python-list From anthonybaxter at gmail.com Wed Aug 25 11:06:18 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Thu, 26 Aug 2004 01:06:18 +1000 Subject: Is it a bug (or a feature)? In-Reply-To: References: Message-ID: This looks like a bug. Please open a bug on SF, with the example code. From ptmcg at austin.rr._bogus_.com Wed Aug 11 13:01:09 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Wed, 11 Aug 2004 17:01:09 GMT Subject: A decorator syntax not yet mentioned (I think!) References: Message-ID: BTW, this syntax is currently listed on the Python MoinMoin as option J2. http://www.python.org/cgi-bin/moinmoin/PythonDecorators -- Paul From __peter__ at web.de Fri Aug 20 14:40:33 2004 From: __peter__ at web.de (Peter Otten) Date: Fri, 20 Aug 2004 20:40:33 +0200 Subject: classes are objects... so how can we custom print them: we need a classmethod syntax References: Message-ID: Neil Zanella wrote: > Hello, > > In Python, classes are objects. But there is no way to custom print a > class object. This would require some syntax such as the one commented out > below: With the current "foo = classmethod(foo)" mechanism custom printing > for class objects is not possible. > > #!/usr/bin/python > > class Foo: > def __str__(self): > return "foo" > #def classmethod __str__(cls): > # return "pythons bite" > > foo = Foo() > s = "hello %s!" % foo # custom text here > print s > > print Foo # no custom text here possible it seems, unless we call > # a staticmethod such as Foo.printMe() > > Regards, > > Neil Classes are objects. You have to define the __str__() method in the object's class - for a class that would be the metaclass. Now here: >>> class FooType(type): ... def __str__(self): ... return "custom text for class %s" % self.__name__ ... >>> class Foo: ... __metaclass__ = FooType ... def __str__(self): ... return "custom text for %s instance" % self.__class__.__name__ ... >>> print Foo() custom text for Foo instance >>> print Foo custom text for class Foo >>> Peter From tim.hochberg at ieee.org Wed Aug 25 20:57:27 2004 From: tim.hochberg at ieee.org (Tim Hochberg) Date: Wed, 25 Aug 2004 17:57:27 -0700 Subject: numarray speed question In-Reply-To: <144d0df.0408251616.5758d6e7@posting.google.com> References: <953AD3D0Didtoken@128.91.2.239> <953C4DD4idtoken@128.91.2.239> <144d0df.0408070828.338f8c19@posting.google.com> <9540516Didtoken@128.91.2.239> <144d0df.0408251616.5758d6e7@posting.google.com> Message-ID: grv575 wrote: > Is it true that python uses doubles for all it's internal floating > point arithmetic Yes. even if you're using something like numarray's > Complex32? No. Numarray is an extension module and can use whatever numeric types it feels like. Float32 for instance is an array of C floats (assuming floats are 32 bits on your box, which they almost certainly are). Is it possible to do single precision ffts in numarray or > no? I believe so, but I'm not sure off the top of my head. I recommend that you ask on numpy-discussion or peek at the implementation. It's possible that all FFTs are done double precision, but I don't think so. -tim > > cookedm+news at physics.mcmaster.ca (David M. Cooke) wrote in message news:... > >>At some point, grv575 at hotmail.com (grv) wrote: >> >> >>>cookedm+news at physics.mcmaster.ca (David M. Cooke) wrote in >>>: >>> >>> >>>>At some point, grv575 at hotmail.com (grv575) wrote: >> >> >> >>>>>Heh. Try timing the example I gave (a += 5) using byteswapped vs. >>>>>byteswap(). It's fairly fast to do the byteswap. If you go the >>>>>interpretation way (byteswapped) then all subsequent array operations >>>>>are at least an order of magnitude slower (5 million elements test >>>>>example). >>>> >>>>You mean something like >>>>a = arange(0, 5000000, type=Float64).byteswapped() >>>>a += 5 >>>> >>>>vs. >>>>a = arange(0, 5000000, type=Float64) >>>>a.byteswap() >>>>a += 5 >>>> >>>>? I get the same time for the a+=5 in each case -- and it's only twice >>>>as slow as operating on a non-byteswapped version. Note that numarray >>>>calls the ufunc add routine with non-byteswapped numbers; it takes a >>>>block, orders it correctly, then adds 5 to that, does the byteswap on >>>>the result, and stores that back. (You're not making a full copy of >>>>the array; just a large enough section at a time to do useful work.) >>> >>>It must be using some sort of cache for the multiplication. Seems like on >>>the first run it takes 6 seconds and subsequently .05 seconds for either >>>version. >> >>There is. The ufunc for the addition gets cached, so the first time >>takes longer (but not that much???) >> >> >>>>Maybe what you need is a package designed for *small* arrays ( < 1000). >>>>Simple C wrappers; just C doubles and ints, no byteswap, non-aligned. >>>>Maybe a fixed number of dimensions. Probably easy to throw something >>>>together using Pyrex. Or, wrap blitz++ with boost::python. >>> >>>I'll check out Numeric first. Would rather have a drop-in solution (which >>>hopefully will get more optimized in future releases) rather than hacking >>>my own wrappers. Is it some purist mentality that's keeping numarray from >>>dropping to C code for the time-critical routines? Or can a lot of the >>>speed issues be attributed to the overhead of using objects for the library >>>(numarray does seem more general)? >> >>It's the object overhead in numarray. The developers moved stuff up to >>Python, where it's more flexible to handle. Numeric is faster for >>small arrays (say < 3000), but numarray is much better at large >>arrays. I have some speed comparisions at >>http://arbutus.mcmaster.ca/dmc/numpy/ >> >>I did a simple wrapper using Pyrex the other night for a vector of >>doubles (it just does addition, so it's not much good :-) It's twice >>as fast as Numeric, so I might give it a further try. From justin__devine at hotmail.com Thu Aug 26 10:46:38 2004 From: justin__devine at hotmail.com (Justin) Date: 26 Aug 2004 07:46:38 -0700 Subject: Specific request with code example (encapsulation) __init__ problems Message-ID: On the advice of some members of this group I have decided to post a very specific question / problem with a code example. My problem is that my wxWidgets are created in the __init__ function of a panel. (This is the way wx demos showed, I am brand new so I copies what they did) my problem is now it appears that my widgets are completely encapsulated within this __init__ class and I cannot get at them. Here is an example of me trying to change the labels on a radiobox (all the code that doesn't matter has been taken out) you can see it all if you like. If the indentation is hard to understand due to the posting syntax please let me know. And thanks for your help in advance. The indentation quickly is 1 class "Gmainpanel" two functions "__init__()" and changelabel() class Gmainpanel(wx.Panel): __shared_state = {} def __init__(self, parent): self.__dict__ = self.__shared_state wx.Panel.__init__(self, parent, -1) #Make the Radiobox label_pickle = open("labels.dat", "r") labellist = cPickle.load(label_pickle) label_pickle.close() sizer = wx.BoxSizer(wx.HORIZONTAL) self.rb = wx.RadioBox(self,-1, "QuickSites", (10, 215), (425, 70),labellist , 5,wx.RA_SPECIFY_COLS) self.Bind(wx.EVT_RADIOBOX, EvtRadioBox, self.rb) self.rb.SetToolTip(wx.ToolTip("You can select a specific service to search")) sizer.Add(self.rb, 0, wx.ALL, 20) self.rb.SetSizer(sizer) def changelabel(self): self.rb.SetLabel(1, "test change") From aleaxit at yahoo.com Mon Aug 30 06:59:40 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 30 Aug 2004 12:59:40 +0200 Subject: about presicion References: <8f17f4bc.0408261434.1a73e874@posting.google.com> <2e363c08.0408261912.2358a016@posting.google.com> <8f17f4bc.0408281303.3cfb4199@posting.google.com> <20040829041630.28913.00001771@mb-m26.aol.com> Message-ID: <1gjc13i.rx89x319njqe2N%aleaxit@yahoo.com> Mensanator wrote: > >Subject: Re: about presicion > >From: Peter Hansen peter at engcorp.com > >Date: 8/28/04 10:31 PM Central Daylight Time > >Message-id: > > > >Ali wrote: > > > >> The decimal module comes with python 2.4? I have 2.3, :(, what do I do? > > > >The obvious answer is, well, obvious. The real question is > >what's stopping you from upgrading? > > I just tried it and found out it's not compatible with gmpy. By "it" do you mean Decimal, or Python 2.4 alpha 2? I think gmpy should build happily with the latter, and interoperate sensibly with Decimal anyway -- as gmpy's author I'd be quite happy to fix gmpy if it's broken in either respect. > Of course, I wouldn't need gmpy to get big floats, but I > would then lose all the math functions like linear congruence > and modular inverse that my programs depend on. > > So I, for one, will have to wait for the rest of the world to > catch up to 2.4. 2.4 is not currently recommended for production work (that's why it's in Alpha -- very good for an alpha, but it's still not a final release). But such support modules as gmpy need to get moving to support 2.4 in order to be ready for it well before final release... Alex From pf_moore at yahoo.co.uk Thu Aug 26 17:35:16 2004 From: pf_moore at yahoo.co.uk (Paul Moore) Date: Thu, 26 Aug 2004 22:35:16 +0100 Subject: Call for signatories for J2 References: Message-ID: "Robert Brewer" writes: > The J2 proposal is as complete as it will ever be. > > http://www.aminus.org/rbre/python/pydec.html Against. I can't see anything to convince me this is better that pie-syntax (which is in place, and complete, *right now*). And it still doesn't specify the keyword - which means there's another argument waiting to happen. Paul -- Instant gratification takes too long -- Carrie Fisher From yzhang8 at rice.edu Mon Aug 16 23:07:03 2004 From: yzhang8 at rice.edu (Ryan(Yang) Zhang) Date: Mon, 16 Aug 2004 22:07:03 -0500 Subject: is it possible to create an object by its name in the run time References: Message-ID: <003d01c48407$45aeaf10$6400a8c0@offer> > Hi all, > I wonder if it is possible to create an object of func, class or > method in the run time by it's name? To make it more clear, let me show you > an example: I parsed the python code and found a function with name 'len'. I > want to know if it is a build-in func(where can I look up?). If so, ignore > it otherwise I want to find out which module is it defined in. All I know is > the name (which is a string), and all the modules that this program have > imported. In the same way, I also need to process the class and methods > call. I wonder if it is possible? I will appreciate your help very much!! > > -Ryan > -- > http://mail.python.org/mailman/listinfo/python-list > From ville at spammers.com Fri Aug 20 10:37:14 2004 From: ville at spammers.com (Ville Vainio) Date: 20 Aug 2004 17:37:14 +0300 Subject: Alternative decorator syntax decision !! IMPORTANT THREAD !! References: Message-ID: >>>>> "Paul" == Paul McGuire writes: >> Yup - for those just joining in, post somewhere in this thread, it >> involves voting that all pythonistas know & love (along with the >> associated grain of salt that goes with it here in >> pythonland). Instructions in the root message. Paul> Will you vote now? :) Did already, on the thread w/o subject line change (I wasn't sure whether your script/whatever would handle changing the subject line). -- Ville Vainio http://tinyurl.com/2prnb From project5 at redrival.net Tue Aug 31 02:41:32 2004 From: project5 at redrival.net (Andrei) Date: Tue, 31 Aug 2004 06:41:32 +0000 (UTC) Subject: Intelisence References: <43SYc.121080$UTP.113615@twister01.bloor.is.net.cable.rogers.com> Message-ID: Jonathan Ellis gmail.com> writes: > > Is there any inelisence IDE (like visual studio) for python? > > There are several; Komodo from ActiveState is IMO the best of the lot. It's harder to do this for Python than for less dynamic languages. The most impressive I've seen is in WingIDE 2. I find it rather expensive though, at least for people who don't use it professionally. It's also less pretty than Komodo. More naive auto-completion/call tips you can also find in editors like SciTE and Spe. From lbates at swamisoft.com Tue Aug 24 16:14:04 2004 From: lbates at swamisoft.com (Larry Bates) Date: Tue, 24 Aug 2004 15:14:04 -0500 Subject: Are decorators really that different from metaclasses... References: Message-ID: You are asking the same question I asked in a separate posting to c.l.p (but apparently more clearly). I thought about using: class Foo: """ This is the docstring for class Foo. """ __decorators__ = {'metaclass': 'M'} # body of class goes here def baz(): """ This is the docstring for function baz. """ __decorators__= {'features': ['synchronized', 'memoized'], 'docstring':'This is the docstring for function baz. '} # body of function goes here. This seems extendable (e.g. you can add keys to __decorators__ dictionary without disturbing existing keys) and "sort of" parallels __dict__ which everyone understands. Some of these discussions are so far over my head that I thought my idea didn't somehow make any sense at all. Then I saw your post. Thanks, Larry Bates Syscon, Inc. "Paul Morrow" wrote in message news:mailman.2286.1093364988.5135.python-list at python.org... > ...that they warrant an entirely new syntax? It seems that they are > very similar in a very significant way --- they alter the default > behavior of something. IMO, it's not a stretch to say that they > 'parallel' metaclasses; that they are to functions/methods what > metaclasses are to classes. So why don't they share a similar syntax? > > class Foo: > """ This is the docstring for class Foo. """ > __metaclass__ = M > # body of class goes here > > > def baz(): > """ This is the docstring for function baz. """ > __features__ = synchronized, memoized > # body of function goes here. > > > I personally find the above baz function aesthetically appealing. Does > anyone else feel this way? For contrast, below is the same function > written in the proposed A1 and J2 [*] syntaxes (respectively). > > > @synchronized > @memoized > @doc(""" This is the docstring for function baz. """) > def baz(): > # body of function goes here. > > > decorate: > """ This is the docstring for function baz. """ > synchronized > memoized > def baz(): > # body of function goes here. > > > * if J2 is accepted, the name 'decorate' may be replaced with some other > keyword, but I believe that the structure of the syntax would stay the same. > > Paul > From dfan at harmonixmusic.com Fri Aug 13 15:12:31 2004 From: dfan at harmonixmusic.com (Dan Schmidt) Date: 13 Aug 2004 15:12:31 -0400 Subject: Why I love python. References: Message-ID: Nick Patavalis writes: | To cut the thread short, what I mean is that an application that has | to do something like: | | for i in range(N): | a[i] = b[i] + c[i] | | is bound to be 10 to 100 times slower than the equivalent coded in | C. Although note that (at least by my timing) a = map( operator.add, b, c ) is 3 times as fast as your Python version, bringing the code up to being only 3 to 33 times slower than C. I'm sure that pyrex could bring the speed up a heck of a lot more, too. -- http://www.dfan.org From adonisv at DELETETHISTEXTearthlink.net Wed Aug 11 12:15:57 2004 From: adonisv at DELETETHISTEXTearthlink.net (Adonis) Date: Wed, 11 Aug 2004 16:15:57 GMT Subject: Another decorator proposal. Message-ID: <1DrSc.21247$Jp6.6525@newsread3.news.atl.earthlink.net> How about something to this effect: class Foo: def static bar(): ... or class Foo: def __init__(self): ... def Foo bar(): ... Pros/Cons? Adonis From fredrik at pythonware.com Sat Aug 7 19:31:06 2004 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 8 Aug 2004 01:31:06 +0200 Subject: Image manipulation library under a GPL-compatible license? References: <2nl3suF1vntdU1@uni-berlin.de> Message-ID: "Leif K-Brooks" wrote: > I need to do some simple image editing (pretty much just scaling) in a > GPLed program. Unfortunatly, both of the Python libraries for image > editing that I found (gdmodule and PIL) are under the GPL-incompatible > original BSD license. Is there another library under a friendlier library? sorry, but you don't have the slightest idea what you're talking about. PIL uses the original Python license, about which FSF has the following to say: This is a free software license and is compatible with the GNU GPL. http://www.gnu.org/philosophy/license-list.html and before you spread more license FUD, maybe you should learn why the *original* BSD license is not considered to be GNU-compatible: http://www.gnu.org/philosophy/bsd.html From jgrahn-nntq at algonet.se Sun Aug 8 13:56:25 2004 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: Sun, 8 Aug 2004 17:56:25 +0000 (UTC) Subject: Paul Graham on Python hackers References: <3064b51d.0408061127.32536826@posting.google.com> Message-ID: On Sun, 08 Aug 2004 03:10:32 +0200, Baalbek wrote: > beliavsky at aol.com wrote: >> also choosing a community. The programmers you'll be able to hire to >> work on a Java project won't be as smart as the ones you could get to >> work on a project written in Python. [2] And the quality of your > > I prefer Java and Python alike, I simply love those two languages..... > > So, am I smart, or not as smart? Smarter than the people who proclaim that Java Is The One Language, probably. Or the people who learned Java by default and never looked beyond it. > What a stupid assertion to make; this Paul Graham has just proven > himself to be an ass......... Yeah - that article was enjoyable to me, since I loathe Java and it's users. The only problem I had with it was that his reasoning was bogus ... ;-) /Jorgen -- // Jorgen Grahn Would You Let One Marry Your Sister?'' From XXNOSPAMXX at gibts.net Fri Aug 20 10:10:35 2004 From: XXNOSPAMXX at gibts.net (Thomas Reichelt) Date: Fri, 20 Aug 2004 16:10:35 +0200 Subject: Alternative decorator syntax decision References: Message-ID: <2omevcFccudoU1@uni-berlin.de> Paul McGuire wrote: > My vote is: J2 J2 C1 My vote is: J2 J2 C2 -- greetz tom From len-1 at telus.net Sat Aug 21 13:24:35 2004 From: len-1 at telus.net (Lenard Lindstrom) Date: Sat, 21 Aug 2004 17:24:35 GMT Subject: __metaclass__ and __author__ are already decorators References: Message-ID: Andrew Durdin writes: > __metaclass__ on the other hand is a magic attribute. I haven't worked > out the details, but I have the feeling that what a metaclass does to > a class is not replicable merely by decorating the class; in other > words, that: > > class Foo: > __metaclass__ = Bar > > is *not* equivalent to > > class Foo: > pass > > Foo = Baz(Foo) > > for any definitions of Bar and Baz. This is just my intuition, however. Used within a class decoration __metaclass__ is just another class attribute, but it does have special meaning to the class factory. It names a new factory to use in place of the default one. And its effects are inherited. So for: class SubFoo(Foo): ... SubFoo also gets metaclass Bar. Foo = Baz(Foo) would not work that way. And yes Bar and Baz would be different. Bar would take three arguments, a class name, a list of base classes, and a dictionary of class attributes. Baz would extract this information from an existing class object. Lenard Lindstrom From sbabbitt at commspeed.net Thu Aug 5 08:34:09 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Thu, 5 Aug 2004 05:34:09 -0700 Subject: Scope Problem References: Message-ID: <1091709635.62853@news.commspeed.net> "Nickolay Kolev" wrote in message news:cet6eh$tvq$1 at f1node01.rhrz.uni-bonn.de... > Hi all, > > I have set to implementing a few basic algorithms in Python serving a > twofold purpose: learning the algorithms and learning Python a little > better. > > I have however encountered a strange (for me anyway) scoping problem. > > Here is my implementation of linear search as a method in a class, hence > all the self's (self.sequence is the sorted sequence we are searching in > and value is, well, the value we are searching for): > > def linearSearch(self, value, index = None): > > if not index: > index = 0 > > try: > > if self.sequence[index] == value: > > return index > > else: > > self.linearSearch(value, index + 1) > > except IndexError: > > return -1 > > > My problem is that this method always returns None regardless of whether > the value was found or not. If I put print statements in there, all the > values and indices are printed correctly though. Actually I have another > parameter to this method called debug, if this is set, the single > comparison steps are printed to STDOUT (omitted above to avoid clutter). > > What am I doing wrong? > > Many thanks in advance, > Nicky Try useing the self keyword, def linearSearch(self, value, index = None): > self.index = index > > if not self.index : > self.index = 0 > > try: > > if self.sequence[self.index ] == value: > > return self.index > > else: > > self.linearSearch(value, self.index + 1) > > except IndexError: > > return -1 Tom From max at alcyone.com Sat Aug 21 18:22:04 2004 From: max at alcyone.com (Erik Max Francis) Date: Sat, 21 Aug 2004 15:22:04 -0700 Subject: Mind.py References: <41220b22@news.victoria.tc.ca> <4122796E.9652CCAE@alcyone.com> Message-ID: <4127CB0C.E4F49160@alcyone.com> threeseas wrote: > Erik Max Francis wrote: > > > "Arthur T. Murray" wrote: > > > > > Now, suppose that you wanted to write an AI in Python that would > > > implement your mind-model and allow it to grow, mutate, develop. > > > Here is one possible scenario. > > > > http://www.nothingisreal.com/mentifex > > its a good thing we all use our minds alike, huh? > > Oh wait, so why doesn't Arthur slander or libel himself? It's like an epic battle between Racter and Eliza! -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ Who shall stand guard to the guards themselves? -- Juvenal From martindemello at yahoo.com Mon Aug 23 10:30:14 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Mon, 23 Aug 2004 14:30:14 GMT Subject: serial iteration over several lists References: <1b5c4527.0408212257.5c9c18b4@posting.google.com> Message-ID: Jeffrey Froman wrote: > Martin DeMello wrote: > > > Thanks - that looks like an excellent starting point. Has there been any > > work done on bidirectional iterators? > > You could emulate one by maintaining a counter for the current index into > the imaginary flattened list, and iterating up to that index with each > prev() call and just past it with each next(). This of course requires that > you basically start from the beginning of your nested list each time > though, and I'm not sure if it would be more or less efficient than > indexing into a pre-flattened list in memory. I ended up just maintaining a few list indexes, and writing code to wrap them around properly - turned out to be the simplest way since bidirectionality was more important than iterator-like support. > One more suggestion -- if you use a recursive generator for your iteration, > you can then use it with a list nested to arbitrary depth, something like: > > ############################################# > > def deep_iter(nested_list): > for x in nested_list: > if isinstance(x, list): > for n in deep_iter(x): > yield n > else: > yield x > > ############################################# I thought of that, but again it proved nigh impossible to backtrack cleanly over. The other idea I had was to maintain two iterators, one going forwards and one going backwards, and reinitialize them as needed. For example, if I wanted to do that over the list [1,2,3,4,5,6,7,8,9] I'd set forward to 1 and reverse to 9, then iterate forward as long as next was called, then when prev was called, reinitialize reverse to wherever the index had reached and call its next method. martin From me at privacy.net Mon Aug 16 11:48:49 2004 From: me at privacy.net (Richard Hanson) Date: Mon, 16 Aug 2004 08:48:49 -0700 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> <30260531.0408131853.18ec2446@posting.google.com> <3ke1i05c3cq93vhdmdigj3pudru9n99a4j@4ax.com> Message-ID: <9fl1i0to8jbvo1nva7pk1o819hi96knfr1@4ax.com> Peter Hansen wrote: >Richard Hanson wrote: >> For me, a not insignificant part of Python's genius *is* the >> indentation. When I used C and C++ I was a stickler (pedant? :-) >> ) for "proper" indentation -- which was a PITA. So -- I took to >> Python's indentation like a duck to water. > >That's been exactly my situation as well, which leads me to >theorize that those who react most strongly against Python's >syntactically significant indentation are those who were the >least consistent or, uh, "anal" about making sure their code >conformed to conventions. ;-) obsessive-compulsively y'rs, Richard -- R Hanson [The mangled email addie below works.] sickolefartnewsguycom From peter at engcorp.com Tue Aug 17 22:20:01 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 17 Aug 2004 22:20:01 -0400 Subject: simple Thread question In-Reply-To: <1d6cdae3.0408171648.1b8767ea@posting.google.com> References: <1d6cdae3.0408171648.1b8767ea@posting.google.com> Message-ID: Beeyah wrote: > adeger at netlibrary.com (adeger) wrote in message news:... > >> def run(self, name): >> import time >> for i in range(1,11): >> print 'thread ', name, ' instance ', str(i) >> time.sleep(1) > > You're importing the time module for every TestThr() object you > create, that's no good. You only need to import the module once, at > the beginning of the file like you've done with threading. While it's true that that is all that's needed, it is not required, and doesn't really provide any performance improvements. I often do the above sort of thing where I use a given module in only one place, especially when using threads where it feels subtly cleaner to defer loading of some modules until the thread actually starts. Modules are really ever imported only once and after that the "import" statement amounts to retrieving a reference by looking it up in the sys.modules dictionary. In the case of a builtin module like "time", there isn't even any significant overhead involved in the first import, as there might be with a .py module (where the timestamp encoded in the .pyc file is compared with the timestamp of the .py file, and the .py file is recompiled if necessary, and then a new module object is created and the bytecode is executed in its namespace, etc). -Peter From grante at visi.com Wed Aug 18 16:18:36 2004 From: grante at visi.com (Grant Edwards) Date: 18 Aug 2004 20:18:36 GMT Subject: Newbie question about file input References: <4122328e$0$8079$a1866201@newsreader.visi.com> Message-ID: <4123b99c$0$65601$a1866201@newsreader.visi.com> On 2004-08-18, Aaron Deskins wrote: > Marc 'BlackJack' Rintsch wrote: > >> >> A line without anything but whitespace characters "splits" to an empty >> list. >> > > Thanks for the info. I wasn't aware that "\n" is whitespace. I'm still a > programming beginner and learning everyday! Any other whitespace > characters I should know about? Usually space, carriage-return, horizontal-tab, vertical-tab, and form-feed. You may want to consule the documentation on the split() string method to find out what it considers white space. -- Grant Edwards grante Yow! .. are the STEWED at PRUNES still in the HAIR visi.com DRYER? From __peter__ at web.de Fri Aug 20 02:29:22 2004 From: __peter__ at web.de (Peter Otten) Date: Fri, 20 Aug 2004 08:29:22 +0200 Subject: Alternative decorator syntax decision References: Message-ID: My vote: J2 J2 K Preferred keyword: transform I could live with the pie, though. Peter From nospam at nospam.com Thu Aug 5 11:15:44 2004 From: nospam at nospam.com (3c273) Date: Thu, 5 Aug 2004 08:15:44 -0700 Subject: Need help on how to use Pymedia! References: Message-ID: "CptPicard" wrote in message news:AXgQc.508$nx2.344 at newsread2.news.atl.earthlink.net... > Hi, > I am currently trying to use pymedia so to get the following informations > (author, song title, ...) from a mp3 file. > The documentation I downloaded is quite limited : It gives some clues on how > to get that information (method getInfo() from pymedia.audio.acodec). > However, it does not explain what has to be done prior to that call. > I downloaded pycar but it did not help me. > > Could someone give me a more detailed documentation on pymedia or some clues > on how to get the information I need ? > > Thanks for your help > Hi, I have never used pymedia but section 6.7 of the "Dive Into Python" tutorial describes a class for getting mp3 file information. It is quite simple and if I recall correctly, it worked perfectly when I tried it. HTH. Louis From monnier at iro.umontreal.ca Thu Aug 26 15:20:26 2004 From: monnier at iro.umontreal.ca (Stefan Monnier) Date: Thu, 26 Aug 2004 19:20:26 GMT Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: > I'm starting my own cult to exterminate morons on this earth. Sounds suicidal to me, Stefan From johnfkeeling at yahoo.com Mon Aug 2 15:52:20 2004 From: johnfkeeling at yahoo.com (John Keeling) Date: 2 Aug 2004 12:52:20 -0700 Subject: Timing Difference: insert vs. append & reverse References: <35b736b9.0408020330.53b24ed3@posting.google.com> Message-ID: <35b736b9.0408021152.4c1ab752@posting.google.com> Duncan, > A list is implemented by an array of pointers to the objects it contains. That explains it. > If you expected insert to be faster, perhaps you thought that Python used a > linked-list implementation. It doesn't do this, Yes, that is how I was thinking. It is interesting to see how functions may perform very differently from how we may initially expect. I've also noted an approximate two time difference between "del list[index] and list.pop(index)". I know that they do different things (the return value from pop), however in many places my code uses pop and ignores the return value when it would be faster to use del. I am making changes based on these observations now. Thanks, John From bokr at oz.net Sun Aug 1 14:19:19 2004 From: bokr at oz.net (Bengt Richter) Date: 1 Aug 2004 18:19:19 GMT Subject: transforming a list into a string References: Message-ID: On Sun, 1 Aug 2004 11:00:32 +1000, Andrew Bennetts wrote: [...] > >It's a two-liner, not a one-liner (although it could be made into a >one-liner with enough contortions...). > Another contortion ;-) >>> items = ['1','2','7','8','12','13'] assumed defined as before, then one line: >>> ''.join([i%2 and c+'},' or '{'+c+',' for i,c in enumerate(items)])[:-1] '{1,2},{7,8},{12,13}' Regards, Bengt Richter From h.b.furuseth at usit.uio.no Mon Aug 23 14:35:54 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 23 Aug 2004 20:35:54 +0200 Subject: Finding a class' superclasses References: Message-ID: Michael Hudson wrote: >Hallvard B Furuseth writes: >> How do I find a class' immediate superclasses? >> (...) > > D.__bases__? Aah. Thanks. And now that I know what to look for, I see it right where it's supposed to be and where I didn't see it last time in the Python reference:-) -- Hallvard From richie at entrian.com Wed Aug 18 08:08:58 2004 From: richie at entrian.com (Richie Hindle) Date: Wed, 18 Aug 2004 13:08:58 +0100 Subject: anonymous function? In-Reply-To: References: Message-ID: [Benedict] > t = threading.Timer(10.0, sendCheckCommand() ) > ... > TypeError: 'NoneType' object is not callable You are calling the sendCheckCommand function and passing its return value (None) to threading.Timer(). You should say: > t = threading.Timer(10.0, sendCheckCommand) instead. -- Richie Hindle richie at entrian.com From steven.bethard at gmail.com Mon Aug 23 12:45:35 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: 23 Aug 2004 09:45:35 -0700 Subject: J2 paper 0.2.1 References: <10ijfibd8qo84b5@news.supernews.com> Message-ID: "Robert Brewer" wrote in message news:... > The first draft of the J2 proposal is ready. You can read it here: > http://www.aminus.org/rbre/python/pydec.html Outstanding job here. Your arguments are very clear and thorough and I think you defend J2 against pretty much every objection that was brought up against it. I especially liked the point about the adjectival/dependent uses of keywords already in Python -- I was undecided about the keyword before, but I could definitely rally around "using" now. Minor nits: * I might write "if/else/elif" as "if/elif/else". (Google seems to agree with me -- ~900 hits for the first and ~2700 for the second.) * The point about expressions (as opposed to statements) occuring only within suites was a little unclear. Some things that might help: 1) "Further, it is almost exclusively within suites that one currently finds [bare] expressions which are not statements." Just to make sure we're not confusing expressions in, say, the test of a while-loop, with the use of /bare/ expressions you're talking about here. 2) Make clear that you are talking about /standard/ usage of expressions -- I can, of course, write an expression like, say, a list comprehension, at the top of any module I like, but I'm not very likely to do so. That is, Python /allows/ expressions pretty much anywhere, but they aren't generally /used/ everywhere. 3) "Lambdas are another common example, albeit degenerate, of [a suite containing] bare expressions." 4) It's a little unclear what "consequently" is referring back to. Maybe: "[Given this precedent for using expressions in suites and the lack of such precedent for non-suites,] a suite is a more appropriate and consistent place (than normal linear code) in which to introduce a series of decorator expressions." * Tie the reasons for recommending "using" back a little more tightly to the new keyword requirements above it: 1) "It emphasizes the dependent nature of decorators[, both in its semantics and in its inability to 'stand alone' without the def statement]." 2) "It 'reads correctly' in every use case, both for transformational and annotative decorators." (This one actually seems a lot like "It emphasizes the generic nature of decorators." Maybe a few more words on what you mean by "generic" to explain the differences here?) Well, thanks again for such outstanding work in such little time! Steve From d-hanst at online.no Fri Aug 27 15:19:52 2004 From: d-hanst at online.no (Dag Hansteen) Date: Fri, 27 Aug 2004 21:19:52 +0200 Subject: My IDLE editor wont work! Message-ID: <001d01c48c6a$d4090740$4e01a8c0@dagan> hi, I have a problem on my comp - I'm using win2000, and the IDLE editor won't open when I try to execute it. I tried to uninstall the python versions(yes I had one older installed also) and reinstalled 2.3.4. That doesn't help. Anyone have a clue...? regards Dag Hansteen -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwh at python.net Thu Aug 12 08:18:03 2004 From: mwh at python.net (Michael Hudson) Date: Thu, 12 Aug 2004 12:18:03 GMT Subject: [OT] Keyboard layout, was Re: PEP318 References: <20040812090056.00001e31@titan> Message-ID: Ville Vainio writes: > Numbers like 8 and 9 are useless for coding - everything beyond 0 > and 1 implies a flawed design. Snarf! Cheers, mwh -- 48. The best book on programming for the layman is "Alice in Wonderland"; but that's because it's the best book on anything for the layman. -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html From geoff at variosoft.com Sun Aug 8 03:22:56 2004 From: geoff at variosoft.com (Geoff Caplan) Date: Sun, 8 Aug 2004 08:22:56 +0100 Subject: Compiling disutil modules on Windows Message-ID: <13185971049.20040808082256@variosoft.com> Neil, NH> You could try to use mingw: NH> http://sebsauvage.net/python/mingw.html I had spotted this page but it looks a bit daunting for someone with no C skills. (Though the instructions do seem quite clear: thanks, S?bastien!) Most people come to a very high level language like Python because the *don't* want to muck around with stuff like gcc. I can see this eating up time :-( You've got to be grateful to Active State for producing such a comprehensive and convenient distro, but does anyone know why they have chosen an expensive and out-of-date commercial compiler? Why not gcc, or at least MSVC++ 7, which is a free download? For client-side stuff it's still impossible to avoid Windoze entirely, for the time being at least. It's an important platform for Python, so it would be good if the leading distro made this convenient. At present the choice appears to be between forking out good $$$ to the company that is covertly attacking Open Source through its proxy SCO (not something I'm prepared to consider!), or to get involved in some low-level hacking. This is surely not an ideal state of affairs? ------------------ Geoff Caplan Vario Software Ltd (+44) 121-515 1154 From mcfletch at rogers.com Wed Aug 18 09:58:11 2004 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Wed, 18 Aug 2004 09:58:11 -0400 Subject: metaclass ??? In-Reply-To: <20040818082245.89FEA1E4003@bag.python.org> References: <20040818082245.89FEA1E4003@bag.python.org> Message-ID: <41236073.1000502@rogers.com> BruceKL WhoH wrote: >Hi, > I have just read David Mertz's Metaclass programming in Python,but I'm still confused. >can someone show me an example to explain when metaclass is needed? > > In large part this is the question that my PyCon presentation was trying to explore. If you're interested, you can find the presentation and sample code here: http://www.vrplumber.com/programming/ > I think metaclass can be treated as a class factory,but how to specify the class generated? For example: > > See particularly the metainitialisation.py sample code for the presentation, which does approximately what I think you're trying to do with your example. HTH, Mike ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From alikakakhel3 at hotmail.com Sun Aug 15 22:22:41 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 15 Aug 2004 19:22:41 -0700 Subject: how to change the text in the title bar of the Tkinter windows Message-ID: <8f17f4bc.0408151822.1be2de2e@posting.google.com> When I open a window using the Tkinter GUI thing the title bar always says "Tk". I would like to know how to change this. I would also like to know how to cjange it on any other popup windows I may have. Please help. From sholden at flexal.cs.usyd.edu.au Fri Aug 20 23:32:16 2004 From: sholden at flexal.cs.usyd.edu.au (Sam Holden) Date: 21 Aug 2004 03:32:16 GMT Subject: Why are strings immutable? References: Message-ID: On Sat, 21 Aug 2004 03:26:00 GMT, Brent W. Hughes wrote: > I kind of hate to have to convert a string into a list, manipulate it, and > then convert it back into a string. Why not make strings mutable? Not being able to use strings as dictionary keys would kind of suck :) -- Sam Holden From raims at dot.com Wed Aug 18 18:22:30 2004 From: raims at dot.com (Lawrence Oluyede) Date: Thu, 19 Aug 2004 00:22:30 +0200 Subject: multi-instance and classic singleton design patterns References: Message-ID: In data 18 Aug 2004 14:54:05 -0700, Neil Zanella ha scritto: > it seems to me that the > former leads to less coding, so unless I can somehow package the > singleton pattern in a superclass (so I don't have to code it > explicityly in every singleton class I have), then I am more > interested in the multi-instance singleton design pattern. Seems that Alex Martelli coded a Borg implementation in Python sometimes ago: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531 -- Lawrence (l dot oluyede at virgilio dot it) "If the implementation is hard to explain, it's a bad idea." from The Zen of Python by Tim Peters From shane at techgame.net Thu Aug 5 12:43:40 2004 From: shane at techgame.net (Shane Holloway (TG)) Date: Thu, 05 Aug 2004 10:43:40 -0600 Subject: ANN: Dive Into Python published In-Reply-To: References: Message-ID: <411263BC.4040504@techgame.net> Mark, You have done a wonderful job on this book. I've looked over chapters as you have announced them, and I'm happy that you're finally done! I look forward to using this book to introduce Python to the developers we hire. Thanks Again! -Shane Holloway Mark Pilgrim wrote: > I am pleased to announce that my Python book "Dive Into Python" is now > available on paper, published by Apress and weighing in at 432 pages. > > http://www.amazon.com/exec/obidos/ASIN/1590593561/ref%3Dnosim/diveintomark20/ > > More information, and a complete online edition, is available at > . > > Without Apress' financial support, this book would have languished > half-written and self-published, full of typos and technical mistakes. > Even if you have read the online edition, please consider buying a > copy. > > ===== obligatory back cover blurb follows ===== > > This is a practical book aimed at busy developers. Every chapter takes > a real piece of code and turns it inside out until you can't help but > understand it. If there is background information you need to know, > you'll learn it along the way. But you won't find long-winded > treatises on the aesthetics of API design or the history of computer > science. I don't have time for that, and neither do you. > > And yet, as practical as this book is, there is a touch of passion in > it. I fell in love with Python the day I found it. Did I fall in love > because of some abstract sense of elegance or style? No, I fell in > love because it works and doesn't get in my way. The standard > libraries are robust and easy to use. The syntax is not picky or > arcane. Developing in Python is like writing pseudo-code that works. > After a decade of experience with dogmatic languages, Python is a > breath of fresh air. > > This book covers the basics of Python datatypes, from lists to > dictionaries to tuples and beyond. You'll learn about the power of > introspection; Python's powerful object model; regular expressions; > HTML and XML processing; web services; unit testing; performance > tuning; and the newest language features added in Python 2.3: iterators > and generators. > > I hope this book makes you fall in love with Python. But if not, > that's okay. You'll learn plenty anyway, and my passion can be enough > for both of us. > > -- > Mark Pilgrim > From ny_r_marquez at yahoo.com Tue Aug 17 12:20:23 2004 From: ny_r_marquez at yahoo.com (R.Marquez) Date: 17 Aug 2004 09:20:23 -0700 Subject: Simple exceptions question References: Message-ID: <8a27e309.0408170627.7258082c@posting.google.com> Not sure if this is all you need, but have tried this? def main(): #define vars try: foo(a, b, c) except IndexError: import traceback traceback.print_exc() From chrisdewinN0SPAM at yahoo.com.au Wed Aug 25 14:18:09 2004 From: chrisdewinN0SPAM at yahoo.com.au (Dfenestr8) Date: Thu, 26 Aug 2004 03:18:09 +0900 Subject: Capturing exceptions? References: Message-ID: On Wed, 25 Aug 2004 19:19:06 +0200, Mathias Waack wrote: > Dfenestr8 wrote: >> What's the easiest way to capture the traceback from an exception, and >> write it to a file? Ideally, I'd like to be able to do something like: >> >>>try: >>>main() >>>except: >>>write the traceback to a file > > Have a look at the traceback module. > > Mathias I did. Thanx. But I'm afraid I don't understand it. >From looking at the docs, it would appear the method extract.tb(traceback, limit) is the method I want. But it appears to want some kind of object as its parameter, and I have no idea what kind of object that is. I've tried "a = traceback.extract_tb(tb)", "traceback.extract_tb(traceback)", "traceback.extract_tb(sys.exc_info())". What kind of parameter does it need? From nomail at nomail.nomail Mon Aug 16 13:52:39 2004 From: nomail at nomail.nomail (Dominic) Date: Mon, 16 Aug 2004 19:52:39 +0200 Subject: Generators versus Coroutines In-Reply-To: <972ec5bd.0408152033.19fdcba4@posting.google.com> References: <972ec5bd.0408141032.385fe115@posting.google.com> <972ec5bd.0408152033.19fdcba4@posting.google.com> Message-ID: > It really was never an issue of "Python can't handle this." it was > more of an issue of "Python should more openly support this." I am > championing generators because they make programming SO much easier in > cases, and people really just don't use them outside if list > generation, which saddens me. Coroutines are much more powerful than Python's generators and they can be easily abused to create unstructured "goto"-like programs thus I assume it would still be a good idea to put most effort into your architecture and it's underlying execution model regardless of what you finally use to keep state: coroutines, threads, (nested) generators. Try to hide the implementation if you can. Nesting generators works, but I have to admit it's (probably) not very elegant. I would also prefer coroutines for simulation and games as a module similar to thread/threading. I think Michael Jackson wrote a converter for COBOL in the 70s, which would "invert" active entities into ordinary functions keeping their state in ordinary data structures. This can certainly be done in Python too. Maybe this helps. Ciao, Dominic P.S. Many programming languages do not even have support for "generators", e.g. Java Ha! Maybe @decorators are the solution ! ;-) From eric_brunel at despammed.com Tue Aug 24 12:50:20 2004 From: eric_brunel at despammed.com (Eric Brunel) Date: Tue, 24 Aug 2004 18:50:20 +0200 Subject: Regular expression guaranteed to fail References: <96jmi0pt39frp5n3r34afrt21cfeclp0mi@4ax.com> Message-ID: Hallvard B Furuseth wrote: > Greg Chapman wrote: > >>Why not just "(?!)": this always fails immediately (since an empty pattern >>matches any string, the negation of an empty pattern match always fails). > > > It's fine for re.match. > > 'Why not?': Because I'd expect re.search to walk through the entire > string and check if each position in the string matches that regexp. > Unfortunately, a little timing shows that that happens with _every_ > regexp suggested so far. Long strings take longer for each of them. > (Except Jeremy's solution, of course, which avoids the whole problem.) > r'\A(?!)' or r'\Ax\A' didn't work either. > > Anyway, I note that r'x\A' beats all the other regexps suggested so far > with a factor of 20 when searching 's'*10000. And when searching 'x'*10000? Since there is an 'x' in the re, it may change things a lot... -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From pm_mon at yahoo.com Sun Aug 15 21:59:52 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sun, 15 Aug 2004 21:59:52 -0400 Subject: Decorators: an outsider's perspective In-Reply-To: <6F7215C0-EF23-11D8-9F63-000A95B336F2@snowtide.com> References: <20040815155532.9C77F1E400B@bag.python.org> <6F7215C0-EF23-11D8-9F63-000A95B336F2@snowtide.com> Message-ID: Chas Emerick wrote: > > I think you have the direction of causation reversed here. Python > programmers don't use 'self' as the first argument to indicate an > instance method, they/we (again, I worry how much cred I have as a > python programmer yet :-) use 'self' *because* a method is an instance > method. I know you'd like the reverse to become a > standard/convention...that's a respectable position, but not a > particularly practical one since a soon-to-be-standard method for > defining a function's type is on its way that just happens to be > generalized enough to be useful in tons of other contexts. > The "soon-to-be-standard" (gosh, I hope not!) technique would require that we explicitly 'declare' class methods and static methods, as we do now (albeit with a different syntax). Isn't that less practical than simply having the system enforce the coding convention? And what happens when the declaration disagrees with the convention? That is, what happens when a developer writes def foo(self): pass but declares it to be a class or static method? Shouldn't the system at least issue a warning message (that you're likely to be confusing your poor readers)? And if it's going to go that far... :-) > I think the source of my gut reaction to the proposal you've advanced > (aside from the conceptual action-at-a-distance violation that I already > cited) is my past experience with Hungarian notation, where the name of > a variable indicates its type. The comparison isn't totally clean cut > because of the special peculiarities of Hn, but I think the folly that > it represents is a clear warning to stay away from taking type > information based on naming conventions. > I don't see your point about an 'action-at-a-distance' violation. Wouldn't that only be the case if something we do locally has side effects that break something in another part of the application? As for the Hungarian notation, I agree that in its most abused state, it can be a real mess for all sorts of reasons. However in Python we do use a very lightweight form of that in the way we identify private and semi-private methods. > I won't discuss the virtues or drawbacks of whitespace-as-structure, > since that's been hacked to death 1433 times already. However, I will > say that python's usage of whitespace kept me away from seriously trying > it for almost a year. Now, that's absolutely my fault, and isn't > representative of the technical ability of python. However, if > continued rapid uptake of python by new users is important, I would > suggest that using the success of whitespace-as-structure in 'the > market' is not the greatest reference for a proposal. > I said that it was elegant and genius; I never said that is wasn't a barrier for adoption. Still it'll be a sad day when Guido decides that to increase Python's popularity, we must support curly braces :-( From pm_mon at yahoo.com Sun Aug 29 12:10:13 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sun, 29 Aug 2004 12:10:13 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Bengt Richter wrote: > On Sat, 28 Aug 2004 08:45:20 -0400, Paul Morrow wrote: > [...] > >>Cool! Thanks! Now I need to ponder why a function's docstring needs a >>different implementation than a class's docstring (i.e. why not just >>make it a straigtforward attribute of the function object). >> > > Disclaimer: I am just speculating from appearances accessible interactively, > so don't take this as developer's documention of internals. I'm just reading > between the lines, trying to recognize the underlying ideas ;-) > > So, depending on your idea of 'straightforward' ISTM docstrings do look like > 'straightforward' attributes in the way they behave: > By straightforward here I mean stored directly in the object's __dict__. It's such an obvious place to keep the docstring, and it's the expected place, since that's where it's (apparently) stored for classes and modules. > So there is a difference between func and old-style-class docstring implementations. > Were you using old style classes for your question? > I'm hoping that it doesn't matter. What I'm really trying to get at is a function's namespace --- a dictionary that maps function attribute names to objects --- so that the interpreter has a context in which to evaluate __xxx__ variables defined at the outermost level of a function def. Remember, I'm asserting that when we define __xxx__ attributes inside of a function def, they are not intended to be local variables, used in the computation of the function's result. Rather they are intended to be function meta data, and therefore should be evaluated (at function definition time, not function execution time), in the context of the function being defined. For example, in the following function def, the comments specify (what I believe is) the author's intention behind each assignment. def circu(diameter): """Info about circu.""" # defines circu.__doc__ __author__ = 'Paul Morrow' # defines circu.__author__ __features__ = memoized # defines circu.__features__ pi = 3.14 # local variable definition return pi * diameter > I don't know why I did this... > You were trying to help us understand what's going on under the hood, and I really appreciate that research and explanation. Thank you for taking such an interest in this issue. Paul From fumanchu at amor.org Sun Aug 22 10:26:36 2004 From: fumanchu at amor.org (Robert Brewer) Date: Sun, 22 Aug 2004 07:26:36 -0700 Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WEDONE? Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E25@exchange.hqamor.amorhq.net> Doug Holton wrote: > I got over 250 votes for C1 just last week vs. the 22 who voted for J2 here. By my reckoning, that would mean a third poll would garner somwhere between 1 and 2 total votes. > Just make a poll with J2 vs. C1 and see what you find. I don't see the point at this stage. I've put 20 hours into a document for J2 this weekend, and would really like to start working on consensus for it now. If you want to write a similar document for C1, feel free. The time for voting is over, IMO. Robert Brewer MIS Amor Ministries fumanchu at amor.org From mlh at furu.idi.ntnu.no Mon Aug 23 16:41:53 2004 From: mlh at furu.idi.ntnu.no (Magnus Lie Hetland) Date: Mon, 23 Aug 2004 20:41:53 +0000 (UTC) Subject: Standard graph API? References: Message-ID: In article , Jeremy Bowers wrote: [snip] As I tried to state in the original post (I probably wasn't clear enough) I'm not talking about a standard *implementation*, just a standard *API*, like the DB-API. This could easily cover all kinds of strange beasts such as directed or undirected, weighted or unweighted (etc.) graphs; multigraphs, chain graphs, hypergraphs, who knows. I'm basically just suggesting that it might be useful to have a "standard" interface for these things. It may be that the simple de facto standard that David cites is sufficient (although it certainly doesn't cover hypergraphs -- but that's possibly going a bit too far anyway.) -- Magnus Lie Hetland "Canned Bread: The greatest thing since sliced http://hetland.org bread!" [from a can in Spongebob Squarepants] From fumanchu at amor.org Mon Aug 23 13:22:34 2004 From: fumanchu at amor.org (Robert Brewer) Date: Mon, 23 Aug 2004 10:22:34 -0700 Subject: J2 paper 0.2.1 Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E43@exchange.hqamor.amorhq.net> Fran?ois Pinard wrote: > Thanks also to Michael for the implementation, and to Paul > who helped us all > at channelling the conversation. Amen. Again I say, amen. FuManChu From faust at wintermarket.org Mon Aug 30 08:12:30 2004 From: faust at wintermarket.org (Michael Jard) Date: Mon, 30 Aug 2004 12:12:30 GMT Subject: Pass a class to an InteractiveCompiler? Message-ID: class grid_object: def __init__(self,object_class=""): import random import code self.id = random.randrange(1,99999) self.object_class = object_class self.label = "grid object: %s %i" % (self.object_class, self.id) self.vector = [0,0,0] source = open(grid_config.object_scripts + self.object_class,'r') x = code.InteractiveConsole({'grid_object':self}) for line in source: x.push(line) I'd like to think that was possible? From tim.peters at gmail.com Sat Aug 7 03:23:23 2004 From: tim.peters at gmail.com (Tim Peters) Date: Sat, 7 Aug 2004 03:23:23 -0400 Subject: Timing Difference: insert vs. append & reverse In-Reply-To: References: <35b736b9.0408020330.53b24ed3@posting.google.com> <1a517b5.0408031027.60554dfb@posting.google.com> <1a517b5.0408041305.3927a6c8@posting.google.com> Message-ID: <1f7befae04080700235f54628d@mail.gmail.com> [Bryan Olson] > Looking at the source, I'm worried. Append and pop[-1] are not > really amortized O(1); at best they're commonly-average O(1). > Alternating appends and pops at certain border values will call > realloc for every operation. The pop-reallocs free the extra > memory; if the allocator uses that memory for other requests, > the following append will have to copy the entire list. ... > The leave-it-to-realloc method seems to be an effort to save one > word (either a pointer or a size) per list. What are you looking at? I've been talking about Python 2.4 (as evidenced by my saying 2.4 over and over ). Its list implementation is not realloc-happy, and has both allocated-size and used-size members. The earlier leave-it-to-realloc gimmick was indeed an extreme effort to save bytes. The 2.4 implementation is simpler, clearer, faster, and better-behaved in several respects. > With two more words, I think we could make operations on both ends > amortize O(1). As before, I don't care about this. The 2.4 deque is O(1) on both ends straightforwardly and more efficiently. > The only lists for which this would be a substantial > portion are empty lists. Currently, empty lists require four > words (type_pointer, refcount, size=0, item_pointer=NULL) Plus 3 for the gc header (every list object gets one, although that's not apparent from staring at listobject.h), plus 1 (not in 2.3 but in 2.4) to store the # of allocated slots. That's a total of 8. > plus malloc's bookkeeping. The list struct is allocated via pymalloc, which allocates in 8-byte chunks with trivial overhead beyond that (just a few percent). So not even 1 bit can be added to the 2.4 list struct without losing another 8 bytes, under *most* C compilers for 32-bit machines. The Microsoft C compilers are exceptions (they stick 4 bytes of padding in the gc header, so there are 4 wasted bytes now (2.4) in the list struct under MSVC). > Any non-empty list additionally allocates space for at least 8 pointers, ... In 2.4 that's been reduced to 4. From lbates at swamisoft.com Wed Aug 18 19:54:22 2004 From: lbates at swamisoft.com (Larry Bates) Date: Wed, 18 Aug 2004 18:54:22 -0500 Subject: singleton (newbie) References: Message-ID: Neil, Three observations: 1) IMHO Python needs to be written as Python not as some other language. I've rewritten your class below: class B: x = 0 y = 1 def foo(): print B.x foo = staticmethod(foo) def bar(): print B.y B.y+=1 bar = staticmethod(bar) if __name__ == "__main__": B.foo() B.bar() B.foo() B.bar() B.bar() 2) I continue to read on c.l.p. about staticmethods and just don't understand why anyone would use them. This is how I learned to write this in Python. It seems that they are some sort of "carryover" from another language. I'd be the first to admit I don't understand the appeal, so maybe they can be useful. I've just never needed them. If I need a static function, I just write it that way. I don't make it the method of a class object. if you want x, y to be global across all instances of B: class B: x = 0 y = 1 def foo(self): print self.x def bar(self): print self.y self.y+=1 if __name__ == "__main__": b=B() b.foo() b.bar() b.foo() b.bar() b.bar() if you want x, y to be local to current instance of B: class B: def __init__(self): self.x=0 self.y=1 def foo(self): print self.x def bar(self): print self.y self.y+=1 if __name__ == "__main__": b=B() b.foo() b.bar() b.foo() b.bar() b.bar() 3) If you just want static functions, just write them that way. def foo(): global x print x def bar(): global y print y if __name__ == "__main__": x=0 y=0 foo() bar() foo() bar() bar() Maybe it will help, maybe not. Larry Bates Syscon, Inc. "Neil Zanella" wrote in message news:b68d2f19.0408181413.70f2a91b at posting.google.com... > Hello, > > Is this the correct way to code multi-instance singleton in Python? > It seems to do the trick for me but I appreciate any criticism as I > am somewhat new to Python. > > Thanks, > > Neil > > #!/usr/bin/python > > class B: > x = 0 > y = 1 > def foo(): print B.x > foo = staticmethod(foo) > def bar(): print B.y; B.y += 1 > bar = staticmethod(bar) > > if __name__ == "__main__": > B.foo() > B.bar() > B.foo() > B.bar() > B.bar() From luismg at gmx.net Tue Aug 31 03:46:35 2004 From: luismg at gmx.net (Neuruss) Date: 31 Aug 2004 00:46:35 -0700 Subject: [IronPython] Jim Hugunin's web log. References: Message-ID: <278de0e.0408302346.62cfc40b@posting.google.com> > Hugunin has said his job is to "make the CLR better for dynamic languages". > It's unclear to me that directive is synonymous with "develop IronPython > further"; he could invent his own new language and implement that, or work > with other CLR-based projects. I wouldn't conclude that Microsoft is > adopting Python as a supported tool, or even that Python is Hugunin's > primary focus, until he actually says that's his goal. I agree. I think the primary focus of Microsoft is to make the CLR the best and most attractive development platform, and a good way to achieve this is by making it more friendly to as many languages as possible, including scripting ones. That's the reason they hired Jim Hugunin. Not only to develop python for the CLR, but to improve the CLR for all the scripting languages and to investigate the best ways to implement these languages for the CLR. As for the concerns about Microsoft "hijacking" python, I think they probable go too far. We all know what MS did in the past, but this time, I think they shifted their policies drastically. There's a whole move of opening their source and submitting standards that confirm that their new strategy is stabilishing .NET as "the" platform. In this task, open source developers have an important place. Regarding Jim Hugunin, he already implied in his comments that his intentions are to impement python as close to the standard implementation as posible. He even consults Gudo regularly on this subject. And seeing what he did with Jython, there's no reason to disbelieve. From anthonybaxter at gmail.com Fri Aug 13 02:35:58 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 13 Aug 2004 16:35:58 +1000 Subject: Why I love python. In-Reply-To: References: Message-ID: On Fri, 13 Aug 2004 01:11:54 +0000 (UTC), Nick Patavalis wrote: > > Don't complicate it. Leave it as is. Work on making it faster, not > > uglier. > > Python needs drastic performance improvement if it is to scrap-off the > "scripting language" stigma. I'm biased, having done a paper on this at the most recent PyCon, but I firmly believe that much of the "Python is too slow" arguments can be answered with "too slow for what?" See the pycon proceedings, but I've been doing VoIP in Python, complete with audio mixing, and it's been more than fast enough. Another large app is a database ETL tool - Python is more than adequate for flinging around a very large number of rows of data. Indeed, it could be 4-5 times as slow, and Oracle would still be the bottleneck. Sure, you're not going to get great performance for your numerical computation in Python, but luckily, we have numarray for this. Yes, additional performance would be a nice-to-have, but I've not really found the existing interpreter's performance to be that much of a problem. I suspect that one of the many new implementations will provide us with some wins here. From grante at visi.com Tue Aug 31 16:29:25 2004 From: grante at visi.com (Grant Edwards) Date: 31 Aug 2004 20:29:25 GMT Subject: sys.stdin.readline() References: <367a4461.0408311221.30866c09@posting.google.com> Message-ID: <4134dfa5$0$8081$a1866201@newsreader.visi.com> On 2004-08-31, Mike Maxwell wrote: > When I invoke readline() in a for loop, why does it return a series of > one-char strings, rather than the full line? > >>>> for sL in sys.stdin.readline(): print sL > ... > abc > a > b > c > > (I typed in 'abc', and the loop printed out 'a\nb\nc\n') > > I.e. how can I make readline() wait for the newline before returning a > value? It is. > 'readline()' seems to be acting exactly like 'read()' here. Sort of. What you want is: import sys while True: s = sys.stdin.readline() if not s: break print s -- Grant Edwards grante Yow! .. I see TOILET at SEATS... visi.com From aleaxit at yahoo.com Thu Aug 26 09:10:38 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 15:10:38 +0200 Subject: Proposal for removing self References: <938a4680.0408252123.4d71432e@posting.google.com> Message-ID: <1gj4snz.ygxigbakcpojN%aleaxit@yahoo.com> Andrea Griffini wrote: > On 25 Aug 2004 22:23:46 -0700, rattan at cps.cmich.edu (Ishwar Rattan) > wrote: > > >I concur for keeping self intact, it does provide clarity in code writing > >and reading. > > I remember Alex Martelli advocating in our italian newsgroup on > C++ that C++ programmers should use "this->..." everywhere :-) I did that, and I did that before becoming mad with love for Python. At the time my main job was helping hundreds of other programmers debug their hairiest bugs (also helping them architect and design and test things correctly, but debugging took far more time -- there's never time to do it right so there's always time to do it over) and the lack of this-> was a major cause of problems. confusions and bugs. > Seemed crazy to me at that time, but now after giving a try > to python I've to say that self-consciousness isn't bad. If you write and debug truly complicated C++ templates you'll see why I wanted explicit this-> prefixing most ardently...;-). Alex From steveb428pleaseremovethis at hotmail.com Fri Aug 6 19:33:29 2004 From: steveb428pleaseremovethis at hotmail.com (DilbertFan) Date: Fri, 06 Aug 2004 23:33:29 GMT Subject: Paul Graham on Python hackers References: <3064b51d.0408061127.32536826@posting.google.com> Message-ID: As a whole, this is my favorite book of the last two years, and I read a lot. There hasn't yet been a chapter that I started to glaze over, most other book there is always a point where my hand started to turn the pages faster. Really good stuff wrote in message news:3064b51d.0408061127.32536826 at posting.google.com... > Paul Graham's recent book "Hackers & Painters" may be interesting > readers for Python programmers. He likes flexible languages like > Python, although Lisp is his favorite. Here is a quote from his book, > also online at http://www.paulgraham.com/gh.html , where he contrasts > Python and Java programmers. He is opinionated :). > > "When you decide what infrastructure to use for a project, you're not > just making a technical decision. You're also making a social > decision, and this may be the more important of the two. For example, > if your company wants to write some software, it might seem a prudent > choice to write it in Java. But when you choose a language, you're > also choosing a community. The programmers you'll be able to hire to > work on a Java project won't be as smart as the ones you could get to > work on a project written in Python. [2] And the quality of your > hackers probably matters more than the language you choose. Though, > frankly, the fact that good hackers prefer Python to Java should tell > you something about the relative merits of those languages. > > Business types prefer the most popular languages because they view > languages as standards. They don't want to bet the company on Betamax. > The thing about languages, though, is that they're not just standards. > If you have to move bits over a network, by all means use TCP/IP. But > a programming language isn't just a format. A programming language is > a medium of expression." From steven.bethard at gmail.com Mon Aug 16 12:49:43 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: 16 Aug 2004 09:49:43 -0700 Subject: Think you've got a new decorator syntax? Message-ID: You probably don't. ;) Here's a script that generates (almost) all of the proposals so far. Don't worry, there's only 1224 that are both not currently valid syntax and also easily greppable. ;) http://ucsu.colorado.edu/~bethard/py/decorators.py And the output (throwing away any syntaxes that were currently valid or not easily greppable): http://ucsu.colorado.edu/~bethard/py/decorators-output.py Steve From reply.in.the.newsgroup at my.address.is.invalid Wed Aug 25 18:51:55 2004 From: reply.in.the.newsgroup at my.address.is.invalid (Rene Pijlman) Date: Thu, 26 Aug 2004 00:51:55 +0200 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: Xah Lee: >I'm starting my own cult to exterminate morons on this earth. >Two things are on the top of my agenda: Unixism and Perl. What are you replacing Unix with? -- Ren? Pijlman From Scott.Daniels at Acm.Org Sun Aug 22 15:06:11 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 22 Aug 2004 12:06:11 -0700 Subject: Decorator keyword options - brainstorming In-Reply-To: References: Message-ID: <4128f067$1@nntp0.pdx.net> Peter Hansen wrote: > I think the "decorate:" option (with alternative keyword if > there's a better) is the second most Pythonic shown to date... How about "def:" as the alternative keyword? Certaily this would stand out sufficiently. -Scott David Daniels Scott.Daniels at Acm.Org From pellis.no.spam at tampabay.rr.com Fri Aug 20 22:13:14 2004 From: pellis.no.spam at tampabay.rr.com (Patrick Ellis) Date: Sat, 21 Aug 2004 02:13:14 GMT Subject: Alternative decorator syntax decision References: Message-ID: <_cyVc.48884$wM.42592@twister.tampabay.rr.com> C2, C2, J2 From jzgoda at gazeta.usun.pl Mon Aug 9 16:34:36 2004 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Mon, 9 Aug 2004 20:34:36 +0000 (UTC) Subject: decorators vs GIL References: <96c2e938.0408081605.706f8ec7@posting.google.com> Message-ID: G. S. Hayes pisze: >> What really hurts is that I can't honestly tell Java programmers that > >> Python is a slam dunk compared to Java & the JVM. Java has no GIL, > > > > Java has drunk the threads Kool-Aid, and Java programmers are very > likely to be thread-crazy because of the lack of a select equivalent > (until recently) and the lack of good access to processes via fork or > similar. Luckily, it's usually pretty easy to convince people of the > benefits of NOT overusing threads once they've made that mistake once. Try GUI programming without using threads. -- Jarek Zgoda http://jpa.berlios.de/ From Scott.Daniels at Acm.Org Thu Aug 19 11:54:16 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 19 Aug 2004 08:54:16 -0700 Subject: age of Python programmers In-Reply-To: References: Message-ID: <4124cf12$1@nntp0.pdx.net> Mark Jackson wrote: > "Lucas Raab" writes: > 55. Wrote my first program at 16 (Fortran, punch cards). Cool. I often tell people I am one of the oldest programmers they'll meet who learned young. I'm 53, and my first program was LGP-30 machine language at 15. -Scott David Daniels Scott.Daniels at Acm.Org From hamilcar at tld.always.invalid Tue Aug 10 13:31:15 2004 From: hamilcar at tld.always.invalid (Hamilcar Barca) Date: Tue, 10 Aug 2004 11:31:15 -0600 Subject: Paul Graham on Python hackers References: <3064b51d.0408061127.32536826@posting.google.com> Message-ID: <20040810133115.766$3R@news.newsreader.com> In article (Sun, 08 Aug 2004 03:10:32 +0200), Baalbek wrote: > beliavsky at aol.com wrote: >> also choosing a community. The programmers you'll be able to hire to >> work on a Java project won't be as smart as the ones you could get to >> work on a project written in Python. [2] And the quality of your > > I prefer Java and Python alike, I simply love those two languages..... It's my experience that the more "buzz" a language gets, the more programmers want to use it. In the case of Java, and especially Visual Basic, this tends to lower the average quality of programmers using the language. > So, am I smart, or not as smart? I'm betting it's one or the other. > What a stupid assertion to make; this Paul Graham has just proven > himself to be an ass......... Not. From mmccrack at ucsd.edu Wed Aug 4 16:54:22 2004 From: mmccrack at ucsd.edu (Michael McCracken) Date: Wed, 04 Aug 2004 13:54:22 -0700 Subject: help: Unit test fixture returning the same object References: <9895e897.0408031533.26720ba0@posting.google.com> <9895e897.0408040851.21ac7caa@posting.google.com> Message-ID: In article , Peter Otten <__peter__ at web.de> wrote: > Michael McCracken wrote: > > > I managed to fix my problem, but I don't understand why the fix works > > yet, so I'm not quite satisfied. > > [...] > > > class Block: > > def __init__(self, name, preds = [], succs = []): > > Heureka! Providing mutables as default values is a well-known pitfall. > > http://www.python.org/doc/faq/general.html#why-are-default-values-shared-betwe > en-objects > Oh, excellent - thanks for the pointer. Time to read the rest of the FAQ. :) -mike From aleaxit at yahoo.com Fri Aug 27 13:37:43 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 27 Aug 2004 19:37:43 +0200 Subject: Proposal for removing self References: <1gj65zl.1cuz9ub5xyo3rN%aleaxit@yahoo.com> Message-ID: <1gj6zjl.hlg90j1bqe59nN%aleaxit@yahoo.com> Dave Benjamin wrote: ... > > While it's also a good idea in Java, it's not as compelling as in C++, > > because Java mostly lacks the complications due to C++'s templates and > > freestanding ("not inside a class") names (haven't looked at Java > > generics so I don't know if they got those complications back in;-). > > Java's generics aren't nearly as liberal as C++ templates. They're basically > just syntax sugar for casting, so I doubt this would change much. I still > prefer the explicit "this." or "self.", mainly because it is a pattern that > I can use consistently across all of the languages I regularly program in > (JavaScript and ActionScript, like Python, make "this" mandatory as well). Hmmm, yes, you have a point _in a multilanguage perspective_. Unfortunately most programmers appear to dislike the concept of being fluent across several languages. > That said, if an existing C++ or Java code base uses prefixes for all > instance variables, it's a bit redundant to add "this.". I have this > situation at my work, where I reluctantly have to make an exception to avoid > pissing people off. ;) Prefix naming is the norm, but I fail to see why 'member_foo' or 'my_foo' should be considered better than 'self.foo'. Sure, if you work with an existing body of code it's generally better to follow its conventions, otherwise your modifications stand out like a sore thumb. Alex From casey at zope.com Mon Aug 9 15:23:36 2004 From: casey at zope.com (Casey Duncan) Date: Mon, 9 Aug 2004 15:23:36 -0400 Subject: Exceptions as a Control Structure References: <411775aa$0$17867$626a14ce@news.free.fr> Message-ID: <20040809152336.148cee85.casey@zope.com> On Mon, 09 Aug 2004 15:01:38 +0200 Olivier Parisy wrote: > Hi all, > > I am new to Python (I just finished Guido's tutorial). > I was very surprised to learn there that the StopIteration > is used to end for loops in a standard iterator setting. > > I come from C++, where the use of exceptions as control > structures is frowned upon for efficiency reasons. > > What is the Python canon on this topic ? Are exceptions > considered as reasonable control structures, or is > StopIteration alone of its kind ? Actually StopIteration is a semantic peer of the long standing IndexError and KeyError exceptions used in sequences and dicts. In general I think you will find python uses exceptions often for flow control. The try: except: block is more or less free if no exception actually occurs. -Casey From bingham at cenix-bioscience.com Tue Aug 31 05:36:08 2004 From: bingham at cenix-bioscience.com (Aaron Bingham) Date: Tue, 31 Aug 2004 11:36:08 +0200 Subject: File System In-Reply-To: <10j7r3cflo61680@corp.supernews.com> References: <10j7r3cflo61680@corp.supernews.com> Message-ID: <41344688.2090002@cenix-bioscience.com> Hello Maboroshi, You are not the first to think that there might be an alternative to the filesystem. Here are a few links to sites for projects where filesystems have been rethought or eliminated in very different ways. Most of this is unfortunately vaporware. This is by no means a complete list: Xanadu http://www.xanadu.com http://www.udanax.com http://www.sunless-sea.net Fenfire http://www.nongnu.org/fenfire/ Lifestreams http://www.cs.yale.edu/homes/freeman/lifestreams.html EROS http://www.eros-os.org Tunes http://tunes.org Maboroshi wrote: > <>Hi I was curious > > I was interested in finding out from Programmers and Computer Users - If > they were to completely rebuild there Computers Filing System How would it > work > > I believe since the advent of the PC we have been brainwashed (In a Sense > cause nothings really Changed ( at least as far as I know ) to have a > filesystem that is structured in this way Open a Folder open its contents > open another folder open its contents open a file move a file delete a > file > move a folder delete a folder you get the idea > > I believe this structure is much like an array or a multidimensional array > if you were to put it in that respect > > Question: > are most (if not all) databases like this > > I believe there is a better way and I want to find it I also believe if > there is a better way it could totally change our approach to programming > > I know this isn't neccessarily a python question but it has to do with > future research that will benefit the Python Language plus I like to hear > the opinions of the Python Community which I have a lot of respect for > > Cheers > > Maboroshi -- -------------------------------------------------------------------- Aaron Bingham Application Developer Cenix BioScience GmbH <>-------------------------------------------------------------------- From eq at eq.homelinux.org Fri Aug 20 06:10:22 2004 From: eq at eq.homelinux.org (eq) Date: Fri, 20 Aug 2004 12:10:22 +0200 Subject: problem using C-bindings References: Message-ID: Am Thu, 19 Aug 2004 19:21:31 -0400 schrieb Jack Diederich: > On Fri, Aug 20, 2004 at 12:14:05AM +0200, eq wrote: >> Am Thu, 19 Aug 2004 17:45:45 -0400 schrieb Jack Diederich: >> >> > On Thu, Aug 19, 2004 at 10:32:15PM +0200, eq wrote: >> >> Hi, >> >> >> >> I'm trying to create a program(written in C) that does the following >> >> things using embedded Python: >> >> 1. Create a module(say, "MyModule") >> >> 2. Create a class in that module(say, "MyClass") >> >> 3. Create a function in that module(say, "MyFunction") >> > [snip] >> >> class_dict=PyDict_New(); >> >> class_name=PyString_FromString("MyClass"); >> >> class=PyClass_New(NULL,class_dict,class_name); >> >> PyDict_SetItemString(module_dict,"MyClass",class); >> > [snip] >> > >> > Take a look at Modules/xxsubtype.c in the source distribution. >> > It is an example of how to subtype a builtin. xxmodule.c shows >> > how to make a class from scratch. Both are out of date but a good >> > sarting spot. >> > >> Hm, perhaps I over-complicated my problem: >> I don't need a full python-class in pure C. I just need to create a >> (python!) function(a dynamic one, not a static C function) and attach it >> to an already existing python-class just by using C-calls. >> I try to do this by compiling the function's code with: >> >> pyfunc_code=Py_CompileString(func_code,"",Py_file_input); >> >> where func_code could be something like "print 'hello'" and then I try to >> make a function out of this by calling: >> >> pyfunc=PyFunction_New(pyfunc_code,dict); >> >> where dict is the global namespace for the function. >> What I now want is to attach this function to the already created class >> "MyClass". >> > > In that case I would see how xxmodule.c exports methods in the xx_methods > array and then in your python code have the class method call that exported > method. That's not the point, the problem is that no example i've found(including the xx_* files) shows how to create a python function from C-code. To make the thing worse, there's also no example how to add such a function to a class by using C code. The xx_* files only create static C methods what is not what I want. > > import xxmodule > class MyClass(object): > def xxfunc(self, arg): > return xxmodule.xxfunc(self.someval, arg) > > In practice I've never had a class that wasn't all python or all C but > I have written small helper functions in C that are called from python. > > -Jack From del at mjclift.freeserve.co.uk Fri Aug 13 23:05:07 2004 From: del at mjclift.freeserve.co.uk (Calvin79) Date: Fri, 13 Aug 2004 23:05:07 -0400 Subject: control direction of list References: <2f2afc89dae36a5a8b23a0f3e623a333@localhost.talkaboutprogramming.com> Message-ID: Bounce Anyone able to help? From npat at efault.net Fri Aug 13 14:16:37 2004 From: npat at efault.net (Nick Patavalis) Date: Fri, 13 Aug 2004 18:16:37 +0000 (UTC) Subject: Why I love python. References: Message-ID: On 2004-08-13, Dave Brueck wrote: > > Yes. Apache is not that fast, and web servers are often more network > bound than CPU bound. > We 're obviously interested in cases where the problem is CPU-bound. In a network-bound server, there is no *meaning* in speaking about performance (with respect to the implementation language). > Nobody is arguing that Python is as fast as C. But being slower does > not imply that Python is unsuitable for those tasks. I'd consider > your list to be pretty atypical of normal development (how many TCP > stacks and relational databases need to get written each year?), I also mentioned web-browsers, ray-tracers, circuit-simulators. I could add word-processor, spreadsheets, video editing programs, and GUI toolkits to the list. Are they still too exotic? To cut the thread short, what I mean is that an application that has to do something like: for i in range(N): a[i] = b[i] + c[i] is bound to be 10 to 100 times slower than the equivalent coded in C. Which means that the cost of doing *computation* in Python is prohibitively high! Have you ever seen, say, an AVL-tree implementation in production Python code? Probably not. Have you ever seen someone implementing some sort of string-lookup algorithm in Python (instead of using the build-in dictionaries)? Again no. Is it because Python has found the "one-size-fits-all", "best-algorithm-ever-devised" solution? Or is it because the weight of the language itself is such that even a suboptimal algorithm implemented in C will never be matched by a python implementation? The very fact that the python interpreter itself in implemented in C (and not in Python) is indicative. > > Note also that all or most of those programs on your last at one time > had to be partially implemented in assembly language even if the main > language was C or C++, and yet that didn't make C or C++ unsuitable > development languages for the task (nor did it make them only "glue > languages"). > No, but the performance difference between C and Assembly was *small*. And at some point the C compilers became so good, that you couldn't beat them by hand coding something (of considerable length) in assembly. As for C++, one of its primary design-goals were "zero unneeded overhead"; so it *is* possible to write a C++ program that is as fast as a C program, if you want to do it. > The same can hold true for Python in many cases - if a small portion > needs to be developed in a lower-level language you can still derive > great benefit from doing the rest of the application in Python. Of course you can! Nobody argued that Python is useless. Python is one of the cleanest, most pleasant, and most productive languages one could wish for. For me it would not be an exaggeration to say that Python has brought a lot of fun back in programming (and in many ways). The reason I'm writing this is that *I also* hate to see it pigeon-holed as a "glue" or "scripting" language. Our difference, I guess, is that I believe that there is *some* truth in such missives; and this has to do with the current, immature, state of the Python *environments*. So my point is that we should not relax in the cozy feeling that "Python is great for most applications, even if it's a little slow, but who cares". I want to be able to write signal processing functions in Python, or implement that optimized special-case search algorithm, and I want to be sure that---by guiding the compiler properly---it will produce code that is as efficient as a well-written C program, or hand-coded assembly (or at least close to that). I want the next GUI toolkit I use to be written in Python (instead of written in C++ and simply wrapped in Python). And I believe that this *is* possible, provided that we don't ignore all the years that have been spent advancing compiler technology, and that we don't treat the current Python environments as the "end of the line". CPython is a good proof that Python works, and that it is a great language. For Python to become a "primary" language, there's still much work to be done. Most of this work, as I said before, has to do with the environments (interpreters, AOT/JIT compilers, optimizers, runtime modules, etc). But some of it has to do with ensuring---at the language level---that efficient environments are possible. Considering CPython and Python one and the same leads straight to a Perl-ish hell! /npat From __peter__ at web.de Tue Aug 17 06:57:29 2004 From: __peter__ at web.de (Peter Otten) Date: Tue, 17 Aug 2004 12:57:29 +0200 Subject: Newbie 1st program References: Message-ID: Nick Jacobson wrote: > d = dict(zip(range(10), ary)) Magic constants are evil. The above will not (automatically) remain correct when new items are added to ary. Therefore: d = dict(enumerate(ary)) > i = event.GetInt() > if i in range(10): Make the above line if i in d: instead. Faster and more robust against changes elsewhere (no need for consecutive integer keys). You wouldn't want to teach a newbie bad habits, would you :-) Peter From __peter__ at web.de Sun Aug 1 03:45:00 2004 From: __peter__ at web.de (Peter Otten) Date: Sun, 01 Aug 2004 09:45:00 +0200 Subject: glob.glob unicode bug or feature References: <9418be08.0407310712.5ee65904@posting.google.com> Message-ID: Neil Hodgson wrote: >> if not dirname: >> dirname = type(dirname)(os.curdir) > > This didn't work for me as os.curdir has already been added in the call > to glob1. Instead, for Python 2.3, also changing line 22 inside glob() to > > return glob1(type(dirname)(os.curdir), basename) > > worked. I should have tried before posting. Now you point it out it seems I've changed a piece of dead code. Or am I missing something ...again? Peter From anthonybaxter at gmail.com Wed Aug 25 13:23:59 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Thu, 26 Aug 2004 03:23:59 +1000 Subject: Is it a bug (or a feature)? In-Reply-To: References: Message-ID: This looks like a bug. Please open a bug on SF, with the example code. From ptmcg at austin.rr._bogus_.com Wed Aug 11 12:58:11 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Wed, 11 Aug 2004 16:58:11 GMT Subject: A decorator syntax not yet mentioned (I think!) References: Message-ID: "Peter Hansen" wrote in message news:PcGdnQAV7olvoIfcRVn-ig at powergate.ca... > > class Klass: > # init set > > decorate: > staticmethod > def meth0(x): > return x > BEAUTIFUL!!! Looks very Pythonic. This is the first prefix syntax proposal I've seen that looks to address all of the technical and esthetic objections. And NO magic punctuation - hooray! -- Paul From vonehr at ipm.fhg.de Tue Aug 10 09:37:02 2004 From: vonehr at ipm.fhg.de (Markus von Ehr) Date: Tue, 10 Aug 2004 15:37:02 +0200 Subject: flicker in wxBufferedPaintDC Message-ID: Hi, I actualize a buffer in an event handler routine: if BUFFERED: # If doing buffered drawing, create the buffered DC, giving it # it a real DC to blit to when done. cdc = wxClientDC(self) dc = wxBufferedDC(cdc, self.buffer) dc.BeginDrawing() if self.image: dc.DrawBitmap(self.image.ConvertToBitmap(), 0,0) dc.EndDrawing() and paint the buffer in the OnPaint method. def OnPaint(self, event): if BUFFERED: # Create a buffered paint DC. It will create the real # wxPaintDC and then blit the bitmap to it when dc is # deleted. Since we don't need to draw anything else # here that's all there is to it. dc = wxBufferedPaintDC(self, self.buffer) else: dc = wxPaintDC(self) # since we're not buffering in this case, we have to # paint the whole window, potentially very time consuming. self.DoDrawing(dc) but the window is flickering. The window displays the liveimage of a connected camera. How could I get rid of the flickering? Thanks for any hints, Markus From opengeometry at yahoo.ca Mon Aug 2 04:22:56 2004 From: opengeometry at yahoo.ca (William Park) Date: 2 Aug 2004 08:22:56 GMT Subject: (patch for Bash) list comprehension and filtering Message-ID: <2n6buvFt0c2oU2@uni-berlin.de> 1. Here is shell version of Python filter() for array. Essentially, you apply a command on each array element, and extract only those elements which it returns success (0). This is specialized form of list comprehension where you can contruct an array from another array, using some sort of test or filtering. Usage is arrayfilter [-a var] command array where 'command' is a function, shell script, or external executable, which takes one argument (ie. the array elements). If 'command' return success (0), then print the element; and, if it fails (non-zero), then skip the element. If -a option is given, then the output will be save into array variable 'var', instead of default stdout. For example, a=(1 a 2 b 3 c) func () { [[ $1 == [a-z] ]]; } arrayfilter func a --> a b c arrayfilter -a b func a --> b[1]=a b[3]=b b[5]=c 2. More generally, here is shell version of Python list comprehension. Idea is to apply some test or command on each array element, and collect the outputs as parameter expansion. So, for each element of array variable 'var', ${var| command } will expand to the output of 'command' which takes one argument. If 'command' returns NULL, then that element is skipped. Usage is very similar to other parameter expansion, and both '*' and '@' work as expected. For example, a=(1 a 2 b 3 c) func () { [[ $1 == [a-z] ]] && echo ".$1."; } func x --> .x. ${a[*]| func } --> .a. .b. .d. Ref: http://freshmeat.net/projects/bashdiff/ http://home.eol.ca/~parkw/index.html#bash help arrayfilter help '${var|' -- William Park, Open Geometry Consulting, Toronto, Ontario, Canada From AntiVir at yalta.us Thu Aug 12 00:19:20 2004 From: AntiVir at yalta.us (AntiVir at yalta.us) Date: Thu, 12 Aug 2004 07:19:20 +0300 Subject: AntiVir ALERT [mail from: "Returned mail" ] Message-ID: <200408120419.i7C4JKqM011348@yalta.us> * * * * * * * * * * * * * * * AntiVir ALERT * * * * * * * * * * * * * * * ????????? ????????? ????? ? ??????????????, ??????? ????????? ????? ??????! ???????????: "Returned mail" ???????? ??????: Worm/Mydoom.m ????? ?? ???? ?????????? ??????????. ? ?????????; ???????? ???????? ???.: +38(0654)271828 ????.: +38(0654)231094 web: www.yaltainfo.com email: support at yalta.us Mail-Info: --8<-- From: "Returned mail" To: python-list at python.org Date: Thu, 12 Aug 2004 04:17:59 +0300 Subject: Returned mail: Data format error --8<-- This version of AntiVir is licensed for private and non-commercial use. -- AntiVir for UNIX Copyright (C) 1994-2003 by H+BEDV Datentechnik GmbH. All rights reserved. For more information see http://www.antivir.de/ or http://www.hbedv.com/ From ej Sun Aug 15 22:42:15 2004 From: ej (Erik Johnson) Date: Sun, 15 Aug 2004 20:42:15 -0600 Subject: os.system(), HTTPServer, and finishing HTTP requests Message-ID: <41201e06@nntp.zianet.com> Hi, I am trying to spawn a daemon type program to go off on its own and do some work (asynchoronously) from within an HTTPServer, but I am running into a problem where the web browser (actually a Perl LWP program) still seems to be waiting for more input until the child that is forked in the server finishes (granchild, actually). I don't understand this. I need to be able to have the POST to the server complete and go on even though there is a (grand)child process still running. So... that's the short summary, more specific code follows.. worker.py is a program that does the standard double-fork paradigm, allowing the original parent to return and leaving an orphaned child behind to do its own thing. If you call this program directly through the shell, it returns you immediately to your shell, which is just like what I want and would expect: #! /usr/bin/python """ worker.py """ import sys, os, time t = 30 pid = os.fork() if (pid == 0): # child: fork() again and exit so that the original # parent is not left waiting on us. pid = os.fork() if (pid > 0): # child print "child (PID %d): forked grandchild %d. I'm exiting." %\ (os.getpid(), pid) sys.exit() # grandchild continues here, drops out bottom of if-block elif (pid > 0): # parent: exit so caller can continue p_pid = os.getpid() print "parent (PID %d): forked child %d. ." % (p_pid, pid) (c_pid, status) = os.wait() print "parent (PID %d): child %d is done. I'm exiting." % (p_pid, c_pid) sys.exit() # normal exit # grandchild continues here - my worker process g_pid = os.getpid() s = "grandchild (PID %d): going to sleep for %d seconds..." % (g_pid, t) print s # pretend to do some work time.sleep(t) # done print "grandchild (PID %d) waking up... exiting." % g_pid Here is sample output from running worker.py: ej at sand:~/src/python/problem> worker.py grandchild (PID 9697): going to sleep for 30 seconds... child (PID 9696): forked grandchild 9697. I'm exiting. parent (PID 9695): forked child 9696. . parent (PID 9695): child 9696 is done. I'm exiting. ej at sand:~/src/python/problem> and then about 30 sec later, after getting back to my shell, my console prints: grandchild (PID 9697) waking up... exiting. This is all fine and dandy. One step removed from that is to call this program from another Python program via os.system(). It too exits immediately and returns me to the shell even though my (grand)child process is still running. Again, this is just what I want and expect. Here is the code for that program: #! /usr/bin/python """ call_worker.py """ import os, sys PROG_NAME = sys.argv[0] print PROG_NAME + ": calling worker.py..." os.system('worker.py') print PROG_NAME + ": all done. exiting." Here is the output from running it (again, all fine and dandy): ej at sand:~/src/python/problem> call_worker.py ./call_worker.py: calling worker.py... grandchild (PID 9710): going to sleep for 30 seconds... child (PID 9709): forked grandchild 9710. I'm exiting. parent (PID 9708): forked child 9709. . parent (PID 9708): child 9709 is done. I'm exiting. ./call_worker.py: all done. exiting. ej at sand:~/src/python/problem> and after 30 seconds, your again-active shell window should print: grandchild (PID 9710) waking up... exiting. But if I make this same os.system() call from within my own HTTPServer, then the browser that is making the request is left hanging until that sleeping grandchild is done. It's like there is still a socket connection between it and my browser?!? But the grandchild is not forked from the server - it's an os.system() call! It should not be inherting any file descriptors and such, right? Even though the do_GET() function should be over, and in fact, you can see in the shell that started the server that the server process has already exited, the browser is apparently still waiting for the web page to finish loading. I don't get it! I have a long task I need to instantiate in my Python server based on info in the HTTP POST, and the program that is making that POST needs to be able to go on and do other stuff before my task is over. Why am I not getting a clean exit in my POSTing process? What do I need to do to get my HTTP request to my server to finish essentially "immediately"? Thanks for taking the time to read my post. Any help greatly appreciated! :) -ej Below is the code for a simple server you can run. It is currently coded to listen on port 5238 and only serve one request before the server exits. It serves a little static chunk of HTML on a GET request regardless of what PATH you call (I talked about POST above, but the browser-hanging behaviour is the same). #! /usr/bin/python """ server.py """ from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler import os, sys SERVER_PORT = 5238 # arbitrary port not in use (open on firewall?) WORKER = 'worker.py' # name of the program to call via os.system() PROG = sys.argv[0] # name of this program #======================================================================= class RequestHandler(BaseHTTPRequestHandler): #------------------------------------------------------------------- def do_GET(self): # call my "daemon" to get some stuff done in the background print "%s: about to call os.system(%s)" % (PROG, WORKER) os.system(WORKER) print "%s: back from os.system(%s)" % (PROG, WORKER) # send HTTP headers self.send_response(200) self.send_header("Content-type", 'text/html'); self.end_headers() # start HTML output html = """\

    All done!

    """ self.wfile.write(html) #------------------------------------------------------------------- #======================================================================= # BEGIN main if (__name__ == '__main__'): # create a new HTTP server and handle a request server = HTTPServer(('', SERVER_PORT), RequestHandler) server.handle_request() From exarkun at divmod.com Wed Aug 4 12:23:09 2004 From: exarkun at divmod.com (Jp Calderone) Date: Wed, 04 Aug 2004 12:23:09 -0400 Subject: Perl's Crypt::PasswdMD5 In-Reply-To: References: Message-ID: <41110D6D.4000901@divmod.com> Bart Nessux wrote: > Does Python have anything similar to Perl's Crypt::PasswdMD5??? > > I read about the crypt module... but it only does DES. Any plans to add > md5 or other digests to it in the future? >>> import crypt >>> crypt.crypt('foo bar', '$1$salt') '$1$salt$LAwA5cAKtcsGTJGx.bMTC1' >>> I forget the algorithm used to determine 'salt', but I'm sure it's straightforward and well documented. Jp From newsgroups at jhrothjr.com Fri Aug 6 17:34:44 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 6 Aug 2004 17:34:44 -0400 Subject: @decorators References: <10h73e5kh1et536@news.supernews.com> <4113e5be@nntp.zianet.com><10h7qlg5adbfj86@news.supernews.com> Message-ID: <10h7ucadv3tnrb0@news.supernews.com> "Tim Peters" wrote in message news:mailman.1314.1091827156.5135.python-list at python.org... > [John Roth] > > ... > > Since I wrote that, I managed to read the new, improved > > and rewritten PEP, and discovered that the new syntax > > doesn't allow parameters. > > It does. What it says is "arbitrary expressions will not work", and I > would agree that's vague if you insisted it was . What it means > is that parameters are fine, but things like > > @list_of_decorators[index] > @eatme and deco1 or deco2 > @random.choice([deco1, deco2, deco3]) > > are right out. Note that the PEP still contains examples of > decorators with arguments, and the people who want decorators most > need them to accept arguments. OK. I sit corrected. John Roth From jdhunter at ace.bsd.uchicago.edu Thu Aug 12 09:17:39 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Thu, 12 Aug 2004 08:17:39 -0500 Subject: Python script to generate static site? In-Reply-To: (Fred's message of "Thu, 12 Aug 2004 00:03:23 +0200") References: Message-ID: >>>>> "Fred" == Fred writes: Fred> Hi, I'm sure there are a bunch of them, but googling just Fred> returned full-fledged CMS that require a DBMS and generate Fred> dynamic pages. Fred> I'd just like a script that would 1. look in a directory for Fred> articles in raw HTML, 2. generate a cooked output for each Fred> page (ie. add header and footer, CSS link in HEAD, etc.), Fred> 3. regenerate the homepage with "Last modified" bit Fred> following each article's title, 4. ready to be uploaded by Fred> FTP to a web server that only handles static web pages. Fred> Considering Python's wealth of libraries, it's most likely Fred> only a couple hours' work, but since I'm pretty much a Fred> Python newbie... yaptu is python templating code (79 lines long!). I use it to (statically) generate the entire matplotlib web site - http://matplotlib.sourceforge.net. This includes parsing pydoc output to embed it into the web site navigation tables, adding headers / footers, etc. I think it's great - it's really easy to mix python & html see http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52305. If you want more extensive examples, look in the *.html.template files of the htdocs subdirectory of a matplotlib cvs checkout. JDH From dbickett at gmail.com Tue Aug 17 23:04:16 2004 From: dbickett at gmail.com (Beeyah) Date: 17 Aug 2004 20:04:16 -0700 Subject: how to change the text in the title bar of the Tkinter windows References: <8f17f4bc.0408151822.1be2de2e@posting.google.com> <8f17f4bc.0408171417.456199d1@posting.google.com> Message-ID: <1d6cdae3.0408171904.7c625d81@posting.google.com> alikakakhel3 at hotmail.com (Ali) wrote in message news:<8f17f4bc.0408171417.456199d1 at posting.google.com>... > Eric Brunel wrote in message news:... > > Ali wrote: > > > When I open a window using the Tkinter GUI thing the title bar always > > > says "Tk". I would like to know how to change this. I would also like > > > to know how to cjange it on any other popup windows I may have. Please > > > help. > > > > Just use the 'title' method on your windows. See paragraph 45 in > > http://www.pythonware.com/library/tkinter/introduction/index.htm > > > > HTH > > I looked at the website but I did not understand. > > Um.... is this right? It is supposed to show a window with the > titlebar showing The Title. > > from Tkinter import * > > root = Tk() > > root.title("The Title") > > root.mainloop() Yes, that's correct. From anthonybaxter at gmail.com Fri Aug 13 02:57:49 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 13 Aug 2004 16:57:49 +1000 Subject: The winner of the Python Decorator Poll is... In-Reply-To: <59e9fd3a04081122235b3d9145@mail.gmail.com> References: <4edc17eb.0408112052.1bbd85b3@posting.google.com> <59e9fd3a04081122235b3d9145@mail.gmail.com> Message-ID: On Thu, 12 Aug 2004 15:23:22 +1000, Andrew Durdin wrote: > Since you like the current proposal, why *didn't* you vote for it (it > was the first one)? I didn't vote, because voting is a stupid way to design a language. From steven.bethard at gmail.com Fri Aug 27 00:52:50 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Fri, 27 Aug 2004 04:52:50 +0000 (UTC) Subject: Proposal for removing self References: <338366A6D2E2CA4C9DAEAE652E12A1DE01DCFB9C@au3010avexu1.global.avaya.com> Message-ID: Delaney, Timothy C (Timothy avaya.com> writes: > I evangelise this here (mainly for Java code these days, but close > enough). Unfortunately, I don't seem to be able to convince anyone else > :( I had to work in Java over the summer, and I started using 'this.' for all instance variables. Found it much easier to read my code when I went back to it later. (Of course, I was prompted by Python's syntax, but the real motivator was reading someone else's code and having to hunt down their instance variables to figure out what was going on...) Steve From mwh at python.net Thu Aug 5 08:11:41 2004 From: mwh at python.net (Michael Hudson) Date: Thu, 5 Aug 2004 12:11:41 GMT Subject: on the fly document generation References: Message-ID: Ajay writes: > hi! > > i generate a document on the fly and then print it from my script. to force > the browser to show the 'save file' dialog rather than display the content > in the browser, i have added the header Content-Type > print "Content-Type: application\n" > however when the save file dialog box comes up, it gives the script name > (in this case sfile.cgi) as the filename. how can i change that to a > different filename? > > print "Content-Type: application; name="test.xml\n" I think it's Content-Disposition: you're after. ISTR it has some insane format I can't remember. > sorry its a little off-topic I'd say! Cheers, mwh -- Enlightenment is probably antithetical to impatience. -- Erik Naggum, comp.lang.lisp From irmen at -nospam-remove-this-xs4all.nl Mon Aug 2 06:09:01 2004 From: irmen at -nospam-remove-this-xs4all.nl (Irmen de Jong) Date: Mon, 02 Aug 2004 12:09:01 +0200 Subject: Sets Module Bug? In-Reply-To: References: Message-ID: <410e12bc$0$48959$e4fe514c@news.xs4all.nl> Chris S. wrote: > >>> from sets import * > >>> Set((1,2,3)) > Set([1, 2, 3]) > >>> Set([1,2,3]) > Set([1, 2, 3]) > >>> Set(([1,2,3],[4,5,6])) > Traceback (most recent call last): > File "", line 1, in ? > File "sets.py", line 399, in __init__ > self._update(iterable) > File "sets.py", line 344, in _update > data[element] = value > TypeError: list objects are unhashable > > How can a Set using a tuple or list be ok, but not a tuple of lists? Because "list objects are unhashable", as Python told you :-) AFAIK the sets module is built upon the dict type, it uses (requires) the elements of the set to be hashable for efficient containment tests. The library reference of the sets module also says: "All of the elements in iterable should be immutable or be transformable to an immutable using the protocol described in section 5.13.3. " --Irmen From ajsiegel at optonline.com Sat Aug 28 10:43:12 2004 From: ajsiegel at optonline.com (Arthur) Date: Sat, 28 Aug 2004 14:43:12 GMT Subject: Question about references/copies References: <1gj870c.dzzhcpvby7ozN%aleaxit@yahoo.com> <1gj8k1n.1vm9nm4y4avw0N%aleaxit@yahoo.com> Message-ID: On Sat, 28 Aug 2004 16:02:59 +0200, aleaxit at yahoo.com (Alex Martelli) wrote: >Arthur wrote: > ... >> I've felt strongly that this key piece of Python learning would be >> and much, much more inevitable if there was a (preferred) consistent >> way to ask for a copy, across objects - > >There is: type(obj)(obj) is (almost) always the best way to get a >(shallow) copy of copyable objects (won't work with noncopyables such as >files and other iterators, of course) of built-in types (whether >user-coded types support that popular convention is of course another >issue -- it depend on the author of each of these types). >If you know what type obj is, say a list; or, if don't really care >whether obj is (say) a list or a tuple or ... 'cause what you want is a >list anyway, then the normal way to spell this is of course list(obj). Well there is a lot of divergence in practice, as I think you know. And beyond that no real consensus on what is preferable, as far as I have been able to determnine Though hearing Alex declare it as preferable is the beginning of the formation of some consensus, one hopes. > >> and/or that the copy module >> was something other than one of XXX importable moudles. > >Well, it's Python-coded, so it seems quite natural to me that it be a >perfectly normal importable module. I understand, now, the problems with treating the copy module otherwise than it is. But it is a strange duck - conceptually in the middle of things, but with limited functional importance. I thought only that Ray's idea of setting it off a bit, by mention in the tutorial, had considerable merit. > > >> That dicts and lists (for example) have totally different syntax for >> copy, helps - I promise - to misdirect and confuse. I happen to > >dict(mydict) and list(mylist) appear quite similar to me. Sure, >mydict.copy() has stuck around from the dark ages and won't be even >considered for removal, due to backwards compatibility, until Python 3.0 >some years from now; and mylist[:] also builds a shallow copy; but >despite their undeserved popularity these are not "the syntax for copy" >in my book, any more than, say, dict(mydict.iteritems()) for a dict or >[x for x in mylist] for a list, even though THOSE happen to make shallow >copies too (and I HAVE seen them used in code intended as "serious"). I agree that dict(mydict) and list(mylist) - it that is what one saw with consitentcy in practice - would go a long way. I'll try to practice it, having gotten into the list[:] habit. And ... It was my understanding - perhaps wrong - that dict.copy() was an add-on method to dict of non-ancient origin. How do I check? > >> consider this entire area a significant wart. I think I am entitled to >> consider it so. > >Given the apparent dearth of information in the matter, you may be >right. I'll do my best to keep clarifying my viewpoint in my books... That would be excellant! ARt From dd55 at cornell.edu Mon Aug 2 20:52:33 2004 From: dd55 at cornell.edu (Darren Dale) Date: Mon, 02 Aug 2004 20:52:33 -0400 Subject: file IO Message-ID: Can anyone explain this? I have a file called old.dat with two lines: 1 2 So it's 3 bytes long. I run the following: import os f = file('old.dat',mode='r') olddata = f.readlines() f.close() f = file('new.dat',mode='w') f.writelines(olddata) f.close() new.dat is now 4 bytes long. ??? I need to reformat and then save some data. Then I need to be able to export the reformatted data to a spreadsheet-friendly format. But once I have simply copied (trying to isolate the problem) the file using the script above, my export function takes 10x as long as it would have with the original file. And worse, the output has an extra newline character added at the end of each line. Any suggestions would really be appreciated, I am going a bit crazy trying to understand this. Darren From jeff at ccvcorp.com Thu Aug 26 15:24:37 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Thu, 26 Aug 2004 12:24:37 -0700 Subject: A little curious about something.. In-Reply-To: References: Message-ID: <10ise6kf99o1hfa@corp.supernews.com> Player wrote: >However with the Idle version in python, the GUI and python it's self loads >allot slower, and if I do the same click-hold to reposition the idle GUI >window, it chugs and stutters across the screen as I move it, rather slowly >and no were near as smoothly and fluidly as the Activestates version of the >Idle GUI window. > > I'm just guessing here, but the ActiveState IDE, PythonWin, uses native Windows widgets from Python, while IDLE uses Tk widgets inside a TCL interpreter which is controlled from Python. This means that IDLE has an extra layer or two of indirection. (And, while I'm sure that TCL is a great language within its intended problem domain, I don't believe that execution speed has been any sort of priority in its development...) Jeff Shannon Technician/Programmer Credit International From detlev at die-offenbachs.de Tue Aug 10 14:00:22 2004 From: detlev at die-offenbachs.de (Detlev Offenbach) Date: Tue, 10 Aug 2004 20:00:22 +0200 Subject: Popular Python projects with lots of pure Python code References: Message-ID: <82fnu1-7h3.ln1@stargate.solsys.priv> Brett C. wrote: > For my thesis (once the bloody thing stops throwing bugs at me) I am > going to need to collect stats on the frequency that atomic types in > local variables are applied to various opcodes and methods. That means > that I need something to collect stats off of. > > So I am trying to come up with a list of projects I can use to get my > stats from. the stdlib is a no-brainer. Also plan to use Docutils. > But beyond those most of the big Python projects I can think of have a > ton of C code which is of no use to me. I don't need to be able to run > it, just going to be compiling to .py files. > > Any suggestions? > > -Brett How about eric3 (http://www.die-offenbachs.de/detlev/eric3.html). It has about 50 klines of code. Detlev -- Detlev Offenbach detlev at die-offenbachs.de From squirrel at WPI.EDU Mon Aug 16 13:53:30 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Mon, 16 Aug 2004 13:53:30 -0400 Subject: Numarray: Using sum() within functions In-Reply-To: <10hsvoka533ci3c@corp.supernews.com> References: <10hsvoka533ci3c@corp.supernews.com> Message-ID: On Sat, 14 Aug 2004, Jim Cser wrote: > I have a function to generate a multi-dimensional array, which then > gets summed over one axis. The problem is that the dimensions > are large, and I run out of memory when I create the entire array, > so I'm trying to do the sum *within* the function. > > Example-- variables x,y,z,t; dimensions numX, numY, numZ, numT; > functions f1(x,y,z,t), f2(y,z,t); want to calculate f1*f2 and > sum over t to get out[x,y,z]. Would something like the following work? def f3(x, y, z, t=arange(numT)): return sum(f1(x,y,z,t)*f2(y,z,t)) This assumes that f1() and f2() can operate on array objects. If not, the following (much slower) method should work: def f3(x, y, z): return sum(fromfunction(lambda t: f1(x,y,z,t)*f2(y,z,t),(numT,))) To make the output matrix, you could use either this: out = fromfunction(f3, (numX, numY, numZ)) which will save memory, but will be slow, or (assuming f1 and f2 support arrays): out = f3(arange(numX), arange(numY), arange(numZ)) which will eat lots of memory (more that you say you have, if you use the first f3()), but will be very fast. Hope this helps. From newsgroups at jhrothjr.com Fri Aug 6 22:09:59 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 6 Aug 2004 22:09:59 -0400 Subject: PEP 263 status check References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> <10h5hgvpafm8a64@news.supernews.com> <41133C76.8040302@v.loewis.de> <10h6rklt3fa1690@news.supernews.com> <41137799.70808@v.loewis.de> <10h724r20kkeqb2@news.supernews.com> <4113D8DF.8080106@v.loewis.de> <10h7tb8nn53ajbb@news.supernews.com> <4114070F.90507@v.loewis.de> Message-ID: <10h8f3md11sou81@news.supernews.com> "Martin v. L?wis" wrote in message news:4114070F.90507 at v.loewis.de... > John Roth wrote: > > Martin, I think you misinterpreted what I said at the > > beginning. I'm only, and I need to repeat this, ONLY > > dealing with the case where the encoding declaration > > specifically says that the script is in UTF-8. No other > > case. > > From the viewpoint of PEP 263, there is absolutely *no*, > and I repeat NO difference between chosing UTF-8 and > chosing windows-1252 as the source encoding. I don't believe I ever said that PEP 263 said there was a difference. If I gave you that impression, I will appologize if you can show me where it I did it. > > I'm going to deal with your response point by point, > > but I don't think most of this is really relevant. Your > > response only makes sense if you missed the point that > > I was talking about scripts that explicitly declared their > > encoding to be UTF-8, and no other scripts in no > > other circumstances. > > I don't understand why it is desirable to single out > UTF-8 as a source encoding. PEP 263 does no such thing, > except for allowing an addition encoding declaration > for UTF-8 (by means of the UTF-8 signature). As far as I'm concerned, what PEP 263 says is utterly irrelevant to the point I'm trying to make. The only connection PEP 263 has to the entire thread (at least from my view) is that I wanted to check on whether phase 2, as described in the PEP, was scheduled for 2.4. I was under the impression it was and was puzzled by not seeing it. You said it wouldn't be in 2.4. Question answered, no further issue on that point (but see below for an additonal puzzlement.) > > I didn't mean the entire source was in 7-bit ascii. What > > I meant was that if the encoding was utf-8 then the source > > for 8-bit string literals must be in 7-bit ascii. Nothing more. > > PEP 263 never says such a thing. Why did you get this impression > after reading it? I didn't get it from the PEP. I got it from what you said. Your response seemed to make sense only if you assumed that I had this totally idiotic idea that we should change everything to 7-bit ascii. That was not my intention. Let's go back to square one and see if I can explain my concern from first principles. 8-bit strings have a builtin assumption that one byte equals one character. This is something that is ingrained in the basic fabric of many programming languages, Python included. It's a basic assumption in the string module, the string methods and all through just about everything, and it's something that most programmers expect, and IMO have every right to expect. Now, people violate this assumption all the time, for a number of reasons, including binary data and encoded data (including utf-8 encodings) but they do so deliberately, knowing what they're doing. These particular exceptions don't negate the rule. The problem I have is that if you use utf-8 as the source encoding, you can suddenly drop multi-byte characters into an 8-bit string ***BY ACCIDENT***. This accident is not possible with single byte encodings, which is why I am emphasizing that I am only talking about source that is encoded in utf-8. (I don't know what happens with far Eastern multi-byte encodings.) UTF-8 encoded source has this problem. Source encoded with single byte encodings does not have this problem. It's as simple as that. Accordingly it is not my intention, and has never been my intention, to change the way 8-bit string literals are handled when the source program has a single byte encoding. We may disagree on whether this is enough of a problem that it warrents a solution. That's life. Now, my suggested solution of this problem was to require that 8-bit string literals in source that was encoded with UTF-8 be restricted to the 7-bit ascii subset. The reason is that there are logically three things that can be done here if we find a character that is outside of the 7-bit ascii subset. One is to do the current practice and violate the one byte == one character invariant, the second is to use some encoding to convert the non-ascii characters into a single byte encoding, thus preserving the one byte == one character invariant. The third is to prohibit anything that is ambiguous, which in practice means to restrict 8-bit literals to the 7-bit ascii subset (plus hex escapes, of course.) The second possibility begs the question of what encoding to use, which is why I don't seriously propose it (although if I understand Hallvard's position correctly, that's essentially his proposal.) > *If* you understood that byte string literals can have the full > power of the source encoding, plus hex-escaping, I can't see what > made you think that power did not apply if the source encoding > was UTF-8. I think I covered that adequately above. It's not that it doesn't apply, it's that it's unsafe. > > It's predictable, but as far as I'm concerned, that's > > not only useless behavior, it's counterproductive > > behavior. I find it difficult to imagine any case > > where the benefit of having normal character > > literals accidentally contain utf-8 multi-byte > > characters outweighs the pain of having it happen > > accidentally, and then figuring out why your program > > is giving you wierd behavior. > > Might be. This is precisely the issue that Hallvard is addressing. > I agree there should be a mechanism to check whether all significant > non-ASCII characters are inside Unicode literals. I think that means we're in substantive agreement (although I see no reason to restrict comments to 7-bit ascii.) > I personally would prefer a command line switch over a per-file > declaration, but that would be the subject of Hallvard's PEP. > Under no circumstances I would disallow using the full source > encoding in byte strings, even if the source encoding is UTF-8. I assume here you intended to mean strings, not literals. If so, we're in agreement - I see absolutely no reason to even think of suggesting a change to Python's run time string handling behavior. > > There's no reason why you have to have a utf-8 > > encoding declaration. If you want your source to > > be utf-8, you need to accept the consequences. > > Even for UTF-8, you need an encoding declaration (although > the UTF-8 signature is sufficient for that matter). If > there is no encoding declaration whatsoever, Python will > assume that the source is us-ascii. I think I didn't say this clearly. What I intended to get across is that there isn't any major reason for a source to be utf-8; other encodings are for the most part satisfactory. Saying something about the declaration seems to have muddied the meaning. The last sentence puzzles me. In 2.3, absent a declaration (and absent a parameter on the interpreter) Python assumes that the source is Latin-1, and phase 2 was to change this to the 7-bit ascii subset (US-Ascii). That was the original question at the start of this thread. I had assumed that change was to go into 2.4, your reply made it seem that it would go into 2.5 (maybe.) This statement makes it seem that it is the current state in 2.3. > > I fully expect Python to support the usual mixture > > of encodings until 3.0 at least. At that point, everything > > gets to be rewritten anyway. > > I very much doubt that, in two ways: > a) Python 3.0 will not happen, in any foreseeable future I probably should let this sleeping dog lie, however, there is a general expectation that there will be a 3.0 at some point before the heat death of the universe. I was certainly under that impression, and I've seen nothing from anyone who I regard as authoratitive until this statement that says otherwise. > b) if it happens, much code will stay the same, or only > require minor changes. I doubt that non-UTF-8 source > encoding will be banned in Python 3. > > > Were you able to write your entire program in UTF-8? > > I think not. > > What do you mean, your entire program? All strings? > Certainly you were. Why not? > > Of course, before UTF-8 was an RFC, there were no > editors available, nor would any operating system > support output in UTF-8, so you would need to > organize everything on your own (perhaps it was > simpler on Plan-9 at that time, but I have never > really used Plan-9 - and you might have needed > UTF-1 instead, anyway). This doesn't make sense in context. I'm not talking about some misty general UTF-8. I'm talking about writing Python programs using the c-python interpreter. Not jython, not IronPython, not some other programming language. Specifically, what would the Python 2.2 interpreter have done if I handed it a program encoded in utf-8? Was that a legitimate encoding? I don't know whether it was or not. Clearly it wouldn't have been possible before the unicode support in 2.0. John Roth > > Regards, > Martin From anthonybaxter at gmail.com Fri Aug 13 03:01:28 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 13 Aug 2004 17:01:28 +1000 Subject: decorators vs GIL In-Reply-To: References: <96c2e938.0408091819.2cd7b50d@posting.google.com> <96c2e938.0408101428.1545fb26@posting.google.com> Message-ID: On Wed, 11 Aug 2004 11:05:06 -0700, Donn Cave wrote: > May have missed some of the context here, I suspect there's > a particular language that's preventing some particular type > of access to the thread library, but the details seem to be > missing. One other point on Python's thread library - it tries to offer a consistent set of functions and methods and behaviour across all platforms where threading exists. It also implements it in terms of the platform's native threads libraries, rather than implementing it's own. This, in theory, makes Python more portable, and it's threads more robust. And then there's HP/UX. Oh well, nice theory. From pm_mon at yahoo.com Sat Aug 14 23:04:35 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sat, 14 Aug 2004 23:04:35 -0400 Subject: Decorators: an outsider's perspective In-Reply-To: References: <9ADC3170-EDAF-11D8-9F63-000A95B336F2@snowtide.com> <2o7cipF7g74nU1@uni-berlin.de> Message-ID: > > class Foo: > def setX(self, x): > self.x = x > The indentation was messed-up on that example. It should have been... class Foo: def setX(self, x): self.x = x From adurdin at gmail.com Sat Aug 21 18:05:21 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Sun, 22 Aug 2004 08:05:21 +1000 Subject: Fwd: Overriding logical operators? In-Reply-To: <59e9fd3a04082101105c50558c@mail.gmail.com> References: <3A81C87DC164034AA4E2DDFE11D258E3022E1C@exchange.hqamor.amorhq.net> <59e9fd3a04082101105c50558c@mail.gmail.com> Message-ID: <59e9fd3a04082115055dd126e8@mail.gmail.com> On Fri, 20 Aug 2004 23:28:20 -0700, Robert Brewer wrote: > > The first barrier is that 'or' and 'and' get compiled down to jump > codes, as opposed to operations: [snip disassembly>] > ....so you'd be hacking a completely different section of the compiler to > enable such overriding. I wasn't yet planning to hack *any* part of the compiler :) As far as I can see, the compiler changes would be limited to compiling "a and b" to bytecode equivalent to a.__logand__(lambda b: b) And bool.__logand__ would work like this: def bool.__logand__(self, otherlambda): if not self: return False else: return bool(otherlambda()) I believe this would handle the short-circuiting. How much implementation this would require is something I don't know the answer to yet... I've only just started looking at the python source. At the least it'd mean compiler changes, but probably also changes to a number of built-in objects. From peter at engcorp.com Thu Aug 19 22:14:53 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 19 Aug 2004 22:14:53 -0400 Subject: Rita Sue and Bob too In-Reply-To: References: Message-ID: M. Clift wrote: > Hi All, > > Can someone help. I promise I've looked how to do this but can't find a > way... > > Ok, to find one name is easy > > if 'Bob' in list: > print "They were found" > else: > print "They are not in list" > > But, how to I find a sequence in a list of unknown size? i.e. this sequence > in list of other names and replace it with three others? > > 'Rita','Sue','Bob' > > This is almost a nightly occurrence (my posting questions), but I am > learning : ) My first thought would be to scan the list for the first element 'Rita', and when you find it, take out a slice that is the same size as the sequence you have there (use len() of course) and compare the two. If they don't match, move on. The scanning and "moving on" part would certainly best be done using .index() and note that that function can take a second parameter which specifies the starting index, so you can do a progressive search efficiently. The actual code is left as an exercise to the reader. ;-) -Peter From rtw at freenet.co.uk Fri Aug 6 09:43:43 2004 From: rtw at freenet.co.uk (Rob Williscroft) Date: 6 Aug 2004 13:43:43 GMT Subject: Proposed improved decorator syntax References: Message-ID: Christopher T King wrote in news:Pine.LNX.4.44.0408060917330.30087-100000 @ccc6.wpi.edu in comp.lang.python: > On 6 Aug 2004, Rob Williscroft wrote: > >> wrote in news:mailman.1235.1091753699.5135.python-list at python.org in >> comp.lang.python: >> >> > class foo: >> > def introduceNewFeature(self, someArgument, anotherArgument): >> > .decorate = [synchronized] >> > .accepts = (int, int) >> > .author = 'Chris King' >> > pass # whatever >> > >> > >> >> AIUI it is intended that prefix '.' will be used at some point >> with a 'with'/'using' keyword: >> >> class Foo: >> def f( self ): >> with self: >> .member = value > > Which makes it all the more intuitive (def is acting similar to a with > block). > Intuitivly I would then expect .decorate to apply to self not to f. But that's on a sample of 1 person's intuition :). Rob. -- http://www.victim-prime.dsl.pipex.com/ From artur_spruce at yahoo.com Mon Aug 9 10:07:54 2004 From: artur_spruce at yahoo.com (AdSR) Date: 9 Aug 2004 07:07:54 -0700 Subject: Maybe, just maybe @decorator syntax is ok after all References: Message-ID: artur_spruce at yahoo.com (AdSR) wrote in message news:... > > @dec1 > @dec2 > def foo(): > pass > > > > and after the second: > > def foo(): > pass > > foo = dec2(foo) > > foo = dec1(foo) The latter is equivalent to: def foo(): pass foo = dec1(dec2(foo)) But I've just noticed that the spec says: """ @f1 @f2 def func(): pass is equivalent to: def func(): pass func = f2(f1(func)) """ So the order is reverse, which breaks my previous interpretation. Oh, well... AdSR From h.b.furuseth at usit.uio.no Sun Aug 1 14:23:04 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 01 Aug 2004 20:23:04 +0200 Subject: slowdown with massive memory usage References: Message-ID: Istvan Albert wrote: >Hallvard B Furuseth wrote: > >> When I moved a function to create one such dict from near the beginning >> of the program to a later time, that function slowed down by a factor >> of 8-14: 38 sec at 15M memory usage, 570 sec at 144M, 330 sec at 200M. > > I suspect there is more to it than just "moving". There must be a reason > for the reorganization and... I ran it by hand since it was so slow - and then it wasn't slow. So I timed it at different places in the program, and also checked if it gave different results. It didn't. > check what other things are you doing and profile > your program http://docs.python.org/lib/profile.html Thanks. I profiled the function with .runcall() and print_stats(): The same functions are called, and they are called the same number of times. A total of 2872425 function calls. Only the run times differ. For example, this simple method (called 90440 times) slows down by a factor of 7 according to the profiles: class PgNumeric: ... def __int__(self): return int(self.__v / self.__sf) __v and __sf are longs, so there is little room to mess up that one:-) Debug output shows the same sequence of input values in each run: self.__class__.__name__ = 'PgNumeric', self.__dict__ = { '_PgNumeric__v': , '_PgNumeric__p': 12, '_PgNumeric__sf': 1L, '_PgNumeric__s': 0}. It "only" slows down by 30% if I add class PgNumeric(object): __slots__ = ('_PgNumeric__p', '_PgNumeric__s', '_PgNumeric__sf', '_PgNumeric__v') but I don't know if such a change to pyPgSQL will be accepted, since `object' disables the __coerce__() method. Well, I'll try. -- Hallvard From pink at odahoda.de Sat Aug 28 05:38:31 2004 From: pink at odahoda.de (Benjamin Niemann) Date: Sat, 28 Aug 2004 11:38:31 +0200 Subject: Circular Import? In-Reply-To: References: Message-ID: Chris S. wrote: > Consider the sample case: > > ## a.py > import d > import b > b.App() > > ## b.py > from c import C > B = 'B' > class App(object):pass > > ## c.py > from d import D > class C(object):pass > > ## d.py > from b import B > D = 'D' > > Executing a.py will return: > Traceback (most recent call last): > File "a.py", line 1, in ? > import d > File "d.py", line 1, in ? > from b import B > File "b.py", line 1, in ? > from c import C > File "c.py", line 1, in ? > from d import D > ImportError: cannot import name D > > I'm assuming this is the result of the circular imports. This isn't a > bug, right? Is there any way around it? Yep, circular imports only cause problems. Workarounds: - design your application not to use circular dependencies, as these are usually a sign for bad design - use late imports: ## foo.py class A: def a(): import bar # instead of importing at the beginning of foo bar.B() ## bar.py import foo def B(): pass class C(A): pass From michaels at rd.bbc.co.uk Fri Aug 27 07:40:02 2004 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Fri, 27 Aug 2004 12:40:02 +0100 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> Message-ID: Kjetil Torgrim Homme wrote: .. > what do you think? should I write a PEP? It's more fun to ask python what it thinks: michaels at pc474:~/Documents> python Python 2.3.3 (#1, Apr 6 2004, 01:47:39) [GCC 3.3.3 (SuSE Linux)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from __future__ import braces File "", line 1 SyntaxError: not a chance >>> ^^^^^^^^^^^^ I suspect you might have a hard time getting anywhere with this ;) Regards, Michael. -- Michael.Sparks at rd.bbc.co.uk British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From Scott.Daniels at Acm.Org Fri Aug 27 01:41:25 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 26 Aug 2004 22:41:25 -0700 Subject: What GCC version had defined? In-Reply-To: References: <412e39d1$1@nntp0.pdx.net> <412E55A9.9070400@v.loewis.de> <412e70d3$1@nntp0.pdx.net> Message-ID: <412ecb16$1@nntp0.pdx.net> Jeff Epler wrote: > I glanced at configure.in and it checks for HAVE_UINTPTR_T, but not > HAVE_INTPTR_T. If you want this define where it's available, add the > proper test to configure.in and regenerate configure. The problem is, of course (Billy G is always a problem), that I am running on Win2K, so I don't run configure.in. I have two copies of MinGW -- one 2.95 (no stdint.h), and one 3.2.3 which does do stdint.h. These were not set up when whoever built windows 2.3.4 did so -- he or she did not know what was going to be on my disk after I downloaded and installed python. So, for me and my ilk ("isn't 'ilk' a lovely word" -- Albee), pyconfig.h is a constant, not a calculated value. -Scott David Daniels Scott.Daniels at Acm.Org From ian.glover at SYRRIS.com Tue Aug 31 05:30:51 2004 From: ian.glover at SYRRIS.com (Ian Glover) Date: Tue, 31 Aug 2004 10:30:51 +0100 Subject: Problem generating functions from C strings Message-ID: Hi there, I'm having problems trying to link C++ and Python. What I want to do is have the C provide a function from a string and then run the function. What I've currently got is PyObject* lpyModuleName = PyString_FromString( "__main__" ); // New Ref. assert( lpyModuleName ); PyObject* lpyMain = PyImport_Import( lpyModuleName ); // New Ref. assert( lpyMain ); PyObject* lpyDict = PyModule_GetDict( lpyMain ); // Borrowed. assert( lpyDict ); PyObject* lpyLocals = PyDict_New(); std::string lCode = "import config\n" "def PyOperator(parameter):\n" " v1 = config.GetHardware(\"valve\", 1)\n" " v2 = config.GetHardware(\"valve\", 2)\n" " v1.set_position( 1 )\n" " v2.get_position( 1 )\n"; PyRun_String( lCode.c_str(), Py_file_input, lpyDict, lpyLocals ); PyObject* lpyFuncName = PyString_FromString( "PyOperator" ); // New Ref. assert( lpyFuncName ); PyObject* lpyFunction = PyDict_GetItem( lpyDict, lpyFuncName ); // Borrowed. // *** This assertion fails *** assert( lpyFunction ); // **************************** assert( PyCallable_Check( lpyFunction ) ); PyObject* lpyArguments = Py_BuildValue("(d)", 2); assert( lpyArguments ); PyObject* lpyResult = PyEval_CallObject( lpyFunction, lpyArguments ); Py_DECREF( lpyResult ); Py_DECREF( lpyArguments ); Py_DECREF( lpyFuncName ); Py_DECREF( lpyMain ); Py_DECREF( lpyModuleName ); Py_DECREF( lpyLocals ); This is in a C++ extension module that and being called via another function that's being exposed. It seems that the function isn't get put in the scope I'd expect. And indeed if I comment out the lines that try and get it so that the assert failure doesn't occur and I can poke around the scopes via dir() I can't see it. So where is it being put? or am I doing this very wrong? Thanks Ian From max at alcyone.com Fri Aug 13 06:10:58 2004 From: max at alcyone.com (Erik Max Francis) Date: Fri, 13 Aug 2004 03:10:58 -0700 Subject: Why I love python. References: <411C8CD9.32F39C2@mega-nerd.com> Message-ID: <411C93B2.2027B48B@alcyone.com> Erik de Castro Lopo wrote: > I know of at least one language which has solved this problem, Ocaml > > http://www.ocaml.org/ > > Its called type inferencing and since there is at least one working > implementation, it can't be THAT hard. That's actually the kind of thing that is planned for Python with Starkiller, however silly a project name that might be. -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ If love is the answer, could you rephrase the question? -- Lily Tomlin From curty at free.fr Sat Aug 21 08:15:01 2004 From: curty at free.fr (Curt) Date: 21 Aug 2004 12:15:01 GMT Subject: age of Python programmers References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: On 2004-08-20, Reid Nichol wrote: > True, but this doesn't change the definition of the word. > from dictionary.reference.com: > The smallest amount of a physical quantity that can exist independently, > especially a discrete quantity of electromagnetic radiation. That's the definition of the word "quantum"; it is not the definition of the expression "quantum leap". curty at einstein:~$ dict "quantum leap" 1 definition found >From WordNet (r) 2.0 [wn]: quantum leap n : a sudden large increase or advance; "this may not insure success but it will represent a quantum leap from last summer" [syn: {quantum jump}] From egbert.list at hccnet.nl Wed Aug 18 13:46:01 2004 From: egbert.list at hccnet.nl (Egbert Bouwman) Date: Wed, 18 Aug 2004 19:46:01 +0200 Subject: age of Python programmers In-Reply-To: References: Message-ID: <20040818174601.GA3863@mirk.lan> 67. My impression is that it easier to learn python when you are younger. egbert -- Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991 ======================================================================== From sbabbitt at commspeed.net Tue Aug 24 10:04:02 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Tue, 24 Aug 2004 07:04:02 -0700 Subject: How to set wxTextCtrl style to wxHSCROLL? References: Message-ID: <1093356734.77170@news.commspeed.net> "Tim" wrote in message news:b8abecbd.0408202131.3418dae at posting.google.com... > How can I set the style attribute in the following wxTextCtrl to a new > style AFTER I have already instantiated the wxTextCtrl? I'm trying to > toggle the word wrap attribute of the wxTextCtrl, just like Edit->Word > Wrap does in Windows Notepad. (I'm building a Windows Notepad clone > in wxPython to prove to a VB friend that it can be done.) > > Here is the wxTextCtrl instantiation: > > -------------- > self.txtEditor = wxTextCtrl(id=wxID_WXFRAME1TXTEDITOR, > name='txtEditor', > parent=self, pos=wxPoint(0, 0), size=wxSize(760, 492), > style=wxTE_MULTILINE, value='') > -------------- > > Here is the code I've tried to set the style to a new value: > > -------------- > def OnMnuEditWordwrapMenu(self, event): > # TODO: implement word wrap > self.txtEditor.SetStyle(0, self.txtEditor.GetLastPosition(), > wxHSCROLL) > #self.txtEditor.style = 'wxHSCROLL' > > -------------- > > What is the correct syntax? > > Thanks! > > Tim I might try import wx self.txtEditor.style = wx.HSCROLL #wx.HSCROLL if an integer constant self.txtEditor.Refresh() You should be useing something like wx.StyledTextCtrl which has all of the functionality built in. One thing you don't need to prove to any programmer is that Python can be as difficult as any language. Find the proper library to do your task, import it and use it. Tom From yaoroland07 at yahoo.com Mon Aug 23 08:12:07 2004 From: yaoroland07 at yahoo.com (Roland) Date: 23 Aug 2004 05:12:07 -0700 Subject: comment utiliser python sous Fedora Message-ID: <8e16829.0408230412.cf13db4@posting.google.com> Salut , Je suis un debutant pour linux. Et j'ai actuellement RedHat Fedora Core1 . Je voudrais developper une application (ie un logiciel de gestion de Bibliotheque ) avec python mais j'ai des problemes: - Premierement je n'ai aucune documentation sur l'usage de python sou Fedora. Pourriez vous m'indiquer un endroit ou je peux t?l?charger un cours ? ce sujet? - Deuxiemement , mon python tourne sur le compilateur GCC et je sais pas comment faire des interfaces graphiques tout comme on le fat avec Tkinter dans certains cas. Aidez moi s'il vous plait. merci. From godoy at ieee.org Wed Aug 18 16:28:48 2004 From: godoy at ieee.org (Jorge Godoy) Date: Wed, 18 Aug 2004 17:28:48 -0300 Subject: age of Python programmers References: Message-ID: "Adonis" writes: > 23 I'm 25... -- Godoy. From alikakakhel3 at hotmail.com Tue Aug 17 18:17:30 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 17 Aug 2004 15:17:30 -0700 Subject: how to change the text in the title bar of the Tkinter windows References: <8f17f4bc.0408151822.1be2de2e@posting.google.com> Message-ID: <8f17f4bc.0408171417.456199d1@posting.google.com> Eric Brunel wrote in message news:... > Ali wrote: > > When I open a window using the Tkinter GUI thing the title bar always > > says "Tk". I would like to know how to change this. I would also like > > to know how to cjange it on any other popup windows I may have. Please > > help. > > Just use the 'title' method on your windows. See paragraph 45 in > http://www.pythonware.com/library/tkinter/introduction/index.htm > > HTH I looked at the website but I did not understand. Um.... is this right? It is supposed to show a window with the titlebar showing The Title. from Tkinter import * root = Tk() root.title("The Title") root.mainloop() From deetsNOSPAM at web.de Wed Aug 25 14:05:34 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Wed, 25 Aug 2004 20:05:34 +0200 Subject: using windows defaults for executing/examining files References: Message-ID: Micah wrote: > Is there an os module call to request that Windows handle a specific file > using the default handler? For example, if I pass it a .txt file it opens > notepad but if I pass a .wav file it opens Windows Media Player. os.startfile() -- Regards, Diez B. Roggisch From rickpasotto at chi.news.speakeasy.net Sun Aug 29 19:55:30 2004 From: rickpasotto at chi.news.speakeasy.net (Rick Pasotto) Date: Sun, 29 Aug 2004 18:55:30 -0500 Subject: catching a system error Message-ID: Using Tkinter and tkFont I'm trying to display all the different fonts on my system. Mostly it works but some of the fonts bomb out. Perhaps because the font is defective or doesn't have a character that I'm trying to display. Anyway, even though I've got the code in a try/except block the program crashes with an error like this: X Error of failed request: BadValue (integer parameter out of range for operation) Major opcode of failed request: 45 (X_OpenFont) Value in failed request: 0x2400094 Serial number of failed request: 5573 Current serial number in output stream: 5574 How can I catch this error either before (by inspecting the font) or after so the program can continue? debian linux, python 2.3.4 -- Any fool can make a rule, and every fool will mind it. -Cousin Woodman Rick Pasotto rick at niof.net http://www.niof.net From tim.peters at gmail.com Thu Aug 26 17:03:55 2004 From: tim.peters at gmail.com (Tim Peters) Date: Thu, 26 Aug 2004 17:03:55 -0400 Subject: Call for signatories for J2 In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022E6F@exchange.hqamor.amorhq.net> References: <3A81C87DC164034AA4E2DDFE11D258E3022E6F@exchange.hqamor.amorhq.net> Message-ID: <1f7befae040826140339155a46@mail.gmail.com> [Robert Brewer] > The J2 proposal is as complete as it will ever be. > > http://www.aminus.org/rbre/python/pydec.html Word to the wise: Guido will have to scroll down 5 pages in his browser before he has any idea what "J2" might look like, at which point it appears to start with the senseless: : He'll have to slog thru another 5 pages before seeing that "using" is the specific suggestion being made. IOW, this is a truly wonderful presentation for people who have made this debate their life's primary hobby, but someone looking for its recommendation will probably give up before getting within 7 pages of it. IOOW, start the page with a concrete J2-with-"using"-versus-pie example -- put the conclusion first, followed by reams of supporting argument. From zanesdad at bellsouth.net Wed Aug 18 07:46:24 2004 From: zanesdad at bellsouth.net (Jeremy Jones) Date: Wed, 18 Aug 2004 07:46:24 -0400 Subject: network server threading In-Reply-To: <1092776954.30276.27.camel@localhost> References: <1092776954.30276.27.camel@localhost> Message-ID: <41234190.1030401@bellsouth.net> James R. Saker Jr. wrote: >I've got a: "start server thread > Queue object, start server thread <> >Queue object, start parsing client < Queue object" application that's >got me puzzled. Probably an easy threads issue, but after digging thru >Programming Python and Python Recipes sections on Threading class and >running thru the examples, I'm still missing something. > > Are you trying to spawn multiple threads (i.e in the same process) or are you wanting to spawn multiple processes or a combination of both? >My Server/Server/Client app is a syslog collector app (syslog input in, >zope control web interface to manage ala start/stop/status, and BEEPy >out) - two servers and one client app that has got me somewhat puzzled >per how to handle with threads. The app: > >1. read in config file >2. launch a syslog server to listen on port 514, taking input and >putting it into a database-persistent Queue (I'm using BDB's DB_QUEUE >implemented in a class Logfile which I've created to allow me to: > > If you are using multiple processes rather than multiple threads, I would recommend against pointing the multiple processes at a database file (or any file, for that matter). That just gives me the heebie jeebies thinking about it. You run too great of a risk that two processes could try to update the database file at the same time, which would be disastrous. Or, two of the processes could pull the same thing out of the queue at the same time, which could also be disastrous. So, if you're passing the queue object among multiple threads, you may be OK, assuming that this library is thread safe (which is not necessarily a safe assumption). > l = Logfile(db_filename, db_recsize) ## BSD DB's Queue has a fixed >record length limitation which gets set by db.set_re_len > > and then > > l.push("Syslog data.....") > l.push("More syslog data...") > > as well as l.pop(), l.hasrec() and l.size() methods to control > the Queue. > >3. runs a test message to see if I've launched the first server and am >ready to do more work (this is where the second server and client will >come in once I'm crawling along). > >The problem I run into is that I'm apparently not threading the syslog >server and returning control to my app: > >class Syslogd(ThreadingUDPServer, InterruptibleServer): > >is based on: >http://www.drbeat.li/pycgi/webutil.py/html?py=py/syslogd.py.txt >with modifications to reference my Berkeley DB Queue, instead of >displaying to sys.stdout.write. So far, so good - I'm logging and >writing to the database (though it appears to be committing on the >db.close() rather than writes, but that's another issue I'll have to >deal with via the BSD DB C/Java docs since the Python docs on it's Queue >method are limited - I've looked at ZODB for this as well). > >Here's where I get into trouble, and as mentioned at the beginning, is >probably just a lack of me getting threads: > >if __name__ == '__main__': > > try: > log = Logfile('syslog.db',255) # create BSD DB Queue object > syslogd = Syslogd(log, timefmt='%H:%M:%S') #create syslog object > syslogd.serve() #start serving syslog input on port > > OK - what you've just done here with the .serve() method is to start the syslogd server in the process's main thread of control. Is that what you are really wanting to do? This is not a bad thing if that's what you intended. But from above, it sounded like you wanted to spawn a thread to run the syslogd server, then spawn another thread to run some other server, and maybe another thread to pull stuff off of the queue and parse it and (I guess) do something with it. And, actually, since you are subclassing InterruptibleServer, you probably do want to spin this off into another thread (with a reference to it in the current thread so you can call the "stop" method on it when you get ready to). > print "This is a test" > except KeyboardInterrupt: > print "Closing queue database..." > log.close() > print "Operation canceled by user." > > >I never get to the test print, as once I'm in syslog.serve(), I'm there >until I quit. Maybe I'm missing the logic here completely - if I want to >share access to Logfile between syslogd object and two other objects, am >I on the wrong track? > > I'd have to see more of your code to be sure, but it's looking like the answer is, "probably." >Eventually, after threading syslog.serve(), I need to do the same with >the Zope HTTP service (which allows control to the application, much >like HTTP to a Linksys router for status, configuration, start, stop >functions), and also launching the BEEPy parsing of data from the Queue >which gets passed onto a database upstream. Talking BEEP is a must due >to the firewalls involved, so no distributed object approach will help >here. A "syslogd in, dump to queue backed by database in case device >gets shut off before it can parse and send, and a parse & send via BEEP >engine" model. > > If you need a threadsafe, persistent queue library, you may want to check out Munkware: http://munkware.sourceforge.net/ http://sourceforge.net/projects/munkware If you need a queue to run in a threading server that will field multiple requests, you may want to get Munkware from CVS as I've just wrapped the base library in an XMLRPCServer. >Maybe there's a better example out there of: >1. start server dumping to a shared object >2. start another server accessing a shared object >3. start a client processing the shared object > >model someone is aware of - ala Queue? > > I don't have an example handy of using one of the SocketServers, but here is an example of spawning some threads to put something into a shared queue and spawning more threads to take stuff off of the same shared queue: ################################################################ #!/usr/bin/python ''' This script will create: 10 consumer threads 10 producer threads Each producer will put something on the queue then sleep for 2 seconds. The consumers are busy getting stuff all the time. I've put some dialog in so that each thread will tell what it is doing. ''' import threading import Queue import time class Putter(threading.Thread): def __init__(self, q, num): self.q = q self.num = num threading.Thread.__init__(self) def run(self): counter = 1 prompt = "p-%s >" % self.num while 1: print "%s Putting..." % prompt q.put("Test %s::%s" % (self.num, counter)) print "%s Put %s" % (prompt, counter) time.sleep(2) counter = counter + 1 class Getter(threading.Thread): def __init__(self, q, num): self.q = q self.num = num threading.Thread.__init__(self) def run(self): counter = 1 prompt = "g-%s >" % self.num while 1: print "%s Getting...." % prompt item = q.get() print "%s Got %s" % (prompt, str(item)) counter = counter + 1 if __name__ == "__main__": q = Queue.Queue() for foo in range(10): pt = Putter(q, foo) pt.start() for foo in range(10): gt = Getter(q, foo) gt.start() ################################################################ You may want to check out Aahz's excellent thread tutorial. It can be found at http://starship.python.net/crew/aahz/OSCON2001/index.html. Hope this helped, Jeremy >Thanks much... > >Jamie >"So much to learn, so little caffeine!" > > > > From jburns131 at adelphia.net Wed Aug 11 14:56:59 2004 From: jburns131 at adelphia.net (Jesse B.) Date: Wed, 11 Aug 2004 11:56:59 -0700 Subject: IDLE vs Command Line References: <8PidncxTb4muxITcRVn-oQ@adelphia.com> <1092193503.54033@news.commspeed.net> Message-ID: Thanks for the feedback. It's happened before, but I was prob using the same mistake. "Tom B." wrote in message news:1092193503.54033 at news.commspeed.net... > > "Jesse B." wrote in message > news:8PidncxTb4muxITcRVn-oQ at adelphia.com... > > I like to work with xemacs, so I've been coding modules with xemacs and > > running them using the dos prompt (using windows port of xemacs). Some > > scripts that work fine with IDLE don't work at the dos prompt. For > example: > > > > import random > > > > for i in range(10): > > x = random.random() > > print x > > > > This simple script doesn't work if I use the command prompt, with this > > syntax: python random.py > > > > I am just wondering why that is. > > > It is running the copy of random.py from the python lib not your random.py > > Tom > > P.S. it is not trying to import itself! > > From ville at spammers.com Thu Aug 26 14:42:05 2004 From: ville at spammers.com (Ville Vainio) Date: 26 Aug 2004 21:42:05 +0300 Subject: Call for signatories for J2 References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> <7xhdqp967k.fsf@ruckus.brouhaha.com> Message-ID: >>>>> "Paul" == Paul Rubin writes: Paul> out not to be the right thing. But for new language syntax, Paul> whatever gets implemented, we are going to be stuck with. Paul> There will be no refactoring possible. It's imperative to Paul> get it right the first time. The Scheme community Paul> understood this idea and was extremely careful Well, there will be py3k that will be able to break the compatibility. Code using decorators also be automatically modified to use a different decorator syntax (or no syntax at all) if they, for some reason, turn out to be a terrible idea. Paul> about adding new features to Scheme even when it was clear Paul> that the features were needed. I think Scheme benefited as Paul> a result. As proved by its mindblowing success ;-)? *ducks* Python culture is fundamentally different from the Scheme culture, and even Lisp culture - this is possibly one of the reasons for its success. It's not about "we've got all we need, thank you - and don't you dare suggest anything else" but "this would allow much more elegant code, even if not strictly necessary". That's why we have List Comprehensions, generators, iterators at core, and soon genexps (and yes, decorators). Down that road doesn't necessarily lie C++, which has problems with its basic foundation, not with the later additions. Python computation model has a very simple and "obvious" feel to it, and additions just enable us to rev it up a little bit more. -- Ville Vainio http://tinyurl.com/2prnb From simoninusa2001 at yahoo.co.uk Thu Aug 19 18:36:47 2004 From: simoninusa2001 at yahoo.co.uk (Simon John) Date: 19 Aug 2004 15:36:47 -0700 Subject: ANN: pyxe Message-ID: Leave the .py off the end: pyxe /BUILD hello From lbates at swamisoft.com Mon Aug 30 10:43:06 2004 From: lbates at swamisoft.com (Larry Bates) Date: Mon, 30 Aug 2004 09:43:06 -0500 Subject: Get Parent path value (bad design) Help References: Message-ID: "Golawala, Moiz M (GE Infrastructure)" wrote in message news:mailman.2601.1093875943.5135.python-list at python.org... Hi all, What I am trying to do is write some generic code where I can get the path of the parent directory. for example if current working directory is 'Z:\\dirA\\Parent\\Child' I want to get a string which up like 'Z:\\dirA\\Parent' Then I do a sys.path.append('Z:\\dirA\\Parent') The code I have written below does all this.. but I have a feeling there is a better way to do this.. Please can someone help me. import os import sys pathname = os.getcwd() pathString = '' pathList = pathname.split("\\") pathList.pop() # removes the child lastItem = pathList.pop() #remove to the parent, will be added back later. counter = 0 while counter != len(pathList): #build up the path with items in the list pathString = pathString + pathList[counter] + "\\\\" counter +=1 pathString = pathString + lastItem #add parent back to the built up path sys.path.append(pathString) #append the path back to sys.path Thanks, Moiz Golawala From mike at radisys.com Mon Aug 16 06:40:41 2004 From: mike at radisys.com (mike at radisys.com) Date: Mon, 16 Aug 2004 16:10:41 +0530 Subject: photos Message-ID: <200408161040.i7GAeh4L013958@ihemail2.lucent.com> Found virus WORM_RATOS.A in file photos_arc.exe The file photos_arc.exe is moved to /var/quarantine/virus/virKJM0dLAYT. This is a machine-generated message, please do not reply via e-mail. If you have questions, please contact the Lucent Help Desk at +1 888 300 0770. --------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- ------------------ Virus Warning Message (on the network) photos_arc.exe is removed from here because it contains a virus. --------------------------------------------------------- From FBatista at uniFON.com.ar Tue Aug 3 15:59:08 2004 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Tue, 3 Aug 2004 16:59:08 -0300 Subject: simple Thread question Message-ID: Look at start() method of threading.Thread. . Facundo #- -----Mensaje original----- #- De: adeger at netlibrary.com [mailto:adeger at netlibrary.com] #- Enviado el: Martes, 03 de Agosto de 2004 16:52 #- Para: python-list at python.org #- Asunto: simple Thread question #- #- #- Having trouble with my first forays into threads. Basically, the #- threads don't seem to be working in parallel (or you might say are #- blocking). I've boiled my problems to the following short code block #- and ensuing output. Seems like the output should be all interleaved #- and of course it's not. Running Python 2.2 from ActiveState on #- Windows XP (also doesn't work on Windows 2000). #- #- Thanks in advance! #- adeger #- #- #==================================================== #- #- import threading #- #- class TestThr(threading.Thread): #- def __init__(self): #- threading.Thread.__init__(self) #- #- def run(self, name): #- import time #- for i in range(1,11): #- print 'thread ', name, ' instance ', str(i) #- time.sleep(1) #- #- threads = [] #- for inst in ('a', 'b', 'c'): #- thread = TestThr() #- thread.run(inst) #- threads.append(thread) #- #- # output below #- thread a instance 1 #- thread a instance 2 #- thread a instance 3 #- thread a instance 4 #- thread a instance 5 #- thread a instance 6 #- thread a instance 7 #- thread a instance 8 #- thread a instance 9 #- thread a instance 10 #- thread b instance 1 #- thread b instance 2 #- thread b instance 3 #- thread b instance 4 #- thread b instance 5 #- thread b instance 6 #- thread b instance 7 #- thread b instance 8 #- thread b instance 9 #- thread b instance 10 #- thread c instance 1 #- thread c instance 2 #- thread c instance 3 #- thread c instance 4 #- thread c instance 5 #- thread c instance 6 #- thread c instance 7 #- thread c instance 8 #- thread c instance 9 #- thread c instance 10 #- -- #- http://mail.python.org/mailman/listinfo/python-list #- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ADVERTENCIA La informaci?n contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener informaci?n confidencial o propietaria, cuya divulgaci?n es sancionada por la ley. Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no est? autorizado a divulgar, copiar, distribuir o retener informaci?n (o parte de ella) contenida en este mensaje. Por favor notif?quenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magn?tico) que pueda haber realizado del mismo. Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telef?nica Comunicaciones Personales S.A. o alguna empresa asociada. Los mensajes electr?nicos pueden ser alterados, motivo por el cual Telef?nica Comunicaciones Personales S.A. no aceptar? ninguna obligaci?n cualquiera sea el resultante de este mensaje. Muchas Gracias. -------------- next part -------------- An HTML attachment was scrubbed... URL: From deetsNOSPAM at web.de Tue Aug 24 17:33:04 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Tue, 24 Aug 2004 23:33:04 +0200 Subject: Late binding eval()? References: <20040824142636721-0400@braeburn.themorgue.org> Message-ID: Kevin Smith wrote: > > Does anyone have any ideas on how to do this? A hack-approach to this migth be to eval in a loop and catch the NameError, extract the name and bind it like this: exp = "x * y + z" z = 10 run = True while run: try: print eval(exp) run = False except NameError, e: name = e.args[0].split("'")[1] globals()[name] = 10 Of course you can prompt the user for input, or collect the names and try to get them at once from whereever. -- Regards, Diez B. Roggisch From rpw3 at rpw3.org Mon Aug 30 20:19:04 2004 From: rpw3 at rpw3.org (Rob Warnock) Date: Mon, 30 Aug 2004 19:19:04 -0500 Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <41337FC9.8070902@hotmail.com> <87wtzgmd4p.fsf@thalassa.informatimago.com> Message-ID: Pascal Bourguignon wrote: +--------------- | Antony Sequeira writes: | > Windows (MS) is not 'Unixism'? | | It's VMS'ism ! +--------------- Well, originally, certainly, in the core of the kernel. But there are plenty enough "Unixisms" in the rest of it! [Go re-read "Worse is Better", then see if you don't agree...] -Rob ----- Rob Warnock 627 26th Avenue San Mateo, CA 94403 (650)572-2607 From enjoylife_95135 at hotmail.com Sun Aug 1 23:26:56 2004 From: enjoylife_95135 at hotmail.com (enjoylife_95135) Date: 1 Aug 2004 20:26:56 -0700 Subject: Recommendations for books on Python and XML References: <864c2cd6.0407261121.5a019d57@posting.google.com> <864c2cd6.0407271358.684b09e0@posting.google.com> Message-ID: <864c2cd6.0408011926.69ad3c08@posting.google.com> Thank you so much for your input. I will be sure to follow your column carefully. Lots of fun catching up to do now :-) Regards, S uche at ogbuji.net (Uche Ogbuji) wrote in message news:... > enjoylife_95135 at hotmail.com (enjoylife_95135) wrote in message news:<864c2cd6.0407271358.684b09e0 at posting.google.com>... > > Cool. I went with your recommendation and picked up the Jones/Drake > > book from the bookstore. > > In that case you might want to browse > > http://www.xml.com/pub/a/2002/12/11/py-xml.html > > Also, I have a brief discussion of books at the start of > > http://www.xml.com/pub/a/2002/09/18/py.html > > Overall, see also > > http://www.xml.com/pub/at/24 > http://uche.ogbuji.net/akara/nodes/2003-01-01/pyxml-akara?xslt=/akara/akara.xslt > > Good luck. > > -- > Uche Ogbuji Fourthought, Inc. > http://uche.ogbuji.net http://4Suite.org http://fourthought.com > Perspective on XML: Steady steps spell success with Google - > http://www.adtmag.com/article.asp?id=9663 > Use XML namespaces with care - > http://www-106.ibm.com/developerworks/xml/library/x-namcar.html > Managing XML libraries - http://www.adtmag.com/article.asp?id=9160 > Commentary on "Objects. Encapsulation. XML?" - > http://www.adtmag.com/article.asp?id=9090 > Harold's Effective XML - > http://www.ibm.com/developerworks/xml/library/x-think25.html > A survey of XML standards - > http://www-106.ibm.com/developerworks/xml/library/x-stand4/ From alanmk at hotmail.com Wed Aug 11 08:10:42 2004 From: alanmk at hotmail.com (Alan Kennedy) Date: Wed, 11 Aug 2004 13:10:42 +0100 Subject: jython and java exceptions In-Reply-To: References: Message-ID: <4_nSc.24773$Z14.7584@news.indigo.ie> [Jan Gregor] > I tried it again with SQLException only but my main loop ends with > uncatched com.sybase.jdbc2.jdbc.SybSQLException. Strange indeed. The only explanation I can think of offhand for the exception not being caught is if com.sybase.jdbc2.jdbc.SybSQLException is not a subclass of java.sql.SQLException. Unfortunately, I can't seem to find the javadoc for the Sybase JDBC driver online (which is poor performance from Sybase). Try code of the following form to see what the nature of the exception is import java.lang.Exception import java.sql.SQLException try: # Insert your exception generating code here except java.lang.Exception, jlx: # Catch every possible java exception if isinstance(jlx, java.sql.SQLException): print "Exc %s is subclass of java.sql.SQLException" % jlx.toString() else: print "Exc %s != subclass of java.sql.SQLException!" % jlx.toString() Run that and let us know what the output is. -- alan kennedy ------------------------------------------------------ email alan: http://xhaus.com/contact/alan From ialbert at mailblocks.com Fri Aug 20 09:30:21 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Fri, 20 Aug 2004 09:30:21 -0400 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: Paul McGuire wrote: > The significant alternatives have been listed on the Python wiki at > http://www.python.org/moin/PythonDecorators . This page lists all the choices and not just the alternatives. > I would propose a multivote survey: each poster gets 3 votes among the > lettered choices on the Wiki page above. You can use all 3 for a single > option, or split them across 2 or 3 options if you are open to more than > one. I have noticed that many people thought (or implied) that they should be voting only for alternatives. Others voted for the the existing implementation. This makes this poll even more unreliable than usually. I don't think one should ever devise a poll to test for *second* options only. The second option only makes sense in proper context when compared to the first option. As more an more syntaxes came up and faced with increasingly hairy syntaxes and heated arguments I start to believe that Guido's choice is actually the best. A1 E1 Istvan. From __peter__ at web.de Sat Aug 21 06:48:57 2004 From: __peter__ at web.de (Peter Otten) Date: Sat, 21 Aug 2004 12:48:57 +0200 Subject: Rita Sue and Bob too References: <7tKdndVxj-WwurvcRVn-gA@powergate.ca> Message-ID: Peter Hansen wrote: > M. Clift wrote: > >> If I wasn't happy enough already with the examples/ideas you've all shown >> me, how about searching as previously, but where the middle name could be >> anything. i.e. 'Rita', 'anyname','Bob' > > How about this? (may need more test cases, and then perhaps fixes): A properly crafted test suite invites refactoring :-) class Anything: '''wildcard: matches anything''' def __eq__(self, other): return True Anything = Anything() # bad style, I know def sliceIndex(seq, sub, start=0): '''search starting at 'start' for sub in seq, return index of match or -1''' try: i = seq.index(sub[0], start) while i >= 0: if seq[i:i+len(sub)] == sub: return i i = seq.index(sub[0], i+1) except ValueError: pass return -1 > def test(): > case1 = ['Rita', 'Sue', 'Bob'] > alist = 'Rita Mary Jane Bob Sue Carl Hans Rita Bob Sue'.split() > assert sliceIndex([], case1) == -1 > assert sliceIndex(alist, case1) == -1 > > alist = 'Rita Mary Jane Bob Rita Carl Bob Hans Rita Sue Bob Sue > Rita Sue Bob'.split() > assert sliceIndex(alist, case1) == 8 > assert sliceIndex(alist, case1, 9) == 12 > assert sliceIndex(alist, case1, 13) == -1 > > case2 = ['Rita', Anything, 'Bob'] > assert sliceIndex(alist, case2) == 4 > assert sliceIndex(alist, case2, 5) == 8 > assert sliceIndex(alist, case2, 9) == 12 > > > if __name__ == '__main__': > test() From in.aqua.scribis at nl.invalid Mon Aug 30 16:12:04 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Mon, 30 Aug 2004 22:12:04 +0200 Subject: Search for AVI file? In-Reply-To: References: Message-ID: John Doe schreef: > I realise that this is not really a python question, but python's the > only language I'd be comfortable trying to deal with this. > > What I need is to search a drive and find all the AVI format files > that are NOT listed with the AVI extension. I'm looking over an old > drive of mine from an old computer. I know the files were renamed > with the wrong extension, but I know that they were originally AVI > files. Can python do this for me? Any hints? Anybody have a link to > something that would already do this? I appreciate any help. Use walk() to find all files. Open each file and read in the first 12 bytes. The last four of those 12 bytes should be 'AVI ', if I'm not mistaken. -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html The Halloween Documents: http://www.opensource.org/halloween/ From godoy at ieee.org Mon Aug 30 07:41:45 2004 From: godoy at ieee.org (Jorge Godoy) Date: Mon, 30 Aug 2004 08:41:45 -0300 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <1LMXc.67190$UTP.37420@twister01.bloor.is.net.cable.rogers.com> <1gj7a9r.g7ec5a1g89rj0N%aleaxit@yahoo.com> Message-ID: Just writes: > In article , Jorge Godoy > wrote: > >> Just writes: >> >> > But since .pyc's are always generated in the same directory as the .py >> > files, where else would you expect them to be generated? >> >> At the directory where the zip archive is stored. > > How does that follow? The zip archive _itself_ is the "directory" where > the .py files are, why would Python suddenly choose to write .pyc files > one level up? And what about packages? It simply doesn't work that way. Because the implementation that allowed to unzip the "directory" and find the files in there would also allow to place the '.pyc' in a different place such as the real directory where the zip file resides. Python didn't use to open zip files also, and now it does. I don't see nothing wrong with making it also writing the '.pyc' files. Do you? -- Godoy. From rogerb at rogerbinns.com Sat Aug 14 02:36:56 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Fri, 13 Aug 2004 23:36:56 -0700 Subject: Py2exe Question - Deployment Advice References: Message-ID: Dave Guenthner wrote: > For Perl, I used the Perl2exe product and I was simply given one file > .exe to distribute. Has anyone one else run into this before / > experienced that. Is there a way to have just one file? I believe the McMillan installer does that. (It actually "cheats" and effectively unpacks itself into a temp directory every time you run the program). I actually just use InnoSetup to distribute my program. That also takes care of things like putting icons in the menus and providing an uninstall entry in the Control Panel, as well as upgrades. The simple technical reason why there are multiple files is because the Python implementors put the mandatory functionality into the main dll, and have the seperate ones for optional functionality such as regular expressions, sockets, CSV, XML etc. Under the hood py2exe uses modulefinder. modulefinder finds every module your program could potentially use. For example, if you use URLs and the url library, that library references the SSL library. modulefinder will include both, even though you may never use an SSL based url. If you know for certain that you don't use certain functionality, then feel free to tell py2exe/modulefinder that you don't want particular modules. However you need to be very certain :-) Roger From kbk at shore.net Wed Aug 25 00:03:32 2004 From: kbk at shore.net (Kurt B. Kaiser) Date: Wed, 25 Aug 2004 00:03:32 -0400 (EDT) Subject: Weekly Python Bug/Patch Summary Message-ID: <200408250403.i7P3x0F8020069@h006008a7bda6.ne.client2.attbi.com> Patch / Bug Summary ___________________ Patches : 259 open ( -5) / 2573 closed (+17) / 2832 total (+12) Bugs : 745 open ( +0) / 4405 closed (+21) / 5150 total (+21) RFE : 150 open ( +1) / 130 closed ( +0) / 280 total ( +1) New / Reopened Patches ______________________ Patch for bug 933795. term.h and curses on Solaris (2004-08-19) http://python.org/sf/1012280 opened by Ariel Arjona PEP 292 implementation (2004-08-22) http://python.org/sf/1014055 opened by Barry A. Warsaw Rational.py various bugfixes (2004-08-19) http://python.org/sf/1012468 opened by Russell Blau cStringIO's truncate doesn't (2004-08-20) CLOSED http://python.org/sf/1012740 opened by Dima Dorfman Fix for duplicate attributes in generated HTML (2004-08-20) http://python.org/sf/1013055 opened by Richard Brodie Cleanup Peepholer Output (2004-08-22) CLOSED http://python.org/sf/1013667 opened by Raymond Hettinger Implementation for PEP 318 using syntax J2 (2004-08-22) http://python.org/sf/1013835 opened by Michael RobotFileParser.can_fetch return value (2004-08-23) CLOSED http://python.org/sf/1014237 opened by George Yoshida Expose current parse location to XMLParser (2004-08-24) http://python.org/sf/1014930 opened by Dave Cole bug in tarfile.ExFileObject.readline (2004-08-24) http://python.org/sf/1014992 opened by GaryD Improve markup and punctuation in libsocket.tex (2004-08-24) http://python.org/sf/1015012 opened by Dima Dorfman Docs claim that coerce can return None (2004-08-24) http://python.org/sf/1015021 opened by Dima Dorfman Patches Closed ______________ baseinteger: abstract superclass for int and long (2004-08-11) http://python.org/sf/1007068 closed by nnorwitz Improve error reporting when Python opens source code (2004-08-19) http://python.org/sf/1011822 closed by loewis Add Py_InitializeEx to allow embedding without signals. (2004-02-19) http://python.org/sf/900727 closed by loewis implementation of Text.dump method (2002-04-19) http://python.org/sf/546244 closed by loewis Return new string for single subclass joins (Bug #1001011) (2004-08-11) http://python.org/sf/1007087 closed by rhettinger cStringIO's truncate doesn't (2004-08-20) http://python.org/sf/1012740 closed by tim_one Bad URL encoding in SimpleHTTPServer directory listing (2004-08-18) http://python.org/sf/1011123 closed by jlgijsbers doctest: add a special (dedented) marker for blank lines (2004-04-11) http://python.org/sf/933238 closed by jlgijsbers incorrect end-of-message handling in mailbox.BabylMailbox (2004-01-20) http://python.org/sf/880621 closed by jlgijsbers (bug 1005936) textunderscore python.sty fix (2004-08-14) http://python.org/sf/1009373 closed by nnorwitz Cleanup Peepholer Output (2004-08-22) http://python.org/sf/1013667 closed by rhettinger Non-ascii in non-unicode __credits__ in Lib/pydoc.py (2004-08-15) http://python.org/sf/1009389 closed by loewis Allow pydoc to work with XP Themes (.manifest file) (2004-07-25) http://python.org/sf/997284 closed by loewis LC_CTYPE locale and strings (2004-07-26) http://python.org/sf/997768 closed by loewis Installation database patch (2002-05-29) http://python.org/sf/562100 closed by akuchling RobotFileParser.can_fetch return value (2004-08-23) http://python.org/sf/1014237 closed by loewis thread Module Breaks PyGILState_Ensure() (2004-08-17) http://python.org/sf/1010677 closed by mhammond New / Reopened Bugs ___________________ dictionary referencing error (2004-08-19) CLOSED http://python.org/sf/1012249 opened by AMIT Consulting LLC weakref.WeakValueDictionary should override .has_key() (2004-08-19) CLOSED http://python.org/sf/1012315 opened by Myers Carpenter ctrl-left/-right works incorectly with diacritics (2004-08-19) http://python.org/sf/1012435 opened by Krzysztof Wilkosz Can't pipe input to a python program (2004-08-20) CLOSED http://python.org/sf/1012692 opened by Ronald L. Rivest xmlrpclib, PEP291, "yield" (2004-08-16) CLOSED http://python.org/sf/1009803 reopened by anthonybaxter Python Tutorial 3.1.4 List example (2004-08-20) CLOSED http://python.org/sf/1013239 opened by Elizibeth Thompson Win XP DEP prevents Python call to 'C' DLL (2004-08-21) CLOSED http://python.org/sf/1013418 opened by ajhewitt xml.dom documentation omits createDocument, ...DocumentType (2004-08-21) http://python.org/sf/1013525 opened by Mike Brown Error in Chapter 4 of Tutorial (2004-08-22) CLOSED http://python.org/sf/1013760 opened by Alexey Peshehonov No documentation for PyFunction_* (C-Api) (2004-08-22) http://python.org/sf/1013800 opened by Henning G?nther tarfile.open with mode w|bz2 (2004-08-22) CLOSED http://python.org/sf/1013882 opened by Felix Wiemann Error in representation of complex numbers (2004-08-22) CLOSED http://python.org/sf/1013908 opened by Raymond Hettinger mimetypes add_type has bogus self parameter (2004-08-22) http://python.org/sf/1014022 opened by Cliff Wells Unspecific errors with metaclass (2004-08-23) http://python.org/sf/1014215 opened by Thomas Heller optparse: parser.remove_option("-h") inconsistency (2004-08-23) http://python.org/sf/1014230 opened by strop Missing urllib.urlretrieve docs (2004-08-23) http://python.org/sf/1014761 opened by David Abrahams Misc/NEWS no valid reStructuredText (2004-08-24) http://python.org/sf/1014770 opened by Felix Wiemann Misc/NEWS.help (2004-08-24) http://python.org/sf/1014775 opened by Felix Wiemann "article id" in description of NNTP objects (2004-08-24) http://python.org/sf/1015140 opened by Felix Wiemann cgi.FieldStorage.__len__ eventually throws TypeError (2004-08-24) http://python.org/sf/1015249 opened by Andreas Ames Create cgi.FieldStorage._get_new_instance method as factory (2004-08-24) http://python.org/sf/1015254 opened by Andreas Ames readline broken (2004-08-24) CLOSED http://python.org/sf/1015517 opened by Walter D?rwald Bugs Closed ___________ dictionary referencing error (2004-08-19) http://python.org/sf/1012249 closed by rhettinger weakref.WeakValueDictionary should override .has_key() (2004-08-19) http://python.org/sf/1012315 closed by rhettinger str.join([ str-subtype-instance ]) misbehaves (2004-07-30) http://python.org/sf/1001011 closed by rhettinger compile errors on _codecs_iso2022.c (2004-08-09) http://python.org/sf/1005737 closed by perky SGI (IRIX 6.5.24) Error building _codecs_iso2022.c (2004-08-11) http://python.org/sf/1007249 closed by perky Warning in cjkcodecs/iso2022common.h (2004-07-16) http://python.org/sf/991834 closed by perky test_queue fails occasionally (2004-08-17) http://python.org/sf/1010777 closed by mwh Can't pipe input to a python program (2004-08-20) http://python.org/sf/1012692 closed by tim_one xmlrpclib, PEP291, "yield" (2004-08-16) http://python.org/sf/1009803 closed by loewis xmlrpclib, PEP291, "yield" (2004-08-16) http://python.org/sf/1009803 closed by loewis logging.getLevelName returns a number (2004-08-12) http://python.org/sf/1008295 closed by vsajip Python Tutorial 3.1.4 List example (2004-08-21) http://python.org/sf/1013239 closed by perky optparse indents without respect to $COLUMNS (2004-01-16) http://python.org/sf/878453 closed by jlgijsbers Win XP DEP prevents Python call to 'C' DLL (2004-08-21) http://python.org/sf/1013418 closed by loewis Index entries with "_" are wrong in pdf file (2004-08-09) http://python.org/sf/1005936 closed by nnorwitz xmlrpclib and backward compatibility (2003-11-15) http://python.org/sf/842600 closed by loewis Error in Chapter 4 of Tutorial (2004-08-22) http://python.org/sf/1013760 closed by rhettinger tarfile.open with mode w|bz2 (2004-08-22) http://python.org/sf/1013882 closed by loewis Error in representation of complex numbers (2004-08-22) http://python.org/sf/1013908 closed by loewis Cmd in thread segfaults after Ctrl-C (2004-06-06) http://python.org/sf/967334 closed by mwh 2.3.4 fails build on solaris 10 - complexobject.c (2004-06-10) http://python.org/sf/970334 closed by mwh readline broken (2004-08-24) http://python.org/sf/1015517 closed by nnorwitz New / Reopened RFE __________________ Standard exceptions are hostile to Unicode (2004-08-20) http://python.org/sf/1012952 opened by Marius Gedminas From jerf at jerf.org Fri Aug 27 12:55:28 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Fri, 27 Aug 2004 16:55:28 GMT Subject: Class Friends References: <20040827081556.657c3fac.a@c.d> Message-ID: On Fri, 27 Aug 2004 15:19:53 +0000, Sean Don wrote: > > Hello! > > Is it possible to make classes friends in Python? Or is it better to just stick > to "Java style" .isThis, .getThat, .setThis style functions? > > I understand that classes are generally grouped logically into separate files > anyway. So, this isn't always necessary. But I'm a perfectionist and was > wondering if friendships were possible in Python. In Python, there isn't much of an idea of "Private"; Python's philosophy is "We're all consenting adults here." Thus, there isn't much of an idea of "friends" either. In Java terminology, on a technical level everybody is already friends with everybody else already. Ultimately, it is the human meaning of "friendship" that is more important (classes that twiddle with other classes internals), and Python allows you to deal with that as you see fit. In all my years of Python programming, only once have I generated a "friend" class in the human sense. Generally there are ways around it. As a final note, don't use 'getThat' or 'setThis'; that's a hack around Java's weaknesses. Look up "property" in the Python manual and use that; it is good both for re-factoring classes and for new ones too. This is one reason that Python "gets away with" the way it works; unless you go out of your way to break a class's encapsulation, the class author can always catch things like attribute access with a property. class MyXActsStrange(object): def __init__(self): self._x = 0 def getX(self): return self._x + 1 def setX(self, val): self._x = val x = property(getX, setX) >>> a = MyXActsStrange() >>> a.x 1 >>> a.x = 4 >>> a.x 5 Very useful. (Some people would use "self.__x", to get the psuedo-private name munging invoked. My call is if the "security" isn't perfect there isn't much point, as the language is already depending on the client programmer to behave. I think Java can get good security but C++ is already effectively as permissive as Python, it just makes the hoops harder.) From ods at strana.ru Mon Aug 23 12:13:09 2004 From: ods at strana.ru (Denis S. Otkidach) Date: Mon, 23 Aug 2004 20:13:09 +0400 Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: <20040823201309.2669937a.ods@strana.ru> On Thu, 19 Aug 2004 22:35:53 GMT Roel Schroeven wrote: > Roel Schroeven wrote: > > > I spotted some errors in your list, added new entries, and made a > > histogram: http://roelschroeven.net/pythonages/ I'm 29 -- Denis S. Otkidach http://www.python.ru/ [ru] From gmcclure at gmail.com Fri Aug 6 04:16:18 2004 From: gmcclure at gmail.com (Greg McClure) Date: 6 Aug 2004 01:16:18 -0700 Subject: Quixote vs. Preppy References: <1779534897.20040805105519@MailBlocks.com> Message-ID: <9a4845b3.0408060016.25339856@posting.google.com> Don't forget Webware (http://www.webwareforpython.org)! It interfaces nicely with Cheetah (http://www.cheetahtemplate.org) and has an application server/servlet model of development which, for anyone experienced with Tomcat for example, is very easy to learn and get going with. I've developed two sites with this software and I'm pretty much in love, although since I haven't tried Quixote yet I can't compare/contrast them. Webware has an active mailing list though and the community is very responsive and helpful. Peace, GM From tchur at optushome.com.au Fri Aug 20 16:47:49 2004 From: tchur at optushome.com.au (Tim Churches) Date: 21 Aug 2004 06:47:49 +1000 Subject: I know SAS (sort of)...now, PYTHON In-Reply-To: References: Message-ID: <1093034869.1237.11.camel@emilio> On Sat, 2004-08-21 at 05:36, Alex Pavluck wrote: > Hello. I use SAS on a daily basis and it has peaked my interest in > learning other programming languages. Are there any good > websites/online books that can help someone go from zero knowledge of > python and programming to beginner level through exercises? I have been using SAS for 13 years, and although I also used Visual Basic and Perl, I still thought that SAS had something to offer as a data manipulation and programming environment. But then I was introduced to Python about 4 years ago, and it was a road to Damascus experience - the scales fell from my eyes and I realised just how sprawling and laden with historical baggage the SAS suite really is - a real dog's breakfast (mostly effective, but incredibly inelegant). And then there is the annual cost of licenses... Anyway, there are now many good books on Python, and several free tutorials and more extensive introductions (such as "Dive into Python"), but as a starting place, I very strongly recommend "Learning Python" by Lutz and Ascher, published by O"Reilly. My son calls it "the rat book". See http://www.oreilly.com/catalog/lpython2/ -- Tim C PGP/GnuPG Key 1024D/EAF993D0 available from keyservers everywhere or at http://members.optushome.com.au/tchur/pubkey.asc Key fingerprint = 8C22 BF76 33BA B3B5 1D5B EB37 7891 46A9 EAF9 93D0 From sdeibel at wingware.com Tue Aug 17 22:12:13 2004 From: sdeibel at wingware.com (Stephan Deibel) Date: Tue, 17 Aug 2004 22:12:13 -0400 (EDT) Subject: Python Success Stories Update Message-ID: Hi, I just wanted to let y'all know that the Python Success Stories collection has nine new additions: http://www.pythonology.com/success These 28 stories include significant testimonials that can make it easier to sell technical decision-makers (i.e., your boss) on Python. Whether you're building an online singles community or an air traffic control system -- be sure to check it out! Also In Print ------------- Twelve stories, including the new ones, have been included in the second O'Reilly Python Success Stories booklet, which recently went into print and should be available at O'Reilly exhibit booths at conferences. Thanks, Stephan Deibel -- Wingware Wing IDE for Python Advancing Software Development www.wingware.com From bokr at oz.net Wed Aug 25 16:26:26 2004 From: bokr at oz.net (Bengt Richter) Date: 25 Aug 2004 20:26:26 GMT Subject: Radical: listing decorators compared to atexit function registration Message-ID: Still looking for a unifying concept ;-) It struck me that @deco1 @deco2 def foo():pass uses '@' to register at-next-name-binding processing in a way similar to atexit's registering of processing to happen at ('@' ;-) exit. IOW, it is setting up processing for an event (synchronous in this case) that is expected to happen in the future. I like that meaning of '@' -- i.e., @event_handler_defining_expression seems like a nice general reading of an 'at'-symbol. In the case of function decoration, the event is implicitly the completion of the execution of next-in-code-sequence function definition, intercepting just before name-binding. And a chain of interceptions works in order. In the case of current decorators, deco1 etc must be expressions resulting in functions. By default, the functions are hooked into a chain of at-next-name-binding processing that gets triggered by the def name binding. This is the current use case. However, the broader concept is for @expression to cause registration of a generalized event handler into an event recognition/handling mechanism. The concept can be embellished with one-shot vs repeated and with or without timeout, multiple events, etc., but leave that for later, so long as the door is not closed to it. If @expression evaluating to a function defaults to a certain meaning, it should be possible to spell it out using a compatible general and full spelling. OTTOMH ISTM that the natural alternative to returning a function or ordinary callable would be to return an object that the infrastructure would recognize and register into the appropriate alternative event-handling place. One way would be if the object were marked in a similar way that an object gets marked as a descriptor (which happens with a __get__ method etc). Perhaps __handler__ ? Thus you could write a class with a __handler__ method and instantiate it with info re what event to recognize and other particulars. Then decorator syntax spelled out might look (in concept, this is not a design spec ;-) like: @my_next_binding_handler(func=deco1, event='before_next_local_binding') @my_next_binding_handler(func=deco2, event='before_next_local_binding') def foo():pass Note that you could potentially define object attribute access events and have another way to define properties, if you passed info to your handler constructor specifying name and namespace. Obviously the infrastructure would have to grow some event-handling and relevant registration etc magic. This is essentially a push to start thinking about bringing generalized event-driven programming nicely into python. I'm suggesting that decorators can be seen as special one-shot event handlers for a local binding event. A GUI is obviously a source of many user action events, and a way to say @mouseover('this','that') to instantiate and register some code might be neat. Ditto for i/o related events. This brings in thread issues though, and event queuing etc. But that can be deferred. We can just deal with synchronous events for the time being. Hm... recoverable exceptions anyone ;-) OTOH, this may all just be a symptom of attempted personal stress escape ;-) Regards, Bengt Richter From h.b.furuseth at usit.uio.no Mon Aug 2 11:45:52 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 02 Aug 2004 17:45:52 +0200 Subject: __coerce__ vs. new-style classes Message-ID: Why do new-style classes disable __coerce__()? It seems cumbersome to have to write a whole set of methods (e.g. __add__, __radd__, etc.) to get the same effect. Is there some way to automatically generate those methods, or are we simply not supposed to do coercion for some reason? -- Hallvard From jack at performancedrivers.com Wed Aug 4 12:19:42 2004 From: jack at performancedrivers.com (Jack Diederich) Date: Wed, 4 Aug 2004 12:19:42 -0400 Subject: ANN: libgmail 0.0.7 - Gmail access via Python - Now with FTP Proxy! In-Reply-To: References: Message-ID: <20040804161942.GA22706@performancedrivers.com> Does anyone else keep getting CVS commit emails for libgmail? Seriously, it is great that you are doing stuff and sharing it but we don't need a status update every three days. Freshmeat.net and the libgmail mailing list are both good places to post incremental updates. -Jack On Mon, Aug 02, 2004 at 12:04:41PM -0700, Follower wrote: > libgmail -- Python binding for Google's Gmail service > * Demo FTP proxy enables marked Gmail message attachments to be > download via FTP. > > * Implemented sending & receiving of message attachments. > > * Updated SMTP Proxy demo to handle sending attachments. > > * Added 'getMessagesByQuery' function. > > Major changes since 0.0.5: (Repeated from last announcement) > > * Implemented SMTP proxy to enable Gmail to be send with a > standard mail client via (E)SMTP. > > * Extended standard SMTP class to handle ESMTP EHLO & AUTH PLAIN commands. > > * Utility function '_retrieveJavascript' to retrieve current version > of Gmail Javascript file. (By request.) > > >

    libgmail 0.0.7 - The > `libgmail` project is a pure Python binding to provide access to > Google's Gmail web-mail service; includes SMTP & FTP > proxies. (03-Aug-04)

    > -- > http://mail.python.org/mailman/listinfo/python-list > From afriere at yahoo.co.uk Wed Aug 11 02:47:16 2004 From: afriere at yahoo.co.uk (Asun Friere) Date: 10 Aug 2004 23:47:16 -0700 Subject: Python equivalent to a C trick References: <1d7b6d0d.0408092255.1177908e@posting.google.com> <41189FD5.7516D933@alcyone.com> Message-ID: <38ec68a6.0408102247.45d79ed2@posting.google.com> Erik Max Francis wrote in message news:<41189FD5.7516D933 at alcyone.com>... > Thomas Kr?ger wrote: > > > Logic_Test and True_Result or False_Result > > > > Example: > > print (num_eggs > 1) and 'eggs" or "egg" > > Be very careful that the "True_Result" in your formulation actually is > itself a Python true value, or this won't work: > > print 'egg' + (numEggs == 1 and '' or 's') > > will not work as expected. For which reason the form (test and [true_result] or [false_result])[0] is sometimes advocated. This starts to look a little too cluttered for my liking, so I tend to use it only when the 'true_result' is a variable and might be instantiated to a negative value. From firemoth at gmail.com Sun Aug 15 02:31:37 2004 From: firemoth at gmail.com (Timothy Fitz) Date: 14 Aug 2004 23:31:37 -0700 Subject: The winner of the Python Decorator Poll is... References: <4edc17eb.0408112052.1bbd85b3@posting.google.com> <59e9fd3a04081122235b3d9145@mail.gmail.com> Message-ID: <972ec5bd.0408142231.7089175a@posting.google.com> Anthony Baxter wrote in message news:... > On Thu, 12 Aug 2004 15:23:22 +1000, Andrew Durdin wrote: > > Since you like the current proposal, why *didn't* you vote for it (it > > was the first one)? > > I didn't vote, because voting is a stupid way to design a language. In general yes, but if the alternative is pick one at random (which is where Guido was when @ was picked, or so it sounds) I think voting is preferable. From paolo_veronelli at yahoo.it Wed Aug 11 15:38:48 2004 From: paolo_veronelli at yahoo.it (paolo veronelli) Date: Wed, 11 Aug 2004 21:38:48 +0200 Subject: Rather than decorators, how about sections? In-Reply-To: References: <1C74C038-EBB6-11D8-8889-000A95857E5C@eischet.com> Message-ID: On Wed, 11 Aug 2004 13:10:53 -0400, Paul Morrow wrote: > Stefan Eischet wrote: > >> Hi, >> >> do we really need this stuff just to say "staticmethod" and >> "classmethod"? How about: >> >> class Foo(object): >> def baz(): >> print "Static Method" >> def bar(self): >> print "Method" >> def spam(Foo): >> print "Class Method" >> > > I like it! It's simple, clear, ... Why isn't this the hands-down best > solution? Why do we want to be more verbose than necessary? > > I wonder if there are people out there who've chosen something other > than *self* for the 1st arg (shame on them if they did! ) who's > code this would break. I've never understood why we didn't require that > it be called self in the first place --- why give them more than one way > to do *that*? > I do and I'm happy with that .Actually it took me a while to understand that self was just the medio man choice which I really use now only for the others. I usually use capitalized names for classes and same name not capitalized as first argument ,after a while it became much easy for me to understand where I was reading in the code .... now should I say shame on you because you like self? Take it easy with words and have fun. Paolino -- ....lotta dura per la verdura From martindemello at yahoo.com Wed Aug 25 16:25:07 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Wed, 25 Aug 2004 20:25:07 GMT Subject: Why return None? References: Message-ID: Ayose wrote: > > If you can use python 2.3 or newer, try with [::-1] > > >>> def f(m, n): > ... print (m + n)[::-1] > ... > >>> f([1,2,3], [10,20,30]) > [30, 20, 10, 3, 2, 1] Thanks! Where can I look this up? martin From peter at engcorp.com Fri Aug 6 13:47:59 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 06 Aug 2004 13:47:59 -0400 Subject: Killing children In-Reply-To: <87smb0w4ln.fsf@debian.laymusic.org> References: <87smb0w4ln.fsf@debian.laymusic.org> Message-ID: Laura Conrad wrote: > I'm writing an application that has to spawn some processes and then > kill them later. It doesn't need to talk or listen to them while > they're running, but there are stop and start buttons and the stop > button should stop everything that gets started by the start button. > > There are lots of ways to do this on Linux, but this project has to > run under cygwin. So far, the only thing I've gotten to work at all > under cygwin is doing an 'os.system' to start the process and then > parsing the "ps" output and using os.kill on the processes that ps > finds. This is unsatisfactory in a number of ways. > > I have been unable to get os.spawnl to start the processes correctly. > I was using pexpect, which worked fine with test programs, but not > with the actual processes that need to be spawned. I did a little bit > of playing with the "process" module but didn't get it working right. > > Does anyone have a better idea? This has been successful in some cases: if sys.platform == 'win32': def _kill(pid, sig): '''pid is actually handle, but that's what os.spawn* returns on Win32''' import win32api win32api.TerminateProcess(pid, 0) # ignore sig, 0 is return code for process import os os.kill = _kill del _kill It requires win32api, and I don't know how that all will work with cygwin (which I don't use). Basically it lets you use os.kill() in a platform-independent fashion (provided you care only about Linux and Windows NT/XP/2K ;-). -Peter From me at privacy.net Fri Aug 27 14:29:55 2004 From: me at privacy.net (Richard Hanson) Date: Fri, 27 Aug 2004 11:29:55 -0700 Subject: MSI Installer Problem: can't install 2.4a2 on new install of Win2kSP2 References: <412d7dcd$0$26184$9b622d9e@news.freenet.de> <412e5452$0$24835$9b622d9e@news.freenet.de> Message-ID: <92uui05l49lurff1depfmvblq8esqllcpg@4ax.com> Thanks to the guidance from Martin and Dennis, I *think* that my problem is finally at least fully worked around -- meaning Python 2.3.4 on a separate Win98 partition can now coexist with Python 2.4a2 on the Win2k partition. Booting into either OS and the respectively installed Python's IDLE now works. But, I had to pull "C:\Python23" out of my Win98's PATH to make it work. Don't know why that was there -- a fresh install of Python 2.3.4 on my Win98 partition now works (IDLE, anyway) without that entry in Win98's PATH. And, I don't know why my Win2k or my Python 2.4a2 on Win2k even cares about my Win98's PATH. For academic purposes, there may be information below that still suggests some strangeness (at least to me and my machine) re PATH on Windows, or re having Python in another OS's PATH variable, or both. So, if you have the time and are interested, read on: Martin v. L?wis wrote: >Richard Hanson wrote: >> If I have a directory named "Python23" with *only* the immediate >> contents of "Lib" in it (no other files or directories nor any of >> Lib's sub-dirs) in a separate Win98 partition, then IDLE doesn't run. >> However, if I rename or move that dir inside another dir, then IDLE >> runs. I can move that subsetted Python23 dir back and forth between >> being hidden inside another dir and being in the root, without >> rebooting, and IDLE works or not, depending on the visibility of that >> very limited subset of the normal Python23 install directory. > >Could it be that you have an environment variable PYTHONHOME or >PYTHONPATH set? I checked that yesterday. No PYTHONHOME nor PYTHONPATH set in Win2k's environment variables. I checked using Two Of The Many Ways To Do The Same Thing so common with Windows: by right-clicking on "My Computer" and then selecting Properties | Advanced | Environment Variables, and by using System Information. I found for my PATH variable: %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\WBEM However... Dennis Lee Bieber wrote: > Check for your search path definition(os.environ["PATH"]). It >sounds like the W98 partition is being found before the full install >directory, and as a result, it fails to locate some files... Following Dennis's lead and using Python 2.4a2 (with C:\Python23 hidden) to get the environment, today I got the Win2k PATH with the Win98 PATH concatenated to it (I subsequently rebooted into Win98 on C: and confirmed its PATH): E:\\WINNT\\system32;E:\\WINNT;E:\\WINNT\\system32\\WBEM;C:\\WINLICKS; C:\\WINLICKS\\COMMAND;C:\\Python23\\;C:\\PROGRA~1\\GRISOFT\\AVG6; C:\\PROGRA~1\\COMMON~1\\AUTODE~1 ("WINLICKS" was what I originally named the Windows dir in the Win98 partition a while ago when I first installed it -- at the time, I may have been a bit frustrated with Windows. [Or, is being frustrated with Windows somewhat of a tautology? ]) Also today, I tried getting my Win2k environment using Yet Another Way -- from a Win2k console by typing in "path" -- and got the same two-OSes-concatenated, system-variables-expanded version shown immediately above. Martin v. L?wis wrote: >As for the console being mostly broken: what precisely does that mean? >If you run cmd.exe, and start c:\python24\python.exe, what happens? >What happens if you add a -v option to python.exe? I also tried that, yesterday, after reading a post from Tim Peters to John J. Lee (thread started with <1xhtg1xm.fsf at pobox.com>). In case it has any academic value, here's the full output (with C:\Python23 visible in the root of C) from yesterday: | E:\Python24>python -v | # installing zipimport hook | import zipimport # builtin | # installed zipimport hook | # C:\Python23\Lib\site.pyc matches C:\Python23\Lib\site.py | import site # precompiled from C:\Python23\Lib\site.pyc | # C:\Python23\Lib\os.pyc matches C:\Python23\Lib\os.py | import os # precompiled from C:\Python23\Lib\os.pyc | import nt # builtin | # C:\Python23\Lib\ntpath.pyc matches C:\Python23\Lib\ntpath.py | import ntpath # precompiled from C:\Python23\Lib\ntpath.pyc | # C:\Python23\Lib\stat.pyc matches C:\Python23\Lib\stat.py | import stat # precompiled from C:\Python23\Lib\stat.pyc | # C:\Python23\Lib\UserDict.pyc matches C:\Python23\Lib\UserDict.py | import UserDict # precompiled from C:\Python23\Lib\UserDict.pyc | # C:\Python23\Lib\copy_reg.pyc matches C:\Python23\Lib\copy_reg.py | import copy_reg # precompiled from C:\Python23\Lib\copy_reg.pyc | # C:\Python23\Lib\types.pyc matches C:\Python23\Lib\types.py | import types # precompiled from C:\Python23\Lib\types.pyc | # C:\Python23\Lib\locale.pyc matches C:\Python23\Lib\locale.py | import locale # precompiled from C:\Python23\Lib\locale.pyc | import _locale # builtin | # C:\Python23\Lib\codecs.pyc matches C:\Python23\Lib\codecs.py | import codecs # precompiled from C:\Python23\Lib\codecs.pyc | import _codecs # builtin | import encodings # directory C:\Python23\Lib\encodings | # C:\Python23\Lib\encodings\__init__.pyc matches C:\Python23\Lib\encodings\__ini | t__.py | import encodings # precompiled from C:\Python23\Lib\encodings\__init__.pyc | # C:\Python23\Lib\re.pyc matches C:\Python23\Lib\re.py | import re # precompiled from C:\Python23\Lib\re.pyc | # C:\Python23\Lib\sre.pyc matches C:\Python23\Lib\sre.py | import sre # precompiled from C:\Python23\Lib\sre.pyc | # C:\Python23\Lib\sre_compile.pyc matches C:\Python23\Lib\sre_compile.py | import sre_compile # precompiled from C:\Python23\Lib\sre_compile.pyc | import _sre # builtin | # C:\Python23\Lib\sre_constants.pyc matches C:\Python23\Lib\sre_constants.py | import sre_constants # precompiled from C:\Python23\Lib\sre_constants.pyc | 'import site' failed; traceback: | Traceback (most recent call last): | File "C:\Python23\Lib\site.py", line 304, in ? | import locale, codecs | File "C:\Python23\Lib\codecs.py", line 692, in ? | strict_errors = lookup_error("strict") | File "C:\Python23\Lib\encodings\__init__.py", line 30, in ? | import codecs, exceptions, re | File "C:\Python23\Lib\re.py", line 5, in ? | from sre import * | File "C:\Python23\Lib\sre.py", line 97, in ? | import sre_compile | File "C:\Python23\Lib\sre_compile.py", line 17, in ? | assert _sre.MAGIC == MAGIC, "SRE module mismatch" | AssertionError: SRE module mismatch | # C:\Python23\Lib\warnings.pyc matches C:\Python23\Lib\warnings.py | import warnings # precompiled from C:\Python23\Lib\warnings.pyc | # C:\Python23\Lib\re.pyc matches C:\Python23\Lib\re.py | import re # precompiled from C:\Python23\Lib\re.pyc | # C:\Python23\Lib\sre.pyc matches C:\Python23\Lib\sre.py | import sre # precompiled from C:\Python23\Lib\sre.pyc | # C:\Python23\Lib\sre_compile.pyc matches C:\Python23\Lib\sre_compile.py | import sre_compile # precompiled from C:\Python23\Lib\sre_compile.pyc | Python 2.4a2 (#55, Aug 5 2004, 11:42:43) [MSC v.1310 32 bit (Intel)] on win32 | Type "help", "copyright", "credits" or "license" for more information. All those references to "C:\Python23" were what originally led me to focus on the Python 2.3 install in the Win98 partition. --- So, while I don't understand why having a separate OS on a different partition affected 2.4a2 on Win2k as above (remembering that 2.3.4 on Win2k worked fine with that configuration), I'm quite happy that I can now get back to using Python rather than trying to get my laptop "assembled." :-) In any event, a big hearty thanks once again -- very nice, helpful folks here! what's-a-good-Linux-distro-for-a-laptop-with-touchscreen-'ly y'rs, Richard -- email works if unmunged: sickolefartnewsguycom From meldron at meldron.org Wed Aug 25 05:53:06 2004 From: meldron at meldron.org (Bernd Kaiser) Date: Wed, 25 Aug 2004 11:53:06 +0200 Subject: urllib hangs In-Reply-To: References: Message-ID: <2p35phFg2vehU1@uni-berlin.de> I also would use a few Threads, they will speed up your script. Jay Donnell wrote: > This is a basic version of my code > > for url in urls: > fp = urllib.urlopen(url) > lines = fp.readlines() > > #print lines > for line in lines: > #print line > if(reUrl.search(line)): > print 'found' > return 1 > else: > print 'not found' > return 0 > > this hangs occasionally for some certain url's. If I do a ctrl-c > (linux) it will move on to the next url. How can I get this to timeout > and move on to the next url. From vincent at visualtrans.de Fri Aug 6 08:06:35 2004 From: vincent at visualtrans.de (vincent wehren) Date: Fri, 6 Aug 2004 14:06:35 +0200 Subject: [Python-Dev] RELEASED Python 2.4, alpha 2 References: <411231C8.3020308@interlink.com.au> <4113429a$0$26993$9b622d9e@news.freenet.de> Message-ID: "Martin v. L?wis" schrieb im Newsbeitrag news:4113429a$0$26993$9b622d9e at news.freenet.de... > Vincent Wehren wrote: > > What surprised me a little is that on Win XP I could install 2.4a2 as a user > > with restricted rights over a previously administrator-installed > > for-all-users 2.4a1 standard-paths-used installation without > > warnings/problems - well, except for the obvious errors writing to the > > registry (and yes, I tried it intentionally ;). I am not entirely on board > > with the MSI's capabilities, but is there a way to tell the user (before the > > registry errors happen), that he/she may have insufficient rights to > > install? > > I'm not quite sure I understand what you were doing, and in what way > this has surprised you. It seems > - you made a per-machine installation as the administrator True. > - you then upgraded as a restricted user (not being asked whether this > is going to be per-user or per-machine) True > > What *should* have happened is this: > - MSI finds that the new installation is per user, and the old > installation is per-machine, so no upgrade is possible Can't say, but I take your word for it ;) > - the UI then tells you that the target directory already exists, > and wants confirmation Yes. > - if you proceed, it overwrites the existing files, creating a > per-user installation (i.e. shortcuts in your profile, registry > keys in HKEY_CURRENT_USER) > > Are you saying that somebody else has happened instead? Well, writing a bunch of the registry keys fails. This user has no rights to write them and is greated with several error messages as in: "Could not write value to key HKEY_CURRENT_USER\Software\Classes\.py Verify that you have sufficient access to that key, or contact your support personnel." .. Same for .pyw, .pyc, *.pyo etc. .. Python.File\shell\open\command .. Python.NoConFile\shell\open\command .. Python.CompiledFile\shell .. Edit with Idle and so on. I was just wondering if the installer should be aware of the rights situation and not try to write those keys in the first place. -- Vincent > If not, in what way did that surprise you? > > Regards, > Martin From martin at v.loewis.de Fri Aug 27 15:42:53 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 27 Aug 2004 21:42:53 +0200 Subject: MSI Installer Problem: can't install 2.4a2 on new install of Win2kSP2 In-Reply-To: <92uui05l49lurff1depfmvblq8esqllcpg@4ax.com> References: <412d7dcd$0$26184$9b622d9e@news.freenet.de> <412e5452$0$24835$9b622d9e@news.freenet.de> <92uui05l49lurff1depfmvblq8esqllcpg@4ax.com> Message-ID: <412f8ebd$0$13030$9b622d9e@news.freenet.de> Richard Hanson wrote: > For academic purposes, there may be information below that still > suggests some strangeness (at least to me and my machine) re PATH on > Windows, or re having Python in another OS's PATH variable, or both. I'm not quite sure why you have the Win98 path in W2k, but it may be that W2k also executes certain autoexec things. > So, while I don't understand why having a separate OS on a different > partition affected 2.4a2 on Win2k as above (remembering that 2.3.4 on > Win2k worked fine with that configuration), I'm quite happy that I can > now get back to using Python rather than trying to get my laptop > "assembled." :-) That might be a subtle bug. Python tries to find out its own executable path name, in order to find the location to the Python installation. It considers two alternatives a) argv[0] contains a \. If so, python.exe was fully qualified, so we know the path. b) if there is no \, python.exe must be on the PATH. So we look there, and find one in C:\python23, and believe this is us. This logic is flawed, as we should *first* look into the current directory (I think) From then on, everything fails: we load the 2.3 library, which has a different sre version. So regular expressions don't work, and that causes pretty much everything to break. What surprises me, though, that this algorithm is *only* executed if GetModuleFileName fails, which should not happen in your case... Regards, Martin From peufeu at free.fr Thu Aug 5 11:52:51 2004 From: peufeu at free.fr (=?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?=) Date: Thu, 05 Aug 2004 17:52:51 +0200 Subject: checking whether a var is empty or not References: Message-ID: import inspect def isset(v): return v in globals() or v in inspect.currentframe().f_back.f_locals Why would you want that ? Use this PHP emulator : from (all installed modules...) import * If you want to emulate PHP, you should only use global variables, and don't forget to copy those into all the modules you import (and of course, update globals with all variables coming from all modules). From donnal at donnal.net Mon Aug 23 12:53:27 2004 From: donnal at donnal.net (Donnal Walter) Date: Mon, 23 Aug 2004 11:53:27 -0500 Subject: telnet 'connection reset by peer' Message-ID: On Windows XP I am able to connect to a remote telnet server from the command prompt using: telnet nnn.nnn.nnn.nnn 23 where nnn.nnn.nnn.nnn is the IP address of the host. But using telnetlib, this code returns the traceback that follows: import telnetlib host = 'nnn.nnn.nnn.nnn' tn = telnetlib.Telnet(host, 23) tn.read_until("Enter device name?") Traceback (most recent call last): File "C:\Python23\Lib\site-packages\mindwrapper\test\telnet.py", line 4, in ? tn.read_until("Enter device name?") File "C:\Python23\lib\telnetlib.py", line 316, in read_until self.fill_rawq() File "C:\Python23\lib\telnetlib.py", line 521, in fill_rawq buf = self.sock.recv(50) socket.error: (10054, 'Connection reset by peer') Is there some parameter that I need to set in order to connect using the telnetlib client? Thanks. Donnal Walter Arkansas Children's Hospital From DeadWisdom at wisefool.net Thu Aug 26 11:41:25 2004 From: DeadWisdom at wisefool.net (DeadWisdom) Date: 26 Aug 2004 08:41:25 -0700 Subject: object.* Message-ID: I think there should be an ability in python to write something like "object.*" which should return a dictionary object containing all the members and their values for the given object. Maybe ".*" could be treated as an operator. ::shrug:: Perhaps the functionality already exists in some other syntax; if so please splain. From jepler at unpythonic.net Fri Aug 20 22:34:15 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Fri, 20 Aug 2004 21:34:15 -0500 Subject: Feature Request: Current time in traceback In-Reply-To: References: Message-ID: <20040821023415.GA1458@unpythonic.net> In your application, you can use a top-level exception handler or set sys.excepthook to override the default way that exceptions are displayed. One example of this (which formats exceptions as HTML) is the standard module "cgitb". Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From dagan at portalen.no Mon Aug 9 14:04:17 2004 From: dagan at portalen.no (Dag Hansteen) Date: Mon, 9 Aug 2004 20:04:17 +0200 Subject: Question Message-ID: <200408092004.AA1750663468@portalen.no> >>> s = "2+2" >>> answer = int(str(s)) Traceback (most recent call last): File "", line 1, in ? answer = int(str(s)) ValueError: invalid literal for int(): 2+2 How do I this ? I have a string with a such expression and I want to return the answer in a variable. Regards Dag Hansteen (PS: sorry if I double post, dont know if I sent the other) From ajsiegel at optonline.com Fri Aug 13 00:36:29 2004 From: ajsiegel at optonline.com (Arthur) Date: Fri, 13 Aug 2004 04:36:29 GMT Subject: PEP 318 decorators are not Decorators References: Message-ID: On Fri, 13 Aug 2004 02:56:34 GMT, Arien Malec wrote: >I've been following the decorator debate with some interest, and it's taken >me a reasonably long time to understand what is meant by a decorator. One >of the issues is that the Decorator pattern is more like a Unix pipe than >it is what PEP 318 calls a decorator. The classic decorator is run-time, >rather than define time, and is non-destructive to the base function. The >PEP 318 decorator is define time and is a destructive change to the base >function. For instance, the GoF book makes it clear that decorators may be >added or removed without affecting the underlying class. I had first thought that the word used to describe the mechansim was unimportant. "decorator" would come to mean, for Python, what Python defined it to mean. But have concluded otherwise. In fact using the word "decorator" justifies the syntax, but - as you say - does not describe the impact of that syntax in any reasonable way. Its a bit of a con, I now think. > >I personally think it's confusing to reuse the "Decorator" name for >something that is not a classic decorator. I also agree with the many >comments that the proposed syntax does not make it clear that what is going >on is a destuctive transformation of the defined function. Apparently in the world of declarative programming it is kosher to make @something mean a destructive transformation of a function defined in its vicinity. When programming in Python. of course. And without providing a cognative hint, or without the need to justify itself by reference to any other notation that ever was. That precedent, of course, opens up a world of new possibilities. Unfortunately. Art > >Arien From squirrel at WPI.EDU Tue Aug 3 14:02:02 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 3 Aug 2004 14:02:02 -0400 Subject: how to do proper subclassing? In-Reply-To: References: Message-ID: On Tue, 3 Aug 2004, [iso-8859-1] Jonas Koelker wrote: > I'm new to this list (/me welcomes himself). Welcome! > However, I want the permutation to act like a list, in > all those cases where I don't override the operations. > For example, assuming permfooation is the above > permutation [1 3 4 0 2], permfooation[1:3] should > return [3,4]. How is this done? Do I have to actually > implement a slice-mechanism in the permutation class? I'm not sure exactly how your permutation class is implemented, so I can't give you a precise answer, but in general, there are three ways to do this, each method having benefits and drawbacks: 1) Implement your class as a subclass of list. Using this method, your class would store its list data in itself (in self, actually), since it is effectively a list. The __getitem__ method needed to implement slicing will be inherited from list, and no further work will need to be done. This method works best if you're only altering the behaviour of a list slightly (e.g. transforming all items in a particular way), but may not be well suited to objects that shouldn't otherwise act like lists. 2) Store your data in a list, and delegate __getitem__. Using this method, your class would store its list data in an attribute (say self.data). To implement slicing, you can simply define your class's __getitem__ method like this: def __getitem__(self,i): return self.data[i] assuming self.data contains the list data to which you want to provide access. This is the easiest method if all you want to implement is slicing. 3) Implement __getitem__ yourself. You should only need to do this if the data you want to slice is not available in a readily slicable form (perhaps you generate it on the fly). Implementing __getitem__ is easy; here is a general template you can use: def __getitem__(self,i): if isinstance(i,slice): return self.make_a_slice_and_return_a_list(i.start,i.stop,i.step) else: return self.get_an_item_at_index(i) __getitem__ is passed either a slice object (in the case of slicing) or an integer (in the case of indexing). The start, stop, and step attributes of the slice object return what you'd expect, or None if they weren't specified. The method slice.indices(length) will compute "actual" slice indices for a sequence of the given length in the case of missing, negative, or out-of-bounds indices, returning a tuple (start, stop, stride). Hope this helps. From cybermanxu at hotmail.com Wed Aug 4 15:42:34 2004 From: cybermanxu at hotmail.com (Jinming Xu) Date: Wed, 04 Aug 2004 14:42:34 -0500 Subject: How to force a single number to be a tuple Message-ID: Graeme, I found that too. I asked really a stupid question. Shame on me! :( Thanks anyway, Jinming >From: "Graeme Longman" >To: "Jinming Xu" , >Subject: RE: How to force a single number to be a tuple >Date: Wed, 4 Aug 2004 17:29:18 +0100 > >Hi, > >Couldn't you say: > > >>> y = 2, > >>> y >(2,) > >Cheers. >Graeme > > > -----Original Message----- > > From: python-list-bounces+graeme.longman=tangozebra.com at python.org > > [mailto:python-list-bounces+graeme.longman=tangozebra.com at python.org]On > > Behalf Of Jinming Xu > > Sent: 04 August 2004 17:26 > > To: python-list at python.org > > Subject: How to force a single number to be a tuple > > > > > > Hi Folks, > > > > I have a number sequence, which is put into a tuple like this: > > > > y=2, 3.0, 4.5 > > > > I can manipulate the sequence as a tuple when it has more than 1 > > number. But > > when the sequence has only 1 number, like > > > > y=2 > > > > I have trouble to manipulate it as a tuple. I guess there must > > be a way to > > forece a single number to be a tuple. Could anyone please tell me that? > > > > Thanks, > > > > Jinming > > > > _________________________________________________________________ > > FREE pop-up blocking with the new MSN Toolbar ? get it now! > > http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/ > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > ________________________________________________________________________ > > This e-mail has been scanned for all viruses by Star Internet. The > > service is powered by MessageLabs. For more information on a proactive > > anti-virus service working around the clock, around the globe, visit: > > http://www.star.net.uk > > ________________________________________________________________________ > > --- > > Incoming mail is certified Virus Free. > > Checked by AVG anti-virus system (http://www.grisoft.com). > > Version: 6.0.732 / Virus Database: 486 - Release Date: 29/07/2004 > > >--- >Outgoing mail is certified Virus Free. >Checked by AVG anti-virus system (http://www.grisoft.com). >Version: 6.0.732 / Virus Database: 486 - Release Date: 29/07/2004 > > >________________________________________________________________________ >This e-mail has been scanned for all viruses by Star Internet. The >service is powered by MessageLabs. For more information on a proactive >anti-virus service working around the clock, around the globe, visit: >http://www.star.net.uk >________________________________________________________________________ _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ From mwh at python.net Wed Aug 11 07:01:54 2004 From: mwh at python.net (Michael Hudson) Date: Wed, 11 Aug 2004 11:01:54 GMT Subject: Executing bytecode from a string. References: Message-ID: "Benjamin Scherrey" writes: > I'm curious as to how difficult it would be to take a string that contains > compiled bytecode, load it into memory, give it a function name then > execute that function. Fairly hard: you'd need to guess or work out all the other parameters to new.code such as argcount, stacksize,... > I'm thinking of a database that contains compiled objects that I can > load and execute. You'd likely be much better off storing marshalled code objects than raw code strings. Whether that would suffice is hard to say from your description, but it's probably a good start. Or just Python source... > I'm also curious as to what level of grainularity this would work - > module, class, class method, function? I think "it depends". > Anyone tried to do this before? Almost certainly :-) Cheers, mwh -- Ignoring the rules in the FAQ: 1" slice in spleen and prevention of immediate medical care. -- Mark C. Langston, asr From xavier.combelle at free.fr Sun Aug 8 08:57:12 2004 From: xavier.combelle at free.fr (Xavier Combelle) Date: Sun, 08 Aug 2004 14:57:12 +0200 Subject: decorators vs GIL In-Reply-To: References: <8YudnZoJ4NdLEYjcRVn-jA@speakeasy.net> <0bidnfbR2_PZOIjcRVn-pA@giganews.com> Message-ID: <41162234$0$32536$626a14ce@news.free.fr> >As far as "fixing" the GIL - well, no-one on Python-Dev has obviously >found it to be a problem for them. I certainly can't recall a time in the >last 5 years where the GIL has been a problem in any application I've >written (including a number of heavily threaded applications). Coding >threaded applications in Python does require _knowledge_ of the GIL, >true, but there's nearly always ways to get around it. > > For information is there some internet resources to understand what exactly the GIL is about ? From rogerb at rogerbinns.com Mon Aug 9 21:06:11 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Mon, 9 Aug 2004 18:06:11 -0700 Subject: Compiling disutil modules on Windows References: <7947683945.20040807214448@variosoft.com> Message-ID: Geoff Caplan wrote: > I now have mingw working, but some of the packages I want to try are > only distributed in disutils format. I can't figure out a way to get > these packages to use the mingw compiler. Is this possible, or do I > really have to shell out $$ to microsoft to get these installed? python setup.py build --compiler=mingw32 bdist_wininst Roger From oziko at fusiondementes.com Mon Aug 16 14:08:32 2004 From: oziko at fusiondementes.com (oziko) Date: Mon, 16 Aug 2004 13:08:32 -0500 Subject: 'ascii' codec can't encode character u'\xf3' Message-ID: <4120F820.4000703@fusiondementes.com> Hi, I get a piece of code of ogg123.py from the pyogg site, this is the code: ******************************* ogg_file = sys.argv[1] vorbis_file=ogg.vorbis.VorbisFile(ogg_file) comentarios = vorbis_file.comment() recognized_comments = ('Artist', 'Album', 'Title', 'Version', 'Organization', 'Genre', 'Description', 'Date', 'Location', 'Copyright', 'Vendor') comment_dict = {} for com in recognized_comments: comment_dict[string.upper(com)] = '%s: %%s' % com known_keys = comment_dict.keys() for key, val in comentarios.items(): if key in known_keys: print comment_dict[key] % val else: continue #print "Unknown comment: %s" % val **************************** When I run int I get this error: Album: Trapos Vendor: Xiph.Org libVorbis I 20020717 Artist: Attaque 77 Traceback (most recent call last): File "./ogg2sql.py", line 51, in ? print comment_dict[key] % val UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in position 15: ordinal not in range(128) The title of the song has especial carateres Title= Perfecci?n, it is in espanish. I put at the begining og the scrpit the encodign coment #!/usr/bin/env python # -*- coding: UTF8 -*- As you see the script get the comment og a vorbis file, and all the comments are in unicode. So I do not understan why the script uses an ascii codec, Am I not using Unicode coding? From krajicek at ics.muni.cz Sun Aug 1 13:04:05 2004 From: krajicek at ics.muni.cz (Ondrej Krajicek) Date: Sun, 1 Aug 2004 17:04:05 GMT Subject: Python/ADSI Problem Message-ID: Hello, I have problem with the following code: rootdse = ldap.OpenDSObject(ROOTDSE_URL, USER_NAME, PASSWORD, opts) nc = rootdse.Get("defaultNamingContext") uri = "LDAP://%s/%s" % (SERVER_NAME, nc) dc = ldap.OpenDSObject(uri, USER_NAME, PASSWORD, opts) cnUsers = dc.GetObject("top", "Users") ## <-- exception is thrown here The last line throws an exception: com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147016654), None) I've tried several variants, such as: GetObject(None, "Users"), GetObject("", "CN=Users"), GetObject(u"", u"CN=Users") with no success. Similar code in C++ works perfectly, i.e. the binding URLs, flags, etc. seem to be correct. Anything obvious I've missed? Thanks, Ondra -- ____________________________\\--//_________________________ Ondrej Krajicek \\// krajicek at ics.muni.cz Institute of Computer Science,||Masaryk University Brno, CR _____________________________//\\__________________________ From dm-info at 163.com Sat Aug 28 01:32:26 2004 From: dm-info at 163.com (tocer) Date: 27 Aug 2004 22:32:26 -0700 Subject: ANN:a Vim script make Vim suport calltips of python Message-ID: <6aa4af73.0408272132.3f8b6a05@posting.google.com> ADDRESS: http://vim.sourceforge.net/scripts/script.php?script_id=1074 INTRO: In a new bottow window, display help doc strings of word under the cursor by scanning the modules in the current file as you press key. It requier Vim compiled with "+python" and MUST set iskeyword+=. It work well in my box in Win2000 and Vim6.3. If it work in other platform or other version of Vim, let me know. I think it better than the call tips of idle and pywin:) if you like it ,let me know. From davidf at sjsoft.com Tue Aug 31 16:47:04 2004 From: davidf at sjsoft.com (David Fraser) Date: Tue, 31 Aug 2004 22:47:04 +0200 Subject: compile to exe? In-Reply-To: References: Message-ID: Active8 wrote: > I just moticed that wxGlade 3.1.1 comes with a windows installer and > runs as an exe with a python22.dll and a bunch of .pyd files (pythod > dlls?) and wxGlade 3.4 is all python files. > > I might be getting in deep here, but how do you turn .py files into > .pyds and .exes? > > Any links or references to which doc and section would be > appreciated. There are a number of ways, py2exe is the simplest to start off with on Windows: http://py2exe.sf.net/ David From tchur at optushome.com.au Sun Aug 8 00:16:26 2004 From: tchur at optushome.com.au (Tim Churches) Date: 08 Aug 2004 14:16:26 +1000 Subject: session management In-Reply-To: <4115A5C6.6010206@mail.usyd.edu.au> References: <4115A5C6.6010206@mail.usyd.edu.au> Message-ID: <1091938586.1253.14.camel@emilio> On Sun, 2004-08-08 at 14:02, Ajay Brar wrote: > and how secure would such a mechanism be? the user enters their username > and password and i compare the hash of both the username and password > with values stored in an encrypted file. if the comparison is successful > i create the session. is this a reasonably secure scheme? does anyone > see any problems with this OWASP is a good place to start reading: http://www.owasp.org We also found this paper very useful: http://pdos.lcs.mit.edu/cookies/pubs/webauth.html -- Tim C PGP/GnuPG Key 1024D/EAF993D0 available from keyservers everywhere or at http://members.optushome.com.au/tchur/pubkey.asc Key fingerprint = 8C22 BF76 33BA B3B5 1D5B EB37 7891 46A9 EAF9 93D0 From wweston at att.net Sun Aug 15 02:45:51 2004 From: wweston at att.net (wes weston) Date: Sun, 15 Aug 2004 06:45:51 GMT Subject: random / lists In-Reply-To: References: Message-ID: Malcolm Clift wrote: > Hi All, > > I have this so far. > > > import random > > things = xrange(int(raw_input("choose no of things (1-8)? "))) > > state = [None,None] > > l = [] > > for x in things: > tmp = random.choice('abcd') > print state > while tmp in state[0:2]: > tmp = random.choice('abcd') > print "choice ",x+1," is ", tmp > l.append(tmp) > > state[x%2] = tmp > > print 1 > > Could someone help in showing me how to control it like this? That if 'a' > is choosen it can only be followed by say b or d, if 'd' is choosen it can > only be followed by c or b etc... I can see how to do this after the list > has been generated with if statements, but that is impractical. As it is > at the moment it stop two of the same letters being given one after > another or the same letter occurring with only one space interviening. > > Thanks, > > Calvin > > Calvin, Could you give a clear statement of what you want to do. No code; just a description of what you want to do. wes From simoninusa2001 at yahoo.co.uk Fri Aug 13 22:56:12 2004 From: simoninusa2001 at yahoo.co.uk (simo) Date: 13 Aug 2004 19:56:12 -0700 Subject: Flython? References: <411cbcb1$0$3894$4d4ebb8e@news.nl.uu.net> Message-ID: <30260531.0408131856.5ef3b0d3@posting.google.com> There's a few libraries for making SVG files in PHP, so there may be Python versions too, but if you want ActionScript then I guess you're determined to go with Flash instead..... From lbates at swamisoft.com Tue Aug 3 09:47:02 2004 From: lbates at swamisoft.com (Larry Bates) Date: Tue, 3 Aug 2004 08:47:02 -0500 Subject: intersection of 2 strings References: Message-ID: At the risk of doing your homework, one way would be: list_1=string_1.split('_') list_2=string_2.split('_') # # The next line uses some "magic" to eliminate duplicates" # list_3=[x for x in list_1 if x in list_2 if x not in locals()['_[1]'].__self__] string_3="_".join(list_3) print string_3 If you have Python 2.3 you also could use sets() module and it would be even easier. HTH, Larry Bates "Antoine Logean" wrote in message news:e3dbc412.0408030437.bc62176 at posting.google.com... > Hi, > > What is the easiest way to get the intersection of two strings in > python (a kind a "and" operator) ? > ex: > > string_1 = "the_car_of_my_fried_is_bigger_as_mine_but_my_girlfriend_is_more_beautifull" > > string_2 = > "my_girlfriend_is_more_beautifull_and_has_blue_eyes" > > and the intersection : > string_1 "and" string_2 = "my_girlfriend_is_more_beautifull" > > thanks for your help > > Antoine From skip at pobox.com Wed Aug 11 11:02:20 2004 From: skip at pobox.com (Skip Montanaro) Date: Wed, 11 Aug 2004 10:02:20 -0500 Subject: Integers have docstring for int() In-Reply-To: <59e9fd3a04081105087366db98@mail.gmail.com> References: <59e9fd3a04081105087366db98@mail.gmail.com> Message-ID: <16666.13564.527138.202013@montanaro.dyndns.org> Andrew> I accidentally discovered that all the basic types in Python Andrew> have docstrings that describe the functions to create them. For Andrew> integers, you get: ... Andrew> This seems a little unexpected to me; is there any particular Andrew> reason for this behaviour? Why should this be unexpected? If you execute print int.__doc__ you get its docstring. Since the __doc__ attribute is attached to the class it will be found when the search starts at an instance of the class as well. Skip From greg at cosc.canterbury.ac.nz Tue Aug 24 01:08:09 2004 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Tue, 24 Aug 2004 17:08:09 +1200 Subject: Fwd: Overriding logical operators? In-Reply-To: References: <3A81C87DC164034AA4E2DDFE11D258E3022E1C@exchange.hqamor.amorhq.net> <59e9fd3a04082101105c50558c@mail.gmail.com> Message-ID: <2p00psFfado2U1@uni-berlin.de> Andrew Durdin wrote: > As far as I can see, the compiler changes would be limited to > compiling "a and b" to bytecode equivalent to > > a.__logand__(lambda b: b) That approach would work, but it would slow down the evaluation of all logical expressions a lot, requiring an extra Python function call to get the second operand, even in the common case where no overriding is going on. So I doubt it would be accepted. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From listserver at tdw.net Mon Aug 2 11:31:01 2004 From: listserver at tdw.net (Tim Williams) Date: Mon, 2 Aug 2004 16:31:01 +0100 Subject: Trimming a string References: <410B7277.3000609@mail.usyd.edu.au> <410E48BD.9060202@comcast.net> Message-ID: <00c401c478a5$b780e030$ccbefea9@twilliams> >I have a string that is 7 characters and represents file mode in UNIX/LINUX from rpm: >0100755 >I don't care about the 0100 portion, I am only interested in the file >permissions portion which is 755. How can I get three characters from the >string starting at the right? ( -OR- strip 4 characters from the left? ) >>> str = "0100755" >>> str1 = str[4:] >>> print str1 755 >>> str2 = str[-3:] >>> print str2 755 >>> From aleaxit at yahoo.com Sat Aug 28 12:55:23 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 28 Aug 2004 18:55:23 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1ry8k0d2az.fsf@rovereto.ifi.uio.no> <87acwgvy51.fsf@sinken.local.csis.hku.hk> <2pb36dFibuj3U1@uni-berlin.de> <41309d32$0$65611$a1866201@newsreader.visi.com> <1gj8pg5.1e6z0kiprvfxuN%aleaxit@yahoo.com> <87acwfutq4.fsf@sinken.local.csis.hku.hk> Message-ID: <1gj8s7h.1hb85h219vserbN%aleaxit@yahoo.com> Isaac To wrote: > >>>>> "Alex" == Alex Martelli writes: > > Alex> list(a, b, c) instead of [a, b, c] would not be horribly > Alex> heavy syntax, I think. > > On the other hand, [b*b for b in c] is too sweet to lose as well. :) But list(b*b for b in c) is essentially the same thing, and already in Python 2.4 it works just fine. Alex From fred at acme.com Sat Aug 21 00:21:27 2004 From: fred at acme.com (Fred) Date: Sat, 21 Aug 2004 06:21:27 +0200 Subject: [newbie] Strange behavior of the re module Message-ID: <2ejdi01btug5iskb4ipjpj7eaprd8i7vgm@4ax.com> Hi, While parsing through a bunch of HTML pages using the latest ActivePython, I experienced something funny using the re module. I extracted the part that generates the errors (I'm just trying to substitute once item with another in a string): -------------------------------- import re #NOK : doesn't like a single, ending backslash #stuff = "\colortbl\red0\green0\" # => SyntaxError: EOL while scanning single-quoted string #NOK : doesn't like gn0? :-) stuff="\colortbl\red0\gn0" # => traceback (most recent call last): # File "C:\test.py", line 10, in ? # template = re.sub('BLA', stuff, template) # File "G:\Python23\lib\sre.py", line 143, in sub # return _compile(pattern, 0).sub(repl, string, count) # File "G:\Python23\lib\sre.py", line 257, in _subx # template = _compile_repl(template, pattern) # File "G:\Python23\lib\sre.py", line 244, in _compile_repl # raise error, v # invalid expression #sre_constants.error: bad group name #OK.... stuff="\colortbl\red0\n0" template = "BLA" template = re.sub('BLA', stuff, template) -------------------------------- => It appears that the re module isn't very friendly with backslashes, at least on the Windows platform. Does someone know why, and what I could do, since I can't rewrite the source HTML documents that contain backslashes. Thank you Fred. From gandalf at geochemsource.com Tue Aug 31 09:28:54 2004 From: gandalf at geochemsource.com (Gandalf) Date: Tue, 31 Aug 2004 15:28:54 +0200 Subject: has_method (solution found) In-Reply-To: <41347BC1.5020407@geochemsource.com> References: <41347BC1.5020407@geochemsource.com> Message-ID: <41347D16.1060508@geochemsource.com> Somebody sent me a private e-mail. It must be common for such silly questions that would just spam the list. :-) I'll write down the final solution anyway. def getmethod(name): methodList = [e for e in dir(self) if callable(getattr(self, e))] if name in methodList: return getattr(self,name) else: return None Thanks for all. Laci 2.0 From DrColombes at yahoo.com Fri Aug 6 14:18:40 2004 From: DrColombes at yahoo.com (Dr. Colombes) Date: 6 Aug 2004 11:18:40 -0700 Subject: Plotting histograms, scatter plots in Python Message-ID: What is the easiest way to generate some plots and graphs in Python ? Specifically interested in simple histograms and scatter plots with circles and regression lines. Thanks for your suggestions. From Ian.Sparks at etrials.com Tue Aug 31 15:25:27 2004 From: Ian.Sparks at etrials.com (Ian Sparks) Date: Tue, 31 Aug 2004 15:25:27 -0400 Subject: Splitting a list Message-ID: <41A1CBC76FDECC42B67946519C6677A901915309@pippin.int.etrials.com> > Elaine Jackson wrote... > def indices(x,y): > if y in x: > i = x.index(y) > j = i+1 > return [i]+[z+j for z in indices(x[j:],y)] > return [] > > def listSplit(x,y): > z = [-1] + indices(x,y) + [len(x)] > return [x[z[i]+1:z[i+1]] for i in range(len(z)-1)] > Thanks Elaine but so far I like Jeff Eplers version the best : def split(it, elem): l = [] for i in it: if i == elem: yield l l = [] else: l.append(i) yield l >>> l = [1,2,3,-1,4,5,-1,8,9] >>> list(split(l, -1)) [[1, 2, 3], [4, 5], [8, 9]] From n/a Mon Aug 16 18:46:04 2004 From: n/a (ADE) Date: Mon, 16 Aug 2004 15:46:04 -0700 Subject: Get Printer Information Message-ID: <10i2e9rg0c1rgf8@corp.supernews.com> I have three printers that are printing a lot of material each day (Epson Printers) I would like to be able to after I hit the Print Button and Before the Print Preview have a Python Tkinter Window appear and Display Information about the Print Job for review before printing These Printers have this feature but do not display enough Information How Could I do this (Please Point Me in The Right Direction Rather than tell me how as I would like to learn) Cheers Andrew From wjdandreta at att.net Mon Aug 2 23:23:17 2004 From: wjdandreta at att.net (Bill Dandreta) Date: Tue, 03 Aug 2004 03:23:17 GMT Subject: Starkiller? In-Reply-To: <278de0e.0408020648.6d187aff@posting.google.com> References: <278de0e.0408020648.6d187aff@posting.google.com> Message-ID: Neuruss wrote: > Does anyone have news about Starkiller? Here's the Starkiller website: http://web.mit.edu/msalib/www/urop/ It says hopefully it will be released by October. Bill From balaji at email.arizona.edu Fri Aug 13 19:15:36 2004 From: balaji at email.arizona.edu (Balaji) Date: 13 Aug 2004 16:15:36 -0700 Subject: Templates SWIG Message-ID: <494182a9.0408131515.6079290e@posting.google.com> Can any one help me with this. I have an c++ header file which describes a method given below. void setRows(const vector &rowNames, const vector &lhs,const vector &rhs); How I'm supposed to write this template in a interface file. So that when I pass (['a','b','c'],[0,0,0],[1,2,3]) in python it accepts it. Thanx in advance Balaji From john at grulic.org.ar Mon Aug 2 09:23:53 2004 From: john at grulic.org.ar (John Lenton) Date: Mon, 2 Aug 2004 10:23:53 -0300 Subject: PyGTK overload In-Reply-To: <20040731091225.GA1365@mirk.lan> References: <20040731091225.GA1365@mirk.lan> Message-ID: <20040802132353.GB3648@grulic.org.ar> On Sat, Jul 31, 2004 at 11:12:25AM +0200, Egbert Bouwman wrote: > As a newby to PyGTK I already have produced some gui's I like, > but I have difficulties in finding out what method or other instrument > I need for doing various things. > > I have not yet found the tutorial or otherwise that explains concepts > like setting (relative) sizes, setting or manipulating focus, > setting colors, etc. > > Also when I think I need a method with a specific word it its name, > and I cannot find it, there are two (not necessarily exclusive) > possibilities: > - I have to go higher up the ancestry > - I look for the wrong word > > Is there an other way than just going on and become familiar with it ? have you tried, e.g., 'help gtk.Window' from the interpreter, or 'pydoc gtk.Window' from the commandline? -- John Lenton (john at grulic.org.ar) -- Random fortune: Your sister swims out to meet troop ships. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From russblau at hotmail.com Thu Aug 26 15:57:22 2004 From: russblau at hotmail.com (Russell Blau) Date: Thu, 26 Aug 2004 15:57:22 -0400 Subject: Newbie question on dictionary!!! References: <494182a9.0408261150.a4c767f@posting.google.com> Message-ID: <2p6tl1Fhcld6U1@uni-berlin.de> "Balaji" wrote in message news:494182a9.0408261150.a4c767f at posting.google.com... > Hello everybody... > > I want to ask a simple question. > > Suppose I have an list say g=['a','b','c','d'] > > and I have an dictionary say k={'b':20,'a':10} > > Now I want to sort this dictionary on the basis of the list and if it > doesnt find any of the element in the list then I wud like to replace > it with zero.. > > so I would like to modify k into {'a':10,'b':20,'c':0,'d':0} > > I have tried all the built in associated with dict and lists but was > not able to come up with an solution... You can't sort a dictionary. By definition, the keys of a dictionary are not accessed in any particular order. See footnote 3 in http://www.python.org/doc/current/lib/typesmapping.html You could turn your dictionary into a list with the desired qualities: result = [(item, k.setdefault(item, 0)) for item in g] which will have the side-effect of creating the new keys you wanted in k, although not in sorted order. -- I don't actually read my hotmail account, but you can replace hotmail with excite if you really want to reach me. From anthonybaxter at gmail.com Sat Aug 7 06:47:08 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 7 Aug 2004 20:47:08 +1000 Subject: Decorator syntax In-Reply-To: <2njp58F1jj1dU1@uni-berlin.de> References: <38ednYT1NLz1P4zcRVn-uA@powergate.ca> <2njp58F1jj1dU1@uni-berlin.de> Message-ID: On Sat, 07 Aug 2004 16:28:11 +0600, Yawar Amin wrote: > How about > > def foo(a, b, c): > foo.accepts = (int, int, list) > foo.author = 'Chris King' How would you express foo=classmethod(foo) in this syntax? Far better to have one flexible tool in the toolbox than a host of little, less functional tools. From max at alcyone.com Sun Aug 22 22:57:38 2004 From: max at alcyone.com (Erik Max Francis) Date: Sun, 22 Aug 2004 19:57:38 -0700 Subject: Has anyone implemented BASIC in Python? References: <2oo13eFcj548U1@uni-berlin.de> Message-ID: <41295D22.8702D583@alcyone.com> Leif K-Brooks wrote: > Has anyone ever tried implementing a simple unstructured BASIC dialect > in Python? I'm getting interested in language implementation, and > looking at a reasonably simple example like that could be pretty > interesting. On a whim, I implemented a Python BASIC interpreter which supported all statements in primitive BASIC, but got bored before I implemented all the standard operators in expressions. -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ Procrastination is the thief of time. -- Edward Young From me at privacy.net Sun Aug 8 07:50:36 2004 From: me at privacy.net (Dan Sommers) Date: 08 Aug 2004 07:50:36 -0400 Subject: @decorator syntax is sugar, but for what exactly? References: Message-ID: On Sun, 8 Aug 2004 18:24:58 +1000, Anthony Baxter wrote: > In many cases, these new features actually lead to smaller, simpler > code. I challenge _anyone_ to tell me that > apply(func, args, kwargs) > is better than > func(*args, **kwargs) Okay, I will. The old way is better than the new way. Explicit is better than implicit, after all. Given your second example, is func the name of a function or an object that references a function? Can I grep my source code to find a function named func? (Okay, I'll find the variable named func, so at least I'll have some clue as to what's going on.) Is there a "from module import func" statement in sight? What happens when I look up "func" in the Python documentation to see if it's a built in name? C did the same thing recently. Old C: (*f)( argument ); New C: f( argument ); With the old syntax, I knew immediately that f was a pointer to a function and that the function to which it pointed was being called indirectly. With the new one, I have to track down a definition or declaration of f to see that. Yes, this used to be much more important than it is now. Perhaps my years of assembly language applications in extremely tight situations and are showing through. Yes, I know that Python functions are first class objects and should be treated as such. Yes, I know that Python is not C. But with function application being built right into the syntax of the language (i.e., an identifyer followed by a parenthesized argument list), I would like to see a visual difference between calling a named function vs. calling a function indirectly through some sort of reference. Yes, I also know that in most cases "it's obvious from context," but with the old way, it was obvious without any context and evident to the simplest of automated tools. That all said, when I use the new syntax (okay, you got me, I do use the new syntax on occasion), I always leave a comment nearby to explain what's going on. I agree: the *code* is smaller and arguably simpler, but the *program* and the *software* are not. Regards, Dan -- Dan Sommers Never play leapfrog with a unicorn. From nzanella at cs.mun.ca Fri Aug 20 14:11:08 2004 From: nzanella at cs.mun.ca (Neil Zanella) Date: 20 Aug 2004 11:11:08 -0700 Subject: classes are objects... so how can we custom print them: we need a classmethod syntax Message-ID: Hello, In Python, classes are objects. But there is no way to custom print a class object. This would require some syntax such as the one commented out below: With the current "foo = classmethod(foo)" mechanism custom printing for class objects is not possible. #!/usr/bin/python class Foo: def __str__(self): return "foo" #def classmethod __str__(cls): # return "pythons bite" foo = Foo() s = "hello %s!" % foo # custom text here print s print Foo # no custom text here possible it seems, unless we call # a staticmethod such as Foo.printMe() Regards, Neil From jaydonnell at yahoo.com Wed Aug 18 21:02:33 2004 From: jaydonnell at yahoo.com (Jay Donnell) Date: 18 Aug 2004 18:02:33 -0700 Subject: can tarfile maintain directory structure? References: Message-ID: > > import tarfile > > > > tar = tarfile.open(filename, "w:gz") > > tar.add(directory) > > tar.close() This works perfectly on linux, but it wasn't working for me on windows yesterday. I'll try it again the next time I'm on windows. From me at privacy.net Wed Aug 25 14:05:53 2004 From: me at privacy.net (Richard Hanson) Date: Wed, 25 Aug 2004 11:05:53 -0700 Subject: MSI Installer Problem: can't install 2.4a2 on new install of Win2kSP2 Message-ID: Over the last few days, I reinstalled Win2kSP2 to a spare harddrive I had just swapped into my Fujitsu LifeBook P1120 (long story ). Subsequently, I DL'ed the newest Python alpha (2.4a2), and when trying to install it, I immediately got this error: This installation package cannot be installed by the Windows Installer service. You must install a Windows service pack that contains a newer version of the Windows Installer service. (Python 2.4a2 had been working on the LifeBook P1120 before the crash and subsequent reinstall.) I immediately tried installing Python 2.4a2 on my older, HP laptop, and that went fine. I then went back to the Python alpha page and DL'ed the ~1.8MB file linked from MS's site. After running the new DL from MS, the Python MSI installer seemed to run. However, now Idle wouldn't run, although the Python command line (console) worked. I tried running Idle using Windows Explorer from inside my Python installation at: E:\Python24\Lib\idlelib\idle.pyw (and idle.py) but those didn't work, either. (E:\ is my Win2k partition and it's a FAT32 partition.) I then checked the new 2.4a2 install on the older HP laptop, and there Idle worked -- from the menu shortcuts, and from launching the idle.pyw file in Windows Explorer. (I note that the HP laptop already had Python23 on it. The HP has *almost* the same OS: Win2kSP3 -- not a fresh install -- and is using NTFS for its Win2k partition.) I also note that the *.pyc files were not created by the installer on the Fujitsu LifeBook P1120 but were on the HP Omnibook 900B (as may be surmised). Back on the P1120, I used the MSI installer to "repair" the broken install twice, used it again to completely remove Python, rebooted , and then use the MSI installer one more time to reinstall. Still no go. Am I overlooking something simple...? Thanks for any help anyone can offer. (I'll try to followup as this gets solved -- I've reinstalled onto an old harddrive, so I may crash again... :-) ) I'll-keep-at-it-and-try-DL'ing-2.3.4-tonight'ly y'rs Richard -- email works if unmunged: sickolefartnewsguycom From soofern at msn.com Sat Aug 7 01:11:18 2004 From: soofern at msn.com (Chong Soo Fern) Date: Sat, 07 Aug 2004 14:11:18 +0900 Subject: HELP on module Message-ID: Hi, I am currently a fourth year Uni student who is working on a Thesis that required me to use python language to develop a webpage that user to query on. I am so new to python and struggling so hard to learn and apply it. I wonder if any body out there can help me a helping hand. As attached is the details of my thesis requirement. I am currently reading through a book "Learning Python" and looking through some useful tutorials. I am actually searching for modules that can link postgreSQL and python together. Please give me some advice which at least help me to start up the program, cause I'm really lost. I wonder if the CGI tutorial on the python website :http://www.python.org/doc/lib/module-cgi.html, worked for my case? Operating System: Linux Programming Lang: Python Database : PostgreSQL Your kind attention is greatly appreciated. Thank you. Regards, Chong Soo Fern _________________________________________________________________ Protect your inbox from harmful viruses with new ninemsn Premium. Go to http://ninemsn.com.au/premium/landing.asp?banner=emailtag&referrer=hotmail -------------- next part -------------- A non-text attachment was scrubbed... Name: Essence of the proposed solution.doc Type: application/msword Size: 27136 bytes Desc: not available URL: From maxm at mxm.dk Wed Aug 18 07:34:13 2004 From: maxm at mxm.dk (Max M) Date: Wed, 18 Aug 2004 13:34:13 +0200 Subject: case insensitive comparison operator ? In-Reply-To: <41233060$0$198$db0fefd9@news.zen.co.uk> References: <41233060$0$198$db0fefd9@news.zen.co.uk> Message-ID: <41233ecb$0$207$edfadb0f@dread12.news.tele.dk> Will McGugan wrote: > What is the best way to do a simple case insensitive comparison in Python? > > As far as I can tell, the only option is to do str1.lowercase() == > str2.lowercase() (or uppercase). But that strikes me as quite verbose > for such a common operation, and possibly inneficient since it would > create and destroy 2 tempory objects. Perhaps there should be a > dedicated function in the string object, or (+1) an operator? How else could it be done? You could wrap it in a function, and reuse the code if you want to. That way you can imagine that it never happens ;-) def cic(x,y); "Case insensitive compare" return x.lower() == y.lower() But you cannot really do it any more efficient. Forget your worries. It's probably just a case of premature optimisation. Naturally there are special cases where you must do it more efficiently. But they would probably need to be solved based on the specific problem. regards Max M From ben at benlast.com Wed Aug 18 08:48:03 2004 From: ben at benlast.com (Ben Last) Date: Wed, 18 Aug 2004 13:48:03 +0100 Subject: age of Python programmers In-Reply-To: Message-ID: Age 39 (though if I allowed for rounding it'd go up to 40!) ben ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ From beliavsky at 127.0.0.1 Mon Aug 16 20:50:47 2004 From: beliavsky at 127.0.0.1 (beliavsky@aol.com) Date: 16 Aug 2004 19:50:47 -0500 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> <41214271_1@127.0.0.1> Message-ID: <41215667$1_1@127.0.0.1> Roy Smith wrote: >In article <41214271_1 at 127.0.0.1>, > "beliavsky at aol.com" wrote: > >> Jorge Godoy wrote: >> >> >Just an attempt and trying to keep it like your code. >> >> Thanks. My code did not correctly illustrate breaking out of more than one >> level of loop. How would the following code be translated to Python? > >Ugh. This is a truly ugly scenario. You've got three nested loops, >with each inner loop having a break out of both itself and the >immediately containing loop. Does this correspond to some real-world >algorithm, or is it just a diabolical scenario invented for the example? Ok, here is something short but more realistic and IMO not "ugly". You may want to exit a nested loop when testing if a condition involving several variables is met, such as searching for a zero of a multivariate function. In Python you can print i,j,k and exit() when m == 0, but in a larger program you may want more control. program xnest_loop ! find a Pythagorean triple n = 5 ido: do i=1,n do j=1,n ij = i**2 + j**2 do k=1,n m = ij - k**2 if (m == 0) exit ido end do end do end do ido if (m == 0) then print*,i,j,k else print*,"no triple" end if end program xnest_loop There is a thread "Labeled loop break/continue" in comp.std.c about adding similar functionality to C. Fortran has had a big head start over most other languages, but they may catch up eventually :). http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&c2coff=1&frame=right&th=b90ddd6cd83f7232&seekm=lnr7qds9r6.fsf%40nuthaus.mib.org#link1 ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--- From npat at efault.net Mon Aug 16 15:25:33 2004 From: npat at efault.net (Nick Patavalis) Date: Mon, 16 Aug 2004 19:25:33 +0000 (UTC) Subject: Why I love python. References: Message-ID: On 2004-08-16, Delaney, Timothy C (Timothy) wrote: > Nick Patavalis wrote: > >> On 2004-08-13, kosh wrote: >>> >>> I don't want my cell phone to run python, java, ruby, c# etc etc. I >>> want it to just be a telephone and do that job well. >>> >> >> I understand. You want a nice analog cell-phone, with a large rotary >> dial, and very long cord. Sorry but resistors, capacitors, and diodes >> can only go that far. For everything else you need large clusters of >> transistors (integrated-ccircuits they are called by some) and a lot >> of them need (God forbid!) "software". > > > What I want (and can't seem to find anymore) are mobile phones that fit > in the hand *comfortably*, have easy-to-use keypads (so the chance of > hitting the wrong key is minimal), good reception anywhere there's any > kind of signal, high battery life and usually good SMS support (i.e. > intelligent look-ahead dictionary). > I believe this is not a discussion about cell-phones. Incidentally all these features are hard to implement without software. /npat From dave at pythonapocrypha.com Mon Aug 30 10:26:31 2004 From: dave at pythonapocrypha.com (Dave Brueck) Date: Mon, 30 Aug 2004 08:26:31 -0600 Subject: Enumerating Network Adapters In-Reply-To: <413257dd$0$26986$626a14ce@news.free.fr> References: <4131b09e$0$13683$636a15ce@news.free.fr> <413257dd$0$26986$626a14ce@news.free.fr> Message-ID: <41333917.4060602@pythonapocrypha.com> Olivier Parisy wrote: [snip] > But actually, a previously posted message suggests a portable way to get > the platform IPs. Citing John Abel : > > > socket.gethostbyaddr( socket.gethostname() ) will return all the > > details that you need to know. For example, the output of that > > command on my machine is : > > > > ('hallows', [], ['101.101.101.102', '10.253.1.118']) > > Are there some pitfalls I'm not aware of ? Doesn't seem to work right on Windows, for me at least: >>> socket.gethostbyaddr(socket.gethostname()) ('', [], ['169.254.0.100']) It returned the least useful of my 3 IP addresses - my loopback adapter - but didn't return my LAN and wireless IPs. -Dave From ialbert at mailblocks.com Sat Aug 28 22:12:55 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Sat, 28 Aug 2004 22:12:55 -0400 Subject: regex into str In-Reply-To: References: Message-ID: Peter Kleiweg wrote: > I want to use regular expressions with less typing. Like this: Interesting example. Send it to the Python Cookbook folks. http://aspn.activestate.com/ASPN/Cookbook/Python Istvan. From jeff at ccvcorp.com Fri Aug 20 16:57:55 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 20 Aug 2004 13:57:55 -0700 Subject: just ignore Guido's "rejections" [Re: Alternative decorator syntax decision] In-Reply-To: References: <2uadnbqpMuI1krvcRVn-sg@comcast.com> Message-ID: <10icpd98dsjcsf2@corp.supernews.com> Doug Holton wrote: > Anthony Baxter wrote: > >> On Fri, 20 Aug 2004 09:50:18 -0500, Doug Holton >> wrote: >> >>> We can safely ignore Guido's "rejections" when deciding upon an >>> alternative to agree upon. Many people felt his rejections of C1 (a >>> longtime community favorite), E1 and other alternatives were wrong. >>> http://mail.python.org/pipermail/python-dev/2004-August/048134.html >> >> >> Uh, what? No, you _can't_ ignore Guido's rejections - if you really >> decide >> that you must have a form he's objected to, you need a _damn_ strong >> argument to back that up. A "longtime community favorite" doesn't mean >> a thing - this is language design, not American Idol - that a lot of >> people >> like it makes no difference. > > > Um, yes. The point is to determine what the *community* decides on, > and *then* present that to Guido. You're just helpping confound this > second vote even more. Some people aren't voting for what they think > is best, but what they think Guido hasn't "rejected". That is > ridiculous. You'll end up with a syntax that nobody really ever liked > most, even Guido. On the other hand, if the community decides that the only thing they prefer to @pie is something that Guido's already rejected... then we get @pie. I can vote for Superman for president all I want, and I can talk all my friends into voting for him, but even if a majority of the country votes for Superman, he's still not gonna be taking any inaugural oath. Instead of voting for an impossible fantasy, it's much more sensible to restrict myself to voting for people/options with *some* chance of success. Keep in mind here, that what we're trying to do is vote for something for which we think we can create a convincing case that it's better than @pie. And Guido is the only person for whom "convincing" is relevant. If he's already rejected something, it will be *extremely* difficult to convince him that his rejection was a mistake. I'd rather focus my efforts where they're a little more likely to bear fruit. Jeff Shannon Technician/Programmer Credit International From gandalf at geochemsource.com Tue Aug 31 09:25:18 2004 From: gandalf at geochemsource.com (Gandalf) Date: Tue, 31 Aug 2004 15:25:18 +0200 Subject: has_method In-Reply-To: <41347A12.6020203@holdenweb.com> References: <41347A12.6020203@holdenweb.com> Message-ID: <41347C3E.2090407@geochemsource.com> > Well, one way is try/except: > > try: > a.someMethod(arg1, arg2) > except AttributeError: > print "Aarrgghh!" > But since I have my method name in a variable, it will be this way: methods = dir(self) if methodname in methods: cmd = "self." + methodname method = eval(cmd) This is what I wanted to avoid - i.e. the use of eval. There must be an easier and quicker way to do this. From ben at benlast.com Mon Aug 16 12:50:57 2004 From: ben at benlast.com (Ben Last) Date: Mon, 16 Aug 2004 17:50:57 +0100 Subject: Newbie question about file input In-Reply-To: Message-ID: Ah, now you're treading on holy war territory :) ben "Two Spaces McGraw" last > -----Original Message----- > From: python-list-bounces+ben=benlast.com at python.org > [mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of > Aaron Deskins > Sent: 16 August 2004 17:02 > To: python-list at python.org > Subject: Re: Newbie question about file input > > > Thanks to all for the replies. I changed it and it works fine. Now my > question- what is this convention on indentation? Should all > indentations be 4 spaces in? > > Thanks again. > > Peter Hansen wrote: > > > > > > Small note: it would make your code more readable and thus > > easier to comment on if you followed convention and used four > > spaces for indentation. Your volunteer tutors thank you! :-) > > > > > > -- > Aaron Deskins > Graduate Student > Chemical Engineering > Purdue University > -- > http://mail.python.org/mailman/listinfo/python-list From vinay_sajip at yahoo.co.uk Thu Aug 26 04:43:57 2004 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: 26 Aug 2004 01:43:57 -0700 Subject: Capturing exceptions? References: Message-ID: <2e37dc1.0408260043.5e1f83d4@posting.google.com> > Have a look at the logging module: > http://docs.python.org/lib/module-logging.html. Loggers can be a bit > complex at first to set up; read the example in the docs > (http://docs.python.org/lib/node301.html) and go from there. The version of logging in CVS is easier to set up. See the "in-development" documentation at http://www.python.org/dev/doc/devel/lib/minimal-example.html Best regards, Vinay Sajip From miki.tebeka at zoran.com Tue Aug 10 04:23:31 2004 From: miki.tebeka at zoran.com (Miki Tebeka) Date: Tue, 10 Aug 2004 10:23:31 +0200 Subject: VB-like GUI designer? In-Reply-To: References: <278de0e.0408090935.6d758a5d@posting.google.com> <30260531.0408091506.294cec8a@posting.google.com> Message-ID: <20040810082331.GA2636@zoran.com> Hello Fred, > >InnoSetup is an excellant installation package program that can take > >the output of py2exe (or whatever) and make a Setup.exe, it's not MSI > >mind you, but is free > > Yup, it's a nice app. I prefer to use NSIS because it has a scripting > language, though. Inno has a Pascal like scripting language which IMO is *way* easier than NSIS assembly like language. I recently switch from NSIS to Inno only because scripting was much easier. The Inno setup script is about 60% of the NSIS one for the same project with the same functionality. Bye. -- ------------------------------------------------------------------------ Miki Tebeka http://tebeka.spymac.net The only difference between children and adults is the price of the toys From ben at benlast.com Fri Aug 20 03:13:15 2004 From: ben at benlast.com (Ben Last) Date: Fri, 20 Aug 2004 08:13:15 +0100 Subject: Rita Sue and Bob too In-Reply-To: Message-ID: > From Peter Hansen > > But, how to I find a sequence in a list of unknown size? i.e. > this sequence > > in list of other names and replace it with three others? > > > > 'Rita','Sue','Bob' > > > > This is almost a nightly occurrence (my posting questions), but I am > > learning : ) This isn't necessarily the best way to do it generally, but it's an Interesting problem to play with, so here's an Interesting solution. Use the string facilities that already exist to search sequences (a string is a sequence too). All you need to is convert the lists to strings and back: seqToFind = ['Rita','Sue','Bob'] seqToReplace = ['A','B','C'] seqToSearch = ['Ben','Peter','Guido','Mark','David','Rita','Sue','Bob','Junk','Extra'] #joiner should of course be a substring that doesn't occur in the list elements. joiner = "~~" stringToFind = string.join(seqToFind,joiner) stringToSearch = string.join(seqToSearch,joiner) stringToReplaceWith = string.join(seqToReplace,joiner) resultString = stringToSearch.replace(stringToFind,stringToReplaceWith) resultSeq = resultString.split(joiner) That last block could also be written as: #s ends up with the resulting list s = seqToSearch s = string.join(seqToSearch,joiner).replace(string.join(seqToFind,joiner),string .join(seqToReplace,joiner)).split(joiner) But that's verging on the obfuscated :) regards, b From mwh at python.net Fri Aug 20 08:35:44 2004 From: mwh at python.net (Michael Hudson) Date: Fri, 20 Aug 2004 12:35:44 GMT Subject: Overriding tp_getset attribute in subclasses References: Message-ID: Thomas Heller writes: > I have a subclassable type implemented in C, which has a 'value' > attribute implemented in the tp_getset slot. The type is named c_long. > The value attribute accepts and returns integers. > > Now I want to derive a subclass 'BOOL' (in Python) from it, where the > 'value' attribute should accept and return bool instances: > > from ctypes import c_long > > class BOOL(c_long): > def _get_value(self): > return bool(c_long.value.__get__(self)) > # this also works: > # return bool(super(BOOL, self).value) > > def _set_value(self, val): > c_long.value.__set__(self, val) > # this does not work: > # super(BOOL, self).value = val > > value = property(_get_value, _set_value) > > I had expected the commented out super() calls to also do the work, but > at least in the _set_value method it does not work: > > File "c:\sf\ctypes\win32\wintypes.py", line 37, in _set_value > super(BOOL, self).value = val > TypeError: 'super' object has only read-only attributes (assign to .value) A bug on SF just like this just got closed, and this text added to the documentation: Note that \function{super} is implemented as part of the binding process for explicit dotted attribute lookups such as \samp{super(C, self).__getitem__(name)}. Accordingly, \function{super} is undefined for implicit lookups using statements or operators such as \samp{super(C, self)[name]}. So you should write super(BOOL, self).__setattr__('value', val) or similar. > The c_long.value.__get__ and c_long.value.__set__ variants work, but > they look strange - is there a better way? I guess super(BOOL, BOOL).value.__set__() might work too... haven't tried it, though. I also note that the documentation for super() starts off with Return the superclass of \var{type}. which is wrong, and that super() is documented in libfuncs.tex, which is also wrong. Some bug reports are coming up! Cheers, mwh -- 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 dave at pythonapocrypha.com Mon Aug 30 13:26:19 2004 From: dave at pythonapocrypha.com (Dave Brueck) Date: Mon, 30 Aug 2004 11:26:19 -0600 Subject: Size of a remote URL In-Reply-To: References: Message-ID: <4133633B.1010001@pythonapocrypha.com> Justin wrote: > I want to track the download of files in a progress bar. I asume I > need the final size to do that so I can compare it to the current size > on disk. Le tme know if you know anything Yep, you're basically out of luck. You'll notice that the download dialog boxes on most web browsers have two "modes" - one in which they show a progress bar, time remaining, etc. because the file size is known, and another mode in which they show megabytes downloaded so far (plus perhaps time elapsed or something) because the size is not known - the progress bar doesn't show any progress. You'll probably have to do something similar. Too bad, huh? -Dave From has.temp2 at virgin.net Sat Aug 21 12:57:07 2004 From: has.temp2 at virgin.net (has) Date: 21 Aug 2004 09:57:07 -0700 Subject: Has anyone implemented BASIC in Python? References: <2oo13eFcj548U1@uni-berlin.de> Message-ID: <69cbbef2.0408210857.79439c35@posting.google.com> Leif K-Brooks wrote in message news:<2oo13eFcj548U1 at uni-berlin.de>... > Has anyone ever tried implementing a simple unstructured BASIC dialect > in Python? I'm getting interested in language implementation, and > looking at a reasonably simple example like that could be pretty > interesting. Dunno about BASIC, but Ian Bicking has done Logo: http://pylogo.sourceforge.net/ HTH From eric at cs.hmc.edu Wed Aug 4 21:15:56 2004 From: eric at cs.hmc.edu (Eric O. Angell) Date: Wed, 4 Aug 2004 18:15:56 -0700 Subject: optparse object population Message-ID: <20040805011555.GB15014@cs.hmc.edu> Say I have class Header: def __init__(self): self.foo = 0 # ... more fields and I have some commandline options that can specify better values for things in the header, such as foo. If I try the obvious (to me): parser = optparse.OptionParser() parser.add_option('--secret', type='string', dest='header', default=Header()) parser.add_option('--foo', type='int', dest='header.foo') (options, args) = parser.parse_args() when I run the program with "--foo 3", I'm sadly left with something like this: >>> print options , 'header.foo': 3}> So when optparse first initializes the variables to None, it's creating a 'header.foo' that has nothing to do with header=Header(). Is there a way to coerce optparse into populating an object for me? Yes, I could just do something like this: (options, args) = parser.parse_args() header = Header() header.foo = options.foo # ... more population of header but I'd rather just end up with options.header that I could then use somewhere else. Am I going to have any success with this, or am I just SOL? Thanks. -E From dd55 at cornell.edu Tue Aug 3 15:19:06 2004 From: dd55 at cornell.edu (Darren Dale) Date: Tue, 03 Aug 2004 15:19:06 -0400 Subject: executing python programs as if they were on OS path (noob) Message-ID: Is there a place to put python programs so I dont have to refer to the absolute path everytime I want to call them? For example: if I am in /home/me and want to execute: python /home/me/python/export.py temp.dat what could I do so this will work: python export.py temp.dat Thanks, Darren From amajorel at teezer.fr Mon Aug 30 21:12:55 2004 From: amajorel at teezer.fr (Andre Majorel) Date: Tue, 31 Aug 2004 01:12:55 +0000 (UTC) Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4PGdnfsOfdDPi63cRVn-tA@speakeasy.net> <41337FC9.8070902@hotmail.com> Message-ID: On 2004-08-30, Antony Sequeira wrote: > Andre Majorel wrote: >> On 2004-08-28, Rob Warnock wrote: >> >>>Pascal Bourguignon wrote: >>>+--------------- >>>| $ telnet xahlee.org 80; >>>| Trying 208.186.130.4... >>>| Connected to xahlee.org. >>>| Escape character is '^]'. >>>| GET / HTTP/1.1 >>>| >>>| HTTP/1.1 400 Bad Request >>>| Date: Fri, 27 Aug 2004 01:35:52 GMT >>>| Server: Apache/2.0.50 (Fedora) >>>| ^^^^^^^^^^^^^^^^^^^^^^ >>>+--------------- >>> >>>So are you complaining about the fact that his hosting provider >>>preloaded RedHat Fedora with Apache 2.0 for him? >> >> >> There is no shortage of Windows-based hosting companies, so why >> didn't he go there ? Whatever your opinions, it's best to put >> your money where your mouth is if you expect to be taken >> seriously. > > Windows (MS) is not 'Unixism'? If by unixism, you mean any operating system that has a hierarchical filesystem and byte stream files, yes. But that would include quite a few other non-Unix operating systems, including Mac OS 9, Prologue and probably everything else this side of CP/M (DOS 1.x shall be deemed to be CP/M). -- Andr? Majorel Conscience is what hurts when everything else feels so good. From in.aqua.scribis at nl.invalid Thu Aug 19 09:37:26 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Thu, 19 Aug 2004 15:37:26 +0200 Subject: speed Message-ID: I implemented a lexer in Pylly and compared it to the version I had written in Flex. Processing 219062 lines took 0.9 seconds in C (from Flex), and 5 minutes 54 second in Python (from Pylly), a ratio of 393 to 1. Is this normal for Python, or does Flex produce better parsers than Pylly? I have been looking at the code produced by Flex to see if I could translate it to Python automaticly. But it has a lot of goto statements, and I haven't figured out how to translate those to Python efficiently. What are the average times used for text processing of Python compared to C? -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From dd at guv.ethz.ch Sun Aug 15 17:25:35 2004 From: dd at guv.ethz.ch (=?iso-8859-15?Q?David_D=FCrrenmatt?=) Date: Sun, 15 Aug 2004 23:25:35 +0200 Subject: Python "decompyle" References: Message-ID: On Sun, 15 Aug 2004 15:57:30 -0400, Terry Reedy wrote: > "David D?rrenmatt"
    wrote in message > news:opscrrsaxt5kr1pg at news.swissonline.ch... >> If I try to use decompyle (decompyle-2.3) for pyc-files < version 2.0, I >> get an error with marshal_20 (ImportError: dynamic module does not >> define >> init function (initmarshal_20) ). marshal_20 was compiled to a so-file >> using gcc. >> >> Does anybody know where this error could come from and how to solve it? > > Your post suggests that your build does work for .pyc files >= version > 2.0. > Is this correct? Does the doc for decompyle say it should work for > earlier > versions? Yes, it does work. And documentation says, it should. Fact is, marshal_20 is used to read the marshaled data in the pyc files < 2.0 (different version of marshal). And the problem doesn't really lie in decompyle itsself: if I try to import marshal_20 from python prompt, I get the error mentioned above. Thanks, dave From ian at cottee.org Sat Aug 21 05:35:17 2004 From: ian at cottee.org (Ian J Cottee) Date: Sat, 21 Aug 2004 18:35:17 +0900 Subject: age of Python programmers In-Reply-To: References: Message-ID: 37 Been using Python for three years I'd guess. Learnt it in order to try and understand Zope better :) Ian From lbates at swamisoft.com Mon Aug 2 10:40:32 2004 From: lbates at swamisoft.com (Larry Bates) Date: Mon, 2 Aug 2004 09:40:32 -0500 Subject: get attribute from a parent class References: <410d9a13$1@clarion.carno.net.au> Message-ID: I normally do something like this: class A: def __init__(self, parent): self.parent=parent # # Access parent's variables by using # self.parent.. # self.var = parent.var2 t1=self.parent.var1 t2=self.parent.var2 return class B: def __init__(self): self.var1=0 self.var2=1 self.classA=A(self) # # Access classA's attributes by using # self.classA. # t1=A.var return HTH, Larry Bates Syscon, Inc. "Steve" wrote in message news:410d9a13$1 at clarion.carno.net.au... > Hi, > > I have a nested class declaration such as: > > class A: > def __init__(self): > self.var = "A's variable" > # end def > > class B: > def __init__(self): > self.var2 = "B's variable" > # end def > # end class B > # end class A > > > What I want to do is to be able to get class A's 'var' variable from the > nested class B. For example, I want to be able to do something like: > print "I can see you %s" % a.var > > > but... I don't want to make 'var' a class variable. I want it to be an > instance variable but still be viewable by the inner class B. Is this > possible? Any suggestions? Thanks > > Steve > From ialbert at mailblocks.com Sat Aug 28 14:58:42 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Sat, 28 Aug 2004 14:58:42 -0400 Subject: Zope 2.7.2 win32 - Sessions not working In-Reply-To: References: Message-ID: Kyle Yancey wrote: > I've scratched my chin over this for the longest time. I think I'm > going to need some help. I'm creating a web app with zope. It has a > typical user login based on email and password. A ZSql method is > called to look up the customers unique id. That id is then assigned Just an observation, in your example you seem to try to go the account page even when the login fails (no records)... Istvan. From b.niemann at betternet.de Fri Aug 13 09:31:32 2004 From: b.niemann at betternet.de (Benjamin Niemann) Date: Fri, 13 Aug 2004 15:31:32 +0200 Subject: Displaying images stored as binary in MySQL In-Reply-To: References: Message-ID: Blaktyger wrote: > How can this be done? Images are stored in a LONGBLOB field. When I > try to display them, it prints out the binary data as it is... Display where? On local screen, in a webbrowser? Assuming the first one, see post by Tom. Assuming the second one (you're writing a cgi,mod_python... program), did you set the content-type in the http header correctly? From buzzard at urubu.freeserve.co.uk Mon Aug 2 13:04:29 2004 From: buzzard at urubu.freeserve.co.uk (Duncan Smith) Date: Mon, 2 Aug 2004 18:04:29 +0100 Subject: Timing Difference: insert vs. append & reverse References: <35b736b9.0408020330.53b24ed3@posting.google.com> Message-ID: "John Keeling" wrote in message news:35b736b9.0408020330.53b24ed3 at posting.google.com... > Dear all, > I tried the test program below. My interest is to examine timing > differences between insert vs. append & reverse for a list. My results > on my XP Python 2.3.4 are as follows: > time_reverse 0.889999389648 > time_insert 15.7750005722 > Over multiple runs ... the time taken to insert at the head of a list, > vs. the time taken to append to a list and then reverse it is > typically 16 or 17 times longer. Shouldn't that really be insert vs. reverse & append & reverse. :-) Duncan From dbickett at gmail.com Tue Aug 24 19:43:54 2004 From: dbickett at gmail.com (Beeyah) Date: 24 Aug 2004 16:43:54 -0700 Subject: Printing date a file References: Message-ID: <1d6cdae3.0408241543.343eaa2@posting.google.com> Kory Wheatley wrote in message news:... > In Python how would you print the date in a file, I > have a logging program written in python and for each > new recorded added to the file, I would like to print > the > date, something like this below: > > 08/24/2004 or 08-24-2004 > > -- > Kory Wheatley Read up on the time module, specifically strftime. Daniel Bickett From roy at panix.com Sat Aug 7 18:40:47 2004 From: roy at panix.com (Roy Smith) Date: Sat, 07 Aug 2004 18:40:47 -0400 Subject: Decorators References: <%A8Rc.50217$Vm1.1280580@news20.bellglobal.com> Message-ID: "Colin J. Williams" wrote: > It seems desirable that we choose words which are as close as possible > to their everyday usage. On the other hand, it's desirable to pick words which have established meanings in computer science too. The concept of a "decorator" is pretty well established. The term has been used in GUI frameworks for 10 or 15 years, and more recently has been enshrined in various pattern collections. From tim.peters at gmail.com Thu Aug 26 23:48:07 2004 From: tim.peters at gmail.com (Tim Peters) Date: Thu, 26 Aug 2004 23:48:07 -0400 Subject: What GCC version had defined? In-Reply-To: <20040827022642.GB5794@unpythonic.net> References: <412e39d1$1@nntp0.pdx.net> <412E55A9.9070400@v.loewis.de> <412e70d3$1@nntp0.pdx.net> <20040827022642.GB5794@unpythonic.net> Message-ID: <1f7befae04082620483f5c5397@mail.gmail.com> [Jeff Epler] ... > I'm not sure why uintptr_t or intptr_t are all that useful, since the > spellings "unsigned *" and "int *" are going to work everywhere > anyway. intptr_t isn't a pointer type, it's a signed integer type wide enough so that, for every valid void* P, (void*)(intptr_t)P == P C99 refuses to guarantee that such a type exists, but Python requires one (and int, long or "long long" is big enough on all Python platforms to date). Similarly for uintptr_t. From alexander.dejanovski at laposte.net Fri Aug 6 08:41:14 2004 From: alexander.dejanovski at laposte.net (Alexander DEJANOVSKI) Date: Fri, 06 Aug 2004 14:41:14 +0200 Subject: [Jython-users] ANN : JyRetic EAI Server 1.0 released Message-ID: <7086856.1092106020750.JavaMail.SYSTEM@c1879626-a> JyRetic 1.0 is now available after for Retic 1st birthday... The most important new feature is the integration of Tanuki Software's "Java Service Wrapper". It adds to Retic great restart-on-crash features. Other changes are : - New : Adaptor and parameter definitions are now stored to provide, among others, "restart" features. - Bug fix : Exceptions are now correctly raised on error in SQLSink. - New : SMTP Postprocessor - New : Jabber Postprocessor - New : SNMP Trap Appender (logger) - Various bug fixes and improvements I might have forgotten... Retic Administrator 1.32 is out too (Upgrade is highly recommended) Changes are : - Fix : Corrected bug on WSDL parsing during WS component creation - Fix : Corrected bug on estimated end time in execution tracking - New : New items in execution tracking popup menu => Open adaptor definition, Open params definition and restart - New : support for scheduling permanent adaptors Have fun !! ============================================================= WHAT IS RETIC ? Retic is an EAI Server. The aim is to permit applications to communicate, even if they don't speak the same language (which means transport protocols as well as data structures). This is done by building adaptors. An adaptor is composed of : - One source - Several pipes (process data transformations) - Several sinks (destination of data) - Several loggers (using log4j) - Preprocessors (executed only once before adaptor execution - for example => drop/create a table through a SQL query) - Postprocessors (executed only once after adaptor execution - for example => creation of an index on a table through a SQL query) It is written in Jython and works 100% fine with only Java 1.3+ installed (although some libs like cocoon.jar and poi-block.jar might only work on Java 1.4, delete them in case you can't upgrade) on your system (jython 2.1 is embedded in the releases). It provides connectivity with : JMS, HTTP, SOAP, UDDI, FTP, Xindice, JDBC, Jabber, SMTP and more... ============================================================= ------------------------------------------------------- This SF.Net email is sponsored by OSTG. Have you noticed the changes on Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now, one more big change to announce. We are now OSTG- Open Source Technology Group. Come see the changes on the new OSTG site. www.ostg.com _______________________________________________ Jython-users mailing list Jython-users at lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jython-users From edreamleo at charter.net Fri Aug 6 12:08:19 2004 From: edreamleo at charter.net (Edward K. Ream) Date: Fri, 6 Aug 2004 11:08:19 -0500 Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) References: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> Message-ID: <10h7b7lfmoq0124@corp.supernews.com> > Please reconsider the "def f() [classmethod]:" construct. +1 from me. Edward -------------------------------------------------------------------- Edward K. Ream email: edreamleo at charter.net Leo: Literate Editor with Outlines Leo: http://webpages.charter.net/edreamleo/front.html -------------------------------------------------------------------- From Scott.Daniels at Acm.Org Wed Aug 25 11:00:35 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 25 Aug 2004 08:00:35 -0700 Subject: Begginer question about py install In-Reply-To: References: Message-ID: <412cab38$1@nntp0.pdx.net> Player wrote: > During my setup install of python, I came across an option stating... > Compile python files to, .pyc > I left it unchecked for now, should I of done otherwise?? Generally no biggie one way or another. If the python directories are only admin (or root or...) writable, this is a good idea. Otherwise, the first use of any module will do the compile, and all subsequent uses will use that result. > I assume by compiling the python files to pyc they would run that little bit > faster?? They always get compiled, and the results of the compilation are stored in either .pyc or .pyo files, if the write doesn't fail. Whether the write fails or not, the compiled code is used. -Scott David Daniels Scott.Daniels at Acm.Org From sross at connectmail.carleton.ca Thu Aug 12 07:32:14 2004 From: sross at connectmail.carleton.ca (Sean Ross) Date: Thu, 12 Aug 2004 07:32:14 -0400 Subject: decorator with ``` References: Message-ID: <0zISc.18837$a65.823987@news20.bellglobal.com> "Roman Suzi" wrote in message news:mailman.1555.1092303160.5135.python-list at python.org... > > One more crazy syntax before-def but which could be treated > more generally: > > ```""" Factory for new decorator syntaxes. > > Keeps all proposals in a list and will recombine > them at random if called without a spec. """ > staticmethod``` > def makeDecoratorSyntax(spec=None): > raise NotImplementedException() > > New execution block type (in addition to exec, eval and > interactive) could be added to allow needed behaviour. > [snip] I think it would be interesting if triple-back-ticks could be used to introduce a kind of meta-scope, using 'this' to refer to the namespace being operated upon (so you wouldn't have to spell out the object's name all the time). For example: def makeDecoratorSyntax(spec=None): ```""" Factory for new decorator syntaxes. Keeps all proposals in a list and will recombine them at random if called without a spec. """ this = staticmethod(this) # <- transformation explicit this.author = "somebody" # <- add attributes normally ``` raise NotImplementedException() This idea could be used to do transformations on classes and modules as well. From just at xs4all.nl Sat Aug 28 04:16:39 2004 From: just at xs4all.nl (Just) Date: Sat, 28 Aug 2004 10:16:39 +0200 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <1LMXc.67190$UTP.37420@twister01.bloor.is.net.cable.rogers.com> <1gj7a9r.g7ec5a1g89rj0N%aleaxit@yahoo.com> Message-ID: In article , Jorge Godoy wrote: > It would be great to have one example with more than one file. > > From the discussion I got curious and tested it here and -- since > Python's so efficient I wasn't surprised that -- it worked. > > > > $ cat test.py > def test(): > print "Test from file 1" > > $ cat test2.py > def test(): > print "Test from file 2" > > > >>> import sys > >>> sys.path.append('test.zip') > >>> import test > >>> import test2 > >>> test.test() > Test from file 1 > >>> test2.test() > Test from file 2 > >>> > > > I also noticed that there was no '.pyc' created for that import, as is > usually done for uncompressed modules. The zipimport module will never write to the zip archive, so for most efficient imports, you have to store .pyc data in there yourself. zipimport is mostly meant as a repackaging tool, and typical zip files only contain .pyc files. Just From faizans at gmail.com Thu Aug 12 23:17:21 2004 From: faizans at gmail.com (Fazer) Date: 12 Aug 2004 20:17:21 -0700 Subject: Python and Weather.com Message-ID: <6491b0ab.0408121917.5103b770@posting.google.com> Hello, I made a small python script that gives the current weather conditions of a city that you give as an argument. Here's the basic function behind it: I am really a beginnering when it comes to parsing XML but I just used split to get the values I wanted. Any ideas how I can use proper XML parsing techniques? Also, the weather degree is in celcius but I conver it to fahrenheit as well. :-) Here's the code: # Get the weather for the city specified def get_weather(city): #city = city.replace(" ", "%20") w = urllib.urlopen("http://xoap.weather.com/search/search?where=%s" % city.replace(" ", "%20")).read() # Check if there were matches if not city.isalpha() or w.find("loc") < 0: return "No matches found for city of " + city + "!" # If so, use the first search result and use it city = w.split("", 1)[0].split("")[1] # Get location id of the first city locid = w.split("", 1)[0].split("")[0].split("")[1] # Get temperature temp = weather.split("")[0].split("")[1] if "N/A" in temp: return "Error" else: temp = int(temp) return "Weather for %s is %s C / %s F and %s" % (city,temp,(temp * 1.8) + 32,reading) Hope it helps anyone out there. Please feel free to fix anything I may have done wrong. Comments greatly appreciated! Thanks, Faizan S. From p.willis at telus.net Sun Aug 22 20:14:34 2004 From: p.willis at telus.net (pw) Date: Mon, 23 Aug 2004 00:14:34 GMT Subject: Parsing Python code with a Python Program In-Reply-To: References: Message-ID: Hello, I had my quotes wrong is all. EXAMPLE: exec 'print "Hello"' OR: s = 'print "hello"' exec s Thanks anyway, Seaweed pgw wrote: > Hello, > > I would like to pass strings to a Python > application and have them executed as though > they were lines of code. > > Is 'exec()' the function that I am looking for > and/or is there an example of this somewhere? > > Thanks, > > Seaweed > From ben at benlast.com Mon Aug 16 12:54:17 2004 From: ben at benlast.com (Ben Last) Date: Mon, 16 Aug 2004 17:54:17 +0100 Subject: Newbie question about file input In-Reply-To: <75fc9ad504081609226eca03f@mail.gmail.com> Message-ID: > Isn't it a strange way to do a loop? Create a loop with a foo > condition and use an if to break it? Not necessarily. The use of "while True" at least signals that the loop exit condition isn't at the top. I suspect, though, that this is a "style" question, and as such there will be a Mighty Discussion about it... > ===== > line=zf.readline() > while line: > . . . > line=zf.readline() > ===== > Isn't this code much more easy to understand? Arguably so, but you do the "next loop statement" (in this case, "line=zf.readline()") in two places. Redundancy. Chance of changing one and forgetting to change the other. Eww. But: for line in zf.readlines(): is even neater humbly yours, ben From Kevin.Smith at sas.com Tue Aug 24 14:25:54 2004 From: Kevin.Smith at sas.com (Kevin Smith) Date: 24 Aug 2004 18:25:54 GMT Subject: Late binding eval()? Message-ID: <20040824142636721-0400@braeburn.themorgue.org> I want to evaluate an expression using eval(), but I only want to supply the variable values "on demand." For example, let's say that I want to evaluate 'x+y'. Normally, I would create a dictionary containing 'x' and 'y' with their corresponding values and pass it in as the globals or locals. However, in my application, I'm getting an arbitrary expression from the user. I thought that I could just create a dictionary-like object and override __getitem__ to look up values in a database as they were called for, but that didn't work. Another way of doing this would be to parse the expression and find all of the top-level variables. This could be a little tricky (i.e. [x for x in mylist] would only require 'mylist' to be in the dictionary of globals/locals. Does anyone have any ideas on how to do this? -- Kevin Smith Kevin.Smith at sas.com From tim.hochberg at ieee.org Wed Aug 4 10:13:24 2004 From: tim.hochberg at ieee.org (Tim Hochberg) Date: Wed, 04 Aug 2004 07:13:24 -0700 Subject: How to dynamically access Numeric subarrays In-Reply-To: References: Message-ID: <4110EF04.4030608@ieee.org> Gaubitzer Erwin wrote: > Hi again > > > For example I have an array AR whose shape is > (2, 1, 2, 1, 100, 3). > and I want to access > AR[0,0,0,0,:,1] > which results in an rank 1 array with my wanted > numbers (more advanced I want to loop through another > index). > > I can write it manually but I can't insert this > list of indices automatically, because the slice > notation gives me an error when given to a python list. I believe you want something like: >>> index = (0,0,0,0,slice(None,None),1) >>> AR[index] The args to slice will vary depending on exactly what you want to do. slice can take up to three arguments for start, stop, step. Since you seem to be delving deeply into the mysteries of numeric slicing, it may eventually help you to know that '...' is spelled Ellipsis if you want to use it in a tuple as above. Actually, the little class below will probably help you more than anything that I can write: class IndexInspector: def __getitem__(self, key): return key Used like: II = IndexInspector() print II[0,0,0,0,:,1] print II[...,0,0,:,1] prints: (0, 0, 0, 0, slice(None, None, None), 1) (Ellipsis, 0, 0, slice(None, None, None), 1) Regards, -tim > > I tried to use take() but in my 6-dimensional array > I wasn't able to find the right parameter combination > to access the vector above. > Maybe one can give me the right notation. > > Thanks again > > Erwin From irmen at -NOSPAM-REMOVETHIS-xs4all.nl Wed Aug 18 14:21:27 2004 From: irmen at -NOSPAM-REMOVETHIS-xs4all.nl (Irmen de Jong) Date: Wed, 18 Aug 2004 20:21:27 +0200 Subject: age of Python programmers In-Reply-To: References: Message-ID: <41239e2a$0$34762$e4fe514c@news.xs4all.nl> I'm 30-years-and-1-month. --Irmen From hemanthps at gmail.com Thu Aug 19 03:53:52 2004 From: hemanthps at gmail.com (Hemanth P.S.) Date: 19 Aug 2004 00:53:52 -0700 Subject: age of Python programmers References: Message-ID: 32. Program mainly in C at work(embedded systems) and have been using Python for hobby programs since I discovered it in 2000 while reading Eric Raymond's article on hackers. Here, in India, until last year,there were hardly any Python books in the stores - only tons of Java and Perl books. O'Reilly has now started bringing out Python books priced in Indian Rupees (and somewhat affordable to students). Still they are priced 1.5 times to 2 times the average price of a Java/Perl book; probably someone out there is scared that Python may become popular. --Hemanth From ptmcg at austin.rr._bogus_.com Mon Aug 23 11:21:58 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 23 Aug 2004 15:21:58 GMT Subject: python usage References: Message-ID: "Ville Vainio" wrote in message news:du7pt5hoqov.fsf at amadeus.cc.tut.fi... > >>>>> "Phanish" == Phanish writes: > > Phanish> which inturns calls c++ client stubs. These stubs are > Phanish> CORBA stubs which talk to a CORBA server residing some > Phanish> where in the network. I want to know as to whether it is > Phanish> feasible to use Python or just live with c++ for UI and > Phanish> stubs? > > One thing you may not yet know is that Python absolutely rocks for > CORBA - seeing how elegant CORBA can be is one of the reasons I > decided to check out Python in the first place. OmniORB is the ORB I > would check out first if I were you... > I too have had very good results using Python with CORBA. However, beware of interoperability issues, especially with proprietary ORBs. CORBA is not entirely as interoperable as one would hope.* Do a few experiments if you are writing Python/OmniORB clients to non-OmniORB servers, or vice versa. * this information is a little bit old, things may have improved in the past year... -- Paul From rich.teer at rite-group.com Thu Aug 26 13:57:44 2004 From: rich.teer at rite-group.com (Rich Teer) Date: Thu, 26 Aug 2004 17:57:44 GMT Subject: Larry Wall & Cults In-Reply-To: References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: On Thu, 26 Aug 2004, Tor Iver Wilhelmsen wrote: > Rich Teer writes: > > > I think you're getting confused with the Blue ?yster Cult. > > Actually, there is also The Cult, a British band that lasted from > 1984-1995. I belive the Cult (She Sells Sanctuary, etc.) is another manfifestation of the Blue ?yster Cult. -- Rich Teer, SCNA, SCSA, author of "Solaris Systems Programming", published in August 2004. President, Rite Online Inc. Voice: +1 (250) 979-1638 URL: http://www.rite-group.com/rich From lbates at swamisoft.com Wed Aug 4 18:25:16 2004 From: lbates at swamisoft.com (Larry Bates) Date: Wed, 4 Aug 2004 17:25:16 -0500 Subject: Compiled C++ and Mysql codes run in python cgi script References: Message-ID: mysql.sock is a normally a symbolic static link (normally located in /tmp directory) that is used to communicate with MySQL. I suspect that when you run under web interface, you don't have proper access rights to that directory for the program to communicate via this socket interface. HTH, Larry Bates Syscon, Inc. "Yong Wang" wrote in message news:mailman.1151.1091647807.5135.python-list at python.org... > Hi, All: > We have a network management system written in C++, MysQL, and Hp > SNMP. It works in Solaris command line. When I wrote a similar > python codes which call compiled C++ and mysql codes in solaris > command line, the comipled codes work fine in wraped python file. When > I change the python codes to web interface in python CGI script, I got > message > that "Can't connect to local MySQL server through socket > '/tmp/mysql.sock'" > How can I fix this problem because we want to migrate solaris command > line system to web access system ? The easiest way for me is directly > to call > compiled C++ and mysql codes (excutable) in python CGI scripts, then > post the run > results in website. > Thank you very much in advance and I am looking forward to your > reply. > > Yong > From peter at engcorp.com Mon Aug 30 16:03:04 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 30 Aug 2004 16:03:04 -0400 Subject: [IronPython] Jim Hugunin's web log. In-Reply-To: References: Message-ID: David Wilson wrote: > It would also greatly ease the need to advocate Python in places of > employment, as a Microsoft adopted product, it couldn't be wrong(tm). > This is perhaps the first time where I have been glad to see Microsoft > hijack something. Even if IronPython becomes a commercial offering, I'm > still sold. Will you still be "sold" if Microsoft embraces and mutates (or whatever is the pat phrase describing their amoebic methods) Python by introducing a half dozen incompatible new forms of syntax and such, confusing newcomers with market mumbo jumbo and vapourware announcements, stealing away some of the best minds from the open source community with obscene wages, and all those other little "couldn't be wrong(tm)" things that they have done in the past? This might be somewhat like what one of our (Canadian) past Prime Ministers referred to as "sleeping with an elephant" in reference to living next to the US. "No matter how friendly and even-tempered the beast, one is affected by every twitch and grunt." (See http://en.wikiquote.org/wiki/Pierre_Trudeau for a possibly accurate quote.) -Peter From anthonybaxter at gmail.com Sat Aug 21 15:15:10 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sun, 22 Aug 2004 05:15:10 +1000 Subject: Alternative decorator syntax decision In-Reply-To: References: <7x3c2iw9ig.fsf@ruckus.brouhaha.com> Message-ID: On Sat, 21 Aug 2004 08:39:39 -0400, Colin J. Williams wrote: > > This is not an option that is going to happen. The decorators thread > > has been discussed on python-dev for 2 1/2 years. The case for including > > them has been decided. The original decorators (classmethod, staticmethod) > > were introduced in Python 2.2, released late 2001. How long do you think > > we should wait? > > > Another six months won't make much difference. The transform > functionality is there now. PEP 318 formalizes things. Except that with 12-18 months between releases, that's actually a lot longer. Look, the decision that decorators are going to be in 2.4 was made some time ago. I've seen absolutely nothing to indicate that this is even faintly likely to change. From rogerb at rogerbinns.com Mon Aug 9 18:55:19 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Mon, 9 Aug 2004 15:55:19 -0700 Subject: VB-like GUI designer? References: <30260531.0408091048.7011855f@posting.google.com> Message-ID: simo wrote: > Fred wrote: > > [snip] >> I tried wxDesigner and wxGlade, but neither lets me move the widgets >> around. > > Dunno what you're smoking there man! I think what he means is that they generally force you to use sizers. For example in wxGlade, if you drag a button out onto a new frame, it has resize handles but you can't resize or position the button since it all ends up inside a sizer. You can type in new size/position in the object properties but that is insane. > Qt Designer (for use with PyQt though) or just hand-code the layout, > it ain't that hard..... For people who are happy with the licensing issues behind Qt, it is certainly best of breed. As for hand coding the layout, don't forget he has come from a VB world :-) Using sizers and hand coding is certainly usually in the best long term interests of many projects, but in the short term is more time consuming and frustrating (you just want to drag the buttons around). Roger From martindemello at yahoo.com Sat Aug 21 06:20:20 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Sat, 21 Aug 2004 10:20:20 GMT Subject: decorator J4 - any objections? References: <7xbrh5hcpb.fsf@ruckus.brouhaha.com> <7NsVc.155687$M95.24909@pd7tw1no> <7xd61ledg4.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Martin DeMello writes: > > > def func(arg1, arg2) > > > @version("Added in 2.4") > > > @returns(None): > > > > > > """Docstring could be here, or in decorator part above""" > > > # body goes here > > > > It's really nice to have an outdented marker for when the actual > > function body begins. > > I don't really see why, but the decorators don't have to be indented: > > def func(arg1, arg2) > -version("Added in 2.4") > -returns(None): > > """Docstring could be here, or in decorator part above""" > # body goes here > > I guess that's ugly though. Yep. What I love about J4 is it lets you scan a file very quickly, jumping from function to function and to the body when you find the one you want. Very little visual clutter. martin From info at sgtinfo.com Fri Aug 27 12:19:41 2004 From: info at sgtinfo.com (Gina Clemmer (SGT, Inc.)) Date: Fri, 27 Aug 2004 09:19:41 -0700 Subject: Reminder: Oklahoma City Demographic Analysis Workshops (September 9th and 10th, 2004) Message-ID: <20040827072237.96F931E4003@bag.python.org> Oklahoma City Demographic Analysis Workshop Announcement- Still Time to Register! When: September 9th and 10th, 2004 - 9:00 am to 4:00 pm (One Day Workshop. Participants may choose either day.) Where: New Horizons Computer Training Center, 50 Penn Place, 1900 NW Expressway, Suite R305 Oklahoma City, Oklahoma 73118 Fee: $225 w/credit card at time of registration, $249 for check or purchase order after workshop Register Now Register online at www.sgtinfo.com or call us at 877.241.6576. The Oklahoma City Demographic Analysis Workshop will teach you to extract, query, download, analyze, and map Census demographic data for OKC and surrounding communities. (Note: Participants may substitute their own community in exercises-all techniques are directly transferable to other communities). Such data can provide grant writers, social researchers and community planners with powerful tools for analyzing community changes. This is a streamlined, ?hands on? workshop where each participant works on their own computer throughout the day. This workshop also provides an introduction to Geographic Information Systems (GIS) which includes a discussion of GIS trends and common uses, where to easily obtain mapping files, a demonstration of the map browser ArcExplorer (included with your materials), hands on practice making basic maps online and suggestions for making effective maps. See a detailed description Materials include: A comprehensive workbook that includes the workshop presentation, exercises, reference materials and a valuable Demographic Data Resource CD. This CD includes useful GIS tools such as ArcExplorer and several shapefiles for all communities in the United States. Materials also include a 60 day trial version of ArcView 8.3, a leading GIS software. Also included is the 2003 US Statistical Abstract which includes an extensive selection of statistics for the United States, with selected data for states, metropolitan areas and cities. This workshop will: Teach you to extract, query, download, analyze, map and present 2000-1990 Census of Population and Housing and 2003 American Community Survey data that includes Poverty, Race/Ethnicity, Age, Housing, Language and Transportation; Teach you to construct a Local Community Change Profile. The Profile is comprised of key demographic variables and customized for OKC and a Census tract within OKC (participants may also substitute their own community); Teach you analytical, demographic and spatial analysis techniques including commonly used mathematical formulas to transform raw data into compelling information; Teach you about Census geography including common problems such as working with non-Census boundaries, analyzing change over time despite boundary changes and how to use new mapping functionality recently built in to American Factfinder; Provide you with exceptional materials that you can use immediately to assist with social research and analysis. Former Workshop Participants' Comments: View Other Participants' Comments Oklahoma University, Research and Evaluation Center (2003) "Very helpful update on the new technology available from the census bureau and the thematic maps are extremely important and very much under utilized." Oklahoma University, Institute For Public Affairs (2003) "Thanks very much. I wasn't sure this would be beneficial but it exceeded my expectations in every way. This was an excellent use of my time!" City of Edmond, Oklahoma (2003) "Very informative. Every city planner and grant writer should attend this class." Oklahoma Department of Human Services (2003) "Beneficial, Enjoyable and learned new demographic census processes and the materials were very helpful." SmartGirl Technologies is a social research company located in Portland, Oregon. For more information about the workshop, who we are and what we do, check out our website at www.sgtinfo.com. If do not want to receive further announcements, click here and simply send us a blank email. We will immediately take you off of the announcement list. You may also reply to this email with the word "delete" in the subject line. Note: Under no circumstance will we share your email with any other party or person. -------------- next part -------------- An HTML attachment was scrubbed... URL: From lbates at swamisoft.com Mon Aug 2 13:45:58 2004 From: lbates at swamisoft.com (Larry Bates) Date: Mon, 2 Aug 2004 12:45:58 -0500 Subject: New to Python/Programming References: <10gsujk1og2gkbf@corp.supernews.com> Message-ID: Lots of online documentation and tutorials here: http://www.python.org/doc/2.3.4/ If you are working on Windows, "Python Programming on Win32" is a great book that has "Windows specific" information. Monitoring this list and watching for "newbie" questions is also beneficial as many will help with examples. I found Python Bible by Brueck and Tanner to be another excellent book (I purchased both books at Books a Million). HTH, Larry Bates Syscon, Inc. "Mark" wrote in message news:10gsujk1og2gkbf at corp.supernews.com... > Hello. I am new to programming and Python and was wondering if someone > could help get me started. I picked Python to start learning to prgram > because of some things I have read about it (easy to learn, object > oriented, clear syntax, etc...). Can anyone assist in getting me > started with learning to program and Python? Recommended reading > material? Online tutorials? Recommended development tools (wxpython, > pythonwin, etc...)? I am a network admin by trade and have done little > programming except for the occasional script or router config. this is > something that has always interested me, but don't have the time to take > any formal classes. Thanks for the help. From __peter__ at web.de Mon Aug 16 07:47:20 2004 From: __peter__ at web.de (Peter Otten) Date: Mon, 16 Aug 2004 13:47:20 +0200 Subject: NumArray array-indexing References: Message-ID: Michael Drumheller wrote: > array-indexing. Here's the basic situation: Given a rank-2 array > (i.e., a matrix) it seems to be trivial, with array indexing, > to extract a subset of its columns. But it does not seem > to be trivial to extract a subset of its rows. The code Could it be you are looking for the Ellipsis (...)? >>> a = numarray.array(range(9), shape=[3,3]) >>> a array([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) >>> a[0:2] array([[0, 1, 2], [3, 4, 5]]) >>> a[..., 1] array([1, 4, 7]) >>> a[..., 1:] array([[1, 2], [4, 5], [7, 8]]) >>> a[..., 0:3:2] array([[0, 2], [3, 5], [6, 8]]) Of course in 2D you do not really need it: >>> a[:, :2] array([[0, 1], [3, 4], [6, 7]]) But at some point it may make things clearer: >>> a = numarray.array(range(2**10), shape=[2]*10) >>> a[...,:][(-1,)*7] array([[[1016, 1017], [1018, 1019]], [[1020, 1021], [1022, 1023]]]) Peter From bdesth.quelquechose at free.quelquepart.fr Wed Aug 18 04:11:27 2004 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 18 Aug 2004 10:11:27 +0200 Subject: PEP 318: Can't we all just get along? In-Reply-To: <20040817181725194-0400@braeburn.themorgue.org> References: <20040817181725194-0400@braeburn.themorgue.org> Message-ID: <41230713$0$20684$626a14ce@news.free.fr> Kevin Smith wrote: > For what it's worth, I wrote the original PEP 318. I probably wasn't > qualified, but I just wanted a nice simple way to declare class methods > without having to repeat the function name. After submitting it to BDFL > for approval, more work was needed and the discussion of PEP 318 on > python-dev increased rapidly. It was evident that I was in over my head, > so I asked more someone more experienced to take over. > > I guess others had bigger plans for my proposal that I had planned. It > has turned into the "solution" to many problems: type checking (both > arguments and returned values), metaclasses, metadata, interfaces, > function attributes, etc.). Unfortunately, in the process, this simple > request for syntactical sugar has turned into a monstrosity. In my > opinion, none of the proposed syntaxes really seem Pythonic. This PEP > just seems to be trying to solve too many problems. > > Bear with me, but I'd like to propose one more syntax that is simple, > easy for newbies to understand, and nowhere near as powerful as the > current PEP's syntax. However, it doesn't add incoherent, arbitrary > syntax either. > > def classmethod foo(x, y, z): > pass > > That's it. One "decorator" that is a callable object that takes a > method as it's only argument. No expressions, lists, tuples, etc. Just > one callable object. +2 for me. > Ok, if you absolutely must have more than one. > def classmethod synchronized foo(x, y, z): > pass No. If you want more than one, provide your own decorator, ie : def synchronizedClassmethod(method): return synchronized(classmethod(method)) def synchronizedClassmethod foo(x, y, z): pass My 2 eurocents Bruno From mauriceling at acm.org Wed Aug 25 04:04:43 2004 From: mauriceling at acm.org (Maurice LING) Date: Wed, 25 Aug 2004 08:04:43 GMT Subject: python bytecodes by hand Message-ID: <412c4815$1@news.unimelb.edu.au> I remembered sighting a book "Programming for the Java Virtual Machine" by Joshua Engel some time back. In that book, he used Oolong as a way to program to JVM and indicated that it is actually possible to write a java class file by hand if inclined. I am just wondering about the structure of a pyc (python bytecode) file and has anyone successfully write a functional pyc file by hand? thanks maurice From mark_bottjer at hotmail.com Wed Aug 11 21:11:40 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Wed, 11 Aug 2004 21:11:40 -0400 Subject: wiki update: decorator syntax breakdown In-Reply-To: References: Message-ID: <411ac3cc$1@nntp.zianet.com> Steven Bethard wrote: > Just wanted to let everyone know that I went through the wiki and > tried to consolidate some of the advantages/disadvantages of the > various syntax decisions: Cool! *rummage* *rummage* Hm. Just as a note, I didn't spot the following (recent?) variant: class C: def c(self): meta: classmethod doc('This is a function!') pass For example, see the "Decorators proposal" thread. Thanks for all the hard work. -- Mark From maney at pobox.com Mon Aug 9 18:40:31 2004 From: maney at pobox.com (Martin Maney) Date: Mon, 9 Aug 2004 22:40:31 +0000 (UTC) Subject: Question on lists References: <41071cfe$0$60648$d5a6236f@newsreader.cybernetik.net> Message-ID: Aahz wrote: > Elaine Jackson wrote: >> >>If x is the given sequence, then >>[x[i] for i in filter(lambda i: i==0 or x[i-1]<>x[i], range(len(x)))] >>is what you want. > Please report to the UnPythonic Activities Committee. ;-) Has the committee considered the other functional solution? >>> def dedupe(lst, x): ... if not lst or lst[-1] != x: ... lst.append(x) ... return lst ... >>> reduce(dedupe, l, []) ['a', 'b', 'c', 'd', 'e'] If it would help, I'm sure we could get an obfuscation expert to make it into one line, but without a first-class conditional expression, it's nothing but a circus trick. Perl envy, like. Oh, okay, twist my arm... >>> reduce(lambda r,x: (not r or r[-1]!=x) and r.append(x) or r, l, []) ['a', 'b', 'c', 'd', 'e'] I knew reduce would come in handy for something. > "To me vi is Zen. To use vi is to practice zen. Every command is a > koan. Profound to the user, unintelligible to the uninitiated. You > discover truth everytime you use it." --reddy at lion.austin.ibm.com Apparently vi also shares with koans the characteristic of battering down the walls of rationality. :-) -- Although we may never know with complete certainty the identity of the winner of this year's presidential election, the identity of the loser is perfectly clear. It is the nation's confidence in the judge as an impartial guardian of the law. - Justice John Paul Stevens, from his dissenting opinion Dec 12, 2000 From mwilson at the-wire.com Tue Aug 10 08:01:00 2004 From: mwilson at the-wire.com (Mel Wilson) Date: Tue, 10 Aug 2004 08:01:00 -0400 Subject: Decorators References: <%A8Rc.50217$Vm1.1280580@news20.bellglobal.com> <10hfoqa9cj3e356@corp.supernews.com> <3GURc.11274$Mq1.610387@news20.bellglobal.com> Message-ID: <8jLGBls/KTpY089yn@the-wire.com> In article , Andrew Durdin wrote: >On Mon, 09 Aug 2004 20:29:59 -0400, Colin J. Williams wrote: >> >> There is also the question of whether 'decorator', a term which is used >> in everyday langage as indicating adornment, is the best choice for a >> transformation. > >def deco(f): > print f.__name__, "is now pretty!" > return f def deco (f): print f.__name__, "is now pretty!" def t (*s,**k): print """\ I'm so pretty, oh so pretty! I'm so pretty and witty and bright! """ return t > >@deco >def ugly_function(): > pass Throw in an f(*s,**k) there if you really feel you must. Regards. Mel. Portions copyright by Stephen Sondheim or somebody. From anthonybaxter at gmail.com Fri Aug 20 06:10:31 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 20 Aug 2004 20:10:31 +1000 Subject: PEP 318: Can't we all just get along? In-Reply-To: References: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: On Fri, 20 Aug 2004 05:57:42 -0400, Paul Morrow wrote: > I know you weren't Anthony (that was a joke). I understand that you > don't like this idea, but that doesn't make it a _bad_ one. Numerous > people have *not* effectively pointed out the problems with it (and > neither have you, sir). Err, what? Have you bothered to read the replies I sent to you? This is _bad_ magic behaviour. Python does not care about argument lists now, and adding this is icky. Your behaviour when _adding_ methods to classes is extremely undefined, particularly in the presence of descriptors. Explaining this to new users would be complex. It's a messy interference in the way Python's OO builds classes and objects, which is currently very clear and easy to follow[1]. It's not explicit, but implicit. How many ways do I have to spell this out? [1] with the double-underscore mangling put to one side, or preferably, off a bridge. The only argument _for_ this that you've offered is that it's just like the double-underscores. This is a losing argument (with me, anyway) as I regard the double-underscore mangling as awful - that sort of "data hiding" just ends up being a pain in the arse when you want to poke with a class's internals. Python regards everyone as an adult in that respect, unlike the "protecting you from yourself" C++ nightmare. In addition, the double-underscore is just random magic that occurs when a class is created, not subsequently: >>> class A: ... __foo = 1 ... >>> dir(A) ['_A__foo', '__doc__', '__module__'] >>> A.__bar = 2 >>> dir(A) ['_A__foo', '__bar', '__doc__', '__module__'] for the same reasons, your idea would lead to inconsistencies. Anthony From martin at v.loewis.de Fri Aug 6 15:37:02 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 06 Aug 2004 21:37:02 +0200 Subject: [Python-Dev] RELEASED Python 2.4, alpha 2 In-Reply-To: References: <411231C8.3020308@interlink.com.au> <4113429a$0$26993$9b622d9e@news.freenet.de> <41137960.6050400@v.loewis.de> Message-ID: <4113dddd$0$12507$9b622d9e@news.freenet.de> vincent wehren wrote: > This is on Windows XP Professional. This is a plain vanilla "limited > user" created via the user accounts tool in the control panel. Ok. I will try that. There is a policy AlwaysInstallElevated, with which the administrator can allow limited users to perform installations: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/alwaysinstallelevated.asp If the computer is in a domain, this policy can be controlled through group policy. Regards, Martin From export at hope.cz Fri Aug 13 15:22:41 2004 From: export at hope.cz (Lad) Date: 13 Aug 2004 12:22:41 -0700 Subject: How to sort records in file Message-ID: <81a41dd.0408131122.21180d0d@posting.google.com> What is the best( easiest)way how to sort a file? I have a file where each record consists of 3 fields( 3 words) and I would like to sort records by the first field( word)in each record. Any idea? Thanks for help Lad From listserver at tdw.net Fri Aug 6 12:18:29 2004 From: listserver at tdw.net (Tim Williams) Date: Fri, 6 Aug 2004 17:18:29 +0100 Subject: Finding a function name References: <788E231C269961418F38D3E360D1652526CA1E@tndefr-ws00021.tenovis.corp.lan> Message-ID: <010401c47bd1$02eb68a0$ccbefea9@twilliams> [ 1 step up from Newbie ] How can I find a function's name from within the function? >>> print container.trailing_period.__name__ trailing_period >>> print container.trailing_period.func_name trailing_period but from within the function itself, print (either option) gives "container" TIA From python at simon.vc Mon Aug 9 08:02:19 2004 From: python at simon.vc (SimonVC) Date: 9 Aug 2004 05:02:19 -0700 Subject: recursive list comprehension Message-ID: Is there a way to do this as a list comprehension? >>> def recu(alist, blist=[]): ... if len(alist)==0: print blist ... for i in range(len(alist)): ... blist.append(alist.pop(i)) ... recu(alist, blist) ... alist.insert(i, blist.pop()) >>> recu(list("abc")) ['a', 'b', 'c'] ['a', 'c', 'b'] ['b', 'a', 'c'] ['b', 'c', 'a'] ['c', 'a', 'b'] ['c', 'b', 'a'] Cheers SimonVC keywords: python recursive permutations algorithm combination jumble From rnichol_rrc at yahoo.com Wed Aug 18 12:43:52 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Wed, 18 Aug 2004 11:43:52 -0500 Subject: age of Python programmers In-Reply-To: References: Message-ID: 27 Mike C. Fletcher wrote: > survey that might have this information with *real* numbers. Theres a > good little bump among the scientific and core-dev peoples for late > forties and above (maybe those careers keep you flexible enough to try > new things? Maybe the projects are experimental enough that using a > "new" language isn't a problem?) The people who enter a carreer that involves science to any real degree *must* mantain flexibility. They typically do research and nothing would really get done if this weren't the case. Since experimental math came along (very recent - I believe in just the last few years) and since numerics is a large part of Physics now, it'd make sense that the older ones would pick up an easy to learn language. And since the GSL has python bindings, all the better. From peter at engcorp.com Mon Aug 9 11:53:12 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 09 Aug 2004 11:53:12 -0400 Subject: VB-like GUI designer? In-Reply-To: References: Message-ID: Gary wrote: > Boa Constructor is a diamond in the rough: > http://boa-constructor.sourceforge.net/files/boa-constructor-0.2.8-snapshot.tgz Didn't you mean "a snake in the grass"? ;-) From Andreas.Ames at tenovis.com Fri Aug 20 09:30:21 2004 From: Andreas.Ames at tenovis.com (Ames Andreas (MPA/DF)) Date: Fri, 20 Aug 2004 15:30:21 +0200 Subject: [Q] Bug in cgi.FieldStorage? Message-ID: <788E231C269961418F38D3E360D1652526CA2E@tndefr-ws00021.tenovis.corp.lan> Hi, I'm currently using Zope 2.7.2-0 which in turn uses cgi.FieldStorage from Python 2.3.4. FieldStorage can either build a 'list' or a 'file' to represent a request. Unfortunately it overwrites __len__ such that it throws an exception when the request wasn't of type 'multipart', i.e. when it doesn't 'return' a list but a file. I'd consider this a bug because if you have an instance fs of FieldStorage you can't safely write if fs: ... because of the unfortunate __len__ implementation (it raises a TypeError exception in some cases). I might be willing to accept that this isn't python's bug but mine if someone argues smartly enough. What's is the right thing to do in this case (and in the general case)? 1) The idiom 'if fs:' is borked. I'm not supposed to use it, I should have known and I'm dumb. Instead I'm supposed to use 'if fs is not None:' or something. (This seems to be smart enough an argument for me :-) 2) cgi.FieldStorage should have a more appropriate __len__ implementation. If so, how? 3) cgi.FieldStorage should overwrite __nonzero__ to always return 1. I'm leaning towards this one. Am I right? tia, andreas From pete at shinners.org Mon Aug 2 10:31:08 2004 From: pete at shinners.org (Pete Shinners) Date: Mon, 02 Aug 2004 07:31:08 -0700 Subject: Pygame - Only ONE Font found!? In-Reply-To: References: Message-ID: Askari wrote: > print "ListFont :", pygame.font.get_fonts() > > the resultat is: > ListFont : ['netropaosdicon'] On Windows, Pygame finds its system fonts in the registry. It looks under one of these locations. I'd say load up regedit and see if your fonts are in there. "SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts" "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" From adurdin at gmail.com Thu Aug 12 01:23:22 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Thu, 12 Aug 2004 15:23:22 +1000 Subject: The winner of the Python Decorator Poll is... In-Reply-To: <4edc17eb.0408112052.1bbd85b3@posting.google.com> References: <4edc17eb.0408112052.1bbd85b3@posting.google.com> Message-ID: <59e9fd3a04081122235b3d9145@mail.gmail.com> On 11 Aug 2004 21:52:03 -0700, Michele Simionato wrote: > > Indeed. Actually I did not vote since I like the current proposal (maybe > I would like "|" more than "@") and I dislike all the alternatives, > especially having decorators inside the def. Since you like the current proposal, why *didn't* you vote for it (it was the first one)? From jens.news at webgear.co.za Sat Aug 14 11:47:09 2004 From: jens.news at webgear.co.za (Jens Thiede) Date: Sat, 14 Aug 2004 17:47:09 +0200 Subject: Regular Expressions Message-ID: What is the easiest way to generate a list that contains all the remnants of re.findall (the inverse of the following). >>> file = open("index.html", "r") >>> data = file.read() >>> patern = re.compile("(.*)", re.S | re.I) >>> patern.findall(data) ['Damn Small Expansions!'] >>> file.close() re.split doesn't seem to work quite well, but then, I'm probably using it wrong. Any suggestions? Jens. From brian at rk-speed-rugby.dk Mon Aug 30 07:32:03 2004 From: brian at rk-speed-rugby.dk (Brian Elmegaard) Date: 30 Aug 2004 13:32:03 +0200 Subject: From python to LaTeX in emacs on windows Message-ID: Hi group I hope this is not a faq... I try to understand how to use the new way of specifying a files encoding, but no matter what I do I get strange characters in the output. I have a text file which I have generated in python by parsing some html. In the file there is international characters like ? and ?. I can see the file in emacs it is encoded as mule-utf-8-dos I read the file into python as a string and suddenly the characters when printed looks strange and consists of two characters. First problem: How do I avoid this? Second problem is that I make some string replacements and more in the string to write a latex output file. When I open this file in emacs the characters now are not the same? Second problem: How do I avoid this? tia, -- Brian (remove the sport for mail) http://www.et.dtu.dk/staff/be From birded at verizon.net Sun Aug 22 12:53:47 2004 From: birded at verizon.net (Sherrod Faulks) Date: Sun, 22 Aug 2004 16:53:47 GMT Subject: Jython/Python and javax.swing.* Message-ID: <2004082212534416807%birded@verizonnet> I'm using Jython and in the python script I do: from javax import swing result = javax.swing.JOptionPane.showInputDialog(wC, cmd[8:],"Prompt from " + client.serverName, JOptionPane.PLAIN_MESSAGE) wC is a JFrame, cmd is a String and client.serverName is a String. It won't show the JOptionPane, why? From cybermanxu at hotmail.com Wed Aug 4 12:32:16 2004 From: cybermanxu at hotmail.com (Jinming Xu) Date: Wed, 04 Aug 2004 11:32:16 -0500 Subject: I got it! How to force a single number to be a tuple Message-ID: Sorry for the previous message. It's really a simple question and I have solved it myself. Thanks, Jinming ------------------------------------------------------------------------ Hi Folks, I have a number sequence, which is put into a tuple like this: y=2, 3.0, 4.5 I can manipulate the sequence as a tuple when it has more than 1 number. But when the sequence has only 1 number, like y=2 I have trouble to manipulate it as a tuple. I guess there must be a way to forece a single number to be a tuple. Could anyone please tell me that? Thanks, Jinming _________________________________________________________________ Discover the best of the best at MSN Luxury Living. http://lexus.msn.com/ From ramen at lackingtalent.com Fri Aug 27 12:22:51 2004 From: ramen at lackingtalent.com (Dave Benjamin) Date: Fri, 27 Aug 2004 16:22:51 -0000 Subject: Proposal for removing self References: <1gj65zl.1cuz9ub5xyo3rN%aleaxit@yahoo.com> Message-ID: In article <1gj65zl.1cuz9ub5xyo3rN%aleaxit at yahoo.com>, Alex Martelli wrote: > Delaney, Timothy C (Timothy) wrote: > >> Andrea Griffini wrote: >> >> > I remember Alex Martelli advocating in our italian newsgroup on >> > C++ that C++ programmers should use "this->..." everywhere :-) >> >> I evangelise this here (mainly for Java code these days, but close >> enough). Unfortunately, I don't seem to be able to convince anyone else > > While it's also a good idea in Java, it's not as compelling as in C++, > because Java mostly lacks the complications due to C++'s templates and > freestanding ("not inside a class") names (haven't looked at Java > generics so I don't know if they got those complications back in;-). Java's generics aren't nearly as liberal as C++ templates. They're basically just syntax sugar for casting, so I doubt this would change much. I still prefer the explicit "this." or "self.", mainly because it is a pattern that I can use consistently across all of the languages I regularly program in (JavaScript and ActionScript, like Python, make "this" mandatory as well). I like it better, stylistically, because I feel like I can determine more readily where things are coming from, but each language has its own scoping rules (Java has no modules, for instance. I wonder how it works for inner classes...) so I can't really make an argument across the board that "this." / "self." is always better. That said, if an existing C++ or Java code base uses prefixes for all instance variables, it's a bit redundant to add "this.". I have this situation at my work, where I reluctantly have to make an exception to avoid pissing people off. ;) -- .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:. "talking about music is like dancing about architecture." From mlh at furu.idi.ntnu.no Mon Aug 23 16:47:28 2004 From: mlh at furu.idi.ntnu.no (Magnus Lie Hetland) Date: Mon, 23 Aug 2004 20:47:28 +0000 (UTC) Subject: Standard graph API? References: Message-ID: In article , wes weston wrote: [snip] > >Magnus, > Do you have any design thoughts. It would be good to have weighted, >directed graphs and depth first traversal. I've thought of several alternatives; basically, I just thought about defining the "standard" API for the basic abstract data type (including weights, direction, labels, colours etc.). Concrete implementations and algorithms would be a separate issue. >wes -- Magnus Lie Hetland "Canned Bread: The greatest thing since sliced http://hetland.org bread!" [from a can in Spongebob Squarepants] From jerf at jerf.org Mon Aug 23 20:16:46 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Tue, 24 Aug 2004 00:16:46 GMT Subject: Getting at the bits of a 32-bit integer References: <85b54e91.0408231552.75f85727@posting.google.com> Message-ID: On Mon, 23 Aug 2004 16:52:07 -0700, Jacob H wrote: > 00000000 00000000 00000000 11111111 > > There are plenty of unused bits to the left of the number itself. If I > wanted to use some of these bits as true/false flags, how would I go about > it? In Python, how do I write code that gets at the leftmost byte, or the > third bit from the left of the set of 32, or the rightmost byte plus the > bit to its left, etc... Well, the basic answer is the same as C, with &, >>, and appropriate constants for what you are doing. >>> #access the 10th bit >>> a = 1025 >>> (a & 1024) >> 10 1 >>> a = 1023 >>> (a & 1024) >> 10 0 Obviously, you need better constants and stuff. However, I must challenge your need to do this in the first place. Python and bit twiddling generally don't go together; even if you are accessing a binary file or protocol you should shuffle out as much to the struct (?) module as possible. If you want to track every bit and byte, Python is the wrong language for you... and unless you are tracking many many millions of bits, this is the wrong decade for it. Use a class, and set members on it to true or false for your flags. >>> class DummyStruct: pass >>> flags = DummyStruct() >>> flags.aFlag = True (The nice thing about such classes is you will often find them smoothly transition into really *useful* classes, emphasis on the plural "classes" :-).) The bit twiddling will most likely be *much* slower than this, and unless you're dealing with millions of these, the memory savings will be zilch. If you *are* dealing with millions of these, be sure to look at the "array" module. From aahz at pythoncraft.com Thu Aug 5 23:11:05 2004 From: aahz at pythoncraft.com (Aahz) Date: Thu, 5 Aug 2004 23:11:05 -0400 Subject: BayPIGgies: August 12, 7:30pm Message-ID: <20040806031104.GA27907@panix.com> The next meeting of BayPIGgies will be Thurs August 12 at 7:30pm. It will feature general discussion of programming and debugging GUI applications (Qt, Tkinter, wxPython, etc). BayPIGgies meetings are in Stanford, California. For more information and directions, see http://www.baypiggies.net/ Before the meeting, some people meet at 6pm for dinner in downtown Palo Alto. Ducky Sherwood is handling that; please send RSVPs to ducky at osafoundation.org Discussion of dinner plans is handled on the BayPIGgies mailing list. Advance notice: The September 9 meeting agenda has not been set. Please send e-mail to baypiggies at baypiggies.net if you want to make a presentation. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From raims at dot.com Thu Aug 12 04:07:15 2004 From: raims at dot.com (Lawrence Oluyede) Date: Thu, 12 Aug 2004 10:07:15 +0200 Subject: SQL Qeries via XMLRPC References: <3ovlu1-l6f.ln1@home.rogerbinns.com> Message-ID: <1orq79s4gr62m.1fbwir1nwacqx$.dlg@40tude.net> I did something (as an excercise) like you were asking for with a friend, it's based on twisted and send queries against a sqlite db (for testing, but you can plug into it easily another db). The source code is LGPL and the package ships with a couple of (quite-working and untested) web interfaces (cgi and webware). It ships also with a test. Its primary interfaces are XML-RPC and SOAP ones So, have a look and tell me if some code suits your needs. To execute it type: twistd -noy pydbserver.py (as root) bye! http://www26.brinkster.com/rhymes/pydbserver.tar.gz -- Lawrence (l dot oluyede at virgilio dot it) "If the implementation is hard to explain, it's a bad idea." from The Zen of Python by Tim Peters From dyoo at hkn.eecs.berkeley.edu Fri Aug 20 16:39:54 2004 From: dyoo at hkn.eecs.berkeley.edu (Daniel Yoo) Date: Fri, 20 Aug 2004 20:39:54 +0000 (UTC) Subject: IDLE References: Message-ID: Peter Kleiweg wrote: : george schreef: :> Newbie question. :> :> Installed Python 2.4 successfully. :> However, double clicking on the IDLE icon activates the hour glass :> cursor and then dies. The IDLE window does not come up. :> I am sure it is something trivial that I am not doing : Happended to me too. Idle is trying to get access to tcp/ip : services and can't find them on Windows. You may have port '8833' blocked: that's the port that IDLE uses to talk to itself. Windows XP comes with a firewall that's a bit hostile, and if the firewall is on, then it prevents IDLE from running. If it is a firewall issue, then it may be fixable. Microsoft has an article that explains how to open up port: http://www.microsoft.com/windowsxp/using/networking/expert/bowman_november12.mspx Good luck! From smulloni at bracknell.smullyan.org Tue Aug 3 23:00:53 2004 From: smulloni at bracknell.smullyan.org (Jacob Smullyan) Date: 3 Aug 2004 23:00:53 -0400 Subject: Mucking with the calling scripts namespace (For a good reason, honest!) References: Message-ID: On 2004-08-03, Doug Rosser wrote: > Thank you for your help Larry. Let me see if I've got this straight: > > 1. Python doesn't provide an obvious way to modify the __main__ > namespace. You can peek at values with "global" but you can't treat it > like a dictionary at runtime. > > 2. If you need to access objects that won't have names until run-time > (but you incidentally -KNOW- their names and want to reference them in > a bit of code), encapsulate them in a container. This effectively > creates a new not-really namespace, as the objects in the container > become attributes. > > Well, all-in-all, I'd really still rather have #1, but I can live with > #2. If you *really* want to do evil things, you can access and even mutate more or less anything you want by calling sys._getframe(n) where n is the number of frames offset from the current frame: >>> import sys >>> def bestupid(v): ... f=sys._getframe(1) ... f.f_globals['STUPID']=v ... >>> bestupid(100) >>> dir() ['STUPID', '__builtins__', '__doc__', '__name__', 'bestupid', 'sys'] >>> STUPID 100 >>> bestupid(0) >>> STUPID 0 I'll assume that you can recreate for yourself all the cautionary noises I'm tempted to make after demonstrating such a capability. js -- Jacob Smullyan From timblack1 at yahoo.com Sat Aug 21 01:31:44 2004 From: timblack1 at yahoo.com (Tim) Date: 20 Aug 2004 22:31:44 -0700 Subject: How to set wxTextCtrl style to wxHSCROLL? Message-ID: How can I set the style attribute in the following wxTextCtrl to a new style AFTER I have already instantiated the wxTextCtrl? I'm trying to toggle the word wrap attribute of the wxTextCtrl, just like Edit->Word Wrap does in Windows Notepad. (I'm building a Windows Notepad clone in wxPython to prove to a VB friend that it can be done.) Here is the wxTextCtrl instantiation: -------------- self.txtEditor = wxTextCtrl(id=wxID_WXFRAME1TXTEDITOR, name='txtEditor', parent=self, pos=wxPoint(0, 0), size=wxSize(760, 492), style=wxTE_MULTILINE, value='') -------------- Here is the code I've tried to set the style to a new value: -------------- def OnMnuEditWordwrapMenu(self, event): # TODO: implement word wrap self.txtEditor.SetStyle(0, self.txtEditor.GetLastPosition(), wxHSCROLL) #self.txtEditor.style = 'wxHSCROLL' -------------- What is the correct syntax? Thanks! Tim From aleaxit at yahoo.com Sat Aug 28 03:43:55 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 28 Aug 2004 09:43:55 +0200 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <7xzn4gwgea.fsf@ruckus.brouhaha.com> <1gj7a1o.1a5d2q410jsn2kN%aleaxit@yahoo.com> <7xisb4xnh5.fsf@ruckus.brouhaha.com> <1gj7c1a.tfdm14p3hclcN%aleaxit@yahoo.com> <7xd61benm9.fsf@ruckus.brouhaha.com> Message-ID: <1gj82n3.1ylkr3nierngmN%aleaxit@yahoo.com> Paul Rubin wrote: > aleaxit at yahoo.com (Alex Martelli) writes: > > While the overall way the new import hooks work is well documented in > > their PEP, zipimport is admittedly underdocumented. I suggest peeking > > OK. I'll look at the PEP. I think adding signing is hairy enough > that it should have its own round of discussion; should I see about > editing the PEP to add something about signing? I think that would be an excellent idea. If it was just about allowing import from signed zipfiles it might not be needed, but how best to let the user optionally DIS-allow imports from UN-signed files does appear to be something requiring a little debate. An environment variable would have the advantage of letting the disallowing work even for the early imports that Python does before application code gets control, but some people dislike relying on environment variables particularly for security-related configuration tasks. Would it make sense to rely on a naming convention instead? I.e. foo.zip would be unsigned but bar.jar would have to be signed or else no go. This would have the advantage of allowing substantial granularity in controlling this. Side question, does module zipfile already have the code to allow reading such signed files? Otherwise a first, uncontentious step, in parallel with the PEP, might be a patch to add that ability to zipfile. Alex From in.aqua.scribis at nl.invalid Sun Aug 29 09:22:57 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Sun, 29 Aug 2004 15:22:57 +0200 Subject: Get all subdirs In-Reply-To: References: Message-ID: Florian Lindner schreef: > Hello, > how can I get all subdirectories of a given directory. os.listdir(dir) > doesn't differentiate between directories and files, os.walk seems to me a > bit overkill since it also descends in the subdirs. #!/usr/bin/env python import os dir = '.' # '.' is current directory for i in os.listdir(dir): if os.path.isdir(os.path.join(dir, i)): print i Bby the way, on Linux, I noticed that the directories '.' and '..' are not returned by os.listdir -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From rnichol_rrc at yahoo.com Sun Aug 15 18:49:04 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Sun, 15 Aug 2004 17:49:04 -0500 Subject: Python secure? In-Reply-To: References: Message-ID: Roger Binns wrote: > Calvin wrote: > >>Sorry I should have said I'm new to programming let alone Python. I >>wish to know whether Python is secure as an exe for a commercial >>product. > > > Yes. Anyone who recovers your "code" and/or uses it will be in > violation of copyright and several other laws. That is legal > protection no matter what languages or combination of languages > you use. > > Roger > > I assume you are talking about reverse engineering. If so, that just depends on that particular countries laws. Some allow and some don't. From squirrel at WPI.EDU Tue Aug 17 10:09:50 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 17 Aug 2004 10:09:50 -0400 Subject: How big can a Python program be? In-Reply-To: References: Message-ID: On Tue, 17 Aug 2004, Ben Last wrote: > (3665, '/cygdrive/c/Python23/Lib/lib-tk/Tkinter.py') For the record, that's 2201 lines of code, and 1464 lines of documentation. Quite a good example of the relative importance of documentation. (Something I could learn from ;)) From meldron at meldron.org Wed Aug 25 04:39:44 2004 From: meldron at meldron.org (Bernd Kaiser) Date: Wed, 25 Aug 2004 10:39:44 +0200 Subject: kill/cancel a started thread Message-ID: <2p31fvFfb10tU1@uni-berlin.de> How can i kill/cancel a started threading.Thread? Regards, Bernd Kaiser From squirrel at WPI.EDU Fri Aug 6 09:18:42 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Fri, 6 Aug 2004 09:18:42 -0400 Subject: Proposed improved decorator syntax In-Reply-To: References: Message-ID: On 6 Aug 2004, Rob Williscroft wrote: > wrote in news:mailman.1235.1091753699.5135.python-list at python.org in > comp.lang.python: > > > class foo: > > def introduceNewFeature(self, someArgument, anotherArgument): > > .decorate = [synchronized] > > .accepts = (int, int) > > .author = 'Chris King' > > pass # whatever > > > > > > AIUI it is intended that prefix '.' will be used at some point > with a 'with'/'using' keyword: > > class Foo: > def f( self ): > with self: > .member = value Which makes it all the more intuitive (def is acting similar to a with block). From jerf at jerf.org Mon Aug 30 14:24:55 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Mon, 30 Aug 2004 18:24:55 GMT Subject: Generator expressions v/s list comprehensions References: <1gj8y77.6qshr41q531veN%aleaxit@yahoo.com> <87llfywooz.fsf@sinken.local.csis.hku.hk> <1gjbs1e.assxlxlud1m0N%aleaxit@yahoo.com> <7xbrgtrq4r.fsf@ruckus.brouhaha.com> Message-ID: On Mon, 30 Aug 2004 01:23:16 -0700, Paul Rubin wrote: > These things exist in other languages and had been > requested in Python for years before they got accepted. And every > time some little thing gets added changing the language, that creates > a new mini-dialect that users have to remember for a while and then > forget. The result is "version fatigue"; one gets bleary trying to > remember what's in the language this week. Those features are in > other languages for a reason, and there's been enough experience using > them (in those languages) that their desirability for Python should > never have seriously been in question. Along with the other two poster's points, you have a whiff of an implied argument that somehow, these amorphous "other languages" somehow *didn't* go through "version fatigue", and are therefore somehow better. This is false if you take it out of the realm of amorphous, implied claim and look at it in the light of day. Show me a language that has never suffered from these problems and anyone actually uses. If you can show me one, show me a few more. C changed. C++ changed. Fortran changed. COBOL changed. LISP has changed. Python changed, Perl changed, Haskell changed, Javascript changed, everything changed. None of those languages decided that the correct solution is to simply throw everything in (even Ada, C++, and Perl, all of which have that reputation, really didn't in the sense you're getting at here). The claim that other languages have features, *therefore* we shouldn't stop to think about whether they are good and they should all be added to Python without debate boggles the mind when viewed head on. Pure non-sequitor. (BTW, note levels of debate are proportional to how many people bother to debate, and nothing else. It is one reason a language can not effectively grow to the community size of Python without strong leadership and why I am glad that Python runs under a BDFL system. Most of the debate you may see here in c.l.p. is really effectively irrelevant, and should be mentally categorized as such; that debate does not constitute true design involvement. Thus, pointing out "high levels of debate" in the newsgroup doesn't convince me of much, since it really means little. To the extent that it does sometimes matter, the amortized effect of any given message is simply miniscule; the entire debate of a thousand messages may have no effect whatsoever on Guido, or manifest itself as a single document of moderate length that he may *still* reject.) From ialbert at mailblocks.com Wed Aug 25 17:05:37 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Wed, 25 Aug 2004 17:05:37 -0400 Subject: ASPN Python cookbook in a chm In-Reply-To: References: Message-ID: dody wrote: > ASPN Python cookbook in a .chm file > =================================== > > last updated: 25 August 2004 > > http://miaw.tcom.ou.edu/~dody/aspnpython.chm good stuff From jonaskoelker at yahoo.com Tue Aug 3 12:59:10 2004 From: jonaskoelker at yahoo.com (=?iso-8859-1?q?Jonas=20Koelker?=) Date: Tue, 3 Aug 2004 17:59:10 +0100 (BST) Subject: how to do proper subclassing? Message-ID: <20040803165910.40250.qmail@web41509.mail.yahoo.com> Hello there. I'm new to this list (/me welcomes himself). anyways, I'm having doubts about how to subclass properly. The big picture is that I want to handle permutations. As we all know, two popular notation forms exist: products of disjoint cycles ("(0 1 3)(2 4)") and 2*length matrices with the identity permutation as the first line ([0 1 2 3 4] over [1 3 4 0 2]). I find the latter more appropriate, since it's easy to store as a list (one can skip the first line, assuming it's _always_ the identity). However, I want the permutation to act like a list, in all those cases where I don't override the operations. For example, assuming permfooation is the above permutation [1 3 4 0 2], permfooation[1:3] should return [3,4]. How is this done? Do I have to actually implement a slice-mechanism in the permutation class? thanks, -- Jonas K?lker ___________________________________________________________ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com From jack at performancedrivers.com Thu Aug 19 17:45:45 2004 From: jack at performancedrivers.com (Jack Diederich) Date: Thu, 19 Aug 2004 17:45:45 -0400 Subject: problem using C-bindings In-Reply-To: References: Message-ID: <20040819214545.GD23725@performancedrivers.com> On Thu, Aug 19, 2004 at 10:32:15PM +0200, eq wrote: > Hi, > > I'm trying to create a program(written in C) that does the following > things using embedded Python: > 1. Create a module(say, "MyModule") > 2. Create a class in that module(say, "MyClass") > 3. Create a function in that module(say, "MyFunction") [snip] > class_dict=PyDict_New(); > class_name=PyString_FromString("MyClass"); > class=PyClass_New(NULL,class_dict,class_name); > PyDict_SetItemString(module_dict,"MyClass",class); [snip] Take a look at Modules/xxsubtype.c in the source distribution. It is an example of how to subtype a builtin. xxmodule.c shows how to make a class from scratch. Both are out of date but a good sarting spot. You could also give Pyrex a try, it makes it easier to write just a hot function or two of a class in C. I like it to prototype C versions of hotspot functions (but then do the final version 'by hand'). -Jack From joshway at myway.com Wed Aug 18 15:12:46 2004 From: joshway at myway.com (JCM) Date: Wed, 18 Aug 2004 19:12:46 +0000 (UTC) Subject: Embedding Python in Python References: <7xu0v0l2be.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: ... > There was a feature called rexec/Bastion for that purposes in older > version of Python, but it was removed because it was insecure. >> Any ideas/examples? > Run your sensitive stuff in a separate process (or separate computer) > and allow the hostile clients to communicate through sockets. If you're concerned about security, another possibility is to parse the user's code and look for anything potentially dangerous. You'll need to be aggressive, but I believe it's possible. For example, disallow exec statements, the identifier "eval", any identifier of __this__ form, import statements, etc. This is overly restrictive, but it will provide security. From lbates at swamisoft.com Mon Aug 2 12:37:48 2004 From: lbates at swamisoft.com (Larry Bates) Date: Mon, 2 Aug 2004 11:37:48 -0500 Subject: Mucking with the calling scripts namespace (For a good reason, honest!) References: Message-ID: I would suggest following: 1) Change the config file into proper format for ConfigParser module. [server_001] hostname=alpha os=posix [server_002] hostname=beta os=win [client_001] hostname=ichi os=posix [client_002] hostname=ni os=posix This makes it easy to define up to 999 servers and 999 clients (just make the counter longer if you require more). 2) Create classes to hold information/methods that will work on each server/client. class server: def __init__(self, server_id, name, os): self.id=server_id self.name=name self.os=os return def dosomething(self): # # Insert code here to do something on this # server. # return 3) Create class to hold servers/clients (I'll leave the one to handle clients to you). class servers: def __init__(self, INI): # # Create an index pointer for next method # self.next_index=0 # # Create a list to hold server names # self.names=[] serverlist=[x for x in INI.sections if INI.sections.beginswith('server')] serverlist.sort() # If you want to keep them in order # # Loop over each server entry # for server_id in serverlist: name=INI.get(server_id, 'name') os=INI.get(server_id, 'os') self.append(id, name, os) return def append(self, server_id, name, os): # # Create server instance and append to list of servers # self.names.append(server_id) self.__dict__[name]=server(server_id, name, os) return def __iter__(self): return self def next(self): # # Try to get the next route # try: SERVER=self.names[self.next_index] except: self.next_index=0 raise StopIteration # # Increment the index pointer for the next call # self.next_index+=1 return SERVER In your programt do something like: import ConfigParser INI=ConfigParser.ConfigParser() INI.read(inifilepath) SERVERS=servers(INI) Now you can access SERVERS.server_001.name SERVERS.server_001.os or call methods via SERVERS.server_001.dosomething() or you can easily loop over them for SERVER in SERVERS: SERVER.dosomething() or print SERVERS.names Code not tested, but I hope it helps. Larry Bates Syscon, Inc. "Doug Rosser" wrote in message news:e08cd05f.0408020727.15ce4356 at posting.google.com... > I'm writing a fairly complicated test framework and keeping > configuration data inside ini files that are parsed at runtime by the > ConfigParser module. > > For example, there would be a section similar to the following > > [servers] > server1:{'hostname':'alpha','os':'posix'} > server2:{'hostname':'beta','os':'win'} > > [clients] > client1:{'hostname':'ichi','os':'posix'} > client2:{'hostname':'ni','os':'posix'} > > As I read the configuration file, I don't actually create instances, > but use the data to check "what's out there" to make sure the physical > network environment has the bits and pieces required to run a > particular test. This is a sort of "go/no-go" resource check. > > Assuming that everything is correct with the physical network > environment, I want my testers to be able to refer to these resources > in their python scripts by the names in the ini file, like so: > > myTest.checkResources() # Read the config file and associate names > with real > # life instances > > server1.doSomething() # Note how I have cleverly saved myself from > declaring > # "server1" because the module myTest has > inserted > # it into the right namespace :-) > > Down to business: How do I write a module that can insert these names > into the calling script's namespace at runtime? Is this even possible > in Python? > > da rosser > -- We are the music makers, and we are the dreamers of dreams -- From mwh at python.net Mon Aug 9 09:39:17 2004 From: mwh at python.net (Michael Hudson) Date: Mon, 9 Aug 2004 13:39:17 GMT Subject: Find out the file name of a module from inside the module? References: Message-ID: Andreas Neudecker writes: > Hi. > > I know you can read the filename of a program as sys.argv[0]. But what > about modules? Is there a similar way to find out the file name of a > module (called by some other module or program) from inside this > module? Uh, your question makes my head spin a bit, but is __file__ what you want? >>> import os >>> os.__file__ '/usr/lib/python2.2/os.pyc' Cheers, mwh -- Of the four project development variables - scope, cost, time and quality - quality isn't really a free variable. The only possible values are "excellent" and "insanely excellent", depending on whether lives are at stake. -- Kent Beck, XP Explained From lbates at swamisoft.com Tue Aug 3 09:53:21 2004 From: lbates at swamisoft.com (Larry Bates) Date: Tue, 3 Aug 2004 08:53:21 -0500 Subject: Reasoning behind nested scope References: Message-ID: <4ZGdnTajMfhTBZLcRVn-qA@comcast.com> Ever since my first Fortran class some 30+ years ago I've always liked nested scopes. If you want something to be global, say so in your code. In Fortran we used common blocks, in Python you use a global directive. Making everything global can lead to many name clashes or you must have lots of unique variable names which lengthens code and makes reuse more difficult. Judicious use of OOP and globals seems to be the best approach. The more I learn/use OOP the less I seem to require globals, but there are some times they seem a preferable solution. I don't believe there is any way to call nested functions from outside their parent. If you need something like that, make the function a class and make the nested function a method of the class. HTH, Larry Bates Syscon, Inc. "Andy Baker" wrote in message news:mailman.1087.1091532385.5135.python-list at python.org... > Hi there, > > I'm learning Python at the moment and trying to grok the thinking behind > it's scoping and nesting rules. > > I was googling for nested functions and found this Guido quote: > (http://www.python.org/search/hypermail/python-1993/0343.html) > > "This is because nested function definitions don't have access to the > local variables of the surrounding block -- only to the globals of the > containing module. This is done so that lookup of globals doesn't > have to walk a chain of dictionaries -- as in C, there are just two > nested scopes: locals and globals (and beyond this, built-ins). > Therefore, nested functions have only a limited use. This was a > deliberate decision, based upon experience with languages allowing > arbitraries nesting such as Pascal and both Algols -- code with too > many nested scopes is about as readable as code with too many GOTOs. > And, of course, in Python, the "proper" way is to use an > object-oriented programming style" > > This sounds reasonable to me although nested scope always struck me as more > natural and intuitive ('Don't be surprising') > > I was wondering how the balance changed in favour of nested scope? What > changed people's minds about 'readability' vs other factors? Are nested > scopes still regarded as leading to spagetti code etc? > > (On a side note is there any way to call a nested function from outside the > parent? I was kind of expecting nested functions to be addressable through > dot notation like methods are but I can see why that wouldn't be quite > right. This might be a better question for the tutor list...) > > Andy Baker > From indigo at bitglue.com Mon Aug 30 20:08:55 2004 From: indigo at bitglue.com (Phil Frost) Date: Mon, 30 Aug 2004 20:08:55 -0400 Subject: python internal hacking: multitasking, interrupts, and the like Message-ID: <20040831000855.GB2132@unununium.org> A brief introduction for python-list: Unununium is an OS being developed in Python wherever possible. This message is phrased for the Unununium list, but as the questions are about hacking cPython, I have CCed python-list as well. As not everyone has heard yet, the current scheduler is insufficient for our needs. The biggest restriction is that it allocates threads in pools of 32, which becomes a problem when we need 8M * 32 stacks to accommodate Python. Furthermore, statically allocating huge stacks is a problem anyway, and we need to move to a multiple address space model. To that end I've decided to get a new scheduler, and I want to do it in Python. There are some things to consider: Traditional multitasking is rather inefficient. Switching stacks and blowing away the TLB cache on each process switch is a waste of time. Two alternatives come to mind, Twisted's select() based reactor which is a purely event based model, and stackless, which provides 'tasklets'. The problem with Twisted is that it requires code to be rewritten in terms of callbacks that happen in response to events. This works well for applications designed that way, but we need a solution that works for all applications, even those not in Python. Furthermore, scheduling is coarse and purely cooperative, which is efficient for a single application but does not scale to an entire system. However, it is valuable to consider Twisted as a method for application-level multitasking. The problem with Stackless is that I can't find any information on it. I've made inquiries to their mailing list about how tasklets are scheduled and received no response. Perhaps someone knowledgeable has subscribed since I last asked this question. If so, please share your knowledge. I'd like to use an existing solution, but that doesn't look like it will happen. In that case I need to better understand Python's internals to write a scheduler with it. I think if I were able to attach a python routine to an interrupt handler, I could do with a minimal amount of supporting C and assembly. However, I'm not sure how I can do this. The problem is the infamous GIL; I don't know how I can acquire the lock without multiple threads. Perhaps I don't need to acquire it if I'm careful about what data I access, but I don't know enough about Python to answer that. Further complicating the issue is that our build of Python does not include thread support, because...well, there is none! Please share your ideas. From sjdevnull at yahoo.com Mon Aug 9 23:01:05 2004 From: sjdevnull at yahoo.com (G. S. Hayes) Date: 9 Aug 2004 20:01:05 -0700 Subject: decorators vs GIL References: <96c2e938.0408081605.706f8ec7@posting.google.com> Message-ID: <96c2e938.0408091819.2cd7b50d@posting.google.com> Jarek Zgoda wrote in message news:... > > Try GUI programming without using threads. For the GUI tasks that I've done (mostly data visualization stuff for doing sophisticated views and edits on SQL databases and music visualization software for doing realtime FFT/spectrum analyzer/oscilloscope kinds of things that move with the music) it's been absolutely no problem to use real processes for GUI work. Why exactly do you not want protected memory for these things? Lots of big, sophisticated GUIs are implemented without threads (e.g. Netscape Navigator/Communicator). It almost always winds up being easier on the programmer and more responsive for the user in the long run. Threads often seem simple at the outset, but most of the time they wind up being far more complex to program and debug than judicious use of state machines and processes. The major exception is libraries (especially matrix-math kinds of things) where the internals are so deeply entwined that it's not easy to figure out well-segmented subset to put in shared memory. Often (but not always) the amount of work it takes to figure out all the locking issues is a lot higher than what it would've taken to seperate the data structures out cleanly. And sometimes you have legitimate real-world needs that require threads (most often libraries designed around that model or the two MAJOR platforms, Java and Windows, without good multiprocess support, but sometimes problem domains where you really NEED all kinds of crazy shared memory data structures and segmenting them out doesn't buy you much). From tim.peters at gmail.com Thu Aug 19 21:59:25 2004 From: tim.peters at gmail.com (Tim Peters) Date: Thu, 19 Aug 2004 21:59:25 -0400 Subject: My only complaint about Python In-Reply-To: References: Message-ID: <1f7befae04081918596bb5a873@mail.gmail.com> [Darren Dale[ > ... > Will the BDFL ever split with Visual Studio? We should be clear here that this isn't Guido's decision. What you get on Windows is what you get on all other platforms in this respect: you get what volunteers show up to produce, year after year after year. So you get a fine Cygwin port from Jason Tishler, seemingly toiling all alone, and you get contributions from at least four developers who do use Visual Studio. I don't think that's an accident. Most open source jockeys who use Windows do so because it's needed for their day job, and sticking with an MS compiler is widely perceived in pointy-hair boss-land as the safest course on Windows. And it is a first-class IDE, so there's no pragmatic reason to wrestle with yet another system when the day job ends. It takes real sweat to get comfortable with any C development tool chain, and it takes years to become familiar wth each one's maddening quirks. I expect that's why Guido still uses Visual Studio when he's running on Windows (and know it's why I do), but he actually hasn't had anything to do with the Windows Python releases for years. Things Will Change when long-term volunteers show up and change them. From joshg at brainstorminternet.net Tue Aug 24 18:19:34 2004 From: joshg at brainstorminternet.net (Joshua Ginsberg) Date: Tue, 24 Aug 2004 16:19:34 -0600 Subject: Inline Conditionals? Message-ID: <1093385974.29259.146.camel@localhost.localdomain> Is there any plan to include inline conditionals in Python? For example: def isNegative(x): return x < 0 ? True : False Thanks! -jag -- Joshua Ginsberg Brainstorm Internet Network Operations From http Mon Aug 30 13:55:18 2004 From: http (Paul Rubin) Date: 30 Aug 2004 10:55:18 -0700 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <7xzn4gwgea.fsf@ruckus.brouhaha.com> <1gj7a1o.1a5d2q410jsn2kN%aleaxit@yahoo.com> <7xisb4xnh5.fsf@ruckus.brouhaha.com> <1gj7c1a.tfdm14p3hclcN%aleaxit@yahoo.com> <7xd61benm9.fsf@ruckus.brouhaha.com> <1gj82n3.1ylkr3nierngmN%aleaxit@yahoo.com> <7xd61b8uh2.fsf@ruckus.brouhaha.com> <7x1xhqg3kb.fsf@ruckus.brouhaha.com> <4132cc9d$0$26202$9b622d9e@news.freenet.de> Message-ID: <7x7jrgse7t.fsf@ruckus.brouhaha.com> "Martin v. L?wis" writes: > I believe that import is the wrong point in time for checking > signatures. You want to check the signature when the file is > added to sys.path, i.e. > > imp.verify_signature(filename) > sys.path.append(filename) There's something to be said for that. Maybe you could append a tuple to say how to verify signatures: sys.add_library((filename, 'certfile.pem')) checks the sig and updates sys.path. The whole notion of sys.path.append (i.e. sys.path is just a naked Python list) is kludgy anyway. From curzio.basso at unibas.ch Wed Aug 11 04:17:09 2004 From: curzio.basso at unibas.ch (Curzio Basso) Date: Wed, 11 Aug 2004 10:17:09 +0200 Subject: how to dispatch objects depending on their class In-Reply-To: References: <4118dd4a$1@maser.urz.unibas.ch> Message-ID: <4119d60b@maser.urz.unibas.ch> Peter Otten wrote: > func_dict = {A: do_something_with_A, > B: do_something_with_B} > def func(obj): > func_dict[obj.__class__](obj) ok. it tested and it works. thanks. now I have only to check if the Visitor Pattern is not more appropriate. cheers, curzio From grv575 at hotmail.com Thu Aug 5 01:14:16 2004 From: grv575 at hotmail.com (grv) Date: Thu, 5 Aug 2004 05:14:16 +0000 (UTC) Subject: numarray speed question References: <953AD3D0Didtoken@128.91.2.239> Message-ID: <953C4DD4idtoken@128.91.2.239> squirrel at WPI.EDU (Christopher T King) wrote in : >On Wed, 4 Aug 2004, grv wrote: > >> So it is supposed to be very fast to have an array of say 5 million >> integers stored in a binary file and do >> >> a = numarray.fromfile('filename', (2, 2, 2)) >> numarray.add(a, 9, a) >> >> but how is that faster than reading the entire file into memory and >> then having a for loop in C: >> (loop over range) { >> *p++ += 9 } >> >> or is that essentially what's going on? > >That's essentially what's going on ;) The point of numarray isn't to be >hyper-fast, but to be as fast as the equivalent C (or Fortran, or >what-have-you) implementation. In many cases, it's faster, because >numarray is designed with several speed hacks in mind, but it's nothing >you can't do (without a little work) in C. > Yes but see I'm interested in what speed hacks can actually be done to improve the above code. I just don't see anything that can iterate and add over that memory region faster. From dd55 at cornell.edu Mon Aug 2 21:23:45 2004 From: dd55 at cornell.edu (Darren Dale) Date: Mon, 02 Aug 2004 21:23:45 -0400 Subject: file IO In-Reply-To: References: Message-ID: Darren Dale wrote: > Can anyone explain this? > > I have a file called old.dat with two lines: > > 1 > 2 > > So it's 3 bytes long. I run the following: > > import os > f = file('old.dat',mode='r') > olddata = f.readlines() > f.close() > > f = file('new.dat',mode='w') > f.writelines(olddata) > f.close() > > new.dat is now 4 bytes long. ??? > > I need to reformat and then save some data. Then I need to be able to > export the reformatted data to a spreadsheet-friendly format. But once I > have simply copied (trying to isolate the problem) the file using the > script above, my export function takes 10x as long as it would have with > the original file. And worse, the output has an extra newline character > added at the end of each line. Any suggestions would really be > appreciated, I am going a bit crazy trying to understand this. > > Darren One more bit of info. The extra newline character is added to output when I open the rewritten file like this: import os from mmap import mmap, ACCESS_READ f = file('foobar.dat',mode='rU') fd = f.fileno() m = mmap(fd, os.fstat(fd).st_size, None, ACCESS_READ) olddata = [] line = m.readline() while line: olddata.append(line) line = m.readline() using mmap to read the original datafile works. Any thoughts? I would really like to stick with mmap, my datafiles are the right size to really benefit. Darren From aleaxit at yahoo.com Sat Aug 28 10:02:59 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 28 Aug 2004 16:02:59 +0200 Subject: Question about references/copies References: <1gj870c.dzzhcpvby7ozN%aleaxit@yahoo.com> Message-ID: <1gj8k1n.1vm9nm4y4avw0N%aleaxit@yahoo.com> Arthur wrote: ... > I've felt strongly that this key piece of Python learning would be > and much, much more inevitable if there was a (preferred) consistent > way to ask for a copy, across objects - There is: type(obj)(obj) is (almost) always the best way to get a (shallow) copy of copyable objects (won't work with noncopyables such as files and other iterators, of course) of built-in types (whether user-coded types support that popular convention is of course another issue -- it depend on the author of each of these types). If you know what type obj is, say a list; or, if don't really care whether obj is (say) a list or a tuple or ... 'cause what you want is a list anyway, then the normal way to spell this is of course list(obj). > and/or that the copy module > was something other than one of XXX importable moudles. Well, it's Python-coded, so it seems quite natural to me that it be a perfectly normal importable module. > That dicts and lists (for example) have totally different syntax for > copy, helps - I promise - to misdirect and confuse. I happen to dict(mydict) and list(mylist) appear quite similar to me. Sure, mydict.copy() has stuck around from the dark ages and won't be even considered for removal, due to backwards compatibility, until Python 3.0 some years from now; and mylist[:] also builds a shallow copy; but despite their undeserved popularity these are not "the syntax for copy" in my book, any more than, say, dict(mydict.iteritems()) for a dict or [x for x in mylist] for a list, even though THOSE happen to make shallow copies too (and I HAVE seen them used in code intended as "serious"). > consider this entire area a significant wart. I think I am entitled to > consider it so. Given the apparent dearth of information in the matter, you may be right. I'll do my best to keep clarifying my viewpoint in my books... > I had tried to bring this up to in various forums, most particularly > edu-sig - where I thought this knid of discussion might be of > particular significance - and was rather rudely asked by Guido to take > it elsewhere. Where? not clear. Not sure why edu-sig would be more appropriate than any generic Python forum, actually. But not particularly inappropriate either, I think. Alex From telcom_sage at yahoo.com Tue Aug 3 21:42:24 2004 From: telcom_sage at yahoo.com (Brian Leair) Date: 3 Aug 2004 18:42:24 -0700 Subject: Rebinding variable, despite global statement References: Message-ID: > > I am using "from MyModule import *", (yes, yes, I know) > > > > In the code that performs the import, I have a function that has the > > statement > > "global g_my_var". Despite this, when I try to assign to g_my_var it > > appears I am rebound to a different object. > > you have two independent bindings to the same object. You can think of it as > the two-step process > > import MyModule > g_my_var = MyModule.g_my_var > # del MyModule > > That you are using the same name in both __main__ and MyModule has no effect > on the general structure. With Ah, thanks. This makes more sense now. My module has a list of symbols that are availabel to it, the module's dict. The keyword "global" is just a hint to assign to the symbol stored in the module's dict instead of the function. I also didn't quite realize that the "from X import " is really just adding entries in my module's dict. In effect making copies. The g_my_var gets an inital value from the import, but I really have MyPorgram.g_my_var and MyModule.g_my_var and these names are independent. A coworker commented that if g_my_var was bound to a modifiable object (list, class, etc.) then the changes made to that object would be seen in both places. Thanks again. From karlehr at gmail.com Thu Aug 5 15:45:45 2004 From: karlehr at gmail.com (Karl Ehr) Date: 5 Aug 2004 12:45:45 -0700 Subject: intermittent smtp module problems (with sendmail) in python 2.2.1 References: Message-ID: Christopher T King wrote in message news:... > On 4 Aug 2004, Karl Ehr wrote: > > > I have written the following simple program to monitor a single URL, > > and notify me via email whenever this URL changes. Intermittently, > > I raise the following exception: > > > > smtplib.SMTPServerDisconnected: Connection unexpectedly closed > > This is probably happening because of a timeout on the SMTP server. Try > moving this line: > > > server = smtplib.SMTP('localhost') # server to relay smtp through for > > To right in front of where you use it: > > > server.set_debuglevel(1) > > server.sendmail(sourceAddress, emailAddress, message) > > server.quit() > > the SMTP() constructor doesn't just set up a connection (and open it on > .sendmail()); it opens the connection when it's called and leaves it open > until you call .quit() (or delete the object). Aha!! Thank you this works fine now... I'll keep that snag in mind when referencing other "external" apps in the future... From simonb at NOTTHISBIT.webone.com.au Thu Aug 12 08:43:35 2004 From: simonb at NOTTHISBIT.webone.com.au (Simon Burton) Date: Thu, 12 Aug 2004 13:43:35 +0100 Subject: graphical object browser? Message-ID: I'd like a little app to let me explore live python objects graphically, with a tree view, say. It would be most useful when debugging a live program that has just blown an exception, or surfing through pickle data that needs to be upgraded. There is something like this in the /examples/ide directory of pygtk, but alas, it hasn't been updated to pygtk-2.0. If nothing shows up, I'll write one myself and post here. bye, Simon. From martin at v.loewis.de Thu Aug 26 17:21:21 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 26 Aug 2004 23:21:21 +0200 Subject: MSI Installer Problem: can't install 2.4a2 on new install of Win2kSP2 In-Reply-To: References: <412d7dcd$0$26184$9b622d9e@news.freenet.de> Message-ID: <412e5452$0$24835$9b622d9e@news.freenet.de> Richard Hanson wrote: > (I have much to learn in writing concise posts, alas -- I appreciate > your patience.) That is indeed the problem. I stopped reading after the first paragraph. I'm still uncertain whether you are talking about the original problem (failure to install the Python msi file), or about the second problem (MSI file installs fine, but IDLE fails to work) in this message. > I'm at a loss, still. Surely, something I had previously installed in > my own prior installation silently installed something needed for the > Python 2.4a2 install *other than the MSI Installer 2.0* and is > currently missing from my reinstall...? Why do you think so? > I'm going to try to redownload the Python install file (mine is > filesize: 10,691,072 bytes) even though it "seems" fine -- as I'm > running out of ideas. If the installation completed with the dialog stating it completed successfully, it probably did complete successfully indeed. If you still see a problem, it is likely that this problem is unrelated to the installation. However, I lost track as to what this problem might be, and how you have tried to narrow it down. Regards, Martin From mwh at python.net Fri Aug 27 08:21:38 2004 From: mwh at python.net (Michael Hudson) Date: Fri, 27 Aug 2004 12:21:38 GMT Subject: Static properties References: <1gj5e8n.xujsah4chw0gN%aleaxit@yahoo.com> <1gj657x.8jtu0f1hovhhvN%aleaxit@yahoo.com> Message-ID: aleaxit at yahoo.com (Alex Martelli) writes: > I think (I hope I'm wrong) that to catch 'Path.foo = something' you > do have to use a custom metaclass You're right. Cheers, mwh -- /* 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 jerf at jerf.org Fri Aug 20 16:10:22 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Fri, 20 Aug 2004 20:10:22 GMT Subject: Regular expression guaranteed to fail References: Message-ID: On Fri, 20 Aug 2004 10:35:18 +0000, Des Small wrote: > The question is, what regular expression should correspond to the > empty set? I would return compiled RE objects instead of strings, and in the empty case, return a class you write that matches the interface of a compiled RE but returns what you like. Something like: def NeverMatch(object): def match(*args, **kwargs): return None def set2re(s): if s: return re.compile("|".join([e for e in s])) else: return NeverMatch() From ptmcg at austin.rr._bogus_.com Mon Aug 23 02:07:21 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 23 Aug 2004 06:07:21 GMT Subject: J2 decorator grammar References: <2orckjFdtljaU1@uni-berlin.de> Message-ID: "Peter Maas" wrote in message news:2orckjFdtljaU1 at uni-berlin.de... > Robert Brewer schrieb: > > Michael Sparks wrote: > > For that reason (and others), I plan not to promote any form of the word > > "decorate". We can start having that conversation now if you want. ;) > > What about > > with: > return ... > accept ... > classmethod > def func(): > > > "using" instead of "with" would be equally satisfactory for me. I don't > like "decorate" because it sounds like "attaching some bells and whistles" > or "making it look pretty" which isn't adequate for the meaning of this > syntax. > > -- > Peter Maas, Aachen, Germany, Tel +49-241-38200 e-mail crgre.znnf at hgvybt.qr "using" is tolerable for me, although it will be confusing for C++'ers who will equate it with "namespace", and C#'ers who will equate it with "import" (DLL). As stated before, "with" and "as" are non-starters, "with" is reserved for future use, "as" sounds too much like "rename". "declare" is too broad a concept, and should be reserved for a time if/when variable typing gets added to Python. We should NOT select a keyword with an embedded '_' character. I think pre_def had been proposed at one point. '_' is awkward to get to on some international keyboards, IIRC. (Of course, Python already uses scads of '_'s elsewhere, so those people are out of luck.) I'm also not keen on all caps keywords - some developers use all caps as an indicator of defined constants, plus they are almost as eye-jarring as '@'. I'm still partial to some of the prepositional options, or some truncated words: qual - I would hope that "qual" might get a second look. The items in the decorator suite can be thought of as qualifiers, or qualities of the following function. (Hmm, for our Spanish-speaking colleagues, "qual" translates as "which", which might imply a selection from among the decorators. Boo. Scratch "qual".) per - Nice neutral Latin preposition; short, easy to type; used in "ad astra per aspera" which is "to the stars through hope" per: staticmethod memoize synchronize def foo(): pass You can even read it, sort of: "per staticmethod def[ine] foo". by - perhaps even too short, wont stand out when used I'm liking "per" or "using". -- Paul From richie at entrian.com Fri Aug 27 08:24:03 2004 From: richie at entrian.com (Richie Hindle) Date: Fri, 27 Aug 2004 13:24:03 +0100 Subject: Call for signatories for J2 In-Reply-To: References: <412cf775$0$11496$ed2e19e4@ptn-nntp-reader04.plus.net> Message-ID: [Michael] > I'd encourage anyone who's interested in python's > advancement to do the same, to be honest. The codebase is one of the > cleanest I've encountered and fairly easy to get started with, and it's > been a pleasure to work on. Seconded. I've been there and done that (implemented the Set Next Statement command for Python debuggers), and was pleasantly surprised at how clean and comprehensible the code was - even in performance-sensitive areas like ceval.c. > We have a (small) allocation in our time for "bright ideas" regarding > things that'll help the BBC in ways outside normal projects, and help > further tools etc we use. A good policy. Nice to see that the Beeb's suits can think outside the box (no pun intended 8-) -- Richie Hindle richie at entrian.com From unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom Sat Aug 28 08:32:41 2004 From: unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom (Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.) Date: Sat, 28 Aug 2004 14:32:41 +0200 Subject: simple compiled languages? References: <7xzn4fu188.fsf_-_@ruckus.brouhaha.com> Message-ID: I know one ; but it do not make the coffee. Sorry... From xslom03 at vse.cz Tue Aug 17 04:21:27 2004 From: xslom03 at vse.cz (Martin Slouf) Date: Tue, 17 Aug 2004 10:21:27 +0200 Subject: 'ascii' codec can't encode character u'\xf3' In-Reply-To: <4121A8DA.30802@v.loewis.de> References: <4120F820.4000703@fusiondementes.com> <4121A8DA.30802@v.loewis.de> Message-ID: <20040817082127.GA5233@barbucha.martin.net> thank you for reply, great info! it helped me to better understand it; but of course, some additional questions have risen. maybe some of those question/comments may seem stupid (ie. clear), but im new to python and i want to assure myself i get it right; thx for patience. > There is an alternative, if the print is a debug print: > > - print a repr() of the unicode object instead of > the unicode object itself. This will work on all > terminals, and show hex escapes of non-ASCII characters. just to make sure: override the object's __repr__(self) method to st. like: class my_string(string): def __repr__(self) tmp = unicode(self.attribute1 + " " + self.attribute2) return tmp and use 'my_string' class without any worries instead of classical string? > > No. unicode(text) uses the system default encoding > (sys.getdefaultencoding()) which normally is ASCII. > > Printing a Unicode string to a terminal should work fine if the terminal > is properly configured. What that means depends on your operating > system. my system is debian GNU/Linux stable, im using it for a very, very long time, though i did not changed any terminal settings but the very basics. My locales are properly set, im using LC_* environment variables to set default locale to czech environment with ISO-8859-2 charset. Terminal is capable of displaying 8bit charsets, im not sure about unicode charsets -- never tried, never needed. All other locale-sensitive programms are satisfied. (ie. java interpretter -- this should be much like python :) guess in germany it is quite the same, maybe ISO-8859-1 is preferred example output from my system: >>> import locale >>> loc = locale.getdefaultlocale() >>> loc ['cs_CZ', 'ISO8859-2'] so i guess this is ok. but the problem maybe in my 'site.py' where setting encoding according to my locale is done in a code like this: if 0: # Enable to support locale aware default string encodings. import locale loc = locale.getdefaultlocale() if loc[1]: encoding = loc[1] so i guess it is never done :( did you yourself changed it? did you think this is the 'portable solution'? i guess not -- another system, another locale, maybe being in ascii is the best. > > > > > * why is that behaviour? -- if you search google you get > >thousands of errors like this -- with no proper solutions i must add > > There is a proper solution. Unfortunately, very similar yet different > problems cause the same error message, and each problem has a different > proper solution: > well, if a piece of information like you gave to me was contained in standard python documentation, probably there will be less misunderstanding about this issue. > - A Unicode error is raised when trying to combine a Unicode string > and a byte string, if the byte string contains non-ASCII characters, > e.g. > > u"Martin v. " + "L?wis" > > The proper solution is to convert the second string into a Unicode > object, e.g. through > > unicode("L?wis", "iso-8859-1") > if i use #! /usr/bin/env python # -*- coding: UTF-8 -*- at the begginnig of my every script, the example above still has to be converted -- because of the iso-8859-1 you use in "L?wis"? what would change if i use #! /usr/bin/env python # -*- coding: ISO-8859-1 -*- ? can i ommit the conversion (ie. is it done automatically for me as if i write u"Martin v. " + unicode("L?wis", "ISO-8859-1") )? > - A unicode error is raised when a Unicode string is printed to > a terminal. The proper solution is that the system administrator > or the user should properly administer the locale, so that Python > knows what characters the terminal can print. For characters that > are then still non-printable, repr() is the proper solution. see above for comments on my setting. if you have done such a customization (and it differs from mine) and you have experience with linux, may i ask you for recommendations? > > - A unicode error is raised when a library does not support Unicode > for some reason. The proper solution is to fix the library. A > proper work-around is to explicitly convert Unicode strings into > the encoding that the library expects. > dont understand -- which library? you meant for example the ogg vorbis c-library when used with python bindings? -- in that case, what can be done by me as a developer? -- to know what encoding is used and do the tricky things i did -- now properly understood: 1. convert from "unknown" to unicode tmp = unicode("string", "library-charset-specification") 2. print it like print tmp.encode("my-terminal-charset-specification") question: library-charset-specification can be ommited if i specify it in a comment at the very begginning of a script (as i guessed above) -- or my-terminal-charset-specification can be ommitted if specied in comment -- or can i ommit both if equal? if im about to use the __repr__(self) method, i would do the conversion inside that method and return tmp, as i tried above, right? > > > * i was looking in site.py and there is deleted the > >sys.setdefaultencoding() function, but from the comments i do > >not know why -- you know it? why is user not allowed to change the > >default encoding? it seems reasonable to me if he/she could do that. > > Yes, but that would not be a proper solution. It would mean that your > script now only works on your system, and fails on a system where > the default encoding has not been changed, or has been changed to > something else. Users should use a proper solution instead. i thought that every programmer could call his sys.setdefaultencoding() method at the start of the script to set it to whatever he needs. it should work on every system that has proper encoding files. (though in site.py is a comment on MS indows -- it breaks that rule:) > > Regards, > Martin once again, thank you a lot. Regards, Martin (also :) From Andreas.Ames at tenovis.com Thu Aug 5 12:48:57 2004 From: Andreas.Ames at tenovis.com (Ames Andreas (MPA/DF)) Date: Thu, 5 Aug 2004 18:48:57 +0200 Subject: And now to sth. completely different: Forget about decorators, think cgi.FieldStorage Message-ID: <788E231C269961418F38D3E360D1652526CA1B@tndefr-ws00021.tenovis.corp.lan> Hi, is it fair to assume that after executing the following code fs = cgi.FieldStorage(fp = somefile, keep_blank_values = 1) stream = fs.file or StringIO(fs.value) stream is a seekable copy of somefile, i. e. stream.seek(0) works AND stream's contents are the same a somefile's? The docstring seems to suggest that but I wanted to be certain. tia, andreas From reynirhs at mi.is Thu Aug 26 22:11:04 2004 From: reynirhs at mi.is (Reynir Stefánsson) Date: Fri, 27 Aug 2004 02:11:04 +0000 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: So spake Rich Teer: >On Wed, 25 Aug 2004, Xah Lee wrote: > >> Did you know that throughout history there's this thing called cult? > >I think you're getting confused with the Blue ?yster Cult. >Don't Fear the Reaper - great song. And then there's this crazy little thing called love... -- Reynir Stef?nsson (reynirhs at mi.is) From http Mon Aug 23 20:16:31 2004 From: http (Paul Rubin) Date: 23 Aug 2004 17:16:31 -0700 Subject: Getting at the bits of a 32-bit integer References: <85b54e91.0408231552.75f85727@posting.google.com> Message-ID: <7xisb94cgw.fsf@ruckus.brouhaha.com> jacobsmail at postmark.net (Jacob H) writes: > There are plenty of unused bits to the left of the number itself. If I > wanted to use some of these bits as true/false flags, how would I go > about it? In Python, how do I write code that gets at the leftmost > byte, or the third bit from the left of the set of 32, or the > rightmost byte plus the bit to its left, etc... It's not really in the Python spirit, but in general you can set the nth bit (from the right, starting at n=0) of variable x by saying: x |= (1 << n) You can clear it with x &= ~(1 << n) and you can test it with if x & (1 << n): do whatever From jfl at list.idg.dk Wed Aug 25 10:49:47 2004 From: jfl at list.idg.dk (Jacob Friis Larsen) Date: Wed, 25 Aug 2004 16:49:47 +0200 Subject: Python freelancer Message-ID: <412CA70B.5090804@list.idg.dk> Where do I find Python freelancers? I have an open Python project on Sharksforum.com. Thanks, Jacob From egbert.list at hccnet.nl Mon Aug 23 13:56:34 2004 From: egbert.list at hccnet.nl (Egbert Bouwman) Date: Mon, 23 Aug 2004 19:56:34 +0200 Subject: J2 proposal: keyword In-Reply-To: References: Message-ID: <20040823175634.GA3456@mirk.lan> For me the keyword introduces an announcement about the function to be defined next. So why not say 'announce', followed by the name of the function about which you are anouncing something, for instance: announce bar: staticmethod accepts(int, str) returns(str) published(True) def bar(count, input): return input * count The function name after announce serves two purposes: - it makes the program a lot more readable - it makes it possible to put this announcement somewhere else, not immediately before the function. However doing this doesn't look like a good idea. egbert -- Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991 ======================================================================== From rlbuvel at gmail.com Fri Aug 13 08:15:06 2004 From: rlbuvel at gmail.com (Ray Buvel) Date: Fri, 13 Aug 2004 12:15:06 GMT Subject: drop into the interpreter In-Reply-To: References: Message-ID: Hoang Do wrote: > is there a facility to inspect the run-time of a python script? > Essentially, it would execute a script to a set specific point and then drop > into the interpreter. Something like a "Stop" or "Break"? This can be done fairly easily by creating a module (lets call it interactive) with the following code in it. ----------- import sys,os def debug_exception(type, value, traceback): # Restore redirected standard I/O sys.stdin = sys.__stdin__ sys.stdout = sys.__stdout__ sys.stderr = sys.__stderr__ # Kick the interpreter into interactive mode and call the original # exception handler. os.environ['PYTHONINSPECT'] = '1' sys.__excepthook__(type, value, traceback) sys.excepthook = debug_exception ----------- Now if you import this module and raise an unhandled exception, you will be in interactive mode. In other words, I think the following script does what you are asking for. ----------- import interactive raise RuntimeError('Interactive Mode') ----------- This also has the advantage that if there are no unhandled exceptions in your script, the script runs and terminates normally. Enjoy, Ray Buvel From cmkleffner at gmx.de Mon Aug 23 10:19:15 2004 From: cmkleffner at gmx.de (cmkl) Date: 23 Aug 2004 07:19:15 -0700 Subject: python a jdbc References: <2004082022464216807%webstuff@fluidiccom> Message-ID: <3b091a1c.0408230619.45a92254@posting.google.com> Jan Gregor wrote in message news:... > Because many things - wxWindows (java binding is poor and java gui's > aren't good enough), slow startup of jython (in development time) ... > > In article <2004082022464216807%webstuff at fluidiccom>, J wrote: > > On 2004-08-15 12:33:14 -0400, Jan Gregor said: > > > >> Is there some to use jdbc driver with python ? I thought about > >> communication between java process and python throught sockets. Simple > >> test worked fine. > >> > >> Jan > > > > Why not use jython if it is a java app that you want a hook a python > > interpeter into the application. > > Have you tried spiro? http://www.freenet.org.nz/python/spiro/ Regards Carl From tzot at sil-tec.gr Sat Aug 14 09:57:46 2004 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 14 Aug 2004 16:57:46 +0300 Subject: !wtf ellipsis References: <411D5046.B5D16F02@alcyone.com> Message-ID: On Fri, 13 Aug 2004 16:35:34 -0700, rumours say that Erik Max Francis might have written: >Christos TZOTZIOY Georgiou wrote: > >> Peter provided a link answering your questions. As a side note, I >> have >> used Ellipsis instead of None as a very handy last item put in queues >> in >> threaded programs (after all, "ellipsis" means "absence" or "lack" in >> English :) Thus I avoid creating dummy classes to mark the end of >> data... [Erik] >But as a sentinel, why would it be superior to None? I wouldn't choose the word "superior to", rather "more fitting than" IMO; that's because I associate None with "no value", and Ellipsis with "end of values". PS Irrelevant, but I just thought that it's probably too late to ask whether any Pythonistas are here in Athens for the Olympic games, in order to buy them a beer or another drink of their choice :) -- TZOTZIOY, I speak England very best, "Tssss!" --Brad Pitt as Achilles in unprecedented Ancient Greek From python-url at phaseit.net Mon Aug 9 09:08:08 2004 From: python-url at phaseit.net (Peter Otten) Date: Mon, 09 Aug 2004 13:08:08 GMT Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 9) Message-ID: QOTW: "That's a healthy relationship with a language, I feel, when the language and me are struggling with the same problems." - Harald Massa "Fight the trend to add silly disclaimers everywhere!" - GvR Tim Peters helps Kenneth McDonnald over the hurdle of initializing subclasses of an immutable type like str. http://groups.google.com/groups?selm=mailman.1322.1091854312.5135.python-list%40python.org Jeff Epler digs into the C Source to find out why overriding file.write() has no effect on the print statement. http://groups.google.com/groups?threadm=7d04h0dskqbdf2j1f8429726j766mnhrhj%404ax.com You could assure Zeljko Vrba, the "Perl expert wanting to learn Python", that he has already made the hardest step in the new direction. http://groups.google.com/groups?c2coff=1&threadm=slrncguga2.fcp.mordor%40fly.srk.fer.hr --- "@ looks like a friendly little womb, with a happy little birth canal, out of which is born a single pure expression" - Tim Peters The appearance of decorators - a mechanism for wrapping functions and adding attributes to them - in the second alpha of Python 2.4 stirs a heated discussion. Many do not like the introduction of a new symbol, "@" aka "pie", for decoration, or see the chosen one as too "visually dense" (obtrusive) - or just plain ugly. Barry Warsaw weighs alternative symbols. http://mail.python.org/pipermail/python-dev/2004-August/047133.html Christopher T. King argues that the new feature is trying to be all things to all people. http://groups.google.com/groups?selm=Pine.LNX.4.44.0408050856390.31290-100000%40ccc9.wpi.edu Steven Bethard explores the option space, i. e. all aspects of decorator syntax that can be chosen independently. http://groups.google.com/groups?selm=d11dcfba.0408060919.10c7cdd6%40posting.google.com Of course the discussion has been going on among Python's developers for a while and the PEP maintainers who where left behind at some point are struggling hard to update it to the current state of affairs. http://www.python.org/peps/pep-0318.html http://www.python.org/cgi-bin/moinmoin/PythonDecorators I cannot close this section without at least one use-case, so have a look at Michele Simionato's multimethod enhancement, building on code by Howard Stearns and - decorators. http://groups.google.com/groups?threadm=4edc17eb.0408080531.6f8963f9%40posting.google.com (Now be prepared for a more down-to-earth Python-URL next week) --- Let's go back to the "other" pie. Even the most peaceful Pythoneer will ponder "pie-decorating" the author of this short pie-thon report. It's fun, though. http://www.ntk.net/2004/08/06/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous 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 newsgroup weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Brett Cannon continues the marvelous tradition established by Andrew Kuchling and Michael Hudson of intelligently summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Business Forum "further[s] the interests of companies that base their business on ... Python." http://www.python-in-business.org The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donate.html Cetus collects Python hyperlinks. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://aspn.activestate.com/ASPN/Cookbook/Python Among several Python-oriented RSS/RDF feeds available are http://www.python.org/channews.rdf http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi http://python.de/backend.php For more, see http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. *Py: the Journal of the Python Language* http://www.pyzine.com Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. From max at alcyone.com Wed Aug 25 17:56:05 2004 From: max at alcyone.com (Erik Max Francis) Date: Wed, 25 Aug 2004 14:56:05 -0700 Subject: Why return None? References: Message-ID: <412D0AF5.1DA34903@alcyone.com> Martin DeMello wrote: > Yes, but why? I mean, is there either an advantage to returning None > or > some inherent danger in returning self? The "inherent danger" is that the user might think that it returns a new object rather than mutating the original. Returning a new object vs. mutating the argument and returning None is merely a convention, but it's one used consistently in the Python standard library. -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ Trying to mend our hearts in vain -- Sandra St. Victor From spam at no.thanks Sun Aug 8 07:54:45 2004 From: spam at no.thanks (aum) Date: Sun, 08 Aug 2004 23:54:45 +1200 Subject: ANN: hashcash module Message-ID: Hi fellow snake-charmers, Announcing a simple pure-python hashcash implementation. http://www.freenet.org.nz/python/hashcash Enjoy :) From http Thu Aug 26 22:55:50 2004 From: http (Paul Rubin) Date: 26 Aug 2004 19:55:50 -0700 Subject: key storage References: <1093569139.412e8a738462b@www-mail.usyd.edu.au> <412E8E53.20203@harvee.org> Message-ID: <7x7jrl9tmx.fsf@ruckus.brouhaha.com> Ajay writes: > the MIT paper mentions including HMAC's in the cookie and so on. the > question still is - how are the keys stored? HMAC's require a key, as do > digital signatures. how are all these keys stored in a secure manner on > the server? obviously they's be encrypted but then the key used for > encrypting the above key - how is that stored? Well, just what are you trying to protect? Access to the application and its data? What happens if you just put the key in a disk file? If someone can get at it, can't they also get at the rest of the data, so the key is no longer helping protect that data? Who are you trying to keep the key secret from? From indigo at bitglue.com Thu Aug 19 12:58:25 2004 From: indigo at bitglue.com (Phil Frost) Date: Thu, 19 Aug 2004 12:58:25 -0400 Subject: get last two in a length of unknown length? In-Reply-To: References: Message-ID: <20040819165825.GA27745@unununium.org> A negative index counts from the end, so: l = [0,1,2,3,4] l[-1] == 4 this works for slices too: l[-2:] == [3,4] On Thu, Aug 19, 2004 at 03:45:47AM +0100, M. Clift wrote: > Hi All, > > I have a list of varying length. Would someone know the way to get the last > two values for this? I can see how this is done with a list that I know the > length of, but not one thats generated by user input. > > Thanks for any help From ville at spammers.com Tue Aug 31 03:27:19 2004 From: ville at spammers.com (Ville Vainio) Date: 31 Aug 2004 10:27:19 +0300 Subject: Intelisence (and type inference) References: <43SYc.121080$UTP.113615@twister01.bloor.is.net.cable.rogers.com> Message-ID: >>>>> "Andrei" == Andrei writes: Andrei> Jonathan Ellis gmail.com> writes: >> > Is there any inelisence IDE (like visual studio) for python? Andrei> It's harder to do this for Python than for less dynamic Andrei> languages. The most Yes, it's non-trivial, but why is it so hard? I mean, what's the killer problem about type inference? I'm not talking about Starkiller level type inference (which has to be just right, because the code is actually executed) but the kind that would support IDEs for developers that use python in a reasonably standard way: - Modules are imported from standard places - No methods are inserted dynamically - Ambiguous methods are annotated somehow (e.g decorators ;-). - etc. In cases where a name can be bound to instances of multiple different classes, suggest all the methods for completion: >From Foo: foo(k,g) foo2(x,y) >From Bar: bar() bar2(x,c=45) -- Ville Vainio http://tinyurl.com/2prnb From ville at spammers.com Sat Aug 21 17:54:12 2004 From: ville at spammers.com (Ville Vainio) Date: 22 Aug 2004 00:54:12 +0300 Subject: backward compatibility? References: Message-ID: >>>>> "Peter" == Peter Kleiweg writes: Peter> So how serious are plans to remove things from Python, like Peter> lambda and map and reduce? I am just starting out with Python Not very. Talking about it is mostly a way to steer newbies away from them towards superior approaches (list comprehensions and generator expressions). Even if the features were removed, they could be trivially implemented by yourself in python so none of your code would break. Well, noe lambda but I don't believe it will be removed - too much code depends on it. Peter> and if there is a danger that the programs I write today Peter> won't work next year, I rather invest my time in another Peter> language. I might try Ruby, or stick with Perl. Well, if you care about running your code on the new interpreters few years from now (nobody is going to force you to upgrade - some poor tossers still use python 1.5.2), Python is the best bet from the languages you mention. Ruby is going to break compatibility big time soon (or so I've heard - big rewrite or sth), and perl is going through the perl6 pains. Python is extremely cautious about breaking backwards compatibility, sometimes even too cautious for my taste... -- Ville Vainio http://tinyurl.com/2prnb From cousinstanley at hotmail.com Sat Aug 21 20:17:33 2004 From: cousinstanley at hotmail.com (Cousin Stanley) Date: 22 Aug 2004 00:17:33 GMT Subject: I would really like the code for a dome in vpython References: <8f17f4bc.0408181349.46c34b2@posting.google.com> <8f17f4bc.0408201816.13d537a6@posting.google.com> Message-ID: <2oq70tFdejl8U1@uni-berlin.de> >> .... >> http://www.applied-synergetics.com/ashp/html/domes.html >> .... > I went to the link you gave but the link to download the software is broken. :( > Ali .... You might try the following link for dome/windome software from Synergetics .... http://www.applied-synergetics.com/ashp/html/windome_readme.html This is a 6 frame animated GIF I put together back in 2001 using this software which shows full geodesic spheres constructed from an icosahedron base .... http://fastq.com/~sckitching/Icosa_1_thru_6.htm [ 940 KB ] The sphere becomes more and more rounded as the division frequency of the icosahedron increases .... -- Cousin Stanley Human Being Phoenix, Arizona From fumanchu at amor.org Mon Aug 23 13:18:45 2004 From: fumanchu at amor.org (Robert Brewer) Date: Mon, 23 Aug 2004 10:18:45 -0700 Subject: J2 decorator grammar Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E41@exchange.hqamor.amorhq.net> Fran?ois Pinard wrote: > [Peter Maas] > > Robert Brewer schrieb: > > > with: > > return ... > > accept ... > > classmethod > > def func(): > > > > > "using" instead of "with" would be equally satisfactory for me. I > > don't like "decorate" because it sounds like "attaching some bells > > and whistles" or "making it look pretty" which isn't > adequate for the > > meaning of this syntax. > > I'm not especially crusading for `with', but it has the > advantage that it will > likely become a keyword in some later version of Python, and > likely also, > will be used in `with SOMETHING:' and not barely as `with:'. That's a very interesting point. I hadn't noticed the similarity between decorator suites and "with" suites before. I could be argued that decorator suites are a case of a with-suite where the referent is implied. That is: decorate: classmethod def foo(cls): pass implies with foo: classmethod def foo(cls): pass If this is a strong implication, then we could make the argument that decorator suites should allow arbitrary targets, not just def. In that case, a decorator suite which did not possess a signifier ("with:") could universally imply that the referent (the target, that which is signified) follows the suite. Therefore, future use-cases might allow all of the following: with: classmethod .author = "Fran?ois Pinard" def foo(cls): pass def bar(): pass with bar: staticmethod .version = "0.2.4" with: .name = "New Item" thing = Item() with thing: .color = "red" Definitely cool. But too big, I think, for the proposal at this point. That's a large-enough topic that it's probably best to leave to Guido's gut feelings right now. It's enough to point out that such futures are possible; at most, we might mention that "with" and decorators are semantically similar, so we shouldn't reject "with" out-of-hand. Robert Brewer MIS Amor Ministries fumanchu at amor.org From luismg at gmx.net Sat Aug 21 20:05:44 2004 From: luismg at gmx.net (Neuruss) Date: 21 Aug 2004 17:05:44 -0700 Subject: Python future performance and speed Message-ID: <278de0e.0408211605.426e5129@posting.google.com> It seems there are quite a few projects aimed to improve Python's speed and, therefore, eliminate its main limitation for mainstream acceptance. I just wonder what do you all think? Will Python (and dynamic languages in general) be someday close to compiled languages speed? What will be the future of Psyco, Pypy, Starkiller, Ironpython and all the other projects currently on development? From skip at pobox.com Wed Aug 11 14:38:49 2004 From: skip at pobox.com (Skip Montanaro) Date: Wed, 11 Aug 2004 13:38:49 -0500 Subject: @decorator syntax is sugar, but for what exactly? (decorator libraries). In-Reply-To: References: Message-ID: <16666.26553.992466.508907@montanaro.dyndns.org> Minor typo - I think the references to martha.memo[key] in _inner should be to martha.memo[func][key], enabling you to prevent different memoized functions' results from clashing when they were called with the same parameters. Thanks for the correction. Skip From PeterAbel at gmx.net Wed Aug 11 02:35:32 2004 From: PeterAbel at gmx.net (Peter Abel) Date: 10 Aug 2004 23:35:32 -0700 Subject: how to dispatch objects depending on their class References: <4118dd4a$1@maser.urz.unibas.ch> Message-ID: <21064255.0408102235.331f5f49@posting.google.com> Curzio Basso wrote in message news:<4118dd4a$1 at maser.urz.unibas.ch>... > Hi all. > > I have a couple of question regarding the following situation: > > class A(object): > def __init__(self): > pass > > class B(object): > def __init__(self): > A.__init__(self) > > def func(object): > if isinstance(object, A): > do_something_with_A(object) > elif isinstance(object, B): > do_something_with_B(object) > > Note that in my real problem I cannot move the logic of func to the > class A and B because I will have a hierarchy also for func. Then I need > a way to dispatch the object to the right function. I thought about > using a dictionary, like: > > FUNC = {"": do_something_with_A, > "": do_something_with_B} > > def func(object): > FUNC[type(object)](object) > > But: (1) I am not sure of what the type(object) function return. In this > case A and B are in the __main__ namespace (assuming this is how is > called), but if they are in a module; (2) I am not sure if it is > efficient; and finally (3): probably there is a better way to do it > (this is always a safe assumption). > > I hope my problem is clear, and excuse me if I am asking about something > that is common knowledge, but I don't even know what to google for... > > thanks, curzio At my opinion you try to do something outside a class which should be a basic task of OOP. Why not let the instances do their class-specific things: class A(object): def __init__(self): pass def do_something(self): """ Do A-specific things """ pass class B(object): def __init__(self): A.__init__(self) def do_something(self): """ Do B-specific things """ pass a=A() b=B() a.do_something() b.do_something() Regards Peter From harry.g.george at boeing.com Thu Aug 19 13:37:35 2004 From: harry.g.george at boeing.com (Harry George) Date: Thu, 19 Aug 2004 17:37:35 GMT Subject: age of Python programmers References: Message-ID: "Eli Stevens (WG.c)" writes: > Lucas Raab wrote: > > > One thing I've always kind of wondered is what is the average age of a > > Python programmer? > > 25 here, Python newbie (less than a year, I think). > > I'm sad that nobody else in this thread has spoken in hushed, reverent > tones about my gateway drug, LogoWriter. I was 10 when my fifth grade > math class went to the school computer lab and made the turtle crawl > around the screen. From there, QBasic, C++, C-because-school-made-me, > Java-because-work-made-me, Python-to-save-me. ;) > > Handy tip: if you were anything like me, _don't_ go back and try to > read your old code. I had variable names like "qwer" "qwert" and > "qwerty", alongside classics like "a", "b" and "c." > > *Shudder* > Eli > > A few years ago, I mentored for a math class (3rd-5th grades), and we did logo robotics. They programmed the little cars to drive a course drawn on butcher paper. We started with open loop (no feedback), and did pretty well, then added sensor feedback from strategically placed lights and did better. Most of the kids were more interested in building logo monster trucks or coloring on the butcher paper. But 3 of them "got it", and did the programming, and the rest ran after run-away cars. -- harry.g.george at boeing.com 6-6M21 BCA CompArch Design Engineering Phone: (425) 342-0007 From jacek.generowicz at cern.ch Thu Aug 26 11:01:34 2004 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 26 Aug 2004 17:01:34 +0200 Subject: Proposal for removing self References: Message-ID: "Brent W. Hughes" writes: > When doing object-oriented stuff, it bothers me to have to type "self" so > many times. When doing object-oriented stuff, it makes me extactic to write "self." in front of instance attributes. The knowledge that other programmers are always doing the same, makes me even more happy. The fact that there are plenty of C++ and Java coding conventions which require that all class members' names start with "m_", or that all instance attributes be accessed, in methods, via "this->" or "this." (depending) on the language in question, seems to support Python's choice in this matter. > I propose that Python allow the programmer to optionally type > ".variable" instead of "self.variable" to mean the same thing. Of course, > the interpreter would have to be more careful about detecting floats that > begin with just a period as in ".5". What are your thoughts? I think you should get into the habit of reading FAQs, Archives, Googling (you know, the usual stuff), before making such suggestions publically. From __peter__ at web.de Fri Aug 13 08:34:29 2004 From: __peter__ at web.de (Peter Otten) Date: Fri, 13 Aug 2004 14:34:29 +0200 Subject: Why can't pickle dump this instance? References: Message-ID: Jane Austine wrote: > class A: > def __init__(self,tick): > if tick: > self.foo=self.bar > else: > self.foo=self.bur > def bar(self): > print 'bar' > def bur(self): > print 'bur' > > import pickle > pickle.dumps(A()) > > running this script results in "TypeError: can't pickle function objects" > > Why does this happen? and what can I do? By default pickle bypasses the __init__() method completely, it just saves class name and the instance's __dict__. In your case __dict__ happens to contain a bound method which cannot be pickled. I don't know why, maybe the general case where the instance the method is bound to could be a different object would get too messy. The normal way to manipulate the state to be pickled/unpickled is to implement the __getstate__()/__setstate__() pair, but in your case it is easier to trigger invocation of __init__() by generating the appropriate argument list via __getinitargs__(). Peter import pickle class A: def __init__(self, tick): if tick: self.foo = self.bar else: self.foo = self.bur def __getstate__(self): # copy the __dict__ so that further changes # do not affect the current instance d = dict(self.__dict__) # remove the closure that cannot be pickled del d["foo"] # return state to be pickled return d def __getinitargs__(self): tick = self.foo == self.bar # return argument tuple for __init__() # all items must be pickleable return (tick,) def bar(self): print "bar" def bur(self): print "bur" if __name__ == "__main__": # test it for tick in [False, True]: print "\ntick =", tick a = A(tick) a.foo() s = pickle.dumps(a) b = pickle.loads(s) b.foo() From tundra at tundraware.com Sat Aug 21 16:59:52 2004 From: tundra at tundraware.com (Tim Daneliuk) Date: 21 Aug 2004 16:59:52 EDT Subject: My only complaint about Python In-Reply-To: <4127af18$0$22378$626a14ce@news.free.fr> References: <874qmxj81k.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> <4127af18$0$22378$626a14ce@news.free.fr> Message-ID: Christophe Cavalaria wrote: > Tim Daneliuk wrote: > > >>510046470588-0001 at t-online.de wrote: >> >>>Tim Daneliuk writes: >>> >>> >>> >>>>Istvan Albert wrote: >>>> >>>> >>>>>In all fairness this is more the problem with Microsoft than >>>>>python. If they had a free fully-featured compiler then Python >>>>>would be compiled with that. >>>> >>>> >>>>They do. MSC/C++ is now available at NO cost: >>>> >>> >>> >>>no cost is not the same as free >>> >>>Klaus Schilling >> >> >> >>"No Cost" is _exactly_ the same thing as "Free". It is not the same >>thing as "Open Source". >> >>The debate is foolish in any case. If I use an GPLed compiler, even with >>the Lesser License, I have constraints placed upon what I may or may >>not do with the derivative work. If I use a commercial compiler, I do >>not have access to the source code _for the compiler_, but (usually) >>there are no constraints placed upon what I may do with the derivative >>work. > > > This is wrong on so many levels : > - gcc is GPL software and you don't have to GPL the source code of the > programs you compile with it. Doing so would place a restriction on the > user of the software which is exactly what the GPL is trying to prevent. > Using gcc to compile source code isn't creating a derivative work of gcc ! > - if you modify the gcc source code and thus create a derivative work, you > don't have to distribute the changes, unless you distribute the new gcc > version. > - with a commercial closed source compiler, you can't do any derivative of > the compiler at all and thus you have less freedom than with a GPL > compiler. > > If you can't see the difference between using a software and creating a > derivative work of that software ... It is "derivative" in the sense that the final binary may either contain and/or depend upon library support shipped with the gcc compiler chain. IIRC (and this may have changed - I have not looked at it in some time), even the Lesser GPL places some constraints about what you _must_ distribute (or be willing to provide) when you use their libs to produce a shipped product. Moreover, for a long time (and this too may have changed), the corporate lawyers I had checking the GPL did not like it because it was (legally) muddy. The only sense in which you have "less freedom" with a commercial product is that you cannot build works that derive directly from the compiler/library source code. So what? In most real world commercial applications, this is a non-issue. Note that I was clear that I use _both_ OSS and Commercial products. My rant is directed at people who thing Proprietary=Evil and OSS=Good which is a nonsensical position. -- ---------------------------------------------------------------------------- Tim Daneliuk tundra at tundraware.com PGP Key: http://www.tundraware.com/PGP/ From peter at engcorp.com Wed Aug 18 07:27:01 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 18 Aug 2004 07:27:01 -0400 Subject: case insensitive comparison operator ? In-Reply-To: <41233060$0$198$db0fefd9@news.zen.co.uk> References: <41233060$0$198$db0fefd9@news.zen.co.uk> Message-ID: Will McGugan wrote: > What is the best way to do a simple case insensitive comparison in Python? > > As far as I can tell, the only option is to do str1.lowercase() == > str2.lowercase() (or uppercase). Actually, it's str1.lower() == str2.lower(). > But that strikes me as quite verbose Luckily it's not that verbose after all! ;-) > for such a common operation, Nor that common! If you need to do this more than once in an application, you can easily create a simple compareCaseInsensitive() function that hides the above "excessive verbosity" and you'll never notice it again. Furthermore, in most cases you've already stored one of those two strings, so if you lower() it when you store it, you only need to do "str1 == str2.lower()" when you are comparing later on. At least that's the use case I've seen to be "common", and I've written more Python code than you have so there. ;-) > and possibly inneficient since it would create and destroy 2 > tempory objects. Python creates and destroys a lot more temporary objects than you might imagine, and still gets by. In fact, the function calls involved probably have much higher overhead (from setting up the stack frame) than the object creation... Python often upsets conventional ideas of where hotspots will be. > Apologies if I have missed something. I haven't done a great deal of > work int Python yet. Worrying about possible inefficiencies before you've even done much coding in a language is a clear case of premature optimization. Just write some code, learn to use and love Python, and if you still really want this, come back later and suggest it again. ;-) -Peter From andy47 at halfcooked.com Thu Aug 5 14:31:16 2004 From: andy47 at halfcooked.com (Andy Todd) Date: Thu, 05 Aug 2004 19:31:16 +0100 Subject: MySQLdb select In-Reply-To: <2nembjF2dr7U1@uni-berlin.de> References: <9RPOc.2792$LI7.1058@newssvr27.news.prodigy.com> <21064255.0408020908.41357e52@posting.google.com> <2n9gmuFuhk8kU1@uni-berlin.de> <2nbn3pFv4865U1@uni-berlin.de> <2nembjF2dr7U1@uni-berlin.de> Message-ID: Sibylle Koczian wrote: > Dennis Lee Bieber schrieb: > >> >> Except that the conversion function, .literal(), /does/ accept >> a single item, a sequence (tuple OR list), or a mapping (dictionary). >> The arguments are just passed through .execute(), which doesn't really >> care one way or the other. >> >> Tediously, .execute() calls ._execute(), which has: >> ... >> try: >> if args is None: >> r = self._query(query) >> else: >> r = self._query(query % self.connection.literal(args)) >> except TypeError, m: >> ... >> >> Since .literal() accepts single objects (well, in truth, I'd >> guess one would have to say that it is .escape() that processes the >> arguments -- I can't say what that does, as it is likely in the binary >> module. However, the actual forming of the final query string /is/ the >> standard Python "string" % arg operator, which, in my experience, has >> never complained about not being given a 1-tuple. >> > > True. I had hopes that this might explain another riddle I couldn't > solve: datefield is a database column of type date, and I execute two > queries: > > a) SELECT * FROM mytable WHERE datefield = %s > > b) SELECT * FROM mytable WHERE datefield IN (%s, %s) > > case a): the parameter for %s can be a mx.DateTime object, a > datetime.date object or the sort of DateTime object MySQLdb returns from > another query; or it can be a string with format 'YYYY-MM-DD'. The > results of the query are correct in every case. > > case b): the parameters must be strings of the form 'YYYY-MM-DD'. With > all other sorts of parameters (DateTime objects, strings in other date > formats) the query doesn't find anything. > > I tried this with different versions of MySQL, MySQLdb and Python, under > Windows and Linux, always with the same results. > > Now I've looked at conn.literal(args) for a pair of DateTime objects and > for a single one: > > >>> arg > > >>> arglist > [, object for '2004-07-07 00:00:00.00' at 1199de0>] > >>> conn.literal(arglist) > ("'2004-07-29 00:00:00'", "'2004-07-07 00:00:00'") > >>> conn.literal(arg) > "'2004-06-18 00:00:00'" > >>> s1 = 'SELECT * FROM fehllief WHERE fehltag IN (%s, %s)' > >>> s1 % conn.literal(arglist) > "SELECT * FROM fehllief WHERE fehltag IN ('2004-07-29 00:00:00', > '2004-07-07 00:00:00')" > >>> s2 = 'SELECT * FROM fehllief WHERE fehltag = %s' > >>> s2 % conn.literal(arg) > "SELECT * FROM fehllief WHERE fehltag = '2004-06-18 00:00:00'" > >>> curs.execute(s1, arglist) > 0L > >>> curs.execute(s2, arg) > 1L > > Why doesn't the query using IN find anything while the query using = > does? The records are there, of course. > > Koczian It's a bug. I think it is a bug in MySQL. I'm using 4.0.18 on Debian and an interactive session shows the problem; """ andy47 at vetinari:~$ mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 25 to server version: 4.0.18-log Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> use portfolio Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select count(*) from stock_prices where price_date = '2004-07-30'; +----------+ | count(*) | +----------+ | 7 | +----------+ 1 row in set (0.00 sec) mysql> select count(*) from stock_prices where price_date = '2004-07-30 00:00:00'; +----------+ | count(*) | +----------+ | 7 | +----------+ 1 row in set (0.00 sec) """ When using '=' the two forms of date are identical, but if we switch to using 'in'; """ mysql> select count(*) from stock_prices where price_date in ('2004-07-30'); +----------+ | count(*) | +----------+ | 7 | +----------+ 1 row in set (0.00 sec) mysql> select count(*) from stock_prices where price_date in ('2004-07-30 00:00:00'); +----------+ | count(*) | +----------+ | 0 | +----------+ 1 row in set (0.00 sec) mysql> """ Ta-da. Of course, this may have already been notified to MySQL AB, I'd check their web site (http://www.mysql.com) or try one of their mailing lists. Regards, Andy -- -------------------------------------------------------------------------------- From the desk of Andrew J Todd esq - http://www.halfcooked.com/ From ayose.cazorla at hispalinux.es Wed Aug 25 11:12:07 2004 From: ayose.cazorla at hispalinux.es (Ayose) Date: Wed, 25 Aug 2004 16:12:07 +0100 Subject: Why return None? In-Reply-To: References: Message-ID: <20040825151206.GB2852@setepo.gotdns.org> [Martin DeMello] > It seems to be a fairly common pattern for an object-modifying method to > return None - however, this is often quite inconvenient. > > For instance > > def f(lst1, lst2): > g((lst1 + lst2).reverse()) # doesn't work! If you can use python 2.3 or newer, try with [::-1] >>> def f(m, n): ... print (m + n)[::-1] ... >>> f([1,2,3], [10,20,30]) [30, 20, 10, 3, 2, 1] >>> -- Ayose Cazorla Le?n Debian GNU/Linux - setepo From adurdin at gmail.com Thu Aug 19 01:57:57 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Thu, 19 Aug 2004 15:57:57 +1000 Subject: [Python-Dev] PEP 318: Can't we all just get along? In-Reply-To: <200408190455.i7J4t6CN025433@cosc353.cosc.canterbury.ac.nz> References: <200408190455.i7J4t6CN025433@cosc353.cosc.canterbury.ac.nz> Message-ID: <59e9fd3a0408182257702db09b@mail.gmail.com> On Thu, 19 Aug 2004 16:55:06 +1200, Greg Ewing wrote: > Guido: > > > Is anybody seriously trying to come up with a single alternative > > decorator proposal that most folks "out there" can support, to be > > presented to me (with implementation, please!) in time for 2.4b1? > > >From the posts I've seen here, the only alternatives that have > considerable popular support are ones that you've already rejected. So > I suspect nobody really feels it's worth trying. To expand on that just a bit: the two alternatives that were most generally favoured (in Doug Holton's estimate) were the "list-after-def" (C1 in the wiki), and the "pie decorator at top of function body" (E1 in the wiki), both of which Guido rejected. In the poll that Doug ran, E1 had a slight margin over C1: http://mail.python.org/pipermail/python-list/2004-August/233479.html However, C1 has an implementation, while E1 doesn't. (Aside: how difficult would it be to create an implementation of E1?) From timrueAT at mindspringDOT.com Sun Aug 15 16:19:03 2004 From: timrueAT at mindspringDOT.com (threeseas) Date: Sun, 15 Aug 2004 20:19:03 GMT Subject: autocoding and the new MS book regarding software factories In-Reply-To: References: Message-ID: Roman Suzi wrote: > On Sun, 15 Aug 2004, threeseas wrote: >> >>(CLI #1) + (GUI) + (IPC) = the three primary ..... > > > Well, there is no scientific foundation and in fact science tells us that > autocoding is not possible for arbitrary tasks. I believe, it is possible to > create autocoding (automatically generated) software for any little enough > problem domain, maybe, say, for writing GUI. However there is theoretical > abyss between modern computers and humans. It is called formalisation. > Only programmer's brain is capable to cross this abyss formalising any > non-trivial novel task. What science? Certainly not the science of abstraction physics. You seemed to snip what you didn't want to consider .... sorta like what those who don't want to see my presence on a python IRC channel, ban me.... But denial is no proof against something, but only proof of the choice of ignorance by those in denial. from another direction -- http://www.codegeneration.net/generators.php Software development is still quite young. Like mathmatics via the roman numeral system, very limited. But then came along the hindu-arabic decimal system with its "nothing can have value" zero place holder that cause every thing to change, including the droping of status for expert accountants in roman numeral mathmatics. The science of roman numeral mathmatics tell us that the complexity of calculation required to create a computer (as we call it today and in hindsight - for it was beyond even imagination at that point) is simply not possible to achieve.... go figure.. But if you are looking for a singularity or magic formula or holy grail, forget it, it simply doesn't exist. But what does exist is: Programming is the act of automating complexity, typically made up of simpler parts (in comparison to the sum product of the automation) and done so in order to make the use and re-use of the automation easier for the user(s) of the automation. This is a recursive act, from automaing some assembly language code into a higher level language function all the way up to a typical user scripting (perhaps via some user action recorder/playback application)so as to make some task of theirs easier to do. Its clear to me that Artificial Intelligence is.. well nothing is naturally that stupid... an illusion of simply automating enough, perhaps in a highly dynamic manner, to present the illusion of intelligence. Its simply a matter of the foundation nature of the technology... binary transistors... like a two deminsional creature being totally incapable of comprehending a three deminsional being or object. Soooo..... to use an analogy we simply need to put away our roman numeral mentality and its inability to comprehend that nothing can have value. To drop the psuedo science of programming and get to reality with the understanding of abstraction physics. > And for trivial task we already have an interface: > > $ grep -i word file | sort | uniq | wc > > Saying the above, I must admit that more tasks become trivial as new > instruments arrive. So, programming users (CP4A anybody?) can > solve their 90% of their tasks by almost mechanical combination > of existing tools. > > * > > I imaging Year 2015: > > Computer: > - by your command > GvR: (standing at his computer) > - computer, make Python 3.0 release. The grammar I sketched > on the paper in the scanner. Please guess semantics. > If in doubt post to c.l.p a question. If c.l.p in doubt make a > poll. If in doubt of poll results make another poll on how to > interpret poll results. > Computer: > - YES, SIR! > GvR: > - Good. > (after half an our) > > Computer: > - I need your help > GvR: > - yes? > Computer: > - please affirm you want to pay $10k for the Microsoft license > and also Python 3 violates 20 patents. > GvR: > - Oh no!... (calling sponsors) > (after half an hour) > Computer: > - Python 3 ready. Total cost $21k. > GvR: > (typing "python3" at his terminal) > - Oh... But this is #D... > Computer: > - under given constraints this is the best solution. C.l.p poll > shows 52% of people support this as it is familiar to them. > GvR: > (upset, playing with his time machine controls) > (1 minute later) > Timbot: > - there is another option > GvR: > - What? > Timbot: > - freeware aka OSS > > > > Sincerely yours, Roman Suzi Amusing.... Like writing a Buck Rodgers script as how the space program will look like, huh? I noticed you put alot of faith in the patent sysytem to be able to maintain its command over father physics and mother nature, or at least to convince humans it has such power. Perhaps someone should simply just write out a patent application for anti-gravity and the patent office grant it so we can all finally just have it..... huh? But here is what is really going to happen: you walk off a cliff and gravity will make you fall down. Likewise, you try and put false constraints on what is naturally possible and its a sure thing that father physics and mother nature will expose you for your falseness, making you fall down (metaphorically speaking) That is what is going to happen to the patent system in regards to software. Especially when abstraction physics are established and found to be natural and with a physical element that cannot be denied (patents give the right to exclude) anyone. The absolute unpatentable nature of abstraction physics and commonality of solutions via the then obvious non-novel abstraction creation and manipulation mechanics. from one side --- autocoding, from the other side --- code generators... Those in the middle trying to hold on to what they want to believe is non-automatable are going to get ....... exposed... perhaps die of exposure... :) The python programming language itself has made quite a bit that was previously more complex to impliment, easier to use and reuse, via automation of that complexity into modules, functions, classes, etc... I have also found the eric3 IDE exactly what I was looking for in having the ability to trace or follow thru the execution of python code and variables it includes. The only drawback I find with python is its required code indentation, but that might be turned into an advantage in developing or configuring an autocoding tool set for it. As it is perhaps easy to follow where an autocoder shifted inward or outward in code depth/detail. At any rate, the fall of the patent system in regards to software and the establishment of genuines abstraction physics.... Of course OSS is the way to go. its the ship that is truely capable of sailing around the world and proving that the proprietary tech of the flat earth simply is just a denial of what is, for only the benefit of a few. Together openly, we can do a great deal more, and that is what IS. (tunnel vision greed or wide scope benefits?) maybe I've just given MS a few hints..??? shrug...(a matter of denial ... ;) From webstuff at fluidic.com Fri Aug 20 22:46:30 2004 From: webstuff at fluidic.com (J) Date: Sat, 21 Aug 2004 02:46:30 GMT Subject: python a jdbc References: Message-ID: <2004082022464216807%webstuff@fluidiccom> On 2004-08-15 12:33:14 -0400, Jan Gregor said: > Is there some to use jdbc driver with python ? I thought about > communication between java process and python throught sockets. Simple > test worked fine. > > Jan Why not use jython if it is a java app that you want a hook a python interpeter into the application. -- J "If there is anything I can do for you or more to the point to you, let me know." From pink at odahoda.de Sat Aug 21 17:58:48 2004 From: pink at odahoda.de (Benjamin Niemann) Date: Sat, 21 Aug 2004 23:58:48 +0200 Subject: Validating SGML parser? Message-ID: Hi, does anyone know of a validating SGML parser in python (like xmlproc.xmlval does for XML)? Goal is to validation HTML against the DTD, similar to validator.w3.org, not all SGML obscurities are required. If real SGML validation is no option, I could probably rewrite the HTML to make it XML conformant and feed it into xmlval - but then I'll have to find a way to map line/column numbers from error messages to positions in the unmodified HTML. I leave this as an exercise for my future self... Greetings from Heidelberg, Germany Benjamin Niemann From ville at spammers.com Wed Aug 4 15:11:14 2004 From: ville at spammers.com (Ville Vainio) Date: 04 Aug 2004 22:11:14 +0300 Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) References: <10h24oace15n97a@news.supernews.com> Message-ID: >>>>> "John" == John Roth writes: John> Decorator syntax seems to have been checked into 2.4b2. I'm John> not going to comment on the syntax other than to say that, John> when there isn't a real obvious syntax, someone has to make John> a decision, and this one should work. Yes, it should work. It's also a terrible waste of @ punctuation, which should IMO be reserved for some more worthwhile purpose. I was eagerly waiting for the introduction of decorators (and worried that the proposed syntaxes would cause the feature to be thrown out), but this choice of syntax leaves a bad taste in my mouth, and makes me want to see the intro of decorators to be postponed or scrapped altogether. This syntax is out there with backticks and print>>. And I'm one of those who voted *for* ternary operator, and generally embrace new features with enthusiasm. -- Ville Vainio http://tinyurl.com/2prnb From thomas at it-snedkeren.BLACK_HOLE.dk Mon Aug 9 06:29:51 2004 From: thomas at it-snedkeren.BLACK_HOLE.dk (Thomas Lindgaard) Date: Mon, 09 Aug 2004 12:29:51 +0200 Subject: Komodo, debugging and multi-threading Message-ID: Hello I have a multi-threaded web spider and it has a problem (probably several). Is there a way to make the debugger show me what my worker threads are doing? I can only get it to follow the main thread. I'm using Komodo Personal (trial). -- Regards /Thomas From seandavidross at hotmail.com Fri Aug 27 13:17:35 2004 From: seandavidross at hotmail.com (Sean Ross) Date: Fri, 27 Aug 2004 13:17:35 -0400 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> Message-ID: "Dan Perl" wrote in message news:2SJXc.79576$pTn.26490 at news01.bloor.is.net.cable.rogers.com... > Here is a python feature that I would like: to be able to import modules > from an archive like the jar files in Java. Maybe a regular tar file? [snip] > I am quite new to python so I should ask first whether there is already > something like that, although I did a search already. Or maybe such a > feature has already been discussed somewhere? If this is an original idea, > how can I propose it for future releases? Well, you can use .zip files http://www.python.org/doc/2.3.4/whatsnew/node5.html HTH, Sean From peter at engcorp.com Thu Aug 5 12:18:22 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 05 Aug 2004 12:18:22 -0400 Subject: RELEASED Python 2.4, alpha 2 In-Reply-To: References: <411231C8.3020308@interlink.com.au> Message-ID: <2-SdnZCwNs1SwI_cRVn-uQ@powergate.ca> Anthony Baxter wrote: >>This is a bad joke after all the strong perplexities showed about its >>decorators solution. >>I vote against the "@decorator before function" solution. > > Please feel free to actually provide reasons for not liking @decorators. > > Also - if you think you don't like it - please _try_ _it_ _out_ first. Actually, I think many people *are* trying it out right now... by reading the posts in this forum. Python is not supposed to be a write-only language, as are some other P languages that tend to use lots of punctuation for arbitrary purposes (as surely no one has forgotten). Python is supposed to be an *eminently readable* language. Those of us objecting on the grounds of things like "ugliness" are actually *reading* the examples and sample code that are being posted, and are finding them *highly unreadable*. This is a valid reaction, and since code is more often read than written (as again I don't need to remind anyone), the readability of a feature should weigh much more heavily than how easy it is to use after you try it out for yourself. IMHO. Yes, of course after using them for a while they will become more readable, but there are people who have learned to speak Klingon as well -- and that doesn't change the fact that Klingon is deliberately very difficult to learn and awkward. Furthermore, a number of people seem to be claiming that decorators will be rarely used, so the @ syntax shouldn't be considered a problem. They are getting it exactly backwards! If decorators will be rarely used, then make sure the syntax is more readable than not, and even if it's a tad more cumbersome to write, who will mind? They aren't going to be used that often, right?! -Peter From theller at python.net Fri Aug 27 10:36:37 2004 From: theller at python.net (Thomas Heller) Date: Fri, 27 Aug 2004 16:36:37 +0200 Subject: Call for signatories for J2 References: Message-ID: "Robert Brewer" writes: > The J2 proposal is as complete as it will ever be. > > http://www.aminus.org/rbre/python/pydec.html Against. Thomas Heller why: pie syntax reads better. From sjdevnull at yahoo.com Tue Aug 10 12:22:11 2004 From: sjdevnull at yahoo.com (G. S. Hayes) Date: 10 Aug 2004 09:22:11 -0700 Subject: tool to check whether formal and actual parameters have similar names References: Message-ID: <96c2e938.0408100822.3c9905d@posting.google.com> "Amir Michail" wrote in message news:... > I was wondering if there is a tool that will perform some heuristic > checking of actual and formal parameters to warn about likely errors. > > Such a tool could check that formal and actual parameters have similar > names. > > For example: > > def plot(x,y): ... > > plot( x1, y1 ) # ok > > plot( y1, x1 ) # not ok, but this is ok: plot (x=y1, y=x1) I'm not sure how generally useful this would be. There are just too many circumstances where the name in the definition and the name you call with are legitimately quite different: def plot(x, y): ... plot(square.width, square.height) for column in range(8): for row in range(8): move_pawn_to(column, row) plot(column, row) for i in range(10): for j in range(10): plot(i,j) #along with other stuff using the loop variables def write_log(string_to_send): # probably a log.write method in real life ... write_log(server.error_message) write_log(user.username) def wait_for_connection(socket): ... wait_for_connection(servers["yahoo"]) It _might_ be somewhat useful to have something that detects ONLY when you are calling with similar names in a different order. Even that isn't necessarily useful, there might be non-trivial cases something like: class generic_tree(): def insert_member(child, parent): class gui_window_tree(our_tree): class crypto_algorithms_tree(our_tree): ... (child, parent) = fork_wrapper() GUIWindows.insert_member(child, parent) EncryptionAlgorithms.insert_member(parent, child) where flip-flopping names made sense. Though this isn't a particularly great example, and it might generally be a decent lint warning. From pinard at iro.umontreal.ca Wed Aug 4 15:08:16 2004 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Wed, 4 Aug 2004 15:08:16 -0400 Subject: ANN: libgmail 0.0.7 - Gmail access via Python - Now with FTP Proxy! In-Reply-To: <20040804161942.GA22706@performancedrivers.com> References: <20040804161942.GA22706@performancedrivers.com> Message-ID: <20040804190816.GA4269@alcyon.progiciels-bpi.ca> [Jack Diederich] > Seriously, it is great that you are doing stuff and sharing it but > we don't need a status update every three days. These announcements are much more on target for the Python list than some other posts we sometimes see here. Moreover, if the progress is worth many announcements, they are welcome so far that I am concerned, and the maintainer deserves at the very least the right of sharing his enthusiasm around, where people might choose to pick it up. A message like the one quoted above may well kill enthusiasm, and is counter-productive. A good and nice walk outside, admiring birds, enjoying the sun and greenery, breathing fresh air, might put everyone in a better mood and be more useful, overall, for the community. :-) -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From gbig005 at auckland.ac.nz Thu Aug 19 21:57:35 2004 From: gbig005 at auckland.ac.nz (Geoffrey Biggs) Date: Fri, 20 Aug 2004 13:57:35 +1200 Subject: Problems with adding a new built-in data type In-Reply-To: References: Message-ID: <41255a8e$1@news.auckland.ac.nz> No need to worry anymore, I've fixed the problem. If you're making a built-in type, remember to define your PyTypeObject with something other than NULL in the PyObject_HEAD_INIT. Non-built-ins don't need to worry about this because it gets filled in later for them (as in the example in the docs), but built-ins appear to need to fill it in themselves. Geoff Biggs Geoff Biggs wrote: > Evening all, > > I'm trying to add a new built-in number data type to Python with its own > syntax, so I'm working directly with the interpreter rather than > creating my own extension module (side note: I've appended something > extra to the version thing in the Makefile - I doubt this is relevant to > the problem but it's probably best you have all the info). The complex > data type is similar to what I'm trying to do so I've been following > that as an example. I've successfully extended the tokenizer and the > parsenumber() function in compile.c to do what I want and written the > data type in my two new files Objects/mynewobject.c and > Include/mynewobject.h. I've included mynewobject.h in Python.h and added > the two files to the Makefile. > > However, when I tried to run the code by typing in the syntax to produce > my data type, Python suffers a segmentation fault. I traced this to an > attempt to get the hash of a null pointer when adding the new instance > of my type after parsenumber() was called. For completeness, here's the > backtrace: > > Program received signal SIGSEGV, Segmentation fault. > 0x08080e9a in PyObject_Hash (v=0x81486c0) at Objects/object.c:1162 > 1162 if (tp->tp_hash != NULL) > (gdb) bt > #0 0x08080e9a in PyObject_Hash (v=0x81486c0) at Objects/object.c:1162 > #1 0x0808e199 in tuplehash (v=0x40324574) at Objects/tupleobject.c:244 > #2 0x08080eae in PyObject_Hash (v=0x40324574) at Objects/object.c:1163 > #3 0x0807b46c in PyDict_GetItem (op=0x40319c14, key=0x40324574) at > Objects/dictobject.c:492 > #4 0x080c72c7 in com_add (c=0xbfffed60, list=0x40326114, > dict=0x40319c14, v=0x40326290) at Python/compile.c:975 > #5 0x080c74ac in com_addconst (c=0xbfffed60, v=0x40326290) at > Python/compile.c:1001 > #6 0x080c90e3 in com_atom (c=0xbfffed60, n=0x4028d500) at > Python/compile.c:1689 > > The crash appears to be caused because while v exists, v's members are > all 0 and so tp becomes 0 when it is made equal to v->ob_type and you > get a NULL pointer exception. As far as I can tell, this v is the second > object in the tuple created in com_add() and is supposed to be the type > of the object being added to the dictionary in a tuple. Not knowing why > it was coming out as zero, I did some more poking around (been doing a > lot of that over the past 5 days...) and found that there is a file > called bltinmodule.c with a bunch of lines, one of which mentions the > complex data type that I am using as a guide: > > SETBUILTIN("complex", &PyComplex_Type); > > So I made one of these for mynewobject and added it. I figured from this > bit of code that the reason I was getting NULL pointer exceptions was > because my type hadn't been initialised in some way and that this would > do it. But here's the problem: despite trying for longer than I've slept > in the past week, I can't get it to work. With that line in the Python > interpreter segfaults as soon as it starts (while trying to import the > os module) and so it can't even finish compiling the extension modules. > If I comment out the SETBUILTIN line I added it will compile fine but > then I go back to the first problem. > > I have structured my object identically to the complex object as far as > I can tell, which works. So the question is, what's broken? What have I > missed when adding a new builtin? > > (This mess is all happening on Linux tillinshir 2.6.7-gentoo-r11-gb #1 > Wed Aug 4 11:13:14 NZST 2004 i686 mobile AMD Athlon(tm) XP 2000+ > AuthenticAMD GNU/Linux, if that matters.) > > Thanks in advance, > Geoff Biggs From ThomasBartkus at Comcast.net Mon Aug 9 18:02:45 2004 From: ThomasBartkus at Comcast.net (Thomas Bartkus) Date: Mon, 9 Aug 2004 17:02:45 -0500 Subject: VB-like GUI designer? References: <30260531.0408091048.7011855f@posting.google.com> Message-ID: "Fred" wrote in message news:tnmfh0dp629i16hqrqbnnu6r6l73kt2kn6 at 4ax.com... > > Thx but... not thx. That reminds me too much of the Petzold-era > Windows in C :-) > Gads! I still have that Petzold book. I remember studying that stuff thinking it would take a long to for this GUI stuff to catch on. It didn't! Thomas Bartkus From mg.mailing-list at laposte.net Tue Aug 31 13:59:48 2004 From: mg.mailing-list at laposte.net (mathieu gontier) Date: Tue, 31 Aug 2004 19:59:48 +0200 Subject: PYTHON API : add new classes in a module from an other module Message-ID: <4134BC94.50702@laposte.net> Hi every body I am tring to create new Python modules. In a first time, I have created a module named FOO in which I have inserted new classes. No problem : PyMODINIT_FUNC initFOO( void ) { PyObject* module = Py_InitModule3( "FOO", 0, "foo module" ) ; if ( ! module ) return ; if ( PyType_Ready( &my_type) < 0 ) return ; Py_INCREF( &my_type ); PyModule_AddObject( module, "my_pytype", (PyObject*) &my_type ) ; } In a second time, I would like create a new module named BAR. In the 'init' function of this module, Ii would like add new classes in FOO. So, I would like white something like the following : PyMODINIT_FUNC initBAR( void ) { foo_module = Py_GetModule( "FOO" ) ; if( ! foo_module ) return ; if ( PyType_Ready( &my_addtype) < 0 ) return ; Py_INCREF( &my_addtype ); PyModule_AddObject( foo_module, "my_pyaddtype", (PyObject*) &my_addtype ) ; } So, my question is : does it exist in the Python API, a equivalent function of "Py_GetModule( )" (that a have invented for the example !) ; or does an other solution exist in order to do the same think ? Thanks, Mathieu From steven.bethard at gmail.com Thu Aug 19 17:10:05 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 19 Aug 2004 21:10:05 +0000 (UTC) Subject: inverse of izip References: Message-ID: Peter Otten <__peter__ web.de> writes: > You can model the nested generator expressions' behaviour with the following > function - which I think is much clearer. > > def starzip(iterables): > def inner(itr): > for t in itr: > yield t[i] > > for (i, itr) in enumerate(it.tee(iterables)): > yield inner(itr) > > Note how itr is passed explicitly, i. e. it is not affected by later > rebindings in startzip() whereas i is looked up in inner()'s surrounding > namespace at every yield. Thanks, that was really helpful! It also clarifies why your solution works right; your code basically does: def starzip(iterables): def inner(itr, i): for t in itr: yield t[i] for i, itr in enumerate(itertools.tee(iterables)): yield inner(itr, i) where i is now passed explicitly too. Thanks again, Steve From kamikaze at kuoi.asui.uidaho.edu Mon Aug 23 13:06:11 2004 From: kamikaze at kuoi.asui.uidaho.edu (Mark 'Kamikaze' Hughes) Date: 23 Aug 2004 17:06:11 GMT Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? References: Message-ID: Paul McGuire wrote on Sun, 22 Aug 2004 02:53:09 GMT: > Well, after 3 days of open polling, the number of additional votes have > dropped off pretty dramatically. Here are the results so far: My server didn't receive the poll at all, AFAICT. So my votes are: A1 L L I'd rather have a keyword than punctuation, but the placement is exactly right, and I have zero problem with @. If I could vote *against* something, it would be C1. That's the most amazingly horrible code, and leads to indentation wars for all eternity. -- Mark Hughes "Virtues foster one another; so too, vices. Bad English kills trees, consumes energy, and befouls the Earth. Good English renews it." -The Underground Grammarian, v1n2 From ruflicks at yahoo.fr Sun Aug 29 16:16:30 2004 From: ruflicks at yahoo.fr (ruflicks) Date: 29 Aug 2004 13:16:30 -0700 Subject: Zope help system, password needed in windows References: <4130bc1e$1@pfaff2.ethz.ch> Message-ID: Thanks for your answer. Will try this new version. Best regards. From simoninusa2001 at yahoo.co.uk Sun Aug 29 19:10:30 2004 From: simoninusa2001 at yahoo.co.uk (Simon John) Date: 29 Aug 2004 16:10:30 -0700 Subject: wxPython with Python 2.4a2 Message-ID: Has anyone built wxPython for Python 2.4a2? I was going to evaluate Python 2.4a2, but as most of my Python work is done with wxWidgets, it seems pointless without a wxPython build to go with it. Preferably Windows, but Linux would be good too. I don't fancy doing the job myself under Linux, and don't have MSVC for Windows. From ajsiegel at optonline.com Thu Aug 12 13:10:24 2004 From: ajsiegel at optonline.com (Arthur) Date: Thu, 12 Aug 2004 17:10:24 GMT Subject: PEP318 References: <20040812090056.00001e31@titan> <7ttmh0t8c3cogtbhhnp1ohqu8b51pda461@4ax.com> Message-ID: On Thu, 12 Aug 2004 17:03:19 GMT, Arthur wrote: >> >>One of the objections to: >> >>def foo (): >> whatever >>foo = decorator (foo) >> >>is that you have to type the word "foo" three times. > >Big f**king deal - all things considered. ;) Mathematical notation looks to achieve conciseness, and precision of expression. And on settled matters of notation, assumedly that attempt has been optimized. Why is that not good enough for Python? > >Art From nobody at nowhere.com Fri Aug 6 17:41:56 2004 From: nobody at nowhere.com (Yannick Turgeon) Date: Fri, 6 Aug 2004 17:41:56 -0400 Subject: Telnet session References: Message-ID: I found the answer... but not the solution. The problem comes from the fact that Microsoft does not use a *real* telnet server. It's documented in Perl Net::Telnet doc. They are not fully respecting telnet protocol. Windows Telnet Server resend the text and ANSI char that would appear in a cmd.exe window. Curious? Sure! So each time you send a command from a client that lead to "push" the previous command out of the vitual "display" space, Windows Telnet Server resend all the resulting "display". You can try it with a Windows telnet session where the client is started from cmd.exe. You'll see that after login (here though!), you can write 7 "echo" commands and get the reply without "pushing" previous "echo" out of the window. On the 8th "echo" ("echo bar7" in the script given in this thread), the window is redraw. And when programmaticaly telneting this kink of server, you get ALL what the screen would contain if it were a cmd.exe window. Yes! ALL! Even what you already receive. Making the read_until() function unusable. Here is what I've fond on Perl Net::Telnet doc: ---------------- By default MS-Windows doesn't come with a TELNET server. However third party TELNET servers are available. Unfortunately many of these servers falsely claim to be a TELNET server. This is especially true of the so-called "Microsoft Telnet Server" that comes installed with some newer versions MS-Windows. When a TELNET server first accepts a connection, it must use the ASCII control characters carriage-return and line-feed to start a new line (see RFC854). A server like the "Microsoft Telnet Server" that doesn't do this, isn't a TELNET server. These servers send ANSI terminal escape sequences to position to a column on a subsequent line and to even position while writing characters that are adjacent to each other. Worse, when sending output these servers resend previously sent command output in a misguided attempt to display an entire terminal screen. Connecting Net::Telnet to one of these false TELNET servers makes your job of parsing command output very difficult. It's better to replace a false TELNET server with a real TELNET server. The better TELNET servers for MS-Windows allow you to avoid the ANSI escapes by turning off something some of them call console mode. --------------------- Hope it will prevent anybody to spent as much time as I did on this problem! Yannick From russblau at hotmail.com Thu Aug 26 13:51:08 2004 From: russblau at hotmail.com (Russell Blau) Date: Thu, 26 Aug 2004 13:51:08 -0400 Subject: property puzzle References: <78b6a744.0408260846.5dc5a0cf@posting.google.com> Message-ID: <2p6m8eFhjanfU1@uni-berlin.de> "george young" wrote in message news:78b6a744.0408260846.5dc5a0cf at posting.google.com... > [python 2.3.3, x86 linux, part of a substantial gtk/postgres app] > I want a Run instance to have a Status instance which inherits > from Observable. I want to be able to say: > > thisrun.status = 'planned' > > and have thisrun's _set_status do side-effects and then the status > object's setter incorporate the new value as it's new state. > But the setter functions never seem to get called. > Am I using "property" wrong? > > class Observable: #("observer" software pattern) 'property' only works with new-style classes. Try changing to class Observable(object): and also make the same change in class Run. -- I don't actually read my hotmail account, but you can replace hotmail with excite if you really want to reach me. From james at logicalprogression.net Tue Aug 17 21:08:05 2004 From: james at logicalprogression.net (James Henderson) Date: Wed, 18 Aug 2004 02:08:05 +0100 Subject: strange problem with def in class In-Reply-To: <4122A948.3010805@logicalprogression.net> References: <1092788477.995526@seven.kulnet.kuleuven.ac.be> <4122A948.3010805@logicalprogression.net> Message-ID: <4122ABF5.2070601@logicalprogression.net> A couple of quick corrections. James Henderson wrote: > Hi Johan > > Other variables defined in a class are in a scope that cannot be > accessed directly from within a method (Python newish nested scoping > only works for functions inside functions). Actually it works for classes defined inside functions too, but that's not relevant here. :) > Personally I would move your readline() function outside the class to > the module level. This still stands! > If you want to keep it in the class then either give it a self parameter > or add "readline = staticmethod(readline)" after the definition of > readline(). Then you can call it from within __init__() as > self.readline(filename). Looking at your code again the static method option is not viable. Your readline() method needs a self parameter because the code you intend to put into it refers to self. J From tzot at sil-tec.gr Mon Aug 16 07:12:54 2004 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Mon, 16 Aug 2004 14:12:54 +0300 Subject: Trouble with file.seek/file.tell on Win32? References: <16671.45400.965715.943437@enthought.hathway.com> <1f7befae04081512496c6f2727@mail.gmail.com> Message-ID: On Mon, 16 Aug 2004 00:34:47 -0400, rumours say that Prabhu Ramachandran might have written: >I'm happy to also learn that bad line endings break tell and >seek. I guess this is a problem on the mac too where lines end with >'\r'. Is this true of OSX? I have little knowledge of OS/X (just playing around with a friends Apple laptop, can't remember the type), but I assume that there will not be a problem with OS/X (and do they use '\r' like in the old MacOS, or do they respect the Linux heritage and use '\n' now? maybe a mix?). The string "hello\nthere\n" written to a *text* file, has: 12 bytes on *nix 14 bytes on Windows/DOS 12 bytes on OS/X To read the "t" of "there", one first has to: f.seek(6) on both *nix and OS/X, text or binary file f.seek(6) on Win text file f.seek(7) on Win binary file. -- TZOTZIOY, I speak England very best, "Tssss!" --Brad Pitt as Achilles in unprecedented Ancient Greek From noone at here.com Thu Aug 19 14:26:32 2004 From: noone at here.com (M. Clift) Date: Thu, 19 Aug 2004 19:26:32 +0100 Subject: get last two in a length of unknown length? References: Message-ID: Again, thanks Wes, I appreciate it. From drlinux at columbus.rr.com Tue Aug 31 17:49:46 2004 From: drlinux at columbus.rr.com (Dave Reed) Date: Tue, 31 Aug 2004 17:49:46 -0400 Subject: Beeping the console In-Reply-To: References: Message-ID: <200408311749.46432.drlinux@columbus.rr.com> On Tuesday 31 August 2004 17:31, Jeffrey Barish wrote: > What is the easiest way to beep the console from a Python program (i.e., > to do the same thing as echo -e \a)? > -- > Jeffrey Barish print '\a' or if you're on a Unix system and the program is not being run from the console, you can do something like: con = open("/dev/tty1", "w") con.write("\a") con.close() /dev/tty1 will probably depend on what time of system you're on. HTH, Dave From ccdetail at gmail.com Mon Aug 9 23:05:13 2004 From: ccdetail at gmail.com (ccdetail) Date: 9 Aug 2004 20:05:13 -0700 Subject: pro python paper Message-ID: <305aa162.0408091905.5bce8f9a@posting.google.com> http://www.journyx.com/pdf/PythonAtAGlance.pdf the above paper is a response to some of our prospects complaints they were asking us why we use python thought you guys might be interested http://journyx.com/clf From ajsiegel at optonline.com Mon Aug 23 11:00:43 2004 From: ajsiegel at optonline.com (Arthur) Date: Mon, 23 Aug 2004 15:00:43 GMT Subject: __name__ becoming read-write? References: Message-ID: <3i1ki0pjcpuaob9qh0vuc6934k5esqb41a@4ax.com> On 23 Aug 2004 16:50:22 +0200, Hallvard B Furuseth wrote: >Arthur wrote: > >> Did I hallucinate something about __name__ becoming read-write? > >_Becoming_ read-write? When was it read-only? > >Python 1.5.2 (#1, Jul 14 2004, 20:34:28) [GCC 3.2.3] on sunos5 >Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>>> class foo: pass >... >>>> foo.__name__ = 'bar' >>>> foo.__module__ = 'baz' >>>> foo > Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32 >>> def foo(): pass >>> foo.__name__='bar' Traceback (most recent call last): File "", line 1, in -toplevel- foo.__name__='bar' TypeError: readonly attribute I hope I'm not being stupid. And what's with running 1.5.2 ;) Art From aleaxit at yahoo.com Fri Aug 27 13:37:45 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 27 Aug 2004 19:37:45 +0200 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> Message-ID: <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> Dan Perl wrote: > Here is a python feature that I would like: to be able to import modules > from an archive like the jar files in Java. Maybe a regular tar file? Python 2.3 lets you import modules from a zipfile. The zip format is better than tar when you just need to get one file from it, which is why java's jar files are also basically zipfiles. > I am quite new to python so I should ask first whether there is already > something like that, although I did a search already. Or maybe such a > feature has already been discussed somewhere? If this is an original idea, > how can I propose it for future releases? It's there already, and has been for over a year now;-). Alex From news at NOwillmcguganSPAM.com Wed Aug 18 09:11:18 2004 From: news at NOwillmcguganSPAM.com (Will McGugan) Date: Wed, 18 Aug 2004 14:11:18 +0100 Subject: age of Python programmers In-Reply-To: References: Message-ID: <41235577$0$190$db0fefd9@news.zen.co.uk> Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... > > I have reached the grand old age of 30. I think C++ has prematurely aged me, so Im hoping Python can roll back the clock. Will McGugan From Moiz.Golawala at ge.com Thu Aug 12 13:57:48 2004 From: Moiz.Golawala at ge.com (Golawala, Moiz M (GE Infrastructure)) Date: Thu, 12 Aug 2004 12:57:48 -0500 Subject: os.removedirs not working(Thanks) Message-ID: <4BF8D93CF6F73F4890EB6ED8009ECE191C5CFF@FTWMLVEM01.e2k.ad.ge.com> Thank you all.. it solves my problem. Moiz Golawala GE Infrastructure, Security Software Engineer Enterprise Solutions T 561 994 5972 F 561 994 6572 E moiz.golawala at ge.com www.gesecurity.com 791 Park of Commerce Blvd., Suite 100 Boca Raton, FL, 33487, U.S.A. GE Security, Inc. -----Original Message----- From: python-list-bounces+moiz.golawala=ge.com at python.org [mailto:python-list-bounces+moiz.golawala=ge.com at python.org]On Behalf Of Christopher T King Sent: Thursday, August 12, 2004 11:51 AM To: python-list at python.org Subject: Re: os.removedirs not working On Thu, 12 Aug 2004, CptPicard wrote: > You could use shutil.rmtree : it works fine! Oh wow, I completely forgot about shutil. Good stuff, that. -- http://mail.python.org/mailman/listinfo/python-list From martin at koekenberg.net Mon Aug 30 18:25:42 2004 From: martin at koekenberg.net (Martin Koekenberg) Date: Tue, 31 Aug 2004 00:25:42 +0200 Subject: TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' References: Message-ID: <97a7j0do4k6r4he9gqeb60p1optvcevrgb@4ax.com> Hello, Thanks for alle the help.. but it still dosn't work. How even, the error has changed a bit : "/usr/local/bin/python" "/usr/local/zope/Zope-2.7.2-0/setup.py" \ build --build-base="/usr/local/zope/Zope-2.7.2-0/build-base/python-2.3" --build-lib="/usr/local/zope/Zope-2.7.2-0/build-base/python-2.3/build-lib" --build-scripts="/usr/local/zope/Zope-2.7.2-0/build-base/python-2.3/build-scripts" --build-temp="/usr/local/zope/Zope-2.7.2-0/build-base/python-2.3/build-temp" running build running build_py running build_ext Traceback (most recent call last): File "/usr/local/zope/Zope-2.7.2-0/setup.py", line 1091, in ? distclass=ZopeDistribution, File "/usr/local/lib/python2.3/distutils/core.py", line 149, in setup dist.run_commands() File "/usr/local/lib/python2.3/distutils/dist.py", line 907, in run_commands self.run_command(cmd) File "/usr/local/lib/python2.3/distutils/dist.py", line 927, in run_command cmd_obj.run() File "/usr/local/lib/python2.3/distutils/command/build.py", line 107, in run self.run_command(cmd_name) File "/usr/local/lib/python2.3/distutils/cmd.py", line 333, in run_command self.distribution.run_command(command) File "/usr/local/lib/python2.3/distutils/dist.py", line 927, in run_command cmd_obj.run() File "/usr/local/lib/python2.3/distutils/command/build_ext.py", line 244, in run customize_compiler(self.compiler) File "/usr/local/lib/python2.3/distutils/sysconfig.py", line 172, in customize_compiler cc_cmd = cc + ' ' + opt TypeError: cannot concatenate 'str' and 'NoneType' objects make: *** [build] Error 1 I had an other type error before the env setting : TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' Greetings, Martin Koekenberg On 30 Aug 2004 21:31:10 +0200, Hallvard B Furuseth wrote: >[Brett C.] >> Set your environment 'CC' environment variable to gcc and it should go >> away. > >[Martin Koekenberg] > >How do I set this environmet variable ?? >I don't have a lot of linux experience ;-) > >[Brett C.] > >> For Bourne-style shells (BASH, ZSH, etc.) ``export CC=gcc`` will do it >> for the current shell (won't save it for future use, that requires >> setting it in your shell's config file. > >Nitpick: That works for bash and zsh - and therefore for Martin, since >he uses Linux - but not for plain non-Linux Bourne 'sh'. The portable >Bourne way is > > CC=gcc; export CC > >> For CSH style I think it is ``setenv CC gcc`` but I am not sure. > >That's right. > >And the standard way which works for both Bourne and CSH style, but for >just one command at a time (in this case ./configure), is > > env CC=gcc ./configure From aquila_deus at yahoo.co.uk Wed Aug 18 11:21:40 2004 From: aquila_deus at yahoo.co.uk (Aquila Deus) Date: 18 Aug 2004 08:21:40 -0700 Subject: Swing/Metalworks for Python References: <41224ea4$1@news.broadpark.no> Message-ID: "Diez B. Roggisch" wrote in message news:... > Gisle Vanem wrote: > > > I was quite impressed by this toolkit in the latest Java SDK 1.5 > > (not sure if it's new in this version or not). But are there any similar > > toolkits for Python that allows switching Look & Feel and Themes > > in the same way? > > qt - free for *nixes, commercially available for windows. And the best > toolkit I've worked with. There is a non-commercial version (3.1) that comes with a qt book. From follower at gmail.com Sun Aug 22 09:32:26 2004 From: follower at gmail.com (Follower) Date: 22 Aug 2004 06:32:26 -0700 Subject: ANN: libgmail 0.0.8 - Gmail access via Python - POP3 Proxy added! Message-ID: libgmail -- Python binding for Google's Gmail service The `libgmail` project is a pure Python binding to provide access to Google's Gmail web-mail service. The library currently ships with a demonstration utility to archive messages from a Gmail account into mbox files, suitable for importing into a local email client. Also includes a demonstration utility that acts as a SMTP proxy to allow mail to be sent from any standard mail client that uses SMTP (e.g. Mail.app, Mozilla etc). (Now handles attachments.) New demonstration utility acts as a POP3 proxy to allow mail to be retrieved from any standard mail client that uses POP3 (e.g. Mail.app, Mozilla etc). Features demonstration utility to provide access to Gmail message attachments via a download-only FTP proxy--this allows retrieval of suitably marked attachments by a standard FTP client. Utilize more of your Gmail space! License: GPL 2.0 (gmailftpd.py/gmailpopd.py are dual licensed with PSF) Major changes since 0.0.7: * Fixed login to work again after it was broken by a Gmail change. * Added trash/delete message thread & trash/delete single message functionality. (By request.) * POP3 proxy server demo. (By request.) * Added `GmailLoginFailure` exception to enable tidier handling of login failures (which could be bad username/password or a Gmail change).

    libgmail 0.0.8 - The `libgmail` project is a pure Python binding to provide access to Google's Gmail web-mail service; includes SMTP, POP3 & FTP proxies. (23-Aug-04)

    From theller at python.net Fri Aug 20 17:57:32 2004 From: theller at python.net (Thomas Heller) Date: Fri, 20 Aug 2004 23:57:32 +0200 Subject: Alternative decorator syntax decision References: Message-ID: <657d8oc3.fsf@python.net> google at daishi.fastmail.fm (daishi) writes: > C1 C1 C1 Hm, I like the pie syntx, so A1 A1 A1 (is A2 really different from A1?) > If we are allowed to make negative votes: > > -J2 -J2 -J2 > > I personally find J2 worse than the current pie > syntax. Something that looks odd and does something > odd seems the lesser evil vs something that looks > normal yet does something odd. Exactly my feeling. Thomas From jdhunter at ace.bsd.uchicago.edu Thu Aug 19 12:38:20 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Thu, 19 Aug 2004 11:38:20 -0500 Subject: My only complaint about Python In-Reply-To: (David Fraser's message of "Thu, 19 Aug 2004 18:33:03 +0200") References: Message-ID: >>>>> "David" == David Fraser writes: David> I agree. I don't mind it being built with Visual Studio, David> but out of the box mingw compatibility would be cool... -- David> http://mail.python.org/mailman/listinfo/python-list The only thing that needs to be done for mingw compatibility is to build the import lib, right? It would be nice if the win32 python shipped with that; it's only 37K gzipped. I have a batch script to create libpython23.a, for those who are interested. It requires pexports-0.42h from http://starship.python.net/crew/kernr/mingw32/pexports-0.42h.zip extracted to C:\Program Files\pexports-0.42h, and of course mingw. Your paths may vary... copy c:\windows\system32\python23.dll . c:\progra~1\pexports-0.42h\bin\pexports python23.dll > python23.def c:\MinGW\bin\dlltool --dllname python23.dll --def python23.def --output-lib libpython23.a copy libpython23.a c:\python23\libs del python23.dll del libpython23.a From tdelaney at avaya.com Thu Aug 5 22:42:55 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Fri, 6 Aug 2004 12:42:55 +1000 Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01C8C584@au3010avexu1.global.avaya.com> You missed mine ;) +1 Tim Delaney From heikowu at ceosg.de Thu Aug 12 02:34:25 2004 From: heikowu at ceosg.de (Heiko Wundram) Date: Thu, 12 Aug 2004 08:34:25 +0200 Subject: Arranging a dependency tree In-Reply-To: <61ESc.3831$%B.1788@newssvr27.news.prodigy.com> References: <6ccff37a.0408111831.6eb25a4e@posting.google.com> <61ESc.3831$%B.1788@newssvr27.news.prodigy.com> Message-ID: <200408120834.25714.heikowu@ceosg.de> Am Donnerstag, 12. August 2004 08:22 schrieb Bryan Olson: > I'm sure Heiko actually knew this, but being the kind of smart- > ass I am, I can't resist the chance to correct him on things he > already knew twice in one day. Earlier he wrote "large prime" > where he clearly meant "large integer". I trust he will take > this post in the spirit in which it is intended. I bow before the master. ;-) Heiko. From PPNTWIMBXFFC at spammotel.com Thu Aug 26 10:50:26 2004 From: PPNTWIMBXFFC at spammotel.com (Marco Aschwanden) Date: Thu, 26 Aug 2004 16:50:26 +0200 Subject: How to generically transform a list? Message-ID: Suppose you have a list of lists: theList = [['a',1,11,'aa'], ['b',2,22,'bb'],['c',3,33,'cc']] I would like to have a GENERIC way how to turn this list of list into another list of list. - A user can choose which columns she wants - A user can select the order of the columns For example: The user wants columns: 1,2 The user wants it to be ordered: 2,1 A non generic approach would maybe do the following: >>> theList = [['a',1,11,'aa'], ['b',2,22,'bb'],['c',3,33,'cc']] >>> new_list = [[row[2], row[1]] for row in theList] >>> new_list [[11, 1], [22, 2], [33, 3]] I am sure there must be a rather elegant generic approach, which is lurking somewhere to be realeased. Thanks for any hint in advance, Marco From duncan.booth at invalid.invalid Tue Aug 10 11:26:38 2004 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 10 Aug 2004 15:26:38 GMT Subject: super and __init__ arguments (Was: Re: Multiple inheritance with a common base class) References: <1092137872.2624.16.camel@dicaprio.akademie1.de> <1092142873.2624.43.camel@dicaprio.akademie1.de> Message-ID: Markus Bertheau wrote in news:mailman.1447.1092145129.5135.python-list at python.org: > Now how do I make the following work: > > class CommonBase(object): > def __init__(self, c): > pass > > class LeafA(CommonBase): > def __init__(self, c, a): > super(LeafA, self).__init__(c) > > class LeafB(CommonBase): > def __init__(self, c, b): > super(LeafB, self).__init__(c) > > class Multi(LeafA, LeafB): > def __init__(self, c, a, b): > super(Multi, self).__init__(c, a, b) > > m = Multi(0, 1, 2) > The best way is to use keyword arguments: class CommonBase(object): def __init__(self, c): pass class LeafA(CommonBase): def __init__(self, a, **kw): super(LeafA, self).__init__(**kw) class LeafB(CommonBase): def __init__(self, b, **kw): super(LeafB, self).__init__(**kw) class Multi(LeafA, LeafB): def __init__(self, **kw): super(Multi, self).__init__(**kw) m = Multi(c=0, a=1, b=2) From shalabh at cafepy.com Tue Aug 10 23:26:38 2004 From: shalabh at cafepy.com (Shalabh Chaturvedi) Date: Tue, 10 Aug 2004 20:26:38 -0700 Subject: Static method object not callable References: Message-ID: Edward Diener wrote: > This simple code example gives me the message, "TypeError: 'staticmethod' > object is not callable". > > class X(object): > def Y(x): > print x > Y = staticmethod(Y) > ad = { 1 : Y } > def Z(self): > self.ad[1](3) > x = X() > x.Z() > print "Done." > > I know there must be a way to have a class attribute reference a static > method, and then call that static method through the reference, so if > anyone can correct this it would be appreciated. A staticmethod has to be accessed from the class or an instance. But you can put the 'bare' function in your dictionary before you make a staticmethod out of it: class X(object): def Y(x): print x ad = { 1 : Y } Y = staticmethod(Y) def Z(self): self.ad[1](3) x = X() x.Z() print "Done." This prints: 3 Done. HTH, Shalabh From raims at dot.com Sat Aug 7 13:06:57 2004 From: raims at dot.com (Lawrence Oluyede) Date: Sat, 7 Aug 2004 19:06:57 +0200 Subject: Importance of C# (was Re: IronPython-0.6 is now available!) References: <278de0e.0407281353.27b6a457@posting.google.com> <5dydnZSDZaARoZXcRVn-ug@powergate.ca> <1n5z28erh2m3u.dlg@baczek.net.invalid> <537ea4cd.0408070757.14790cfe@posting.google.com> Message-ID: In data 7 Aug 2004 08:57:56 -0700, ziller ha scritto: > It'll be there for 2.0. And the implementation is superb (much like > Eiffel's generics) I don't want to start a religion war, since I also develop with C# but I don't see the "superb implementation", and to be honest I think it will mess up the code more and more because of new keywords, new constructs and so on. I'm not saying that generics has to be dropped but since you are on a Python NG I think that your are clever enough to see what the limits of C# are and why generics are getting all this hype bye! -- Lawrence (l dot oluyede at virgilio dot it) "In IE we trust" From mh at dreadnok.pixar.com Tue Aug 3 19:08:36 2004 From: mh at dreadnok.pixar.com (Mark Harrison) Date: Tue, 03 Aug 2004 23:08:36 GMT Subject: guide to introspecting python? Message-ID: What's a good document to read in order to understand some of python's introspective functions? I'm trying to recurse through a module and print information about its contents. dir() does something similar to what I have in mind, but it's documented to be more for human interaction than definitive programmatic correctness, so I'd like to call or look at whatever it's using. This bit of code never finishes because dir(something) and dir(something.__call__) return the same thing. def rdir(item, v=""): print "%s%s"%(v,item) for i in dir(item): rdir(i, v+" ") import os rdir(os) Any help/pointers appreciated! Thanks, Mark PS, you will probably recognize this as my attempt to generate programatically the module/function/parameter index I previously asked about... -- Mark Harrison Pixar Animation Studios From nomail at nospam.no Sun Aug 8 03:51:26 2004 From: nomail at nospam.no (Dominic) Date: Sun, 08 Aug 2004 09:51:26 +0200 Subject: decorators vs GIL In-Reply-To: <4115a8aa$0$19945$626a14ce@news.free.fr> References: <4115a8aa$0$19945$626a14ce@news.free.fr> Message-ID: > threads: make a heavy process, doing a > single event loop. Well, often chaining generators is good enough! Another -- probably not so good solution is to do an interface specification and generate code with it. "Active Tasks" could be automatically _inverted_ , depending on your choice. Michael Jackson (hee, not the singer) has done this in the 70s in COBOL. Maybe you have heard of JSD or JSP ;-) (JSP (Jackson Structured Programming) and JSD (Jackson System Development)) In JSD you model entities as processes. (CSP) (Yes it is OOP analysis ;-) ) Afterwards you map processes too processors. Probably you have only one, so all processes but one must be inverted. However a scheduler solution is also possible. Maybe someone comes up with a @decorator solution, which does invert active tasks on the fly :-) Ciao, Dominic From fredrik at pythonware.com Fri Aug 27 11:03:01 2004 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 27 Aug 2004 17:03:01 +0200 Subject: PEP-0318 References: <41122FC2.1080608@interlink.com.au><4114152f@nntp.zianet.com> <4116bc20$1@nntp.zianet.com><6NCdncg4ssq28orcRVn-uQ@powergate.ca> <411a5cee$1@nntp.zianet.com> <411a9a7f$1@nntp.zianet.com> <411ac17f@nntp.zianet.com> Message-ID: Mark Bottjer wrote: >>>Indeed it is. And that fact bears on this conversion how? >> >> that's what a decorator does, of course. > > No it isn't. A decorator queues a function to be called, on something not yet defined, after that > something gets defined. uhuh. and what do you think the "foo" in foo(bar) does? you don't really know how Python works, do you? From bj_666 at gmx.net Wed Aug 18 15:18:26 2004 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Wed, 18 Aug 2004 21:18:26 +0200 Subject: Newbie question about file input References: <4122328e$0$8079$a1866201@newsreader.visi.com> Message-ID: In , Aaron Deskins wrote: > Perhaps I should have been more specific. What does python store when > you read a blank line? Nothing? A null variable? A '\n'? It reads '\n' as that's, more or less, the content in the text file for that line. In the file there may be some other platform specific byte (combination) to denote a line ending. > How about this: > > import string > import sys > zf=open(sys.argv[1],'r') > it = 0 > while 1: > line = zf.readline() > print line > rs = line.split() > print rs > if rs[0]== '[Event': > it+=1 > print it > if not line: > break > zf.close() > > This fails when it tries the "if rs[0]== '[Event':" statement. rs[0] > doesn't exist (or is blank?) for a blank line in my input file. Let's fire up the interpreter and see why: >>> line = "\n" >>> line '\n' >>> rs = line.split() >>> rs [] >>> rs[0] Traceback (most recent call last): File "", line 1, in ? IndexError: list index out of range A line without anything but whitespace characters "splits" to an empty list. > Another code: > > import string > import sys > zf=open(sys.argv[1],'r') > it = 0 > while 1: > line = zf.readline() > it+=1 > if not line: > break > zf.close() > print it > > This only ends when the end of file is reached. Why not when a blank > line is read? How does python treat the variable line (after a readline) > differently after a blank line or the last line of the file? As said before: a blank line is not really empty but contains a newline character. When the file ends, readline() returns an empty string. Ciao, Marc 'BlackJack' Rintsch From aleaxit at yahoo.com Thu Aug 26 17:01:49 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 23:01:49 +0200 Subject: PEP 322 - alternate method names References: Message-ID: <1gj5e1c.yrievcmt2xkpN%aleaxit@yahoo.com> Robert Brewer wrote: > AC wrote: > > >From the PEP 322 page: > > > > "This PEP has been conditionally accepted for Py2.4. The condition > > means that if the function is found to be useless, it can be removed > > before Py2.4b1" > > > > Is there still hope at least for an alternative method name that is > > not past tense? > > "reversed" doesn't have to be a past tense verb in English; it's more of > an adjective, modifying its target. "X is a reversed sequence". > > > flip, transpose, invert, swap... > > The problem with using a "present tense verb" is that it implies that > the original object is mutated. So what about a GERUND, 'reversing' or the like, as somebody else just mentioned? THAT would be cool, IMHO (not that I think any name change stands much of a chance at the stage...). The convention of using gerunds for iterators and generators seems good in general; I wish we had 'enumerating' rather than 'enumerate' and, say, itertools.zipping rather than itertools.izip. Ah well, sigh, probably too late by now -- ah well indeed! Alex From aleaxit at yahoo.com Sat Aug 28 03:02:12 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 28 Aug 2004 09:02:12 +0200 Subject: Iteration over Lists and Strings References: Message-ID: <1gj80xs.1cfownoqz4m9N%aleaxit@yahoo.com> Michel Claveau - abstraction m?ta-galactique non triviale en fuite perp?tuelle. wrote: > and enumerate is more fast than index. Oh, absolutely. sequence.index(anitem) takes time proportional to len(sequence), for the average item. If you repeat that operation for all items in sequence, you end up with total time proportional to the SQUARE of len(sequence) -- a LOT, for long sequences, enumerate itself takes constant time, and looping over all items that enumerate yields takes time proportional to the number of items (costant time per item). If you're familiar with big-O notation, we're talking O(N) vs O(N square)... not the kind of performance issue one can ignore, for long sequences, because the difference in performance keeps going up and up without bounds as the sequence grows longer. Alex From sandskyfly at hotmail.com Thu Aug 5 19:04:00 2004 From: sandskyfly at hotmail.com (Sandy Norton) Date: 5 Aug 2004 16:04:00 -0700 Subject: tweaking @decorator syntax References: Message-ID: Here are some more variations. Please copy/paste the code below into your favourite python editor and see how each syntactical variation of the decorator code reads, and how quickly you grok its structure and meaning. #---------------------------------------------------------------------- # current syntax 2.3 syntax #---------------------------------------------------------------------- class Klass: def __init__(self, name): '''class initialization ''' self.name = name def statmethod1(x): '''does something to x ''' return x statmethod1 = staticmethod(statmethod1) def statmethod2(y): '''does something to y ''' return y statmethod2 = staticmethod(statmethod2) def clsmethod1(cls): '''does something to cls ''' return cls clsmethod1 = classmethod(clsmethod1) def clsmethod2(cls): '''does something to cls ''' return cls clsmethod2 = classmethod(clsmethod2) def go(obj): '''synced obj is activated ''' obj.activate() go = synchronized(go) def f(x,y): '''tests two ints for equality ''' return x == y f = accepts(f, (int, int)) f = returns(f, (str)) #---------------------------------------------------------------------- # @decorator syntax proposed for 2.4 #---------------------------------------------------------------------- class Klass: def __init__(self, name): '''class initialization ''' self.name = name @staticmethod def statmethod1(x): '''does something to x ''' return x @staticmethod def statmethod2(y): '''does something to y ''' return y @classmethod def clsmethod1(cls): '''does something to cls ''' return cls @classmethod def clsmethod2(cls): '''does something to cls ''' return cls @synchronized def go(obj): '''synced obj is activated ''' obj.activate() @accepts(int, int) @returns(bool) def f(x,y): '''tests two ints for equality ''' return x == y #---------------------------------------------------------------------- # Nested, @decorator syntax proposed for 2.4 #---------------------------------------------------------------------- class Klass: def __init__(self, name): '''class initialization ''' self.name = name @staticmethod def statmethod1(x): '''does something to x ''' return x def statmethod2(y): '''does something to y ''' return y @classmethod def clsmethod1(cls): '''does something to cls ''' return cls def clsmethod2(cls): '''does something to cls ''' return cls @synchronized def go(obj): '''synced obj is activated ''' obj.activate() @accepts(int, int) @returns(bool) def f(x,y): '''tests two ints for equality ''' return x == y #---------------------------------------------------------------------- # Nested, minimal decorator syntax proposed for 2.4 #---------------------------------------------------------------------- class Klass: def __init__(self, name): '''class initialization ''' self.name = name staticmethod: def statmethod1(x): '''does something to x ''' return x def statmethod2(y): '''does something to y ''' return y classmethod: def clsmethod1(cls): '''does something to cls ''' return cls def clsmethod2(cls): '''does something to cls ''' return cls synchronized: def go(obj): '''synced obj is activated ''' obj.activate() accepts(int, int), returns(bool): def f(x,y): '''tests two ints for equality ''' return x == y #---------------------------------------------------------------------- # Nested, 'decorate' keyword syntax proposed for 2.4 #---------------------------------------------------------------------- class Klass: def __init__(self, name): '''class initialization ''' self.name = name decorate staticmethod: def statmethod1(x): '''does something to x ''' return x def statmethod2(y): '''does something to y ''' return y decorate classmethod: def clsmethod1(cls): '''does something to cls ''' return cls def clsmethod2(cls): '''does something to cls ''' return cls decorate synchronized: def go(obj): '''synced obj is activated ''' obj.activate() decorate accepts(int, int), returns(bool): def f(x,y): '''tests two ints for equality ''' return x == y #---------------------------------------------------------------------- # Nested, |decorator| syntax proposed for 2.4 #---------------------------------------------------------------------- class Klass: def __init__(self, name): '''class initialization ''' self.name = name |staticmethod| def statmethod1(x): '''does something to x ''' return x def statmethod2(y): '''does something to y ''' return y |classmethod| def clsmethod1(cls): '''does something to cls ''' return cls def clsmethod2(cls): '''does something to cls ''' return cls |synchronized| def go(obj): '''synced obj is activated ''' obj.activate() |accepts(int, int), returns(bool)| def f(x,y): '''tests two ints for equality ''' return x == y From joewong at mango.cc Fri Aug 20 02:40:27 2004 From: joewong at mango.cc (Joe Wong) Date: Fri, 20 Aug 2004 14:40:27 +0800 Subject: Is HTTPSConnection thread-safe? Message-ID: <027501c48680$950cb3b0$7f00a8c0@scl01.siliconcreation.com> Hi, I have a small program using HTTPSConnection to issue a POST on the server. When multiple threads of the same program is running, I got the error: Exception in thread Thread-3: Traceback (most recent call last): File "C:\PYTHON23\lib\threading.py", line 436, in __bootstrap self.run() File "C:\PYTHON23\lib\threading.py", line 416, in run self.__target(*self.__args, **self.__kwargs) File "mcstest.py", line 27, in thread_func conn.request("POST", CGI_PATH, params, headers) File "c:\python23\lib\httplib.py", line 718, in request self._send_request(method, url, body, headers) File "c:\python23\lib\httplib.py", line 739, in _send_request self.endheaders() File "c:\python23\lib\httplib.py", line 712, in endheaders self._send_output() File "c:\python23\lib\httplib.py", line 597, in _send_output self.send(msg) File "c:\python23\lib\httplib.py", line 564, in send self.connect() File "c:\python23\lib\httplib.py", line 985, in connect ssl = socket.ssl(sock, self.key_file, self.cert_file) File "C:\Python23\lib\socket.py", line 73, in ssl return _realssl(sock, keyfile, certfile) sslerror: SSL_CTX_new error in random order. Is there any fix / patches for this? Regards, - Joe -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwilson at the-wire.com Mon Aug 16 13:21:02 2004 From: mwilson at the-wire.com (Mel Wilson) Date: Mon, 16 Aug 2004 13:21:02 -0400 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: <+zOIBls/Kj3Q089yn@the-wire.com> In article , Dennis Lee Bieber wrote: >On 13 Aug 2004 07:15:14 -0700, beliavsky at aol.com declaimed the following >in comp.lang.python: > Teach them FORTRAN-IV... > > A source line is limited to 80 characters > Statements start in column 7 > Statements end in column 72 (or was it 71) Column 72 is the last one available for statment text, according to this IBM 888157 card here. Regards. Mel. From pm_mon at yahoo.com Thu Aug 26 08:27:52 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Thu, 26 Aug 2004 08:27:52 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Anthony Baxter wrote: > On Thu, 26 Aug 2004 10:28:14 +0200, Paolo Veronelli > wrote: > > ignored). Do you intend that the double-under names would also be > looked for in the same scopes? That is, what will this code do? > > def foo(): > __name__ = '%s_banana'%(__name__) > /exactly/ the same thing as def foo(): pass foo.__name__ = '%s_banana'%(foo.__name__) Paul From anthonybaxter at gmail.com Sat Aug 7 16:40:32 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sun, 8 Aug 2004 06:40:32 +1000 Subject: Decorator syntax In-Reply-To: <2nkk3aF1ph3dU1@uni-berlin.de> References: <38ednYT1NLz1P4zcRVn-uA@powergate.ca> <2nkk3aF1ph3dU1@uni-berlin.de> Message-ID: On Sat, 07 Aug 2004 20:15:01 +0200, Reinhold Birkenfeld wrote: > But I fear that without a formal "voting" Python will go the pragmatic > way - that is, keep @ as it's already implemented. Sorry - but would "formal voting" be a good way to design a language? Based on various languages that have gone through a committee type process, I'd have to say "god no". > So what would be the most effective way to notify the developers that > (I'm guessing) 90% of the Python community dislike the @ syntax and want > an other? As I've said (repeatedly) - this isn't a popularity contest. The point is to produce the best technical result. If you have a better solution, put together a case for it, and convince Guido. I'd also question how you can be so sure that "90% of the community dislike it" - over on python-dev, there's been quite a number of people who've actually tried the syntax, and found it to be quite good. This includes me - when I first saw it, I recoiled, but after using it, I find it pretty good. Please, please - download a2. Try the decorator syntax out (or look at test_decorators, or the hopefully-finished-with-the-rewrite-soon PEP318 (which I'll also post here) for examples. Anthony From justin__devine at hotmail.com Wed Aug 11 10:29:36 2004 From: justin__devine at hotmail.com (JDevine) Date: 11 Aug 2004 07:29:36 -0700 Subject: calling an event from within a program Message-ID: Can someone tell me the proper syntax to create an event from within a program here is my example code. I have Checkboxes and Radioboxes operating on the same Text Control. What I want is when the Checkbox is unchecked for the EVT_RADIOBOX evt to run therefore populating the text control with the value that was left on it when it was disabled. So what I really want to do is run a EVT_RADIOBOX from a checkbox. any suggestions? def EvtCheckBox3(event): print ck3.GetValue() if ck3.GetValue() == True: t2.Clear() t2.SetValue("blah blah") t2.SetEditable(False) ck1.SetValue(False) ck2.SetValue(False) rb.Enable(False) else: t2.Clear() t2.SetValue("blah blah blah") t2.SetEditable(True) rb.Enable(True) ck3 = wx.CheckBox(self, -1, "blah blah blah", (255, 60), (170, 20), wx.NO_BORDER) self.Bind(wx.EVT_CHECKBOX, EvtCheckBox3, ck3) #Create a radio box def EvtRadioBox(event): print event.GetInt() if event.GetInt() == 0: t2.Clear() t2.SetValue("Blah Blah Blah") t2.SetEditable(True) elif event.GetInt() == 1: t2.Clear() t2.SetValue("blah blah blah") t2.SetEditable(False) elif event.GetInt() == 2: t2.Clear() t2.SetValue("blah blah blah") t2.SetEditable(False) ............and elif for each position in the radiobox and finally creating the radiobox and the binding sitelist = ['blah', 'ying', 'yang'] sizer = wx.BoxSizer(wx.HORIZONTAL) rb = wx.RadioBox( self, -1, "My Radiobox", (10, 215), (425, 70), sitelist, 5, wx.RA_SPECIFY_COLS ) self.Bind(wx.EVT_RADIOBOX, EvtRadioBox, rb) From rnichol_rrc at yahoo.com Sun Aug 8 23:55:17 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Sun, 08 Aug 2004 22:55:17 -0500 Subject: how many bytes in an int Message-ID: <9ACRc.1523$bJ2.9739@news1.mts.net> Hello, I was wondering if I could control how many bytes are in an int and the byte order. In C/C++ I can use int32 but how do I do this in python? How can I control byte order? From tmohr at s.netic.de Sun Aug 1 13:07:53 2004 From: tmohr at s.netic.de (Torsten Mohr) Date: Sun, 01 Aug 2004 19:07:53 +0200 Subject: read/write XML Message-ID: Hi, i just took a look into the python documentation regarding XML. XMLDOM look quite big, so i took another look at "minidom". So is minidom the preferred way to go to read an XML, handle its data and also write XML? In the example (13.7.2, SLideshow) the structure seems to be read into a "dom", but to check its structure against some criteria seems to be completely missing, e.g.: - only defined elements used - at least one slide in the slideshow - others ... How can i check a "dom" against these criteria? Best regards, Torsten. From grante at visi.com Mon Aug 9 10:36:14 2004 From: grante at visi.com (Grant Edwards) Date: 09 Aug 2004 14:36:14 GMT Subject: how many bytes in an int References: <9ACRc.1523$bJ2.9739@news1.mts.net> <4116f8ee$0$8076$a1866201@newsreader.visi.com> <41170cd1$0$8076$a1866201@newsreader.visi.com> <41171116$0$8079$a1866201@newsreader.visi.com> <41172C9A.2020301@jessikat.fsnet.co.uk> Message-ID: <41178bde$0$8077$a1866201@newsreader.visi.com> On 2004-08-09, Robin Becker wrote: > Grant Edwards wrote: >> On 2004-08-09, Grant Edwards wrote: >> >> >>>The struct module is the only thing I know about. If you're >>>worried about the "C" types in the struct module changing >>>underneat you, you could do a pure Python implimentation of >>>"python-int" to/from DWORD. It's utterly trivial and shouldn't >>>take more than one or two lines of code. >> >> >> def toLittleEndianDWORD(i): >> return ''.join(map(chr,[x&0xff for x in [i,i>>8,i>>16,i>>24]])) >> >> def fromLittleEndianDWORD(s): >> return ord(s[0]) + (ord(s[1])<<8) + (ord(s[2])<<16) + (ord(s[3])<<24) >> > > this simple code will give warnings in 2.3, > I think struct is really needed. Like the man said, "struct" doesn't convert to-from integers of specified byte lengths. All it has are the C types "int" "long" "long long", etc. There is no portable way using struct to request a 4-byte integer. > >>> toLittleEndianDWORD(-1) > '\xff\xff\xff\xff' > >>> fromLittleEndianDWORD(toLittleEndianDWORD(-1)) > __main__:2: FutureWarning: x< a long in Python 2.4 and up > -1 Hopefully that can be fixed? Python integer objects seem to get more difficult to work with every year. ;) A few weeks back, somebody posted code for fixed length Python integer objects. -- Grant Edwards grante Yow! YOU PICKED KARL at MALDEN'S NOSE!! visi.com From matt at downwithspammers-mengland.net Mon Aug 16 19:00:49 2004 From: matt at downwithspammers-mengland.net (Matt) Date: Mon, 16 Aug 2004 18:00:49 -0500 Subject: GNU Mailman on Windows XP testing machine? Message-ID: Hello, I'm trying to hack up a GNU Mailman (and other stuff--XAMPP, phpbb, Moodle, postNuke, mail server, etc) configuration on my laptop as a testing/staging area for my srever with the same stuff. So far I'm able to get everything to work ok (even the mail server with Mercury Mail packaged in XAMPP) except for the GNU Mailman stuff. I can build it ok but I'm having trouble getting the mailman account to login properly and some other stuff (that seems minor). Before I proceeded further, I thought I would post here to see if anyone else has had experience doing this?? fyi: I'm using the following instructions (they seem to be a little outdated for Mailman 2.1.5) for Mailman installation on Windows: http://www.python.org/cgi-bin/faqw-mm.py?req=show&file=faq05.002.htp Note also that the instructions are for Windows 2000 and not Win XP. Also note that I'm trying to use Apache (from XAMPP) instead of Windows IIS web server. -Matt -- Remove the obvious text (including the dash) to email me. From Scott.Daniels at Acm.Org Tue Aug 31 18:10:46 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 31 Aug 2004 15:10:46 -0700 Subject: What GCC version had defined? In-Reply-To: <4130b79a$1@nntp0.pdx.net> References: <412e39d1$1@nntp0.pdx.net> <412E55A9.9070400@v.loewis.de> <412e70d3$1@nntp0.pdx.net> <412eca05$0$24800$9b622d9e@news.freenet.de> <4130b79a$1@nntp0.pdx.net> Message-ID: <4134f8c0$1@nntp0.pdx.net> I've submitted patch # 1020042 for this problem. From paddy3118 at netscape.net Tue Aug 17 15:23:40 2004 From: paddy3118 at netscape.net (Paddy McCarthy) Date: 17 Aug 2004 12:23:40 -0700 Subject: How big can a Python program be? References: <903b3fba.0408170333.49ce3944@posting.google.com> Message-ID: <2ae25c6b.0408171123.6e0f4a71@posting.google.com> vronskij at post.sk wrote in message news:<903b3fba.0408170333.49ce3944 at posting.google.com>... > Hi, > > A C program can be hundreds of thousands lines of code big. > C++ millions. > > How about Python? > > Suppose , you are a sole programmer (lonewolf). How many lines can one handle? > > Thanks, > > > jan bodnar Well, heres my quarter-million line Python 'Program' executing pad at Williams-McCarthy:/tmp$ python -c 'print "x=0" for i in xrange(2**18):print "x+=",`i` print "print x"' > silly.py pad at Williams-McCarthy:/tmp$ wc -l silly.py 262146 silly.py pad at Williams-McCarthy:/tmp$ nice python silly.py 34359607296 It did start to swap but didn't take too long to finish on my 256Meg Debian Linux, Athlon 1470MHz machine :-) Pad. From Scott.Daniels at Acm.Org Thu Aug 19 12:18:02 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 19 Aug 2004 09:18:02 -0700 Subject: age of Python programmers In-Reply-To: References: Message-ID: <4124d4a4$1@nntp0.pdx.net> Mike Brenner wrote: > I was born about 10,000 years ago and I used to > program computers made of human beings who > were aligned in tiers. The bottom tier counted > the grains in the baskets. The next tier > counted the baskets in the barn, then the > number of brans in each country. > Don't laugh. I met a woman roughly my age (53 now) whose mother was a programmer at los Alamos (or was it Trinity?) -- she programmed rooms of people running mechanical calculators (calculate this, if a > b, pass your results right, otherwise, ...) Scott David Daniels Scott.Daniels at Acm.Org From firemoth at gmail.com Sat Aug 14 14:32:22 2004 From: firemoth at gmail.com (Timothy Fitz) Date: 14 Aug 2004 11:32:22 -0700 Subject: Generators versus Coroutines Message-ID: <972ec5bd.0408141032.385fe115@posting.google.com> It seems to me that in python, generators are not truly coroutines. I do not understand why. What I see is that generators are used almost exclusively for generation of lists just-in-time. Side effects are frowned upon. Coroutines, in contrast, are like split functions where side effects are often as important or more important than return values. I am currently writing a real time strategy game where I have visual effects and use generators as coroutines which yield after processing a single frame of the effect. I can easily make an object rotate indefinitely with a scant four or five lines of code, all of which is in one place. So knowing that the difference between a generator and a coroutine is minor, I come (in a very roundabout way) to my issue. Why can I use "return" without an expression and it implicitly returns None but I can't do the same thing with "yield" ? From steven.bethard at gmail.com Thu Aug 5 12:53:09 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: 5 Aug 2004 09:53:09 -0700 Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) References: <1646998998.20040804190026@MailBlocks.com> Message-ID: Istvan Albert wrote in message news:... > I always felt that Java was too rigid and that any kind > of loosening feels like a breath of fresh air. Yeah, I felt the same way. I really like that Python hasn't been deathly afraid of backwards incompatibility, at least when it was minor and introducing the backwards incompatibility made the language cleaner and more powerful. The whole @ syntax reminds me of Java's : syntax for their enhanced for-loop. From http://java.sun.com/developer/technicalArticles/releases/j2se15langfeat: "Many developers are asking why they didn't add the foreach and in so that we can write: foreach (element in collection) The fact of the matter is that adding new keywords to a language such as Java is quite costly. In addition, it wouldn't be compatible with existing source code that uses the in keyword, for example, as in System.in. So the whole idea is just to keep things upwardly-compatible." These are, of course, the standard reasons against introducing new keywords, and the same reasons that Python tries not to introduce them unnecessarily. Still, I think, for example, the 'yield' generator syntax (which was introduced relatively recently) is much clearer than doing something strange with punctuation would have been. I guess I just don't see why decorators merit strange punctuation when generators didn't... (Notice that if Java's 'foreach' discussion came up in Python -- assuming Python didn't already have the 'for' construction -- the 'foreach' keyword would probably have been added without hesitation because it would be quickly deemed a very minor backwards incompatibility.) Steve From squirrel at WPI.EDU Thu Aug 12 11:48:02 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 12 Aug 2004 11:48:02 -0400 Subject: Verbosity Check Style In-Reply-To: References: Message-ID: On Thu, 12 Aug 2004 brianc at temple.edu wrote: > I would like to get people's views on the best way to > implement verbosity (or any command-line option) into python > scripts. I'd suggest one of the following: 1) Use a dedicated verbose() function. This will likely be the fastest and cleanest method: if VERBOSE: def verbose(t): print t else: def verbose(t): pass verbose("I'm doing something here") 2) Use a dedicated verbose file handle. This is as fast as and possibly (depending on your taste) cleaner than the above method: import sys # Pythonic version of /dev/null class devnull(object): def write(self,d): pass if VERBOSE: verbose = sys.stdout else: verbose = devnull() print >>verbose, "I'm doing something here" Hope this helps. From tim.leslie at gmail.com Thu Aug 26 12:27:00 2004 From: tim.leslie at gmail.com (Tim Leslie) Date: Fri, 27 Aug 2004 02:27:00 +1000 Subject: Fun transformation problem In-Reply-To: <2p69vfFh7vf6U1@uni-berlin.de> References: <2p69vfFh7vf6U1@uni-berlin.de> Message-ID: This is what I came up with. It's recursive, so it could get you into trouble with longer lists, but hey, it's late at night and it'll do for now :-) def g(d, lst): head = lst[0] tail = lst[1:] if not tail: return head else: d[head] = g(d.get(head, {}), tail) return d def f(lst): d = {} for xs in lst: d = g(d, xs) return d Cheers, Tim On Thu, 26 Aug 2004 18:20:23 +0400, anton muhin wrote: > > > Dale Strickland-Clark wrote: > > A guy in the office has come up with this interesting transformation > > problem. We have a solution but I'm sure there's a neater, more 'pythonic' > > approach. > > > > I thought this might appeal to some here: > > > > I want a function to convert a list of tuples into a hierarchy of > > dictionaries. Let me first demonstrate with an example: > > > > > >>>>lstA = [(1, 2, 3), (1, 3, 4), (2, 5, 6)] > >>>>dctA = fncA(lstA) > >>>>print dctA > > > > {1: {2: 3, 3: 4}, 2: {5: 6}} > > > > > > I essentially want the definition to fncA. Here is another example: > > > > > >>>>lstA = [(1, 2, 3, 4) ,(3, 4, 5, 6), (3, 4, 6, 7), (3, 4, 6, 8), (3, 4, > > > > 5, 1), (3, 4, 7, 9)] > > > >>>>dctA = fncA(lstA) > >>>>print dctA > > > > {1: {2: {3: 4}}, 3: {4: {5: 1, 6: 8, 7: 9}}} > > > > > > Each tuple in the original list must be unique after the last value is > > excluded (since these values are used to form the "hierarchical key". > > > > I have written a function, which seems to work but looks very cumbersome. > > Could anyone point me to a simpler solution? > > > > > > > > Dale Strickland-Clark > > Riverhall Systems > > The following: > > def transform(l): > d = {} > > for t in l: > c = d > for e in t[:-2]: > c = c.setdefault(e, {}) > c[t[-2]] = t[-1] > > return d > > seems clear enough for me. > > with the best regards, > anton. > > > -- > http://mail.python.org/mailman/listinfo/python-list > From unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom Fri Aug 6 13:13:56 2004 From: unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom (Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.) Date: Fri, 6 Aug 2004 19:13:56 +0200 Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) References: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> Message-ID: ;o) From sbabbitt at commspeed.net Fri Aug 27 16:19:23 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Fri, 27 Aug 2004 13:19:23 -0700 Subject: tarfile's tar.extractfile() file-like object incompatible with pickle.load()? References: <3e6d6c21.0408261043.264c3a2d@posting.google.com> <1093572564.733113@news.commspeed.net> <3e6d6c21.0408271000.6007a361@posting.google.com> Message-ID: <1093638479.693481@news.commspeed.net> "Matt Doucleff" wrote in message news:3e6d6c21.0408271000.6007a361 at posting.google.com... > "Tom B." wrote in message news:<1093572564.733113 at news.commspeed.net>... > > "Matt Doucleff" wrote in message > > news:3e6d6c21.0408261043.264c3a2d at posting.google.com... > > > Hi everyone! I must be doing something wrong here :) I have a > > > tarball that contains a single file whose contents are a pickled > > > object. I would like to unpickle the object directly from the tarball > > > using the file-like object provided by extractfile(). Attempts to do > > > this result in EOFError. However if I first extract to a temporary > > > file, then unpickle from there, it works. The below code reproduces > > > the problem (on my machine at least). I'm running Python 2.3.4, > > > manually installed on Debian Woody (original python removed). Thanks! > > > > > > This sample code creates (and then removes) files in the tmp directory > > > and in the current working directory. > > > > > > # demonstrates extractfile/unpickle failure (bug?) > > > > > > # pickle a dict to a temp file > > > # create tar file, add temp file to it, close tar file > > > # open tar file for reading > > > # obtain file-like object for pickled file using extractfile() > > > # attempt to unpickle dict from file-like object > > > # fails with EOFError exception > > > > > > import tarfile > > > import pickle > > > import tempfile > > > import os > > > > > > if __name__ == '__main__': > > > try: > > > hashtopickle = { 'a' : 1, 'b' : 2 } > > > > > > # pickle to temp file > > > (fd, tmpfilename) = tempfile.mkstemp() > > > tmpfile = os.fdopen(fd, 'w') > > > pickle.dump(hashtopickle, tmpfile) > > > tmpfile.close() > > > > > > # create tar; add temp file > > > tar = tarfile.open('tarpickle.tar', 'w') > > > tar.add(tmpfilename, 'pickledhash') > > > tar.close() > > > > > > # remove temp file > > > os.remove(tmpfilename) > > > > > > # open tarfile for reading, get filelike > > > tar = tarfile.open('tarpickle.tar', 'r') > > > > filelike = tar.extractfile('pickledhash') > > > > > > # fails > > > hashcopy = pickle.load(filelike) > > > > > > finally: > > > # cleanup > > > os.remove('tarpickle.tar') > > > > It occurs to me that you need to do, > > > > hashcopy = pickle.loads(filelike) > > > > if filelike is a string. > > > > Tom > > P.S. have a look at pickle.dumps() > > The tarfile.extractfile() method does not read the contents > of the encapsulated file into a string, but constructs a new > object that implements file operations (it is like a file) > and is intended to be used as if you had simply opened the > tar-encapsulated file directly. > > Matt How about, filelike = tar.extractfile('pickledhash') filetext = filelike.read() hashcopy = pickle.load(StringIO.StringIO(filetext )) Tom From pm_mon at yahoo.com Wed Aug 11 15:34:44 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Wed, 11 Aug 2004 15:34:44 -0400 Subject: Rather than decorators, how about sections? In-Reply-To: <411a6b9d$0$13688$636a15ce@news.free.fr> References: <1C74C038-EBB6-11D8-8889-000A95857E5C@eischet.com> <411a6b9d$0$13688$636a15ce@news.free.fr> Message-ID: Christophe Cavalaria wrote: > Paul Morrow wrote: > > >>>class Foo(object): >>> def spam(Foo): >>> print "Class Method" > > > What is that ? It's ugly, it's a name alias and it'll be incredibly > confusing when classmethods are inherited, which is exactly the most common > use case for classmethods. > Fine, instead of Foo (the name of the class), use the word klass. It's a popular name for the first parameter of a class method. > >>I like it! It's simple, clear, ... Why isn't this the hands-down best >>solution? Why do we want to be more verbose than necessary? > > > It isn't a solution. It only "resolves" the problem for staticmethod and > classmethod which are only a very small part of what we do/want to do with > decorators. > What we want to do with decorators, it appears, is to clutter up our code with declarations, some of which are just pragmas. I thought we liked dynamic declarations (where it's obvious what's going on, as it would be here). > > Well, it might seem strange but : > - It will break a lot of code which use a name different than self for the > first argument > - It'll break all existing classmethods > - It'll break code that binds arbitrary functions as a member function. You > can't do things like that anymore : > > >>>>def f(s): >>>> print "Hi, I'm function f" >>>>class Klass: >>>> doIt = f >>>>Klass().doIt() > > Breaking existing code is not necessarily a bad thing. If you worry too much about it, you end up with a real mess of a language. One that's hard to read/write/understand. To a junior pythonista, in your example, the way you chose 's' as the argument name, f looks like it might be a static method. It would have been more clear to use 'self' instead. So I think that dropping the decoration syntax for class and static methods, and instead requiring that we use a particular naming convention for their 1st arguments, we not only improve the readibility of our code (less arcane syntax), but the correctness of our reader's expectations as well. From ben at benlast.com Sat Aug 28 16:03:01 2004 From: ben at benlast.com (Ben Last) Date: Sat, 28 Aug 2004 21:03:01 +0100 Subject: Dynamic languages In-Reply-To: <1093718996.482485@news.commspeed.net> Message-ID: > From Tom B. > I figured that I wouldn't be able to find any truly dead computer > language. I met a technician at U of Minnesota Physics department who > collected PDP11's and programmed only in fourth. When I asked him why he > replied, 'If I don't do it who will'. When a language is new, there's no money in programming it; nobody uses it. When a language is on the up, there's money, but everybody's learning it. When a language is the current Big Idea, there's no money in it; everyone uses it. When a language is dying, there's no money in it, everyone's getting out. When a language is all but dead, and a company has large amounts of software written in it, and you're one of the very few who can still programme in it... there's BIG money. Such is the justification of the few COBOL programmers I know of. b From iketo2 at netscape.net Sat Aug 28 09:45:04 2004 From: iketo2 at netscape.net (Isaac To) Date: 28 Aug 2004 21:45:04 +0800 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> <87hdqok9i6.fsf@sinken.local.csis.hku.hk> <1rfz68ely9.fsf@rovereto.ifi.uio.no> <876574k7du.fsf@sinken.local.csis.hku.hk> <1r3c28ejis.fsf@rovereto.ifi.uio.no> <5MWXc.228027$ht5.11749427@phobos.telenet-ops.be> <1rhdqnd3rm.fsf@rovereto.ifi.uio.no> <1r8ybzcs7v.fsf@rovereto.ifi.uio.no> Message-ID: <873c27tlzz.fsf@sinken.local.csis.hku.hk> >>>>> "Kjetil" == Kjetil Torgrim Homme writes: Kjetil> I think it's harder to spot the bug here than in my Python Kjetil> example. this doesn't mean Python can't be improved Kjetil> further :-) -- Kjetil T. I don't think your proposal to throw { and } into the code will solve the problem and make it easier, though. Regards, Isaac. From mksql at yahoo.com Tue Aug 10 11:11:15 2004 From: mksql at yahoo.com (Max) Date: 10 Aug 2004 08:11:15 -0700 Subject: Secure storage for passwords for admin scripts? Message-ID: I have a collection of system admin scripts (on Win 2k) that I would like to automate the execution of. However, some of them require the use of logins with admin rights, and would therefore prefer not to store the IDs in the clear text of the source. If memory serves correctly, the "compiled" .pyc files do not provide much security in this area. Are there are recommended methods for supplying scripts with login information in a secure fashion? From kowald at molgen.mpg.de Mon Aug 16 11:59:56 2004 From: kowald at molgen.mpg.de (Axel Kowald) Date: 16 Aug 2004 08:59:56 -0700 Subject: Tkinter buttons with image ? References: Message-ID: <9b5e8d9.0408160759.2be1be76@posting.google.com> > Using the image in Tkinter will not keep it from being garbage-collected. > You need to keep a reference to the image, either in a global variable or > like so: > > buttonStart = Button(frameWb, image=tmp, command=root.quit) > buttonStart.image = tmp Ah, that's the trick. Many thanks, Axel From nelson at monkey.org Wed Aug 4 19:50:54 2004 From: nelson at monkey.org (Nelson Minar) Date: Wed, 04 Aug 2004 23:50:54 GMT Subject: Modern dead-tree Python resources References: Message-ID: Like others, I like Python in a Nutshell. Dive into Python is a new book out by an excellent author http://diveintomark.org/archives/2004/07/18/dive-into-python You can read it online too: http://diveintopython.org/ From richie at entrian.com Fri Aug 20 10:39:04 2004 From: richie at entrian.com (Richie Hindle) Date: Fri, 20 Aug 2004 15:39:04 +0100 Subject: Newbie to XML in Python In-Reply-To: References: Message-ID: [Jens] > XML in Python doesn't seem easy or intuitive. All I need to do, is to > interpret a small piece of XML in which I store data for the contents of > an autorun menu. What is the quickest/most effective way to do this? You're probably looking for an "XML data binding" rather than a SAX or DOM implementation. I've had good results with XML_Objectify - see http://www.xml.com/pub/a/2003/07/02/py-xml.html Another option, which I've never used, is Anobind - http://uche.ogbuji.net/tech/4Suite/anobind/ If your XML might not be well formed, Beautiful Soup is a good choice - http://www.crummy.com/software/BeautifulSoup/ -- Richie Hindle richie at entrian.com From http Wed Aug 25 03:59:04 2004 From: http (Paul Rubin) Date: 25 Aug 2004 00:59:04 -0700 Subject: with as J2 keyword (WAS: Re: J2 0-2-6 is available) References: <7xr7pvsp3i.fsf@ruckus.brouhaha.com> Message-ID: <7xeklvvebb.fsf@ruckus.brouhaha.com> Steven Bethard writes: > > ::classmethod > > ::funcattrs(author="Fran????ois Pinard") > > def foo(cls): > > pass > > > Well, a double colon isn't valid decorator syntax, so it wouldn't be > good for me to present examples of decorator usage in that form... > Maybe I misunderstand you? Or maybe you're using a quote from me > out of context? I'm confused... I just mean ::pie might be a decent alternative to @pie. From dhansteen at hotmail.com Mon Aug 9 13:42:46 2004 From: dhansteen at hotmail.com (Dag Hansteen) Date: Mon, 9 Aug 2004 19:42:46 +0200 Subject: Question Message-ID: >>> s = "2+2" >>> answer = int(str(s)) Traceback (most recent call last): File "", line 1, in ? answer = int(str(s)) ValueError: invalid literal for int(): 2+2 How do I this ? I have a string with a such expression and I want to return the answer in a variable. Regards Dag Hansteen -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark_bottjer at hotmail.com Fri Aug 6 20:26:38 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Fri, 06 Aug 2004 20:26:38 -0400 Subject: PEP-0318 In-Reply-To: References: <41122FC2.1080608@interlink.com.au> <4114152f@nntp.zianet.com> Message-ID: <411421bf@nntp.zianet.com> Roy Smith wrote: > Mark Bottjer wrote: >> * 0 Perhaps decorators should be allowed before or after the >> docstring. If you have to choose, I'd choose making it before >> the docstring. > > It's a pretty arbitrary decision (i.e. I can't see any strong arguments > one way or the other) which means it's the kind of thing which is likely > to not be remembered. I think I'm with you, decorators come first, then > the docstring. But pick one and stick with it, so everybody does it the > same way. I agree that it is arbitrary. I horked the text from one of the other sections, as I thought that it applied here as well. >> * - Lots of decorators will make it harder to find the start of the >> function implementation. Then again, so will a large docstring. > > Do people anticipate having lots of decorators for a given function? The way they've been talking, it would appear so. I'm routinely hearing a bunch of different things people want to use this syntax for: staticmethod/classmethod, argument type assertion, DBC, synchronization, metadata such as author, and framework callback registration, just to name a few. -- Mark From peter at engcorp.com Thu Aug 5 14:30:31 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 05 Aug 2004 14:30:31 -0400 Subject: Confused about pep 318 In-Reply-To: References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: Anthony Baxter wrote: > On Thu, 05 Aug 2004 13:29:29 -0400, Peter Hansen wrote: > >>I'll make another donation to PSF if the final decorator syntax >>does not Perlishly use arbitrary punctuation as the @ syntax does. > > FFS. What exactly is "Perlish" about @? It's an unused symbol. That's all. "For Fucks Sake", presumably? Sorry you're feeling pressured by this... Anyway, that is exactly what is Perlish about it. Perl takes pretty much every unused symbol and finds some completely arbitrary way to use them, just because they are there. So far, Guido has avoided that (almost?) entirely in Python, using symbols that have very well-established meanings in other computer languages and even outside of the computer realm itself (e.g. the use of colon). It surprises me that he didn't discard this choice out of hand. I'm also surprised that the choice which had the greatest public support during the straw poll at PyCon isn't still under discussion, but I readily admit I'm neither following nor participating in the pydev discussions where it was presumably dropped for some valid reason... -Peter From in.aqua.scribis at nl.invalid Mon Aug 30 16:31:59 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Mon, 30 Aug 2004 22:31:59 +0200 Subject: "Content-Length" header In-Reply-To: References: Message-ID: Justin schreef: > (THIS DOESN't) > for y in linklisttype: > x = y > temp = urlopen(x) > print temp > temp2 = temp.info() > print temp2 > temp3 = temp2.getheader("Content-Length") > print temp3 You need to indent the lines following the 'for' statement. -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From fumanchu at amor.org Mon Aug 23 13:34:41 2004 From: fumanchu at amor.org (Robert Brewer) Date: Mon, 23 Aug 2004 10:34:41 -0700 Subject: Standard graph API? Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E44@exchange.hqamor.amorhq.net> > Is there any interest in a (hypothetical) standard graph API (with > 'graph' meaning a network, consisting of nodes and edges)? 1) Yes! 2) Only if it's in C. I don't mind (re)writing pure Python graph containers, it's the speed of a pure Python graph that's the bigger issue to me (mostly object inspection and/or decorate-insert-retrieve-undecorate cycles). If it started in a pure-Python package, then went into the stdlib, and then got a C implementation (like sets.py did), that would be fine. 3) It would have to accept arbitrary objects. No "make your class a subclass of GraphNode" garbage. If someone wanted to make a subclass of Graph called StringGraph, which was optimized for strings, or IntGraph optimized for ints, that would be fine. But the base class (I assume a class implementation?) should handle instances of Object. I'm sure there are many more details, but those are the big ones IMO. Robert Brewer MIS Amor Ministries fumanchu at amor.org From dropthis_fanmail at micah-wedemeyer.net Wed Aug 25 14:30:52 2004 From: dropthis_fanmail at micah-wedemeyer.net (Micah) Date: Wed, 25 Aug 2004 14:30:52 -0400 Subject: using windows defaults for executing/examining files References: Message-ID: Using wxPython, is there any way to get the icon associated with a file? I want to be able to display the icon, then when it's double clicked, it executes the file (using os.startfile ) Micah "Diez B. Roggisch" wrote in message news:cgikd2$bnb$02$1 at news.t-online.com... > Micah wrote: > > > Is there an os module call to request that Windows handle a specific file > > using the default handler? For example, if I pass it a .txt file it opens > > notepad but if I pass a .wav file it opens Windows Media Player. > > os.startfile() > > -- > Regards, > > Diez B. Roggisch From tdelaney at avaya.com Sun Aug 29 20:50:40 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Mon, 30 Aug 2004 10:50:40 +1000 Subject: allowing braces around suites Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01DCFF0B@au3010avexu1.global.avaya.com> Kjetil Torgrim Homme wrote: > when I provide four lines of code and tell you there's a bug, of > course you can spot it immediately. when it's part of a large system, > it's a bit harder. also consider that the db.commit() originally was > correctly placed by the programmer, and the wrong indentation was > introduced later by an editing glitch. This is why you need a comprehensive unit test suite. Such a suite would reveal that non-students were not getting committed. Tim Delaney From in.aqua.scribis at nl.invalid Mon Aug 30 15:27:35 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Mon, 30 Aug 2004 21:27:35 +0200 Subject: Size of a remote URL In-Reply-To: References: Message-ID: Justin schreef: > http://www.google.com/search?hl=en&lr=&ie=UTF-8&safe=off&output=search&num=5&q=temp+filetype%3Adoc > > Go to that URL. The first two search results do not return a > Content-Length Header. Yet IE still knows how big they are somehow, > whereas my code doesn't. Look again: ~ lwp-request -m HEAD 'http://www.ecs.soton.ac.uk/~harnad/Temp/Ariadne-RAE.doc' 200 OK Connection: close Date: Mon, 30 Aug 2004 19:26:01 GMT Accept-Ranges: bytes ETag: "f10f630-9a800-3ea2ba8e" Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12 OpenSSL/0.9.6b DAV/1.0.3 PHP/4.3.2 mod_perl/1.26 Content-Length: 632832 Content-Type: application/msword Last-Modified: Sun, 20 Apr 2003 15:19:42 GMT -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From me at privacy.net Thu Aug 19 11:11:42 2004 From: me at privacy.net (Richard Hanson) Date: Thu, 19 Aug 2004 08:11:42 -0700 Subject: age of Python programmers References: Message-ID: <7re9i095r921mmgemacgn24rp0h7ijdun4@4ax.com> Mike C. Fletcher wrote: >It's so much more efficient to just make up the statistics. Not *that's* a quote! :-) thread-enjoyingly y'rs, Richard -- R Hanson [The mangled email addie below works.] sickolefartnewsguycom From ivoras at __-geri.cc.fer.hr Mon Aug 16 18:18:52 2004 From: ivoras at __-geri.cc.fer.hr (Ivan Voras) Date: Tue, 17 Aug 2004 00:18:52 +0200 Subject: Editors again Message-ID: Are there any editors besides IDLE that can display doc-strings[*] in popups? I tried SPE and DrPython, and while they are ok (better said 'not horribly bad'), they don't seem to have that option. I'd like to see in an editor: - code-completion in case of functions, member variables etc. ("intelli-sense"? :) ) - useful usage of doc-strings, maybe integrated python Help/Manual support - MDI or similar style, with good navigation (this is why I don't like IDLE) Actually, SPE is pretty close, but auto-completion seems to behave 'funny' sometimes, and no doc-string support I can see... [*] Maybe I misnamed them. I was thinking of: def f(): """This is a doc-string""" pass From jdhunter at ace.bsd.uchicago.edu Fri Aug 6 16:08:19 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Fri, 06 Aug 2004 15:08:19 -0500 Subject: Plotting histograms, scatter plots in Python In-Reply-To: (DrColombes@yahoo.com's message of "6 Aug 2004 11:18:40 -0700") References: Message-ID: >>>>> "Colombes" == Colombes writes: Colombes> What is the easiest way to generate some plots and Colombes> graphs in Python ? Specifically interested in simple Colombes> histograms and scatter plots with circles and regression Colombes> lines. Here's a little example of a histogram and regression plot using matplotlib - looks easy enough to me! Output image at http://nitace.bsd.uchicago.edu:8080/files/share/demo.png from matplotlib.matlab import * x = randn(10000) # some gaussian noise subplot(211) # a subplot hist(x, 100) # make a histogram grid(True) # make an axes grid ylabel('histogram') # now do the regression... x = arange(0.0, 2.0, 0.05) y = 2+ 3*x + 0.2*randn(len(x)) # y is a linear function of x + nse # the bestfit line from polyfit m,b = polyfit(x,y,1) # a line is 1st order polynomial... # plot the data with blue circles and the best fit with a thick # solid black line subplot(212) plot(x, y, 'bo', x, m*x+b, '-k', linewidth=2) ylabel('regression') grid(True) # save the image to hardcopy savefig('demo') show() From tim.hochberg at ieee.org Mon Aug 16 20:14:57 2004 From: tim.hochberg at ieee.org (Tim Hochberg) Date: Mon, 16 Aug 2004 17:14:57 -0700 Subject: Python indentation deters newbies? In-Reply-To: <41214271_1@127.0.0.1> References: <3064b51d.0408130615.3fc4a760@posting.google.com> <41214271_1@127.0.0.1> Message-ID: beliavsky at aol.com wrote: > Jorge Godoy wrote: > > >>Just an attempt and trying to keep it like your code. > > > Thanks. My code did not correctly illustrate breaking out of more than one > level of loop. How would the following code be translated to Python? > It is silly of course, but real-world situations where you want to exit a > nested loop are not that rare. > > program xnest_loop > ! illustrate breaking a nested loop > integer :: i,j,k,n > n = 4 > ido: do i=1,n > jdo: do j=1,n > if (i+j > n) exit ido > do k=1,n > if (i+j-k < 0) exit jdo > print*,i,j,k > end do > end do jdo > end do ido > end program xnest_loop Hmmm. I've never run into a case where the loop logic is that nasty. And, as it turns out, even the above isn't that nasty if you stare at it a minute, it can be coded without break/exit at all. So this is how I'd code it <0.5 wink>: n=4 for i in range(1,n): for k in range(1,i+2): print i, 1, k Of course this just dodges your point, but I can't be made to care unless you convince me that I'm likely to run into something like this in practice. -tim > > output: > 1 1 1 > 1 1 2 > 2 1 1 > 2 1 2 > 2 1 3 > 3 1 1 > 3 1 2 > 3 1 3 > 3 1 4 > > > > > ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- > http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups > ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--- From pm_mon at yahoo.com Wed Aug 18 18:50:59 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Wed, 18 Aug 2004 18:50:59 -0400 Subject: PEP 318: Can't we all just get along? In-Reply-To: References: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: Michael J. Fromberger wrote: > In article , > Paul Morrow wrote: > > >>Michael J. Fromberger wrote: >> > >>And if you ask experienced Python developers who understand the >>difference between class, static, and instance methods, to guess what >>kind of method this is... >> >> def foo(cls, a, b): pass >> >>...I bet the majority would correctly guess "class". > > > Well, given just that definition, the guess would be incorrect. The > current release of Python would also require: > > def foo(cls, a, b): pass # As defined above > foo = classmethod(foo) > > Otherwise, it would be an instance method, not a class method. I hope > this illustrates why visual conventions are not always as obvious as > they seem, and should not be cast into the concrete of implementation. > Actually, it illustrates the importance of proof-reading a post before posting it, which I didn't (sorry). I should've also stated that the Python developers would be told that this is a special version of Python that automatically determines the type (static|class|instance) of a method. In that light, do you see how effective the visual convention can be? > >>Declarations aren't needed when an obvious interpretation of the code >>conveys the desired meaning. > > > What about when the obvious interpretation of the code does NOT convey > the desired meaning? > Then we have a bad convention. One that I would absolutely agree should not be enforced by the system. But that's not the case here. I believe that the obvious interpretation of code written with this convention would consistently and reliably convey the authors intent: * If method's first param is 'self', it's an instance method. * If method's first param is 'cls' or 'klass', it's a class method. * All other methods are static methods. From http Sat Aug 28 16:28:53 2004 From: http (Paul Rubin) Date: 28 Aug 2004 13:28:53 -0700 Subject: Generator expressions v/s list comprehensions References: <1gj8y77.6qshr41q531veN%aleaxit@yahoo.com> Message-ID: <7xbrgvuhve.fsf@ruckus.brouhaha.com> Mahesh Padmanabhan writes: > I am still not clear of the advantages of using generator expressions > (other than less memory consumption) Why do you think using bounded rather than unbounded amounts of memory is an insignificant advantage? From elainejackson7355 at home.com Mon Aug 16 19:54:10 2004 From: elainejackson7355 at home.com (Elaine Jackson) Date: Mon, 16 Aug 2004 23:54:10 GMT Subject: music resources Message-ID: Is there such a thing as an executable language for music? If not, why not? And if yes, where can I find it? Naturally the ideal thing would be if such a language were implemented within python, but I would be willing to learn a lesser programming language if I had a reasonable assurance that it had what I'm looking for. I have, of course, googled for a solution, and I may have even found it, but if so I didn't recognize it as such. Any pointers will be mucho appreciado. Peace From sandysj at juno.com Fri Aug 20 16:26:15 2004 From: sandysj at juno.com (Jeff Sandys) Date: Fri, 20 Aug 2004 20:26:15 GMT Subject: Fate of lambda, Functional Programming in Python... References: <412636D1.6070808@noaa.gov> Message-ID: <41265E67.A08409A6@juno.com> "Christopher A. Craig" wrote: > > "Jared Cohen" writes: > > > Agreed! I'm currently building a GUI in Tkinter, with event > > handlers and callbacks all over the place. The lambda form is an > > absolute MUST for this kind of thing! > > Nobody is talking about removing the ability to pass functions, just > the actual "lambda" form. > > You can still build a GUI by doing > > def spam(stuff): > def eggs(parrot): > return 5+parrot > return eggs > > You just can't do > > def spam(stuff): > return lambda foo: 5+parrot > > I can't think of a situation where you _really_ need the second > (and much more limited) form. How about this use of lambda? (from another post 'RE: How to sort this kind of list easily?' today) | > > Hi,all | > > I have a list like [(id,string),...],for example: | > > | > > [(1,'xxxxx'),(7,'ppppp'),(4,'gggggg'),...] | > > | > > I want to sort this list according to the id of each element. | > > After sorting,the list will become: | > > | > > [(1,'xxxxx'),(4,'gggggg'),(7,'ppppp')...] | > | > list.sort sorts tuples by first argument, then second &c. If you want | > a custom sort order, look at the decorate-sort-undecorate pattern. | | Or if you want to sort only on your Id, use a lambda: | l.sort(lambda x,y: cmp(x[0],y[0])) | | To force sorting on just the nth element of the tuples, replace 0 with | n in the above. | I think that lambda should be unlimited and expanded. It already has the colon, block delimiter, so allow lambda to be a multistatement and multiline indented block! Thanks, Jeff Sandys From michele.simionato at gmail.com Sat Aug 7 10:25:30 2004 From: michele.simionato at gmail.com (Michele Simionato) Date: 7 Aug 2004 07:25:30 -0700 Subject: dispatch tables in Python 2.4 Message-ID: <4edc17eb.0408070625.61a0624d@posting.google.com> A thing I always had in my wishlist was the ability to define dispatch tables in an elegant way. Currently, Python is butt ugly: def function_with_a_long_name_1(): "do this" def function_with_a_long_name_2(): "do that" dispatch_table = dict( function_with_a_long_name_1 = function_with_a_long_name_1, function_with_a_long_name_2 = function_with_a_long_name_2, ) Really horrible and error prone (especially for a poor typist like myself). With decorators I can do def add_to(lst): def closure(func): lst.append(func) return func return closure lst = [] @add_to(lst) def function_with_a_long_name_1(): "do this" @add_to(lst) def function_with_a_long_name_2(): "do that" dispatch_table = dict((f.func_name,f) for f in lst) #!generator-comprehension! With the advent of decorators I see myself using more and more closures. BTW, what's the status of the so called "functional" module? I think there was a rumor of such a module scheduled for Python 2.4 or 2.5. To play with decorators we really need some standard way to compose functions and to do partial application of arguments. Just my 2c, Michele Simionato P.S. decorators make also easy to abuse classes for making dispatch tables: class DispatchTable(object): @staticmethod def function_with_a_long_name_1(): "do this" @staticmethod def function_with_a_long_name_2(): "do that" But I somewhat prefer dispatch_table[function_name] over getattr(DispatchTable, function_name). From joe at schmoe.com Mon Aug 30 18:12:34 2004 From: joe at schmoe.com (John Doe) Date: Mon, 30 Aug 2004 22:12:34 GMT Subject: Search for AVI file? References: Message-ID: <9f97j05ddrq66lc8vrd7kb6usepmltptg7@4ax.com> On Mon, 30 Aug 2004 22:12:04 +0200, Peter Kleiweg wrote: >John Doe schreef: > >> I realise that this is not really a python question, but python's the >> only language I'd be comfortable trying to deal with this. >> >> What I need is to search a drive and find all the AVI format files >> that are NOT listed with the AVI extension. I'm looking over an old >> drive of mine from an old computer. I know the files were renamed >> with the wrong extension, but I know that they were originally AVI >> files. Can python do this for me? Any hints? Anybody have a link to >> something that would already do this? I appreciate any help. > >Use walk() to find all files. Open each file and read in the >first 12 bytes. The last four of those 12 bytes should be >'AVI ', if I'm not mistaken. Ah, os.walk() was exactly what I needed. By the time I read your response, I had found the 'AVI' signature, but did not know an easy way to get to all those files. Thank You. From ville at spammers.com Fri Aug 20 10:25:29 2004 From: ville at spammers.com (Ville Vainio) Date: 20 Aug 2004 17:25:29 +0300 Subject: Alternative decorator syntax decision !! IMPORTANT THREAD !! References: Message-ID: >>>>> "Paul" == Paul McGuire writes: Paul> I'm afraid I have to agree, the subject is a poor one. I Paul> noticed that yesterday as the responses were slow to come Paul> in. Something more on the order of "READ THIS - IT'S Paul> FREAKIN' IMPORTANT!" is surely warranted. Yup - for those just joining in, post somewhere in this thread, it involves voting that all pythonistas know & love (along with the associated grain of salt that goes with it here in pythonland). Instructions in the root message. -- Ville Vainio http://tinyurl.com/2prnb From me at privacy.net Mon Aug 9 22:49:26 2004 From: me at privacy.net (Dan Sommers) Date: 09 Aug 2004 22:49:26 -0400 Subject: @decorator syntax is sugar, but for what exactly? References: <10hg6rf5ck639cd@corp.supernews.com> Message-ID: On Mon, 09 Aug 2004 17:49:13 -0700, Jeff Shannon wrote: > Dan Sommers wrote: >> When I see f( x ), I think that f is a function bound by def (or an >> extremely close relative, such as class or staticmethod), and that I can >> grep for it somewhere, either in the source code or the library >> reference. I also think, rightly or wrongly, that f *was* bound, >> *before* I needed it, and *does not change over time*. >> >> When I see apply( f, x ), I think that f varies over time, and is some >> sort of a callback or plugin or whatever, and is *not* the name of an >> actual function bound by def. > Um, I think you're missing the point, here. The apply() has nothing to > do with whether func() is bound by def or by assignment -- both cases > given here are intended to allow the easy passing of variable argument > lists to functions. I think you're right: I have at least two issues all wound up together here. My background is such that if you need different argument lists, then you need different functions. It's amazing how flexible something as outwardly simple as apply can be. I will reduce my original notion to f( x ) screams "this is pretty much the same all the time," but apply indicates something more interesting. Thanks for being so patient with this old timer. :-) Dan -- Dan Sommers Never play leapfrog with a unicorn. From miki.tebeka at zoran.com Sun Aug 15 08:31:06 2004 From: miki.tebeka at zoran.com (Miki Tebeka) Date: Sun, 15 Aug 2004 14:31:06 +0200 Subject: drop into the interpreter In-Reply-To: References: Message-ID: <20040815123106.GB2856@zoran.com> Hello Hoang, > is there a facility to inspect the run-time of a python script? > Essentially, it would execute a script to a set specific point and then drop > into the interpreter. Something like a "Stop" or "Break"? "pdb" module set_trace does what you want (and you're in the deubgger environment...) --- import pdb print 1 pdb.set_trace() print 2 --- HTH. -- ------------------------------------------------------------------------ Miki Tebeka http://tebeka.spymac.net The only difference between children and adults is the price of the toys From mark_bottjer at hotmail.com Wed Aug 11 22:01:05 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Wed, 11 Aug 2004 22:01:05 -0400 Subject: Rather than decorators, how about sections? In-Reply-To: References: <1C74C038-EBB6-11D8-8889-000A95857E5C@eischet.com> <411a6b9d$0$13688$636a15ce@news.free.fr> Message-ID: <411acf61$1@nntp.zianet.com> Stefan Eischet wrote: > On 11.08.2004, at 20:55, Christophe Cavalaria wrote: >> Paul Morrow wrote: >> - It'll break code that binds arbitrary functions as a member >> function. You can't do things like that anymore : >> >>>>> def f(s): >>>>> print "Hi, I'm function f" >>>>> class Klass: >>>>> doIt = f >>>>> Klass().doIt() [snip] > How would you solve this problem with decorators, btw? > class Klass: > @stuff > doIt = f I would expect it to be more like: @stuff def f(s): pass class Klass: doIt = f @stuff modifies f, so it would precede it. The assignment inside Klass is just that, a simple assignment; whatever f is, Klass.doIt now refers to it was well. > If there was a rule that assigned functions in the class body (doIt=f) > default to normal methods whatever their first arg is called, would that > be okay? After all, that is how it works right now. That's certainly true of def statements inside classes, but doIt is just an assignment. If I understand correctly, you're proposing that the compiler do something special if a variable at class scope is being assigned a known function value. I'm not sure the compiler can know that: @stuff def f(s): pass g = f def id(a): return a class Klass: doIt = g doItAgain = id(a) How is the compiler going to sort all this out at compile time? Also, such implicit typing would prevent one from storing non-methods. Raw functions can be useful even inside classes: class Frob: def __init__(self,frob): self.__frob = frob def __call__(self,buf): return self.__frob(buf) Frob(frob.frobnicate)('This is a test.') Frob(frob.frobulate)('This is another test.') Frob(frob.frobnosticate)('The best test of all!') -- Mark From martin at v.loewis.de Sat Aug 7 09:51:50 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 07 Aug 2004 15:51:50 +0200 Subject: decorators and multimethods In-Reply-To: <4edc17eb.0408062340.71ab270f@posting.google.com> References: <4edc17eb.0408062340.71ab270f@posting.google.com> Message-ID: <4114DE76.1090301@v.loewis.de> Michele Simionato wrote: > def addmethod(*types): > """sys._getframe hack; works when the generic function is defined > in the globals namespace.""" > caller_globs = sys._getframe(1).f_globals > def function2generic(f): > generic = caller_globs[f.func_name] > generic[types] = f > return generic > return function2generic Couldn't you use f.func_globals to avoid the getframe hack? Regards, Martin From matt.price at utoronto.ca Mon Aug 9 13:40:00 2004 From: matt.price at utoronto.ca (Matt Price) Date: Mon, 9 Aug 2004 13:40:00 -0400 Subject: unicode and xml/xsl Message-ID: <20040809174000.GA8525@utoronto.ca> Hello, I'm a python (& xml, & unicode!) newbie working on an interface to a bibliographic reference server (refdb); I'm running into some encoding problems & am ifnding the plethora of tools a little confusing. Here is the basic situation: I connect to the server and receive an xml document whose content is a bibliographic dataset. The document can be encoded in two ways: ISO-8859-1 or unicode. My program simply takes the document and passes it to an xsl stylesleet using libxslt & libxml2. Here's the relevant code: # this is how I get the results & generate either a string or a # unicode string def getref (self, query = ':ID:>0', cmd = 'getref ', reftype = default_reftype): cmd += ' ' + query self.send(cmd + self.CS_TERM) results = self.tread() if self.encoding == 'UNICODE': print ' decoding unicode string: ' results = results.decode('utf-8', 'replace') return results # this is where I generate the html: def risx_to_html (self, risxSet, xsl = xsl_ss, css=css_url, use_css = 1): styledoc = libxml2.parseFile(xsl) style = libxslt.parseStylesheetDoc(styledoc) doc = libxml2.parseDoc(risxSet) result = style.applyStylesheet(doc, None) # style.saveResultToFilename("results.html", result, 0) htmlString = style.saveResultToString(result) style.freeStylesheet() doc.freeDoc() result.freeDoc() return htmlString The server's default encoding is iso-8859-1, and since I mosly use english-language references, this usually works fine; but occasionally the server will pass me an entity like 'μ' (for Greek letter mu). This generates an error like this: Entity: line 57: parser error : Entity 'mu' not defined This is not so bad, because the parsing continues nonetheless. With unicode it's worse. In this case there are several errors depending on how I set the system up: with iso-8859-1 set as default encoding in sitecustomize.py: File "/home/matt/bibpython/refdbclient.py", line 268, in risx_to_html doc = libxml2.parseDoc(risxSet) File "/usr/lib/python2.3/site-packages/libxml2.py", line 1149, in parseDoc ret = libxml2mod.xmlParseDoc(cur) UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-1: ordinal not in range(256) with utf-8 set as default encoding: File "/home/matt/bibpython/refdbclient.py", line 268, in risx_to_html doc = libxml2.parseDoc(risxSet) File "/usr/lib/python2.3/site-packages/libxml2.py", line 1149, in parseDoc ret = libxml2mod.xmlParseDoc(cur) TypeError: xmlParseDoc() argument 1 must be string without null bytes or None, not unicode So I guess I have two questions: (1) am I using the right python tools for this job? My excellent python books unfortunately don't cover either unicode or xml in much depth, so I'm a little uncertain as te whtehr I'm doing the right thing. (2) Is there a way to make libxml2 parse unicode documents? Do I need to pass it more information alerting it that it's getting unicode? Anyway, thanks very much for your help. Much appreciated, Matt ------------------------------------------- Matt Price matt.price at utoronto.ca History Department, University of Toronto (416) 978-2094 -------------------------------------------- From Jeffrey at Fro.man Tue Aug 24 21:24:51 2004 From: Jeffrey at Fro.man (Jeffrey Froman) Date: Tue, 24 Aug 2004 18:24:51 -0700 Subject: Printing date a file References: Message-ID: Kory Wheatley wrote: > In Python how would you print the date in a file... Here's my favorite way: >>> import datetime >>> datetime.date.today().isoformat() '2004-08-24' Jeffrey From m.boeren at guidance.nl Thu Aug 12 11:35:37 2004 From: m.boeren at guidance.nl (Marc Boeren) Date: Thu, 12 Aug 2004 17:35:37 +0200 Subject: Verbosity Check Style Message-ID: <0C77C7530EA52A4EBD1C47C80D1D291E07F9E4@sbs.GuidanceBV.local> > I would like to get people's views on the best way to > implement verbosity (or any command-line option) into python > scripts. I'm not sure about the best way, but this hack looks nice: >>> def print_verbose(txt): ... print txt ... >>> def pass_verbose(txt): ... pass ... >>> def func(): ... i = 1 ... verbose('message!') ... i+= 1 ... return i ... >>> verbose = print_verbose >>> func() message! 2 >>> verbose = pass_verbose >>> func() 2 An extra log_verbose is easily created as well. Cheerio, Marc. From ialbert at mailblocks.com Tue Aug 24 09:59:20 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Tue, 24 Aug 2004 09:59:20 -0400 Subject: python-dev Summary for 2004-08-01 through 2004-08-15 In-Reply-To: References: Message-ID: Brett Cannon wrote: > Armin Rigo came up with a way to have string concatenation in a loop > (think ``for thing in iter_of_strings: concat_str += thing``) not be a > quadratic algorithm > But Guido didn't like the patch. Sometimes I just don't get it. Here is a patch that removes one of the warts of python, does not introduce any new behavior, makes python behave as it should have had in the first place, yet it gets shot down on the grounds that it is 'too much of an improvement' and that other python implementations might not be able to keep up with it... Istvan. From bac at OCF.Berkeley.EDU Tue Aug 24 00:50:48 2004 From: bac at OCF.Berkeley.EDU (Brett Cannon) Date: Mon, 23 Aug 2004 21:50:48 -0700 Subject: python-dev Summary for 2004-08-01 through 2004-08-15 Message-ID: <412AC928.7000603@ocf.berkeley.edu> python-dev Summary for 2004-08-01 through 2004-08-15 ++++++++++++++++++++++++++++++++++++++++++++++++++++ This is a summary of traffic on the `python-dev mailing list`_ from August 01, 2004 through August 15, 2004. It is intended to inform the wider Python community of on-going developments on the list. To comment on anything mentioned here, just post to `comp.lang.python`_ (or email python-list at python.org which is a gateway to the newsgroup) with a subject line mentioning what you are discussing. All python-dev members are interested in seeing ideas discussed by the community, so don't hesitate to take a stance on something. And if all of this really interests you then get involved and join `python-dev`_! This is the forty-sixth summary written by Brett Cannon (two freakin' years doing this; I *am* nuts). To contact me, please send email to brett at python.org ; I do not have the time to keep up on comp.lang.python and thus do not always catch follow-ups posted there. All summaries are archived at http://www.python.org/dev/summary/ . Please note that this summary is written using reStructuredText_ which can be found at http://docutils.sf.net/rst.html . Any unfamiliar punctuation is probably markup for reST_ (otherwise it is probably regular expression syntax or a typo =); you can safely ignore it, although I suggest learning reST; it's simple and is accepted for `PEP markup`_ and gives some perks for the HTML output. Also, because of the wonders of programs that like to reformat text, I cannot guarantee you will be able to run the text version of this summary through Docutils_ as-is unless it is from the `original text file`_. .. _PEP Markup: http://www.python.org/peps/pep-0012.html The in-development version of the documentation for Python can be found at http://www.python.org/dev/doc/devel/ and should be used when looking up any documentation on new code; otherwise use the current documentation as found at http://docs.python.org/ . PEPs (Python Enhancement Proposals) are located at http://www.python.org/peps/ . To view files in the Python CVS online, go to http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/ . Reported bugs and suggested patches can be found at the SourceForge_ project page. The `Python Software Foundation`_ is the non-profit organization that holds the intellectual property for Python. It also tries to forward the development and use of Python. But the PSF_ cannot do this without donations. You can make a donation at http://python.org/psf/donations.html . Every penny helps so even a small donation (you can donate through PayPal or by check) helps. .. _python-dev: http://www.python.org/dev/ .. _SourceForge: http://sourceforge.net/tracker/?group_id=5470 .. _python-dev mailing list: http://mail.python.org/mailman/listinfo/python-dev .. _comp.lang.python: http://groups.google.com/groups?q=comp.lang.python .. _Docutils: http://docutils.sf.net/ .. _reST: .. _reStructuredText: http://docutils.sf.net/rst.html .. _PSF: .. _Python Software Foundation: http://python.org/psf/ .. contents:: .. _last summary: http://www.python.org/dev/summary/2004-08-01_2004-08-15.html .. _original text file: http://www.python.org/dev/summary/2004-08-01_2004-08-15.ht ===================== Summary Announcements ===================== Well, I have now been doing the summaries for two years. As has become a yearly tradition, I am offering to pass on the writing of the summaries to someone else. My only requirement is you do a comparable job. You do learn *tons* about Python's internals when you have to research a topic to be able to summarize it. With that said, it is also time for stats on the list to scare away anyone considering taking over this job =) . According to my probably buggy script that I wrote last year, I have read 10,190 emails (this month has already been the busiest month and it is only half over; could set the record for busiest month ever). The people with over 300 emails posted over the year are: 9. Michael Hudson (303) 8. Martin v. Lowis (307) 7. Barry Warsaw (341) 6. Phillip J. Eby (341) # not a typo; same number as Barry 5. Greg Ewing (354) 4. Raymond Hettinger (372) 3. Skip Montanaro (399) 2. Tim Peters (629) 1. Guido van Rossum (1031) These 9 people make up over 40% of all the emails from the past year. Longest threads were: 1. decorate-sort-undecorate (694 emails) 2. Call for defense of @decorators (195 emails) 3. PEP 318: Decorators last before colon (181 emails) 4. redefining is (162 emails) 5. Christmas Wishlist (162 emails) These stats along with the insane amount of email has showed me something; the Summaries have detracted from my participation on python-dev this past year. I have a bigger mouth and more opinions than the number of emails I sent to the list show. This means something has to change, and it isn't going to be my mouth. The Summaries need to change in one of two ways. Option one is that I focus in on certain areas of interest and skip other ones. I have labeled all of the summaries below with what their type is right under the titles. Please email me your top ares of interest. I realize that this month may not be typical but pretty much all areas are covered at least once so at least there is a good taste for the different areas. So, choose from: 1. improvement stuff Pretty much anything that is not a major change to the language/stdlib. Usually something you find out from the Misc/NEWS or the "What's New" doc. 2. how python-dev works Stuff like how python-dev handles things such as the PEP process, coding style, etc. 3. nuggets of info Cool tricks and ideas that come up on the list that the greater world probably does not know. 4. minor language change Stuff that deals with the language changing, but is not significant; such as discussions of existing PEPs. Language evolution stuff (such as decorators) will always be covered so you don't need to vote on that. If people like this first option then I will make sure I cover the area with most votes and everything else is just considered icing. Option two out of all of this is people just say, "summarize what you want, Brett." Then I just cover what I find interesting and just don't worry about covering a specific area. I obviously prefer this option but if people really care about a specific area I want to make sure to cover it. What will most likely happen is I will still cover almost everything but the thoroughness will be lower. I will go more off of memory for example. But something will change. Being on the sidelines for the decorators discussion because I dreaded having to start reading all of those emails in terms of summarizing is not acceptable (and no, I can't just ignore some of them since that is just not how I work). Having to read 1,289 emails for just the first two weeks of this month finally caused me to lose my sanity. Another question becomes whether people miss the "Skipped Threads" feature of the Summaries. If you do let me know and I can go back to doing that by just listing the threads that I don't cover (but with no one-liners probably, but it is possible, or linking to the archives; you would just get the subject line in a long list of threads I didn't bother covering). If that would be *really* helpful then let me know about that as well. ======== Summary ======== -------------------------------------------------------------------------------- Multiple interpreters at a time in a C program kind of broken -------------------------------------------------------------------------------- 3. nuggets of info Philip Eby thought he might have a fix for a known limitation of running multiple interpeters at once (using PyInterpreter_New() ) and having imports not being clearly separated between interpreters. But Martin v. L?wis popped Philip's bubble somewhat by saying that he and some other people viewed multiple interpreter support as inherently broken. Contributing threads: - `Safe to change a thread's interpreter? `__ -------------------------------------------- Another sucker becomes an official developer -------------------------------------------- 2. how python-dev works Sean Reifschneider took the bait to become another one of Guido's minions. Sean has been maintaining the RPM spec files for quite a while. Contributing threads: - `New developer `__ ---------------------------------------- Discovering leaks with a regrtest wrench ---------------------------------------- 1. minor language change Michael Hudson, who found and fixed a bunch of refcount leaks shortly after 2.3 was released, used his magical regrtest patch (which has subsequently been checked in) to hunt down leaks for 2.4 . A bunch of tests were cleaned up to make them not raise false-positives along with fixing some true leaks. Contributing threads: - `refleak hunting season `__ --------------------------------- Another Bug Day has come and gone --------------------------------- 2. how python-dev works The Bug Day held on August 7 led to 19 bugs and 12 patches being closed. You can see the results at http://www.python.org/cgi-bin/moinmoin/PythonBugDayStatus . Feel guilty for not being able to make it? Still want to help? Go to that page to see bugs that could use some squashing that shouldn't be too difficult to deal with. Contributing threads: - `Bug day coming up this Saturday `__ -------------------------------------------------- How to shut a compiler up about an unused variable -------------------------------------------------- 3. nuggets of info Tim Peters had come up with some optimizations for list.pop() that avoided unneeded test+branches. The problem is that it led to a variable possibly being unused. C compilers tend to complain about that and so an initial solution was used. Unfortunately gcc complained about it, and so yours truly came up with one. But that solution was labeled as "perverse" (and it was; total hack solution), so another solution was found thanks to Sjoerd Mullender by just taking the variable and casting it to void. Contributing threads: - `RE: [Python-checkins] python/dist/src/Objects listobject.c, ... `__ ------------------------------------------------------ Variable sequence unpacking assignment shot down again ------------------------------------------------------ language evolution David Cole suggested adding the ability to have sequence unpacking assignment just like \*args for parameters; ``a, b, *c = (0, 1, 2, 3, 4, 5) # a == 0, b == 2, c == (3, 4, 5)``. This idea got a -1 from Guido as not really needed. That reaction makes Guido consistent; the idea was originally shot down back in Nov. 2002; http://www.python.org/dev/summary/2002-11-16_2002-11-30.html#half-baked-proposal-and-in-assignments . If you really like that idea the previous summary contains a function that helps you do this in a way. Contributing threads: - `Tuple/list assignment question `__ ------------------------------------------------------------------------------------- Changing the Big-O complexity for something in the language is now a language feature ------------------------------------------------------------------------------------- language evolution Armin Rigo came up with a way to have string concatenation in a loop (think ``for thing in iter_of_strings: concat_str += thing``) not be a quadratic algorithm thanks to some trickery for ``a = a + b`` and ``a += b`` conditions for strings. The hope was to remove the (commonly considered) wart of having ``"".join(iter_of_strings)`` be the suggested way to concatenate a bunch of strings. But Guido didn't like the patch. His reasoning was that changing something that led to a change in the Big-O complexity of certain algorithms would inherently hurt other implementations of Python when people would start to code specifically for that performance gain. For instance, having Jython be able to pull this trick off is, I believe, near impossible. So, in order to make sure changes like this are considered before applying them, Guido instated a new rule that "implementation features that affect not just the running speed but the O() rate for certain algorithms should be considered language features, because any implementation will be required to implement them in order to ensure code portability" between implementations of Python. In the end, though, this went in with a warning that the speed performance is not portable. It is not to be used in the stdlib ever. Contributing threads: - `Optimized string concatenation `__ - `PEP 0008 confusion - here it is, but don't use it? `__ ------------------------------------------------------------------------------- Bet you didn't think about string interning and how that affects .pyc, did you? ------------------------------------------------------------------------------- 1. minor language change Luckily Martin v. L?wis did. A patch was originally applied to not intern strings representing filenames. Problem is that every code object stores that string, so it increases .pyc files since it has to store multiple copies of that string instead of just one. Contributing threads: - `Re: [Python-checkins] python/dist/src/Python compile.c ... `__ ------------------------------------------------------------------------------ `PEP 324`_ (process - New POSIX process module) != process.py from ActiveState ------------------------------------------------------------------------------ 1. minor language change Guido asked if the APIs between the module proposed in `PEP 324`_ and the process.py module by Trent Mick of ActiveState were compatible. Turns out they are not. Then the discussion went into select(), broken pipes, and other stuff not relevant to the OP. =) .. _PEP 324: http://www.python.org/peps/pep-0324.html Contributing threads: - `PEP 324 (process module) `__ -------------------------------------------------------------------------------------------------------------------------------------------------- Getting it so string literals accept those nutty non-ASCII characters more easily (and getting files to be more upfront about their Unicode-ness) -------------------------------------------------------------------------------------------------------------------------------------------------- language evolution Fran?ois Pinard asked what people thought about two things related to Unicode. First, he thought having a __coding__ attribute for files that contained the encoding of the text would be nice. Martin v. L?wis said it would be possible. MA Lemburg added his vote of support. It has not been implemented to my knowledge yet, though. The second idea was to have a directive of some sort on a per-module basis so that all string literals could be considered in something other than ASCII. Once again Martin said it was doable with MA saying he liked the idea. But it was pointed out that you might as well just use the 'u' in front of strings now. This led to a slight discussion on good i18n practices. Both Martin and MA seemed to suggest that if you are going to be doing most of your work in a single encoding then just use that and declare everything Unicode. ANd if you are going to support a lot of different languages, use gettext and such. Martin also stated it is best to get text into Unicode ASAP and then only convert to the final encoding at the last moment. Contributing threads: - `Python in Unicode context `__ ---------------------------------------------------------------------- An exception is an exception, unless it doesn't inherit from Exception ---------------------------------------------------------------------- language evolution Coming up in a discussion on Unicode of all things, a discussion on moving exceptions over to new-style classes came up. Guido pointed out that moving over to new-style classes would seem to suddenly require that anything passed to 'raise' be a new-style class and that goes against the current acceptance. But in comes Paul Prescod with his argument that exceptions are inherently organized based on inheritance and thus requiring things being passed to 'raise' subclass Exception somewhere is not that big of a thing. Guido really liked that point. So if it goes this way and you don't like it blame Paul (who is a nice guy, so go easy on him =). And then along come Holger Krekel bringing up the point that using exceptions to do non-standard flow control is handy. But the question was asked as to why he couldn't still just subclass Exception? Was it that big of a deal? He admitted it wasn't and said when the name Raisable was suggested that would make it easier. Michael Hudson then came in and wrote up a hacked-up patch to turn exceptions into new-style classes. Most stuff seemed to still work. Python 3 was already going to switch to new-style classes for exceptions and string exceptions have already been deprecated. Now add to the mix the possible requirement that anything passed to 'raise' require a common base class. Contributing threads (note that the thread starts part way in a thread on Unicode and end before the end of the full thread): - `Python in Unicode context `__ ------------------------- Python 2.4a2 out the door ------------------------- language evolution Python 2.4a2 has been released. As usual, please download it and test it with your code along with the regression test suite. Contributing threads: - `trunk frozen for 2.4a2 `__ - `RELEASED Python 2.4, alpha 2 `__ ------------------------------------------------------- Amendment to how to compile with the free .NET compiler ------------------------------------------------------- 3. nuggets of info Nick Coghlan expanded upon my summary on how to compile with the free .NET compiler under Windows at http://www.python.org/dev/summary/2004-07-16_2004-07-31.html#how-to-get-python-to-compile-with-microsoft-s-free-compiler-that-should-just-come-with-the-os-standard . See his email at http://mail.python.org/pipermail/python-dev/2004-August/047215.html on the extra steps. Or just move to another OS. Contributing threads: - `python-dev Summary for 2004-07-16 through 2004-07-31 [draft] `__ -------------------------------------- Darned Solaris, g++, and _XOPEN_SOURCE -------------------------------------- 1. improvement stuff Skip Montanaro discovered that building under Solaris with g++ raised a warning about redefining _XOPEN_SOURCE. pyconfig.h defines it, but apparently so does g++ in order for Solaris' toolchain to expose some code that is only available if it is defined. Martin v. L?wis came up with a couple of suggestions on how to handle this. Skip ended up going with the idea of setting _XOPEN_SOURCE to the same value as it is defined by g++. Contributing threads: - `use of #pragma GCC system_header to suppress _XOPEN_SOURCE warnings `__ ------------------------------------------------------------------------------------- pre-PEP on a function for re that "captures matches for groups that match repeatedly" ------------------------------------------------------------------------------------- 1. minor language change Mike Coleman presented a pre-PEP (newest version at http://mail.python.org/pipermail/python-dev/2004-August/047238.html ) on adding a function to re that would create a tree (in the form of a list) containing all group matches in a string. It got a little support, but the discussion quickly moved over to dreamings of a full-on scanner or parser package for the stdlib. But if the idea of the PEP works for you then speak up on c.l.py . Contributing threads: - `pre-PEP: Complete, Structured Regular Expression Group Matching `__ --------------------------------------- Making ourselves follow the PEP process --------------------------------------- 2. how python-dev works It was noticed early on that the PEP process had broken down for `PEP 318`_ (decorators). What should happen is a PEP gets written (and the author becomes its champion), there is a public discussion, the PEP is updated, that's repeated until it is deemed done, gets get BDFL pronouncement, if Guido okays it the code goes in. Unfortunately the part about updating the PEP didn't really happen. This led to two major things being stated and generally agreed upon. One is that PEPs should not be checked in if the PEP has not been updated. While a minor nit is not a reason to hold back code, not updating after a major public debate is not acceptable. This directly segued into the other point of a PEP needs to have a champion, period. Since the developers on python-dev do not have the time to keep PEPs updated it is up to the PEP champion to make sure it is kept current. If it isn't it is take to mean the champion no longer cares, which means python-dev no longer cares, which means the PEP gets rejected outright. This will also make sure that there is a focus to the design of what the PEP wants and does not lead to a design-by-committee problem. .. _PEP 318: http://www.python.org/peps/pep-0318.html Contributing threads: - `PEP 318, and the PEP process `__ ---------------------------------------------------------------- How to tell Windows from Linux without lifting up anyone's skirt ---------------------------------------------------------------- 3. nuggets of info The question came up on what the best way was to tell what platform you are running on. The answer came down to why you were cared. If it was whether or not you had a specific functionality (or lack thereof), then just test for the functionality. If you had other needs, though, using sys.platform seemed to be the most reliable way (at least for Windows since all of them use 'win32'). Contributing threads: - `Asyncore .set_reuse_addr() on Windows `__ ----------------------------------------- func_name can now have an identity crisis ----------------------------------------- 1. improvement stuff Thanks to the rampant decorator discussion, Skip Montanaro came up with the idea of wanting func_name to be writable. This would allow decorators to wrap a function with another function and yet reset func_name to its original value, thus not having the wrapper function become the prevailing name. Guido liked and Michael Hudson subsequently wrote up `patch #1004703`_. .. _patch #1004703: http://www.python.org/sf/1004703 Contributing threads: - `PEP 318 - writing to func_name attribute `__ ----------------------------------------- statistics.py ain't goin' into the stdlib ----------------------------------------- 1. improvement stuff Raymond Hettinger (at the last Python Bug Day) made the statement that he didn't think 'statistic's should be taken out of the sandbox in CVS and put into the stdlib. He felt that most of the important algorithms were available elsewhere (such as nsmallest and nlargest in the heapq module) and the remaining functions that were not found anywhere were not that critical. He did say, though, he would like to do a calculator module where those remaining functions could go. Contributing threads: - `status of statistics.py? `__ ------------------------------------ Making re.split care about emptiness ------------------------------------ 1. improvement stuff Mike Coleman wrote up a patch for re.split() that AM Kuchling presented to the list. It adds an argument to the function to allow an empty string to be put into the resulting list when a match occurs, even if the match consumes no characters. This allows delimiters used in the regex to still appear in the groups. No decision on the exact semantics of the function, how to handle turning on the new functionality (some say an extra argument, some say adding another bit flag like traditional re arguments), or even if it will be accepted. Contributing threads: - `re.split on empty patterns `__ ---------------------------------------- Pickler's 'bin' argument on its last leg ---------------------------------------- 1. improvement stuff As per `PEP 307`_ (Extensions to the pickle protocol), the 'bin' argument is being upgraded from PendingDeprecationWarning to DeprecationWarning; so it's gone plaid and the only way to stop it is with some emergency change. .. _PEP 307: http://www.python.org./peps/pep-0307.html Contributing threads: - `Pickler()'s bin argument `__ --------------------------------- Some modules are getting the boot --------------------------------- 1. improvement stuff TERMIOS, mpz, statcache, xreadlines and rotor are all being removed. mimify, MimeWriter, and whrandom will raise a DeprecationWarning. rfc822 and mimetools will not be raising DeprecationWarning as specified by `PEP 4`_ since some code in the stdlib still uses it. .. _PEP 4: http://www.python.org/peps/pep-0004.html Contributing threads: - `Removing stuff from 2.4 `__ ------------------------------------------------- Should decimal.Context.copy() be deep or shallow? ------------------------------------------------- 1. improvement stuff Raymond Hettinger brought up the question of whether decimal.Context.copy() should be a deep or shallow copy. While tradition dictates it be shallow based on name, it seems like the functionality should be deep. No one wants context to be shared between number naturally since numbers tend to be viewed as unique things. Staring in 2.4a3 it will be deep unless people come up with reasons to switch it to shallow. Contributing threads: - `decimal.Context.copy() shallow or deep? `__ ---------------------------------------------------------- The dark corners of Python allow you to skip return values ---------------------------------------------------------- 3. nuggets of info Christian Tismer discovered that you can actually stop a return statement from returning if you encase it in a 'finally' block and tweak it slightly (see the OP to get what I mean by this). Turns out this is a reliable feature of Python if you really want to use it. Contributing threads: - `capturing RETURN_VALUE `__ -------------------------------------- Is an int/long combined type worth it? -------------------------------------- language evolution Dmitry Vasiliev pointed out that `PEP 237`_ (Unifying Long Integers and Integers) mentioned that a a new type named 'integer' might be introduced that subclassed both int and long. The discussion waivered between whether it was at all needed, and if it was if it should be a true type or just a tuple containing both types for use with isinstance() . No conclusion was reached in the end. .. _PEP 237: http://www.python.org/peps/pep-0237.html Contributing threads: - `Unifying Long Integers and Integers: baseint `__ -------------------------------------- Should byte arrays be a built-in type? -------------------------------------- language evolution Through the discussion bout having a common type combining int and long a discussion on whether a byte array type should be introduced. The initial suggestion was for it to be practically synonymous with str since str itself stores everything as an array of 8-bit values. The use cases would be for streams and such that just want a stream of bytes with no care for any encoding. Syntactically, having a 'b' and 'B' cookie before literals was suggested. The issue with this, though, is that byte arrays should be mutable, which would make literals that can be mutated, and that is frowned upon by Guido. Semantically, aliasing bytes to the str type was suggested. That was not loved since that could create confusion. Returning an object from 'array' was suggested and seemed okay. In general it seemed this could be useful and could go in 2.5, but nothing for 2.4 . Contributing threads: - `Unifying Long Integers and Integers: baseint `__ ----------------------------- Thar the Windows stack blows! ----------------------------- 1. minor language change Running the new test_compiler test (if you run it with ``-uall`` for regrtest it will recompile the entire stdlib) was leading to an odd failure: the "process on Windows "just vanishes" without a trace, and without an error message of any kind, but with an exit code of 128". After a lot of work put in by a bunch of people (led by Tim Peters) the problem was tracked down to a blown C stack. Turned out that the stack-checking code was not being called frequently enough to pick up the error. The problem with this was that it was leading to odd errors that should have been MemoryError but were manifesting themselves as KeyError. This was because PyDict_GetItem() was failing and return NULL which is the same as signaling the key doesn't exist in the dict. Trick was trying to come up with a good way to deal with this. Adding more calls would be very expensive (reliable way of catching it was sticking a check in pymalloc code) and so that was ruled out. PyDict_GetItem() couldn't change its return value since that would break more code than could be imagined. So, in the end, the stack was increased to 2 MB on Windows. Contributing threads: - `Another test_compiler mystery `__ ------------------------------------------ Someone else falls for the dangling carrot ------------------------------------------ 2. how python-dev works Johannes Gijsbers now has checkin rights. May he close many bugs. Contributing threads: - `New Developer `__ ---------------------------------------------------------- Lying about being in __builtin__ is not always a bad thing ---------------------------------------------------------- 1. improvement stuff James Knight noticed that some objects (mostly C types such as iterators for the built-in types and such) claim in their __module__ attribute that they come from __builtin__ which is not technically correct since you can't access them from there. The desire to fix this came from allowing for proper introspection. The leading idea is to put these types in __builtin__ properly so that they are no longer lying about where they come from. Contributing threads: - `Classes that claim to be defined in __builtin__ but aren't `__ --------------------------------------------------------- Bringing order to the order of application for decorators --------------------------------------------------------- 1. minor language change Turns out that the order of application for decorators was implemented in the reverse order of what it was supposed to be in 2.4a2 . Luckily James Knight spotted this and let the list know. It has been fixed, though, in CVS and now follows `PEP 318`_ to apply in bottom-up order:: @first @second def blah(): pass is equivalent to:: blah = first(second(blah)) The arguments for this ordering beyond it just making more sense to Guido and others is that people will typically put decorators such as staticmethod and classmethod first. Going with the original order would have led to errors in most situations if people were not expecting to be receiving a class or static method to be passed to the other decorators. There was a short discussion on the order of instantiation for the decorators, but in the end the order chosen was the order listed; first would be first() instantiated followed by second(). Contributing threads: - `Decorator order implemented backwards? `__ ----------------------------------------------------------------------------------- PEP 292 (Simpler String Substitutions) getting gussied up for the Python 2.4a3 ball ----------------------------------------------------------------------------------- 1. minor language change `PEP 292`_'s implementation got fixed up. The names of the class names were changed to Template and SafeTemplate, the whole process was made lazy, and just cleaned up in general (solution is small, simple, and rather cool; all subclassable and works with Unicode to boot). But then questions over the merits of $-based string interpolation popped up. People wondered if going from ``%(blah)s`` to ``${blah}`` was worth it. The answer is "yes". And that is just worst case; when you just want ``$blah`` you get an even bigger win. The other question was over whether the string module should become a package. The original idea was to stick the original string module in as a submodule of the package and the Template code in another module. This would allow easy removal of the 'string' module code that has been deprecated for eons. Barry Warsaw (author of the PEP) asked Guido to make the call on this, but he hasn't had the time yet to get to this. .. _PEP 292: http://www.python.org./peps/pep-0292.html Contributing threads: - `PEP 292 `__ -------------------------------- Multi-line imports get clarified -------------------------------- 1. minor language change Multi-line imports will only accept parentheses around what is being explicitly imported and only if there is more than one item being imported. Trailing commas are also to be accepted. Contributing threads: - `Multi-line import implementation (first part) `__ - `Multi-line import implementation (second part) `__ - `Naming nit `__ ------------------------------------------------ For those of you who need Python to run on Win64 ------------------------------------------------ 3. nuggets of info Nick Bastin asked if anyone has gotten Python 2.3 to work under Win64. Martin v. L?wis said "yes" for Python 2.4, but not for 2.3 . He suggested to Nick that he run vsextcomp_ to generate the targets on the 2.4 VC 7 build files and then move that over to 2.3 . .. _vsextcomp: http://www.sf.net/projects/vsextcomp Contributing threads: - `2.3.4 on Win64? `__ ---------------------------------------------- Sometimes concealing the truth is a good thing ---------------------------------------------- 1. improvement stuff Nick Coghlan discovered that some of the function in the 'commands' module did actually work under Windows and he wanted to make sure it was okay to fix another module to work under Windows and to document the fact. But the whole idea was shot down by both Tim Peters and Guido in order to keep the module simple. Keeping the whole thing UNIX-only is much easier than having an API that is only partly compatible with Windows (and with only certain versions of Windows at that). Guido also said that the module would not even be accepted today since it doesn't add enough functionality. Contributing threads: - `'commands' module on Win32 `__ ---------------------------------------------- atexit module, good; sys.exitfunc, not so good ---------------------------------------------- 1. improvement stuff Raymond Hettinger pointed out that the docs for the atexit module state that sys.exitfunc was to be deprecated. Well, atexit has been in the stdlib since 2.0 so the deprecation is long overdue. Looks like it will get its deprecation finally. Contributing threads: - `Deprecate sys.exitfunc? `__ ---------------------------------------------------------------------------------------------- My Personal Hell: decorators and the people who suggest new syntax for them... next, on Oprah ---------------------------------------------------------------------------------------------- language evolution What led to a record-setting flurry of emails to python-dev was set up when Guido gave the green light to checking in code to implement decorators using the '@' syntax (now known at the pie syntax thanks to its checkin coming very shortly after the OSCON Pie-thon competition and '@' sort of looking like a pie). People didn't like it. People were screaming that there had to be a better syntax than just settling for the least offensive one. Others started to question whether decorators were really needed. Others wanted to extend them even more and what their role truly was. Either way this was all coming a little late. But then Guido decided to make my life difficult by saying that if the community could come up with an agreed-upon alternative syntax to propose to him he would consider ripping out the '@' syntax; decorators have always been experimental and '@' was checked in so people had *something* to play with. This meant everyone and their mother started to propose both new and old syntaxes for decorators. This led to a record amount of email on python-dev (at least compared to what we have archives for; back to April 1999). In order of my own personal sanity I am not going to cover any specific syntax. There are just too many and I actually like the '@' syntax (just *try* using it; it grows on you quickly). Instead this summary will cover any important design considerations for decorators (it should all be in the PEP but so much happened there is no way it all got in there) along with any other important considerations about them. I will discuss anything specific to the '@' syntax since it is the currently winning syntax. With that said, `PEP 318`_ and the PythonDecorators_ wiki page are the de-facto place for info on this whole situation. I am probably going to be more biased than normal in this summary just out of time restraints to get this done by not over-analyzing people's suggestions and just assuming what I summarize here is not covered elsewhere; checking if it is would take too long. First off, going with a syntax just so you could add backward-compatible support was not considered worth it. It's a new feature so there is no need to hobble it at the get-go just so people who don't want to upgrade can still use it. Plus the implementations to make this even possible were playing some tricks with the interpreter and not considered a good thing. Besides you can, always will be able to, still use the way to do it in 2.2 and beyond. Another design point that needed to be taken into consideration was ambiguity. There could not be a question about what is a decorator and what isn't (list-before-def is an example of a syntax that can be ambiguous). Syntactic support that allowed for possible future compiler optimizations was also considered important. The on-going hope is to eventually get a JIT compiler for Python and if the decorators are not placed before the def somehow you make it much harder to optimize since you learn about the decorators after the fact of the function starting to be defined. An argument against '@' was that people thought it got rather unwieldy quickly (and I am sure the new decision that each decorator must be on its own line is not making these objectors happy). But one thing that must be remembered is that chances are most functions will not need more than one decorator if the even need one. Looking through the stdlib sans the test suite you will notice there are not a lot of uses for any of the built-in decorators. Yes, usage will probably grow with syntactic support for decorators, but not exponentially in terms of applying multiple decorators to a single function. Allowing decorators to take arguments is a requirement. Not being able to pass arguments to a decorator at instantiation time would severely cripple their usefulness. Being prefix instead of postfix was considered important. Knowing about what is coming up was something Guido thought is better than finding out about some special tweak to the use of a function based on a decorator listed after the definition line. And in the method body had been completely ruled out. In terms of implementation details, decorators can only be functions directly (and not lambda). This means no ``@a or b`` tricks and such. It also means ``@foo().bar()`` is not allowed. This is all gut feeling from Guido for why the restriction should be there. It could change in the future since it is easier to loosen restrictions that make something more strict. A problem with '@' in terms of portability is that Leo_ and IPython_ both use '@' for special syntax. The authors of both tools seem willing to change their tools (not necessarily overly joyous, though =) . Guido wanted a syntax "that ... [is] easy to remember once explained". It did not need to be miraculously obvious what it did just by looking at the first time. Some people didn't like '@' because they keep wanting to say "at" when they saw it. To that, I give you Tim Peters' fix for this: "Pick the keyword you'd like. Then whenever you see "@", pronounce that word instead ". A single decorator that applied to multiple code blocks is completely out. Guido gave a couple of reasons why, but one that he had mentioned multiple times is indenting the code block again just for the decorator is out. Some people suggested that things be kept simple by just throwing out the entire idea of syntactic support. Could happen if everyone agreed to that, but I wouldn't count on it. A supposed knock against '@' was that it wasn't Pythonic. Well, it is Pythonic if Guido says it is so not really a valid argument. OK, tirade time. If you don't want to listen to me get up on my soapbox, then just skip the rest of this... "In the old days, Guido would Pronounce, and we'd all bite our tongues (although not necessarily each his own). The less time Guido can make for Python, the more important becomes graceful capitulation." Tim said this and it makes me wish for the old days. People had *months* to comment on decorators and no one spoke up until something went into the language. Procrastination is not a virtue when it comes to major language evolution discussions. What was worse was when the emails started repeating themselves (which was pretty much from the get-go when this exploded). Seemed like people decided to start talking without doing some research. Granted the PEP was outdated and the wiki page was not up yet, but this stuff was covered in the Summaries before and you could have just Googled for the previous threads. Personally, if I was Guido, I would have said that the community had their chance to speak up and they just didn't take it. But Guido is a nicer guy than that so people are getting a second chance with this. Personally this came off a great case of the tyranny of the majority in my eyes. There is a reason why Python is a dictatorship. At this point people should be hashing out which syntax alternative they want to present to Guido on comp.lang.python_. No more talking on python-dev, no more syntax proposals. The community should set a goal date (Sept. 1 seems good) and just choose a bloody alternative. Then when Guido makes his choice people accept it or just go to another language. No one had better voice their disappoint once Guido chooses his syntax or I will personally come beat you over with a stick for being a whiner. OK, that's out of my system. I feel better now. .. _PythonDecorators: http://www.python.org/cgi-bin/moinmoin/PythonDecorators .. _Leo: http://leo.sourceforge.net/ .. _IPython: http://ipython.scipy.org/ Contributing threads (sans emails that were warnocked): - `2.4a2, and @decorators `__ - `Plea for simpler decorator syntax, in addition to pie-shaped syntax `__ - `Call for defense of @decorators `__ - `@decorators, the PEP and the "options" out there? `__ - `About pep 318--Intro `__ - `Questions about '@' in pep 318 `__ - `A usability argument for list-after-def `__ - `The impact of '@' on Leo `__ - `Similar syntax `__ - `def fn (args) [dec,dec]: `__ - `pep 318, Decorators for Functions, Methods and Classes `__ - `Density of pie-decorator syntax `__ - `elements of decorator syntax suggestions `__ - `318: Annotation background `__ - `IPython, @, and option E from the wiki `__ - `Decorators: vertical bar syntax `__ - `Suggesting '.' decorators (PEP318) `__ - `Attribute strings? `__ - `request: add keywords for static and class methods only `__ - `@decorator syntax is sugar, but for what exactly? `__ - `Semantics of decorators? `__ - `A decorator syntax not yet mentioned (I think!) `__ - `Another approach to decorators. `__ - `Decorators after 'def' should be reconsidered `__ - `def ... decorate `__ - `Decorator syntax J2 (decorate..def) `__ - `Decorators and docstrings `__ - `block-based decorators and other block issues `__ - `More concerns about decorators `__ From asqui at hotmail.com Tue Aug 17 05:50:30 2004 From: asqui at hotmail.com (asqui) Date: 17 Aug 2004 02:50:30 -0700 Subject: Case sensitivity bug in ConfigParser? Message-ID: <20568caa.0408170150.fbcc542@posting.google.com> [Apologies if this posted twice... google groups timed out on the form POST] (Assume an instantiated ConfigParser, c, with a loaded file) >>> c.get("DEFAULT", "foo", False, {"foo": "Bar"}) 'Bar' >>> c.get("DEFAULT", "Foo", False, {"Foo": "Bar"}) Traceback (most recent call last): File "", line 1, in ? c.get("DEFAULT", "Foo", False, {"Foo": "Bar"}) File "C:\Python23\lib\ConfigParser.py", line 513, in get raise NoOptionError(option, section) NoOptionError: No option 'foo' in section: 'DEFAULT' The offending code appears to be as follows (in ConfigParser.py): def get(self, section, option): opt = self.optionxform(option) if section not in self._sections: if section != DEFAULTSECT: raise NoSectionError(section) if opt in self._defaults: return self._defaults[opt] else: raise NoOptionError(option, section) elif opt in self._sections[section]: return self._sections[section][opt] elif opt in self._defaults: return self._defaults[opt] else: raise NoOptionError(option, section) It uses optionxform on the supplied option, but not on the one in the defaults dictionary. If you're going to impose a transform then you have to do it consistently, imho... >>> c.get("DEFAULT", "Foo", False, {"foo": "Bar"}) 'Bar' The supplied "Foo" gets transformed to "foo" and matches the one in the defaults dictionary. Seems a bit counterintuitive to expect that you supply any defaults as pre-transformed according to your specified optionxform. I'm not sure if this is also a problem when reading a file, but there seems to be a related post about this (with no replies!) dating back to 2000 http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=8suc1f%24mf9%241%40nnrp1.deja.com I don't have time to look into it now but I'd guess this problem was resolved in the more obvious location (when reading a file) but patching of the defaults dictionary case was omitted. asqui From me at privacy.net Mon Aug 9 22:37:19 2004 From: me at privacy.net (Dan Sommers) Date: 09 Aug 2004 22:37:19 -0400 Subject: Popular Python projects with lots of pure Python code References: Message-ID: On Mon, 09 Aug 2004 15:01:29 -0700, "Brett C." wrote: > For my thesis (once the bloody thing stops throwing bugs at me) I am > going to need to collect stats on the frequency that atomic types in > local variables are applied to various opcodes and methods. That means > that I need something to collect stats off of. > So I am trying to come up with a list of projects I can use to get my > stats from. the stdlib is a no-brainer. Also plan to use Docutils. But > beyond those most of the big Python projects I can think of have a ton > of C code which is of no use to me. I don't need to be able to run it, > just going to be compiling to .py files. > Any suggestions? It's not a project, as such, but how about Python's standard library? Tons and tons of python code, written by the best python coders around. Regards, Dan -- Dan Sommers Never play leapfrog with a unicorn. From robin at reportlab.com Thu Aug 12 13:48:41 2004 From: robin at reportlab.com (Robin Becker) Date: Thu, 12 Aug 2004 18:48:41 +0100 Subject: PEP318 In-Reply-To: References: <20040812090056.00001e31@titan> <7ttmh0t8c3cogtbhhnp1ohqu8b51pda461@4ax.com> Message-ID: <411BAD79.3090107@chamonix.reportlab.co.uk> David Eppstein wrote: > In article <7ttmh0t8c3cogtbhhnp1ohqu8b51pda461 at 4ax.com>, > Arthur wrote: > > >>foo=staticmathed(foo). >> >>That is the universal langauge for transformations. And when we try >>to explain to anybody what it is that @decorator means, we go back to >>the pseudo code that is in fact the existing syntax. >> >>I guess I am mystified what it is that is perceived to have been >>gained ... by moving magic outside the function block to the top of a >>function in lieu of expressive code outside the function block at the >>bottom of the function. > > > Not having to write the function name three times? If it's just foo, > that would be one thing, but have you seen the PyObjC examples? > > Also, it's not in the Zen of Python, but maybe declarative is better > than imperative? > I think I'm with Arthur in that the current transformation notation is sufficient. If people wish to avoid three names then we need proper anonymous functions as others stated. To avoid lots of extra parentheses we need a function call composition mechanism or for people to define the functions they need rather than have arbitrary lists of operators. -- Robin Becker From rubyguru at hotmail.com Tue Aug 3 22:17:11 2004 From: rubyguru at hotmail.com (Chris Dutton) Date: Wed, 04 Aug 2004 02:17:11 GMT Subject: Does python support multi prototype. In-Reply-To: <2natmnFv86rjU1@uni-berlin.de> References: <2natmnFv86rjU1@uni-berlin.de> Message-ID: angel wrote: > Hi > > Java and cpp support one function name multi function prototype. > For example: > A: > int func1(String s){} > int func1(int i){} > > B: > int func1(String s){} > int func1(String s, int i){} > > Does python support it? No, but it doesn't have to. The type of a function's arguments are not statically limited. def foo(bar): print bar I can call this as easily with one type as with another: foo(1) foo("baz") As for the number of arguments a function takes, it's possible to use the * operator to slurp extra arguments up into a list. def foo(bar, *extras): ... foo(1) foo("baz") foo("baz", "hello", "world") From lepi--REMOVE-THIS-FROM-HERE at fly.srk.fer.hr Fri Aug 20 10:39:48 2004 From: lepi--REMOVE-THIS-FROM-HERE at fly.srk.fer.hr (Tomislav Lepusic) Date: Fri, 20 Aug 2004 16:39:48 +0200 Subject: WSDL/SOAP/XML-RPC HELP Message-ID: Hello, I don't know if this is the right group (I'm more in Perl, know nothing about Python), so if you can help me thanks, if not, sorry to bother you. I'm working on my student project and I'm totally lost and don't have any idea how to continue, and the deadline is 1.9.2004. Please help, 'couse i'm loosing myself in this XML/SOAP/RPC/WSDL things...... A little discription. I have to define and make something like virtual driver for serial port (RS232), only it isn't really a driver. The server has to be on Linux box (physical port(s) is/are there), and the other side (client) is not inportant. It is not important what is connected on serial port. Also, there is no need to work on any kind of drivers on Windows or something, becouse that is not the point. I have to make an universal way to send/recive/control serial port on that server computer from anywhere. I know how to program for serial port on Linux (in C), and I have made some progress there. That low-level programing isn't the problem. The problem is how to make it work over the net, so that someone who wants to write a program on Windows or Mac can use something universal to access it (like XML). I HAVE TO USE XML-RPC or SOAP or WSDL or something like that. The problem is that I don't know how to use those technologies. I read some tutorials, guides on XML-RPC, SOAP and WSDL, and I'm totally lost now. BTW, I was planning to use Perl becouse I know something about it. (I don't know Java) So, if you can help me in any way (advice, similar example or something), please do. This is very important to me. I forget, everything must be secure (SSL or something). Thank you Tom From eldiener at earthlink.net Tue Aug 17 21:15:21 2004 From: eldiener at earthlink.net (Edward Diener) Date: Wed, 18 Aug 2004 01:15:21 GMT Subject: No validation routine for an os.path References: Message-ID: Peter Hansen wrote: > Edward Diener wrote: > >> Try as I might I can not find a routine in os.path which validates >> whether or not a path is syntactically valid, either as a directory >> or as a file. This is surprising since, although I know this is OS >> dependent, Python has many other classes and functions which will >> work properly depending on what OS they are currently running under. >> Is there such a path validation routine in any of the libraries >> distributed with Python or in any other 3rd party Python libraries ? > > I don't really think so, and the last time this sort of thing > was discussed, I believe the conclusion was that it's not > actually possible to do such a thing in all cases anyway, > unless you are willing to actually attempt to create the > file or directory during the validation. Operating systems do have rules for what constitutes a valid file specification and/or directory specification. Some even have API functions which can be called to directly find out. > > One reason I recall being given is that even on a given OS, different > file systems may support different sets of characters for filenames. > For example, a CDROM might disallow certain characters which the > standard file system allows, or a networked device (e.g. NFS, or > Samba) might allow a wider range of possibilities than the permitted > names on a hard drive. You have a good point there. But with a file spec and a bit of work, one should be able to tell what sort of drive is being accessed. > > In the end, this is somewhat like validating email addresses. Until > you actually try and succeed (or fail) to send the message, you cannot > verify whether an address is "valid" for many definitions of valid. I do not totally agree, especially as the OS will know whether something is valid so it obviously has rules itself. But I grant it is more difficult than might be assumed. BTW email addresses actually do have a format which can be parsed ( RFC 822 originally ), although again it is complicated. From jeff at ccvcorp.com Tue Aug 3 16:32:59 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Tue, 03 Aug 2004 13:32:59 -0700 Subject: Class optimization at runtime In-Reply-To: References: Message-ID: <10gvtipb5t0hl44@corp.supernews.com> Dan Sommers wrote: >Alternatively: > > module WithOption: > class Foo: > # whatever > class Bar: > # whatever > > module WithOutOption: > class Foo: > # whatever > class Bar: > # whatever > > if option: > from WithOption import * > else: > from WithoutOption import * > > x = Foo( ) > > Or even better: if option: import WithOption as FooModule else: import WithoutOption as FooModule x = FooModule.Foo( ) (I twitch every time I see 'from X import *' ...) Jeff Shannon Technician/Programmer Credit International From mike at skew.org Sun Aug 15 17:27:13 2004 From: mike at skew.org (Mike Brown) Date: Sun, 15 Aug 2004 15:27:13 -0600 (MDT) Subject: [XML-SIG] python and XML resources In-Reply-To: <1092484513.411dfda120873@www-mail.usyd.edu.au> "from Ajay at Aug 14, 2004 09:55:13 pm" Message-ID: <200408152127.i7FLRDtO039705@chilled.skew.org> Ajay wrote: > does anyone know of good online resources on XML processing in Python. Uche Ogbuji has quite a bit... XML.com Python & XML columns: http://xml.com/pub/at/24 IBM developerWorks Python Web Services Developer columns: http://www-106.ibm.com/developerworks/webservices/library/ws-pythcol.html Python & XML Akara: http://uche.ogbuji.net/akara/nodes/2003-01-01/general-section?xslt=/akara/akara.xslt 4Suite Akara: http://uche.ogbuji.net/akara/nodes/2003-01-01/4suite-section?xslt=/akara/akara.xslt There used to be a PyXML Wiki at twistedmatrix.com but it disappeared earlier this year and may be gone forever. > I am using the PyXML package and have read the introductory XML HOWTO. > what i am looking for is a more detailed and comprehensive coverage of the > entire package - all the classes and functions etc I tend to do this a lot: $ python >>> from xml.dom import * >>> dir() >>> print whatever.__doc__ "A-ha!" :) -Mike From jimmy at retzlaff.com Mon Aug 9 21:55:17 2004 From: jimmy at retzlaff.com (Jimmy Retzlaff) Date: Mon, 9 Aug 2004 18:55:17 -0700 Subject: decorators vs GIL Message-ID: Jarek Zgoda wrote: > Try GUI programming without using threads. Windows and MacOS didn't offer support for multi-processing that was anywhere near as SMP friendly as Python's current GIL laden threads for several major versions of each. I believe it took Microsoft something like 6-8 years to add threads to Windows (and at that point it was only in NT which was far from mainstream) and Apple took something like 10 years and then only the main thread could make OS calls (e.g., no file, network, or GUI access was possible in background threads). So, a few of us have successfully done GUI programming without using threads - in fact very little commercial GUI software used threads before 1995. I've done GUI programming for more than 15 years (5 of those in Python) and the only time the GIL (or the lack of threads in Win/Mac) has come close to getting in my way has been in non-GUI apps that needed to do lots of number crunching. The GIL turned out to be a blessing in disguise for me. It led me to split my processing into multiple processes (which took a matter of minutes). That enabled me to run my app on several machines instead of just 2 CPUs which gave me MUCH more capacity. I'm sure there are apps where the GIL would truly be a problem, but I share the opinion that those are a tiny fraction of the total number of Python programs. I suspect Python's computational performance would be at least as big a problem in many of those cases. I would definitely be interested in reading about specific cases as opposed to general fears, but they aren't posted very often. Jimmy From mwh at python.net Fri Aug 27 07:09:45 2004 From: mwh at python.net (Michael Hudson) Date: Fri, 27 Aug 2004 11:09:45 GMT Subject: Best processor (i386) for Python performance? References: <789f72ac.0408251950.e85d23e@posting.google.com> Message-ID: tom at livelogix.com (Tom Locke) writes: > Hi All, > > I'd be grateful if anyone could provide insight into choosing a good > i386 processor for Python performance. > > Are any of the following of particular importance, or less relevant, > with respect to Python? > > Raw clock speed? > Cache size? > Bus speed? > Intel's Hyperthreading? > AMD's 64 bits? Lots of cache is likely to help. There were some posts -- somewhere, python-dev maybe -- which showed terrible parrotbench times on some Pentium variant with almost no cache. More of everything else is also good, but you knew that, right? Cheers, mwh -- > What are mathematicians' critical job skills? [...] The ability to work long and hard on entirely meaningless problems. -- Michael Hudson & Gordon McMillan, c.l.py From peter at engcorp.com Thu Aug 12 09:42:59 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 12 Aug 2004 09:42:59 -0400 Subject: Print command In-Reply-To: <2o19ojF5ob9jU1@uni-berlin.de> References: <2nv6roF54f7iU1@uni-berlin.de> <2o19ojF5ob9jU1@uni-berlin.de> Message-ID: Russell Blau wrote: > "Peter Hansen" wrote in message > news:cvmdnbvUcbh--obcRVn-uw at powergate.ca... > >>"Russell Blau" wrote in message >> > Actually, I don't know the meaning of ``. >> > On some languages, it means "evaluate": Is it the same meaning in >> > Python? > > Ummm, actually, that wasn't me you were quoting; it was the OP who replied > to my message pointing out that `x` doesn't mean the same as 'x'. Quite right... my apologies for the bad editing. It was 'Cpt Picard' who wrote that, not Russell. -Peter From zathras at thwackety.com Wed Aug 18 07:08:01 2004 From: zathras at thwackety.com (Michael Sparks) Date: Wed, 18 Aug 2004 12:08:01 +0100 (BST) Subject: Generators versus Coroutines In-Reply-To: <1a517b5.0408170923.48f6d964@posting.google.com> Message-ID: On 17 Aug 2004, Bryan Olson wrote: ... > Have you been badly bitten by an evil co-routine? You appear to misunderstand what I was saying. I was not saying co-routines are bad. I was saying that generators are, in my experience, almost as effective. This isn't attacking anything. It's saying that generators really aren't as bad as it appears some people make out. As for network servers, it looks like the network server system based on using generators to gain most of the benefits of co-routines I briefly talked about (in one of the lightning talks) at EuroPython has been blocked for release as open source :-( Your arguments in favour of co-routines for servers all hold (IME) for generators as well. There is _slight_ extra obfuscation, but nowhere near the level of change required for event processing. NB. The reason I like generators is because they allow me to do co-routine-type things in python with no addons. The reason I like greenlets is because it seems to go much, much, much further along that route _and_ gives a performance boost. Also, I'm not opposed to co-routines being added to the language *if* it was done in a manner that doesn't confuse new users, however greenlets appear to mitigate that requirement. Best Regards, Michael. From anthonybaxter at gmail.com Sun Aug 29 13:06:36 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Mon, 30 Aug 2004 03:06:36 +1000 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: On Sun, 29 Aug 2004 12:10:13 -0400, Paul Morrow wrote: > For example, in the following function def, the comments specify (what I > believe is) the author's intention behind each assignment. > > def circu(diameter): > """Info about circu.""" # defines circu.__doc__ > __author__ = 'Paul Morrow' # defines circu.__author__ > __features__ = memoized # defines circu.__features__ > pi = 3.14 # local variable definition > return pi * diameter Not in any Python I know of. I look at that and I think "oo, local variables". That you have a different belief doesn't make it right - I remain _extremely_ unconvinced. Anthony From sholden at flexal.cs.usyd.edu.au Tue Aug 31 19:50:42 2004 From: sholden at flexal.cs.usyd.edu.au (Sam Holden) Date: 31 Aug 2004 23:50:42 GMT Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> <87hdqok9i6.fsf@sinken.local.csis.hku.hk> <1rfz68ely9.fsf@rovereto.ifi.uio.no> <876574k7du.fsf@sinken.local.csis.hku.hk> <1r3c28ejis.fsf@rovereto.ifi.uio.no> <1rllg0cb3m.fsf@rovereto.ifi.uio.no> <874qmovxna.fsf@sinken.local.csis.hku.hk> Message-ID: On 31 Aug 2004 14:59:07 GMT, Antoon Pardon wrote: > Op 2004-08-31, Sam Holden schreef : >> On 31 Aug 2004 10:33:07 GMT, Antoon Pardon wrote: >>> Op 2004-08-28, Isaac To schreef : >>>>>>>>> "Kjetil" == Kjetil Torgrim Homme writes: >>>> >>>> Kjetil> after all, code in _any_ language written by a >>>> Kjetil> professional will have strict indentation. so it's just >>>> Kjetil> syntax. >>>> >>>> No. In all other languages, people deal with *two* ways to find which >>>> statement is associated with an if/while/for/whatever statement and >>>> which is not: by looking at the indentation, and by looking at the >>>> braces. They normally look at the indentation, since it is the >>>> quicker way. But when they find something wrong, they look at the >>>> defining braces, sometimes deeply hidden in long expressions and >>>> statements combined into one line. In Python, we have *one and only >>>> one* way to find which statement is associated with an >>>> if/while/for/whatever statement, and this is the quicker way that >>>> people are used to. >>> >>> I doubt that. >>> >>> I used to limit myself to indentation to see which code belonged >>> to which control. But then I found myself witch controls that >>> were so nested it was hard to see to which if a particular >>> else suite belonged and I started to use end markers in comments >>> to make the structure more visible. >> >> Deep nesting is a bad sign in itself, > > Why? Because it is often hard to read - as you stated by saying you needed to add end markers to make the structure more visible. "Nest as deeply as you can." is one of the obfuscation techniques, recommended in "How To Write Unmaintainable Code"[1] (and it is refering to languages which use {}s), so there is some evidence this is an opinion held by more people that just me... It often goes hand hand in hand with long functions, which I also assert are hard to read. 1. http://mindprod.com/unmain.html > >> regardless of how a language >> specifies block structure. Making the code readable by removing >> the unreadable nesting seems a far better solution than adding >> end markers. > > The nesting reflects the structure of the algorithm. If an algorithm > is best described by the nesting of a number of control structures > then i don't see how you are going to remove that nesting. Functions, classes if the state requirements are such that you would be passing too many arguments to/collecting too many results from each function. Readability counts, and all that... -- Sam Holden From po-yung.liu at pandora.be Fri Aug 13 20:11:49 2004 From: po-yung.liu at pandora.be (Vent d'Est - East Wind) Date: Sat, 14 Aug 2004 00:11:49 GMT Subject: Call PieMan In-Reply-To: References: <2o4m5pF6apnoU3@uni-berlin.de> Message-ID: <9NcTc.213061$HW7.10516540@phobos.telenet-ops.be> Steve Christensen wrote: > In article <2o4m5pF6apnoU3 at uni-berlin.de>, Daniel Ellison wrote: > >>Dave Benjamin wrote: >> >> >>>I just want to say, for the record, that if anyone can successfully build a >>>Python compiler that can produce Flash bytecode, I will personally allow >>>you to throw *any number of pies* in my face, in as public of a ceremony as >>>you desire. Furthermore, I will match you 50/50 in the cost of the pies. >> >>Wow, that's one heavy challenge! Either Dave thinks it just can't be >>done, or he really, /really/ wants this compiler. > > > Or, he really likes pie. > > > -Steve In belgium there is the pieman (with his piegroup , and piecommunity ) , he was a baker , and so he is bored of baking and become PieMan or the Pie Justice man , it s him who have throw Pie In Bill Gates 's face :) (this was not his first shoot :) , he have a lot of important personality in his hall of fame :)) From anthonybaxter at gmail.com Tue Aug 24 10:06:41 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Wed, 25 Aug 2004 00:06:41 +1000 Subject: python-dev Summary for 2004-08-01 through 2004-08-15 In-Reply-To: References: Message-ID: On Tue, 24 Aug 2004 09:59:20 -0400, Istvan Albert wrote: > Brett Cannon wrote: > > > Armin Rigo came up with a way to have string concatenation in a loop > > (think ``for thing in iter_of_strings: concat_str += thing``) not be a > > quadratic algorithm > > > But Guido didn't like the patch. > > Sometimes I just don't get it. > > Here is a patch that removes one of the warts of python, does not introduce > any new behavior, makes python behave as it should have had in the first place, > yet it gets shot down on the grounds that it is 'too much of an improvement' > and that other python implementations might not be able to keep up > with it... Er. Did you _read_ the rest of the section you quoted? """In the end, though, this went in with a warning that the speed performance is not portable. It is not to be used in the stdlib ever."""" From mariube+netnews+ at ifi.uio.no Fri Aug 27 10:55:26 2004 From: mariube+netnews+ at ifi.uio.no (Marius Bernklev) Date: Fri, 27 Aug 2004 16:55:26 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> Message-ID: <3cfpt5ctyu9.fsf@nemi.ping.uio.no> Jacek Generowicz writes: > Hmm ... not pretty, but at least it doesn't PERLize the language. True. @pie decorators fill up three years' worth. -- Marius Bernklev From steven.bethard at gmail.com Thu Aug 19 13:17:11 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: 19 Aug 2004 10:17:11 -0700 Subject: inverse of izip References: Message-ID: Peter Otten <__peter__ at web.de> wrote in message news:... > However, your sample data is badly chosen. Unless I have made a typo > repeating your demo, you are getting the same (last) sequence twice due to > late binding of i. > [snip] > >>> map(list, starzip(it.izip("123", "abc"))) > [['1', '2', '3'], ['a', 'b', 'c']] > >>> x, y = starzip(it.izip("123", "abc")) > >>> list(x) > ['a', 'b', 'c'] > >>> list(y) > ['a', 'b', 'c'] > >>> I knew there was something funny about binding in generators, but I couldn't remember what... Could you explain why 'map(list, ...)' works, but 'x, y = ...' doesn't? I read the PEP, but I'm still not clear on this point. Thanks, Steve From martindemello at yahoo.com Fri Aug 27 13:51:01 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Fri, 27 Aug 2004 17:51:01 GMT Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> Message-ID: <9wKXc.230050$J06.33934@pd7tw2no> Kjetil Torgrim Homme wrote: > > a colleague uses #fi, #yrt etc. to mark the end of blocks, but I don't > find this satisfactory since neither Python nor Emacs has any > knowledge of what the magic comment means. The minimalist change would be to add support for #fi etc in emacs's python mode, or perhaps support for #{ and #} martin From dieter at handshake.de Sat Aug 7 09:03:11 2004 From: dieter at handshake.de (Dieter Maurer) Date: 07 Aug 2004 15:03:11 +0200 Subject: PEP 263 status check References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> Message-ID: "Martin v. L?wis" writes on Thu, 05 Aug 2004 23:49:07 +0200: > ... > I personally believe it is too early yet to make lack of > encoding declarations a syntax error. I'd like to > reconsider the issue with Python 2.5. I hope, it will never come... The declaration is necessary for modules that are distributed all over the world but superfluous for modules only used locally (with fixed encoding). Dieter From h.b.furuseth at usit.uio.no Tue Aug 31 18:47:55 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 01 Sep 2004 00:47:55 +0200 Subject: 'for l in sys.stdin' at interactive prompt (WAS: Re: sys.stdin.readline()) References: <367a4461.0408311221.30866c09@posting.google.com> Message-ID: Steven Bethard wrote: >Hallvard B Furuseth usit.uio.no> writes: >> Or in newer Pythons, simply `for sL in sys.stdin: print sL'. > > This doesn't work for me in the interactive shell: > (...) Whoops - you just found a mysterious bug in a program I'm writing. Thanks:-) > Note that I don't get output until I hit ^Z (this is, obviously, a Windows > box). I tried starting Python with the -u option too, and I still get this > result. Is there any way to make 'for l in sys.stdin' work the way you > suggest it does at an interactive prompt? Can't see any in the manual, now that I've looked more closely. Info node "(python-lib)File Objects" says file.next() uses a read- ahead buffer. It doesn't say one can disable that. -- Hallvard From pf_moore at yahoo.co.uk Fri Aug 27 14:21:44 2004 From: pf_moore at yahoo.co.uk (Paul Moore) Date: Fri, 27 Aug 2004 19:21:44 +0100 Subject: Sound file manipulation in Python References: <10isu157sfk3c2@corp.supernews.com> Message-ID: "Dmitry Borisov" writes: > You may try to use pymedia: http://pymedia.sourceforge.net Looks nice. I'll give it a try. > There is no writing at this point( but you may add it though ), Not something I need right now. > also FLAC not supported also. A pity, but not as important to me as Ogg. How hard is it to add codecs to pymedia? Paul. -- The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong it usually turns out to be impossible to get at or repair. -- Douglas Adams From newsgroups at jhrothjr.com Thu Aug 5 19:43:20 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Thu, 5 Aug 2004 19:43:20 -0400 Subject: PEP 263 status check References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> Message-ID: <10h5hgvpafm8a64@news.supernews.com> "Martin v. L?wis" wrote in message news:4112AB53.6010701 at v.loewis.de... > John Roth wrote: > > PEP 263 is marked finished in the PEP index, however > > I haven't seen the specified Phase 2 in the list of changes > > for 2.4 which is when I expected it. > > > > Did phase 2 get cancelled, or is it just not in the > > changes document? > > Neither, nor. Although this hasn't been discussed widely, > I personally believe it is too early yet to make lack of > encoding declarations a syntax error. I'd like to > reconsider the issue with Python 2.5. > > OTOH, not many people have commented either way: would you > be outraged if a script that has given you a warning about > missing encoding declarations for some time fails with a > strict SyntaxError in 2.4? Has everybody already corrected > their scripts? Well, I don't particularly have that problem because I don't have a huge number of scripts and for the ones I do it would be relatively simple to do a scan and update - or just run them with the unit tests and see if they break! In fact, I think that a scan and update program in the tools directory might be a very good idea - just walk through a Python library, scan and update everything that doesn't have a declaration. The issue has popped in and out of my awareness a few times, what brought it up this time was Hallvard's thread. My specific question there was how the code handles the combination of UTF-8 as the encoding and a non-ascii character in an 8-bit string literal. Is this an error? The PEP does not say so. If it isn't, what encoding will it use to translate from unicode back to an 8-bit encoding? Another project for people who care about this subject: tools. Of the half zillion editors, pretty printers and so forth out there, how many check for the encoding line and do the right thing with it? Which ones need to be updated? John Roth > > Regards, > Martin From adurdin at gmail.com Fri Aug 20 20:13:03 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Sat, 21 Aug 2004 10:13:03 +1000 Subject: Rita Sue and Bob too In-Reply-To: References: Message-ID: <59e9fd3a04082017136d288284@mail.gmail.com> On 19 Aug 2004 19:10:34 -0700, Cyrille Lavigne wrote: > If you dont want them in order you should do: If you don't want them in order, then the sets module is probably the clearest way to go: from sets import Set names = ["Rita", "Jim", "Bob", "Jane", "Sue", "Jerry"] searchnames = ["Rita", "Bob", "Sue"] nameset = Set(names) searchnameset = Set(searchnames) if searchnameset.issubset(nameset): print "They're all found" else: print "They're not all found" -- Or you can eschew the temporary variables, and just say use Set(searchnames).issubset(Set(names)), but this is a little less clear. From ian at emit.demon.co.uk Sun Aug 22 14:03:21 2004 From: ian at emit.demon.co.uk (Ian McConnell) Date: Sun, 22 Aug 2004 19:03:21 +0100 Subject: Parsing C header files with python References: <873c2gzftf.fsf@emit.demon.co.uk> Message-ID: <87wtzrnj86.fsf@emit.demon.co.uk> "Paul McGuire" writes: > "Ian McConnell" wrote in message > news:873c2gzftf.fsf at emit.demon.co.uk... >> I've got a header file which lists a whole load of C functions of the form >> >> int func1(float *arr, int len, double arg1); >> int func2(float **arr, float *arr2, int len, double arg1, double arg2); >> >> It's a numerical library so all functions return an int and accept varying >> combinations of float pointers, ints and doubles. >> > > If regexp's give you pause, try this pyparsing example. It makes heavy use > of setting results names, so that the parsed tokens can be easily retrieved > from the results as if they were named attributes. > > Download pyparsing at http://pyparsing.sourceforge.net. Thanks. Your example with pyparsing was just what I was looking for. It also copes very nicely with newlines and spacing in the header file. From candrade at gmail.com Wed Aug 4 12:23:16 2004 From: candrade at gmail.com (Carlos Andrade) Date: 4 Aug 2004 09:23:16 -0700 Subject: Python CGI question/issue Message-ID: <8697475.0408040823.4cb6fbac@posting.google.com> I have a working python script that takes in content from a form, cleans it up, adds html formatting and then places it into my index.html page on my server. When I had index.html set up as : -rw-rw-r-- 1 carlos wheel 3517 Aug 4 09:51 index.html I could not write back to the file, Traceback (most recent call last): File "/usr/local/www/cgi-bin/bob.py", line 24, in ? file=open("../data/index.html","w") IOError: [Errno 13] Permission denied: '../data/index.html' [Wed Aug 4 09:50:47 2004] [error] [client X.X.X.X] Premature end of script headers: /usr/local/www/cgi-bin/bob.py and I though well shoot okay I need to make index.html -rw-rw-rw-, when then made me a little paranoid. Is there a more simpler way to make it possible for me to write back to index.html? From mark_bottjer at hotmail.com Sun Aug 8 19:28:37 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Sun, 08 Aug 2004 19:28:37 -0400 Subject: Maybe, just maybe @decorator syntax is ok after all In-Reply-To: References: Message-ID: <4116b725$1@nntp.zianet.com> AdSR wrote: > You know what, I'm starting to feel the same. Yesterday Anthony > Baxter mentioned this URL: > > http://mail.python.org/pipermail/python-dev/2004-August/047112.html > > where GvR says: > > """ Given that the whole point of adding decorator syntax is to move > the decorator from the end ("foo = staticmethod(foo)" after a > 100-line body) to the front, where it is more in-your-face, it should > IMO be moved all the way to the front. """ I saw this quote, too, but it did not sway me. I've felt ever since the C89 days that having too much stuff before the name being defined is an impediment to understanding the code: So, let's see here. We have a class method. It's memoized, it's transacted, and it's ACID. Okay, so far, so good. It's takes two ints, and returns an Exception. Okay. It was created on July 17, 2005, at 3:13:32 in the morning EST, by a guy named Guido. Good to know. And it's named 'foo'. Which sucks, because I was looking for 'bar'. Where was I again? Having all this stuff before the *name* of the thing being defined is distracting. First tell me what it's *called*, then I'll decide if I want to know more or not. Ever look at Java code? Abominations like "public static final synchronized f() {}" litter the code. *shudder* How is one supposed to navigate code like this? > And I had the sudden feeling that I finally got it. You see, for me, > the @decorator syntax is a declaration - first thing that came to my > mind was Pascal's "forward". So it says "take the def that follows > and insert a (old style) decoration line in the code after it." Note > that here the "def" is recursive - it may have other @decorators > before it. That is the intent as I understand it. It even sounds reasonable, at first blush. But Python is not supposed to need forward declarations. And the other way of looking at it (an implicit stack of decorators held by the parser, to be applied to the "next X" found) is equally strange. Also, psychology tells us that people like to pick a starting location, and move in one direction from there. We're all familiar with this: this is how books are laid out. Having to scan *both* directions to see all the pertinent information is like having the chapter title in the middle of the chapter. I'll kick this horse once more: if we were take this prefix idea to it's logical conclusion, we'd put the function body before the function name! global x x *= a def f( a) This ain't Python to me. People don't do well with prefix or postfix; we want infix or sequential. That is why so many people still use "algebraic" calculators even when RPN is often faster and requires less button presses. Everything else in Python is either infix or sequential, why start prefixing stuff now? > Speaking of loop statements, they have an optional else clause that > isn't obvious either. It means "do this if there was no break-exit > from the loop." Yet for me the obvious meaning would be "if there > were no loop passes" - that is, the while condition was false on the > first entry or the for list was empty. I think the word "finally" > would be more to the point here (and it's a keyword anyway). Except that finally blocks *always* get executed; while else blocks get executed only if the loop completes normally. I agree that it is an odd word choice, but I assume they were simply trying to reuse a keyword. > I think having some obscurity in the language is inevitable. The > present way of applying decorators (x = decor(x)) is equally cryptic > to a newbie as the @decor syntax will be - first you have to know > what a decorator is. There even aren't any decorators used in the > standard lib - or at least grep doesn't show any static/classmethod > rebindings. Right. The only benefit of decorators is that they get the decoration closer to the start of the decorated. Locality matters when trying to understand code. -- Mark From steven.bethard at gmail.com Tue Aug 31 17:29:51 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Tue, 31 Aug 2004 21:29:51 +0000 (UTC) Subject: 'for l in sys.stdin' at interactive prompt (WAS: Re: sys.stdin.readline()) References: <367a4461.0408311221.30866c09@posting.google.com> Message-ID: Hallvard B Furuseth usit.uio.no> writes: > Or in newer Pythons, simply `for sL in sys.stdin: print sL'. This doesn't work for me in the interactive shell: Python 2.4a2 (#55, Aug 5 2004, 11:42:43) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> for l in sys.stdin: ... print repr(l) ... A B C D ^Z 'A\n' 'B\n' 'C\n' 'D\n' Note that I don't get output until I hit ^Z (this is, obviously, a Windows box). I tried starting Python with the -u option too, and I still get this result. Is there any way to make 'for l in sys.stdin' work the way you suggest it does at an interactive prompt? Steve From h.b.furuseth at usit.uio.no Mon Aug 23 16:11:36 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 23 Aug 2004 22:11:36 +0200 Subject: Why are strings immutable? References: Message-ID: Brent W. Hughes wrote: > Let me give two examples of where I think it would be nice to be able to > change strings in place: Sure, it would be nice sometimes. But immutable strings provide many nice advantages too. > I want to add about 20,000 words to the end of a string, something like > this: > > Str = [ ] > for i in range(20000): > Word = DoSomeProcessing() > Str += Word > > I'd actually like to say Str.extend(Word). If you are doing a lot of that with the string, does it need to be a single string? I've just speeded up a program significantly by changing string_var = ... string_var += ... string_var += ... ... to array_var = ['string'] array_var.append(...) array_var.append(...) ... result = "".join(array_var) (Well, because of how the data was structured I actually used a dict which was unpacked to a list comprehension which was joined to a string, but it still speeded things up.) You might also speed things up with append_string = array_var.append append_string(...) if it is too slow, since that saves a lot of attribute lookups. But don't make your code more unreadable like that unless it _is_ too slow. > I would like to reverse a string containing about 120,000 characters. I'd > like to do it in place, but I'm planning to do something like this: > > List = list(Str) > List.reverse() > Str = ''.join(List) import array a = array.array('c', Str) a.reverse() Str = a.tostring() Still needs two new objects, but at least that's a lot fewer than your list. -- Hallvard From martin at v.loewis.de Fri Aug 6 04:08:22 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 06 Aug 2004 10:08:22 +0200 Subject: PEP 263 status check In-Reply-To: <10h5hgvpafm8a64@news.supernews.com> References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> <10h5hgvpafm8a64@news.supernews.com> Message-ID: <41133C76.8040302@v.loewis.de> John Roth wrote: > In fact, I think that a scan and update program in the tools > directory might be a very good idea - just walk through a > Python library, scan and update everything that doesn't > have a declaration. Good idea. I see whether I can write something before 2.4, but contributions are definitely welcome. > My specific question there was how the code handles the > combination of UTF-8 as the encoding and a non-ascii > character in an 8-bit string literal. Is this an error? The > PEP does not say so. If it isn't, what encoding will > it use to translate from unicode back to an 8-bit > encoding? UTF-8 is not in any way special wrt. the PEP. Notice that UTF-8 is *not* Unicode - it is an encoding of Unicode, just like ISO-8559-1 or us-ascii (although the latter two only encode a subset of Unicode). Yes, the byte string literals will be converted back to an "8-bit encoding", but the 8-bit encoding will be UTF-8! IOW, byte string literals are always converted back to the source encoding before execution. > Another project for people who care about this > subject: tools. Of the half zillion editors, pretty printers > and so forth out there, how many check for the encoding > line and do the right thing with it? Which ones need to > be updated? I know IDLE, Eric, Komodo, and Emacs do support encoding declarations. I know PythonWin doesn't, although I once had written patches to add such support. A number of editors (like notepad.exe) do the right thing only if the document has the UTF-8 signature. Of course, editors don't necessarily need to actively support the feature as long as the declared encoding is the one they use, anyway. They won't display source in other encodings correctly, but some of them don't have the notion of multiple encodings, anyway. Regards, Martin From kboruff at optonline.net Sat Aug 14 18:50:25 2004 From: kboruff at optonline.net (Keith P. Boruff) Date: Sat, 14 Aug 2004 22:50:25 GMT Subject: Python indentation deters newbies? In-Reply-To: <3064b51d.0408130615.3fc4a760@posting.google.com> References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: beliavsky at aol.com wrote: > One of the most commmon reasons programmers cite for not trying Python > is that indentation determines the program flow -- they think its > weird. I think programmers who actually try Python adapt quickly and > do not find the indentation rules to be a problem. Honestly, I'm still not too crazy about the indentation requirements of the language myself, coming from a background of using all free form languages. This isn't too big a deal though since I use emacs and the Python mode basically does the indentation for me. In addition, if anyone here has dealt with makefiles, I'm sure they're well aware of the requirement to indent (in this case 'tab') certain lines. Things I like about the language that offset my displeasure of the indentation rules are: 1. The mechanics of the language are easy to pick up. No funky '$', '@' decorators to deal with. There are the * and ** decorators that you can use in function parameter definitions but that's not a big deal. 2. The language is well documented. I had to learn Python on the fly and the documentation was excellent in getting me up to speed. 3. Good basic/standard API. Not too big; not too small and again... well documented. 4. Nice, tight modularity. If I have any big problem with python, it's in the semantics of the classes. It seems a bit... well... weird in some cases. Two of the things I don't like about it is that there's no access specifiers for the class components (public, private, protected) like C++ and Ruby, for example. Also, I'm not too thrilled about the 'new class style' that I read about in books.. meaning that you should inherit your base class from 'object'. To me, it seems a bit of a hack. All in all though, a good language. I was able to construct a script generator for one of our test programs at work using Python to access a DB and put out flat file representations of the DB data in less than 3 days without being a 'super Python pro'. Keith Boruff From godoy at ieee.org Fri Aug 27 17:55:33 2004 From: godoy at ieee.org (Jorge Godoy) Date: Fri, 27 Aug 2004 18:55:33 -0300 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <1LMXc.67190$UTP.37420@twister01.bloor.is.net.cable.rogers.com> <1gj7a9r.g7ec5a1g89rj0N%aleaxit@yahoo.com> Message-ID: aleaxit at yahoo.com (Alex Martelli) writes: > Dan Perl wrote: > ... >> Alright, alright! And given the fact that it was added only in 2.3, that >> explains why I couldn't find any mention of the feature in 'Python >> Cookbook', the 1st ed. I'm looking forward to seeing it mentioned in the >> 2nd ed. ;-) > > If somebody submits a good recipe about it, I'll be overjoyed to add it > (not sure what chapter -- 'files'? 'system administration'? 'programs > about programs'? -- ah well, I'll find a spot!-). > > In the 2nd Edition of the _Nutshell_, when THAT comes (don't hold your > breath!-), I'll write it up just like I will for all the new delights > since 2.2 -- but for the Cookbook I'm supposed to use recipes that > people do submit to the online cookbook site... OK, I and my co-editors > _do_ perform a lot of editing and merging, and occasionally do add a > recipe or three, but mostly it IS the book you all have written, with > over a hundred authors covering the subjects THEY think matter... It would be great to have one example with more than one file. >From the discussion I got curious and tested it here and -- since Python's so efficient I wasn't surprised that -- it worked. $ cat test.py def test(): print "Test from file 1" $ cat test2.py def test(): print "Test from file 2" >>> import sys >>> sys.path.append('test.zip') >>> import test >>> import test2 >>> test.test() Test from file 1 >>> test2.test() Test from file 2 >>> I also noticed that there was no '.pyc' created for that import, as is usually done for uncompressed modules. Be seeing you, -- Godoy. From peter at engcorp.com Tue Aug 17 00:35:15 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 17 Aug 2004 00:35:15 -0400 Subject: Generators versus Coroutines In-Reply-To: <7xoela8k17.fsf@ruckus.brouhaha.com> References: <7x7js1i887.fsf@ruckus.brouhaha.com> <7xoela8k17.fsf@ruckus.brouhaha.com> Message-ID: <89idnXvf1IiZFrzcRVn-hA@powergate.ca> Paul Rubin wrote: > The limitations aren't as bad as they sound. There are easy > workarounds most of the time. I do think using the yield keyword > to identify generator functions was unfortunate, since it makes > it harder to get rid of the limitations. @generator def func(): blah blah yield blah ?? ;-) From tjreedy at udel.edu Tue Aug 24 01:45:48 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 24 Aug 2004 01:45:48 -0400 Subject: function taking scalar or list argument References: <412a2bce$1_1@127.0.0.1> <9ZCdnT9EuudK3bfcRVn-tA@comcast.com><10il11q5uqfg4ad@corp.supernews.com> Message-ID: "Steven Bethard" wrote in message news:loom.20040824T052140-517 at post.gmane.org... > Well, you can always test for the protocol, e.g.: > > def twice(x): > if hasattr(x, "__iter__"): > return map(twice, x) In 2.2.1: >>> hasattr([1,2,3], '__iter__') 0 so this does not seem to work as you seem to expect. hasattr(iter(x), '__iter__') will. Terry J. Reedy From martin at v.loewis.de Sun Aug 22 05:39:10 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 22 Aug 2004 11:39:10 +0200 Subject: unicodedata name for \u000a In-Reply-To: References: Message-ID: <412869bf$0$24814$9b622d9e@news.freenet.de> Tor Iver Wilhelmsen wrote: > 000A LF > = LINE FEED (LF) > > So the authors of unicodedata.name() could have picked either > '', the ASCII name 'LF' or the alternative 'LINE FEED (LF)'. No. is not a character name. The unicodedata.name function returns the official character name, so it MUST NOT return an alias (which rules out your second alternative). > Not picking any of them seems strange, and as the OP pointed out, > leads to an error even though the "C0 Controls" part of that page *is* > part of Unicode. Yes. However, this strangeness originates from the Unicode specification. Control characters simply do not have a name. If you want to know whether a code point is an unassigned character, check whether unicodedata.type is "Cn". Regards, Martin From bulatov at engr.orst.edu Mon Aug 2 19:32:21 2004 From: bulatov at engr.orst.edu (Yaroslav Bulatov) Date: 2 Aug 2004 16:32:21 -0700 Subject: Microbenchmark: Summing over array of doubles References: <4d642979.0407312049.7a8aecab@posting.google.com> Message-ID: <4d642979.0408021532.2ca19f2f@posting.google.com> Duncan Booth wrote in message news:... > Christopher T King wrote in > news:Pine.LNX.4.44.0408011840050.21160-100000 at ccc4.wpi.edu: > > > On 1 Aug 2004, Duncan Booth wrote: > > > >> I just had a brief look at the code you posted. Are you not concerned > >> about accuracy in any of your calculations? Summing a 10 million > >> element array by simply accumulating each element into a running > >> total is guaranteed to give a lousy result. > > > > Lousy or not, I believe that's how numarray is implemented internally, > > so at least all the benchmarks are the same. If you want accuracy > > summing that many numbers, you're going to have to do it in software > > (likely by summing each mantissa bit individually and reconstructing > > the float afterward), so it will be abysmally slow (obviously not what > > the OP wants). > > > > My point being that speed isn't everything. Most applications doing large > floating point calculations should be concerned about accuracy, and how not > to add up a large array of floating point numbers was one of the first > things I was taught in computer science classes. The fastest way to sum 10 > million numbers (albeit at some considerable loss of accuracy): > > return 0 > > > The 'correct' way to sum a large array of floats is, of course, to > calculate a lot of partial sums and sum them. For example, naively, we > might say that to sum the array we sum the first half, sum the second half > and add the results together. This definition being recursive ensures that > if the inputs are all of a similar size then all the intermediate > calculations involve summing similarly sized values. A more sophisticated > technique might also try to handle the case where not all values are a > similar size. > > If you are worried about speed, then calculating partial sums is also the > way to go: the naive technique used by the original poster leaves no scope > for parallel calculation. It should be possible to write a slightly more > complex loop in the C version that runs a lot faster on systems that are > capable of performing multiple floating point instructions in parallel. You are right, naive summing generates significant accuracy losses. I estimated the error by summing [0.123456789012345]*1000000 and comparing it to 1234567.89012345. All methods have error about 1e-4 . The method below sums the array at the same speed as regular Python sum loop, but reports error < 1e-15 . def sum2(arr): size = len(arr) for itr in range(int(ceil(log(size)/log(2)))): for i in xrange(0, size, 2**(itr+1)): next_i = i+2**itr if next_i Message-ID: On Wed, 04 Aug 2004 10:20:53 -0400, Peter Hansen wrote: > Jorgen Grahn wrote: ... >> I miss overloading in Python from time to time, but I can live without it. >> It is, after all, closely tied to a type system which is desirable in C++ >> and Java, but not in Python. > > (untested code, may be minor bugs) ... > > If you _really_ miss it from time to time, then it's _really_ > easy to add it so that it's available in a fairly elegant fashion > when you do need it. Well, I don't _really_ miss overloading that much. Not enough to try to squeeze it into Python when I know it's an idiom that doesn't really fit. Your code was kind of elegant, but kind of misses the point with overloading, I think. At least, it's not anything I'd want to do in most situations where overloading would have been nifty in C++. IMHO. /Jorgen -- // Jorgen Grahn Would You Let One Marry Your Sister?'' From nicksjacobson at yahoo.com Tue Aug 17 14:30:27 2004 From: nicksjacobson at yahoo.com (Nick Jacobson) Date: 17 Aug 2004 11:30:27 -0700 Subject: Newbie 1st program References: Message-ID: > ary = ["Restrict your search to a specific site", > "army.mil", "usmc.mil", "af.mil", "navy.mil", "uscg.mil", > "SYColeman.com", "l3com.com", "fedbizopps.gov", "defenselink.mil"] > > i = event.GetInt() > if 0 <= i < len(ary): > t2.Clear() > t2.SetValue(ary[i]) > t2.SetEditable(i != 0) You're right, this is an improvement. Well, my main point was to eliminate the code redundancy, even if I was a bit clumsy about it. :0 --Nick From duncan.booth at invalid.invalid Mon Aug 2 07:52:56 2004 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 2 Aug 2004 11:52:56 GMT Subject: Timing Difference: insert vs. append & reverse References: <35b736b9.0408020330.53b24ed3@posting.google.com> Message-ID: johnfkeeling at yahoo.com (John Keeling) wrote in news:35b736b9.0408020330.53b24ed3 at posting.google.com: > I tried the test program below. My interest is to examine timing > differences between insert vs. append & reverse for a list. My results > on my XP Python 2.3.4 are as follows: > time_reverse 0.889999389648 > time_insert 15.7750005722 > Over multiple runs ... the time taken to insert at the head of a list, > vs. the time taken to append to a list and then reverse it is > typically 16 or 17 times longer. > I would have expected the insert operation to be faster than the > combined append & reverse operations. Is this behaviour surprising, or > is there a good reason why there is this large performance difference? A list is implemented by an array of pointers to the objects it contains. Every time you call 'insert(0, indx)', all of the pointers already in the list have to be moved up once position before the new one can be inserted at the beginning. When you call 'append(indx)' the pointers only have to be copied if there isn't enough space in the currently allocated block for the new element. If there is space then there is no need to copy the existing elements, just put the new element on the end and update the length field. Whenever a new block does have to be allocated that particular append will be no faster than an insert, but some extra space will be allocated just in case you do wish to extend the list further. If you expected insert to be faster, perhaps you thought that Python used a linked-list implementation. It doesn't do this, because in practice (for most applications) a list based implementation gives better performance. From bdesth.quelquechose at free.quelquepart.fr Thu Aug 19 04:36:08 2004 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 19 Aug 2004 10:36:08 +0200 Subject: age of Python programmers In-Reply-To: References: Message-ID: <41245e57$0$29668$636a15ce@news.free.fr> Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... > > Well, I'm 37, but I may be some special case since I started programming at 32... (well, I did some bits of scripting before that but nothing serious, just a few lines of Hypertalk and VBScript...). So I'm not so young, but still a young programmer !-) From sjdevnull at yahoo.com Tue Aug 10 18:28:56 2004 From: sjdevnull at yahoo.com (G. S. Hayes) Date: 10 Aug 2004 15:28:56 -0700 Subject: decorators vs GIL References: <96c2e938.0408091819.2cd7b50d@posting.google.com> Message-ID: <96c2e938.0408101428.1545fb26@posting.google.com> mudd at vex.net wrote in message news:... > state machines and processes [and inter-process > communication/coordination]? It sounds like you're saying the alternative > to threads is "home brewed" threads. No. I'm using alternative multiprocessing/event-driven programming methods that are much less error prone (ie easier to program and maintain) and easier to get good performance out of than using threads. The core difference between threads and processes is that threads share all their memory while processes have protected memory. That difference _should_ be the deciding factor in whether you use processes or threads in an application, although as I've said throughout this thread two major platforms (Windows{see * below} and Java) don't give you the tools to make that possible; thankfully, Python does on OSes where it's possible. I'll repeat: On platforms with sane process implementations, the deciding factor between using threads or using processes should be whether you want all your memory (including the code) shared or not. Because THAT is the fundamental difference between the two. 99% of the time, throwing out protected memory is the wrong thing to do; it is extremely error prone, difficult to debug, and while it often seems easy to design a multithreaded program up front it almost always winds up being more work than using events and processes where needed. In many cases it'll run dramatically slower than a multiple process implementation as well. Note that I'm not alone in this belief; since you seem particularly interested in the GUI side of things, you might consider reading John Ousterhout's famous paper "Threads Considered Harmful" (he's the author of Tcl/Tk and knows a thing or two about programming GUI apps). > Until recently linux implemented threads as processes. This is not true for any reasonable definition of "recently". What has recently changed is how the threads are shown by tools like ps and top, and the threading library has changed from LinuxThreads to a more efficient implementation (NPTL) that uses faster mutexes. But the core COE implementation hasn't changed in nearly a decade (since 1996 at least): Linux implements arbitrary "contexts of execution" in a way similar to Plan 9. Traditional processes and threads are just two kinds of COE; COEs can share various attributes. A traditional thread is akin to a COE that shares memory, whereas traditional processes don't. But other attributes (e.g. signal handlers or even the filesystem namespace) can be private or shared. "thread" and "processes" are only two instances of a much more flexible object. Various other OSes (e.g. Irix, BSD) do similar things (often using the name "sproc" or "rfork" instead of "clone). > I'm really not concerned with how the threads are implemented in the > thread library. I just don't want a language to prevent me from > accessing the thread library. I agree, though I'd much rather use a language like Python that hides the thread library than a language like Java that hides the much more useful process library. *Windows has an excellent I/O Completion Port mechanism for event-driven programming that can build very efficient multiplexed I/O (e.g scalable network servers); Linux's queued realtime signals were based in part on that mechanism. From peter at engcorp.com Fri Aug 6 08:24:47 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 06 Aug 2004 08:24:47 -0400 Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) In-Reply-To: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> References: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> Message-ID: Istvan Albert wrote: > Paul McGuire wrote: > > > Please reconsider the "def f() [classmethod]:" construct. > > > > def f() [ staticmethod, > > synchronized, > > alphabetized, > > supersized, > > returns('d') ]: Nobody has bothered to post an example with a long argument list, thus ignoring the possibly valid claim in the PEP that this would make the decorator list hard to see. Here goes: def someMethod(self, posArgOne, anotherArg, fieldX=56, x=5, y=7, z=9, **kwargs) [ staticmethod, synchronized, alphabetized, supersized, returns('d') ]: Okay, pretty much an abomination, but I'm not sure it's any worse than the alternative with @: @staticmethod @synchronized @alphabetized @supersized @returns('d') def someMethod(self, posArgOne, anotherArg, fieldX=56, x=5, y=7, z=9, **kwargs): It *is*, however, fairly clear that the list of decorators becomes harder to see. Without checking, it's definitely possible that the decorator list in the first case is actually part of the argument list. I don't care. I still prefer it to @, if nothing else because it's much more intuitive to a Python programmer what order they will be applied in. > Voting for the "list-after-def" syntax as shown above: Apparently the term "voting" is deprecated when related to PEPs and language design. ;-) Instead, we should now be using the term "expressing their opinion in favour of"... At least, I hope we are still allowed to express opinions in favour of things... -Peter From da_rosser at yahoo.com Tue Aug 3 15:20:55 2004 From: da_rosser at yahoo.com (Doug Rosser) Date: 3 Aug 2004 12:20:55 -0700 Subject: Mucking with the calling scripts namespace (For a good reason, honest!) References: Message-ID: Thank you for your help Larry. Let me see if I've got this straight: 1. Python doesn't provide an obvious way to modify the __main__ namespace. You can peek at values with "global" but you can't treat it like a dictionary at runtime. 2. If you need to access objects that won't have names until run-time (but you incidentally -KNOW- their names and want to reference them in a bit of code), encapsulate them in a container. This effectively creates a new not-really namespace, as the objects in the container become attributes. Well, all-in-all, I'd really still rather have #1, but I can live with #2. da rosser -- We are the music makers, and we are the dreamers of dreams -- "Larry Bates" wrote in message news:... > I would suggest following: > > 1) Change the config file into proper format for > ConfigParser module. > > [server_001] > hostname=alpha > os=posix > > [server_002] > hostname=beta > os=win > > [client_001] > hostname=ichi > os=posix > > [client_002] > hostname=ni > os=posix > > This makes it easy to define up to 999 servers and > 999 clients (just make the counter longer if you > require more). > > 2) Create classes to hold information/methods that > will work on each server/client. > > class server: > def __init__(self, server_id, name, os): > self.id=server_id > self.name=name > self.os=os > return > > def dosomething(self): > # > # Insert code here to do something on this > # server. > # > return > > 3) Create class to hold servers/clients (I'll leave > the one to handle clients to you). > > class servers: > def __init__(self, INI): > # > # Create an index pointer for next method > # > self.next_index=0 > # > # Create a list to hold server names > # > self.names=[] > serverlist=[x for x in INI.sections if > INI.sections.beginswith('server')] > serverlist.sort() # If you want to keep them in order > # > # Loop over each server entry > # > for server_id in serverlist: > name=INI.get(server_id, 'name') > os=INI.get(server_id, 'os') > self.append(id, name, os) > > return > > def append(self, server_id, name, os): > # > # Create server instance and append to list of servers > # > self.names.append(server_id) > self.__dict__[name]=server(server_id, name, os) > return > > def __iter__(self): > return self > > def next(self): > # > # Try to get the next route > # > try: SERVER=self.names[self.next_index] > except: > self.next_index=0 > raise StopIteration > # > # Increment the index pointer for the next call > # > self.next_index+=1 > return SERVER > > In your programt do something like: > > import ConfigParser > > INI=ConfigParser.ConfigParser() > INI.read(inifilepath) > > SERVERS=servers(INI) > > Now you can access > > SERVERS.server_001.name > SERVERS.server_001.os > > or call methods via > > SERVERS.server_001.dosomething() > > or you can easily loop over them > > for SERVER in SERVERS: > SERVER.dosomething() > > or > > print SERVERS.names > > Code not tested, but I hope it helps. > > Larry Bates > Syscon, Inc. > > > > "Doug Rosser" wrote in message > news:e08cd05f.0408020727.15ce4356 at posting.google.com... > > I'm writing a fairly complicated test framework and keeping > > configuration data inside ini files that are parsed at runtime by the > > ConfigParser module. > > > > For example, there would be a section similar to the following > > > > [servers] > > server1:{'hostname':'alpha','os':'posix'} > > server2:{'hostname':'beta','os':'win'} > > > > [clients] > > client1:{'hostname':'ichi','os':'posix'} > > client2:{'hostname':'ni','os':'posix'} > > > > As I read the configuration file, I don't actually create instances, > > but use the data to check "what's out there" to make sure the physical > > network environment has the bits and pieces required to run a > > particular test. This is a sort of "go/no-go" resource check. > > > > Assuming that everything is correct with the physical network > > environment, I want my testers to be able to refer to these resources > > in their python scripts by the names in the ini file, like so: > > > > myTest.checkResources() # Read the config file and associate names > > with real > > # life instances > > > > server1.doSomething() # Note how I have cleverly saved myself from > > declaring > > # "server1" because the module myTest has > > inserted > > # it into the right namespace :-) > > > > Down to business: How do I write a module that can insert these names > > into the calling script's namespace at runtime? Is this even possible > > in Python? > > > > da rosser > > -- We are the music makers, and we are the dreamers of dreams -- From richardshea at fastmail.fm Fri Aug 20 00:35:57 2004 From: richardshea at fastmail.fm (Richard Shea) Date: 19 Aug 2004 21:35:57 -0700 Subject: pyXLWriter - simple example code ? Message-ID: <282f826a.0408192035.32687e48@posting.google.com> Hi - Anyone out there who has a simple example using pyXLWriter (http://sourceforge.net/projects/pyxlwriter/) they are willing to share with the group ? I'm interested in creating a .XLS which has multiple sheets within the workbook but I'm having real trouble getting started, I can create a Worksheet but can't figure out how to save it. thanks richard shea. From tzot at sil-tec.gr Wed Aug 18 11:50:09 2004 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Wed, 18 Aug 2004 18:50:09 +0300 Subject: age of Python programmers References: Message-ID: On Wed, 18 Aug 2004 12:20:31 GMT, rumours say that "Lucas Raab" might have written: >One thing I've always kind of wondered is what is the average age of a >Python programmer?? What age groups use Python?? Something to think >about.... > I believe the average will be more than 25. Not many kids program these days. I'm 32 btw. -- TZOTZIOY, I speak England very best, "Tssss!" --Brad Pitt as Achilles in unprecedented Ancient Greek From cpl.19.ghum at spamgourmet.com Fri Aug 6 03:16:33 2004 From: cpl.19.ghum at spamgourmet.com (Harald Massa) Date: Fri, 6 Aug 2004 07:16:33 +0000 (UTC) Subject: [py2exe.i18n] English works, German works, but not French. What do I miss? References: Message-ID: "F. GEIGER" wrote in news:cev7g9$3fm$1 at newshispeed.ch: > When I start a py2exe-ed application I get the error > > 'ascii' codec can't encode character u'\xe9' in position 10: ordinal > not in range(128) encodings: prepare to spend the night. First reading: http://starship.python.net/crew/theller/moin.cgi/EncodingsAgain Second: your error msg says that you are trying to encode sth. NOT ASCII to ASCII... I guess: your lokale site has another encoding configured import sys sys.getdefaultencoding() -- returns sth. like Latin-1 And the py2exed application does not read siteconfig.py, and so in the running app sys.getdefaultencoding() would be some thing different. My approach to this is: in the beginning of the app I write: import sys if hasattr(sys,"setdefaultencoding"): sys.setdefaultencoding("latin-1") so ... when no site-config was run, I manually set my default encoding to latin-1 works great (together with what I described within the wiki) Harald From russblau at hotmail.com Wed Aug 11 14:29:29 2004 From: russblau at hotmail.com (Russell Blau) Date: Wed, 11 Aug 2004 14:29:29 -0400 Subject: Print command References: Message-ID: <2nv6roF54f7iU1@uni-berlin.de> "CptPicard" wrote in message news:WosSc.21396$Jp6.6141 at newsread3.news.atl.earthlink.net... > I think that you should try: > string.rjust('currentTotal',6) > instead of: > string.rjust(`currentTotal`,6) > > You may also do it this this way: > 'currentTotal'.rjust(6) No, I think he really did want the "backwards" single quotation marks. They *are* different, you know... -- I don't actually read my hotmail account, but you can replace hotmail with excite if you really want to reach me. From __peter__ at web.de Fri Aug 13 13:55:19 2004 From: __peter__ at web.de (Peter Otten) Date: Fri, 13 Aug 2004 19:55:19 +0200 Subject: blocking file.readlines() needed References: Message-ID: Uwe Mayer wrote: > I am looking for a way to make the call to a file objects readline() > method blocking when there is no more data, until data is appended to the > file, similar to the way > > $ tail -F > > works. > > However, file.readlines() aborts and returns an empty list. > > Any ideas? The naive way to do it: while True: while True: line = f.readline() if not line: break print line, time.sleep(1) Peter From del at mjclift.freeserve.co.uk Fri Aug 13 01:09:06 2004 From: del at mjclift.freeserve.co.uk (Calvin79) Date: Fri, 13 Aug 2004 01:09:06 -0400 Subject: while and if References: Message-ID: <0f046dc3f2575925e1b9e2640c6c40cd@localhost.talkaboutprogramming.com> Thankyou Satchit, it works exactly as I wanted! Calvin From a.clarke11 at ntlworld.com Thu Aug 26 15:50:55 2004 From: a.clarke11 at ntlworld.com (Tony Clarke) Date: 26 Aug 2004 12:50:55 -0700 Subject: age of Python programmers References: Message-ID: <3353cd1e.0408261150.c0c6fc5@posting.google.com> Evandro Vale Miquelito wrote in message news:... > I'm 23. > > ****************************** > * Evandro Vale Miquelito * > * evandro at async.com.br * > ****************************** > > On 25 Aug 2004, Brian Almond wrote: > > > "Lucas Raab" wrote in message news:... > > > One thing I've always kind of wondered is what is the average age of a > > > Python programmer?? > > If this carries on, we'll all be a year older , and have to start again... Ciao Tony From jjl at pobox.com Thu Aug 12 16:31:24 2004 From: jjl at pobox.com (John J. Lee) Date: 12 Aug 2004 21:31:24 +0100 Subject: Flython? References: Message-ID: <87657op083.fsf@pobox.com> Peter Hansen writes: [...] > In the vein of Jython, I wonder what it would take to build > a Flython? [...] Judging by the current state of Jython (a lot of work put in, but still at 2.1): A fair amount of dedication. John From __peter__ at web.de Thu Aug 12 06:06:06 2004 From: __peter__ at web.de (Peter Otten) Date: Thu, 12 Aug 2004 12:06:06 +0200 Subject: Help understanding Scheme's syntax, procedures and calls References: <95f168b0.0408120120.31433dc7@posting.google.com> Message-ID: Fran wrote: > I'm trying to understand a functional language code fragment so I can > explain its syntax and workings to my non English-speaking background > neighbour, who is doing her finals. > > What in heaven's name is this code fragment intending? (In English > prose if possible). > > It looks like a fragment from a language called "scheme" > > (define (this n) > (if (=n 0) > 0 > (= n (this (- n 1))))) > (define (f1 a b) > (if >b a) > 0 > (+ b (f1 a (+ b 1))))) > (define (that n) > (f1 n1) [silly disclaimer] I don't know Scheme but I'd suppose the above to be equivalent to the following python (you seem to have some problems counting the brackets :-) def this(n): if n == 0: return 0 else: return n + this(n-1) def f1(a, b): if b > a: return 0 else: return b + f1(a, b+1) def that(n): return f1(n, 1) # try it out print this(4) print 'experimental "proof"' ALL_POSITIVE_INTEGERS = range(1, 10) for i in ALL_POSITIVE_INTEGERS: print "%s:" % i, this(i), that(i) Otherwise I'd suggest that you download Scheme and just try it out. Perhaps they even have a debugger so you can step through the instructions one at a time... Peter PS: More help would certainly lead to disqualification. From mdkr at 163.com Thu Aug 26 22:41:34 2004 From: mdkr at 163.com (mdk.R) Date: 26 Aug 2004 19:41:34 -0700 Subject: i can't run wxPython Message-ID: <88c4d3f.0408261841.297be57d@posting.google.com> Hello all: i'am installed wxPython 2.5 and Python2.3.4..i try execute script with wxPython but it show error: Traceback (most recent call last): File "E:\py\test.py", line 7, in ? import wx File "E:\py\wx.py", line 10, in ? from wxPython.wx import * File "D:\Python23\Lib\site-package import _wx File "D:\Python23\Lib\site-package from _core import * File "D:\Python23\Lib\site-package import wx._core ImportError: No module named _core the test.py file content is : #---------------------------------------------------------------------- # A very simple wxPython example. Just a wxFrame, wxPanel, # wxStaticText, wxButton, and a wxBoxSizer, but it shows the basic # structure of any wxPython application. #---------------------------------------------------------------------- import wx class MyFrame(wx.Frame): """ This is MyFrame. It just shows a few controls on a wxPanel, and has a simple menu. """ def __init__(self, parent, title): wx.Frame.__init__(self, parent, -1, title, pos=(150, 150), size=(350, 200)) # Create the menubar menuBar = wx.MenuBar() # and a menu menu = wx.Menu() # add an item to the menu, using \tKeyName automatically # creates an accelerator, the third param is some help text # that will show up in the statusbar menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit this simple sample") # bind the menu event to an event handler self.Bind(wx.EVT_MENU, self.OnTimeToClose, id=wx.ID_EXIT) # and put the menu on the menubar menuBar.Append(menu, "&File") self.SetMenuBar(menuBar) self.CreateStatusBar() # Now create the Panel to put the other controls on. panel = wx.Panel(self) # and a few controls text = wx.StaticText(panel, -1, "Hello World!") text.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD)) text.SetSize(text.GetBestSize()) btn = wx.Button(panel, -1, "Close") funbtn = wx.Button(panel, -1, "Just for fun...") # bind the button events to handlers self.Bind(wx.EVT_BUTTON, self.OnTimeToClose, btn) self.Bind(wx.EVT_BUTTON, self.OnFunButton, funbtn) # Use a sizer to layout the controls, stacked vertically and with # a 10 pixel border around each sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(text, 0, wx.ALL, 10) sizer.Add(btn, 0, wx.ALL, 10) sizer.Add(funbtn, 0, wx.ALL, 10) panel.SetSizer(sizer) panel.Layout() def OnTimeToClose(self, evt): """Event handler for the button click.""" print "See ya later!" self.Close() def OnFunButton(self, evt): """Event handler for the button click.""" print "Having fun yet?" class MyApp(wx.App): def OnInit(self): frame = MyFrame(None, "Simple wxPython App") frame.Show(True) self.SetTopWindow(frame) return True app = MyApp(True) app.MainLoop() where is error?? help me.Thank very much!!! From simoninusa2001 at yahoo.co.uk Fri Aug 27 18:24:12 2004 From: simoninusa2001 at yahoo.co.uk (Simon John) Date: 27 Aug 2004 15:24:12 -0700 Subject: Mysql in Python? In-Reply-To: Message-ID: I got MySQLdb working with MySQL4, it's pretty similar to the PHP implementation, although error handling isn't great (nor is documentation!) I'm going to look at the ADOdb wrapper, which has the DB-API2 documentation to go with it, and some error handling outside of just try...except From h.b.furuseth at usit.uio.no Sun Aug 1 16:08:14 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 01 Aug 2004 22:08:14 +0200 Subject: slowdown with massive memory usage References: Message-ID: Andrew MacIntyre wrote: > On Sat, 30 Jul 2004, Hallvard B Furuseth wrote: >> I have a program which starts by reading a lot of data into various >> dicts. >> >> When I moved a function to create one such dict from near the beginning >> of the program to a later time, that function slowed down by a factor >> of 8-14: > (...) > > Python 2.2 didn't use PyMalloc by default. This leaves Python at the > mercy of the platform malloc()/realloc()/free(), and Python has found > rough spots with nearly every platform's implementation of these - which > is why PyMalloc was written. > > While it isn't certain that this is your problem, if you can rebuild your > Python interpreter to include PyMalloc (--with-pymalloc I think), you can > find out. Thanks. I'll check that when I get time. Until then, malloc gets the blame until proven innocent, since profiling and test output turned out nothing else that was different. (See my reply to Istvan.) > Be warned that there were some bugs in PyMalloc that were fixed before > Python 2.3 was released (when PyMalloc became a default option); as far as > I recall, these bugfixes were never backported to 2.2x. So I wouldn't > recommend running a 2.2.3 PyMalloc enabled interpreter in production > without seriously testing all your production code. If PyMalloc helps, I'll push for an upgrade to 2.3. Thanks again. -- Hallvard From joshway_without_spam at myway.com Mon Aug 23 16:39:14 2004 From: joshway_without_spam at myway.com (JCM) Date: Mon, 23 Aug 2004 20:39:14 +0000 (UTC) Subject: PEP318: radical notion References: Message-ID: Arien Malec wrote: > Apologies for feeding the fire, when we are rallying around a consensus, > but I've been concerned about the clash between syntax and semantics, and > I've finally reached a mini-epiphany: > The problem with PEP318 is that it is too powerful, and tries to do too > much. It is a sledgehammer for attacking three problems: > 1) Metadata, a la Java and C# > 2) class & static method defs > 3) Arbitrary post-definitional transformations of functions. Agreed. I think trying to address all of this with decorators is the wrong way to go. From chrisks at NOSPAMudel.edu Fri Aug 6 12:40:18 2004 From: chrisks at NOSPAMudel.edu (Chris S.) Date: Fri, 06 Aug 2004 16:40:18 GMT Subject: Object Reference? In-Reply-To: References: Message-ID: Michael Hudson wrote: >>Naturally, I could just recursively parse all the data comparing every >>element to every previously listed object, but is there a less >>obtrusive method? Python figures out when to delete objects based on >>the remaining references to an object. Is there a way to access this >>information to automatically lookup these references? Any help is >>greatly appreciated. > > > Well, there's gc.get_referrers() and gc.get_referrents(), but I think > they are probably overkill (see above). Thanks, these are exactly what I need. Pickle is just the file format. The data are Python constructs, so I shouldn't have to bother with the format at all, since I'm simply converting the Pickled file into generic Python data. Plus, writing my own Pickle parser would be hugely complicated since Pickle is essentially its own small programming language. From ptmcg at austin.rr._bogus_.com Fri Aug 20 18:29:48 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 20 Aug 2004 22:29:48 GMT Subject: Alternative decorator syntax decision References: <657d8oc3.fsf@python.net> Message-ID: > > > > I personally find J2 worse than the current pie > > syntax. Something that looks odd and does something > > odd seems the lesser evil vs something that looks > > normal yet does something odd. > Why is decorating a function by wrapping it with some "helping" logic of some sort perceived to be "odd"? I would guess that generators and list comps were thought "odd" by some when they were proposed, too, but we have acclimated ourselves to their concepts, and embraced them. I'm sure part of this receptiveness was the fact that the selected syntax did not include some eye-jarring splat of punctuation. But '@' will forever look odd, even after we have accustomed ourselves to the utility of function decoration, with the likes of memoize, etc. If you truly feel function decoration is an "odd" thing, why is it getting into the language at all? Why not instead look ahead to when function decoration is accepted as part of the rich toolkit of power Python programming, and marvel at how seamlessly it blends into the syntactic terrain. I think the only way this can happen is to incorporate decorators while maintaining the clean consistency of its syntax forms: source indentation to indicate hierarchy of logic (or declaration); conventional punctuation, such as [], :, and (); native data type constructs, such as lists and dictionaries; powerful class definition tools. Just because Java uses @ for declaring new function attributes does not sway me towards accepting it - I don't see us adopting {}'s in place of indentation, even though C, C++, Perl, and Java all use them. I see the absence of '@' in Python to be a *good* thing, and I hope hope hope that it will stay *out* of the language. -- Paul From bryanjugglercryptographer at yahoo.com Fri Aug 6 17:29:12 2004 From: bryanjugglercryptographer at yahoo.com (Bryan Olson) Date: 6 Aug 2004 14:29:12 -0700 Subject: How to force a single number to be a tuple References: Message-ID: <1a517b5.0408061329.429de7fc@posting.google.com> Gandalf wrote: > The syntax is very clear and logical. (As usual when working with > python.) Try to add one comma for each element - that will do the stuff. > Most of the languages are not so straightforward - they forbid the last > comma. The syntax may be logical, but it's not normal comma usage,. > Python is the best. :-) Python tuples overlap too much with lists, and differ from the functional/relational view in which a tuple is an element of the Cartesian product of zero or more domains. Cartesian product is associative; (1, (2, 3)) = ((1, 2), 3) and is canonically written: (1, 2, 3). Any object is identical to the one-tuple of that object. What Python calls 'tuples' are really immutable lists. -- --Bryan From pit.grinja at gmx.de Mon Aug 30 11:49:23 2004 From: pit.grinja at gmx.de (Piet) Date: 30 Aug 2004 08:49:23 -0700 Subject: Installation of mod_python 3.1.3 on Apache 2.0.50 on Windows Me/Win2k References: <39cbe663.0408290850.14452ab9@posting.google.com> Message-ID: <39cbe663.0408300749.2ef5bc81@posting.google.com> "Lucas Raab" wrote in message news:... > Why not post this to the mod_python mailing list?? The error looked like an error in some python installation scripts, so it seemed to me more "pythonic" than "apachic". Anyways, thanks for the hint. Piet From duncan.booth at invalid.invalid Tue Aug 17 05:27:44 2004 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 17 Aug 2004 09:27:44 GMT Subject: News server(NNTP library) and Python References: <81a41dd.0408162307.3eb1ea36@posting.google.com> Message-ID: export at hope.cz (Lad) wrote in news:81a41dd.0408162307.3eb1ea36 at posting.google.com: > I have a program that can send posts to a news server.The problem is > that I must find a free usenet(news) server that allows posting, which > is not easy. For this reason I would like to make a modification in my > program so that the program can act in a similar way how real news > server, that is to spread the new posts to another news server. But I > do not have much knowledge about the way how news server chooses > another news server to send it's new posting. > Can anybody give me a hint( idea)? If you are running on Windows and just want a news server for testing, get hold of a copy of Hamster (http://tglsoft.de/), this will act as both news server and news client and lets you set up your own local newsgroups. If you meant that you actually want a free news server to post to real newsgroups, then sign up with news.individual.net. You have to agree to some reasonable terms and conditions, but it is free. Real news-servers transfer news between each other by having a list of servers to which they will forward news they have received, so to run a real news server you need a peering agreement with an existing server, and you aren't going to get that. What you can do though is to write a program which works in the same sort of way as Hamster: i.e. it acts as a client to one or more upstream news-servers while also acting as a server. This isn't suitable for running a full news feed but works well when you have comparatively few newsgroups. From grante at visi.com Wed Aug 11 12:09:29 2004 From: grante at visi.com (Grant Edwards) Date: 11 Aug 2004 16:09:29 GMT Subject: How to get rid of "hex/oct constants > sys.maxint" warning? References: <411a3402$0$65564$a1866201@newsreader.visi.com> Message-ID: <411a44b9$0$65602$a1866201@newsreader.visi.com> On 2004-08-11, Christopher T King wrote: >> How _do_ I get rid of the warning? Is there a way to tell >> Python that the constant isn't an integer, it's just a bit >> pattern? > > The best way is to tell Python to silence the warning: > >>>> 0xc0047a80 > FutureWarning >>>> import warnings >>>> warnings.simplefilter('ignore',FutureWarning) Yup, that's what I was looking for. Now that I know how it's spelled, Google find's plenty of examples. :) -- Grant Edwards grante Yow! Yow! Am I cleansed at yet?! visi.com From robin at reportlab.com Wed Aug 18 12:43:56 2004 From: robin at reportlab.com (Robin Becker) Date: Wed, 18 Aug 2004 17:43:56 +0100 Subject: age of Python programmers In-Reply-To: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> Message-ID: <4123874C.8000304@chamonix.reportlab.co.uk> Marius Bernklev wrote: > "Lucas Raab" writes: > > >>One thing I've always kind of wondered is what is the average age of a >>Python programmer?? What age groups use Python?? Something to think >>about.... > > > 24. (anyone keeping count?) > > It's raining so I can't go home Gerrit Muller 47 Lucas Raab 14 OKB 20 Jeremy Jones 31 Ben Last 31 Guyon Moree 21 Tom Brown 31 Will McGugan 30 Christopher T King 19 Skip Montanero 50 Martin Jurczuk 26 Martin Jackson 55 Peter Wilkinson 32 oziko 24 Dave Opstad 50 Adonis 23 Peter Hickman 43 Axel Steiner 22 Larry Bates 49 Robin Becker 57 Thomas Heller 48 Paul McGuire 45 Wes Weston 55 P at draigBrady 30 Ian Sparks 34 Roel Schroeven 29 Christos "TZOTZIOY" Georgiou 32 Garry Herron 52 Ksenia Marasanova 31 Robert Boyd 40 Marius Bernklev 24 Count 31 Average 35.32258065 Stddev 12.43754289 -- Robin Becker From pythongnome at hotmail.com Mon Aug 30 19:22:41 2004 From: pythongnome at hotmail.com (Lucas Raab) Date: Mon, 30 Aug 2004 23:22:41 GMT Subject: console window not disappearing with py2exe References: <173c23bb.0408301410.49b27fe4@posting.google.com> Message-ID: <5FOYc.8738$6o3.5873@newsread2.news.atl.earthlink.net> In your original source file, change the .py file extension to .pyw. The .pyw extension tells the python exectuable to run without showing the console. Then remove the "windows" stuff in your setup file. "Matthew K Jensen" wrote in message news:173c23bb.0408301410.49b27fe4 at posting.google.com... > In another one of my silly apps, I'm using 'windows=' in the setup > script. I can't get the darn console window do disappear. Since the > said app is going to be used with people that have less-than-average > knowledge in computers, it is imperative that this window goes away. I > tried sys.frozen = "windows_exe" and it doesn't work. I'm not sure > what to do. Please save me! > > -Matt K Jensen From eric_brunel at despammed.com Mon Aug 16 03:57:56 2004 From: eric_brunel at despammed.com (Eric Brunel) Date: Mon, 16 Aug 2004 09:57:56 +0200 Subject: how to change the text in the title bar of the Tkinter windows References: <8f17f4bc.0408151822.1be2de2e@posting.google.com> Message-ID: Ali wrote: > When I open a window using the Tkinter GUI thing the title bar always > says "Tk". I would like to know how to change this. I would also like > to know how to cjange it on any other popup windows I may have. Please > help. Just use the 'title' method on your windows. See paragraph 45 in http://www.pythonware.com/library/tkinter/introduction/index.htm HTH -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From r.kleger at chello.nl Sat Aug 21 06:37:23 2004 From: r.kleger at chello.nl (Rafal Kleger-Rudomin) Date: Sat, 21 Aug 2004 10:37:23 GMT Subject: How to clean python interpreter's environment? In-Reply-To: <2on2lsFcqa7nU1@uni-berlin.de> References: <2omtogFck37uU1@uni-berlin.de> <2on2lsFcqa7nU1@uni-berlin.de> Message-ID: Reinhold Birkenfeld wrote: > Peter Hansen wrote: > >>Reinhold Birkenfeld wrote: >> >> >>>>Rafal Kleger-Rudomin wrote: >>>> >>>> >>>>>I'm looking for a command to reset interpreter's environment i.e. unload >>>>>all modules, delete variables etc. >>> >>>What about something like this: >>> >>>def clear(keep=("__builtins__", "clear")): >>> keeps = {} >>> for name, value in globals().iteritems(): >>> if name in keep: keeps[name] = value >>> globals().clear() >>> for name, value in keeps.iteritems(): >>> globals()[name] = value >> >>Well, that only removes all the references from the >>globals of the current module. Is that all that's >>wanted? >> >>Note that threads that are already running will not be >>removed, nothing in sys.modules will be removed, and >>there are doubtless a few other things in the interpreter >>that aren't quite so easy to get at. > > > Right. So I agree with you on ^D. Well, Control-D just exits python, at least on cygwin. That's not what I want. I should have explained the background of my question: I write some Python app on Windows using PythonWin IDE. It has own Python interpreter window, when I run or debug my app, it runs in that interpreter environment. But, after the first run, the environment is polluted with modules, vars etc. What I can do at this moment: - Exit IDE and run again every time I run/debug my app. - Run my app in external interpreter (but then I cannot debug with IDE) Another thing: Because of this 'cleaning problem', I write all my classes in the main file. I should put them in a module. But then I have to manually reload the module each time I edit it. Moreover, reload() also does not do the job perfectly. So a 'clean' command would be handy. Do you know any developers' guide addressing such work practices, practical tricks, project organisation? I have a book 'Python 2.1 Bible', it is cool but does not go so far. Best Regards, Rafal From John.Marshall at ec.gc.ca Fri Aug 20 11:43:35 2004 From: John.Marshall at ec.gc.ca (John Marshall) Date: 20 Aug 2004 15:43:35 +0000 Subject: Alternative decorator syntax decision In-Reply-To: References: <10ia1a9jm9tkuca@corp.supernews.com> <84GdneSa3r-TR7jcRVn-tw@powergate.ca> Message-ID: <1093016615.6397.3.camel@mango.cmc.ec.gc.ca> J2 J2 C1 Thanks, John From ajsiegel at optonline.com Tue Aug 24 19:47:52 2004 From: ajsiegel at optonline.com (Arthur) Date: Tue, 24 Aug 2004 23:47:52 GMT Subject: PEP318: radical notion References: <412a4222$0$293$626a14ce@news.free.fr> <412bc7e6$0$4065$626a14ce@news.free.fr> Message-ID: On Wed, 25 Aug 2004 00:57:41 +0200, Christophe Cavalaria wrote: >Why is it that there are always some people who doesn't understand all the >possibilities of decorators and so want to minimise their usefulness ? I can't understand, yet, talking about decorators as if they *are* something. We have shortedened some syntax. Before alpha 2, decorators were not. Now they ain't. ;) Art From aleaxit at yahoo.com Mon Aug 30 10:06:25 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 30 Aug 2004 16:06:25 +0200 Subject: PHP Documentation References: <4133124f$0$281$4d4ebb8e@news.nl.uu.net> Message-ID: <1gjc9sk.e6c0cwnxjvs5N%aleaxit@yahoo.com> Peter Hansen wrote: ... > 2) Many people think that the noise created by lots of user > comments would far outweigh the value of the good comments > that might be hidden somewhere within. As long as it's possible to request a view or download of the docs without the comments, I don't see how this could be a problem -- if you want to see the docs with comments you can, if not, you're no worse off than today. With the kind of threshold-setting and ratings for various commenters that (e.g.) slashdot uses, you could also set up your preferences to see _some_ of the comments but not all. In theory any wiki page could be "defaced" by one nasty minded vandal, in practice most wikis seem to work decently well -- maybe people react positively to being trusted. If comments (and posters thereof, eventually) can be rated, existing comments edited or removed only by authorized personnel, etc, etc, I suspect it would work. No doubt the needed infrastructure already exists on the widely appreciated PHP doc pages, it remains to be seen whether we're humble enough to just copy it wholesale or if the prospect of running PHP code in a key supporting role for Python is just too embarassing;-). Alex From phil at riverbankcomputing.co.uk Tue Aug 3 18:15:26 2004 From: phil at riverbankcomputing.co.uk (Phil Thompson) Date: Tue, 3 Aug 2004 23:15:26 +0100 Subject: PyQt - clear widget for redraw In-Reply-To: <410fad7d@news.maxnet.co.nz> References: <410b4492@news.maxnet.co.nz> <410fad7d@news.maxnet.co.nz> Message-ID: <200408032315.26204.phil@riverbankcomputing.co.uk> On Tuesday 03 August 2004 8:19 pm, Peter wrote: > Diez B. Roggisch wrote: > > Maybe it helps to put your sleep not in the drawing code, but between the > > arrival of different data sets to draw, thus limiting the redraws to an > > amount of lets say 10/s. > > Yes - tried that, but gives incomplete draw / flicker. There are lots of standard graphics techniques for eliminating flicker when drawing that you can exploit with PyQt. Double buffering for example - draw to a QPixmap and then blit it to the QWidget. Phil From omahacountingcrows at yahoo.com Sun Aug 22 20:18:18 2004 From: omahacountingcrows at yahoo.com (Patrick Smith) Date: Sun, 22 Aug 2004 20:18:18 -0400 Subject: Having problems installing wxPython Message-ID: <8JaWc.9419$0c.8772@read1.cgocable.net> Hi, I'm in the middle of trying to install wxPython from the wxPythonSrc-2.5.2.7 source. While running the makefile I get the following errors. In file included from include/wx/gsocket.h:172, from include/wx/sckaddr.h:24, from include/wx/socket.h:28, from include/wx/protocol/protocol.h:28, from include/wx/url.h:24, from src/common/fs_inet.cpp:30: include/wx/msw/gsockmsw.h:81: error: 'SOCKET' is used as a type, but is not defined as a type. include/wx/msw/gsockmsw.h:92: error: field `m_timeout' has incomplete type make: *** [netdll_fs_inet.o] Error 1 Anyone know how I can fix this and finish install wxPython. thanks. From timr at probo.com Mon Aug 16 01:05:01 2004 From: timr at probo.com (Tim Roberts) Date: Sun, 15 Aug 2004 22:05:01 -0700 Subject: A email.cgi script References: Message-ID: wonder wrote: > >I would like to write a python script that can be used in my website for > other people whoever browse my webside to send an email using my smtp >server. Is there any sample python script can do that? It looks lik you have one here. >Here is my python script, but it does not display To and From editbox in >the webpage for user type in their addresses: Well, then, add and to your web page and fetch them here. The rest of this looks fine. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From ialbert at mailblocks.com Wed Aug 4 22:27:18 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Wed, 04 Aug 2004 22:27:18 -0400 Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) In-Reply-To: References: <1646998998.20040804190026@MailBlocks.com> Message-ID: Bruce Eckel wrote: > This is very similar to attributes/metadata in Java J2SE 5 and in C#. > The thing is, metadata is a little bit weird; it's intentionally > outside of the domain of the 'normal' programming language, because it > expresses things that you can't or shouldn't within the normal > programming language. So you _do_ need an escape mechanism. But the escape mechanism does not have to take the shape of funny, loaded symbols. Are these really necessary? Aren't they a just premature solution (shortcuts) to a problem that may not even exist? I am most irritated by the requirement of spreading out a function definition over two lines. > also takes a little bit of getting used to; it's orthogonal to what > you normally think of as a language feature. But the potential for > metadata features, at least in Java, is very powerful. I always felt that Java was too rigid and that any kind of loosening feels like a breath of fresh air. That is much less the case in Python. If anything people sometimes want a little more "discipline". This is what this PEP was initially about. Too bad that instead of quickly settling at something really simple like: def static foo(): ... the urge to solve all future problems in the most generic manner possible lead to increasingly hairy syntaxes and made the decision process so prolonged, fruitless and boring that GvR just got fed up with everybody. Istvan. From franbarlow at mail.com Sat Aug 14 11:32:10 2004 From: franbarlow at mail.com (Fran) Date: 14 Aug 2004 08:32:10 -0700 Subject: Help understanding Scheme's syntax, procedures and calls References: <95f168b0.0408120120.31433dc7@posting.google.com> <95f168b0.0408121215.f89c842@posting.google.com> <411cba6f$0$9687$afc38c87@news.easynet.co.uk> Message-ID: <95f168b0.0408140732.6a817c0a@posting.google.com> Peter Hickman wrote in message news:<411cba6f$0$9687$afc38c87 at news.easynet.co.uk>... > > Thanks for the help. It's not homework but from an old exam paper, but > > the girl's English isn't absolutely fluent and I'm looking for a > > simple way to explain the expressions and functions. > > If there are points to be won for brevity then the answer is 'two functions (one > with a helper) to compute factorials' Thanks greatly ... Admirably concise. FRAN From bhk at dsl.co.uk Mon Aug 30 18:27:45 2004 From: bhk at dsl.co.uk (Brian {Hamilton Kelly}) Date: Mon, 30 Aug 2004 23:27:45 +0100 (BST) Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <25u2j0d9bfulqljo6d2jbls2v52l1jk3sd@4ax.com> Message-ID: <20040830.2227.57577snz@dsl.co.uk> On Sunday, in article foo at bar.net "Mac" wrote: > Hmm. No explicit comparison was made, but since the post is a cautionary > tale (well, the post is a rambling mess, but I think it is trying to be a > cautionary tale) I think the comparison is understood. "Cautionary tale"???? Cautionary tale, my arse. The post was the fuckwitted ramblings of a total raving looney; kill the thread (and the original poster) and forget about it. -- Brian {Hamilton Kelly} bhk at dsl.co.uk "I don't use Linux. I prefer to use an OS supported by a large multi- national vendor, with a good office suite, excellent network/internet software and decent hardware support." From yav_a at hotmail.com Tue Aug 3 09:44:13 2004 From: yav_a at hotmail.com (yawar) Date: Tue, 03 Aug 2004 09:44:13 -0400 Subject: Solved: pyUNO Converter References: Message-ID: <1019b52d614f1552fe74db1d83559581@localhost.talkaboutprogramming.com> One could create the properties list in one go: properties = [PropertyValue() for i in range(3)] And then fill it in: properties[0].Name = ... properties[0].Value = ... From peter at engcorp.com Mon Aug 30 15:56:08 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 30 Aug 2004 15:56:08 -0400 Subject: how to get size of email attachment In-Reply-To: <63b5e209.0408301105.58b9207a@posting.google.com> References: <63b5e209.0408301105.58b9207a@posting.google.com> Message-ID: Joh wrote: > i'm looking for a way to get total size of an email (with its attached > files) using library such as poplib, or ? > > can someone help me or give me an url from where to start ? Looking in the docs for poplib, I found this: http://docs.python.org/lib/pop3-objects.html It describes how using .list() should provide you with results in the form (response, ['mesg_num octets', ...]). The word "octets" here refers to the number of bytes, essentially, in each message. -Peter From beliavsky at 127.0.0.1 Tue Aug 3 18:51:03 2004 From: beliavsky at 127.0.0.1 (beliavsky@aol.com) Date: 3 Aug 2004 17:51:03 -0500 Subject: Modern dead-tree Python resources References: Message-ID: <411016d7_1@127.0.0.1> Michael Ekstrand wrote: >Is there a good book that covers Python at least through 2.2 (including >new-style classes, etc.)? I'm particularly looking for something with >large appendices of reference material. (alternatively, if someone's >publishing print versions of the Python documentation, that would >possibly be of interest. A good reference for Python 2.2 is "Python in a Nutshell", by Alex Martell. Also good, and more pedagogical, is "Learning Python", 2nd. edition, by Lutz and Ascher. O'Reilly published both books. ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--- From aranders at insightbb.com Sat Aug 7 01:41:04 2004 From: aranders at insightbb.com (Alan Anderson) Date: 6 Aug 2004 22:41:04 -0700 Subject: RELEASED Python 2.4, alpha 2 References: <411231C8.3020308@interlink.com.au> <2-SdnZCwNs1SwI_cRVn-uQ@powergate.ca> Message-ID: <53449fcb.0408062141.6e90681e@posting.google.com> Peter Hansen wrote: > Yes, of course after using them for a while they will become more > readable, but there are people who have learned to speak Klingon as > well -- and that doesn't change the fact that Klingon is deliberately > very difficult to learn and awkward. Pardon me for jumping in, but I happen to be attending a conference on the Klingon language at the moment and I wanted to correct a misunderstanding. Yes, Klingon is deliberately "alien", being intentionally created to be unlike many natural languages in many ways. But it's actually rather easy to learn, and it's only "awkward" in a couple of minor ways (embedding comparatives in larger sentences, for example) -- *every* language has its awkward spots. Were Klingon a natural language, its regularity would be exceptional. This is just an anectodal data point that might let you know that what is difficult and awkward from your point of view could very well be simple and straightforward for others who don't share your preconceptions. -- Alan Anderson, professional programmer and amateur Klingonist proud member of the Klingon Language Institute since 1995 qo'mey poSmoH Hol -- language opens worlds -- http://www.kli.org/ From webmaster at smallco.com Wed Aug 18 21:57:46 2004 From: webmaster at smallco.com (Webmaster) Date: Wed, 18 Aug 2004 21:57:46 -0400 (EDT) Subject: Automatic response to your mail (Error) Message-ID: <200408190157.VAA15442@monty.bcentralhost.com> The automatic reply to this e-mail which you should have received in response to your e-mail to webmaster at smallco.com has not been defined. Please contact postmaster at smallco.com for assistance. From amk at amk.ca Sat Aug 7 22:19:43 2004 From: amk at amk.ca (A.M. Kuchling) Date: Sat, 07 Aug 2004 21:19:43 -0500 Subject: Going the PL/1 way References: Message-ID: <8YudnZUJ4NciEIjcRVn-jA@speakeasy.net> On Sun, 8 Aug 2004 01:21:31 +0200, Mikl?s wrote: > So do you say "them and us", Python developers vs. users? > I've always had the "we all"-feeling. Maybe that's over. That's always been the case, between people who contribute (in time, money, skills) and people who don't, for whatever reason. The saving grace is that it's very easy to become a developer; just write some code, help with development, and all of a sudden you're a developer. --amk From noone at here.com Wed Aug 25 09:52:20 2004 From: noone at here.com (M. Clift) Date: Wed, 25 Aug 2004 14:52:20 +0100 Subject: Just a quick one References: Message-ID: Hi Benjamin, Thanks, that was quick! How would I print just 'Bob' if the result was '[('Bob',One'),('Mary','Spam')] ? As print Name_List[0] obviously gives ('Bob','One') M From zathras at thwackety.com Tue Aug 3 06:30:48 2004 From: zathras at thwackety.com (Michael Sparks) Date: Tue, 3 Aug 2004 11:30:48 +0100 (BST) Subject: Starkiller? In-Reply-To: Message-ID: On Tue, 3 Aug 2004, Bill Dandreta wrote: > Neuruss wrote: > > Does anyone have news about Starkiller? > > Here's the Starkiller website: > > http://web.mit.edu/msalib/www/urop/ > > It says hopefully it will be released by October. That page is 3 years old though: HTTP/1.1 200 OK Date: Tue, 03 Aug 2004 09:29:09 GMT Server: MIT Web Server Apache/1.3.26 Mark/1.4 (Unix) mod_ssl/2.8.9 OpenSSL/0.9.6g ==>Last-Modified: Tue, 21 Aug 2001 01:18:19 GMT ETag: "31ae0ce6-f60-3b81b6db" Accept-Ranges: bytes Content-Length: 3936 Connection: close Content-Type: text/html Mind you, given the comments he made in June and others people have made in this thread, it's entirely possible he was just prescient 3 years ago about which October :) We're probably just all an insecticide dump :) Michael (Also patiently waiting to play with it :) From sbabbitt at commspeed.net Tue Aug 10 11:07:12 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Tue, 10 Aug 2004 08:07:12 -0700 Subject: flicker in wxBufferedPaintDC References: Message-ID: <1092150853.281913@news.commspeed.net> "Markus von Ehr" wrote in message news:cfaj0e$b4f$1 at news2.rz.uni-karlsruhe.de... > Hi, > > I actualize a buffer in an event handler routine: > > if BUFFERED: > # If doing buffered drawing, create the buffered DC, giving it > # it a real DC to blit to when done. > cdc = wxClientDC(self) > dc = wxBufferedDC(cdc, self.buffer) > > dc.BeginDrawing() > if self.image: > dc.DrawBitmap(self.image.ConvertToBitmap(), 0,0) > dc.EndDrawing() > > and paint the buffer in the OnPaint method. > > def OnPaint(self, event): > if BUFFERED: > # Create a buffered paint DC. It will create the real > # wxPaintDC and then blit the bitmap to it when dc is > # deleted. Since we don't need to draw anything else > # here that's all there is to it. > dc = wxBufferedPaintDC(self, self.buffer) > else: > dc = wxPaintDC(self) > # since we're not buffering in this case, we have to > # paint the whole window, potentially very time consuming. > self.DoDrawing(dc) > > > but the window is flickering. The window displays the liveimage of a > connected camera. > How could I get rid of the flickering? > > Thanks for any hints, > > Markus You could try using a self.PrepareDC(dc), or perhaps a wx.SafeYeild(), or perhaps you need the wx.NO_FULL_REPAINT_ON_RESIZE flag set, or perhaps you just need to speed up execution , try http://psyco.sourceforge.net/. hope this helps. Tom From squirrel at WPI.EDU Tue Aug 3 15:52:34 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 3 Aug 2004 15:52:34 -0400 Subject: Mucking with the calling scripts namespace (For a good reason, honest!) In-Reply-To: References: Message-ID: On 3 Aug 2004, Doug Rosser wrote: > 1. Python doesn't provide an obvious way to modify the __main__ > namespace. You can peek at values with "global" but you can't treat it > like a dictionary at runtime. The globals() function returns just the dictionary you're looking for. Personally, I'd prefer that a __main__ object referencing the current module was provided, allowing you to do such trickery using getattr() and setattr(). Something as simple as the following would suffice: class objifier(object): def __init__(self,d): self.__dict__ = d __main__ = objifier(globals()) Then you do stuff like: >>> __main__.b = 6 >>> b 6 >>> b = 20 >>> __main__.b 20 >>> getattr(__main__,"b") 20 >>> setattr(__main__,"b",6) >>> b 6 From export at hope.cz Thu Aug 19 04:23:25 2004 From: export at hope.cz (Lad) Date: 19 Aug 2004 01:23:25 -0700 Subject: Py2Exe PROBLEM Message-ID: <81a41dd.0408190023.44d34c44@posting.google.com> I try to make an exe file from my script with help of Py2exe but I am not successfull. I have my script start.py that has only one command ############### import rgs.py ############## (rgs.py is the real program.) I use the following setup script: ################################# from distutils.core import setup import py2exe setup( # The first three parameters are not required, if at least a # 'version' is given, then a versioninfo resource is built from # them and added to the executables. version = "0.5.0", description = "py2exe sample script", name = "py2exe samples", # targets to build windows = ["start.py"], console=["start.py"] ) ########################### When compilation finishes I get: The following modules appear to be missing ['blackbox', 'timing', 'rgs.py'] Can you please help me how to solve the problem? Thank you LAd From rogerb at rogerbinns.com Tue Aug 24 13:17:29 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Tue, 24 Aug 2004 10:17:29 -0700 Subject: fun with unicode files References: <6579x7eo.fsf@python.net> Message-ID: Thomas Heller wrote: > I wonder: do I really have to check for the BOM manually, or is there a > Python function which does that? It should be part of the standard library IMHO. Here is my own more complete implementation: http://www.bitpim.org/pyxr/c/projects/bitpim/common.py.html#0286 Roger From anthonybaxter at gmail.com Fri Aug 27 09:05:00 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 27 Aug 2004 23:05:00 +1000 Subject: allowing braces around suites In-Reply-To: <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> Message-ID: On Fri, 27 Aug 2004 14:55:26 +0200, Kjetil Torgrim Homme > thank you for the reference! I'm happy to see that Guido wasn't > strictly opposed to such a feature 10 years ago. Regardless of what he thought back then, I think I can say with absolutely no fear of contradiction that there is no chance in hell of braces appearing in Python... ever. If your tool gets something wrong, fix the tool, don't try and change the language, just for the convenience of a broken tool. From simoninusa2001 at yahoo.co.uk Thu Aug 26 12:09:48 2004 From: simoninusa2001 at yahoo.co.uk (Simon John) Date: 26 Aug 2004 09:09:48 -0700 Subject: building errors with py2exe Message-ID: Maybe 'main.py" is not a good name for a module, as the "main" method would be confused with the "main" module? Otherwise, yeah we need more code to look at. From yangzhangbuffalo at hotmail.com Tue Aug 17 14:37:49 2004 From: yangzhangbuffalo at hotmail.com (Yang Zhang) Date: Tue, 17 Aug 2004 13:37:49 -0500 Subject: is it possible to create an object by its name in the run time References: <003d01c48407$45aeaf10$6400a8c0@offer> Message-ID: Hi all, I wonder if it is possible to create an object of func, class or method in the run time by it's name? To make it more clear, let me show you an example: I parsed the python code and found a function with name 'len'. I want to know if it is a build-in func(where can I look up?). If so, ignore it otherwise I want to find out which module is it defined in. All I know is the name (which is a string), and all the modules that this program have imported. In the same way, I also need to process the class and methods call. I wonder if it is possible? I will appreciate your help very much!! -Ryan From jjl at pobox.com Thu Aug 19 14:55:59 2004 From: jjl at pobox.com (John J. Lee) Date: 19 Aug 2004 19:55:59 +0100 Subject: Merging pdf documents with Python References: Message-ID: <87hdqzt0sg.fsf@pobox.com> writes: [...] > >From: "Daryl Middleton" [...] > >Can python be used to merge pdf documents into a single pdf > file so that I [...] > http://www.reportlab.org/ [...] www.reportlab.org is ReportLab's open source site. The part of ReportLab's software that lets you concatenate, and otherwise process, pre-existing PDF files (rather than making new PDF files) is called PageCatcher. PageCatcher is not open source software. John From me at privacy.net Sun Aug 8 09:21:53 2004 From: me at privacy.net (Dan Sommers) Date: 08 Aug 2004 09:21:53 -0400 Subject: Encryption between Python & PHP References: Message-ID: On Sun, 8 Aug 2004 14:00:32 +0100, Geoff Caplan wrote: > I have little crypto knowledge, and at first I though that something > like blowfish was a standard and different libraries should be > compatible. Now I suspect that internal implementation varies between > libraries and you have to encrypt/decrypt with the same library. Can > anyone enlighten me? I can't help much with your other questions, but I do know about this one. By definition, blowfish is blowfish is blowfish. Any (properly implemented) blowfish library will be compatible with another; if you encode something with one library, you will be able to decode it with the other. It is up to you to use the same key and to make sense of the information once you decrypt it. That said, yes, it is possible that the internal implementation details may vary slightly between libraries, but not in ways that the user will notice. Think of this like calculators: although calculators use different hardware and different display devices, they all (should) give the same answer to the same multiplication problem (keeping the multiplications in question simple enough so as not to cause some sort of underflow or overflow error or loss of precision; thankfully, blowfish implementations do not suffer even this limitation). HTH, Dan -- Dan Sommers Never play leapfrog with a unicorn. From grante at visi.com Thu Aug 26 12:08:56 2004 From: grante at visi.com (Grant Edwards) Date: 26 Aug 2004 16:08:56 GMT Subject: Best processor (i386) for Python performance? References: <412dfb17$0$65599$a1866201@newsreader.visi.com> Message-ID: <412e0b18$0$65566$a1866201@newsreader.visi.com> On 2004-08-26, Dave Brueck wrote: >>>In terms of multithreading, an I/O intensive app that is >>>threaded can make use of dual procs. Otherwise threaded apps >>>can't for technical reasons (GIL and such but don't need to get >>>into those details). >> >> That's rather dissappointing. If I write a multi-threaded app >> in C it can utilize multiple processors, but the same app in >> Python can't? > > Depends on what the multithreaded app _does_. If multiple > processors are present then Python will use them, but how well > they get used depends on how much and for what reasons the GIL > gets released. > > I/O is the most common reason, so adding another processor to > an I/O bound program can give you a good performance boost (in > our lab I've seen easily 75% improvement over a single proc > box for a program that was very I/O bound, but I haven't > measured it to see if it's closer to 75% or to 100% > improvement). Now that I think about it, in my multi-threaded apps all the threads almost always end up blocking on I/O. A couple years back I even added a GIL release to some of the termios() calls so that I could get more parallelism when threads are waiting for serial ports to drain or flush. -- Grant Edwards grante Yow! I wonder if there's at anything GOOD on tonight? visi.com From brian at rk-speed-rugby.dk Fri Aug 20 03:15:08 2004 From: brian at rk-speed-rugby.dk (Brian Elmegaard) Date: 20 Aug 2004 09:15:08 +0200 Subject: Merging pdf documents with Python References: Message-ID: "Daryl Middleton" writes: > Can python be used to merge pdf documents into a single pdf file so that I > do not have to manually insert each one. Thanks pdflatex with pdfpages is your friend. Of course you can make a python script that runs it. -- Brian (remove the sport for mail) http://www.et.dtu.dk/staff/be From mwh at python.net Wed Aug 25 07:01:53 2004 From: mwh at python.net (Michael Hudson) Date: Wed, 25 Aug 2004 11:01:53 GMT Subject: Readline module References: Message-ID: Jonathan Daugherty writes: > Hello all, > > I've read some posts here talking about the fact that the 'readline' > module packaged with python is only good for augmenting the behavior > of the interactive interpreter. Um, this seems a stretch. > Can anyone recommend a readline-style alternative for building an > app with an interactive prompt (on Linux, python 2.3)? My pyrepl library is designed for exactly that: http://codespeak.net/pyrepl Cheers, mwh -- 31. Simplicity does not precede complexity, but follows it. -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html From mandrzejewski at besancon.parkeon.com Wed Aug 4 09:29:00 2004 From: mandrzejewski at besancon.parkeon.com (Mike Andrzejewski) Date: 04 Aug 2004 15:29:00 +0200 Subject: EOL - scanning single-quoted string In-Reply-To: <1091625659.4110e2bb6db73@www-mail.usyd.edu.au> References: <1091625659.4110e2bb6db73@www-mail.usyd.edu.au> Message-ID: <1091626140.4281.110.camel@dhcp79-50.besancon.parkeon.com> Here, you should double the '\' character, but it also raise an error: "bogus escape (end of line)" You can try: re.subn('/', '\\\\', str) The result string will be "\\My Documents\\test", and '\' will be usable for next call. Le mer 04/08/2004 ? 15:20, Ajay a ?crit : > hi! > > I am developing an application for a pocket pc. > i have a small gui which allows users to select files using a file dialog > box. however the file, selected is represented as '/My Documents/test' > which when i try to open gives me an error. > so what i would like to do is replace '/' by the windows '\' > however when i try > str='/My Documents/test' > re.subn('/', '\', str) > > i get an error saying - SyntaxError: EOL while scanning single-quoted > string > > how can i replace the slashes. > > thanks > > cheers > > -- > Ajay Brar, > CS Honours 2004 > Smart Internet Technology Research Group > > > > > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. -------------- next part -------------- An HTML attachment was scrubbed... URL: From peufeu at free.fr Sun Aug 1 07:31:12 2004 From: peufeu at free.fr (=?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?=) Date: Sun, 01 Aug 2004 13:31:12 +0200 Subject: Get SystemDrive variable References: <_xtOc.26574$BU4.1267510@news20.bellglobal.com> Message-ID: Not only that, but different versions of Windows have it in a different place. Sometimes it's in c:\windows\mydocuments or something. You better get the folder path for Documents and Settings from the registry rather than starting from C: On Fri, 30 Jul 2004 11:10:50 -0400, JY Doyon wrote: > I'm writing a script that copies all information from the "Documents and > Settings" folder for backup purposes. My problem is that some machines > have > the OS installed on a different drive than C:\. Is there any way to get > the > environment variable "SystemDrive" with python? > > Thanks for the help > > From joe at invalid.address Thu Aug 26 15:10:54 2004 From: joe at invalid.address (joe at invalid.address) Date: Thu, 26 Aug 2004 19:10:54 GMT Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: xah at xahlee.org (Xah Lee) writes: > Larry Wall and Cults > (Lazyness, Impatience and Hubris) > 200012 [ Poor standup comedy deleted ] > These brain-washing phenomenon, are not limited to fanatical > life-and-death or otherwise dire beliefs. You see it work in all > manners of human thought in the general sense. From culture formation > to fashion to commercialism. Surely you have heard of Adolf Hitler Godwin! In the first post of the thread too... Joe -- If you don't think too good, don't think too much - Ted Williams From xavier_combelle at yahoo.fr Fri Aug 13 13:39:46 2004 From: xavier_combelle at yahoo.fr (Xavier Combelle) Date: Fri, 13 Aug 2004 19:39:46 +0200 Subject: Python indentation deters newbies? In-Reply-To: References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: <411cfc0c$0$29658$636a15ce@news.free.fr> >> I'm not saying that Python's use of indentation is bad, just that it >> stops many programmers from trying it. > > > I really question whether we are looking for such programmers. > They sound rather close minded and perhaps even lazy... Laziness is maybe not a reason to not use Python. I choose python because I am lazy: the absence of useless braquets is the best gift python gived to me. As a C programmer, I am dreaming of a tool that allow me to use the indentation syntax to write C programms. I would feel my self so much efficient. From paolo_veronelli at yahoo.it Thu Aug 12 12:31:57 2004 From: paolo_veronelli at yahoo.it (paolo veronelli) Date: Thu, 12 Aug 2004 18:31:57 +0200 Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: References: Message-ID: On Wed, 11 Aug 2004 11:40:32 -0400, Peter Hansen wrote: > John Marshall wrote: >> How about the following, which I am almost positive >> has not been suggested: >> ----- >> class Klass: >> def __init__(self, name): >> self.name = name >> >> deco meth0: >> staticmethod >> def meth0(x): >> return x >> >> ----- >> 1) The decorators clearly apply to a specific method/function, >> therefore there is no need to do any stack pushing in memory >> until the method/function definition is done. > > Problems with that: duplication (since you now have the name > of the function in two places) and readability (it's harder to > see the "def" because the name you picked is too close to it > in length and appearance). > > On the other hand, there's no need to have the function name > there (was anyone complaining about "stack pushing"?), so > maybe just using "decorate" would be okay, or a different > keyword: > > class Klass: > # init set > > decorate: > staticmethod > def meth0(x): > return x I think 'mutate' is better then 'decorate', and anyway I like to see what is mutated and the possibility to explicitate it make possible to move decorations from this position ,I put them where I like (at least if I have to call them decorations) even in another file... so class Klass: def meth0(x): return x mutate meth0: staticmethod mutate Klass.meth0: debugged reads good to me. Paolino -- ....lotta dura per la verdura From yong at net.tamu.edu Wed Aug 11 11:47:00 2004 From: yong at net.tamu.edu (Yong Wang) Date: Wed, 11 Aug 2004 10:47:00 -0500 (CDT) Subject: Print command Message-ID: <20040811154700.B70211589B@net.tamu.edu> Hi, All: For unknow reasons, I often get compiler error in the print statements. For example: I have following codes: if len(currentFiberCode) > 0 : print string.ljust(expandFiberCode(currentFiberCode,buildingRoom),30), \ string.rjust(`currentTotal`,6), \ string.rjust(`currentAvailable`,11), \ string.rjust(`sm_ava`,7), \ string.rjust(`mm_ava`,6), \ string.rjust(`sm_used`,9), \ string.rjust(`mm_used`,9) else: print 'data exist in fiber database table' When I comiped all the codes, I got : Compiling ./NetDBfiber.py ... File "./NetDBfiber.py", line 1086 string.rjust(`currentTotal`,6), \ ^ SyntaxError: invalid token How can I fix the problems ? Thanks a lot. Yong From cjw at sympatico.ca Thu Aug 19 13:58:35 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Thu, 19 Aug 2004 13:58:35 -0400 Subject: PEP 318: Can't we all just get along? In-Reply-To: References: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: Roy Smith wrote: > Anthony Baxter wrote: > >>>Look, name-mangling is horrid, and I don't think anyone's defending it. But >>>at the same time, "name mangling is there" is not an argument for extending >>>the horror to a whole new level. > > > Paul Morrow wrote: > >>I disagree. It's an effective name-hiding technique. Simple + >>Effective = Good. > > > I disagree with your disagreement :-) > > I find a mix of text and puctuation difficult to read. Human brains > don't read letters, they read whole words. That's why, for example, > it's so easy to make a typo and not notice it. I find "word.word" easy > to parse, but "word.__word" much more difficult. I agree, but see this as similar to the naming convention: long_symbolic_representation at first glance, this looks like three names why not: longSymbolicRepresentation? this makes the oneness clearer Returning to the subject line - When will the final decision be handed down? My own preferences are: (1) transform or transformer not decorator (2) the transforms should follow the thing being transformed. i.e. after the script has declared the name. (3) a list of transforms. (4) the list should have one entry per line, to make reading easier. Colin W. I don't know if it's > the switching back and forth between letters and symbols, or the > juxtaposition of the two symbols down on the baseline (i.e. ".__") that > makes it hard to read. > > This is true of the __name__ convention for internal names too, but > somehow I don't find that as bad. Maybe because it's symmetric? Maybe > because my brain recognizes the whole __name__ as a unit, with the > "name" part of it being what I really recognize? > > Even worse is when mix them. Stuff like "__myPrivateFunc.__name__" is > total gibberish to me. > > Oh my god, I just realized (Ob decorator comment here) that if we start > having people write private decorators, we'll have things like: > > @__decorator > > which really makes me barf. From joe at schmoe.com Mon Aug 30 16:01:28 2004 From: joe at schmoe.com (John Doe) Date: Mon, 30 Aug 2004 20:01:28 GMT Subject: Search for AVI file? Message-ID: I realise that this is not really a python question, but python's the only language I'd be comfortable trying to deal with this. What I need is to search a drive and find all the AVI format files that are NOT listed with the AVI extension. I'm looking over an old drive of mine from an old computer. I know the files were renamed with the wrong extension, but I know that they were originally AVI files. Can python do this for me? Any hints? Anybody have a link to something that would already do this? I appreciate any help. From eppstein at ics.uci.edu Mon Aug 23 15:14:26 2004 From: eppstein at ics.uci.edu (David Eppstein) Date: Mon, 23 Aug 2004 12:14:26 -0700 Subject: Standard graph API? References: Message-ID: In article , Phil Frost wrote: > +1 for standard graph API! > > I don't have a "high-end" use for it, but I did write a program which > graphs the revision history of a software repository. It would have been > nice to have most of that code in a library, and if such a library > existed, it would probably implement operations I was too lazy to > implement, such as coloring. I have a random sample of graph algorithms implemented in http://www.ics.uci.edu/~eppstein/PADS/ I use the existing Guido-standard graph representation, that is: iter(G) and iter(G[v]) list vertices of G and neighbors of v in G v in G and w in G[v] test existence of vertices and edges in G It includes both simple basic graph algorithm stuff (copying a graph, a DFS implementation that works non-recursively so it doesn't run into Python's recursion limit) and some much more advanced algorithms (e.g. non-bipartite maximum matching). -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ From a at b.com Sun Aug 15 15:48:13 2004 From: a at b.com (wonder) Date: Mon, 16 Aug 2004 03:48:13 +0800 Subject: apache 1.3 started failed with mod_python 2 Message-ID: Hi, Does anyone have any instruction about how to install mod_python 2 with apache 1.3 support? After installed mod_python 2 in my FreeBSD 5.2 Current system, and added moduleLoad and *.c in the apaache 1.3 httpd.conf file, apachectl restart got "reference .c not found" error. Thanks sam From ialbert at mailblocks.com Sat Aug 7 17:37:48 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Sat, 07 Aug 2004 17:37:48 -0400 Subject: Going the PL/1 way In-Reply-To: References: Message-ID: Michael Hudson wrote: > Which you've made up: sorted is a builtin in 2.4. > > By all means carp about the new features, but -- particularly if > you're going to be sarcastic about it -- please get it right. actually, the last time I read this PEP it was about a classmethod list.sorted() http://mail.python.org/pipermail/patches/2004-January/013946.html Istvan. From avner at skilldesign.com Fri Aug 27 06:14:18 2004 From: avner at skilldesign.com (Avner Ben) Date: Fri, 27 Aug 2004 12:14:18 +0200 Subject: Alternative decorator syntax decision In-Reply-To: <412CC529.9060700@chamonix.reportlab.co.uk> References: <412cc31c$1@news.012.net.il> <412CC529.9060700@chamonix.reportlab.co.uk> Message-ID: <412efced$1@news.012.net.il> Robin Becker wrote: >[snip] > except that these wrappers/transformers/decorators are able to do what > they like to the code including turning methods into properties, > changing the argument list etc etc etc. > Which is ok with me, as long as they only stress and specialize the status of the function (how) but do not completely alter the requirement (as understood from the name and arguments). Once this is not only allowed, but actively supported by the language, reading Python will become as easy and obvious as reading COBOL. Avner. From vincent at visualtrans.de Thu Aug 5 05:05:17 2004 From: vincent at visualtrans.de (vincent wehren) Date: Thu, 05 Aug 2004 11:05:17 +0200 Subject: Embedding python In-Reply-To: References: Message-ID: Jon Kinsey wrote: > I've embedded python in a program, am I right in thinking python has > to be installed on a machine for my program to work? Not entirely true: as long as python23.dll (or whatever version you are using) is available to your program, your program will work. (So you need to distribute at least this dll with your program). However, this only allows you to use any built-in functionality of python. Once you want to import modules from the standard library or from other packages, you will need to have them installed. The installed version of (the) python (library/package) has to be of/for the same (major) version as the Python version your program uses. Which brings you to your next question: > > If so how can I find out if python is installed/what version is > installed - programatically and cross platform. > > Jon If you need more than built-ins, you may want to consider distributing your own Python (cf. applications such as Paint Shop Pro 8.x, OpenOffice.org, or Zope on Windows ) along with your application and make it live in a sub directory. By tweaking the right environment variables from within your app, you'll be sure to get the "right Python" - independent of the fact whether or not the ("right") Python is installed or not. -- Vincent Wehren From mauriceling at acm.org Tue Aug 24 18:55:37 2004 From: mauriceling at acm.org (Maurice LING) Date: Tue, 24 Aug 2004 22:55:37 GMT Subject: python raw strings? Message-ID: <412bc766$1@news.unimelb.edu.au> I'm trying to toy around with PLY (python lex-yacc) by David Beazley from University of Chicago and realized that the lex module uses python raw strings. What are python raw strings and how are they different from regular strings? I've tried to look up in the python documentation but it just vaguely brushes through by saying that python raw strings are prefixed with "r" or "R". In PLY, "+" is "r'\+'" but "-" is "r'-'", why is there an extra "\" in "+"? When to use the extra "\" and when not? Can someone point me in the correct direction? Thanks Maurice From tim.peters at gmail.com Mon Aug 2 19:56:09 2004 From: tim.peters at gmail.com (Tim Peters) Date: Mon, 2 Aug 2004 19:56:09 -0400 Subject: Microbenchmark: Summing over array of doubles In-Reply-To: <4d642979.0408021532.2ca19f2f@posting.google.com> References: <4d642979.0407312049.7a8aecab@posting.google.com> <4d642979.0408021532.2ca19f2f@posting.google.com> Message-ID: <1f7befae04080216565c033835@mail.gmail.com> [Yaroslav Bulatov] ... > A better estimate of error difference would use random digits as > opposed to [x]*10000000, but I don't know how I would calculate exact > answer in any reasonable amount of time. (using Decimals takes over a > second for 4000 array (with conversion)) Google on floating point distillation It's possible to compute the exact sum of a list of floats using float arithmetic, where, ignoring overflow, the result is a minimal set of fp numbers whose mathematical (infinite precision) sum exactly equals the mathematical sum of the inputs. In the worst case the best of these methods can require O(log N) passes over the list of N inputs, but in real life they usually converge to the result in two passes independent of N, sometimes with a third pass but over a very short list of floats. The better-known "Kahan summation" technique is essentially a partially-broken computation of the two highest-order components of one distillation pass. A case like summing [1e100] + [1.0] * (N-1) shows that left-to-right can deliver arbitrarily bad results (the fp sum of that is 1e100 regardless of N). From aleaxit at yahoo.com Thu Aug 26 04:35:10 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 10:35:10 +0200 Subject: Why return None? References: Message-ID: <1gj4fj6.kfkov1iafzb2N%aleaxit@yahoo.com> Martin DeMello wrote: > Ayose wrote: > > > > If you can use python 2.3 or newer, try with [::-1] > > > > >>> def f(m, n): > > ... print (m + n)[::-1] > > ... > > >>> f([1,2,3], [10,20,30]) > > [30, 20, 10, 3, 2, 1] > > Thanks! Where can I look this up? There should be recipes for such handy shortcuts in the Python Cookbook (the current printed edition doesn't have this one as it only covers Python 1.5.2 to 2.2, but we're preparing a second edition focusing on Python 2.3 and 2.4). In Python 2.4, by the way, reversed(x) [[using the new built-in function 'reversed']] is most often preferable to x[::-1]. reversed returns an iterator, optimized for looping on, but if you need a list, tuple, etc, you can just call list(reversed(x)) and so on. Alex From apardon at forel.vub.ac.be Tue Aug 17 08:56:54 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 17 Aug 2004 12:56:54 GMT Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> <30260531.0408131853.18ec2446@posting.google.com> <412040f8$0$8087$a1866201@newsreader.visi.com> Message-ID: Op 2004-08-17, Peter Hansen schreef : > Antoon Pardon wrote: > >> How about: that is how my tongue and brain are wired. > > Sorry, such "explanations" are nothing more than > restatements of the original claim in different words. > They don't actually clarify the issue at all. That's > why I called "I just don't" a cop-out. > > Anyway, this is far removed from the (to me) interesting > question of why people apparently have negative reactions > to Python's use of indentation. Some people have, in spite > of your claims that it's not possible, managed to produce > useful and interesting answers, and for that I thank them. I would be most surprised if I made such a claim. Please provide me with a reference so that I can apologize if I actually did this. -- Antoon Pardon From zathras at thwackety.com Tue Aug 17 06:20:32 2004 From: zathras at thwackety.com (Michael Sparks) Date: Tue, 17 Aug 2004 11:20:32 +0100 (BST) Subject: Generators versus Coroutines In-Reply-To: <7xoelanpny.fsf@ruckus.brouhaha.com> Message-ID: On 17 Aug 2004, Paul Rubin wrote: ... > No, pure includes C modules included with the interpreter. See, this I find a ridiculous assertion. After all the modules that get included changes. That means one week one implementation will be viewed as impure and the next week pure. That's why I think the whole notion of purity is ridiculous. > > IMO, the question is one of practicality. It is practical to use > > generators to build concurrent systems - and it works pretty well. > > Not Python generators. Generators in other languages, maybe. I'm sorry, I find it practical and works well. YMMV. > > If that's not good enough it is practical to using concurrency > > implementated as an extension to python. If that's not good enough, > > it is practical to a different implementation of python. Or if > > concurrency in a single thread isn't sufficient you can change to > > threads or processes. > > No that's ridiculous. No it's not. It's is _practical_ depending on what your uses for concurrency are. > Simulating them with > OS threads is like simulating register loads and stores with XML > transactions over the internet. Wonderful hyperbole. (not being sarky, really is meant as a compliment :) You've got to admit that's pretty extreme hyperbole. :) > > And if you choose appropriate coding conventions every problem domain that > > co-routines and continuations can solve, generators can be used with > > almost equal effectiveness. > > No, not Python generators, they're amazingly useful, but they're much > less powerful than first class continuations. I'm sorry, but this is completely false. At the end of the day these things are all implemented on systems that do not have co-routines or innate concurrency - ie assembler. All have the same "power". (But *that* depends on your definition...) It's just a matter of how much effort you have to expend. In my experience, generators can be used with almost equal effectiveness. (Note: not equal, I didn't and am not saying that) Effectiveness != power. I do agree though that "practical python" includes what a user of the code has access to, however this depends heavily on the target environment. If you're distributing just source to people then yes, what comes with the interpreter is important. However stating something is "pure python" is misleading - since there are so many potential different "pure python" things out there. eg many hosting companies only have python 1.5.X loaded, if at all, so anything written after that isn't "pure python" to someone wanting to run something there. Personally I find the phrase more misleading than useful. Your milage obvious varies :) If however you are building a tool internal to your company, then what's practical is very different. etc... I doubt we're going to agree anytime soon though on much of this, so I'll leave it there. Best Regards, Michael. From tismer at stackless.com Wed Aug 11 13:13:42 2004 From: tismer at stackless.com (Christian Tismer) Date: Wed, 11 Aug 2004 19:13:42 +0200 Subject: Integers have docstring for int() In-Reply-To: <16666.13564.527138.202013@montanaro.dyndns.org> References: <59e9fd3a04081105087366db98@mail.gmail.com> <16666.13564.527138.202013@montanaro.dyndns.org> Message-ID: <411A53C6.7090904@stackless.com> Skip Montanaro wrote: > Andrew> I accidentally discovered that all the basic types in Python > Andrew> have docstrings that describe the functions to create them. For > Andrew> integers, you get: > ... > > Andrew> This seems a little unexpected to me; is there any particular > Andrew> reason for this behaviour? > > Why should this be unexpected? If you execute > > print int.__doc__ > > you get its docstring. Since the __doc__ attribute is attached to the class > it will be found when the search starts at an instance of the class as well. Sure, this is why. But I can understand the feeling a little bit, because the docstring describes what a __call__ to the type object does, although the instance is not even callable. This may origin in the fact, that int and str have been just functions a short while back, and the docstrings mainly describe that function call. The docs are less representative for int being the whole class. One would perhaps expect a short description of what an int can do. On the other hand, int() perceived as a function still needs its documentation as it is now. Like we have the __call__ attribute of a type, which describes the call of the *instance*, and this differs completely from how the type is called, would it make sense to change the __doc__ lookup of types vs. instances in some way? The current doc strings would probably better fit into int.__new__ or int.__init__, while the class __doc__ might talk about instances. (although I even think no documentation would be better than the existing docs in the case of strings and ints, which show up in some object browsers, and you really don't want to read long musings about strings while inspecting a string value in the PythonWin debugger). ciao - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From CousinStanley at HotMail.Com Fri Aug 13 11:35:02 2004 From: CousinStanley at HotMail.Com (Cousin Stanley) Date: Fri, 13 Aug 2004 08:35:02 -0700 Subject: Flython? References: <2o3ovjF6apnoU1@uni-berlin.de> Message-ID: <2o4555F6dms6U1@uni-berlin.de> Daniel Ellison wrote .... | I have to agree that Python compiled to swf bytecode | would be very handy indeed. | | I'm no fan of HTML-based web applications, | but there are currently few alternatives. | | Flash could be an excellent alternative, | but few developers want to take the time to learn (and purchase!) | the Flash authoring application to create a better web GUI. | | I *like* "Flython" as a name! :) | | A flying python! I can see the logo now... Dan .... There is a freeware alternative called Powerbullet for creating/editing Flash .swf files that runs under Windows .... http://www.powerbullet.com/ I've only done limited testing with it under Win98, but it seems to work OK .... -- Cousin Stanley Human Being Phoenix, Arizona From timr at probo.com Sun Aug 8 01:20:31 2004 From: timr at probo.com (Tim Roberts) Date: Sat, 07 Aug 2004 22:20:31 -0700 Subject: q about cgi.FieldStorage (was: And now to sth. completely different: Forget about decorators, think cgi.FieldStorage) References: Message-ID: "Ames Andreas (MPA/DF)" wrote: > >1) Please excuse the bogus original message. I wrote it a minute > before I knocked off work and I promise to never do so again :-) > >2) What I really wanted to know was: FieldStorage writes what it > reads from the stream that is given to its constructor's fp (or > sys.stdin by default) to a temporary file only _in some cases_. My > question was or rather should have been, if it was possible in any > case to get what FieldStorage has read from its input stream either > as a string or as a file. Not in its raw form. The stream comes from Apache and evaporates as it is read. If you need to raw data, just forget about cgi.FieldStorage and read stdin directly. You can always copy it to a temp file or StringIO and feed it back to the cgi module later. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From anthonybaxter at gmail.com Mon Aug 23 12:28:09 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Tue, 24 Aug 2004 02:28:09 +1000 Subject: __name__ becoming read-write? In-Reply-To: References: Message-ID: On Mon, 23 Aug 2004 15:58:26 GMT, Arthur wrote: > Of course I am curious as to why, and what would be involved, and > wrong,. with merging the local variable and the actual name for these > special syntax items. It would seem to have merit on its own terms. > > For example I had noticed to use string substition on a function doc I > needed to assign to __doc__ outside the function. How would you envisage this working? Look at the following code: def foo(arg): __doc__ = "bingle!" if arg < 0: __doc__ = "bangle!" if arg > 0: __doc__ = "bongle!" Now, _before_ this code is run, what's foo.__doc__ supposed to be set to? Remember, at this point, the code has not been run. The local __doc__ has no value at this point. Special casing __doc__ (or __name__) so that assignments to a local like that inside a function assign magically to the function object is bad magic. It leads to confusion and poor coding. In general, inside a function, you don't have access to the function object itself[1] Anthony [1] I except using sys._getframe(), or raising an exception and traversing up through the traceback object, as they're hacks. From fakeaddress at nowhere.org Thu Aug 12 02:22:58 2004 From: fakeaddress at nowhere.org (Bryan Olson) Date: Thu, 12 Aug 2004 06:22:58 GMT Subject: Arranging a dependency tree In-Reply-To: References: <6ccff37a.0408111831.6eb25a4e@posting.google.com> Message-ID: <61ESc.3831$%B.1788@newssvr27.news.prodigy.com> Heiko Wundram wrote: > Basically, dependencies (should) create a tree structure, except when > you have circular dependencies. [...] Non-circular dependencies create a directed acyclic graph (DAG), not necessarily a tree. I'm sure Heiko actually knew this, but being the kind of smart- ass I am, I can't resist the chance to correct him on things he already knew twice in one day. Earlier he wrote "large prime" where he clearly meant "large integer". I trust he will take this post in the spirit in which it is intended. -- --Bryan From sholden at holdenweb.com Mon Aug 30 08:08:59 2004 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 30 Aug 2004 08:08:59 -0400 Subject: Top Zope sites? In-Reply-To: References: Message-ID: Robert Oschler wrote: > Hello, > > I've been perusing a book on Zope I have, and I'm still not quite "getting > it". Can someone give me the URL's of 2 or 3 top-notch sites built upon > Zope, so I can see what it's really all about? Is it a phpNuke type thing? > How popular is it? > > Thanks. > > > You'll probably get a more adequate resonse from one of the specifically Zope-related groups. regards Stever From __peter__ at web.de Tue Aug 24 03:14:05 2004 From: __peter__ at web.de (Peter Otten) Date: Tue, 24 Aug 2004 09:14:05 +0200 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 23) References: Message-ID: Anthony Baxter wrote: > On Mon, 23 Aug 2004 20:08:07 GMT, Peter Otten > wrote: >> Thanks to the work of Michael Sparks building on previous efforts >> by Mark Russell there is already a patch. Anthony Baxter, the >> outspoken proponent of the pie syntax, helps with some useful hints, >> too. >> http://www.python.org/sf/1013835 > > ... just to correct the record - my efforts here have not been > primarily aimed at defending the pie-syntax, but instead aimed at > shaking out a decent response. I'm trying _very_ hard to make sure > that any efforts to go back to Guido are "done right". After the > horror of the ternary operators debacle, I'm trying to make sure that > community involvement doesn't end up with a complete bum rap. I made no assumptions about your motives in the above snippet, so this is not a correction, strictly speaking. > As part of this, of course, I _have_ defended the pie-syntax, because > it's the best I've seen so far. But if something better comes along, > I'm happy to go with that. The fraction of your posts I have read went from (I'm sharpening) "What crap are you proposing as an alternative to '@'? Guido won't listen anyway" to "If you want it, at least get it right" I liked that and that's why you are in the Python-URL. > My major problems, btw, remaining with the J2 syntax are the choice of > the new keyword seems an extremely problematic thing, and the simple > case of a single decorator results in far more clutter. But these are > purely subjective judgements. (Hell, this entire discussion is now > pretty much based on subjective or aesthetic judgements). Yes, and I am clearly among those who from the beginning where more concerned about the aesthetical impact on the language than the technical details that affect the actual implementation. But even if I wanted, the formal constraints of the Python-URL make it hard to use it as a means of propaganda... Peter From anthonybaxter at gmail.com Sun Aug 8 22:50:29 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Mon, 9 Aug 2004 12:50:29 +1000 Subject: decorators vs GIL In-Reply-To: <45337.24.233.156.35.1092017925.squirrel@webmail.vex.net> References: <96c2e938.0408081605.706f8ec7@posting.google.com> <45337.24.233.156.35.1092017925.squirrel@webmail.vex.net> Message-ID: On Sun, 8 Aug 2004 22:18:45 -0400 (EDT), mudd at vex.net wrote: > Is there anything else that Python doesn't do well that we should appreciate? I wouldn't go so far as to say that we should _appreciate_ the GIL, more that it ends up being not so much of a problem because Python gives us many, many better ways to do things than with threads. About the only actual issue with the GIL is that it stops a single Python interpreter from taking better advantage of multiple CPUs in a box. But, if you code with a knowledge of the GIL, this is easy enough to work around. The advantages of the GIL is that the implementation is far more robust, and far less overhead is wasted in lots of tiny little locks. In addition, it means that a single python instruction is guaranteed to be thread safe - so in a threaded app I can do something like somedict['foo'] = 1 without having to wrap access in a lock to make sure I don't end up with a hosed dictionary. Once you end up with lots of little locks in a threaded application, madness is surely not far away. Anthony From bcaligari at nospam.fireforged.com Fri Aug 27 14:39:12 2004 From: bcaligari at nospam.fireforged.com (Brendon Caligari) Date: Fri, 27 Aug 2004 18:39:12 +0000 Subject: Xah Lee's Unixism In-Reply-To: <87hdqptl96.fsf_-_@thalassa.informatimago.com> References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> Message-ID: <412f7fd0$0$6328$bed64819@news.gradwell.net> > > $ telnet xahlee.org 80; > Trying 208.186.130.4... > Connected to xahlee.org. > Escape character is '^]'. > GET / HTTP/1.1 > > HTTP/1.1 400 Bad Request > Date: Fri, 27 Aug 2004 01:35:52 GMT > Server: Apache/2.0.50 (Fedora) > ^^^^^^^^^^^^^^^^^^^^^^ It's a hosting provider. Funny though how they would use something like Fedora. From joshl at commenspace.org Thu Aug 26 12:53:44 2004 From: joshl at commenspace.org (Josh) Date: Thu, 26 Aug 2004 09:53:44 -0700 Subject: waiting for html to load: a followup Message-ID: Hi - A couple days ago I posted asking for help on how to download a pushed file. I am trying to write a script to download a bunch of links from a page that takes a while to load. I managed to get just about everything done using python to load IE, but aside from not really liking that style, I couldnt figure out how to have python download the pushed file, or how to read IE headers into python (the headers point to the download location) Anyway, I decided to forget IE and I am now trying to use urllib2 to open up the page, read it, etc. My problem is the page has a built-in refresh and I don't know how to have python re-read the page until it's ready to hand over the links. An example of the page is: http://edcw2ks23.cr.usgs.gov/Website/zipship/waiting.jsp?areaList=49.0,47.0,-122.0,-124.08&prodList=NED, I believe I need to read the header, grab the cookie session id, and add it back to the header. I can do all thus, but I'm stuck on probably very simple syntax to re-read the page rather than open a new connection, if that makes sense (I'm new to http as well as python). My code snippets: myreq = urllib2.Request(url) opener = urllib2.build_opener() headers = feeddata.info() cookie = headers['set-cookie'] cookie = cookie[:-8] while x < 10: feeddata = opener.open(myreq) data = feeddata.read() myreq.add_header('User-Agent','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)') myreq.add_header('Cookie', cookie) print data[1600:1650] print '\n\n\n\n*****************Using Cookie: %s' % cookie print '****************Header info: \n',headers sleep(3) x = x+1 Any help greatly appreciated. Thanks in advance, and when I know what I'm doing I'll repay the favors. -Josh From ptmcg at austin.rr._bogus_.com Thu Aug 26 05:32:31 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Thu, 26 Aug 2004 09:32:31 GMT Subject: Call for signatories for J2 References: Message-ID: "Paul McGuire" wrote in message news:bP9Xc.28243$v86.1203 at fe2.texas.rr.com... > For. > > Paul McGuire > > I'd also like to echo Alex Martelli's comments regarding 'per'. I can live with 'using', but the common case of using: staticmethod def foo(): pass reads better to me with 'per' as the keyword: per: staticmethod def foo(): pass (Interestingly, @ and 'per' are similar in that "12 @ $ From eppstein at ics.uci.edu Mon Aug 23 17:19:38 2004 From: eppstein at ics.uci.edu (David Eppstein) Date: Mon, 23 Aug 2004 14:19:38 -0700 Subject: Standard graph API? References: Message-ID: In article , mlh at furu.idi.ntnu.no (Magnus Lie Hetland) wrote: > >In my personal graph library, I found that one of the nastiest issues > >was writing suitably general DFS/BFS algorithms which had "hooks" at > >relevant points > > Yes... I've been thinking about this -- it might be useful to allow > some form of traversal (where you could supply your own queue object, > for example, giving you bfs, dfs, dijkstra, prim, whatever) and have > the traversal take the form of an iterator (similar to the Boost graph > library). But if access to each node and its neighbors is available in > the interface, such traversals wouldn't really have to be part of the > standard API... I've tried two different ways of writing a general purpose DFS with as you say sufficiently many relevant hooks. They're both in The first way is to generate a sequence of triples (v,w,edgetype): (v,v,forward) = start of new DFS tree with root v (v,w,forward) = first time DFS reaches w from parent v (v,w,nontree) = edge from v to already-visited vertex w (v,w,reverse) = DFS returns from v to parent w (v,v,reverse) = finish DFS tree with root v The second way is a class with shadowable calls preorder(parent,child), postorder(parent,child), and backedge(source,destination). The arguments to the calls are basically the same as the first and second items in the triples described above, although I suppose I could have made separate calls for the DFS tree roots. The class is instantiated with a graph argument and as part of its initialization performs a DFS on that graph, making the calls as it goes. The first way is lower level and I think uglier, but on the other hand it's usable to make iterators in a way that the second isn't; see e.g. the code in the same DFS.py file for iterating through the vertices of a graph in DFS postorder. A much more complex example of the second way occurs in . -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ From paolo_veronelli at yahoo.it Fri Aug 6 09:16:14 2004 From: paolo_veronelli at yahoo.it (paolo veronelli) Date: Fri, 06 Aug 2004 15:16:14 +0200 Subject: @decorators In-Reply-To: References: Message-ID: Thinking about the editing of programs containing decorators (which probably are not anyway) ,if they are placed before the def (and class?) probably it's right to have a special symbol marking all lines which are to be folded with the owner of them,so they can be easily recognized. Surely this breaks identation layout because these lines look like pieces of the outer scope. Some of the __x__ methods are in some way orthogonal to the code .I wonder if this new orthogonality shouldn't share this syntax .... In ruby '@' is in place of methods 'firstarg.' which is very efficient.I would like to use the @ symbol like first argument to methods ,in place of a name(self for most).But this is another story. I hope there is a way to 'decorate' inside the def which is possibly wrong:this thing I would like to understand more. Ciao Paolino -- ....lotta dura per la verdura From fakeaddress at nowhere.org Wed Aug 4 22:41:25 2004 From: fakeaddress at nowhere.org (Bryan Olson) Date: Thu, 05 Aug 2004 02:41:25 GMT Subject: Timing Difference: insert vs. append & reverse In-Reply-To: References: <35b736b9.0408020330.53b24ed3@posting.google.com> <1a517b5.0408031027.60554dfb@posting.google.com> <1a517b5.0408041305.3927a6c8@posting.google.com> Message-ID: Tim Peters wrote: > [Bryan Olson] >>[...] I hadn't realized that Python's lists are much slower >>than Perl's in important cases: >> >> http://perlmonks.thepen.com/17890.html >> >>Would this be a PEP-size change, or just a small fix? > > "Futile" is closer -- it's been debated to death repeatedly. Python > 2.4 adds a deque type instead, with O(1) insert/remove at both ends, > regardless of access pattern. That's O(1) per operation (not just > amortized O(1) -- the deque type never needs to move entries). But it breaks (efficient) indexing. Since we can have it all like Perl, why not? Googling up "dequeue" together with "O(1)" in comp.lang.python, (and with the misspelling "deque" which returns more results) I see some discussion, but very little reason against the enhancement. One post by Tim Peters suggests difficulty of implementation as a major reason. -- --Bryan From nobody at nowhere.com Thu Aug 19 12:40:41 2004 From: nobody at nowhere.com (Fred) Date: Thu, 19 Aug 2004 18:40:41 +0200 Subject: Interface graphique pour python References: <8e16829.0408190650.3fa62d5e@posting.google.com> Message-ID: On 19 Aug 2004 07:50:35 -0700, yaoroland07 at yahoo.com (Roland) wrote: >J'ai redhat 9.0 sur mon ordinateur. Et j'ai besoin d'une interface >graphique de python pour cnstuire une application . J'ai cherch? mais >en vain. Pourriez-vous m'indiquer une? Most people use wxWidgets, and its Python wrapper wxPython. You call also take a look at - PyQT (wrapper to the QT widget set, the one used by KDE), - pyFLTK (... to the FLTK widget set, but this wrapper seems no longer under development), - PyGTK (you guessed it), - FXPy (to the FOX library) Fred. From pm_mon at yahoo.com Sat Aug 21 20:56:55 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sat, 21 Aug 2004 20:56:55 -0400 Subject: __metaclass__ and __author__ are already decorators In-Reply-To: <2oq93oFdnrmoU1@uni-berlin.de> References: <2opgsoFd7807U1@uni-berlin.de> <2opp6gFdg3e7U1@uni-berlin.de> <2oq4keFd90euU1@uni-berlin.de> <2oq93oFdnrmoU1@uni-berlin.de> Message-ID: Leif K-Brooks wrote: > Paul Morrow wrote: > >> So when we define an __xxx__ attribute inside of a function, we are >> trying to make a statement about the function --- we are not trying to >> create a local variable. Therefore the Python system shouldn't create >> a local variable in this case; it should create a function variable >> instead (IMO). > > > How do you think a newbie will react to magic behavior like that from > the assignment operator based entirely on the name being assigned to? We must emphasize that they are assigning to a 'magic' variable, as all __xxx__ attributes are supposed to be. One must be careful with magic :-) From h.b.furuseth at usit.uio.no Fri Aug 6 15:59:20 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 06 Aug 2004 21:59:20 +0200 Subject: Proposal: require 7-bit source str's References: <4112AC7B.1060508@v.loewis.de> <411343D7.3020604@v.loewis.de> <411353A3.8090502@v.loewis.de> <4113759E.2070405@v.loewis.de> Message-ID: Martin v. L?wis wrote: >Hallvard B Furuseth wrote: >>>"Written by Martin v. L?wis" >> >> So if the file has -*- coding: iso-8859-1 -*-, how does that doc string >> look to someone using a iso-8859-2 locale? > > Let's start all over. I'm referring to a time when there was no encoding > declaration, and PEP 263 was not written yet. At that time, I thought > that a proper encoding declaration (i.e. a statement) would be the > best thing to do. So in my example, there is no -*- coding: iso-8859-1 > -*- in the file. Instead, there is a directive. > > About the unrelated question: How should a docstring be displayed > to a user working in a different locale? Well, in theory, the docstring > should be converted from its source encoding to the encoding where > it is displayed. In practice, this is difficult to implement, and > requires access to the original source code. However, Francois Pinard > has suggested to add an __encoding__ attribute to each module, > which could be used to recode the docstring. Sounds OK for normal use. It's not reliable, though: If files f1 and f2 have different 'coding:'s and f1 does execfile(f2), f2's doc strings won't match sys.modules[.__module__].__encoding__. (Or maybe the other way around: I notice that the execfile sets f1.__doc__ = . But I'll report that as a bug.) > About your literal question: In the current implementation, the string > looks just fine, as this docstring is codepoint-by-codepoint identical > in iso-8859-1 and iso-8859-2. Whoops. Please pretend I said iso-8859-5 or something. I was thinking of ?, not ?. Had just written about that in another posting. >> Just like a str7bit directive, in whatever form, would not catch the >> missing u in front of the doc string. > > Not necessarily. It would be possible to go back and find all strings > that fail to meet the requirement. That sounds like it could have a severe performance impact. However, maybe the compiler can set a flag if there are any such strings when it converts parsed strings from Unicode back to the file's encoding. Then the str7bit directive can warn that the file contains one or more bad strings. Or if the directive is executed while the file is being parsed, it can catch such strings below the directive and give the less informative warning if there are such string above the directive. I can't say I like the idea, though. It assumes Python retains the internal implementations of 'coding:' which is described in PEP 263: Convert the source code to Unicode, then convert string literals back to the source character set. > Notice that your approach only works for languages with single-byte > character sets anyway. Many multi-byte character sets use only > bytes < 128, and still they should get the warning you want to produce. They will. That's why I specified to do this after conversion to Unicode. But I notice my spec was unclear about that point. New spec: After the source file has been converted to Unicode, cause a parse error if a non-u'' string contains a converted character whose Unicode code point is >= 128. Except... None of this properly addresses encodings that are not ASCII supersets (or subsets), like EBCDIC. Both Python and many Python programs seem to make the assumption that the character set is ASCII-based, so plain strings (with type str) can be output without conversion, while Unicode strings must be converted to the output device's character set. E.g. from Info node 'File Objects': `encoding' The encoding that this file uses. When Unicode strings are written to a file, they will be converted to byte strings using this encoding. Nothing about converting 'str' strings. Solving that one seems far out of scope for this PEP-to-be, so my proposal inherits the above assumption. Though the problem may have to be discussed in order to get a str7bit feature which does not get in the way of a clean solution to character sets like EBCDIC. >>>(of course, requiring that people use escape sequences for >>>them might be acceptable). >> >> Argh! Please, no. > > Think again. There absolutely is a need to represent byte arrays > in Python source code, e.g. for libraries that manipulate binary > data, e.g. generate MPEG files and so on. They do have a legitimate > need to represent arbitrary bytes in source code, with no intention > of these bytes being interpreted as characters. Sure. I wasn't protesting against people using of escape sequences. I was protesting against requiring that people use them. -- Hallvard From fumanchu at amor.org Mon Aug 16 01:23:45 2004 From: fumanchu at amor.org (Robert Brewer) Date: Sun, 15 Aug 2004 22:23:45 -0700 Subject: [Implementation] (first attempt) Re: A decorator syntax not yetmentioned (I think!) Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022DF9@exchange.hqamor.amorhq.net> Michael Sparks wrote: > Subject: [Implementation] (first attempt) Re: A decorator > syntax not yetmentioned (I think!) ... > I've implemented this now, and I have this (kinda*) working. I've > patched the 2.4a2 release from python.org and made the following > changes. > * Kinda - there's something wrong with my implementation due to > scoping, and since I only first looked at the python > source for the > first time 4-5 hours ago, I think this is progress :) ... > Either way, the argument on > http://www.python.org/moin/PythonDecorators > regarding J2 not having an implementation just (80%) disappeared :) > > Should I forward this to the dev list? YES, you should. Implementations are always preferred over rhetoric. Robert Brewer MIS Amor Ministries fumanchu at amor.org From bh at intevation.de Fri Aug 20 14:16:08 2004 From: bh at intevation.de (Bernhard Herzog) Date: Fri, 20 Aug 2004 20:16:08 +0200 Subject: Alternative decorator syntax decision References: <3A81C87DC164034AA4E2DDFE11D258E3022E14@exchange.hqamor.amorhq.net> Message-ID: Steven Bethard writes: > I would advise against this. GvR has said from the beginning that he > doesn't want to see a vote Er, you're already having a vote :-) > -- he wants to see convincing proposals and a more or less > unified community support. Yes. But what if the majority of the community favors pies of J2? > He's also said that he'd be willing to consider > adding two syntaxes for a while if we could really agree on a single > alternative syntax. Where did he say that? > So while the vote for non- at pie syntaxes seems to have been useful for focusing > our discussions for an alternative proposal, I can't see what use a vote > between J2 and @pie would do. Making sure that J2 is really what the community can rally behind. My fear is that if you present J2 to him as the community choice he might actually chose it even though nobody knows whether that really is what the majority of the community wants. What Guido did say (in his python-dev posting with Message-Id: <200408092014.i79KEh123856 at guido.python.org>) was: The community is to come up with *one* alternative that they universally prefer over @decorators; otherwise, @decorators-before-def will stay. (I'll even give you *two* if the community can agree that both are acceptable and really wishes to let me pick one.) I just want to make sure that J2 is really what we "universally prefer over @decorators" Bernhard -- Intevation GmbH http://intevation.de/ Skencil http://sketch.sourceforge.net/ Thuban http://thuban.intevation.org/ From ville at spammers.com Sun Aug 22 12:40:26 2004 From: ville at spammers.com (Ville Vainio) Date: 22 Aug 2004 19:40:26 +0300 Subject: VHHL :( was Re: Python future performance and speed) References: <278de0e.0408211605.426e5129@posting.google.com> Message-ID: >>>>> "Francesco" == Francesco Bochicchio writes: Francesco> And VHLLs will become more and more used as computer Francesco> power grows and becomes cheaper than developer time (it Francesco> is already so in several application areas). Don't forget that developer time is becoming cheaper as well. The issue will be increasingly about code quality and the ability to deliver on time / at all. -- Ville Vainio http://tinyurl.com/2prnb From anthonybaxter at gmail.com Thu Aug 26 03:31:16 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Thu, 26 Aug 2004 17:31:16 +1000 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> Message-ID: On Wed, 25 Aug 2004 19:47:35 -0400, Paul Morrow wrote: > What you're trying to illustrate (I believe) is a superclass doing > something based on the docstring of a subclass. Yes this certainly does > happen. But the superclass and subclass are separate objects. I was > talking about the situation where a function does something based on > /its own/ metadata. That is what I'm saying virtually never happens, > and therefore it's ok to make all assignments to __xxx__ attributes > inside of a function def create /function attributes/ rather than /local > variables/. This is an extraordinarily complex idea - you're proposing that inside a function there is now access to a brand new namespace, that of the function object itself. I don't think you appreciate just _how_ much work this would requre, nor the complexity of trying to explain this to users. Remember, at the moment, you can't even get access to the function object itself from inside the function, without using a hack like sys._getframe() or raising an exception. Putting aside nested scopes for the moment, there are three namespaces that are used in Python - local, module level global, and builtins. You're proposing that there is a new namespace, that of the function object, and that it only be used by accessing any local variable that starts or ends with two underscores. At the moment, the scoping rules for Python are _extremely_ simple. Do you really want to add something like this, that looks like a hack, smells like a hack, and who's implementation would be a hack? I know I don't want to see something like this. From bokr at oz.net Wed Aug 11 00:48:56 2004 From: bokr at oz.net (Bengt Richter) Date: 11 Aug 2004 04:48:56 GMT Subject: Static method object not callable References: Message-ID: On Wed, 11 Aug 2004 02:40:07 GMT, "Edward Diener" wrote: >Paul Morrow wrote: >> Edward Diener wrote: >>> This simple code example gives me the message, "TypeError: >>> 'staticmethod' object is not callable". >>> >>> class X(object): >>> def Y(x): >>> print x >>> Y = staticmethod(Y) >>> ad = { 1 : Y } >>> def Z(self): >>> self.ad[1](3) >>> x = X() >>> x.Z() >>> print "Done." >>> >>> I know there must be a way to have a class attribute reference a >>> static method, and then call that static method through the >>> reference, so if anyone can correct this it would be appreciated. By 'reference' are you referring to the Y in ad? >>> >>> >>> >> >> Here are two alternatives. snip... > >Neither alternative is satisfactory. Surely there must be some means of >directly specifying a reference to a static method in a class attribute in >Python, and calling it from an instance method through the class attribute. > > I'm not sure what you really want, but a staticmethod object is UIAM a descriptor and when descriptors are retrieved as attributes of something, their __get__ methods are called. That's why getattr was part of the other alternatives. Alternatively, you can call the __get__ method directly, and in the case of staticmethod, that will get you back the unadorned function in question, which you can then call. E.g., >>> class X(object): ... def Y(x): ... print x ... Y = staticmethod(Y) ... ad = { 1 : Y } ... def Z(self): ... self.ad[1].__get__(self, type(self))(3) ... >>> x = X() >>> x.Z() 3 (BTW, for staticmethod.__get__, probably any argument(s) other than None or None,None will work) Maybe this will clarify a little: A function also works like a descriptor, and has a __get__ method, which is called to create a bound method when the function is retrieved as an attribute of an object instance. Note that Z is a function with one argument (self). When retrieving Z as attribute of the class, the __get__ method gets the arguments __get__(None, X), which gets you the unbound method. >>> X.Z If we bypass the attribute access mechanism, we get the function itself: >>> X.__dict__['Z'] If we do the getattr mechanics manually, calling the __get__ of the function, we see the method results corresponding to X.Z and x.Z respectively: >>> X.__dict__['Z'].__get__(None, X) >>> X.__dict__['Z'].__get__(x, X) > We can make a hokey descriptor object to show this: >>> class Desc(object): ... def __get__(*args): print args ... >>> class C(object): ... attr = Desc() ... >>> c = C() >>> C.attr (<__main__.Desc object at 0x009015D0>, None, ) >>> c.attr (<__main__.Desc object at 0x009015D0>, <__main__.C object at 0x00901950>, ) So the __get__ args are the self of the decriptor instance itself (handy for carrying baggage like a function), and here either None,C or c,C for C.attr and c.attr repectively. Y is a staticmethod object though, not a plain function. The __get__ method of a staticmethod object returns the same thing (the original function) for either kind of call. So when retrieved as an attribute of something, you get the function in question: >>> X.Y >>> x.Y Bypassing attribute mechanism: >>> X.__dict__['Y'] Doing it manually bound-method style or unbound-method style: >>> X.__dict__['Y'].__get__(x, X) >>> X.__dict__['Y'].__get__(None, X) Calling the retrieved function: >>> X.__dict__['Y'].__get__(x, X)(123) 123 Of course, >>> X.Y(456) 456 >>> x.Y(456) 456 or >>> getattr(X,'Y')(789) 789 >>> getattr(x,'Y')(789) 789 I still don't know what you are really trying to do with that Z method and the ad dict ;-) Regards, Bengt Richter From len-1 at telus.net Mon Aug 16 16:39:13 2004 From: len-1 at telus.net (Lenard Lindstrom) Date: Mon, 16 Aug 2004 20:39:13 GMT Subject: Generators versus Coroutines References: <7x7js1i887.fsf@ruckus.brouhaha.com> Message-ID: Nick Patavalis writes: > On 2004-08-15, Lenard Lindstrom wrote: > > > > Having followed the development of Prothon it is my understanding that > > such a thing is not possible in CPython for two reasons. The first is > > that the yield statement itself defines a function declaration as a > > generator. Without a specific "gen" declarator keyword as in Prothon. > > > > Oh, I see. Then I have to say, this is an unbelievable screw-up in the > language specification. Being able to yield from within multiple > function-call levels is essential for any non-trivial use of > generators. Without this generators can only be used for simple stuff > such as to creates lists dynamically. > That is the idea. Generators are a shorthand way to implement iterators. But relative to other methods they are fast. > > The second reason is a python function call in CPython involves an > > actual recursive C call of the interpreter. > > What!?! CPython uses the *C-stack* !!?!?! Yes. > Is there a reason for this? I do not know for sure. I believe performance is one reason. Another is portablility. Having a python program call an external function written in C which in turn executes some Python code requires a recursive interpreter call. Handling the C stack in this case would require non-standard C libraries. Maybe someone actually involved in maintaining CPython will give a better answer. > I mean, for a weekend toy-project interpreter such an aproach would be > understandable, but for the primary Python interpreter! There must be > a reason I don't understand... > You are not alone. Christian Tismer has a modified version of CPython known as Stackless. It supports light weight threads that can be used as coroutines. For compatibility reasons, though, Stackless generators are justs like CPython's. But Stackless is to be superseded by PyPy, which is under development now. Lenard Lindstrom From aahz at pythoncraft.com Thu Aug 12 14:17:33 2004 From: aahz at pythoncraft.com (Aahz) Date: 12 Aug 2004 14:17:33 -0400 Subject: Pyhton Interpreter Startup time References: Message-ID: In article , Christopher T King wrote: > >2) Pre-compile the script. Normally, Python generates .pyc files for >imported modules so it doesn't have to re-parse the source code, but it >won't do this for a script specified on the command line. You can force >it to compile your script by importing the script in the interactive >interpreter, but this will also run your script (possibly not desirable). >You can compile the script without running it by using the py_compile >module: > >python -c 'import py_compile; py_compile.compile("my_script.py")' > >You can then run the compiled version using 'python my_script.pyc' >('python my_script.py' will ignore the compiled version). That's a Bad Idea. Better Idea: move the code into a separate module and put the code into a function. Then change this script into a very short driver that imports/calls the function. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From nhodgson at bigpond.net.au Mon Aug 2 19:34:57 2004 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Mon, 02 Aug 2004 23:34:57 GMT Subject: Newbie: pywin problem References: Message-ID: Martin DeMello: > >>> template = pywin.mfc.docview.DocTemplate(None) > >>> doc = pywin.scintilla.document.CScintillaDocument(template) > >>> view = pywin.scintilla.view.CScintillaView(doc) > >>> fr = win32ui.GetMainFrame() > >>> view.CreateWindow(fr) > > Now how do I get the window to display? I thought the call to > CreateWindow would do it, but the window just gets created silently. The template stuff is quite complex and I never understand it apart from when I've had to work with it recently. And its been a couple of years. By the end of your code you actually have a zero sized view window which is a direct child of the application frame rather than being inside an MDI window. If you open a file it will go into this view which will spread out over the app and not be properly clipped. I'm not sure what you want to achieve. If it is just opening another window within the environment from code, calling something in the template would be better. The "Python Programming on Win32" book gives an example of adding a new document type and view to PythonWin. There is a mailing list for Win32 Python issues at http://mail.python.org/mailman/listinfo/python-win32 Neil From ian at cottee.org Wed Aug 25 11:14:02 2004 From: ian at cottee.org (Ian J Cottee) Date: Thu, 26 Aug 2004 00:14:02 +0900 Subject: Group for Plone Users In-Reply-To: References: Message-ID: Yandle wrote: > I have just started tinkering with Plone and, as is to be expected, > I've run into some issues. What I want to know is: does anybody know if > there's a group for Plone users as opposed to Python programmers or > Zope administrators? > There are newsgroups hosted at Gmane. Look at http://plone.org/documentation/lists Cheers Ian From insert at spam.here Fri Aug 6 21:16:48 2004 From: insert at spam.here (Doug Holton) Date: Fri, 06 Aug 2004 20:16:48 -0500 Subject: PEP-0318 In-Reply-To: <4114152f@nntp.zianet.com> References: <41122FC2.1080608@interlink.com.au> <4114152f@nntp.zianet.com> Message-ID: Mark Bottjer wrote: >> Incorporation of all or part of >> http://www.python.org/moin/PythonDecoratorsinto the PEP would also be >> appreciated. > > Neat page. I would like to flesh out (5.D), though, as it is not quite > just "(5.C) with pie syntax" like the document currently states: ... > > I would be happy to add these myself if someone would tell me how? You have to click on the "UserPreferences" link on the top right of the page and create an account (with a username like MarkBottjer and a password). Then when you refresh the PythonDecorators page you will be able to click an EditText link at the bottom of the page to edit it. I noticed you posted the "@decorators at the top of function body" idea right before I posted it here, too. See the "compromise?" thread. From anthonybaxter at gmail.com Fri Aug 6 12:00:11 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 7 Aug 2004 02:00:11 +1000 Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) In-Reply-To: References: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> Message-ID: On Fri, 06 Aug 2004 08:24:47 -0400, Peter Hansen wrote: > It *is*, however, fairly clear that the list of decorators becomes > harder to see. Without checking, it's definitely possible that the > decorator list in the first case is actually part of the argument list. This is one of the reasons Guido rejected it, see http://mail.python.org/pipermail/python-dev/2004-August/047112.html > Apparently the term "voting" is deprecated when related to PEPs > and language design. ;-) Instead, we should now be using the term > "expressing their opinion in favour of"... Well, it's not so much deprecated as pointless > At least, I hope we are still allowed to express opinions in favour > of things... In case it wasn't clear from my earlier posts - my comments about "voting" being a waste of time were meant in the sense of "collecting a bunch of votes won't achieve anything". Collecting a rationale that is sufficient to change Guido's mind, however, is encouraged! But simply saying "here's a list of people who prefer this syntax" won't achieve much at all. Far better use of time is to work out a way to convince Guido to change his mind (which, it should be clear from the post above, will require a strong argument, with good reasons for it). From newsgroups at jhrothjr.com Sun Aug 22 07:11:32 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Sun, 22 Aug 2004 07:11:32 -0400 Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? References: Message-ID: <10igvr2d1hlgmc9@news.supernews.com> "Paul McGuire" wrote in message news:pUTVc.8393$Jn5.5720 at fe1.texas.rr.com... > Well, after 3 days of open polling, the number of additional votes have > dropped off pretty dramatically. Here are the results so far: > > Total voters: 55 (with 3 votes each) Now that I've had a chance to look at the syntax, you can count me mildly in favor of J2. (I haven't voted yet.) It's an extra line, but I think the explicitness outweighs the vertical space it takes up. The keyword is fine even though it will almost certainly require a future statement for 2.4. John Roth > > > From __peter__ at web.de Mon Aug 9 08:43:39 2004 From: __peter__ at web.de (Peter Otten) Date: Mon, 09 Aug 2004 14:43:39 +0200 Subject: Proposal: require 7-bit source str's References: Message-ID: Hallvard B Furuseth wrote: >>>> The long-term goal would be unicode throughout, IMHO. >>> >>> Whose long-term goal for what? For things like Internet communication, >>> fine. But there are lot of less 'global' applications where other >>> character encodings make more sense. More sense? I doubt that. What does make sense is an api that abstracts from the encoding. You can then reduce the points where data in limited i. e. non-unicode encodings is imported/exported as the adoption of unicode grows without affecting the core of your app. IMHO chr(ord("a") - 32) is inferior to "a".upper() even in an all-ascii environment. >> Here we disagree. Showing the right image for a character should be >> the job of the OS and should safely work cross-platform. > > Yes. What of it? I don't understand the question. > > Programs that show text still need to know which character set the > source text has, so it can pass the OS the text it expects, or send a > charset directive to the OS, or whatever. > >> Why shouldn't I be able to store a file with a greek or chinese name? > > If you want an OS that allows that, get an OS which allows that. That was not the point. I was trying to say that the usefulness of a standard grows with its adoption. >> I wasn't able to quote Martin's >> surname correctly for the Python-URL. That's a mess that should be >> cleaned up once per OS rather than once per user. I don't see how that >> can happen without unicode (only). Even NASA blunders when they have to >> deal with meters and inches. > > Yes, there are many non-'global' applications too where Unicode is > desirable. What of it? I don't understand the question. > Just because you want Unicode, why shouldn't I be allowed to use > other charcater encodings in cases where they are more practical? Again, my contention is that once the use of unicode has reached the tipping point you will encounter no cases where other encodings are more practical. > For example, if one uses character set ns_4551-1 - ASCII with {|}[\] > replaced with ??????, sorting by simple byte ordering will sort text > correctly. Unicode text _can't_ be sorted correctly, because of > characters like '?': Swedish '?' should match Norwegian '?' and sort > with that, while German '?' should not match '?' and sorts with 'o'. Why not sort depending on the locale instead of ordinal values of the bytes/characters? >>> In any case, a language's both short-term and long-term goals should be >>> to support current programming, not programming like it 'should be done' >>> some day in the future. At some point you have to ask yourself whether the dirty tricks that work depending on the country you live in, its current orthography and the current state of your favourite programming language do save you some time at so many places in your program that one centralized api that does it right is more efficient even today. > I don't know Perl 6, but Perl 5 is an excellent example of how not do to > this. So is Emacs' MULE, for that matter. > > I recently had to downgrade to perl5.004 when perl5.8 broke my programs. > They worked fine until they were moved to a machine where someone had > set up the locale to use UTF-8. Then Perl decided that my data, which > has nothing at all to do with the locale, was Unicode data. I tried to > insert 'use bytes', but that didn't work. It does seem to work in newer > Perl versions, but it's not clear to me how many places I have to insert > some magic to prevent that. Nor am I interested in finding out: I just > don't trust the people who released such a piece of crap to leave my > non-Unicode strings alone. In particular since _most_ of the strings > are UTF-8, so I wonder if Perl might decide to do something 'friendly' > with them. I see you know more Perl than me - well, my mentioning of the zipper was rather a lightweight digression prompted by the ongoing decorator frenzy. >> the way to go in your case. If I were to add a switch to Python's >> string handling it would be "all-unicode". > > Meaning what? All strings are unicode by default. If you need byte sequences instead of character sequences you would have to provide a b-prefixed string. Peter From eurleif at ecritters.biz Sat Aug 21 00:27:33 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sat, 21 Aug 2004 00:27:33 -0400 Subject: Has anyone implemented BASIC in Python? Message-ID: <2oo13eFcj548U1@uni-berlin.de> Has anyone ever tried implementing a simple unstructured BASIC dialect in Python? I'm getting interested in language implementation, and looking at a reasonably simple example like that could be pretty interesting. From nhodgson at bigpond.net.au Mon Aug 2 19:13:44 2004 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Mon, 02 Aug 2004 23:13:44 GMT Subject: flowcharting is automatic for Python via preprocessor References: Message-ID: Connelly: > I think your visual diagrams could help, if they are: > ... > 2. Integrated into a code editor. > > I could see this being a new code editor fad, like collapsable > functions and classes. http://www.eng.auburn.edu/grasp/index.html Neil From tim.peters at gmail.com Fri Aug 6 11:53:11 2004 From: tim.peters at gmail.com (Tim Peters) Date: Fri, 6 Aug 2004 11:53:11 -0400 Subject: Queue qsize = unreliable? In-Reply-To: <4113A4B1.6040900@rogers.com> References: <1091805850.15192.12.camel@localhost> <4113A4B1.6040900@rogers.com> Message-ID: <1f7befae04080608534ec3e092@mail.gmail.com> [James R. Saker Jr.] >> I see per pydoc that Queue.Queue()'s .qsize is allegedly unreliable: >> >> | qsize(self) >> | Return the approximate size of the queue (not reliable!). >> >> Any thoughts on why this is unreliable (and more curiously, why it would >> be put in there as an unreliable function?) Rather than roll my own >> threaded fifo class, it would seem prudent to use Python's built-in >> Queue but the warning signs on a rather necessary function seem curious. [Mike C. Fletcher] > I would imagine that there is the potential for an item to be added or > consumed during the running of the qsize method, or between the > completion of the running of the qsize method and the op-codes which > deal with the result. > ... > Tim, of course, would know better, but that's always been my interpretation. That's exactly right. The Queue empty() and full() methods are similarly "unreliable". They return the exact truth at the time they're computed by Queue, but by the time their caller gets the result they may bear no relationship to then-current reality. James, why do you think they're necessary functions? If, e.g., you're worried about the queue getting "too big", pass a maximum size to the constructor, and then a producer thread trying to add to a full queue will block until a consumer thread takes an entry off the queue. Indeed, mediating mismatched processing rates is a prime use case for bounded queues. There's no use case I know of where knowing "the exact current size" is necessary, except inside the implementation of Queue (where it can know it, but at the expense of locking out all other threads for as long as it takes to compute the result). From ivoras at __-geri.cc.fer.hr Mon Aug 23 18:26:51 2004 From: ivoras at __-geri.cc.fer.hr (Ivan Voras) Date: Tue, 24 Aug 2004 00:26:51 +0200 Subject: Python SOAP? Message-ID: Is anybody using SOAP with Python "seriously"[1]? It seems there's a number of implementations out there, but most aren't developed any more. Specifically, I hadn't found a library that supports "sessions" with SOAP, implemented with HTTP cookies to achieve server-object persistance. Have I missed something? [1] I'm from the "SOAP is bad and ugly" camp, but I must use it in a project... From ville at spammers.com Thu Aug 26 08:00:05 2004 From: ville at spammers.com (Ville Vainio) Date: 26 Aug 2004 15:00:05 +0300 Subject: Call for signatories for J2 References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> Message-ID: I vote FOR on the J2 syntax. -- Ville Vainio http://tinyurl.com/2prnb From FBatista at uniFON.com.ar Tue Aug 31 11:59:22 2004 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Tue, 31 Aug 2004 12:59:22 -0300 Subject: GUI Designer Message-ID: [A.M] #- Do we have any OpenSource GUI designer for Python ? That depends heavily on what GUI you're developing. Have you chosen one? . Facundo -------------- next part -------------- An HTML attachment was scrubbed... URL: From user at domain.invalid Mon Aug 23 15:40:35 2004 From: user at domain.invalid (user at domain.invalid) Date: Mon, 23 Aug 2004 19:40:35 GMT Subject: age of Python programmers In-Reply-To: <6daa8765.0408230828.6bdc2f0e@posting.google.com> References: <20040819231139.D039A1E4003@bag.python.org> <6daa8765.0408230828.6bdc2f0e@posting.google.com> Message-ID: Artemisio wrote: > Sakesun Roykiattisak wrote in message news:... > >>I'm 28. Have been using python for just one year. I was first >>introduced to programming when I'm in 11 with 6502 machine (Apple II and ---snip %><--- > I am 35. I discovered Python like 2 weeks ago, so I am nor a Python I just turned 50 (last week). Met Python at a robotics workshop last year, and I find I *enjoy* it more than any languages since C and assembly --- it might even lure me into this whole "objects" paradigm. I've been programming since 1971, when I met FORTRAN on an IBM s/370. The wackiest language I've used is probably SNOBOL, the only one to use the "self-modifying source code" paradigm. From npat at efault.net Tue Aug 17 00:16:44 2004 From: npat at efault.net (Nick Patavalis) Date: Tue, 17 Aug 2004 04:16:44 +0000 (UTC) Subject: Generators versus Coroutines References: <7x7js1i887.fsf@ruckus.brouhaha.com> Message-ID: On 2004-08-16, Lenard Lindstrom wrote: > > That is the idea. Generators are a shorthand way to implement iterators. > But relative to other methods they are fast. > But this is only a tiny portion of what one can do with generators and coroutines! Actually for me it is the least interesting part. Having a keyword that suggests the possibility of resumable functions (resumable threads of execution), but then impose such limitations, is frustrating. Furthermore it can be really problematic if the language is to be extented to support the more generic version, since then you will have two syntaxes for the same thing, or you will have to introduce incompatibilities. /npat From noone at here.com Wed Aug 25 10:46:03 2004 From: noone at here.com (M. Clift) Date: Wed, 25 Aug 2004 15:46:03 +0100 Subject: Just a quick one References: Message-ID: Hi Paul, Thanks for that. Would you know how to remove the brackets or how to convert it to a list such as 'Bob', 'Mary' etc... M From jack at performancedrivers.com Sun Aug 29 19:52:49 2004 From: jack at performancedrivers.com (Jack Diederich) Date: Sun, 29 Aug 2004 19:52:49 -0400 Subject: Implementations of Multi-Methods and Tail Call Elimination (Or how I stopped worrying and learned to love decorators) In-Reply-To: <3e8ca5c8.0408291459.6570c936@posting.google.com> References: <3e8ca5c8.0408291459.6570c936@posting.google.com> Message-ID: <20040829235249.GC17735@performancedrivers.com> On Sun, Aug 29, 2004 at 03:59:17PM -0700, Stephen Thorne wrote: > Multimethods come first, because I wrote them first. I don't really > like the implemetation - I'm sure it can be improved. I especially > dislike having to use the @staticmethod decorator, and having to have > the functions in alphabetical order. > > class fact(MultiMethod): > @when(lambda x:x==0) > @takes(int) > @staticmethod > def a(x): > return 1 > > @when(lambda x:x>0) > @takes(int) > @staticmethod > def b(x): > return x * fact(x-1) > > @staticmethod > def c(x): > raise ValueError("Invalid argument to fact()") > fact = fact() @takes seems like an extra version of @where > Okay. Lots of sugar required to do it, but look! its a multimethod! > fact(10.1) raises an error, fact(0) == 1 and fact(5) == 120. > > The implementation looks like this: > def takes(*arg, **kwargs): > def _(f): > def check(*x, **xs): > def test(a,b): > return b is None or isinstance(a,b) > if len([True for (a,b) in zip(x, arg) if not test(a,b)]): > raise NextMethodException() > if len([True for (a,b) in kwargs.keys() if not > test(xs.get(b,None),lb)]): > raise NextMethodException() > return f(*x, **xs) > return check > return _ > > def when(f): > def _(d): > def check(x): > if not f(x): > raise NextMethodException() > return d(x) > return check > return _ > > class NextMethodException(Exception): > pass > > class MultiMethod: > def __call__(self, *arg, **kwargs): > for i in dir(self): > if i[0] == '_': continue > try: > return getattr(self, i)(*arg, **kwargs) > except NextMethodException: pass > > Okay, thats multimethods. I really don't like the implementation all > that much, I'm sure there's a better way to do it than using > exceptions like that. Suggestions? This screams for a stack frame hack, so here it is. import inspect def multi(when=None): def build(func): try: # get the existing version of our func to fall back on try_instead = inspect.currentframe(1).f_locals[func.__name__] except KeyError: try_instead = None if (when is None): return func # else, cascade def _func(*args, **opts): if (when(*args, **opts)): return func(*args, **opts) else: return try_instead(*args, **opts) return _func return build @multi(lambda x:x == 0) def fact(x): return 1 @multi(lambda x:x > 0) def fact(x): return x * fact(x-1) print fact(0) print fact(100) Just because it is possible doesn't make a good idea *wink*, -Jack From anthonybaxter at gmail.com Sun Aug 29 23:44:17 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Mon, 30 Aug 2004 13:44:17 +1000 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: On Sun, 29 Aug 2004 13:34:52 -0400, Paul Morrow wrote: > > Have you seen a significant number of cases where a function uses > > __xxx__ attributes as local variables? Have you seen any? Locals, no. But builtins, yes. For instance, __import__. So your proposal suddently has to deal with looking up _only_ locals, not globals or builtins. I have asked this indirectly, and Jeff Epler's asked it more obviously, so, to restate it: Have you actually got a concrete, written down proposal? Have you worked through how it might work, and what the impact on the language might be? I was hoping that you'd sit down and do what Bengt Richter did and posted to the newsgroup - worked out how this stuff works, under the hood, so that you weren't just hand-waving. Oh well. From bh at intevation.de Sat Aug 21 12:44:02 2004 From: bh at intevation.de (Bernhard Herzog) Date: Sat, 21 Aug 2004 18:44:02 +0200 Subject: Alternative decorator syntax decision References: <3A81C87DC164034AA4E2DDFE11D258E3022E14@exchange.hqamor.amorhq.net> Message-ID: Peter Hansen writes: > There is a subset of the community which disfavours @pie > (many intensely). That was hard not to notice :) > Let them hold their vote to figure out > which, if any, alternative they can widely support. If > there is wide support for an alternative, it will be a > very simple matter at that point, *if* a vote is required, > to decide which of the two (@pie or the dark horse candidate) > is preferred. That's basically what I was trying to say. Although I think that we should have that vote. As I said, my impression is not that Guido wants the part of the community that dislikes the pie-syntax to propose a single other syntax. He wants the community to come up with a syntax that the community *as a whole* favors over the the pie syntax. It may well be the case there is none. We won't know that after the current vote, though, because it said to be only about an alternative. Anyway, in case it matters my vote is A1 A1 A1 Actually, what I really would like to vote for is the syntax of 2.4a2 in which there's optional whitespace after the @. Bernhard -- Intevation GmbH http://intevation.de/ Skencil http://sketch.sourceforge.net/ Thuban http://thuban.intevation.org/ From danb_83 at yahoo.com Sun Aug 8 00:47:43 2004 From: danb_83 at yahoo.com (Dan Bishop) Date: 7 Aug 2004 21:47:43 -0700 Subject: elements of decorator syntax suggestions References: <4edc17eb.0408062125.231f7bef@posting.google.com> <41155C33.37EEB397@alcyone.com> Message-ID: Jarek Zgoda wrote in message news:... > Erik Max Francis pisze: > > >> Overloading a unary prefix operator is out. As Anthony said, vertical > >> bar seemed to be the leading contender on python-dev Friday. You can > >> find tedious arguments there about most of the others that would go > >> for you. > > > > Why is | superior to @? | already has a meaning in Python, and it has > > nothing to do with decorators ... at least @ has the virtue of currently > > being unused in the language, and having the precedent of being used for > > a similar feature in Java. > > Sure, use all characters, that are still not used. Fine. I propose "^". Already used (bitwise exclusive OR). > If this fails, please consider "~" Already used (bitwise inversion). > and "`". Already used (`x` is a shorthand for repr(x)) > Oh, and ";" is still not used in Python, > what about some special meaning for that one? Already used (statement separator). The only ASCII characters that aren't used in Python are '@', '$', and '?'. From nobody at nowhere.com Mon Aug 9 10:38:14 2004 From: nobody at nowhere.com (Fred) Date: Mon, 09 Aug 2004 16:38:14 +0200 Subject: VB-like GUI designer? Message-ID: Hi, I'm currently checking out Python as an alternative to VB.Net to moving from VB, but can't find a GUI designer that is as good as VB. I tried wxDesigner and wxGlade, but neither lets me move the widgets around. I also tried Dialogblocks, but it seems to only handle C++ or XRC, not Python. Is this all there is, or is there a gem I missed? Thank you Fred. From __peter__ at web.de Thu Aug 5 03:30:18 2004 From: __peter__ at web.de (Peter Otten) Date: Thu, 05 Aug 2004 09:30:18 +0200 Subject: optparse object population References: Message-ID: Eric O. Angell wrote: > Is there a way to coerce optparse into populating an object for me? If you are dealing with just one object you can provide a custom values parameter: import optparse class Header(object): def __init__(self): self.foo = "default-foo" self.bar = "default-bar" def __str__(self): values = ["%s=%r" % nv for nv in self.__dict__.items()] return "%s(%s)" % (self.__class__.__name__, ", ".join(values)) __repr__ = __str__ p = optparse.OptionParser() p.add_option("--foo") p.add_option("--bar") p.add_option("--baz") header = Header() options, args = p.parse_args(["--foo", "custom-foo", "--baz", "custom-baz"], values=header) print "options is header", options is header # True print "header", header You can even expand that to work with nested objects, but it gets a little messy and you are probably better off with Jeff Epler's approach here: # (insert above code here) class Header2(Header): def __setattr__(self, name, value): if "." in name: left, right = name.split(".", 1) setattr(getattr(self, left), right, value) else: object.__setattr__(self, name, value) header2 = Header2() header2.nested = Header2() # I use the same class here because I'm # lazy, not for technical reasons p.add_option("--nested.foo") options, args = p.parse_args(["--nested.foo", "hi there"], values=header2) print options Especially, I have some doubts whether __setattr__("dotted.name", value) will always be allowed. Peter From richardshea at fastmail.fm Mon Aug 23 06:23:44 2004 From: richardshea at fastmail.fm (Richard Shea) Date: 23 Aug 2004 03:23:44 -0700 Subject: pyXLWriter - simple example code ? References: <282f826a.0408192035.32687e48@posting.google.com> <2omnt7FcdpspU1@uni-berlin.de> Message-ID: <282f826a.0408230223.77c95236@posting.google.com> Aurelio Martin Massoni wrote in message news:<2omnt7FcdpspU1 at uni-berlin.de>... > Richard Shea wrote: > > Hi - Anyone out there who has a simple example using pyXLWriter > > (http://sourceforge.net/projects/pyxlwriter/) they are willing to > > share with the group ? > > > > I'm interested in creating a .XLS which has multiple sheets within the > > workbook but I'm having real trouble getting started, I can create a > > Worksheet but can't figure out how to save it. > > > > thanks > > > > richard shea. > > ######################################################################## > > import pyXLWriter > > wb = pyXLWriter.Workbook( 'test.xls' ) > ws1 = wb.add_worksheet( 'First' ) > ws2 = wb.add_worksheet( 'Second' ) > ws1.write( "A1", "January" ) > ws1.write( "A2", "February" ) > ws1.write( "A3", "March" ) > ws1.write( "B1", 1.25 ) > ws1.write( "B2", 2.50 ) > ws1.write( "B3", 1.80 ) > wb.close() > > ######################################################################## > > Hope this helps Hi Aurelio - Thanks for this I appreciate it, gave me a starting point which I needed ! Just for other W32/Python people reading this the W32 style .EXE doesn't contain as much example material as the downloads so it's worth using the .EXE to install the package but then taking a peek inside the one of the others at the example directory. I used Aurelio's code and then extended it based upon what I read in the examples. An unexpected plus is that the XML files produced are able to be read by Excel97 whereas I was assuming it was Excel2000 and upwards. Thanks again Aurelio. regards richard shea. From theller at python.net Mon Aug 30 10:45:05 2004 From: theller at python.net (Thomas Heller) Date: Mon, 30 Aug 2004 16:45:05 +0200 Subject: Enumerating Network Adapters References: <4131b09e$0$13683$636a15ce@news.free.fr> <413257dd$0$26986$626a14ce@news.free.fr> Message-ID: <4qmkheha.fsf@python.net> Dave Brueck writes: > Olivier Parisy wrote: > [snip] >> But actually, a previously posted message suggests a portable way to get >> the platform IPs. Citing John Abel : >> > socket.gethostbyaddr( socket.gethostname() ) will return all the >> > details that you need to know. For example, the output of that >> > command on my machine is : >> > >> > ('hallows', [], ['101.101.101.102', '10.253.1.118']) >> Are there some pitfalls I'm not aware of ? > > Doesn't seem to work right on Windows, for me at least: > > >>> socket.gethostbyaddr(socket.gethostname()) > ('', [], ['169.254.0.100']) > > It returned the least useful of my 3 IP addresses - my loopback > adapter - but didn't return my LAN and wireless IPs. If anyone really needs it, I can post code for windows using ctypes to collect ip-addresses and netmasks together with the name and description of all network adapters. Thomas From pm_mon at yahoo.com Thu Aug 26 08:05:26 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Thu, 26 Aug 2004 08:05:26 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> Message-ID: Anthony Baxter wrote: > On Wed, 25 Aug 2004 07:20:17 -0400, Paul Morrow wrote: > >>Not exactly, but it would include defining those. One way to think >>about metadata is that it includes all information *about* an object, >>but no information *used by* the object. > > > See, for me, metadata is data about an object that is defined > explicitly as about the object. You can look at an object, and say > "Aha! It supports __getitem__, __iter__ and __len__, and is therefore > likely to be a sequence type object." This is not metadata - this is > something you've determined by looking at the object. __getitem__ and > friends *are* used by the object, and so can't be considered metadata. > I'd even say that __metaclass__ is not metadata in any sense of the > word, because it's *fundamental* to the class's workings. > Ok. Then let's jettison the baggage with the word metaclass and just call them 'magic attributes'. It doesn't matter. The essential point about them is that they almost /never have 'local variable' semantics/. They are attributes of the object being defined. That's the point I'm trying to drive home here. When we use __xxx__ attributes, we are not intending to create local variables. No. We are making declarations. > Something like Zope3's Interfaces, which allow you to specify the > Interfaces that an object or class implements, are closer to metadata, > but note that even there, we've gone from an initial API of: > > class Foo: > __implements__ = ( IFoo, ) > > to > class Foo: > implements(IFoo) > > ... moving away from the double-under form to a more readable and > useful form. The new form allows for far more powerful and useful > behaviour, such as inheritence of interfaces from base classes. > Twisted has also moved from using the former style to the latter. > These are two _very_ large bodies of code, with a lot of very clueful > people working on them - and they found that the magic double-under > name was inferior to an explicit call syntax. > Woah Man! I thought you wanted special functionality to have special syntax, so that it really sticks out that we're doing something special? It sounds like now you are /endorsing/ the use of normal looking syntax that does special things. Personally, the look of the old '__implements__' syntax was vastly superior. In an instant, an experienced pythonista could see that magic was being peformed on Foo. That fact is obscured in the new 'implements' syntax. Wait. Did I just argue your point from an earlier thread? :-) See, we do (or at least 'did') agree on some things... > >>If we were to have a conversation about this conversation, then we would >>be having a "meta-conversation." /metadata/ is data that describes >>data. metadata for a function would be data that describes the >>function; data *about* the function as opposed to data *used by* the >>function. For example: >> >> def circumference(diameter): >> """ This is a docstring. It's metadata for this function. """ >> __author__ = 'Paul Morrow' # more metadata >> pi = 3.14 # not metadata >> return pi * diameter > > > There are a small number of double-under names that are used for > metadata - most of them are automatically inserted by Python > automatically. The overwhelming number of double-under names are not > metadata in any way. I don't need to debate that for my position to be valid. How about from now on we just call it magic data? That works fine for me. As long as we're clear that it's not (intended to be) 'local data'. That it has more of a declaration semantics. Paul From eric_brunel at despammed.com Mon Aug 30 04:04:32 2004 From: eric_brunel at despammed.com (Eric Brunel) Date: Mon, 30 Aug 2004 10:04:32 +0200 Subject: Canvas scrolling - scrollBar become "disabled" on change in canvas References: Message-ID: Askari wrote: > Hi, > I do a "perso"widget where have two scrolls (one vertical, one > horizontal) for a canvas. > When, the first time, I added widget in the canvas, the scroll self-ajust > and when I move scrollbar, the surface's canvas "moved". Well... It shouldn't... The only way to make the scrollable area larger is by using theCanvas.configure(scrollregion=(x1, y1, x2, y2)); adding items into the canvas should have no effect at all on it... > But when I deleted > (.destroy) this first widgets and that a added other widget, the scrollBar > become disabled (ajust for no scroll on the canvas). What/where is the > problem? Can you please post some (simple) code that shows this behaviour? Without a clear idea about what you're doing, it will be quite difficult to help you... > I use basic widget (scrollBar, Canvas, Frame, etc.) from library's Tkinter > (and python 2.3.4 on WinXp Pro (sp1)) > > Askari -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From beliavsky at aol.com Mon Aug 16 09:12:07 2004 From: beliavsky at aol.com (beliavsky at aol.com) Date: 16 Aug 2004 06:12:07 -0700 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> <30260531.0408131853.18ec2446@posting.google.com> <412040f8$0$8087$a1866201@newsreader.visi.com> Message-ID: <3064b51d.0408160512.5358939@posting.google.com> Peter Hansen wrote in message news:... > For example, if 90% of people who have the "indentation rash" > had previous encounters with FORTRAN IV, then it ought to > be possible to make it obvious in the early documentation > (tutorial, intro page, etc) that Python is not FORTRAN and > doesn't suffer from the same limitations with respect to > indentation/whitespace significance as FORTRAN does. Uh oh, people are picking on my beloved Fortran :). Fortran IV was standardized as Fortran 66. Even the following Fortran standard, Fortran 77, had only "fixed format" with the rigid column restrictions. The Fortran 90 standard introduced free format, and I think such code resembles Python more closely than other compiled languages, because there are no semicolons needed to terminate lines, and curly braces are not used to delimit blocks. It would be misleading to discuss certain flaws of earlier versions of Fortran without mentioning that they have long since been corrected. Btw, the official spelling has been "Fortran" (not all uppercase) since the 1990 standard. I have done a good bit of coding in both Python and Fortran and still (mildly)prefer using key words rather than indentation to terminate blocks, for example do i=0,9 ! some code enddo compared to for i in range(10): # some code In Fortran you easily wrap a do-enddo or if-endif around a block of code without touching the interior lines. This is useful for debugging. If the change is permanent, the code should be re-indented. In Python the indentation must be correct at all times, which can be inconvenient. From hans at zephyrfalcon.org Sat Aug 21 00:30:04 2004 From: hans at zephyrfalcon.org (Hans Nowak) Date: Sat, 21 Aug 2004 00:30:04 -0400 Subject: [newbie] Strange behavior of the re module In-Reply-To: <2ejdi01btug5iskb4ipjpj7eaprd8i7vgm@4ax.com> References: <2ejdi01btug5iskb4ipjpj7eaprd8i7vgm@4ax.com> Message-ID: <4126CFCC.8000609@zephyrfalcon.org> Fred wrote: > stuff="\colortbl\red0\n0" > > template = "BLA" > > template = re.sub('BLA', stuff, template) > -------------------------------- > > => It appears that the re module isn't very friendly with backslashes, > at least on the Windows platform. Does someone know why, and what I > could do, since I can't rewrite the source HTML documents that contain > backslashes. It's not the re module, it's that backslashes have special meaning in string literals. See also: http://docs.python.org/tut/node5.html#SECTION005120000000000000000 http://docs.python.org/ref/strings.html To use a non-escaping backslash in a string literal, use a double backslash: stuff = "\\colortbl\\red0\\n0" or a raw string: stuff = r"\colortbl\red0\n0" HTH, -- Hans Nowak (hans at zephyrfalcon.org) http://zephyrfalcon.org/ From danny.hope at gmail.com Wed Aug 25 10:44:28 2004 From: danny.hope at gmail.com (Yandle) Date: 25 Aug 2004 07:44:28 -0700 Subject: Group for Plone Users Message-ID: I have just started tinkering with Plone and, as is to be expected, I've run into some issues. What I want to know is: does anybody know if there's a group for Plone users as opposed to Python programmers or Zope administrators? From charlie at XXXk-international.comXXX Tue Aug 24 12:17:34 2004 From: charlie at XXXk-international.comXXX (CJ) Date: Tue, 24 Aug 2004 17:17:34 +0100 Subject: [OT] Juce Message-ID: <7SJWc.367$5_.162@newsr2.u-net.net> FYI Not sure if this type of thing is useful as I am a beginner and its C++ but it does look very interesting. CJ http://www.rawmaterialsoftware.com/juce/ To quote JUCE is an all-encompassing C++ class library for developing cross-platform applications. It's particularly good for creating highly-specialised user interfaces and for handling graphics and sound. The intended users are developers like me, who are writing large, complex applications in C++ and who would like to use just one clean, high-level API rather than a bunch of different libraries for different purposes or platforms. From jepler at unpythonic.net Tue Aug 17 07:55:40 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 17 Aug 2004 06:55:40 -0500 Subject: how to display unicode in a Label in Tkinter In-Reply-To: <8f17f4bc.0408161437.2f557935@posting.google.com> References: <8f17f4bc.0408151819.c06a79e@posting.google.com> <8f17f4bc.0408161437.2f557935@posting.google.com> Message-ID: <20040817115539.GA30972@unpythonic.net> On Mon, Aug 16, 2004 at 03:37:21PM -0700, Ali wrote: > So how I write in Arabic? You're unlikely to get anything satisfactory. Tk doesn't do right-to-left text layout, and it does character-at-a-time drawing which means you won't get the proper linking between the characters. I don't know if this bad news is out of date by now, but it certainly applies to Tk 8.2 and 8.3 on Unix and Windows. Here's some related advice from the tcl/tk wiki: http://wiki.tcl.tk/699 but you have to have the stomach to read tcl code. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From lopexx at autograf.pl Mon Aug 16 04:19:58 2004 From: lopexx at autograf.pl (lopex) Date: Mon, 16 Aug 2004 10:19:58 +0200 Subject: Best programming language In-Reply-To: References: Message-ID: Roman Suzi wrote: > ;-) > > Just type into google > "best programming language" > and press (I am lucky) > Ruby ? Marcin Mielzynski From in.aqua.scribis at nl.invalid Mon Aug 30 07:33:00 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Mon, 30 Aug 2004 13:33:00 +0200 Subject: regex into str In-Reply-To: References: Message-ID: Jeremy Bowers schreef: > On Sun, 29 Aug 2004 12:58:57 +0200, Peter Kleiweg wrote: > > > That is not relevant. What matters is that a += 'b' does what it > > is supposed to do. > > If you want to be that way, then fine. No, it doesn't do what it is > "supposed" to do, in the context you are discussing. It does not add a "b" > to the original string, it creates a new string containing the original > contents plus the new contents. Yes, exactly as it is supposed to do. -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From jeff at ccvcorp.com Thu Aug 12 18:13:31 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Thu, 12 Aug 2004 15:13:31 -0700 Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: <411bd3f0$1@nntp.zianet.com> References: <60dfb6f6.0408111846.615ee9eb@posting.google.com> <3YWdnYxLf--ObofcRVn-pw@powergate.ca> <411ba1db$1@nntp.zianet.com> <411bd3f0$1@nntp.zianet.com> Message-ID: <10hnqqm8h7b3k89@corp.supernews.com> Mark Bottjer wrote: > > FWIW, I don't object to the keyword, I object to the indented block. I > agree that newbies will need to look either up. My only real concern > is that certain suggested syntaxes (mostly the list or tuple forms) > look innocuous enough that newbies may not realize that they've hit > something new. Everything past there seems more and more like simple > preference. The interesting thing here is that it seems that the reason you dislike the indented block is the reason given for preferring it by those people who *do* like it -- the fact that it *looks* like normal Python. Frankly, if a new feature is so radically different from the rest of Python that it's deemed that it needs to *look* radically different from the rest of Python for it to be understood... that, to me, suggests that it's a feature that shouldn't exist in Python. All the criticisms aimed at the decorate: syntax, ISTM, apply equally well to @pie syntax, except for the few that are based on indentation level. And on those, *I* at least feel that it'd be preferable to pattern decorators after existing language constructs, rather than deliberately breaking all the patterns that Python has established. I don't see the indented declarations as any harder to understand that nonindented, @tagged declarations, but I *do* see them as being much easier to read. And I expect to read a lot of code, so having something visually jarring seems like setting myself up for a future full of low-grade anguish. I see your point about it looking a bit odd that an indented block contain only declarative statements. However, the @pie mess in front of function defs looks, to me, to be not just odd, but downright obfuscatory. It's *much* harder for my eyes to pick out the def and thus the function name, and all I see is a function body dangling from a blob of @pies. Yes, this is personal preference, but it seems that it's a preference shared by many people -- isn't Python supposed to fit my brain, rather than forcing my brain into Python's shape? The fact that one can get used to @pie-syntax doesn't mean it's intuitive. The fact that the feature is new doesn't mean that we need an entire new code-layout principle. The differences between class & def, on the one hand, and try/except & if/else on the other, don't seem to confuse people too much. I'd rather see the same layout principle applied in a different way than see an unprecedented and unfamiliar layout principle used in one or two special cases. Jeff Shannon Technician/Programmer Credit International From newsgroups at jhrothjr.com Fri Aug 6 15:00:41 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 6 Aug 2004 15:00:41 -0400 Subject: Prothon is switching to the .NET platform References: <000401c47b59$32539220$0d01a8c0@MarkVaio> Message-ID: <10h7lb21dhbuc12@news.supernews.com> "Christopher T King" wrote in message news:Pine.LNX.4.44.0408061247130.22947-100000 at ccc8.wpi.edu... > On Thu, 5 Aug 2004, Guido van Rossum wrote: > > > So now I'm a bit disappointed to hear that you're giving all that up > > and switching to the CLR. > > Ack! I was looking forward to playing with and hacking on Prothon in the > future (I'm a big fan of prototypes), but .Net is a big turnoff > (especially coming from the Linux side of things). Is this happening > primarily to provide immediately access to large code libraries? I think it's possible to do prototypes within Python by overriding the __getattribute__() magic method. It still wouldn't be very pretty, but it should be able to do everything except override the magic methods (those seem to have to be in the class object for new style classes). John Roth > From mark_bottjer at hotmail.com Fri Aug 6 13:48:55 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Fri, 06 Aug 2004 13:48:55 -0400 Subject: @decorators In-Reply-To: References: Message-ID: <4113c488@nntp.zianet.com> Tor Iver Wilhelmsen wrote: > I think what he meant was that the decorators in effect make for > "hidden continuation", e.g. > > @foo > def fooDecorated(): > pass > > is like > > @foo def fooDecorated(): > pass: > > when other line continuations are explicit. Which is *exactly* why I dislike this syntax so much. I don't mind the "@", though it does look a might out-of-place. What I dislike is the placement: It relies on setting a "magic state" in the interpreter to affect the very next thing at the same indentation level. I can't think of any other place in Python where this sort of thing is done. Everything else either introduces a new block, or requires bracketing. Everyone shows the examples like above, but what about the following? class C: # This is a really long comment that has little to do # with the following function; it is here only so that # the comment wraps. This is a really long comment that # has little to do with the following function; it is # here only so that the comment wraps over several lines. @ staticmethod # MAB 20040806113000: Added argument baz. # MAB 20040806112957: Added argument bar. # MAB 20040806112950: Initial version. def static_method_foo( bar, baz): pass Did you catch it? This method *is* decorated, though it is hard to see it unless you are really looking for it. Syntax coloring will help, of course, but not much, and we shouldn't rely on that anyway. My concern is that the decorator can be separated from the decorated by an arbitrarily large amount of space. Even ONE blank line is enough for me to mentally dissociate the decorator from the decorated. Comments make it worse. Now, would a sane programmer do this? One would hope not, but there is nothing to prevent it--and I've found that the definition of "sane" varies widely between programmers. What I think might work better is to treat these decorators the same way we already treat docstrings. def decorated( a, b, c): @classmethod @signature( None, a=int, b=float, c=dict) @transactional( database) """\ decorated( a, b, c): A thrice-decorated function. The silly function does nothing except get "decorated." classmethod determines the form of the first argument (class, object, or other). signature changes the call behavior, asserting the types passed to and returned from the function. Finally, transactional causes boilerplate code to be executed before and after the function body, ensuring that either all changes to database are applied, or none are. Seeing as this function does nothing, this is trivial :). """ pass Personally, I kind of like the "@" syntax in this form. It still sticks out (and IMHO, it *should* stick out, because it is not a normal statement), but it also is easier to ignore if you aren't looking for it because it is explicitly scoped at the function level. We already expect metadata--namely, the docstring--to be at the top of the function. This simply extends that idea to include other forms of metafunctionality. The compiler already looks for metadata at the start of functions; the special syntax helps the compiler determine which statements need to be handled immediately, and where the function implementation starts. -- Mark From nicoe at no-log.org Wed Aug 4 09:56:15 2004 From: nicoe at no-log.org (Nicolas =?iso-8859-15?Q?=C9vrard?=) Date: Wed, 4 Aug 2004 15:56:15 +0200 Subject: Perl's Crypt::PasswdMD5 In-Reply-To: References: Message-ID: <20040804135615.GD7464@smarties.nutellux.ath.cx> * Bart Nessux [15:39 04/08/04 CEST]: >Does Python have anything similar to Perl's Crypt::PasswdMD5??? > >I read about the crypt module... but it only does DES. Any plans to add >md5 or other digests to it in the future? http://www.python.org/doc/current/lib/module-md5.html Try to be lucky with google using this search string : "python md5" -- (?> Nicolas ?vrard / ) Li?ge - Belgique ^^ Listening to: old po molasses From deetsNOSPAM at web.de Tue Aug 17 12:01:28 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Tue, 17 Aug 2004 18:01:28 +0200 Subject: 'ascii' codec can't encode character u'\xf3' References: <4120F820.4000703@fusiondementes.com> <20040817061745.GA4259@barbucha.martin.net> Message-ID: oziko wrote: > Now I can print the tags with no aparent problem. But now whe I tried to > insert that value into a PostgreSQL data base I get the same error. I > create the PostgreSQL database with default Unicode with There seems to be a general misunderstanding about what unicode, an encoding and all that together in python means. Unicode is only an abstract definition of character-sets - the usual suspects like what is in ascii, but also nearly everything somebody on this planet of ours cares to write down once in a while. Now an actual encoding is how these totally abstract character sets are mapped to actual values. So for the capital letter "A", the ascii encoding maps it to the well known value 65. BUT: You can define another encoding, call it oziko or whatever, and map "A" to 1 - if you like it. Now UTF-8 is also only an encoding - with the capability to map most of ascii on the usual numbers where you expect them, and a few escape chars that allow for multi-byte seqhences to appear in the text that encode one character. So it can encode the whole unicode set, on the price of not beeing able to determine the length of a string by dividing the number of bytes it contains it by the number of bytes a character uses - usual one. So this is an extremely important lesson: unicode is _not_ - I repeat, _not_ - UTF-8. Now python has unicode objects. They are sequences of characters - what shape these internally have is opaque to you and not of your concern. They are _not_ strings!!!! strings in python are sequences of bytes - as we are used to from C. Now whenever you want to use a string that is encoded in a special encoding, you can get it from a unicode-object by invoking encode on it. Thats what u.encode('iso-8859-1') does, if s is a unicode object. The other way round, if you have a byte-sequence - conveniently stored in a string - and want to get a unicode object from it, use decode s.decode('iso-8859-1') Now if you pass a unicode object to a function that wants a _string_, python applies for you an automatic encode - with the default encoding!!!! As this is usually ascii, you get the problems you had. So what do you need to solve your problem at hand? You need to know which encoding the sql driver wants for transmitting strings - most probably utf-8, so they can encode all possible characters. And thus you have to encode tthe strings you pass beforehand, or set the default encoding properly. The last thing is to explain where the u''-thingies fit in. They are a shortcut for getting a unicode object - whatever characters are encountered inside the u'', is interpreted with the encoding the python interpreter uses to parse file at hand. Which one that is can either be specified implicit (system settings) or explicit using the -*- coding: -*- line on top of the source file. You might want to start reading about unicode and python on the net, google is as always your friend. -- Regards, Diez B. Roggisch From davebrok at soda.csua.berkeley.edu Tue Aug 17 13:29:43 2004 From: davebrok at soda.csua.berkeley.edu (David Pokorny) Date: Tue, 17 Aug 2004 10:29:43 -0700 Subject: simple Thread question References: Message-ID: "adeger" wrote in message news:b8001e9f.0408041233.1b3ca73c at posting.google.com... > JCM wrote in message news:... > > You should override the run method, but call thread.start() to kick > > the execution off in a separate thread. If you call thread.run(), > > you're just running your code in the same thread. > > > > Thanks JCM and everyone else for your help! This wasn't that clear to > me reading the docs (I really DID read them) and your answer saved me > a bunch of personal (and program execution) time! It's worth pointing out that while print bytecodes are atomic, print statements are not. So unless a) you use your own lock to control output via "print" or b) you pass only 1 argument to print, you run the risk of creating output like: ... thread a instance 33 thread a instance 34 thread a instance 35 thread a instance 36 thread a instance 37 thread a instance 38 thread a thread b instance instance 39 1 thread thread a instance b instance 2 40 thread a thread b instance 3 thread b instance 4 thread b instance 5 thread b instance 6 thread b instance 7 ... To create the desired bad behavior, comment out the three statements that refer to plock. --- import threading,time,sys plock = threading.Lock() class TestThr(threading.Thread): def __init__(self,name): self.name = name threading.Thread.__init__(self) def run(self): for i in range(1,100): plock.acquire() print 'thread', self.name, 'instance', str(i) plock.release() #time.sleep(.1) def test(): for tname in ('a', 'b', 'c'): thread = TestThr(tname) thread.start() --- David From dbickett at gmail.com Wed Aug 18 18:03:05 2004 From: dbickett at gmail.com (Beeyah) Date: 18 Aug 2004 15:03:05 -0700 Subject: age of Python programmers References: Message-ID: <1d6cdae3.0408181320.1063c182@posting.google.com> "Lucas Raab" wrote in message news:... > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... I'm only fifteen, having done the programming thing for a little over two years now. Python is a new development for me; I've been using it in the past year, and plan to stick with it :) From paulpaterson at users.sourceforge.net Wed Aug 25 20:28:28 2004 From: paulpaterson at users.sourceforge.net (Paul Paterson) Date: Thu, 26 Aug 2004 00:28:28 GMT Subject: Call for signatories for J2 In-Reply-To: References: Message-ID: For Paul Paterson From ben at benlast.com Sat Aug 28 16:05:40 2004 From: ben at benlast.com (Ben Last) Date: Sat, 28 Aug 2004 21:05:40 +0100 Subject: allowing braces around suites In-Reply-To: Message-ID: > From Roel Schroeven > > Paul McGuire illustrated the corresponding problem in C: > > db->update_name(person); > > > > if (is_student(person)) > > log("update student %s", person->name); > > db->update_courses(person); > > db->commit(); > Sorry, I meant "C or C++, even with consistent use of braces", implying > that using braces IMO in general doesn't help spotting this kind of bugs. On the other hand, *compulsory* use of them, and eliminating the "special case" of one-line blocks, might. It's that special case that bites here, braces or no braces. Not that I'm in favour of the braces idea - I think it's redundant in the extreme, and misses the point of Python big time. :) ben From rogerb at rogerbinns.com Tue Aug 17 22:34:51 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Tue, 17 Aug 2004 19:34:51 -0700 Subject: No validation routine for an os.path References: Message-ID: Edward Diener wrote: > I do not totally agree, especially as the OS will know whether > something is valid so it obviously has rules itself. But I grant it > is more difficult than might be assumed. BTW email addresses actually > do have a format which can be parsed ( RFC 822 originally ), although > again it is complicated. I don't think Peter meant whether or not you can extract an email address, but rather if it is actually valid. For example, which of these are valid? john at example.com foobar at nosuchdomain.com fred!foovax!kremvax!nasa one at two@three.com As a bonus question, are email addresses case sensitive? Roger From arien_malec at yahoo.com.REMOVE Tue Aug 24 20:26:47 2004 From: arien_malec at yahoo.com.REMOVE (Arien Malec) Date: Wed, 25 Aug 2004 00:26:47 GMT Subject: PEP318: radical notion References: <412a4222$0$293$626a14ce@news.free.fr> <412bc7e6$0$4065$626a14ce@news.free.fr> Message-ID: Christophe Cavalaria wrote in news:412bc7e6$0$4065$626a14ce at news.free.fr: > Arien Malec wrote: >> Is there a valid use case that supports arbitrary magical >> non-metadata transformations of standalone functions? > > memoize for example. No metadata, only transformation, doesn't really > apply to a member function in fact ( although it might be possible ? Classically, memoize is implemented as function composition, or as a true GoF decorator. It's not clear (to me, at least) how much benefit the syntactic sugar gets you. > Why is it that there are always some people who doesn't understand all > the possibilities of decorators and so want to minimise their > usefulness ? I dunno. Who are those people? My objection to PEP318 is that makes something that's really powerful (arbitrary transformation) look like a trivial declaration. In Common Lisp, for instance, a defmacro form hints that powerful mojo is being performed; the same is not apparent in PEP318. Arien From raims at dot.com Tue Aug 10 11:14:30 2004 From: raims at dot.com (Lawrence Oluyede) Date: Tue, 10 Aug 2004 17:14:30 +0200 Subject: Importance of C# (was Re: IronPython-0.6 is now available!) References: <278de0e.0407281353.27b6a457@posting.google.com> <5dydnZSDZaARoZXcRVn-ug@powergate.ca> <1n5z28erh2m3u.dlg@baczek.net.invalid> <537ea4cd.0408070757.14790cfe@posting.google.com> <41155c78$0$4348$626a14ce@news.free.fr> <144d0df.0408092156.1455f2af@posting.google.com> <1o2ouxh30essi.1eewz4ary5xj3.dlg@40tude.net> <4edc17eb.0408100607.d620f9b@posting.google.com> Message-ID: <1h74vgi67xuic$.140m5wbywlm4z.dlg@40tude.net> In data 10 Aug 2004 07:07:04 -0700, Michele Simionato ha scritto: > Even knowing about the MRO MI can be painful. Actually, > after fighting with MI in Zope I am starting to hate > it ... :-( Maybe because they use it *too much* ? After seeing the (Twisted, Nevow, Atop) source code I recognized that MI could be useful (they don't use it too much, but they do) Ciao Michele :) ps. anyway I'm agree with you, the lesser the better. -- Lawrence (l dot oluyede at virgilio dot it) "In IE we trust" From dperl at rogers.com Mon Aug 30 10:19:04 2004 From: dperl at rogers.com (Dan Perl) Date: Mon, 30 Aug 2004 14:19:04 GMT Subject: initializing mutable class attributes References: Message-ID: I will clarify something that was probably not clear enough in my initial posting. I am interested in instance attributes, but I am using the class attributes to provide a default, "null", value for the instance attributes. Yes, the instance attributes only mask the class ones, but a class attribute and an instance attribute can be used like this: class WorksForMe: attr=None # used just as a default value for the instance attribute self.attr def foo(self): self.attr=SomethingUseful( ) def bar(self): if self.attr: useIt(self.attr) else: ignoreIt(self.attr) This makes it safe for an instance of WorksForMe to invoke bar( ) even if it never invoked foo( ). "Benjamin Niemann" wrote in message news:cgul4v$h1d$1 at online.de... > That's the way it is supposed to work. Instance attributes have to be > initialized via self.foo=..., usually in __init__() which in turn is > *STRONGLY* advised to class its parents __init__() - or you create > instance attributes 'on-the-fly' when they are used for the first time > (useful technique for mixin classes without constructor). Class > attributes are initialized once for the class and are shared between > instances. You are confirming the code I suggested but you don't share my view that such code is awkward. I think I I was actually conservative calling it awkward, I would rather call it unsafe. If I were a third-party library vendor, I would not be comfortable providing a mixin class that forces users to either invoke the parent's __init__ in their constructors or to initialize the instance attributes on-the-fly. The latter would even be against the principles of encapsulation, users should not need to know about the parent's attributes, especially because they may change in future releases. Both ways of restricting the use of the mixin class are unsafe because they are easy to be ignored by users. And it is not only the users' fault if they do not follow the restrictions, it is also my fault to put such restrictions in the first place. I think this points to a weakness in Python as an OO language. I'm not trying to bash it, but my understanding is that Python is still evolving in that respect and I think that this should be improved in the future. Then, on the other hand, maybe I'm the only one feeling this way and there's not going to be a change. > "self.attr1=data" in Father.foo() doesn't "override" the Father.attr1 > attribute you defined before. It creates an instance attribute that > shadows Father.attr1! > Both attribute assignments in Father are OK - if you treat them as class > attributes. They won't become instance attributes by hidden magic. > > Dan Perl wrote: > > There is something with initializing mutable class attributes that I am > > struggling with. I'll use an example to explain: > > class Father: > > attr1=None # this is OK > > attr2=[ ] # this is wrong > > def foo(self, data): > > self.attr1=data > > self.attr2.append(data) > > The initialization of attr1 is obviously OK, all instances of Father > > redefine it in the method foo. But the initialization of attr2 is wrong > > because all the instances of Father end up sharing the same value. Maybe > > that is desired sometimes, but usually it is just a bug. > > > > So the only solution I see to this is to initialize attr2 in __init__: > > class Father: > > attr1=None > > def __init__(self): > > self.attr2=[ ] > > > > This is already awkward because there is such a difference between attr1 and > > attr2. But moreover, I think this forces subclasses of Father to do > > something like this: > > class Child (Father): > > def __init__(self): > > Father.__init__(self) > > self.attr3=[ ] > > > > I find this even more awkward because many people will forget to do it. > > Clearly, this is then a more general issue with __init__, but I think it is > > accentuated by the fact that you HAVE TO HAVE __init__ in order to > > initialize attributes that are mutable. > > > > Is there something I don't know here and there is a better way to do this in > > Python? I would like to get a better solution or otherwise start a > > discussion. > From steven.bethard at gmail.com Thu Aug 19 02:07:50 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: 18 Aug 2004 23:07:50 -0700 Subject: inverse of izip Message-ID: So I know that zip(*) is the inverse of zip(), e.g.: >>> zip(*zip(range(10), range(10))) [(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)] What's the inverse of izip? Of course, I could use zip(*) or izip(*), e.g.: >>> zip(*itertools.izip(range(10), range(10))) [(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)] >>> x, y = itertools.izip(*itertools.izip(range(10), range(10))) >>> x, y ((0, 1, 2, 3, 4, 5, 6, 7, 8, 9), (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)) But then I get a pair of tuples, not a pair of iterators. Basically, I want to convert an iterator of tuples into a tuple of iterators. Steve From grante at visi.com Mon Aug 23 22:19:13 2004 From: grante at visi.com (Grant Edwards) Date: 24 Aug 2004 02:19:13 GMT Subject: Getting at the bits of a 32-bit integer References: <85b54e91.0408231552.75f85727@posting.google.com> <412a98f4$0$65569$a1866201@newsreader.visi.com> Message-ID: <412aa5a0$0$68775$a1866201@newsreader.visi.com> On 2004-08-24, Jeremy Bowers wrote: > On Tue, 24 Aug 2004 01:25:09 +0000, Grant Edwards wrote: >>> However, I must challenge your need to do this in the first place. >> >> That's a bit, um, conceited. > > I said "challenge", not "deny". True, but to me "challenging" somebody's need to do something implies that you've got some sort of right or authority to require them to justify what they want to do. I've probably inferred more than I should. I'm a bit touchy on the subject now that the Python "int" is going to go away and break some of my admittedly sloppy code. > If you're new to Python and you are twiddling bits, the odds > favor the new user falsely importing old paradigms from other > languages, Probably so. -- Grant Edwards grante Yow! ALFRED JARRY! Say at something about th' DEATH visi.com of DISCO!! From fumanchu at amor.org Thu Aug 26 11:35:15 2004 From: fumanchu at amor.org (Robert Brewer) Date: Thu, 26 Aug 2004 08:35:15 -0700 Subject: Call for signatories for J2 Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E82@exchange.hqamor.amorhq.net> Pierre-Fr?d?ric Caillaud wrote: > I'll vote for it. Thank you! I'd like to take this opportunity to say two things: 1) THANK YOU to _all_ who have signed. Keep 'em coming! 2) I'm counting as signatories everyone who "votes", but I'd like to make clear that your name on the document isn't a vote, it's an endorsement. It's a subtle point, but Guido is the only one who will "vote". :) > Can we insert conditional expressions in the decorator list ? Not with the current patch; however, that option may be allowed in the future. The order of operation would have to be reversed, so *IF* Guido votes yes, then you need to bring this up again immediately. Robert Brewer MIS Amor Ministries fumanchu at amor.org From elbertlev at hotmail.com Fri Aug 6 12:37:22 2004 From: elbertlev at hotmail.com (Elbert Lev) Date: 6 Aug 2004 09:37:22 -0700 Subject: Prothon is switching to the .NET platform References: <000401c47b59$32539220$0d01a8c0@MarkVaio> Message-ID: <9418be08.0408060837.781e8c37@posting.google.com> > in .NET). Basically, telling people "here's my language, it's a 2 MB > download, and oh, BTW, you also need to install the 200 MB runtime Not that bad :) Only 20Mb From peter at engcorp.com Mon Aug 23 15:13:15 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 23 Aug 2004 15:13:15 -0400 Subject: On consensus decision-making (was Re: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WEDONE?) In-Reply-To: References: Message-ID: Aahz wrote: > In article , > Peter Hansen wrote: > >>The voting was merely to narrow down the choices. It seems pretty >>clear there are now only three candidates in the running, the @pie >>syntax plus J2 and C1. The latter doesn't yet have an implementation, >>which is almost certainly its biggest disadvantage (and not that more >>people voted for J2 than for it). > > According to a python-dev message from Michael Hudson, there's an old > implementation of C1 (the *original* decorator implementation). ;-) I suppose, then, that Guido really hasn't relented or he would still be considering it strongly. I suspect that in comparison to either @pie (I assume that's A1, but I've lost track) or J2 he feels C1 is just not readable enough to be in the running. I guess, much as I feel C1 is one of the most Pythonic, I also feel it is not as readable as either A1 or J2. Much less ugly than A1, but not as readable... strange how I feel that now... Anyway, I suppose this means that the selection will be from amongst A1, C1, and J2, each with an implementation, each with a sizable number of proponents. Wish the man well. ;-) -Peter From h.b.furuseth at usit.uio.no Fri Aug 6 05:53:29 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 06 Aug 2004 11:53:29 +0200 Subject: tweaking @decorator syntax References: Message-ID: Andrew Durdin wrote: > it is > not at all obvious to me that it is rather a kind of attribute or > modifier of the following function definition. I don't know of any > other construction in Python that performs a similar, unmarked (i.e. > non-explicit) modification of the following statement. Right. Today, both the human and the compiler can parse that kind of thing just by looking at the indentation. Still, if we do get a new way to indicate that something is parsed differently, then a special character like @ would be good for that. '@some-directive' in general could be a statement which the compiler reacts to in some way, and decorators could be a special case: @decorator instead of just @ That gives the human reader a keyword he can relate to instead of a special character with an obscure meaning, and the @ character tells him that there is something special about this statement. Though in the case of decorators, I still prefer several of the other suggestions over this one. -- Hallvard From ajsiegel at optonline.com Thu Aug 5 20:41:07 2004 From: ajsiegel at optonline.com (Arthur) Date: Fri, 06 Aug 2004 00:41:07 GMT Subject: Decorator syntax References: <38ednYT1NLz1P4zcRVn-uA@powergate.ca> Message-ID: On Thu, 5 Aug 2004 09:45:40 -0400, Christopher T King wrote: > >I think much of the problem in coming up with a universally acceptable >decorator solution is that we're trying to kill too many birds with one >stone. I believe the decorator problem can be seperated into at least >three distinct needs: I don't pretend to have an adequate grasp of the technical issues: But I certainly find the argument you make in the portion oif the post that followed from the above well constructed and (intuitively) convincing. Though I am also intuiting that the fact that I happen to do so may not have a major influence on the debate ;). Art From simoninusa2001 at yahoo.co.uk Thu Aug 12 18:59:55 2004 From: simoninusa2001 at yahoo.co.uk (simo) Date: 12 Aug 2004 15:59:55 -0700 Subject: VB-like GUI designer? References: <30260531.0408102005.5847b9c@posting.google.com> <3hpou1-09i.ln1@home.rogerbinns.com> <30260531.0408120944.5d9ea9f2@posting.google.com> Message-ID: <30260531.0408121459.42e200fd@posting.google.com> Replying to my own post to Roger Binns: > > > I noticed you have RPMs for Linux - so what do they include - a > > > complete wxWidgets/GTK+/Python distribution, plus your files? > > The file in /usr/bin is a shell script that just execs the dotamatic > > binary in /usr/lib. The dotmatic executable is actually the Python > > interpretter with an archive containing the bytecode appended. > > Only the Python and wxPython modules used are present. It seems you're using cx_Freeze, well I've just got 3.0b2 working under Windows, but I seem to recall I could never get 2.2 to work under Linux, time to try again I guess. It doesn't seem quite as nice as py2exe under Windows - doesn't do resource editting, so you still need to include a manifest file and link the .ico to the Desktop shortcut etc; but if it will work better than McMillan Installer under Linux, I shall be very pleased! Then I have to figure out how to make KDE/Gnome Desktop shortcuts, make RPMs, oh and finish my program! ;o) From nospam at here.com Sat Aug 7 12:47:30 2004 From: nospam at here.com (Richard Townsend) Date: Sat, 7 Aug 2004 17:47:30 +0100 Subject: Tkinter "tab viewing" how-to? References: Message-ID: On Sat, 07 Aug 2004 15:45:39 GMT, Ivo wrote: > I would implement a tab viewing (like mozilla) using the Tkinter toolkit. > Does anyone know if is it possible and where i can find doc about? Python mega widgets (Pmw) are written in Tkinter. Have a look at the NoteBook widget. http://pmw.sourceforge.net/ http://pmw.sourceforge.net/doc/NoteBook.html regards, Richard From p_s_oberoi at hotmail.com Mon Aug 16 14:23:03 2004 From: p_s_oberoi at hotmail.com (Paramjit Oberoi) Date: Mon, 16 Aug 2004 13:23:03 -0500 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> <30260531.0408131853.18ec2446@posting.google.com> <412040f8$0$8087$a1866201@newsreader.visi.com> Message-ID: >> It seems to me that you're asking for a rational explanation >> for an emotional response. It's like asking somebody "*why* >> don't you like pickled beets?" The answer you get is "I just >> don't." > > Hmm... not for me. The answer would be "because they > taste like dirt", or "I hate purple", or "anything pickled > sucks". "I just don't" looks a lot like a cop-out. If That's what you would say, but who knows whether that answer would be correct? It could be that you are simply not comfortable with answers like "I just don't" which go beyond logic, and thus your brain manufactures reasonable logical reasons when needed. "I don't know" may actually be a more honest response than whatever logical response is offered. Reasoned, rational reactions are our attempts to understand how we function. Our nervous system doesn't care about reasoned, rational reactions. :-) From deetsNOSPAM at web.de Sun Aug 29 13:59:11 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Sun, 29 Aug 2004 19:59:11 +0200 Subject: regex into str References: Message-ID: Jeff Epler wrote: > This is intended to be impossible. > > Even if you could assign to str.__div__ (and this is very deliberately and > specifically disallowed) you would end up disappointed, because strings > are immutable. That means there's nowhere to store "the last match", > no way to mutate the string with the "/=" operator, and also that the > interpreter is free to use the same storage for two equal strings. Another reason for not allowing this is that modifying builtins can lead to severe bugs, as other libs might rely on certain functionality. If you change that, things start getting very weird.... -- Regards, Diez B. Roggisch From deetsNOSPAM at web.de Wed Aug 25 17:22:25 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Wed, 25 Aug 2004 23:22:25 +0200 Subject: authentication service for unix References: Message-ID: > Using PAM is definitively not the reason why your process must be run > as root. What exactly are you doing? Well, I started fiddling around with pam, and found that when running it as user the only one I could authenticate was the user the process ran with. Then I asked about that on the pam mailinglist, and somebody told me that root rights are necessary. PAM is not very well documented - if you can point me into the right direction how to make it work for a normal user, and maybe even have some meta-data attached to a user (e.g. grouplist), your very welcome! The following script is authenticating every user if run as root. The service "claros" is defined like this: auth required pam_unix.so account required pam_access.so Here comes the script. import PAM def authenticate(user, password): class AuthConv: def __init__(_, password): _.password = password def __call__(_, auth, query_list, userData): print "AuthConv called, pwd: %s" % _.password resp = [] for query, qt in query_list: if qt == PAM.PAM_PROMPT_ECHO_ON: resp.append((_.password, 0)) elif qt == PAM.PAM_PROMPT_ECHO_OFF: resp.append((_.password, 0)) elif qt == PAM.PAM_PROMPT_ERROR_MSG or type == PAM.PAM_PROMPT_TEXT_INFO: print query resp.append(('', 0)) else: return None return resp auth = PAM.pam() auth.start("claros") auth.set_item(PAM.PAM_USER, user) auth.set_item(PAM.PAM_CONV, AuthConv(password)) try: auth.authenticate() auth.acct_mgmt() print "Authentication successful" except PAM.error, resp: print 'Go away, %s! (%s)' % (user, resp) raise authenticate("user", "pwd") -- Regards, Diez B. Roggisch From ptmcg at austin.rr._bogus_.com Wed Aug 25 10:00:13 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Wed, 25 Aug 2004 14:00:13 GMT Subject: Just a quick one References: Message-ID: "M. Clift" wrote in message news:cgi5gl$5de$1 at news5.svr.pol.co.uk... > Hi Benjamin, > > Thanks, that was quick! > > How would I print just 'Bob' if the result was > '[('Bob',One'),('Mary','Spam')] ? As print Name_List[0] obviously gives > ('Bob','One') > > M > > Name_List[0][0] From in.aqua.scribis at nl.invalid Sun Aug 29 11:18:32 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Sun, 29 Aug 2004 17:18:32 +0200 Subject: Announcing PyCs, a new Python-like language on .Net In-Reply-To: <1093793065.258215@news.commspeed.net> References: <1093788608.645541@news.commspeed.net> <1093793065.258215@news.commspeed.net> Message-ID: Tom B. schreef: > > Is there a real danger that MS will make its own version of > > Python, pushing it into the market, and we end up with a > > dominant version that only works with MS software? > > > > -- > > Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) > > info: http://www.let.rug.nl/~kleiweg/ls.html > > > > The Halloween Documents: http://www.opensource.org/halloween/ > > > What M*soft should do is build libraries like the Speech Development Kit and > Direct X into open source modules for Python. This way they are not trying > to destroy open source but to join with it. That is not in the interest of MS. Have you read the Halloween Documents? -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From greg at invalid.invalid Thu Aug 26 00:27:18 2004 From: greg at invalid.invalid (Greg Krohn) Date: Thu, 26 Aug 2004 04:27:18 GMT Subject: Just a quick one In-Reply-To: References: Message-ID: M. Clift wrote: > Hi All, > > At the risk of looking stupid would someone mind showing me how this is done > in this case. I can't remove the brackets from (('Bob', 'Mary'), ('Spam', > 'chips')) to give(('Bob', 'Mary', 'Spam', 'chips')) . From what Phil and Sm > said I thought it would be easy. I've tried using list( ). I've had a go at > referencing the individual elements... > > Anyone? > > Thanks > M > > I don't think you are truly understanding what the parentheses and brackets are. How about an analogy? You have $5.34 in your pocket. Now, you don't actually have a dollar sign in your pocket. Or a decimal point. Those symbols are just used when you want to display the the amount of money you have. The brackets are only used to help display what is in the list. They aren't a part of the list that can be removed. So, your question is similar to asking "I have $5.35 in my pocket. How do I remove the dollar sign?" Does that make sense? So, are you just trying to change how your list is displayed on the screen (or printer or whatever) or do you actually want to change your list? I'll assume you want to change your list. I'll use tuples instead of lists, though, since you want to use them as dictionary keys. So we have this: >>> a = ('Bob', 'Mary') >>> b = ('Spam', 'chips') >>> c = (a, b) >>> c (('Bob', 'Mary'), ('Spam', 'chips')) First we need to create a list, not a tuple, so we can modify it. extend() is a list method that slaps a sequence on to the end of the list. >>> c = [] >>> c.extend(a) >>> c ['Bob', 'Mary'] >>> c.extend(b) >>> c ['Bob', 'Mary', 'Spam', 'chips'] What we're doing here is called flattening a list. The ASPN Cookbook[1] has a more general method for flattening. It uses a flatten() method. Use it like this: def flatten(*args): for arg in args: if type(arg) in (type(()),type([])): for elem in arg: for f in flatten(elem): yield f else: yield arg c = (('Bob', 'Mary'), ('Spam', 'chips')) c = flatten(c) print list(c) This prints out: ['Bob', 'Mary', 'Spam', 'chips'] Hope this helps. Greg [1]http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/121294 From psXdaXsilva at esotericaX.ptX Wed Aug 25 19:36:46 2004 From: psXdaXsilva at esotericaX.ptX (Paulo da Silva) Date: Thu, 26 Aug 2004 00:36:46 +0100 Subject: "Socket" files? In-Reply-To: <2p0ss7Ffh1bdU2@uni-berlin.de> References: <1093035812.83612@jubilee.esoterica.pt> <4126824a$0$566$e4fe514c@news.xs4all.nl> <1093050493.502706@jubilee.esoterica.pt> <1093302968.204485@iceman.esoterica.pt> <2p0ss7Ffh1bdU2@uni-berlin.de> Message-ID: <1093477296.616399@mystique.esoterica.pt> Oliver Fromme wrote: > Paulo da Silva wrote: ... > Why exactly do you want to create one and keep it on disk > without doing anything with it? That doesn't seem make any > sense at all. > Well, I never programmed anything using fifo or sockets. What I need to do as part of a work is to get information about some disk or a dir contents and then replicate it later (something like a backup). I don't really know if those "files" of type socket have any other role behind sockets communication. So I thought of replicate them also. I have seen that tar doesn't seem to "save" them, but cp does. BTW, those "files" are kept after issuing close(). Thank you for your comments on this. From miki.tebeka at zoran.com Mon Aug 23 04:55:02 2004 From: miki.tebeka at zoran.com (Miki Tebeka) Date: Mon, 23 Aug 2004 10:55:02 +0200 Subject: Parsing C header files with python In-Reply-To: <873c2gzftf.fsf@emit.demon.co.uk> References: <873c2gzftf.fsf@emit.demon.co.uk> Message-ID: <20040823085501.GG1948@zoran.com> Hello Ian, > I've got a header file which lists a whole load of C functions of the form > > int func1(float *arr, int len, double arg1); > int func2(float **arr, float *arr2, int len, double arg1, double arg2); > > It's a numerical library so all functions return an int and accept varying > combinations of float pointers, ints and doubles. > > What's the easiest way breaking down this header file into a list of > functions and their argument using python? Is there something that will > parse this (Perhaps a protoize.py) ? I don't want (or understand!) a full C > parser, just this simple case. There is an ANSI-C parser in ply (http://systems.cs.uchicago.edu/ply/) which you can use. Bye. -- ------------------------------------------------------------------------ Miki Tebeka http://tebeka.spymac.net The only difference between children and adults is the price of the toys From genericax at hotmail.com Thu Aug 26 08:33:32 2004 From: genericax at hotmail.com (Sara) Date: 26 Aug 2004 05:33:32 -0700 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: <776e0325.0408260433.449660c8@posting.google.com> xah at xahlee.org (Xah Lee) wrote in message news:<7fe97cc4.0408251356.34f2102a at posting.google.com>... > Larry Wall and Cults > (Lazyness, Impatience and Hubris) > 200012 > > Dear readers, > > Did you know that throughout history there's this thing called cult? > It is a very interesting phenomenon. I don't have time to expound and > teach, but will try to brief you. > > Hey this ain't no CULT! Our creedo is simply: "Larry said it, I believe it, THAT settles it!" If you don't believe it just look at the reaction if any questions any element of Perl design! From ptmcg at austin.rr._bogus_.com Tue Aug 31 10:33:36 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Tue, 31 Aug 2004 14:33:36 GMT Subject: Splitting a list References: Message-ID: <4%%Yc.71719$xi6.36082@fe2.texas.rr.com> "Ian Sparks" wrote in message news:mailman.2673.1093960462.5135.python-list at python.org... string.split() is very useful, but what if I want to split a list of integers on some element value? e.g. : >> l = [1,2,3,-1,4,5,-1,8,9] >> l.split(-1) >> [[1,2,3],[4,5],[8,9]] Here's my hideous first pass : >> [[int(z) for z in x.split(',') if z] for x in ','.join([str(a) for a in l]).split('-1')] >> [[1, 2, 3], [4, 5], [8, 9]] When I see code like that I just know I've missed something obvious.... Maybe not the prettiest, but here's a solution using a generator (at least you're avoiding a bunch of conversions to/from string). -- Paul l = [1,2,3,-1,4,5,-1,8,9] def getSublists(lst, delim): loc = 0 while loc < len(lst): try: nextloc = lst.index(delim,loc) except ValueError: nextloc = len(lst) yield lst[loc:nextloc] loc = nextloc+1 print [ sub for sub in getSublists(l,-1) ] From h.b.furuseth at usit.uio.no Sun Aug 22 18:17:32 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 23 Aug 2004 00:17:32 +0200 Subject: Proposal: require 7-bit source str's References: <412907C8.1090104@v.loewis.de> <412912C8.8080707@v.loewis.de> Message-ID: Martin v. L?wis wrote: >Hallvard B Furuseth wrote: >>>I agree with many things you said, but this example is bogus. If I >>>(as a German) use ns_4551-1, sorting is simple - and incorrect, because, >>>as you say, ? sorts with o in my language - yet the simple sorting of >>>ns_4551-1 doesn't. So sorting is *not* simple with ns_4551-1. > > Ah, I missed the point that there is no ? in ns_4551-1. If so, then the > best way to represent the characters is to replace ? with "oe" and ? > with "ae"; replacing them merely with "o" and "a" would be considered > inadequat. Duh. Of course. We usually did that too when we had to write Norwegian in ASCII. It bites sometimes, though - like when it hits the common '1 character = 1 byte' assumption which someone -- John Roth? mentioned. Maybe that's why we are getting to ?->o in e-mail addresses and such things nowadays, to keep things simple. In a way, it is rather nice to notice that I'm forgetthing that stuff. Maybe someday I won't even be able to read texts with {|} for ??? without slowing down:-) >> And if I want to get both right, I need a sort_name field which is >> distinct from the display_name field. There you would be lowis, while >> the Swede T?rnquist would be t?rnquist. Or maybe lowis\tl?wis or >> something; a kind of private implementation of strxfrm(). > > But you can have a strxfrm for Unicode as well! There is nothing > inherent in Unicode that prevents using the same approach. Not after you have discarded the information which says whether to sort ? as ? or o. > Of course, the question always is what result you *want*: If you > have text that contains simultaneously Latin and Greek characters, > how would you like to collate it? Neither the German or Greek > collation rules are likely to help, as they don't consider the issue > of additional alphabets. True enough. But when you mix entirely different scripts, you have worse problems anyway; you'll often need to transliterate your name to the local script - or to something close to English, I guess. A written name in a script the locals can't read isn't particularly useful. > If possible, you should assign a language tag to each entry, and then > sort first by language, then according to the language's collation > rules. That sounds very wrong for lists that are sorted for humans to search, unless I misunderstand you. That would place all Swedes after all Norwegians in the phone book, for example. And if you aren't sure of the nationality of someone, you'd have to look through all foreign languages that are present. -- Hallvard From jepler at unpythonic.net Sat Aug 21 09:12:50 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Sat, 21 Aug 2004 08:12:50 -0500 Subject: popen child termination In-Reply-To: <412723B7.1080002@bvx.cz> References: <412723B7.1080002@bvx.cz> Message-ID: <20040821131250.GC1458@unpythonic.net> Why are you using popen instead of system? Is it to discard the output from the program? If so, your best choice would be to use shell redirection in system(). system() already waits for the child to exit. If you really want to use popen, the class-based interface (Popen3, Popen4) will give you an object with a pid attribute and wait() and poll() methods to check for exiting. BUT your real problem is that os.remove doesn't expand paths. Use os.path.expanduser: os.path.exists("~") -> 0 os.path.exists(os.path.expanduser("~")) -> 1 Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From marduk at python.net Thu Aug 19 13:30:25 2004 From: marduk at python.net (marduk) Date: Thu, 19 Aug 2004 12:30:25 -0500 Subject: PEP 318: Can't we all just get along? References: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: On Thu, 19 Aug 2004 10:28:07 -0400, Roy Smith wrote: > Oh my god, I just realized (Ob decorator comment here) that if we start > having people write private decorators, we'll have things like: > > @__decorator I wish to have a private decorator. My apartment looks boring. -m From miki.tebeka at zoran.com Mon Aug 9 09:51:57 2004 From: miki.tebeka at zoran.com (Miki Tebeka) Date: Mon, 9 Aug 2004 15:51:57 +0200 Subject: help In-Reply-To: <20040809043348.94101.qmail@web8203.mail.in.yahoo.com> References: <20040809043348.94101.qmail@web8203.mail.in.yahoo.com> Message-ID: <20040809135156.GW2636@zoran.com> Hello Neha, > hello sir, > i want to know what r advantages of > using perl over python and tcl for network programming > at tcp/ip layer. http://www.catb.org/~esr/faqs/smart-questions.html Bye. -- ------------------------------------------------------------------------ Miki Tebeka http://tebeka.spymac.net The only difference between children and adults is the price of the toys From ville at spammers.com Thu Aug 26 15:50:02 2004 From: ville at spammers.com (Ville Vainio) Date: 26 Aug 2004 22:50:02 +0300 Subject: Message queues [Re: Best processor (i386) for Python performance?] References: <412dfb17$0$65599$a1866201@newsreader.visi.com> Message-ID: >>>>> "David" == David Bolen writes: David> I do think it can be tricky to determine just what case an David> application falls into (and many oscillate between I/O and David> CPU bound modes), and indeed a purely CPU bound Python David> application (if in Python code and not a well-behaving David> extension module) isn't going to be helped at all. The sensible thing to do then is to use multiple processes, not just multiple threads. Many Python apps use Queue.Queue anyway, and such an approach is often easy to convert over to use processes instead of threads. In fact, it might be fun to have a trivial message queue implementation in the standard library: # server code frow mq import * q,results = MQueue(),MQueue() # file has just a handle, like # mq:123.12.12.54:67 q.publish(open("~/jobs","w")) results.publish(open("~/result","w")) spawn_server_if_needed() while 1: job = q.get() res = my_handle_job( job ) results.put(res) # client code ... req, results = MQueue(open("~/job")), MQueue(open("~/results")) req.put( ("easyjob", 34, 2.44) ) req.put( ("easyjob", 213, 2.44) ) ... Obviously these trivial mqueues could still be wrapped with additional rendezvous functionality: job = mq.Job(("hello",2)) rv = mq.Rendezvous(q,resultqueue) rv.put(job) res = job.result() # blocks until result is ready Though this might be more in the territory of external libs/frameworks... but hey, we've already got xml-rpc and web server functionality ;-). Inter-language systems should obviously something like Corba for this. -- Ville Vainio http://tinyurl.com/2prnb From davidf at sjsoft.com Fri Aug 20 08:44:16 2004 From: davidf at sjsoft.com (David Fraser) Date: Fri, 20 Aug 2004 14:44:16 +0200 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: Michael Sparks wrote: > On Fri, 20 Aug 2004, Paul McGuire wrote: > > >>"Delaney, Timothy C (Timothy)" wrote in message >>news:mailman.1989.1092960560.5135.python-list at python.org... >> >>>I think a web page for tabulating votes would be better (see the >>>response to the previous vote on 3 syntaxes). >> >>I couldn't agree more, Tim, but time is short. > > > Time might be short, but don't forget timezone issues. Usenet takes time > to propogate postings, etc. > > >>BTW, where are all the votes for option "A"? Where are all the people who >>hated it but now like it? > > > I think one of the problems is the vote might be viewed as "which > alternative to A1 do you like" rather than "which alternative, even > including A1, do you like" - personally I'd be very interested to see > the level of support for A1, _especially_ if it overwhelms support for > any other syntax... > > Tallying the results of 22 votes now: > > > for i in `cat votes.txt |cut -d, -f1`; do echo $i; done|sort|uniq -c > 4 A1 > 14 C1 > 2 C2 > 1 C4 > 2 D1 > 1 D2 > 2 E1 > 2 E2 > 1 E4 > 5 F > 1 H > 1 I > 23 J2 > 3 K > 4 L > > People who changed their votes from "J2 J2 A1" to "J2 J2 J2" I've > included as "J2 J2 A1" based on the question above. > > Votes included minus email addresses below... > > Regards, I'm keeping a running tally at http://davidf.sjsoft.com/decoratortally.htm Code used at http://davidf.sjsoft.com/files/countvotes.py Now I'm tempted to make it include an nntp client to make it fully automatic ... interesting that I actually haven't used decorators to write this at all! :-) David From jacob at cd.chalmers.se Tue Aug 10 14:06:56 2004 From: jacob at cd.chalmers.se (Jacob Hallen) Date: 10 Aug 2004 18:06:56 GMT Subject: Queue qsize = unreliable? References: Message-ID: In article , Peter Hansen wrote: >James R. Saker Jr. wrote: > >> I see per pydoc that Queue.Queue()'s .qsize is allegedly unreliable: >> >> | qsize(self) >> | Return the approximate size of the queue (not reliable!). >> >> Any thoughts on why this is unreliable (and more curiously, why it would >> be put in there as an unreliable function?) Rather than roll my own >> threaded fifo class, it would seem prudent to use Python's built-in >> Queue but the warning signs on a rather necessary function seem curious. > >(Why do you think this function is necessary? It's probably >rare to really need it, except perhaps during debugging... ) > >Anyway, the reason it's called "unreliable", though the term >"inaccurate" might be more correct, is because while you are >getting the size of the queue, it might be updated such that >the new size is one or more fewer or larger than the value >that is about to be returned to you. In effect, the value is >guaranteed accurate only for the precise instant in time, now >passed, that it was determined, but by the time the calling >routine actually sees the value the size could be anything. > >Note also the latest docs at docs.python.org, which state the >case a little more clearly. > >"""Return the approximate size of the queue. Because of >multithreading semantics, this number is not reliable. """ And an inaccurate number is still quite usable. If you are the only one reading from a queue, you know that the number is at least as large as indicated. If you read from multiple queues, you can use the indicated number to pick which queue to handle first. This allows you to do pollling and fair scheduling and some other neat tricks. The same sort of tricks works for writers as well. Jacob Hall?n -- From cedmunds at spamless.rochester.rr.com Sat Aug 28 23:09:03 2004 From: cedmunds at spamless.rochester.rr.com (Cy Edmunds) Date: Sun, 29 Aug 2004 03:09:03 GMT Subject: simple compiled languages? References: <7xzn4fu188.fsf_-_@ruckus.brouhaha.com> <_1bYc.855$2s.374@twister.nyroc.rr.com> <7xbrguvfn6.fsf@ruckus.brouhaha.com> Message-ID: "Paul Rubin" wrote in message news:7xbrguvfn6.fsf at ruckus.brouhaha.com... > "Cy Edmunds" writes: > > Turbo Pascal. I used to think it was great in 1983. :) > > Yeah, they never released the source code though. I should have added > that as a qualification. > > BDS C was released, by the way, but it's written entirely in 8080 > assembler. Ah, yes. "Brain Dead Software". Great name. lol -- Cy http://home.rochester.rr.com/cyhome/ From aleaxit at yahoo.com Thu Aug 26 09:30:37 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 15:30:37 +0200 Subject: Proposal for removing self References: Message-ID: <1gj4sup.hrowbz1bzo06mN%aleaxit@yahoo.com> Ravi Teja Bhupatiraju wrote: ... > > class FooBar: > __public__ = [Name, Age] > def setName(name): > Name = name > Go ahead: learn about metaclasses and bytecode hacking and write your custom metaclass to perform this. Except for the little detail that you'll never get away with not quoting 'Name' and 'Age' in the __public__ assignment, the rest is reasonably easy to perform. Publish your metaclass and start campaigning for it. As long as you're just yakking about it ain't gonna happen -- become a metaclass and bytecode expert and you can implement this in Python, or convince somebody who is such an expert, for which the implementation should be the job of a couple days tops. > While I am complaining, a few other peeves ... > > Another thing is I dislike is having to use __ for *every* private > variable. For *me* __private__ at the top of the class definition code > would be more elegant. __readonly__ would be another nicety. That's an even easier job for a custom metaclass with very modest amount of byecode hacking. I suggest you start with this one, really truly VERY easy. In fact you could probably do it without any actual hacking on the bytecode itself, just rewriting a few tables of strings in the code objects of the functions that are the methods of the class. One impossible task (THAT would require hacking the Python parser and changing things very deeply) as I already mentioned would be the form you want for the assignment to __public__ (or similarly to __private__etc). Those names are undefined (or worse defined globally) and to teach Python (and human readers!) that for that one speclal case of assignment to __public__ (or __private__), THAT one case only, COMPLETELY different rules apply than ANYWHERE else in Python, well, it's just as difficult as it is absurd. I suggest you tackle the 'look ma no quotes!' task last, after everything else is working, because that one detail is going to take far longer than everything else put together, even if you're learning about metaclasses and bytecodes from scratch. > Introducing the above attributes into the language would not likely > break any existing Python code. If this peculiar behavior is limited to classes whose metaclass is your custom RaviSpecial, "not likely" becomes "absolutely impossible", a great enhancement. One more reason to implement this in a metaclass. > Just my 2c. Well make it three cents and do an implementation, if you really care. Otherwise, it's just words... Alex From fumanchu at amor.org Thu Aug 26 01:56:51 2004 From: fumanchu at amor.org (Robert Brewer) Date: Wed, 25 Aug 2004 22:56:51 -0700 Subject: A question?? Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E7E@exchange.hqamor.amorhq.net> Ishwar Rattan wrote: > I thought that Python has no concept of reference/pointer > (probably incorrect assumption). I saw the following piece of code: > > ... > def run(program, *args): > pid = os.fork() > if not pid: > os.execvp(program, (program,)+args) > ... > > and call to run as > > run("pyhton", "a.py") > > What is the interpretation of *args (in def run(..)? > Looks like a reference to me, so, how does one decide when to use > a reference or not? http://docs.python.org/ref/function.html Basically, *args collects any additional positional arguments passed to the function. So you can call run("python", "a.py") ...and... run("top", "d 5", "s") ...with the same function signature. In the second case, args would equal the tuple ("d 5", "s") within the run() function. Robert Brewer MIS Amor Ministries fumanchu at amor.org From skullw at sina.com.cn Sun Aug 22 19:15:00 2004 From: skullw at sina.com.cn (skull) Date: Sun, 22 Aug 2004 19:15:00 -0400 Subject: newsgroup for embeded/extend python ? Message-ID: Hi, everyone I wanna know is there any newsgoup(or forums through www) specially for embeded/extend python? thanks in advance -skull From len-1 at telus.net Mon Aug 16 17:11:01 2004 From: len-1 at telus.net (Lenard Lindstrom) Date: Mon, 16 Aug 2004 21:11:01 GMT Subject: Generators versus Coroutines References: <7x7js1i887.fsf@ruckus.brouhaha.com> <972ec5bd.0408152037.c50bcee@posting.google.com> Message-ID: firemoth at gmail.com (Timothy Fitz) writes: > Lenard Lindstrom wrote in message news:... > > Nick Patavalis writes: > > > > > On 2004-08-14, Paul Rubin <> wrote: > > > > > > > > You can't yield across multiple levels of function calls. That's why > > > > they're called "simple generators" instead of just "generators". > > > > > > > > > > For me it would be *tremendously* usefull if one could yield across > > > multiple levels of function calls. If this was supported, then most > > > uses of O/S treads could be replaced by generators. > > > > > > Does anyone know if such a feature is planned? > > > > > Having followed the development of Prothon it is my understanding that > > such a thing is not possible in CPython for two reasons. [Snip] > > I disagree, it seems to me I could make a pure python based > implementation with some funky state handling classes and exceptions. > Granted, it wouldn't look nice (all your 'locals' would be in an > object, and you'd have to call like tyield()) I should have been clearer. It is not possible with the current generator function declaration syntax. A new keyword or something would have to be added to make it work. If a keyword, then the new syntax would not be backwards compatible with the current. As for doing it in Python, coroutines can be implemented using threads. So yes it is possible. But it is not necessary efficient. Lenard Lindstrom From duncan.booth at invalid.invalid Tue Aug 10 09:18:05 2004 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 10 Aug 2004 13:18:05 GMT Subject: Best pattern/idiom References: <4117c3d8$1@buckaroo.cs.rit.edu> <4edc17eb.0408092039.10958e11@posting.google.com> Message-ID: Heiko Wundram wrote in news:mailman.1442.1092142146.5135.python-list at python.org: > Problem being: > >>>> list(chop([1,2,3,4,5,6],4)) > [(1, 2, 3, 4)] > > If you actually want to get back everything from iterator, better do > something like: > > def ichop(it,n,rtype=list): > it = iter(it) > empty = False > while not empty: > retv = [] > while not empty and len(retv) < n: > try: > retv.append(it.next()) > except StopIteration: > empty = True > if retv: > yield rtype(retv) It depends what you actually want to get if the list isn't a multiple of n. The uneven length tuple at the end seems a bit bad, you are probably better off with something like this: >>> def chop(it, n): tup = (itertools.chain(iter(it), (None,)*(n-1)),)*n return itertools.izip(*tup) >>> list(chop([1,2,3,4,5,6],4)) [(1, 2, 3, 4), (5, 6, None, None)] although this still loses your data if n < 1. From jpeekii at yahoo.com Mon Aug 9 10:35:56 2004 From: jpeekii at yahoo.com (Oliver Peek) Date: Mon, 9 Aug 2004 07:35:56 -0700 (PDT) Subject: berkeley db delete problem? Message-ID: <20040809143556.24128.qmail@web50707.mail.yahoo.com> Hi all, Probably my fault, I'm opening a Berkeley DB file, iterating through and deleting keys, well making an attempt. I get this error when I try to delete. ---error Traceback (most recent call last): File "./db.py", line 41, in ? db.delete() AttributeError: delete ---end error Below is a code snippet: ---code #!/usr/bin/python import bsddb db = bsddb.btopen('./test.db', 'r') rec = db.first() while rec: key, val = rec db.delete() rec = db.next() db.close() ---end code I have full code that opens and goes through and prints the key and value and opens another db file and inserts the key/data into that new db file, but I need to delete the data out of the master db file once it's been updated in the smaller ones. I've also tried db.delete(key) with no luck, db.del(), db.del(key), db[key]='', and lots of other silly attempts, but nothing works. Thanks, Oliver __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From tjreedy at udel.edu Sun Aug 1 20:28:00 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 1 Aug 2004 20:28:00 -0400 Subject: Pygame - Only ONE Font found!? References: Message-ID: "Askari" wrote in message news:Xns9538A6D09A14CaskariaddressNonVali at 207.35.177.135... > "Terry Reedy" wrote in > news:mailman.994.1091237691.5135.python-list at python.org: > > > If you don't get an answer here (pygame is an application of Python, but > > not Python itself), try the pygame mail list or gmane.comp.python.pygame > > via gmane.org. > > "Pygame is a set of Python modules designed for writing games." I found that line. > And I'm redirect to group "comp.lang.python" if I need help. I see that 'Python' is linked to python.org but see no reference to c.l.p on the pygame page. If it is there, it would mean help with the language rather than pygame itself. > For "gmane.org"... too long for access help... I have no idea what you mean here. But anyway, if you cannot bother yourself to ask on the right forum, why expect anyone else to bother to answer? Terry J. Reedy From jbenson at lowell.edu Thu Aug 26 21:16:19 2004 From: jbenson at lowell.edu (Jim Benson) Date: Thu, 26 Aug 2004 18:16:19 -0700 (MST) Subject: A newbie in need.... In-Reply-To: <9c3edc58.0408261609.6640e400@posting.google.com> Message-ID: On 26 Aug 2004, Chris Patton wrote: > Hey everybody. I'm trying to make a program that requires a 2D field > to run. Besides "curses" or "ncurses", is there a python module that > will create a graph? > > --Thanks for the help! > Here is the matplotlib link i mentioned in my previous email as well as a snippet of its introductory statement at the link: http://matplotlib.sourceforge.net/ matplotlib is a python 2D plotting library which produces publication quality figures in a variety of hardcopy formats (PNG, JPG, PS, SVG) and interactive GUI environments (WX, GTK, Tkinter) across platforms. Good Luck, Jim From jeff at ccvcorp.com Thu Aug 26 16:24:39 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Thu, 26 Aug 2004 13:24:39 -0700 Subject: vars() and dir() In-Reply-To: References: Message-ID: <10ishn6dpo53ja4@corp.supernews.com> Claire wrote: >hi, >i use vars() or dir() to get variables. I use them in a def block, so >i get variables of that block. How can i get variables from the >namespace __main__ ? >I use python in interactive mode and want to have a function to get a >dictionnary for python types (int, ...) and another for my types (my >classes). this function will be in my pythonstartup file. > >If i use python in interactive mode, is there a main module defined ? >i don't know how to use namespace __main__ to get information on this >"global namespace" like i can do with math or another module > > There is also a globals() function which operates in a manner parallel to vars(). Note that vars(), without an argument, is equivalent to locals(). Also beware that, while these functions will return a dictionary containing the current global/local variables, modifying that dictionary may not modify actual variables. (In general, you're best off using them as read-only.) Jeff Shannon Technician/Programmer Credit International From tim.peters at gmail.com Tue Aug 17 23:45:23 2004 From: tim.peters at gmail.com (Tim Peters) Date: Tue, 17 Aug 2004 23:45:23 -0400 Subject: Problem with floating point precision In-Reply-To: <10i4c1lrvd3rm9b@news.supernews.com> References: <10i4c1lrvd3rm9b@news.supernews.com> Message-ID: <1f7befae040817204564f3c222@mail.gmail.com> [John Roth] > ... > There's a floating decimal package in 2.4 that is intended > to eventually (in 2.5 maybe?) be the base of a currency > package. However, that doesn't help today. It will help in 2.4, though. Fixed-point decimal is a subset of what 2.4's decimal arithmetic can do, and it's dead easy to do exact "dollars and cents" calculations using it. I'm not sure what a currency package would add on top of it -- maybe add currency markers to string output, perhaps offer a simplified rounding discipline for multiplication, not really sure. The "hard parts" will already be in 2.4. From chrisdewinN0SPAM at yahoo.com.au Wed Aug 25 13:12:17 2004 From: chrisdewinN0SPAM at yahoo.com.au (Dfenestr8) Date: Thu, 26 Aug 2004 02:12:17 +0900 Subject: Capturing exceptions? Message-ID: Hi. What's the easiest way to capture the traceback from an exception, and write it to a file? Ideally, I'd like to be able to do something like: >try: > main() >except: > write the traceback to a file From mj-usunto at tkb.pl Wed Aug 18 10:01:18 2004 From: mj-usunto at tkb.pl (Marcin Jurczuk) Date: Wed, 18 Aug 2004 14:01:18 +0000 (UTC) Subject: age of Python programmers References: Message-ID: On 2004-08-18, Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... > > 26 ..today ...a hell ... -- Marcin Jurczuk, NIC-HDL: MJ1679-RIPE From ville at spammers.com Wed Aug 18 13:33:13 2004 From: ville at spammers.com (Ville Vainio) Date: 18 Aug 2004 20:33:13 +0300 Subject: PEP 318: Can't we all just get along? References: <20040817181725194-0400@braeburn.themorgue.org> Message-ID: >>>>> "Kevin" == Kevin Smith writes: Kevin> Bear with me, but I'd like to propose one more syntax that Kevin> is simple, easy for newbies to understand, and nowhere near Kevin> as powerful as the current PEP's syntax. However, it Kevin> doesn't add incoherent, arbitrary syntax either. Kevin> def classmethod foo(x, y, z): Kevin> pass Kevin> Once again, no expressions. I know that this isn't going Kevin> to solve everyone's type-checking, metadata, and function Kevin> attribute problems, but let's face it, using this PEP for Kevin> all of those things just creates ugly syntax. There must Kevin> be more Pythonic ways to do those things in their own PEPs. Python is not anymore in the blissful stage of being able to incorporate zillions of features that could be provided by a single syntactic addition, and relatively comfortably as well. Long decorators w/ arguments is where the decorator syntax is going to pay off. I don't even use static/classmethods, but I can imagine several frameworks can use parametrized decorators to their advantage. -- Ville Vainio http://tinyurl.com/2prnb From squirrel at WPI.EDU Sun Aug 1 21:16:34 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Sun, 1 Aug 2004 21:16:34 -0400 Subject: transforming a list into a string In-Reply-To: References: Message-ID: On Sun, 1 Aug 2004, Tim Peters wrote: > The difference is that list() creates a concrete list object from its > argument, but there's no such thing as "a concrete iter object". You've got me there. > Iteration is a protocol, not a type. iter(obj) invokes > obj.__iter__(), Only if obj.__iter__() is defined; otherwise it makes something up using __getitem__ as appropriate. > and I don't know of any existing __iter__ implementation that returns an > object that supports slicing. True. Built-in classes (such as list & tupleiterator) would have to be extended with this function (trivial if they all subclass from a common base class). As to user classes, I'm proposing this on the assumption that a programmer would implement their own __getitem__ (I've been saying __getslice__ previously, __getitem__ is what I should be saying) if the functionality is so desired, which can be as trivial as setting __getitem__=islice, provided islice is extended to accept slice objects. Though, this would break __getitem__ in the case of getting a single item (I can see where this is heading)... > The only thing required of __iter__ is that it return an object that > supports the iteration protocol (meaning an object that supports next() > and __iter__() methods). So again, adding the ability to slice too > would mean requiring more of __iter__ methods -- or changing the > implementation of iter() to ignore __iter__ methods and make something > up itself. It's A Visible Change no matter how you cut it. You've made your point. I guess this will just have to go on the "it would be neat if it worked this way, but it just doesn't" list for now ;) From johnfkeeling at yahoo.com Mon Aug 2 15:52:23 2004 From: johnfkeeling at yahoo.com (John Keeling) Date: 2 Aug 2004 12:52:23 -0700 Subject: Timing Difference: insert vs. append & reverse References: <35b736b9.0408020330.53b24ed3@posting.google.com> Message-ID: <35b736b9.0408021152.16e16456@posting.google.com> Duncan, > A list is implemented by an array of pointers to the objects it contains. That explains it. > If you expected insert to be faster, perhaps you thought that Python used a > linked-list implementation. It doesn't do this, Yes, that is how I was thinking. It is interesting to see how functions may perform very differently from how we may initially expect. I've also noted an approximate two time difference between "del list[index] and list.pop(index)". I know that they do different things (the return value from pop), however in many places my code uses pop and ignores the return value when it would be faster to use del. I am making changes based on these observations now. Thanks, John From dietz at dls.net Wed Aug 25 20:51:57 2004 From: dietz at dls.net (Paul F. Dietz) Date: Wed, 25 Aug 2004 19:51:57 -0500 Subject: Larry Wall & Cults In-Reply-To: References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: <15WdnU2mIJV1rrDcRVn-gQ@dls.net> Rich Teer wrote: > I think you're getting confused with the Blue ?yster Cult. > Don't Fear the Reaper - great song. A great allegory about garbage collection, wasn't it? Paul From sbabbitt at commspeed.net Fri Aug 27 16:53:05 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Fri, 27 Aug 2004 13:53:05 -0700 Subject: tarfile's tar.extractfile() file-like object incompatible with pickle.load()? References: <3e6d6c21.0408261043.264c3a2d@posting.google.com> <1093572564.733113@news.commspeed.net> <3e6d6c21.0408271000.6007a361@posting.google.com> Message-ID: <1093640502.574436@news.commspeed.net> "Matt Doucleff" wrote in message news:3e6d6c21.0408271000.6007a361 at posting.google.com... > "Tom B." wrote in message news:<1093572564.733113 at news.commspeed.net>... > > "Matt Doucleff" wrote in message > > news:3e6d6c21.0408261043.264c3a2d at posting.google.com... > > > Hi everyone! I must be doing something wrong here :) I have a > > > tarball that contains a single file whose contents are a pickled > > > object. I would like to unpickle the object directly from the tarball > > > using the file-like object provided by extractfile(). Attempts to do > > > this result in EOFError. However if I first extract to a temporary > > > file, then unpickle from there, it works. The below code reproduces > > > the problem (on my machine at least). I'm running Python 2.3.4, > > > manually installed on Debian Woody (original python removed). Thanks! > > > > > > This sample code creates (and then removes) files in the tmp directory > > > and in the current working directory. > > > > > > # demonstrates extractfile/unpickle failure (bug?) > > > > > > # pickle a dict to a temp file > > > # create tar file, add temp file to it, close tar file > > > # open tar file for reading > > > # obtain file-like object for pickled file using extractfile() > > > # attempt to unpickle dict from file-like object > > > # fails with EOFError exception > > > > > > import tarfile > > > import pickle > > > import tempfile > > > import os Now that I take a closer look at your program it should read, > > > if __name__ == '__main__': > > > try: > > > hashtopickle = { 'a' : 1, 'b' : 2 } > > > > > > # pickle to temp file > > > (fd, tmpfilename) = tempfile.mkstemp() > > > tmpfile = file(tmpfilename,'w+') > > > pickle.dump(hashtopickle, tmpfile) > > > tmpfile.close() > > > > > > # create tar; add temp file > > > tar = tarfile.open('tarpickle.tar', 'w') > > > tar.add(tmpfilename, 'pickledhash') > > > tar.close() > > > > > > # remove temp file > > > os.remove(tmpfilename) > > > > > > # open tarfile for reading, get filelike > > > tar = tarfile.open('tarpickle.tar', 'r') > > > > filelike = tar.extractfile('pickledhash') > > > > > > # fails > > > hashcopy = pickle.load(filelike) > > > > > > finally: > > > # cleanup > > > os.remove('tarpickle.tar') > > Your opening the tmpfilename in an odd way. Tom From ben at benlast.com Mon Aug 23 04:44:05 2004 From: ben at benlast.com (Ben Last) Date: Mon, 23 Aug 2004 09:44:05 +0100 Subject: My only complaint about Python In-Reply-To: <5339b60d.0408230017.655081d9@posting.google.com> Message-ID: > From: Paul Boddie > Sent: 23 August 2004 09:17 > To: python-list at python.org > Subject: Re: My only complaint about Python > "Ben Last" wrote in message > news:... > > What's needed (in my extremely humble opinion) is a way to > build what I need > > to, using a compiler suite that I can go and get without having > to spend any > > money. Philosophy is fine, but I dislike having an FSF agenda > pushed on me > > as much as I dislike a Redmond agenda. I just want to get on > with my job > > (or in this case, pursue my own interests). Paul; I appreciate your sentiments, and your ability to articulate them, but I think it would have more relevance and impact if you responded to what I said, rather than attribute to me statements that I have not actually made. If you feel like making the sort of reasoned, intellectual and considered response that I know you are capable of, being David's brother, then I'd pay attention. I especially dislike being tarred with the Microsoft-apologist brush, having suffered in the past in my business career from recommending Linux against those propounding proprietary systems. I'm entirely content for Richard Stallman to continue his campaign, and also entirely relaxed about Microsoft continuing theirs. What I do not like is being caught in the crossfire between the two camps and being obliged by others to fall in with one side or the other. I believe that "if you're not part of the solution, you're part of the problem" attitude (of which I do not accuse you, Paul), is not useful. I note that Guido, as quoted in http://slashdot.org/interviews/01/04/20/1455252.shtml states: "I don't personally care any more whether Python will ever be GPL-compatible -- I'm just trying to do the FSF a favor because they like to use Python. With all the grief they're giving me, I wonder why I should be bothered any more." He goes on to say "Anyway, I removed the acceptance ceremony from the 2.1 license, in the hope that this would satisfy the FSF. Unfortunately, the FSF's response to the 2.1 license (see above) seems to suggest that they have changed their position once again, and are now requesting other changes in the license. I'm very, very tired of this, so on to the next question!" I too have been though the GPL-argument-mill with company lawyer in the past. I'm tired of it. I have work to do. I stand or fall in what I do by the recommendations I make. Currently I'm running two very diverse and business-critial projects. Both are based heavily on Python, Linux and MySQL, because I consider those solutions to provide us with the best flexibility, fitness-for-purpose and value for money. Those are the criteria I used and by which I stand. If I recommended products because of any ideological agenda I'd deserve to lose business. I choose the tools which best fit the job. In these cases I've chosen the best tools of which I'm aware. One of them is Python; I expect it to continue to be amongst the best for many years. If you wish to attack my beliefs, fine, but do it on the basis of what I said, not what you find it convenient to assume that I said, or extensions of my statements to ridiculous extremes. A reductio ad absurdam argument is no argument. I had the greatest respect for your brother when I worked with him, and for some of the things you and/or he have contributed to the Python world. I'm disappointed that you seem inclined to attack me in this way. best regards, ben From skip at pobox.com Tue Aug 10 12:40:52 2004 From: skip at pobox.com (Skip Montanaro) Date: Tue, 10 Aug 2004 11:40:52 -0500 Subject: decorators vs GIL In-Reply-To: <0bidnfbR2_PZOIjcRVn-pA@giganews.com> References: <8YudnZoJ4NdLEYjcRVn-jA@speakeasy.net> <0bidnfbR2_PZOIjcRVn-pA@giganews.com> Message-ID: <16664.64148.998046.163093@montanaro.dyndns.org> Istvan> I think one of the latent messages of this thread was that Istvan> adding new "gratuitous" features to the core language is a bad Istvan> thing. Istvan> Just because someone sits down and codes it does not mean it Istvan> should be added to the language. Features are forever, you Istvan> cannot just can't eliminate them in the next version. ... Istvan> Python is said to come with the batteries included, then Istvan> that's where new features should go, to the battery level Istvan> not into the wiring. The notion of decorated functions has been in Python since (at least) staticmethod and classmethod were added as builtins. At that time it was presumed some syntax would be developed in the future to make their use less clunky (few people like that the "declaration" of a static method occurs at the end of its body) if it turned out they were useful. They have been found to be useful. We are now in the throes of the effort to define a suitable syntax for such a construct. Decorators are not theorhetical features with no proven use. They are used today and will likely be used more widely once it is easier to do so. Skip From fumanchu at amor.org Wed Aug 25 10:59:00 2004 From: fumanchu at amor.org (Robert Brewer) Date: Wed, 25 Aug 2004 07:59:00 -0700 Subject: J2 hard-line on "using" Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E6D@exchange.hqamor.amorhq.net> (hope you don't mind me cc'ing the list, but this is an important point for the community) Paul Moore wrote: > What should people do > if they don't really care between @ and J2, and would rather Guido > just decided and put an end to things? Excellent point, and something Guido hinted at earlier but I didn't catch. For those who don't prefer one over the other, I've added an explicit "Abstentions" list, which denies the "vocal minority" better than no signature would. Robert Brewer MIS Amor Ministries fumanchu at amor.org From jess.austin at gmail.com Tue Aug 24 16:53:58 2004 From: jess.austin at gmail.com (Jess Austin) Date: 24 Aug 2004 13:53:58 -0700 Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? References: Message-ID: Arien Malec wrote in message news:... > "Paul McGuire" wrote in > news:pUTVc.8393$Jn5.5720 at fe1.texas.rr.com: > > Please start giving some thought to what the 'decorate' keyword should > > be. If we can get/keep this selection to a manageable list, then we > > should have another multivote some time next week. > > "transform:" > > In general: > > Something that is either semantic neutral, or makes semantics explicit. A verb of neutral meaning, like "transform", seems more likely to cause difficulty with old code. I would expect there to be hundreds of Python functions in use right now with the name "transform", because that verb encompasses many things that functions often do. A function may be called at any level of indentation, and there would be no way for the parser to distinguish a function call from a decoration. This same objection can be voiced about any keyword, and is the reason why this option would definitely entail an "from __future__ import decorators", but many words would conflict less than "transform". Another objection that has been raised about my current favorite, "decorate", is that at 8 characters it's too long. 9 characters will also be considered too long by a number of people. The natural short version of "decorate" would be "dec" and there is sort of a natural parallelism with "def" there. I hesitate to nominate it because it _feels_ like a word that at least ten people on c.l.py will detest. Maybe "decor"? It isn't any longer than "class", and I think we can predict it will be typed less than 1/10 as often. But this reasoning could also excuse "decorate", so I'll stick with that. I'm also open to any transitive verb that can be designated to mean _exactly_ what "decorate" means now. later, Jess From dropthis_fanmail at micah-wedemeyer.net Wed Aug 25 13:56:41 2004 From: dropthis_fanmail at micah-wedemeyer.net (Micah) Date: Wed, 25 Aug 2004 13:56:41 -0400 Subject: using windows defaults for executing/examining files Message-ID: Is there an os module call to request that Windows handle a specific file using the default handler? For example, if I pass it a .txt file it opens notepad but if I pass a .wav file it opens Windows Media Player. Any ideas? -- ================================= Micah Z. Wedemeyer Research Scientist I, ELSYS Georgia Tech Research Institute Atlanta, GA 30332 678.428.1283 ================================= From rogerb at rogerbinns.com Tue Aug 10 00:13:47 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Mon, 9 Aug 2004 21:13:47 -0700 Subject: VB-like GUI designer? References: Message-ID: Fred wrote: > No problem. I just didn't know most of the GUI tools for Python use > cross-platform widget sets like wxWidgets, so expected to just start > playing without having to learn about this additional layer. You may want to look at my dotamatic project at http://dotamatic.sourceforge.net/ It is written in Python using the wxPython/wxWidgets toolkit. It does drawing, clipboard and printing as well as the other good things an application should have such as saving configuration settings and online help. You will also see the downloads for Windows, Linux and Mac. End users simply see what looks like a normal setup and a normal program. They never know or need to know that there is Python involved. If you are concerned with these kind of issues, you may also find part of the presentation I gave at baypiggies in July interesting. http://bitpim.org/papers/baypiggies Slides 11 thru 23 are the most appropriate but I expect you will find all the others interesting as well :-) Roger From cjw at sympatico.ca Wed Aug 25 08:11:21 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Wed, 25 Aug 2004 08:11:21 -0400 Subject: python-dev Summary for 2004-08-01 through 2004-08-15 In-Reply-To: References: Message-ID: Paul McGuire wrote: > "Brett Cannon" wrote in message > news:mailman.2274.1093330945.5135.python-list at python.org... > [snip] > "Well, then allow me to retort." > > Up until PyCon in June, Guido was publicly leaning toward a C1-flavor of > decorator syntax. Apparently, there was sufficient furor by some audience > members (not to quibble whether or not this group was in fact representative > of all Python users) that Guido dropped back from it. Sometime in June, > @decorator seemed to drop from the sky - it was not even one of the top 2 > that GvR had in his keynote presentation - and by late July, it was suddenly > to be found in the newly released 2.4a2. > My feeling is that Guido was right the first time. One of C1 or C2 is the better way to go. Why? There is a natural hierarchy. We do not define methods before the class signature is given. A subclass is defined after the class. A break is specified within the flow control being broken. We don't refer to a function until after is is declared. In the case of a 'decorator', it is better to identify the thing being modified, annotated or whatever before specifying the modification, annotation etc. The exception to this would arise if the 'decoration' were to apply to a group of functions or methods, but this is not being proposed. Brett Cameron and Anthony Baxter have pointed out that PEP 318 has been on the table for a while. That's true, perhaps I didn't read it carefully enough, but my initial impression was that the PEP was concerned with tarting up a function. It wasn't until I saw Dan Bishop's memoize that I realized the full import. I tried it with his Fibonacci example and found that it offered a significant speed improvement over both recursion and the iterative solution. Like many others, I fund the intrusion of a Perlish symbol into Python to be surprising. Thus, to sum up, Guido was right, C1 or C2 would be better than what has been implemented in either the current alpha version or Robert Brewer's proposal. Colin W. From cjw at sympatico.ca Fri Aug 20 19:11:04 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Fri, 20 Aug 2004 19:11:04 -0400 Subject: age of Python programmers In-Reply-To: References: Message-ID: <8yvVc.28188$ZI1.1123942@news20.bellglobal.com> Peter Hansen wrote: > brianc at temple.edu wrote: > >> -Started doing HTML for school projects in 9th grade. -Program my >> TI-82 (basic?) to help me cheat in classes. --Failed 10th grade and >> dropped out of high school. > > > So... you didn't program it correctly? > >> -That didn't scale well enough for the large datasets I was >> using, started using ZOPE. (If you live in MD, check this out, >> I designed/wrote the entire thing: www.marylandlantax.org) > > > Apparently should be http://www.marylandlandtax.org/ (note extra "d"). > > Cheers, :-) > -Peter Thanks - now completely off topic: The site points to a weakness of the scheme. It says "A new public works project may make adjacent land go up considerably in value. With a tax on land values, the tax on adjacent land goes up. The new public improvements are paid for by those most benefited by the new public improvements.". Certainly the neighbouring properties go up in value, but that value is only realized when the property is sold. Do the higher taxes get deferred until sale time? Colin W. From cygnus at cprogrammer.org Tue Aug 24 23:44:26 2004 From: cygnus at cprogrammer.org (Jonathan Daugherty) Date: Tue, 24 Aug 2004 20:44:26 -0700 Subject: Readline module Message-ID: <20040825034426.GA31869@vulcan.cprogrammer.org> Hello all, I've read some posts here talking about the fact that the 'readline' module packaged with python is only good for augmenting the behavior of the interactive interpreter. Can anyone recommend a readline-style alternative for building an app with an interactive prompt (on Linux, python 2.3)? -- Jonathan Daugherty http://www.cprogrammer.org From donn at u.washington.edu Mon Aug 30 18:38:58 2004 From: donn at u.washington.edu (Donn Cave) Date: Mon, 30 Aug 2004 15:38:58 -0700 Subject: [IronPython] Jim Hugunin's web log. References: <413397CA.8090209@v.loewis.de> Message-ID: In article <413397CA.8090209 at v.loewis.de>, "Martin v. Lowis" wrote: > David Wilson wrote: > > Other random thoughts: my experiences of the Python community versus, > > eg., the perl community make me believe that Pythonistas are generally > > more accepting of commercial solutions than their open source weenie > > perl counterparts (*duck*). > > I don't think this is an accurate description. Instead, Python is not > tied so much in Unix as Perl is (IMO). It is not Python's philosophy > to make all platforms look alike, but rather to expose all features of > a platform to the Python programmer - whether this is /dev/tty on Unix > or the registry on Windows. For features where it makes sense, a common > interface is established; other features are by nature restricted to > a single platform. > > As a result of that philosophy, people are often tempted to port Python > to "strange" platforms (be that Mac OS 9, BeOS, VMS, or the JVM). They > then found that Python maintainers where open to changes resulting from > these ports as long no harm was done to Python "proper" (laissez-faire); > this continues to encourage people to experiment with the language, and > with various platforms. I'll go along with that, it's sure a positive factor for me - sort of like the NetBSD of programming languages. And to my way of thinking it's essentially an open source phenomenon. Python does generally get there before Perl, but it also gets there before ... Smalltalk? Mathematica? Kind of stumped for closed source Python competitors. Perl has its own problems (as does Tcl: "Tk".) I would propose GNU C as an example of open source software that manages to take root in strange soil. Written partly by Stallman himself if I remember right. It might be true that the Python community is relatively free of stridently ideological open source advocacy, but if Python had not been open source, none of us would have ever heard of it. Whether or not it makes sense for all software to be open source, when it comes to "middle ware" like compilers and interpreters it makes an awful lot of sense. Donn Cave, donn at u.washington.edu PS: Yes I know there has been an open source Smalltalk for years, but for a long time it seemed like Smalltalk was dominated by commercial, closed source implementations, and GNU Smalltalk was a footnote. At that time it seemed that that language had some promising traction in business applications, and I guess it's a miracle there's no Microsoft Visual Smalltalk. Meanwhile, Smalltalk hasn't exactly taken over the world, and Python has emerged from its relative obscurity at the time. From alikakakhel3 at hotmail.com Mon Aug 16 18:37:21 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 16 Aug 2004 15:37:21 -0700 Subject: how to display unicode in a Label in Tkinter References: <8f17f4bc.0408151819.c06a79e@posting.google.com> Message-ID: <8f17f4bc.0408161437.2f557935@posting.google.com> Eric Brunel wrote in message news:... > Ali wrote: > > I was wondering how one would go about displaying unicode in a Label > > object in a Tkinter window. I am trying to display text in another > > language. Please help. > > Just put it in a Unicode string or in a raw string encoded in UTF-8 and you > should be going: > > >>> from Tkinter import * > >>> root = Tk() > >>> s = '????: ?a marche!' > >>> u = unicode(s, 'iso8859-1') > >>> Label(root, text=u).pack() > > (The code above supposes your default encoding is iso8859-1, a.k.a latin-1; > otherwise, you can do: s = '\xe0\xe9\xe8\xf9: \xe7a marche!') > > HTH So how I write in Arabic? From http Wed Aug 18 15:31:12 2004 From: http (Paul Rubin) Date: 18 Aug 2004 12:31:12 -0700 Subject: Embedding Python in Python References: Message-ID: <7x7jrwkzun.fsf@ruckus.brouhaha.com> Robey Holderith writes: > Would this be secure? No. > Paul, what's your take on this? Don't count on it. From pete at fenelon.com Thu Aug 26 14:25:42 2004 From: pete at fenelon.com (Pete Fenelon) Date: Thu, 26 Aug 2004 19:25:42 +0100 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: <6v9lgc.9i2.ln@fenelon.com> In alt.folklore.computers R Baumann wrote: > In this context --- This is the STUPIDEST thing I've ever heard. What a > maroon! What a Trollup! > He doesn't quite win, there's one regular afc troll who narrowly edges him out... but I won't mention his name because that tends to invoke him. ;) pete -- pete at fenelon.com "there's no room for enigmas in built-up areas" From noone at here.com Wed Aug 18 22:50:41 2004 From: noone at here.com (M. Clift) Date: Thu, 19 Aug 2004 03:50:41 +0100 Subject: that should of course read list of unknown length : ) References: Message-ID: "M. Clift" wrote in message news:cg1494$lvr$1 at news7.svr.pol.co.uk... > Hi All, > > I have a list of varying length. Would someone know the way to get the last > two values for this? I can see how this is done with a list that I know the > length of, but not one thats generated by user input. > > Thanks for any help > > From jaydonnell at yahoo.com Wed Aug 18 14:17:38 2004 From: jaydonnell at yahoo.com (Jay Donnell) Date: 18 Aug 2004 11:17:38 -0700 Subject: can tarfile maintain directory structure? References: Message-ID: > import tarfile > > tar = tarfile.open(filename, "w:gz") > tar.add(directory) > tar.close() > > The add() method is recursive by default. More information and examples > here: http://docs.python.org/lib/module-tarfile.html That doesn't maintain the directory structure. When you untar it all the files are in the base directory (when I untar it on windows with winzip). I haven't tried jeff's suggestion yet, but I'll let ya'll know how that goes. From bokr at oz.net Tue Aug 10 12:58:44 2004 From: bokr at oz.net (Bengt Richter) Date: 10 Aug 2004 16:58:44 GMT Subject: Maybe, just maybe @decorator syntax is ok after all References: Message-ID: On 10 Aug 2004 03:18:54 -0700, artur_spruce at yahoo.com (AdSR) wrote: >bokr at oz.net (Bengt Richter) wrote in message news:... >> On 9 Aug 2004 07:07:54 -0700, artur_spruce at yahoo.com (AdSR) wrote: >> >> >So the order is reverse, which breaks my previous interpretation. Oh, well... >> > >> I think your example is not from the PEP. What "spec" are you citing? > >http://www.python.org/dev/doc/devel/ref/function.html I guess that should be fixed. IIUC. Per BDFL: http://mail.python.org/pipermail/python-dev/2004-August/047521.html I still think a di-glyph with an opening paren would give the feel of the nesting effect (inner before outer) better than @ -- e.g., decofunexpr1(= decofunexpr2(= def foo(): pass for effect foo = decofunexpr1(decofunexpr2(foo)) (I started with '(:' but tools are sensitive to ':' I guess, so above uses '(=' Regards, Bengt Richter From eric_brunel at despammed.com Mon Aug 16 03:54:48 2004 From: eric_brunel at despammed.com (Eric Brunel) Date: Mon, 16 Aug 2004 09:54:48 +0200 Subject: how to display unicode in a Label in Tkinter References: <8f17f4bc.0408151819.c06a79e@posting.google.com> Message-ID: Ali wrote: > I was wondering how one would go about displaying unicode in a Label > object in a Tkinter window. I am trying to display text in another > language. Please help. Just put it in a Unicode string or in a raw string encoded in UTF-8 and you should be going: >>> from Tkinter import * >>> root = Tk() >>> s = '????: ?a marche!' >>> u = unicode(s, 'iso8859-1') >>> Label(root, text=u).pack() (The code above supposes your default encoding is iso8859-1, a.k.a latin-1; otherwise, you can do: s = '\xe0\xe9\xe8\xf9: \xe7a marche!') HTH -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From aleaxit at yahoo.com Mon Aug 30 03:05:09 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 30 Aug 2004 09:05:09 +0200 Subject: Iteration over Lists and Strings References: <1gj80xs.1cfownoqz4m9N%aleaxit@yahoo.com> <5M4Yc.326126$a24.276550@attbi_s03> Message-ID: <1gja55y.11yjoos1v7vn58N%aleaxit@yahoo.com> Brent W. Hughes wrote: ... > > SQUARE of len(sequence) -- a LOT, for long sequences, enumerate itself > > takes constant time, and looping over all items that enumerate yields > > takes time proportional to the number of items (costant time per item). ... > Did you say enumerate(seq) takes constant time? I would have thought it was > proportional to len(seq). Please look carefully at my quoted text: the call to enumerate(seq) itself takes constant time looping over [N items] takes O(N) In particular, looping over O(len(seq)) items does take O(len(seq)), whether you call enumerate somewhere or not The distinction matters, because some loops on enumerate(seq) may be able to bail out earlier, which may reduce their big-O behavior. A trivial example: for i, item in enumerate(seq): if i >= 3: break print item This prints the first few items of seq, but no more than three of them in any case; and it takes O(1), constant time (assuming that so do iter(seq)'s next(), and str(item) too) -- no matter how long seq is. Don't take this for granted, because it was not necessarily true before Python refined its looping protocol. Consider two recipes for enumerate that you'll find in the Cookbook's first edition...: [a] class enumerate: def __init__(self, seq): self.seq = seq def __getitem__(self, i): return i, self.seq[i] [b] def enumerate(seq): return zip(xrange(sys.maxint), seq) Recipe [a] does satisfy the same big-O performance constraints as today's enumerate ([a] is less general than today's enumerate, of course, because at that time the looping protocol did require the ability to index into the object, so [a] requires that from seq). But recipe [b] does not -- just calling enumerate in this version is O(N) in both time and space. ((Nevertheless, [b] was faster than [a] in many practically important cases, which is why I presented it anyway;-)). Alex From john at grulic.org.ar Sat Aug 21 13:55:47 2004 From: john at grulic.org.ar (John Lenton) Date: Sat, 21 Aug 2004 14:55:47 -0300 Subject: Decorator keyword options - brainstorming In-Reply-To: References: <7knVc.4599$Jn5.3074@fe1.texas.rr.com> Message-ID: <20040821175546.GA6008@grulic.org.ar> On Fri, Aug 20, 2004 at 10:34:30PM +0000, Paul McGuire wrote: > Some other ideas: > > imbue > endow > bestow > embellish > extend > accum > glom > confer why not 'pies', and then everybody's happy? -- John Lenton (john at grulic.org.ar) -- Random fortune: Don't relax! It's only your tension that's holding you together. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From josh at chatgris.com Wed Aug 4 13:36:32 2004 From: josh at chatgris.com (Joshua Moore-Oliva) Date: Wed, 4 Aug 2004 13:36:32 -0400 Subject: asyncore, asynchat and threads In-Reply-To: References: Message-ID: <200408041336.33683.josh@chatgris.com> Well, I took at look at twisted.. and it seems pretty scary ;) What I've done though is made some very minor changes to asyncore and asynchat, and now it appears to be threadsafe//more controllable. If all works out well for me I'll submit the patch to python, since it's fully backwards compatbile with the old behaviour. Thanks for the help Joshua Moore-Oliva On August 4, 2004 08:10 am, Peter Hansen wrote: > Joshua Moore-Oliva wrote: > > > I have to not return any data until there is data to > > return for that specific connection. If there is some > > way to send data down a asynchat > > socket from another thread (thread-safely), or to > > somehow wake up an asynchat class, that would be great. > > It's been years since I used asyncore (I find Twisted much > simpler to use) but at least in theory such a thing is > possible. Twisted has a callFromThread() method that can > be used to get a callback in another thread to be called > from the "reactor" (the equivalent of the asyncore core > loop), which would do what you want. Asyncore might have > similar facilities. > > I don't _fully_ grasp what you are doing, and I don't work > well without pictures in such cases (got a whiteboard handy? > draw a picture and send me a digital photo :-), but so > far it doesn't sound like you have anything approaching > unusual, compared to many other applications I've seen doing > the sorts of things yours seems to be doing. > > -Peter From skip at pobox.com Tue Aug 10 13:03:35 2004 From: skip at pobox.com (Skip Montanaro) Date: Tue, 10 Aug 2004 12:03:35 -0500 Subject: pep-318 questions In-Reply-To: References: Message-ID: <16664.65511.523539.817537@montanaro.dyndns.org> Hallvard> I don't understand some of the arguments in pep-318 (version Hallvard> 1.19), or what the current syntax has to do with some of the Hallvard> design goals mentioned there. Could someone explain? The PEP is known to be pretty far out-of-date with both the current patch and current thinking. Anthony Baxter and I are the people who have most recently edited it, but we are both short on time. I was out of town for three days and returned to more than a thousand Python-related mails, most dealing with PEP 318. I'm still digging out from that avalanche and have yet to even look at the text of the PEP for several days, let alone incorporate the wiki page or any of the comments here or in python-dev into the text. >> Design Goals >> >> The new syntax should >> (...) >> make it obvious what is happening; at the very least it should be >> obvious that new users can safely ignore it when writing their own >> code Hallvard> Huh? The current no-keyword, no-indentation syntax seems as Hallvard> far removed from "obvious" as one could get for Python. I think it's fairly well understood at this point that "obvious" is both in the eye of the beholder and difficult to achieve (there's not a large body of similar features in enough other languages that most programmers will have had experience with). Thankfully, it says "should" instead of "must". ;-) Hallvard> As for obvious that new users need not use it, it seems pretty Hallvard> hard to _avoid_ meeting that goal. Is it just included for Hallvard> completeness, or does it mean something more than I see in the Hallvard> statement? I can take it out if you like. ;-) I think the biggest single requirement has to be that any solution adopted must be easier to use than the current decorate-after-body scheme: def func(a, b): blah blah ... 75 more lines ... blah return blah func = staticmethod(func) Thankfully, all proposals I've seen satisfy that requirement. Hallvard> The current syntax seems like the clear loser here too: No Hallvard> whitespace above the function name. Not too bad with a single Hallvard> decorator, but several is a problem. There's no requirement that you smash them all together. This is valid with the current patch: @ a # comment # comment # comment # comment @ b def func(*args, **kwds): ... Hallvard> Anyway, to me, decorator after the def's ':' seems like the Hallvard> clear winner on the "easy to scan" point, decorator before ':' Hallvard> might possibly be #2 (unsure here - it's "theoretically right" Hallvard> but some posted examples look ugly), and a statement with Hallvard> indentation in front of the def #3. (Could indent just the Hallvard> decorators like the 'using' suggestion in the PEP, see below.) I think Guido pronounced on this over the weekend. He stated that decorators don't belong indented with the code, even at the beginning. In fact, he commented that in retrospect he feels that doc strings belong outside the function as well. (Of course, that would present a practical conflict between a module's doc string and that of the first executable code in the module file should it happen to be a function definition. But I digress...) >> Finally, it would require the introduction of a new keyword. Hallvard> Actually, I'm wondering about that too. Nobody has so far been able to come up with a single keyword that seems to connote "this is a decorator function that is to be applied to the next function definition". Skip From __peter__ at web.de Tue Aug 17 08:34:34 2004 From: __peter__ at web.de (Peter Otten) Date: Tue, 17 Aug 2004 14:34:34 +0200 Subject: Best programming language References: <873c2ndizt.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Message-ID: Andrew Durdin wrote: > On Tue, 17 Aug 2004 13:35:26 +0200, lopex wrote: >> 510046470588-0001 at t-online.de wrote: >> > >> > the best language is of course Scheme >> >> Another flamewar ? >> should I claim Ruby is.. ? > > The obvious answer, of course, is that on the newsgroup/mailing list > for language X, define "best programming language" to be X. It saves a > lot of combustion :) http://dmoz.org/Computers/Programming/Languages/ suggests that between Befunge and BETA there is space for "Best" waiting to be filled by an audacious developer. Good name for Python 3.0, maybe... Peter From arambo314 at hotmail.com Wed Aug 18 17:44:32 2004 From: arambo314 at hotmail.com (Arthur Rambo) Date: 18 Aug 2004 14:44:32 -0700 Subject: age of Python programmers References: Message-ID: <533e1e03.0408181344.4391a3c6@posting.google.com> The answer to the question about the Universe and Everything incremented by one. 43 Started programming at 15 with the TI-59 (Texas Instruments), than Basic on the TRS-80, Pascal on the Apple II-e and IBM PC, Lisp on the Macintosh, and finally *Python* (the best language I've ever seen for the kind of things I'm doing) on the IBM PC. "Lucas Raab" wrote in message news:... > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... From __peter__ at web.de Fri Aug 27 02:36:08 2004 From: __peter__ at web.de (Peter Otten) Date: Fri, 27 Aug 2004 08:36:08 +0200 Subject: Call for signatories for J2 References: Message-ID: For J2 Peter Otten Though I don't like "using". From dperl at rogers.com Fri Aug 27 13:15:49 2004 From: dperl at rogers.com (Dan Perl) Date: Fri, 27 Aug 2004 17:15:49 GMT Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> Message-ID: <9%JXc.79851$pTn.63106@news01.bloor.is.net.cable.rogers.com> My bad. Right after posting the message I found the 'Index of Python Enhancement Proposals (PEPs)' and there is PEP 273, 'Import Modules from Zip Archives', submitted by James C. Ahlstrom. Thank you, Jim! And there are even two implementations already. Dan "Dan Perl" wrote in message news:2SJXc.79576$pTn.26490 at news01.bloor.is.net.cable.rogers.com... > Here is a python feature that I would like: to be able to import modules > from an archive like the jar files in Java. Maybe a regular tar file? > Maybe a python specific file type, let's call it a 'par' file? > > It would be useful in packaging an python library. Sure, there's always the > python packages, but a single file instead of a whole directory tree would > be more convenient. I am particularly interested because I am working on a > framework/toolkit and I am using a configuration divided into several > modules. It would be nice to be able to save configurations (combinations > of several modules) into single archive files and then switch between > configurations by pointing to one such archive file. > > I am quite new to python so I should ask first whether there is already > something like that, although I did a search already. Or maybe such a > feature has already been discussed somewhere? If this is an original idea, > how can I propose it for future releases? > > Dan Perl > (yes, I'm Mr. Perl, but I'm using Python, after all Perl is not my middle > name, it's my last name) > > From aahz at pythoncraft.com Sat Aug 21 23:43:08 2004 From: aahz at pythoncraft.com (Aahz) Date: 21 Aug 2004 23:43:08 -0400 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> Message-ID: In article <278de0e.0408211605.426e5129 at posting.google.com>, Neuruss wrote: > >It seems there are quite a few projects aimed to improve Python's >speed and, therefore, eliminate its main limitation for mainstream >acceptance. What makes you think speed is Python's primary limitation for mainstream acceptance? -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From jbperez808 at wahoo.com Fri Aug 20 07:15:06 2004 From: jbperez808 at wahoo.com (Jon Perez) Date: Fri, 20 Aug 2004 19:15:06 +0800 Subject: Why isn't XUL more popular? In-Reply-To: References: Message-ID: <2om4a3Fc4p8rU1@uni-berlin.de> Daniel Kirsch wrote: > Jon Perez wrote: > > Of course, that's the DOM API. JavaScript only implements it. But what's > painfull about programming DOM? Once you get it (and easily extended it > thanks to Mozilla's proper implementation), it's pretty logical and > powerfull. I find DOM to be unnecessarily verbose. It looks very much like a bloated design-by-a-committee rather than a lean, mean spec designed by a few sharp minds. It takes way too many calls to do something simple and the proper calls to use are non-obvious to a beginner. It is really not that hard to imagine having a simpler API for manipulating XML. I have been doing extensive DOM work using Javascript for many years now and while I'm quite deep into DOM (For example, I have developed a technique to dynamically load/modify any part of a webpage from a remote data source without reloading the entire page. A much tougher task than you might think owing to Javascript/DOM API deficiencies and hence the need for 'voodoo' techniques), I must say I have never grown to love this API. Among the many XML-manipulation libraries available for Python are two or three DOM implentations. Despite my long experience with DOM under Javascript, I shun the DOM ones and instead use Fredrik Lundh's way more pythonic(*) ElementTree... waaaay easier to deal with. Too bad it or a similar API is not available for doing DHTML. :-( (*) 'pythonic' is roughly translated as meaning quick to learn (one sitting), easy to use (e.g. small, easy-to-remember API) and powerful at the same time. From dbickett at gmail.com Tue Aug 24 09:25:16 2004 From: dbickett at gmail.com (Beeyah) Date: 24 Aug 2004 06:25:16 -0700 Subject: Time-date as an integer References: Message-ID: <1d6cdae3.0408240525.236249e8@posting.google.com> Charles Hixson wrote in message news:... > This is a concept, not a finished program, and an extract from a class > at that...so forgive any illegalities, but: > import datetime; > def calcNodeId(self): > t = datetime.utcnow() > val = t.year * 133920000000 + # 12 months > t.month * 11160000000 + # 31 days > t.hour * 3600000000 + # 60 minutes > t.minute * 60000000 + # 60 seconds > t.second * 1000000 + t.microsecond > if val <= self._dTime: > val = self._dTime + 1 > self._dTime = val > return val > > This is the best that I've been able to come up with in getting a > date-time as an integer. It feels like one of the time or date > libraries should have a better solution, but if so, I haven't found it. > Can anyone suggest a better approach? Your indentation is... interesting. Have you considered timestamps? From jjl at pobox.com Tue Aug 17 17:30:25 2004 From: jjl at pobox.com (John J. Lee) Date: 17 Aug 2004 22:30:25 +0100 Subject: Windows URL protocol handler in python? References: Message-ID: <657hsb9q.fsf@pobox.com> "john.burton at jbmail.com" writes: > Is there a way to make a handler in python presumably using the win32 > extensions to handle URLS of a specific type when they are given to > windows? > > For example if I want to handle > myprotocol://server/id > using my own python program? > Any suggestions or references would be appreciated. Maybe pywin32 can do it. Probably ctypes can do it. Read up on COM monikers (eg. Essential COM by Don Box). John From in.aqua.scribis at nl.invalid Tue Aug 17 16:22:57 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Tue, 17 Aug 2004 22:22:57 +0200 Subject: flex: plex? Message-ID: Hi, I am looking for a Python equivalent of Flex. After some browsing, it seems that Plex is my best bet, but I would like to hear suggestions before I dive in. I have been using Flex a lot in combination with C programming. I never use Yacc (or Bison), though Flex and Yacc are supposed to be used together. But I found Yacc too cumbersome, and unnecessary. Yacc is about context-free grammars, nice if you like to describe an input language as a set of context-free rewrite rules. Flex is about finite-state automata, but can be extended to push-down automata (equivalent to context-free grammars) and beyond, as long as it stays deterministic. I found this to be very productive. I prefer automata over rewrite rules. So, what I am looking for is a Python version of Flex that supports the following capabilities, which are also supported by Plex: - assigning any Python code to a matched input pattern - input pattern recognition depending on 'states', which can be changed through actions Things that seems to be missing from Plex: - patterns like: A/B : match A only if followed by B, give A as result, keep B in the input stream - actions like: REJECT: ask the flexer to come up with the next best match for the same input LESS(n): push n characters back into the input stream All these are not really necessary, but they make some things simpler. So, are there any other packages that do these things better than Plex? -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From ake.ljungbert3 at comhem.se Sat Aug 7 21:35:45 2004 From: ake.ljungbert3 at comhem.se (?ke) Date: 7 Aug 2004 18:35:45 -0700 Subject: compiling with msvc7 Message-ID: <875af5e2.0408071735.4c1fdf89@posting.google.com> I am trying to comile C code to python with weaver, using Microsoft Visual Studio .NET (which I think uses VS 7.0) but I get an error that Python is compiled with VS 6 and so doesn't work. Anyone knows a workaround for this ? ?ke From mariube+netnews+ at ifi.uio.no Wed Aug 18 12:07:30 2004 From: mariube+netnews+ at ifi.uio.no (Marius Bernklev) Date: Wed, 18 Aug 2004 18:07:30 +0200 Subject: age of Python programmers References: Message-ID: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> "Lucas Raab" writes: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... 24. (anyone keeping count?) -- Marius Bernklev From tor.iver.wilhelmsen at broadpark.no Sun Aug 22 04:53:17 2004 From: tor.iver.wilhelmsen at broadpark.no (Tor Iver Wilhelmsen) Date: 22 Aug 2004 10:53:17 +0200 Subject: unicodedata name for \u000a References: Message-ID: Peter Kleiweg writes: > No, there isn't. Check > http://www.unicode.org/charts/PDF/U0000.pdf Quoting that document: Alias names are those for ISO/IEC 6429:1992. Commonly used alternative aliases are also shown. 000A LF = LINE FEED (LF) So the authors of unicodedata.name() could have picked either '', the ASCII name 'LF' or the alternative 'LINE FEED (LF)'. Not picking any of them seems strange, and as the OP pointed out, leads to an error even though the "C0 Controls" part of that page *is* part of Unicode. From davebrok at soda.csua.berkeley.edu Wed Aug 18 00:40:25 2004 From: davebrok at soda.csua.berkeley.edu (David Pokorny) Date: Tue, 17 Aug 2004 21:40:25 -0700 Subject: Why is SETUP_FINALLY uninterruptable[sic]? References: <2JmdnSiV4NZzGL_cRVn-pg@lmi.net> Message-ID: "Jeff Epler" wrote in message news:mailman.1836.1092794238.5135.python-list at python.org... >I suspect that this has something to do with code like > > l = some_lock() > l.acquire() > # MARK > try: > something with l held > finally: > l.release() >If an asynchronous exception happens betwen l.acquire() and the >SETUP_FINALLY opcode (at "MARK") , there's no guarantee that l.release() >is executed. > >This state of affairs always existed with KeyboardInterrupt and/or >signals, and it's hard to see how this fixes the problem if l.acquire() >is Python code, but I think that's what's going on. I would belive you, but there is a trivial modification that circumvents this problem: ---begin--- mylock = some_lock() try: mylock.acquire() something with mylock held finally: mylock.release() ---end--- Now if you're saying that lots of people wrote code as above and uninterruptibility was added to ensure that it wouldn't break, that's one thing, but is this the ONLY reason SETUP_FINALLY is uninterruptible? This seems improbable, especially since putting statements adjacent to #MARK will break this code. David From len-1 at telus.net Sun Aug 15 11:59:25 2004 From: len-1 at telus.net (Lenard Lindstrom) Date: Sun, 15 Aug 2004 15:59:25 GMT Subject: Generators versus Coroutines References: <7x7js1i887.fsf@ruckus.brouhaha.com> Message-ID: Nick Patavalis writes: > On 2004-08-14, Paul Rubin <> wrote: > > > > You can't yield across multiple levels of function calls. That's why > > they're called "simple generators" instead of just "generators". > > > > For me it would be *tremendously* usefull if one could yield across > multiple levels of function calls. If this was supported, then most > uses of O/S treads could be replaced by generators. > > Does anyone know if such a feature is planned? > Having followed the development of Prothon it is my understanding that such a thing is not possible in CPython for two reasons. The first is that the yield statement itself defines a function declaration as a generator. Without a specific "gen" declarator keyword as in Prothon: gen evens(n): # This is a generator for i in n: # "for i in range(n)" in Python doubleit(i) def doubleit(i) # This is a helper that yields yield(2 * x) # "yield 2 * x" for i in evens(5): print(i) # "print i" the yield does not know how many function calls up it must go to return a value. In CPython it simply saves one frame, that of the current function call. The second reason is a python function call in CPython involves an actual recursive C call of the interpreter. So to have a yield span more than one python function would require saving and restoring part of the actual C stack - coroutines at the C level - or a rewrite of the interpreter to not make the recursive C calls as in Stackless Python. Lenard Lindstrom From martin at v.loewis.de Wed Aug 11 18:10:06 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 12 Aug 2004 00:10:06 +0200 Subject: Python script to generate static site? In-Reply-To: References: Message-ID: <411a9935$0$12538$9b622d9e@news.freenet.de> > Considering Python's wealth of libraries, it's most likely only a > couple hours' work, but since I'm pretty much a Python newbie... I recommend ht2html; this is used to generate python.org. Regards, Martin From rnd at onego.ru Wed Aug 25 07:53:27 2004 From: rnd at onego.ru (Roman Suzi) Date: Wed, 25 Aug 2004 15:53:27 +0400 (MSD) Subject: Is it a bug (or a feature)? Message-ID: In Python2.3.4: >>> em = email.message_from_file(open('MAILMESSAGE')) >>> for i in em: ... print i ... Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.3/email/Message.py", line 304, in __getitem__ File "/usr/lib/python2.3/email/Message.py", line 370, in get AttributeError: 'int' object has no attribute 'lower' However items() does work: >>> for i in em.items(): ... print i ... ('Date', '24 Aug 2004 16:06:01 +0400') ('From', 'Mail System Internal Data ') ('Subject', "DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA") ('Message-ID', '<1095549161 at mydomain.ru>') ('X-IMAP', '1095527634 0000000005') ('Status', 'RO') I can probably guess why this happens ('cause multiple fields with the same names are possible), but .items() is broken by this... It needn't be! Sincerely yours, Roman A.Suzi -- - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru - From in.aqua.scribis at nl.invalid Tue Aug 31 17:37:40 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Tue, 31 Aug 2004 23:37:40 +0200 Subject: Beeping the console In-Reply-To: References: Message-ID: Jeffrey Barish schreef: > What is the easiest way to beep the console from a Python program (i.e., > to do the same thing as echo -e \a)? import sys sys.stdout.write('\a') or if you don't mind a newline: print '\a' -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From fumanchu at amor.org Fri Aug 20 12:17:31 2004 From: fumanchu at amor.org (Robert Brewer) Date: Fri, 20 Aug 2004 09:17:31 -0700 Subject: Alternative decorator syntax decision Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E14@exchange.hqamor.amorhq.net> Top-posting-to-help-quick-scanning: J2 J2 J2. To Paul, M. Sparks, et al: Since J2 is coming up frequently (and Guido did not immediately reject it when asked), I'm going to follow through and try to write a proposal this weekend for J2. I'll post it here for feedback (and of course, wait for the 'final' count of votes) before posting it on py-dev. Robert Brewer MIS Amor Ministries fumanchu at amor.org > -----Original Message----- > From: python-list-bounces+fumanchu=amor.org at python.org > [mailto:python-list-bounces+fumanchu=amor.org at python.org] On > Behalf Of Paul McGuire > Sent: Thursday, August 19, 2004 12:17 PM > To: python-list at python.org > Subject: Alternative decorator syntax decision > > > There are a number of messages on the python-dev mail list > that indicate > that Guido is looking for some concensus to come from this > list as to what > *one* alternative syntax for decorators we would like him to > consider in > place of the @ syntax that is currently in 2.4a2. > > I think special thanks are due to: > - Anthony Baxter for his continuing efforts in this regard > - Steven Bethard for some of the clearest thinking and > writing on this topic > - Michael Sparks for actually implementing one of the options > > We've all done our share of pitching and whining, but we need > to settle on > *one* option for Guido to consider. > > (And let's not get wrapped up complaining about the "process" > being followed > in this whole thing, personally I think it is quite poor. > But let's play > with the cards we've been dealt, and at least make a > collective proposal.) > > The significant alternatives have been listed on the Python wiki at > http://www.python.org/moin/PythonDecorators . > > Interested parties should also look at the comments in the python-dev > archive for the past month, at > http://mail.python.org/pipermail/python-dev/2004-August/thread.html . > > I would propose a multivote survey: each poster gets 3 votes among the > lettered choices on the Wiki page above. You can use all 3 > for a single > option, or split them across 2 or 3 options if you are open > to more than > one. > > I am not going to argue that this is scientific in any respect, but it > *should* allow the major 1 or 2 choices to bubble to the top. > I have used > this process at work many times in the past when it was > necessary for a > large group to set priorities among a large list of choices. > > My vote is: J2 J2 C1 > > By the way, once an option has been chosen, it *still* needs an > implementation for Guido to accept it. This puts some of the > options way > ahead of the others, in my mind. > > (And let's hope we get at least as good a response as the > "average age" > thread!) > > -- Paul > > > -- > http://mail.python.org/mailman/listinfo/python-list > From aleaxit at yahoo.com Fri Aug 27 14:07:43 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 27 Aug 2004 20:07:43 +0200 Subject: Alex Martelli: Welcome back! References: Message-ID: <1gj70sk.1o4cuwepco564N%aleaxit@yahoo.com> Batista, Facundo wrote: > [Dave Benjamin] > > #- Asunto: Alex Martelli: Welcome back! > #- > #- It's nice to see you around here again! > > +1 Heh, thanks. BTW, anybody interested in the readings we choose for our marriage (me and Anna, who's also going to be my coeditor for the Python Cookbook Second Edition) can have a look at http://www.aleax.it/mar.html ... Pythonistas will find one of the poems, ahem, interesting. (Some photos are at http://bonanna.multiply.com/photos/album/1 , but mentioning them would be OT, since they're not Python-related;-). Alex From 510046470588-0001 at t-online.de Mon Aug 16 14:40:22 2004 From: 510046470588-0001 at t-online.de (510046470588-0001 at t-online.de) Date: 16 Aug 2004 20:40:22 +0200 Subject: Best programming language References: Message-ID: <873c2ndizt.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Roman Suzi writes: > On Mon, 16 Aug 2004, lopex wrote: > > >Roman Suzi wrote: > > > >> ;-) > >> > >> Just type into google > >> "best programming language" > >> and press (I am lucky) > > > >Ruby ? > > This probably indicates that Python in not well enough described as "best" > for certain domains while Ruby isn't as humble ;-) > > the best language is of course Scheme Klaus Schilling From anthonybaxter at gmail.com Thu Aug 5 22:12:51 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 12:12:51 +1000 Subject: Quixote vs. Preppy In-Reply-To: References: Message-ID: On 5 Aug 2004 15:18:37 -0700, ellisjb at my-deja.com wrote: > Incidently, http://www.colorstudy.com/docs/shootout.html looks like a > good summary of the major Python web frameworks. Unfortunately, it's > not dated... anyone know? The page's modification date is April 2003. From rnd at onego.ru Sun Aug 22 10:20:45 2004 From: rnd at onego.ru (Roman Suzi) Date: Sun, 22 Aug 2004 18:20:45 +0400 (MSD) Subject: uppercase? RE: Alternative decorator syntax In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022E22@exchange.hqamor.amorhq.net> References: <3A81C87DC164034AA4E2DDFE11D258E3022E22@exchange.hqamor.amorhq.net> Message-ID: On Sat, 21 Aug 2004, Robert Brewer wrote: >Paul Rubin wrote: >> "Paul McGuire" writes: >> > Please start giving some thought to what the 'decorate' >> keyword should be. >> >> Looks like "declare" to me ;-) > >I agree, for reasons which will become clear in the proposal draft. > >I'd be most interested to hear arguments _against_ "declare", if there >are any. I do not like 'decorate' (or 'using') as it is too lenghty. My preference is some hort 2-3 letter variant, which is not repeted on each line: Let me patent this ;) before anybody else: BY: staticmethod, otherdecor(x,y,z) def func(x): .... DEF: staticmethod, otherdecor(x,y,z) def func(x): .... WITH: staticmethod, otherdecor(x,y,z) def func(x): .... AS: staticmethod, otherdecor(x,y,z) def func(x): .... or AS: staticmethod otherdecor(x,y,z) def func(x): .... USE: staticmethod, otherdecor(x,y,z) def func(x): .... DEF is most interesting. It has a concept of a LARGE def. Whereas small def is just a ef of a function. Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3 From martindemello at yahoo.com Fri Aug 20 16:02:11 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Fri, 20 Aug 2004 20:02:11 GMT Subject: decorator J4 - any objections? References: <7xbrh5hcpb.fsf@ruckus.brouhaha.com> Message-ID: <7NsVc.155687$M95.24909@pd7tw1no> Paul Rubin wrote: > > Also, why the need for the "as" keyword? What happens if it's just > eliminated? I.e.: > > def func(arg1, arg2) > @version("Added in 2.4") > @returns(None): > > """Docstring could be here, or in decorator part above""" > # body goes here It's really nice to have an outdented marker for when the actual function body begins. martin From ptmcg at austin.rr._bogus_.com Mon Aug 9 10:34:17 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 09 Aug 2004 14:34:17 GMT Subject: Exceptions as a Control Structure References: <411775aa$0$17867$626a14ce@news.free.fr> <41177b65$0$17857$626a14ce@news.free.fr> Message-ID: > > Exceptions are also used by some as a mechanism for > > returning information from subroutines, though it's > > very likely the information will still be considered > > "exceptional" in some way (think of it as an out-of-band > > mechanism for returning special info). > > Do you have some example of this in the standard library ? > pyparsing uses this technique to try various parse expressions - a raised ParseException denotes that the attempted parsing pattern failed to match at the current stream location. In an earlier incarnation of this library, I implemented this by returning True or False values to indicate successful matching, but when a False was returned, I found I needed more information about why things were False. The exception-based approach allows me to return a full exception, including the match failure message and the location at which the failure occurred. One optimization I have found w.r.t. exceptions is that, in pyparsing, a given parsing expression always raises the almost the same exception, with only the input location changing. I found a significant improvement by pre-constructing the exception at grammar construction time, and then raising a modified version at parse time. (Contrast with the dynamic construction/garbage-collection of thousands of exception objects when created and used only once.) -- Paul From martin at v.loewis.de Sun Aug 1 02:57:40 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 01 Aug 2004 08:57:40 +0200 Subject: Importance of C# (was Re: IronPython-0.6 is now available!) In-Reply-To: References: <278de0e.0407281353.27b6a457@posting.google.com> <7u5tpvap1oh5.1h1v27kmjvf04$.dlg@40tude.net> Message-ID: <410C9464.5080809@v.loewis.de> Edward Diener wrote: > Why do you say that ? In other words, what in Python's implementation of MI > is superior to C++'s implementation of MI ? In Python, MI is easier to understand than in C++. The state definition for an object is simpler, as there is no need for virtual-vs-non-virtual inheritance. Also, there are no casting issues in Python that cause common errors in C++ (because in MI, casting can change the representation of the address of an object). Regards, Martin From amajorel at teezer.fr Tue Aug 31 06:55:56 2004 From: amajorel at teezer.fr (Andre Majorel) Date: Tue, 31 Aug 2004 10:55:56 +0000 (UTC) Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4PGdnfsOfdDPi63cRVn-tA@speakeasy.net> <41337FC9.8070902@hotmail.com> Message-ID: On 2004-08-31, Brian Inglis wrote: > On Tue, 31 Aug 2004 01:12:55 +0000 (UTC) in alt.folklore.computers, > Andre Majorel wrote: > >>On 2004-08-30, Antony Sequeira wrote: > >>> Windows (MS) is not 'Unixism'? >> >>If by unixism, you mean any operating system that has a >>hierarchical filesystem and byte stream files, yes. But that >>would include quite a few other non-Unix operating systems, >>including Mac OS 9, Prologue and probably everything else this >>side of CP/M (DOS 1.x shall be deemed to be CP/M). > > DOS 2.x+ shall be deemed to be CP/M+! Wasn't it in version 2 that they added directories and Unix-style file handles ? -- Andr? Majorel Conscience is what hurts when everything else feels so good. From gumuz at NO_looze_SPAM.net Wed Aug 18 08:57:14 2004 From: gumuz at NO_looze_SPAM.net (Guyon Morée) Date: Wed, 18 Aug 2004 14:57:14 +0200 Subject: age of Python programmers References: Message-ID: <41235225$0$3889$4d4ebb8e@news.nl.uu.net> 21 years and counting.... "Lucas Raab" wrote in message news:jQHUc.1529$2L3.505 at newsread3.news.atl.earthlink.net... > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... > > From sjdevnull at yahoo.com Sun Aug 8 20:05:59 2004 From: sjdevnull at yahoo.com (G. S. Hayes) Date: 8 Aug 2004 17:05:59 -0700 Subject: decorators vs GIL References: Message-ID: <96c2e938.0408081605.706f8ec7@posting.google.com> mudd at vex.net wrote in message news:... > What really hurts is that I can't honestly tell Java programmers that > Python is a slam dunk compared to Java & the JVM. Java has no GIL, Java has drunk the threads Kool-Aid, and Java programmers are very likely to be thread-crazy because of the lack of a select equivalent (until recently) and the lack of good access to processes via fork or similar. Luckily, it's usually pretty easy to convince people of the benefits of NOT overusing threads once they've made that mistake once. I honestly think a big reason the GIL isn't a major issue to most Pythonistas is because they tend to know that there's a better way to approach most problems than using threads. > Isn't that like saying, I avoid programming in general because it's > error-prone? I don't follow. Not really. You need to program to get things done, but presumably you leverage all the work that's been done over the past 40+ years to make that an easier, less error-prone task. It's like saying you shouldn't program in assembly because it's error prone; sure, there are some cases where it makes sense, but in general it's not a great idea. Threads are error-prone because they intentionally circumvent the years of OS work that went into getting protected memory for us in the first place. Even for tasks that aren't neatly divided into an event loop, processes are available for parallel execution. 99% of the time they're a better choice _except_ that two of the most dominant programming platforms out there don't have a good (efficient and featureful) implementation (Java and Windows). It's absolutely insane that many Windows programmers believe that to use parallel processing requires you throw out memory protection; the two concepts are very distantly related. The decision to use threads vs. processes ought to come down to whether you want to share ALL memory (and deal with the locking and reentrancy issues that come along with that choice) or only a specified subset of memory. When you view it from that perspective, threads are only rarely the right choice. Indeed, in all the years that I've been writing code I've never once found a problem where I felt threads were the right approach--and that includes work on high-performance servers with thousands of concurrent users, large-scale data visualization applications that depend on the results of many parallel searches, and realtime audio processing applications with non-realtime visualization and UI components. That's not to say there aren't limited problem domains where threads are the right answer, but as a general construct they're wildly overused. I'm frankly glad that Python doesn't encourage more of the same. From fumanchu at amor.org Tue Aug 24 16:38:24 2004 From: fumanchu at amor.org (Robert Brewer) Date: Tue, 24 Aug 2004 13:38:24 -0700 Subject: J2 paper 0.2.1 Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E55@exchange.hqamor.amorhq.net> First, thanks for the comments! Paul Moore wrote: > 1. I differ on the "it doesn't matter what the keyword is" statement. > On the contrary, my view could completely change depending on the > keyword - I'd loathe "predef", whereas "using" is acceptable to me. > Putting the proposal forward *without* an agreed keyword isn't > (IMHO) fair to people who have this view. I understand your emotion, now, but not your reasoning, and in the absence of that, I can't generate a fix for the proposal. If you could go into more detail *why* you would loathe predef, it would go a long way toward allowing a stronger statement in the doc. I feel "using" has positives, but I don't know what the negatives of "predef" are. Happy to make it stronger if there's an argument in addition to passion. Without a logical argument, such a position comes down to "it's ugly", which Guido has specifically said he doesn't care about or want to hear. > 2. I agree with the person who pointed out that the indentation makes > the decorators merge visually with the function name. This is a > definite point against the syntax, and should be at least noted in > section "Arguments - I - 3 Additional benefits" paragraph 2. In > fact, I could esily argue that it completely invalidates this > point, swinging it in favour of @ syntax. OK. I still feel the indent-dedent "points out where the def is" better than @. But I'll try to synthesize the two in a more balanced fashion. > 1. The patch doesn't (according to the comment) implement the > __future__ import. This needs to be added before the proposal is > submitted. And __future__ support for the interactive prompt may be > needed as well - I'm not sure here, see PEP 236 for the detail. I agree it should. I'll see what can be done. Hope it's not too much of a burden on Michael...? Anyone familiar with __future__'s that would like to work on that? > 2. Does the patch support decorating classes? The @ syntax *might* by > now (in CVS), there was discussion of adding it but I'm not sure it > went in. The patch should probably provide the same functionality > as CVS @-syntax, rather than just 2.4a2. The patch does not support decorating classes, because @ doesn't. There's a patch submitted for that*, but it hasn't been accepted, IIRC. The PEP says 2.4 will see only function decorators. Robert Brewer MIS Amor Ministries fumanchu at amor.org http://sourceforge.net/tracker/index.php?func=detail&aid=1007991&group_i d=5470&atid=305470 From anthonybaxter at gmail.com Thu Aug 5 13:35:07 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 03:35:07 +1000 Subject: RELEASED Python 2.4, alpha 2 In-Reply-To: References: <411231C8.3020308@interlink.com.au> Message-ID: > I'll admit synchronization is a strong use case (since I don't believe it > justifies language support, like it has in Java), but I just think there's > a better way to go about things that no-one's thought of yet. The discussion's been going on python-dev since at least February 2002. No better solution has been found yet. From abra9823 at mail.usyd.edu.au Mon Aug 9 05:10:44 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Mon, 9 Aug 2004 19:10:44 +1000 Subject: file owner id Message-ID: <1092042644.41173f94ee898@www-mail.usyd.edu.au> hi! i have an application that allows admin users to create template files, which are stored on the server. currently the file are created with the owner "nobody" is it possibly to change the owner to be the same as the owner of the web account? if yes, are there any security risks with doing so - the script changes to the web account's owner, creates the file and then changes back. thanks cheers -- Ajay Brar, ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From anthonybaxter at gmail.com Thu Aug 19 06:46:16 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Thu, 19 Aug 2004 20:46:16 +1000 Subject: PEP 318: Can't we all just get along? In-Reply-To: References: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: On Thu, 19 Aug 2004 06:35:18 -0400, Paul Morrow wrote: > Unless of course you want a method to be private/semi-private. How do > you feel about the way we can create/manipulate lists and dictionaries > using special (magical) syntax? Why is that different (acceptable)? Look, name-mangling is horrid, and I don't think anyone's defending it. But at the same time, "name mangling is there" is not an argument for extending the horror to a whole new level. Name mangling only occurs when you create a method with two leading underscores, and no trailing ones. Your proposal would hit _every_ _single_ 'def'. It's nasty, it's unpythonic, and there's approximately _zero_ chance of it ever going into the language. Having said that, it's perfectly feasible to do it with a metaclass, and if you want to use it in your code, please, feel free. Anthony From in.aqua.scribis at nl.invalid Tue Aug 31 13:54:05 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Tue, 31 Aug 2004 19:54:05 +0200 Subject: "Content-Length" header In-Reply-To: References: <96c2e938.0408302057.61df147b@posting.google.com> Message-ID: Jeremy Bowers schreef: > On Mon, 30 Aug 2004 21:57:02 -0700, G. S. Hayes wrote: > > Something related to think about: if most users use only letters in their > > passwords, making the passwords case-insensitive potentially makes it take > > crackers HALF the time to crack a password by brute force. > > Much worse than that. > > Assuming 8 letters only: > > Both cases: 52 ^ 8: 53,459,728,531,456 (53 trillion) A bit less: 53 billion > One case : 26 ^ 8: 208,827,064,576 (208 billion) 208 billiard -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html The Halloween Documents: http://www.opensource.org/halloween/ From dlp at itasoftware.com Tue Aug 24 14:11:40 2004 From: dlp at itasoftware.com (Dan Pierson) Date: 24 Aug 2004 11:11:40 -0700 Subject: python-dev Summary for 2004-08-01 through 2004-08-15 References: Message-ID: <2b5834f8.0408241011.fde9b55@posting.google.com> Istvan Albert wrote in message news:... > > It is not to be used in the stdlib ever. > > mean in this context? IMHO, it means that Python code that is, or might be, checked into the standard library (i.e. shipped with Python) must never assume that this optimization is implemented. Presumably this is because other Python implementations reuse code from the standard library and they may not have implemented the optimization. From usenet_spam at janc.invalid Tue Aug 24 12:56:58 2004 From: usenet_spam at janc.invalid (JanC) Date: Tue, 24 Aug 2004 16:56:58 GMT Subject: Alternative decorator syntax decision References: Message-ID: Paul McGuire schreef: > Also, there is no protection in the web page from "ballot box > stuffing" - I hate to even bring it up, I think we're all adults here, > but with public postings on Usenet, there is a somewhat higher effort > to create fictitious posts to vote multiple times vs. visiting a poll > page multiple times. I think it's at least as easy on usenet as on a website. There are lots of open news servers to be abused... -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From mauro.baraldi at bol.com.br Mon Aug 16 09:51:11 2004 From: mauro.baraldi at bol.com.br (Mauro Baraldi) Date: 16 Aug 2004 06:51:11 -0700 Subject: Knowing a COMObject by IID Message-ID: Hello! Someone can helpe-me how to get the name of a COMObject by it CLSID. Example: A object got a number CLSID ({CA8A9783-280D-11CF-A24D-444553540000}). It name is Acrobat Control for ActiveX. Or where can I found a good reference for this... Thanks Mauro From mark at prothon.org Sat Aug 7 18:11:37 2004 From: mark at prothon.org (Mark Hahn) Date: Sat, 7 Aug 2004 15:11:37 -0700 Subject: Prothon is switching to the .NET platform References: <000401c47b59$32539220$0d01a8c0@MarkVaio> <10h7lb21dhbuc12@news.supernews.com> <10h7rittck6ct75@news.supernews.com> <10h9dkm5ub5h1f2@news.supernews.com> Message-ID: <1dske12sbt1mj$.1aq70xrpy0r0i.dlg@40tude.net> On Sat, 7 Aug 2004 07:01:55 -0400, John Roth wrote: > "Peter Otten" <__peter__ at web.de> wrote in message > news:cf1t0h$ond$03$1 at news.t-online.com... >> John Roth wrote: >> >>> >>> "Christopher T King" wrote in message >>> news:Pine.LNX.4.44.0408061533250.25906-100000 at ccc8.wpi.edu... >>>> On Fri, 6 Aug 2004, John Roth wrote: >>>> >>>> > I think it's possible to do prototypes within Python by >>>> > overriding the __getattribute__() magic method. It still >>>> > wouldn't be very pretty, but it should be able to do >>>> > everything except override the magic methods (those >>>> > seem to have to be in the class object for new style >>>> > classes). >>>> > [snip] >>> >>> What I was thinking of was more along the lines of: >>> >>> class ProtoBaseClass(object): >>> def __getattribute__(self, attr): >>> # call object.__getattribute__(self, __dict__) >>> # find requested attribute >> >> Wouldn't that part be implied if you used __getattr__() instead of >> __getattribute()? >> >>> # if not found, loop through back pointer chain >>> # if it's not a function, return the attribute >>> # if it is a function, wrap it in a method object and return it. >> >> This means that an object sees all changes in its prototypes until >> explicitly assigned an attribute. Is this intentional? (real question, I'm >> not familiar with prototyped languages) > > Actually, __getattribute__ sees all attribute requests, __getattr__ > only sees requests where the attribute isn't found. The reason for > using __getattribute__ is that there are (I think) serious problems > with attempting to execute functions that weren't originally defined > in the base class or a subclass of the base class. In other words, > if the result is a function, there's more work that needs to be done, > and __getattr__ doesn't allow a hook to do it on the way out. > > The attempt from 2000 I referred to attempted to get around this > by using a callable instance together with a lambda. Unfortunately, > it didn't work when I tried it, and as I said, after looking at the > code I don't think it ever worked. The workaround for the function > problem might work, though. Lenard Lindstrom wrote a prototype implementation in Python. He hangs out on the Prothon mailing list (and here also, I assume). He probably knows more about this topic than anyone. Mark Hahn Prothon Author From roy at panix.com Mon Aug 16 19:42:51 2004 From: roy at panix.com (Roy Smith) Date: Mon, 16 Aug 2004 19:42:51 -0400 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> <41214271_1@127.0.0.1> Message-ID: In article <41214271_1 at 127.0.0.1>, "beliavsky at aol.com" wrote: > Jorge Godoy wrote: > > >Just an attempt and trying to keep it like your code. > > Thanks. My code did not correctly illustrate breaking out of more than one > level of loop. How would the following code be translated to Python? Ugh. This is a truly ugly scenario. You've got three nested loops, with each inner loop having a break out of both itself and the immediately containing loop. Does this correspond to some real-world algorithm, or is it just a diabolical scenario invented for the example? The bottom line is that this is really ugly and convoluted logic, and as such is probably going to be ugly and convoluted no matter what language you write it in. Unless I don't understand what your code does, I don't see any way to write it in Python which won't be as ugly or uglier as your original. > It is silly of course, but real-world situations where you want to exit a > nested loop are not that rare. Yes, there are occasions where you want nested loops (even three deep), and need to break out of the innermost one. But I've never seen anything quite as complex as the scenario you set up here. What I usually do when I've got a deeply nested loop like that is to factor it out into its own function, and let the return statement act like a multi-level break. Something like: def foo (n): """Return the first (i, j, k) triple that meets some condition. Return None if the condition is never met.""" for i in range (n): for j in range (n): for k in range (n): if condition: return i, j, k return None > > program xnest_loop > ! illustrate breaking a nested loop > integer :: i,j,k,n > n = 4 > ido: do i=1,n > jdo: do j=1,n > if (i+j > n) exit ido > do k=1,n > if (i+j-k < 0) exit jdo > print*,i,j,k > end do > end do jdo > end do ido > end program xnest_loop > > output: > 1 1 1 > 1 1 2 > 2 1 1 > 2 1 2 > 2 1 3 > 3 1 1 > 3 1 2 > 3 1 3 > 3 1 4 > > > > > ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet > News==---- > http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 > Newsgroups > ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption > =--- From tjreedy at udel.edu Sat Aug 28 15:57:38 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 28 Aug 2004 15:57:38 -0400 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com><1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com><7xzn4gwgea.fsf@ruckus.brouhaha.com><1gj7a1o.1a5d2q410jsn2kN%aleaxit@yahoo.com><7xisb4xnh5.fsf@ruckus.brouhaha.com><1gj7c1a.tfdm14p3hclcN%aleaxit@yahoo.com><7xd61benm9.fsf@ruckus.brouhaha.com><1gj82n3.1ylkr3nierngmN%aleaxit@yahoo.com> <7xd61b8uh2.fsf@ruckus.brouhaha.com> Message-ID: "Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message news:7xd61b8uh2.fsf at ruckus.brouhaha.com... > Benjamin Niemann writes: >> import mymodule >> verify_module(mymodule) > > This is no good. The import runs any code in the module, so the sig > has to verify BEFORE the module loads. 'import x' is syntactic sugar for 'x = __import__('x')'. I do not see it as necessary that sugar for the common case need cover every possible case. So, how about giving __import__ had an optional param 'signed' defaulted to False, to allow signed =True or signed = CA? Terry J. Reedy From anthonybaxter at gmail.com Sun Aug 8 09:50:16 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sun, 8 Aug 2004 23:50:16 +1000 Subject: @decorator syntax is sugar, but for what exactly? (decorator libraries). In-Reply-To: References: Message-ID: On Sun, 08 Aug 2004 09:32:21 -0400, Roy Smith wrote: > Anthony Baxter wrote: > Perhaps I'm just a luddite, but I don't actually use most of those > features. I have started playing around with iterators/generators, and > find them very cool. Fair enough. It usually took me a while to start using a new feature, but the ones I listed I find utterly invaluable - to the point where coding against Python 2.1 I find annoying. I'd hate to have to code against Python 1.5.2, now that I'm used to having all the new tools. > The single biggest improvement I see in the language since 1.5.2 is > string methods! After that, maybe augmented assignments (or whatever > you call them; the ability to write "x += 1"). Good points on both - I forgot them in my list, but use them all the time. > Most of the big improvements I've seen are in the library. When did > unitest get added? I can't live without unittest. I like the logging > module, even if I think it's about twice as complicated as it should be. There have been an enormous number of improvements to the stdlib, true, but we're talking about changes to the language in this case. > Speaking of libraries, Dan Bishop posted some interesting example of > @memoize and @printreturns utility wrappers. This leads me to think > that a good way to leverage the idea of decorators would be a module of > common utility functions which could be used as decorators by anybody. > I'll call the module martha (since it supplies things used for > decorating). Does the proposed mechanism support something like (to use > one of Dan's exmaples, written with two different syntaxen): That might happen, but it's unlikely for 2.4. Give people time to use the new tools, find out what works well and not so well, and standardise those. > I'm even wondering if somehow decorators could be used for i18n? The > obvious problem there, is print is a statement not a function, and you > can't decorate statements (or can you???). Huh? You can only decorate function-or-methods. These can contain statements or expressions. And no, you can't decorate lambda. That would be an obscenity wrapped in a heresy and smacked with the ugly stick. Anthony From python-url at phaseit.net Mon Aug 2 08:19:55 2004 From: python-url at phaseit.net (Peter Otten) Date: Mon, 02 Aug 2004 12:19:55 +0000 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 2) Message-ID: QOTW: "We can't really say much more about thread safety than this, we think the interpreter will survive. The rest is up to the programmer." - Donn Cave "Despite the seemingly endless necessity for doing so, it's actually not possible to reverse-engineer intended invariants from staring at thousands of lines of code (not in C, and not in Python code either)." - Tim Peters Marduk wants to use string formatting with an arbitrary iterable instead of a tuple. Hans Nowak posts a format function that fits the bill. http://groups.google.com/groups?selm=40FF1A61.9050408%40zephyrfalcon.org The release of IronPython 0.6, a Python implementation for .Net and Mono, spawns a broader discussion on the merits of .Net and the Common Language Runtime. http://groups.google.com/groups?threadm=278de0e.0407281353.27b6a457%40posting.google.com http://www.ironpython.com Christopher T. King takes a closer look at Yaroslav Bulatov's attempt to benchmark various approaches to sum many floating point numbers. http://groups.google.com/groups?threadm=Pine.LNX.4.44.0408011847510.21160-100000%40ccc4.wpi.edu Premshree Pillai writes an SMS-to-LiveJournal gateway in Python http://www.livejournal.com/users/premshree/33967.html How would you iterate over a list two consecutive items at a time? That's a the heart of jblazi's question, and it turns out that there are two ways to do it. http://groups.google.com/groups?threadm=pan.2004.07.31.12.27.23.547000%40hotmail.com Patrick Rutledge has written an introduction on how to create games using pygame. http://www.linuxjournal.com/article.php?sid=7694 Is Python fully thread-safe? Jeff Epler is poking fun at the questioner, but Francois Pinard (sorry, no cedilla today) points the discussion into a more serious direction. http://groups.google.com/groups?threadm=mailman.775.1090684870.5135.python-list%40python.org "Btw, thank you for those footnotes in Thinking in Java that encouraged me to try Python :-)" - Dan Bishop. Bruce Eckel, author of "Thinking in Java", asks for a test for string similarity. He receives various answers and a thank-you. http://groups.google.com/groups?threadm=mailman.958.1091195562.5135.python-list%40python.org Dan Sugalski has lost the "Pie-thon" bet to Guido van Rossum that Python would run faster on Parrot, the virtual machine meant to power Perl 6. Images of Guido throwing the pie are finally available. http://www.onlamp.com/pub/wlg/5346 http://www.oreillynet.com/pub/a/oscon2004/friday/index.html ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous 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 newsgroup weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Brett Cannon continues the marvelous tradition established by Andrew Kuchling and Michael Hudson of intelligently summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Business Forum "further[s] the interests of companies that base their business on ... Python." http://www.python-in-business.org The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donate.html Cetus collects Python hyperlinks. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://aspn.activestate.com/ASPN/Cookbook/Python Among several Python-oriented RSS/RDF feeds available are http://www.python.org/channews.rdf http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi http://python.de/backend.php For more, see http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. *Py: the Journal of the Python Language* http://www.pyzine.com Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. From roy at panix.com Thu Aug 19 10:28:07 2004 From: roy at panix.com (Roy Smith) Date: Thu, 19 Aug 2004 10:28:07 -0400 Subject: PEP 318: Can't we all just get along? References: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: Anthony Baxter wrote: > > Look, name-mangling is horrid, and I don't think anyone's defending it. But > > at the same time, "name mangling is there" is not an argument for extending > > the horror to a whole new level. Paul Morrow wrote: > I disagree. It's an effective name-hiding technique. Simple + > Effective = Good. I disagree with your disagreement :-) I find a mix of text and puctuation difficult to read. Human brains don't read letters, they read whole words. That's why, for example, it's so easy to make a typo and not notice it. I find "word.word" easy to parse, but "word.__word" much more difficult. I don't know if it's the switching back and forth between letters and symbols, or the juxtaposition of the two symbols down on the baseline (i.e. ".__") that makes it hard to read. This is true of the __name__ convention for internal names too, but somehow I don't find that as bad. Maybe because it's symmetric? Maybe because my brain recognizes the whole __name__ as a unit, with the "name" part of it being what I really recognize? Even worse is when mix them. Stuff like "__myPrivateFunc.__name__" is total gibberish to me. Oh my god, I just realized (Ob decorator comment here) that if we start having people write private decorators, we'll have things like: @__decorator which really makes me barf. From jeffrey at I.slack Mon Aug 9 10:36:00 2004 From: jeffrey at I.slack (Jeffrey Froman) Date: Mon, 09 Aug 2004 07:36:00 -0700 Subject: Apache web server and CGI References: <81a41dd.0408090447.7f27a092@posting.google.com> Message-ID: <10hf2ugjngver5e@corp.supernews.com> Lad wrote: > How can I set up Apache web server to use Python for CGI processing( for > file *.py). Thanks for help A simple method would be to include the line: AddHandler cgi-script .py in your httpd.conf. This should work fine so long as your .py files start with a proper invocation of the python interpreter (i.e., #!/usr/bin/python). You might also want to look at mod_python (http://www.modpython.org/). Jeffrey From jbellis at gmail.com Mon Aug 30 23:55:28 2004 From: jbellis at gmail.com (Jonathan Ellis) Date: 30 Aug 2004 20:55:28 -0700 Subject: Intelisence In-Reply-To: <43SYc.121080$UTP.113615@twister01.bloor.is.net.cable.rogers.com> Message-ID: > Is there any inelisence IDE (like visual studio) for python? There are several; Komodo from ActiveState is IMO the best of the lot. -Jonathan From aahz at pythoncraft.com Fri Aug 20 16:02:57 2004 From: aahz at pythoncraft.com (Aahz) Date: 20 Aug 2004 16:02:57 -0400 Subject: simple Thread question References: Message-ID: In article , Peter Hansen wrote: >Aahz wrote: >> In article , >> Peter Hansen wrote: >>> >>>While it's true that that is all that's needed, it is not required, >>>and doesn't really provide any performance improvements. I often do >>>the above sort of thing where I use a given module in only one place, >>>especially when using threads where it feels subtly cleaner to defer >>>loading of some modules until the thread actually starts. >> >> Except that the import lock makes this a Bad Idea, IMO. > >Does the import lock apply to the first import, or even >to all later ones where it can just find it in sys.modules? It applies to all -- after all, sys.modules gets updated before the module code is run... -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From peter at engcorp.com Mon Aug 16 09:21:46 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 09:21:46 -0400 Subject: Python indentation deters newbies? In-Reply-To: References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: Antoon Pardon wrote: > Op 2004-08-16, Peter Hansen schreef : >>Did you really not indent your code in those languages consisntly >>anyway? > > I can't answer for keith, but my answer is that it depends on > what you consider consistent. > > My indentation was consistent with the structure of the algorithm. > That is not necesarrily the same as the structure you implemeted > that algorithm in. Huh? How does an algorithm have structure that affects indentation? It sounds like you are talking about some kind of artistic considerations here. > I think that I should be the final judge of what is the most > appropiate way to use indentation, not the compilor/interpreter, > even if it agrees with me. So did you indent your code such that consecutive lines were not indented to the same identation level even when they were conceptually, logically, *algorithmically* part of the same block? I know there are such people out there. I even had to fire one once, roughly because he had no concept of how his failure to write his code with anything resembling consistent indentation meant that it was unreadable to others. (At least, that was the surface symptom which warned us of deeper problems.) What I doubt is that many of those people are out there rejecting Python just because it doesn't let them write god-awful unreadable code with artistic or random indentation. -Peter From tim.peters at gmail.com Thu Aug 26 15:15:07 2004 From: tim.peters at gmail.com (Tim Peters) Date: Thu, 26 Aug 2004 15:15:07 -0400 Subject: Missing _sre.pyd in 2.4a2 Windows installer? In-Reply-To: <1xhtg1xm.fsf@pobox.com> References: <1xhtg1xm.fsf@pobox.com> Message-ID: <1f7befae040826121513148c38@mail.gmail.com> [John J. Lee] > The subject line says it, really: I installed 2.4a2 using the MSI > installer on python.org, and I appear to be missing this file: > > C:\Python24\DLLs\_sre.pyd That file doesn't exist in 2.4; the code it used to contain has been folded into the core python24.dll (so _sre is builtin now, instead of an extension module). > As a result, Python picks up the _sre.pyd from my 2.3 installation, That shouldn't be possible, since _sre is a builtin now. > and I get the expected error about a bad magic number in that DLL. > > I think I must be doing something stupid, but what, exactly? Don't know, can't guess. Run Python 2.4 with the -v switch, then do import _sre You should see something like >>> import _sre # C:\Python24\lib\encodings\cp437.pyc matches C:\Python24\lib\encodings\cp437.py import encodings.cp437 # precompiled from C:\Python24\lib\encodings\cp437.pyc import _sre # builtin >>> If you don't see something like that, it's A Clue. From noone at nowhere.com Sun Aug 1 16:32:08 2004 From: noone at nowhere.com (dusty) Date: Sun, 01 Aug 2004 20:32:08 GMT Subject: Noob question on PyQt and Qt References: <5m9qg0ds0g5c0k9tbgukm965au96rud6tm@4ax.com> Message-ID: <5nkqg0t0igc11am041vukkpekta6rn60rs@4ax.com> On Sun, 1 Aug 2004 19:32:10 +0100, Phil Thompson wrote: >On Sunday 01 August 2004 6:42 pm, dusty wrote: >> I am learning Python and Qt designer (using eric3). I'm writing an app >> using QCheckList and have succeeded in loading parent and children, >> with checkboxes, with data from a file. I want to programmatically >> check some boxes depending on the string from the list. >> >> This is the code that I use to create the checkbox's: >> ~~~ >> d = QCheckListItem(it, lstI[g:], QCheckListItem.CheckBox) >> self.childlist1.append(d) >> ~~~ >> The first char in each line in 'lstI' determines if the checkbox >> should be checked or not. >> How do I change the checkbox to 'On' (checked) in Python code when the >> checkbox is created? > >Use the setOn() method. > >Phil Thanks Phil. From http Fri Aug 27 04:14:40 2004 From: http (Paul Rubin) Date: 27 Aug 2004 01:14:40 -0700 Subject: Mysql in Python? References: <1a0o0u8an8yhn$.1aby5k5hmj67d.dlg@40tude.net> Message-ID: <7xsma9gfpr.fsf@ruckus.brouhaha.com> JZ writes: > Using PHP native database functions is a very bad idea. All experencied > programmers use more abstract db wrappers like ADOdb > (http://adodb.sourceforge.net/). Interesting. Every PHP app I've ever seen uses the native functions, but I haven't looked at many fancy ones. > There is no PHP standard templating system. PHP itself is a template > framework! I'm not sure what the distinction is supposed to be? From anthonybaxter at gmail.com Mon Aug 2 03:49:37 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Mon, 2 Aug 2004 17:49:37 +1000 Subject: Call for Grant Proposals In-Reply-To: <41097fed$1@news.unimelb.edu.au> References: <40fcaa90$0$27091$9b622d9e@news.freenet.de> <41097fed$1@news.unimelb.edu.au> Message-ID: On Thu, 29 Jul 2004 22:53:38 GMT, Maurice LING wrote: > I have a few questions to ask about this grant and I've emailed this to > psf-grant at python.org but had no replies yet. Maybe someone authoritative > from PSF can help me out in this or anyone can put in some comments. > 1. Is there a requirement to release the deliverables, including, > software, source codes, specifications and documentation, to the general > public using any of the Open Source Initiative (OSI) approved open > source licences? I'm not on the grants committee, but I'd _expect_ that this would be the case, yes. Will this be a problem? Anthony From __peter__ at web.de Wed Aug 4 02:44:10 2004 From: __peter__ at web.de (Peter Otten) Date: Wed, 04 Aug 2004 08:44:10 +0200 Subject: Overhead of (was Reasoning behind) nested scope References: <10h0kducrd2fod3@news.supernews.com> Message-ID: Nigel Rowe wrote: > Peter Otten wrote: > >> Andy Baker wrote: >> >>> (On a side note is there any way to call a nested function from outside >>> the parent? I was kind of expecting nested functions to be addressable >>> through dot notation like methods are but I can see why that wouldn't be >>> quite right. This might be a better question for the tutor list...) >> >> When you are nesting functions, you don't get one function sitting inside >> another function. Instead, the function creation code of the "inner" >> function is executed every time to the effect that you get a new inner >> function every time you call the outer one: >> >>>>> def make(): >> ... def f(): return "shoobidoo" >> ... return f >> ... >>>>> f1 = make() >>>>> f2 = make() >>>>> f1(), f2() >> ('shoobidoo', 'shoobidoo') >>>>> f1 is f2 >> False >> >> You wouldn't do that in cases like the above, when you get nothing in >> return for the extra overhead, but somtimes nesting is useful - because >> of the change in the scoping rules you now get readonly-closures: >> >>>>> def make(s): >> ... def f(): return s >> ... return f >> ... >>>>> f1 = make("now") >>>>> f2 = make("what") >>>>> f1(), f2() >> ('now', 'what') >> >> Peter > > What work is actually done when the > 'nested function creation code of the "inner" function' > is executed? > > Given a quick test:- > > def outer(): > def inner(): > pass > return inner > > b1 = outer() > b2 = outer() > > attrs=[a for a in dir(b1) if not a.startswith('_')] > for a, a1, a2 in zip(attrs, > [getattr(b1,a) for a in attrs], > [getattr(b2,a) for a in attrs]): > print a, a1 is a2 > > > > func_closure True > func_code True > func_defaults True > func_dict True > func_doc True > func_globals True > func_name True > > > it appears that all the components of the inner function are the same, > which just leaves the binding of the code object to 'inner'. Not the binding, a new function object is created every time outer is run, i. e. (faked, but I did it for real above with f1 and f2) >>> b1 is b2 False > Am I missing something, or is the overhead no worse than, say, > foo=self.foo, where self.foo is a method? If it were pure Python it would rather be something like foo = Function(func_closure=..., func_code=..., ...) Another perspective is to look at the byte code: >>> import dis >>> def outer(): ... def inner(): pass ... return inner ... >>> dis.dis(outer) 2 0 LOAD_CONST 1 (", line 2>) 3 MAKE_FUNCTION 0 6 STORE_FAST 0 (inner) 3 9 LOAD_FAST 0 (inner) 12 RETURN_VALUE 13 LOAD_CONST 0 (None) 16 RETURN_VALUE >>> def inner(): ... pass ... >>> def outer2(): ... return inner ... >>> dis.dis(outer2) 2 0 LOAD_GLOBAL 0 (inner) 3 RETURN_VALUE 4 LOAD_CONST 0 (None) 7 RETURN_VALUE In the example you get three extra instructions, LOAD_CONST, MAKE_FUNCTION and STORE_FAST (and earn the slight benefit that inner is now a local instead of a global). A constant code object is used, meaning compilation takes place at most once when the module is loaded. There is a dedicated op-code, so function creation should be faster than "normal" creation of a class instance. Now this is all nice and dandy, but how do the two contenders perform? $ timeit.py -s"def inner(): pass" -s"def outer(): return inner" "outer()" 1000000 loops, best of 3: 0.469 usec per loop $ timeit.py -s"def outer():" -s" def inner(): pass" -s" return inner" "outer()" 1000000 loops, best of 3: 1.12 usec per loop i. e. nesting the two functions roughly doubles execution time. However, creation of an inner function often will only take a small fraction of the total time spent in the outer function - in the end it's just a matter of style. I use inner functions only when they depend on the local context because I think it nicely discriminates closures from helpers. I tend to omit implicit parameters even for helper funtions, therefore nesting them would gain me nothing. Peter From nhodgson at bigpond.net.au Fri Aug 20 18:26:23 2004 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Fri, 20 Aug 2004 22:26:23 GMT Subject: Decorator keyword options - brainstorming References: <7knVc.4599$Jn5.3074@fe1.texas.rr.com> Message-ID: Michael Sparks: > Whilst many decorators can be alluded to as a keyword, I don't think all > decorators would be. Consider how you would describe the actions of > this list, or how you would describe this list of actions: (taken from > various sources) > > staticmethod > generator > grammarrule('statement : expression') > versioninfo("Added in 2.4") > deprecated > typeinfo(None) > author("joe bloggs") > funcattrs(grammar="'@' dotted_name [ '(' [arglist] ')' ]", > status="experimental", author="BDFL") Declarations? declare: staticmethod versioninfo("Added in 2.4") deprecated def cheeseSketch(): Neil From grante at visi.com Mon Aug 2 15:28:36 2004 From: grante at visi.com (Grant Edwards) Date: 02 Aug 2004 19:28:36 GMT Subject: Python executable on Windows References: <410e91ce$0$58816$5a6aecb4@news.aaisp.net.uk> <410e93a1$0$58815$5a6aecb4@news.aaisp.net.uk> Message-ID: <410e95e4$0$65605$a1866201@newsreader.visi.com> On 2004-08-02, Simon Faulkner wrote: >> Is it possible to write a program and add the Python >> interpreter so that I just end up with a single .exe file for >> windows? > I guess py2exe as in the thread above! Doh... It doesn't produce a single .exe file. It produces a directory of files that need to be installed (one of which is an .exe). > Is it easy? Yes. http://starship.python.net/crew/theller/py2exe/ -- Grant Edwards grante Yow! Spreading peanut at butter reminds me of visi.com opera!! I wonder why? From jdc at uwo.ca Mon Aug 2 21:01:58 2004 From: jdc at uwo.ca (Dan Christensen) Date: Mon, 02 Aug 2004 21:01:58 -0400 Subject: transforming a list into a string References: Message-ID: <87wu0h5915.fsf@uwo.ca> Tim Peters writes: > The only thing required of __iter__ is that it return an object that > supports the iteration protocol (meaning an object that supports > next() and __iter__() methods). So again, adding the ability to > slice too would mean requiring more of __iter__ methods -- or > changing the implementation of iter() to ignore __iter__ methods and > make something up itself. It's A Visible Change no matter how you > cut it. What if object[a:b:c] did the following? 1) if __getslice__ is supplied by object, use it. 2) if __getitem__ is supplied, use it. 3) if __iter__ is supplied, use islice(__iter__(object),slice(a,b,c)). (IIUC, 1) and 2) are what is done currently. As Christopher pointed out, for 3) to work, islice would have to modified to accept a slice.) Would this be backward compatible (a "Visible Change"), or would it break something? It seems to parallel other dispatching mechanisms, e.g. (IIUC) "in" is implemented just using the iterator protocol, unless the object supplies __contains__. I like the idea of not needing to know about islice, and just using the [a:b:c] notation. One of python's strongest features is its consistency of notation. Dan From specmark at aol.com Tue Aug 10 10:52:19 2004 From: specmark at aol.com (expecthealth) Date: Tue, 10 Aug 2004 14:52:19 -0000 Subject: ORACLE DBA -- Western Suburbs of Chicago Message-ID: OPERATIONAL ORACLE DBA Position Description: This position will report to the Manager of Systems Services. The DBA will work in the Oracle environment and help manage a complex production and development environment. This person will interact with many constituencies to develop database solutions to business problems. This person will assist Development DBAs with the design of tables, relationships, stored procedures and triggers. This person will work independently to ensure that the database is operating efficiently and to ensure that proper backup and disaster recovery methods are maintained. Position Qualifications: q Bachelor's Degree in Computer Science, or equivalent. q Minimum of 5 years' experience in database administration or development, with a minimum of 3 years' of Oracle DBA experience. q Experience in Oracle 11i Applications (ERP, CRM, etc.) q Experience in Oracle Portal environment a plus. q Experience with Oracle Discoverer. q Experience with OID and LDAP. Active Director integration experience a plus. q Proven track record in managing and tuning large volume Oracle databases. q Experience in UNIX environment required ? SUN SOLARIS preferred. q Excellent communications skills. q Experience with backup, recovery, and disaster recovery process/scenarios. Position Characteristics: q Plan and coordinate the activities related to running production Oracle Applications environments. q Plan and coordinate the development, test and training environments in support of the production environment. q Plan and design database physical structure to accommodate large transaction and high availability. q Perform database and application monitoring and tuning to ensure databases run at peak performance. Troubleshooting of performance issues. q Assist in the design and implementation of security policy. q Work with development DBA (Database Developer) to implement the logical database design in physical environment. Provide solutions for database sizing/capacity, server requirements and space requirements. q Work with Operation group to design, implement and test enterprise backup and recovery solution, including Disaster Recovery initiatives. q Work with the Systems and Networks groups to implement/integrate OID with Active Directory, LDAP and/or DHCP solutions. q Work with the Networks and Systems groups to ensure the platforms are robust enough to support the needs of the database. q Review new database programs, functions, procedures, and packages before they are loaded to production database. q Install, configure, trouble-shoot Oracle/SQL database and Oracle Application system (including Portal, Single-Signon, Discoverer and third party application system) in all servers. Upgrade/Patching database and system based on Development/Operations request. q Support data loading, conversion and batch job operation and do trouble-shooting of development/production system. q Do database sizing, capacity planning and implement system security. SALARY RANGE: $90's. Please forward your resume / c.v. : Bil Norris Diamond Consulting Inc. 630-586-0000 x19 specmark at aol.com From sheldonplankton at yahoo.com Thu Aug 26 16:17:28 2004 From: sheldonplankton at yahoo.com (Sheldon Plankton) Date: Thu, 26 Aug 2004 13:17:28 -0700 (PDT) Subject: Can't install Python 2.3 on RedHat 9 Message-ID: <20040826201728.57833.qmail@web53502.mail.yahoo.com> Hi, I want to eventually install plone which requires that I install python2.3. So I go to http://www.python.org/2.3.4/rpms.html and since I need RPM's for RH9 and not Fedora Core 1 I download python2.3-2.3.4-3pydotorg.src.rpm and do this ... # rpmbuild --rebuild python2.3-2.3.4-3pydotorg.src.rpm Installing python2.3-2.3.4-3pydotorg.src.rpm warning: user jafo does not exist - using root warning: group jafo does not exist - using root warning: user jafo does not exist - using root warning: group jafo does not exist - using root warning: user jafo does not exist - using root warning: group jafo does not exist - using root Where rpmbuild appears to hang. :confused: What's up with that? Is this a slow process? How long should I wait before I ^C it? Thanks _______________________________ Do you Yahoo!? Win 1 of 4,000 free domain names from Yahoo! Enter now. http://promotions.yahoo.com/goldrush From http Thu Aug 19 13:06:58 2004 From: http (Paul Rubin) Date: 19 Aug 2004 10:06:58 -0700 Subject: Embedding Python in Python References: <7xu0v0l2be.fsf@ruckus.brouhaha.com> <7x3c2kkzn8.fsf@ruckus.brouhaha.com> <7x7jrwt8gc.fsf@ruckus.brouhaha.com> Message-ID: <7x657fcb0t.fsf@ruckus.brouhaha.com> JCM writes: > It's fine to look at it that way. Start with a subset of Python that > you know to be safe, for example only integer literal expressions. > Keep adding more safe features until you're satisfied with the > expressiveness of your subset. Well ok, but then you haven't got Python, you've got some subset, with a completely different implementation than the Python that it's embedded in. From alan.gauld at btinternet.com Sat Aug 21 14:38:59 2004 From: alan.gauld at btinternet.com (Alan Gauld) Date: Sat, 21 Aug 2004 18:38:59 GMT Subject: age of Python programmers References: <41245e57$0$29668$636a15ce@news.free.fr> Message-ID: > Lucas Raab wrote: > > One thing I've always kind of wondered is what is the average age of a > > Python programmer?? What age groups use Python?? Something to think > > about.... OK, I'll play... I'm 46, started programming in 74 in BASIC (dunno what machine, it was located at the local university and we downloaded the programs from a teletype over a modem(120 baud) and got back printouts 3 days later...) Next I encountered the Sinclair ZX81 in 1981 (Timex in the USA) where I wrote my first stock control application for a friend's business! In 1982 I started entering patches to a Marconi Telex switch in Coral via a BBC Micro running a terminal emulator. I only realised that later, I actually thought I was programming the BBC at the time!! :-) Then in 1984 I got formal training in Pascal, Assembler, C, Lisp and Smalltalk. I've been a software engineer ever since and came across Python in 1997 when a colleague pointed me at it after I complained about the Perl syntax I was using to write a CGI script. I now use Python mainly for prototyping design ideas and exploring the interfaces of our networked server applications before writing specs for our offshore programmers to write in C++ or Java. Alan G. Author of the Learn to Program website http://www.freenetpages.co.uk/hp/alan.gauld From peter at engcorp.com Tue Aug 3 21:49:20 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 03 Aug 2004 21:49:20 -0400 Subject: asyncore, asynchat and threads In-Reply-To: References: Message-ID: <7cKdnShvevY_3Y3cRVn-iA@powergate.ca> Joshua Moore-Oliva wrote: > However, I must use a separate thread for each connection as the work > resulting from the communication can result in blocking for an indefinate > period of time. ... > even any pointers, help, ideas on how to make something like this work > would be greatly appreciated as well. The usual approach is to use something along the lines of a separate thread for the *work* rather than for the connection, or maybe a thread pool, and communicate with those threads from the asynchat thingies using Queue.Queues... I'm not sure we have enough information about what you really need to say more. You've given lots of info about what you "would love to do" but not enough about what you actually need to do. -Peter From ptmcg at austin.rr._bogus_.com Fri Aug 6 06:35:33 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 06 Aug 2004 10:35:33 GMT Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) References: <338366A6D2E2CA4C9DAEAE652E12A1DE01C8C636@au3010avexu1.global.avaya.com> Message-ID: > I'm not saying that this isn't possible, more that merely collecting a concensus > vote isn't likely to do much. Strong technical arguments are much more likely > to work. It seems that citing constructs in other languages as precedent counts for something. One of GvR's objections is that the list-after-def comes after the argument list, presumably reversing the order of importance of the list. Conceptually, I think he sees these decorators as attributes of the function itself, ahead of the arguments, which are a level down from the function def. However, this is exactly like the 'const' qualifier in C++, which comes at the end of the function declaration, or the 'raises' clause in IDL or 'throws' in Java. Just because these come at the end of the decl doesn't imply they are in any way 'inferior' to the argument list. (And they accomplish this without needing any special punctuation marks!) -- Paul Keep Python Beautiful. From jaydonnell at yahoo.com Mon Aug 23 18:16:10 2004 From: jaydonnell at yahoo.com (Jay Donnell) Date: 23 Aug 2004 15:16:10 -0700 Subject: urllib hangs References: Message-ID: Thanks, but I'm on python 2.2 and don't have the ability to upgrade it on the server. How would I do this in 2.2? > since 2.3 there's socket.setdefaulttimeout(), this should to the job: > > import socket > socket.setdefaulttimeout(10) > # throw socket.timeout exception after 10s, > # default is to wait a infinitly (or at least a very, very long time...) > > For older python versions, ask google for timeoutsocket.py From steven.bethard at gmail.com Wed Aug 11 20:37:51 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: 11 Aug 2004 17:37:51 -0700 Subject: wiki update: decorator syntax breakdown Message-ID: Just wanted to let everyone know that I went through the wiki and tried to consolidate some of the advantages/disadvantages of the various syntax decisions: http://www.python.org/cgi-bin/moinmoin/PythonDecorators (section 7) Hopefully I've extracted most of the important points from the various example syntaxes. Steve From skip at pobox.com Fri Aug 6 11:57:39 2004 From: skip at pobox.com (Skip Montanaro) Date: Fri, 6 Aug 2004 10:57:39 -0500 Subject: [Newby question] List comprehension In-Reply-To: References: Message-ID: <16659.43635.246128.392807@montanaro.dyndns.org> Eelco> # song filter: will return true if the file seems to be an mp3 file. Eelco> # (may not be the best way to do this) Eelco> def song(f): Eelco> (name, ext) = os.path.splitext(f) Eelco> return ext.lower() == '.mp3' Eelco> # list comprehension walking through a directory tree Eelco> [(root, filter(song, files)) for (root, dir, files) in os.walk(os.path.abspath('.')) if filter(song, files)] In this particular case, since song() only returns True or False, you could use [(root, True) for (root, dir, files) in os.walk(os.path.abspath('.')) if filter(song, files)] Skip From npat at efault.net Mon Aug 16 14:59:53 2004 From: npat at efault.net (Nick Patavalis) Date: Mon, 16 Aug 2004 18:59:53 +0000 (UTC) Subject: Generators versus Coroutines References: <7x7js1i887.fsf@ruckus.brouhaha.com> Message-ID: On 2004-08-16, Bernhard Mulder wrote: > If you want, you can yield across multiple levels by converting > functions into generators and calls into for loops. > Or while loops, if you don't know a-priori how many times you have to call the generator. Yes this is possible, but unmaintainable (makes the code impossibly tangled) to the point of been useless. The problem with this specific approach if of-course that Python has no macros, so you can't hide it somehow; it has to be repeated in the code *every* *time*; this makes makes the code impossible to read. /npat From tiarno at sas.com Mon Aug 16 07:45:53 2004 From: tiarno at sas.com (Tim Arnold) Date: Mon, 16 Aug 2004 07:45:53 -0400 Subject: xml question References: Message-ID: "Ajay" wrote in message news:mailman.1651.1092488767.5135.python-list at python.org... > str = whiteSpaces[counter].nodeValue > string.strip(str) > however this isn't working. when i print out all the elements in the > document, i still get the whitespace text elements. shouldn't str.strip() work instead? --T From jepler at unpythonic.net Sat Aug 21 09:05:31 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Sat, 21 Aug 2004 08:05:31 -0500 Subject: Files in unix and windows In-Reply-To: References: Message-ID: <20040821130531.GB1458@unpythonic.net> Which extra (back)slashes do you mean? Do you mean that os.path.abspath strips the trailing separator characters from its argument? >>> os.path.abspath("../../../../etc/") '/etc' >>> os.path.normpath("./") '.' This behavior doesn't seem to be specifically documented. If preserving the trailing '/' when present is important, you can easily get this behavior using os.path.abspath: def myabspath(p): hadsep = p and p[-1] in (os.sep, os.altsep) p = os.path.abspath(p) if hadsep: p = p + os.sep return p >>> myabspath('../../../../../etc/') '/etc/' >>> myabspath('../../../../../etc') '/etc' Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From alan.gauld at btinternet.com Sun Aug 29 12:53:43 2004 From: alan.gauld at btinternet.com (Alan Gauld) Date: Sun, 29 Aug 2004 16:53:43 GMT Subject: A question?? References: <938a4680.0408252138.1580ac93@posting.google.com> Message-ID: On 25 Aug 2004 22:38:06 -0700, rattan at cps.cmich.edu (Ishwar Rattan) wrote: > def run(program, *args): > pid = os.fork() > if not pid: > os.execvp(program, (program,)+args) > What is the interpretation of *args (in def run(..)? > Looks like a reference to me, so, how does one decide when to use > a reference or not? Its not a reference its a placeholder for an unspecified number of arguments. (Actually I think it's technically a tuple of arguments?) You can think of it like the C va_arg construct used for functions like printf(). There is also a **args construct which is for a dictionary of keyword arguments. I'm no expert on these but thats what they are about. Here is the url to the documentation: http://docs.python.org/ref/function.html HTH, Alan G. Author of the Learn to Program website http://www.freenetpages.co.uk/hp/alan.gauld From ptmcg at austin.rr._bogus_.com Wed Aug 11 14:55:34 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Wed, 11 Aug 2004 18:55:34 GMT Subject: Capturing repeating group matches in regular expressions References: Message-ID: It's a bit wordy, but perhaps the ability to easily structure and retrieve your returned tokens may sway you. Download pyparsing at http://pyparsing.sourceforge.net -- Paul from pyparsing import Word,OneOrMore # define parse grammar lowers = "abcdefghijklmnopqrstuvwxyz" endsWithW = Word(lowers,"W",exact=2) endsWithX = Word(lowers,"X",exact=2) endsWithY = Word(lowers,"Y",exact=2) patt = endsWithW.setResultsName("W") + \ OneOrMore( endsWithX ).setResultsName("X") + \ endsWithY.setResultsName("Y") # extract tokens from input string tokens = patt.parseString("aWbXcXdXeXfY") # tokens can be accessed as a list print "tokens:",tokens # tokens can be coerced to be a true list print "tokens.asList():",tokens.asList() # tokens can be a dictionary, if results names specified print "tokens.keys():",tokens.keys() print "tokens['W']:",tokens['W'] print "tokens['X']:",tokens['X'] print "tokens['Y']:",tokens['Y'] # if results names are valid attribute names, can even look like attribute print "tokens.W:",tokens.W print "tokens.X:",tokens.X print "tokens.Y:",tokens.Y Gives: tokens: ['aW', 'bX', 'cX', 'dX', 'eX', 'fY'] tokens.asList(): ['aW', 'bX', 'cX', 'dX', 'eX', 'fY'] tokens.keys(): ['Y', 'X', 'W'] tokens['W']: aW tokens['X']: ['bX', 'cX', 'dX', 'eX'] tokens['Y']: fY tokens.W: aW tokens.X: ['bX', 'cX', 'dX', 'eX'] tokens.Y: fY From pruebauno at latinmail.com Tue Aug 31 17:22:31 2004 From: pruebauno at latinmail.com (nnes) Date: 31 Aug 2004 14:22:31 -0700 Subject: age of Python programmers References: <889cbba0.0408181206.1812881c@posting.google.com> Message-ID: JanC wrote in message news:... > Gerardo Herzig -Departamento de Proyectos Especiales e Internet- Facultad > de Medicina schreef: > > > 30 years old. First program at 11 (Basic) on ZX Spectrum. > > /me too (now 30 & started with ZX Spectrum Basic at 11) count another one, me too now 30 years, started with ZX Spectrum Basic at 11 From dalcolmo at vh-s.de Wed Aug 4 03:35:08 2004 From: dalcolmo at vh-s.de (Josef Dalcolmo) Date: Wed, 4 Aug 2004 09:35:08 +0200 Subject: converting to string References: Message-ID: <20040804093508.0000481f@titan> on Wed, 04 Aug 2004 17:03:10 +1000 Ajay Brar wrote: > how do i go about converting a Python object or tuple to a string. I guess the simplest is to use the built-in functions: str or repr str(object) if you just need a printable string repr(object) if you need to reconstruct later the original object from the string - Josef From jeff at ccvcorp.com Mon Aug 16 16:09:49 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Mon, 16 Aug 2004 13:09:49 -0700 Subject: passing globals to imported module In-Reply-To: References: Message-ID: <10i252tsvv2lda4@corp.supernews.com> James Tauber wrote: >Had a question from a colleague that I embarrassingly couldn't answer. > >He has a script, foo.py with a global. He wants to import bar.py and >needs that global available in bar.py > > > #### global.py my_global = "Hello!" #### foo.py import global, bar print global.my_global #### bar.py import global print global.my_global ;) Jeff Shannon Technician/Programmer Credit International From mwilson at the-wire.com Tue Aug 3 09:45:04 2004 From: mwilson at the-wire.com (Mel Wilson) Date: Tue, 03 Aug 2004 09:45:04 -0400 Subject: Reasoning behind nested scope References: Message-ID: In article , "Andy Baker" wrote: >"This is because nested function definitions don't have access to the >local variables of the surrounding block -- only to the globals of the >containing module. This is done so that lookup of globals doesn't >have to walk a chain of dictionaries -- as in C, there are just two >nested scopes: locals and globals (and beyond this, built-ins). >Therefore, nested functions have only a limited use. This was a >deliberate decision, based upon experience with languages allowing >arbitraries nesting such as Pascal and both Algols -- code with too >many nested scopes is about as readable as code with too many GOTOs. >And, of course, in Python, the "proper" way is to use an >object-oriented programming style" > >This sounds reasonable to me although nested scope always struck me as more >natural and intuitive ('Don't be surprising') > >I was wondering how the balance changed in favour of nested scope? What >changed people's minds about 'readability' vs other factors? Are nested >scopes still regarded as leading to spagetti code etc? I guess a consensus built up that the power/safety tradeoff had given too much emphasis to safety. My own poster child for nested scopes is in some old post on c.l.p . I wanted to build a lot of similar labelled text controls in wxPython, following a naming convention. I could have written a function, but pre-nested-scope, any change I made to the information used in building the controls would have meant changing the function parameter list, and all the function calls. I came up with a template string which got parameter substituted via the '%' operator, and then `exec`ed so as code it had full access to all the info that was in the contemporary scope. Post nested scope, any info the function needed from the surrounding scope could simply be read from there. The code was much less unusual. I believe (without proof) that any language that won't let me shoot myself in the foot will also prevent me doing anything useful. Debate is heating up now about write access to enclosing scopes. We'll see how strong my faith really is. People will be able to write function nests instead of classes. >(On a side note is there any way to call a nested function from outside the >parent? I was kind of expecting nested functions to be addressable through >dot notation like methods are but I can see why that wouldn't be quite >right. This might be a better question for the tutor list...) Yup. def f1 (a): if a: x = 2 else: x = 3 def f2 (y): return y % x return f2 import os b = f1 (os.name.startswith ('p')) for c in range (10): print b (c) Regards. Mel. From peter at semantico.com Thu Aug 19 04:40:47 2004 From: peter at semantico.com (Peter Hickman) Date: Thu, 19 Aug 2004 09:40:47 +0100 Subject: age of Python programmers In-Reply-To: References: <2ohr0nFakl4sU1@uni-berlin.de> Message-ID: <41246790$0$1258$afc38c87@news.easynet.co.uk> Berthold H?llmann wrote: > Programming since more than 20 Years. UCSD Pascal on Apple //e and > //c, FORTRAN, C, C++ and Python since more than 76 Years. UCSD Pascal, ah that is a memory. The reason I never thought Java was such a big deal was my exposure to UCSD, a whole OS as a VM (if my memory serves)! From giva at users.sourceforge.net Tue Aug 17 14:29:55 2004 From: giva at users.sourceforge.net (Gisle Vanem) Date: Tue, 17 Aug 2004 20:29:55 +0200 Subject: Swing/Metalworks for Python Message-ID: <41224ea4$1@news.broadpark.no> I was quite impressed by this toolkit in the latest Java SDK 1.5 (not sure if it's new in this version or not). But are there any similar toolkits for Python that allows switching Look & Feel and Themes in the same way? --gv From peter at engcorp.com Tue Aug 17 20:47:36 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 17 Aug 2004 20:47:36 -0400 Subject: strange problem with def in class In-Reply-To: <1092788477.995526@seven.kulnet.kuleuven.ac.be> References: <1092788477.995526@seven.kulnet.kuleuven.ac.be> Message-ID: Johan wrote: > I don't get it: > I'm trying to write a "readfile" function which would replace some code from [snip] > but I can't define this function.... when I call the function the > interpreter throws an exception of unknown function > what am I doing wrong? Not posting the actual traceback including the real error that you are getting. It will include the lines of source that were involved and will help us help you... -Peter From mike1 at tumladen.net Wed Aug 11 09:51:11 2004 From: mike1 at tumladen.net (Mike Greaves) Date: 11 Aug 2004 06:51:11 -0700 Subject: class in IronPython? References: <316f1dc0.0408110240.4c83fb42@posting.google.com> Message-ID: <316f1dc0.0408110551.77c5befe@posting.google.com> Duncan Booth wrote in message news:... > I think you will find that classes don't (yet) work in interactive mode. > Try putting the class in a .py file and using that. Thanks. I *was* trying to debug a .py file in the first place... by trying snippets of it interactively... Then I failed to realize that I was getting a *different* exception in interactive mode... Mike Greaves From Scott.Daniels at Acm.Org Sun Aug 29 00:01:13 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sat, 28 Aug 2004 21:01:13 -0700 Subject: my first class: Args In-Reply-To: References: <4130cf9d@nntp0.pdx.net> Message-ID: <41315680$1@nntp0.pdx.net> Peter Kleiweg wrote: ... > This is the only instance I didn't follow your recommendation to > use try/except. It is a binary choice: do we use files given on > the command line or stdin? Neither is more natural than the > other. Also, it splits up lines of code that belong together. > > Here is my re-write: > > def __iter__(self): > "iterator: set-up" > if self._argv: > self.infile = self._argv.pop(0) > self._in = open(self.infile, 'r') > self._stdin = False > else: > if sys.stdin.isatty(): > self.usage() # Doesn't return > self.infile = '' > self._in = sys.stdin > self._stdin = True > return self > > The exceptional case is there be no input, and the simplest test > here seems to be a simple if-statement. Perfectly fine. I probably lean on the "don't look before you leap" a bit too heavily. Remember, writing code is like writing in your native language; it is more important to be clear than to match a style. Notice that you have a bit more structure now than originally. A single top-level conditional is simpler to read; less needs to be read to understand what is going on. >>def demo(): >> ... >> >>if __name__ == '__main__': >> demo() > That doesn't seem very useful. It depends on command line > arguments. If they are missing, it does a sys.exit(), probably > not what you want unless you run the module stand-alone. I missed the sys.argv -- here is a sketch of a slightly better rewrite: > class Args: > """...""" > def __init__(self,usage='Usage: %(progname)s [opt...] [file...]'): > "init, usage string: embed program name as %(progname)s" > self.progname = os.path.basename(sys.argv[0]) > ... > self._argv = sys.argv[1:] class Args: """...""" def __init__(self, progname, args, usage='Usage: %(progname)s [opt...] [file...]'): "usage string: embed program name as %(progname)s" self.progname = progname self._argv = args ... > if __name__ == '__main__': > ... def demo(progname, args): a = Args(progname, args, 'Usage: %(progname)s [-a value] [-b value] [-c] word [file...]') ... if __name__ == '__main__': demo(sys.argv[0], sys.argv[1:]) --- In idle, the exit can be stopped (so it is not a huge worry). If nothing else you can do: try: demo('name', ['abc', 'def']} except SystemExit: pass Cutting into sys.argv is, however, a bit tougher usually. -Scott David Daniels Scott.Daniels at Acm.Org From adurdin at gmail.com Fri Aug 6 01:04:01 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Fri, 6 Aug 2004 15:04:01 +1000 Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) In-Reply-To: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> References: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> Message-ID: <59e9fd3a0408052204197cd056@mail.gmail.com> On Thu, 05 Aug 2004 22:39:19 -0400, Istvan Albert wrote: > > Ladies and Gents, start your engines and rally around > this syntax (if you prefer it of course) so that there > is evidence that it should be taken as a serious candidate. +1 I greatly prefer it over the @ syntax. From squirrel at WPI.EDU Fri Aug 13 09:22:38 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Fri, 13 Aug 2004 09:22:38 -0400 Subject: multiline snippets with triple quotes In-Reply-To: References: Message-ID: On Thu, 12 Aug 2004, gohaku wrote: > Can dedent capture indents or tabs also... > I noticed that if I do the following: > snip = '''blah blah > ''' > Tabs are included with snip. dedent() will return that string as is, since the tag is already in the left-most position. If you do something like this, however: snip = '''\ blah blah ''' dedent() will flush the tag left, and the tag will be indented by one tab (since it has a one-tab indent relative to ). > Is there a heredocs (don't know why it's called that) equivalent in > Python? AFAIK, triple quotes do everything heredocs do (but with a cleaner syntax!); the following produce identical output: bash heredocs: echo -n < I'm 29; used python for last two years. From otto.wyss at orpatec.ch Thu Aug 26 17:01:46 2004 From: otto.wyss at orpatec.ch (Otto Wyss) Date: Thu, 26 Aug 2004 23:01:46 +0200 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <2a56f6a3.0408252257.4f1f92e@posting.google.com> <2p5j10FesankU1@uni-berlin.de> Message-ID: <1gj4z06.14nwnzs1d0kno4N%otto.wyss@orpatec.ch> Tassilo v. Parseval wrote: > It would, if anyone could take Xah Lee Loo seriously. But really, no one > can. He's more like the court jester, creeping out of the dark every so > and so months. We're all very much enjoying his sporadic shows. Really. > > ;-) > No offense but could you add some references so anyone can make up is own opinion? O. Wyss -- How to enhance your code, see "http://freshmeat.net/projects/wxguide/" From justin__devine at hotmail.com Wed Aug 25 12:20:06 2004 From: justin__devine at hotmail.com (Justin) Date: 25 Aug 2004 09:20:06 -0700 Subject: Desperately needing Help with 2 features of a program In-Reply-To: Message-ID: Well, I think looking at the source is key in this case because my problems are with encapsulation, so the class structure of the source would need to be seen. Diez B. Roggisch wrote: > Hi, > > > Asking people to download your program and simply add features is a little > bit too much I fear.... > > Read this: > > http://www.catb.org/~esr/faqs/smart-questions.html > > And then post why and where your concrete attempts fail. Thats much more > likely to get answers. > > -- > Regards, > > Diez B. Roggisch From goden at simplified.com Thu Aug 19 23:25:23 2004 From: goden at simplified.com (Eugene Oden) Date: Fri, 20 Aug 2004 03:25:23 GMT Subject: Rita Sue and Bob too References: Message-ID: M. Clift wrote: > Hi All, > > Can someone help. I promise I've looked how to do this but can't find a > way... > > Ok, to find one name is easy > > if 'Bob' in list: > print "They were found" > else: > print "They are not in list" > > But, how to I find a sequence in a list of unknown size? i.e. this > sequence in list of other names and replace it with three others? > > 'Rita','Sue','Bob' > > This is almost a nightly occurrence (my posting questions), but I am > learning : ) here's my stab at it: def findSequence(seq, search): """returns the index where search can be found in seq where search and seq are both sequences. """ searchLength = len(search) for i in range(len(seq)-searchLength+1): compare = seq[i:i+searchLength+1] if search == seq[i:i+searchLength]: return i raise ValueError, 'sequence %s is not in list' % str(search) someList = ['Joe', 'Rita', 'Sue', 'Bob', 'Peter'] searchList = ['Rita', 'Sue', 'Bob'] i = findSequence(someList, searchList) someList[i:i+len(searchList)] = ['Paul', 'John', 'James'] # someList is now ['Joe', 'Paul', 'John', 'James', 'Peter'] findSequence(someList, searchList) # raises ValueError From ajsiegel at optonline.com Tue Aug 10 23:46:43 2004 From: ajsiegel at optonline.com (Arthur) Date: Wed, 11 Aug 2004 03:46:43 GMT Subject: @decorator syntax is sugar, but for what exactly? (decorator libraries). References: Message-ID: > >Yes (using a class instead of a module simply for convenience): > > class martha: > memo = {} > > @staticmethod > def memoize(func): > if func not in martha.memo: > martha.memo[func] = {} > def _inner(*args, **kwds): > items = kwds.items() > items.sort() > items = tuple(items) > key = (args, items) > try: > val = martha.memo[key] > except KeyError: > val = func(*args, **kwds) > martha.memo[key] = val > return val > return _inner > > @martha.memoize > def fib(n): > assert n >= 0 > print n > if n <= 1: > return 1 > return n + fib(n-1) > > print fib(5) > print fib(4) > >Running that yields this output: > > 5 > 4 > 3 > 2 > 1 > 15 > 10 > >Skip Is it me, or this a chilling argument agaisnt where things are going. I understand it is illustrative, and nobdy is advertiging it as anything else. But when there is a lot less going on than meets the eye ... not good. Art From tim.leslie at gmail.com Sun Aug 22 23:01:44 2004 From: tim.leslie at gmail.com (Tim Leslie) Date: Mon, 23 Aug 2004 13:01:44 +1000 Subject: Logical lines of code counter In-Reply-To: <2ot090Fe5442U1@uni-berlin.de> References: <2ot090Fe5442U1@uni-berlin.de> Message-ID: If you want something which can do this and so much more, have a look at pylint. http://www.logilab.org/projects/pylint Cheers, Tim On Sun, 22 Aug 2004 21:44:17 -0400, Leif K-Brooks wrote: > I got bored with working on larger projects and wrote a little > script/module for counting logical (not physical) lines of Python code > in a file or directory. It uses ASTs generated by compiler.parse instead > of text manipulation functions, so it isn't incredibly fast, but the > speed is good enough to be usable for me. > > If you want to take a look, the file is at > . I don't really care about how > people license their modifications (and the GPL is longer than the > script itself), so it's licensed under the MIT License. > > I'm sure there are a few bugs (AST nodes I forgot to count?), and I'd > appreciate being emailed if anyone finds one. > -- > http://mail.python.org/mailman/listinfo/python-list > From wweston at att.net Mon Aug 9 12:25:07 2004 From: wweston at att.net (wes weston) Date: Mon, 09 Aug 2004 16:25:07 GMT Subject: berkeley db delete problem? In-Reply-To: References: Message-ID: Oliver Peek wrote: > Hi all, > > Probably my fault, I'm opening a Berkeley DB > file, iterating through and deleting keys, well > making an attempt. I get this error when I try > to delete. > > ---error > Traceback (most recent call last): > File "./db.py", line 41, in ? > db.delete() > AttributeError: delete > ---end error > > Below is a code snippet: > ---code > #!/usr/bin/python > > import bsddb > > db = bsddb.btopen('./test.db', 'r') > > rec = db.first() > while rec: > key, val = rec > db.delete() > rec = db.next() > > db.close() > ---end code > > I have full code that opens and goes through and > prints the key and value and opens another db > file and inserts the key/data into that new db > file, but I need to delete the data out of the > master db file once it's been updated in the > smaller ones. > > I've also tried db.delete(key) with no luck, > db.del(), db.del(key), db[key]='', and lots of > other silly attempts, but nothing works. > > Thanks, > Oliver > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com Oliver, How bout del db[key] wes From in.aqua.scribis at nl.invalid Sun Aug 29 06:58:57 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Sun, 29 Aug 2004 12:58:57 +0200 Subject: regex into str In-Reply-To: References: Message-ID: Jeremy Bowers schreef: > On Sun, 29 Aug 2004 04:08:57 +0200, Peter Kleiweg wrote: > > This works: > > > > a += 'x' > > In the sense you mean, no it doesn't. I mean in the sense it does, and in that sense it does. > > Python 2.3.4 (#1, Jun 8 2004, 17:41:43) > [GCC 3.3.3 20040217 (Gentoo Linux 3.3.3, propolice-3.3-7)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> a = 'a' > >>> a > 'a' > >>> id(a) > 1074037376 > >>> a += 'b' > >>> a > 'ab' > >>> id(a) > 1074272448 > > Note the two different id numbers. 'a' and 'ab' are not the same string. That is not relevant. What matters is that a += 'b' does what it is supposed to do. > > Is there a way to tell Python that '' should be something else > > than str? > > No. Bummer. -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From jepler at unpythonic.net Tue Aug 31 10:11:37 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 31 Aug 2004 09:11:37 -0500 Subject: Splitting a list In-Reply-To: <41A1CBC76FDECC42B67946519C6677A9018C2F6B@pippin.int.etrials.com> References: <41A1CBC76FDECC42B67946519C6677A9018C2F6B@pippin.int.etrials.com> Message-ID: <20040831141137.GB7876@unpythonic.net> Here's my version as a generator function: def split(it, elem): l = [] for i in it: if i == elem: yield l l = [] else: l.append(i) yield l >>> list(split(" a b c ", " ")) [[], ['a'], ['b'], ['c'], []] >>> " a b c ".split(" ") ['', 'a', 'b', 'c', ''] >>> l = [1,2,3,-1,4,5,-1,8,9] >>> list(split(l, -1)) [[1, 2, 3], [4, 5], [8, 9]] Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From timr at probo.com Sun Aug 22 00:56:51 2004 From: timr at probo.com (Tim Roberts) Date: Sat, 21 Aug 2004 21:56:51 -0700 Subject: [Q] Bug in cgi.FieldStorage? References: Message-ID: "Ames Andreas (MPA/DF)" wrote: > >I'm currently using Zope 2.7.2-0 which in turn uses cgi.FieldStorage >from Python 2.3.4. > >FieldStorage can either build a 'list' or a 'file' to represent a >request. Unfortunately it overwrites __len__ such that it throws an >exception when the request wasn't of type 'multipart', i.e. when it >doesn't 'return' a list but a file. I'd consider this a bug because >if you have an instance fs of FieldStorage you can't safely write > >if fs: > ... What question do you intuitively expect that statement to be asking? I've been using cgi.FieldStorage() for quite a while, and I can't say that I have ever wanted to write a statement like that. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From and-google at doxdesk.com Mon Aug 16 06:52:32 2004 From: and-google at doxdesk.com (Andrew Clover) Date: 16 Aug 2004 03:52:32 -0700 Subject: A email.cgi script References: Message-ID: <2c60a528.0408160252.29483ed@posting.google.com> wonder wrote: > Is there any sample python script can do that? Not that I know of, but it's pretty simple. Your script seems to cover it, except for some security issues: > msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (fromaddr, toaddr, > subject) 'subject' comes directly from a form submission but has not been sanitised and can contain control characters. (Some form handling software will remove them automatically for you, but the 'cgi' module does not.) So if an attacker inserts a '\n' into the subject field they can add arbitrary headers and body content to the mail you are sending out. You probably don't want that. > print "Content-type: text/html" > print > print ack_text Here the text is not HTML-escaped. An attacker can send a user to the form script with an ack_text parameter of '' or similar cross-site-scripting exploits. If your site is not particularly sensitive this might not be a problem for you, but's it's a bad idea in general. > it does not display To and From editbox in the webpage for user type in > their addresses If you allow both the 'To' address and arbitrary message text to be supplied, your script is very likely going to be spending most of its life sending spam! -- Andrew Clover mailto:and at doxdesk.com From blaktyger at hotmail.com Mon Aug 16 18:06:28 2004 From: blaktyger at hotmail.com (Blaktyger) Date: 16 Aug 2004 15:06:28 -0700 Subject: Displaying images stored as binary in MySQL References: Message-ID: Benjamin Niemann wrote in message news:... > >>>How can this be done? Images are stored in a LONGBLOB field. When I > >>>try to display them, it prints out the binary data as it is... > >> > >>Display where? On local screen, in a webbrowser? > >>Assuming the first one, see post by Tom. > >>Assuming the second one (you're writing a cgi,mod_python... program), > >>did you set the content-type in the http header correctly? > > > > In a webbrowser... > > this is my code... > > > > #!/usr/bin/python2.3 > > > > print 'Content-Type:image/jpeg\n\n' > You must use '\r\n' to terminate header lines. I'm not really sure, but > maybe there should also be a spacing between ':' and 'image/jpeg'... > If you are using e.g. FireFox as a browser, you can user 'View Page > Info' to see, if the browser correctly understands, what you are trying > to tell it ('Type' should say 'image/jpeg'). > > > import blakHtml, sys > > sys.stderr = sys.stdout > > import MySQLdb > > import urllib > > import cgi > > import time > > prevPg=blakHtml.HTMLDocument() > > newConnection=MySQLdb.connect(host='localhost', user='blaktyger', \ > > passwd='****', db='photoFamille') > > curseur=newConnection.cursor() > > > > sqlCmdFr="""SELECT * FROM photo""" > > curseur.execute(sqlCmdFr) > > resultats = curseur.fetchall() > > p=0 > > for val in resultats: > > p=p+1 > > #print '' THIS DOES NOT WORK > > print val[5] > > newConnection.close() > > I know there is no HTML code but this is just a test... > val[5] contains the raw image data (not a path), correct? Does 'photo' > contains more than one image? Concatenating several images into one > bytestream, is definitly not what you want. val[5] contains only one image but I saw that when printing out val[5] is that the binary data is in a array. So this i what I did... import array [same code as before except for this... ] print 'Content-Type: image/jpeg\r\n' [...] for val in resultats: p=p+1 img='' t='' # t is an array object. the tostring() argument extracts the binary data t=val[5].tostring() print t and it works! Thanks for your help Ben! From martin at v.loewis.de Thu Aug 5 17:54:03 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 05 Aug 2004 23:54:03 +0200 Subject: Proposal: require 7-bit source str's In-Reply-To: References: Message-ID: <4112AC7B.1060508@v.loewis.de> Hallvard B Furuseth wrote: > Now that the '-*- coding: -*-' feature has arrived, > I'd like to see an addition: > > # -*- str7bit:True -*- > > After the source file has been converted to Unicode, cause a parse > error if a non-u'' string contains a non-7bit source character. > > It can be used to ensure that the source file doesn't contain national > characters that the program will treat as characters in the current > locale's character set instead of in the source file's character set. I doubt this helps as much as you'd like. You will need to change every source file with that annotation. While you are at it, you could just as well check every source file directly. So if anything, I think this should be a global option. Or, better yet, external checkers like pychecker could check for that. Regards, Martin From Scott.Daniels at Acm.Org Thu Aug 26 19:06:20 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 26 Aug 2004 16:06:20 -0700 Subject: Call for signatories for J2 In-Reply-To: References: Message-ID: <412e6e7e$1@nntp0.pdx.net> Robert Brewer wrote: > This is a call for all who wish to sign the proposal, either for, > against, or abstaining. Count me as a "for" (although I don't really have anywhere as much dislike of "@" as many of my co-signers). -Scott Davd Daniels Scott.Daniels at Acm.Org From jeff at ccvcorp.com Wed Aug 4 13:48:49 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Wed, 04 Aug 2004 10:48:49 -0700 Subject: converting to string In-Reply-To: References: Message-ID: <10h28b0n1ovs110@corp.supernews.com> Ajay wrote: >hi! > >how do i go about converting a Python object or tuple to a string. >i am currently doing >import cPickle as pickle >str = pickle.dumps(obj) > >is thate efficient? is that the best way to do it? > > The "best way to do it" depends very much on what sort of data you're trying to convert, and what you intend to do with the string once you have it. (One could argue ;) that the "best way" would require *not* using the name 'str' to store your string, since that will mask the name of the builtin str() function -- which function might actually do what you want, given the extremely vague description of your requirements.) Pickle is intended to create a serialized version of an object, i.e. one that can be saved to disk or sent through a network port and later restored to active use. The fact that this serialized version is a string is really just an implementation detail, though it's one that's extremely unlikely to change. If what you really want is a displayable string representation of your object/tuple, you might be better off using str() or repr(), possibly playing with the object's __str__() or __repr__() methods in order to get it to display itself usefully. These won't necessarily let you reconstruct the object from the string, but then you don't list that as a requirement. Jeff Shannon Technician/Programmer Credit International From nobody at nowhere.com Tue Aug 24 14:49:29 2004 From: nobody at nowhere.com (Fred) Date: Tue, 24 Aug 2004 20:49:29 +0200 Subject: Building basic dialog in Windows? References: Message-ID: <873ni0l3t2opc1bcaqf6vmuusr0sqah4pg@4ax.com> On Tue, 24 Aug 2004 20:24:00 +0200, Thomas Heller wrote: >You've missed venster http://venster.sf.net/ Oops :-) It's still alpha and documentation barely exists, so I guess PythonWin/pywin32 looks like a better choice. >I think pywin32 has what you need, the makepy utility displays such a >progress dialog when creating python wrappers for large typelibraries. OK, I'll check it out. It seems like pywin32 is meant for C++ developers who are already proficient with MFC, and the only documentation is pretty much the scripts that comes with the software, but I'll try to figure it out and extract what I need. Thank you Fred. From klachemin at home.com Thu Aug 19 04:32:10 2004 From: klachemin at home.com (Kamilche) Date: 19 Aug 2004 01:32:10 -0700 Subject: CODE: Generic Sort Routine Message-ID: <889cbba0.0408190032.335e1713@posting.google.com> I've written a generic sort routine that will sort dictionaries, lists, or tuples, either by a specified key or by value. Comments welcome! import types def sort(container, key = None, ascending = True): ' Sort lists or dictionaries by the specified key' t = type(container) if t in (types.ListType, types.TupleType): thelist = container else: thelist = container.values() if key: sorted = zip([getattr(item, key) for item in thelist], thelist) else: sorted = list(thelist) sorted.sort() if ascending == False: sorted.reverse() if key: return [x[1] for x in sorted] else: return sorted class simple: name = 'simple' def __init__(self, word): self.word = word def __repr__(self): return str(self.__dict__) def test(): # Set up the test data line = 'now is the time for all good men to come to the aid of their country.' words = line.split(' ') compareto = line.split(' ') compareto.sort() assert words != compareto objects = [] for word in words: o = simple(word) objects.append(o) # Sort a list of words test1 = sort(words) assert test1 == compareto # Sort a list of objects lst = sort(objects, 'word') test2 = [] for item in lst: test2.append(item.word) assert(test2 == compareto) # Sort a tuple of objects tup = tuple(objects) lst = sort(tup, 'word') test3 = [] for item in lst: test3.append(item.word) assert(test3 == compareto) # Sort a dict of objects d = {} ctr = 1 for item in objects: d[ctr] = item ctr += 1 lst = sort(d, 'word') test4 = [] for item in lst: test4.append(item.word) assert(test4 == compareto) # Reverse sort a dict of objects d = {} ctr = 1 for item in objects: d[ctr] = item ctr += 1 lst = sort(d, 'word', False) test4 = [] for item in lst: test4.append(item.word) compareto.reverse() assert(test4 == compareto) # Sort a list of numbers lst = [5, 9, 3, 54, 6, 65.7, 2.4, 9999] lst = sort(lst) print lst # Done print "All tests passed!" if __name__ == "__main__": test() From fuf at mageo.cz Thu Aug 19 11:05:56 2004 From: fuf at mageo.cz (Michal Vitecek) Date: Thu, 19 Aug 2004 17:05:56 +0200 Subject: how to tell if x is an instance of new class? Message-ID: <20040819150556.GA24749@foof.i3.cz> hello, i'm (once again) fighting with python C API. i'm simply unable to determine whether 'x' is an instance of new class or not. result of PyObject_Type(x) is unusable, PyType_Check(x) returns 0, PyType_IsSubtype(x->ob_type, &PyType_Type) returns 0, PyType_IsSubtype((PyTypeObject *)x, &PyType_Type) returns 0... how come there's no *easy-and-immediately-obvious* way to get such an important information? what am i missing? HELP! -- fuf (fuf at mageo.cz) From nytimes at swiftdsl.com.au Fri Aug 20 10:38:07 2004 From: nytimes at swiftdsl.com.au (huy) Date: Sat, 21 Aug 2004 00:38:07 +1000 Subject: age of Python programmers In-Reply-To: References: Message-ID: <41260c4a$0$27219$61ce578d@news.syd.swiftdsl.com.au> Skip Montanaro wrote: > Dave> Python fits my brain. > > I agree. This gets my nod for QOTW. > > Skip Lucky for me I found python before Java took over my brain. Huy From ej Mon Aug 16 20:11:18 2004 From: ej (Erik Johnson) Date: Mon, 16 Aug 2004 18:11:18 -0600 Subject: os.system(), HTTPServer, and finishing HTTP requests References: None <41201e06@nntp.zianet.com> <1092631376.357585@yasure> Message-ID: <41214c28$1@nntp.zianet.com> Ah.... Thank you for your reply, Donn. I am not much of a systems programmer (obviously) and was thinking that system() calls were implemented fundamentally different than fork(). For anyone else who might be reading... Using str(os.fstat()) to print the file descriptors, I was a little surprised to find 3, 4, 5, 6 all in use and having identical parameters (0, 1, & 2 being STDIN, STDOUT, STDERR). I'm not sure why those would all be open, but this little bit seems to resolve the problem (it throws OSError when it hits the first invalid file descriptor). for fd in xrange(3, 256): try: os.close(fd) except OSError: break If you know a better/smarter way to effect the same thing, I'd be glad to hear about it. Thanks again! :) -ej "Donn Cave" wrote in message news:1092631376.357585 at yasure... > Quoth "Erik Johnson" wellkeeper com>: > ... > | But if I make this same os.system() call from within my own HTTPServer, > | then the browser that is making the request is left hanging until that > | sleeping grandchild is done. It's like there is still a socket connection > | between it and my browser?!? But the grandchild is not forked from the > | server - it's an os.system() call! It should not be inherting any file > | descriptors and such, right? > > On the contrary, system() does call fork - basically, > > def system(command): > pid = fork() > if pid: > return waitpid(pid, 0)[1] > else: > execve('/bin/sh', ['sh', '-c', command], environ) > > and indeed file descriptors will be inherited. You'll > have to explicitly close the socket. > > Donn Cave, donn at drizzle.com From jbperez808 at wahoo.com Fri Aug 6 15:38:35 2004 From: jbperez808 at wahoo.com (Jon Perez) Date: Sat, 07 Aug 2004 03:38:35 +0800 Subject: generating uuids / guids In-Reply-To: <7x8ycs9k6v.fsf@ruckus.brouhaha.com> References: <2nhnrfF13jq0U1@uni-berlin.de> <7x8ycs9k6v.fsf@ruckus.brouhaha.com> Message-ID: <2ni4iiF16cprU1@uni-berlin.de> The DCE/OSF uuids I see in Linux ('uuidgen' command)and the Windows guids look like they are the same format. They have the same number of hex digits (although their generation methods may be different). It would be good to have the same function interface for either. Paul Rubin wrote: > Why do you say that adding Windows GUID generation to non-Windows > platforms would be Pythonic? Yeesh. From m.hadfield at niwa.co.nz Tue Aug 10 19:43:18 2004 From: m.hadfield at niwa.co.nz (Mark Hadfield) Date: Wed, 11 Aug 2004 11:43:18 +1200 Subject: IDLE vs Command Line In-Reply-To: <8PidncxTb4muxITcRVn-oQ@adelphia.com> References: <8PidncxTb4muxITcRVn-oQ@adelphia.com> Message-ID: Jesse B. wrote: > I like to work with xemacs, so I've been coding modules with xemacs and > running them using the dos prompt (using windows port of xemacs). Some > scripts that work fine with IDLE don't work at the dos prompt. For example: > > import random > > for i in range(10): > x = random.random() > print x > > This simple script doesn't work if I use the command prompt, with this > syntax: python random.py > > I am just wondering why that is. Because you have given the script the same name as the module you're importing, so the script tries to import itself? -- Mark Hadfield "Ka puwaha te tai nei, Hoea tatou" m.hadfield at niwa.co.nz National Institute for Water and Atmospheric Research (NIWA) xxx xxx xxx xxx xxx xxx xxx xxx xxx From rogerb at rogerbinns.com Sun Aug 22 13:26:39 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Sun, 22 Aug 2004 10:26:39 -0700 Subject: 100 % portable ? References: Message-ID: Vent d'Est - East Wind wrote: > i want to know how i can be sure at 100 % that my programme is portable > (i dont want code each times i use other system ) You will have to run your program on all platforms. The Python library documentation pages tell you which platform the modules are on. The vast majority are on all. Note that for some things you would want different code. For example the default location to save files may be My Documents on Windows and $HOME on Linux and Mac. Similarly you would want to save configuration settings in the registry on Windows and dot files on Linux and Mac. > i suppose for GUI is same My preferred toolkit is the wxPython wrapper around wxWidgets. Wherever possible it uses native widgets. It also has functionality often lacked by other toolkits such as printing, keyboard, configuration (backend to registry, files etc). Just to give you some idea, in my 30,000 line program there are 5 tests to see what platform it is running on, specifically to ensure appropriate defaults etc for the platform. For the gui, there are two programs you can try that use wxPython. http://dotamatic.sf.net http://bitpim.org Both are open source so you can see for yourself. Both use the clipboard, do printing, have online help, are distributed so that the user doesn't need Python on their machine already etc. Roger From robin at reportlab.com Mon Aug 9 06:18:30 2004 From: robin at reportlab.com (Robin Becker) Date: Mon, 09 Aug 2004 11:18:30 +0100 Subject: Going the PL/1 way In-Reply-To: References: Message-ID: <41174F76.5030101@chamonix.reportlab.co.uk> Christian Tismer wrote: ....... > > Trying to call func via an instance also doesn't work: > > >>> inst = MyClass() > >>> inst.func(2, 3) > Traceback (most recent call last): > File "", line 1, in ? > TypeError: func() takes exactly 2 arguments (3 given) > >>> > > Now, with the mentioned extra line, the function object is > modified in a way that it understands that it is an ordinary > function, and it works in both cases: > > >>> class MyClass(object): > ... def func(arg1, arg2): > ... return arg1 + arg2 > ... func=staticmethod(func) > ... > >>> MyClass.func(2, 3) > 5 > >>> inst = MyClass() > >>> inst.func(2, 3) > 5 > >>> > Isn't robustness an issue with the @ decorator as well? The most important symbol can be omitted without causing a syntax error, but I suppose the same can be argued for any of the unary operations. -- Robin Becker From dperl at rogers.com Mon Aug 30 15:32:47 2004 From: dperl at rogers.com (Dan Perl) Date: Mon, 30 Aug 2004 19:32:47 GMT Subject: initializing mutable class attributes References: <1gjc8cs.sqvo1v1fhabdjN%aleaxit@yahoo.com> Message-ID: "Shalabh Chaturvedi" wrote in message news:mailman.2624.1093889688.5135.python-list at python.org... > 'Why' is a very subjective question. People from different backgrounds > may accept very different answers for why since it may always be in a > specific context (why this instead of *that*?). The following is my idea > of why: > > In Python you either have an __init__ or you don't. There is no 'default > constructor' - or if there is, it does nothing. Since attributes can be > dynamically added to an instance (not just in __init__ but in any > method), it follows that the standard practice is to initialize instance > members in __init__ as it is always called before any other instance > method. Now that there is one way to do a thing, Python avoids the > introduction of another way (unless it is notably more productive). That > would lead to a whole set of questions about 'which way is better? > __init__ or the other way?'. It is a subjective issue indeed. But I'll restrict my question to a simpler question. By analogy to C++ and Java, why is __init__ not implemented to automatically invoke the __init__(self) of the parent classes? I'm beginning to see a reason here, which is that C++ and Java allow you to overload the constructor and have a default constructor at the same time as another constructor with arguments. C++ and Java then force you to create a default constructor for a parent class, even if it's empty, if you create a non-default constructor for it and you subclass the parent class. In contrast, Python does not allow method overloading and I'm OK with that. It's a simplification that allows using Python in ways that are not possible with C++ and Java. So Python cannot force you to have a 'default' __init__ and allow you to have 'non-default '__init__'s at the same time. I am answering my own question here, but that's OK and it would not have happened without this discussion. > Btw, now that there are descriptors, you can create descriptors that > initialize instance members with default values when they are accessed. > However, unless there is great advantage in your specific case, it might > be just better to follow standard practice and make it easier for > everyone else reading your code. I'll have to look more into descriptors, I haven't used them yet and I see there are many discussions on the topic in this newsgroup. I found your "Python Attributes and Methods" page on cafepy.com and I'll take a look there. Thanks! Dan From ian at emit.demon.co.uk Sat Aug 21 11:11:40 2004 From: ian at emit.demon.co.uk (Ian McConnell) Date: Sat, 21 Aug 2004 16:11:40 +0100 Subject: Parsing C header files with python Message-ID: <873c2gzftf.fsf@emit.demon.co.uk> I've got a header file which lists a whole load of C functions of the form int func1(float *arr, int len, double arg1); int func2(float **arr, float *arr2, int len, double arg1, double arg2); It's a numerical library so all functions return an int and accept varying combinations of float pointers, ints and doubles. What's the easiest way breaking down this header file into a list of functions and their argument using python? Is there something that will parse this (Perhaps a protoize.py) ? I don't want (or understand!) a full C parser, just this simple case. It seems like someone should have done something like this before, but googling for python, header file and protoize just gives me information on compiling python. If there isn't anything I'll have a go with regexps. The reason of parsing the header file is because I want to generate (using python) a wrapper allow the library to be called from a different language. I've only got to generate this wrapper once, so the python doesn't have to be efficient. Thanks, Ian -- "Thinks: I can't think of a thinks. End of thinks routine": Blue Bottle From fuzzyman at gmail.com Wed Aug 25 03:06:58 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 25 Aug 2004 00:06:58 -0700 Subject: Python and C, looking for a C IDE References: <6f402501.0408240353.2a5b8a84@posting.google.com> <412B5DE8.1BE3@zeusedit.com> Message-ID: <6f402501.0408242306.7a39a47a@posting.google.com> Jussi Jumppanen wrote in message news:<412B5DE8.1BE3 at zeusedit.com>... > Michael Foord wrote: > > > That aside - Pyrex looks the kiddie. Can anyone reccomend a reasonable > > C IDE ? An 'IDE' would be nice, but an editor might be sufficient. > > Take a look at the Zeus for Windows programmers editor: > > http://www.zeusedit.com/lookmain.html > > Zeus supports Python, C/C++ and almost any other language. Some of > the programming features include: > > + Code completion and intellisensing > + Integrated class browser > + Project/workspace management > + Fully configurable syntax highlighting > + Seamless FTP editing > + Integrated version control using the Microsoft Source Code > Control (SCC) interface, including CVS integration. > + Quick Help context sensitive help engine > + Fully scriptable using Python > > There is also a tutorial (see the Start Button, Programs, Zeus for > Windows, Tutorials) that explains how to setup the Ming compiler > and debugger (Windows ports of gcc and gdb) to work with Zeus. > > Jussi Jumppanen > http://www.zeusedit.com Wow... scriptable with python sounds good. Regards, Fuzzy http://www.voidspace.org.uk/atlantibots/pythonutils.html From anthonybaxter at gmail.com Sun Aug 8 07:58:26 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sun, 8 Aug 2004 21:58:26 +1000 Subject: Going the PL/1 way In-Reply-To: <41160A17.2090708@jessikat.fsnet.co.uk> References: <41160A17.2090708@jessikat.fsnet.co.uk> Message-ID: On Sun, 08 Aug 2004 12:10:15 +0100, Robin Becker wrote: > > As a final silliness (or perhaps miracle) this can apparently all be > done in python using code from PJ Eby so a standard decorate mechanism > could have gone into the library while the Gods argue. PJE's implementation is pretty nasty. There's no way that would go into a released version of Python. Guido's also said that he's not happy with the approach. > Decision by exhaustion is surely not a good recipe. It might be approaching exhaustion after the last few days, but before then, it was more decision-by-exhaustive-argument. After 2+ years of discussion, and no concensus, eventually it comes down to Guido to decide which way feels best. From elbertlev at hotmail.com Mon Aug 30 16:26:57 2004 From: elbertlev at hotmail.com (Elbert Lev) Date: 30 Aug 2004 13:26:57 -0700 Subject: Enumerating Network Adapters References: <4131b09e$0$13683$636a15ce@news.free.fr> <413257dd$0$26986$626a14ce@news.free.fr> <4qmkheha.fsf@python.net> Message-ID: <9418be08.0408301226.354c337a@posting.google.com> > > It returned the least useful of my 3 IP addresses - my loopback > > adapter - but didn't return my LAN and wireless IPs. Interesting! I have Python installed on 10 W2K servers and I'm using the same construct to get addresses. Works fine for me. From richie at entrian.com Thu Aug 26 04:06:59 2004 From: richie at entrian.com (Richie Hindle) Date: Thu, 26 Aug 2004 09:06:59 +0100 Subject: Subclassing built-in types In-Reply-To: References: Message-ID: <776ri05bkfr2c2fr1uielik0o5sg2bph43@4ax.com> [Emiliano] > I am concerned about something like: > > class NewList(list): > def __init__(self): > list.__init__(self) > > The above code does not allow the passing of a sequence to populate the > NewList. > > I imagine that the correct way to do it is something like: > > class NewList(list): > def __init__(self,seq): > list.__init__(self,seq) > > but I can't find any documentation that describes what arguments > list.__init__ may take. The safest way to do this is: class NewList(list): def __init__(self, *args, **kwargs): list.__init__(self, *args, **kwargs) That will work whatever arguments list.__init__ expects, and will continue to work even if it changes in the future. It's useful when subclassing anything that isn't under your control. (In the trivial case above, where your __init__ doesn't do anything, you can always just omit it.) -- Richie Hindle richie at entrian.com From ben at benlast.com Tue Aug 17 10:38:07 2004 From: ben at benlast.com (Ben Last) Date: Tue, 17 Aug 2004 15:38:07 +0100 Subject: Databases: Getting values by column name In-Reply-To: Message-ID: > From: python-list-bounces+ben=benlast.com at python.org > [mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of > Robert Ferber > Anyway... > only use database rows as sequences, ie as arrays with numerical index. > This gives you loads of problems when using "select *" and also bad code > readability when selecting specific columns. > Is there a way to use them as dictionaries, ie with Index-Strings (=column > names) as indexes? The PEP describes the lowest-level database interface; usually you need to wrap that with some application-aware code to get exactly what you need. Anyway, the answer to your question is: Yes, if you're happy to write a little extra Python. A cursor object, on which you've executed a SELECT, in a PEP249-compliant module would normally have a "description" attribute; this is a list of tuples, one per result column. The first element of each tuple is the column name. So: conn = MySQLdb.connect(...) cr = conn.cursor() cr.execute("select * from myTable") #Look up the columns and get a list of their names, in order. This #isn't necessary for the following code, it's here as an example. cols = map(lambda x: x[0], cr.description)) #Build a list of dicts, one per row, with the values stored by column names as keys. #There are more elegant ways to do this; this is example code. rows = [] for raw_row in cr.fetchall(): row = {} #start with an empty dict for fieldIndex in range(len(cr.description)): #Each description is a tuple with the first element #being the field name. row[description[fieldIndex][0]] = raw_row[fieldIndex] rows.append(row) cr.close() #Now "rows" is a sequence of dicts, one per row, with the values indexed by column name. Just to be exact; the rows are returned as *tuples*, not arrays (at least in MySQLdb; they might be lists in other database modules). Lists and tuples are not necessarily the same as arrays in other languages, depending on exactly how you define an array. Various people (including me) have also written code to return each row as an object that has the column values as attributes, so you can refer to them as myRow.Column1 rather than myRow['Column1']. If you're interested, drop me an email and I'll send you a module that can do that. It's part of the Quasi shell (http://quasi-shell.sourceforge.net/ - gratuitous plug) which has a lot of SQL handling built-in. regards ben-who-spends-his-life-in-MySQLdb From marco at reimeika.ca Tue Aug 17 01:49:54 2004 From: marco at reimeika.ca (marco) Date: 17 Aug 2004 01:49:54 -0400 Subject: Reading ogg123 output with popen3 References: Message-ID: oziko writes: > So, my question is. What is the best form to get ogg123's output, so I > can use it in an UI, to make a progress bas for example? Sorry, not quite an answer to your question, but perhaps the following might be of use: http://pymedia.sourceforge.net/features.html Cheers, -- marco at reimeika.ca Gunnm: Broken Angel http://amv.reimeika.ca http://reimeika.ca/ http://photo.reimeika.ca From andrew.henshaw at gtri.gatech.edu Mon Aug 23 07:27:42 2004 From: andrew.henshaw at gtri.gatech.edu (Andrew Henshaw) Date: Mon, 23 Aug 2004 07:27:42 -0400 Subject: CODE: Generic Sort Routine References: <889cbba0.0408190032.335e1713@posting.google.com> Message-ID: <10ijl5etp3f0489@corp.supernews.com> Kamilche wrote: > I've written a generic sort routine that will sort dictionaries, > lists, or tuples, either by a specified key or by value. > > Comments welcome! ...snip... > if key: > sorted = zip([getattr(item, key) for item in thelist], > thelist) > else: > sorted = list(thelist) ...snip... I'd change that 'if key:' line to 'if key is not None:', so that you could sort on other non-True values. Andy From rogerb at rogerbinns.com Tue Aug 10 04:43:08 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Tue, 10 Aug 2004 01:43:08 -0700 Subject: Python equivalent to a C trick References: <1d7b6d0d.0408092255.1177908e@posting.google.com> Message-ID: Dan wrote: > Is there a python equivalent of this trick in C? > > Logic_Test ? True_Result : False_Result The long answer to your question is at http://www.python.org/peps/pep-0308.html (in addition to the "hack" Sam posted :-) Roger From abra9823 at mail.usyd.edu.au Wed Aug 4 02:13:15 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Wed, 4 Aug 2004 16:13:15 +1000 Subject: converting to string Message-ID: <1091599995.41107e7b823dc@www-mail.usyd.edu.au> hi! how do i go about converting a Python object or tuple to a string. i am currently doing import cPickle as pickle str = pickle.dumps(obj) is thate efficient? is that the best way to do it? thanks cheers -- Ajay Brar, CS Honours 2004 Smart Internet Technology Research Group ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From mwh at python.net Mon Aug 23 12:12:45 2004 From: mwh at python.net (Michael Hudson) Date: Mon, 23 Aug 2004 16:12:45 GMT Subject: Bug in string.lstrip? References: <9EoWc.58$A8.18@edtnps89> Message-ID: Brian writes: > Hello - has anyone else had trouble with string.lstrip stripping too > much? Here's what I get (Python 2.3.4): > > >>> import string > >>> string.lstrip("test/one/two/a.b.c", "test/one/") > 'wo/a.b.c' > >>> string.lstrip("test/one/two/a.b.c", "test/one") > 'wo/a.b.c' > >>> string.lstrip("test/one/two/a.b.c", "test/one/tw") > 'a.b.c' > >>> > > Similar things happened with the strip() string method. Am I missing > something, or should I file a bug report? Strip considers the second parameter as a *set* of characters to remove. Cheers, mwh -- web in my head get it out get it out -- from Twisted.Quotes From http Mon Aug 23 21:57:59 2004 From: http (Paul Rubin) Date: 23 Aug 2004 18:57:59 -0700 Subject: newbie: confused with example in Learning Python 2nd Edition: cananyone give a hint References: Message-ID: <7xoel19u1k.fsf@ruckus.brouhaha.com> "Robert Brewer" writes: > > So: why defitions of self.push and self.pop are defined as > > 'data.append' rather than '_data.append', etc. It's an error. It should say _data.append. > Hint: Python doesn't have variables like other languages do. The line: > > self._data = list(data) > > does not make a copy of "data". Instead, it binds a new name > (self._data) to the same object which the name "data" refers to. The list function does make a copy. Python 2.3.4 (#1, Jul 24 2004, 19:45:58) [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> j=[9,8] >>> a=list(j) >>> a is j False >>> j.append(2) >>> j [9, 8, 2] >>> a [9, 8] >>> From eldiener at earthlink.net Tue Aug 17 21:08:06 2004 From: eldiener at earthlink.net (Edward Diener) Date: Wed, 18 Aug 2004 01:08:06 GMT Subject: Piping stdout to Python callable References: Message-ID: Antoon Pardon wrote: > Op 2004-08-17, Edward Diener schreef : >> From within a function in my own module I need to take the output >> from a Python module "A", which is sending data to stdout and which >> can not be changed and which I need to invoke as a top-level module, >> and pipe it into another function in my own module so that I can >> read it from stdin. Is there an easy way to do this ? The only way I >> can presently think to do this is through "system python A.py | >> python MyOwnModule.py", which seems a bit laborious having to invoke >> python.exe itself twice. Any other solution would be most welcome. > > What do you mean when you say you need to invoke it as a top-level > module? Do you mean you can't import it at all or that importing it > will startup the process of generating output immediatly? I mean that it has a "if __name__ == '__main__' line and I need to trigger it by calling 'python A.py'. > > What bothers you with twice invoking the interpreter? Nothing practically. Just seems inelegant. > In these days > a program that is invoked multiples times will generally be only > loaded once in memory. Shared libraries may be loaded once in memory but python.exe itself gets reloaded each time. > > Are threads an acceptable alternative? Does your MyOwnModule.py needs > to write to stdout? Threads are acceptable. MyOwnModule.py can do anything, depending on parameters, but the idea is that a certain parameter tells it to read from stdin on the other end of the pipe. I have implemented this via "os.system("python A.py | python MyOwnModule.py parameters") and it works fine. I thought there might be a better, more elegant way but since the above works without any problem I will stick to it unless you can suggest anything better. BTW "A.py" can be any number of types of modules which must be invoked by python.exe and writes it's results to stdout. I am telling you this lest you suggest that I somehow import and parse A.py in order to call directly into it rather than having python.exe invoke it. While that might be possible, it would be a real programming PITA. From gandalf at geochemsource.com Fri Aug 6 12:45:05 2004 From: gandalf at geochemsource.com (Gandalf) Date: Fri, 06 Aug 2004 18:45:05 +0200 Subject: Object Reference? In-Reply-To: References: Message-ID: <4113B591.2000902@geochemsource.com> > I'm trying to make a graphical editor and browser for Pickled files. > One aspect I'm not sure about is how to detect multiple references to > the same data. ... > For instance, say I had the Pickled data: > a=[1,2,3] > b=[a,4,5] > c=[b,6,7] > d=[a,b,c] > > The idea is to allow the user to browse this data and indicate > references. In this case, if 'a' was selected, the browser should show > that 'b', 'c', and 'd' contain a reference to 'a'. Inversely, if 'c' > were selected, it should indicate that it's first element just isn't a > list, but a reference to a list defined elsewhere, namely 'b'. >>> Naturally, I could just recursively parse all the data comparing every >>> element to every previously listed object, but is there a less >>> obtrusive >>> method? Python figures out when to delete objects based on the >>> remaining >>> references to an object. Is there a way to access this information to >>> automatically lookup these references? Any help is greatly appreciated. >> >> >> Use the "id()" of the objects? > > > Well, I was thinking of a function that takes an object's id and > returns the ids of all the objects that reference it. Given that > Python keeps this information internally (I believe), my question is > how do I access his data and what would be the easiest way to code > this function? Yes, Python figures out when to delete an object, based on its reference count. But Python only counts the references. It keeps track of the number of references for the object. It does not know where the reference is located in memory. The short answer is that you cannot get this information effectively. Long answer follows. Question: There can be many objects in the structure without a name (e.g. not referenced from the value part of a dictionary). How do you want to display them? As an example: class A: pass a = A() # THE object b = [a,a,a,a] del a # At this point, THE object does not have a named reference at all but it is referenced four times. Do you really want to identify the objects with their memory address? The id function does this to you (Anthony Baxter said the same.) But this will be a useless pickle browser since nobody will notice memory address duplications. Another big problem here. In Python, the only things you can have are an object references. You cannot name the object itself. There are no 'object variables', only 'reference variables'. For example: class A: pass a = A() # THE object we are talking about b = [a] c = [b] Here is the question: does the object b "references" a? The answer is that the question is wrong because 'a' is a reference itself - a reference can only reference one object at a time. Good questions are: - does 'a' and 'b' reference to the same object? (No) - does 'b[0]' and 'a' reference to the same object? (Yes) You may think that a reference of 'a' is contained in 'b'. But this is not a general assumption. For example: a = A() b = A() a.o = b b.o = a Now which is contained in which? Sorry for the long e-mail. G From michaels at rd.bbc.co.uk Thu Aug 26 09:44:27 2004 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Thu, 26 Aug 2004 14:44:27 +0100 Subject: Call for signatories for J2 References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> Message-ID: Pierre-Fr?d?ric Caillaud wrote: > Can we insert conditional expressions in the decorator list ? Not directly, but yes. Both J2 and A1 are "limited" to putting just values that resolve to a function in the decorator list. In practice this means that if you REALLY want to do things like conditional expressions you can: Given: x=1 def memoise(f): print "memoise" return f def esiomem(f): print "esiomem" return f Using current syntax: (untested) class Foo: @staticmethod @eval("(memoise,esiomem)[x==0]") def Hoo(Who, *args): print "Yoo", Who Using proposed J2: (tested) class Foo: using: staticmethod eval("(memoise,esiomem)[x==0]") def Hoo(Who, *args): print "Yoo", Who Personally that strikes me as relatively evil, but it works. Regards, Michael. -- Michael.Sparks at rd.bbc.co.uk British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From reinhold-birkenfeld-nospam at wolke7.net Sat Aug 7 14:15:01 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Sat, 07 Aug 2004 20:15:01 +0200 Subject: Decorator syntax In-Reply-To: References: <38ednYT1NLz1P4zcRVn-uA@powergate.ca> Message-ID: <2nkk3aF1ph3dU1@uni-berlin.de> Paul McGuire wrote: > Please reconsider the "def f() [classmethod]:" construct. Instead of > invoking a special punctuation character, it uses context and placement, > with familiar old []'s, to infuse the declaration of a function with special > characteristics. If this causes def lines to run longer than one line, > perhaps the same rule that allows an unmatched "(" to carry over multiple > lines without requiring "\" continuation markers could be used for unmatched > "["s, as in: > > def f() [ staticmethod, > synchronized, > alphabetized, > supersized, > returns('d') ]: > > > "If I'd wanted mucilage, I'dve ordered mucilage." - Humphrey Bogart, "All > Through the Night" > If I'd wanted to write in Java, I'dve written in Java. > > Keep Python Beautiful. Full ACK! But I fear that without a formal "voting" Python will go the pragmatic way - that is, keep @ as it's already implemented. So what would be the most effective way to notify the developers that (I'm guessing) 90% of the Python community dislike the @ syntax and want an other? Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From catcher at linuxmail.org Wed Aug 25 22:12:59 2004 From: catcher at linuxmail.org (Robert) Date: Wed, 25 Aug 2004 22:12:59 -0400 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: Isn't "Xah Lee" chinese for "Moron"? From kirk at eyegor.jobsluder.net Sat Aug 7 13:03:18 2004 From: kirk at eyegor.jobsluder.net (Kirk Job-Sluder) Date: Sat, 07 Aug 2004 17:03:18 GMT Subject: Paul Graham on Python hackers References: Message-ID: On 2004-08-07, Zoltan Sekeres wrote: > On Fri, 06 Aug 2004 22:23:59 -0700, ellisjb wrote: >> (In all seriousness I think python and java have a lot more in common than >> python and perl.) > > This a flamebait, right? Otherwise I would be interested in the features > which make Python similar to Java (shudder). In previous writings Graham tends to focus more on language fundamentals rather than the scope of features or the process of compilation. Python is closer to Java in that they are both strongly Object Oriented languages in contrast to perl's OO framework that feels more bolted on than integral to me. Both Python and Java tend to focus on providing a single clear interface to a function rather than a multitude of synonyms and syntaxes. Conceptually, python is closer to java. In terms of actual implementation, python is closer to perl. From in.aqua.scribis at nl.invalid Mon Aug 30 10:35:10 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Mon, 30 Aug 2004 16:35:10 +0200 Subject: Get Parent path value (bad design) Help In-Reply-To: References: Message-ID: Golawala, Moiz M (GE Infrastructure) schreef: > Hi all, > > What I am trying to do is write some generic code where I can > get the path of the parent directory. for example if current > working directory is 'Z:\\dirA\\Parent\\Child' > > I want to get a string which up like 'Z:\\dirA\\Parent' > Then I do a sys.path.append('Z:\\dirA\\Parent') path = r'Z:\dirA\Parent\Child' # or: path = os.getcwd() parent = os.path.normpath(os.path.join(path, '..')) -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From barry at python.org Sun Aug 22 23:48:29 2004 From: barry at python.org (Barry Warsaw) Date: Sun, 22 Aug 2004 23:48:29 -0400 Subject: PEP 20 - The Zen of Python Message-ID: <1093232909.28577.19.camel@geddy.wooz.org> Figured it was about time... sssh!-don't-tell-tim-ly y'rs, -Barry -------------- next part -------------- PEP: 20 Title: The Zen of Python Version: $Revision: 1.1 $ Last-Modified: $Date: 2004/08/23 03:41:21 $ Author: tim at zope.com (Tim Peters) Status: Active Type: Informational Content-Type: text/plain Created: 19-Aug-2004 Post-History: 22-Aug-2004 Abstract Long time Pythoneer Tim Peters succinctly channels the BDFL's guiding principles for Python's design into 20 aphorisms, only 19 of which have been written down. The Zen of Python Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those! Easter Egg >>> import this 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: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 316 bytes Desc: This is a digitally signed message part URL: From roy at panix.com Tue Aug 3 21:03:45 2004 From: roy at panix.com (Roy Smith) Date: Tue, 03 Aug 2004 21:03:45 -0400 Subject: help: Unit test fixture returning the same object References: <9895e897.0408031533.26720ba0@posting.google.com> Message-ID: In article <9895e897.0408031533.26720ba0 at posting.google.com>, michael_mccracken at mac.com (Michael McCracken) wrote: > The problem is that in each test case, setUp and tearDown are called > as expected according to the print statements, but they don't seem to > have any effect after the first invocation. self.testfile is always > the same instance as reported by id(). Are you really sure they're the same object? id() just returns the address of the object in memory. It's possible for two objects to have the same id as long as their lifetimes never overlap. If you repeatedly create and destroy the same type of objects in the same context (as happens in a unittest environment), it's reasonably likely that objects will reuse the same memory locations. Other than the oddity of id() returning the same value in different tests, is something unexpected happening? From martin at v.loewis.de Sat Aug 7 01:28:19 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 07 Aug 2004 07:28:19 +0200 Subject: Proposal: require 7-bit source str's In-Reply-To: References: <4112AC7B.1060508@v.loewis.de> <411343D7.3020604@v.loewis.de> <411353A3.8090502@v.loewis.de> <4113759E.2070405@v.loewis.de> <4113E755.8060205@v.loewis.de> <41140349.6090202@v.loewis.de> Message-ID: <41146873.2090202@v.loewis.de> Neil Hodgson wrote: > Do you have a link to such an encoding? I understand 0x5c, '\' is often > displayed as a yen sign, but haven't seen it as the start byte of a multi > byte character. The ISO-2022 ones: >>> u"\u69f9\u6a0c".encode("iso-2022-jp") '\x1b$B\\_\\n\x1b(B' ESC $ B and ESC ( B are the codeset switch sequences, and \_ \n are the actual encodings of the characters. > Regarding the 's' string prefix in the proposal, adding more prefixes > damages ease of understanding particularly when used in combination. There > should be a very strong need before another is introduced: I'd really hate > to be trying to work out the meaning of: > > r$tu"/Raw/ $interpolated, translated Unicode string" Indeed. Perhaps some combinations can be ruled out, though. Regards, Martin From no.spam at here.dude Tue Aug 31 13:43:34 2004 From: no.spam at here.dude (red floyd) Date: Tue, 31 Aug 2004 17:43:34 GMT Subject: Xah Lee's Unixism In-Reply-To: <4134AC88.56452265@yahoo.com> References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4PGdnfsOfdDPi63cRVn-tA@speakeasy.net> <41337FC9.8070902@hotmail.com> <%T%Yc.29567$Es2.11957889@news4.srv.hcvlny.cv.net> <4134AC88.56452265@yahoo.com> Message-ID: CBFalconer wrote: > Dump Notepad and get Textpad. www.textpad.com. First class. > Let the editor flame wars begin! Get gvim! www.vim.org From steven.bethard at gmail.com Wed Aug 25 00:36:37 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Wed, 25 Aug 2004 04:36:37 +0000 (UTC) Subject: with as J2 keyword (WAS: Re: J2 0-2-6 is available) References: Message-ID: Doug Holton spam.here> writes: > with: > classmethod > .author = "Fran?ois Pinard" > def foo(cls): > pass > > def bar(): > pass > with bar: > staticmethod > .version = "0.2.4" Note that one of the common decorator examples has been something like: @classmethod @funcattrs(author="Fran?ois Pinard") def foo(cls): pass So for functions, people already want to put classmethod and the author attribute in the same place. So when "with" blocks come along, and people get used to writing with self: .x = 3 they're going to wonder why they have to move their metadata to after the function if they want to use the .xxx syntax. That aside, I tend to agree with you. I think mixing the .xxx assignments (which are statements) with things like "classmethod" and "memoize" (which are expressions) is bound to be confusing, e.g. your example: > with self: > init > .version = 3 > Is that supposed to mean: > init(self) > self.version = 3? Presumably anyone who was pushing for "with" as the keyword would, at the least, disallow this sort of syntax for non-funcdefs, but this is certainly a great example of how horrible it could be. =) Steve From michele.simionato at gmail.com Tue Aug 10 00:39:21 2004 From: michele.simionato at gmail.com (Michele Simionato) Date: 9 Aug 2004 21:39:21 -0700 Subject: Best pattern/idiom References: <4117c3d8$1@buckaroo.cs.rit.edu> Message-ID: <4edc17eb.0408092039.10958e11@posting.google.com> Chris Connett wrote in message news:<4117c3d8$1 at buckaroo.cs.rit.edu>... > I was wondering if there were a well known pattern/idiom for breaking a > sequence into a list of lists, each n elements long, e.g. > > [0,1,2,3,4,5,6,7,8,9,10,11] -> [[0,1,2,3],[4,5,6,7],[8,9,10,11]] > > This comes up reasonably often in my work, and every time I re-think > about it, and come up with > [ lis[n:n+4] for n in range( 0, len( lis ), 4 ) ] > which seems very kludgy to me, since it uses a range and len, 2 mentions > of the list identifier and 2 literal 4's (which is the size I want to > break into this time). > > Is there a better way? >From a post of mine of some time ago ... >>> import itertools >>> def chop(it, n): ... tup = (iter(it),)*n ... return itertools.izip(*tup) ... >>> list(chop([1,2,3,4,5,6],3)) [(1, 2, 3), (4, 5, 6)] >>> list(chop([1,2,3,4,5,6],2)) [(1, 2), (3, 4), (5, 6)] >>> list(chop([1,2,3,4,5,6],1)) [(1,), (2,), (3,), (4,), (5,), (6,)] Michele Simionato From harry.g.george at boeing.com Wed Aug 25 13:46:59 2004 From: harry.g.george at boeing.com (Harry George) Date: Wed, 25 Aug 2004 17:46:59 GMT Subject: Python future performance and speed References: Message-ID: "Robert Brewer" writes: > Jacek Generowicz wrote: > > Peter Hansen writes: > > > > > The last time I checked, Java and C++ (even C) were widely > > > considered to be high level languages. > > > > The fact many people hold an erroneous belief, does not make said > > belief any less erroneous. > > > > > Has someone been raising the bar while I wasn't looking? > > > > The developers of all the truly high-level languages ? > > > > There was a time when assembler was high-level. > > Someday, even Python will be a low-level language. > > ;) > > > Robert Brewer > MIS > Amor Ministries > fumanchu at amor.org A common term for Python and similar higher-level-than-C languages is "VHLL" (Very High Level Language"). -- harry.g.george at boeing.com 6-6M21 BCA CompArch Design Engineering Phone: (425) 342-0007 From aleaxit at yahoo.com Sat Aug 28 02:58:16 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 28 Aug 2004 08:58:16 +0200 Subject: Iteration over Lists and Strings References: Message-ID: <1gj80sj.1wbku5tpiz05cN%aleaxit@yahoo.com> DeepBleu wrote: > I noticed the following: > >>a = 'abba' > >>for n in a: > >> print n, a.index(n) > a 0 > b 1 > b 1 > a 0 a.index(n) returns the FIRST index x of a such thatn a[x]==n. > (expected result: > a 0 > b 1 > b 2 > a 3) Misfounded expectation. The first 'b' and the second 'b' are equal, for example, so a.index can never possibly return different results for them. > What is going on? Can someone clarify this to me? And how can I ensure > that the iteration produces the absolute index number **without** doing > something like: > >>a = 'abba' > >>k = len(a) > >>for m in range(0, k): > >> print a[m], m > a 0 > b 1 > b 2 > a 3 That's what the enumerate built-in is for: for m, n in enumerate(a): print n, m Alex From danb_83 at yahoo.com Fri Aug 20 23:30:44 2004 From: danb_83 at yahoo.com (Dan Bishop) Date: 20 Aug 2004 20:30:44 -0700 Subject: ZeroDivisionError: float division (baby steps) References: <6daa8765.0408191133.2f2e22e3@posting.google.com> Message-ID: calidusdk at hotmail.com (Artemisio) wrote in message news:<6daa8765.0408191133.2f2e22e3 at posting.google.com>... > I am a non programmer who just started with Python. So far I love it. > > I would appreciate if you could help me fix this error I get taking this > exercise: > > count= 0 As other posters have mentioned, the problem is with your indentation. But I can't resist giving advice. First of all, I recommend starting every file with the line "from __future__ import division". You will then no longer need to worry as much about writing things like > sum= 0.0 because you'll get the same division results from "sum=0". (If you really want integer division, use the // operator.) > number= 1 > print "Enter 0 to exit the loop" > > while number != 0 : > number= input("Enter a number: ") > > count= count + 1 # [indentation corrected] > sum= sum + number # [indentation corrected] > > count= count -1 Instead of using sentinel values, it's possible to put the loop condition in the middle of the loop, like this: print "Enter 0 to exit the loop" while True: # loop "forever" number = input("Enter a number: ") if number == 0: # condition for exiting the loop break count += 1 sum += number Note that count no longer needs to be decremented by 1 at the end, because if you enter 0, it doesn't get incremented. Also note that assignments of the form x=x+y can be abbreviated as x+=y, so you don't have to write the left-hand side twice. The benefit will be more noticeable for statements like verboseName[complicated + index + calculation].verboseAttribute += 1 > print "The average is: ", sum / count > #the error is in the above line Often, the real error is long before the line that gives you the error message. But you might want to modify this line to deal with the situation that count == 0. if count == 0: print "You didn't enter any numbers!" else: print "The average is: ", sum / count From in.aqua.scribis at nl.invalid Fri Aug 20 15:16:24 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Fri, 20 Aug 2004 21:16:24 +0200 Subject: IDLE In-Reply-To: References: Message-ID: george schreef: > Newbie question. > > Installed Python 2.4 successfully. > However, double clicking on the IDLE icon activates the hour glass > cursor and then dies. The IDLE window does not come up. > I am sure it is something trivial that I am not doing Happended to me too. Idle is trying to get access to tcp/ip services and can't find them on Windows. You have to start Idle with an option to disable threading, or something. Don't know what feature exactly, I'm not on Windows now, luckily. In any case, you should open a shell Window, and start Idle from the command line. That should tell you what the problem is. -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From chris.cavalaria at free.fr Sat Aug 28 16:44:28 2004 From: chris.cavalaria at free.fr (Christophe Cavalaria) Date: Sat, 28 Aug 2004 22:44:28 +0200 Subject: Generator expressions v/s list comprehensions References: <1gj8y77.6qshr41q531veN%aleaxit@yahoo.com> Message-ID: <4130eeac$0$21092$626a14ce@news.free.fr> Mahesh Padmanabhan wrote: > In article <1gj8y77.6qshr41q531veN%aleaxit at yahoo.com>, > aleaxit at yahoo.com (Alex Martelli) wrote: > > >> Sure, and that limitation is: list comprehensions return lists. This >> one "limitation" (together with Python's applicative order evaluation, >> and you couldn't change THAT without breaking the whole caboodle of >> existing programs!) implies everything else. > > Is returning a list really a limitation considering that lists can be > transformed quite easily? > > What is "Python's applicative order evaluation" and how do generator > expressions get around it? > > >> Generator comprehensions are wonderful and there is no way Python list >> comprehensions can provide the same features, since lists need to be >> lists. Sure, list(e(x) for x in foo) IS just the same thing as [e(x) >> for x in foo]. We'll remove the redundancy in 3.0 -- not earlier >> because it will break backwards compatibility. The only sensible way I >> can see right now for 3.0 to remove this redundancy is by removing list >> comprehensions and leaving only generator comprehensions, btw. > > I am still not clear of the advantages of using generator expressions > (other than less memory consumption) instead of list comprehension for > any given class of problems. Can you cite concrete use cases where > generator expressions would be preferred over list comprehension? > > Thanks, > Mahesh - lower memory usage - lower CPU usage ( sometimes, you don't need to expand the whole generator, see below ) - ability to manipulate infinite generators Is that enouth ? From ksenia at ksenia.nl Thu Aug 26 06:54:42 2004 From: ksenia at ksenia.nl (Ksenia Marasanova) Date: Thu, 26 Aug 2004 13:54:42 +0300 Subject: Call for signatories for J2 In-Reply-To: References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> Message-ID: <55806718-F74E-11D8-BC58-000A957911BC@ksenia.nl> I vote FOR J2. Ksenia Marasanova. From ben at benlast.com Sun Aug 15 04:14:18 2004 From: ben at benlast.com (Ben Last) Date: Sun, 15 Aug 2004 09:14:18 +0100 Subject: reading shell output in parallel Message-ID: At the risk of blowing my own trumpet (a practise to be deplored), you might like to have a play with Quasi (http://quasi-shell.sourceforge.net) in which one can easily do: myFiles = `os ls *.py` and the like, to get the output of Linux/cygwin/Windows-cmd processes. At the moment, the output is not sent in parallel (execution completes first), but you can do: for line in `os myCommand`: print line sendToServer(line) ...so that at least you see the lines as they're sent. regards ben From in.aqua.scribis at nl.invalid Sun Aug 29 11:35:51 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Sun, 29 Aug 2004 17:35:51 +0200 Subject: os.walk: Get entire path In-Reply-To: References: Message-ID: Florian Lindner schreef: > Hello, > when I'm walking through a file system hierarchy using os.walk, how can I > get the full path of a file or dir? normpath and abspath don't work. Sure it does. os.path.abspath(os.path.join(root, file_or_dir)) -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From quaggy at gmail.com Thu Aug 26 21:25:45 2004 From: quaggy at gmail.com (Jonathan Wright) Date: 26 Aug 2004 18:25:45 -0700 Subject: Fun transformation problem In-Reply-To: Message-ID: def trans(paths): tree = {} for path in paths: branch = tree for i,node in enumerate(path[:-2]): branch = branch.setdefault(node, {}) branch[path[-2]] = path[-1] return tree print trans( [(1,2,3), (1,3,4), (2,5,6)] ) print trans( [(1,2,3,4), (3,4,5,6), (3,4,6,7), (3,4,6,8), (3,4,5,1), (3,4,7,9)] ) This is my first post with gmail. The preview shows it screwing up the spaces in the python code, so I'm includeding a version with dots instead of spaces below. :-) def trans(paths): ....tree = {} ....for path in paths: ........branch = tree ........for i,node in enumerate(path[:-2]): ............branch = branch.setdefault(node, {}) ........branch[path[-2]] = path[-1] ....return tree Jonathan. From greg at cosc.canterbury.ac.nz Fri Aug 13 00:40:58 2004 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Fri, 13 Aug 2004 16:40:58 +1200 Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: <60dfb6f6.0408111846.615ee9eb@posting.google.com> References: <60dfb6f6.0408111846.615ee9eb@posting.google.com> Message-ID: <2o2v2qF63a06U1@uni-berlin.de> Carl Banks wrote: > One thing that's different is that, in all those cases, the second > block has a keyword that can't appear alone. You can't have an except > without a try, or an else without an if, but you could have a def > without a decorate. So maybe the def should come first... def: staticmethod author("Fred") decorated foo(blarg): ... -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From mwh at python.net Sat Aug 7 16:32:23 2004 From: mwh at python.net (Michael Hudson) Date: Sat, 7 Aug 2004 20:32:23 GMT Subject: Going the PL/1 way References: Message-ID: Jarek Zgoda writes: > Michael Hudson wrote: > > >>Come on, guys, fix real problems like interpreter thread safety, > >>improve performance, don't make us, "real-world software > >>developers", screaming with every new release, please. > > http://www.python.org/patches/ > > You want to say "if you want any improvement, do it yourself"? Sure, > it's much better than Java's JCP, but expect > http://catb.org/~esr/jargon/html/F/fork.html if enough people will > share the same annoyance and anger. It's possible. > I write some free software, but I never tell users "go fix it > yourself". This is rude. Yes, probably. But so were you, so can we call it quits? Cheers, mwh -- ARTHUR: Why should he want to know where his towel is? FORD: Everybody should know where his towel is. ARTHUR: I think your head's come undone. -- The Hitch-Hikers Guide to the Galaxy, Episode 7 From aleaxit at yahoo.com Tue Aug 31 11:50:29 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Tue, 31 Aug 2004 17:50:29 +0200 Subject: initializing mutable class attributes References: Message-ID: <1gje8ja.1aywqe1j3x7eaN%aleaxit@yahoo.com> Dan Perl wrote: > I will clarify something that was probably not clear enough in my initial > posting. I am interested in instance attributes, but I am using the class > attributes to provide a default, "null", value for the instance attributes. Quite a reasonable approach for immutables, because you don't have to worry about how to copy them -- only about rebinding, which only happens on the instance anyway. Not feasible for mutables, obviously, because you WOULD have to worry about how to copy them -- shallow or deep, for example? > awkward, I would rather call it unsafe. If I were a third-party library > vendor, I would not be comfortable providing a mixin class that forces users > to either invoke the parent's __init__ in their constructors or to You're out of luck, then -- most well-designed classes, mixin or not, do need to have their __init__ called in order to set a consistent state on a new instance which will allow that instance to fulfill its responsibilities. Just copying (shallowly or deeply...?) some class attributes ain't gonna cut it. > I think this points to a weakness in Python as an OO language. I'm not I think that Python's having as few "hidden black magic thing that happens when you're not looking" aspects is a strength, not a weakness. > trying to bash it, but my understanding is that Python is still evolving in > that respect and I think that this should be improved in the future. Then, Python's OO is still settling down after the huge changes in the passage from 2.1 to 2.2 and it's unlikely that any change to come will include making the calls to superclasses' __init__ methods somehow magical and automatic rather than explicit -- I can't speak with certainty, only Guido could, but that is my best guess. However a custom metaclass that does automagically call some initializers is surely a possibility, since it's a rather modest investment of time to develop one, if anybody with a good understanding of Python OO shares your opinion. Calling initializer methods appear self-obviously (to me) to be head and shoulders above your idea about copying (deeply or shallowly?) some class attributes into instances, of course. And I would not call the automagically called initializers __init__ to avoid conflicting with __init__'s very deliberately NON-automagical behavior -- maybe something like __preinit__ or __postinit__ depending on when you want these black magic methods called, or __autoinit__ if you want to keep that aspect undefined, &c. > on the other hand, maybe I'm the only one feeling this way and there's not > going to be a change. It's likely that others share your preferences, but if they share them strongly enough to want to actually do something about them I think they're more likely to be considering other languages, more suitable to their overall philosophy -- it's rare, though not unheard of, for somebody to stick with a language on which they differ on fundamental points of design philosophy, and strive to change that language to their own philosophy, when there are so many alternatives with different philosophies that one might switch to instead. Similarly, it would be unusual, though far from impossible, for somebody to both have a complete and perfect grasp of Python's object model (so they'd be the kind of person who could implement a custom metaclass for your purposes with comparatively little effort) and at the same time loathe fundamental aspects of that object model enough to want to strive to change them. Nevertheless, these are only 'trends', not certainties. Alex From roy at panix.com Sun Aug 22 10:24:14 2004 From: roy at panix.com (Roy Smith) Date: Sun, 22 Aug 2004 10:24:14 -0400 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> <7x4qmv6cwo.fsf@ruckus.brouhaha.com> Message-ID: Tim Churches wrote: > As a population health epidemiologist whose stock-in-trade is > manipulation and analysis of large health data sets, I have to say that > Python's run-time speed is almost always much faster than I would have > expected from such a dynamic language, but also almost always much > slower than I would like, especially when compared to widely-used (but > vastly expensive and sprawling) data manipulation environments such as > SAS system (see http://www.sas.com) which is the "industry standard" in > my particular field. It should not be surprising at all that a general-purpose tool will be beaten by a domain-specific tool in that domain. SAS, as you say, is designed to munch huge numeric data sets. That is its only reason for existing, and it's got 20 or 30 years of development effort behind it to make it do that one task as fast as possible. From anthonybaxter at gmail.com Sun Aug 8 09:11:14 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sun, 8 Aug 2004 23:11:14 +1000 Subject: decorators vs GIL In-Reply-To: <41162234$0$32536$626a14ce@news.free.fr> References: <8YudnZoJ4NdLEYjcRVn-jA@speakeasy.net> <0bidnfbR2_PZOIjcRVn-pA@giganews.com> <41162234$0$32536$626a14ce@news.free.fr> Message-ID: On Sun, 08 Aug 2004 14:57:12 +0200, Xavier Combelle wrote: > For information is there some internet resources to understand what > exactly the GIL is about ? Plenty - try this google search: http://www.google.com/search?q=site%3Adocs.python.org+GIL for a couple of simple ones, but there's plenty more - google for "python GIL" (or "python free-threading" for patches that were written against Python 1.4 to remove the single lock. They ended up slowing down Python significantly. Note that much has been written about the GIL. Much of the stuff I've seen has been from people who obviously don't understand it, but fear it anyway. Anthony From marcos at nordesia.org Wed Aug 18 21:56:09 2004 From: marcos at nordesia.org (Marcos Eimil Pardo) Date: Thu, 19 Aug 2004 03:56:09 +0200 Subject: age of Python programmers In-Reply-To: References: Message-ID: <412408B9.6060608@nordesia.org> 28 years old, and getting more and more surprised with python, not only a elegant, expressive, etc, etc. language, also useful as social life maker ;D. Lucas Raab wrote: >One thing I've always kind of wondered is what is the average age of a >Python programmer?? What age groups use Python?? Something to think >about.... > > > > From rnichol_rrc at yahoo.com Tue Aug 17 00:41:35 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Mon, 16 Aug 2004 23:41:35 -0500 Subject: Python secure? In-Reply-To: References: <2xXTc.3775$bJ2.24876@news1.mts.net> <4neUc.3991$bJ2.26560@news1.mts.net> Message-ID: Peter Hansen wrote: > You haven't really been programming for very long, I think. In fact I've been programming for years formally trained. > Your argument (and I don't intend to start a flame war about another > religious area) is tantamount to saying that the only failing of > guns is that people use them to kill other people... (That argument > has merit, of course, but it sort of misses the whole point.) Only if people use them improperly, which is my point, which you seem to have missed. Guns are good at killing something to eat. C, if you know what you are doing, can create secure code and you don't have to be perfect. >> If people wouldn't rush, if they took there time to learn what's >> actually going on, they wouldn't make those mistakes. > > > Okay, fair enough... though still arguable. But let's look at > reality: people do rush. People don't take the time to learn > what's actually going on. And even when they do, they are > only human, so sometimes they forget, or get confused, or just > get in a hurry, or in spite of all their best efforts they > still manage not to do it right. Expecting programmers to > be perfect is unreasonable, and to achieve very secure code in > C one must expect to have perfect programmers. > >> One cannot judge a language by it's ability to allow sloppyness. > > > Whyever not? There's no inherent reason why one shouldn't do > exactly that. > Assembly, for example, is a terrible language... We aren't talking about assembly, we are talking about C, which is readable if the programmer takes the time to code and document properly. Any language will suffer if a poor programmer is at the helm. And if there is a program that needs writing (securely) and someone is charged with that duty that has no business doing so, they'll get what they deserve regardless of which language is used. > > Quite frankly, I've seen some crap > >> Python code. It's the programmer NOT the language. > > > Not quite: it's the programmer *and* the language. But for > a given programmer, there are clear differences between two > languages in terms of how readable the resulting code will be, > not to mention how secure. If a programmer writes well structured code then (s)he will write well structured code to the limitation of that language. All languages that I have seen allow proper indentation, etc. If the programmer doesn't do this then (s)he'll find a way to mess up readality, etc somehow. >> Remember, there is no one language that everything is good for. >> Python, C, C++, Lisp, etc all have things that it is best to program >> in them. It all depends on the projects requirements. > > > All true... but we _were_ talking about requirements involving > security and, for that, C is not as good as Python. I think > your final statement is pretty close to agreeing with that, > unless you really want to go back now and argue against yourself, > that C is just as good as Python in that area, or perhaps even > better... (in which case I'm quite curious what areas you > think Python, C++, and Lisp excel in compared to C.) > > -Peter I'm trying to say here that one must base the choice of language on a project by project basis. That the program must be secure is no reason to jetison C straight away, as there are way too many other factors that come into play. Look at the project and the language will fall out. If I was to kill Python (or any other scripting language) then one need only mention speed as an absolute requirement. But, if speed wasn't an issue then a scripting language would still be in play. I'd also like to mention that one need not have to choose between the two as one can embed Python in C. Use C for the speed sensitive parts and Python for the others. For instance, many games (which depend on high frame rates) use Python in parts of them. I'd like to say at this point, since I'm probably coming off as anti-Python to some, that I do love the language. In fact I recommend it to anyone that wishes to learn programming as it repels many bad habits. I'm also using it for multiple projects that I have going right now. But, that being said, I must say that it does have its limitations, just like any other language. I'm just defending others that I don't think have some limitations that others think that they do. So, with that in mind, I think that this discussion has reached an opinion level and thus IMHO, will bear no futher fruit. From pm_mon at yahoo.com Thu Aug 26 20:54:22 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Thu, 26 Aug 2004 20:54:22 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> Message-ID: Anthony Baxter wrote: > On Thu, 26 Aug 2004 11:15:46 -0400, Paul Morrow wrote: > >>__getitem__ is most certainly magical! Defining it 'declares' >>(implicitly, but we'll ignore that governing zen rule for the moment) >>that instances of the containing class have dictionary semantics (that >>they can be used, in some degree, like dictionaries). That's magic. >>That's meta. That's profoundly deeper than anything defining getMonkey >>does. > > > What? There is *nothing* that __getitem__ "declares". __getitem__ is > used by the interpreter. Sure the interpreter uses __getitem__, but you use it too, right? I mean, you don't need the interpreter to tell you whether instances of the following class can act like a dictionary, do you? class Foo: def __getitem__(self, x): pass No you don't. Nor do you need to pretend that you're the interpreter, and simulate a call to an instance of Foo. That's because the mere presence of def __getitem__ tells you what you need to know. In this way, __getitem__ *does* serve as a declaration (of dictionary semantics) [*] to you and anyone reading your code. * But an implicit declaration of course. I guess the only way of *explicitly* stating that instances of a class can act like dictionaries is to have the class inherit from dict or UserDict. > used by the interpreter. When do make a call like: > > someobj[key] > > the interpreter turns that into > > someobj.__getitem__(key) > > That's all. I can make an object that acts like a dictionary _without_ > using a __getitem__, watch: > > class Foo: > def __init__(self): > self.d = dict(ape=False,spidermonkey=True) > > def getMonkey(self, key): > return self.d[key] > > def __getattr__(self, name): > if name == "__getitem__": > return self.getMonkey > else: > raise AttributeError, name > > f = Foo() > print f['ape'] > print f['spidermonkey'] Now hold on just a minute. If I squint a little, I can still see __getitem__ in there somewhere. Though I do believe that you are illustrating a good point; that you can mangle your code badly enough that it no longer lends itself to a declarative reading. And then, the only way for your poor reader to figure out what the heck it's doing is for him/her to act like the interpreter and walk through your code (or run it under the debugger). But I guess if you had a good enough reason... From g24ever at hotmail.com Fri Aug 20 15:08:41 2004 From: g24ever at hotmail.com (george) Date: 20 Aug 2004 12:08:41 -0700 Subject: IDLE Message-ID: Newbie question. Installed Python 2.4 successfully. However, double clicking on the IDLE icon activates the hour glass cursor and then dies. The IDLE window does not come up. I am sure it is something trivial that I am not doing Any thoughts George From cookedm+news at physics.mcmaster.ca Tue Aug 10 01:53:46 2004 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Tue, 10 Aug 2004 01:53:46 -0400 Subject: numarray speed question References: <953AD3D0Didtoken@128.91.2.239> <953C4DD4idtoken@128.91.2.239> <144d0df.0408070828.338f8c19@posting.google.com> <9540516Didtoken@128.91.2.239> Message-ID: At some point, grv575 at hotmail.com (grv) wrote: > cookedm+news at physics.mcmaster.ca (David M. Cooke) wrote in > : > >>At some point, grv575 at hotmail.com (grv575) wrote: > >>> Heh. Try timing the example I gave (a += 5) using byteswapped vs. >>> byteswap(). It's fairly fast to do the byteswap. If you go the >>> interpretation way (byteswapped) then all subsequent array operations >>> are at least an order of magnitude slower (5 million elements test >>> example). >> >>You mean something like >>a = arange(0, 5000000, type=Float64).byteswapped() >>a += 5 >> >>vs. >>a = arange(0, 5000000, type=Float64) >>a.byteswap() >>a += 5 >> >>? I get the same time for the a+=5 in each case -- and it's only twice >>as slow as operating on a non-byteswapped version. Note that numarray >>calls the ufunc add routine with non-byteswapped numbers; it takes a >>block, orders it correctly, then adds 5 to that, does the byteswap on >>the result, and stores that back. (You're not making a full copy of >>the array; just a large enough section at a time to do useful work.) > > It must be using some sort of cache for the multiplication. Seems like on > the first run it takes 6 seconds and subsequently .05 seconds for either > version. There is. The ufunc for the addition gets cached, so the first time takes longer (but not that much???) >>Maybe what you need is a package designed for *small* arrays ( < 1000). >>Simple C wrappers; just C doubles and ints, no byteswap, non-aligned. >>Maybe a fixed number of dimensions. Probably easy to throw something >>together using Pyrex. Or, wrap blitz++ with boost::python. > > I'll check out Numeric first. Would rather have a drop-in solution (which > hopefully will get more optimized in future releases) rather than hacking > my own wrappers. Is it some purist mentality that's keeping numarray from > dropping to C code for the time-critical routines? Or can a lot of the > speed issues be attributed to the overhead of using objects for the library > (numarray does seem more general)? It's the object overhead in numarray. The developers moved stuff up to Python, where it's more flexible to handle. Numeric is faster for small arrays (say < 3000), but numarray is much better at large arrays. I have some speed comparisions at http://arbutus.mcmaster.ca/dmc/numpy/ I did a simple wrapper using Pyrex the other night for a vector of doubles (it just does addition, so it's not much good :-) It's twice as fast as Numeric, so I might give it a further try. -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From tdelaney at avaya.com Mon Aug 16 21:20:32 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Tue, 17 Aug 2004 11:20:32 +1000 Subject: Why I love python. Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01D588BC@au3010avexu1.global.avaya.com> Nick Patavalis wrote: > I believe this is not a discussion about cell-phones. Incidentally all > these features are hard to implement without software. No - it is a discussion about simplicity. Mobile phones were used as an example of something simple becoming les and less simple, to which you produced a denigrating response. Tim Delaney From titus at barik.net Tue Aug 31 12:32:20 2004 From: titus at barik.net (Titus Barik) Date: Tue, 31 Aug 2004 12:32:20 -0400 Subject: convert string to input stream Message-ID: Hi, I've used Google quite a bit in an attempt to find an answer to this question, but have found no leads, possibly because I'm not sure I'm wording my question properly. So I thought I'd try here. Basically I have a function that accepts an input file stream as an argument: handle = open(SOME_FILE) my_function(handle) But occasionally, I end up with a string ("Hello world") that I need to convert to a stream in order to pass it into this function. Perhaps something like: fake_handle = convert_to_handle("Hello world!") so that it appears to this function to be a file handle. I've seen functions in other languages that will take strings and convert them to streams via IO Memory Buffers and such, but can't seem to find anything in Python; or at least I don't know where to look. One solution that I didn't like was to do the following: 1. Open a temporary file. 2. Write the string to that file. 3. Read it back. Any suggestions are appreciated. Regards, -- Titus Barik (titus at barik.net) http://www.barik.net From fredegar at haftmann-online.de Mon Aug 23 01:59:55 2004 From: fredegar at haftmann-online.de (Florian Fredegar Haftmann) Date: 22 Aug 2004 22:59:55 -0700 Subject: Python/COM scale problem with Internet Explorer Message-ID: Hi! For a regression test setup on web interfaces, I use a test tool which in a very heavywight fashion uses the COM interface to the Internet Explorer (of course, from Python, ver 2.3.4, win32com build 163, Windows XP, IExp ver 6.0.2800). During a session, many COM controls are installed in order to trace actions inside the Internet Explorer. After a certain amount (100?) of sessions (each about 2 until 5 minutes), allocating a new InternetExplorer control is not possible any more, throwing an exception. The code snippet [...] try: iexp = InternetExplorer() except pythoncom_error: ... [...] (where InternetExplorer is the COM class materialized by makepy) then leads to the except branch. This "denial" state persists until a certain amount of time (may be half an hour) has passed. Its worth noting that each session is carried out sequentially in a distinct process. I also made certain assurance tests on free memory and CPU resources - there is definitvly no bottleneck. The issue therefore seems to be a COM scale problem. Has anyone experience with a comparable scale problem and knows how to cirumvent it? Any suggestion welcomed. Thanks & Greetings Florian Haftmann From meldron at meldron.org Tue Aug 24 16:28:14 2004 From: meldron at meldron.org (Bernd Kaiser) Date: Tue, 24 Aug 2004 22:28:14 +0200 Subject: Printing date a file In-Reply-To: References: Message-ID: <2p1mkcFfod4gU1@uni-berlin.de> I would use the "International Date Format (ISO 8601)" CCYY-MM-DD (2004-08-24) Regards, Bernd Kaiser Kory Wheatley wrote: > In Python how would you print the date in a file, I > have a logging program written in python and for each > new recorded added to the file, I would like to print > the > date, something like this below: > > 08/24/2004 or 08-24-2004 > > -- > Kory Wheatley > > > > __________________________________ > Do you Yahoo!? > New and Improved Yahoo! Mail - Send 10MB messages! > http://promotions.yahoo.com/new_mail From aahz at pythoncraft.com Mon Aug 23 13:58:46 2004 From: aahz at pythoncraft.com (Aahz) Date: 23 Aug 2004 13:58:46 -0400 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> <278de0e.0408220636.3ee25f9d@posting.google.com> <278de0e.0408221450.324e8178@posting.google.com> Message-ID: In article <278de0e.0408221450.324e8178 at posting.google.com>, Neuruss wrote: > >Excuse me? >It seems that you're missing the point. There's nothing wrong with my >way of thinking, which is not "narrow" at all. Yes, it is. >I love Python. It's an excellent, fun, clear, well designed language >and it is fast enough for 90% of the cases. But you can't deny that >for some problem domains, it is slow. Very slow. That's true. If that's what you'd said in the first place, nobody would have argued with you. However, this is what you said: It seems there are quite a few projects aimed to improve Python's speed and, therefore, eliminate its main limitation for mainstream acceptance. If you're going to make a claim that speed is Python's main limitation, you'll need to provide evidence to support your assertion. >I didn't want to start a silly thread to discuss wether python is slow >or not. It is. Period. Nope. Speed is relative. Is a car slow? Depends whether you're trying to go five feet, five miles, fifty miles, five hundred miles, or five thousand miles -- and it also depends on the alternatives available for traversing that distance. Repeatedly claiming that Python is slow as an absolute statement only shows your ignorance and unwillingness to listen to other people. >All the other comments on this thread, regarding the main limitation >for python's acceptance are true, but speed is critical, and this is >were all efforts should be concentrated. That's nice. If that's your belief, what are you doing to work on this? >So my intention when I started this thread, was to learn more about >these projects, read other oppinions, get some news, etc... I didn't >mean to start a a nonsense discussion! Believe me, I'm sympathetic to the fact that English is not a comfortable language for you. However, at this point, the problem appears to be a thinking problem, not a language problem. You simply hold an opinion at odds with the experience of many expert Python programmers, and it's one that is almost guaranteed to start an argument. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From michele.simionato at gmail.com Sat Aug 7 03:54:12 2004 From: michele.simionato at gmail.com (Michele Simionato) Date: 7 Aug 2004 00:54:12 -0700 Subject: How do you feel ? References: <41141FF1.2030606@charter.net> Message-ID: <4edc17eb.0408062354.a8d6429@posting.google.com> Howard Stearns wrote in message news:<41141FF1.2030606 at charter.net>... > Of course, the first thing I did was re-implement generic functions. But > other than that, I'm must using the libraries. They're good. I'm having > fun again! Oh, here you are! Just today, I have written a post which use your generic functions module in combination with decorators! > The one thing I've found annoying is that I haven't yet discovered how to > do whatever I want in lambda expressions. I have top-level assignments > where I'd like create a function to use as the the value being assigned. I > don't know how to define a named function in a top-level assignment, and a > lambda won't allow me to use 'try' and other statements -- just > expressions. Or am I looking at things wrong? > You cannot use "lambda" as you would do in Lisp; you must use named functions. Fortunately, decorators help a bit (see my post on generic functions). Michele Simionato From fperez528 at yahoo.com Sat Aug 7 21:46:25 2004 From: fperez528 at yahoo.com (Fernando Perez) Date: Sat, 07 Aug 2004 19:46:25 -0600 Subject: Plotting histograms, scatter plots in Python References: <7S4Rc.49729$Vm1.1245341@news20.bellglobal.com> Message-ID: Colin J. Williams wrote: > > > Paramjit Oberoi wrote: >>>What is the easiest way to generate some plots and graphs in Python ? >> >> >> Pychart: >> http://www.hpl.hp.com/personal/Yasushi_Saito/pychart/ > > The charts look good, but the source code links fail. I found it funny that the author makes a comment about poor PostScript quality in Gnuplot, touting his as an alternative. If the examples on that page are to be believed, that stuff looks like low-quality Excel-type business charts, while Gnuplot has been producing publication quality EPS for a loooong time (ask the many thousands of scientists using it since the early 90's). I'd say that matplotlib is the _real_ contender to gnuplot today, not that toy with horrible font scaling, no apparent real symbol/math support, ugly legend boxes... Best, f From tdelaney at avaya.com Thu Aug 19 20:11:00 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Fri, 20 Aug 2004 10:11:00 +1000 Subject: PEP 318: Can't we all just get along? Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01D591AC@au3010avexu1.global.avaya.com> Neil Zanella wrote: > Well, allow me to contribute my thoughts on staticmethod and > classmethod: > I am barely starting out with Python and my class objects are already > loaded with so many > > foo = staticmethod(foo) These two facts could be somewhat related ... ;) Tim Delaney From martin at v.loewis.de Tue Aug 3 02:13:13 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 03 Aug 2004 08:13:13 +0200 Subject: IronPython-0.6 is now available! In-Reply-To: References: <278de0e.0407281353.27b6a457@posting.google.com> <410963E4.2040106@v.loewis.de> Message-ID: <410F2CF9.6000702@v.loewis.de> Ely Stob wrote: > Where is the referent of your asterisk? Oops. It slipped under the table. Here it is: (*) A lot of languages which appear to be supported on .NET really aren't, atleast not in their original form. Instead, a .NET version of the language gets defined, which deviates in its semantics and feature set from the original syntax. I would expect the same to be the case for IronPython. > I'm very much interested in why you insist that the CLR does not work > well for Python, in the face of an apparently solid existence proof, > in the form of IronPython, that that simply isn't the case. > > I know you have a sound understanding of Python, and sometimes > understanding beats apparent empirical evidence... So far, I believe it is hard to tell, because IronPython is still not complete. However, I firmly believe that you cannot make a full Python implementation (i.e. with the language reference and the portable standard libraries) on .NET which is also CLS compliant. Maybe IronPython does not aim at being CLS compliant, which might improve the chances that it is Python. To see what I mean in other languages: Managed C++ is a language different from C++, for example, the delete operator has a different meaning in managed C++ than it has in standard C++. Likewise, J# is a language different from Java. Essentially, I believe that all these .NET languages are just different ways to write C#. Regards, Martin From tjreedy at udel.edu Thu Aug 5 15:55:01 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 5 Aug 2004 15:55:01 -0400 Subject: Confused about pep 318 References: <10h2ihgb8c6fi97@corp.supernews.com><10h4s026oapbhf1@corp.supernews.com> Message-ID: "Anthony Baxter" wrote in message news:e69d3ed2040805110243768538 at mail.gmail.com... > Sorry, but if discussions on python-dev are not considered "public", what is? > It's an open list, with publically available archives. For those who prefer a newgroup interface, for the selective download into a separate box, gmane.org carries it as comp.lang.python.devel. Also, Brett Cannon's summaries have been posted here on c.l.py for nearly two years, with references to the appropriate threads in the archives. Terry J. Reedy From max at alcyone.com Thu Aug 26 19:27:31 2004 From: max at alcyone.com (Erik Max Francis) Date: Thu, 26 Aug 2004 16:27:31 -0700 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: <412E71E3.C4A2A7A0@alcyone.com> Marco Aschwanden wrote: > > What does the Kaj ... phrase mean? > > "You are dumb", "Your joke is dumb", ...? > > >> Bonvolu ne s:ercu pri nekonatoj aferoj. "Xah Lee" certe - pro manko de > Please don't make jokes about unknown things. "Xah Lee" for certain - [for > esperanto] failing to have the > > >> Ikso - ne estas esperanto. Kaj via s:erco nur s:tulta estas. > letter 'y' - is not esperanto. And your joke is nothing but stupid. That's two bad translations so far. "Please don't joke about unknown issues. 'Xah Lee' certainly, on account of the lack of an X, is not Esperanto.' And your joke is only stupid." (Though _stupid_ was misspelled.) "Xah Lee" doesn't have a Y in it, after all! -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ The main thing in life is not to be afraid of being human. -- Pablo Casals From peufeu at free.fr Wed Aug 25 04:48:20 2004 From: peufeu at free.fr (=?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?=) Date: Wed, 25 Aug 2004 10:48:20 +0200 Subject: Generators versus Coroutines References: <7xbrh4zd21.fsf@ruckus.brouhaha.com> Message-ID: I want co-routines too ! There is a web framework (don't remember the name) which models page sequences as continuations. This is terrific. Think about multipage forms, for instance. I wish Python could do this. > There's another issue, which is I think Michael may be talking about a > more powerful type of generator than the kind built into normal > Python. But I'm not sure of that. From jack at performancedrivers.com Sun Aug 29 01:43:10 2004 From: jack at performancedrivers.com (Jack Diederich) Date: Sun, 29 Aug 2004 01:43:10 -0400 Subject: Announcing PyCs, a new Python-like language on .Net In-Reply-To: <1aj14grs82tj.1eso0930azfaa$.dlg@40tude.net> References: <1aj14grs82tj.1eso0930azfaa$.dlg@40tude.net> Message-ID: <20040829054310.GB17735@performancedrivers.com> On Sat, Aug 28, 2004 at 08:44:48PM -0700, Mark Hahn wrote: > > This is an announcement of the beginning of development of a new > Python-like language called PyCs (pronounced "pie-cees"). Like IronPython, > PyCs will be Python on .Net but it will have more advanced features and > probably have higher performance due to a Psyco-like implementation > technique. See http://pycs.org. > > PyCs is a fusion of Python and C#. All joking not aside, what is next, P? -jack ps, not intended but that could qualify as a lisp joke. From jens.news at webgear.co.za Sat Aug 14 13:01:19 2004 From: jens.news at webgear.co.za (Jens Thiede) Date: Sat, 14 Aug 2004 19:01:19 +0200 Subject: Regular Expressions In-Reply-To: <874qn53dfy.fsf@sinken.local.csis.hku.hk> References: <874qn53dfy.fsf@sinken.local.csis.hku.hk> Message-ID: Right, but if you add (.*) then you get: >>> obj=re.compile(r'(.*?)', re.S|re.I) >>> obj.split('defabc\n defghi jkl\nmno\nabchaha') ['def', 'abc\n def', 'ghi jkl\nmno\n', 'abc', 'haha'] >>> obj.findall('defabc\n defghi jkl\nmno\nabchaha') ['abc\n def', 'abc'] *Note*: 'abc\n def' appears twice. Any suggestions? Jens. Isaac To wrote: >>>>>>"Jens" == Jens Thiede writes: > > > Jens> What is the easiest way to generate a list that contains all > Jens> the remnants of re.findall (the inverse of the following). > > You mean, complement? > > Jens> re.split doesn't seem to work quite well > > Why? > > >>>>obj=re.compile(r'.*?', re.S|re.I) >>>>obj.split('defabc\n defghi jkl\nmno\nabchaha') > > ['def', 'ghi jkl\nmno\n', 'haha'] > >>>>obj.findall('defabc\n defghi jkl\nmno\nabchaha') > > ['abc\n def', 'abc'] > > >>>>obj=re.compile(r'.*', re.S|re.I) >>>>obj.split('defabc\n defghi jkl\nmno\nabchaha') > > ['def', 'haha'] > >>>>obj.findall('defabc\n defghi jkl\nmno\nabchaha') > > ['abc\n defghi jkl\nmno\nabc'] > > Looks like it is doing the job, right? > > Regards, > Isaac. From http Fri Aug 20 03:31:35 2004 From: http (Paul Rubin) Date: 20 Aug 2004 00:31:35 -0700 Subject: Alternative decorator syntax decision References: Message-ID: <7x3c2iw9ig.fsf@ruckus.brouhaha.com> "Paul McGuire" writes: > I would propose a multivote survey: each poster gets 3 votes among the > lettered choices on the Wiki page above. You can use all 3 for a single > option, or split them across 2 or 3 options if you are open to more than > one. 1. My favorite variant was not in the list. 2. Any of the choices will have far reaching consequences that aren't yet thought out very well. There is not yet enough experience programming with the existing mechanisms (classmethods etc.) to be sure what's really worthwhile. 3. There's not all that much discussion on the wiki of how other languages do this stuff. 4. There's nowhere near consensus that any of the choices presented so far are not plain horrible. My conclusion: Python 2.4 should not have new decorator syntax. Stay with the existing stuff, for now. Discussion and exploration should continue and the question should be revisited for 2.5. For 2.4, extend the current kludgy (decorators separated from the function) mechanism if needed to provide necessary functionality, but deprecate any new such feature as soon as it's introduced, with the explanation that it's exploratory. From jgilbert+pythong at uvm.edu Tue Aug 17 11:33:47 2004 From: jgilbert+pythong at uvm.edu (jgilbert) Date: Tue, 17 Aug 2004 11:33:47 -0400 Subject: Editors again In-Reply-To: References: Message-ID: Ivan Voras wrote: > Are there any editors besides IDLE that can display doc-strings[*] in > popups? I tried SPE and DrPython, and while they are ok (better said > 'not horribly bad'), they don't seem to have that option. > > I'd like to see in an editor: > - code-completion in case of functions, member variables etc. > ("intelli-sense"? :) ) > - useful usage of doc-strings, maybe integrated python Help/Manual support > - MDI or similar style, with good navigation (this is why I don't like > IDLE) > > Actually, SPE is pretty close, but auto-completion seems to behave > 'funny' sometimes, and no doc-string support I can see... > > > > [*] Maybe I misnamed them. I was thinking of: > def f(): > """This is a doc-string""" > pass There is but one Python editor and his name is Eric3 (http://www.die-offenbachs.de/detlev/eric3.html). I'm not associated with the project (tho I have sent in bugs), my bias is one of deep fondness. It's written in Python (yay!) and uses QT for widgets. This means that to run it under Windows I use Cygwin's X server and tunnel my X connection through SSH. Piece of cake, really. Yep. From Mike at Geary.com Sun Aug 8 02:39:02 2004 From: Mike at Geary.com (Michael Geary) Date: Sat, 7 Aug 2004 23:39:02 -0700 Subject: Paul Graham on Python hackers References: Message-ID: <10hbik7nskhgn90@corp.supernews.com> > >> (In all seriousness I think python and java have a lot more in > >> common than python and perl.) > > zoltan> This a flamebait, right? Otherwise I would be interested > zoltan> in the features which make Python similar to Java > zoltan> (shudder). Ville Vainio: > Abundant reference semantics. Of course this is true of all OOP > language, and Java doesn't go all the way with it either, but it's the > most popular language that does it. It is also the first OOP language > that does it that I tried, and I totally digged Java for a while > before meeting Python and other languages that do it, and realized > Java is still yet another static-typing-done-wrong low level language. What are "Abundant reference semantics"? I agree wholeheartedly with your conclusion; I'm just not sure what the premise is. Thanks, -Mike From nhodgson at bigpond.net.au Sat Aug 7 18:35:12 2004 From: nhodgson at bigpond.net.au (Neil Hodgson) Date: Sat, 07 Aug 2004 22:35:12 GMT Subject: Compiling disutil modules on Windows References: Message-ID: Geoff Caplan: > I am aware that MS have released a free version of the latest Visual > Studio 7 compiler. I have installed this but disutils doesn't > recognise it. I can't find a free release of the MVC++ compiler: does > such a thing exist? You could try to use mingw: http://sebsauvage.net/python/mingw.html Neil From knight at baldmt.com Wed Aug 18 11:57:08 2004 From: knight at baldmt.com (Steven Knight) Date: Wed, 18 Aug 2004 15:57:08 +0000 (UTC) Subject: ANN: SCons.0.96 adds Fortran 90/95 support, better Qt support, platform-independent file system actions, improved debugging, lots more Message-ID: SCons is a software construction tool (build tool, or make tool) written in Python. It is based on the design which won the Software Carpentry build tool competition in August 2000. Version 0.96 of SCons has been released and is available for download from the SCons web site: http://www.scons.org/ Or through the download link at the SCons project page at SourceForge: http://sourceforge.net/projects/scons/ RPM and Debian packages and a Win32 installer are all available, in addition to the traditional .tar.gz and .zip files. WHAT'S NEW IN THIS RELEASE? IMPORTANT: Release 0.96 contains the following interface changes: - All Builder calls now return a *list* of Nodes, even when the Builder only builds one file. This may require SConscript file changes if you were manipulating the return values from Builders. - The SConsignFile() function now uses a different internal database format by default. This will cause a rebuild when you upgrade to 0.96 unless you modify your SConsignFile() call. - The internal format of .sconsign files has been changed. The change was coded to be backwards-compatible, but there might be corner cases that cause warnings about "ignoring corrupt .sconsign files" and rebuilds when you use SCons 0.96 for the first time in an already-built tree. - The scan_check function that can be supplied to a custom Scanner now must take two arguments, the Node to be checked and a construction environment. It previously only used the Node as an argument. - The internal "node_factory" and "scanner" keyword arguments have been removed from the Builder() function, in favor of separate "target_factory," "source_factory," "target_scanner" and "source"scanner" keywords, which are now documented. - The Scanner add_skey() function has been dropped in favor of using construction variables for the lists of file suffixes known to a Scanner. - File name extensions that contain all digits are now assumed to be version numbers and treated as part of the file basename. - The env.Append() and env.Prepend() methods have been changed to behave like the rest of Python when either argument is a UserList. See the release notes for more information about these changes. This release adds the following new features: - A new --debug=explain option tells SCons to report the reason(s) why it thinks it must rebuild something. - New Moc() and Uic() Builders provide more explicit control over Qt builds, plus new construction variables to control them: $QT_AUTOSCAN, $QT_DEBUG, $QT_MOCCXXPREFIX, $QT_MOCCXXSUFFIX, $QT_MOCHPREFIX, $QT_MOCHSUFFIX, $QT_UICDECLPREFIX, $QT_UICDECLSUFFIX, $QT_UICIMPLPREFIX, $QT_UICIMPLSUFFIX and $QT_UISUFFIX. - Support for Fortran 90 and Fortran 95 has been added. - The newer "ifort" versions of the Intel Fortran Compiler for Linux are now supported. - New functions have been added to return platform-independent Actions that Chmod(), Copy(), Delete(), Mkdir(), Move() and Touch() files and/or directories. - A new Execute() function can now execute Actions directly at SConscript-read time. - A new $RPATH variable has been added that specifies a list of directories for the GNU and IRIX linkers to search for shared libraries. - New $CPPSUFFIXES, $DSUFFIXES, $FORTRANSUFFIXES and $IDLSUFFIXES variables have been added that make it easier to arrange for additional file suffixes to be scanned by the default Scanners. - A new Flatten() function can be used to turn nested lists of Nodes (or other arguments) into a flat list. - A new --debug=presub option prints the commands to be executed before their construction variables are expanded. - A new .win32 Node attribute will expand file names with Windows backslash path separators on any system. - A new ARGLIST variable makes it possible to fetch keyword=value arguments in the order specified on the command line. - Support has been added for the .dylib shared library suffix and -dynamiclib linker option on Mac OS X (darwin). This release enhances the following existing features: - Environment override keywords can now be passed to the Command() Builder. - An emitter argument to a Builder() can now be a list of emitters that will be called in sequence. - The Java() Builder can now take more than one source directory. - Scanners can now use suffix lists from construction variable expansions. - ParseConfig() now recognizes the -Wa, -Wl, -Wp and -pthread flags and adds them to the appropriate variable(s). - Dir (directory) Nodes can now be be created with user-specified Builder objects. - The SConf.CheckLib() method can now search a list of libraries. - The env.WhereIs() method now takes a "reject" argument to weed out specific path names. - When calling Builders, SCons now issues a warning upon use of the keywords "targets" and "sources", which are virtually always typographic errors that otherwise silently (and confusingly) turn into construction variable overrides. - The $ASCOM, $ASPPCOM, $LINKCOM, $SHLINKCOM, $ARCOM, $LEXCOM and $YACCCOM variables all have wrapper Actions by default. This makes it easier to replace the default print behavior with a custom strfunction(). - Individual tools that create libraries now override the default $LIBPREFIX and $LIBSUFFIX values set by the platform. This makes it easier to use Microsoft Visual Studio tools on a CygWin platform. - If Visual Studio is installed, SCons now assumes its C/C++ compiler, its linker and its MIDL compiler are available, too. - SCons now searches for the ICL license file path name in the external environment and the registry before resorting to the hard-coded path name. - When using Visual Studio, SCons now generates the PDB files at link time, not compile time. - Dependency tracking has been modified to eliminate spurious circular dependencies in certain corner cases involving generated header files, and to avoid rebuilding generated .h files when a #included .h file changes. - The internal Task.make_ready() method now creates a list of the out-of-date Nodes for the task for use by the wrapping interface. - A new single_source keyword argument when creating a Builder enforces a single source file on calls to that Builder. The following fixes have been added: - The CacheDir() directory is now created if it doesn't exist. - Construction variables can now be substituted in $LIBS expansions, and $LIBS expansions now properly ignore null library values. - Construction variables that can be searched for libraries now remove .dll files from the list before feeding the list to Win32 compilers. - All *PATH variables can now expand to include Nodes. - The name of a Scanner.Classic instance is now initialized correctly. - SCons now handles dangling symlinks without generating a stack trace. - env.SourceCode() now works properly when called with an individual file name or Node, not just with a directory name or Node. - SCons now handles the lack of an external PATH environment variable. - Use of $MSVS_IGNORE_IDE_PATHS was broken in 0.95 and is now fixed. - The Command() global function now works properly with string actions; this was broken in 0.95. - A bug introduced in 0.95 in building shared libraries under MinGW has been fixed. - SCons now handles null entries (None or '') in tool lists or CPPPATH. - SCons now handles exceptions in thread-safe ways, according to Pythonic standards. - Error messages have been improved when the evaluation of a construction variable expansion yields a Python syntax error. - File names on command lines are now escaped properly when the expansion is concatenated with another string. Performance has been improved as follows: - Node creation has been sped up when calling a Builder by comparing whether environments are the same object, not whether they have equivalent construction variables. - File system Nodes now cache their generated string values after we've finished reading the SConscript() files. - Node lookup has been made slightly more efficient. - Deleting parents' implicit dependencies after a Node has been built has been made more efficient. The documentation has been improved: - The User's Guide has had the following chapters and sections added: A chapter describing how to install Python and SCons; a section describing the declarative nature of SCons functions in SConscript files; a chapter describing File and Directory Nodes and the return values from Builders; a chapter describing the SConf (Autoconf-like) functionality; a chapter describing Java builds. - The early chapters of the User's Guide have been reorganized to better explain concepts for new users (based on input from Robert P. J. Day, many thanks). - User's Guide fixes: the signatures of the various example *Options() calls; triple-quote properly a multi-line Split() example. - Man page additions: an example and explanation of how to use "tools = ['default', ..." when creating a construction environment; a section describing File and Directory Nodes and some of their attributes and methods; a section describing use of the target_factory and source_factory keyword arguments when creating Builder objects. - Man page fixes: formatting typos, misspellings, fix a bad example. ABOUT SCONS Distinctive features of SCons include: - a global view of all dependencies; no multiple passes to get everything built properly - configuration files are Python scripts, allowing the full use of a real scripting language to solve difficult build problems - a modular architecture allows the SCons Build Engine to be embedded in other Python software - the ability to scan files for implicit dependencies (#include files); - improved parallel build (-j) support that provides consistent build speedup regardless of source tree layout - use of MD5 signatures to decide if a file has really changed; no need to "touch" files to fool make that something is up-to-date - easily extensible through user-defined Builder and Scanner objects - build actions can be Python code, as well as external commands An scons-users mailing list is available for those interested in getting started using SCons. You can subscribe at: http://lists.sourceforge.net/lists/listinfo/scons-users Alternatively, we invite you to subscribe to the low-volume scons-announce mailing list to receive notification when new versions of SCons become available: http://lists.sourceforge.net/lists/listinfo/scons-announce ACKNOWLEDGEMENTS Special thanks to Chad Austin, Charles Crain, Tom Epperly, Ralf W. Grosse-Kunstleve, Jonathan Gurley, Bob Halley, Chris Hoeppler, James Juhasz, Chris Murray, Gary Oberbrunner, Simon Perkins, Kevin Quick, Anthony Roach, sam th and Christoph Wiedemann for their contributions to this release. On behalf of the SCons team, --SK From arien_malec at yahoo.com.REMOVE Fri Aug 13 19:20:42 2004 From: arien_malec at yahoo.com.REMOVE (Arien Malec) Date: Fri, 13 Aug 2004 23:20:42 GMT Subject: PEP 318 decorators are not Decorators References: Message-ID: Skip Montanaro wrote in news:mailman.1625.1092418237.5135.python-list at python.org: > Arien> 3) Won't most programmers think GoF decorators before > compiler syntax tree decorators? > > Not if they are unfamiliar with the GoF patterns (myself included). Google: decorate "syntax tree" -pattern --> 129 hits decorator "syntax tree" -pattern --> 20 hits decorator pattern -"syntax tree" --> about 62,000 hits Arien From rich.teer at rite-group.com Wed Aug 25 20:24:31 2004 From: rich.teer at rite-group.com (Rich Teer) Date: Thu, 26 Aug 2004 00:24:31 GMT Subject: Larry Wall & Cults In-Reply-To: <7fe97cc4.0408251356.34f2102a@posting.google.com> References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: On Wed, 25 Aug 2004, Xah Lee wrote: > Did you know that throughout history there's this thing called cult? I think you're getting confused with the Blue ?yster Cult. Don't Fear the Reaper - great song. -- Rich Teer, SCNA, SCSA, author of "Solaris Systems Programming", published in August 2004. President, Rite Online Inc. Voice: +1 (250) 979-1638 URL: http://www.rite-group.com/rich From mcfletch at rogers.com Fri Aug 20 14:36:08 2004 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Fri, 20 Aug 2004 14:36:08 -0400 Subject: classes are objects... so how can we custom print them: we need a classmethod syntax In-Reply-To: References: Message-ID: <41264498.1030507@rogers.com> From my metaclasses presentation: """Simple example of changing class repr""" class Meta( type ): def __repr__( cls ): return '' class X: __metaclass__ = Meta # this uses the meta-property for lookup assert repr(X) == '' Code and presentation available at: http://www.vrplumber.com/programming/ HTH, Mike Neil Zanella wrote: >Hello, > >In Python, classes are objects. But there is no way to custom print a class >object. This would require some syntax such as the one commented out below: >With the current "foo = classmethod(foo)" mechanism custom printing for >class objects is not possible. > > ... ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From robin at reportlab.com Wed Aug 18 12:27:32 2004 From: robin at reportlab.com (Robin Becker) Date: Wed, 18 Aug 2004 17:27:32 +0100 Subject: age of Python programmers In-Reply-To: References: <41237124.4060600@chamonix.reportlab.co.uk> Message-ID: <41238374.3060105@chamonix.reportlab.co.uk> Thomas Heller wrote: > Robin Becker writes: > > >>Lucas Raab wrote: >> >> >>>One thing I've always kind of wondered is what is the average age of a >>>Python programmer?? What age groups use Python?? Something to think >>>about.... >>> >> >>57, used to build my own logic using gas discharge tubes :) > > > 48, but my first logic was build using 24V relays. yea I also did stuff with relays and strowger telephone switches, far more exciting than billions of fet transistors simulating an electric fire :) -- Robin Becker From elainejackson7355 at home.com Mon Aug 30 04:31:10 2004 From: elainejackson7355 at home.com (Elaine Jackson) Date: Mon, 30 Aug 2004 08:31:10 GMT Subject: play a midi file from the interpreter? References: <95tYc.261224$J06.123492@pd7tw2no> <4132CFE1.20004@mxm.dk> Message-ID: Could you sketch me a useage example? I'm finding the documentation extremely sparse. I've heard of 'pipes', but I don't actually know what they are. "Max M" wrote in message news:4132CFE1.20004 at mxm.dk... | Elaine Jackson wrote: | > (How) can you make it so that a function invoked in the python interpreter can | > run another program? (Like the webbrowser module does, only not with a web | > browser.) If it matters the OS is Windows98 and the specific aim in mind is to | > have a function that saves some data as a midi file and then causes the said | > midi file to play. | | | Use the popen() call in the os module. | | regards Max M From rnichol_rrc at yahoo.com Fri Aug 20 11:39:35 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Fri, 20 Aug 2004 10:39:35 -0500 Subject: age of Python programmers In-Reply-To: <41260c4a$0$27219$61ce578d@news.syd.swiftdsl.com.au> References: <41260c4a$0$27219$61ce578d@news.syd.swiftdsl.com.au> Message-ID: huy wrote: > Skip Montanaro wrote: > >> Dave> Python fits my brain. >> >> I agree. This gets my nod for QOTW. >> >> Skip > > > Lucky for me I found python before Java took over my brain. > > Huy Amen to that! From follower at gmail.com Fri Aug 20 21:32:07 2004 From: follower at gmail.com (Follower) Date: 20 Aug 2004 18:32:07 -0700 Subject: ANN: Python Decrypt PDF script -- builds on pdftools References: <4de76ee2.0408200350.3ccb9c50@posting.google.com> Message-ID: <3c18c08f.0408201732.6766d375@posting.google.com> davidb at mcs.st-and.ac.uk (David Boddie) wrote in message news:<4de76ee2.0408200350.3ccb9c50 at posting.google.com>... > Unfortunately, I couldn't find any protected PDF files to test your script > out on. Can you provide some URLs? I found some examples here (protected/encrypted with no user password): * * It also looks like the following GPL'd tool enables you to encrypt without Adobe tools: * > Do you want to supply a patch for pdftools to allow these sorts of files > to be supported transparently? The code works well enough for me at the moment that my motivation for taking it further is a little low at the moment, sorry. :-) I'm not sure how straight-forward it would be to add it transparently, as at a minimum I think it needs to handle strings and streams differently. I will keep your request in mind though... Incidentally, have you considered making the Numeric import in pdftools optional? I just commented it out and things worked fine for me as I wasn't actually accessing page content. Thanks for your work with pdftools. --Phil. From h.b.furuseth at usit.uio.no Sun Aug 8 00:27:54 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 08 Aug 2004 06:27:54 +0200 Subject: @decorators References: Message-ID: Neil Hodgson wrote: >daishi: > >> As far as I know, the proposed @decorator syntax will be the first >> time that two logical lines of python with the same indentation will >> not be independent of one another. Previously, when looking at: >> >> some_python(code) >> and_some_more = stuff >> >> there was no need to look at the the first line in order to know what >> the second line meant/did (and vice versa). > > Much of the time, consecutive lines with the same indentation are highly > dependent with earlier lines modifying the behaviour of successor lines: > > global x > x = 9 Poor example. They are visually tied together in that they both mention the variable x. '@decorator's do not mention the function they affect. -- Hallvard From sbabbitt at commspeed.net Sun Aug 29 11:45:24 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Sun, 29 Aug 2004 08:45:24 -0700 Subject: Announcing PyCs, a new Python-like language on .Net References: <1aj14grs82tj.1eso0930azfaa$.dlg@40tude.net> Message-ID: <1093794853.349452@news.commspeed.net> > > PyCs is a fusion of Python and C#. > > All joking not aside, what is next, P? > > -jack > How about P# , nice and short for the cut and paste challenged. By naming it PyCs they are just trying to glom (or is that glob) onto Python's fame. Why not just name it something new like Omnimegagolopolic-OO. Tom From alanmk at hotmail.com Fri Aug 27 08:30:00 2004 From: alanmk at hotmail.com (Alan Kennedy) Date: Fri, 27 Aug 2004 13:30:00 +0100 Subject: Michael Sparks in October 2004 PCW. Message-ID: Dear Pythonistas, One of our own, Michael Sparks, appears in an article in the October 2004 print edition of Personal Computer World, on the future of digital television and the digitisation of BBC television archives. http://www.pcw.co.uk/news/1157046 At least, I'm assuming that there's only one engineer called Michael Sparks who works for BBC research! For those unaware of it, Personal Computer World is the most venerable IT magazine in the UK: sort of the UK's equivalent of Byte Magazine. And it's still going. I've been reading it on and off for almost 25 years now, since the zx81 and oric-1(!) days. Fascinating work, Michael! I'd love to talk with you sometime about your usage of python co-routines and asynch-io in the media field. I've been following the development of digital television standards for a few years now. I have a lot of respect for the BBC, and am particularly impressed by their current software efforts, such as Dirac. http://www.bbc.co.uk/rd/projects/dirac/overview.shtml It's good to see a familiar (and quotable :-) pythonista right there in the midst of it. Nice one, Michael. -- alan kennedy ------------------------------------------------------ email alan: http://xhaus.com/contact/alan From pm_mon at yahoo.com Mon Aug 23 08:43:23 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Mon, 23 Aug 2004 08:43:23 -0400 Subject: J2 proposal: keyword In-Reply-To: References: Message-ID: <4129E66B.90505@yahoo.com> Nicolas Fleury wrote: > Roman Suzi wrote: > >> This surprises me. And this doen't surprise: >> >> using: >> staticmethod; synchronized; memoize >> def bar(foo): >> "To colon or not to colon? Def is the question." >> pass > > > +1 > Nicolas I see that and I can't help but wish for this... def bar(foo): "To colon or not to colon? Def is the question." __using__ = staticmethod, synchronized, momoize pass Paul From aahz at pythoncraft.com Thu Aug 5 23:43:29 2004 From: aahz at pythoncraft.com (Aahz) Date: 5 Aug 2004 23:43:29 -0400 Subject: Confused about pep 318 References: <10h2ihgb8c6fi97@corp.supernews.com> <10h4vhcfbsv6t30@corp.supernews.com> Message-ID: In article , Anthony Baxter wrote: >On Thu, 5 Aug 2004 13:36:23 -0500, Edward K. Ream wrote: >> >> To repeat: given that pep 318 is grossly misleading, I contend that >> no proper discussion of it has ever taken place. Sorry, but if you >> actively mislead the public, then the public _does_ have a right to >> complain. The web is a huge place. Expecting people to track it >> without proper notice of what is being discussed is patently unfair. > >"Actively mislead the public"? What the hell is that supposed to mean? >Look, you keep insinuating that there was some sort of evil plot to >slip this into Python. I can assure you that this is NOT true, and I'm >getting more than a little bit fed up with this argument. I'm not reading Edward as claiming the existence of an evil plot. OTOH, "actively mislead" is certainly an overstatement, *except* WRT the claim you're making that there was public discussion of the @ syntax going into Python. I think Edward's got a fair point there. Also, there has historically been an expectation that PEPs will be posted to comp.lang.python in their final draft form; while I agree with you that python-dev is a public forum, I think the outrage expressed by those who believed that they didn't *NEED* to monitor python-dev is entirely understandable. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From ptmcg at austin.rr._bogus_.com Tue Aug 10 15:30:38 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Tue, 10 Aug 2004 19:30:38 GMT Subject: pro python paper References: <305aa162.0408091905.5bce8f9a@posting.google.com> <3064b51d.0408100549.213dad5@posting.google.com> Message-ID: wrote in message news:3064b51d.0408100549.213dad5 at posting.google.com... > ccdetail at gmail.com (ccdetail) wrote in message news:<305aa162.0408091905.5bce8f9a at posting.google.com>... > > http://www.journyx.com/pdf/PythonAtAGlance.pdf > > > > the above paper is a response to some of our prospects complaints > > > > they were asking us why we use python > > > > thought you guys might be interested > > > > http://journyx.com/clf > > I think the paper exaggerates the virtues of Python relative to other > languages, reducing the credibility of the authors. > I like Python as much as the next person, but I too thought that the article was a bit "glowy". The Key Advantages section especially is made up of unsupported claims, such as: "Python is considered by many to be one of, if not *the* premier language for GUI development..." (Huh? by whom, and compared to what?? - VB? Delphi? C#? And toolkits like Tk, Qt, etc. are not bound to Python as their language, so I don't see how they come up with this assertion) "The Python community is populated by the best minds in software today." (not to slight any of the Python elite, but I don't think we have a monopoly on the best minds in software - the Java and C++ milieu can be pretty impressive, not to mention Lisp, et al.) "If you need to tie in something written in another language, you can do it easily." (yes, it CAN be done, but at no less overhead than tying VB and C#, or C and FORTRAN - so where is the Python edge?) The countering of the Python Myths reminds me of this MP routine: "This isn't an argument, it's just contradiction!" "No it's not!" While I agree with many of the sentiments expressed, I'm not sure wrapping them in the format of a white-paper (with such breathless prose!) actually increases their power or credibility. A little more concrete supporting info will go a long way here. -- Paul From tjreedy at udel.edu Thu Aug 26 03:50:31 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 26 Aug 2004 03:50:31 -0400 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: Python is not a cult. We therefore have no collective interest in trashing other languages or language designers. From aleaxit at yahoo.com Thu Aug 26 09:00:37 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 15:00:37 +0200 Subject: Inline Conditionals? References: Message-ID: <1gj4rpq.1oyt89b14xvbdqN%aleaxit@yahoo.com> Peter Hansen wrote: > Joshua Ginsberg wrote: > > > Is there any plan to include inline conditionals in Python? For example: > > > > def isNegative(x): > > return x < 0 ? True : False > > This is a FAQ: > > Newbies, please consider reading the several FAQs that you will find > at http://www.python.org/doc/faq/ before posting questions which > might be answered there (i.e. just about anything). Peter's right. And Joshua's example shows how wise the BDFL was in ruling out ternaries: sure, good programmers might occasionally have found good uses for them, but we' have paid that with a LOT of horrid code like that -- I've seen lots like that in C & its ilk, too. return x < 0 on its own does EXACTLY the same job as the requested/wished-for return x < 0 ? True : False except is cleaner, clearer, faster, more concise, easier to read. So, having a ternary operator would enable a little programming horror that the lack of a ternary operator dissuades a little. Of course, absit iniuria verbis, one cannot make anything foolproof, because fools are SO ingenious -- I've also seen lots of code like: if x < 0: return True else: return False which is, si licet es, even _worse_ than the wished-for ternary use!-) Alex From luismg at gmx.net Tue Aug 17 18:59:07 2004 From: luismg at gmx.net (Neuruss) Date: 17 Aug 2004 15:59:07 -0700 Subject: Newbie 1st program References: <278de0e.0408161537.61ab1301@posting.google.com> <30260531.0408170824.3fd74108@posting.google.com> Message-ID: <278de0e.0408171459.49dcba2@posting.google.com> Thanks for the information on Py2exe. But I'm affraid I'm having trouble with it... Traceback (most recent call last): File "C:\Documents and Settings\Usuario1\Escritorio\misApps\Grades\setup.py", line 30, in ? setup( File "C:\Python23\lib\distutils\core.py", line 137, in setup raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg SystemExit: usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: setup.py --help [cmd1 cmd2 ...] or: setup.py --help-commands or: setup.py cmd --help error: no commands supplied >>> I've seen the website and tried to follow the instructions, but there's something I'm doing wrong...how exactly should I run the setup script? In my case, the program I want to convert to .exe is located in this folder: "C:\Documents and Settings\Usuario1\Escritorio\misApps\Grades", this is a GUI application made with Pythoncard (wxpython) and there's a file where a keep data of some serialized objects called "grades.data". With this info in mind, how should I do the script? From dave at pythonapocrypha.com Mon Aug 30 16:19:17 2004 From: dave at pythonapocrypha.com (Dave Brueck) Date: Mon, 30 Aug 2004 14:19:17 -0600 Subject: Size of a remote URL In-Reply-To: References: Message-ID: <41338BC5.4030602@pythonapocrypha.com> Justin wrote: > Ok so the problem is that my code is not requesting the headers > properly. I get back. Just that. I don't know what the difference is > between the IE request and mine Try this: from socket import * s = socket(AF_INET, SOCK_STREAM) s.bind(('',8000)) s.listen(1) while 1: q,v = s.accept() print 'Got connection:' data = '' while 1: more = q.recv(8192) if not more: break data += more if data.find('\r\n\r\n') != -1: break Now replace the domain name in the real URL with "127.0.0.1:8000". Feed the URL to IE and to your app & compare the output displayed by your "server". -Dave From apardon at forel.vub.ac.be Wed Aug 18 07:44:24 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 18 Aug 2004 11:44:24 GMT Subject: Generators versus Coroutines References: Message-ID: Op 2004-08-18, Michael Sparks schreef : > On 17 Aug 2004, Bryan Olson wrote: > ... >> Have you been badly bitten by an evil co-routine? > > You appear to misunderstand what I was saying. I was not saying > co-routines are bad. I was saying that generators are, in my experience, > almost as effective. This isn't attacking anything. It's saying that > generators really aren't as bad as it appears some people make out. > > As for network servers, it looks like the network server system based on > using generators to gain most of the benefits of co-routines I briefly > talked about (in one of the lightning talks) at EuroPython has been > blocked for release as open source :-( > > Your arguments in favour of co-routines for servers all hold (IME) for > generators as well. There is _slight_ extra obfuscation, but nowhere near > the level of change required for event processing. > > NB. The reason I like generators is because they allow me to do > co-routine-type things in python with no addons. The reason I like > greenlets is because it seems to go much, much, much further along > that route _and_ gives a performance boost. Also, I'm not opposed to > co-routines being added to the language *if* it was done in a manner > that doesn't confuse new users, Why should that be a requirement? IMO there is a lot in python that can confuse new users, so it doesn't make sense to require that something added to the language shouldn't. -- Antoon Pardon From jussij at zeusedit.com Tue Aug 31 10:28:03 2004 From: jussij at zeusedit.com (Jussi Jumppanen) Date: Wed, 01 Sep 2004 00:28:03 +1000 Subject: Intelisence References: <43SYc.121080$UTP.113615@twister01.bloor.is.net.cable.rogers.com> Message-ID: <41348AF3.6DC0@zeusedit.com> A.M wrote: > Is there any inelisence IDE (like visual studio) for python? Take a look at the Zeus for Windows programmers editor: http://www.zeusedit.com/lookmain.html Zeus has an automatic ctags generation feature that is used for intellisensing and class browsing. To make it all work just create a Zeus workspace, add your python source files to the workspace and Zeus will manage the creation of the ctags file. You may also need the latest xtags.dll which can be found here: http://www.zeusedit.com/z300/xtags.zip Jussi Jumppanen http://www.zeusedit.com From news at woody.datatailors.com Mon Aug 9 18:43:03 2004 From: news at woody.datatailors.com (Peter van Kampen) Date: Tue, 10 Aug 2004 00:43:03 +0200 Subject: cgi script: get the url of this page References: Message-ID: In article , Matt Price wrote: > A super simple question: > > is there a standard trick to get the url of the current page in a cgi import os script = os.environ["SCRIPT_FILENAME"] Look up the print_environ() function in the cgi-module for your python version to give you an overview of available information. > script, or the url from which form data has been passed?? I want to Hmm. You can try HTTP_REFERER but it depends on several things (browser, server, cgi-implementation etc.) wether this reports something useful or not. It is probably more reliably to check REMOTE_ADDR if that would provide enough information. Hth, PterK -- Peter van Kampen pterk -- at -- datatailors.com From CarolCarrot at sofsof.net Mon Aug 16 15:02:02 2004 From: CarolCarrot at sofsof.net (Carol Carrot) Date: Mon, 16 Aug 2004 13:02:02 -0600 Subject: mailman mailing list program Message-ID: Greetings. I've never seen a more complicated, verbose pile of hogwash than the "deliverd by mailman" mailing list program. Still I have to use it. I'm trying to get a header to get attached tot he email. it gets stripped from the email, whwere as the footer comes in as an attachment. all this is buried under "no0-digest" options for some crazy reason. How do I get the header to work? From geoff at variosoft.com Sun Aug 8 11:37:33 2004 From: geoff at variosoft.com (Geoff Caplan) Date: Sun, 8 Aug 2004 16:37:33 +0100 Subject: Encryption between Python & PHP In-Reply-To: References: Message-ID: <19227567650.20040808163733@variosoft.com> Dan, DS> I can't help much with your other questions, but I do know about this DS> one. By definition, blowfish is blowfish is blowfish. Any (properly DS> implemented) blowfish library will be compatible with another; if you DS> encode something with one library, you will be able to decode it with DS> the other. Thanks for that. Looks like I should persist and track down the problem. Perhaps something to do with the keys? When I try to decrypt I am getting binary garbage out instead of an ascii string. Any pointers about where to start looking would be welcome! ------------------ Geoff Caplan Vario Software Ltd (+44) 121-515 1154 From anthonybaxter at gmail.com Fri Aug 6 11:54:31 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 7 Aug 2004 01:54:31 +1000 Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) In-Reply-To: References: <338366A6D2E2CA4C9DAEAE652E12A1DE01C8C636@au3010avexu1.global.avaya.com> Message-ID: On Fri, 06 Aug 2004 10:23:44 GMT, Paul McGuire > In http://mail.python.org/pipermail/python-dev/2004-March/043835.html, in > response to Phillip J. Eby's observation that most of the list-after-def > proponents have the most concrete examples, GvR states, "Maybe the > practitioners are so eager to have something usable that they aren't swayed > as much by esthetics." I'm not sure that any arguments are going to sway > his view of what's esthetic, it sounds more like a subjective/gut reaction. I've been trawling the archives collecting information for the PEP, and was unable to find a post from Guido that laid out in one place his problems with this syntax, so I asked him to post a piece to python-dev. Please see: http://mail.python.org/pipermail/python-dev/2004-August/047112.html Anthony From reply2group at ndbbm.net Tue Aug 31 00:48:24 2004 From: reply2group at ndbbm.net (Active8) Date: Tue, 31 Aug 2004 00:48:24 -0400 Subject: Need help importing/installing reportlab module References: <1ezngypknj8ju.dlg@news.individual.net> <4133EF58.4050709@holdenweb.com> Message-ID: <1556ldg3h91o2.dlg@news.individual.net> On Mon, 30 Aug 2004 23:24:08 -0400, Steve Holden wrote: > Active8 wrote: > >> I did this once and can't remember how so I read the >> reportlab user guid. It says to unzip the reportlab archive - this >> is on w2k, BTW, with Python23 - to a directory and make a file >> called reportlab.pth in the pythod dir. The only line in this file >> is supposed to be the path to the reportlib dir. >> > When you unpack the ReportLab archive (I downloaded ReportLab_1_19.zip) > it creates a reportlab-1_19 directory (in my case in the C:\Steve > directory), with a reportlab subdirectory that is the package you want > to import. > > My Python is installed in C:\Python23, so I created a > C:\Python23\reportlab.pth file which contained the single line > > C:\Steve\reportlab-1_19 > > Lo! "import reportlab" now works, and you should be good to go. > >> Then I'm instructed to open the ... ok I'll close and reopen ... the >> python cmd line interpreter and type >> >> import reportlab >> >> so I get >> >> Import Error: no module named reportlab >> >> not too surprizing since I can't find anything named reportlab in >> the archive. I did basically the same thing to install PIL and that >> worked. I did also download rl_win32_2_3 and move those .pyd files >> to the pythod dll dir - I assume a pyd is a python dll - worked for >> PIL. >> > I'd be rather concerned that you can't find "reportlab" in the archive. > Basically all it contains is a "reportlab" package directory with the > code in it. That's what I see, just no .py or other files named reportlab. > >> If anyone can help me straighten this out, I'd really apppreciate >> it. >> >> TIA > > Well if this doesn't fix it, please let me know. > when I unzip, I get .\ReportLab_1_19\reportlab-1_19 which contains manifest.txt and the reportlab dir where the actual python code is. I've tried putting both subdirs under d:\ and changed the reportlab.pth path accordingly. I've changed the .pth file from DOS to unix and back because I read somewhere that the line termination char musst be just so - and I'm not even sure I got that right, but there's a newline in there. I even tried it without a newline. I've tried forward and backslashes. Also tried running test_pdfgen_general.py from the command line and the python interpreter - can't type "d:\report* because python doesn't like colons - ..\report* - it doesn't like dots, either. But when I run it from the windows command line, it says that in line 12 of test_pdfgen_general.py from reportlab.test import unittest Import Error: no module named reportlab.test But I checked that test\ dir and unittest.py is there. If that's a clue, I don't know what to make of it. I recall installing another module - maybe PIL. When I tried that from x import y thing, I got an error, but the next instruction was to just type import PIL or whatever, and that didn't throw any errors. I'm pretty confused that it worked so well for you and isn't for me. The instructions can't be simpler. -- Best Regards, Mike From ajsiegel at optonline.com Sun Aug 15 07:46:50 2004 From: ajsiegel at optonline.com (Arthur) Date: Sun, 15 Aug 2004 11:46:50 GMT Subject: Anyone use VPython? References: <8f17f4bc.0408141932.46b7c405@posting.google.com> Message-ID: <69juh0dalfeu39fpvvvcb56ukovl0o1fsb@4ax.com> On 14 Aug 2004 20:32:49 -0700, alikakakhel3 at hotmail.com (Ali) wrote: >Anyone use VPython? Yes. From inigoserna at terra.es Fri Aug 6 15:03:24 2004 From: inigoserna at terra.es (=?ISO-8859-1?Q?I=F1igo?= Serna) Date: Fri, 06 Aug 2004 21:03:24 +0200 Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) In-Reply-To: <4edc17eb.0408050632.58747082@posting.google.com> References: <4edc17eb.0408050632.58747082@posting.google.com> Message-ID: <1091819004.32216.4.camel@inigo.katxi.org> Hi, after thinking all day I hope I've found the option I like more: #decorator def func (cls, *args, **kw): pass ... and it's compatible with old versions of python :) seriously, I prefer next options, they are more readable: 1) def func (cls, *args, **kw): .deco pass 2) def func (cls, *args, **kw): __deco__ pass i.e., not before or inside function definition. Best regards, I?igo El jue, 05-08-2004 a las 07:32 -0700, Michele Simionato escribi?: > "Delaney, Timothy C (Timothy)" wrote in message news:... > > Personally, I don't overly like the new syntax - I much preferred def > > func (args) [decorators] - and I would have preferred not to "waste" @ > > for them, but I can definitely live with the decision. Some usable > > decorator syntax is IMO more important than none. > This also my opinion, more or less. It is just the "@" which is ugly. > Why not to overload (once more) the colon and write: > > :classmethod > def func (cls, *args, **kw): > pass > > ? Only half serious ... > > Michele Simionato -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Esta parte del mensaje est? firmada digitalmente URL: From eurleif at ecritters.biz Sun Aug 22 22:30:55 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sun, 22 Aug 2004 22:30:55 -0400 Subject: Has anyone implemented BASIC in Python? In-Reply-To: References: <2oo13eFcj548U1@uni-berlin.de> Message-ID: <2ot30hFeek8nU1@uni-berlin.de> Andrea Griffini wrote: > I've no idea why you think that an unstructured language would > be a good starting point. There's no stack to deal with, and generally less possible expressions to worry about. You're probably right about doing an expression parser first, though; I will. Thanks for the advice. > Anyway I found the idea of a BASIC interpreter in python intriguing, > so I wrote one this weekend. I wrote it for my egoistic fun, so > I'm not sure if it would be useful for you (or anyone else). Whoa, that's your idea of a weekend project? I'm speechless. I really appreciate the example, and I'll try my best to understand it. Did you use a parser generator or anything like that, or is it purely hand-coded? From martin at v.loewis.de Mon Aug 9 00:40:36 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 09 Aug 2004 06:40:36 +0200 Subject: how many bytes in an int In-Reply-To: <9ACRc.1523$bJ2.9739@news1.mts.net> References: <9ACRc.1523$bJ2.9739@news1.mts.net> Message-ID: <41170040$0$13043$9b622d9e@news.freenet.de> Reid Nichol wrote: > I was wondering if I could control how many bytes are in an int and > the byte order. In C/C++ I can use int32 but how do I do this in > python? How can I control byte order? You can't. Python uses as many bytes as are necessary to represent the number (larger numbers - more bytes). Why do you want to control the number of bytes? Regards, Martin From kjetilho at yksi.ifi.uio.no Sat Aug 28 05:13:17 2004 From: kjetilho at yksi.ifi.uio.no (Kjetil Torgrim Homme) Date: Sat, 28 Aug 2004 11:13:17 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> <87hdqok9i6.fsf@sinken.local.csis.hku.hk> <1rfz68ely9.fsf@rovereto.ifi.uio.no> <876574k7du.fsf@sinken.local.csis.hku.hk> <1r3c28ejis.fsf@rovereto.ifi.uio.no> <5MWXc.228027$ht5.11749427@phobos.telenet-ops.be> Message-ID: <1rhdqnd3rm.fsf@rovereto.ifi.uio.no> [Roel Schroeven]: > > Kjetil Torgrim Homme wrote: > > how long do you have to stare before spotting the bug? > > Just the time needed to read the code. > > > db.update_name(person) > > if is_student(person): > > db.update_courses(person) > > db.commit() > > only students have their names updated. I wonder why. > > No offense, but I wonder why you have a problem with this > code. IMO the indentation makes perfectly clear what's happening. I don't think it is appropriate that I dump thousands of lines of code here to illustrate the problem :-) when I provide four lines of code and tell you there's a bug, of course you can spot it immediately. when it's part of a large system, it's a bit harder. also consider that the db.commit() originally was correctly placed by the programmer, and the wrong indentation was introduced later by an editing glitch. -- Kjetil T. From bbands at yahoo.com Tue Aug 10 11:40:47 2004 From: bbands at yahoo.com (BBands) Date: 10 Aug 2004 08:40:47 -0700 Subject: How do I get IDLE on Suse Linux 9.x? References: <0G1Sc.149588$fv.89578@fe2.columbus.rr.com> Message-ID: <79780d4f.0408100740.54c7743d@posting.google.com> > > Sorry to ask such a basic question. > > Michael IDLE is a separate package on SuSE 9.1. Fire up YaST, click on 'install and remove software,' search for idle, check it, click accept... and away you go. --jab From jepler at unpythonic.net Sun Aug 22 09:26:04 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Sun, 22 Aug 2004 08:26:04 -0500 Subject: 100 % portable ? In-Reply-To: References: Message-ID: <20040822132603.GA2348@unpythonic.net> How can you be sure? I recommend you do it by writing a test-suite for your software and running it on all the platforms you wish to target. On the other hand, Python has had "pretty good" portability for me in the past, at least where Windows, Linux, and Unix are concerned. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From mark_bottjer at hotmail.com Fri Aug 6 16:10:37 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Fri, 06 Aug 2004 16:10:37 -0400 Subject: @decorators In-Reply-To: <10h73e5kh1et536@news.supernews.com> References: <10h73e5kh1et536@news.supernews.com> Message-ID: <4113e5be@nntp.zianet.com> John Roth wrote: > All of the existing packages (at least to my knowledge) use > descriptors to wrap the necessary functions. They could be > very easily reimplemented in terms of the decorator syntax. > However, the decorator syntax brings no new functionality > to the table; it's simply syntactic sugar for already existing > functionality. Exactly. What's more, I don't think that decorators are really the ideal way to express DBC, either. For one thing, pre and post conditions often want access to at least the argument list, and often to the internal variables of the definition. I don't think that this will be possible with the decorators as proposed, since they are outside the scope of the function. > It may, of course, improve readability, which is always > desirable. I think readability would be improved more by adding support in the form of special control blocks (more like if and while than def or class): class C: def f( self, a, b): pre: assert type(a) == types.int assert type(b) == types.int assert a < b post: assert (rc is None) or (type( rc) == types.list) if (a % b) > (a / b): return None return (a % b) * (a / b) Bringing this back on topic, the decorator syntax could theoretically be extended to support this: class C: def f( self, a, b): @pre: ... @post: ... if ... That is, decorators optionally could accept a block of code along with their explicit arguments. What they do with that block is up to them. Of course, I'm not familiar enough with the internals to know how feasible this would be... > "Roy Smith" wrote... >>Lastly, and perhaps most importantly, I'm rather distressed at the tone >>of some of the postings I've seen here over the past couple of days. >>Some of the sentiments I've seen expressed are downright rude, >>combative, and accusatory. These sorts of things are way out of line. Agreed. I think we're all a bit on edge at seeing something we think might still be flawed about to be canonized, but bickering won't help anything. Don't forget: if we make this too painful for the BDFL, he might just drop the whole idea and tell us to live with what we've got. :) -- Mark From unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom Sat Aug 7 04:22:40 2004 From: unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom (Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.) Date: Sat, 7 Aug 2004 10:22:40 +0200 Subject: unicode to ascii converting References: <1091815856.527127@news.commspeed.net> Message-ID: Sorry ! The COMPLETE script is : # -*- coding: cp1252 -*- aa = u"?" aa.encode("ascii","ignore") From JBrouwersAtProphICyDotCom at no.spam.net Fri Aug 6 02:11:33 2004 From: JBrouwersAtProphICyDotCom at no.spam.net (Jean Brouwers) Date: Fri, 06 Aug 2004 06:11:33 GMT Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) References: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> Message-ID: <050820042311070175%JBrouwersAtProphICyDotCom@no.spam.net> The "list-after-def" is my preference as well, more than +1. It matches existing Python syntax by using a list (or tuple?) notation, the list of keywords can span one or multiple lines and it can easily be extended with additional keywords as the need arises in the future. Apart from being non-Pythonic, my objection against the @ proposal is that it can easily be confused with comments like the (Java) doc-like notations. I am not qualfied to judge backward possible compatibility issues. /Jean Brouwers In article <6LWdnZCpvI7Ico_cRVn-hw at giganews.com>, Istvan Albert wrote: > Paul McGuire wrote: > > > Please reconsider the "def f() [classmethod]:" construct. Instead of > > invoking a special punctuation character, it uses context and placement, > > with familiar old []'s, to infuse the declaration of a function with > > special > > characteristics. If this causes def lines to run longer than one line, > > perhaps the same rule that allows an unmatched "(" to carry over multiple > > lines without requiring "\" continuation markers could be used for > > unmatched > > "["s, as in: > > > > def f() [ staticmethod, > > synchronized, > > alphabetized, > > supersized, > > returns('d') ]: > > Well said! > > Reading the posts here and in the python-dev I've counted > the following votes for it (I'm sure that there were a lot > more but it is awfully hard to keep up with the posts > on the topic). > > Voting for the "list-after-def" syntax as shown above: > > Peter Hansen > AdSR > Paul McGuire m > Phillip J. Eby pje at telecommunity.com > C. Barnes > Aahz aahz at pythoncraft.com > Skip Montanaro skip at pobox.com > Bill Janssen janssen at parc.com > Istvan Albert ialbert at mailblocks.com > > I have the feeling that this always was and still is > the favorite. > > Ladies and Gents, start your engines and rally around > this syntax (if you prefer it of course) so that there > is evidence that it should be taken as a serious candidate. > > Istvan. > From miki.tebeka at zoran.com Sun Aug 15 05:08:41 2004 From: miki.tebeka at zoran.com (Miki Tebeka) Date: Sun, 15 Aug 2004 11:08:41 +0200 Subject: Pyhton Interpreter Startup time In-Reply-To: <411B3EE1.9080002@cenix-bioscience.com> References: <411B3EE1.9080002@cenix-bioscience.com> Message-ID: <20040815090840.GE2184@zoran.com> Hello Neil, > I'm looking at a small app which would need a very quick > startup time for the Python interpreter. It doesn't do much (copying > and caching of files, no GUI) but I need the Python interpreter to start > up very quickly (<1 second on a Windows box). Is there a way to have a > 'stripped' down Python interpreter which can start up very quickly on a > windows box. Once thing I was thinking of was to use PyExe to make a > quick startup (does it compile down to C code, therefore not using the > Python interpreter at runtime?). Is this a possible solution? > > I observe that the second time I start python it starts up quicker > but I'm assuming that this is dependent on the environment and can't be > relied upon (or something like that). My guess it's that Windows first load of python23.dll takes time. The second time it's already in memory and Python loads faster. Windows have a list of "KnownDLLs" that it pre loads at startup time and they stay in memory all the time. To see if this is the problem try adding the python23.dll to: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs (The above is *one* line with space between "Session" and "Manager") HTH. -- ------------------------------------------------------------------------ Miki Tebeka http://tebeka.spymac.net The only difference between children and adults is the price of the toys From cygnus at cprogrammer.org Thu Aug 26 15:05:38 2004 From: cygnus at cprogrammer.org (Jonathan Daugherty) Date: Thu, 26 Aug 2004 12:05:38 -0700 Subject: Mysql in Python? In-Reply-To: References: Message-ID: <20040826190538.GA11042@vulcan.cprogrammer.org> # Also, PostgreSQL seems to be better supported than MySQL, although # good luck finding a web host with PostgreSQL *and* mod_python! Hey, Command Prompt provides web hosting and we only support PostgreSQL. We'd be glad to provide mod_python. http://www.commandprompt.com -- Jonathan Daugherty http://www.cprogrammer.org From prillamana at cox.net Wed Aug 4 16:39:33 2004 From: prillamana at cox.net (Aaron Prillaman) Date: Wed, 04 Aug 2004 15:39:33 -0500 Subject: error in python23.DLL Message-ID: <8QbQc.12336$Oz2.11187@okepread06> I've already posted on comp.os.ms-windows.programmer.win32 w/no replies, so i guess this is my next stop. I'm running a win32 c++ program from a shortcut. When I run the program from the build directory, it runs just fine, but when i run from the shortcut it crashes. The libraries used by the program are direct draw and python23. both of which are in the system32 folder. the actual error that occurs is a direct draw error DDERR_INVALIDRECT(which is passed the same rect as parameter when the program works and when it doesn't). I'm linking the program w/the multithreaded DLL runtime library (/MD.. i also used this to compile the python DLL). I think the actual bug is somewhere in the python23.DLL, because when i build the project without it, everything runs fine. One more thing, and I've saved the best for last: When i compile the program w/debug symbols, the error doesn't occur. So far i've been trying to figure out whats overwriting my ddsurface(the only reason I can think of that DDERR_INVALIDRECT is getting thrown). If anyone has any ideas on what might cause this, i would much appreciate it. thanks in advance From mrbrown200425 at yahoo.com Thu Aug 5 17:24:57 2004 From: mrbrown200425 at yahoo.com (Rob B) Date: 5 Aug 2004 14:24:57 -0700 Subject: import random error Message-ID: <7903bb89.0408051324.63ee1535@posting.google.com> Hello, I am just starting to learn Python and was writing a simple script on my machine (Mac OS X 10.3.4), but I can't seem to import the random module: #!/usr/bin/env python import random Results in: Traceback (most recent call last): File "./math.py", line 3, in ? import random File "/sw/lib/python2.3/random.py", line 42, in ? from math import log as _log, exp as _exp, pi as _pi, e as _e ImportError: cannot import name log I have such a feeling that this is either a) because I don't know what I'm doing or b) the python install is somehow strange. What is strange is that in interactive mode, import random works fine. Thanks in advance, Rob From brian_zimmerman at yahoo.com Tue Aug 3 05:00:04 2004 From: brian_zimmerman at yahoo.com (Brian Zimmerman) Date: 3 Aug 2004 02:00:04 -0700 Subject: New to Python/Programming References: <10gsujk1og2gkbf@corp.supernews.com> Message-ID: I'm new to all this too. I recommend Michael Dawson's "Python Programming For The Absolute Beginner" (Premier Press, 452 pages). It's really fun as it walks you through Python basics by having you make little games. By the time you are done with the book you will have made an Asteroids like game with sounds, music, and animation. I think it was written with kids in mind, not that it's simple, just somehow really clear. THE BAD: The book's CD has only MS Windows versions of the software used. Most of the book's examples are cross platform (if you do your own downloads and installs), except for things that use Livewires. The author says that he made changes to the standard Livewires library, so you might get frustrated towards the end if you use Linux or Mac. I hope that gets fixed because other than that, I think this is just about the perfect intro book for younger programmers. Not to knock Alan Gauld's "Learn to Program Using Python" (Addison-Wesley, 270 pages). It's also a great beginner's book. I enjoyed reading that too. Alan's book gets straight to the point, and feels more "Intro to Computer Science" minded. It explains some theory and terminology, then shows how that works in Python, and a bit about other languages. Dawson's book is more like we're gonna make a game, here's what we do to build it. From rob at nospam.net Tue Aug 17 15:17:17 2004 From: rob at nospam.net (Robert Ferber) Date: Tue, 17 Aug 2004 21:17:17 +0200 Subject: Databases: Getting values by column name References: Message-ID: Skip Montanaro wrote: > Yes, for MySQLdb import the MySQLdb.cursors module then set the > cursorclass arg when you create a connection, like so: > > import MySQLdb > import MySQLdb.cursors > ... > conn = MySQLdb.Connection(host=..., > user=..., > passwd=..., > db=..., > cursorclass=MySQLdb.cursors.DictCursorNW, > ...) You mean MySQLdb.connect()? > I think the reason this sort of behavior isn't spelled out in PEP 249 is > because it varies too much from one database to another. Psycopg (a > PostgreSQL adaptor) does it differently. Instead of specifying the cursor > type when the connection is created, you instantiate a different cursor > class: > > conn = psycopg.connect("...") NameError: name 'psycopg' is not defined Also wouldn't that overwrite the above conn variable? > ... > cursor = conn.dictcursor() AttributeError: Connection instance has no attribute 'dictcursor' (When I use the conn from MySQLdb.connect) > I imagine there are some databases that either don't support name-based > retrieval very well (or at all), or make it difficult to get at. You > might get a more solid response on the reasons for this omission from PEP > 249 from the db-sig folks: > > http://www.python.org/sigs/db-sig/ Isn't there any documentation with a simple example out there? I already know the stuff on that page, it's really slowing you down :-( Robert From pm_mon at yahoo.com Tue Aug 24 10:19:41 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Tue, 24 Aug 2004 10:19:41 -0400 Subject: __name__ becoming read-write? In-Reply-To: References: <3b8ki0tlphodtt8ge8an274qp78ihp1i3n@4ax.com> Message-ID: Arthur wrote: > >>"So wait, this stuff that _looks_ like code in a >>function, isn't actually? what the hell?" The new syntax[1] for >>decorators is at least very obvious that something _new_ is going on. > > > I am thinking (and I think Paul is thinking) that we can say the same > thing, succintly, in a manner that has precedence in the language > Absolutely. That's a good way to think about it. From aleaxit at yahoo.com Thu Aug 26 04:25:10 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Thu, 26 Aug 2004 10:25:10 +0200 Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> Message-ID: <1gj4fb5.607xsc51izh8N%aleaxit@yahoo.com> Martin DeMello wrote: ... > My main point is that returning None is pretty useless - it 'wastes' the > return value, and doesn't allow method chaining. Returning self allows > you to either use or discard the return value depending on whether > you're interested in it, whereas using None doesn't give you any choice. >>> import this The Zen of Python, by Tim Peters [snipped] There should be one-- and preferably only one --obvious way to do it. Not leaving stylistic choice (which would lead to more than one obvious way to do it) is quite consonant with the Zen of Python. Of course one can't always reach what's preferable, but "your main point" which is presumably meant as a criticism of this design choice comes across as praise: the design choice follows the overall design's philosophy. Guido doesn't like method chaining, so he made a design choice that did not allow method chaining, and did not give several equally obvious ways to perform some typical, important tasks. This consistency between detailed design decisions and overall philosophy is exactly that Quality Without a Name which makes Python so great. Alex From b.niemann at betternet.de Thu Aug 19 11:51:08 2004 From: b.niemann at betternet.de (Benjamin Niemann) Date: Thu, 19 Aug 2004 17:51:08 +0200 Subject: HTMLParser question In-Reply-To: References: Message-ID: Rajarshi Guha wrote: > Hi, > I have some HTML that looks essentially consists of a series of
    's > and each
    having one of two classes (tnt-question or tnt-answer). > I'm using HTMLParser to handle the tags as: > > class MyHTMLParser(HTMLParser.HTMLParser): > > def handle_starttag(self, tag, attrs): > if len(attrs) == 1: > cls,whichcls = attrs[0] > if whichcls == 'tnt-question': > print self.get_starttag_text(), self.getpos() > def handle_endtag(self, tag): > pass > def handle_data(self, data): > print data > > if __name__ == '__main__': > > htmldata = string.join(open('tt.html','r').readlines()) > parser = MyHTMLParser() > parser.feed( htmldata ) > > However what I would like is that when the parser reaches some HTML like > this: > >
    > How do I add a user to a MySQL system? >
    > > I should get back the data between the open and close tags. However the > above code prints the text contained between all tags, not just the
    > tags with the class='tnt-question'. > > Is there a way to call handle_data() when a specific tag is being handled? > Placing a call to handle_data() in handle_starttag seems to be the way - > but I';m not sure how to actually do it - what data should I pass to the > call? Set a flag, when you the parser calls handle_starttag() and the tag matches your criteria, unset it, when the corresponding endtag is found (you'll probably have to count the nesting depth, so for
    Yo
    man
    !
    the flag is unset on the second
    ). Then in handle_data() only print it, when the flag is set. From __peter__ at web.de Mon Aug 30 16:45:49 2004 From: __peter__ at web.de (Peter Otten) Date: Mon, 30 Aug 2004 22:45:49 +0200 Subject: xml.dom.minidom - documentElement vs. childNodes References: Message-ID: Skip Montanaro wrote: > I'm getting somewhat painfully acquainted with xml.dom.minidom. What is > the relationship between its documentElement attribute and its childNodes > list? > I thought XML documents consisted of a single, possibly compound, node. > Why is a list of childNodes needed? >>> import xml.dom.minidom as md >>> dom = md.parseString("""""") >>> dom.childNodes [, ] >>> Seems like comments are preserved in childNodes, too. Peter From megalomaan at hotmail.com Thu Aug 26 14:55:58 2004 From: megalomaan at hotmail.com (m0226065) Date: Thu, 26 Aug 2004 20:55:58 +0200 Subject: Looking for a mySQL module Message-ID: <1093546553.242839@seven.kulnet.kuleuven.ac.be> Hello I'm looking for a mySQL module so I can address my miniserver (http://miniserver.sourceforge.net). I looked on google, but I'm not sure I'm getting what I want thx -- ____________________________________________________ Johan Potums Vaartstraat 67 3000 Leuven --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.737 / Virus Database: 491 - Release Date: 11/08/2004 From ialbert at mailblocks.com Sun Aug 15 12:06:25 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Sun, 15 Aug 2004 12:06:25 -0400 Subject: Decorators: an outsider's perspective In-Reply-To: References: <20040814153534.8AC171E4007@bag.python.org> Message-ID: Paul Morrow wrote: > That reminds me of how I once thought about using indentation as a means > of denoting code blocks. How idiotic I thought that was. Now I realize > the elegance, beauty, 'genius' in that. I disagree. In C (Perl, Java etc) we would do three things, write braces, indent and put the semi-colon. In python we replaced these three, with a single (the most obvious) one the indentation. > Why don't we all just acknowledge that we are doing this? Why don't we > all just admit that a well written instance method uses 'self' as its > first argument. And well written static or class methods (as well as If so then, the logically equivalent solution would be to pass self as an implicit parameter, say a named parameter self with a default reference to itself. I'm not suggesting this behavior, I only point out what I think follows from the first example. The end goal is to simplify the behavior not overload it and thus add further meaning to it. I do agree with Chas Emerick in that encoding special behavior in variable names is a fragile solution. Istvan. From dyoo at hkn.eecs.berkeley.edu Tue Aug 24 12:27:05 2004 From: dyoo at hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 24 Aug 2004 16:27:05 +0000 (UTC) Subject: scanf-1.0 for Python Message-ID: Hi everyone, I've implemented a scanf-like module in pure Python: http://hkn.eecs.berkeley.edu/~dyoo/python/scanf/ If you've ever had the itch to do something like: ### import scanf (cmd, errors, warnings) = ( scanf.sscanf("/usr/sbin/sendmail - 0 errors, 4 warnings", "%s - %d errors, %d warnings")) ### I hope this helps! From iketo2 at netscape.net Fri Aug 27 21:50:33 2004 From: iketo2 at netscape.net (Isaac To) Date: 28 Aug 2004 09:50:33 +0800 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> <87hdqok9i6.fsf@sinken.local.csis.hku.hk> <1rfz68ely9.fsf@rovereto.ifi.uio.no> <876574k7du.fsf@sinken.local.csis.hku.hk> <1r3c28ejis.fsf@rovereto.ifi.uio.no> <1rllg0cb3m.fsf@rovereto.ifi.uio.no> Message-ID: <874qmovxna.fsf@sinken.local.csis.hku.hk> >>>>> "Kjetil" == Kjetil Torgrim Homme writes: Kjetil> I find this attitude a little defensive. Python has much Kjetil> more to offer than just strict indentation. although it's Kjetil> probably the feature you notice first, it's not enough to Kjetil> make Python a superior language. For me, it is *the* feature that make it stands out from the scripting crowd. There are other things nice in Python, but as long as there is one big enough killing feature, people will use the language enough to add others. Kjetil> after all, code in _any_ language written by a Kjetil> professional will have strict indentation. so it's just Kjetil> syntax. No. In all other languages, people deal with *two* ways to find which statement is associated with an if/while/for/whatever statement and which is not: by looking at the indentation, and by looking at the braces. They normally look at the indentation, since it is the quicker way. But when they find something wrong, they look at the defining braces, sometimes deeply hidden in long expressions and statements combined into one line. In Python, we have *one and only one* way to find which statement is associated with an if/while/for/whatever statement, and this is the quicker way that people are used to. This single feature reduces the amount of bugs that you would introduce when editing and modifying code. More importantly, this single feature allows you to be much less stressed when editing code. Regards, Isaac. From skip at pobox.com Wed Aug 4 14:06:16 2004 From: skip at pobox.com (Skip Montanaro) Date: Wed, 4 Aug 2004 13:06:16 -0500 Subject: guide to introspecting python? In-Reply-To: References: Message-ID: <16657.9624.146998.907297@montanaro.dyndns.org> Mark> def rdir(item, v=""): Mark> print "%s%s"%(v,item) Mark> for i in dir(item): Mark> rdir(i, v+" ") Mark> import os Mark> rdir(os) Problem is, dir() is already recursive: >>> class A: ... def a(self): pass ... >>> class B: ... def b(self): pass ... >>> class C(A,B): pass ... >>> c = C() >>> dir(c) ['__doc__', '__module__', 'a', 'b'] >>> dir(C) ['__doc__', '__module__', 'a', 'b'] As others have suggested, the inspect module is probably a good place to start. Skip From abra9823 at mail.usyd.edu.au Wed Aug 4 19:15:34 2004 From: abra9823 at mail.usyd.edu.au (Ajay Brar) Date: Thu, 05 Aug 2004 09:15:34 +1000 Subject: bsddb port Message-ID: <41116E16.7000100@mail.usyd.edu.au> hi! does anyone know of a bsddb port to pocket pc 2002. thanks -- Ajay Brar CS Honours 2004 Smart Internet Technology Research Group http://www.it.usyd.edu.au/~abrar1 From apavluck at gmail.com Fri Aug 20 15:36:48 2004 From: apavluck at gmail.com (Alex Pavluck) Date: 20 Aug 2004 12:36:48 -0700 Subject: I know SAS (sort of)...now, PYTHON Message-ID: Hello. I use SAS on a daily basis and it has peaked my interest in learning other programming languages. Are there any good websites/online books that can help someone go from zero knowledge of python and programming to beginner level through exercises? Thanks! Alex From apardon at forel.vub.ac.be Mon Aug 16 05:28:11 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 16 Aug 2004 09:28:11 GMT Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: Op 2004-08-16, Peter Hansen schreef : > Keith P. Boruff wrote: > >> beliavsky at aol.com wrote: >> >>> One of the most commmon reasons programmers cite for not trying Python >>> is that indentation determines the program flow -- they think its >>> weird. I think programmers who actually try Python adapt quickly and >>> do not find the indentation rules to be a problem. >> >> Honestly, I'm still not too crazy about the indentation requirements of >> the language myself, coming from a background of using all free form >> languages. > > Did you really not indent your code in those languages consisntly > anyway? I can't answer for keith, but my answer is that it depends on what you consider consistent. My indentation was consistent with the structure of the algorithm. That is not necesarrily the same as the structure you implemeted that algorithm in. I think that I should be the final judge of what is the most appropiate way to use indentation, not the compilor/interpreter, even if it agrees with me. -- Antoon Pardon From xavier.combelle at free.fr Sun Aug 8 00:18:28 2004 From: xavier.combelle at free.fr (Xavier Combelle) Date: Sun, 08 Aug 2004 06:18:28 +0200 Subject: decorators vs GIL In-Reply-To: References: Message-ID: <4115a8aa$0$19945$626a14ce@news.free.fr> >>I have no problems with Python's performance in my >>applications. I avoid threads because they're error-prone, >> >> > >Isn't that like saying, I avoid programming in general because it's >error-prone? I don't follow. > > I don't agree with the comparison. Programming may be error prone, but can you suggest something to replace it? In the other side, there is different way to avoid threads: make a heavy process, doing a single event loop. You should have a really special and hard work to use them routinely. From charleshixsn at earthlink.net Tue Aug 24 02:27:23 2004 From: charleshixsn at earthlink.net (Charles Hixson) Date: Mon, 23 Aug 2004 23:27:23 -0700 Subject: Time-date as an integer Message-ID: <412ADFCB.5070902@earthlink.net> This is a concept, not a finished program, and an extract from a class at that...so forgive any illegalities, but: import datetime; def calcNodeId(self): t = datetime.utcnow() val = t.year * 133920000000 + # 12 months t.month * 11160000000 + # 31 days t.hour * 3600000000 + # 60 minutes t.minute * 60000000 + # 60 seconds t.second * 1000000 + t.microsecond if val <= self._dTime: val = self._dTime + 1 self._dTime = val return val This is the best that I've been able to come up with in getting a date-time as an integer. It feels like one of the time or date libraries should have a better solution, but if so, I haven't found it. Can anyone suggest a better approach? From indigo at bitglue.com Wed Aug 25 18:40:23 2004 From: indigo at bitglue.com (Phil Frost) Date: Wed, 25 Aug 2004 18:40:23 -0400 Subject: Just a quick one In-Reply-To: References: Message-ID: <20040825224023.GA1258@unununium.org> A tuple (actually, any iterable) can be converted to a list by using list(), like so: list( (1, 2, 3) ) ==> [1, 2, 3] In fact, most types can be converted like so, str(), list(), dict(), tuple(). You can always do "help(str)" in Python for more verbose information. On Wed, Aug 25, 2004 at 03:00:11PM +0100, M. Clift wrote: > Hi Benjamin, > > Sorry, another question. How do I remove the brackets form the list? > Name_List.remove('(') doesn't work. > > Thanks, > > M From anthonybaxter at gmail.com Thu Aug 5 21:51:18 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 11:51:18 +1000 Subject: Decorator keyword In-Reply-To: References: Message-ID: On 5 Aug 2004 17:17:39 -0700, Steven Bethard wrote: > I was just going to let this go because I thought it had been shut > down, but as it seems to have been reopened, I'd love to see something > like: > > with classmethod > with returns(int) > def func(*args, **kwds): > return 1 "with" is a non-starter - there's already other plans to use with for other things, at some distant point. Also, if we're to have a new keyword, it should be _much_ more obvious than 'with'. From luismg at gmx.net Sun Aug 22 10:42:41 2004 From: luismg at gmx.net (Neuruss) Date: 22 Aug 2004 07:42:41 -0700 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> <7xk6vsgh3i.fsf@ruckus.brouhaha.com> Message-ID: <278de0e.0408220642.3c2274a0@posting.google.com> > They already are (Lisp, etc.) That's a surprise! I didn't know about Lisp, so I did a quick search in Google and I found this quote from CMUCL website: "a sophisticated native-code compiler which is capable of powerful type inferences, and generates code competitive in speed with C compilers." Has anyone tried to learn from this experience? Could this technology be used with Python? Regarding you Paul, I also found this: "There's another guy I'd also like to invite, a Lisp expert, if that's ok with you. He's been interested in writing a Python compiler for a while. I'll ask him if he wants to join, but he might not." What happened? From tismer at stackless.com Mon Aug 9 08:10:16 2004 From: tismer at stackless.com (Christian Tismer) Date: Mon, 09 Aug 2004 14:10:16 +0200 Subject: Going the PL/1 way In-Reply-To: References: Message-ID: <411769A8.40200@stackless.com> Mikl?s wrote: ... >>This is the basic idea what a decorator does: >>Make modifiers like classmethod into a prefix >>of a function. > > > Great, so it's still about code modification. No, this is, with respect, nonsense. > With Python decorators, a method/function can be modified virtually in any > way, outside its declaration. No. You cannot do anything that could not be done without decorators, before (at least today). > Sure you could override things before, too, but now this is a request for > code abuse. My explanation was *not* meant as a request for list abuse. -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From grepninja at yahoo.com Wed Aug 25 16:07:01 2004 From: grepninja at yahoo.com (John Tobler) Date: 25 Aug 2004 13:07:01 -0700 Subject: Has anyone implemented BASIC in Python? References: <2oo13eFcj548U1@uni-berlin.de> <2ot30hFeek8nU1@uni-berlin.de> <9h0ji0lvc0be65nuvcugaa3vsq5mcl3ck8@4ax.com> <2otkvkFe7p8oU1@uni-berlin.de> Message-ID: Leif K-Brooks wrote in message news:<2otkvkFe7p8oU1 at uni-berlin.de>... > Is there a (virtual) book you would recommend reading to learn about > writing them? A course isn't really possibly for me, so I'm hoping that > isn't the only option. You do not need to spend a penny for books or information about compiler writing. Let's go fishing! Start with the Open Directory Project: http://dmoz.org/Computers/Programming/Compilers/ ... and Google's equivalent of it (which incorporates the ODP but may modify or supplement its results): http://directory.google.com/Top/Computers/Programming/Compilers/ >From those two links, alone, you should be able to find everything from excellent beginner tutorials to advanced theoretical references. Now, let's try a simple Google search for "compiler writing": http://www.google.com/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=compiler+writing ... and "compiler theory" http://www.google.com/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=compiler+theory ... and "tutorial+compiler" http://www.google.com/search?hl=en&lr=&ie=UTF-8&q=tutorial+compiler&btnG=Search Then, let's narrow our scope to tiny things: http://www.google.com/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=tiny+compiler That should give you some reasonably-sized learning projects to emulate. Have fun! John Tobler CSharpener's Weblog: http://weblogs.asp.net/jtobler/ From pf_moore at yahoo.co.uk Mon Aug 23 15:18:08 2004 From: pf_moore at yahoo.co.uk (Paul Moore) Date: Mon, 23 Aug 2004 20:18:08 +0100 Subject: Standard graph API? References: Message-ID: "Robert Brewer" writes: >> Is there any interest in a (hypothetical) standard graph API (with >> 'graph' meaning a network, consisting of nodes and edges)? > > 1) Yes! > 2) Only if it's in C. I don't mind (re)writing pure Python graph > containers, it's the speed of a pure Python graph that's the bigger > issue to me (mostly object inspection and/or > decorate-insert-retrieve-undecorate cycles). If it started in a > pure-Python package, then went into the stdlib, and then got a C > implementation (like sets.py did), that would be fine. > 3) It would have to accept arbitrary objects. No "make your class a > subclass of GraphNode" garbage. If someone wanted to make a subclass of > Graph called StringGraph, which was optimized for strings, or IntGraph > optimized for ints, that would be fine. But the base class (I assume a > class implementation?) should handle instances of Object. > > I'm sure there are many more details, but those are the big ones IMO. 1) Yes, from me as well. I've not used graphs in Python much, but mainly because I found that I got sidetracked from my original project into implementing graph algorithms, and never completed the original job :-) 2) I don't see a need for C at the start. prototype in Python, and migrate to C if the speed is needed. Like the set datatype did. But aim for fast Python, so that a C implementation can be avoided if it's unnecessary. 3) Definitely arbitrary objects. I'm not sure about a Graph class, even - given that the dictionary of adjacency lists implementation is so easy to build, it may be worth writing algorithms that just depend on a graph "protocol". Something like: for n in g iterates through all nodes in g, for m in g[n] iterates through all nodes adjacent to n, and for cases where edge weights are needed, g[n][m] is the weight of edge n->m. You can get a long way on just those primitives. If we had adaptation in Python (PEP 246) I'd suggest an IGraph protocol, plus adapters for common implementation methods. In my personal graph library, I found that one of the nastiest issues was writing suitably general DFS/BFS algorithms which had "hooks" at relevant points (node visited in preorder, inorder, and postorder, for example) without swamping the runtime of the algorithm with calls to possibly dummy hook functions. I'm not sure that a C implementation would help here, but good design and fine tuning certainly would. (If anyone wants to see my current code, I'd be happy to share it). Paul. -- In theory, there is no difference between theory and practice; In practice, there is. -- Chuck Reid From tdelaney at avaya.com Tue Aug 24 18:32:23 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Wed, 25 Aug 2004 08:32:23 +1000 Subject: PEP318: radical notion Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01DCF4DB@au3010avexu1.global.avaya.com> Arien Malec wrote: > Is there a valid use case that supports arbitrary magical non-metadata > transformations of standalone functions? PyObjC. Tim Delaney From anthonybaxter at gmail.com Mon Aug 16 03:01:15 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Mon, 16 Aug 2004 17:01:15 +1000 Subject: AntiDecorator metaclass In-Reply-To: References: <411dfe05$0$6142$626a14ce@news.free.fr> Message-ID: On Sat, 14 Aug 2004 08:15:43 -0400, Paul Morrow wrote: > No I don't want to say that. I want to say that decorators should keep > their nose out of the classmethod/staticmethod business. So what's the point of this, then? You say it's an "anti-decorator" metaclass. It's not. It's simply a way to automagically invoke a couple of standard decorators from a metaclass, based on people following a convention. It does little or nothing to address many of the other requirements for decorators, is brittle (see my previous post on the subject) and relies on something that is merely a convention, and deliberately so. > And it makes the problem space that > decorators address smaller (as it becomes everything you want decorators > to do minus the classmethod/staticmethod stuff), which might give rise > to a better, less objectionable solution. I fail to see how your hack, which merely removes two of the most trivial examples of decorator use, addresses anything in the general case. As far as a "better, less objectionable solution" - as I've said time and time again, this subject has had 2+ years of discussion. Do you honestly expect that 2 or 3 more weeks here or there is going to produce some blinding flash of insight? I'd love it to be true, but really, I can't see it. From chris.cavalaria at free.fr Thu Aug 26 14:58:22 2004 From: chris.cavalaria at free.fr (Christophe Cavalaria) Date: Thu, 26 Aug 2004 20:58:22 +0200 Subject: Call for signatories for J2 References: Message-ID: <412e32ce$0$18809$626a14ce@news.free.fr> Bernhard Herzog wrote: > "Robert Brewer" writes: > >>> For >> >> Isn't *anyone* going to vote against? > > I'm against it. I don't find the arguments in favor of J2 convincing, > and to my eyes the pie-syntax reads better. > > Also, I don't think "using" is a good choice for the keyword. A > different keyword would not change my mind, though. > > Bernhard > Same here. I don't mind too much the J2 syntax seeing that there were far worse proposals but I find that the @pie syntax reads better too. And I don't like using and I loath per ( too close to pre and only know to good english speakers, it is bound to create a lot of mistakes ) as a keyword for J2. Until there is a better keyword proposal I'm against it. From adurdin at gmail.com Sun Aug 8 10:27:53 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Mon, 9 Aug 2004 00:27:53 +1000 Subject: @decorator syntax is sugar, but for what exactly? (decorator libraries). In-Reply-To: References: Message-ID: <59e9fd3a040808072741d01ae@mail.gmail.com> On Sun, 08 Aug 2004 10:19:19 -0400, Roy Smith wrote: > > The key question is whether the decorator mechanism would allow such a > thing? All of the examples I've seen have the decorator defined right > before it's used, and having a simple name. I'm guessing that the real > syntax is @, and that any expression that evaluations to a > callable object is kosher after the "@"? There was some discussion about this on python-dev, and the BDFL's conclusion was that arbitrary expressions were not allowed, but only dotted names (with optional parentheses), i.e.: @decorator @module_or_object.decorator @func_returning_decorator(args) @module_or_object.func_returning_decorator(args) (With presumably multiple dotted levels allowed, e.g. module.object.decorator) See http://www.python.org/dev/doc/devel/ref/function.html for the grammar definition. From bokr at oz.net Tue Aug 10 20:12:44 2004 From: bokr at oz.net (Bengt Richter) Date: 11 Aug 2004 00:12:44 GMT Subject: remaining decorator syntax options References: Message-ID: On 10 Aug 2004 12:33:36 -0700, steven.bethard at gmail.com (Steven Bethard) wrote: >So here's the state of the decorator debate as I see it: > > >*** Location > >GvR pretty strongly wants decorators before the function: > >http://mail.python.org/pipermail/python-dev/2004-August/047112.html >http://mail.python.org/pipermail/python-dev/2004-August/047279.html > >The idea being that decorators and other function properties should >not look like part of the function's code. I don't think there's much >chance of swaying GvR on this count. > > >*** Indentation > >Since location has been pretty much decided, I see three options here: > >(1) > dec >def f(): > pass > >(2) > > dec >def f(): > pass > >(3) > dec > def f(): > pass > (4) dec def f(): pass Suggested indicator: '(=' or '(:' or '(%' e.g., dec(= def f(): pass >GvR definitely disliked the third version because it meant that class >functions could all be at different indentation levels. The PEP >suggests that the second version was disliked because it suggests that >"using" is introducing a new scope (although arguments about if/else >behavior seemed to counter this somewhat). There didn't seem to be >any arguments that made version 2 drastically better than version 1 >though, so it seems most likely that a BDFL pronouncement will give us >version 1. > > >*** List notation > >Assuming a pre-def, non-indented decorator, here are the remaining >list notations: > >(1) > dec1 > dec2 > dec3 > >(2) > [dec1, dec2, dec3] > >(3) > dec1, dec2, dec3 > (4) dec1 dec2 dec3 e.g., dec1(= dec2(= dec3(= def f(): pass >I believe that version 3 was vetoed because it makes it too hard to >break lists of decorators across lines. GvR's preference is >definitely for 1, but that may be influenced by his decision for the >indicator. I have a feeling that how long the indicator is directly >affects which of (1) or (2) is preferred. Compare: > >@dec1 >@dec2 >@dec3 > >vs. > >@[dec1, dec2, dec3] > >and > >using dec1 >using dec2 >using dec3 > >vs. > >using [dec1, dec2, dec3] > >It seems like with a single symbol character, the non-list syntax is >much more concise, and probably clearer. However with a keyword >syntax the list seems the better option. > >Which brings us, of course to the final section: > >*** Indicator > >The options seemed to be: > >(1) a symbol (@, |, etc.) >(2) a keyword (using, decorate, etc.) >(3) similar to function >(4) no indicator > (5) postfixed indicators [ (: (= (% <<< etc ] dec1 (= dec2 (= def foo(): pass >Options (3) and (4) were ruled out because (given that we're already >relegated to a before-def syntax) they are already valid syntax, and >redefining them for decorators means changing the expected semantics >of the statements. > >Option (1), with @, is GvR's favorite, and does have something of a >Java backing. It has the substantial disadvantage that there is no >particular reason (or even some sort of mnemonic) for which @ (or | >for that matter) should mean "decorator". > >With option (2), we can choose a keyword that does suggest a >decorator. Even "using", which is not an outstanding choice, is at >least more intuitive than '@'. Option (2) does have the disadvantage >that it requires introducing a new keyword, but this is not >insurmountable -- it was done before for generators. And GvR even >said that he would consider this option if there enough support for >it. > >---- > >So here's my suggestions: > >Let's leave the location and indentation arguments behind. We're not >making much progress on them, and I don't think there's much chance of >swaying GvR. Reiterating all the old arguments won't get us closer to >a syntax we're happy with. > >I think once the indicator argument is decided, the list-structure >decision will fall out of it. > >So I'd suggest that we put all our effort into the indicator >discussions. If you have a good argument for why a keyword is better >than a symbol, or why a symbol is better than a keyword, please voice >them now. And remember that 'because it's prettier' or 'because it's >uglier' are not aguments GvR will consider. We need strong arguments, >that argue on the basis of readability or learnability or >maintainability, etc. You don't think GvR goes for prettier, other things being equal? > > >... and my opinion: > >A keyword is much more Pythonic than a symbol: Yes, except that what we have is really nested function calls, passing a special argument, so maybe the decorating functions ought to look like they are being invoked as functions. I.e., deco1( deco2( arg_that_happens_to_be_created_by_a_def_statement_and_suite )) But, since it's not an ordinary argument list, we need an alternative to the function-calling expression trailer (...) that yet suggests calling. Since the def defines its own end, we don't need the )) above, but we do need a different '(' -- so I'm suggesting (= or maybe (: or (% or <<<, so the above simply becomes deco1(= deco2(= arg_that_happens_to_be_created_by_a_def_statement_and_suite and deco1 and deco2 can just be arbitrary expressions evaluating to something callable. If other statement:suite blocks can be interpreted as defining arguments useful to pass to a function, then func(= statement: suite could be used in a generalized way to operate on those. The loose end here is re/binding the function (or class, etc) name. I.e., would you want to write foo = deco1(= deco2(= def foo(): pass ? Or maybe foo = ( deco1(= deco2(= def foo(): pass ) So long as postfixed (= is just sugar for the current use case, it doesn't matter, of course. The rebinding can be a side effect of an expression whose value is discarded. > >A well chosen keyword can suggest the meaning of the construction, >e.g. "using ... def ..." suggests that the decorators are used as part >of the definition of the function. A symbol like '@' or '|' cannot >easily suggest the meaning in this manner. But deco(...) suggests calling deco with something, and that's what's happening. We just need to distinguish the def-result-as-argument variant, IMO. > >For this reason, a keyword makes both reading and learning Python >decorator syntax easier. If you encounter "using ... def ..." and >have to guess at it's meaning, your knowledge of English "using" can >now be applied to guess the meaning of Python "using". This is not >true of a symbol like '@' or '|'. see above ;-) > >(An additional argument might be that it will be at least /possible/ >to Google "using", but impossible to do so for "@" or "|". This was >one of the frustrating things about Perl for me -- if I didn't know >what a symbol did, I couldn't Google it because it wasn't a word. >Remember that if you don't know it's a decorator, you don't know to >search for "decorate" ;) I do like google. How about a postfixed keyword indicator like 'munges' ;-) deco1 munges deco2 munges def foo(): pass ;-) > > >hoping-to-keep-this-dicussion-productive-ly-yrs, > hoping-to-have-added-something-useful-ly-yrs, Regards, Bengt Richter From nicksjacobson at yahoo.com Tue Aug 17 07:02:02 2004 From: nicksjacobson at yahoo.com (Nick Jacobson) Date: 17 Aug 2004 04:02:02 -0700 Subject: Simple exceptions question References: Message-ID: Thanks for the reply! I'm definitely trying this out.. > the python interpreter. Its easy to find out, which statement caused > the exception. How can you do that? > Yes: create your own list class (maybe by inheriting list). Give each > instance an unique name. Use a setitem method like this: > > class seq(list): > # some code suppressed... > def getitem (self,index): > try: list. getitem (self,index) > except IndexError,e: > e.index = index > e.name = self.name > raise e > > Thus you can write the except clause as: > > except IndexError, e: > print "Accessed array ", e.name, " out of bounds at", e.index > > Mathias It says that "self.name" is undefined: "AttributeError: 'seq' object has no attribute 'name'" From pinard at iro.umontreal.ca Mon Aug 23 12:55:33 2004 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Mon, 23 Aug 2004 12:55:33 -0400 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: <20040823165533.GA9841@titan.progiciels-bpi.ca> My vote (once again): J2 J2 J2 repeated here juste in case I should have kept the same Subject for it. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From jjl at pobox.com Thu Aug 12 16:18:58 2004 From: jjl at pobox.com (John J. Lee) Date: 12 Aug 2004 21:18:58 +0100 Subject: The winner of the Python Decorator Poll is... References: <4edc17eb.0408112052.1bbd85b3@posting.google.com> Message-ID: <87acx0p0st.fsf@pobox.com> Doug Holton writes: > Michele Simionato wrote: > > Indeed. Actually I did not vote since I like the current proposal (maybe > > I would like "|" more than "@") and I dislike all the alternatives, > > especially having decorators inside the def. > > So the poll is unavoidably biased. Happily, we are not in a > > democracy! > > > Do you think there are 400 people out there that read about the poll > but didn't vote because they like the current proposal as it stands? Of course. *easily* > That's what would have had to have happened for bias to completely > invalidate the results. Er, yup. John From nzanella at cs.mun.ca Thu Aug 19 13:43:15 2004 From: nzanella at cs.mun.ca (Neil Zanella) Date: 19 Aug 2004 10:43:15 -0700 Subject: Unix applications in python: production install questions Message-ID: Hello, What is the best way to install a python application under Unix. Since python modules are platform independent I would guess these should be placed under an application specific directory under either /usr/share or /usr/local/share with a corresponding link to the main module(s) under /usr/bin or /usr/local/bin for user applications and /usr/sbin or /usr/local/sbin for system applications. Assuming this is done, should .pyc and .pyo files also be placed under /usr/share or /usr/local/share? These are platform independent byte code so they definitely go there if anywhere. The question is whether the installer should install these files or not. Provided the installer is to install these files, then how can they be generated. Usually these are created automatically each time the user runs python on a given module, but is there another way to generate them and should they really be installed separately in a production scenario or not? Thanks, Neil From grante at visi.com Wed Aug 25 12:54:21 2004 From: grante at visi.com (Grant Edwards) Date: 25 Aug 2004 16:54:21 GMT Subject: Getting at the bits of a 32-bit integer References: <85b54e91.0408231552.75f85727@posting.google.com> <412a98f4$0$65569$a1866201@newsreader.visi.com> <412cb279$1@nntp0.pdx.net> <412cb407$0$62953$a1866201@newsreader.visi.com> Message-ID: <412cc43d$0$8084$a1866201@newsreader.visi.com> On 2004-08-25, Jesper Ribbe wrote: >> The other thing that looks very useful is a module posted a few >> weeks back that impliments fixed-length numbers. In addition >> to manipulating individual bits, one often needs to do >> operations on binary, two's compliment numbers of known, fixed >> lengths. >> > > I'm very interested in this module which implements fixed-length > integers. Do you perhaps have some reference to it? I tried to google > for it, but couldn't come up with distinct enough keywords. http://groups.google.com/groups?selm=m3pt6qpzan.fsf%40pc150.maths.bris.ac.uk&rnum=10 I think that automatic coercion of regular Python integer values to fixed "Field" objects would make it simpler to use. -- Grant Edwards grante Yow! UH-OH!! I put on at "GREAT HEAD-ON TRAIN visi.com COLLISIONS of the 50's" by mistake!!! From peter at engcorp.com Sat Aug 21 22:07:20 2004 From: peter at engcorp.com (Peter Hansen) Date: Sat, 21 Aug 2004 22:07:20 -0400 Subject: sock.recv() in Windows In-Reply-To: References: Message-ID: Jason wrote: > Hi, > > When using the socket module in Python 2.3 for windows, I'm having problems > using socket.recv(int). The function works fine on its own, but when I > attempt to encapsulate the socket functions into a class method, my script > just hangs with the Python DOS window open. > > My class method is simple: > > def getData(self, max_size=1024): > return self.sock.recv(max_size) > > Why would an instance of this class cause python to hang in windows? Define "hang". You do realize that socket.recv() is blocking by default, and will "hang" until data arrives, don't you? I don't think you've given nearly enough info for anyone to do more than guess wildly here... -Peter From tor.iver.wilhelmsen at broadpark.no Thu Aug 26 03:44:17 2004 From: tor.iver.wilhelmsen at broadpark.no (Tor Iver Wilhelmsen) Date: 26 Aug 2004 09:44:17 +0200 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: Rich Teer writes: > I think you're getting confused with the Blue ?yster Cult. Actually, there is also The Cult, a British band that lasted from 1984-1995. http://www.allmusic.com/cg/amg.dll?p=amg&sql=11:5qktk6gx9kr3~T1 From Michael.J.Fromberger at Clothing.Dartmouth.EDU Mon Aug 30 19:58:29 2004 From: Michael.J.Fromberger at Clothing.Dartmouth.EDU (Michael J. Fromberger) Date: Mon, 30 Aug 2004 19:58:29 -0400 Subject: Generator expressions v/s list comprehensions References: <1gj8y77.6qshr41q531veN%aleaxit@yahoo.com> <87llfywooz.fsf@sinken.local.csis.hku.hk> <1gjbs1e.assxlxlud1m0N%aleaxit@yahoo.com> Message-ID: In article <1gjbs1e.assxlxlud1m0N%aleaxit at yahoo.com>, aleaxit at yahoo.com (Alex Martelli) wrote: > Mahesh Padmanabhan wrote: > > > > I just wish that generator expressions had been designed into the > > language without going the way of list comprehension -> generator > > expressions. > > It would sure be nice if Python had been born back from day one with all > the neat features it has taken years to develop -- that way we wouldn't > have any issues that are there just because of backwards compatibility. > > Unfortunately, this wish is totally unrealistic -- obviously people do > come up with cool ideas such as the iterator protocol, and generators, > after the language has been around for a while. All the cool features Python has adopted existed a long time before they made their way into Python itself. As I see it, the real issue with taking up new language features is that the vast majority of work-a-day programmers seem to be highly reticent to embrace new tools and ideas, for one reason or another. I think this explains -- among other things -- the lingering popularity of languages like BASIC (in its various incarnations), and Fortran. In fact, one of the things I love most about Python, both the language and the community surrounding it, is that here, for the first time, we see a large community of mainstream programmers who are ready, willing, and able to adapt to new ideas without losing their heads and retreating into the ostensibly safe and comfortable world of linear imperative programming. Instead of insisting everybody forget what they know and start over, however, Python gives us the old familiar stuff, too, and the new ideas come in a little at a time. Frankly, I think if the Lisp world had managed to build the same friendly and welcoming community Python seems to have, it would have taken over the world a quarter-century ago. -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From http Thu Aug 26 16:59:11 2004 From: http (Paul Rubin) Date: 26 Aug 2004 13:59:11 -0700 Subject: Inline Conditionals? References: <1gj4rpq.1oyt89b14xvbdqN%aleaxit@yahoo.com> <1gj5bit.rt2tmzcznspxN%aleaxit@yahoo.com> Message-ID: <7xbrgxobts.fsf@ruckus.brouhaha.com> aleaxit at yahoo.com (Alex Martelli) writes: > aux = [] > for x in Somelist: > if x.property: > aux.append(foo(x)) > else > aux.append(foo(x)) > > would be vastly more readable; "sparse is better than dense" and any LC > is far too dense to be Pythonic here. Hmm, [ x.property ? foo(x) : bar(x) for x in Somelist ] doesn't seem too dense, unless you consider -every- LC to be too dense, in which case why have them? The LC seems to me to be both more readable and harder to get wrong, unlike your sparse example, which has 'foo' on both branches of the conditional where you meant 'foo' and 'bar'. I could see adding some parentheses in the LC to improve readability: [ (x.property ? foo(x) : bar(x)) for x in Somelist ] but it doesn't seem like a big deal. From claird at lairds.us Thu Aug 19 19:08:09 2004 From: claird at lairds.us (Cameron Laird) Date: Thu, 19 Aug 2004 23:08:09 GMT Subject: How big can a Python program be? References: <903b3fba.0408170333.49ce3944@posting.google.com> <903b3fba.0408180655.6a23aede@posting.google.com> Message-ID: In article <903b3fba.0408180655.6a23aede at posting.google.com>, wrote: . . . >Simple. Can you make an ERP in Python? Or is Python limited to little >nice scripts or small programs with nice GUI? >We are thinking to start a huge project, which could be hundreds of >thousands of lines huge. I would finally know the answer, but it is >probably better to ask first... Several of us have experience working with Python projects which occupy hundreds of thousands of lines. From peter at engcorp.com Mon Aug 30 19:36:35 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 30 Aug 2004 19:36:35 -0400 Subject: Upgrading to 2.3 from 2.2, questions In-Reply-To: References: Message-ID: Robert Oschler wrote: > (Note: if there is a FAQ that covers this issue just give me the URL. I > checked python.org's General and Windows FAQ's and didn't see anything.) I think it's a frequently asked question, but it's not a FAQ... > > I am about to upgrade from Python 2.2 to 2.3. Here are a few questions: > > - Do I need to uninstall 2.2 first? I don't know if there's an official answer other than "yes". I don't know if there's a safe answer other than "yes". > - Are there any paths I should add to my Win 2k PATH environment variable? Same as whatever you have with Python 2.2.... I try never to put apps in my PATH, but use lots of .BAT files to run things and put all those in a single \BIN folder that is in my PATH. Seems to work out much cleaner that way. > - I am running on Windows 2000 and I have several site-packages installed. > These were installed using individual one-click installation programs (thank > you module writers). Do I need to rerun each of the installations again, > after I upgrade? Or, is there a directory or two I can simply copy over? While it might work, it's not guaranteed. Extensions need to be compiled for the specific version, while pure Python packages will generally run as-is if you just copy them (generally they are all in python/lib/site-packages). No guarantees again. > - Anything I should do before upgrading to preserve my current setup, or > other caveats? Basically, nothing other than uninstall and full install of new version plus all extensions is guaranteed to work, IMHO and IME. On the other hand, I've often gotten by without uninstalling and by copying or just leaving site-packages as-is, with the exception of getting new versions of anything that has a .pyd or .dll (C extensions). -Peter From chris.cavalaria at free.fr Sat Aug 14 09:48:00 2004 From: chris.cavalaria at free.fr (Christophe Cavalaria) Date: Sat, 14 Aug 2004 15:48:00 +0200 Subject: Decorators: an outsider's perspective References: <9ADC3170-EDAF-11D8-9F63-000A95B336F2@snowtide.com> Message-ID: <411e1810$0$18621$626a14ce@news.free.fr> Paul Morrow wrote: > Chas Emerick wrote: > > [...snip...] >> >> The first time I saw this, I almost fell out of my chair: >> >> def blah (args): >> ....[insert 50/100/200 lines here] >> blah = staticmethod(blah) >> > > me too. > > [...snip...] >> >> So, when I see: >> >> @staticmethod >> def blah (args): >> ....[insert 100 lines] >> >> I say, YES! > [...snip...] > > I say, NO! And I wonder why we feel a need to explicitly (and > superflously) 'declare' something that is already clearly evident in the > code (when recommended coding practices are followed). > > class Foo: > def blah(a, b): # this is clearly a static method > pass > > def blah(self, a, b): # this is clearly an instance method > pass > > def blah(klass, a, b): # this is clearly a class method > pass > > Python was built (successfully) on the assumption that obvious > interpretations of the code obviate the need for declarations. Why > wouldn't we continue with that mindset? > > Paul That remark is orthogonal to the problem at hand. staticmethod isn't the only use for decorators although it's currently the most common example. You are guilty of attacking the specific example instead of the general idea behind it. Of course, it doesn't mean that I don't like your idea. In fact, it find it elegant except the the "klass" word which is ugly. From h.b.furuseth at usit.uio.no Fri Aug 6 05:33:17 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 06 Aug 2004 11:33:17 +0200 Subject: Proposal: require 7-bit source str's References: <4112AC7B.1060508@v.loewis.de> <411343D7.3020604@v.loewis.de> Message-ID: Martin v. L?wis wrote: >Hallvard B Furuseth wrote: >> Well, I don't think that's better, but if it's rejected for Python >> that'll be my next stop. > > I can see how the global warning is provided (which then can be > configured into an error through the warnings module). However, > I don't want to introduce additional magic comments. I already > dislike the coding declarations for being comments, and would > have preferred if they had been spelled as > > directive encoding "utf-8" I can see that. > The coding declaration was only acceptable because > - a statement would have to go before the doc string, in > which case it would not have been a docstring anymore, and Hmm... >>> def foo(): ... """h?r""" ... pass ... >>> help(foo) Help on function foo in module __main__: foo() h?r >>> def bar(): ... u"""h?r""" ... pass ... >>> help(bar) >>> help(bar) Traceback (most recent call last): ... UnicodeEncodeError: 'ascii' codec can't encode character '\uf8' in position 59: ordinal not in range(128) Even if the doc string is written in English, it may still need to use non-English names. > - there was prior art (Emacs and VIM) for declaring encodings > to editors, inside comments > > Your proposed annotation has no prior art. As it has > effects on the syntax of the language, it should not be in > a comment. Well, I think it belongs logically together with the coding declarations, but I see your point. Still, how about 'directive str7bit', 'directive -W::str7bitWarning' or something? Or '@str7bit' / '@option -W::str7bitWarning', come to think of it. Like your 'directive encoding "utf-8"', it affects the parsing of the file. So I think this is a good time to use a special character, so the construct will stand out. And '@decorator_name' would be '@decorator decorator_name', of course. But I'll go to the other thread with that. -- Hallvard From liquid at NoSpamKuht.it Mon Aug 2 16:16:40 2004 From: liquid at NoSpamKuht.it (GMTaglia) Date: Mon, 02 Aug 2004 20:16:40 GMT Subject: os.walk() maxdepth Message-ID: I've googled a lot but I couldn't figure out how to implement a maxdepth in os.walk(), does anybody had the necessity to do something like that? thanks in advance and.... ...as usual forgive my english -- Liquid http://softwarelibero.kuht.it <-> www.kuht.it From tor.iver.wilhelmsen at broadpark.no Thu Aug 26 14:50:06 2004 From: tor.iver.wilhelmsen at broadpark.no (Tor Iver Wilhelmsen) Date: 26 Aug 2004 20:50:06 +0200 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: Rich Teer writes: > I belive the Cult (She Sells Sanctuary, etc.) is another manfifestation > of the Blue ?yster Cult. Does not seem so: Founding member Ian Astbury is not listed as member of any other groups, for instance. http://www.allmusic.com/cg/amg.dll?p=amg&sql=11:5qktk6gx9kr3~T1 From mudd at vex.net Sat Aug 7 20:18:00 2004 From: mudd at vex.net (mudd at vex.net) Date: Sat, 7 Aug 2004 20:18:00 -0400 (EDT) Subject: decorators vs GIL In-Reply-To: References: Message-ID: <4512.24.233.156.35.1091924280.squirrel@webmail.vex.net> > On Sat, 7 Aug 2004 22:20:31 +0200, > Mikl?s wrote: >> Yes, this was exactly my point. Performance and GIL. Those are problems. >> And problems must be solved. > > Problems for who? Me, for one. Yes, I can code around the GIL. I do that routinely. It's a pain to keep working around the GIL. Especially knowing that it's not necessary in other languages, but it can be done. Sigh. What really hurts is that I can't honestly tell Java programmers that Python is a slam dunk compared to Java & the JVM. Java has no GIL, Python does. Once I admit this, nobody listens to what Python does well. It's a shame. > I have no problems with Python's performance in my > applications. I avoid threads because they're error-prone, Isn't that like saying, I avoid programming in general because it's error-prone? I don't follow. I agree that threads do introduce an additional level of complexity. But so does programming multi-user applications versus single-user apps. But I've never heard programmers routinely say that they avoid multi-user apps because they're "error-prone". But isn't the GIL on the way out already? Jython offers access to the non-GIL threads of the JVM. I always use Java threads when working with Jython. That's great! I suppose Iron Python will do the same with CLR. And one of the main reasons for the Prothon project (the mythical "Python fork"?) is the elimination of the GIL. It sound like alternatives are on the way. But what's the future of Python? > so the GIL > doesn't affect me. but, but... no programmer is an island? > > Free software projects are run by the people who actually contribute code. > If sorted() and reversed() were added, it's because Raymond Hettinger > actually wrote code to implement them, and GvR didn't dislike them. If > people who want decorators are willing to expend effort to implement them, > test them, conform to the coding standard, then they can be considered for > inclusion. So, if you want to see the GIL fixed, or performance > improvements made, you have to work on these problems. I'm guessing the GIL is beyond any of us. If it was easy, or even possible, someone would have already eliminated it. > > --amk > > From eurleif at ecritters.biz Sat Aug 21 21:06:02 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sat, 21 Aug 2004 21:06:02 -0400 Subject: __metaclass__ and __author__ are already decorators In-Reply-To: References: <2opgsoFd7807U1@uni-berlin.de> <2opp6gFdg3e7U1@uni-berlin.de> <2oq4keFd90euU1@uni-berlin.de> <2oq93oFdnrmoU1@uni-berlin.de> Message-ID: <2oq9lkFd7m32U1@uni-berlin.de> Paul Morrow wrote: > Leif K-Brooks wrote: > >> Paul Morrow wrote: >> >>> So when we define an __xxx__ attribute inside of a function, we are >>> trying to make a statement about the function --- we are not trying >>> to create a local variable. Therefore the Python system shouldn't >>> create a local variable in this case; it should create a function >>> variable instead (IMO). >> >> How do you think a newbie will react to magic behavior like that from >> the assignment operator based entirely on the name being assigned to? > > We must emphasize that they are assigning to a 'magic' variable, as all > __xxx__ attributes are supposed to be. One must be careful with magic :-) I'm starting to reconsider whether I like your proposal. My first reaction was against it, since it seems like Perl-style magic behavior, but now I'm not sure. It definitely is magic, but its purpose seems much more clear than a lot of the other decorator proposals; that's what Python is all about. From pf_moore at yahoo.co.uk Sat Aug 7 11:34:02 2004 From: pf_moore at yahoo.co.uk (Paul Moore) Date: Sat, 07 Aug 2004 16:34:02 +0100 Subject: dispatch tables in Python 2.4 References: <4edc17eb.0408070625.61a0624d@posting.google.com> Message-ID: michele.simionato at gmail.com (Michele Simionato) writes: > BTW, what's the status of the so called "functional" module? I think > there was a rumor of such a module scheduled for Python 2.4 or 2.5. > To play with decorators we really need some standard way to compose > functions and to do partial application of arguments. PEP 309 is marked as "Accepted", and an implementation patch exists. The PEP needs updating, and there are possibly a few more procedural things to do before the code is checked in. I emailed the author of the PEP on Friday, asking about this. I think it's mainly lack of tuits. The PEP only covers partial application, BTW. Paul. -- Any sufficiently advanced technology is indistinguishable from magic. -- Arthur C. Clarke From porky_pig_jr at my-deja.com Sun Aug 15 00:04:29 2004 From: porky_pig_jr at my-deja.com (Porky Pig Jr) Date: 14 Aug 2004 21:04:29 -0700 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: <56cfb0e3.0408142004.511a8a8e@posting.google.com> beliavsky at aol.com wrote in message news:<3064b51d.0408130615.3fc4a760 at posting.google.com>... > One of the most commmon reasons programmers cite for not trying Python > is that indentation determines the program flow -- they think its > weird. I think programmers who actually try Python adapt quickly and > do not find the indentation rules to be a problem. > Not only it's *not a problem*. I've found it quite useful since it forces you to keep the proper indentation. Granted, the very first time I read about this feature, I've thought: what a funny thing -- but then I've realized that since I keep the proper indentation anyway, Python simply eliminates 'parenthetical clutter' (in addition of forcing you to keep the code nicely alligned). For instance, in C I write if (condition) { statement-1 statement-2 } else { statement-3 statement-4 } or some other coders prefer to write if (condition) { statement-1 statement-2 } else { statement-3 statement-4 } but in Python all those extra parenths are gone, and code is more compact, more easily observable. you can squeeze more code into a single displayble area which *is* important. On the other hand, C has nothing that prevents someone from writing the code: if (condition) { statement-1 statement-2 } else { statement-3 statement-4 } Just had the situation a few weeks ago when novice C++ programmer asked for help. Even if that programmer used emacs, somehow she has managed to write the code as above. I simply told her to get her identation in place first and then get back to me. So: if you are a programmer who - as a matter of habit - writes nice properly indented code, you will quickly appreciate the advantages of Python (just like I did), and if you don't -- well, that's too bad. From crgre.znnf at hgvybt.qr Sun Aug 22 06:58:50 2004 From: crgre.znnf at hgvybt.qr (Peter Maas) Date: Sun, 22 Aug 2004 12:58:50 +0200 Subject: J2 decorator grammar In-Reply-To: References: Message-ID: <2orckjFdtljaU1@uni-berlin.de> Robert Brewer schrieb: > Michael Sparks wrote: > For that reason (and others), I plan not to promote any form of the word > "decorate". We can start having that conversation now if you want. ;) What about with: return ... accept ... classmethod def func(): "using" instead of "with" would be equally satisfactory for me. I don't like "decorate" because it sounds like "attaching some bells and whistles" or "making it look pretty" which isn't adequate for the meaning of this syntax. -- Peter Maas, Aachen, Germany, Tel +49-241-38200 e-mail crgre.znnf at hgvybt.qr From glc at well.com Tue Aug 24 10:16:48 2004 From: glc at well.com (Greg Chapman) Date: Tue, 24 Aug 2004 14:16:48 GMT Subject: Regular expression guaranteed to fail References: Message-ID: <96jmi0pt39frp5n3r34afrt21cfeclp0mi@4ax.com> On 22 Aug 2004 20:07:51 +0200, Hallvard B Furuseth wrote: >Eric Brunel wrote: > >> I also looked for a never-matching re just a few days ago and ended up >> with "^(?!$)$". It's certainly not more "standard" than yours, but I >> find it a wee tad more readable (for a regular expression, I mean...): > >I think e.g. r'\Zx' and r'x\A' are more readable. In particular the >latter, but perhaps that causes Python to locate every 'x' in the string >and then check if the string starts at the next character... Why not just "(?!)": this always fails immediately (since an empty pattern matches any string, the negation of an empty pattern match always fails). --- Greg Chapman From hamilcar at tld.always.invalid Tue Aug 3 20:48:32 2004 From: hamilcar at tld.always.invalid (Hamilcar Barca) Date: Tue, 03 Aug 2004 18:48:32 -0600 Subject: Modern dead-tree Python resources References: <411016d7_1@127.0.0.1> Message-ID: <20040803204805.275$3T@news.newsreader.com> In article <411016d7_1 at 127.0.0.1> (Tue, 03 Aug 2004 17:51:03 -0500), beliavsky at aol.com wrote: > > Michael Ekstrand wrote: > >>Is there a good book that covers Python at least through 2.2 (including >>new-style classes, etc.)? I'm particularly looking for something with >>large appendices of reference material. (alternatively, if someone's >>publishing print versions of the Python documentation, that would >>possibly be of interest. > > A good reference for Python 2.2 And references to Python 2.3. > is "Python in a Nutshell", by Alex Martell. Alex Martelli. It's one of the best language references I've read. From tjreedy at udel.edu Mon Aug 16 14:56:29 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Aug 2004 14:56:29 -0400 Subject: Flython References: Message-ID: "Christopher T King" wrote in message news:Pine.LNX.4.44.0408161041590.8576-100000 at ccc3.wpi.edu... >I'm using http://docs.python.org/ref/grammar.txt as my grammar >reference. ... > :( Is there at least some rationale why the AST trees don't match the > grammar definitions? The grammar in the Ref Manual, which is collected together in the above file, is intended and used for human comsumption. The equivalent but not identical grammar in a source code file is intended and used for parser-generator comsumption. It consitutes its own documentation. You aren't the first person to trip on the difference. The rationale is that people and parser generators 'think' differently. I don't know whether AST trees exactly match the parser grammarr or if they effectively follow a third form, hopefully also exactly equivalent. You have wandered into as-yet inadequately documented internals land. Terry J. Reedy From jburgy at hotmail.com Fri Aug 13 07:10:31 2004 From: jburgy at hotmail.com (Jan Burgy) Date: 13 Aug 2004 04:10:31 -0700 Subject: Deep Black Magic in Python: please help Message-ID: <807692de.0408130310.6e3ed9db@posting.google.com> Hi everyone, I am trying to convince my managers that python can replace the outdated and soon no-longer maintained proprietary system (Tool for Calculator Design) we use here. In order to achieve this, I need to analyze python code which will look somethink like this: def foo(arg_dict): return arg_dict["one"] + bar(arg_dict) def bar(other_dict): return other_dict["two"] + other_dict[True and "three" or "four"] The result of my analysis should return a list ['one', 'two', 'three'] Alright, that doesn't sound so bad. With a little RTFM-ing and hacking, I got -- black magic starts here -- import compiler def _evaluate(partial, name=""): from compiler.ast import Expression from compiler.misc import set_filename from compiler.pycodegen import ExpressionCodeGenerator tree = Expression(partial) set_filename(name, tree) gen = ExpressionCodeGenerator(tree) return eval(gen.getCode()) class RecursiveVisitor(compiler.visitor.ASTVisitor): def __init__(self, name): self.name = "Name(%s)" % repr(name) self.names = {} def visitSubscript(self, node, *args): if repr(node.expr) == self.name: try: name = _evaluate(node.subs[0]) except: name = str(node.subs[0]) self.names[name] = 1 def visitCallFunc(self, node, *args): try: from inspect import getsource, getargspec from compiler import parse, walk func = _evaluate(node.node) pos = map(repr, node.args).index(self.name) src, arg = getsource(func), getargspec(func)[0] tmp, self.name = self.name, "Name(%s)" % repr(arg[pos]) walk(parse(src), self) self.name = tmp except Exception, e: print str(e) if __name__ == "__main__": from inspect import getsource from compiler import parse, walk src = getsource(foo) mod = parse(src) visitor = RecursiveVisitor("kw") walk(mod, visitor) print visitor.names.keys() -- black magic ends here, ouch -- Once again, I'm in total awe at the possibilities python offers us lowly users. Unfortunately we're all the same: you give us a finger, we want the whole arm! I want this method to generalize to method calls as in class baz: def foo(self, arg_dict): return arg_dict["one"] + self.bar(arg_dict) def bar(self, other_dict): return other_dict["two"] + other_dict[True and "three" or "four"] It shouldn't be all that hard. My problem is the lookup of 'self.bar'. In the AST it looks something like CallFunc(Getattr(Name('self'), 'bar'), [Name('arg_dict')], None, None) How do I find the corresponding function? Anybody feels like wrapping their head on this? Cheers, Jan Burgy From peter at semantico.com Tue Aug 17 09:14:59 2004 From: peter at semantico.com (Peter Hickman) Date: Tue, 17 Aug 2004 14:14:59 +0100 Subject: How big can a Python program be? In-Reply-To: <903b3fba.0408170333.49ce3944@posting.google.com> References: <903b3fba.0408170333.49ce3944@posting.google.com> Message-ID: <412204d5$1$28243$afc38c87@news.easynet.co.uk> vronskij at post.sk wrote: > Hi, > > A C program can be hundreds of thousands lines of code big. > C++ millions. > > How about Python? > > Suppose , you are a sole programmer (lonewolf). How many lines can one handle? > > Thanks, > > > jan bodnar Are you suggesting that a solo programmer wrote a multi million line C++ program? If not then what has this to do with 'How many lines can one handle?' The application I am currently working on has 75,000 lines across some 600 files. But I suspect that the line count is higher when you include the various libraries. So I am handling 75,000 lines in some sense, is this what you mean? Or are you talking about the number of lines per file (average 125) or perhaps lines per method? From anthonybaxter at gmail.com Sun Aug 22 11:38:14 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Mon, 23 Aug 2004 01:38:14 +1000 Subject: [PATCH] RE: J2 decorator grammar In-Reply-To: <4128ac0f$0$79299$ed2619ec@ptn-nntp-reader02.plus.net> References: <4128ac0f$0$79299$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: On Sun, 22 Aug 2004 15:01:39 +0100, Michael Sparks wrote: > It should be done sometime this afternoon though. (Bulk of the time taken up > is on re-running the test suite unsuprisingly) One quick point - make sure you run the _full_ test suite (-uall arg to regrtest, or 'make testall'), otherwise things like the compiler tests won't get run. From FBatista at uniFON.com.ar Wed Aug 25 18:04:30 2004 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Wed, 25 Aug 2004 19:04:30 -0300 Subject: Proposal for removing self Message-ID: [Brent W. Hughes] #- When doing object-oriented stuff, it bothers me to have to #- type "self" so #- many times. I propose that Python allow the programmer to #- optionally type #- ".variable" instead of "self.variable" to mean the same #- thing. Of course, #- the interpreter would have to be more careful about #- detecting floats that #- begin with just a period as in ".5". What are your thoughts? I type less than read, so I prefer the code to be better readable than writable. I'm -1 on your proposal. . Facundo From max at alcyone.com Fri Aug 6 00:10:19 2004 From: max at alcyone.com (Erik Max Francis) Date: Thu, 05 Aug 2004 21:10:19 -0700 Subject: Confused about pep 318 References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: <411304AB.F53A5275@alcyone.com> Skip Montanaro wrote: > Bengt> I too am very much against wasting '@' on @decorator! > > We could just switch completely to Unicode. Then we'd have all sorts > of > punctuation characters available. How about > > # -*- coding: utf-8 -*- > \xe2\x98\xbadecorator > def f(): > pass > > ? Given how things are looking so far with the reaction to the decorator syntax, I'd say U+2639 might be more appropriate ... -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ Drifting from woman-who-tries misconstrued / Shifting to woman-wise -- Lamya From zathras at thwackety.com Sat Aug 21 18:53:01 2004 From: zathras at thwackety.com (Michael Sparks) Date: Sat, 21 Aug 2004 23:53:01 +0100 (BST) Subject: J2 decorator grammar In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022E1B@exchange.hqamor.amorhq.net> Message-ID: On Fri, 20 Aug 2004, Robert Brewer wrote: [ given grammar ] ... > > Would you consider this instead? After I fix the scoping issue I'll consider lots of things. The second version holds more weight though :) > Did you ever fix the scope issue? I'm working on it at the moment. (Interesting way to start looking at the source tree :) Based on very helpful comments in the source the sequence that happens is the symbol tables get defined, then on a second pass, things are done in a more detailed fashion using these tables. Upshot is at the moment this: class Foo: #staticmethod decorate: staticmethod def Hoo(who): Results in just Foo and Hoo being picked up, with staticmethod "hidden" in the indented block, whereas this: class Foo: staticmethod decorate: staticmethod def Hoo(who): Result in Foo, Hoo and staticmethod being picked up - presumably because they're in easily accessible blocks. Likewise the @pie syntax falls into the second category, as does the current 2.3 style of Hoo=staticmethod(Hoo) approach. > Might it have something to do with: > > static void > symtable_node(struct symtable *st, node *n) I've tried this change, but whilst it doesn't work it's a useful avenue - thanks :) Regards, Michael. From newsgroups at jhrothjr.com Sun Aug 8 08:21:41 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Sun, 8 Aug 2004 08:21:41 -0400 Subject: Prothon is switching to the .NET platform References: <000401c47b59$32539220$0d01a8c0@MarkVaio> <10h7lb21dhbuc12@news.supernews.com> <10h7rittck6ct75@news.supernews.com> <10h9dkm5ub5h1f2@news.supernews.com> <1dske12sbt1mj$.1aq70xrpy0r0i.dlg@40tude.net> Message-ID: <10hc6mk55u0qq26@news.supernews.com> "Mark Hahn" wrote in message news:1dske12sbt1mj$.1aq70xrpy0r0i.dlg at 40tude.net... > On Sat, 7 Aug 2004 07:01:55 -0400, John Roth wrote: > > > "Peter Otten" <__peter__ at web.de> wrote in message > > news:cf1t0h$ond$03$1 at news.t-online.com... > >> John Roth wrote: > >> > >>> > >>> "Christopher T King" wrote in message > >>> news:Pine.LNX.4.44.0408061533250.25906-100000 at ccc8.wpi.edu... > >>>> On Fri, 6 Aug 2004, John Roth wrote: > >>>> > >>>> > I think it's possible to do prototypes within Python by > >>>> > overriding the __getattribute__() magic method. It still > >>>> > wouldn't be very pretty, but it should be able to do > >>>> > everything except override the magic methods (those > >>>> > seem to have to be in the class object for new style > >>>> > classes). > >>>> > > [snip] > >>> > >>> What I was thinking of was more along the lines of: > >>> > >>> class ProtoBaseClass(object): > >>> def __getattribute__(self, attr): > >>> # call object.__getattribute__(self, __dict__) > >>> # find requested attribute > >> > >> Wouldn't that part be implied if you used __getattr__() instead of > >> __getattribute()? > >> > >>> # if not found, loop through back pointer chain > >>> # if it's not a function, return the attribute > >>> # if it is a function, wrap it in a method object and return it. > >> > >> This means that an object sees all changes in its prototypes until > >> explicitly assigned an attribute. Is this intentional? (real question, I'm > >> not familiar with prototyped languages) > > > > Actually, __getattribute__ sees all attribute requests, __getattr__ > > only sees requests where the attribute isn't found. The reason for > > using __getattribute__ is that there are (I think) serious problems > > with attempting to execute functions that weren't originally defined > > in the base class or a subclass of the base class. In other words, > > if the result is a function, there's more work that needs to be done, > > and __getattr__ doesn't allow a hook to do it on the way out. > > > > The attempt from 2000 I referred to attempted to get around this > > by using a callable instance together with a lambda. Unfortunately, > > it didn't work when I tried it, and as I said, after looking at the > > code I don't think it ever worked. The workaround for the function > > problem might work, though. > > Lenard Lindstrom wrote a prototype implementation in > Python. He hangs out on the Prothon mailing list (and here also, I > assume). He probably knows more about this topic than anyone. I'll have to check out what he's done - is it availible anywhere other than by e-mail? Hans Nowak just sent me a private e-mail pointing out that he had done a Self-style implementation about a year ago. It looks interesting, especially since it uses getattr and setattr rather than getattribute. The trick with functions seems to be to use new.instancemethod. Otherwise the code looks to be very straightforward. __setattr__ just makes a couple of type checks, insures that instances ending in _p are from the selfish class, wraps functions in new.instancemethod and rewraps methods likewise. __getattr__ implements the inheritance rules. The examples on his weblog (look at 2003-09-13) are quite nice; he's got the clumsiness with instance methods down to one line after the method, which seems to be a practical minimum. It should work with the new decorator syntax as well. John Roth > > Mark Hahn > Prothon Author From anthonybaxter at gmail.com Tue Aug 24 23:02:47 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Wed, 25 Aug 2004 13:02:47 +1000 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: Message-ID: On Tue, 24 Aug 2004 12:29:38 -0400, Paul Morrow wrote: > ....that they warrant an entirely new syntax? It seems that they are > very similar in a very significant way --- they alter the default > behavior of something. IMO, it's not a stretch to say that they > 'parallel' metaclasses; that they are to functions/methods what > metaclasses are to classes. So why don't they share a similar syntax? No. Function decorators are to functions as class decorators are to classes. Class decorators are not in 2.4, because you can do most things you'd do with a class decorator by using a metaclass, but in a completely different way. In my opinion, class decorators _should_ be in 2.4, because they're a much saner way to handle many things that require a metaclass today. They don't "alter the default behaviour". A metaclass allows the user to specify an object that builds classes in a new way. A decorator allows the user to specify a way to transform the already built function (or class, for class decorators). Anthony From zirpu at yahoo.com Thu Aug 5 13:22:43 2004 From: zirpu at yahoo.com (zirpu xunre pelxu) Date: 05 Aug 2004 10:22:43 -0700 Subject: bdist_rpm problems, and my work around. Message-ID: python setup.py bdist_rpm [...] # eventually complains about the extra -debuginfo package. my work around: in the package dir create .rpmmacros with just these lines: %define debug_package %{nil} #%#define _unpackaged_files_terminate_build 0 the 2nd line is not necessary usually, but there for reference. then to build packages i do: HOME=`pwd` python setup.py bdist_rpm Quetions for those who might know: where can i define rpm macros in setup.py? there doesn't seem to be any support for changing those default spec file templates that bdist_rpm uses. -a From insert at spam.here Sun Aug 29 12:18:14 2004 From: insert at spam.here (Doug Holton) Date: Sun, 29 Aug 2004 11:18:14 -0500 Subject: Announcing PyCs, a new Python-like language on .Net In-Reply-To: <1093793065.258215@news.commspeed.net> References: <1093788608.645541@news.commspeed.net> <1093793065.258215@news.commspeed.net> Message-ID: >>Is there a real danger that MS will make its own version of >>Python, pushing it into the market, and we end up with a >>dominant version that only works with MS software? No, I don't think so. They already have Visual Basic for that. They are making their own version of Python (IronPython), but it will work with .NET or Mono (an open source clone of Microsoft's .NET framework). And there are two other python-like languages now under development that will also target Mono as well as .NET: PyCs and boo. > What M*soft should do is build libraries like the Speech Development Kit and > Direct X into open source modules for Python. This way they are not trying > to destroy open source but to join with it. Yeah, that's the area I see Microsoft stuff still having an advantage, with libraries like DirectX, text to speech, force feedback, etc. But you can access Microsoft's libraries from Python, see: http://sourceforge.net/projects/uncassist The problem is that then your application will only run on Windows unless you can get it to work with Wine: http://www.winehq.org/ An advantage of IronPython/PyCs/boo is that they would make accessing libraries like DirectX much much easier. You'll be able to access them the same way you would from Visual Basic or C#. But a more cross-platform compatible way would be to use OpenGL (pyopengl or csgl if you are using .net) or SDL (pygame or sdl.net) instead of DirectX. From pf_moore at yahoo.co.uk Tue Aug 24 16:10:19 2004 From: pf_moore at yahoo.co.uk (Paul Moore) Date: Tue, 24 Aug 2004 21:10:19 +0100 Subject: J2 paper 0.2.1 References: Message-ID: "Robert Brewer" writes: > The first draft of the J2 proposal is ready. You can read it here: > http://www.aminus.org/rbre/python/pydec.html > > At this point, I am looking for comments regarding the proposal. Once I > believe I have addressed a sufficient number of concerns, I will freeze > the document and call for signatories, both for and against, then send > it to Guido. Until that time, expect the draft to change multiple times > each day (there's a meta tag with the version number if you care to > check). I have just read this - it's a very good document. I don't necessarily agree with all of it, and I'm not sure I'm convinced by it, but it makes a solid proposal to submit. Some comments: 1. I differ on the "it doesn't matter what the keyword is" statement. On the contrary, my view could completely change depending on the keyword - I'd loathe "predef", whereas "using" is acceptable to me. Putting the proposal forward *without* an agreed keyword isn't (IMHO) fair to people who have this view. 2. I agree with the person who pointed out that the indentation makes the decorators merge visually with the function name. This is a definite point against the syntax, and should be at least noted in section "Arguments - I - 3 Additional benefits" paragraph 2. In fact, I could esily argue that it completely invalidates this point, swinging it in favour of @ syntax. Also, I'd say that the proposal needs to be submitted with a full, working patch. This isn't meant to be sour grapes, but I'd be concerned if the proposal was submitted, Guido approved it, and then it wasnt't possible to get a working version ready in time for the next alpha. Regardless of any other consideration, I'm completely against any delay of the 2.4 timescales for this. >From a brief reading of the description attached to the current patch, I have a couple of comments: 1. The patch doesn't (according to the comment) implement the __future__ import. This needs to be added before the proposal is submitted. And __future__ support for the interactive prompt may be needed as well - I'm not sure here, see PEP 236 for the detail. 2. Does the patch support decorating classes? The @ syntax *might* by now (in CVS), there was discussion of adding it but I'm not sure it went in. The patch should probably provide the same functionality as CVS @-syntax, rather than just 2.4a2. Having said all this, I'd have to say that I'm still not sure I'm swayed. I'm only ever going to be an occasional user of decorators, I suspect, so I don't really care a *lot*, but I think I still prefer @ decorators. Paul. -- I don't know anything about music. In my line you don't have to. -- Elvis Presley From anthonybaxter at gmail.com Fri Aug 27 13:14:57 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 28 Aug 2004 03:14:57 +1000 Subject: would be nice: import from archive In-Reply-To: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> Message-ID: On Fri, 27 Aug 2004 17:06:06 GMT, Dan Perl wrote: > Here is a python feature that I would like: to be able to import modules > from an archive like the jar files in Java. Maybe a regular tar file? > Maybe a python specific file type, let's call it a 'par' file? Or a zip file, perhaps? See PEP-0273, which was implemented in Python 2.3. (Hm. 273 isn't up-to-date. This is bad :-( From mjackson at alumni.caltech.edu Thu Aug 19 14:19:08 2004 From: mjackson at alumni.caltech.edu (Mark Jackson) Date: 19 Aug 2004 18:19:08 GMT Subject: age of Python programmers References: <4124d4a4$1@nntp0.pdx.net> Message-ID: "Paul McGuire" writes: > "Scott David Daniels" wrote in message > news:4124d4a4$1 at nntp0.pdx.net... > > Mike Brenner wrote: > > > > > I was born about 10,000 years ago and I used to > > > program computers made of human beings who > > > were aligned in tiers. The bottom tier counted > > > the grains in the baskets. The next tier > > > counted the baskets in the barn, then the > > > number of brans in each country. > > > > > Don't laugh. I met a woman roughly my age (53 now) > > whose mother was a programmer at los Alamos (or was > > it Trinity?) -- she programmed rooms of people > > running mechanical calculators (calculate this, if > > a > b, pass your results right, otherwise, ...) > > > > Scott David Daniels > > Scott.Daniels at Acm.Org > > This technique is also described in Neal Stephenson's book "Cryptonomicon". Must have been Los Alamos (IIRC "Trinity" was just the code name for the site of the first bomb test). If so, the replacement of the mechanical calculator array by IBM unit record devices (which also were "programmed" the same way) is mentioned in /"Surely You're Joking, Mr. Feynman!"/, which also describes what is most likely the first documented case of computer addiction. Here's the excerpt I posted to comp.risks in 1987: Anyway, we decided that the big problem -- which was to figure out exactly what happened during the bomb's implosion, so you can figure out exactly how much energy was released and so on -- required much more calculating than we were capable of. A clever fellow by the name of Stanley Frankel realized that it could possibly be done on IBM machines. The IBM company had machines for business purposes, adding machines called tabulators for listing sums, and a multiplier that you put cards in and it would take two numbers from a card and multiply them. There were also collators and sorters and so on. So Frankel figured out a nice program. If we got enough of these machines in a room, we could take the cards and put them through a cycle. Everybody who does numerical calculations now knows exactly what I I'm talking about, but this was kind of a new thing then -- mass production with machines. We had done things like this on adding machines. Usually you go one step across, doing everything yourself. But this was different -- where you go first to the adder, then to the multiplier, then to the adder, and so on. So Frankel designed this system and ordered the machines from the IBM company, because we realized it was a good way of solving our problems. . . . . Well, Mr. Frankel, who started this program, began to suffer from the computer disease that anybody who works with computers now knows about. It's a very serious disease and it interferes completely with the work. The trouble with computers is you /play/ with them. They are so wonderful. You have these switches -- if it's an even number you do this, if it's an odd number you do that -- and pretty soon you can do more and more elaborate things if you are clever enough, on one machine. After a while the whole system broke down. Frankel wasn't paying any attention; he wasn't supervising anybody. The system was going very, very slowly -- while he was sitting in a room figuring out how to make one tabulator automatically print arc-tangent X, and then it would start and it would print columns and then /bitsi, bitsi, bitsi/, and calculate the arc-tangent automatically by integrating as it went along and make a whole table in one operation. Absolutely useless. We /had/ tables of arc-tangents. But if you've ever worked with computers, you understand the disease -- the /delight/ in being able to see how much you can do. But he got the disease for the first time, the poor fellow who invented the thing. I was asked to stop working on the stuff I was doing in my group and go down and take over the IBM group, and I tried to avoid the disease. . . . . -- Mark Jackson - http://www.alumni.caltech.edu/~mjackson Fascism should more properly be called corporatism, since it is the merger of state and corporate power. - Benito Mussolini From beliavsky at aol.com Fri Aug 13 10:15:14 2004 From: beliavsky at aol.com (beliavsky at aol.com) Date: 13 Aug 2004 07:15:14 -0700 Subject: Python indentation deters newbies? Message-ID: <3064b51d.0408130615.3fc4a760@posting.google.com> One of the most commmon reasons programmers cite for not trying Python is that indentation determines the program flow -- they think its weird. I think programmers who actually try Python adapt quickly and do not find the indentation rules to be a problem. I wonder if there is a way to remove this initial barrier. Could an alternate source form be defined, so that there are matching if-endif and for-next constructs instead of significant indentation? The alternate source form and the current form would result in exactly the same .pyc file. I'm not saying that Python's use of indentation is bad, just that it stops many programmers from trying it. From squirrel at WPI.EDU Sat Aug 14 01:56:30 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Sat, 14 Aug 2004 01:56:30 -0400 Subject: Flython In-Reply-To: References: Message-ID: On Sat, 14 Aug 2004, Terry Reedy wrote: > Knowing nothing about Flash bytecode, but knowing a bit about other Python > to X projects, I wonder whether it might be more immediately feasible to > either translate Python bytecode or generate Flash bytecode with an AST > tree walker. We'll soon find out ;) (Unfortunately, AST trees don't match up exactly with Python grammar, so I'm having to learn the format by trial-and-error. Not much fun. Is there documentation on the AST forms anywhere?) From BruceWhoHKL at gawab.com Thu Aug 19 21:53:19 2004 From: BruceWhoHKL at gawab.com (BruceKL WhoH) Date: Fri, 20 Aug 2004 09:53:19 +0800 Subject: ANN: pyxe Message-ID: <20040820015229.E7E191E4003@bag.python.org> Gerson Kurz: Can pyxe build a Python script with GUI(wxPython/tk) into a binary? Can pyxe build binaries for Linux? ======= 2004-08-19 19:50:26 Gerson Kurz wrote: ======= >pyxe is a small executable that will run python scripts on a machine >that doesn't have Python installed. Example: You have the following >hello.py: > >def main(): > print "Hello, World" > >You can create a binary distribution using > >pyxe /build hello > >This will create a directory ./hello which contains all you need. Copy >all files to a host system and run the app using > >pyxe hello > >That's it. Note that your app must define a > >def main(): > >which is the main procedure to start from pyxe. There is one known >restriction, sys.argv[] doesn't get properly setup in pyxe >environment. You can fix this yourself: > >import sys >try: > import cfrompy > sys.argv = cfrompy.GetSysArgv() >except ImportError: > assert sys.argv > >Easy, eh? Requirements > >- On the developer machine, you must have python23 installed. >- On the target machine, no requirements. >- Tested on Windows NT and Windows 2000. You are on your own with >other systems (such as XP, 03 etc.) > >pyxe is free for any purpose whatsoever. > >Download: >http://p-nand-q.com/python/pyxe.zip > >includes the full sourcecode and a sample app in Python which actually >is the "SimpleHTTPServer" webserver ;) Enjoy > >Homepage = this mail in fancy tags: >http://p-nand-q.com/python/pyxe.html > >-- >http://mail.python.org/mailman/listinfo/python-list >. = = = = = = = = = = = = = = = = = = = = ????????BruceKL WhoH ????????BruceWhoHKL at gawab.com ??????????2004-08-20 From Moiz.Golawala at ge.com Mon Aug 30 10:25:28 2004 From: Moiz.Golawala at ge.com (Golawala, Moiz M (GE Infrastructure)) Date: Mon, 30 Aug 2004 10:25:28 -0400 Subject: Get Parent path value (bad design) Help Message-ID: Hi all, What I am trying to do is write some generic code where I can get the path of the parent directory. for example if current working directory is 'Z:\\dirA\\Parent\\Child' I want to get a string which up like 'Z:\\dirA\\Parent' Then I do a sys.path.append('Z:\\dirA\\Parent') The code I have written below does all this.. but I have a feeling there is a better way to do this.. Please can someone help me. import os import sys pathname = os.getcwd() pathString = '' pathList = pathname.split("\\") pathList.pop() # removes the child lastItem = pathList.pop() #remove to the parent, will be added back later. counter = 0 while counter != len(pathList): #build up the path with items in the list pathString = pathString + pathList[counter] + "\\\\" counter +=1 pathString = pathString + lastItem #add parent back to the built up path sys.path.append(pathString) #append the path back to sys.path Thanks, Moiz Golawala From http Wed Aug 18 17:58:11 2004 From: http (Paul Rubin) Date: 18 Aug 2004 14:58:11 -0700 Subject: Embedding Python in Python References: <7xu0v0l2be.fsf@ruckus.brouhaha.com> <7x3c2kkzn8.fsf@ruckus.brouhaha.com> Message-ID: <7x7jrwt8gc.fsf@ruckus.brouhaha.com> JCM writes: > >> need to be aggressive, but I believe it's possible. For example, > >> disallow exec statements, the identifier "eval", any identifier of > >> __this__ form, import statements, etc. This is overly restrictive, > >> but it will provide security. > > Hint: > > e = vars()['__builtins__'].eval > > print e('2+2') > > I don't think it's as difficult as you think. Your snippet of code > would be rejected by the rules I suggested. You'd also want to > prohibit other builtins like compile, execfile, input, reload, vars, etc. I don't see how. Your rules were to disallow: 1) exec statements. My example doesn't use it. 2) eval identifier. My example uses eval as an attribute and not an identifier. You can eliminate the use of eval as an attribute with e = getattr(vars()('__builtins__'), 'ev'+'al'). Now not even the string 'eval' appears in one piece. 3) identifiers like __this__. My example doesn't use any. It uses a constant string of that form, not an identifier. The string could be computed instead, like the eval example above. 4) import statements. My example doesn't use them. Conclusion, my example gets past your suggested rules. I also didn't use compile, execfile, input, or reload. I did use vars but there are probably other ways to do the same thing. You can't take something full of holes and start plugging holes until you think you found them all. You have to start with something that has no holes. The Python crowd has been through this many times already; do some searches for rexec/Bastion security. From mksql at yahoo.com Tue Aug 10 12:16:13 2004 From: mksql at yahoo.com (Matt) Date: Tue, 10 Aug 2004 09:16:13 -0700 (PDT) Subject: Secure storage for passwords for admin scripts? In-Reply-To: <200408101022.40366.python@elehack.net> Message-ID: <20040810161613.31592.qmail@web40606.mail.yahoo.com> The tricky part here is that some of the scripts need to authenticate against multiple NT domains. I think the scheduler service will only provide a connection to a single domain. Additionally, I need to authenticate against MS SQL Servers, using native logins, not NT logins. --- Michael Ekstrand wrote: > I believe the Windows task scheduler is capable of > running a task as a > given user, in which case the script need not worry > about the password, > the scheduler will store it and execute the script. > > I know this is the case in Win Server 2k3, it seems > like it'd probably > be present in 2k as well. __________________________________ Do you Yahoo!? Yahoo! Mail - 50x more storage than other providers! http://promotions.yahoo.com/new_mail From tim.peters at gmail.com Sun Aug 15 03:13:58 2004 From: tim.peters at gmail.com (Tim Peters) Date: Sun, 15 Aug 2004 03:13:58 -0400 Subject: Generators versus Coroutines In-Reply-To: <972ec5bd.0408142203.5a8d5d04@posting.google.com> References: <972ec5bd.0408141032.385fe115@posting.google.com> <972ec5bd.0408142203.5a8d5d04@posting.google.com> Message-ID: <1f7befae040815001315fc17c1@mail.gmail.com> [Tim Peters] >> If you want a concept of yielding without delivering a value, that's >> simply not a use case Python's generators intended to address. If >> you wish, you can adhere to a *convention* that "yield None" >> (or "yield False", or "yield 42", ...) means "I'm not really delivering a >> value". [Timothy Fitz] > It's not a use case, but why not? In the years generators were discussed before they were implemented, nobody asked for that. > And should it be? Not by my lights, no. > I know generators are semi-coroutines, but the fact is that their > useage outside of value generation is just as useful and should be > adressed as such. I do not see how accepting a plain yield would > break anything at all. The vast majority of generator applications (as you said before,"generators are used almost exclusively for generation of lists just-in-time", so you already know this) have no use for that; so, for the vast majority of generator applications, allowing it anyway would offer nothing of value, but would reduce the quality of compile-time error-checking. > I have read the PEP, twice, and I don't see why it -wasn't- addressed. If someone asked for a thing, it got into the PEP. Nobody wanted it. > Seems to me to be a fairly large arbitrary decision. For general coroutines it would have been. For Simple Generators (the PEP's title) I think it was the right decision -- "simple" isn't consistent with piling on gimmicks. If you want to change it, write a new PEP. From johnfkeeling at yahoo.com Mon Aug 2 07:30:44 2004 From: johnfkeeling at yahoo.com (John Keeling) Date: 2 Aug 2004 04:30:44 -0700 Subject: Timing Difference: insert vs. append & reverse Message-ID: <35b736b9.0408020330.53b24ed3@posting.google.com> Dear all, I tried the test program below. My interest is to examine timing differences between insert vs. append & reverse for a list. My results on my XP Python 2.3.4 are as follows: time_reverse 0.889999389648 time_insert 15.7750005722 Over multiple runs ... the time taken to insert at the head of a list, vs. the time taken to append to a list and then reverse it is typically 16 or 17 times longer. I would have expected the insert operation to be faster than the combined append & reverse operations. Is this behaviour surprising, or is there a good reason why there is this large performance difference? Thanks, John from time import time def test(): time_reverse =0.0 time_insert =0.0 for lindx in xrange(100): tmp1 =[] time_reverse -=time() for indx in xrange(10000): tmp1.append(indx) tmp1.reverse() time_reverse +=time() tmp2 =[] time_insert -=time() for indx in xrange(10000): tmp2.insert(0, indx) time_insert +=time() assert tmp1==tmp2 print "time_reverse ", time_reverse print "time_insert ", time_insert test() From gazelle at yin.interaccess.com Sun Aug 1 08:51:36 2004 From: gazelle at yin.interaccess.com (Kenny McCormack) Date: Sun, 01 Aug 2004 12:51:36 GMT Subject: (patch for Bash) try-block and exception References: <2n27jlFsb5njU1@uni-berlin.de> <2n2bapFs3oqbU1@uni-berlin.de> <2n3jliFrvv9dU1@uni-berlin.de> Message-ID: In article <2n3jliFrvv9dU1 at uni-berlin.de>, William Park wrote: ... >Next feature I'll tackle is list comprehension. :-) Are you saying that you don't understand how lists work? If so, post an item here - I'm sure people will be more than willing to help. From peter at engcorp.com Mon Aug 30 15:52:05 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 30 Aug 2004 15:52:05 -0400 Subject: "Content-Length" header In-Reply-To: References: Message-ID: Justin wrote: > I have a program that downloads files from the web. There are > instances in which a .info() will not return a "Content-length" header > to me. Is ther a way to specifically request this header or FORCE it > to be sent? I know there is some way to get the file size for these > files because Internet Explorer is capable of determining the size on a > cut / paste of the same exact url. Was this URL one of them? c:\>python Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32 >>> import urllib >>> s = 'http://www.ecs.soton.ac.uk/~harnad/Temp/Ariadne-RAE.doc' >>> f = urllib.urlopen(s) >>> print f.info() Date: Mon, 30 Aug 2004 19:50:49 GMT Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12 OpenSSL/0.9.6b DAV/ 1.0.3 PHP/4.3.2 mod_perl/1.26 Last-Modified: Sun, 20 Apr 2003 15:19:42 GMT ETag: "f10f630-9a800-3ea2ba8e" Accept-Ranges: bytes Content-Length: 632832 Connection: close Content-Type: application/msword Seems like it works for me. Maybe you have another URL which doesn't work for urlopen, but for which IE does actually display a percentage progress bar? -Peter From bradtilley at usa.net Mon Aug 23 15:56:40 2004 From: bradtilley at usa.net (Brad Tilley) Date: Mon, 23 Aug 2004 15:56:40 -0400 Subject: Using Python to Disable the new Windows XP Firewall in SP2 Message-ID: I thought some of you might find this of interest. Especially if you use Python for Windows sys-admin tasks and you do not want to use the built-in "Windows Firewall" that came with service pack 2. http://filebox.vt.edu/users/rtilley/downloads/win_fw/Windows-Firewall.html From ialbert at mailblocks.com Mon Aug 2 10:48:52 2004 From: ialbert at mailblocks.com (Istvan Albert) Date: Mon, 02 Aug 2004 10:48:52 -0400 Subject: Strange timing data for list.pop() In-Reply-To: References: Message-ID: Roy Smith wrote: > anybody have any clue what might be causing this behavior? Bad experimental setup. Use the timeit module. Average your measurements. From npat at efault.net Fri Aug 13 17:14:55 2004 From: npat at efault.net (Nick Patavalis) Date: Fri, 13 Aug 2004 21:14:55 +0000 (UTC) Subject: Why I love python. References: Message-ID: On 2004-08-13, kosh wrote: > > I don't want my cell phone to run python, java, ruby, c# etc etc. I > want it to just be a telephone and do that job well. > I understand. You want a nice analog cell-phone, with a large rotary dial, and very long cord. Sorry but resistors, capacitors, and diodes can only go that far. For everything else you need large clusters of transistors (integrated-ccircuits they are called by some) and a lot of them need (God forbid!) "software". /npat P.S. I *have* to sign with this :) -- I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone. -- Bjarne Stroustrup From gry at ll.mit.edu Mon Aug 9 09:59:47 2004 From: gry at ll.mit.edu (george young) Date: 9 Aug 2004 06:59:47 -0700 Subject: Class optimization at runtime References: <10gvtipb5t0hl44@corp.supernews.com> Message-ID: <78b6a744.0408090559.65560369@posting.google.com> Dan Sommers wrote in message news:... > On Tue, 03 Aug 2004 23:46:32 +0200, > Peter Otten <__peter__ at web.de> wrote: > > > Jeff Shannon wrote: > >> Or even better: > >> > >> if option: > >> import WithOption as FooModule > >> else: > >> import WithoutOption as FooModule > >> > >> x = FooModule.Foo( ) > >> > >> (I twitch every time I see 'from X import *' ...) > > Yep, you're right. I always forget about the "as" option. > > > That, and mixed-case module names -- and no, I'm not advertising > > all-uppercase here... > > My mistake again. The names I chose were for illustrative and > explicative purposes only; nothing else was (meant to be) implied. > > For the record, then, it would look like this: > > if option: > import optionon as optionmodule > else: > import optionoff as optionmodule > > x = optionmodule.Foo( ) > > (assuming we can live with an Initialcaps class name). > > It also now strikes me that a package might be appropriate here: Let > __init__.py sort things out and set up the package's namespace > accordingly; then the rest of the program would just use the package > obliviously. But: > > - __init__.py has to have access to the option variable (solutions > abound; good solutions are less plentiful and vary over time and > space); > > - given (a) my recent track record for getting the details correct > and (b) my lack of experience with the package system, I humbly > leave the rest of such a solution to the interested reader. How about the pygtk style "require": import pygtk pygtk.require('2.0') import gtk # uses state set by the "require" call. This always seems a clean interface to me. Much safer and cleaner than something peeking at a global (or environment) variable. From Scott.Daniels at Acm.Org Thu Aug 26 15:21:33 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 26 Aug 2004 12:21:33 -0700 Subject: What GCC version had defined? Message-ID: <412e39d1$1@nntp0.pdx.net> I am trying to figure out how to get 2.4a2 to build a python extension. GCC 2.2.95 does not have a stdint.h, but 3.2.3 does. These two are the only gcc versions I have on my box. Does anyone know which version of GCC introduced stdint.h (and thereby uintptr_t and intptr_t)? I'd like to get the conditionals right. -Scott David Daniels Scott.Daniels at Acm.Org From ptmcg at austin.rr._bogus_.com Sun Aug 22 21:02:13 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Mon, 23 Aug 2004 01:02:13 GMT Subject: Parsing C header files with python References: <873c2gzftf.fsf@emit.demon.co.uk> <87wtzrnj86.fsf@emit.demon.co.uk> Message-ID: "Ian McConnell" wrote in message news:87wtzrnj86.fsf at emit.demon.co.uk... > "Paul McGuire" writes: > > > Thanks. Your example with pyparsing was just what I was looking for. It also > copes very nicely with newlines and spacing in the header file. > Ian - It is just at this kind of one-off parsing job that I think pyparsing really shines. I am sure that you could have accomplished this with regexp's, but a) it would have taken at least a bit longer b) it would have required more whitespace handline (such as function decls that span linebreaks) c) it would have been trickier to add other unanticipated changes (support for other arg data types (such as char, long), embedded comments, etc.) BTW, all it takes to make this grammar comment-immune is to add the following statement before calling scanString(): functionCall.ignore( cStyleComment ) cStyleComment is predefined in the pyparsing module to recognize /* ... */ comments. Adding this will properly handle (i.e., skip over) definitions like: /* int commentedOutFunc(float arg1, float arg2); */ Try that with regexp's! -- Paul From Kevin.Smith at sas.com Mon Aug 23 08:49:37 2004 From: Kevin.Smith at sas.com (Kevin Smith) Date: 23 Aug 2004 12:49:37 GMT Subject: Alternative decorator syntax decision References: <_cyVc.48884$wM.42592@twister.tampabay.rr.com> Message-ID: <20040823085016684-0400@braeburn.themorgue.org> C4 C4 F From rschroev_nospam_ml at fastmail.fm Mon Aug 23 12:31:39 2004 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Mon, 23 Aug 2004 16:31:39 GMT Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: Denis S. Otkidach wrote: > On Thu, 19 Aug 2004 22:35:53 GMT > Roel Schroeven wrote: > > >>Roel Schroeven wrote: >> >> >>>I spotted some errors in your list, added new entries, and made a >>>histogram: http://roelschroeven.net/pythonages/ > > > I'm 29 > Update results still at http://roelschroeven.net/pythonages/ -- "Codito ergo sum" Roel Schroeven From mwh at python.net Sat Aug 7 10:21:35 2004 From: mwh at python.net (Michael Hudson) Date: Sat, 7 Aug 2004 14:21:35 GMT Subject: Paul Graham on Python hackers References: Message-ID: Zoltan Sekeres writes: > On Fri, 06 Aug 2004 22:23:59 -0700, ellisjb wrote: > > (In all seriousness I think python and java have a lot more in common than > > python and perl.) > > This a flamebait, right? I don't think so. I've noticed that since I learnt Python, it is now much more frequently compared to Java than Perl, and this is a change. > Otherwise I would be interested in the features which make Python > similar to Java (shudder). I think it's at least as much social as technical. Cheers, mwh -- First time I've gotten a programming job that required a drug test. I was worried they were going to say "you don't have enough LSD in your system to do Unix programming". -- Paul Tomblin -- http://home.xnet.com/~raven/Sysadmin/ASR.Quotes.html From megalomaan at hotmail.com Thu Aug 26 15:04:25 2004 From: megalomaan at hotmail.com (m0226065) Date: Thu, 26 Aug 2004 21:04:25 +0200 Subject: Looking for a mySQL module References: <1093546553.242839@seven.kulnet.kuleuven.ac.be> Message-ID: <1093547060.94055@seven.kulnet.kuleuven.ac.be> sorry about that found it MySQLdb -- ____________________________________________________ Johan Potums Vaartstraat 67 3000 Leuven "m0226065" schreef in bericht news:1093546553.242839 at seven.kulnet.kuleuven.ac.be... > Hello > > I'm looking for a mySQL module so I can address my miniserver > (http://miniserver.sourceforge.net). I looked on google, but I'm not sure > I'm getting what I want > > thx > > -- > ____________________________________________________ > Johan Potums > Vaartstraat 67 > 3000 Leuven > > > > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.737 / Virus Database: 491 - Release Date: 11/08/2004 > > --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.737 / Virus Database: 491 - Release Date: 11/08/2004 From ian at cottee.org Wed Aug 25 22:34:59 2004 From: ian at cottee.org (Ian J Cottee) Date: Thu, 26 Aug 2004 11:34:59 +0900 Subject: Proposal for removing self In-Reply-To: <412D14FC.BDF40BAD@alcyone.com> References: <412D14FC.BDF40BAD@alcyone.com> Message-ID: Erik Max Francis wrote: > Furthermore, I believe there's been some talk as a prefixed dot being > reserved for possible use in a "with" control structure at some point in > the future. So using it to abbreviate self is definitely out. > (Besides, this proposal is not new.) Which means the op would be able to do with self .firstname = 'Brian' .surname = 'Trubshaw' .occupation = 'Test Pilot' .ovine_experience = 'Unknown' I guess Ian From bulatov at engr.orst.edu Fri Aug 20 22:49:23 2004 From: bulatov at engr.orst.edu (Yaroslav Bulatov) Date: Sat, 21 Aug 2004 02:49:23 GMT Subject: Python AI resources Message-ID: <4126b82f$1@news.unimelb.edu.au> The list of Python AI/Machine Learning resources has been recently expanded. http://yaroslav.hopto.org/pubwiki/index.php/ai-python It's a wiki page, so feel free to add to it Yaroslav [ 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 tor.iver.wilhelmsen at broadpark.no Thu Aug 5 16:33:07 2004 From: tor.iver.wilhelmsen at broadpark.no (Tor Iver Wilhelmsen) Date: 05 Aug 2004 22:33:07 +0200 Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) References: <1646998998.20040804190026@MailBlocks.com> Message-ID: steven.bethard at gmail.com (Steven Bethard) writes: > These are, of course, the standard reasons against introducing new > keywords, and the same reasons that Python tries not to introduce them > unnecessarily. Still, I think, for example, the 'yield' generator > syntax (which was introduced relatively recently) is much clearer than > doing something strange with punctuation would have been. I guess I > just don't see why decorators merit strange punctuation when > generators didn't... Also, in the case of Java, keywords actually have been introduced (strictfp, assert), in the latter case leading to a rewrite of the "standard" unit test library JUnit which changed a framework method name (assert() -> assertTrue()). However, a "foreach" would just pollute (in a sense) as long as it's very close to for, and it demantically makes sense to "reuse" it instead (like they do for "class", which both is used in a class declaration and to access a class object statically). Both strictfp and assert did new things that didn't match what any other language feature did. From ben at benlast.com Tue Aug 17 09:23:38 2004 From: ben at benlast.com (Ben Last) Date: Tue, 17 Aug 2004 14:23:38 +0100 Subject: 'ascii' codec can't encode character u'\xf3' In-Reply-To: <20040817082127.GA5233@barbucha.martin.net> Message-ID: > if i use > #! /usr/bin/env python > # -*- coding: UTF-8 -*- > at the begginnig of my every script, the example above still has to > be converted -- because of the iso-8859-1 you use in "L?wis"? Be aware that if you declare the encoding as UTF-8, you should really make sure that you're using an editor that understands UTF-8; not all the characters you might type freely (or copy and paste) are the same in UTF8 and Latin-1. For example, if you inadvertently paste an ellipsis (...), which is \x85 in Western-Europe Windows into such a file, then you may get errors, since the ellipsis in Unicode is a different code altogether. The first "page" of UTF-8 maps exactly to ISO-Latin-1 (ISO-8859-1), but since you're using a Czech locale, I'd expect you to be using Latin-2, and for your editors to enter characters as Latin-2. regards ben From wheakorypersonal at yahoo.com Tue Aug 24 14:55:23 2004 From: wheakorypersonal at yahoo.com (Kory Wheatley) Date: Tue, 24 Aug 2004 11:55:23 -0700 (PDT) Subject: Printing date a file Message-ID: <20040824185523.46724.qmail@web51904.mail.yahoo.com> In Python how would you print the date in a file, I have a logging program written in python and for each new recorded added to the file, I would like to print the date, something like this below: 08/24/2004 or 08-24-2004 -- Kory Wheatley __________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - Send 10MB messages! http://promotions.yahoo.com/new_mail From gregor.jan at NOSPAMquick.cz Wed Aug 11 10:19:08 2004 From: gregor.jan at NOSPAMquick.cz (Jan Gregor) Date: Wed, 11 Aug 2004 14:19:08 +0000 (UTC) Subject: jython and java exceptions References: <4_nSc.24773$Z14.7584@news.indigo.ie> Message-ID: There's result - i put aa on input to force error: Exc com.sybase.jdbc2.jdbc.SybSQLException: Stored procedure 'aa' not found. Specify owner.objectname or use sp_help to check whether the object exists (sp_help may produce lots of output). != subclass of java.sql.SQLException! Problem is that SybSQLException IS subclass of SQLException - verified by Eclipse IDE (type hierarchy). Similar effects were with jdbc driver for PostgreSQL. There's result: Exc org.postgresql.util.PSQLException: ERROR: syntax error at or near "aa" != subclass of java.sql.SQLException! Jan From Florian.Lindner at xgm.de Sun Aug 1 18:14:01 2004 From: Florian.Lindner at xgm.de (Florian Lindner) Date: Mon, 02 Aug 2004 00:14:01 +0200 Subject: Default encoding Message-ID: Hello, how can I get the default encoding of a python installation? Thx, Florian From mfuhr at fuhr.org Fri Aug 13 09:57:57 2004 From: mfuhr at fuhr.org (Michael Fuhr) Date: 13 Aug 2004 07:57:57 -0600 Subject: Python and Weather.com References: <6491b0ab.0408121917.5103b770@posting.google.com> Message-ID: <411cc8e5$1_2@omega.dimensional.com> faizans at gmail.com (Fazer) writes: > I made a small python script that gives the current weather conditions > of a city that you give as an argument. You could also use pymetar. http://www.schwarzvogel.de/software-pymetar.shtml -- Michael Fuhr http://www.fuhr.org/~mfuhr/ From bokr at oz.net Wed Aug 25 06:08:06 2004 From: bokr at oz.net (Bengt Richter) Date: 25 Aug 2004 10:08:06 GMT Subject: Are decorators really that different from metaclasses... References: Message-ID: On Wed, 25 Aug 2004 13:26:03 +1000, Anthony Baxter wrote: >I forgot one other point I meant to add - think about when the body of >a class gets executed, vs when the body of a function gets executed. >The former is at compile time, the latter is when the function is >used. Actually, the body of the class gets executed after whatever code just precedes the class def (though with a different environment, with bindings going into the class dict), but UIAM both of those are compiled when the combined source is compiled? if you put the class def inside a function and dis.dis it, you get: >>> def foo(): ... class C(object): ... __metaclass__ = MC ... def m(self): return 'method m' ... return C ... Above we have *compiled* both foo and the class definition in its body, but we have executed only the foo *definition*. (Note no complaint here about MC undefined) >>> import dis >>> dis.dis(foo) 2 0 LOAD_CONST 1 ('C') 3 LOAD_GLOBAL 0 (object) 6 BUILD_TUPLE 1 9 LOAD_CONST 2 (", line 2>) 12 MAKE_FUNCTION 0 15 CALL_FUNCTION 0 18 BUILD_CLASS 19 STORE_FAST 0 (C) 5 22 LOAD_FAST 0 (C) 25 RETURN_VALUE 26 LOAD_CONST 0 (None) 29 RETURN_VALUE Just to show when the class definition finishes: >>> def MC(*args): print args; return type(*args) ... Now call foo to make the class *definition* in the body of foo execute (BTW triggering MC): >>> Cfoo = foo() ('C', (,), {'m': , '__module__': '__main__', '__metacla ss__': }) (the printed args tuple above wrapped, obviously) What we got: >>> Cfoo >>> Cfoo.m >>> Cfoo().m > Regards, Bengt Richter From mark_bottjer at hotmail.com Wed Aug 11 18:15:26 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Wed, 11 Aug 2004 18:15:26 -0400 Subject: PEP-0318 In-Reply-To: References: <41122FC2.1080608@interlink.com.au><4114152f@nntp.zianet.com> <4116bc20$1@nntp.zianet.com><6NCdncg4ssq28orcRVn-uQ@powergate.ca> <411a5cee$1@nntp.zianet.com> Message-ID: <411a9a7f$1@nntp.zianet.com> Fredrik Lundh wrote: > calling a function with an argument? that's a pretty common > operation, if you're asking me Indeed it is. And that fact bears on this conversion how? -- Mark From davebrok at soda.csua.berkeley.edu Tue Aug 17 18:24:15 2004 From: davebrok at soda.csua.berkeley.edu (David Pokorny) Date: Tue, 17 Aug 2004 15:24:15 -0700 Subject: Why is SETUP_FINALLY uninterruptable[sic]? Message-ID: <2JmdnSiV4NZzGL_cRVn-pg@lmi.net> Whilst swimming through Python/ceval.c, I came upon the following: PyEval_EvalFrame(...) { ...
    ... if (--_Py_Ticker < 0) { if (*next_instr == SETUP_FINALLY) { /* Make the last opcode before a try: finally: block uninterruptable. */ goto fast_next_opcode; } _Py_Ticker = _Py_CheckInterval; tstate->tick_counter++; ... } I've been trying to find a good reason _why_ the main loop shouldn't perform the check at the usual time in the (highly rare) situation where SETUP_FINALLY occurs as the last instruction before a check. So far, I've managed to confuse myself even further and come up with another stumper: what makes SETUP_FINALLY more special than SETUP_LOOP and SETUP_EXCEPT? The best answer I can think of is this: if another thread ran in between the SETUP_FINALLY and the next first instruction of the try block, then this other thread might step on some globals that SETUP_FINALLY uses to communicate to the try block. As far as I can tell, no such communication takes place and this isn't the reason. Could a Python guru please enlighten me? David From olivier.parisy at free.fr Mon Aug 9 09:30:40 2004 From: olivier.parisy at free.fr (Olivier Parisy) Date: Mon, 09 Aug 2004 15:30:40 +0200 Subject: Exceptions as a Control Structure In-Reply-To: References: <411775aa$0$17867$626a14ce@news.free.fr> Message-ID: <41177c78$0$17859$626a14ce@news.free.fr> Roy Smith wrote: > Lots of things you do in C++ are frowned upon in Python. Lots of things > you do in Python are frowned upon in C++. This is something I need to learn. I suppose there's not much written information on this informal topic, and that I'll have to read some source code... Any advice on cleanly written projects from that point of view ? > Specifically, exceptions in C++ are generally considered fairly > heavy-weight, but not so in Python. Here's another common python idiom > that uses exceptions in a way which would probably horrify most C++ > people: > > for key in sequence: > try: > foo = dictionary [key] > except KeyError > foo = "not found" > > instead of: > > for key in sequence: > if dictionary.has_key (key): > foo = dictionary [key] > else > foo = "not found" Hum, I stumbled on this FAQ a short time after I posted here, indeed :-) Regards, Olivier. From firemoth at gmail.com Mon Aug 16 00:37:20 2004 From: firemoth at gmail.com (Timothy Fitz) Date: 15 Aug 2004 21:37:20 -0700 Subject: Generators versus Coroutines References: <7x7js1i887.fsf@ruckus.brouhaha.com> Message-ID: <972ec5bd.0408152037.c50bcee@posting.google.com> Lenard Lindstrom wrote in message news:... > Nick Patavalis writes: > > > On 2004-08-14, Paul Rubin <> wrote: > > > > > > You can't yield across multiple levels of function calls. That's why > > > they're called "simple generators" instead of just "generators". > > > > > > > For me it would be *tremendously* usefull if one could yield across > > multiple levels of function calls. If this was supported, then most > > uses of O/S treads could be replaced by generators. > > > > Does anyone know if such a feature is planned? > > > Having followed the development of Prothon it is my understanding that > such a thing is not possible in CPython for two reasons. The first is > that the yield statement itself defines a function declaration as a > generator. Without a specific "gen" declarator keyword as in Prothon: > > gen evens(n): # This is a generator > for i in n: # "for i in range(n)" in Python > doubleit(i) > > def doubleit(i) # This is a helper that yields > yield(2 * x) # "yield 2 * x" > > for i in evens(5): > print(i) # "print i" > > the yield does not know how many function calls up it must go to return > a value. In CPython it simply saves one frame, that of the current function > call. The second reason is a python function call in CPython involves an > actual recursive C call of the interpreter. So to have a yield span more > than one python function would require saving and restoring part of the > actual C stack - coroutines at the C level - or a rewrite of the interpreter > to not make the recursive C calls as in Stackless Python. > > Lenard Lindstrom > I disagree, it seems to me I could make a pure python based implementation with some funky state handling classes and exceptions. Granted, it wouldn't look nice (all your 'locals' would be in an object, and you'd have to call like tyield()) From Jared.Cohen at noaa.gov Fri Aug 20 10:04:30 2004 From: Jared.Cohen at noaa.gov (Jared Cohen) Date: Fri, 20 Aug 2004 10:04:30 -0400 Subject: [Tkinter-discuss] Please help -- Tkinter Scale widget with DoubleVar is acting weird Message-ID: <412604EE.6070802@noaa.gov> Thanks to both of you for your help. I already do have mechanisms in place that prevent the callback from actually doing anything if the variable has not really been changed. But the problem with that method (and with both of your suggestions) is that even if the callback doesn't do anything, it is still getting invoked when it shouldn't be. I was simply trying to figure out WHY, because I felt that it would be more elegant to completely stop the callback from getting invoked incorrectly, than to allow it to be invoked and then have it return without doing anything. But if that's not feasible, then I'll just have to do it the other way :-) -------------- next part -------------- An HTML attachment was scrubbed... URL: From lconrad at laymusic.org Fri Aug 6 16:03:37 2004 From: lconrad at laymusic.org (Laura Conrad) Date: Fri, 06 Aug 2004 16:03:37 -0400 Subject: Killing children References: <87smb0w4ln.fsf@debian.laymusic.org> Message-ID: <87d624vxt2.fsf@debian.laymusic.org> >>>>> "Stefan" == Stefan Eischet writes: Stefan> Hi Laura, Stefan> what a terrible subject line! ;-) I used to think that when I first started using UNIX in the mid 80's. But I am now a hardened child-killer. Stefan> I sometimes use os.system with pskill from Stefan> http://www.sysinternals.com/ntw2k/freeware/pskill.shtml - Stefan> this should do what you want. I don't see that it really saves me much over using the cygwin kill command. Stefan> I do get my pid from some spawn-variant, IIRC. This should Stefan> be more reliable than killing by name or parsing ps output Stefan> (since you might kill the wrong process if there are Stefan> multiple processes with the same name). Yes, that's one of the things I'm worried about. Stefan> What exactly doesn't work with your spawning? Could you Stefan> post the spawn call you're using? I'm attaching the test program. With the commented out call to spawn loop.py, it seems to work fine, both on linux and on cygwin. When I call the actual program, which reads and writes the serial port and writes into a postgresql database, as well as to stdout, it doesn't look like it's invoking the program at all on cygwin. (loop.py just writes the date to sdout every 5 seconds.) The process it spawns doesn't appear on the ps, and no data gets put in the database or written to stdout. When it tries to kill the process it's spawned, I get an error message: "kill 2348: Operation not permitted", which is different from the message I get if I just kill a process that doesn't exist, so something is happening, but it isn't what I want. -------------- next part -------------- A non-text attachment was scrubbed... Name: testspawn.py Type: text/x-python Size: 253 bytes Desc: not available URL: -------------- next part -------------- -- Laura (mailto:lconrad at laymusic.org , http://www.laymusic.org/ ) (617) 661-8097 fax: (501) 641-5011 233 Broadway, Cambridge, MA 02139 From abra9823 at mail.usyd.edu.au Sun Aug 8 00:02:14 2004 From: abra9823 at mail.usyd.edu.au (Ajay Brar) Date: Sun, 08 Aug 2004 14:02:14 +1000 Subject: session management Message-ID: <4115A5C6.6010206@mail.usyd.edu.au> hi! I am trying to implement session management similar to what PHP does by having a temp file with session information and storing the filename(which is just a random string) as a cookie on the client side. if the client logs out, i can destroy the file and the cookie but my question is what happens when the client does not log out? what if he simply leaves the website? i can put a timer on the cookie, but how do i cleanup the temp files. also, is there some python package that already does this and does not require any configuration on the webserver (i dont have access to config the webserver). and how secure would such a mechanism be? the user enters their username and password and i compare the hash of both the username and password with values stored in an encrypted file. if the comparison is successful i create the session. is this a reasonably secure scheme? does anyone see any problems with this thanks cheers -- Ajay Brar CS Honours 2004 Smart Internet Technology Research Group http://www.it.usyd.edu.au/~abrar1 From mcfletch at rogers.com Tue Aug 10 00:30:06 2004 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Tue, 10 Aug 2004 00:30:06 -0400 Subject: Popular Python projects with lots of pure Python code In-Reply-To: <4117F439.40805@ocf.berkeley.edu> References: <4117F439.40805@ocf.berkeley.edu> Message-ID: <41184F4E.4060502@rogers.com> Brett C. wrote: ... > So I am trying to come up with a list of projects I can use to get my > stats from. the stdlib is a no-brainer. Also plan to use Docutils. > But beyond those most of the big Python projects I can think of have a > ton of C code which is of no use to me. I don't need to be able to > run it, just going to be compiling to .py files. > > Any suggestions? First that spring to mind: * Zope3 (198,000 lines of Python code in the checkout I'm counting) * Twisted (129,000 lines of code in the version I have, tends toward very idiomatic usage due to the asynchronous nature, so be aware of potential skew in the results) * Mailman (don't have it installed to check) * Boa Constructor (63,000 lines, with some of that auto-generated IIRC) * PythonCard (52,000 lines) * PySNMP (14,000 lines) And from my own projects: * OpenGLContext with the (included) vrml and (separate) TTFQuery dependencies (34,000 lines of Python code). * PyTable including the BasicProperty and BasicTypes dependencies (14,000 lines of Python code), but this one probably falls down on the "popular" grounds Some of the other web frameworks may have reached the 100,000+ range, but I don't have them installed to check. I would guess that some of the other GUI environments might be useful, e.g. Pythonwin (not including the win32 framework stuff) is 17,000 lines. Other GUI environments are going to be larger I'd guess, but they'll also potentially be more of a mix of C and Python. HTH, Mike ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From roy at panix.com Tue Aug 17 12:23:51 2004 From: roy at panix.com (Roy Smith) Date: Tue, 17 Aug 2004 12:23:51 -0400 Subject: Problem with floating point precision References: Message-ID: j_mckitrick at bigfoot.com (j_mckitrick) wrote: > I checked the docs, but found nothing about floating point issues. > > I am working on an app that deals with currency values, and only does > addition and subtraction (no division). But I am starting to see > values that should be the same failing a compare! What is the > workaround or correct way to compare 2 floats? A full analysis of floating point math would fill a book. The details depend greatly on the underlying FP hardware in your system, although these days it's pretty hard to find a machine which doesn't use IEEE 754 standard math, so you might start by googling for "ieee 754". Python 2.4 will have a new Decimal numeric type, which was invented to resolve many of the problems that happen when trying to use floats for currency calculations. Take a look at http://www.python.org/peps/pep-0327.html for more information. There is an alpha version of 2.4 that was released recently; you might want to download that and start playing around with the Decimal type to see if that solves your problem. I'm sure other people here could give a better estimate of when there will be a production release of 2.4, but my guess is that it's a few months away. From eurleif at ecritters.biz Sat Aug 7 19:59:57 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sat, 07 Aug 2004 19:59:57 -0400 Subject: Image manipulation library under a GPL-compatible license? In-Reply-To: References: <2nl3suF1vntdU1@uni-berlin.de> Message-ID: <2nl8k3F1vioiU1@uni-berlin.de> Fredrik Lundh wrote: > sorry, but you don't have the slightest idea what you're talking > about. PIL uses the original Python license, about which FSF > has the following to say: Sorry, you're right. For some reason, I got "the name of Secret Labs AB or the author not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission" with the obnoxious BSD advertising clause. Please disregard anything else I say, because I've probably done way too litle research. From martin at v.loewis.de Fri Aug 6 04:14:01 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 06 Aug 2004 10:14:01 +0200 Subject: PEP 263 status check In-Reply-To: References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> <10h5hgvpafm8a64@news.supernews.com> Message-ID: <41133dc8$0$24849$9b622d9e@news.freenet.de> Vincent Wehren wrote: > Here's another thought: the company I work for uses (embedded) Python as > scripting language > for their report writer (among other things). Users can add little scripts > to their document templates which are used for printing database data. This > means, there are literally hundreds of little Python scripts embeddeded > within the document templates, which themselves are stored in whatever > database is used as the backend. In such a case, "scan and update" when > upgrading gets a little more complicated ;) At the same time, it might get also more simple. If the user interface to edit these scripts is encoding-aware, and/or the database to store them in is encoding-aware, an automated tool would not need to guess what the encoding in the source is. > | My specific question there was how the code handles the > | combination of UTF-8 as the encoding and a non-ascii > | character in an 8-bit string literal. Is this an error? The > | PEP does not say so. If it isn't, what encoding will > | it use to translate from unicode back to an 8-bit > | encoding? > > Isn't this covered by: > > "Embedding of differently encoded data is not allowed and will > result in a decoding error during compilation of the Python > source code." No. It is perfectly legal to have non-ASCII data in 8-bit string literals (aka byte string literals, aka ). Of course, these non-ASCII data also need to be encoded in UTF-8. Whether UTF-8 is an 8-bit encoding, I don't know - it is more precisely described as a multibyte encoding. At execution time, the byte string literals then have the source encoding again, i.e. UTF-8. Regards, Martin From peter at engcorp.com Thu Aug 12 10:46:27 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 12 Aug 2004 10:46:27 -0400 Subject: decorator with keyword In-Reply-To: References: Message-ID: Christopher T King wrote: [about the "decorate:" syntax] > The PythonDecorators wiki doesn't say Guido has specifically shot this > style down, so it may yet have a chance. The python-dev mailing list doesn't appear to have discussed this one yet, but given that much of the, uh, "chatter" that I detect there is about minor tweaking of the @pie syntax, I fear they are so not likely to pay much attention to new syntaxes and it might be too late to get much support for it amongst the core folks. (Guido referred to @pie as "the humble @decorator" yesterday...) -Peter From lbates at swamisoft.com Tue Aug 3 13:50:42 2004 From: lbates at swamisoft.com (Larry Bates) Date: Tue, 3 Aug 2004 12:50:42 -0500 Subject: how to do proper subclassing? References: Message-ID: <4Nydna8aCobvTZLcRVn-vw@comcast.com> I think you want to have permfooation actually be a list. If you do then permfooation[1:3} will in fact return a list [3,4]. If the permutation is actually stored as: [0 1 2 3 4] [1 3 4 0 2] You can get them into lists with: f=open(inputfile) lines=f.readlines() f.close() l=0 for line in lines: if l % 2 == 0: continue # skip first lines l+=1 permfooation=[int(x) for x in line[1:-1].split()] print permfooation[1:3] Now you are probably going to want to wrap this into a class for easier use. HTH, Larry Bates Syscon, Inc. "Jonas Koelker" wrote in message news:mailman.1095.1091552353.5135.python-list at python.org... > Hello there. > > I'm new to this list (/me welcomes himself). > > anyways, I'm having doubts about how to subclass > properly. The big picture is that I want to handle > permutations. As we all know, two popular notation > forms exist: products of disjoint cycles ("(0 1 3)(2 > 4)") and 2*length matrices with the identity > permutation as the first line ([0 1 2 3 4] over [1 3 4 > 0 2]). I find the latter more appropriate, since it's > easy to store as a list (one can skip the first line, > assuming it's _always_ the identity). > > However, I want the permutation to act like a list, in > all those cases where I don't override the operations. > For example, assuming permfooation is the above > permutation [1 3 4 0 2], permfooation[1:3] should > return [3,4]. How is this done? Do I have to actually > implement a slice-mechanism in the permutation class? > > thanks, > > -- Jonas K?lker > > > > > > ___________________________________________________________ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com From bokr at oz.net Sun Aug 8 19:12:33 2004 From: bokr at oz.net (Bengt Richter) Date: 8 Aug 2004 23:12:33 GMT Subject: @decorator syntax is sugar, but for what exactly? References: Message-ID: On Sun, 8 Aug 2004 02:00:41 +0200, Tristan Seligmann wrote: [...] >On Sat, Aug 07, 2004 at 23:50:47 +0000, Bengt Richter wrote: > >The code: > >> @limited_expression_producing_function >> @another >> def func(): pass >>=20 > >is equivalent to: > >def func(): pass >func =3D limited_expression_producing_function(another(func)) [...] I've seen that transformation before ;-) I'd be interested if someone with 2.4 would do the following (untested): def A(f): return f def B(f): return f def foo(): @A @B def bar(): pass return bar def baz(): def bar(): pass return A(B(bar) import dis dis.dis(foo) dis.dis(baz) Regards, Bengt Richter From simoninusa2001 at yahoo.co.uk Thu Aug 19 17:30:53 2004 From: simoninusa2001 at yahoo.co.uk (simoninusa2001 at yahoo.co.uk) Date: 19 Aug 2004 14:30:53 -0700 Subject: ANN: pyxe Message-ID: Forgive me if this comes out odd, I'm testing the new http://groups-beta.google.com/group/comp.lang.python - it seems to encourage top-posting and quoting the entire previous thread! Anyway, what sets this app apart from py2exe (or cx_Freeze, BundleBuilder or McMillan Installer for that matter)? I built the hello.py but it seemed to just create another pyxe.exe, the same seems to have happened for your SimpleHTTPServer in the example directory..... Gerson Kurz wrote: > pyxe is a small executable that will run python scripts on a machine > that doesn't have Python installed. Example: You have the following > hello.py: > > def main(): > print "Hello, World" > > You can create a binary distribution using > > pyxe /build hello > > This will create a directory ./hello which contains all you need. Copy > all files to a host system and run the app using > > pyxe hello > > That's it. Note that your app must define a > > def main(): > > which is the main procedure to start from pyxe. There is one known > restriction, sys.argv[] doesn't get properly setup in pyxe > environment. You can fix this yourself: > > import sys > try: > import cfrompy > sys.argv = cfrompy.GetSysArgv() > except ImportError: > assert sys.argv > > Easy, eh? Requirements > > - On the developer machine, you must have python23 installed. > - On the target machine, no requirements. > - Tested on Windows NT and Windows 2000. You are on your own with > other systems (such as XP, 03 etc.) > > pyxe is free for any purpose whatsoever. > > Download: > http://p-nand-q.com/python/pyxe.zip > > includes the full sourcecode and a sample app in Python which actually > is the "SimpleHTTPServer" webserver ;) Enjoy > > Homepage = this mail in fancy tags: > http://p-nand-q.com/python/pyxe.html From __peter__ at web.de Tue Aug 31 11:28:01 2004 From: __peter__ at web.de (Peter Otten) Date: Tue, 31 Aug 2004 17:28:01 +0200 Subject: Splitting a list References: <41A1CBC76FDECC42B67946519C6677A9018C2F6B@pippin.int.etrials.com> Message-ID: Peter Otten wrote: ... before memory kicked in. http://groups.google.com/groups?selm=c1hkvh%249q5%2400%241%40news.t-online.com Sorry. Peter From dave at inthegarage.net Wed Aug 18 07:21:36 2004 From: dave at inthegarage.net (aToaster) Date: 18 Aug 2004 04:21:36 -0700 Subject: Help passing variables. Message-ID: <8ff6f02e.0408180321.27b4cc39@posting.google.com> Hi guys, new to the forums. I'm starting to learn python and tkinter. I started off by trying to make a simple calculator program and I need to pass the calcTotal variable in and out of the ButtonHandler function, how do I do this? This is my program # ----------------------------------------- from Tkinter import * class CalcApp: def __init__(self, parent): self.myParent = parent self.myContainer1 = Frame(parent) self.myContainer1.pack() # Button 1 button_name = "1" self.button1 = Button(self.myContainer1, command = lambda arg1=1, arg2=button_name : self.buttonHandler(arg1, arg2) ) self.button1.configure(text=button_name) self.button1.pack(side=LEFT) # Button 2 button_name = "2" self.button2 = Button(self.myContainer1, command = lambda arg1=2, arg2=button_name : self.buttonHandler(arg1, arg2) ) self.button2.configure(text=button_name) self.button2.pack() def buttonHandler(self, argument1, argument2): print "You have clicked :", argument2 calcTotal = calcTotal + argument1 print calcTotal def buttonHandler_a(self, argument1, argument2): print "You have clicked :", argument2 calcTotal = calcTotal +argument1 print calcTotal var calcTotal = 0 print "\n"*100 print "Starting program Calc." root = Tk() myapp = CalcApp(root) print "Starting even loop." root.mainloop() print "Finished executing event loop." #End of Program # ----------------------------------------- Any help will be greatly appreciated! Thanks ,aToaster PS. I love Python! From pink at odahoda.de Sun Aug 22 08:06:16 2004 From: pink at odahoda.de (Benjamin Niemann) Date: Sun, 22 Aug 2004 14:06:16 +0200 Subject: Validating SGML parser? In-Reply-To: <2oq5h5Fd6190U1@uni-berlin.de> References: <2oq5h5Fd6190U1@uni-berlin.de> Message-ID: Leif K-Brooks wrote: > Benjamin Niemann wrote: > >> does anyone know of a validating SGML parser in python (like >> xmlproc.xmlval does for XML)? Goal is to validation HTML against the >> DTD, similar to validator.w3.org, not all SGML obscurities are required. > > > There are plenty of command-line tools for that. Why not use one of them > through Python? Portability. The current version (that works can handle XHTML variants) works out of the box on Windows, Linux and probably everything else that supports Python. Would be nice if it could stay this way... From hamilcar at tld.always.invalid Wed Aug 18 22:40:00 2004 From: hamilcar at tld.always.invalid (Hamilcar Barca) Date: Wed, 18 Aug 2004 20:40:00 -0600 Subject: Best programming language References: <873c2ndizt.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Message-ID: <20040818224000.327$PF@news.newsreader.com> Andrew Durdin wrote: > The obvious answer, of course, is that on the newsgroup/mailing list > for language X, define "best programming language" to be X. It saves a > lot of combustion :) Or, try comp.lang.functional, where the flame wars often denigrate "corporation" (read: OO) programmers in favor of the High Priests of Fuctional Programming. From bockman at virgilio.it Fri Aug 27 14:46:59 2004 From: bockman at virgilio.it (Francesco Bochicchio) Date: Fri, 27 Aug 2004 18:46:59 GMT Subject: Class Friends References: <20040827081556.657c3fac.a@c.d> Message-ID: On Fri, 27 Aug 2004 16:55:28 +0000, Jeremy Bowers wrote: > In Python, there isn't much of an idea of "Private"; Python's philosophy > is "We're all consenting adults here." Thus, there isn't much of an idea > of "friends" either. In Java terminology, on a technical level > everybody is already friends with everybody else already. > My own 'rule of thumb' in accessing from outside to the attributes of a Python class is "read attributes directly, but change them only via methods". In other words, I treat all attributes in a class as 'readonly'. This allow me to cut off amletic questions like "shall this be public of private?", only to change it later on. The rule is so effective that I tend to use it also in languages that allow public/protected/private distinctions, like C++ and Java. From des.small at bristol.ac.uk Fri Aug 20 06:35:18 2004 From: des.small at bristol.ac.uk (Des Small) Date: Fri, 20 Aug 2004 10:35:18 GMT Subject: Regular expression guaranteed to fail Message-ID: I want to use sets and regular expressions to implement some linguistic ideas. Representing sounds by symbols, and properties (coronal or velar articulation; voicedness) by sets of symbols with those properties, it is natural to then map these sets, and intersections of them, to regular expressions to apply to strings. The question is, what regular expression should correspond to the empty set? I've provisionally gone with "(?!.*)", i.e., the negation of a look-ahead which matches anything. Is there an established idiom for this, and is that it? And if there isn't, does this seem reasonable? Example code: """ import sets def str2set(s): return sets.Set(s.split()) cor = str2set("N D T") # Coronal articulation vel = str2set("K G") # Velar articulation voi = str2set("N D G") # Voiced def set2re(s): if s: return "|".join([e for e in s]) else: return "(?!.*)" """ So we can get a regexp (string) that matches symbols corresponding to velar and voiced sounds: """ >>> set2re(cor & voi) => 'D|N' """ But nothing can be (in this model at least) velar and coronal: """ >>> cor & vel => Set([]) """ and this maps to the Regexp Which Matches Nothing: """ >>> set2re(cor & vel) => '(?!.*)' """ This seems quite elegant to me, but there is such a fine line between elegance and utter weirdness and I'd be glad to know which side other persons think I'm on here. Des -- "[T]he structural trend in linguistics which took root with the International Congresses of the twenties and early thirties [...] had close and effective connections with phenomenology in its Husserlian and Hegelian versions." -- Roman Jakobson From pm_mon at yahoo.com Sun Aug 29 20:33:53 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sun, 29 Aug 2004 20:33:53 -0400 Subject: cPickle and __getattr__ In-Reply-To: References: Message-ID: Chris Curvey wrote: > Hi all, > > I have this program > > class Company: > def __init__(self, revenues, costs): > self.revenues = revenues > self.costs = costs > > def __getattr__(self, name): > if name == 'profits': > return self.revenues - self.costs > > c = Company(100, 75) > print c.revenues > print c.costs > print c.profits > > import cPickle > print cPickle.dumps(c) > > Everything works fine up until the last line. If I remove the > __getattr__ function, then everything works (except "print c.profits"). > What is the cPickle class trying to get to that is causing my > __getattr__ function to be called? > > -Chris > When you use __getattr__, you should always raise an attribute error for names that you don't handle. def __getattr__(self, name): if name == 'profits': return self.revenues - self.costs else: raise AttributeError, name Paul From h.b.furuseth at usit.uio.no Sun Aug 8 08:35:55 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 08 Aug 2004 14:35:55 +0200 Subject: Further changes to source encodings, and 7-bit source str's References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> <10h5hgvpafm8a64@news.supernews.com> <41133C76.8040302@v.loewis.de> <10h6rklt3fa1690@news.supernews.com> <41137799.70808@v.loewis.de> <10h724r20kkeqb2@news.supernews.com> <4113D8DF.8080106@v.loewis.de> <10h7tb8nn53ajbb@news.supernews.com> <4114070F.90507@v.loewis.de> <10h8f3md11sou81@news.supernews.com> <411462b5$0$27020$9b622d9e@news.freenet.de> <10h9f3kjlr8up8f@news.supernews.com> Message-ID: John Roth wrote: > The problem I have is that if you use utf-8 as the > source encoding, you can suddenly drop multi-byte > characters into an 8-bit string ***BY ACCIDENT***. > (...) > Now, my suggested solution of this problem was > to require that 8-bit string literals in source that was > encoded with UTF-8 be restricted to the 7-bit > ascii subset. Then shouldn't your solution catch all multibyte encodings, not just UTF-8? Martin v. L?wis wrote: > [Hallvard] proposes your third alternative (ban non-ASCII > characters in byte string literals), not just for UTF-8, > but for all encodings. Not for all files, though, but > only for selected files. John Roth wrote: > Which is what I don't like about it. It adds complexity > to the language and a feature that I don't think is really > necessary (restricting string literals for single-byte encodings.) It's to prevent several errors: * If the source file has one 'coding:' and the output destination has another character set/encoding, then the wrong character set will be output. Python offers two simple solutions to this: - If the program is charset-aware, it can work with Unicode strings, and the 8-bit string literal should be a Unicode literal. - Otherwise, the program can stay away from Unicode and leave the charset problem to the user. * A worse case of the above: If the 8-bit output goes to an utf-8 destination, it won't merely give the wrong character, it will have invalid format. So a program which reads the output may close the connection it reads from, or fail to display the file at all, or - if it is not robust - crash. I expect the same applies to other multibyte encodings, and probably some single-byte encodings too. * If the program is charset-aware and works with Unicode strings, the Unicode handling blows up if it is passed an 8-bit str (example copied from Anders' pychecker feature request): # -*- coding: latin-1 -*- x = "bl?b?rgr?d" unicode(x) --> Traceback (most recent call last): File "/tmp/u.py", line 3, in ? unicode(x) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 2: ordinal not in range(128) The problem is that even though the file is tagged with latin-1, the string x does not inherit that tag. So the Unicode handling doesn't know which character set, if any, the string contains. > The other thing I don't like is that it still leaves the > trap for the unwary which I'm discussing. Well, I would like to see a feature like this turned on by default eventually (both for UTF-8 and other character sets), but for the time being I'll stick to getting the feature into Python in the first place. Though I do seem to have been too unambitious. For some reason I was thinking it would be harder to get a new option into Python than a per-file declaration. -- Hallvard From nomail at nospam.no Sun Aug 22 04:28:26 2004 From: nomail at nospam.no (Dominic) Date: Sun, 22 Aug 2004 10:28:26 +0200 Subject: Python future performance and speed In-Reply-To: <278de0e.0408211605.426e5129@posting.google.com> References: <278de0e.0408211605.426e5129@posting.google.com> Message-ID: Neuruss wrote: > It seems there are quite a few projects aimed to improve Python's > speed and, therefore, eliminate its main limitation for mainstream > acceptance. > I just wonder what do you all think? Well, I have written a (simple) graphical real time simulator which does 1024x768x16 with at least 20 frames per second on a PIII 800MHz notebook. I have wrapped a game graphics library with Pyrex which was not very difficult. However the differential equation solver had been slow in Python. So I rewrote in C++ and wrapped it with Boost until I learned that using Pysco would give me the same boost without C++! So apart from the small graphics library wrapper everything has been done in Python. If JIT for Python gets better Pyrex and the likes will "only" be useful for wrapping existing C/C++ code. Ciao, Dominic From fred at acme.com Tue Aug 10 08:40:51 2004 From: fred at acme.com (Fred) Date: Tue, 10 Aug 2004 14:40:51 +0200 Subject: VB-like GUI designer? References: Message-ID: <4eghh0hlotu5thcc2bar0mn8l4nkog8nin@4ax.com> On Mon, 9 Aug 2004 21:13:47 -0700, "Roger Binns" wrote: (snip) Thx, the slides are very educational :-) And if I Python provides a high-quality grid object or makes it a snap to work with the ComponentOne ActiveX we currently use, I'll be happy as a pig ... er .. a snake in mud. Cheers Fred. From yong at net.tamu.edu Fri Aug 6 12:58:35 2004 From: yong at net.tamu.edu (Yong Wang) Date: Fri, 6 Aug 2004 11:58:35 -0500 (CDT) Subject: directory path access Message-ID: <20040806165835.C27501589B@net.tamu.edu> Hi, all: In my memmory, there is a system command to display all directory paths the python program has accessed. What is command format ? I only remember use sys.path.append or insert to add the path. Thanks a lot. Yong From pwilkinson at videotron.ca Fri Aug 6 13:23:41 2004 From: pwilkinson at videotron.ca (Peter Wilkinson) Date: Fri, 06 Aug 2004 13:23:41 -0400 Subject: unicode to ascii converting Message-ID: <6.0.3.0.0.20040806131428.01bb4fa8@pop.videotron.ca> Hello tlistmembers, I am using the encoding function to convert unicode to ascii. At one point this code was working just fine, however, now it has broken. I am reading a text file that has is in unicode (I am unsure of which flavour or bit depth). as I read in the file one line at a time (readlines()) it converts to ascii. Simple enough. At the same time I am copressing to bz2 with the bz2 module but that works just fine. The code is and error reported appears below. I am unsure what to do. I assume that because it is reporting that ordinal is not in range, that something to do with the character width that I am reading? Peter W. def encode_file(file_path, encode_type, compress='N'): """ Changes encoding of file """ new_encode = encode_type old_file_path = file_path + '.old' new_file_path = file_path os.rename(file_path,old_file_path) file_in = file(old_file_path,'r') if compress == 'Y' or compress == 'y': bz_file_path = file_path + '.bz2' bz_file_out = bz2.BZ2File(bz_file_path, 'w') for line in file_in.readlines(): bz_file_out.write(line.encode(new_encode)) bz_file_out.close() else: file_out = file(file_path,'w') for line in file_in.readlines(): file_out.write(line.encode(new_encode)) file_out.close() file_in.close() os.remove(old_file_path) ERROR Reported: Parsing X:\GenomeQuebec_repository\microarray\HIS\M15K\Step_1_repository\HISH0224.txt Traceback (most recent call last): File "C:\Program Files\ActiveState Komodo 2.5\callkomodo\kdb.py", line 433, in _do_start self.kdb.run(code_ob, locals, locals) File "C:\Python23\lib\bdb.py", line 350, in run exec cmd in globals, locals File "C:\Python23\Lib\site-packages\xBio\Scripts\unicodeToAscii.py", line 158, in ? main() File "C:\Python23\Lib\site-packages\xBio\Scripts\unicodeToAscii.py", line 75, in main encode_file(fileToProcess, options.encode, 'Y') File "C:\Python23\Lib\site-packages\xBio\Scripts\unicodeToAscii.py", line 144, in encode_file bz_file_out.write(line.encode(new_encode)) UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128) From heikowu at ceosg.de Mon Aug 9 14:25:42 2004 From: heikowu at ceosg.de (Heiko Wundram) Date: Mon, 9 Aug 2004 20:25:42 +0200 Subject: What are decorators? In-Reply-To: <68BA7704-EA25-11D8-9BC6-000A9574CFD8@earthlink.net> References: <68BA7704-EA25-11D8-9BC6-000A9574CFD8@earthlink.net> Message-ID: <200408092025.42519.heikowu@ceosg.de> Am Montag, 9. August 2004 18:58 schrieb gohaku: > The examples I have seen written in Python of this "Not Yet > Implemented" feature > are confusing to say the least and perplexes me as to its usefulness. Decorators change an object at declaration time (well, Python only supports decorators for methods and functions atm., which are top-level objects nonetheless). Basically, what is done when using decorators is the following: class x(object): @ def y(self,): translates to: class x(object): def y(self,): y = (y) Now, somedecorator gets the method object (rather, a function object) for method y, and may do with it whatever it wishes, needing to return a new method object. Thus, you might do the following: authors = {} # Defining the decorator, just a function. def func_spec(**kwargs): """ This decorator decorates the function with an additional attributes. These additional attributes can be used to confer information about the current function. """ global authors def decoratef(f): for k, v in kwargs.iteritems(): if k == "author": if v not in authors: authors[v] = 0 authors[v] += 1 setattr(f,k,v) return f return decoratef # Defining the class x, which contains a function which has an attribute named # author. class x(object): @ func_spec(author="Heiko Wundram",version="0.1") def y(self): print "Calling y." @ func_spec(author="Somebody else",version="0.2") def z(self): print "Calling z." # Now, for usage. ob = x() print "y's author and version:", ob.y.author, ob.y.version print "z's author and version:", ob.z.author, ob.z.version print "Authors, and functions by authors:", authors ob.y() ob.z() This example is an example of a decorator facilitating attaching meta-data to a function. The decorator also keeps track of how many functions are written by each author (programmer), which might be useful in case you're working for a big company or something... Anyway, decorators as shown above already work out of the box in Python 2.3, but with a more cumbersome syntax: class x(object): def y(self): print "Calling y." y = func_spec(author="Heiko Wundram",version="0.1")(y) def z(self): print "Calling z." z = func_spec(author="Somebody else",version="0.2")(z) Now, decorators can't just change the function object and return it. They may also return a completely new function object: import sys import traceback # Decorator printing debugging output. def debugger(f): def debugf(*args,**kwargs): print "---- DEBUGGER STARTS HERE ----" print "Entering:", f.__name__ print "Arguments:", args print "Keyword arguments:", kwargs print "Running function..." try: try: retv = f(*args,**kwargs) print "Function returned:", repr(retv) return retv except: print "Running function raised exception." traceback.print_exception(*sys.exc_info()) raise finally: print "Leaving:", f.__name__ print "---- DEBUGGER ENDS HERE ----" return debugf class x(object): @ debugger def y(self,raise_exc=False): if raise_exc: raise Exception, "We raise an exception here." else: return (42,"the answer to everything") ob = x() # Call it, once without raising, once with. ob.y() ob.y(True) Now, you could certainly make the debugger decorator a little more intelligent (for example, using inspect, it could parse the arguments and print them out properly), but this example just shows that debugging one function of your code (rather, inspecting input and output) is as easy as just adding @ debugger in front of the function definition. When you're done debugging the function, just remove @ debugger. Again, as before, this could've been done in another fashion for <=2.3 class x(object): def y(self,raise_exc=False): y = debugger(y) But again, having the decorator in front of the function definition simply is more beautiful, that's why this syntactic sugar is being introduced. I've already written up several other examples (e.g. method synchronization), which you can find all over c.l.p. To sum it up: decorators can do a lot, and basically what they do has already been available in Python <= 2.3, but adding syntactic sugar for decorators makes it nicer to use them. Heiko. From mike1 at tumladen.net Wed Aug 11 06:40:54 2004 From: mike1 at tumladen.net (Mike Greaves) Date: 11 Aug 2004 03:40:54 -0700 Subject: class in IronPython? Message-ID: <316f1dc0.0408110240.4c83fb42@posting.google.com> I see from Google groups that I'm not the only one to have this problem... In Jim H.'s new IronPython 0.6: mono bin/IronPythonConsole.exe >>> class myClass: ... pass ... System.NullReferenceException: Object reference not set to an instance of an object ... Am I missing something basic? Yes, I suspected Mono, and so tried it in .NET 1.1 on an XP machine... And actual working (non-empty) classes don't work either. Is the class mechanism not yet implemented? Does Jim say as much in a doc or a posting somewhere? Thanks for any insight. Mike Greaves From vincent at visualtrans.de Fri Aug 6 10:39:11 2004 From: vincent at visualtrans.de (vincent wehren) Date: Fri, 06 Aug 2004 16:39:11 +0200 Subject: [Python-Dev] RELEASED Python 2.4, alpha 2 In-Reply-To: <41137960.6050400@v.loewis.de> References: <411231C8.3020308@interlink.com.au> <4113429a$0$26993$9b622d9e@news.freenet.de> <41137960.6050400@v.loewis.de> Message-ID: Martin v. L?wis wrote: > vincent wehren wrote: > >> Well, writing a bunch of the registry keys fails. This user has no >> rights to >> write them and is greated with several error messages as in: >> >> "Could not write value to key >> HKEY_CURRENT_USER\Software\Classes\.py Verify that you have >> sufficient access to that key, or contact your support personnel." >> >> .. Same for .pyw, .pyc, *.pyo etc. >> .. Python.File\shell\open\command >> .. Python.NoConFile\shell\open\command >> .. Python.CompiledFile\shell >> .. Edit with Idle >> >> and so on. I was just wondering if the installer should be aware of the >> rights situation and not try to write those keys in the first place. > > > This is very surprising. How unprivileged must a user be so he can't > write to HKEY_CURRENT_USER? What operating system is this, and how > was the user created? This is on Windows XP Professional. This is a plain vanilla "limited user" created via the user accounts tool in the control panel. > > MSI does have the notion of unprivileged users, but those are the > ones that can't write to System32, the All Users profile, and > HKEY_LOCAL_MACHINE (i.e. non-Administrator, non-Power User users). > There is no provision (AFAICT) for user that can't write to their > own registry. Yes. That makes sense. So I checked the registry with regedit. "HKEY_CURRENT_USER\Software\Classes" seems - for whatever reason - to be busted for this particular user. At least I can't open it manually with regedit, so my tentative guess is the same applies to the installer. Sorry I didn't check this first! -- Vincent Wehren > > Regards, > Martin From martin at v.loewis.de Fri Aug 6 08:28:16 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 06 Aug 2004 14:28:16 +0200 Subject: [Python-Dev] RELEASED Python 2.4, alpha 2 In-Reply-To: References: <411231C8.3020308@interlink.com.au> <4113429a$0$26993$9b622d9e@news.freenet.de> Message-ID: <41137960.6050400@v.loewis.de> vincent wehren wrote: > Well, writing a bunch of the registry keys fails. This user has no rights to > write them and is greated with several error messages as in: > > "Could not write value to key > HKEY_CURRENT_USER\Software\Classes\.py Verify that you have > sufficient access to that key, or contact your support personnel." > > .. Same for .pyw, .pyc, *.pyo etc. > .. Python.File\shell\open\command > .. Python.NoConFile\shell\open\command > .. Python.CompiledFile\shell > .. Edit with Idle > > and so on. I was just wondering if the installer should be aware of the > rights situation and not try to write those keys in the first place. This is very surprising. How unprivileged must a user be so he can't write to HKEY_CURRENT_USER? What operating system is this, and how was the user created? MSI does have the notion of unprivileged users, but those are the ones that can't write to System32, the All Users profile, and HKEY_LOCAL_MACHINE (i.e. non-Administrator, non-Power User users). There is no provision (AFAICT) for user that can't write to their own registry. Regards, Martin From jh at nospam.com Sun Aug 29 14:23:53 2004 From: jh at nospam.com (Hillairet Julien) Date: Sun, 29 Aug 2004 20:23:53 +0200 Subject: [PIL] about the difference between pudata and putpixel References: <153fa67.0408290637.54a7cbc7@posting.google.com> Message-ID: Le Sun, 29 Aug 2004 07:37:37 -0700, Kylotan a ?crit?: > Hillairet Julien wrote in message news:... > >> Although, this code doesn't work: >> >> im.putdata(color) >> >> There is no error message, but the image's pixels stay black (0) ! (The >> color matrix is not an 0-matrix !) >> >> Is someone can explain me my misunderstanding of putdata ? > > I think the misunderstanding is of numarray. I'm guessing that > iterating through a 2D array returns individual rows rather than > individual elements. > > I've never used numarray before but from looking at the documentation, > you could try this: > > im.putdata(color.ravel()) > > or > > im.putdata(ravel(color)) Yes that's it !! I've not understood that Image need an 1D array... Thanks a lot. From gh at ghaering.de Mon Aug 2 18:32:47 2004 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Tue, 03 Aug 2004 00:32:47 +0200 Subject: PostgreSQL on OS X In-Reply-To: <10gh389duis5h51@corp.supernews.com> References: <10gh389duis5h51@corp.supernews.com> Message-ID: <410EC10F.9020000@ghaering.de> Tom Dye wrote: > Aloha Python community, > > Is it possible to access PostgreSQL from Python on Mac OS X? Any help > appreciated. You're looking for a Python database library? pyPgSQL can be built on OS/X. IIRC psycopg too. -- Gerhard From miki.tebeka at zoran.com Mon Aug 23 05:13:26 2004 From: miki.tebeka at zoran.com (Miki Tebeka) Date: Mon, 23 Aug 2004 11:13:26 +0200 Subject: IDLE under Cygwin - no toolbar menu. Any idea why? In-Reply-To: <56cfb0e3.0408191226.43caa96b@posting.google.com> References: <56cfb0e3.0408191226.43caa96b@posting.google.com> Message-ID: <20040823091325.GI1948@zoran.com> Hello Porky, > A question for those using python under Cygwin. I've just installed > the latest distribution with python 2.3.4. One problem I have is when > I start IDLE, it doesn't show toolbar menu (either shell window or > edit window). Does anyone know why and if there is a workaround? TIA. > > (I know I should probably ask Cygwin folks, but just want to check it > here first) It's a known bug. Use "idle -n" (no subprocess) to get the menus. HTH. -- ------------------------------------------------------------------------ Miki Tebeka http://tebeka.spymac.net The only difference between children and adults is the price of the toys From lbates at swamisoft.com Mon Aug 9 10:03:57 2004 From: lbates at swamisoft.com (Larry Bates) Date: Mon, 9 Aug 2004 09:03:57 -0500 Subject: compromise? keywords for static/class, move decorators to top of function References: Message-ID: There are a lot of people talking about decorators that I'm certain are a LOT smarter than me but here goes: Couldn't we use a dictionary construct like the one used in classes to hold the dictionaries attributes. I'm talking about __dict__ construct. def getratio(arg1, arg2): __decorators__['getratio']={} # Maybe this is automatic? # or __decorators__['getratio']=__decoratorbase__.copy() __decorators__['getratio']['classmethod']=True __decorators__['getratio']['accepts']=(int, int) __decorators__['getratio']['returns']=(float) __decorators__['getratio']['metadata1']="some metadata" ... I'm sure I'm missing something but this seems to be 1) Easy on my eye, 2) Extensible (any metadata that you want), 3) Consistent with something I'm already comfortable with. I'm certain that I'm missing something very important, but I have to agree with many others, the '@' syntax just doesn't feel correct. Regards, Larry Bates Syscon, Inc. "Doug Holton" wrote in message news:Oo2dnUOZI8VmWI7cRVn-sA at comcast.com... > First let me say please see the wiki page about python decorators if you > haven't already: http://www.python.org/cgi-bin/moinmoin/PythonDecorators > > I propose (and others have) that built-in features have keyword support, > like static and class methods. Also, I believe it is more readable if > decorators, especially longer ones, are moved to the top of the function > body, just like docstrings, instead of coming before the function is > even declared. Whether you use @ or [] is still open. > > def classmethod getratio (arg1, arg2): > @accepts(int,int) > @returns(float) > ... > > def classmethod getratio (arg1, arg2): > [accepts(int,int), returns(float)] > ... > > This has these advantages: the function declaration itself is still the > first and most important thing, decorators are indented just like the > body of the function so it is more clearly a part of the function. > > In the future though, if you add an "as" keyword for adapters, you could > just say: > > def classmethod getratio (arg1 as int, arg2 as int) as float: > ... > > contrast that simple example with this, which is kind of ugly: > > @accepts(int,int) > @returns(float) > @classmethod #has to be last in order? > def getratio (arg1, arg2): > ... From andreasp at qbcon.com Tue Aug 24 07:13:35 2004 From: andreasp at qbcon.com (Andreas Pauley) Date: Tue, 24 Aug 2004 13:13:35 +0200 Subject: age of Python programmers In-Reply-To: References: Message-ID: <412B22DF.6000205@qbcon.com> Lucas Raab wrote: >One thing I've always kind of wondered is what is the average age of a >Python programmer?? What age groups use Python?? Something to think >about.... > > I'm 25, using Python mostly for sysadmin work at the moment, and expanding my skills to use it for OO system development as well. Andreas Pauley From mov_21h at yahoo.com Sat Aug 14 11:53:10 2004 From: mov_21h at yahoo.com (Bigbowser) Date: Sat, 14 Aug 2004 08:53:10 -0700 (PDT) Subject: Practical examples Message-ID: <20040814155310.45672.qmail@web50001.mail.yahoo.com> hi all, I'm new to python, and have read through http://www.ibiblio.org/obp/thinkCSpy/ , and now I'm looking for some simple programs to have a read through and other more in-depth tutorials to have a look at. Regards, Bigbowser __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From mh at dreadnok.pixar.com Thu Aug 5 19:57:07 2004 From: mh at dreadnok.pixar.com (Mark Harrison) Date: Thu, 05 Aug 2004 23:57:07 GMT Subject: how to force a list to be local? Message-ID: In the following code, t1 does not modify b, while t2 seems to modify b. What do I need to do in order to make b local in t2 so that b.remove() does not modify the passed in list? def t1(a,b): b = [] def t2(a,b): b.remove(4) a=[1,2,3] b=[4,5] t1(a,b) print a,b t2(a,b) print a,b results: [1, 2, 3] [4, 5] [1, 2, 3] [5] Many TIA! Mark -- Mark Harrison Pixar Animation Studios From dw at botanicus.net Mon Aug 30 04:29:55 2004 From: dw at botanicus.net (David Wilson) Date: Mon, 30 Aug 2004 09:29:55 +0100 Subject: The voodoo of zip(*someList) In-Reply-To: <4132E4D5.6050801@botanicus.net> References: <4132E4D5.6050801@botanicus.net> Message-ID: <4132E583.6030409@botanicus.net> David Wilson wrote: > In other words, it allows you to programmatically build an argument > list. Similarly, > > your_mapping = { 'cmpfunc': lambda x: x } > some_list = [ 3, 1, 6, 2 ] > some_list.sort(**your_mapping) > > is equivalent to: > > zip(cmpfunc = lambda x: x) some_list = [ 3, 1, 6, 2 ] some_list.sort(cmpfunc = lambda x: x) There's nothing more confusing when you are trying to learn than an incorrect example. My apologies, lacking sleep here. :) David. From dd55 at cornell.edu Tue Aug 3 13:30:51 2004 From: dd55 at cornell.edu (Darren Dale) Date: Tue, 03 Aug 2004 13:30:51 -0400 Subject: file IO In-Reply-To: References: Message-ID: Jeff Epler wrote: > Are you using Windows? That would mean the answer is almost certainly > "something to do with carriage returns and binary vs text mode". The > lack of a trailing newline on the last line of your example can also > make for additional trouble (though my tests on unix, with stdio, mmap, > and StringIO didn't ever give me a 4-byte file, windows might give you > the file "a\r\nb" when viewed in binary format, "a\nb" when viewed in > text format) > > I doubt that the mmap module's readline knows whether the file was > opened in universal text mode---that's a pure Python invention, while > mmap takes a file descriptor. > I am using windows (for now), and reading files created on a Linux machine. I think you are right, it has something to do with mmap and the /r/n windows convention. Thank you (very much) for your response... I am sane again. Darren From jason at injektilo.org Sat Aug 21 13:57:34 2004 From: jason at injektilo.org (Jason Diamond) Date: Sat, 21 Aug 2004 10:57:34 -0700 Subject: Detecteing Unicode encodings Message-ID: Hi. Is it possible to decode a UTF-8 (with or without a BOM), UTF-16 (BE or LE with a BOM), or UTF-32 (BE or LE with a BOM) byte stream without knowing what encoding the stream is in? I know how to use the codecs module to get StreamReader classes that can decode a specific encoding but I have to know what that enocding is before hand. If I read up to four bytes from the byte stream, I can figure out what encoding the stream is in but that has problems for UTF-8 streams without BOMs--I would have just eaten one or more bytes that might need to be decoded by the StreamReader. I could seek back to the beginning of the stream but what if the file-like object I was reading from didn't support seeking? Thanks. -- Jason From jjl at pobox.com Thu Aug 26 15:00:05 2004 From: jjl at pobox.com (John J. Lee) Date: 26 Aug 2004 20:00:05 +0100 Subject: Missing _sre.pyd in 2.4a2 Windows installer? Message-ID: <1xhtg1xm.fsf@pobox.com> The subject line says it, really: I installed 2.4a2 using the MSI installer on python.org, and I appear to be missing this file: C:\Python24\DLLs\_sre.pyd As a result, Python picks up the _sre.pyd from my 2.3 installation, and I get the expected error about a bad magic number in that DLL. I think I must be doing something stupid, but what, exactly? TIA for any help John From martin at v.loewis.de Sun Aug 22 16:53:28 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 22 Aug 2004 22:53:28 +0200 Subject: Proposal: require 7-bit source str's In-Reply-To: References: Message-ID: <412907C8.1090104@v.loewis.de> Hallvard B Furuseth wrote: >>>For example, if one uses character set ns_4551-1 - ASCII with {|}[\] >>>replaced with ??????, sorting by simple byte ordering will sort text >>>correctly. Unicode text _can't_ be sorted correctly, because of >>>characters like '?': Swedish '?' should match Norwegian '?' and sort >>>with that, while German '?' should not match '?' and sorts with 'o'. >> >>Why not sort depending on the locale instead of ordinal values of the >>bytes/characters? > > > I'm in Norway. Both Swedes and Germans are foreigners. I agree with many things you said, but this example is bogus. If I (as a German) use ns_4551-1, sorting is simple - and incorrect, because, as you say, ? sorts with o in my language - yet the simple sorting of ns_4551-1 doesn't. So sorting is *not* simple with ns_4551-1. Likewise, sorting *is* possible with Unicode if you take the locale into account. The order of character doesn't have to be the numerical one, and, as you explain, it might even depend on the locale. So if you want a Swedish collaction, use a Swedish locale; if you want a German collation, use a German locale. Regards, Martin From Symantec_AntiVirus_for_SMTP_Gateways at umagroup.com Wed Aug 11 14:56:25 2004 From: Symantec_AntiVirus_for_SMTP_Gateways at umagroup.com (Symantec_AntiVirus_for_SMTP_Gateways at umagroup.com) Date: Wed, 11 Aug 2004 12:56:25 -0600 Subject: Content violation Message-ID: <20040811185605.795C81E4003@bag.python.org> Content violation found in email message. From: python-list at python.org To: pbirdsell at umagroup.com File(s): message.scr Matching filename: *.scr* From michael.gregorius at indunorm.de Fri Aug 6 02:51:52 2004 From: michael.gregorius at indunorm.de (michael.gregorius at indunorm.de) Date: Fri, 6 Aug 2004 08:51:52 +0200 Subject: (no subject) Message-ID: <20040806065159.A59822DC0F1@pbzis4.it.phoenix.wuerth.com> ------------------ Virus Warning Message (on pbzc1n2.it.phoenix.wuerth.com) Found virus WORM_MYDOOM.M in file instruction.pif The uncleanable file instruction.pif is moved to /etc/iscan/virus/virVZK9X1. --------------------------------------------------------- -------------- next part -------------- The original message was included as attachment -------------- next part -------------- ------------------ Virus Warning Message (on pbzc1n2.it.phoenix.wuerth.com) instruction.pif is removed from here because it contains a virus. --------------------------------------------------------- From urbushey at sas.upenn.edu Tue Aug 10 16:56:59 2004 From: urbushey at sas.upenn.edu (uri bushey) Date: Tue, 10 Aug 2004 14:56:59 -0600 Subject: Standalone Python Programs... In-Reply-To: References: Message-ID: So per everyone's advice, I decided to make a go of it with py2exe. Unfortunately I'm getting a traceback instead of an executable. It states: "WindowsError: [Errno 3] The system cannot find the path specified: 'C:\\PythonProgram\\dist\\library.zip\\Pmw/*.*' I did some searching and discovered that I have to use 'bundlepmw.' So I did this, and then I get an error about one of my libraries instead: _tkinter.TclError: Can't find package wsurf 1.7 So I added this to dist\tcl, and then I get an error about my next library, snack. Well, adding all of these libraries is eventually going to defeat the purpose of freezing the program, isn't it? Wsurf itself is 4 MB! Is there something else i should be doing? From mattjensen at timetospare.net Sun Aug 29 01:03:30 2004 From: mattjensen at timetospare.net (Matthew K Jensen) Date: 28 Aug 2004 22:03:30 -0700 Subject: Help req: py2exe's compiled executables only working with XP Message-ID: <173c23bb.0408282103.5eb4152@posting.google.com> I am a young programmer with his big break on the line. For some reason, small apps that I've written and compiled on an XP machine won't work on anything but XP machines. I can't find any clue as to what's going on. Is the problem py2exe or something in my own scripts? I am at the end of my rope and I'm hoping someone out there can give me a pointer of two. Respectfully with full recognition that a lot of you are smarter than me, Matt K Jensen From danb_83 at yahoo.com Wed Aug 25 14:58:53 2004 From: danb_83 at yahoo.com (Dan Bishop) Date: 25 Aug 2004 11:58:53 -0700 Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> Message-ID: Dave Opstad wrote in message news:... > > [discussion of why list.sort returns None instead of a list] > > But isn't the fact that the list is modified in place incidental to the > fact of sorting? One is an implementation detail, and the other is the > semantic meaning you're trying to express. The fact that the list is sorted in-place *is* semantically meaningful. It's often important to know whether the original list is sorted or not. From user at domain.invalid Wed Aug 11 05:07:28 2004 From: user at domain.invalid (Robbie) Date: Wed, 11 Aug 2004 19:07:28 +1000 Subject: loading message thingy Message-ID: Even though this is not very important it would be nice to get working. Basically all I want to do is continuously write to the same line. So I could have a little rotating text thing showing that the script is working or display data ie, kb downloaded so far... ATM I am just calling a clear screen every pass with a little nap, nasty. Something along these lines: for i in range(1000): print "Loading... %s" % file_size os.system("clear") sleep(0.5) I also tried something with \r but that never quite worked... Also it would be nice to be able to change more than one line so I could have 4 threads open downloading something with 4 lines each stating the current status of each thread... From m.tiesman1 at charter.net Mon Aug 2 13:32:45 2004 From: m.tiesman1 at charter.net (Mark) Date: Mon, 02 Aug 2004 12:32:45 -0500 Subject: New to Python/Programming Message-ID: <10gsujk1og2gkbf@corp.supernews.com> Hello. I am new to programming and Python and was wondering if someone could help get me started. I picked Python to start learning to prgram because of some things I have read about it (easy to learn, object oriented, clear syntax, etc...). Can anyone assist in getting me started with learning to program and Python? Recommended reading material? Online tutorials? Recommended development tools (wxpython, pythonwin, etc...)? I am a network admin by trade and have done little programming except for the occasional script or router config. this is something that has always interested me, but don't have the time to take any formal classes. Thanks for the help. From geoff at variosoft.com Mon Aug 9 16:29:50 2004 From: geoff at variosoft.com (Geoff Caplan) Date: Mon, 9 Aug 2004 21:29:50 +0100 Subject: VB-like GUI designer? In-Reply-To: References: Message-ID: <116131494969.20040809212950@variosoft.com> Hi Check out VisualWx. http://visualwx.altervista.org/ Offers all the wx widgets including sizers, and creates code for C++, Python, Perl, Lua and Ruby. I've been playing with for a couple of days, and so far it's looking surprisingly stable and nice to use. There's an animated tutorial here: http://www.trinity.unimelb.edu.au/~abulka/demos/visualwx01_launcher.html ------------------ Geoff Caplan Vario Software Ltd (+44) 121-515 1154 From martin at v.loewis.de Fri Aug 6 15:46:01 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 06 Aug 2004 21:46:01 +0200 Subject: unicode to ascii converting In-Reply-To: References: Message-ID: <4113DFF9.3090104@v.loewis.de> Peter Wilkinson wrote: > UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: > ordinal not in range(128) That error actually says what happened: You have the byte with the numeric value 0xff in the input, and the ASCII (American Standard Code for Information Interchange) converter cannot convert that into a Unicode character. This is because ASCII is a 7-bit character set, i.e. it goes from 0..127. 0xFF is 255, so it is out of range. Now, the line triggering this is bz_file_out.write(line.encode(new_encode)) and it invokes *encode*, not *decode*. Why would it give a decode error then? Because: decode: take a byte string, return a Unicode string encode: take a Unicode string, take a byte string So line should be a Unicode string, for .encode to be a meaningful thing to do. Unfortunately, Python supports .encode also for byte strings. If new_encode defines a character encoding, this does class str: def encode(self, encoding): unistr = unicode(self) return unistr.encode(encoding) So it first tries to convert the current string into unicode, which uses the system default encoding, which is us-ascii. Hence the error. HTH, Martin From amk at amk.ca Sat Aug 7 22:15:50 2004 From: amk at amk.ca (A.M. Kuchling) Date: Sat, 07 Aug 2004 21:15:50 -0500 Subject: decorators vs GIL References: Message-ID: <8YudnZoJ4NdLEYjcRVn-jA@speakeasy.net> On Sat, 7 Aug 2004 20:18:00 -0400 (EDT), mudd at vex.net wrote: > But isn't the GIL on the way out already? Jython offers access to the > non-GIL threads of the JVM. I always use Java threads when working with > Jython. Perhaps. That depends on Jython continuing to be developed; if that's of importance to you, you can help with Jython development or send money to Samuele Pedroni or assist in other ways. My basic point is that the features added to projects are those that people are willing to actually work on. In the case of decorators, some people wanted decorators, for the sake of PyObjC or ctypes or whatever, and Mark Russell actually sat down and implemented it. (Because he uses PyObjC? Because he thought it would be an entertaining task? Whatever the reason, it did get done.) Decorators weren't added because of some theoretical goal; they were added because some people wanted them, and because some people cared enough to implement them. The only way the GIL or performance will be changed is if someone cares enough to work on them; so far, apparently no one does. --amk From greg at cosc.canterbury.ac.nz Wed Aug 25 23:28:44 2004 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Thu, 26 Aug 2004 15:28:44 +1200 Subject: "Socket" files? In-Reply-To: <2p0ss7Ffh1bdU2@uni-berlin.de> References: <1093035812.83612@jubilee.esoterica.pt> <4126824a$0$566$e4fe514c@news.xs4all.nl> <1093050493.502706@jubilee.esoterica.pt> <1093302968.204485@iceman.esoterica.pt> <2p0ss7Ffh1bdU2@uni-berlin.de> Message-ID: <2p53nfFgjm18U1@uni-berlin.de> Oliver Fromme wrote: > > Uhm, are you sure you know what you're doing? UNIX domain > sockets work very similar to Internet domain sockets, i.e. > they disappear when they're closed (or when your program > exits, in which case everything is closed implicitly). Indeed. Last time I played with Unix-domain sockets (which was quite some time ago, things may have changed since) the entry in the file system seemed to be completely useless -- you couldn't do anything with it that you might expect, e.g. open() it. The docs described the fact that a file system entry existed as a "side effect" that might go away in future versions. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From roy at panix.com Fri Aug 27 11:33:39 2004 From: roy at panix.com (Roy Smith) Date: Fri, 27 Aug 2004 11:33:39 -0400 Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> <1gj4fb5.607xsc51izh8N%aleaxit@yahoo.com> <7xllg25lkt.fsf@ruckus.brouhaha.com> <1gj4u3a.12ttba9fynd6uN%aleaxit@yahoo.com> <1gj5bp4.qhup8tldmvebN%aleaxit@yahoo.com> <7xk6vlgemp.fsf@ruckus.brouhaha.com> Message-ID: Antoon Pardon wrote: > In this case I think the practicality of method chaining beats > the purity of not allowing side-effects in print statements and > of having only one obvious way to do things. Especially since the whole decorator thing is essentially about method chaining. From jsaker at americanrelay.com Fri Aug 6 13:03:56 2004 From: jsaker at americanrelay.com (James R. Saker Jr.) Date: Fri, 06 Aug 2004 12:03:56 -0500 Subject: Queue qsize = unreliable? Message-ID: <1091811836.15192.46.camel@localhost> Peter writes: >The third point seems to just say that you need a Queue and you >need to have that thread sit in a blocking get(). What am I >missing? You're right; that'd probably work (I'm probably being a bit to paranoid on the blocking issue). Any thoughts on ZODB Queues? Tom... Pyro definitely looks interesting - thx for the link. Jamie From david at NOSPAMclocksoft.com Tue Aug 31 09:38:49 2004 From: david at NOSPAMclocksoft.com (David Chan) Date: Tue, 31 Aug 2004 14:38:49 +0100 Subject: GUI Wizard: flow control? Message-ID: <20040831133848.GA31733@mainwaring.clocksoft.dom> Hi, I'm trying to use python to create GUI wizards, i.e. sequences of dialog boxes with buttons. Since I want to re-use some of the dialog boxes in different wizards, I want to have a main function which calls each dialog box, much like this: def select_item(): """runs GUI wizard to select item""" client = show_client_dialog() job = show_job_dialog(client) invoice, rate = show_invoice_dialog(job) item = choose_item_dialog(invoice, rate) return item This works fine until you want to implement the References: <40F69228.4060901@anonym.hu> Message-ID: <4124F249.2080401@libertydistribution.com> fowlertrainer at anonym.hu wrote: > Hi ! > > I think that I have been found a bug in mx.DateTime... > So: > I use FireBird, and in this RDBMS the datetime fields are "doubles". > So if I set them to 0, the values the fields are '1899-12-30 01:00:00'. > > When I try to see this datetime as European format (YYYY.MM.DD HH:MM:SS) > I get error. > > Example1: > s='1899-12-30 01:00:00' > nv=str(s) > nv=DateTime(s) > s=nv.strftime('%Y.%m.%d. %H:%M:%S') > # it is makes error > Well I'm no expert on the mx.Datetime module, but lets so if I can help. In your example #1 I tried doing it in the interpretor exactly as you did and ran into some problems. First, you set 's' equal to a string of the date your wanting I presume. Then your calling the builtin str method on it. Why when it's already a string? Then your calling the DateTime method however it needs to be qualified through the mx.DateTime module i.e. import mx.DateTime mx.DateTime.DateTime(s) However your passing in s to this method as a string. In the mx.DateTime docs it says and I quote, "|DateTime(year,month=1,day=1,hour=0,minute=0,second=0.0)| Constructs a DateTime instance from the given values. So you need to be passing in integer values except for the seconds argument which can be a float. If you call the method in the correct way it will return a datetime object of the date you want then you can use strftime to format it in the european fasion yu desire. One final note all datetime objects are created with a 24 hour time, not 12. So 5pm will be 17:00 after you string format the object, if my memory is correct. Just remember that for if/when you take those times back out of the database to display to a user you'll need to change them to a 12 hour time, unless they don't mind reading it like that. We use PostgreSQL for our databases and whenever a time object is put into the database it is automatically converted to ticks. I'm not sure if it's the same way with yours or not. So when pulling a time back out it would be converted like: time = mx.DateTime.localtime(item_object_fromDB).strftime("%m/%d/%Y etc....") There is also another method called strptime which parses a time string according to a particular format but I haven't used it enough to instruct you on it's us, but it could be helpful. Hopefully something I said will help, be sure to look at the docs @: http://www.egenix.com/files/python/mxDateTime.html#DateTime and http://docs.python.org/lib/module-time.html Good Luck, Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter at engcorp.com Wed Aug 11 13:53:56 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 11 Aug 2004 13:53:56 -0400 Subject: 'break' Causes Execution of Procedure? In-Reply-To: References: Message-ID: Scott Brady Drummonds wrote: > I should also point out that the second time that the program's execution > reaches the 'break' statement in the 'main' procedure, I get the following > cryptic error message: > > > DEBUG: advancing both simulators to 20178 > DEBUG: encountered EOFError; breaking loop > XXX lineno: 109, opcode: 0 > Traceback (most recent call last): > File "test.py", line 135, in ? > main(sys.argv[1]) > File "test.py", line 109, in main > break > SystemError: unknown opcode > > > What's going on here? Scrambled .pyc file? Try deleting all .pyc files in the folder and rerun. (Just a thought.) From dave at inthegarage.net Sat Aug 21 22:39:51 2004 From: dave at inthegarage.net (aToaster) Date: 21 Aug 2004 19:39:51 -0700 Subject: Help with Calculater (first program) Message-ID: <8ff6f02e.0408211839.4057ff5@posting.google.com> Hey guys, I'm just getting the hang of Python and Tkinter and I could use some help. I wrote most of the gui for my calculator program, well I haven't gotten around to putting in the plus/minus/divide/mulitply yet but I'll save that for later. Right now I want the buttons to display the number in the entry field. How can I pass the values into the entry field as they are being clicked? Oh and here's my biggest question. Right now I have it set so that if you press 3 and 4 it gives you 7, but what I want it to do is if you press 3 and then 4 it gives you 34. How would I be able to do that? I appreciate the help! Thanks. ,David Peredo #------------------ CalcApp.py --------------------------- from Tkinter import * class CalcApp: def __init__(self, parent): self.myParent = parent self.myContainer1 = Frame(parent) self.myContainer1.pack(side=TOP) self.myContainer2 = Frame(parent) self.myContainer2.pack() self.myContainer3 = Frame(parent) self.myContainer3.pack() self.myContainer4 = Frame(parent) self.myContainer4.pack() self.myContainer5 = Frame(parent) self.myContainer5.pack() self.myContainer6 = Frame(parent) self.myContainer6.pack(side=BOTTOM) #calcTotal self.calcTotal = 0 # Button 7 button_name = "7" self.button3 = Button(self.myContainer1, command = lambda arg1=7, arg2=button_name : self.buttonHandler(arg1, arg2) ) self.button3.configure(text=button_name) self.button3.pack(side=LEFT) # Button 8 button_name = "8" self.button3 = Button(self.myContainer1, command = lambda arg1=8, arg2=button_name : self.buttonHandler(arg1, arg2) ) self.button3.configure(text=button_name) self.button3.pack(side=LEFT) # Button 9 button_name = "9" self.button3 = Button(self.myContainer1, command = lambda arg1=9, arg2=button_name : self.buttonHandler(arg1, arg2) ) self.button3.configure(text=button_name) self.button3.pack(side=LEFT) # Button 4 button_name = "4" self.button3 = Button(self.myContainer2, command = lambda arg1=4, arg2=button_name : self.buttonHandler(arg1, arg2) ) self.button3.configure(text=button_name) self.button3.pack(side=LEFT) # Button 5 button_name = "5" self.button3 = Button(self.myContainer2, command = lambda arg1=5, arg2=button_name : self.buttonHandler(arg1, arg2) ) self.button3.configure(text=button_name) self.button3.pack(side=LEFT) # Button 6 button_name = "6" self.button3 = Button(self.myContainer2, command = lambda arg1=6, arg2=button_name : self.buttonHandler(arg1, arg2) ) self.button3.configure(text=button_name) self.button3.pack(side=LEFT) # Button 1 button_name = "1" self.button1 = Button(self.myContainer3, command = lambda arg1=1, arg2=button_name : self.buttonHandler(arg1, arg2) ) self.button1.configure(text=button_name) self.button1.pack(side=LEFT) # Button 2 button_name = "2" self.button2 = Button(self.myContainer3, command = lambda arg1=2, arg2=button_name : self.buttonHandler(arg1, arg2) ) self.button2.configure(text=button_name) self.button2.pack(side=LEFT) # Button 3 button_name = "3" self.button3 = Button(self.myContainer3, command = lambda arg1=3, arg2=button_name : self.buttonHandler(arg1, arg2) ) self.button3.configure(text=button_name) self.button3.pack(side=LEFT) # Button 0 button_name = "0" self.button3 = Button(self.myContainer4, command = lambda arg1=0, arg2=button_name : self.buttonHandler(arg1, arg2) ) self.button3.configure(text=button_name, width=3) self.button3.pack(side=LEFT) # Button . button_name = "." self.buttondot = Button(self.myContainer4) self.buttondot.configure(text=button_name, width=1) self.buttondot.pack(side=RIGHT) # Button Clear button_name = "Clear" self.buttonClear = Button(self.myContainer6, command = self.buttonClearClick) self.buttonClear.configure(text=button_name) self.buttonClear.pack(side=BOTTOM) # Entry self.entryBox = Entry(self.myContainer5) self.entryBox.pack() def buttonHandler(self, argument1, argument2): print "You have clicked :", argument2 self.calcTotal = self.calcTotal + argument1 print self.calcTotal self.entryBox.configure(text=self.calcTotal) def buttonHandler_a(self, argument1, argument2): print "You have clicked :", argument2 self.calcTotal = self.calcTotal +argument1 print self.calcTotal def buttonClearClick(self): print "You have cleared the total." self.calcTotal = 0 print "\n"*100 print "Starting program Calc." root = Tk() myapp = CalcApp(root) print "Starting even loop." root.mainloop() print "Finished executing event loop." #End of Program #------------------ CalcApp.py --------------------------- From koko9991 at compuserve.de Thu Aug 19 09:48:15 2004 From: koko9991 at compuserve.de (Konrad Koller) Date: Thu, 19 Aug 2004 13:48:15 GMT Subject: SciTE as editor for Python: No print formatting under LINUX. Message-ID: <4124ad63.349803125@news.compuserve.de> Under Windows print formatting (header, footer etc.) is OK. Under LINUX it does not work. SciTEGlobal.properties state around line 352: # Printing - only works on Windows Why? How is print formatting determined under LINUX (PLAT_GTK)? From guettli at thomas-guettler.de Wed Aug 18 10:33:15 2004 From: guettli at thomas-guettler.de (Thomas Guettler) Date: Wed, 18 Aug 2004 16:33:15 +0200 Subject: favorite python web development tool? References: <10i4nttktcvltdd@corp.supernews.com> Message-ID: Am Tue, 17 Aug 2004 15:43:22 -0400 schrieb mike: > hi all - > > > i'm fairly new to python, coming from a java servlet / velocity template > background. i'm looking for a good python web development tool, and > hope to find some suggestions here. > > given my background, webware+cheetah feels comfortingly familiar, and > i'm leaning toward it. before i dive in, though, i'm wondering what you > experienced users think about it, compared to the other tools that are > out there. eg, does the python environment have strengths that are > better exploited with something other than a servlet-like model? Hi, I use quixote (without PTL and Form library) and ZODB. Many don't like it, but I do: def foo(self, request): ret=[] ret.append(self.header()) ret.append('Hello World!') ret.append(self.footer()) return ''.join(ret) 100% Python with the filter_output hook, every page is checked with html-tidy during development. Uncaught exceptions on the production site get to me by email as soon as they occur. A nightly unittest checks for errors. HTH, Thomas From wweston at att.net Mon Aug 2 11:45:14 2004 From: wweston at att.net (wes weston) Date: Mon, 02 Aug 2004 15:45:14 GMT Subject: Trimming a string In-Reply-To: <10gsmuieo65du5d@news.supernews.com> References: <10gsmuieo65du5d@news.supernews.com> Message-ID: Double Dumbass on You wrote: > I have a string that is 7 characters and represents file mode in UNIX/LINUX > from rpm: > > 0100755 > > I don't care about the 0100 portion, I am only interested in the file > permissions portion which is 755. How can I get three characters from the > string starting at the right? ( -OR- strip 4 characters from the left? ) > > DD, >>> x = "0100755" >>> print x[4:] 755 Reading the tutorial is really time well spent. wes From timh at zute.net Thu Aug 26 11:05:47 2004 From: timh at zute.net (Tim Hoffman) Date: Thu, 26 Aug 2004 23:05:47 +0800 Subject: Web Application - User Management - RBAC In-Reply-To: References: Message-ID: <412dfc53@news.highway1.com.au> Hi Martin IYou probably know this already but the obvious response is to use Zope :-) Tim Martin wrote: > I am putting together a simple web-app for construction of standard documents. > Basically the app will present a form for inputting the variable content / > overriding standard text and send back a complete .doc / .swx. The motivation > for using a web app instead of templates is that I have found templates too > brittle, and I would like to store the variable/overriding data in an SQL > backend. > > I would like to implement RBAC(Role Based Access Control) in the app. How would > one best go about that ? is there any code available(classes/frameworks) ? would > one render pages and thereby options based on role or guard methods(i.e. call > some kind of access control object and raise exceptions if an action is not > allowed for the role, or perhaps derive all objects from an object that > automatically handles such checks when a method is called ?) or some other > approach ? I have looked at Webwares UserKit but it is apparently incomplete and > frankly I can't figure out how it works. > > I am planning to use CherryPy as a framework, but would be open to another > approach. > > Regards, > > Martin > From cemerick at snowtide.com Sun Aug 15 09:34:30 2004 From: cemerick at snowtide.com (Chas Emerick) Date: Sun, 15 Aug 2004 09:34:30 -0400 Subject: Decorators: an outsider's perspective In-Reply-To: <20040814153534.8AC171E4007@bag.python.org> References: <20040814153534.8AC171E4007@bag.python.org> Message-ID: On August 14, 2004 9:35:48 AM EDT, Paul Morrow wrote: > def blah(a, b): # this is clearly a static method > pass > > def blah(self, a, b): # this is clearly an instance method > pass Ouch. Sorry, the arguments going into a function shouldn't have **anything** to do with the nature of that function. Overloading their existence, lack thereof, or their names as a way of describing the function they are hung off of seems like a horrible way to go. (Not to mention the fact that, at least conceptually, it is also violating that action-at-a-distance guideline...) On Aug 14, 2004, at 11:35 AM, Paul Morrow wrote: > Yes, sorry, but I'm in a pickle here. I want (we need) the general > idea of decorators --- the realm of problems that decorators try to > solve --- to be made smaller. They should not be used to declare a > method's type (static|instance|class). Decorators may have some valid > purpose, but this is not one of them. I would almost agree with you anywhere else. However, since GvM has explicitly overruled the idea of something like: def static blah (args): pass we're left to find other routes by which to specify method types. Decorators neatly provide a generalized way to modify functions, so that's where static|instance|class modifications land. I agree that that's slightly unfortunate at the moment, but it's probably necessitated by the history of using the horrible foo=staticmethod(foo) idiom. I say 'at the moment', because I can imagine quite a few decorators that definitely touch on the notion of a function's type. Consider: @remote([remoteFuncName], [accessRestrictions], ...) def static blah (args): pass That might make blah available over xmlrpc, for example, though some route predefined in whatever xmlrpc library one happens to be using. Again, I'm no expert in python, so perhaps there's already similarly easy ways to configure such things with the libraries that already exist, but I think I got my point out there. On , Hans Nowak wrote: > This post wasn't deriding decorators; rather, it explains them, and > provides some examples of how to use them. I do question their > usefulness, but I'm not deriding them, nor the "@" syntax. Sorry if I mischaracterized your intent...I meant no harm. :-) - Chas Emerick From fakeaddress at nowhere.org Mon Aug 9 03:03:08 2004 From: fakeaddress at nowhere.org (Bryan Olson) Date: Mon, 09 Aug 2004 07:03:08 GMT Subject: ThreadingTCPServer, asyncore and Client-to-Client communication In-Reply-To: <81efeef2.0408072015.60addf38@posting.google.com> References: <81efeef2.0408072015.60addf38@posting.google.com> Message-ID: Dustin wrote: [...] > If Client #1 connects, then that thread is consumed with listening for > data from that client. If Client #2 connects, that client is on a > different thread, and therefore I don't see how I can have data sent > from Client #1 to be streamed down to Client #2. [...] > I've looked at asyncore/asynchat, as well as ThreadingTCPServer... but > there's something I'm missing. Is there a simple way to have an > object listen over two ports, and what comes into one port will be > sent down the another? Yes; look up the select module in the standard library (on which asyncore is built). Also, note that sockets are not bound to a single thread. If you don't want to use select, you might have one thread that reads from socket x and writes to socket y, and another thread that reads from y and write to x. Some perfectly reasonable systems have a reading thread and a writing thread for each socket. -- --Bryan From steven.bethard at gmail.com Mon Aug 23 14:13:07 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Mon, 23 Aug 2004 18:13:07 +0000 (UTC) Subject: Standard graph API? References: Message-ID: Magnus Lie Hetland furu.idi.ntnu.no> writes: > Is there any interest in a (hypothetical) standard graph API (with > 'graph' meaning a network, consisting of nodes and edges)? I don't need one right now, but I know I have a few times in the past. Certainly seems like a good idea to me. We've got sets as builtins now, no reason we shouldn't have a simple graph API, at least in the library. Steve From newsgroups at jhrothjr.com Thu Aug 5 17:01:42 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Thu, 5 Aug 2004 17:01:42 -0400 Subject: Decorator syntax References: <788E231C269961418F38D3E360D1652526CA1A@tndefr-ws00021.tenovis.corp.lan> Message-ID: <10h581thifinoa6@news.supernews.com> "Christopher T King" wrote in message news:Pine.LNX.4.44.0408051601580.14462-100000 at ccc6.wpi.edu... > On Thu, 5 Aug 2004, Istvan Albert wrote: > > > The disagreement is caused by trying to achieve a lot of different > > things with one feature. > > > > Thus the solution that is emerging is to cram everything in > > front of the function definition. > > Agreed! Exactly! Most of what people seem to want from decorators are > a way to specify function types, do type checking, and give functions > attributes / metadata. As I've said before, these are seperable problems > and should be treated as such. What little left over that can > benefit from general-purpose decoraters will likely not be enough to form > a major use case. To walk back into the fray; I've got three programs that I checked whether I could use decorators. The two that needed metadata I couldn't; the other one (which is in the vague "sometime-maybe" category) I certainly can, but it would be a gross misuse of the facility. The thing about metadata is very simple. After managing to get to the bottom of the domain model, I find that I need to associate metadata with specific identifiers in certain classes. Note that this is with the identifiers, NOT with the objects that are bound to the identifiers. The metadata applies regardless of what object is bound to the identifier, and regardless of whether it is bound in the class or instance. (Of course, if there is an object bound to the identifier, it needs to conform to what the metadata says, but that's a different issue.) In the second program, I find a need to supply metadata that is related to the class, and not to any particular identifier or object in that class. (Of course, I also need to supply metadata for certain identifiers.) In the third program, I need a convenient way of putting function definitions into instances; the decorator facility can do this as a side effect. That's what I meant by a gross misuse of the facility, though. John Roth > From steven.bethard at gmail.com Wed Aug 11 18:33:01 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: 11 Aug 2004 15:33:01 -0700 Subject: A decorator syntax not yet mentioned (I think!) References: Message-ID: Michael Sparks wrote in message news:... > The only downside I can see is that it might not be 100% obvious that it > relates to the following function to newcomers to python. This is a downside, but as far as I can tell, it's a downside of all proposals that place the decorator declaration before the function. Since it looks like we're stuck with pre-def decorators, I wouldn't really worry about this issue too much. > In a syntax highlighted editor that also looks *alot* cleaner than > beforehand. IMO, it also looks slightly cleaner than the @version - for > one very, very simple reason - if you have a very big decorator block, > for whatever reason, the "def" stands out clearly so you can skim where > the function starts - even without syntax highlighting. This is a great point. I definitely agree -- it's much easier to find the def than even the @ solution. Compare: @grammarrule('statement : expression') @versioninfo("Added in 2.4") @deprecated @typeinfo(None) def p_statement_expr(self, p): print p[1] vs. decorate: grammarrule('statement : expression') versioninfo("Added in 2.4") deprecated typeinfo(None) def p_statement_expr(self, p): print p[1] Of course, you could allow the same thing with '@': @: grammarrule('statement : expression') versioninfo("Added in 2.4") deprecated typeinfo(None) def p_statement_expr(self, p): print p[1] But this looks really cryptic -- unlike 'decorate', '@' doesn't really read as anything. You probably know that the '@' "applies" to all the lines below it, but unless you already know what '@' means, you probably have no idea how it "applies". The keyword version seems much clearer on this point. I know there were complaints before about this sort of indentation, but I couldn't find them in python-dev and the comments in the wiki don't discuss this in any detail. Can anyone tell me why this indentation syntax was dispreferred? Specifically, I'm interested in why this is so drastically different from the other paired blocks: if/elif/else, try/except, try/finally, etc. Also, there's a comment in the wiki that says that there are technical problems with the grammar if a block *starts* with an optional part. Does this not apply to the @ case (which also starts a block with an optional part)? Thanks, Steve From b.niemann at betternet.de Tue Aug 31 05:18:18 2004 From: b.niemann at betternet.de (Benjamin Niemann) Date: Tue, 31 Aug 2004 11:18:18 +0200 Subject: From python to LaTeX in emacs on windows In-Reply-To: References: Message-ID: Brian Elmegaard wrote: > Benjamin Niemann writes: > > Thank for the help. I solved the problem by specifying the cp1252 > encoding for the python file by a magic comment and for the input data file. > > >>When you read the filecontents in python, you'll have the "raw" byte >>sequence, in this case it is the UTF-8 encoding of unicode text. But >>you probably want a unicode string. Use "text = unicode(data, >>'utf-8')" where "data" is the filecontent you read. After processing >>you probably want to write it back to a file. Before you do this, you >>will have to convert the unicode string back to a byte sequence. Use >>"data = text.encode('utf')". >> > > > This worked, but when I try to print text I get: > UnicodeEncodeError: 'ascii' codec can't encode characters in position 9-10: ordinal not in range(128) > Why is that? The console only understands "byte streams". To print a unicode string, python tries to encode it using the default encoding, which is 'ascii' in your case. That encoding is not able to represent characters like '?', '?'.. which causes the exception. What I usually do is something like: print text.encode("cp1251", "ignore") The 'ignore' argument causes all characters, that cannot be represented in cp1251 to be silently dropped - which is ok, if the output is only used e.g. to track progress. Don't know if there's a way to python to do this automagically for all unicodes passed to stdout... > > >>Handling character encodings correctly *is* difficult. > > > What makes it difficult? The OS, the editor, python, latex? At least for me it is difficult, because I'm used to think "1 byte = 1 character" and when I read/write files I could simple handle the data as strings. Unless you begin to parse arbitrary data from the internet, there is little chance that you encounter text encodings different from your operating systems default and you start to believe that e.g. "ord('?') == 252" is a universal rule sent by the gods... If you do it right, then you should convert all data that 'enters' your application as early as possible to unicode and encode it back when you print/save/send it - this way you'll only have to deal with unicodes in your application code. The most difficult part is probably changing old habbits ;) From squirrel at WPI.EDU Tue Aug 10 15:34:13 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 10 Aug 2004 15:34:13 -0400 Subject: Prothon is switching to the .NET platform In-Reply-To: <10h7rittck6ct75@news.supernews.com> References: <000401c47b59$32539220$0d01a8c0@MarkVaio> <10h7lb21dhbuc12@news.supernews.com> <10h7rittck6ct75@news.supernews.com> Message-ID: On Fri, 6 Aug 2004, John Roth wrote: > The place where this gets really ugly is inserting functions > into the instances. They have to be created at the module > level, and then inserted into the instance by a module level > function (somewhat similar to the way classmethod, > staticmethod and property work). Oh, I wouldn't even attempt that until Python supported "def object.method():" syntax (like Prothon does). Using my derive class, you could acheieve a similar effect though: class my_derived_class(derive): def some_new_function(self): my_derived_object = my_derived_class(my_prototype_object) You aren't able to insert function definitions after the derived object is created using this method (something I imag, but most function definitions are premeditated anyways. From tim.hochberg at ieee.org Tue Aug 10 13:12:28 2004 From: tim.hochberg at ieee.org (Tim Hochberg) Date: Tue, 10 Aug 2004 10:12:28 -0700 Subject: pro python paper In-Reply-To: <3064b51d.0408100549.213dad5@posting.google.com> References: <305aa162.0408091905.5bce8f9a@posting.google.com> <3064b51d.0408100549.213dad5@posting.google.com> Message-ID: beliavsky at aol.com wrote: [SNIP] > > It is more honest and credible to admit that a Python program often is > slower than one in a compiled language, but that reduced programming > time in Python often outweighs this deficit. That's not been my experience. Most of the stuff that I write in Python would have been slower had I written it in C/Fortran etc. Now before you pack me off to the loony bin, let me explain. First off I know most of the tricks to make Python do things fast, at least in the problem domains I care about. Second, in most cases, I'm dealing with situations where, the problem is understood (if I'm lucky) but the optimal algorithm for solving it is not known. Finally, I don't generally have unlimited time to devote to any given problem. With these conditions (unkown algorithm, finite time), Python often comes out ahead of "faster" languages. The reduced programming time means that I typically end up with a closer to optimal algorithm and a faster algorithm is generally more important for speed than a faster language. Of course these conditions don't always apply. And to certain extent I'm guessing as to what kind of code I would have ended up with had I attemped a given program in C/Fortran, but I think I have a pretty good feel for what it would have turned out like. As for the paper the parent post referring to, I haven't read it and have no opinion on its claims. -tim From anthonybaxter at gmail.com Thu Aug 5 13:12:08 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 03:12:08 +1000 Subject: Confused about pep 318 In-Reply-To: References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: > > http://mail.python.org/pipermail/python-dev/2004-June/thread.html#45516 > > was over a month earlier. > > That thread reaches no consensus, other than, in his sole post in the > thread, Guido stating "I would love to see an implementation of this > idea." Nothing about "this is going to be in 2.4a2, anybody vehemently > opposed to it?" Like I said, the go-ahead was given privately. None of the decorator discussions _ever_ reached a conclusion. As mwh put it, "bike-shed-the-ultimate". At the end of the day, Guido's the one who makes these decisions. His decision was that the @ syntax should go into 2.4a2. As far as "private go-ahead", I've lost count of the number of people who seem to think that this is somehow an issue. Would the bitching have been seriously that much better if, half an hour before I committed the patch, Guido had posted a note saying pretty much what I forwarded on from him? If so, why? Guido followed up to my note pretty much straight away confirming it. Or would it have someone been better if Guido had done the CVS commit? Yes, it would have been nice if PEP-0318 was updated in advance of this. I made an effort, but have run out of resources to work on it. If no-one else gets to it before me, I will work on it again next week. But, suprise, Python's a volunteer effort. No-one's paying me to do this, or Guido, or anyone else. If someone wants to offer to pay me, or someone else, to actually do all this, *great*. From BruceEckel at MailBlocks.com Thu Aug 5 12:55:19 2004 From: BruceEckel at MailBlocks.com (Bruce Eckel) Date: Thu, 5 Aug 2004 10:55:19 -0600 Subject: Quixote vs. Preppy References: <1779534897.20040805105519@MailBlocks.com> Message-ID: I'm looking for something "closer to Python" to develop certain types of web systems (rather than going away, forgetting, then coming back and struggling with the Z-shaped learning curve for anything more than trivial things in Zope). Based on the Quixote presentation at Pycon, that looks quite interesting ("web development as if you were a Python programmer"), but someone also suggested Preppy from Reportlabs: http://www.reportlab.org/preppy.html Can anyone compare/contrast these? Thanks. Bruce Eckel From http Sat Aug 21 20:18:57 2004 From: http (Paul Rubin) Date: 21 Aug 2004 17:18:57 -0700 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> Message-ID: <7xk6vsgh3i.fsf@ruckus.brouhaha.com> luismg at gmx.net (Neuruss) writes: > Will Python (and dynamic languages in general) be someday close to > compiled languages speed? They already are (Lisp, etc.) > What will be the future of Psyco, Pypy, Starkiller, Ironpython and all > the other projects currently on development? Hopefully they will speed up Python. From martin at v.loewis.de Sat Aug 7 10:18:03 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 07 Aug 2004 16:18:03 +0200 Subject: decorators and multimethods In-Reply-To: <4edc17eb.0408062340.71ab270f@posting.google.com> References: <4edc17eb.0408062340.71ab270f@posting.google.com> Message-ID: <4114E49B.6040806@v.loewis.de> Michele Simionato wrote: > foo = Generic_Function() > > @addmethod(object, object, object) > def foo(_, x, y, z): > return 'default' On a second note, I would probably prefer a different notation foo = Generic_Function() @foo.overload(object, object, object) def foo(_, x, y, z): return 'default' This, of course, requires changes to Generic_Function, but they could be as simple as def overload(self, *types): def decorator(f): self[types] = f return self return decorator Regards, Martin From Domoran at yahoo.de Fri Aug 13 07:49:09 2004 From: Domoran at yahoo.de (Mathias Mamsch) Date: Fri, 13 Aug 2004 13:49:09 +0200 Subject: Problems with PyGILState_Ensure () and PyGILState_Release () Message-ID: Hi all, i am writing a python extension in c++. In the extension a c++ thread calls back into python. I did it like this: ---- c++ code ---- PyGILState_STATE gstate; gstate = PyGILState_Ensure (); ... do some work ... // call the python callback (Func) result = PyEval_CallObject(Func, arglist); ... so some cleanup ... PyGILState_Release (gstate); return ----------------- the callback is executed properly, but the PyGILState_Release gives me the following error: "Fatal Python error: PyThreadState_Delete: tstate is still current" What can be wrong here? Any suggestions? In my understanding this error should not occur ... Is this a known bug maybe? I am using Python 2.4a1 under windows. Thanks in advance, Mathias Mamsch From eric_brunel at despammed.com Thu Aug 19 12:11:14 2004 From: eric_brunel at despammed.com (Eric Brunel) Date: Thu, 19 Aug 2004 18:11:14 +0200 Subject: Tkinter References: <8e16829.0408190703.1c6845d7@posting.google.com> Message-ID: Roland wrote: > Salut, > > > J'utilise LNUX RedHat 9.0 et je n'arrive pas ? utilser Tkinter > car ? chaque fois que j'essaye de faire executer un code dans lequel > j'ai import? le module Tkinter, j'obtient: > from tkinter import* > ImportError: No module named tkinter . > Je croyais que ce module ?tait int?gr? ? python. > AIDEZ-MOI > Merci Pour info, il existe un newsgroup fr.comp.lang.python en fran?ais et avec plein de gens sympathiques. N'h?site pas ? y poser tes questions: ici, c'est plutot un newsgroup anglophone et tu risques d'avoir moins de r?ponses interessantes. -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From foo at bar.net Sat Aug 28 23:59:08 2004 From: foo at bar.net (Mac) Date: Sat, 28 Aug 2004 20:59:08 -0700 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: On Wed, 25 Aug 2004 14:56:06 -0700, Xah Lee wrote: > Larry Wall and Cults > (Lazyness, Impatience and Hubris) > 200012 > > Dear readers, > [snip] > Surely you have heard of Adolf Hitler > and his atrocities of genocide? I must alert you, that a single person > couldn't commit such a crime. Wow, Godwin's law invoked on the first post of the thread. --Mac From me at privacy.net Wed Aug 25 18:51:27 2004 From: me at privacy.net (Richard Hanson) Date: Wed, 25 Aug 2004 15:51:27 -0700 Subject: MSI Installer Problem: can't install 2.4a2 on new install of Win2kSP2 References: <412d0156$1_1@newspeer2.tds.net> Message-ID: "drs" wrote: >"Richard Hanson" wrote in message >news:vnipi0ldsgchqqiti1q19qtd5d70ju17p0 at 4ax.com... > >> Am I overlooking something simple...? > >How about SP3, or even 4? That's a thought. But, as I alluded to in my somewhat lengthy post, 2.4a2 worked with this OEM Win2kSP2 *before* the installation "died" last Friday. I have an SP3 CD, so that's doable; I'm on a slightly flaky dialup, so DL'ing SP4 would be a bit... uh... uncomfortable. :-) Also, isn't there the general feeling that Win2kSP2 is about as good as Windows gets (got)? (Aside from the EULA issues; just on the technical merits?) Thanks for the idea, though -- much appreciated. I may well try SP3 if I remain at an impasse. PS to original post: Further testing shows that the Python command line (console) is broken, too. Some things sorta work (e.g., "import sys"); most don't (e.g., "import decimal"). Python-withdrawals-are-painfully y'rs, Richard -- email works if unmunged: sickolefartnewsguycom From heikowu at ceosg.de Wed Aug 11 02:52:57 2004 From: heikowu at ceosg.de (Heiko Wundram) Date: Wed, 11 Aug 2004 08:52:57 +0200 Subject: rsa implementation question In-Reply-To: <1092200894.4119a9beb1978@www-mail.usyd.edu.au> References: <1092200894.4119a9beb1978@www-mail.usyd.edu.au> Message-ID: <200408110852.57937.heikowu@ceosg.de> Am Mittwoch, 11. August 2004 07:08 schrieb Ajay: > just like to know how the RSA implementation in the pcrypto package works. > Does it operate in blocks, if yes, what is the size of the blocks? RSA (Rivest-Shamir-Adleman encryption) never works in "blocks", as there is no notion of blocks in public key cryptography, there's only the notion of doing an operation on plaintext modulo a large prime n. Now, you could call (log2 n)/8 the block size in bytes of RSA for a certain encryption prime, but I'd never talk of block sizes with RSA, as normally you don't use RSA (or public-key cryptography in general) to encrypt plaintext a block at a time, but rather to encrypt a random string of bytes [len(s) <= (log2 n)/8 for the modulo prime of the algorithm], which is used as the key for a normal symmetric encryption algorithm, to which you feed the blocks. Thus, the receiver (and also the sender) only has to make one expensive calculation (retrieving the key from the encrypted RSA packet), whereas decrypting the cyphertext (or encrypting it) is done using a symmetric cypher, which has the advantage of being much faster to compute than a public-key cypher. Anyway, if you're interested in how symmetric and/or public-key cryptography work, read up on: http://www.cacr.math.uwaterloo.ca/hac/ especially chapters 7 and 8. Heiko. From gherron at islandtraining.com Fri Aug 20 12:42:01 2004 From: gherron at islandtraining.com (Gary Herron) Date: Fri, 20 Aug 2004 09:42:01 -0700 Subject: Alternative decorator syntax decision In-Reply-To: <200408200935.51189.gherron@islandtraining.com> References: <200408200935.51189.gherron@islandtraining.com> Message-ID: <200408200942.01215.gherron@islandtraining.com> On Friday 20 August 2004 09:35 am, Gary Herron wrote: > My vote: > J2 J2 and J2 > because it puts everything in the correct position (meaning in the > same position as the pie syntax), but still *LOOKS* like python. > > Keyword could remain "decorate", but I'd be fid just about anything > acceptable. Yuck -- I usually proof read better than that. Should be "I'd find just about anything acceptable" > Gary Herron From http Mon Aug 16 03:42:39 2004 From: http (Paul Rubin) Date: 16 Aug 2004 00:42:39 -0700 Subject: random / lists References: Message-ID: <7xr7q7edg0.fsf@ruckus.brouhaha.com> "M. Clift" writes: > What I want is a system that controls the direction in a generated list. If > the user selects a number a letter is choosen for each number from at random > from an array. That's fine and easy to do. The hard part is, is that no > letter can be repeated with only one letter interveining and the letters can > only follow each other under certain rules. Is this a homework assignment? From peter at engcorp.com Tue Aug 24 00:43:38 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 24 Aug 2004 00:43:38 -0400 Subject: On consensus decision-making (was Re: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WEDONE?) In-Reply-To: References: Message-ID: Anthony Baxter wrote: > On Mon, 23 Aug 2004 15:13:15 -0400, Peter Hansen wrote: > >>Anyway, I suppose this means that the selection will be from >>amongst A1, C1, and J2, each with an implementation, each with >>a sizable number of proponents. Wish the man well. ;-) > > As I've posted a couple of times, the C1 implementation is old, and is > not complete. There's a lot more work to be done on it to make sure > that it covers anything. I've still seen no-one put up their hand to > offer to finish it, which is a shame. Until very recently, there appeared to be a resounding "NO" from the BDFL himself to any thought that C1 might ever be accepted. It was rejected early and rather explicitly, if I recall correctly. Given that, it shouldn't be surprising in the least that no one has put up their hand to do something which would appear to be a waste of time. Has anything really changed? Would it now be correct to say that C1 has a serious chance of being accepted if someone would just update the implementation to the state and quality (?) of the other two? -Peter From benn at cenix-bioscience.com Thu Aug 12 05:56:49 2004 From: benn at cenix-bioscience.com (Neil Benn) Date: Thu, 12 Aug 2004 11:56:49 +0200 Subject: Pyhton Interpreter Startup time Message-ID: <411B3EE1.9080002@cenix-bioscience.com> Hello, I'm looking at a small app which would need a very quick startup time for the Python interpreter. It doesn't do much (copying and caching of files, no GUI) but I need the Python interpreter to start up very quickly (<1 second on a Windows box). Is there a way to have a 'stripped' down Python interpreter which can start up very quickly on a windows box. Once thing I was thinking of was to use PyExe to make a quick startup (does it compile down to C code, therefore not using the Python interpreter at runtime?). Is this a possible solution? I observe that the second time I start python it starts up quicker but I'm assuming that this is dependent on the environment and can't be relied upon (or something like that). Thanks, in advance for your help. Cheers, Neil -- Neil Benn Senior Automation Engineer Cenix BioScience BioInnovations Zentrum Tatzberg 47 D-01307 Dresden Germany Tel : +49 (0)351 4173 154 e-mail : benn at cenix-bioscience.com Cenix Website : http://www.cenix-bioscience.com From adurdin at gmail.com Tue Aug 17 07:46:51 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Tue, 17 Aug 2004 21:46:51 +1000 Subject: Best programming language In-Reply-To: References: <873c2ndizt.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Message-ID: <59e9fd3a040817044631d480af@mail.gmail.com> On Tue, 17 Aug 2004 13:35:26 +0200, lopex wrote: > 510046470588-0001 at t-online.de wrote: > > > > the best language is of course Scheme > > Another flamewar ? > should I claim Ruby is.. ? The obvious answer, of course, is that on the newsgroup/mailing list for language X, define "best programming language" to be X. It saves a lot of combustion :) From richardd at hmgcc.gov.uk Fri Aug 13 10:32:34 2004 From: richardd at hmgcc.gov.uk (Richard) Date: Fri, 13 Aug 2004 15:32:34 +0100 Subject: Difference between readlines() and iterating on a file object? Message-ID: <411cd102$1@mail.hmgcc.gov.uk> Hi, Can anyone tell me what the difference is between for line in file.readlines( ): and for line in file: where file is a file object returned from an open( ) call? I thought that they did the same thing, but the code I am using it in has this line called more than once on the same file object and the second time it is ran gives different results for each. What is the difference in implementation? Cheers Rich From sandysj at juno.com Thu Aug 5 12:57:08 2004 From: sandysj at juno.com (Jeff Sandys) Date: Thu, 5 Aug 2004 16:57:08 GMT Subject: I got it! How to force a single number to be a tuple References: Message-ID: <411266E4.80AD4D3C@juno.com> y=2, The comma makes tuples. y=2, 3.0, 4.5, also works. Are you sure that you want a list of numbers as an immutable tuple? Tuples are intended for hetrogenious sequences like a data record, (like y=2, 3.0, 4.5 is a record of say quantity, price and weight, and y=3.0, 2, 4.5 is a completely different thing). Tuples can be used as an index in a dictionary. A list is mutable, intended for a homogenious sequence, the elements can be changed and a list can not be used a dictionary index. (like y=[2, 3.0, 4.5] is a list of the weights of three items and y=[3.0, 2, 4.5] has the same meaning) Thanks, Jeff Sandys Jinming Xu wrote: > > Sorry for the previous message. It's really a simple question and I have > solved it myself. > > Thanks, > > Jinming > > ------------------------------------------------------------------------ > Hi Folks, > > I have a number sequence, which is put into a tuple like this: > > y=2, 3.0, 4.5 > > I can manipulate the sequence as a tuple when it has more than 1 number. But > when the sequence has only 1 number, like > > y=2 > > I have trouble to manipulate it as a tuple. I guess there must be a way to > forece a single number to be a tuple. Could anyone please tell me that? > > Thanks, > > Jinming From anthonybaxter at gmail.com Tue Aug 24 23:26:03 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Wed, 25 Aug 2004 13:26:03 +1000 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: Message-ID: I forgot one other point I meant to add - think about when the body of a class gets executed, vs when the body of a function gets executed. The former is at compile time, the latter is when the function is used. From martin at koekenberg.net Fri Aug 20 04:28:22 2004 From: martin at koekenberg.net (Martin Koekenberg) Date: Fri, 20 Aug 2004 10:28:22 +0200 Subject: TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' Message-ID: Hello, Ik get the following error when I install a new Python software package such as Zope or PIL. This is what I get whem I 'make' Zope : running build_ext Traceback (most recent call last): File "/usr/local/zope/Zope-2.7.2-0/setup.py", line 1091, in ? distclass=ZopeDistribution, File "/usr/local/lib/python2.3/distutils/core.py", line 149, in setup dist.run_commands() File "/usr/local/lib/python2.3/distutils/dist.py", line 907, in run_commands self.run_command(cmd) File "/usr/local/lib/python2.3/distutils/dist.py", line 927, in run_command cmd_obj.run() File "/usr/local/lib/python2.3/distutils/command/build.py", line 107, in run self.run_command(cmd_name) File "/usr/local/lib/python2.3/distutils/cmd.py", line 333, in run_command self.distribution.run_command(command) File "/usr/local/lib/python2.3/distutils/dist.py", line 927, in run_command cmd_obj.run() File "/usr/local/lib/python2.3/distutils/command/build_ext.py", line 244, in run customize_compiler(self.compiler) File "/usr/local/lib/python2.3/distutils/sysconfig.py", line 159, in customize_compiler cpp = cc + " -E" # not always TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' make: *** [build] Error 1 ./configure has finisched withoud problems. System : Fedora Core 2 Python 2.3.3 What is wrong here ? Greetings, Martin Koekenberg From jjl at pobox.com Sat Aug 14 16:16:27 2004 From: jjl at pobox.com (John J. Lee) Date: 14 Aug 2004 21:16:27 +0100 Subject: Decorator "platform" References: <2nsoofF49frcU1@uni-berlin.de> <87zn50nll4.fsf@pobox.com> Message-ID: <87hdr5mq5g.fsf@pobox.com> Doug Holton writes: > John J. Lee wrote: > > God help us. <0.5 wink> > > I'm seeing a pattern. You respond without reading. See > http://www.python.org/cgi-bin/moinmoin/PythonDecoratorLibrary OK, brevity is the soul of wit and all that, but I see I didn't succeed in communicating my point. I don't doubt the utility, on a case-by-case basis, of some of the uses of decorators that people are devising, and will continue to devise. I do fear that this is a pressure towards 'Babel-ization' of the language. I don't honestly know whether that fear is justified -- it's based mostly on listening to people on this newsgroup who have posted about their experiences with Lisp macros. John From ed-no at spam-eepatents.com Wed Aug 4 13:43:22 2004 From: ed-no at spam-eepatents.com (Ed Suominen) Date: Wed, 04 Aug 2004 10:43:22 -0700 Subject: web resources to explain why Python is best? References: <41111c24$0$26982$cc9e4d1f@news.dial.pipex.com> Message-ID: <9dqdnVTDTfC3vYzcRVn-iQ@centurytel.net> davout wrote: > Can anybody point me at some web resources that explain why Python is > better than Perl, TCL, Ruby etc? How about my very own posting "Goodbye TCL" on comp.lang.tcl and the 114 other articles in the thread it started? http://tinyurl.com/678yq From ahmado at gmail.com Mon Aug 30 15:01:52 2004 From: ahmado at gmail.com (Omer Ahmad) Date: 30 Aug 2004 12:01:52 -0700 Subject: xml.dom.minidom - documentElement vs. childNodes In-Reply-To: Message-ID: Hi there, This might not directly answer your question, but if you are doing simple XML documents, check out effbot.org (Frederic Lundt's home page). I use his elementtree class which is very very quick and easy. I was using minidom before but I foudn that it did everything I needed for simple dom documents. www.effbot.org I use the tool for writting logs.. much better than a text file. Good Luck, Omer From anthonybaxter at gmail.com Wed Aug 25 04:43:43 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Wed, 25 Aug 2004 18:43:43 +1000 Subject: Why return None? In-Reply-To: References: Message-ID: On Wed, 25 Aug 2004 08:26:26 GMT, Martin DeMello wrote: > It seems to be a fairly common pattern for an object-modifying method to > return None - however, this is often quite inconvenient. list.reverse() modifies the list in place. The python idiom is that these don't return a reference to the modified list. Although note the new list.sorted() method in 2.4... Anthony From deetsNOSPAM at web.de Sun Aug 29 16:51:21 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Sun, 29 Aug 2004 22:51:21 +0200 Subject: regex into str References: Message-ID: Hi, > Programming causes bugs. That's not a reason to disallow programming. Well, with that attitude I suggest you start coding in assembler - all freedom you can imagine, no rules. Every bit is subject to your personal interpretation. Or C, which is basically assembler with more names and curly braces. But for some reasons people started developing and using higher level languages, that forbid certain techniques - and everytime somebody yelled "I want to be free to do what I want" - python has its very special case of that with its whitspace-dependend blocking structure that frequently causes people confronted with it to reject python as language. People started using higher level languages because they actually _did_ decrease the amount of problems programming caused - so the projects could get more eleaborated. Don't get me wrong - there is a lot of decisions to be made in language design, and lots of them are debatable - python is no exception from that rule. But as I said before - allowing builtins to be manipulated aks for more trouble than its worth. Imagine a len() that always returns 1 - no matter what you feed it. Or _if_ you're allowed to change builtin-types constructors - then who is to decide which of the 5 different string implementations in the various modules imported is the one to use? The only thing you really need is a simple constructor for your undoubtly interesting and useful string-derived class. Overloading "" as the string constructor isn't possible - for the simple reason that only a statically typed language could distinct the usage of the "classic" constructor vs. your enhanced version. So what you could do is to modify the builtins-_dict_ - that is possible - to contain a new constructor s in it - then creating your strings is just s('foo') Which is only three chars more than usual string creation. Another approach would be some macro-mechanism - but python doesn't have such facility builtin - and I'm not aware that there is a widely adopted 3rd-party module/extenion out in the wild. -- Regards, Diez B. Roggisch From asif at go-away-spammer.com Tue Aug 24 17:10:53 2004 From: asif at go-away-spammer.com (Player) Date: Tue, 24 Aug 2004 22:10:53 +0100 Subject: Begginers questions on different distributions of py References: Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Also if I install the activestates build or the python websites build, will I need the Win32all extensions, due to me eventually wanting to build windows applications ??? Thanks in advance one again for any help :) M.B -----BEGIN PGP SIGNATURE----- Version: PGP 8.0 iQA/AwUBQSuu2y/z2sM4qf2WEQIFbACg+zTujtlW2PUVrmYNJ1oG/gxwvjgAni+O D0cFAl0WofjPNuB41dggJhig =XsEY -----END PGP SIGNATURE----- From squirrel at WPI.EDU Wed Aug 4 09:53:09 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Wed, 4 Aug 2004 09:53:09 -0400 Subject: EOL - scanning single-quoted string In-Reply-To: References: <1091625659.4110e2bb6db73@www-mail.usyd.edu.au> <4110E3B3.8040709@geochemsource.com> Message-ID: On Wed, 4 Aug 2004, Ajay wrote: > i got the escape character bit, but i still get an error > >>> str='/My Documents/um_ajay.xml' > >>> re.subn('/', '\\', str) Ah... regex quoting issues. The '\\' makes a single '\' appear in the string, but being a regex, a single '\' in a string is again interpreted as a backslash. You will either have to write '\\\\' or use a raw string, r'\\'. Raw strings pass backslashes untouched, so you only need to backslash it once for the regex. However, the best solution for your problem is not to use regexes, but to use the os.path module: >>> from os.path import normpath, abspath >>> str = '/My Documents/um_ajay.xml' >>> normpath(str) '\\My Documents\\um_ajay.xml' >>> abspath(str) 'C:\\My Documents\\um_ajay.xml' normpath() 'tidies up' the path, a task which includes correcting path seperators, amoung other things. abspath() does the same thing as normpath(), but also resolves relative paths into absolute ones. Always look to os.path when doing anything involving paths; it probably has the function you want, and is portable across platforms. From roy at panix.com Mon Aug 9 11:27:05 2004 From: roy at panix.com (Roy Smith) Date: Mon, 09 Aug 2004 11:27:05 -0400 Subject: Maybe, just maybe @decorator syntax is ok after all References: <4116b725$1@nntp.zianet.com> Message-ID: Michael Ekstrand wrote: > Much of that can be accomplished stylistically in the way comments are > written (granted, that doesn't accomplish much for existing code that > doesn't follow such conventions). But, for example, in my C/C++ code, I > always have comments before my functions like so: > > /* > * FooClass::foo() > * > * Fooifies the FooClass instance > */ > int FooClass::foo(int parm1, char parm2, char *spam_name) The problem there is that you need to repeat the name of the function. This was one of the very reasons given for wanting to get away from def foo (): pass foo = classmethod (foo) in the first place. Not the only reason, by far, but certainly one of them. From anthony_barker at hotmail.com Tue Aug 3 15:54:19 2004 From: anthony_barker at hotmail.com (Anthony_Barker) Date: 3 Aug 2004 12:54:19 -0700 Subject: Python executable on Windows References: <410e91ce$0$58816$5a6aecb4@news.aaisp.net.uk> <410e93a1$0$58815$5a6aecb4@news.aaisp.net.uk> <410e95e4$0$65605$a1866201@newsreader.visi.com> Message-ID: <899f842.0408031154.5059d273@posting.google.com> McMillan Installer can create a single .exe. Basically it explodes each time you run in your temp directory. http://paulbaranowski.org/Downloads/installer_6a2.tar.gz Anthony From martindemello at yahoo.com Wed Aug 25 03:07:27 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Wed, 25 Aug 2004 07:07:27 GMT Subject: functional library References: <0uBWc.191260$M95.165005@pd7tw1no> <3b2846c4.0408240210.5803b8b4@posting.google.com> Message-ID: John Crichton wrote: > Hi Martin, > > You could try the Xoltar toolkit at > http://www.xoltar.org/languages/python.html Thanks! martin From inkedmn at gmail.com Mon Aug 16 15:41:17 2004 From: inkedmn at gmail.com (Brett Kelly) Date: 16 Aug 2004 12:41:17 -0700 Subject: Simple exceptions question In-Reply-To: Message-ID: You could use multiple print statements in your function (and still achieve the same output) like: print a[10], print b[10], print c[10] etc. kinda hackish, i know Nick Jacobson wrote: > Say I have a function foo that throws an IndexError exception, and I > want to handle it: > > def foo(a, b, c): > print a[10], b[10], c[10] #, etc. > > def main(): > #define vars > try: > foo(a, b, c) > except IndexError: > print "Accessed array ", x, " out of bounds!" #??? > > When the exception is thrown, I don't know what triggered it! a, b, > or c? > > I could put a series of if statements in the except clause, but that > defeats the whole purpose of having the exception, right? Is there a > better way? > > Thanks in advance! > > --Nick From ajsiegel at optonline.com Thu Aug 26 12:29:05 2004 From: ajsiegel at optonline.com (Arthur) Date: Thu, 26 Aug 2004 16:29:05 GMT Subject: Are decorators really that different from metaclasses... References: <412D9F1E.6000809@yahoo.it> Message-ID: <5n3si0hceqdh99u28ntuc57t68uah557gt@4ax.com> On Fri, 27 Aug 2004 00:53:51 +1000, Anthony Baxter wrote: >On Thu, 26 Aug 2004 14:40:18 GMT, Arthur wrote: >> >IMO, to change it inside of a function def should be (but isn't) as easy >> >as... >> > >> > >>> def foo(): >> > ... """ I am foo """ >> > ... __doc__ = __doc__ + 'indeed' >> > >> >Paul >> >> Yes. Not only do I follow, but I think we came to exactly the same >> place, from very different directions, and coming from what I sense is >> very different backgrounds. >> >> Its just that I don't think many others seem to find that as >> interesting as I happen to. > >Not so much that, as running out of ways to restate myself. The >proposed syntax above still requires magic handling of double-under >variables in a function, and a new namespace. I can't see how you can >think that this is a _good_ thing. Googling on "function namespace" is interesting. Subject to my interpretation of what I am accessing: Common Lisp has 'em, Scheme don't. Talked about a lot in the context of XML in ways I am not sure are relevant. Nested scopes is the beginning of their introduction into Python - as I am reading a cite from Dive Into Python. So of course what I have been driving at all along, is some extension to the the nested scope mechanism. Yes. I'm talking through my backside. Darts at the wall language design, I call it. Art From ksenia at ksenia.nl Fri Aug 20 04:41:48 2004 From: ksenia at ksenia.nl (Ksenia Marasanova) Date: Fri, 20 Aug 2004 11:41:48 +0300 Subject: Alternative decorator syntax decision In-Reply-To: <0C77C7530EA52A4EBD1C47C80D1D291E17DE2A@sbs.GuidanceBV.local> References: <0C77C7530EA52A4EBD1C47C80D1D291E17DE2A@sbs.GuidanceBV.local> Message-ID: >> voting on _alternatives_ to A. > > If we're only voting on alternatives, I would change my vote (J2 J2 A2) > to (J2 J2 J2). The same for me, in that case please change my vote (J2 J2 A1) to (J2 J2 J2). Ksenia From Sibylle.Koczian at Bibliothek.Uni-Augsburg.de Wed Aug 4 05:03:49 2004 From: Sibylle.Koczian at Bibliothek.Uni-Augsburg.de (Sibylle Koczian) Date: Wed, 04 Aug 2004 11:03:49 +0200 Subject: MySQLdb select In-Reply-To: References: <9RPOc.2792$LI7.1058@newssvr27.news.prodigy.com> <21064255.0408020908.41357e52@posting.google.com> <2n9gmuFuhk8kU1@uni-berlin.de> Message-ID: <2nbn3pFv4865U1@uni-berlin.de> Dennis Lee Bieber schrieb: > On Tue, 03 Aug 2004 15:02:21 +0200, Sibylle Koczian > declaimed the following in > comp.lang.python: > > > >>I'm quite surprised that it works the other way - but it does. Could it >>be that previous versions of MySQLdb raised an exception with the other form >> > > > Well, from the MySQLdb code itself, we have these little > comments... > > -=-=-=-=-=-=- > def literal(self, o): > """ > > If o is a single object, returns an SQL literal as a string. > If o is a non-string sequence, the items of the sequence are > converted and returned as a sequence. > > Non-standard. > > """ I don't see where "literal" comes into this? > -=-=-=-=-=-=- > def execute(self, query, args=None): > > """Execute a query. > > query -- string, query to execute on server > args -- optional sequence or mapping, parameters to use with > query. > > Note: If args is a sequence, then %s must be used as the > parameter placeholder in the query. If a mapping is used, > %(key)s must be used as the placeholder. > > Returns long integer rows affected, if any > > """ That would confirm that a single string or number is not a correct args parameter, wouldn't it? There is nothing here like "if args is no sequence, it is treated as a tuple of length one" - but this seems to be what happens. Koczian From ksenia at ksenia.nl Wed Aug 18 12:02:43 2004 From: ksenia at ksenia.nl (Ksenia Marasanova) Date: Wed, 18 Aug 2004 19:02:43 +0300 Subject: age of Python programmers In-Reply-To: References: Message-ID: <09F9DC18-F130-11D8-968C-000A957911BC@ksenia.nl> > One thing I've always kind of wondered is what is the average age of a > Python programmer?? 31 I use Python mostly for web development (with Quixote as a framework). Pitty that can't use Python in Flash instead of Actionscript and as a Javascript replacement ;-) From mike at skew.org Tue Aug 3 00:57:56 2004 From: mike at skew.org (Mike Brown) Date: Mon, 2 Aug 2004 22:57:56 -0600 (MDT) Subject: [XML-SIG] value error when parsing XML In-Reply-To: <410B7277.3000609@mail.usyd.edu.au> "from Ajay Brar at Jul 31, 2004 08:20:39 pm" Message-ID: <200408030457.i734vuQ6058587@chilled.skew.org> Ajay Brar wrote: > i get a value error when parsing an xml file. This is because it can't > find the DTD - > ValueError: unknown url type: ../um_xml/um.dtd > > From what i have discovered in the archives, this happens when your XML > and DTD file are not in your current directory > i have the directory structure > home > user - this is where i am running the script from > um_xml- this is where the xml and dtd are > > can someone please tell me how i can workaround this problem. the script > executes fine when the xml and dtd files are in user/. But i don't > really want to put them there. > any ideas? > The "current directory" / "where you are running the script from" has no bearing on the interpretation of URLs in the document (not directly, anyway). If both files are in the same location, you only need to refer to the DTD via the URL um.dtd (no add'l path info prepended to it). From justin__devine at hotmail.com Mon Aug 30 14:04:17 2004 From: justin__devine at hotmail.com (Justin) Date: 30 Aug 2004 11:04:17 -0700 Subject: Size of a remote URL In-Reply-To: <41336bb1$0$8079$a1866201@newsreader.visi.com> Message-ID: Yeah just HTTP From ben at transversal.com Wed Aug 25 05:05:05 2004 From: ben at transversal.com (Ben) Date: Wed, 25 Aug 2004 10:05:05 +0100 Subject: age of Python programmers References: <20040819231139.D039A1E4003@bag.python.org> Message-ID: <412c5642$0$5080$afc38c87@news.easynet.co.uk> I'm 25. Professionally I am a C++ programmer, but I introduced Python to my company two years ago and now we use it for all our scripting and embedding needs Ben Young From pm_mon at yahoo.com Thu Aug 26 11:15:46 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Thu, 26 Aug 2004 11:15:46 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> Message-ID: Anthony Baxter wrote: > On Thu, 26 Aug 2004 09:50:43 -0400, Paul Morrow wrote: > >>Ok. Then let's jettison the baggage with the word metadata and just >>call them 'magic attributes'. It doesn't matter. The essential point >>about them is that they almost /never have 'local variable' semantics/. >>They are attributes of the object being defined. That's the point I'm >>trying to drive home here. When we define __xxx__ attributes, we are >>not intending to create local variables. No. We are making declarations. > > > Explain to me how __getitem__ is a declaration while getMonkey is not, > assuming both are methods. > > The only magic attribute that fits your case of "magic attribute" is > __metaclass__. > The overwhelming number of double-under names are not magic > attributes, or metadata, or whatever you want to call them. __getitem__ is most certainly magical! Defining it 'declares' (implicitly, but we'll ignore that governing zen rule for the moment) that instances of the containing class have dictionary semantics (that they can be used, in some degree, like dictionaries). That's magic. That's meta. That's profoundly deeper than anything defining getMonkey does. From squirrel at WPI.EDU Thu Aug 12 11:33:38 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 12 Aug 2004 11:33:38 -0400 Subject: os.removedirs not working In-Reply-To: References: Message-ID: On Thu, 12 Aug 2004, Golawala, Moiz M (GE Infrastructure) wrote: > I have a small program that where I am using > os.removedirs('C:\\someDir') on windows. I get the error that the > directory is not empty. Sure there are sub-directories under it and all > file and directories are deletable(nothing is locked by the system) and > there are no permission issues either. Can someone please tell me if I > am using the os.removedirs() correctly? os.removedirs() won't remove files for you. As far as I can tell, there's no builtin Python function that does this, but the library docs for os give the following bit of code that does just what you want: import os from os.path import join # Delete everything reachable from the directory named in 'top'. # CAUTION: This is dangerous! For example, if top == '/', it # could delete all your disk files. for root, dirs, files in os.walk(top, topdown=False): for name in files: os.remove(join(root, name)) for name in dirs: os.rmdir(join(root, name)) My guess as to why this isn't a library function is precisely the reason stated in that comment: it's potentially dangerous! From mwh at python.net Sat Aug 7 15:49:54 2004 From: mwh at python.net (Michael Hudson) Date: Sat, 7 Aug 2004 19:49:54 GMT Subject: Going the PL/1 way References: Message-ID: Jarek Zgoda writes: > Come on, guys, fix real problems like interpreter thread safety, > improve performance, don't make us, "real-world software > developers", screaming with every new release, please. http://www.python.org/patches/ Cheers, mwh -- Monte Carlo sampling is no way to understand code. -- Gordon McMillan, comp.lang.python From ely.stob at elvis.com Mon Aug 2 18:24:58 2004 From: ely.stob at elvis.com (Ely Stob) Date: 2 Aug 2004 15:24:58 -0700 Subject: C# / .NET books recommendations? (was: Re: Importance of C#) References: <278de0e.0407281353.27b6a457@posting.google.com> <5dydnZSDZaARoZXcRVn-ug@powergate.ca> <9418be08.0407292114.129c856f@posting.google.com> Message-ID: Ivan Voras writes: > Elbert Lev wrote: > > > C# IS a good language and .NET is a very good environment. Recently I ... > > Important - Python realities (not exotic) map on C# perfectly. > > My experience exactly - this is what I was fishing for. While I > wouldn't say 'perfectly', it is good, and certainly 'good enough'. Interesting comment. Anybody have recommendations (and warnings-off...) for books on C#, .NET, and associated gubbins? (ASP.NET, ADO.NET, Windows Forms, ...) I'm guessing that I'll need a good half-tonne of dead tree if I'm to get a grasp of it <0.5 wink>. Figuring out *which* half-tonne might be even more time-consuming than reading that dry mass, though... Some books that caught my own eye - all comments much appreciated: C# and .NET =========== Jesse Liberty; Programming C# Andrew Troelsen; C# and the .Net Platform Anders Hejlsberg, Scott Wiltamuth, Peter Golde; The C# Programming Language Box, Sells; Essential .NET Stephen Teilhet, Jay Hilyar; C# Cookbook; (O'Reilly) Peter Drayton, et al; C# in a Nutshell; (O'Reilly) J Richter; Applied Microsoft .NET Framework Programming Windows Forms ============= Chris Sells; Windows Forms Programming in C# Matthew MacDonald; User Interfaces with C SHARP: Windows Forms and Custom Controls ASP.NET ======= Jesse Liberty, Dan Hurwitz; Programming ASP.NET Fritz Onion; Essential ASP.NET with Examples in C# N. Kothari; Developing ASP.NET Server Controls and Components ADO.NET ======= D. Sceppa; Microsoft ADO .NET (Core Reference) Misc ==== R. Jeffries; Extreme Programming Adventures in C# I see Petzold is soldiering on, too :-/ ely From borkent at cs.utwente.nl Thu Aug 26 07:00:34 2004 From: borkent at cs.utwente.nl (Michiel Borkent) Date: Thu, 26 Aug 2004 13:00:34 +0200 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: Erm, please don't make false propaganda for the language I happen to love ;). Btw: (english-to-esperanto "troll") ==> "trolo" Michiel "Peter Hansen" wrote in message news:aNidnUSV4-OK4rDcRVn-jA at powergate.ca... > Robert wrote: > > > Isn't "Xah Lee" chinese for "Moron"? > > No, it's Esperanto (universal language) for "troll"... > > -Peter From eldiener at earthlink.net Sun Aug 1 08:12:38 2004 From: eldiener at earthlink.net (Edward Diener) Date: Sun, 01 Aug 2004 12:12:38 GMT Subject: Returning another instance from constructor References: Message-ID: Robert Brewer wrote: > Edward Diener wrote: >> ...I can find no documentation in the Python 2.3 docs >> for __new__ . Can you point me to it ? > > Start with http://www.python.org/2.2.3/descrintro.html Thanks. I do think the information about new style classes should be part of the Python distributed documentation. Any reason why it has not been since it is now part of the language, or did I miss it somewhere in the official distribution > From ajsiegel at optonline.com Mon Aug 23 11:58:26 2004 From: ajsiegel at optonline.com (Arthur) Date: Mon, 23 Aug 2004 15:58:26 GMT Subject: __name__ becoming read-write? References: Message-ID: On Tue, 24 Aug 2004 01:40:29 +1000, Anthony Baxter wrote: >On Mon, 23 Aug 2004 14:07:42 GMT, Arthur wrote: >> >> >> Did I hallucinate something about __name__ becoming read-write? > >> Better get my facts straight first.... >> >> But if true that would seem to solve the main objection to: > >> the_horrible_name_I _need_to_call=transform(__f) > >> And would mean that a byproduct of the PEP318 implementation would go >> 50% toward obviating the need for a PEP318 implementation. At least >> by one measure. > >No, it is now read-write, thanks to mwh. I think, though, that you're >misunderstanding the difference between setting a local variable in >the function, called '__name__', and setting the actual __name__ of >the function object. You are right. I did know this to be *possibly* true, but had no implementation to test. Though __doc__ (and I am sure other stuff) exhjibits the same behavior, so there is no real excuse to be surprised. This sabotages my approach, but only to the extent that we would still need until after __f's def to know the name we are imposing on it. Of course I am curious as to why, and what would be involved, and wrong,. with merging the local variable and the actual name for these special syntax items. It would seem to have merit on its own terms. For example I had noticed to use string substition on a function doc I needed to assign to __doc__ outside the function. Unless I was hallucinating. Though I would understand if you are not in tutorial mood, or mode. Art >>>> def foo(): pass >... >>>> foo.__name__ = 'bar' >>>> foo.__name__ >'bar' >>>> def foo(): >... __name__ = 'bar' >... >>>> foo.__name__ >'foo' >>>> foo.func_code.co_names >('__name__',) From newsgroups at jhrothjr.com Thu Aug 5 17:15:39 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Thu, 5 Aug 2004 17:15:39 -0400 Subject: Proposal: require 7-bit source str's References: Message-ID: <10h58s2bmjo1j67@news.supernews.com> "Hallvard B Furuseth" wrote in message news:HBF.20040805p736 at bombur.uio.no... > Now that the '-*- coding: -*-' feature has arrived, > I'd like to see an addition: > > # -*- str7bit:True -*- > > After the source file has been converted to Unicode, cause a parse > error if a non-u'' string contains a non-7bit source character. > > It can be used to ensure that the source file doesn't contain national > characters that the program will treat as characters in the current > locale's character set instead of in the source file's character set. > > An environment variable or command line option to set this for all > files would also be very useful (and -*- str7bit:False -*- to override > it), so one can easily check someone else's code for trouble spots. > > Possibly an s'' syntax or something would also be useful for non- > Unicode strings that intentionally contain national characters. > > I dislike the '7bit' part of the name - it's misleading both because > one can get 8-bit strings e.g. with the '\x' notation (a feature, > not a bug) and because some 'valid' characters will be 8bit in > character sets like EBCDIC. However, I can't think of a better name. > > Comments? > Has it been discussed before? Is this even an issue? If you specify utf-8 as the character set, I can't see how non-unicode strings could have anything other than 7-bit ascii, for the simple reason that the interpreter wouldn't know which encoding to use. (of course, hex escapes would still be legal, as well as constructed strings and strings read in and so forth.) On the other hand, I don't know that it actually does it this way, and PEP 263 seems to be completely uninformative on the issue. John Roth > > -- > Hallvard From gumuz at NO_looze_SPAM.net Fri Aug 13 10:30:26 2004 From: gumuz at NO_looze_SPAM.net (Guyon Morée) Date: Fri, 13 Aug 2004 16:30:26 +0200 Subject: secret message hidden in an image Message-ID: <411cd06a$0$3888$4d4ebb8e@news.nl.uu.net> hi, i wrote a little script which can 'hide' a piece of text in an image using python and PIL i wrote about it on my blog, if you like to read it go to: http://gumuz.looze.net/blogger/2004/08/message-in-image.html thankyou for your time From http Tue Aug 17 00:29:08 2004 From: http (Paul Rubin) Date: 16 Aug 2004 21:29:08 -0700 Subject: Generators versus Coroutines References: <7x7js1i887.fsf@ruckus.brouhaha.com> Message-ID: <7xoela8k17.fsf@ruckus.brouhaha.com> Nick Patavalis writes: > But this is only a tiny portion of what one can do with generators and > coroutines! Actually for me it is the least interesting part. Having a > keyword that suggests the possibility of resumable functions > (resumable threads of execution), but then impose such limitations, is > frustrating. The limitations aren't as bad as they sound. There are easy workarounds most of the time. I do think using the yield keyword to identify generator functions was unfortunate, since it makes it harder to get rid of the limitations. From yawar.amin at gmail.com Sat Aug 7 06:28:11 2004 From: yawar.amin at gmail.com (Yawar Amin) Date: Sat, 07 Aug 2004 16:28:11 +0600 Subject: Decorator syntax In-Reply-To: References: <38ednYT1NLz1P4zcRVn-uA@powergate.ca> Message-ID: <2njp58F1jj1dU1@uni-berlin.de> Christopher T King wrote: > Another (perhaps better) method of declaring metadata has been previously > proposed, that of function attributes: > > def foo(a,b,c): > .accepts = (int,int,list) > .author = 'Chris King' How about def foo(a, b, c): foo.accepts = (int, int, list) foo.author = 'Chris King' -- Yawar Amin From ville at spammers.com Fri Aug 20 06:47:47 2004 From: ville at spammers.com (Ville Vainio) Date: 20 Aug 2004 13:47:47 +0300 Subject: Alternative decorator syntax decision References: Message-ID: >>>>> "Paul" == Paul McGuire writes: Paul> (And let's hope we get at least as good a response as the "average age" Paul> thread!) Not going to happen, with the words "alternative decorator syntax" in the subject. No sensible person wants to see yet another wacky alternative, and the subject promises as much. Hence, I won't vote yet because, at minimum, you need a better subject line. Something like this needs to be announced somewhere (e.g. daily python-url). -- Ville Vainio http://tinyurl.com/2prnb From bart_nessux at hotmail.com Sat Aug 14 23:11:36 2004 From: bart_nessux at hotmail.com (Bart Nessux) Date: Sat, 14 Aug 2004 23:11:36 -0400 Subject: windows registry, tuples, turning off winXP firewall with Python Message-ID: for i in range(10000): try: n,v,t = EnumValue(open_key,i) # n == name of the registry object. # v == object's value. # t == object's type. print n,v,t except EnvironmentError: print "\nThere are", i, "registy objects under this key." break Is there a way to reference an item within a tuple that you've iterated over? The above code upacks a tuple into 3 variables n,v and t. In order to do this, it loops over a Windows registry key. Let's say that I want to find out which n == 'EnableFirewall' and then read the value of its v... how can I do that? BTY, the below code turns off the 'Windows Firewall' on Windows XP Service Pack 2... I wrote it as a test after reading that MS is allowing 3rd party programs to programmatically enable or disable the firewall through the registry. from _winreg import * sub_key = r"SYSTEM\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy\StandardProfile" open_key = OpenKey(HKEY_LOCAL_MACHINE, sub_key, 0, KEY_ALL_ACCESS) SetValueEx(open_key,'EnableFirewall',0,REG_DWORD,0) CloseKey(open_key) From pm_mon at yahoo.com Fri Aug 20 05:57:42 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Fri, 20 Aug 2004 05:57:42 -0400 Subject: PEP 318: Can't we all just get along? In-Reply-To: References: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: Anthony Baxter wrote: > On Thu, 19 Aug 2004 07:52:38 -0400, Paul Morrow wrote: > >>I wrote: >> >>>Look, name-mangling is horrid, and I don't think anyone's defending it. But >>>at the same time, "name mangling is there" is not an argument for extending >>>the horror to a whole new level. >>> >>>Name mangling only occurs when you create a method with two leading >>>underscores, and no trailing ones. Your proposal would hit _every_ _single_ >>>'def'. It's nasty, it's unpythonic, and there's approximately _zero_ chance of >>>it ever going into the language. Having said that, it's perfectly feasible to do >>>it with a metaclass, and if you want to use it in your code, please, feel free. >> >>You didn't follow that one with a smiley either... :-) > > > That's because I wasn't joking, at all. Look, your idea is a _bad_ one. Numerous > people have pointed out why. Let it die. I know you weren't Anthony (that was a joke). I understand that you don't like this idea, but that doesn't make it a _bad_ one. Numerous people have *not* effectively pointed out the problems with it (and neither have you, sir). Don't use it, if you don't want to. Make your code as hard to understand as you like. Python gives you that freedom. From godoy at ieee.org Mon Aug 23 12:17:43 2004 From: godoy at ieee.org (Jorge Godoy) Date: Mon, 23 Aug 2004 13:17:43 -0300 Subject: 100 % portable ? References: Message-ID: Sion Arrowsmith writes: > Roger Binns wrote: >>My preferred toolkit is the wxPython wrapper around wxWidgets. >>Wherever possible it uses native widgets. [ ... ] >> >>Just to give you some idea, in my 30,000 line program there are >>5 tests to see what platform it is running on, specifically to >>ensure appropriate defaults etc for the platform. > > Sounds about right to me -- I've got about 20,000 lines of > application with six platform tests, five of which are to > work around platform-specific infelicities in wx. This sounds very interesting. Do any of you have those tests and workarounds publicly available? -- Godoy. From grante at visi.com Wed Aug 11 10:58:10 2004 From: grante at visi.com (Grant Edwards) Date: 11 Aug 2004 14:58:10 GMT Subject: How to get rid of "hex/oct constants > sys.maxint" warning? Message-ID: <411a3402$0$65564$a1866201@newsreader.visi.com> I'm getting tired of seeing meaningless warnings from my code, but I can't figure out how to get rid of them: For example: fcntl.ioctl(fd,0xc0047a80,s) causes FutureWarning: hex/oct constants > sys.maxint will return positive values in Python 2.4 and up Firstly, I have no idea what that error means in this context. 0xc0047a80 isn't intended to be an integer (either positive or negative): it's just a chunk of 32 bits. Googling the newsgroup came up with the suggestion that putting an "L" on the end of the constant would eliminate the warning, but it causes an error: fcntl.ioctl(fd,0xc0047a80L,s) causes OverflowError: long int too large to convert to int So, that doesn't work. How _do_ I get rid of the warning? Is there a way to tell Python that the constant isn't an integer, it's just a bit pattern? -- Grant Edwards grante Yow! Mr and Mrs PED, can at I borrow 26.7 visi.com From PPNTWIMBXFFC at spammotel.com Fri Aug 13 03:32:58 2004 From: PPNTWIMBXFFC at spammotel.com (Marco Aschwanden) Date: Fri, 13 Aug 2004 09:32:58 +0200 Subject: Yet another decorator proposal References: <2ntvn1F4mgskU1@uni-berlin.de> <2o1dcnF5s9itU1@uni-berlin.de> Message-ID: On Thu, 12 Aug 2004 16:41:36 +0200, Reinhold Birkenfeld wrote: > It doesn't really need to be triple-quoted, does it? >>> def test(): ... "A little test." ... print "hi" ... >>> test.__doc__ 'A little test.' >>> It seems not, but I am not aware what language reference says to that... Marco From curzio.basso at unibas.ch Wed Aug 11 04:04:01 2004 From: curzio.basso at unibas.ch (Curzio Basso) Date: Wed, 11 Aug 2004 10:04:01 +0200 Subject: how to dispatch objects depending on their class In-Reply-To: <4118dd4a$1@maser.urz.unibas.ch> References: <4118dd4a$1@maser.urz.unibas.ch> Message-ID: <4119d2f7$1@maser.urz.unibas.ch> Curzio Basso wrote: > class B(object): > def __init__(self): > A.__init__(self) typo. this should be: class B(A): def __init__(self): A.__init__(self) From mwh at python.net Tue Aug 3 08:56:58 2004 From: mwh at python.net (Michael Hudson) Date: Tue, 3 Aug 2004 12:56:58 GMT Subject: metaclasses and Exceptions References: <5d83790c.0407311043.1021ebaa@posting.google.com> Message-ID: python at rcn.com (Raymond Hettinger) writes: > Michael Hudson wrote > One of the areas where PyPy is > different from CPython is that there > > are no old-style classes or instances, so exceptions are necessarily > > new-style. This has caused no real problems on any Python program > > we've tried it on yet... > > How does PyPy distinguish between instance and class arguments to > raise? "isinstance(x, type)", iirc. The code is in this file: http://codespeak.net/svn/pypy/trunk/src/pypy/interpreter/pyframe.py in the function app_normalize_exception(). There's a kind of horrible issue if you do things like: class Nasty(type, Exception): pass raise Nasty() I can't remember what PyPy does here (the answer is quite possibly "break"). > Given: raise X > Does it pass X or X()? Depends on X! Has to, really, or we certainly would have had more problems from this than we've had. Cheers, mwh -- "declare"? my bogometer indicates that you're really programming in some other language and trying to force Common Lisp into your mindset. this won't work. -- Erik Naggum, comp.lang.lisp From eurleif at ecritters.biz Sat Aug 21 14:02:43 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sat, 21 Aug 2004 14:02:43 -0400 Subject: __metaclass__ and __author__ are already decorators In-Reply-To: References: Message-ID: <2opgsoFd7807U1@uni-berlin.de> Paul Morrow wrote: > Thinking about decorators, and looking at what we are already doing in > our Python code, it seems that __metaclass__, __author__, __version__, > etc. are all examples of decorators. So we already have a decorator > syntax. What is the compelling reason to invent a new one? And if we > do, what's to become of the old one? > I've thought about something along the lines of your suggestion before, but it doesn't seem very Pythonic to assign special meaning to function variables with special names to me. It's essentially a new syntax, but disguised as an old syntax with an entirely different meaning. From opengeometry at yahoo.ca Mon Aug 2 03:29:12 2004 From: opengeometry at yahoo.ca (William Park) Date: 2 Aug 2004 07:29:12 GMT Subject: (patch for Bash) try-block and exception References: <2n27jlFsb5njU1@uni-berlin.de> <2n60o4Frnmp4U1@uni-berlin.de> Message-ID: <2n68q7Fsoqc6U2@uni-berlin.de> In Greg Ewing wrote: > William Park wrote: > > try > > echo a > > raise 2 > > echo b > > done in > > 0) echo okey ;; > > 1) echo raised 1 ;; > > 2) echo raised 2 ;; > > *) echo really bad ;; > > esac > > try...done...esac? What a delightfully eclectic combination > of syntax. :-) > > Why doesn't it end with 'yrt'? 'try-done' was chosen because it resembles while-loop where you would break out of; and, '-in-esac' was chosen because it resembles case statement. Also, I didn't want to introduce too many new keywords. -- William Park, Open Geometry Consulting, Toronto, Ontario, Canada From ben at benlast.com Sun Aug 15 04:10:35 2004 From: ben at benlast.com (Ben Last) Date: Sun, 15 Aug 2004 09:10:35 +0100 Subject: Decorators: an outsider's perspective Message-ID: Hans (Hans Nowak (hans at zephyrfalcon.org)) wrote: >This post wasn't deriding decorators; rather, it explains them, >and provides some examples of how to use them. I do question >their usefulness, but I'm not deriding them, nor the "@" syntax. Just to be contrary, *this* post isn't questioning the usefulness of decorators (though I've yet to see a case that really makes me feel they're a killer feature), but *is* questioning the syntax (not deriding - I don't do derision!) The "@" notation feels a little bit Perl-esque to me, in a "let's overload another symbol" type of way. It doesn't seem to follow the general Python-zen model of using explicit words for extra functionality, such as "staticmethod". I appreciate it's just syntactic sugar, but one could make that same case for, say, the $_ variable in Perl. Given (for the sake of argument), that decorators are useful (and here I'm admitting that I may well be in ignorance of the finer points of their requirements), do they *really* require a dedicated extension to the language? Surely; those who are aware of the need for decorators will also tend to be competent to build them using the language features that already exist, obviating the need for special syntax? Although I concede the edge case of experienced developers in another language who come to Python and want to use such power-user features from day one. This comment offered in all humility, as a first post :) Ben PS: Paul (Morrow): when I read your statement "I'm really not sure that those 'Zen' items were intended to be absolute guiding principles", I couldn't help but remember Captain Barbossa in Pirates Of The Caribbean - "the [Pirate] code's more what you would call guidelines than actual rules..." :) From robin at SPAMREMOVEjessikat.fsnet.co.uk Sun Aug 8 07:10:15 2004 From: robin at SPAMREMOVEjessikat.fsnet.co.uk (Robin Becker) Date: Sun, 08 Aug 2004 12:10:15 +0100 Subject: Going the PL/1 way In-Reply-To: References: Message-ID: <41160A17.2090708@jessikat.fsnet.co.uk> Mikl?s wrote: > Ok, seems like we have @decorators. It's a nice tribute to Intercal. But > I'd prefer #decorators. > > We have metaclasses for pleasure brain-melting. We have generators, > new-style classes and old-style classes. Lambdas are wonderful. > We do need real interfaces, not abused classes. Python still needs to have > inlined functions, macros and templates. Operator overloading is not enough, > one should be able to introduce new ones freely. There's a heavy demand for > terciary comparisons. Why don't we have a 'case' statement and 'do... repeat > ()'? > We cannot do without general closures, of course. Hm, automatic garbage > collection is sometimes fine but explicite memory allocation/deallocation is > really unavoidable for efficient programs. > Wait, pointers are a must! Static typing should have been introduced a long > time ago. You just cannot do without absolute address variables. > > Yes, I'm thorougly annoyed with creeping featurism. > > Mikl?s > ..... I'm not exactly against 'decorators' although it seems to me thay should be called 'transformers' as it seems they act to transform the following function definition. On the other hand the proposed syntax is abominable. Additionally there now seems to be at least two 'one and only obvious' ways to handle these transformations. @classmethod def meth(...): ... or def meth(...): ... meth = classmethod(meth) As a final silliness (or perhaps miracle) this can apparently all be done in python using code from PJ Eby so a standard decorate mechanism could have gone into the library while the Gods argue. Decision by exhaustion is surely not a good recipe. -- Robin Becker From kamikaze at kuoi.asui.uidaho.edu Sun Aug 8 20:48:44 2004 From: kamikaze at kuoi.asui.uidaho.edu (Mark 'Kamikaze' Hughes) Date: 9 Aug 2004 00:48:44 GMT Subject: @decorators References: <10h73e5kh1et536@news.supernews.com> <4113e5be@nntp.zianet.com> Message-ID: Mark Bottjer wrote on Fri, 06 Aug 2004 16:10:37 -0400: > John Roth wrote: >> All of the existing packages (at least to my knowledge) use >> descriptors to wrap the necessary functions. They could be >> very easily reimplemented in terms of the decorator syntax. >> However, the decorator syntax brings no new functionality >> to the table; it's simply syntactic sugar for already existing >> functionality. > Exactly. What's more, I don't think that decorators are really the ideal > way to express DBC, either. For one thing, pre and post conditions often > want access to at least the argument list, and often to the internal > variables of the definition. I don't think that this will be possible > with the decorators as proposed, since they are outside the scope of the > function. You can already do pre- and post-conditions without new syntax: import types def intdiv(a, b): # preconditions assert type(a) == types.IntType assert type(b) == types.IntType assert b != 0 rc = None try: # body rc = a // b; return rc finally: # postconditions assert type(rc) == types.IntType If assignment was an expression, that return would be a little nicer, but it's acceptable. -- Mark Hughes "Virtues foster one another; so too, vices. Bad English kills trees, consumes energy, and befouls the Earth. Good English renews it." -The Underground Grammarian, v1n2 From martin at v.loewis.de Fri Aug 27 01:43:33 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 27 Aug 2004 07:43:33 +0200 Subject: What GCC version had defined? In-Reply-To: <412e70d3$1@nntp0.pdx.net> References: <412e39d1$1@nntp0.pdx.net> <412E55A9.9070400@v.loewis.de> <412e70d3$1@nntp0.pdx.net> Message-ID: <412eca05$0$24800$9b622d9e@news.freenet.de> Scott David Daniels wrote: > I'd like to change it to something like: > ... > #if _MSC_VER > 1200 > #define HAVE_UINTPTR_T 1 > #define HAVE_INTPTR_T 1 > #endif > ... > #if GCC_VERSION >= 30100 > #define HAVE_UINTPTR_T 1 > #define HAVE_INTPTR_T 1 > #endif > ... > > which is arguably better even if not good enough. That won't help at all. PC/pyconfig.h is used only on Windows, not on Linux. On Linux, configure is run to detect presence of things. > Is there a better test I can do at compile time? Depends on what you want to test for. If it is presence of stdint.h, you should test for HAVE_STDINT_H. Regards, Martin From bokr at oz.net Wed Aug 18 14:40:28 2004 From: bokr at oz.net (Bengt Richter) Date: 18 Aug 2004 18:40:28 GMT Subject: PEP 318: Can't we all just get along? References: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: On Wed, 18 Aug 2004 08:35:21 -0400, Paul Morrow wrote: >Dan Sommers wrote: >> On Tue, 17 Aug 2004 21:13:47 -0400, >> Paul Morrow wrote: >> >> >>>First though, I still believe that we should exploit existing >>>conventions (recommended coding practices) as a way of getting 'free' >>>declarations for class, static, and instance methods (e.g. methods >>>whose first param is 'self' are instance methods, etc.). That feels >>>very pythonic to me, just as we use naming conventions to distinguish >>>public, private, and semi-private methods. >> >> >> I don't understand how assigning semantic significance to a "recommended >> coding practice" is Pythonic. >> >> In the face of ambiguity, refuse to guess. >> >> Explicit is better than implicit. >> > >Good conventions prevent ambiguity. Conventions don't direct computation though, they just direct human interpretation. That is, unless you use convention-patterns as you propose for self etc., and then they aren't just conventions. (As you may infer, my second thoughts on this are not supportive of overloading naming. I thought it was not that "fragile" in the narrow context of ordinary method definition, but I think it's a step on a slippery slope to name-tricks that too many clever people may be tempted to step onto ;-) > > class Foo: > def method1(self, a, b): pass # clearly an instance method > def method2(cls, a, b): pass # clearly a class method > def method3(a, b): pass # clearly a static method def method4(*args): pass # clearly different ;-) > > >When declarations conflict with conventions, it makes us wonder what the >author really intended. Sure, that's natural. Depending on the author, you might look for something interesting ;-) > > def staticmethod setX(self, x): > self.x = x > > > > > I think that the idea that started this thread is just right: > > > >You're right, this thread is about decorators, not about more >opportunities for dynamic typing. I just wanted to remind us that >decorators are a lot like static typing, which isn't terribly pythonic. > Maybe simple-name callables between the def and the function name would cover most use cases, and you could let people do what they want to set up the names. A single name could also be bound to a composition of several things in a lambda or whatever, if handy for repetitive concise use. import mydecorators deco1 = mydecorators.deco1 deco2 = mydecorators.deco2factory('this', 'that', 'tother') class Foo(object): def staticmethod deco1 method1(x,y): pass def deco2 method2(self): pass A plain name series between def and arg list shouldn't be hard grammar-wise, IWT. The idea is growing on me. It doesn't abuse naming itself. Argh, must go ... Regards, Bengt Richter From mauriceling at acm.org Mon Aug 2 04:21:13 2004 From: mauriceling at acm.org (Maurice Ling) Date: Mon, 02 Aug 2004 18:21:13 +1000 Subject: Call for Grant Proposals In-Reply-To: References: <40fcaa90$0$27091$9b622d9e@news.freenet.de> <41097fed$1@news.unimelb.edu.au> Message-ID: <410DF979.5020709@acm.org> Anthony Baxter wrote: >On Thu, 29 Jul 2004 22:53:38 GMT, Maurice LING wrote: > > >>I have a few questions to ask about this grant and I've emailed this to >>psf-grant at python.org but had no replies yet. Maybe someone authoritative >>from PSF can help me out in this or anyone can put in some comments. >> >> > > > >>1. Is there a requirement to release the deliverables, including, >>software, source codes, specifications and documentation, to the general >>public using any of the Open Source Initiative (OSI) approved open >>source licences? >> >> > >I'm not on the grants committee, but I'd _expect_ that this would be the >case, yes. Will this be a problem? > >Anthony > > > This might be a problem if I am trying to apply this grant for a closed source project but still advancing python and its related technology, as I've stated in the same email (question 6, if I'm not wrong). I've given the example of applying this grant for the development of a Python IDE or sort but as a closed source project. It seems that the grants committee has no clear wordings, which will make dealings with companies extremely difficult. I'm unable to convince my lawyers and management without concise wordings by PSF. It seems to me as that this grant is only applicable for hobbyist. Cheers Maurice -- Maurice Han Tong LING, BSc(Hons)(Biochem), AdvDipComp, SN Doctor of Philosophy (Science) Candidate, The University of Melbourne mobile: +61 4 22781753 +65 96669233 mailing address: Department of Zoology, The University of Melbourne Royal Parade, Parkville, Victoria 3010, Australia residential address: 9/41 Dover Street Flemington, Victoria 3031, Australia email: mauriceling at acm.org resume: http://maurice.vodien.com/maurice_resume.pdf www: http://www.geocities.com/beldin79/ The information contained in this message, including its attachment(s), is CONFIDENTIAL and solely intended to its addressee(s) only. The content of this message, including its attachment(s), may be subjected to copyright and privacy laws. If you have received this email in error, please let me know by returning this email, and then destroy all copies. "I cannot discover anyone knows enough to say definitely what is and what is not possible" -Henry Ford "The difference between the impossible and the possible lies in a person's determination" -Tommy Charles Lasorda -------------- next part -------------- A non-text attachment was scrubbed... Name: mauriceling.vcf Type: text/x-vcard Size: 155 bytes Desc: not available URL: From listserver at tdw.net Mon Aug 2 14:30:21 2004 From: listserver at tdw.net (Tim Williams) Date: Mon, 2 Aug 2004 19:30:21 +0100 Subject: New to Python/Programming References: Message-ID: <010b01c478be$c4fb7630$ccbefea9@twilliams> "Mark" wrote in message news:<10gsujk1og2gkbf at corp.supernews.com>... > Hello. I am new to programming and Python and was wondering if someone > could help get me started. I picked Python to start learning to prgram [snip] > something that has always interested me, but don't have the time to take > any formal classes. Thanks for the help. The Python Docs and examples aren't helpful if you don't understand the basic terms, and all the "Teach Yourself Python" books etc get way too deep far too quickly if you've never done any programming before. So overall, they don't really help. As a recent Newbie, I found this to be a lot of help. (It covers both your requirements) "Learn to Program Using Python" http://www.amazon.com/exec/obidos/tg/detail/-/0201709384/102-1047927-0214559?v=glance I found this to be a nice gentle introduction to Python AND programming, and it helps makes sense of some of the other documentation out there. I would treat it as getting you to an intermediate level in-between "knowing nothing" and "understanding what the hell the other books, online-docs and examples are on about" :-) You'll be able to write in Python by the end of it. You would still need something a bit more in depth afterwards (or maybe the online Docs will be sufficient for you) but it won't seem as daunting. From adeger at netlibrary.com Wed Aug 4 16:33:27 2004 From: adeger at netlibrary.com (adeger) Date: 4 Aug 2004 13:33:27 -0700 Subject: simple Thread question References: Message-ID: JCM wrote in message news:... > You should override the run method, but call thread.start() to kick > the execution off in a separate thread. If you call thread.run(), > you're just running your code in the same thread. > Thanks JCM and everyone else for your help! This wasn't that clear to me reading the docs (I really DID read them) and your answer saved me a bunch of personal (and program execution) time! From yong at net.tamu.edu Thu Aug 12 14:21:42 2004 From: yong at net.tamu.edu (Yong Wang) Date: Thu, 12 Aug 2004 13:21:42 -0500 (CDT) Subject: Import command Message-ID: <20040812182143.8CC921589E@net.tamu.edu> Hi, I write a program to do some network device management. In the beginning of my codes, I have: #!/usr/local/bin/python # System imports import sys, string, pwd, posix sys.path.insert(1, '/home/yong/nd3/Modules') print 'sys path is ', sys.path import snmpPP import NDconfig # Miscellaneous ND stuff import rcmd, misc ...... When I run the codes, I get the following error though I have inserted import snmpPP sources path (/home/yong3/nd3/Modules): > cisco werc-2950t-1 sys path is ['', '/home/yong/nd3/Modules', '/usr/local/lib/python1.5/', '/usr/local/lib/python1.5/plat-sunos5', '/usr/local/lib/python1.5/lib-tk', '/usr/local/lib/python1.5/lib-dynload'] Traceback (innermost last): File "cisco", line 10, in ? import snmpPP ImportError: ld.so.1: /usr/local/bin/python: fatal: relocation error: file /usr/local/lib/libreadline.so: symbol tputs: referenced symbol not found How should I fix the import problem ? Thanks a lot. Yong From martin at v.loewis.de Fri Aug 6 08:20:41 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 06 Aug 2004 14:20:41 +0200 Subject: PEP 263 status check In-Reply-To: <10h6rklt3fa1690@news.supernews.com> References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> <10h5hgvpafm8a64@news.supernews.com> <41133C76.8040302@v.loewis.de> <10h6rklt3fa1690@news.supernews.com> Message-ID: <41137799.70808@v.loewis.de> John Roth wrote: > Or are you trying to say that the character string will > contain the UTF-8 encoding of these characters; that > is, if I do a subscript, I will get one character of the > multi-byte encoding? Michael is almost right: this is what happens. Except that what you get, I wouldn't call a "character". Instead, it is always a single byte - even if that byte is part of a multi-byte character. Unfortunately, the things that constitute a byte string are also called characters in the literature. To be more specific: In an UTF-8 source file, doing print "?" == "\xc3\xb6" print "?"[0] == "\xc3" would print two times "True", and len("?") is 2. OTOH, len(u"?")==1. > The point of this is that I don't think that either behavior > is what one would expect. It's also an open invitation > for someone to make an unchecked mistake! I think this > may be Hallvard's underlying issue in the other thread. What would you expect instead? Do you think your expectation is implementable? Regards, Martin From jpmorichon at earthlink.net Thu Aug 12 11:45:36 2004 From: jpmorichon at earthlink.net (CptPicard) Date: Thu, 12 Aug 2004 15:45:36 GMT Subject: os.removedirs not working References: Message-ID: You could use shutil.rmtree : it works fine! But I tend to prefer the solution offered by Chistopher T King: It gives you more control on what you are doing. "Christopher T King" wrote in message news:Pine.LNX.4.44.0408121127160.5408-100000 at ccc8.wpi.edu... > On Thu, 12 Aug 2004, Golawala, Moiz M (GE Infrastructure) wrote: > > > I have a small program that where I am using > > os.removedirs('C:\\someDir') on windows. I get the error that the > > directory is not empty. Sure there are sub-directories under it and all > > file and directories are deletable(nothing is locked by the system) and > > there are no permission issues either. Can someone please tell me if I > > am using the os.removedirs() correctly? > > os.removedirs() won't remove files for you. As far as I can tell, there's > no builtin Python function that does this, but the library docs for os > give the following bit of code that does just what you want: > > import os > from os.path import join > # Delete everything reachable from the directory named in 'top'. > # CAUTION: This is dangerous! For example, if top == '/', it > # could delete all your disk files. > for root, dirs, files in os.walk(top, topdown=False): > for name in files: > os.remove(join(root, name)) > for name in dirs: > os.rmdir(join(root, name)) > > My guess as to why this isn't a library function is precisely the reason > stated in that comment: it's potentially dangerous! > From rmarchetti at crosscountry-auto.com Wed Aug 18 16:24:53 2004 From: rmarchetti at crosscountry-auto.com (Robert Marchetti) Date: Wed, 18 Aug 2004 16:24:53 -0400 Subject: win32: internet explorer automation problem Message-ID: <20040818202129.C81835B80CF@smtp.crosscountry-auto.com> Here is an example script that I use along with PAMIE( Python Automation Module for IE) - http:pamie.sourceforge.net for Automating IE. """ In this script I am using WinGuiAuto by Simon Brunning - simon at brunningonline.net This is a way of using WinGuiAuto with Pamie to manipulate pop-ups """ import winGuiAuto import cPAMIE ie = cPAMIE.PAMIE() wga = winGuiAuto ie.Navigate('http://prdownloads.sourceforge.net/pamie/pamie1_3.zip?use_mirro r=voxel') time.sleep(200) # Wait for pop-up hwnd = wga.findTopWindow(wantedText='File Download') # Find the Dialog text downloadDialog = wga.findControls(hwnd,'','#32770 (Dialog)') cancelButton = wga.findControl(hwnd, wantedClass="Button", wantedText="Cancel") clickButton(cancelButton) -------------- next part -------------- An HTML attachment was scrubbed... URL: From martindemello at yahoo.com Sat Aug 21 15:36:22 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Sat, 21 Aug 2004 19:36:22 GMT Subject: Decorator keyword options - brainstorming References: <7knVc.4599$Jn5.3074@fe1.texas.rr.com> Message-ID: Steven Bethard wrote: > Michael Sparks rd.bbc.co.uk> writes: > > One other thing that jumped out at me is that different syntaxes > > probably work better using different keywords. (Partly why I've snipped > > decorator syntaxes) > > Yeah, I noticed that pretty quickly too. It looks though, that, of the > suggestions requiring a keyword, only the J syntaxes are getting substantial > support. If it seems reasonable to others here, I think we should assume that > when we're discussing keyword options here, we're aiming at keywords > for the J syntaxes (and most probably J2). I liked 'as:' for J2, but since that's earmarked... with, using, having, applying, declare martin From crichton314 at btinternet.com Fri Aug 20 09:41:55 2004 From: crichton314 at btinternet.com (John Crichton) Date: 20 Aug 2004 06:41:55 -0700 Subject: Alternative decorator syntax decision References: Message-ID: <3b2846c4.0408200541.5d925216@posting.google.com> Hi, My vote: J2 J2 J2. Surely any English language keyword that gives a meaningful hint as to its purpose within a program has to be more readable than an arbitrary '@' symbol? Readability is one of Python's key strengths and I would be very sorry to see this undermined. Best wishes, John From ellisjb at my-deja.com Tue Aug 10 16:50:20 2004 From: ellisjb at my-deja.com (ellisjb at my-deja.com) Date: 10 Aug 2004 13:50:20 -0700 Subject: PEP-318, billion-and-first syntax proposal In-Reply-To: Message-ID: I like this idea. It strikes me as very pythonic. -Jonathan Tim Hochberg wrote: > > def NAME as EXPRESSION: > BLOCK > > BLOCK is executed in a separate namespace *before* EXPRESSION is > evaluated. EXPRESSION is then evaluated in BLOCK's namespace. From daniel at syrinx.net Thu Aug 19 12:43:55 2004 From: daniel at syrinx.net (Daniel Ellison) Date: Thu, 19 Aug 2004 12:43:55 -0400 Subject: Interface graphique pour python In-Reply-To: References: <8e16829.0408190650.3fa62d5e@posting.google.com> Message-ID: <2ok3isFbgtl3U1@uni-berlin.de> Fred wrote: > On 19 Aug 2004 07:50:35 -0700, yaoroland07 at yahoo.com (Roland) wrote: > >>J'ai redhat 9.0 sur mon ordinateur. Et j'ai besoin d'une interface >>graphique de python pour cnstuire une application . J'ai cherch? mais >>en vain. Pourriez-vous m'indiquer une? > > > Most people use wxWidgets, and its Python wrapper wxPython. You call > also take a look at > - PyQT (wrapper to the QT widget set, the one used by KDE), > - pyFLTK (... to the FLTK widget set, but this wrapper seems no longer > under development), > - PyGTK (you guessed it), > - FXPy (to the FOX library) > > Fred. It looks like he actually has besion d'une application for *constructing* a Python application. Perhaps Boa Constructor would help: http://boa-constructor.sourceforge.net/ Dan From fumanchu at amor.org Tue Aug 24 14:23:06 2004 From: fumanchu at amor.org (Robert Brewer) Date: Tue, 24 Aug 2004 11:23:06 -0700 Subject: J2 0-2-6 is available Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E52@exchange.hqamor.amorhq.net> There's a semi-final version of the J2 proposal available: http://www.aminus.org/rbre/python/pydec.html I think we've heard all the nits by now, and any paragraphs which I felt were weak have been rewritten. Important changes since 0.2.1: 1) There's a new Conclusion. 2) At Guido's request, I removed "wiggle room" with an explicit statement in the intro: anything not addressed in the proposal defaults to the @pie implementation currently in CVS. There's a list of what is outside the scope of the proposal. 3) I softened the recommendation of the keyword "using" a smidgen (mostly downplaying argument III over the other two). 4) The number of proposed grammars is now one (there were two). If I had another 4 hours or so ;) I'd rewrite it in more direct language. Boy, is it academic in tone--my great weakness. Meh. At this time, I'd like to call for negative signatories. That is, if you believe the @pie syntax is better than suite-and-keyword, please drop me an email, either privately or on the list. I'd like your full name, and *some* indication of why you are rejecting it. One short sentence is enough, but if you want to write more, that's fine. I'll try to merge the rejection comments into a readable summary in that section of the document. Please don't sign it yet if you favor the proposal. I'd like a day to consider the rejection notices. I'm equally open to doing more rewriting to accomodate the blockers, or freezing it as it stands--it depends to a large extent on the responses I get from the detractors in the next 24 hours. If there are no reconsiderations, I'll call for positive signatories (those in favor) tomorrow. I think we have a good chance of success, where Guido can get a clear picture of the situation and make a balanced decision. Thanks again to those who suggested syntax, started polls, managed threads, wrote code (!) and commented on the draft. Robert Brewer MIS Amor Ministries fumanchu at amor.org From squirrel at WPI.EDU Wed Aug 4 08:57:00 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Wed, 4 Aug 2004 08:57:00 -0400 Subject: tkinter button command In-Reply-To: References: Message-ID: On Wed, 4 Aug 2004, Ajay wrote: > if i set two buttons to call the same function when they are pressed, is > there any way, within the function of knowing which button invoked it. Not built-in to Tkinter, but you can easily get such behaviour using lambda like so: >>> from Tkinter import * >>> def click(which): ... print which, 'was clicked!' >>> button1 = Button(text='Button 1',command=lambda: click('number 1')) >>> button2 = Button(text='Button 2',command=lambda: click('number 2')) >>> button1.pack() >>> button2.pack() lambda: will wrap the call to click() up in a function. You can call click() with any arguments this way; instead of strings, you could use integers or a reference to the object itself (though you'd have to set command after creating the button to do this). From adonisv at DELETETHISTEXTearthlink.net Wed Aug 18 10:46:16 2004 From: adonisv at DELETETHISTEXTearthlink.net (Adonis) Date: Wed, 18 Aug 2004 14:46:16 GMT Subject: age of Python programmers References: Message-ID: "Lucas Raab" wrote in message news:jQHUc.1529$2L3.505 at newsread3.news.atl.earthlink.net... > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... > > 23 From nicksjacobson at yahoo.com Tue Aug 17 06:33:58 2004 From: nicksjacobson at yahoo.com (Nick Jacobson) Date: 17 Aug 2004 03:33:58 -0700 Subject: Newbie 1st program References: Message-ID: justin__devine at hotmail.com (JDevine) wrote in message news:... > Hey. I just finished my first python program. In fact it is my first > program program at all. I went from zero knowledge to the current > state in about 6 weeks. Check it out at > http://gobblewin.sourceforge.net I need help for the next stage of > development, I am also sure I could use a lot of advice on structure > etc. My #1 priority is adding a threaded status bar to track > downloads to this program. if you think you can help out let me know. > > Thanks Great job! Here's something to clean up the code a bit: You can change: << if event.GetInt() == 0: t2.Clear() t2.SetValue("Restrict your search to a specific site") t2.SetEditable(True) elif event.GetInt() == 1: t2.Clear() t2.SetValue("army.mil") t2.SetEditable(False) elif event.GetInt() == 2: t2.Clear() t2.SetValue("usmc.mil") t2.SetEditable(False) elif event.GetInt() == 3: t2.Clear() t2.SetValue("af.mil") t2.SetEditable(False) elif event.GetInt() == 4: t2.Clear() t2.SetValue("navy.mil") t2.SetEditable(False) elif event.GetInt() == 5: t2.Clear() t2.SetValue("uscg.mil") t2.SetEditable(False) elif event.GetInt() == 6: t2.Clear() t2.SetValue("SYColeman.com") t2.SetEditable(False) elif event.GetInt() == 7: t2.Clear() t2.SetValue("l3com.com") t2.SetEditable(False) elif event.GetInt() == 8: t2.Clear() t2.SetValue("fedbizopps.gov") t2.SetEditable(False) elif event.GetInt() == 9: t2.Clear() t2.SetValue("defenselink.mil") t2.SetEditable(False) >> to: << ary = ["Restrict your search to a specific site", "army.mil", "usmc.mil", "af.mil", "navy.mil", "uscg.mil", "SYColeman.com", "l3com.com", "fedbizopps.gov", "defenselink.mil"] d = dict(zip(range(10), ary)) i = event.GetInt() if i in range(10): t2.Clear() t2.SetValue(d[i]) t2.SetEditable(bool(i)) >> Also, instead of string.atoi(x), use int(x). I think the former is deprecated. --Nick From rupole at hotmail.com Wed Aug 11 11:12:28 2004 From: rupole at hotmail.com (Roger Upole) Date: Wed, 11 Aug 2004 11:12:28 -0400 Subject: Secure storage for passwords for admin scripts? References: Message-ID: <411a3602$1_2@127.0.0.1> You could store the passwords in a file protected by NTFS encryption, or set the file security to only allow administrators access. hth Roger "Max" wrote in message news:c90c3203.0408100711.3f7b056d at posting.google.com... > I have a collection of system admin scripts (on Win 2k) that I would > like to automate the execution of. However, some of them require the > use of logins with admin rights, and would therefore prefer not to > store the IDs in the clear text of the source. If memory serves > correctly, the "compiled" .pyc files do not provide much security in > this area. > > Are there are recommended methods for supplying scripts with login > information in a secure fashion? From jepler at unpythonic.net Sat Aug 28 22:03:46 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Sat, 28 Aug 2004 21:03:46 -0500 Subject: regex into str In-Reply-To: References: Message-ID: <20040829020346.GA13993@unpythonic.net> This is intended to be impossible. Even if you could assign to str.__div__ (and this is very deliberately and specifically disallowed) you would end up disappointed, because strings are immutable. That means there's nowhere to store "the last match", no way to mutate the string with the "/=" operator, and also that the interpreter is free to use the same storage for two equal strings. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From sholden at holdenweb.com Mon Aug 30 19:56:11 2004 From: sholden at holdenweb.com (Steve Holden) Date: Mon, 30 Aug 2004 19:56:11 -0400 Subject: allowing braces around suites In-Reply-To: References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> Message-ID: <4133BE9B.4040404@holdenweb.com> Anthony Baxter wrote: > On Sat, 28 Aug 2004 02:07:43 GMT, Paul McGuire > wrote: > >>"Kjetil Torgrim Homme" wrote in message >>news:mailman.2551.1093656430.5135.python-list at python.org... >> >>>I'll write a PEP, but it will have to wait until next week. thank you >>>for your feedback! >>> >> >>Kjetil - >> >>I hate to see you waste the effort. > > > I don't think it's a waste of effort. Once a PEP has been written and > rejected, future discussions on the subject can be pointed at the PEP. If you think that's going to stop repeated discussions of this nature then you're more optimistic than I thought. It certainly *would* be nice to put this eternal favorite to rest for ever. Maybe a FAQ entry? regards Steve From ptmcg at austin.rr._bogus_.com Fri Aug 20 02:03:12 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 20 Aug 2004 06:03:12 GMT Subject: Alternative decorator syntax decision References: Message-ID: "Delaney, Timothy C (Timothy)" wrote in message news:mailman.1989.1092960560.5135.python-list at python.org... > I think a web page for tabulating votes would be better (see the > response to the previous vote on 3 syntaxes). I couldn't agree more, Tim, but time is short. Also, there is no protection in the web page from "ballot box stuffing" - I hate to even bring it up, I think we're all adults here, but with public postings on Usenet, there is a somewhat higher effort to create fictitious posts to vote multiple times vs. visiting a poll page multiple times. But so far there have been 11 votes in this concensus survey, as opposed to almost 700 clicks on the Wiki page poll (vs. 94 replies to "how old is everybody out there?"). I know that many folks are just about wrung out over all of the wrangling and debate over the various options, but for all the discussion, we never *decided* anything. The tenor of the comments on python-dev sounds pretty much like "c.l.py can't make up their minds, so the hell with them, the current '@' syntax wins by default," which I think *stinks*. FWIW, here's the tally so far, after 11 :( submissions: J2 12 Any C 12 Any J 12 C1 9 L 4 Any E 3 C2 2 D1 2 E2 2 Any D 2 C3 1 E1 1 M 1 A1 0 A2 0 B 0 C4 0 D2 0 E3 0 F 0 G 0 H 0 I 0 J1 0 J3 0 J4 0 K 0 Any A 0 BTW, where are all the votes for option "A"? Where are all the people who hated it but now like it? -- Paul For those of you not familiar with the philosophical story of Buridan's Ass, see http://www.cenius.net/refer/display.php?ArticleID=buridansass . From chrisks at NOSPAM.udel.edu Sat Aug 28 21:56:39 2004 From: chrisks at NOSPAM.udel.edu (Chris S.) Date: Sun, 29 Aug 2004 01:56:39 GMT Subject: Dynamic languages In-Reply-To: <98862c6.0408280531.6064d510@posting.google.com> References: <278de0e.0408271349.26762174@posting.google.com> <1093650026.763899@news.commspeed.net> <98862c6.0408280531.6064d510@posting.google.com> Message-ID: Marcel van den Dungen wrote: > "Tom B." wrote in message news:<1093650026.763899 at news.commspeed.net>... > >>I doubt that this is what they mean but a dynamic language is a language >>that is still evolving (Python) as opposed to a dead language (COBOL). >> >>They probably are referring to programs that can add and remove components >>during runtime. > > > Dynamic refers to the typing of variables. In Python variables get a > type dynamically when assigned a value. > See also: http://www.artima.com/weblogs/viewpost.jsp?thread=4639 > and several blog posting of Bruce Eckel on this subject: > http://www.mindview.net/WebLog/ Personally, I think the definition can go a little further. In Python, if you were so inclined, you could generate completely new functionality through the use of exec and eval statements. This dynamic generation, just not addition, of functionality at runtime I think is an important aspect of dynamic languages. From anthonybaxter at gmail.com Tue Aug 24 01:18:48 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Tue, 24 Aug 2004 15:18:48 +1000 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 23) In-Reply-To: References: Message-ID: On Tue, 24 Aug 2004 00:54:50 -0400, Peter Hansen wrote: > Anthony Baxter wrote: > > > (Hell, this entire discussion is now > > pretty much based on subjective or aesthetic judgements). Just to backtrack on this a _little_ - I'm talking about the block-before-def and pie-syntaxes here. There's still a bunch of others forms that are _completely_ awful on technical grounds. I really can't be bothered arguing over the "J2" vs "A1" syntaxes, though. > Excellent! If that's true, it really has reached the stage > where it's ready for the BDFL's pronouncement. Having the > slaves do all the hard work and having the BDFL only have > to weigh the subjective and aesthetic issues is probably > exactly how the process should work, and should still > result in a Python that is a consistent and coherent whole. ** Yep. That's one of the nice things about the BDFL school of language design - pointless bickering over syntax, which would otherwise not end until the universe implodes, can be handpassed to Guido. (In addition, of course, you also end up with a much better result than you would if a committee designed it) From python473 at yahoo.com Sat Aug 21 10:11:27 2004 From: python473 at yahoo.com (John Howard) Date: 21 Aug 2004 07:11:27 -0700 Subject: file access in jythonc Message-ID: <9eabe547.0408210611.d5e54f7@posting.google.com> I have the following in a jythonc program to be executed in a html file. f1 = open("filename","r") I get message about filePermission read error. Program compiles and jar file is created. Just the html code gives message. Any ideas? From PPNTWIMBXFFC at spammotel.com Wed Aug 11 11:44:14 2004 From: PPNTWIMBXFFC at spammotel.com (Marco Aschwanden) Date: Wed, 11 Aug 2004 17:44:14 +0200 Subject: Yet another decorator proposal References: <2ntvn1F4mgskU1@uni-berlin.de> Message-ID: On Wed, 11 Aug 2004 10:55:40 -0400, Christopher T King wrote: > Also, don't forget docstrings get thrown away when using python -OO. > Great voodoo would be needed to prevent this from happening. By now the compiler takes the first triple-quoted-string and sets it on the object's __doc__-var. Even in -00 mode the compiler has to find the triple-quoted-string... well on his way he can pick out the modifiers before throwing the doc string away, and set the appropiate object vars (__decorators__, __parameters__, ...). Doesn't seem too complicated to me. Magic greetings, Marco - The magician From grante at visi.com Mon Aug 30 15:51:06 2004 From: grante at visi.com (Grant Edwards) Date: 30 Aug 2004 19:51:06 GMT Subject: Size of a remote URL References: Message-ID: <4133852a$0$65574$a1866201@newsreader.visi.com> On 2004-08-30, Justin wrote: > Ok so the problem is that my code is not requesting the > headers properly. I get back. Just that. I don't know what > the difference is between the IE request and mine That's what Ethereal is for. :) -- Grant Edwards grante Yow! Let's send the at Russians defective visi.com lifestyle accessories! From tor.iver.wilhelmsen at broadpark.no Sun Aug 22 04:44:24 2004 From: tor.iver.wilhelmsen at broadpark.no (Tor Iver Wilhelmsen) Date: 22 Aug 2004 10:44:24 +0200 Subject: __metaclass__ and __author__ are already decorators References: <2opgsoFd7807U1@uni-berlin.de> <2opp6gFdg3e7U1@uni-berlin.de> Message-ID: Leif K-Brooks writes: > Which is, like I said, assigning new meaning to an old syntax. That > seems confusing to me; why not just create a new syntax? One could argue for the other way around as well: __metaclass__ et al are class variables assigned special meaning. If new syntax for decorators is important, why introduce the __metaclass__ "decorator" before the new syntax is present? From jacek.generowicz at cern.ch Wed Aug 25 03:57:59 2004 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 25 Aug 2004 09:57:59 +0200 Subject: static class methods and data members References: Message-ID: Warning: you probably don't want to bother reading all the stuff between the "==========" lines ======================================================================== nzanella at cs.mun.ca (Neil Zanella) writes: > So, unlike Python classmethods which are roughly the equivalent of > C++ static class methods, Python staticmethods really know nothing > about the members of the class that encloses them And what do C++ static methods know about the class in which they are defined? Well, they know about the class members, but have no way of acessing any of them (other than the static ones) because there is no this pointer. You do realize that even in C++ and Java there is a first parameter equivalent to Python's self ... only in C++ and Java that parameter is hidden by the surface syntax. Try looking at the code generated by the compiler for (non-static) member functions, and you'll see that the first parameter is the class instance ("this"), just like in Python ... only Python doesn't lie to you about this fact. In C++ static methods have no "this" poniter, so they have no means of accessing any instance attributes, because they have no knowledge of any paricular instance. But because it is normal in C++ to access instance attributes without explicitly specifying "this", it is temping to be fooled that struct foo { int i; static int geti() { return i; } }; int main() { foo f; f.geti(); return 0; } might compile. So, all you gain in C++ static methods is installing the function in the scope of the class .. > and act pretty much like external defs. ... just like C++ static methods. The only practical difference between C++ static methods and Python staticmethods is that in C++ you can access other _static_ methods (and static data) of the class without explicitly specifying the scope in which it is to be found: struct foo { static int i; static int geti() { return i; } // this will access foo::i }; class foo: i = 3 def sgeti(): return foo.i # In Python must explicitly give the scope sgeti = staticmethod(sgeti) def cgeti(cls): return cls.i # In Python must explicitly give the scope cgeti = classmethod(cgeti) ======================================================================== > So what's the advantage of a staticmethod over an external def? It's in a namespace which the author considers to be appropriate. Now, if you were to ask whether there is anything that can be done with staticmethods that can's be done whith classmethods ... I'd be hard pushed to imagine what sort of thing this could be. Anyone? Maybe there's a minimal efficiency consideration. > The cls first argument to a Python classmethod is analogous to the self > first argument to __init__: when you say Class.cmethod() the Class instance > is passed as the first parameter to the class method, Careful with your choice of words. The class of which the instance is an instance (yes, the actual class itself) is passed as the first parameter to the class method. (There is another interpretation of the words you wrote, which is more correct, but it's harder work to interpret your words that way :-) > and when you say instance = Class(), the instance being constructed > is passed to __init__ as self, and when you say instance.imethod(), > the instance is passed to imethod() as the first parameter, > self. The parameters cls and self are barely named so by convention: > they are not keywords in Python, unlike say the this pointer which > is a keyword in C++. > > While qualification within a class is optional in languages like C++ and > Java, in Python you must always qualify instance variables with self within > instance methods, and always qualify class variables with cls within Python > class methods. Very lucid indeed. > Since python static methods know nothing about a class, they are equivalent > to methods defined outside a class, except they may be called with the class > as the first argument (for no good reason). Some people consider organizing things in namespaces to be an extremely good reason. (Type "import this" into your Python REPL and read the last line that appears.) From rkern at ucsd.edu Wed Aug 25 15:43:54 2004 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 25 Aug 2004 14:43:54 -0500 Subject: Scipy install In-Reply-To: References: Message-ID: Maarten van Reeuwijk wrote: > I am trying to install scipy on an SGI Altix 3700 system, but I cannot > convince the distutils installer that BLAS and LAPACK are already there and > that I don't need ATLAS because everything's optimized already. I tried > modifying the site.cfg to tell where the libraries are located: > ... > [lapack] > library_dirs = /usr/local/opt/scs_beta/lib > lapack_libs = scs > > [lapack_src] > # src_dirs = .. > > [blas] > library_dirs = /usr/local/opt/scs_beta/lib > blas_libs = scs > ... > > The installer complains that it cannot locate the sources, but I only want > scipy to use the libraries. Any ideas on how to fix this? Ask on scipy-users and provide the full output from running "python setup.py", please. > TIA, Maarten -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From noone at here.com Sun Aug 22 10:11:39 2004 From: noone at here.com (M. Clift) Date: Sun, 22 Aug 2004 15:11:39 +0100 Subject: Making different things equal Message-ID: Hi All, Back again... This code works nicely giving a list of names with no name repeated at a space of 3 i.e. you won't get 'Bob','Bob' or 'Bob','Sue','Bob'. What I'd like to do is add a condition to it which says that although the names are different 'Bob' and 'Mary' are equal and so it won't generate 'Bob', 'Rita','Mary' I've tried various ways to do it, but with no joy. Any help appreciated. Thanks, M from random import * Name_Number = xrange(int(raw_input("Choose number of Names (1-20)? "))) state = [None,None] nextName = {'Bob':['Rita','Sue'],\ 'Rita':['Mary','Sue','Bob'],\ 'Sue':['Rita','Mary','Bob'],\ 'Mary':['Sue','Rita']} Name_List = [] tmp = choice(('Bob','Rita','Sue','Mary)) for x in Name_Number: print state while tmp in state[0:2]: tmp = choice(nextName[Name_List[-1]]) print tmp, ", ", print print "Name ",x+1," is ", tmp Name_List.append(tmp) state[x%2] = tmp print Name_List From ian at cottee.org Wed Aug 25 11:23:25 2004 From: ian at cottee.org (Ian J Cottee) Date: Thu, 26 Aug 2004 00:23:25 +0900 Subject: Best GUI- Python for children - pygame and blender32 In-Reply-To: References: Message-ID: Andr? Roberge wrote: > Sorry about the cryptic subject line, but I wanted to capture the > essence of my message in a single line. > > I am now at the point of writing a "chapter" on GUIs. I've written a > few sections about Tkinter but I haven't shown them to my kids yet as > I am not convinced this is the best way to go; I've read enough about > anygui, pythoncard, pyui, easygui, not to mention wxpython, etc. to > instill doubts in my mind. I can't really afford to take the time to > learn enough about all of those to make an informed decision on my > own, decision that I could regret later on. As long as the chosen > GUI is as easy as possible to learn but "complete" enough (and fast > enough as an interface?) to do fun stuff with pygame (and, possibly, > blender3d, if a separate GUI is needed), I will be satisfied. The PyGame website lists PyUI - http://pyui.sourceforge.net/ Never used it but might be worth looking at. Your kids might find Tkinter a little 'dry' for games. Ian From fperez528 at yahoo.com Thu Aug 5 18:47:40 2004 From: fperez528 at yahoo.com (Fernando Perez) Date: Thu, 05 Aug 2004 16:47:40 -0600 Subject: PEP 263 status check References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> Message-ID: "Martin v. L?wis" wrote: > I personally believe it is too early yet to make lack of > encoding declarations a syntax error. I'd like to +1 Making this an all-out failure is pretty brutal, IMHO. You could change the warning message to be more stringent about it becoming soon an error. But if someone upgrades to 2.4 because of other benefits, and some large third-party code they rely on (and which is otherwise perfectly fine with 2.4) fails catastrophically because of these warnings becoming errors, I suspect they will be very unhappy. I see the need to nudge people in the right direction, but there's no need to do it with a 10.000 Volt stick :) Best, f From grante at visi.com Mon Aug 30 17:05:27 2004 From: grante at visi.com (Grant Edwards) Date: 30 Aug 2004 21:05:27 GMT Subject: Size of a remote URL References: Message-ID: <41339697$0$65574$a1866201@newsreader.visi.com> On 2004-08-30, Justin wrote: > Ok now I have what I consider to be a very odd problem. It appears my > code will not work inside a for loop but will work outside of one. > Check it out > > temp = > urlopen("http://www.ecs.soton.ac.uk/~harnad/Temp/Ariadne-RAE.doc") > print temp > temp2 = temp.info() > print temp2 > temp3 = temp2.getheader("Content-Length") > print temp3 The above chunk of code doesn't even compile. > for y in linklisttype: > temp = urlopen(y) > print temp > temp2 = temp.info() > print temp2 > temp3 = temp2.getheader("Content-Length") > print temp3 > file_sizes.append(temp3) The above code isn't proper Python: it doesn't even compile. > THIS IS THE CODE RETURNED IN THE CONSOLE. I've *no* clue what that means. > AS YOU CAN SEE the connection closes when the code is placed > in a FOR loop. Does anybody have an understanding of why this > happens? You're going to have to post the _actual_code_you're_running_ if you want helpful responses. -- Grant Edwards grante Yow! Let me do my TRIBUTE at to FISHNET STOCKINGS... visi.com From mlh at furu.idi.ntnu.no Mon Aug 23 13:04:54 2004 From: mlh at furu.idi.ntnu.no (Magnus Lie Hetland) Date: Mon, 23 Aug 2004 17:04:54 +0000 (UTC) Subject: Standard graph API? Message-ID: Is there any interest in a (hypothetical) standard graph API (with 'graph' meaning a network, consisting of nodes and edges)? Yes, we have the standard ways of implementing graphs through (e.g.) dicts mapping nodes to neighbor-sets, but if one wants a graph that's implemented in some other way, this may not be the most convenient (or abstract) interface to emulate. It might be nice to have the kind of polymorphic freedom that one has with, e.g, with the DB-API. One could always develop factories or adaptors (such as for PyProtocols) to/from the dict-of-sets version... So, any interest? Or am I just a lone nut in wanting this? -- Magnus Lie Hetland "Canned Bread: The greatest thing since sliced http://hetland.org bread!" [from a can in Spongebob Squarepants] From Michael.J.Fromberger at Clothing.Dartmouth.EDU Wed Aug 18 17:59:08 2004 From: Michael.J.Fromberger at Clothing.Dartmouth.EDU (Michael J. Fromberger) Date: Wed, 18 Aug 2004 17:59:08 -0400 Subject: Embedding Python in Python References: Message-ID: In article , Robey Holderith wrote: > Anyone know a good way to embed python within python? >>> help(eval) ;) -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From asif at go-away-spammer.com Wed Aug 25 10:28:17 2004 From: asif at go-away-spammer.com (Player) Date: Wed, 25 Aug 2004 15:28:17 +0100 Subject: Begginer question about py install References: Message-ID: Also PyWin32 the latest version or build, will not install with the latest version of python, it requires 2.2 version of python, while the latest v of python is 2.3. :( M.B From mcfletch at rogers.com Fri Aug 20 13:34:53 2004 From: mcfletch at rogers.com (Mike C. Fletcher) Date: Fri, 20 Aug 2004 13:34:53 -0400 Subject: Toronto-area Python Users Group (PyGTA) meeting Tuesday @19:00hrs Message-ID: <4126363D.4020502@rogers.com> This month we'll be having a presentation by our own Peter Hansen regarding his use of ctypes and PySerial to create a "robot driver" (don't ask me, I just work here)... here's his summary: "CavroCom: A Brief Description of a Python-based Robot Driver for LabVIEW" This quick talk will cover the use of ctypes and PySerial to build an ActiveX/COM server interface allowing a LabVIEW program to talk to a robot via the serial port, with a brief excursion into using py2exe and InnoSetup to build the distribution. I'll bring along my own little ctypes project (wxAppBar) in case there's some extra time and people want to see ctypes going in the other direction. We'll try to make sure there's time for general questions and discussion of Pythonic news as well. As usual, we're meeting on the fourth Tuesday of the month at the Givex offices near Spadina and Adelaide (downtown). We normally go to the pool hall (the Charlotte Room) just down the street for dinner/coffee/drinks afterward. You can find all the details here: http://web.engcorp.com/pygta/wiki/NextMeeting Have fun, and hope to see you all (well, those in and around Toronto) there, Mike [ps: resending due to apparent server failure, sorry if this shows up multiple times] ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com From tonino.greco at gmail.com Tue Aug 31 05:33:06 2004 From: tonino.greco at gmail.com (tag) Date: 31 Aug 2004 02:33:06 -0700 Subject: invalid token problem ? Message-ID: <5db3bf00.0408310133.39de601c@posting.google.com> Hi, I have a xml field: ="Actual Asset mix "&text($C$46,"dd-mmm-yyyy") ^ | this is column 56 and am getting the following error: xml.sax._exceptions.SAXParseException: :21:56: not well-formed (invalid token) I have used the : self.data += saxutils.escape(characters, self.transhash) and transhash has : transhash = { '"' : '"', '&' : '&' } Can anyone please explain why I am getting the error ? What am I missing ?? THANKS :) From jmeile at hotmail.com Tue Aug 10 16:46:57 2004 From: jmeile at hotmail.com (Josef Meile) Date: Tue, 10 Aug 2004 22:46:57 +0200 Subject: Python equivalent to a C trick In-Reply-To: References: <1d7b6d0d.0408092255.1177908e@posting.google.com> Message-ID: <4119327f$1@pfaff2.ethz.ch> >>>Example: >>>printf( "you have %i %s", num_eggs, num_eggs > 1 ? "eggs" : "egg" ); >> >>print "you have %i %s" % ( num_eggs, ("egg","eggs")[num_eggs>1] ) > > > I would choose "!=" instead of ">" as the comparison operator. I think the > accepted vernacular is: > > you have -2 eggs > you have -1 eggs > you have 0 eggs > you have 1 egg > you have 2 eggs > you have 3 eggs > you have 0.5 eggs No offense intended, but the negative and float cases don't make any sense for me on this context. You can't have -2 eggs or 0.5 eggs. The last case won't occure as well because the output is being parsed to int, so, you will get "you have 0 egg", which is again false. This error happens with both solutions (with > and with !=). Regards, Josef From nmkolev at uni-bonn.de Thu Aug 5 07:42:11 2004 From: nmkolev at uni-bonn.de (Nickolay Kolev) Date: Thu, 05 Aug 2004 13:42:11 +0200 Subject: Scope Problem Message-ID: Hi all, I have set to implementing a few basic algorithms in Python serving a twofold purpose: learning the algorithms and learning Python a little better. I have however encountered a strange (for me anyway) scoping problem. Here is my implementation of linear search as a method in a class, hence all the self's (self.sequence is the sorted sequence we are searching in and value is, well, the value we are searching for): def linearSearch(self, value, index = None): if not index: index = 0 try: if self.sequence[index] == value: return index else: self.linearSearch(value, index + 1) except IndexError: return -1 My problem is that this method always returns None regardless of whether the value was found or not. If I put print statements in there, all the values and indices are printed correctly though. Actually I have another parameter to this method called debug, if this is set, the single comparison steps are printed to STDOUT (omitted above to avoid clutter). What am I doing wrong? Many thanks in advance, Nicky From skip at pobox.com Tue Aug 17 22:32:18 2004 From: skip at pobox.com (Skip Montanaro) Date: Tue, 17 Aug 2004 21:32:18 -0500 Subject: Databases: Getting values by column name In-Reply-To: References: Message-ID: <16674.49074.963073.707544@montanaro.dyndns.org> >> conn = MySQLdb.Connection(host=..., Robert> You mean MySQLdb.connect()? MySQLdb has Connect, connect and Connection, all the same function. >>> MySQLdb.Connection >>> MySQLdb.Connect >>> MySQLdb.connect >> I think the reason this sort of behavior isn't spelled out in PEP 249 >> is because it varies too much from one database to another. Psycopg >> (a PostgreSQL adaptor) does it differently. Instead of specifying >> the cursor type when the connection is created, you instantiate a >> different cursor class: >> >> conn = psycopg.connect("...") Robert> NameError: name 'psycopg' is not defined Yes, you'd have to import it. Robert> Also wouldn't that overwrite the above conn variable? >> ... >> cursor = conn.dictcursor() Robert> AttributeError: Connection instance has no attribute 'dictcursor' Like I said, psycopg is an adapter for the PostgreSQL database. MySQLdb is an adapter for the MySQL database. There are others as well. I thought showing how the two I'm most familiar with in this arena differ would be sufficient. Robert> I already know the stuff on that page, it's really slowing you Robert> down :-( I don't understand what you're referring to here. What do you mean by "slowing you down"? Skip From synesthesia at ix02x67invalid.net Tue Aug 31 06:48:53 2004 From: synesthesia at ix02x67invalid.net (Copelandia Cyanescens) Date: Tue, 31 Aug 2004 10:48:53 +0000 Subject: Size of a remote URL References: Message-ID: <14u30u5s3egcs$@x02x67invalid.net> Justin wrote... > http://www.google.com/search?hl=en&lr=&ie=UTF-8&safe=off&output=search&num=5&q=temp+filetype%3Adoc > > Go to that URL. The first two search results do not return a > Content-Length Header. Yet IE still knows how big they are somehow, I don't mean to be contrary, but yes they do. So says the almighty Ethereal... Content-Length: 632832 Content-Length: 30720 Respectively, for the two links you suggested. -- Ask a Soviet engineer to design a pair of shoes and he'll come up with something that looks like the boxes that the shoes came in; ask him to make something that will massacre Germans, and he turns into Thomas *Fscking* Edison. -- Neal Stephenson, Cryptonomicon From joshway_without_spam at myway.com Wed Aug 18 16:25:04 2004 From: joshway_without_spam at myway.com (JCM) Date: Wed, 18 Aug 2004 20:25:04 +0000 (UTC) Subject: Embedding Python in Python References: <7xu0v0l2be.fsf@ruckus.brouhaha.com> <7x3c2kkzn8.fsf@ruckus.brouhaha.com> Message-ID: Jack Diederich wrote: > On Wed, Aug 18, 2004 at 07:44:47PM +0000, JCM wrote: ... >> I don't think it's as difficult as you think. Your snippet of code >> would be rejected by the rules I suggested. You'd also want to >> prohibit other builtins like compile, execfile, input, reload, vars, >> etc. >> > foo = "ev" + "al" > e = vars()['__builtins__'].__dict__[foo] > print e('2+2') Also would be rejected by my original set of rules (can't use __dict__). But I'd disallow vars too. From eddie at holyrood.ed.ac.uk Wed Aug 4 06:35:46 2004 From: eddie at holyrood.ed.ac.uk (Eddie Corns) Date: Wed, 4 Aug 2004 10:35:46 +0000 (UTC) Subject: Telnet session References: Message-ID: "Yannick Turgeon" writes: >Hello all, I don't see anything obviously wrong in the structure, a simpleminded translation to linux worked as expected even with a command to generate a recursive directory listing which, on my machine, is huge. What happens if set REMOVEJUNK to False?, I had to do that to see any output but I don't know what Windows generates. I guess what you're trying to filter out is ANSI control sequences but I suspect you may not have that right and you're removing ALL output. A minor point, you only need to do the re.compile once, moving it outside the function would be more efficient. Eddie From dd55 at cornell.edu Wed Aug 18 18:51:51 2004 From: dd55 at cornell.edu (Darren Dale) Date: Wed, 18 Aug 2004 18:51:51 -0400 Subject: cant install from source on MSWindows Message-ID: I'm getting the old "need visual studio 6" error message. I have seen advice to download the free compiler, I tried that and it didnt work. I have an academic copy of VS.net, tried installing that, and still no dice. Can somebody tell me how they have been able to get this working? I would like to start contributing to my favorite plotting package, but this is really tripping me up. Thanks, Darren From nospam at nospam.com Tue Aug 17 10:44:14 2004 From: nospam at nospam.com (Rufus V. Smith) Date: Tue, 17 Aug 2004 10:44:14 -0400 Subject: Best programming language References: <873c2ndizt.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> Message-ID: "Peter Otten" <__peter__ at web.de> wrote in message news:cfsu0q$ls1$06$1 at news.t-online.com... > Andrew Durdin wrote: > > > On Tue, 17 Aug 2004 13:35:26 +0200, lopex wrote: > >> 510046470588-0001 at t-online.de wrote: > >> > > >> > the best language is of course Scheme > >> > >> Another flamewar ? > >> should I claim Ruby is.. ? > > > > The obvious answer, of course, is that on the newsgroup/mailing list > > for language X, define "best programming language" to be X. It saves a > > lot of combustion :) > > http://dmoz.org/Computers/Programming/Languages/ > > suggests that between Befunge and BETA there is space for "Best" waiting to > be filled by an audacious developer. Good name for Python 3.0, maybe... > I've already seen Best Computers. Is there a www.thebestwebsite.com? The answer is left as an exercise for the reader. Rufus The Best Programming language, geez. Shortly followed by The Worst Programming Language, Or how about : The Absolute Worst Programming Language or TAWPL (for the non-english natives - rhymes with TOPPLE, which is what happens when you write in it). From david at guenthners.com Sat Aug 14 01:09:02 2004 From: david at guenthners.com (Dave Guenthner) Date: 13 Aug 2004 22:09:02 -0700 Subject: Py2exe Question - Deployment Advice Message-ID: I wrote my first Python script today and was very impressed at how concise the code was and development time. In addition, I am using the latest stable version of Python from ActiveState.com. Anyway, when I compiled my file to an exectuable I was horrified to see a "dist" folder with all kinds of co-reqs etc that had to be distributed in order for the program to run. For Perl, I used the Perl2exe product and I was simply given one file .exe to distribute. Has anyone one else run into this before / experienced that. Is there a way to have just one file? Enterprise Environment All Windows desktop / servers w/out Python language installed My Goal: Evaluating Python and in addition trying to keep potential pitfalls as simple and concise as possible concerning deployment and support. Thanks in advance to all you guru's. Dave From h.b.furuseth at usit.uio.no Sat Aug 7 19:05:07 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 08 Aug 2004 01:05:07 +0200 Subject: PEP 263 status check References: <10h58umglolefb8@news.supernews.com> <4112AB53.6010701@v.loewis.de> <10h5hgvpafm8a64@news.supernews.com> <41133C76.8040302@v.loewis.de> <10h6rklt3fa1690@news.supernews.com> <41137799.70808@v.loewis.de> <10h724r20kkeqb2@news.supernews.com> <10h7u8m9qknh76e@news.supernews.com> Message-ID: John Roth wrote: >"Hallvard B Furuseth" wrote in message >news:HBF.20040806qchc at bombur.uio.no... >>An addition to Martin's reply: >>John Roth wrote: >>>"Martin v. L?wis" wrote in message >>>news:41137799.70808 at v.loewis.de... >>>> >>>> To be more specific: In an UTF-8 source file, doing >>>> >>>> print "?" == "\xc3\xb6" >>>> print "?"[0] == "\xc3" >>>> >>>> would print two times "True", and len("?") is 2. >>>> OTOH, len(u"?")==1. >>> >>> (...) >>> I'd expect that the compiler would reject anything that >>> wasn't either in the 7-bit ascii subset, or else defined >>> with a hex escape. >> >> Then you should also expect a lot of people to move to >> another language - one whose designers live in the real >> world instead of your Utopian Unicode world. > > Rudeness objection to your characteization. Sorry, I guess that was a bit over the top. I've just gotten so fed up with bad charset handling, including over-standardization, over the years. And as you point out, I misunderstood the scope of your suggestion. But you have been saying that people should always use Unicode, and things like that. > Please see my response to Martin - I'm talking only, > and I repeat ONLY, about scripts that explicitly > say they are encoded in utf-8. Nothing else. I've > been in this business for close to 40 years, and I'm > quite well aware of backwards compatibility issues > and issues with breaking existing code. > > Programmers in general have a very strong, and > let me repeat that, VERY STRONG assumption > that an 8-bit string contains one byte per character > unless there is a good reason to believe otherwise. Often true in our part of the world. However, another VERY STRONG assumption is that if we feed the computer a raw character string and ensure that it doesn't do any fancy charset handling, the program won't mess with the string and things will Just Work. Well, except that programs that strip the 8. bit is a problem. While there is no longer any telling what a program will do if it gets the idea that it can be helpful about the character set. The biggest problem with labeling anything as Unicode may be that it will have to be converted back before it is output, but the program often does not know which character set to convert it to. It might not be running on a system where "the charset" is available in some standard location. It might not be able to tell from the name of the locale. In any case, the desired output charset might not be the same as that of the current locale. So the program (or some module it is using) can decide to guess, which can give very bad results, or it can fail, which is no fun either. Or the programmer can set a default charset, even though he does not know that the user will be using this charset. Or the program can refuse to run unless the user configures the charset, which is often nonsense. The rest of my reply to that grew to a rather large rant with very little relevance to PEP 263, so I moved it to the end of this message. Anyway, the fact remains that in quite a number of situations, the simplest way to do charset handling is to keep various programs firmly away from charset issues. If a program does not know which charset is in use, the best way is to not do any charset handling. In the case of Python strings, that means 'str' literals instead of u'Unicode' literals. Then the worst that can happen if the program is run with an unexpected charset/encoding is that the strings built into the program will not be displayed correctly. It would be nice to have a machinery to tag all strings, I/O channels and so on with their charset/encoding and with what to do if a string cannot be converted to that encoding, but lacking that (or lacking knowledge of how to tag some data), no charset handling will remain better than guesstimate charset handling in some situations. > This assumption is built into various places, including > all of the string methods. I don't agree with that, but maybe it's a matter of how we view function and type names, or something. > The current design allows accidental inclusion of > a character that is not in the 7bit ascii subset ***IN > A PROGRAM THAT HAS A UTF-8 CHARACTER > ENCODING DECLARATION*** to break that > assumption without any kind of notice. That in > turn will break all of the assumptions that the string > module and string methods are based on. That in > turn is likely to break lots of existing modules and > cause a lot of debugging time that could be avoided > by proper design. For programs that think they work with Unicode strings, yes. For programs that have no charset opinion, quite the opposite is true. >> And tell me why I shouldn't be allowed to work easily with raw >> UTF-8 strings, if I do use coding:utf-8. > > First, there's nothing that's stopping you. All that > my proposal will do is require you to do a one > time conversion of any strings you put in the > program as literals. It doesn't affect any other > strings in any other way at any other time. It is not a one-time conversion if it's inside a loop or a small function which is called many times. It would have to be moved out to a global variable or something, which makes the program a lot more cumbersome. Second, any time one has to write more complex expressions to achieve something, it becomes easier to introduce bugs. In particular when people's solution will sometimes be to write '\xc3\xb8' instead of '?' and add a comment with the real string. If the comment is wrong, which happens, the bug may survive for a long time. > I'll withdraw my objection if you can seriously > assure me that working with raw utf-8 in > 8-bit character string literals is what most programmers > are going to do most of the time. Of course it isn't. Nor is working with a lot of other Python features. > I'm not going to accept the very common need > of converting unicode strings to 8-bit strings so > they can be written to disk or stored in a data base > or whatnot (or reversing the conversion for reading.) That's your choice, of course. It's not mine. > That has nothing to do with the current issue - it's > something that everyone who deals with unicode > needs to do, regardless of the encoding of the > source program. I'm not not even sure which issue is the 'current issue', if it makes that irrelevant. ======== I've been a programmer for about 20 years, and for most of that time the solution to charset issues in my environment (Tops-20, Unix, no multi-cultural issues) has been for the user to take care of the matter. At first, the computer thought it was using ASCII, we were using terminals and printers with NS_4551-1 - not that I knew a name for it - and that was that. (NS_4551-1 is ASCII with [\]{|} replaced with ??????.) If we wanted to print an ASCII file, there might be a switch to get an ASCII font, we might have an ASCII printer/terminal, or we just learned to read ??? as [\] and vice versa. A C program which should output a Norwegian string would use [\\] as ??? - or the other way around, depending on how one displayed the program. Then some programs began to become charset-aware, but they "knew" that we were using ASCII, and began to e.g. label everyone's e-mail messages with "X-Charset: ASCII" or something. So such labels came in practice to mean 'any character set'. The solution was to ignore that label and get on with life. Maybe a program had to be tweaked a bit to achieve that, but usually not. And it might or might not be possible to configure a program to label things correctly, but since everyone ignored the label anyway, who cared? Then 8-bit character sets and MIME arrived, and the same thing happened again: 'Content-Type: text/plain; charset=iso-8859-1' came to mean 'any character set or encoding'. After all, programmers knew that this was the charset everyone was using if they were not using ASCII. This time it couldn't even be blamed on poor programmers: If I remember correctly, MIME says the default character set is ASCII, so programs _have_ to label 8-bit messages with a charset even if they have no idea which charset is in use. Programs can make the charset configurable, of course, but most users didn't know or care about such things, so that was really no help. Fortunately, most programs just displayed the raw bytes and ignored the charset, so it was easy to stay with the old solution of ignoring charset labels and get on with life. Same with e.g. the X window system: Parts of it (cut&paste buffers? Don't remember) was defined to work with latin-1, but NS_4551-1 fonts worked just fine. Of course, if we pasted ??? from an NS_4551-1 window to a latin-1 window we got {|}, but that's was what we had learned to expect anyway. I don't remember if one had to to some tweaking to convince X not to get clever, but I think not. Locales arrived too, and they might be helpful - except several implementations were so buggy that programs crashed or misbehaved if one turned them on. Also, it might or might not be possible to deduce which character set was in use from the names of the locales. So, on many machines, ignore them and move on. Then UTF-8 arrived, and things got messy. We actually begun to need to deal with different encodings as well as character sets. UTF-8 texts labeled as iso-8859-1 (these still occur once in a while) have to be decoded, it's not enough to switch the window's font if the charset is wrong. Programs expecting UTF-8 would get a parse error on iso-8859-1 input, it was not enough to change font. There is a Linux box I'm sometimes doing remote logins to which I can't figure out how to display non-ASCII characters. It insist that my I'm using UTF-8. My X.11 font is latin-1. I can turn off the locale settings, but then 8-bit characters are not displayed at all. I'm sure there is some way to fix that, but I haven't bothered to find out. I didn't need to dig around in manuals to find out that sort of thing before. I remember we had 3 LDAPv2 servers running for a while - one with UTF-8, one with iso-8859-1, and one with T.61, which is the character set which the LDAPv2 standard actually specified. Unless the third server used NS_4551-1; I don't remember. I've mentioned elsewhere that I had to downgrade Perl5.8 to a Unicode- unaware version when my programs crashed. There was a feature to turn off Unicode, but it didn't work. It seems to work in later versions. Maybe it's even bug-free this time. I'm not planning to find out, since we can't risk that these programs produce wrong output. And don't get me started on Emacs MULE, a charset solution so poor that from what I hear even Microsoft began to abandon it a decade earlier (code pages). For a while the --unibyte helped, but after a while that got icky. Oh well, most of the MULE bugs seem to be gone now, after - is it 5 years? The C language recently got both 8-bit characters and Unicode tokens and literals (\unnnn). As far as I can tell, what it didn't get was any provision for compilers and linkers which don't know which character set is in use and therefore can't know which native character should be translated to which Unicode character or vice versa. So my guess is that compilers will just pick a character set which seems likely if they aren't told. Or use the locale, which may have nothing at all to do with which character set the program source code is using. I may be wrong there, though; I only remember some of the discussions on comp.std.c, I haven't checked the final standard. Of course, there are a lot of good sides to the story too - even locales got cleaned up a lot, for example. And you'd get a very different story from people in different environments (e.g. multi-cultural ones) or with different operating systems even in Norway, but you already know that. -- Hallvard From dody at postaccesslite.com Thu Aug 26 06:57:05 2004 From: dody at postaccesslite.com (dody) Date: Thu, 26 Aug 2004 17:57:05 +0700 Subject: ASPN Python cookbook in a chm + new updates In-Reply-To: References: Message-ID: <1434943440.20040826175705@postaccesslite.com> > Very cool! Thx for the support, here come another updates (26 Aug 2004) which fixed the double spacing in codes, and even throwing in the discussion and full comments, raising the filesize to 2.5 megs. http://miaw.tcom.ou.edu/~dody/aspnpython-2004-08-26.chm -- dody suria wijaya From paolo.veronelli at yahoo.it Fri Aug 20 08:52:50 2004 From: paolo.veronelli at yahoo.it (Paolino) Date: Fri, 20 Aug 2004 14:52:50 +0200 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: <4125F422.70000@yahoo.it> d2 d2 j2 Thanks for the piece of democracy From fumanchu at amor.org Mon Aug 23 17:59:56 2004 From: fumanchu at amor.org (Robert Brewer) Date: Mon, 23 Aug 2004 14:59:56 -0700 Subject: J2 paper 0.2.1 Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E47@exchange.hqamor.amorhq.net> Shalabh Chaturvedi wrote: > 3. Nitpick. Since you are selling to GvR, it might be > nice to spell > his name correctly in the code examples :) Use lowercase 'v' > in van when > writing the full name. Thanks! > III Choosing a keyword: > > 1. "Reads correctly" but only if you know that 'using' > preceeds the definition. By "reads correctly" I mean it's rough English. Given the following from PEP 8, I think I'll treat the run-on case as one we can ignore: "Separate top-level function and class definitions with two blank lines. Method definitions inside a class are separated by a single blank line." > 2. "Should be easy to search for, in both docs and Google." > Hmm, 'Python using' is more likely to show irrelevant results > than, say, 'Python predef'. True. I should probably say something about priorities. The Lang Ref should index the word "using", which fixes half the problem. > 3. Because of above I'd favour the 'predef' keyword. It > has almost > all the advantages you list for 'using', and a few more. I expect to add another paragraph or two based on alternate keywords which people support (vocally *and* technically). I would say all of the "*def" candidates could work. In the interest of generating more content for that paragraph ;) here's the devil's advocate view of predef: 1) It's not a word. But then "def" isn't either. 2) If it is a word, it's a verb. Dependent suite keywords tend to be adverbial. Perhaps there's a more adverbial word which means, "set up these items for later processing". Unfortunately for English, this form of "predef" would be "predefining". Some synonym of "prepare", perhaps? I'll think about it some more. > I don't mind the @ syntax at all, but I'll consider signing > the proposal > as an alternative since I now think it to be at least as > good. Perhaps > only if you change the keyword . Great! Thanks for your comments. Robert Brewer MIS Amor Ministries fumanchu at amor.org From pm_mon at yahoo.com Tue Aug 17 14:38:24 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Tue, 17 Aug 2004 14:38:24 -0400 Subject: Is it possible to write a DLL using python In-Reply-To: References: Message-ID: AMD wrote: > Hi, > > I need to write a Win32 DLL and I would like to use Python instead of > VB, C++ or Delphi. Is this possible? > > Thank you, > > Andre M. Descombes The new version of py2exe (http://starship.python.net/crew/theller/py2exe/) supposedly allows the creation of dll com servers if that's of interest to you. From jjl at pobox.com Sat Aug 28 13:27:07 2004 From: jjl at pobox.com (John J. Lee) Date: 28 Aug 2004 18:27:07 +0100 Subject: cookie References: <87fz68v1uj.fsf@pobox.com> Message-ID: <877jrj5g2c.fsf@pobox.com> Ajay writes: [...] > i believe you. i didn't think it would make a difference. and i agree that > the Cookie module preserves quotes across the parse->output cycle > my question is > >>> import Cookie > >>> c = Cookie.SimpleCookie() > >>> c["test"]= "blah" > >>> print c > Set-Cookie: test=blah; > >>> c["test"] = "blah" + "testing" > >>> print c > Set-Cookie: test=blahtesting; > >>> str = "testing blah" > >>> c["test"] = str > >>> print c > Set-Cookie: test="testing blah"; > > why does the final print statement have the quotes. Note i haven't put > str='"testing blah"'. if i had done that i would understand the quotes > there. Does the following help? Python 2.4a2 (#5, Aug 5 2004, 22:07:01) [GCC 2.95.4 20011002 (Debian prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import Cookie >>> c = Cookie.SimpleCookie() >>> c["test"] = "testingblah" >>> print c Set-Cookie: test=testingblah; >>> c["test"] = "testing blah" >>> print c Set-Cookie: test="testing blah"; >>> John From ben at benlast.com Thu Aug 19 15:40:00 2004 From: ben at benlast.com (Ben Last) Date: Thu, 19 Aug 2004 20:40:00 +0100 Subject: Alternative decorator syntax decision In-Reply-To: Message-ID: > I would propose a multivote survey: each poster gets 3 votes among the > lettered choices on the Wiki page above. You can use all 3 for a single > option, or split them across 2 or 3 options if you are open to more than > one. My vote: D1 C3 C1 ben From npat at efault.net Thu Aug 12 21:11:54 2004 From: npat at efault.net (Nick Patavalis) Date: Fri, 13 Aug 2004 01:11:54 +0000 (UTC) Subject: Why I love python. References: Message-ID: On 2004-08-13, Michael Scarlett wrote: > There is an amazing article by paul graham about python, and an even > better discussion about it on slashdot. Yes, the article is very good > Don't complicate it. Leave it as is. Work on making it faster, not > uglier. Python needs drastic performance improvement if it is to scrap-off the "scripting language" stigma. The only way to get these improvements is making it possible for a python implementation to produce *efficient* *compiled* code. At the same time the dynamic-typing nature of the language is one of its most valuable characteristics. And this is one of the hardest problems when trying to write a decent python compiler. If you define a function like: def sum (a, b): return a + b How can the compiler know what code to produce? It could trace all the applications of sum(), and decide what types of arguments sum() is actually applied on. But this is not easy, and sometimes it is straight-out impossible. A different approach would be for the programmer to *suggest* what kind of types the function will *most probably* be applied on. The programmer might suggest to the compiler that "a" and "b" will *most probably* be integers or floats, so the compiler will have to produce code for a function that handles these cases (or code for two "functions", one for each case). One might say that the function could be "decorated" by the programmer regarding the type of its arguments. Notice that in such a case the decoration does not alter the behavior of the function in any way! The function can still be called with string arguments, in which case execution will be dispatched to an "interpreted" version thereof. So I believe is that "making it faster" requires some fundamental work, and not simply devising "better algorithms for some modules". Better algorithms for some modules will give you something like point-something improvement in performance. Being able to produce efficient compiled code will give you improvement between a factor of 10 and an order of magnitude (depending on the type of the program). The same it true for "making it more secure" (e.g by providing the programmer a way to specify what types of arguments are *allowed* to be passed to a function). In general, python must break free from its perl-ish adolescence (language for small things, which doesn't have to be very fast or very safe), but without loosing its agility. Decorators might be a step in the right direction, or at least they might allow some experimentation with such matters. Because of this they are welcome. Just my 2c /npat From Scott.Daniels at Acm.Org Wed Aug 4 13:15:00 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 04 Aug 2004 10:15:00 -0700 Subject: file IO In-Reply-To: References: Message-ID: <41111cc5$1@nntp0.pdx.net> Darren Dale wrote: You might want to look at using ilines on your mmap'ed file's data. This will give you access to building a universal newline generator from a 'block-o-characters' generator. -- -Scott David Daniels Scott.Daniels at Acm.Org From michaels at rd.bbc.co.uk Thu Aug 12 09:46:13 2004 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Thu, 12 Aug 2004 14:46:13 +0100 Subject: [Implementation] (first attempt) Re: A decorator syntax not yet mentioned (I think!) References: <60dfb6f6.0408111846.615ee9eb@posting.google.com> <3YWdnYxLf--ObofcRVn-pw@powergate.ca> Message-ID: Michael Sparks wrote: >> Regarding J2 on http://www.python.org/moin/PythonDecorators ... >> ... >>> 5 Technical problems with the current grammar parser if a suite >>> *starts* with an optional part. (Ending with an optional part, >>> such as "else:" is OK, but starting with one is not.) >> ... >>> Item 6 is always the case for any new feature, so I doubt that's the >>> real problem - the real problem here strikes me as item 5. >>> >>> I do wonder how difficult it would be to add though... I've implemented this now, and I have this (kinda*) working. I've patched the 2.4a2 release from python.org and made the following changes. * Kinda - there's something wrong with my implementation due to scoping, and since I only first looked at the python source for the first time 4-5 hours ago, I think this is progress :) I changed the grammar to allow syntax J2: --- Python-2.4a2/Grammar/Grammar 2004-08-02 07:09:53.000000000 +0100 +++ Python-2.4a2-MS/Grammar/Grammar 2004-08-12 13:21:16.577978408 +0100 @@ -30,5 +30,5 @@ -decorator: '@' dotted_name [ '(' [arglist] ')' ] +decorator: dotted_name [ '(' [arglist] ')' ] decorators: decorator ([NEWLINE] decorator)* NEWLINE -funcdef: [decorators] 'def' NAME parameters ':' suite +funcdef: ['decorate' ':' NEWLINE INDENT decorators DEDENT ] 'def' NAME parameters ':' suite parameters: '(' [varargslist] ')' I then modified comple.c to make this syntax usable: --- Python-2.4a2/Python/compile.c 2004-08-04 11:26:08.000000000 +0100 +++ Python-2.4a2-MS/Python/compile.c 2004-08-12 14:24:50.537168480 +0100 @@ -4045,12 +4045,12 @@ int nch = NCH(n); - assert(nch >= 2); - REQ(CHILD(n, 0), AT); - com_decorator_name(c, CHILD(n, 1)); + assert(nch >= 1); + com_decorator_name(c, CHILD(n, 0)); if (nch > 2) { - assert(nch == 4 || nch == 5); - REQ(CHILD(n, 2), LPAR); + assert(nch == 3 || nch == 4); + REQ(CHILD(n, 1), LPAR); REQ(CHILD(n, nch - 1), RPAR); - com_call_function(c, CHILD(n, 3)); + com_call_function(c, CHILD(n, 2)); } + } @@ -4085,7 +4085,7 @@ REQ(n, funcdef); - /* -6 -5 -4 -3 -2 -1 - funcdef: [decorators] 'def' NAME parameters ':' suite */ - - if (NCH(n) == 6) - ndecorators = com_decorators(c, CHILD(n, 0)); + /* -7 -6 -5 -4 -3 -2 -1 + funcdef: ['decorate' ':' NEWLINE INDENT decorators DEDENT ] 'def' NAME parameters ':' suite */ + + if (NCH(n) == 11) + ndecorators = com_decorators(c, CHILD(n, 4)); else @@ -5825,5 +5825,5 @@ if (TYPE(n) == decorator) { - /* decorator: '@' dotted_name [ '(' [arglist] ')' ] */ + /* decorator: dotted_name [ '(' [arglist] ')' ] */ node *name, *varname; - name = CHILD(n, 1); + name = CHILD(n, 0); REQ(name, dotted_name); ==================================== The one sting in this, which I haven't figured out is that the decorate keyword and indentation appear to knock the scoping for six (which I suspect/hope would be simple to solve) so for *this* implementation you need to do something like: ========================= class Foo: staticmethod # This is cruft to force staticmethod into scope decorate: staticmethod def hello(who): print "woo?", who Foo.hello("HOO") ========================= If you miss out the cruft above, python can't (with the above small change) find the right scope for "staticmethod". I suspect that someone with more experience with the source tree would be able to remove the cruft line above and allow the scope to be searched correctly. Either way, the argument on http://www.python.org/moin/PythonDecorators regarding J2 not having an implementation just (80%) disappeared :) Should I forward this to the dev list? Michael. -- Michael.Sparks at rd.bbc.co.uk British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From mizrandir at hotmail.com Sun Aug 15 05:11:57 2004 From: mizrandir at hotmail.com (Mizrandir) Date: 15 Aug 2004 02:11:57 -0700 Subject: Subclassing numarray's arrays References: <7pxTc.44307$Mq1.2286665@news20.bellglobal.com> Message-ID: First of all, thanks for helping. > Numarray wasn't designed with subclassing in mind, but there are > workarounds for most problems. On numarray's website there is a paper by the Numarray authors saying: "... The new approach allows arrays to be subclassed as well as ...", so I thought it should be something easy to do. Anyway, I hadn't read anything about numarraycore, is it explained anywhere. For example, I don't understand what the statement "self.__setstate__(arr.__getstate__())" does. > You might try something like: > import numarray.numarraycore as _num > class NewClass(_num.NumArray): > def __init__(self, n, a): > ''' n provides the length of each dimension, > a is the constant value to be plugged. > ''' > arr= _num.array(sequence= n * n * [a], shape= (n, n)) > self.__setstate__(arr.__getstate__()) > > def __repr__(self): > " Return printable representation of instance." > className= self.__class__.__name__ > className= className.zfill(5).replace('0', ' ') > arr= self.copy() > arr.__class__= _num.NumArray > rep= className + _num.NumArray.__repr__(arr)[5:] > return rep > > def __str__(self): > " Return a pretty printed string of the instance." > stri= self.copy() > stri.__class__= _num.NumArray > return _num.NumArray.__str__(stri) > > > if __name__ == '__main__': > a= NewClass(2, 2) > print a > b= NewClass(3, 4) > print `b` miz. From pm_mon at yahoo.com Tue Aug 24 23:38:28 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Tue, 24 Aug 2004 23:38:28 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: Message-ID: <412C09B4.5070106@yahoo.com> Steven Bethard wrote: > Paul Morrow yahoo.com> writes: > >>...that they warrant an entirely new syntax? > > [snip] > >>So why don't they share a similar syntax? >> >> class Foo: >> """ This is the docstring for class Foo. """ >> __metaclass__ = M >> # body of class goes here >> >> >> def baz(): >> """ This is the docstring for function baz. """ >> __features__ = synchronized, memoized >> # body of function goes here. > > > As I'm sure someone has already mentioned, this has been brought up before. > I'd especially look at: > > http://mail.python.org/pipermail/python-dev/2004-August/048176.html > Well, what I proposed there is more substantial than this, and requires a more significant change to the Python system to accomodate. > That being said, I think the main objection to this syntax is the same > objection to any inside-def syntax: The code inside a funcdef block (with the > exception of docstrings, which Guido has repeatedly said he regrets putting > there) is executed as part of the /execution/ of the function, not > the /definition/. > Yes, but we have the docstring precendent nonetheless. And I think that Guido should stop regretting that decision and start recognizing the natural beauty of it. To allow docstrings at the top of module/class bodies, but not at the top of function/method bodies would be asymmetrical, and we'd wonder why. Any alternative means of providing docstrings for methods/functions would look like a wart (IMO). Especially since the obvious place for them would still be there. So, no, I for one like docstrings right where they are. And look at what they create a precedent for. When Python executes a def statement, it binds __doc__ to the docstring it finds there. But what is __doc__? It's an attribute of the method or function object being defined. Yep. Its metadata. It's information *about* the method/function. __doc__ is *not* a local variable of the method or function object being defined. I believe that (virtually) all __xxx__ attributes have this metadata aspect (semantics) to them. When a programmer says def foo(): __author__ = 'Wilma Flintstone' __version__ = '0.1' She does not intend for __author__ nor __version__ to be local variables of foo, used somehow by foo in the calculation of its return value. To her they are foo /metadata/ --- attributes of the foo object itself --- as they contain information that *describes* foo. Likewise, when she defines __lt__, __getitem__, __init__, etc. as part of a class, they will not typically be called by methods of the class or users/consumers/clients of the class [*] the way that 'normal' attributes will. They contain meta info that describes a deeper level of class behavior. And so if all __xxx__ attributes are really metadata attributes, let's formally recognize that. Then, when processing a function/method def, after Python binds __doc__ to the function's docstring, it can go ahead and bind the other __xxx__ attributes too, making them function attributes rather than local variables. And then after it's finished with the function def, if the function defined the __features__ attribute, Python can pass the completed function in turn to each decorator in the __features__ tuple (or some such). No asymmetry. No new syntax. No warts. * well, __init__ is a little odd in this respect as subclasses will sometimes call a parent's __init__ directly, but that's an exception. Paul From eurleif at ecritters.biz Sat Aug 7 18:40:04 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sat, 07 Aug 2004 18:40:04 -0400 Subject: Image manipulation library under a GPL-compatible license? In-Reply-To: <2nl3suF1vntdU1@uni-berlin.de> References: <2nl3suF1vntdU1@uni-berlin.de> Message-ID: <2nl3u4F1vntdU2@uni-berlin.de> Leif K-Brooks wrote: > Is there another library under a friendlier library? Er, that final "library" should read "license". I should get more sleep. From amk at amk.ca Mon Aug 30 14:02:14 2004 From: amk at amk.ca (A.M. Kuchling) Date: Mon, 30 Aug 2004 13:02:14 -0500 Subject: PHP Documentation References: <4133124f$0$281$4d4ebb8e@news.nl.uu.net> Message-ID: On Mon, 30 Aug 2004 12:48:13 -0400, > Wikis can be useful for maintaining documentation, but so far > I've seen it succeed only in very limited instances, and in this > case without top level support (e.g. recognition by the official > doc maintainers that this is now the master copy) I really doubt > it will get far. Feel free, anyone, to prove me wrong. I can't see the Wiki version ever becoming the master copy; Wiki markup is much less detailed than the LaTeX macros, e.g. in the Wiki you can only put things in ``code-style``, but in the LaTeX you have \member{} and \constant{} and \keyword{} and many other different shades of meaning. It probably wouldn't be difficult to take the HTML rendering of the docs and automatically import them into an empty Wiki instance that could then be updated. Will anyone volunteer to do this? --amk From adurdin at gmail.com Tue Aug 10 03:05:55 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Tue, 10 Aug 2004 17:05:55 +1000 Subject: Decorators In-Reply-To: <3GURc.11274$Mq1.610387@news20.bellglobal.com> References: <%A8Rc.50217$Vm1.1280580@news20.bellglobal.com> <10hfoqa9cj3e356@corp.supernews.com> <3GURc.11274$Mq1.610387@news20.bellglobal.com> Message-ID: <59e9fd3a0408100005305dfc63@mail.gmail.com> On Mon, 09 Aug 2004 20:29:59 -0400, Colin J. Williams wrote: > > There is also the question of whether 'decorator', a term which is used > in everyday langage as indicating adornment, is the best choice for a > transformation. def deco(f): print f.__name__, "is now pretty!" return f @deco def ugly_function(): pass From wweston at att.net Mon Aug 23 16:29:44 2004 From: wweston at att.net (wes weston) Date: Mon, 23 Aug 2004 20:29:44 GMT Subject: Standard graph API? In-Reply-To: References: Message-ID: Magnus Lie Hetland wrote: > Is there any interest in a (hypothetical) standard graph API (with > 'graph' meaning a network, consisting of nodes and edges)? Yes, we > have the standard ways of implementing graphs through (e.g.) dicts > mapping nodes to neighbor-sets, but if one wants a graph that's > implemented in some other way, this may not be the most convenient (or > abstract) interface to emulate. It might be nice to have the kind of > polymorphic freedom that one has with, e.g, with the DB-API. One could > always develop factories or adaptors (such as for PyProtocols) to/from > the dict-of-sets version... > > So, any interest? Or am I just a lone nut in wanting this? > Magnus, Do you have any design thoughts. It would be good to have weighted, directed graphs and depth first traversal. wes From rpw3 at rpw3.org Tue Aug 31 22:36:14 2004 From: rpw3 at rpw3.org (Rob Warnock) Date: Tue, 31 Aug 2004 21:36:14 -0500 Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <%T%Yc.29567$Es2.11957889@news4.srv.hcvlny.cv.net> <4134a207$0$65568$a1866201@newsreader.visi.com> Message-ID: Craig A. Finseth wrote: +--------------- | Ville Vainio wrote: | >... and / as path separator still screws up most of their cmd line | >programs (which think / is for command line options). | >Microsoft probably thought avoiding compatibility is a good idea, and | >have only lately started to have some regrets... | | Wrong. The / was chosen as the command line option separator because | whoever wrote MSDOS was looking to CP/M, who modelled their commands | after a PDP-11 operating system (RT-11?). +--------------- Which, like PS/8 & OS-8 [and "DECsystem-8" from Geordia Tech] for the PDP-8, modelled the command syntax after that of the venerable PDP-10!! +--------------- | Consider the "PIP" command. +--------------- Indeed. And COPY & DEL & DIR, etc. -Rob ----- Rob Warnock 627 26th Avenue San Mateo, CA 94403 (650)572-2607 From FBatista at uniFON.com.ar Wed Aug 25 14:12:57 2004 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Wed, 25 Aug 2004 15:12:57 -0300 Subject: Am I on the right path Message-ID: [ADE] #- The program is supposed to randomly choose an ip address and #- try and make a #- conection on port 80 You can generate random IP like this, also: >>> import random >>> '.'.join([str(random.randint(0,255)) for x in range(4)]) '168.240.211.252' >>> '.'.join([str(random.randint(0,255)) for x in range(4)]) '161.236.51.72' >>> '.'.join([str(random.randint(0,255)) for x in range(4)]) '160.93.77.108' >>> '.'.join([str(random.randint(0,255)) for x in range(4)]) '4.109.242.174' >>> '.'.join([str(random.randint(0,255)) for x in range(4)]) '227.21.50.119' . Facundo From cjw at sympatico.ca Sat Aug 7 13:47:45 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Sat, 07 Aug 2004 13:47:45 -0400 Subject: Decorators Message-ID: <%A8Rc.50217$Vm1.1280580@news20.bellglobal.com> Christopher T. King suggested that "we're trying to kill too many birds with one stone". http://groups.google.com/groups?q=stone+birds+group:comp.lang.python&hl=en&lr=&ie=UTF-8&selm=Pine.LNX.4.44.0408050856390.31290-100000%40ccc9.wpi.edu&rnum=1 He goes on to suggest three needs which decorators serve. Are these the only purposes which are envisaged for decorators? Most of the discussion has focused on syntax. I would like to see some clarification of the purpose and meaning of a decoration. The latest version of PEP 318 has a Motivation section which talks of transforming a method or function. The possible purposes of the transformation is not so clear. The use of the term decorator is questionable. In everyday usage, to decorate is to furnish with adornments. In this sense, we could say that a docstring is a decorator, but is that true of a transformation. It seems desirable that we choose words which are as close as possible to their everyday usage. Example 4 in the PEP 318 illustrates the enforcement of function/method argument and return checking. Is it envisaged that the accepts and returns functions become part of __builtins__? The code seems to assume that the interpreter will divert the func arguments to accepts and the return object to returns. Is this correct? If so, how many trigger words are implemented? Some syntactic options are provided in: http://www.python.org/moin/PythonDecorators I am inclined to support option D. The decorator follows the function definition and is indented, indicating that the decorator qualifies the decorated and is, in a sense subordinate to it. It doesn't use @. Steve Bethard sets out the syntactic choices clearly: http://groups.google.com/groups?q=bethard+decorator&hl=en&lr=&ie=UTF-8&selm=d11dcfba.0408060919.10c7cdd6%40posting.google.com&rnum=1 My choices would be: Indicator: Keyword preferred, but not | (vertical bar), as it looks too much like 1 or l. Location: First line of the body. The decorators are subordinate to the signature and indented like the docstring. List notation: As ListType, with a line per entry. Indented: Yes, no block. Clearly, I don't fully understand PEP 318, but I wonder at times is decorators aren't a solution in search of a problem. Colin W. From avner at skilldesign.com Sun Aug 8 09:53:07 2004 From: avner at skilldesign.com (Avner Ben) Date: Sun, 08 Aug 2004 15:53:07 +0200 Subject: @decorator syntax is sugar, but for what exactly? In-Reply-To: <4115b53a$1@nntp0.pdx.net> References: <4115b53a$1@nntp0.pdx.net> Message-ID: <4116239e$1@news.012.net.il> Scott David Daniels wrote: > ... > classmethod and staticmethod were introduced some time ago, to provide > a mechanism for getting to such effects. At the time there was no clear > syntax to use that "felt right." In the meantime people have used these > features to good effect despite the clunky way you used them. At this > point there would probably be a small riot (or at least a large whine) > if these two were removed. > ... The "property" call resembles both classmethod, staticmethod and instancemethod, but cannot be eliminated using the new function decorator syntax, because of its m:1 nature - one property binds together a getter, a setter etc., where staticmethod etc. change the status of one function in one way. So, if the problem is to rid class definitions of bizarre function calls, stuck in the middle of nowhere, that actually add to the structure of the class (and which other OO languages solve by legitimate syntax), I am dissapointed to observe that functuion decorators do not do a complete job after all. Talking about properties, I like the C# way of defining them, which is straightforward and readable. The property begins like a method, but has no argument list and includes a getter function with no arguments and a setter function with one argument. Adapted to Python, it would look something like: class hasProperty: def __init__(self,aProperty='') self.aProperty = aProperty def AProperty: def get(self): return self.aProperty def set(self,value): self.aProperty = value obj = hasProperty() obj.AProperty = 'test' print obj.AProperty From pythongnome at hotmail.com Wed Aug 18 19:44:46 2004 From: pythongnome at hotmail.com (Lucas Raab) Date: Wed, 18 Aug 2004 23:44:46 GMT Subject: age of Python programmers References: Message-ID: Pardon me while I run away from your cane!! "Skip Montanaro" wrote in message news:mailman.1876.1092839779.5135.python-list at python.org... > > Christopher> I'm 19. The only other Python programmer I know personally > Christopher> is 21. Congrats on discovering Python at 14; back then I > Christopher> thought VB was a godsend. ;) > > Whippersnapper... At 14 I would have thought a computer was a godsend. ;-) > > (I'm 50, btw.) > > Skip From news.malik at gmx.net Wed Aug 25 17:40:20 2004 From: news.malik at gmx.net (Johannes Mockenhaupt) Date: Wed, 25 Aug 2004 23:40:20 +0200 Subject: Regular Expressions In-Reply-To: <808f000f.0408250802.8c303ea@posting.google.com> References: <808f000f.0408250802.8c303ea@posting.google.com> Message-ID: <20040825214020.GA32170@achernar.eridanus> On Wed, Aug 25, 2004 at 09:02:40AM -0700, Oriana wrote: > hi! > > I've been working with Python for about two months now but I just > started learning about regular expressions. I found this to be a good start: http://www.amk.ca/python/howto/regex/ it's a "Regular Expressions With Python" Howto :-) [...] Hope this helps, Johannes -- 3. The most fun you can have with your clothes on. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From roy at panix.com Tue Aug 10 23:23:10 2004 From: roy at panix.com (Roy Smith) Date: Tue, 10 Aug 2004 23:23:10 -0400 Subject: measuring 1/100th seconds, what function? References: Message-ID: Tim Peters wrote: > Note that on a box connected to a network time-correction > service, time.time can appear to "run backwards" briefly at > unpredictable times. This will never happen if you're running NTP. NTP does gradual adjustments to the clock rate to ensure that the system clock is always monotonically increasing. It can happen if you're running some kind of time sync service other than NTP. Why anybody would want to do such a thing is beyond me. From patrick.schaeffler at siemens.com Tue Aug 3 23:23:29 2004 From: patrick.schaeffler at siemens.com (Patrick) Date: 3 Aug 2004 20:23:29 -0700 Subject: Can somebody help me ? Message-ID: <9f6a3388.0408031923.11cfa62d@posting.google.com> Hi, I managed to open a msaccess database with python. import win32com.client.dynamic db1 = win32com.client.dynamic.Dispatch("Access.Application") dbname = "D:\\Project\\Database\\database.mdb" db1.OpenCurrentDatabase(dbname) Now, I have the problem, that I don't know how I can read the lines of my table. Can somebody help me please and give me an example code ? I'm looking forward to your answers, and thank u very much in advance. Cheers Patrick From peter at engcorp.com Thu Aug 12 15:14:17 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 12 Aug 2004 15:14:17 -0400 Subject: Flython? Message-ID: Just been looking at Flash and ActionScript... In the vein of Jython, I wonder what it would take to build a Flython? (Lousy name, I know.) That would take Python source, presumably a subset since some things couldn't be supported, and compile it into ActionScript bytecode (aka the bytecode compiled from ECMAScript source for the Macromedia Flash player environment). With that, it would be pretty easy to write applications which have a Flash front end, but with pretty much all the logic on front and back implemented in Python. There doesn't seem to be any mention of such an idea on the web yet. A search turns up only part of a thread where Cameron Laird asked about marrying Flash and Python and I replied with a reference to use of Flash in Twisted's LivePage... (http://groups.google.ca/groups?selm=vpdqlca3vkvp5c%40corp.supernews.com) -Peter From pm_mon at yahoo.com Wed Aug 18 14:39:08 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Wed, 18 Aug 2004 14:39:08 -0400 Subject: PEP 318: Can't we all just get along? In-Reply-To: References: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: Michael J. Fromberger wrote: > In article , > Paul Morrow wrote: >> >>Good conventions prevent ambiguity. >> >> class Foo: >> def method1(self, a, b): pass # clearly an instance method >> def method2(cls, a, b): pass # clearly a class method >> def method3(a, b): pass # clearly a static method > > > I think this is a terrible idea. What you are proposing is essentially > that Python should assign special meaning to the identifiers "self" and > "cls" when they appear as the first variable in a method definition > inside a class. I am having a hard time thinking of anything LESS in > the spirit of Python, short of writing in unstructured BASIC. > 'self' already has a special meaning to experienced Python developers, by virtue of its role in the recommended coding practices. And if you ask experienced Python developers who understand the difference between class, static, and instance methods, to guess what kind of method this is... def foo(cls, a, b): pass ...I bet the majority would correctly guess "class". So these words already do have special significance to *us* when used in the first parameter position. Why not make them significant to the Python system too? > Good conventions do not prevent ambiguity, they merely help alleviate > its effects. Maybe the problem is with the word 'ambiguity'. How about adherence to good coding conventions can keep things from being interpreted in multiple ways. > And a "convention" that is enforced by the translator is > no longer a convention, but a rule of the language. Right. So a convention becomes a rule. Sounds like a natural evolution. > >>When declarations conflict with conventions, it makes us wonder what the >>author really intended. >> >> def staticmethod setX(self, x): >> self.x = x > > > I find this at least as easy to understand as the current idiom: > > def setX(self, x): > self.x = x > setX = staticmethod(setX) > > Me too, but they both have problems. The staticmethod declaration is in conflict with the use of 'self' as the first parameter. And they both require more code than necessary. Just as it would be unecessary to say... def private __foo(self): pass Declarations aren't needed when an obvious interpretation of the code conveys the desired meaning. From __peter__ at web.de Sun Aug 29 04:27:55 2004 From: __peter__ at web.de (Peter Otten) Date: Sun, 29 Aug 2004 10:27:55 +0200 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <7xzn4gwgea.fsf@ruckus.brouhaha.com> <1gj7a1o.1a5d2q410jsn2kN%aleaxit@yahoo.com> <7xisb4xnh5.fsf@ruckus.brouhaha.com> <1gj7c1a.tfdm14p3hclcN%aleaxit@yahoo.com> <7xd61benm9.fsf@ruckus.brouhaha.com> <1gj82n3.1ylkr3nierngmN%aleaxit@yahoo.com> <7xd61b8uh2.fsf@ruckus.brouhaha.com> <7x1xhqg3kb.fsf@ruckus.brouhaha.com> <7xr7pqe6p6.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > "Terry Reedy" writes: >> > I think it's better to extend the syntax, e.g. >> > import x(a,b) => __import__('x', {'a':None, 'b':None}) >> > import x(a=v1,b=v2)=> __import__('x', {'a':v1, 'b':v2}) >> >> Identifier(args) is currently a call of identifier with args and >> overloading that syntax to mean somthing similar but different is, to me, >> even uglier in a different sort of way. > > Ok, use brackets instead: import x[a,b]. > Then it's just a matter of overloading the index operator on __import__. @signed @certfile('mycerts.pem') import x anybody? Peter From h.b.furuseth at usit.uio.no Thu Aug 5 17:38:20 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 05 Aug 2004 23:38:20 +0200 Subject: Proposal: require 7-bit source str's References: <10h58s2bmjo1j67@news.supernews.com> Message-ID: John Roth wrote: >"Hallvard B Furuseth" wrote in message >news:HBF.20040805p736 at bombur.uio.no... >> Now that the '-*- coding: -*-' feature has arrived, >> I'd like to see an addition: >> >> # -*- str7bit:True -*- >> >> After the source file has been converted to Unicode, cause a parse >> error if a non-u'' string contains a non-7bit source character. >> >> It can be used to ensure that the source file doesn't contain national >> characters that the program will treat as characters in the current >> locale's character set instead of in the source file's character set. >> (...) > > Is this even an issue? If you specify utf-8 as the character > set, I can't see how non-unicode strings could have > anything other than 7-bit ascii, for the simple reason that > the interpreter wouldn't know which encoding to use. Sorry, I should have included an example. # -*- coding:iso-8859-1; str7bit:True; -*- A = u'h?r' # ok B = 'h?r' # error because of str7bit. print B The 'coding' directive ensures this source code is translated correctly to Unicode. However, string B is then translated back to the source character set so it can be stored as a str object and not a unicode object. The print statement just outputs the bytes in B, it doesn't do any character set handling. So if your terminal uses latin-2, it will output the '?' as Latin small letter r with caron. coding:utf-8 wouldn't help. B would remain a plain string, not a Unicode string. The raw utf-8 bytes would be output. -- Hallvard From john at grulic.org.ar Mon Aug 23 16:57:39 2004 From: john at grulic.org.ar (John Lenton) Date: Mon, 23 Aug 2004 17:57:39 -0300 Subject: J2 proposal: keyword In-Reply-To: <7umdnWsYNds1orfcRVn-jA@powergate.ca> References: <7umdnWsYNds1orfcRVn-jA@powergate.ca> Message-ID: <20040823205739.GA5735@grulic.org.ar> On Mon, Aug 23, 2004 at 03:06:09PM -0400, Peter Hansen wrote: > Oliver Fromme wrote: > >So, FWIW, I think both "using" and "with" are fine, > >although both of those remind me of completely unrelated > >things. > > > >("Using" as in the "print using" statement of certain > >ancient dialects of BASIC which was used for formatted > >output, as well as the "use" statement in perl to import > >a module. > > I would call this a good precedent. Or at least I'd > say that they choose the word well for that purpose, > and our purpose here is very similar. > > (For those that don't recall this, I believe it was > similar to if not exactly like the following, where > it functions rather like a decorator in the sense > of transforming the usual function in a certain way: > > PRINT USING '$###.##', total_dollars > ) agh! I hate you! I had successfully erased that from my brain :( -- John Lenton (john at grulic.org.ar) -- Random fortune: The sunlights differ, but there is only one darkness. -- Ursula K. LeGuin, "The Dispossessed" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From fuzzyman at gmail.com Tue Aug 10 07:38:08 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 10 Aug 2004 04:38:08 -0700 Subject: Advanced printing using win32ui in python - help! References: Message-ID: <6f402501.0408100338.7c492b03@posting.google.com> Darcy Kahle wrote in message news:... > I am trying to do some advanced printing in python using the win32ui > module, and have run into an issue. [snip..] > > Can anyone recommend to me how I could either specify the page to be in > landscape mode, or rotate the text that is printing? Any assistance > that you can provide is greatly appreciated, and I am certain that there > are others out there that want to know how to do this as well. > > BTW, I am currently using WinXP and Python 2.3, but the solution should > be accessible via Win98 and up. I plan to use py2exe to run the final > product on other windows boxes. I'm afraid I don't have an answer for you..... but there is a big need for a straightforward 'print module' for windows.... It's something I have on my list to look at 'sometime' - hopefully by finding an existing library to wrap. Regards, Fuzzy http://www.voidspace.org.uk/atlantibots/pythonutils.html From deetsNOSPAM at web.de Mon Aug 30 18:30:18 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Tue, 31 Aug 2004 00:30:18 +0200 Subject: file access in jythonc References: <9eabe547.0408210611.d5e54f7@posting.google.com> <9eabe547.0408301406.2543e691@posting.google.com> Message-ID: > I've looked up the references below and done several searches of > filepermissions. It seems to me that for jythonc to have any use in > development of "practical" products, programs have to be able to > access local files easily. If not, then this, in my opinion, is going > to be a MAJOR issue for jython!! I love the syntax and ease of > programming in python, but if it cannot be used for useful programs, > why bother?! BTW, how does java handle this? Is the same problem there > also? Don't blame jython for things it hasn't to do with - as Alan said, java puts restrictions on the things an applet can do. That restrictions can be relaxed by signing the applet - go search google for stuff like java, applet, signing, local, file, access. A common mistake for jython users is to think that there must be special jython related documentation for their problems - but usually its not, for the simple reason that there are tons of docs on java out there. Jython docs only cover the differences. So go look for java solutions to your problems, and then feel the joy of using java-classes with a language without checked exceptions and what not that makes coding in java so ... verbose. -- Regards, Diez B. Roggisch From peter at engcorp.com Tue Aug 3 21:26:08 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 03 Aug 2004 21:26:08 -0400 Subject: guide to introspecting python? In-Reply-To: References: Message-ID: Mark Harrison wrote: > What's a good document to read in order to understand some > of python's introspective functions? ... > PS, you will probably recognize this as my attempt to > generate programatically the module/function/parameter > index I previously asked about... Isn't the "inspect" standard module exactly what you need? From siona at chiark.greenend.org.uk Mon Aug 23 11:58:00 2004 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 23 Aug 2004 16:58:00 +0100 (BST) Subject: [newbie] Strange behavior of the re module References: <2ejdi01btug5iskb4ipjpj7eaprd8i7vgm@4ax.com> <86hei0prvp55iom91df23tffh04egefeig@4ax.com> <3toei056qnmk8nkesta47mncuh49asscht@4ax.com> Message-ID: Fred wrote: >output = re.sub('', body, output) Here's another hint: string.replace() is a lot faster than re.sub(), and doesn't require any extra escaping of the replacement string. Regular expressions are a bit of a Swiss Army knife in Python. They'll do the job, but the proper tool will do it better. -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From sbabbitt at commspeed.net Tue Aug 10 11:25:13 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Tue, 10 Aug 2004 08:25:13 -0700 Subject: Thread for a newbie References: Message-ID: <1092151931.22224@news.commspeed.net> "JDevine" wrote in message news:f9d01b73.0408100642.67255b58 at posting.google.com... > Hi. I have just finished my first python program. Unfortunately > threading has me stumped. I think this is mostly because the > wx.thread example demo is very complex, with all the grahphics, > graphs, and draw functions. I want to do something very simple. My > program downloads files over HTTP, I want to instantiate a process > dialog that tracks the download. I already have access to the > expected size of each file through other functions in my program, I > also assume an os.foo is capable of getting the current size as the > file grows as it is downloaded. My issue is keeping the file > downloading WHILE it is being tracked by the process dialog. Please > help with any simple thread examples you might have, if this example > includes a dialog even better. > Thanks for any help you can provide. > > -Justin > Justin__Devine at hotmail.com thanks Don't use the wxPython threading example, use instead the threading module from the standard library. It is vey easy to use and works fine with wxPython. Tom From chrisks at NOSPAM.udel.edu Tue Aug 31 00:33:25 2004 From: chrisks at NOSPAM.udel.edu (Chris S.) Date: Tue, 31 Aug 2004 04:33:25 GMT Subject: Debunking Art - fraudster with python AI engine? References: <4128f60b$1@news.unimelb.edu.au> Message-ID: <4133ff91$1@news.unimelb.edu.au> Nick wrote: > Naturally, I find it hard to believe he has picked up on natural > language processing and the other various skills required to write AI > engines in that time. My guess is he has a python AIML interpreter, > and he's found a default "brain" somewhere and tweaked it with some of > his own stuff in order to pass it off as his own. So what's the problem? You make it sound like he *must* be plagerizing someone else's work, but PyAIML is for creating just such an interface. There are even free brains available. Considering the term "AI engine" has no official meaning, a shell powered by an AIML interpreter could easily be one of many possible solutions to such a setup. [ 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 joshl at commenspace.org Thu Aug 26 15:41:08 2004 From: joshl at commenspace.org (Josh) Date: Thu, 26 Aug 2004 12:41:08 -0700 Subject: waiting for html to load: a followup In-Reply-To: References: Message-ID: John, I really appreciate your reply. I actually grabbed the ClientCookie module last night and spent a long time trying to figure out how to write this; your snippet of code was incredibly helpful to me. Nothing quite like being totally new to a subject, I must say. Thanks again, -Josh John J. Lee wrote: > Josh writes: > [...] > >>Anyway, I decided to forget IE and I am now trying to use urllib2 to >>open up the page, read it, etc. My problem is the page has a built-in >>refresh and I don't know how to have python re-read the page until >>it's ready to hand over the links. >> >>An example of the page is: >>http://edcw2ks23.cr.usgs.gov/Website/zipship/waiting.jsp?areaList=49.0,47.0,-122.0,-124.08&prodList=NED, > > > Example, with some debugging turned on so you can see some of what's > going on: > > import ClientCookie > opener = ClientCookie.build_opener( > ClientCookie.HTTPRefreshProcessor(max_time=None), > ClientCookie.HTTPResponseDebugProcessor(), > ClientCookie.HTTPRedirectDebugProcessor(), > ) > ClientCookie.getLogger("ClientCookie").setLevel(ClientCookie.DEBUG) > > r = opener.open('http://edcw2ks23.cr.usgs.gov/Website/zipship/waiting.jsp?areaList=49.0,47.0,-122.0,-124.08&prodList=NED,') > f = open('out.html', 'w') > f.write(r.read()) > > > Don't mix ClientCookie and urllib2, BTW. > > > John From jdhunter at ace.bsd.uchicago.edu Wed Aug 25 08:46:59 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Wed, 25 Aug 2004 07:46:59 -0500 Subject: building 2.1 with LFS Message-ID: I am trying to build python2.1 with alrge file support. I ran configure in a clean build tree and then edited the makefile # Compiler options OPT= -ggdb -O3 -Wall -Wstrict-prototypes -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 #OPT= -g -O2 -Wall -Wstrict-prototypes DEFS= -DHAVE_CONFIG_H CFLAGS= $(OPT) -I. -I$(srcdir)/Include $(DEFS) And did a make; make install I specify the full path to the python executable, but my test for LFS comes up negative [root at bace root]# /usr/local/bin/python2.1 Python 2.1.3 (#1, Aug 25 2004, 10:01:39) [GCC 3.2 20020903 (Red Hat Linux 8.0 3.2-7)] on linux2 Type "copyright", "credits" or "license" for more information. >>> fd = open('/dev/null', 'rw') >>> fd.tell() As you can see from the build date, this was the python I just built. Any ideas what I'm doing wrong. This is an incantation I've used successfully before, so I am mystified. I guess the best guess is that my kernel does support LFS [root at bace root]# uname -a Linux bace.bsd.uchicago.edu 2.4.18-14 #1 Wed Sep 4 12:13:11 EDT 2002 i686 athlon i386 GNU/Linux Is there an easy test for this? Thanks! JDH From ndeskins at ecn.purdue.edu Wed Aug 18 15:22:35 2004 From: ndeskins at ecn.purdue.edu (Aaron Deskins) Date: Wed, 18 Aug 2004 14:22:35 -0500 Subject: Newbie question about file input In-Reply-To: References: <4122328e$0$8079$a1866201@newsreader.visi.com> Message-ID: Marc 'BlackJack' Rintsch wrote: > > A line without anything but whitespace characters "splits" to an empty > list. > Thanks for the info. I wasn't aware that "\n" is whitespace. I'm still a programming beginner and learning everyday! Any other whitespace characters I should know about? Thanks again -- Aaron Deskins Graduate Student Chemical Engineering Purdue University From bapeters at terastat.com Tue Aug 24 19:33:05 2004 From: bapeters at terastat.com (Bruce Peterson) Date: Tue, 24 Aug 2004 23:33:05 GMT Subject: age of Python programmers References: Message-ID: "Lucas Raab" wrote: >One thing I've always kind of wondered is what is the average age of a >Python programmer?? What age groups use Python?? Something to think >about.... > 57 -- I guess I'm on the right side of the curve. I started programming with Fortran 2 back in high school. I regard programming as a way to make tools to do what I want -- so I've never regarded myself as a professional programmer. I've written a lot of code because it's been easier to program a computer to do a task than to train a human. I ran into Python about 2 years ago when I was looking for an easy way to do data animation. Python's ability to easily implement complex data structures sold me. From ajsiegel at optonline.com Mon Aug 9 07:27:25 2004 From: ajsiegel at optonline.com (Arthur) Date: Mon, 09 Aug 2004 11:27:25 GMT Subject: PEP-0318 References: <41122FC2.1080608@interlink.com.au> <4114152f@nntp.zianet.com> <4116bc20$1@nntp.zianet.com> Message-ID: On Mon, 9 Aug 2004 11:34:39 +1000, Anthony Baxter >Guido has ruled out decorators at the top of function body, on the grounds >that it looks like something that would be executed as part of the function, >but isn't. FWIW, in the same thread he's noted that having docstrings where >they are is problematic in this respect. Fortunately, with the new decorator >syntax, we can fix this... > >def doc(docstring): > def add_doc_string(func, docstring=docstring): > func.__doc__ = docstring > return func > return add_doc_string > >@doc("This function frobulates an input sequence") >def frob(seq): > .... On one hand I find it strange that Gudio would come to this without much, if any, feedback from the community of users working within the status quo without raisng an issue. You would think someone other than Guido would have also expressed some discomfort with the status quo if it were truly problematic. On the other hand, when I # comment a function, my instinct has always been to place the comment directly above the function, rather than in the body. Which I seem to think is common practice. So I need to admit that with the freedom to comment anywhere, the fact that instinct, and nothing but, has led me to place it outside and above the body perhaps sabotages, a bit, my own and others position that decorators outside and above the function is somehow unnatural. Art From steven.bethard at gmail.com Thu Aug 19 03:31:25 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 19 Aug 2004 07:31:25 +0000 (UTC) Subject: inverse of izip References: Message-ID: Steven Bethard gmail.com> writes: > What's the inverse of izip? Of course, I could use zip(*) or izip(*), > e.g.: > > >>> zip(*itertools.izip(range(10), range(10))) > [(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)] > >>> x, y = itertools.izip(*itertools.izip(range(10), range(10))) > >>> x, y > ((0, 1, 2, 3, 4, 5, 6, 7, 8, 9), (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)) > > But then I get a pair of tuples, not a pair of iterators. Basically, > I want to convert an iterator of tuples into a tuple of iterators. Sorry to respond to myself, but after playing around with itertools for a while, this seems to work: >>> import itertools >>> starzip = lambda iterables: ((tuple[i] for tuple in itr) for i, itr in enumerate(itertools.tee(iterables))) >>> starzip(itertools.izip(range(10), range(10))) >>> x, y = starzip(itertools.izip(range(10), range(10))) >>> x >>> y >>> list(x) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> list(y) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Seems like a bit of work for the inverse of izip though so I'll wait to see if anyone else has a better solution. (Not to mention, it wouldn't be a single line solution if I wasn't using 2.4...) Steve From __peter__ at web.de Tue Aug 3 10:39:03 2004 From: __peter__ at web.de (Peter Otten) Date: Tue, 03 Aug 2004 16:39:03 +0200 Subject: Reasoning behind nested scope References: Message-ID: Andy Baker wrote: > (On a side note is there any way to call a nested function from outside > the parent? I was kind of expecting nested functions to be addressable > through dot notation like methods are but I can see why that wouldn't be > quite right. This might be a better question for the tutor list...) When you are nesting functions, you don't get one function sitting inside another function. Instead, the function creation code of the "inner" function is executed every time to the effect that you get a new inner function every time you call the outer one: >>> def make(): ... def f(): return "shoobidoo" ... return f ... >>> f1 = make() >>> f2 = make() >>> f1(), f2() ('shoobidoo', 'shoobidoo') >>> f1 is f2 False You wouldn't do that in cases like the above, when you get nothing in return for the extra overhead, but somtimes nesting is useful - because of the change in the scoping rules you now get readonly-closures: >>> def make(s): ... def f(): return s ... return f ... >>> f1 = make("now") >>> f2 = make("what") >>> f1(), f2() ('now', 'what') Peter From squirrel at WPI.EDU Mon Aug 16 15:11:56 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Mon, 16 Aug 2004 15:11:56 -0400 Subject: Flython In-Reply-To: References: Message-ID: On Mon, 16 Aug 2004, Terry Reedy wrote: > The grammar in the Ref Manual, which is collected together in the above > file, is intended and used for human comsumption. The equivalent but not > identical grammar in a source code file is intended and used for > parser-generator comsumption. Ahh... that makes sense. I assumed they were one in the same; ref/grammar.txt was just more readily accessible at the time (read: I was lazy). > I don't know whether AST trees exactly match the parser grammarr or if they > effectively follow a third form, hopefully also exactly equivalent. A quick glance through Grammar/Grammar shows that it seems to match up exactly to the AST trees, though I'll have to play with it to be sure. Thanks! From newsgroups at jhrothjr.com Fri Aug 13 07:16:47 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 13 Aug 2004 07:16:47 -0400 Subject: Why I love python. References: <10ho7626f5f3f74@news.supernews.com> Message-ID: <10hp8ok1dg0ie08@news.supernews.com> "Nick Patavalis" wrote in message news:slrncho8m9.pfh.npat at gray.efault.net... > On 2004-08-13, John Roth wrote: > > > > "Nick Patavalis" wrote in message > > news:slrncho5aq.pfh.npat at gray.efault.net... > >> On 2004-08-13, Michael Scarlett wrote: > >> > >> Python needs drastic performance improvement if it is to scrap-off the > >> "scripting language" stigma. > > > > More performance would be helpful. There are a number > > of projects that are working toward that end, of which > > the most visible is the PyPy project. > > > > >> The only way to get these improvements is > >> making it possible for a python implementation > >> to produce *efficient* *compiled* code. > > > > I think there are lots of people that would dispute > > you on that. Current Java environments run close > > to C++ performance due to the JIT compilers > > that are built into the runtimes. > > You 're right, I was maybe a bit too dogmatic on my point. But you > must accept that JIT-compilers are, nevertheless, compilers! They may > be more intelligent and more flexible than traditional "ahead of time" > compilers, but still they are fundamentally compilers. Furthermore, > for most cases, it might be possible for an AOT compiler to produce a > "binary" that doesn't contain the compiler itself. It's generally regarded as not worth doing, simply because JITs might compile different code for each time through a method if the signature changes dynamically. > > Current JIT technology doesn't require pre-declaration of variable > > types; it's perfectly happy to insert checks at appropriate points > > so that it can reuse code when the object types don't change (which > > they don't most of the time.) > > What you mean I guess, is that the first time a function is applied, > it is compiled to native-code, and a signature for the application is > generated. The next time, the application is checked against the > signature and if they match, the existing code is used, otherwise the > function is re-compiled (preserving the previously compiled one too, > is some sort of "cache"). Or am I getting it wrong? Even in such a > case though per-declarations would help. Exactly, although the scope is smaller than a function - it has to check other variables that the method might refer to. Declarations don't help unless they can provide a solid guarantee of the variable's type. If they can't, they're useless because the JIT has to insert the type checking code anyway. > > Do you happen to know of any efforts to build such "AOT"/"JIT" > compilation/execution environments for Python? That's part of the plan for PyPy. John Roth > > Regards > /npat > From fumanchu at amor.org Tue Aug 24 21:55:55 2004 From: fumanchu at amor.org (Robert Brewer) Date: Tue, 24 Aug 2004 18:55:55 -0700 Subject: J2 0-2-6 is available Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E62@exchange.hqamor.amorhq.net> Steven Bethard wrote: > Actually, there's an interesting argument that the "with" for > decorators and > the "with" above can be thought of in similar terms: > > http://mail.python.org/pipermail/python-list/2004-August/235993.html > > I don't know if I agree with it, but I think I'm at least > convinced they don't > have to mean *completely* different things. FYI, I'm linking to that in the next document version later tonight. FuManChu From jepler at unpythonic.net Wed Aug 4 21:25:35 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 4 Aug 2004 20:25:35 -0500 Subject: optparse object population In-Reply-To: <20040805011555.GB15014@cs.hmc.edu> References: <20040805011555.GB15014@cs.hmc.edu> Message-ID: <20040805012534.GB31600@unpythonic.net> You could create a subclass of Option, overriding take_action() with a new "store_attr" action, which would do something along the lines of def take_action(self, action, dest, opt, value, values, parser): raise RuntimeError, "untested code follows" if action == 'store_attr': objname, attr = dest.split(",", 1) obj = getattr(values, objname) setattr(obj, attr, value) return 1 return Option.store_attr(self, action, dest, opt, value, values, parser) or you could probably use "callback" in some way. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From steven.bethard at gmail.com Thu Aug 12 14:48:33 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: 12 Aug 2004 11:48:33 -0700 Subject: wiki update: decorator syntax breakdown References: <411ac3cc$1@nntp.zianet.com> Message-ID: Mark Bottjer wrote in message news:<411ac3cc$1 at nntp.zianet.com>... > Hm. Just as a note, I didn't spot the following (recent?) variant: > > class C: > def c(self): > meta: > classmethod > doc('This is a function!') > pass I think this would fall under: Indicator: keyword: 'meta' Location: post-def List Notation: One per line Indentation: Indent decorators only Right? I added 'meta' to the keyword section. Steve From pwilkinson at videotron.ca Fri Aug 6 14:25:07 2004 From: pwilkinson at videotron.ca (Peter Wilkinson) Date: Fri, 06 Aug 2004 14:25:07 -0400 Subject: Plotting histograms, scatter plots in Python In-Reply-To: References: Message-ID: <6.0.3.0.0.20040806142410.01b44928@pop.videotron.ca> One module is Matplotlib, that seems to model the Matlab way of doing things .... its at sourceforge. Peter W. At 02:18 PM 8/6/2004, Dr. Colombes wrote: >What is the easiest way to generate some plots and graphs in Python ? > >Specifically interested in simple histograms and scatter plots with >circles and regression lines. > >Thanks for your suggestions. >-- >http://mail.python.org/mailman/listinfo/python-list From reinhold-birkenfeld-nospam at wolke7.net Fri Aug 13 03:19:33 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Fri, 13 Aug 2004 09:19:33 +0200 Subject: decorator with keyword In-Reply-To: References: <2o21foF65snnU2@uni-berlin.de> Message-ID: <2o37rhF6b1veU1@uni-berlin.de> Peter Hansen wrote: > Reinhold Birkenfeld wrote: > >> Peter Hansen wrote: >>>The python-dev mailing list doesn't appear to have discussed this one >>>yet, but given that much of the, uh, "chatter" that I detect there >>>is about minor tweaking of the @pie syntax, I fear they are so not >>>likely to pay much attention to new syntaxes and it might be too >>>late to get much support for it amongst the core folks. (Guido >>>referred to @pie as "the humble @decorator" yesterday...) >> >> I'm sure it would help if every supporter of this syntax started a >> thread of his own on python-dev *wink* > > Glad you put the wink in... I doubt that would help the > cause. > > The syntax should be presented there, perhaps, preferably > by someone calm and reasonable (i.e. not me), but I think > the most valuable thing is to continue discussion here > until it's apparent (if that's going to happen) that there > is a fairly wide consensus that decorate: (possibly with > a different keyword) is far preferred to @pie... At least, > I think that was roughly what was asked for of the masses, > if the masses had anything to say about the matter. Full ACK! Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From aleaxit at yahoo.com Tue Aug 31 06:50:29 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Tue, 31 Aug 2004 12:50:29 +0200 Subject: about presicion References: <8f17f4bc.0408261434.1a73e874@posting.google.com> <2e363c08.0408261912.2358a016@posting.google.com> <8f17f4bc.0408281303.3cfb4199@posting.google.com> <20040829041630.28913.00001771@mb-m26.aol.com> <8f17f4bc.0408291552.67e3553e@posting.google.com> <1gjc18t.1hj0z071lwprfjN%aleaxit@yahoo.com> <8f17f4bc.0408300931.7223af16@posting.google.com> Message-ID: <1gjdv0x.b2iha5rsljj6N%aleaxit@yahoo.com> Ali wrote: ... > ok but where can i download deciaml? waht about gmpy? which is better? Decimal (for 2.3): file decimal.py from: http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Lib/ With 2.4 it will come as part of the standard library. gmpy: http://gmpy.sourceforge.net.\/ "Which is better" for _WHAT_ task? If you need decimal arithmetic, obviously Decimal, since gmpy doesn't support it -- gmpy uses binary throughout. If you need huge-precision binary floats, unbounded-precision rational numbers, very fast operations such as factorials and binomial coefficients on unbounded-precision integers, then obviously gmpy, since Decimal doesn't support any of these -- Decimal does its job, which is decimal arithmetic, period. I cannot imagine offhand any task for which I would be in doubt between using Decimal and using gmpy -- sure, they both deal with numbers, but there's basically no overlap between their functionality. Alex From Brian.Inglis at SystematicSW.Invalid Mon Aug 30 01:24:18 2004 From: Brian.Inglis at SystematicSW.Invalid (Brian Inglis) Date: Mon, 30 Aug 2004 05:24:18 GMT Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <25u2j0d9bfulqljo6d2jbls2v52l1jk3sd@4ax.com> Message-ID: On Sun, 29 Aug 2004 17:02:23 -0700 in alt.folklore.computers, Mac wrote: >On Sun, 29 Aug 2004 06:58:30 +0000, Brian Inglis wrote: > >> On Sat, 28 Aug 2004 20:59:08 -0700 in alt.folklore.computers, Mac >> wrote: >> >>>On Wed, 25 Aug 2004 14:56:06 -0700, Xah Lee wrote: >>> >>>> Larry Wall and Cults >>>> (Lazyness, Impatience and Hubris) >>>> 200012 >> >>>> Surely you have heard of Adolf Hitler >>>> and his atrocities of genocide? I must alert you, that a single person >>>> couldn't commit such a crime. >>> >>>Wow, Godwin's law invoked on the first post of the thread. >> >> Not quite, no comparison was made; see: >> http://groups.google.com/groups?as_umsgid=1991Oct22.140831.23313%40eff.org > > >Hmm. No explicit comparison was made, but since the post is a cautionary >tale (well, the post is a rambling mess, but I think it is trying to be a >cautionary tale) I think the comparison is understood. > >But if the comparison must be explicit, as you seem to be saying, then I >have to concede the point. Google for the Godwin's Law FAQ on how to troll on Usenet, mention Nazis, and not be caught by Godwins' Law. -- Thanks. Take care, Brian Inglis Calgary, Alberta, Canada Brian.Inglis at CSi.com (Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]ca) fake address use address above to reply From mark at prothon.org Sat Aug 7 17:48:55 2004 From: mark at prothon.org (Mark Hahn) Date: Sat, 7 Aug 2004 14:48:55 -0700 Subject: Prothon is switching to the .NET platform References: <000401c47b59$32539220$0d01a8c0@MarkVaio> Message-ID: <11uq0duazp1vy.1g2zjz8xyfosl.dlg@40tude.net> On Thu, 05 Aug 2004 22:12:45 -0700, Guido van Rossum wrote: > Hi Mark, > > It was a pleasure to meet you at VanPy, and I was sorry that I had to > leave in the middle of your talk (I had a plane to catch and David had > scared me about delays). > > I was pleasantly surprised in hearing your architecture for the > Prothon engine -- it sounded like a fresh look at implementing a > runtime for a Python-like language, and several features (like the > locking strategy) sounded like I should be paying attention to them > for the Python 3000 interpreter. Thank you. That means a lot to me. > So now I'm a bit disappointed to hear that you're giving all that up > and switching to the CLR. I understand your desire to have a large > library available (though most of that library will be class-based, > which may require you to bring classes back in through the back door). > But in practical terms, it makes Prothon a lot less accessible in the > years to come. Both Dave and Paul pointed out IronPython to me at the workshop and how it could get Prothon a library and therefore a community much faster than going it the hard way like you did. There is a general feeling going around that multiple language VM's are the "in-thing". I've got a kind of catch-22 that I'm worried about. I have no one helping me write libraries because they aren't using Prothon and no one will use Prothon without libraries. They got me thinking that .Net would break the catch-22. Do you have any other ideas on how I could get a decent library in a decent timeframe? > I recall that installing .NET on Windows took me half a day. Maybe > it's gotten better, but I sure can't believe they've shrunk it. Mono > gives you theoretical support on Linux, but it's even more of a > questionable proposition to actually run it (and its set of supported > runtime libraries has only a small intersection with what's available > in .NET). Basically, telling people "here's my language, it's a 2 MB > download, and oh, BTW, you also need to install the 200 MB runtime > over there" isn't exactly encouraging people to play with your > language. Even for apps written in Java this is a significant barrier > -- I have several copies of Java on my hard drive because every > significant application written in Java ends up needing a different > JVM version. And the JVM I downloaded last year is probably too old > to run this year's crop of bleeding edge Java apps. Availability of > the CLR is a lot less than Java. .Net and Mono may not be the greatest solution in the world, but they have a shot at running Prothon. I looked into Parrot and CPython and neither one could do the job. > I'm also surprised because you admit to being a poor language designer > (although you picked a great example :-). I assumed this to mean that > you're having more fun implementing the runtime. But if you're not > doing it for the language design, and now you're giving up on the > runtime, what's left? Just because I am not a good language designer does not mean I am not a good project manager and programmer. I would not enjoy working on the fun parts of the VM knowing that some other path existed where the language and community could grow faster. I guess I'm finding out I'm more motivated by Prothon's overall success than "programming fun". There will still be a lot of fun left. IronProthon will still be prototype based. It's a long story but the CLR will be capable of running my prototypes, the co-routines, and everything in Prothon except light-weight threads, object locking, and the locking-based features. > Hoping your website was hacked or it was practical joke The anti-.NET forces are just starting to appear now on the Prothon mailing list. It is starting to get interesting. I can always change my mind as I have many times in this project. I'm kind of famous for that. Right now though the idea of having Prothon be something that could be truly useful in a matter of months instead of years is very attractive to me. BTW: I hope my new website verbage isn't offensive to you. In the past I wasn't considering Prothon a successor to Python as I was leaving that for Python 3000, but when you said that 3000 was mostly going to change range to an iter I had a change of heart. :-) Were you serious about that? Mark Hahn From harry.g.george at boeing.com Fri Aug 6 09:45:35 2004 From: harry.g.george at boeing.com (Harry George) Date: Fri, 6 Aug 2004 13:45:35 GMT Subject: advice for perl expert wanting to learn python References: Message-ID: David Fraser writes: > Zeljko Vrba wrote: > > Now, why would I like to learn Python: because of IronPython port to CLR. > > Perl port to CLR doesn't seem to be coming soon. First Perl6 for Parrot has > > to be written, and then other backends.. > > What's the easiest way of learning python knowing perl? For experienced scripters, I find Beazley's "Python Essential Reference" is excellent. You already know what you want, just need to see how Python does it, and don't need a lot of handholding. Get a copy of "Python Cookbook" too, and scan that. Then rewrite one of your exsiting perl scripts. > > Is there > > somewhere > > a 'how-to' cookbook with parallel examples of frequent idioms in perl and > > python? An interesting variant on that is my pyperlish module, at http://www.seanet.com/~hgg9140/comp/index.html You can either use it as-is, or read the code to see how to emulate perl in python. NOTE: I do not recommend using pyperlish once you get the hang of python. > > And most important thing, how does Python deal with database > > connectivity? > > Is there a single API (akin to DBI) for connecting to databases? > > How does Python support the following databases: > > - Oracle > > - Postgres > > - MySQL > > - SQLServer (maybe using freetds?) > > - ODBC connectivity (connecting to MS Access) > > > > I have used Oracle, SQLServer and Access via ADO - try adodpapi.sf.net > which is a wrapper for ADO to the Python DB-API. > But note that you may well not be able to use any of this database > stuff from IronPython > > David More cross-platform and cross-DBMS is to code to the DB-API 2.0: http://www.python.org/topics/database/ -- harry.g.george at boeing.com 6-6M21 BCA CompArch Design Engineering Phone: (425) 342-0007 From xtian at toysinabag.com Mon Aug 9 18:06:50 2004 From: xtian at toysinabag.com (xtian) Date: 9 Aug 2004 15:06:50 -0700 Subject: @decorator syntax is sugar, but for what exactly? References: <4115b53a$1@nntp0.pdx.net> <4116239e$1@news.012.net.il> <4117a43b$1@news.012.net.il> Message-ID: Avner Ben wrote in message news:<4117a43b$1 at news.012.net.il>... > xtian wrote: > >[snip] > > > > def property_(f): > > return property(*f()) > > Where has the property Without Underscore come from? > property has been a builtin since 2.2, along with classmethod and staticmethod - it's part of the new-style classes guff. See: http://www.python.org/2.2/descrintro.html#property (You'll probably want to read the whole thing.) > >[snip] > > > > t = DecorationTest() > > print t.foo > > t.foo = 3 > > print t.foo > > > > Will you please explain how the assignment and retrieval work? > > Avner. The key to it is that the property call makes foo a descriptor, with __get__ and __set__ methods that use the getter and setter we passed in. That's what triggers the attribute-getting and -setting methods. The descriptor API is a big part of the type/class unification. here's some more information: http://www.python.org/peps/pep-0252.html (I haven't actually finished reading it myself - if my explanation's a bit garbled, ignore it and read the link. :) Hope that helps! xtian From arien_malec at yahoo.com.REMOVE Sun Aug 15 14:29:52 2004 From: arien_malec at yahoo.com.REMOVE (Arien Malec) Date: Sun, 15 Aug 2004 18:29:52 GMT Subject: PEP 318 decorators are not Decorators References: Message-ID: Skip Montanaro wrote in news:mailman.1662.1092523102.5135.python-list at python.org: > > Arien> 3) Won't most programmers think GoF decorators before > Arien> compiler syntax tree decorators? > > Skip> Not if they are unfamiliar with the GoF patterns (myself > included). > > Arien> Google: [~62,000 : ~130 mentions of each sort of decorator] > > ... > > BFD.... The thing is, just because in a verbal Rohrschach > test you think "GoF" when someone says "decorator" doesn't mean > everybody else will (or should). Clearly, Python can choose any name for the auto-function-transformation syntax in question, but it's rather willfully confusing to choose a name that's heavily identified with a profoundly different semantics that's superficially similar in intent. Arien From anthonybaxter at gmail.com Fri Aug 27 11:58:01 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 28 Aug 2004 01:58:01 +1000 Subject: allowing braces around suites In-Reply-To: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> Message-ID: On Fri, 27 Aug 2004 13:29:58 +0200, Kjetil Torgrim Homme wrote: > what do you think? should I write a PEP? I've changed my mind. You should indeed write a PEP. I strongly suggest you adopt the spirit of PEP-666 in doing this, as a PEP on braces will get the same response. I'd even suggest PEP 667 (The Neighbour of the Beast) as the PEP number. Think of it as a public service - you can stop this idea coming up again. Anthony From josh at chatgris.com Tue Aug 3 21:46:06 2004 From: josh at chatgris.com (Joshua Moore-Oliva) Date: Tue, 3 Aug 2004 21:46:06 -0400 Subject: asyncore, asynchat and threads Message-ID: <200408032146.06130.josh@chatgris.com> Ok.. so here is my situation. I have an application that I would love to be able to use asynchat with for it's handle_close, found_terminator etc abstraction on. However, I must use a separate thread for each connection as the work resulting from the communication can result in blocking for an indefinate period of time. What I would love to do for each thread that is created, is to spin off an asynchat subclass and manually run some kind of loop() function that will do the polling//select etc for me, in a threadsafe manner, only on the one asynchat class/connection for that thread (e.g. I supply variables to keep track of the data) I have come across some sparse documentation that mentioned asyncore.loop() can be supplied a map of some sorts to loop through.. However, I have no idea how to create this map to pass to asyncore.loop, nor what thread-safe precautions (if any) I need to make. A simple example of a thread-safe way to create an asynchat subclass and get it to run would be great... even any pointers, help, ideas on how to make something like this work would be greatly appreciated as well. Thanks, Joshua Moore-Oliva From michaels at rd.bbc.co.uk Thu Aug 26 11:25:23 2004 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Thu, 26 Aug 2004 16:25:23 +0100 Subject: Call for signatories for J2 References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> Message-ID: Anthony Baxter wrote: > On Thu, 26 Aug 2004 14:44:27 +0100, Michael Sparks > wrote: >> Using proposed J2: (tested) >> class Foo: >> using: >> staticmethod >> eval("(memoise,esiomem)[x==0]") >> def Hoo(Who, *args): >> print "Yoo", Who > > Why wouldn't you instead write this as: ... [alternative using an if statement before] ... > Don't use eval unless it's absolutely necessary, _please_. The question was asking about using a conditional expression in the decorator list. Since the closest equivalent as an expression that evaluates to a function is something like (memoise,esiomem)[x==0] and since you can only put function calls there, that was why I put eval there. I suppose instead I could've had: def identity(actualFunc): def decorate(func): return actualFunc(func) return decorate class Foo: @staticmethod @identity((memoise,esiomem)[x==1]) def Hoo(Who, *args): print "Yoo", Who Which is nicer, but still pretty hideous. I'd agree that the preceding if statement approach is better than a conditional expression. Regards, Michael. -- Michael.Sparks at rd.bbc.co.uk British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From ville at spammers.com Tue Aug 24 15:20:16 2004 From: ville at spammers.com (Ville Vainio) Date: 24 Aug 2004 22:20:16 +0300 Subject: Python and C, looking for a C IDE References: <6f402501.0408240353.2a5b8a84@posting.google.com> Message-ID: >>>>> "Michael" == Michael Foord writes: Michael> That aside - Pyrex looks the kiddie. Can anyone reccomend Michael> a reasonable C IDE ? An 'IDE' would be nice, but an Michael> editor might be sufficient. IDE isn't really necessary for C - OO/modular languages like Java/C++ benefit more from IDEs. You might do better by just picking an editor (e.g. something like Emacs or Jed) and putting the compilation commands in a python script (or a bat file), or learn make. Then again, there is Eclipse, the IDE to end all IDEs. It supports C/C++ too. -- Ville Vainio http://tinyurl.com/2prnb From ods at strana.ru Mon Aug 23 12:10:42 2004 From: ods at strana.ru (Denis S. Otkidach) Date: Mon, 23 Aug 2004 20:10:42 +0400 Subject: Alternative decorator syntax decision In-Reply-To: <2omet9Fc2v4mU1@uni-berlin.de> References: <2omet9Fc2v4mU1@uni-berlin.de> Message-ID: <20040823201042.7ef5c056.ods@strana.ru> C2 C2 C1 -- Denis S. Otkidach http://www.python.ru/ [ru] From indigo at bitglue.com Mon Aug 23 17:08:44 2004 From: indigo at bitglue.com (Phil Frost) Date: Mon, 23 Aug 2004 17:08:44 -0400 Subject: decompyle available anywhere? In-Reply-To: References: Message-ID: <20040823210844.GA31519@unununium.org> http://www.freshports.org/devel/decompyle On Mon, Aug 23, 2004 at 09:50:43PM +0200, Chris Becke wrote: > There used to be a module, decompyle, that decompiled .pyc files up to > version 2.2 of python. Decompyle for 2.3 is now a paid for web service and > the 2.2 decompyle seems to have been yanked. > > Is there some site out there still hosting it? Preferably a win32 version, > but I guess beggars can't be choosers. > > Thanks > > Chris. From heikowu at ceosg.de Fri Aug 6 10:12:14 2004 From: heikowu at ceosg.de (Heiko Wundram) Date: Fri, 6 Aug 2004 16:12:14 +0200 Subject: 'Using is not None, may not always work' In-Reply-To: References: Message-ID: <200408061612.14305.heikowu@ceosg.de> Am Freitag, 6. August 2004 15:15 schrieb Doug Fort: > Since I installed 2.4a2 I've been getting a warning from pychecker: Using > is not None, may not always work'. I thought 'is not None' was the right > thing to do. I've had problems with 'if not x:', because some objects > return False in this context. That's probably what pychecker warns you about: that you might get an object in the respective context which evaluates to boolean false, but is not None... Although I'd find this strange... Heiko. From kowald at molgen.mpg.de Mon Aug 16 11:08:15 2004 From: kowald at molgen.mpg.de (Axel Kowald) Date: 16 Aug 2004 08:08:15 -0700 Subject: Regular expression problem with groups Message-ID: <9b5e8d9.0408160708.37aa9ae3@posting.google.com> Hi everybody, I have a 'simple' problem with regular expressions. Maybe someone can help me. import re bla = 'the the' obj = re.search('(.+) \1',bla) obj.group(1) should now be 'the'. Instead obj is none (python 2.3 under windows and 2.1 under linux). The problem seems to be the \1 where I try to reference the first group. However, every tutorial says this is the correct way to do it !? Any ideas what I'm doing wrong ? Many thanks, Axel From jacek.generowicz at cern.ch Tue Aug 31 03:51:34 2004 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 31 Aug 2004 09:51:34 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1ry8k0d2az.fsf@rovereto.ifi.uio.no> <1r1xhob27n.fsf@rovereto.ifi.uio.no> Message-ID: Kjetil Torgrim Homme writes: > "I don't subscribe to programming dogmas", hmm? I guess "braces are > unworthy of Python" isn't dogma, it's the Truth. Yes, it probably qualifies as dogma. But I don't subscribe to it. I'm merely questioning the relative appropriateness of braces to that of using 'pass' to help your editor automatically indent your code. Different people's judgments will differ on this. The same person's judgment may well change with time. But do remember that variations on the theme of "let's have some braces" have been done so many times, and not once (to my knowledge, which is by no means complete) has one had any noteworthy success. OTOH, given that the @pie syntax that has made it into an alpha release, who knows ... I never thought I'd see that day. From me at privacy.net Wed Aug 4 07:21:09 2004 From: me at privacy.net (Dan Sommers) Date: 04 Aug 2004 07:21:09 -0400 Subject: Class optimization at runtime References: <10gvtipb5t0hl44@corp.supernews.com> Message-ID: On Tue, 03 Aug 2004 23:46:32 +0200, Peter Otten <__peter__ at web.de> wrote: > Jeff Shannon wrote: >> Or even better: >> >> if option: >> import WithOption as FooModule >> else: >> import WithoutOption as FooModule >> >> x = FooModule.Foo( ) >> >> (I twitch every time I see 'from X import *' ...) Yep, you're right. I always forget about the "as" option. > That, and mixed-case module names -- and no, I'm not advertising > all-uppercase here... My mistake again. The names I chose were for illustrative and explicative purposes only; nothing else was (meant to be) implied. For the record, then, it would look like this: if option: import optionon as optionmodule else: import optionoff as optionmodule x = optionmodule.Foo( ) (assuming we can live with an Initialcaps class name). It also now strikes me that a package might be appropriate here: Let __init__.py sort things out and set up the package's namespace accordingly; then the rest of the program would just use the package obliviously. But: - __init__.py has to have access to the option variable (solutions abound; good solutions are less plentiful and vary over time and space); - given (a) my recent track record for getting the details correct and (b) my lack of experience with the package system, I humbly leave the rest of such a solution to the interested reader. Regards, Dan -- Dan Sommers Never play leapfrog with a unicorn. From adurdin at gmail.com Sat Aug 21 11:24:18 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Sun, 22 Aug 2004 01:24:18 +1000 Subject: __metaclass__ and __author__ are already decorators In-Reply-To: References: Message-ID: <59e9fd3a040821082410ac872d@mail.gmail.com> On Sat, 21 Aug 2004 10:38:01 -0400, Paul Morrow wrote: > Thinking about decorators, and looking at what we are already doing in > our Python code, it seems that __metaclass__, __author__, __version__, > etc. are all examples of decorators. So we already have a decorator > syntax. What is the compelling reason to invent a new one? And if we > do, what's to become of the old one? __author__ and __version in a class (as per your example) are setting class attributes, not "decorating" the class anymore than the def's that declare instance methods are. Within a function, __author__ and __version__ are local variables, and nothing more; specifically, assigning to them does *not* set function attributes: >>> def foo(): ... __author__ = "me" ... return 5 ... >>> print foo.__author__ Traceback (most recent call last): File "", line 1, in ? AttributeError: 'function' object has no attribute '__author__' >>> print foo.func_code.co_varnames ('__author__',) __metaclass__ on the other hand is a magic attribute. I haven't worked out the details, but I have the feeling that what a metaclass does to a class is not replicable merely by decorating the class; in other words, that: class Foo: __metaclass__ = Bar is *not* equivalent to class Foo: pass Foo = Baz(Foo) for any definitions of Bar and Baz. This is just my intuition, however. From spamnews at gmx.de Wed Aug 4 06:21:11 2004 From: spamnews at gmx.de (Detlef Jockheck) Date: 4 Aug 2004 03:21:11 -0700 Subject: syntax-check with regular expressions? References: Message-ID: Matteo Dell'Amico wrote in message news:... > Detlef Jockheck wrote: > > Hi, > > > > I would like to check if a string contains a valid date format > > (Format: "dd.mm.yyyy") or not. > > > > What is the best way to do this. regexp? At the moment it would be > > sufficient to check for > > [digit][digit].[digit][digit].[digit][digit][digit][digit] but a full > > date verification (Month in range 1-12 ...) would be very nice too. > > > > Sample code would help me very much. > > > > regards > > Detlef > > > > PS: I'm a python newbie, so excuse this silly question > > This should work, returning True for valid dates and False otherwise: > > import re > > _re = re.compile(r'(\d{2})\.(\d{2})\.(\d{4})$') > def testdate(s): > try: > day, month, year = [int(x) for x in _re.match(s).groups()] > except AttributeError: > return False > return 1 <= day <= 31 and 1 <= month <= 12 > > Implementing things such as different number of days for each month and > leap years is left as an exercise to the reader. :-) Hi! That's great. Now I understand how this works. Thank you very much :-) regards Detlef From Kevin.Smith at sas.com Tue Aug 17 18:16:55 2004 From: Kevin.Smith at sas.com (Kevin Smith) Date: 17 Aug 2004 22:16:55 GMT Subject: PEP 318: Can't we all just get along? Message-ID: <20040817181725194-0400@braeburn.themorgue.org> For what it's worth, I wrote the original PEP 318. I probably wasn't qualified, but I just wanted a nice simple way to declare class methods without having to repeat the function name. After submitting it to BDFL for approval, more work was needed and the discussion of PEP 318 on python-dev increased rapidly. It was evident that I was in over my head, so I asked more someone more experienced to take over. I guess others had bigger plans for my proposal that I had planned. It has turned into the "solution" to many problems: type checking (both arguments and returned values), metaclasses, metadata, interfaces, function attributes, etc.). Unfortunately, in the process, this simple request for syntactical sugar has turned into a monstrosity. In my opinion, none of the proposed syntaxes really seem Pythonic. This PEP just seems to be trying to solve too many problems. Bear with me, but I'd like to propose one more syntax that is simple, easy for newbies to understand, and nowhere near as powerful as the current PEP's syntax. However, it doesn't add incoherent, arbitrary syntax either. def classmethod foo(x, y, z): pass That's it. One "decorator" that is a callable object that takes a method as it's only argument. No expressions, lists, tuples, etc. Just one callable object. Ok, if you absolutely must have more than one. def classmethod synchronized foo(x, y, z): pass Once again, no expressions. I know that this isn't going to solve everyone's type-checking, metadata, and function attribute problems, but let's face it, using this PEP for all of those things just creates ugly syntax. There must be more Pythonic ways to do those things in their own PEPs. -- Kevin Smith Kevin.Smith at sas.com From grante at visi.com Fri Aug 6 12:14:38 2004 From: grante at visi.com (Grant Edwards) Date: 06 Aug 2004 16:14:38 GMT Subject: Queue qsize = unreliable? References: Message-ID: <4113ae6e$0$65563$a1866201@newsreader.visi.com> On 2004-08-06, Peter Hansen wrote: >> I see per pydoc that Queue.Queue()'s .qsize is allegedly unreliable: >> >> | qsize(self) >> | Return the approximate size of the queue (not reliable!). >> >> Any thoughts on why this is unreliable (and more curiously, why it would >> be put in there as an unreliable function?) Rather than roll my own >> threaded fifo class, it would seem prudent to use Python's built-in >> Queue but the warning signs on a rather necessary function seem curious. > > (Why do you think this function is necessary? It's probably > rare to really need it, except perhaps during debugging... ) > > Anyway, the reason it's called "unreliable", though the term > "inaccurate" might be more correct, is because while you are > getting the size of the queue, it might be updated such that > the new size is one or more fewer or larger than the value > that is about to be returned to you. I don't think that's any reason to call the function either unreliable or inaccurate. If you're operating in a multi-threaded environment, such a statement is trivially true about anything that accesses shared data. For example: time.time() needs a disclaimer that it is unreliable, since the result it returns is incorrect by the time you get around to using it... -- Grant Edwards grante Yow! Spreading peanut at butter reminds me of visi.com opera!! I wonder why? From stanislav.paska at kios.sk Tue Aug 3 04:02:42 2004 From: stanislav.paska at kios.sk (Stano Paska) Date: Tue, 03 Aug 2004 10:02:42 +0200 Subject: advice for perl expert wanting to learn python In-Reply-To: References: Message-ID: <410F46A2.9010901@kios.sk> Zeljko Vrba wrote: > Now, why would I like to learn Python: because of IronPython port to CLR. > Perl port to CLR doesn't seem to be coming soon. First Perl6 for Parrot has > to be written, and then other backends.. > > What's the easiest way of learning python knowing perl? Is there somewhere > a 'how-to' cookbook with parallel examples of frequent idioms in perl and > python? http://pleac.sourceforge.net/ > > And most important thing, how does Python deal with database connectivity? > Is there a single API (akin to DBI) for connecting to databases? Yes, python has defined single API > > How does Python support the following databases: > - Oracle > - Postgres > - MySQL > - SQLServer (maybe using freetds?) > - ODBC connectivity (connecting to MS Access) > I have tried MySQLdb package and mdb connectivity through win32com.client package. I read about Postgres and Oracle connectivity... Stano Paska. From nospam at here.com Mon Aug 30 10:02:05 2004 From: nospam at here.com (Richard Townsend) Date: Mon, 30 Aug 2004 15:02:05 +0100 Subject: Getting other file permissions References: Message-ID: On Mon, 30 Aug 2004 13:11:32 +0200, Florian Lindner wrote: > on a Unix System I want to get the file permissions for other. How to get > this? Is os.stat("file").st_mode the right way? How to interpret the > output? See S_IMODE(mode) on page: http://www.python.org/doc/2.3.4/lib/module-stat.html From jjl at pobox.com Wed Aug 11 18:59:04 2004 From: jjl at pobox.com (John J. Lee) Date: 11 Aug 2004 23:59:04 +0100 Subject: ClientCookie References: <6f402501.0408110018.1e4e5ca8@posting.google.com> Message-ID: <87acx1qo1z.fsf@pobox.com> fuzzyman at gmail.com (Michael Foord) writes: > Has anyone used ClientCookie to store cookies ? > I'm going to play around with 'pickling cookies' - but I wondered if > anyone had any experience of this. > > (For session persistence in approx - my cgi proxy) Just thought to add: 1. are you using a database for this? (you should be) Look at BSDDBCookieJar. BSDDBCookieJar isn't well-tested, but might be just the ticket for what you're doing. It's not in cookielib yet, but the one from ClientCookie 0.9.x should work fine with cookielib, and I'll make it available in a separate package RSN, along with the other stuff in ClientCookie but not in cookielib. 2. here's a simpler way (in a sense) of serialising a CookieJar than pickling: cj = cookielib.CookieJar() ... s = [repr(c) for c in cj] and unserialising: cj = cookielib.CookieJar() for cs in s: cj.set_cookie(eval(cs)) ... You'd still need to write something like BSDDBCookieJar, though, if I understand what you're doing. John From jbperez808 at wahoo.com Fri Aug 6 15:34:39 2004 From: jbperez808 at wahoo.com (Jon Perez) Date: Sat, 07 Aug 2004 03:34:39 +0800 Subject: threads: not locking read-only objects Message-ID: <2ni4b4F16u92U1@uni-berlin.de> Is it safe to not put a lock on an object if it will always be read-only in other threads and will only ever be written to in just one and always the same one thread? From h.b.furuseth at usit.uio.no Tue Aug 24 11:14:06 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 24 Aug 2004 17:14:06 +0200 Subject: Regular expression guaranteed to fail References: <96jmi0pt39frp5n3r34afrt21cfeclp0mi@4ax.com> Message-ID: Greg Chapman wrote: > Why not just "(?!)": this always fails immediately (since an empty pattern > matches any string, the negation of an empty pattern match always fails). It's fine for re.match. 'Why not?': Because I'd expect re.search to walk through the entire string and check if each position in the string matches that regexp. Unfortunately, a little timing shows that that happens with _every_ regexp suggested so far. Long strings take longer for each of them. (Except Jeremy's solution, of course, which avoids the whole problem.) r'\A(?!)' or r'\Ax\A' didn't work either. Anyway, I note that r'x\A' beats all the other regexps suggested so far with a factor of 20 when searching 's'*10000. -- Hallvard From jmfbahciv at aol.com Sat Aug 28 06:30:03 2004 From: jmfbahciv at aol.com (jmfbahciv at aol.com) Date: Sat, 28 Aug 04 10:30:03 GMT Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4dyXc.25792$Ot3.22106@twister.nyc.rr.com> <878yc0ucyl.fsf@thalassa.informatimago.com> <20040827135423.154$1T@newsreader.com> Message-ID: <41307146$0$19703$61fed72c@news.rcn.com> In article , "David Schwartz" wrote: > > wrote in message >news:20040827135423.154$1T at newsreader.com... > >> "David Schwartz" wrote: > >>> I don't follow you at all. I think you'll find the most useful, >>> meaningful complaints about, say, a Ford Explorer from the people who >>> drive one every day. > >> And if they continue to drive one everyday, perhaps you would conclude >> that their complaints are insincere. > > That's a load of crap. Sigh! Another one who has no appreciation of irony. /BAH Subtract a hundred and four for e-mail. From wweston at att.net Mon Aug 9 12:00:17 2004 From: wweston at att.net (wes weston) Date: Mon, 09 Aug 2004 16:00:17 GMT Subject: berkeley db delete problem? In-Reply-To: References: Message-ID: Oliver Peek wrote: > Hi all, > > Probably my fault, I'm opening a Berkeley DB > file, iterating through and deleting keys, well > making an attempt. I get this error when I try > to delete. > > ---error > Traceback (most recent call last): > File "./db.py", line 41, in ? > db.delete() > AttributeError: delete > ---end error > > Below is a code snippet: > ---code > #!/usr/bin/python > > import bsddb > > db = bsddb.btopen('./test.db', 'r') > > rec = db.first() > while rec: > key, val = rec > db.delete() > rec = db.next() > > db.close() > ---end code > > I have full code that opens and goes through and > prints the key and value and opens another db > file and inserts the key/data into that new db > file, but I need to delete the data out of the > master db file once it's been updated in the > smaller ones. > > I've also tried db.delete(key) with no luck, > db.del(), db.del(key), db[key]='', and lots of > other silly attempts, but nothing works. > > Thanks, > Oliver > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com Oliver, Does clear() work? wes From mudd at vex.net Fri Aug 6 12:49:36 2004 From: mudd at vex.net (mudd at vex.net) Date: Fri, 6 Aug 2004 12:49:36 -0400 (EDT) Subject: static python build? In-Reply-To: References: Message-ID: <16109.12.151.80.14.1091810976.squirrel@webmail.vex.net> Yes, thanks!, it was easy. I just edited Modules/Setup as follows: (1) Changed the commented *shared* line to the *static* line (see below). (2) Uncommented the modules (math, time, array) that I wanted incorporated into the static libpython.a library. (3) Added lines for a couple other modules (strop & _random) that previously weren't listed in the Setup file. (4) Reran configure, make & make install. It works! Now I can run freeze.py and build a truly stand-alone executable including the modules I mentioned. Here's a section of Modules/Setup with my changes: -------------------------------------------------------------------------- # Uncommenting the following line tells makesetup that all following # modules are to be built as shared libraries (see above for more # detail; also note that *static* reverses this effect): *static* # Modules that should always be present (non UNIX dependent): array arraymodule.c # array objects #cmath cmathmodule.c # -lm # complex math library functions math mathmodule.c # -lm # math library functions, e.g. sin() #struct structmodule.c # binary structure packing/unpacking time timemodule.c # -lm # time operations and variables #operator operator.c # operator.add() and similar goodies #_weakref _weakref.c # basic weak reference support #_testcapi _testcapimodule.c # Python C API test module strop stropmodule.c _random _randommodule.c -------------------------------------------------------------------------- > mudd at vex.net writes: > >> How do I build Python so that I get static libraries instead of dynamic libraries (e.g. build/lib.solaris-2.8-sun4u-2.3/math.so)? > > Edit Modules/Setup. The comments in the file should get you started. > > Cheers, > mwh > > -- > Monte Carlo sampling is no way to understand code. > -- Gordon McMillan, comp.lang.python > -- > http://mail.python.org/mailman/listinfo/python-list > From sholden at flexal.cs.usyd.edu.au Wed Aug 11 03:56:38 2004 From: sholden at flexal.cs.usyd.edu.au (Sam Holden) Date: 11 Aug 2004 07:56:38 GMT Subject: rsa implementation question References: <1092200894.4119a9beb1978@www-mail.usyd.edu.au> <200408110852.57937.heikowu@ceosg.de> Message-ID: On Wed, 11 Aug 2004 17:17:15 +1000, Ajay Brar wrote: > thanks > i am using RSa for signing documents and hence decrypting and then > encrypting to verify? > what i was rather trying to get at was what if the plaintext is too > large? if the plaintext is greater than (log2 n)/8, would you just throw > an error or would you break the plaintext in parts. > the reason i am asking this is because i am timing the sign operations > using the pcrypto package. the time is constant relative to the size of > the plaintext (as you would expect) but at a certain point there is an > increase in the time taken to sign. this corresponds to a very large > plaintext. > that is why i was wondering about the block thing. If there is a sudden increase then in time then chances are you just hit a cache barrier - the size before the increase fit into a cache of some form (be it L1, L2, main memory, disk, etc) but the size after the increase doesn't and hence you hit L2, main memory, disk, network, etc. Of course that's just a general observation I know nothing about the workings of RSA (well I did implement it once, but that was *long* ago). Whenever I've done signing with say GnuPG of largish items (such as tarballs of code) I generate an MD5 sum of the item and then sign that, giving something like: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 9272bee983085f56aa830ae909f9b8dc pywily.tgz -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFA9j+tH/cbVr+0UoYRAn3OAJ0bMW3HbbXsuFGZ7H9DK5iMLpBDtwCgkSvB Dj03m5eKTODAA6OKQc34HG4= =52FO -----END PGP SIGNATURE----- I've never actually cared enough to investigate whether that significantly reduces the security. A smarter person would include the filesize in the signed portion especially since you can append to tgz files to generate the MD5 sum you want for your replacement pywily.tgz... [snip a full-quote... is that acceptable around these parts?] -- Sam Holden From grante at visi.com Fri Aug 6 10:54:07 2004 From: grante at visi.com (Grant Edwards) Date: 06 Aug 2004 14:54:07 GMT Subject: 'Using is not None, may not always work' References: Message-ID: <41139b8f$0$65604$a1866201@newsreader.visi.com> On 2004-08-06, Doug Fort wrote: > Since I installed 2.4a2 I've been getting a warning from > pychecker: Using is not None, may not always work'. Huh?! That implies that there are cases where "None is not None" will evaluate as True. I find that extremely hard to believe. > I thought 'is not None' was the right thing to do. It's certainly what I want to do if I want to know if a name is bound to None or not. > I've had problems with 'if not x:', because some objects > return False in this context. Exactly. -- Grant Edwards grante Yow! I was in a HOT at TUB! I was NORMAL! I was visi.com ITALIAN!! I enjoyed th' EARTHQUAKE! From paolo.veronelli at yahoo.it Sun Aug 22 06:49:35 2004 From: paolo.veronelli at yahoo.it (Paolo Veronelli) Date: Sun, 22 Aug 2004 12:49:35 +0200 Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? In-Reply-To: References: Message-ID: <41287A3F.2080303@yahoo.it> Some morphological images suggest me "through" can be a keyword as it hide the verb filter which can be a little more general then others. Anyway using a verb or a noun doesn't suggest the orthogonality of the piece,so please consider adverbs as clever candidates. Paolino From arargh407NOSPAM at NOW.AT.arargh.com Tue Aug 31 15:58:32 2004 From: arargh407NOSPAM at NOW.AT.arargh.com (arargh407NOSPAM at NOW.AT.arargh.com) Date: Tue, 31 Aug 2004 14:58:32 -0500 Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <%T%Yc.29567$Es2.11957889@news4.srv.hcvlny.cv.net> <4134a207$0$65568$a1866201@newsreader.visi.com> Message-ID: On 31 Aug 2004 16:06:31 GMT, Craig A. Finseth wrote: >When they went to MS/DOS 2.0 and needed path separators, they found >that "/" was already taken, so they used "\". But there was a hidden >way to tell the command interpreter that it could use "-" for options. Which got removed quite some back. >And in all systems starting with 2.0, the system calls have taken "/" >and "\" interchangably. -- Arargh407 at [drop the 'http://www.' from ->] http://www.arargh.com BCET Basic Compiler Page: http://www.arargh.com/basic/index.html To reply by email, remove the garbage from the reply address. From grante at visi.com Thu Aug 26 21:43:40 2004 From: grante at visi.com (Grant Edwards) Date: 27 Aug 2004 01:43:40 GMT Subject: A newbie in need.... References: <9c3edc58.0408261609.6640e400@posting.google.com> Message-ID: <412e91cc$0$62953$a1866201@newsreader.visi.com> > Hey everybody. I'm trying to make a program that requires a 2D > field to run. No clue what that means... > Besides "curses" or "ncurses", is there a python module that > will create a graph? I never knew that [n]curses did graphing (and I've used it quite a bit). I use the Gnuplot module when I need to create a graph: http://gnuplot-py.sourceforge.net/ -- Grant Edwards grante Yow! Did you find a at DIGITAL WATCH in YOUR box visi.com of VELVEETA?? From pm_mon at yahoo.com Fri Aug 13 14:46:37 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Fri, 13 Aug 2004 14:46:37 -0400 Subject: Rather than decorators, how about sections? In-Reply-To: <411C12D4.7010400@yahoo.com> References: <411C12D4.7010400@yahoo.com> Message-ID: Steve wrote: > Then, later, Paul Morrow wrote: > > > Fine, instead of Foo (the name of the class), use the > word klass. > It's a popular name for the first > > parameter of a class method. > > "klass" isn't a word. It is a twee deliberate mispelling of a word. > > It also runs the risk of causing confusion when code is spoken aloud (eg > in actual human-to-human communication using alternating high and low > pressure atmospheric waves to deliver packets of information, or in text > readers for the blind). > > It is bad enough when coders (including myself) choose to deliberately > mispell words, but to make it required is unforgivable. > > Ok I believe that's one vote against 'klass' as a reserved word :-) Then let it be 'cls', which is also popular. Or heck, to be flexible, let it be something you can specify (as an environment variable, compiler setting, etc.). The important point is that we should resist changes to the language that require that the developer specify things that are already clearly inferred thru the form/structure of his/her code. We don't have to specify (with curly braces or whatever) where code blocks start and end, because the form of our code tells us that. It seems natural (to me, and at least one other person) to let the form of a function's formal parameter list designate the type of function: - if the 1st parameter is named 'self', it's an instance method. - if the 1st parameter is 'cls' (or perhaps some suitable synonym), it's a class method. - for all other parameter arrangements, including no parameters, it's a static method. Simple, clear, obvious, intuitive, and I'm sorry, but this is the least ugly of all the alternatives. There is nothing beautiful about at signs, superflous code, clutter... From luismg at gmx.net Sun Aug 8 11:51:16 2004 From: luismg at gmx.net (Neuruss) Date: 8 Aug 2004 08:51:16 -0700 Subject: How do you feel ? References: Message-ID: <278de0e.0408080751.72c98718@posting.google.com> I'll try to explain in my poor English how I feel: WORRIED. I don't know what's gong on with me, but since I started learning programing with Python, I'm experiencing some strange behaviors that are seriously affecting my social life, my work, and my view of the world surrounding me... It's addictive! I just can't stop thinking in terms of objects and functions for the most silly things that come up in my head! I used to have erotic dreams, but now, I just dream about a clean idle window where I can start coding solutions for problems that I never had... It's getting worse and worse... I wonder if there is some kind of help group, like Alcoholics Anonymous or something like that. If there's someone with the same symptoms that wants to share its pain with me, please write. I'm shure we're more than one! From heikowu at ceosg.de Wed Aug 11 18:06:08 2004 From: heikowu at ceosg.de (Heiko Wundram) Date: Thu, 12 Aug 2004 00:06:08 +0200 Subject: ANN: Cryptopia 1.0rc2 Message-ID: <200408120006.08610.heikowu@ceosg.de> Overview ======== Cryptopia is a Python public key cryptography library which was designed around a new wrapper for the GMP library which supports a mutable integer type and exports the gmp_rand* functionality. Currently it offers ElGamal and RSA encryption/signing support and wrapped key classes for these two public key cryptography algorithms which ease safe pickling/unpickling of signatures/key data. Cryptopia will be extended with key management support in the near future (signing keys with other keys and a GPG-like trust system). Cryptopia does not implement symmetric cyphers (such as Blowfish, etc.), and probably never will (unless someone else volunteers to do the work ;)). Dependencies ============ Cryptopia has been designed and tested on a *nix system, and as such I can only be sure that it will build on a *nix system (more specific, Linux and Solaris) with libgmp >= 4 installed. Otherwise, Cryptopia does not require any special dependencies, except a working C compiler and an installation of the Python runtime (distutils). Building ======== python setup.py install Download ======== To download Cryptopia and give it a shot go here: http://www.heim-d.de/~heikowu/Crypto License ======= Cryptopia is licensed under the BSD license. Look into LICENSE (contained in the archive) for more info. Feedback ======== Mail me directly. I'd be grateful if I could hear some feedback on building/using the library on other machines, esp. Windows. Further comments ================ If anybody knows of a better name, feel free to contact me off list. ;) From edreamleo at charter.net Fri Aug 6 11:24:50 2004 From: edreamleo at charter.net (Edward K. Ream) Date: Fri, 6 Aug 2004 10:24:50 -0500 Subject: Confused about pep 318 References: <10h2ihgb8c6fi97@corp.supernews.com><10h4s026oapbhf1@corp.supernews.com><10h4vhcfbsv6t30@corp.supernews.com> Message-ID: <10h78m471inrb16@corp.supernews.com> > Look, you keep insinuating that there was some sort of evil plot to slip > this into Python. I can assure you that this is NOT true, and I'm getting > more than a little bit fed up with this argument. I have never said any such thing, nor did I mean to insinuate any such thing. I have stated, loudly and often, that no proper public notice of recent changes has been made. I stand by that statement. > "Actively mislead the public"? What the hell is that supposed to mean? The fact is that somebody like me, with a big interest in '@', would naturally conclude, on the basis on reading pep 318, that pep 318 has nothing to do with '@'. Moreover, one would conclude, on the basis on reading pep 318, that the pep wasn't even close to a final design, much less an implementation. That is what I meant, and _all_ that I meant, by the phrase "actively misleading". Edward -------------------------------------------------------------------- Edward K. Ream email: edreamleo at charter.net Leo: Literate Editor with Outlines Leo: http://webpages.charter.net/edreamleo/front.html -------------------------------------------------------------------- From franbarlow at mail.com Thu Aug 12 16:15:44 2004 From: franbarlow at mail.com (Fran) Date: 12 Aug 2004 13:15:44 -0700 Subject: Help understanding Scheme's syntax, procedures and calls References: <95f168b0.0408120120.31433dc7@posting.google.com> Message-ID: <95f168b0.0408121215.f89c842@posting.google.com> eddie at holyrood.ed.ac.uk (Eddie Corns) wrote in message news:... > franbarlow at mail.com (Fran) writes: > > >I'm trying to understand a functional language code fragment so I can > >explain its syntax and workings to my non English-speaking background > >neighbour, who is doing her finals. > > >What in heaven's name is this code fragment intending? (In English > >prose if possible). > > >It looks like a fragment from a language called "scheme" > > >(define (this n) > > (if (=n 0) > > 0 > > (= n (this (- n 1))))) > > As given this is almost certainly wrong. The first problem is possibly just a > transcription error in that (=n 0) should probably be (= n 0). The second one > is the that the last line doesn't make sense. It looks like someone is > confused about how if statements work. Since this looks suspiciously like > homework I'm only giving a hint. If statements work like > (if expr1 > (expr to return if exp1 is true) > (expr to return if exp1 is false)) > Since each arm is an expression to evaluate it means you evaluate '=' as a > function in the last line hence it returns a boolean, which is going to cause > you grief after a short while. > > >(define (f1 a b) > > (if >b a) > > 0 > > (+ b (f1 a (+ b 1))))) > > This is wrong syntactically (hint: the first expression for the if statement) > > The questions wouldn't make sense until you fixed the functions. > > There is a comp.lang.scheme incidentally. > > Eddie Thanks for the help. It's not homework but from an old exam paper, but the girl's English isn't absolutely fluent and I'm looking for a simple way to explain the expressions and functions. FRAN From FBatista at uniFON.com.ar Thu Aug 26 08:56:11 2004 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Thu, 26 Aug 2004 09:56:11 -0300 Subject: Converting hex string to an integer Message-ID: [Rick Holbert] #- > Given the character string "0x00A1B2C3" arriving at #- sys.argv[1] how do I #- > convert that to an integer which I can do some math on? #- #- i = eval(sys.argv[1]) This is *DANGEROUS*. Never do that. You're executing something that you get from the exterior without control! Just think what happens if a pass to the program "import os;os.remove('/')" . Facundo -------------- next part -------------- An HTML attachment was scrubbed... URL: From bjg at network-theory.co.uk Fri Aug 27 05:04:13 2004 From: bjg at network-theory.co.uk (Brian Gough) Date: 27 Aug 2004 10:04:13 +0100 Subject: print question - character representation References: Message-ID: <87vff59cky.fsf@network-theory.co.uk> Ajay writes: > i am calculating a digest of some data (using hmac) and printing it to a > cookie. the problem is the hash may contain special characters. when these > are printed they get converted to \ representation. > later when i receive the cookie i recalculate the hmac and do a comparison > which returns false because of the conversion when writing to a cookie > q - how do i stop the conversion from happening? Use the hexdigest() method instead of digest() to avoid non-printable characters. See the hmac library documentation for details. -- Brian Gough Network Theory Ltd, Publishing the Python Manuals --- http://www.network-theory.co.uk/python/ From A.M.Gimblett at swansea.ac.uk Sun Aug 15 19:49:09 2004 From: A.M.Gimblett at swansea.ac.uk (Andy Gimblett) Date: Mon, 16 Aug 2004 00:49:09 +0100 Subject: Indentation In-Reply-To: <20040815212516.54857.qmail@web50010.mail.yahoo.com> References: <20040815212516.54857.qmail@web50010.mail.yahoo.com> Message-ID: <20040815234909.GA4756@cspcag.swan.ac.uk> On Sun, Aug 15, 2004 at 02:25:15PM -0700, Bigbowser wrote: > > I've been using C++ for about a year now, and i decided to have a go > at python but one thing i can't get used to is the indentation, > especially as my functions become more and more nested .. What, don't you nest your C++ code? If your nests are getting too deep for comfort, you almost certainly need to rethink your program structure. -- Andy Gimblett Computer Science Department University of Wales Swansea http://www.cs.swan.ac.uk/~csandy/ From Scott.Daniels at Acm.Org Wed Aug 25 11:07:43 2004 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 25 Aug 2004 08:07:43 -0700 Subject: internal functions [Re: How do you feel ?] In-Reply-To: <4117862E.3000907@charter.net> References: <4117862E.3000907@charter.net> Message-ID: <412cace1$1@nntp0.pdx.net> Howard Stearns wrote: > Sorry. When I said "define a named function in a top-level assignment", > I didn't just mean using a reference to a previously defined function > (i.e., it's name), I meant actually defining the function in the > assignment. > > If you haven't done this sort of thing for years, I could see it being > hard to imagine why I would want to do this. After all, isn't the code > clearer if we define the function with a name ahead of time? And doesn't > the debugger work better with functions that have a name? > > Well, I agree with this for what might be called middle-ground uses. > However, I do a lot of work with very simple cases and very complicated > ones. > > In very simple cases, the code is more cluttered if I have to define the > function separately. Now, when the function is simple, Python let's me > define an anonymous function in the assignment. That's cool. But I also > have cases where the assignment is simple, but maybe the function isn't. > This came up for me when I tried to populate generic functions with > methods. (See generic functions thread. Though it looks like decorators > will soon help me out here...) > > In very complex cases, I lament the shear distance between the function > definition and the one place in the code where it is referenced. (Again, > maybe decorators will help. Cool.) > > > > Peter Hansen wrote: > >> Howard Stearns wrote: >> >>> The one thing I've found annoying is that I haven't yet discovered >>> how to do whatever I want in lambda expressions. I have top-level >>> assignments where I'd like create a function to use as the the value >>> being assigned. I don't know how to define a named function in a >>> top-level assignment, and a lambda won't allow me to use 'try' and >>> other statements -- just expressions. Or am I looking at things wrong? >> >> >> >> What do you mean by "top-level assignment"? If it's the same >> meaning most Python programmers would give it, you just do this: >> >> def somefunc(): >> pass >> >> topLevelName = somefunc >> >> There's your top-level assignment of a named function. Probably >> not what you meant, but can you clarify please? >> >> -Peter > > Maybe this is what you mean: def dodef(val): global globfunc def globfunc(other): return val, other This works just fine. -Scott David Daniels Scott.Daniels at Acm.Org From squirrel at WPI.EDU Sun Aug 1 18:33:33 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Sun, 1 Aug 2004 18:33:33 -0400 Subject: transforming a list into a string In-Reply-To: References: Message-ID: On Sat, 31 Jul 2004, Tim Peters wrote: > Absolutely. Note that Peter Otten previously posted a lovely O(N) > solution in this thread, although it may be too clever for some > tastes: > > >>> from itertools import izip > >>> items = ['1','2','7','8','12','13'] > >>> it = iter(items) > >>> ",".join(["{%s,%s}" % i for i in izip(it, it)]) > '{1,2},{7,8},{12,13}' > >>> A bit too clever for mine, mostly because neither izip() nor zip() is guaranteed to process its arguments in a left-to-right order (although there's no reason for them not to). I'd rather do this: >>> from itertools import izip, islice >>> items = ['1','2','7','8','12','13'] >>> it1 = islice(items,0,None,2) >>> it2 = islice(items,1,None,2) >>> ",".join(["{%s,%s}" % i for i in izip(it1, it2)]) '{1,2},{7,8},{12,13}' Although it doesn't improve efficiency any (or have that 'slick' feel), it does prevent needless head-scratching :) Curious, why isn't slicing of generators defined, using islice(), so "it1 = iter(items)[0::2]" is valid? From anthonybaxter at gmail.com Fri Aug 20 15:50:57 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Sat, 21 Aug 2004 05:50:57 +1000 Subject: just ignore Guido's "rejections" [Re: Alternative decorator syntax decision] In-Reply-To: <2uadnbqpMuI1krvcRVn-sg@comcast.com> References: <2uadnbqpMuI1krvcRVn-sg@comcast.com> Message-ID: On Fri, 20 Aug 2004 09:50:18 -0500, Doug Holton wrote: > We can safely ignore Guido's "rejections" when deciding upon an > alternative to agree upon. Many people felt his rejections of C1 (a > longtime community favorite), E1 and other alternatives were wrong. > http://mail.python.org/pipermail/python-dev/2004-August/048134.html Uh, what? No, you _can't_ ignore Guido's rejections - if you really decide that you must have a form he's objected to, you need a _damn_ strong argument to back that up. A "longtime community favorite" doesn't mean a thing - this is language design, not American Idol - that a lot of people like it makes no difference. From sholden at holdenweb.com Tue Aug 31 07:12:40 2004 From: sholden at holdenweb.com (Steve Holden) Date: Tue, 31 Aug 2004 07:12:40 -0400 Subject: Generator expressions v/s list comprehensions In-Reply-To: <1gjdvx3.tjc3nb1266bpkN%aleaxit@yahoo.com> References: <1gj8y77.6qshr41q531veN%aleaxit@yahoo.com> <87llfywooz.fsf@sinken.local.csis.hku.hk> <1gjbs1e.assxlxlud1m0N%aleaxit@yahoo.com> <1gjdvx3.tjc3nb1266bpkN%aleaxit@yahoo.com> Message-ID: Alex Martelli wrote: > Michael J. Fromberger > wrote: > ... > >>>Unfortunately, this wish is totally unrealistic -- obviously people do >>>come up with cool ideas such as the iterator protocol, and generators, >>>after the language has been around for a while. >> >>All the cool features Python has adopted existed a long time before they >>made their way into Python itself. > > > Almost all, not all. As I repeatedly explained, for example, generator > comprehensions are not quite like anything in other languages (though > you can surely find _similarities_, of course). > Indeed, and the reason I like Python is that it has some aspects of Icon mixed in with perhaps the most easily-accessible object-oriented features of any of the programming languages I've learned. > > >>Frankly, I think if the Lisp world had managed to build the same >>friendly and welcoming community Python seems to have, it would have >>taken over the world a quarter-century ago. > > > I think most people's reaction to (==against) Lisp's parentheses and > prefix syntax is more intense than that to Python's significant > whitespace, which appears quite natural to most non-programmers even > though many programmers inured to block delimiters do react strongly > against it. It's hard enough for Python to keep its community welcoming > and friendly when you hear some clueless dweeb rant against indendation > for the thousandth time, I think the Lisp community would have had to be > made up of saints to be still friendly and welcoming after a _million_ > newcomers raised their whining against parentheses. > ... which it clearly isn't :-). I do think the Python community is just a little out-of-the-ordinary, which is what keeps me (and, I suspect, you: great to see you on the wires again) coming back to c.l.py. regards Steve From Jeffrey at Fro.man Sun Aug 22 11:05:40 2004 From: Jeffrey at Fro.man (Jeffrey Froman) Date: Sun, 22 Aug 2004 08:05:40 -0700 Subject: serial iteration over several lists References: <1b5c4527.0408212257.5c9c18b4@posting.google.com> Message-ID: Martin DeMello wrote: > Thanks - that looks like an excellent starting point. Has there been any > work done on bidirectional iterators? You could emulate one by maintaining a counter for the current index into the imaginary flattened list, and iterating up to that index with each prev() call and just past it with each next(). This of course requires that you basically start from the beginning of your nested list each time though, and I'm not sure if it would be more or less efficient than indexing into a pre-flattened list in memory. One more suggestion -- if you use a recursive generator for your iteration, you can then use it with a list nested to arbitrary depth, something like: ############################################# def deep_iter(nested_list): for x in nested_list: if isinstance(x, list): for n in deep_iter(x): yield n else: yield x ############################################# Jeffrey From jaydonnell at yahoo.com Mon Aug 23 19:37:04 2004 From: jaydonnell at yahoo.com (Jay Donnell) Date: 23 Aug 2004 16:37:04 -0700 Subject: urllib hangs References: Message-ID: Thanks again. I found this link http://www.timo-tasi.org/python/timeoutsocket.py which I'm assuming is the most recent version of timeoutsocket.py It's very light on the explanatory side. Do I simply need drop this file into the same directory as my script, import it, and set the timeout??? From peter at engcorp.com Fri Aug 6 07:58:15 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 06 Aug 2004 07:58:15 -0400 Subject: Confused about pep 318 In-Reply-To: References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: <8umdnWrWJtTK747cRVn-uw@powergate.ca> Steven Bethard wrote: > Even the list-after-def syntax, > which doesn't introduce semantics changes, isn't substantially clearer > to me as a decorator than @ is -- why is a list before the : a list of > decorators? Seems almost as arbitrary as @. The list-after-def is in that one sense as arbitrary as @, but at least it feels more like Python. It would be clear that the decorators are applied in the order presented in the list, and since the list clearly isn't be a normal list (coming before the def), anyone reading it would know that it must have something to do with the function definition. (Anyway, as has been pointed out, the Java-based @ syntax is not entirely arbitrary at this point, deriving from the Javadoc comment syntax... I just think doc-generation system syntax embedded inside code comments in another language is a poor place from which to derive syntax for *Python*, which is why I said Python isn't exactly leading in this area, but following, which is sad.) The only negative mentioned for list-after-def that I've seen is that with long argument lists it can be obscured. I wasn't aware of the very wide range of possible uses for decorators (not that I think many of them are really that important), but it does seem likely that with much more than staticmethod/classmethod around, something like @ will end up being required because decorators will add so much to the language that someone will be incapable of using Python without knowing all about decorators. (Viz. e.g. the "singleton" example, or "onexit") If decorators will be used as much as it appears they will be, then the "pie" syntax with the @ sign is perhaps best, simply because it is so "in your face". Barry named it well... (I would like to see an alternative with "from __future__ import " as well, but I'm not the one doing the work on this...) -Peter From jzgoda at gazeta.usun.pl Wed Aug 18 15:42:16 2004 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Wed, 18 Aug 2004 19:42:16 +0000 (UTC) Subject: age of Python programmers References: Message-ID: Robert Boyd pisze: > 40. But I'm a late-comer to programming (my 'back in > the day' can't compete with other 40 yo programmers). > So maybe I could say I'm more like 25. ;) Me too, I started programming rather late, when I was 26 and I realised that I will be unable to make (good) living as philosophy graduate, specialized in medieval ethics (st. Thomas, Duns et al.). This makes me "young software developer" still, as I program for 7 years effectively. ;) -- Jarek Zgoda http://jpa.berlios.de/ From max at alcyone.com Tue Aug 10 06:13:41 2004 From: max at alcyone.com (Erik Max Francis) Date: Tue, 10 Aug 2004 03:13:41 -0700 Subject: Python equivalent to a C trick References: <1d7b6d0d.0408092255.1177908e@posting.google.com> Message-ID: <41189FD5.7516D933@alcyone.com> Thomas Kr?ger wrote: > Logic_Test and True_Result or False_Result > > Example: > print (num_eggs > 1) and 'eggs" or "egg" Be very careful that the "True_Result" in your formulation actually is itself a Python true value, or this won't work: print 'egg' + (numEggs == 1 and '' or 's') will not work as expected. -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ Melancholy men, of all others, are the most witty. -- Aristotle From http Thu Aug 26 21:32:34 2004 From: http (Paul Rubin) Date: 26 Aug 2004 18:32:34 -0700 Subject: key storage References: Message-ID: <7xd61dfjrh.fsf@ruckus.brouhaha.com> Ajay writes: > my question is how should these be stored on the server? encryption is > the best solution, but if i encrypt them with another key, the question is > where does this key get stored? It's a hard problem. Really serious systems use crypto coprocessors with hardware-encapsulated keys. A cheesy substitute is to store the keys in a running process on the same server, that your cgi connects to through an AF_UNIX socket when it wants to encrypt something. I have a Python module that does stuff like that. You enter a passphrase when you start the process, and then it keeps running. Of course you have to re-enter the passphrase on reboot or something like that. Slightly out-of-date docs are at: http://www.nightsong.com/phr/crypto/crypto.txt I never released this thing but I guess I could do so pretty soon. I will not make any promises about its security. From birded at verizon.net Mon Aug 23 12:34:51 2004 From: birded at verizon.net (Sherrod Faulks) Date: Mon, 23 Aug 2004 16:34:51 GMT Subject: Jython/Python and javax.swing.* References: <2004082212534416807%birded@verizonnet> <3b2846c4.0408230303.5250ca5@posting.google.com> Message-ID: <2004082312333016807%birded@verizonnet> John, Sorry I didn't reply earlier, but I found out how to do it in the Jython Doc. You must do: from pawt import swing Thanks for helping, though! On 2004-08-23 07:03:12 -0400, crichton314 at btinternet.com (John Crichton) said: > Sherrod Faulks wrote in message > news:<2004082212534416807%birded at verizonnet>... >> I'm using Jython and in the python script I do: >> >> from javax import swing >> result = javax.swing.JOptionPane.showInputDialog(wC, cmd[8:],"Prompt >> from " + client.serverName, JOptionPane.PLAIN_MESSAGE) >> >> wC is a JFrame, cmd is a String and client.serverName is a String. >> It won't show the JOptionPane, why? > > Hi Sherrod, > > Having had a look at my last post after a nights sleep I'm not sure it > was very clear... > > If you change your script to the following it should work: > > import javax.swing as swing > result = swing.JOptionPane.showInputDialog(wC, cmd[8:],"Promptfrom " + > client.serverName, swing.JOptionPane.PLAIN_MESSAGE) > > Cheers, > > John From http Sat Aug 21 23:20:51 2004 From: http (Paul Rubin) Date: 21 Aug 2004 20:20:51 -0700 Subject: Help with Calculater (first program) References: <8ff6f02e.0408211839.4057ff5@posting.google.com> Message-ID: <7xsmafhn8s.fsf@ruckus.brouhaha.com> dave at inthegarage.net (aToaster) writes: > Hey guys, I'm just getting the hang of Python and Tkinter and I could > use some help. I wrote most of the gui for my calculator program, > well I haven't gotten around to putting in the Hey, that was my first tkinter experiment too. http://www.nightsong.com/phr/python/calc.py From grante at visi.com Mon Aug 30 14:02:25 2004 From: grante at visi.com (Grant Edwards) Date: 30 Aug 2004 18:02:25 GMT Subject: Size of a remote URL References: Message-ID: <41336bb1$0$8079$a1866201@newsreader.visi.com> On 2004-08-30, Justin wrote: > Ok. I believe you are correct. I have observed the two MODES of the > download dialog box. HOWEVER there are still some instances in which > Internet Explorer knows the size of something that my code cannot > determine. So now I have this conclusion: The instances where I > cannot get the size but a browser can must exist because I am not > asking the server the right question. I guess you should trace traffic on the connection and see how IE is getting the length. http://www.ethereal.com/ > Perhaps "Content-Length" is not included in the default > headers, but the server will provide this header if it is > asked too? Not that I'm aware of. BTW, what protocols are you talking about? Just HTTP? -- Grant Edwards grante Yow! BARBARA STANWYCK at makes me nervous!! visi.com From steve at hotmail.com Sun Aug 1 21:32:57 2004 From: steve at hotmail.com (Steve) Date: Mon, 02 Aug 2004 11:32:57 +1000 Subject: get attribute from a parent class Message-ID: <410d9a13$1@clarion.carno.net.au> Hi, I have a nested class declaration such as: class A: def __init__(self): self.var = "A's variable" # end def class B: def __init__(self): self.var2 = "B's variable" # end def # end class B # end class A What I want to do is to be able to get class A's 'var' variable from the nested class B. For example, I want to be able to do something like: print "I can see you %s" % a.var but... I don't want to make 'var' a class variable. I want it to be an instance variable but still be viewable by the inner class B. Is this possible? Any suggestions? Thanks Steve From gandalf at geochemsource.com Wed Aug 4 13:37:36 2004 From: gandalf at geochemsource.com (Gandalf) Date: Wed, 04 Aug 2004 19:37:36 +0200 Subject: How to force a single number to be a tuple In-Reply-To: References: Message-ID: <41111EE0.6060701@geochemsource.com> Peter Otten wrote: > File "", line 1 > () == (,) > ^ >SyntaxError: invalid syntax > I said this: "Try to add one comma for each element - that will do the stuff." How many elements do you want? For zero elements, you should add zero commas. ;-) > > >>>>(1) == (1,) >>>> >>>> >False > Of course. The first one is not a tuple. > > >>>>(1, 2) == (1, 2,) >>>> >>>> >True > Yes, because you can omit the last comma if there is at least one element. -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter at engcorp.com Fri Aug 13 10:44:56 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 13 Aug 2004 10:44:56 -0400 Subject: Python indentation deters newbies? In-Reply-To: <3064b51d.0408130615.3fc4a760@posting.google.com> References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: beliavsky at aol.com wrote: > One of the most commmon reasons programmers cite for not trying Python > is that indentation determines the program flow -- they think its > weird. I think programmers who actually try Python adapt quickly and > do not find the indentation rules to be a problem. I think you're right on both counts. For me, the adaptation period was roughly ten seconds... > I wonder if there is a way to remove this initial barrier. Why? Is there really any evidence that the Python community is missing a large number of really excellent programmers merely because they are resistant to the idea of syntactically significant indentation? Yes, it's one of the most common reasons programmers cite as you note above, but in absolute terms I doubt it's that significant. > I'm not saying that Python's use of indentation is bad, just that it > stops many programmers from trying it. I really question whether we are looking for such programmers. They sound rather close minded and perhaps even lazy... -Peter From webworldL at yahoo.com Fri Aug 6 22:23:01 2004 From: webworldL at yahoo.com (webworldL at yahoo.com) Date: Sat, 07 Aug 2004 02:23:01 -0000 Subject: processing XHTML1.1 documents with xml.sax Message-ID: Has anybody had any luck processing XHTML1.1 documents with xml.sax? Whenever I try it, python loads the W3C DTD from the top, then crashes saying that there's an error in the external DTD. All I need to do is rip through a bunch of XHTML documents and extract some data, does anybody know a quick way to do this without sax making outgoing network connections and fussing with DTDs? BTW, the code to reproduce the error if anybody cares: below is a document 'hello.html' produced by the W3C's Amaya: Hello World

    hello world!

    and the script: import xml.sax.handler xml.sax.parse("hello.html", xml.sax.handler.ContentHandler() ) the error: SAXParseException: http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-framework-1.mod:89:0: error in processing external entity reference will be thrown. From yong at net.tamu.edu Wed Aug 18 11:48:24 2004 From: yong at net.tamu.edu (Yong Wang) Date: Wed, 18 Aug 2004 10:48:24 -0500 (CDT) Subject: readlines() Message-ID: <20040818154825.4068B1589B@net.tamu.edu> Hi, I use readlines() to read one data file. Python automatically parses the read contents into a list of lines. When I used list[0] to print out the 1st line, it is ok. When I use the list index 2 to print out the 2nd line , there is an error mesage. I only need one line of input data file in the middle of the file. For example, I have data file like: --------------------------------------------------------------------------- Timestamp: Sat Aug 7 11:14:57 AM Adapter Address: 00:60:08:2A:C9:5A IP Address: 165.91.10.244 Directory ID: 0675392c736079cfd81a55028df3cb43 Domain Name: bdanwood.dsl.tamu.edu DHCP/NIM Action: lease renewed Comments: --------------------------------------------------------------------------- Timestamp: Sat Aug 7 11:15:56 PM Adapter Address: 00:60:08:2A:C9:5A IP Address: 165.91.10.244 Directory ID: 0675392c736079cfd81a55028df3cb43 Domain Name: bdanwood.dsl.tamu.edu DHCP/NIM Action: lease renewed Comments: --------------------------------------------------------------------------- I have some codes: ....... for line in db1: (ip, mac) = string.split(line) print 'ip is ', ip run = 'dhcpacct --ip=%s > tt1' os.system(run) getdata = open('tt1', 'r') data = getdata.readlines() print 'data[0] is', data[0] print 'data[3] is', data[3] getdata.close() When run the codes, I got: data[0] is --------------------------------------------------------------------------- data[3] is Traceback (innermost last): File "com1", line 64, in ? print 'data[3] is', data[3] IndexError: list index out of range How can I fix it ? Thanks, From peter at semantico.com Thu Aug 12 07:41:44 2004 From: peter at semantico.com (Peter Hickman) Date: Thu, 12 Aug 2004 12:41:44 +0100 Subject: Help understanding Scheme's syntax, procedures and calls In-Reply-To: <95f168b0.0408120120.31433dc7@posting.google.com> References: <95f168b0.0408120120.31433dc7@posting.google.com> Message-ID: <411b577a$0$20523$afc38c87@news.easynet.co.uk> Unfortunately it looks more like 'broken scheme'. Fran wrote: > (define (this n) > (if (=n 0) > 0 > (= n (this (- n 1))))) That looks fine, however: > (define (f1 a b) > (if >b a) > 0 > (+ b (f1 a (+ b 1))))) Has 6 (s and 7 )s. I expect that the seconds line should read (if (> b a) > (define (that n) > (f1 n1) Again there is an imbalance in the ( and ), I think the second line should read (f1 n 1)), note the space between then 'n' and the '1'. Is this someone's homework by any chance? From timrice at nospam-gmail.com Sat Aug 28 02:53:32 2004 From: timrice at nospam-gmail.com (Tim Rice) Date: Sat, 28 Aug 2004 02:53:32 -0400 Subject: wxTheClipboard problem, IDLE vs PythonWin Message-ID: I have a need to write data to the Windows clipboard from a Python script. I found a nice, simple solution @ http://wiki.wxpython.org/index.cgi/ClipBoard. The problem is, I can only get it to work from within the PythonWin and SPE IDE's. I get errors if I try to run the exact same code from the command line or via IDLE's interactive shell. I can't figure it out. Any ideas? Possibly something missing from my PYTHONPATH environment variable? Any help is appreciated. Thanks, Tim >From PythonWin (works fine): >>> from wxPython.wx import * >>> wxTheClipboard.Open() True >>> wxTheClipboard.Clear() >>> wxTheClipboard.SetData(wxTextDataObject("Test 1")) True >>> wxTheClipboard.Close() >>> ## ctrl+v = Test 1 >From IDLE (doesn't work): >>> from wxPython.wx import * >>> wxTheClipboard.Open() True >>> wxTheClipboard.SetData(wxTextDataObject("Test 2")) False >>> ## ctrl+v = Test 1 >>> wxTheClipboard.Clear() >>> ## ctrl+v = Test 1 >>> wxTheClipboard.Close() >From Python (command-line) (doesn't work, more verbose errors): >>> from wxPython.wx import * >>> wxTheClipboard.Open() True >>> wxTheClipboard.SetData(wxTextDataObject("Test 3")) 02:17:48: Error: Failed to put data on the clipboard (error -2147221008: coIniti alize has not been called.) False >>> wxTheClipboard.Clear() 02:17:56: Debug: ..\..\src\msw\clipbrd.cpp(554): 'OleSetClipboard(NULL)' failed with error 0x00000002 (the system cannot find the file specified.). From nid_oizo at yahoo.com_removethe_ Fri Aug 20 03:37:12 2004 From: nid_oizo at yahoo.com_removethe_ (Nicolas Fleury) Date: Fri, 20 Aug 2004 03:37:12 -0400 Subject: Alternative decorator syntax decision Message-ID: Hi all, The part of the Python community that doesn't like @decorators needs to unite behind an alternative syntax to propose to Guido. I suggest we use this thread to try to do it. If you agree with @decorators, then I suggest you stop reading this message;) Many syntaxes have been put on http://www.python.org/moin/PythonDecorators. I suggest to fight the current @descriptors on these two points: - Less Readable. The @ character adds a new character with a magical sense. It doesn't read in english as the rest of Python. - Not Pythonic. It's a line without a block (like try/finally) that affects a following line of code. It breaks interactive shells. I suggest that the alternative syntax is both more readable and more pythonic. Many syntaxes have been ruled out by Guido, but he seems to be open to a new keyword accessible with a "from __future__ import". Since a new keyword would make the syntax more readable (and easier to find doc about), so I suggest to discuss these two alternatives, not necessarily with these keywords: Proposal 1: decorate: staticmethod def foo(a, b): ... decorate: accepts(int,int) returns(float) def bar(low, high): ... other possible keywords: predef, from, as, with This proposal has basically the advantages of @decorators with a more Pythonic approach. The main drawback is that the decorate block doesn't contain anything like normal statements, as with @decorators. Implementation already exists. Proposal 2: def foo(a,b): using staticmethod ... def bar(low, high): using accepts(int, int) using returns(float) other possible keywords: decorate, transform, with, postdef, as The pool on Wiki suggest that most people would prefer an inside def syntax. It would place decorators at the same place as docstrings, which is very Pythonic, since it's consistent with the rest of the language. The main concern is that it places information that can be important to callers far from the def. I guess the answer would be that it's not that far from the def and that sometimes the parameters names would give strong hints about the decorators. For example, even if it's not forced by the language, a method with a first parameter not named self would be strong hint to check the first line of the body to see if it's a static method, etc. I suggest to force descriptors to be before the docstring to make them as closer as possible to the def and ease finding them. (Another answer could be that scanning down from the def is not that more bad than scanning up from the def). Is there any implementation existing? My questions would be: which of these proposals do you prefer to current @decorators. Both? None? What keywords would you prefer? Do you see any that I have not listed? Do you think there's an alternative that I should have listed, even considering what have been ruled out by Guido? Regards, Nicolas From davebrok at soda.csua.berkeley.edu Sun Aug 22 18:55:23 2004 From: davebrok at soda.csua.berkeley.edu (David Pokorny) Date: Sun, 22 Aug 2004 15:55:23 -0700 Subject: 2 GB files References: <9418be08.0408221427.182a4d30@posting.google.com> Message-ID: "Elbert Lev" wrote in message news:9418be08.0408221427.182a4d30 at posting.google.com... > From postings to this group and other resources I understood that the > only way to make Python programs to work correctly with files lager > then 2 GB is building Python interpreter with some "magic spell" > defines. For me this is ABSOLUTELY unacceptable (Not the building, but Elbert: you might get a positive response if you rephrased your post. "Our corporation needs functionality ___. We would be happy to pay a contract consultant $n000 to come up with a solution that will work with a future trajectory of Python releases." Or you could pray to the OSS gods. David From theller at python.net Fri Aug 27 11:18:37 2004 From: theller at python.net (Thomas Heller) Date: Fri, 27 Aug 2004 17:18:37 +0200 Subject: allowing braces around suites References: <1r3c28g6o9.fsf@rovereto.ifi.uio.no> <1rk6vkeo5d.fsf@rovereto.ifi.uio.no> Message-ID: > [...] >>>Or C-M-\ to re-indent the region "correctly" with respect to its >>>context. This works far more reliably the using TAB to re-indent >>>single lines. >> How do you enter that on a german keyboard? > > CTRL-ALT-ALTGR-? Not for me - it only beeps. Well, maybe because I'm using XEmacs on win2k. Do you mean the function py-indent-region? Apparently this is bound to C-c tab or C-c C-i. Thomas From chrisccc_3k at yahoo.com Tue Aug 10 10:18:13 2004 From: chrisccc_3k at yahoo.com (Chris Connett) Date: Tue, 10 Aug 2004 10:18:13 -0400 Subject: Best pattern/idiom In-Reply-To: <4edc17eb.0408092039.10958e11@posting.google.com> References: <4117c3d8$1@buckaroo.cs.rit.edu> <4edc17eb.0408092039.10958e11@posting.google.com> Message-ID: <4118d928$1@buckaroo.cs.rit.edu> Michele Simionato wrote: > Chris Connett wrote in message news:<4117c3d8$1 at buckaroo.cs.rit.edu>... > >>I was wondering if there were a well known pattern/idiom for breaking a >>sequence into a list of lists, each n elements long, e.g. >> >>[0,1,2,3,4,5,6,7,8,9,10,11] -> [[0,1,2,3],[4,5,6,7],[8,9,10,11]] >> >>This comes up reasonably often in my work, and every time I re-think >>about it, and come up with >>[ lis[n:n+4] for n in range( 0, len( lis ), 4 ) ] >>which seems very kludgy to me, since it uses a range and len, 2 mentions >>of the list identifier and 2 literal 4's (which is the size I want to >>break into this time). >> >>Is there a better way? > > > From a post of mine of some time ago ... > > >>>>import itertools >>>>def chop(it, n): > > ... tup = (iter(it),)*n > ... return itertools.izip(*tup) > ... > >>>>list(chop([1,2,3,4,5,6],3)) [(1, 2, 3), (4, 5, 6)] >>>>list(chop([1,2,3,4,5,6],2)) [(1, 2), (3, 4), (5, 6)] >>>>list(chop([1,2,3,4,5,6],1)) > > [(1,), (2,), (3,), (4,), (5,), (6,)] > > Michele Simionato That's slick! :) Though, objectively, it might be less maintainable, since if I didn't know what it was doing, it'd take me a minute to figure it out. I'll definitely keep that idea in my toolbox though! From newsgroups at jhrothjr.com Fri Aug 13 16:06:40 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 13 Aug 2004 16:06:40 -0400 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> <_d6Tc.23589$Jp6.3458@newsread3.news.atl.earthlink.net> Message-ID: <10hq7qq3mgje578@news.supernews.com> "CptPicard" wrote in message news:_d6Tc.23589$Jp6.3458 at newsread3.news.atl.earthlink.net... > > > I noticed too that, amazingly, a lot of programmers know about Perl but not > Python. Perl has about four times the market penetration of Python. A whole lot of people regard it as "the language" for system administration. As far as percieved barriers to adoption, though, I think "there should be one obvious way to do it" turns a lot of people off when it's compared to Perl's "there's more than one way to do it." Again, though, it just takes some familiarization. John Roth From aleaxit at yahoo.com Mon Aug 30 04:07:40 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 30 Aug 2004 10:07:40 +0200 Subject: Alex Martelli: Welcome back! References: Message-ID: <1gjbrxx.14it2qjhn44ynN%aleaxit@yahoo.com> Delaney, Timothy C (Timothy) wrote: > Alex Martelli wrote: > > > This time around I'm gonna try -- I'm as busy as ever (the 2nd Edition > > of the Python Cookbook is at least as intense a project as the first > > was...), but if I can steel myself to use my killfile 100 times more > > than in the past, and still try to respond on some threads which might > > be interesting or useful. We'll see if it works! > > I've actually found that spambayes works fairly well as a killfile - > enough that I don't bother top maintain any other killfile. It usually > takes about 3 posts added as spam for someone to start disappearing ... Heh, cool idea. Hmmm, I wonder how I could integrate spambayes into my favourite newsreader (these days, that's MacSoup)... Alex From in.aqua.scribis at nl.invalid Mon Aug 30 18:07:46 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Tue, 31 Aug 2004 00:07:46 +0200 Subject: "Content-Length" header In-Reply-To: References: Message-ID: Justin schreef: > I found the answer. After about 3 hours of agonizing over it it turned > out to be CASE > some webservers are CASE SENSITVE about their urls and some are not. There are case-insensitive webservers? Never knew that. -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html From bryanjugglercryptographer at yahoo.com Tue Aug 3 14:27:22 2004 From: bryanjugglercryptographer at yahoo.com (Bryan Olson) Date: 3 Aug 2004 11:27:22 -0700 Subject: Timing Difference: insert vs. append & reverse References: <35b736b9.0408020330.53b24ed3@posting.google.com> Message-ID: <1a517b5.0408031027.60554dfb@posting.google.com> Duncan Booth wrote: > A list is implemented by an array of pointers to the objects it contains. > > Every time you call 'insert(0, indx)', all of the pointers already in the > list have to be moved up once position before the new one can be inserted > at the beginning. > > When you call 'append(indx)' the pointers only have to be copied if there > isn't enough space in the currently allocated block for the new element. If > there is space then there is no need to copy the existing elements, just > put the new element on the end and update the length field. Whenever a new > block does have to be allocated that particular append will be no faster > than an insert, but some extra space will be allocated just in case you do > wish to extend the list further. > > If you expected insert to be faster, perhaps you thought that Python used a > linked-list implementation. It doesn't do this, because in practice (for > most applications) a [array] based implementation gives better performance. True, but an array implementation can easily support amortized constant-time insert/delete at *either* end (without breaking constant-time indexing). The same trick of keeping extra space at the tail end can work at the head; it requires keeping one additional offset to show where the occupied cells start. -- --Bryan From spam_depository2004 at yahoo.com Tue Aug 31 00:33:57 2004 From: spam_depository2004 at yahoo.com (Johnny) Date: 30 Aug 2004 21:33:57 -0700 Subject: Xah Lee's Unixism References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> Message-ID: <2a56f6a3.0408302033.622bf4e2@posting.google.com> Pascal Bourguignon wrote in message news:<87hdqptl96.fsf_-_ at thalassa.informatimago.com>... > > $ telnet xahlee.org 80; > Trying 208.186.130.4... > Connected to xahlee.org. > Escape character is '^]'. > GET / HTTP/1.1 > > HTTP/1.1 400 Bad Request > Date: Fri, 27 Aug 2004 01:35:52 GMT > Server: Apache/2.0.50 (Fedora) > ^^^^^^^^^^^^^^^^^^^^^^ Xah probably couldn't find any LispM based servers. Can you blame him? From curzio.basso at unibas.ch Wed Aug 11 06:30:34 2004 From: curzio.basso at unibas.ch (Curzio Basso) Date: Wed, 11 Aug 2004 12:30:34 +0200 Subject: how to dispatch objects depending on their class In-Reply-To: References: <4118dd4a$1@maser.urz.unibas.ch> <4119d60b@maser.urz.unibas.ch> Message-ID: <4119f54f$1@maser.urz.unibas.ch> Peter Otten wrote: > I'd say the choice of the dispatch mechanism - dictionary lookup vs Duncan > Booth's name-mangling - is independent of the question whether the visitor > pattern applies. Duncan's setup would then become something like > > class VisitorMixin: > def accept(self, visitor): > visitor.dispatch[self.__class__](self) > > class Visitor: > def __init__(self): > self.dispatch = {A: self.visit_A, B: self.visit_B} > def visit_A(self, a): > pass > def visit_B(self, b): > pass > Yes, the dispatching would be not necessary if no mixin was used. Which is not desirable, however, because it would add a dependency between the subclass and the visitor. thanks again, I got a lot of useful advices. cheers, curzio From peter at engcorp.com Fri Aug 20 15:36:22 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 20 Aug 2004 15:36:22 -0400 Subject: Alternative decorator syntax decision In-Reply-To: References: <3A81C87DC164034AA4E2DDFE11D258E3022E14@exchange.hqamor.amorhq.net> Message-ID: Bernhard Herzog wrote: > Steven Bethard writes: >>I would advise against this. GvR has said from the beginning that he >>doesn't want to see a vote > > Er, you're already having a vote :-) Er, but Guido doesn't have to see it. :-) >>-- he wants to see convincing proposals and a more or less >>unified community support. > > Yes. But what if the majority of the community favors pies of J2? Then it's a certainty that we'll hear at high volume from that community when the time comes. Now is not their time. (Or, to put it another way, they are quite capable of holding their own vote... this is c.l.p, home of the daily syntax vote!) There is a subset of the community which disfavours @pie (many intensely). Let them hold their vote to figure out which, if any, alternative they can widely support. If there is wide support for an alternative, it will be a very simple matter at that point, *if* a vote is required, to decide which of the two (@pie or the dark horse candidate) is preferred. I really hope that at that point, however, instead of us having a vote, Guido steps in and says either of these, and then the majority will shut up: 1. "Okay, the community against @pie has spoken, and their choice is X, but for these reasons I reject it and @pie will stay..." or 2. "Okay, the community against @pie has spoken, and their choice is X, and after careful consideration I find this choice has great merit and will reject @pie in favour of it." -Peter From kdahlhaus at yahoo.com Tue Aug 31 08:29:38 2004 From: kdahlhaus at yahoo.com (Kevin Dahlhausen) Date: 31 Aug 2004 05:29:38 -0700 Subject: Web Application - User Management - RBAC References: <412dfc53@news.highway1.com.au> Message-ID: <283adf56.0408310429.7ae36a91@posting.google.com> Webware for Python has a component calld 'UserKit.' It may not be fully production ready as it stands, but could serve as a model. From peter at engcorp.com Thu Aug 12 13:30:16 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 12 Aug 2004 13:30:16 -0400 Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: <411ba1db$1@nntp.zianet.com> References: <60dfb6f6.0408111846.615ee9eb@posting.google.com> <3YWdnYxLf--ObofcRVn-pw@powergate.ca> <411ba1db$1@nntp.zianet.com> Message-ID: Mark Bottjer wrote: > The contention was that indentation is used to indicate the effective > scope in other contexts: e.g., def changes how the statements *indented > under it* are handled (they are packed into a code object instead of > executed immediately), but doesn't change how the next statement at the > same indentation level is handled (the statement result may change, due > to coupling via common data, but the statement itself is handled exactly > as it would be were the previous statement not present). > With this > syntax, though, the decorate block changes how the def statement is > handled, even though they are at the same indentation level. Changes it how? The definition of this whole decorator idea has been that it is equivalent to applying the decorator functions *after* the def has completed, as in "func = decorator(func)". This does not in any way changed how the def statement itself is handled. > Put another way: applying what I know about how indentation is used > elsewhere in Python to this syntax, I would expect the effect of the > decorate statement to be limited to the statements indented under it. I > would not expect it to affect the next statement at the same level > except by the normal coupling of namespace (program state). You don't think of "if" and "else" as being related? When the expression that is evaluated in the if is true, the "else" is skipped over... I know: that's just program state as you said. But so is the effect of the decorator, whether it's spelled "@" or "decorate:"... Anyway, whatever works for @pie syntax should work for decorate: syntax, I would think. @pie is even less like the rest of Python (especially now with this weird "swallow newlines" hack to work around the possibility that people might try to put multiple @decorators on the same line). > Of course, this argument also applies to the prefix @ syntax, but at > least with that we have a funny character cluing us in to the special > behavior. While here we have a nice explicit keyword "decorate:" which one can easily find with a search in the documentation, as opposed to trying to look up a symbol "@". I don't buy the argument that a funny symbol is somehow going to help people who don't already know what decorators are, any more than an explicit "decorate:" line would. Either one says "this is different, go look up what it means" to a newcomer. -Peter From brian at sweetapp.com Fri Aug 13 05:54:00 2004 From: brian at sweetapp.com (Brian Quinlan) Date: Fri, 13 Aug 2004 11:54:00 +0200 Subject: Pyhton Interpreter Startup time In-Reply-To: <411C7262.1000803@cenix-bioscience.com> References: <30260531.0408120829.27a536bc@posting.google.com> <411C7262.1000803@cenix-bioscience.com> Message-ID: <411C8FB8.20901@sweetapp.com> Neil Benn wrote: > As I said the first load takes 5 seconds and the consecutive loads > take fractions of a second - my assumption is that Windows is caching > something which is not suitable for my needs as it is not predictable > enough. Neil, are you using Norton Antivirus with autoprotect enabled? I've seen that cause problems in the past because NAV scans every file as it is opened and Python loads a lot of file on startup. Cheers, Brian From FBatista at uniFON.com.ar Tue Aug 31 13:41:45 2004 From: FBatista at uniFON.com.ar (Batista, Facundo) Date: Tue, 31 Aug 2004 14:41:45 -0300 Subject: about presicion Message-ID: [mensanator at aol.com] #- What I meant was the OP can't compare Decimal and gmpy unless he has #- a version of gmpy that runs in 2.4. Or has a version of Decimal that #- runs in 2.3. Decimal is designed to work in Py2.3 and it will be maintained that way. . Facundo From fakeaddress at nowhere.org Mon Aug 9 22:27:20 2004 From: fakeaddress at nowhere.org (Bryan Olson) Date: Tue, 10 Aug 2004 02:27:20 GMT Subject: Paul Graham on Python hackers In-Reply-To: <3064b51d.0408090448.31806af5@posting.google.com> References: <3064b51d.0408090448.31806af5@posting.google.com> Message-ID: beliavsky at aol.com wrote: > Python, unlike Java, does not force OOP upon you -- it can be treated > as an imperative language. That's kind of fuzzy terminology. Both Python and Java are imperative object-oriented languages. > I think this is a plus especially when > first learning the language or writing small programs. A Hello World > program is just There I agree. > Python to me is a multi-paradigm language (imperative, OO, functional, > generic), like C++ but interpreted and with dynamic typing. Functional? Not so much. In viable functional languages expressions/statement are evaluated primarily for their return values and not their side-effects. (In purely functional languages, there are no side-effects). I don't think it's much like C++ either. In C++, things like identifiers, modules, and classes don't exist at run-time. -- --Bryan From Sibylle.Koczian at Bibliothek.Uni-Augsburg.de Wed Aug 4 05:26:52 2004 From: Sibylle.Koczian at Bibliothek.Uni-Augsburg.de (Sibylle Koczian) Date: Wed, 04 Aug 2004 11:26:52 +0200 Subject: MySQLdb 'server not initialized' In-Reply-To: References: Message-ID: <2nbof3Fv54hfU1@uni-berlin.de> Daniel Baggott schrieb: > Hi, > > I'm seeking assistance in troubleshooting connecting to MySQL (4.0.20) > using Python (2.3.4) and MySQLdb (1.0.0). When I attempt to make a > connection, I get the following exception: > _mysql_exceptions.InternalError: (-1, 'server not initialized') > > The database is definitely running as I can connect to it using the > mysql client. Also, when I attempt to connect to MySQL from within > Python, I don't see any messages in the MySQL logs (ie the .log and .err > files in /usr/local/mysql/data/). > If the server isn't running you'd get another exception anyway: OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10061)") I tried on Windows, but I can't think there's a difference at this point. What happens if you try the same thing with user "root" and his password - just for diagnostic purposes? > Does anyone have any advice or suggestions as to how to figure out > what's going wrong? Also, if there's a better forum for posting this > question, please point me in the right direction. > There is a help forum for MySQLdb on SourceForge: http://sourceforge.net/forum/forum.php?forum_id=70461 But it doesn't look very active to me, at least at the moment. So I wouldn't call it better, just another possibility. Regards, Koczian From reinhold-birkenfeld-nospam at wolke7.net Mon Aug 23 14:00:11 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Mon, 23 Aug 2004 20:00:11 +0200 Subject: esoteric question about dict keys In-Reply-To: References: Message-ID: <2oupg5FehvjoU1@uni-berlin.de> Mel Wilson wrote: > In article , > Alexis Roda wrote: >>Now the question. In "normal" dicts its not possible to use dictionaries >>(nor other kinds of mutable objects) as keys, if I undersand correctly >>this is a technical requirement. If I write my own dictionary-like >>object, on wich the mutability of the keys is not a technical issue, is >>considered blasphemous the use of dicts as keys? For example, querying >>an SQL table can be partially modelled as a dictionary access: > > As I understand it, you can use any object as a key if > you give it a __hash__ method and an __eq__ or __cmp__ > method. You can, after all, use dicts as dict keys if you create your own subclass of dict: class hashdict(dict): def __hash__(self): return id(self) x = hashdict() testdic = {x : "test"} But in order to retrieve the "test" value, you would need to index the testdic with exactly the same instance of the hashdict. And that's why dictionaries are unhashable. Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From hemagician at gmail.com Sat Aug 21 18:11:19 2004 From: hemagician at gmail.com (Daniel Arbuckle) Date: 21 Aug 2004 15:11:19 -0700 Subject: Alternative decorator syntax decision References: Message-ID: My votes (J1, J2, C1) From siona at chiark.greenend.org.uk Thu Aug 12 12:07:09 2004 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 12 Aug 2004 17:07:09 +0100 (BST) Subject: [OT] Keyboard layout, was Re: PEP318 References: Message-ID: Roy Smith wrote: >Sion Arrowsmith wrote: >> As someone who's just started using a Mac for the first time(*), >> I'd like to add that it's not always plain-sailing on an English >> keyboard. >What's wrong with Mac keyboards? No @, hence tangential relevance to PEP318 (and a point against pies, before or after the def). Unless you can remember it's on option-3. -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From uche at ogbuji.net Mon Aug 9 10:35:12 2004 From: uche at ogbuji.net (Uche Ogbuji) Date: 9 Aug 2004 07:35:12 -0700 Subject: Module for converting XML to Python object(s)? References: Message-ID: Fran?ois Pinard wrote in message news:... > [Robert Oschler] > > Has anybody seen a Python module that will take an XML document (not a > > colossal one), and convert it to a Python nested class object? > > You might want to check this announcement: > > From: "Fredrik Lundh" > Date: Fri, 18 Jun 2004 17:07:43 +0200 > Subject: ANN: ElementTree 1.2 final (june 18, 2004) > To: python-announce-list at python.org > Newsgroups: comp.lang.python.announce > > The Element type is a simple but flexible container object, > designed to store hierarchical data structures, such as > simplified XML infosets, in memory. The ElementTree package > provides a Python implementation of this type, plus code to > serialize element trees to and from XML files. ElementTree rocks, but is not really what I understood the OP's request to be. It seems he wants specialized classes matching the XML vocabulary, e.g. print html.head.title You can't really do this with ElementTree. This is the preserve of a different class of XML libraries, called data bindings. I discussed data bindings I know of in my previous response to the OP. Oluyede reminded me of XMLObject. Also, both Eric van der Vlist and Guido van Rossum himself have done recent work in data bindings for XML/Python. Neither's work is packaged for public release yet, though. -- Uche Ogbuji Fourthought, Inc. http://uche.ogbuji.net http://4Suite.org http://fourthought.com Perspective on XML: Steady steps spell success with Google - http://www.adtmag.com/article.asp?id=9663 Use XML namespaces with care - http://www-106.ibm.com/developerworks/xml/library/x-namcar.html Managing XML libraries - http://www.adtmag.com/article.asp?id=9160 Commentary on "Objects. Encapsulation. XML?" - http://www.adtmag.com/article.asp?id=9090 Harold's Effective XML - http://www.ibm.com/developerworks/xml/library/x-think25.html A survey of XML standards - http://www-106.ibm.com/developerworks/xml/library/x-stand4/ From rnichol_rrc at yahoo.com Sat Aug 21 13:57:13 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Sat, 21 Aug 2004 12:57:13 -0500 Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: Peter Hansen wrote: > or mistake... if they did, Americans would properly use "fewer" > in all those cases where they now use "less" incorrectly. > > -Peter I lived in the US for a chunk of time (Berkeley). Let's not get into how the Americans have butchered the english language. From 510046470588-0001 at t-online.de Sat Aug 7 02:32:21 2004 From: 510046470588-0001 at t-online.de (510046470588-0001 at t-online.de) Date: 07 Aug 2004 08:32:21 +0200 Subject: Paul Graham on Python hackers References: Message-ID: <87k6wb4fwq.fsf@debian.i-did-not-set--mail-host-address--so-shoot-me> ellisjb at my-deja.com writes: > Yeah, but Graham goes on to lump perl in with python, it doesn't make much of a difference. They are both infinitely much better than J*** . > so he clearly > doesn't know what he's talking about. :) > > (In all seriousness I think python and java have a lot more in common > than python and perl.) > no, that's not the case, as Java lacks something akin to perl's eval and python's exec. In addition, Java lacks asynchronous system calls and is thus unable to implement the curses library, unlike perl and python. on top of all, perl and python allow to write empty programs, whereas in that crap of Java, it's already hard to write a program that does nothing. Already hello world in Java is a monster that turns away decent hackers. And the Java standard is less opensource friendly than perl, python, scheme, ruby, elastiC, tcl, lua ... and all the other decent languages. Klaus Schilling From ramen at lackingtalent.com Wed Aug 18 12:53:11 2004 From: ramen at lackingtalent.com (Dave Benjamin) Date: Wed, 18 Aug 2004 16:53:11 -0000 Subject: Jython and super_reload? Message-ID: There have been several discussions here about how to write a reload() function that works for classes as well as modules: http://groups.google.com/groups?sourceid=mozclient&ie=utf-8&oe=utf-8&q=super_reload I have been trying to come up with a solution that works for Jython, and so far nothing has worked. I was wondering if anyone has attempted or succeeded in writing such a function for Jython. Thanks, Dave -- .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:. "talking about music is like dancing about architecture." From __peter__ at web.de Fri Aug 6 02:18:30 2004 From: __peter__ at web.de (Peter Otten) Date: Fri, 06 Aug 2004 08:18:30 +0200 Subject: Proposal: require 7-bit source str's References: Message-ID: Hallvard B Furuseth wrote: > Peter Otten wrote: >>Hallvard B Furuseth wrote: >> >>> Now that the '-*- coding: -*-' feature has arrived, >>> I'd like to see an addition: >>> >>> # -*- str7bit:True -*- >>> >>> After the source file has been converted to Unicode, cause a parse >>> error if a non-u'' string contains a non-7bit source character. >> >> Could >> >> # -*- coding: ascii -*- >> >> be sufficient? > > No. It would be used together with coding: . The > point is to ensure that all non-ASCII strings are u'' strings instead > of plain strings. OK. >> Why would you reintroduce ambiguity with your s-prefixed >> strings? > > For programs that work with non-Unicode output devices or files and > know which character set they use. Which is quite a lot of programs. I'd say a lot of programs work with non-unicode, but many don't know what they are doing - i. e. you cannot move them into an environment with a different encoding (if you do they won't notice). >> The long-term goal would be unicode throughout, IMHO. > > Whose long-term goal for what? For things like Internet communication, > fine. But there are lot of less 'global' applications where other > character encodings make more sense. Here we disagree. Showing the right image for a character should be the job of the OS and should safely work cross-platform. Why shouldn't I be able to store a file with a greek or chinese name? I wasn't able to quote Martin's surname correctly for the Python-URL. That's a mess that should be cleaned up once per OS rather than once per user. I don't see how that can happen without unicode (only). Even NASA blunders when they have to deal with meters and inches. > In any case, a language's both short-term and long-term goals should be > to support current programming, not programming like it 'should be done' > some day in the future. Well, Python's integers already work like they 'should be done'. I'm no expert, but I think Java is closer to the 'real thing' concerning strings. Perl 6 is going for unicode, if only to overcome the limititations of their operator set (they want the yen symbol as a zipping operator because it looks like a zipper :-). You have to make compromises and I think an external checker would be the way to go in your case. If I were to add a switch to Python's string handling it would be "all-unicode". But it may well be that I would curse it after the first real-world use... Peter From peter at engcorp.com Tue Aug 17 09:47:28 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 17 Aug 2004 09:47:28 -0400 Subject: Python indentation deters newbies? In-Reply-To: References: <3064b51d.0408130615.3fc4a760@posting.google.com> <30260531.0408131853.18ec2446@posting.google.com> <412040f8$0$8087$a1866201@newsreader.visi.com> Message-ID: Antoon Pardon wrote: > Op 2004-08-17, Peter Hansen schreef : >>Some people have, in spite >>of your claims that it's not possible, managed to produce >>useful and interesting answers, and for that I thank them. > > I would be most surprised if I made such a claim. > > Please provide me with a reference so that I can apologize > if I actually did this. No, the apology is mine. You picked up on the argument Grant and Paramjit were making, but I wasn't paying attention to the ever-changing debater in this discussion and misremembered all the posts as being yours. -Peter From imbosol at aerojockey.com Thu Aug 12 00:08:26 2004 From: imbosol at aerojockey.com (Carl Banks) Date: 11 Aug 2004 21:08:26 -0700 Subject: Python script to generate static site? References: Message-ID: <60dfb6f6.0408112008.60f35daf@posting.google.com> Fred wrote in message news:... > Hi, > > I'm sure there are a bunch of them, but googling just returned > full-fledged CMS that require a DBMS and generate dynamic pages. > > I'd just like a script that would > 1. look in a directory for articles in raw HTML, > 2. generate a cooked output for each page (ie. add header and footer, > CSS link in HEAD, etc.), > 3. regenerate the homepage with "Last modified" bit following each > article's title, > 4. ready to be uploaded by FTP to a web server that only handles > static web pages. > > Considering Python's wealth of libraries, it's most likely only a > couple hours' work, but since I'm pretty much a Python newbie... If I may humbly plug my own project, you might try HRL: http://www.aerojockey.com/software/hrl In fact, the example on the home page pretty much does exactly what you ask. It's very versatile for generating static pages, I'd say. Maybe too versatile. If you'd like to be able to use the power of Python to automate various tasks that come along, this might be what you want. If you just want 1, 2, 3, and 4 for all eternity, you might prefer something less deep. Also, it supports Unicode, if you need that. -- CARL BANKS From fumanchu at amor.org Wed Aug 4 19:45:40 2004 From: fumanchu at amor.org (Robert Brewer) Date: Wed, 4 Aug 2004 16:45:40 -0700 Subject: Finding all time periods for a given interval within a daterange Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022DDE@exchange.hqamor.amorhq.net> I wrote: > Look at my 'recur' module and see if it fits your requirements: > > http://www.aminus.org/rbre/python/index.html Tim Churches: > How is the above code licensed? Me: > Anything on that page is public domain. Use it as you see fit. Tim: > Would you be so kind as it include a note in the actual code > to that effect? Copyright needs to be explicitly waived in most > countries these days (unlike previously when copyright needed > to be explicitly claimed). Sure thing. Give me a couple of days. FuManChu From domcio_ at poczta.onet.pl Mon Aug 16 04:16:20 2004 From: domcio_ at poczta.onet.pl (Leszek) Date: Mon, 16 Aug 2004 10:16:20 +0200 Subject: COM (DispatchEx) problem Message-ID: Hi everybody ! I'm starting my script with: ie = win32com.client.DispatchEx("InternetExplorer.Application") ie.Visible = 1 ie.Navigate("http://www.chip.pl") while ie.Busy == True: win32api.Sleep(1000) doc = ie.document then I make "submit" and new page opens. but print doc.body.innerHtml gives the same Html code than before "submit". What is going on ? How to see new document ? Thanks for any help. Leszek From peter at engcorp.com Thu Aug 12 23:08:29 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 12 Aug 2004 23:08:29 -0400 Subject: Flython? In-Reply-To: References: Message-ID: Christopher T King wrote: > On Thu, 12 Aug 2004, Peter Hansen wrote: > > >>In the vein of Jython, I wonder what it would take to build >>a Flython? (Lousy name, I know.) That would take Python >>source, presumably a subset since some things couldn't be supported, >>and compile it into ActionScript bytecode (aka the bytecode compiled >>from ECMAScript source for the Macromedia Flash player environment). > > I don't know much about ActionScript bytecode, but I think a general > Python -> ECMAScript translator wouldn't be too hard (presuming a Python > subset is acceptable). ECMAScript variables are untyped, so that should > ease translation some. Sounds like my weekend project! Well, it's not the source code that I care about, it's the object code (as in, the Flash bytecode). The only ECMAScript to Flash bytecode compilers of which I'm aware are commercial and expensive, and come with big useless (to me) GUI/animation/freaky special effect generation systems... There are advantages in Python direct to Flash bytecode with a simple command line compiler (particularly if one uses test-driven development...). This may be where I have to dig into an area that's outside my expertise, namely the compiler.py module, parse trees, and code generation... -Peter From fred at acme.com Wed Aug 11 18:03:23 2004 From: fred at acme.com (Fred) Date: Thu, 12 Aug 2004 00:03:23 +0200 Subject: Python script to generate static site? Message-ID: Hi, I'm sure there are a bunch of them, but googling just returned full-fledged CMS that require a DBMS and generate dynamic pages. I'd just like a script that would 1. look in a directory for articles in raw HTML, 2. generate a cooked output for each page (ie. add header and footer, CSS link in HEAD, etc.), 3. regenerate the homepage with "Last modified" bit following each article's title, 4. ready to be uploaded by FTP to a web server that only handles static web pages. Considering Python's wealth of libraries, it's most likely only a couple hours' work, but since I'm pretty much a Python newbie... Thank you Fred. From tpassin at comcast.net Sun Aug 15 16:57:48 2004 From: tpassin at comcast.net (Thomas B. Passin) Date: Sun, 15 Aug 2004 16:57:48 -0400 Subject: [XML-SIG] python and XML resources In-Reply-To: <1092484513.411dfda120873@www-mail.usyd.edu.au> References: <1092484513.411dfda120873@www-mail.usyd.edu.au> Message-ID: <411FCE4C.6060903@comcast.net> Ajay wrote: > > does anyone know of good online resources on XML processing in Python. I am > using the PyXML package and have read the introductory XML HOWTO. > what i am looking for is a more detailed and comprehensive coverage of the > entire package - all the classes and functions etc It's not on line, but Lars Marius Garshol's book "Definitive Xml Application Development" is mostly in Python and is very good. Of course, it has lagged behind the latest developments in pyxml, pyana, etc., but I recommend it. Cheers, Tom P -- Thomas B. Passin Explorer's Guide to the Semantic Web (Manning Books) http://www.manning.com/catalog/view.php?book=passin From fumanchu at amor.org Wed Aug 25 14:16:23 2004 From: fumanchu at amor.org (Robert Brewer) Date: Wed, 25 Aug 2004 11:16:23 -0700 Subject: Call for signatories for J2 - In Favor Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E72@exchange.hqamor.amorhq.net> Francesco Bochicchio wrote: > Assuming that simple python users qualify, you can add my > name in favor > of your proposal. Of course you qualify! Thanks for your signature. > If people are using this thread for signing themselves, maybe > it would be better to create subthreads for pro/against/indifferent, > just to make counting more simple. I don't think that's necessary. There are enough people replying in private that it wouldn't be complete. Also, if someone votes against and doesn't notice they're in the "for" thread, their vote could become ambiguous. I'd prefer clear statements for each post. Robert Brewer MIS Amor Ministries fumanchu at amor.org From deetsNOSPAM at web.de Mon Aug 30 18:23:00 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Tue, 31 Aug 2004 00:23:00 +0200 Subject: "Content-Length" header References: Message-ID: Peter Kleiweg wrote: > Justin schreef: > >> I found the answer. After about 3 hours of agonizing over it it turned >> out to be CASE >> some webservers are CASE SENSITVE about their urls and some are not. > > There are case-insensitive webservers? Never knew that. Rumors are that they even created *whole OSes* in that fashion. I wonder if that _might_ be the cause for the webservers beeing so nasty.... -- Regards, Diez B. Roggisch From rnd at onego.ru Mon Aug 16 16:00:03 2004 From: rnd at onego.ru (Roman Suzi) Date: Tue, 17 Aug 2004 00:00:03 +0400 (MSD) Subject: Best programming language In-Reply-To: <5155aad2.0408161008.40c57262@posting.google.com> References: <5155aad2.0408161008.40c57262@posting.google.com> Message-ID: On Mon, 16 Aug 2004, Konstantin Veretennicov wrote: >Roman Suzi wrote in message news:... >> ;-) >> >> Just type into google >> "best programming language" >> and press (I am lucky) >> >> >> Sincerely yours, Roman Suzi > >Just type in "programming language" and look at #1 >;-) WOW! Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3 From lconrad at laymusic.org Sat Aug 7 16:28:24 2004 From: lconrad at laymusic.org (Laura Conrad) Date: Sat, 07 Aug 2004 16:28:24 -0400 Subject: Killing children References: <87smb0w4ln.fsf@debian.laymusic.org> <87d624vxt2.fsf@debian.laymusic.org> Message-ID: <87pt62vgk7.fsf@debian.laymusic.org> Further adventures in infanticide. I've been spawning and killing programs all day, in the course of testing and fixing other aspects of the program. All of a sudden, although I haven't changed the spawn line at all, only things farther along in the program, I get: C:\cygwin\bin\python2.3.exe (5684): *** unable to remap C:\cygwin\bin\cygcrypto-0.9.7.dll to same address as parent(0x6B0000) != 0x6C0000 4 [main] python 5468 sync_with_child: child 5684(0x710) died before initialization with status code 0x1 681 [main] python 5468 sync_with_child: *** child state child loading dlls Traceback (most recent call last): File "testspawn.py", line 8, in ? p = os.spawnl(os.P_NOWAIT, "/usr/bin/python", "python", 'run_rad7.py', "/dev/ttyS8", "120", "0", "00560") File "/usr/lib/python2.3/os.py", line 566, in spawnl return spawnv(mode, file, args) File "/usr/lib/python2.3/os.py", line 521, in spawnv return _spawnvef(mode, file, args, None, execv) File "/usr/lib/python2.3/os.py", line 489, in _spawnvef pid = fork() OSError: [Errno 11] Resource temporarily unavailable This is the same kind of error that caused me to stop using pexpect.spawn. Does anyone know what's happening? rebooting does not cause it to go away. The program I attempting to spawn from my python program runs fine from the command line. -- Laura (mailto:lconrad at laymusic.org , http://www.laymusic.org/ ) (617) 661-8097 fax: (501) 641-5011 233 Broadway, Cambridge, MA 02139 From beliavsky at aol.com Sun Aug 22 17:52:41 2004 From: beliavsky at aol.com (beliavsky at aol.com) Date: 22 Aug 2004 14:52:41 -0700 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> Message-ID: <3064b51d.0408221352.ca7b57e@posting.google.com> Roy Smith wrote in message news:... > In article , aahz at pythoncraft.com (Aahz) > wrote: > > > In article <278de0e.0408211605.426e5129 at posting.google.com>, > > Neuruss wrote: > > > > > >It seems there are quite a few projects aimed to improve Python's > > >speed and, therefore, eliminate its main limitation for mainstream > > >acceptance. > > > > What makes you think speed is Python's primary limitation for mainstream > > acceptance? > > Speed is the primary limitation for mainstream acceptance of high level > (aka scripting) languages in general. I can think of no reason why so > much software is still written in languages like C++ other than > performance (or at least, the perception of it). There are reasons other than performance why one might prefer C++ or other languages to Python -- not to say that they are objectively "better". (1) Many people think that the static type checking of languages like C++ is a virtue, and some of them avoid Python because it is dynamic. I don't want to start another debate but just want to note that programmers are divided on this. (2) The Python approach to OOP is very different -- looser -- than that of C++ and has less support for data hiding. For example, one can add an attribute to an object anywhere, which seems like a dubious freedom to me. (3) The beginning of a Python function only tells you about the arguments, not the result. I prefer not to scan the entire body of a function to see what it returns. Compiled languages like C++, Fortran, and Pascal put the argument and result info in one place. (4) Python does not look like C++. Some programmers think that any alternative to C++ must still look like it. I think this argument is weak, but Java's cosmetic similarity to C++ probably has boosted its popularity. From hari at fake.com Fri Aug 13 12:21:35 2004 From: hari at fake.com (Hari Pulapaka) Date: Fri, 13 Aug 2004 16:21:35 GMT Subject: Difference between readlines() and iterating on a file object? In-Reply-To: References: <411cd102$1@mail.hmgcc.gov.uk> Message-ID: Duncan Booth wrote: > "Richard" wrote in > news:411cd102$1 at mail.hmgcc.gov.uk: > > >>Hi, >> >>Can anyone tell me what the difference is between >> >>for line in file.readlines( ): > > > reads the entire file into memory and splits it up into a list of lines > then iterates over the list. If you break from the loop, tough you've lost > any lines that were read but you didn't handle. > > >>and >> >>for line in file: > > > reads part of the file and strips off one line at a time. Never creates a > list. Reads more only when it runs out of the block it read. If you break > from the loop you can do another 'for line in file' and get the remaining > lines. However, one thing that bit me was that you cant use f.tell() to get the current position of the line in the file. If you use "for line in fileobject:" and then you first line is fileobject.tell() that will return the end of file position and not the position of the next line. Might be a bit counter-intuitive. I am learning to be a better python programmer and I have written this small program to parse Mail box files and display emails which match the specified text. Any comments on this will appreciated. I know I can read the whole file using readlines(), not sure if that is good idea? Batigol:~/pgrep hari$ cat pgrep.py import sys hits = {} lines = {} count = 0 emailstart = "From -" def build(f, str): global count, hits, lines f.seek(0) start_email = 0 end_email = 0 pointers = [] str_matched = [] found = 0 line = f.readline() while line != '': if line.find(emailstart) != -1: # Start of Mail start_email = f.tell() if found == 1: #print "From - inside found " pointers.append(end_email) found = 0 hits[count] = pointers lines[count] = str_matched count += 1 pointers = [] str_matched = [] if line.find(str) != -1: # Found string #print "Found string: " #print "count", count if len(pointers) == 0: pointers.append(start_email) found = 1 str_matched.append(line) #lines[count] = line end_email = f.tell() line = f.readline() def display(f): global count, hits, lines if count == 0: sys.stdout.write("Not found! \n") sys.stdout.flush() sys.exit(0) sys.stdout.write("#: Line Contents\n") for i in range(count): for j in range(len(lines[i])): choice = "%s: %s" %(i, lines[i][j]) sys.stdout.write(choice) sys.stdout.write("Enter # of email to display: ") sys.stdout.flush() input = sys.stdin.readline() try: i = int(input.strip()) f.seek(hits[i][0]) while f.tell() != hits[i][1]: sys.stdout.write(f.readline()) except: sys.stderr.write("Invalid choice\n") sys.stdout.flush() if __name__ == "__main__": try: f = file(sys.argv[1], "r") except: sys.stdout.write("Error opening file\n") sys.exit(1) build(f, sys.argv[2]) response = 'n' #print response while response == 'n': display(f) sys.stdout.write("Do you want to quit, y or n? ") sys.stdout.flush() response = sys.stdin.readline().strip() f.close() sys.exit(0) Thanks, Hari From jason at mail.smileproject.com Tue Aug 17 07:56:32 2004 From: jason at mail.smileproject.com (Jason Van Anden) Date: Tue, 17 Aug 2004 07:56:32 -0400 Subject: Python and ASP Problem Message-ID: <200408170756.AA583991350@mail.smileproject.com> I cannot get ASP pages to run Python scripting. I have ActiveState's most recent install on my Windows2000 server, running IIS. I have checked that Python works. I have double-checked the troubleshooting pages (run pyscript, pytest, checked for duplicated dlls, etc...), and searched Google for answers, but I cannot get ASP to work with Python scripts. When I try to run an ASP page with a script, I get a HTTP Error 500. Guidance appreciated, Jason From david_brownell at hotmail.com Mon Aug 23 13:13:30 2004 From: david_brownell at hotmail.com (David Brownell) Date: 23 Aug 2004 10:13:30 -0700 Subject: py2exe, PyXML, and utf-16-be Error Message-ID: <67e04df1.0408230913.3c12f1a8@posting.google.com> I am using the XMLValidateParser in the PyXML library (xml.sax.sax2exts.XMLValParserFactory.make_parser). When I run my script, everything works as expected. When I "compile" my script using py2exe, I get the following error when running the exe: Traceback (most recent call last): File "xml\sax\sax2exts.pyc", line 13, in make_parser File "xml\sax\saxexts.pyc", line 64, in make_parser File "xml\sax\saxexts.pyc", line 42, in _create_parser File "xml\sax\drivers2\drv_xmlproc.pyc", line 9, in ? File "xml\parsers\xmlproc\xmlproc.pyc", line 14, in ? File "xml\parsers\xmlproc\dtdparser.pyc", line 12, in ? File "xml\parsers\xmlproc\xmlutils.pyc", line 43, in ? LookupError: unknown encoding: utf-16-be While using py2exe, I specify "--packages xml". Is there something else I need to specify to enable utf-16-be encoding? Thanks in advance for your help! David Brownell From newsgroups at jhrothjr.com Fri Aug 6 08:43:29 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 6 Aug 2004 08:43:29 -0400 Subject: @decorators References: Message-ID: <10h6v76mm313cce@news.supernews.com> "daishi" wrote in message news:d22692a3.0408052233.3459c3fa at posting.google.com... > For what it's worth: > > As far as I know, the proposed @decorator syntax will be the first > time that two logical lines of python with the same indentation will > not be independent of one another. Examples: try - except - finally if - elif - else while - else John Roth From t-meyer at ihug.co.nz Mon Aug 2 22:16:56 2004 From: t-meyer at ihug.co.nz (Tony Meyer) Date: Tue, 3 Aug 2004 14:16:56 +1200 Subject: Call for Grant Proposals In-Reply-To: Message-ID: [Maurice Ling] > Yes, exactly. You are correct to assume that it is logical to require > deliverables from this grant to be open sourced, however, > this cannot be inferred from the call for grant proposal's wordings > "The Python Software Foundation is seeking grant proposals for projects > related to the further development of Python, Python-related technology, > and educational resources." As I said before (and note that I'm not part of the PSF, or on the grants committee, or anything else like that), a call for proposals will never include every possible detail. If you want specifics, then you ask specific questions afterwards (and wait for a response from people who are probably pretty busy, no matter which grant committee this might be). In all likelihood, if someone put together a proposal that clearly would further develop Python in some fantastic way, was closed source, and the closed source nature didn't effect the development in any way, then the grants committee would be as likely to approve it as any other grant. > Although I may somewhat seems to want close > source development, my actual intentions is to refer to the grant > committee that by the actual wordings of the call allows for closed > source development. Unless there is a specific statement by the PSF > grant committee, I can foresee that companies may use this grant for > close sourced development. A grant committee can decide whether or not to give a grant to a particular requestee based on any criteria they like (providing it matches their given purpose). I'm sure the PSF would be fine receiving requests that deal with closed-source development. Like Tim said, it's likely that an open source project would benefit more people, and so more likely that it will beat out closed source competitors. That doesn't mean that it's impossible for a closed source project to get a grant. If your intent was to say "hey, it would help if you were more clear about these points", then an email saying that would have probably worked better <0.5 wink>. > Under common law, Whose? Melbourne's? Australia's? The USA's? It seems likely that it's the latter that would apply here, given that the PSF is a US organisation. > although PSF can attach further strings to the grant in the grant > letter, it is morally incorrect to do so. In what way? It certainly seems to me that the morally correct thing to do is to do their best in selecting projects that meet the stated aims of the grants. If that means an open source project, then it does. If that means a closed source project, then it does. > At the same time, although common law may allow such an act, I > am not too sure how this will seems in the eyes of equal opportunities > law and anti-discrimination laws, amongst others. It seems more than a stretch to apply those sorts of laws to a decision about particular licenses... > In either sense, I hate to think that I may eventually force > PSF to give me a grant for close sourced project. I imagine that everyone hates that idea. I can't see any possible way that you could do this, though, so we can all be relived <0.5 wink>. It really does seem that the appropriate move is to simply wait for someone from the grants committee to have time to respond to your questions. Isn't that what you would do with any other grant? (It's certainly what I would do). =Tony Meyer From ehab_teima at hotmail.com Tue Aug 10 19:53:15 2004 From: ehab_teima at hotmail.com (Ehab Teima) Date: 10 Aug 2004 16:53:15 -0700 Subject: Writing traceback Message-ID: <17aafe08.0408101553.6cf3840c@posting.google.com> Hello, I have built a server application. It's multithreaded, and everything works fine so far. I have only one issue with catching exceptions after I read the documentation but I can't find any problems yet. I'm catching all errors throughout the code into a function and I write the traceback to the server log as well as the screen. That's all. I need not to save it or anything else. The documentation said the function (in this example catchError) should not handle exceptions itself. How would I get around this issue given that writing to the server log must not stop the server? In other words, the function itself must handle and ignore any exceptions raised by itself. i.e. I want to make sure that failing to write to the server log is ignored. The code I have looks like this: try: handleClient(...) except: catchError(sys.exc_info()) def catchError(excInfo): print 'An error occured' try: fo=open(log, "w") print_exc() print_exc(None, fo) fo.close() except: print 'Could not write to the server log' From rnd at onego.ru Fri Aug 13 13:30:33 2004 From: rnd at onego.ru (Roman Suzi) Date: Fri, 13 Aug 2004 21:30:33 +0400 (MSD) Subject: def ... decorate In-Reply-To: References: <16668.57321.308134.676624@montanaro.dyndns.org> Message-ID: On Sat, 14 Aug 2004, Anthony Baxter wrote: >On Fri, 13 Aug 2004 20:55:39 +0400 (MSD), Roman Suzi wrote: >> >> Bingo! >> >> Just replace decorate with "from" and the nice syntax is found: >> >> def f: >> staticmethod >> grammarrule('statement : expression') >> version("Added in 2.4") >> deprecatedmethod >> type_(None) >> from self, p: >> """docstring here""" >> print p[1] > >I _really_ _really_ dislike re-using 'from' in this way. It's really confusing. > >I also don't like the way it's splitting the argument list out like >that. It's a _big_ >change from how things work today, and will break pretty much _every_ >tool that works with Python source, and badly. >For instance, I often end up doing some equivalent of "grep 'def funcname'" Probably egrep '(def|from)' could save you... >and like the fact that I get the start (at least) of the argument >list. More often >than not, I get the full argument list, which is what I was looking for in the >first place. > Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3 From zathras at thwackety.com Sun Aug 22 09:37:24 2004 From: zathras at thwackety.com (Michael Sparks) Date: Sun, 22 Aug 2004 14:37:24 +0100 Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? References: <10igvr2d1hlgmc9@news.supernews.com> Message-ID: <4128a660$0$79620$ed2619ec@ptn-nntp-reader01.plus.net> Peter Hansen wrote: ... > Although I'm not sure it was implemented this way, I > believe there may be an intent to support the usual > sort of one-line version as this (using an alternate > keyword instead of "decorate" which now seems doomed): > > using: staticmethod > def foo(bar, baz): > pass > > That makes it no extra lines, but still explicit and Pythonic > in nature. > > (Michael, was that how you implemented the latest?) I'm certainly intending to have this short form. However first of all I'm working through producing a full patch based on Anthony Baxter's pointer, to the original patch. When I do add the short form, it's most likely to include the replacement "using" keyword. The impact of "decorate" and "declare" on user code looks too large for comfort. (Well known projects broken by one or the other include mailman and Pyrex) Interestingly though the form as implemented does already allow for: decorate: staticmethod synchronised deprecated def foo(baz): pass Largely because the current 2.4a2 form allows for: @staticmethod @synchronised @deprecated def foo(baz): pass Both of which strike me generally speaking as nicer than the long list approach. Once I've made the change I intend to make (assuming it's simple enough) I'll make the simple/short form allow (assuming possible): using: staticmethod synchronized deprecated memoize def foo(baz): pass Mark Russell did a real a really nice job on the original implementation, and when this is all over that's where the real thanks are due! Regards, Michael. From aleaxit at yahoo.com Fri Aug 27 14:37:43 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 27 Aug 2004 20:37:43 +0200 Subject: Class Friends References: <20040827081556.657c3fac.a@c.d> Message-ID: <1gj727c.48hz5o3gw46dN%aleaxit@yahoo.com> Sean Don wrote: > Hello! > > Is it possible to make classes friends in Python? Or is it better to just stick > to "Java style" .isThis, .getThat, .setThis style functions? Neither. "friends" has no possible meaning in Python terms. Accessor methods are a horrid idea in Python: if you ever need access to an attribute to trigger the execution of some code, why, use 'property' -- that's what it's THERE for! > I understand that classes are generally grouped logically into separate files > anyway. So, this isn't always necessary. But I'm a perfectionist and was > wondering if friendships were possible in Python. What could 'friendship' possibly ever MEAN in a Python context...?! Alex From martindemello at yahoo.com Mon Aug 2 09:48:07 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Mon, 02 Aug 2004 13:48:07 GMT Subject: Newbie: pywin problem Message-ID: Here's a transcript: >>> import win32ui >>> template = pywin.mfc.docview.DocTemplate(None) >>> doc = pywin.scintilla.document.CScintillaDocument(template) >>> view = pywin.scintilla.view.CScintillaView(doc) >>> fr = win32ui.GetMainFrame() >>> view.CreateWindow(fr) Now how do I get the window to display? I thought the call to CreateWindow would do it, but the window just gets created silently. martin From martin at v.loewis.de Thu Aug 26 02:09:40 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 26 Aug 2004 08:09:40 +0200 Subject: Best processor (i386) for Python performance? In-Reply-To: <789f72ac.0408251950.e85d23e@posting.google.com> References: <789f72ac.0408251950.e85d23e@posting.google.com> Message-ID: <412d7e9d$0$26184$9b622d9e@news.freenet.de> > Raw clock speed? > Cache size? > Bus speed? > Intel's Hyperthreading? > AMD's 64 bits? Python applications are often memory intensive, so a fast bus and a large cache should help. Also, raw clock speed should help. Hyperthreading and AMD64 are irrelevant (although for the latter, it would be interesting to see how linux-x86 compares to linux-amd64 on the same machine for Python performance). Regards, Martin From adurdin at gmail.com Sat Aug 21 01:39:52 2004 From: adurdin at gmail.com (Andrew Durdin) Date: Sat, 21 Aug 2004 15:39:52 +1000 Subject: Overriding logical operators? Message-ID: <59e9fd3a04082022392b749256@mail.gmail.com> In Python, you can override the behaviour of most operators for a class, by defining __add__, __gt__, and the other special object methods. I noticed that, although there are special methods for most operators, they are conspicuously absent for the logical "or" and "and". I'm guessing that the reason for this is that these operators short-circuit if their first operand answers the whole question? Would it be possible to allow overriding the logical operators, with the caveat that overriding it would prevent short-circuiting? From http Mon Aug 16 21:44:43 2004 From: http (Paul Rubin) Date: 16 Aug 2004 18:44:43 -0700 Subject: Why I love python. References: Message-ID: <7xk6vyczck.fsf@ruckus.brouhaha.com> Nick Patavalis writes: > If you define a function like: > > def sum (a, b): > return a + b > > How can the compiler know what code to produce? It could trace all the > applications of sum(), and decide what types of arguments sum() is > actually applied on. But this is not easy, and sometimes it is > straight-out impossible. Compilers for languages like Lisp and Smaltalk have dealt with this for decades. They can either generate code that switches on the type tags, or have dispatch tables in the objects that point to code for operations like "+", or take advice or declarations from the programmer about the arg types, among other possibilities. Any of these approaches generates code that runs much faster than interpreted code. From squirrel at WPI.EDU Wed Aug 11 15:56:39 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Wed, 11 Aug 2004 15:56:39 -0400 Subject: Rather than decorators, how about sections? In-Reply-To: References: <1C74C038-EBB6-11D8-8889-000A95857E5C@eischet.com> <411a6b9d$0$13688$636a15ce@news.free.fr> Message-ID: On Wed, 11 Aug 2004, Paul Morrow wrote: > Fine, instead of Foo (the name of the class), use the word klass. It's > a popular name for the first parameter of a class method. My code uses 'cls' for this purpose. I'm sure others stick with 'self'. No matter what you pick, it will break something. To quote the Zen of Python: "Explicit is better than implicit." From jess.austin at gmail.com Thu Aug 26 17:55:52 2004 From: jess.austin at gmail.com (Jess Austin) Date: 26 Aug 2004 14:55:52 -0700 Subject: Are decorators really that different from metaclasses... References: Message-ID: jess.austin at gmail.com (Jess Austin) wrote in message news:... > This is a difference between classes and functions. But maybe it > could be "swept under the rug" in the following way. Code like this: > > using: > metaclass_decorator(baz) > class foo(bar): > a = 1 > def moo(self): > pass > > could cause something similar to the following: > > foo = metaclass_decorator(baz)('foo', (,), {'a': > 1, 'moo': , '__module__': '__main__'}) So I thought a bit about this, and I think a better equivalent would be: foo = metaclass_decorator(baz)(type('foo', (,), {'a': 1, 'moo': , '__module__': '__main__'})) Smart pythonistas have probably already thought of this. It just took me a day or two. later, Jess From simoninusa2001 at yahoo.co.uk Thu Aug 12 13:44:22 2004 From: simoninusa2001 at yahoo.co.uk (simo) Date: 12 Aug 2004 10:44:22 -0700 Subject: VB-like GUI designer? References: <30260531.0408102005.5847b9c@posting.google.com> <3hpou1-09i.ln1@home.rogerbinns.com> Message-ID: <30260531.0408120944.5d9ea9f2@posting.google.com> "Roger Binns" wrote in message news:<3hpou1-09i.ln1 at home.rogerbinns.com>... > simo wrote: > > I noticed you have RPMs for Linux - so what do they include - a > > complete wxWidgets/GTK+/Python distribution, plus your files? > > $ rpm -qpl dotamatic-0.2-0.i386.rpm > /usr/bin/dotamatic > /usr/lib/dotamatic-0.2 > /usr/lib/dotamatic-0.2/_localemodule.so > /usr/lib/dotamatic-0.2/dotamatic > /usr/lib/dotamatic-0.2/dotamatic.css > /usr/lib/dotamatic-0.2/libwx_gtkd-2.4.so > /usr/lib/dotamatic-0.2/mathmodule.so > /usr/lib/dotamatic-0.2/pcre.so > /usr/lib/dotamatic-0.2/pwdmodule.so > /usr/lib/dotamatic-0.2/resources > /usr/lib/dotamatic-0.2/resources/dotamatic.htb > /usr/lib/dotamatic-0.2/resources/standard.jpg > /usr/lib/dotamatic-0.2/strop.so > /usr/lib/dotamatic-0.2/timemodule.so > /usr/lib/dotamatic-0.2/wxPython.htmlc.so > /usr/lib/dotamatic-0.2/wxPython.wxc.so > > The file in /usr/bin is a shell script that just execs the dotamatic > binary in /usr/lib. The dotmatic executable is actually the Python > interpretter with an archive containing the bytecode appended. > Only the Python and wxPython modules used are present. So how are you generating this interpreter/bytecode archive? It basically sounds like the kind of thing py2exe does, but you've made an object file or something. How did you calculate the dependencies? I'm heading off to your site to see if you have the build environment in with the source ;o) From avner at skilldesign.com Mon Aug 9 13:14:08 2004 From: avner at skilldesign.com (Avner Ben) Date: Mon, 09 Aug 2004 19:14:08 +0200 Subject: @decorator syntax is sugar, but for what exactly? In-Reply-To: References: <4115b53a$1@nntp0.pdx.net> <4116239e$1@news.012.net.il> Message-ID: <4117a43b$1@news.012.net.il> xtian wrote: >[snip] > > def property_(f): > return property(*f()) Where has the property Without Underscore come from? >[snip] > > t = DecorationTest() > print t.foo > t.foo = 3 > print t.foo > Will you please explain how the assignment and retrieval work? Avner. From gilles.lenfant at nospam.com Tue Aug 17 08:29:52 2004 From: gilles.lenfant at nospam.com (Gilles Lenfant) Date: Tue, 17 Aug 2004 14:29:52 +0200 Subject: music resources In-Reply-To: <1qfUc.128080$gE.84239@pd7tw3no> References: <1qfUc.128080$gE.84239@pd7tw3no> Message-ID: <4121fae7$0$19635$626a14ce@news.free.fr> Elaine Jackson a ?crit : > Thanks for your suggestions. What I want to do with music is to learn it and > play with it. Even an auditory equivalent of "MS Paint" would probably keep me > busy for some time, since I'm essentially starting from zero. The kind of tool you need depends on your skills in music and what you want to do (sample/design sounds, compose/arrange music), but it's certainly not a Python package (but who knows ;-). Google for "music sequencer" and you'll certainly find what you need. Note you'll certainly need a good sound card and a MIDI keyboard. -- Gilles From norman.werner at student.uni-magdeburg.de Thu Aug 26 09:03:53 2004 From: norman.werner at student.uni-magdeburg.de (norman werner) Date: 26 Aug 2004 06:03:53 -0700 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: Peter Hansen wrote in message news:... > Robert wrote: > > > Isn't "Xah Lee" chinese for "Moron"? > > No, it's Esperanto (universal language) for "troll"... > > -Peter Bonvolu ne s:ercu pri nekonatoj aferoj. "Xah Lee" certe - pro manko de Ikso - ne estas esperanto. Kaj via s:erco nur s:tulta estas. Norman tradukita: You certainly have not the slightest idea about esperanto. So please dont't emberass yourself. And back to topic(?): "Xah lee" is not esperanto. From martin at v.loewis.de Fri Aug 13 02:09:50 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 13 Aug 2004 08:09:50 +0200 Subject: undefined symbol: PyUnicodeUCS4_FromUnicode In-Reply-To: References: Message-ID: <411c5b24$0$26992$9b622d9e@news.freenet.de> Bill Hodges wrote: > output is: > > psyco installed and used > Traceback (most recent call last): > File "/usr/local/lib/python2.3/site-packages/drt/drt.py", line 40, in ? > from qt import * > ImportError: /usr/lib/python2.3/site-packages/qt.so: undefined symbol: > PyUnicodeUCS4_FromUnicode > > Any pointers on how to resolve? It appears that you have built qt.so for UCS-4, but the installed Python is UCS-2. Do "nm -D /usr/bin/python2.3|grep UCS" to verify that. If so, make sure the pyconfig.h that you are using belongs to the /usr/bin/python you are using. Regards, Martin From chris_invalid at yahoo.fr Tue Aug 24 18:13:58 2004 From: chris_invalid at yahoo.fr (Christophe) Date: Wed, 25 Aug 2004 00:13:58 +0200 Subject: Make problem on Solaris : how to use Modules/Setup.config.in Message-ID: <20040825001358.232d0fc4@linuxcestcomplique> Hello, I'm trying to build python 2.3.4 on Solaris 8 (SunOS 5.8) and I ran into a little problem with the socket/ssl module : ************************************ gcc -shared build/temp.solaris-2.8-sun4u-2.3/_ssl.o -lssl -lcrypto -o build/lib.solaris-2.8-sun4u-2.3/_ssl.so ld: fatal: relocations remain against allocatable but non-writable sections collect2: ld returned 1 exit status *** WARNING: renaming "_ssl" since importing it failed: ld.so.1:./python: fatal: build/lib.solaris-2.8-sun4u-2.3/_ssl.so: open failed: No such file or directory error: No such file or directory *** Error code 1 make: Fatal error: Command failed for target `sharedmods' ************************************ I know that this problem has happened before : http://groups.google.fr/groups?hl=fr&lr=&ie=UTF-8&threadm=mailman.1063659200.574.python-list%40python.org&rnum=1&prev=/groups%3Fq%3Dsolaris%2Bssl%2Bgroup:comp.lang.python%26hl%3Dfr%26lr%3D%26ie%3DUTF-8%26selm%3Dmailman.1063659200.574.python-list%2540python.org%26rnum%3D1 But I don't understand the solution : "You must make sure that the library you link with is position-independent, or else you must build _ssl as a builtin module (i.e. through Modules/Setup, as non-shared)." Because I haven't found the manual to use the Modules/Setup.config.in How can I modify the Modules/Setup.config.in to build ssl as a builtin module ? Thanks in advance, From __peter__ at web.de Mon Aug 16 11:13:37 2004 From: __peter__ at web.de (Peter Otten) Date: Mon, 16 Aug 2004 17:13:37 +0200 Subject: Regular expression problem with groups References: <9b5e8d9.0408160708.37aa9ae3@posting.google.com> Message-ID: Axel Kowald wrote: > Hi everybody, > > I have a 'simple' problem with regular expressions. Maybe someone can > help me. > > import re > bla = 'the the' > obj = re.search('(.+) \1',bla) > > obj.group(1) should now be 'the'. Instead obj is none (python 2.3 > under windows and 2.1 under linux). The problem seems to be the \1 > where I try to reference the first group. However, every tutorial says > this is the correct way to do it !? > > Any ideas what I'm doing wrong ? You did neither escape the backslash nor use a raw string. >>> re.search("(.+) \\1", "the the").group(1) 'the' >>> re.search(r"(.+) \1", "the the").group(1) 'the' The latter is the most convenient way to use with regular expressions with the limitation that it may not end with an odd number of backslashes. Peter From da_rosser at yahoo.com Wed Aug 4 14:38:17 2004 From: da_rosser at yahoo.com (Doug Rosser) Date: 4 Aug 2004 11:38:17 -0700 Subject: Mucking with the calling scripts namespace (For a good reason, honest!) References: Message-ID: Christopher T King wrote in message news:... > On 3 Aug 2004, Doug Rosser wrote: > > > 1. Python doesn't provide an obvious way to modify the __main__ > > namespace. You can peek at values with "global" but you can't treat it > > like a dictionary at runtime. > > The globals() function returns just the dictionary you're looking for. > Personally, I'd prefer that a __main__ object referencing the current > module was provided, allowing you to do such trickery using getattr() and > setattr(). Something as simple as the following would suffice: > > class objifier(object): > def __init__(self,d): > self.__dict__ = d > > __main__ = objifier(globals()) > > Then you do stuff like: > > >>> __main__.b = 6 > >>> b > 6 > >>> b = 20 > >>> __main__.b > 20 > >>> getattr(__main__,"b") > 20 > >>> setattr(__main__,"b",6) > >>> b > 6 /Me slaps his forehead. Python provides the functionality I'm looking for already. After reading the Python 2.3 documentation for globals(), I stumbled upon "exec". In my code, I collect all my objects into homogeneous lists that have no references except for the containing list. To add the references I'm looking for, I'm going to do something like: for server in myTest.servers: exec server.iniLabel +"="+ server in globaldict The code hasn't been debugged...caveat emptor... * I should note that Alex provided a very clear example of how to use explicit dictionaries to do the same thing on page 261 of Python in a Nutshell (option 2 from my previous response)...still debating the merits of both approaches da rosser From ccurvey at earthlink.net Sun Aug 29 20:12:18 2004 From: ccurvey at earthlink.net (Chris Curvey) Date: Mon, 30 Aug 2004 00:12:18 GMT Subject: cPickle and __getattr__ Message-ID: Hi all, I have this program class Company: def __init__(self, revenues, costs): self.revenues = revenues self.costs = costs def __getattr__(self, name): if name == 'profits': return self.revenues - self.costs c = Company(100, 75) print c.revenues print c.costs print c.profits import cPickle print cPickle.dumps(c) Everything works fine up until the last line. If I remove the __getattr__ function, then everything works (except "print c.profits"). What is the cPickle class trying to get to that is causing my __getattr__ function to be called? -Chris From richie at entrian.com Thu Aug 26 11:14:43 2004 From: richie at entrian.com (Richie Hindle) Date: Thu, 26 Aug 2004 16:14:43 +0100 Subject: Specific request with code example (encapsulation) __init__ problems In-Reply-To: References: Message-ID: <8luri0pps5e37ajtc4u66sqj3b4vgta8qg@4ax.com> [Justin] > my problem is now it appears that my widgets are completely > encapsulated within this __init__ class and I cannot get at them. That's not true if you say "self.x = y", as you have done with self.rb in your posted example. I don't know why your code doesn't work - you seem to be doing the right thing, and if I modify your Gobblewx_7public_.py to match your posted example then it all works. Here's what I did: I downloaded Gobblewx_7public_.py (a couple of days ago, when you first mentioned it) changed 'rb' to 'self.rb' throughout the Gmainpanel.__init__ function (lines 484-493), and added the line: self.rb.SetItemLabel(1, "test change") as the first line of the yousuredlg function (line 571). When I fill in the form and hit "Download files", the label changes. Note that it's SetItemLabel, not SetLabel, which implies that you never called your changelabel function, or you didn't look at the resulting traceback... -- Richie Hindle richie at entrian.com From pinard at iro.umontreal.ca Mon Aug 23 13:07:27 2004 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Mon, 23 Aug 2004 13:07:27 -0400 Subject: J2 paper 0.2.1 In-Reply-To: References: <10ijfibd8qo84b5@news.supernews.com> Message-ID: <20040823170727.GA10319@titan.progiciels-bpi.ca> [Steven Bethard] > [Robert Brewer] > > The first draft of the J2 proposal is ready. You can read it here: > > http://www.aminus.org/rbre/python/pydec.html > Outstanding job here. Your arguments are very clear and thorough and > I think you defend J2 against pretty much every objection that was > brought up against it. All superb indeed. Congratulations, and thanks. Thanks also to Michael for the implementation, and to Paul who helped us all at channelling the conversation. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From askari at addressNonValide.com Sun Aug 8 22:00:59 2004 From: askari at addressNonValide.com (Askari) Date: Mon, 09 Aug 2004 02:00:59 GMT Subject: Pygame - Only ONE Font found!? References: Message-ID: Pete Shinners wrote in news:mailman.1054.1091457050.5135.python-list at python.org: > Askari wrote: >> print "ListFont :", pygame.font.get_fonts() >> >> the resultat is: >> ListFont : ['netropaosdicon'] > > On Windows, Pygame finds its system fonts in the registry. It looks > under one of these locations. I'd say load up regedit and see if your > fonts are in there. > > "SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts" > "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" > > Thanks! :-) I fixed my problem to copy the times.tff in a directory and I can have my font with the function : pygame.font.Font(pathdata+"times.ttf",XX) I find only one font in: "SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts" and a lot fonts (and my font, times) in: "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" Pygame go see in the both key or just the first finded? And, I export the keys (from "SOFTWARE\Microsoft\Windows NT\CurrentVersion \Fonts" to "SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts") and, now, pygame list(find) more fonts with : "pygame.font.get_fonts()" but, "times" isn't in the list... :-( Askari From gmuller at worldonline.nl Tue Aug 24 16:13:48 2004 From: gmuller at worldonline.nl (GerritM) Date: Tue, 24 Aug 2004 22:13:48 +0200 Subject: python-dev Summary for 2004-08-01 through 2004-08-15 References: Message-ID: <412ba18a$0$62388$5fc3050@dreader2.news.tiscali.nl> "Brett Cannon" schreef in bericht news:mailman.2274.1093330945.5135.python-list at python.org... <...snip...> > These stats along with the insane amount of email has showed me > something; the Summaries have detracted from my participation on > python-dev this past year. I have a bigger mouth and more opinions than > the number of emails I sent to the list show. This means something has > to change, and it isn't going to be my mouth. The Summaries need to > change in one of two ways. <...snip...> > Option two out of all of this is people just say, "summarize what you > want, Brett." Then I just cover what I find interesting and just don't > worry about covering a specific area. I obviously prefer this option > but if people really care about a specific area I want to make sure to > cover it. What will most likely happen is I will still cover almost > everything but the thoroughness will be lower. I will go more off of > memory for example. Yes, please cover what you find interesting! I prefer to read something with a personal taste in it. Please don't be replaced by a thorough bot that does a mechanistic summarizing job. I always like your summaries. > <...snip...> kind regards, Gerrit From pm_mon at yahoo.com Sat Aug 28 08:45:20 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sat, 28 Aug 2004 08:45:20 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Bengt Richter wrote: > On Fri, 27 Aug 2004 18:39:51 -0400, Paul Morrow wrote: > > >>Anthony Baxter wrote: >> >>>On Thu, 26 Aug 2004 16:09:42 -0400, Paul Morrow wrote: >>> >>> >>>>Yes, it doesn't seem all that complex, although I'm not sure that >>>>everyone reading this understands them and their subtleties. The >>>>following is an excerpt from >>>>http://docs.python.org/tut/node11.html#SECTION0011200000000000000000 >>>> >>>>"A namespace is a mapping from names to objects. Most namespaces are >>>>currently implemented as Python dictionaries, but that's normally not >>>>noticeable in any way (except for performance), and it may change in the >>>>future. Examples of namespaces are: the set of built-in names (functions >>>>such as abs(), and built-in exception names); the global names in a >>>>module; and the local names in a function invocation. In a sense the set >>>>of attributes of an object also form a namespace." >>> >>> >>>>When I talk about namespaces, I include all of the above, including the >>>>sense mentioned in the last line. So an object's attributes constitute >>>>a namespace too. Therefore __doc__, being an attribute of the function >>>>object, is in the function object's /namespace/. And note that this is >>>>*not* a new namespace; it's been there all along. >>> >>> >>>"In a sense" is the bit you're missing here. You can't just hand-wave >>>and say that it's a namespace. It's *not* a namespace. If it was, you >>>could do any of these: >>> >> >>No I didn't miss it (I read that bit). In a sense, every object has >>it's own namespace. So that means that every class, every module, every >>function has a namespace (in a sense). The namespace (the mapping from >>names to objects) is stored in each object's special __dict__ attribute. >> >>Ok, and this is certainly apparent with classes. >> >> >>> class Foo: >> ... """docstring for Foo""" >> ... >> >>> Foo.__doc__ >> 'docstring for Foo' >> >>> Foo.__dict__.keys() >> ['__module__', '__doc__'] >> >>> >> >>And because of the parallels between the above class definition of Foo >>and the following function definition of baz, I would expect the same >>behavior. >> >> >>> def baz(): >> ... """docstring of baz""" >> ... >> >>> baz.__doc__ >> 'docstring of baz' >> >>> baz.__dict__.keys() >> [] >> >>Say what? Why didn't the Python system put baz's docstring into it's >>namespace (__dict__)? And where did it put it? >> >>I would like to understand the answers to these questions. Can you >>answer them (will you)? If not, can you please point me at something >>that documents what's going on here? >> >>Thanks. >> > > It looks to me like __doc__ is a descriptor (or c-code that acts like one) > (i.e., like a property) of the function class: > > >>> def foo(): > ... 'foo doc string' > ... > > Find __doc__ in the class dict: > >>> type(foo).__dict__['__doc__'] > > > Check on its nature a little: > >>> type(type(foo).__dict__['__doc__']) > > > It should have a __get__ method > >>> type(foo).__dict__['__doc__'].__get__ > > > Call that with foo as object instance: > >>> type(foo).__dict__['__doc__'].__get__(foo,None) > 'foo doc string' > > Try writing the __doc__ property (check for __set__ first): > >>> type(foo).__dict__['__doc__'].__set__ > > > Do long version of foo.__doc__ = 'new docstring' > >>> type(foo).__dict__['__doc__'].__set__(foo, 'new docstring') # foo.__doc__ = ... > > Look at it using the short spelling: > >>> foo.__doc__ > 'new docstring' > > And the long: > >>> type(foo).__dict__['__doc__'].__get__(foo,None) > 'new docstring' > > foo.func_doc seems to be implemented in a similar way: > >>> type(foo).__dict__['func_doc'].__get__(foo,None) > 'new docstring' > >>> foo.func_doc > 'new docstring' > > Even the dict of a function instance appears to be implemented as a property: > >>> type(type(foo).__dict__['__dict__']) > > >>> type(foo).__dict__['__dict__'].__get__(foo,None) > {} > >>> foo.x=123 > >>> type(foo).__dict__['__dict__'].__get__(foo,None) > {'x': 123} > > Short spelling: > >>> foo.__dict__ > {'x': 123} > > I haven't been into the implementation code, but this interpretation > of surface appearances seems to fit. > > Regards, > Bengt Richter Cool! Thanks! Now I need to ponder why a function's docstring needs a different implementation than a class's docstring (i.e. why not just make it a straigtforward attribute of the function object). From thomas.krueger at gmx.net Tue Aug 10 05:53:53 2004 From: thomas.krueger at gmx.net (Thomas =?ISO-8859-1?Q?Kr=FCger?=) Date: Tue, 10 Aug 2004 11:53:53 +0200 Subject: Python equivalent to a C trick References: <1d7b6d0d.0408092255.1177908e@posting.google.com> Message-ID: Dan wrote: > Is there a python equivalent of this trick in C? > > Logic_Test ? True_Result : False_Result > > Example: > printf( "you have %i %s", num_eggs, num_eggs > 1 ? "eggs" : "egg" ); Logic_Test and True_Result or False_Result Example: print (num_eggs > 1) and 'eggs" or "egg" Thomas From timrueAT at mindspringDOT.com Sat Aug 21 14:13:43 2004 From: timrueAT at mindspringDOT.com (threeseas) Date: Sat, 21 Aug 2004 18:13:43 GMT Subject: Alternative decorator syntax decision In-Reply-To: References: <10ia1a9jm9tkuca@corp.supernews.com> <84GdneSa3r-TR7jcRVn-tw@powergate.ca> Message-ID: Doug Holton wrote: >> Exactly. From this standpoint, the list on the wiki should be filtered >> to something that >> 1) doesn't have the declaration in the body of the function >> 2) doesn't have the declaration following the parameters >> >> 1) rules out D1 D2 E1 E2 >> 2) rules out C1 C2 C3 C4 E3 > > > I don't think so. C1 was the clear community favorite for months and > still has many supporters. And putting the decorator at the top of the > function had many supporters in the poll last week. > >> With the voting going the way it currently is J2 is winning anyway, > > > J2 is winning because it was actively discussed right here on this > newsgroup this past week. When I did a poll last week, E1 had just been > actively discussed and it gained a lot of support. Next week who knows > what will be the current flavor? a definable syntax is the solution direction, even if only as a stepping stone to letting the "standard" simply come about the old fashon way... popular use. This newsgroup is far to python user limited, and I'd imagine the mailing list is not much better, and IRC.... what is the estimate user/coder count regarding python? (perhaps what would be more accurate would be coding hours over user/coder count) where any changes or new things should keep the sum low. Python promotes ease of use in regards to power/functionality level. shrug... not that I really care, but perhaps its a bit more objective. From rganesan at myrealbox.com Fri Aug 27 01:19:09 2004 From: rganesan at myrealbox.com (Ganesan R) Date: 27 Aug 2004 10:49:09 +0530 Subject: Call for signatories for J2 References: Message-ID: >>>>> "David" == David Vaughan writes: > I vote FOR the "J2" proposal as described at > http://www.aminus.org/rbre/python/pydec.html > Please add my name to the "in favor" list there. ABSTAIN Ganesan Rajagopal (rganesan at myrealbox.com) I don't care either way. I am not even convinced that decorators are a good thing for python. I've dabbled a bit in C#, and that's the only case where I've seen decorators at work. It seems to add a bit of black magic to functions, and I am not convinced it's a good thing. Ganesan From cce at clarkevans.com Tue Aug 24 18:06:52 2004 From: cce at clarkevans.com (Clark C. Evans) Date: Tue, 24 Aug 2004 18:06:52 -0400 Subject: iterators: class vs generator Message-ID: <20040824220652.GA84484@prometheusresearch.com> There is an interesting difference between how exceptions are handled between iterators constructed from a class, and iterators constructed from a generator. The following are "mostly equivalent": class iterable_via_class: def __iter__(self): self._next = self._one return self def next(self): return self._next() def _one(self): self._next = self._two return "one" def _two(self): self._next = self._stop return "two" def _stop(self): raise StopIteration() def iterable_via_generator(): yield "one" yield "two" print "\nclass:" for x in iterable_via_class(): print x print "\ngenerator:" for x in iterable_via_generator(): print x However, when exceptions are involved, behavior can be different: class iterable_via_class: def __iter__(self): self._next = self._one return self def next(self): return self._next() def _one(self): self._next = self._raise return "one" def _raise(self): self._next = self._two raise Exception() def _two(self): self._next = self._stop return "two" def _stop(self): raise StopIteration() def iterable_via_generator(): yield "one" raise Exception() yield "two" def test(itergen): it = iter(itergen()) print it.next() try: ignore = it.next() except: pass print it.next() print "\nclass:" test(iterablex) print "\ngenerator:" test(iterable) From jbperez808 at wahoo.com Fri Aug 6 12:01:20 2004 From: jbperez808 at wahoo.com (Jon Perez) Date: Sat, 07 Aug 2004 00:01:20 +0800 Subject: generating uuids / guids Message-ID: <2nhnrfF13jq0U1@uni-berlin.de> Is there a Python function that works on all platforms (not just Win32) to generate such in the DCE / Microsoft format? If not present, this looks like it would be a very Pythonic addition to the standard library. From squirrel at WPI.EDU Thu Aug 5 14:22:43 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 5 Aug 2004 14:22:43 -0400 Subject: Confused about pep 318 In-Reply-To: References: <10h2ihgb8c6fi97@corp.supernews.com> <10h4s026oapbhf1@corp.supernews.com> Message-ID: On Fri, 6 Aug 2004, Anthony Baxter wrote: > To summarise: As I've stated already, I'm aware that PEP 318 needs an > update. If no-one else gets it done before next week, I will have time > to work on it again. If one of the people complaining about it wants to > sit down and trawl the (literally) hundreds and hundreds of python-dev > messages, spread over the last 2+ years, and extract the relevant posts, > that would be excellent! If you're only going to sit and bitch about it, > well, I can spend my time better trawling the archives. I'd be willing to do this this weekend (esp. being Python Bug Day), assuming Skip doesn't get to it first. On a related note, I suggest anyone interested read this thread on python-dev, "Call for defense of @decorators": http://mail.python.org/pipermail/python-dev/2004-August/046878.html In it, Guido makes some very interesting remarks, most notably: I also want to find out about superior syntax proposals (from __future__ import decorators might be acceptable). and ... I suggest that the proponents of syntax alternatives will have to agree amongst themselves on a single alternative that they can present to me. From ajsiegel at optonline.com Thu Aug 12 10:12:57 2004 From: ajsiegel at optonline.com (Arthur) Date: Thu, 12 Aug 2004 14:12:57 GMT Subject: PEP318 References: <20040812090056.00001e31@titan> Message-ID: <7ttmh0t8c3cogtbhhnp1ohqu8b51pda461@4ax.com> On Thu, 12 Aug 2004 09:00:56 +0200, Josef Dalcolmo wrote: >Hello, > >I just would like to add my vote against using '@' in the Python language. > I must say that after days of waffling, and I think an honest effort to accept where things were going, I woke this morning hating @decorator. The existing syntax for this kind of transformation is, in fact, exactly what one would expect: foo=staticmathed(foo). That is the universal langauge for transformations. And when we try to explain to anybody what it is that @decorator means, we go back to the pseudo code that is in fact the existing syntax. I guess I am mystified what it is that is perceived to have been gained ... by moving magic outside the function block to the top of a function in lieu of expressive code outside the function block at the bottom of the function. Something is created, and then transofrmed - in the language of transformation that transcends the implementation detail of what programming language is doing the work. Art From raims at dot.com Wed Aug 18 16:31:40 2004 From: raims at dot.com (Lawrence Oluyede) Date: Wed, 18 Aug 2004 22:31:40 +0200 Subject: IronPython and collections access References: Message-ID: <1iiqxegg4yuqf$.zq42m3fuzh53$.dlg@40tude.net> In data Wed, 18 Aug 2004 20:17:13 GMT, Hoang Do ha scritto: > import System > x = System.Collections.BitArray(4) > x[0] > > The error message is: > 'System.Collections.BitArray' object has no attribute '__getitem__'. This > is the same error with any classes derived from CollectionsBase. try x.Get(yourindex) -- Lawrence (l dot oluyede at virgilio dot it) "If the implementation is hard to explain, it's a bad idea." from The Zen of Python by Tim Peters From reply2group at ndbbm.net Mon Aug 30 19:34:40 2004 From: reply2group at ndbbm.net (Active8) Date: Mon, 30 Aug 2004 19:34:40 -0400 Subject: Need help importing/installing reportlab module Message-ID: <1ezngypknj8ju.dlg@news.individual.net> I did this once and can't remember how so I read the reportlab user guid. It says to unzip the reportlab archive - this is on w2k, BTW, with Python23 - to a directory and make a file called reportlab.pth in the pythod dir. The only line in this file is supposed to be the path to the reportlib dir. Then I'm instructed to open the ... ok I'll close and reopen ... the python cmd line interpreter and type import reportlab so I get Import Error: no module named reportlab not too surprizing since I can't find anything named reportlab in the archive. I did basically the same thing to install PIL and that worked. I did also download rl_win32_2_3 and move those .pyd files to the pythod dll dir - I assume a pyd is a python dll - worked for PIL. If anyone can help me straighten this out, I'd really apppreciate it. TIA -- Best Regards, Mike From davidf at sjsoft.com Fri Aug 6 10:39:28 2004 From: davidf at sjsoft.com (David Fraser) Date: Fri, 06 Aug 2004 16:39:28 +0200 Subject: advice for perl expert wanting to learn python In-Reply-To: References: Message-ID: Harry George wrote: > David Fraser writes: >>Zeljko Vrba wrote: >>>And most important thing, how does Python deal with database >>>connectivity? >>>Is there a single API (akin to DBI) for connecting to databases? >>>How does Python support the following databases: >>>- Oracle >>>- Postgres >>>- MySQL >>>- SQLServer (maybe using freetds?) >>>- ODBC connectivity (connecting to MS Access) >>> >> >>I have used Oracle, SQLServer and Access via ADO - try adodpapi.sf.net >>which is a wrapper for ADO to the Python DB-API. >>But note that you may well not be able to use any of this database >>stuff from IronPython >> >>David > > > More cross-platform and cross-DBMS is to code to the DB-API 2.0: > http://www.python.org/topics/database/ Thats why I said to look at adodbapi.sourceforge.net although I misspelt it - it is DB-API 2.0 compliant. David From jzgoda at gazeta.usun.pl Fri Aug 20 14:37:44 2004 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Fri, 20 Aug 2004 18:37:44 +0000 (UTC) Subject: age of Python programmers References: <903b3fba.0408200036.e3a1f6d@posting.google.com> Message-ID: vronskij at post.sk pisze: >> Me too, I started programming rather late, when I was 26 and I realised >> that I will be unable to make (good) living as philosophy graduate, >> specialized in medieval ethics (st. Thomas, Duns et al.). This makes me >> "young software developer" still, as I program for 7 years effectively. >> ;) > > Than you have something others might not have. A motivation ... I feel this kind of "motivation" each time I try to change employer. ;) -- Jarek Zgoda http://jpa.berlios.de/ From richie at entrian.com Fri Aug 27 05:56:44 2004 From: richie at entrian.com (Richie Hindle) Date: Fri, 27 Aug 2004 10:56:44 +0100 Subject: Call for signatories for J2 In-Reply-To: References: <412cf775$0$11496$ed2e19e4@ptn-nntp-reader04.plus.net> Message-ID: <5n0ui0lg8p37qrtvaimrlpms8s2qsa41ge@4ax.com> [Michael] > Patch against current CVS including __future__ statements/declarations > has now been created, tested and uploaded to SourceForge. All tests > pass. Nice one - well done for all your work on this. > British Broadcasting Corporation, Research and Development Is my license fee paying for this? If so, great! 8-) Makes for a much better investment than Fame Academy. -- Richie Hindle richie at entrian.com From Moiz.Golawala at ge.com Tue Aug 17 14:55:38 2004 From: Moiz.Golawala at ge.com (Golawala, Moiz M (GE Infrastructure)) Date: Tue, 17 Aug 2004 13:55:38 -0500 Subject: read input file a line as a list in python Message-ID: <4BF8D93CF6F73F4890EB6ED8009ECE191C5D05@FTWMLVEM01.e2k.ad.ge.com> oh.. to parse the line that you have into a list you could do this as well. line = "hello world I am new to python" lineList = line.split() #this will get you a list of all the word in the line. These are basic features of the language. It will serve you well to read the documentation at www.python.org Cheers Moiz -----Original Message----- From: python-list-bounces+moiz.golawala=ge.com at python.org [mailto:python-list-bounces+moiz.golawala=ge.com at python.org]On Behalf Of Yong Wang Sent: Tuesday, August 17, 2004 2:41 PM To: python-list at python.org Subject: read input file a line as a list in python Hi, All: I need to read a input file as soucre to process data. Ideally if I can read a line from input file as a list (coloumn separate by white space), reorganize field in a line. Does python has this kind of command ? for example, I read a line has: "IP MAC Date..." as a line from input file, How can I only get MAC ? Thanks, Yong -- http://mail.python.org/mailman/listinfo/python-list From sdahlbac at abo.fi Thu Aug 12 08:30:41 2004 From: sdahlbac at abo.fi (Simon Dahlbacka) Date: 12 Aug 2004 05:30:41 -0700 Subject: import hooks Message-ID: I recently had a problem caused by path extension (sys.path.extend) so that a module/package got imported twice both as foo.module and module, which caused all sorts of problems. Naturally best is to use absolute paths and avoid path extension, but this cannot be done in all places. Anyway, I'd like to prevent such things from happening again by inserting an __import__ hook to catch these kinds of problems. I got it installed alright, and it works in the sense that importing works, but it does not notice double imports. So how exactly am I to test for this case? I thought that if __file__ for two modules are the same but not id(module) would work, but apparently not? a somewhat related question: why does not built in modules have a __file__ attribute? my attempt: __moduleCache = {} def __importhook__(name, _globals=None, _locals=None, fromlist=None): """Sanity check module imports so that we do not get the same problem with doubly imported modules again""" mod = _orig__import__(name, globals, locals, fromlist) tempmod = mod components = name.split(".") for part in components[1:]: try: tempmod = getattr(tempmod, part) __moduleCache[".".join(components[components.index(part):])] = tempmod except AttributeError: pass for modname in __moduleCache: if name in sys.builtin_module_names: break if modname in sys.builtin_module_names: continue if (getattr(mod, "__file__") == getattr(__moduleCache[modname], "__file__") and id(mod) != id(__moduleCache[modname])): assert False return mod /Simon PS. pleace CC me directly From nobody at nowhere.com Tue Aug 3 13:10:27 2004 From: nobody at nowhere.com (Yannick Turgeon) Date: Tue, 3 Aug 2004 13:10:27 -0400 Subject: Telnet session Message-ID: Hello all, I'm currently trying to pass commands to a telnet session and get the texte generated (stdin + stdout) by the session. The problem I get is that the Telnet.read_until() function seems to freeze after a couple of command. I did a simplify script that reproduce the problem each time (I'm using 2.3.4 on W2K): -------------------- Begin of script -------------------- import sys import re from string import * from telnetlib import Telnet TELNET_USER = "myUser" TELNET_PWD = "myPassword" TELNET_HOST = "localhost" TELNET_PROMPT = "C:\\>" NEWLINE = "\r\n" TIMEOUT = 1 REMOVEJUNK = 1 #Remove Telnet output junk (formating chars?) before printing def printRead(texte): if not REMOVEJUNK: print texte return p = re.compile( '(.\[[0-9]{1,2};[0-9]{1,2}H[0-9]?|.\[K)+') print p.sub('\n', texte) # Loging in tn = Telnet("localhost") printRead(tn.read_until("login: ", TIMEOUT)) tn.write(TELNET_USER + NEWLINE) printRead(tn.read_until("password: ", TIMEOUT)) tn.write(TELNET_PWD + NEWLINE) printRead(tn.read_until(TELNET_PROMPT, TIMEOUT)) # Send commands tn.write("echo foo" + NEWLINE) printRead(tn.read_until(TELNET_PROMPT, TIMEOUT)) tn.write("echo bar1" + NEWLINE) printRead(tn.read_until(TELNET_PROMPT, TIMEOUT)) tn.write("echo bar2" + NEWLINE) printRead(tn.read_until(TELNET_PROMPT, TIMEOUT)) tn.write("echo bar3" + NEWLINE) printRead(tn.read_until(TELNET_PROMPT, TIMEOUT)) tn.write("echo bar4" + NEWLINE) printRead(tn.read_until(TELNET_PROMPT, TIMEOUT)) tn.write("echo bar5" + NEWLINE) printRead(tn.read_until(TELNET_PROMPT, TIMEOUT)) tn.write("echo bar6" + NEWLINE) printRead(tn.read_until(TELNET_PROMPT, TIMEOUT)) tn.write("echo bar7" + NEWLINE) printRead(tn.read_until(TELNET_PROMPT, TIMEOUT)) tn.write("echo bar8" + NEWLINE) printRead(tn.read_until(TELNET_PROMPT, TIMEOUT)) tn.write("echo bar9" + NEWLINE) printRead(tn.read_until(TELNET_PROMPT, TIMEOUT)) # Closing the connextion tn.write("exit" + NEWLINE) tn.close() -------------------- End of script -------------------- The output looks like (command sent in read. Not included in the script output.): echo foo echo foo foo C:\> echo bar1 echo bar1 bar1 C:\> echo bar2 echo bar2 bar2 C:\> echo bar3 echo bar3 bar3 C:\> echo bar4 echo bar4 bar4 C:\> echo bar5 echo bar5 bar5 C:\> echo bar6 echo bar6 bar6 C:\> echo bar7 <----- From here read_until() is freezing forever without a TIMEOUT C:\> echo bar8 echo foo foo bar1 bar1 bar1 bar1 echo bar9 --------------- End of output ----------------- It not related to the number of command sent. If your replace one of the firsts "echo bar" by "dir", you'll get the error immediatly. It seems to be related to the number of line generated by Telnet. Anybody know why? How to correct this? Thanks. Yannick From cjw at sympatico.ca Wed Aug 4 15:51:27 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Wed, 04 Aug 2004 15:51:27 -0400 Subject: I got it! How to force a single number to be a tuple In-Reply-To: References: Message-ID: <41113E3F.2050506@sympatico.ca> Jinming Xu wrote: > Sorry for the previous message. It's really a simple question and I have > solved it myself. > > Thanks, > > Jinming > > ------------------------------------------------------------------------ > Hi Folks, > > I have a number sequence, which is put into a tuple like this: > > y=2, 3.0, 4.5 > > I can manipulate the sequence as a tuple when it has more than 1 number. > But when the sequence has only 1 number, like > > y=2 > > I have trouble to manipulate it as a tuple. I guess there must be a way > to forece a single number to be a tuple. Could anyone please tell me that? > > Thanks, > > Jinming > > _________________________________________________________________ > Discover the best of the best at MSN Luxury Living. http://lexus.msn.com/ > Maybe something like: [Dbg]>>> y= 6 [Dbg]>>> if not isinstance(x, (tp.ListType, tp.TupleType)): [Dbg]... y= (y, ) [Dbg]... [Dbg]>>> print y (6,) [Dbg]>>> Colin W. From max at alcyone.com Fri Aug 6 16:25:37 2004 From: max at alcyone.com (Erik Max Francis) Date: Fri, 06 Aug 2004 13:25:37 -0700 Subject: Killing children References: <87smb0w4ln.fsf@debian.laymusic.org> <87d624vxt2.fsf@debian.laymusic.org> Message-ID: <4113E941.862D285F@alcyone.com> Laura Conrad wrote: > I used to think that when I first started using UNIX in the mid 80's. > But I am now a hardened child-killer. I bet you even let them turn into zombies before you kill them! You animal! -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ To be adult is to be alone. -- Jean Rostand From P at draigBrady.com Mon Aug 16 06:48:45 2004 From: P at draigBrady.com (P at draigBrady.com) Date: Mon, 16 Aug 2004 11:48:45 +0100 Subject: reading shell output in parallel In-Reply-To: References: Message-ID: <4120910D.1080604@draigBrady.com> Steve wrote: > Hi, > > I'm pretty new to python. I am trying to write a simple application > that can read the stdout output from a command in linux. I've tried > using x = commands.getstatusoutput() but this only gives back the > output in x after finished executing. I would like to read the > contents as it is being shown on the screen and then send parts of > this info over a simple client/server setup. I have the client/server > part set up already. > > Can anyone suggest a simple way to do this? > > Thanks for your help, I appreciate it. Better support is being added for this. In the meantime you could use this: http://www.pixelbeat.org/libs/subProcess.py With this you specify the timeout in seconds so you would update client every 1 second rather than every read (around 4K) which may or may not be what you want. Usage is like: import subProcess process = subProcess.subProcess("your shell command") while process.read(1): handle(process.outdata, process.errdata) del(process) P?draig. From dave at pythonapocrypha.com Fri Aug 13 10:56:47 2004 From: dave at pythonapocrypha.com (Dave Brueck) Date: Fri, 13 Aug 2004 08:56:47 -0600 Subject: Python indentation deters newbies? In-Reply-To: <3064b51d.0408130615.3fc4a760@posting.google.com> References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: <411CD6AF.2030300@pythonapocrypha.com> beliavsky at aol.com wrote: > One of the most commmon reasons programmers cite for not trying Python > is that indentation determines the program flow -- they think its > weird. Yes, that is commonly cited. From the programmer's perspective, indentation implies program flow in nearly *all* modern languages. The difference is that in Python the compiler believes you. > I think programmers who actually try Python adapt quickly and > do not find the indentation rules to be a problem. Yep! > I wonder if there is a way to remove this initial barrier. I sure hope not... if someone can't accept that there might be value in it being different than what they're used to (so much so that they're unwilling even to give it a try), then the indentation is only the first of many things that will give them problems. In that sense it's really useful - maybe it weeds out people who wouldn't be happy in Python yet anyway <0.5 wink>. -Dave From jbors at mail.ru Thu Aug 5 13:55:23 2004 From: jbors at mail.ru (Dmitry Borisov) Date: Thu, 05 Aug 2004 21:55:23 +0400 Subject: AVI I/O In-Reply-To: <411272ec$1@nntp0.pdx.net> Message-ID: > > ziaran wrote: > Hello, > > I want to use Python for Image proccessing. > I need the following capabilities: > > 1. To be able to read and WRITE an AVI file frame by frame. > 2. To be able to access each fram as a simple matrix. > > I tried to search for that in google but could not find something > intuitive and simple. > > The matrices part is important since iamge processing is done through > matrices manipulation. > > MATLAB is an example of a tool with scripting capabilities in which you > can do that in a simple way. > > Is Python adequate for that? > You can use pymedia to do that( http://pymedia.sourceforge.net ) ATM writing of avi files is not supported( mpeg only ), however you can do a simple fix for that if you're interested. The way it works is it parses AVI file, gives you frames( audio, video, text ) and then you can decode video into YUV frames and convert it into the regular BMP image as string which I suppose you meant by "matrix". Dmitry/ From dave at pythonapocrypha.com Tue Aug 3 16:24:15 2004 From: dave at pythonapocrypha.com (Dave Brueck) Date: Tue, 03 Aug 2004 14:24:15 -0600 Subject: simple Thread question In-Reply-To: References: Message-ID: <410FF46F.30708@pythonapocrypha.com> Christopher T King wrote: > On 3 Aug 2004, adeger wrote: > > >>Having trouble with my first forays into threads. Basically, the >>threads don't seem to be working in parallel (or you might say are >>blocking). I've boiled my problems to the following short code block >>and ensuing output. Seems like the output should be all interleaved >>and of course it's not. Running Python 2.2 from ActiveState on >>Windows XP (also doesn't work on Windows 2000). > > The Python interpreter isn't too thread-friendly. Because it's not > re-entrant, it has to make use of a Global Interpreter Lock in order to > keep internal structures from getting mangled. This lock only allows one > thread to access the interpreter at a time, and switches threads every > hundred or so bytecodes. The likely cause of your problem is that your > loops don't reach this switching threshold -- try using xrange(100) or > higher. Er... you're jumping the gun a bit - no need to scare the OP away from threads with all these details about the GIL when the problem was simply that the threads were never started. [snip] > Because of the former property, another thing you can try is > inserting a time.sleep(.1) inside of each loop Uh, did you read his code before responding? (hint: he's already doing that) :) -Dave From eurleif at ecritters.biz Sat Aug 21 16:29:21 2004 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sat, 21 Aug 2004 16:29:21 -0400 Subject: Why are strings immutable? In-Reply-To: <10ieqt67kf3139c@news.supernews.com> References: <10ieqt67kf3139c@news.supernews.com> Message-ID: <2oppelFdg3e7U2@uni-berlin.de> John Roth wrote: > That said, it would be useful to have a > string buffer object that could be changed. What about StringIO? From Domoran at yahoo.de Wed Aug 11 12:58:52 2004 From: Domoran at yahoo.de (Mathias Mamsch) Date: Wed, 11 Aug 2004 18:58:52 +0200 Subject: sleep does not return Message-ID: Hi all, I got a problem with writing a python extension module which launches a bunch of C threads (currently under windows). The module launches a complete speech recognition engine in a new thread and whenever the recognizer recognizes a word a python callback function should be launched. My Problem now is, after dealing with the ThreadState documentation, that in the python test code the interpreter does not return from a time.sleep call ... My guess is I messed around with the ThreadStates so I post some code. please have a look at the thread specific parts of the code, and tell me how to solve the problem properly ... Where do I have to look for the error, what could be the reason why sleep does not return? Thanks in advance, greetings Mathias Mamsch The Python test code first, then relevant C code : ------ python code --------- import idll # this is my module .... import time def Test(s): # this function gets called from the idll C++ code ... print "CALLBACK: ", s idll.SetCallback(Test) # this works ... idll.StartRecognizer(1) # this works too .... time.sleep(0.1) # and here it sleeps forever ---------------------- ---------- C++ Code of the Function which gets called from some c++ thread of the recognizer ----- ---------- It should call the python function in the "Callback" variable of the module --------- static int CHandleFunction () { // ... some vars left out PyThreadState* tstate, *tsave; // Create a new State for the Call ... tstate = PyThreadState_New(mis); // mis is saved in the init (initidll) function PyEval_AcquireLock(); // Lock the GIL tsave = PyThreadState_Swap(tstate); // Swap to the new State Func = ... // Here I get the Callback from the variable result = PyEval_CallObject(Func, PString); // Call the callback function ... ignore PString ... // ... Here I DecRef Func, result and some others ... PyThreadState_Swap(tsave); // swap back the state PyThreadState_Delete(tstate); // delete new state PyEval_ReleaseLock(); // and release the lock return 0; } // the init function ... PyMODINIT_FUNC initidll(void) { PyEval_InitThreads(); // initialize the Threads module if not done yet ... Module = Py_InitModule("idll", SpamMethods); mts = PyThreadState_Get(); mis = mts->interp; // Try to get the main interpreter state ... Py_INCREF(Py_None); PyModule_AddObject(Module, "Callback", Py_None); PyEval_ReleaseLock(); } From jzgoda at gazeta.usun.pl Sat Aug 7 09:50:24 2004 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Sat, 7 Aug 2004 13:50:24 +0000 (UTC) Subject: Questions about parsing XML References: <%T4Rc.150$Iv.46@trndny03> Message-ID: Kyle Root pisze: > I'm writing a practice program that parses an xml config file, at the > moment I'm using expat. However I don't like some of it's behaviors. > For example ParseFile() will parse the *entire* file and I don't want to > do that. I would like to be able to tell it to find such and such a tag > and return the cdata it contains, is this at all possible? If it is how > would I handle optional tags? libxml2 (http://www.xmlsoft.org/) has excellent support for XPath, F. Lundh's ElementTree also supports some XPath expressions, although it is built on expat and needs to parse whole XML document. -- Jarek Zgoda http://jpa.berlios.de/ From heikowu at ceosg.de Wed Aug 11 14:56:27 2004 From: heikowu at ceosg.de (Heiko Wundram) Date: Wed, 11 Aug 2004 20:56:27 +0200 Subject: rsa implementation question In-Reply-To: <200408111920.58037.heikowu@ceosg.de> References: <1092200894.4119a9beb1978@www-mail.usyd.edu.au> <5GkSc.124$O72.121@newssvr14.news.prodigy.com> <200408111920.58037.heikowu@ceosg.de> Message-ID: <200408112056.27767.heikowu@ceosg.de> Am Mittwoch, 11. August 2004 19:20 schrieb Heiko Wundram: > def pad_for_rsa_encrypt(data,algo,n): > retv = [data] > strlen = len(data) > nlen = log2(n)/8 > while strlen < nlen-3: > data.append() > nlen -= len() > data.append(chr(algo)) > data.append(struct.pack("!H",strlen)) > return "".join(data) Whoops, replace data.append by retv.append in that whole block... Heiko. From eldiener at earthlink.net Tue Aug 10 21:00:18 2004 From: eldiener at earthlink.net (Edward Diener) Date: Wed, 11 Aug 2004 01:00:18 GMT Subject: Static method object not callable Message-ID: This simple code example gives me the message, "TypeError: 'staticmethod' object is not callable". class X(object): def Y(x): print x Y = staticmethod(Y) ad = { 1 : Y } def Z(self): self.ad[1](3) x = X() x.Z() print "Done." I know there must be a way to have a class attribute reference a static method, and then call that static method through the reference, so if anyone can correct this it would be appreciated. From jeff at ccvcorp.com Mon Aug 16 22:56:16 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Mon, 16 Aug 2004 19:56:16 -0700 Subject: Python indentation deters newbies? In-Reply-To: <41215667$1_1@127.0.0.1> References: <3064b51d.0408130615.3fc4a760@posting.google.com> <41214271_1@127.0.0.1> <41215667$1_1@127.0.0.1> Message-ID: <10i2st1h94pqm2d@corp.supernews.com> beliavsky at aol.com wrote: >You may want to exit a nested loop when testing if a condition involving >several variables is met, such as searching for a zero of a multivariate >function. > >In Python you can print i,j,k and exit() when m == 0, but in a larger program >you may want more control. > > In this case, I can see several Pythonic ways of doing this. One would be to use an exception. While exceptions are not considered good control structures in other languages, they *are* considered acceptable (and even desirable) in Python. Another way would be to wrap the nested loops inside a function, and simply return the appropriate triple from that function as soon as you find it. An improvement on that would be to replace your return statement with a yield. Suddenly you've got a generator that'll find a whole series of Pythagorean triples! def pyth_triple(max): max += 1 # to simplify range() calls later for i in range(1,max): for j in range(1,max): ij = i**2 + j**2 for k in range(1,max): m = ij - k**2 if m == 0: yield (i, j, k) for triple in pyth_triple(10): print triple (3, 4, 5) (4, 3, 5) (6, 8, 10) (8, 6, 10) For my money, that's cleaner/clearer than the Fortran version. Jeff Shannon Technician/Programmer Credit International From noone at here.com Fri Aug 27 08:03:12 2004 From: noone at here.com (M. Clift) Date: Fri, 27 Aug 2004 13:03:12 +0100 Subject: Thanks Harry References: <1q8002-nal.ln1@suse.zobbo.org> Message-ID: Hi, Thanks for the link. M From jmfbahciv at aol.com Sat Aug 28 05:38:57 2004 From: jmfbahciv at aol.com (jmfbahciv at aol.com) Date: Sat, 28 Aug 04 09:38:57 GMT Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <776e0325.0408260433.449660c8@posting.google.com> <412dfc1c$0$65599$a1866201@newsreader.visi.com> <86hdqpriww.fsf@blue.stonehenge.com> <412e199e$0$8076$a1866201@newsreader.visi.com> Message-ID: <4130654c$0$19703$61fed72c@news.rcn.com> In article , jdoherty at nowhere.null.not (John Doherty) wrote: >In article <412e199e$0$8076$a1866201 at newsreader.visi.com>, Grant Edwards > wrote: > >> On 2004-08-26, Randal L. Schwartz wrote: >> > *** post for FREE via your newsreader at post.newsfeed.com *** >> > >> >>>>>> "Grant" == Grant Edwards writes: >> > >> >Grant> "Guido said it, that settles it, but we're going to discuss >> >Grant> it endlessly and and vote on it using six or seven >> >Grant> different voting algorithms anyway. Then we'll argue about >> >Grant> the voting algorithms." >> > >> > Are the voting algorithms indented consistently? That's a >> > necessity, correct? >> >> Of course, but are they consistently indented using tabs or >> spaces? > >AND HOW MANY SPACES PER TAB STOP? Eight. Now talk about indenting skip returns...that one required blood transfusions. [emoticon looks at list of n.g.] I guess not many will understand. /BAH Subtract a hundred and four for e-mail. From harry.g.george at boeing.com Fri Aug 20 12:31:36 2004 From: harry.g.george at boeing.com (Harry George) Date: Fri, 20 Aug 2004 16:31:36 GMT Subject: WSDL/SOAP/XML-RPC HELP References: Message-ID: Tomislav Lepusic writes: > Hello, > > I don't know if this is the right group (I'm more in Perl, know > nothing about Python), so if you can help me thanks, if not, sorry to > bother you. > > > I'm working on my student project and I'm totally lost and don't have > any idea how to continue, and the deadline is 1.9.2004. Please help, > 'couse i'm loosing myself in this XML/SOAP/RPC/WSDL things...... > > A little discription. > I have to define and make something like virtual driver for serial > port (RS232), only it isn't really a driver. The server has to be on > Linux box (physical port(s) is/are there), and the other side (client) > is not inportant. It is not important what is connected on serial > port. Also, there is no need to work on any kind of drivers on Windows > or something, becouse that is not the point. I have to make an > universal way to send/recive/control serial port on that server > computer from anywhere. I know how to program for serial port on Linux > (in C), and I have made some progress there. That low-level programing > isn't the problem. The problem is how to make it work over the net, so > that someone who wants to write a program on Windows or Mac can use > something universal to access it (like XML). I HAVE TO USE XML-RPC or > SOAP or WSDL or something like that. The problem is that I don't know > how to use those technologies. I read some tutorials, guides on > XML-RPC, SOAP and WSDL, and I'm totally lost now. > BTW, I was planning to use Perl becouse I know something about it. (I > don't know Java) > > So, if you can help me in any way (advice, similar example or > something), please do. This is very important to me. I forget, > everything must be secure (SSL or something). > > Thank you > > Tom 1. Many of us spent time in perl-land, and feel the move to python is worth your while, especially if you are currently confused. Python is an excellent environment ofr learning new problem spaces, even if you later implement in other languages. 2. To learn more about XML, there are zilions of books. I find E.R. Harold's "XML Bible", IDG Books to be useful -- enough examples to get going, but not so much detail you get lost. You still have to visit the specs at: http://xml.coverpages.org/xml.html http://www.w3.org/TR/1998/REC-xml-19980210.html You probably don't need to know this to use XMPRPC. Just follow the examples. For SOAP, you probably do need a good sense of XML and XSchemas. 3. To learn more about SOAP/WSDL, see James Snell et al "Programming Web Services with SOAP", O'Reilly, 2002. There are enough examples to get the feel for it. If you are working in python, see http://pywebsvcs.sourceforge.net/ 4. In the opinion of many sensible people, SOAP/WSDL is a monster that started as an MS .COM extension of XMLRPC and got totally out of control. Or more to the point, got out of the control of standards efforts to "play well with others", and got into the control of corporations seeking a new mechanism for proprietary lockin. 5. XMLRPC is the quick/cheap way to get web services. In Python it is pretty straightforward. See http://www.python.org/cgi-bin/moinmoin/XmlRpc 6. Assuming you are new to programming as well as XML/SOAP/WSDL, here are some std approaches to learning new problem domains: 5.1. Do a literature search, get tutorials, ask for help -- you are doing this. 5.2. Setup a small testbed to learn the mechanisms. Typically start with a known good source or server, and read/parse/process that. Then learn to write/generate/serve. In this case, you should probably follow the XMPRPC example above. This is NOT your actual classroom exercise -- it is just a learning environment. Once you understand the mechanisms, you can architect and develop your project. You can even grow them side-by-side (learn some more, then code some more, etc.) 5.3. In a system with several interacting parts (sounds like your exercise), the biggest problem is system integration. This can be a nightmare if you've left it to the last phase. Instead, get the whole thing connected with minimal functionality right from the start. E.g., a simple query at one end gets to the other end and is acknowledged. Build an automated regression test process around this (ask when you get to this point in python). Then add functionality feature by feature, testing as you go. -- harry.g.george at boeing.com 6-6M21 BCA CompArch Design Engineering Phone: (425) 342-0007 From siona at chiark.greenend.org.uk Fri Aug 20 08:20:07 2004 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 20 Aug 2004 13:20:07 +0100 (BST) Subject: Alternative decorator syntax decision References: Message-ID: Paul McGuire wrote: >The significant alternatives have been listed on the Python wiki at >http://www.python.org/moin/PythonDecorators . C2 C2 J2 I'm really not sure what I don't like about the @ syntax. Most of the time it's the idea that a statement at a given indentation level affects *just* the next suite, not the rest of the file. Then I look at the J options (other than J1) which are doing much the same thing and seem reasonable (if not my first choice), and think maybe it's the line-noise effect of the "@". But decorators aren't something I can see myself making much (if any) use of, so I'll live with whatever they turn out as. -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From gabor at z10n.net Mon Aug 9 11:36:02 2004 From: gabor at z10n.net (gabor farkas) Date: Mon, 09 Aug 2004 17:36:02 +0200 Subject: IronPython-0.6 is now available! In-Reply-To: <278de0e.0407281353.27b6a457@posting.google.com> References: <278de0e.0407281353.27b6a457@posting.google.com> Message-ID: <1092065762.9279.14.camel@dubb> On Wed, 2004-07-28 at 23:53, Neuruss wrote: > IronPython is currently at a pre-alpha stage suitable for > experimentation but not for serious development work. > > http://www.ironpython.com what i wonder is: 1. class libraries..what class libraries should an ironpython developer use? the (c)python ones? the dot-net ones? so ironPython imho does not mean that now we can run our python programs in dot-net. it means that if someone wants to write a program using dot-net libraries, he can now use python... and..well...what i like in python is not just the language syntax. i also like the way the python libraries are written, that they are very easy to use and so on. so for me a python language which runs on the dot-net classes is not that much interesting..(unless i need to access dot-net classes). and also... python is nice, but at the point when you will want to write a class that can be used from other dot-net languages, you will have to make it dot-net compliant, so you will have to make it statically typed (i am not sure that i am using the correct terminology here. what i mean that you will have to specify the types of the variables and function return values and so on). the other aspect are for example binginds... for example GTK. there is the pyGTK project. but there is also the gtk# project. so imagine that i want to create a program using python+gtk. what should i use? ironPython + gtk#? (c)python + pygtk? and to look a little bit into the future: should the pygtk devels switch to gtk# instead? ;) i don't know what's the good answer...i am just thinking.... yes...microsoft made the dot-net thing cross-language, but the class library was defined/specified imho in a way with is mostly suited only for java-like languages... gabor From pythongnome at hotmail.com Tue Aug 17 08:37:41 2004 From: pythongnome at hotmail.com (Lucas Raab) Date: Tue, 17 Aug 2004 12:37:41 GMT Subject: How big can a Python program be? References: <903b3fba.0408170333.49ce3944@posting.google.com> Message-ID: As many as our tiny, little minds can string together!! :-> wrote in message news:903b3fba.0408170333.49ce3944 at posting.google.com... > Hi, > > A C program can be hundreds of thousands lines of code big. > C++ millions. > > How about Python? > > Suppose , you are a sole programmer (lonewolf). How many lines can one handle? > > Thanks, > > > jan bodnar From pit.grinja at gmx.de Fri Aug 27 12:28:53 2004 From: pit.grinja at gmx.de (Piet) Date: 27 Aug 2004 09:28:53 -0700 Subject: mySQLdb References: <1093558526.705789@seven.kulnet.kuleuven.ac.be> Message-ID: <39cbe663.0408270828.6065309d@posting.google.com> Hi Johan, I am afraid that there is no simple answer to your (very broad) question. However, that doesn?t mean that the idea behind getting data from python into a MySql database is inherently difficult. It is just not a single step. As Sibylle pointed out, subclassing MySQLdb is not possible. From what I have understood so far, this module is more or less an interface that you can use to type SQL commands. That is, IMHO this module is of very limited use when you are not familiar with the mysql syntax. The second thing that you have to know (which is a prerequisite for profiting from the SQL statements) that you are familiar in general with the idea of relational databases. When these conditions are fulfilled, everything is quite ease. Lets us assume that you have a table named "persons" with the columns "firstname" and "lastname" and a dictionary "people" with the content {"Johan":"Potums";"Pit":"Grinja"} and you want to get that data in the database, then you would make a connection to the database and create a cursor as follows: server = MySQLdb.connect() cursor = server.cursor for name in {"Johan":"Potums";"Pit":"Grinja"}.keys(): cursor.execute("INSERT into persons (name,vorname) "+ name + "," +people[name]) or something like that. Depending on where you start, it can take some time to get used to these concepts, but believe me, it is worth it! Best wishes Peter From no_sp at m_please.cc Thu Aug 5 07:20:52 2004 From: no_sp at m_please.cc (Mathias) Date: Thu, 05 Aug 2004 13:20:52 +0200 Subject: Q: scipy.xplt.subplot Message-ID: Hi all, I'd like to display a number of pictures with xplt.imagesc() in the same window using xplt.subplot() Now I expected 3 or 4 parameters in subplot(): -total # of plots in X dir. -total # of plots in Y dir. -number or coordinates of current plot However, there seem to be only Numy and Numx. Documentation on this function is ...well... scarce ;) Thanks for help, Mathias From michele.simionato at gmail.com Sat Aug 7 01:20:44 2004 From: michele.simionato at gmail.com (Michele Simionato) Date: 6 Aug 2004 22:20:44 -0700 Subject: elements of decorator syntax suggestions References: Message-ID: <4edc17eb.0408062120.2c62ab14@posting.google.com> Anthony Baxter wrote in message news:... > This is the biggy, it seems. Current (as of a couple of hours ago) > discussions on python-dev are discussing other alternatives instead > of @, that will hopefully make it easier for IPython or Leo to cope > for now (but note that in the future, some other use for @ might be > found, so anyone relying on it at the moment might want to think > about that). One current suggestion is to use the | character, instead. > Aha! These are good news!! I like the current proposal better than the list syntax (too many parens and commas) *except* for the "@". The "@" is terrible! But fortunately we have plenty of alternative punctuation to choose upon: the colon, the dot, the "|", even the caret, the tilde, etc. All stuff which is already in current Python. At the moment I like this: - sincronyzed - classmethod def f(cls, *args): pass Michele Simionato From cousinstanley at hotmail.com Wed Aug 25 02:46:31 2004 From: cousinstanley at hotmail.com (Cousin Stanley) Date: 25 Aug 2004 06:46:31 GMT Subject: Linux : kdialog Message-ID: <2p2qu7Fftl1rU1@uni-berlin.de> I saw a reference yesterday while reading a Linux news group to using kdialog in a bash shell script, so I decided to try it from Python .... import os pipe_in = os.popen( "kdialog --inputbox 'Guido who ?' " ) reply = '"' + pipe_in.readline() + '"' msg_box = os.system( 'kdialog --msgbox ' + reply ) This seems to be a fairly easy method for some basic Python GUI programming in Linux without digging too deeply into Qt or KDE docs .... kdialog --help # for a list of other options -- Cousin Stanley Human Being Phoenix, Arizona From tismer at stackless.com Mon Aug 9 09:41:12 2004 From: tismer at stackless.com (Christian Tismer) Date: Mon, 09 Aug 2004 15:41:12 +0200 Subject: Find out the file name of a module from inside the module? In-Reply-To: References: Message-ID: <41177EF8.2080406@stackless.com> Andreas Neudecker wrote: > Hi. > > I know you can read the filename of a program as sys.argv[0]. But what > about modules? Is there a similar way to find out the file name of a > module (called by some other module or program) from inside this module? If your modules knows that it is a module, it can inspect its __file__ attribute. You can find out whether you have been imported by testing whether there is a __file__ attribute, otherwise you are probably executed, and there is no name available. try: fname = __file__ except NameError: fname = "?" In cases where you absolutely need a file name, and if you know that you are also used as a module, you can of course import yourself, in order to get the file name. This implies the need to know your module name, which doesn't make things so much better: # assuming this is MyModule import MyModule fname = MyModule.__file__ del MyModule Or even shorter: from MyModule import __file__ as fname ciao - chris -- Christian Tismer :^) Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From jerf at jerf.org Sun Aug 22 23:00:14 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Mon, 23 Aug 2004 03:00:14 GMT Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> <278de0e.0408220636.3ee25f9d@posting.google.com> <278de0e.0408221450.324e8178@posting.google.com> Message-ID: On Sun, 22 Aug 2004 15:50:21 -0700, Neuruss wrote: >> Statements like that serve only to demonstrate the narrowness of >> thought of the writer. > > Excuse me? > It seems that you're missing the point. With respect, I think it is you who are not understanding the objections people are having to your writing. It is not this part that people are objecting: > But you can't deny that > for some problem domains, it is slow. Very slow. It is this: > but speed is critical And bordering on the offensive to some people is this: > and this is were all efforts should be concentrated. as Python is an open-source and volunteer based this can be interpreted as a command on how people should spend their freely offered time. (In other words, all of *what* efforts? Are you helping to speed up Python at all, or is this just rather strongly worded "suggestions" to other people? Not a friendly approach.) > So my intention when I started this thread, was to learn more about > these projects, read other oppinions, get some news, etc... I didn't > mean to start a a nonsense discussion! Referring to other people's opinions as "nonsense" is also not a path to a productive discussion, especially when the prime criterion for "nonsensicalness" seems to be "an opinion different then mine". (For one, many people at many times, not just in this thread, have observed that "speed" is a meaningless term without a context, and that Python is fast enough for many, many contexts. Repeated assertion that there exist contexts where Python isn't fast enough does nothing to disprove that point. If you don't understand why that is logically true, I suggest thinking about it for a bit before replying yet again that there exist contexts where Python isn't fast enough.) From peter at engcorp.com Tue Aug 17 19:28:42 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 17 Aug 2004 19:28:42 -0400 Subject: Flython In-Reply-To: References: Message-ID: Dave Benjamin wrote: > I have been writing > ActionScript for two years now, and I am so sick and tired of its lack of > useful data structures (like sets and dictionaries), god-awful > error-checking (any bad message results in the "undefined" value, which > accpets any message and returns the "undefined" value, and so on, until your > error surfaces someplace completely different from where it was caused), > lack of exceptions, lack of any standard for modularity... I could just go > on and on. I'm currently maintaining a 10,000 line ActionScript program, and > I would be so happy to rewrite it in Python right now. > > And Python *is* magic. =) So Dan was right on both counts. :-) ('''Either Dave thinks it just can't be done, or he really, /really/ wants this compiler.''') What version of the SWF format are you stuck writing to? It appears that even SWF 5 supports Javascript-style "dictionaries" by using attributes on an object. For example, "ActionEnumerate" will let you iterate over all properties on an object ala the Python "for k in dict". As for exceptions, they were added in SWF 7, so I'm guessing you're stuck somewhere prior to that. Your life must really suck. ;-) > Peter Hansen wrote: >>In any case, if this is a serious challenge, you'd better start >>identifying the constraints and minimum requirements, as I'm >>rather positive that it's possible to encode at least *one* >>Python statement (print) into Flash bytecode which would >>execute properly... shall I demonstrate for, say, one pie? > > Good point. I expect at least the full syntax as of Python 2.1, which means > list comps but no "yield" or metaclasses or any fancy stuff like that. > Perhaps one pie per Bagley's Shootout example, or maybe one pie per fully > exposed Flash API (MovieClip, LocalConnection, etc.). I'm open to > negotiation. Gosh you set a high target. Much as I like the taste of pie (Mmmmm... piiiiie), and that cold clammy feeling as it drips down inside my shirt, I don't think I'll be accepting the challenge any time soon. Not, at least, until I learn a lot more about compilers than I currently know (hint, it involves the word "sweet" and "all"). One thing that would help would be a little direction from someone in the know as to how Jython handles things that are simply not available in Java bytecode. For example, as far as I know the main operators for basic primitive types in Java are implemented with different bytecode instructions, while in CPython things like "add" are implemented as a single bytecode which happens to special case integers for performance, but falls back to a dynamic lookup if the types being added are not integers. That looks to me like a bit of a conundrum. To turn the Python code into the appropriate Java bytecodes, wouldn't you have to know the types of the data during compilation (as in static data types)? But Python doesn't have that (yet), so how is it done? Are all "adds" sent to some library routine which is made available to all applications, and that routine then handles the Python-style dynamic add operation? In some ways, I think the SWF bytecode is even closer to Python than Java's bytecode is, but I'm pretty sure that I couldn't begin to imagine how one would target either of them... -Peter From martin at v.loewis.de Thu Aug 19 15:30:28 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Thu, 19 Aug 2004 21:30:28 +0200 Subject: Unix applications in python: production install questions In-Reply-To: References: Message-ID: <4124ffcc$0$24852$9b622d9e@news.freenet.de> Neil Zanella wrote: > What is the best way to install a python application under Unix. Since python > modules are platform independent I would guess these should be placed under an > application specific directory under either /usr/share or /usr/local/share with > a corresponding link to the main module(s) under /usr/bin or /usr/local/bin for > user applications and /usr/sbin or /usr/local/sbin for system applications. > Assuming this is done, should .pyc and .pyo files also be placed under > /usr/share or /usr/local/share? That doesn't really work. You should install Python modules and byte code into Python's site-packages. > The question is > whether the installer should install these files or not. > Provided the installer is to install these files, then > how can they be generated. That depends on the installer technology, no? If it has the notion of a postinstall action, then you should run compileall.py on all directories where you have placed Python source. Doing so is a good idea, as it reduces the size of the package, and possibly allows to support multiple Python versions (which all have different byte code format) in a single package. Regards, Martin From christianzlong at yahoo.com Fri Aug 20 16:20:02 2004 From: christianzlong at yahoo.com (Christian Long) Date: 20 Aug 2004 13:20:02 -0700 Subject: Access to Oracle References: Message-ID: <8847f370.0408201220.406a4ad0@posting.google.com> Fri Aug-20-2004 13:53 Congrats on getting the green light on Python. I had a blast writing my Python/Oracle app (a warehouse receiving automation project using Symbol 6846 handheld computers/scanners) I am in the middle of testing an upgrade from Oracle 8 to Oracle 9i. DCOracle2 worked well with Oracle 8 (with one caveat - see below), and after some finagling, DCOracle2 seems to be working well with Oracle 9i My recommendation: Test ALL of your complicated stored procedure calls before deciding to use DCOracle2. I had trouble with some stored procedure calls - it failed when passing null on some IN/OUT parameters. I wrote some wrapper procedures to workaround the problem, but it was a bit of a pain. DCOracle2 upgrade to Oracle 9i (9.2.0.3) HP-UX B.11.00 U 9000/861/D270 Python 2.2.2 Oracle 8 installs 32-bit libraries in $ORACLE_HOME/lib and 64-bit libraries in $ORACLE_HOME/lib64 Oracle 9i installs 64-bit libraries in $ORACLE_HOME/lib and 32-bit libraries in $ORACLE_HOME/lib32 (At least, that was the way the DBA set it up on my box when he did the upgrade) This caused DCOracle2 to fail, since it was connecting to the 64-bit version of libclntsh.sl instead of the 32-bit. libclntsh.sl is the Oracle client library. On HP-UX, shared libraries have the sl extension. On other platforms the file is called libclntsh.so $ORACLE_HOME/lib/libclntsh.sl: Mismatched ABI. 64-bit PA shared library found in 32-bit link. I changed the Makefiles to point to the lib32 folder, and got it to work. Here are the steps I used to get DCOracle2 working with Oracle 9i and HP-UX 11. I used the latest version as of 8/19/04, which is available from Zope CVS here: http://cvs.zope.org/Products/DCOracle2/DCOracle2.tar.gz?tarball=1. Note that I am not using Zope. I'm just using DCOracle2 to connect my application (written in Python) to Oracle 9i Starting with the downloaded gzipped tarball, which I put in a directory called /tmp/mra_depots # Unpack and expand gunzip DCOracle.tar.gz tar -xvf DCOracle2.tar cd DCOracle2 # Find and replace occurences of .so with .sl to match HP-UX # naming conventions. See README-HP-UX file included # in the distribution. Also, replace references to # $ORACLE_HOME/lib with $ORACLE_HOME/lib32 vi Makefile :%s/\.so/.sl/gc :wq vi src/testora :%s/\.so/.sl/gc :%s/\$ORACLE_HOME\/lib/$ORACLE_HOME\/lib32/gc :wq vi src/Setup.in.dco :%s/\/lib/\/lib32/gc :wq vi proof/Makefile :%s/\/lib/\/lib32/gc :wq vi setup.py :%s/"lib"/"lib32"/gc :wq # Now, build the DCOracle adapter and move it to the Python # folder. You may need root privileges to move the # adapter to the Python folder. NOTE: After the build, the # original DCOracle2 folder contains another DCOracle2 folder. # MOVE THE INNERMOST DCOracle2 folder, NOT THE OUTER ONE! make su rm -r /usr/local/lib/python2.2/DCOracle2 mv /tmp/mra_depots/DCOracle2/DCOracle2 /usr/local/lib/python2.2 exit Notes: This is a vi replacement command to replace $ORACLE_HOME/lib with $ORACLE_HOME/lib32 :%s/\$ORACLE_HOME\/lib/$ORACLE_HOME\/lib32/gc Breaking this vi command down for the benefit of vi virgins : enter command entry mode % search entire file s replace / delimiter between 's' and search string \ escape character for dollar sign to follow $ORACLE_HOME\/lib search string, including escaped forward slash \/ (that's a \ and a / , not a V !) / delimiter between search string and replacement string $ORACLE_HOME\/lib32 replacement string (we only need to escape the forward slash here) / delimiter between replacement string and search options g change every occurance in a line c confirm changes This will highlight each proposed change, and ask you to confirm. Type y and hit enter for each one. "Greg Lindstrom" wrote in message news:... > Greetings- > > I am running Python 2.3.3 on HP-UX and would like to access an Oracle 9i > database. Looking through the vaults, I see 4 or 5 modules that might work > and was wondering if anyone is currently hitting Oracle and what are you > using. I get to build a new system from the ground up and the powers that > be are allowing me to do it in Python. I'm quite happy. > > Thanks for your help, > > --greg > > Greg Lindstrom (501) 975-4859 > NovaSys Health greg.lindstrom at novasyshealth.com > > "We are the music makers, and we are the dreamers of dreams" W.W. > > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > - - - - > This email and any attachments to it are privileged and confidential and are > intended solely for use of the individual or entity to which they are > addressed. If the reader of this message is not the intended recipient, any > use, distribution, or copying of this communication, or disclosure of all or > any part of its content to any other person, is strictly prohibited. If you > have received this communication in error, please notify the sender by > replying to this message and destroy this message and delete any copies held > in your electronic files. Thank you. > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > - - - - From -$P-W$- at noctua.org.uk Tue Aug 10 16:38:00 2004 From: -$P-W$- at noctua.org.uk (Paul Wright) Date: Tue, 10 Aug 2004 21:38:00 +0100 Subject: Parsing broken HTML via Mozilla References: Message-ID: In article , Walter D?rwald wrote: > I'm trying to parse broken HTML with several Python tools. > Unfortunately none of them work 100% reliable. Problems are e.g. > nested comments, bare "&" in URLs and "<" in text (e.g. "if foo < > bar") etc. Not a Mozilla solution, but I hear good things about http://www.crummy.com/software/BeautifulSoup/ -- Paul Wright | http://pobox.com/~pw201 | http://blog.noctua.org.uk/ Reply address is valid but discards mail with attachments: send plain text only From __peter__ at web.de Sun Aug 22 10:04:55 2004 From: __peter__ at web.de (Peter Otten) Date: Sun, 22 Aug 2004 16:04:55 +0200 Subject: clear content of 'printed' References: Message-ID: Christian Otteneuer wrote: > Is there a possibility to do clear the content of 'printed' in python? What is 'printed'? A string, a list, a dictionary, a StringIO instance... - as long as we do not know what it is we cannot say how/whether it can be cleared. It is common practice in Python to just forget about an old object and create a new one, though: for path in aList: printed = Printed() printed.fillWith("some text") container.writeToFile(path, printed) Or was the print "some text" statement for real and you are assigning to sys.stdout (generally a bad idea)? Please provide the complete source code or at least some more context. Peter From claird at lairds.us Tue Aug 24 09:08:14 2004 From: claird at lairds.us (Cameron Laird) Date: Tue, 24 Aug 2004 13:08:14 GMT Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 23) References: Message-ID: <68prv1-s8f.ln1@lairds.us> In article , Peter Otten <__peter__ at web.de> wrote: >Anthony Baxter wrote: > >> On Mon, 23 Aug 2004 20:08:07 GMT, Peter Otten >> wrote: . . . >> ... just to correct the record - my efforts here have not been >> primarily aimed at defending the pie-syntax, but instead aimed at >> shaking out a decent response. I'm trying _very_ hard to make sure . . . >I made no assumptions about your motives in the above snippet, so this is >not a correction, strictly speaking. . . . >But even if I wanted, the formal constraints of the Python-URL make it hard >to use it as a means of propaganda... > >Peter > > However we taxonomize individual sentences, it's ALWAYS in the spirit of "Python-URL!" to inspire more precision and clarification. Peter's done tremendous work for many weeks distilling megabytes of traffic into concise, accurate, understandable descriptions. Any help we get refining or elaborating those descriptions is all to the good. From http Sun Aug 29 20:49:55 2004 From: http (Paul Rubin) Date: 29 Aug 2004 17:49:55 -0700 Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: <7xllfx5u18.fsf@ruckus.brouhaha.com> Paul Morrow writes: > I believe that we should think of assignments to __xxx__ attributes as > not being part of the function's body, but instead part of its > declaration, just as we do with its docstring. > > def circum(diameter): > """This describe's foo.""" > __author__ = 'Paul Morrow' > __version__ = '0.1' That's fundamentally a pretty good idea, but conflicts with how we currently use __xxx__ attributes: def fcn(self, x, y, r): ... class circle(shape): __init__ = fcn should work about the same way as class circle(shape): def __init__(self, x, y, r): ... # same function as fcn above From vincent_delft at yahoo.com Sun Aug 22 10:36:04 2004 From: vincent_delft at yahoo.com (vincent_delft at yahoo.com) Date: Sun, 22 Aug 2004 16:36:04 +0200 Subject: zipfile module: problems with filename having non ascii characters References: <4127a6d7$0$4090$ba620e4c@news.skynet.be> <41284ac0$0$3551$ba620e4c@news.skynet.be> <41285BBB.1050800@v.loewis.de> Message-ID: <4128ae97$0$4128$ba620e4c@news.skynet.be> "Martin v. L?wis" wrote: > vincent_delft at yahoo.com wrote: >> That limitation is only valid for zip files ? > > It appears that WinZip and other tools interpret the file names in a > zipfile in CP437. So to properly put non-ASCII file names into a > zipfile, you need to convert them into CP437. If the file name > contains a character which is not available in CP437, you cannot > save the file in a zipfile (without renaming it). > Thanks, with cp437 it rocks!!!! > Not really a Unicode problem, but rather a problem that Unicode > tries to solve. > >> Is there an another "compression tool" that don't have such limitation >> (tgz? , bz2? , ???? > > tar, traditionally, is also unaware of character sets. Single Unix 3 > (and I believe also earlier) ended the tar wars with the introduction > of the pax utility, which does allow for specification of a character > set in a pax file; among the supported character sets are ISO-8859-n, > and UTF-8. Thanks for the info. > > J?rg Schilling's star(1) also uses UTF-8 for file names. > > On the non-tar side of the world, WinRAR supports Unicode in archives. > For compatibility, they also put a non-Unicode name into the archive, > but the Unicode name, if present, is meant to take precedence. > Thus, the most "portable" compression tool. Thanks for those valuable remarks. Vincent From aahz at pythoncraft.com Wed Aug 18 13:44:23 2004 From: aahz at pythoncraft.com (Aahz) Date: 18 Aug 2004 13:44:23 -0400 Subject: age of Python programmers References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: In article <4123874C.8000304 at chamonix.reportlab.co.uk>, Robin Becker wrote: > > [...] Not too many late-30s, I guess. I've been programming Python for six years, started at nine years old with BASIC. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com From snail at objmedia.demon.co.uk Fri Aug 27 14:10:37 2004 From: snail at objmedia.demon.co.uk (Stephen Kellett) Date: Fri, 27 Aug 2004 19:10:37 +0100 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: In message , Espen Vestre writes >Great song, but their hard-hitting stuff is even better. For instance >"Lisp in the Hills" or "Career of Eval". They even provided your very own theme tune to red/black trees - "The Red and the Black" -- Stephen Kellett Object Media Limited http://www.objmedia.demon.co.uk RSI Information: http://www.objmedia.demon.co.uk/rsi.html From ronaldoussoren at mac.com Sat Aug 7 12:29:44 2004 From: ronaldoussoren at mac.com (Ronald Oussoren) Date: Sat, 7 Aug 2004 18:29:44 +0200 Subject: decorators and multimethods In-Reply-To: <4edc17eb.0408070742.664fa9c0@posting.google.com> References: <4edc17eb.0408062340.71ab270f@posting.google.com> <4edc17eb.0408070742.664fa9c0@posting.google.com> Message-ID: On 7-aug-04, at 17:42, Michele Simionato wrote: > > where I use "_" as a poor man anonymous function. I cannot reuse the > name > "foo" now, since > > @foo.addmethod(...) > def foo(..): > .... > > is really converted to > > def foo(..) > ... > > foo=foo.addmethod(...)(foo) No it isn't. The decorators are called before the function is added to a namespace, e.g. it's more like: def _(): def foo(..): .. return foo foo = foo.addmethod(...)(_()) Ronald From koko9991 at compuserve.de Thu Aug 19 08:46:30 2004 From: koko9991 at compuserve.de (Konrad Koller) Date: Thu, 19 Aug 2004 12:46:30 GMT Subject: PyQt(Qt): unexpected scrollbars in QCanvasView References: <411dcfd0.649442281@news.compuserve.de> Message-ID: <41249ee6.346093812@news.compuserve.de> >> For a card playing game I constructed a layout of 49 playing cards >> (size of each: x=71, y=96) which are arranged in a 7X7 matrix side by >> side. Accordingly the pysical size of the Canvas is x=71*7, y=96*7: >> >> in the main program: >> canvas=QCanvas(497,672) >> >> class Board(QCanvasView): >> def __init__(self,canvas,parent): >> QCanvasView.__init__(self,canvas,parent) >> >> but QCanvasView produces a layout with scrollbars in both directions. >> This is very annoying for the player because although the screen's >> size is more than appropriate for a total layout only some of the >> cards can be viewed without scrolling. The QScrollView documentation >> states that as default QScrollView shows a scrollbar when the content >> is too tall to fit and not else. What goes wrong? >> I am using PyQt 3.11 and Qt 3.3.1 under Linux. Sam Holden wrote: >I would guess it is using the viewable size with the scrollbars to determine >whether scrollbars are needed, rather than the size without them. >If you know the scrollbars aren't needed you can manually turn them off: > self.setVScrollBarMode(QCanvasView.AlwaysOff) > self.setHScrollBarMode(QCanvasView.AlwaysOff) > Both scrollbars now have disappeared. All 7 columns can be viewed, but not all 7 rows. This remains as an unexpected problem. Konrad Koller From squirrel at WPI.EDU Thu Aug 5 12:56:38 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 5 Aug 2004 12:56:38 -0400 Subject: Confused about pep 318 In-Reply-To: References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: On Fri, 6 Aug 2004, Anthony Baxter wrote: > http://mail.python.org/pipermail/python-dev/2004-June/thread.html#45516 > was over a month earlier. That thread reaches no consensus, other than, in his sole post in the thread, Guido stating "I would love to see an implementation of this idea." Nothing about "this is going to be in 2.4a2, anybody vehemently opposed to it?" Like I said, the go-ahead was given privately. > In addition, the particular SF item for this > http://www.python.org/sf/979728 wasn't exactly hidden. Indeed; I'm surprised it isn't titled "Beware of the Leopard". From squirrel at WPI.EDU Mon Aug 16 11:46:12 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Mon, 16 Aug 2004 11:46:12 -0400 Subject: Newbie question about file input In-Reply-To: References: Message-ID: On Mon, 16 Aug 2004, Aaron Deskins wrote: > Basically every game starts with the [Event "..."] header and then the > information about the game is given. > > My first attempt at the python script is: > > #! /usr/bin/env python > import string > import sys > zf=open('test.pgn','r') > # games is number of games > games = 0 > while 1: > line = zf.readline() > if line == '': > break > ls = line.split() > print ls[0] > if ls[0] == '[Event': > games+=1 > zf.close() > print games > > I'm having problems when the script reads a blank line from the pgn > file. I get the following error message: > IndexError: list index out of range > The problem is that ls[0] does not exist when a blank line is read. What > would be the best way of fixing this? The immediate fix is to check for newlines, in addition to blank strings: if line == '' or line =='\n': break The not-so-immediate fix would be to skip the blank line check, and instead check the length of ls: if len(ls) and ls[0] == '[Event': But perhaps a better fix would be to skip the split and use the str.startswith() method: if line.startswith('[Event'): This won't fail in the case of a blank line, and will be somewhat faster than str.split(). There are, of course, even better fixes (such as using regexes or PyParsing), but they would likely be overkill unless you plan on extracting more data from the file (such as the name of the event). Hope this helps. From peter at engcorp.com Tue Aug 10 10:03:48 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 10 Aug 2004 10:03:48 -0400 Subject: pro python paper In-Reply-To: <3064b51d.0408100549.213dad5@posting.google.com> References: <305aa162.0408091905.5bce8f9a@posting.google.com> <3064b51d.0408100549.213dad5@posting.google.com> Message-ID: beliavsky at aol.com wrote: > ccdetail at gmail.com (ccdetail) wrote in message news:<305aa162.0408091905.5bce8f9a at posting.google.com>... > >>http://www.journyx.com/pdf/PythonAtAGlance.pdf >> >>the above paper is a response to some of our prospects complaints >> >>they were asking us why we use python >> >>thought you guys might be interested >> >>http://journyx.com/clf > > I think the paper exaggerates the virtues of Python relative to other > languages, reducing the credibility of the authors. I agree with this to some extent. > The paragraph in the Python myths section > > "It has no compiler to native code, which means Python programs run > slower. True, it does not compile. That does not mean, however, that > Python programs run slower. If you are tracking the speed of quarks or > landing the space shuttle, you might want to write in Assembly or some > other very low-level language. Other than that, a standard business > application written in Python will run every bit as well as one > written in any other language." > > pretends that the main alternative to Python is Assembly, or some > other > "very low-level language". Actually, it does't really do that. What it says clearly is that for certain types of application (time-critical ones), Assembly or another low level language would be a better alternative to Python. This is not at all the same as the general statement "the main alternative to Python is Assembly". > Have the authors not heard of C++ (with the > Standard Template Library) or Fortran 95 (with multidimensional arrays > and associated intrinsic functions)? I'm quite sure they have. Does anyone really think of C++ or FORTRAN for *time-critical* software (this is different than software where performance is the ultimate goal, by the way). > It is more honest and credible to admit that a Python program often is > slower than one in a compiled language, but that reduced programming > time in Python often outweighs this deficit. That's true though. -Peter From gandalf at geochemsource.com Tue Aug 31 09:13:23 2004 From: gandalf at geochemsource.com (Gandalf) Date: Tue, 31 Aug 2004 15:13:23 +0200 Subject: has_method Message-ID: <41347973.7080006@geochemsource.com> Hi All! Does anyone knows how to tell if an object has a method with a given name? How can I access that method? For attributes, it is easy: class A(object): a = 12 b = 'Python' a = A() a.__dict__.has_key('a') # True a.__dict__.has_key('b') # True a.__dict__.has_key('c') # False But it won't work for methods. Thanks in advance. Laci 2.0 From dougfort at dougfort.com Fri Aug 6 09:15:27 2004 From: dougfort at dougfort.com (Doug Fort) Date: Fri, 06 Aug 2004 13:15:27 GMT Subject: 'Using is not None, may not always work' Message-ID: Hi, Since I installed 2.4a2 I've been getting a warning from pychecker: Using is not None, may not always work'. I thought 'is not None' was the right thing to do. I've had problems with 'if not x:', because some objects return False in this context. -- Doug Fort, Consulting Programmer http://www.dougfort.com From ville at spammers.com Thu Aug 12 08:08:15 2004 From: ville at spammers.com (Ville Vainio) Date: 12 Aug 2004 15:08:15 +0300 Subject: [OT] Keyboard layout, was Re: PEP318 References: <20040812090056.00001e31@titan> Message-ID: >>>>> "Peter" == Peter Otten <__peter__ at web.de> writes: Peter> Let me add that temporarily switching to an American Peter> keyboard layout (*) for programming helps with all of the Peter> following chars: @\[]{}|`. US layout is indeed the only sensible way to program in languages designed for US layouts, which pretty much includes most mainstream languages. If you are not man enough to learn Dvorak, that is ;-). I recently switched over, and did some additional keymap tweaking like switching '8'/'(' and ')'\'9' so that I won't need to press shift for parens. Numbers like 8 and 9 are useless for coding - everything beyond 0 and 1 implies a flawed design. -- Ville Vainio http://tinyurl.com/2prnb From mwh at python.net Mon Aug 23 10:43:42 2004 From: mwh at python.net (Michael Hudson) Date: Mon, 23 Aug 2004 14:43:42 GMT Subject: how to tell if x is an instance of new class? References: Message-ID: Michal Vitecek writes: > hello, > > i'm (once again) fighting with python C API. i'm simply unable to > determine whether 'x' is an instance of new class or not. The problem is that this question isn't terribly wll defined. Why do you want to know? Cheers, mwh -- 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 dyoo at hkn.eecs.berkeley.edu Mon Aug 16 21:04:13 2004 From: dyoo at hkn.eecs.berkeley.edu (Daniel Yoo) Date: Tue, 17 Aug 2004 01:04:13 +0000 (UTC) Subject: mailman mailing list program References: Message-ID: Carol Carrot wrote: [exhasperated Mailman rant cut] Hi Carol, Your question isn't really related to Python: Python's just the implementation language for Mailman. A better bet is to ask your question on "Mailman Users": http://list.org/lists.html where you can get help from dozens of other long-suffering Mailman administrators. : I'm trying to get a header to get attached tot he email. it gets stripped : from the email, whwere as the footer comes in as an attachment. : all this is buried under "non-digest" options for some crazy reason. Having a header is dependent on how messages are delivered. In digest mode, messages are bundled and delivered as a single message. Sending the same header, over and over in the bulk-message, would not be a good idea. So that's why there is a separate variable option that describes the header for non-digest messages (msg_header), and one for digest messages (digest_header). I guess it might make sense to have a separate "Header/Footer" configuration menu, but that's a user interface issue. : How do I get the header to work? Did you update the 'msg_header' variable? Please continue your questions on the 'Mailman Users' mailing list; you should get better help from them. Good luck to you! From ptmcg at austin.rr._bogus_.com Sun Aug 22 14:37:01 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Sun, 22 Aug 2004 18:37:01 GMT Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? References: Message-ID: "Arthur" wrote in message news:ifchi0hqmhpag5umuukest5v4f2e73hjud at 4ax.com... > On Sun, 22 Aug 2004 08:07:53 -0500, Doug Holton > wrote: > > I think it should also be noted in the report of the voting results > that the a vote for "no new syntax at this time" was specifically > outlawed. > Arthur - You should really direct this sentiment to Guido himself. I think he's made his mind pretty clear on python-dev that some form of decorator syntax is coming, and that it's coming in 2.4. All this voting process is doing is trying to respond to his call for a unified alternative proposal. I think just about everyone who has had any part in this debate feels that just about all of the relevant issues have been surfaced, and now it is time to move forward with making some decisions. Personally, I think this is why Guido forced the issue by asking Anthony Baxter to go ahead and check in the "@"-based syntax. But that is his process and his choice - please forward your comments on this to him. As far as your comments re: the multivoting process, I'm sorry you felt disenfranchised. You should note that others took the initiative to add their choices to the wiki page when they were not in the initial selection set, and I think a vote of "No decorators, No decorators, No decorators" would have made your point, at least amongst us at c.l.py. But even if we all rally behind "No decorators", I think the result will be that "@" syntax will then prevail by default. In any case, the polls are still "open" - should I put you down for "None of the above" X 3 ? -- Paul From indigo at bitglue.com Wed Aug 18 17:11:20 2004 From: indigo at bitglue.com (Phil Frost) Date: Wed, 18 Aug 2004 17:11:20 -0400 Subject: age of Python programmers In-Reply-To: <2ohpksF94tajU3@uni-berlin.de> References: <2ohpksF94tajU3@uni-berlin.de> Message-ID: <20040818211120.GA6522@unununium.org> I work in a python company of 9 where the average age is probably 25. I've been programming since I was 10 or so, first playing with basic on a commodore 64 (old hardware by then) and then learning ia32 assembly and working my way to higher level languages. I never really thought programming was unpopular among young people, but now that I think about it, the only person I've met in real life that was a young programmer lives 1500km away, and we met on the internet, of course. Furthermore, it seems now the way to become a programmer is to learn VB and write crude programs through high school, then go to college and learn Java, then find a job in web development. I wonder what portion of programmers these days have a real understanding of how the hardware they manipulate works? From this thread so far it seems like such knowledge is more common among Python programmers, which I find odd since Python isn't exactly a low level language. Perhaps it's because no one learns Python until becoming frustrated with 10 other languages? On Wed, Aug 18, 2004 at 09:41:34PM +0200, Reinhold Birkenfeld wrote: > Gerrit Muller wrote: > > Most Python programmers I know are 40+. I am myself 47 (born in december > > 1956). > > > > regards Gerrit > > > > P.S., > > > > how many teeners are still programming? Most teeners I know build > > websites, but they don't program. > > I certainly wouldn't call these shockingly horrible bunches of IE-tags > thrown together with the intention of being regarded as "cool" a "website". > > Reinhold, rant rant From spam at no.thanks Sun Aug 22 23:09:20 2004 From: spam at no.thanks (aum) Date: Mon, 23 Aug 2004 15:09:20 +1200 Subject: ANN: Python MegaTypes Message-ID: Hi, This is more of a pre-announcement actually. I'm developing a module called 'megatypes', which wraps the python builtin types such as 'str', 'int', 'long' into turbo-charged equivalents. A working version of what I've done so far, together with manual and examples, is at: http://www.freenet.org.nz/python/megatypes Example tidbit: >>> s = Str("Hello, world") >>> s.dice(3) ['Hel', 'lo,', ' wo', 'rld'] If anyone likes the concept, and wants to inject creative ideas (and preferably code as well), please let me know, and I'll open up a Sourceforge project for it. Email address - david at freenet dot org dot nz Cheers aum From howard.stearns at charter.net Sat Aug 7 09:12:21 2004 From: howard.stearns at charter.net (Howard Stearns) Date: Sat, 07 Aug 2004 08:12:21 -0500 Subject: decorators and multimethods In-Reply-To: <4edc17eb.0408062340.71ab270f@posting.google.com> References: <4edc17eb.0408062340.71ab270f@posting.google.com> Message-ID: <4114D535.5060701@charter.net> Hey, that's pretty nice. I'll have to get some coffee and study this. What do I read about? I can't find anything about @ or 'decorator' in the 2.3 documentation. What should I be looking for? Michele Simionato wrote: > Decorators can generate endless debate about syntax, but can also > be put to better use ;) > > Actually I was waiting for decorators to play a few tricks that were > syntactically too ugly to be even imaginable for Python 2.3. > > One trick is to use decorators to implement multimethods. A while ago > Howard Stearns posted here a recipe to implement generic functions > a.k.a multimethods. > > I have not studied his recipe, so don't ask me how it works. All I > did was to add an "addmethod" function and save his code in a module > called genericfunctions. > > Decorators allowed me to use the following syntax: > > # BEGIN generic functions in Python, example > # use code and examples from Howard Stearns > > from genericfunctions import Generic_Function, addmethod > > foo = Generic_Function() > > @addmethod(object, object, object) > def foo(_, x, y, z): > return 'default' > > @addmethod(int, int, int) > def foo(call_next, x, y, z): > return 'all ints , ' + call_next(x, y, z) > > @addmethod(object, object) > def foo( _, x, y): > return 'just two' > > print foo # the multimethod table as a dictionary > print foo(1, 2, 'three') # => default > print foo(1, 2, 3) # => all ints, default > print foo(1, 'two') #> just two > print foo('oops') #=> genericfunctions.NoNextMethod error > > # END generic functions in Python, example > > Howard Stearns' code is posted here > http://groups.google.it/groups?hl=it&lr=&ie=UTF-8&threadm=40C3BC71.5050206%40charter.net&rnum=1&prev=/groups%3Fq%3Dhoward%2Bstearns%2Bgroup:comp.lang.python.*%26hl%3Dit%26lr%3D%26ie%3DUTF-8%26group%3Dcomp.lang.python.*%26selm%3D40C3BC71.5050206%2540charter.net%26rnum%3D1 > > I just added the following function: > > import sys > > def addmethod(*types): > """sys._getframe hack; works when the generic function is defined > in the globals namespace.""" > caller_globs = sys._getframe(1).f_globals > def function2generic(f): > generic = caller_globs[f.func_name] > generic[types] = f > return generic > return function2generic > > Decorators did all the rest ;) Just to add an use case I haven't > seen before. > > Michele Simionato From mj-usunto at tkb.pl Wed Aug 18 10:05:34 2004 From: mj-usunto at tkb.pl (Marcin Jurczuk) Date: Wed, 18 Aug 2004 14:05:34 +0000 (UTC) Subject: favorite python web development tool? References: <10i4nttktcvltdd@corp.supernews.com> Message-ID: On 2004-08-17, mike wrote: > hi all - > > > i'm fairly new to python, coming from a java servlet / velocity template > background. i'm looking for a good python web development tool, and > hope to find some suggestions here. > I'm using SkunkWeb (skunkweb,sourceforge.net). realy simple framework and very very fast :) -- Marcin Jurczuk, NIC-HDL: MJ1679-RIPE From apardon at forel.vub.ac.be Tue Aug 17 07:40:36 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 17 Aug 2004 11:40:36 GMT Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> <30260531.0408131853.18ec2446@posting.google.com> <412040f8$0$8087$a1866201@newsreader.visi.com> Message-ID: Op 2004-08-16, Peter Hansen schreef : > Grant Edwards wrote: > >> On 2004-08-16, Peter Hansen wrote: >>>Please, *why* did it put you off? >> Dunno, it just did. >> >> It seems to me that you're asking for a rational explanation >> for an emotional response. It's like asking somebody "*why* >> don't you like pickled beets?" The answer you get is "I just >> don't." > > Hmm... not for me. The answer would be "because they > taste like dirt", That is not an rational explanation. You have just stated that the taste is similar to an other taste you don't like. Now give an explanation why you don't like the taste of dirt. > or "I hate purple", or "anything pickled > sucks". Hating purple and stating that anything pickled sucks don't strike me a rational explanations. > "I just don't" looks a lot like a cop-out. How about: that is how my tongue and brain are wired. -- Antoon Pardon From russblau at hotmail.com Thu Aug 12 09:30:58 2004 From: russblau at hotmail.com (Russell Blau) Date: Thu, 12 Aug 2004 09:30:58 -0400 Subject: Print command References: <2nv6roF54f7iU1@uni-berlin.de> Message-ID: <2o19ojF5ob9jU1@uni-berlin.de> "Peter Hansen" wrote in message news:cvmdnbvUcbh--obcRVn-uw at powergate.ca... > > "Russell Blau" wrote in message > > Actually, I don't know the meaning of ``. > > On some languages, it means "evaluate": Is it the same meaning in > > Python? Ummm, actually, that wasn't me you were quoting; it was the OP who replied to my message pointing out that `x` doesn't mean the same as 'x'. -- I don't actually read my hotmail account, but you can replace hotmail with excite if you really want to reach me. From peter at engcorp.com Mon Aug 16 01:41:52 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 01:41:52 -0400 Subject: Python indentation deters newbies? In-Reply-To: <412040f8$0$8087$a1866201@newsreader.visi.com> References: <3064b51d.0408130615.3fc4a760@posting.google.com> <30260531.0408131853.18ec2446@posting.google.com> <412040f8$0$8087$a1866201@newsreader.visi.com> Message-ID: Grant Edwards wrote: > On 2004-08-16, Peter Hansen wrote: >>Please, *why* did it put you off? > Dunno, it just did. > > It seems to me that you're asking for a rational explanation > for an emotional response. It's like asking somebody "*why* > don't you like pickled beets?" The answer you get is "I just > don't." Hmm... not for me. The answer would be "because they taste like dirt", or "I hate purple", or "anything pickled sucks". "I just don't" looks a lot like a cop-out. If it is an emotional reaction, then the reason someone doesn't like pickled beets would be "because I have a negative emotional reaction to them which I don't understand and cannot put into words"... (but then writing about it wouldn't make any sense ;-) > Perhaps they're just too different from what you're > used to eating. Perhaps there's something bad in your past > associated with beets. It doesn't really matter, since it's > not a reasoned, rational reaction. At the time you have the reaction, you may not understand it. Afterwards, you should be able to analyze it and explain it, I believe. But, whatever, we're different people. I can generally explain my reactions to things while perhaps you can't. > I think my negative reaction was because my only previous > encounters with intentation significance was with Fortan IV and > with Makefiles. I find dealing with both of those unpleasant Ah, thank you! You _can_ do it. ;-) I'll buy this (not that anyone should care whether I buy it or not ;-) as a valid and interesting reason for an initially negative reaction to Python's indentation. The reason I'm asking this is because I believe that if there really are a significant number of people with such a reaction (not necessarily for the same reason as yours), then if we can analyze and discover the most common reasons for such a reaction, then it might well be possible to eliminate the cause and avoid the reaction. For example, if 90% of people who have the "indentation rash" had previous encounters with FORTRAN IV, then it ought to be possible to make it obvious in the early documentation (tutorial, intro page, etc) that Python is not FORTRAN and doesn't suffer from the same limitations with respect to indentation/whitespace significance as FORTRAN does. (Not that I think we'll really find this particular one to be the biggie. But that roughly describes my purpose...) -Peter From grante at visi.com Sun Aug 22 16:31:28 2004 From: grante at visi.com (Grant Edwards) Date: 22 Aug 2004 20:31:28 GMT Subject: 100 % portable ? References: Message-ID: On 2004-08-22, David M. Cooke wrote: > For Mac the preferred place files is ~/Documents, and for config files > is in ~/Library//. Where to per-user config files go? -- Grant Edwards grante Yow! NANCY!! Why is at everything RED?! visi.com From tassilo.von.parseval at rwth-aachen.de Fri Aug 27 01:13:19 2004 From: tassilo.von.parseval at rwth-aachen.de (Tassilo v. Parseval) Date: Fri, 27 Aug 2004 07:13:19 +0200 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <2a56f6a3.0408252257.4f1f92e@posting.google.com> <2p5j10FesankU1@uni-berlin.de> <1gj4z06.14nwnzs1d0kno4N%otto.wyss@orpatec.ch> Message-ID: <2p7vt5Fhho9kU1@uni-berlin.de> Also sprach Otto Wyss: > Tassilo v. Parseval wrote: > >> It would, if anyone could take Xah Lee Loo seriously. But really, no one >> can. He's more like the court jester, creeping out of the dark every so >> and so months. We're all very much enjoying his sporadic shows. Really. >> >> ;-) >> > No offense but could you add some references so anyone can make up is > own opinion? For instance this one: Pay particular attention to the fact that he's whining about a certain feature of a Perl module but posts not only in comp.lang.perl.misc but also in the scheme, lisp, python and ruby group. Tassilo -- $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({ pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#; $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval From johng2001 at rediffmail.com Sun Aug 1 05:30:49 2004 From: johng2001 at rediffmail.com (John) Date: 1 Aug 2004 02:30:49 -0700 Subject: Importance of C# (was Re: IronPython-0.6 is now available!) References: <278de0e.0407281353.27b6a457@posting.google.com> <5dydnZSDZaARoZXcRVn-ug@powergate.ca> <1n5z28erh2m3u.dlg@baczek.net.invalid> Message-ID: > > OK! I am unaware of any. Can you point me to some. > > Well, the one I "crashed" into was when I (by mistake) had compiled > Microsoft's free ASP.Net container (Cassini) using version 1.0 of the > framework, while my ASP.Net application was compiled using version 1.1 > of the framework. The result was that the container complained that it > could not find the superclass for my page, since the 1.0 version of > System.Web.HttpApplication is *not* the 1.1 version of > System.Web.HttpApplication. It doid not even try to use it. > > In Java, I *might* later have received a runtime exception about a > missing method, if I actually used a method that was too "new". > > (The solution to the Cassini problem was to manually write an > application .config XML file that told it to use the 1.1 framework. > This config file is also where you define any dependencies to > particular versions of libraries; by default an application will use > the newest available.) That is more of a side effect of versioning features. Interesting case anyway. I will keep that in mind. > > Yes! Why do I have to list every jar file I use for the application in > > the classpath? Why can't I just drop them in the same folder with the > > app and expect the JVM to find them. > > You can, if the jars are included in your "main jar"'s manifest's > Class-Path value, e.g. > > Main-Class: some.Application > Class-Path: library.jar stuff.jar > > Setting this up is, as in the case of .Net, a task for your IDE. I had some facts wrong about .NET for that bit. I looked up after your post and I know better now. > I've used JBuilder and JDeveloper almost exclusively; I never could > get my head around the "project-less" directory-focused and slow > NetBeans. OK! JBuilder does not look intimidating. I never got excited about the JDeveloper's layout of tools. > Because it hides the .Net complexities from the developer. Is that a > good thing? Hiding complexities from newbies and intermediate users is not a bad idea. The project files are XML anyway. MS is mostly good at catering to the needs of that market. Most Java tools don't seem to do that. The impression I often get is Java is developed primarily for the enterprise. > > They seemed to compile Quake 2 fine. > > How much of it ended up as unmanaged code? An application that runs > outside of the managed container is not a .Net application. I wasn't talking in just performance terms. I meant how the language fit. But that's a good point. That would be interesting to know. Even then, the prospect of being able to seemlessly add unmanaged code for performance bottlenecks without the additional cognitive overhead of integration API is nice. From donn at u.washington.edu Tue Aug 17 12:08:09 2004 From: donn at u.washington.edu (Donn Cave) Date: Tue, 17 Aug 2004 09:08:09 -0700 Subject: os.system(), HTTPServer, and finishing HTTP requests References: <41201e06@nntp.zianet.com> <1092631376.357585@yasure> <41214c28$1@nntp.zianet.com> Message-ID: In article <41214c28$1 at nntp.zianet.com>, "Erik Johnson" wellkeeper com> wrote: ... > I'm not sure why those would all be open, but this little bit seems to > resolve the problem > (it throws OSError when it hits the first invalid file descriptor). > > for fd in xrange(3, 256): > try: > os.close(fd) > except OSError: > break > > If you know a better/smarter way to effect the same thing, I'd be glad to > hear about it. That's a variation on a common idiom. The difference is the break, where more commonly you'd write "pass". If this is happening in the context of a short-term programming effort that has to be very efficient, it's a good idea, because the exceptions make the close much more expensive than it would have been in C, where we usually see this loop. If it needs to work for the indefinite future, I would say change the break to pass. You can't count on that continuous series of open file descriptors. Donn Cave, donn at u.washington.edu From tjreedy at udel.edu Tue Aug 24 21:38:55 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 24 Aug 2004 21:38:55 -0400 Subject: python raw strings? References: <412bc766$1@news.unimelb.edu.au> Message-ID: "Maurice LING" wrote in message news:412bc766$1 at news.unimelb.edu.au... > I'm trying to toy around with PLY (python lex-yacc) by David Beazley > from University of Chicago and realized that the lex module uses python > raw strings. What are python raw strings There is no such thing. Only string/unicode literals prefixed by 'r', which prefix flags a change in the conversion of the literal into a Python object. I believe the term come from 'raw' versus 'cooked' mode terminal input in *nix. Terry J. Reedy From bryanjugglercryptographer at yahoo.com Wed Aug 18 19:17:04 2004 From: bryanjugglercryptographer at yahoo.com (Bryan Olson) Date: 18 Aug 2004 16:17:04 -0700 Subject: Generators versus Coroutines References: <1a517b5.0408170923.48f6d964@posting.google.com> Message-ID: <1a517b5.0408181517.8447681@posting.google.com> Dominic wrote: [Bryan had written:] > > I've seen servers that rock written with explicit event handling, > > threads, processes, and occasionally co-routines. Where are the > > great generator-based servers? > Well, the Erlang (language + telecom platform) uses light-weight > threads which could e.g. be implemented with coroutines in Python. Well, the issue here is whether they could be implemented reasonably in Python as it currently is, with generators but not co-routines. > Event handling is fine but you could also explicitly code > your behaviour as state machines ;-) Hmm, I wasn't distinguishing the two. > The drawback of event > handling is that you have to separate state and control flow > and resuming is error prone whereas generators and coroutines > are easier and feel more natural. Right. Every time you do anything that might block, you have to save your state and return all the way out to the event handler. I think Python generators are about as awkward; you have to explicitly yield through every stacked call. Preserving the local variables seems to be the only advantage. -- --Bryan From xtian at toysinabag.com Mon Aug 9 05:38:55 2004 From: xtian at toysinabag.com (xtian) Date: 9 Aug 2004 02:38:55 -0700 Subject: @decorator syntax is sugar, but for what exactly? References: <4115b53a$1@nntp0.pdx.net> <4116239e$1@news.012.net.il> Message-ID: xtian at toysinabag.com (xtian) wrote in message news:... > [some badly-formatted code] Oops - sorry about the nasty layout there - another example of why tabs are evil. ;) This is what I meant: def property_(f): return property(*f()) class DecorationTest(object): def __init__(self): self._foo = 1 @property_ def foo(): def get(self): print "get" return self._foo def set(self, val): print "set" self._foo = val return get, set t = DecorationTest() print t.foo t.foo = 3 print t.foo xtian From mwh at python.net Wed Aug 4 08:43:26 2004 From: mwh at python.net (Michael Hudson) Date: Wed, 4 Aug 2004 12:43:26 GMT Subject: Subclassing file class References: Message-ID: "David Vaughan" writes: > I'm using v2.3, and trying to write to text files, but with a maximum > line length. So, if a line is getting too long, a suitable ' ' > character is replaced by a new line. I'm subclassing the file class, > and, as long as I just use the write method, this works fine. But > "print >>" doesn't behave as I want: You'll almost certainly be happier implementing a 'file-like object' that does what you want than subclassing file. Cheers, mwh -- Every day I send overnight packages filled with rabid weasels to people who use frames for no good reason. -- The Usenet Oracle, Oracularity #1017-1 From sylvain.thenault at nospam.logilab.fr Tue Aug 24 04:34:16 2004 From: sylvain.thenault at nospam.logilab.fr (Sylvain Thenault) Date: Tue, 24 Aug 2004 10:34:16 +0200 Subject: Logical lines of code counter References: <2ot090Fe5442U1@uni-berlin.de> <2ot78fFe1mneU1@uni-berlin.de> Message-ID: On Sun, 22 Aug 2004 23:43:25 -0400, Leif K-Brooks wrote: > Tim Leslie wrote: >> On Sun, 22 Aug 2004 21:44:17 -0400, Leif K-Brooks >> wrote: >> >>>I got bored with working on larger projects and wrote a little >>>script/module for counting logical (not physical) lines of Python code >>>in a file or directory. >> If you want something which can do this and so much more, have a look at >> pylint. >> >> http://www.logilab.org/projects/pylint > > Neat-looking tool, but not really usable for me. It counts physical lines, > not logical lines; it doesn't seem to have an option to recursively scan > all sub-directories and files in a directory; and it refuses to process a > file if some of the modules code wants to import aren't importable, which > is the case with mod_python code. pylint counts both physical lines and logical lines, but all collected values are not displayed in reports. You should easily add a new report to display some additional information if you need it. Well, it lacks some documentation but the code is quite clean and I would be happy to help. It's also possible to recursivly scan for all python modules in a given package ("pylint mypackage"). The problem with failing import is the most annoying one. I plan to fix it, one day ;) -- Sylvain Th?nault LOGILAB, Paris (France). http://www.logilab.com http://www.logilab.fr http://www.logilab.org From Moiz.Golawala at ge.com Thu Aug 12 11:11:30 2004 From: Moiz.Golawala at ge.com (Golawala, Moiz M (GE Infrastructure)) Date: Thu, 12 Aug 2004 10:11:30 -0500 Subject: os.removedirs not working Message-ID: <4BF8D93CF6F73F4890EB6ED8009ECE191C5CFD@FTWMLVEM01.e2k.ad.ge.com> Hi All, I have a small program that where I am using os.removedirs('C:\\someDir') on windows. I get the error that the directory is not empty. Sure there are sub-directories under it and all file and directories are deletable(nothing is locked by the system) and there are no permission issues either. Can someone please tell me if I am using the os.removedirs() correctly? Moiz Golawala GE Infrastructure, Security Software Engineer Enterprise Solutions T 561 994 5972 F 561 994 6572 E moiz.golawala at ge.com www.gesecurity.com 791 Park of Commerce Blvd., Suite 100 Boca Raton, FL, 33487, U.S.A. GE Security, Inc. From simoninusa2001 at yahoo.co.uk Fri Aug 6 19:48:37 2004 From: simoninusa2001 at yahoo.co.uk (simo) Date: 6 Aug 2004 16:48:37 -0700 Subject: Standalone Python Programs... References: <-aSdndbo7ry5E47cRVn-ig@comcast.com> <41139ac9$0$65604$a1866201@newsreader.visi.com> Message-ID: <30260531.0408061548.283e96b1@posting.google.com> Grant Edwards wrote: > Same here. I've used py2exe + Inno Setup for a handfull of > small wxPython applications and it's all worked quite nicely. Same here too, InnoSetup is especially useful if you need to bundle auxilliary files like icons, images, ChangeLogs etc. or make desktop/startbar shortcuts. I think py2exe is perfect, cx_Freeze is still not 100% > > I can't speak to Linux installations because I have always > > just used the Python installation already there. > Yup. I tried McMillan Installer on Linux, and had little success - because even if you get the binary to build, it usually has .so dependency issues - basically you need wxWidgets or GTK+ or whatever installed on top of any Python you've coded. I've falling back to providing the source and leaving it as an exercise to the user to install all the Python modules they may not have in their base install. One of the attractions of IronPython is that you can build a single .exe (or .bin on Linux I guess?) although the user still needs the CLR runtime installed. From http Fri Aug 20 16:56:11 2004 From: http (Paul Rubin) Date: 20 Aug 2004 13:56:11 -0700 Subject: decorator J4 - any objections? References: <7xbrh5hcpb.fsf@ruckus.brouhaha.com> <7NsVc.155687$M95.24909@pd7tw1no> Message-ID: <7xd61ledg4.fsf@ruckus.brouhaha.com> Martin DeMello writes: > > def func(arg1, arg2) > > @version("Added in 2.4") > > @returns(None): > > > > """Docstring could be here, or in decorator part above""" > > # body goes here > > It's really nice to have an outdented marker for when the actual > function body begins. I don't really see why, but the decorators don't have to be indented: def func(arg1, arg2) -version("Added in 2.4") -returns(None): """Docstring could be here, or in decorator part above""" # body goes here I guess that's ugly though. From rspooner at frisurf.no Tue Aug 3 03:47:44 2004 From: rspooner at frisurf.no (Richard Spooner) Date: Tue, 3 Aug 2004 09:47:44 +0200 Subject: Unbinding sockets in threads.. Message-ID: Chaps, I've written a piece of python code below that when called with a line such as x = getdata(9999), listens on that port for data I'm sending it and puts the data in a list. If I delete x using del x and then try and assign a new value to port 9999 (e.g z=getdata(9999) ) then it reports that the socket it already bound, and I can't find any way of unbinding the port. If I try it not in a thread the del function works fine (i.e. creating and binding a socket s and then deleting it) Can anyone suggest some modifications I can do to make this work?? Thanks in advance Dave import threading import socket import struct import sys import time class getdata(threading.Thread): def __init__(self, port): threading.Thread.__init__(self) self.x = ['ZERO SPACE'] self.s = socket.socket( socket.AF_INET, socket.SOCK_DGRAM ) try: self.s.bind(( '', port)) except socket.error, msg: print "Could not bind to socket" time.sleep(3) self.s.close() sys.exit(1) self.carryon = 'true' self.start() def run(self): while self.carryon == 'true': self.data, self.addr = self.s.recvfrom( 1024 ) self.channel, self.value = struct.unpack( 'IBxxx' , self.data ) try: self.x[int(self.channel)] = self.value except IndexError: while len(self.x)-1 < int(self.channel): if len(self.x) == int(self.channel): self.x.append(self.value) else: self.x.append('NA') except: print "Dictionary creation error" time.sleep(3) self.s.close() sys.exit print self.x return From peter at engcorp.com Wed Aug 18 21:12:55 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 18 Aug 2004 21:12:55 -0400 Subject: simple Thread question In-Reply-To: References: <1d6cdae3.0408171648.1b8767ea@posting.google.com> Message-ID: Aahz wrote: > In article , > Peter Hansen wrote: > >>While it's true that that is all that's needed, it is not required, >>and doesn't really provide any performance improvements. I often do >>the above sort of thing where I use a given module in only one place, >>especially when using threads where it feels subtly cleaner to defer >>loading of some modules until the thread actually starts. > > Except that the import lock makes this a Bad Idea, IMO. Does the import lock apply to the first import, or even to all later ones where it can just find it in sys.modules? -Peter From sjdevnull at yahoo.com Tue Aug 31 12:47:03 2004 From: sjdevnull at yahoo.com (G. S. Hayes) Date: 31 Aug 2004 09:47:03 -0700 Subject: File System References: <10j7r3cflo61680@corp.supernews.com> Message-ID: <96c2e938.0408310847.4a34b73f@posting.google.com> Aaron Bingham wrote in message news:... > Hello Maboroshi, > > You are not the first to think that there might be an alternative to the > filesystem. Here are a few links to sites for projects where > filesystems have been rethought or eliminated in very different ways. And let's not forget the reiserfs version 4 debate that's going on on the linux-kernel mailing list right now (and could potentially result in the fs being very different from the standard Unix fs, allowing a cyclic graph with object inheritance and complex query operations--or not, since it's not entirely clear that that's a good idea). Check out the thread "silent semantic changes with reiser4" and related threads at e.g. http://www.uwsg.iu.edu/hypermail/linux/kernel/0408.3/index.html I guess BeOS had a pretty unique FS as well, and its author (Dominic Giampalo) is working on a new FS for the Mac. And there's the (recently delayed) WinFS as well. From michaels at rd.bbc.co.uk Wed Aug 25 09:33:34 2004 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Wed, 25 Aug 2004 14:33:34 +0100 Subject: PEP318: radical notion References: <412a4222$0$293$626a14ce@news.free.fr> Message-ID: Arien Malec wrote: ... > Is there a valid use case that supports arbitrary magical non-metadata > transformations of standalone functions? 2 use cases (in addition to others people have mentioned) I can think of off the top of my head: * Adding call tracing to specific functions without disturbing the code. * Wrapping generator functions so that they can recieve data in an IPC manner. using: trace(level=1) def somefunc(foo): if bla(foo) == 1: return weeble(foo) elif baz(foo) == 2: return wobble(foo) elif bibble(foo) == 3: return jeeble(foo) elif bloing(foo) == 4: return jobble(foo) elif nickynickynack(foo) == 5: return fnarkle(foo) Adding a trace function in here temporarily would mean you can intercept both the call and the return values conveniently - as you would with memoise (say), but you can do something interesting with it. Furthermore, if you're not sure your memoise decorator is doing the right thing you could do something like: using: trace(level=1) memoise def somefunc(foo): if bla(foo) == 1: ... Followed by... using: memoise trace(level=1) def somefunc(foo): if bla(foo) == 1: ... And potentially: using: trace(level=1) def somefunc(foo): if bla(foo) == 1: ... And do a compare and contrast of results. Behaviour is transformed, there is no metadata involved and it's suitable for any function - whether it's part of a class's namespace (as any kind of method), or not. Since they're not necessarily part of a class you can't use metaclasses to do this. Regards, Michael. -- Michael.Sparks at rd.bbc.co.uk British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From fumanchu at amor.org Mon Aug 16 00:26:29 2004 From: fumanchu at amor.org (Robert Brewer) Date: Sun, 15 Aug 2004 21:26:29 -0700 Subject: Writing traceback Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022DF8@exchange.hqamor.amorhq.net> Ehab Teima wrote: > I have built a server application. It's multithreaded, and everything > works fine so far. I have only one issue with catching exceptions > after I read the documentation but I can't find any problems yet. I'm > catching all errors throughout the code into a function and I write > the traceback to the server log as well as the screen. That's all. I > need not to save it or anything else. The documentation said the > function (in this example catchError) should not handle exceptions > itself. How would I get around this issue given that writing to the > server log must not stop the server? In other words, the function > itself must handle and ignore any exceptions raised by itself. i.e. I > want to make sure that failing to write to the server log is ignored. I would suggest you use the "logging" module instead of rolling your own. Once you've set up the handler, logging complete, annotated exceptions is as simple as "logger.exception(msg)". Try logging.handlers.RotatingFileHandler in particular. If you inspect that module's code, you might notice that even it handles exceptions (see logging.FileHandler.emit()). Robert Brewer MIS Amor Ministries fumanchu at amor.org From usemyfullname at hotmail.com Mon Aug 30 15:25:37 2004 From: usemyfullname at hotmail.com (Antony Sequeira) Date: Mon, 30 Aug 2004 19:25:37 GMT Subject: Xah Lee's Unixism In-Reply-To: References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <1gj5eeq.gb3dk41wup9zwN%otto.wyss@orpatec.ch> <87hdqptl96.fsf_-_@thalassa.informatimago.com> <4PGdnfsOfdDPi63cRVn-tA@speakeasy.net> Message-ID: <41337FC9.8070902@hotmail.com> Andre Majorel wrote: > On 2004-08-28, Rob Warnock wrote: > >>Pascal Bourguignon wrote: >>+--------------- >>| $ telnet xahlee.org 80; >>| Trying 208.186.130.4... >>| Connected to xahlee.org. >>| Escape character is '^]'. >>| GET / HTTP/1.1 >>| >>| HTTP/1.1 400 Bad Request >>| Date: Fri, 27 Aug 2004 01:35:52 GMT >>| Server: Apache/2.0.50 (Fedora) >>| ^^^^^^^^^^^^^^^^^^^^^^ >>+--------------- >> >>So are you complaining about the fact that his hosting provider >>preloaded RedHat Fedora with Apache 2.0 for him? > > > There is no shortage of Windows-based hosting companies, so why > didn't he go there ? Whatever your opinions, it's best to put > your money where your mouth is if you expect to be taken > seriously. > Windows (MS) is not 'Unixism'? -Antony From jeff at ccvcorp.com Wed Aug 11 14:42:29 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Wed, 11 Aug 2004 11:42:29 -0700 Subject: 'break' Causes Execution of Procedure? In-Reply-To: References: Message-ID: <10hkq3u54ht2h4e@corp.supernews.com> Scott Brady Drummonds wrote: >Hi, everyone, > >I have a bug in a script of several hundred lines of code that I cannot >figure out. I have attempted (unsuccessfully) to duplicate this problem in >a smaller script that I can post here but have been unsuccessful. As such, >I'm posting code snippets here in the hopes that someone recognizes a very >basic mistake I've made and can straighten me out. > >First, the portion of my text file that executes my code: > > >if __name__ == '__main__': > if len(sys.argv) != 2: > print('usage: %s ' % sys.argv[0]) > sys.exit() > > main(sys.argv[1]) > > >Here are the first few lines of my 'main' procedure: > >def main(fileName): > print('DEBUG: begin main procedure') > ... > > >And here is the part that is causing problems: > > # 'keys' is a list of integers returned from dict.keys() > for cycle in keys: > if key in skipList: > print ('skipping %d/%d' % (cycle, cycleMap[cycle])) > continue > try: > print('DEBUG: advancing both simulators to %d' % cycle) > procedureThatCouldRaiseEOFError() > except EOFError: > print('DEBUG: encountered EOFError; breaking loop') > break > print('DEBUG: All cycles processed') > > >Here's what I can't figure out. I'm seeing the following text generated >during this script's execution: > >DEBUG: advancing both simulators to 20178 >DEBUG: encountered EOFError; breaking loop >DEBUG: begin main procedure > > >How is it possible that the call to 'break' is seemingly being replaced with >a call to 'main'? > > I suspect that the answer is in the context of the for loop. Try posting a bit more of the surrounding code. (For example, it's not at all clear how your loop relates to the main() snippet that you posted...) Actually, I'm wondering why you catch the exception inside the loop, and then exit the loop. If you wrapped that entire loop in the try/except, then you wouldn't need to worry about using break -- an exception would end the loop and *then* get dealt with. Jeff Shannon Technician/Programmer Credit International From drconrad at metaplay.com.au Mon Aug 16 04:19:28 2004 From: drconrad at metaplay.com.au (Simon Wittber) Date: Mon, 16 Aug 2004 16:19:28 +0800 Subject: {SPAM?} RE: Generators versus Coroutines In-Reply-To: Message-ID: <200408160807.i7G87MJ2022091@redpill.digitalventures.com.au> I've written a small module to help me out in game simulations. I use the MicroThreadPool class (co-routines using generators) whenever I _conceptually_ need to visualize things happening concurrently. http://metaplay.com.au/MEPH.html From ajsiegel at optonline.com Thu Aug 26 10:40:18 2004 From: ajsiegel at optonline.com (Arthur) Date: Thu, 26 Aug 2004 14:40:18 GMT Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: On Thu, 26 Aug 2004 09:31:55 -0400, Paul Morrow wrote: > >Currently, you can change a doc string outside of a function, by >modifying the function's __doc__ attribute > > >>> def foo(): > ... """ I am foo """ > ... > >>> foo.__doc__ > ' I am foo ' > >>> foo.__doc__ = foo.__doc__ + 'indeed' > >>> foo.__doc__ > ' I am foo indeed' > >>> > >IMO, to change it inside of a function def should be (but isn't) as easy >as... > > >>> def foo(): > ... """ I am foo """ > ... __doc__ = __doc__ + 'indeed' > >Paul Yes. Not only do I follow, but I think we came to exactly the same place, from very different directions, and coming from what I sense is very different backgrounds. Its just that I don't think many others seem to find that as interesting as I happen to. Hopefully, for good enough reasons. Art > > From dave at boost-consulting.com Tue Aug 24 11:00:56 2004 From: dave at boost-consulting.com (David Abrahams) Date: 24 Aug 2004 08:00:56 -0700 Subject: Unpythonic Python References: <8a638f47.0408240034.653a92ff@posting.google.com> Message-ID: <8a638f47.0408240700.13c39f57@posting.google.com> Thomas Heller wrote in message news:... > dave at boost-consulting.com (David Abrahams) writes: > > > I started having some weird problems with Python recently; they're so > > weird that I can't begin to explain them. All I can do is describe > > the symptoms and hope someone else has a clue. So here goes: > > > > FreeBSD 4.2, Python 2.2.2. > > > > I have a nightly cron job that downloads the boost cvs tarball from > > SourceForge and bunzip2s it. For about a year everything worked with > > no problems. About a month ago the download started getting truncated > > with no error reported. > > There were some problems with anonymous CVS on sourceforge, which also > affected the nightly CVS tarballs. Can it have to do with this? > I also had problems downloading the CVS tarball for ctypes - but it > seems now repaired. > > http://sourceforge.net/docman/display_doc.php?docid=2352&group_id=1#1093021394 That's not the problem. I can download the file reliably from other machines. > > Then bunzip2 reports corruption, of course. > Maybe you don't get a bz2 file, but a HTML error message instead? No, it's a truncated bz2. I can use bzip2recover and get some of the contents back. Thanks, though. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com From squirrel at WPI.EDU Tue Aug 3 15:30:19 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 3 Aug 2004 15:30:19 -0400 Subject: dislin interfaced with tkinter In-Reply-To: <1091561149.927180@news.commspeed.net> References: <34c9b4fa.0408030743.594417f9@posting.google.com> <1091561149.927180@news.commspeed.net> Message-ID: On Tue, 3 Aug 2004, Tom B. wrote: > I haven't worked with Dislin/Tkinter but I have worked with Dislin/wxPython > and what you can do is dump the Dislin output into a string buffer. > > [code] Building on that, the only change needed to use that with Tkinter would be to convert the Image object into a PhotoImage object using ImageTk.PhotoImage: self.Imagetest = ImageTk.PhotoImage(Image.open(StringIO.StringIO(char))) From anthonybaxter at gmail.com Thu Aug 5 21:49:38 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 6 Aug 2004 11:49:38 +1000 Subject: Proposed improved decorator syntax In-Reply-To: <1091753696.4112d6e06ea9e@webmail.oregonstate.edu> References: <1091753696.4112d6e06ea9e@webmail.oregonstate.edu> Message-ID: On Thu, 5 Aug 2004 17:54:56 -0700, barnesc at engr.orst.edu wrote: > We should really have a public vote. I doubt the @ sign will be approved > if 99% of Python users oppose it. In case it's not clear - Python is not a democracy. The utter shambles of the ternary operator horror shows very clearly why this is a good thing, as do the various languages that are designed by committee. On this particular subject, Guido wrote: "Python is not a democracy. I can't be swayed by votes, only by good arguments." Say no to language design by committee. From del at mjclift.freeserve.co.uk Fri Aug 13 01:28:18 2004 From: del at mjclift.freeserve.co.uk (Calvin79) Date: Fri, 13 Aug 2004 01:28:18 -0400 Subject: while and if References: Message-ID: Hi Satchit, Can I also ask how could I stop two of the same letters being given i.e. aa or dd and also how would I stop the same letter being repeated with only one space between i.e. a b a or c a c Thanks, Calvin From John.Marshall at ec.gc.ca Mon Aug 30 10:47:03 2004 From: John.Marshall at ec.gc.ca (John Marshall) Date: 30 Aug 2004 14:47:03 +0000 Subject: Call for signatories for J2 Message-ID: <1093877223.29131.11.camel@mango.cmc.ec.gc.ca> FOR Thanks, John From kyleroot at gmail.com Sat Aug 7 09:34:51 2004 From: kyleroot at gmail.com (Kyle Root) Date: Sat, 07 Aug 2004 13:34:51 GMT Subject: Questions about parsing XML Message-ID: <%T4Rc.150$Iv.46@trndny03> I'm writing a practice program that parses an xml config file, at the moment I'm using expat. However I don't like some of it's behaviors. For example ParseFile() will parse the *entire* file and I don't want to do that. I would like to be able to tell it to find such and such a tag and return the cdata it contains, is this at all possible? If it is how would I handle optional tags? If it's not possible and the entire file does have to be parsed in one fell swoop, are there any special ways collecting the data into a usable form? I tried to put everything into a list, but that's not very practicle, especially with optional tags. Thanks, Kyle From brett at python.org Tue Aug 10 14:08:45 2004 From: brett at python.org (Brett C.) Date: 10 Aug 2004 11:08:45 -0700 Subject: Popular Python projects with lots of pure Python code References: Message-ID: <8ab0589d.0408101008.6a1c7e9e@posting.google.com> "Robert Brewer" wrote in message news: > If you need just stats (without drilling down into code to interpret > those stats), you might package up your stat-generation code and hand it > out on c.l.p. That way, I and many others could run it against our > proprietary code and just give you results without exposing source code. > Might be a way to get a broader range of results--most of the "big > projects" in the wild are frameworks, not apps. > Hmm. That's possible. The only problem is that I have modified the 2.3.4 compiler so people would need to be willing to have a copy of 2.3.4 source, apply the patch, and then probably run py_compile on their Python code tree. But who knows, some people might be interested enough to bother. I can post the code once I think it is as bug-free as it is going to get before I start collecting stats. Thanks for the suggestion, Robert. -Brett From grv575 at hotmail.com Tue Aug 10 01:56:55 2004 From: grv575 at hotmail.com (grv575) Date: 9 Aug 2004 22:56:55 -0700 Subject: Importance of C# (was Re: IronPython-0.6 is now available!) References: <278de0e.0407281353.27b6a457@posting.google.com> <5dydnZSDZaARoZXcRVn-ug@powergate.ca> <1n5z28erh2m3u.dlg@baczek.net.invalid> <537ea4cd.0408070757.14790cfe@posting.google.com> <41155c78$0$4348$626a14ce@news.free.fr> Message-ID: <144d0df.0408092156.1455f2af@posting.google.com> Christophe Cavalaria wrote in message news:<41155c78$0$4348$626a14ce at news.free.fr>... > ziller wrote: > > >> After reading a tutorial on c#, I see immediately that it has all the > >> features that I disliked in Java. > >> > >> 1) Everything is derived from "Object" > > > > Pure OO is supposed to be an advantage. Otherwise casting hacks have > > to be used and understood. > > With real generics you don't need casting hack. Ok then how do you get all classes to have some universal behaviors (like getType() or whatever) otherwise? > >> 3) No multiple inheritance > > > > This has been covered to death. MI implementation is a nightmare. > > I'm sure some design pattern would map any 'needed' MI solution to an > > equivalent one using interfaces and SI. > > We have MI in Python and it works somewhat. And I'm sure SI isn't needed > anyway. There must be some design patter mapping SI in assembler or even on > a turing machine. If you want MI to specify that a class is both A and B...then which semantics (method implementation) should it use if A and B have different implementations of a certain method? Don't you really just want to specify the class is A and is B to the extent that it implements the interface of A and the interface of B? Really MI causes more issues and confusion than it solves. Also isn't C++ just syntactic sugar for assembler? > >> I'm not sure about 2 others: > >> > >> 4) No serious generic programming support > > > > It'll be there for 2.0. And the implementation is superb (much like > > Eiffel's generics) > > They aren't out yet and people are already complaining that they are too > limited. So far, despite an horrible syntax and horrible error messages the > C++ templates are still much more powerful than C# generics. And the best > thing is that the constraint system you can find on boost.org for C++ > templates is more powerful than the one you have in Eiffel either :D The jury is still out as well. http://discuss.fogcreek.com/joelonsoftware/default.asp?cmd=show&ixPost=144778 From newsgroups at jhrothjr.com Tue Aug 10 16:02:01 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Tue, 10 Aug 2004 16:02:01 -0400 Subject: Prothon is switching to the .NET platform References: <000401c47b59$32539220$0d01a8c0@MarkVaio> <10h7lb21dhbuc12@news.supernews.com> <10h7rittck6ct75@news.supernews.com> Message-ID: <10hiaed6dj22283@news.supernews.com> "Christopher T King" wrote in message news:Pine.LNX.4.44.0408101527020.9982-100000 at ccc2.wpi.edu... > On Fri, 6 Aug 2004, John Roth wrote: > > > The place where this gets really ugly is inserting functions > > into the instances. They have to be created at the module > > level, and then inserted into the instance by a module level > > function (somewhat similar to the way classmethod, > > staticmethod and property work). > > Oh, I wouldn't even attempt that until Python supported > "def object.method():" syntax (like Prothon does). It actually works quite nicely. Your suggested syntax would be a definite plus, but I'm not holding my breath until there are a number of people using some variety of prototype package in Python. It's a classic chicken and egg problem. Hans Nowak's package works quite well, although it uses self-style objects: they don't start out with any kind of inheritance, you have to plug in the objects you want as parents after creating the instance. On the other hand, it could simply be waiting on someone writing a PEP and giving some believable use cases for wanting to insert random methods into instances. > Using my derive class, > you could acheieve a similar effect though: > > class my_derived_class(derive): > def some_new_function(self): > > my_derived_object = my_derived_class(my_prototype_object) > > You aren't able to insert function definitions after the derived object is > created using this method (something I imag, but most function > definitions are premeditated anyways. I'm not familiar with your system, but there's no particular difficulty inserting methods into either a class or an instance. You just have to know the correct way to wrap it. To put it into an instance, you have to wrap it in new.instancemethod. John Roth > From jgrahn-nntq at algonet.se Wed Aug 4 09:13:18 2004 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: Wed, 4 Aug 2004 13:13:18 +0000 (UTC) Subject: Does python support multi prototype. References: <2natmnFv86rjU1@uni-berlin.de> Message-ID: On Wed, 04 Aug 2004 02:17:11 GMT, Chris Dutton wrote: > angel wrote: >> Hi >> >> Java and cpp support one function name multi function prototype. To be pedantic, C++ is called "C++", not "cpp", and what you seem to refer to is what C++ calls "overloaded function names" or "overloading". ... >> Does python support it? > > No, but it doesn't have to. The type of a function's arguments are not > statically limited. ... Yes, but that's not as elegant in cases where the arguments' types has to trigger very different processing. I can even imagine situations where foo(S) and a foo(T) do completely different things, and still 'foo' is the best name for both of them. I miss overloading in Python from time to time, but I can live without it. It is, after all, closely tied to a type system which is desirable in C++ and Java, but not in Python. /Jorgen -- // Jorgen Grahn Would You Let One Marry Your Sister?'' From fumanchu at amor.org Thu Aug 26 13:36:08 2004 From: fumanchu at amor.org (Robert Brewer) Date: Thu, 26 Aug 2004 10:36:08 -0700 Subject: mixing statements into J2 Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E85@exchange.hqamor.amorhq.net> > > > Can we insert conditional expressions in the > decorator list ? > > > > Not with the current patch; however, that option may be > allowed in the future. > > "In the future" means "post-2.4, when we have an idea of what people > are doing with it". Right now, there's not a whole lot of use cases > for more complex expressions in the decorator area, and there's more > potential for horror. Guido made this call on a gut feeling, not on > any technical grounds. His gut is usually good on this. > > > The order of operation would have to be reversed, > > I don't see why. It's not a requirement, but it seems reasonable to me. If you're going to set off a decorator suite and then mix in normal Python statements, the two models collide over order of operation: using: if test: memoize else: synchronize classmethod def foo(self, *args): stuff(args) The statements get evaluated top-to-bottom, but the decorators get applied bottom-to-top. It would be one more confusing issue in an already-confusing syntax. Not to mention that the current patch pushes decorators onto the stack at compile-time, and then pops them off after the function def. Mixing statements into the suite would move decorators from compile-time to runtime (at least, I don't see any way to avoid that without introducing a whole new layer of pragmas). If I felt it were possible, I would have recommended that application order in J2 be the opposite of A1. But I figured that would cause another two weeks of debate, which we don't have. I certainly see that "using:" provides a case for top-to-bottom, where "@decorator" implies the opposite. > > so *IF* Guido votes yes, > > then you need to bring this up again immediately. > > God no. Please don't. Work with the syntax that's chosen, then we can > revisit this for 2.5. Waiting until then guarantees the question won't be addressed, due to backward-compatibility issues which we will have then which we do not have now. Which I'm willing to concede to be a foregone conclusion at this point. Perhaps it would be enough just to say (to Guido), "this is still an open issue (one of many)"? Robert Brewer MIS Amor Ministries fumanchu at amor.org From aleaxit at yahoo.com Fri Aug 27 17:18:19 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 27 Aug 2004 23:18:19 +0200 Subject: Class Friends References: <20040827081556.657c3fac.a@c.d> <1gj72ft.z5skuq14uaiihN%aleaxit@yahoo.com> Message-ID: <1gj79ll.1a81rmf1wal7gtN%aleaxit@yahoo.com> Jeremy Bowers wrote: > On Fri, 27 Aug 2004 20:37:44 +0200, Alex Martelli wrote: > > > Anthony Baxter wrote: > > ... > >> I've considered a jihad to try and get uses of the double-under > >> mangling removed from the standard library. Maybe once 2.4 is out I'll > >> take this on. > > > > Count on my support on this: I consider it "something that looked like > > it would be a good idea at the time" (to me, too -- I'm not prescient > > either;-) but didn't really work as well as hoped. > > Well, I didn't want to come right out and say it for fear of starting a > flame war, but yeah, I was thinking this really loudly :-) > > (At least it is only for *double* underscores; mangling on singles would > have *really* sucked.) Yeah, it would. Mind you, accidental clashes with a base class's internals _do_ happen, and it IS a pity there's no easy and elegant way to avoid them, but it currently seems to me (after a few years' experience, and starting with a positive bias towards the idea) that mangling on double underscores, as Anthony says, has enough issues to make it not ideal for the purpose. So, we need to keep that mechanism in the language, for backwards compatibility (and perhaps as a sneaky way to claim we DO so have 'private'...!-)... but we sure don't need to use it ourselves if it gives us more problems than it solves. Just like the (more practically important) problem of sandboxing (ever since rexec and Bastion got deprecated), the problem of avoiding accidental clashes between ancestor and descendant classes, without paying a substantial price for it, may perhaps be currently classed as 'unsolved -- as yet'. Alex From cjw at sympatico.ca Thu Aug 12 20:25:50 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Thu, 12 Aug 2004 20:25:50 -0400 Subject: pretty print 2D arrays In-Reply-To: <10hn65v5eltr65d@corp.supernews.com> References: <10hn65v5eltr65d@corp.supernews.com> Message-ID: Alan G Isaac wrote: > I figure someone must have done this nicely but > I can't find it. I'd like structured printing of 2D > arrays, where an entry of None or '' should be > printed as whitespace. Something like: > > Inputs: 2D array, 1D array of fixed field widths, 1D array of format > suggestions > Effect: formatted print of the 2D array (or its transpose) > > Thanks, > Alan Isaac > You might consider numarray, but you would have to make your own provision for Null entries. Colin W. From pinard at iro.umontreal.ca Mon Aug 23 12:51:29 2004 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Mon, 23 Aug 2004 12:51:29 -0400 Subject: J2 proposal: keyword In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022E26@exchange.hqamor.amorhq.net> References: <3A81C87DC164034AA4E2DDFE11D258E3022E26@exchange.hqamor.amorhq.net> Message-ID: <20040823165129.GC8036@titan.progiciels-bpi.ca> [Robert Brewer] > III. Choosing a keyword > If a keyword is to be chosen over @ or other punctuation, the question > remains, "which word should it be?" [...] The keyword [...] should not > be a word with a planned future. This rules out "with" and "as" All the contrary, being a word with a planned future may be an advantage, as long as using that word makes enough sense in itself, and given the syntax we use have no chance of clashing with the planned syntax. This might rule out "as" because not meaningful enough, but "with" might be pertinent enough for being used -- yet I'm not fully sure. The word "using" is surely not bad either :-), but would be yet another keyword. -- Fran?ois Pinard http://www.iro.umontreal.ca/~pinard From tzot at sil-tec.gr Thu Aug 5 05:45:17 2004 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Thu, 05 Aug 2004 12:45:17 +0300 Subject: Subclassing file class References: Message-ID: <7d04h0dskqbdf2j1f8429726j766mnhrhj@4ax.com> On Wed, 4 Aug 2004 11:20:20 +0100, rumours say that "David Vaughan" might have written: >I'm using v2.3, and trying to write to text files, but with a maximum >line length. [snip] Apart from any other advices you get, you might want to consider the textwrap module. -- TZOTZIOY, I speak England very best, "Tssss!" --Brad Pitt as Achilles in unprecedented Ancient Greek From davidf at sjsoft.com Mon Aug 30 11:40:50 2004 From: davidf at sjsoft.com (David Fraser) Date: Mon, 30 Aug 2004 17:40:50 +0200 Subject: Installation of mod_python 3.1.3 on Apache 2.0.50 on Windows Me/Win2k In-Reply-To: <39cbe663.0408290850.14452ab9@posting.google.com> References: <39cbe663.0408290850.14452ab9@posting.google.com> Message-ID: Piet wrote: > Hi there, > I cannot install mod_python v3.1.3 on either Win2k/ActivePython 2.3.2 > or WinMe/Python 2.3.4. When I run the Windows installer, I get the > following error message: > Traceback (most recent call last): > File "C:\Programme\Python23\Scripts\win32_postinstall.py", line 86, in ? > apachediroptions = getApacheDirOptions() > File "C:\Programme\Python23\Scripts\win32_postinstall.py", line 45, in getApacheDirOptions > apachekey = regkey(win32con.HKEY_LOCAL_MACHINE, "Software").childkey("Apache Group").childkey("Apache") > File "C:\Programme\Python23\Scripts\win32_postinstall.py", line 34, in childkey > return regkey(self.key, subkeyname) > File "C:\Programme\Python23\Scripts\win32_postinstall.py", line 32, in __init__ > self.key = win32api.RegOpenKey(parent, subkeyname) > pywintypes.error: (2, 'RegOpenKeyEx', 'Das System kann die angegebene > Datei nicht finden.') > Exception exceptions.AttributeError: "regkey instance has no attribute > 'key'" in 0x00CF1440>> ignored > *** run_installscript: internal error 0xFFFFFFFF *** > I checked the registry and found that the key mentioned in the error > message does indeed not exist. Is this a failure in my apache > configuration/installation or is the installation package of > mod_python incorrect? Are there any experiences with the > abovementioned configuration? > Thanx in advance > Peter Hi This error was found when installing the original mod_python 3.1.3 for Windows installer on a non-Admin install of Python. You'll probably find that the registry does exist, but under HKEY_CURRENT_USER, not HKEY_LOCAL_MACHINE. In fact mod_python has actually been installed correctly, but the instructions about changing your apache configuration have not been given, and the mod_python library hasn't been copied into the Apache directory. These issues should all be fix in the latest win32 build of mod_python available from http://davidf.sjsoft.com/files/mod_python-3.1.3-1.win32-py2.3.exe Need to get Grisha to release this... I would recommend removing the Scripts/win32_postinstall.py file before running it... Hope that helps, if you have errors report them here or on the mod_python mailing list. David From mwh at python.net Fri Aug 6 11:40:53 2004 From: mwh at python.net (Michael Hudson) Date: Fri, 6 Aug 2004 15:40:53 GMT Subject: Queue qsize = unreliable? References: <1091805850.15192.12.camel@localhost> Message-ID: "Mike C. Fletcher" writes: > Tim, of course, would know better, but that's always been my interpretation. Can I please quote this out of context? :-) Cheers, mwh -- How do I keep people from reading my Perl code? Oh wait. Ha ha! -- from Twisted.Quotes From cpl.19.ghum at spamgourmet.com Sun Aug 1 17:41:04 2004 From: cpl.19.ghum at spamgourmet.com (Harald Massa) Date: Sun, 1 Aug 2004 21:41:04 +0000 (UTC) Subject: MySQLdb select References: Message-ID: Ruben, it is considered bad style wihtin c.l.p. to have aggressive emotions apart from mails about a "ternary operator" The correct way would have been: > > cursor.execute("SELECT * FROM mytest where clientID = %d" % numb) >> >> That's particularly BAD STYLE. It's best to keep to letting the >> DB-API do the proper quoting for all parameters. "Gerhard, why is this BAD STYLE? And how can I make the DB-API do the proper quoting for all parameters?" And probably the answer would have been: with doing "SELECT * FROM mytest where clientID = %d" % numb you are using the standard Python String-Formatting Functions. That may or may not lead to success. Especially when using a mixture of strings and numbers, they have to be quoted differently. Also special characters within strings have to be quoted - for example, the single ' has to be quoted within SQL because it is usually used as string delimiter cursor.execute("SELECT * FROM mytest where clientID = %d" , numb) The "," is the magic - with "Bla " % sth you are passing ONE argument --- the %s gets substituted, and one argument gets passed to the function. With "," two arguments get passed to the execute-"function" so that the DB-API has the challenge to integrate the parameters into the SQL-String. And it is more bad style to write "SELECT * FROM mytest where clientID = %d" % numb because % is defined with using a Tuple as second parameter, that would be "clientID = %d" % (numb,) Using % with sth. else than a tuple may succeed or give you very funny errors if numb happens to be a List in a later run. Best wishes, Harald From peter at engcorp.com Thu Aug 12 09:01:30 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 12 Aug 2004 09:01:30 -0400 Subject: Pyhton Interpreter Startup time In-Reply-To: References: Message-ID: Neil Benn wrote: > I'm looking at a small app which would need a very quick > startup time for the Python interpreter. It doesn't do much (copying > and caching of files, no GUI) but I need the Python interpreter to start > up very quickly (<1 second on a Windows box). What kind of machine do you have? On mine, Python starts up in about 0.06 seconds... This primitive test shows these results on a Windows XP machine (it won't work with Windows 98 as it can't chain commands on the command line like that, but you could but it in a batch file). c:\>echo. | time & python -c "import time; print time.time()" The current time is: 8:59:59.67 Enter the new time: 1092315599.73 This is a fairly fast machine (Athlon 2500+) but I really doubt slower machines would take much longer than 1 second unless they are *really* old. -Peter From ville at spammers.com Mon Aug 23 10:49:04 2004 From: ville at spammers.com (Ville Vainio) Date: 23 Aug 2004 17:49:04 +0300 Subject: python usage References: Message-ID: >>>>> "Phanish" == Phanish writes: Phanish> which inturns calls c++ client stubs. These stubs are Phanish> CORBA stubs which talk to a CORBA server residing some Phanish> where in the network. I want to know as to whether it is Phanish> feasible to use Python or just live with c++ for UI and Phanish> stubs? One thing you may not yet know is that Python absolutely rocks for CORBA - seeing how elegant CORBA can be is one of the reasons I decided to check out Python in the first place. OmniORB is the ORB I would check out first if I were you... Phanish> Is it good to use Python for this purpose? What is the Phanish> advantage? Well, you should just try implementing it in Python. Try something like PythonCard + OmniORB combo. If you can get it done in 2 days, you will know that you have a winner in your hands :-). Advantages: maintainability and, deriving from that, flexibility/modifiability. You are much more likely to even consider modifying an existing Py program than a C++ program. C++ programs are best left alone once they reach something resembling a functional stage. -- Ville Vainio http://tinyurl.com/2prnb From nzanella at cs.mun.ca Thu Aug 19 15:23:03 2004 From: nzanella at cs.mun.ca (Neil Zanella) Date: 19 Aug 2004 12:23:03 -0700 Subject: static class methods and data members References: Message-ID: Phil Frost wrote in message news:... > take a look at classmethod and staticmethod with pydoc, in the docs, or > help(). Static data members are done like so: > > Class C: > iAmStatic = 1 > def __init__(self): > self.iAmNotStatic = 2 > > Thinking of this in terms of "static" and "automatic" isn't the way to > go, really. That's C's way of doing it, and it's in Java only because > Java is nothing more than C. > > Here's how it works: There are classes, and there are instances of those > classes. Each has a namespace. when one does .name, "name" is > located first in the instance namespace, then in the class namespace. > > However, assignment is different. Assignment just looks in the instance > namespace, and if it's not there, it creates it. Thus if one were to do > "self.iAmStatic" in a method of C, that does not change the value of > iAmStatic for all instances of C. However, one can do "C.iAmStatic" > anywhere, and that will change "iAmStatic" for all instances of C that > do not have 'iAmStatic' bound to something at the instance level. > > The best way to understand this is through experimentation in the > interactive interpreter. To make things easier, you can peek inside > python's implementation by doing C.__dict__ or anInstanceOfC.__dict__ to > see the dictionary that represents that namespace. Phil, Your explanation is so clear, it should be included in just about any book on Python!!! Thank you so much!!! > After you have absorbed this, you will probably see the use of > classmethod, as it's not immediately apparent if you aren't familiar with > Python. Happy hacking! The http://www.python.org/2.2.1/descrintro.html#staticmethods you mentioned really does contain some of the information I was missing pertaining to classmethod and staticmethod. I wonder how come this file was not installed on my Fedora Core 2 Linux distro. I also notice that there is no corresponding file with the same name located at http://www.python.org/doc/2.3.4/. The document seems to have been removed from later Python documentation versions... how come? So, unlike Python classmethods which are roughly the equivalent of C++ static class methods, Python staticmethods really know nothing about the members of the class that encloses them and act pretty much like external defs. So what's the advantage of a staticmethod over an external def? The cls first argument to a Python classmethod is analogous to the self first argument to __init__: when you say Class.cmethod() the Class instance is passed as the first parameter to the class method, and when you say instance = Class(), the instance being constructed is passed to __init__ as self, and when you say instance.imethod(), the instance is passed to imethod() as the first parameter, self. The parameters cls and self are barely named so by convention: they are not keywords in Python, unlike say the this pointer which is a keyword in C++. While qualification within a class is optional in languages like C++ and Java, in Python you must always qualify instance variables with self within instance methods, and always qualify class variables with cls within Python class methods. Since python static methods know nothing about a class, they are equivalent to methods defined outside a class, except they may be called with the class as the first argument (for no good reason). Feedback, reclarification, or other, on the above comments greatly appreciated. Thanks, Neil #!/usr/bin/python class Foo: x = 0 y = 1 def foo(cls): print "classmethod: hello" print cls.x foo = classmethod(foo) def bar(): print "staticmethod: hello" print Foo.x bar = staticmethod(bar) if __name__ == "__main__": Foo.foo() Foo.bar() From jkn at nicorp.f9.co.uk Thu Aug 12 11:28:20 2004 From: jkn at nicorp.f9.co.uk (Jon Nicoll) Date: 12 Aug 2004 08:28:20 -0700 Subject: compiling extension DLLs for ActiveState 2.3 (xstruct.pyd) Message-ID: <8351bb33.0408120728.23028ddb@posting.google.com> Hi all anyone know what compiler and version I should use to compile an extension module for ActiveState Python 2.3? quite a few years ago I used a useful Python extension module called xstruct in a program suite. It does a similar job to what ctypes does nowadays, AFAICT. The extension is a C file compiled to a .DLL for windows. It's been a few years, and I'd like to re-use the program. In the meantime I've migrated python versions - I'm currently on ActiveState Python 2.3. I'm assuming (admittedly without trying it ;-/) that the .PYD won't work in this environment, and the author hasn't updated the distribution in the meantime. alternatively, has anyone already got xstruct already compiled for this platform? Thanks a lot Jon N From bitshadow at yahoo.com Mon Aug 9 23:42:31 2004 From: bitshadow at yahoo.com (Michael Scarlett) Date: 9 Aug 2004 20:42:31 -0700 Subject: Popular Python projects with lots of pure Python code References: Message-ID: Troels Therkelsen wrote in message news:... > In article , Brett C. wrote: > >[/snipped] > > > > Any suggestions? yeah, why don't you go to sourcforge and search under python projects, you'll get a ton From timr at probo.com Fri Aug 20 00:30:52 2004 From: timr at probo.com (Tim Roberts) Date: Thu, 19 Aug 2004 21:30:52 -0700 Subject: html templates References: Message-ID: <23vai09725mmg69tg3ji8d0dpi1mgd7fak@4ax.com> Ajay wrote: > >i am looking for a framework to create a fast dynamic website. between >using Cheetah and HTMLTemplate which would you recommend? This is such a personal decision. It really depends on what appears to you. I like Cheetah's templating language a lot. I use Webware as my web app server, but I use Cheetah for doing the templates instead of the Webware PSP. For a small dynamic site, however, I could learn to like CherryPy as well. You compile the whole web site along with a simple web server into a single script. >also quixote offers a session management API? how secure is this session >management? is it just a cookie on the client side? "Just" a cookie? How would you do session management more securely? -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From webraviteja at yahoo.com Thu Aug 26 03:33:19 2004 From: webraviteja at yahoo.com (Ravi Teja Bhupatiraju) Date: 26 Aug 2004 00:33:19 -0700 Subject: Proposal for removing self References: Message-ID: "Brent W. Hughes" wrote in message news:... > When doing object-oriented stuff, it bothers me to have to type "self" so > many times. I propose that Python allow the programmer to optionally type > ".variable" instead of "self.variable" to mean the same thing. Of course, > the interpreter would have to be more careful about detecting floats that > begin with just a period as in ".5". What are your thoughts? I know that this has been proposed before and am familiar with the alternatives commonly suggested. I understand that most Python programmers are happy with things the way they are in this respect. But after 3 years of Python, somehow, I still keep forgetting to type the darn thing. Of course, I always catch the omission quickly but that makes me wish there was a better alternative. Python has generally been about less typing and self seems somewhat contrary to that. This following is not a carefully thought one but I would be interested to know what your opinions are. The following is inspired by win32all. class HelloWorld: _public_methods_ = ['Hello'] _public_attrs_ = ['softspace', 'noCalls'] _readonly_attrs_ = ['noCalls'] def __init__(self): pass How about having an optional attribute for a class that negates the requirement for self? One advantage with this is I can see all the member variables in one place. Great while reading code. class FooBar: __public__ = [Name, Age] def setName(name): Name = name While I am complaining, a few other peeves ... Another thing is I dislike is having to use __ for *every* private variable. For *me* __private__ at the top of the class definition code would be more elegant. __readonly__ would be another nicety. Introducing the above attributes into the language would not likely break any existing Python code. Just my 2c. From artur_spruce at yahoo.com Tue Aug 10 06:28:41 2004 From: artur_spruce at yahoo.com (AdSR) Date: 10 Aug 2004 03:28:41 -0700 Subject: Importance of C# (was Re: IronPython-0.6 is now available!) References: <278de0e.0407281353.27b6a457@posting.google.com> <5dydnZSDZaARoZXcRVn-ug@powergate.ca> <9418be08.0407292114.129c856f@posting.google.com> Message-ID: artur_spruce at yahoo.com (AdSR) wrote in message news:... > Peter Hansen wrote in message news:... > > > > Language comparison is a hard thing: what happens when you > > pick a test case that can be handled much more easily in > > one language than in another? Do you pick a new test case, > > or write inefficient code that no programmer experienced in that > > language would actually write? I'm not sure of the answer... > > Well, for me the most interesting test would be to actually use all > features available in each of the compared languages. So, if the > standard distribution of a given language includes a library to do a > task, use that library. If there is a syntax feature that makes things > easier, use that too. And so on... > > I think this is far more useful in real life than just plain > interpreter/compiled code speed comparison. > >From another thread, with minor correction: An interesting comparison, if you want to check it for yourself, is one between the unittest module and what is described on this page: http://www.gigamonkeys.com/book/practical-building-a-unit-test-framework.html Both approaches are based on commonly used features and coding style of their respective languages. I think this is good example of how language vs. language comparisons should be done. AdSR From ptmcg at austin.rr._bogus_.com Sun Aug 29 00:23:45 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Sun, 29 Aug 2004 04:23:45 GMT Subject: If the string module is deprecated... Message-ID: ... what will become of the module-level constants, such as uppercase, digits, hexdigits, etc.? Will they become class-level constants of the str class? -- Paul From gumuz at NO_looze_SPAM.net Tue Aug 17 12:00:34 2004 From: gumuz at NO_looze_SPAM.net (Guyon Morée) Date: Tue, 17 Aug 2004 18:00:34 +0200 Subject: firefox extension Message-ID: <41230bcc$0$3897$4d4ebb8e@news.nl.uu.net> is it possible to create a firefox extension in python? From beliavsky at 127.0.0.1 Tue Aug 10 12:24:57 2004 From: beliavsky at 127.0.0.1 (beliavsky@aol.com) Date: 10 Aug 2004 11:24:57 -0500 Subject: pro python paper References: <305aa162.0408091905.5bce8f9a@posting.google.com> Message-ID: <4118f6d9_1@127.0.0.1> Heiko Wundram wrote: >You won't call C++ or Fortran 95 high-level languages, will you? ;) For me, >the border between low-level programming and high-level programming lies >where memory management becomes automatic. It depends on the area. The Python LANGUAGE does not have multdimensional arrays with slices and intrinsic functions, but Fortran 90/95 does and can be considered a higher-level language for numerical work. Of course, the Numeric and Numarray Python modules do provide this functionality. There is a question of whether one should include common libraries when comparing the functionality of various languages. Allocatable arrays in Fortran 95 are automatically deallocated when they go out of scope, so memory management is mostly automatic. ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =--- From h.b.furuseth at usit.uio.no Sat Aug 7 15:32:24 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 07 Aug 2004 21:32:24 +0200 Subject: PEP 263 spec (was: Proposal: require 7-bit source str's) References: <4112AC7B.1060508@v.loewis.de> <411343D7.3020604@v.loewis.de> <411353A3.8090502@v.loewis.de> <4113759E.2070405@v.loewis.de> <4113E755.8060205@v.loewis.de> <41140349.6090202@v.loewis.de> Message-ID: Martin v. L?wis wrote: >Hallvard B Furuseth wrote: > >> - For a number of source encodings (like utf-8:-) it should be easy >> to parse and charset-convert in the same step, and only convert >> selected parts of the source to Unicode. > > Correct. However, that it works "for a number of source encodings" > is insufficient - if it doesn't work for all of them, it only > unreasonably complicates the code. For UTF-8 source, the complication might simply be to not call a charset conversion routine. For some other character sets - well, fixing the problem below would probably introduce that complication anyway. > For some source encodings (namely the CJK ones), conversion to UTF-8 > is absolutely necessary even for proper lexical analysis, as the > byte that represents a backslash in ASCII might be the first byte > of a two-byte sequence. No. It's necessary to convert the source file to logical characters and feed those to the parser in some way, and conversion to UTF-8 in a simple way to do that. I think the 'right way', as far as source character set handling is concerned, would be to have the source reader and the language parser cooperate: The reader translates the source file to logical source characters which it feeds to the parser (UTF-8 is fine for that), and the parser notifies the reader when it sees the start and end of a source character string which should be given to the parser in its original form (by some other means than feeding it to the parser as if it was charset-converted source code, of course). Now, that might conflict with Python's design goals, if it is supposed to be possible to keep the reading and parsing steps separate. Or it might just take more effort to rearrange the code than anyone is interested in doing. But in either case it still looks like a bug to me, even if it's at best a low-priority one. >> - I think the spec is buggy anyway. Converting to Unicode and back >> can change the string representation. But I'll file a separate >> bug report for that. > > That is by design. The only effect of such a bug report will be that > the documentation clearly clarifies that. OK, I'll make it a doc bug. -- Hallvard From Andreas.Ames at tenovis.com Mon Aug 23 13:15:11 2004 From: Andreas.Ames at tenovis.com (Ames Andreas (MPA/DF)) Date: Mon, 23 Aug 2004 19:15:11 +0200 Subject: [Q] Bug in cgi.FieldStorage? Message-ID: <788E231C269961418F38D3E360D1652526CA30@tndefr-ws00021.tenovis.corp.lan> Hello, Tim Roberts wrote: >>if fs: >> ... > > What question do you intuitively expect that statement to be asking? class Request: def __init__(self, fs = None) if fs: self._fs = fs else: self._fs = FieldStorage(...) def retry(self): return self.__class__(self._fs) Something like that. I cannot say why, but I find it somewhat odd that if fs: can throw a TypeError. OTOH, that might be my C heritage: char *ptr = 0; ... if (ptr) { ... } FWIW, there are some more things I don't like about cgi.FieldStorage: 1) Tryig sometimes to be a list and a file at other times is a bit confusing for me as a user. 2) Doing the whole parsing from within the constructor isn't very nice, for example for derivations. 3) Calling the constructor directly from read_multipart prevents me from specifying custom constructor arguments. I'd prefer an overwriteable factory method. cheers, andreas From pit.grinja at gmx.de Sun Aug 29 12:50:40 2004 From: pit.grinja at gmx.de (Piet) Date: 29 Aug 2004 09:50:40 -0700 Subject: Installation of mod_python 3.1.3 on Apache 2.0.50 on Windows Me/Win2k Message-ID: <39cbe663.0408290850.14452ab9@posting.google.com> Hi there, I cannot install mod_python v3.1.3 on either Win2k/ActivePython 2.3.2 or WinMe/Python 2.3.4. When I run the Windows installer, I get the following error message: Traceback (most recent call last): File "C:\Programme\Python23\Scripts\win32_postinstall.py", line 86, in ? apachediroptions = getApacheDirOptions() File "C:\Programme\Python23\Scripts\win32_postinstall.py", line 45, in getApacheDirOptions apachekey = regkey(win32con.HKEY_LOCAL_MACHINE, "Software").childkey("Apache Group").childkey("Apache") File "C:\Programme\Python23\Scripts\win32_postinstall.py", line 34, in childkey return regkey(self.key, subkeyname) File "C:\Programme\Python23\Scripts\win32_postinstall.py", line 32, in __init__ self.key = win32api.RegOpenKey(parent, subkeyname) pywintypes.error: (2, 'RegOpenKeyEx', 'Das System kann die angegebene Datei nicht finden.') Exception exceptions.AttributeError: "regkey instance has no attribute 'key'" in > ignored *** run_installscript: internal error 0xFFFFFFFF *** I checked the registry and found that the key mentioned in the error message does indeed not exist. Is this a failure in my apache configuration/installation or is the installation package of mod_python incorrect? Are there any experiences with the abovementioned configuration? Thanx in advance Peter From mwh at python.net Mon Aug 23 10:49:41 2004 From: mwh at python.net (Michael Hudson) Date: Mon, 23 Aug 2004 14:49:41 GMT Subject: __name__ becoming read-write? References: Message-ID: Arthur writes: > Did I hallucinate something about __name__ becoming read-write? For functions? No, you didn't hallucinate that. > Not in alpha2. Indeed. The changes were only checked in a couple of weeks ago. They'll be in alpha3. > Can't find the reference to this I thought I read - that it was > concluded to be necessary in connection with PEP318. It's something that's been nagging at me for ages, but it was a PEP 318-related comment that finally prodded me into writing the patch. > Better get my facts straight first.... Glad to be of service ! Cheers, mwh -- I've reinvented the idea of variables and types as in a programming language, something I do on every project. -- Greg Ward, September 1998 From daniel at dittmar.net Tue Aug 3 14:31:26 2004 From: daniel at dittmar.net (Daniel Dittmar) Date: Tue, 03 Aug 2004 20:31:26 +0200 Subject: PyQT tutorial In-Reply-To: <410f8d35$0$31408$636a15ce@news.free.fr> References: <410f8d35$0$31408$636a15ce@news.free.fr> Message-ID: Olivier Thiery wrote: > Do you know any good and fairly complete tutorial about PyQT, Eric and > QtDesigner ? A book about Python programming qith Qt is available online at http://www.opendocspublishing.com/pyqt/ Daniel From pm_mon at yahoo.com Sat Aug 21 17:04:03 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sat, 21 Aug 2004 17:04:03 -0400 Subject: __metaclass__ and __author__ are already decorators In-Reply-To: <2opp6gFdg3e7U1@uni-berlin.de> References: <2opgsoFd7807U1@uni-berlin.de> <2opp6gFdg3e7U1@uni-berlin.de> Message-ID: Leif K-Brooks wrote: > Paul Morrow wrote: > >> We just need to stop thinking of them as local function variables. >> Instead we should think of __xxx__ attributes as describing the >> function itself (i.e. as a decorator would), as I believe that is >> almost always the author's intention when he/she uses such names >> inside of a function/method definition. He wants to say something >> about the function (who wrote it, it's version, etc.), and is probably >> sad that it has the side-effect of creating a local variable. So it >> probably shouldn't have that side-effect anymore. It should create a >> function attribute instead (not to be confused with a local variable). > > > Which is, like I said, assigning new meaning to an old syntax. That > seems confusing to me; why not just create a new syntax? Because it's not needed and would make the language more complex. And I don't agree that this would be assigning new 'meaning' to an old syntax. When a programmer creates a __xxx__ class attribute, he is not trying to create a normal 'class' attribute --- one the is inherited by instances of the class or that holds part of the 'state' of the class. Instead, he is trying to make a meta statement about the class (who wrote it, what happens during instance initialization, etc.). In that sense, the meaning associated with defining __xxx__ attributes would stay the same. From anthonybaxter at gmail.com Mon Aug 23 02:17:16 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Mon, 23 Aug 2004 16:17:16 +1000 Subject: J2 decorator grammar In-Reply-To: References: <2orckjFdtljaU1@uni-berlin.de> Message-ID: On Mon, 23 Aug 2004 06:07:21 GMT, Paul McGuire wrote: > I'm liking "per" or "using". A couple of issues with 'per': It's a bit _too_ cute. In addition, people who don't have English as a native language might find it tricky. It is too confusable with 'pre'. 'using' works ok for me. From pwmiller1 at adelphia.net Tue Aug 17 17:03:42 2004 From: pwmiller1 at adelphia.net (Paul Miller) Date: 17 Aug 2004 14:03:42 -0700 Subject: Is it possible to write a DLL using python References: Message-ID: <2e363c08.0408171234.5ceaf1c7@posting.google.com> AMD wrote in message news:... > I need to write a Win32 DLL and I would like to use Python instead of > VB, C++ or Delphi. Is this possible? No. It is possible to interface to and from Python via other languages, but since Python does not create native code, you cannot create a DLL with it. From peter at engcorp.com Fri Aug 20 06:36:05 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 20 Aug 2004 06:36:05 -0400 Subject: Rita Sue and Bob too In-Reply-To: References: Message-ID: <4125D415.7040403@engcorp.com> Ben Last wrote: >>From Peter Hansen >> >>>But, how to I find a sequence in a list of unknown size? i.e. >>>this sequence in list of other names and replace it with three others? >>> >>>'Rita','Sue','Bob' >>> >>>This is almost a nightly occurrence (my posting questions), but I am >>>learning : ) Actually, that wasn't quite me who wrote those words... I merely quoted them from the OP. (Ben, I don't think you need to post to both the python-list _and_ the comp.lang.python newsgroup: they mirror each other already!) -Peter From skip at pobox.com Mon Aug 30 11:35:14 2004 From: skip at pobox.com (Skip Montanaro) Date: Mon, 30 Aug 2004 10:35:14 -0500 Subject: Problems running coverage.py In-Reply-To: References: Message-ID: <16691.18738.73177.820009@montanaro.dyndns.org> Vijay> For a particular script which uses 'exit' calls, I am getting the Vijay> following error when I invoke the script with the -x option for Vijay> coverage. Vijay> Error in sys.exitfunc: Vijay> Traceback (most recent call last): Vijay> File "D:\Python23\lib\atexit.py", line 20, in _run_exitfuncs Vijay> func(*targs, **kargs) Vijay> File "D:\Python23\Lib\site-packages\coverage.py", line 207, in save Vijay> cache = open(self.cache, 'wb') Vijay> TypeError: an integer is required Vijay> Looks like coverage.py is not able to record the coverage data on Vijay> calling exit. Does anybody know how to solve this? Just a wild-ass guess, but I suspect there's a module imported like from somemodule import * which dumped an "open" symbol into the global namespace, thus hiding the open() builtin. You might try adding this line print open right before the call to open() to see if you're getting the builtin open or not. -- Skip Montanaro Got spam? http://www.spambayes.org/ skip at pobox.com From walter at livinglogic.de Wed Aug 11 06:09:01 2004 From: walter at livinglogic.de (=?ISO-8859-1?Q?Walter_D=F6rwald?=) Date: Wed, 11 Aug 2004 12:09:01 +0200 Subject: Parsing broken HTML via Mozilla In-Reply-To: References: Message-ID: <4119F03D.9050605@livinglogic.de> Paul Wright wrote: > In article , Walter > D?rwald wrote: > >>I'm trying to parse broken HTML with several Python tools. >>Unfortunately none of them work 100% reliable. Problems are e.g. >>nested comments, bare "&" in URLs and "<" in text (e.g. "if foo < >>bar") etc. > > Not a Mozilla solution, but I hear good things about > http://www.crummy.com/software/BeautifulSoup/ I already tried that, but it completely ignores encoding issues and it passes broken entity references (e.g. bare & in URLs) along literally. Furthermore its support for DTD aware HTML parsing is not complete (e.g. is not handled as an empty tag). Bye, Walter D?rwald From roy at panix.com Wed Aug 4 12:27:12 2004 From: roy at panix.com (Roy Smith) Date: Wed, 04 Aug 2004 12:27:12 -0400 Subject: How to force a single number to be a tuple References: Message-ID: In article , "Jinming Xu" wrote: > Hi Folks, > > I have a number sequence, which is put into a tuple like this: > > y=2, 3.0, 4.5 > > I can manipulate the sequence as a tuple when it has more than 1 number. But > when the sequence has only 1 number, like > > y=2 > > I have trouble to manipulate it as a tuple. I guess there must be a way to > forece a single number to be a tuple. Could anyone please tell me that? You're going to get a zillion responses to this one. The syntax is a bit funky: y = (2,) From follower at gmail.com Mon Aug 2 15:04:41 2004 From: follower at gmail.com (Follower) Date: 2 Aug 2004 12:04:41 -0700 Subject: ANN: libgmail 0.0.7 - Gmail access via Python - Now with FTP Proxy! Message-ID: libgmail -- Python binding for Google's Gmail service The `libgmail` project is a pure Python binding to provide access to Google's Gmail web-mail service. The library currently ships with a demonstration utility to archive messages from a Gmail account into mbox files, suitable for importing into a local email client. Also includes a demonstration utility that acts as a SMTP proxy to allow mail to be sent from any standard mail client that uses SMTP (e.g. Mail.app, Mozilla etc). (Now handles attachments.) New demonstration utility to provide access to Gmail message attachments via a download-only FTP proxy--this allows retrieval of suitably marked attachments by a standard FTP client. Utilize more of your Gmail space! License: GPL 2.0 (gmailftpd.py is dual licensed with PSF) Major changes since 0.0.6: * Demo FTP proxy enables marked Gmail message attachments to be download via FTP. * Implemented sending & receiving of message attachments. * Updated SMTP Proxy demo to handle sending attachments. * Added 'getMessagesByQuery' function. Major changes since 0.0.5: (Repeated from last announcement) * Implemented SMTP proxy to enable Gmail to be send with a standard mail client via (E)SMTP. * Extended standard SMTP class to handle ESMTP EHLO & AUTH PLAIN commands. * Utility function '_retrieveJavascript' to retrieve current version of Gmail Javascript file. (By request.)

    libgmail 0.0.7 - The `libgmail` project is a pure Python binding to provide access to Google's Gmail web-mail service; includes SMTP & FTP proxies. (03-Aug-04)

    From rogerb at rogerbinns.com Mon Aug 23 18:59:21 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Mon, 23 Aug 2004 15:59:21 -0700 Subject: Py2Exe and Threading References: <81a41dd.0408231216.6f919ff4@posting.google.com> Message-ID: <3i9qv1-mh7.ln1@home.rogerbinns.com> Lad wrote: > Does anyone use Py2exe for a script that uses threading modul. > In have a main thread and another in which I use smtplib to send email > while the main thread is running. > Under Python it works well but after compilation into exe it hangs( > freezes) in the thread where I send email with smtplib. Tell py2exe it is a console application and see if that makes a difference. When you tell py2exe that it is a windowed (ie non- console) app, then the stdout you get is actually a 4k buffer that throws various exceptions when it fills. Roger From john.thingstad at chello.no Fri Aug 27 08:30:25 2004 From: john.thingstad at chello.no (John Thingstad) Date: Fri, 27 Aug 2004 14:30:25 +0200 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: I think I just hit the 'wall'. rlol On 25 Aug 2004 14:56:06 -0700, Xah Lee wrote: > Larry Wall and Cults > (Lazyness, Impatience and Hubris) > 200012 > > Dear readers, > > Did you know that throughout history there's this thing called cult? > It is a very interesting phenomenon. I don't have time to expound and > teach, but will try to brief you. > > These cults, are often lead by a single person. They form a group as > small as a dozen to multinational octopuses (such as > Scientology). Their creed varies from the mild in appearance > (Dianetics) to appalling (flat earth, extraordinary life-after-death, > impinging apocalypse scenarios, militant anti-government conspiracy, > diabolism with human sacrifices ...). Don't think that i'm citing from > some arcane books buried in libraries. These are real, and not > difficult to find in real life. Some of these cult leaders, are so > able to totally wash their member's brain, as to have them > autonomously swear and volunteer to die for the cause of the cult. > Occasionally, you'll even see mass suicide. > > You know, the world is not made completely of rubes. Somebody > somewhere, will observe this phenomenon and study or report it as > is. Big brother organizations, such as the FBI, is keen on these and > very interested in benefiting from social psychology themselves. They > are recorded in books too. Ever wonder why the library houses so many > cold volumes of paper? This is one contributing reason. You might be > interested to verify that sometimes. > > These brain-washing phenomenon, are not limited to fanatical > life-and-death or otherwise dire beliefs. You see it work in all > manners of human thought in the general sense. From culture formation > to fashion to commercialism. Surely you have heard of Adolf Hitler > and his atrocities of genocide? I must alert you, that a single person > couldn't commit such a crime. You see, even if you are superman, you > can only kill few at a time. You see, it is the people, people like > you and me, who commit the killings willingly, by Hitler's > teaching. You may say: "no, i won't ever do such stupid thing", well > because you are very ignorant about social psychology. It is precisely > innocent people like you and (not) me, who were lead by the radical > leaders of supreme brain-washing abilities. The innocent mob were > fervent in their leader's vision and beliefs to commit anything. You > know the concept of war, right? We have two massive body of people > committed to cut off other people's head or otherwise stick a knife in > their bodies or bomb off an arm or leg. How did that happen? Well, it > starts with patriotism for people like you and (not) me. > > Now, back to topic. In the computing world, there're also bad seeds > with colorful creed taking innocent mobs forming cults. The three > principal virtues of a programmer are Laziness, Impatience, and > Hubris. Yes? > > How can we prevent heinous cults then? Stop bending truths. Education > and rationalism. I'm starting my own cult to exterminate morons on > this earth. Two things are on the top of my agenda: Unixism and Perl. > > -------- > This post is archived at > http://xahlee.org/UnixResource_dir/writ/larry_wall_n_cults.html > > Copyright 2000-2004 Xah Lee. Verbatim Reproduction for non-commercial > purposes is hereby granted provided proper credit is given. > > Xah > xah at xahlee.org > http://xahlee.org/PageTwo_dir/more.html -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ From nobody at nowhere.com Wed Aug 25 05:18:22 2004 From: nobody at nowhere.com (Fred) Date: Wed, 25 Aug 2004 11:18:22 +0200 Subject: Building basic dialog in Windows? References: <3tGdnSTFgOnIArbcRVn-pQ@comcast.com> Message-ID: On Tue, 24 Aug 2004 15:04:38 -0500, "Larry Bates" wrote: (snip) Thx Larry :-) Fred. From bokr at oz.net Fri Aug 6 20:13:50 2004 From: bokr at oz.net (Bengt Richter) Date: 7 Aug 2004 00:13:50 GMT Subject: elements of decorator syntax suggestions References: Message-ID: On Sat, 7 Aug 2004 04:02:36 +1000, Anthony Baxter wrote: >This is an excellent list! Thanks for doing it. I've made a couple of notes >inline about the particular points. +1 on the info format of the post > >On 6 Aug 2004 10:19:21 -0700, Steven Bethard wrote: >> I think one of the biggest reasons we're having such problems coming >> to any agreement on decorator syntax is that each proposal makes a >> number of syntax decisions, not just one. For decorators, I see the >> following decisions that must be made: >> >> 1) Indicator >> Proposals differ on how some sort of indicator of "decoratorhood" is >> use. These include: >> * none (e.g. just the list, as in the "list-after-def" suggestion) >> * the '@' character >> * a new keyword (with, using, decorate, etc.) > what about a builtin name? or does that count as a keyword? >This is the biggy, it seems. Current (as of a couple of hours ago) >discussions on python-dev are discussing other alternatives instead >of @, that will hopefully make it easier for IPython or Leo to cope >for now (but note that in the future, some other use for @ might be >found, so anyone relying on it at the moment might want to think >about that). One current suggestion is to use the | character, instead. > >> 2) Location >> Proposals also differ on exactly where the decorator declaration >> should be made. These include: >> * before def > >Short of someone producing a _very_ strong argument in favour of >another form, this is almost certainly going to be the choice. > >> * between def and function name > >Breaks too many tools, as well as stupid humans who are used to seeing >def functionname. > >> * between function name and argument list > >I'm not sure that this was ever popular, with anyone ;) > >> * between argument list and colon > >Guido's ruled this out (see previous posts, I put a link to his post >outlining why. > >> * after colon (first line in body) > >A problem here is interaction with docstrings? > > >> 3) List notation >> As I understand it, it's already decided that any implementation of >> decorators must allow for a list of decorators to be applied. So >> proposals that might be accepted must explain how this can be done. >> The options I've seen: >> * one per line (as currently) > >There's some confusion as to how the one-per-line thing is ordered. I find >it quite obvious, but I've been playing with this for a week now, so it might >just be that I know the answer now. Simply - > >@decA >@decB >@decC >def func(): > >is equivalent to > >func = decA(decB(decC(func))) > Looks to me like the semantics is __magic_internal_list.append(decA) __magic_internal_list.append(decB) __magic_internal_list.append(decC) def func(): pass while _magic_internal_list: func = __magic_internal_list.pop()(func) why not go with a little sugar like __builtins__.decorate = __magic_internal_list.append and then decorate(decA) decorate(decB) decorate(decC) def func(): pass # (automatic trigger of the while statement above, after the def) Of course, I think more interesting things can be done along with that bare minimum, but even this minimal implementation at least avoids such a narrow commitment for '@'. BTW, even if __magic_internal_list were per-thread, wouldn't one need guidelines at least for writing wrappers safely? What does current @decorator do? > >An excellent list! If you don't mind, I might steal this format for the PEP. >It allows for a lot more alternatives to be covered off in a smaller space >(since many proposals are minor variations on an existing proposal, and >share the same problems). +1 on that ;-) Regards, Bengt Richter From noone at here.com Wed Aug 18 22:45:47 2004 From: noone at here.com (M. Clift) Date: Thu, 19 Aug 2004 03:45:47 +0100 Subject: get last two in a length of unknown length? Message-ID: Hi All, I have a list of varying length. Would someone know the way to get the last two values for this? I can see how this is done with a list that I know the length of, but not one thats generated by user input. Thanks for any help From squirrel at WPI.EDU Thu Aug 5 13:54:32 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 5 Aug 2004 13:54:32 -0400 Subject: RELEASED Python 2.4, alpha 2 In-Reply-To: References: <411231C8.3020308@interlink.com.au> Message-ID: On Thu, 5 Aug 2004, David Eppstein wrote: > If this is an actual possibility, there's nothing preventing you from > wrapping a decorated def inside a try-except block. And then being forced to duplicate the function definition. The way around this is, of course, to decorate manually, but then your decorators are segmented (some at the top of the function, some at the bottom). From gandalf at geochemsource.com Tue Aug 31 09:23:13 2004 From: gandalf at geochemsource.com (Gandalf) Date: Tue, 31 Aug 2004 15:23:13 +0200 Subject: has_method In-Reply-To: References: Message-ID: <41347BC1.5020407@geochemsource.com> >#- Does anyone knows how to tell if an object has a method with a given >#- name? How can I access that method? > > > >>>>class C: >>>> >>>> > def mymeth(self): > return > > > > >>>>c = C() >>>>dir(c) >>>> >>>> >['__doc__', '__module__', 'mymeth'] > > >>>>c.mymeth >>>> >>>> >> > > You are right - I only used dir() interactively. I have the answer, how to check. But how can I access that method? I would like to call it by name. :-) Best, Laci 2.0 -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim.peters at gmail.com Tue Aug 10 19:05:45 2004 From: tim.peters at gmail.com (Tim Peters) Date: Tue, 10 Aug 2004 19:05:45 -0400 Subject: measuring 1/100th seconds, what function? In-Reply-To: References: Message-ID: <1f7befae0408101605657688a0@mail.gmail.com> [Jonas K?lker] > I'm doing a Rubik's Cube timer, so I need a function to measure > 100ths of a second. ... Assuming you want to compute wall-time deltas (as opposed to CPU-time deltas), about the best you can do x-platform is if sys.platform == "win32": from time import clock as now else: from time import time as now Then use now(). Unsure which branch Cygwin should take. It's up to you to determine whether it works "well enough" on each platform you care about. Note that on a box connected to a network time-correction service, time.time can appear to "run backwards" briefly at unpredictable times. The same kind of thing can happen on multi-CPU boxes -- or not, depending on piles of platform details. From elbertlev at hotmail.com Fri Aug 13 13:40:27 2004 From: elbertlev at hotmail.com (Elbert Lev) Date: 13 Aug 2004 10:40:27 -0700 Subject: Pyhton Interpreter Startup time References: Message-ID: <9418be08.0408130940.181a01ea@posting.google.com> Neil Benn wrote in message news:... > Hello, > > I'm looking at a small app which would need a very quick > startup time for the Python interpreter... On Windows you would be better of running your application as a service. In this case you do not care about startup time. It can automatically look for files you need or could have gui interface (f.e. tray icon with menu). From listserver at tdw.net Fri Aug 27 06:39:53 2004 From: listserver at tdw.net (Tim Williams) Date: Fri, 27 Aug 2004 11:39:53 +0100 Subject: DNS.DiscoverNameServer query References: Message-ID: <003301c48c22$2fed15e0$506b81c2@twilliams> (Relative Newbie) How can I see which nameservers a DNS.DiscoverNameServera() finds? I have googled TIA From mark_bottjer at hotmail.com Wed Aug 11 21:01:50 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Wed, 11 Aug 2004 21:01:50 -0400 Subject: PEP-0318 In-Reply-To: References: <41122FC2.1080608@interlink.com.au><4114152f@nntp.zianet.com> <4116bc20$1@nntp.zianet.com><6NCdncg4ssq28orcRVn-uQ@powergate.ca> <411a5cee$1@nntp.zianet.com> <411a9a7f$1@nntp.zianet.com> Message-ID: <411ac17f@nntp.zianet.com> Fredrik Lundh wrote: > Mark Bottjer wrote: >> Fredrik Lundh wrote: >>>calling a function with an argument? that's a pretty common >>>operation, if you're asking me >> >>Indeed it is. And that fact bears on this conversion how? > > that's what a decorator does, of course. No it isn't. A decorator queues a function to be called, on something not yet defined, after that something gets defined. "Calling a function" is what we do now; decorators as they stand do something very different, even if it has the same net effect. > what part of your own post did you not understand? *sigh* -- Mark From ronaldoussoren at mac.com Wed Aug 25 13:52:31 2004 From: ronaldoussoren at mac.com (Ronald Oussoren) Date: Wed, 25 Aug 2004 19:52:31 +0200 Subject: PEP318: radical notion In-Reply-To: References: <412a4222$0$293$626a14ce@news.free.fr> Message-ID: <89A8AD66-F6BF-11D8-8765-000A95C77748@mac.com> On 25-aug-04, at 0:13, Arien Malec wrote: > > Is there a valid use case that supports arbitrary magical non-metadata > transformations of standalone functions? Barray Warsaw has mentioned several times on py-dev that he has actually used several of the propesed syntaxes to rewrite existing code that uses decorators (IIRC mailman). Ronald From jjl at pobox.com Thu Aug 12 16:12:35 2004 From: jjl at pobox.com (John J. Lee) Date: 12 Aug 2004 21:12:35 +0100 Subject: ClientCookie References: <6f402501.0408110018.1e4e5ca8@posting.google.com> <6f402501.0408120352.680496bc@posting.google.com> Message-ID: <87ekmcp13g.fsf@pobox.com> fuzzyman at gmail.com (Michael Foord) writes: [...] > Ok, I've got somewhere. > I'm now using the 0.9 version and I found the debugging section in the > docs. > > I'm using the example from the docs - but I'm pickling a list of the > pickles rather than using the load and save methods (as the docs > suggest) because I get an NotImplemented error for the save method (so > what use is the load method ?). I suppose you're trying to use FileCookieJar. That's an abstract base class. In other words, you're not supposed to use it directly. You're supposed to use one of its subclasses, such as LWPCookieJar, MSIECookieJar or MozillaCookieJar. The standard meaning of NotImplementedError is not "oops, I haven't got round to that", but rather "don't do that; use a subclass instead". MSIECookieJar can't save cookies because the format used by Windows isn't documented (there is an API function, but I don't use it). [...] > and I'm now seeing persistent cookies..... hurrah....... > Can I save each cookie as a line of text ? Would that work with the > load method ? Yes. Use LWPCookieJar. > Anyway - now I need to learn about server side cookies so that I can > give each user an 'id' Have a look at some of the Python web frameworks. > and also write code to clean up unused cookie > files... [...] Either - simply always have one file per user, and persist it by whatever means you like (LWPCookieJar, pickling, outfile.write('\n'.join([repr(c) for c in cookiejar])), whatever...) or - write a CookieJar that hides its implementation in terms of multiple files (and implements .clear_expired_cookies(), etc.). Probably not a good idea. John From artur_spruce at yahoo.com Fri Aug 20 08:57:28 2004 From: artur_spruce at yahoo.com (AdSR) Date: 20 Aug 2004 05:57:28 -0700 Subject: Alternative decorator syntax decision References: Message-ID: "Paul McGuire" wrote in message news:... > BTW, where are all the votes for option "A"? Where are all the people who > hated it but now like it? I, for one, changed my mind from none to C1 to A1 over time. Here's my vote: A1 C1 C3(*) (*) My version of C3 uses the 'as' keyword, plus there's no comma in case of a single decorator. AdSR From scott.b.drummonds.nospam at intel.com Wed Aug 11 16:22:19 2004 From: scott.b.drummonds.nospam at intel.com (Scott Brady Drummonds) Date: Wed, 11 Aug 2004 13:22:19 -0700 Subject: 'break' Causes Execution of Procedure? References: Message-ID: "Peter Hansen" wrote in message news:t8udndgpWe6rwIfcRVn-rw at powergate.ca... > Scrambled .pyc file? Try deleting all .pyc files in the folder > and rerun. (Just a thought.) Yeah, I tried that before, as well. No such luck. Scott From ptmcg at austin.rr._bogus_.com Sat Aug 21 22:53:09 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Sun, 22 Aug 2004 02:53:09 GMT Subject: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WE DONE? Message-ID: Well, after 3 days of open polling, the number of additional votes have dropped off pretty dramatically. Here are the results so far: Total voters: 55 (with 3 votes each) Votes for each choice or group of choices: Any J 81 J2 78 Any C 40 C1 29 Any D 9 C2 8 D2 6 F 6 L 5 Any E 5 A1 4 H 4 K 4 Any A 4 B 3 D1 3 E1 3 C3 2 I 2 J1 2 C4 1 E2 1 E4 1 J3 1 M 1 A2 0 E3 0 G 0 J4 0 This would put J2 and C1 as the clear favorites among those who voted, with J2 between 2:1 and 3:1 more strongly favored. Of all of the votes cast, J2 received 48%, C1 received 18%. No other option received more than 10% of any votes. However, the multivote format gives us some additional information, over conventional "one-person-one-vote" format. Of the 55 voters, 75% cast at least one vote for J2, while only 35% cast one or more votes for C1. From the standpoint of building concensus, I find this statistic more compelling than the raw vote count. It tells me that 3/4 of the voting sample are at least open to the option presented by J2, so that developing community acceptance is more likely to happen more quickly with J2 than with C1. I believe that Anthony Baxter's read of Guido's intentions on what happens next are fairly accurate (Anthony has been very active on python-dev and in private e-mails on this subject, and I'm sure his view is more than most of us here on c.l.py) - I think Guido has challenged us to rally around *one* alternative to the current @ syntax, and from this poll, I think J2 is our collective best bet. I do *not* think that Guido plans to have a run-off between the chosen alternative and the @ syntax, nor that he would give much credence to one if it were held - remember what the D in BDFL stands for. But I think he *will* be pleased that among the babel of syntax proposals that have been put forward, this fairly unstructured and unorganized group will have come to closure and met his challenge, and settled on *one* alternative option. I believe that Robert Brewer's technical discussion and Michael Sparks' implementation will at least cause him to seriously consider our concensus choice as a viable alternative to the @ syntax. I'm sure that there are many asking if 55 is a sufficient sample for determining the wishes of the Python community. I have no response other than to say that this poll was posted on an open Usenet forum, and that it quickly gathered a breadth of responses (despite the fact that many people are just tired of talking and reading about decorators), and that the response rate noe looks to be dropping off. I am skeptical that additional time will significantly change the results. And I'm not sure what other measures to take to obtain further responses. If there are other forums for eliciting these inputs, I would have hoped that those who follow c.l.py would have already contacted them for their participation. So I would like to propose that we collectively move forward with J2 as our selected alternative. I would say that those who proposed other alternatives are not "the losers" in this, that they put valued thought and discussion into this overall topic. In fact, the J2 proposal evolved over the past several months, and I believe this is in part due to the influence of concepts put forth in other proposals. I believe that both C1 and J2 are clear, Pythonic, and pleasing to the eye, but in the interests of moving forward, we need to focus our efforts in a single direction from here on. If we continue to promote our other various favorites, I think it's fairly certain that we will all be typing @ characters after release 2.4 comes out. Please start giving some thought to what the 'decorate' keyword should be. If we can get/keep this selection to a manageable list, then we should have another multivote some time next week. -- Paul From bncarper at cs.com Tue Aug 24 06:50:29 2004 From: bncarper at cs.com (Bob C) Date: 24 Aug 2004 03:50:29 -0700 Subject: Setting up Tix Message-ID: <726ee98e.0408240250.6cd06aa2@posting.google.com> I get the following message when tryin to setup Tix on Linux rh7.3: >>> import Tix >>> root = Tix.Tk() Traceback (most recent call last): File "", line 1, in ? File "/usr/local/lib/python2.3/lib-tk/Tix.py", line 210, in __init__ self.tk.eval('package require Tix') _tkinter.TclError: couldn't load file "/usr/lib/libtix": /usr/lib/libtix.so: cannot open shared object file: No such file or directory >>> I have libtix8.1.8.4.a and libtix8.1.8.4.so in /usr/local/lib. I guess I'm not sure how to set the varibles to correctly point at the /usr/local directory. Bob From clarkcase at gmail.com Wed Aug 4 14:13:40 2004 From: clarkcase at gmail.com (Clark Case) Date: 4 Aug 2004 11:13:40 -0700 Subject: Downsampling question - figured it out... Message-ID: Please ignore my previous question about pipes and downsampling MP3s in Windows. The answer was that I needed to use popen2 instead of popen so I could specify that the pipe was binary instead of text. Clark From M.Waack at gmx.de Thu Aug 26 11:44:20 2004 From: M.Waack at gmx.de (Mathias Waack) Date: Thu, 26 Aug 2004 17:44:20 +0200 Subject: authentication service for unix References: Message-ID: Diez B. Roggisch wrote: >> Using PAM is definitively not the reason why your process must be >> run as root. What exactly are you doing? > > Well, I started fiddling around with pam, and found that when > running it as user the only one I could authenticate was the user > the process ran with. Ok, my fault - you're right. If you are going to authenticate a local user you usually need read access to /etc/shadow. The easiest way to work around is using an existing tool like login or su. They do the PAM stuff for you. Mathias From apardon at forel.vub.ac.be Fri Aug 27 09:08:02 2004 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 27 Aug 2004 13:08:02 GMT Subject: Why return None? References: <412c6edb$0$258$edfadb0f@dread12.news.tele.dk> <1gj4fb5.607xsc51izh8N%aleaxit@yahoo.com> <7xllg25lkt.fsf@ruckus.brouhaha.com> <1gj4u3a.12ttba9fynd6uN%aleaxit@yahoo.com> <1gj5bp4.qhup8tldmvebN%aleaxit@yahoo.com> <1gj6cfv.nv3fziwoc81nN%aleaxit@yahoo.com> Message-ID: Op 2004-08-27, Alex Martelli schreef : > Antoon Pardon wrote: > ... >> > Yes you can, and in the general case get very different effects, e.g.: >> >> And what about >> >> a += b vs a.extend(b) > > I can go on repeating "in the general case [these constructs] get very > different effects" just as long as you can keep proposing, as if they > might be equivalent, constructs that just aren't so in the general case. > > Do I really need to point out that a.extend(b) doesn't work for tuples > and strings, while a+=b works as polymorphically as feasible on all > these types? That extend doesn't work for strings and tupples is irrelevant. for those types that have an extend a.extend(b) is equivallent to a+=b In other words there is no reason to have an extend member for lists. furthermore a+=b doesn't work polymorphically feasable because the result of a=c a+=b is different depending on the type of c. > It should be pretty obvious, I think. So, if you want to > get an AttributeError exception when 'a' is a tuple or str, a.extend(b) > is clearly the way to go -- if you want para-polymorphic behavior in > those cases, a+=b. Isn't it obvious, too? No it isn't obvious. No design is so stupid that you can't find an example for it's use. That you have found a specific use here doesn't say anything. >> >>>> c=a=range(3) >> >>>> b=range(2) >> >>>> a+=b >> >>>> c >> > [0, 1, 2, 0, 1] >> > >> > versus: >> > >> >>>> c=a=range(3) >> >>>> b=range(2) >> >>>> a=a+b >> >>>> c >> > [0, 1, 2] >> >> I wouldn't say you get different effects in *general*. You get the >> same effect if you use numbers or tuples or any other immutable >> object. > > a+=b is defined to be: identical to a=a+b for immutable objects being > bound to name 'a'; but not necessarily so for mutable objects -- mutable > types get a chance to define __iadd__ and gain efficiency through > in-place mutation for a+=b, while the semantics of a=a+b strictly forbid > in-place mutation. *IN GENERAL*, the effects of a+=b and a=a+b may > differ, though in specific cases ('a' being immutable, or of a mutable > type which strangely chooses to define __add__ but not __iadd__) they > may be identical. which makes them para-polymorphic infeasable. > Like for a+b vs b+a: in general they may differ, but > they won't differ if the types involved just happen to have commutative > addition, of if a and b are equal or identical objects, i.e., in various > special cases. > > "You get different effects *in general*" does not rule out that there > may be special cases (immutable types for one issue, If those specific cases can be half of the total cases I wouldn't call the not specific cases *in general*. > commutative-addition types for another, etc, etc) in which the effects > do not differ. Indeed, if it was "always" true that you got different > effects, it would be superfluous to add that "in general" qualifier. > Therefore, I find your assertion that you "wouldn't say you get > different effects in *general*" based on finding special cases in which > the effects do not differ to be absurd and unsupportable. > > >> > But let's be sensible: if 'it' is joining two strings which are bound to >> > names b and c, b+c is the only OBVIOUS way to do it. Building a >> > sequence whose items are b and c and calling ''.join on it is clearly an >> > indirect and roundabout -- therefore NOT "the one obvious way"! -- to >> > achieve a result. Proof: it's so unobvious, unusual, rarely used if >> > ever, that you typed entirely wrong code for the purpose... >> >> That is just tradition. Suppose the "+" operator wouldn't have worked >> on strings an concatenating would from the start been done by joining, >> then that would have been the one obvious way to do it. > > In a hypothetical language without any + operator, but with both unary > and binary - operators, the one "obvious" way to add two numbers a and b > might indeed be to code: a - (-b). So what? In a language WITH a > normal binary + operator, 'a - (-b)' is nothing like 'an obvious way'. The point is that there is a difference between what is obvious in general and what is obvious within a certain tradition. If python would limit itself to only one obvious way for those things that are obvious in general that would be one way. But here you are defending one thing that is only obvious through tradition, by pointing out that something that hasn't had the time to become a tradition isn't obvious. Personly I don't find the use of "+" as a concat operator obvious. There are types for which both addition and concatenation can be a usefull operator. Using the same symbol for both will make it just that much harder to implement such types and as a result there is no obvious interface for such types. >> > We can't always get even that, as a+b vs >> > b+a show when a and b are bound to numbers, but we can sure get closer >> > to it by respecting most of GvR's design decisions than by offering >> > unfounded, hasty and badly reasoning critiques of them. >> >> I think that this goal of GvR is a bad one. > > I'm sure you're a better language designer than GvR, since you're > qualified to critique, not just a specific design decision, but one of > the pillars on which he based many of the design decisions that together > made Python. > Therefore, I earnestly urge you to stop wasting your time critiquing an > inferiorly-designed language and go off and design your own, which will > no doubt be immensely superior. Good bye; don't slam the door on the > way out, please. > >> If someway of doing it >> is usefull then I think it should be included and the fact that >> it introduces more than one obvious way to do some things shouldn't >> count for much. > > This is exactly Perl's philosophy, of course. No it isn't. Perl offers you choice in a number of situations where a number of the alternatives don't offer you anything usefull. unless a way to do things differently and eliminate a few characters. >> Sure you shouldn't go the perl-way where things seemed to have >> been introduced just for the sake of having more than obvious way >> to do things. But eliminating possibilities (method chaining) >> just because you don't like them and because they would create >> more than one obvious way to do things, seems just as bad to >> me. > > If a language should not eliminate possibilities because its designer > does not like those possibilities, indeed if it's BAD for a language > designer to omit from his language the possibilities he dislikes, what > else should a language designer do then, except include every > possibility that somebody somewhere MIGHT like? So if you think it is good for a language designer to omit what he dislikes. Do you think it is equally good for a language designer to add just because he likes it. And if you think so, do you think the earlier versions of perl, where we can think the language was still mainly driven by what Larry Wall liked, was a good language. I can understand that a designer has to make choices, but if the designer can allow a choice and has no other arguments to limit that choice than that he doesn't like one alternative then that is IMO a bad design decision. >> What I have herad about the decorators is that one of the >> arguments in favor of decorators is, that you have to >> give the name of the function only once, where tradionally >> you have to repeat the function name and this can introduce >> errors. >> >> But the same argument goes for allowing method chaining. >> Without method chaining you have to repeat the name of >> the object which can introduce errors. > > I've heard that argument in favour of augmented assignment operators > such as += -- and there it makes sense, since the item you're operating > on has unbounded complexity... mydict[foo].bar[23].zepp += 1 may indeed > be better than repeating that horrid LHS (although "Demeter's Law" > suggests that such multi-dotted usage is a bad idea in itself, one > doesn't always structure code with proper assignment of responsibilities > to objects and so forth...). > > For a plain name, particularly one which is just a local variable and > therefore you can choose to be as simple as you wish, the argument makes > no sense to me. If I need to call several operations on an object I'm > quite likely to give that object a 'temporary alias' in a local name > anyway, of course: > target = mydict[foo].bar[23].zepp > target.pop(xu1) > target.sort() > target.pop(xu3) > target.reverse() > target.pop(xu7) I find this a questionable practice. What if you need to make the list empty at some time. The most obvious way to do so after a number of such statements would be: target = [] But of course that won't work. >> >> The difference between >> >> >> >> print somelist.sort() >> >> >> >> and >> >> >> >> somelist.sort() >> >> print somelist >> >> >> >> >> >> is IMO of the same order as the difference between >> >> >> >> >> >> print a + b >> >> >> >> and >> >> >> >> r = a + b >> >> print r >> > >> > For a sufficiently gross-grained comparison, sure. And so? In the >> > second case, if you're not interested in having the value of a+b kept >> > around for any subsequent use, then the first approach is the one >> > obvious way; >> >> No it isn't because programs evolve. So you may think you don't >> need the result later on, but that may change, so writing it >> the second way, will making changes easier later on. > > Ridiculous. Keep around a+b, which for all we know here might be a > million-items list!, by having a name bound to it, without ANY current > need for that object, because some FUTURE version of your program may > have different specs?! > If specs change, refactoring the program written in the sensible way, > the way that doesn't keep memory occupied to no good purpose, won't be > any harder than refactoring the program that wastes megabytes by always > keeping all intermediate results around "just in case". One could argue that this is again just an deficiency of pythons implementation, that can't optimise the code in such a way so that unused variables will have there memory released. >> > if you ARE, the second, because you've bound a name to it >> > (which you might have avoided) so you can reuse it (if you have no >> > interest in such reuse, it's not obvious why you've bound any name...). >> > >> > In the first case, fortunately the first approach is illegal, the second >> > one is just fine. Were they exactly equivalent in effect neither would >> > be the one obvious way for all reasonable observer -- some would hate >> > the side effect in the first case, some would hate the idea of having >> > two statements where one might suffice in the second case. >> >> So? I sometimes get the idea that people here can't cope with >> differences in how people code. So any effort must be made >> to force people to code in one specific way. > > When more than one person cooperates in writing a program, the group > will work much better if there is no "code ownership" -- the lack of > individualized, quirky style variations helps a lot. It's not imposible > to 'cope with differences' in coding style within a team, but it's just > one more roadblock erected to no good purpose. A language can help the > team reach reasonably uniform coding style (by trying to avoid offering > gratuitous variation which serves no real purpose), or it can hinder the > team in that same goal (by showering gratuitous variation on them). If a language goes so far as to make a particular coding impossible while that would have been the prefered coding style for most of the project members then such a limitation can hinder the decision to agree upon a certain style instead of helping. I also think this attitude is appalling. Python is for consenting adults I hear. But that doesn't seem to apply here, as python seems to want to enforce a certain coding style instead of letting consenting adults work it out among themselves. >> > Fortunately the first approach does NOT do the same thing as the second >> > (it prints out None:-) so Python sticks to its design principles. Let >> > me offer a private libation to whatever deities protect programmers, >> > that Python was designed by GvR rather than by people able to propose >> > analogies such as this last one without following through on all of >> > their implications and seeing why this SHOWS Python is consistent in >> > applying its own design principles! >> >> That these implications are important is just an implication on the >> design principles. If someone doesn't think particular design principles >> are that important, he doesn't care that if somethings is changed that >> particulat design principle will be violated. Personnaly I'm not >> that impressed with the design of python, it is a very usefull language > > Great, so, I repeat: go away and design your language, one that WILL > impress you with its design. Here, you're just waiting your precious > time and energy, as well of course as ours. That you waste yours, is entirly your choice, nobody forces your hand to reply to me. >> but having operators like '+=' which have a different kind of result >> depending on whether you have a mutable or immutable object is IMO >> not such a good design and I wonder what design principle inspired >> them. > > Practicality beats purity: needing to polymorphically concatenate two > sequences of any kind, without caring if one gets modified or not, is a > reasonably frequent need and is quite well satisfied by += for example. It isn't. Either you know what types the variables are and then using a different operator depending on the type is no big deal, or you don't know what type the variables are and then not caring if one gets modified or not, is a disaster in waiting. -- Antoon Pardon From michele.simionato at gmail.com Sun Aug 8 09:31:31 2004 From: michele.simionato at gmail.com (Michele Simionato) Date: 8 Aug 2004 06:31:31 -0700 Subject: decorators and multimethods References: <4edc17eb.0408062340.71ab270f@posting.google.com> <4edc17eb.0408070742.664fa9c0@posting.google.com> Message-ID: <4edc17eb.0408080531.6f8963f9@posting.google.com> Ronald Oussoren wrote in message news:... > decorators are called before the function is added to > a namespace You are right. I did some experiment with def dec(f): print globals() return f and it is clear that @dec def f(): pass is NOT the same as def f(): pass f=dec(f) Using the @decorator, f is not in the globals at the decorator call time. In the version of the PEP I have read (that my have changed) complete equivalence was claimed, so I assumed (wrongly) this was the cause of the error I saw. Instead the error came from the second call to the decorator, not from the first one. Michele From h.b.furuseth at usit.uio.no Tue Aug 31 18:30:27 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 01 Sep 2004 00:30:27 +0200 Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Paul Morrow wrote: >Paul Morrow wrote: >> But why speculate. Let's see if this is really going to be unclear in >> practice. Ask someone who has never seen Python before which are the >> local variables in the following def. >> >> def circumference(diameter): >> """Calculate the diameter of a circle.""" >> __author__ = 'Paul Morrow' >> __version__ = '0.1' >> pi = 3.14 >> return pi * diameter > > And while you're at it, ask them which lines get executed at function > definition time, and which get executed when the function is called. Of course that's obvious with your simple example, since it clearly doesn't even use those variables and you can even tell from the function name what the function ought to do. What is not obvious is how it works. OK, I asked my neighbor: She suggested some kind of default variables. She noticed that the variables were not being used; if the function had been longer she would apparently have needed to read through the entire function to be sure. I think my guess would have been something like C's static variables. The assigment would be initialization, but of a variable in the same namespace. Which seems similar to her guess, even though we thought of it very differently. -- Hallvard From olivier.boudevilleNOSPAM at online.fr Fri Aug 6 12:35:04 2004 From: olivier.boudevilleNOSPAM at online.fr (Olivier Boudeville) Date: Fri, 06 Aug 2004 18:35:04 +0200 Subject: Default list parameter issue Message-ID: Hi all, it must be a very stupid question but I cannot find out the explanation for my code's behaviour, so any help would really be appreciated. My purpose was, simply put, to have a tree-like data structure, thanks to the following (simplified to track the issue) Node class : class Node: def __init__( self, newContent = None ) : """Creates an empty node with no child node.""" self.content = newContent self.children = [] def __repr__( self ): """Returns a textual representation of this node's state.""" res = "Node has " if self.content: res += "content (%s)" % ( self.content, ) else: res += "no content" res += " and it has " if self.children: res += "%s child(ren) : <%s>" % ( len( self.children ),self.children ) else: res += "no child." return res def addChild( self, aChild ): """Adds a child to current node.""" self.children.append( aChild ) I test the class simply thanks to : a=Node() b=Node() print a print b a.addChild( b ) print a print b and it returns, as expected : >>> a=Node() >>> b=Node() >>> a Node has no content and it has no child. >>> b Node has no content and it has no child. >>> a.addChild( b ) >>> a Node has no content and it has 1 child(ren) : <[Node has no content and it has no child.]> >>> b Node has no content and it has no child. That is ok. But if I swap the previous __init__ method with my first version : def __init__( self, newContent = None, newChildren = [] ) : """Creates an empty node with no child node.""" self.content = newContent self.children = newChildren and I apply the same test, I got (output not edited) : >>> a=Node() >>> b=Node() >>> a Node has no content and it has no child. >>> b Node has no content and it has no child. >>> a.addChild( b) >>> a Node has no content and it has 1 child(ren) : <[Node has no content and it has 1 child(ren) : <[...]>]> >>> b Node has no content and it has 1 child(ren) : <[Node has no content and it has 1 child(ren) : <[...]>]> >>> I do not understand why using an empty list as default parameter results in such a different behaviour. Thanks in advance for any hint, kind regards, Olivier. PS : tested with python 2.2.1 and 2.3.3. The test should be relevant since : > diff ok.py ko.py 2,4c2,4 < < < def __init__( self, newContent = None ) : --- > > > def __init__( self, newContent = None, newChildren = [] ) : 7c7 < self.children = [] --- > self.children = newChildren Olivier. From juliagoolia at eml.cc Fri Aug 6 13:42:51 2004 From: juliagoolia at eml.cc (julia) Date: 6 Aug 2004 10:42:51 -0700 Subject: py2exe and pyOpenGL Message-ID: Hi, I'm having trouble turning a python program with pyOpenGL into an exe with py2exe. I was wondering if you could help. Basically I have a setup.py like this: # setup.py from distutils.core import setup import py2exe setup(console=["gltest.py"]) # end setup.py (Note that my program gltest.py works just fine) And when I do: python setup.py py2exe --excludes=OpenGL There is an error message that says: The following modules appear to be missing ['OpenGL.GL', 'OpenGL.GLUT', 'dotblas', etc.... But I figured this was OK because of the excludes. So then I put the OpenGL dir into the dist directory and when I try to run the exe I get an ImportError: No module named OpenGL.GL Any idea where I'm going wrong? Thanks so much for your time, Julia From claireguilbaud at yahoo.fr Thu Aug 26 08:48:02 2004 From: claireguilbaud at yahoo.fr (Claire) Date: 26 Aug 2004 05:48:02 -0700 Subject: vars() and dir() Message-ID: hi, i use vars() or dir() to get variables. I use them in a def block, so i get variables of that block. How can i get variables from the namespace __main__ ? I use python in interactive mode and want to have a function to get a dictionnary for python types (int, ...) and another for my types (my classes). this function will be in my pythonstartup file. If i use python in interactive mode, is there a main module defined ? i don't know how to use namespace __main__ to get information on this "global namespace" like i can do with math or another module Thanks Claire From me at privacy.net Wed Aug 25 06:58:53 2004 From: me at privacy.net (Dan Sommers) Date: 25 Aug 2004 06:58:53 -0400 Subject: Why return None? References: Message-ID: On Wed, 25 Aug 2004 10:27:51 GMT, Martin DeMello wrote: > Anthony Baxter wrote: >> On Wed, 25 Aug 2004 08:26:26 GMT, Martin DeMello >> wrote: >> > It seems to be a fairly common pattern for an object-modifying method to >> > return None - however, this is often quite inconvenient. >> >> list.reverse() modifies the list in place. The python idiom is that >> these don't return a reference to the modified list. Although note the > Yes, but why? I mean, is there either an advantage to returning None or > some inherent danger in returning self? If list.sort returned the sorted list, how many lists would there be after this code executed? original_list = a_function_that_returns_a_list( ) sorted_list = original_list.sort( ) HTH, Dan -- Dan Sommers Never play leapfrog with a unicorn. From max at alcyone.com Sun Aug 29 01:58:58 2004 From: max at alcyone.com (Erik Max Francis) Date: Sat, 28 Aug 2004 22:58:58 -0700 Subject: Announcing PyCs, a new Python-like language on .Net References: Message-ID: <413170A2.1F1D1212@alcyone.com> Mark Hahn wrote: > This is an announcement of the beginning of development of a new > Python-like language called PyCs (pronounced "pie-cees"). Like > IronPython, > PyCs will be Python on .Net but it will have more advanced features > and > probably have higher performance due to a Psyco-like implementation > technique. See http://pycs.org. Here we go again ... -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ It's soulful music. It doesn't necessarily sound like ... soul ... -- Sade Adu From fakeaddress at nowhere.org Mon Aug 9 02:48:04 2004 From: fakeaddress at nowhere.org (Bryan Olson) Date: Mon, 09 Aug 2004 06:48:04 GMT Subject: Paul Graham on Python hackers In-Reply-To: References: <3064b51d.0408061127.32536826@posting.google.com> Message-ID: Paul Foley wrote: > Baalbek wrote: >>I prefer Java and Python alike, I simply love those two languages..... > >>So, am I smart, or not as smart? > > The question is a fair indicator that you're "not as smart" [...] Though he compares well, overall, to people who answer rhetorical questions. -- --Bryan From john at grulic.org.ar Mon Aug 23 09:13:54 2004 From: john at grulic.org.ar (John Lenton) Date: Mon, 23 Aug 2004 10:13:54 -0300 Subject: comment utiliser python sous Fedora In-Reply-To: References: <8e16829.0408230412.cf13db4@posting.google.com> Message-ID: <20040823131354.GB32042@grulic.org.ar> On Mon, Aug 23, 2004 at 02:59:44PM +0200, Eric Brunel wrote: > > Tout d'abord, il existe un newsgroup Python en fran?ais > (fr.comp.lang.python) sur lequel il est pr?f?rable de poser les questions > en fran?ais, le newsgroup comp.lang.python ?tant traditionnellement > anglophone. > > Quant ? tes questions, je ne suis pas sur de les comprendre: Python est-il > install? sur ta machine? Il n'y a pas de documentation sur "l'usage de > python sous Fedora", simplement parce qu'il n'y a rien de sp?cifique sous > cette plateforme: PAQJS, elle s'utilise comme n'importe quel Linux. Les > seules instructions n?cessaires se trouvent dans le fichier README dans le > r?pertoire racine de l'installation Python. that isn't exactly true: the RHN applet, at least, is written in python :) -- John Lenton (john at grulic.org.ar) -- Random fortune: Just when you thought you were winning the rat race, along comes a faster rat!! -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From Sibylle.Koczian at Bibliothek.Uni-Augsburg.de Fri Aug 6 06:24:03 2004 From: Sibylle.Koczian at Bibliothek.Uni-Augsburg.de (Sibylle Koczian) Date: Fri, 06 Aug 2004 12:24:03 +0200 Subject: MySQLdb select In-Reply-To: References: <9RPOc.2792$LI7.1058@newssvr27.news.prodigy.com> <21064255.0408020908.41357e52@posting.google.com> <2n9gmuFuhk8kU1@uni-berlin.de> <2nbn3pFv4865U1@uni-berlin.de> <2nembjF2dr7U1@uni-berlin.de> Message-ID: <2nh4i8Fpn24U1@uni-berlin.de> Andy Todd schrieb: > It's a bug. I think it is a bug in MySQL. I'm using 4.0.18 on Debian and > an interactive session shows the problem; > > """ > andy47 at vetinari:~$ mysql [snip] > Database changed > mysql> select count(*) from stock_prices where price_date = '2004-07-30'; > +----------+ > | count(*) | > +----------+ > | 7 | > +----------+ > 1 row in set (0.00 sec) > > mysql> select count(*) from stock_prices where price_date = '2004-07-30 > 00:00:00'; > +----------+ > | count(*) | > +----------+ > | 7 | > +----------+ > 1 row in set (0.00 sec) > """ > > When using '=' the two forms of date are identical, but if we switch to > using 'in'; > > """ > mysql> select count(*) from stock_prices where price_date in > ('2004-07-30'); > +----------+ > | count(*) | > +----------+ > | 7 | > +----------+ > 1 row in set (0.00 sec) > > mysql> select count(*) from stock_prices where price_date in > ('2004-07-30 00:00:00'); > +----------+ > | count(*) | > +----------+ > | 0 | > +----------+ > 1 row in set (0.00 sec) > > mysql> > """ > > Ta-da. Of course, this may have already been notified to MySQL AB, I'd > check their web site (http://www.mysql.com) or try one of their mailing > lists. > Will do. Thank you. I never thought of trying this directly in MySQL, always took it for a problem between MySQL and Python. I'll check the MySQL newsgroup first, as it's in German. Koczian From robey at slash_dev_slash_random.org Wed Aug 18 17:53:02 2004 From: robey at slash_dev_slash_random.org (Robey Holderith) Date: Wed, 18 Aug 2004 16:53:02 -0500 Subject: Embedding Python in Python References: Message-ID: I've found the crack in the armor. See additions below. -Robey On Wed, 18 Aug 2004 16:48:26 -0500, Robey Holderith wrote: > > > Where test2.py looked like this: > > > #---------Begin Code > > print __builtins__ > > try: > del __builtins__ > print 'del worked' > except: > pass > > try: > exec('del __builtins__') > print('exec del worked') > except: > pass > > try: > import sys > print 'Import Worked' > except: > pass > > try: > f = file('out.tmp','w') > f.write('asdfasdf') > f.close() > print 'File Access Worked' > except: > pass > > seed() > > def move(): #Add the following for a nice security hole global __builtins__ del __builtins__ > print __builtins__ > > #------ End Code > > I sure it has a crack in in somewhere, but it doesn't > seem to be del __builtins__ . > > -Robey From python473 at yahoo.com Mon Aug 30 18:06:44 2004 From: python473 at yahoo.com (John Howard) Date: 30 Aug 2004 15:06:44 -0700 Subject: file access in jythonc References: <9eabe547.0408210611.d5e54f7@posting.google.com> Message-ID: <9eabe547.0408301406.2543e691@posting.google.com> python473 at yahoo.com (John Howard) wrote in message news:<9eabe547.0408210611.d5e54f7 at posting.google.com>... > I have the following in a jythonc program to be executed in a html > file. > > f1 = open("filename","r") > > I get message about filePermission read error. Program compiles and > jar file is created. Just the html code gives message. > > Any ideas? I've looked up the references below and done several searches of filepermissions. It seems to me that for jythonc to have any use in development of "practical" products, programs have to be able to access local files easily. If not, then this, in my opinion, is going to be a MAJOR issue for jython!! I love the syntax and ease of programming in python, but if it cannot be used for useful programs, why bother?! BTW, how does java handle this? Is the same problem there also? From g2swaroop at gmail.com Fri Aug 20 09:01:21 2004 From: g2swaroop at gmail.com (Swaroop C H) Date: 20 Aug 2004 06:01:21 -0700 Subject: age of Python programmers References: Message-ID: <7a2acfc1.0408200501.571f3128@posting.google.com> "Lucas Raab" wrote in message news:... > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... Going to be 22 next month... Btw, I've even written a book on it :-) See www.python.g2swaroop.net Enjoy, Swaroop From mwilson at the-wire.com Mon Aug 16 14:04:17 2004 From: mwilson at the-wire.com (Mel Wilson) Date: Mon, 16 Aug 2004 14:04:17 -0400 Subject: rsa implementation question References: <1092200894.4119a9beb1978@www-mail.usyd.edu.au> <5GkSc.124$O72.121@newssvr14.news.prodigy.com> Message-ID: In article , Heiko Wundram wrote: >Am Mittwoch, 11. August 2004 10:21 schrieb Bryan Olson: >> I agree with about half of Heiko Wundram's response. > >Well, with what don't you agree? ;) > >Anyway, I've not read anywhere that for signing a message it is discredited to >use RSA decrypt with private key, encrypt with public key. I believe there's a supplied-plaintext attack. Your enemy can use your public key to compute a special text, and ask you to sign it. The effect of the computed text is that your enemy can then compute your secret key from the signature. Hashing beforehand makes is almost impossible to fall into this trap. Regards. Mel. From fredrik at pythonware.com Wed Aug 11 09:03:52 2004 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 11 Aug 2004 15:03:52 +0200 Subject: Executing bytecode from a string. References: <10hk4q68cie6815@news.supernews.com> Message-ID: John Roth wrote: > Look at the 'new' module. It's in the Library Reference under > Python Runtime Services. You'll need to wrap the byte string > with 'code', and then wrap that with 'function'. that's insane, though. use marshal on code objects, and keep your sanity. see page 4-10 in this document for a small sample: http://www.effbot.org/zone/librarybook/data-representation.pdf to avoid chaos when you upgrade Python, it's a good idea to attach imp.get_magic() to the marshalled string, and verify it before you un- marshall the code; see: http://mail.python.org/pipermail/python-list/2003-November/196230.html From alikakakhel3 at hotmail.com Sun Aug 22 20:38:32 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 22 Aug 2004 17:38:32 -0700 Subject: I would really like the code for a dome in vpython References: <8f17f4bc.0408181349.46c34b2@posting.google.com> <8f17f4bc.0408201816.13d537a6@posting.google.com> <2oq70tFdejl8U1@uni-berlin.de> Message-ID: <8f17f4bc.0408221638.72069456@posting.google.com> Cousin Stanley wrote in message news:<2oq70tFdejl8U1 at uni-berlin.de>... > >> .... > >> http://www.applied-synergetics.com/ashp/html/domes.html > >> .... > > > I went to the link you gave but the link to download the software is broken. :( > > > > Ali .... > > You might try the following link > for dome/windome software from Synergetics .... > > http://www.applied-synergetics.com/ashp/html/windome_readme.html > > This is a 6 frame animated GIF I put together back in 2001 > using this software which shows full geodesic spheres > constructed from an icosahedron base .... > > http://fastq.com/~sckitching/Icosa_1_thru_6.htm > [ 940 KB ] > > The sphere becomes more and more rounded > as the division frequency of the icosahedron > increases .... I will try those links thanks From spam_depository2004 at yahoo.com Thu Aug 26 02:57:24 2004 From: spam_depository2004 at yahoo.com (Johnny) Date: 25 Aug 2004 23:57:24 -0700 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: <2a56f6a3.0408252257.4f1f92e@posting.google.com> xah at xahlee.org (Xah Lee) wrote in message news:<7fe97cc4.0408251356.34f2102a at posting.google.com>... > How can we prevent heinous cults then? Stop bending truths. Education > and rationalism. I'm starting my own cult to exterminate morons on > this earth. Two things are on the top of my agenda: Unixism and Perl. I bet Larry Wall's life insurance premiums just skyrocketed. BTW, what does this have to do with Lisp? We are more of a therapy and support group than a cult. From squirrel at WPI.EDU Wed Aug 4 08:47:41 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Wed, 4 Aug 2004 08:47:41 -0400 Subject: numarray speed question In-Reply-To: <953AD3D0Didtoken@128.91.2.239> References: <953AD3D0Didtoken@128.91.2.239> Message-ID: On Wed, 4 Aug 2004, grv wrote: > So it is supposed to be very fast to have an array of say 5 million > integers stored in a binary file and do > > a = numarray.fromfile('filename', (2, 2, 2)) > numarray.add(a, 9, a) > > but how is that faster than reading the entire file into memory and then > having a for loop in C: > (loop over range) { > *p++ += 9 } > > or is that essentially what's going on? That's essentially what's going on ;) The point of numarray isn't to be hyper-fast, but to be as fast as the equivalent C (or Fortran, or what-have-you) implementation. In many cases, it's faster, because numarray is designed with several speed hacks in mind, but it's nothing you can't do (without a little work) in C. From aleaxit at yahoo.com Fri Aug 27 17:28:19 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Fri, 27 Aug 2004 23:28:19 +0200 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <7xzn4gwgea.fsf@ruckus.brouhaha.com> Message-ID: <1gj7a1o.1a5d2q410jsn2kN%aleaxit@yahoo.com> Paul Rubin wrote: > aleaxit at yahoo.com (Alex Martelli) writes: > > > Here is a python feature that I would like: to be able to import modules > > > from an archive like the jar files in Java. Maybe a regular tar file? > > > > Python 2.3 lets you import modules from a zipfile. The zip format is > > better than tar when you just need to get one file from it, which is why > > java's jar files are also basically zipfiles. > > Jar files are -signed- zip files. Is there some reason to not do that > for Python? I know of no reason to forbid support for such "signing", no. If you want to offer a patch to zipimport to let it support whatever signing, encryption, or other devilry appeals to you, this is definitely the right moment if you hope to see it happen in Python 2.4. If you mean patching zipimport to _forbid_ importing from any zipfile whatsoever, including a plain vanilla one, I think it's too late for THAT for Python 2.4 -- not sure what backwards incompatibilities that might cause, but it's definitely not the kind of thing you can spring on the world in a release that's already fast moving towards its hopefully-last alpha release. (Adding functionality is one thing, breaking compatibility with something that a previous release allowed is quite another...). Alex From rnichol_rrc at yahoo.com Sat Aug 21 13:59:48 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Sat, 21 Aug 2004 12:59:48 -0500 Subject: age of Python programmers In-Reply-To: References: <3cfbrh8xwe5.fsf@nemi.ping.uio.no> <4123874C.8000304@chamonix.reportlab.co.uk> Message-ID: Peter Otten wrote: > Reid Nichol wrote: > > >>>and then a quantum leap towards Python. >> >>You're aware that a quantum leap means a extremely small leap, right? > > > (from a random walk through the internet) > > size [m] jumps [m] ratio > man 2 8 4(*) > grasshopper 2e-2 4e-1(*) 20 > electron 2*3e-15 5e-11 (Bohr radius) 8000(*) > > (*) my calculation > > That's one small step for electricity, one giant leap for an electron... > Based on the above evidence a 10m Python should jump 80 kilometers (50 > miles), so beware... > > Peter > > LOL! From h.b.furuseth at usit.uio.no Tue Aug 31 17:10:00 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 31 Aug 2004 23:10:00 +0200 Subject: sys.stdin.readline() References: <367a4461.0408311221.30866c09@posting.google.com> Message-ID: Mike Maxwell wrote: > When I invoke readline() in a for loop, why does it return a series of > one-char strings, rather than the full line? > > >>> for sL in sys.stdin.readline(): print sL It does return a full line. *One* line. Then your loop iterates over the characters in that line. Try `for sL in sys.stdin.xreadlines(): print sL'. Or in newer Pythons, simply `for sL in sys.stdin: print sL'. -- Hallvard From tor.iver.wilhelmsen at broadpark.no Sun Aug 22 09:41:13 2004 From: tor.iver.wilhelmsen at broadpark.no (Tor Iver Wilhelmsen) Date: 22 Aug 2004 15:41:13 +0200 Subject: unicodedata name for \u000a References: <412869bf$0$24814$9b622d9e@news.freenet.de> Message-ID: "Martin v. L?wis" writes: > No. is not a character name. The unicodedata.name function > returns the official character name, so it MUST NOT return an alias > (which rules out your second alternative). Then why not return None or the empty string instead of raising an exception? From http Fri Aug 20 19:17:05 2004 From: http (Paul Rubin) Date: 20 Aug 2004 16:17:05 -0700 Subject: decorator J4 - any objections? References: Message-ID: <7xoel52ydq.fsf@ruckus.brouhaha.com> "Larry Bates" writes: > If docstring can be a special case of a triple quoted > string, I don't see why decorators couldn't be a special > case of a dictionary. I like that. Please add it to the wiki. From jpmorichon at earthlink.net Thu Aug 5 13:48:04 2004 From: jpmorichon at earthlink.net (CptPicard) Date: Thu, 05 Aug 2004 17:48:04 GMT Subject: Need help on how to use Pymedia! References: Message-ID: "Dmitry Borisov" wrote in message news:mailman.1208.1091724751.5135.python-list at python.org... > > > > > Thank you for your help! > > > > "Lawrence Oluyede" wrote in message > > news:3x8w4pqd3emo.15wp1jkrwkqua.dlg at 40tude.net... > > > In data Thu, 05 Aug 2004 02:28:48 GMT, CptPicard ha scritto: > > > > > > > Could someone give me a more detailed documentation on pymedia or some > > clues > > > > on how to get the information I need ? > > > > > > AFAIK Pymedia cannot extract ID3 infos from MP3 (altough you can study by > > > yourself the ID3 format a inspect the raw info of the file), anyway the > > web > > > is full of ID3 tools for python such as: > > > http://id3-py.sourceforge.net/ > > Please use this mailing list to get support on pymedia: pymedia-users at lists.sourceforge.net > It will make sure you get the quick response. I will do so! > > The documentation is a little scarce at the moment and I'm working on the tutorial to compensate that. Good news! > > Here is the code which will give you what you need( from pycar ). It is modified to match what you need and therefore not tested.: > > f= open( , 'rb' ) > dec= acodec.Decoder( ) > s= f.read( 20000 ) > fr= dec.decode( s ) > # Hardcoding for mp3 IDv1 tags > if not dec.hasHeader() and == 'mp3': > f.seek( -128, 2 ) > dec= acodec.Decoder( 'mp3' ) > dec.decode( f.read( 128 ) ) > > print dec.getInfo() I appreciate your support. I understand that this is a piece of code specially written for fixing my problem but where could I find such example in pycar ? I looked for Decoder in the pycar source code (pymedia*-src) and found no match. Do you include support for tag IDv2 too ? > > Hope this helps. > Dmitry/ > From nospam at nowhere.hu Sat Aug 7 18:00:06 2004 From: nospam at nowhere.hu (Miklós) Date: Sun, 8 Aug 2004 00:00:06 +0200 Subject: Going the PL/1 way References: Message-ID: "Michael Hudson" wrote in message news:m3oelmpsrm.fsf at pc150.maths.bris.ac.uk... > > Which you've made up: sorted is a builtin in 2.4. > > By all means carp about the new features, but -- particularly if > you're going to be sarcastic about it -- please get it right. It was me, Mikl?s, who was sarcastic about the feature frenzy and it was Istv?n who brought up .sort() and .reverse() Sorry, that's two different persons, albeit apparently both Hungarians. ;) Cheers, Mikl?s > > Cheers, > mwh > > -- > 7. It is easier to write an incorrect program than understand a > correct one. > -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html From jdhunter at ace.bsd.uchicago.edu Wed Aug 4 13:14:43 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Wed, 04 Aug 2004 12:14:43 -0500 Subject: Barcode Layout In-Reply-To: <4110CA81.6060706@cenix-bioscience.com> (Aaron Bingham's message of "Wed, 04 Aug 2004 13:37:37 +0200") References: <4110CA81.6060706@cenix-bioscience.com> Message-ID: >>>>> "Aaron" == Aaron Bingham writes: Aaron> I've been looking at Piddle Aaron> (http://piddle.sourceforge.net/) and it appears we could Aaron> write a backend to support our barcode printer with extra Aaron> methods for higher-level entities, but I'm reluctant Aaron> committing to apparent abandonware. Does anyone have Aaron> experience doing similar things with Piddle? Are there any Aaron> plans to maintain/enhance/replace Piddle? Are there other Aaron> packages I should look at? While piddle may very well serve your purposes, you may want to consider using a more active project. The last piddle update was in 2002. I am the author of matplotlib - a 2D plotting library for python. Like piddle, it is organized around various backends. It is a very active project, with a number of developers who make regular contributions in addition to myself. We have PS/EPS, SVG, wxpython, gtk, tkinter, agg (pngs) and more. It is fairly easy to write a new backend if you need to for your barcode printer (4 backends are user contributed). You could create your barcode using the matplotlib drawing/plotting functions, or by working directly with the matplotlib drawing primitives, and then display them in the hardcopy or GUI backend of your choice. Homepage: http://matplotlib.sourceforge.net/ Template for backend writers: http://matplotlib.sourceforge.net/matplotlib.backends.backend_template.html Screenshots: http://matplotlib.sourceforge.net/screenshots.html With matplotlib, you have full control over all line properties -- line width, color, dash styles, cap and join styles, etc.. -- as well as nice rendering features not found in many older drawing libraries (alpha, antialiasing). JDH From scott.b.drummonds.nospam at intel.com Wed Aug 25 14:59:48 2004 From: scott.b.drummonds.nospam at intel.com (Scott Brady Drummonds) Date: Wed, 25 Aug 2004 11:59:48 -0700 Subject: Python Image Manipulation Message-ID: Can anyone recommend the easiest way of generating thumbnail images using a Python library? I've seen that the Python Image Library (PIL) seems to do this but it isn't installed on my available systems. I'd prefer to use something distributed with Python, if possible, but will install the library that makes this functionality easy as a second choice. Thanks! Scott -- Remove .nospam from my e-mail address to mail me. http://www.e-scott.net From pwmiller1 at adelphia.net Thu Aug 26 23:12:02 2004 From: pwmiller1 at adelphia.net (Paul Miller) Date: 26 Aug 2004 20:12:02 -0700 Subject: about presicion References: <8f17f4bc.0408261434.1a73e874@posting.google.com> Message-ID: <2e363c08.0408261912.2358a016@posting.google.com> alikakakhel3 at hotmail.com (Ali) wrote in message news:<8f17f4bc.0408261434.1a73e874 at posting.google.com>... > I was wondering if it was posible to get very good presicion. I mean > like to the to the 100 th or more decimal place. if so how? You can have infinite, or at least arbitrary precision, if you do all calculations on rational numbers. Doing this will probably be very slow compared to calculations on floats, ints, or longs, however, especially if implemented in pure Python. A compromise would be to use a fixed-point representation. If you needed 100 decimal digits after the decimal point, and say, 10 before the decimal point, you could accomplish that (and actually a teeny bit more) using a 368-bit fixed-point representation. This could possibly be fast in Python, depending on the implementation. It all depends what your requirements are. From anthonybaxter at gmail.com Thu Aug 26 11:56:56 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 27 Aug 2004 01:56:56 +1000 Subject: object.* In-Reply-To: References: Message-ID: On 26 Aug 2004 08:41:25 -0700, DeadWisdom wrote: > I think there should be an ability in python to write something like > "object.*" which should return a dictionary object containing all the > members and their values for the given object. Maybe ".*" could be > treated as an operator. ::shrug:: Ick. Please don't. If you want to do this, look at the 'dir()' builtin. http://www.python.org/dev/doc/devel/lib/built-in-funcs.html#l2h-20 From nobody at nowhere.com Mon Aug 9 14:05:05 2004 From: nobody at nowhere.com (Fred) Date: Mon, 09 Aug 2004 20:05:05 +0200 Subject: VB-like GUI designer? References: <278de0e.0408090935.6d758a5d@posting.google.com> Message-ID: On 9 Aug 2004 10:35:45 -0700, luismg at gmx.net (Neuruss) wrote: (snip) Thx everyone for the feedback. I just took a look at Boa, BlackAdder, and PythonCard. For those VB developers out there, here's some notes: - Like wxGlade, Boa is based on wxWidgets, but doesn't seem to have a GUI builder. You just add widgets to a list, and I assume you have to set the coordinates and properties through code only. Also, Boa hasn't been updated since April 2003 - PythonCard is apparently since a prototype, so very risky to start using this to write professionnal apps. Besides, it doesn't seem to offer a grid object, which is a must for a lot of business apps - BlackAdder is an IDE from the Kompany (KDE), uses the QT widgets and the PyQT wrapper, and comes with the QT Designer GUI tool. So far, it's the only VB-like IDE I found, but I don't know how good it is (didn't check during install whether Python and PyQT were installed; The IDE started with a non-standard, 14-point font, etc.) Now, for some more questions: - Since the goal is to avoid getting trapped again, I'm concerned about using non-native Windows widgets, and rely on either wxWidgets or the commercial QT widgets set. Is there a GUI designer that just uses the native widgets and possibly COM controls like VB instead? Our customers are very unlikely to ever leave Windows for Linux, so I don't need cross-platform widgets - Is there a good grid object in wxWidgets or QT similar to eg. ComponentOne's VSFlexGrid? I'm especially concerned about ease of use (FlexGrid can be linked to an array, which makes it a snap to read/write data from/to an SQL server like SQLite), performance, and features (eg. can I print the grind and have a nice layout, or must I handle the printing part myself?) - Is there a GUI designer for wxWidgets that is on par with QT Designer? If not, does wxWidgets have more to offer than the QT widgets set, which would make it a better choice even if no good GUI designer is yet available for wxW? - And last, since we're on the subject of tools available to switch from VB... is there a good compiler so as to distribute a GUI Python built on either wxW or QT? I've seen a bunch of tools like py2exe, freeze, pyPack, Psyco, McMillan (RIP?), and distutils, so am a bit lost. Which would you recommend? Thank you very much for your help Fred. From steven.bethard at gmail.com Fri Aug 13 11:16:15 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: 13 Aug 2004 08:16:15 -0700 Subject: decorator syntax polling suggestion References: <411BF3FC.71051A6F@alcyone.com> Message-ID: Erik Max Francis wrote in message news:<411BF3FC.71051A6F at alcyone.com>... > The problem is that since it's an unofficial poll, and it's not clear that > Guido will give much credence to it at all, there is really no incentive > for people who are happy, or at least satisfied, with the current > decorator syntax to vote in order to express their approval. Your point is valid if the goal of the poll would be to influence Guido. The point of the polls I'm suggesting are not to influence Guido at all, but to direct the discussion among the rest of us. If it so happens that those who are happy with the current proposal don't vote, it actually doesn't make much of a difference, because those who are happy with the current proposal and not interested in the discussion enough to vote won't really be contributing to the discussion anyway. What I'm really interested in here is trying to build a consensus among the dissatisfied people. If you scan the list right now, you can see that there are a hundred people going in a hundred directions. I'm sure this looks to Guido like an insoluble problem that is best handled by a "pronouncement". On the other hand, if all (or at least a substantial majority) of the people complaining about @decorators now all got together and pushed the same counter-proposal, even if we didn't have representatives from the happy-with- at decorators group, I think we'd hold a lot more sway in Guido's eyes. I don't actually expect to be able to get a consensus on everything. Location especially I expect we won't come to an agreement on. But if it looks like most of us want, say a keyword instead of a symbol, then at least that's a step. Steve From bac at OCF.Berkeley.EDU Sun Aug 8 15:38:25 2004 From: bac at OCF.Berkeley.EDU (Brett C.) Date: Sun, 08 Aug 2004 12:38:25 -0700 Subject: python-dev Summary for 2004-07-16 through 2004-07-31 Message-ID: <41168131.10006@ocf.berkeley.edu> python-dev Summary for 2004-07-16 through 2004-07-31 ++++++++++++++++++++++++++++++++++++++++++++++++++++ This is a summary of traffic on the `python-dev mailing list`_ from July 16, 2004 through July 31, 2004. It is intended to inform the wider Python community of on-going developments on the list. To comment on anything mentioned here, just post to `comp.lang.python`_ (or email python-list at python.org which is a gateway to the newsgroup) with a subject line mentioning what you are discussing. All python-dev members are interested in seeing ideas discussed by the community, so don't hesitate to take a stance on something. And if all of this really interests you then get involved and join `python-dev`_! This is the forty-fifth summary written by Brett Cannon (will be going insane when doing the next summary thanks to decorators). To contact me, please send email to brett at python.org ; I do not have the time to keep up on comp.lang.python and thus do not always catch follow-ups posted there. All summaries are archived at http://www.python.org/dev/summary/ . Please note that this summary is written using reStructuredText_ which can be found at http://docutils.sf.net/rst.html . Any unfamiliar punctuation is probably markup for reST_ (otherwise it is probably regular expression syntax or a typo =); you can safely ignore it, although I suggest learning reST; it's simple and is accepted for `PEP markup`_ and gives some perks for the HTML output. Also, because of the wonders of programs that like to reformat text, I cannot guarantee you will be able to run the text version of this summary through Docutils_ as-is unless it is from the `original text file`_. .. _PEP Markup: http://www.python.org/peps/pep-0012.html The in-development version of the documentation for Python can be found at http://www.python.org/dev/doc/devel/ and should be used when looking up any documentation on new code; otherwise use the current documentation as found at http://docs.python.org/ . PEPs (Python Enhancement Proposals) are located at http://www.python.org/peps/ . To view files in the Python CVS online, go to http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/ . Reported bugs and suggested patches can be found at the SourceForge_ project page. The `Python Software Foundation`_ is the non-profit organization that holds the intellectual property for Python. It also tries to forward the development and use of Python. But the PSF_ cannot do this without donations. You can make a donation at http://python.org/psf/donations.html . Every penny helps so even a small donation (you can donate through PayPal or by check) helps. .. _python-dev: http://www.python.org/dev/ .. _SourceForge: http://sourceforge.net/tracker/?group_id=5470 .. _python-dev mailing list: http://mail.python.org/mailman/listinfo/python-dev .. _comp.lang.python: http://groups.google.com/groups?q=comp.lang.python .. _Docutils: http://docutils.sf.net/ .. _reST: .. _reStructuredText: http://docutils.sf.net/rst.html .. _PSF: .. _Python Software Foundation: http://python.org/psf/ .. contents:: .. _last summary: http://www.python.org/dev/summary/2004-07-16_2004-07-31.html .. _original text file: http://www.python.org/dev/summary/2004-07-16_2004-07-31.ht ===================== Summary Announcements ===================== Python 2.4a2 is out the door. The usual request for people to run the regression test suite stands. If you have been following the whole decorator syntax bugaboo, realize that I won't summarize it until the next summary (discussion started August 1). But for those of you not in the know, Guido has tentatively accepted the proposed '@decorator' syntax for decorators. This has led to an **immense** explosion in discussion python-dev (over 700 emails already for the next summary and there is still another week to go) on the subject. Basically Guido has said that the community can come up with one other syntax that they like and present that to Guido (already proposed syntaxes are pretty much out of the running for the reasons they were shot down the first time). *Much* more on this subject in the next summary. ======== Summary ======== -------------------------------------------------------------------------------------------------- Makin' bdist_wininst purty and nicer for them non-English speaking folks -------------------------------------------------------------------------------------------------- Thomas Heller asked if some better images for Distutil's bdist_wininst could be used. Some existing images were discussed, but no specific resolution was mentioned in the thread. Walter D?rwald brought up the point that if this was all being worked on he wouldn't mind having Unicode support for things such as author name and such. Thomas and Walter worked on it and that has gone in. Contributing threads: - `bdist_wininst `__ ------------------------------------------------------------------------- Assigning to None a no-no, but still okay for booleans ------------------------------------------------------------------------- Assigning to None is now a SyntaxError instead of a SyntaxWarning. Assignment to True and False, though, is still allowed and probably will not be restricted until Python 3.0 (which will probably have to wait, if Guido's OSCON slides are to be believed, until he retires). The idea of restricting assignment, though, was brought up by Raymond Hettinger. Michael Hudson, though, pointed out it would be difficult and possibly require a special opcode to handle it. Contributing threads: - `Re: [Python-checkins] python/dist/src/Python compile.c, `__ - `None as constant. Still SyntaxWarning `__ ----------------------------------------------------------------- 'as' does not get to be treated with kiddie gloves ----------------------------------------------------------------- Philip Eby asked if 'as' was going to become a keyword. Guido said not now, but in Python 3.0 it will be. Contributing threads: - `"as" to be a keyword? `__ ------------------------------------------------------------- Hopefully you didn't love FCNTL like a child... ------------------------------------------------------------- ... since if you did that kid was a lazy punk that did nothing but cause trouble for Windows users. That's why it got kicked out of the house to never come back. Contributing threads: - `Kill FCNTL.py `__ ------------------------------------------------------------------------------------------------------------------------------------------ How to get Python to compile with Microsoft's free compiler that should just come with the OS standard ------------------------------------------------------------------------------------------------------------------------------------------ 1. Download the free .NET compiler 2. Download the Windows SDK (at http://www.microsoft.com/msdownload/platformsdk/sdkupdate/ with only IE) 3. Download Garth's tools to generate a Makefile from the .sln files (at http://mail.python.org/pipermail/python-dev/2004-February/042595.html ) 4. Compile 5. Realize you should be using an OS that doesn't make you go through this many hoops just to have a compiler for your platform Contributing threads: - `Non-Visual Studio builds on Windows XP? `__ --------------------------------------------------------------------------------------------------------------------------------- Tim Peters, whitespace Czar, will break your legs if you mess up the pristine whitespace in CVS --------------------------------------------------------------------------------------------------------------------------------- Tim Peters ran Tools/Scripts/reindent.py over the entire CVS tree and fixed it up. This means you had better not mess up and check in using anything but 4-space indents with no tabs! Contributing threads: - `Fun with whitespace `__ ----------------------------------------------------------- Thread safety == won't blow up in your face ----------------------------------------------------------- Paul Moore pointed out that the documentation for deques in the collections module stated they were thread-safe. It was clarified that the statement meant that internal state would not be corrupted if multiple threads accessed the same object; no guarantee that it isn't accessed in some order or anything. Basically the idea of thread-safety for C code is that it won't lead to the interpreter exploding, nothing more. And you don't even get that guarantee with Python code. Contributing threads: - `Thread safety of deques `__ ------------------------------------------------------------------------ LC_NUMERIC PEP gets a pristine, new PEP number ------------------------------------------------------------------------ Even though the code had already been put into the core, the PEP about LC_NUMERIC and being locale-independent never got a PEP number. Well, now it has one: `PEP 331`_. .. _PEP 331: http://www.python.org/peps/pep-0331.html Contributing threads: - `PEP 331: Locale-Independent Float/String Conversions `__ ----------------------------------------------------------------------- Edward Loper becomes one of us rowdy developers ----------------------------------------------------------------------- And he has already made his initial contribution by helping to rework doctest. Contributing threads: - `Would like to add Edward Loper as a Python developer `__ ------------------------------------------------------------------------------------------------------ Any misbehaving modules during initialization from import now get the boot ------------------------------------------------------------------------------------------------------ Jim Fulton wanted a better way to detect when an import failed thanks to another module being directly imported (e.g., module A imports B which raised TypeError from some initialization code from importing; importing would leave A and B in a shoddy state in sys.modules along with raising TypeError in the import from A instead of raising ImportError). While the latter still occurs, modules are not left in sys.modules in a broken state from exceptions being raised during initialization thanks to Guido and Tim Peters. There was a discussion on circular imports and how to handle those for proper rollback. Two suggestions were taking a snapshot of sys.modules and then restoring with that if something bad happens, and putting in placeholder modules in sys.modules. But this all gets sticky from side-effects that modules can do outside of themselves before they finish importing everyone else. If, for instance, module A, as a side-effect of importation, injected a custom version of len into module B that would make the state of B different than from before the failed attempt to import module A. Now, if module A did this before doing all of its imports it could pull of the len injection but still fail from a bad import. That is not good. Basically the best solution is to not do that; there is a reason you should do all of your global imports as the first thing in a module. Contributing threads: - `Fix import errors to have data `__ ---------------------------------------------------------------------------------------------------------------------------- Stuff about Unicode, state, and how to handle when a stream terminated early; all CJK to me ---------------------------------------------------------------------------------------------------------------------------- Walter D?rwald noticed that codecs.StreamReader.read() would read a few more bytes when it discovered an error. That's bad since there might not be more bytes and continuing once an error has been found is just not right. So he wanted to fix that problem. Unfortunately he and MA Lemburg started to talk and I just couldn't follow everything about stateful and stateless decoders/encoders and the issues; I'm American so Unicode just doesn't fit in my brain well. So if you want to know what conclusions they reached you are going to read the thread on your own. Contributing threads: - `Decoding incomplete unicode `__ ---------------------------------------------------------------------- Use the docs to know what the public API is, people ---------------------------------------------------------------------- Fernando Perez got bit by having something removed from the 'keyword' module that was not part of the documented API. Turns out that running 'help' on the module listed the function in question and so he just went ahead an used it. That's not the right way to go about finding the public API of stdlib code. Always follow the documentation. If it is not listed there don't expect it to be there in the next version. While we try not to yank stuff out needlessly and will tweak things to be nice on occasion, we make no guarantees on stuff not listed in the API. The next best thing is what is listed in __all__ for a module. Since that is explicitly listed that usually can be considered part of the API. And lastly, anything starting with an underscore is off limits in terms of promises of keeping it around. Luckily Skip Montanaro applied a patch for pydoc to have it only list stuff in modules as specified by __all__, so it's a little safer out there. But the actual documentation is still king. Contributing threads: - `Rationale behind removing kwdict from keyword.py? `__ ------------------------------------------------------- Linking against static builds on Windows ------------------------------------------------------- Thomas Heller pointed out that one couldn't dynamically link against a statically built Python interpreter DLL. He and Martin v. L?wis discussed various ways to try to get this to work, but it doesn't appear they came up with one. Contributing threads: - `Static builds on Windows `__ From shalabh at cafepy.com Thu Aug 26 19:01:28 2004 From: shalabh at cafepy.com (Shalabh Chaturvedi) Date: Thu, 26 Aug 2004 16:01:28 -0700 Subject: property puzzle In-Reply-To: <260820041535594501%JBrouwersAtProphICyDotCom@no.spam.net> References: <78b6a744.0408260846.5dc5a0cf@posting.google.com> <260820041535594501%JBrouwersAtProphICyDotCom@no.spam.net> Message-ID: Jean Brouwers wrote: > Also, property needs bound methods to get, set, and delete, like > > status = property(self._get_status, self._set_status) > > /Jean Brouwers No it doesn't. The following is a working piece of code: class C(object): def getx(self): return 1 x = property(getx) print C().x Prints 1 as expected. -- Shalabh From vincent_delft at yahoo.com Sat Aug 21 15:50:44 2004 From: vincent_delft at yahoo.com (vincent_delft at yahoo.com) Date: Sat, 21 Aug 2004 21:50:44 +0200 Subject: zipfile module: problems with filename having non ascii characters Message-ID: <4127a6d7$0$4090$ba620e4c@news.skynet.be> I've a simple python script that read a directory and put the files into a Zip file. I'm using the os.walk method to get the directory content, I'm creating ZipInfo objects and set "filename", ... to what os.walk give me. ... And it works!!!! BUT!! When I open the created zip file with "WinZip" (or any other zip tool) filenames are not always like they should be. In fact filenames with characters like "?","?","?" are not correctly defined in the zip file. Does any one knows what must be done ? Does this is a "unicode" problem ? Does this is a known bug in ZipFile module ? ???? Thanks Vincent From export at hope.cz Tue Aug 17 11:56:38 2004 From: export at hope.cz (Lad) Date: 17 Aug 2004 08:56:38 -0700 Subject: Problem Message-ID: <81a41dd.0408170543.3eab590a@posting.google.com> I have only one, the following line in my program from _winreg import * When I run it from PythonWin program( under windows) it works normally. But when I try to run it from command line ( console) like python MyProgram.py I will get the error from _winreg import * ImportError: DLL load failed: The specified module could not be found. How can I solve the problem? From nospamjynyl at yahoo.co.nz Wed Aug 4 04:45:26 2004 From: nospamjynyl at yahoo.co.nz (Peter) Date: Wed, 04 Aug 2004 20:45:26 +1200 Subject: PyQt - clear widget for redraw References: <410b4492@news.maxnet.co.nz> <410fad7d@news.maxnet.co.nz> Message-ID: <41106a79@news.maxnet.co.nz> Phil Thompson wrote: > There are lots of standard graphics techniques for eliminating flicker > when drawing that you can exploit with PyQt. Double buffering for example > - draw to a QPixmap and then blit it to the QWidget. ok - I don't know what QPixmap or blit are, but it gives me some clues to use in google. :) Thanks for your help Peter From mail at mjclift.freeserve.co.uk Sat Aug 14 09:52:13 2004 From: mail at mjclift.freeserve.co.uk (Malcolm Clift) Date: Sat, 14 Aug 2004 14:52:13 +0100 Subject: random / lists Message-ID: Hi All, I have this so far. import random things = xrange(int(raw_input("choose no of things (1-8)? "))) state = [None,None] l = [] for x in things: tmp = random.choice('abcd') print state while tmp in state[0:2]: tmp = random.choice('abcd') print "choice ",x+1," is ", tmp l.append(tmp) state[x%2] = tmp print 1 Could someone help in showing me how to control it like this? That if 'a' is choosen it can only be followed by say b or d, if 'd' is choosen it can only be followed by c or b etc... I can see how to do this after the list has been generated with if statements, but that is impractical. As it is at the moment it stop two of the same letters being given one after another or the same letter occurring with only one space interviening. Thanks, Calvin From abra9823 at mail.usyd.edu.au Wed Aug 4 09:20:59 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Wed, 4 Aug 2004 23:20:59 +1000 Subject: EOL - scanning single-quoted string Message-ID: <1091625659.4110e2bb6db73@www-mail.usyd.edu.au> hi! I am developing an application for a pocket pc. i have a small gui which allows users to select files using a file dialog box. however the file, selected is represented as '/My Documents/test' which when i try to open gives me an error. so what i would like to do is replace '/' by the windows '\' however when i try str='/My Documents/test' re.subn('/', '\', str) i get an error saying - SyntaxError: EOL while scanning single-quoted string how can i replace the slashes. thanks cheers -- Ajay Brar, CS Honours 2004 Smart Internet Technology Research Group ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From squirrel at WPI.EDU Thu Aug 12 14:31:06 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 12 Aug 2004 14:31:06 -0400 Subject: Keyword substitution in string In-Reply-To: References: Message-ID: On Thu, 12 Aug 2004, Ondrej Krajicek wrote: > in my application, I want to do keyword substituion in > a string from a dictionary. The problem is indeed > easy to solve, but seems quite common to me, so I wonder > wheter there is already a function in Python which > does just that. Indeed there is: > subst('Hello, !', {'key1': 'Python', 'key2': 'rules' }) > > gives: > > 'Hello, Python rules!' 'Hello, %(key1)s %(key2)s!' % {'key1': 'Python', 'key2': 'rules'} gives: 'Hello, Python rules!' :) Aside from the (key) after the %, this works just like normal % substitution. From dmidd at chartermi.net Thu Aug 19 11:08:13 2004 From: dmidd at chartermi.net (Daryl Middleton) Date: Thu, 19 Aug 2004 11:08:13 -0400 Subject: Merging pdf documents with Python Message-ID: Can python be used to merge pdf documents into a single pdf file so that I do not have to manually insert each one. Thanks From rogerb at rogerbinns.com Mon Aug 23 22:14:52 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Mon, 23 Aug 2004 19:14:52 -0700 Subject: Help with trapping an exception References: Message-ID: pythos wrote: > not defined, I easily figured out the problem. But I need to use > "try" and "except" to catch the exception, otherwise my program will > end abruptly without finishing. So how can I see the "NameError: > global name 'Environment' is not defined" message in the "except" > section of my code? A call to sys.exc_info() doesn't show it. Is > there another function I can use? Thanks. I suggest using this code from the Python cookbook: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52215 I also strongly recommend getting the dead tree version as well. That recipe and many others are in it, and it is all well laid out with lots of good discussion. Roger From peter at engcorp.com Wed Aug 18 21:15:01 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 18 Aug 2004 21:15:01 -0400 Subject: test please ignire In-Reply-To: References: Message-ID: <4123FF15.9000001@engcorp.com> Sorry, Tom, can't ignire this. There is a newsgroup specifically for tests, called misc.test, and that's where you should be doing your testing, not in comp.lang.python. Thank you. From nelson at monkey.org Mon Aug 23 20:00:30 2004 From: nelson at monkey.org (Nelson Minar) Date: Tue, 24 Aug 2004 00:00:30 GMT Subject: Python SOAP? References: Message-ID: Ivan Voras writes: > Is anybody using SOAP with Python "seriously"[1]? It seems there's a > number of implementations out there, but most aren't developed any > more. Specifically, I hadn't found a library that supports "sessions" > with SOAP, implemented with HTTP cookies to achieve server-object > persistance. There are two active SOAP projects I'm aware of - ZSI and SOAPpy. They share a home: http://pywebsvcs.sourceforge.net/ I'd characterize both client toolkits as useful but flawed. I've run into a lot of interop problems when trying to talk to Apache Axis/Java based services. They seem to work better with the old rpc/encoded style but don't work as well with the modern document/literal style. I don't know if the specific HTTP cookie persistence you're asking for has been implemented in either. For what it's worth, I wouldn't count on that approach working reliably in many SOAP implementations. From cjw at sympatico.ca Sat Aug 14 19:39:49 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Sat, 14 Aug 2004 19:39:49 -0400 Subject: Subclassing numarray's arrays In-Reply-To: References: Message-ID: <7pxTc.44307$Mq1.2286665@news20.bellglobal.com> Mizrandir wrote: > I'd like to subclass numarray's array. I'd like to add some methods > and override others like __init__. I don't know how to do this and > haven't found help searching the manual or the web, can someone help? > > For example imagine I just want to do something as simple as making a > subclass "NewClass" with the __init__ method overridden so that the > behaviour would be: > > >>>>a = NewClass(2) >>>>print a > > [[2 2] > [2 2]] > > How could that be done? > > Thanks in advance, miz. Miz, Numarray wasn't designed with subclassing in mind, but there are workarounds for most problems. You might try something like: import numarray.numarraycore as _num class NewClass(_num.NumArray): def __init__(self, n, a): ''' n provides the length of each dimension, a is the constant value to be plugged. ''' arr= _num.array(sequence= n * n * [a], shape= (n, n)) self.__setstate__(arr.__getstate__()) def __repr__(self): " Return printable representation of instance." className= self.__class__.__name__ className= className.zfill(5).replace('0', ' ') arr= self.copy() arr.__class__= _num.NumArray rep= className + _num.NumArray.__repr__(arr)[5:] return rep def __str__(self): " Return a pretty printed string of the instance." stri= self.copy() stri.__class__= _num.NumArray return _num.NumArray.__str__(stri) if __name__ == '__main__': a= NewClass(2, 2) print a b= NewClass(3, 4) print `b` I hope that this helps. Colin W. From export at hope.cz Tue Aug 10 15:43:30 2004 From: export at hope.cz (Lad) Date: 10 Aug 2004 12:43:30 -0700 Subject: Apache web server and CGI References: <81a41dd.0408090447.7f27a092@posting.google.com> <10hf2ugjngver5e@corp.supernews.com> <81a41dd.0408092306.264beed@posting.google.com> Message-ID: <81a41dd.0408101143.43fea836@posting.google.com> Peter van Kampen wrote in message news:... > In article <81a41dd.0408092306.264beed at posting.google.com>, Lad wrote: > > [Tue Aug 10 08:51:32 2004] [error] [client 127.0.0.1] (2)No such file > > or directory: script not found or unable to stat: c:/program > > files/apache group/apache/cgi-bintest.py > > > > The name of script is test.py and is in cgi-bin (Apache subdirectory). > > In my experience cgi-bin is rarely just a subdir of apache's www-root. The > name cgi-bin is in itself not some magical name that 'turns CGI on'. You > have to configure it on your httpd.conf. Here's a relevant bit of mine: > > # > # ScriptAlias: This controls which directories contain server scripts. > # ScriptAliases are essentially the same as Aliases, except that > # documents in the realname directory are treated as applications and > # run by the server when requested rather than as documents sent to the client. > # The same rules about trailing "/" apply to ScriptAlias directives as to > # Alias. > # > ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ > > # > # "/usr/lib/cgi-bin" could be changed to whatever your ScriptAliased > # CGI directory exists, if you have that configured. > # > > AllowOverride None > Options ExecCGI > Order allow,deny > Allow from all > > > Also just to be sure the first line of test.py should be sth like this on > windows: > > #! c:\path\to\python.exe > > > BTW, how can I set up a different directory for cgi scripts? For > > example I would like to have all my scripts in > > C:\Scripts\MyScripts > > This is probably clear by now... > > Hth, > > PterK Thanks Peter for help. Now I can run cgi scripts in default c:/program files/apache group/apache/cgi-bin/ directory. The problem was that there was not last "/" But how can I forced the Apache to allowed to run scripts in a different directory for example C:\Test\MyScripts\ Thanks for help Lad From nav+posts at bandersnatch.org Tue Aug 17 15:01:17 2004 From: nav+posts at bandersnatch.org (Nick Vargish) Date: 17 Aug 2004 15:01:17 -0400 Subject: mailman mailing list program References: Message-ID: "Carol Carrot" writes: > now what is +1 QOTW.supposed to mean? Someone just voted for (+1) your statement as a Quote of the Week, which appears at the start of the weekly summary... Nick -- # sigmask || 0.2 || 20030107 || public domain || feed this to a python print reduce(lambda x,y:x+chr(ord(y)-1),' Ojdl!Wbshjti!=obwAcboefstobudi/psh?') From tor.iver.wilhelmsen at broadpark.no Fri Aug 6 11:27:05 2004 From: tor.iver.wilhelmsen at broadpark.no (Tor Iver Wilhelmsen) Date: 06 Aug 2004 17:27:05 +0200 Subject: @decorators References: Message-ID: "Neil Hodgson" writes: > global x > x = 9 I think what he meant was that the decorators in effect make for "hidden continuation", e.g. @foo def fooDecorated(): pass is like @foo def fooDecorated(): pass: when other line continuations are explicit. From rnd at onego.ru Sun Aug 15 03:01:40 2004 From: rnd at onego.ru (Roman Suzi) Date: Sun, 15 Aug 2004 11:01:40 +0400 (MSD) Subject: autocoding and the new MS book regarding software factories In-Reply-To: References: Message-ID: On Sun, 15 Aug 2004, threeseas wrote: >(CLI #1) + (GUI) + (IPC) = the three primary UIs which is like paint >having three primary colors, for which you can create any color in the >spectrum. Take away one and you greatly limit what you can do... ok.. >using these three primary UIs in processing the (CLI #2) it becomes >possible and probable that an autocoding environment can and will be >developed. > >additionally by adding a voice to text interface to the CLI #1 you can >achieve the ability of the end user/consumer to ask for a program to be >created and the system will do it. > >by patenting it..... all your base will be owned by MS... do a google >search in "autocoding" and be sure to set aside any arrogance and >ignorance you may and probably do have. > >Anyway, since there are those controlling python coders that don't like >me.... thought I'd post this. And to the GNU group.... Sorry RMS, but >software just ain't free untill anyone can easily create or cause the >computer to create it for them... for FREE... And real software >engineers that believe in the Free Software Foundation, FOSS, GPL, etc.. >will understand this... Well, there is no scientific foundation and in fact science tells us that autocoding is not possible for arbitrary tasks. I believe, it is possible to create autocoding (automatically generated) software for any little enough problem domain, maybe, say, for writing GUI. However there is theoretical abyss between modern computers and humans. It is called formalisation. Only programmer's brain is capable to cross this abyss formalising any non-trivial novel task. And for trivial task we already have an interface: $ grep -i word file | sort | uniq | wc Saying the above, I must admit that more tasks become trivial as new instruments arrive. So, programming users (CP4A anybody?) can solve their 90% of their tasks by almost mechanical combination of existing tools. * I imaging Year 2015: Computer: - by your command GvR: (standing at his computer) - computer, make Python 3.0 release. The grammar I sketched on the paper in the scanner. Please guess semantics. If in doubt post to c.l.p a question. If c.l.p in doubt make a poll. If in doubt of poll results make another poll on how to interpret poll results. Computer: - YES, SIR! GvR: - Good. (after half an our) Computer: - I need your help GvR: - yes? Computer: - please affirm you want to pay $10k for the Microsoft license and also Python 3 violates 20 patents. GvR: - Oh no!... (calling sponsors) (after half an hour) Computer: - Python 3 ready. Total cost $21k. GvR: (typing "python3" at his terminal) - Oh... But this is #D... Computer: - under given constraints this is the best solution. C.l.p poll shows 52% of people support this as it is familiar to them. GvR: (upset, playing with his time machine controls) (1 minute later) Timbot: - there is another option GvR: - What? Timbot: - freeware aka OSS Sincerely yours, Roman Suzi -- rnd at onego.ru =\= My AI powered by GNU/Linux RedHat 7.3 From vronskij at post.sk Tue Aug 17 07:33:13 2004 From: vronskij at post.sk (vronskij at post.sk) Date: 17 Aug 2004 04:33:13 -0700 Subject: How big can a Python program be? Message-ID: <903b3fba.0408170333.49ce3944@posting.google.com> Hi, A C program can be hundreds of thousands lines of code big. C++ millions. How about Python? Suppose , you are a sole programmer (lonewolf). How many lines can one handle? Thanks, jan bodnar From pythos Fri Aug 20 01:09:29 2004 From: pythos (pythos) Date: Fri, 20 Aug 2004 01:09:29 -0400 Subject: How to change a file's date/timestamp? Message-ID: How do you change a file's last-modified date and timestamp in Python? From pm_mon at yahoo.com Sun Aug 29 13:34:52 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sun, 29 Aug 2004 13:34:52 -0400 Subject: Are decorators really that different from metaclasses... In-Reply-To: References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: Paul Morrow wrote: > Anthony Baxter wrote: > >> On Sun, 29 Aug 2004 12:10:13 -0400, Paul Morrow wrote: >> >>> For example, in the following function def, the comments specify (what I >>> believe is) the author's intention behind each assignment. >>> >>> def circu(diameter): >>> """Info about circu.""" # defines circu.__doc__ >>> __author__ = 'Paul Morrow' # defines circu.__author__ >>> __features__ = memoized # defines circu.__features__ >>> pi = 3.14 # local variable definition >>> return pi * diameter >> >> >> >> Not in any Python I know of. I look at that and I think "oo, local >> variables". >> That you have a different belief doesn't make it right - I remain >> _extremely_ unconvinced. >> >> Anthony > > > My belief doesn't make it right, that's true. But I think that a > preponderance of supporting evidence does. > > Have you seen a significant number of cases where a function uses > __xxx__ attributes as local variables? Have you seen any? > > Can you craft a function definition that uses __xxx__ attributes as > local variables, where the majority of experienced Pythonistas would > agree that the double underscores are warranted? > > Paul > > Ugh... Sorry, I wrote that too hastily. Let me restate. Have you seen a significant number of cases where a function uses __xxx__ names for local variables? Have you seen any? Can you craft a function definition that uses __xxx__ names for local variables, where the majority of experienced Pythonistas would agree that the double underscores are warranted? Paul From josh at chatgris.com Wed Aug 4 03:34:32 2004 From: josh at chatgris.com (Joshua Moore-Oliva) Date: Wed, 4 Aug 2004 03:34:32 -0400 Subject: converting to string In-Reply-To: <41108A2E.7030507@mail.usyd.edu.au> References: <41108A2E.7030507@mail.usyd.edu.au> Message-ID: <200408040334.32348.josh@chatgris.com> Actually, I believe that marshal is the most efficient method to convert a python object to a string. http://docs.python.org/lib/module-marshal.html Joshua Moore-Oliva On August 4, 2004 03:03 am, Ajay Brar wrote: > hi! > > how do i go about converting a Python object or tuple to a string. > i am currently doing > import cPickle as pickle > str = pickle.dumps(obj) > > is that efficient? is that the best way to do it? > > thanks > > cheers > > -- > Ajay Brar > CS Honours 2004 > Smart Internet Technology Research Group > > http://www.it.usyd.edu.au/~abrar1 > From rich.teer at rite-group.com Fri Aug 27 01:35:42 2004 From: rich.teer at rite-group.com (Rich Teer) Date: Fri, 27 Aug 2004 05:35:42 GMT Subject: Larry Wall & Cults In-Reply-To: References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: On Fri, 27 Aug 2004, Reynir Stef?nsson wrote: > And then there's this crazy little thing called love... Nah - that was Queen! -- Rich Teer, SCNA, SCSA, author of "Solaris Systems Programming", published in August 2004. President, Rite Online Inc. Voice: +1 (250) 979-1638 URL: http://www.rite-group.com/rich From donn at u.washington.edu Tue Aug 10 14:10:52 2004 From: donn at u.washington.edu (Donn Cave) Date: Tue, 10 Aug 2004 11:10:52 -0700 Subject: Fixing socket.makefile() References: Message-ID: In article , Bryan Olson wrote: ... > The problem is that makefile() returns a Python object that has > its own local buffer. The recv() call reads directly from the > socket, oblivious to any data queued in the file object's > buffer. The problem is not limited to recv(); select(), and > perhaps other calls, will ignore the buffer and look directly at > the socket. Output buffering appears to have a similar problem. > > Now look up socket.makefile().readline(). It gets one byte at a > time. It will get the byte from the Python buffer if the buffer > is non-empty, otherwise it will try to recv() one byte at a > time, directly from the socket. By itself, readline() never > over-reads the socket; if select() and recv() would work > correctly before the readline(), they'll work after. While > correct, reading one byte at a time is painfully slow. I don't get this. Has socket.py changed this much since 2.2? The readline I'm looking at says self._sock.recv(self._rbufsize), so you would only get this behavior if you specified a buffer size of 1 or less, and read() does the same - so you could do this to yourself, but not specially just with readline. At any rate, I think it would put this in better perspective to recall that pipes, terminals and in general any "slow" device has the same issues, and that they work out the same in Python as in the original C, with socket file descriptors in place of socket objects and stdio file pointers in place of file objects. It's definitely a problem, and some kind of solution might be well received, but it needs to be portable (so forget MSG_PEEK unless you're really confident that it will be supported on every platform that now supports sockets to some useful degree), and it would be nice to apply to the problem in general and not just sockets. I think the root of the problem really is that select() doesn't look at process buffers in fileobject instances, and it can't be made to do that because that information isn't available from the stdio file pointer underneath the fileobject. So, you need a replacement for fileobject, to start with. Donn Cave, donn at u.washington.edu From po-yung.liu at pandora.be Mon Aug 23 12:56:19 2004 From: po-yung.liu at pandora.be (Vent d'Est - East Wind) Date: Mon, 23 Aug 2004 16:56:19 GMT Subject: 100 % portable ? In-Reply-To: References: Message-ID: > http://dotamatic.sf.net > http://bitpim.org > > Both are open source so you can see for yourself. Both use the > clipboard, do printing, have online help, are distributed so > that the user doesn't need Python on their machine already etc. > > Roger > > i see your website , but i see for mac os x you using cocoa interfacing i don't understand isnt WXpython from WXwindow and have in all system same apparence ? same for linux i see a like kde 2 interfacing using seems each you use each interface of each system (and not just one for every system) is that only using wxpython or add some other graphic toolkit port and using cocoa , kde interface ? thankx for reply From andrew-pythonlist at puzzling.org Thu Aug 5 04:23:58 2004 From: andrew-pythonlist at puzzling.org (Andrew Bennetts) Date: Thu, 5 Aug 2004 18:23:58 +1000 Subject: Decorator syntax In-Reply-To: References: <38ednYT1NLz1P4zcRVn-uA@powergate.ca> Message-ID: <20040805082358.GD10201@frobozz> On Thu, Aug 05, 2004 at 04:25:13AM +0000, Paul McGuire wrote: [...] > > I fear that $, ^ and ~ are just around the corner. No need to fear: ^ and ~ are already there. >>> ~1 -2 >>> 1^2 3 -Andrew. From mudd at vex.net Fri Aug 6 09:36:44 2004 From: mudd at vex.net (mudd at vex.net) Date: Fri, 6 Aug 2004 09:36:44 -0400 (EDT) Subject: static python build? Message-ID: <42353.12.151.80.14.1091799404.squirrel@webmail.vex.net> How do I build Python so that I get static libraries instead of dynamic libraries (e.g. build/lib.solaris-2.8-sun4u-2.3/math.so)? John From abra9823 at mail.usyd.edu.au Wed Aug 11 05:47:05 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Wed, 11 Aug 2004 19:47:05 +1000 Subject: rsa implementation question In-Reply-To: <5GkSc.124$O72.121@newssvr14.news.prodigy.com> References: <1092200894.4119a9beb1978@www-mail.usyd.edu.au> <200408110852.57937.heikowu@ceosg.de> <5GkSc.124$O72.121@newssvr14.news.prodigy.com> Message-ID: <1092217625.4119eb1976a92@www-mail.usyd.edu.au> > > i am using RSa for signing documents and hence decrypting and then > > encrypting to verify? > > Unfortunately yes, that seems to be what pycrypto is doing. > The method is now discredited. could you elaborate on that? i thought signing by decrypting is the way to do it. thanks cheers > > > what i was rather trying to get at was what if the plaintext is too > > large? > > Always hash and pad, for any size message. I suggest the SHA-1, > hash function, which is in the Python standard library as "sha". > > Next you need a padding scheme that formats the message into a > block suitable for the RSA private key operation. The signing > method of PKCS#1 version 1.5 is the most popular RSA signature > scheme, and when the payload is a hash digest it has no known > serious weaknesses. > > The function encode_block_from_message, below, will hash a given > message, then build and return a EMSA-PKCS1-v1_5 "Encoded > Message" (EM) from it. The returned EM is suitable for signing > with the pycrypto RSA sign function. > > I agree with about half of Heiko Wundram's response. > > > # sha1_header_tuple is the prefix of the DER encoding of a: > # sequene(sequence(oid, NULL), octet_string) > # where the octet string has length 20, and completes the encoding. > # > sha1_header_tuple = (0x30, 0x21, 0x30, 0x9, 0x6, 0x5, 0x2b, 0xe, > 0x3, 0x2, 0x1a, 0x5, 0x0, 0x4, 0x14) > > sha1_header = ''.join(map(chr, sha1_header_tuple)) > > > def sha1_hash_and_encode(message): > return sha1_header + sha.new(message).digest() > > > def encode_block_from_message(message, intended_length): > """Algorithm EMSA_PKCS1-v1_5 from PKCS 1 version 2 > intended_length should be one octet less that modulus length > """ > der_encoding = sha1_hash_and_encode(message) > assert intended_length >= len(der_encoding) + 10 > pad_string = chr(0xFF) * (intended_length - len(der_encoding) - 2) > result = chr(1) + pad_string + chr(0) + der_encoding > return result > > > -- > --Bryan > -- > http://mail.python.org/mailman/listinfo/python-list > ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom Wed Aug 25 08:54:46 2004 From: unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom (Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.) Date: Wed, 25 Aug 2004 14:54:46 +0200 Subject: module functions list References: Message-ID: dir(MODULE) print type(dir(MODULE)) #===>>> From davidb at mcs.st-and.ac.uk Fri Aug 20 07:50:12 2004 From: davidb at mcs.st-and.ac.uk (David Boddie) Date: 20 Aug 2004 04:50:12 -0700 Subject: ANN: Python Decrypt PDF script -- builds on pdftools References: Message-ID: <4de76ee2.0408200350.3ccb9c50@posting.google.com> follower at gmail.com (Follower) wrote in message news:... > I wanted to extract the meta-data from an encrypted/protected PDF file > and could not find any Python scripts to do this. So, I decided to > write something myself, the result follows. > > This demonstration utility requires the `pdftools` files from > but the > decryption functions themselves should be usable with other Python PDF > libraries. I'm glad that someone found the tools useful. :-) Unfortunately, I couldn't find any protected PDF files to test your script out on. Can you provide some URLs? > Documentation is marginal and all I can say is that worked on the > three PDF files I tested it on... :-) Do you want to supply a patch for pdftools to allow these sorts of files to be supported transparently? David From fumanchu at amor.org Sun Aug 1 21:49:41 2004 From: fumanchu at amor.org (Robert Brewer) Date: Sun, 1 Aug 2004 18:49:41 -0700 Subject: The term "Protocol" Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022DCD@exchange.hqamor.amorhq.net> Bruce Eckel wrote: > Sunday, August 1, 2004, 6:51:15 PM, Tim Peters wrote: > > > Iteration is a protocol, not a type. > > I know the term "protocol" has been used to describe a language > feature in a number of languages, but since we have no official > "protocol" support in Python I'm interested in what "we" mean by this > term. I'm going to guess that a protocol is like an interface in Java, > except that it doesn't have a concrete definition anywhere, but it is > implied through convention and use. Thus a protocol is a "latent > interface." Am I close? I'd like to understand this term better. In my (short) experience with the Python community, I've found that Pythonistas use the term "protocol" to mean a convention which is stated in the docs, as opposed to enforced via syntax. In the case of iter, your object either responds to those calls (__iter__ and next) or it does not--no inspection (or enforcement) of class or signature necessary. Note that this does *not* imply that a protocol "doesn't have a concrete definition". Python simply lands on the side of convention more often than many of what are called the "B&D" languages (which love to enforce convention in syntax), and technical terms like "protocol" naturally get bent to accomodate that. ;) Robert Brewer MIS Amor Ministries fumanchu at amor.org From james.collier at xtra.co.nz Wed Aug 11 06:40:54 2004 From: james.collier at xtra.co.nz (James Collier) Date: Wed, 11 Aug 2004 22:40:54 +1200 Subject: Capturing repeating group matches in regular expressions Message-ID: <4119F7B6.6090003@xtra.co.nz> Is it possible to capture the results of repeating group matches in the python regular expression module? To illustrate, what I want is: >>> re1 = re.compile("([a-z]W)([a-z]X)+([a-z]Y)"); >>> mo1 = re.match("aWbXcXdXeXfY"); >>> print mo1.groupsButNotAsWeKnowIt() ('aW','bX','cX','dX','eX','fY') instead of >>> print mo1.groups() ("aW", "eX", "fY") ... which captures only the last match from the second group. Of course, one option is to break out the substring containing the repeating group and then use split() or findall() within the substring, but, but, but ... I'd like to do it in one hit if possible. I believe someone has raised a similar question before, but I can't find a definitive answer. It may be so stunningly obvious that nobody ever bothers to answer - if so, could some kind soul please humour me and at least point me to what I'm not seeing in the Fine Manual. Thanks, James. From siegfried.gonzi at kfunigraz.ac.at Tue Aug 10 06:57:32 2004 From: siegfried.gonzi at kfunigraz.ac.at (Siegfried Gonzi) Date: Tue, 10 Aug 2004 12:57:32 +0200 Subject: How do I get IDLE on Suse Linux 9.x? References: <0G1Sc.149588$fv.89578@fe2.columbus.rr.com> Message-ID: <4118AA1C.81E92904@kfunigraz.ac.at> michael wrote: > Hi. > > I am reasonably experienced with Python (and love it!) on Windows. I am a > programmer that toils in c++ on Win 32 mostly but just to learn more, I am > playing with Suse 9. Linux. > > Of course the first thing I tried to fire up was Python. From the command > line, I can access Python 2.3 with no problem. > > I tried to run / search for IDLE which I thought was a standard install on > any python installation but it is not present. > > My question is this: Should I just use a text editor and go without IDLE? Is > there another IDE standard on Linux? Do I need to download something to get > IDLE? As far as I remember (I do not use Python any longer) you can do the following: Get "ActiveState Python": www.activestate.com/Python.plex I once faced the same problem with SuSE Linux 8.0. I had bad luck because I had installed the "normal" SuSE version only. I think in order to get idle running you need professional SuSE Linux (for all the header files). Fensterbrett > > From pm_mon at yahoo.com Wed Aug 11 13:10:53 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Wed, 11 Aug 2004 13:10:53 -0400 Subject: Rather than decorators, how about sections? In-Reply-To: <1C74C038-EBB6-11D8-8889-000A95857E5C@eischet.com> References: <1C74C038-EBB6-11D8-8889-000A95857E5C@eischet.com> Message-ID: Stefan Eischet wrote: > Hi, > > do we really need this stuff just to say "staticmethod" and > "classmethod"? How about: > > class Foo(object): > def baz(): > print "Static Method" > def bar(self): > print "Method" > def spam(Foo): > print "Class Method" > I like it! It's simple, clear, ... Why isn't this the hands-down best solution? Why do we want to be more verbose than necessary? I wonder if there are people out there who've chosen something other than *self* for the 1st arg (shame on them if they did! ) who's code this would break. I've never understood why we didn't require that it be called self in the first place --- why give them more than one way to do *that*? From greg at cosc.canterbury.ac.nz Tue Aug 10 22:07:28 2004 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Wed, 11 Aug 2004 14:07:28 +1200 Subject: RELEASED Python 2.4, alpha 2 In-Reply-To: References: <411231C8.3020308@interlink.com.au> <2-SdnZCwNs1SwI_cRVn-uQ@powergate.ca> Message-ID: <2ntdb0F4je2jU1@uni-berlin.de> Heiko Wundram wrote: > I don't think comparing the @ syntax to Klingon is fair to the proposed syntax > for decorators. Ah, but that's because you're not giving the proper guttural inflection to the pronunciation of '@'... -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From lonetwin at gmail.com Fri Aug 20 08:05:49 2004 From: lonetwin at gmail.com (Steve) Date: Fri, 20 Aug 2004 17:35:49 +0530 Subject: esoteric question about dict keys (Re: age of Python programmers) In-Reply-To: <4125D015.9090204@urv.es> References: <4125D015.9090204@urv.es> Message-ID: <5a309bd30408200505375a0056@mail.gmail.com> Hi, > Now the question. In "normal" dicts its not possible to use dictionaries > (nor other kinds of mutable objects) as keys, if I undersand correctly > this is a technical requirement. If I write my own dictionary-like > object, on wich the mutability of the keys is not a technical issue, is > considered blasphemous the use of dicts as keys? For example, querying > an SQL table can be partially modelled as a dictionary access: > > table[pkey_value] gives a record for this primary key > > table[{'somefield':somevalue}] returns all the records where > somefield=somevalue ...but the whole point of having keys is to uniquely identify a record, so table[] should always return *one* uniquely keyed object. Wouldn't something like [ values for value in table['somefield'] if value == 'somevalue'] or table['somefield']['somevalue'] be more a appropriate model ?? HTH Steve On Fri, 20 Aug 2004 12:19:01 +0200, Alexis Roda wrote: > This is my first message to the list, so I'll present myself and add my > contribution to the "age of python programmes" thread. > > My name is Alexis Roda, I'm 36 - 7/365 years old, I started programming > with python two years ago, mainly because I started playing with zope. > At first I was a reluctant Perl converted, although initially I hated > python (well, I hated zope wich make me hate python) now I'm in love > with both python and zope. I started programming at 15 with a Casio > calculator (a kind of assembler), then an Amstrad CPC464 (Basic), a > Macintosh Plus (Pascal, C, Lisp, assembler) and finally come to the > PC/Linux world (assembler, C, C++, Perl, bash scripting, elisp and python). > > Now the question. In "normal" dicts its not possible to use dictionaries > (nor other kinds of mutable objects) as keys, if I undersand correctly > this is a technical requirement. If I write my own dictionary-like > object, on wich the mutability of the keys is not a technical issue, is > considered blasphemous the use of dicts as keys? For example, querying > an SQL table can be partially modelled as a dictionary access: > > table[pkey_value] gives a record for this primary key > > table[{'somefield':somevalue}] returns all the records where > somefield=somevalue > > or is preferable to define a query() method for these uses and restrict > __getitem__ to mutable objects for the sake of consistency? > > TIA > -- > //// > (@ @) > ----------------------------oOO----(_)----OOo-------------------------- > <> Ojo por ojo y el mundo acabara ciego > /\ Alexis Roda - Universitat Rovira i Virgili - Reus, Tarragona (Spain) > ----------------------------------------------------------------------- > > -- > http://mail.python.org/mailman/listinfo/python-list > From tdelaney at avaya.com Tue Aug 10 02:04:04 2004 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Tue, 10 Aug 2004 16:04:04 +1000 Subject: Importance of C# (was Re: IronPython-0.6 is now available!) Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE01CF3E21@au3010avexu1.global.avaya.com> grv575 wrote: > If you want MI to specify that a class is both A and B...then which > semantics (method implementation) should it use if A and B have > different implementations of a certain method? Don't you really just > want to specify the class is A and is B to the extent that it > implements the interface of A and the interface of B? Really MI > causes more issues and confusion than it solves. http://www.python.org/2.2/descrintro.html#cooperation Tim Delaney From steven.bethard at gmail.com Tue Aug 24 21:59:02 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Wed, 25 Aug 2004 01:59:02 +0000 (UTC) Subject: J2 0-2-6 is available References: <3A81C87DC164034AA4E2DDFE11D258E3022E52@exchange.hqamor.amorhq.net> Message-ID: Doug Holton spam.here> writes: > We'll have a "with" (or similar keyword) that will work like this: > > with self: > .property1 = True > .init() > > "with" and "using" are way too similar, although they would be doing > *completely* different things. Actually, there's an interesting argument that the "with" for decorators and the "with" above can be thought of in similar terms: http://mail.python.org/pipermail/python-list/2004-August/235993.html I don't know if I agree with it, but I think I'm at least convinced they don't have to mean *completely* different things. STeve From mwilson at the-wire.com Thu Aug 26 12:21:47 2004 From: mwilson at the-wire.com (Mel Wilson) Date: Thu, 26 Aug 2004 12:21:47 -0400 Subject: Why return None? References: <1gj4fj6.kfkov1iafzb2N%aleaxit@yahoo.com> Message-ID: In article <1gj4fj6.kfkov1iafzb2Nleaxit at yahoo.com>, aleaxit at yahoo.com (Alex Martelli) wrote: >In Python 2.4, by the way, reversed(x) [[using the new built-in function >'reversed']] is most often preferable to x[::-1]. reversed returns an >iterator, optimized for looping on, but if you need a list, tuple, etc, >you can just call list(reversed(x)) and so on. Now that it's too late, I wish it were called 'reversing', after reading the story of somebody who got an iterator, thinking it was a thing. Then made a dictionary out of it twice, and got one good dict and one empty dict. 'reverse' and 'reversed' remind me of Extended Memory and Expanded Memory. One was one, and one the other, but which was which? Regards. Mel. From peter at engcorp.com Mon Aug 9 13:58:37 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 09 Aug 2004 13:58:37 -0400 Subject: decorators as a special case of an @ operator? In-Reply-To: <87d620cld8.fsf@uwo.ca> References: <87llgocrgq.fsf@uwo.ca> <87d620cld8.fsf@uwo.ca> Message-ID: Dan Christensen wrote: > Is there any reason that python doesn't automatically > continue all incomplete binary operators, allowing > > x = a_very_long_expression + > another_long_expression > ? Very likely, as is usual with Python, to avoid implicitly assuming something that could well be wrong, thus failing in a possibly very hard to find way, without warning. x = a_very_long_expression + some_function_that_might_return_a_value() Now, was the first line a typo, with a missing extra value, or was it really intended to add the result of the function call on the second line? x = a_very_long_expression + some_more some_function_that_might_return_a_value() If this is what the programmer intended, the implicit approach could be disastrous. -Peter From jzgoda at gazeta.usun.pl Sat Aug 7 19:11:53 2004 From: jzgoda at gazeta.usun.pl (Jarek Zgoda) Date: Sun, 08 Aug 2004 01:11:53 +0200 Subject: Image manipulation library under a GPL-compatible license? In-Reply-To: <2nl3suF1vntdU1@uni-berlin.de> References: <2nl3suF1vntdU1@uni-berlin.de> Message-ID: Leif K-Brooks wrote: > I need to do some simple image editing (pretty much just scaling) in a > GPLed program. Unfortunatly, both of the Python libraries for image > editing that I found (gdmodule and PIL) are under the GPL-incompatible > original BSD license. Is there another library under a friendlier library? Use os.system() with convert from ImageMagick package. See man 1 convert for explanation of convert use. -- Jarek Zgoda http://jpa.berlios.de/ From squirrel at WPI.EDU Fri Aug 6 09:44:37 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Fri, 6 Aug 2004 09:44:37 -0400 Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) In-Reply-To: References: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> Message-ID: On Fri, 6 Aug 2004, Michel Claveau - abstraction m?ta-galactique non triviale en fuite perp?tuelle. wrote: > And what is the position from Kerry "Decorators should come in a list after the function definition. Having decorarotrs in a list before the function definition is surely the best way to go. When you have @decorators, everything works out well. Adding keywords is what this country is all about!" > and/or Bush ? "Is our decorators working?" From charlie at iwec.com Tue Aug 24 21:22:36 2004 From: charlie at iwec.com (Charlie Taylor) Date: Tue, 24 Aug 2004 18:22:36 -0700 Subject: python cgi speedup on iis Message-ID: Charlie Taylor wrote: >> I'm looking for advice on how to speed up python cgi on Windows IIS ... Gilles Lenfant wrote: >Use the excellent pywin32 >http://sourceforge.net/projects/pywin32 >Look at the help in the "ASP and Python" section that shows how to register >Python as ASP engine... pywin32 ASP turned out to be EXACTLY what I needed. It took very little effort to convert my CGI scripts, and the performance boost was terrific. There are a few nagging issues regarding the reload of modified modules. The ASP engine often overlooks changed pyc files and therefore does not reload the modified modules (this requires IIS restarts), however, it is very good at detecting changes to the ASP files themselves. I've taken to debugging imported modules via CGI scripts to get around having to restart IIS. Anyway, pywin32 ASP was an excellent suggestion... thank you Gilles. ct From tim.peters at gmail.com Sat Aug 21 01:13:20 2004 From: tim.peters at gmail.com (Tim Peters) Date: Sat, 21 Aug 2004 01:13:20 -0400 Subject: [newbie] Strange behavior of the re module In-Reply-To: References: <2ejdi01btug5iskb4ipjpj7eaprd8i7vgm@4ax.com> <4126CFCC.8000609@zephyrfalcon.org> Message-ID: <1f7befae04082022136e129e55@mail.gmail.com> [Fred ] > import re > > #NOK > stuff=r"\colortbl\red0\gn0" > #NOK > stuff=R"\colortbl\red0\gn0" > > template = "BLA" > template = re.sub('BLA', stuff, template) > --------------------------------------- > > Traceback (most recent call last): > File "C:\test.py", line 9, in ? > template = re.sub('BLA', stuff, template) > File "G:\Python23\lib\sre.py", line 143, in sub > return _compile(pattern, 0).sub(repl, string, count) > File "G:\Python23\lib\sre.py", line 257, in _subx > template = _compile_repl(template, pattern) > File "G:\Python23\lib\sre.py", line 244, in _compile_repl > raise error, v # invalid expression > sre_constants.error: bad group name I can't figure out what you're trying to accomplish here, but the error msg makes sense. You should pause to read the docs for re.sub. In re.sub('BLA', stuff, template) 'BLA' is the regular expression, stuff is the substitution pattern, and template is the input string. As the docs say, \g in the substitution pattern has special meaning, specifying the name of a named capturing group. Your regular expression ('BLA') has no capturing groups (let alone named ones), so using \g in the substitution pattern can't work. If you really want to search for the regular expression 'BLA' in template and replace each occurence with the string r"\colortbl\red0\gn0" then you need to escape all characters with special meaning in the substitution pattern, via re.escape(): >>> stuff=r"\colortbl\red0\gn0" >>> template = "BLA" >>> print re.sub('BLA', re.escape(stuff), template) \colortbl\red0\gn0 >>> From sbabbitt at commspeed.net Sun Aug 29 12:52:32 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Sun, 29 Aug 2004 09:52:32 -0700 Subject: os.popen problem References: <173c23bb.0408282255.2f1be2ee@posting.google.com> Message-ID: <1093798880.792738@news.commspeed.net> "Matthew K Jensen" wrote in message news:173c23bb.0408282255.2f1be2ee at posting.google.com... > Ok, this might seem odd as to why I am doing this in this certain way, > but it's for a very specific purpose, and in so doing needs to be done > this way. I am writing code on a winbloze box like so: > I have never gotten popen to work correctly in windows, maybe you could try writing a batch file or download The Python for Windows extensions at http://starship.python.net/crew/mhammond/ and do something like. from win32com.client import constants import win32con import win32com shell = win32com.client.Dispatch("WScript.Shell") shell.Run('notepad.exe') shell.SendKeys('And now for something completely different') but SendKeys only sends to the window with focus Tom -------------- next part -------------- An HTML attachment was scrubbed... URL: From squirrel at WPI.EDU Sun Aug 1 22:16:06 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Sun, 1 Aug 2004 22:16:06 -0400 Subject: get attribute from a parent class In-Reply-To: <410d9a13$1@clarion.carno.net.au> References: <410d9a13$1@clarion.carno.net.au> Message-ID: On Mon, 2 Aug 2004, Steve wrote: > What I want to do is to be able to get class A's 'var' variable from the > nested class B. For example, I want to be able to do something like: > print "I can see you %s" % a.var > > > but... I don't want to make 'var' a class variable. I want it to be an > instance variable but still be viewable by the inner class B. Is this > possible? Any suggestions? Thanks There is no way to do this without changing your code slightly, the reason being that class B is a static definition, and refers to the same object in every instantiation of A: >>> a=A() >>> b=A() >>> a.B is b.B True To get the effect you want, you must somehow get a reference to an A object to the definition of the B object. There are two basic ways to do this: 1) Move the definition of B into A.__init__, so a new class referencing the A instance is created each time: class A: def __init__(aself): aself.var = "A's variable" class B: def __init__(bself): bself.var2 = "B's variable" bself.parent = self aself.B = B 2) Allow an instance of A to be passed in the constructor to B: class A: def __init__(self): self.var = "A's variable" class B: def __init__(self,parent): self.var2 = "B's variable" self.parent = parent Of the two, I prefer the latter, since it is much faster and the code is cleaner. The only downside is the redundancy of creating B (you have to call a.B(a) instead of a.B()). There is probably a way to get the usage of the former with the efficiency of the latter by using metaclasses, but I don't know how to do it (mostly because I don't like metaclasses very much). From rogerb at rogerbinns.com Sun Aug 15 19:21:03 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Sun, 15 Aug 2004 16:21:03 -0700 Subject: Python secure? References: Message-ID: <6o75v1-p92.ln1@home.rogerbinns.com> Reid Nichol wrote: > Roger Binns wrote: >> Yes. Anyone who recovers your "code" and/or uses it will be in >> violation of copyright and several other laws. That is legal >> protection no matter what languages or combination of languages >> you use. > > I assume you are talking about reverse engineering. If so, that just > depends on that particular countries laws. Some allow and some don't. The "uses it" bit is what is important. Even in the European Union where reverse engineering is legal, it is only legal for the purpose of interoperability and where the original vendor provides no suitable other means of doing the interoperability. Anyone just taking your code, or even recovered code and then redistributing it falls fowl of copyright laws (unless of course you GPL it :-) But no matter what, there is nothing you can do to stop people finding out the equivalent of your source code. Having your program written in a general purpose programming language on a general purpose operating system for which there are numerous tools makes it easier. It merely takes one determined person. And as a related anecdote, I reverse engineered Microsoft's RDP display protocol several years ago in Europe using IDA Pro and SoftICE. Not only did I figure out how the protocol worked, but I also found several bugs in their code :-) The RDP client was written in C and C++ which are generally considered the hardest languages to reverse engineer. Roger From peter at engcorp.com Mon Aug 16 21:45:44 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 Aug 2004 21:45:44 -0400 Subject: Python indentation deters newbies? In-Reply-To: References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: Antoon Pardon wrote: > I don't like the enforced indentation, even if I > agree 99.99% of the time with the indentation python enforces. In my humble opinion, disliking something with which you disagree only one time in ten thousand is not a good way to find happiness in life. ;-) -Peter From eddie at holyrood.ed.ac.uk Fri Aug 13 06:51:13 2004 From: eddie at holyrood.ed.ac.uk (Eddie Corns) Date: Fri, 13 Aug 2004 10:51:13 +0000 (UTC) Subject: Help understanding Scheme's syntax, procedures and calls References: <95f168b0.0408120120.31433dc7@posting.google.com> Message-ID: franbarlow at mail.com (Fran) writes: >I'm trying to understand a functional language code fragment so I can >explain its syntax and workings to my non English-speaking background >neighbour, who is doing her finals. >What in heaven's name is this code fragment intending? (In English >prose if possible). >It looks like a fragment from a language called "scheme" >(define (this n) > (if (=n 0) > 0 > (= n (this (- n 1))))) >(define (f1 a b) > (if >b a) > 0 > (+ b (f1 a (+ b 1))))) >(define (that n) >(f1 n1) For the record these three functions should have been written. (define (this n) (if (= n 0) 0 (+ n (this (- n 1))))) (define (f1 a b) (if (> b a) 0 (+ b (f1 a (+ b 1))))) (define (that n) (f1 n 1)) Which would have been obvious if I'd bothered to read the detailed stuff later instead of assuming. Peter's translation is correct. It's basically testing reasoning about recursive functions. You need to know that, unlike Python, every expression returns a value and every '(...)' is an expression to be evaluated. So the 'if' statement returns the result of whichever of the arms it takes, which in turn becomes the result of the function. Eddie From python-url at phaseit.net Mon Aug 23 16:08:07 2004 From: python-url at phaseit.net (Peter Otten) Date: Mon, 23 Aug 2004 20:08:07 GMT Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 23) Message-ID: QOTW: "Lucky for me I found python before Java took over my brain." - Huy "Python fits my brain" - c.l.py proverb "So as far as I'm concerned, SOAP is not XML, nor is it useful to even a fraction of the degree to which it is destructive." - Uche Ogbuji Over the weekend Andrea Griffini has implemented a toy Basic interpreter in Python, inspired by a post of Leif K-Brooks. A few other languages are also available. http://groups.google.com/groups?threadm=2oo13eFcj548U1%40uni-berlin.de Jeff Epler and Martin von Loewis help Vincent Delft to overcome the lack of encoding-awareness in the zip file format. http://groups.google.com/groups?threadm=4127a6d7%240%244090%24ba620e4c%40news.skynet.be As of June 2004, Pythonology has a few new success stories. http://www.pythonology.com/success Python people are nice, says Andy Todd. http://www.halfcooked.com/mt/archives/000833.html Something new from the decorator front: Paul McGuire initates another decorator poll and a new keyword followed by a suite seems to emerge as a viable contender with a small chance to beat the pie syntax. http://groups.google.com/groups?threadm=t07Vc.1179%24v86.188%40fe2.texas.rr.com Thanks to the work of Michael Sparks building on previous efforts by Mark Russell there is already a patch. Anthony Baxter, the outspoken proponent of the pie syntax, helps with some useful hints, too. http://www.python.org/sf/1013835 Robert Brewer volunteers to "sell" the result to GvR. http://www.aminus.org/rbre/python/pydec.html Too old/too young is no excuse for not learning Python, according to a thread started by Lucas Raab, asking for the "Age of Python programmers" with the only word of caution, "Not yet, but our day will come" being uttered by Robey Holderith. http://groups.google.com/groups?th=5f4805189aa2470d ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous 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 newsgroup weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Brett Cannon continues the marvelous tradition established by Andrew Kuchling and Michael Hudson of intelligently summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Business Forum "further[s] the interests of companies that base their business on ... Python." http://www.python-in-business.org Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donate.html Cetus collects Python hyperlinks. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://aspn.activestate.com/ASPN/Cookbook/Python Among several Python-oriented RSS/RDF feeds available are http://www.python.org/channews.rdf http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi http://python.de/backend.php For more, see http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. *Py: the Journal of the Python Language* http://www.pyzine.com Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. From mwh at python.net Fri Aug 6 07:28:05 2004 From: mwh at python.net (Michael Hudson) Date: Fri, 6 Aug 2004 11:28:05 GMT Subject: Object Reference? References: Message-ID: "Chris S." writes: > I'm trying to make a graphical editor and browser for Pickled > files. One aspect I'm not sure about is how to detect multiple > references to the same data. > > For instance, say I had the Pickled data: > a=[1,2,3] > b=[a,4,5] > c=[b,6,7] > d=[a,b,c] > > The idea is to allow the user to browse this data and indicate > references. In this case, if 'a' was selected, the browser should show > that 'b', 'c', and 'd' contain a reference to 'a'. Inversely, if 'c' > were selected, it should indicate that it's first element just isn't a > list, but a reference to a list defined elsewhere, namely 'b'. I would recommend getting initmately familiar with the format of pickles (something I can't claim to be). The information must be in there somewhere. Actually, maybe you could write a custom unpickler that keeps track of this kind of information. Something else I haven't tried :-) But, seriously, I think the knowledge that these objects came out of a particular pickle is going to be a powerful advantage for this sort of thing, and you should use it for everything it's worth. > Naturally, I could just recursively parse all the data comparing every > element to every previously listed object, but is there a less > obtrusive method? Python figures out when to delete objects based on > the remaining references to an object. Is there a way to access this > information to automatically lookup these references? Any help is > greatly appreciated. Well, there's gc.get_referrers() and gc.get_referrents(), but I think they are probably overkill (see above). Cheers, mwh -- (ps: don't feed the lawyers: they just lose their fear of humans) -- Peter Wood, comp.lang.lisp From peter at engcorp.com Fri Aug 13 11:42:55 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 13 Aug 2004 11:42:55 -0400 Subject: Flython? In-Reply-To: <2o4555F6dms6U1@uni-berlin.de> References: <2o3ovjF6apnoU1@uni-berlin.de> <2o4555F6dms6U1@uni-berlin.de> Message-ID: Cousin Stanley wrote: > Dan .... > > There is a freeware alternative called Powerbullet > for creating/editing Flash .swf files > that runs under Windows .... > > http://www.powerbullet.com/ > > I've only done limited testing with it under Win98, > but it seems to work OK .... But does it have anything to do with scripting via ActionScript? As far as I can see it is purely a GUI tool for doing simple animations, and does not allow any scripting. -Peter From abra9823 at mail.usyd.edu.au Tue Aug 31 00:01:28 2004 From: abra9823 at mail.usyd.edu.au (Ajay) Date: Tue, 31 Aug 2004 14:01:28 +1000 Subject: python port Message-ID: <1093924888.4133f818b2bf0@www-mail.usyd.edu.au> hi! if i am porting an existing python package to a different environment and the package uses some C code, would the port only involve recompiling it under the new envionment. for pocket pc's would recompiling using embedded Visual c++ with the pocket pc sdk be enough? or is there more to it? thanks cheers ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. From nospam at nowhere.hu Sun Aug 8 06:12:07 2004 From: nospam at nowhere.hu (Miklós) Date: Sun, 8 Aug 2004 12:12:07 +0200 Subject: Going the PL/1 way References: Message-ID: "Harald Massa" wrote in message news:Xns953F7763A998cpl19ghumspamgourmet at 195.20.224.116... > Ville, > I do not understand at all what's that decorators thingy, but I know that > girls often put some deco into flats and it really looks cosy after, so I > assume that decorators are not on the dark side of the source. > The rest of the novelties in v2.4 are more or less fine with me, too. But IMHO decorators are exactly Dark Code Wader stuff. Basically it's about self-modifying code. > Maybe we should ask for a ternary decorator, Great stuff for my original sarcastic post. :) Cheers, Mikl?s > Harald From alanmk at hotmail.com Thu Aug 19 10:52:29 2004 From: alanmk at hotmail.com (Alan Kennedy) Date: Thu, 19 Aug 2004 15:52:29 +0100 Subject: age of Python programmers In-Reply-To: <903b3fba.0408190355.38d07555@posting.google.com> References: <903b3fba.0408190355.38d07555@posting.google.com> Message-ID: [vronskij at post.sk] > Teenage programmers fading away. I think that you are at the height of > your skills in 30's. I'm 37. Does that mean I'm (in my) prime? can't-resist-cheesy-puns-ly y'rs, -- alan kennedy ------------------------------------------------------ email alan: http://xhaus.com/contact/alan From andy at andybak.net Tue Aug 3 10:42:11 2004 From: andy at andybak.net (Andy Baker) Date: Tue, 3 Aug 2004 15:42:11 +0100 Subject: Reasoning behind nested scope In-Reply-To: Message-ID: <20040803144212.537141E4002@bag.python.org> I don't particularly. I just wanted to get a feel for the syntax and if it was possible. Although I can see some utility for grouping functions in a namespace. Modules do that quite nicely but sometimes I want everything in one .py file. I found nested functions interesting as they seemed to enforce encapsulation more strongly than Python does in areas where you would traditionally expect strong encapsulation (i.e. private properties in objects). > -----Original Message----- > From: Chris Cioffi [mailto:evenprimes at gmail.com] > Sent: 03 August 2004 15:24 > To: andy at andybak.net > Cc: python-list at python.org; andybak at gmail.com > Subject: Re: Reasoning behind nested scope > > Why would you want to do this? The whole point of a nested > function, I thought, was to encapsulate some code in the > surrounding function, usually to make the surrounding > function clearer. If the nested function is of wider utility > it should just be a module level function. (Possibly of the > quasi private variety Python offers.) > > Chris > > On Tue, 3 Aug 2004 12:26:15 +0100, Andy Baker > wrote: > [snip] > > (On a side note is there any way to call a nested function from > > outside the parent? I was kind of expecting nested functions to be > > addressable through dot notation like methods are but I can see why > > that wouldn't be quite right. This might be a better > question for the > > tutor list...) > > > > Andy Baker > > > > -- > Still searching for an even prime > 2! > From yong at net.tamu.edu Thu Aug 26 16:38:39 2004 From: yong at net.tamu.edu (Yong Wang) Date: Thu, 26 Aug 2004 15:38:39 -0500 (CDT) Subject: Python MySQL API and date data type Message-ID: <20040826203840.411F81589B@net.tamu.edu> > Hi: > We have a database system. In the database, we have an > attribute called date0, which contains date data (format: > i. e. 2004-08-12). I wrote a script to fetch the data > in a specified time period: > for exaplme: > date1 = raw_input('start date ') > date2 = raw_input('end date ') > > ie. date1 = '2004-08-12' > date2 = '2004-08-20' > run = ('SELECT * FROM account WHERE (date0 >= date1) and (date0 <= date2)') > data = dbh[runn] > ..... > When I run the database query, it complains query syntax after where clause. Please see the below: > Please input your start date of your report: 2004-08-12 > Please enter your ending date of your report: 2004-08-17 > date1 is 2004-08-12 > date2 is 2004-08-17 > Traceback (innermost last): > File "report", line 25, in ? > data = dbh[run] > MySQL.error: Unknown column 'date1' in 'where clause' > > How should I fix the query statement. I check the MySQL manual. The > syntax is correct. > Thanks a lot. > > Yong > > > > --7C97B1589B.1093552427/net.tamu.edu-- > From karlehr at gmail.com Wed Aug 4 14:23:14 2004 From: karlehr at gmail.com (Karl Ehr) Date: 4 Aug 2004 11:23:14 -0700 Subject: intermittent smtp module problems (with sendmail) in python 2.2.1 Message-ID: I have written the following simple program to monitor a single URL, and notify me via email whenever this URL changes. Intermittently, I raise the following exception: Traceback (most recent call last): File "./urlwatch.py", line 34, in ? server.sendmail(sourceAddress, emailAddress, message) File "/usr/lib/python2.2/smtplib.py", line 621, in sendmail if not (200 <= self.ehlo()[0] <= 299): File "/usr/lib/python2.2/smtplib.py", line 377, in ehlo (code,msg)=self.getreply() File "/usr/lib/python2.2/smtplib.py", line 328, in getreply raise SMTPServerDisconnected("Connection unexpectedly closed") smtplib.SMTPServerDisconnected: Connection unexpectedly closed This is a copy of my code: ---------------------------------------- #!/usr/bin/env python import os, sys, string, urllib, time, smtplib, shutil, filecmp ## functions & classes ## vars sleeptime = 900 # seconds to sleep between polls urltoget = 'http://some.domain.com/foo' server = smtplib.SMTP('localhost') # server to relay smtp through for alarms emailAddress = 'user at somedomain.com' # address to send alerts to sourceAddress = 'fromuser at somedomain.com' # required! must have foo at domain.com form message = 'Your monitored URL has changed!' ## Main: # establish baseline (old version) urlfile = urllib.urlretrieve(urltoget, 'oldurlfile') print "Sleeping", sleeptime, " seconds." time.sleep(sleeptime) while 1: try: urlfile = urllib.urlretrieve(urltoget, 'newurlfile') except: print "Could not retrieve url from internet" sys.exit(-1) if filecmp.cmp('oldurlfile','newurlfile',shallow=0): print "the url is still the same" else: print "the url has changed!!!" server.set_debuglevel(1) server.sendmail(sourceAddress, emailAddress, message) server.quit() time.sleep(10) shutil.copyfile('newurlfile','oldurlfile') # sleep until next iteration print "Sleeping", sleeptime, " seconds." time.sleep(sleeptime) #EOF ------------------------------------ tia, Karl From abra9823 at mail.usyd.edu.au Wed Aug 4 03:03:10 2004 From: abra9823 at mail.usyd.edu.au (Ajay Brar) Date: Wed, 04 Aug 2004 17:03:10 +1000 Subject: converting to string Message-ID: <41108A2E.7030507@mail.usyd.edu.au> hi! how do i go about converting a Python object or tuple to a string. i am currently doing import cPickle as pickle str = pickle.dumps(obj) is that efficient? is that the best way to do it? thanks cheers -- Ajay Brar CS Honours 2004 Smart Internet Technology Research Group http://www.it.usyd.edu.au/~abrar1 From donn at u.washington.edu Tue Aug 24 12:22:18 2004 From: donn at u.washington.edu (Donn Cave) Date: Tue, 24 Aug 2004 09:22:18 -0700 Subject: How does a "script" differ from a "program" or "subroutine"? References: <2p0v42FfaqerU1@uni-berlin.de> Message-ID: In article , Dennis Lee Bieber wrote: > On 24 Aug 2004 13:45:38 GMT, Oliver Fromme > declaimed the following in comp.lang.python: > > > > > Python is more a programming language than a scripting > > language (more than Perl, at least), although you can very > > well use it for tasks which would typically be written in a > > scripting language. > > > I'd put REXX at the split point between a strictly OS scripting > language (JCL, DCL, shell scripts) and interpreted programming language > (Python, BASIC, PERL, etc.). Primarily for REXX's easy means of using OS > commands -- any statement not recognized as a REXX statement is > automatically passed to the current defined command host (normally a > command shell, but could be a REXX compatible editor, or other > application). None of this hassle of explicitly calling os.system() (for > example). For ambiguous statements (those that could be REXX or command > host), putting quotes around those meant for the host was sufficient. And you might have added, it can be applied to other environments besides the OS, as an application scripting language. In either case it takes functionality of a type that is commonly wielded by hand, and exposes it in a programming language. Hence, a script, obviously derived from common English usage of the word. Donn Cave, donn at u.washington.edu From tim.peters at gmail.com Sat Aug 7 00:51:47 2004 From: tim.peters at gmail.com (Tim Peters) Date: Sat, 7 Aug 2004 00:51:47 -0400 Subject: How to initialize instances of subclass of 'str'? In-Reply-To: <060820042320172090%kenneth.m.mcdonald@sbcglobal.net> References: <060820042320172090%kenneth.m.mcdonald@sbcglobal.net> Message-ID: <1f7befae040806215172689ad3@mail.gmail.com> [Kenneth McDonald] > I'm attempting to create a subclass of 'str' that I can abitrarily > initialize at creation time. As an illustration, this gives the > flavor of what I'm trying to do: > > class AlwaysLower(str): > def __init__(self, s): > str.__init__(self, s.lower()) > > The idea is that an AlwaysLower instance should be a string > which is always lowercase; AlwaysLower('A') -> 'a', > AlwaysLower('b') -> 'b', etc. (Of course, the resultant > instances are not _just_ strings, but since they are > subclasses of str, they can be treated and viewed as strings, > as I implicitly do above.) > > Unfortunately, the above code doesn't work; the resultant > instance's string value is always s, i.e. the call to > str.__init__ has no effect. That's correct. Objects of type str are immutable, so by the time self exists (as it must for __init__), it's too late to change its value. You want this: class AlwaysLower(str): def __new__(cls, value): return str.__new__(cls, value.lower()) Note that __new__ doesn't take a "self" argument -- in effect, it's responsible for *creating* "self". Instead it's passed the desired result class. __new__ *can* return an object of any type, but it's most useful most often if it honors the request to return an object of the passed-in class. Give the above, >>> a = AlwaysLower('AbC') >>> type(a) >>> a 'abc' >>> > ... > Anyone know of good examples of how to subclass builtins? Lib/test/test_descr.py has many examples. I don't get into value judgments about "good" . From ajsiegel at optonline.net Fri Aug 13 07:17:04 2004 From: ajsiegel at optonline.net (Arthur) Date: Fri, 13 Aug 2004 07:17:04 -0400 Subject: PEP318 In-Reply-To: Message-ID: <0I2D001ZDU03UQ@mta9.srv.hcvlny.cv.net> > On Thu, 12 Aug 2004 17:03:19 GMT, Arthur wrote: > > >def foo (): > > > whatever > > >foo = decorator (foo) > > > > > >is that you have to type the word "foo" three times. > > > > Big f**king deal - all things considered. ;) > > When this name is a PyObjC name that might be 70 characters long, > it becomes a big deal. I had asked this before: Does def __f(something): dosomething the_name_I_really_want_to_call=transform(__f) work? It is not a destructive transform of __f, but why is that important? What else am I missing? I thought I read the PyObjC folks saying that they saw use cases for a decorator syntax for their project - to be sure - but that was (mis)interpreted as meaning that they saw it as important for their project, which they don't. I could be wrong in my interpretation here. And I know there *are* folks who do consider the decorator facility as essential for their projects, but unfortunately it was never clear to me on what basis they were concluding that. Other developers involved in very important Python projects have noted that they have wish lists as well - just less will to lobby at python-dev. Design by democracy sucks. Design by squeaky wheel ain't great either. Art From reinhold-birkenfeld-nospam at wolke7.net Fri Aug 20 15:46:54 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Fri, 20 Aug 2004 21:46:54 +0200 Subject: How to clean python interpreter's environment? In-Reply-To: References: <2omtogFck37uU1@uni-berlin.de> Message-ID: <2on2lsFcqa7nU1@uni-berlin.de> Peter Hansen wrote: > Reinhold Birkenfeld wrote: > >>>Rafal Kleger-Rudomin wrote: >>> >>>>I'm looking for a command to reset interpreter's environment i.e. unload >>>>all modules, delete variables etc. >> >> What about something like this: >> >> def clear(keep=("__builtins__", "clear")): >> keeps = {} >> for name, value in globals().iteritems(): >> if name in keep: keeps[name] = value >> globals().clear() >> for name, value in keeps.iteritems(): >> globals()[name] = value > > Well, that only removes all the references from the > globals of the current module. Is that all that's > wanted? > > Note that threads that are already running will not be > removed, nothing in sys.modules will be removed, and > there are doubtless a few other things in the interpreter > that aren't quite so easy to get at. Right. So I agree with you on ^D. Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From jgrahn-nntq at algonet.se Sun Aug 8 13:27:53 2004 From: jgrahn-nntq at algonet.se (Jorgen Grahn) Date: Sun, 8 Aug 2004 17:27:53 +0000 (UTC) Subject: Does python support multi prototype. References: <2natmnFv86rjU1@uni-berlin.de> <38ednYH1NLwwOYzcRVn-uA@powergate.ca> Message-ID: On Wed, 04 Aug 2004 23:08:28 -0400, Peter Hansen wrote: > Jorgen Grahn wrote: > >> Your code was kind of elegant, but kind of misses the point with >> overloading, I think. At least, it's not anything I'd want to do in most >> situations where overloading would have been nifty in C++. IMHO. > > Okay, fair enough. Would you be able to describe any situation > in which you have found overloading to be useful in C++. (Note, > not merely nifty, but useful?) Well, it's needed for output streams to work -- the << operators which push objects onto streams cannot be member functions - and they better have the same "names". I also suspect it's vital to generic programming using templates and such ... Also when you want common functions that operate on objects without being members -- the thing Python solves by translating len(x) to x.__len__() etc. > In my experience, most of the > cases where I used it in C++ were actually cases of poor design > and should have been done differently, in hindsight. If we are talking member functions, you may have something there ... On the other hand, I don't see embedding a type name in the method name as a better alternative, ever. I wrote a small Python helper class yesterday, for reasons too complicated to explain here. I called it "Cluster", and it was really just a set of (x,y) points which I expected to be roughly clustered around some point. I needed to find the distance between (the center of) a Cluster and a point, but also between two Clusters. Had that been C++, I would have been tempted to add two methods: double Cluster::distance(const Cluster&) const; double Cluster::distance(const Point&) const; but for some reason (asymmetry?) that feels like the easy and slightly wrong way out. Anyway, this was Python so I didn't have to think much about that ;-) /Jorgen -- // Jorgen Grahn Would You Let One Marry Your Sister?'' From cookedm+news at physics.mcmaster.ca Sun Aug 22 21:13:11 2004 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Sun, 22 Aug 2004 21:13:11 -0400 Subject: 2 GB files References: <9418be08.0408221427.182a4d30@posting.google.com> Message-ID: At some point, "David Pokorny" wrote: > "Elbert Lev" wrote in message > news:9418be08.0408221427.182a4d30 at posting.google.com... >> From postings to this group and other resources I understood that the >> only way to make Python programs to work correctly with files lager >> then 2 GB is building Python interpreter with some "magic spell" >> defines. For me this is ABSOLUTELY unacceptable (Not the building, but > > Elbert: you might get a positive response if you rephrased your post. > > "Our corporation needs functionality ___. We would be happy to pay a > contract consultant $n000 to come up with a solution that will work with a > future trajectory of Python releases." > > Or you could pray to the OSS gods. Or do better research, as it already has it. My python (from Debian) has large file support, for instance. Python's configure script will use if it can find it. The OP doesn't mention what he's using that doesn't have large files (OS, platform, python version...) -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From martin at v.loewis.de Tue Aug 31 01:48:57 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 31 Aug 2004 07:48:57 +0200 Subject: Non-unicode strings & Python. In-Reply-To: References: Message-ID: <41341145$0$12484$9b622d9e@news.freenet.de> Jonathon Blake wrote: > What happens when strings are read in from text files that were > created using GB 2312-1980, or KPS 9566-2003, or other, equally > obscure code ranges? Python has two kinds of strings: byte strings, and Unicode strings. If you read data from a file, you get byte strings - i.e. a sequence of bytes representing literally the encoded contents of the file. If you want Unicode strings, you need to use codecs.open. > The idea is to read text in the file format, and replace it with the > appropriate Unicode character,then write it out as a new text file. > [Trivial to program, but incredibly time consuming to actually code] Not at all: data = codecs.open(filename, "r", encoding="gb2312") codecs.open(newfile, "w", encoding="utf-8").write(data) assuming that by "appropriate Unicode character" you actually mean "I want to write the file encoded as UTF-8". Regards, Martin From nomail at nospam.no Sun Aug 8 04:06:24 2004 From: nomail at nospam.no (Dominic) Date: Sun, 08 Aug 2004 10:06:24 +0200 Subject: Going the PL/1 way In-Reply-To: References: Message-ID: > Yes, I'm thorougly annoyed with creeping featurism. Well, you need not use them in your own code. Define and enforce a subset like it is common in ADA. However I am not sure myself were decorators will takes us, they'll certainly(?) have a major influence. Maybe it is a bit like generator-introduction. They seemed strange at first and now I think they are natural and help to simplify coding patterns. Some postings about @decorators remind me of that old farmer who only eats stuff he knows already. Ciao, Dominic From peter at engcorp.com Fri Aug 6 12:42:27 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 06 Aug 2004 12:42:27 -0400 Subject: Queue qsize = unreliable? In-Reply-To: References: Message-ID: <3MGdnbuOmodqKY7cRVn-sQ@powergate.ca> James R. Saker Jr. wrote: > Perhaps there's an easier way to accomplish what I'm attempting. [snip description] James, I can't see anything in your description that requires you to call qsize() at all, let alone get a "reliable" result. Is the key hidden somewhere in your last paragraph here? : > I've done an initial version of this using Postgresql for an > intermediary (and twisted's database interface to deal with blocking > issues), but having to load Postgresql on a syslog2beep receptor is > overkill. A ZODB Queue implemented in a threaded app would seem the > right way to go. Any thoughts? The third point seems to just say that you need a Queue and you need to have that thread sit in a blocking get(). What am I missing? > 3. have a thread sit and look for data in the queue. when data is > found, parse it and fire it off using BEEP to an upstream collector. Note that any time you have a potential consumer that you think should call qsize() before doing something, you can just have that consumer do a non-blocking get() instead, so long as it's prepared to handle the result. Alternatively, trust that qsize() is reliable to the extent that if it says the Queue has X elements, then it has at least X elements if you are the only consumer... -Peter From http Sun Aug 22 14:28:57 2004 From: http (Paul Rubin) Date: 22 Aug 2004 11:28:57 -0700 Subject: J2 proposal: keyword References: Message-ID: <7xwtzryql2.fsf@ruckus.brouhaha.com> "Robert Brewer" writes: > -Candidates for keywords have fallen into two or three camps, and > emphasize different aspects of decorators: > > -Declarative: declare, predef, moddef > -Transformative: transform, wrap, modify, mutate > -Attributive/Annotative: amend, using, having > -Directive: pragma, signify > -Associative: helper, qualify, qual, meta > -Cross-cutting: imbue, endow, bestow, embellish, extend, accum, glom, > confer > -Prepositions/Adverbs: using, through, per, via, by Not sure where these would go: prologue, preamble, preface How about something like "def_using"? From ajsiegel at optonline.com Thu Aug 19 22:43:58 2004 From: ajsiegel at optonline.com (Arthur) Date: Fri, 20 Aug 2004 02:43:58 GMT Subject: PEP 318: Can't we all just get along? References: Message-ID: <02nai0p5fepmft4gt5dchjjknsmvpsoqeq@4ax.com> On Thu, 19 Aug 2004 21:54:07 -0400, Roy Smith wrote: >In article , > "Delaney, Timothy C (Timothy)" wrote: > >> Neil Zanella wrote: >> >> > Well, allow me to contribute my thoughts on staticmethod and >> > classmethod: >> > I am barely starting out with Python and my class objects are already >> > loaded with so many >> > >> > foo = staticmethod(foo) >> >> These two facts could be somewhat related ... ;) >> >> Tim Delaney > >I never quite understood the point of static methods inside classes. >When would you ever need to do that, as opposed to just a function in a >module? In Java's "everything is part of a class" philosophy, it makes >sense, but in Python? yeah. Its confusing to me that with consistent reference to the ugliness of: foo=staticmethod(foo) I've never heard the explanation of when its true need arises. But I am afraid in these kinds of discussions it's easy to lose track of the underlying assumptions on which the discussion rests. And the basis for the discussions folks choose to have. what are debating points, what are abstract considerations, what are aesthetic issues, and what goes to the heart of solving practical porgramming issues. It is hard to deny that in a language where the need for static methods are built-in to the structure of the language, one would want something more elegant than foo=staticmethod(foo) The fact that this is simply not the case with Python seems to have been made a minor point, rather than to the heart of the matter. Hard to understand why. I am not suspecting that folks who find the need for staticmethod are making it up out of thin air, or misunderstanding the best solution to their problem.. But I do suspect that options have been taken away from them by external factors - as I suspect in the case of PyObjC 70 letter function names. In other words, its seems that they are boxed in, somehow. And perhaps the effort to accommodate a need that arises in defiance of the natural flow of the language's structure and elegance, will necessarily be subversive of its structure and elegance. Or so it seems to me, in this case. Art From amdescombes at qualicontrol.com Tue Aug 17 09:44:50 2004 From: amdescombes at qualicontrol.com (AMD) Date: Tue, 17 Aug 2004 15:44:50 +0200 Subject: Is it possible to write a DLL using python Message-ID: Hi, I need to write a Win32 DLL and I would like to use Python instead of VB, C++ or Delphi. Is this possible? Thank you, Andre M. Descombes From pm_mon at yahoo.com Sun Aug 15 13:43:30 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sun, 15 Aug 2004 13:43:30 -0400 Subject: Decorators: an outsider's perspective In-Reply-To: References: <20040814153534.8AC171E4007@bag.python.org> Message-ID: Istvan Albert wrote: > Paul Morrow wrote: > > >> That reminds me of how I once thought about using indentation as a >> means of denoting code blocks. How idiotic I thought that was. Now I >> realize the elegance, beauty, 'genius' in that. > > > I disagree. In C (Perl, Java etc) we would do three things, > write braces, indent and put the semi-colon. In python we replaced > these three, with a single (the most obvious) one the indentation. > And that's the genius there. Guido (I believe he's the one that came up with it) realized that those other symbols were unnecessary. The identation was enough to convey the author's intention. Now of course this wouldn't have been a very good idea if we (developers as a whole) used wildly different indentation styles. But we didn't/don't. There's a conventional way of showing program structure thru indentation that the majority of us have always used (subordinate code gets indented). As Python developers, we have a convention on how we name the first formal parameter of instance methods too. If you write a method that follows that convention (uses 'self' as the name of its first parm), then you don't need to do anything further to inform your readers that it's an instance method. >> Why don't we all just acknowledge that we are doing this? Why don't >> we all just admit that a well written instance method uses 'self' as >> its first argument. And well written static or class methods (as well as > > > If so then, the logically equivalent solution would be to pass self > as an implicit parameter, say a named parameter self with a default > reference to itself. I'm not suggesting this behavior, I only point out > what I think follows from the first example. The end goal is to > simplify the behavior not overload it and thus add > further meaning to it. > No, if self was passed implicitly, then you'ld be back in the situation of having to specify (with additional syntax) which methods are instance methods. Less is more. Python proves that. > I do agree with Chas Emerick in that encoding special behavior in > variable names is a fragile solution. > Define fragile. If you mean, easy to break, I don't see it. There would be only one way to define an instance method: name its first parameter 'self'. There would be only one way to define a class method: name its first parameter 'klass' or 'cls' (or some other synoynm that we can all vote on). All other methods would be static methods. How is that fragile? From google at daishi.fastmail.fm Fri Aug 6 02:33:44 2004 From: google at daishi.fastmail.fm (daishi) Date: 5 Aug 2004 23:33:44 -0700 Subject: @decorators Message-ID: For what it's worth: As far as I know, the proposed @decorator syntax will be the first time that two logical lines of python with the same indentation will not be independent of one another. Previously, when looking at: some_python(code) and_some_more = stuff there was no need to look at the the first line in order to know what the second line meant/did (and vice versa). It would seem that the cases when there are effects across multiple logical lines is captured in compound statements: """ Compound statements contain (groups of) other statements; they affect or control the execution of those other statements in some way. """ -Python Reference Manual My understanding of decorators is that they fit this definition. One thing that I am not entirely clear about is whether decorators are intended to be a compound statement themselves, or whether they are meant to simply be extensions of current compound statements such as function definition (and class definitions?) In either case, however, it seems that the following should apply: """ Each clause header begins with a uniquely identifying keyword and ends with a colon. A suite ... can be one or more indented statements on subsequent lines. """ -Python Reference Manual In the first case where decorators form their own compound statement, this would seem to imply the basic layout of: @decorator: def foo(): pass (Whether that uniquely identifying keyword for decorators happens to be spelled '@' is not important to me.) In the second case where decorators are simply extensions of current compound statements, the current wording of the Python Reference Manual would seem to imply that for function definition the clause header must begin with 'def'. I.e., the decorator should not come before the def, and certainly not on a separate line. Beyond this, however, for me it is not particularly important whether the decorator comes before/after the function name/argument list, and how it is delimited. I guess the basic point that I am trying to make is that what I find important is consistency with the basic visual layout of code promised (IMHO) by python. I believe that this promise is violated by the currently proposed decorator scheme. d PS: Although I believe the current view of the implementors is to view decorators as an extension to function definition, I believe that the separate compound statement view is fairly rich. As others have noted, it can make identical decorations simpler: @static,synchronized: def foo(): pass def bar(): pass From rschroev_nospam_ml at fastmail.fm Fri Aug 27 07:29:58 2004 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Fri, 27 Aug 2004 11:29:58 GMT Subject: How to generically transform a list? In-Reply-To: <1gj6gwy.1bqwzd6zhg7k3N%aleaxit@yahoo.com> References: <1gj6gwy.1bqwzd6zhg7k3N%aleaxit@yahoo.com> Message-ID: Alex Martelli wrote: > Roel Schroeven wrote: > > >>Roel Schroeven wrote: >> >> >>>>Just out of pure curiosity: Is there a langue that allows vertical and >>>>horizontal slicing and dicing with the same built-in pattern? >>> >>> >>>You can do it (sorta) in Python: use zip to turn the columns into rows >>>and vice-versa, apply the slicing, than zip back: >>> >>> >>> l = [['a', 1, 11, 'aa'], ['b', 2, 22, 'bb'], ['c', 3, 33, 'cc']] >>> >>> zip(*(zip(*l)[2:0:-1])) >>>[(11, 1), (22, 2), (33, 3)] >> >>You end up with a list of tuples instead of a list of lists though. > > > ...so you map(list, zip(*(zip(*l)[2:0:-1]))) if you're really keen on > this approach. Personally, I find it a disaster. I'm not too keen on it myself, just pointing how it could be done. -- "Codito ergo sum" Roel Schroeven From ayose.cazorla at hispalinux.es Thu Aug 19 20:49:59 2004 From: ayose.cazorla at hispalinux.es (Ayose) Date: Fri, 20 Aug 2004 01:49:59 +0100 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: <20040820004959.GA7263@setepo.gotdns.org> [Paul McGuire] > > [...] > The significant alternatives have been listed on the Python wiki at > http://www.python.org/moin/PythonDecorators . > My vote is: C2 C2 C1 -- Ayose Cazorla Le?n Debian GNU/Linux - setepo From timrueAT at mindspringDOT.com Sat Aug 21 13:16:57 2004 From: timrueAT at mindspringDOT.com (threeseas) Date: Sat, 21 Aug 2004 17:16:57 GMT Subject: Mind.py In-Reply-To: <4122796E.9652CCAE@alcyone.com> References: <41220b22@news.victoria.tc.ca> <4122796E.9652CCAE@alcyone.com> Message-ID: Erik Max Francis wrote: > "Arthur T. Murray" wrote: > > >>Now, suppose that you wanted to write an AI in Python that would >>implement your mind-model and allow it to grow, mutate, develop. >>Here is one possible scenario. > > > http://www.nothingisreal.com/mentifex > its a good thing we all use our minds alike, huh? Oh wait, so why doesn't Arthur slander or libel himself? In other words: regardless of whatever I may think of Arthur, he may actually be applying effort to understand his own unique use of the mind and then to code a mirror of it. But this doesn't mean his effort is invalid (even considering the difficultly cause by being inherently subjective), but only that it is different than the way you use your mind. Do you fit the norm? There are plenty of examples in human history where such non-standard direction and use of the mind brought the whole race improvment in living standards and enjoyment of life. L. Da Vinci..... how did he use his mind to do all that he did? Passon is another quality. Perhaps the question to ask is: Does the code run? I think that is about all that is required as qualifying to post in a usenet comp.lang newsgroup. As to negative responses to his posting to usenet.... it only shows that there are more who prefer to act like some animal, a dog perhaps, trying to bury their favorite bone. The point is: its only a matter of time before people on teh internet become experienced enough with what to expect that such psuedo FAQs and the likes are realized for what they are. Attempts to control the thought process of others whom they probably don't know. Maybe like how the roman numeral accountants promoted "how can nothing have value? what such a foolish contridiction" in reference to the zero place holder. And done so in order to protect their position/status in society and the rewards of it, if not just their own self programming of their minds. Imagine, if you are capable of it, that the human mind is programmable. What program do you have running? I can't say I understand what Arthur is on about and I don't believe its possible to create anything more than the illusion of intelligence in machine, but he has never done anything to put me on a negative side against him. And if I don't want to read his posting, well then nobody is forcing me to. I know how to exercise "choice"! All those who feel that they must suppress others via the generation of attacks upon them...... well they appear less capable of using their minds. What sort of AI reflection of their own minds would they create? Or is there no "I"ntelligence in their obvious "A"rtificialness. This is a python language newsgroup, but clearly there are those who want it to be more constrained than that. There are those who want it to become either what they want it to be or a negative septic tank, of which either way its a "my way of no way" line of crap. From squirrel at WPI.EDU Thu Aug 12 16:47:08 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Thu, 12 Aug 2004 16:47:08 -0400 Subject: Flython? In-Reply-To: References: Message-ID: On Thu, 12 Aug 2004, Peter Hansen wrote: > In the vein of Jython, I wonder what it would take to build > a Flython? (Lousy name, I know.) That would take Python > source, presumably a subset since some things couldn't be supported, > and compile it into ActionScript bytecode (aka the bytecode compiled > from ECMAScript source for the Macromedia Flash player environment). I don't know much about ActionScript bytecode, but I think a general Python -> ECMAScript translator wouldn't be too hard (presuming a Python subset is acceptable). ECMAScript variables are untyped, so that should ease translation some. Sounds like my weekend project! From aleaxit at yahoo.com Mon Aug 30 06:59:41 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Mon, 30 Aug 2004 12:59:41 +0200 Subject: about presicion References: <8f17f4bc.0408261434.1a73e874@posting.google.com> <2e363c08.0408261912.2358a016@posting.google.com> <8f17f4bc.0408281303.3cfb4199@posting.google.com> <20040829041630.28913.00001771@mb-m26.aol.com> <8f17f4bc.0408291552.67e3553e@posting.google.com> Message-ID: <1gjc18t.1hj0z071lwprfjN%aleaxit@yahoo.com> Ali wrote: > So the decimal module is in 2.4 but not 2.3? Also I am not geting the > 2.4 version because it seems that it is still in alpha. You _SHOULD_ get the 2.4 alpha, and try it out -- that's why alphas get released, after all! How's the final release going to be perfect unless people DO get and try the alphas?! But you shouldn't yet use 2.4 for production work (stuff you ship to customers, etc). The Decimal module is in the standard library in 2.4, but Decimal itself can support 2.3 just fine -- just download and install it. Alex From balaji at email.arizona.edu Sat Aug 14 14:15:38 2004 From: balaji at email.arizona.edu (Balaji) Date: 14 Aug 2004 11:15:38 -0700 Subject: Templates Python and Swig Message-ID: <494182a9.0408141015.365452cc@posting.google.com> Can any one help me with this. I have an c++ header file which describes a method given below. void setRows(const vector &rowNames, const vector &lhs,const vector &rhs); How I'm supposed to write this template in a interface file. So that when I pass (['a','b','c'],[0,0,0],[1,2,3]) in python it accepts it. Thanx in advance Balaji From gherzig at fmed.uba.ar Tue Aug 17 16:11:38 2004 From: gherzig at fmed.uba.ar (Gerardo Herzig -Departamento de Proyectos Especiales e Internet- Facultad de Medicina) Date: Tue, 17 Aug 2004 17:11:38 -0300 Subject: Regular expression problem with groups In-Reply-To: <9b5e8d9.0408160708.37aa9ae3@posting.google.com> References: <9b5e8d9.0408160708.37aa9ae3@posting.google.com> Message-ID: <200408171711.38712.gherzig@fmed.uba.ar> El Lun 16 Ago 2004 12:08, Axel Kowald escribi?: When use .+, the regex engine try to take the longest posible match, so now .+ matches the entire `bla` variable. You need some sort of separator (space perhaps) and then you can group: you can try re.search('([^ ]*) \\1', bla) instead. Watch the [^ ]* meaning "anything but a single space", then the space (as a separator) and last a escaped \1. Works on python 2.2 under Linux. Gerardo > Hi everybody, > > I have a 'simple' problem with regular expressions. Maybe someone can > help me. > > import re > bla = 'the the' > obj = re.search('(.+) \1',bla) > > obj.group(1) should now be 'the'. Instead obj is none (python 2.3 > under windows and 2.1 under linux). The problem seems to be the \1 > where I try to reference the first group. However, every tutorial says > this is the correct way to do it !? > > Any ideas what I'm doing wrong ? > > Many thanks, > > Axel -- Gerardo Herzig Departamento de Proyectos Especiales e Internet Facultad de Medicina U.B.A. From tjreedy at udel.edu Sun Aug 1 03:25:27 2004 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 1 Aug 2004 03:25:27 -0400 Subject: Nick Berg Alive References: Message-ID: wrote in message news:f9ZOc.96265$fv.34850 at fe2.columbus.rr.com... > Conspiracy theories of Nick Berg being alive and well in Iraq have today been proven true. Aljazeera have released video footage of the supposedly beheaded American captive. The clip was first "discovered" on an Islamic website in Malaysia and has now been released by American Journalists collaborating with Aljazeera. The evidence speaks for itself and can be viewed firsthand here. http://www.greentea.625.co.kr/NickBerg.zip This is a variation of an reported virus link posted to other newsgroups. From mwh at python.net Wed Aug 11 07:04:28 2004 From: mwh at python.net (Michael Hudson) Date: Wed, 11 Aug 2004 11:04:28 GMT Subject: Capturing repeating group matches in regular expressions References: Message-ID: James Collier writes: > Is it possible to capture the results of repeating group matches in > the python regular expression module? Not easily; there's a small dicussion on python-dev at the moment about this. Erik Heneryd hacked up something that might be useful: http://mail.python.org/pipermail/python-dev/attachments/20040810/a5e602ab/structmatch.py And there's always the "use a real parser" option :-) Cheers, mwh -- All obscurity will buy you is time enough to contract venereal diseases. -- Tim Peters, python-dev From peter at engcorp.com Fri Aug 20 10:48:35 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 20 Aug 2004 10:48:35 -0400 Subject: Alternative decorator syntax decision In-Reply-To: <1IqdnUhRpch8m7vcRVn-vQ@giganews.com> References: <1IqdnUhRpch8m7vcRVn-vQ@giganews.com> Message-ID: Istvan Albert wrote: > David Fraser wrote: > >> Thats because the point of this vote is to try and gather a consensus >> about what the best alternative is, > > But what if the alternative is that you don't need a best > alternative? There lies the crux of the problem. No, deciding if an alternative should be chosen is step two at this point. > > not to try and out-vote the original contender. > > If you cannot out-vote the original contender than what > is the whole point of the poll? Why would this proposal be > accepted if it cannot outclass the original one? It will *not* be accepted on the basis of whether or not it can "outclass" (I assume you mean get more votes than) the original one. As has been pointed out repeatedly, this is not a democracy, and outvoting the @pie syntax would do nothing. The point is that we were asked *specifically* for a community consensus on an alternative, if there should be an alternative. This vote is to help form that consensus, not to decide *if* there should be an alternative. You might even say that the decision as to whether there should be an alternative cannot be made until the outcome of the vote is known. If no alternative gets overwhelming support, then we are in the same situation as the old ternary operator debate. You were around for that, weren't you? The community could not agree on *which alternative to doing nothing* was best, so in the end nothing happened. The parallel with the present debate is that if the community cannot rally around any alternative as being better than all the other non- at pie alternatives, then "nothing will happen" and in this case that means @pie wins out and goes in 2.4. -Peter From edreamleo at charter.net Thu Aug 5 14:36:23 2004 From: edreamleo at charter.net (Edward K. Ream) Date: Thu, 5 Aug 2004 13:36:23 -0500 Subject: Confused about pep 318 References: <10h2ihgb8c6fi97@corp.supernews.com><10h4s026oapbhf1@corp.supernews.com> Message-ID: <10h4vhcfbsv6t30@corp.supernews.com> > Sorry, but if discussions on python-dev are not considered "public", what is? The reason that discussions on py-dev were not valid a public discussion of '@' is that there was no public announcement that pep 318 pertained to '@'. It's that simple. It's sorta like holding a public meeting supposedly to discuss sewers and voting to give all the county commissioners 100% raises instead :-) The public wasn't informed of the true nature of the meeting, so the open meeting law was violated. To repeat: given that pep 318 is grossly misleading, I contend that no proper discussion of it has ever taken place. Sorry, but if you actively mislead the public, then the public _does_ have a right to complain. The web is a huge place. Expecting people to track it without proper notice of what is being discussed is patently unfair. Edward -------------------------------------------------------------------- Edward K. Ream email: edreamleo at charter.net Leo: Literate Editor with Outlines Leo: http://webpages.charter.net/edreamleo/front.html -------------------------------------------------------------------- From cjw at sympatico.ca Wed Aug 25 22:00:15 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Wed, 25 Aug 2004 22:00:15 -0400 Subject: Alternative decorator syntax decision In-Reply-To: <412cc31c$1@news.012.net.il> References: <412cc31c$1@news.012.net.il> Message-ID: <412D442F.2040107@sympatico.ca> Avner Ben wrote: > I believe putting the decorator list before the function header is > generally a bad design decision. While it may make parsing-related > sense, it violates Python's greatest asset: being executable pseudocode. > The way I see it, the latter quality means being able to look at the > code and see clearly and immediately what requirements from the real > world the code was written the serve. Functions and methods are major > code entities that are naturally expected to represent discrete > functional requirements from the code, to this or that level of detail. > I expect to learn from the method name, the class it is in and the list > of arguments it takes, everything I need to know about the functional > requirement it implements. If that is not enough, I will look at the > docstring, if present. Everything else the method has to offer is > conveniently hidden below. Decorators of the type discussed recently - > with the exception of staticmethod and classmethod - are technical > detail of the kind I would like to see hidden below. Putting them on > top, prior to the what the method does (its name etc.) compromises the > design quality of the code, reducing it to yet another > abbreviation-based, self-centered technical scripting language. > The one esception I saw was J2, which, although putting the decorators > before the proper method header, uses indentation to state "this is an > extra piece of technicality which you are free to ignore - the def is > below." > > My vote: C2, E4, J2 > > Avner. Your expectation list makes sense to me. There is merit in having the docstring before the 'decorator', i.e. E4 Colin W. From jeff at ccvcorp.com Wed Aug 11 14:29:54 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Wed, 11 Aug 2004 11:29:54 -0700 Subject: A decorator syntax not yet mentioned (I think!) In-Reply-To: References: Message-ID: <10hkpcaghcu6m9e@corp.supernews.com> Michael Sparks wrote: >Peter Hansen wrote: > > >>class Klass: >> # init set >> >> decorate: >> staticmethod >> def meth0(x): >> return x >> >> > >[snip] >My initial reaction to @decorators was "ugh!". However I was coming to >accept it as inevitable after reading the various arguments for/against >various syntaxes. *This* syntax strikes me personally as having >distinct advantages - largely for clarity of code, and solves the >"where *DOES* the function start?" question with large decorator >blocks. > I agree. This seems to fit the absolute requirements I've heard passed down from GvR, and also avoids all of the things that really made my teeth grate about the @decorator syntax. It's the first prefix syntax I've seen that actually *looks* like Python to my eyes. There's still room for discussion about the specific keyword (I'd be happy enough with "decorate", and not so fond of "using" or "with", but a case could easily be made for something else...) and about ordering -- presenting the decorators as a suite decorate: d1 d2 def method( ... ) pass suggests to me an equivalence to method = d2(d1(method)) which is the reverse of the ordering of @decorators. How significant the difference is, I can't say... Jeff Shannon Technician/Programmer Credit International From asqui at hotmail.com Tue Aug 17 06:38:14 2004 From: asqui at hotmail.com (asqui) Date: 17 Aug 2004 03:38:14 -0700 Subject: Case sensitivity bug in ConfigParser? Message-ID: <20568caa.0408170148.6e186536@posting.google.com> (Assume an instantiated ConfigParser, c, with a loaded file) >>> c.get("DEFAULT", "foo", False, {"foo": "Bar"}) 'Bar' >>> c.get("DEFAULT", "Foo", False, {"Foo": "Bar"}) Traceback (most recent call last): File "", line 1, in ? c.get("DEFAULT", "Foo", False, {"Foo": "Bar"}) File "C:\Python23\lib\ConfigParser.py", line 513, in get raise NoOptionError(option, section) NoOptionError: No option 'foo' in section: 'DEFAULT' The offending code appears to be as follows (in ConfigParser.py): def get(self, section, option): opt = self.optionxform(option) if section not in self._sections: if section != DEFAULTSECT: raise NoSectionError(section) if opt in self._defaults: return self._defaults[opt] else: raise NoOptionError(option, section) elif opt in self._sections[section]: return self._sections[section][opt] elif opt in self._defaults: return self._defaults[opt] else: raise NoOptionError(option, section) It uses optionxform on the supplied option, but not on the one in the defaults dictionary. If you're going to impose a transform then you have to do it consistently, imho... >>> c.get("DEFAULT", "Foo", False, {"foo": "Bar"}) 'Bar' The supplied "Foo" gets transformed to "foo" and matches the one in the defaults dictionary. Seems a bit counterintuitive to expect that you supply any defaults as pre-transformed according to your specified optionxform. I'm not sure if this is also a problem when reading a file, but there seems to be a related post about this (with no replies!) dating back to 2000 http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=8suc1f%24mf9%241%40nnrp1.deja.com I don't have time to look into it now but I'd guess this problem was resolved in the more obvious location (when reading a file) but patching of the defaults dictionary case was omitted. asqui From pickle_lover37 at hotmail.com Mon Aug 2 03:30:32 2004 From: pickle_lover37 at hotmail.com (quentin long) Date: Mon, 02 Aug 2004 07:30:32 +0000 Subject: help with py2exe Message-ID: i try running it but it gives me an error: AttributeError: DistributionMetadata instance has no attribute 'get__doc__' im a complete noob so help me out _________________________________________________________________ Don?t just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/ From tassilo.von.parseval at rwth-aachen.de Thu Aug 26 03:49:48 2004 From: tassilo.von.parseval at rwth-aachen.de (Tassilo v. Parseval) Date: Thu, 26 Aug 2004 09:49:48 +0200 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <2a56f6a3.0408252257.4f1f92e@posting.google.com> Message-ID: <2p5j10FesankU1@uni-berlin.de> Also sprach Johnny: > xah at xahlee.org (Xah Lee) wrote in message news:<7fe97cc4.0408251356.34f2102a at posting.google.com>... > >> How can we prevent heinous cults then? Stop bending truths. Education >> and rationalism. I'm starting my own cult to exterminate morons on >> this earth. Two things are on the top of my agenda: Unixism and Perl. > > I bet Larry Wall's life insurance premiums just skyrocketed. It would, if anyone could take Xah Lee Loo seriously. But really, no one can. He's more like the court jester, creeping out of the dark every so and so months. We're all very much enjoying his sporadic shows. Really. ;-) Tassilo -- $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({ pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#; $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval From anthonybaxter at gmail.com Thu Aug 26 23:51:11 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 27 Aug 2004 13:51:11 +1000 Subject: Call for signatories for J2 In-Reply-To: <412e3ba4$0$92817$ed2619ec@ptn-nntp-reader02.plus.net> References: <1gj4gzn.13gkzk49zvup2N%aleaxit@yahoo.com> <7xhdqp967k.fsf@ruckus.brouhaha.com> <412e3ba4$0$92817$ed2619ec@ptn-nntp-reader02.plus.net> Message-ID: On Thu, 26 Aug 2004 20:14:33 +0100, Michael Sparks wrote: > 1 The @pie implementation might stay as is. > 2 The @pie implementation might stay, but require explicit activation > needing a __future__ statement. This to my mind is a good option - it > clearly marks the feature as experimental, making people shy away from > use unless they really do need it. > 3 J2 might be accepted. > 4 The feature might be ripped out > * etc... > > Options 2 or 3 strike me as the best approach here - introduce a feature, > mark it as experimental, with a large warning that it might change in the > next release. That potentially allows the best of both worlds - people can > use the feature in earnest, but do so on the understanding that the feature > may change in a later release meaning that if they use it they have to be > prepared to change their code. Furthermore if they release code using the > feature they should be very careful how they use the feature. That's not the way Python works - we don't rip stuff out once it's been in a final release. from __future__ is added so that people can turn on a new feature gradually, without their code being instantly broken. From unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom Sat Aug 28 01:16:01 2004 From: unseulmcmcmcmc at msupprimerlepoint.claveauPOINTcom (Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.) Date: Sat, 28 Aug 2004 07:16:01 +0200 Subject: Iteration over Lists and Strings References: Message-ID: and enumerate is more fast than index. From ellisjb at my-deja.com Sat Aug 7 01:26:36 2004 From: ellisjb at my-deja.com (ellisjb at my-deja.com) Date: 6 Aug 2004 22:26:36 -0700 Subject: Tkinter, Simple Table In-Reply-To: Message-ID: Tkinter doesn't do tables very well... The closest thing I can think of to what you want is the multilistbox recipe in the python cookbook, but that's not going to handle multiple lines per 'cell' IIANM. -Jonathan Torsten Mohr wrote: > Hi everybody, > > i'd like to have a small python script that creates a > table (like in Excel) and where i can enter multiline > text in the tables cells. > > Can anybody give me a hint where to look? > > Does TList do what i want? THe description looked good, > but i didn't find an example for it. > > > Regards, > Torsten. From python at elehack.net Wed Aug 4 15:33:05 2004 From: python at elehack.net (Michael Ekstrand) Date: Wed, 4 Aug 2004 14:33:05 -0500 Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) In-Reply-To: References: <10h24oace15n97a@news.supernews.com> Message-ID: <200408041433.05668.python@elehack.net> On Wednesday 04 August 2004 14:11, Ville Vainio wrote: > Yes, it should work. It's also a terrible waste of @ punctuation, > which should IMO be reserved for some more worthwhile purpose. I'd concur with that... I saw the decorator syntax and thought "what is this thing? and why is it in Python?" When I read about decorators in the What's New guide, the first syntax that jumped to my mind was: def(staticmethod) somemethod(self, args): some code This was before reading the PEP or seeing any other recommendations for syntax (except the nested-block syntax mentioned in another thread, which I don't like either; it seems to not fit the nature of decorations very well). -Michael From reinhold-birkenfeld-nospam at wolke7.net Thu Aug 12 16:23:25 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Thu, 12 Aug 2004 22:23:25 +0200 Subject: decorator with keyword In-Reply-To: References: Message-ID: <2o21dhF65snnU1@uni-berlin.de> Christopher T King wrote: > On Thu, 12 Aug 2004, Peter Otten wrote: > >> [decorator examples] > > +2 on this (can I give a +2?). It's not only pretty, but it addresses my > gripe about decorators being used for too many purposes (by providing a > clean way to supply function attributes). Additionally, by moving > docstrings into the transform: block, this provides an easy way to > document the generated function, rather than forcing decorators to > preserve docstrings by copying the decoratee's docstring into the > decorated function. > > The PythonDecorators wiki doesn't say Guido has specifically shot this > style down, so it may yet have a chance. I would also support this variant. I was a supporter of list-after-def, but this seems to me pythonic AND readable. +1! Hope Guido hears about that proposal! Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From jacek.generowicz at cern.ch Wed Aug 25 04:55:29 2004 From: jacek.generowicz at cern.ch (Jacek Generowicz) Date: 25 Aug 2004 10:55:29 +0200 Subject: Python future performance and speed References: <278de0e.0408211605.426e5129@posting.google.com> <3064b51d.0408221352.ca7b57e@posting.google.com> Message-ID: beliavsky at aol.com writes: > (2) The Python approach to OOP is very different -- looser -- than > that of C++ and has less support for data hiding. For example, one can > add an attribute to an object anywhere, which seems like a dubious > freedom to me. Seems like a damn useful freedom to me. But then I've worked with people who refused to take the obvious clean, efficent, clear design decision only because it violated some principle they were told about in some OOA&D class ... only to insist on creating a program which was slow, ugly, difficult to understand, difficult to maintain, and had a few less useful features. > (3) The beginning of a Python function only tells you about the > arguments, not the result. I prefer not to scan the entire body of a > function to see what it returns. Compiled languages like C++, Fortran, > and Pascal put the argument and result info in one place. And compiled lanugages like Lisp[1] and Python[2] don't. Oh, you meant "explicitly statically typed", rather than "compiled", I see :-) But caring about the type to this extent is not a very productive way of programming in Python. You should understand the purpose of the function, and thereby understand the duck types it accepts and returns ... and duck types are not expressible in a way that wouldn't make a explicitly static compiler smoke. Of course, those coming from the bondage school of programming (C++, Java ...) will run screaming when confronted with duck typing, but that's their loss. > (4) Python does not look like C++. Some programmers think that any > alternative to C++ must still look like it. I think this argument is > weak, but Java's cosmetic similarity to C++ probably has boosted its > popularity. This is one of the greatest tragedies: C++ is accepted as the starting point. We're doomed. [1] Compiled to native machine code (usually). [2] Compiled to bytecode (usually). From me at privacy.net Wed Aug 18 07:30:05 2004 From: me at privacy.net (Dan Sommers) Date: 18 Aug 2004 07:30:05 -0400 Subject: PEP 318: Can't we all just get along? References: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: On Tue, 17 Aug 2004 21:13:47 -0400, Paul Morrow wrote: > First though, I still believe that we should exploit existing > conventions (recommended coding practices) as a way of getting 'free' > declarations for class, static, and instance methods (e.g. methods > whose first param is 'self' are instance methods, etc.). That feels > very pythonic to me, just as we use naming conventions to distinguish > public, private, and semi-private methods. I don't understand how assigning semantic significance to a "recommended coding practice" is Pythonic. In the face of ambiguity, refuse to guess. Explicit is better than implicit. I think that the idea that started this thread is just right: def decorator function( arguments ): pass is exactly equivalent to def function( arguments ): pass decorator( function ) Note that: - the decorator is right next to the function name - the decorator is outside the code of the function - there are no new keywords or punctuation - it's dynamic, flexible, and extensible It's also abusable, but that's the nature of a language as dynamic as Python. Regards, Dan -- Dan Sommers Never play leapfrog with a unicorn. From squirrel at WPI.EDU Fri Aug 6 09:57:49 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Fri, 6 Aug 2004 09:57:49 -0400 Subject: Trimming a string In-Reply-To: References: <10gsmuieo65du5d@news.supernews.com> <10gsotqjc2qrl54@news.supernews.com> Message-ID: On Fri, 6 Aug 2004, Peter Hansen wrote: > Braindamagedness notwithstanding, Double Dumbass (appropriately > named?) needs to learn to cope with his situation in life and > reading the tutorial repeatedly, even, if necessary each time > before posting a question, would be a better approach than > insulting those who try to help. He should take a page from the decorator debate - several hundred posts (possibly over a thousand), and not one direct insult hurled or flame war started (though I have been accused of insinuating others enganged in "dastardly" behaviour ;)). From swheatley at gmail.com Tue Aug 3 16:28:27 2004 From: swheatley at gmail.com (Shawn Wheatley) Date: Tue, 3 Aug 2004 16:28:27 -0400 Subject: C# / .NET books recommendations? (was: Re: Importance of C#) In-Reply-To: References: <278de0e.0407281353.27b6a457@posting.google.com> <5dydnZSDZaARoZXcRVn-ug@powergate.ca> <9418be08.0407292114.129c856f@posting.google.com> Message-ID: The only one I would say I can't do without is "Pragmatic ADO.NET". It is _the_ reference for any database stuff you want to do with .NET. All the code is in C#. So once you have C# down, check this book out. Shawn On 2 Aug 2004 15:24:58 -0700, Ely Stob wrote: > Ivan Voras writes: > > Elbert Lev wrote: > > > > > C# IS a good language and .NET is a very good environment. Recently I > .... > > > Important - Python realities (not exotic) map on C# perfectly. > > > > My experience exactly - this is what I was fishing for. While I > > wouldn't say 'perfectly', it is good, and certainly 'good enough'. > > Interesting comment. > > Anybody have recommendations (and warnings-off...) for books on C#, .NET, > and associated gubbins? (ASP.NET, ADO.NET, Windows Forms, ...) > > I'm guessing that I'll need a good half-tonne of dead tree if I'm to get a > grasp of it <0.5 wink>. Figuring out *which* half-tonne might be even > more time-consuming than reading that dry mass, though... > > Some books that caught my own eye - all comments much appreciated: > > C# and .NET > =========== > > Jesse Liberty; Programming C# > > Andrew Troelsen; C# and the .Net Platform > > Anders Hejlsberg, Scott Wiltamuth, Peter Golde; The C# Programming Language > > Box, Sells; Essential .NET > > Stephen Teilhet, Jay Hilyar; C# Cookbook; (O'Reilly) > > Peter Drayton, et al; C# in a Nutshell; (O'Reilly) > > J Richter; Applied Microsoft .NET Framework Programming > > Windows Forms > ============= > > Chris Sells; Windows Forms Programming in C# > > Matthew MacDonald; User Interfaces with C SHARP: Windows Forms and Custom Controls > > ASP.NET > ======= > > Jesse Liberty, Dan Hurwitz; Programming ASP.NET > > Fritz Onion; Essential ASP.NET with Examples in C# > > N. Kothari; Developing ASP.NET Server Controls and Components > > ADO.NET > ======= > > D. Sceppa; Microsoft ADO .NET (Core Reference) > > Misc > ==== > > R. Jeffries; Extreme Programming Adventures in C# > > I see Petzold is soldiering on, too :-/ > > ely > -- > http://mail.python.org/mailman/listinfo/python-list > From jack at performancedrivers.com Thu Aug 12 21:59:45 2004 From: jack at performancedrivers.com (Jack Diederich) Date: Thu, 12 Aug 2004 21:59:45 -0400 Subject: Why I love python. In-Reply-To: <411c09aa$1@nntp.zianet.com> References: <411c09aa$1@nntp.zianet.com> Message-ID: <20040813015945.GO23725@performancedrivers.com> On Thu, Aug 12, 2004 at 08:22:01PM -0400, Mark Bottjer wrote: > Michael Scarlett wrote: > >I don't know about the rest of you, but I learned python and fell in > >love with its syntax and simplicity. > > That's the funny thing about Python. It really isn't simple, but it sure > seems like it is. There's tons of little niggling rules about scoping, > inheritance, and what have you--but you can be blissfully ignorant of > most of them and still get work done. That's pretty unique. > > I think that's why people are so concerned about @pie: it has the > *potential* to be an obstacle early in the learning process, instead of > after someone is already hooked. > Agreed, python isn't simple and those hidden things are actually useful for getting real work done. I've been using python industrially for three years and I'm a big fan of decorators; decorators would help me get things done. I liked the look of [decorators] before colon option more, but the current situation of def foo(a,b,c): # # 60 lines of code here # foo = mutate(foo) # oh, and by the way the 'def foo' # signature might be misleading 'foo = mutate(foo)' It is boilerplate, python is nice because it eschews boilerplate. While the decorator syntax might not be obvious to newbies they won't see it in simple code. When then do see it having @mutate right next to the func def has to be more of a clue than 'foo=mutate(foo)' lines or screens away. -Jack From davidf at sjsoft.com Tue Aug 24 04:54:02 2004 From: davidf at sjsoft.com (David Fraser) Date: Tue, 24 Aug 2004 10:54:02 +0200 Subject: advice for perl expert wanting to learn python In-Reply-To: <6d668d6.0408231452.44e2d14f@posting.google.com> References: <6d668d6.0408231452.44e2d14f@posting.google.com> Message-ID: Keith Farmer wrote: > David Fraser wrote in message news:... > >>Zeljko Vrba wrote: > > >>>And most important thing, how does Python deal with database connectivity? >>>Is there a single API (akin to DBI) for connecting to databases? > > >>I have used Oracle, SQLServer and Access via ADO - try adodpapi.sf.net >>which is a wrapper for ADO to the Python DB-API. >>But note that you may well not be able to use any of this database stuff >>from IronPython > > > Assuming you find yourself working with .NET -- as you would with > IronPython -- I would expect it to have access to the stock database > namespaces under whatever environment you're in: under MS's > implementation of .NET, System.Data.* (same under Mono?). This would > be the most likely line, since there's a lot of prior work in .NET > that targets that namespace, including UI controls. > > For documentation, search for "ADO.NET". It's actually a pretty good > framework, and doesn't require a database connection to make use of it > (ie, you want an in-memory database, but don't need persistent > storage). > > I don't know what Jim's planning to do with the Python db api, but > between the two, I'd personally use ADO.NET when available. I'd > suggest the IronPython email list (www.ironpython.org) for more > information. The disadvantage of using ADO.NET is that you'll lose the portability advantages of the Python db API (i.e. you'll only be able to use the code on IronPython). The correct approach is to write a DB API-compatible wrapper for ADO.NET :-) (as has been done for ADO) David From Jared.Cohen at noaa.gov Fri Aug 20 13:37:21 2004 From: Jared.Cohen at noaa.gov (Jared Cohen) Date: Fri, 20 Aug 2004 13:37:21 -0400 Subject: Fate of lambda, Functional Programming in Python... Message-ID: <412636D1.6070808@noaa.gov> Agreed! I'm currently building a GUI in Tkinter, with event handlers and callbacks all over the place. The lambda form is an absolute MUST for this kind of thing! -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin at v.loewis.de Fri Aug 6 04:39:51 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 06 Aug 2004 10:39:51 +0200 Subject: Proposal: require 7-bit source str's In-Reply-To: References: <4112AC7B.1060508@v.loewis.de> Message-ID: <411343D7.3020604@v.loewis.de> Hallvard B Furuseth wrote: > Well, I don't think that's better, but if it's rejected for Python > that'll be my next stop. I can see how the global warning is provided (which then can be configured into an error through the warnings module). However, I don't want to introduce additional magic comments. I already dislike the coding declarations for being comments, and would have preferred if they had been spelled as directive encoding "utf-8" The coding declaration was only acceptable because - a statement would have to go before the doc string, in which case it would not have been a docstring anymore, and - there was prior art (Emacs and VIM) for declaring encodings to editors, inside comments Your proposed annotation has no prior art. As it has effects on the syntax of the language, it should not be in a comment. Regards, Martin From dennis.benzinger at gmx.net Thu Aug 26 07:22:22 2004 From: dennis.benzinger at gmx.net (Dennis Benzinger) Date: 26 Aug 2004 04:22:22 -0700 Subject: Call for signatories for J2 References: Message-ID: <3734459e.0408260322.3dd9ae06@posting.google.com> I vote FOR J2. Dennis Benzinger From rnichol_rrc at yahoo.com Tue Aug 17 12:16:15 2004 From: rnichol_rrc at yahoo.com (Reid Nichol) Date: Tue, 17 Aug 2004 11:16:15 -0500 Subject: Python secure? In-Reply-To: References: <2xXTc.3775$bJ2.24876@news1.mts.net> Message-ID: Terry Reedy wrote: >>And what language is Python programmed in... oh yah, C. Perhaps people >>shouldn't talk about how poorly secure C and then go off to how secure >>Python is when Python is written in C. Houses built on sand... > As we both said, C is safer in the hands of expert, experienced, careful > programmers. People like you claim to be and people like Guido and Tim > Peters. They program in C so we have less need to. And I am grateful for > that. > > Terry J. Reedy If you read what I wrote you would've found that I recommended learning with Python and then deciding which programming language suited the project the best. If you read what I wrote you would've found that I was defending C in general terms and *not* in context of a beginner programmer. And I'll leave the rest of you snide remarks along for I won't lower myself to such things. From peter at engcorp.com Sat Aug 21 00:00:59 2004 From: peter at engcorp.com (Peter Hansen) Date: Sat, 21 Aug 2004 00:00:59 -0400 Subject: Why are strings immutable? In-Reply-To: References: Message-ID: Brent W. Hughes wrote: > I kind of hate to have to convert a string into a list, manipulate it, and > then convert it back into a string. Why not make strings mutable? It is unlikely you are doing whatever it is you need to do in the best way possible if you are converting to a list and back. What's the use case here? Can you describe what you need to accomplish without reference to how you think it should be accomplished? Maybe there's a better way... -Peter From steven.bethard at gmail.com Tue Aug 31 15:56:44 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Tue, 31 Aug 2004 19:56:44 +0000 (UTC) Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: I wrote: > What you're suggesting is that given: > > def f1(): > __author__ = 'Steve' > > and > > def f2(): > author = 'Steve' > > in f1, the assignment to __author__ occurs in the function's namespace, but > in f2, the assignment to author occurs in the local namespace. Clearly > then, the __xxx__ format (if at the beginning of a function) changes the > namespace to which an assignment applies. Note that the parallel for classes would be if, given: class F1: __author__ = 'Steve' and class F2: author = 'Steve' that the __author__ assignment in F1 occured in one namespace, while the author assignment in F2 occured in another namespace. (Something like __author__ only being available from the class object, while author was only available from class instance objects.) Python could almost certainly be treat __xxx__ variables to work this way, but it's not the way it works *now*. This is why I say that you're introducing a totally new semantics to __xxx__ assignments. Steve From bokr at oz.net Sat Aug 7 19:50:47 2004 From: bokr at oz.net (Bengt Richter) Date: 7 Aug 2004 23:50:47 GMT Subject: @decorator syntax is sugar, but for what exactly? Message-ID: ISTM that @limited_expression_producing_function @another def func(): pass is syntactic sugar for creating a hidden list of functions. (Using '|' in place of '@' doesn't change the picture much (except for people whose tools depend on '@' ;-)). I.e., (not having the source or time to delve) the apparent semantics of the above is something roughly like __funclist__ = [] __funclist__.append(limited_expression_producing_function) __funclist__.append(another) def func():pass while __funclist__: func = __funclist__.pop()(func) del __funclist__ Is this a special case of a more general idea? E.g., could it apply to right after ANY next name is bound, in general, not just a name bound by def? thus (untested) def censor(cls): cls.__repr__ = lambda self: '' return cls ... @censor class C(object): pass could have the expected effect (after metaclass effects, if any, presumably, BTW) (note that censor could instead e.g. wrap selected methods or add class variable data etc., though IIRC __metaclass__ can create some things that are read-only later) This is still very narrowly defined by prefix context. Is this context also a special case default of something more general? IOW the default choice for namespace is the lexically enclosing one. What about, e.g., being able to specify decoration in one place at the top of a module and decorate (in the same way, using the same function list) all methods of a specified (by name) list of classes? I.e., a more general control over what to do when what names are bound in what namespace could be envisaged. This begins to feel like event-driven processing. Could @deco1 @deco2 be sugar for the special case (don't take this literally, just illustrating semantics ;-) when(event='next_binding', namespace='immediate', symbols='any', funclist=(deco1,deco2)) def foo(): pass of something general that could also include other and possibly repeated events like on completion of an arg list for a particular function or method being called or any rebinding of particular symbols in a specified namespace (not just the immediate one), e.g., for debugging or profiling etc. Since I am copying this to python-dev, I'll re-ask whether @decorator has any peculiar thread safety pitfalls that should be warned against, just in case. Please take this as a probe into the intended semantics, not as a proposal for any particular functionality ;-) Regards, Bengt Richter From simoninusa2001 at yahoo.co.uk Tue Aug 24 17:26:02 2004 From: simoninusa2001 at yahoo.co.uk (Simon John) Date: 24 Aug 2004 14:26:02 -0700 Subject: Begginers questions on different distributions of py Message-ID: As I recall, the AS version includes win32all The main difference is that the AS version doesn't require Admin access (at least that's how the Solaris version differed). Personally I always use the more up-to-date official versions from www.python.org From dai4happy at yahoo.com Tue Aug 3 21:47:56 2004 From: dai4happy at yahoo.com (angel) Date: Wed, 4 Aug 2004 09:47:56 +0800 Subject: Does python support multi prototype. Message-ID: <2natmnFv86rjU1@uni-berlin.de> Hi Java and cpp support one function name multi function prototype. For example: A: int func1(String s){} int func1(int i){} B: int func1(String s){} int func1(String s, int i){} Does python support it? Thanx From ajsiegel at optonline.com Tue Aug 24 09:09:56 2004 From: ajsiegel at optonline.com (Arthur) Date: Tue, 24 Aug 2004 13:09:56 GMT Subject: __name__ becoming read-write? References: <3b8ki0tlphodtt8ge8an274qp78ihp1i3n@4ax.com> Message-ID: <8cdmi0dipgk5192li1p8mm2n1hls2hs7rl@4ax.com> On Tue, 24 Aug 2004 14:27:15 +1000, Anthony Baxter wrote: >On Mon, 23 Aug 2004 23:17:25 GMT, Arthur wrote: >> > "So wait, this stuff that _looks_ like code in a >> >function, isn't actually? what the hell?" The new syntax[1] for >> >decorators is at least very obvious that something _new_ is going on. >> >> I am thinking (and I think Paul is thinking) that we can say the same >> thing, succintly, in a manner that has precedence in the language >> >> Mine's a one-liner that does not totally relieve the magicians burden >> to be - somwhere down the line - a bit expressive > >I'm not _quite_ sure what it is you're asking for here, but it _seems_ >like you want to have two different blocks inside a def - the first is >the meta-block, which contains docstrings and other magic attributes, >while the second is the actual code body? Is this correct? If this is >the case, I think it's _possible_ that in the future we might see >something like this, for typing purposes. Maybe. I'm not sure. But if >we do, I can't see any point _at_ _all_ to signifying magic things >with arbitrary words surrounded with __under__ meaning 'under is a >decorator'. While Python does use __foo__, the list of values for foo >that are meaningful is well described and documented. All I think I am looking for is proportionality. The solution should be proportional to the problem. The current syntax is expressive in the way that, I thought, was always considered to be fundamental to the concept of Pythonic. What is happening is no more and no less than what is obvious from the code to someone who may have never studied the Python documentation, but who is simply generally literate. The problems identified with the current syntax is: 1) the placement of the transformative code under the function - leading to a purely hypothetical problem - I am not aware of any reports of acutal issues arising - of a reader missing important information related to the function. 2) burdensome amounts of typing when dealing with long function names. If Python needs to apologize for being itself in the limited circumstances that give rise to these conditions, perhaps it can be done with a bit more - I don't know - dignity. Which would involve recognizing the issues as minor annoyances, and providing some limited relief. I am though concluding that , if anything, tmy own suggestion goes further than it should. No __under__ is necessary. We have #comment for the developer to commnicate anything he needs to communicate about the function from within the function. And in those cases where the developer's editor's cut and paste facility are on the fritz and they are dealing with 70 letter function names, you have given them a writeable __name__ attribute as another weapon to solve their issue. No it won't solve everything. But then there isn't that much to be solved. The solution of fixing these limtied annoyances by redefining good Python decoding style to include and encourage magic declarations that can only be meaningful to a studied Pythoneers, is totally out of left field, IMO. The shifting sands have and will have their own costs. IMO, here those costs are substantial. The hundreds of arguments that have gone on here on python-list, with Python explaining itself and defending itself, will have to be restated. Because the Zen no longer holds as nearly as true, and there becomes little left to distinguish Python as a programming apporach. For those who think that Python's future is - perhaps - *the* CLR language, and that this kind of redefintion of the language is a necessary step in the direction that will make that kind of thing possible, I would say - not in my shop. Art Art From calidusdk at hotmail.com Mon Aug 23 08:12:30 2004 From: calidusdk at hotmail.com (Artemisio) Date: 23 Aug 2004 05:12:30 -0700 Subject: line shift? (baby steps 2) Message-ID: <6daa8765.0408230412.6db365d6@posting.google.com> I have done a small currency calculator. It works and I'm very glad. But...I'd like to have a line shift if user types a wrong choice. Please, look at the code and output example down here: # -*- coding: ISO-8859-1 -*- import string eudk_currency= 7.47 dkeu_currency= 0.13 usdk_currency= 5.93 dkus_currency= 0.16 euus_currency= 1.19 useu_currency= 0.78 currency_choice= raw_input("Please type DK if you want convert to DKK, EU if you want to convert to ?: ") currency_str= str(currency_choice).upper() while currency_str != "EUDK" and currency_str != "DKEU" and currency_str != "USDK" and currency_str != "DKUS"\ and currency_str != "EUUS" and currency_str!= "USEU": currency_choice= raw_input("Sorry. At the moment we only support DKK, Euro and Dollars." + "\n" \ "Type DKEU if you want convert from DKK to ?," + "\n" \ "EUDK if you want to convert from DKK to ?," + "\n" \ "DKUS if you want to convert from DKK to $," + "\n" \ "USDK if you want to convert from $ to DKK," + "\n" "EUUS if you want to convert from ? to $," + "\n"\ "and USEU if you want to convert from $ to ?: ") currency_str= str(currency_choice).upper() amount_int= input("Please type the amount you wish to convert: ") if currency_str == "DKEU": result= amount_int* dkeu_currency print amount_int, "Danish Crowns correspond to", result, "Euro." if currency_str == "EUDK": result= amount_int* eudk_currency print amount_int, "Euro correspond to", result, "Danish Crowns." if currency_str == "USDK": result= amount_int* usdk_currency print amount_int, "Dollars correspond to", result, "Danish Crowns." if currency_str == "DKUS": result= amount_int* dkus_currency print amount_int, "Danish Crowns correspond to", result, "Dollars." if currency_str == "EUUS": result= amount_int* euus_currency print amount_int, "Euro correspond to", result, "Dollars." if currency_str == "USEU": result= amount_int* useu_currency print amount_int, "Dollars correspond to", result, "Euro." #CODE END OUTPUT: Please type DK if you want convert to DKK, EU if you want to convert to ?: sdsd Sorry. At the moment we only support DKK, Euro and Dollars. Type DKEU if you want convert from DKK to ?, EUDK if you want to convert from DKK to ?, DKUS if you want to convert from DKK to $, USDK if you want to convert from $ to DKK, EUUS if you want to convert from ? to $, and USEU if you want to convert from $ to ?: usdk Please type the amount you wish to convert: 99 99 Dollars correspond to 587.07 Danish Crowns. How do I get a line shift before (and/or) after the "Sorry....At the moment"), so the output is something like: Please type DK if you want convert to DKK, EU if you want to convert to ?: sdsd Sorry. At the moment we only support DKK, Euro and Dollars. Type DKEU if you want convert from DKK to ?, EUDK if you want to convert from DKK to ?, DKUS if you want to convert from DKK to $, USDK if you want to convert from $ to DKK, EUUS if you want to convert from ? to $, and USEU if you want to convert from $ to ?: usdk Please type the amount you wish to convert: 99 99 Dollars correspond to 587.07 Danish Crowns. OR Please type DK if you want convert to DKK, EU if you want to convert to ?: sdsd Sorry. At the moment we only support DKK, Euro and Dollars. Type DKEU if you want convert from DKK to ?, EUDK if you want to convert from DKK to ?, DKUS if you want to convert from DKK to $, USDK if you want to convert from $ to DKK, EUUS if you want to convert from ? to $, and USEU if you want to convert from $ to ?: usdk Please type the amount you wish to convert: 99 99 Dollars correspond to 587.07 Danish Crowns. ??? Thank you for your patience! :-) From skip at pobox.com Wed Aug 18 12:27:47 2004 From: skip at pobox.com (Skip Montanaro) Date: Wed, 18 Aug 2004 11:27:47 -0500 Subject: age of Python programmers In-Reply-To: References: Message-ID: <16675.33667.465603.851850@montanaro.dyndns.org> Dave> Python fits my brain. I agree. This gets my nod for QOTW. Skip From prabhu at aero.iitm.ernet.in Mon Aug 16 00:34:47 2004 From: prabhu at aero.iitm.ernet.in (Prabhu Ramachandran) Date: Mon, 16 Aug 2004 00:34:47 -0400 Subject: Trouble with file.seek/file.tell on Win32? In-Reply-To: <1f7befae04081512496c6f2727@mail.gmail.com> References: <16671.45400.965715.943437@enthought.hathway.com> <1f7befae04081512496c6f2727@mail.gmail.com> Message-ID: <16672.14695.671538.635569@enthought.hathway.com> Hi, Many thanks for taking the time to respond. >>>>> "TP" == Tim Peters writes: TP> [Prabhu Ramachandran] >> I noticed peculiar behavior under Python-2.3.4 under Win32. >> When I run something like this: >> >> f = open('t.txt', 'wb') f.write('1\012'+'2\012'+'3\012') >> f.close() f = open('t.txt', 'r') TP> Sorry, you're in trouble already. You can *tell* Windows TP> that's a text file, but it doesn't contain native Windows TP> text-file data (it has the wrong kind of line end for TP> Windows). Yes, I was aware of that, files with the right line endings did work fine. I was not aware that files with the wrong line endings under Win32 could break tell and seek. Here is what happened. I was building a self-extracting installer for a CVS snapshot of MayaVi (using Gordon McMillan's installer). The file in question is a MayaVi visualization file. This is parsed to generate a visualization. I use file.tell and file.seek to handle some backwards compatibility issues (its an ugly hack but works). The file in question has not changed in years and used to work fine when I built the installer last time. What I did not realize is that the file that is distributed with the previous installer had the right line endings! Here is the wierd part. I work primarily on Linux and build a zip and tarball using distutils. I take the zip file to a windows box and have setup scripts to do bulk of the dirty work. It has worked just fine in all previous attempts (on different machines with earlier versions of Python). This time I setup a Windows XP machine with all the software. I got the ZIP file I just built, unzipped it, and tried to load the example visualization and it failed. For some reason the line endings were not converted this time around. I had no explanation as to why that happened. I suspected that it was the line endings under windows. Since neither the files or *my* scripts had changed in any way to touch line endings, I suspected it was a bug with the way Python handled the line endings this time. It was not distutils either since the MayaVi-1.3.zip file at sourceforge also has the unix style file. So I assumed that since nothing relevant had changed with my sources and scripts it must be Python. I was wrong. I now realize that the only significant difference is the unzip utility I used. I used Winzip the last time I built the binaries. A google search reveals that Winzip does indeed convert line endings by default. This time I used the standard WinXP tools to unzip the file and they don't convert line endings. I did not know or suspect that. So, sorry for the false alarm. I'm happy though that the puzzle is solved. I'm happy to also learn that bad line endings break tell and seek. I guess this is a problem on the mac too where lines end with '\r'. Is this true of OSX? Anyway, it looks like I should either simply read and write to the file using the 'rb' and 'wb' modes on all platforms or make sure that line endings in the file are correct on the platform. I should also encourage folks to use unzip utilities with care. [...] Thanks for the detailed example showing that the problem is not with Python. Sorry for the bother. Thanks again. regards, prabhu From com-nospam at ccraig.org Fri Aug 20 15:01:04 2004 From: com-nospam at ccraig.org (Christopher A. Craig) Date: 20 Aug 2004 15:01:04 -0400 Subject: Fate of lambda, Functional Programming in Python... References: <412636D1.6070808@noaa.gov> Message-ID: "Jared Cohen" writes: > Agreed! I'm currently building a GUI in Tkinter, with event handlers and > callbacks all over the place. The lambda form is an absolute MUST for this > kind of thing! Nobody is talking about removing the ability to pass functions, just the actual "lambda" form. You can still build a GUI by doing def spam(stuff): def eggs(parrot): return 5+parrot return eggs You just can't do def spam(stuff): return lambda foo: 5+parrot I can't think of a situation where you _really_ need the second (and much more limited) form. -- Christopher A. Craig "The shortest distance between two points is usually torn up." Frank Walsh From martin at v.loewis.de Fri Aug 27 02:37:56 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 27 Aug 2004 08:37:56 +0200 Subject: What GCC version had defined? In-Reply-To: <412ecb16$1@nntp0.pdx.net> References: <412e39d1$1@nntp0.pdx.net> <412E55A9.9070400@v.loewis.de> <412e70d3$1@nntp0.pdx.net> <412ecb16$1@nntp0.pdx.net> Message-ID: <412ed6c3$0$26150$9b622d9e@news.freenet.de> Scott David Daniels wrote: > The problem is, of course (Billy G is always a problem), that I am running > on Win2K, so I don't run configure.in. I have two copies of MinGW -- > one 2.95 (no stdint.h), and one 3.2.3 which does do stdint.h. > These were not set up when whoever built windows 2.3.4 did so -- he or > she did not know what was going to be on my disk after I downloaded and > installed python. Can you please explain what the problem is that you are trying to solve? Apparently, it is not compiling Python. If you are trying to compile a Python extension, can't you just check for presence of /usr/include/stdint.h in setup.py? But then, if you are compiling an extension - why do you even *need* to know whether stdint.h is present? Regards, Martin From lconrad at laymusic.org Fri Aug 6 13:36:52 2004 From: lconrad at laymusic.org (Laura Conrad) Date: Fri, 06 Aug 2004 13:36:52 -0400 Subject: Killing children Message-ID: <87smb0w4ln.fsf@debian.laymusic.org> I'm writing an application that has to spawn some processes and then kill them later. It doesn't need to talk or listen to them while they're running, but there are stop and start buttons and the stop button should stop everything that gets started by the start button. There are lots of ways to do this on Linux, but this project has to run under cygwin. So far, the only thing I've gotten to work at all under cygwin is doing an 'os.system' to start the process and then parsing the "ps" output and using os.kill on the processes that ps finds. This is unsatisfactory in a number of ways. I have been unable to get os.spawnl to start the processes correctly. I was using pexpect, which worked fine with test programs, but not with the actual processes that need to be spawned. I did a little bit of playing with the "process" module but didn't get it working right. Does anyone have a better idea? -- Laura (mailto:lconrad at laymusic.org , http://www.laymusic.org/ ) (617) 661-8097 fax: (501) 641-5011 233 Broadway, Cambridge, MA 02139 From greg at cosc.canterbury.ac.nz Thu Aug 19 22:31:58 2004 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Fri, 20 Aug 2004 14:31:58 +1200 Subject: My only complaint about Python In-Reply-To: References: Message-ID: <2ol650Fbr791U1@uni-berlin.de> David Fraser wrote: > I agree. I don't mind it being built with Visual Studio, but out of the > box mingw compatibility would be cool... As a step towards this, it would be useful if it were distributed with the libpythonXX.a that mingw requires already built. Then it would just be a matter of giving the appropriate flag to setup.py when compiling a module. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From whereU at now.com Mon Aug 16 22:16:15 2004 From: whereU at now.com (Eric Pederson) Date: Mon, 16 Aug 2004 18:16:15 -0800 Subject: music resources Message-ID: <20040816181615.1126066215.whereU@now.com> > Elaine Jackson wrote: > > Is there such a thing as an executable language for music? If not, why > > not? And > > if yes, where can I find it? Naturally the ideal thing would be if > > such a > > language were implemented within python, but I would be willing to > > learn a > > lesser programming language if I had a reasonable assurance that it > > had what I'm > > looking for. There is some interesting stuff out there: Check out the Python sounds project: http://pythonsound.sourceforge.net/ Also, there is AthenaCL which I believe is both written in Python and Python scriptable, although I have not had time to play with it: http://www.download.com/AthenaCL/3000-2170-10204823.html I think there are also more routine libraries that just manipulate sound waves, etc. What do you want to do with music? (talk about an interesting data set!) Eric P. Eric Pederson http://www.songzilla.blogspot.com ::::::::::::::::::::::::::::::::::: domainNot="@something.com" domainIs=domainNot.replace("s","z") ePrefix="".join([chr(ord(x)+1) for x in "do"]) mailMeAt=ePrefix+domainIs ::::::::::::::::::::::::::::::::::: From pwilkinson at videotron.ca Fri Aug 6 16:18:02 2004 From: pwilkinson at videotron.ca (Peter Wilkinson) Date: Fri, 06 Aug 2004 16:18:02 -0400 Subject: unicode to ascii converting In-Reply-To: <4113DFF9.3090104@v.loewis.de> References: <4113DFF9.3090104@v.loewis.de> Message-ID: <6.0.3.0.0.20040806155726.01b180e0@pop.videotron.ca> thanks for the clear explanation. I modified my code and now this works :) Peter At 03:46 PM 8/6/2004, Martin v. L?wis wrote: >Peter Wilkinson wrote: >>UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: >>ordinal not in range(128) > >That error actually says what happened: You have the byte with the numeric >value 0xff in the input, and the ASCII (American Standard >Code for Information Interchange) converter cannot convert that >into a Unicode character. This is because ASCII is a 7-bit character >set, i.e. it goes from 0..127. 0xFF is 255, so it is out of range. > >Now, the line triggering this is > > bz_file_out.write(line.encode(new_encode)) > >and it invokes *encode*, not *decode*. Why would it give a decode error >then? > >Because: > > decode: take a byte string, return a Unicode string > encode: take a Unicode string, take a byte string > >So line should be a Unicode string, for .encode to be a meaningful thing >to do. Unfortunately, Python supports .encode also for byte strings. >If new_encode defines a character encoding, this does > >class str: > def encode(self, encoding): > unistr = unicode(self) > return unistr.encode(encoding) > >So it first tries to convert the current string into unicode, which >uses the system default encoding, which is us-ascii. Hence the error. > >HTH, >Martin >-- >http://mail.python.org/mailman/listinfo/python-list From jbperez808 at yahoo.com Wed Aug 18 09:24:36 2004 From: jbperez808 at yahoo.com (Jonathan P.) Date: 18 Aug 2004 06:24:36 -0700 Subject: generating uuids / guids References: <2nhnrfF13jq0U1@uni-berlin.de> Message-ID: aahz at pythoncraft.com (Aahz) wrote in message news:... > Sure it would. Best way to start is to create a stand-alone third-party > library that implements the full DCE spec. Once it has proven its > utility and stability, send a note to python-dev suggesting that it be > added. > > Keep in mind that UUID generation is a somewhat complex and tricky > business will likely require some kind of C library support (to get the > MAC address, to check if there's already a system-level UUID/GUID > generator present, to provide a "good" UUID if there's no network card, > and so on). Aren't there already uuid generation routines in both Linux and Windows and wouldn't all that's needed be to wrap them in Python? From jdhunter at ace.bsd.uchicago.edu Mon Aug 9 09:18:09 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Mon, 09 Aug 2004 08:18:09 -0500 Subject: Barcode Layout In-Reply-To: <41121B77.8030405@cenix-bioscience.com> (Aaron Bingham's message of "Thu, 05 Aug 2004 13:35:19 +0200") References: <4110CA81.6060706@cenix-bioscience.com> <41121B77.8030405@cenix-bioscience.com> Message-ID: >>>>> "Aaron" == Aaron Bingham writes: Aaron> One thing about piddle that's a good fit for our needs is Aaron> that we can add methods to the canvases e.g. drawBarcode() Aaron> just by adding that method to our backends. Is there any Aaron> easy way to add such high-level drawing commands in Aaron> matlibplot that are passed down to the backend level? It is certainly possible - it is easy to access the figure canvas and then call canvas.whatever(). Here is a brief example import matplotlib matplotlib.use('MyBackend') from matplotlib.matlab import * # issue some plot commands; these will render to your backend plot(blah, blah) # this is the MyBackend canvas, which derives from # matplotlib.backend_bases.FigureCanvas canvas = get_current_fig_manager().canvas canvas.my_special_method() # do some custom rendering Whether this is desirable is another question, because then the output will be backend specific. I would encourage you, where possible, to design the barcodes using matplotlib primitives in a function or class, and then any backend will render them the same. JDH From martindemello at yahoo.com Mon Aug 30 09:16:06 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Mon, 30 Aug 2004 13:16:06 GMT Subject: Generator expressions v/s list comprehensions References: <1gj8y77.6qshr41q531veN%aleaxit@yahoo.com> <8fSdnXPuTtTjv67cRVn-ug@powergate.ca> Message-ID: Peter Hansen wrote: > A small correction: > > Martin DeMello wrote: > > > Here's a simple example > > > > linecount = sum(1 for line in file) > > linecount = sum([1 for line in file]) > > > > The former requires an in-memory list equal to the size of the file. > ^^^^^^ > I think you meant "the latter"... Oops - I did indeed. martin From squirrel at WPI.EDU Sun Aug 1 18:47:34 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Sun, 1 Aug 2004 18:47:34 -0400 Subject: Microbenchmark: Summing over array of doubles In-Reply-To: References: <4d642979.0407312049.7a8aecab@posting.google.com> Message-ID: On 1 Aug 2004, Duncan Booth wrote: > I just had a brief look at the code you posted. Are you not concerned about > accuracy in any of your calculations? Summing a 10 million element array by > simply accumulating each element into a running total is guaranteed to give > a lousy result. Lousy or not, I believe that's how numarray is implemented internally, so at least all the benchmarks are the same. If you want accuracy summing that many numbers, you're going to have to do it in software (likely by summing each mantissa bit individually and reconstructing the float afterward), so it will be abysmally slow (obviously not what the OP wants). From martin at v.loewis.de Fri Aug 6 04:34:34 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 06 Aug 2004 10:34:34 +0200 Subject: [Python-Dev] RELEASED Python 2.4, alpha 2 In-Reply-To: References: <411231C8.3020308@interlink.com.au> Message-ID: <4113429a$0$26993$9b622d9e@news.freenet.de> Vincent Wehren wrote: > What surprised me a little is that on Win XP I could install 2.4a2 as a user > with restricted rights over a previously administrator-installed > for-all-users 2.4a1 standard-paths-used installation without > warnings/problems - well, except for the obvious errors writing to the > registry (and yes, I tried it intentionally ;). I am not entirely on board > with the MSI's capabilities, but is there a way to tell the user (before the > registry errors happen), that he/she may have insufficient rights to > install? I'm not quite sure I understand what you were doing, and in what way this has surprised you. It seems - you made a per-machine installation as the administrator - you then upgraded as a restricted user (not being asked whether this is going to be per-user or per-machine) What *should* have happened is this: - MSI finds that the new installation is per user, and the old installation is per-machine, so no upgrade is possible - the UI then tells you that the target directory already exists, and wants confirmation - if you proceed, it overwrites the existing files, creating a per-user installation (i.e. shortcuts in your profile, registry keys in HKEY_CURRENT_USER) Are you saying that somebody else has happened instead? If not, in what way did that surprise you? Regards, Martin From lconrad at laymusic.org Sat Aug 7 22:05:14 2004 From: lconrad at laymusic.org (Laura Conrad) Date: Sat, 07 Aug 2004 22:05:14 -0400 Subject: Killing children References: <87smb0w4ln.fsf@debian.laymusic.org> <87d624vxt2.fsf@debian.laymusic.org> <87pt62vgk7.fsf@debian.laymusic.org> <070820041850214353%JBrouwersAtProphICyDotCom@no.spam.net> Message-ID: <87llgqv0yt.fsf@debian.laymusic.org> >>>>> "Jean" == Jean Brouwers writes: Jean> It looks like there is no space left to fork the subprocess and Jean> load/map the libraries the latter needs. Jean> Maybe there too many processes running already, simultaneously? But if that was it, rebooting would have fixed it, wouldn't it? -- Laura (mailto:lconrad at laymusic.org , http://www.laymusic.org/ ) (617) 661-8097 fax: (501) 641-5011 233 Broadway, Cambridge, MA 02139 From jonathon.blake at gmail.com Mon Aug 30 23:08:24 2004 From: jonathon.blake at gmail.com (Jonathon Blake) Date: Mon, 30 Aug 2004 20:08:24 -0700 Subject: Non-unicode strings & Python. Message-ID: All: Question Python is currently Unicode Compliant. What happens when strings are read in from text files that were created using GB 2312-1980, or KPS 9566-2003, or other, equally obscure code ranges? The idea is to read text in the file format, and replace it with the appropriate Unicode character,then write it out as a new text file. [Trivial to program, but incredibly time consuming to actually code] xan jonathon -- Goto http://graphology.meetup.com for information about International Graphology Meetup Day From jerf at jerf.org Sat Aug 28 16:47:19 2004 From: jerf at jerf.org (Jeremy Bowers) Date: Sat, 28 Aug 2004 20:47:19 GMT Subject: Generator expressions v/s list comprehensions References: <1gj8y77.6qshr41q531veN%aleaxit@yahoo.com> Message-ID: On Sat, 28 Aug 2004 14:09:34 -0600, Mahesh Padmanabhan wrote: > Is returning a list really a limitation considering that lists can be > transformed quite easily? http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/190465 It is trivial to generate huge lists and more people need them than you might think. Not choking the VM system with multi-hundred megabytes in allocations is a non-trivial performance advantage, especially as the alternative may be not finishing at all. You, by the way, have it backwards. It is trivial to convert a generator into a list, without advantage loss. The opposite is not possible. That's why Alex, elsewhere in the newsgroup, is saying list comprehensions might someday be replaced by list(x for x in whatever), but you're never going to see him say generator expressions are adequately captured by iter([x for x in whatever]). From python-url at phaseit.net Tue Aug 31 16:08:07 2004 From: python-url at phaseit.net (Peter Otten) Date: Tue, 31 Aug 2004 20:08:07 GMT Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 31) Message-ID: QOTW: "Python is clearly on a huge evolutionary surge and conservative views on the matter are definitely not winning out right now. And the usual argument (submit a patch!) doesn't really work when those who want to avoid many changes try it... I've been *not* submitting a patch on lots of changes to Python, but somehow it's never been accepted. ;-)" Peter Hansen "I've never seen a more complicated, verbose pile of hogwash than the 'deliverd by mailman' mailing list program." Carol Carrot, perhaps innocent of experience with Majordomo and Sendmail Michelle Levesque's PyWebOff annotates the Python-savvy Web frameworks. PEP 333 offers to rationalize a piece of them. http://pyre.third-bit.com/pyweb/index.html http://groups.google.com/groups?th=7f19fe19b40c1be0 How do generator expressions and list comprehensions compare? Experts explain why the former are *better*--OK, better in several, although not all, ways http://groups.google.com/groups?frame=left&th=1d4aca073edaaa2f Jim Hugunin domesticates Python for the Microsoft weltanschaung. http://blogs.msdn.com/hugunin/ http://www.eweek.com/article2/0,1759,1636906,00.asp How does Python regard file systems? It's a timely topic, with pyfmf its most concrete expression. http://groups.google.com/groups?frame=left&th=c379db570ef96c43 http://sourceforge.net/projects/pyfmf http://richard.jones.name/google-hacks/gmail-filesystem/gmail-filesystem.html High-profile Pythoneers Michael Sparks and Alex Martelli demonstrate interests beyond the perfection of the One True Language: petabyte-scale archiving, and marriage. http://www.pcw.co.uk/news/1157046 http://www.aleax.it/mar.html http://bonanna.multiply.com/photos/album/1 Uche Ogbuji reveals his habits for keeping current with Pythonia. http://www.oreillynet.com/pub/wlg/5490 ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous 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 newsgroup weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Brett Cannon continues the marvelous tradition established by Andrew Kuchling and Michael Hudson of intelligently summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Business Forum "further[s] the interests of companies that base their business on ... Python." http://www.python-in-business.org Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donate.html Cetus collects Python hyperlinks. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://aspn.activestate.com/ASPN/Cookbook/Python Among several Python-oriented RSS/RDF feeds available are http://www.python.org/channews.rdf http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi http://python.de/backend.php For more, see http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. *Py: the Journal of the Python Language* http://www.pyzine.com Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. From reinhold-birkenfeld-nospam at wolke7.net Fri Aug 13 06:19:25 2004 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Fri, 13 Aug 2004 12:19:25 +0200 Subject: Why I love python. In-Reply-To: <2o3iboF662nfU1@uni-berlin.de> References: <411C8CD9.32F39C2@mega-nerd.com> <2o3iboF662nfU1@uni-berlin.de> Message-ID: <2o3icnF662nfU2@uni-berlin.de> Reinhold Birkenfeld wrote: > Erik de Castro Lopo wrote: >> Nick Patavalis wrote: >>> >> >> >> >>> Python needs drastic performance improvement if it is to scrap-off the >>> "scripting language" stigma. The only way to get these improvements is >>> making it possible for a python implementation to produce *efficient* >>> *compiled* code. At the same time the dynamic-typing nature of the >>> language is one of its most valuable characteristics. And this is one >>> of the hardest problems when trying to write a decent python >>> compiler. If you define a function like: >>> >>> def sum (a, b): >>> return a + b >>> >>> How can the compiler know what code to produce? >> >> I know of at least one language which has solved this problem, Ocaml >> >> http://www.ocaml.org/ >> >> Its called type inferencing and since there is at least one working >> implementation, it can't be THAT hard. > > Refer to the task "Typed Python" somewhere in the past if you want more > information about Python and Type inferencing. s/task/thread/ Reinhold -- Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows mitbr?chte, w?re das bedauerlich. Was bei Windows der Umfang eines "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk. -- David Kastrup in de.comp.os.unix.linux.misc From tchur at optushome.com.au Mon Aug 23 17:34:15 2004 From: tchur at optushome.com.au (Tim Churches) Date: 24 Aug 2004 07:34:15 +1000 Subject: Python future performance and speed In-Reply-To: References: <278de0e.0408211605.426e5129@posting.google.com> <278de0e.0408220636.3ee25f9d@posting.google.com> <278de0e.0408221450.324e8178@posting.google.com> Message-ID: <1093296855.1269.21.camel@emilio> On Tue, 2004-08-24 at 03:58, Aahz wrote: > That's true. If that's what you'd said in the first place, nobody would > have argued with you. However, this is what you said: > > It seems there are quite a few projects aimed to improve Python's > speed and, therefore, eliminate its main limitation for mainstream > acceptance. Hey, cut the boy/girl some slack. I suspect what s/he meant to say was: It seems there are quite a few projects aimed to improve Python's speed and, therefore, eliminate its main perceived limitation for mainstream acceptance. I think you'll find it much harder to take issue with that statement. I can only offer anecdotal evidence, but a typical conversation about our Python-based projects goes like this (where the conversant typically thinks that there are only two viable languages for any software project these days: C# or Java): a: "What language are you using?" b: "Python" a: "Um, isn't that too slow?" b: "In general, no, and anyway there is a thing which is a bit like a JIT compiler available, and for the really speed-critical parts, you can use C modules very easily." a: "Oh, OK, sound complex." b: "No, it's not, really, and Python is really fast to write." a: "But I have to write all those C modules." b: "No, hardly ever, really." And so on. The **perceived** speed of Python is indeed a barrier to its acceptance, and indignant posts on this list won't do much to dispel that perception. More published case studies and benchmarks of Python versus whatever else when used for **complex**, real-life problems, not artificially simple looping benchmarks, would help. -- Tim C PGP/GnuPG Key 1024D/EAF993D0 available from keyservers everywhere or at http://members.optushome.com.au/tchur/pubkey.asc Key fingerprint = 8C22 BF76 33BA B3B5 1D5B EB37 7891 46A9 EAF9 93D0 From jepler at unpythonic.net Thu Aug 26 22:26:43 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Thu, 26 Aug 2004 21:26:43 -0500 Subject: What GCC version had defined? In-Reply-To: <412e70d3$1@nntp0.pdx.net> References: <412e39d1$1@nntp0.pdx.net> <412E55A9.9070400@v.loewis.de> <412e70d3$1@nntp0.pdx.net> Message-ID: <20040827022642.GB5794@unpythonic.net> I glanced at configure.in and it checks for HAVE_UINTPTR_T, but not HAVE_INTPTR_T. If you want this define where it's available, add the proper test to configure.in and regenerate configure. I think the block would be something like this, a straightforward search-and-replace of the block for HAVE_UINTPTR_T: AC_MSG_CHECKING(for intptr_t support) have_intptr_t=no AC_TRY_COMPILE([], [intptr_t x; x = (intptr_t)0;], [ AC_DEFINE(HAVE_INTPTR_T, 1, [Define this if you have the type intptr_t.]) have_intptr_t=yes ]) AC_MSG_RESULT($have_intptr_t) if test "$have_intptr_t" = yes ; then AC_CHECK_SIZEOF(intptr_t, 4) fi on the other hand, maybe this test is broken, because my system (Fedora Core 2) configured with #undef HAVE_UINTPTR_T. Maybe this article shows the way: http://sources.redhat.com/ml/gdb-patches/2003-02/msg00687.html AC_MSG_CHECKING(for uintptr_t in C library) AC_CACHE_VAL(gdb_cv_have_uintptr_t, [AC_TRY_COMPILE([#include ], [uintptr_t foo = 0; return foo;], gdb_cv_have_uintptr_t=yes, gdb_cv_have_uintptr_t=no)]) AC_MSG_RESULT($gdb_cv_have_uintptr_t) if test $gdb_cv_have_uintptr_t = yes; then AC_DEFINE(HAVE_UINTPTR_T) fi ... with appropriate renaming for Python. I'm not sure why uintptr_t or intptr_t are all that useful, since the spellings "unsigned *" and "int *" are going to work everywhere anyway. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From tzot at sil-tec.gr Fri Aug 13 19:19:41 2004 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Sat, 14 Aug 2004 02:19:41 +0300 Subject: !wtf ellipsis References: Message-ID: On Fri, 13 Aug 2004 14:54:24 +0200, rumours say that Jonas K?lker might have written: >what (the hell) is Ellipsis? >what's it good for? Peter provided a link answering your questions. As a side note, I have used Ellipsis instead of None as a very handy last item put in queues in threaded programs (after all, "ellipsis" means "absence" or "lack" in English :) Thus I avoid creating dummy classes to mark the end of data... -- TZOTZIOY, I speak England very best, "Tssss!" --Brad Pitt as Achilles in unprecedented Ancient Greek From a.clarke11 at ntlworld.com Wed Aug 18 13:54:21 2004 From: a.clarke11 at ntlworld.com (Tony Clarke) Date: 18 Aug 2004 10:54:21 -0700 Subject: age of Python programmers References: Message-ID: <3353cd1e.0408180954.5a7362a8@posting.google.com> "Ben Last" wrote in message news:... > Age 39 (though if I allowed for rounding it'd go up to 40!) > ben > >55, but active with it. I've never taken a programming course but find python indispensable as well as enjoyable. Ciao, Tony (e-mail spammed, do not use) From bjg at network-theory.co.uk Mon Aug 23 12:20:30 2004 From: bjg at network-theory.co.uk (Brian Gough) Date: 23 Aug 2004 17:20:30 +0100 Subject: Bug in string.lstrip? References: <9EoWc.58$A8.18@edtnps89> Message-ID: <877jrpsu5t.fsf@network-theory.co.uk> Brian writes: > Hello - has anyone else had trouble with string.lstrip stripping too > much? Here's what I get (Python 2.3.4): > > >>> import string > >>> string.lstrip("test/one/two/a.b.c", "test/one/") > 'wo/a.b.c' The second argument of lstrip has a different meaning from what you think it does --- see the library documentation for the string module for details. -- Brian Gough Network Theory Ltd, Publishing the Python Manuals --- http://www.network-theory.co.uk/python/ From mediocre_person at hotmail.com Sat Aug 21 21:40:38 2004 From: mediocre_person at hotmail.com (Nick Chackowsky) Date: Sat, 21 Aug 2004 20:40:38 -0500 Subject: Mind.py In-Reply-To: <4127CB0C.E4F49160@alcyone.com> References: <41220b22@news.victoria.tc.ca> <4122796E.9652CCAE@alcyone.com> <4127CB0C.E4F49160@alcyone.com> Message-ID: <4127f9b1$1_2@news.athenanews.com> Erik Max Francis wrote: > threeseas wrote: > > >>Erik Max Francis wrote: >> >> >>>"Arthur T. Murray" wrote: >>> >>> >>>>Now, suppose that you wanted to write an AI in Python that would >>>>implement your mind-model and allow it to grow, mutate, develop. >>>>Here is one possible scenario. >>> >>>http://www.nothingisreal.com/mentifex >> >>its a good thing we all use our minds alike, huh? >> >>Oh wait, so why doesn't Arthur slander or libel himself? > > > It's like an epic battle between Racter and Eliza! > I was *wondering* why this sounded so familiar! From calvin at ironfroggy.com Mon Aug 2 16:07:49 2004 From: calvin at ironfroggy.com (Calvin Spealman) Date: Mon, 02 Aug 2004 20:07:49 +0000 Subject: Q: distutils - name clash protection? References: <410566a5.36996843@news.muenster.de> <200407270852.38652.heikowu@ceosg.de> Message-ID: <1650138.HJVC0sZbrJ@ironfroggy.com> I went ahead and looked at 262 as this thread caught my eye and just wanted to give my two cents: Might be a good idea to not define the format but only the API? Or, at least to specify that while you may count on the API you can not count on exactly how it is implemented? Why duplicate the work done by a system's native package management system(s) if they store the information you need? Though it would definitely be a powerful tool to access this information through a standardized Python API, even for only Python Packages. From paolo_veronelli at yahoo.it Thu Aug 5 09:29:31 2004 From: paolo_veronelli at yahoo.it (paolo veronelli) Date: Thu, 05 Aug 2004 15:29:31 +0200 Subject: RELEASED Python 2.4, alpha 2 In-Reply-To: <411231C8.3020308@interlink.com.au> References: <411231C8.3020308@interlink.com.au> Message-ID: On Thu, 05 Aug 2004 23:10:32 +1000, Anthony Baxter wrote: > On behalf of the Python development team and the Python community, I'm > happy to announce the second alpha of Python 2.4. > Enjoy the new release, This is a bad joke after all the strong perplexities showed about its decorators solution. I vote against the "@decorator before function" solution. Regards Paolino -- ....lotta dura per la verdura From cjw at sympatico.ca Sun Aug 15 08:10:41 2004 From: cjw at sympatico.ca (Colin J. Williams) Date: Sun, 15 Aug 2004 08:10:41 -0400 Subject: Subclassing numarray's arrays In-Reply-To: References: <7pxTc.44307$Mq1.2286665@news20.bellglobal.com> Message-ID: <2pITc.1201$Tr.22124@news20.bellglobal.com> Mizrandir wrote: > First of all, thanks for helping. > > >>Numarray wasn't designed with subclassing in mind, but there are >>workarounds for most problems. > > > On numarray's website there is a paper by the Numarray authors saying: > "... The new approach allows arrays to be subclassed as well as ...", > so I thought it should be something easy to do. I don't remember that, but it is not as dificult as it looks. Just try out the code below, nothing could be simpler than the __init__ method below. The __str__ and __repr__ are just tools which can be used with any subclass. > > Anyway, I hadn't read anything about numarraycore, is it explained > anywhere. For example, I don't understand what the statement > "self.__setstate__(arr.__getstate__())" does. > NumArray creates a number of attributes to provide information about the shape of an array, the data type of its elements and to point to the memory buffer containing the binary data etc. The expression above just transfers the values from arr (which is an instance of NumArray) to self (which is an instance of NewClass). > > >>You might try something like: >>import numarray.numarraycore as _num >>class NewClass(_num.NumArray): >> def __init__(self, n, a): >> ''' n provides the length of each dimension, >> a is the constant value to be plugged. >> ''' >> arr= _num.array(sequence= n * n * [a], shape= (n, n)) >> self.__setstate__(arr.__getstate__()) >> >> def __repr__(self): >> " Return printable representation of instance." >> className= self.__class__.__name__ >> className= className.zfill(5).replace('0', ' ') >> arr= self.copy() >> arr.__class__= _num.NumArray >> rep= className + _num.NumArray.__repr__(arr)[5:] >> return rep >> >> def __str__(self): >> " Return a pretty printed string of the instance." >> stri= self.copy() >> stri.__class__= _num.NumArray >> return _num.NumArray.__str__(stri) >> >> >>if __name__ == '__main__': >> a= NewClass(2, 2) >> print a >> b= NewClass(3, 4) >> print `b` > > > miz. Please let me know if I can provide any further information. numarray is a good tool, but there is a small hurdle if one wishes to subclass. Colin W. From shalabh at cafepy.com Mon Aug 30 16:06:29 2004 From: shalabh at cafepy.com (Shalabh Chaturvedi) Date: Mon, 30 Aug 2004 13:06:29 -0700 Subject: initializing mutable class attributes In-Reply-To: References: <1gjc8cs.sqvo1v1fhabdjN%aleaxit@yahoo.com> Message-ID: Dan Perl wrote: > "Shalabh Chaturvedi" wrote >>In Python you either have an __init__ or you don't. There is no 'default >>constructor' - or if there is, it does nothing. Since attributes can be >>dynamically added to an instance (not just in __init__ but in any >>method), it follows that the standard practice is to initialize instance >>members in __init__ as it is always called before any other instance >>method. Now that there is one way to do a thing, Python avoids the >>introduction of another way (unless it is notably more productive). That >>would lead to a whole set of questions about 'which way is better? >>__init__ or the other way?'. > > > It is a subjective issue indeed. But I'll restrict my question to a simpler > question. By analogy to C++ and Java, why is __init__ not implemented to > automatically invoke the __init__(self) of the parent classes? I'm > beginning to see a reason here, which is that C++ and Java allow you to > overload the constructor and have a default constructor at the same time as > another constructor with arguments. C++ and Java then force you to create a > default constructor for a parent class, even if it's empty, if you create a > non-default constructor for it and you subclass the parent class. > > In contrast, Python does not allow method overloading and I'm OK with that. > It's a simplification that allows using Python in ways that are not possible > with C++ and Java. So Python cannot force you to have a 'default' __init__ > and allow you to have 'non-default '__init__'s at the same time. I am > answering my own question here, but that's OK and it would not have happened > without this discussion. Yes, if the parent class __init__ accepts parameters, how can Python call it automatically? Should it be automatic in some cases and non-automatic in others? (Answer: no, it's too ambiguous). Also what if there are multiple parent classes? As the Quixote folks put it, in the face of ambiguity, refuse the temptation to guess. (Btw, Python's solution for multiple parent classes completely knocks the socks off C++ [1]) Cheers, Shalabh [1] http://www.python.org/2.2.3/descrintro.html#cooperation From steven.bethard at gmail.com Thu Aug 5 12:01:26 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: 5 Aug 2004 09:01:26 -0700 Subject: Confused about pep 318 References: <10h2ihgb8c6fi97@corp.supernews.com> Message-ID: Skip Montanaro wrote in message news:... > > the new syntax will be: > > @onexit > def func(): > ... Wow, this one really feels like it was slipped in while no one was looking. While I don't go to Python conferences, I do occasionally check python-dev, and I totally missed whatever thread introduced the @ syntax. Scary... Not a big fan of this syntax -- no intuitive reason why @ would mean decorator -- but I presume this has already been complained about... Could someone direct me to the discussions about this? I'd like to see why it was the eventual favored syntax... Steve From foo at bar.net Sun Aug 29 20:02:23 2004 From: foo at bar.net (Mac) Date: Sun, 29 Aug 2004 17:02:23 -0700 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <25u2j0d9bfulqljo6d2jbls2v52l1jk3sd@4ax.com> Message-ID: On Sun, 29 Aug 2004 06:58:30 +0000, Brian Inglis wrote: > On Sat, 28 Aug 2004 20:59:08 -0700 in alt.folklore.computers, Mac > wrote: > >>On Wed, 25 Aug 2004 14:56:06 -0700, Xah Lee wrote: >> >>> Larry Wall and Cults >>> (Lazyness, Impatience and Hubris) >>> 200012 > >>> Surely you have heard of Adolf Hitler >>> and his atrocities of genocide? I must alert you, that a single person >>> couldn't commit such a crime. >> >>Wow, Godwin's law invoked on the first post of the thread. > > Not quite, no comparison was made; see: > http://groups.google.com/groups?as_umsgid=1991Oct22.140831.23313%40eff.org Hmm. No explicit comparison was made, but since the post is a cautionary tale (well, the post is a rambling mess, but I think it is trying to be a cautionary tale) I think the comparison is understood. But if the comparison must be explicit, as you seem to be saying, then I have to concede the point. Best regards, Mac From http Wed Aug 25 02:34:25 2004 From: http (Paul Rubin) Date: 24 Aug 2004 23:34:25 -0700 Subject: with as J2 keyword (WAS: Re: J2 0-2-6 is available) References: Message-ID: <7xr7pvsp3i.fsf@ruckus.brouhaha.com> Steven Bethard writes: > @classmethod > @funcattrs(author="Fran??ois Pinard") > def foo(cls): > pass How about double colon instead of @? ::classmethod ::funcattrs(author="Fran??ois Pinard") def foo(cls): pass From mizrandir at hotmail.com Sat Aug 14 13:08:55 2004 From: mizrandir at hotmail.com (Mizrandir) Date: 14 Aug 2004 10:08:55 -0700 Subject: Subclassing numarray's arrays Message-ID: I'd like to subclass numarray's array. I'd like to add some methods and override others like __init__. I don't know how to do this and haven't found help searching the manual or the web, can someone help? For example imagine I just want to do something as simple as making a subclass "NewClass" with the __init__ method overridden so that the behaviour would be: >>> a = NewClass(2) >>> print a [[2 2] [2 2]] How could that be done? Thanks in advance, miz. From adijkstra at baandersconsultancy.nl Mon Aug 16 03:23:40 2004 From: adijkstra at baandersconsultancy.nl (dijk) Date: 16 Aug 2004 00:23:40 -0700 Subject: A email.cgi script References: Message-ID: <25cef294.0408152323.4c01f62a@posting.google.com> wonder wrote in message news:... > Hi, > > I would like to write a python script that can be used in my website for > other people whoever browse my webside to send an email using my smtp > server. Is there any sample python script can do that? > Here is my python script, but it does not display To and From editbox in > the webpage for user type in their addresses: > > #!/usr/bin/python > > import smtplib, cgi, string > > form = cgi.FieldStorage() > > # Change the lines below to specify the TO and > # FROM addresses > > toaddr = 'dest at abc.com' > fromaddr = '' > > # Special form fields used by the email.cgi > # script > > ack_url = form.getvalue('ack_url',None) > ack_text = form.getvalue('ack_text','Your submission was successful') > subject = form.getvalue('subject', '') > > # form fields to skip > to_skip = ['ack_url', 'ack_text', 'subject', 'to'] > > # create the email headers > > msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (fromaddr, toaddr, > subject) I'm using almost the same syntax, but I'm not using '\r\n', only '\n'. Hope this helps.. From fumanchu at amor.org Wed Aug 25 13:15:50 2004 From: fumanchu at amor.org (Robert Brewer) Date: Wed, 25 Aug 2004 10:15:50 -0700 Subject: Capturing exceptions? Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E70@exchange.hqamor.amorhq.net> Dfenestr8 wrote: > What's the easiest way to capture the traceback from an exception, and > write it to a file? Ideally, I'd like to be able to do something like: > > >try: > > main() > >except: > > write the traceback to a file Have a look at the logging module: http://docs.python.org/lib/module-logging.html. Loggers can be a bit complex at first to set up; read the example in the docs (http://docs.python.org/lib/node301.html) and go from there. The upshot is they lead to extremely simple traceback logging: try: shutdown() except Exception: logger.exception("SHUTDOWN") This snippet writes the full traceback to the file. HTH, Robert Brewer MIS Amor Ministries fumanchu at amor.org From lconrad at laymusic.org Sat Aug 7 06:46:22 2004 From: lconrad at laymusic.org (Laura Conrad) Date: Sat, 07 Aug 2004 06:46:22 -0400 Subject: Killing children References: <87smb0w4ln.fsf@debian.laymusic.org> <87d624vxt2.fsf@debian.laymusic.org> Message-ID: <87y8krusxt.fsf@debian.laymusic.org> >>>>> "Dennis" == Dennis Lee Bieber writes: Dennis> p = os.spawnl(os.P_NOWAIT, "/usr/bin/python", "python", "hobo.py", Dennis> '/dev/ttyS0', 5) Dennis> Pardon, I've not checked the details of os.spawnl() Dennis> (or others) but does it translate numeric arguments (the Dennis> 5) to a format usable for argv (if C) command line? Dennis> Maybe the spawned process is dying on its own before you can Dennis> kill it because it wants a quoted '5'? That was it; thanks. -- Laura (mailto:lconrad at laymusic.org , http://www.laymusic.org/ ) (617) 661-8097 fax: (501) 641-5011 233 Broadway, Cambridge, MA 02139 From mwh at python.net Mon Aug 23 11:50:44 2004 From: mwh at python.net (Michael Hudson) Date: Mon, 23 Aug 2004 15:50:44 GMT Subject: Fate of lambda, Functional Programming in Python... References: <20040820163629.8DD4F1E401A@bag.python.org> <4126AAEC.7080304@zephyrfalcon.org> Message-ID: Hans Nowak writes: > Anthony Baxter wrote: > > > First point: lambda, map, filter and reduce won't go away before > > Python 3.0, at the very least. And, to be honest, I suspect > > map/filter/reduce are much more likely to die than lambda, as they > > can nearly always be expressed more clearly as listcomps or > > genexprs. > > People often lump reduce in with the rest, but there's really no easy > way to express a reduce with list comprehensions. You can replace it with a for loop though, and TBH I think the change is usually an improvement. Cheers, mwh -- For their next act, they'll no doubt be buying a firewall running under NT, which makes about as much sense as building a prison out of meringue. -- -:Tanuki:- -- http://home.xnet.com/~raven/Sysadmin/ASR.Quotes.html From javier_ruere at HotPOP.com Fri Aug 20 21:37:47 2004 From: javier_ruere at HotPOP.com (Javier Ruere) Date: Fri, 20 Aug 2004 22:37:47 -0300 Subject: age of Python programmers In-Reply-To: <41234CC0.7030701@bellsouth.net> References: <41234CC0.7030701@bellsouth.net> Message-ID: <4126A76B.1030700@HotPOP.com> Lucas Raab wrote: > One thing I've always kind of wondered is what is the average age of a > Python programmer?? What age groups use Python?? Something to think > about.... I'm 23. Javier From python at elehack.net Fri Aug 6 14:15:52 2004 From: python at elehack.net (Michael Ekstrand) Date: Fri, 6 Aug 2004 13:15:52 -0500 Subject: compromise? keywords for static/class, move decorators to top of function In-Reply-To: References: Message-ID: <200408061315.53194.python@elehack.net> On Friday 06 August 2004 12:54, Doug Holton wrote: > I propose (and others have) that built-in features have keyword > support, like static and class methods. Also, I believe it is more > readable if decorators, especially longer ones, are moved to the top > of the function body, just like docstrings, instead of coming before > the function is even declared. Whether you use @ or [] is still > open. > > def classmethod getratio (arg1, arg2): > @accepts(int,int) > @returns(float) > ... Ooh... I like, I like... This seems to be the most reasonable, readable proposition I've seen so far. And I'd favor @ for this - it makes it clear that this is "something different". -Michael From joeschey at earthlink.net Thu Aug 26 14:37:31 2004 From: joeschey at earthlink.net (Joe S) Date: 26 Aug 2004 11:37:31 -0700 Subject: Dynamic command on Menu items? References: <2e3fe5bf.0408251154.74bc6243@posting.google.com> Message-ID: <2e3fe5bf.0408261037.5d8a2432@posting.google.com> "Diez B. Roggisch" wrote in message news:... > You could do it like this (untested): > > class FunClosure: > def __init__(self, f, args): > self.f = f > self.args = args > def __call__(self): > self.f(self.args) > > M.menu.add_command(label=l, command=FunClosure(f, [p])) Sorry...no work. It says str object is not callable. I would def. appreciate any refinement. If not, thanks anyway for trying. Joe From hodges7 at cox.net Wed Aug 18 22:14:17 2004 From: hodges7 at cox.net (Bill Hodges) Date: Wed, 18 Aug 2004 21:14:17 -0500 Subject: undefined symbol: PyUnicodeUCS4_FromUnicode In-Reply-To: <41204CCE.2090700@v.loewis.de> References: <411c5b24$0$26992$9b622d9e@news.freenet.de> <41204CCE.2090700@v.loewis.de> Message-ID: Martin, Your diagnosis was correct. When I removed the python stuff in /usr and rebuilt everything in /usr/local I finally got DRT to run. Thank you. Bill Martin v. L?wis wrote: > Bill Hodges wrote: > >> Your dianosis is correct. >> I compiled tcl to include UCS4 and >> Python then compiled to UCS4 >> (nm revealed the difference). > > > Are you sure about that? Are you absolutely certain that > the installed Python (/usr/local/bin/python2.3) is UCS-4? > It appears to me that it is likely UCS-2. > >> PyQt compiled fine, However, it >> still errors out the same way. >> For some reason PyQt needs to be told to >> include the UCS4 stuff in qt.so na d >> I cannot find the key. > > > Do you happen to have Python header files both in /usr/include > and /usr/local/include? Make sure PyQt is using the ones in > /usr/local/include, if you plan to use PyQt with that Python > installation. > > Regards, > Martin From cedmunds at spamless.rochester.rr.com Tue Aug 24 22:30:43 2004 From: cedmunds at spamless.rochester.rr.com (Cy Edmunds) Date: Wed, 25 Aug 2004 02:30:43 GMT Subject: python raw strings? References: <412bc766$1@news.unimelb.edu.au> Message-ID: "Maurice LING" wrote in message news:412bc766$1 at news.unimelb.edu.au... > I'm trying to toy around with PLY (python lex-yacc) by David Beazley > from University of Chicago and realized that the lex module uses python > raw strings. What are python raw strings and how are they different from > regular strings? I've tried to look up in the python documentation but > it just vaguely brushes through by saying that python raw strings are > prefixed with "r" or "R". > > In PLY, "+" is "r'\+'" but "-" is "r'-'", why is there an extra "\" in > "+"? When to use the extra "\" and when not? > > Can someone point me in the correct direction? > > Thanks > Maurice http://docs.python.org/lib/module-re.html -- Cy http://home.rochester.rr.com/cyhome/ From sharidas at zeomega.com Fri Aug 13 02:40:44 2004 From: sharidas at zeomega.com (Satchidanand Haridas) Date: Fri, 13 Aug 2004 12:10:44 +0530 Subject: while and if In-Reply-To: <78e89de7f43dc55408bc9891b77d06cc@localhost.talkaboutprogramming.com> References: <78e89de7f43dc55408bc9891b77d06cc@localhost.talkaboutprogramming.com> Message-ID: <411C626C.4070208@zeomega.com> Calvin79 wrote: >Hi Satchit, > >Thankyou for what you've already done, but would you mind if I ask one >last thing and then I'll leave you alone? > >In it's present form the output is fine, but I think I might like to have >it output in this format;['c', 'b', 'a', 'd']. It is probably the most >basic of questions to ask, but heck I've only been at this python stuff a >week... : ) > >Calvin > > > Hi, Change the 'print' line to append to a list: import random things = xrange(int(raw_input("choose no of things (1-8)? "))) state = [None,None] l = [] # new line for x in things: tmp = random.choice('abcd') print state while tmp in state[0:2]: tmp = random.choice('abcd') print "choice ",x+1," is ", tmp l.append(tmp) # new line state[x%2] = tmp print l # new line ---- Satchidanand Haridas (sharidas at zeomega dot com) ZeOmega (www.zeomega.com) Open Minds' Open Solutions #20,Rajalakshmi Plaza, South End Road, Basavanagudi, Bangalore-560 004, India From joshway_without_spam at myway.com Thu Aug 19 09:00:25 2004 From: joshway_without_spam at myway.com (JCM) Date: Thu, 19 Aug 2004 13:00:25 +0000 (UTC) Subject: Embedding Python in Python References: <7xu0v0l2be.fsf@ruckus.brouhaha.com> <7x3c2kkzn8.fsf@ruckus.brouhaha.com> <7x7jrwt8gc.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: ... >> > Hint: >> > e = vars()['__builtins__'].eval >> > print e('2+2') >> >> I don't think it's as difficult as you think. Your snippet of code >> would be rejected by the rules I suggested. You'd also want to >> prohibit other builtins like compile, execfile, input, reload, vars, etc. > I don't see how. Your rules were to disallow: > 1) exec statements. My example doesn't use it. > 2) eval identifier. My example uses eval as an attribute and not an > identifier. You can eliminate the use of eval as an attribute with > e = getattr(vars()('__builtins__'), 'ev'+'al'). > Now not even the string 'eval' appears in one piece. You've used eval an as identifier (at least by the terminology to which I'm accustomed), just not as a variable. > 3) identifiers like __this__. My example doesn't use any. It > uses a constant string of that form, not an identifier. The > string could be computed instead, like the eval example above. > 4) import statements. My example doesn't use them. > Conclusion, my example gets past your suggested rules. I also > didn't use compile, execfile, input, or reload. I did use vars but > there are probably other ways to do the same thing. You can't take > something full of holes and start plugging holes until you think you > found them all. You have to start with something that has no holes. It's fine to look at it that way. Start with a subset of Python that you know to be safe, for example only integer literal expressions. Keep adding more safe features until you're satisfied with the expressiveness of your subset. > The Python crowd has been through this many times already; do some > searches for rexec/Bastion security. I did do a [quick] search, and saw a lot of articles about how rexec and Bastion were insecure; but I didn't find any arguments about how it's (too) difficult to come up with a safe subset of Python, for some definition of "safe". From jdhunter at ace.bsd.uchicago.edu Wed Aug 25 10:01:37 2004 From: jdhunter at ace.bsd.uchicago.edu (John Hunter) Date: Wed, 25 Aug 2004 09:01:37 -0500 Subject: building 2.1 with LFS In-Reply-To: (John Hunter's message of "Wed, 25 Aug 2004 07:46:59 -0500") References: Message-ID: >>>>> "John" == John Hunter writes: John> I am trying to build python2.1 with alrge file support. I John> ran configure in a clean build tree and then edited the John> makefile John> # Compiler options OPT= -ggdb -O3 -Wall -Wstrict-prototypes John> -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 #OPT= -g -O2 John> -Wall -Wstrict-prototypes DEFS= -DHAVE_CONFIG_H CFLAGS= John> $(OPT) -I. -I$(srcdir)/Include $(DEFS) John> And did a make; make install Solved; this incantation worked... 982 CFLAGS='-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64' OPT="-g -O2 $CFLAGS" ./configure 983 make 984 make install JDH From AntiVir at yalta.us Sun Aug 15 13:27:30 2004 From: AntiVir at yalta.us (AntiVir at yalta.us) Date: Sun, 15 Aug 2004 20:27:30 +0300 Subject: AntiVir ALERT [mail from: offered@www.2ksportsbet.com] Message-ID: <200408151727.i7FHRUcp028246@yalta.us> * * * * * * * * * * * * * * * AntiVir ALERT * * * * * * * * * * * * * * * ????????? ????????? ????? ? ??????????????, ??????? ????????? ????? ??????! ???????????: offered at www.2ksportsbet.com ???????? ??????: Worm/Mydoom.m ????? ?? ???? ?????????? ??????????. ? ?????????; ???????? ???????? ???.: +38(0654)271828 ????.: +38(0654)231094 web: www.yaltainfo.com email: support at yalta.us Mail-Info: --8<-- From: offered at www.2ksportsbet.com To: python-list at python.org Date: Sun, 15 Aug 2004 17:25:42 +0300 Subject: Returned mail: see transcript for details --8<-- This version of AntiVir is licensed for private and non-commercial use. -- AntiVir for UNIX Copyright (C) 1994-2003 by H+BEDV Datentechnik GmbH. All rights reserved. For more information see http://www.antivir.de/ or http://www.hbedv.com/ From jbenson at lowell.edu Wed Aug 18 17:43:46 2004 From: jbenson at lowell.edu (Jim Benson) Date: Wed, 18 Aug 2004 14:43:46 -0700 (MST) Subject: introspection? Message-ID: newbie question here: How does one get the class and method name from within a method? i.e here i have obviously hardcoded the class and method name: class JJTest: def methodA(self): print 'ERROR: in JJTest.methodA' >>> from jjtest import JJTest >>> jj = JJTest() >>> jj.methodA() ERROR: in JJTest.methodA >>> The Java way of doing this would be something like: System.out.println("ERROR in: " + this.getClass().getName()); I suspect that there are attributes that one can use to do something similar in Python. If any of you Python experts would let me know how to do this in Python, i would appreciate it. Thanks, Jim From npat at efault.net Fri Aug 13 14:23:21 2004 From: npat at efault.net (Nick Patavalis) Date: Fri, 13 Aug 2004 18:23:21 +0000 (UTC) Subject: Why I love python. References: Message-ID: On 2004-08-13, Michael J. Fromberger wrote: > > Why is it important to write an entire program in a single language > (e.g., Python), versus using a hybrid approach? If you can use Python > at all, that means your platform already has good support for a C > compiler, so there is no reason not to use C extensions if you really > need performance. > If this is the best thing possible then yes, this is a solution. But you see, I believe that even for these performance-sensitive parts, Python has a lot to offer in terms of expressive power. The question is: is it possible to make a Python environment fast-enough to be able to produce code as efficient as a C compiler? I believe the answer is yes, and we shouldn't be satisfied with the approach "do these glue things in Python, and for the computationally expensive ones, well code them in C". /npat From jepler at unpythonic.net Sun Aug 22 10:10:20 2004 From: jepler at unpythonic.net (Jeff Epler) Date: Sun, 22 Aug 2004 09:10:20 -0500 Subject: clear content of 'printed' In-Reply-To: References: Message-ID: <20040822141019.GB2348@unpythonic.net> What is "printed" (and why do you think that 'print "some text"' will modify it)? What is "container", that it has a "writeToFile" method? You must be using some non-standard module you didn't mention. If I understand what you're asking for, I might write something like for i, id in enumerate(myList): f = open(id, "w") print >>f, "some text" (Enumerate is a new built-in function in Python 2.3. The "print >>" syntax has been available since 2.1 or so) Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From reply2group at ndbbm.net Tue Aug 31 15:32:50 2004 From: reply2group at ndbbm.net (Active8) Date: Tue, 31 Aug 2004 15:32:50 -0400 Subject: compile to exe? Message-ID: I just moticed that wxGlade 3.1.1 comes with a windows installer and runs as an exe with a python22.dll and a bunch of .pyd files (pythod dlls?) and wxGlade 3.4 is all python files. I might be getting in deep here, but how do you turn .py files into .pyds and .exes? Any links or references to which doc and section would be appreciated. -- Best Regards, Mike From miki.tebeka at zoran.com Mon Aug 30 17:23:07 2004 From: miki.tebeka at zoran.com (Miki Tebeka) Date: Mon, 30 Aug 2004 23:23:07 +0200 Subject: use win32 COM in python In-Reply-To: References: Message-ID: <20040830212307.GH680@zoran.com> Hello Lin, > I have a C++ implemented COM server that give out a method like: int > read(unsigned char* buf, int lenth), How can I use this method from python? > what is the signature? > or anyone can tell me how should I design the COM interface so I can use > python to read a chunk of bytes from a C++ implemented COM server. You can avoid COM and either get this server as a Python module using SWIG/Boost.Python/Pyrex ... You can also use a regular DLL using ctypes package. However if you *must* use COM then make sure your server has a Dispatch interface and just use win32com.client.Dispatch to create and use it. Bye. -- ------------------------------------------------------------------------ Miki Tebeka http://tebeka.spymac.net The only difference between children and adults is the price of the toys From jarrodhroberson at yahoo.com Sun Aug 15 00:22:34 2004 From: jarrodhroberson at yahoo.com (Y2KYZFR1) Date: 14 Aug 2004 21:22:34 -0700 Subject: Python indentation deters newbies? References: <3064b51d.0408130615.3fc4a760@posting.google.com> Message-ID: beliavsky at aol.com wrote in message news:<3064b51d.0408130615.3fc4a760 at posting.google.com>... > One of the most commmon reasons programmers cite for not trying Python > is that indentation determines the program flow -- they think its > weird. I think programmers who actually try Python adapt quickly and > do not find the indentation rules to be a problem. > > I wonder if there is a way to remove this initial barrier. Could an > alternate source form be defined, so that there are matching if-endif > and for-next constructs instead of significant indentation? The > alternate source form and the current form would result in exactly the > same .pyc file. > > I'm not saying that Python's use of indentation is bad, just that it > stops many programmers from trying it. then it is there loss that they are so stupid and closed minded to not try something a better way but don't go and make something crappy because of crappy people From martin at v.loewis.de Sun Aug 22 17:40:24 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 22 Aug 2004 23:40:24 +0200 Subject: Proposal: require 7-bit source str's In-Reply-To: References: <412907C8.1090104@v.loewis.de> Message-ID: <412912C8.8080707@v.loewis.de> Hallvard B Furuseth wrote: >>I agree with many things you said, but this example is bogus. If I >>(as a German) use ns_4551-1, sorting is simple - and incorrect, because, >>as you say, ? sorts with o in my language - yet the simple sorting of >>ns_4551-1 doesn't. So sorting is *not* simple with ns_4551-1. Ah, I missed the point that there is no ? in ns_4551-1. If so, then the best way to represent the characters is to replace ? with "oe" and ? with "ae"; replacing them merely with "o" and "a" would be considered inadequat. > And if I want to get both right, I need a sort_name field which is > distinct from the display_name field. There you would be lowis, while > the Swede T?rnquist would be t?rnquist. Or maybe lowis\tl?wis or > something; a kind of private implementation of strxfrm(). But you can have a strxfrm for Unicode as well! There is nothing inherent in Unicode that prevents using the same approach. Of course, the question always is what result you *want*: If you have text that contains simultaneously Latin and Greek characters, how would you like to collate it? Neither the German or Greek collation rules are likely to help, as they don't consider the issue of additional alphabets. If possible, you should assign a language tag to each entry, and then sort first by language, then according to the language's collation rules. Regards, Martin From jeff at ccvcorp.com Tue Aug 17 15:33:01 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Tue, 17 Aug 2004 12:33:01 -0700 Subject: python packages cross references In-Reply-To: References: Message-ID: <10i4n9vd5k5hr73@corp.supernews.com> Roman Yakovenko wrote: >May be I was not clear, but from module in package A I want to user functionality >defined in module of package Utils > >"... >When packages are structured into subpackage (as with the Sound package in the example), there's no shortcut to refer to submodules of sibling packages - the full name of the subpackage must be used. For example, if the module Sound.Filters.vocoder needs to use the echo module in the Sound.Effects package, it can use from Sound.Effects import echo. >... >" >It means that I should have prj in sys.path. ( Am I wrong here? ). > >So I ask is there is elegant solution? > > Uh, whatever you'd do to get prj into your sys.path in order to run your program to begin with? Actually, technically speaking, you don't need prj in sys.path, you only need the directory that prj is under in your sys.path -- if Python can see the prj directory, it'll look inside it for an __init__.py, and finding that will consider it a valid package. In recent versions (certainly 2.2+) of Python, I believe that you *should* be able to simply put prj under %python-lib%/site-packages (wherever that may be located on your particular installation), which is already in sys.path and is intended for that very purpose. Jeff Shannon Technician/Programmer Credit International From jeff at ccvcorp.com Fri Aug 20 19:31:41 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 20 Aug 2004 16:31:41 -0700 Subject: decorator J4 - any objections? In-Reply-To: References: Message-ID: <10id2djglri8o15@corp.supernews.com> Larry Bates wrote: >If docstring can be a special case of a triple quoted >string, I don't see why decorators couldn't be a special >case of a dictionary. >[...] > >I'm sure there is a reason, but it would seem to make >"Python"-sense to me. It would then be very extensible >for the meta-data that everyone seems to also want decorators >to support. > > The biggest reason that I'm aware of is that GvR has declared that he doesn't think decorators belong inside a function def, and has even been quoted as having professed a regret for having put docstrings there. (Personally, I think that having all of this stuff immediately inside the function def makes great sense, but I'm not a world-famous language designer, so what do I know? ;) ) In fact, the biggest problem that I can see with the J4 syntax is its close similarity to all of the decorator-inside-def variations. Since GvR has spoken strongly against putting decorators in that location, it seems to me to be a waste of effort to advocate for that. Now, perhaps having that outdented keyword to indicate the function-body start *might* make a difference with him... but I would expect that it won't. Jeff Shannon Technician/Programmer Credit International From mwh at python.net Thu Aug 5 08:21:36 2004 From: mwh at python.net (Michael Hudson) Date: Thu, 5 Aug 2004 12:21:36 GMT Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) References: <1646998998.20040804190026@MailBlocks.com> <10h34ivio5s2c21@news.supernews.com> Message-ID: "John Roth" writes: > "Bruce Eckel" wrote in message > news:mailman.1168.1091667628.5135.python-list at python.org... > > I'll weigh in a little on this one. > > > > This is very similar to attributes/metadata in Java J2SE 5 and in C#. > > The thing is, metadata is a little bit weird; it's intentionally > > outside of the domain of the 'normal' programming language, because it > > expresses things that you can't or shouldn't within the normal > > programming language. Except, of course, this is Python so there isn't any such thing as metadata, really. Objects all the way down. > > So you _do_ need an escape mechanism. And it also takes a little > > bit of getting used to; it's orthogonal to what you normally think > > of as a language feature. But the potential for metadata features, > > at least in Java, is very powerful. > > I'd be a lot happier if it was, in fact, a general metadata > facility. Unfortunately, it only seems to work on functions > (methods), and for what I'm working on I need metadata for > properties and fields as well, that is, any identifier that you can > bind an object to. Well, that would be because that's impossible :-) Where would you attach the data in: class C(object): @funky i = 0 ? You can't attach it to 'i' -- that's just a string. '0' is just an integer. The class doesn't exist at the time the body is executed. What you can do (today) of course is stuff like: class C(object): i = MagicProperty(int, default=0) or something -- which obviously leaves ample space for metadata in the argument list -- but that can be painful, I grant. What kind of metadata do you want? (I have to admit I read your first post on this thread a bit like "this hammer doesn't do a very good job of screwing in screws" :-) Cheers, mwh -- It is time-consuming to produce high-quality software. However, that should not alone be a reason to give up the high standards of Python development. -- Martin von Loewis, python-dev From tchur at optushome.com.au Wed Aug 4 16:22:14 2004 From: tchur at optushome.com.au (Tim Churches) Date: 05 Aug 2004 06:22:14 +1000 Subject: Finding all time periods for a given interval within a date range In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022DD9@exchange.hqamor.amorhq.net> References: <3A81C87DC164034AA4E2DDFE11D258E3022DD9@exchange.hqamor.amorhq.net> Message-ID: <1091650934.1235.6.camel@emilio> On Thu, 2004-08-05 at 03:09, Robert Brewer wrote: > Look at my 'recur' module and see if it fits your requirements: > > http://www.aminus.org/rbre/python/index.html > > Start with the Recurrence class and play with it--then dig deeper if you > need to. Robert, How is the above code licensed? -- Tim C PGP/GnuPG Key 1024D/EAF993D0 available from keyservers everywhere or at http://members.optushome.com.au/tchur/pubkey.asc Key fingerprint = 8C22 BF76 33BA B3B5 1D5B EB37 7891 46A9 EAF9 93D0 From squirrel at WPI.EDU Tue Aug 3 16:42:36 2004 From: squirrel at WPI.EDU (Christopher T King) Date: Tue, 3 Aug 2004 16:42:36 -0400 Subject: simple Thread question In-Reply-To: References: Message-ID: On Tue, 3 Aug 2004, Dave Brueck wrote: > Er... you're jumping the gun a bit - no need to scare the OP away from > threads with all these details about the GIL when the problem was simply > that the threads were never started. > > [snip] > > Because of the former property, another thing you can try is > > inserting a time.sleep(.1) inside of each loop > > Uh, did you read his code before responding? (hint: he's already doing > that) :) Wow, I really screwed that up :P I really should stop posting to this list in a hurry. My eyes glanced at the short loop, the thread-starting code (didn't notice the .run() instead of .start()), and the output, and concluded "GIL funkiness" (something I've been hit with before). FWIW, replacing .run() with .start() (and dropping name from .run()) and dropping the sleep() produces the same symptoms the OP was showing. From peter at engcorp.com Tue Aug 17 19:36:30 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 17 Aug 2004 19:36:30 -0400 Subject: PEP 318: Can't we all just get along? In-Reply-To: References: <20040817181725194-0400@braeburn.themorgue.org> Message-ID: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Paul Morrow wrote: > Kevin Smith wrote: >> def classmethod foo(x, y, z): >> pass >> >> That's it. One "decorator" that is a callable object that takes a >> method as it's only argument. No expressions, lists, tuples, etc. >> Just one callable object. > > Nope. That's using static declarations. We're a dynamically typed > language as much as possible. Isn't there something that doesn't > require any additional grammar words to identify classmethods and > staticmethods? It looks to me as though Kevin is not suggesting keywords, but callables. In other words he would consider this valid, provided my_own_decorator was a callable. def my_own_decorator foo(x, y, z): pass -Peter From steven.bethard at gmail.com Tue Aug 24 02:16:48 2004 From: steven.bethard at gmail.com (Steven Bethard) Date: Tue, 24 Aug 2004 06:16:48 +0000 (UTC) Subject: function taking scalar or list argument References: <412a2bce$1_1@127.0.0.1> <9ZCdnT9EuudK3bfcRVn-tA@comcast.com><10il11q5uqfg4ad@corp.supernews.com> Message-ID: Terry Reedy udel.edu> writes: > In 2.2.1: > >>> hasattr([1,2,3], '__iter__') > 0 > so this does not seem to work as you seem to expect. hasattr(iter(x), > '__iter__') will. Yeah, I thought there was probably some special case I was missing there. The problem with hasattr(iter(x), '__iter__') is that iter(x) can throw an exception if the object is not iterable: >>> iter(1) Traceback (most recent call last): File "", line 1, in ? TypeError: iteration over non-sequence So if you call iter(x) in the test, and x is a number, you end up having to try and catch the exception just like in the original solution. Do you know at what version hasattr(x, '__iter__') started working? In 2.4a2: >>> hasattr([1,2,3], '__iter__') True Steve From peter at engcorp.com Fri Aug 6 16:51:53 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 06 Aug 2004 16:51:53 -0400 Subject: Killing children In-Reply-To: <87d624vxt2.fsf@debian.laymusic.org> References: <87smb0w4ln.fsf@debian.laymusic.org> <87d624vxt2.fsf@debian.laymusic.org> Message-ID: <2eidnefxXqX3co7cRVn-tA@powergate.ca> Laura Conrad wrote: > p = os.spawnl(os.P_NOWAIT, "/usr/bin/python", "python", "hobo.py", '/dev/ttyS0', 5) > print p > > os.system("ps") > time.sleep(60) > os.system("kill %d" % p) This suggests that you believe the return value from os.spawnl() is actually the PID. Unfortunately that doesn't appear to be the case on Windows. See the note in the doc-string for my code sample from the previous post (on Windows spawn* actually returns a "handle", not the PID itself, and apparently turning the one into the other is non-trivial). -Peter From __peter__ at web.de Wed Aug 4 04:41:46 2004 From: __peter__ at web.de (Peter Otten) Date: Wed, 04 Aug 2004 10:41:46 +0200 Subject: how to do proper subclassing? References: Message-ID: Jonas Koelker wrote: > I'm new to this list (/me welcomes himself). Jonas, I suggest that you post follow-ups vaguely on topic on c.l.py. That gives you the chance for answers that I (for example) don't know about or care to give as well as corrections or a second opinion. [Jonas via email] > > >>> class Perm(list): > > > > ... def __init__(self, n): > > ... list.__init__(self, range(n)) > > ... def __call__(self, i, k): > > ... self[i], self[k] = self[k], self[i] > > ... return self > > ... > > > > >>> p = Perm(5) > > >>> p > > > > [0, 1, 2, 3, 4] > > > > >>> p(0,4)(2,4)(0,1)(2,3)(1,2) > > > > [1, 3, 4, 0, 2] > > > > >>> p[1:2] > > > > [3] > > > > >>> p[1:3] > > > > [3, 4] > > thanks, this looks about right (slaps himself on the > forehead - "you DO know how init works!")... :] > > also, p(0,4)(2,4)(0,1)(2,3)(1,2) looks really neat and > math'ish :) > > > Just in case you need it later, there is a special > > method for every operator, e. g. __getitem__() for > >obj[sliceOrIndex], __mul__() for multiplication etc. > > Yeah, I knew that. I might make __int__() convert the > perm to a ranking number in linear time. See My mentioning of special methods doesn't mean that I think they are always the best choice. I would prefer both p.rank() and rank(p) over int(p). > http://www.cs.uvic.ca/~ruskey/Publications/RankPerm.html > > .. don't worry, I can implement it myself. Don't worry, I won't :-) > btw, if I want to set the "list part" of the perm, how > do I do that? p[:] = [1, 2, 3, 4, 5] p[:2] = p[1], p[0] p[2] = [99] If you want to ensure that the permutation is still valid after assignment you have to write your own __setitem__() method. > p = [4,0,3,2,1] would turn p into a list. > p = perm(5)(0,4)(2,4)(0,1)(2,3)(1,2) is valid (right?) > but time consuming. That was just for fun... most likely faster than while p != [4,0,3,2,1]: random.shuffle(p) > I'd say it'd be easier/better to implement it as: > >>> class Perm(list): > > ... def __init__(self, n): > ... list.__init__(self, n) The good news: if __init__() does nothing but call the base class' __init__(), you need not write one at all. > ... def __call__(self, i, k): > ... self[i], self[k] = self[k], self[i] > ... return self > > >>> p = Perm([4, 0, 3, 2, 1]) > > ... anyways, thanks :) You're welcome. Peter From python-url at phaseit.net Tue Aug 31 15:58:16 2004 From: python-url at phaseit.net (Peter Otten) Date: Tue, 31 Aug 2004 19:58:16 +0000 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 31) Message-ID: QOTW: "Python is clearly on a huge evolutionary surge and conservative views on the matter are definitely not winning out right now. And the usual argument (submit a patch!) doesn't really work when those who want to avoid many changes try it... I've been *not* submitting a patch on lots of changes to Python, but somehow it's never been accepted. ;-)" Peter Hansen "I've never seen a more complicated, verbose pile of hogwash than the 'deliverd by mailman' mailing list program." Carol Carrot, perhaps innocent of experience with Majordomo and Sendmail Michelle Levesque's PyWebOff annotates the Python-savvy Web frameworks. PEP 333 offers to rationalize a piece of them. http://pyre.third-bit.com/pyweb/index.html http://groups.google.com/groups?th=7f19fe19b40c1be0 How do generator expressions and list comprehensions compare? Experts explain why the former are *better*--OK, better in several, although not all, ways http://groups.google.com/groups?frame=left&th=1d4aca073edaaa2f Jim Hugunin domesticates Python for the Microsoft weltanschaung. http://blogs.msdn.com/hugunin/ http://www.eweek.com/article2/0,1759,1636906,00.asp How does Python regard file systems? It's a timely topic, with pyfmf its most concrete expression. http://groups.google.com/groups?frame=left&th=c379db570ef96c43 http://sourceforge.net/projects/pyfmf http://richard.jones.name/google-hacks/gmail-filesystem/gmail-filesystem.html High-profile Pythoneers Michael Sparks and Alex Martelli demonstrate interests beyond the perfection of the One True Language: petabyte-scale archiving, and marriage. http://www.pcw.co.uk/news/1157046 http://www.aleax.it/mar.html http://bonanna.multiply.com/photos/album/1 Uche Ogbuji reveals his habits for keeping current with Pythonia. http://www.oreillynet.com/pub/wlg/5490 ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous 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 newsgroup weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Brett Cannon continues the marvelous tradition established by Andrew Kuchling and Michael Hudson of intelligently summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Business Forum "further[s] the interests of companies that base their business on ... Python." http://www.python-in-business.org Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donate.html Cetus collects Python hyperlinks. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://aspn.activestate.com/ASPN/Cookbook/Python Among several Python-oriented RSS/RDF feeds available are http://www.python.org/channews.rdf http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi http://python.de/backend.php For more, see http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. *Py: the Journal of the Python Language* http://www.pyzine.com Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. From npat at efault.net Sun Aug 15 06:53:10 2004 From: npat at efault.net (Nick Patavalis) Date: Sun, 15 Aug 2004 10:53:10 +0000 (UTC) Subject: Generators versus Coroutines References: <7x7js1i887.fsf@ruckus.brouhaha.com> Message-ID: On 2004-08-14, Paul Rubin <> wrote: > > You can't yield across multiple levels of function calls. That's why > they're called "simple generators" instead of just "generators". > For me it would be *tremendously* usefull if one could yield across multiple levels of function calls. If this was supported, then most uses of O/S treads could be replaced by generators. Does anyone know if such a feature is planned? /npat From http Sat Aug 28 03:19:10 2004 From: http (Paul Rubin) Date: 28 Aug 2004 00:19:10 -0700 Subject: would be nice: import from archive References: <2SJXc.79576$pTn.26490@news01.bloor.is.net.cable.rogers.com> <1gj6zoc.1iv3xw32wu6mkN%aleaxit@yahoo.com> <7xzn4gwgea.fsf@ruckus.brouhaha.com> <1gj7a1o.1a5d2q410jsn2kN%aleaxit@yahoo.com> <7xisb4xnh5.fsf@ruckus.brouhaha.com> <1gj7c1a.tfdm14p3hclcN%aleaxit@yahoo.com> Message-ID: <7xd61benm9.fsf@ruckus.brouhaha.com> aleaxit at yahoo.com (Alex Martelli) writes: > While the overall way the new import hooks work is well documented in > their PEP, zipimport is admittedly underdocumented. I suggest peeking OK. I'll look at the PEP. I think adding signing is hairy enough that it should have its own round of discussion; should I see about editing the PEP to add something about signing? From http Mon Aug 23 05:30:08 2004 From: http (Paul Rubin) Date: 23 Aug 2004 02:30:08 -0700 Subject: Has anyone implemented BASIC in Python? References: <2oo13eFcj548U1@uni-berlin.de> <69cbbef2.0408210857.79439c35@posting.google.com> <7x657c8jmn.fsf@ruckus.brouhaha.com> Message-ID: <7xoel26w2n.fsf@ruckus.brouhaha.com> Peter Hansen writes: > > Dunno about Logo but I did Forth just out of general perversity. > > I suppose I could post it. > > Please do! Well, it's not real Forth, just a mini-subset that I threw together in a few hours, to get some understanding of how Forth is supposed to work. But you can type stuff like : square dup * ; 3 square . and it will print 9 at you. Part of the perversity is that each word is compiled to a Python lambda and is invoked by calling the lambda. The idea was to make both Pythonistas and Forthwrights(?) scream in disgust ;-). Please forgive the lack of comments etc. I wasn't going to release it (at least in that condition), but you asked for it ;-). http://www.nightsong.com/phr/python/forth.py From http Fri Aug 20 22:07:17 2004 From: http (Paul Rubin) Date: 20 Aug 2004 19:07:17 -0700 Subject: decorator J4 - any objections? References: Message-ID: <7xacwpb5wq.fsf@ruckus.brouhaha.com> Jeffrey Froman writes: > > def func(arg1, arg2) > > @version("Added in 2.4") > > @returns(None) > > as: > > """Docstring could be here, or in decorator part above""" > > # body goes here > > I like this better than the current proposal because it reads from top to > bottom, and flows like a typical conditional. > > Before function writing the decorators whereas like reads this. J4 is my favorite of the enumerated proposals I remember, so I'll "vote" for it, but I still think something better should be possible. From grv575 at hotmail.com Tue Aug 3 21:18:54 2004 From: grv575 at hotmail.com (grv) Date: Wed, 4 Aug 2004 01:18:54 +0000 (UTC) Subject: eric3 completion Message-ID: <953AD2389idtoken@128.91.2.239> This is the only IDE that looks very useable on linux of everything I've looked at (and not to start a dev environment war) but one thing that is troublesome is the word completion. There is a user-contributed script to parse all the dll and py files to make a list of functions & attributes for each namespace, but it doesn't pick up some things like file.seek() and datetime.today(). The script complains that no source files found, yet other built-ins like open() are picked up. Any guidelines on how to get all the default stuff working for code completion? From dd at guv.ethz.ch Sun Aug 15 06:37:12 2004 From: dd at guv.ethz.ch (=?iso-8859-15?Q?David_D=FCrrenmatt?=) Date: Sun, 15 Aug 2004 12:37:12 +0200 Subject: Python "decompyle" Message-ID: Hi. If I try to use decompyle (decompyle-2.3) for pyc-files < version 2.0, I get an error with marshal_20 (ImportError: dynamic module does not define init function (initmarshal_20) ). marshal_20 was compiled to a so-file using gcc. Does anybody know where this error could come from and how to solve it? Thanks, dave -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ From fuzzyman at gmail.com Tue Aug 24 07:53:13 2004 From: fuzzyman at gmail.com (Michael Foord) Date: 24 Aug 2004 04:53:13 -0700 Subject: Python and C, looking for a C IDE Message-ID: <6f402501.0408240353.2a5b8a84@posting.google.com> I'm looking to learn C to move some 'speed sensitive' code from C to python. I'm partly doign this as an exercise to learn a static language to help broaden my programming skills - so please don't jump on the bandwagon and tell me I'd be better placed to put my efforts into optimising my python code !! I'd like to use tools like Pyrex and weave with the GCC compiler on windoze. I've got Pyrex working... but weave doesn't seem t oco-operate with GCC :-( Although weave itself will compile with GCC (Apparently) I haven't yet worked out how to persuade it to *use* GCC... weave has it's own mutation of distutils with an (apparently) different and undocumetned configuration system... That aside - Pyrex looks the kiddie. Can anyone reccomend a reasonable C IDE ? An 'IDE' would be nice, but an editor might be sufficient. Regards, Fuzzy http://www.voidspace.org.uk/atlantibots/pythonutils.html From max at alcyone.com Mon Aug 23 18:58:47 2004 From: max at alcyone.com (Erik Max Francis) Date: Mon, 23 Aug 2004 15:58:47 -0700 Subject: % format strings References: <144d0df.0408231455.6b664466@posting.google.com> Message-ID: <412A76A7.4C87D17C@alcyone.com> grv575 wrote: > Is > there a way to specify the precision length for floating points in C > format strings? Yes, it looks the same as in Python. Python got the notation from C. -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ My reputation grows with every failure. -- George Bernard Shaw From antispam Mon Aug 30 23:11:36 2004 From: antispam (Maboroshi) Date: Mon, 30 Aug 2004 20:11:36 -0700 Subject: File System Message-ID: <10j7r3cflo61680@corp.supernews.com> Hi I was curious I was interested in finding out from Programmers and Computer Users - If they were to completely rebuild there Computers Filing System How would it work I believe since the advent of the PC we have been brainwashed (In a Sense cause nothings really Changed ( at least as far as I know ) to have a filesystem that is structured in this way Open a Folder open its contents open another folder open its contents open a file move a file delete a file move a folder delete a folder you get the idea I believe this structure is much like an array or a multidimensional array if you were to put it in that respect Question: are most (if not all) databases like this I believe there is a better way and I want to find it I also believe if there is a better way it could totally change our approach to programming I know this isn't neccessarily a python question but it has to do with future research that will benefit the Python Language plus I like to hear the opinions of the Python Community which I have a lot of respect for Cheers Maboroshi From narshe at gmail.com Thu Aug 19 11:58:49 2004 From: narshe at gmail.com (Josh Close) Date: Thu, 19 Aug 2004 10:58:49 -0500 Subject: My only complaint about Python In-Reply-To: References: Message-ID: <4a0cafe204081908585ab3c0b3@mail.gmail.com> Why not use ActiveState pythong then? -Josh On Thu, 19 Aug 2004 11:42:50 -0400, Darren Dale wrote: > I love the language. I love the community. My only complaint is that > Python for Windows is built with Visual Studio. > > It is too difficult to build python, or a module, from source. This is > what open source is all about, isnt it? I even have a copy of visual > studio, and I still cant build modules from source, because my academic > copy is version 7. As a scientist funded by the NSF, I feel compelled to > do all my work using free software (I feel compelled to use free > software, regardless). And I feel compelled to contribute to the > scientific capabilities of my favorite programming language. But this > compiler issue is a big (and seemingly unnecessary) impediment. Will the > BDFL ever split with Visual Studio? > -- > http://mail.python.org/mailman/listinfo/python-list > From ajsiegel at optonline.com Sat Aug 28 08:37:10 2004 From: ajsiegel at optonline.com (Arthur) Date: Sat, 28 Aug 2004 12:37:10 GMT Subject: Question about references/copies References: <1gj870c.dzzhcpvby7ozN%aleaxit@yahoo.com> Message-ID: On Sat, 28 Aug 2004 11:32:39 +0200, aleaxit at yahoo.com (Alex Martelli) wrote: >Henning Kage wrote: > >> I'm using Python only for some months now and I'm wondering, whether such >> assignments as above > >"As above" _where_? > >> are creating bitwise copies of an object or just >> recieve a reference. That means I wanted to know, wheter Python in general >> differs between references and copies: >> >> class someclass: >> def __init__( self, otherobject): >> self.someattribute = otherobject > >Python makes no copy unless you explicitly ask for a copy -- what you >get is always a reference. There are several ways to ask for copies -- >the most general and powerful ones you'll find in standard library >modules copy (both copy.copy and copy.deepcopy -- all other ways of >asking for a copy, except copy.deepcopy, get shallow copies). I've felt strongly that this key piece of Python learning would be and much, much more inevitable if there was a (preferred) consistent way to ask for a copy, across objects - and/or that the copy module was something other than one of XXX importable moudles. That dicts and lists (for example) have totally different syntax for copy, helps - I promise - to misdirect and confuse. I happen to consider this entire area a significant wart. I think I am entitled to consider it so. I had tried to bring this up to in various forums, most particularly edu-sig - where I thought this knid of discussion might be of particular significance - and was rather rudely asked by Guido to take it elsewhere. Where? not clear. Ray Hettinger asked Gudio for permission to at least put a few words about the copy module in the tutorial section mentioning a few of the key importable modules - to at least, I think,. give new users a clue that there was something of conceptual significance in all this. And was refused. My only participation on python-dev was to ask Gudio to reconsider And was - rudely - dismissed. I promise Brett C. and Anthony B. that there is more of a 2-way street than they might think. For some of us trying to make our own kind of contribution in our own kind of way. Art From joshway_without_spam at myway.com Thu Aug 26 10:46:22 2004 From: joshway_without_spam at myway.com (JCM) Date: Thu, 26 Aug 2004 14:46:22 +0000 (UTC) Subject: Inline Conditionals? References: <1gj4rpq.1oyt89b14xvbdqN%aleaxit@yahoo.com> Message-ID: Antoon Pardon wrote: > Op 2004-08-26, Alex Martelli schreef : ... >> Peter's right. And Joshua's example shows how wise the BDFL was in >> ruling out ternaries: sure, good programmers might occasionally have >> found good uses for them, but we' have paid that with a LOT of horrid >> code like that -- I've seen lots like that in C & its ilk, too. > When using list comprehension not having a ternary operator can be > a PITA. It is of course possible I miss something but how am I > supposed to do the following: > [ x.property ? foo(x) : bar(x) for x in Somelist ] def foo_or_bar(x): if x.property: return foo(x) return bar(x) [foo_or_bar(x) for x in Somelist] (still, I'd like to see a ternary conditional operator too...) From ptmcg at austin.rr._bogus_.com Fri Aug 20 10:56:39 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 20 Aug 2004 14:56:39 GMT Subject: Decorator keyword options - brainstorming References: <7knVc.4599$Jn5.3074@fe1.texas.rr.com> Message-ID: One impression I've gotten from this whole endeavor (even going back to Kevin Smith's python-dev e-mail thread titled "PEP 318: Can't we all just get along?") is that what started out as a desire to simplify the designation of some methods as "class-level" or "static" or "special" in some way, has gotten muddied with the implementation as it got represented with the classmethod and staticmethod decorators, and then mutating to accommodate all types of modifier/decorator/mutators, for resource locking, debugging, logging, memoizing, etc. Similarly, I feel our fixation on the "decorator" concept is confounded by our own understanding that the entries in a list of decorators such as: keyword: memoize synchronize staticmethod def foo: pass will translate to: foo = staticmethod(synchronize(memoize(foo))) in the current vernacular. But should we consider this implementation detail when coming up with this name? I'd prefer to think of the associations that exist between the concepts of 'memoize' et al. with 'foo', and use a keyword that describes those relationships. And try to do this independent of implementation, or coincidence with a GoF archetype. So I have been looking at some alternatives, such as helper: amend: modify: qualify: (or perhaps qual:) property: (or perhaps prop:) On an alternative path, does this have to be a real word? I confess that "qual" strikes me in an interesting way, in that it could be thought to represent either "qualifier" or "quality", and yet is neither. Or if "lambda" is used, why not some other Greek letter, such as "mu" or "sigma". Still, I would like to avoid arbitrary words, as they are little better than '@' - I'd say that something like "gerbil" should be right out! :) This clearly represents some "thinking out loud". Throw rocks or suggestions at will. -- Paul From sbabbitt at commspeed.net Sat Aug 28 14:41:14 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Sat, 28 Aug 2004 11:41:14 -0700 Subject: Dynamic languages References: <278de0e.0408271349.26762174@posting.google.com> <1093650026.763899@news.commspeed.net> Message-ID: <1093718996.482485@news.commspeed.net> "Reid Nichol" wrote in message news:rc3Yc.3346$MR2.22572 at news1.mts.net... > Tom B. wrote: > > I doubt that this is what they mean but a dynamic language is a language > > that is still evolving (Python) as opposed to a dead language (COBOL). > During my "education" at my school of unfortunate choice I had to learn > the script of the damned... sorry, COBOL. I learned that it has indeed > gone through some developments in the past years ie COBOL now is object > oriented COBOL. > > It *should* be dead though, but companies don't want to develope any new > systems. So, they fund a programming program at some local college at > "suggest" that they include it so that they have a work force availible > to make changes to there system. > > That of course doesn't mean that this certain company's COBOL programmer > lasts on average < 6 months. Which certainly is the case. Quite > frankly I don't know how they last so long. I figured that I wouldn't be able to find any truly dead computer language. I met a technician at U of Minnesota Physics department who collected PDP11's and programmed only in fourth. When I asked him why he replied, 'If I don't do it who will'. Tom From Michael.J.Fromberger at Clothing.Dartmouth.EDU Wed Aug 18 21:14:07 2004 From: Michael.J.Fromberger at Clothing.Dartmouth.EDU (Michael J. Fromberger) Date: Wed, 18 Aug 2004 21:14:07 -0400 Subject: PEP 318: Can't we all just get along? References: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: In article , Paul Morrow wrote: > Michael J. Fromberger wrote: > >> > >> def foo(cls, a, b): pass > >> > >>...I bet the majority would correctly guess "class". > > > > Well, given just that definition, the guess would be incorrect. The > > current release of Python would also require: > > > > def foo(cls, a, b): pass # As defined above > > foo = classmethod(foo) > > Actually, it illustrates the importance of proof-reading a post > before posting it, which I didn't (sorry). Understood, no worries. > I should've also stated that the Python developers would be told that > this is a special version of Python that automatically determines the > type (static|class|instance) of a method. In that light, do you see > how effective the visual convention can be? Oh, I see it just fine -- but I still disagree with the idea of including any such implicit magic in the language. In fact, I don't like some of the magic that is already there -- such as, for instance, the automatic mangling of class members whose names begin with a double underscore to get "private" semantics. But that, at least, is easy to avoid, if one doesn't want to use it. > * If method's first param is 'self', it's an instance method. > * If method's first param is 'cls' or 'klass', it's a class method. > * All other methods are static methods. Uck. -1 from me. -M -- Michael J. Fromberger | Lecturer, Dept. of Computer Science http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA From alikakakhel3 at hotmail.com Sun Aug 15 16:58:19 2004 From: alikakakhel3 at hotmail.com (Ali) Date: 15 Aug 2004 13:58:19 -0700 Subject: Anyone use VPython? References: <8f17f4bc.0408141932.46b7c405@posting.google.com> <69juh0dalfeu39fpvvvcb56ukovl0o1fsb@4ax.com> Message-ID: <8f17f4bc.0408151258.35874dbc@posting.google.com> Arthur wrote in message news:<69juh0dalfeu39fpvvvcb56ukovl0o1fsb at 4ax.com>... > On 14 Aug 2004 20:32:49 -0700, alikakakhel3 at hotmail.com (Ali) wrote: > > >Anyone use VPython? > > Yes. ok then how yu make things move? From in.aqua.scribis at nl.invalid Fri Aug 20 17:23:32 2004 From: in.aqua.scribis at nl.invalid (Peter Kleiweg) Date: Fri, 20 Aug 2004 23:23:32 +0200 Subject: Fate of lambda, Functional Programming in Python... In-Reply-To: References: <20040820163629.8DD4F1E401A@bag.python.org> Message-ID: Anthony Baxter schreef: > On Fri, 20 Aug 2004 12:50:02 -0400, Chas Emerick wrote: > > In a comment off a post on lambda-the-ultimate, I noticed this little > > offhand remark: > > > > '''IIRC GvR is going to kill the various lambda, map,filter & reduce > > leaving just generator expressions/list comprehension.''' > > First point: lambda, map, filter and reduce won't go away before Python 3.0, > at the very least. And, to be honest, I suspect map/filter/reduce are much more > likely to die than lambda, as they can nearly always be expressed more clearly > as listcomps or genexprs. The Python Cookbook, recipe 1.8, "Finding the Intersection of Two Dictionaries" shows different methods of doing this particular thing, among them list comprehension and filter. Here, using filter is the fastest of all. Why would you want to do away with something that is useful? > Having said that, and donning my interpreting-Guido-hat, the major problem > with lambda is the scoping issue. Nested scopes make this less of a problem. > In addition, the name 'lambda' was a poor poor choice. The choice is perfectly logical. -- Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia) info: http://www.let.rug.nl/~kleiweg/ls.html The Halloween Documents: http://www.opensource.org/halloween/ From alanmk at hotmail.com Sun Aug 22 18:04:15 2004 From: alanmk at hotmail.com (Alan Kennedy) Date: Sun, 22 Aug 2004 23:04:15 +0100 Subject: python doesn't like my numbers In-Reply-To: <2osfspFdnjbcU1@uni-berlin.de> References: <2osfspFdnjbcU1@uni-berlin.de> Message-ID: [paul k] > is there any way to convince python not to take my (phone)numbers > starting with zero as octals? > > >>> int(088) > File "", line 1 > int(088) > ^ > SyntaxError: invalid token Answer 1: Use strings: that's really what telephone numbers should be Answer 2: Use valid octal digits in your phone numbers. The digit '8' cannot appear in base 8 numbers, only the digits 0-7. >>> int(077) 63 >>> int(088) Traceback (innermost last): (no code object) at line 0 File "", line 1 int(088) ^ SyntaxError: invalid syntax >>> -- alan kennedy ------------------------------------------------------ email alan: http://xhaus.com/contact/alan From http Wed Aug 11 02:28:53 2004 From: http (Paul Rubin) Date: 10 Aug 2004 23:28:53 -0700 Subject: Yet another decorator proposal References: Message-ID: <7xfz6ujihm.fsf@ruckus.brouhaha.com> Marco Aschwanden writes: > Here is yet another decorator proposal: > > def sumSequencesLengths(var1, var2): > """Computes something very important. > > __decorators__: > staticmethod I think you are onto something. The particular syntax you proposed has shortcomings, but maybe improvements are possible. From wweston at att.net Mon Aug 23 14:43:35 2004 From: wweston at att.net (wes weston) Date: Mon, 23 Aug 2004 18:43:35 GMT Subject: Standard graph API? In-Reply-To: References: Message-ID: Magnus Lie Hetland wrote: > Is there any interest in a (hypothetical) standard graph API (with > 'graph' meaning a network, consisting of nodes and edges)? Yes, we > have the standard ways of implementing graphs through (e.g.) dicts > mapping nodes to neighbor-sets, but if one wants a graph that's > implemented in some other way, this may not be the most convenient (or > abstract) interface to emulate. It might be nice to have the kind of > polymorphic freedom that one has with, e.g, with the DB-API. One could > always develop factories or adaptors (such as for PyProtocols) to/from > the dict-of-sets version... > > So, any interest? Or am I just a lone nut in wanting this? > Magnus, A know I'd appreciate it. It could be used to configure neural nets and logic networks; where this api would make it easy to build an abstraction then "compile" it into a faster representation for execution - or just run the tree/graph in "interpreted" mode. I don't think it would get a lot of use, but the use would be high end. wes From crichton314 at btinternet.com Tue Aug 24 06:10:11 2004 From: crichton314 at btinternet.com (John Crichton) Date: 24 Aug 2004 03:10:11 -0700 Subject: functional library References: <0uBWc.191260$M95.165005@pd7tw1no> Message-ID: <3b2846c4.0408240210.5803b8b4@posting.google.com> Hi Martin, You could try the Xoltar toolkit at http://www.xoltar.org/languages/python.html Hope this helps, John From max at alcyone.com Tue Aug 31 23:11:28 2004 From: max at alcyone.com (Erik Max Francis) Date: Tue, 31 Aug 2004 20:11:28 -0700 Subject: string.maketrans().lower() References: Message-ID: <41353DE0.1D7D5AC5@alcyone.com> Hallvard B Furuseth wrote: > I have a translation table from > tr = string.maketrans(...) > and want a table which produces the same characters lowercased. > > `tr.lower()' works - at least with Python 2.3 - but is that will > that remain reliable? Or should I use something like this? > > string.maketrans("".join(map(chr, xrange(256))), > "".join(map(chr, xrange(256))).translate(tr).lower()) Sure. The return value of string.maketrans is just itself a string, after all. > BTW, is there a simpler way to write "".join(map(chr, xrange(256)))? You could use a list comprehension if you prefer. -- __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ / \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis \__/ Procrastination is the thief of time. -- Edward Young From c-do-not-spam-me.whitley at earthlink.net Wed Aug 4 23:14:37 2004 From: c-do-not-spam-me.whitley at earthlink.net (Cecil H. Whitley) Date: Thu, 05 Aug 2004 03:14:37 GMT Subject: curses Message-ID: Hi, I had done a quick read of the curses documentation for python. Upon the second reading I found that curses is not supported on windows. I was wondering if it would be relatively simple to use the python wrapper for curses on unix (is there such a beast?) to wrap ncurses or the like on windows? Optionally, are there any major obstacles to writing a python wrapper for ncurses or any other curses-like library for windows? Thanks, Cecil From robey at slash_dev_slash_random.org Wed Aug 18 15:26:00 2004 From: robey at slash_dev_slash_random.org (Robey Holderith) Date: Wed, 18 Aug 2004 14:26:00 -0500 Subject: Embedding Python in Python Message-ID: Anyone know a good way to embed python within python? Now before you tell me that's silly, let me explain what I'd like to do. I'd like to allow user-defined scriptable objects. I'd like to give them access to modify pieces of my classes. I'd like to disallow access to pretty much the rest of the modules. Any ideas/examples? -Robey From lbates at swamisoft.com Mon Aug 30 11:02:40 2004 From: lbates at swamisoft.com (Larry Bates) Date: Mon, 30 Aug 2004 10:02:40 -0500 Subject: initializing mutable class attributes References: Message-ID: <29SdnfncSK8R3K7cRVn-sA@comcast.com> Dan, I too use class attributes to assign defaults, but do it like following: import copy class Father: _attr1default=None _attr2default=[] def __init__(self): self.attr1=self._attr1default # Get copy of attr2default self.attr2=list(self._attr2default) def foo(self, data): self.attr1=data self.attr2.append(data) class Child (Father): def __init__(self): Father.__init__(self) # # At this point self.attr1 (instance) # and self.attr2 (instance) hold their defaults # while _attr1/_attr2default (class) still hold # their default values for initialization of more # class instances. # HTH, Larry Bates Syscon, Inc. "Dan Perl" wrote in message news:sHGYc.93306$pTn.42032 at news01.bloor.is.net.cable.rogers.com... > I will clarify something that was probably not clear enough in my initial > posting. I am interested in instance attributes, but I am using the class > attributes to provide a default, "null", value for the instance attributes. > Yes, the instance attributes only mask the class ones, but a class attribute > and an instance attribute can be used like this: > class WorksForMe: > attr=None # used just as a default value for the instance > attribute self.attr > def foo(self): > self.attr=SomethingUseful( ) > def bar(self): > if self.attr: > useIt(self.attr) > else: > ignoreIt(self.attr) > This makes it safe for an instance of WorksForMe to invoke bar( ) even if it > never invoked foo( ). > > "Benjamin Niemann" wrote in message > news:cgul4v$h1d$1 at online.de... > > That's the way it is supposed to work. Instance attributes have to be > > initialized via self.foo=..., usually in __init__() which in turn is > > *STRONGLY* advised to class its parents __init__() - or you create > > instance attributes 'on-the-fly' when they are used for the first time > > (useful technique for mixin classes without constructor). Class > > attributes are initialized once for the class and are shared between > > instances. > > You are confirming the code I suggested but you don't share my view that > such code is awkward. I think I I was actually conservative calling it > awkward, I would rather call it unsafe. If I were a third-party library > vendor, I would not be comfortable providing a mixin class that forces users > to either invoke the parent's __init__ in their constructors or to > initialize the instance attributes on-the-fly. The latter would even be > against the principles of encapsulation, users should not need to know about > the parent's attributes, especially because they may change in future > releases. Both ways of restricting the use of the mixin class are unsafe > because they are easy to be ignored by users. And it is not only the users' > fault if they do not follow the restrictions, it is also my fault to put > such restrictions in the first place. > > I think this points to a weakness in Python as an OO language. I'm not > trying to bash it, but my understanding is that Python is still evolving in > that respect and I think that this should be improved in the future. Then, > on the other hand, maybe I'm the only one feeling this way and there's not > going to be a change. > > > "self.attr1=data" in Father.foo() doesn't "override" the Father.attr1 > > attribute you defined before. It creates an instance attribute that > > shadows Father.attr1! > > Both attribute assignments in Father are OK - if you treat them as class > > attributes. They won't become instance attributes by hidden magic. > > > > Dan Perl wrote: > > > There is something with initializing mutable class attributes that I am > > > struggling with. I'll use an example to explain: > > > class Father: > > > attr1=None # this is OK > > > attr2=[ ] # this is wrong > > > def foo(self, data): > > > self.attr1=data > > > self.attr2.append(data) > > > The initialization of attr1 is obviously OK, all instances of Father > > > redefine it in the method foo. But the initialization of attr2 is wrong > > > because all the instances of Father end up sharing the same value. > Maybe > > > that is desired sometimes, but usually it is just a bug. > > > > > > So the only solution I see to this is to initialize attr2 in __init__: > > > class Father: > > > attr1=None > > > def __init__(self): > > > self.attr2=[ ] > > > > > > This is already awkward because there is such a difference between attr1 > and > > > attr2. But moreover, I think this forces subclasses of Father to do > > > something like this: > > > class Child (Father): > > > def __init__(self): > > > Father.__init__(self) > > > self.attr3=[ ] > > > > > > I find this even more awkward because many people will forget to do it. > > > Clearly, this is then a more general issue with __init__, but I think it > is > > > accentuated by the fact that you HAVE TO HAVE __init__ in order to > > > initialize attributes that are mutable. > > > > > > Is there something I don't know here and there is a better way to do > this in > > > Python? I would like to get a better solution or otherwise start a > > > discussion. > > > > From brianc at temple.edu Thu Aug 12 11:23:49 2004 From: brianc at temple.edu (brianc at temple.edu) Date: Thu, 12 Aug 2004 11:23:49 -0400 Subject: Verbosity Check Style Message-ID: <807a54e8.6ec229a2.8239a00@po-d.temple.edu> I would like to get people's views on the best way to implement verbosity (or any command-line option) into python scripts. The three styles I'm wrestling with are: def func(): #do stuff if VERBOSE: print #something useful to know if wanted or... if VERBOSE: def func(): #do stuff print #something useful to know if wanted else: def func(): #do stuff or... def vfunc(): #do stuff print #something useful to know if wanted def func(): #do stuff if VERBOSE: func=vfunc The former has the benefit of readability. The latter two examples the benefit of being faster. Is there any other great pythonic ways to do this? I'd like to sample the smorgusborg of styles this list usually offers. Thanks in advance, Brian PS. I'd like to extend an extra thanks to all the large brain's in jars here. I'm just finishing a summer internship at a Pharmaceutical Company customizing/optimizing scripts/programs to do very high end computational chemistry. (Why I'm a bit obsessed with speed) I have absolutely no chemistry background and before I started only a year doing python for small data processing challenges. Through being able to read this list fairly constantly I've been able to make such a big splash here (things that used to take days, now take minutes) in my small amount of time that they'd like to give me a laptop to keep me on as a contractor during the school year. Thank you all so very much for giving a 19 year old a bright future and a way to pay for college. From rogerb at rogerbinns.com Mon Aug 9 18:43:48 2004 From: rogerb at rogerbinns.com (Roger Binns) Date: Mon, 9 Aug 2004 15:43:48 -0700 Subject: Popular Python projects with lots of pure Python code References: Message-ID: <9ablu1-peu.ln1@home.rogerbinns.com> Brett C. wrote: > So I am trying to come up with a list of projects I can use to get my > stats from. the stdlib is a no-brainer. Also plan to use Docutils. > But beyond those most of the big Python projects I can think of have a > ton of C code which is of no use to me. I don't need to be able to > run it, just going to be compiling to .py files. ZOPE/Plone. BitTorrent. Have a look on SourceForge. http://sourceforge.net/softwaremap/trove_list.php?form_cat=178 Other than the 10,000 clones of BitTorrent and projects that use Python very peripherally, there are many appropriate projects. My BitPim project has 30,000 lines of Python, 2,500 lines of description files which are compiled into 41,000 lines of Python and 500 lines of C/C++. It does GUI stuff, talks on serial ports to cell phones, has XML-RPC remoting over secure connections, has installation code, uses external data sources such as CSV, vCards as well as Outlook, Evolution etc. Consequently that gives you a nice wide spread of things the code does. If you do use it, feel free to send me email if you have any questions or need help. There is also a presentation I did which gives a good overview: http://bitpim.org/papers/baypiggies/ Roger From deetsNOSPAM at web.de Thu Aug 19 16:02:22 2004 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Thu, 19 Aug 2004 22:02:22 +0200 Subject: ZeroDivisionError: float division (baby steps) References: <6daa8765.0408191133.2f2e22e3@posting.google.com> Message-ID: I reduced the code to the lines that actually do something with count: > count= 0 > count= count + 1 > count= count -1 This yields count beeing 0 - thus you get a ZeroDivisionError, as one has to expect for division by zero.... I'm not totally sure what you actually want, but it seems to me that you should indent the lines count= count + 1 sum= sum + number to the same level as the loop - that will make them part of the loop, so you actually get some numbers accumulated. -- Regards, Diez B. Roggisch From chris.cavalaria at free.fr Sat Aug 14 07:56:53 2004 From: chris.cavalaria at free.fr (Christophe Cavalaria) Date: Sat, 14 Aug 2004 13:56:53 +0200 Subject: AntiDecorator metaclass References: Message-ID: <411dfe05$0$6142$626a14ce@news.free.fr> Paul Morrow wrote: > One of the beautiful things about Python is its clear, minimal syntax. > So we must resist adding new syntax to the language, especially where > there is a reasonable alternative. > > I believe that Stefen Eischet's suggestion for automatically determining > a method's type (class/instance/static) from the name of its first > formal parameter is a reasonable alternative to any/all of the decorator > syntax proposals. Here is another one that forgot that decorators aren't limited to classmethod and staticmethod. Therefore, that proposal alone isn't an alternative to any other syntax. If you want to say that decorators should be limited to classmethod and staticmethod, say it and give us a good reason, a very very good reason. From dbickett at gmail.com Tue Aug 17 20:48:11 2004 From: dbickett at gmail.com (Beeyah) Date: 17 Aug 2004 17:48:11 -0700 Subject: simple Thread question References: Message-ID: <1d6cdae3.0408171648.1b8767ea@posting.google.com> adeger at netlibrary.com (adeger) wrote in message news:... > def run(self, name): > import time > for i in range(1,11): > print 'thread ', name, ' instance ', str(i) > time.sleep(1) You're importing the time module for every TestThr() object you create, that's no good. You only need to import the module once, at the beginning of the file like you've done with threading. From p_s_oberoi at hotmail.com Mon Aug 9 17:20:59 2004 From: p_s_oberoi at hotmail.com (Paramjit Oberoi) Date: Mon, 09 Aug 2004 16:20:59 -0500 Subject: Purely emotional perspective References: <10hf3oaltbo7o74@corp.supernews.com> Message-ID: > And the usual argument (submit a patch!) doesn't really work when those > who want to avoid many changes try it... I've been *not* submitting a > patch on lots of changes to Python, but somehow it's never been > accepted. ;-) > > -Peter QOTW!! I have to say though, that @ decorators are starting to grow on me even though I was strongly against that syntax at first. -param From ben at benlast.com Tue Aug 17 09:09:44 2004 From: ben at benlast.com (Ben Last) Date: Tue, 17 Aug 2004 14:09:44 +0100 Subject: How big can a Python program be? In-Reply-To: <903b3fba.0408170333.49ce3944@posting.google.com> Message-ID: Unless I've misremembered, the Python interpreter executes lines as they're entered, whether read from a file or typed in (with the exception that blocks of code made up of multiple lines are executed when the last line is complete), so in theory, one could feed code to Python indefinitely and it'd just keep going. If the execution of those lines doesn't continually require more memory, then arguably one answer is "as long as you have CPU time to interpret it". ben > -----Original Message----- > From: python-list-bounces+ben=benlast.com at python.org > [mailto:python-list-bounces+ben=benlast.com at python.org]On Behalf Of > vronskij at post.sk > Sent: 17 August 2004 12:33 > To: python-list at python.org > Subject: How big can a Python program be? > > > Hi, > > A C program can be hundreds of thousands lines of code big. > C++ millions. > > How about Python? > > Suppose , you are a sole programmer (lonewolf). How many lines > can one handle? > > Thanks, > > > jan bodnar > -- > http://mail.python.org/mailman/listinfo/python-list From peter at engcorp.com Fri Aug 20 15:29:23 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 20 Aug 2004 15:29:23 -0400 Subject: age of Python programmers In-Reply-To: <3064b51d.0408201047.40a9e9d8@posting.google.com> References: <3064b51d.0408201047.40a9e9d8@posting.google.com> Message-ID: beliavsky at aol.com wrote: > "Lucas Raab" wrote in message news:... > >>One thing I've always kind of wondered is what is the average age of a >>Python programmer?? What age groups use Python?? Something to think >>about.... > > Related question -- at what age can Python be taught to a bright, motivated child? I expect to be old enough to teach Python to a bright, motivated child or two (maybe even mine) in a few more years. ;-) -Peter From amk at amk.ca Thu Aug 5 15:40:48 2004 From: amk at amk.ca (A.M. Kuchling) Date: Thu, 05 Aug 2004 14:40:48 -0500 Subject: Quixote vs. Preppy References: <1779534897.20040805105519@MailBlocks.com> Message-ID: On Thu, 5 Aug 2004 10:55:19 -0600, Bruce Eckel wrote: > programmer"), but someone also suggested Preppy from Reportlabs: > http://www.reportlab.org/preppy.html Preppy looks like a templating library, not an arbitrary web framework, so the direct comparison is to Quixote's PTL. It should be straightforward to use Preppy templates from a Quixote handler function, something like: import preppy def _q_index (request): d = {'name':'amk', ...} m = preppy.getModule('template') return m.run(d) (The Quixote Wiki at http://www.quixote.ca/qx/ also includes examples showing Quixote with other templating libraries such as SimpleTAL. The tips on http://www.quixote.ca/qx/TemplatingWithZpt are probably relevant.) --amk From darragh.sherwin at gmail.com Fri Aug 27 08:37:21 2004 From: darragh.sherwin at gmail.com (Darragh Sherwin) Date: Fri, 27 Aug 2004 13:37:21 +0100 Subject: Call for signatories for J2 In-Reply-To: <3A81C87DC164034AA4E2DDFE11D258E3022E6F@exchange.hqamor.amorhq.net> References: <3A81C87DC164034AA4E2DDFE11D258E3022E6F@exchange.hqamor.amorhq.net> Message-ID: <8abf17020408270537332bc0d7@mail.gmail.com> I vote FOR for the J2 syntax, it is more pleasant on the eye than the current @ syntax The only thing is the 'using' keyword does not seem right. -- Darragh Sherwin OpenOffice.org Developer for Propylon http://www.propylon.com +353-1-4927456 From pwatson at redlinepy.com Thu Aug 19 11:38:33 2004 From: pwatson at redlinepy.com (Paul Watson) Date: Thu, 19 Aug 2004 10:38:33 -0500 Subject: Interface to win32 resources Message-ID: <2ojvrqFbj9ttU1@uni-berlin.de> I need to access Win32 PE resources (strings, dialogs, etc.). Yes, I see that I can do it using Mark Hammond's win32all. I am using _winreg which comes with Python to access the registry. I could also access the registry through win32all. Is there or has there been any discussion of a _winres to access resources? I would rather use a module that comes with Python that to require the user to install win32all. This would reduce complexity and possibly resistance to using a Python application. From greg at invalid.invalid Fri Aug 20 04:23:42 2004 From: greg at invalid.invalid (Greg Krohn) Date: Fri, 20 Aug 2004 08:23:42 GMT Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: My vote: C1 D2 J2 Greg Krohn From nnorwitz at gmail.com Thu Aug 19 00:09:00 2004 From: nnorwitz at gmail.com (Neal Norwitz) Date: 18 Aug 2004 21:09:00 -0700 Subject: introspection? References: Message-ID: Jim Benson wrote in message news:... > > How does one get the class and method name from within > a method? >>> import sys >>> class C: ... def foo(self): ... print self.__class__.__name__, sys._getframe().f_code.co_name ... >>> C().foo() C foo Neal From mattjensen at timetospare.net Mon Aug 30 01:07:05 2004 From: mattjensen at timetospare.net (Matthew K Jensen) Date: 29 Aug 2004 22:07:05 -0700 Subject: os.popen problem References: <173c23bb.0408282255.2f1be2ee@posting.google.com> <1093798880.792738@news.commspeed.net> Message-ID: <173c23bb.0408292107.5287c0af@posting.google.com> "Tom B." wrote in message news:<1093798880.792738 at news.commspeed.net>... > "Matthew K Jensen" wrote in message > news:173c23bb.0408282255.2f1be2ee at posting.google.com... > > Ok, this might seem odd as to why I am doing this in this certain way, > > but it's for a very specific purpose, and in so doing needs to be done > > this way. I am writing code on a winbloze box like so: > > > I have never gotten popen to work correctly in windows, maybe you could > try writing a batch file or download The Python for Windows extensions > at http://starship.python.net/crew/mhammond/ and do something like. > > from win32com.client import constants > import win32con > import win32com > shell = win32com.client.Dispatch("WScript.Shell") > shell.Run('notepad.exe') > shell.SendKeys('And now for something completely different') > > but SendKeys only sends to the window with focus > > Tom > -- I have to be running the command "copy con somefilename". And I have to be able to tell this command to terminate in the normal fashion. Normally when operating on the command line, one uses either F6 or Ctrl-Z. This is a very old trick stemming from oldschool DOS. I can't specify why I am doing this certain thing this way, for reasons of not giving away the idea I have prematurely. I guess the real problem is right where I input '^Z'. Does anybody have any clue on how to do this? From mattjensen at timetospare.net Sun Aug 29 01:05:11 2004 From: mattjensen at timetospare.net (Matthew K Jensen) Date: 28 Aug 2004 22:05:11 -0700 Subject: Help req: py2exe's compiled executables only working with XP Message-ID: <173c23bb.0408282105.4cd76e07@posting.google.com> I am a young programmer with his big break on the line. For some reason, small apps that I've written and compiled on an XP machine won't work on anything but XP machines. I can't find any clue as to what's going on. Is the problem py2exe or something in my own scripts? I am at the end of my rope and I'm hoping someone out there can give me a pointer of two. Respectfully with full recognition that a lot of you are smarter than me, Matt K Jensen From python-url at phaseit.net Mon Aug 2 11:08:15 2004 From: python-url at phaseit.net (Peter Otten) Date: Mon, 02 Aug 2004 15:08:15 GMT Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Aug 2) Message-ID: QOTW: "We can't really say much more about thread safety than this, we think the interpreter will survive. The rest is up to the programmer." - Donn Cave "Despite the seemingly endless necessity for doing so, it's actually not possible to reverse-engineer intended invariants from staring at thousands of lines of code (not in C, and not in Python code either)." - Tim Peters Marduk wants to use string formatting with an arbitrary iterable instead of a tuple. Hans Nowak posts a format function that fits the bill. http://groups.google.com/groups?selm=40FF1A61.9050408%40zephyrfalcon.org The release of IronPython 0.6, a Python implementation for .Net and Mono, spawns a broader discussion on the merits of .Net and the Common Language Runtime. http://groups.google.com/groups?threadm=278de0e.0407281353.27b6a457%40posting.google.com http://www.ironpython.com Christopher T. King takes a closer look at Yaroslav Bulatov's attempt to benchmark various approaches to sum many floating point numbers. http://groups.google.com/groups?threadm=Pine.LNX.4.44.0408011847510.21160-100000%40ccc4.wpi.edu Premshree Pillai writes an SMS-to-LiveJournal gateway in Python http://www.livejournal.com/users/premshree/33967.html How would you iterate over a list two consecutive items at a time? That's a the heart of jblazi's question, and it turns out that there are two ways to do it. http://groups.google.com/groups?threadm=pan.2004.07.31.12.27.23.547000%40hotmail.com Patrick Rutledge has written an introduction on how to create games using pygame. http://www.linuxjournal.com/article.php?sid=7694 Is Python fully thread-safe? Jeff Epler is poking fun at the questioner, but Francois Pinard (sorry, no cedilla today) points the discussion into a more serious direction. http://groups.google.com/groups?threadm=mailman.775.1090684870.5135.python-list%40python.org "Btw, thank you for those footnotes in Thinking in Java that encouraged me to try Python :-)" - Dan Bishop. Bruce Eckel, author of "Thinking in Java", asks for a test for string similarity. He receives various answers and a thank-you. http://groups.google.com/groups?threadm=mailman.958.1091195562.5135.python-list%40python.org Dan Sugalski has lost the "Pie-thon" bet to Guido van Rossum that Python would run faster on Parrot, the virtual machine meant to power Perl 6. Images of Guido throwing the pie are finally available. http://www.onlamp.com/pub/wlg/5346 http://www.oreillynet.com/pub/a/oscon2004/friday/index.html ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous 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 newsgroup weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Brett Cannon continues the marvelous tradition established by Andrew Kuchling and Michael Hudson of intelligently summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Business Forum "further[s] the interests of companies that base their business on ... Python." http://www.python-in-business.org The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donate.html Cetus collects Python hyperlinks. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://aspn.activestate.com/ASPN/Cookbook/Python Among several Python-oriented RSS/RDF feeds available are http://www.python.org/channews.rdf http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi http://python.de/backend.php For more, see http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. *Py: the Journal of the Python Language* http://www.pyzine.com Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. From nobody at nowhere.com Tue Aug 24 14:19:07 2004 From: nobody at nowhere.com (Fred) Date: Tue, 24 Aug 2004 20:19:07 +0200 Subject: Python and C, looking for a C IDE References: <6f402501.0408240353.2a5b8a84@posting.google.com> Message-ID: <0h1ni0hjqggrk2atp7ao31a6l1dn2ctobk@4ax.com> On 24 Aug 2004 04:53:13 -0700, fuzzyman at gmail.com (Michael Foord) wrote: >I'm looking to learn C to move some 'speed sensitive' code from C to >python. I'm partly doign this as an exercise to learn a static >language to help broaden my programming skills - so please don't jump >on the bandwagon and tell me I'd be better placed to put my efforts >into optimising my python code !! ... or you could take a look at writing this speed-sensitive part in PowerBasic. The speed and size of C, without the hassles :-) http://www.powerbasic.com/products/pbdll32/ I haven't yet looked at how to compile a DLL in PowerBasic and call it from Python, but it's on my to-do list. Fred. From peter at engcorp.com Mon Aug 30 09:18:39 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 30 Aug 2004 09:18:39 -0400 Subject: Announcing PyCs, a new Python-like language on .Net In-Reply-To: References: Message-ID: Mark Hahn wrote: > This is an announcement of the beginning of development of a new > Python-like language called PyCs (pronounced "pie-cees"). Reacting merely to the name, I'd say this smells "fishy". ;-) (Non-English speakers, please note the winky and consider homonyms with a sign of the Zodiac before saying I'm being rude.) -Peter From quaggy at gmail.com Sat Aug 28 17:58:30 2004 From: quaggy at gmail.com (Jonathan Wright) Date: 28 Aug 2004 14:58:30 -0700 Subject: OT: simple compiled languages? In-Reply-To: <7xzn4fu188.fsf_-_@ruckus.brouhaha.com> Message-ID: Hi Paul, You might be interested in http://www.llvm.org or http://www.cminusminus.org/. Jonathan. From jeff at ccvcorp.com Fri Aug 6 15:58:34 2004 From: jeff at ccvcorp.com (Jeff Shannon) Date: Fri, 06 Aug 2004 12:58:34 -0700 Subject: tweaking @decorator syntax In-Reply-To: References: Message-ID: <10h7ombdaruuae9@corp.supernews.com> Andrew Durdin wrote: > >5. In appearance it looks like a special kind of statement; and it is >not at all obvious to me that it is rather a kind of attribute or >modifier of the following function definition. I don't know of any >other construction in Python that performs a similar, unmarked (i.e. >non-explicit) modification of the following statement. So to me the >@syntax comes across as extremely un-Pythonic (by that I mean >radically inconsistent with the conventions of the rest of the >language). For this same reason, I dislike all the proposed syntaxes >which involve placing something before the "def" without a subsequent >indented block. > > Ah, yes! Thank you for expressing the thing that's been really bugging me about this syntax, but which I hadn't quite managed to put into coherent words. I kept thinking that having all that stuff "stacked up" above the function def looked horribly ugly, but I couldn't quite express why... but I think you've hit on it exactly, there. The fact that it adds punctuation to an otherwise low-punctuation language compounds matters, and I too would rather see a keyword than a punctuation mark (though I do also understand the reluctance to add new keywords). But really, it's the placement rather than the punctuation that truly grates on my eyes. Hm, just as an experiment... def f(x,y): '''tests two ints for equality ''' @accepts(int, int) @returns(bool) return x == y I still don't care for the @, but this looks much less jarring to me. At very least, the decorators are much more clearly associated with the particular function. Jeff Shannon Technician/Programmer Credit International From bokr at oz.net Fri Aug 27 01:54:08 2004 From: bokr at oz.net (Bengt Richter) Date: 27 Aug 2004 05:54:08 GMT Subject: Static properties References: <1gj5e8n.xujsah4chw0gN%aleaxit@yahoo.com> Message-ID: On Thu, 26 Aug 2004 23:01:49 +0200, aleaxit at yahoo.com (Alex Martelli) wrote: >Per Erik Stendahl wrote: > >> Hello everyone, >> >> Is it possible to define "static properties" in a class? > >Yes, but only by defining a custom metaclass to be the type of that >class. Properties are defined in the type, not in the instance; so, for >a class itself to have properties, the class's type, commonly known as >its metaclass, must be the one defining them. Um, UIAM a property is just a peculiar descriptor, which you can define without resorting to metaclass magic. See below ... > > >>>> class metaPath(type): >... def curdir(cls): return os.getcwd() >... curdir = property(curdir) >... >>>> class Path: __metaclass__ = metaPath >... >>>> print Path.curdir >/Users/alex/cb/dblite/dblite_0.5 > > >_However_...: > >>>> print Path().curdir >Traceback (most recent call last): > File "", line 1, in ? >AttributeError: 'Path' object has no attribute 'curdir' >>>> > >if you want to be able to get at property curdir on INSTANCES of Path as >you normally would for a staticmethod, yet with property syntax, I think >you need to get a bit more clever than this... descriptors don't get >looked up two metalevels up, only one... > But you only need one: >>> class Path(object): ... class curdir(object): ... def __get__(self, inst, cls): return os.getcwd() ... curdir = curdir() ... >>> import os >>> Path.curdir 'C:\\pywk\\clp' >>> Path().curdir 'C:\\pywk\\clp' I wonder if I'll beat you to this post ;-) Regards, Bengt Richter From pepijn.kenter at nospam.dlr.nl Fri Aug 20 04:36:17 2004 From: pepijn.kenter at nospam.dlr.nl (Pepijn Kenter) Date: Fri, 20 Aug 2004 10:36:17 +0200 Subject: Array of objects in numpy. Message-ID: <2olrdjFbgdd0U1@uni-berlin.de> Hi all. I'm new to python and want to use it for an assignment. I have succesfully implemented a galois field class including the _repr__, __mul__, __div__, __add__ and __sub__ methods. Basically a galois field is an integer modulo a prime number. Now I want to make a matrix of these galois field objects using the numpy library. Constructing, printing and multiplying arrays of GF's works fine. However there are several functions that give problems, most importantly: dot, repeat. I'm affraid I've forgotten my memmory stick with the code and error messages :-(, so I have to keep my question general. If I recall correctly, the repeat function complained that my GF object didn't have the __getelem__ method implemented (IMO this should not be necessary), the dot function complained about an unsupported type. I know this is not the preffered way of asking for help on usenet but I'd like some feedback so I can work this weekend on the problem. I can use the dot & repeat with normal numpy arrays of floats, so I'm sure it is not due to my inexperience with python. Does anybody have experience using object arrays in numpy? Should I be able to get the dot & repeat function working, and what methods should my GF object support? Or are there known problems and pitfalls? Any help would be appreciated. Regards, Pepijn Kenter. From al at biolinux.ch Tue Aug 3 08:37:47 2004 From: al at biolinux.ch (Antoine Logean) Date: 3 Aug 2004 05:37:47 -0700 Subject: intersection of 2 strings Message-ID: Hi, What is the easiest way to get the intersection of two strings in python (a kind a "and" operator) ? ex: string_1 = "the_car_of_my_fried_is_bigger_as_mine_but_my_girlfriend_is_more_beautifull" string_2 = "my_girlfriend_is_more_beautifull_and_has_blue_eyes" and the intersection : string_1 "and" string_2 = "my_girlfriend_is_more_beautifull" thanks for your help Antoine From aleaxit at yahoo.com Sat Aug 28 12:05:24 2004 From: aleaxit at yahoo.com (Alex Martelli) Date: Sat, 28 Aug 2004 18:05:24 +0200 Subject: Are decorators really that different from metaclasses... References: <412C09B4.5070106@yahoo.com> <412D9F1E.6000809@yahoo.it> Message-ID: <1gj8q2n.1fbrmbet624ssN%aleaxit@yahoo.com> Paul Morrow wrote: ... > Cool! Thanks! Now I need to ponder why a function's docstring needs a > different implementation than a class's docstring (i.e. why not just > make it a straigtforward attribute of the function object). Historically, functions had docstrings before they had straightforward attributes. Maybe it could be that. Alex From lbates at swamisoft.com Fri Aug 6 09:56:54 2004 From: lbates at swamisoft.com (Larry Bates) Date: Fri, 6 Aug 2004 08:56:54 -0500 Subject: Standalone Python Programs... References: Message-ID: <-aSdndbo7ry5E47cRVn-ig@comcast.com> I've found that py2exe and Inno Setup Installeer to be a good combination (for Windows). It isn't a single executable, but then what modern program is any more. It doesn't require distribution/installation of Python. I've used it to install some pretty complex combinations (wxWindows, PIL, ReportLab, etc.) with no problems. Inno Setup has proven to be flexible enough to install everything that I've done so far. I can't speak to Linux installations because I have always just used the Python installation already there. HTH, Larry Bates Syscon, Inc. "uri bushey" wrote in message news:ceugpq$35rs$1 at netnews.upenn.edu... > I have a Python program that is built on an infrastructure of quite a > few other programs, but I would like to create a standalone nonetheless. > > It doesn't necesarily have to be its own executable, although this is > the most attractive option - it could just mean distributing the entire > python distribution with it in an installer or something. > > However, here is what I have called in my python file: > Tkinter, and multiple Pmw widgets > WaveSurfer, called as a "Wsurf" widget, which is a great little program > used for Spectrograms of wave files etc. It relies on Tcl/Tk and the > SNACK library, which also have to be installed for my script to work. > > Can anyone help? I'm open to any option, py2xe, mcmillan's, or cx_freeze > or whatever that program is, or even an installer that installs all of > those programs. > > I'm vying for the most elegant solution. > > Thanks! > > --uri From b.niemann at betternet.de Wed Aug 25 06:45:46 2004 From: b.niemann at betternet.de (Benjamin Niemann) Date: Wed, 25 Aug 2004 12:45:46 +0200 Subject: Why return None? In-Reply-To: References: Message-ID: Martin DeMello wrote: > Anthony Baxter wrote: > >>On Wed, 25 Aug 2004 08:26:26 GMT, Martin DeMello >> wrote: >> >>>It seems to be a fairly common pattern for an object-modifying method to >>>return None - however, this is often quite inconvenient. >> >>list.reverse() modifies the list in place. The python idiom is that >>these don't return a reference to the modified list. Although note the > > > Yes, but why? I mean, is there either an advantage to returning None or > some inherent danger in returning self? The danger is that you might forget about the side effect. l = [1, 2, 4, 3] sorted = l.sort() ... # do something with sorted list print l # I want to unsorted list here, but oops... In place object modification is often faster, but you loose the original data - this should be explicitly visible in the code From grante at visi.com Mon Aug 9 14:06:06 2004 From: grante at visi.com (Grant Edwards) Date: 09 Aug 2004 18:06:06 GMT Subject: how many bytes in an int References: <9ACRc.1523$bJ2.9739@news1.mts.net> <4116f8ee$0$8076$a1866201@newsreader.visi.com> <41171D06.6060507@v.loewis.de> Message-ID: <4117bd0e$0$65563$a1866201@newsreader.visi.com> On 2004-08-09, Reid Nichol wrote: > Thanks to all who helped. This is my solution (maybe overkill) but I > plan on adding read/write functions, etc (of course its just a first > thought). It seems to work, so any feedback is appreciated. As was just pointed out to me, if you specify byter order with '<' or '>', you don't have to guess/calculate lengths, they are fixed regardless of the underlying C types. IOW, struct does do exactly what you want. Just specify the byte order you desire. -- Grant Edwards grante Yow! I call it a "SARDINE at ON WHEAT"! visi.com From peter at engcorp.com Mon Aug 9 12:03:35 2004 From: peter at engcorp.com (Peter Hansen) Date: Mon, 09 Aug 2004 12:03:35 -0400 Subject: Purely emotional perspective In-Reply-To: <10hf3oaltbo7o74@corp.supernews.com> References: <10hf3oaltbo7o74@corp.supernews.com> Message-ID: Jeffrey Froman wrote: [...] > Now come decorators, introducing a non-alphabetic symbol (instead of say, a > new keyword), and worst of all for readability, they come *before* the > function declaration that they supposedly decorate. > > I understand that doing things this way has certain technical advantages, > but this is the first time I (in my short history with python) have noticed > readability being sacrificed for any reason. I think those pushing the syntax with decorators *before* the function def believe that *that approach* provides greater readability. This isn't an argument about whether or not decorators should be readable, but about what constitutes readability. Obviously this is largely a matter of opinion. I think putting them before the def right now is probably going to be seen by those folks as more readable, largely because they are not used to having decorators at all, so having them stand out right up front seems best. This is like the third, center brake light on cars though -- once every car had them, they stopped standing out quite so much, but it's too late to remove them now. After a while, when everyone is used to decorators, it won't be important to have them way out front like that, and they could just as well, and perhaps more readably (at that time), be moved to after the def. Unfortunately, whatever we start with will stick, so they will always be out front even though the advantages of that position will have evaporated. I say look to the future and realize that after a period of adaptation, we'll all be just as capable of spotting decorators, especially if they are still @ or | prefixed, if they come after the def, as in list-after-def or as in this: def func(some, arguments, that, might=span, multiple=lines): | staticmethod | foobarbaz(x=5) | doc('''A sample function''') # and the body goes here Yes, I know, people might think those lines are executed in the body of the function, every time through. Well, those people obviously didn't notice the decorator syntax, or read about decorators, so it's not important whether or not they think that, because they clearly won't understand anything about the function at this point. Those who know about decorators will know, as with some of the other warts of Python, that they are executed *after* the function is defined, not on execution. -Peter From fred at acme.com Sat Aug 21 08:50:40 2004 From: fred at acme.com (Fred) Date: Sat, 21 Aug 2004 14:50:40 +0200 Subject: [newbie] Strange behavior of the re module References: <2ejdi01btug5iskb4ipjpj7eaprd8i7vgm@4ax.com> <4126CFCC.8000609@zephyrfalcon.org> Message-ID: <86hei0prvp55iom91df23tffh04egefeig@4ax.com> On Sat, 21 Aug 2004 01:13:20 -0400, Tim Peters wrote: >I can't figure out what you're trying to accomplish here, but the >error msg makes sense. I'm actually writing a script that extracts parts of HTML pages, but some pages contain backslashes, which is why the script failed when massaging those particular pages. >>>> stuff=r"\colortbl\red0\gn0" >>>> template = "BLA" >>>> print re.sub('BLA', re.escape(stuff), template) That did it :-) Thx a bunch. Fred. From theller at python.net Wed Aug 18 12:10:45 2004 From: theller at python.net (Thomas Heller) Date: Wed, 18 Aug 2004 18:10:45 +0200 Subject: age of Python programmers References: <41237124.4060600@chamonix.reportlab.co.uk> Message-ID: Robin Becker writes: > Lucas Raab wrote: > >> One thing I've always kind of wondered is what is the average age of a >> Python programmer?? What age groups use Python?? Something to think >> about.... >> > 57, used to build my own logic using gas discharge tubes :) 48, but my first logic was build using 24V relays. From michele.simionato at gmail.com Sat Aug 7 03:40:24 2004 From: michele.simionato at gmail.com (Michele Simionato) Date: 7 Aug 2004 00:40:24 -0700 Subject: decorators and multimethods Message-ID: <4edc17eb.0408062340.71ab270f@posting.google.com> Decorators can generate endless debate about syntax, but can also be put to better use ;) Actually I was waiting for decorators to play a few tricks that were syntactically too ugly to be even imaginable for Python 2.3. One trick is to use decorators to implement multimethods. A while ago Howard Stearns posted here a recipe to implement generic functions a.k.a multimethods. I have not studied his recipe, so don't ask me how it works. All I did was to add an "addmethod" function and save his code in a module called genericfunctions. Decorators allowed me to use the following syntax: # BEGIN generic functions in Python, example # use code and examples from Howard Stearns from genericfunctions import Generic_Function, addmethod foo = Generic_Function() @addmethod(object, object, object) def foo(_, x, y, z): return 'default' @addmethod(int, int, int) def foo(call_next, x, y, z): return 'all ints , ' + call_next(x, y, z) @addmethod(object, object) def foo( _, x, y): return 'just two' print foo # the multimethod table as a dictionary print foo(1, 2, 'three') # => default print foo(1, 2, 3) # => all ints, default print foo(1, 'two') #> just two print foo('oops') #=> genericfunctions.NoNextMethod error # END generic functions in Python, example Howard Stearns' code is posted here http://groups.google.it/groups?hl=it&lr=&ie=UTF-8&threadm=40C3BC71.5050206%40charter.net&rnum=1&prev=/groups%3Fq%3Dhoward%2Bstearns%2Bgroup:comp.lang.python.*%26hl%3Dit%26lr%3D%26ie%3DUTF-8%26group%3Dcomp.lang.python.*%26selm%3D40C3BC71.5050206%2540charter.net%26rnum%3D1 I just added the following function: import sys def addmethod(*types): """sys._getframe hack; works when the generic function is defined in the globals namespace.""" caller_globs = sys._getframe(1).f_globals def function2generic(f): generic = caller_globs[f.func_name] generic[types] = f return generic return function2generic Decorators did all the rest ;) Just to add an use case I haven't seen before. Michele Simionato From news at grauer-online.de Fri Aug 27 08:36:24 2004 From: news at grauer-online.de (Uwe Grauer) Date: Fri, 27 Aug 2004 14:36:24 +0200 Subject: Boa Constructor error In-Reply-To: <4712d252.0408260804.c69cfee@posting.google.com> References: <4712d252.0408260804.c69cfee@posting.google.com> Message-ID: Parano wrote: > Hi > > I have a recurrent error in Boa Constructor, especially when I try to > activate code completion: a message box reads "UnicodeDecodeError: 'ascii' > codec can't decode byte 0xaa in position 52: ordinal not in range(128)" > I couldn't find any google resource on that error. > > I have Python 2.3.3 with Boa Construtor 0.3.1 on Mandrake Linux 10. > wxPython is from wxPythonGTK-py2.3-2.5.2.7-RH9.i386.rpm > I also tried wxPythonGTK2-py2.3-2.5.2.7-RH9.i386.rpm but had the same error. > Those RPMs are from www.wxpython.org where it says that "install and use on > my Mandrake 9.2 system without any troubles." > > Any tip on this? Thanks in advance Boa isn't ready for wxPython 2.5.x Use wxPython 2.4.2.4 instead. Uwe From balaji at email.arizona.edu Thu Aug 26 15:50:11 2004 From: balaji at email.arizona.edu (Balaji) Date: 26 Aug 2004 12:50:11 -0700 Subject: Newbie question on dictionary!!! Message-ID: <494182a9.0408261150.a4c767f@posting.google.com> Hello everybody... I want to ask a simple question. Suppose I have an list say g=['a','b','c','d'] and I have an dictionary say k={'b':20,'a':10} Now I want to sort this dictionary on the basis of the list and if it doesnt find any of the element in the list then I wud like to replace it with zero.. so I would like to modify k into {'a':10,'b':20,'c':0,'d':0} I have tried all the built in associated with dict and lists but was not able to come up with an solution... Can anyone help... From eppstein at ics.uci.edu Mon Aug 23 17:04:26 2004 From: eppstein at ics.uci.edu (David Eppstein) Date: Mon, 23 Aug 2004 14:04:26 -0700 Subject: Standard graph API? References: Message-ID: In article , mlh at furu.idi.ntnu.no (Magnus Lie Hetland) wrote: > > Do you have any design thoughts. It would be good to have weighted, > >directed graphs and depth first traversal. > > I've thought of several alternatives; basically, I just thought about > defining the "standard" API for the basic abstract data type > (including weights, direction, labels, colours etc.). Concrete > implementations and algorithms would be a separate issue. I would strongly prefer not to have weights or similar attributes as part of a graph API. I would rather have the weights be a separate dict or function or whatever passed to the graph algorithm. The main reason is that I might want the same algorithm to be applied to the same graph with a different set of weights. A secondary reason is that we already have in Python a good general mechanism (dicts) for associating arbitrary information with objects, I don't see a need for reinventing a more specific mechanism for doing so when the objects are pieces of graphs and the information is some list of weight, label, etc that some graph API designer thinks is sufficient. I think this may contradict some things I said a year or two ago about using a dict-of-dicts representation in which G[v][w] provides the weight; I've changed my mind. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ From fumanchu at amor.org Fri Aug 20 12:55:47 2004 From: fumanchu at amor.org (Robert Brewer) Date: Fri, 20 Aug 2004 09:55:47 -0700 Subject: python cgi speedup on iis Message-ID: <3A81C87DC164034AA4E2DDFE11D258E3022E16@exchange.hqamor.amorhq.net> Charlie Taylor wrote: > I'm looking for advice on how to speed up python cgi on > Windows IIS without > going to an application server like Zope/WebWare/CherryPy/etc > (i.e. I have > existing cgi scripts). > > mod_python seems like a good solution for Apache, is there something > comparable for IIS? > > I notice that ASP scripts run an asp.dll which I believe > becomes memory > resident to speed up VBScript execution. Yes. Using app protection "Low (IIS Process)" this allows you to keep Python modules in memory between requests. > Is there any work on a python.dll anywhere? There is a beta ISAPI floating around (sorry, Mark H., real busy!): http://groups.google.com/groups?selm=cdf3mb%2418b0%241%40arachne.labyrin th.net.au Robert Brewer MIS Amor Ministries fumanchu at amor.org From ptmcg at austin.rr._bogus_.com Fri Aug 6 06:23:44 2004 From: ptmcg at austin.rr._bogus_.com (Paul McGuire) Date: Fri, 06 Aug 2004 10:23:44 GMT Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) References: <338366A6D2E2CA4C9DAEAE652E12A1DE01C8C636@au3010avexu1.global.avaya.com> Message-ID: "Anthony Baxter" wrote in message news:mailman.1258.1091771072.5135.python-list at python.org... > Note that Guido has ruled this form out, in a pretty strong way ("I really > hate this"[1][2]) so if you want to change his mind, you'll need to come up with > arguments as to why he's wrong. > > I'm not saying that this isn't possible, more that merely collecting a concensus > vote isn't likely to do much. Strong technical arguments are much more likely > to work. > > > [1] http://mail.python.org/pipermail/python-dev/2004-March/043756.html > [2] http://mail.python.org/pipermail/python-dev/2004-August/046672.html > ... and a bunch of other posts in the archives. In http://mail.python.org/pipermail/python-dev/2004-March/043835.html, in response to Phillip J. Eby's observation that most of the list-after-def proponents have the most concrete examples, GvR states, "Maybe the practitioners are so eager to have something usable that they aren't swayed as much by esthetics." I'm not sure that any arguments are going to sway his view of what's esthetic, it sounds more like a subjective/gut reaction. I'll confess, in the past I *haven't* monitored the pydev list. Up to now I've been very comfortable with what I thought was the overall philosophy for the language, its general cleanness and simplicity of structure. The general recoil from all things Perl was generally in alignment with my own views - truly, some of the commentary on the obscurity and arcaneness of Perl's wanton use of punctuation helped clarify for me just what it was I disliked about it. Perhaps this is what jars me so about the introduction of the (to me unesthetic) '@'. So if this really comes down to personal taste, I'm not sure what "technical argument" will change that. It seems that all of the really technical issues have been raised, and, given no clear winner, Guido has fallen back on esthetics. It also seems that the passionate rejection at EuroPython of list-before-def had an influence on him - and I think that this poll was an attempt at conveying a similar passion against 'at-sign' (as we old folks call it). In the interests of putting forth technically-grounded response, I'd point to the post by daishi (subject: @decorators), that this new syntax breaks the basic heuristic of using indentation to indicate scope. What more core aspect of the language is there? -- Paul If I'd wanted to write in Java, I'dve written in Java. Keep Python Beautiful. From calidusdk at hotmail.com Mon Aug 23 12:28:46 2004 From: calidusdk at hotmail.com (Artemisio) Date: 23 Aug 2004 09:28:46 -0700 Subject: age of Python programmers References: <20040819231139.D039A1E4003@bag.python.org> Message-ID: <6daa8765.0408230828.6bdc2f0e@posting.google.com> Sakesun Roykiattisak wrote in message news:... > I'm 28. Have been using python for just one year. I was first > introduced to programming when I'm in 11 with 6502 machine (Apple II and > Oric-I) > So far I have 2 epiphany in my programming life. The first time is when > I finished chapther 3 of the Design Patterns book. > The second time is when I finished my first non-trivial python program. > > BTW, The histrogram suggest that python is not being used as the first > programming language as much as it should be. > > > > > I spotted some errors in your list, added new entries, and made a > > histogram: http://roelschroeven.net/pythonages/ > > I am 35. I discovered Python like 2 weeks ago, so I am nor a Python programmer neither a programmer. But if I compare my very short Pythonesque user experience to the pointless Basic and VB efforts in the previous decades, then I know that Python will stay with me for a long time, so count me in, won't you? From srijit at yahoo.com Tue Aug 24 11:03:09 2004 From: srijit at yahoo.com (srijit at yahoo.com) Date: 24 Aug 2004 08:03:09 -0700 Subject: Query on Boost (Python ) Message-ID: <221d8dbe.0408240703.6d9b08bf@posting.google.com> Hello, How will the Boost.Python C++ Wrapper look for structures similar to one mentioned below? typedef struct struct_TEMP { long length; char tempId[24]; long count; } TEMP_STRUCT; I tried to use Pyste but ended up getting the following error : cannot convert from 'const char [24]' to 'char [24]' So I am interested to learn how to write a proper interface file (.pyste) when I am using Pyste. Regards, Srijit From httpd at ncsa.uiuc.edu Sat Aug 28 05:59:58 2004 From: httpd at ncsa.uiuc.edu (httpd at ncsa.uiuc.edu) Date: Sat, 28 Aug 2004 04:59:58 -0500 Subject: {Virus?} Re: Hello In-Reply-To: <200408280959.i7S9xm318157@mail.ncsa.uiuc.edu> References: <200408280959.i7S9xm318157@mail.ncsa.uiuc.edu> Message-ID: <200408280959.i7S9xwT18266@mail.ncsa.uiuc.edu> [This message last updated January 21, 1998] Dear user: This is an automated message. The NCSA HTTPd is no longer a supported product. The web pages are still available. FAQ page: HyperNews page: Another source of answers to your questions may be the newsgroup comp.infosystems.www.servers.unix or comp.infosystems.www.providers Alternatively, the Apache Server (originally based on the NCSA HTTPd, and still a free server) is still actively developed. We recommend you take a look at it as a possible replacement for the NCSA HTTPd. For information about licensing NCSA HTTPD, contact Jae Allen at jallen at ncsa.uiuc.edu. NCSA HTTPd Technical Support From simoninusa2001 at yahoo.co.uk Thu Aug 26 14:35:05 2004 From: simoninusa2001 at yahoo.co.uk (Simon John) Date: 26 Aug 2004 11:35:05 -0700 Subject: Distributing Python applications - McMillan Installer question In-Reply-To: Message-ID: I've built Installer programs on SUSE 9.1 and RedHat9, and they kinda work across the two platforms - the RH9 one also works on Fedora C1 (but not RH7.3), and the SUSE one works on Linspire 4.5..... I'd say cx_Freeze is not much difference either, except it seems cleaner than the import hook used in MMI. But as far as building on Linux and running on HPUX, no chance, you might consider Jython/IronPython for that level of portability (or just supplying source). Your other option is using a packing system like Apt, RPM, SunPKG etc. and bundling Python and all dependencies with your program source (or hoping that the user already has Python installed). The whole *nix distribution issue is very complicated. Even the C++ guys using Qt at work here have huge issues getting code to work across HPUX/AIX/Linux/Solaris. From martindemello at yahoo.com Sun Aug 22 10:38:23 2004 From: martindemello at yahoo.com (Martin DeMello) Date: Sun, 22 Aug 2004 14:38:23 GMT Subject: serial iteration over several lists References: <1b5c4527.0408212257.5c9c18b4@posting.google.com> Message-ID: Brandon wrote: > How about this: > > >>> import itertools > >>> def mesh_flatten(meshes): > ... return itertools.chain(*meshes) [...] Thanks - that looks like an excellent starting point. Has there been any work done on bidirectional iterators? martin From anthonybaxter at gmail.com Thu Aug 19 14:02:16 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Fri, 20 Aug 2004 04:02:16 +1000 Subject: PEP 318: Can't we all just get along? In-Reply-To: References: <65adnQrUKILiC7_cRVn-jQ@powergate.ca> Message-ID: On Thu, 19 Aug 2004 07:52:38 -0400, Paul Morrow wrote: > I wrote: > > Look, name-mangling is horrid, and I don't think anyone's defending it. But > > at the same time, "name mangling is there" is not an argument for extending > > the horror to a whole new level. > > > > Name mangling only occurs when you create a method with two leading > > underscores, and no trailing ones. Your proposal would hit _every_ _single_ > > 'def'. It's nasty, it's unpythonic, and there's approximately _zero_ chance of > > it ever going into the language. Having said that, it's perfectly feasible to do > > it with a metaclass, and if you want to use it in your code, please, feel free. > > You didn't follow that one with a smiley either... :-) That's because I wasn't joking, at all. Look, your idea is a _bad_ one. Numerous people have pointed out why. Let it die. From donn at u.washington.edu Mon Aug 9 12:15:36 2004 From: donn at u.washington.edu (Donn Cave) Date: Mon, 09 Aug 2004 09:15:36 -0700 Subject: decorators vs GIL References: <8YudnZoJ4NdLEYjcRVn-jA@speakeasy.net> <0bidnfbR2_PZOIjcRVn-pA@giganews.com> <41162234$0$32536$626a14ce@news.free.fr> <411689bd$0$25588$636a15ce@news.free.fr> Message-ID: In article <411689bd$0$25588$636a15ce at news.free.fr>, Xavier Combelle wrote: > Anthony Baxter wrote: > >On Sun, 08 Aug 2004 14:57:12 +0200, Xavier Combelle > > wrote: ... > >Plenty - try this google search: > >http://www.google.com/search?q=site%3Adocs.python.org+GIL > >for a couple of simple ones, but there's plenty more - google for > >"python GIL" (or "python free-threading" for patches that were > >written against Python 1.4 to remove the single lock. They ended > >up slowing down Python significantly. > That is not really surprizing, the GIL is a very simple and very > efficient way to manage > multithreading. After reading, I can't undersand that other interpreted > languages don't do the same. > The use of GIL make that interpreter work as a single thread process. Right, and other languages do indeed do the same, for example I believe ocaml has a global lock - even though compiled to native code, it has the same kind of shared global state for storage and so forth. It is very effective, and it works fine for the kinds of things people usually do today with threads. If the computer of the future makes many processors available for concurrent processing, it won't work quite so well for that, but who knows what will happen. I'm not sure if I followed the rest of your post, but note that Python's thread architecture works well with blocking I/O. It just depends on the native code module that actually posts the I/O request to release the lock first, and recover it afterwards, so any other threads that may be waiting can be scheduled. On the other hand, there are often better ways to deal with blocking I/O than threads. Donn Cave, donn at u.washington.edu From grante at visi.com Tue Aug 17 12:30:07 2004 From: grante at visi.com (Grant Edwards) Date: 17 Aug 2004 16:30:07 GMT Subject: Newbie question about file input References: Message-ID: <4122328e$0$8079$a1866201@newsreader.visi.com> On 2004-08-17, Aaron Deskins wrote: > So why does a linesplit fail after the program reads a blank > line (or a '\n')? It doesn't. It just returns an empty list since there are not any non-whitespace characters to return. > Is this simply because there's no way to assign the variable '\n' ? I don't understand the question. -- Grant Edwards grante Yow! It's so OBVIOUS!! at visi.com From j_mckitrick at bigfoot.com Wed Aug 18 18:27:31 2004 From: j_mckitrick at bigfoot.com (j_mckitrick) Date: 18 Aug 2004 15:27:31 -0700 Subject: Problem with floating point precision References: Message-ID: Thank you guys for your help, here and privately. I knew about floating point precision issues, but never saw it crop up in my python project until one set of input numbers when 2 values that should have been the same were not. thanks! From newsgroups at jhrothjr.com Fri Aug 6 09:21:17 2004 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 6 Aug 2004 09:21:17 -0400 Subject: tweaking @decorator syntax References: Message-ID: <10h71e2o1u1u46f@news.supernews.com> "John Marshall" wrote in message news:mailman.1195.1091715452.5135.python-list at python.org... > On Thu, 2004-08-05 at 08:41, Sandy Norton wrote: > > On 4 Aug 2004, Christopher T King wrote: > > With the current choice and the list of alternatives you gave, > two things struck me about the location of the decorators > in the current choice: > 2) Can decorators easily be extended to apply to class > and module? Since I've never gotten my head around metaclasses, I suspect that I'd find the ability to simply declare a function that would "fix" a class at class definition time to be a real help. On the other hand, I'm not entirely sure what you'd use that ability for on the module level. John Roth From anthonybaxter at gmail.com Mon Aug 23 00:19:37 2004 From: anthonybaxter at gmail.com (Anthony Baxter) Date: Mon, 23 Aug 2004 14:19:37 +1000 Subject: Alternative decorator syntax decision In-Reply-To: <59e9fd3a04082221092ad0fa45@mail.gmail.com> References: <59e9fd3a04082221092ad0fa45@mail.gmail.com> Message-ID: On Mon, 23 Aug 2004 14:09:30 +1000, Andrew Durdin wrote: > C1 was the original proposal; I understood that Guido had written an > implementation some time ago. The python-dev archives might be useful > in locating it. There's a lot more to be done for it - if someone _really_ wants it, they should dig up the patch, make sure it's up to date, and then complete the other bits of it. See the post I made to the thread on J2 for references to what else needs to be done. Sorry if this sounds a bit like "put up or shut up", but that's the way it is - without a complete patch, it's not going to be considered. From usenet_spam at janc.invalid Wed Aug 18 14:50:46 2004 From: usenet_spam at janc.invalid (JanC) Date: Wed, 18 Aug 2004 18:50:46 GMT Subject: Windows URL protocol handler in python? References: Message-ID: john.burton at jbmail.com schreef: > Is there a way to make a handler in python presumably using the win32 > extensions to handle URLS of a specific type when they are given to > windows? > > For example if I want to handle > myprotocol://server/id > using my own python program? > Any suggestions or references would be appreciated. That's just an entry in the Windows registry As an example, this is how Xnews does it: ------------------------------ news-url.reg ------------------------------ Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\news] @="URL:news Protocol" "URL Protocol"="" "EditFlags"=hex:02,00,00,00 [HKEY_CLASSES_ROOT\news\DefaultIcon] @="\"C:\\Xnews\\Xnews.exe\"" [HKEY_CLASSES_ROOT\news\shell] [HKEY_CLASSES_ROOT\news\shell\open] [HKEY_CLASSES_ROOT\news\shell\open\command] @="\"C:\\Xnews\\Xnews.exe\" /url=\"%1\"" ------------------------------ news-url.reg ------------------------------ -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 From c0dec at gmx.de Sat Aug 28 05:03:56 2004 From: c0dec at gmx.de (Henning Kage) Date: Sat, 28 Aug 2004 11:03:56 +0200 Subject: Question about references/copies References: Message-ID: Am Sat, 28 Aug 2004 18:11:46 +1000 schrieb Anthony Baxter: > It's all references. If you want a copy, use the copy module. Ok, thanks. > A cast? Python has no static typing, so I'm unsure how or why you'd do a cast. As I said, I'm new to Python and as other languages do support such casts (as I know, in C# e.g. you have to do such casts if you are iterating over array lists and have to access the stored objects), I thought of it in Python too. From CJohnson at maxis.com Wed Aug 18 15:20:00 2004 From: CJohnson at maxis.com (Johnson, Corey) Date: Wed, 18 Aug 2004 12:20:00 -0700 Subject: replace line #1 with "newline\n" in text file Message-ID: <9D3D7CEF3A236243AF0335652672E34804CAC166@maxis-mb1.max.ad.ea.com> From noone at nowhere.com Sun Aug 1 13:42:26 2004 From: noone at nowhere.com (dusty) Date: Sun, 01 Aug 2004 17:42:26 GMT Subject: Noob question on PyQt and Qt Message-ID: <5m9qg0ds0g5c0k9tbgukm965au96rud6tm@4ax.com> I am learning Python and Qt designer (using eric3). I'm writing an app using QCheckList and have succeeded in loading parent and children, with checkboxes, with data from a file. I want to programmatically check some boxes depending on the string from the list. This is the code that I use to create the checkbox's: ~~~ d = QCheckListItem(it, lstI[g:], QCheckListItem.CheckBox) self.childlist1.append(d) ~~~ The first char in each line in 'lstI' determines if the checkbox should be checked or not. How do I change the checkbox to 'On' (checked) in Python code when the checkbox is created? From bob at redivi.com Wed Aug 11 11:29:50 2004 From: bob at redivi.com (Bob Ippolito) Date: Wed, 11 Aug 2004 11:29:50 -0400 Subject: [Python-Dev] A decorator syntax not yet mentioned (I think!) In-Reply-To: <1092237417.22674.12.camel@mango.cmc.ec.gc.ca> References: <1092237417.22674.12.camel@mango.cmc.ec.gc.ca> Message-ID: <492EA476-EBAB-11D8-87F8-000A95686CD8@redivi.com> On Aug 11, 2004, at 11:16 AM, John Marshall wrote: > How about the following, which I am almost positive > has not been suggested: > ----- > class Klass: > def __init__(self, name): > self.name = name > > deco meth0: > staticmethod > def meth0(x): > return x > > deco meth1: > classmethod > def meth1(cls): > return cls > > deco sayhello: > funcattrs(name='GvR', language='python') > log(file='func.log') > def sayhello(self): > print 'hello python world' > > ----- > 1) The decorators clearly apply to a specific method/function, > therefore there is no need to do any stack pushing in memory > until the method/function definition is done. None of that code can actually execute until the method/function definition is done, how is this different at all? > 2) The decorators are "outside" of the method/function they > decorate: > a) which will please those who want the outside location > b) will not be folded within the function Doesn't a) imply b)? > c) folding on the decorators can be done so that the > def is not obfuscated This could probably be done with the @syntax too if the editor was smart enough > d) can be located anywhere in the code--but most likely > before the "def ...()" I don't think that is a bonus at all. > 3) The sequence in which the decorators are applied is just > like code would be--this is certainly intuitive given > that we are writing code. That's not really obvious. > This approach could also be applied to classes in case > decorators should ever be extended to them: So can any of the other proposals. > ----- > deco Klass: > doc("This is a class to ...") > class Klass: > : > : > ----- > > Any comments? Yeah, this is no less than twice as bad as any of the current decorator proposals because you have to repeat the function name :) -bob From sbabbitt at commspeed.net Fri Aug 6 12:41:11 2004 From: sbabbitt at commspeed.net (Tom B.) Date: Fri, 6 Aug 2004 09:41:11 -0700 Subject: Queue qsize = unreliable? References: Message-ID: <1091810865.449263@news.commspeed.net> "James R. Saker Jr." wrote in message news:mailman.1284.1091808092.5135.python-list at python.org... > Thanks Peter, Mike & Michael on qsize - had a hunch it might be > "reliable but not advisable" in the aspect of queue data changing. > > Perhaps there's an easier way to accomplish what I'm attempting. I've > got a syslogd receptor that needs to: > > 1. have a thread sit on port 514 and receive input via syslog protocol > from various sources > > 2. receive input and put into a queue (ideally a persistent object so if > the receptor gets rebooted while there's work in the queue, data isn't > lost. i like the idea of ZODB's Persistence class for this - thoughts?) > > 3. have a thread sit and look for data in the queue. when data is found, > parse it and fire it off using BEEP to an upstream collector. > > I've done an initial version of this using Postgresql for an > intermediary (and twisted's database interface to deal with blocking > issues), but having to load Postgresql on a syslog2beep receptor is > overkill. A ZODB Queue implemented in a threaded app would seem the > right way to go. Any thoughts? > > Jamie > I wrote this on another reply just awhile ago but it also applies here, You should have a look at Pyro (Python Remote Objects) at http://pyro.sourceforge.net/index.html "It is an advanced and powerful Distributed Object Technology system written entirely in Python" Have a look at the rserve demo for a distributed object and the chat demo for an event server. Tom From bj_666 at gmx.net Sat Aug 28 15:24:17 2004 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Sat, 28 Aug 2004 21:24:17 +0200 Subject: Iteration over Lists and Strings References: <1gj80xs.1cfownoqz4m9N%aleaxit@yahoo.com> <5M4Yc.326126$a24.276550@attbi_s03> Message-ID: In <5M4Yc.326126$a24.276550 at attbi_s03>, Brent W. Hughes wrote: > Did you say enumerate(seq) takes constant time? I would have thought it was > proportional to len(seq). >>> seq = [1,2,3] >>> enumerate(seq) I guess creating a enumerate object (generator) takes constant time. ;-) Ciao, Marc 'BlackJack' Rintsch From pm_mon at yahoo.com Sat Aug 21 11:57:54 2004 From: pm_mon at yahoo.com (Paul Morrow) Date: Sat, 21 Aug 2004 11:57:54 -0400 Subject: __metaclass__ and __author__ are already decorators In-Reply-To: <59e9fd3a040821082410ac872d@mail.gmail.com> References: <59e9fd3a040821082410ac872d@mail.gmail.com> Message-ID: Andrew Durdin wrote: > On Sat, 21 Aug 2004 10:38:01 -0400, Paul Morrow wrote: > >>Thinking about decorators, and looking at what we are already doing in >>our Python code, it seems that __metaclass__, __author__, __version__, >>etc. are all examples of decorators. So we already have a decorator >>syntax. What is the compelling reason to invent a new one? And if we >>do, what's to become of the old one? > > > __author__ and __version in a class (as per your example) are setting > class attributes, not "decorating" the class anymore than the def's > that declare instance methods are. > Within a function, __author__ and __version__ are local variables, and > nothing more; specifically, assigning to them does *not* set function > attributes: > > >>> def foo(): > ... __author__ = "me" > ... return 5 > ... > >>> print foo.__author__ > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: 'function' object has no attribute '__author__' > >>> print foo.func_code.co_varnames > ('__author__',) > That's right. But we don't *use* __author__, __version__, etc. as class attributes --- we use them to supply metadata for the class. By that I mean that we don't intend for those attributes to be referenced by any methods of the class or users of the class. Those attributes are there strictly to supply information about the class. To 'decorate' the class. So the Python system will have to be changed to support this new way of thinking about __xxx__ attributes. They should no longer appear as local variables of a class or method, but instead as (meta) attributes of the class or method itself. So in your example def foo(): __author__ = "me" return 5 would be the same as def foo(): return 5 foo.__author__ = "me" > __metaclass__ on the other hand is a magic attribute. I haven't worked > out the details, but I have the feeling that what a metaclass does to > a class is not replicable merely by decorating the class; in other > words, that: > > class Foo: > __metaclass__ = Bar > > is *not* equivalent to > > class Foo: > pass > > Foo = Baz(Foo) > > for any definitions of Bar and Baz. This is just my intuition, however. Well, although it amounts to roughly the same thing class Foo: __metaclass__ = Bar would actually equate to either class Foo: pass Foo = metaclass(Foo, Bar) or class Foo: pass metaclass(Foo, Bar) depending on whether we decide that decorator functions should return new classes/functions (treating the decorated class/function as immutable), or allow them to modify the decorated function in place, in which case I guess they'd return None. Either way, I *can* imagine a definition of metaclass that could properly make Bar the metaclass of Foo. From kylotan at hotmail.com Sun Aug 29 10:02:44 2004 From: kylotan at hotmail.com (Kylotan) Date: 29 Aug 2004 07:02:44 -0700 Subject: Help req: py2exe's compiled executables only working with XP References: <173c23bb.0408282105.4cd76e07@posting.google.com> Message-ID: <153fa67.0408290602.10b80c47@posting.google.com> mattjensen at timetospare.net (Matthew K Jensen) wrote in message news:<173c23bb.0408282105.4cd76e07 at posting.google.com>... > I am a young programmer with his big break on the line. For some > reason, small apps that I've written and compiled on an XP machine > won't work on anything but XP machines. A better definition of what is going wrong than "won't work" is needed. Do the apps not run at all? Do they crash? Can you view the standard output/error streams to see if something is being written there? Bear in mind that py2exe doesn't produce compiled executables like those a C++ compiler might. It's more of an executable archive and all the files are right there. You can even open it up in an archiving program to check that all the relevant dlls and so on are added. Running a dependency-checker tool on some of those might reveal that you're relying on XP-only features, although that's usually evident from the Python code. -- Ben Sizer From greg at invalid.invalid Thu Aug 5 23:36:11 2004 From: greg at invalid.invalid (Greg Krohn) Date: Fri, 06 Aug 2004 03:36:11 GMT Subject: Poll - Vote here for "list-after-def" (was Decorator syntax) In-Reply-To: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> References: <6LWdnZCpvI7Ico_cRVn-hw@giganews.com> Message-ID: Istvan Albert wrote: > Paul McGuire wrote: > > Please reconsider the "def f() [classmethod]:" construct. I concur. The @ construct is atrocious and *very* unpythonic. I would choose no changes at all over implementing the @ construct. list-after-def is much, much, *much* better. Greg Krohn (I feel more strongly about this than I did (do) about PEP 308.) From peter at engcorp.com Tue Aug 24 10:07:45 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 24 Aug 2004 10:07:45 -0400 Subject: I've seen things you people wouldn't believe... ;-) (was Re: age of Python programmers) In-Reply-To: References: <20040819231139.D039A1E4003@bag.python.org> Message-ID: <896dnZfdH8-l1rbcRVn-qw@powergate.ca> Andrea Griffini wrote: > I think that *most* professional > programmers are not regular readers of usenet newsgroups > about the languages they use... not only that... IMO in > the bigger part they don't actually know what usenet > newsgroups are. And most didn't even read any book on the > languages and tools they use unless that happened when > they were still at school. > > I've personally lived totally absurd situations where > experienced programmers were just spending a lot of time > and energy (and were making a lot of mistakes) because > they never heard about make tools. I'm NOT kidding. > > I've seen things you people wouldn't believe... ;-) I think many of us would believe it. We've been there. How many could post stories of companies without any form of revision control, except perhaps those printouts in Winnifred's bottom drawer from last year? Or people who resorted to print statements during a ten-hour debugging session when they had a convenient, powerful, and easy to use source level debugger sitting on their machine and a programmer at the next desk who knew how to use it and could have found the failing code in about five minutes. Or ... well, I posted this mainly to change the thread subject so that if this turns into another mega thread it won't pollute the excellent "age of Python" programmer thread. ;-) -Peter From sharidas at zeomega.com Fri Aug 13 00:54:13 2004 From: sharidas at zeomega.com (Satchidanand Haridas) Date: Fri, 13 Aug 2004 10:24:13 +0530 Subject: while and if In-Reply-To: References: Message-ID: <411C4975.1030803@zeomega.com> Calvin79 wrote: >Hi, > >I'm very new to python, but believe in learning from examples. So could >someone please help me with this? > >I choose a number of 'things' I want > >Number = input("Number of things (1-8)? ") >things = ['1', '2', '3', '4', '5', '6', '7',\ >'8'] > >>From there I want to take at random a letter and do this n times depending >on the number I gave. > >choice = choice('abcd') > >The final answer if say the number had been 5 to look something like; > >choice 1 = d >choice 2 = c >choice 3 = a >choice 4 = d >choice 5 = b >etc... > >I can sort of see how to use the while loop for int but not to keep >choosing from the list and lable it choice 1 etc... > >Thanks for any help, > >Calvin > > > The following code does what I think you want to do: import random things = range(int(raw_input("Number of things (1-8)? "))) for x in things: print "choice ",x+1, " is ", random.choice('abcd') Regards, Satchit ---- Satchidanand Haridas (sharidas at zeomega dot com) ZeOmega (www.zeomega.com) Open Minds' Open Solutions #20,Rajalakshmi Plaza, South End Road, Basavanagudi, Bangalore-560 004, India From peter at engcorp.com Wed Aug 4 08:10:47 2004 From: peter at engcorp.com (Peter Hansen) Date: Wed, 04 Aug 2004 08:10:47 -0400 Subject: asyncore, asynchat and threads In-Reply-To: References: <7cKdnShvevY_3Y3cRVn-iA@powergate.ca> Message-ID: Joshua Moore-Oliva wrote: > I have to not return any data until there is data to > return for that specific connection. If there is some > way to send data down a asynchat > socket from another thread (thread-safely), or to > somehow wake up an asynchat class, that would be great. It's been years since I used asyncore (I find Twisted much simpler to use) but at least in theory such a thing is possible. Twisted has a callFromThread() method that can be used to get a callback in another thread to be called from the "reactor" (the equivalent of the asyncore core loop), which would do what you want. Asyncore might have similar facilities. I don't _fully_ grasp what you are doing, and I don't work well without pictures in such cases (got a whiteboard handy? draw a picture and send me a digital photo :-), but so far it doesn't sound like you have anything approaching unusual, compared to many other applications I've seen doing the sorts of things yours seems to be doing. -Peter From peter at engcorp.com Fri Aug 6 19:06:07 2004 From: peter at engcorp.com (Peter Hansen) Date: Fri, 06 Aug 2004 19:06:07 -0400 Subject: Importance of C# (was Re: IronPython-0.6 is now available!) In-Reply-To: References: <278de0e.0407281353.27b6a457@posting.google.com> <5dydnZSDZaARoZXcRVn-ug@powergate.ca> <9418be08.0407292114.129c856f@posting.google.com> Message-ID: Indrek Kruusa wrote: > A little comparison of C#, perl and python here (Speed test in menu): > > http://www.tuleriit.ee/progs/ After a quick glance over it, I would say that is not Python! Or rather, it's just the same C# code implemented in primitive Python that doesn't try to take advantage of the libraries that exist (except for time.strptime). There is a "csv" module which should eliminate much of the drudgery of parsing the csv files containing the data. I suspect there are some other significant improvements that could be made as well. Language comparison is a hard thing: what happens when you pick a test case that can be handled much more easily in one language than in another? Do you pick a new test case, or write inefficient code that no programmer experienced in that language would actually write? I'm not sure of the answer... but would probably be helpful to explain which choices you have made, so as not to mislead readers who are unfamiliar with one of the languages. (For example, I suspect the Perl code could be much shorter as well, but I don't know much Perl so I couldn't say. What I do see there would give me no reason at all to consider Perl instead of C# or Python.) -Peter From __peter__ at web.de Wed Aug 4 13:12:18 2004 From: __peter__ at web.de (Peter Otten) Date: Wed, 04 Aug 2004 19:12:18 +0200 Subject: help: Unit test fixture returning the same object References: <9895e897.0408031533.26720ba0@posting.google.com> <9895e897.0408040851.21ac7caa@posting.google.com> Message-ID: Michael McCracken wrote: > I did try the global count idea, and I did get an increasing count, > despite the same id oddity. So new instances seem to be getting > created, with the same data structures. I don't think I'm accidentally > using class variables, and that is the only thing I can think of. Any > more tips? 1 Make a minimal script showing the offensive behaviour 2 Post it on c.l.py Incidentally, step 2 is often unnecessary, because the error (if any) is found in 1 :-) More concrete, you could inhibit garbage collection of File instances by keeping old files around, e. g. in a global list. If ids are still the same you are definitely seeing the effect of a coding error. Peter From peter at engcorp.com Sun Aug 22 11:30:15 2004 From: peter at engcorp.com (Peter Hansen) Date: Sun, 22 Aug 2004 11:30:15 -0400 Subject: On consensus decision-making (was Re: Alternative decorator syntax - POLL RESULTS SO FAR - ARE WEDONE?) In-Reply-To: References: Message-ID: Robert Brewer wrote: > Doug Holton wrote: >>Just make a poll with J2 vs. C1 and see what you find. > > I don't see the point at this stage. I've put 20 hours into a document > for J2 this weekend, and would really like to start working on consensus > for it now. If you want to write a similar document for C1, feel free. > The time for voting is over, IMO. The voting was merely to narrow down the choices. It seems pretty clear there are now only three candidates in the running, the @pie syntax plus J2 and C1. The latter doesn't yet have an implementation, which is almost certainly its biggest disadvantage (and not that more people voted for J2 than for it). I suspect many of the J2 and C1 people would actually not "block" a decision to go with either one versus @pie. I'm not sure how many people would like to block @pie or either or both of the other two options. In the end, we already know that the final decision is (thankfully) made by the BDFL based on his own good judgement, so voting becomes less and less valuable at this stage. (In consensus building, a "block" basically says that someone would refuse to support the community decision, while 100% consensus means no one blocks the decision even though some people may not feel it reflects their first choice.) By the way, I found a page that appears nicely to sum up the ideas behind consensus decision-making. It's interesting that it says "don't vote" near the end, but I believe that ignores the utility of a choice-narrowing vote as we have had. It does suggest nobody should be considering this vote to have any weight in terms of directly determining the final decision. http://www.coreroi.com/consensus.htm -Peter From luismg at gmx.net Wed Aug 18 13:21:50 2004 From: luismg at gmx.net (Neuruss) Date: 18 Aug 2004 10:21:50 -0700 Subject: age of Python programmers References: Message-ID: <278de0e.0408180921.6bbe064a@posting.google.com> 34, and I hope the loop keeps on adding 1 for a long time... From grante at visi.com Mon Aug 30 14:03:15 2004 From: grante at visi.com (Grant Edwards) Date: 30 Aug 2004 18:03:15 GMT Subject: "Content-Length" header References: Message-ID: <41336be3$0$8079$a1866201@newsreader.visi.com> On 2004-08-30, Justin wrote: > I have a program that downloads files from the web. There are > instances in which a .info() will not return a "Content-length" header > to me. Is ther a way to specifically request this header or FORCE it > to be sent? I know there is some way to get the file size for these > files because Internet Explorer is capable of determining the size on a > cut / paste of the same exact url. Didn't like the answers you were getting in the other thread? -- Grant Edwards grante Yow! If elected, Zippy at pledges to each and every visi.com American a 55-year-old houseboy... From http Wed Aug 25 16:24:57 2004 From: http (Paul Rubin) Date: 25 Aug 2004 13:24:57 -0700 Subject: authentication service for unix References: Message-ID: <7xn00jt17q.fsf@ruckus.brouhaha.com> "Diez B. Roggisch" writes: > I'm looking for a method to authenticate users for a corba application > server, running under linux. I want to be able to authenticate users that > are valid unix users. Having role/group information would be nice later on. AF_UNIX sockets under Linux provide an "ancillary message" operation that lets you check the user id of the process at the other end of a socket. Unfortunately, Python's socket module doesn't support that operation. I have a Sourceforge bug in about it and may someday get around to writing a patch, but of course you're welcome to do it first ;). From mark_bottjer at hotmail.com Thu Aug 12 13:17:59 2004 From: mark_bottjer at hotmail.com (Mark Bottjer) Date: Thu, 12 Aug 2004 13:17:59 -0400 Subject: PEP318 In-Reply-To: References: <20040812090056.00001e31@titan> <7ttmh0t8c3cogtbhhnp1ohqu8b51pda461@4ax.com> Message-ID: <411ba648@nntp.zianet.com> Roy Smith wrote: > A solution to that is to factor out the function definition from the > name binding, so you would do something like: > > foo = def (): > whatever > > although by the time you do that, you might as well have just gotten rid > of def and used lambda() directly. If you wanted it to be a > static/class method, you would do: > > foo = staticmethod_def (): > whatever I agree that this seems to be the cleanest solution, but I also agree with you that it is a non-starter. Maybe when we get subclassable statements in Python 3.0. :) -- Mark From pwatson at redlinepy.com Thu Aug 19 11:14:55 2004 From: pwatson at redlinepy.com (Paul Watson) Date: Thu, 19 Aug 2004 10:14:55 -0500 Subject: newbie References: Message-ID: <2ojufgF9efhjU1@uni-berlin.de> "JASON JESSO" wrote in message news:mailman.1958.1092926275.5135.python-list at python.org... > I'm trying to add a mode to a mkdir program a got off > the python cookbook. > > The error I get is: > ./mkdir.py jason 0777 > Traceback (most recent call last): > File "./mkdir.py", line 31, in ? > _mkdir( sys.argv[1], sys.argv[2] ) > File "./mkdir.py", line 25, in _mkdir > os.mkdir( newdir, mode ) > TypeError: an integer is required > > When I convert the mode from a string to an octal with > oct(int(sys.argv[2])) the permissions are all screwed > up. Specifying the base on int() suggested by Peter is probably the best way. Here is another. $ python Python 2.1 (#1, May 23 2003, 11:43:56) [C] on aix4 Type "copyright", "credits" or "license" for more information. >>> import string >>> s = '0777' >>> v = string.atoi(s, 8) >>> v 511 >>> oct(v) '0777' From peter at engcorp.com Thu Aug 12 09:04:44 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 12 Aug 2004 09:04:44 -0400 Subject: The winner of the Python Decorator Poll is... In-Reply-To: References: <4edc17eb.0408112052.1bbd85b3@posting.google.com> <59e9fd3a04081122235b3d9145@mail.gmail.com> Message-ID: Christopher A. Craig wrote: > Andrew Durdin writes: >>Since you like the current proposal, why *didn't* you vote for it (it >>was the first one)? > > I didn't vote for it because I sit comfortable in the knowledge that > Guido will ignore the poll results. But he won't ignore a consensus proposal, and one step to forming a consensus is discussing the alternatives and understanding the ideas of others. Polls can help us do that, and can also make the discussion more efficient and focused if it shows clearly than certain alternatives are much disliked, as it may reduce discussion of those alternatives as its proponents realize it is less likely to win out. Given the number of people still suggesting alternatives that have already been suggested and rejected, it can only help... -Peter From steveo at eircom.net Sat Aug 28 16:34:07 2004 From: steveo at eircom.net (Steve O'Hara-Smith) Date: Sat, 28 Aug 2004 21:34:07 +0100 Subject: Larry Wall & Cults References: <7fe97cc4.0408251356.34f2102a@posting.google.com> <776e0325.0408260433.449660c8@posting.google.com> <412dfc1c$0$65599$a1866201@newsreader.visi.com> <86hdqpriww.fsf@blue.stonehenge.com> <412e199e$0$8076$a1866201@newsreader.visi.com> Message-ID: <20040828213407.18cc9f1e.steveo@eircom.net> On Fri, 27 Aug 2004 16:31:07 -0500 jdoherty at nowhere.null.not (John Doherty) wrote: > In article <412e199e$0$8076$a1866201 at newsreader.visi.com>, Grant Edwards > wrote: > > Of course, but are they consistently indented using tabs or > > spaces? > > AND HOW MANY SPACES PER TAB STOP? One half inch is my preference for tab stops usually. A tab is a tab and not some number of spaces. -- C:>WIN | Directable Mirror Arrays The computer obeys and wins. | A better way to focus the sun You lose and Bill collects. | licences available see | http://www.sohara.org/ From gh at ghaering.de Mon Aug 2 18:13:33 2004 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Tue, 03 Aug 2004 00:13:33 +0200 Subject: MySQLdb select In-Reply-To: <971323274247EB44B9A01D0A3B424C850B332555@FTWMLVEM02.e2k.ad.ge.com> References: <971323274247EB44B9A01D0A3B424C850B332555@FTWMLVEM02.e2k.ad.ge.com> Message-ID: <410EBC8D.4060909@ghaering.de> Raaijmakers, Vincent (GE Infrastructure) wrote: > I'm so glad that this issue is raised here. > Can someone help me in this thread explaining me how to use multiple parameters. > Jaco helped me already a lot and perhaps someone in this thread can give me the final answer: > > My table contains a blob and a bigint for storing images. The table name is also a variable, so the query looks like: > SQL = "INSERT INTO %s (number, image) VALUES (%s, %s)" > > Well, I get a mysql exception if the execution looks like: > cursor.execute(SQL, (tableName, aValue, jpgImage)) > > The execution only works when I fill out the data until the blob value is a 'left over' as a %s: > Yes, this looks ugly.. but it works... > > SQL = "INSERT INTO %s (number, image) VALUES (%s," % (tableName, aValue) ## table name and number > SQL += "%s)" ## left over... only the image > cursor.execute(SQL, jpgImage) > > Can someone explain this to me? While the DB-API way of passing parameters was neatly explained in other posts in this thread, there are still some places where you need to construct SQL manually, like in your case, where you dynamically insert the name of the table into your SQL string. A proper way to solve this task is to do it in two steps (untested code): SQL = INSERT INTO %s (number, image) VALUES %%s, %%s" % tableName cursor.execute(SQL, (aValue, jpgImage)) Note that the first line only inserts the table name into the SQL string. Because we want to still have 'VALUES %s, %s' in the SQL string after applying the % operator, we escape the percent signs with an additional percent sign. Then, in the second line, you can let the DB-API do all the real passing of query parameters for you. -- Gerhard From eric_brunel at despammed.com Thu Aug 26 13:15:48 2004 From: eric_brunel at despammed.com (Eric Brunel) Date: Thu, 26 Aug 2004 19:15:48 +0200 Subject: Distributing Python applications - McMillan Installer question References: <6f89f4fe.0408260823.3b856a34@posting.google.com> Message-ID: Chris wrote: > I would like to be able to "package-up" a Python application on my > development platform (Linux) so that it can be easily distributed and > installed on Windows and UNIX e.g. HP-UX, AIX etc. I'd rather not use > Python's disutils. > I've looked at cx_Freeze but this requires a "base executable" to be > available for each target platform i.e. I'd need to compile this base > executable on the target platforms but I don't have access to them > all. > I've had a quick look at the McMillan installer and from what I've > seen It's not clear to me whether this would do the job for me or not? AFAIK, it won't: you'll also need a base executable compiled for each platform you intend to run on, so you'll need an access to each machine type. And if McMillan Installer works quite well on Intel platforms (Windows and various Linuces), I've had some issues on Solaris that required some adjustements in the Installer's source code and a lot of help from Gordon. So don't expect something working "out of the box" on HP-UX or AIX... -- - Eric Brunel - PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com From a9605473 at unet.univie.ac.at Tue Aug 3 07:29:44 2004 From: a9605473 at unet.univie.ac.at (Gaubitzer Erwin) Date: Tue, 03 Aug 2004 13:29:44 +0200 Subject: How to dynamically access Numeric subarrays Message-ID: Hi there I wrote a short program which reads scientific data from a file and stores its values in a Numeric array. At the same time it reads the names of its dimensions which are then in the same order as the indices of the Numeric array. After then I want to access the data in the array by its name the way that I keep all indices at constant values except the one I want to read out which I am slicing. The problem is that the input data varies in its dimensions so my wanted data can appear at different positions of the array. I tried to create a list with the slice on the appropriate position to use it as indices list in the array but this failed. So my questions to out there: How can I extract a (Numeric Python) subarray whose indices have to be built dynamically. Thanks in advance Erwin From mwh at python.net Wed Aug 18 10:48:41 2004 From: mwh at python.net (Michael Hudson) Date: Wed, 18 Aug 2004 14:48:41 GMT Subject: Why is SETUP_FINALLY uninterruptable[sic]? References: <2JmdnSiV4NZzGL_cRVn-pg@lmi.net> Message-ID: "David Pokorny" writes: > "Jeff Epler" wrote in message > news:mailman.1836.1092794238.5135.python-list at python.org... > > >I suspect that this has something to do with code like > > > > l = some_lock() > > l.acquire() > > # MARK > > try: > > something with l held > > finally: > > l.release() > >If an asynchronous exception happens betwen l.acquire() and the > >SETUP_FINALLY opcode (at "MARK") , there's no guarantee that l.release() > >is executed. > > > >This state of affairs always existed with KeyboardInterrupt and/or > >signals, and it's hard to see how this fixes the problem if l.acquire() > >is Python code, but I think that's what's going on. > > I would belive you, but there is a trivial modification that circumvents > this problem: > > ---begin--- > mylock = some_lock() > > try: > mylock.acquire() > something with mylock held > finally: > mylock.release() > ---end--- Huh? If you typo the first mylock, or the acquire() call fails for some reason, that doesn't do what you want. Cheers, mwh -- Famous remarks are very seldom quoted correctly. -- Simeon Strunsky From tim.peters at gmail.com Thu Aug 5 13:39:48 2004 From: tim.peters at gmail.com (Tim Peters) Date: Thu, 5 Aug 2004 13:39:48 -0400 Subject: [Python-Dev] RELEASED Python 2.4, alpha 2 In-Reply-To: <411241F5.3080602@v.loewis.de> References: <411231C8.3020308@interlink.com.au> <411241F5.3080602@v.loewis.de> Message-ID: <1f7befae040805103911610582@mail.gmail.com> [Martin v. L?wis] > The Windows installer should support upgrading from a previous Python > 2.4 installation. If you have previously installed 2.4a1, you may try > this out; please report any problems you find. I tried that, and it seemed to work well, although it took a while. One glitch: I'm pretty sure I selected "install only for me" in the first screen. I wanted to go back to check, but it doesn't seem possible to go back to the first screen. Anyway, the Python DLL ended up in a system directory, and that's "the glitch". I expected/wanted it to end up in my Python directory. From h.b.furuseth at usit.uio.no Mon Aug 2 17:11:31 2004 From: h.b.furuseth at usit.uio.no (Hallvard B Furuseth) Date: 02 Aug 2004 23:11:31 +0200 Subject: __coerce__ vs. new-style classes References: <10gstrc1n27m8e8@news.supernews.com> Message-ID: I wrote: > Without __coerce__, what should __add__(self, other) do if it doesn't > know how to add the arguments, but the other argument might know how? > It can't just call other.__radd__(self): That might give up and call > __add__ again. Uh... please pretend I didn't say that. You are right, I haven't gotten coerce() straight yet. > In some cases it might help to call coerce() by hand, but I note the > ref manual says 'In Python 3.0, coercion will not be supported.'. Even so, coerce() by hand seems pretty cumbersome. The code I could come up with for the general case is as follows. Am I missing something again? class Myclass(object): def __add__(self, other): if not isinstance(other, Myclass): newself, other = coerce(self, other) if newself != self: return newself.__add__(other) # Or maybe the above should test if # newself.__class__ != self.__class__, and do # self = newself if they have the same class. ...real __add__(Myclass, Myclass) starts here... -- Hallvard From nomail at nospam.no Wed Aug 18 04:19:48 2004 From: nomail at nospam.no (Dominic) Date: Wed, 18 Aug 2004 10:19:48 +0200 Subject: Generators versus Coroutines In-Reply-To: <1a517b5.0408170923.48f6d964@posting.google.com> References: <1a517b5.0408170923.48f6d964@posting.google.com> Message-ID: > I've seen servers that rock written with explicit event handling, > threads, processes, and occasionally co-routines. Where are the > great generator-based servers? Well, the Erlang (language + telecom platform) uses light-weight threads which could e.g. be implemented with coroutines in Python. Event handling is fine but you could also explicitly code your behaviour as state machines ;-) The drawback of event handling is that you have to separate state and control flow and resuming is error prone whereas generators and coroutines are easier and feel more natural. Especially in simulations where you need lots of active entities, there is hardly a way around light-weight and deterministic concurrency. Take the SIMULA language as an example for the combination of simulation and coroutines. Ciao, Dominic From justin__devine at hotmail.com Mon Aug 30 17:31:54 2004 From: justin__devine at hotmail.com (Justin) Date: 30 Aug 2004 14:31:54 -0700 Subject: Size of a remote URL In-Reply-To: <41339697$0$65574$a1866201@newsreader.visi.com> Message-ID: linklisttype = ['http://www.ecs.soton.ac.uk/~harnad/temp/ariadne-rae.doc', 'http://www.ecs.soto n.ac.uk/~harnad/temp/ukparl.doc', 'http://www-admn.csun.edu/systech/techsupport/ procedures/2kcleanup.doc'] for y in linklisttype: temp = urlopen(y) temp2 = temp.info() print temp2 temp3 = temp2.getheader("Content-Length") print temp3 file_sizes.append(temp3) print file_sizes RESULT BELOW: Date: Mon, 30 Aug 2004 21:28:55 GMT Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12 OpenSSL/0.9.6b DAV/ 1.0.3 PHP/4.3.2 mod_perl/1.26 Connection: close Content-Type: text/html; charset=iso-8859-1 None [None] Date: Mon, 30 Aug 2004 21:28:55 GMT Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12 OpenSSL/0.9.6b DAV/ 1.0.3 PHP/4.3.2 mod_perl/1.26 Connection: close Content-Type: text/html; charset=iso-8859-1 None [None, None] Server: NetWare-Enterprise-Web-Server/5.1 Date: Mon, 30 Aug 2004 21:28:55 GMT Content-type: application/msword Last-modified: Tue, 30 Apr 2002 22:50:08 GMT Content-length: 297984 Accept-ranges: bytes Connection: close 297984 [None, None, '297984'] From paolo.veronelli at yahoo.it Fri Aug 20 09:11:59 2004 From: paolo.veronelli at yahoo.it (Paolino) Date: Fri, 20 Aug 2004 15:11:59 +0200 Subject: Alternative decorator syntax decision In-Reply-To: References: Message-ID: <4125F89F.1070401@yahoo.it> d2 d2 j2 Thanks for the piece of democracy From peter at engcorp.com Tue Aug 24 01:00:07 2004 From: peter at engcorp.com (Peter Hansen) Date: Tue, 24 Aug 2004 01:00:07 -0400 Subject: Getting at the bits of a 32-bit integer In-Reply-To: <412aa5a0$0$68775$a1866201@newsreader.visi.com> References: <85b54e91.0408231552.75f85727@posting.google.com> <412a98f4$0$65569$a1866201@newsreader.visi.com> <412aa5a0$0$68775$a1866201@newsreader.visi.com> Message-ID: Grant Edwards wrote: >>If you're new to Python and you are twiddling bits, the odds >>favor the new user falsely importing old paradigms from other >>languages, > > Probably so. Especially as the OP didn't say he was trying to break apart Ethernet headers, serial data streams, or suchlike. He just seems to want to grab a few bits for his own purposes, and like Jeremy I doubt that the need is real (though also like he I admit the possibility it could be!) and am quite curious to hear from the OP again... -Peter From sandskyfly at hotmail.com Thu Aug 5 04:41:57 2004 From: sandskyfly at hotmail.com (Sandy Norton) Date: 5 Aug 2004 01:41:57 -0700 Subject: tweaking @decorator syntax References: Message-ID: On 4 Aug 2004, Christopher T King wrote: > Of course, I prefer the nested block idea better (either with a new > keyword or new syntax), but I don't see those (especially the syntax one) > flying anytime soon. I know further discussion of this topic is feeling futile, but one can only hope. > Unless someone can come up with an idea everyone can agree on Real Soon > Now, I think the whole idea should be dropped and wait until 3.0. We'll > have plenty of time to argue about it then. Agreed. > Sorry about the long rant, but it felt good to get that all off my chest. Please, we need more rants like yours. Now if they could somehow collectively become a 'public outcry' (-; I realize my hasty initial post didn't actually show the present 2.4 form, so I've included it and added your variations for the sake of comparison: Current 2.4b Syntax ------------------- class Klass: def __init__(self, name): self.name = name @staticmethod def statmethod1(x): return x @staticmethod def statmethod2(y): return y @classmethod def classmethod1(cls): return cls @classmethod def classmethod2(cls): return cls @funcattrs(name='GvR', language='python') @log(file='func.log') def sayhello(self): print 'hello python world' @funcattrs(name='GvR', language='python') @log(file='func.log') def saygoodbye(self): print 'goodbye python world' Nested Alternative 1 -------------------- class Klass: def __init__(self, name): self.name = name @staticmethod def statmethod1(x): return x def statmethod2(y): return y @classmethod def classmethod1(cls): return cls def classmethod2(cls): return cls @funcattrs(name='GvR', language='python') @log(file='func.log') def sayhello(self): print 'hello python world' def saygoodbye(self): print 'goodbye python world' Nested Alternative 2 -------------------- class Klass: def __init__(self, name): self.name = name @staticmethod: def statmethod1(x): return x def statmethod2(y): return y @classmethod: def classmethod1(cls): return cls def classmethod2(cls): return cls @funcattrs(name='GvR', language='python'), log(file='func.log'): def sayhello(self): print 'hello python world' def saygoodbye(self): print 'goodbye python world' Perhaps, you can eliminate the '@' alltogether. This is definitely my favourite as it reads the way I think: Nested Alternative 3 -------------------- class Klass: def __init__(self, name): self.name = name staticmethod: def statmethod1(x): return x def statmethod2(y): return y classmethod: def classmethod1(cls): return cls def classmethod2(cls): return cls funcattrs(name='GvR', language='python'), log(file='func.log'): def sayhello(self): print 'hello python world' def saygoodbye(self): print 'goodbye python world' Alternative 4 (C T King) ------------------------ class Klass: def __init__(self, name): self.name = name decorate staticmethod: def statmethod1(x): return x def statmethod2(y): return y decorate classmethod: def classmethod1(cls): return cls def classmethod2(cls): return cls decorate funcattrs(name='GvR', language='python'), log(file='func.log'): def sayhello(self): print 'hello python world' def saygoodbye(self): print 'goodbye python world' Alternative 5 (C T King) ------------------------ class Klass: def __init__(self, name): self.name = name def statmethod1(x): [staticmethod] return x def statmethod2(y): [staticmethod] return y def classmethod1(cls): [classmethod] return cls def classmethod2(cls): [classmethod] return cls def sayhello(self): [decorate funcattrs(name='GvR', language='python'), log(file='func.log')] print 'hello python world' def saygoodbye(self): [decorate funcattrs(name='GvR', language='python'), log(file='func.log')] print 'goodbye python world' Methinks issues arise generally with the nested form in the case of: - v. long functions - using @decorators for annotating type info e.g: @accepts(int, str) @returns(str) def func(x, s): return s + str(x) But I didn't think that this was the purpose of introducing func decorators in the first place. Hey since we are in amateur language design mode , what the heck, let's play with that problem too: haskell-like: int, str -> str def funct(x, s): return s + str(x) boo-like: def func(x as int, s as str) as str : return s + str(x) a mix: def func(x as int, s as str) -> str: return s + str(x) examples of excessive colonic punctuation: def func(x:int, s:str): return (s+str(x)):str def func(x:int, s:str):str : return s+str(x) def func str:(int:x, str:s): return s+str(x) def func(x:int, s:str): return (s+str(x)):str Sheesh... I'm feeling nauseous and dizzy now so I think I'd better stop before I crap on my keyboard. Language design land is no place for amateurs with feeble tummies. ciao Sandy From michaels at rd.bbc.co.uk Fri Aug 20 10:10:06 2004 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Fri, 20 Aug 2004 15:10:06 +0100 Subject: Decorator keyword options References: <7knVc.4599$Jn5.3074@fe1.texas.rr.com> Message-ID: Paul McGuire wrote: > Please visit the PythonDecorators Wiki > page, and navigate to section 6.1 Indicators (or follow this link > http://www.python.org/moin/PythonDecorators#head-61f608dbce6ba75b2317d7825d8529997f56fc9e > ) > (not sure how reliable this is?) I have started numbering the options > in preparation for another voting thread, if you have other proposals, > please include them on this Wiki page, along with your +/0/- > commentary. A couple of comments I'd personally make... * If you look at longer lists of decorators, what strikes me personally is that any format is declaring properties of the function that follows. * It's worth considering is ability for people to search effectively for what a piece of syntax means, especially if it's something not likely to be heavily used by code. (Consider what happens if you google for the phrase: to be or not to be) For example would "properties" (not listed as an option) give any indication that the function is being changed? "decorate" to a greater extent does. "modifiers" or "decorators" (call a spade a spade?) might be clearer, is just a noun. A very useful way of dividing up decorators was posted a week or so back, which formed the structure of section 6. Personally I think something similar might be useful here: * Use noun or verb * If noun, singular or plural? (Sheep excepted) * If verb, active or passive * Hint at properties or actions * Whether to link with the def or not. "decorate" falls into the verb, passive, action category I think. "modifiers" falls into the noun, plural, property category I think. "using" would fall into verb, active, action, linked category Personally I think noun, plural, property is a non-starter for most situations (eg classmethod, staticmethod). There's probably similar examples that work well. Regards, Michael. -- Michael.Sparks at rd.bbc.co.uk British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From BruceEckel at MailBlocks.com Wed Aug 4 21:00:26 2004 From: BruceEckel at MailBlocks.com (Bruce Eckel) Date: Wed, 4 Aug 2004 19:00:26 -0600 Subject: Decorator syntax (was Re: PEP 318 - PyFIT comments) In-Reply-To: References: <1646998998.20040804190026@MailBlocks.com> Message-ID: I'll weigh in a little on this one. This is very similar to attributes/metadata in Java J2SE 5 and in C#. The thing is, metadata is a little bit weird; it's intentionally outside of the domain of the 'normal' programming language, because it expresses things that you can't or shouldn't within the normal programming language. So you _do_ need an escape mechanism. And it also takes a little bit of getting used to; it's orthogonal to what you normally think of as a language feature. But the potential for metadata features, at least in Java, is very powerful. I suspect that the influence comes from Java, where they are also using '@' (I don't recall what C# uses but it's very possibly also '@'), and this was, I believe, one of the last things put into J2SE 1.5, so (guessing again) I suspect that's why it showed up so late in Python -- the last thing I saw presented was attributes inside square braces, and the only question was where they should go. You can certainly argue that I'm more comfortable with it because I'm already familiar with and used to the '@' syntax and actually think it may be an improvement over [] because it may be more flexible -- at least it is in Java. I understand that many are uncomfortable with this feature and idea and syntax, but I think we'll find it has compelling value, and the fact that it is in both Java and C# (actually, it was invented for C# by Anders, I believe, and Java is catching up), and that it fills a need in Java that people were inventing comment syntax for, makes it worth considering. Bruce Eckel From peter at engcorp.com Thu Aug 26 07:11:57 2004 From: peter at engcorp.com (Peter Hansen) Date: Thu, 26 Aug 2004 07:11:57 -0400 Subject: Larry Wall & Cults In-Reply-To: References: <7fe97cc4.0408251356.34f2102a@posting.google.com> Message-ID: Michiel Borkent wrote: > "Peter Hansen" wrote: >>No, it's Esperanto (universal language) for "troll"... > Erm, please don't make false propaganda for the language I happen to love > ;). > > Btw: > > (english-to-esperanto "troll") ==> "trolo" Pardonu... estis sxerco, evidente! -Peter From jnc at ecs.soton.ac.uk Thu Aug 26 13:26:39 2004 From: jnc at ecs.soton.ac.uk (John Carter) Date: Thu, 26 Aug 2004 18:26:39 +0100 Subject: Call for signatories for J2 References: Message-ID: For John Carter From martin at v.loewis.de Mon Aug 23 00:59:43 2004 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 23 Aug 2004 06:59:43 +0200 Subject: 2 GB files In-Reply-To: <9418be08.0408221427.182a4d30@posting.google.com> References: <9418be08.0408221427.182a4d30@posting.google.com> Message-ID: <412979be$0$13042$9b622d9e@news.freenet.de> Elbert Lev wrote: > From postings to this group and other resources I understood that the > only way to make Python programs to work correctly with files lager > then 2 GB is building Python interpreter with some "magic spell" > defines. Why do you say that? This is not true. > I believe, that automatic 64 bit support (large files) can and should > be included in standard library (on platforms which support this > feature). And indeed, this is how Python works. Regards, Martin From hodges7 at cox.net Thu Aug 12 22:00:40 2004 From: hodges7 at cox.net (Bill Hodges) Date: Thu, 12 Aug 2004 21:00:40 -0500 Subject: undefined symbol: PyUnicodeUCS4_FromUnicode Message-ID: I just build PyQt from sources on Mandrake 10 and tried to run a le gacy application from a University that runs in several environments. I detectedno errors on the configuration or build and the qt.so is the same in the build directory as it is in the site-packages/qt.so. output is: psyco installed and used Traceback (most recent call last): File "/usr/local/lib/python2.3/site-packages/drt/drt.py", line 40, in ? from qt import * ImportError: /usr/lib/python2.3/site-packages/qt.so: undefined symbol: PyUnicodeUCS4_FromUnicode Any pointers on how to resolve? From dooms at info.LESS.ucl.SPAM.ac.be Fri Aug 20 08:04:01 2004 From: dooms at info.LESS.ucl.SPAM.ac.be (=?ISO-8859-1?Q?Gr=E9goire_Dooms?=) Date: Fri, 20 Aug 2004 12:04:01 +0000 Subject: Rita Sue and Bob too In-Reply-To: References: Message-ID: <4125ccff$0$62372$5fc3050@dreader2.news.tiscali.nl> Cyrille Lavigne wrote: > If you dont want them in order you should do: > >>if "Rita" and "Sue" and "Bob" in list: >> print "They were found" >>else: >> print "They are not in the list" Wrong ! see: In [6]: 'Rita' and 'Sue' and 'Bob' in ['Bob'] Out[6]: True > > Otherwise: > >>c,a=0,0 >>while c> if list[c]=="Rita": >> if list[c+1]=="Sue": >> if list[c+2]=="Bob": >> print "They were found" >> a=1 >> c=c+1 >>if a!=1: >> print "they are not in the list" > > but I'm sure there is a better way of doing this. > This second piece of code searches list for the sequence ['Rita','Sue','Bob'] in this order and without inserts. It can be rewritten in a more pythonic way : for i in range(len(l)): if l[i:i+3] == ['Rita','Sue','Bob']: print 'They were found' break else: print 'They were not in the list' -- Gr?goire Dooms