Comment #3 on issue 1838 by asmeurer: Add support for [0]*S(5), etc.
http://code.google.com/p/sympy/issues/detail?id=1838
The motivation was this conversation on IRC:
xvedejas joined the chat room.
[11:43am] xvedejas: can anyone here help me with sympy?
[11:43am] xvedejas: it seems to have interfered with my python types
causing weird things to happen
[11:44am] xvedejas: TypeError: can't multiply sequence by non-int of
type 'Integer'
[11:56am] asmeurer: hi xvedejas
[11:56am] asmeurer: can you give me some code that causes that?
[12:10pm] xvedejas: self.n = 5
[12:10pm] xvedejas: List = [0] * self.n
[12:11pm] xvedejas: just like that basically
[12:11pm] xvedejas: I actually fixed the problem by only importing sympy
within a smaller scope, but it's
strange that it would cause that anyways
[12:11pm] asmeurer: would that normally work?
[12:11pm] xvedejas: yes
[12:11pm] xvedejas: [0] * 5 == [0, 0, 0, 0, 0]
[12:11pm] asmeurer: I did not know about that feature.
[12:12pm] asmeurer: what is self here?
[12:12pm] asmeurer: probably the easiest fix would be [0]*int(self.n)
[12:12pm] xvedejas: yes but I'd have to do that to every integer it seems
[12:13pm] xvedejas: I've fixed it however by only importing sympy in the
method that uses it
[12:13pm] asmeurer: what ever you are doing is sympifying self.n, so if you
avoid that somehow, it should to it
too I guess
[12:14pm] asmeurer: are you doing exactly self.n = 5 or self.n = result of
some calculation?
[12:14pm] xvedejas: it's the result of a calculuation... that has nothing
to do with sympy
[12:14pm] asmeurer: well it is somehow being converted to a sympy Integer
[12:14pm] xvedejas: alright
[12:14pm] asmeurer: which will happen if it is the result of any sympy
calculation
[12:15pm] xvedejas: at any rate, I'd like to say thanks to the creaters of
sympy, I'm using it for a math program
I'll be presenting at a couple conferences
[12:15pm] asmeurer: but if list.__mul__ doesn't call __int__, I don't think
there is a way that we can fix that
[12:15pm] asmeurer: unless Int.__rmul__ would work
[12:15pm] asmeurer: hmm...
[12:16pm] asmeurer: I'm going to grab lunch now, but I might play around
with that after words
[12:16pm] xvedejas: alright
[12:16pm] asmeurer: glad you are finding sympy useful!
[12:16pm] xvedejas: simplified some matrix algebra greatly :)
[12:17pm] asmeurer: by the way, if your presentation is posted online, we
would like to know about it so we can
add it to http://docs.sympy.org/outreach.html
[12:17pm] You have set yourself away with "lunch".
[12:17pm] xvedejas: cool
[1:05pm] You have returned from away.
[1:12pm] asmeurer: xvedejas: I think I could implement it so that
sympify(5)*[0] would work, but it seems that
list.__mul__(Integer) doesn't return NotImplemented, so __rmul__ (i.e.,
[0]*sympify(5)) won't work
[1:23pm] howlymowly left the chat room. (Remote host closed the connection)
[1:29pm] howlymowly joined the chat room.
[1:29pm] howlymowly left the chat room. (Remote host closed the connection)
[1:36pm] asmeurer: actually, the overridding works in Python 2.5
[1:50pm] asmeurer: OK, nevermind, it can work anywhere
[1:50pm] asmeurer: http://github.com/asmeurer/sympy/tree/list-int-mul.
[2:10pm] asmeurer: xvedejas:
http://code.google.com/p/sympy/issues/detail?id=1838
[2:11pm] asmeurer: Thanks for the report. It's always fun to learn about
new Python syntactical features.
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to sympy-iss...@googlegroups.com.
To unsubscribe from this group, send email to
sympy-issues+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en.