-1

I am trying to create a python list from text file and this is my try

my_file = open("Sample.txt", "r")
content_list = my_file.readlines().replace('\n','')
print(content_list)

Solved

mylist = open('Sample.txt', 'r').read().splitlines()
print(mylist)
YasserKhalil
  • 9,138
  • 7
  • 36
  • 95

1 Answers1

0

You can strip method.

If strip doesn't work then follow below approach

Use str.splitlines() to split your document into lines without newlines; you can rejoin it if you want to:

doclines = doc.splitlines() doc_rejoined = ''.join(doclines)

Prasad
  • 1,089
  • 13
  • 21