Very reversed question here, I need to take a .txt file and add it to a list.
The output file:
abc123
What the list should be:
list = ["abc123"]
Very reversed question here, I need to take a .txt file and add it to a list.
The output file:
abc123
What the list should be:
list = ["abc123"]
You can use:
with open("","r") as f:
data=f.readlines()
#Or same:
f=open("","r")
data=f.readlines()
f.close()
data
is in list, it read each line. And put each line in list.
Do you mean add the content to a list? If so, you may use:
with open("filename") as f:
content = f.read()
yourlist.append(content)
# Do something here...
If you want to add the file object to a list, you may use:
with open("filename") as f:
yourlist.append(f)
# Do something here...