[ANN] Release 0.71.4 of Task Coach
Hi, We're happy to announce release 0.71.4 of Task Coach. This release fixes a few bugs. Bugs fixed: * Opening an old .tsk file with missing e-mail attachments would crash Task Coach. * Don't throw exception when showing an (error) message while synchronizing. * When merging from the same file multiple times, update the existing items instead of duplicating them. * Don't set negative priorities to zero in the task editor (Linux only). * Save the column width of the first column when automatic resizing of columns is off. * Actually delete tasks and notes when SyncML is disabled. * Do not create subitems in two steps, this is counter intuitive. * Properly iterate over the open viewers with Ctrl-PgDn and Ctrl-PgUp. * Update the task viewer when a note is deleted from a task. * Update the tray icon tool tip when deleting an overdue task. * Wrap long lines in description tool tip windows. Feature added: * Add a Purge deleted items entry in the File menu for people who have been using Task Coach with SyncML disabled. What is Task Coach? Task Coach is a simple task manager that allows for hierarchical tasks, i.e. tasks in tasks. Task Coach is open source (GPL) and is developed using Python and wxPython. You can download Task Coach from: http://www.taskcoach.org In addition to the source distribution, packaged distributions are available for Windows XP/Vista, Mac OS X, and Linux (Debian and RPM format). Note that Task Coach is alpha software, meaning that it is wise to back up your task file regularly, and especially when upgrading to a new release. Cheers, Task Coach developers -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
can graphs be made in python as we make in java
HI folks... i need some suggestion on making graphs. Will this be possible with normal python setup file or do i need to download add ons for that.. help me out -- http://mail.python.org/mailman/listinfo/python-list
Re: can graphs be made in python as we make in java
On Sun, Dec 7, 2008 at 12:29 AM, suku [EMAIL PROTECTED] wrote: HI folks... i need some suggestion on making graphs. Will this be possible with normal python setup file or do i need to download add ons for that.. Python includes no such module for that in the standard library. You'll need to use a third-party library. If you're writing a webapp, pygooglechart (http://pygooglechart.slowchop.com/) is pretty good. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com help me out -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Brain going crazy with recursive functions
[EMAIL PROTECTED] wrote: I'm trying to solve the 9-tile puzzle using as functional an approach as possible. I've recently finished reading SICP and am deliberately avoiding easy python-isms for the more convoluted scheme/functional methods. The following function is trivial to do with for loops and directly accessing arrays with [] syntax. I'm trying to limit myself to the types of idioms/semantics one finds in minimal scheme, such as in SICP. I want eventually to port this to scheme, but I know python better, so that's where I'm starting. My current problem is the following. The 9-tile puzzle consists of a list of lists like this [[1,2,3],[4,5,6],[7,8,0]], where the numbers can be jumbled up. I'm looking for the location of the zero using *only* recursion and operators that are similar to car/cdr. The return value should be the row,col of the zero. For example above the return value would be (2,2). I'm also trying to define a single linear_search(...) function which does the search for within the row (an inner list above) and within the whole list. linear_search takes as an argument a truth_function which does the actual work. What's tricky is that the truth function for the array-as-a-whole is also the linear_search for a row. Once I'm in linear_search for the array, I also call linear_search for each row. The problem is the line where it says acc.insert(0,idx) looks fishy to me. It works fine and returns the row,col of the location of the zero tile, but it seems to be mutating a variable, and that's the thing I'm trying to avoid. In a sense, it's not hard enough and python is making this too easy :) (although it took a bit of mind-wrenching to get to this point. Recursion makes you either dumber or smarter, I'm not sure which). How do I accumulate the inner value of the search so it pops out at the end, without resorting to a mutable variable? I did a bit of search and the word monad came up, but I'm not sure what that is (I know it relates to haskell and some other purely functional stuff, but I get very lost when trying to read that stuff). def linear_search(array, truth_func, acc): # Goes through each element of array and applies truth_func. # Returns index if found, otherwise returns None def linear_search_iter(idx, truth_func, arr, acc): if arr: tf = truth_func(arr[0]) if tf or type(tf) is int: acc.insert(0,idx) return idx, acc+[idx] else: return linear_search_iter(idx+1, truth_func, arr[1:], acc) return linear_search_iter(0, truth_func, array, acc) def locate_zero(p): # Locates empty tile. Returns (r,c) tuple def find_zero_in_row(row): return linear_search(row, lambda x: x==0, acc) acc = [] ls = linear_search(p, find_zero_in_row, acc) print acc return acc thanks Michael I am honestly getting lost in your code. The following fulfills your requirements as far as I can tell. It uses None as a sentinel for the truth function matching no elements of the array. Some assignments are made within the code simply to make it more readable. They are not necessary. The first element that the truth function evaluates to True is returned. I hope it helps. James def linear_search(array, truth_func, loc=(0,0)): idx1, idx2 = loc if idx1 = len(array): return None if idx2 = len(array[idx1]): return linear_search(array, truth_func, (idx1+1, 0)) value = array[idx1][idx2] tf = truth_func(value) if tf: return loc else: return linear_search(array, truth_func, (idx1, idx2+1)) a = [[5, 3, 4], [2, 0, 1], [8, 6, 7]] linear_search(a, lambda x: x==0) -- http://mail.python.org/mailman/listinfo/python-list
Re: Brain going crazy with recursive functions
James Stroud wrote: def linear_search(array, truth_func, loc=(0,0)): idx1, idx2 = loc if idx1 = len(array): return None if idx2 = len(array[idx1]): return linear_search(array, truth_func, (idx1+1, 0)) value = array[idx1][idx2] tf = truth_func(value) if tf: return loc else: return linear_search(array, truth_func, (idx1, idx2+1)) a = [[5, 3, 4], [2, 0, 1], [8, 6, 7]] linear_search(a, lambda x: x==0) PS: If I just made it to easy for you, you can practice by generalizing this to an N-dimensional array using recursion. I'm tempted to do it myself but I'm going to try to resist instead and do some work that pays. -- http://mail.python.org/mailman/listinfo/python-list
var or inout parm?
How can I make a var parm, where the called function can modify the value of the parameter in the caller? def f(x): x = x + 1 n = 1 f(n) # n should now be 2 Many TIA!! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list
Re: var or inout parm?
On Sun, Dec 7, 2008 at 12:54 AM, [EMAIL PROTECTED] wrote: How can I make a var parm, where the called function can modify the value of the parameter in the caller? Not directly possible or encouraged. You can emulate it by sticking the value in a container object (e.g. list) though: def f(x): x[0] += 1 #non-augmented assignment would work too n = [1] f(n) print n[0] #== 2 Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com def f(x): x = x + 1 n = 1 f(n) # n should now be 2 Many TIA!! Mark -- Mark Harrison Pixar Animation Studios -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: can graphs be made in python as we make in java
suku wrote: HI folks... i need some suggestion on making graphs. Will this be possible with normal python setup file or do i need to download add ons for that.. help me out I like pychart. It has the advantage of being pure python and makes very nice looking plots. You might also check out matplotlib if you are into heavyweight plotting and interactive application development. James -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3.0 automatic decoding of UTF16
John Machin wrote: Here's the scoop: It's a bug in the newline handling (in io.py, class IncrementalNewlineDecoder, method decode). It reads text files in 128- byte chunks. Converting CR LF to \n requires special case handling when '\r' is detected at the end of the decoded chunk n in case there's an LF at the start of chunk n+1. Buggy solution: prepend b'\r' to the chunk n+1 bytes and decode that -- suddenly with a 2-bytes-per- char encoding like UTF-16 we are 1 byte out of whack. Better (IMVH[1] O) solution: prepend '\r' to the result of decoding the chunk n+1 bytes. Each of the OP's files have \r on a 64-character boundary. Note: They would exhibit the same symptoms if encoded in utf-16LE instead of utf-16BE. With the better solution applied, the first file [the truncated one] gave the expected error, and the second file [the apparently OK one] gave sensible looking output. [1] I thought it best to be Very Humble given what you see when you do: import io print(io.__author__) Hope my surge protector can cope with this :-) ^%!//() NO CARRIER Please post this on the tracker so it can get included with other io work for 3.0.1. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get a beep, OS independent ?
Rainy wrote: On Dec 6, 3:40 pm, Stef Mientki [EMAIL PROTECTED] wrote: hello, I want to give a small beep, for windows there's message-beep, and there seems to be something like curses , but that package seems to be totally broken in P2.5 for windows. Any other suggestions ? thanks, Stef Mientki For win there's winsound, you have to check sys.platform and do what's necessary for the platform in question. In linux I think you can just print '\a' (or does that only work in terminals?). If you know that ext. speakers are always on, you can do a nicer beep by using some wav file, in linux it's probably easiest to use an external program to play it, like wavplay. Basically, there is no single answer, it depends on circumstances. -- http://mail.python.org/mailman/listinfo/python-list '\a' or chr(7) prints an inverted BEL. So it looks that Python version independency is even worse than OS independency ;-) I'll take a look at wxPython and Pygame if there's something useful. anyway thanks, Stef -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get a beep, OS independent ?
On Sun, Dec 7, 2008 at 1:27 AM, Stef Mientki [EMAIL PROTECTED] wrote: Rainy wrote: On Dec 6, 3:40 pm, Stef Mientki [EMAIL PROTECTED] wrote: hello, I want to give a small beep, for windows there's message-beep, and there seems to be something like curses , but that package seems to be totally broken in P2.5 for windows. Any other suggestions ? thanks, Stef Mientki For win there's winsound, you have to check sys.platform and do what's necessary for the platform in question. In linux I think you can just print '\a' (or does that only work in terminals?). If you know that ext. speakers are always on, you can do a nicer beep by using some wav file, in linux it's probably easiest to use an external program to play it, like wavplay. Basically, there is no single answer, it depends on circumstances. -- http://mail.python.org/mailman/listinfo/python-list '\a' or chr(7) prints an inverted BEL. Inverted bell? What do you mean? And what version dependency are you referring to? Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com So it looks that Python version independency is even worse than OS independency ;-) I'll take a look at wxPython and Pygame if there's something useful. anyway thanks, Stef -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Number of Python 3.x packages at the PyPI
[EMAIL PROTECTED] wrote: Is there an easy way to see the number of PyPI packages which have been ported to Python 3? Yes: browse all pacakges classified with Programming Language :: Python :: 3 You can find them at http://pypi.python.org/pypi?:action=browsec=533 It seems that some package authors only classify with Programming Language :: Python :: 3 Are there any special arrangements necessary for PyPI packages which have both a Python 2.x version and a Python 3.x version? So far, no such need has been identified. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3.0 automatic decoding of UTF16
On Dec 7, 8:15 pm, Terry Reedy [EMAIL PROTECTED] wrote: John Machin wrote: Here's the scoop: It's a bug in the newline handling (in io.py, class IncrementalNewlineDecoder, method decode). It reads text files in 128- byte chunks. Converting CR LF to \n requires special case handling when '\r' is detected at the end of the decoded chunk n in case there's an LF at the start of chunk n+1. Buggy solution: prepend b'\r' to the chunk n+1 bytes and decode that -- suddenly with a 2-bytes-per- char encoding like UTF-16 we are 1 byte out of whack. Please post this on the tracker so it can get included with other io work for 3.0.1. I'm fiddling with a short bug-demo script right now. -- http://mail.python.org/mailman/listinfo/python-list
Re: Guido's new method definition idea
Sorry Dennis, I don't understand your answer. I'm not very knowledgable with all the OO vocabulary, but just use OO. self.a , self.b , self.c are stored in the object and could later be used by other object-methods. like def print_a_b_c(self): print self,a,self.b,self.c the name 'class_elements' was just a suggestion it could be also something like 'auto_prepend_self' or whatever. bye N Dennis Lee Bieber wrote: On Sat, 06 Dec 2008 19:02:22 +0100, News123 [EMAIL PROTECTED] declaimed the following in comp.lang.python: example: class C: class_elements a,b,c,d def method(self,arg): global d a,b,c = arg[0..3] d = a + b self.e = a + d instead of class C: def method(self,arg): self.a,self.b,self.c,self.d = arg[0..4] self.e = self.a + self.b I would declare this a poor example, since a, b, c, aren't used as attributes -- they are just invocation locals. -- http://mail.python.org/mailman/listinfo/python-list
Re: as keyword woes
On Dec 6, 9:35 pm, Carl Banks [EMAIL PROTECTED] wrote: On Dec 6, 8:17 pm, Steven D'Aprano [EMAIL PROTECTED] I don't like cast, because a cast is an instruction to the compiler to treat data as some type other than what it was defined as. It doesn't create a new piece of data. (At least in C-like languages.) Actually, C-like languages do exactly that. (float)i doesn't take the bits of int i and treat them as if they were a float, it creates new data in the appropriate data type that matches the value of i semantically, which would have a very different bit pattern. '(float) i' does what he said. int i; float f= ( (float) i ); f= 1; printf( %x %f\n, i, f ); /Output: 3f80 1.00 Sorry for the tangent. -- http://mail.python.org/mailman/listinfo/python-list
Re: Guido's new method definition idea
Lie wrote: On Dec 7, 1:02 am, News123 [EMAIL PROTECTED] wrote: What would be interesting would be some syntactical sugar to get rid of the 'self' (at least in the code body). example: class C: class_elements a,b,c,d def method(self,arg): global d a,b,c = arg[0..3] d = a + b self.e = a + d Nah, that would make it not explicit. Explicit here also means that to refer to self's a, we need to explicitly refer to self. Well being explicit when trying to suggest an implicit syntax (in order to reduce typing) is a little difficult ;-) Though you're right my main goal is not being implicit but would be reducing typing and have shorter source code lines. If 'global 'varname' is accepted inside a def, then moving 'class_elements varnames' inside the def could be acceptable as well though it would requiere, that this statement is repeated per def bye N -- http://mail.python.org/mailman/listinfo/python-list
Re: Rich Comparisons Gotcha
Rasmus Fogh wrote: Dear All, For the first time I have come across a Python feature that seems completely wrong. After the introduction of rich comparisons, equality comparison does not have to return a truth value, and may indeed return nothing at all and throw an error instead. As a result, code like if foo == bar: or foo in alist cannot be relied on to work. This is clearly no accident. According to the documentation all comparison operators are allowed to return non-booleans, or to throw errors. There is explicitly no guarantee that x == x is True. I'm not a computer scientist, so my language and perspective on the topic may be a bit naive, but I'll try to demonstrate my caveman understanding example. First, here is why the ability to throw an error is a feature: class Apple(object): def __init__(self, appleness): self.appleness = appleness def __cmp__(self, other): assert isinstance(other, Apple), 'must compare apples to apples' return cmp(self.appleness, other.appleness) class Orange(object): pass Apple(42) == Orange() Second, consider that any value in python also evaluates to a truth value in boolean context. Third, every function returns something. A function's returning nothing is not a possibility in the python language. None is something but evaluates to False in boolean context. But surely you can define an equal/unequal classification for all types of object, if you want to? This reminds me of complex numbers: would 4 + 4i be equal to sqrt(32)? Even in the realm of pure mathematics, the generality of objects (i.e. numbers) can not be assumed. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Source code generation using Python
Any suggestions? I've happily used Cheetah with Leo (http://webpages.charter.net/ edreamleo/front.html) to organise and script my code generation needs, but you may also be happy with cog (http://nedbatchelder.com/code/ cog/). AK -- http://mail.python.org/mailman/listinfo/python-list
Re: Guido's new method definition idea
On Sun, 07 Dec 2008 12:43:13 +0100, News123 wrote: Sorry Dennis, I don't understand your answer. I'm not very knowledgable with all the OO vocabulary, but just use OO. self.a , self.b , self.c are stored in the object and could later be used by other object-methods. In Python terminology, they are called attributes. This is fairly standard for most OO languages too. If the attribute is stored in the instance, it is an instance attribute. If it is shared by all instances and stored in the class, it is a class attribute. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: python book for non technical absolute beginner
Thanks for your answers, I'll look at - Python Programming, for the absolute beginner (second edition by MichaelDawson. and at the LiveWires Course: http://www.livewires.org.uk/python/home I looked at http://www.greenteapress.com/thinkpython/thinkCSpy/ but think it's not a good choice for a non engineer, as this course tries to explain many principles, which are not really needed to get started. AN example is recursion. Recursion is important but confuses easily. I remember still how quite some people at school disconencted mentally when the teacher tried to explain the 'mathematical induction'. bye N News123 wrote: Hi, One of my 'non technical' friends complained about knowing nothing at all about programming (though using computers regularly for mails / web browsing / googling and downloading / cropping photos ) He wants to play a little with programming to stimulate parts of his otehrwise idle brain cells. ;-) Normally it's more the social science / linguistic parts being exercised, I thought python might be a nice language for this No my question does anybody know a nice beginners book (or a learning CD or on line tutorial)? Ideally it shouldn't be too serious and have a lot of small nice mini-examples thanks in advance for any suggestions hints bye N -- http://mail.python.org/mailman/listinfo/python-list
Re: var or inout parm?
On Sun, 07 Dec 2008 08:54:46 +, mh wrote: How can I make a var parm, where the called function can modify the value of the parameter in the caller? By using another language. def f(x): x = x + 1 n = 1 f(n) # n should now be 2 Python doesn't work like that. You should read this: http://effbot.org/zone/python-objects.htm Some work arounds, in order from worst-to-best: (1) Use a hard-coded global name: x = 1 def f(): global x x = x + 1 f() assert x == 2 (2) Wrap the value you want to change in a list, then modify the list in place. n = [1] def f(alist): alist[0] = alist[0] + 1 f(n) assert n[0] == 2 (4) Just use an ordinary function. Functions can return multiple values. n = 1 def f(x): return (x+1, 99) n, y = f(n) assert y == 99 assert n == 2 (5) Find another way to solve your problem. Why do you think you need var parameters? What problem are you hoping to solve by using them? As a former Pascal programmer, I missed var parameters at first, but now I don't. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: as keyword woes
On Dec 6, 2:29 pm, Guido van Rossum [EMAIL PROTECTED] wrote: snip So, assuming I now wish to propose a corrective PEP to remedy this situation for Python 3.1 and beyond, what is the best way to get started on such a proposal? Don't bother writing a PEP to make 'as' available as an attribute again. It has no chance of being accepted. Instead, think of a different word you could use. You could use the Latin 'qua' or the Spanish 'como', for example. qua: -dictionary.com –adverb as; as being; in the character or capacity of: The work of art qua art can be judged by aesthetic criteria only. -- http://mail.python.org/mailman/listinfo/python-list
Re: var or inout parm?
[EMAIL PROTECTED] schrieb: How can I make a var parm, where the called function can modify the value of the parameter in the caller? def f(x): x = x + 1 n = 1 f(n) # n should now be 2 Chris showed one way, another is simply returning it. As python can return ad-hoc created tuples unpack them, some C++-wrappers for example treat out/inout vars like this: def foo(in, inout): return inout, out1, out2 x, y, z = foo(a, x) Obviously you are responsible for properly assigning the returned inout to the right name again. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Rich Comparisons Gotcha
Robert Kern Wrote: Terry Reedy wrote: Rasmus Fogh wrote: Personally I would like to get these [EMAIL PROTECTED]* misfeatures removed, What you are calling a misfeature is an absence, not a presence that can be removed. That's not quite true. Rich comparisons explicitly allow non-boolean return values. Breaking up __cmp__ into multiple __special__ methods was not the sole purpose of rich comparisons. One of the prime examples at the time was numpy (well, Numeric at the time). We wanted to use == to be able to return an array with boolean values where the two operand arrays were equal. E.g. In [1]: from numpy import * In [2]: array([1, 2, 3]) == array([4, 2, 3]) Out[2]: array([False, True, True], dtype=bool) SQLAlchemy uses these operators to build up objects that will be turned into SQL expressions. print users.c.id==addresses.c.user_id users.id = addresses.user_id Basically, the idea was to turn these operators into full-fledged operators like +-/*. Returning a non-boolean violates neither the letter, nor the spirit of the feature. Unfortunately, if you do overload __eq__ to build up expressions or whatnot, the other places where users of __eq__ are implicitly expecting a boolean break. While I was (and am) a supporter of rich comparisons, I feel Rasmus's pain from time to time. It would be nice to have an alternate method to express the boolean yes, this thing is equal in value to that other thing. Unfortunately, I haven't figured out a good way to fit it in now without sacrificing rich comparisons entirely. The best way, IMHO, would have been to use an alternative notation in numpy and SQLalchemy, and have '==' always return only a truth value - it could be a non-boolean as long as the bool() function gave the correct result. Surely the extra convenience of overloading '==' in special cases was not worth breaking such basic operations as 'bool(x == y)' or 'x in alist'. Again, the problem is only with '==', not with '', '=' etc. Of course it is done now, and unlikely to be reversed. and constrain the __eq__ function to always return a truth value. It is impossible to do that with certainty by any mechanical creation-time checking. So the implementation of operator.eq would have to check the return value of the ob.__eq__ function it calls *every time*. That would slow down the speed of the 99.xx% of cases where the check is not needed and would still not prevent exceptions. And if the return value was bad, all operator.eq could do is raise and exception anyway. Sure, but then it would be a bug to return a non-boolean from __eq__ and friends. It is not a bug today. I think that's what Rasmus is proposing. Yes, that is the point. If __eq__ functions are *supposed* to return booleans I can write generic code that will work for well-behaved objects, and any errors will be somebody elses fault. If __eq__ is free to return anything, or throw an error, it becomes my responsibility to write generic code that will work anyway, including with floating point numbers, numpy, or SQLalchemy. And I cannot see any way to do that (suggestions welcome). If purportedly general code does not work with numpy, your average numpy user will not be receptive to the idea that it is all numpys fault. Current behaviour is both inconsistent and counterintuitive, as these examples show. x = float('NaN') x == x False ll = [x] x in ll True x == ll[0] False import numpy y = numpy.zeros((3,)) y array([ 0., 0., 0.]) bool(y==y) Traceback (most recent call last): File stdin, line 1, in module ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() ll1 = [y,1] y in ll1 True ll2 = [1,y] y in ll2 Traceback (most recent call last): File stdin, line 1, in module ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() Can anybody see a way this could be fixed (please)? I may well have to live with it, but I would really prefer not to. --- Dr. Rasmus H. Fogh Email: [EMAIL PROTECTED] Dept. of Biochemistry, University of Cambridge, 80 Tennis Court Road, Cambridge CB2 1GA, UK. FAX (01223)766002 -- http://mail.python.org/mailman/listinfo/python-list
Re: Select, interrupted system call, log rotation?
On Dec 6, 8:39 pm, Rainy [EMAIL PROTECTED] wrote: I got an interrupted system call exception in select and I don't know what could have caused it. Here's the error: select.select(inputs, [], [], 9) error: (4, 'Interrupted system call') Caught an exception, shutting down... It's py2.3, on mach architecture. I'm trying to figure out what caused it, and the only idea I have so far is that it could be that I have python's logging system log rotation thing running and I think I've seen a reference somewhere that it uses SIGALRM when log file reaches set size to stop and switch Python's logging package doesn't use signals, as it's cross-platform. The handler just checks when a log event is handled whether rotation should occur, and if it should, then the log files are rotated. Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
Re: Rich Comparisons Gotcha
Jamed Stroud Wrote: Rasmus Fogh wrote: Dear All, For the first time I have come across a Python feature that seems completely wrong. After the introduction of rich comparisons, equality comparison does not have to return a truth value, and may indeed return nothing at all and throw an error instead. As a result, code like if foo == bar: or foo in alist cannot be relied on to work. This is clearly no accident. According to the documentation all comparison operators are allowed to return non-booleans, or to throw errors. There is explicitly no guarantee that x == x is True. I'm not a computer scientist, so my language and perspective on the topic may be a bit naive, but I'll try to demonstrate my caveman understanding example. First, here is why the ability to throw an error is a feature: class Apple(object): def __init__(self, appleness): self.appleness = appleness def __cmp__(self, other): assert isinstance(other, Apple), 'must compare apples to apples' return cmp(self.appleness, other.appleness) class Orange(object): pass Apple(42) == Orange() True, but that does not hold for __eq__, only for __cmp__, and for__gt__, __le__, etc. Consider: Class Apple(object): def __init__(self, appleness): self.appleness = appleness def __gt__(self, other): assert isinstance(other, Apple), 'must compare apples to apples' return (self.appleness other.appleness) def __eq__(self, other): if isinstance(other, Apple): return (self.appleness == other.appleness) else: return False Second, consider that any value in python also evaluates to a truth value in boolean context. Third, every function returns something. A function's returning nothing is not a possibility in the python language. None is something but evaluates to False in boolean context. Indeed. The requirement would be not that return_value was a boolean, but that bool(return_value) was defined and gave the correct result. I understand that in some old Numeric/numpy version the numpy array __eq__ function returned a non-empty array, so that bool(numarray1 == numarray2) was true for any pair of arguments, which is one way of breaking '=='. In current numpy, even bool(numarray1 == 1) throws an error, which is another way of breaking '=='. But surely you can define an equal/unequal classification for all types of object, if you want to? This reminds me of complex numbers: would 4 + 4i be equal to sqrt(32)? Even in the realm of pure mathematics, the generality of objects (i.e. numbers) can not be assumed. It sounds like that problem is simpler in computing. sqrt(32) evaluates to 5.6568542494923806 on my computer. A complex number c with non-zero imaginary part would be unequal to sqrt(32) even if it so happened that c*c==32. Yours, Rasmus --- Dr. Rasmus H. Fogh Email: [EMAIL PROTECTED] Dept. of Biochemistry, University of Cambridge, 80 Tennis Court Road, Cambridge CB2 1GA, UK. FAX (01223)766002 -- http://mail.python.org/mailman/listinfo/python-list
Re: var or inout parm?
[EMAIL PROTECTED] wrote: How can I make a var parm, where the called function can modify the value of the parameter in the caller? def f(x): x = x + 1 n = 1 f(n) # n should now be 2 Many TIA!! Mark Why not run it and see? Your function returns None. The function in effect takes a copy of n. n is not changed. Colin W. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get a beep, OS independent ?
Chris Rebert wrote: On Sun, Dec 7, 2008 at 1:27 AM, Stef Mientki [EMAIL PROTECTED] wrote: Rainy wrote: On Dec 6, 3:40 pm, Stef Mientki [EMAIL PROTECTED] wrote: hello, I want to give a small beep, for windows there's message-beep, and there seems to be something like curses , but that package seems to be totally broken in P2.5 for windows. Any other suggestions ? thanks, Stef Mientki For win there's winsound, you have to check sys.platform and do what's necessary for the platform in question. In linux I think you can just print '\a' (or does that only work in terminals?). If you know that ext. speakers are always on, you can do a nicer beep by using some wav file, in linux it's probably easiest to use an external program to play it, like wavplay. Basically, there is no single answer, it depends on circumstances. -- http://mail.python.org/mailman/listinfo/python-list '\a' or chr(7) prints an inverted BEL. Inverted bell? In the output window (stdout) which is black letters on white background, it prints bell in white letters with a black background. What do you mean? And what version dependency are you referring to? Well some of you actually hear something, I don't, so I expect that the Python version differs. cheers, Stef Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get a beep, OS independent ?
Stef Mientki [EMAIL PROTECTED] wrote: In the output window (stdout) which is black letters on white background, it prints bell in white letters with a black background. What do you mean? And what version dependency are you referring to? Well some of you actually hear something, I don't, so I expect that the Python version differs. I expect it is the terminal software you are using that differs rather than Python. Python is just printing the ascii bell character: some environments will interpret that as a request to make a beep, some will do things like flashing the whole screen, others just output a graphic character. Python doesn't know what your environment will do. -- http://mail.python.org/mailman/listinfo/python-list
Re: python book for non technical absolute beginner
On Dec 6, 9:21 am, News123 [EMAIL PROTECTED] wrote: Hi, One of my 'non technical' friends complained about knowing nothing at all about programming (though using computers regularly for mails / web browsing / googling and downloading / cropping photos ) He wants to play a little with programming to stimulate parts of his otehrwise idle brain cells. ;-) Normally it's more the social science / linguistic parts being exercised, I thought python might be a nice language for this No my question does anybody know a nice beginners book (or a learning CD or on line tutorial)? Ideally it shouldn't be too serious and have a lot of small nice mini-examples thanks in advance for any suggestions hints bye N For something completely different, try http://rur-ple.sourceforge.net/ It's Karel the robot, using only Python, and comes with a whole bunch of lessons and exercises. André -- http://mail.python.org/mailman/listinfo/python-list
How to Write to csv file to create bulk address book
Hi , I am new to scripting, I am working on script which would create 'n' number address book entries into a csv file which would be used to import into a address book. I need suggestions for the same The fileds for csv file are as follows Title,First Name,Middle Name,Last Name,Suffix,Company,Department,Job Title,Business Street,Business Street 2,Business Street 3,Business City,Business State,Business Postal Code,Business Country,Home Street,Home Street 2,Home Street 3,Home City,Home State,Home Postal Code,Home Country,Other Street,Other Street 2,Other Street 3,Other City,Other State,Other Postal Code,Other Country,Assistant's Phone,Business Fax,Business Phone,Business Phone 2,Callback,Car Phone,Company Main Phone,Home Fax,Home Phone,Home Phone 2,ISDN,Mobile Phone,Other Fax,Other Phone,Pager,Primary Phone,Radio Phone,TTY/TDD Phone,Telex,Account,Anniversary,Assistant's Name,Billing Information,Birthday,Business Address PO Box,Categories,Children,Directory Server,E-mail Address,E- mail Type,E-mail Display Name,E-mail 2 Address,E-mail 2 Type,E- mail 2 Display Name,E-mail 3 Address,E-mail 3 Type,E-mail 3 Display Name,Gender,Government ID Number,Hobby,Home Address PO Box,Initials,Internet Free Busy,Keywords,Language,Location,Manager's Name,Mileage,Notes,Office Location,Organizational ID Number,Other Address PO Box,Priority,Private,Profession,Referred By,Sensitivity,Spouse,User 1,User 2,User 3,User 4,Web Page All the entries written by csv file by script can be random dummy as this address book is used for testing purpose. Thank you in advance, Kanthi -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get a beep, OS independent ?
On Dec 7, 2008, at 6:36 AM, Duncan Booth wrote: Python is just printing the ascii bell character: some environments will interpret that as a request to make a beep, some will do things like flashing the whole screen, others just output a graphic character. Python doesn't know what your environment will do. Agreed. But invoking the standard system beep is such a basic function that it ought to be easier than this. I'm pretty sure it's a single OS call on all platforms. On OS X, for example, it's void NSBeep(void); declared in NSGraphics.h. I'm sure it's something similarly simple on other platforms. Where's the standard place for this sort of OS-abstraction function, outside the standard Python library? I'm talking about something more light-weight than wx, QT, or TK; something that just wraps standard functions (like the system beep) and works in console apps or in any flavor of GUI app. Is there such a module out there somewhere? Best, - Joe -- http://mail.python.org/mailman/listinfo/python-list
Re: Rich Comparisons Gotcha
Quoting James Stroud [EMAIL PROTECTED]: First, here is why the ability to throw an error is a feature: class Apple(object): def __init__(self, appleness): self.appleness = appleness def __cmp__(self, other): assert isinstance(other, Apple), 'must compare apples to apples' return cmp(self.appleness, other.appleness) class Orange(object): pass Apple(42) == Orange() I beg to disagree. The right answer for the question Am I equal to this chair right here? is not I don't know, nor I can't compare. The answer is No, I'm not a chair, thus I'm not equal to this chair right here. If someone comes to my house, looking for me, he will not run away because he sees a chair before he sees me. Your assert doesn't belong inside the methot, it should be up to the caller to decide if the human-chair comparisons make sense or not. I certainly don't want to be type-checking when looking for an object within a mixed-type collection. This reminds me of complex numbers: would 4 + 4i be equal to sqrt(32)? I assume you meant sqrt(32i). Well, sqrt is a function, and if its result value is defined as 4+4i, then the answer is 'yes', otherwise, the answer should be no. sqrt(4) is *not* -2, and should not be equal to -2. The standard definition of the square root _function_ for real numbers is to take the non-negative real root. I haven't heard of a standard square root _function_ for complex numbers (there is of course, a definition of square root, but it is not a function). So, if by your definition of sqrt, sqrt(32i) returns a number, there is no ambiguity. -2 is not sqrt(4). If you need the answer to be 'True', you may be asking the wrong question. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get a beep, OS independent ?
Sorry, with import Tkinter Tkinter.Tk().bell() you get a new window for the same price... So it's usefull only when using tkinter -- http://mail.python.org/mailman/listinfo/python-list
Re: Don't you just love writing this sort of thing :)
Lawrence D'Oliveiro [EMAIL PROTECTED] writes: In message [EMAIL PROTECTED], Arnaud Delobelle wrote: * you seem to disregard the fact that in 'programming language' there is the word 'language'. A language is a way to _communicate_ information, in the case of a programming language you communicate it to the computer but also to other human beings. It was Niklaus Wirth, I think who pointed out that programming languages are not properly languages but are actually notations. Like mathematics is a notation. I suppose anyone could call them what they want. The fact is that they are languages with grammars. Anyway, replace 'language' with 'notation' in my point and it is still meaningful. And mathematics, too, is a predominantly functional, not a procedural, notation. Well, mathematics is seldom concerned with procedures, that's true. But mathematics is more preoccupied with relations than functions. Could that be why so many people are frightened of functional constructs, like my code example and things like lambdas? Because they look too much like mathematics? I don't think that people have been frightened by it. They don't think it's expressed elegantly as Python is designed to be used as an imperative language. -- Arnaud -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: Rich Comparisons Gotcha
On Sun, 07 Dec 2008 13:03:43 +, Rasmus Fogh wrote: Jamed Stroud Wrote: ... Second, consider that any value in python also evaluates to a truth value in boolean context. But bool(x) can fail too. So not every object in Python can be interpreted as a truth value. Third, every function returns something. Unless it doesn't return at all. A function's returning nothing is not a possibility in the python language. None is something but evaluates to False in boolean context. Indeed. The requirement would be not that return_value was a boolean, but that bool(return_value) was defined and gave the correct result. If __bool__ or __nonzero__ raises an exception, you would like Python to ignore the exception and return True or False. Which should it be? How do you know what the correct result should be? From the Zen of Python: In the face of ambiguity, refuse the temptation to guess. All binary operators are ambiguous when dealing with vector or array operands. Should the operator operate on the array as a whole, or on each element? The numpy people have decided that element-wise equality testing is more useful for them, and this is their prerogative to do so. In fact, the move to rich comparisons was driven by the needs of numpy. http://www.python.org/dev/peps/pep-0207/ It is a *VERY* important third-party library, and this was not the first and probably won't be the last time that their needs will move into Python the language. Python encourages such domain-specific behaviour. In fact, that's what operator-overloading is all about: classes can define what any operator means for *them*. There's no requirement that the infinity of potential classes must all define operators in a mutually compatible fashion, not even for comparison operators. For example, consider a class implementing one particular version of three-value logic. It isn't enough for == to only return True or False, because you also need Maybe: True == False = returns False True == True = returns True True == Maybe = returns Maybe etc. Or consider fuzzy logic, where instead of two truth values, you have a continuum of truth values between 0.0 and 1.0. What should comparing two such fuzzy values for equality return? A boolean True/False? Another fuzzy value? Another one from the Zen: Special cases aren't special enough to break the rules. The rules are that classes can customize their behaviour, that methods can fail, and that Python should not try to guess what the correct value should have been in the event of such a failure. Equality is a special case, but it isn't so special that it needs to be an exception from those rules. If you really need a guaranteed-can't-fail[1] equality test, try something like this untested wrapper class: class EqualityWrapper(object): def __init__(self, obj): self.wrapped = obj def __eq__(self, other): try: return bool(self.wrapped == other) except Exception: return False # or maybe True? Now wrap all your data: data = [a list of arbitrary objects] data = map(EqualityWrapper, data) process(data) [1] Not a guarantee. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get a beep, OS independent ?
On Sun, 07 Dec 2008 07:17:30 -0700, Joe Strout wrote: But invoking the standard system beep is such a basic function that it ought to be easier than this. I'm pretty sure it's a single OS call on all platforms. On OS X, for example, it's void NSBeep(void); declared in NSGraphics.h. I'm sure it's something similarly simple on other platforms. I'm not so sure. Under Unix the system beep is usually in the terminal emulation and triggered by sending '\a' to it. AFAIK there is no standard beep in X-Windows so every desktop environment implements something like audio notifications. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get a beep, OS independent ?
On Dec 7, 12:40 am, Stef Mientki [EMAIL PROTECTED] wrote: hello, I want to give a small beep, for windows there's message-beep, and there seems to be something like curses , but that package seems to be totally broken in P2.5 for windows. Any other suggestions ? thanks, Stef Mientki Not sure it's the simplest solution, but import Tkinter Tkinter.Tk().bell() makes a beep -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3.0 automatic decoding of UTF16
John Machin schrieb: He did. Ugly stuff using readline() :-) Should still work, though. Well, well, I'm a C kinda guy used to while (fgets(b, sizeof(b), f)) kinda loops :-) But, seriously - I find that whole while True: and if line == construct ugly as hell, too. How can reading a file line by line be achieved in a more pythonic kind of way? Regards, Johannes -- Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit, verlästerung von Gott, Bibel und mir und bewusster Blasphemie. -- Prophet und Visionär Hans Joss aka HJP in de.sci.physik [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: python book for non technical absolute beginner
I like this one: http://www.freenetpages.co.uk/hp/alan.gauld/ -- Powered by Gentoo GNU/LINUX http://www.linuxcrazy.com pgp.mit.edu -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3.0 automatic decoding of UTF16
On Sun, 07 Dec 2008 16:05:53 +0100 Johannes Bauer [EMAIL PROTECTED] wrote: But, seriously - I find that whole while True: and if line == construct ugly as hell, too. How can reading a file line by line be achieved in a more pythonic kind of way? for line in open(filename): do stuff with line -- D'Arcy J.M. Cain [EMAIL PROTECTED] | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
Re: Guido's new method definition idea
Erik Max Francis [EMAIL PROTECTED] writes: [about removing self] P.S. You're beating a long-dead horse here; your precise proposal has been brought up countless times on comp.lang.python and shot down every single time for the same reason. It isn't going to happen. I guess it's part of the process of learning Python :) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Python idea/proposal to assist in single-archive python applications
Python Community The following is just an idea that I considered that may be helpful in creating an application in a single archive easier and with less code. Such an application would be similar to jar files for Java. First, the application and all data files should be able to run either extracted or zipped up into an archive. When running an application as part of an archive, the first step Python would do would be to insert that archive into sys.path, and then load the internal file of the same name as the __main__ module. This zip file: myapp.zip | |-- myapp.py |-- myapp.pyc (optional) |-- application/ (main application package) |-- pixmaps/ |-- ... Could be run as something like: python --par myapp.zip In addition it is needed to be able to open a file just as easily whether that file is in the archive or not. Assuming that a datafile in an application may be located relative to the '__file__' attributes, the following will not work in an archive: file = open(os.path.join(os.path.dirname('__file__'), '..', 'pixmaps', 'splash.png')) However, a simple function, perhaps built-in, could be provided which would work for reading either internal files or regular files. That is, the function would be able to open a file '/path/to/file', and it would also be able to open a file '/path/to/zipfile.zip/internal/file'. If built in the function could also take advantage of the open modes 'rb', 'rt' and 'rU'. Currently this is not so easy. First it would require the user writing a function to be able to open a file internally and externally just as easily, using zipfile and StringIO for any internal files. Secondly, opening a file in such a way only allows binary opens, it can't take advantage of pythons 'rU' open mode if the application so needs. Also, it still requires an external startup script to set the path and import the internal module. If this function was provided in Python, then and application could fairly easily run just as well zipped up as they would unzipped. Brian Vanderburg II -- http://mail.python.org/mailman/listinfo/python-list
Re: can graphs be made in python as we make in java
On 2008-12-07, suku [EMAIL PROTECTED] wrote: i need some suggestion on making graphs. Will this be possible with normal python setup file or do i need to download add ons for that.. gnuplot-py matplotlib vtk -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get a beep, OS independent ?
On 2008-12-07, Joe Strout [EMAIL PROTECTED] wrote: But invoking the standard system beep What makes you think there is such a thing as the standard system beep? -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: Rich Comparisons Gotcha
On Sun, 07 Dec 2008 13:03:43 +, Rasmus Fogh wrote: Jamed Stroud Wrote: ... Second, consider that any value in python also evaluates to a truth value in boolean context. But bool(x) can fail too. So not every object in Python can be interpreted as a truth value. Third, every function returns something. Unless it doesn't return at all. A function's returning nothing is not a possibility in the python language. None is something but evaluates to False in boolean context. Indeed. The requirement would be not that return_value was a boolean, but that bool(return_value) was defined and gave the correct result. If __bool__ or __nonzero__ raises an exception, you would like Python to ignore the exception and return True or False. Which should it be? How do you know what the correct result should be? From the Zen of Python: In the face of ambiguity, refuse the temptation to guess. All binary operators are ambiguous when dealing with vector or array operands. Should the operator operate on the array as a whole, or on each element? The numpy people have decided that element-wise equality testing is more useful for them, and this is their prerogative to do so. In fact, the move to rich comparisons was driven by the needs of numpy. http://www.python.org/dev/peps/pep-0207/ It is a *VERY* important third-party library, and this was not the first and probably won't be the last time that their needs will move into Python the language. Python encourages such domain-specific behaviour. In fact, that's what operator-overloading is all about: classes can define what any operator means for *them*. There's no requirement that the infinity of potential classes must all define operators in a mutually compatible fashion, not even for comparison operators. For example, consider a class implementing one particular version of three-value logic. It isn't enough for == to only return True or False, because you also need Maybe: True == False = returns False True == True = returns True True == Maybe = returns Maybe etc. Or consider fuzzy logic, where instead of two truth values, you have a continuum of truth values between 0.0 and 1.0. What should comparing two such fuzzy values for equality return? A boolean True/False? Another fuzzy value? Another one from the Zen: Special cases aren't special enough to break the rules. The rules are that classes can customize their behaviour, that methods can fail, and that Python should not try to guess what the correct value should have been in the event of such a failure. Equality is a special case, but it isn't so special that it needs to be an exception from those rules. If you really need a guaranteed-can't-fail[1] equality test, try something like this untested wrapper class: class EqualityWrapper(object): def __init__(self, obj): self.wrapped = obj def __eq__(self, other): try: return bool(self.wrapped == other) except Exception: return False # or maybe True? Now wrap all your data: data = [a list of arbitrary objects] data = map(EqualityWrapper, data) process(data) [1] Not a guarantee. Well, lots to think about. Just to keep you from shooting at straw men: I would have liked it to be part of the design contract (a convention, if you like) that 1) bool(x == y) should return a boolean and never throw an error 2) x == x return True I do *not* say that bool(x) should never throw an error. I do *not* say that Python should guess a return value if an __eq__ function throws an error, only that it should have been considered a bug, or at least bad form, for __eq__ functions to do so. What might be a sensible behaviour (unlike your proposed wrapper) would be the following: def eq(x, y): if x is y: return True else: try: return (x == y) except Exception: return False If is is possible to change the language, how about having two diferent functions, one for overloading the '==' operator, and another for testing list and set membership, dictionary key identity, etc.? For instance like this - Add a new function __equals__; x.__equals__(y) could default to bool(x.__eq__(y)) - Estalish by convention that x.__equals__(y) must return a boolean and may not intentionally throw an error. - Establish by convention that 'x is y' implies 'x.__equals__(y)' in the sense that (not (x is y and not x.__equals__(y)) must always hold - Have the Python data structures call __equals__ when they want to compare objects internally (e.g. for 'x in alist', 'x in adict', 'set(alist)', etc. - Provide an equals(x,y) built-in that calls the __equals__ function - numpy and others who (mis)use '==' for their own purposes could use def __equals__(self, other): return (self is other) For the float NaN case it looks like things are already behaving like this. For numpy objects you would not lose anything, since 'numpyArray in alist' is broken
Re: Guido's new method definition idea
On Sun, 07 Dec 2008 02:49:27 -0500 acerimusdux [EMAIL PROTECTED] wrote: I'm not sure though whether allowing both syntaxes would make things more or less confusing. It might actually be helpful in some respects for newcomers to realize that self.method(arg) is somewhat the same as method(self, arg). [snip] A professor of mine once said something to the effect that in teaching it is not so important to *tell* people a lot but to *omit* as much as practically possible. This might be the single most wise thing I have ever heard. If you're a newbee and you know nothing of the language, and probably nothing about programming at all, having two possibilities will thoroughly confuse you. Only when you have a working(!) knowledge of one version will you be able to appreciate the other. Since in this case the other option has no practical benefits whatsoever (IMHO), there's absolutely no need for it. /W PS: I will state again that I do like the idea in itself, its just about 20 years too late for it. -- My real email address is constructed by swapping the domain with the recipient (local part). -- http://mail.python.org/mailman/listinfo/python-list
Re: Python idea/proposal to assist in single-archive python applications
Brian Allen Vanderburg II [EMAIL PROTECTED] wrote: In addition it is needed to be able to open a file just as easily whether that file is in the archive or not. Assuming that a datafile in an application may be located relative to the '__file__' attributes, the following will not work in an archive: Why not use pkgutil.get_data()? Provided you remember to put your zip file on PYTHONPATH you can already run modules directly out of a zipfile (Python 2.5 and later). If your zipfile contains __main__.py then with Python 2.6 or later you can run it directly: just specify the zip filename on the command line. I'm not sure what, if anything, you are asking for that doesn't already exist in Python. -- http://mail.python.org/mailman/listinfo/python-list
Re: can graphs be made in python as we make in java
On Sun, 7 Dec 2008 00:29:13 -0800 (PST) suku [EMAIL PROTECTED] wrote: HI folks... i need some suggestion on making graphs. Will this be possible with normal python setup file or do i need to download add ons for that.. help me out rpy Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Number of Python 3.x packages at the PyPI
Martin http://pypi.python.org/pypi?:action=browsec=533 Martin It seems that some package authors only classify with Martin Programming Language :: Python :: 3 I did a release for lockfile yesterday which supports 3.0. I added the Programming Language :: Python :: 3.0 tag, but not the more inlusive tag above. I just updated the information to include it so it now appears in the search results. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: Guido's new method definition idea
On Sat, 6 Dec 2008 23:21:04 -0800 (PST) Lie [EMAIL PROTECTED] wrote: I think we have to test this on newbies. [snip] Now that's talking like a programmer! Ideas on how such a survey could be conducted? Anyone? If this dead horse is revived because of that reason, then I'd go with changing the error message to something that is less confusing to newbies[1]. + googol I remember being tripped with the (thinking that python miscounted the number of argument) when I was new. This has the advantage of backward compatibility and no syntax change, just less misleading error message. [1] anything could work, but I like this one: (c is an instance of class C) if the code is: c.foo(...), Error: TypeError: c.foo() takes exactly 3 argument while if the code is: C.foo(...), Error: C.foo() takes exactly 4 arguments You can implement c.foo as a curried C.foo function, catch C.foo's TypeError exception then reraise it as c.foo exception. I'm not sure that I'd find that less confusing. Because a c.foo() *does* take four arguments, not three. It's just that the first one is implicit (Right?). How about: TypeError: c.foo() takes exactly 3 arguments in addition to the implicit instance reference. or TypeError: c.foo() takes exactly 4 arguments (5 given, including the implicit instance reference) ... or something less kludgy in that general direction. This would explain exactly what is wrong. /W -- My real email address is constructed by swapping the domain with the recipient (local part). -- http://mail.python.org/mailman/listinfo/python-list
Re: Mathematica 7 compares to other languages
Xah Lee wrote: I didn't realize until after a hour, that if Jon simply give numerical arguments to Main and Create, the result timing by a factor of 0.3 of original. What a incredible sloppiness! and he intended this to show Mathematica speed with this code? The Main[] function calls Create. The create has 3 parameters: level, c, and r. The level is a integer for the recursive level of raytracing . The c is a vector for sphere center i presume. The r is radius of the sphere. His input has c and r as integers, and this in Mathematica means computation with exact arithmetics (and automatic kicks into infinite precision if necessary). Changing c and r to float immediately reduced the timing to 0.3 of original. That is only true if you solve a completely different and vastly simpler problem, which I see you have (see below). The RaySphere function contain codes that does symbolic computation by calling Im, which is the imaginary part of a complex number!! and if so, it returns the symbol Infinity! The possible result of Infinity is significant because it is used in Intersect to do a numerical comparison in a If statement. So, here in these deep loops, Mathematica's symbolic computation is used for numerical purposes! Infinity is a floating point number. So, first optimization at the superficial code form level is to get rid of this symbolic computation. That does not speed up the original computation. Instead of checking whethere his “disc = Sqrt[b^2 - v.v + r^2]” has imaginary part, one simply check whether the argument to sqrt is negative. That does not speed up the original computation. after getting rid of the symbolic computation, i made the RaySphere function to be a Compiled function. That should improve performance but the Mathematica remains well over five orders of magnitude slower than OCaml, Haskell, Scheme, C, C++, Fortran, Java and even Lisp! Besides the above basic things, there are several aspects that his code can improve in speed. For example, he used pattern matching to do core loops. e.g. Intersect[o_, d_][{lambda_, n_}, Bound[c_, r_, s_]] any Mathematica expert knows that this is something you don't want to do if it is used in a core loop. Instead of pattern matching, one can change the form to Function and it'll speed up. Your code does not implement this change. Also, he used “Block”, which is designed for local variables and the scope is dynamic scope. However the local vars used in this are local constants. A proper code would use “With” instead. (in lisp, this is various let, let*. Lispers here can imagine how lousy the code is now.) Earlier, you said that Module should be used. Now you say With. Which is it and why? Your code does not implement this change either. Here's a improved code. The timing of this code is about 0.2 of the original. ... Timing[Export[image.pgm,[EMAIL PROTECTED]@Main[2,100,4.]]] You have only observed a speedup because you have drastically simplified the scene being rendered. Specifically, the scene I gave contained over 80,000 spheres but you are benchmarking with only 5 spheres and half of the image is blank! Using nine levels of spheres as I requested originally, your version is not measurably faster at all. Perhaps you should give a refund? -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?u -- http://mail.python.org/mailman/listinfo/python-list
Re: Netbeans Early Access and Python3
On Dec 6, 12:54 pm, king kikapu [EMAIL PROTECTED] wrote: Hi, have anyone using this release of NetBeans (6.5 with Python support) with Python 3 without any problems ? I mean, does it work with Python3 or only with 2.x ? No-one is using NetBeans for Python development ?? -- http://mail.python.org/mailman/listinfo/python-list
Re: Brain going crazy with recursive functions
[EMAIL PROTECTED] writes: I'm trying to solve the 9-tile puzzle using as functional an approach as possible. I've recently finished reading SICP and am deliberately avoiding easy python-isms for the more convoluted scheme/functional methods. The following function is trivial to do with for loops and directly accessing arrays with [] syntax. I'm trying to limit myself to the types of idioms/semantics one finds in minimal scheme, such as in SICP. I want eventually to port this to scheme, but I know python better, so that's where I'm starting. My current problem is the following. The 9-tile puzzle consists of a list of lists like this [[1,2,3],[4,5,6],[7,8,0]], where the numbers can be jumbled up. I'm looking for the location of the zero using *only* recursion and operators that are similar to car/cdr. The return value should be the row,col of the zero. For example above the return value would be (2,2). I'm not sure what your code does but there is a canonical way to transform a loop the call of a recursive function. I don't think I can put it into words easily so I've demonstrated it below on your 'locate_zero' function. def find_zero(square): The normal imperative way in simple Python. i = 0 for row in square: j = 0 for n in row: if n == 0: return i, j j += 1 i += 1 def func_find_zero(square): The translation into recursive calls. A function is created for each loop. There are no mutations. def square_loop(square, i): def row_loop(row, j): if row: if row[0] == 0: return i, j else: return row_loop(row[1:], j+1) if square: res = row_loop(square[0], 0) if res is not None: return res else: return square_loop(square[1:], i+1) return square_loop(square, 0) I've intentionally made both function 'non-clever' to make the translation process more apparent. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: Python idea/proposal to assist in single-archive python applications
[EMAIL PROTECTED] wrote: Why not use pkgutil.get_data()? Provided you remember to put your zip file on PYTHONPATH you can already run modules directly out of a zipfile (Python 2.5 and later).If your zipfile contains __main__.py then with Python 2.6 or later you can run it directly: just specify the zip filename on the command line. I'm not sure what, if anything, you are asking for that doesn't already exist in Python. -- http://mail.python.org/mailman/listinfo/python-list I wasn't aware of __main__.py for Python 2.6, I think this will work for my needs. I'll look into using pkgutil for for loading data from the archive. Thanks. Brian Vanderburg II -- http://mail.python.org/mailman/listinfo/python-list
Re: Number of Python 3.x packages at the PyPI
On 7 Dec, 09:20, Martin v. Löwis [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: Are there any special arrangements necessary for PyPI packages which have both a Python 2.x version and a Python 3.x version? So far, no such need has been identified. I've had to fork my appscript project's codebase in order to add support for Python 3.x. I would like to distribute both 2.x and 3.x versions under the same package name for obvious reasons. This isn't a problem with eggs as the Python version number is included in each egg's name, but what about source distributions where both filenames are exactly the same (appscript-0.19.0.tar.gz)? Thanks, has -- Control AppleScriptable applications from Python, Ruby and ObjC: http://appscript.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Rich Comparisons Gotcha
On Dec 7, 4:23 pm, Rasmus Fogh [EMAIL PROTECTED] wrote: If is is possible to change the language, how about having two diferent functions, one for overloading the '==' operator, and another for testing list and set membership, dictionary key identity, etc.? I've often thought that this would have made a lot of sense too, though I'd probably choose to spell the well-behaved structural equality == and the flexible numeric equality eq (a la Fortran). Hey, we could have *six* new keywords: eq, ne, le, lt, ge, gt! See the recent (September?) thread Comparing float and decimal for some of the fun that results from lack of transitivity of equality. But I think there's essentially no chance of Python changing to support this. And even if there were, Python's conflation of structural equality with numeric equality brings significant benefits in terms of readability of code, ease of learning, and general friendliness; it's only really troublesome in a few corner cases. Is the tradeoff worth it? So for me, this comes down to a case of 'practicality beats purity'. Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Guido's new method definition idea
Hi folks, The story of the explicit self in method definitions has been discussed to death and we all know it will stay. However, Guido himself acknowledged that an alternative syntax makes perfect sense and having both (old and new) in a future version of python is a possibility since it maintains backward compatibility. The alternative syntax will be syntactic sugar for the old one. This blog post of his is what I'm talking about: http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay... The proposal is to allow this: class C: def self.method( arg ): self.value = arg return self.value instead of this: class C: def method( self, arg ): self.value = arg return self.value -1 I explained why deep in the thread but I'll elaborate more here. When I see a def statement, I mentally equate that to an assigment to the thing being def'ed. So for instance, when I see this: def something(): I think of it like this: somthing = the defined function Thus, if I were to see a function definition like this def foo.bar(): return 1 I would think you were defining a function and assigning it to foo.bar. IOW, it would be mostly equivalent to this: foo.bar = lambda: 1 (Analogously, I would expect a definition like this: def baz[10](): return 1 to be equivalent to this: baz[10] = lambda: 1 ) So, if, inside a class definition, I were to see this: def self.method(): return 1 Well, I'd understand that is was a method assigment, of course, but it would conflict with what I would expect the natural meaning of something like def a.b() would be. The above statement is not equivalent to: self.method = lambda: 1 but I think that's what it ought to be, in general. Similarly, to those coming from Ruby or those operating under the frequent misunderstanding that the `def`s are happening in the context of a class object (which in reality has yet to be created), `self` in this context might be misconstrued as the class object and thus `def self.foo` might be misunderstood (through the intuitive equivalence you mention) as a defining a classmethod rather than an instance method. This is actually a real counter argument, I think. Self, the instance, doesn't exist until it is created and certainly doesn't exist during class creation. So something like class C: def self.meth( arg ): return arg can be confusing since 'self' appears as if it was defined in the scope of C but clearly it isn't yet. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Re: How to Write to csv file to create bulk address book
I am new to scripting, I am working on script which would create 'n' number address book entries into a csv file which would be used to import into a address book. I need suggestions for the same Please check out the 'csv' module. It comes with Python. Batteries included. :-) http://docs.python.org/library/csv.html There are nice examples at the end of that page. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get a beep, OS independent ?
On Dec 7, 7:49 am, Stef Mientki [EMAIL PROTECTED] wrote: Chris Rebert wrote: On Sun, Dec 7, 2008 at 1:27 AM, Stef Mientki [EMAIL PROTECTED] wrote: Rainy wrote: On Dec 6, 3:40 pm, Stef Mientki [EMAIL PROTECTED] wrote: hello, I want to give a small beep, for windows there's message-beep, and there seems to be something like curses , but that package seems to be totally broken in P2.5 for windows. Any other suggestions ? thanks, Stef Mientki For win there's winsound, you have to check sys.platform and do what's necessary for the platform in question. In linux I think you can just print '\a' (or does that only work in terminals?). If you know that ext. speakers are always on, you can do a nicer beep by using some wav file, in linux it's probably easiest to use an external program to play it, like wavplay. Basically, there is no single answer, it depends on circumstances. -- http://mail.python.org/mailman/listinfo/python-list '\a' or chr(7) prints an inverted BEL. Inverted bell? In the output window (stdout) which is black letters on white background, it prints bell in white letters with a black background. What do you mean? And what version dependency are you referring to? Well some of you actually hear something, I don't, so I expect that the Python version differs. Works for me on WinXP, Python 2.5: C:\python -c print chr(7) makes a beep. George -- http://mail.python.org/mailman/listinfo/python-list
Re: Guido's new method definition idea
Daniel Fetchinson a écrit : (snip) It doesn't add anything but makes something that exists a bit clearer Err... I fail to see how magically transforming def self.foo(...) into def foo(self, ...) makes anything clearer about what really happens and how Python's object model works. and friendlier to newbies. I'd rather say more acceptable to java-brainwashed developpers. -- http://mail.python.org/mailman/listinfo/python-list
Re: dict subclass and pickle bug (?)
James Stroud wrote: Hello All, I subclassed dict and overrode __setitem__. When instances are unpickled, the __setstate__ is not called before the keys are assigned via __setitem__ in the unpickling protocol. I googled a bit and found that this a bug filed in 2003: http://bugs.python.org/issue826897 It is still open with normal priority. Am I missing something? Is there a workaround for this bug that makes fixing it pointless or has it just fallen through the cracks for the last 5 years? Try this: def __newobj__(cls, *args): return cls.__new__(cls, *args) class DictPlus(dict): def __init__(self, *args, **kwargs): dict.__init__(self, *args, **kwargs) self.extra_thing = ExtraThingClass() def __setitem__(self, k, v): do_something_with(self.extra_thing, k, v) dict.__setitem__(self, k, v) def __setstate__(self, state): dict.update(self, state[0]) self.__dict__.update(state[1]) def __reduce__(self): state = (dict(self), self.__dict__) return (__newobj__, (self.__class__,), state) Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: Guido's new method definition idea
On Sun, 07 Dec 2008 19:13:18 +0100 Bruno Desthuilliers [EMAIL PROTECTED] wrote: and friendlier to newbies. I'd rather say more acceptable to java-brainwashed developpers. Why would you rather be unfriendly and seed ambivalence? I do see the fun in a little Python snobbism, but ... come on. /W -- My real email address is constructed by swapping the domain with the recipient (local part). -- http://mail.python.org/mailman/listinfo/python-list
Re: Guido's new method definition idea
News123 a écrit : Lie wrote: On Dec 7, 1:02 am, News123 [EMAIL PROTECTED] wrote: What would be interesting would be some syntactical sugar to get rid of the 'self' (at least in the code body). This has been debated to hell and back. And it's *not* going to happen. example: class C: class_elements a,b,c,d def method(self,arg): global d a,b,c = arg[0..3] d = a + b self.e = a + d Nah, that would make it not explicit. Explicit here also means that to refer to self's a, we need to explicitly refer to self. Well being explicit when trying to suggest an implicit syntax (in order to reduce typing) is a little difficult ;-) Though you're right my main goal is not being implicit but would be reducing typing and have shorter source code lines. then use 's' instead of 'self'. If 'global 'varname' is accepted inside a def, then moving 'class_elements varnames' inside the def could be acceptable as well self.x is an instance attribute, not a class attribute. Aslo, the def statement creates a function, not a method, so the notion of class_element or however you name it is totally irrelevant here. -- http://mail.python.org/mailman/listinfo/python-list
Is 3.0 worth breaking backward compatibility?
IMO: breaking backward compatibility is a big deal, and should only be done when it is seriously needed. Also, IMO, most of, if not all, of the changes being made in 3.0 are debatable, at best. I can not think of anything that is being changed that was really a show stopper anyway. At best, I am a casual python user, so it's likely that I am missing something. -- http://mail.python.org/mailman/listinfo/python-list
Re: Guido's new method definition idea
Daniel Fetchinson a écrit : Hi folks, The story of the explicit self in method definitions has been discussed to death and we all know it will stay. However, Guido himself acknowledged that an alternative syntax makes perfect sense and having both (old and new) in a future version of python is a possibility since it maintains backward compatibility. The alternative syntax will be syntactic sugar for the old one. This blog post of his is what I'm talking about: http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay.html The proposal is to allow this: class C: def self.method( arg ): self.value = arg return self.value instead of this: class C: def method( self, arg ): self.value = arg return self.value I.e. explicit self stays only the syntax is slightly different and may seem attractive to some. As pointed out by Guido classmethods would work similarly: class C: @classmethod def cls.method( arg ): cls.val = arg return cls.val The fact that Guido says, Now, I'm not saying that I like this better than the status quo. But I like it a lot better than [...] but it has the great advantage that it is backward compatible, and can be evolved into a PEP with a reference implementation without too much effort. shows that the proposal is viable. I'd like this new way of defining methods, what do you guys think? Anyone ready for writing a PEP? What's the advantage? If there is not a good reason, I would strongly opposed polluting the language. Did you read the blog post? The advantage is having a less confusing situation for newbies Once again: how is adding magical syntax going to reduce confusion ? (confusing the number of arguments to a method call). This is only confusing the first time. The correct solution to this problem is IMHO to better document Python's object model, specially how the descriptor protocol turns functions into methods. -- http://mail.python.org/mailman/listinfo/python-list
Importing the re module fails
This is a little puzzling. Using ipython: [EMAIL PROTECTED] Logstuff]$ ipython Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38) Type copyright, credits or license for more information. [snip ipython help message] In [1]: import re This works fine. But with the regular python interpreter I get this: [EMAIL PROTECTED] Logstuff]$ python Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38) [GCC 4.3.2 20080917 (Red Hat 4.3.2-4)] on linux2 Type help, copyright, credits or license for more information. import re Traceback (most recent call last): File stdin, line 1, in module File /usr/lib/python2.5/re.py, line 10, in module # AB ([EMAIL PROTECTED]). AttributeError: 'module' object has no attribute 'compile' What gives? Has Fedora-10 botched python or does anybody else have that problem es well? /W -- My real email address is constructed by swapping the domain with the recipient (local part). -- http://mail.python.org/mailman/listinfo/python-list
Re: Guido's new method definition idea
The story of the explicit self in method definitions has been discussed to death and we all know it will stay. However, Guido himself acknowledged that an alternative syntax makes perfect sense and having both (old and new) in a future version of python is a possibility since it maintains backward compatibility. The alternative syntax will be syntactic sugar for the old one. This blog post of his is what I'm talking about: http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-stay.html The proposal is to allow this: class C: def self.method( arg ): self.value = arg return self.value instead of this: class C: def method( self, arg ): self.value = arg return self.value I.e. explicit self stays only the syntax is slightly different and may seem attractive to some. As pointed out by Guido classmethods would work similarly: class C: @classmethod def cls.method( arg ): cls.val = arg return cls.val The fact that Guido says, Now, I'm not saying that I like this better than the status quo. But I like it a lot better than [...] but it has the great advantage that it is backward compatible, and can be evolved into a PEP with a reference implementation without too much effort. shows that the proposal is viable. I'd like this new way of defining methods, what do you guys think? Anyone ready for writing a PEP? What's the advantage? If there is not a good reason, I would strongly opposed polluting the language. Did you read the blog post? The advantage is having a less confusing situation for newbies Once again: how is adding magical syntax going to reduce confusion ? (confusing the number of arguments to a method call). This is only confusing the first time. The correct solution to this problem is IMHO to better document Python's object model, specially how the descriptor protocol turns functions into methods. As I've said in another reply the argument that def self.meth( arg ) is confusing because self doesn't exist in the current scope as an instance is convincing to me. So I no longer like the alternate syntax mentioned by Guido. Still, improved error messages would be desirable (concerning the number of arguments passed to an instance method). Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Re: Is 3.0 worth breaking backward compatibility?
On Sun, 7 Dec 2008 11:22:23 -0800 (PST) walterbyrd [EMAIL PROTECTED] wrote: IMO: breaking backward compatibility is a big deal, and should only be done when it is seriously needed. Plze. Python 3 is shipping now, and so is 2.x, where x 5. Python 2 is going to be around for quite some time. What is everybody's problem? Also, IMO, most of, if not all, of the changes being made in 3.0 are debatable, at best. I can not think of anything that is being changed that was really a show stopper anyway. Right. But warts accumulate, and some day you'll have a troglodyte of a language. Better to scrubb off some warts every now and then, so the whole thing remains agile. At best, I am a casual python user, so it's likely that I am missing something. Yes, the big picture. Also, being a casual Python user (like myself, just to clarify), *you* will least be bitten by the incombatibilties. I *really* don't get all the outrage. It's a major new version. What better time to tighten things up a bit? /W -- My real email address is constructed by swapping the domain with the recipient (local part). -- http://mail.python.org/mailman/listinfo/python-list
Re: Importing the re module fails
Andreas Waldenburger schrieb: This is a little puzzling. Using ipython: [EMAIL PROTECTED] Logstuff]$ ipython Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38) Type copyright, credits or license for more information. [snip ipython help message] In [1]: import re This works fine. But with the regular python interpreter I get this: [EMAIL PROTECTED] Logstuff]$ python Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38) [GCC 4.3.2 20080917 (Red Hat 4.3.2-4)] on linux2 Type help, copyright, credits or license for more information. import re Traceback (most recent call last): File stdin, line 1, in module File /usr/lib/python2.5/re.py, line 10, in module # AB ([EMAIL PROTECTED]). AttributeError: 'module' object has no attribute 'compile' What gives? Has Fedora-10 botched python or does anybody else have that problem es well? In my re.py module on line 10, there is no import - it has way to much comments on the module beginning. So - how does your /usr/lib/python2.5/re.py look like? And what about some modules lying around (potentially *pycs) that mask system modules? Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Is 3.0 worth breaking backward compatibility?
On Sun, 7 Dec 2008 20:35:53 +0100 Andreas Waldenburger [EMAIL PROTECTED] wrote: On Sun, 7 Dec 2008 11:22:23 -0800 (PST) walterbyrd [EMAIL PROTECTED] wrote: At best, I am a casual python user, so it's likely that I am missing something. Yes, the big picture. OK, that was a bit harsh. I apologize. But my point remains. To reiterate: * It's not like they rewrote Pascal and called it Python 3. * There is a script that helps you porting. Jeez. * Also: Spilt milk. Sorry, I do get agitated over things like this. /W -- My real email address is constructed by swapping the domain with the recipient (local part). -- http://mail.python.org/mailman/listinfo/python-list
Re: Importing the re module fails
On Sun, 07 Dec 2008 20:36:58 +0100 Diez B. Roggisch [EMAIL PROTECTED] wrote: Andreas Waldenburger schrieb: This is a little puzzling. Using ipython: [EMAIL PROTECTED] Logstuff]$ ipython Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38) Type copyright, credits or license for more information. [snip ipython help message] In [1]: import re This works fine. But with the regular python interpreter I get this: [EMAIL PROTECTED] Logstuff]$ python Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38) [GCC 4.3.2 20080917 (Red Hat 4.3.2-4)] on linux2 Type help, copyright, credits or license for more information. import re Traceback (most recent call last): File stdin, line 1, in module File /usr/lib/python2.5/re.py, line 10, in module # AB ([EMAIL PROTECTED]). AttributeError: 'module' object has no attribute 'compile' What gives? Has Fedora-10 botched python or does anybody else have that problem es well? In my re.py module on line 10, there is no import - it has way to much comments on the module beginning. So - how does your /usr/lib/python2.5/re.py look like? Just like the error message says: # AB ([EMAIL PROTECTED]). on line ten. That's what confused me so much (among being confused anyway). And what about some modules lying around (potentially *pycs) that mask system modules? Bullseye. I had a re.pyc in the current directory, because I stupidly created a testbed called re.py. Realizing my folly I renamed it to something else, while forgetting to delete the already created re.pyc. Thanks, and sorry for the noise. (I do wonder why ipython didn't complain, though.) /W -- My real email address is constructed by swapping the domain with the recipient (local part). -- http://mail.python.org/mailman/listinfo/python-list
Re: Guido's new method definition idea
Daniel Fetchinson a écrit : (snip) Still, improved error messages would be desirable (concerning the number of arguments passed to an instance method). Then count me as +2 on this !-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Number of Python 3.x packages at the PyPI
I've had to fork my appscript project's codebase in order to add support for Python 3.x. I would like to distribute both 2.x and 3.x versions under the same package name for obvious reasons. This isn't a problem with eggs as the Python version number is included in each egg's name, but what about source distributions where both filenames are exactly the same (appscript-0.19.0.tar.gz)? I see. My initial reaction was that something should be done about this; please do bring this up on [EMAIL PROTECTED] On second thought: can't you just include the source of both versions in a single source distribution file? If you are going to release them in lock-step, you probably want to always release both sets of sources together; if you don't release them in lock-step, users will get confused how to obtain the most recent release for 3.x (say) if some version has only the 2.x release. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get a beep, OS independent ?
On Dec 7, 2008, at 8:48 AM, Grant Edwards wrote: On 2008-12-07, Joe Strout [EMAIL PROTECTED] wrote: But invoking the standard system beep What makes you think there is such a thing as the standard system beep? Because OS X (the platform with which I'm most familiar) certainly has one, and REALbasic has had a Beep method for years which works on all platforms. If RB can do it, we can do it too. Best, - Joe -- http://mail.python.org/mailman/listinfo/python-list
[OT] [sort of] Malcom Reynolds?
Just found this in the re module's docs: m = re.match(r(?Pfirst_name\w+) (?Plast_name\w+), Malcom Reynolds) Does this represent an attempt to phase out the gratuitous Monty Python references in favor of gratuitous Firefly references? Because if so, I'm all for it. Anyways, stuff like that really makes reading documentation fun. /W -- My real email address is constructed by swapping the domain with the recipient (local part). -- http://mail.python.org/mailman/listinfo/python-list
Re: Brain going crazy with recursive functions
On Sat, 06 Dec 2008 23:33:35 -0800, 5lvqbwl02 wrote: I'm trying to solve the 9-tile puzzle using as functional an approach as possible. I've recently finished reading SICP and am deliberately avoiding easy python-isms for the more convoluted scheme/functional methods. The following function is trivial to do with for loops and directly accessing arrays with [] syntax. I'm trying to limit myself to the types of idioms/semantics one finds in minimal scheme, such as in SICP. I want eventually to port this to scheme, but I know python better, so that's where I'm starting. My current problem is the following. The 9-tile puzzle consists of a list of lists like this [[1,2,3],[4,5,6],[7,8,0]], where the numbers can be jumbled up. I'm looking for the location of the zero using *only* recursion and operators that are similar to car/cdr. The return value should be the row,col of the zero. For example above the return value would be (2,2). I'm also trying to define a single linear_search(...) function which does the search for within the row (an inner list above) and within the whole list. linear_search takes as an argument a truth_function which does the actual work. What's tricky is that the truth function for the array-as-a-whole is also the linear_search for a row. Once I'm in linear_search for the array, I also call linear_search for each row. The problem is the line where it says acc.insert(0,idx) looks fishy to me. It works fine and returns the row,col of the location of the zero tile, but it seems to be mutating a variable, and that's the thing I'm trying to avoid. In a sense, it's not hard enough and python is making this too easy :) (although it took a bit of mind-wrenching to get to this point. Recursion makes you either dumber or smarter, I'm not sure which). How do I accumulate the inner value of the search so it pops out at the end, without resorting to a mutable variable? I did a bit of search and the word monad came up, but I'm not sure what that is (I know it relates to haskell and some other purely functional stuff, but I get very lost when trying to read that stuff). def linear_search(array, truth_func, acc): # Goes through each element of array and applies truth_func. # Returns index if found, otherwise returns None def linear_search_iter(idx, truth_func, arr, acc): if arr: tf = truth_func(arr[0]) if tf or type(tf) is int: acc.insert(0,idx) return idx, acc+[idx] else: return linear_search_iter(idx+1, truth_func, arr[1:], acc) return linear_search_iter(0, truth_func, array, acc) def locate_zero(p): # Locates empty tile. Returns (r,c) tuple def find_zero_in_row (row): return linear_search(row, lambda x: x==0, acc) acc = [] ls = linear_search(p, find_zero_in_row, acc) print acc return acc locate_zero([[5, 3, 4], [2, 0, 1], [8, 6, 7]]) correctly returns (1,1) In most functional languages, their natural data types differs. For example, Haskell's list is a linked list, which if expressed in python would look like this: Python: [1, 2, 3, 4, 5] Haskell-in-Python: [1, [2, [3, [4, [5, []] linked list is more natural to use with recursive functions, so your locate zero would be like this: def search_tile(row, depth = 0): head, tail = row if head == 0: return depth elif len(tail) == 0: return None else: return search_tile(tail, depth + 1) def search_row(grid, depth = 0): head, tail = grid st = search_tile(head) if st is not None: return depth, st elif tail == []: return None else: return search_row(tail, depth + 1) Now, you noticed that lots of the code is similar, we want to generalize it. It's easy: def search_linear(list_, checker, depth = 0): head, tail = list_ if checker(head): return depth, () if checker(head) is True else checker(head) # I intentionally doesn't factor out checker(head) # as most functional language would automatically # do so because side-effect is impossible elif tail == (): return () else: return search_linear(tail, checker, depth + 1) data = (1, (2, (3, (0, () print search_linear(data, lambda x: x == 0) # (3, ()) data = (0, (2, (3, (4, () print search_linear(data, lambda x: x == 0) #(0, ()) data = (1, (2, (3, (4, () print search_linear(data, lambda x: x == 0) #() data = ((5, (3, (4, (, ((2, (0, (1, (, ((8, (6, (7, (, ( print search_linear(data, lambda row: search_linear(row, lambda tile: tile == 0)) #(1, (1, ())) -- http://mail.python.org/mailman/listinfo/python-list
Re: Guido's new method definition idea
Bruno Desthuilliers wrote: Daniel Fetchinson a écrit : (snip) It doesn't add anything but makes something that exists a bit clearer Err... I fail to see how magically transforming def self.foo(...) into def foo(self, ...) makes anything clearer about what really happens and how Python's object model works. and friendlier to newbies. I'd rather say more acceptable to java-brainwashed developpers. Nicely put! :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: [OT] [sort of] Malcom Reynolds?
In article [EMAIL PROTECTED], Andreas Waldenburger [EMAIL PROTECTED] wrote: Just found this in the re module's docs: m = re.match(r(?Pfirst_name\w+) (?Plast_name\w+), Malcom Reynolds) Does this represent an attempt to phase out the gratuitous Monty Python references in favor of gratuitous Firefly references? Because if so, I'm all for it. Ask Georg Brandl: http://svn.python.org/view/python/trunk/Doc/library/re.rst?rev=67553view=log -- Aahz ([EMAIL PROTECTED]) * http://www.pythoncraft.com/ It is easier to optimize correct code than to correct optimized code. --Bill Harlan -- http://mail.python.org/mailman/listinfo/python-list
Python for kids?
I have a 12-year-old son who spends too much time playing Xbox live and watching silly YouTube videos. I would like to try to get him interested in programming. Is anyone aware of a good book or website that addresses this concern, preferably (but not necessarily) using Python? I could try to teach him Python myself, but I'm afraid I would just frustrate him and kill his interest in programming. I did a Google search and found a few things, but not a lot. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Guido's new method definition idea
On Dec 5, 2008, at 21:21 , Daniel Fetchinson wrote: The proposal is to allow this: class C: def self.method( arg ): self.value = arg return self.value instead of this: class C: def method( self, arg ): self.value = arg return self.value I have never understood the objection to the explicit self. As far as I can tell it just stems from laziness, and perhaps (more legitimately) from an unclear error message about arguments. When I was a python newbie, a short while ago, I would have to look twice at the number of arguments in the error, but quickly learned what this meant. Forgetting self, which I still do, makes me do a face slap, but I always felt that it is *my* problem, and I still do. It is far clearer what is going on with the explicit self. Even if I were lazy, and didn't want to type it, it seems as if the proposal saves me nothing thereso why have it? It is also confusing, because when you're reading the code, self is not defined at the time, so it looks weird to have self.method pop up. Allowing both would be *ultra* confusing. I teach python to a lot of students who are new programmers, and for them to see two different forms for the same thing would be very bad, and I see absolutely no benefit, even to experienced programmers. What problem is it supposed to solve? +1 on changing the error text, however, perhaps even with a suggestion...possibly missing 'self' argument. bb -- Brian Blais [EMAIL PROTECTED] http://web.bryant.edu/~bblais -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for kids?
On Dec 7, 2008, at 15:13 , Russ P. wrote: I have a 12-year-old son who spends too much time playing Xbox live and watching silly YouTube videos. I would like to try to get him interested in programming. Is anyone aware of a good book or website check out: http://www.briggs.net.nz/log/writing/snake-wrangling-for-kids/ it's specifically for Python, and geared for the age of your son. bb -- Brian Blais [EMAIL PROTECTED] http://web.bryant.edu/~bblais -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for kids?
On Sun, 7 Dec 2008 12:13:37 -0800 (PST) Russ P. [EMAIL PROTECTED] wrote: I have a 12-year-old son who spends too much time playing Xbox live and watching silly YouTube videos. I would like to try to get him interested in programming. Is anyone aware of a good book or website that addresses this concern, preferably (but not necessarily) using Python? I could try to teach him Python myself, but I'm afraid I would just frustrate him and kill his interest in programming. I did a Google search and found a few things, but not a lot. Thanks. Since your son seems to enjoy games, getting him interested in game programming seems the most appropriate thing to do. I'm not much of a Gamer myself, but I should think maybe modding a shooter or other kind of game should be within the grasp of a 12 year old (provided you let him play shooters). Also, there's AGS (and friends) for making Adventure games. Depending on his interests, smaller projects might work out as well, such as Sudoku, Mahjongh, Card Games and whatnot. Any of those could well become father and son projects as long as you let him have the lead. Has he ever expressed an interest in programming at all? /W -- My real email address is constructed by swapping the domain with the recipient (local part). -- http://mail.python.org/mailman/listinfo/python-list
Re: Is 3.0 worth breaking backward compatibility?
walterbyrd: I can not think of anything that is being changed that was really a show stopper anyway. I agree, but Python and its culture has a characteristic that not many other languages share: it tries to be a tidy language, to have one obvious way to do most things, it values readability and sometimes even elegance. So even if those problems aren't showstoppers for most languages, for the Python culture they are bad enough to need a fix. The amount of warts in the language that a Python programmer is used to tolerate in the the language is probably 1/20 of the warts a C++ programmer digests with no problem every day. Different languages, different cultures, and sometimes even different psychology cognitive profile of the programmer. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Source code generation using Python
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 ats wrote: I want to generate 3 different versions of a C++ source code, basically injecting different flavours of inline assembler depending on target compiler/CPU. Are you aware that there are also packages that let you generate and call C code from Python on the fly? I find it most productive to write my code in all Python first and to also develop a comprehensive test suite. Then profile and replace selected portions with lower level C code with the tests being able to confirm your code is correct. Here are some packages that take an alternate approach: http://www.cs.tut.fi/~ask/cinpy/ http://code.google.com/p/shedskin/ http://pyinline.sourceforge.net/ http://scipy.org/Weave http://mdevan.nfshost.com/llvm-py/ I like LLVM the most. Roger -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkk8MkUACgkQmOOfHg372QRhsgCcCUzWHAHmjC1490yYba7c9Xrt DxMAnj/Ur2GoJkQgMrx65hYEqPwKLdVV =CvGB -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for kids?
On Dec 7, 9:13 pm, Russ P. [EMAIL PROTECTED] wrote: I have a 12-year-old son who spends too much time playing Xbox live and watching silly YouTube videos. I would like to try to get him interested in programming. Lot of people learn to program even before age of 12. But I think it's better for you to help him get interest in problem- solving and some of the other bases of the mathematic, scientific and computational mindset. Once those interests are in place, he will probably go looking by himself for things like programming languages, math and science (of course at that point a gentle guide toward good ideas, good problems to solve, good books to read and good programming languages, helps). Otherwise you risk pushing a person to learn using a tool (programming is interesting by itself, but it's mostly a tool still) before having any use for such tool or desire to learn it. And this may lead to someone with no passion to solve problems and learn. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for kids?
On Dec 7, 4:13 pm, Russ P. [EMAIL PROTECTED] wrote: I have a 12-year-old son who spends too much time playing Xbox live and watching silly YouTube videos. I would like to try to get him interested in programming. Is anyone aware of a good book or website that addresses this concern, preferably (but not necessarily) using Python? I could try to teach him Python myself, but I'm afraid I would just frustrate him and kill his interest in programming. I did a Google search and found a few things, but not a lot. Thanks. http://rur-ple.sourceforge.net André -- http://mail.python.org/mailman/listinfo/python-list
Re: Guido's new method definition idea
On Sat, 06 Dec 2008 16:34:56 -0800, Erik Max Francis wrote: `$` as a shortcut for self, on the other hand, gives absolutely no mnemonic indication what it stands for, and users would be simply left guessing. However, $ is sometimes used as an alternative way of writing S̸ (I've attempted to write here S followed by U+0338 COMBINING LONG SOLIDUS OVERLAY, in order to produce an S with a stroke through it). This is the symbol of the barred subject in Lacanian psychoanalysis, which is the Lacanian symbol for the concept of the self (see http://nosubject.com/Bar ). So, if we want Python to the programming language of choice for Lacanian psychoanalysts, perhaps we should adopt the symbol $ (or even, with Python 3's support for unicode identifiers, S followed by U+0388) instead of self. -- http://mail.python.org/mailman/listinfo/python-list
Re: Guido's new method definition idea
On Sun, 07 Dec 2008 20:56:40 GMT I V [EMAIL PROTECTED] wrote: So, if we want Python to the programming language of choice for Lacanian psychoanalysts, perhaps we should adopt the symbol $ (or even, with Python 3's support for unicode identifiers, S followed by U+0388) instead of self. OK, I'm sold. :) /W -- My real email address is constructed by swapping the domain with the recipient (local part). -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get a beep, OS independent ?
On Sun, 07 Dec 2008 00:40:53 +0100, Stef Mientki wrote: I want to give a small beep, for windows there's message-beep, and there seems to be something like curses , but that package seems to be totally broken in P2.5 for windows. Any other suggestions ? Many people have suggested sending an ASCII 07 to your terminal window, but sometimes you don't have a terminal window. Then there's the question of using the sound card versus using the PC speaker. Too complicated for me. I used a kluge: a short C program that beeps the way I want, in this case using ioctl(fd,KDMKTONE,arg) on /dev/tty0 (this is Linux). The program has enough privileges to execute even when run by unprivileged users, and of course can be invoked by whatever language you're working in. -- To email me, substitute nowhere-spamcop, invalid-net. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get a beep, OS independent ?
Peter Pearson schrieb: On Sun, 07 Dec 2008 00:40:53 +0100, Stef Mientki wrote: I want to give a small beep, for windows there's message-beep, and there seems to be something like curses , but that package seems to be totally broken in P2.5 for windows. Any other suggestions ? Many people have suggested sending an ASCII 07 to your terminal window, but sometimes you don't have a terminal window. Then there's the question of using the sound card versus using the PC speaker. Too complicated for me. I used a kluge: a short C program that beeps the way I want, in this case using ioctl(fd,KDMKTONE,arg) on /dev/tty0 (this is Linux). The program has enough privileges to execute even when run by unprivileged users, and of course can be invoked by whatever language you're working in. This can be done with python also, no need for C. See the module fcntl. The privilege-problem persists of course. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Is 3.0 worth breaking backward compatibility?
Have a read of this http://www.b-list.org/weblog/2008/dec/05/python-3000/ It's a response to questions similar to yours by James Bennett On Sun, Dec 7, 2008 at 7:22 PM, walterbyrd [EMAIL PROTECTED] wrote: IMO: breaking backward compatibility is a big deal, and should only be done when it is seriously needed. Also, IMO, most of, if not all, of the changes being made in 3.0 are debatable, at best. I can not think of anything that is being changed that was really a show stopper anyway. At best, I am a casual python user, so it's likely that I am missing something. -- http://mail.python.org/mailman/listinfo/python-list -- http://www.unprotectedhex.com http://www.smashthestack.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Rich Comparisons Gotcha
Rasmus Fogh wrote: Current behaviour is both inconsistent and counterintuitive, as these examples show. x = float('NaN') x == x False Blame IEEE for that one. Rich comparisons have nothing to do with that one. ll = [x] x in ll True x == ll[0] False import numpy y = numpy.zeros((3,)) y array([ 0., 0., 0.]) bool(y==y) Traceback (most recent call last): File stdin, line 1, in module ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() ll1 = [y,1] y in ll1 True ll2 = [1,y] y in ll2 Traceback (most recent call last): File stdin, line 1, in module ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() Can anybody see a way this could be fixed (please)? I may well have to live with it, but I would really prefer not to. Make a concrete proposal for fixing it that does not break backwards compatibility. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Is 3.0 worth breaking backward compatibility?
2008/12/7 walterbyrd [EMAIL PROTECTED]: IMO: breaking backward compatibility is a big deal, and should only be done when it is seriously needed. Also, IMO, most of, if not all, of the changes being made in 3.0 are debatable, at best. I can not think of anything that is being changed that was really a show stopper anyway. But that's what a major release number does for you. Modula2 was quite a break from Modula. Think of Python3.0 it as a new language, if you like, that's inspired by Python2. You can stay with Python2 or you can adopt the new language. That way you won't have to think of it in terms of breaking any sort of backwards compatibility because there is no backwards ;-) -- Tim Rowe -- http://mail.python.org/mailman/listinfo/python-list
Re: Rich Comparisons Gotcha
Luis Zarrabeitia wrote: Quoting James Stroud [EMAIL PROTECTED]: First, here is why the ability to throw an error is a feature: class Apple(object): def __init__(self, appleness): self.appleness = appleness def __cmp__(self, other): assert isinstance(other, Apple), 'must compare apples to apples' return cmp(self.appleness, other.appleness) class Orange(object): pass Apple(42) == Orange() I beg to disagree. The right answer for the question Am I equal to this chair right here? is not I don't know, nor I can't compare. The answer is No, I'm not a chair, thus I'm not equal to this chair right here. If someone comes to my house, looking for me, he will not run away because he sees a chair before he sees me. Your assert doesn't belong inside the methot, it should be up to the caller to decide if the human-chair comparisons make sense or not. I certainly don't want to be type-checking when looking for an object within a mixed-type collection. This reminds me of complex numbers: would 4 + 4i be equal to sqrt(32)? I assume you meant sqrt(32i). No, I definitely didn't mean sqrt(32i). I'm using sqrt() to represent the mathematical square root, and not an arbitrary function one might define, by the way. My point is that 4 + 4i, sqrt(32), and sqrt(-32) all exist in different spaces. They are not comparable, even when testing for equality in a pure mathematical sense. If when encounter these values in our programs, we might like the power to decide the results of these comparisons. In one context it might make sense to throw an exception, in another, it might make sense to return False based on the fact that we consider them different types, in yet another context, it might make sense to look at complex plane values as vectors and return their scalar magnitude for comparison to real numbers. I think this ability to define the results of comparisons is not a shortcoming of the language but a strength. -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Rich Comparisons Gotcha
Rasmus Fogh wrote: Current behaviour is both inconsistent and counterintuitive, as these examples show. x = float('NaN') x == x False Perhaps this should raise an exception? I think the problem is not with comparisons in general but with the fact that nan is type float: py type(float('NaN')) type 'float' No float can be equal to nan, but nan is a float. How can something be not a number and a float at the same time? The illogicality of nan's type creates the possibility for the illogical results of comparisons to nan including comparing nan to itself. ll = [x] x in ll True x == ll[0] False But there is consistency on the basis of identity which is the test for containment (in): py x is x True py x in [x] True Identity and equality are two different concepts. Comparing identity to equality is like comparing apples to oranges ;o) import numpy y = numpy.zeros((3,)) y array([ 0., 0., 0.]) bool(y==y) Traceback (most recent call last): File stdin, line 1, in module ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() But the equality test is not what fails here. It's the cast to bool that fails, which for numpy works like a unary ufunc. The designers of numpy thought that this would be a more desirable behavior. The test for equality likewise is a binary ufunc and the behavior was chosen in numpy for practical reasons. I don't know if you can overload the == operator in C, but if you can, you would be able to achieve the same behavior. ll1 = [y,1] y in ll1 True ll2 = [1,y] y in ll2 Traceback (most recent call last): File stdin, line 1, in module ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() I think you could be safe calling this a bug with numpy. But the fact that someone can create a bug with a language is not a condemnation of the language. For example, C makes it real easy to crash a program by overrunning the limits of an array, but no one would suggest to remove arrays from C. Can anybody see a way this could be fixed (please)? I may well have to live with it, but I would really prefer not to. Your only hope is to somehow convince the language designers to remove the ability to overload == then get them to agree on what you think the proper behavior should be for comparisons. I think the probability of that happening is about zero, though, because such a change would run counter to the dynamic nature of the language. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Rich Comparisons Gotcha
Robert Kern wrote: Terry Reedy wrote: Rasmus Fogh wrote: Personally I would like to get these [EMAIL PROTECTED]* misfeatures removed, What you are calling a misfeature is an absence, not a presence that can be removed. That's not quite true. In what way, pray tell. My statement still looks quite true to me. Rich comparisons explicitly allow non-boolean return values. They do so by not doing anything to the return value of the underlying method. As I said, the OP is complaining about an absence of a check. Moreover, the absence is intentional as I explained in the part snipped and as you further explained. And if the return value was bad, all operator.eq could do is raise and exception anyway. Sure, but then it would be a bug to return a non-boolean from __eq__ and friends. It is not a bug today. I think that's what Rasmus is proposing. Right, the addition of a check that is absent today. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: Rich Comparisons Gotcha
James Stroud wrote: [cast to bool] for numpy works like a unary ufunc. Scratch that. Not thinking and typing at same time. -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Rich Comparisons Gotcha
Rasmus Fogh wrote: Can anybody see a way this could be fixed (please)? I may well have to live with it, but I would really prefer not to. I made a suggestion in my first response, which perhaps you missed. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3.0 automatic decoding of UTF16
On Dec 8, 2:05 am, Johannes Bauer [EMAIL PROTECTED] wrote: John Machin schrieb: He did. Ugly stuff using readline() :-) Should still work, though. Well, well, I'm a C kinda guy used to while (fgets(b, sizeof(b), f)) kinda loops :-) But, seriously - I find that whole while True: and if line == construct ugly as hell, too. How can reading a file line by line be achieved in a more pythonic kind of way? By using for line in open(.) as mentioned in (1) my message that you were replying to (2) the tutorial: http://docs.python.org/3.0/tutorial/inputoutput.html#reading-and-writing-files ... skip the stuff on readline() and readlines() this time :-) While waiting for the bug to be fixed, you'll need something like the following: def utf16_getlines(fname, newline_terminated=True): f = open(fname, 'rb') raw_bytes = f.read() f.close() decoded = raw_bytes.decode('utf16') if newline_terminated: normalised = decoded.replace('\r\n', '\n') lines = normalised.splitlines(True) else: lines = decoded.splitlines() return lines That avoids the chunk-reading problem by reading the whole file in one go. In fact given the way I've written it, there can be 4 copies of the file contents. Fortunately your files are tiny. HTH, John -- http://mail.python.org/mailman/listinfo/python-list