Live data from Hacker News

Python bug: Can assign [] = (), but not () = []

bugs.python.org

1–10 of 53 posts

Re: Python bug: Can assign [] = (), but not () = []

#7

This is a fun numpy quirk: >>> 'x'*3.5 Traceback (most recent call last): File " ", line 1, in TypeError: can't multiply sequence by non-int of type 'float' >>> import numpy as np >>> print 'x'*np.float64(3.5) xxx

I use R predominantly, so forgive the lack of adequate Python-ese.

Is this behavior because numpy overloads the multiplication operation with a string as string repetition and then implicitly casts the float64 down to an integer of 3? I'm curious why this behavior manifests. When I get a chance I'll test 'xyz'*np.float(3.5)

Re: Python bug: Can assign [] = (), but not () = []

#8

This is a fun numpy quirk: >>> 'x'*3.5 Traceback (most recent call last): File " ", line 1, in TypeError: can't multiply sequence by non-int of type 'float' >>> import numpy as np >>> print 'x'*np.float64(3.5) xxx

As an occasional numpy contributor, I would call this a bug.

Re: Python bug: Can assign [] = (), but not () = []

#9
post #8

This is a fun numpy quirk: >>> 'x'*3.5 Traceback (most recent call last): File " ", line 1, in TypeError: can't multiply sequence by non-int of type 'float' >>> import numpy as np >>> print 'x'*np.float64(3.5) xxx

As an occasional numpy contributor, I would call this a bug.

Good point - I found it after it caused a really weird bug in a library I use. I'll open an issue on github...
Post reply on HN