I\'m having issues in reading a file into a list, When I do it only creates one item from the entire file rather than reading each element into its own field. I\'m using
If you're okay with reading the entire file's contents into memory, you can also use str.splitlines()
with open('your_file.txt') as f:
lines = f.read().splitlines()
splitlines() is similar to split('\n') but if your file ends with a newline, split('\n') will return an empty string at the very end, whereas splitlines() handles this case the way you want.