From ilias at lazaridis.com Sun Dec 25 23:47:31 2005 From: ilias at lazaridis.com (Ilias Lazaridis) Date: Mon, 26 Dec 2005 06:47:31 +0200 Subject: Indentation/whitespace In-Reply-To: <1135567568.622263.88450@g44g2000cwa.googlegroups.com> References: <1135360496.036672.326570@g47g2000cwa.googlegroups.com> <1135567568.622263.88450@g44g2000cwa.googlegroups.com> Message-ID: Robert Hicks wrote: > I disagree...I don't think the whitespace rule will ever be > "optional". Why would it be so? If someone doesn't like it...choose > another language. It is that simple really. > Robert It's not that simple. But let's simply await. We will know in 2 years. - TAG.python.evolution.whitespace . -- http://lazaridis.com From pinard at iro.umontreal.ca Tue Dec 13 20:57:02 2005 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Tue, 13 Dec 2005 20:57:02 -0500 Subject: Comparing dictionaries, is this valid Python? In-Reply-To: References: <20051214001716.GA2340@alcyon.progiciels-bpi.ca> Message-ID: <20051214015702.GA4559@alcyon.progiciels-bpi.ca> [Peter Hansen] >> it only says "Comparison operations are supported by all objects" >> [...] >I'm not checking the 2.3.5 version, but that latest one is fairly clear >on what comparisons on mappings do: >http://docs.python.org/ref/comparisons.html Yes, indeed. Thanks a lot! -- Fran?ois Pinard http://pinard.progiciels-bpi.ca From tim.hochberg at ieee.org Tue Dec 27 09:56:34 2005 From: tim.hochberg at ieee.org (Tim Hochberg) Date: Tue, 27 Dec 2005 07:56:34 -0700 Subject: python coding contest In-Reply-To: References: <43AEBD43.7080407@airlangen.de> <43AECBFA.2070209@stackless.com> <43b0b977@nntp0.pdx.net> <0v6sf.9742$9e.3250@tornado.texas.rr.com> Message-ID: Paul McGuire wrote: > "Shane Hathaway" wrote in message > news:mailman.2581.1135676005.18701.python-list at python.org... > >>I'm down to 133 characters (counted according to 'wc -c') on a single >>line. It contains about 11 whitespace characters (depending on what you >>consider whitespace.) It's way too tricky for my taste, but it's fun to >>play anyway. Has anyone done better so far? Here's a hint on my >>strategy: the code contains three large integers. :-) >> > > With 1 large integer, I am down to 200 characters on 1 multiline line. I > can guess why you have 3 integers vs. 1, but I don't see how that saves you > any characters of code. This is interesting. I have a six line solution that is 133 characters long. I use no long integers, which is what's interesting; two distinct solutions with the same length. I played with long integers for a bit, and I can see how one could use a single long integer, but no idea how one would use three. -tim From dickinsm at gmail.com Fri Dec 30 20:24:01 2005 From: dickinsm at gmail.com (Mark Dickinson) Date: Fri, 30 Dec 2005 20:24:01 -0500 Subject: python coding contest Message-ID: <5c6f2a5d0512301724l6ba60e34v968441eb30e8c40b@mail.gmail.com> Here's a variant of Andr?'s brilliant idea that's 119 characters long, and fully printable: j=''.join;seven_seg=lambda z:j(j(' _ | |_ _|_|' [ord('^r|=Zm.:v\r'[int(a)])%u*2:][:3]for a in z) +"\n"for u in(3,7,8)) Mark From codecraig at gmail.com Wed Dec 7 11:37:57 2005 From: codecraig at gmail.com (py) Date: 7 Dec 2005 08:37:57 -0800 Subject: uuDecode problem In-Reply-To: <1h76wc0.1icaljqjdsxt1N%aleax@mail.comcast.net> References: <1133966318.424045.186400@g49g2000cwa.googlegroups.com> <1h76wc0.1icaljqjdsxt1N%aleax@mail.comcast.net> Message-ID: <1133973477.785148.189340@g43g2000cwa.googlegroups.com> Alex Martelli wrote: > binascii.b2a_uu only works for up to 45 bytes at once; but if you were > feeding it more than 45 bytes, this should raise a binascii.Error > itself. > Definitely not, given the above limit. But I still don't quite > understand the exact mechanics of the error you're getting. > > > Alex here is an example. def doSomething(): data = aFile.readlines() result = [] for x in data: result.append(encode(x)) return result def printResult(encodedData): """encodedData is a list of strings which are uu encoded""" print decode(encodedData) encode(data): """data is a string""" if len(data) > 45: tmp = [] for c in data: tmp.append(binascii.b2a_uu(c)) return ''.join(tmp) else: return binascii.b2a_uu(data) decode(data): """data is a list of strings""" result = [] for val in data if len(val) > 45: response = [] for x in val: response.append(binascii.a2b_uu(x)) result.append(response) else: result.append(binascii.a2b_uu(val)) return ''.join(result) ...i would use those functions like data = doSomething() printResult(data) Now i get this... " response.append(binascii.a2b_uu(x)) java.lang.StringIndexOutOfBoundsException: java.lang.StringIndexOutOfBoundsExcep tion: String index out of range: 1" So the error is in the decode method .....this is in Jython...perhaps Jython doesn't handle binascii.a2b_uu ? or perhaps since the actual data is being encoded in python, then read in and decoded in my jython script..that could be the problem? thanks. From bokr at oz.net Tue Dec 6 12:08:43 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 06 Dec 2005 17:08:43 GMT Subject: i=2; lst=[i**=2 while i<1000] References: Message-ID: <4395c513.320349167@news.oz.net> On Tue, 06 Dec 2005 15:44:33 +0000, Steve Holden wrote: >Daniel Sch?le wrote: >> hi, >> >> [...] >> >> >>>># pseudo code >>>>i=2 >>>>lst=[i**=2 while i<1000] >>>> >>>>of course this could be easily rewritten into >>>>i=2 >>>>lst=[] >>>>while i<1000: >>>> i**=2 >>>> lst.append(i) >>>> >>> >>> >>>Neither of these loops would terminate until memory is exhausted. Do you >>>have a use case for a 'while' in a list comprehension which would >>>terminate? >> >> >> unless I am missing something obvious, I can not see why the loop should >> not terminate > >In that case, kindly explain how the condition i<1000 can become false >when it starts at 2 and never changes! [In other words: you *are* >missing something obvious]. > >> sure pseudo code is not executable but the other one works >> while tests the boolean expression first then decides whether to execute >> the body or not, in particular no next-iterator is involved(??) >> as it would be in >> lst=range(5) >> for i in lst: >> del lst[0] >> >Indeed. But the test condition is initially true, and can never become >false, so the loop is endless. It will probably eventually terminate by >throwing a MemoryError exception when lst and its element values use up >all available space. > >Don't you have an interpreter you could run the code in to verify that >it does indeed loop interminably? You seem to be assuming that the >expression i**2 changes the value of i. It doesn't. > No, but i**=2 does. Are you two talking about the same code? >>> i=2 >>> lst=[] >>> while i<1000: ... i**=2 ... lst.append(i) ... >>> lst [4, 16, 256, 65536] Regards, Bengt Richter From cvanarsdall at mvista.com Thu Dec 15 10:14:38 2005 From: cvanarsdall at mvista.com (Carl J. Van Arsdall) Date: Thu, 15 Dec 2005 07:14:38 -0800 Subject: Why and how "there is only one way to do something"? In-Reply-To: <1134658912.768421.312010@f14g2000cwb.googlegroups.com> References: <1134646944.453716.75850@o13g2000cwo.googlegroups.com> <1134649479.444890.193020@z14g2000cwz.googlegroups.com> <1134649959.077878.151430@g47g2000cwa.googlegroups.com> <1134652082.682017.284470@g47g2000cwa.googlegroups.com> <1134655105.795025.150700@g49g2000cwa.googlegroups.com> <1134658912.768421.312010@f14g2000cwb.googlegroups.com> Message-ID: <43A1885E.6040609@mvista.com> bonono at gmail.com wrote: > >>>> Would you, say, remove "for" loops because they could be written as >>>> "while" loops. Don't forget the word "obvious" that appears in that >>>> catchphrase ... >>>> >>>> >>> If every "for" usage can be done with "while" and that "while" is the >>> preferred way, why not ? As I said, the problem is that "obvious" >>> really is subjective in many case. And if it really is obvious, it >>> really is obvious and I doubt there would be that much disagreement. >>> I think comparing "for" and "while" loops in python is problematic. Although yes a "for" loop could be done with a "while" in python a "for" loop shouldn't be used for general looping, the "obvious" case for a "for" loop is to iterate though a list or something similar to that. I wouldn't typically use "while" loops for that, and although it could be done, if you were familiar with python using a "for" loop would be the most obvious. I think it really is obvious in most cases with python. Although, obvious to whom is a good question. If you don't know the language very little will be obvious to you, however one who is familiar with python (rtfm) would know which cases should obviously use "while" and which cases should obviously use "for" 2cents -- Carl J. Van Arsdall cvanarsdall at mvista.com Build and Release MontaVista Software From mwm at mired.org Wed Dec 7 20:55:04 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 07 Dec 2005 20:55:04 -0500 Subject: Mutability of function arguments? References: <1134001014.716406.10800@z14g2000cwz.googlegroups.com> Message-ID: <86fyp4xshz.fsf@bhuda.mired.org> "ex_ottoyuhr" writes: > I'm trying to create a function that can take arguments, say, foo and > bar, and modify the original copies of foo and bar as well as its local > versions -- the equivalent of C++ funct(&foo, &bar). C++'s '&' causes an argument to be passed by reference. Python does that with all arguments. Any changes you make to the argument in the function will be seen in the caller unless you explicitly make a copy to pass. > I've looked around on this newsgroup and elsewhere, and I gather that > this is a very common concern in Python, but one which is ordinarily > answered with "No, you can't. Neat, huh?" A few websites, newsgroup > posts, etc. have recommended that one ask for a more "Pythonic" way of > doing things; so, is there one, or at least one that doesn't involve > using objects as wrappers for mutable arguments? If your arguments are mutable, you don't need to do anything to be able to change them - just call the mutator methods. If your arguments aren't mutable, then you can't change them, either in the function or in the original namespace. If what you really want to do is rebind a variable in the calling namespace - well, you can't do that. The standard way to deal with the usual uses for passing references in C is to return the value (or values - Python handles multi-valued return and assignment much cleaner than C++) and rebind the variables at the point of the call. If you insist on writing C/C++ in Python, you can wrap an immutable object in an instance of class with a method to let you change it, as you suggest: > And, indeed, would that approach work? Would declaring: > class FooWrapper : > __init__(fooToLoad) : > self.foo = fooToLoad > mean that I could now declare a FooWrapper holding a foo, pass the > FooWrapper to a function, and have the function conclude with the foo > within the FooWrapper now modified? If you like an extended lambda calculus syntax, you can use my Ref class: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/456150. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From apardon at forel.vub.ac.be Thu Dec 1 06:26:41 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 1 Dec 2005 11:26:41 GMT Subject: Python as Guido Intended References: <43830213$0$84151$892e7fe2@authen.yellow.readfreenews.net> <1132678387.884058.107900@z14g2000cwz.googlegroups.com> <1132701667.183254.166910@g47g2000cwa.googlegroups.com> <86y83g1bww.fsf@bhuda.mired.org> <1132704024.711460.194310@f14g2000cwb.googlegroups.com> <1132768993.161352.260810@g49g2000cwa.googlegroups.com> <1132791525.595643.4710@g49g2000cwa.googlegroups.com> <86k6ey25y2.fsf@bhuda.mired.org> <1132863273.378601.323870@f14g2000cwb.googlegroups.com> <86fyplwwri.fsf@bhuda.mired.org> <86fypkim4x.fsf@bhuda.mired.org> <861x10v4ks.fsf@bhuda.mired.org> <86psoj2w0c.fsf@bhuda.mired.org> <864q5tomrv.fsf@bhuda.mired.org> Message-ID: On 2005-11-30, Mike Meyer wrote: > Antoon Pardon writes: >> On 2005-11-29, Mike Meyer wrote: >>> Antoon Pardon writes: >>>>> You see, you can make languages more powerful by *removing* things >>>>> from it. >>>> You cast this in way to general terms. The logic conclusion >>>> from this statements is that the most powerfull language >>>> is the empty language. >>> The only way you reach that conclusion is if you read the statement as >>> saying that removing things *always* makes a langauge more >>> powerful. That's not what I said, >> I would say it is the common interpretation for such a sentence. > > You'd be wrong. "Can" denotes a possibility, not a certainty. You didn't write: Removing things can make a language more powerfull. You wrote: You can make a language more powerfull by removing things. In the first case "can" describes a possible outcome of removing things. In the second case "can" describes that this is a decision you are allowed and able to make. Not the possibility of the outcomes should you make the decision. What your sentence states is that you can make this decision and that if you do so, removing things will accomplish this goal > If I'd > say "You *will* make languages more powerful by removing features", > then you'd be right. But that isn't what I said. No this states that I don't have a choice in removing features or not. Anyway that is how I read those sentences. I just want to add that I'm not interrested in whether your interpretation is the right one or mine. I understand now what you meant and that is enough for meu. The above should be considered as an explanation of how understood, not as a correction of how yuo should have wrote it. >>>>> We don't talk much about how you produce buffer >>>>> overfows in Python, but people have asked for that as well. Adding >>>>> ways to write hard-to-read code is frowned upon. And so on. >>>> Do you mean people have asked for the possibility that a buffer >>>> overflow would overwrite other variables? >>> Buffer overflows don't have to overwrite variables. They just asked >>> how you create buffer overflows in Python. >> I do wonder what they mean with a buffer overflow. Would the following >> classify: >> buf = range(10) >> buf[10] = 10 > > Well, you'd have to ask them. Personsally, I wouldn't count that, > because no data outside the scope of buf got written to. I find this odd. You seem to argue that you don't want bufferoverflows allowed in python, but then you don't seem to know what is meant by it. If you don't know what they mean, how can you decide you don't want it. And I seem to remember people asking about the possibility of overflow in Python, but I never understood those inquiries in the sense they would want it, but more in a sense of how python protects against it. So I have a bit of a problem understanding the relevance here. >>>>> I won't speak for others, but I wouldn't reject it out of hand. You >>>>> haven't provided enough information. Accepting it just because it adds >>>>> a way to do something is wrong. First, you have to ask whether or not >>>>> that something is something we want in Python at all. Then you >>>>> consider whether how the way proposed fits with the language: is it >>>>> ugly? >>>> That is a highly subjective question, answering it says more about >>>> the person then about the proposal. >>> True. But whether or not a language is good is a highly subjective >>> question. Since the goal - keeping python good to the people who >>> already consider it good - is subjective, it's only natural that part >>> of the evaluation process be sujectie. >>>>> Is it prone to abuse? >>>> I don't see why this is always brought up, given the number of >>>> features that can be abused in python. >>> Just because Python isn't perfect is no reason to make it worse. >> Why is it worse. You seem to think that if one has a toolbox, which >> lacks a hammer, that the fact that the hammer can be abused makes >> your toolbox less usefull if you add a hammer to it. > > Look again. I never said it would make Python less useful, I said it > would make it worse. Those aren't the same thing. It's possible to > make a language both more useful and worse at the same time. For > instance, Python would clearly be more useful if it could interpret > perl 6 scripts. I disagree. Having more possibilities doesn't imply more usefull. One of my nefews has this kind of army swiss knife with tons of possibilities. But I find the few tools I have that total less possibilities more usefull. Now adding a extra possibilty to the army swiss knife may make it worse, less usefull. Putting an extra tool in my toolbox doesn't make it worse or less usefull, since I can just ignore the tools I don't use. > Personally, I think adding the features required to do > that would make the language (much, much) worse. Oddly enough, I think > adding the features to Perl so it could interpret Python scripts would > make it better as well as more useful :-). > >> We have a toolbox, full of equipment that can be abused, yet >> that something else can be abused too, seems to be a mayor >> stumbling block for adding it. > > "Major" is your word, not mine. That is the impression I get from the emphasis that is always put on abuse possibilities of a proposed addition in this group. > I just listed it as something to > consider. It may be there's an obscure corner case that's really > abusive, but chances are no one would ever stumble over it. That's not > a major problem. On the other hand, if there's an obvious and > attractive use that's abusive, that's a reason for looking for another > way to add that functionality. Well you said it, that's a reason for looking for another way to add that functionality. My impression is that few people look at it that way, but instead seem to think it a reason to simply reject the functionality. -- Antoon Pardon From nyamatongwe+thunder at gmail.com Thu Dec 15 16:47:20 2005 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Thu, 15 Dec 2005 21:47:20 GMT Subject: access to preallocated block of memory? In-Reply-To: <1134681437.096820.90960@o13g2000cwo.googlegroups.com> References: <1134599434.424994.224240@g47g2000cwa.googlegroups.com> <43a0d34d$0$23555$626a54ce@news.free.fr> <11q1na8n36n2e40@corp.supernews.com> <1134665269.569267.119180@g44g2000cwa.googlegroups.com> <11q3i7iqnju837b@corp.supernews.com> <1134681437.096820.90960@o13g2000cwo.googlegroups.com> Message-ID: Greg Copeland: > I already have access to the block on memory...I > simply need information about existing python facilities which will > allow me to expose the block to python as a native type...from which I > can read byte for byte and optionally write to. As I originally said, > I have a pointer and the block's length. I have access to it already. > I simply need to expose it to python. What facilities already exist to > allow this which do not cause malloc/memcpy on said block? There is no generic array.at(address,length) in core Python as it would be a hole in Python's type system, allowing reading from or writing to any memory location and thus making it easier for Python to cause memory corruption and crashes. Libraries such as ctypes or its predecessor calldll do allow such access on some operating systems but not VxWorks. It would be quicker to write a special-purpose library for your job rather than port ctypes. Neil From mwm at mired.org Mon Dec 19 19:14:30 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 19 Dec 2005 19:14:30 -0500 Subject: Which Python web framework is most like Ruby on Rails? References: <1134496403.011407.169930@g44g2000cwa.googlegroups.com> <1134497848.620585.259200@g44g2000cwa.googlegroups.com> <1134502590.154469.37760@g49g2000cwa.googlegroups.com> <1134503125.765106.239640@g14g2000cwa.googlegroups.com> <1h7j2gk.aktins1kknr40N%aleax@mail.comcast.net> <1134574436.740981.134140@z14g2000cwz.googlegroups.com> <861x0fgkn3.fsf@bhuda.mired.org> <1134646215.706929.245390@g49g2000cwa.googlegroups.com> <86d5jyovuv.fsf@bhuda.mired.org> <1134747621.405701.297470@f14g2000cwb.googlegroups.com> <86lkykuao4.fsf@bhuda.mired.org> Message-ID: <86slso39qx.fsf@bhuda.mired.org> Benji York writes: > Russell E. Owen wrote: >> I disagree. Once you've picked a database (not trivial in itself, of >> course), you typically only have a few options for talking to in in >> Python. > Perhaps it's off-topic for this thread, but I think "picking a > database" is the first mistake most people make. It's a form of > premature optimization. For lots of problems, that's true. But not for all of them. > Just like any other component in a system, develop your app without a > database until you see that you need one, don't just assume you do > from the beginning. What makes me think "I need a database" is a requirement that says "multiple simultaneous writers". Yes, it's possible to deal with the data locking and the like on your own - but this tends to be system-dependent, and hard to get right except in the simple cases. It's also one of the things that databases are *really* good at. In this case, using a database isn't a performance optimization, it's a code simplification optimization, sort of like using Queue.Queue to do threading. > That's also why I don't see much point to the > relational-database-centric web frameworks that are all the rage > today, but I'll save that rant for another day. If your web clients can write data, then you've got multiple simultaneous writers - which means you probably want a database. Of course, people like to build web apps that don't write data on top of relational databases, which I think are well deserving of your rant. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From fphsml at gmail.com Mon Dec 19 17:07:12 2005 From: fphsml at gmail.com (James) Date: 19 Dec 2005 14:07:12 -0800 Subject: What is unique about Python? In-Reply-To: <1135014944.705793.113620@f14g2000cwb.googlegroups.com> References: <1135014944.705793.113620@f14g2000cwb.googlegroups.com> Message-ID: <1135030032.073777.75460@g14g2000cwa.googlegroups.com> >> The indentation-based syntax seems to be unique I think Haskell was there first. As well as ABC, one of Python's precursors. Python is a pragmatic language, just like C (I wish I could say that about Java). It does not necessarily innovate but incorporates things known to work elsewhere. C and Java have not done anything particularly unique either. They are included in curricula by their popularity. Isn't that a good enough argument? From bobrien18 at yahoo.com Thu Dec 22 13:14:10 2005 From: bobrien18 at yahoo.com (KraftDiner) Date: 22 Dec 2005 10:14:10 -0800 Subject: A simple list question. Message-ID: <1135275250.833196.66520@g14g2000cwa.googlegroups.com> Is there a cleaner way to implement this code? if len(self.listOfObjects) == 0: self.listOfObjects.append(self.currentObject) elif: self.listOfObjects[self.currentSlice] = self.currentObject listOfObjects is a list of lists.... If the listOfObjects is [] then I have to use append to add the first list otherwise I can access each list using the index into the list. From grante at visi.com Wed Dec 14 10:32:49 2005 From: grante at visi.com (Grant Edwards) Date: Wed, 14 Dec 2005 15:32:49 -0000 Subject: definition of 'polymorphism' and python References: Message-ID: <11q0ep16eqdp2d7@corp.supernews.com> On 2005-12-14, Gabriel Zachmann wrote: > I understand the Wikipedia article on Polymorphism ( > http://en.wikipedia.org/wiki/Polymorphism_%28computer_science%29 > ) that it doesn't make sense to talk about polymorphism in a > fully dynamically typed language -- does the Python community > agree? No. -- Grant Edwards grante Yow! Youth of today! Join at me in a mass rally visi.com for traditional mental attitudes! From steven.bethard at gmail.com Thu Dec 1 19:09:44 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 01 Dec 2005 17:09:44 -0700 Subject: aligning a set of word substrings to sentence In-Reply-To: References: Message-ID: <1uednWs4rJNZDRLenZ2dnUVZ_sGdnZ2d@comcast.com> Paul McGuire wrote: > "Steven Bethard" wrote in message > news:dpWdnfW-CeBj1xLeRVn-tw at comcast.com... > >>I've got a list of word substrings (the "tokens") which I need to align >>to a string of text (the "sentence"). The sentence is basically the >>concatenation of the token list, with spaces sometimes inserted beetween >>tokens. I need to determine the start and end offsets of each token in >>the sentence. For example:: >> >>py> tokens = ['She', "'s", 'gon', 'na', 'write', 'a', 'book', '?'] >>py> text = '''\ >>... She's gonna write >>... a book?''' >>py> list(offsets(tokens, text)) >>[(0, 3), (3, 5), (6, 9), (9, 11), (12, 17), (18, 19), (20, 24), (24, 25)] > > =================== > from pyparsing import oneOf > > tokens = ['She', "'s", 'gon', 'na', 'write', 'a', 'book', '?'] > text = '''\ > She's gonna write > a book?''' > > tokenlist = oneOf( " ".join(tokens) ) > offsets = [(start,end) for token,start,end in tokenlist.scanString(text) ] > > print offsets > =================== > [(0, 3), (3, 5), (6, 9), (9, 11), (12, 17), (18, 19), (20, 24), (24, 25)] Now that's a pretty solution. Three cheers for pyparsing! :) STeVe From mistobaan at gmail.com Fri Dec 23 10:47:25 2005 From: mistobaan at gmail.com (Fabrizio Milo) Date: Fri, 23 Dec 2005 16:47:25 +0100 Subject: GUI and graph In-Reply-To: <43ab3f99$1_1@newspeer2.tds.net> References: <1135288231.524102.326870@f14g2000cwb.googlegroups.com> <43ab3f99$1_1@newspeer2.tds.net> Message-ID: > pydot is pretty amazing in its abilitity to make nice, readable renderings of graph data. > http://dkbza.org/pydot.html Well It's thanks to graphwiz.. http://www.research.att.com/sw/tools/graphviz/ I suggest to read the DOT language specification ( it is really easy ) and to roll up your own python script to build your dot file. Fabrizio Milo aka Misto From twic at urchin.earth.li Fri Dec 9 06:10:04 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Fri, 9 Dec 2005 11:10:04 +0000 Subject: Validating an email address Message-ID: Hi all, A hoary old chestnut this - any advice on how to syntactically validate an email address? I'd like to support both the display-name-and-angle-bracket and bare-address forms, and to allow everything that RFC 2822 allows (and nothing more!). Currently, i've got some regexps which recognise a common subset of possible addresses, but it would be nice to do this properly - i don't currently support quoted pairs, quoted strings, or whitespace in various places where it's allowed. Adding support for those things using regexps is really hard. See: http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html For a level to which i am not prepared to stoop. I hear the email-sig are open to adding a validation function to the email package, if a satisfactory one can be written; i would definitely support their doing that. tom -- Women are monsters, men are clueless, everyone fights and no-one ever wins. -- cleanskies From ajikoe at gmail.com Fri Dec 9 09:26:44 2005 From: ajikoe at gmail.com (ajikoe at gmail.com) Date: 9 Dec 2005 06:26:44 -0800 Subject: idea of building python module using pyrex In-Reply-To: References: <1134125136.966666.53940@g14g2000cwa.googlegroups.com> <1134133449.883496.12330@z14g2000cwz.googlegroups.com> <1134135133.879743.158980@g47g2000cwa.googlegroups.com> Message-ID: <1134138404.818857.303210@z14g2000cwz.googlegroups.com> Hello David, Is SciPy works with python 2.4.2, Windows XP? I thought it is only for python 2.3? pujo From max at alcyone.com Wed Dec 14 19:23:28 2005 From: max at alcyone.com (Erik Max Francis) Date: Wed, 14 Dec 2005 16:23:28 -0800 Subject: quick unicode Q In-Reply-To: References: Message-ID: <9ZadneziZ8EdKj3enZ2dnUVZ_v-dnZ2d@speakeasy.net> John Morey wrote: > I have a variable that contains a string which may or may not include > unicode characters, I understand that I declare a unicode string like this > u'whatever' , the question is that when that string is read in from > an external source (in this case an id3 tag) how do I make the > interpretter understand that it may contain unicode? Read it as a string, and then decode it with the .decode method. You specify what encoding it's in. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis You are in the music / In the man's car next to me -- Sade From yahoo at nospam.leszczynscy Wed Dec 14 14:43:20 2005 From: yahoo at nospam.leszczynscy (Andy Leszczynski) Date: Wed, 14 Dec 2005 14:43:20 -0500 Subject: ?: in Python In-Reply-To: References: Message-ID: Lawrence Oluyede wrote: > Il 2005-12-14, Andy Leszczynski ha scritto: > >>How can do elegantly in Python: >> >>if condition: >> a=1 >>else: >> a=2 >> >>like in C: >> >>a=condition?1:2 >> > > > There are tons of threads on this newsgroup and in the python-dev mailing > list about a ternary operator. There's also a PEP AFAIK. > > I like this: > > In [1]:switch = True > > In [2]:a = (1, 2)[switch] > > In [3]:print a > 2 > > Like it too, thx. Switch does not have to be bool, so it is more powerfull than ?:. A. From mru at inprovide.com Thu Dec 15 04:05:44 2005 From: mru at inprovide.com (=?iso-8859-1?q?M=E5ns_Rullg=E5rd?=) Date: Thu, 15 Dec 2005 09:05:44 +0000 Subject: PHP = Perl Improved References: <1133844932.007824.26780@g43g2000cwa.googlegroups.com> <1134056349.035360.209840@f14g2000cwb.googlegroups.com> <1134155716.631143.191340@f14g2000cwb.googlegroups.com> <40baj4F17t2b4U1@individual.net> <87irtrp0wp.fsf@gmail.com> Message-ID: Martin Christensen writes: >>>>>> "Tin" == Tin Gherdanarra writes: > > Tin> Xah Lee wrote: >>> recently i got a project that involves the use of php. In 2 days, i >>> read almost the entirety of the php doc. Finding it a breeze >>> because it is roughly based on Perl, of which i have mastery. > > Tin> I suspect that you are a computer program posing as a human > Tin> usenet correspondent. > > Tin> Please answer these questions: [...] > > Will you accept a solution in Perl? He has mastery of that language, > you know. You might have better luck if you phrase your questions in > Perl, too, since he doesn't seem to understand it when people tell him > to bugger off in plain English. OK, lets try: die; -- M?ns Rullg?rd mru at inprovide.com From rbt at athop1.ath.vt.edu Tue Dec 6 08:20:27 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Tue, 06 Dec 2005 08:20:27 -0500 Subject: How to execute an EXE via os.system() with spaces in the directory name? In-Reply-To: References: <1133666170.048074.321150@z14g2000cwz.googlegroups.com> Message-ID: jepler at unpythonic.net wrote: > This comes up from time to time. The brain damage is all Windows', not > Python's. Here's one thread which seems to suggest a bizarre doubling > of the initial quote of the commandline. > > http://groups.google.com/group/comp.lang.python/browse_frm/thread/89d94656ea393d5b/ef40a65017848671 I do this: # remove spaces from ends of filenames. for root, dirs, files in os.walk('programs'): for fname in files: new_fname = fname.strip() if new_fname != fname: new_path = os.path.join(root,new_fname) old_path = os.path.join(root,fname) os.renames(old_path,new_path) # remove spaces from middle of filenames. for root, dirs, files in os.walk('programs'): for f in files: new_f = string.replace(f, ' ' , '-') new_path = os.path.join(root,new_f) old_path = os.path.join(root,f) os.renames(old_path,new_path) # install files. for root, dirs, files in os.walk('programs'): installable = ['.exe', '.msi', '.EXE', '.MSI'] for f in files: ext = os.path.splitext(f) if ext[1] in installable: print f install = os.system(os.path.join(root,f)) From desparn at wtf.com Mon Dec 12 10:39:54 2005 From: desparn at wtf.com (Rick Wotnaz) Date: Mon, 12 Dec 2005 10:39:54 -0500 Subject: Using XML w/ Python... References: <1134277924.398538.296150@g49g2000cwa.googlegroups.com> <1134333951.509929.5490@g49g2000cwa.googlegroups.com> <1134342781.330978.303580@g47g2000cwa.googlegroups.com> <1134347722.851087.169300@g49g2000cwa.googlegroups.com> <1134350340.363450.80270@g43g2000cwa.googlegroups.com> <1134359242.311767.12510@z14g2000cwz.googlegroups.com> <1134363744.268651.221840@g47g2000cwa.googlegroups.com> <1134366913.890682.123960@z14g2000cwz.googlegroups.com> <1134369549.926561.113940@f14g2000cwb.googlegroups.com> <1134370144.530537.146790@f14g2000cwb.googlegroups.com> <1134370395.530700.281190@g47g2000cwa.googlegroups.com> <1134372862.503403.26240@g14g2000cwa.googlegroups.com> Message-ID: uche.ogbuji at gmail.com wrote in news:1134372862.503403.26240 at g14g2000cwa.googlegroups.com: > """ > Spoke too soon, i get this error when running amara in > ActivePython > >>>> import amara >>>> amara.parse("http://www.digg.com/rss/index.xml") > > Traceback (most recent call last): > File "", line 1, in ? > File "C:\Python23\Lib\site-packages\amara\__init__.py", line > 50, in > parse > if IsXml(source): > NameError: global name 'IsXml' is not defined > > So im guessing theres an error with one of the files... > """ > > IsXml is imported conditionally, so this is an indicator that > somethign about your module setup is still not agreeing with > ActivePython. What do you see as the output of: > > python -c "import amara; print dir(amara)" > > ? I get: > > ['InputSource', 'IsXml', 'Uri', 'Uuid', '__builtins__', > '__doc__', '__file__', '__name__', '__path__', '__version__', > 'bindery', 'binderytools', 'binderyxpath', 'create_document', > 'dateutil_standins', 'domtools', 'os', 'parse', 'pushbind', > 'pushdom', 'pyxml_standins', 'saxtools'] > Not wanting to hijack this thread, but it got me interested in installing amara. I downloaded Amara-allinone-1.0.win32-py2.4.exe and ran it. It professed that the installation directory was to be D:\Python24\Lib\site-packages\ ... but it placed FT and amara in D: \Python24\Python24\Lib\site-packages . Possibly the installer is part of the problem here? -- rzed From http Mon Dec 19 03:30:51 2005 From: http (Paul Rubin) Date: 19 Dec 2005 00:30:51 -0800 Subject: Accessing next/prev element while for looping References: Message-ID: <7xzmmxh4jo.fsf@ruckus.brouhaha.com> Joseph Garvin writes: > And this way I can keep referring to j instead of myarray[i], but I'm > still forced to use myarray[i-1] and myarray[i+1] to refer to the > previous and next elements. Being able to do j.prev, j.next seems more > intuitive. > > Is there some other builtin somewhere that provides better > functionality that I'm missing? You could use a generator comprehension (untested): for prev,cur,next in ((myarray[i-1], myarray[i], myarray[i+1]) for i in xrange(1,len(myarray)-1)): do_something_with (prev, cur, next) Alternatively (untested): elts = iter(myarray) prev,cur,next = elts.next(),elts.next(),elts.next() for next2 in elts: do_something_with (prev, cur, next) prev,cur,next = cur, next, next2 Of course these fail when there's less than 3 elements. From JohnBMudd at gmail.com Sun Dec 4 06:49:31 2005 From: JohnBMudd at gmail.com (JohnBMudd at gmail.com) Date: 4 Dec 2005 03:49:31 -0800 Subject: ANN: Dao Language v.0.9.6-beta is release! In-Reply-To: References: <1133174924.322968.273370@o13g2000cwo.googlegroups.com> <1133436396.469598.183880@g44g2000cwa.googlegroups.com> <1133444785.664900.103910@g14g2000cwa.googlegroups.com> <1133448804.937838.71220@g43g2000cwa.googlegroups.com> <1133546901.454612.158690@o13g2000cwo.googlegroups.com> <8441p15lu4h7u0gd0jcm0ac732fkjuahvt@4ax.com> Message-ID: <1133696971.466976.213370@f14g2000cwb.googlegroups.com> This is amazing. Python could take over the programming world except one of it's best features (scope by indent) is a primary reason why it never will. It's not flexible enough. A large percentage of programmers won't even try the language. And even amongst Python enthusiast who appreciate the feature (me included) we can't agree on how to use it. Python is too flexible. And nobody else sees the need for change? Oh, except those who think Tabs are evil and should no longer be allowed. How about (1) add some more flexibility for optional braces and (2) add a formatting tool so I can reformat Python code to the "correct" style? Python is just a program, not a religion. Unless... Tabs really are evil. John From mtnBikingMark at gmail.com Tue Dec 13 15:29:44 2005 From: mtnBikingMark at gmail.com (mtnBikingMark at gmail.com) Date: 13 Dec 2005 12:29:44 -0800 Subject: Is unicode_escape broken? Message-ID: <1134505784.139964.283370@g47g2000cwa.googlegroups.com> Hi, I am confused by unicode_escape functionality - it doesn't seem to follow string_escape functionality. I would expect that given the same string (or at least a non-unicode and unicode string appropriately) that they would produce more or less the same output, but: >>> "\t\\t".encode('string_escape') '\\t\\\\t' >>> u"\t\\t".encode('unicode_escape') '\\t\\t' (I would have expected "\\t\\\\t" ) and then round - tripping also seems to be broken for unicode_escape: >>> "\t\\t".encode('string_escape').decode('string_escape') '\t\\t' >>> u"\t\\t".encode('unicode_escape').decode('unicode_escape') u'\t\t' Python Version "Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32" Thanks Mark From rupole at hotmail.com Tue Dec 13 23:31:39 2005 From: rupole at hotmail.com (Roger Upole) Date: Tue, 13 Dec 2005 23:31:39 -0500 Subject: query to find name of the OS, ip addr, mac addr etc References: <1134525425.464311.134530@g49g2000cwa.googlegroups.com> Message-ID: <1134534951_89733@spool6-east.superfeed.net> If you have Pywin32 installed, you can use WMI to get all these details. The WMI classes to look at are win32_networkadapter and win32_operatingsystem. Roger -- "Ask the ToeCutter - HE knows who I am !" wrote: > Hi all, > > 1) Am working on windows XP, and is there any way i can get the whole > name as "windows Xp" using python script? > > i have tried with > "os.sys.platform" but it just gives me as "win32", but can > i get the whole OS name as "windows Xp". > > If this is not possible, atleast i have a exe file, which puts all > the information about the system on the desktop, like os name, ip addr, > mac addr, etc etc, is there a way where i can collect this information > (from exe file to a text file ) with python script, so that atleast > that way i ll get the full OS name. > > 2) How can i get the "ip address" of my system? using python script. > > 3) How can i get the "mac address" of the system? using python script. > > 4) And how can i get the my "computer name" ? using python script. > > Thanks in advance for having given a thought on my queries. > > regards > yogi > ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =---- From rpdooling at gmail.com Mon Dec 5 14:01:43 2005 From: rpdooling at gmail.com (BartlebyScrivener) Date: 5 Dec 2005 11:01:43 -0800 Subject: Bitching about the documentation... References: <1133757861.843461.37910@g47g2000cwa.googlegroups.com> <1133806205.373629.178540@g44g2000cwa.googlegroups.com> Message-ID: <1133809302.968844.303990@g14g2000cwa.googlegroups.com> Go to Python.org Click on DEVELOPERS The lead sentence says: Contributors and potential contributors should read Documenting Python, which describes in details the conventions and markup used in creating and maintaining the Python documentation. The CVS trunk version is the recommended version for contributors, regardless of which Python branch is being modified. The link takes you straight to a primer on LaTex. Did I miss something? bs From rbt at athop1.ath.vt.edu Tue Dec 6 09:21:39 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Tue, 06 Dec 2005 09:21:39 -0500 Subject: extract python install info from registry In-Reply-To: <1133878580.778826.115150@g14g2000cwa.googlegroups.com> References: <1133878580.778826.115150@g14g2000cwa.googlegroups.com> Message-ID: <43959E73.3080201@athop1.ath.vt.edu> gene tani wrote: >> There's more to it than that... isn't there? I've used _winreg and the >> win32 extensions in the past when working with the registry. I thought >> perhaps someone had already scripted something to extract this info. >> > > Yes, a small firm named Microsoft has done this (but not tested w/2.4): > > http://www.microsoft.com/technet/scriptcenter/scripts/python/os/registry/osrgpy01.mspx > That tells me this: Caption: Registry Current Size: 2 Description: Registry Install Date: 20051125152108.000000-300 Maximum Size: 54 Name: Microsoft Windows XP Professional|C:\WINDOWS|\Device\Harddisk0\Partition1 Proposed Size: 54 Status: OK From JMailone at gmail.com Tue Dec 13 00:12:42 2005 From: JMailone at gmail.com (Jay) Date: 12 Dec 2005 21:12:42 -0800 Subject: ActivePython and Amara In-Reply-To: <1134448508.990548.21560@g49g2000cwa.googlegroups.com> References: <1134446316.705290.216120@g49g2000cwa.googlegroups.com> <1134448508.990548.21560@g49g2000cwa.googlegroups.com> Message-ID: <1134450762.478964.67570@g14g2000cwa.googlegroups.com> Woah woah woah, calm your ass down a little. I didn't say that the "hijacker" made it go off topic. Did I? I just said that the thread was going off topic from the dam title. We weren't talking about XML no more now were we. And who the hell are you talking to thinking that I haven't researched my ass off up till 4AM in the dam morning looking for an explanation on Google, friends and other resources... Also, >If you had ANY understanding of Python, you would have realized this. < So now your saying I don't know any python when I have read about a shitload of tutorials... So, I think first of all, you got some damn attitude, second of all, I never asked anyone to debug my program all I freaking asked for was help trying to get a module onto activepython which, I would love for you to Google "activepython and amara" not many relevant results. Third of all, I don't appreciate you saying that I don't know python when I have worked my ass off learning it! Now, with that out of the way. Stay the hell of my thread cuz you have some damn attitude problem and I don't need your rants about my questions. "Sometimes you really need to slow down and learn something before you can continue with what you want to do." ^^^^^^^^^^Take your post, and shove it up your ass. BYE -Jay From FalconHedgehog at gmail.com Mon Dec 5 11:35:43 2005 From: FalconHedgehog at gmail.com (Falc) Date: 5 Dec 2005 08:35:43 -0800 Subject: Learning Python... In-Reply-To: <43946796$0$21224$626a54ce@news.free.fr> References: <1133798486.507133.244170@f14g2000cwb.googlegroups.com> <43946796$0$21224$626a54ce@news.free.fr> Message-ID: <1133800543.849558.45920@f14g2000cwb.googlegroups.com> I am going to read "A Byte Of Python" and possibly a few others afterwards. I sure will read Dive into Python. Thanks a lot guys, it's beed a great help. I'll buy "Learning Python" when I can but I'm on a *very* tight budget at the moment. Thanks again. :) From rdjdvd at inwind.it Tue Dec 20 16:08:40 2005 From: rdjdvd at inwind.it (LocaWapp) Date: 20 Dec 2005 13:08:40 -0800 Subject: "class Server" has a big error: what is? In-Reply-To: References: <1134851880.336093.154120@g43g2000cwa.googlegroups.com> Message-ID: <1135112920.110695.193790@g47g2000cwa.googlegroups.com> Steven D'Aprano ha scritto: > On Sat, 17 Dec 2005 12:38:00 -0800, LocaWapp wrote: > > > "class Server" has a big error: what is? > > > > http://groups.google.it/group/comp.lang.python/browse_thread/thread/de458cb7675ff4b6/f333453b0dc1aab6?q=locawapp&rnum=1#f333453b0dc1aab6 > > > Is this a game of Twenty Questions? We guess what the error is, and you > tell us if we are getting colder or hotter? > > You might find a little bit more interest in helping you if you post the > traceback and the relevant bits of code. > > > -- > Steven. Hi Steven. The big error (big for me) is inside the HTTP protocol (see the version 001 or follow the link on top, but you don't see the version 002 because it is fixed). LocaWapp From tim.peters at gmail.com Mon Dec 26 11:56:29 2005 From: tim.peters at gmail.com (Tim Peters) Date: Mon, 26 Dec 2005 11:56:29 -0500 Subject: build curiosities of svn head (on WinXP) In-Reply-To: References: <417ha5F1d1ajeU1@news.dfncis.de> Message-ID: <1f7befae0512260856s44a7b87alf88a98cc47cc78ff@mail.gmail.com> [David Murmann] ... >> second, the build order in "pcbuild.sln" for elementtree seems to be >> wrong, nant tried to build elementtree before pythoncore (which failed). >> i fixed this by building elementtree separately. [Steve Holden] > Yes, the elementtree module is a new arrival for 3.5, so the build may > not yet be perfectly specified. This is useful information. I just checked in a fix for that. Thanks! ... >> ... and i could reproduce the expected failure (ATM) of the regression >> test suite: >> >> http://mail.python.org/pipermail/python-dev/2005-December/059033.html Note that all tests pass on Windows as of Sunday (in release and debug builds, with and without -O). From steve at REMOVETHIScyber.com.au Fri Dec 23 16:16:07 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sat, 24 Dec 2005 08:16:07 +1100 Subject: sorting with expensive compares? References: Message-ID: On Fri, 23 Dec 2005 19:26:11 +0100, Peter Otten wrote: > Dan Stromberg wrote: > >> I'm wanting to sort a large number of files, like a bunch of output files >> from a large series of rsh or ssh outputs on a large series of distinct >> machines, a music collection in .ogg format (strictly redistributable and >> legally purchased music), a collection of .iso cdrom images (strictly >> redistributable and legally purchased software), and so forth. > > Are you really trying to establish an order or do want to eliminate the > duplicates? > >>>> File("perfectly_legal.ogg") < File("free_of_charge.mp3") > True > > doesn't make that much sense to me, regardless of what the comparison may > actually do. If I have understood the poster's algorithm correctly, it gets even weirder: Sorted list of files -> [parrot.ogg, redhat.iso, george.log, fred.log, rhino.ogg, cat.ogg, debian.iso, sys_restore.iso, adrian.log, fox.ogg, ...] It seems to this little black duck that by sorting by file contents in this way, the effect to the human reader is virtually to randomise the list of file names. Even if you limit yourself to (say) a set of ogg files, and sort by the binary contents -> # album-track [parrot-6.ogg, rhino-1.ogg, cat-12.ogg, fox-2.ogg, parrot-3.ogg, ...] most people looking at the list would guess it had been shuffled, not sorted. So I too don't know what the original poster hopes to accomplish by sorting on the content of large binary files. -- Steven. From smithsm at samuelsmith.org Wed Dec 7 10:51:33 2005 From: smithsm at samuelsmith.org (Samuel M. Smith) Date: Wed, 7 Dec 2005 08:51:33 -0700 Subject: Unexpected behavior of read only attributes and super In-Reply-To: References: Message-ID: <299B03FC-E1B6-48D9-8ACD-DFEA07C45D93@samuelsmith.org> On 06 Dec, 2005, at 20:53, Steven Bethard wrote: > Samuel M. Smith wrote: >> The dict class has some read only attributes that generate an >> exception >> if I try to assign a value to them. >> I wanted to trap for this exception in a subclass using super but it >> doesn't happen. >> >> class SD(dict): >> pass >> > [snip] >> s = SD() >> super(SD,s).__setattr__('__iter__', True) >> >> Expecting to get the ReadOnly exception but I don't get the >> exception. > > Note that __iter__ is on the dict *type* not dict instances. Try > this: > > py> class SD(dict): > ... pass > ... > py> super(SD, SD).__init__ = False > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: 'super' object attribute '__init__' is read-only > > You can always shadow class-level attributes in the instance dict. > (That's what you were doing.) If you want to (try to) replace an > attribute in the class dict, you need to use the class object, not an > instance object. > I guess that's where my understanding breaks down. I thought the only way to access class attributes was by calling the class directly as your example indicates but __iter__ is a class attribute that I can access from the instance at least to read it. So what determines which class attributes get copied to the instance and which ones don't? From suresh.reddy at isquaresoft.com Wed Dec 14 06:20:03 2005 From: suresh.reddy at isquaresoft.com (suresh.reddy at isquaresoft.com) Date: 14 Dec 2005 03:20:03 -0800 Subject: openings on java with japanese language Message-ID: <1134559203.847016.50000@g47g2000cwa.googlegroups.com> send your profile to suresh.reddy at isquaresoft.com Job Code: JJ1 Job Description: Skills: Experience in Java, J2EE, Struts and servlets. This is for onsite (Japan) and should be proficient at Japanese Knowledge (Level 3/4). Number of positions : 6 Experience: 3-5 years on Real time experience on Struts and servlets. From bonono at gmail.com Sun Dec 18 21:46:02 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 18 Dec 2005 18:46:02 -0800 Subject: Wingide is a beautiful application In-Reply-To: References: <1134839352.112192.182010@o13g2000cwo.googlegroups.com> <1134929375.728971.141000@o13g2000cwo.googlegroups.com> Message-ID: <1134960362.104254.90910@o13g2000cwo.googlegroups.com> I have been using vi/vim for a very long time and love it(now using ion3 + vim, not even gvim on debian), but never found it blend well with the Windows GUI. Sybren Stuvel wrote: > Claudio Grondi enlightened us with: > > The file I was editing was just 22 KByte large having 450 lines, so > > you try here to explain to me, that for speed reasons Vim has to cut > > it into pieces? > > Yep. > > > Stani SPE based on Scintilla does it right, UltraEdit does it right, > > Wing does it right, so what, are we now on a 1 MHz computer with 128 > > KByte of memory for all the system and program files what would make > > such approach necessary? > > I'm giving you the reason why syntax highlighting in VIM doesn't > always do what you expect. I never said it wasn't a silly reason. > Having said that, A quick Ctrl+L usually fixes this for me. > > >> Wrong. I have used Vim for years, and only found a few minor > >> issues, nothing more. > > Let us know about them, so that we know it too. > > Syntax highlighting is awfully slow on files with very long lines. > That's the only thing I can think of now. And it's fixed in the > upcoming VIM 7. > > > But this is what I have experienced. Are you on a *nix system? > > Yep. > > > I speak here about Microsoft Windows XP SP 2 on a 3GByte RAM > > equipped Pentium 4 and Cream-Vim installed > > I use Vim and GVim, on a 1.25 GB RAM equipped AthlonXP, on Ubuntu > Linux. > > > But is does not work out of the box for me with the download I have > > mentioned and I was not able to fix it as I tried. > > That's probably because when you install Vim in Windows, it changes > key settings to be more appropriate for Windows. Rip those > Win32-compatability crap out of your .vimrc (or is it called _vimrc > there?) so you can use all the keys everybody else can. > > > Yes, I see your point, but with the increasing speed of the hardware > > and better software quality it is now possible to choose tools which > > are easy to use and don't have a steep learning curve. > > True. I find Vim very easy to use, and it didn't take me long to learn > it. It does help if you're on a platform which supplies 'vimtutor' > along with vim, and doesn't mangle the keybindings, though. > > > I am used to Microsoft Windows way of designing user interfaces, so > > I expect software running on Windows to provide what I am used to. > > LOL don't get me started on the Microsoft way in combination with my > expectations... > > > The times where the user had to adopt to the software are over. > > You're very wrong there. Users have to adopt to the software, unless > they write their own. You also have to adopt to all sort of things in > your life, so what's the big issue with software? > > To give you a few examples: I live in The Netherlands, so I buy cars > with the steering wheel on the left. I have to use that, no matter > what I want - unless I take the effort to import a car from abroad. I > have to screw to the right to get a screw inside a piece of wood. I > have to adopt to that. That's the way things work. > > > Now there are all preconditions available making it possible to > > adopt the software to the user. > > And most users get afraid of all those options they can set and all > those things they can tweak to get the software to adopt to their > whishes. > > > What other editing tools have you already evaluated? I tried as many > > as possible including Vim before I decided to spend money on > > purchasing UltraEdit and inspite of the fact, that there are so many > > new editors there, I still see no chance to replace UltraEdit with > > any other editing tool > > I've tried UltraEdit, didn't like it, went back to Vim. Same with > other editors. I don't like the way I get popups in UE when I want to > search or replace something. I haven't tested this, but I haven't seen > a way to re-wrap text like Vim can - even in this post it can rewrap > your text without messing up the '>' symbols in front of it. It can > even rewrap comments, strings etc. in source code without messing up > indentation or marker characters. > > > Just evaluate yourself at least SPE and Wing and come back to tell > > here about your experience comparing them to Vim > > I'll see if I can get around to it. I'm very busy atm, but I'm busy > doing Python programming, so perhaps I can do some with the IDEs you > mentioned. > > Hmm... neither are bundled with Ubuntu. > > SPE is already annoying because of all the new windows it opens... Not > a good start. I remember using it before, to check out the Blender > integration. Unfortunately, that didn't work. I'll give it another go. > > WingIDE is commercial software, which I'm not going to use. I'm not > all against commercial software, but if there is a Free alternative, > I'd rather use that. > > Sybren > -- > The problem with the world is stupidity. Not saying there should be a > capital punishment for stupidity, but why don't we just take the > safety labels off of everything and let the problem solve itself? > Frank Zappa From adurdin at gmail.com Thu Dec 29 19:35:25 2005 From: adurdin at gmail.com (Andrew Durdin) Date: Fri, 30 Dec 2005 11:35:25 +1100 Subject: python coding contest In-Reply-To: <43B25B0F.90509@hathawaymix.org> References: <43b0b977@nntp0.pdx.net> <43b23eec.184598698@news.oz.net> <43B25B0F.90509@hathawaymix.org> Message-ID: <59e9fd3a0512291635u14202551qe5e221e279fae89@mail.gmail.com> On 12/28/05, Shane Hathaway wrote: > I just found a 125 character solution. It's actually faster and more > readable than the 133 character solution (though it's still obscure.) Having spent a good deal of time and effort, and not getting below 144 characters, I am now very eager to see how these shorter versions work, particularly the 6 120-character solutions. I also expect that someone (I'll certainly give it a try) will produce a yet shorter version after the contest closes, based on the knowledge from the winning solutions. From mwm at mired.org Wed Dec 28 00:43:01 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 28 Dec 2005 00:43:01 -0500 Subject: predicting function calls? References: Message-ID: <864q4tdbfe.fsf@bhuda.mired.org> roy at panix.com (Roy Smith) writes: > Objects can have attributes (data) and operations associated with > them. It would be very convenient to use the "." syntax to access > both of these, i.e. be able to say: > > print handle.someAttribute > print handle.someOperation (arg1, arg2) > > I'm using __getattr__() to process both of these constructs, and > herein lies the rub; I need to do different things depending on > whether the name is an attribute or an operation. I can ask the DB > for a list of the names of all the operations supported by a given > object, but that's a fairly expensive thing to do, so I'd rather avoid > it if possible. It would be really nice if I had some way to find > out, from inside __getattr__(), if the value I'm about to return will > get called as a function (i.e., the name is followed by an open > paren). I can't see any way to do that, but maybe I'm missing > something? > > Any ideas? Fnorb (a pure-Python CORBA orb) dealt with this by not allowing attributes per se. Instead, it provided _get_AttributeName and _set_AttributeName as appropriate for each attribute in the IDL. Doing this means that *everything* you hand back from __getattr__ is going to be a callable, and presumably called at some point. Properties postdate Fnorb, so weren't considered in it's design. You might be able to do something with them as well. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From steve at holdenweb.com Thu Dec 8 04:35:28 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 08 Dec 2005 09:35:28 +0000 Subject: Is Python string immutable? In-Reply-To: <311b5ce10512071851u21c924b3v8d2dfb961e105bce@mail.gmail.com> References: <311b5ce10511301758y13707430l13a27182713c79b@mail.gmail.com> <311b5ce10512071851u21c924b3v8d2dfb961e105bce@mail.gmail.com> Message-ID: Frank Potter wrote: > Thank you very much. > Steve Holden, I post my soucecode at my blog here: > http://hiparrot.wordpress.com/2005/12/08/implementing-a-simple-net-spider/ > > I wish you can read and give me some suggestion. > Any comments will be appreciated. > Before any intensive scrutiny of the code perhaps you can answer a few questions. 1. Are you absolutely sure you have published the code you are running? The code you reference has indentation problems that give syntax errors. 2. Why do you continually create new threads when you could have a fixed set of threads sharing a list of URLs to scan? 3. What steps have you taken to ensure that the program does indeed perform according to its specifications? It seems to me that this code is a Java program transliterated into Python. A more natural way to express the algorithm would be for a number of worker threads to share Queue.Queue of URLs to be visited. The only other data structure that would then need locking would be a dictionary of URLs that had already been considered. Overall you appear to be spending large amounts of time locking and unlocking things, and creating threads unnecessarily, but you don't claim that the algorithm is particularly refined, and it shouldn;t affect memory usage. However, I would like to be sure that the excessive memory usage *is* indeed something to do with your program, as I contend, and not some buggy aspect of threading, so I await your answers with interest. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From shane at hathawaymix.org Sat Dec 10 03:16:00 2005 From: shane at hathawaymix.org (Shane Hathaway) Date: Sat, 10 Dec 2005 01:16:00 -0700 Subject: Proposal: Inline Import In-Reply-To: <439a345e$1_3@newspeer2.tds.net> References: <86r78lviq5.fsf@bhuda.mired.org> <439a345e$1_3@newspeer2.tds.net> Message-ID: <439A8EC0.8010602@hathawaymix.org> Kent Johnson wrote: > Shane Hathaway wrote: >>I'm talking about using imports *everywhere*. The penalty would be >>appreciable. > > > Have you tried it? > > D:\Projects\CB>python -m timeit -s "import re" "import re" > 1000000 loops, best of 3: 1.36 usec per loop > > You need a lot of imports before 1 usec becomes "appreciable". Let me fully elaborate the heresy I'm suggesting: I am talking about inline imports on every other line of code. The obvious implementation would drop performance by a double digit percentage. > And your > proposal is doing the import anyway, just under the hood. How will you > avoid the same penalty? The more complex implementation, which I suggested in the first message, is to maintain a per-module dictionary of imported objects (distinct from the global namespace.) This would make inline imports have almost exactly the same runtime cost as a global namespace lookup. But never mind, this proposal is a distraction from the real issue. See the next thread I'm starting. Shane From malvert at telenet.be Fri Dec 16 08:21:45 2005 From: malvert at telenet.be (malv) Date: 16 Dec 2005 05:21:45 -0800 Subject: Robotics and parallel ports In-Reply-To: References: Message-ID: <1134739304.905843.77080@o13g2000cwo.googlegroups.com> Hi, Thank you for the info. The dlp usb solution looks like a terrific gadget, especially since parallel ports have almost disppeared, at least on portables. In fact, would in linux not any py software capable of dealing with a usb connection (almost) suffice? Any further comments would be much appreciated. malv From robic0 Sun Dec 18 21:42:52 2005 From: robic0 (robic0) Date: Sun, 18 Dec 2005 18:42:52 -0800 Subject: Xah's Edu Corner: Responsible Software Licensing References: <1133844932.007824.26780@g43g2000cwa.googlegroups.com> <1134780763.066592.45390@g49g2000cwa.googlegroups.com> <43a53e43$0$11062$e4fe514c@news.xs4all.nl> Message-ID: On Sun, 18 Dec 2005 11:47:29 +0100, "Martin P. Hellwig" wrote: >Xah Lee wrote: > >Nice rant, btw in most EU countries the software creator can not >withdraw the responsibility of his/her/it creation, regardless of what >the disclaimer says. Pretty big damned statement there boy! As about a coverall generalization for all faults if I ever heard! > The law is the leading authority and not some >Disclaimer/EULA, that's why most US EULA's are unauthoritative in the EU. If the software opens a file and is in the middle of writing to it, then the user dumps the power to the machine and ends up having to reformat, thereby losing all his data, at what point does the liability stop? And how is fault proven or dished out? Does the law specifically state "repeatability" in its language? From scott.daniels at acm.org Sun Dec 4 09:47:34 2005 From: scott.daniels at acm.org (Scott David Daniels) Date: Sun, 04 Dec 2005 06:47:34 -0800 Subject: distutils problem windows xp python 2.4.2 In-Reply-To: <1133696800.758765.325450@g44g2000cwa.googlegroups.com> References: <1133656407.448394.298260@g49g2000cwa.googlegroups.com> <4392429a$1@nntp0.pdx.net> <1133696800.758765.325450@g44g2000cwa.googlegroups.com> Message-ID: <4393016e@nntp0.pdx.net> ajikoe at gmail.com wrote: > It didn't work with visual studio 5. .Net framework 2.0 > Do you have any suggestions? "It didn't work" is not very diagnosable. --Scott David Daniels scott.daniels at acm.org From kent at kentsjohnson.com Thu Dec 15 12:53:11 2005 From: kent at kentsjohnson.com (Kent Johnson) Date: Thu, 15 Dec 2005 12:53:11 -0500 Subject: Worthwhile to reverse a dictionary In-Reply-To: <1134586744.920392.91890@g47g2000cwa.googlegroups.com> References: <1134582611.355566.198990@g14g2000cwa.googlegroups.com> <43a05dc4$0$29563$da0feed9@news.zen.co.uk> <1134585835.467731.20610@g43g2000cwa.googlegroups.com> <1134586744.920392.91890@g47g2000cwa.googlegroups.com> Message-ID: <43a1aa64$1_2@newspeer2.tds.net> rudysanford at hotmail.com wrote: > What is the difference between > > " d1 = {'A' : '1', 'B' : '2', 'C' : '3'} " > > and > > " d1 = dict(A = 1, B = 2, C = 3) " ? > > All of the dictionary examples I saw (python.org, aspn.activestate.com, > Learning Python by Lutz, among others) use d={'x' : 'y'}. > The second form is only available in Python 2.3 and newer, so any example that is older than that will use the first form. Kent From twic at urchin.earth.li Sat Dec 10 11:34:13 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Sat, 10 Dec 2005 16:34:13 +0000 Subject: ANN: Dao Language v.0.9.6-beta is release! In-Reply-To: References: <1133174924.322968.273370@o13g2000cwo.googlegroups.com> <1133696971.466976.213370@f14g2000cwb.googlegroups.com> <1133702966.030710.51090@g47g2000cwa.googlegroups.com> <1133776917.483883.150120@o13g2000cwo.googlegroups.com> <1133788564.145604.234630@g49g2000cwa.googlegroups.com> <1133868635.352421.97010@g43g2000cwa.googlegroups.com> <1133905766.918194.210850@o13g2000cwo.googlegroups.com> Message-ID: On Sat, 10 Dec 2005, Sybren Stuvel wrote: > Zeljko Vrba enlightened us with: > >> Find me an editor which has folds like in VIM, regexp search/replace >> within two keystrokes (ESC,:), marks to easily navigate text in 2 >> keystrokes (mx, 'x), can handle indentation-level matching as well as >> VIM can handle {}()[], etc. And, unlike emacs, respects all (not just >> some) settings that are put in its config file. Something that works >> satisfactorily out-of-the box without having to learn a new programming >> language/platform (like emacs). > > Found it! VIM! ED IS THE STANDARD TEXT EDITOR. tom -- Argumentative and pedantic, oh, yes. Although it's properly called "correct" -- Huge From graham.fawcett at gmail.com Thu Dec 22 12:07:21 2005 From: graham.fawcett at gmail.com (Graham Fawcett) Date: 22 Dec 2005 09:07:21 -0800 Subject: Guido at Google In-Reply-To: References: <43a939e3$0$23986$626a14ce@news.free.fr> <1135165473.419546.212040@g49g2000cwa.googlegroups.com> <1h7wvw8.1of7z5vg23o7eN%aleax@mail.comcast.net> <1135184562.041865.204010@g47g2000cwa.googlegroups.com> <1135213658.989740.100660@o13g2000cwo.googlegroups.com> <1135261132.904386.4680@z14g2000cwz.googlegroups.com> Message-ID: <1135271241.913430.36230@g49g2000cwa.googlegroups.com> Peter Hansen wrote: > Graham Fawcett wrote: > > Steve Holden wrote: > >>>Nicola Musatti wrote: > >>>Of course, I'm going on vacation next week and there was talk > >>>about a one-way ticket to Mexico. The real question is will they let me *back* in? :-) > >>I would be careful coming back across the border. I heard that the PSU > > > > [suspicous premature end-of-sentence] > > > > Steve, I hope that the PSU is just jamming your comms, and not holding > > you captive over the holidays for your transgressions against the > > cabal! > > At about the same instant that he sent that message to group, I was > trying to call Steve on Google Talk and he suddenly went offline. I > haven't seen him since. There is no Steve Holden, and he has never been at war with Eurasia. Remove the P, S and U keys from your keyboard immediately. double-plus-good'ly yours, ...umm... doble-l-good'ly yor, Graham From hgk at et.uni-magdeburg.de Thu Dec 22 02:45:33 2005 From: hgk at et.uni-magdeburg.de (Hans Georg Krauthaeuser) Date: Thu, 22 Dec 2005 08:45:33 +0100 Subject: scipy.stats.itemfreq: overflow with add.reduce In-Reply-To: References: Message-ID: Hans Georg Krauthaeuser schrieb: > Hans Georg Krauthaeuser schrieb: > >> Hi All, >> >> I was playing with scipy.stats.itemfreq when I observed the following >> overflow: >> >> In [119]:for i in [254,255,256,257,258]: >> .....: l=[0]*i >> .....: print i, stats.itemfreq(l), l.count(0) >> .....: >> 254 [ [ 0 254]] 254 >> 255 [ [ 0 255]] 255 >> 256 [ [0 0]] 256 >> 257 [ [0 1]] 257 >> 258 [ [0 2]] 258 >> >> itemfreq is pretty small (in stats.py): >> >> ---------------------------------------------------------------------- >> def itemfreq(a): >> """ >> Returns a 2D array of item frequencies. Column 1 contains item values, >> column 2 contains their respective counts. Assumes a 1D array is passed. >> >> Returns: a 2D frequency table (col [0:n-1]=scores, col n=frequencies) >> """ >> scores = _support.unique(a) >> scores = sort(scores) >> freq = zeros(len(scores)) >> for i in range(len(scores)): >> freq[i] = add.reduce(equal(a,scores[i])) >> return array(_support.abut(scores, freq)) >> ---------------------------------------------------------------------- >> >> It seems that add.reduce is the source for the overflow: >> >> In [116]:from scipy import * >> >> In [117]:for i in [254,255,256,257,258]: >> .....: l=[0]*i >> .....: print i, add.reduce(equal(l,0)) >> .....: >> 254 254 >> 255 255 >> 256 0 >> 257 1 >> 258 2 >> >> Is there any possibility to avoid the overflow? >> >> BTW: >> Python 2.3.5 (#2, Aug 30 2005, 15:50:26) >> [GCC 4.0.2 20050821 (prerelease) (Debian 4.0.1-6)] on linux2 >> >> scipy_version.scipy_version --> '0.3.2' >> >> >> Thanks and best regards >> Hans Georg Krauth?user > > After some further investigation: > > In [150]:add.reduce(array(equal([0]*256,0),typecode='l')) > Out[150]:256 > > In [151]:add.reduce(equal([0]*256,0)) > Out[151]:0 > > The problem occurs with arrays with typecode 'b' (as returned by equal). > > Workaround patch for itemfreq is obvious, but ... is it a bug or a feature? > > regards > Hans Georg I feel a bit lonely here, but, nevertheless a further remark: The problem comes directly from the ufunc 'add' for typecode 'b'. In contrast to 'multiply' the typecode is not 'upcasted': In [178]:array(array([1],'b')*2) Out[178]:array([2],'i') In [179]:array(array([1],'b')+array([1],'b')) Out[179]:array([2],'b') So, for a array a with typecode 'b' it follows that a+a != a*2 At the moment, I don't have the time to try the new scipy_core. It would be nice to hear whether the problem is known or even already fixed!? Regards Hans Georg Krauth?user From jmeile at hotmail.com Fri Dec 9 14:26:21 2005 From: jmeile at hotmail.com (Josef Meile) Date: Fri, 09 Dec 2005 20:26:21 +0100 Subject: Overloading In-Reply-To: References: Message-ID: <4399DA5D.5000300@hotmail.com> >>In C++ you can overload functions and constructors. For example if I have a >>class that represents a complex number, than it would be nice if I can >>write two seperate constructors > > > Python doesn't support this, but it does support default arguments: Yes, in part you are right since the python core doesn't include them. However they can be implemented with decorators: * Subject: decorators and multimethods Group: comp.lang.python Link: http://tinyurl.com/d45ym Anyway, as you, I also use the default arguments. Regards Josef From mahs at telcopartners.com Sat Dec 17 18:27:26 2005 From: mahs at telcopartners.com (Michael Spencer) Date: Sat, 17 Dec 2005 15:27:26 -0800 Subject: object oriented programming question In-Reply-To: <5f56302b0512171410i6df31c38oe5c3300dc1b54e17@mail.gmail.com> References: <5f56302b0512171410i6df31c38oe5c3300dc1b54e17@mail.gmail.com> Message-ID: Daniel Nogradi wrote: > I have class 'x' with member 'content' and another member 'a' which is an > instance of class '_a'. The class '_a' is callable and has a method 'func' > which I would like to use to modify 'content' but I don't know how to > address 'content' from the class '_a'. Is it possible? > > Here is the code that I've described above: > > class _a: > def __call__(self, v): > print v > > def func(): > """I would like to do something > with ?content? here""" > > class x: > def __init__(self): > self.content = [ ] > > a = _a() > > > Now I would like to be able to say > > inst = x() > x.a(5) > x.a.func() > > where the second line prints '5' as expected, but I don't know how to make > the third line change 'x.content'. > Hello Daniel You've certainly got a lot going on here. The heart of your question seems to be how a nested (inner) class _a can access its parent, x. The short answer is that, in Python, it can't without some help. _a and its instances are unaware of the context in which they are defined, so they hold no references to x or instance of x. (Technically this is because the class is not created until after the statements in the class suite are executed) Before we get to that, though, note that you've made content an attribute of x's instances, not the x class. So there is no x.content, only inst.content. I'll assume this was a typo, and you intended inst.content. If this distinction is mysterious you may want to check: http://docs.python.org/tut/node11.html Now, back to the question of how instance a could get a reference to inst. The simplest way to program this is to give it the reference explicitly: class _a: def func(self): """I would like to do something with ?content? here. """ print self.__parent__.content class x: def __init__(self): self.content = ["I'm", "self.", "content"] a = _a() >>> inst = x() >>> inst.a.__parent__ = inst # give inst.a a reference to its parent >>> inst.a.func() ["I'm", 'self.', 'content'] >>> There is a way to automate "inst.a.__parent__ = inst", although it's not ideal "getting starting with Python objects" material. The solution is to have _a implement the descriptor protocol (see: http://users.rcn.com/python/download/Descriptor.htm), and make the classes "new-style", i.e., derived from 'object': class _a(object): ## def __call__(self, v): Method is irrelevant to this discussion ## print v def func(self): """I would like to do something with ?content? here. """ print self.__parent__.content def __get__(self, obj, cls): """Store a reference to the referring obj""" if isinstance(obj, cls): self.__parent__ = obj return self class x(object): def __init__(self): self.content = ["I'm", "self.", "content"] a = _a() >>> inst = x() >>> inst.a.func() #no need to set inst.a.__parent__ = inst manually now ["I'm", 'self.', 'content'] >>> HTH Michael From eddie at holyrood.ed.ac.uk Fri Dec 16 06:14:36 2005 From: eddie at holyrood.ed.ac.uk (Eddie Corns) Date: Fri, 16 Dec 2005 11:14:36 +0000 (UTC) Subject: Python and curses References: <1134723087.877227.16620@g49g2000cwa.googlegroups.com> Message-ID: "linuxfreak" writes: >Was wanting to write a text based application in python.... seems >curses module is the way to go... anyone knows of any good tutorials >apart from the one written by esr There is at least 1 higher level library atop curses. http://excess.org/urwid/ I've only played with it a little bit but it looks useful. Eddie From michaelschneider at fuse.net Thu Dec 29 09:28:11 2005 From: michaelschneider at fuse.net (Michael Schneider) Date: Thu, 29 Dec 2005 09:28:11 -0500 Subject: - E04 - Leadership! Google, Guido van Rossum, PSF In-Reply-To: <1135672111.204591.192590@o13g2000cwo.googlegroups.com> References: <1135672111.204591.192590@o13g2000cwo.googlegroups.com> Message-ID: <328a8$43b3f27e$d8c4f6e6$21725@FUSE.NET> Congratulations to Guide, Mike Harald Armin Massa wrote: > Guido at Google: a message in THE public forum c.l.p. > > A confirmation by Martellibot, that Guido is IN FACT sitting 15m > distant from him; and everybody in Python knows where Martellibot has > his desk. > > Can it get more official than this? > > yeah: > a confirmation by Greg Stein @ Google within slashdot, that Guido is > working at Google. > > I am sure that more people in the Python community are reading c.l.p. > and /. than the washington post, the people affected have been > informed. > > I guess that's as formal and official as it can get. > > And concerning Guido, Python, community and leadership: > > Guido is the designer, the creator of Python. He has nearly unlimeted > trust in his design decisions: we all know, that he is THE gifted > language designer. His proclamations are accepted because he has proven > over time that he knows what's best for the language. > > Allow me to quote Greg Stein: > "Ha! Guido would quit in a heartbeat if you tried to make him manage > people. That just isn't where he's at. He's absolutely brilliant and > loves to write excellent code. Great. We're gonna let him do just that > :-)" > > So, Google with their geek-version of the Playboy-Mansion, free massage > parleurs, free lunch and dinner and best recruitment tactics on the > planet and the known universe will not be able to make Guido manage > people. > > Somehow the Python community managed itself through the years... Python > grew healthy and steadily; forked less then usual, inspired other > languages and got faster and faster and faster. > > Maybe only mediocre and less ideas need a great leader. Maybe a great > idea can lead for itself? > > Harald > > -- > GHUM Harald Massa > persuadere et programmare > Harald Armin Massa > Reinsburgstra?e 202b > 70197 Stuttgart > 0173/9409607 > -- The greatest performance improvement occurs on the transition of from the non-working state to the working state. From robert.kern at gmail.com Wed Dec 21 12:03:45 2005 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 21 Dec 2005 12:03:45 -0500 Subject: Which Python web framework is most like Ruby on Rails? In-Reply-To: <1h7wv99.1jjl97h1ufrsq9N%aleax@mail.comcast.net> References: <1134496403.011407.169930@g44g2000cwa.googlegroups.com> <1135029071.990723.134030@z14g2000cwz.googlegroups.com> <1135083100.135409.165580@f14g2000cwb.googlegroups.com> <1135085077.952662.55340@o13g2000cwo.googlegroups.com> <1135086632.969355.205990@g47g2000cwa.googlegroups.com> <43a83537_2@newspeer2.tds.net> <1135112530.312697.313110@f14g2000cwb.googlegroups.com> <43a8a992$1_1@newspeer2.tds.net> <7xmziudf0q.fsf@ruckus.brouhaha.com> <1135154960.265287.322030@z14g2000cwz.googlegroups.com> <7xk6dypuxy.fsf@ruckus.brouhaha.com> <1h7wv99.1jjl97h1ufrsq9N%aleax@mail.comcast.net> Message-ID: Alex Martelli wrote: > Paul Rubin wrote: > > >>Richie Hindle writes: >> >>>A good solution would be multiple-licensing. You state that the >>>code is (for example) triple-licensed under the GPL, LGPL and BSD >>>licenses. The user of your code decides which license to obey. >>>It's no more work for you, and you can please almost everyone (the >>>only people you won't please are those who believe that there is One >>>True License, and frankly you should ignore them - it's your code). >> >>That's silly, you might as well just use BSD instead of triple >>licensing like that. > > You're pointing out yourself, a few lines lower, while this isn't so: > >>Another downside to BSD is that it becomes impermissible to improve >>Karrigell by transplanting GPL code into it from other programs. Yet > > ...which obviously is not a problem if K is available under either GPL > or BSD at the user's choice: anybody wanting to transplant GPL code into > it will pick the GPL side of the dual-licensing (I don't see any further > advantage in adding LGPL to the mix, maybe I'm missing s/thing...). If K were to be dual licensed GPL/BSD, Pierre could not take some GPLed third party code, incorporate it into K, and distribute K+3rdparty under both licenses. 3rdparty would always be under the GPL, and the GPL conditions would apply to the combination as a whole. That's the scenario Paul is referring to. Of course, someone who is not Pierre who wants to distribute a web app with K and some third party GPL module can do so just as well if K is only BSD-licensed since BSD is compatible with the GPL. Dual licensing would only be necessary if the alternative licenses were incompatible, e.g. Artistic/GPL like Perl or MPL/GPL like Mozilla. -- Robert Kern robert.kern at gmail.com "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From aum at spam.me.please Tue Dec 6 02:40:56 2005 From: aum at spam.me.please (aum) Date: Tue, 06 Dec 2005 20:40:56 +1300 Subject: ANN: pygene - genetic algorithms package Message-ID: Hi all, I looked at a few genetic algorithms/genetic programming packages for Python, and found them somewhat convoluted, complicated and counter-intuitive to use. So I've written a genetic algorithms package which I hope will be more approachable to beginners. The first release of pygene is up at: http://www.freenet.org.nz/python/pygene The package includes full api documentation, and an implementation of the travelling salesman problem, plus a couple of simpler cases. -- Cheers aum From peter at engcorp.com Wed Dec 21 08:22:02 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 21 Dec 2005 08:22:02 -0500 Subject: How to check if a string "is" an int? In-Reply-To: References: <1135159955.302316.24060@g43g2000cwa.googlegroups.com> <1135165047.116025.325690@g43g2000cwa.googlegroups.com> <43a948ff$1_3@newspeer2.tds.net> Message-ID: Steven D'Aprano wrote: > On Wed, 21 Dec 2005 07:36:15 -0500, Kent Johnson wrote: >>Maybe so, but '15'.isdigit() == True: > > Well I'll be a monkey's uncle. > > In that case, the name is misleadingly wrong. I suppose it is not likely > that it could be changed before Python 3? That was my first thought too, Steven, but then I considered whether I'd think the same about the others: islower, isspace, istitle, isupper, isalnum, isalpha. Some of those suffer from the same confusion, probably inspired by having written lots of C in the past, but certain "istitle" wouldn't be particularly useful on a single character. isalnum and isalpha don't necessarily invoke the same mental awkwardness since, after all, what is "an alpha"? It could just as well be read "is this string alphabetic" as "is this character 'an alpha'". Given that Python doesn't have a distinct concept of "character" (but merely a string of length one), having those routines operate on the entire string is probably pretty sensible, and I'm not sure that naming them "isdigits()" would be helpful either since then it would feel awkward to use them on length-one-strings. -Peter From mwm at mired.org Fri Dec 2 12:13:55 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 02 Dec 2005 12:13:55 -0500 Subject: Death to tuples! References: <86y839ux1j.fsf@bhuda.mired.org> <86y834rcfb.fsf@bhuda.mired.org> <86vey8pesd.fsf@bhuda.mired.org> Message-ID: <86zmnjpgks.fsf@bhuda.mired.org> Antoon Pardon writes: >>> Well there are two possibilities I can think of: >>> >>> 1) >>> arg_default = ... >>> def f(arg = arg_default): >>> ... >> >> Yuch. Mostly because it doesn't work: >> >> arg_default = ... >> def f(arg = arg_default): >> ... >> >> arg_default = ... >> def g(arg = arg_default): >> >> That one looks like an accident waiting to happen. > It's not because accidents can happen, that it doesn't work. > IMO that accidents can happen here is because python > doesn't allow a name to be marked as a constant or unreboundable. Loets of "accidents" could be fixed if Python marked names in various ways: with a type, or as only being visible to certain other types, or whatever. A change that requires such a construct in order to be usable probably needs rethinking. Even if that weren't a problem, this would still require introducting a new variable into the global namespace for every such argument. Unlike other similar constructs, you *can't* clean them up, because the whole point is that they be around later. The decorator was an indication of a possible solution. I know it fails in some cases, and it probably fails in others as well. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From sybrenUSE at YOURthirdtower.com.imagination Fri Dec 16 11:34:38 2005 From: sybrenUSE at YOURthirdtower.com.imagination (Sybren Stuvel) Date: Fri, 16 Dec 2005 17:34:38 +0100 Subject: Invoking Unix commands from a Python app References: <1134748219.593317.55180@g44g2000cwa.googlegroups.com> <1134749168.458182.112100@g44g2000cwa.googlegroups.com> Message-ID: Rob Cowie enlightened us with: > Ok, I know see that os.spawnl() will suffice. However, how do I > retrieve the output of the command. Apparently, os.spawnl() didn't suffice. Check out the popen2 module and Popen* classes. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa From andymac at bullseye.apana.org.au Tue Dec 13 18:11:28 2005 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Wed, 14 Dec 2005 09:11:28 +1000 Subject: threading IOError In-Reply-To: <1134493980.966751.154230@g49g2000cwa.googlegroups.com> References: <1134493980.966751.154230@g49g2000cwa.googlegroups.com> Message-ID: <439F5520.4040703@bullseye.apana.org.au> Gabriel Genellina wrote: > Hi > > I'm using Python 2.4.2 on Windows 98 SE. > > In a program with several threads, sometimes (I cant determine exactly > when or why) one thread dies with the following traceback: > > 12/13/05 02:17:47 (WatchDog ) Unhandled thread exception > Traceback (most recent call last): > File "E:\prog\pop3\TaskScheduler.py", line 60, in run > self.finished.wait(self.interval) > File "C:\Apps\Python\Lib\threading.py", line 348, in wait > self.__cond.wait(timeout) > File "C:\Apps\Python\Lib\threading.py", line 218, in wait > remaining = endtime - _time() > IOError: [Errno 2] No such file or directory > > The error appears to be inside the time module, and I can't explain the > IOError there. > > Maybe this crash is related too: sometimes, the full program crashes > with an Invalid Page Fault with the following info: > > PYTHONW provoc? un error de p?gina no v?lida en el m?dulo > PYTHON24.DLL de 016f:1e0ab51f. > Registros: > EAX=1e19d1af CS=016f EIP=1e0ab51f EFLGS=00010206 > EBX=00841f80 SS=0177 ESP=0071e6ec EBP=00000000 > ECX=73962000 DS=0177 ESI=1e06a1b0 FS=1a07 > EDX=1e19d1b0 ES=0177 EDI=00000000 GS=0000 > > Any ideas? Quite some time ago I saw the same sort of issue - inexplicable exceptions from apparently benign code. Tim Peters prognosticated that there was a bug in an extension module, and indeed that proved to be the case (a 3rd party extension, which fortunately I had source for and was able to build). I doubt that any of Python's standard extension modules will be involved (as they are generally mature and widely used and tested) but you should look at the source for any others looking for unhandled error returns. Typically, errno is set but the failure return from the routine setting errno is ignored or not properly handled. What then happens is the next time an exception gets propagated through Python's internals, the errno value gets picked up and is used to identify the exception (incorrectly). The invalid page fault may well be because a garbage pointer is handed to a routine, possibly as a consequence of the mishandled error return. ------------------------------------------------------------------------- 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 dodysw at gmail.com Fri Dec 23 12:03:35 2005 From: dodysw at gmail.com (Dody Suria Wijaya) Date: Sat, 24 Dec 2005 04:03:35 +1100 Subject: Python IMAP4 Memory Error In-Reply-To: References: <43ab6d46$1@clarion.carno.net.au> <20051223091822.1217.467053970.divmod.quotient.7746@ohm> Message-ID: <43ac2df9@clarion.carno.net.au> like magic it did the trick :D This should be applied to future Python release. Thanks. Fredrik Lundh wrote: > Jean-Paul Calderone wrote: > if you look at the debug output (which you may already have done), > it's an obvious case of fragmentation-inducing behaviour. any malloc- > based system may choke on the sequence > > for a large number of attempts: > allocate a 15 megabyte block > shrink block to a couple of kilobytes > occasionally allocate a medium-sized block > > from what I can tell, replacing the > > data = self.sslobj.read(size-read) > > line with > > data = self.sslobj.read(min(size-read, 16384)) > > should do the trick. From raims at dot.com Thu Dec 15 12:25:19 2005 From: raims at dot.com (Lawrence Oluyede) Date: Thu, 15 Dec 2005 18:25:19 +0100 Subject: Tuples References: <1134667177.201781.261080@g43g2000cwa.googlegroups.com> Message-ID: Il 2005-12-15, Tuvas ha scritto: First, these are lists not tuples > Let's say I make a program something like follows: > > x=[] > x.append([1,2,3]) > x.append([4,5,6]) > print x > print x[0] > print x[0][1] > x[0][1]=5 > > Okay, everything works here as expected except the last line. Why won't > this work? Thanks for the help! > Why not? for me works. After the last sentence if you print out x you get: [[1, 5, 3], [4, 5, 6]] -- Lawrence - http://www.oluyede.org/blog "Anyone can freely use whatever he wants but the light at the end of the tunnel for most of his problems is Python" From steve at holdenweb.com Wed Dec 14 07:25:19 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 14 Dec 2005 12:25:19 +0000 Subject: First practical Python code, comments appreciated In-Reply-To: <1134561240.888915.181440@f14g2000cwb.googlegroups.com> References: <1134561240.888915.181440@f14g2000cwb.googlegroups.com> Message-ID: planetthoughtful wrote: > Hi All, > > I've written my first piece of practical Python code (included below), > and would appreciate some comments. My situation was that I had a > directory with a number of subdirectories that contained one or more > zip files in each. Many of the zipfiles had the same filename (which is > why they had previously been stored in separate directories). I wanted > to bring all of the zip files (several hundrd in total) down to the > common parent directory and obviously rename them in the process by > appending a unique string to each filename. > > The code below did the job admirably, but I don't imagine it is > anywhere near as efficiently written as it could and should be. Note: > I'm aware there was no need, for example, to wrap the "os.walk(path)" > statement in a def -- in a couple of places I added extra steps just to > help familiarize myself with Python syntax. > > I'd very much like to see how experienced Python coders would have > achieved the same task, if any of you can spare a couple of minutes to > share some knowledge with me. > > Many thanks and much warmth, > > planetthoughtful Brave of you. Please note I haven't actually tested the exact format of these suggestions, so I made have made stupid typos or syntax errors. > > import os > fcount = 0 > path = 'X:\zipfiles' > def listFiles(path): > mylist = os.walk(path) > return mylist > > filelist = listFiles(path) > for s in filelist: > if len(s[2]) > 0: You don't really need this "if" - with an empty s the "for" loop on the next line will simply execute its body zero times, giving the effect you appear to want without the extra level of logic. > for f in s[2]: > pad = str(fcount) > if len(pad) == 1: > pad = "00" + pad > elif len(pad) == 2: > pad = "0" + pad > Here you could take advantage of the string formatting "%" operator and instead of the "if" statement just say pad = "%03d" % fcount >>> ["%03d" % x for x in (1, 3, 10, 30, 100, 300)] ['001', '003', '010', '030', '100', '300'] > (fname, fext) = os.path.splitext(f) > oldname = f There isn't really any advantage to this assignment, though I admit it does show what you are doing a little better. So why not just use for oldname in s[2]: to control the loop, and then replace the two statements above with (fname, fext) = os.path.splitext(oldname) Note that assignments of one plain name to another are always fast operations in Pythin, though, so this isn't criminal behaviour - it just clutters your logic a little having essentially two names for the same thing. > newname = fname + "_" + pad + fext > os.rename(s[0] + "\\" + oldname, path + "\\" + newname) That form is non-portable. You might argue "I'm never going to run this program on anything other than Windows", and indeed for throwaway programs it's often easier to write something non-portable. It's surprising, though, how often you end up *not* throwing away such programs, so it can help to write portably from the start. I'd have used newname = os.path.join(path, "%s_%s.%s" % (fname, pad, fext)) os.rename(os.path.join(s[0], oldname), newname) > fcount = fcount + 1 > Just a few pointers to make the script simpler, but your program is a very creditable first effort. Let us know what mistakes I made! regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From steve at holdenweb.com Thu Dec 15 03:59:14 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 15 Dec 2005 08:59:14 +0000 Subject: How to get the local mac address? In-Reply-To: <1134636649.937619.304060@g49g2000cwa.googlegroups.com> References: <1134575518.767407.112490@g44g2000cwa.googlegroups.com> <1134618652.007425.149540@g14g2000cwa.googlegroups.com> <1134630506.774844.192790@f14g2000cwb.googlegroups.com> <1134630954.491132.260930@g43g2000cwa.googlegroups.com> <1134636649.937619.304060@g49g2000cwa.googlegroups.com> Message-ID: bonono at gmail.com wrote: > Steve Holden wrote: > >>Why should you want to associate a MAC address with a socket? Each >>interface has an IP address, and it's that you should be using. > > Say for example I want to find out the MAC if a particular interface in > python. > When you are asked "why would you want to do something" it isn't normally considered sufficient to reply "suppose I want to do something". I'm still trying to find out what use case (apart from curiosity) drives this need to know. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From aleax at mail.comcast.net Tue Dec 13 23:26:43 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Tue, 13 Dec 2005 20:26:43 -0800 Subject: Still Loving Python References: <1134489879.436360.273220@g47g2000cwa.googlegroups.com> Message-ID: <1h7izab.1takgju1v6q6zyN%aleax@mail.comcast.net> J?r?me Laheurte wrote: ... > Sorry for the harsh tone, I just think GUI builders are *evil*. Except > maybe for QT Designer, which has a nice model where you implement > callbacks by subclassing the generated classes. At least you don't have to > look at the generated code. Try Interface Builder on a Mac: it builds interfaces as _data_ files, not "generated code". You can then use the same UI from Objective C, Java, Python (w/PyObjC), AppleScript... interface-painters which generate code are a really bad idea. (I'm sure Apple's IB is not the only interface-painter which encodes the UI as a datafile, easily interpreted at startup by a suitable library for whatever language you're using to flesh it out -- it's such an obviously RIGHT idea!). Alex From fdu.xiaojf at gmail.com Thu Dec 15 23:54:49 2005 From: fdu.xiaojf at gmail.com (Xiao Jianfeng) Date: Fri, 16 Dec 2005 12:54:49 +0800 Subject: The difference between "import package.module" and "from package import module"(about pymol) Message-ID: <43A24899.40105@gmail.com> Hello, In pymol I can use "from chempy import Atom" but "import chempy.Atom" doesn't work. It says,"ImportError: No module named Atom". What is going wrong ? Thanks From http Wed Dec 21 03:35:01 2005 From: http (Paul Rubin) Date: 21 Dec 2005 00:35:01 -0800 Subject: Which Python web framework is most like Ruby on Rails? References: <1134496403.011407.169930@g44g2000cwa.googlegroups.com> <1135029071.990723.134030@z14g2000cwz.googlegroups.com> <1135083100.135409.165580@f14g2000cwb.googlegroups.com> <1135085077.952662.55340@o13g2000cwo.googlegroups.com> <1135086632.969355.205990@g47g2000cwa.googlegroups.com> <43a83537_2@newspeer2.tds.net> <1135112530.312697.313110@f14g2000cwb.googlegroups.com> <43a8a992$1_1@newspeer2.tds.net> Message-ID: <7xmziudf0q.fsf@ruckus.brouhaha.com> Steve Holden writes: > > However the work I do is commercial and proprietary and I doubt > > I could get approval to release it under GPL. > I see the GPL is a problem in this environment, and you are clearly > aware of the issues it raises. Do be aware, though, that not all GPL > authors are rabid communists, and some will consider licensing to you > under other licenses if you ask them. It's always worth asking, as > some authors have chosen GPL in a somewhat uninformed way rather than > as a political statement (you'll notice I too am trying to avoid the > flame wars). I'm trying to avoid flame wars too, but my take on this is that Kent's reading is a little too restrictive and the GPL isn't really a problem in this situation unless he's actually modifying Karrigell itself, rather than writing applications that run under it. I'm not trying to advocate Karrigell (I browsed the docs for a minute and it looks nice but I have no experience with it) but I don't see the GPL as an obstacle to that type of usage. All kinds of proprietary applications are written and distributed all the time to run under the GPL'd Linux kernel and Karrigell apps don't seem too terribly different from that. From simon at airlangen.de Sun Dec 25 21:33:19 2005 From: simon at airlangen.de (Simon Hengel) Date: Mon, 26 Dec 2005 03:33:19 +0100 Subject: python coding contest In-Reply-To: References: <43AEBD43.7080407@airlangen.de> <43AECBFA.2070209@stackless.com> Message-ID: <43AF566F.1060209@airlangen.de> > Is it necessary to keep the input parameter as 'input'? Reducing that to > a single character drops the length of a program by at least 8 > characters. Technically it changes the interface of the function, so > it's a little bogus, but test.py doesn't check. (Personally I prefer > that if be illegal, but if it's legal I'll have to do it). You may change input to something more short, like x. Everything that passes the test, has a good chance to be accepted. Cheers, Simon Hengel -- python coding contest - http://www.pycontest.net/ From gene.tani at gmail.com Tue Dec 13 13:17:28 2005 From: gene.tani at gmail.com (gene tani) Date: 13 Dec 2005 10:17:28 -0800 Subject: Which Python web framework is most like Ruby on Rails? In-Reply-To: <1134496403.011407.169930@g44g2000cwa.googlegroups.com> References: <1134496403.011407.169930@g44g2000cwa.googlegroups.com> Message-ID: <1134497848.620585.259200@g44g2000cwa.googlegroups.com> seberino at spawar.navy.mil wrote: > I'm interested in knowing which Python web framework is most like Ruby > on Rails. > > I've heard of Subway and Django. > > > Are there other Rails clones in Python land I don't know about? > > Which one has largest community/buzz about it? > > > Chris Subway and Django are *exactly* like rails, and they have buzz. And have you looked at slashdot codebase? Seriously, these frameworks are broad and deep, write more about your app, platform, databases and DBMS and you'll get a better anwer, e.g. you like has_and_blongs_to_many, you want an ActiveRecord clone, or you like the naming defaults in rails' scaffolding, you like the DSL quality of the rails code, ... From apardon at forel.vub.ac.be Fri Dec 16 05:18:39 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 16 Dec 2005 10:18:39 GMT Subject: Enumeration idioms: Values from different enumerations References: <873bkt1xtj.fsf@rose.polar.local> <86fyotpovq.fsf@bhuda.mired.org> <87ek4d2zwg.fsf@rose.polar.local> Message-ID: Op 2005-12-16, Ben Finney schreef : > Mike Meyer writes: >> Peter Hansen writes: >>> That is, [perhaps] trying to compare enumerations that should not >>> be compared *is* an error (raising an exception) *because* the >>> whole point of enumerations is to avoid errors in such cases. >> >> Except it might not be an error. For instance, if I've got a list of >> enum objects taken from various types (say I've got one set of enums >> for days of the week, another for months of the year, and so on, and >> which I use depends on whether the user wants to select days of the >> week, months of the year, etc), it makes perfect sense to want to know >> if a specific enum value is in the list, and the obvious way to check >> it is with "my_value in enum_list". That won't work if you raise an >> exception - it takes a relatively convoluted bit of code to make this >> test. > > The 'enum' package in Cheeseshop doesn't do that. Enumerations are > sequences (of unique arbitrary values), that can be iterated and tested > for membership. Sure but we do have this: >>> from enum import Enum >>> day = Enum('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun') >>> col = Enum('red', 'green', 'blue') >>> lst= [day.mon, col.red] >>> col.blue in lst Traceback (most recent call last): File "", line 1, in ? File "enum.py", line 100, in __cmp__ raise EnumValueCompareError(self, other) enum.EnumValueCompareError: Not values from the same enumeration: (EnumValue(, 2, 'blue'), EnumValue(, 0, 'mon')) > What's being discussed here is what happens when comparing the *values* > from the enumeration. > >> Python generally uses '==' to mean "is the same value". To do that, >> a simple true/false return is enough. In raising an exception, >> you're making '==' carry an extra meaning (I'm not sure *what* that >> is, though). > > The problem with "is the same value" as an explanation for '==' is > that it doesn't help in cases such as:: > > >>> ShirtSize = Enum('small', 'medium', 'large') > >>> AppleSize = Enum('small', 'large') > > What should be the result of this comparison:: > > >>> ShirtSize.small == AppleSize.small > > Are they "the same value"? They're both "small" (and they both coerce > to the same string value, and in this case the same integer value). > > If not, is 'False' the right way to indicate that? I would agree 'False' is the right answer here. -- Antoon Pardon From uval at rz.uni-karlsruhe.de Wed Dec 21 10:39:19 2005 From: uval at rz.uni-karlsruhe.de (=?ISO-8859-1?Q?Daniel_Sch=FCle?=) Date: Wed, 21 Dec 2005 16:39:19 +0100 Subject: How to check if a string "is" an int? In-Reply-To: <1135159955.302316.24060@g43g2000cwa.googlegroups.com> References: <1135159955.302316.24060@g43g2000cwa.googlegroups.com> Message-ID: pinkfloydhomer at gmail.com wrote: > How do I check if a string contains (can be converted to) an int? I > want to do one thing if I am parsing and integer, and another if not. > > /David > others already answered, this is just an idea >>> def isNumber(n): ... import re ... if re.match("^[-+]?[0-9]+$", n): ... return True ... return False does not recognize 0x numbers, but this is easy to fix if wanted >>> def isNumber(n): ... import re ... if re.match("^[-+]?[0-9A-Fa-f]+$", n): ... return True ... return False hth Daniel From baxter.brad at gmail.com Sat Dec 31 12:11:58 2005 From: baxter.brad at gmail.com (Brad Baxter) Date: 31 Dec 2005 09:11:58 -0800 Subject: Xah's Edu Corner: Examples of Quality Technical Writing In-Reply-To: <1133844932.007824.26780@g43g2000cwa.googlegroups.com> References: <1133844932.007824.26780@g43g2000cwa.googlegroups.com> Message-ID: <1136049118.504774.101670@g47g2000cwa.googlegroups.com> Xah Lee wrote: > i had the pleasure to read the PHP's manual today. > > http://www.php.net/manual/en/ > > although Pretty Home Page is another criminal hack of the unix lineage, > but if we are here to judge the quality of its documentation, it is a > impeccability. > > it has or possesses properties of: > > ? To the point and useful. > > PHP has its roots in mundaness, like Perl and Apache. Its doc being > practicality oriented isn't a surprise, as are the docs of Perl and > Apache. > > ? Extreme clarity! > > The doc is extremely well-written. The authors's writing skills > shows, that they can present their ideas clearly, and also that they > have put thoughts into what they wanted to say. > > ? Ample usage examples. > > As with Perl's doc, PHP doc is not afraid to show example snippets, > yet not abuse it as if simply slapping on examples in lieu of proper > spec or discussion. > > ? Appropriate functions or keywords are interlinked. > > This aspect is also well done in other quality docs, such as > Mathematica, Java, MS JScript, Perl's official docs. > > ? No abuse of jargons. > > In fact, it's so well written that there's almost no jargons in its > docs, yet conveys its intentions to a tee. This aspect can also be seen > in Mathematica's doc, or Microsoft's JScript doc, for examples. > > ? No author masturbation. (if fact, you won't see a first-person > perspective, as is the case with most quality tech writing.) > > We must truely appreciate the authors of the PHP doc. Because, PHP, as > a free shit in the unix shit culture, with extreme ties to Perl and > Apache (both of which has extremely motherfucked docs), but can wean > itself from a shit milieu and stand pure and clean to become a paragon > of technical writing. > --- original Sat Dec 31 11:44:54 2005 +++ corrected Sat Dec 31 11:56:59 2005 @@ -1,28 +1,28 @@ -i had the pleasure to read the PHP's manual today. +I had the pleasure to read the PHP's manual today. http://www.php.net/manual/en/ -although Pretty Home Page is another criminal hack of the unix lineage, -but if we are here to judge the quality of its documentation, it is a +Although Pretty Home Page is another criminal hack of the unix lineage, +if we are here to judge the quality of its documentation, it is an impeccability. -it has or possesses properties of: +It has or possesses properties of: - To the point and useful. PHP has its roots in mundaness, like Perl and Apache. Its doc being -practicality oriented isn't a surprise, as are the docs of Perl and +practicality-oriented isn't a surprise; so are the docs of Perl and Apache. - Extreme clarity! The doc is extremely well-written. The authors's writing skills -shows, that they can present their ideas clearly, and also that they -have put thoughts into what they wanted to say. +show, they can present their ideas clearly, and they +have put thought into what they wanted to say. - Ample usage examples. - As with Perl's doc, PHP doc is not afraid to show example snippets, + As with Perl's doc, PHP's doc is not afraid to show example snippets, yet not abuse it as if simply slapping on examples in lieu of proper spec or discussion. @@ -31,18 +31,18 @@ This aspect is also well done in other quality docs, such as Mathematica, Java, MS JScript, Perl's official docs. -- No abuse of jargons. +- No abuse of jargon. - In fact, it's so well written that there's almost no jargons in its -docs, yet conveys its intentions to a tee. This aspect can also be seen + In fact, it's so well written that there's almost no jargon in its +docs, yet it conveys its intentions to a tee. This aspect can also be seen in Mathematica's doc, or Microsoft's JScript doc, for examples. -- No author masturbation. (if fact, you won't see a first-person +- No author masturbation. (In fact, you won't see a first-person perspective, as is the case with most quality tech writing.) -We must truely appreciate the authors of the PHP doc. Because, PHP, as +We must truly appreciate the authors of the PHP doc. Because PHP, as a free shit in the unix shit culture, with extreme ties to Perl and -Apache (both of which has extremely motherfucked docs), but can wean +Apache (both of which have extremely motherfucked docs), can wean itself from a shit milieu and stand pure and clean to become a paragon of technical writing. HTH -- Brad From bearophileHUGS at lycos.com Tue Dec 6 19:52:57 2005 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 6 Dec 2005 16:52:57 -0800 Subject: str attributes Message-ID: <1133916777.212340.175410@g49g2000cwa.googlegroups.com> I don't know if this was already discussed. I think that maybe Python 2.5 can add some attributes to the str object: >>> str.ascii_letters 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' >>> str.hexdigits '0123456789abcdefABCDEF' etc. And maybe this too: str.maketrans(from, to) (I think string.capwords() isn't important enough to be added too). Bye, bearophile From python at rcn.com Mon Dec 5 14:38:04 2005 From: python at rcn.com (Raymond Hettinger) Date: 5 Dec 2005 11:38:04 -0800 Subject: hash() References: Message-ID: <1133811484.798173.110860@g14g2000cwa.googlegroups.com> [John Marshall] > For strings of > 1 character, what are the chances > that hash(st) and hash(st[::-1]) would return the > same value? Python's string hash algorithm is non-commutative, so a collision with a reversed string is not likely. The exact answer depends on the population of strings being hashed, but it's not hard to compute collision statistics for a sampling of those strings: collisions = len(sample) - len(set(hash(s) for s in sample)) FWIW, here is how Python computes string hash values: static long string_hash(PyStringObject *a) { register int len; register unsigned char *p; register long x; len = a->ob_size; p = (unsigned char *) a->ob_sval; x = *p << 7; while (--len >= 0) x = (1000003*x) ^ *p++; x ^= a->ob_size; if (x == -1) x = -2; return x; } > My goal is to uniquely identify multicharacter strings, > all of which begin with "/" and never end with "/". > Therefore, st != st[::-1]. Just use a set -- no string reversal is needed for detection of unique multicharacter strings.. Raymond From fredrik at pythonware.com Wed Dec 14 16:04:55 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 14 Dec 2005 22:04:55 +0100 Subject: Simple (?) question about print statement References: <1134593069.007297.43690@o13g2000cwo.googlegroups.com> Message-ID: "TY" wrote: > I have this little simple script: > > for i in range(10): > for j in range(5000000): pass # Timing-delay loop > print i > > When you run it, it behaves as you would expect -- it prints 0 > on the next line prints 1 on the next line prints 2 > etc. > > But if you add a comma at the end of print statement on the last line > like this: > > for i in range(10): > for j in range(5000000): pass # Timing-delay loop > print i, > > Now it does this: > > then prints 0 1 2 3 4 5 6 7 8 9 all at once. > > Why????? > > How can I make it to print each numbers on the same line with pauses in > between them? because stdout is line buffered. try this instead: import time, sys for i in range(10): time.sleep(0.8) # seconds; tune as necessary print i, sys.stdout.flush() # flush stdout print From jeremy.d.brewer at gmail.com Thu Dec 1 14:30:39 2005 From: jeremy.d.brewer at gmail.com (jbrewer) Date: 1 Dec 2005 11:30:39 -0800 Subject: Python CGI In-Reply-To: <1133426940.268485.167600@g49g2000cwa.googlegroups.com> References: <1133412721.816114.64490@g43g2000cwa.googlegroups.com> <1133426940.268485.167600@g49g2000cwa.googlegroups.com> Message-ID: <1133465439.466709.119160@g47g2000cwa.googlegroups.com> Thanks guys. I didn't realize that hidden form fields were so easy to use. Jeremy From fredrik at pythonware.com Tue Dec 6 15:49:28 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 6 Dec 2005 21:49:28 +0100 Subject: Calculating Elapsed Time References: <20051206203655.33326.qmail@web35704.mail.mud.yahoo.com> Message-ID: Jean Johnson wrote: > I have a start and end time that is written using the > following: > > time.strftime("%b %d %Y %H:%M:%S") > > How do I calculate the elapsed time? import time FORMAT = "%b %d %Y %H:%M:%S" t1 = time.strftime(FORMAT) print t1 time.sleep(1) t2 = time.strftime(FORMAT) print t2 # later s1 = time.mktime(time.strptime(t1, FORMAT)) s2 = time.mktime(time.strptime(t2, FORMAT)) print s2 - s1 From http Tue Dec 6 02:18:28 2005 From: http (Paul Rubin) Date: 05 Dec 2005 23:18:28 -0800 Subject: Tabs bad References: <1133174924.322968.273370@o13g2000cwo.googlegroups.com> <1133436396.469598.183880@g44g2000cwa.googlegroups.com> <1133444785.664900.103910@g14g2000cwa.googlegroups.com> <1133448804.937838.71220@g43g2000cwa.googlegroups.com> <1133546901.454612.158690@o13g2000cwo.googlegroups.com> <8441p15lu4h7u0gd0jcm0ac732fkjuahvt@4ax.com> <1133550936.417650.141880@g14g2000cwa.googlegroups.com> <439201f7$1@nntp0.pdx.net> <87d5kd5kgz.fsf_-_@lucien.dreaming> <87psoau2m2.fsf@lucien.dreaming> Message-ID: <7xacfeae2j.fsf@ruckus.brouhaha.com> bkhl at stp.lingfil.uu.se (Bj?rn Lindstr?m) writes: > Actually using tabs for eight spaces and then filling out with spaces to > the correct indentation is the convention for Emacs Lisp. Of course, > since everyone coding Emacs Lisp does it with the same editor, it's no > problem. The variable `indent-tabs-mode' controls this. I like no tabs. From zorro at chez.Com Wed Dec 21 06:18:04 2005 From: zorro at chez.Com (JB) Date: Wed, 21 Dec 2005 12:18:04 +0100 Subject: Guido at Google Message-ID: <43a939e3$0$23986$626a14ce@news.free.fr> It seems that our master Guido van Rossum had an offer from google and he accepted it!! long life to Guido & Goole ! many things to come ;) ju? From skip at pobox.com Wed Dec 7 07:33:49 2005 From: skip at pobox.com (skip at pobox.com) Date: Wed, 7 Dec 2005 06:33:49 -0600 Subject: Documentation suggestions In-Reply-To: <1133957439.216561.206010@g47g2000cwa.googlegroups.com> References: <1133957439.216561.206010@g47g2000cwa.googlegroups.com> Message-ID: <17302.54957.614886.327023@montanaro.dyndns.org> >> The library reference has so many modules that the table of contents >> is very large. Again, not really a problem that we can fix; >> splitting it up into separate manuals doesn't seem like it would >> help. Iain> I like the Global Module Index in general - it allows quick access Iain> to exactly what I want. I would like a minor change to it though Iain> - stop words starting with a given letter rolling over to another Iain> column (for example, os.path is at the foot of one column, while Iain> ossaudiodev is at the head of the next), and provide links to each Iain> initial letter at the top of the page. I know it's not what you asked for, but give http://staging.musi-cal.com/modindex/ a try. See if by dynamically migrating the most frequently requested modules to the front of the section it becomes more manageable. Skip From pemboa at gmail.com Sat Dec 31 01:57:28 2005 From: pemboa at gmail.com (Arthur Pemberton) Date: Sat, 31 Dec 2005 00:57:28 -0600 Subject: Photogallery written in Python? Message-ID: <16de708d0512302257r34a9a349g7875a5c704599437@mail.gmail.com> Does anyone know of a photo gallery implemented in python? Preferably one as featureful as those used at kde-look.org and art.gnome.org? Thank you. -- As a boy I jumped through Windows, as a man I play with Penguins. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jstroud at ucla.edu Sat Dec 17 17:01:03 2005 From: jstroud at ucla.edu (James Stroud) Date: Sat, 17 Dec 2005 14:01:03 -0800 Subject: Tkinter interactive In-Reply-To: References: Message-ID: cm012b5105 wrote: > Hello i am fairly new to python, > I have written an interactive programme a small example of it is here. > s = raw_input ("Do you have any children? ") > if s== 'yes': > print "Thats great" > elif s=='no': > print "Well my boss has 2" > > > Now i have also been looking at Tkinter if we take the basic "hello, world" > programme which is like this. > > # File: hello1.py > > from Tkinter import * > > root = Tk() > > w = Label(root, text="Hello,!") > w.pack() > > root.mainloop() > > What i want is to incorporate this in to my programme so when i start my > programme a little box appears saying hello then my interactive programme > runs within the box > This it what it looks like > > from Tkinter import * > > root = Tk() > > w = Label(root, text="Hello,!") > w.pack() > s = raw_input ("Do you have any children? ") > if s== 'yes': > print "Thats great" > elif s=='no': > print "Well my boss has 2" > > The result of that is i just get another box open and start to run my > interactive programme as though it ignores the Tk box which says hello hope > this makes sense any advise on this please. > thanks nige GUI programming is kind of advanced. It is tough to make a leap from the hello world program of a new language to an interactive gui interface. I think you can save yourself a lot of frustration and confusion by first working throught the python tutorial: http://docs.python.org/tut/tut.html Then working throught the "Tkinter tutorial": http://www.python.org/doc/life-preserver/ Pound these out over the course of a few weekends and you will be leaps and bounds further in your understanding than if you attempted to learn through unguided exploration (though the latter may be more fun sometimes). James From shane at hathawaymix.org Fri Dec 9 19:31:18 2005 From: shane at hathawaymix.org (Shane Hathaway) Date: Fri, 09 Dec 2005 17:31:18 -0700 Subject: Proposal: Inline Import In-Reply-To: References: Message-ID: <439A21D6.7040207@hathawaymix.org> Xavier Morel wrote: > Shane Hathaway wrote: > >>Thoughts? > > > >>> import re; name_expr = re.compile('[a-zA-Z]+') > >>> name_expr > <_sre.SRE_Pattern object at 0x00F9D338> > >>> > > the import statement can be called anywhere in the code, why would you > add strange syntactic sugar that doesn't actually bring anything? That syntax is verbose and avoided by most coders because of the speed penalty. It doesn't replace the idiom of importing everything at the top of the module. What's really got me down is the level of effort required to move code between modules. After I cut 100 lines from a 500 line module and paste them to a different 500 line module, I have to examine every import in both modules as well as examine the code I moved for missing imports. And I still miss a lot of cases. My test suite catches a lot of the mistakes, but it can't catch everything. If I could just avoid import statements altogether, moving code would be easier, regardless of extra typing. But I can't avoid import statements unless there's a different way to import that lots of people like. Shane From bokr at oz.net Thu Dec 22 14:56:08 2005 From: bokr at oz.net (Bengt Richter) Date: Thu, 22 Dec 2005 19:56:08 GMT Subject: jython: True and False boolean literals? References: <1135277482.738555.166060@f14g2000cwb.googlegroups.com> Message-ID: <43ab04ba.360618782@news.oz.net> On 22 Dec 2005 10:51:22 -0800, davidmichaelkarr at gmail.com wrote: >Aren't there boolean literals for "True" and "False" in Python >(jython)? I can't get "true", "True", "false", or "False" to work. I >ended up having to use "(1==1)" and "(1==0)". > You may want to upgrade to a newer version. Regards, Bengt Richter From cjw at sympatico.ca Sun Dec 25 19:08:38 2005 From: cjw at sympatico.ca (Colin J. Williams) Date: Sun, 25 Dec 2005 19:08:38 -0500 Subject: Python IDE's In-Reply-To: <8zlrf.5426$oW.423@newssvr11.news.prodigy.com> References: <8zlrf.5426$oW.423@newssvr11.news.prodigy.com> Message-ID: J. D. Leach wrote: > Quick question as I am rather new to Python. What is the preferred tool > amongst you gurus to use in coding Python? I have ran across Eric3 and > found it to be pretty well full-featured. Any comments or suggestions for > better tools/IDE's? > > J.D. Leach I wouldn't say "preferred" yet but I've started using PyScripter and am favourably impressed. Colin W. From steve at REMOVETHIScyber.com.au Fri Dec 30 23:52:30 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sat, 31 Dec 2005 15:52:30 +1100 Subject: why writing list to file puts each item from list on seperate line? References: <1136002972.824455.273390@g14g2000cwa.googlegroups.com> Message-ID: On Fri, 30 Dec 2005 20:22:52 -0800, homepricemaps wrote: > if i use the code below to write a list to a file > > list = (food, price, store) Why are you shadowing the built in type list? This is bad practice. Sooner or later you will do this: list = [1, 2, 3] something = process(list) ... lots of code ... # try to convert to a list myList = list(something) and then you'll spend ages trying to work out why list() raises an exception. > data.append(list) > f = open(r"test.txt", 'a') > f.write ( os.linesep.join( list ) ) > > > it outputs to a file like this > > apple > .49 > star market That's what you told it to do. Walk through the code: >>> data = [] >>> L = ("apple", "0.49", "market") >>> data.append(L) >>> data [("apple", "0.49", "market")] # a list with one tuple So far so good. But now watch: >>> f = open(r"test.txt", 'a') I hope you aren't opening the file EVERY time you want to write a single line >>> f.write(os.linesep.join(L)) Remember what L is: ("apple", "0.49", "market"). You now join that list (actually a tuple) into a single string: "apple\n0.49\nmarket\n" and write that string to the file. What happened to data? It never gets used after you append to it. > and i want it to do > > apple, .49. star market Then what you want to do is change data to a list of strings rather than a list of tuples. Before appending to data, you join the tuple ("apple", "0.49", "market") like so: data.append(", ".join(L) + "\n") # note newline at the end of each line Then, after you have appended ALL the lines, you open your file once for writing, and write data in one go: f.writelines(data) Hope this helps. -- Steven. From fredrik at pythonware.com Tue Dec 20 09:42:15 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 20 Dec 2005 15:42:15 +0100 Subject: pythonic equivalent of upvar? References: <20051220141030.GA22256@mrao.cam.ac.uk> Message-ID: David MacKay wrote: > def main(): > ## Define DEFAULTS that can be overridden on the command line > decode=0 ## are we decoding? > verbose=0 ## verbose output? > bits=7 ## how big are the blocks? > N = 10000 ## What is the file length? > file="blah" ## file name string class options: decode = False # are we decoding? verbose = False # verbose output? bits = 7 # how big are the blocks? N = 10000 # What is the file length? file = "blah" # file name string read_options(options) From istvan.albert at gmail.com Thu Dec 1 22:14:15 2005 From: istvan.albert at gmail.com (Istvan Albert) Date: 1 Dec 2005 19:14:15 -0800 Subject: CGI question References: <1133297606.952324.251210@g44g2000cwa.googlegroups.com> Message-ID: <1133493255.300293.175370@g43g2000cwa.googlegroups.com> > I'm still wondering though, if there's some part of the python standard > modules that will convert those % escapes to ASCII or similar - and I believe that functionality is provided by the quote/unquote functions in the urllib module: http://www.python.org/doc/current/lib/module-urllib.html Istvan. From bram at geenspam.sara.nl Mon Dec 12 11:22:56 2005 From: bram at geenspam.sara.nl (Bram Stolk) Date: Mon, 12 Dec 2005 17:22:56 +0100 Subject: how fast can you pingpong pickled objects? Message-ID: <1134404525.155291@blaat.sara.nl> Hi there, I'm transfering small pickled object over a socket. The performance I see is lower than expected. How fast should I be able to ping/pong small objects in python? I use a threaded SocketServer, telnetlib and pickle to test this, and I see that a 100 ping-pongs take 4 seconds or so, (over the localhost network). ping localhost gives me 0.06 msec, so the network is fast enough. My test code is here: http://stolk.org/tmp/pingpong.py Is there a limit in Python on how many times per second a thread can be scheduled? Thanks, Bram From mwm at mired.org Tue Dec 13 16:55:14 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 13 Dec 2005 16:55:14 -0500 Subject: Another newbie question References: <863bl4xk11.fsf@bhuda.mired.org> <7xd5k71avc.fsf@ruckus.brouhaha.com> <4398D289.9050902@REMOVEMEcyber.com.au> <86vexzvy86.fsf@bhuda.mired.org> <8664pxv523.fsf@bhuda.mired.org> Message-ID: <86fyowu0fx.fsf@bhuda.mired.org> Antoon Pardon writes: > Op 2005-12-11, Steven D'Aprano schreef : >> On Sat, 10 Dec 2005 15:46:35 +0000, Antoon Pardon wrote: >> Do you really think that my class and some other class written by >> another person will have the same API? > If both writers try to implement the same kind of object I would > think the API would be very similar yes. That's why we have one great web applications platform, right? http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From gandalf at designaproduct.biz Tue Dec 6 00:14:32 2005 From: gandalf at designaproduct.biz (Laszlo Zsolt Nagy) Date: Tue, 06 Dec 2005 06:14:32 +0100 Subject: extract python install info from registry In-Reply-To: References: Message-ID: <43951E38.5000503@designaproduct.biz> >There's more to it than that... isn't there? I've used _winreg and the >win32 extensions in the past when working with the registry. I thought >perhaps someone had already scripted something to extract this info. > > Ok, if you need to get all changes in the registry, you can use regdiff. http://p-nand-q.com/download/regdiff.html Take a snapshot before and after installing Python. However, this is not a wise approach. For example: 1. One can have a system drive 'C:\' others 'G:\' 2. One can have Windows installed in \Windows others in \WinNT and others in \MyWinNT 3. For many registry values, you cannot really tell if you need to correct a value or not. As a result, I believe you will only be able to use the 'regdiff' only on the same type of computer, with the same system drive, same system directory, same windows version etc. For other computers, there is no guarantee for that it will work. Les From muttu2244 at yahoo.com Thu Dec 15 19:09:51 2005 From: muttu2244 at yahoo.com (muttu2244 at yahoo.com) Date: 15 Dec 2005 16:09:51 -0800 Subject: doubt on csv file In-Reply-To: References: <1134685079.284072.308350@g14g2000cwa.googlegroups.com> Message-ID: <1134691791.548428.97690@o13g2000cwo.googlegroups.com> hey thanks a lot for that it worked . From spe.stani.be at gmail.com Wed Dec 21 15:37:49 2005 From: spe.stani.be at gmail.com (SPE - Stani's Python Editor) Date: 21 Dec 2005 12:37:49 -0800 Subject: ANN: SPE 0.8.1.b IDE (realtime error underlining & script tooltips) Message-ID: <1135197469.690051.59190@o13g2000cwo.googlegroups.com> Release news from http://pythonide.stani.be This new release is for under your Christmas tree. (If you want more presents, just donate to SPE and receive the manual in your mailbox ;-) There are so many changes and fixes. The new cool features not to be missed are the realtime error underlinging and the tooltips for the file tabs, which gives you a preview of the file by the docstring. Mac users should upgrade as this fixed the most critical bug of SPE on Mac, the click inside selection crash. So just open the package and discover the present... :**New features**: - errors are underlined in red as you type (as preference) - tooltips on tabs showing path and docstring - drag and drop for script tabs - Edit>Show docstring (Ctrl+Shift+Space) - middle click pastes selected text - single instance application (enable it as preference) :**Improved features**: - file tabs (thanks to Andrea Gavana's NotebookCtrl) - add single click toggle for explore (not for Mac) - better code completion and docstring - dialog popup to confirm save before executing whole file - if signature not specified opens a choose file dialog - selected text is now always copied to the find dialog :**Fixes**: - clicking inside selection=deselect(no mac crash anymore) - launching debugger - removed unnecessary print statement - find in files clear behavior (by Thurston Stone) - ask to save before running a modified file - changed text 'save before run' to 'save before execute' - run with sys.executable (movable python) - info.PYTHON_EXEC to pythonw for Mac - __name__ in shell is now "__main__" for executing scripts - Kiki dialog box (by Andrea Gavana) - import sys when right version wxPython is not found **Changes**: - auto reload change file is off by default :**Contributors**: - Andrea Gavana - Thurston Stone - Bill Peterson (manual review) - Michael Foord (manual review) - Theo de Ridder (for a lot of suggestions & critical feedback) :**Donations**: - Ramon Diaz-Uriarte, http://ligarto.org/rdiaz (15 euro) - Dmeetry Raizman, Symula Inc, http://www.symula.com (20 dollar) Both donators received the SPE manual. :**Installation**: - See http://pythonide.stani.be/manual/html/manual2.html - There is now an update section for MacOS X! :**Development**: - http://developer.berlios.de/mail/?group_id=4161\ SVN 117 About SPE: SPE is a python IDE with auto-indentation, auto completion, call tips, syntax coloring, uml viewer, syntax highlighting, class explorer, source index, auto todo list, sticky notes, integrated pycrust shell, python file browser, recent file browser, drag&drop, context help, ... Special is its blender support with a blender 3d object browser and its ability to run interactively inside blender. Spe integrates with XRCed (gui designer) and ships with wxGlade (gui designer), PyChecker (source code doctor), Kiki (regular expression console) and WinPdb (remote, multi-threaded debugger). SPE is looking for people who can take screenshots for the new tutorial. The development of SPE is driven by its donations. Anyone who donates can ask for an nice pdf version of the manual without ads (60 pages). From amca01 at gmail.com Sun Dec 4 02:27:37 2005 From: amca01 at gmail.com (Alasdair) Date: 3 Dec 2005 23:27:37 -0800 Subject: Trouble with idle from python 2.4.2 on SUSE linux 9.3 Message-ID: <1133681257.915728.87140@g43g2000cwa.googlegroups.com> I've just installed python 2.4.2 from source - it works fine from the command line. But when I attempt to start idle, I am told: ** IDLE can't import Tkinter. Your Python may not be configured for Tk. ** I have tcl 8.4 and tk 8.4 on my system; can anybody provide me with some advice? Sorry if this is a FAQ; I've spent some time searching the net for helpful clues, and I am a python ultra-newbie. Thanks, Alasdair From mjackson at alumni.caltech.edu Wed Dec 7 13:38:13 2005 From: mjackson at alumni.caltech.edu (Mark Jackson) Date: 7 Dec 2005 18:38:13 GMT Subject: Documentation suggestions References: <1133957439.216561.206010@g47g2000cwa.googlegroups.com> Message-ID: Steven Bethard writes: > skip at pobox.com wrote: > > Iain> I like the Global Module Index in general - it allows quick access > > Iain> to exactly what I want. I would like a minor change to it though > > Iain> - stop words starting with a given letter rolling over to another > > Iain> column (for example, os.path is at the foot of one column, while > > Iain> ossaudiodev is at the head of the next), and provide links to each > > Iain> initial letter at the top of the page. > > > > I know it's not what you asked for, but give > > > > http://staging.musi-cal.com/modindex/ > > > > a try. See if by dynamically migrating the most frequently requested > > modules to the front of the section it becomes more manageable. > > That's pretty cool. What I don't know is how it would look after > thousands of people using it. I know that I probably only have 10 > modules or so that I consistently need to check the docs for. Your hack > above would conveniently place those all at the top if I was the only > user. But are those 10 modules the same 10 modules that other folks > need? I don't know... > > Of course, the only way to find out is to try... Or you can just look up the module you need to write a 'bot to constantly look up the docs for your favorite 10 modules. . . . -- Mark Jackson - http://www.alumni.caltech.edu/~mjackson If it made sense, that would be a very powerful idea. - Bruce Eric Kaplan From carsten at uniqsys.com Wed Dec 14 13:12:48 2005 From: carsten at uniqsys.com (Carsten Haese) Date: Wed, 14 Dec 2005 13:12:48 -0500 Subject: Python C/API - *arg,**kwds variable argumnents In-Reply-To: <1134579601.397238.136460@o13g2000cwo.googlegroups.com> References: <1134550072.264022.251540@g44g2000cwa.googlegroups.com> <1134579073.583892.88150@z14g2000cwz.googlegroups.com> <1134579601.397238.136460@o13g2000cwo.googlegroups.com> Message-ID: <1134583968.26584.13.camel@dot.uniqsys.com> On Wed, 2005-12-14 at 12:00, mdcb808 at gmail.com wrote: > essentially I already use PyArg_ParseTupleAndKeywords, but that seems > to emulate fixed arg list definitions like - > func (x,y,t=0,u=1) It's unclear what you are actually trying to accomplish. My guess is that you want to implement a function/method that takes any number of arbitrarily named keyword arguments. If that is the case, you can simply use the dictionary that is passed to your C function as the third argument. Hope this helps, Carsten. From adelagon at gmail.com Wed Dec 28 22:04:10 2005 From: adelagon at gmail.com (Alvin A. Delagon) Date: Thu, 29 Dec 2005 11:04:10 +0800 Subject: getting the status codes from the ftplib module Message-ID: <43B3522A.3070507@gmail.com> I'm very sorry, newbie here! @_@ I'm still getting the hang of Thunderbird. From ray_usenet at yahoo.com Thu Dec 22 19:02:34 2005 From: ray_usenet at yahoo.com (Ray) Date: 22 Dec 2005 16:02:34 -0800 Subject: Please enlighten me about PyPy In-Reply-To: References: <1135220393.141758.62590@g43g2000cwa.googlegroups.com> Message-ID: <1135295999.812047.198350@o13g2000cwo.googlegroups.com> Carl Friedrich Bolz wrote: > Hi! > > some more pointers in addition to the good stuff that Luis wrote... Thanks Carl! That solidified my mental picture of PyPy a lot more :) Warm regards, Ray From justin.azoff at gmail.com Wed Dec 28 23:21:56 2005 From: justin.azoff at gmail.com (Justin Azoff) Date: 28 Dec 2005 20:21:56 -0800 Subject: Number set type References: <1135823048.653998.206650@o13g2000cwo.googlegroups.com> Message-ID: <1135830116.674097.278680@f14g2000cwb.googlegroups.com> Heiko Wundram wrote: > Union of two IP4Ranges is simply normalizing a concatenated list of both > IP4Range ranges. Normalizing takes O(log n)+O(n) = O(n) steps, where n is > the number of ranges in the combined IP4Range. I see now :-) If the ranges are sorted, I bet you could just iterate through both at the same time, merging intersecting ranges where possible. > Intersection takes O(n^2) steps in my current implementation (which I know > is mathematically correct), where n is max(n_1,n_2) where n_1 is the number > of ranges in the first IP4Range and n_2 the number of ranges in the second > IP4Range respectively. > > Intersecting two IP4Ranges can be done with fewer steps, and I think it > could be done in O(n) in the case of normalized and sorted ranges, and I > have a few ideas of myself, but I'm currently too lazy to try to prove them > correct. Yes.. if they are sorted, something like this should work: def intersection(self, other): ret = [] ai=iter(self.ranges) bi=iter(other.ranges) try : a = ai.next() b = bi.next() except StopIteration: return IP4Range([]) while 1: try : if a.intersects(b): ret.append(a.intersection(b)) a = ai.next() b = bi.next() elif a.start < b.start: a = ai.next() else : b = bi.next() except StopIteration: break return IP4Range(ret) -- - Justin From paul at boddie.org.uk Sun Dec 11 17:49:47 2005 From: paul at boddie.org.uk (Paul Boddie) Date: 11 Dec 2005 14:49:47 -0800 Subject: XML and namespaces In-Reply-To: References: <1133820095.330922.192960@g47g2000cwa.googlegroups.com> <1134321906.625557.38100@g44g2000cwa.googlegroups.com> Message-ID: <1134341387.675379.175970@g14g2000cwa.googlegroups.com> Alan Kennedy wrote: > Serialisation and namespace normalisation are both in the realm of DOM > Level 3, whereas minidom is only L2 compliant. Automagically introducing > L3 semantics into the L2 implementation is the wrong thing to do. I think I'll have to either add some configuration support, in order to let the user specify which standards they have in mind, or to deny/assert support for one or another of the standards. It's interesting that minidom plus PrettyPrint seems to generate the xmlns attributes in the serialisation, though; should that be reported as a bug? As for the toxml method in minidom, the subject did seem to be briefly discussed on the XML-SIG mailing list earlier in the year: http://mail.python.org/pipermail/xml-sig/2005-July/011157.html > its-not-about-namespaces-its-about-automagic-ly'yrs Well, with the automagic, all DOM users get the once in a lifetime chance to exchange those lead boots for concrete ones. I'm sure there are all sorts of interesting reasons for assigning namespaces to nodes, serialising the document, and then not getting all the document information back when parsing it, but I'd rather be spared all the "amusement" behind all those reasons and just have life made easier for just about everyone concerned. I think the closing remarks in the following message say it pretty well: http://mail-archives.apache.org/mod_mbox/xml-security-dev/200409.mbox/<1095071819.17967.44.camel%40amida> And there are some interesting comments on this archived page, too: http://web.archive.org/web/20010211173643/http://xmlbastard.editthispage.com/discuss/msgReader$6 Anyway, thank you for your helpful commentary on this matter! Paul From gene.tani at gmail.com Mon Dec 12 12:58:06 2005 From: gene.tani at gmail.com (gene tani) Date: 12 Dec 2005 09:58:06 -0800 Subject: PHP = Perl Improved In-Reply-To: References: <1133844932.007824.26780@g43g2000cwa.googlegroups.com> <1134056349.035360.209840@f14g2000cwb.googlegroups.com> <1134155716.631143.191340@f14g2000cwb.googlegroups.com> Message-ID: <1134410286.888136.290900@g44g2000cwa.googlegroups.com> Tim Roberts wrote: > "Xah Lee" wrote: > > >recently i got a project that involves the use of php. In 2 days, i > >read almost the entirety of the php doc. Finding it a breeze because it > >is roughly based on Perl, of which i have mastery. > > > >i felt a sensation of neatness, as if php = Perl Improved, for a > >dedicated job of server-side scripting. > > The design of the PHP language is not too bad, and the standard library is > extensive. It is quite possible to write well-structured, class-based web > programs with PHP. > > However, it seems that almost no one actually does so. Virtually all of > the vast PHP code samples on the web are crap. Maybe the simplicity of the > language encourages inexperienced programmers who write spaghetti code > without a thought to the structure; I don't know the exact cause, but I > have seen it more often than not. > -- > - Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. agreed, once you explain MVC, it's pretty hard to argue against it. Keeping from getting defaced is another matter. About a year ago, this page (or somethign very similar) was php.net's *homepage*, I almost fell over when i saw it. Moral of hte story, don't use shared server. http://www.php.net/security-note.php From tutufan at gmail.com Fri Dec 9 11:41:29 2005 From: tutufan at gmail.com (tutufan at gmail.com) Date: 9 Dec 2005 08:41:29 -0800 Subject: what's wrong with "lambda x : print x/60,x%60" References: <1133823550.667597.186820@g14g2000cwa.googlegroups.com> <7xd5kaj4ac.fsf@ruckus.brouhaha.com> <1133839905.988733.168440@g14g2000cwa.googlegroups.com> <1133859120.717550.211900@g47g2000cwa.googlegroups.com> <7xfyp6d2ba.fsf@ruckus.brouhaha.com> Message-ID: <1134146489.129213.31630@g49g2000cwa.googlegroups.com> Re using the same variable name over and over for different objects in the same scope: Argh--don't do this. It makes a mess for the guy (or gal) that comes after you and has to understand the code. Our forefathers fought and died so that we could have as many unique variable names as we like. So use them! From utabintarbo at gmail.com Fri Dec 9 09:49:14 2005 From: utabintarbo at gmail.com (utabintarbo) Date: 9 Dec 2005 06:49:14 -0800 Subject: Encoding of file names In-Reply-To: References: <1134046955.592312.301590@f14g2000cwb.googlegroups.com> <1134064103.056405.28470@f14g2000cwb.googlegroups.com> <4398B772.2070008@v.loewis.de> Message-ID: <1134139754.532809.112060@g47g2000cwa.googlegroups.com> Part of the reason (I think) is that our CAD/Data Management system (which produces the aforementioned .MODEL files) substitutes (stupidly, IMNSHO) non-printable characters for embedded spaces in file names. This is part of what leads to my consternation here. And yeah, Windows isn't helping matters much. No surprise there. :-P Just for s&g's, I ran this on python 2.3 on knoppix: >>> DIR = os.getcwd() >>> files = os.listdir(DIR) >>> file = files[-1] >>> print file L07JS41C.04389525AA.QTR?INR.E?C-P.D11.081305.P2.KPF.model >>> print repr(file) 'L07JS41C.04389525AA.QTR\xb1INR.E\xb4C-P.D11.081305.P2.KPF.model' >>> fullname = os.path.join(DIR, file) >>> print os.path.isfile(fullname) True <--- It works fine here >>> print os.path.isdir(fullname) False >>> files = os.listdir(unicode(DIR)) >>> file = files[-1] >>> print file L07JS41C.04389525AA.QTR?INR.E?C-P.D11.081305.P2.KPF.model >>> print repr(file) 'L07JS41C.04389525AA.QTR\xb1INR.E\xb4C-P.D11.081305.P2.KPF.model' >>> fullname = os.path.join(DIR, file) >>> print os.path.isfile(fullname) True <--- It works fine here too! >>> print os.path.isdir(fullname) False >>> This is when mounting the same samba share in Linux. This tends to support Tom's point re:the "non-roundtrippability" thing. Thanks again to all. From steve at REMOVETHIScyber.com.au Sun Dec 18 07:39:00 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 18 Dec 2005 23:39:00 +1100 Subject: Accessing next/prev element while for looping References: Message-ID: On Sun, 18 Dec 2005 23:36:29 +1100, Steven D'Aprano wrote: > Python lists aren't linked lists? They are arrays. [slaps head for the stupid typo] That should have been a full stop, not question mark. Python lists are not linked lists, period. -- Steven. From x at y.z Tue Dec 6 12:29:59 2005 From: x at y.z (D H) Date: Tue, 06 Dec 2005 11:29:59 -0600 Subject: Documentation suggestions In-Reply-To: <1133888936.173226.105630@g49g2000cwa.googlegroups.com> References: <1133888936.173226.105630@g49g2000cwa.googlegroups.com> Message-ID: Ian Bicking wrote: >>There are endless minor bugs in the library reference, but that seems >>unavoidable. It documents many different and shifting modules, and >>what to document is itself a contentious issue, so I don't think the >>stream of small problems will ever cease. > > > Since the topic of php.net-style comments comes up often, I thought I'd > note I've been working on a comment system: > http://pythonpaste.org/comment/commentary/ -- this might be useful for > collecting and managing small updates and fixes to the documentation. Yes, do it the way php's documentation is done, Xah Lee's recent trolls aside. From amk at amk.ca Thu Dec 8 09:38:43 2005 From: amk at amk.ca (A.M. Kuchling) Date: Thu, 08 Dec 2005 08:38:43 -0600 Subject: Documentation suggestions References: <1133888319.779023.53940@o13g2000cwo.googlegroups.com> <1133919072.484143.234100@g47g2000cwa.googlegroups.com> <43971481$1_3@newspeer2.tds.net> Message-ID: <5PmdnZAaFPPu2AXeRVn-sQ@speakeasy.net> On Wed, 07 Dec 2005 12:10:18 -0500, Kent Johnson wrote: > OK I'll bite. That Beginners Guide page has bugged me for a long time. > It's a wiki page but it is marked as immutable so I can't change it. > Here are some immediate suggestions: Good suggestions; thanks! I've applied most of them. > - Change the sentence "Read BeginnersGuide/Overview to learn the key > points." to "Read BeginnersGuide/Overview to learn what makes Python > special." Or maybe get rid of it completely - I'm not sure evangelism > belongs on this page. Yes, it does; fairly often the webmaster alias receives e-mails that ask "so what is Python?" --amk From bearophileHUGS at lycos.com Thu Dec 1 09:01:00 2005 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 1 Dec 2005 06:01:00 -0800 Subject: for x in list that maximizes f(x)] <--newbie help In-Reply-To: <1133444754.901618.265580@z14g2000cwz.googlegroups.com> References: <1133444754.901618.265580@z14g2000cwz.googlegroups.com> Message-ID: <1133445659.944297.300670@z14g2000cwz.googlegroups.com> If the elements of mylist can be compared (es. not complex values), then this can be a solution for you: from math import sin as f mylist = [float(2*i)/10 for i in xrange(10)] pairs = [(f(x), x) for x in mylist] ymax = max(pairs)[1] print pairs, "\n" print ymax You can also try this, for Py2.4: print max((f(x), x) for x in mylist)[1] Bye, bearophile From lycka at carmen.se Wed Dec 14 03:58:02 2005 From: lycka at carmen.se (Magnus Lycka) Date: Wed, 14 Dec 2005 09:58:02 +0100 Subject: OO in Python? ^^ In-Reply-To: <1134486233.926141.49140@g47g2000cwa.googlegroups.com> References: <1134486233.926141.49140@g47g2000cwa.googlegroups.com> Message-ID: bonono at gmail.com wrote: > Magnus Lycka wrote: > >>The static typing means that you either have to make several >>implementations of many algorithms, or you need to work with >>those convoluted templates that were added to the language as >>an afterthought. > > I don't see this in Haskell. No, I was refering to C++ when I talked about templates. I don't really know Haskell, so I can't really compare it to Python. A smarter compiler can certainly infer types from the code and assemble several implementations of an algorithm, but unless I'm confused, this makes it difficult to do the kind of dynamic linking / late binding that we do in Python. How do you compile a dynamic library without locking library users to specific types? I don't doubt that it's possible to make a statically typed language much less assembly like than C++... From mwm at mired.org Thu Dec 1 23:38:47 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 01 Dec 2005 23:38:47 -0500 Subject: Making immutable instances References: <8664qgghvu.fsf@bhuda.mired.org> <7xirua3d3p.fsf@ruckus.brouhaha.com> <86u0duodzl.fsf@bhuda.mired.org> <1133333467.677454.134110@g49g2000cwa.googlegroups.com> <86acfloox6.fsf@bhuda.mired.org> <1133402729.430608.21400@g43g2000cwa.googlegroups.com> <86fypdmpi5.fsf@bhuda.mired.org> <1133410318.274544.326740@g47g2000cwa.googlegroups.com> <86zmnll9z3.fsf@bhuda.mired.org> <1133412285.671655.294540@g49g2000cwa.googlegroups.com> <86vey9l6x9.fsf@bhuda.mired.org> <1133420913.475070.200660@f14g2000cwb.googlegroups.com> <86oe41l1h6.fsf@bhuda.mired.org> <1133422590.108177.36850@g44g2000cwa.googlegroups.com> <86u0dsraaz.fsf@bhuda.mired.org> <7xmzjklkeb.fsf@ruckus.brouhaha.com> <86r78wpd00.fsf@bhuda.mired.org> <1133487114.936205.264880@z14g2000cwz.googlegroups.com> <863blcp647.fsf@bhuda.mired.org> <1133492105.359639.114990@z14g2000cwz.googlegroups.com> Message-ID: <86psogyuy0.fsf@bhuda.mired.org> bonono at gmail.com writes: > Mike Meyer wrote: >> > By design, this is a "don't use" feature so it would be very hard to >> > find a "use case" ;-) >> But I can think of use cases for instances with no mutable attributes, >> which is another "don't use" case. If I can do that, those proposing >> that instances ought to be immutable should be able to come up with a >> use case. > Lose you, can you clarify ? There are lots of use cases where you want your attributes to be immutable. Rationals, enums, anything where you want your instance to contain some used as a "value", or usable as a dictionary key that might equal other instances, or - well, you should get the idea. >> This is a problem with OO in general, not with not having immutable >> instances. You get the same problem if, instead of attaching >> attributes to your instances, I subclass your class and add the >> attribute in the subclass (which I can do even if both my instances >> and yours are immutable). In short, immutable instances don't solve >> your problem, so this doesn't work as a use case. > um, that could be true(already forgot if I can do this in say C++). How > would I solve this kind of issue then, just curious. B&D languages have facilities for doing this kind of thing. Alex Martelli has mentioned "final" classes in Java. C++ and Eiffel let you declare an attribute as not modifiable by subclasses. Eiffel requires that subclasses that override attributes (or methods, for that matter) do so in a type-compatable manner, so you'd probably get a compile error in your subclass in this case. There are certainly methods I've never heard of as well. In Python, you can do things that try and enforce this (I don't know how, because it's not something I think is reasonable to want to do), but the language is also powerful enough that I'd be surprised if they couldn't be defeated in some manner. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From paul at boddie.org.uk Sun Dec 11 11:30:03 2005 From: paul at boddie.org.uk (Paul Boddie) Date: 11 Dec 2005 08:30:03 -0800 Subject: OO in Python? ^^ References: <1134259673.171328.313630@f14g2000cwb.googlegroups.com> Message-ID: <1134318603.314458.169280@g47g2000cwa.googlegroups.com> Heiko Wundram wrote: > Maybe I'm assuming things by thinking that others also follow my line of > thought, but I've actually had very positive responses so far when telling > people that a certain feature is a certain way and then pointing them to > the ZoP, they all pretty much told me after a certain time of thought that > "the decision made sense now." Sorry to come across all harsh on the subject. Perhaps you know people who are more meditative than I do, but I notice that you served up some concrete advice elsewhere in the thread, so if the ZoP doesn't provide any guidance to the questioner as it is, at least there's something else to read through and grasp. Paul From apardon at forel.vub.ac.be Fri Dec 2 04:48:25 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 2 Dec 2005 09:48:25 GMT Subject: Death to tuples! References: <86y839ux1j.fsf@bhuda.mired.org> <86y834rcfb.fsf@bhuda.mired.org> <86vey8pesd.fsf@bhuda.mired.org> Message-ID: On 2005-12-01, Mike Meyer wrote: > Antoon Pardon writes: >> On 2005-12-01, Mike Meyer wrote: >>> Antoon Pardon writes: >>>> I know what happens, I would like to know, why they made this choice. >>>> One could argue that the expression for the default argument belongs >>>> to the code for the function and thus should be executed at call time. >>>> Not at definion time. Just as other expressions in the function are >>>> not evaluated at definition time. >>> >>> The idiom to get a default argument evaluated at call time with the >>> current behavior is: >>> >>> def f(arg = None): >>> if arg is None: >>> arg = BuildArg() >>> >>> What's the idiom to get a default argument evaluated at definition >>> time if it were as you suggested? >> >> Well there are two possibilities I can think of: >> >> 1) >> arg_default = ... >> def f(arg = arg_default): >> ... > > Yuch. Mostly because it doesn't work: > > arg_default = ... > def f(arg = arg_default): > ... > > arg_default = ... > def g(arg = arg_default): > > That one looks like an accident waiting to happen. It's not because accidents can happen, that it doesn't work. IMO that accidents can happen here is because python doesn't allow a name to be marked as a constant or unreboundable. > This may not have been the reason it was done in the first place, but > this loss of functionality would seem to justify the current behavior. > > And, just for fun: > > def setdefaults(**defaults): > def maker(func): > def called(*args, **kwds): > defaults.update(kwds) > func(*args, **defaults) > return called > return maker So it seems that with a decorator there would be no loss of functionality. -- Antoon Pardon From anand.pasoria at in.bosch.com Mon Dec 19 04:31:55 2005 From: anand.pasoria at in.bosch.com (Anand) Date: Mon, 19 Dec 2005 15:01:55 +0530 Subject: Columns and Rows in Excel References: <43A66BAB.30703@REMOVEMEcyber.com.au> Message-ID: Greetings, The worksheet is currently opened in Excel. And I want to read the data from the excel worksheet. Instead of looping through the entire worksheet, I want to limit the looping to the rows and columns used so far! Thanks and regards, Anand "Steven D'Aprano" wrote in message news:43A66BAB.30703 at REMOVEMEcyber.com.au... > Anand wrote: > > > Greetings, > > > > How can I find the number of active columns and rows used in an excel work > > sheet? > > What I mean is how can i find the last column and row or cell position, > > where the data is stored in an excel sheet? > > Is the worksheet currently open in Excel or OpenOffice, > and you wish to query the application for that information? > > Or do you want to read the spreadsheet in from a file? > > > > -- > Steven. > From garabik-news-2005-05 at kassiopeia.juls.savba.sk Fri Dec 30 17:54:05 2005 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Fri, 30 Dec 2005 22:54:05 +0000 (UTC) Subject: python encoding bug? Message-ID: I was playing with python encodings and noticed this: garabik at lancre:~$ python2.4 Python 2.4 (#2, Dec 3 2004, 17:59:05) [GCC 3.3.5 (Debian 1:3.3.5-2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> unicode('\x9d', 'iso8859_1') u'\x9d' >>> U+009D is NOT a valid unicode character (it is not even a iso8859_1 valid character) The same happens if I use 'latin-1' instead of 'iso8859_1'. This caught me by surprise, since I was doing some heuristics guessing string encodings, and 'iso8859_1' gave no errors even if the input encoding was different. Is this a known behaviour, or I discovered a terrible unknown bug in python encoding implementation that should be immediately reported and fixed? :-) happy new year, -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From walter at livinglogic.de Fri Dec 23 11:19:49 2005 From: walter at livinglogic.de (=?ISO-8859-1?Q?Walter_D=F6rwald?=) Date: Fri, 23 Dec 2005 17:19:49 +0100 Subject: print UTF-8 file with BOM In-Reply-To: References: <1135303948.111836.40210@o13g2000cwo.googlegroups.com> Message-ID: <43AC23A5.4090404@livinglogic.de> John Bauman wrote: > UTF-8 shouldn't need a BOM, as it is designed for character streams, and > there is only one logical ordering of the bytes. Only UTF-16 and greater > should output a BOM, AFAIK. However there's a pending patch (http://bugs.python.org/1177307) for a new encoding named utf-8-sig, that would output a leading BOM on writing and skip it on reading. Bye, Walter D?rwald From mwm at mired.org Thu Dec 8 09:50:10 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 08 Dec 2005 09:50:10 -0500 Subject: Mutability of function arguments? References: <1134001014.716406.10800@z14g2000cwz.googlegroups.com> <86fyp4xshz.fsf@bhuda.mired.org> <439811ea$1_2@newspeer2.tds.net> Message-ID: <86d5k7y76l.fsf@bhuda.mired.org> Kent Johnson writes: > Mike Meyer wrote: >> "ex_ottoyuhr" writes: >> >>>I'm trying to create a function that can take arguments, say, foo and >>>bar, and modify the original copies of foo and bar as well as its local >>>versions -- the equivalent of C++ funct(&foo, &bar). >> C++'s '&' causes an argument to be passed by reference. Python does >> that with all arguments. Any changes you make to the argument in the >> function will be seen in the caller unless you explicitly make a copy >> to pass. > I would say, from the point of view of a C++ programmer, Python passes > references by value. In other words if you think of variables as > pointers (references) to values, and function call as passing the > reference by value, the behaviour of Python makes sense. While the description is right, the terminology is wrong, and places the emphasis in the wrong place. Your description of "passes references by value" is a description of call by reference. C passes all arguments by value, to pass a reference, the C programmer creates the reference to the value "by hand", then dereferences it by hand at the other end. So C's "call-by-reference" passes the reference by value. There's no difference between C's call-by-reference and Python's call-by-reference, and using different words to try and imply there is will just cause problems further on. The real difference is in the way names behave in the two languages. As you put it, "variables are references to values", except Python names don't have most of the things associated with variables in other programming languages, so it's better to call them names. We use "bound" to show that we're not copying a value over a fixed memory location, hence "names are bound to values." This is the crucial point, and the one that need to be emphasized. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From lists at nabble.com Sat Dec 17 00:05:09 2005 From: lists at nabble.com (Murtog (sent by Nabble.com)) Date: Fri, 16 Dec 2005 21:05:09 -0800 (PST) Subject: why does php have a standard SQL module and Python doesn't !? In-Reply-To: <1134672939.084114.255660@g44g2000cwa.googlegroups.com> References: <1134672939.084114.255660@g44g2000cwa.googlegroups.com> Message-ID: <1984758.post@talk.nabble.com> This confusion is usual, its because python implements a padronized way to access databases, so you can change your database without having to change too much code. The easiest and quickest manner to access a MySQL and using Python is: 1) Geting the module using this site: http://www.python.org/topics/database/modules.html 2) Read this tutorial(very very useful): http://www.kitebird.com/articles/pydbapi.html I hope this helps you. Sorry for my english. Cheers! =] -- Sent from the Python - python-list forum at Nabble.com: http://www.nabble.com/why-does-php-have-a-standard-SQL-module-and-Python-doesn%27t-%21--t750596.html#a1984758 -------------- next part -------------- An HTML attachment was scrubbed... URL: From cjw at sympatico.ca Fri Dec 9 10:12:43 2005 From: cjw at sympatico.ca (Colin J. Williams) Date: Fri, 09 Dec 2005 10:12:43 -0500 Subject: efficient 'tail' implementation In-Reply-To: <1134023470.390252.32870@g43g2000cwa.googlegroups.com> References: <1134023470.390252.32870@g43g2000cwa.googlegroups.com> Message-ID: s99999999s2003 at yahoo.com wrote: > hi > > I have a file which is very large eg over 200Mb , and i am going to use > python to code a "tail" > command to get the last few lines of the file. What is a good algorithm > for this type of task in python for very big files? > Initially, i thought of reading everything into an array from the file > and just get the last few elements (lines) but since it's a very big > file, don't think is efficient. > thanks > If your file is seekable you could consider using file's seek function. This would appear to give you a way of just working with the last, say 1mb. Colin W. From chris at kateandchris.net Thu Dec 29 17:44:31 2005 From: chris at kateandchris.net (Chris Lambacher) Date: Thu, 29 Dec 2005 17:44:31 -0500 Subject: using NamedTemporaryFile on windows In-Reply-To: References: <%yIsf.2220$OU3.2055@news01.roc.ny> Message-ID: <20051229224431.GA27529@kateandchris.net> On Thu, Dec 29, 2005 at 12:40:34AM -0500, Peter Hansen wrote: > > What I don't understand is why you _can't_ reopen the NamedTemporaryFile > under Windows when you can reopen the file created by mkstemp (and the > files created by TemporaryFile are created by mkstemp in the first place). Basically the only reason that you want a NamedTemporaryFile is so that you can write something to a file, tell another process to use that file (that you have just written to) and then have file cleanup taken care of for you automatically. This works on Unix where you can have process open a file for reading while another process has the file open for writing. You can't do this on Windows without jumping through a lot of hoops(sqlite and MS Access come to mind as programs that manage this, though they may start a server process to manage it). mkstemp does create a file for you, but you are responsible for removing the file when you are done. Unfortunately this is what you are left with on Windows. -Chris From doritrieur at hotmail.com Tue Dec 13 07:40:23 2005 From: doritrieur at hotmail.com (doritrieur) Date: 13 Dec 2005 04:40:23 -0800 Subject: How do i read line from an input file, without the /n Message-ID: <1134477623.371071.327000@g44g2000cwa.googlegroups.com> How do i read line from an input file, without the /n ? the readline function returns also the /n character at the end. i need to read a line without the training /n is this possible? thanks, Dorit From kent at kentsjohnson.com Fri Dec 9 20:37:47 2005 From: kent at kentsjohnson.com (Kent Johnson) Date: Fri, 09 Dec 2005 20:37:47 -0500 Subject: Catching error text like that shown in console? In-Reply-To: References: Message-ID: <439a2e66$1_2@newspeer2.tds.net> Peter A. Schott wrote: > I know there's got to be an easy way to do this - I want a way to catch the > error text that would normally be shown in an interactive session and put that > value into a string I can use later. I've tried just using a catch statement > and trying to convert the output to string, but this doesn't always work. I > really don't have programs complex enough to do a lot of specific catching at > this point - I just want to know: > 1. something failed > 2. here's the error output/traceback If you just want to catch exceptions and print a traceback, use the traceback module. This is handy for example if you are processing a number of items and don't want a failure in one to abort the whole loop: import traceback for work in thingsToDo: try: doSomeWork(work) except: traceback.print_exc() If you want more control over the exception info - for example to put it in a string instead of printing it - look at the other functions in the traceback module. Kent From mahs at telcopartners.com Sat Dec 17 19:58:59 2005 From: mahs at telcopartners.com (Michael Spencer) Date: Sat, 17 Dec 2005 16:58:59 -0800 Subject: effbot ExeMaker: custom icon? Message-ID: What is the recommended way to change the icon of the exe ExeMaker* produces? (I tried replacing the exemaker.ico file, and indeed removing it; but that had no effect.) Thanks Michael *http://effbot.org/zone/exemaker.htm From fredrik at pythonware.com Mon Dec 5 15:59:54 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 5 Dec 2005 21:59:54 +0100 Subject: how to check compile options References: <4394A9E6.30305@plovarna.cz> Message-ID: "Michal" wrote: > how i could check, if my python was compiled with option > WANT_HUGE_STACK_SIZE=yes (or option CFLAG: -DTHREAD_STACK_SIZE=0x100000) > > i have already installed python 2.3.5 on my freebsd 5.4 from ports, but > i dont remember, if i used this options. to check Python configuration variables, you can do >>> from distutils.sysconfig import * >>> d = parse_config_h(open(get_config_h_filename())) >>> for k in d: ... print k, d[k] ... HAVE_SELECT 1 HAVE_ST_BLOCKS 1 HAVE_GETPEERNAME 1 HAVE_GETC_UNLOCKED 1 ... but I'm not sure THREAD_STACK_SIZE really is a Python configuration variable (I cannot seem to find any traces of that in the Python sources...) From mrmakent at cox.net Thu Dec 22 16:20:50 2005 From: mrmakent at cox.net (mrmakent at cox.net) Date: 22 Dec 2005 13:20:50 -0800 Subject: File object question References: Message-ID: <1135286450.406575.261000@f14g2000cwb.googlegroups.com> See http://www.python.org/doc/2.4.2/lib/os-file-dir.html for the 'stat' function import os os.stat(path).st_size This will return the size in bytes of the file designated by 'path'. From max at alcyone.com Thu Dec 8 23:23:03 2005 From: max at alcyone.com (Erik Max Francis) Date: Thu, 08 Dec 2005 20:23:03 -0800 Subject: ANN: pygene - genetic algorithms package In-Reply-To: <1133858140.232822.104220@o13g2000cwo.googlegroups.com> References: <1133858140.232822.104220@o13g2000cwo.googlegroups.com> Message-ID: malv wrote: > How is your package different from a nn package? Is this an addon for > genetic programming or does it include the standard nn components as > well, such as backprop etc? > Not being very familiar with genetic programming, forgive me my naive > question, I could not immediately find the answer. No one answered your question, so I will: Neural networks and genetic algorithms/programming are not closely related. A neural network is a model comprising a network of artificial neurons, and signals propagate from inputs, through the neurons of the network (which typically consists of several layers), and finally to the outputs. Algorithms exist to allow neural networks to be trained, so that given a set of inputs and desired outputs, one can iteratively come up with a neural network (of sufficient complexity) that satisfies that criterion. Neural networks can be used for things like pattern recognition and the like. Genetic algorithms/programming is an approach whereby you can start with a population of random programs, apply artificial selection by keeping those that do better at a task than others and genetic modification like mutation and crossover (simulation sexual reproduction) to create diversity, ultimately resulting (hopefully) in programs that are adept at the task. They could be used in conjunction with one another (for instance, a genetic algorithm where the program is represented by an array of neural network weights), but beyond intermixing ideas they really aren't related. -- 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 never could have predicted / That I'd feel this way -- India Arie From bill at oldieshome.org.uk Fri Dec 16 04:52:29 2005 From: bill at oldieshome.org.uk (bill at oldieshome.org.uk) Date: 16 Dec 2005 01:52:29 -0800 Subject: CherryPy wiki not working In-Reply-To: References: <1134665331.717524.144010@g43g2000cwa.googlegroups.com> Message-ID: <1134726749.271172.229370@g49g2000cwa.googlegroups.com> Yes, it looks like some type of virus has affected my computer. CherryPy was fine from home using my IMac. But at work from both Firefox and IE I get this problem and now it has affected another site. The URLs at CherryPy look like this : http://www.cherrypy.org/store/0_1_540744_1_1_index.html Still, not a Python problem. Bill From grante at visi.com Thu Dec 15 09:18:10 2005 From: grante at visi.com (Grant Edwards) Date: Thu, 15 Dec 2005 14:18:10 -0000 Subject: How to get the local mac address? References: <1134575518.767407.112490@g44g2000cwa.googlegroups.com> <1134618652.007425.149540@g14g2000cwa.googlegroups.com> <1134630506.774844.192790@f14g2000cwb.googlegroups.com> <1134630954.491132.260930@g43g2000cwa.googlegroups.com> <1134636649.937619.304060@g49g2000cwa.googlegroups.com> <1134637733.906828.43600@g44g2000cwa.googlegroups.com> Message-ID: <11q2up2gttjs845@corp.supernews.com> On 2005-12-15, bonono at gmail.com wrote: >>>>Why should you want to associate a MAC address with a socket? Each >>>>interface has an IP address, and it's that you should be using. >>> >>> Say for example I want to find out the MAC if a particular >>> interface in python. >> >> When you are asked "why would you want to do something" it >> isn't normally considered sufficient to reply "suppose I want >> to do something". I'm still trying to find out what use case >> (apart from curiosity) drives this need to know. > > That is nothing but curiosity of why there is no such thing. I > didn't start a thread with "what the xyz@!% hell that I cannot > get MAC address through the socket module". > > And I answer things the way I want to, if it does fit your > expected answer, there is nothing I can do. I am not here to > convince you. Taking an attitude like that towards one of the most respected people in the Python community is bound to be rather counter productive. Nobody owes you any answers, so yes, in fact, you _are_ here to convince people that you deserve their help. -- Grant Edwards grante Yow! Didn't I buy a 1951 at Packard from you last March visi.com in Cairo? From rupole at hotmail.com Fri Dec 23 00:05:05 2005 From: rupole at hotmail.com (Roger Upole) Date: Fri, 23 Dec 2005 00:05:05 -0500 Subject: Providing 'default' value with raw_input()? References: <1135270517.004645.87750@g47g2000cwa.googlegroups.com> <1135272716.461392.126630@g49g2000cwa.googlegroups.com> Message-ID: <1135314532_8199@spool6-east.superfeed.net> If you have Pywin32 build 205 installed, you can use the win32console module to add the data to the typeahead buffer before you call raw_input. import win32console stdin=win32console.GetStdHandle(win32console.STD_INPUT_HANDLE) def raw_input_with_default(prompt, default_val): keypresses=[] for c in default_val: evt=win32console.PyINPUT_RECORDType(win32console.KEY_EVENT) evt.Char=unicode(c) evt.RepeatCount=1 evt.KeyDown=True keypresses.append(evt) stdin.WriteConsoleInput(keypresses) return raw_input(prompt) data=raw_input_with_default('modify this: ','some data') print data hth Roger "planetthoughtful" wrote: > Hi Steve, > > As keir mentioned, my goal is to be able to edit the value returned > from a record stored in SQLite, so that it can be updated with the new > value. > > To give a little background: as a learning exercise I'm writing a > command line app that will allow me to quickly capture todo items > (based on a similar concept used by an app for the Mac described on > 43folders.com). I have the functionality working for adding todo items, > and listing items by various criteria, and updating the status of > items, but haven't included any functionality for being able to edit > items. > > It seems, according to kier, that this simply can't be done via the > command line in DOS, which is a shame. > > Sorry I didn't explain myself very well in my original post. > > Much warmth, > > planetthoughtful > ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =---- From skip at pobox.com Wed Dec 7 06:37:35 2005 From: skip at pobox.com (Skip Montanaro) Date: Wed, 7 Dec 2005 05:37:35 -0600 Subject: A more dynamic Python Library Reference index Message-ID: <17302.51583.612022.556720@montanaro.dyndns.org> I broke down and wrote a dynamic global module index for the Python library reference manual last night using Myghty. It's something I've wanted for quite awhile and as I'm just learning to use Myghty I thought it would be a good tool to experiment with (better I think than Moin, which was my original thought). At any rate, it's available on a trial basis at http://staging.musi-cal.com/modindex/ The idea is that it fetches and caches the the global module index from http://www.python.org/dev/doc/devel/modindex.html (note: that's the development version of the libref manual global index) and rewrites most links to feed through a hit counter/redirector. When the above module index page is requested, it displays the 20 most frequently requested modules at the top of the page. Give it a try and let me know what you think. Skip From nathan at moreheadstate.edu Mon Dec 12 23:31:39 2005 From: nathan at moreheadstate.edu (Nathan Gilbert) Date: 13 Dec 2005 04:31:39 GMT Subject: Python Graph API Message-ID: Has there been any work done lately on the Python Graph API? Thanks in advance, NG -- "The life of a repoman is always intense." From carsten at uniqsys.com Mon Dec 12 16:38:31 2005 From: carsten at uniqsys.com (Carsten Haese) Date: Mon, 12 Dec 2005 16:38:31 -0500 Subject: "0 in [True,False]" returns True In-Reply-To: <439deb17$0$18320$8fcfb975@news.wanadoo.fr> References: <439deb17$0$18320$8fcfb975@news.wanadoo.fr> Message-ID: <1134423511.19134.75.camel@dot.uniqsys.com> On Mon, 2005-12-12 at 16:26, Pierre Quentel wrote: > Hi all, > > In some program I was testing if a variable was a boolean, with this > test : if v in [True,False] > > My script didn't work in some cases and I eventually found that for v = > 0 the test returned True > > So I changed my test for the obvious "if type(v) is bool", but I still > find it confusing that "0 in [True,False]" returns True > > By the way, I searched in the documentation what "obj in list" meant and > couldn't find a precise definition (does it test for equality or > identity with one of the values in list ? equality, it seems) ; did I > miss something ? Where/how did you search? http://docs.python.org/lib/typesseq.html states unambiguously that "x in s" returns "True if an item of s is equal to x, else False" HTH, Carsten. From scott.daniels at acm.org Thu Dec 29 12:38:45 2005 From: scott.daniels at acm.org (Scott David Daniels) Date: Thu, 29 Dec 2005 09:38:45 -0800 Subject: Is this a refrence issue? In-Reply-To: <1135808875.038100.301050@o13g2000cwo.googlegroups.com> References: <1135808875.038100.301050@o13g2000cwo.googlegroups.com> Message-ID: <43b41f15@nntp0.pdx.net> KraftDiner wrote: > I have a list and want to make a copy of it and add an element > to the end of the new list, but keep the original intact.... Nobody has mentioned the obvious yet: tmp = myList + [something] --Scott David Daniels scott.daniels at acm.org From martin at v.loewis.de Sat Dec 3 05:38:06 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 03 Dec 2005 11:38:06 +0100 Subject: os.rename copies when old is in-use - is this deliberate? In-Reply-To: References: Message-ID: <4391758e$0$26955$9b622d9e@news.freenet.de> Tony Meyer wrote: > Is this the intended behaviour? Sort-of. os.rename invokes the C library's rename, and does whatever this does. It is expected that most platform's C libraries do what the documentation says rename does, but platforms may vary in their implementation of the C library, and from one compiler version to the other. Microsoft's documentation of rename/_rename/_wrename is here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_rename.2c_._wrename.asp It doesn't say anything about renaming in-use files, either. Looking at the implementation of _rename, I see that it directly calls MoveFile, which is documented here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/movefile.asp That doesn't mention the in-use case, either. Regards, Martin From smithsm at samuelsmith.org Thu Dec 8 15:26:47 2005 From: smithsm at samuelsmith.org (Samuel M. Smith) Date: Thu, 8 Dec 2005 13:26:47 -0700 Subject: Unexpected behavior of read only attributes and super In-Reply-To: References: Message-ID: > > > P.S. Note that there is an additional complication resulting from the > fact that functions are descriptors: > >>>> class C(dict): > ... pass > ... >>>> C.__iter__ > >>>> C().__iter__ > > > Even though the C instance is accessing the __iter__ function on the > class, it gets back a different value because descriptors return > different values depending on whether they are accessed from a > class or > an instance. I don't think you need to understand this to solve your > problem though, so I won't go into any more details unless you > think it > would be helpful. I found your explanation very helpful. After reading it I went back and read my Nutshell book and realized that the explanation was in there but I didn't "get" it until now. Although I did find an exception to the rule for attribute writes. (See !Whoops below) If you would care to elaborate on the how the lookup differs with method descriptor it would be most appreciated. Mostly because it seems that having slots defined changes the method lookup as opposed to the variable lookup and apparently some of the type class variables are special enough that they have their own rules. This might help explain why it is that when I define __slots__, the behavior when writing an attribute is different for attributes that exist in the class versus attributes that exist in __slots__ versus attributes that do not exist at all. It is also different if the class attribute is a method vesus a variable. For example >>> class C(dict): ... __slots__ = ['a','b'] ... >>> c = C() >>> c.a Traceback (most recent call last): File "", line 1, in ? AttributeError: a So slot defined but not assigned gets error >>> c.a = 5 >>> c.a 5 OK here >>> c.c Traceback (most recent call last): File "", line 1, in ? AttributeError: 'C' object has no attribute 'c' Surprise error gives no clue that slots is the reason for the error >>> c.c = 4 Traceback (most recent call last): File "", line 1, in ? AttributeError: 'C' object has no attribute 'c' ditto Now the behavior is different for class variables and methods when slots defined versus when slots is not defined. >>> c.__iter__ = 4 Traceback (most recent call last): File "", line 1, in ? AttributeError: 'C' object attribute '__iter__' is read-only >>> super(C,c).__iter__ = 4 Traceback (most recent call last): File "", line 1, in ? TypeError: 'super' object has only read-only attributes (assign to .__iter__) >>> >>> c.__class__ = C >>> c.__class__ it let me assign it! But not shadowed >>> c.__dict__ Traceback (most recent call last): File "", line 1, in ? AttributeError: 'C' object has no attribute '__dict__' !Whoops now I am confused again. Didn't you say > When "writing" an attribute (i.e. using the assignment statement), > Python does not try to do any namespace searching. Thus if you use > the > instance in an assignment statement, then it is the instance's > attributes that get modified, and if you use the class in an > assignment > statement, then it is the class's attributes that get modififed: Then why wasn't __class__ added to c.__dict__ ? Looks like namespace searching to me. So to cross check if slots is not defined >>> class C(dict): ... pass ... >>> c = C() >>> c.__iter__ = 1 >>> c.__dict__ {'__iter__': 1} >>> c.__class__ = C >>> c.__dict__ {'__iter__': 1} >>> try again a different way class B(C): ... pass ... >>> c.__class__ = B >>> c.__dict__ {'__iter__': 4} OK but maybe __class__ is magic, so I tried again >>> class C(dict): ... a = 0 ... >>> c = C() >>> c.a 0 >>> c.a = 4 >>> c.__dict__ {'a': 4} OK __class__ is special now with slots defined >>> class C(dict): ... __slots__ = ['b'] ... a = 0 ... >>> c = C() >>> c.a 0 >>> c.a = 4 Traceback (most recent call last): File "", line 1, in ? AttributeError: 'C' object attribute 'a' is read-only >>> >>> C.a = 5 >>> c.a 5 >>> So the rule is that when __slots__ is defined class variables become read only. What if the class variable is included in __slots__ >>> class C(dict): ... __slots__ = ['b'] ... b = 1 ... >>> c = C() >>> c.b 1 >>> c.b = 2 Traceback (most recent call last): File "", line 1, in ? AttributeError: 'C' object attribute 'b' is read-only So even though b is in slots I still can't create an instance variable by that name and shadow the class variable. It feels like the implementation of slots is half baked. Finally Since the "way" of python is that if an object does not have an attribute but you can assign it one then it creates one dynamically (in the same 'way' that if a variable does not exist is creates one upon assignment). Because slots break this paradigm then at the very least the error messages should point out that this object is using slots "so beware". For example I would prefer something like the following c.a AttributeError: Slot 'a' not yet assigned c.c AttributeError: No slot named 'c' on instance c.c = 4 AttributeError: No slot named 'c' on instance if change rule to not access class from instance when slots define c.__iter__ = 4 AttributeError: No slot named '__iter__' on instance or with current behavior AttributeError: No slot name '__iter__' class 'C' object attribute '__iter__' is read-only super(C,c).__iter__ = 4 TypeError: 'super' object has only read-only attributes (assign to .__iter__) From fredrik at pythonware.com Wed Dec 28 04:28:34 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 28 Dec 2005 10:28:34 +0100 Subject: getting the status codes from the ftplib module References: <43B2568F.7010802@gmail.com> Message-ID: Alvin A. Delagon wrote: > I'm writing a simple python code that will upload files onto a ftp > server. Everything's fine and working great except that the script I > wrote don't know is an upload is successful or not. Is there a way to > obtain the ftp status codes with this module? Thanks in advance! the module raises an exception if something fails. if you didn't get an exception, everything worked as expected. most methods, including the storlines and storbinary methods, also return the status code. From aleax at mail.comcast.net Sat Dec 3 21:39:00 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Sat, 3 Dec 2005 18:39:00 -0800 Subject: Scientific Notation References: <1133663674.341405.95410@g44g2000cwa.googlegroups.com> Message-ID: <1h70bsh.10qldrqew9dd6N%aleax@mail.comcast.net> Dustan wrote: > How can I get a number into scientific notation? I have a preference > for the format '1 E 50' (as an example), but if it's well known, it > works. You mean something like: >>> print '%e' % (1e50) 1.000000e+50 ...? Alex From luismgz at gmail.com Mon Dec 19 16:51:12 2005 From: luismgz at gmail.com (Luis M. Gonzalez) Date: 19 Dec 2005 13:51:12 -0800 Subject: Which Python web framework is most like Ruby on Rails? In-Reply-To: <1134496403.011407.169930@g44g2000cwa.googlegroups.com> References: <1134496403.011407.169930@g44g2000cwa.googlegroups.com> Message-ID: <1135029071.990723.134030@z14g2000cwz.googlegroups.com> Sorry for the interruption, but... Has anyone tried KARRIGELL?? I find hard to believe there is any easier python framework than this one. It's incredibly flexible, very fun, very powerful and with an almost flat learning curve. Go check it out (NOW!) http://karrigell.sourceforge.net/ From aleax at mail.comcast.net Sun Dec 4 23:32:23 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Sun, 4 Dec 2005 20:32:23 -0800 Subject: timeit's environment References: <1133756241.079255.246230@g43g2000cwa.googlegroups.com> Message-ID: <1h72bnp.1iap42p1ml8q1hN%aleax@mail.comcast.net> wrote: > Why doesn't the following work? It generates a "NameError: global > name 'data' is not defined" error. > > import timeit > > global data > data = [3,8,4,8,6,0,5,7,2,1] > > env = "global data; x = data" > > print timeit.Timer('x.sort()', env).timeit() > print timeit.Timer('x.sort(cmp=cmp', env).timeit() > > How can I get timeit() to see an external (to it) variable? > (In the real program 'data' is very expensive to create and > contains non-reproducable data and the two timeit calls > must be run on identical objects. You have to use 'from __main__ import data as x' rather than just say 'global data; x=data', because timeit is a separate module from your __main__ one. Alex From larry.bates at websafe.com Mon Dec 19 11:44:35 2005 From: larry.bates at websafe.com (Larry Bates) Date: Mon, 19 Dec 2005 10:44:35 -0600 Subject: RasAdminUserGetInfo In-Reply-To: <1135010283.304598.160910@f14g2000cwb.googlegroups.com> References: <1135010283.304598.160910@f14g2000cwb.googlegroups.com> Message-ID: <43A6E373.6040508@websafe.com> future_retro at yahoo.co.uk wrote: > Anyone got any idea how to use this? It looks like it isn't available > directly from the win32 extensions. > > Thanks, MW. > Google is your friend: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/rras/rras/rasadminusergetinfo.asp -Larry Bates From grante at visi.com Tue Dec 13 10:18:54 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 13 Dec 2005 15:18:54 -0000 Subject: "0 in [True,False]" returns True References: <439deb17$0$18320$8fcfb975@news.wanadoo.fr> <1134443878.946064.8580@g44g2000cwa.googlegroups.com> <1134459973.203587.269910@g14g2000cwa.googlegroups.com> Message-ID: <11ptpiuf3lse907@corp.supernews.com> On 2005-12-13, bonono at gmail.com wrote: > > Fredrik Lundh wrote: >> bonono at gmail.com wrote: >> >> > > but seriously, unless you're writing an introspection tool, testing for >> > > bool is pretty silly. just use "if v" or "if not v", and leave the rest to >> > > Python. >> > > >> > The OP's code(and his work around) doesn't look like he is testing for >> > boolean >> >> which of course explains why he wrote >> >> In some program I was testing if a variable was a boolean >> >> in the post I replied to... >> >> > but more like the data type of something. I thought there is some idiom >> > in python which said something like "don't assume" ? >> >> "think before you post" ? >> > Don't know what you mean. > > He seems to be testing "boolean type", not whether it is true > or false. Right. But that's almost always pointless. Knowing whether a variable is a boolean or not is very rarely useful. What one wants to know is whether a varible is true or not. The code for that is: if v: something if not v: something -- Grant Edwards grante Yow! My DIGITAL WATCH at has an automatic SNOOZE visi.com FEATURE!! From t-meyer at ihug.co.nz Sun Dec 4 19:39:55 2005 From: t-meyer at ihug.co.nz (Tony Meyer) Date: Mon, 5 Dec 2005 13:39:55 +1300 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 2) In-Reply-To: <1133740404.946655.246410@g44g2000cwa.googlegroups.com> References: <1133740404.946655.246410@g44g2000cwa.googlegroups.com> Message-ID: <253C6E8D-BF51-4EDC-A6DB-3B843C87AB93@ihug.co.nz> >> Among the treasures available in The Wiki is the current >> copy of "the Sorting min-howto": >> http://www.amk.ca/python/howto/sorting/sorting.html > > Why is this a "treasure" when it is way out of date? Note that the updated version of this is at: http://wiki.python.org/ moin/HowTo/Sorting =Tony.Meyer From skip at pobox.com Fri Dec 30 00:26:47 2005 From: skip at pobox.com (skip at pobox.com) Date: Thu, 29 Dec 2005 23:26:47 -0600 Subject: Question about re.sub and callables In-Reply-To: <1135919234.295744.311490@g47g2000cwa.googlegroups.com> References: <1135919234.295744.311490@g47g2000cwa.googlegroups.com> Message-ID: <17332.50455.89890.29896@montanaro.dyndns.org> Guyon> The solution I came up with to tackle this is with some funny Guyon> globals, which doesnt feel 'right': ... Guyon> Is there any other way to do this? You've almost got it right. Just lose the "global": def test(data, pre, post): p = re.compile("([0-9])") def repl(m): return pre + m.group(1) + post print p.sub(repl, data) For a full explanation, google for "python nested scopes". Skip From haraldarminmassa at gmail.com Wed Dec 21 09:06:43 2005 From: haraldarminmassa at gmail.com (Harald Armin Massa) Date: 21 Dec 2005 06:06:43 -0800 Subject: Guido at Google In-Reply-To: <43a939e3$0$23986$626a14ce@news.free.fr> References: <43a939e3$0$23986$626a14ce@news.free.fr> Message-ID: <1135174003.737464.211650@g43g2000cwa.googlegroups.com> > It seems that our master Guido van Rossum had an offer from google and > he accepted it!! Isn't Guido-Sans official title BDFL? *wink* whatever, if it's true, congratulations and best wishes. Now there is one *bot and the BDFL at google, we have still 3 bots in the wild, do we? Suggesting to name a Rigobot .... Harald From fredrik at pythonware.com Tue Dec 20 04:45:30 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 20 Dec 2005 10:45:30 +0100 Subject: How to call function which is in one program ... References: <1135065364.079621.155280@g44g2000cwa.googlegroups.com> Message-ID: "Shahriar Shamil Uulu" wrote: > i got another questions. For example i have two programs in python > like: first.py, second.py. > In first.py i have a function test() like: > # first.py > ... > def test(name): > print name > > .... so other functions > ========================= > > #second.py > > Question is how i can include first.py into second.py and use function > test.py. # File: second.py import first first.test() tips: read a Python tutorial *before* you post your next question. start here: http://www.python.org/doc/Intros.html From drevil_53711 at yahoo.com Fri Dec 9 13:51:34 2005 From: drevil_53711 at yahoo.com (Steve Young) Date: Fri, 9 Dec 2005 10:51:34 -0800 (PST) Subject: build_opener() Message-ID: <20051209185134.32105.qmail@web40424.mail.yahoo.com> Hello, I had a question about urllib2's build_opener() statement. I am trying to just get the html from any webpage as a string but I need everything on the page to be the same as what it'd be if I would browse to that page (and at the very least, all the href's). This is my code: url = 'http://news.yahoo.com/fc/world/iraq' req = Request(url) f = build_opener().open(req) page = f.read() f.close() return page so looking at the source of the page browsing to the page, one of the links has an href that looks like this: href = http://news.yahoo.com/s/ap/20051118/ap_on_re_mi_ea/iraq_051118153857;_ylt=AiPsFWWIyLLbGdlCQFLMn8NX6GMA;_ylu=X3oDMTBiMW04NW9mBHNlYwMlJVRPUCUl after running the code and looking at the returned page's same link, it looks like this: href = http://192.168.23.106/s/ap/20051118/ap_on_re_mi_ea/iraq_051118153857 it seems that everything after the semi-colon is missing after running the build_opener(). Is there a way that I can get the page as a string with all the links (href's) to not be missing anything? Thanks. -Steve --------------------------------- Yahoo! Shopping Find Great Deals on Holiday Gifts at Yahoo! Shopping --------------------------------- Yahoo! Shopping Find Great Deals on Holiday Gifts at Yahoo! Shopping -------------- next part -------------- An HTML attachment was scrubbed... URL: From uche.ogbuji at gmail.com Mon Dec 5 21:19:01 2005 From: uche.ogbuji at gmail.com (uche.ogbuji at gmail.com) Date: 5 Dec 2005 18:19:01 -0800 Subject: XML and namespaces In-Reply-To: References: Message-ID: <1133835541.503521.192000@f14g2000cwb.googlegroups.com> Wilfredo S?nchez Vega: """ I'm having some issues around namespace handling with XML: >>> document = xml.dom.minidom.Document() >>> element = document.createElementNS("DAV:", "href") >>> document.appendChild(element) >>> document.toxml() '\n' Note that the namespace wasn't emitted. If I have PyXML, xml.dom.ext.Print does emit the namespace: >>> xml.dom.ext.Print(document) Is that a limitation in toxml(), or is there an option to make it include namespaces? """ Getting back to the OP: PyXML's xml.dom.ext.Print does get things right, and based on discussion in this thread, the only way you can serialize correctly is to use that add-on with minidom, or to use a third party, properly Namespaces-aware tool such as 4Suite (there are others as well). Good luck. -- Uche Ogbuji Fourthought, Inc. http://uche.ogbuji.net http://fourthought.com http://copia.ogbuji.net http://4Suite.org Articles: http://uche.ogbuji.net/tech/publications/ From mwm at mired.org Fri Dec 9 17:20:36 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 09 Dec 2005 17:20:36 -0500 Subject: pyparsing and LaTeX? References: Message-ID: <86mzj9x68b.fsf@bhuda.mired.org> "Tim Arnold" writes: > For now I'm working on a tag translator to convert from one LaTeX tagset to > another, which is a pretty simple task compared to writing a full parser > like pyLaTeX > http://pylatex.sourceforge.net/ You might check out the LyX project. They use python for their scripting, and have tools to convert LaTeX to LyX's TeX-like format. Then again, they may not have anything you can use. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From claudio.grondi at freenet.de Mon Dec 19 19:55:34 2005 From: claudio.grondi at freenet.de (Claudio Grondi) Date: Tue, 20 Dec 2005 01:55:34 +0100 Subject: ANNOUNCE; Try python beta In-Reply-To: <86oe3c39ho.fsf@bhuda.mired.org> References: <86oe3c39ho.fsf@bhuda.mired.org> Message-ID: Mike Meyer wrote: > Ok, I've given it the interface I want, and made it less of an > attractive nuisance. > > http://www.mired.org/home/mwm/try_python/ is now ready for people to > play with. There's no tutorial information on it yet, that's the next > thing to do. However, I won't be able to work on it for a while, so if > you want to make suggestions about what that should look like, all > such suggestions will be given proper consideration. > > >> 1+1 SyntaxError: unexpected EOF while parsing (line 1) It does work for me in FireFox and Netscape: >>> 1+1 2 but in Opera I get: >>> 1+1 ?????????????????????????>>> I am most curious about the last one with no idea how it comes? Maybe the subject of your posting should be changed to: Try my skills in processing form requests from different Internet browser? Claudio From harald_karner at a1.net Thu Dec 1 11:52:40 2005 From: harald_karner at a1.net (Harald Karner) Date: Thu, 01 Dec 2005 17:52:40 +0100 Subject: Is there no compression support for large sized strings in Python? In-Reply-To: <3v8lf6F14kmc3U1@individual.net> References: <3v89rnF14jf6mU1@individual.net> <3v8lf6F14kmc3U1@individual.net> Message-ID: Claudio Grondi wrote: > Anyone on a big Linux machine able to do e.g. : > \>python -c "print len('m' * 2500*1024*1024)" > or even more without a memory error? I tried on a Sun with 16GB Ram (Python 2.3.2) seems like 2GB is the limit for string size: > python -c "print len('m' * 2048*1024*1024)" Traceback (most recent call last): File "", line 1, in ? OverflowError: repeated string is too long > python -c "print len('m' * ((2048*1024*1024)-1))" 2147483647 From poeta_sam at yahoo.com Mon Dec 19 14:08:53 2005 From: poeta_sam at yahoo.com (Marian) Date: Mon, 19 Dec 2005 11:08:53 -0800 (PST) Subject: this where I am so far ! Message-ID: <20051219190853.67436.qmail@web53512.mail.yahoo.com> Any one who have a clue how can I add and remove records from a list. if the record is dictionary type) This the program I am working on. I have no idea how can I remove and add some more courses ! import cPickle, shelve def write_file(): CIT101 = ["Academic Computer Skills"] CIT111 = ["Database Management"] CIT115 = ["Intro to Computer scince"] CIT127 = ["ACCESS"] CIT211 = ["Systems Analysis and Design"] CIT216 = ["Visual Basic"] CIT218 = ["Intermediate Visual Basic"] CIT234 = ["Decision Support Using Excel"] pickle_file = open("pickles1.dat","w") cPickle.dump(CIT101, pickle_file) cPickle.dump(CIT111, pickle_file) cPickle.dump(CIT115, pickle_file) cPickle.dump(CIT127, pickle_file) cPickle.dump(CIT211, pickle_file) cPickle.dump(CIT216, pickle_file) cPickle.dump(CIT218, pickle_file) cPickle.dump(CIT234, pickle_file) print "A file has been created and the required specifications have been added" pickle_file.close def read_file(): pickle_file = open("pickles1.dat","r") CIT101 = cPickle.load(pickle_file) CIT111 = cPickle.load(pickle_file) CIT115 = cPickle.load(pickle_file) CIT127 = cPickle.load(pickle_file) CIT211 = cPickle.load(pickle_file) CIT216 = cPickle.load(pickle_file) CIT218 = cPickle.load(pickle_file) CIT234 = cPickle.load(pickle_file) pickle_file.close() pickles = shelve.open("pickles2.dat") pickles["CIT101"] = ["Academic Computer Skills"] pickles["CIT111"] = ["Database Management"] pickles["CIT115"] = ["Intro to Computer scince"] pickles["CIT127"] = ["ACCESS"] pickles["CIT211"] = ["Systems Analysis and Design"] pickles["CIT216"] = ["Visual Basic"] pickles["CIT218"] = ["Intermediate Visual Basic"] pickles["CIT234"] = ["Decision Support Using Excel"] pickles.sync() for key in pickles.keys(): print key, "-", pickles[key] def dele_file(): word_dele = raw_input("Which record do u want to delete?: ") if word_dele in picles.keys(): del word_dele else: print "There is no such record in file pickles2.dat" pickles.close() def display_instructions(): """Display the Main menue""" print \ """ Main Manue: 1. Exit 2. Create a new file and add specifications 3. (not working)Add more courses to the file 4. Read the file 5. (not working)Delete file """ # exit the program >>> 1 <<< def over_program(): """Exit the program""" print "Good Bye!" def main(): choice = None display_instructions() while choice != 1: choice = raw_input("\nChoice: ") if choice == "1": over_program() break elif choice == "2": write_file() elif choice == "3": add_to_file() elif choice == "4": read_file() elif choice == "5": delete_file() else: print "\nSorry, but", choice, "isn't a valid choice." main() raw_input("Press Enter Key to Exit.") __________________________________________________ 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 bokr at oz.net Thu Dec 15 15:55:03 2005 From: bokr at oz.net (Bengt Richter) Date: Thu, 15 Dec 2005 20:55:03 GMT Subject: access to preallocated block of memory? References: <1134599434.424994.224240@g47g2000cwa.googlegroups.com> Message-ID: <43a1d18e.1109976431@news.oz.net> On 14 Dec 2005 14:30:34 -0800, "Greg Copeland" wrote: >I am running python on VxWorks. In the course of operation, a vxworks >tasks writes to a reserved area of memory. I need access to this chunk >of memory from within python. Initially I thought I could simply >access it as a string but a string would reallocate and copy this chunk >of memory; which is not something I can have as it would waste a huge >amount of memory. We're talking about something like 40MB on a device >with limited RAM. I have been looking at array. It looks promising. >What's the best route to go here? Ideally, I would like to simply pass >in the address of the reserved block and a length, and have the memory >accessible. > >Is there some existing python object/facility I can use or will I need >to create a custom module? Any tips, hints, or pointers would >certainly be appreciated! What have you gathered from people who have gone before? googling python vxworks gives about 50k hits ;-) Your post does not have enough info about your environment, but for the sake of eliciting same, suppose you had a custom extension module written in C that would give you the access to the "reserved area of memory" that you want. So e.g. from the point of view of your python program, it looks like a module you can import, e.g., import vxreservedmem Ok, how does the module know where the "reserved area" is? Would you link the C to some vx library interface to establish location and size? Or? Is there already a python interface to provide some access? Can there be more than one instance, so the module should be able to give you multiple objects that you can use to access different areas? Once you have an access-providing object, what kind of access do you require? What is represented within the "memory area" besides an array of bytes? Do the bytes represent C structs and primitive types? Are there access locks that determine when it's safe to touch the bytes? A single lock for the whole area, or individual locks for structs/subregions within the whole? Do you just need read access or do you want to store info? How would you like to select chunks of info? Just slices of byte arrays, or are there meaningful arrays of numbers -- integer, floats, etc. or bit fields etc? You could define a pure python vxresrvedmem module that just simulates the real thing, to test ideas -- and to communicate more clearly to us what the problem is. What modules/libraries do you have to give you access now from python to the vxworks environment? A file system? /dev/magic_stuff? or /proc/magic_stuff or ? Regards, Bengt Richter From peter at engcorp.com Thu Dec 29 13:25:05 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 29 Dec 2005 13:25:05 -0500 Subject: BUG trace realtime In-Reply-To: <1135878446.231861.33490@z14g2000cwz.googlegroups.com> References: <1135843733.589747.43950@g44g2000cwa.googlegroups.com> <1135878446.231861.33490@z14g2000cwz.googlegroups.com> Message-ID: malv wrote: > After one of those 'hangs', with some luck, > I was able to spot the cause of the trouble: a piece of old code that > wasn't supposed to be out there! Really dumb. > FYI, to my surprise, Python really quit. No more CPU time, no message, > nothing. I can't recall having seen this before. If you post the relevant "old code" it's very likely someone could point out exactly why it failed, and how it wasn't *Python* that "quit", but merely something in your code that was blocking. (In other words, Python probably did exactly what you told it to do.) In general, Python does not "quit". It's very robust. When you get a failure like that, always suspect your own code structure. -Peter From JMailone at gmail.com Sun Dec 18 02:33:02 2005 From: JMailone at gmail.com (Jay) Date: 17 Dec 2005 23:33:02 -0800 Subject: urllib.urlopen In-Reply-To: <1134888001.146802.241270@o13g2000cwo.googlegroups.com> References: <1134855533.888083.218540@o13g2000cwo.googlegroups.com> <7069q1t5nj5ci1g34ep4qrr1e4mptfnjkl@4ax.com> <1134888001.146802.241270@o13g2000cwo.googlegroups.com> Message-ID: <1134891182.775395.157560@g47g2000cwa.googlegroups.com> Easy Fix... import urllib the_url = "http://www.google.com" req = urllib.urlopen(the_url) Does this work for you?? From bretthoerner at gmail.com Sun Dec 4 20:00:04 2005 From: bretthoerner at gmail.com (Brett Hoerner) Date: 4 Dec 2005 17:00:04 -0800 Subject: Favorite flavor of Linux? (for python or anything else) In-Reply-To: References: <17d4ae400512040601j7ba8bf6cx89eae7f20b8820a6@mail.gmail.com> Message-ID: <1133744404.754416.247720@z14g2000cwz.googlegroups.com> I have to add another vote for Gentoo. I agree that you just "have less problems" on Gentoo. Updates are from source, but you don't have to update mid-day while working on a project... if you really want the new version of KDE (etc) then start an update and go to sleep, not a big deal. Portage (package management) is amazing, also... for both new and advanced users. Also, I don't use it for the CFLAGS, etc. If Gentoo were the same speed, or even mildly slower than Ubuntu, I would still use it. The general speed boost is just a bonus. I use very simple (-O2 -pipe) CFLAGS, by the way, but -march-pentium-m on my laptop makes a big difference over -mcpu-i386 distros. From gene.tani at gmail.com Fri Dec 9 17:04:02 2005 From: gene.tani at gmail.com (gene tani) Date: 9 Dec 2005 14:04:02 -0800 Subject: Catching error text like that shown in console? In-Reply-To: References: Message-ID: <1134165842.099902.140040@f14g2000cwb.googlegroups.com> Peter A. Schott wrote: > I know there's got to be an easy way to do this - I want a way to catch the > error text that would normally be shown in an interactive session and put that > value into a string I can use later. I've tried just using a catch statement > and trying to convert the output to string, but this doesn't always work. I > really don't have programs complex enough to do a lot of specific catching at > this point - I just want to know: > 1. something failed > 2. here's the error output/traceback > > Anyone know how I can do this or if it's possible? Didn't find anything doing a > search so I figured I'd hit up the experts. > > Thanks. > > -Pete Schott I don't have an exact answer for you, but since no one else replied: look at subprocess module, and os.popen4() http://docs.python.org/lib/os-newstreams.html#os-newstreams http://docs.python.org/lib/module-subprocess.html http://mail.python.org/pipermail/python-list/2005-October/305671.html Hint: mentioning your O/S is pretty essential; for many issues, what version of py and how you installed it also From steve at holdenweb.com Wed Dec 14 04:21:29 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 14 Dec 2005 09:21:29 +0000 Subject: newbie-one more example of difficulty in van Rossum's tutorial In-Reply-To: <1134544953.241727.196850@g49g2000cwa.googlegroups.com> References: <1134510271.914315.126150@z14g2000cwz.googlegroups.com> <1134544953.241727.196850@g49g2000cwa.googlegroups.com> Message-ID: bobueland at yahoo.com wrote: > Thanks Brian, now I get it. BTW there is no fuzzuness in your > explanaition it is crystal clear. > You might also want to note that name-mangling and the reason for it are pretty advanced topics for an introductory tutorial. Having got thus far, further learning might better be gained by using Python on actual projects. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From jzgoda at o2.usun.pl Sun Dec 18 06:10:53 2005 From: jzgoda at o2.usun.pl (Jarek Zgoda) Date: Sun, 18 Dec 2005 12:10:53 +0100 Subject: Cp1251-symbols in SOAP request In-Reply-To: <1134855556.798708.130640@g49g2000cwa.googlegroups.com> References: <1134849561.822052.99460@g49g2000cwa.googlegroups.com> <_KSdnaq2V4mL7TnenZ2dnUVZ_sqdnZ2d@speakeasy.net> <1134850652.210396.160750@f14g2000cwb.googlegroups.com> <1134851327.203167.232230@g14g2000cwa.googlegroups.com> <1134855556.798708.130640@g49g2000cwa.googlegroups.com> Message-ID: Pelmen napisa?(a): > but socket will raise an exception if it'll be in cp1251 I am not a socket programming expert, but I didn't notice anything strange when sending utf-8 or latin2 texts over sockets. -- Jarek Zgoda http://jpa.berlios.de/ From pelmenmail at mail.ru Sat Dec 17 16:39:16 2005 From: pelmenmail at mail.ru (Pelmen) Date: 17 Dec 2005 13:39:16 -0800 Subject: Cp1251-symbols in SOAP request In-Reply-To: References: <1134849561.822052.99460@g49g2000cwa.googlegroups.com> <_KSdnaq2V4mL7TnenZ2dnUVZ_sqdnZ2d@speakeasy.net> <1134850652.210396.160750@f14g2000cwb.googlegroups.com> <1134851327.203167.232230@g14g2000cwa.googlegroups.com> Message-ID: <1134855556.798708.130640@g49g2000cwa.googlegroups.com> but socket will raise an exception if it'll be in cp1251 From dayakiran at gmail.com Fri Dec 16 00:15:37 2005 From: dayakiran at gmail.com (Daya Kiran Sunkara) Date: Fri, 16 Dec 2005 10:45:37 +0530 Subject: Problem with os.path Message-ID: <713503cd0512152115r647c59efy4041be3a6a3cb6ea@mail.gmail.com> Hi All, I have a program which fetches the list of files inside a directory. For fetching this list I am making use of the glob.glob method which takes path as a parameter. For building the path I am making use of os.path.join. My code looks somewhat like this: ----------------------------------------------------------------------- import glob import os path = 'E:\mktrisk\service\marketdata\da' for filename in glob.glob(os.path.join(path,'*.java')): datafile = open(filename,'r').readlines() ---------------------------------------------------------------------- this program works fine when the string 'path' is not too long. When I pass a longer string as path, the program doesn't work. Now I am not sure whether its a limitation with the string class or with os.path. I am passing a valid path to the program and I am running this on Python 2.4.2 on Windows XP. Any help will be greatly appreciated. regards, Daya From rbt at athop1.ath.vt.edu Tue Dec 27 17:31:21 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Tue, 27 Dec 2005 17:31:21 -0500 Subject: html resize pics Message-ID: What's a good way to resize pictures so that they work well on html pages? I have large jpg files. I want the original images to remain as they are, just resize the displayed image in the browser. From alanmk at hotmail.com Mon Dec 5 19:02:50 2005 From: alanmk at hotmail.com (Alan Kennedy) Date: Tue, 06 Dec 2005 00:02:50 +0000 Subject: XML and namespaces In-Reply-To: References: <1133820095.330922.192960@g47g2000cwa.googlegroups.com> Message-ID: [Alan Kennedy] >>On the contrary, once you start second guessing the standards and making >>guesses about what users are really trying to do, and making decisions >>for them, then some people are going to get different behaviour from >>what they rightfully expect according to the standard. People whose >>expectations match with the guesses made on their behalf will find that >>their software is not portable between DOM implementations. [Fredrik Lundh] > and this hypothetical situation is different from the current situation in > exactly what way? Hmm, not sure I understand what you're getting at. If changes are made to minidom that implement non-standard behaviour, there are two groups of people I'm thinking of 1. The people who expect the standard behaviour, not the modified behaviour. From these people's POV, the software can then be considered broken, since it produces different results from what is expected according to the standard. 2. The people who are ignorant of the decisions made on their behalf, and assume that they have written correct code. But their code won't work on other DOM implementations (because the automagic namespace fixup code isn't present, for example). From these people's POV, the software can then be considered broken. [Alan Kennedy] >>With something as finicky as XML namespaces, you can't just make ad-hoc >>decisions as to what the user "really wants". That's why DOM L2 punted >>on the whole problem, and left it to DOM L3. [Fredrik Lundh] > so L2 is the "we support namespaces, but we don't really support them" > level ? Well, I read it as "we support namespaces, but only if you know what you're doing". [Fredrik Lundh] > maybe we could take everyone involved with the DOM design out to the > backyard and beat them with empty PET bottles until they promise never > to touch a computer again ? :-D -- alan kennedy ------------------------------------------------------ email alan: http://xhaus.com/contact/alan From malvert at telenet.be Mon Dec 5 11:03:23 2005 From: malvert at telenet.be (malv) Date: 5 Dec 2005 08:03:23 -0800 Subject: Eclipse best/good or bad IDE for Python? References: <1133484357.699232.164930@z14g2000cwz.googlegroups.com> <43906032.2080408@esss.com.br> <87ek4spd6s.fsf@pobox.com> Message-ID: <1133798603.720765.147540@g43g2000cwa.googlegroups.com> It would not be misplaced in a python forum to draw your attention to Bruce A. Tate's book: "Beyond Java", publ O'Reilly Sep. 2005, ISBN 0-596-10094-9. Bruce explains why: "... Java is abandoning its base, and conditions are ripe for an alternative to emerge". Personally, I have never felt any need in Python to have to fall back on Java tools in order to program in a more efficient manner. The less clutter, the better! malv From paul at boddie.org.uk Wed Dec 21 18:53:33 2005 From: paul at boddie.org.uk (Paul Boddie) Date: 21 Dec 2005 15:53:33 -0800 Subject: libxml2 and mindom References: <1135172760.655562.324080@g49g2000cwa.googlegroups.com> <1135175641.386142.175690@g49g2000cwa.googlegroups.com> <1135180625.179666.268180@o13g2000cwo.googlegroups.com> Message-ID: <1135209213.116756.63320@g43g2000cwa.googlegroups.com> ankit wrote: > I checked for it and here are my comments on it: > libxml2dom has Alpha release . So there may be some bugs in it. In our > project we cant take risk to move back after deciding for one. Thanks > for your reply. Understood. I accept that there's some way to go before libxml2dom can be considered mature. > I checked some other options like libgdome2. Can you make some comments > on that? Sorry, but I've only investigated the libxml2 DOM libraries for other languages in passing - I haven't actually used any of them. > The reason for using minidom is its simplicity for traversing document > tree. Right. > And also I want schema support in the package along with minidom > support. > Can you provide any other option(package) which would suffice this > requirement. Whilst lxml also wraps libxml2, that package doesn't expose a DOM API as far as I know, although one was once proposed/discussed/partially developed. Here's a link to that project: http://codespeak.net/lxml/ > As far as I know no other package instead of libxml2 provides schema > support. > Am I right. I think you'd be best served asking on the XML-SIG mailing list and searching its archives. See here: http://mail.python.org/pipermail/xml-sig/ Paul From jeremit0 at gmail.com Thu Dec 29 13:02:29 2005 From: jeremit0 at gmail.com (jeremito) Date: 29 Dec 2005 10:02:29 -0800 Subject: Extending Python with C++ In-Reply-To: References: <1135877970.877373.140900@g47g2000cwa.googlegroups.com> Message-ID: <1135879348.995783.243900@g43g2000cwa.googlegroups.com> Oops, sorry. My question is, how can I know if my Python interpreter was lined by C++? The non-specific questions are, of course, does anyone have any hints or suggestions? Good websites to visit? Thanks, Jeremy From twic at urchin.earth.li Mon Dec 12 20:43:52 2005 From: twic at urchin.earth.li (Tom Anderson) Date: Tue, 13 Dec 2005 01:43:52 +0000 Subject: OO in Python? ^^ In-Reply-To: References: <1134308880.689307.22090@z14g2000cwz.googlegroups.com> <1h7f90l.l5s3sh1cqq9ozN%aleax@mail.comcast.net> Message-ID: On Mon, 12 Dec 2005, Donn Cave wrote: > In article <1h7f90l.l5s3sh1cqq9ozN%aleax at mail.comcast.net>, > aleax at mail.comcast.net (Alex Martelli) wrote: > >> Tom Anderson wrote: >> ... >> >> >>> For example, if i wrote code like this (using python syntax): >>> >>> def f(x): >>> return 1 + x >>> >>> The compiler would think "well, he takes some value x, and he adds it to 1 >>> and 1 is an integer, and the only thing you can add to an integer is >>> another integer, so x must be an integer; he returns whatever 1 + x works >>> out to, and 1 and x are both integers, and adding two integers makes an >>> integer, so the return type must be integer" >> >> hmmm, not exactly -- Haskell's not QUITE as strongly/rigidly typed as >> this... you may have in mind CAML, which AFAIK in all of its variations >> (O'CAML being the best-known one) *does* constrain + so that "the only >> thing you can add to an integer is another integer". In Haskell, + can >> sum any two instances of types which meet typeclass Num -- including at >> least floats, as well as integers (you can add more types to a typeclass >> by writing the required functions for them, too). Therefore (after >> loading in ghci a file with >> f x = x + 1 >> ), we can verify...: >> >> *Main> :type f >> f :: (Num a) => a -> a > > But if you try > f x = x + 1.0 > > it's > f :: (Fractional a) => a -> a > > I asserted something like this some time ago here, and was set straight, > I believe by a gentleman from Chalmers. You're right that addition is > polymorphic, but that doesn't mean that it can be performed on any two > instances of Num. That's what i understand. What it comes down to, i think, is that the Standard Prelude defines an overloaded + operator: def __add__(x: int, y: int) -> int: def __add__(x: float, y: float) -> float: def __add__(x: str, y: str) -> str: # etc So that when the compiler hits the expression "x + 1", it has a finite set of possible interpretations for '+', of which only one is legal - addition of two integers to yield an integer. Or rather, given that "1" can be an int or a float, it decides that x could be either, and so calls it "alpha, where alpha is a number". Or something. While we're on the subject of Haskell - if you think python's syntactically significant whitespace is icky, have a look at Haskell's 'layout' - i almost wet myself in terror when i saw that! tom -- limited to concepts that are meta, generic, abstract and philosophical -- IEEE SUO WG From jzgoda at o2.usun.pl Thu Dec 1 17:32:04 2005 From: jzgoda at o2.usun.pl (Jarek Zgoda) Date: Thu, 01 Dec 2005 23:32:04 +0100 Subject: UnicodeDecodeError In-Reply-To: <1133438862.533325.40760@g47g2000cwa.googlegroups.com> References: <1133368054.944179.150920@f14g2000cwb.googlegroups.com> <1133438862.533325.40760@g47g2000cwa.googlegroups.com> Message-ID: ash napisa?(a): > If you dont mind, I have another question for you. I use wxPython for > GUI development. When i use a string containing "&" character as a > label for statictext, the "&" does'nt appear.It is replaced by a short > _. I have tried different encodings but have no success. what should i > do so that "&" appears on screen? Double your ampersand character. -- Jarek Zgoda http://jpa.berlios.de/ From pan.kubusREMOVE_IT at gmail.com Sun Dec 11 14:35:52 2005 From: pan.kubusREMOVE_IT at gmail.com (eXt) Date: Sun, 11 Dec 2005 20:35:52 +0100 Subject: ANN: pygene0.12 - Genetic Programming&Algorithms Library In-Reply-To: References: Message-ID: aum wrote: > Hi all, > > This announcement supersedes an earlier announcement of pygene. > > pygene 0.2 now supports genetic programming, in addition to the classical > Mendelian genetic algorithms of the earlier version. I thank the > respondents to the earlier announcement for inspiring me to implement GP > functionality. > > http://www.freenet.org.nz/python/pygene Cool! I'll surly take a look at that :) -- eXt From fuzzyman at gmail.com Thu Dec 1 06:38:37 2005 From: fuzzyman at gmail.com (Fuzzyman) Date: 1 Dec 2005 03:38:37 -0800 Subject: New Ordered Dictionery to Criticise In-Reply-To: <1133197857.754686.133740@g44g2000cwa.googlegroups.com> References: <1133197857.754686.133740@g44g2000cwa.googlegroups.com> Message-ID: <1133437117.799033.205870@g49g2000cwa.googlegroups.com> Fuzzyman wrote: > Sorry for this hurried message - I've done a new implementation of out > ordered dict. This comes out of the discussion on this newsgroup (see > blog entry for link to archive of discussion). > > See the latest blog entry to get at it : > http://www.voidspace.org.uk/python/weblog/index.shtml > Hello all, I've just done a new "beta 2" version. It has a full version of FancyODict with the custome "callable sequence objects" for keys, values and items. They are almost completely covered by tests. You can download the new(er) version from : http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=odictbeta2.py Full discussion of the remaining issues below, or at : http://www.voidspace.org.uk/python/weblog/arch_d7_2005_11_26.shtml#e147 Progress on the updated implementation of dict continues. (I hestitate to say *new* version, as it's just a heavy makeover for the old code - which was basically sound). ``FancyODict`` is now a full implementation of an Ordered Dictionary, with custom *callable sequence objects* for ``keys``, ``values``, and ``items``. These can be called like normal methods, but can also be accessed directly as sequence objects. This includes assigning to, indexing, and slicing - as well as all the other relevant sequence methods. {sm;:-)} I've also added an optional index to ``OrderedDict.popitem``. I'm sure there are lots of ways this can be optimised for efficiency - but the new objects have got pretty full test coverage. You can download the new version (for testing) from `odict Beta 2 `_ The following issues still remain : * ``FancyOdict`` is a separate class from ``OrderedDict``. Because this version is *undoubtably* less efficient than OrderedDict, my current thinking is that I should leave them separate (and have both available). Being able to operate on the keys/values/items as sequences is for convenience only. Anyone got a suggestion for a better name than ``FancyODict`` ? * You can no longer access the key order directly. The old ``sequence`` attribute is depracated and will eventually go away. You can currently alter the order (of keys, values *and* items) by passing an iterable into those methods. Someone has suggested that this "smells bad" - and it ought to be done through separate `setkeys``, ``setvalues``, and ``setitems`` methods. I'm *inclined* to agree, but I don't feel strongly about it. Anyone else got any opinions ? * ``repr`` ought to return a value that ``eval`` could use to turn back into an OrderedDict. I have actually done an implementation of this, but it would mean that *all* the doctests need to be changed. I *will* do this at some point. * Slice assignment. The semantics for slice assignment are fiddly. For example, what do you do if in a slice assignment a key collides with an existing key ? My current implementation does what an ordinary dictionary does, the new value overwrites the previous one. This means that the dictionary can reduce in size as the assignment progresses. {sm;:?} I think this is preferable to raising an error and preventing assignment. It does prevent an optimisation whereby I calculate the indexes of all the new items in advance. It also means you can't rely on the index of a key from a slice assignment, unless you know that there will be no key collisions. In general I'm *against* preventing programmers from doing things, so long as the documentation carries an appropriate warning. An example will probably help illustrate this : .. raw:: html {+coloring} d = OrderedDict() d[1] = 1 d[2] = 2 d[3] = 3 d[4] = 4 d.keys() [1, 2, 3] # fetching every other key # using an extended slice # this actually returns an OrderedDict d[::2] {1: 1, 3: 3} # we can assign to every other key # using an ordered dict d[::2] = OrderedDict([(2, 9), (4, 8)]) len(d) == 4 False d {2: 9, 4: 8} """ Because of the key collisions the length of d has changed - it now only has two keys instead of four. """ {-coloring} > Criticism solicited (honestly) :-) > > We (Nicola Larosa and I) haven't yet made any optimisations - but there > are two implementations to play with. > > One allows you to access the keys attribute as if it was a sequence (as > well as a method). > > All the best, > > Fuzzyman > http://www.voidspace.org.uk/python/index.shtml From http Sat Dec 24 16:29:47 2005 From: http (Paul Rubin) Date: 24 Dec 2005 13:29:47 -0800 Subject: Timing out arbitrary functions References: <7xfyoi4q6x.fsf@ruckus.brouhaha.com> Message-ID: <7x7j9u9oac.fsf@ruckus.brouhaha.com> Steven D'Aprano writes: > > Is something stopping you from using sigalarm? > > Pure ignorance of its existence. > Thanks, I'll check it out. Two things to keep in mind: - You can have only ONE alarm pending for the whole process. If different things in the program need timeouts of their own, you have to manage that yourself, maybe with heapq. And the thing you're trying to time out may itself mess with the alarm or its handler. - The alarm raises an exception in the main thread. If you want a timeout in some other thread, you're more or less out of luck. Antoon Pardon has posted a couple times about a ctypes-dependent hack that raises asynchronous exceptions in arbitrary threads, that might be worth looking into if you have to. I haven't done so for now. Besides sigalarm you might be able to concoct something with SIGIO (have another thread sleep til the timeout then send a character back to the main process through a pipe) or some other signal (use os.kill). The same issues would apply as with sigalarm. From dodysw at gmail.com Tue Dec 13 17:26:16 2005 From: dodysw at gmail.com (Dody Suria Wijaya) Date: Wed, 14 Dec 2005 09:26:16 +1100 Subject: Keep-alived RPC in Python Message-ID: <439f4aa2$1@clarion.carno.net.au> I'm looking for a RPC library in Python that can keep its TCP connection alive for the duration of a user's login session. The reason is, each user login to the application server will impose a single dedicated database connection, and a TCP disconnect will indiciate application server to then destroy the database connection properly. Thanks. background: I currently uses builtin XMLRPC library in Python, but since the connection is not being kept-alive, the only way application server know that it should destroy databaase connection is via 1) User doing logoff which trigger calling RPC logoff, and 2) a user activity timeout using monitoring thread. Problem is, client can't guarantee that it will send logoff RPC (ie: killed/reboot), and timeout can not be too short or it will auto-logoff too early. -- dsw From peter at engcorp.com Fri Dec 30 11:03:56 2005 From: peter at engcorp.com (Peter Hansen) Date: Fri, 30 Dec 2005 11:03:56 -0500 Subject: python code optimization In-Reply-To: <582c100f0512300641k10539b73mab2a70965e3d789@mail.gmail.com> References: <582c100f0512300641k10539b73mab2a70965e3d789@mail.gmail.com> Message-ID: Darius Ku?inskas wrote: > I know that sometimes optimization is not good idea. It's neither good nor bad. Whether or not to optimize is merely a decision that should not be made without considering the cost, and without a real need driving it. The need can only be seen by profiling your code and measuring inadequate performance (which implies a standard by which you're judging it). The cost is not only the time it takes to optimize (which is often small) but more importantly the effect on the readability and maintainability of the code. Most people don't bother measuring, and most ignore the readability cost, and that's why most optimization is "premature" and why "sometimes optimization is not a good idea" (if you really want to express it that way). > So I want to know what you think about this one: ... > we optimize code like this: > tables = [] > pfTablesExtend = tables.extend > for i in ... : > pfTablesExtend(...) > > I what to know is this bad idea? Say you opinion about that! It's very easy to judge based on the guidance I gave above. Was the unoptimized code really too slow? And does the result actually improve the speed sufficiently? That is, did you measure before and after and is the reduction in runtime significant? If the answer to any of these questions is "no", then optimizing was a bad idea. And does the value of the optimization outweigh the cost? In this case, as a casual reader of that code (perhaps missing some context?), I would say that reading "pfTablesExtend" surprises me, since I can't tell what "pf" means, and there are no comments pointing out that the performance without that extra stuff was insufficient. If I were maintaining your code, I would probably hesitate a moment out of uncertainty about why anyone would have done that in the first place, and then I'd simply remove the optimization, assuming the programmer had prematurely optimized. You can judge for yourself whether that makes the time involved in optimizing this worth it. ;-) -- Peter From fredrik at pythonware.com Thu Dec 15 16:46:14 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 15 Dec 2005 22:46:14 +0100 Subject: Overlapping Regular Expression Matches With findall() References: <1134654936.491126.140370@g49g2000cwa.googlegroups.com> <1134678366.932633.311310@g49g2000cwa.googlegroups.com> Message-ID: Mystilleef wrote: > Thanks for your response. I was going by the definition in > the manual. "non-overlapping" in that context means that if you e.g. search for "(ba)+" in the string "bababa", you get one match ("bababa"), not three or six. in your case, it sounds like you want a search for "ba" to return only one match. > I know I can filter the list containing found matches myself, but that > is somewhat expensive for a list containing thousands of matches. if the order doesn't matter, you don't have to build a list: >>> text = "cat catched catnip cat catatonic cat cat cat kat" >>> set(m.group() for m in re.finditer("cat\w*", text)) set(['catatonic', 'catnip', 'catched', 'cat']) if you need to preserve the order, you could use a combination of a list and a set (or a dictionary): >>> s = set(); w = [] >>> for m in re.finditer("cat\w*", text): ... m = m.group() ... if m not in s: ... s.add(m); w.append(m) ... >>> w ['cat', 'catched', 'catnip', 'catatonic'] From claudio.grondi at freenet.de Sun Dec 18 14:40:10 2005 From: claudio.grondi at freenet.de (Claudio Grondi) Date: Sun, 18 Dec 2005 20:40:10 +0100 Subject: Wingide is a beautiful application In-Reply-To: <1134929375.728971.141000@o13g2000cwo.googlegroups.com> References: <1134839352.112192.182010@o13g2000cwo.googlegroups.com> <1134929375.728971.141000@o13g2000cwo.googlegroups.com> Message-ID: sjdevnull at yahoo.com wrote: > Claudio Grondi wrote: > >>The only thing what makes a difference to me is, that Wing 'understands' >>Python code what results in features not available elsewhere (e.g. go to >>definition). > > > This is something that pretty much any reasonable programming editor > will get you. Vim and emacs both do it. > > I get the feeling that a ot of people working with heavy IDEs don't > realize how capable vim/emacs are, so I'll give a brief rundown of what > my Vim environment does for me. (I do Python web development)--if you > don't like the Vi keybindings, the Cream package is Vim that behaves > like a regular modeless editor but with all of vim's power (and a nice > embedded Python interpreter for writing extensions): I have tried Vim already multiple times in the past and it had always problems. But what was in the past must not stay this way forever, so I have got the latest download at http://heanet.dl.sourceforge.net/sourceforge/cream/cream-0-33-1-gvim-6-3-90-1.exe and installed it loading my current Python file. With [Strg]-[End] I went to the end of the file where I wanted to continue editing, but the syntax highlighting told me there is no code but only a comment. I checked it and found out, that Vim is apparently not able to do proper highlighting when jumping to the end of the file not going through other parts of the code before. Going back to the point where triple quotes comment begun (quite in the middle of the file) and back to the end did the trick to get proper highlighting again. Apparently Vim syntax highlighting analyses only the code it has already 'seen' within the editing window. This is not what I expect from a mature editor. I have stopped here, because I found this problem after three seconds of using it, so imagine how much other problems will become apparent after using it three hours, right? Vim similar as Wing has no [View] menu entry one can use for changing the text appearance in any reasonable Windows program, so the ancient Unix/Linux is still there with the system font as default setting for displaying text... It looks as I were in a DOS box, not in a text editor on Windows. Loading a 100 MByte large file into this editor which pretends to be able to edit files of any size results in an Error. I was not able to find how to do rectangular select/paste and there was no code folding for Python script code available. Sorry, also this time still valid: Vim on Windows "no thank's". I was just waste of my time to try it out again. Claudio > > 1. Python syntax checking: as I'm typing along, if I input a syntax > error then the line is immediately highlighted in red. Useful for > catching brainos like: > if a=1: > (which will highlight in red when I hit enter, point out that I need == > instead of =). > 2. Normal tag-jump stuff: Ctrl-click on a function/method call (or > class or whatever) will jump to the function/method/class definition > (Ctrl-T works as well if you don't like clicking). It keeps a stack of > visited files so you can drill down through your call stack and then > pop back up to where you came from. > 3. Python class browsing stuff: A Class menu shows the parent and child > classes of the one you're currently in, and all the methods of the > current class; selecting any of the above jumps to the appropriate file > and line. > 4. Interactive documentation stuff: When I type an open-paren, it looks > to see what the prior keyword is and displays help for it in the status > line (preferring Python documentation, then docstrings, then comments > before the function/method/class definition). Even if there's no > help/comments, it'll show the arguments that the function takes. So > if, say, I type: > > cmp( > > then the status line displays: > > cmp(x, y) Compare the two objects X and Y and return an integer > according to ... > > If I hit F1 it'll show the full help text. Often the arguments are > enough, and I find the status-line display a lot less intrusive than > many on-the-fly help systems I've seen. > > 5. A client menu selects which client I want to work in (so, say, I get > a bug report for Client A, I select them from the menu). The Class > menu and other functions respect this (if I'm in the generic Company > class, the Class menu will list Client A's Company subclass before the > subclasses of other companies; if I jump to the Company definition, > it'll go to Company A's client-specific version). It also restarts > development httpd servers on the current machine running with conf > files appropriate to that client. > 6. Full version control integration, including side-by-side diff > viewing/editing, etc > 7. Editor control on uncaught errors; if I hit a web page on my > development httpd and it throws an uncaught exception, my editor will > jump to the line the exception occured at (preferring a location in the > stack that's in a file I'm currently editing).and I'll have the stack > trace in a scratch buffer if I want it, or as I jump up/down the stack > it'll show relevant parts of the trace in the status line. > > There's a lot I'm forgetting, but the basic point is that even "simple" > text editors like vim can easily do a lot of Python-specific niceties > for you (emacs is similarly capable). > From anubispr at gmail.com Fri Dec 9 14:14:56 2005 From: anubispr at gmail.com (Efrain Marrero) Date: Fri, 9 Dec 2005 15:14:56 -0400 Subject: new in programing Message-ID: <2005120915145616807-anubispr@gmailcom> i want to now how to do this in python this is java for(int i=1 ; i<=lim ; i++){ for(int j=i+1; j<=lim+1; j++){ for(int k =j+1; k<=lim+2;k++){ for(int l=k+1 ; l<=lim+3;l++){ for(int m=l+1 ; m<=lim+4;m++){ for(int o=m+1 ; o<=lim+5;o++){ From bulliver at badcomputer.org Sun Dec 4 21:40:33 2005 From: bulliver at badcomputer.org (darren kirby) Date: Sun, 4 Dec 2005 18:40:33 -0800 Subject: Favorite flavor of Linux? (for python or anything else) In-Reply-To: <86wtikwc12.fsf@bhuda.mired.org> References: <17d4ae400512040601j7ba8bf6cx89eae7f20b8820a6@mail.gmail.com> <1133744404.754416.247720@z14g2000cwz.googlegroups.com> <86wtikwc12.fsf@bhuda.mired.org> Message-ID: <200512041840.38036.bulliver@badcomputer.org> quoth the Mike Meyer: > A lot of the > rough edges of Gentoo have been dealt with in FreeBSD. For instance, > you can update from source, but you can also get binary updates. You can sort of do this with Gentoo. Check out the "--usepkg", "--getbinpkg" and "--buildpkg" emerge options. The only problem is that I don't think there are many (any?) official repositories of binary packages, and if there are, they don't have the full array of all packages available from portage. I haven't checked in a while though, so this may be different now. In any event, it is an excellant timesaver if you have a network of similar systems. emerge from source on your staging server, build a bin package, and push it to the rest of the systems. -d -- darren kirby :: Part of the problem since 1976 :: http://badcomputer.org/ "...the number of UNIX installations has grown to 10, with more expected..." - Dennis Ritchie and Ken Thompson, June 1972 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From anton.vredegoor at gmail.com Wed Dec 28 10:45:23 2005 From: anton.vredegoor at gmail.com (Anton Vredegoor) Date: 28 Dec 2005 07:45:23 -0800 Subject: - E04 - Leadership! Google, Guido van Rossum, PSF References: <43b15d36$0$82640$ed2619ec@ptn-nntp-reader03.plus.net> <1135782518.053020.14730@g43g2000cwa.googlegroups.com> Message-ID: <1135784723.379971.131020@g47g2000cwa.googlegroups.com> Robert Kern wrote: > I have a friend who works at Google. He has no backstabbing history at all. Stop > insulting my friends. Your friends work for people who would never hire me. My resume sucks, but I'm not a bad person or a mediocre programmer. They sold out. > For Software Engineer: > > """ > Requirements: > > * BS or MS in Computer Science or equivalent (PhD a plus). Right here. > * Several years of software development experience. > * Enthusiasm for solving interesting problems. > * Experience with Unix/Linux or Windows environments, C++ development, > distributed systems, machine learning, information retrieval, network > programming and/or developing large software systems a plus. > """ > > I don't see any "damaged soul" requirement. I do. Experience here is an eufemism for having worked for the man. > >>(Especially if he uses PyPy to experiment and play in ... :) > > > > Yes PyPy could save Python, or destroy the world. I have the impression > > not many enough people realize that a selfhosting programming language > > is something on the same level as a nano assembler or an artificial > > intelligence. > > ??? What the hell are you smoking? We already have self-hosting programming > languages. Yes. We have humans too. > > Anton > > > > 'make my day, prove me wrong' > > Prove yourself right. Ok. That's a bit harder. I suppose we agree that if we have an intelligent program that is more intelligent than a human and have this program design an even more intelligent program than things start to accelerate pretty fast? Now the combination of a programmer with a tool (program) that can be used to make a better tool. This gives a better human-machine combination, which then can be used to further improve the combination. I don't think I have completely proven my point now, but since the danger is very real and big, coming close is already reason enough to watch this carefully. Why hasn't it happened yet with lisp? I don't know, why didn't the world get destroyed by all out atomic warfare? Couldn't it have happened? If we create AI why would AI keep us around if we ourselves won't even hire people that do not comply to absurdly specific preconditions? Don't we let our poor people starve in the undeveloped countries or even in our own cities? If we want to prove we belong to the next world we should start now. Open work communities where everyone can start working and get paid. The same thing as open source code or usenet but now with money for everyone. Anton 'sorry, I don't want to start a flamewar, but I really believe what I wrote here' From rpdooling at gmail.com Mon Dec 26 11:29:53 2005 From: rpdooling at gmail.com (BartlebyScrivener) Date: 26 Dec 2005 08:29:53 -0800 Subject: Windows and python execution References: <43afdec0$0$15788$14726298@news.sunsite.dk> <43b003e7$0$15787$14726298@news.sunsite.dk> Message-ID: <1135614593.830965.227830@g47g2000cwa.googlegroups.com> The installer can put python.exe in his PATH but if he's storing his scripts in some oddball place then he has to tell Windows where to find them. rpd From doudehou at gmail.com Wed Dec 21 02:41:36 2005 From: doudehou at gmail.com (ddh) Date: 20 Dec 2005 23:41:36 -0800 Subject: Why my thread can't access the global data? In-Reply-To: <1135150104.125436.98790@g43g2000cwa.googlegroups.com> References: <1135149190.470423.46610@g47g2000cwa.googlegroups.com> <1135150104.125436.98790@g43g2000cwa.googlegroups.com> Message-ID: <1135150896.831283.284870@g14g2000cwa.googlegroups.com> Thank you, but I think it may be not this reason. You see, when accept returns, the go_on will be checked in 'while go_on:', so if it is set to be false, the loop will end. I have set a 0.5 second time out on the select() function. So the 'go_on' will be checked at a frequency every 0.5 second at least. Pelmen wrote: > your main loop already on accept when your thread change the go_on imho > try to input another string after 'quit' > > and actually there is no need to use thread From steve.horsley at gmail.com Fri Dec 16 13:29:42 2005 From: steve.horsley at gmail.com (Steve Horsley) Date: Fri, 16 Dec 2005 18:29:42 +0000 Subject: OO in Python? ^^ In-Reply-To: References: Message-ID: Matthias Kaeppler wrote: > Hi, > > sorry for my ignorance, but after reading the Python tutorial on > python.org, I'm sort of, well surprised about the lack of OOP > capabilities in python. Honestly, I don't even see the point at all of > how OO actually works in Python. > > For one, is there any good reason why I should ever inherit from a > class? ^^ There is no functionality to check if a subclass correctly > implements an inherited interface and polymorphism seems to be missing > in Python as well. I kind of can't imagine in which circumstances > inheritance in Python helps. For example: > > class Base: > def foo(self): # I'd like to say that children must implement foo > pass > > class Child(Base): > pass # works > > Does inheritance in Python boil down to a mere code sharing? > > And how do I formulate polymorphism in Python? Example: > > class D1(Base): > def foo(self): > print "D1" > > class D2(Base): > def foo(self): > print "D2" > > obj = Base() # I want a base class reference which is polymorphic This line is redundant. You don't appear to want to actually create a Base object here, and the following code will ensure that you end up having an 'obj' variable anyway. > if (): > obj = D1() > else: > obj = D2() > OK. So now you have 'obj' referencing either a D1 or a D2. Both D1 and D2 objects have a foo() method, so here is polymorphism. There is no evidence of inheritance here though, because you chose to override the only method that they could have inherited from class Base. Now, if Base had also had a bar(self) method, both would have inherited that. Try this: class Base: def __init__(self): self.value = 0 def foo(self): print "Base", self.value def bar(self): self.value += 1 class D1(Base): def foo(self): print "D1", self.value class D2(Base): def foo(self): print "D2", self.value want1 = False if want1: obj = D1() else: obj = D2() obj.foo() obj.bar() obj.foo() Steve From fredrik at pythonware.com Mon Dec 12 14:37:51 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 12 Dec 2005 20:37:51 +0100 Subject: namespace in Python? References: Message-ID: "Carl" wrote: > What is the equivalent of a C++ (or C#) namespace in Python? modules and packages: http://docs.python.org/tut/node8.html From python-url at phaseit.net Wed Dec 21 11:30:35 2005 From: python-url at phaseit.net (Cameron Laird) Date: Wed, 21 Dec 2005 16:30:35 +0000 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 21) Message-ID: QOTW: "[P]ortability is an n-way street." - Paul McGuire "Python's polymorphism support is so good that it makes inheritance much less important than it is in other languages." - Ben Sizer Skip Montanaro presents the affirmative case for Python as a unit-testing framework for C++: http://groups.google.com/group/comp.lang.python/browse_thread/thread/1d214e2b636aa313/ Oh. Wow. Nintendo DS-s run Python: http://groups.google.com/group/comp.lang.python/browse_thread/thread/4aec55ce14c73dd2/ Eggs is "a Python-specific apt-get" (not limited to Debian, though): http://groups.google.com/group/comp.lang.python/browse_thread/thread/cb116f06f3a64a59/ mechanize scrapes the Web. This page has Actual Working Examples: http://www.junkheap.net/projects/python-windows-ssl/python-windows-ssl.html Python's local functions are inexpensive, preaches Fredrik Lundh. This reality is behind Pythonia's relative disaffection for lambda: http://groups.google.com/group/comp.lang.python/browse_thread/thread/b2481e0184cec255/ In the same thread, Christopher Subich makes a sophisticated argument for lambda as "encapsulated expression" rather than "anonymous function". vd12 collects implementations of the crucial cross-product function. Compare their readability to those coded in other well-known languages: http://groups.google.com/group/comp.lang.python/msg/41c7b5849068e4f2 Tim Delaney distinguishes -c and -m in the course of explaining "a perfect example of a 'new' one-obvious-way replacing an old way": http://groups.google.com/group/comp.lang.python/browse_thread/thread/3b6a37b52da3ec3/ ======================================================================== 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. For far, FAR more Python reading than any one mind should absorb, much of it quite interesting, several pages index much of the universe of Pybloggers. http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog http://www.planetpython.org/ http://mechanicalcat.net/pyblagg.html 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 Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous tradition early borne by Andrew Kuchling, Michael Hudson and Brett Cannon 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/ 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 Kurt B. Kaiser publishes a weekly report on faults and patches. http://www.google.com/groups?as_usubject=weekly%20python%20patch 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. del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python *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/topic/python/ (requires subscription) http://groups-beta.google.com/groups?q=python-url+group:comp.lang.python*&start=0&scoring=d& 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 There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. 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 bonono at gmail.com Thu Dec 15 01:14:22 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 14 Dec 2005 22:14:22 -0800 Subject: OO in Python? ^^ In-Reply-To: <1h7kymc.1n6gss7to9krnN%aleax@mail.comcast.net> References: <1134486233.926141.49140@g47g2000cwa.googlegroups.com> <1h7kxmv.1u4vb861asqa1lN%aleax@mail.comcast.net> <1134626006.923551.294410@g47g2000cwa.googlegroups.com> <1h7kymc.1n6gss7to9krnN%aleax@mail.comcast.net> Message-ID: <1134627262.620671.41660@g49g2000cwa.googlegroups.com> Alex Martelli wrote: > wrote: > > > Alex Martelli wrote: > > > wrote: > > > > > > > > those convoluted templates that were added to the language as > > > > > an afterthought. > > > > I don't see this in Haskell. > > > > > > Well, historically templates HAVE been added to Haskell "as an > > > afterthought" (well after the rest of the language was done), and > > > judging mostly from > > > > > .ps> it doesn't seem unfair to call them "convoluted"... > > > > > I think I was talking about the need to add templates in order for > > writing generic functions that was mentioned(see the example given > > about sum), not in the context you are talking about. You seem to have > > skipped the other half of the text I quoted. > > Right, you can get good genericity with Haskell's typeclasses (I've > posted about that often in the past, and desperately and so far > unsuccessfully tried to convince Guido to use something close to > typeclasses rather than "interfaces" for such purposes as PEP 246 > [protocol adaptation]); it's the state of _templates_ in Haskell, > specifically, which I was rather dubious about (it may be that I just > haven't dug into them deep enough yet, but they do seem not a little > "convoluted" to me, so far). > Yup, the templates is an afterthought and the point of discussion by Lispers(?) too. I have no idea what it is intended for, there must be some need for it but definitely beyond what I can handle. From fredrik at pythonware.com Tue Dec 13 05:53:59 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 13 Dec 2005 11:53:59 +0100 Subject: "0 in [True,False]" returns True References: <439deb17$0$18320$8fcfb975@news.wanadoo.fr><1134469801.271680.144240@f14g2000cwb.googlegroups.com> Message-ID: Duncan Booth wrote: > > > For HTML attributes that don't have an explicit value (such as the > > SELECTED attribute in OPTION) the keyword argument to the function must > > have the value True > > A better way to do this (given that HTML defines exactly which attributes > do not take a value) is to use the attribute name and simply generate the > attribute only if the value is non-false. footnote: strictly speaking, minimized attributes have values but no names; it's up to the parser to determine what attribute you're setting when you specify the value. (for example, in , "ismap" is the value, not the attribute name. it's up to the parser to figure out (from the DTD) that this value can only be used by the "ismap" attribute, and interpret it as ) From codecraig at gmail.com Wed Dec 7 09:38:38 2005 From: codecraig at gmail.com (py) Date: 7 Dec 2005 06:38:38 -0800 Subject: uuDecode problem Message-ID: <1133966318.424045.186400@g49g2000cwa.googlegroups.com> Hi, I am encoding a string such as... [code] data = someFile.readlines() encoded = [] for line in data: encoded.append(binascii.b2a_uu(stringToEncode)) return encoded [/code] ...I then try to decode this by... [code] def decode(data): result = [] for val in data: result.append(binascii.a2b_uu(val)) return result [/code] this seems to work sometimes....for example a list which has a short string in it like ["this is a test"] however if the list of data going into the decode function contains a bunch of elements I get the following error... result.append(binascii.a2b_uu(val)) binascii.Error: Trailing garbage ..any idea why this is happening? Anyone successfully use the uu to encode/decode strings of varying length (even larger strings, more than a few hundred characters)? From mcPas.De.Spam at mclaveauPas.De.Spam.com Sun Dec 18 06:18:50 2005 From: mcPas.De.Spam at mclaveauPas.De.Spam.com (Michel Claveau) Date: Sun, 18 Dec 2005 12:18:50 +0100 Subject: Can Python write foreign characters to the console? References: <43A25DB9.5313E3B2@telus.net> <43a26b5f$0$21023$636a55ce@news.free.fr> <43A311D6.9040701@v.loewis.de> <43a32244$0$21047$636a55ce@news.free.fr> <43A3EBBE.6020504@v.loewis.de> Message-ID: Hi! I have a problem, under win-XP, with this code : # -*- coding: cp-1252 -*- import sys print u"Martin v. L?wis" print "? for No?l" print u"? for No?l" sys.exit() ==> "Python a provoqu? une erreur" Am I the only one to have that? Michel Claveau -- @-salutations Michel Claveau From aahz at pythoncraft.com Sun Dec 4 13:56:09 2005 From: aahz at pythoncraft.com (Aahz) Date: 4 Dec 2005 10:56:09 -0800 Subject: Favorite flavor of Linux? (for python or anything else) References: <17d4ae400512040601j7ba8bf6cx89eae7f20b8820a6@mail.gmail.com> Message-ID: In article , Christoph Haas wrote: > >The operating system/distribution is not connected to the application >(Python). It will probably run everywhere. But we recently had this >topic and a majority seemed to vote for Ubuntu. I personally prefer >Debian. Ubuntu *is* Debian, just repackaged. I used to prefer Debian until stable wouldn't work with my newest machine because it was two years out of date (this was *not* a machine with bleeding-edge components). Of course, one can use Debian-testing, but that isn't packaged, and I want a packaged OS. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Don't listen to schmucks on USENET when making legal decisions. Hire yourself a competent schmuck." --USENET schmuck (aka Robert Kern) From ownowl at club-internet.fr Thu Dec 29 09:29:31 2005 From: ownowl at club-internet.fr (ownowl) Date: Thu, 29 Dec 2005 15:29:31 +0100 Subject: split text file with x0Dx0A In-Reply-To: References: <43b3ca6e$0$11353$7a628cd7@news.club-internet.fr> Message-ID: <43b3f2ce$0$11348$7a628cd7@news.club-internet.fr> Fredrik Lundh a ?crit : > "ownowl" wrote: > > >>beginer under python, I have a problem to get lines in a text file. >>lines have inside the \n (x0A) char, and le readline method split the >>line at this char too (not only at x0Dx0A). > > > that's not a very clever design, at least if you plan to read the files > from C or compatible languages... > > >>for resume, I want to split a file to lines with only those chars : x0Dx0A >> >>A idea ? > > > the easiest way to do this is to open the file in binary mode, gobble up > the entire file, and split it yourself: > > for line in open(filename, "rb").read().split("\r\n"): > ... > > great thank's From tismer at stackless.com Sun Dec 25 12:29:27 2005 From: tismer at stackless.com (Christian Tismer) Date: Sun, 25 Dec 2005 18:29:27 +0100 Subject: python coding contest In-Reply-To: <43AED161.9060409@airlangen.de> References: <43AEBD43.7080407@airlangen.de> <43AECBFA.2070209@stackless.com> <43AED161.9060409@airlangen.de> Message-ID: <43AED6F7.9090108@stackless.com> Simon Hengel wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > >> I'm envisioning lots of convoluted one-liners which >> are more suitable to a different P-language... :-) > I feel that python is more beautiful and readable, even if you write > short programs. > >> How about """best compromize between shortness and readibility >> plus elegance of design"""? > I would love to choose those criteria for future events. But I'm not > aware of any algorithm that is capable of creating a ranking upon them. > Maybe we can come up with a solution. Any ideas? Me neither :-) Maybe a compromize proposal could be like this: - Squeezing many lines into one using semicola does not help, the program will be expanded to use one statement per line - blank lines are allowed and not counted if they are not needed as part of the code - the length of names does not count, unless the code depends on it. Some harmonization procedure might be applied to every solution before counting lines, in order to avoid spectacular cryptic stuff. I have no idea whether I'm serious about this. Having this said, I'm trashing my one-liner :-)) if-it-doesn't-look-like-Python-it-is-not-Python - ly y'rs -- chris -- Christian Tismer :^) tismerysoft GmbH : 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 802 86 56 mobile +49 173 24 18 776 fax +49 30 80 90 57 05 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From iddw at hotmail.com Wed Dec 21 09:46:20 2005 From: iddw at hotmail.com (Dave Hansen) Date: Wed, 21 Dec 2005 08:46:20 -0600 Subject: parsing engineering symbols References: Message-ID: On Wed, 21 Dec 2005 19:10:21 +0530 in comp.lang.python, Suresh Jeevanandam wrote: [re: SI prefixes] > >Exactly what I wanted. > >It would be nice if the standard float function takes care of these. No, it wouldn't. Regards, -=Dave -- Change is inevitable, progress is not. From laurent.pointal at limsi.fr Mon Dec 5 10:42:09 2005 From: laurent.pointal at limsi.fr (Laurent Pointal) Date: Mon, 05 Dec 2005 16:42:09 +0100 Subject: Creating referenceable objects from XML In-Reply-To: References: Message-ID: Michael Williams wrote: > Hi All, > > I'm looking for a quality Python XML implementation. All of the DOM > and SAX implementations I've come across so far are rather convoluted. > Are there any quality implementations that will (after parsing the XML) > return an object that is accessible by name? Such as the following: > > > > > xml = """ > > MyBook > the author > > """ > > > > > > And after parsing the XML allow me to access it as so: > > book.title > > I need it to somehow convert my XML to intuitively referenceable > object. Any ideas? I could even do it myself if I knew the mechanism > by which python classes do this (create variables on the fly). > > Thanks in advance! Another tool (ElementsTree already quoted): Amara ( http://uche.ogbuji.net/uche.ogbuji.net/tech/4suite/amara/ ) [never tested but bookmarked as it seem interresting] A+ Laurent. From universal_used at hotmail.com Wed Dec 7 15:46:56 2005 From: universal_used at hotmail.com (questions?) Date: 7 Dec 2005 12:46:56 -0800 Subject: List index question In-Reply-To: References: <1133987988.721922.215270@o13g2000cwo.googlegroups.com> Message-ID: <1133988416.883893.94590@g14g2000cwa.googlegroups.com> sorry, I realized the problem already. sorry for the confusion. THanks for the answer!!! From dcrespo at gmail.com Tue Dec 20 10:36:07 2005 From: dcrespo at gmail.com (Daniel Crespo) Date: 20 Dec 2005 07:36:07 -0800 Subject: allow_none=True in SimpleXMLRPCServer In-Reply-To: <1134577564.209913.222150@g14g2000cwa.googlegroups.com> References: <1134416960.599321.148130@g47g2000cwa.googlegroups.com> <43a04646$1@clarion.carno.net.au> <1134577564.209913.222150@g14g2000cwa.googlegroups.com> Message-ID: <1135092966.984245.259980@z14g2000cwz.googlegroups.com> Hi Dody! It works perfect! Now, I want the SimpleXMLRPCServer.py not to be on the same directory, but in my /lib directory. I tried it, but it seems that the module loads from python24/ first. How can I change this? Thank you! From boris317 at gmail.com Mon Dec 12 15:22:54 2005 From: boris317 at gmail.com (shawn a) Date: Mon, 12 Dec 2005 15:22:54 -0500 Subject: TypeError: no arguments expected In-Reply-To: References: Message-ID: thanks for all your input. Ive gotten it to work thanks! --shawn On 12/12/05, Steve Holden wrote: > Dennis Lee Bieber wrote: > > On Sun, 11 Dec 2005 22:00:55 -0500, shawn a > > declaimed the following in comp.lang.python: > > > > > >>I havet these 2 files in the same dir. This is code im writing to learn pythong > >>mkoneurl.py: > >>#! /usr/bin/env python > >> > >>import make_ou_class > >> > >>run = make_ou_class.makeoneurl() > > > > > > Okay, you've just defined a "run" object that contains an instance > > of "makeoneurl"... What do you expect it to do? > > > Let's get the terminology right: sloppy terminology leads to sloppy > thinking. The statement binds the name "run" to a newly-created > "make_one_url" instance. Remember, "run" isn't an object, it's a > reference to an object like all Python names. > > > >>==================================== > >>make_ou_class.py: > >> > > > > Well, first off... You need to /supply/ a placeholder for "self". > > ALL methods of a class receive the instance as the first argument. So... > > > Again you need to be a little careful here, since we now have class > methods and static methods to cloud the picture. So it would be more > accurate to say that "instance methods are all automatically called with > a reference to the instance as the first argument; it is conventional to > use the name 'self' to refer to the instance". > > > [...] > > regards > Steve > -- > Steve Holden +44 150 684 7255 +1 800 494 3119 > Holden Web LLC www.holdenweb.com > PyCon TX 2006 www.python.org/pycon/ > > -- > http://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Wed Dec 7 17:12:38 2005 From: __peter__ at web.de (Peter Otten) Date: Wed, 07 Dec 2005 23:12:38 +0100 Subject: option argument length References: Message-ID: Ritesh Raj Sarraf wrote: > ./sarraf.py --fetch-update /bar > > If the user gives the /bar argument, the program should save the > downloaded files to /bar. But I'm assuming that the user could be dumb or > too lazy, in which case --fetch-udpate should use the parser.set_defaults > value i.e. /foo > > ./sarraf.py --set-upgrade foo.dat --upgrade-type minimal > > set-upgrade will again write data to foo.dat. If the user doesn't pass it > as an arguemnt it should take the defaults (again whatever is there in > parser.set_defaults). This will be inclusive with the --upgrade-type > option because the user will have a choice of selecting what kind of > upgrade he'd like to do, minimal or full or blah. > > For this I think this should be enough: > > if not options.set_upgrade and options.upgrade_type: > parser.error("They?are?mutually?inclusive?options") > > > But my main concern is what if the user doesn't pass any arguemtns. Every > option I have has a default value. So I want to check what the user has > passed. > But unfortunately the args variable has "0" as its value always. args are just the leftover arguments. For ./sarraf.py alpha --set-upgrade foo.dat beta it would be ["alpha", "beta"]. --- I think your description is starting to make sense to me. Your user can either update or upgrade but you cannot just check the value of e. g. set_upgrade because you want to treat the default value and that same value given on the command line differently. If this is a correct assessment I don't think what you want is covered by optparse. However, I hacked something together: import optparse parser = optparse.OptionParser() parser.add_option("--alpha") parser.add_option("--beta") class Values(object): def __init__(self): self.__defaults = {} def set_defaults(self, **kw): self.__defaults.update(kw) def __len__(self): """Number of options set by the user.""" return len(self.__dict__) -1 def __getattr__(self, name): try: return self.__defaults[name] except KeyError: raise AttributeError def is_default(self, name): """Return True when the default fro option 'name' wasn't overriden by the user""" return name not in self.__dict__ values = Values() values.set_defaults(alpha="xxx", beta="yyy") options, args = parser.parse_args(values=values) print "len(options) =", len(options) print "alpha =", options.alpha, print "(using default)" * options.is_default("alpha") print "beta =", options.beta, print "(using default)" * options.is_default("beta") Not particularly elegant but I'm not able to come up with something better for the moment. Maybe you should just provide fewer defaults to the parser. Or you could look into option callbacks for an alternate approach. > Is my way (up till now) of using optparse logically incorrect or improper > ? Well, as the optparse author points out, "required options" are a self-contradictory term -- don't use them if you can avoid it. Would your problem go away if you used two different scripts, one for updating and the other for upgrading? Peter From ashokagk at gmail.com Thu Dec 1 17:25:48 2005 From: ashokagk at gmail.com (ash) Date: 1 Dec 2005 14:25:48 -0800 Subject: how to run an external program... In-Reply-To: References: <1133467023.049531.63550@g44g2000cwa.googlegroups.com> <438F658E.5030503@websafe.com> Message-ID: <1133475948.120744.245630@o13g2000cwo.googlegroups.com> Thanks for Philippe, Larry and Fredrik for the help. the subprocess module did the trick. From mneyer at gmail.com Thu Dec 22 17:35:15 2005 From: mneyer at gmail.com (mneyer at gmail.com) Date: 22 Dec 2005 14:35:15 -0800 Subject: GUI and graph In-Reply-To: <1135288231.524102.326870@f14g2000cwb.googlegroups.com> References: <1135288231.524102.326870@f14g2000cwb.googlegroups.com> Message-ID: <1135290915.355110.156630@g47g2000cwa.googlegroups.com> Look up the information on graphical displays in Tk for python. http://www.pythonware.com/library/tkinter/introduction/ From larry.bates at websafe.com Mon Dec 19 09:08:16 2005 From: larry.bates at websafe.com (Larry Bates) Date: Mon, 19 Dec 2005 08:08:16 -0600 Subject: attach a pdf file to an email In-Reply-To: <1134969942.046260.112160@f14g2000cwb.googlegroups.com> References: <1134969942.046260.112160@f14g2000cwb.googlegroups.com> Message-ID: <43A6BED0.4070606@websafe.com> nonamehkg at hotmail.com wrote: > Hi, I am writing a simple program that sends emails with attachments. > > I could use "MIMEImage" for .png and then attach it to an > "MIMEMultipart" object. But I couldn't or don't know how to attachment > a .pdf or something else to my emails. > > I'm new to python, could somebody help me about that? > > > Thank You, > > > kychan > Here is a great helper class that I have used for several years. I didn't write it, but it has worked fine. Even if you want to write your own, it should help as a guide. http://motion.sourceforge.net/related/send_jpg.py Larry Bates From esj at harvee.org Sat Dec 31 13:57:46 2005 From: esj at harvee.org (Eric S. Johansson) Date: Sat, 31 Dec 2005 13:57:46 -0500 Subject: bsddb3 locking questions In-Reply-To: References: Message-ID: Eric S. Johansson wrote: > are there any simple examples of how to do record locking with bsddb3? got this far with sample code from the activeware site filename = 'fruit' # Get an instance of BerkeleyDB db_env = db.DBEnv() db.set_lk_detect(db.DB_LOCK_YOUNGEST) db_env.open("/tmp/bsddb3",db.DB_INIT_LOCK|db.DB_CREATE) db_env.lock_id() stuck at lock_id(). it returns a 1 (failure according to the docs and there is no hint of where the lock id value is returned so I can use it in the lock_get call. at least that is what I think I need to do. From peter at engcorp.com Mon Dec 19 19:38:43 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 19 Dec 2005 19:38:43 -0500 Subject: Parsing text In-Reply-To: <1135034110.049662.204290@g49g2000cwa.googlegroups.com> References: <1135034110.049662.204290@g49g2000cwa.googlegroups.com> Message-ID: sicvic wrote: > I was wondering if theres a way where python can read through the lines > of a text file searching for a key phrase then writing that line and > all lines following it up to a certain point, such as until it sees a > string of "---------------------" > > Right now I can only have python write just the line the key phrase is > found in. That's a good start. Maybe you could post the code that you've already got that does this, and people could comment on it and help you along. (I'm suggesting that partly because this almost sounds like homework, but you'll benefit more by doing it this way than just by having an answer handed to you whether this is homework or not.) -Peter From mwilliams at mgreg.com Tue Dec 6 20:13:57 2005 From: mwilliams at mgreg.com (Michael Williams) Date: Tue, 6 Dec 2005 20:13:57 -0500 Subject: dynamic variable referencing In-Reply-To: References: Message-ID: <321C681E-B4B3-4247-8299-53ED9FF90A4B@mgreg.com> I would RTM, but I'm not sure exactly what to look for. Basically, I need to be able to call a variable dynamically. Meaning something like the following: - I don't want to say OBJECT.VAR but rather OBJECT. ("string") and have it retrieve the variable (not the value of it) if in fact it exists. . . The purpose is to create an XML tree myself by means of OBJECT. ("string").__setattr(name,value). I eventually want to be able to say BOOK[0].AUTHOR.FIRSTNAME . . . that kind of thing. I've seen existing libraries, but I'd really rather know how to do it myself. Any assistance would be appreciated. Regards, Michael From http Tue Dec 13 15:41:05 2005 From: http (Paul Rubin) Date: 13 Dec 2005 12:41:05 -0800 Subject: newbie: generate a function based on an expression References: <1134452303.564542.155370@g14g2000cwa.googlegroups.com> <86oe3llboa.fsf@bhuda.mired.org> <1134485074.415539.66780@f14g2000cwb.googlegroups.com> Message-ID: <7xslswybku.fsf@ruckus.brouhaha.com> "Jacob Rael" writes: > I read about the security concerns involved in using eval(). I don't > expect this project to grow to the point where I require a web > interface. However, since I am learning, I might as well learn the > right way. I think you're going to have to write an actual parser and evaluator. There are various tools that can help you do that (PyParse, etc.) but if it's for a learning project, you might like to try doing it from scratch. From kent at kentsjohnson.com Fri Dec 23 08:12:39 2005 From: kent at kentsjohnson.com (Kent Johnson) Date: Fri, 23 Dec 2005 08:12:39 -0500 Subject: sorting with expensive compares? In-Reply-To: <1135325364.611405.216880@g43g2000cwa.googlegroups.com> References: <1135325364.611405.216880@g43g2000cwa.googlegroups.com> Message-ID: <43abf47a_3@newspeer2.tds.net> bonono at gmail.com wrote: > Dan Stromberg wrote: >>Python appears to have a good sort method, but when sorting array elements >>that are very large, and hence have very expensive compares, is there some >>sort of already-available sort function that will merge like elements into >>a chain, so that they won't have to be recompared as many times? > > Sounds like DSU time. > > [a] -> [ (hash(a), a) ] This won't work - elements with different hashes will sort by hash and elements with the same hash will still be compared which is exactly what the OP is trying to avoid. If there is some function of the arrays which sorts in the same order as the natural comparison then that function can be used as a sort key. sort(arrayList, key=some_proxy_function) Kent From dwahler at gmail.com Sat Dec 24 12:13:33 2005 From: dwahler at gmail.com (David Wahler) Date: 24 Dec 2005 09:13:33 -0800 Subject: Timing out arbitrary functions References: Message-ID: <1135444413.014292.142730@g14g2000cwa.googlegroups.com> Steven D'Aprano wrote: > I have a problem and I don't know where to start looking for a solution. > > I have a class that needs to call an arbitrary function and wait for a > result. The function, being completely arbitrary and not under my control, > may be very time consuming and possibly may not even halt. My class needs > to be able to give up waiting for a result after a specified amount of > time. > > I'm thinking something conceptually like this: > > # pseudo-code: > set time out to 30 seconds > try: > result = somefunction() > except TimeOut: > # 30 second time out happened > print "somefunction() timed out without returning" > else: > print "somefunction() returned %s" % result > > > The easy (for some definition of easy) solution would be to code > somefunction() so that it raised an exception if it hadn't returned a > result within a certain time. Unfortunately, I can't do rely on that -- I > only have control over the calling code, not the called somefunction(), > which may be any arbitrary function. > > How do others handle something like this? What should I be looking for? > I'm after a lightweight solution, if any such thing exists. For simple cases, I would use signal.alarm() with a SIGALARM handler that raises a TimeOut exception. However, this is by no means foolproof; you have to rely on the called function not to mess with your signal handler. Plus, if your alarm occurs within a try-except block that catches the TimeOut, it'll still be dropped. And to the best of my knowledge, you can't otherwise forcibly terminate the execution of a Python thread or block of code. If you're going to be running untrusted code, I would use the subprocess module to invoke a separate Python instance which takes the code to be executed on stdin, and returns a pickled copy of the return value on stdout. Then you can start it running, wait 30 seconds, and then kill it if it hasn't already returned. -- David From ggrp1.20.martineau at dfgh.net Thu Dec 15 21:03:27 2005 From: ggrp1.20.martineau at dfgh.net (Martin Miller) Date: 15 Dec 2005 18:03:27 -0800 Subject: Python IDE (was: PythonWin troubleshooting) In-Reply-To: <1134696437.635875.106850@z14g2000cwz.googlegroups.com> References: <1134442802.612256.10760@g49g2000cwa.googlegroups.com> <1134696437.635875.106850@z14g2000cwz.googlegroups.com> Message-ID: <1134698607.827229.223380@g49g2000cwa.googlegroups.com> You might want to also to consider the Komodo IDE from ActiveState (the same company that produces ActivePython and hosts the ASPN Cookbook). This isn't an endorsement -- I have no experience with it -- but its feature set looks good [see http://activestate.com/Products/Komodo]. If someone with actual experience using Komodo with Python is listening, I'd be very interested in hearing what you think of it or other alternatives (I plan on taking a look at PyScripter and any others I hear about). Best, -Martin ========== chuck wrote: > Apparently not too many people use or are interested in PythonWin. I'm > giving up on it. It used to work pretty good. > > I'm lucky that I have found PyScripter (http://www.mmm-experts.com/) a > python IDE for the windows platform which is much more stable and has > more features that PythonWin. If you are doing Python development on > Windows I'd recommend taking a look at it. > > I'm also evaluating Wing IDE. I may have another post with comments on > it for anyone who might be interested. From maravilloso at gmail.com Wed Dec 21 07:04:21 2005 From: maravilloso at gmail.com (Maravilloso) Date: 21 Dec 2005 04:04:21 -0800 Subject: ANNOUNCE; Try python beta In-Reply-To: <86oe3c39ho.fsf@bhuda.mired.org> References: <86oe3c39ho.fsf@bhuda.mired.org> Message-ID: <1135166661.656145.18440@o13g2000cwo.googlegroups.com> I'm afraid that I've spoiled the "try_python" working by means of executing the sentence: open("try.py").write("\n") Sorry. I hope it don't be difficult for you to restore the module again to the default folder. In any case, I think it should include some control for malicious code like that one. From aleax at mail.comcast.net Sat Dec 10 21:11:20 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Sat, 10 Dec 2005 18:11:20 -0800 Subject: Another newbie question References: <863bl4xk11.fsf@bhuda.mired.org> <7xd5k71avc.fsf@ruckus.brouhaha.com> <4398D289.9050902@REMOVEMEcyber.com.au> <86vexzvy86.fsf@bhuda.mired.org> <8664pxv523.fsf@bhuda.mired.org> <86u0dgu7ii.fsf@bhuda.mired.org> <1h7ct3q.1ia5gdn9h56hnN%aleax@mail.comcast.net> <864q5gtu9d.fsf@bhuda.mired.org> Message-ID: <1h7d6p0.ow99cp1dwq6buN%aleax@mail.comcast.net> Mike Meyer wrote: ... > Take our much-abused coordinate example, and assume you've exposed the > x and y coordinates as attributes. > > Now we have a changing requirement - we want to get to make the polar > coordinates available. To keep the API consistent, they should be > another pair of attributes, r and theta. Thanks to Pythons nice > properties, we can implement these with a pair of getters, and compute > them on the fly. > > If x and y can't be manipulated individually, you're done. If they > can, you have more work to do. If nothing else, you have to decide > that you're going to provide an incomplete interface, in that users > will be able to manipulate the object with some attributes but not > others for no obvious good reason. To avoid that, you'll have to add > code to run the coordinate transformations in reverse, which wouldn't > otherwise be needed. Properties make this possible, which is a great > thing. Properties make this _easier_ (but you could do it before properties were added to Python, via __setattr__ -- just less conveniently and directly) -- just as easy as setX, setY, setRho, and setTheta would (in fact, we're likely to have some of those methods under our properties, so the difference is all in ease of USE, for the client code, not ease of IMPLEMENTATION, compared to setter-methods). If we keep the internal representation in cartesian coordinates (attributes x and y), and decide that it would interfere with the class's usefulness to have rho and theta read-only (i.e., that it IS useful for the user of the class to be able to manipulate them directly), we do indeed need to "add code" -- the setter methods setRho and setTheta. But let's put that in perspective. If we instead wanted to make the CoordinatePair class immutable, we'd STILL have to offer an alternative constructor or factory-function -- if it's at all useful to manipulate rho and theta in a mutable class, it must be at least as useful to be able to construct an immutable version from rho and theta, after all. So, we ARE going to have, say, a classmethod (note: all the code in this post is untested)...: class CoordinatePair(object): def fromPolar(cls, rho, theta): assert rho>=0 return cls(rho*math.cos(theta), rho*math.sin(theta)) fromPolar = classmethod(fromPolar) # etc etc, the rest of this class well, then, how much more code are we adding, to implement setRho and setTheta when we decide to make our class mutable? Here...: def setRho(self, rho): c = self.fromPolar(rho, self.getTheta()) self.x, self.y = c.x, c.y def setTheta(self, theta): c = self.fromPolar(self.getRho(), theta) self.x, self.y = c.x, c.y That's the maximum possible "difficulty" (...if THIS was a measure of real "difficulty" in programming, I doubt our jobs would be as well paid as they are...;-) -- it's going to be even less if we need anyway to have a method to copy a CoordinatePair instance from another, such as def copyFrom(self, other): self.x, self.y = other.x, other.y since then the above setters also become no-brainer oneliners a la: def setRho(self, rho): self.copyFrom(self.fromPolar(rho, self.getTheta())) and you might choose to further simplify this method's body to self.copyFrom(self.fromPolar(rho, self.theta)) since self.theta is going to be a property whose accessor half is the above-used self.getTheta (mostly a matter of style choice here). Really, I don't think this makes a good poster child for your "attribute mutators make life more difficult" campaign...;-) Alex From pythonnew at gmail.com Sun Dec 4 05:16:49 2005 From: pythonnew at gmail.com (Ben Bush) Date: Sun, 4 Dec 2005 02:16:49 -0800 Subject: enter and event Message-ID: <8c11e4350512040216h5d092a9t7c49983639cd59fa@mail.gmail.com> When I read python Manuel, I got confused by the following code: def turnRed(self, event): event.widget["activeforeground"] = "red" self.button.bind("", self.turnRed) I can not understand it. From richardjones at optushome.com.au Thu Dec 15 21:58:40 2005 From: richardjones at optushome.com.au (richard) Date: Fri, 16 Dec 2005 13:58:40 +1100 Subject: SVG rendering with Python References: <43a095b1$1@news.uni-ulm.de> <43a09922$0$18202$afc38c87@news.optusnet.com.au> Message-ID: <43a22d5f$0$30065$afc38c87@news.optusnet.com.au> Andreas Lobinger wrote: > richard wrote: >> Dennis Benzinger wrote: >>>Does anybody know of a SVG rendering library for Python? >> Google "python svg" > > ... to find what? The answer to the OP's question. Richard From bokr at oz.net Sun Dec 11 23:13:34 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 12 Dec 2005 04:13:34 GMT Subject: OO in Python? ^^ References: <1134308880.689307.22090@z14g2000cwz.googlegroups.com> Message-ID: <439cf844.792206863@news.oz.net> On Mon, 12 Dec 2005 01:12:26 +0000, Tom Anderson wrote: >tom > >-- >????`????,,,,????`????,,,,????`????,,,,????`???? >---910079544-1780890058-1134349946=:30272-- [OT} (just taking liberties with your sig ;-) ,<@>< ????,,,,????`????,,,,????P`????,,y,,????t`????,,h,,????o`????,,n,,???? Regards, Bengt Richter From pelmenmail at mail.ru Wed Dec 14 07:57:56 2005 From: pelmenmail at mail.ru (Pelmen) Date: 14 Dec 2005 04:57:56 -0800 Subject: Get rid of recursive call __getattr__ Message-ID: <1134565076.821710.77740@f14g2000cwb.googlegroups.com> How can I get rid of recursive call __getattr__ inside this method, if i need to use method or property of the class? From tobias.bell at web.de Sun Dec 25 18:57:01 2005 From: tobias.bell at web.de (Tobias Bell) Date: Mon, 26 Dec 2005 00:57:01 +0100 Subject: python coding contest In-Reply-To: <1135551508.876543.175350@g47g2000cwa.googlegroups.com> References: <1135551508.876543.175350@g47g2000cwa.googlegroups.com> Message-ID: Andr? schrieb: > Neat idea! Indeed > > I'm far from being a decent Python programmer but I managed (for fun) > to do it in a one-liner; however, it was definitely longer (in term of > number of characters) than the more readable multi-line solution. I made a readable version with 352 bytes and a non-readable with 290 bytes. But it's a really ugly lambda, map, reduce kludge. Looks like Perl. > > Andr? > Tobias From kenneth.m.mcdonald at sbcglobal.net Sun Dec 4 20:44:28 2005 From: kenneth.m.mcdonald at sbcglobal.net (Kenneth McDonald) Date: Sun, 4 Dec 2005 19:44:28 -0600 Subject: Installing Eric? Message-ID: <97E2D11E-0F7B-457C-8DEE-BF3430CCBD84@sbcglobal.net> I'm wondering if anyone has experience/tips to offer on installing Eric on OS X and XP. Installation on both seems to require a number of steps, some of them seeming potentially fragile, and I'm wondering if I'm looking at a job of perhaps hours (days?), or if everyone manages in just a few minutes. Thanks, Ken From fredrik at pythonware.com Thu Dec 22 13:23:07 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 22 Dec 2005 19:23:07 +0100 Subject: newbie: concatenate literals (using jython) References: <1135275279.588385.58510@g43g2000cwa.googlegroups.com> Message-ID: davidmichaelkarr at gmail.com wrote: > I'm using Jython (actually WebLogic WLST), and trying to do something > really simple. I want to create a string from two function calls and a > literal, like: > > serverport = server.getListenAddress() + ':' + server.getListenPort() > > This complains: > > TypeError: __add__ nor __radd__ defined for these operands > > I've looked at various references, and this seems like the way I'm > supposed to do this, but I'm obviously missing something. Note that > "getListenPort()" returns an int. Is that a problem? yes. python's string concatenation operator doesn't convert things nilly- willy (should "1"+1 be 2 or "11" ?). to convert an object to a string, use str(obj). see this tutorial section for more info: http://docs.python.org/tut/node9.html#SECTION009100000000000000000 From pinard at iro.umontreal.ca Sun Dec 4 22:39:47 2005 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Sun, 4 Dec 2005 22:39:47 -0500 Subject: Detect character encoding In-Reply-To: <3vgg0kF15o9jfU1@uni-berlin.de> References: <3vgg0kF15o9jfU1@uni-berlin.de> Message-ID: <20051205033947.GA23584@phenix.sram.qc.ca> [Diez B. Roggisch] >Michal wrote: >> is there any way how to detect string encoding in Python? >Recode might be of help here, it has such heuristics built in AFAIK. If we are speaking about the same Recode ?, there are some built in tools that could help a human to discover a charset, but this requires work and time, and is far from fully automated as one might dream. While some charsets could be guessed almost correctly by automatic means, most are difficult to recognise. The whole problem is not easy. -- Fran?ois Pinard http://pinard.progiciels-bpi.ca From http Mon Dec 12 03:51:10 2005 From: http (Paul Rubin) Date: 12 Dec 2005 00:51:10 -0800 Subject: lambda (and reduce) are valuable References: <3iomf.519$hB6.515@trnddc05> <7xfyoy7qou.fsf@ruckus.brouhaha.com> <7xvexu1z1a.fsf@ruckus.brouhaha.com> Message-ID: <7xr78i1ywx.fsf@ruckus.brouhaha.com> Paul Rubin writes: > binops = {'+': (lambda x,y: x+y), > '-': (lambda x,y: x-y), > '*': (lambda x,y: x*y), > '/': (lambda x,y: x/y), > '**': (lambda x,y: x**y) > } > How would you refactor that, with no lambda? Ok, with operator.add and so forth. I don't remember if I knew about those at the time. You can easily see though, how additional such simple functions might be wanted, that aren't in the operator module. From steve at holdenweb.com Thu Dec 15 11:57:44 2005 From: steve at holdenweb.com (Steve Holden) Date: Thu, 15 Dec 2005 16:57:44 +0000 Subject: Why and how "there is only one way to do something"? In-Reply-To: References: <1134646944.453716.75850@o13g2000cwo.googlegroups.com> Message-ID: Aahz wrote: > In article , > Steve Holden wrote: > >>Aahz wrote: >> >>>In article , >>>Steve Holden wrote: >>> >>>>(Part of) Python's credo (which you can read in context by typing >>>> >>>> import this >>>> >>>>at an interactive command prompt) is "There should be one (and >>>>preferably only one) way to do it". >>> >>>Actually, I've gotten used to doing >>> >>> python -c 'import this' >> >>Faster: >> >> python -m this > > > Only in Python 2.4 and later: > > starship:~> python2.3 -m this > Unknown option: -m > usage: python2.3 [option] ... [-c cmd | file | -] [arg] ... > Try `python -h' for more information. > > Why, oh why, do so many people on this newsgroup only consider the latest > version "correct"? I've been guilty myself on occasion, but I do try to > label my suggestions with version warnings. Why, oh why, do people who don't run the latest version assume that a solution for a more recent version labels their original solution "incorrect"? Dammit, the only word in my post apart from the command was "faster". Not "wronger" or "righter" or even "better". So climb down off that high horse. Sheesh. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From oliphant.travis at ieee.org Fri Dec 30 15:23:56 2005 From: oliphant.travis at ieee.org (Travis E. Oliphant) Date: Fri, 30 Dec 2005 13:23:56 -0700 Subject: csrss.exe & Numeric In-Reply-To: <1135950228.369918.281510@g49g2000cwa.googlegroups.com> References: <1135950228.369918.281510@g49g2000cwa.googlegroups.com> Message-ID: jelle wrote: > I have a function that uses the Numeric module. When I launch the > function csrss.exe consumes 60 / 70 % cpu power rather than having > python / Numeric run at full speed. Has anyone encountered this problem > before? It seriously messes up my Numeric performance. > Are you memory-limited so that the process is swapping memory to disk? We'll need more details to offer a better suggestion. Best, -Travis From mwm at mired.org Tue Dec 20 09:59:58 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 20 Dec 2005 09:59:58 -0500 Subject: putenv References: <1135056536.750981.302130@g14g2000cwa.googlegroups.com> <11qf61ksr02aof9@corp.supernews.com> Message-ID: <863bknq0ep.fsf@bhuda.mired.org> Terry Hancock writes: > On Tue, 20 Dec 2005 05:35:48 -0000 > Grant Edwards wrote: >> On 2005-12-20, dpugmire at gmail.com >> wrote: >> > I have csh script that calls a bunch of python programs >> > and I'd like to use env variables as kind of a global >> > variable that I can pass around to the pythong scripts. >> >> You can't change the environment of the parent process. >> >> IOW, the python programs can't change the environment of >> the calling csh script (or, by extenstion, the environment >> of subsequent python programs that are called by the csh >> script). > > There is an evil trick, however: > > Instead of setting the environment directly, have the python > program return csh code to alter the environment the way you > want, then call the python code by "sourcing" its output: > > source `my_script.py` Does this actually work? It looks to me like you need two levels: my_script.py creates a file, then outputs the name of the file, as the csh source command reads commands from the file named as an argument. To be able to output the commands directly, you'd need to use the eval command, not the source command. > It's ugly, but it does work -- I have had to use this > before in a production environment. Well, it's not really > any less advisable than scripting in csh to begin with. ;-) Doesn't matter what you're scripting in - you'll have to do some such circumlocution to set the parent scripts environment variables. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From luismgz at gmail.com Tue Dec 20 08:50:33 2005 From: luismgz at gmail.com (Luis M. Gonzalez) Date: 20 Dec 2005 05:50:33 -0800 Subject: Which Python web framework is most like Ruby on Rails? In-Reply-To: <1135085077.952662.55340@o13g2000cwo.googlegroups.com> References: <1134496403.011407.169930@g44g2000cwa.googlegroups.com> <1135029071.990723.134030@z14g2000cwz.googlegroups.com> <1135083100.135409.165580@f14g2000cwb.googlegroups.com> <1135085077.952662.55340@o13g2000cwo.googlegroups.com> Message-ID: <1135086632.969355.205990@g47g2000cwa.googlegroups.com> > Karrigell can also work with . . . all the databases for which a Python > API exists (sqlite, mySql, PostGreSQL, ZODB, etc). Well, that's exactly what makes KARRIGELL so especial. It is very flexible and lets you use whatever database or component you want. It doesn't force you to use an specific package for each task. It doesn't force you either to learn and use any templating language (you don't need it!), although you can do it if you want. The traditional "Hello world" page, can be coded like this: print "Hello World" No boilerplate code, no need to write a class or to fidle with strange configurations. It's simply python! The only problem with KARRIGELL, I guess, is that its creator is very humble and doesn't like to advertise his creature. He is not very fond of "marketing" ... This is too bad because I feel that other frameworks are getting a lot of the attention that Karrigells deserve... Luis From tgm2tothe10thpower at replacetextwithnumber.hotmail.com Fri Dec 9 20:11:59 2005 From: tgm2tothe10thpower at replacetextwithnumber.hotmail.com (Thomas G. Marshall) Date: Sat, 10 Dec 2005 01:11:59 GMT Subject: PHP = Perl Improved References: <1133844932.007824.26780@g43g2000cwa.googlegroups.com> <1134056349.035360.209840@f14g2000cwb.googlegroups.com> <1134155716.631143.191340@f14g2000cwb.googlegroups.com> Message-ID: Roedy Green said something like: > On 9 Dec 2005 11:15:16 -0800, "Xah Lee" wrote, quoted > or indirectly quoted someone who said : > >> recently i got a project that involves the use of php. In 2 days, i >> read almost the entirety of the php doc. Finding it a breeze because it >> is roughly based on Perl, of which i have mastery. > > that's very lovely, but off topic. Trolling for language flame wars > belong is comp.lang.java.advocacy. I had plonked him back in May for this kind of crap. I suggest you do the same. -- If I can ever figure out how, I hope that someday I'll succeed in my lifetime goal of creating a signature that ends with the word "blarphoogy". From timr at probo.com Fri Dec 23 03:03:44 2005 From: timr at probo.com (Tim Roberts) Date: Fri, 23 Dec 2005 08:03:44 GMT Subject: Parsing a date-time string? References: <1135158192.987122.245440@g43g2000cwa.googlegroups.com> Message-ID: <8pbnq1lpb623k5rjlte0nak15v3k7gb9mj@4ax.com> "Tim N. van der Leeuw" wrote: > >I want to parse strings containing date-time, which look like the >following: > > "Mon Dec 19 11:06:12:333 CET 2005" > >That's a problem for strptime it seems, b/c I cannot find any >format-spec for the milliseconds-part in here. (I'm also not sure about >the validity of the tz part, but ...) Central European Time. GMT +1 hour. Quite valid. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From steve.horsley at gmail.com Sun Dec 25 13:32:05 2005 From: steve.horsley at gmail.com (Steve Horsley) Date: Sun, 25 Dec 2005 18:32:05 +0000 Subject: Linux > python > file-I/O ? In-Reply-To: References: Message-ID: news at absamail.co.za wrote: > I've just started to test/learn python. > I've got Linux > mandrake9 > python & documentation. > What I'll initially want to be doing needs file I/O, so I > wanted to confirm file I/O early in my tests. > > Following the examples : >>>> f=open('/tmp/workfile', 'w') >>>> print f > <-- OK > > But: >>>> f.read(size) > Traceback (most recent call last): > File "", line 1, in ? > NameError: name 'size' is not defined <-- ?? Obj-method unknown ?? > > > What's wrong ? > size should be a number of bytes to read. E.g.: f.read(1000) would read 1000 bytes. The size is optional: f.read() would read the entire file in one hit. Beware doing this on huge files that could run you out of memory. > I read: "The set of such modules is a configuration > option which also depends on the underlying platform." > My documenation refers also to Mac & Win installations. > Is there a linux > python NewsGroup ? > Not that I know of. Python is much the same whatever platform it is on. The problem you see above would be exactly the same on Linux, Windows or any other O/S. Just remember to say what O/S when you post problems, just in case it's relevant. Steve From fredrik at pythonware.com Thu Dec 1 12:35:27 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 1 Dec 2005 18:35:27 +0100 Subject: A bug in struct module on the 64-bit platform? References: <1133396081.089848.252550@o13g2000cwo.googlegroups.com><1133416268.242154.190940@g43g2000cwa.googlegroups.com> <20051201132739.GA23791@unpythonic.net> Message-ID: jepler at unpythonic.net wrote: > This is the case on my linux/x86_64 machine: > $ python -c 'import struct; print struct.calcsize("idi")' > 20 > I don't know much about 'itanium', but i'd be surprised if they > chose 4-byte alignment for doubles. oops. missed your reply. > http://h21007.www2.hp.com/dspp/tech/tech_TechDocumentDetailPage_IDX/1,1701,180,00.html fwiw, the same applies to HP-UX: http://devresource.hp.com/drc/STK/docs/refs/64concepts.jsp maybe this is a Windows issue? http://msdn.microsoft.com/library/default.asp?url=/library/en-us/win64/win64/storing_a_64_bit_value.asp I couldn't find anything on alignment, but maybe it's the LLP64 model that's messing things up for the struct module? running the following snippet with different values for TYPE might help us figure this out: #define TYPE char // try short, int, long, float typedef struct { TYPE c; double x; } st_double; main() { printf("align = %d\n", (sizeof(st_double) - sizeof(double))); } From ankitrastogi82 at gmail.com Mon Dec 26 04:47:07 2005 From: ankitrastogi82 at gmail.com (ankit) Date: 26 Dec 2005 01:47:07 -0800 Subject: libxml2 and mindom In-Reply-To: <1135209213.116756.63320@g43g2000cwa.googlegroups.com> References: <1135172760.655562.324080@g49g2000cwa.googlegroups.com> <1135175641.386142.175690@g49g2000cwa.googlegroups.com> <1135180625.179666.268180@o13g2000cwo.googlegroups.com> <1135209213.116756.63320@g43g2000cwa.googlegroups.com> Message-ID: <1135590427.247528.81800@g44g2000cwa.googlegroups.com> Hi Paul, Now I am fixed with libxml2 and libxml2dom. but can you tell me to what extent libxml2dom supports minidom. because I want minidom for traversing. Where I can find the documentation of libxml2dom. From ajikoe at gmail.com Fri Dec 9 08:04:09 2005 From: ajikoe at gmail.com (ajikoe at gmail.com) Date: 9 Dec 2005 05:04:09 -0800 Subject: idea of building python module using pyrex In-Reply-To: References: <1134125136.966666.53940@g14g2000cwa.googlegroups.com> Message-ID: <1134133449.883496.12330@z14g2000cwz.googlegroups.com> Hello, I just wonder if someone has already build it. Thanks for the response. Best Regards, pujo From tim.peters at gmail.com Sat Dec 17 17:26:07 2005 From: tim.peters at gmail.com (Tim Peters) Date: Sat, 17 Dec 2005 17:26:07 -0500 Subject: doctest fails to NORMALIZE_WHITESPACE ? In-Reply-To: <20051217104127.GA30487@mrao.cam.ac.uk> References: <20051217085751.EFDC013EEFF@localhost.localdomain> <1f7befae0512170200w75180f14g69f00e410206f358@mail.gmail.com> <20051217104127.GA30487@mrao.cam.ac.uk> Message-ID: <1f7befae0512171426s4ae00363x73fe4962df20130a@mail.gmail.com> [David MacKay, having fun with doctest] ... > I've got a follow-up question motivated by my ugly backslash continuations. [Tim] >> When Python doesn't "look clean", it's not Python -- and backslash >> continuation & semicolons often look like dirt to the experienced >> Python's eye. > The reason I was making those ugly single-line monsters was I had somehow got > the impression that each fresh line starting ">>>" was tested > _completely_separately_ by doctest; so, to preserve state I thought I had to write > > >>> a=[2, 5, 1]; a.sort(); print a > [1, 2, 5] > > rather than > > >>> a=[2, 5, 1] > >>> a.sort() > >>> print a > [1, 2, 5] > > But I see now I was wrong. Yup, that would be pretty unusable ;-) > Question: > Does doctest always preserve state throughout the entire sequence of tests > enclosed by `"""`, as if the tests were entered in a single interactive session? Pretty much. doctest can take inputs from several places, like (as you're doing) docstrings, but also from files, or from the values in a __test__ dictionary. I'll note parenthetically that doctests are heavily used in Zope3 and ZODB development, and "tutorial doctests" in files have proved to be pleasant & very effective. For example, That entire file is "a doctest", and contains as much expository prose as code. It's written in ReST format, and tools in Zope3 can present such doctest files as nicely formatted documentation too. Unlike most docs, though, each time we run ZODB's or Zope3's test suite, we automatically verify that the examples in _this_ documentation are 100% accurate. Standard practice now is to write a tutorial doctest for a new feature first, before writing any implementation code; this folds in some aspects of test-driven development, but with some care leaves you with _readable_ testing code and a tutorial intro to the feature too. That doctest makes it a little easier to write prose than to write code is a bias that's amazingly effective in getting people to write down what they _think_ they're doing ;-) Anyway, running any piece of Python code requires a global namespace, and doctest uses a single (but mutable!) global namespace for each _batch_ of tests it runs. In the case of a doctest file, a single global namespace is used across the entire file. In your case, letting doctest extract tests from module docstrings, one global namespace is created per docstring. In that case, the globals the tests in a docstring use are initially a shallow copy of the module's __dict__. That way the tests can "see" all the top-level functions and classes and imports (etc) defined in the module, but can't mutate the module's __dict__ directly. Assignments within a doctest alter bindings in the same namespace object, so these bindings are also visible to subsequent code in the same docstring. That's a long-winded way of expanding on section 5.2.3.3 ("What's the Execution Context?") in the docs. > Or is there a way to instruct doctest to forget its state, and start > the next `>>>` with a clean slate? Goodness no -- and nobody would want that. You would lose _all_ globals then, including losing the ability to refer to functions and classes (etc) defined in the module. If, for some reason, you want to destroy some particular binding within a doctest, then you do that the same way you destroy a global binding outside of doctest, with `del`; e.g., """ >>> x = range(1000000) >>> len(x) 1000000 >>> del x # free the memory for the giant list >>> x Traceback (most recent call last): ... NameError: name 'x' is not defined """ works fine as a doctest. From michaelschneider at fuse.net Wed Dec 7 11:25:33 2005 From: michaelschneider at fuse.net (Michael Schneider) Date: Wed, 07 Dec 2005 11:25:33 -0500 Subject: Ant (with Python extensions) good replacement for distutils? In-Reply-To: <1133807818.187874.214190@g14g2000cwa.googlegroups.com> References: <1133807818.187874.214190@g14g2000cwa.googlegroups.com> Message-ID: <63e9$43970d09$d8c4f6e6$5058@FUSE.NET> I would vote against ant because java must be installed to run it. The bootstrap install should be very simple. If you make python usage dependent on: 1) download java 2) install java 3) add java to path 4) download ant 5) install ant 6) add ant to path 7) download ptyhon 8) install python 9) add python to path 10) download package 11) run ant to install package just food for thought, Mike seberino at spawar.navy.mil wrote: > I know distutils well but don't know anything about Ant except that it > is a build > tool from Apache project. > > Could it possible be better or as good as distutils? > (There are extensions for Python.) > > Chris > -- The greatest performance improvement occurs on the transition of from the non-working state to the working state. From t-meyer at ihug.co.nz Sat Dec 3 06:03:47 2005 From: t-meyer at ihug.co.nz (Tony Meyer) Date: Sun, 4 Dec 2005 00:03:47 +1300 Subject: os.rename copies when old is in-use - is this deliberate? In-Reply-To: <4391758e$0$26955$9b622d9e@news.freenet.de> References: <4391758e$0$26955$9b622d9e@news.freenet.de> Message-ID: <513AB523-645D-43EC-9BB4-C6A21CBF4684@ihug.co.nz> [Tony Meyer] >> Is this the intended behaviour? > [Martin v. L?wis] > Sort-of. os.rename invokes the C library's rename, and does whatever > this does. It is expected that most platform's C libraries do what > the documentation says rename does, but platforms may vary in their > implementation of the C library, and from one compiler version to > the other. [snip links to Microsoft documentation, which don't cover the in-use case] Thanks for that. In your opinion, would a documentation patch that explained that this would occur on Windows (after the existing note about the Windows rename not being atomic) be acceptable? (The Windows platform C library for Python 2.4+ is in msvcrt71.dll, right? Does that mean that behaviour will be consistent across Windows versions, or could 9x/NT/XP/etc all behave differently?) =Tony.Meyer From steve at holdenweb.com Mon Dec 12 05:17:24 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 12 Dec 2005 10:17:24 +0000 Subject: TypeError: no arguments expected In-Reply-To: References: Message-ID: Dennis Lee Bieber wrote: > On Sun, 11 Dec 2005 22:00:55 -0500, shawn a > declaimed the following in comp.lang.python: > > >>I havet these 2 files in the same dir. This is code im writing to learn pythong >>mkoneurl.py: >>#! /usr/bin/env python >> >>import make_ou_class >> >>run = make_ou_class.makeoneurl() > > > Okay, you've just defined a "run" object that contains an instance > of "makeoneurl"... What do you expect it to do? > Let's get the terminology right: sloppy terminology leads to sloppy thinking. The statement binds the name "run" to a newly-created "make_one_url" instance. Remember, "run" isn't an object, it's a reference to an object like all Python names. > >>==================================== >>make_ou_class.py: >> > > Well, first off... You need to /supply/ a placeholder for "self". > ALL methods of a class receive the instance as the first argument. So... > Again you need to be a little careful here, since we now have class methods and static methods to cloud the picture. So it would be more accurate to say that "instance methods are all automatically called with a reference to the instance as the first argument; it is conventional to use the name 'self' to refer to the instance". > [...] regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From e.a.m.brouwer at alumnus.utwente.nl Mon Dec 26 19:15:25 2005 From: e.a.m.brouwer at alumnus.utwente.nl (Martijn Brouwer) Date: Tue, 27 Dec 2005 01:15:25 +0100 Subject: closing stdin, stdout and stderr In-Reply-To: <43B07929.2030909@jessikat.fsnet.co.uk> References: <43B07929.2030909@jessikat.fsnet.co.uk> Message-ID: <1135642525.7195.19.camel@martijn.example.com> On Mon, 2005-12-26 at 23:13 +0000, Robin Becker wrote: > Martijn Brouwer wrote: > > I am writing a unix daemon in python, so I want to close stdin, stdout > > and stderr. > > My first attempt was to the standard file descriptors using their > > close() methods. After closing stdout, I could not print anymore, so > > this seemed to work. However, later I noticed that they were not really > > closed. When I close them using os.close(), it did work. > > What is the difference between these two methods and what is the reason > > behind it? It took me a day to find out why I could not log out after > > starting the daemon. > > > > Martijn > > > > > > > I've had excellent results with variants of the cookbook entry at > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731 > I read this one, which was the reason that I tried os.close instead of sys.stdXXX.close(). But I would like to know why it does not close a file discriptor is I call its close method(). Martijn -- Martijn Brouwer From pythonnew at gmail.com Sun Dec 4 08:39:32 2005 From: pythonnew at gmail.com (Ben Bush) Date: Sun, 4 Dec 2005 05:39:32 -0800 Subject: oval In-Reply-To: <3vg36mF1593ufU1@uni-berlin.de> References: <3vg36mF1593ufU1@uni-berlin.de> Message-ID: <8c11e4350512040539u41243301y46703ea1cc00beea@mail.gmail.com> On 12/4/05, Diez B. Roggisch wrote: > Ben Bush wrote: > > I tested the following code and wanted to get the message of "oval2 > > got hit" if I click the red one. But I always got "oval1 got hit". > > from Tkinter import * > > root=Tk() > > canvas=Canvas(root,width=100,height=100) > > canvas.pack() > > a=canvas.create_oval(10,10,20,20,tags='oval1',fill='blue') > > b=canvas.create_oval(50,50,80,80,tags='oval2',fill='red') > > def myEvent(event): > > if a: > > Here is your problem. a is a name, bound to some value. So - it is true, > as python semantics are that way. It would not be true if it was e.g. > > False, [], {}, None, "" > > > What you want instead is something like > > if event.source == a: > ... > > Please note that I don't know what event actually looks like in Tkinter, > so check the docs what actually gets passed to you. got AttributeError: Event instance has no attribute 'source' From mwm at mired.org Fri Dec 30 21:11:28 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 30 Dec 2005 21:11:28 -0500 Subject: List index method for complex list item types? References: <1135991601.987015.111210@z14g2000cwz.googlegroups.com> Message-ID: <86zmmi817z.fsf@bhuda.mired.org> techiepundit at futurepundit.com writes: > I have a list of sockets that I use for select.select calls like this: [...] > But a thought struck me while writing this: Does Python not provide a > way to search a list of sublists to find something on, say, the value > of the first sublist item field as a way to find the index to the item > one wants in the parent list? No, it doesn't. It's not hard to write, though. ISTR something about list methods growing optional arguments that might be usable for this in 2.5, but you'd have to check it yourself. But a list is the wrong tool to use for this problem. > There does not appear to be an alternative to lists that has better > functionality for this purpose. Dictionaries are immutable, right? One > can't use dictionaries for doing look-ups on dynamically changing > lists? Dictionaries are mutable. But you could still use them this way. > For efficiency's sake it seems to me one wants a search function on > lists that returns two things: > - index where the item found. > - full item which matches on the particular field one is looking up > on. Indexing into a list is fast, so there's no really not much need for this. > Am I wrong in thinking Python doesn't really provide an automated way > to search lists of complex things? No, you're not wrong. But using lists is the wrong way to solve your problem. > Also, ii C++ one can use STL iterators to move thru a list or deque. > But if one needs to advance thru a list with array indexes that does > Python index in each time if one is looping thru the list? > > In Python maybe the trick is to use > ii = 0 > For item in List > # see if item matches > > ii = ii + 1 > > and then somehow pop out of the for loop once one finds a match? Use "break" to pop out of the list. Use "enumerate" to iterate through both the list and an index into the list. However, for your problem - finding data associated with a socket that you're using in a select - a list is the wrong tool. Sockets are usable as dictionary keys. So you can store arbitrary extra data in a dictionary indexed by the sockets. That will be faster than searching a list, even if the comparison is very simple. Alternatively, subclass socket, add the data you want associated with each socket to the instances of the subclass, and pass select instances of your subclass. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From jim.steil at customcall.com Mon Dec 12 13:36:33 2005 From: jim.steil at customcall.com (Jim Steil) Date: Mon, 12 Dec 2005 12:36:33 -0600 Subject: Newbie - BigInt Message-ID: <439DC331.4030403@customcall.com> I am trying to call a SOAP web service with python and I having success unless I need to pass a BigInteger parameter. Since python is dynamically typed it seems to be sending a regular int instead of BigInteger and my web service doesn't like that. Is there a way for me to tell my variable that it should be a big integer instead of int? -Jim -- Jim Steil VP of Application Development CustomCall Data Systems (608) 274-3009 x286 -------------- next part -------------- An HTML attachment was scrubbed... URL: From desparn at wtf.com Mon Dec 12 12:58:02 2005 From: desparn at wtf.com (Rick Wotnaz) Date: Mon, 12 Dec 2005 12:58:02 -0500 Subject: Using XML w/ Python... References: <1134277924.398538.296150@g49g2000cwa.googlegroups.com> <1134333951.509929.5490@g49g2000cwa.googlegroups.com> <1134342781.330978.303580@g47g2000cwa.googlegroups.com> <1134347722.851087.169300@g49g2000cwa.googlegroups.com> <1134350340.363450.80270@g43g2000cwa.googlegroups.com> <1134359242.311767.12510@z14g2000cwz.googlegroups.com> <1134363744.268651.221840@g47g2000cwa.googlegroups.com> <1134366913.890682.123960@z14g2000cwz.googlegroups.com> <1134369549.926561.113940@f14g2000cwb.googlegroups.com> <1134370144.530537.146790@f14g2000cwb.googlegroups.com> <1134370395.530700.281190@g47g2000cwa.googlegroups.com> <1134372862.503403.26240@g14g2000cwa.googlegroups.com> <1134407093.043211.114640@g49g2000cwa.googlegroups.com> Message-ID: uche.ogbuji at gmail.com wrote in news:1134407093.043211.114640 at g49g2000cwa.googlegroups.com: > """ > Not wanting to hijack this thread, but it got me interested in > installing amara. I downloaded > Amara-allinone-1.0.win32-py2.4.exe and ran it. It professed that > the installation directory was to be > D:\Python24\Lib\site-packages\ ... but it placed FT and amara in > D: \Python24\Python24\Lib\site-packages . Possibly the installer > is part of the problem here? > """ > > That's really good to know. Someone else builds the Windows > installer package for Amara (I'm a near Windows illiterate), but > I definitely want to help be sure the installer works properly. > In fact, your message rings a bell that this specifically came > up before: > > http://lists.fourthought.com/pipermail/4suite/2005-November/00761 > 0.html > > I'll have to ask some of the Windows gurus on the 4Suite list > whether they know why this might be. Do you mind if I cc you on > those messages, so that you can perhaps try out any solutions we > come up with? > > Thanks. > I'd be delighted to run them. Bring 'em on! If this is useful information: the opening screen of the installer correctly shows D:\Python24\ as my Python directory, and correctly shows (on my computer): D:\Python24\Lib\site-packages\ as the Installation Directory. The file names as it installs are of the form "Python24\Lib\site-packages\...", which to me hints that it takes that generated name and appends it to the Python directory to produce the actual file path it then uses. -- rzed From infidel02 at lycos.com Tue Dec 20 17:01:53 2005 From: infidel02 at lycos.com (infidel02 at lycos.com) Date: 20 Dec 2005 14:01:53 -0800 Subject: Wed Development - Dynamically Generated News Index In-Reply-To: References: <1134937675.084361.20770@g49g2000cwa.googlegroups.com> Message-ID: <1135114497.939788.139380@g14g2000cwa.googlegroups.com> Hi Jean-Paul, The truth of the matter is that I was hoping that this could be accomplished using pure CGI. I am considering wether I need to learn these new frameworks, but I am in somewhat of a hurry. Also I have this problem with this simple test script that I have written. It pulls the infromation from the database correctly, but is printing out the html tags in the browser, not sure what is wrong: Script #!/usr/bin/python # import MySQL module import MySQLdb, cgi # connect db = MySQLdb.connect(host="localhost", user="nancy", passwd="intentions", db="ardDB") # create a cursor cursor = db.cursor() # execute SQL statement cursor.execute("SELECT * FROM news where storyDATE < '2005-10-1';") # get the resultset as a tuple result = cursor.fetchall() db.close() print """ Content-Type: text/html\n\n DB Test</tile> </head> <body> """ # iterate through resultset for record in result: print """<h1>%s</h1> <p>%s</p> <p>%s<p> """ %(record[1],record[2],record[3]) print """ </body> </html> """ Results: <html> <head> <title>DB Test</tile> </head> <body> <h1>Heading 4</h1> <p>Body 4</p> <p>2005-09-01<p> <h1>Heading 5</h1> <p>Body 5</p> <p>2005-09-10<p> <h1>Heading 6</h1> <p>Body 6</p> <p>2005-09-12<p> </body> </html> From limodou at gmail.com Mon Dec 26 09:42:24 2005 From: limodou at gmail.com (limodou) Date: Mon, 26 Dec 2005 22:42:24 +0800 Subject: Fwd: oddness question for threading in pyw In-Reply-To: <505f13c0512252306v40e66138m@mail.gmail.com> References: <505f13c0512252306v40e66138m@mail.gmail.com> Message-ID: <505f13c0512260642r1181b297x@mail.gmail.com> I forward this letter from wxPython maillist, because it seems that no one answers my question, so I want to ask somebody for help in here. Thanks. ---------- Forwarded message ---------- From: limodou <limodou at gmail.com> Date: 2005-12-26 ??3:06 Subject: oddness question for threading in pyw To: wxpython-users at lists.wxwidgets.org When I'm dealing theading program in wxPython, I find an oddness question. If the python filename is '.pyw' suffixed, and the thread is set as daemon, when I double clicked it to run, the thread object seems be blocked till I exit the program. But if the thread is not set as daemon, every thing is ok. But if the python filename is not '.pyw' suffixed, but '.py', the question is disappeared. Can anybody explain it for me, and how to resolved it? Need I change the deamon to false? There is a testing program, which I modified from the wxPython Threading Demo. import random import time import thread import threading import wx import wx.lib.newevent #---------------------------------------------------------------------- # This creates a new Event class and a EVT binder function (UpdateBarEvent, EVT_UPDATE_BARGRAPH) = wx.lib.newevent.NewEvent() #---------------------------------------------------------------------- class CalcBarThread(threading.Thread): def __init__(self, win, barNum, val): threading.Thread.__init__(self, name="CalcBarThread") self.win = win self.barNum = barNum self.val = val self.keepGoing = self.running = True def Start(self): self.keepGoing = self.running = True thread.start_new_thread(self.Run, ()) def Stop(self): self.keepGoing = False def IsRunning(self): return self.running def run(self): while self.keepGoing: evt = UpdateBarEvent(barNum = self.barNum, value = int(self.val)) wx.PostEvent(self.win, evt) sleeptime = (random.random() * 2) + 0.5 time.sleep(sleeptime/4) sleeptime = sleeptime * 5 if int(random.random() * 2): self.val = self.val + sleeptime else: self.val = self.val - sleeptime if self.val < 0: self.val = 0 if self.val > 300: self.val = 300 self.running = False #---------------------------------------------------------------------- class GraphWindow(wx.Window): def __init__(self, parent, labels): wx.Window.__init__(self, parent, -1) self.values = [] for label in labels: self.values.append((label, 0)) font = wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD) self.SetFont(font) self.colors = [ wx.RED, wx.GREEN, wx.BLUE, wx.CYAN, "Yellow", "Navy" ] self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) self.Bind(wx.EVT_PAINT, self.OnPaint) def SetValue(self, index, value): assert index < len(self.values) cur = self.values[index] self.values[index:index+1] = [(cur[0], value)] def SetFont(self, font): wx.Window.SetFont(self, font) wmax = hmax = 0 for label, val in self.values: w,h = self.GetTextExtent(label) if w > wmax: wmax = w if h > hmax: hmax = h self.linePos = wmax + 10 self.barHeight = hmax def GetBestHeight(self): return 2 * (self.barHeight + 1) * len(self.values) def Draw(self, dc, size): dc.SetFont(self.GetFont()) dc.SetTextForeground(wx.BLUE) dc.SetBackground(wx.Brush(self.GetBackgroundColour())) dc.Clear() dc.SetPen(wx.Pen(wx.BLACK, 3, wx.SOLID)) dc.DrawLine(self.linePos, 0, self.linePos, size.height-10) bh = ypos = self.barHeight for x in range(len(self.values)): label, val = self.values[x] dc.DrawText(label, 5, ypos) if val: color = self.colors[ x % len(self.colors) ] dc.SetPen(wx.Pen(color)) dc.SetBrush(wx.Brush(color)) dc.DrawRectangle(self.linePos+3, ypos, val, bh) ypos = ypos + 2*bh if ypos > size[1]-10: break def OnPaint(self, evt): width, height = size =self.GetSize() bmp = wx.EmptyBitmap(width, height) dc = wx.MemoryDC() dc.SelectObject(bmp) self.Draw(dc, size) wdc = wx.PaintDC(self) wdc.BeginDrawing() wdc.Blit(0,0, size[0], size[1], dc, 0,0) wdc.EndDrawing() dc.SelectObject(wx.NullBitmap) def OnEraseBackground(self, evt): pass #---------------------------------------------------------------------- class TestFrame(wx.Frame): def __init__(self, parent, log): wx.Frame.__init__(self, parent, -1, "Thread Test", size=(450,300)) self.log = log #self.CenterOnParent() panel = wx.Panel(self, -1) panel.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)) wx.StaticText(panel, -1, "This demo shows multiple threads interacting with this\n" "window by sending events to it, one thread for each bar.", (5,5)) panel.Fit() self.graph = GraphWindow(self, ['Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven']) self.graph.SetSize((450, self.graph.GetBestHeight())) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(panel, 0, wx.EXPAND) sizer.Add(self.graph, 1, wx.EXPAND) self.SetSizer(sizer) self.SetAutoLayout(True) sizer.Fit(self) self.Bind(EVT_UPDATE_BARGRAPH, self.OnUpdate) self.threads = [] self.threads.append(CalcBarThread(self, 0, 50)) self.threads.append(CalcBarThread(self, 1, 75)) self.threads.append(CalcBarThread(self, 2, 100)) self.threads.append(CalcBarThread(self, 3, 150)) self.threads.append(CalcBarThread(self, 4, 225)) self.threads.append(CalcBarThread(self, 5, 300)) self.threads.append(CalcBarThread(self, 6, 250)) self.threads.append(CalcBarThread(self, 7, 175)) for t in self.threads: # t.setDeamon(True) t.start() self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) def OnUpdate(self, evt): self.graph.SetValue(evt.barNum, evt.value) self.graph.Refresh(False) def OnCloseWindow(self, evt): busy = wx.BusyInfo("One moment please, waiting for threads to die...") wx.Yield() for t in self.threads: t.Stop() running = 1 while running: running = 0 for t in self.threads: running = running + t.IsRunning() time.sleep(0.1) self.Destroy() #--------------------------------------------------------------------------- class wxApp(wx.App): def OnInit(self): frame = TestFrame(None, None) frame.Show() self.SetTopWindow(frame) return True if __name__ == '__main__': app = wxApp(0) app.MainLoop() Please note that if I change the code: for t in self.threads: # t.setDeamon(True) t.start() to for t in self.threads: t.setDeamon(True) t.start() you will see the problem. Thanks a lot. -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit From mwm at mired.org Fri Dec 2 20:10:41 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 02 Dec 2005 20:10:41 -0500 Subject: Setting PYTHONPATH from Makefile References: <1133533711.665760.61810@f14g2000cwb.googlegroups.com> <86mzjjow8f.fsf@bhuda.mired.org> <mailman.1525.1133571277.18701.python-list@python.org> Message-ID: <8664q7oui6.fsf@bhuda.mired.org> Inyeol Lee <inyeol.lee at siliconimage.com> writes: > On Fri, Dec 02, 2005 at 07:33:20PM -0500, Mike Meyer wrote: >> > The problem is that myscript.py and some modules that myscript.py >> > imports are not in the current directory, but in another place in the >> > filesystem, say, /path/to/stuff. If this was a tcsh script, I would >> > just do: >> > >> > setenv PYTHONPATH /path/to/stuff >> > python myscript.py > How about using python -m? > Assuming Make uses Bourne shell, > > %.abc: %.def > PYTHONPATH=/path/to/stuff:/path/to/another python -m myscript That will break __name__ (at least with 2.4.2). Whether or not it matters will depend on the script. <mike -- Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From roy at panix.com Wed Dec 28 09:28:18 2005 From: roy at panix.com (Roy Smith) Date: Wed, 28 Dec 2005 09:28:18 -0500 Subject: predicting function calls? References: <dot5nu$qdp$1@panix2.panix.com> <864q4tdbfe.fsf@bhuda.mired.org> Message-ID: <roy-D372E8.09281828122005@reader1.panix.com> In article <864q4tdbfe.fsf at bhuda.mired.org>, Mike Meyer <mwm at mired.org> wrote: > Fnorb (a pure-Python CORBA orb) dealt with this by not allowing > attributes per se. Instead, it provided _get_AttributeName and > _set_AttributeName as appropriate for each attribute in the IDL. Doing > this means that *everything* you hand back from __getattr__ is going > to be a callable, and presumably called at some point. That's exactly what the low-level C/C++ API does in the system I'm working with. It is, unfortunately, not the interface that's exposed by the serial protocol. From steve at REMOVETHIScyber.com.au Mon Dec 12 08:17:13 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Tue, 13 Dec 2005 00:17:13 +1100 Subject: Another newbie question References: <mailman.1825.1134012125.18701.python-list@python.org> <863bl4xk11.fsf@bhuda.mired.org> <pan.2005.12.08.21.51.01.122810@REMOVETHIScyber.com.au> <7xd5k71avc.fsf@ruckus.brouhaha.com> <4398D289.9050902@REMOVEMEcyber.com.au> <86vexzvy86.fsf@bhuda.mired.org> <pan.2005.12.10.05.32.30.468540@REMOVETHIScyber.com.au> <8664pxv523.fsf@bhuda.mired.org> <pan.2005.12.10.13.52.41.727175@REMOVETHIScyber.com.au> <slrndplu2r.bru.apardon@rcpc42.vub.ac.be> <pan.2005.12.11.06.08.33.747614@REMOVETHIScyber.com.au> <slrndpqq9u.gl6.apardon@rcpc42.vub.ac.be> Message-ID: <pan.2005.12.12.13.17.12.848692@REMOVETHIScyber.com.au> On Mon, 12 Dec 2005 12:12:46 +0000, Antoon Pardon wrote: >> And maybe it isn't a Coordinate class at all, hmmm? > > Indeed it isn't. It is usually a Point class. > >> An ordinary, Cartesian, real-valued Coordinate is a pair of ordinates, an >> X and Y ordinates. That's what it *is* -- a coordinate class without X and >> Y ordinates isn't a coordinate class, regardless of how they are >> implemented (via properties, named attributes, or a whole bucketful of >> helper functions). > > That is why a coordinate class is a bad idea. It mentions an > implementation in what should be an abstract idea like a 2D point. > > In that case if you find out that you are manipulating your objects > in ways, for which polar coordinates are better, you can transparantly > change the implementation. That's a great idea Antoon, but you don't go far enough. Why limit yourself to something as concrete as a pair of floats? What we actually need is an even more abstract class, one which can hold an arbitrary number of ordinates, not just two. And why limit ourselves to floats? What if the user decides that he wants to specify ordinates as written English numbers like the Morse Code for "thirty-seven point three four", coded in base64? For that matter, now that we have an arbitrary number of ordinates, why limit yourself to list implementation? Perhaps a better implementation is a tree structure, or an orchard, or some sort of mapping? Or some hybrid of all three. And the methods, well, the methods. It is so limiting to be forced into one specific API, with names like instance.move(), rotate(), reflect() and so forth. What if I should change my mind, and decide what I really need is a message-passing model instead? We better write some more code isolating the methods from the user, making the class even more abstract again, just in case we should ever choose to change those methods' interface. Heaven forbid that we should actually decide on a model for our class, ever. Sure, we'll end up having to implement a Turing-complete programming language as our class, but I think we'll all agree that that cost is a small price to pay for something which is sufficiently abstract. -- Steven From michaelschneider at fuse.net Wed Dec 7 11:03:09 2005 From: michaelschneider at fuse.net (Michael Schneider) Date: Wed, 07 Dec 2005 11:03:09 -0500 Subject: How to ping in Python? In-Reply-To: <43967F92.7070501@designaproduct.biz> References: <mailman.1615.1133789266.18701.python-list@python.org> <4396FB2F.1090103@fuse.net> <43967F92.7070501@designaproduct.biz> Message-ID: <439707BD.7020104@fuse.net> Les, I only ping internal machines. You are right about shutting down ports. When we disable telent, we also disable ping. Many people may not though, good luck, Mike Laszlo Zsolt Nagy wrote: > Michael Schneider wrote: > >> I telnet to port 13 (returns time) >> > The problem is that most modern up-to-date servers use firewalls. They > only open the ports that are absolutely necessary. Usually the time > service is part of inetd, which is disabled by default, on most of the > servers. PING ICMP may work, but sometimes it does not either. In the > worst case, all port are closed and you have no way to tell if there > is a computer or not. > > Can you tell more about what kind of server do you need to "ping"? > > Example: if you need to know if a web server is alive, you should > connect to port 80 (http). If the connection was successful, you can > close the connection immeditelly. You can expect a HTTP server to open > the HTTP port, but all other ports may be closed. > > Les > > > > -- The greatest performance improvement occurs on the transition of from the non-working state to the working state. From rupole at hotmail.com Tue Dec 13 19:54:42 2005 From: rupole at hotmail.com (Roger Upole) Date: Tue, 13 Dec 2005 19:54:42 -0500 Subject: How can I load python script into Html ?? References: <1134508651.661786.120380@g43g2000cwa.googlegroups.com> <1134512146.581066.274760@o13g2000cwo.googlegroups.com> Message-ID: <1134521934_89515@spool6-east.superfeed.net> Mozilla is growing python support: http://weblogs.mozillazine.org/roadmap/archives/008865.html Using Pywin32, Python can also be registered as an ActiveScript language so that it can be used in Internet Explorer. Roger -- "Ask the ToeCutter - HE knows who I am !" "Steve M" <sjmaster at gmail.com> wrote: > Man, I don't even know where to start. There is no way this will work > if you don't have a web browser that can interpret Python. I don't know > of one, and I don't think anybody wants one because using a browser > that would execute arbitrary Python code provided by the server would > be an obscene security mistake. > > Javascript is specifically designed for client-side scripting, whereas > Python is not. You'll have to re-think what you wanted to accomplish, > and if it was just "I prefer coding in Python to coding in Javascript" > then you're basically SOL. > > Hope this helps! > ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =---- From JMailone at gmail.com Sun Dec 11 03:33:40 2005 From: JMailone at gmail.com (Jay) Date: 11 Dec 2005 00:33:40 -0800 Subject: Using XML w/ Python... In-Reply-To: <1134281747.980982.300220@g43g2000cwa.googlegroups.com> References: <1134277924.398538.296150@g49g2000cwa.googlegroups.com> <1134281747.980982.300220@g43g2000cwa.googlegroups.com> Message-ID: <1134290020.154477.261240@z14g2000cwz.googlegroups.com> Yes i know, i did check out a couple but i could never understand it. They were confusing for me and i wasnt hoping for a full typed tutorial, just like some help with excactly wat im trying to do, not the whole module... but watever, Thx alot for the feedbak. From d.kucinskas at gmail.com Fri Dec 30 09:41:48 2005 From: d.kucinskas at gmail.com (=?ISO-8859-2?Q?Darius_Ku=E8inskas?=) Date: Fri, 30 Dec 2005 16:41:48 +0200 Subject: python code optimization Message-ID: <582c100f0512300641k10539b73mab2a70965e3d789@mail.gmail.com> Hi, I know that sometimes optimization is not good idea. So I want to know what you think about this one: we have code like this: tables = [] for i in ... : tables.extend(...) we optimize code like this: tables = [] pfTablesExtend = tables.extend for i in ... : pfTablesExtend(...) I what to know is this bad idea? Say you opinion about that! -- Best Regards Darius Ku?inskas -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-list/attachments/20051230/f3dd85a0/attachment.html> From fredrik at pythonware.com Wed Dec 21 11:56:24 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 21 Dec 2005 17:56:24 +0100 Subject: Resizing of PIL images References: <1135181413.820493.124320@g14g2000cwa.googlegroups.com> <doc02m$k22$1@sea.gmane.org> Message-ID: <doc1fq$plg$1@sea.gmane.org> Peter Hansen wrote: > See the docs on transform(). From the sounds of it, if resize() won't > stretch something (it's own docs don't make that clear) "resize" resizes the image to the given size. "thumbnail" (which is an in-place operation) doesn't; it creates an image no larger than the given size. </F> From svensson_ove at hotmail.com Mon Dec 19 07:51:48 2005 From: svensson_ove at hotmail.com (Ove Svensson) Date: 19 Dec 2005 13:51:48 +0100 Subject: canceling and joining threads References: <1134992792.503678.149200@g44g2000cwa.googlegroups.com> Message-ID: <eczek499rmj.fsf@ericsson.com> "sir_alex" <chimaera29 at libero.it> writes: > Hello everybody! I have a couple of questions about threads: the first > is, is there the possibility to cancel a thread while it is executing > (like the C function thread_cancel), for implementing something like an > "abort" button? As far as I know, python thread does not support thread cancellation, and that is probably a good thing. Thread cancellation can be _very_ difficult to get right. If not done right, you end up with resource leaks and/or deadlock. It is much better to use some explicit synchronization mechanism to tell a thread that it shall terminate itself. You could, for example, use a state variable, a mutex and a condition variable. > And the second is, i have a GUI in which there's a > button that launches a thread implemented using the threading module > (creating a class which inherits from threading.Thread and overriding > __init__ and run), i chose to use threads to avoid the problem of > freezing my windows, but after i call classobject.start() this happens: > if i then call classobject.join(), then the button is freezed, because > now the button waits the end of the thread, And that is only to be expected. Join is not a mechanism for terminating threads, it us a mechanism for _blocking__ until the designated thread terminates. > if i don't make this call > the button releases itself (that is a good behavior) but the thread > freezes until i give a ctrl-c in the console from which i launched my > app. So, how can i make my button release while the thread is > executing? (my GUI is implemented in GTK and i use libglade) (sorry for > the length of this post...) When the button is being pressed, use some explicit synchronization to inform the thread that it shall terminate. From qwweeeit at yahoo.it Wed Dec 14 05:07:42 2005 From: qwweeeit at yahoo.it (qwweeeit) Date: 14 Dec 2005 02:07:42 -0800 Subject: List text files showing LFs and expanded tabs (was: Colorize expanded tabs) References: <1134392482.563110.181660@g14g2000cwa.googlegroups.com> <1134405983.087180.321680@o13g2000cwo.googlegroups.com> Message-ID: <1134554862.856803.189970@g14g2000cwa.googlegroups.com> Hi Gene, thank you for your reply, also if my post was meant to be only an exercise to apply color to lfs and expanded tabs in listing files and not to apply it to an editor. However your comment has directed me to consider more deeply other editors (I use kwrite). I am inclined to change to vim but I haven't found the vim module for python. By the way I'm not sure that vim can display lfs and expanded tabs in color! Bye. From callmebill at gmail.com Thu Dec 8 20:21:43 2005 From: callmebill at gmail.com (callmebill at gmail.com) Date: 8 Dec 2005 17:21:43 -0800 Subject: Dynamically add Class to Modules In-Reply-To: <mailman.1869.1134080270.18701.python-list@python.org> References: <1134078141.188649.84560@z14g2000cwz.googlegroups.com> <mailman.1869.1134080270.18701.python-list@python.org> Message-ID: <1134091303.752349.210810@z14g2000cwz.googlegroups.com> Hi Michael... It didn't seem to take. Here is some of the actual code: [[[[[[[[[[ from the runner ]]]]]]]]]]]]] print "+++++++++++++++++++++++++++++++++++++++" print "::Dir before exec:",dir(testModule) import CodeGenBase if hasattr( testModule,"TheTestCode" ): print testModule.TheTestCode %(testModule.TheTestName, testModule.TheTestName ) exec testModule.TheTestCode %(testModule.TheTestName, testModule.TheTestName ) else: print "PASSING" print "::Dir after exec:",dir( testModule ) print "+++++++++++++++++++++++++++++++++++++++" [[[[[[[[[[[[[[[[[[[ from the test file ]]]]]]]]]]]]]]]]]]]] TheTestName = "FOO_TEST_NAME" TheTestCode = \ """class %sTestCase( CodeGenBase.CodeGenBase ): def __init__( self,methodName ): CodeGenBase.CodeGenBase.__init__( self,methodName ) def test%s(self): self.SetupAndRunConfigTxtTests() """ .....It doesn't look like the new class is sticking. Below is some output: +++++++++++++++++++++++++++++++++++++++ ::Dir before exec: ['BuildRunBase', 'CodeGenBase', 'ConfigHelper', 'TheTestCode' , 'TheTestName', '__builtins__', '__doc__', '__file__', '__name__', 'isSupported ', 'os', 'sys'] class FOO_TEST_NAMETestCase( CodeGenBase.CodeGenBase ): def __init__( self,methodName ): CodeGenBase.CodeGenBase.__init__( self,methodName ) def testFOO_TEST_NAME(self): self.SetupAndRunConfigTxtTests() ::Dir after exec: ['BuildRunBase', 'CodeGenBase', 'ConfigHelper', 'TheTestCode', 'TheTestName', '__builtins__', '__doc__', '__file__', '__name__', 'isSupported' , 'os', 'sys'] +++++++++++++++++++++++++++++++++++++++ Hopefully I just missed something obvious, which happens all too often. Any ideas? Thanks again for the help! From bcully at gmail.com Thu Dec 15 10:55:15 2005 From: bcully at gmail.com (Brian Cully) Date: 15 Dec 2005 07:55:15 -0800 Subject: Why and how "there is only one way to do something"? In-Reply-To: <1134655866.972456.119460@f14g2000cwb.googlegroups.com> References: <1134646944.453716.75850@o13g2000cwo.googlegroups.com> <1134649479.444890.193020@z14g2000cwz.googlegroups.com> <1134649959.077878.151430@g47g2000cwa.googlegroups.com> <mailman.2139.1134650874.18701.python-list@python.org> <1134652082.682017.284470@g47g2000cwa.googlegroups.com> <mailman.2144.1134654716.18701.python-list@python.org> <1134655866.972456.119460@f14g2000cwb.googlegroups.com> Message-ID: <1134662115.808820.278540@g47g2000cwa.googlegroups.com> bonono at gmail.com wrote: > C-programmer learning python : > > Hi, where is condition ? true : false > > someone prefer the if/else statement type: > > Can't you see that the following is much more readable, stupid(well not > the exact word but tone in such a way like words of messy or elegant > etc.) > > if condition: > true > else: > false Except that the latter isn't an expression, and thus can't be used inline. Where you can do: somevar = condition ? true : false You have to do, instead: if condition: somevar = true else: somevar = false It may not seem like a big deal to you, but this approach has a number of problems, depending on what you're doing. When you're using the ternary operator you avoid temporary variables, and if you use it a lot, that's much less that you have to keep track of. It's embeddable in other arbitrary code, so you can move it around as you need to, or just keep the morass of side-effects down. Readability isn't just line-by-line, but a whole work. if/else may work well most of the time, but sometimes it's ugly, and even though it's obvious, it doesn't necessarily make your code easier to read. From deets at web.de Mon Dec 5 06:32:11 2005 From: deets at web.de (Diez B. Roggisch) Date: 5 Dec 2005 03:32:11 -0800 Subject: Creating referenceable objects from XML In-Reply-To: <mailman.1593.1133756228.18701.python-list@python.org> References: <mailman.9303.1133755013.18700.python-list@python.org> <mailman.1593.1133756228.18701.python-list@python.org> Message-ID: <1133782331.071433.256750@f14g2000cwb.googlegroups.com> Michael Williams wrote: > I'm looking for a quality Python XML implementation. All of the DOM > and SAX implementations I've come across so far are rather > convoluted. Welcome to the wonderful world of XML. > I need it to somehow convert my XML to intuitively referenceable > object. Any ideas? I could even do it myself if I knew the > mechanism by which python classes do this (create variables on the fly). You've been given the advice to use ElementTree - I can only second that. But if for whatever reason you do want to do it yourself (or for future use), the getattr/setattr functions are what you are looking for. Look them up in TFM. Regards, Diez From electronicmailfixtosend at telus.net Fri Dec 16 01:21:05 2005 From: electronicmailfixtosend at telus.net (Bock) Date: Fri, 16 Dec 2005 06:21:05 GMT Subject: Can Python write foreign characters to the console? Message-ID: <43A25DB9.5313E3B2@telus.net> I was just told about Python. My searching and reading over the net I was able to learn that Python can handle "foreign" characters via Unicodes. Can or does Python write unicode to the screen? For example, in c++ cout >> "Hello World." would send this string to the screen/monitor. I want to find a programming language that can write German ???? as screen output? Most programming languages/operating systems in North America limit one to the 127 characters of ascii. Thank you for any explanation/direction. From mwm at mired.org Fri Dec 23 16:15:41 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 23 Dec 2005 16:15:41 -0500 Subject: Herds of cats References: <43a939e3$0$23986$626a14ce@news.free.fr> <1135174003.737464.211650@g43g2000cwa.googlegroups.com> <1135192878.129577.257820@g49g2000cwa.googlegroups.com> <1135232795.170575.184780@g14g2000cwa.googlegroups.com> <1135233297.257898.180320@f14g2000cwb.googlegroups.com> <mailman.2425.1135244426.18701.python-list@python.org> <1135258709.692444.238580@g49g2000cwa.googlegroups.com> <1135260688.041530.133900@f14g2000cwb.googlegroups.com> <1h7yryq.1bmmgzylnnhkN%aleax@mail.comcast.net> <1135273624.592241.180820@g49g2000cwa.googlegroups.com> <dvar73-pub.ln1@lairds.us> <1135338104.410096.247570@g14g2000cwa.googlegroups.com> <1h80kaj.9vcvv2xzlm5cN%aleax@mail.comcast.net> <mailman.2494.1135357788.18701.python-list@python.org> Message-ID: <86psnna51e.fsf@bhuda.mired.org> Steve Holden <steve at holdenweb.com> writes: > Alex Martelli wrote: >> Not a bad point at all, although perhaps not entirely congruent to >> open >> source: hiring key developers has always been a possibility (net of >> non-compete agreements, but I'm told California doesn't like those). California places pretty strict limits on non-compete agreements. I was at Ingres when their parent company - ASK - got bought by CA. CA required people choosing to leave the company to sign an agreement that included *their* standard non-compete clause before getting the separation cash. Enough people left that found this clause irritating that it got take to multiple lawyers. Every last one of them declared it unenforceable in CA. > The essential difference, it seems to me, is that buying the company > gets you control over the company's proprietary technologies, whereas > hiring the developer only gets you access to the development skills of > the people who've been involved open source developments. But it's not at all clear which of these is the more desirable outcome. CA bought ASK to get control of Ingres, which their Unicenter product used as a database. The *entire* server software development group left, meaning CA had all the sources and technologies, but none of the talent that created them. We called this the $300 million source license. CA pretty clearly got screwed on this deal. They have since open-sourced the Ingres product. <mike -- Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From martin at v.loewis.de Fri Dec 16 14:09:39 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 16 Dec 2005 20:09:39 +0100 Subject: python24.dll and encodings ? In-Reply-To: <d5jxa28r.fsf@python.net> References: <2eOdnc4wJOpWIQreRVn-tw@comcast.com> <4397f8f4$0$10575$9b622d9e@news.freenet.de> <yZydnaYy_rnC8QLeRVn-vw@comcast.com> <43a07401$0$23363$9b622d9e@news.freenet.de> <vexrwi6d.fsf@python.net> <YamdnTWobvTVdjzenZ2dnUVZ_tOdnZ2d@comcast.com> <d5jxa28r.fsf@python.net> Message-ID: <43A310F3.5020608@v.loewis.de> Thomas Heller wrote: > Technically, as far as py2exe is concerned, it would be nice if the zlib > module was a builtin module because it would be easier to bootstrap the > executable - for obvious reasons the zlib module cannot be loaded from a > (compressed) zipfile. Unfortunately, this collides with Martin's > current policy to exclude extensions that need third party source code > from the python dll. That could change, of course. I personally would have no problems requiring that zlib is available on the build machine - I always have it available. I would expect that others using the subversion trunk on Windows would object, though. Perhaps it might be possible to create some sort of compile time condition, ideally automatically detected. In any case, a PEP would have to answer these issues. Regards, Martin From sdb1031 at gmail.com Sat Dec 3 22:16:10 2005 From: sdb1031 at gmail.com (sdb1031 at gmail.com) Date: 3 Dec 2005 19:16:10 -0800 Subject: How to execute an EXE via os.system() with spaces in the directory name? Message-ID: <1133666170.048074.321150@z14g2000cwz.googlegroups.com> I am trying to run an exe within a python script, but I'm having trouble with spaces in the directory name. The following example will display the usage statement of the program, so I know that the space in the path to the exe is being handled correctly and that the program was executed. CMD= r'"C:\program files\some directory\engine\theexe.exe"' os.system(CMD) But the required argument for the exe require a path to a file to be specified. When I try to run the following, os.system(CMD2) CMD2= r'"C:\program files\some directory\engine\theexe.exe" "C:\program files\some directory\engine\file.txt"' I get this error: Unable to open file C:\Program So, it looks to me like the space in the path for the argument is causing it to fail. Does anyone have any suggestions that could help me out? Thanks, Steve From saint.infidel at gmail.com Fri Dec 2 11:56:49 2005 From: saint.infidel at gmail.com (infidel) Date: 2 Dec 2005 08:56:49 -0800 Subject: Why my modification of source file doesn't take effect when debugging? In-Reply-To: <1133533013.168498.193580@o13g2000cwo.googlegroups.com> References: <1133533013.168498.193580@o13g2000cwo.googlegroups.com> Message-ID: <1133542609.889493.136970@g14g2000cwa.googlegroups.com> > I'm using the Windows version of Python and IDLE. When I debug my .py > file, my modification to the .py file does not seem to take effect > unless I restart IDLE. Saving the file and re-importing it doesn't help > either. Where's the problem? "import" only reads the file the first time it's called. Every import call after that looks up the module in memory. This is to prevent circular dependencies between modules from creating infinite loops. You need to use the reload() function: >>> import foo #change the contents of foo >>> foo = reload(foo) From donn at drizzle.com Sat Dec 3 00:49:02 2005 From: donn at drizzle.com (Donn Cave) Date: Sat, 03 Dec 2005 05:49:02 -0000 Subject: General question about Python design goals References: <dmdlhj$87b$1@online.de> <mailman.1272.1133169959.18701.python-list@python.org> <dmg1rt$kqp$1@online.de> <86k6estfkd.fsf@bhuda.mired.org> <7xu0du64zo.fsf@ruckus.brouhaha.com> <86psoiodat.fsf@bhuda.mired.org> <7xhd9u63bv.fsf@ruckus.brouhaha.com> <1133333864.276803.147250@g49g2000cwa.googlegroups.com> <dml4ba$lu0$1@online.de> <1133402240.754943.175200@o13g2000cwo.googlegroups.com> <1133421224.376658@jetspin.drizzle.com> <86k6epl12q.fsf@bhuda.mired.org> <donn-F7BEBD.12463501122005@gnus01.u.washington.edu> <861x0vouap.fsf@bhuda.mired.org> Message-ID: <1133588941.793601@jetspin.drizzle.com> Quoth Mike Meyer <mwm at mired.org>: | Donn Cave <donn at u.washington.edu> writes: ... |> For me, conceptually, if an object can't be accessed |> sequentially, then it can't be mapped to a sequence. | | So you're saying that for should implicitly invoke list (or maybe | iter) on any object that it's passed that's not a list or iterator? Not really saying anything so concrete about it -- doesn't make any difference to me how it works, just saying that all these things come together. Convert to list, iterate, for. They're conceptually not just related, but bound together. |> Anyway, it seems to me that in the end this is about |> that balance between practicality and purity. Maybe |> it's more like tuples have a primary intended purpose, |> and some support for other applications. Not white, |> but not pure black either. | | If you do that, you've just weakened the case for not having count | etc. as methods of tuples. | | It really is the dichotomy of "tuples aren't meant to be sequences so | they don't have ..." versus being able to access them sequentially | that gets me. That just doesn't seem right. The case is weakened only if we have been pretending it was really strong. I guess this may be why this issue drives certain people crazy. There's a case for "don't have", but it isn't air-tight, so what do we do? Well, that's the one thing I really like about the winter holiday season -- some particularly flavorful ales come out of the local micro-breweries around this time of year, just in time to ease my worries about tuples. Donn Cave, donn at drizzle.com From samgurung at gmail.com Fri Dec 16 03:53:18 2005 From: samgurung at gmail.com (linuxfreak) Date: 16 Dec 2005 00:53:18 -0800 Subject: Python IDE Message-ID: <1134723197.985536.212950@g14g2000cwa.googlegroups.com> Which is a better python IDE SPE or WingIDE in terms of features From fredrik at pythonware.com Wed Dec 14 12:57:41 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 14 Dec 2005 18:57:41 +0100 Subject: Python C/API - *arg,**kwds variable argumnents References: <1134550072.264022.251540@g44g2000cwa.googlegroups.com> Message-ID: <dnpmen$9d$1@sea.gmane.org> mdcb808 at gmail.com wrote: > I am writing a C extension with python 2.3.5 and need constructs > similar to python > func(*args, **kwds) > What's a neat way to do that? static PyObject* myfunc(PyObject* self, PyObject* args, PyObject* kw) { ... args is a tuple, kw is a dictionary ... } static PyMethodDef _functions[] = { {"myfunc", (PyCFunction) myfunc, METH_VARARGS|METH_KEYWORDS}, {NULL, NULL} }; </F> From bonono at gmail.com Thu Dec 1 09:40:28 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 1 Dec 2005 06:40:28 -0800 Subject: [[x,f(x)] for x in list that maximizes f(x)] <--newbie help In-Reply-To: <1133444754.901618.265580@z14g2000cwz.googlegroups.com> References: <1133444754.901618.265580@z14g2000cwz.googlegroups.com> Message-ID: <1133448028.921314.181670@f14g2000cwb.googlegroups.com> Niels L Ellegaard wrote: > I just started learning python and I have been wondering. Is there a > short pythonic way to find the element, x, of a list, mylist, that > maximizes an expression f(x). > > In other words I am looking for a short version of the following: > > pair=[mylist[0],f(mylist[0])] > for x in mylist[1:]: > if f(x) > pair[1]: > pair=[x,f(x)] this is already very short, what else you want? May be this : max(((f(x), x) for x in mylist)) That is first generate the (f(x),x) pairs then find the max one(first compare f(x) then x) From bonono at gmail.com Sat Dec 17 01:07:54 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 16 Dec 2005 22:07:54 -0800 Subject: Which Python web framework is most like Ruby on Rails? In-Reply-To: <867ja4txyn.fsf@bhuda.mired.org> References: <1134496403.011407.169930@g44g2000cwa.googlegroups.com> <1134497848.620585.259200@g44g2000cwa.googlegroups.com> <1134502590.154469.37760@g49g2000cwa.googlegroups.com> <1134503125.765106.239640@g14g2000cwa.googlegroups.com> <1h7j2gk.aktins1kknr40N%aleax@mail.comcast.net> <IY2dnQsUIMyesD3enZ2dnUVZ_sadnZ2d@comcast.com> <1134574436.740981.134140@z14g2000cwz.googlegroups.com> <861x0fgkn3.fsf@bhuda.mired.org> <1134697514.020118.74190@g44g2000cwa.googlegroups.com> <1h7mlg2.1j9mpknczvjz8N%aleax@mail.comcast.net> <mailman.2190.1134704340.18701.python-list@python.org> <1h7mnym.jixziycxvvvgN%aleax@mail.comcast.net> <86slstppaj.fsf@bhuda.mired.org> <1134737226.616118.271480@o13g2000cwo.googlegroups.com> <86psnwubam.fsf@bhuda.mired.org> <1134760743.300790.269400@g43g2000cwa.googlegroups.com> <867ja4txyn.fsf@bhuda.mired.org> Message-ID: <1134799674.264460.200410@z14g2000cwz.googlegroups.com> Mike Meyer wrote: > It's conceivable that a change might make Python more popular and also > detract from the language in some way. For a ridiculous example, > making Python interpret Perl 6 would certainly make it more popular, > but I would argue that would seiously detract from the language. > why would one want python to interpret Perl 6 ? From 63q2o4i02 at sneakemail.com Wed Dec 7 13:51:54 2005 From: 63q2o4i02 at sneakemail.com (63q2o4i02 at sneakemail.com) Date: 7 Dec 2005 10:51:54 -0800 Subject: Binary representation of floating point numbers In-Reply-To: <439639db.350245786@news.oz.net> References: <1133896798.210432.179430@g43g2000cwa.googlegroups.com> <86hd9muefp.fsf@bhuda.mired.org> <1133907913.048728.23580@o13g2000cwo.googlegroups.com> <1133908651.917580.22440@g44g2000cwa.googlegroups.com> <11pc5ennlc0pd48@corp.supernews.com> <439639db.350245786@news.oz.net> Message-ID: <1133981514.276620.48800@g47g2000cwa.googlegroups.com> That looks pretty cool. I'll try it out. thanks Michael From aahz at pythoncraft.com Mon Dec 5 13:49:45 2005 From: aahz at pythoncraft.com (Aahz) Date: 5 Dec 2005 10:49:45 -0800 Subject: Bitching about the documentation... References: <mailman.1565.1133705473.18701.python-announce-list@python.org> <mailman.1628.1133798275.18701.python-list@python.org> <1133799969.284272.218830@z14g2000cwz.googlegroups.com> <mailman.1635.1133803625.18701.python-list@python.org> Message-ID: <dn2249$flf$1@panix2.panix.com> In article <mailman.1635.1133803625.18701.python-list at python.org>, <skip at pobox.com> wrote: > > Tim Peters? Read it no matter what the subject says. A-men! -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "Don't listen to schmucks on USENET when making legal decisions. Hire yourself a competent schmuck." --USENET schmuck (aka Robert Kern) From fuzzyman at gmail.com Thu Dec 1 03:46:05 2005 From: fuzzyman at gmail.com (Fuzzyman) Date: 1 Dec 2005 00:46:05 -0800 Subject: HTML parsing/scraping & python In-Reply-To: <mailman.1417.1133406042.18701.python-list@python.org> References: <mailman.1417.1133406042.18701.python-list@python.org> Message-ID: <1133426765.321856.179280@g44g2000cwa.googlegroups.com> The standard library module for fetching HTML is urllib2. The best module for scraping the HTML is BeautifulSoup. There is a project called mechanize, built by John Lee on top of urllib2 and other standard modules. It will emulate a browsers behaviour - including history, cookies, basic authentication, etc. There are several modules for automated form filling - FormEncode being one. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml From martin at v.loewis.de Sat Dec 3 06:51:27 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 03 Dec 2005 12:51:27 +0100 Subject: os.rename copies when old is in-use - is this deliberate? In-Reply-To: <513AB523-645D-43EC-9BB4-C6A21CBF4684@ihug.co.nz> References: <mailman.1530.1133602350.18701.python-list@python.org> <4391758e$0$26955$9b622d9e@news.freenet.de> <513AB523-645D-43EC-9BB4-C6A21CBF4684@ihug.co.nz> Message-ID: <439186BF.1080203@v.loewis.de> Tony Meyer wrote: > Thanks for that. In your opinion, would a documentation patch that > explained that this would occur on Windows (after the existing note > about the Windows rename not being atomic) be acceptable? In principle, yes. We cannot do that for every platform, of course, but it probably won't be necessary for any platform, either. > (The Windows platform C library for Python 2.4+ is in msvcrt71.dll, > right? Does that mean that behaviour will be consistent across Windows > versions, or could 9x/NT/XP/etc all behave differently?) The behaviour could be different in principle, yes. I found a KB article that says that MoveFile, on Windows CE 4.0, on a FAT file system, would move the file even if it was open. I'm actually also surprised by the behaviour - I would have expected that the failure to delete the file after the copy would cause an error, or that the attempt to open the file with FILE_SHARE_DELETE would cause an error right away. Somebody should investigate this with Sysinternal's filemon, to find out whether the MoveFile operation really succeeds. Perhaps there is a bug in the CRT, or in Python, also. Regards, Martin From fuzzyman at gmail.com Wed Dec 21 11:57:07 2005 From: fuzzyman at gmail.com (Fuzzyman) Date: 21 Dec 2005 08:57:07 -0800 Subject: Guido at Google In-Reply-To: <1h7wvw8.1of7z5vg23o7eN%aleax@mail.comcast.net> References: <43a939e3$0$23986$626a14ce@news.free.fr> <1135165473.419546.212040@g49g2000cwa.googlegroups.com> <1h7wvw8.1of7z5vg23o7eN%aleax@mail.comcast.net> Message-ID: <1135184227.795949.257840@f14g2000cwb.googlegroups.com> Alex Martelli wrote: > Fuzzyman <fuzzyman at gmail.com> wrote: > > > That's potentially very good news. (Or slightly sinister -depending on > > your paranoia levels). > > > > You got any references on that ? > > I don't think there was any official announcement, but it's true -- he > sits about 15 meters away from me;-). > Cool - pass on my regards and thanks to him. ;-) > > > I was just thinking that the open source offerings from google are > > actually pretty pitiful - considering the time investment they have put > > into developing software systems. (Summer of Code not-withstanding of > > course). > > The key technical person for opensource at Google isn't Guido and isn't > me -- rather, I'd focus on Greg Stein (whose contributions to open > source have been very wide-ranging, and who's been our engineering > manager for opensource for quite a while now... not a secret, you can > read about that on Greg's own blog). If you want more opensource from > us, he's most probably the best person to bug about it!-). I'm sure > that, being the chairman of the Apache Software Foundation (the VP of > the ASF is also a Google employee), he can bend your ears about that;-). > Well, employing key open-source personnel and supporting them in their work *probably* counts as helping the open-source world. OTOH they (you...) must have worked on/with tremendous systems - like load balancing software as one example off the top of my head. I guess these are the competitive edge of google - and also there is a lot of work turning in house systems into 'released' ones, even if the will is there. Even so - the code that has been directly released by google is relatively slender. > > > I wonder if this heralds google finally upgrading from Python 2.2 ;-) > > We currently use multiple versions of Python, and I personally don't see > that changing overnight. But, we'll see. > I've no axe to grind on that one. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml > > Alex From onurb at xiludom.gro Wed Dec 7 04:44:28 2005 From: onurb at xiludom.gro (bruno at modulix) Date: Wed, 07 Dec 2005 10:44:28 +0100 Subject: dynamic variable referencing In-Reply-To: <mailman.1751.1133918042.18701.python-list@python.org> References: <mailman.9799.1133916903.18700.python-list@python.org> <mailman.1751.1133918042.18701.python-list@python.org> Message-ID: <4396aefe$0$28634$636a15ce@news.free.fr> Michael Williams wrote: > I would RTM, but I'm not sure exactly what to look for. Basically, I > need to be able to call a variable dynamically. Meaning something like > the following: > > - I don't want to say OBJECT.VAR but rather > OBJECT. ("string") and have it retrieve the variable (not the value > of it) if in fact it exists. . . getattr(obj, 'name', defaultvalue) You can also implement the special methods __getitem__ and __setitem__ to allow indexed access to attributes, ie: class FalseDict(object): def __init__(self, toto, tata): self.toto = toto self.tata = tata def __getitem__(self, name): return getattr(self, name) def __setitem__(self, name, value): setattr(self, name, value) f = FalseDict('toto', 'tata') f['toto'] f['tata'] = 42 > > The purpose is to create an XML tree myself Don't reinvent the wheel. ElementTree (and it's C based brother) are very good at this. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From godoy at ieee.org Sat Dec 3 21:46:46 2005 From: godoy at ieee.org (Jorge Godoy) Date: 04 Dec 2005 00:46:46 -0200 Subject: Scientific Notation References: <1133663674.341405.95410@g44g2000cwa.googlegroups.com> <1h70bsh.10qldrqew9dd6N%aleax@mail.comcast.net> <1133664042.615633.45570@g14g2000cwa.googlegroups.com> Message-ID: <87psod1svd.fsf@jupiter.g2ctech> "Dustan" <DustanGroups at gmail.com> writes: > No, I mean given a big number, such as > 1000000000000000000000000000000000000000000000000000, convert it into > scientific notation. It's the same. >>> print "%e" % 1000000000000000000000000000000000000000000000000000 1.000000e+51 -- Jorge Godoy <godoy at ieee.org> From steve at REMOVETHIScyber.com.au Fri Dec 9 23:48:46 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sat, 10 Dec 2005 15:48:46 +1100 Subject: ANN: Dao Language v.0.9.6-beta is release! References: <1133174924.322968.273370@o13g2000cwo.googlegroups.com> <1133696971.466976.213370@f14g2000cwb.googlegroups.com> <mailman.1559.1133697611.18701.python-list@python.org> <1133702966.030710.51090@g47g2000cwa.googlegroups.com> <Pine.LNX.4.62.0512042209410.17499@urchin.earth.li> <1133776917.483883.150120@o13g2000cwo.googlegroups.com> <1133788564.145604.234630@g49g2000cwa.googlegroups.com> <1133868635.352421.97010@g43g2000cwa.googlegroups.com> <1133905766.918194.210850@o13g2000cwo.googlegroups.com> <slrndpd5l2.jsc.apardon@rcpc42.vub.ac.be> <slrndpdvq3.bh1.mordor@fly.srk.fer.hr> <pan.2005.12.07.18.20.24.981816@REMOVETHIScyber.com.au> <slrndpfrcn.jsc.apardon@rcpc42.vub.ac.be> <pan.2005.12.08.22.10.43.910197@REMOVETHIScyber.com.au> <slrndpif8i.lae.mordor@fly.srk.fer.hr> Message-ID: <pan.2005.12.10.04.48.45.661341@REMOVETHIScyber.com.au> On Fri, 09 Dec 2005 08:15:14 +0000, Zeljko Vrba wrote: > On 2005-12-08, Steven D'Aprano <steve at REMOVETHIScyber.com.au> wrote: >> >> Making a mistake in indentation level is precisely analogous to leaving >> out markers in other languages. If your editor is smart enough, and the >> > But look at the following example: > > if a: > some_code1 > if b: > some_code2 > > If I accidentaly delete if b:, then some_code2 gets under the if a: which is > not intended. With braces (or other delimiters): > > if(a) { > some_code1; > } > if(b) { > some_code2; > } > > if I delete if(b) I get a syntax error about unmatched braces. Not unless you also delete the opening brace on the same line, surely? Okay, you've deleted the line and you get a syntax error. But not if you accidentally deleted the previous brace as well, or if there was an earlier unmatched brace somewhere earlier in your code. We could play this game all day -- you find some error or typo where redundant braces will save the day, and I'll find another error where they won't. In the meantime, you're spending more time thinking about braces plus indentation than I am thinking about just indentation. And I bet that you've made more mistakes where you got the indentation right but the braces wrong, even with a smart editor, than I've accidentally deleted code in a way that the indentation levels just happen to wrongly match up. > IMO, the "right" > way to handle braces in C is always to include them, even when they are not > technically obligatory. I code like that for a long time and it has saved me > a lot of headache. Sure, and that's good advice for C, but that's because C is labouring under the disadvantage that indentation is not meaningful to the compiler, but is meaningful to the human programmer. -- Steven. From bonono at gmail.com Thu Dec 15 09:24:14 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 15 Dec 2005 06:24:14 -0800 Subject: How to get the local mac address? In-Reply-To: <11q2up2gttjs845@corp.supernews.com> References: <1134575518.767407.112490@g44g2000cwa.googlegroups.com> <1134618652.007425.149540@g14g2000cwa.googlegroups.com> <1134630506.774844.192790@f14g2000cwb.googlegroups.com> <1134630954.491132.260930@g43g2000cwa.googlegroups.com> <mailman.2129.1134634919.18701.python-list@python.org> <1134636649.937619.304060@g49g2000cwa.googlegroups.com> <mailman.2131.1134637340.18701.python-list@python.org> <1134637733.906828.43600@g44g2000cwa.googlegroups.com> <11q2up2gttjs845@corp.supernews.com> Message-ID: <1134656654.701596.222530@g44g2000cwa.googlegroups.com> Grant Edwards wrote: > On 2005-12-15, bonono at gmail.com <bonono at gmail.com> wrote: > > >>>>Why should you want to associate a MAC address with a socket? Each > >>>>interface has an IP address, and it's that you should be using. > >>> > >>> Say for example I want to find out the MAC if a particular > >>> interface in python. > >> > >> When you are asked "why would you want to do something" it > >> isn't normally considered sufficient to reply "suppose I want > >> to do something". I'm still trying to find out what use case > >> (apart from curiosity) drives this need to know. > > > > That is nothing but curiosity of why there is no such thing. I > > didn't start a thread with "what the xyz@!% hell that I cannot > > get MAC address through the socket module". > > > > And I answer things the way I want to, if it does fit your > > expected answer, there is nothing I can do. I am not here to > > convince you. > > Taking an attitude like that towards one of the most respected > people in the Python community is bound to be rather counter > productive. > > Nobody owes you any answers, so yes, in fact, you _are_ here to > convince people that you deserve their help. > I get my answer anyway, and I don't know who is respected on here and if I do, it won't change a thing in the way I answer it. From grante at visi.com Thu Dec 1 09:39:23 2005 From: grante at visi.com (Grant Edwards) Date: Thu, 01 Dec 2005 14:39:23 -0000 Subject: Newbie: Python & Serial Port question References: <mailman.1418.1133407731.18701.python-list@python.org> Message-ID: <11ou2oro4r9lp41@corp.supernews.com> On 2005-12-01, Kinsley Turner <kingsleyturner at westpac.com.au> wrote: >> Am a python newbie. Does python have a native way to communicate with a >> PC serial port? I found that pyserial needs java. > You can't just open the serial port like a file? Yes. > Perhaps you'd need to set the correct port parameters > with some other app, Just use termios. Or better yet, pyserial. > but it should be do-able. -- Grant Edwards grante Yow! Intra-mural sports at results are filtering visi.com through th' plumbing... From donn at drizzle.com Tue Dec 13 01:13:10 2005 From: donn at drizzle.com (Donn Cave) Date: Tue, 13 Dec 2005 06:13:10 -0000 Subject: OO in Python? ^^ References: <dnfmcm$aqp$02$1@news.t-online.com> <dnfnnb$m0n$1@eeyore.INS.cwru.edu> <dngpv7$u5a$01$1@news.t-online.com> <pan.2005.12.11.13.39.05.246028@REMOVETHIScyber.com.au> <1134308880.689307.22090@z14g2000cwz.googlegroups.com> <pan.2005.12.11.15.01.53.327129@REMOVETHIScyber.com.au> <Pine.LNX.4.62.0512120029580.30272@urchin.earth.li> <1h7f90l.l5s3sh1cqq9ozN%aleax@mail.comcast.net> <donn-938248.10402312122005@gnus01.u.washington.edu> <Pine.LNX.4.62.0512130126440.25381@urchin.earth.li> Message-ID: <1134454390.69041@jetspin.drizzle.com> Quoth Tom Anderson <twic at urchin.earth.li>: ... | While we're on the subject of Haskell - if you think python's | syntactically significant whitespace is icky, have a look at Haskell's | 'layout' - i almost wet myself in terror when i saw that! That's funny. I don't think I ever bothered to acquaint myself with the rules of the notation, so once in a while my intuition fails me and I have to re-indent, but it's rare. Off the top of my head, it seems to me Haskell code commonly has a lot more structure than Python code - hierarchically structured expressions instead of series of statements - so maybe it's not surprising if the layout notation can be more complex. Donn Cave, donn at drizzle.com From richie at entrian.com Tue Dec 20 10:27:25 2005 From: richie at entrian.com (Richie Hindle) Date: Tue, 20 Dec 2005 15:27:25 +0000 Subject: ANNOUNCE; Try python beta In-Reply-To: <86u0d3ol3a.fsf@bhuda.mired.org> References: <86oe3c39ho.fsf@bhuda.mired.org> <do7kqd$m7k$1@newsreader3.netcologne.de> <86fyoo330b.fsf@bhuda.mired.org> <mailman.2339.1135079325.18701.python-list@python.org> <86u0d3ol3a.fsf@bhuda.mired.org> Message-ID: <me8gq1l69ji9s3qslaikg4pmkjo0nhog1u@4ax.com> [Richie] > I think it's your JavaScript '\r' processing that's broken. Certainly the > error ("unexpected EOF while parsing") is consistent with having a \r on the > end of the expression. [Mike] > Python doesn't care about the trailing newline. That's a carriage return, not a newline: >>> eval("1+2\r") Traceback (most recent call last): File "<stdin>", line 1, in ? File "<string>", line 1 1+2 ^ SyntaxError: unexpected EOF while parsing > My assumption is that if splitting on '\n' leaves us with one > thing, we may have gotten a string that used \r for newlines Ah, OK. Your comment talks about DOS - that won't happen on DOS (or Windows) which uses \r\n. I don't know about the Mac. But the \r\n pair isn't handled by your code - strip() on the server side will make it work if that's the problem: >>> eval("1+2\r".strip()) 3 -- Richie Hindle richie at entrian.com From bokr at oz.net Mon Dec 19 07:50:11 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 19 Dec 2005 12:50:11 GMT Subject: Can you pass functions as arguments? References: <1134976409.394144.82390@o13g2000cwo.googlegroups.com> <7xr7898sh3.fsf@ruckus.brouhaha.com> Message-ID: <43a6ab51.75585376@news.oz.net> On 18 Dec 2005 23:18:48 -0800, Paul Rubin <http://phr.cx at NOSPAM.invalid> wrote: >bobueland at yahoo.com writes: >> I want to calculate f(0) + f(1) + ...+ f(100) over some function f >> which I can change. So I would like to create a function taking f as >> argument giving back the sum. How do you do that in Python? > >You can just pass f as an argument. The following is not the most >concise or general way, it just shows how you can pass a function. > > def square(x): > return x**2 > > def sum100(f): # f(0)+f(1)+...+f(100) > s = 0 > for i in xrange(101): > s += f(i) > return s > > print sum100(square) # pass square as an argument or >>> def square(x): return x*x ... >>> from itertools import imap >>> sum(imap(square, xrange(101))) 338350 which seems to agree with >>> def sum100(f): ... s = 0 ... for i in xrange(101): ... s += f(i) ... return s ... >>> sum100(square) 338350 or if the OP actually wants the specific function, >>> def sum100a(f): return sum(imap(f, xrange(101))) ... >>> sum100a(square) 338350 Regards, Bengt Richter From rurpy at yahoo.com Mon Dec 5 17:37:51 2005 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: 5 Dec 2005 14:37:51 -0800 Subject: Bitching about the documentation... In-Reply-To: <mailman.1628.1133798275.18701.python-list@python.org> References: <mailman.1565.1133705473.18701.python-announce-list@python.org> <1133740404.946655.246410@g44g2000cwa.googlegroups.com> <mailman.1579.1133743606.18701.python-list@python.org> <1133745360.027320.211150@g44g2000cwa.googlegroups.com> <mailman.1591.1133755014.18701.python-list@python.org> <1133757861.843461.37910@g47g2000cwa.googlegroups.com> <mailman.1628.1133798275.18701.python-list@python.org> Message-ID: <1133822271.447061.323950@g47g2000cwa.googlegroups.com> <skip at pobox.com> wrote in message news:mailman.1628.1133798275.18701.python-list at python.org... --snip-- > rurpy> Well, I'm not totally sure but I think I would be willing to a > rurpy> least try contributing something. A large amount of the time I > rurpy> waste when writing Python programs is directly attributable to > rurpy> poor documentation. (To be fair Python is not the only software > rurpy> with this problem.) > > rurpy> But, the standard responce of "don't complain, fix it yourself" > rurpy> is bogus too. There are plenty of people on this list willing to > rurpy> sing python's praises, for balance, there should be people > rurpy> willing to openly point out python's flaws. Documentation is > rurpy> certainly one of them. And I was correcting a posting that > rurpy> explicitly said there was exceptionaly good information in that > rurpy> Howto. That was just plain wrong. > > Sure, feel free to point of flaws. Just don't let that be the only way you > contribute. Over time the value of your criticism (valid or not) will be > discounted. > > The preferred way to correct problems with the documentation is to submit a > bug report to SourceForge. Many of the active developers (including those > who do write most of documentation) don't necessarily track c.l.py closely, > so postings here often will get lost because people can't attend to them > immediately. > > The problem with marching in here and saying "fix the docs" is that you are > an unknown quantity (I certainly don't recognize your email address and as > far as I've seen you never sign your posts. I don't believe my name, etnic heritage, gender, age, employer or school, or part of the world I live in, have any bearing on the contents of my postings. > I don't believe I've ever seen > contributions from you either. (Can't double-check right now because > SourceForget is basically unresponsive.) I try to contribute on c.l.p when I can but those times are rare. I freely admit I am a python newbie so in most cases it is more appropriate for me to read answers than to supply them. And traffic is so high it is rare when I see a question I can answer, that someone hasn't already answered better. > The combination makes you look > suspiciously like a troll. I doubt that's the case. Troll detectors are > notorious for generating false positives. Still, my threat assessment level > got raised. I would say I am more than 90% serious and less than 10% troll. :-) Perhaps the reason your detector went off is because I have posted some Politically Incorrect opinions in the same absolutist, dogmatic, style used by many PC posters? Sorry, life is short and I am not interested in sugar coating anything. > Operating under the rurpy's-not-a-troll assumption, your posts suggest to me > that you don't understand how Python is developed. Behind the scenes lots > of documentation *does* get written. In my experience it hass generally not > been written by people who whine, "fix the docs". In short, there seems to > be no shortage of people willing to castigate the Python developers for > poor documentation. There does appear to be a shortage of people willing to > actually roll up their sleeves and help. Well, I guess I would be willing to consider trying to help. (I say "try" because I am lousy at technical writing so my help may not be very helpful.) One thing that's not clear to me is exactly what audience are the docs aimed at? If the powers-that-be have declared that the Lang Ref. Manual is going to be a minimalist reference with an audience that already has a high level knowledge of Python, there is no point in my contributing because: 1. I can't write at that level. 2. I have no interest in a manual positioned at that level. If the audience is some lower level (e.g. programmers with some familiarity with OO but no Python knowledge) then I would be much more motivated to help. (Note that I am NOT talking about turning the Lang.Ref.Man into a tutorial!!!) > The other thing to remember is that most of the people who wind up writing > the documentation don't personally need most of the documentation they > write. After all, they are generally the authors of code itself and are > thus the experts in its use. It's tough to put yourself in the shoes of a > novice, so it's tough to write documentation that would be helpful for new > users. It's extremely helpful if new users submit documentation patches as > they figure things out. It's generally unnecessary to write large tomes. > Often all that's needed is a few sentences or an example or two. From scott.daniels at acm.org Mon Dec 19 22:42:54 2005 From: scott.daniels at acm.org (Scott David Daniels) Date: Mon, 19 Dec 2005 19:42:54 -0800 Subject: Which Python web framework is most like Ruby on Rails? In-Reply-To: <1h7tyly.10xhpeaq51hz8N%aleax@mail.comcast.net> References: <1134496403.011407.169930@g44g2000cwa.googlegroups.com> <1134497848.620585.259200@g44g2000cwa.googlegroups.com> <1134502590.154469.37760@g49g2000cwa.googlegroups.com> <1134503125.765106.239640@g14g2000cwa.googlegroups.com> <1h7j2gk.aktins1kknr40N%aleax@mail.comcast.net> <IY2dnQsUIMyesD3enZ2dnUVZ_sadnZ2d@comcast.com> <1134574436.740981.134140@z14g2000cwz.googlegroups.com> <861x0fgkn3.fsf@bhuda.mired.org> <1134646215.706929.245390@g49g2000cwa.googlegroups.com> <86d5jyovuv.fsf@bhuda.mired.org> <1134747621.405701.297470@f14g2000cwb.googlegroups.com> <86lkykuao4.fsf@bhuda.mired.org> <rowen-4C9BAD.14564319122005@gnus01.u.washington.edu> <mailman.2324.1135035015.18701.python-list@python.org> <86slso39qx.fsf@bhuda.mired.org> <43a760ce$1@nntp0.pdx.net> <1h7tyly.10xhpeaq51hz8N%aleax@mail.comcast.net> Message-ID: <43a77d54$1@nntp0.pdx.net> Alex Martelli wrote: > Scott David Daniels <scott.daniels at acm.org> wrote: >> If the data you store and update is sufficiently valuable to your >> enterprise, picking a database may be vital. Transactions guarantee >> every update either happens or not, and infrastructure is provided >> for you to be able to backup and restore the data you've obtained. > > A good point, but there are others. If the data is valuable, there WILL > be requests from parts of the enterprise to use that data in other ways > that were originally not anticipated. If you keep the data in a > relational DB with any kind of sensible schema, then the data IS > reusable, including in impromptu exploratory ways from interactive > prompts of many kinds -- you don't necessarily need "programmers" to > enable such reuse. We are in violent agreement here. My contention is that you need a _real_ relational database here, not that you need to pick a vendor. MySQL vs. Pick vs. ... should be shut out early. A truly relational DB has value, picking a particular one early does not. The attributes I describe are available from any reputable relational DB vendor, and make no mistake, PostgreSQL is what I consider a vendor -- a provider of a fully thought-out and implemented solution. > ... maintaining portability among different databases may well be a > great choice, even when it requires the overhead of a "database > independence layer". Yup. I think you should choose a vendor, but not in the sense of buying lock-in; in the sense of accepting a data model. --Scott David Daniels scott.daniels at acm.org From john.morey at gmail.com Wed Dec 14 19:20:10 2005 From: john.morey at gmail.com (John Morey) Date: Thu, 15 Dec 2005 00:20:10 +0000 Subject: quick unicode Q Message-ID: <pan.2005.12.15.00.20.10.455682@gmail.com> I have a variable that contains a string which may or may not include unicode characters, I understand that I declare a unicode string like this u'whatever' , the question is that when that string is read in from an external source (in this case an id3 tag) how do I make the interpretter understand that it may contain unicode? cheers From robert.kern at gmail.com Sat Dec 17 00:33:16 2005 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 16 Dec 2005 21:33:16 -0800 Subject: Next floating point number In-Reply-To: <pan.2005.12.17.03.23.38.554652@REMOVETHIScyber.com.au> References: <pan.2005.12.17.03.23.38.554652@REMOVETHIScyber.com.au> Message-ID: <do07uu$ia5$1@sea.gmane.org> Steven D'Aprano wrote: > Unless I have missed something, Python doesn't appear to give an interface > to the C library's next float function. I assume that most C floating > point libraries will have such a function. http://www.mkssoftware.com/docs/man3/nextafter.3.asp -- Robert Kern robert.kern at gmail.com "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From kent at kentsjohnson.com Wed Dec 7 12:10:18 2005 From: kent at kentsjohnson.com (Kent Johnson) Date: Wed, 07 Dec 2005 12:10:18 -0500 Subject: Documentation suggestions In-Reply-To: <mailman.1765.1133944972.18701.python-list@python.org> References: <mailman.1715.1133886680.18701.python-list@python.org> <1133888319.779023.53940@o13g2000cwo.googlegroups.com> <1133919072.484143.234100@g47g2000cwa.googlegroups.com> <mailman.1765.1133944972.18701.python-list@python.org> Message-ID: <43971481$1_3@newspeer2.tds.net> Steve Holden wrote: > BartlebyScrivener wrote: >> Now you are on a page with promising-looking links that all start with >> "BeginnersGuide," but the first three are not warm welcomes, they are >> housekeeping matters about where you can take courses or how to >> download Python for people who don't know whether they want to or not >> yet, or there's one that says "examples" which will take you to the >> ActiveState Cookbook site so you can get really confused. <snip many more valid criticisms> > I think the Python community as a whole should take this on board as > fair criticism. It would be really nice if a total beginner did actually > see a usable path through the web to their first working Python program. OK I'll bite. That Beginners Guide page has bugged me for a long time. It's a wiki page but it is marked as immutable so I can't change it. Here are some immediate suggestions: - get rid of the 1-7 list at the top it is very confusing and does not present information in a useful form or order. All of these links except the help link appear in the body text in more useful form. - Change the sentence "Read BeginnersGuide/Overview to learn the key points." to "Read BeginnersGuide/Overview to learn what makes Python special." Or maybe get rid of it completely - I'm not sure evangelism belongs on this page. - Add a sentence at the end of the paragraph that starts, "Once you've read a tutorial" that says, "Many other resources are listed in BeginnersGuide/Help." On the BeginnersGuide/NonProgrammers page, I agree, Guido's tutorial probably shouldn't be listed first even with the disclaimer. It goes way to fast for a beginner. Alan Gauld's tutorial is very popular on the tutor list, so is A Byte of Python (which is not listed on the NonProgrammers page). I would list them first. Or maybe take a vote on the tutor list for favorite beginner's tutorial. That should help a little, maybe we won't confuse the newbies before they even get to an interpreter prompt. Kent PS I am aware of the usual SF bug report procedure for docs, does it apply to these pages? I don't know, they don't have the usual "About this document" link at the bottom. I'm happy to submit a patch if that will help. Otherwise I'm not sure what "the Python community as a whole [taking] this on board" should look like. From skip at pobox.com Sun Dec 4 17:21:15 2005 From: skip at pobox.com (skip at pobox.com) Date: Sun, 4 Dec 2005 16:21:15 -0600 Subject: Detect character encoding In-Reply-To: <439369e6$0$11073$e4fe514c@news.xs4all.nl> References: <mailman.1560.1133702297.18701.python-list@python.org> <3vgg0kF15o9jfU1@uni-berlin.de> <86mzjgmzf9.fsf@bhuda.mired.org> <439369e6$0$11073$e4fe514c@news.xs4all.nl> Message-ID: <17299.27611.395739.676528@montanaro.dyndns.org> Martin> I read or heard (can't remember the origin) that MS IE has a Martin> quite good implementation of guessing the language en character Martin> encoding of web pages when there not or falsely specified. Gee, that's nice. Too bad the source isn't available... <0.5 wink> Skip From max at alcyone.com Tue Dec 13 05:14:52 2005 From: max at alcyone.com (Erik Max Francis) Date: Tue, 13 Dec 2005 02:14:52 -0800 Subject: "0 in [True,False]" returns True In-Reply-To: <1134467098.050659.190220@g43g2000cwa.googlegroups.com> References: <439deb17$0$18320$8fcfb975@news.wanadoo.fr> <mailman.2017.1134463342.18701.python-list@python.org> <7xirtt9xn6.fsf@ruckus.brouhaha.com> <UNedneFMsuxRCQPeRVn-jg@speakeasy.net> <1134467098.050659.190220@g43g2000cwa.googlegroups.com> Message-ID: <Af-dnTs4UquBAgPenZ2dnUVZ_tCdnZ2d@speakeasy.net> bonono at gmail.com wrote: > True, but if that is the only reason, Two built-in value of > True/False(0/1) serves the need which is what is now(well sort of). Why > have seperate types and distinguish them ? Because of this: x = True y = 1 # but I mean it to represent true print x, y Besides, it's not the only reason, but it's a good one. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis Ipsa scientia potestas est. "Knowledge itself is power." -- a Latin proverb From raims at dot.com Sun Dec 18 19:08:30 2005 From: raims at dot.com (Lawrence Oluyede) Date: Mon, 19 Dec 2005 01:08:30 +0100 Subject: Changing a shell's current directory with python References: <mailman.2279.1134950381.18701.python-list@python.org> Message-ID: <slrndqbufu.ac3.raims@voodoo.myself> irIl 2005-12-18, Andy B. <abuecker at gmail.com> ha scritto: > I've got a python utility that I want to change my shell's current > directory based on criteria it finds. I've scoured google and the > python cookbook and can't seem to figure out if this is even possible. > So far, all my attempts have changed the current python session only. > Am I going to have to wrap this in a shell script? > > % pwd > /var/tmp > % myutil.py > # do some stuff and cd to '/var/log' > % pwd > /var/log Just look in the library: import os os.chdir("path") -- Lawrence - http://www.oluyede.org/blog "Anyone can freely use whatever he wants but the light at the end of the tunnel for most of his problems is Python" From fredrik at pythonware.com Thu Dec 8 11:48:04 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 8 Dec 2005 17:48:04 +0100 Subject: Encoding of file names References: <1134046955.592312.301590@f14g2000cwb.googlegroups.com> Message-ID: <dn9o46$qoa$1@sea.gmane.org> "utabintarbo" wrote: > I am trying to programatically access files created on an IBM AIX > system, stored on a Sun OS 5.8 fileserver, through a samba-mapped drive > on a Win32 system. Not confused? OK, let's move on... ;-) > > When I ask for an os.listdir() of a relevant directory, I get filenames > with embedded escaped characters (ex. > 'F07JS41C.04389525AA.UPR\xa6INR.E\xa6C-P.D11.081305.P2.KPF.model') how did you print that name? "\xa6" is a "broken vertical bar", which, as far as I know, is a valid filename character under both Unix and Windows. if DIR is a variable that points to the remote directory, what does this print: import os files = os.listdir(DIR) file = files[0] print file print repr(file) fullname = os.path.join(DIR, file) print os.path.isfile(fullname) print os.path.isdir(fullname) (if necessary, replace [0] with an index that corresponds to one of the problematic filenames) when you've tried that, try this variation (only the listdir line has changed): import os files = os.listdir(unicode(DIR)) # <-- this line has changed file = files[0] print file print repr(file) fullname = os.path.join(DIR, file) print os.path.isfile(fullname) print os.path.isdir(fullname) </F> From JMailone at gmail.com Mon Dec 12 02:55:44 2005 From: JMailone at gmail.com (Jay) Date: 11 Dec 2005 23:55:44 -0800 Subject: Using XML w/ Python... In-Reply-To: <1134372862.503403.26240@g14g2000cwa.googlegroups.com> References: <1134277924.398538.296150@g49g2000cwa.googlegroups.com> <1134333951.509929.5490@g49g2000cwa.googlegroups.com> <1134342781.330978.303580@g47g2000cwa.googlegroups.com> <1134347722.851087.169300@g49g2000cwa.googlegroups.com> <1134350340.363450.80270@g43g2000cwa.googlegroups.com> <q5qpp19gramngf961gi0dmoig3ej4m48q2@4ax.com> <1134359242.311767.12510@z14g2000cwz.googlegroups.com> <1134363744.268651.221840@g47g2000cwa.googlegroups.com> <1134366913.890682.123960@z14g2000cwz.googlegroups.com> <1134369549.926561.113940@f14g2000cwb.googlegroups.com> <1134370144.530537.146790@f14g2000cwb.googlegroups.com> <1134370395.530700.281190@g47g2000cwa.googlegroups.com> <1134372862.503403.26240@g14g2000cwa.googlegroups.com> Message-ID: <1134374144.620694.48020@f14g2000cwb.googlegroups.com> when putting excactly what you got, i got >>> python -c "import amara; print dir(amara)" Traceback ( File "<interactive input>", line 1 python -c "import amara; print dir(amara)" ^ SyntaxError: invalid syntax when doing it seperately, i got> >>> import amara >>> print dir(amara) ['__builtins__', '__doc__', '__file__', '__name__', '__path__', '__version__', 'binderytools', 'os', 'parse'] >>> From jrsotty at cri74.org Mon Dec 5 05:31:24 2005 From: jrsotty at cri74.org (Jean-Roch SOTTY) Date: Mon, 5 Dec 2005 11:31:24 +0100 Subject: libxml2 and XPath - Iterate through repeating elements? In-Reply-To: <1133544680.148228.53200@z14g2000cwz.googlegroups.com> References: <1133544680.148228.53200@z14g2000cwz.googlegroups.com> Message-ID: <200512051131.24889.jrsotty@cri74.org> Le Vendredi 2 D?cembre 2005 18:31, nickheppleston at gmail.com a ?crit?: > I'm trying to iterate through repeating elements to extract data using > libxml2 but I'm having zero luck - any help would be appreciated. > > My XML source is similar to the following - I'm trying to extract the > line number and product code from the repeating line elements: > > <order xmlns="some-ns"> > <header> > <orderno>123456</orderno> > </header> > <lines> > <line> > <lineno>1</lineno> > <productcode>PENS</productcode> > </line> > <line> > <lineno>2</lineno> > <productcode>STAPLER</productcode> > </line> > <line> > <lineno>3</lineno> > <productcode>RULER</productcode> > </line> > </lines> > </order> The result of an xpath evaluation is a list of node, which you can perform another xpatheval() on : import libxml2 doc = libxml2.parseFile(XmlFile) root = doc.getRootElement() line_nodes = root.xpathEval('lines/line') for line_node in line_nodes: print line_node.xpathEval('lineno')[0].content print line_node.xpathEval('productcode')[0].content doc.freeDoc() -- Cordially Jean-Roch SOTTY From exarkun at divmod.com Tue Dec 27 16:37:09 2005 From: exarkun at divmod.com (Jean-Paul Calderone) Date: Tue, 27 Dec 2005 16:37:09 -0500 Subject: python coding contest In-Reply-To: <dosafj$s91$1@sea.gmane.org> Message-ID: <20051227213709.1217.602144154.divmod.quotient.8417@ohm> On Tue, 27 Dec 2005 14:02:57 -0700, Tim Hochberg <tim.hochberg at ieee.org> wrote: >Shane Hathaway wrote: >> Paul McGuire wrote: >> >> >> Also, here's another cheat version. (No, 7seg.com does not exist.) >> >> import urllib2 >> def seven_seg(x):return urllib2.urlopen('http://7seg.com/'+x).read() >> >And another one from me as well. > >class a: > def __eq__(s,o):return 1 >seven_seg=lambda i:a() > This is shorter as "__eq__=lambda s,o:1". But I can't find the first post in this thread... What are you guys talking about? Jean-Paul From mwm at mired.org Wed Dec 14 10:10:29 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 14 Dec 2005 10:10:29 -0500 Subject: Still Loving Python References: <1134489879.436360.273220@g47g2000cwa.googlegroups.com> <slrndptsl4.eba.raims@voodoo.myself> <dnmtau$n8r$1@bagan.srce.hr> <pan.2005.12.13.17.41.22.605915@free.fr> <867ja8tyzm.fsf@bhuda.mired.org> <dnnjmg$rc1$1@online.de> <86r78gsbrj.fsf@bhuda.mired.org> <mailman.2066.1134530095.18701.python-list@python.org> <86bqzks5hb.fsf@bhuda.mired.org> <mailman.2081.1134565399.18701.python-list@python.org> Message-ID: <86slsvww7u.fsf@bhuda.mired.org> Peter Decker <pydecker at gmail.com> writes: > On 12/13/05, Mike Meyer <mwm at mired.org> wrote: >> > Why this need to have everyone do things the way you do? >> Whatever makes you think I have this need? I said I hated them. I'm >> pretty sure I didn't say everyone should have to use them. > Sorry, but there is a world of difference between saying "I prefer X > over Y" and "Yes, Y is evil". And unless English is a second language > for you, it's insulting to imply a difference between calling > something evil and agreeing with someone who did, even if you added a > smiley. I don't agree. I do apologize, though - no insult as intended. > This is a 'discussion' list. Nothing kills discussion faster than > zealots who call those who disagree with them evil or idiots or > clueless n00bs. There's also a world of difference between saying "X is evil" and saying "users of X are evil." Unless English is a second language for you, going from a statement about X to a statement about is users of X is insulting. <mike -- Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From bonono at gmail.com Tue Dec 6 11:55:28 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 6 Dec 2005 08:55:28 -0800 Subject: i=2; lst=[i**=2 while i<1000] In-Reply-To: <4395c066.319152306@news.oz.net> References: <dn463i$234$1@news2.rz.uni-karlsruhe.de> <Xns9724930AC50DBduncanbooth@127.0.0.1> <dn48es$421$1@news2.rz.uni-karlsruhe.de> <Xns972499E70BDB9duncanbooth@127.0.0.1> <1133883705.255507.106080@g49g2000cwa.googlegroups.com> <4395c066.319152306@news.oz.net> Message-ID: <1133888127.976077.95500@g44g2000cwa.googlegroups.com> Bengt Richter wrote: > On 6 Dec 2005 07:41:45 -0800, bonono at gmail.com wrote: > > > >If one really wants a very messy one-liner, it is possible > > > >import operator > >x=3D[2] > >lst=3Dlist(((operator.setitem(x,0,x[0]**2),x[0])[1] for _ in > >xrange(10000000) if x[0] < 1000 or iter([]).next())) > > > Or > >>> list(iter(lambda b=[2]:b.append(b[0]**2) or b[0]<1000 and b.pop(0) or None, None)) > [2, 4, 16, 256] > out of curiosity, what stops the iterator ? From gherron at islandtraining.com Fri Dec 23 18:37:49 2005 From: gherron at islandtraining.com (Gary Herron) Date: Fri, 23 Dec 2005 15:37:49 -0800 Subject: Indentation/whitespace In-Reply-To: <1135360496.036672.326570@g47g2000cwa.googlegroups.com> References: <1135360496.036672.326570@g47g2000cwa.googlegroups.com> Message-ID: <43AC8A4D.6070109@islandtraining.com> Joe wrote: >Is Python going to support s syntax the does not use it's infamous >whitespace rules? I recall reading that Python might include such a >feature. Or, maybe just a brace-to-indentation preprocessor would be >sufficient. > > Only over our dead bodies! ("our" = the large and always growing Python community.) >Many people think Python's syntax makes sense. There are strong >feelings both ways. It must depend on a person's way of thinking, >because I find it very confusing, even after using with Python for some >time, and trying to believe the advice that I would learn to like it. >The most annoying thing is that multiple dedents are very unreadable. I >still don't understand how anybody can think significant-but-invisible >dedentation is a good thing. > > You've got the visible/invisible aspect of things *exactly* backwards. The point on a line of text where things change from white space to non-white space is *highly* visible. The several pixels that represent a { or } are nearly invisible within a line of text. (So one usually compensates by putting them alone on a line, making them somewhat more visible.) Try this experiment: Print out a page of C++ code, tape it to the wall, and start walking backwards. You will still be able to discern the structure of the code *long* after you can no longer identify the curly-braces. (Provided you properly indented you C++ code -- you *do* indent you C++ code don't you?) Gary Herron >Note: No need to follow up with long opinions of why indentation is >good -- they have been posted hundreds of times. It just seems that >Python developers think the whitespace thing is only an issue for >newbies. I think that many experienced users don't learn to like it, >but instead just learn to live with it. > > > From tim.golden at viacom-outdoor.co.uk Fri Dec 30 10:08:21 2005 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Fri, 30 Dec 2005 15:08:21 -0000 Subject: WMI - invalid syntax error? Message-ID: <9A28C052FF32734DACB0A288A3533991044D242E@vogbs009.gb.vo.local> [py] > import wmi > # the ip of my own local desktop > machine = "1.2.3.4" > try: > w = wmi.WMI(machine) # also tried, wmi.WMI(computer=machine) > except Exception, e: > print "ERROR:", e . . > c:>python > >>> from MyScript import * > >>> ERROR: -0x7ffbfe1c - Invalid syntax . . > here's the trace... > > File "MyScript.py", line 10, > wmiObj = wmi.WMI(machine) > File "wmi.py", line 519, in __init__ > handle_com_error (error_info) > File "wmi.py", line 131, in handle_com_error > raise x_wmi, "\n".join (exception_string) > x_wmi: -0x7ffbfe1c - Invalid syntax . . > one more note, I am using WMI v0.6 ....however, I also tried it with > the latest version 1.0 rc2. OK, so if I understand you: at the interpreter you can do this: <interpreter> import wmi w = wmi.WMI ("1.2.3.4") # no problem </interpreter> but if you put it into a file and then import * from that file, it fails with a wmi exception: <blah.py> import wmi w = wmi.WMI ("1.2.3.4") </blah.py> <interpreter> from blah import * ## some kind of x_wmi exception happens here </interpreter> And this happens on wmi 0.6 and 1.0rc2. Is this correct? It's just that you've got several things which could to be blurring the issue - the fact that you're using an explicit IP address rather than passing no params, which will then use the local machine automatically; you've added an exception handler which doesn't do much; your traceback in the second email doesn't (quite) match the MyScript in the first. It's not that these are wrong - I'm just trying to eliminate non-essentials to get to the core of the thing. In short, what I wrote above works for me on 0.6 and 1.0rc2. A syntax error usually means that the moniker's got problems - that's the string which the wmi module builds up on your behalf to get something to pass to MS COM. Could you just post (or send by private email if you prefer) the exact script you're running? If you want to send it privately, please us mail <at> timgolden.me.uk. Thanks TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. 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 mwm at mired.org Thu Dec 1 15:22:36 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 01 Dec 2005 15:22:36 -0500 Subject: python speed References: <hhupo15bdg0tvnivtpu60907nanuose44r@4ax.com> <dmk12h$617$1@news.al.sw.ericsson.se> <438d9409$0$67256$157c6196@dreader2.cybercity.dk> <a8aro1t22hoh568u3pkdskmeffn0tuego1@4ax.com> <1133358884.407477.219560@g47g2000cwa.googlegroups.com> <438db382$0$67257$157c6196@dreader2.cybercity.dk> <1133368487.648595.50950@z14g2000cwz.googlegroups.com> <86sltdn6ma.fsf@bhuda.mired.org> <mailman.1431.1133432317.18701.python-list@python.org> Message-ID: <86lkz4r2ib.fsf@bhuda.mired.org> "Fredrik Lundh" <fredrik at pythonware.com> writes: > Mike Meyer wrote: >> If you wire everything down, you can always hand-code assembler that >> will be faster than HLL code > but that doesn't mean that your hand-coded assembler will always be faster > than an HLL implementation that addresses the same problem: True. But you can always recode the assembler to make it faster than the HLL for the case at hand, possibly making it worse in other cases. > http://mail.python.org/pipermail/python-announce-list/2005-November/004519.html > "Pure Python division is 16x slower than GMP but can actually > be faster in some instances; for example, dividing a 2,000,000 > digit number by an 800,000 digit number" This isn't the case I outlined, though. This is general-purpose assembler package, not assembler code designed specifically for dividing a 2,000,000 digit number by an 800,000 digit number. <mike -- Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From samschul at pacbell.net Sat Dec 31 00:19:42 2005 From: samschul at pacbell.net (sam) Date: 30 Dec 2005 21:19:42 -0800 Subject: UpDate For SCSIPython Storage device test library In-Reply-To: <1135820805.192122.45090@g43g2000cwa.googlegroups.com> References: <1135820805.192122.45090@g43g2000cwa.googlegroups.com> Message-ID: <1136006382.254184.231530@g47g2000cwa.googlegroups.com> Just a added note,that these routines will access any storage drive that is mounted under Windows. The Scsi Pass Through layer maps all Pcmcia,IDE,andSCSI drives to use SCSI commands. This allows a user to access all these interfaces with a common command set. Sam Schulenburg From dodysw at gmail.com Thu Dec 22 12:29:49 2005 From: dodysw at gmail.com (Dody Suria Wijaya) Date: Fri, 23 Dec 2005 04:29:49 +1100 Subject: Python IMAP4 Memory Error In-Reply-To: <43aa7411@clarion.carno.net.au> References: <43aa7411@clarion.carno.net.au> Message-ID: <43aae29a$1@clarion.carno.net.au> Mode details, this occurs on Python 2.4.2 windows, but not on Python 2.3.4 cygwin or Python 2.3.5 windows binary. Dody Suria Wijaya wrote: > > Hi, I encountered a Memory Error Exception on using IMAP4 just like in > Python documentation example, on a specially large email (10 MB). Any > idea how to fix/circumvent this? > > >>> typ, data = M.fetch(89, '(RFC822)') > Traceback (most recent call last): > File "<stdin>", line 1, in ? > File "C:\Python24\lib\imaplib.py", line 426, in fetch > typ, dat = self._simple_command(name, message_set, message_parts) > File "C:\Python24\lib\imaplib.py", line 1028, in _simple_command > return self._command_complete(name, self._command(name, *args)) > File "C:\Python24\lib\imaplib.py", line 858, in _command_complete > typ, data = self._get_tagged_response(tag) > File "C:\Python24\lib\imaplib.py", line 959, in _get_tagged_response > self._get_response() > File "C:\Python24\lib\imaplib.py", line 921, in _get_response > data = self.read(size) > File "C:\Python24\lib\imaplib.py", line 1123, in read > data = self.sslobj.read(size-read) > MemoryError > > -- > dsw From xah at xahlee.org Tue Dec 27 15:22:15 2005 From: xah at xahlee.org (Xah Lee) Date: 27 Dec 2005 12:22:15 -0800 Subject: PHP = Perl Improved In-Reply-To: <1134155716.631143.191340@f14g2000cwb.googlegroups.com> References: <1133844932.007824.26780@g43g2000cwa.googlegroups.com> <1134056349.035360.209840@f14g2000cwb.googlegroups.com> <1134155716.631143.191340@f14g2000cwb.googlegroups.com> Message-ID: <1135714935.515690.271110@g43g2000cwa.googlegroups.com> ?use bytes; # Larry can take Unicode and shove it up his ass sideways. # Perl 5.8.0 causes us to start getting incomprehensible # errors about UTF-8 all over the place without this.? From: the source code of WebCollage (1998) http://www.jwz.org/webcollage/ by Jamie W. Zawinski (~1971-) The code is 3.4 thousand lines of Perl in one single file. Rather incomprehensible. Xah xah at xahlee.org ? http://xahlee.org/ From steve at holdenweb.com Sat Dec 24 05:02:28 2005 From: steve at holdenweb.com (Steve Holden) Date: Sat, 24 Dec 2005 10:02:28 +0000 Subject: Indentation/whitespace In-Reply-To: <1135380715.339155.241090@o13g2000cwo.googlegroups.com> References: <1135360496.036672.326570@g47g2000cwa.googlegroups.com> <mailman.2499.1135379732.18701.python-list@python.org> <1135380715.339155.241090@o13g2000cwo.googlegroups.com> Message-ID: <doj6bi$opk$2@sea.gmane.org> thakadu wrote: > I consider myself a fairly experienced Python coder and although I am > not "uncomfortable" with significant whitespace there are a few places > where I do find it annoying and I wouldnt mind an alternate block > delimitation syntax. I would prefer something like the ruby "end" > though rather than '{' and '}'. [...] > Of course, therein lies the answer: the "I don't like indentation" crowd should all be put in a room and not allowed out until they can all agree on the best alternative. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From stygian at tesco.net Fri Dec 2 12:09:57 2005 From: stygian at tesco.net (Glen) Date: Fri, 02 Dec 2005 17:09:57 +0000 Subject: Detect TKinter window being closed? References: <dmpqdf$tvc$1@domitilla.aioe.org> Message-ID: <dmpv68$59i$1@domitilla.aioe.org> Thanks Fredrik and Adonis that's just what I needed, plus a bit more to learn about. From herman at kuleuven.net Thu Dec 1 12:04:52 2005 From: herman at kuleuven.net (hermy) Date: Thu, 01 Dec 2005 18:04:52 +0100 Subject: [newbie] super() and multiple inheritance Message-ID: <1133456690.895788@seven.kulnet.kuleuven.ac.be> Hi, I'm trying to figure out how to pass constructor arguments to my superclasses in a multiple inheritance situation. As I understand it, using super() is the preferred way to call the next method in method-resolution-order. When I have parameterless __init__ methods, this works as expected. However, how do you solve the following simple multiple inheritance situation in python ? class A(object): def __init__(self,x): super(A,self).__init__(x) print "A init (x=%s)" % x class B(object): def __init__(self,y): super(B,self).__init__(y) print "B init (y=%s)" % y class C(A,B): def __init__(self,x,y): super(C,self).__init__(x,y) <-------- how to do this ??? print "C init (x=%s,y=%s)" % (x,y) What I want is that when I create a class C object x = C(10,20) that the x argument of C's __init__ is used to initialize the A superclass, and the y argument is used to initialize the B superclass. In C++, I would do this using initilaization lists, like: C::C(int x, int y) : A(x), B(y) { ... } I'm probably overlooking some basic stuff here, but I haven't been able to figure this out. Googling got me lots of examples, but all with empty __init__ argument lists (which obviously works, but is too trivial in practice). regards, herman From mgedmin at gmail.com Fri Dec 30 17:22:43 2005 From: mgedmin at gmail.com (Marius Gedminas) Date: 30 Dec 2005 14:22:43 -0800 Subject: python coding contest References: <mailman.2561.1135629433.18701.python-list@python.org> <doq7v2$i9g$1@news.tiscali.fr> <43b0b977@nntp0.pdx.net> <Xns97395FB4B1AD6duncanbooth@127.0.0.1> <43b23eec.184598698@news.oz.net> <43B25B0F.90509@hathawaymix.org> <59e9fd3a0512291635u14202551qe5e221e279fae89@mail.gmail.com> <43B4C671.6020900@hathawaymix.org> <dp3nmr$tru$1@sea.gmane.org> <mailman.2730.1135962496.18701.python-list@python.org> <1135963485.219878.183210@o13g2000cwo.googlegroups.com> <mailman.2733.1135966065.18701.python-list@python.org> <1135969160.749209.3070@g47g2000cwa.googlegroups.com> <43B59FAE.7060003@freenet.de> Message-ID: <1135981363.360564.18820@o13g2000cwo.googlegroups.com> I managed it with vim. From farproc at gmail.com Tue Dec 20 07:48:15 2005 From: farproc at gmail.com (Kevin Yuan) Date: Tue, 20 Dec 2005 20:48:15 +0800 Subject: How to get the path of current running python script? In-Reply-To: <9afea2ac0512200437u4ee849a0w@mail.gmail.com> References: <G29179236.205.1680.3@mx-extra.net> <9afea2ac0512200437u4ee849a0w@mail.gmail.com> Message-ID: <4ab8749e0512200448m1a4067c3p@mail.gmail.com> Oh, my god! I forgot that python is written in C! int main(int argc, char* argv[]) { printf(argv[0]); return 0; } *argv[0]* also woks here!! :) :) :) Thank you very much!! 2005/12/20, Tim Williams (gmail) <tdwdotnet at gmail.com>: > > > On 20/12/05, Kevin Yuan <farproc at gmail.com> wrote: > > > > I tried the following > > > > >>>> getFilePath = lambda name: os.path.normpath('%s\\%s' % (sys.modules[name].prefix, > > sys.modules[name].__name__)) > > >>>> getFilePath('__main__') > > > > > getFilePath = sys.argv[0] ?? > > > :) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-list/attachments/20051220/22c04788/attachment.html> From skip at pobox.com Tue Dec 6 06:46:18 2005 From: skip at pobox.com (skip at pobox.com) Date: Tue, 6 Dec 2005 05:46:18 -0600 Subject: Usenet falsehoods (was Re: Bitching about the documentation...) In-Reply-To: <dn350c$m1p$1@panix3.panix.com> References: <mailman.1565.1133705473.18701.python-announce-list@python.org> <mailman.1658.1133823752.18701.python-list@python.org> <1133824739.638927.257530@g14g2000cwa.googlegroups.com> <11p9kl1cm57dr7b@corp.supernews.com> <dn350c$m1p$1@panix3.panix.com> Message-ID: <17301.31242.965031.317886@montanaro.dyndns.org> >> Hmm, I though he explained it: >> >> 1) Not using your real name. >> >> 2) A yahoo, aol, or hotmail address. >> >> In the ancient and hallowed (by net standards) history of Usenet, both >> of these (particularly the first one) have been pretty good predictors >> of crankness. aahz> I've been on the Net for more than fifteen years, and while this aahz> canard about real names gets trotted out from time to time, it's aahz> quite clear that many many people have been active on the Net aahz> *and* taken seriously using names that aren't what you'd call a aahz> "real name". As the person who raised this particular flag, I will note a few things: 1. Monty Python humor aside, this is generally a serious mailing list and newsgroup. In my experience, most people deal professionally with others of like interests by using their real names. 2. While I haven't been to many PyCons, I've been to enough to have met many Python folk. Hell, maybe I've met rurpy and don't even know it. Real people have real names. Using your real name on the net makes you less virtual to the people you communicate with. 3. I'm an Internet dinosaur. I date from the time before l33t speak, the Morris worm, spam and Windows increased the need for people to hide behind virtual masks and throw away email addresses every few months. At the dawn of time, basically everyone used their real names. It's probably just my misunderstanding about how people use avatars on the net nowadays, but I still expect professional people to communicate profesionally. That includes using real names. For completeness, though I usually don't here, my full sig: -- Skip Montanaro Katrina Benefit Concerts: http://www.musi-cal.com/katrina skip at pobox.com From peter.mosley at talk21.com Tue Dec 20 03:39:01 2005 From: peter.mosley at talk21.com (peter.mosley at talk21.com) Date: 20 Dec 2005 00:39:01 -0800 Subject: Unable to install Python Imaging Library References: <1134939843.351677.28060@f14g2000cwb.googlegroups.com> <mailman.2278.1134940953.18701.python-list@python.org> Message-ID: <1135067941.359344.81590@g47g2000cwa.googlegroups.com> Thanks for that reply. I hadn't tried installing the Tcl and Tk development libraries - because I had no idea these that these were necessary (or that they even existed!). My first attempt to do so was a total failure, as I downloaded the RPM files from http://rpmfind.net, but immediately entered a dependency hell. My next attempt was a little more thought out - I looked for the appropriate files on some Fedora Core 1 distribution discs, and to my surprise found them. To my even greater surprise, I could load these without problems and then the PIL install ran smoothly. So thanks to your hint I have got there. Much appreciated. Peter From rudysanford at hotmail.com Wed Dec 14 13:43:55 2005 From: rudysanford at hotmail.com (rudysanford at hotmail.com) Date: 14 Dec 2005 10:43:55 -0800 Subject: Worthwhile to reverse a dictionary In-Reply-To: <43a05dc4$0$29563$da0feed9@news.zen.co.uk> References: <1134582611.355566.198990@g14g2000cwa.googlegroups.com> <43a05dc4$0$29563$da0feed9@news.zen.co.uk> Message-ID: <1134585835.467731.20610@g43g2000cwa.googlegroups.com> Thanks so much. That seems to have it. This is the sort of thing I had before: #!/usr/local/bin/python # make a short dictionary d1 = {'A' : '1', 'B' : '2', 'C' : '3'} for letter in d1.keys(): print letter, '\t', d1[letter] # make a space between the output of the 2 dictionaries print '\n' # reverse the keys and values from the first dictionary # from this point many things were tried, about the best I achieved was # getting the last key/value pair as displayed when printing the d1 # it was properly reversed but there was only one pair d2 = {d1[letter] : letter} for num in d2.keys(): print num, '\t', d2[num] This displays A 1 C 3 B 2 2 B From gutfreund at kessertech.com Thu Dec 15 12:20:36 2005 From: gutfreund at kessertech.com (Yechezkal Gutfreund) Date: Thu, 15 Dec 2005 12:20:36 -0500 Subject: SPE 0.8.1.b Python IDE (complete rewrite for running files) Message-ID: <005501c6019b$dd52fd40$3501a8c0@KESSER> Are you familiar with any Python efforts that parrallel Ruby on Rails (integrated Ajax compliant IDE?). <spe.stani.be at gmail.com> wrote in message news:<mailman.2149.1134654745.18701.python-announce-list at python.org>... > Release news from http://pythonide.stani.be > > This release is the result of a complete rewrite of the run system. > It's now possible to run multi-threaded applications (like wxPython, > gtk, ...) with SPE and still control them through the debugger. Also > selected text can be executed in the shell. > > Read more at http://pythonide.stani.be/manual/html/manual3.html (see > 1.3 Running files). > > New features: > * launch the debugger at any time at a running script > * launch the debugger at unhandled exceptions when running your > script > * execute selected lines as code snippets in the shell > > Improved features: > * redesigned toolbar > > Bug fixes: > * Show/hide shell (Mac) > * Check run (0.8.1.b) > > Installation: > * See http://pythonide.stani.be/manual/html/manual2.html > * There is now an update section for MacOS X! > > Contributors: > * Nir Aides (debug support) > * Thurston Stone (bug report) > > Development: > * http://developer.berlios.de/mail/?group_id=4161 > > Donations (thanks!): > * Widhaya Trisarnwadhana > > About SPE: > SPE is a python IDE with auto-indentation, auto completion, call tips, > syntax coloring, uml viewer, syntax highlighting, class explorer, > source index, auto todo list, sticky notes, integrated pycrust shell, > python file browser, recent file browser, drag&drop, context help, ... > Special is its blender support with a blender 3d object browser and its > ability to run interactively inside blender. Spe integrates with XRCed > (gui > designer) and ships with wxGlade (gui designer), PyChecker (source > code doctor), Kiki (regular expression console) and WinPdb (remote, > multi-threaded debugger). > > SPE is looking for native English speakers to review its manual. > > The development of SPE is driven by its donations. Anyone who donates > can ask for an nice pdf version of the manual without ads (60 pages). > From mhellwig at xs4all.nl Tue Dec 27 04:32:28 2005 From: mhellwig at xs4all.nl (Martin P. Hellwig) Date: Tue, 27 Dec 2005 10:32:28 +0100 Subject: [EVALUATION] - E04 - Leadership! Google, Guido van Rossum, PSF In-Reply-To: <donih3$sb2$1@usenet.otenet.gr> References: <donih3$sb2$1@usenet.otenet.gr> Message-ID: <43b10a64$0$11065$e4fe514c@news.xs4all.nl> Ilias Lazaridis wrote: <cut> So I guess you volunteer http://www.python.org/psf/volunteer.html ? -- mph From gregpinero at gmail.com Thu Dec 15 00:14:10 2005 From: gregpinero at gmail.com (=?ISO-8859-1?Q?Gregory_Pi=F1ero?=) Date: Thu, 15 Dec 2005 00:14:10 -0500 Subject: Optimize function similiar to dict.update() but adds common values In-Reply-To: <312cfe2b0512141017x2b38267bhc1202b4d9b87c6f@mail.gmail.com> References: <mailman.2089.1134572647.18701.python-list@python.org> <dnpfsp$pvm$02$1@news.t-online.com> <mailman.2096.1134578871.18701.python-list@python.org> <dnpk8b$8eh$01$1@news.t-online.com> <312cfe2b0512141017x2b38267bhc1202b4d9b87c6f@mail.gmail.com> Message-ID: <312cfe2b0512142114l65a15880gde1a6a2ffa536a67@mail.gmail.com> OK, I ran Peter's add_freq3 and it ran four times on really large dictionaries in about 3000 seconds. So I'd say that at a minimum that's ten times faster than my original function since it ran all last night and didn't finish. Much obliged, Peter! -Greg On 12/14/05, Gregory Pi?ero <gregpinero at gmail.com> wrote: > Yes, that makes sense. I can't wait to run it tonight. Sorry I can't > give you the running time of my original function as it never finished > :-( > > I'll report back the running time of the new function though, assuming > it finishes ;-) > > Thanks again, > > -Greg > > > On 12/14/05, Peter Otten <__peter__ at web.de> wrote: > > Gregory Pi?ero wrote: > > > > > Here's a question about your functions. if I only look at the keys in > > > freq2 then won't I miss any keys that are in freq1 and not in freq2? > > > > No. As I start with a copy of freq1, all keys of freq1 are already there. > > There is probably a loop involved, but it in Python's underlying C > > implementation, which is a bit faster. > > > > What is left to do is to (1) add key and value for the 20% of freq2 that are > > not in freq1, and to (2) increase the value for the 80% where the key > > occurs in both freq1 and freq2. This is done by the for-loop. > > > > Peter > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > > -- > Gregory Pi?ero > Chief Innovation Officer > Blended Technologies > (www.blendedtechnologies.com) > -- Gregory Pi?ero Chief Innovation Officer Blended Technologies (www.blendedtechnologies.com) From mahs at telcopartners.com Mon Dec 12 19:09:52 2005 From: mahs at telcopartners.com (Michael Spencer) Date: Mon, 12 Dec 2005 16:09:52 -0800 Subject: Pattern matching with string and list In-Reply-To: <1134428753.217125.185700@o13g2000cwo.googlegroups.com> References: <1134428753.217125.185700@o13g2000cwo.googlegroups.com> Message-ID: <dnl3gf$k3c$1@sea.gmane.org> olaufr at gmail.com wrote: > Hi, > > I'd need to perform simple pattern matching within a string using a > list of possible patterns. For example, I want to know if the substring > starting at position n matches any of the string I have a list, as > below: > > sentence = "the color is $red" > patterns = ["blue","red","yellow"] > pos = sentence.find($) > # here I need to find whether what's after 'pos' matches any of the > strings of my 'patterns' list > bmatch = ismatching( sentence[pos:], patterns) > > Is an equivalent of this ismatching() function existing in some Python > lib? > > Thanks, > > Olivier. > As I think you define it, ismatching can be written as: >>> def ismatching(sentence, patterns): ... re_pattern = re.compile("(%s)\Z" % "|".join(patterns)) ... return bool(re_pattern.match(sentence)) ... >>> ismatching(sentence[pos+1:], patterns) True >>> ismatching(sentence[pos+1:], ["green", "blue"]) False >>> (For help with regular expressions, see: http://www.amk.ca/python/howto/regex/) or, you can ask the regexp engine to starting looking at a point you specify: >>> def ismatching(sentence, patterns, startingpos = 0): ... re_pattern = re.compile("(%s)\Z" % "|".join(patterns)) ... return bool(re_pattern.match(sentence, startingpos)) ... >>> ismatching(sentence, patterns, pos+1) True >>> but, you may be able to save the separate step of determining pos, by including it in the regexp, e.g., >>> def matching(patterns, sentence): ... re_pattern = re.compile("\$(%s)" % "|".join(patterns)) ... return bool(re_pattern.search(sentence)) ... >>> matching(patterns, sentence) True >>> matching(["green", "blue"], sentence) False >>> then, it might be more general useful to return the match, rather than the boolean value - you can still use it in truth testing, since a no-match will evaluate to False >>> def matching(patterns, sentence): ... re_pattern = re.compile("\$(%s)" % "|".join(patterns)) ... return re_pattern.search(sentence) ... >>> if matching(patterns, sentence): print "Match" ... Match >>> Finally, if you are going to be doing a lot of these it would be faster to take the pattern compilation out of the function, and simply use the pre-compiled regexp, or as below, its bound method: search: >>> matching = re.compile("\$(%s)\Z" % "|".join(patterns)).search >>> matching(sentence) <_sre.SRE_Match object at 0x01847E60> >>> bool(_) True >>> bool(matching("the color is $red but there is more")) False >>> bool(matching("the color is $pink")) False >>> bool(matching("the $color is $red")) True >>> HTH Michael From me at privacy.net Thu Dec 22 19:44:02 2005 From: me at privacy.net (Dan Sommers) Date: Thu, 22 Dec 2005 19:44:02 -0500 Subject: Socket programming design problem References: <1135289529.7a1ac2eff304702d3cf8046581abe51b@roc.usenetexchange.com> Message-ID: <m2zmmszlpp.fsf@unique.fqdn> On Thu, 22 Dec 2005 22:12:09 +0000, David <null at example.net> wrote: > a) Big problem, I can't see how to receive from more than one socket > at once. I need to do this so that data from the TCP connection can > be sent out on the UDP one and vice versa. Do I need a thread for > each, or is there some other way I can listen on two sockets at once > (maybe non-blocking ones?) Try the select module: http://www.python.org/doc/current/lib/module-select.html Regards, Dan -- Dan Sommers <http://www.tombstonezero.net/dan/> From kent at kentsjohnson.com Fri Dec 23 08:35:14 2005 From: kent at kentsjohnson.com (Kent Johnson) Date: Fri, 23 Dec 2005 08:35:14 -0500 Subject: Detect File System changes In-Reply-To: <1135337753.570684.193960@f14g2000cwb.googlegroups.com> References: <1135337753.570684.193960@f14g2000cwb.googlegroups.com> Message-ID: <43abf9c4$1_3@newspeer2.tds.net> Lukas Meyer wrote: > Hello, > > I'm trying to detect changes in a directory. E.g if someone crates a > file, i'll execute another function on this file. > > I tried to solve this by creating a loop that permanently checks the > contents of this directory with os.listdir() and compares it with the > one before. But this isn't really working properly. > > Can anyone give me a hint to get this working? We just had a thread on this topic: http://groups.google.com/group/comp.lang.python/browse_frm/thread/b8808c14ecd333ab/ca7110a9776904eb?rnum=4#ca7110a9776904eb Kent From steve at holdenweb.com Wed Dec 14 09:44:01 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed, 14 Dec 2005 14:44:01 +0000 Subject: First practical Python code, comments appreciated In-Reply-To: <9OVnf.47280$%i.23808@tornado.texas.rr.com> References: <1134561240.888915.181440@f14g2000cwb.googlegroups.com> <mailman.2080.1134563479.18701.python-list@python.org> <9OVnf.47280$%i.23808@tornado.texas.rr.com> Message-ID: <43A02FB1.708@holdenweb.com> Paul McGuire wrote: [...] > portability is an n-way street. +1 QOTW regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From steve at holdenweb.com Tue Dec 13 12:19:01 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 13 Dec 2005 17:19:01 +0000 Subject: IsString In-Reply-To: <Pine.LNX.4.62.0512131521420.25594@urchin.earth.li> References: <1134404765.862884.296050@g49g2000cwa.googlegroups.com> <gY-dnW3ANpQDdwDe4p2dnA@comcast.com> <pan.2005.12.12.22.35.23.727622@REMOVETHIScyber.com.au> <GaudnXMLt4uLhgPeRVn-vQ@comcast.com> <pan.2005.12.13.11.51.46.230681@REMOVETHIScyber.com.au> <Pine.LNX.4.62.0512131521420.25594@urchin.earth.li> Message-ID: <dnmvq8$ann$1@sea.gmane.org> Tom Anderson wrote: > On Tue, 13 Dec 2005, Steven D'Aprano wrote: > > >>On Mon, 12 Dec 2005 18:51:36 -0600, Larry Bates wrote: >> >>[snippidy-doo-dah] >> >> >>>I had the same thought, but reread the post. He asks "if a given >>>variable is a character or a number". I figured that even if he is >>>coming from another language he knows the difference between "a given >>>variable" and the "contents of a give variable". I guess we will >>>see.... ;-). This list is so good, he gets BOTH questions answered. >> >>The problem is, Python doesn't have variables (although it is >>oh-so-tempting to use the word, I sometimes do myself). It has names in >>namespaces, and objects. > > > In what sense are the names-bound-to-references-to-objects not variables? > In a very important sense, one which you should understand in order to understand the nature of Python. In C if you declare a variable as (for example) a character string of length 24, the compiler will generate code that allocates 24 bytes to this variable on the stack frame local to the function in which it's declared. Similarly if you declare a variable as a double-length floating point number the compiler will emit code that allocates 16 bytes on the local stack-frame. In Python a name (*not* a "variable", though people do talk loosely about "instance variables" and "class variables" just to be able to use terms familiar to users of other to languages) is simply *bound* to a value. The only storage that is required, therefore, is enough to hold a pointer (to the value currently bound to the name). Thus assignment (i.e. binding to a name, as opposed to binding to an element of a data structure) NEVER copes the object, it simply stores a pointer to the bound object in the part of the local namespace allocated to that name. > >>It be a subtle difference, but an important one. > > > No, it's just spin, bizarre spin for which i can see no reason. Python has > variables. > You appear very confident of your ignorance ;-) > >>That's why, for instance, Python is neither call by reference nor call >>by value, it is call by object. > > > No, python is call by value, and it happens that all values are pointers. > Just like java, but without the primitive types, and like LISP, and like a > load of other languages. Python's parameter passing is NO DIFFERENT to > that in those languages, and those languages are ALL described as > call-by-value, so to claim that python does not use call-by-reference but > some random new 'call-by-object' convention is incorrect, unneccessary, > confusing and silly. > > </rant> > > I'm sure this has been argued over many times here, and we still > all have our different ideas, so please just ignore this post! > Couldn't! I do apologise, though, for any implication you assertions are based on ignorance because you do demonstrate quite a sophisticated knowledge of what goes on under the hood. As long as you can accept that "Python 'variables' are all references" then the rest is indeed semantics. Of course it will be helpful for newcomers if we can adopt a standard terminology ... regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From drew.smathers at gmail.com Thu Dec 22 14:15:49 2005 From: drew.smathers at gmail.com (drew.smathers at gmail.com) Date: 22 Dec 2005 11:15:49 -0800 Subject: Guido at Google References: <43a939e3$0$23986$626a14ce@news.free.fr> <1135165473.419546.212040@g49g2000cwa.googlegroups.com> <1h7wvw8.1of7z5vg23o7eN%aleax@mail.comcast.net> <1135184227.795949.257840@f14g2000cwb.googlegroups.com> <1135215046.296776.281710@g49g2000cwa.googlegroups.com> <dodi54$4a0$1@usenet.otenet.gr> Message-ID: <1135278949.011172.272620@g47g2000cwa.googlegroups.com> And I have around one year to wait for Ruby to get rid of the nasty syntax copied from Perl and make it look as beautiful as Python .... Then I'll consider switching. ;) Ummm, I'm sorry, did you say clean reflective meta-model??? So this: caller[0] =~ /in `([^']+)'/ ? $1 : '(anonymous)' vs. the python example: filename, line, fname, source = traceback.extract_stack(limit=2)[0] return fname is what you call clean?? Hmmm ... interesting. From laurentlaporte at yahoo.com Wed Dec 28 05:48:03 2005 From: laurentlaporte at yahoo.com (Laurent Laporte) Date: 28 Dec 2005 02:48:03 -0800 Subject: csv.Sniffer: wrong detection of the end of line delimiter Message-ID: <1135766883.689923.45080@g47g2000cwa.googlegroups.com> hello, I'm using cvs standard module under Python 2.3 / 2.4 to read a CSV file. The file is opened in binary mode, so I keep the end of line terminator. It appears that the csv.Sniffer force the line terminator to be '\r\n'. It's fine under Windows but wrong under Linux or Macintosh. More about this line terminator: Potential bug in the _guess_delimiter() method. The first line of code does a wrong splitting: data = filter(None, data.split('\n')) It doesn't take care of the real line terminator! Here is a patch (not a perfect one): # ------- begin of patch ------- class PatchedSniffer(csv.Sniffer): def __init__(self): csv.Sniffer.__init__(self) def sniff(self, p_data, p_delimiters = None): t_dialect = csv.Sniffer.sniff(self, p_data, p_delimiters) t_dialect.lineterminator = self._guessLineTerminator(p_data) return t_dialect def _guessLineTerminator(self, p_data): for t_lineTerminator in ['\r\n', '\n', '\r']: if t_lineTerminator in p_data: return t_lineTerminator else: return '\r\n' # Windows default (Excel) def _formatDataForGuess(self, p_data): t_lineTerminator = self._guessLineTerminator(p_data) return '\n'.join(p_data.split(t_lineTerminator)) def _guess_delimiter(self, p_data, p_delimiters): t_data = self._formatDataForGuess(p_data) (t_delimiter, t_skipInitialSpace) = \ csv.Sniffer._guess_delimiter(self, t_data, p_delimiters) if t_delimiter == '' and '\t' in p_data: t_delimiter = '\t' return (t_delimiter, t_skipInitialSpace) # ------- end of patch ------- Bye. ------- Laurent. From alvarof at freeshell.org Thu Dec 15 07:34:51 2005 From: alvarof at freeshell.org (Alvaro Figueiredo) Date: Thu, 15 Dec 2005 10:34:51 -0200 Subject: iniciante In-Reply-To: <1134614016.536447.143840@f14g2000cwb.googlegroups.com> References: <1134614016.536447.143840@f14g2000cwb.googlegroups.com> Message-ID: <200512151034.51420.alvarof@freeshell.org> At Thursday 15 December 2005 00:33, tetri wrote: > algu?m recomenda algum material dispon?vel na internet para iniciar > os estudos em python? > outra coisa, pe?o que brasileiros (ou ao menos aqueles que me > entendem) se identifiquem, assim podemos come?ar discuss?es em > portugu?s mesmo, o que acham? There is a brazilian mail list for python in the site below. H? uma lista de e-mail brasileira de Python no site abaixo. http://www.pythonbrasil.com.br/ -- Alvaro Figueiredo alvarof at freeshell.org From farproc at gmail.com Tue Dec 27 21:15:53 2005 From: farproc at gmail.com (Kevin Yuan) Date: Wed, 28 Dec 2005 10:15:53 +0800 Subject: Redirecting both stdout and stderr to the same file In-Reply-To: <s3b1644f.016@dfw-gwd.dfw.wa.gov> References: <s3b1644f.016@dfw-gwd.dfw.wa.gov> Message-ID: <4ab8749e0512271815q49cae159o@mail.gmail.com> You should redirecte sys.stderr if you want to log error message. saveout = sys.stdout saveerr = sys.stderr fsock = open('runtime.log', 'w') sys.stdout = sys.stderr = fsock 2005/12/28, Randy Kreuziger <KREUZRSK at dfw.wa.gov>: > > Can stdout and stderr be redirected to the same file? I would like to > redirect both to the same file but I'm not sure how to do it. Currenting > I'm redirectiong stdout using the following code: > saveout = sys.stdout > fsock = open('runtime.log', 'w') > sys.stdout = fsock > > The problem is that when en error occurs that my program was not written > to handle that error message is being sent to the cmd window and not my log > file. My program may simply need to be more robust however I'm still a > python novice. > > Thanks > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-list/attachments/20051228/19695258/attachment.html> From kevin.dahlhausen at gmail.com Thu Dec 15 23:11:10 2005 From: kevin.dahlhausen at gmail.com (kevin.dahlhausen at gmail.com) Date: 15 Dec 2005 20:11:10 -0800 Subject: Swig-Mingw-DistUtil Extension - Entry Point Not Found? In-Reply-To: <1133506676.670582.283590@g49g2000cwa.googlegroups.com> References: <1133506676.670582.283590@g49g2000cwa.googlegroups.com> Message-ID: <1134706270.891911.20310@g49g2000cwa.googlegroups.com> I was able to build a working extension module under 2.4 / cygwin-mingw by declaring the following: short ** _imp___ctype = 0; ( I put it at the top of my swig .i file ). This potentially dangerous tip is from: http://www.nabble.com/msvcr71-t336430.html From stevecanfield at yahoo.com Wed Dec 14 15:16:22 2005 From: stevecanfield at yahoo.com (stevecanfield at yahoo.com) Date: 14 Dec 2005 12:16:22 -0800 Subject: set & random.choice question Message-ID: <1134591382.203393.79510@g14g2000cwa.googlegroups.com> I want to do something like this: from random import choice x = set(("jenny", "jacqui", "claire", "chris", "tracy")) somebody = random.choice(x) but I bet a "TypeError: unindexable object" error. Any suggestions for an elegant workaround? I'm using set because I want to know that I have a collection of unique objects. steve From tim.leeuwvander at nl.unisys.com Thu Dec 22 08:15:38 2005 From: tim.leeuwvander at nl.unisys.com (Tim N. van der Leeuw) Date: 22 Dec 2005 05:15:38 -0800 Subject: Parsing a date-time string? In-Reply-To: <mailman.2412.1135219448.18701.python-list@python.org> References: <1135158192.987122.245440@g43g2000cwa.googlegroups.com> <1135158829.072060.282770@g47g2000cwa.googlegroups.com> <1d987df30512211835q70bf924el54e9f500854f6592@mail.gmail.com> <mailman.2412.1135219448.18701.python-list@python.org> Message-ID: <1135257338.892628.259040@g47g2000cwa.googlegroups.com> I downloaded the tar.bz2 file, extracted it, and had no problem building it and creating a windows installer using 'python ./setup.py bdist_wininst' This windows installer I then used to install it via the 'official windows' way :) luck, --Tim From aleax at mail.comcast.net Thu Dec 22 04:08:09 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Thu, 22 Dec 2005 01:08:09 -0800 Subject: Guido at Google References: <43a939e3$0$23986$626a14ce@news.free.fr> <1135174003.737464.211650@g43g2000cwa.googlegroups.com> <1135192878.129577.257820@g49g2000cwa.googlegroups.com> <1135232795.170575.184780@g14g2000cwa.googlegroups.com> <1135233297.257898.180320@f14g2000cwb.googlegroups.com> <1h7y24z.q9skb3o6gmm5N%aleax@mail.comcast.net> <1135239242.808041.180310@g43g2000cwa.googlegroups.com> <1h7y3oi.14k93kylxmcr4N%aleax@mail.comcast.net> <1135240816.215541.127520@z14g2000cwz.googlegroups.com> Message-ID: <1h7y5c2.1o5j3p21ikcpmkN%aleax@mail.comcast.net> <bonono at gmail.com> wrote: ... > > > > > I wonder how high a particular programming language is in the prioirty > > > > > of either organisations of such size ? ... > from me), there really is nothing I can do other changing the mail name > which I am intended to. Sorry, can't parse this (I doubt it's English). > What is your meaning of "wrong idea in the general case" ? In the general case, it's pretty general;-). In the specific case of your "question" above quoted (interpreting the mis-spelled words and grammatical errors to the best of my modest ability), reading it as rhetorical means it's in fact intended as a statement (that a particular programming language cannot have high priority for organizations of size similar to MS's and Google's), and such a statement is incorrect (as I tried showing with several examples displaying "particular programming languages" having high strategical priorities for organizations with many thousands of employees, including one with more personnel [larger size] than Google's). An example of rhetorical question: "Do you really think that a specific technology [including a software one, such as a programming language] cannot have, in certain cases, *extremely high* strategic priority for organizations with thousands of employees?" In this example, the question is phrased to hint at how silly such an opinion would be, and therefore imply that you can't really think that (and must have ulterior motives for so suggesting, etc etc). Rhetorical questions are a perfectly legitimate style of writing (although, like all stylistic embellishments, they can be overused, and can be made much less effective if murkily or fuzzily phrased), of course. Alex From steve at REMOVETHIScyber.com.au Wed Dec 7 13:20:25 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Thu, 08 Dec 2005 05:20:25 +1100 Subject: ANN: Dao Language v.0.9.6-beta is release! References: <1133174924.322968.273370@o13g2000cwo.googlegroups.com> <1133696971.466976.213370@f14g2000cwb.googlegroups.com> <mailman.1559.1133697611.18701.python-list@python.org> <1133702966.030710.51090@g47g2000cwa.googlegroups.com> <Pine.LNX.4.62.0512042209410.17499@urchin.earth.li> <1133776917.483883.150120@o13g2000cwo.googlegroups.com> <1133788564.145604.234630@g49g2000cwa.googlegroups.com> <1133868635.352421.97010@g43g2000cwa.googlegroups.com> <1133905766.918194.210850@o13g2000cwo.googlegroups.com> <slrndpd5l2.jsc.apardon@rcpc42.vub.ac.be> <slrndpdvq3.bh1.mordor@fly.srk.fer.hr> Message-ID: <pan.2005.12.07.18.20.24.981816@REMOVETHIScyber.com.au> On Wed, 07 Dec 2005 15:26:59 +0000, Zeljko Vrba wrote: > Braces are very convenient to match block start and end. Open a C program > in the VI editor, and press % in command mode on some brace.. It will take > you to its matching brace. How do you do something like that with python code > (or any code that is based purely on indentation..) (1) You don't need to, because you can *see* where the indentation changes, so you don't need to rely on your editor counting for you. (2) And if you do need to, then you should use a smarter editor that understands indentation levels, not just braces. Braces are superfluous if you use consistent indentation, and indentation is superfluous -- to the compiler -- if you use braces. But indentation is *not* superfluous to the human eye: we can parse indentation very easily, but nested braces/brackets only with great difficulty. That's why programmers in languages that ignore indentation still indent their code, or at least the sensible ones do. -- Steven. From muttu2244 at yahoo.com Tue Dec 27 22:29:12 2005 From: muttu2244 at yahoo.com (muttu2244 at yahoo.com) Date: 27 Dec 2005 19:29:12 -0800 Subject: query on python list Message-ID: <1135740552.280991.142380@z14g2000cwz.googlegroups.com> hi all am searching for a key in a list, am using Found = 0 for item in list: if not key == item: Found = 0 elif key == item: Found =1 Now based on the Found value i ll manipulate the list. but whenever the "key and item" doesnt match it makes "Found = 0", even though i have an item that matches the key, but it overwrites the Found variable to 0, in the next loop when "key ! = item", and hence all my calculations are going wrong, If i find a key in my list, some how the variable "Found " should be 1,till it comes out of the loop. How can i do that. thanks in advance yogi From pydecker at gmail.com Tue Dec 27 14:08:15 2005 From: pydecker at gmail.com (Peter Decker) Date: Tue, 27 Dec 2005 14:08:15 -0500 Subject: Beautiful Python In-Reply-To: <1135706537.090717.116880@z14g2000cwz.googlegroups.com> References: <1135591267.398830.129050@g44g2000cwa.googlegroups.com> <1135632760.677540.108550@z14g2000cwz.googlegroups.com> <1135706537.090717.116880@z14g2000cwz.googlegroups.com> Message-ID: <ca55a9900512271108l6b8f9983r71b6ed49e3954f42@mail.gmail.com> On 27 Dec 2005 10:02:17 -0800, Gekitsuu <gekitsuu at gmail.com> wrote: > My > hypothetical situation was as follows. I'm writing a new generic SQL > module and I want to make it so I only call the appropriate module for > the type of SQL server I'm talking to. Then it would make sense to > load, for instance, the mysql module and not the sqlite, postgresql, > etc. You should take a look at the Dabo project. The dabo.db module take a setting and imports just the required library for the chosen database. It really isn't that difficult a concept to handle. -- # p.d. From mwilliams at mgreg.com Sun Dec 11 09:54:15 2005 From: mwilliams at mgreg.com (Michael Williams) Date: Sun, 11 Dec 2005 09:54:15 -0500 Subject: Using XML w/ Python... In-Reply-To: <mailman.10495.1134281704.18700.python-list@python.org> References: <mailman.10495.1134281704.18700.python-list@python.org> Message-ID: <70EFC4EA-4877-488F-8CF7-40CA32860420@mgreg.com> If you just want to get into it and use it, I'd recommend the following: http://uche.ogbuji.net/uche.ogbuji.net/tech/4suite/amara/ It requires the installation of the 4Suite module as well, but it's well worth it. I uses data binding techniques to convert your document into a large tree of named XML Object (for lack of a better explanation). You will then be able to output any portion by calling something like the following: document.body.text.xml() What you call, of course, will depend on the name of each of your nodes in the document. Keep in mind as well that currently there are a couple of issues with "freezing" this into a binary as well. If you just plan to let Python interpret it without "compiling" you will be fine. Amara is an amazing product. And being free doesn't hurt. ;) Regards, Michael On Dec 11, 2005, at 1:15 AM, python-list-request at python.org wrote: > OK, I have this XML doc, i dont know much about XML, but what i want > to do is take certain parts of the XML doc, such as blah > and take just that and put onto a text doc. Then same thing > doe the part. Thats about it, i checked out some of the xml > modules but dont understand how to use them. Dont get parsing, so if > you could please explain working with XML and python to me. Email > me at > jmailone at gmail.com > > Aim- jayjay08balla > MSN- Jmailone at gmail.com > Yahoo- raeraefad72 > > > Thx -------------- next part -------------- An HTML attachment was scrubbed... URL: From python-url at phaseit.net Tue Dec 27 19:08:04 2005 From: python-url at phaseit.net (Cameron Laird) Date: Wed, 28 Dec 2005 00:08:04 GMT Subject: Dr. Dobb's Python-URL! - weekly Python news and links (Dec 27) Message-ID: QOTW: "My wild-ass guess is that, same as most other Open Source communities, we average about one asshole per member." - Tim Peters http://groups.google.com/group/comp.lang.python/msg/02236cc5ab54fd90?hl=en "[T]he only fundamentally new concept that has been added since Python 1.5.2 is generators. And a lot of the stuff you want generators for can be emulated with sequences and extra buffer layers." - Fredrik Lundh gene tani and Olivier Grisel collect information about memory- and time-profiling: http://groups.google.com/group/comp.lang.python/browse_thread/thread/6186ae64a564ad5a/ Python builds in a convenience for, "this segment of code isn't finished." http://groups.google.com/group/comp.lang.python/browse_thread/thread/3179dcce33a33fbb/ You want to constrain the time allowed to a particular Python function to execute. A reasonably standard solution is available. To limit *two* potentially concurrent functions, though ... well, that's not a strength of Python: http://groups.google.com/group/comp.lang.python/browse_thread/thread/bd808b80fc8191/ Contest your Python coding: http://groups.google.com/group/comp.lang.python/browse_thread/thread/ac7fdb93af4e0b2f/ Sorting depends on comparisons. It is NOT possible, in general, to memoize these comparisons, in the sense that the Python run-time library should take on the responsibility for developers. DSU and other situation-specific strategies always remains available, of course: http://groups.google.com/group/comp.lang.python/msg/8007c9d7fabe6223 http://groups.google.com/group/comp.lang.python/browse_thread/thread/773d64e6d8b77802/ Yes, Guido's at Google. He'll work on and with Python. How much more "official" do you need it to be? http://groups.google.com/group/comp.lang.python/browse_thread/thread/32dc95bd671542f3/ Peter Hansen and David Wahler lucidly explain how hard it is to keep even a little security. A digital datum in any one useful place is likely to leak all over, even for a problem as seemingly simple as protection of a password used for cron-automated access: http://groups.google.com/group/comp.lang.python/browse_thread/thread/b8bdb21a084d6a99/ Is it "humane" that Ruby typically abbreviates "get(end)" as "last"? Dave Benjamin and Kent Johnson discuss the matter seriously and usefully (with examples!): http://groups.google.com/group/comp.lang.python/browse_thread/thread/d2ada62cd187dd65/ ======================================================================== 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. For far, FAR more Python reading than any one mind should absorb, much of it quite interesting, several pages index much of the universe of Pybloggers. http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog http://www.planetpython.org/ http://mechanicalcat.net/pyblagg.html 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 Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous tradition early borne by Andrew Kuchling, Michael Hudson and Brett Cannon 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/ 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 Kurt B. Kaiser publishes a weekly report on faults and patches. http://www.google.com/groups?as_usubject=weekly%20python%20patch 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. del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python *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/topic/python/ (requires subscription) http://groups-beta.google.com/groups?q=python-url+group:comp.lang.python*&start=0&scoring=d& 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 There is *not* an RSS for "Python-URL!"--at least not yet. Arguments for and against are occasionally entertained. 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 apardon at forel.vub.ac.be Tue Dec 13 04:25:57 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 13 Dec 2005 09:25:57 GMT Subject: "0 in [True,False]" returns True References: <439deb17$0$18320$8fcfb975@news.wanadoo.fr> Message-ID: Op 2005-12-13, Steve Holden schreef : > Pierre Quentel wrote: >> Hi all, >> >> In some program I was testing if a variable was a boolean, with this >> test : if v in [True,False] >> >> My script didn't work in some cases and I eventually found that for v = >> 0 the test returned True >> >> So I changed my test for the obvious "if type(v) is bool", but I still >> find it confusing that "0 in [True,False]" returns True >> >> By the way, I searched in the documentation what "obj in list" meant and >> couldn't find a precise definition (does it test for equality or >> identity with one of the values in list ? equality, it seems) ; did I >> miss something ? >> > It actually uses the __contains__() method of the right-hand operand, > and in the case of a list that will test for equality of the left-hand > operand to one of the list elements. Since False == 0 that's why you see > what you do. > > The really interesting question your post raises, though, is "Why do you > feel it's necessary to test to see whether a variable is a Boolean?". I can give you one example. I have written a tube class. A tube behaves like Queue but it has additional code so that it can be registed with gtk in the same way as file descriptor can be registered with io_add_watch. The way this is implemented is by registering an idle handler when the tube is not empty and removing it when the tube is empty. So I have a variable cb_src (for callback source) that can be a boolean or an integer. The possible values are False: Not registered by the user True: Registered by the user but no nternal idle callback registerd a number: gtk integer ID, from the registered idle callback handler. -- Antoon Pardon From aleax at mail.comcast.net Sat Dec 10 11:15:28 2005 From: aleax at mail.comcast.net (Alex Martelli) Date: Sat, 10 Dec 2005 08:15:28 -0800 Subject: Another newbie question References: <863bl4xk11.fsf@bhuda.mired.org> <864q5jxjbj.fsf@bhuda.mired.org> <1h79nd4.s908ow1e76823N%aleax@mail.comcast.net> <86r78mx552.fsf@bhuda.mired.org> <1h7akp2.7ljit93a0eayN%aleax@mail.comcast.net> <86irtxx577.fsf@bhuda.mired.org> <1h7bft4.by5ylo1addna9N%aleax@mail.comcast.net> <86ek4lvd2n.fsf@bhuda.mired.org> Message-ID: <1h7cfhv.1m0zh81bgpm6kN%aleax@mail.comcast.net> Mike Meyer wrote: ... > >> it. Nothing you do with zim.foo or zim.foo.bar can change the state of > >> zim. The only invariants you need to check are bar's, which you do at > >> the exit to it's baz method. > > So foo's class is not allowed to have as its invariant any formula > > depending on the attributes of its attribute bar, such as "bar.x>23" or > > the like? > > Of course you can do such things. But it's a silly thing to do. That I guess this is the crux of our disagreement -- much like, it seems to me, your disagreement with Xavier and Steven on the other half of this thread, as I'll try to explain in the following. > invariant should be written as x > 23 for the class bar is an instance Let's, for definiteness, say that bar is an instance of class Bar. Now, my point is that absolutely not all instances of Bar are constrained to always have their x attribute >23 -- in general, their x's can vary all over the place; rather, the constraint applies very specifically to this one instance of Bar -- the one held by foo (an instance of Foo) as foo's attribute bar. Let's try to see if I can make a trivially simple use case. Say I'm using a framework to model statical structures in civil engineering. I have classes such as Truss, Beam, Pier, Column, Girder, and so forth. So in a given structure (class Foo) I might have a certain instance of Beam, attribute beam1 of instances of Foo, which carries a certain load (dependent on the overall loads borne by each given instance of Foo), and transfers it to an instance of Pier (attribute pier1 of instances of Foo) and one of Girder (attribute girder1 ditto). Each of these structural elements will of course be able to exhibit as attributes all of its *individual* characteristics -- but the exact manner of *relationship* between the elements depends on how they're assembled in a given structure, and so it's properly the business of the structure, not the elements. So, one invariant that had better hold to ensure a certain instance foo of Foo is not about to crash, may be, depending on how Foo's detailed structual geometry is, something like: foo.beam1.force_transferred_A <= foo.pier1.max_load_top AND foo.beam1.force_transferred_B <= foo.girder1.max_load_A The natural place to state this invariant is in class Foo, by expressing 'foo' as 'self' in Python (or omitting it in languages which imply such a lookup, of course). If I'm not allowed (because you think "it's silly"!) to express a class invariant in terms of attributes of the attributes of an instance of that class, I basically have to write tons of boilerplate, violating encapsulation, to express what are really attributes of attributes of foo "as if" they were attributes of foo directly, e.g. def beam1_force_transferred_A(): return beam1.force_transferred_A (or other syntax to the same purpose). After going through this pointless (truly silly) exercise I can finally code the invariant as self.beam1_force_transferred_A <= self.pier1_max_load_top AND (etc). Changing a lot of dots into underscores -- what a way to waste programmer time! And all to NO advantage, please note, since: > of. Invariants are intended to be used to check the state of the > class, not the state of arbitary other objects. Doing the latter > requires that you have to check the invariants of every object pretty > much every time anything changes. ...in the end the invariant DOES have to be checked when anything relevant changes, anyway, with or without the silly extra indirection. But besides the wasted work, there is a loss of conceptual integrity: I don't WANT Foo to have to expose the internal details that beam1's reference point A transfers the force to pier1's top, etc etc, elevating all of these internal structural details to the dignity of attributes of Foo. Foo should expose only its externally visible attributes: loads and forces on all the relevant points, geometric details of the exterior, and structural parameters that are relevant for operating safety margins, for example. The point is that the internal state of an object foo which composes other objects (foo's attributes) beam1, pier1, etc, INCLUDES some attributes of those other objects -- thus stating that the need to check those attributes' relationships in Foo's class invariant is SILLY, strikes me as totally out of place. If the state is only of internal relevance, important e.g. in invariants but not to be externally exposed, what I think of as very silly instead is a style which forces me to build a lot of "pseudoattributes" of Foo (not to be exposed) by mindless delegation to attributes of attributes. > Invariants are a tool. Used wisely, they make finding and fixing some > logic bugs much easier than it would be otherwise. Used unwisely, they > don't do anything but make the code bigger. I disagree, most intensely and deeply, that any reference to an attribute of an attribute of self in the body of an invariant is necessarily "unwise". > > I'm also quite dubious as to how you can then express some > > invariants that can be very important > > Not all invariants, pre-conditions or post-conditions can be > expressed. Not all can be sensibly CHECKED, but most definitely all can be EXPRESSED. Another one of my long-standing contentions with Eiffel is the inability to express invariants (and pre- and post- conditions) because the compiler is unable to figure out a decent way to check them; Z and the VDL, just to name very old design languages, show easy ways to allow full expression. Of course, if a condition is of the form, say, "all items of potentially infinite iterable X satisfy predicate P", it may not be runtime-checkable -- big furry deal, I want to be able to EXPRESS it anyway, because apart from runtime checking there are other precious uses of such conditions (e.g., the compiler might be able to DEDUCE from such a condition some important optimization, or the compiletime proof of other assertions, when run in the appropriate mode). But that has little to do with the use case I covered here. Surely you're not claiming that the structural invariants showing that foo isn't about to crash *can't be expressed*, just because the obvious way to express them violates your stylistic preferences (which I find totally unjustified in this case) and the way that meets your style preferences, without offering any advantages, requires lots of pesky useless boilerplate?! That's not the DEFINITION of "can't"!-) > > Fortunately, for most of my work, I do get to use Python, Objective-C, > > or Haskell, which, albeit in very different ways, are all "purer" (able > > to stick to their principles)... > > I think Eiffel is fairly pure. But practicality beats purity, so there > are places where it has to give in and deviate from it's > principles. Clearly, you don't agree with the underlying > philosoiphy. So don't use it. I don't, but I also occasionally take the time to explain, as I've done here, where it (or, in this case, a specific style you claim it requires -- not using attributes of attributes in a class invariant -- I'd appreciate URLs to where Meyers dictates this restriction, btw) interferes with purity, practicality, or both. Alex From rbt at athop1.ath.vt.edu Wed Dec 21 13:36:42 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Wed, 21 Dec 2005 13:36:42 -0500 Subject: Guido at Google In-Reply-To: <1h7wvw8.1of7z5vg23o7eN%aleax@mail.comcast.net> References: <43a939e3$0$23986$626a14ce@news.free.fr> <1135165473.419546.212040@g49g2000cwa.googlegroups.com> <1h7wvw8.1of7z5vg23o7eN%aleax@mail.comcast.net> Message-ID: Alex Martelli wrote: > I don't think there was any official announcement, but it's true -- he > sits about 15 meters away from me;-). For Americans: 15 meters is roughly 50 feet. From nogradi at gmail.com Sun Dec 18 08:46:02 2005 From: nogradi at gmail.com (Daniel Nogradi) Date: Sun, 18 Dec 2005 14:46:02 +0100 Subject: object oriented programming question In-Reply-To: References: <5f56302b0512171410i6df31c38oe5c3300dc1b54e17@mail.gmail.com> Message-ID: <5f56302b0512180546r6a55fb58oa152f4e2b42b2533@mail.gmail.com> > > Hello Daniel > You've certainly got a lot going on here. > > The heart of your question seems to be how a nested (inner) class _a can > access > its parent, x. The short answer is that, in Python, it can't without some > help. > _a and its instances are unaware of the context in which they are > defined, so > they hold no references to x or instance of x. (Technically this is > because the > class is not created until after the statements in the class suite are > executed) > > Before we get to that, though, note that you've made content an attribute > of x's > instances, not the x class. So there is no x.content, only inst.content > . I'll > assume this was a typo, and you intended inst.content. If this > distinction is > mysterious you may want to check: http://docs.python.org/tut/node11.html > > Now, back to the question of how instance a could get a reference to > inst. The > simplest way to program this is to give it the reference explicitly: > > > class _a: > > def func(self): > """I would like to do something > with ?content? here. > """ > print self.__parent__.content > > > class x: > def __init__(self): > self.content = ["I'm", "self.", "content"] > > a = _a() > > >>> inst = x() > >>> inst.a.__parent__ = inst # give inst.a a reference to its parent > >>> inst.a.func() > ["I'm", 'self.', 'content'] > >>> > > > > There is a way to automate "inst.a.__parent__ = inst", although it's not > ideal > "getting starting with Python objects" material. The solution is to have > _a > implement the descriptor protocol (see: > http://users.rcn.com/python/download/Descriptor.htm), and make the classes > "new-style", i.e., derived from 'object': > > class _a(object): > > ## def __call__(self, v): Method is irrelevant to this discussion > ## print v > > def func(self): > """I would like to do something > with ?content? here. > """ > print self.__parent__.content > > > def __get__(self, obj, cls): > """Store a reference to the referring obj""" > if isinstance(obj, cls): > self.__parent__ = obj > return self > > class x(object): > def __init__(self): > self.content = ["I'm", "self.", "content"] > > a = _a() > > > >>> inst = x() > >>> inst.a.func() #no need to set inst.a.__parent__ = inst manually now > ["I'm", 'self.', 'content'] > >>> > > HTH > > Michael Hi Michael, Thanks for the detailed answer, and yes, it was a typo, I meant inst = x() inst.a(5) inst.a.func() Following your example I could put together exactly what I wanted, thank you very much. Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: From gtcopeland at gmail.com Thu Dec 15 11:47:49 2005 From: gtcopeland at gmail.com (Greg Copeland) Date: 15 Dec 2005 08:47:49 -0800 Subject: access to preallocated block of memory? References: <1134599434.424994.224240@g47g2000cwa.googlegroups.com> <43a0d34d$0$23555$626a54ce@news.free.fr> <11q1na8n36n2e40@corp.supernews.com> Message-ID: <1134665269.569267.119180@g44g2000cwa.googlegroups.com> So array can not map a pre-existing chunk of memory? I did not port the mmap module because such semantics don't exist on VxWorks. Based on comments thus far, it looks like mmap is my best bet here? Any other options? From http Mon Dec 5 22:24:59 2005 From: http (Paul Rubin) Date: 05 Dec 2005 19:24:59 -0800 Subject: what's wrong with "lambda x : print x/60,x%60" References: <1133823550.667597.186820@g14g2000cwa.googlegroups.com> Message-ID: <7xd5kaj4ac.fsf@ruckus.brouhaha.com> Steve Holden writes: > Defining a function, and giving it a name, > isn't "polluting the namespace", any more than assigning > sub-expressions to temporary variables is polluting the namespace. Nor any less. > Why use temporary variables when all you have to do is make your > expressions three lines long to avoid "polluting the namespace"? Indeed. I'd much rather say x = a + b + (c * d) + e than temp1 = a + b temp2 = c * d temp3 = temp1 + temp2 x = temp3 + e I don't understand why the critics of lambda don't understand that having to use so many temp variables, for either numbers or functions, can work against both concision and clarity. > Even without shouting "Namespaces are a honking good idea, let's do > more of those", I should just like to make a small plea for everyone > to remember that namespaces are there specifically to allow us to name > things! Not everything needs a name. From roberto.alsina at gmail.com Fri Dec 30 08:53:17 2005 From: roberto.alsina at gmail.com (roberto.alsina at gmail.com) Date: 30 Dec 2005 05:53:17 -0800 Subject: python coding contest References: <43b0b977@nntp0.pdx.net> <43b23eec.184598698@news.oz.net> <43B25B0F.90509@hathawaymix.org> <59e9fd3a0512291635u14202551qe5e221e279fae89@mail.gmail.com> Message-ID: <1135950797.472962.315840@g49g2000cwa.googlegroups.com> Thomas Heller wrote: > X=' _ _ _ | _| _ |_|_ ' > Y=0x23018F406A3530EC273F008 > j="".join > seven_seg=lambda n:j(j(c)+"\n"for c in zip(*[X[Y>>m+int(d)*9&7::8]for d in n for m in(6,3,0)])) Interesting bit: Although there are more 3-char combinations when you read vertically, they compact better. If A=" ", B="_" and C="|", this 12 char string contains al possible combinations: BBBABAAACACC which is 2 chars shorter than the best for horizontal combinations: ABAAACBABCBCAC Still, I don't think this vertical idea can go below 123 or 124, but it's good :-) Now I wonder what the 119 solution is! From ilias at lazaridis.com Thu Dec 29 10:08:16 2005 From: ilias at lazaridis.com (Ilias Lazaridis) Date: Thu, 29 Dec 2005 17:08:16 +0200 Subject: [EVALUATION] - E04 - Leadership! Google, Guido van Rossum, PSF In-Reply-To: <43B3F4EF.1010909@xs4all.nl> References: <43b10a64$0$11065$e4fe514c@news.xs4all.nl> <43b25450$0$11062$e4fe514c@news.xs4all.nl> <43b2949f$0$11077$e4fe514c@news.xs4all.nl> <43b3c9dd$0$11077$e4fe514c@news.xs4all.nl> <43B3F4EF.1010909@xs4all.nl> Message-ID: Martin P. Hellwig wrote: > Ilias Lazaridis wrote: >> Martin P. Hellwig wrote: >>> Ilias Lazaridis wrote: >>> >>> I'm suspecting that we have different definitions (or at least the >>> implications of that) of used terms. >>> I think it's important to first define these definition in a form >>> acceptable to both of us. >>> >>> In the link you gave, the title was "Efficiency Management". >>> Now I believe that in _most_ implementations the words in the titles >>> are mutual exclusive. So my first question is, please define >>> "Efficiency" my second one is, please define "Management". >> >> " >> * The terminology is not yet aligned to commonly used business or >> standards organisation terminology [like e.g. ISO]. >> * This will happen after the process definition has finalized. >> " >> source: http://lazaridis.com/efficiency/process.html (V 0.8c - alpha) >> >> - >> >> I am a few steps from having the final diagramms ready, then I can >> align the terminology (e.g. asking for feedback, thus people can >> detect existent constructs and suggest terminology changes) >> >> I'll send you an email with some details (thus we don't discuss this >> off-topic in public). >> >> . >> > > Ilias Lazaridis wrote in email: > > Hi, > > > > just point me to a website you are related to (your personal one, > > your business one, ...) and I'll initialize the process, as defined in > > the draft-document: > > > > http://lazaridis.com/efficiency/textual.html > > > > - > > > > What I need at this point: > > > > - Website adress > > - your requirements & constraints for my processing > > Hey, > > I respond on your "private" mail and list in one and to both, I don't > regard this as off-topic because it is still in regard of your OP, > although that post can be seen as a bait to go OT. You should not reproduce private conversation on public media. > I didn't ask you for making an analyze, I asked you for your definitions > because I think they are not the same as used in my contexts. [...] Making an small analysis can assist you to understand the terminology (and me to align the terminology). You are free to reject this. As I am free to terminate the discussion here. Feel free to contact me with private email (after a few hours). Thank you. . -- http://lazaridis.com From kent at kentsjohnson.com Mon Dec 19 14:03:26 2005 From: kent at kentsjohnson.com (Kent Johnson) Date: Mon, 19 Dec 2005 14:03:26 -0500 Subject: What is unique about Python? In-Reply-To: <1135014944.705793.113620@f14g2000cwb.googlegroups.com> References: <1135014944.705793.113620@f14g2000cwb.googlegroups.com> Message-ID: <43a700cb$1_3@newspeer2.tds.net> gsteff wrote: > I'm a computer science student, and have recently been trying to > convince the professor who teaches the programming language design > course to consider mentioning scripting languages in the future. Along > those lines, I've been trying to think of features of Python, and > scripting languages in general, that can't be found in older languages, > and have been having a surprising amount of trouble. Dynamic typing > can be found in Smalltalk, the module concept can be found in Ada, > functional parameters and the dynamic creation of functions can be > found in Lisp. The indentation-based syntax seems to be unique, but > that's not really what I'm looking for. So I'm wondering, what is > innovative about Python, either in its design or implementation? Or is > its magic really just in combining many useful features of prior > languages in an unusually pleasant way? IMO it is the latter. Most of the features of Python can be found in other languages. Not so many languages have them all. It is the combination of ease of use and power that makes Python stand out. Kent From anand.pasoria at in.bosch.com Mon Dec 19 00:45:23 2005 From: anand.pasoria at in.bosch.com (Anand) Date: Mon, 19 Dec 2005 11:15:23 +0530 Subject: Columns and Rows in Excel Message-ID: Greetings, How can I find the number of active columns and rows used in an excel work sheet? What I mean is how can i find the last column and row or cell position, where the data is stored in an excel sheet? A code snippet would be of great help. Thanks for your cooperation and help. Best regards, Anand From bonono at gmail.com Wed Dec 14 21:56:56 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 14 Dec 2005 18:56:56 -0800 Subject: lambda (and reduce) are valuable In-Reply-To: References: <3iomf.519$hB6.515@trnddc05> Message-ID: <1134615416.210866.273390@g47g2000cwa.googlegroups.com> Marc 'BlackJack' Rintsch wrote: > In , Christopher Subich wrote: > > > Chris Mellon wrote: > >> functions with real names is crucial to maintainable code. The only > >> reason to ever use a lamdba in Python is because you don't want to > >> give a function a name, and that is just not a compelling use case for > >> GUI events. > > > > Ah, but that neglects the sheer utility of delayed-evaluation > > expressions. Consider the key= parameter to list.sort, et. al: > > > > complicated_list.sort(key=lambda x: x[3]) > > This can be written as:: > > from operator import itemgetter > complicated_list.sort(key=itemgetter(3)) > Though I find the lambda form easier for me to understand but itemgetter should be the preferred way as it should have some performance advantage and sort are those kind of functions that need it, in general. From kay.schluehr at gmx.net Sun Dec 4 01:36:42 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 3 Dec 2005 22:36:42 -0800 Subject: Python package installing rationale Message-ID: <1133678202.419186.263280@g47g2000cwa.googlegroups.com> In almost any case I install a Python package via distutils some directories in the package tree are left behind e.g. the docs, licenses, tests etc. I wonder if there is some rationale behind this? Should it be left to the "creative freedom" of the user to copy the docs whereever she wants or is there a dedicated place for them and if any why isn't it simple to declare it in the setup script? From steven.bethard at gmail.com Wed Dec 7 20:38:48 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Wed, 07 Dec 2005 18:38:48 -0700 Subject: Documentation suggestions In-Reply-To: References: Message-ID: Aahz wrote: > In article , > A.M. Kuchling wrote: > >>So now we're *really* stuck. The RefGuide doesn't describe the rules; >>the PEP no longer describes them either; and probably only Guido can >>write the new text for the RefGuide. (Or are the semantics the same >>and only some trivial details are different?) > > Raymond Hettinger (and/or maybe one of the metaclass wizards) can > probably also write it, with Guido editing after. That might produce > even more accuracy in the end. I'm not a metaclass wizard, but I have submitted a few doc patches trying to address some of the inaccuracies in the description of new-style classes and related matters: http://www.python.org/sf/1123716 http://www.python.org/sf/1163367 The problem is that they don't seem to get accepted (even when accompanied by positive comments). And unfortunately, I don't currently have time to do the 5 reviews for 1 deal offered by some of the python-dev folks. STeVe From pobrien at orbtech.com Thu Dec 1 14:51:17 2005 From: pobrien at orbtech.com (Pat) Date: 1 Dec 2005 11:51:17 -0800 Subject: ANN: Louie-1.0b2 - Signal dispatching mechanism References: Message-ID: <1133466677.443614.265260@f14g2000cwb.googlegroups.com> Thomas Heller wrote: > > What is the difference between PyDispatcher and Louie? > (I'm still using a hacked version of the original cookbook recipe...) Not too much at this point, but the general differences are listed on this page: http://louie.berlios.de/changes.html Matt and I plan to experiment with other changes for Nufox, PyQt, Schevo and other things that we are working on. -- Patrick K. O'Brien Orbtech http://www.orbtech.com Schevo http://www.schevo.org From tim.peters at gmail.com Fri Dec 30 15:57:16 2005 From: tim.peters at gmail.com (Tim Peters) Date: Fri, 30 Dec 2005 15:57:16 -0500 Subject: csrss.exe & Numeric In-Reply-To: <1135950228.369918.281510@g49g2000cwa.googlegroups.com> References: <1135950228.369918.281510@g49g2000cwa.googlegroups.com> Message-ID: <1f7befae0512301257t6d98b1dfi5af69da790aaf1db@mail.gmail.com> [jelle] > I have a function that uses the Numeric module. When I launch the > function csrss.exe consumes 60 / 70 % cpu power rather than having > python / Numeric run at full speed. Has anyone encountered this problem > before? It seriously messes up my Numeric performance. > > I'm running 2.4.2 on xp. Need more clues than that. What does your function do? What facilities does your function make use of? csrss.exe is the "user-mode side" of Windows, and consumes a lot of CPU if, for example, you're starting/stopping many threads, or display a lot of output to "a DOS box". You should also be aware that several kinds of malware install a program named "csrss.exe" or "CSRSS.EXE" (search the web for more on that, and run a virus scan). From bonono at gmail.com Thu Dec 15 08:50:59 2005 From: bonono at gmail.com (bonono at gmail.com) Date: 15 Dec 2005 05:50:59 -0800 Subject: Why and how "there is only one way to do something"? In-Reply-To: References: <1134646944.453716.75850@o13g2000cwo.googlegroups.com> <1134649479.444890.193020@z14g2000cwz.googlegroups.com> <1134649959.077878.151430@g47g2000cwa.googlegroups.com> <1134652082.682017.284470@g47g2000cwa.googlegroups.com> Message-ID: <1134654658.914474.263050@o13g2000cwo.googlegroups.com> Chris Mellon wrote: >You seem very, very interested in portraying anyone who > wants to encourage good style and readability as a language Nazi. I > don't appreciate that. You'll notice that I haven't taken the easy way > out and told you to go away and play with Perl, right? Noop. My stand is that good style and readability is a subjective matter, to certain extend. The often quoted example of the ternary operator demonstate that. I have no problem reading it as "this is the preferred way in python, because we have done a large usability study which indicate that", but saying it as "obvious" as if it is truth is just strange to me and yes I would repeatedly pointing that out. You can tell me to go away but that won't change anything. For most people, they are not what you described as "trying to be smart" but because of their background, truly feel that their way is more intuitive(or obvious). It is just like there are language on this planet that reads from right to left horizontally, as well as top to bottom, then right to left. And you are trying to tell them that English way is the "right way" or the obvious way. I can't get your meaning of "language Nazi" so using the idiom of "don't assume", I cannot comment on that part. > Any time you want to write something in any way other than the obvious > way, ask yourself why? Is it more obvious *to you*, which is a good > reason as long as you're only writing code for yourself? Or is it just > to be different, or because you think it'll be faster, or just because > the slickness of it appeals to you? > The point is again, "obvious" is not so obvious sometimes. You seem to be assuming that anyone that use style different from you is intentionally doing it and that your style would first come to their mind but they don't use it, for the sake of proving that they are smart. I don't know where you get that idea. For most of the question I see asking here, they are from another language background and their obvious way is what they are asking for that they cannot find in python. From mwm at mired.org Sun Dec 11 23:22:14 2005 From: mwm at mired.org (Mike Meyer) Date: Sun, 11 Dec 2005 23:22:14 -0500 Subject: Random Number Generation? References: <439cd3ff.782921311@news.oz.net> Message-ID: <86y82rlzbd.fsf@bhuda.mired.org> bokr at oz.net (Bengt Richter) writes: > Theoretically, the chances of getting an integer from a uniformly > random sample from an interval of real numbers is practically zero, > and even allowing for IEEE 754 double representation, Well, if we're going to be picky, the chances of getting a number with an IEEE 754 representation from a uniformly random sample from an interval of real numbers is practically zero. Of course, this is true for *any* finite subset of the reals (such as the set of numbers that have names that can be pronounced in the average human lifespan), and probably an infinite number of infinite subsets as well. But I tend to pick irrationals when asked to "pick a number between 1 and 10." > So what do you mean by "integer"? > And what by "decimals"? I think we should start by finding out what he means by "number", which is apparently a superset of both what he means by "integer" and "decimals". http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From siona at chiark.greenend.org.uk Tue Dec 6 12:47:37 2005 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 06 Dec 2005 17:47:37 +0000 (GMT) Subject: i=2; lst=[i**=2 while i<1000] References: <1133883705.255507.106080@g49g2000cwa.googlegroups.com> <4395c066.319152306@news.oz.net> <1133888127.976077.95500@g44g2000cwa.googlegroups.com> Message-ID: wrote: >Bengt Richter wrote: >> >>> list(iter(lambda b=[2]:b.append(b[0]**2) or b[0]<1000 and b.pop(0) or None, None)) >> [2, 4, 16, 256] >out of curiosity, what stops the iterator ? : iter(o, sentinel) [ ... ] The iterator created in this case will call o with no arguments for each call to its next() method; if the value returned is equal to sentinel, StopIteration will be raised, otherwise the value will be returned. In this case, o is: lambda b=[2]:b.append(b[0]**2) or b[0]<1000 and b.pop(0) or None which returns None when b[0]>=1000 (None or (False and _) or None evaluates to the last None). -- \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 pinard at iro.umontreal.ca Fri Dec 2 13:01:18 2005 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Fri, 2 Dec 2005 13:01:18 -0500 Subject: Setting PYTHONPATH from Makefile In-Reply-To: <1133533711.665760.61810@f14g2000cwb.googlegroups.com> References: <1133533711.665760.61810@f14g2000cwb.googlegroups.com> Message-ID: <20051202180118.GA20733@phenix.sram.qc.ca> [pinkfloydhomer at gmail.com] > I have a Makefile target that uses a python script, like: > %.abc: %.def > python myscript.py > If this was a tcsh script, I would just do: > setenv PYTHONPATH /path/to/stuff > python myscript.py > but this cannot be done from a Makefile. Use: %.abc: %.def PYTHONPATH=/path/to/stuff python myscript.py In fact, within Make or outside Make, for any shell command, you may write: VAR1=VALUE1 VAR2=VALUE2 ... COMMAND ARGUMENTS so temporarily setting VAR1, VAR2... in the environment for the duration of COMMAND only. This is a useful feature of the shell. -- Fran?ois Pinard http://pinard.progiciels-bpi.ca From quentel.pierre at wanadoo.fr Wed Dec 21 03:49:20 2005 From: quentel.pierre at wanadoo.fr (Pierre Quentel) Date: 21 Dec 2005 00:49:20 -0800 Subject: Which Python web framework is most like Ruby on Rails? In-Reply-To: <7xmziudf0q.fsf@ruckus.brouhaha.com> References: <1134496403.011407.169930@g44g2000cwa.googlegroups.com> <1135029071.990723.134030@z14g2000cwz.googlegroups.com> <1135083100.135409.165580@f14g2000cwb.googlegroups.com> <1135085077.952662.55340@o13g2000cwo.googlegroups.com> <1135086632.969355.205990@g47g2000cwa.googlegroups.com> <43a83537_2@newspeer2.tds.net> <1135112530.312697.313110@f14g2000cwb.googlegroups.com> <43a8a992$1_1@newspeer2.tds.net> <7xmziudf0q.fsf@ruckus.brouhaha.com> Message-ID: <1135154960.265287.322030@z14g2000cwz.googlegroups.com> Hello all, I am Karrigell's author. I have chosen the GPL licence almost at random (I saw that the Python licence was GPL-compatible), so I don't mind switching to another Open Source licence if the GPL is liable to cause problems. Which one would you advice : BSD ? Python licence ? another ? Regards, Pierre From apardon at forel.vub.ac.be Mon Dec 12 05:03:49 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 12 Dec 2005 10:03:49 GMT Subject: slice notation as values? References: <1134245232.901948.119880@g43g2000cwa.googlegroups.com> <439b8748.697746856@news.oz.net> Message-ID: Op 2005-12-11, Bengt Richter schreef : > On 10 Dec 2005 12:07:12 -0800, "Devan L" wrote: > >> >>Antoon Pardon wrote: >>> On 2005-12-10, Duncan Booth wrote: >>[snip] >>> >> I also think that other functions could benefit. For instance suppose >>> >> you want to iterate over every second element in a list. Sure you >>> >> can use an extended slice or use some kind of while. But why not >>> >> extend enumerate to include an optional slice parameter, so you could >>> >> do it as follows: >>> >> >>> >> for el in enumerate(lst,::2) >>> > >>> > 'Why not'? Because it makes for a more complicated interface for something >>> > you can already do quite easily. >>> >>> Do you think so? This IMO should provide (0,lst[0]), (2,lst[2]), >>> (4,lst[4]) ... >>> >>> I haven't found a way to do this easily. Except for something like: >>> >>> start = 0: >>> while start < len(lst): >>> yield start, lst[start] >>> start += 2 >>> >>> But if you accept this, then there was no need for enumerate in the >>> first place. So eager to learn something new, how do you do this >>> quite easily? >> >>>>> lst = ['ham','eggs','bacon','spam','foo','bar','baz'] >>>>> list(enumerate(lst))[::2] >>[(0, 'ham'), (2, 'bacon'), (4, 'foo'), (6, 'baz')] >> >>No changes to the language necessary. >> > Or, without creating the full list intermediately, > > >>> lst = ['ham','eggs','bacon','spam','foo','bar','baz'] > >>> import itertools > >>> list(itertools.islice(enumerate(lst), 0, None, 2)) > [(0, 'ham'), (2, 'bacon'), (4, 'foo'), (6, 'baz')] As far as I understand use of this idiom can turn an O(n) algorithm into an O(n^2) algorithm. Suppose I have a list with 10 000 elements and I want the sum of the first 100, the sum of the second 100 ... One way to do that would be: for i in xrange(0,10000,100): sum(itertools.islice(lst, i, i+100)) But itertools.islice would each time start from the begining of the list and iterate over i elements before giving 100 elements to sum. Which would make this implementation O(n^2) instead of O(n). -- Antoon Pardon From steve at holdenweb.com Mon Dec 26 11:02:27 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 26 Dec 2005 16:02:27 +0000 Subject: build curiosities of svn head (on WinXP) In-Reply-To: References: <417ha5F1d1ajeU1@news.dfncis.de> Message-ID: Steve Holden wrote: > David Murmann wrote [...] >>apart from that everything went fine, and i could reproduce the expected >>failure (ATM) of the regression test suite: >> >> http://mail.python.org/pipermail/python-dev/2005-December/059033.html >> >>btw, if anyone is interested in the (rather small) build-script for >>nant, just ask, >> >>so long, David. > > > This is terrific news. Just recently there have been indications that > the Windows platform needs a larger base of developers, and this might > be just the thing to promote that. It might be worth a quick post to > python-dev to see what interest your new development gets. Well done! > David: Apparently Tim Peters has just tracked down the causes of the build errors with VC7, so the Subversion repository should now hold a valid project file for you to test against. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ From pythonnew at gmail.com Sun Dec 4 05:44:36 2005 From: pythonnew at gmail.com (Ben Bush) Date: Sun, 4 Dec 2005 02:44:36 -0800 Subject: oval Message-ID: <8c11e4350512040244k2121cc6dja379854fdb0be219@mail.gmail.com> I tested the following code and wanted to get the message of "oval2 got hit" if I click the red one. But I always got "oval1 got hit". from Tkinter import * root=Tk() canvas=Canvas(root,width=100,height=100) canvas.pack() a=canvas.create_oval(10,10,20,20,tags='oval1',fill='blue') b=canvas.create_oval(50,50,80,80,tags='oval2',fill='red') def myEvent(event): if a: print "oval1 got hit!" else: print "oval2 got hit" canvas.tag_bind('oval1','