datetime.timedelta(x,y)在CoCalc.com上返回TypeError,但在其他地方有效-为什么?

时间:2019-02-07 03:06:46

标签: python jupyter-notebook sage

我的代码在onlinegdb.com上有效,但在CoCalc.com上无效。

2019-02-07 11:28:22 [scrapy.core.engine] INFO: Spider opened
2019-02-07 11:28:23 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2019-02-07 11:28:24 [scrapy.core.engine] DEBUG: Crawled (200) 
<GET https://www.tayara.tn/listings/bureaux-et-plateaux-140/b54871b9-cad3 4113-97ce-a2eac095146f/chambre-d'enfant> (referer: None)
{'Source': 'Tayara', 'Reference': 'b54871b9-cad3-4113-97ce-a2eac095146f', 
'Titre': ["chambre d'enfant"], 'Gouvernorat': 'Nabeul', 'Delegation': 'El Haouaria'}
2019-02-07 11:28:24 [scrapy.core.engine] INFO: Closing spider (finished)
2019-02-07 11:28:24 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 298,
 'downloader/request_count': 1,
 'downloader/request_method_count/GET': 1,
 'downloader/response_bytes': 33258,
 'downloader/response_count': 1,
 'downloader/response_status_count/200': 1,
 'finish_reason': 'finished',
 'finish_time': datetime.datetime(2019, 2, 7, 2, 28, 24, 680904),
 'log_count/DEBUG': 1,
 'log_count/INFO': 7,
 'response_received_count': 1,
 'scheduler/dequeued': 1,
 'scheduler/dequeued/memory': 1,
 'scheduler/enqueued': 1,
 'scheduler/enqueued/memory': 1,
 'start_time': datetime.datetime(2019, 2, 7, 2, 28, 23, 33853)}
2019-02-07 11:28:24 [scrapy.core.engine] INFO: Spider closed (finished)

返回

url

我不清楚这是功能还是错误。

3 个答案:

答案 0 :(得分:2)

如果其他人有这样的问题-事实证明我使用的是Sage数学内核,而不是Python数学内核。该网站提供了15种不同的内核。

答案 1 :(得分:2)

雅各布的自我回答是正确的;这里有更多细节。

在SageMath中,有一个称为preparser的东西可以解释事物,以便整数是数学整数,而不是Python整数。所以for example

sage: preparse('1+1')
'Integer(1)+Integer(1)'

还有很多涉及-尝试preparse('f(x)=x^2')来获得真正的乐趣。但是,是的,这是一个功能。

不过,要解决Sage内核中的问题,您可以执行this

import datetime
slowduration = datetime.timedelta(int(0),int(1))
print(slowduration)

得到0:00:01作为答案。

答案 2 :(得分:2)

为补充@kcrisman的答案和“ int(0), int(1)”技巧...

如果要坚持使用Sage内核,还有两个选择

  • (1)使用preparser(False)禁用准备器,
  • (2)将r(用于“原始”)附加到整数,例如datetime.timedelta(0r, 1r)

另请参阅有关Sage的浮点数和整数准备的类似问题和答案:

最后,请注意,可以使用以下任一方法将代码从外部文件加载到Sage中:

  • load('/path/to/filename.py')
  • load('/path/to/filename.sage')

其中.sage个文件将获得“ Sage-prepared”,而.py个文件将无法获得。

这提供了绕过预准备器的第三个选项:从.py文件加载代码。