Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Turning a txt. file into a list in sagemath/python

Hi,

This seems like a very basic question but I have not been able to find a satisfying answer. I'm sorry if it's been answered before.

I have a file in my computer called say text.txt that is made up of a bunch(a lot) of numbers one on each row like so:

2.14
3.15
7.8
etc.

Questions:

  1. How can I open and read this file in sage? I am using the online notebook(https://cloud.sagemath.com/) I've been trying to use basic python commands like open("file path") and also uploading the text file as a document in the notebook but I can't seem to get it to work. I should say that my programming knowledge is limited.

  2. Once I have opened this file so I can read and write to it, what would be the best code to turn it into a list with all the number in it(i.e. L = [2.14, 3.15, 7.8,...])?

Thanks a lot!