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