Re: Bug with lists of pairs of lists and append()
I'm using list(l) to copy the list, Tero uses l[:], but the idea is the same. Thanks a lot for your response and the hint. But do you just want all proper partitions of lst? Then this is much simpler: lst = [0, 1, 2] s = [(lst[:i], lst[i:]) for i in range(1, len(lst))] Ah, thanks a lot for that nice line of code! Python keeps astonishing me ;-) Cheers, Gabriel. -- __ Life is so constructed that the event does not, cannot, will not match the expectation. (Charlotte Bronte) __ zach in.tu-clausthal.de __@/'www.gabrielzachmann.org __ -- http://mail.python.org/mailman/listinfo/python-list
Re: Bug with lists of pairs of lists and append()
If you're familiar with C or C++, think of s as holding a pointer to x which in turn holds a pointer to l and r, so when you change l or r, x (and s indirectly) is still pointing to the same lists which by the AH - thanks a million -- that makes it crystal clear! [Python's apparent simplicity keeps making me forget that everything is a pointer ...] BTW: It's not really misbehaving. It's doing exactly what you're telling it to do ;-) i had a feeling ... ;-) Cheers, Gabriel. -- __ Life is so constructed that the event does not, cannot, will not match the expectation. (Charlotte Bronte) __ zach in.tu-clausthal.de __@/'www.gabrielzachmann.org __ -- http://mail.python.org/mailman/listinfo/python-list
Re: Bug with lists of pairs of lists and append()
Thanks a lot for your response, too. Best regards, Gabriel. -- __ Life is so constructed that the event does not, cannot, will not match the expectation. (Charlotte Bronte) __ zach in.tu-clausthal.de __@/'www.gabrielzachmann.org __ -- http://mail.python.org/mailman/listinfo/python-list
Re: Bug with lists of pairs of lists and append()
x = (list(l), list(r)) BTW: I prefer this syntax, because it makes the copy explicit, while l[:] seems to me more implicit ... Best regards, Gabriel. -- __ Life is so constructed that the event does not, cannot, will not match the expectation. (Charlotte Bronte) __ zach in.tu-clausthal.de __@/'www.gabrielzachmann.org __ -- http://mail.python.org/mailman/listinfo/python-list
Bug with lists of pairs of lists and append()
Well, could some kind soul please explain to me why the following trivial code is misbehaving? #!/usr/bin/python s = [] l = [ 0 ] r = [0, 0] while r: x = (l,r) print x s.append( x ) l.append( r.pop(0) ) print s The output I get is: ([0], [0, 0]) ([0, 0], [0]) [([0, 0, 0], []), ([0, 0, 0], [])] and the error is in the last line: the two pairs in the outer list are identical and they should be equal to the pairs one the first and the 2nd line, respectively! Shouldn't they? I think I'm going nuts -- for the life of me I don't see what's going on ... Thanks a lot in advance for any insights, etc. Best regards, Gabriel. -- http://mail.python.org/mailman/listinfo/python-list
Bug with lists of pairs of lists and append()
Well, could some kind soul please explain to me why the following trivial code is misbehaving? #!/usr/bin/python lst = [ 0, 1, 2 ] s = [] l = [ lst[0] ] r = lst[1:] while r: x = (l,r) print x s.append( x ) l.append( r.pop(0) ) print s The output I get is: ([0], [1, 2]) ([0, 1], [2]) [([0, 1, 2], []), ([0, 1, 2], [])] and the error is in the last line: the two pairs in the outer list are identical and they should be as the pairs on the first and the 2nd line, respectively! I think I'm going nuts -- for the life of me I don't see what's going on ... (I've been tracking down a bug in my larger python script, and the cause seems to boil down to the above snippet.) Thanks a lot in advance for any insights, etc. Best regards, Gabriel. -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib behaves strangely
On the other hand something which is simply retrieving one or two fixed pages doesn't fit that definition of a bot so is probably alright. They i think so, too. even provide a link to some frameworks for writing bots e.g. http://sourceforge.net/projects/pywikipediabot/ ah, that looks nice .. Best regards, Gabriel. -- /---\ | If you know exactly what you will do -- | | why would you want to do it? | | (Picasso) | \---/ -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib behaves strangely
headers = {} headers['User-Agent'] = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4' request = urllib2.Request(url, headers) file = urllib2.urlopen(request) ah, thanks a lot, that works ! Best regards, Gabriel. -- /---\ | If you know exactly what you will do -- | | why would you want to do it? | | (Picasso) | \---/ -- http://mail.python.org/mailman/listinfo/python-list
urllib behaves strangely
Here is a very simple Python script utilizing urllib: import urllib url = http://commons.wikimedia.org/wiki/Commons:Featured_pictures/chronological; print url print file = urllib.urlopen( url ) mime = file.info() print mime print file.read() print file.geturl() However, when i ecexute it, i get an html error (access denied). On the one hand, the funny thing though is that i can view the page fine in my browser, and i can download it fine using curl. On the other hand, it must have something to do with the URL because urllib works fine with any other URL i have tried ... Any ideas? I would appreciate very much any hints or suggestions. Best regards, Gabriel. -- /---\ | If you know exactly what you will do -- | | why would you want to do it? | | (Picasso) | \---/ -- http://mail.python.org/mailman/listinfo/python-list
const objects (was Re: Death to tuples!)
I was wondering why python doesn't contain a way to make things const? If it were possible to declare variables at the time they are bound to objects that they should not allow modification of the object, then we would have a concept _orthogonal_ to data types themselves and, as a by-product, a way to declare tuples as constant lists. So this could look like this: const l = [1, 2, 3] def foo( const l ): ... and also const d = { 1 : 1, 2 : 2, ... } etc. It seems to me that implementing that feature would be fairly easy. All that would be needed is a flag with each variable. Just my tupence, Gabriel. -- /---\ | Any intelligent fool can make things bigger, more complex,| | or more violent. It takes a touch of genius - and a lot of courage - | | to move in the opposite direction. (Einstein) | \---/ -- http://mail.python.org/mailman/listinfo/python-list
definition of 'polymorphism' and python
I understand the Wikipedia article on Polymorphism ( http://en.wikipedia.org/wiki/Polymorphism_%28computer_science%29 ) that it doesn't make sense to talk about polymorphism in a fully dynamically typed language -- does the Python community agree? cheers, gabriel. -- /---\ | Any intelligent fool can make things bigger, more complex,| | or more violent. It takes a touch of genius - and a lot of courage - | | to move in the opposite direction. (Einstein) | \---/ -- http://mail.python.org/mailman/listinfo/python-list
Re: ownership problem?
the problem isn't determining who owns it, the problem is determining who's supposed to release it. that's not a very common problem in a that's about what i meant. i think, in c++, the ownership problem means the problem to determine who and when is to delete an object, or to keep track thereof. The object could be something as simple as a list element. Best regards, Gabriel. -- /---\ | Any intelligent fool can make things bigger, more complex,| | or more violent. It takes a touch of genius - and a lot of courage - | | to move in the opposite direction. (Einstein) | \---/ -- http://mail.python.org/mailman/listinfo/python-list
ownership problem?
Is it correct to say that the typical ownership problem, which frequently arises in C++, does not occur normally in Python? Best regards, Gabriel. -- /---\ | Any intelligent fool can make things bigger, more complex,| | or more violent. It takes a touch of genius - and a lot of courage - | | to move in the opposite direction. (Einstein) | \---/ -- http://mail.python.org/mailman/listinfo/python-list
Re: different binding behavior
We've just had a HUGE thread arguing about this behaviour, just three or five days ago. Let's not start it again. ok, could you please point me to it? In a nutshell, the behaviour is because ints are immutable and can't be changed in place, and lists are mutable and can be changed in place. Imagine that ints could be changed in place. Then you could do this: i don't see why there should be only one instance of Int with the value 0. But if all this has already been debated (and, apparently, my point didn't succeed), there is no need to discuss all this over again. In any case, thanks a lot for your response and summary. Best regards, Gabriel. -- /---\ | Any intelligent fool can make things bigger, more complex,| | or more violent. It takes a touch of genius - and a lot of courage - | | to move in the opposite direction. (Einstein) | \---/ -- http://mail.python.org/mailman/listinfo/python-list
different binding behavior
It seems to me that the following behavior of python (2.4.1) is inconsistent: a=1 b=a a+=1 b 1 a 2 a=[1,2] b=a b+=[3] a [1, 2, 3] b [1, 2, 3] Why was it implemented like this?? Best regards, Gabriel. -- /---\ | Any intelligent fool can make things bigger, more complex,| | or more violent. It takes a touch of genius - and a lot of courage - | | to move in the opposite direction. (Einstein) | \---/ -- http://mail.python.org/mailman/listinfo/python-list