Re: Bug with lists of pairs of lists and append()

2007-10-01 Thread Gabriel Zachmann
> 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 matc

Re: Bug with lists of pairs of lists and append()

2007-10-01 Thread Gabriel Zachmann
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)

Re: Bug with lists of pairs of lists and append()

2007-10-01 Thread Gabriel Zachmann
> 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 simplici

Re: Bug with lists of pairs of lists and append()

2007-10-01 Thread Gabriel Zachmann
> 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

Bug with lists of pairs of lists and append()

2007-09-28 Thread Gabriel Zachmann
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]) ([

Bug with lists of pairs of lists and append()

2007-09-28 Thread Gabriel Zachmann
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])

Re: urllib behaves strangely

2006-06-13 Thread Gabriel Zachmann
> 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. -- /

Re: urllib behaves strangely

2006-06-13 Thread Gabriel Zachmann
> 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

urllib behaves strangely

2006-06-12 Thread Gabriel Zachmann
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 fi

definition of 'polymorphism' and python

2005-12-14 Thread Gabriel Zachmann
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. -- /--

const objects (was Re: Death to tuples!)

2005-12-14 Thread Gabriel Zachmann
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-produc

Re: ownership problem?

2005-11-27 Thread Gabriel Zachmann
> 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 t

ownership problem?

2005-11-20 Thread Gabriel Zachmann
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,

Re: different binding behavior

2005-11-18 Thread Gabriel Zachmann
> 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 plac

combine doxygen and doc-strings?

2005-11-18 Thread Gabriel Zachmann
Is there a way to combine doxygen comments, like this one ## Documentation for a function. # @var a - variable # More details. def func( a ): pass with the doc strings, like this one def func( a ): """ Documentation for a function. More details. """ pass ? Ob

different binding behavior

2005-11-10 Thread Gabriel Zachmann
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. -- /