I am trying to convert a .txt file to regular Python list. I have done this before, but the previous situations have involved manually constructed files. I am currently trying to process a .txt file that was composed by another Python script that wrote a list into said .txt file. I am not sure why these formats are being perceived as different by Python
Here is what I mean:
The first .txt looked like:
(Let's call it x.txt)
I like dogs
Go home
This is the greatest Ice Cream ever
Now if I do:
f = open('x.txt', encoding = "utf8")
z = f.readlines()
print(z)
I get
['I like dogs','Go home','This is the greatest Ice Cream ever']
This is exactly what I want ^
My current .txt file looks like:
(Let's call it y.txt)
['I like dogs','Go home','This is the greatest Ice Cream ever']
Now if I do:
f = open('y.txt', encoding = "utf8")
z = f.readlines()
print(z)
I get a bizarre output that looks like:
['[\'I like dogs. \', \'Go home\', \'This is the greatest Ice Cream
ever\',]]
I thought double brackets only existed really in Pandas? Where am I going wrong here? How can I get a regular list format output.
Note: To provide some context, I am trying to feed this list into some text cleaning script. When I try to feed that second output into it, I don't get an error, but it turns the list of strings into one long string in a list like: ['IlikedogsGohomeThisisthegreatestIceCreamever']
['I like dogs','Go home','This is the greatest Ice Cream ever']inside the text file, they will be saved with string formatting and again while you doreadlines()these list-of-strings-converted-to-single-string would be inside a list.