get text from txt file python

45

get text from txt file python -

with open ("data.txt", "r") as myfile:
    data = myfile.read().splitlines()

python read text file into string -

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

python read text file -

# where f is the file alias
with open(r"path\to\file.txt", encoding='UTF8') as f:
    contents = f.read()
    print(contents)

Comments

Submit
0 Comments