[IPython-User] running sum(datetime.timedelta) gives an error! but not always
Moritz Emanuel Beber
Thu Jun 27 06:22:16 CDT 2013
On 06/24/2013 07:09 PM, BrunoV wrote:
> Hello, I'm new to this list and a beginner in python.
> I'm trying to use datetime module.
> to do it simple here is the part of the code I'm using:
> import datetime as dtm
> toto = [[dtm.timedelta(0, 25200), dtm.timedelta(0, 3600)]]
> print sum(toto)
I don't immediately get why you want a list of lists [[...]] rather than
a list [...] here. That is probably part of the TypeError.
> If I start ipython with this line:
> ipython -pylab -wthread and then copy paste these lines in Ipython console
> using %cpaste
> everything it is working as expected.
My guess is the following: when you do -pylab ipython also does an from
numpy import * so that the sum function is actually numpy.sum and not
the python standard. (You can test this by simply entering sum into the
prompt, it will show the module it's from.)
> But if I run the file containing this portion of code using the %run
> the_file.py, I get the following error:
> TypeError: unsupported operand type(s) for +: 'int' and 'list'
> WARNING: Failure executing file: <try.py>
> I get the same error in Ipython console when Ipython is started without any
> So I suppose the error is linked with the use of pylab option.
> Is it normal that using %run, and using %cpaste I'm getting the same
> How can I get my script working using %run
> Thank you very much for your answers.
So try with a single list and then %run (which using the standard sum
function), that should work.
> View this message in context: http://python.6.x6.nabble.com/running-sum-datetime-timedelta-gives-an-error-but-not-always-tp5022260.html
> Sent from the IPython - User mailing list archive at Nabble.com.
> IPython-User mailing list
More information about the IPython-User