with open ("data.txt", "r") as myfile:
data = myfile.read().splitlines()
# read and print all contents of a file
with open('data.txt', 'r') as f:
contents = f.read()
print(contents)
# loop through file line by line removing newlines
with open('data.txt', 'r') as f:
for line in f:
print(line.rstrip())
# read first 14 bytes of file
with open('data.txt', 'r') as f:
print(f.read(14))
print(f"The current file position is {f.tell()}")
# move to beginning of file
f.seek(0, 0)
# print 30 bytes from position
print(f.read(30))
# where f is the file alias
with open(r"path ofile.txt", encoding='UTF8') as f:
contents = f.read()
print(contents)
f=open("Diabetes.txt",'r')
f.read()
file = '/home/text/chapter001.txt'
f=open(file,'r')
data = f.read()
print('data =',data)
# credit to Stack Overflow user in the source link
# it has been assumed that each line is separated by a '
' character
with open('data.txt', 'r') as file:
data = file.read().replace('
', ' ')
# write data in a file.
file1 = open("SofthuntFile1.txt","w")
multiple_string = ["This is Mango
","This is Apple
","This is Banana
"]
#
is placed to indicate EOL (End of Line)
file1.write("Hello
")
file1.writelines(multiple_string)
file1.close() #to change file access modes
file1 = open("SofthuntFile1.txt","r+")
print("Output of Read function is ")
print(file1.read())
print()
# seek(n) takes the file handle to the nth
bite from the beginning.
file1.seek(0)
print( "Output of Readline function is ")
print(file1.readline())
print()
file1.seek(0)
# To show difference between read and readline
print("Output of Read(9) function is ")
print(file1.read(9))
print()
file1.seek(0)
print("Output of Readline(9) function is ")
print(file1.readline(9))
file1.seek(0)
# readlines function
print("Output of Readlines function is ")
print(file1.readlines())
print()
file1.close()
import pandas as pd
color_table = pd.read_table("/content/drive/My Drive/Site sharing/PSD Resources/Colors.txt")
print(color_table)