Woli123 Woli123 - 1 year ago 139
Python Question

Extracting data from a text file as a list in python 3.4.3

I have tried reaching but i'm unable to find the correct syntax for what I need to do.
For the task i'm attempting to complete i'm required to store multiple lists in a text file the access them in the python program and giving them a variable name. The multiple lines in the text document all have different amounts of items and i need each line to be made into its own list.
I'm not sure how to do this and would greatly appreciate if you could help me.

Answer Source
fileContent = []
with open('filename.txt') as f:
    for line in f:

The code would read the lines from a file and form a list of lines wherein each line is list of words.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download