In [ ]:
def filecopy(f1,f2):
fp=open(f1,'r')
fp1=open(f2,'w')
l=fp.readline()
while l!='':
fp1.write(l)
l=fp.readline()
fp.close()
fp1.close()
In [2]:
import os
print(os.getcwd())
In [7]:
filecopy('corona.txt.txt','covid.txt')
In [8]:
def filecpy(f1,f2):
fp=open(f1,'r')
fp1=open(f2,'w')
l=fp.read()
fp1.write(l)
fp.close()
fp1.close()
In [9]:
filecpy('covid.txt','covid19.txt')
In [5]:
def fileread(f):
fl=open(f)
print(fl.read())
In [11]:
fileread('covid19.txt')
In [13]:
fileread('corona.txt.txt')
In [14]:
fileread('covid19.txt')
In [15]:
def filereadlines(f):
fl=open(f)
print(fl.readlines())
In [16]:
filereadlines('covid19.txt')
In [1]:
def filereadline(f):
fl=open(f)
l=fl.readline()
while l!='':
print(l)
l=fl.readline()
fl.close()
In [2]:
filereadline('covid19.txt')
In [3]:
def countline(f):
py=0
fl=open(f)
l=fl.readline()
while l!='':
print(l)
py+=1
l=fl.readline()
print('number of lines in file is ',py)
fl.close()
In [4]:
countline('covid.txt')
In [2]:
s = 'testing 1 2 testing'
d = {}
for word in s.split():
word = int(word) if word.isdigit() else word
if word in d:
d[word] += 1
else:
d[word] = 1
print(d)
In [3]:
print(s.split())
In [6]:
"sd sd fdgf dfgdfg".split()
Out[6]:
In [15]:
def readtextbin(fil):
f=open(fil,'rb')
import pickle
data=pickle.load(f)
print(data)
f.close()
In [16]:
readtextbin('covid.txt')
In [8]:
fobj_in = open("covid19.txt")
fobj_out = open("covid2019.txt","w")
i = 1
for line in fobj_in:
print(line.rstrip())
fobj_out.write(str(i) + ": " + line)
i = i + 1
fobj_in.close()
fobj_out.close()
In [6]:
fileread('covid2019.txt')
In [15]:
def filecountword(fl):
fc=open(fl)
count=0
for line in fc:
print(line.split())
print(len(line.split()))
count+=len(line.split())
print('number of word in file is',count)
fc.close()
In [16]:
filecountword('covid2019.txt')
In [ ]:
def filecountword(fl):
fc=open(fl)
count=0
fc.filecount
print('number of word in file is',count)
fc.close()
No comments:
Post a Comment