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.Wed, 15 Dec 2021 09:40:10 +0100import txt file contents to SageMath/Pythonhttps://ask.sagemath.org/question/60268/import-txt-file-contents-to-sagemathpython/I have a text file with contents like the following
[[1, 4], [2, 6], [5, 7]]
[[1, 4], [2, 7], [5, 8]]
I would like to import the contents to SageMath/Python, and assign L=[[[1, 4], [2, 6], [5, 7]], [[1, 4], [2, 7], [5, 8]]].
I tried to use the following
with open('somefile.txt', 'r') as fp:
L = [RDF(l.strip()) for l in fp.readlines()]
But there is some error: could not convert string to float: '[[1, 4], [2, 6], [5, 7]]'
How could I solve this problem? How to convert the values to integer (not float)? Thank you very much.lijr07Wed, 15 Dec 2021 09:40:10 +0100https://ask.sagemath.org/question/60268/