From 030d8875a1714ed683ef3b369742edc619e1c3ad Mon Sep 17 00:00:00 2001 From: rakesh Date: Mon, 8 Jul 2019 08:56:25 +0530 Subject: [PATCH] File reading and Writing --- Testing.txt | 2 ++ fileHandling/Create_Text_File.py | 10 ++++++++++ fileHandling/Find_lines_start_with_T.py | 11 +++++++++++ fileHandling/Total_word_count.py | 12 ++++++++++++ fileHandling/file_read.py | 2 +- fileHandling/file_read_linewise.py | 11 +++++++++++ 6 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 Testing.txt create mode 100644 fileHandling/Create_Text_File.py create mode 100644 fileHandling/Find_lines_start_with_T.py create mode 100644 fileHandling/Total_word_count.py create mode 100644 fileHandling/file_read_linewise.py diff --git a/Testing.txt b/Testing.txt new file mode 100644 index 0000000..b9acd9c --- /dev/null +++ b/Testing.txt @@ -0,0 +1,2 @@ +This is rakesh and this is my first file handling program in Python +This is second line and i am learning new things in pythinthird line of the same program \ No newline at end of file diff --git a/fileHandling/Create_Text_File.py b/fileHandling/Create_Text_File.py new file mode 100644 index 0000000..6fb5111 --- /dev/null +++ b/fileHandling/Create_Text_File.py @@ -0,0 +1,10 @@ +#program to create Text File using Python +# made by : rakesh kumar +# Last Compiled on : 7/7/2018 + +file = open("Testing.txt","w") +file.write("This is rakesh and this is my first file handling program in Python \n") +file.write("This is second line and i am learning new things in pythin") +file.writelines("third line of the same program") +file.close() +print("File Generated please check") \ No newline at end of file diff --git a/fileHandling/Find_lines_start_with_T.py b/fileHandling/Find_lines_start_with_T.py new file mode 100644 index 0000000..2bf0da7 --- /dev/null +++ b/fileHandling/Find_lines_start_with_T.py @@ -0,0 +1,11 @@ +#program to find out total number of "Project" word in any given test file +#made by : rakesh kumar +# made on : 07/07/2018 + +file = open(r"abcd.txt",'r') +count=0; +for line in file.readlines(): + if line[0]=='T': + count+=1 +file.close() +print("Total lines that start with alphabet 'T' :",count) \ No newline at end of file diff --git a/fileHandling/Total_word_count.py b/fileHandling/Total_word_count.py new file mode 100644 index 0000000..accd996 --- /dev/null +++ b/fileHandling/Total_word_count.py @@ -0,0 +1,12 @@ +#program to find out total number of "Project" word in any given test file +#made by : rakesh kumar +# made on : 07/07/2018 + +file = open(r"abcd.txt",'r') +words=lines=0 +for line in file.readlines(): + lines+=1 + words+=len(line.split()) +file.close() +print("Total Words in this File :",words) +print("Total Lines in this File :",lines) diff --git a/fileHandling/file_read.py b/fileHandling/file_read.py index 6ac8ac4..5aada0a 100644 --- a/fileHandling/file_read.py +++ b/fileHandling/file_read.py @@ -1,4 +1,4 @@ -file = open(r"C:\Users\acer\Desktop\PythonBox\pythonPrograms\fileHandling\abcd.txt",'r') +file = open(r"abcd.txt",'r') data1 = file.read() print(data1) file.close() \ No newline at end of file diff --git a/fileHandling/file_read_linewise.py b/fileHandling/file_read_linewise.py new file mode 100644 index 0000000..28db2df --- /dev/null +++ b/fileHandling/file_read_linewise.py @@ -0,0 +1,11 @@ +#program to find out total number of "Project" word in any given test file +#made by : rakesh kumar +# made on : 07/07/2018 + +file = open(r"abcd.txt",'r') +count=0; +for line in file.readlines(): + if "Project" in line.split(): + count+=1 +file.close() +print("Total 'Project' term available :",count) \ No newline at end of file