Re: how to make portable distribution of python 2.6?
Hi there, numpy, matplotlib are already parts of Portable Python, PyQt is coming in one of the next versions. Creating it is not so difficult, it is basically repackaging of the python core and the required modules. Tricky part is keeping it portable as big part of libs is storing their configuration settings all over the place or require python env. variables. Drop me an email an maybe I can help you by including modules you need in next release of Portable Python. I'm already helping several universities, maybe we can work together to create one distribution which targets computer classes (together with tutorials, documentation, how-to guides etc.) keep pythoning ! Perica Zivkovic On Aug 13, 8:23 pm, zaur szp...@gmail.com wrote: On 13 авг, 21:28, Thomas Jollans tho...@jollans.com wrote: On 2010-08-13 19:00, zaur wrote: All greetings! How to make portable distribution of python 2.6? I don't know, but what you're looking for probably already exists. Do you mean portable as in portable, i.e. take this and build it for your system, it should work if your OS is supported? Then you can get source tarballs from python.org http://python.org/download/ Or do you understand portable the way that is fashionable in the Windows world nowadays for some reason, i.e. look, Ma, already installed if you happen to use Microsoft Windows of roughly the right version! Then http://www.portablepython.com/ is exactly where Google would have lead you had you searched. I want to realize howto build my own portable python in order to use them without installation. I want also to be able install modules (numpy, matplotlib, pyqt, etc...) when it is necessary. This very usefull for teaching python in computer classes. -- http://mail.python.org/mailman/listinfo/python-list
Re: writing \feff at the begining of a file
On Saturday 14 August 2010, it occurred to Steven D'Aprano to exclaim: On Fri, 13 Aug 2010 18:25:46 -0400, Terry Reedy wrote: A short background to MRAB's answer which I will try to get right. The byte-order-mark was invented for UTF-16 encodings so the reader could determine whether the pairs of bytes are in little or big endiean order, depending on whether the first two bute are fe and ff or ff and fe (or maybe vice versa, does not matter here). The concept is meaningless for utf-8 which consists only of bytes in a defined order. This is part of the Unicode standard. However, Microsoft (or whoever) re-purposed (hijacked) that pair of bytes to serve as a non-standard indicator of utf-8 versus any non-unicode encoding. The result is a corrupted utf-8 stream that python accommodates with the utf-8-sig(nature) codec (versus the standard utf-8 codec). Is there a standard way to autodetect the encoding of a text file? I do this: No, there is no way to autodetect the encoding of a text file. Open the file in binary mode; if the first three bytes are codecs.BOM_UTF8, then it's a Microsoft UTF-8 text file; otherwise if the first two byes are codecs.BOM_BE or codecs.BOM_LE, the encoding is utf-16- be or utf-16-le respectively. Unless the file happens to be UCS-2/UTF-16, or it happens to be a UTF-8 with garbage at the top. If there's no BOM, then re-open the file and read the first two lines. If either of them match this regex 'coding[=:]\s*([-\w.]+)' then I take the encoding name from that. This matches Python's behaviour, and supports EMACS and vi encoding declarations. This is a completely different method, and probably the most common in real usage: 1. Assume the file is ASCII (or some similar code page), but be liberal about characters you don't recognize 2. Know the file format you're reading. 3. Switch encoding once you have reached an indication of which exact character set to use. For Python, use the coding cookie if it's there For XML, read the ?xml ... ? declaration. For HTML, look for a meta http-equiv='Content-Type' ... tag, or just guess If no encoding is specified in a way you recognize, then you're out of luck. You'd usually just guess. (better still, you'd know what encoding you're dealing with in the first place, but that's too much to ask, I suppose...) You can try to take an educated guess by cross-referencing character frequencies with tables for known encoding/language combinations. I think this is what Microsoft IE does when it encounters a web page of unspecified encoding. -- http://mail.python.org/mailman/listinfo/python-list
Re: writing \feff at the begining of a file
Is there a standard way to autodetect the encoding of a text file? Use the chardet module: http://chardet.feedparser.org/ Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: looping through possible combinations of McNuggets packs of 6,9 and 20
On Aug 12, 4:33 am, Paul Rubin no.em...@nospam.invalid wrote: Baba raoul...@gmail.com writes: exercise: given that packs of McNuggets can only be bought in 6, 9 or 20 packs, write an exhaustive search to find the largest number of McNuggets that cannot be bought in exact quantity. Is that a homework problem? Hint: first convince yourself that a largest number actually exists. If I recall, this was a puzzler on the NPR radio show Car Talk. Still might be homework, though. -- http://mail.python.org/mailman/listinfo/python-list
Re: looping through possible combinations of McNuggets packs of 6, 9 and 20
On Aug 13, 8:25 pm, Ian Kelly ian.g.ke...@gmail.com wrote: It's not. You're not just trying to find the sixth value that can be bought in exact quantity, but a sequence of six values that can all be bought in exact quantity. The integers [6, 9, 12, 15, 18, 20] are not sequential. Hi Ian, Thanks for stating the obvious. I obviously hadn't understood a fundamental part of the theorem which states that 6 SEQUENTIAL passes must be found! That's a good lesson learned and will help me in future exercises to make sure i understand the theory first. Thanks again! Ok so with your and News123's help (no offence to all others but i need to keep it simple at this stage)i was able to find the solution: 43 my code is probably not elegant but a huge step forward from where i started: def can_buy(n_nuggets): for a in range (0,n_nuggets): for b in range (0,n_nuggets): for c in range (0,n_nuggets): #print trying for %d: %d %d %d % (n_nuggets,a,b,c) if 6*a+9*b+20*c==n_nuggets: return [a,b,c] return [] for n_nuggets in range(50): result1 = can_buy(n_nuggets) result2 = can_buy(n_nuggets+1) result3 = can_buy(n_nuggets+2) result4 = can_buy(n_nuggets+3) result5 = can_buy(n_nuggets+4) result6 = can_buy(n_nuggets+5) if result1!=[] and result2!=[] and result3!=[] and result4!=[] and result5!=[] and result6!=[]: if (n_nuggets+5)-n_nuggets==5: print n_nuggets-1 break i suppose this can be tweaked to make it shorter? For instance i wonder if i can do the same with less variable to be defined? tnx Baba -- http://mail.python.org/mailman/listinfo/python-list
print v. print()
I am learning Python from Hammond Robinson's _Python Programming on Win32_, January 2000 edition. This print Sleeping for 10 seconds which appears in some example code, fails to... um... Compile? Interpret? Well, whatever the word is, it fails. Trial and error revealed that print(Sleeping for 10 seconds) does the trick. I am using version 3.1.2, presumably the book's authors used some earlier version. So why the change from print to print()? I should warn you that I know nothing about computers in general or Python in particular. -- I can't go on, I'll go on. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is python not written in C++ ?
In article i3ahdl$ce...@reader1.panix.com, Grant Edwards inva...@invalid.invalid wrote: I also looked at Modula-3 once, and thought it had some real promise, but I think it's probably deader than Ada now. That's because you should be using Oberon instead. -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ ...if I were on life-support, I'd rather have it run by a Gameboy than a Windows box. --Cliff Wells -- http://mail.python.org/mailman/listinfo/python-list
Re: print v. print()
On Saturday 14 August 2010, it occurred to Frederick Williams to exclaim: I am learning Python from Hammond Robinson's _Python Programming on Win32_, January 2000 edition. This print Sleeping for 10 seconds which appears in some example code, fails to... um... Compile? Interpret? Well, whatever the word is, it fails. Trial and error revealed that print(Sleeping for 10 seconds) does the trick. I am using version 3.1.2, presumably the book's authors used some earlier version. Yes, indeed. Python 3.0 changed a number of things, the most visible is removing the print statement in favour of the print() function. So why the change from print to print()? There's no reason for print to be a statement -- it can just as well be a function, which makes the language more regular, and therefore quite possibly easier to learn. I should warn you that I know nothing about computers in general or Python in particular. -- http://mail.python.org/mailman/listinfo/python-list
Re: print v. print()
Thomas Jollans wrote: On Saturday 14 August 2010, it occurred to Frederick Williams to exclaim: So why the change from print to print()? There's no reason for print to be a statement -- it can just as well be a function, which makes the language more regular, and therefore quite possibly easier to learn. The downside to a print() function is that assigning to `print` can mask the function, and leave a neophyte without any way to get output out of the program. The problem with that downside, I guess, is that rogue assignment to sys.stdout can kill a print statement just as dead as a print() function, so the statement's so-called advantage is not that great. Mel. -- http://mail.python.org/mailman/listinfo/python-list
Re: looping through possible combinations of McNuggets packs of 6, 9 and 20
Baba wrote: def can_buy(n_nuggets): for a in range (0,n_nuggets): for b in range (0,n_nuggets): for c in range (0,n_nuggets): #print trying for %d: %d %d %d % (n_nuggets,a,b,c) if 6*a+9*b+20*c==n_nuggets: return [a,b,c] return [] for n_nuggets in range(50): result1 = can_buy(n_nuggets) result2 = can_buy(n_nuggets+1) result3 = can_buy(n_nuggets+2) result4 = can_buy(n_nuggets+3) result5 = can_buy(n_nuggets+4) result6 = can_buy(n_nuggets+5) if result1!=[] and result2!=[] and result3!=[] and result4!=[] and result5!=[] and result6!=[]: if (n_nuggets+5)-n_nuggets==5: print n_nuggets-1 break i suppose this can be tweaked to make it shorter? For instance i wonder if i can do the same with less variable to be defined? That can_buy function is a computational heavyweight -- very repetitive when called inside a loop. It could be cheaper to compute a list of quantities that can be purchased, then check to see what's in the list -- or the set, if you optimize a bit more. Mel. -- http://mail.python.org/mailman/listinfo/python-list
Re: python ide for ubuntu
Hi Bhanu, if you want to use QT try eric4 for python2 or eric5 for python3. Is very nice IDE, but if you want to develop only pure python use kate or similar or eclipse if you need a nice way to see the debug processes On Thu, Aug 12, 2010 at 7:44 AM, Roald de Vries downa...@gmail.com wrote: Hi Bhanu, On Aug 12, 2010, at 4:15 AM, Bhanu Kumar wrote: Hi All, Is there any good free python IDE available in Ubuntu? See a similar discussion at django-users mailing list: http://groups.google.com/group/django-users/browse_thread/thread/562189578285211 Cheers, Roald -- http://mail.python.org/mailman/listinfo/python-list -- Juan Andres Knebel -- http://mail.python.org/mailman/listinfo/python-list
Re: looping through possible combinations of McNuggets packs of 6, 9 and 20
On 8/14/10, Baba raoul...@gmail.com wrote: On Aug 13, 8:25 pm, Ian Kelly ian.g.ke...@gmail.com wrote: It's not. You're not just trying to find the sixth value that can be bought in exact quantity, but a sequence of six values that can all be bought in exact quantity. The integers [6, 9, 12, 15, 18, 20] are not sequential. Hi Ian, Thanks for stating the obvious. I obviously hadn't understood a fundamental part of the theorem which states that 6 SEQUENTIAL passes must be found! That's a good lesson learned and will help me in future exercises to make sure i understand the theory first. Thanks again! Ok so with your and News123's help (no offence to all others but i need to keep it simple at this stage)i was able to find the solution: 43 my code is probably not elegant but a huge step forward from where i started: def can_buy(n_nuggets): for a in range (0,n_nuggets): for b in range (0,n_nuggets): for c in range (0,n_nuggets): #print trying for %d: %d %d %d % (n_nuggets,a,b,c) if 6*a+9*b+20*c==n_nuggets: return [a,b,c] return [] for n_nuggets in range(50): result1 = can_buy(n_nuggets) result2 = can_buy(n_nuggets+1) result3 = can_buy(n_nuggets+2) result4 = can_buy(n_nuggets+3) result5 = can_buy(n_nuggets+4) result6 = can_buy(n_nuggets+5) if result1!=[] and result2!=[] and result3!=[] and result4!=[] and result5!=[] and result6!=[]: if (n_nuggets+5)-n_nuggets==5: print n_nuggets-1 break i suppose this can be tweaked to make it shorter? For instance i wonder if i can do the same with less variable to be defined? tnx Baba One tweak: def can_buy(n_nuggets): for a in range (0,n_nuggets): for b in range (0,n_nuggets): for c in range (0,n_nuggets): #print trying for %d: %d %d %d % (n_nuggets,a,b,c) if 6*a+9*b+20*c==n_nuggets: return [a,b,c] return [] for n_nuggets in range(50): if (can_buy(n_nuggets) and can_buy(n_nuggets+1) and can_buy(n_nuggets+2) and can_buy(n_nuggets+3) and can_buy(n_nuggets+4) and can_buy(n_nuggets+5)): print n_nuggets - 1 break -- http://mail.python.org/mailman/listinfo/python-list
Re: looping through possible combinations of McNuggets packs of 6, 9 and 20
On Sat, Aug 14, 2010 at 8:52 AM, Baba raoul...@gmail.com wrote: my code is probably not elegant but a huge step forward from where i started: def can_buy(n_nuggets): for a in range (0,n_nuggets): for b in range (0,n_nuggets): for c in range (0,n_nuggets): #print trying for %d: %d %d %d % (n_nuggets,a,b,c) if 6*a+9*b+20*c==n_nuggets: return [a,b,c] return [] for n_nuggets in range(50): result1 = can_buy(n_nuggets) result2 = can_buy(n_nuggets+1) result3 = can_buy(n_nuggets+2) result4 = can_buy(n_nuggets+3) result5 = can_buy(n_nuggets+4) result6 = can_buy(n_nuggets+5) if result1!=[] and result2!=[] and result3!=[] and result4!=[] and result5!=[] and result6!=[]: if (n_nuggets+5)-n_nuggets==5: print n_nuggets-1 break i suppose this can be tweaked to make it shorter? For instance i wonder if i can do the same with less variable to be defined? Instead of calling can_buy() 6 times on every iteration of the main loop, I would suggest maintaining a list of the sequential results. Just call it once on each number of nuggets in order. If the number of nuggets is purchasable, and the list is empty or the last item in the list is the number of nuggets - 1, then append the number of nuggets to the list. If the last item in the list is not the number of nuggets - 1, then they're not sequential and you start a new list. When the length of the list reaches 6, you're done, and the answer is equal to the first item in the list - 1. You can also improve the can_buy() function by tightening up the loop limits. You don't need to go all the way up to n_nuggets on each loop. -- http://mail.python.org/mailman/listinfo/python-list
Re: looping through possible combinations of McNuggets packs of 6, 9 and 20
Baba wrote: On Aug 13, 8:25 pm, Ian Kelly ian.g.ke...@gmail.com wrote: It's not. You're not just trying to find the sixth value that can be bought in exact quantity, but a sequence of six values that can all be bought in exact quantity. The integers [6, 9, 12, 15, 18, 20] are not sequential. Hi Ian, Thanks for stating the obvious. I obviously hadn't understood a fundamental part of the theorem which states that 6 SEQUENTIAL passes must be found! That's a good lesson learned and will help me in future exercises to make sure i understand the theory first. Thanks again! Ok so with your and News123's help (no offence to all others but i need to keep it simple at this stage)i was able to find the solution: 43 my code is probably not elegant but a huge step forward from where i started: def can_buy(n_nuggets): for a in range (0,n_nuggets): for b in range (0,n_nuggets): for c in range (0,n_nuggets): #print trying for %d: %d %d %d % (n_nuggets,a,b,c) if 6*a+9*b+20*c==n_nuggets: return [a,b,c] return [] for n_nuggets in range(50): result1 = can_buy(n_nuggets) result2 = can_buy(n_nuggets+1) result3 = can_buy(n_nuggets+2) result4 = can_buy(n_nuggets+3) result5 = can_buy(n_nuggets+4) result6 = can_buy(n_nuggets+5) if result1!=[] and result2!=[] and result3!=[] and result4!=[] and result5!=[] and result6!=[]: if (n_nuggets+5)-n_nuggets==5: print n_nuggets-1 break i suppose this can be tweaked to make it shorter? For instance i wonder if i can do the same with less variable to be defined? Increase the number of nuggets one by one and keep a count of the number of consecutive successes. If you can buy a number of nuggets exactly, increment the count, otherwise reset the count. When the count reaches 6 you know that you're at the end of a sequence of consecutive successes. -- http://mail.python.org/mailman/listinfo/python-list
Re: python ide for ubuntu
Thanks!! On Sat, Aug 14, 2010 at 9:49 PM, Juan Andres Knebel juankne...@gmail.comwrote: Hi Bhanu, if you want to use QT try eric4 for python2 or eric5 for python3. Is very nice IDE, but if you want to develop only pure python use kate or similar or eclipse if you need a nice way to see the debug processes On Thu, Aug 12, 2010 at 7:44 AM, Roald de Vries downa...@gmail.comwrote: Hi Bhanu, On Aug 12, 2010, at 4:15 AM, Bhanu Kumar wrote: Hi All, Is there any good free python IDE available in Ubuntu? See a similar discussion at django-users mailing list: http://groups.google.com/group/django-users/browse_thread/thread/562189578285211 Cheers, Roald -- http://mail.python.org/mailman/listinfo/python-list -- Juan Andres Knebel -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: minidom help -- line number
On Saturday 14 August 2010, it occurred to GZ to exclaim: Hi All, I am writing a little program that reads the minidom tree built from an xml file. I would like to print out the line number of the xml file on the parts of the tree that are not valid. But I do not seem to find a way to correspond minidom nodes to line numbers. The DOM does not contain things like line number information. You work with the structure of the document, not the appearance of the file you happen to be using as a source. You can't use line numbers with minidom. For stream-based parsers like SAX and eXpat (both in the standard library) this makes more sense, and they both allow you to check the current line number in one way or another. -- http://mail.python.org/mailman/listinfo/python-list
Re: EXOR or symmetric difference for the Counter class
On Aug 12, 1:20 pm, Paddy paddy3...@googlemail.com wrote: I find myself needing to calculate the difference between two Counters or multisets or bags. I want those items that are unique to each bag. Tell us about your use cases. I'm curious how a program would ascribe semantic meaning to the result. The phrase unique to each bag doesn't quite cover it, perhaps something like number in either source above the minimum held in common. AFAICT, I've never needed something like this as a primitive. Even the xor operation for regular sets is rarely used. I know how to calculate it: b = Counter(a=1, b=2) c = Counter(a=3, b=1) diff = (b - c) + (c - b) diff Counter({'a': 2, 'b': 1}) That seems simple enough. You could also use: diff = (b | c) - (b c) # max(b,c) - min(b,c) Raymond -- http://mail.python.org/mailman/listinfo/python-list
Re: looping through possible combinations of McNuggets packs of 6, 9 and 20
On 8/14/2010 10:52 AM, Baba wrote: for n_nuggets in range(50): result1 = can_buy(n_nuggets) result2 = can_buy(n_nuggets+1) result3 = can_buy(n_nuggets+2) result4 = can_buy(n_nuggets+3) result5 = can_buy(n_nuggets+4) result6 = can_buy(n_nuggets+5) if result1!=[] and result2!=[] and result3!=[] and result4!=[] and result5!=[] and result6!=[]: if (n_nuggets+5)-n_nuggets==5: print n_nuggets-1 break i suppose this can be tweaked to make it shorter? For instance i wonder if i can do the same with less variable to be defined? [Other responders have covered a lots of the points I make below. I guess I need to be quicker!] First, congratulations on getting to a solution! Code can very often be made shorter, although it's not always worth your while to do so. And often, shorter code is less understandable code -- which makes a big difference if you need to revisit the code later on. Here are some things that can be done with your for-loop: 1. You don't need this if test, because it's always true: if (n_nuggets+5)-n_nuggets==5: 2. Whenever you find yourself inventing a series of variables like result1, result2, result3, etc., think about using a list instead. results = [] for i in range(6): results.append(can_buy(n_nuggets + i)) And to get really fancy, you can use a single list comprehension statement to do it all results = [can_buy(n_nuggets + i) for i in range(6)] 3. Your if statement tests whether all the lists are non-empty. In Python, expressions (a) and (b) are equivalent: (a) if result[0] != [] (b) if result[0] So your if test can be expressed as: if (result[0] and result[1] and result[2] and result[3] and result[4] and result[5]) (The parentheses are not required by if, but they *do* enable you to split the expression across two or more lines.) And you can use the all function to rescue this cumbersome statement; if all(results) After all this work, the code is getting pretty short: for n_nuggets in range(50): results = [can_buy(n_nuggets + i) for i in range(6)] if all(results): print n_nuggets-1 break 4. The variable results is defined in one statement, and then is used just once, in the very next statement. There's no harm in that, and I think it makes the mode easier to understand, but you can get rid of it: for n_nuggets in range(50): if all([can_buy(n_nuggets + i) for i in range(6)]): print n_nuggets-1 break But wait, there's more ... :-) So far, we've just refined the *implementation* of your algorithm. But the algorithm itself could use some work. * When n_nuggets==0, we compute can_buy(0), can_buy(1), can_buy(2), can_buy(3), can_buy(4), and can_buy(5). * When n_nuggets==1, we compute can_buy(1), can_buy(2), can_buy(3), can_buy(4), can_buy(5), and can_buy(6). ... and so on. We can use an algorithm in which can_buy(i) is computed just once for each value of i: can_buy_count = 0 n_nuggets = 0 while n_nuggets 50: if can_buy(n_nuggets): can_buy_count += 1 else: can_buy_count = 0 if can_buy_count == 6: print n_nuggets - 6 break else: n_nuggets += 1 And here's how you could shorten *this* code: ### cbc = can buy count cbc = 0 n_nuggets = -1 while n_nuggets 50: n_nuggets += 1 cbc = cbc+1 if can_buy(n_nuggets) else 0 if cbc == 6: print n_nuggets - 6 break HTH, John -- http://mail.python.org/mailman/listinfo/python-list
Re: minidom help -- line number
On Aug 14, 12:07 pm, Thomas Jollans tho...@jollybox.de wrote: On Saturday 14 August 2010, it occurred to GZ to exclaim: Hi All, I am writing a little program that reads the minidom tree built from an xml file. I would like to print out the line number of the xml file on the parts of the tree that are not valid. But I do not seem to find a way to correspond minidom nodes to line numbers. The DOM does not contain things like line number information. You work with the structure of the document, not the appearance of the file you happen to be using as a source. You can't use line numbers with minidom. For stream-based parsers like SAX and eXpat (both in the standard library) this makes more sense, and they both allow you to check the current line number in one way or another. So I am basically out of luck if I want to tie back to the original file for file error reporting etc. sounds like a deficiency to me. -- http://mail.python.org/mailman/listinfo/python-list
Re: minidom help -- line number
On Saturday 14 August 2010, it occurred to GZ to exclaim: On Aug 14, 12:07 pm, Thomas Jollans tho...@jollybox.de wrote: On Saturday 14 August 2010, it occurred to GZ to exclaim: Hi All, I am writing a little program that reads the minidom tree built from an xml file. I would like to print out the line number of the xml file on the parts of the tree that are not valid. But I do not seem to find a way to correspond minidom nodes to line numbers. The DOM does not contain things like line number information. You work with the structure of the document, not the appearance of the file you happen to be using as a source. You can't use line numbers with minidom. For stream-based parsers like SAX and eXpat (both in the standard library) this makes more sense, and they both allow you to check the current line number in one way or another. So I am basically out of luck if I want to tie back to the original file for file error reporting etc. sounds like a deficiency to me. The DOM is disjunct from the original file, stream, string, etc. That's in the nature of the DOM, and it's probably true for most, if not all, DOM implementations, in other programming languages as well as Python. If you want to stay close to the file, you're better of with SAX. (or a similar approach, like eXpat) -- http://mail.python.org/mailman/listinfo/python-list
Re: minidom help -- line number
On Sat, Aug 14, 2010 at 11:56 AM, Thomas Jollans tho...@jollybox.de wrote: The DOM is disjunct from the original file, stream, string, etc. That's in the nature of the DOM, and it's probably true for most, if not all, DOM implementations, in other programming languages as well as Python. If you want to stay close to the file, you're better of with SAX. (or a similar approach, like eXpat) The minidom parse function can also accept any SAX2 parser, so it should be possible to create a customized parser that stashes the line numbers somewhere and use that together with minidom. I've never attempted this myself, so I won't be able to help with details. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list
problem in using linalg solver in numpy
Hi Friends When run the below program in python i got error like this , Matrix [[ 8 -6 2] [-4 11 -7] [ 4 -7 6]] row vecotr X [[ 28 -40 33]] Traceback (most recent call last): File solve.py, line 16, in module print A*B File /usr/lib/python2.6/dist-packages/numpy/core/defmatrix.py, line 290, in __mul__ return N.dot(self, asmatrix(other)) ValueError: objects are not aligned #!/usr/bin/python N=3 from numpy import linalg from numpy import matrix fr=open('mat.txt','r') A=matrix([[int(fr.readline()) for j in range(N)]for i in range(N)]) B=matrix([[int(fr.readline())for j in range(N)]]) print 'Matrix \n',A print 'row vecotr X\n',B #A=matrix([[3,4],[5,2]]) #B=matrix([[11],[9]]) print A*B #y=linalg.solve(A,B) #print 'Solution vectoris \n',y The input file is 8 -6 2 -4 11 -7 4 -7 6 28 -40 33 please try to fix the error in the program Thankx in advance -- http://mail.python.org/mailman/listinfo/python-list
Chrome ore Sell Pakistani 30% - 52%,
Chrome ore Sell Pakistani 30% - 52%, http://buy-sell-pakistani-minerals.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Tk window and contents will not display
The scenario is this: I want to loop around all of the images in a given directory (which I know will be images, but I guess I should check), show an image in a window, wait 2 seconds and show the next one and repeat that indefinitley, which will be until the user closes the window. This is the code I extracted from the larger program and made work - sort of - in a standalone fashion. When I run the code, each of the file names gets displayed, and I can view the images, so it has to be something I am doing wrong with this chunk of code. However, I don't see what the problem is. from Tkinter import * import time import os import ImageTk import Image class externalLoopDisplay: def show(self): # # Create a frame # self.window = Tk() self.f = Frame(self.window, bg=Gray) self.f.grid() self.btnRefresh = Button(self.f, text=Close, command=self.window.destroy, bg=Gray,highlightbackground=Red, highlightcolor=Green) self.btnRefresh.grid(row=0, column=2) self.loopImage() def loopImage(self): dir = Radar/net17 while 1: fileList = os.listdir(dir) number = len(fileList) c = 1 for gifFile in fileList: print externalLoopDisplay.show:,top of for loop + str(c) + of + str(number) print externalLoopDisplay.show:,showing file + dir + / + gifFile self.window.title(Image + str(c) + of + str(number)) image = Image.open(dir + / + gifFile) canvasWidth, canvasHeight = image.size self.w = Canvas(self.f, width=canvasWidth, height=canvasHeight) photo = ImageTk.PhotoImage(image=image) netRadarImage = Label(self.w, image=photo) netRadarImage.image = photo self.w.grid(row=1, column=0, columnspan=3) netRadarImage.grid( row=1, column=0) time.sleep(10) c = c + 1 self.w.destroy() loop=externalLoopDisplay() loop.show() -- http://mail.python.org/mailman/listinfo/python-list
Re: problem in using linalg solver in numpy
Pramod wrote: When run the below program in python i got error like this , Matrix [[ 8 -6 2] [-4 11 -7] [ 4 -7 6]] row vecotr X [[ 28 -40 33]] Traceback (most recent call last): File solve.py, line 16, in module print A*B File /usr/lib/python2.6/dist-packages/numpy/core/defmatrix.py, line 290, in __mul__ return N.dot(self, asmatrix(other)) ValueError: objects are not aligned A=matrix([[int(fr.readline()) for j in range(N)]for i in range(N)]) B=matrix([[int(fr.readline())for j in range(N)]]) print A*B Row or column; I can't remember which is which either. Try again with B = matrix([[int(fr.readline())] for j in range(N)] or A*B.transpose() Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: problem in using linalg solver in numpy
Pramod wrote: Hi Friends When run the below program in python i got error like this , Matrix [[ 8 -6 2] [-4 11 -7] [ 4 -7 6]] row vecotr X [[ 28 -40 33]] Traceback (most recent call last): File solve.py, line 16, in module print A*B File /usr/lib/python2.6/dist-packages/numpy/core/defmatrix.py, line 290, in __mul__ return N.dot(self, asmatrix(other)) ValueError: objects are not aligned [snip] If you're trying to multiply element-wise use the 'multiply' function. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python Sandbox
On 8/13/10 8:04 PM, Steven D'Aprano wrote: On Fri, 13 Aug 2010 16:37:40 -0700, Stephen Hansen wrote: Howdy-ho. So, I'm working on a project which embeds Python into a bigger system to provide extensibility. In this project, there's basically two types of people who will be entering python code. The trusted folks, who write code which are in files, and which can do anything. The untrusted folks, who are writing very simple chunks of code which can only do limited things. I suggest that if the untrusted code is only supposed to be simple and limited, you would be best off to write your own mini-language using Python syntax. I considered it and rejected it. The return from the effort required doesn't even vaguely come close to making it worth it. My worst case fall-back plan is to embed /another/ language (be it Lua or JavaScript through V8) and offer it a very limited environment. But I don't want to do that (and considering I solved the while True: pass problem last night, I'm pretty sure I won't decide to). The fact is that Python is not designed to be used by untrusted users, and it is REALLY hard to keep it in a sandbox. There was an attempt to sandbox Python, if I recall correctly it was the bastion module, but it turned out to be so leaky that it was removed from the standard library with extreme prejudice. Since then, others have been working on it, including Google, but I don't know how successful they've been. I know all this -- but its not relevant really, I think. I'm not trying to create a safe yet relatively complete or functional Python. All those efforts to sandbox Python fail because of the incredible dynamic nature of the language has lots of enticing little holes in it. But I'm not interested in a full or even vaguely full subset of Python, and I'm not requiring that this security be done on the code-level. For example, when you go to save your bit of code, it will go in and if it finds __ anywhere in the text it just replaces it with xx. And, since getattr is not available, '_' + '_' won't get you anywhere. Here's an example... suppose you wish to allow reading files, but not writing them. Sounds simple? http://tav.espians.com/a-challenge-to-break-python-security.html Yeah, I'm aware of this little challenge-- but every one of those exploits calls for a special attribute call or method creation which is impossible(I think) in my setup. Although Paul Cannon's little exploit is very interesting, and I'm going to go brute force murder try/except in a similar way to __ above (in this context, exceptions aren't important) now. Now, I'm not suggesting that the exploits there are directly applicable to your sandbox, but they give a small idea of the sorts of things you need to consider. I'm creating a much, much more restrictive subset of Python then most sandboxes try to do-- I could make my own custom mini-language, except good lord, that's a whole lot of work since there are real needs for *some* programming power here. Or I could embed another language in a more restrictive way then Python is embedded-- but good lord, now I have to handle three languages to get things done :) I just need a certain limited context where someone can be handed certain Python objects and manipulate them. I'd like people to be able to use some fundamental Python power -- the rich, beautiful data types for example (notably in this case, strings), list comprehensions and stuff, to do what they need to do. Python's very easy, I'd like them to be able to use that easy. But I don't need anywhere near full Python power, so sweeping rules like, 'no, you can't even type __' or, 'sorry, no exception handling for you', work well. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Tk window and contents will not display
Chris Hare wrote: The scenario is this: I want to loop around all of the images in a given directory (which I know will be images, but I guess I should check), show an image in a window, wait 2 seconds and show the next one and repeat that indefinitley, which will be until the user closes the window. This is the code I extracted from the larger program and made work - sort of - in a standalone fashion. When I run the code, each of the file names gets displayed, and I can view the images, so it has to be something I am doing wrong with this chunk of code. However, I don't see what the problem is. I have not looked at your code in detail, but event loops and time.sleep() don't play together very well. Use after(delay_in_milliseconds, callable) instead. Here's a simple example that loops over images passed from the command line: import Image import ImageTk import os import sys import Tkinter as tk from itertools import cycle def next_image(): imagefile = next(imagefiles) image = Image.open(imagefile) w, h = image.size image = image.resize((700, 700*h//w)) label.image = label[image] = ImageTk.PhotoImage(image=image) root.title(Now showing %s % os.path.basename(imagefile)) root.after(2000, next_image) if __name__ == __main__: imagefiles = sys.argv[1:] assert imagefiles imagefiles = cycle(imagefiles) root = tk.Tk() label = tk.Label(root) label.pack() root.after_idle(next_image) root.mainloop() -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python Sandbox
On 14Aug2010 12:56, Stephen Hansen me+list/pyt...@ixokai.io wrote: | On 8/13/10 8:04 PM, Steven D'Aprano wrote: | On Fri, 13 Aug 2010 16:37:40 -0700, Stephen Hansen wrote: | So, I'm working on a project which embeds Python into a bigger system to | provide extensibility. In this project, there's basically two types of | people who will be entering python code. | | The trusted folks, who write code which are in files, and which can do | anything. | | The untrusted folks, who are writing very simple chunks of code which | can only do limited things. | | I suggest that if the untrusted code is only supposed to be simple and | limited, you would be best off to write your own mini-language using | Python syntax. | | I considered it and rejected it. The return from the effort required | doesn't even vaguely come close to making it worth it. Ok, what about this: run the untrusted code in a separate process, if necessary running as a user with different privileges. Provide objects that need to be shared as some sort of proxy. Then your untrusted users can do whatever they like in python because they won't be presented with the inner parts of the privileged stuff. This is all rather vague because I don't know exactly what your untrusted users need to be able to do, nor how. Cheers, -- Cameron Simpson c...@zip.com.au DoD#743 http://www.cskk.ezoshosting.com/cs/ Computers in the future may weigh no more than 1.5 tons. --Popular Mechanics, forecasting the relentless march of science, 1949 -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is python not written in C++ ?
In article 7xeieevrze@ruckus.brouhaha.com, Paul Rubin no.em...@nospam.invalid wrote: I'm not sure what the hiring issue is. I think anyone skilled in C++ or Java can pick up Ada pretty easily. It's mostly a subset of C++ with different surface syntax. Heck, I learned Ada as a sixteen-year-old knowing only BASIC and Pascal. -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ ...if I were on life-support, I'd rather have it run by a Gameboy than a Windows box. --Cliff Wells -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python Sandbox
On Sat, Aug 14, 2010 at 12:56 PM, Stephen Hansen me+list/pyt...@ixokai.io wrote: On 8/13/10 8:04 PM, Steven D'Aprano wrote: On Fri, 13 Aug 2010 16:37:40 -0700, Stephen Hansen wrote: Howdy-ho. So, I'm working on a project which embeds Python into a bigger system to provide extensibility. In this project, there's basically two types of people who will be entering python code. The trusted folks, who write code which are in files, and which can do anything. The untrusted folks, who are writing very simple chunks of code which can only do limited things. I suggest that if the untrusted code is only supposed to be simple and limited, you would be best off to write your own mini-language using Python syntax. I considered it and rejected it. The return from the effort required doesn't even vaguely come close to making it worth it. My worst case fall-back plan is to embed /another/ language (be it Lua or JavaScript through V8) and offer it a very limited environment. But I don't want to do that (and considering I solved the while True: pass problem last night, I'm pretty sure I won't decide to). The fact is that Python is not designed to be used by untrusted users, and it is REALLY hard to keep it in a sandbox. There was an attempt to sandbox Python, if I recall correctly it was the bastion module, but it turned out to be so leaky that it was removed from the standard library with extreme prejudice. Since then, others have been working on it, including Google, but I don't know how successful they've been. I know all this -- but its not relevant really, I think. I'm not trying to create a safe yet relatively complete or functional Python. All those efforts to sandbox Python fail because of the incredible dynamic nature of the language has lots of enticing little holes in it. But I'm not interested in a full or even vaguely full subset of Python, and I'm not requiring that this security be done on the code-level. For example, when you go to save your bit of code, it will go in and if it finds __ anywhere in the text it just replaces it with xx. And, since getattr is not available, '_' + '_' won't get you anywhere. Here's an example... suppose you wish to allow reading files, but not writing them. Sounds simple? http://tav.espians.com/a-challenge-to-break-python-security.html Yeah, I'm aware of this little challenge-- but every one of those exploits calls for a special attribute call or method creation which is impossible(I think) in my setup. Although Paul Cannon's little exploit is very interesting, and I'm going to go brute force murder try/except in a similar way to __ above (in this context, exceptions aren't important) now. Now, I'm not suggesting that the exploits there are directly applicable to your sandbox, but they give a small idea of the sorts of things you need to consider. I'm creating a much, much more restrictive subset of Python then most sandboxes try to do-- I could make my own custom mini-language, except good lord, that's a whole lot of work since there are real needs for *some* programming power here. Or I could embed another language in a more restrictive way then Python is embedded-- but good lord, now I have to handle three languages to get things done :) I just need a certain limited context where someone can be handed certain Python objects and manipulate them. I'd like people to be able to use some fundamental Python power -- the rich, beautiful data types for example (notably in this case, strings), list comprehensions and stuff, to do what they need to do. Python's very easy, I'd like them to be able to use that easy. But I don't need anywhere near full Python power, so sweeping rules like, 'no, you can't even type __' or, 'sorry, no exception handling for you', work well. I assume you're cutting out the import machinery? Geremy Condra -- http://mail.python.org/mailman/listinfo/python-list
Re: Tk window and contents will not display
On Aug 14, 2010, at 3:14 PM, Peter Otten wrote: Chris Hare wrote: The scenario is this: I want to loop around all of the images in a given directory (which I know will be images, but I guess I should check), show an image in a window, wait 2 seconds and show the next one and repeat that indefinitley, which will be until the user closes the window. This is the code I extracted from the larger program and made work - sort of - in a standalone fashion. When I run the code, each of the file names gets displayed, and I can view the images, so it has to be something I am doing wrong with this chunk of code. However, I don't see what the problem is. I have not looked at your code in detail, but event loops and time.sleep() don't play together very well. Use after(delay_in_milliseconds, callable) instead. Here's a simple example that loops over images passed from the command line: import Image import ImageTk import os import sys import Tkinter as tk from itertools import cycle def next_image(): imagefile = next(imagefiles) image = Image.open(imagefile) w, h = image.size image = image.resize((700, 700*h//w)) label.image = label[image] = ImageTk.PhotoImage(image=image) root.title(Now showing %s % os.path.basename(imagefile)) root.after(2000, next_image) if __name__ == __main__: imagefiles = sys.argv[1:] assert imagefiles imagefiles = cycle(imagefiles) root = tk.Tk() label = tk.Label(root) label.pack() root.after_idle(next_image) root.mainloop() Thanks Peter. I threw away what I started with and merged your code into my class: class externalLoopDisplay: def show(self): main.logging.debug(externalLoopDisplay.show:,start) self.window = Tk() self.btnClose = Button(self.window, text=Close, command=self.window.destroy, bg=backColor,highlightbackground=warnColor, highlightcolor=okColor) self.btnClose.grid(row=0, column=2) self.label = Label(self.window) self.label.grid(row=1, column=0, columnspan=3) dirName = getRadarPath() + /net + str(netNumber.get()) # e.g. .../Radar/net17/net17-MMDDHHMMSS.gif self.imagefiles = glob.glob(dirName + /*.gif) self.imagefiles = cycle(self.imagefiles) self.window.after_idle(self.next_image) def next_image(self): imagefile = next(self.imagefiles) image = Image.open(imagefile) w, h = image.size image = image.resize((600, 550*h//w)) self.label.image = self.label[image] = ImageTk.PhotoImage(image=image) # bails here self.window.title(Now showing %s % os.path.basename(imagefile)) self.window.after(2000, next_image) I marked where the code bails with an error saying pyimage2 doesn't exist. All of the images exist and worked just fine with your standalone script. Suggestions? -- http://mail.python.org/mailman/listinfo/python-list
Re: Tk window and contents will not display
Chris Hare wrote: Thanks Peter. I threw away what I started with and merged your code into my class: class externalLoopDisplay: def show(self): main.logging.debug(externalLoopDisplay.show:,start) self.window = Tk() self.btnClose = Button(self.window, text=Close, command=self.window.destroy, bg=backColor,highlightbackground=warnColor, highlightcolor=okColor) self.btnClose.grid(row=0, column=2) self.label = Label(self.window) self.label.grid(row=1, column=0, columnspan=3) dirName = getRadarPath() + /net + str(netNumber.get()) # e.g. .../Radar/net17/net17-MMDDHHMMSS.gif self.imagefiles = glob.glob(dirName + /*.gif) self.imagefiles = cycle(self.imagefiles) self.window.after_idle(self.next_image) def next_image(self): imagefile = next(self.imagefiles) image = Image.open(imagefile) w, h = image.size image = image.resize((600, 550*h//w)) self.label.image = self.label[image] = ImageTk.PhotoImage(image=image) # bails here self.window.title(Now showing %s % os.path.basename(imagefile)) self.window.after(2000, next_image) I marked where the code bails with an error saying pyimage2 doesn't exist. All of the images exist and worked just fine with your standalone script. Suggestions? Google says you are calling Tkinter.Tk() more than once where you should instead use Tkinter.Toplevel(). As you didn't post that part of the code it's hard to verify, but when I add a second root = tk.Tk() to my example script I get a very similar exception: Exception in Tkinter callback Traceback (most recent call last): File /usr/lib/python2.6/lib-tk/Tkinter.py, line 1413, in __call__ return self.func(*args) File /usr/lib/python2.6/lib-tk/Tkinter.py, line 498, in callit func(*args) File cycle_image.py, line 16, in next_image label.image = label[image] = ImageTk.PhotoImage(image=image) File /usr/lib/python2.6/lib-tk/Tkinter.py, line 1212, in __setitem__ self.configure({key: value}) File /usr/lib/python2.6/lib-tk/Tkinter.py, line 1205, in configure return self._configure('configure', cnf, kw) File /usr/lib/python2.6/lib-tk/Tkinter.py, line 1196, in _configure self.tk.call(_flatten((self._w, cmd)) + self._options(cnf)) TclError: image pyimage1 doesn't exist By the way: for future posts please remember to cut and paste the traceback, don't paraphrase the error message. Peter -- http://mail.python.org/mailman/listinfo/python-list
Pop return from stack?
Assuming I have a module 'foo.py' with something like this: def error(s): print Error, s sys.exit(1) def func(s): ... do some processing ... call error() if bad .. go to system exit. ... more processing and then I write a new program, test.py, which: import foo def myerror(s): print new error message foo.error = myerror a = foo.func(..) Now, if an error is encountered myerror() is called. Fine. But execution resumes in func(). Not exactly what I wanted. I can fix this simply by wrapping the call to foo.func() in a try/ expect and have myerror() raise an exception. This appears to work, but I'm hesitant to use this out of fear that I'm building up some kind of stack overflow or something which will bite me later. Is there a better way? Simplest for an old assembler guy like me would be pop a return address off the stack ... but python isn't assembler :) I don't want to change stuff in the foo.py module since it's part of an existing program. But, if I must, I suppose I could. I'd prefer to just short-circuit this if possible. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tk window and contents will not display
On Aug 14, 2010, at 5:49 PM, Peter Otten wrote: Chris Hare wrote: Thanks Peter. I threw away what I started with and merged your code into my class: class externalLoopDisplay: def show(self): main.logging.debug(externalLoopDisplay.show:,start) self.window = Tk() self.btnClose = Button(self.window, text=Close, command=self.window.destroy, bg=backColor,highlightbackground=warnColor, highlightcolor=okColor) self.btnClose.grid(row=0, column=2) self.label = Label(self.window) self.label.grid(row=1, column=0, columnspan=3) dirName = getRadarPath() + /net + str(netNumber.get()) # e.g. .../Radar/net17/net17-MMDDHHMMSS.gif self.imagefiles = glob.glob(dirName + /*.gif) self.imagefiles = cycle(self.imagefiles) self.window.after_idle(self.next_image) def next_image(self): imagefile = next(self.imagefiles) image = Image.open(imagefile) w, h = image.size image = image.resize((600, 550*h//w)) self.label.image = self.label[image] = ImageTk.PhotoImage(image=image) # bails here self.window.title(Now showing %s % os.path.basename(imagefile)) self.window.after(2000, next_image) I marked where the code bails with an error saying pyimage2 doesn't exist. All of the images exist and worked just fine with your standalone script. Suggestions? Google says you are calling Tkinter.Tk() more than once where you should instead use Tkinter.Toplevel(). As you didn't post that part of the code it's hard to verify, but when I add a second root = tk.Tk() to my example script I get a very similar exception: Exception in Tkinter callback Traceback (most recent call last): File /usr/lib/python2.6/lib-tk/Tkinter.py, line 1413, in __call__ return self.func(*args) File /usr/lib/python2.6/lib-tk/Tkinter.py, line 498, in callit func(*args) File cycle_image.py, line 16, in next_image label.image = label[image] = ImageTk.PhotoImage(image=image) File /usr/lib/python2.6/lib-tk/Tkinter.py, line 1212, in __setitem__ self.configure({key: value}) File /usr/lib/python2.6/lib-tk/Tkinter.py, line 1205, in configure return self._configure('configure', cnf, kw) File /usr/lib/python2.6/lib-tk/Tkinter.py, line 1196, in _configure self.tk.call(_flatten((self._w, cmd)) + self._options(cnf)) TclError: image pyimage1 doesn't exist By the way: for future posts please remember to cut and paste the traceback, don't paraphrase the error message. Peter -- http://mail.python.org/mailman/listinfo/python-list Yes - you are bang on. Thanks. One final question if I may, how would you suggest I handle checking for new files and adding them to the list? For example, if the loop is playing and a new image is added, how can I detect it and then refresh the list of file? I am stuck on that part with this new approach. Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: Pop return from stack?
On Sunday 15 August 2010, it occurred to bvdp to exclaim: Assuming I have a module 'foo.py' with something like this: def error(s): print Error, s sys.exit(1) def func(s): ... do some processing ... call error() if bad .. go to system exit. ... more processing and then I write a new program, test.py, which: import foo def myerror(s): print new error message foo.error = myerror a = foo.func(..) Now, if an error is encountered myerror() is called. Fine. But execution resumes in func(). Not exactly what I wanted. I can fix this simply by wrapping the call to foo.func() in a try/ expect and have myerror() raise an exception. This appears to work, but I'm hesitant to use this out of fear that I'm building up some kind of stack overflow or something which will bite me later. An exception will walk up the stack, calling any cleaning-up code that needs to be done (removing object references, executing finally: blocks, exiting context managers properly. It won't break anything. Don't be afraid of Python's high-level features! Is there a better way? Simplest for an old assembler guy like me would be pop a return address off the stack ... but python isn't assembler :) Now that has a decent chance of messing things up and you (if you wrote decent assembly ;-)) know it -- without properly cleaning up before resuming execution in the right place, you could end up in a right state with memory leaks, leaked file descriptors, half-arsed database transactions, etc etc. I don't want to change stuff in the foo.py module since it's part of an existing program. But, if I must, I suppose I could. I'd prefer to just short-circuit this if possible. Exceptions. Simple. In the end, all system.exit does is raise a SystemExit exception... - Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python Sandbox
Hi, I know all this -- but its not relevant really, I think. I'm not trying to create a safe yet relatively complete or functional Python. All those efforts to sandbox Python fail because of the incredible dynamic nature of the language has lots of enticing little holes in it. But I'm not interested in a full or even vaguely full subset of Python, and I'm not requiring that this security be done on the code-level. I had the same problem, and so I created a pseudo-sandbox for embedding Python in templates. This pseudo-sandbox creates a restricted Python environment, where only whitelisted functions/classes are allowed. Additionally, it prevents things like '0 .__class__'. You can find some documentation at http://simple-is-better.org/template/pyratemp.html#evaluation, and the pseudo-sandbox itself in my template-engine, class EvalPseudoSandbox on the website above. (Please write me if you have any comments.) But note that this is not a real sandbox! As soon as you allow *any* unsafe function (e.g. open, import, eval, getattr etc.), you can easily break out. Also, don't directly pass complete modules to the pseudo-sandbox, since they may contain unsafe functions/classes/etc. And be warned: There *may* also be ways to break out of the pseudo-sandbox even without passing unsafe functions to it -- although I don't know any. If you know or find such a way: Please tell me! You could also take a look at Jinja (which is also a template-engine), and which claims to include a sandbox. But the Jinja-sandbox seems to be much more complicated than my pseudo-sandbox, and I haven't analyzed it and don't know how it works. For example, when you go to save your bit of code, it will go in and if it finds __ anywhere in the text it just replaces it with xx. And, since getattr is not available, '_' + '_' won't get you anywhere. I don't think that searching the text is the right way; in my pseudo-sandbox, I compile the code and search co_names for such names instead. I just need a certain limited context where someone can be handed certain Python objects and manipulate them. I'd like people to be able to use some fundamental Python power -- the rich, beautiful data types for example (notably in this case, strings), list comprehensions and stuff, to do what they need to do. Python's very easy, I'd like them to be able to use that easy. I was in the exact same position ;). (Although I don't have fully untrusted/bad users, and so my pseudo-sandbox is sufficient for my cases, even though I haven't proved that it really is secure...) regards, Roland -- http://mail.python.org/mailman/listinfo/python-list
Working with PDFs?
Just curious if anyone knows if it's possible to work with pdf documents with Python? I'd like to do the following: - Pull out text from each PDF page (to search for specific words) - Combine separate pdf documents into one document - Add bookmarks (with destination settings) A few programs I've been looking at are pdfminer, pyPDF, etc from this link: http://pypi.python.org/pypi?%3Aaction=searchterm=pdfsubmit=search Originally, I was using AppleScript and JavaScript to do this in Acrobat. But now Acrobat 9 has broken this process and I can't seem to make it work. I'd like to find other workarounds instead of having to rely on Adobe. Thanks for your help. Jay -- http://mail.python.org/mailman/listinfo/python-list
Re: Tk window and contents will not display
Chris Hare wrote: On Aug 14, 2010, at 5:49 PM, Peter Otten wrote: Chris Hare wrote: Thanks Peter. I threw away what I started with and merged your code into my class: class externalLoopDisplay: def show(self): main.logging.debug(externalLoopDisplay.show:,start) self.window = Tk() self.btnClose = Button(self.window, text=Close, command=self.window.destroy, bg=backColor,highlightbackground=warnColor, highlightcolor=okColor) self.btnClose.grid(row=0, column=2) self.label = Label(self.window) self.label.grid(row=1, column=0, columnspan=3) dirName = getRadarPath() + /net + str(netNumber.get()) # e.g. .../Radar/net17/net17-MMDDHHMMSS.gif Thanks. One final question if I may, how would you suggest I handle checking for new files and adding them to the list? For example, if the loop is playing and a new image is added, how can I detect it and then refresh the list of file? I am stuck on that part with this new approach. Chris Replacing self.imagefiles = glob.glob(dirName + /*.gif) self.imagefiles = cycle(self.imagefiles) with self.imagefiles = image_cycler(os.path.join(dirname, *.gif)) where image_cycler() looks as follows def image_cycler(pattern): while True: for fn in glob.glob(pattern): yield fn would be the simplest way. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python Sandbox
On Sun, 15 Aug 2010 01:24:00 +0200, Roland Koebler wrote: I had the same problem, and so I created a pseudo-sandbox for embedding Python in templates. This pseudo-sandbox creates a restricted Python environment, where only whitelisted functions/classes are allowed. Additionally, it prevents things like '0 .__class__'. Hmmm... is that meant just as an illustration of a general technique, or do you actually have something against the class of 0? 0 .__class__ seems pretty innocuous to me: type(0) is 0 .__class__ is int True [...] But note that this is not a real sandbox! As soon as you allow *any* unsafe function (e.g. open, import, eval, getattr etc.), you can easily break out. Isn't that true of any sandbox though? Surely by definition, if you allow an unsafe function in any sandbox, it's no longer an effective sandbox. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python Sandbox
On Sat, 14 Aug 2010 12:56:45 -0700, Stephen Hansen wrote: I suggest that if the untrusted code is only supposed to be simple and limited, you would be best off to write your own mini-language using Python syntax. I considered it and rejected it. The return from the effort required doesn't even vaguely come close to making it worth it. I suppose that depends on how simple the untrusted code will be, but I guess you're in the best position to make that call. My worst case fall-back plan is to embed /another/ language (be it Lua or JavaScript through V8) and offer it a very limited environment. But I don't want to do that (and considering I solved the while True: pass problem last night, I'm pretty sure I won't decide to). I assume you mean you've solved the problem of DOS attacks from users running infinite loops. How did you do that? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: print v. print()
On Sat, 14 Aug 2010 11:44:22 -0400, Mel wrote: The downside to a print() function is that assigning to `print` can mask the function, and leave a neophyte without any way to get output out of the program. On the other hand, the upside to a print() function is that assigning to `print` can monkey-patch the function, allowing the advanced user to modify it's functionality at runtime. Whether that's a feature or a shooting offence is a matter of opinion. (I think it's a feature, albeit one which is easy to misuse.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: shelf-like list?
In af7fdb85-8c87-434e-94f3-18d8729bf...@l25g2000prn.googlegroups.com Raymond Hettinger pyt...@rcn.com writes: On Aug 12, 1:37=A0pm, Thomas Jollans tho...@jollybox.de wrote: On Tuesday 10 August 2010, it occurred to kj to exclaim: I'm looking for a module that implements persistent lists: objects that behave like lists except that all their elements are stored on disk. =A0IOW, the equivalent of shelves, but for lists rather than a dictionaries. . . . You could simply use pickle to save the data every once in a while. That is a very reasonable solution. Sorry I don't follow. Some sample code would be helpful. TIA, ~K -- http://mail.python.org/mailman/listinfo/python-list
Re: Pop return from stack?
On Sat, 14 Aug 2010 16:05:05 -0700, bvdp wrote: Assuming I have a module 'foo.py' with something like this: def error(s): print Error, s sys.exit(1) def func(s): ... do some processing ... call error() if bad .. go to system exit. ... more processing and then I write a new program, test.py, which: import foo def myerror(s): print new error message foo.error = myerror a = foo.func(..) This general technique is called monkey patching. Now, if an error is encountered myerror() is called. Fine. But execution resumes in func(). Not exactly what I wanted. Of course it does. Your new error handler fails to exit, so execution resumes like it does after any other function. You can either manually exit from your own error handler: def myerror(s): print new error message sys.exit(2) or call the original error handler: def myerror(s): print new error message foo._error(s) That second technique requires some preparation before hand. In module foo, after defining the error() function, you then need to create a second, private, name to it: _error = error I can fix this simply by wrapping the call to foo.func() in a try/ expect and have myerror() raise an exception. This appears to work, but I'm hesitant to use this out of fear that I'm building up some kind of stack overflow or something which will bite me later. Exceptions are the standard way of doing things. That's what sys.exit() does -- it raises SystemExit exception. With very few exceptions, if you're writing your own error handlers like this, you're doing it wrong. Your error handler throws away useful debugging information, and it gives you no extra information that a standard Python traceback couldn't give. Is there a better way? Simplest for an old assembler guy like me would be pop a return address off the stack ... but python isn't assembler :) Oh my ... I've seen people writing Java in Python, C++ in Python, Perl in Python, even VB in Python, but this is the first time I've meet some one who wants to write assembler in Python :) -- Steven -- http://mail.python.org/mailman/listinfo/python-list
How to add silent stretches to MP3 using Python?
Here's the problem: I have about 25,000 mp3 files, each lasting, *on average*, only a few seconds, though the variance is wide (the longest one lasts around 20 seconds). (These files correspond to sample sentences for foreign language training.) The problem is that there is basically no padding before and after the sound signal. I want to prepend about 2 seconds of silence to each file, and append another silent stretch at the end lasting either 2 seconds or some multiplier of the duration of the original file, whichever is greater. I know that manipulating MP3 audio programmatically is usually not easy, but this has got to be one of the simplest manipulations possible, so I'm hoping I'll be able to pull it off with Python. But I have not had much luck finding a Python library to do this. If someone knows how to do this, and could give me some pointers, I'd appreciate it. TIA! ~K -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python Sandbox
For example, when you go to save your bit of code, it will go in and if it finds __ anywhere in the text it just replaces it with xx. And, since getattr is not available, '_' + '_' won't get you anywhere. That's not as secure as you might think. First of all you can write _ in more way than you may think. 2*chr(0x5f) + insecure + 2*chr(0x5f) '__insecure__' \x5f\x5finsecure\x5f\x5f '__insecure__' str(u\N{LOW LINE}\N{LOW LINE}insecure\N{LOW LINE}\N{LOW LINE}) '__insecure__' If you have access to eval, exec or compile you can easily work around your restrictions: getattribute = eval(object.__getattribute__) getattribute(int, __new__)(int, 3) 3 As you can see, black listing isn't the best approach here. Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: Tk window and contents will not display
On Aug 14, 2010, at 6:46 PM, Peter Otten wrote: Chris Hare wrote: On Aug 14, 2010, at 5:49 PM, Peter Otten wrote: Chris Hare wrote: Thanks Peter. I threw away what I started with and merged your code into my class: class externalLoopDisplay: def show(self): main.logging.debug(externalLoopDisplay.show:,start) self.window = Tk() self.btnClose = Button(self.window, text=Close, command=self.window.destroy, bg=backColor,highlightbackground=warnColor, highlightcolor=okColor) self.btnClose.grid(row=0, column=2) self.label = Label(self.window) self.label.grid(row=1, column=0, columnspan=3) dirName = getRadarPath() + /net + str(netNumber.get()) # e.g. .../Radar/net17/net17-MMDDHHMMSS.gif Thanks. One final question if I may, how would you suggest I handle checking for new files and adding them to the list? For example, if the loop is playing and a new image is added, how can I detect it and then refresh the list of file? I am stuck on that part with this new approach. Chris Replacing self.imagefiles = glob.glob(dirName + /*.gif) self.imagefiles = cycle(self.imagefiles) with self.imagefiles = image_cycler(os.path.join(dirname, *.gif)) where image_cycler() looks as follows def image_cycler(pattern): while True: for fn in glob.glob(pattern): yield fn would be the simplest way. Peter -- http://mail.python.org/mailman/listinfo/python-list Perfect! Thank you -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python Sandbox
On Sun, Aug 15, 2010 at 12:06:35AM +, Steven D'Aprano wrote: Hmmm... is that meant just as an illustration of a general technique, or do you actually have something against the class of 0? It's a short illustration; 0 .__class__ itself is harmless, but e.g. 0 .__class__.__base__.__subclasses__() isn't. But note that this is not a real sandbox! As soon as you allow *any* unsafe function (e.g. open, import, eval, getattr etc.), you can easily break out. Isn't that true of any sandbox though? Surely by definition, if you allow an unsafe function in any sandbox, it's no longer an effective sandbox. In my opinion, a real sandbox should allow to use unsafe functions (e.g. open(), import modules etc.) -- so you could run your normal code in it. But it should prevent the bad effects of the code, e.g. by redirecting I/O, limiting resources etc. regards, Roland -- http://mail.python.org/mailman/listinfo/python-list
Re: How to add silent stretches to MP3 using Python?
Here's the problem: I have about 25,000 mp3 files, each lasting, *on average*, only a few seconds, though the variance is wide (the longest one lasts around 20 seconds). (These files correspond to sample sentences for foreign language training.) The problem is that there is basically no padding before and after the sound signal. I want to prepend about 2 seconds of silence to each file, and append another silent stretch at the end lasting either 2 seconds or some multiplier of the duration of the original file, whichever is greater. I know that manipulating MP3 audio programmatically is usually not easy, but this has got to be one of the simplest manipulations possible, so I'm hoping I'll be able to pull it off with Python. But I have not had much luck finding a Python library to do this. If someone knows how to do this, and could give me some pointers, I'd appreciate it. While it's (1) not 100% python and (2) doesn't allow for your 2 seconds...or some multiplier of the duration, whichever is greater, you can use mp3wrap[1] to losslessly join the files. If you happen to make a 2-seconds-of-silence MP3, you can then join your files together with the silence. For 25k files, you might have to stitch subsets of them together incrementally and then stitch together the resulting files. -tkc [1] http://mp3wrap.sourceforge.net/ or apt-get install mp3wrap here on my Debian box -- http://mail.python.org/mailman/listinfo/python-list
Re: Pop return from stack?
On Aug 14, 4:05 pm, bvdp b...@mellowood.ca wrote: Assuming I have a module 'foo.py' with something like this: def error(s): print Error, s sys.exit(1) def func(s): ... do some processing ... call error() if bad .. go to system exit. ... more processing and then I write a new program, test.py, which: import foo def myerror(s): print new error message foo.error = myerror a = foo.func(..) Now, if an error is encountered myerror() is called. Fine. But execution resumes in func(). Not exactly what I wanted. I can fix this simply by wrapping the call to foo.func() in a try/ expect and have myerror() raise an exception. This appears to work, but I'm hesitant to use this out of fear that I'm building up some kind of stack overflow or something which will bite me later. What do you think a few words of data the stack are going to do? Just do it this way. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python Sandbox
On 8/14/10 5:06 PM, Steven D'Aprano wrote: On Sun, 15 Aug 2010 01:24:00 +0200, Roland Koebler wrote: I had the same problem, and so I created a pseudo-sandbox for embedding Python in templates. This pseudo-sandbox creates a restricted Python environment, where only whitelisted functions/classes are allowed. Additionally, it prevents things like '0 .__class__'. Hmmm... is that meant just as an illustration of a general technique, or do you actually have something against the class of 0? 0 .__class__ seems pretty innocuous to me: type(0) is 0 .__class__ is int True Assuming you have a totally restricted environment, where none of the normal built-ins are available-- notably type-- in theory I thought once that you could exec pretty safely. Because there's just no access to anything! But, alas, someone showed me I was wrong. 0 .__class__ can lead you to type. And type.__subclasses__ happily leads you to everything in the world. I solve this by just refusing to allow getattr, and __ anywhere in the file to be saved just gets turned into xx, so its impossible (I think) for users to access or use any special method. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python Sandbox
On 8/14/10 2:25 PM, Cameron Simpson wrote: Ok, what about this: run the untrusted code in a separate process, if necessary running as a user with different privileges. Way too much overhead by a really significant margin: I need to do many, many, many, many, many very short (often very *very* short) little scripts. Doing IPC to separate processes, even if they're long-running, and handling proxying of my objects that these scripts need to read from and tweak in certain ways, would just kill performance. I really do need an embedded language -- and a very restricted subset of Python is really ideal for that, which is why I'm going for this. :) -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python Sandbox
On 8/14/10 4:24 PM, Roland Koebler wrote: You can find some documentation at http://simple-is-better.org/template/pyratemp.html#evaluation, and the pseudo-sandbox itself in my template-engine, class EvalPseudoSandbox on the website above. (Please write me if you have any comments.) How are you implementing refusing-names-beginning-with-underscore, out of curiosity? You could also take a look at Jinja (which is also a template-engine), and which claims to include a sandbox. But the Jinja-sandbox seems to be much more complicated than my pseudo-sandbox, and I haven't analyzed it and don't know how it works. I'll take a look. I just need a certain limited context where someone can be handed certain Python objects and manipulate them. I'd like people to be able to use some fundamental Python power -- the rich, beautiful data types for example (notably in this case, strings), list comprehensions and stuff, to do what they need to do. Python's very easy, I'd like them to be able to use that easy. I was in the exact same position ;). (Although I don't have fully untrusted/bad users, and so my pseudo-sandbox is sufficient for my cases, even though I haven't proved that it really is secure...) I don't *really* have a bunch fully untrusted / bad users, in fact I expect I will sort of trust all the people doing this level of coding -- but I believe that either incompetance and maliciousness is inevitable in any sort of online community, and making it at least as hard as possible to do damage while giving people as much freedom and tools to do great is the ideal goal. :) -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Working with PDFs?
On 8/14/2010 7:44 PM, jyoun...@kc.rr.com wrote: Just curious if anyone knows if it's possible to work with pdf documents with Python? I'd like to do the following: search python pdf library reportlab -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python Sandbox
On 8/14/10 5:36 PM, Christian Heimes wrote: For example, when you go to save your bit of code, it will go in and if it finds __ anywhere in the text it just replaces it with xx. And, since getattr is not available, '_' + '_' won't get you anywhere. That's not as secure as you might think. First of all you can write _ in more way than you may think. Well yes, I know-- but as I said in the original post, eval, exec, compile, getattr and such, are all unavailable. So its possible someone can write '_' in various ways (though I'm disallowing both chr and unichr for entirely different reasons), and they can even put them together so that there's a __ as a string in some variable, I can't find any way in which they would then be able to get to get a special method. Namely, type.__subclasses__ or object.__getattribute__. They can't enter any code which does blah.__class__, and they can't construct a string through twisty ways to then do getattr(blah, twisty) where twisty = __class__. If you have access to eval, exec or compile you can easily work around your restrictions: I think its pretty much a given that if you're even trying to do some kind of restricted sandbox, eval and the like are the first things to go. :) As you can see, black listing isn't the best approach here. But I have a two pronged strategy: the black list is only half of the equation. One, I'm blacklisting all the meta functions out of builtins. Eval, compile, getattr, and such. Then, I'm doing some blatant textual munging, making it so someone can not access any __special__ methods, or use exec. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python Sandbox
On 8/14/10 5:09 PM, Steven D'Aprano wrote: My worst case fall-back plan is to embed /another/ language (be it Lua or JavaScript through V8) and offer it a very limited environment. But I don't want to do that (and considering I solved the while True: pass problem last night, I'm pretty sure I won't decide to). I assume you mean you've solved the problem of DOS attacks from users running infinite loops. How did you do that? Since I only have to run this on Unix-isms, I'm using alarm()/signal(). The C code takes the hash of the source code that's going to be executed and marks it, then sets an alarm and executes the code (though its usually been compiled into a code object). There's no code which would -ever- in this situation take longer then 2 seconds to run (and that's extremely generous), but the alarm is 5: if the code doesn't return and cancel the alarm by then, I know the code is functionally broken. So, the signal handler records the hash of the code that failed -- it'll never be tried again -- logs an error message, and restarts the whole process (which happens seamlessly with virtually no user interruption, but this system is not architected in a way where its readily able to resume operation in the event of a signal interrupt). This isn't perfect: infinite loops it kills, but things like [0] * 10^^100 crash head first into the machine and bring it to a crawl. I haven't figured out a strategy for trying to address that yet, and ultimately, I may not find one. That's okay: perfection isn't my goal, infinite loops are easy enough to do on accident that halting them is important. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Pop return from stack?
On Sat, Aug 14, 2010 at 5:23 PM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: snip Oh my ... I've seen people writing Java in Python, C++ in Python, Perl in Python, even VB in Python, but this is the first time I've meet some one who wants to write assembler in Python :) +1 QOTW Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python Sandbox
On Sat, Aug 14, 2010 at 8:07 PM, Stephen Hansen me+list/pyt...@ixokai.io wrote: On 8/14/10 5:09 PM, Steven D'Aprano wrote: My worst case fall-back plan is to embed /another/ language (be it Lua or JavaScript through V8) and offer it a very limited environment. But I don't want to do that (and considering I solved the while True: pass problem last night, I'm pretty sure I won't decide to). I assume you mean you've solved the problem of DOS attacks from users running infinite loops. How did you do that? Since I only have to run this on Unix-isms, I'm using alarm()/signal(). The C code takes the hash of the source code that's going to be executed and marks it, then sets an alarm and executes the code (though its usually been compiled into a code object). There's no code which would -ever- in this situation take longer then 2 seconds to run (and that's extremely generous), but the alarm is 5: if the code doesn't return and cancel the alarm by then, I know the code is functionally broken. So, the signal handler records the hash of the code that failed -- it'll never be tried again -- logs an error message, and restarts the whole process (which happens seamlessly with virtually no user interruption, but this system is not architected in a way where its readily able to resume operation in the event of a signal interrupt). This isn't perfect: infinite loops it kills, but things like [0] * 10^^100 crash head first into the machine and bring it to a crawl. I haven't figured out a strategy for trying to address that yet, and ultimately, I may not find one. That's okay: perfection isn't my goal, infinite loops are easy enough to do on accident that halting them is important. cpulimit or a cgroups container can both be easy solutions here, depending on your exact needs. Geremy Condra -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python Sandbox
On 8/14/10 8:11 PM, geremy condra wrote: cpulimit or a cgroups container can both be easy solutions here, depending on your exact needs. Hmm! I wasn't aware of those, I'll check that out. Thanks. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python Sandbox
On Sat, Aug 14, 2010 at 8:18 PM, Stephen Hansen me+list/pyt...@ixokai.io wrote: On 8/14/10 8:11 PM, geremy condra wrote: cpulimit or a cgroups container can both be easy solutions here, depending on your exact needs. Hmm! I wasn't aware of those, I'll check that out. Thanks. Np. I wrote a set of cgroups bindings in Python a few years ago that I could probably lay my hands on if they'd help, although they may be out of date by now. Geremy Condra -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is python not written in C++ ?
In message 44d30ac7-931e-4eb0-9aed-f664c872d...@l20g2000yqm.googlegroups.com, sturlamolden wrote: A C++ compiler can use Python's header files and link with Python's C API correctly. But it cannot compile Python's C source code. A C compiler is required to compile and build Python. Since when do you find a C++ compiler not accompanied by a C one? -- http://mail.python.org/mailman/listinfo/python-list
Re: Pop return from stack?
An exception will walk up the stack, calling any cleaning-up code that needs to be done (removing object references, executing finally: blocks, exiting context managers properly. It won't break anything. Don't be afraid of Python's high-level features! Okay, I believe you (and the rest of the gang. In my trivial program the exception in working ... so I'll leave it alone. Thanks. - Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Pop return from stack?
On Aug 14, 5:23 pm, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: This general technique is called monkey patching. New term for me :) Now, if an error is encountered myerror() is called. Fine. But execution resumes in func(). Not exactly what I wanted. Of course it does. Your new error handler fails to exit, so execution resumes like it does after any other function. I guess I wasn't being clear. I don't want to exit in my new bit of code. Just continue a loop (which I didn't show in the example). Exceptions are the standard way of doing things. That's what sys.exit() does -- it raises SystemExit exception. Okay, didn't know that exit() was really an exception. Good to know. But, like I said, I'm not looking to exit. With very few exceptions, if you're writing your own error handlers like this, you're doing it wrong. Your error handler throws away useful debugging information, and it gives you no extra information that a standard Python traceback couldn't give. Yeah, but I really don't want a traceback printed out for a user just because a file can't be found, or he's got a bad bit of syntax in his file. So, that's why I have the specific error routine. Works fine in the main program. Oh my ... I've seen people writing Java in Python, C++ in Python, Perl in Python, even VB in Python, but this is the first time I've meet some one who wants to write assembler in Python :) Naw, I had my fun with assembler in the good old days. Never want to write another line of it :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is python not written in C++ ?
On 2010-08-14, Aahz a...@pythoncraft.com wrote: Paul Rubin no.em...@nospam.invalid wrote: I'm not sure what the hiring issue is. I think anyone skilled in C++ or Java can pick up Ada pretty easily. It's mostly a subset of C++ with different surface syntax. Heck, I learned Ada as a sixteen-year-old knowing only BASIC and Pascal. Unfortunately, there just aren't that many Aahzes to hire (sixteen years old or otherwise), and of the non-Aahz progrommers out there it's shocking how many of them them are apparently incapable of learning a second language. Regardless of how easy something is to learn, management always wants to hire people who don't have to. -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: shelf-like list?
This should help: http://docs.python.org/library/pickle.html -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer Zindagi Games On Sat, Aug 14, 2010 at 5:13 PM, kj no.em...@please.post wrote: In af7fdb85-8c87-434e-94f3-18d8729bf...@l25g2000prn.googlegroups.com Raymond Hettinger pyt...@rcn.com writes: On Aug 12, 1:37=A0pm, Thomas Jollans tho...@jollybox.de wrote: On Tuesday 10 August 2010, it occurred to kj to exclaim: I'm looking for a module that implements persistent lists: objects that behave like lists except that all their elements are stored on disk. =A0IOW, the equivalent of shelves, but for lists rather than a dictionaries. . . . You could simply use pickle to save the data every once in a while. That is a very reasonable solution. Sorry I don't follow. Some sample code would be helpful. TIA, ~K -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: shelf-like list?
On Sat, Aug 14, 2010 at 5:13 PM, kj no.em...@please.post wrote: In af7fdb85-8c87-434e-94f3-18d8729bf...@l25g2000prn.googlegroups.com Raymond Hettinger pyt...@rcn.com writes: On Aug 12, 1:37=A0pm, Thomas Jollans tho...@jollybox.de wrote: On Tuesday 10 August 2010, it occurred to kj to exclaim: I'm looking for a module that implements persistent lists: objects that behave like lists except that all their elements are stored on disk. =A0IOW, the equivalent of shelves, but for lists rather than a dictionaries. . . . You could simply use pickle to save the data every once in a while. That is a very reasonable solution. Sorry I don't follow. Some sample code would be helpful. I would assume something along the lines of (untested): from pickle import dump MOD_THRESHOLD = 42 class PersistentList(list): def __init__(self, filepath): self.filepath = filepath self._mod_count = 0 def save(self): with open(self.filepath, 'w') as f: dump(self, f) self._mod_count = 0 def append(self, *args, **kwds): super(PersistentList, self).append(*args, **kwds) self._mod_count += 1 if self._mod_count = MOD_THRESHOLD: # obviously time-since-last-dump or other # more sophisticated metrics might be used instead self.save() # define similar wrappers for list's other mutator methods: __delitem__, __iadd__, __imul__, __setitem__, extend, insert, pop, remove, etc. # using decorators should help decrease code duplication Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
[issue5867] No way to create an abstract classmethod
Daniel Urban urban.dani...@gmail.com added the comment: I'm attaching a new patch adding the abc.abstractclassmethod and abc.abstractstaticmethod decorators. -- Added file: http://bugs.python.org/file18519/abstractclassstaticmethod.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5867 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9548] locale can be imported at startup but relies on too many library modules
Nick Coghlan ncogh...@gmail.com added the comment: As we move more and more infrastructure into Python code, we're going to see this pattern (i.e. a bootstrap module underlying the real module) more and more often (e.g. I seem to recall Brett has to do something similar when playing with the pure Python __import__ implementation). I don't have an issue with it - it's a solid, standard solution to a recurring problem with otherwise circular dependencies. The only changes I would suggest to Antoine's patch are to explicitly scope interpreter startup in the _bootlocale docstring (to make it clear that sitecustomize.py should use the ordinary locale module) and to mention the nature of _bootlocale in a comment just before the from _bootlocale import * line in locale.py. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9548 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9601] ftplib should accept 250 on MKD
Eric Smith e...@trueblade.com added the comment: Since this is a feature request, it could only be added to 3.2, not the other versions. -- nosy: +eric.smith type: behavior - feature request versions: -Python 2.5, Python 2.6, Python 2.7, Python 3.1, Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9601 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9548] locale can be imported at startup but relies on too many library modules
STINNER Victor victor.stin...@haypocalc.com added the comment: Antoine fixed #9589 by rewriting site.py code in C and calling it more much earlier: r83988. This commit fixes the initial problem of this issue: $ ./python -c 'import heapq; print(heapq.heapify)' built-in function heapify $ cat | ./python -c 'import heapq; print(heapq.heapify)' built-in function heapify Can we close this issue, or do you consider that it is still very important to not load too much modules at startup? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9548 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue586680] -S hides standard dynamic modules
STINNER Victor victor.stin...@haypocalc.com added the comment: r83988 does really fix this issue in python 3.2, 8 years later, yeah! -- nosy: +haypo, pitrou resolution: duplicate - fixed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue586680 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9589] test_heapq: AttributeError: 'int' object has no attribute 'pop'
STINNER Victor victor.stin...@haypocalc.com added the comment: r83988 is also the correct fix for #586680: I updated this issue. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9589 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue586680] -S hides standard dynamic modules
STINNER Victor victor.stin...@haypocalc.com added the comment: Ooops, I didn't notice that Antoine did already updated this issue. Restore the resolution as duplicate since the superseder field is set. -- resolution: fixed - duplicate ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue586680 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9596] PC/getpathp.c unused?
Antoine Pitrou pit...@free.fr added the comment: Oh, my bad. Is there any reason for the MS_WINDOWS guards in Modules/getpath.c, then? -- resolution: - invalid status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9596 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9601] ftplib should accept 250 on MKD
Changes by Antoine Pitrou pit...@free.fr: -- nosy: +giampaolo.rodola ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9601 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9596] PC/getpathp.c unused?
Martin v. Löwis mar...@v.loewis.de added the comment: No, the guards are probably redundant. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9596 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9520] Add Patricia Trie high performance container
Antoine Pitrou pit...@free.fr added the comment: For example, on the x64 machine the following dict() mapping 10,000,000 very short unicode keys (~7 chars) to integers eats 149 bytes per entry. This is counting the keys too. Under 3.x: d = {} for i in range(0, 1000): d[str(i)] = i ... sys.getsizeof(d) 402653464 sys.getsizeof(d) / len(d) 40.2653464 So, the dict itself uses ~40 bytes/entry. Since this is a 64-bit Python build, each entry uses three words of 8 bytes each, that is 24 bytes per entry (one word for the key, one word for the associated value, one word for the cached hash value). So, you see the ratio of allocated entries in the hash table over used entries is only a bit above 2, which is reasonable. Do note that unicode objects themselves are not that compact: sys.getsizeof(100) 72 If you have many of them, you might use bytestrings instead: sys.getsizeof(b100) 40 I've modified your benchmark to run under 3.x and will post it in a later message (I don't know whether bio.trie exists for 3.x, though). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9520 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9520] Add Patricia Trie high performance container
Antoine Pitrou pit...@free.fr added the comment: So, here is the modified benchmark. It first creates a cache of the random wordlist, because it is quite long to compute (for N up to 1000). The cache is reused in subsequent runs. This takes some memory though (probably won't run it if you have less than 2GB). The cache itself is quite small on-disk (around 80 MB). I'm outputting the total dict size and the space occupied per individual key, and I've also timed lookups separately. Here are results on my machine: 1000 words ( 961 keys), 3269137 words/s, 16980987 lookups/s, 51 bytes/key (0.0MB) 1 words (9042 keys), 2697648 words/s, 13680052 lookups/s, 87 bytes/key (0.8MB) 10 words ( 83168 keys), 2462269 words/s, 6956074 lookups/s, 37 bytes/key (3.0MB) 50 words ( 389442 keys), 1802431 words/s, 4733774 lookups/s, 64 bytes/key (24.0MB) 100 words ( 755372 keys), 1702130 words/s, 4485229 lookups/s, 66 bytes/key (48.0MB) 200 words ( 1463359 keys), 1616658 words/s, 4251021 lookups/s, 68 bytes/key (96.0MB) 500 words ( 3501140 keys), 1608889 words/s, 3909212 lookups/s, 57 bytes/key (192.0MB) 1000 words ( 6764089 keys), 1531136 words/s, 3600395 lookups/s, 59 bytes/key (384.0MB) As you can see, the O(1) behaviour seems almost observed up to the 1000 words limit (given the way the data is computed, I'm afraid I can't go further than that). Of course, very small dicts are faster because everything fits in the CPU caches. -- Added file: http://bugs.python.org/file18520/dcbench-py3k.py ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9520 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9584] Allow curly braces in fnmatch
Mathieu Bridon boche...@fedoraproject.org added the comment: Wow, I certainly didn't expect to generate so much controversy. :-/ First of all, thanks for the comments on the patch Antoine and David. I don't get what the purpose of these two lines is. Forbid empty patterns? I copy-pasted the handling of the '[' character in the same file, and adapted it. This test was to properly handle sequences like '[]]', and you are right, it has nothing to do in this patch, I just forgot to remove it. You probably mean while j n instead of while i n. Yes, that's a typo. :-/ Regardless, it's simpler to use j = pat.find('}', j). I know, I just thought I would try to remain consistent with the way the '[' char was handled. You should also add a test for unmatched braces. Currently: I realised that after submitting the patch, yes. Actually, there are several other cases that I didn't properly handle, like a closing brace without a matching opening brace, or even nested braces (which are perfectly acceptable in the context of a shell like Bash). I'm working on an improved patch that would correctly handle those cases (with much more unit tests!), I guess I just hit the submit button too quickly. :) --- Now, about whether or not this is appropriate in fnmatch, I agree with David that if we want to remain really consistent with shell implementations, then fnmatch probably isn't the appropriate place to do so. In this case, I guess the correct way to implement it would be to expand the braces and generate several patterns that would all be fed to different fnmatch calls? Implementing it in fnmatch just seemed so convenient, replacing the braces with '(...|...)' constructs in a regex. People seem to agree that a thread on python-ideas would be good to discuss this change, but this ticket already generated some discussion. Should I start the thread on the mailing-list anyway or is this ticket an appropriate forum for further discussion? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9584 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7219] Unhelpful error message when a distutils package install fails due to a permissions error
Michael Foord mich...@voidspace.org.uk added the comment: The None error message *looks* to me like the result of a failed assertion. That may not be correct of course... -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7219 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4947] sys.stdout fails to use default encoding as advertised
STINNER Victor victor.stin...@haypocalc.com added the comment: Attached patch fixes this old and annoying issue. The issue only concerns sys.std* files, because Python only set the encoding and errors attributes for these files. -- keywords: +patch versions: +Python 2.7 Added file: http://bugs.python.org/file18521/file_write-2.7.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4947 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4947] sys.stdout fails to use default encoding as advertised
STINNER Victor victor.stin...@haypocalc.com added the comment: Oh, I forgot to write that my patch uses also the errors attribute. Update the patch to add tests on errors: file_write-2.7-v2.patch. -- Added file: http://bugs.python.org/file18522/file_write-2.7-v2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4947 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4947] sys.stdout fails to use default encoding as advertised
Changes by STINNER Victor victor.stin...@haypocalc.com: Removed file: http://bugs.python.org/file18521/file_write-2.7.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4947 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4947] sys.stdout fails to use default encoding as advertised
Antoine Pitrou pit...@free.fr added the comment: Your patch threatens to break compatibility. I think it would be better to simply change the encoding and errors attributes of standard streams. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4947 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9601] ftplib should accept 250 on MKD
Giampaolo Rodola' g.rod...@gmail.com added the comment: The server responses 250 instead of 257 (which would be correct according to RFC959, ftp) In response to what command? MKD? And what do you mean by tolerate? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9601 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8857] socket.getaddrinfo needs tests
Giampaolo Rodola' g.rod...@gmail.com added the comment: I'm not sure whether it's a problem with my python installation but this is what I get on FreeBSD 7.0 with both python 2.7 and 3.2: import socket socket.getaddrinfo('localhost', 80) Traceback (most recent call last): File stdin, line 1, in module socket.gaierror: [Errno 9] servname not supported for ai_socktype -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8857 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9602] PyObject_AsCharBuffer() should only accept read-only objects
New submission from STINNER Victor victor.stin...@haypocalc.com: mmap, buffer, bytearray, string and unicode objects set the char buffer callback (bf_getcharbuffer). The bytearray object sets also the release buffer callback (bf_releasebuffer). In Python 2.7, PyObject_AsCharBuffer() accepts bytearray objects, whereas the t# format of PyArg_Parse functions rejects byte bytearray objects (expect an pinned buffer object). In Python 3.2, PyObject_AsCharBuffer() releases the buffer. PyObject_AsCharBuffer() documentation (in 2.7 and 3.2) says that the function only accepts read-only objects. Something is wrong here. If the caller doesn't hold a kind of lock, the object cannot be protected against futher modifications. The caller has to ensure that the object is not modifiable until it finishs to use the char* pointer. I think that it would be safer to respect the documentation: PyObject_AsCharBuffer() should only accept read-only objects. The most important change is that functions using PyObject_AsCharBuffer() will not accept bytearray objects anymore. Attached patch (for Python 2.7) changes PyObject_AsCharBuffer() to reject modifiable objects. It removes also the character buffer callback from the bytearray type. To avoid breaking compatibility too much, I patched int(), long() and float() to still support bytearray objects. Examples of functions rejecting bytearray with the patch: - int(), long(), float(), complex() - many str methods: split, partition, rpartition, rsplit, index, find, count, translate, replace, startswith, endswith - writelines() of file objects (eg. sys.stdout.writelines) - writelines() method of a bz2 file -- My patch breaks backward compatibility, and I don't know that it is acceptable in Python 2.7. I will write a similar patch for Python 3.2. -- components: Interpreter Core files: PyObject_AsCharBuffer-2.7.patch keywords: patch messages: 113895 nosy: haypo, pitrou priority: normal severity: normal status: open title: PyObject_AsCharBuffer() should only accept read-only objects versions: Python 2.7, Python 3.2 Added file: http://bugs.python.org/file18523/PyObject_AsCharBuffer-2.7.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9602 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9584] Allow curly braces in fnmatch
Éric Araujo mer...@netwok.org added the comment: python-idea is read by more people. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9584 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9602] PyObject_AsCharBuffer() should only accept read-only objects
Antoine Pitrou pit...@free.fr added the comment: I don't think we should change anything in 2.7 at this point. It risks breaking compatibility while we are at the end of the 2.x line, for little added benefit (the old buffer API has always been insecure with mutable buffers). As for 3.2, PyObject_AsCharBuffer() should IMO be deprecated, as well as any other functions meant to query the old buffer API. -- nosy: +loewis ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9602 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8428] buildbot: test_multiprocessing timeout (test_notify_all? test_pool_worker_lifetime?)
Florent Xicluna florent.xicl...@gmail.com added the comment: Still failing on 3.2 and 2.7 - x86 FreeBSD 7.2 3.x r83981, r83971 ... http://www.python.org/dev/buildbot/all/builders/x86%20FreeBSD%207.2%203.x/builds/823 - x86 FreeBSD 7.2 2.7 r83985, r83806 ... http://www.python.org/dev/buildbot/all/builders/x86%20FreeBSD%207.2%202.7/builds/67 - x86 XP-4 2.7 r83985 http://www.python.org/dev/buildbot/all/builders/x86%20XP-4%202.7/builds/146 - sparc Ubuntu 2.7 r82939 http://www.python.org/dev/buildbot/all/builders/sparc%20Ubuntu%202.7/builds/11 Traceback on x86 XP-4 2.7: test test_multiprocessing failed -- Traceback (most recent call last): File D:\cygwin\home\db3l\buildarea\2.7.bolen-windows\build\lib\test\test_multiprocessing.py, line 746, in test_notify_all self.assertReturnsIfImplemented(6, get_value, woken) File D:\cygwin\home\db3l\buildarea\2.7.bolen-windows\build\lib\test\test_multiprocessing.py, line 120, in assertReturnsIfImplemented return self.assertEqual(value, res) AssertionError: 6 != 5 Traceback on x86 FreeBSD 7.2 3.x: == FAIL: test_notify_all (test.test_multiprocessing.WithProcessesTestCondition) -- Traceback (most recent call last): File /usr/home/db3l/buildarea/3.x.bolen-freebsd7/build/Lib/test/test_multiprocessing.py, line 740, in test_notify_all self.assertReturnsIfImplemented(6, get_value, woken) File /usr/home/db3l/buildarea/3.x.bolen-freebsd7/build/Lib/test/test_multiprocessing.py, line 114, in assertReturnsIfImplemented return self.assertEqual(value, res) AssertionError: 6 != 3 Additionally, these 2.7 buildbots hang on test_multiprocessing: - PPC Leopard 2.7 r83996, r83961 ... http://www.python.org/dev/buildbot/all/builders/PPC%20Leopard%202.7/builds/84 - PPC Tiger 2.7 r83961, r83879 ... http://www.python.org/dev/buildbot/all/builders/PPC%20Tiger%202.7/builds/100 - x86 FreeBSD 7.2 2.7 r83765 http://www.python.org/dev/buildbot/all/builders/x86%20FreeBSD%207.2%202.7/builds/54 -- components: +Tests nosy: +flox type: - behavior versions: +Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8428 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4947] sys.stdout fails to use default encoding as advertised
STINNER Victor victor.stin...@haypocalc.com added the comment: Your patch threatens to break compatibility Yes it does. But I think that nobody relies on this bug. If your terminal uses something that utf-8, you will see strange characters if you write something else than ascii characters. I supopse that anybody facing this problem uses a workaround like replacing sys.stdout object, encode manually each string with the right encoding or something else. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4947 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4947] sys.stdout fails to use default encoding as advertised
STINNER Victor victor.stin...@haypocalc.com added the comment: 3rd version of the patch: accept character buffer objects without reencoding them. Add also tests on character buffer objects. -- Added file: http://bugs.python.org/file18524/file_write-2.7-v3.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4947 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4947] sys.stdout fails to use default encoding as advertised
Changes by STINNER Victor victor.stin...@haypocalc.com: Removed file: http://bugs.python.org/file18522/file_write-2.7-v2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4947 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9600] multiprocessing Pool instantiation crashes on 64 bit 2.6.6rc1 under Windows 7
Brian Curtin cur...@acm.org added the comment: Ok, it turns out this is in fact a regression from 2.6.5. My prior investigation for that 3.x issue must not have been on the 2.6 version I thought it was. Barry: the fix from #9513 (e.g., r83722) will correct this. -- priority: normal - release blocker ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9600 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9425] Rewrite import machinery to work with unicode paths
STINNER Victor victor.stin...@haypocalc.com added the comment: r84012 creates _Py_stat(). It is a little bit different than the attached patch (_Py_stat.patch): it doesn't clear Python exception on unicode conversion error. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9425 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9425] Rewrite import machinery to work with unicode paths
Changes by STINNER Victor victor.stin...@haypocalc.com: Removed file: http://bugs.python.org/file18448/_Py_stat.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9425 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9425] Rewrite import machinery to work with unicode paths
STINNER Victor victor.stin...@haypocalc.com added the comment: r84012 patchs zipimporter_init() to use the new PyUnicode_FSDecoder() and use Py_UNICODE* (unicode) strings instead of char* (byte) strings. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9425 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5930] Transient error in multiprocessing (test_number_of_objects)
Florent Xicluna florent.xicl...@gmail.com added the comment: It happens on some 3.1 buildbots: - x86 FreeBSD 7.2 3.1 r83984, r83968, ... http://www.python.org/dev/buildbot/all/builders/x86%20FreeBSD%207.2%203.1/builds/595 - ARMv4 Debian 3.1 r83831, r83805, r83772, ... http://www.python.org/dev/buildbot/all/builders/ARMv4%20Debian%203.1/builds/257 (...) test_number_of_objects (test.test_multiprocessing.WithManagerTestZZZNumberOfObjects) ... 2c44bbe0: refcount=1 _thread.lock object at 0x2c44bbe0 2c56030c: refcount=2 multiprocessing.pool.Pool object at 0x2c56030c 2cf51a0c: refcount=1 _RLock owner=None count=0 2e3b81b4: refcount=1 generator object genexpr at 0x2e3b81b4 2e466e34: refcount=1 multiprocessing.pool.ApplyResult object at 0x2e466e34 2e5a506c: refcount=1 multiprocessing.pool.IMapIterator object at 0x2e5a506c 2c44bbe0: refcount=1 _thread.lock object at 0x2c44bbe0 2c56030c: refcount=2 multiprocessing.pool.Pool object at 0x2c56030c 2cf51a0c: refcount=1 _RLock owner=None count=0 2e3b81b4: refcount=1 generator object genexpr at 0x2e3b81b4 2e466e34: refcount=1 multiprocessing.pool.ApplyResult object at 0x2e466e34 2e5a506c: refcount=1 multiprocessing.pool.IMapIterator object at 0x2e5a506c FAIL (...) == FAIL: test_number_of_objects (test.test_multiprocessing.WithManagerTestZZZNumberOfObjects) -- Traceback (most recent call last): File /usr/home/db3l/buildarea/3.1.bolen-freebsd7/build/Lib/test/test_multiprocessing.py, line 1085, in test_number_of_objects self.assertEqual(refs, EXPECTED_NUMBER) AssertionError: 6 != 1 -- versions: -Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5930 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8857] socket.getaddrinfo needs tests
Giampaolo Rodola' g.rod...@gmail.com added the comment: This seems to be related with issue 1282647. Modified patch which skips the test in case of buggy libc version is in attachment. -- Added file: http://bugs.python.org/file18525/getaddrinfo3.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8857 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1282647] socket.getaddrinfo() bug for IPv6 enabled platforms
Giampaolo Rodola' g.rod...@gmail.com added the comment: I agree with Bert that this is not a Python issue hence I'm closing this out as invalid. Btw, the libc version in which this has been fixed should be 2.1.2: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=52195 -- nosy: +giampaolo.rodola resolution: - invalid status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1282647 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com