Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Importing array list in text file into Python

I have an array list in a txt file like:

[1, 2, 3, 4, 5]

I would like to get this data into an array in my python code. Afterall, when I print it in Python I should see below output:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[1, 2, 3, 4, 5]

(Exactly same with content in txt.)

Is that possible? If yes, how?

>Solution :

To read the data from your txt file and store it as a list in Python, you can use the following code:


with open('path/to/your/file.txt', 'r') as file: data = file.read()
myList = data.split()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading