I am reading some text from a text file that says hello my name is Matthew. But when i print it it says ['Hello my name is matthew']. Does anyone know how to trim the [' '] from the string?
Code below
File1 = open('Text.txt')
PlainText = File1.readlines()
File1.close()
print(PlainText)
PlainText = File1.read().rstrip()['Hello my name is matthew']is python's way of telling you that you have a list with a single string value. Your sring is atPlainText[0].print(PlainText[0]). Because the item is a list, so pulling out the first index in the list will get you your string.readorreadlinemethods are fine. If you want ot read multiple lines and have each line be a different string, thenreadlines orfor line in File1:` would be the way to go.