Short, crazy example: list-derived class, with __iadd__
class Vec(list): def __init__(self): list.__init__(self, [0.0, 0.0]) def __iadd__(self, other): assert isinstance(other, Vec) self[0] += other[0] self[1] += other[1] print "right now, v is: ", self, " as you'd expect" v = Vec() w = Vec() w[0] = 1.0 w[1] = 2.0 print "v starts:", v print "(w is:", w, " which is fine)" v += w print "(w still is:", w print "after iadd, v: ", v, " <-- becomes None! What the hey?" # - running it: py> python badvec.py v starts: [0.0, 0.0] (w is: [1.0, 2.0] which is fine) right now, v is: [1.0, 2.0] (w still is: [1.0, 2.0] later, v is: None <-- becomes None! What the hey? py> python -V Python 2.5.1 -- Any explanation from a guru? Thanks much... -- http://mail.python.org/mailman/listinfo/python-list
Re: Short, crazy example: list-derived class, with __iadd__ <- nevermind, me == idiot
__iadd__ is supposed to /return/ something, most likely self. My bad. On Wed, 29 Aug 2007 20:49:59 +, Moon wrote: > class Vec(list): > def __init__(self): > list.__init__(self, [0.0, 0.0]) > > def __iadd__(self, other): > assert isinstance(other, Vec) > self[0] += other[0] > self[1] += other[1] > print "right now, v is: ", self, " as you'd expect" > > > v = Vec() > w = Vec() > w[0] = 1.0 > w[1] = 2.0 > print "v starts:", v > > print "(w is:", w, " which is fine)" > > v += w > > print "(w still is:", w > > print "after iadd, v: ", v, " <-- becomes None! What the hey?" > > > # - running it: > > py> python badvec.py > v starts: [0.0, 0.0] > (w is: [1.0, 2.0] which is fine) > right now, v is: [1.0, 2.0] > (w still is: [1.0, 2.0] > later, v is: None <-- becomes None! What the hey? > > py> python -V > Python 2.5.1 > > -- Any explanation from a guru? > > Thanks much... -- http://mail.python.org/mailman/listinfo/python-list
Hello
Hello I have problem with python installation.I downloaded python 3.5 but I cannot use it on my computer.I can not open the idle. I get something like saying "users\local settings\Application data\programs\python\python35-32\pythonw.exe is not valid win32 application. Thanks that will be help if you can solve this. -- https://mail.python.org/mailman/listinfo/python-list
python for net manager
hi there, i just want to write a small tool to manage the network, including detect the ip addr,netmask, and send the arp request to find out locale's ip-mac turtple, is there any way to succeed this exlude 'subprocess call'? thanks -- http://mail.python.org/mailman/listinfo/python-list
why does Py_Finalize() always crashes?
I used Python as embeded in C++ program, which is made up of a EXE and a DLL. Py_Initialize() and Py_Finalize() are put in DllMain(). But everytime after the program starts, an "Access Violation" will be thrown. I looked up the Assembly code, the crash appears after Py_Finalize() returns: }else if(dwReason == DLL_PROCESS_DETACH){1000B4B9 test eax,eax 1000B4BB jne DllMain+23h (1000B4C3h) Py_Finalize();1000B4BD call dword ptr [__imp__Py_Finalize (1000E1A0h)] } return true;1000B4C3 mov al,1 <-- 0xC005 thrown by here}1000B4C5 ret 0Ch What may be the probable reason that caused this error? Thank you:) -- http://mail.python.org/mailman/listinfo/python-list