Re: language design question
isinstance(1, object) True What's 1 . len() ? That's easy! since 1 is actually syntactic sugar for set([set([])]), clearly 1.len() == 1. ;-) v. (actually, make that frozenset([frozenset([])])...) -- http://mail.python.org/mailman/listinfo/python-list
Re: Tuple assignment and generators?
Wow, so, to see if I understand correctly: r = 0 s = 0 t = 11 u = 11 r == s True t == u True r is s True t is u False ... ? what the...? does anybody else get mighty uncomfortable about this? s. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tuple assignment and generators?
No. Why should you ever care about whether two integers representing values are the same object? Your tests should be with `==`, not `is`. Given this though, what other such beauties are lurking in the interpreter, under the name of 'implementation accidents'? One of the things that drew me to python is the claimed consistency and orthogonality of both language and implementation, not sacrificing clarity for performance, minimizing ad-hoc design hacks and weird gotcha's, etc... In fact, I think my code contains things like if len(arg) is 0: and so on, and I feel I should be able to do so given the way python treats (claims to treat?) constant objects, even if I don't care whether the values actually represent the same object. s. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tuple assignment and generators?
beasts. It can get even worse: I can define an object (in C++ as well as in python) that is not even equal to itself. Not that I felt the need for that so far hehe... now you've picked my curiosity... how? ps. def __eq__(self, other): return False does not count ! -- http://mail.python.org/mailman/listinfo/python-list
Re: Tuple assignment and generators?
so anything you don't understand, and cannot be bothered to look up in the documentation, just has to be an inconsistent ad-hoc weird-gotcha design ? Does the documentation mention that x is y returns True when they are both 0 but not when they are 11 ? If so, I stand corrected. *plonk* away ... s. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tuple assignment and generators?
language reference, objects: Even the importance of object identity is affected in some sense: for immutable types, operations that compute new values may actually return a reference to any existing object with the same type and value, while for mutable objects this is not allowed. E.g., after a = 1; b = 1, a and b may or may not refer to the same object with the value one, depending on the implementation, but after c = []; d = [], c and d are guaranteed to refer to two different, unique, newly created empty lists. (note the use of may or may not and depending on the implementation) /F That, I knew. What I did not know, nor get from this explanation, is that this behaviour may differ not only within the same implementation, but with instances of the same class or type (in this case, 'int'). Is this really a case of me being too dumb or too lazy, or could it just be that this behaviour is not all that consistent ? v. v. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tuple assignment and generators?
E.g., after a = 1; b = 1, a and b may or may not refer to the same object with the value one, depending on the implementation, But when in a specific implementation this property _does_ hold for ints having value 1, I expect the same behaviour for ints with other values than 1. I guess I'm kind of weird that way. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tuple assignment and generators?
Are you telling us that you *had* read that doc, and tripped because it says depending on the implementation, when it should say at the choice of the implementation ? no. let's see, where to start ... ? let's say there's a certain property P, for the sake of this lng discussion, something more or less like a class or type's property of having immutable values, such that any instance with value X has a single, unique representation in memory and any two instantiations of objects with that value X are in fact references to the same object. Then, for example, python strings have property P whereas python lists do not: x = test y = test x is y True x = [] y = [] x is y False Now, as it turns out, whether or not python integers have property P _depends_on_their_value_. For small values, they do. For large values they don't. Yes, I understand about the interpreter optimization. I didn't know this, and I find it neither evident nor consistent. I don't think the above post explains this, regardless of how you read implementation. In fact, the whole string of replies after my initial question reminded me of something I read not too long ago, but didn't quite understand at the time. source : http://www.oreillynet.com/ruby/blog/2006/01/a_little_antiantihype.html ''' Pedantry: it's just how things work in the Python world. The status quo is always correct by definition. If you don't like something, you are incorrect. If you want to suggest a change, put in a PEP, Python's equivalent of Java's equally glacial JSR process. The Python FAQ goes to great lengths to rationalize a bunch of broken language features. They're obviously broken if they're frequently asked questions, but rather than 'fessing up and saying we're planning on fixing this, they rationalize that the rest of the world just isn't thinking about the problem correctly. Every once in a while some broken feature is actually fixed (e.g. lexical scoping), and they say they changed it because people were confused. Note that Python is never to blame. ''' taking this rant with the proverbial grain of salt, I did think it was funny. Anyway, thanks for all the attempts to show me. I will get it in the end. v. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tuple assignment and generators?
oh wow... it gets better... x = test! y = test! x is y False x = test y = test x is y True ... I had no clue. I guess the take-away lesson is to steer clear from any reliance on object identity checks, if at all possible. Are there any other such optimizations one should like to know about? v. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tuple assignment and generators?
You've been told that quite a few times before that is is not intended for what you used it. I got that. I was cleaning up some code that used is incorrectly immediately after. Some people actually listen to what others tell. Others seem to be driven by the deep desire to make even the tiniest bit of getting-a-grasp a public affair. Not really. I always found python to be true to that -- admittedly elusive -- principle of least surprise up to now (special cases aren't special enough to break the rules, maybe? I don't know. but then you figured that, right?), and was thrown off quite a bit by the behaviour described in one of the earlier posts, that is all. I wanted to ask people's explanations about it and learnt a few things on the way (thanks Dave). What did you get from all of this? -- http://mail.python.org/mailman/listinfo/python-list
Re: how to construct a binary-tree using python?
Depending on what concrete use you have for binary trees, you may want to consider tuples. What's cool about them is that you get pattern matching on your tree for free. x = ((2,4),(5,6)) y, _ = x y (2, 4) (_,y), _ = x y 4 Or you could code your own binary tree class subclassing tuple. ... just a thought. v. -- http://mail.python.org/mailman/listinfo/python-list
Re: definitive source on advanced python?
wow, this looks nice. thanks a lot. -- http://mail.python.org/mailman/listinfo/python-list
Re: definitive source on advanced python?
Thank you. The original question was not meant to sound particularly arrogant, and as you point out a book covering ONLY things like metaprogramming would probably be pretty useless in its own way. I have been using python on and off for about a year or so but still find myself staring at some of the funky recipes at the aspn cookbook site, not knowing which way is up. A good reference seems to be hard to come by, hence the question. Thanks for the link, I will have a look at some of the material. s. -- http://mail.python.org/mailman/listinfo/python-list
definitive source on advanced python?
Hi all, Is there some sort of coherent source (dead tree format, maybe?) on some of the more advanced features of python (decorators, metaclasses, etc)? I'm sort of looking for a python book that actually gets to the good stuff at some point, without first spending 6 chapters on how to append ints to a list. I can't seem to find any. I get the impression people just get by with scraps and code snippets posted on blogs left and right. (hope I'm wrong and my google skills just suck ...) Thanks in advance, stijn. -- http://mail.python.org/mailman/listinfo/python-list
Re: any() and all() on empty list?
I'm completely on board with the semantics for any(). But all() bothers me. If all() receives an empty list, it will return True, and I don't like that. To me, all() should be a more restrictive function than any(), and it bothers me to see a case where any() returns False but all() returns True. Who should we call to report this fallacy? GvR? Goedel? Tarski? no, wait... Frege ! or wait... actually, I think that must be Aristotle. Sorry Aristotle, the ol' syllogisms have to go. ; -) All silliness aside, the meaning of all() in python corresponds just fine with all in both language and logic. s. -- http://mail.python.org/mailman/listinfo/python-list
Re: Uses of The 4th Dimension (New Discovery by The Human Race!)
I WISH TO KNOW THE TRUTH: WHEN WILL WE HAVE PYPY? -- http://mail.python.org/mailman/listinfo/python-list
Re: High Order Messages in Python
On a (somewhat) related note, I've always wondered whether it is possible to emulate ruby blocks using a python generator '+ alpha'. In my limited understanding of the ruby block, the generator can inject values into a block, I suppose, but what is the block itself? can it be a function? a class instance? what would it look like? I am sure someone must have played around with this. any pointers? cheers, v. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python vs Ruby
You can tell everything is well in the world of dynamic languages when someone posts a question with nuclear flame war potential like python vs. ruby and after a while people go off singing hymns about the beauty of Scheme... I love this place. v. -- http://mail.python.org/mailman/listinfo/python-list
Re: pywordnet install problems
Thanks, I already figured it out a few days ago. In the wordnet.py file, just override the path (WNHOME and/or WNSEARCH) to the wordnet 2.0directory that has the lexnames files etc... (on my ubuntu box: '/usr/share/wordnet') That seems to fix it, although python gives a few warnings at startup. checking the web it seems this is a known issue. Thanks for the help though... I didn't bother posting the solution as I thought noone was interested anymore. cheers, vdrab. -- http://mail.python.org/mailman/listinfo/python-list
Re: pywordnet install problems
hello Steve, I had WordNet 2.0 installed but just now I tried it with 1.7.1 as well and the result was the same. It's a shame, glossing over the pywordnet page really made me want to give it a try. Are there any workarounds you can recommend ? I had a quick look at the wordnet.py file, and it looks readable enough to try and fiddle around with it, but if possible I'd like to avoid having to mess with the source file. Is there any other person / list I can ask for help on this? thanks a lot. vdrab. -- http://mail.python.org/mailman/listinfo/python-list
pywordnet install problems
hello pythoneers, I recently tried to install wordnet 2.0 and pywordnet on both an ubuntu linux running python 2.4 and a winXP running activePython 2.4.1, and I get the exact same error on both when I try to from wordnet import * : running install error: invalid Python installation: unable to open /usr/lib/python2.4/config/Makefile (No such file or directory) Adding the directories and files in question (touch Makefile) makes the install go through but (obviously) breaks the import of wordnet.py: import wordnet Traceback (most recent call last): File stdin, line 1, in ? File wordnet.py, line 1348, in ? N = Dictionary(NOUN, 'noun') File wordnet.py, line 799, in __init__ self.indexFile = _IndexFile(pos, filenameroot) File wordnet.py, line 945, in __init__ self.rewind() File wordnet.py, line 958, in rewind if (line[0] != ' '): IndexError: string index out of range Is this pywordnet package abandoned, are there weird versioning issues, or am I just extremely unlucky for the install to fail on two machines? any help greatly appreciated, vdrab. -- http://mail.python.org/mailman/listinfo/python-list