2024-09-29 23:17:02 发布
网友
我的代码可以在onlinegdb.com上运行,但不能在CoCalc.com上运行
import datetime slowduration = datetime.timedelta(0,1) print(slowduration)
退货
TypeError: unsupported type for timedelta seconds component: sage.rings.integer.Integer
我不清楚这是一个特性还是一个bug
雅各布的自我回答是正确的;这里有更多的细节
在SageMath中有一种称为preparser的东西,它解释事物,使整数是数学整数,而不是Python整数。所以for example:
sage: preparse('1+1') 'Integer(1)+Integer(1)'
还有更多的事情要做-试试preparse('f(x)=x^2')找些真正的乐趣。但是是的,这是一个特点
preparse('f(x)=x^2')
不过,要解决Sage内核中的问题,可以执行this:
import datetime slowduration = datetime.timedelta(int(0),int(1)) print(slowduration)
得到0:00:01作为你的答案
0:00:01
为了补充@kcrisman的答案和“int(0), int(1)”技巧
int(0), int(1)
如果想要坚持Sage内核,还有两个选择
preparser(False)
r
datetime.timedelta(0r, 1r)
另请参见围绕Sage准备浮点和整数的类似问题和答案:
最后,请注意,可以使用以下任一方法从外部文件将代码加载到Sage中:
load('/path/to/filename.py')
load('/path/to/filename.sage')
其中.sage文件将获得“Sage preparsed”,而.py文件将不会
.sage
.py
这提供了第三个绕过preparser的选项:从.py文件加载代码
如果其他人有这样的问题-结果是我使用的是Sage数学内核,而不是Python数学内核。这个网站提供15种不同的果仁
雅各布的自我回答是正确的;这里有更多的细节
在SageMath中有一种称为preparser的东西,它解释事物,使整数是数学整数,而不是Python整数。所以for example:
还有更多的事情要做-试试
preparse('f(x)=x^2')
找些真正的乐趣。但是是的,这是一个特点不过,要解决Sage内核中的问题,可以执行this:
得到
0:00:01
作为你的答案为了补充@kcrisman的答案和“
int(0), int(1)
”技巧如果想要坚持Sage内核,还有两个选择
preparser(False)
禁用preparserr
(表示“raw”),例如datetime.timedelta(0r, 1r)
李>另请参见围绕Sage准备浮点和整数的类似问题和答案:
最后,请注意,可以使用以下任一方法从外部文件将代码加载到Sage中:
load('/path/to/filename.py')
load('/path/to/filename.sage')
其中
.sage
文件将获得“Sage preparsed”,而.py
文件将不会这提供了第三个绕过preparser的选项:从
.py
文件加载代码如果其他人有这样的问题-结果是我使用的是Sage数学内核,而不是Python数学内核。这个网站提供15种不同的果仁
相关问题 更多 >
编程相关推荐