[Tutor] cannonical matrix representation?
What's the best way to represent a matrix M with 4 dimensions, such as M[x][y][z][t] where each element in the sparse matrix could be a simple number, or could be an executable Python function snipped that returns a value when that cell is evaluated? The user of the program will type in Python functions to be inserted into particular cells in the 4-D matrix. I did't see any package that exactly does this; do I write my own Matrix class and base it on lists? Thanks! -Mike p.s. This seems to me like it ought to be built into the base language - multidimensional object arrays. (Indeed, maybe it is, and I'm just too dense to notice!) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Simple Tkinter question
I'm trying to update an Entry's textvariable several times within my Button handler, like so: from Tkinter import * from time import * def my_update(): for i in range(3): tv.set("Now it's %d"%i) sleep(1) root=Tk() tv=StringVar() Entry(textvariable=tv).pack() tv.set("Initial Value of StringVar") Button(text="Update", command=my_update).pack() root.mainloop() What happens when I hit the Update button is a 3-second pause, then "Now it's 2" is displayed. What I expected to see in the Entry was: "Now it's 0" (right away) "Now it's 1" (after 1 second pause) "Now it's 2" (after another 1 second pause) Any idea what's going on here? Why doesn't "tv.set("") happen immediately? Thanks, -Mike ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Combining dictionaries
On Tue, 6 Sep 2005, Danny Yoo wrote: >> No, that's not what he wants. >> >> He wants c = a + b to work when a and b are dictionaries. >> >> Why is Python broken in such an obvious way? > It might not be obvious. If a and b overlap so that they share keys, then > we might have the following situation: I did consider that, but of course, "update" has to deal with that issue already. >c1 = a + b >c2 = b + a > > Are c1 and c2 the same? Answer: maybe > One possible problem is that this kind of "merging" operation on > dictionaries isn't "commutative". And notationally, addition is supposed > to be so. Forcing the notation of arithmetic on dictionaries is > seductive, but it can invite logical errors. ( See my note, below, on the "*" operator [1]. ) Then use an operator like "++" which would be non-commutative "addition". >>> a={1:1,2:2} >>> b={2:22,3:3} >>> c=dict(a) >>> c.update(b) # This would be c = a ++ b >>> c {1: 1, 2: 22, 3: 3} >>> c=dict(b) >>> c.update(a) # This would be c = b ++ a >>> c {1: 1, 2: 2, 3: 3} Seems like a straightforward improvement. -- [1] Speaking of things that are suprising: >>> "foo" "bar "*3 'foobar foobar foobar ' >>> "foo" + "bar "*3 'foobar bar bar ' This also seems like a nasty bug (to me, at least). Because one would think that the "*" operator would bind more closely than the '"' or implied concatenation would. How can I actively help fix these Python bugs? > Best of wishes to you! Same to you! Thanks! -Mike ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Combining dictionaries
>Is this what you want ? > >c = dict(a) >c.update(b) > >Pierre >> Is there an easy way to combine dictionaries? >> >> a = {} >> b = {} >> >> a = {'a':'a', 'b':'b', 'c':'c'} >> b = {'1':1, '2':2, '3':3} >> c = a + b # doesn't seem to work >> >> desired: >> c = {'a':'a', 'b':'b', 'c':'c', '1':1, '2':2, '3':3} >> >> Frank No, that's not what he wants. He wants c = a + b to work when a and b are dictionaries. Why is Python broken in such an obvious way? Thanks -Mike ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Case ?
Why does Python not have a "case" statement, like C? Thanks! -Mike ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor