Re: [Tutor] Python dir(handle) function acts weird

2015-04-05 Thread Steven D'Aprano
On Sun, Apr 05, 2015 at 09:39:02AM -0400, Solomon Vimal wrote: > Hi, > I have two versions of the same software S4.1 and S5, say - they are > treated as COM handles. > When I use methodsview in MATLAB to see the list of methods in both, I get > more or less the same function list, but in Python, wh

Re: [Tutor] Matrix bug

2015-04-05 Thread Steven D'Aprano
On Sun, Apr 05, 2015 at 11:12:32AM -0300, Narci Edson Venturini wrote: > The next code has an unexpected result: > > >>>a=3*[3*[0]] > >>>a > [[0, 0, 0], [0, 0, 0], [0, 0, 0]] > >>>a[0][0]=1 > >>>a > [[1, 0, 0], [1, 0, 0], [1, 0, 0]] It isn't obvious, and it is *very* common for people to run into

Re: [Tutor] Matrix bug

2015-04-05 Thread Alan Gauld
On 05/04/15 15:12, Narci Edson Venturini wrote: The next code has an unexpected result: a=3*[3*[0]] Note that this makes three references to the list of 3 references to 0. In other words you reference the same list 3 times. So when you change the first copy you change the other 2 also. Put a

Re: [Tutor] Matrix bug

2015-04-05 Thread Emile van Sebille
On 4/5/2015 7:12 AM, Narci Edson Venturini wrote: The next code has an unexpected result: a=3*[3*[0]] a now contains three references to the same object, hence the results you show below. You can create three distinct objects as follows: >>> a = [ [0,0,0] for i in (0,1,2) ] >>> a[1][1]=1

Re: [Tutor] Python dir(handle) function acts weird

2015-04-05 Thread Alan Gauld
On 05/04/15 14:39, Solomon Vimal wrote: Hi, I have two versions of the same software S4.1 and S5, say - they are treated as COM handles. When I use methodsview in MATLAB to see the list of methods in both, I get more or less the same function list, but in Python, when I use dir(s4.1) I get the id

[Tutor] Python dir(handle) function acts weird

2015-04-05 Thread Solomon Vimal
Hi, I have two versions of the same software S4.1 and S5, say - they are treated as COM handles. When I use methodsview in MATLAB to see the list of methods in both, I get more or less the same function list, but in Python, when I use dir(s4.1) I get the identical list to MATLAB methodsview, but di

[Tutor] Matrix bug

2015-04-05 Thread Narci Edson Venturini
The next code has an unexpected result: >>>a=3*[3*[0]] >>>a [[0, 0, 0], [0, 0, 0], [0, 0, 0]] >>>a[0][0]=1 >>>a [[1, 0, 0], [1, 0, 0], [1, 0, 0]] The code assigned to "1" a(0,0), a(1,0) and a(2,0). It was expected: [[1, 0, 0], [0, 0, 0], [0, 0, 0]] When the followind code is ran, them the corre

Re: [Tutor] Use of "or" in a lambda expression

2015-04-05 Thread boB Stepp
On Sun, Apr 5, 2015 at 3:06 AM, Alan Gauld wrote: > On 05/04/15 04:45, boB Stepp wrote: > > He could have done it in various other ways too: > > eg. > lambda : all(print('Hello lambda world!'), sys.exit() ) > > >> Well, now I am curious as to why the "all" form evaluates BOTH >> el

Re: [Tutor] Loops

2015-04-05 Thread Steven D'Aprano
On Sun, Apr 05, 2015 at 01:11:06PM +0200, Marcus Lütolf wrote: > Why do I get this traceback with the infinite loop below but not with the > definitw loop (bottom of mail)? You forgot to show the definite loop, but the error in the infinite loop is explained by the error message. You should read

Re: [Tutor] Loops

2015-04-05 Thread Alan Gauld
On 05/04/15 12:11, Marcus Lütolf wrote: Why do I get this traceback with the infinite loop below but not with the definitw loop (bottom of mail)? I don;t see anyt loops at the bottom. But as for this one... count = 0 total = 0 while True: x = raw_input('Enter a number') raw_input read

Re: [Tutor] Loops

2015-04-05 Thread Mark Lawrence
On 05/04/2015 12:11, Marcus Lütolf wrote: Why do I get this traceback with the infinite loop below but not with the definitw loop (bottom of mail)? Thanks for help, Marcus. count = 0 total = 0 while True: x = raw_input('Enter a number') count = count + 1 total = total + x pr

[Tutor] Loops

2015-04-05 Thread Marcus Lütolf
Why do I get this traceback with the infinite loop below but not with the definitw loop (bottom of mail)? Thanks for help, Marcus. count = 0 total = 0 while True: x = raw_input('Enter a number') count = count + 1 total = total + x print count, total, (total/count) T

Re: [Tutor] Use of "or" in a lambda expression

2015-04-05 Thread Alan Gauld
On 05/04/15 04:45, boB Stepp wrote: He could have done it in various other ways too: eg. lambda : all(print('Hello lambda world!'), sys.exit() ) Well, now I am curious as to why the "all" form evaluates BOTH elements. Apparently it does not apply the short-circuit logic we have been discussi