ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 02 Aug 2024 17:08:59 +0200The sum function doesn't work in my Jupyter notebook. I get the following error message. Any help appreciated.https://ask.sagemath.org/question/78542/the-sum-function-doesnt-work-in-my-jupyter-notebook-i-get-the-following-error-message-any-help-appreciated/ Traceback (most recent call last)
Cell In[106], line 2
1 number=Integer(20240801)
----> 2 print(sum(number.digits()))
TypeError: 'sage.rings.rational.Rational' object is not callableThu, 01 Aug 2024 06:43:08 +0200https://ask.sagemath.org/question/78542/the-sum-function-doesnt-work-in-my-jupyter-notebook-i-get-the-following-error-message-any-help-appreciated/Comment by Emmanuel Charpentier for <p>Traceback (most recent call last)
Cell In[106], line 2
1 number=Integer(20240801)
----> 2 print(sum(number.digits()))</p>
<p>TypeError: 'sage.rings.rational.Rational' object is not callable</p>
https://ask.sagemath.org/question/78542/the-sum-function-doesnt-work-in-my-jupyter-notebook-i-get-the-following-error-message-any-help-appreciated/?comment=78544#post-id-78544WorksForMe(TM) in 10.5.beta0 :
sage: number=Integer(20240801)
sage: sum(number.digits())
17
What happen(s|ned) in the 105 previous cells ?
HTH,Thu, 01 Aug 2024 11:09:43 +0200https://ask.sagemath.org/question/78542/the-sum-function-doesnt-work-in-my-jupyter-notebook-i-get-the-following-error-message-any-help-appreciated/?comment=78544#post-id-78544Comment by tolga for <p>Traceback (most recent call last)
Cell In[106], line 2
1 number=Integer(20240801)
----> 2 print(sum(number.digits()))</p>
<p>TypeError: 'sage.rings.rational.Rational' object is not callable</p>
https://ask.sagemath.org/question/78542/the-sum-function-doesnt-work-in-my-jupyter-notebook-i-get-the-following-error-message-any-help-appreciated/?comment=78543#post-id-78543Does the error persist when you run only the following code in a new Jupyter session? (with no other prior code parts, just the following two lines.)
number=Integer(20240801)
print(sum(number.digits()))Thu, 01 Aug 2024 07:43:16 +0200https://ask.sagemath.org/question/78542/the-sum-function-doesnt-work-in-my-jupyter-notebook-i-get-the-following-error-message-any-help-appreciated/?comment=78543#post-id-78543Answer by Max Alekseyev for <p>Traceback (most recent call last)
Cell In[106], line 2
1 number=Integer(20240801)
----> 2 print(sum(number.digits()))</p>
<p>TypeError: 'sage.rings.rational.Rational' object is not callable</p>
https://ask.sagemath.org/question/78542/the-sum-function-doesnt-work-in-my-jupyter-notebook-i-get-the-following-error-message-any-help-appreciated/?answer=78548#post-id-78548You may have introduced variable `sum` with a rational value somewhere earlier in your code. If that is the case, calling `sum()` will raise an error like the one you observe.Thu, 01 Aug 2024 16:09:20 +0200https://ask.sagemath.org/question/78542/the-sum-function-doesnt-work-in-my-jupyter-notebook-i-get-the-following-error-message-any-help-appreciated/?answer=78548#post-id-78548Comment by Max Alekseyev for <p>You may have introduced variable <code>sum</code> with a rational value somewhere earlier in your code. If that is the case, calling <code>sum()</code> will raise an error like the one you observe.</p>
https://ask.sagemath.org/question/78542/the-sum-function-doesnt-work-in-my-jupyter-notebook-i-get-the-following-error-message-any-help-appreciated/?comment=78573#post-id-78573@voodooguru: a better solution is to not overwrite the value of `sum` and use another name for the variable.Fri, 02 Aug 2024 17:08:59 +0200https://ask.sagemath.org/question/78542/the-sum-function-doesnt-work-in-my-jupyter-notebook-i-get-the-following-error-message-any-help-appreciated/?comment=78573#post-id-78573Comment by voodooguru for <p>You may have introduced variable <code>sum</code> with a rational value somewhere earlier in your code. If that is the case, calling <code>sum()</code> will raise an error like the one you observe.</p>
https://ask.sagemath.org/question/78542/the-sum-function-doesnt-work-in-my-jupyter-notebook-i-get-the-following-error-message-any-help-appreciated/?comment=78572#post-id-78572Yes, importing the symbolic_sum as sum did the job. Thank you rburing and Max Alekseyev for helping me out. Much appreciated.Fri, 02 Aug 2024 16:57:34 +0200https://ask.sagemath.org/question/78542/the-sum-function-doesnt-work-in-my-jupyter-notebook-i-get-the-following-error-message-any-help-appreciated/?comment=78572#post-id-78572Comment by rburing for <p>You may have introduced variable <code>sum</code> with a rational value somewhere earlier in your code. If that is the case, calling <code>sum()</code> will raise an error like the one you observe.</p>
https://ask.sagemath.org/question/78542/the-sum-function-doesnt-work-in-my-jupyter-notebook-i-get-the-following-error-message-any-help-appreciated/?comment=78568#post-id-78568The default value is `symbolic_sum`, which has a fallback to Python's `sum` when few arguments are given. See e.g. the output of `sum??` in a SageMath session.Fri, 02 Aug 2024 15:49:55 +0200https://ask.sagemath.org/question/78542/the-sum-function-doesnt-work-in-my-jupyter-notebook-i-get-the-following-error-message-any-help-appreciated/?comment=78568#post-id-78568Comment by Max Alekseyev for <p>You may have introduced variable <code>sum</code> with a rational value somewhere earlier in your code. If that is the case, calling <code>sum()</code> will raise an error like the one you observe.</p>
https://ask.sagemath.org/question/78542/the-sum-function-doesnt-work-in-my-jupyter-notebook-i-get-the-following-error-message-any-help-appreciated/?comment=78565#post-id-78565@rburing: I believe the default value of `sum` is the Python's one, not Sage's `symbolic_sum`.Fri, 02 Aug 2024 14:07:58 +0200https://ask.sagemath.org/question/78542/the-sum-function-doesnt-work-in-my-jupyter-notebook-i-get-the-following-error-message-any-help-appreciated/?comment=78565#post-id-78565Comment by rburing for <p>You may have introduced variable <code>sum</code> with a rational value somewhere earlier in your code. If that is the case, calling <code>sum()</code> will raise an error like the one you observe.</p>
https://ask.sagemath.org/question/78542/the-sum-function-doesnt-work-in-my-jupyter-notebook-i-get-the-following-error-message-any-help-appreciated/?comment=78560#post-id-78560Indeed, one should avoid using names of builtin functions for variables, to avoid losing access to the functions. To get the function back one can do `from sage.misc.functional import symbolic_sum as sum`Fri, 02 Aug 2024 12:06:49 +0200https://ask.sagemath.org/question/78542/the-sum-function-doesnt-work-in-my-jupyter-notebook-i-get-the-following-error-message-any-help-appreciated/?comment=78560#post-id-78560