0
votes

my input file content is

12sljg1', 'kf
[]
             ffdasfsdfdsf
Process finished with exit code 0

I am reading these lines into a list and print them with code:

lines = [line.splitlines() for line in open(r'C:\Users\BerkayS\Desktop\testfile.txt', 'r')]

print(lines[0:2])

Output is:

[["12sljg1', 'kf"], ['[]']]

Why it is putting quotation mark (") to start and end of the member at first position which is

12sljg1', 'kf

?

2
Because it is a string. - user5547025
What output do you expect? - user5547025
Because the first string already has a single quote in it, so it can't use the single quote to denote it as a string without escaping them. - James Jenkinson
Thanks James thats exactly what i want to learn. @LutzHorn [] is not a string too ? - abidinberkay

2 Answers

1
votes

Your print statement is using default formating for this type of structure. Your structure is List So python will indicate this by adding [] to representation Additionaly to show members of list and indicate its type again its add "" to show You its string

You must use some formating to ommit this.

0
votes

That's how the Python output represents strings