Python read text file into string

Simplest way:

file = open('data.txt', 'r')text = file.read().strip()file.close()

METHOD 2: 

with open('data.txt', 'r') as myfile:    data=myfile.read().replace('n', '')

METHOD 3:

with open("data.txt") as myfile:    data="".join(line.rstrip() for line in myfile)

join() will join a list of strings, and rstrip() with no arguments will trim whitespace, including newlines, from the end of strings.