From 07e900967cebe964df8221fbef82a55e996eb2de Mon Sep 17 00:00:00 2001 From: rakesh Date: Wed, 27 Nov 2019 20:39:58 +0530 Subject: [PATCH] bianry file handling --- Automation/move.py | 11 ++++++----- database/select_command.py | 4 ---- fileHandling/Create_binary_file.py | 18 +++++++++--------- fileHandling/fileCompress.py | 13 ++++++++----- fileHandling/oswalk.py | 6 ++++++ fileHandling/random_word.py | 1 - fileHandling/read_binary_file.py | 7 ++++--- fileHandling/removeExtraSpaceNewline.py | 6 ++++++ fileHandling/search_in_binary_file.py | 17 +++++++++++++++++ student.dat | Bin 89 -> 114 bytes 10 files changed, 56 insertions(+), 27 deletions(-) create mode 100644 fileHandling/oswalk.py create mode 100644 fileHandling/removeExtraSpaceNewline.py create mode 100644 fileHandling/search_in_binary_file.py diff --git a/Automation/move.py b/Automation/move.py index e708805..2845c92 100644 --- a/Automation/move.py +++ b/Automation/move.py @@ -7,11 +7,12 @@ dest_dir = "C:/test" files = glob.glob(source+"/*.txt") +for file in files: + print(file) + shutil.move(file, dest_dir) -# for file in files: -# print(file) -# shutil.copy(file, dest_dir) -# os.unlink(file) -while True: + +""" while True: print("Hello rakesh") time.sleep(5) + """ diff --git a/database/select_command.py b/database/select_command.py index c362053..027c037 100644 --- a/database/select_command.py +++ b/database/select_command.py @@ -20,10 +20,6 @@ t = PrettyTable(['ID', 'Question', 'A', 'B', 'C', 'D', 'Ans', 'Exp', 'gid', 'sid', 'tid']) for idr, question, a, b, c, d, ans, exp, gid, sid, tid in results: - #idr = record[0] - #name = record[1] - #fname = record[2] - #add = record[3] t.add_row([idr, question, a, b, c, d, ans, exp, gid, sid, tid]) # print(idr,name,fname,add,phone,email) print(t) diff --git a/fileHandling/Create_binary_file.py b/fileHandling/Create_binary_file.py index a9264b4..3b23355 100644 --- a/fileHandling/Create_binary_file.py +++ b/fileHandling/Create_binary_file.py @@ -1,18 +1,18 @@ # program to create a binary file of records - Just like structure # made by : rakesh kumar -# Compiled on : 8-July-2018 +# Compiled on : 27-Nov-2019 import pickle -list =[] +list = [] while True: roll = input("Enter student Roll No:") - sname = input("Enter student Name :") - student = {"roll":roll,"name":sname} + sname = input("Enter student Name :") + student = {"roll": roll, "name": sname} list.append(student) - choice= input("Want to add more record(y/n) :") - if(choice=='n'): + choice = input("Want to add more record(y/n) :") + if(choice == 'n'): break -file = open("student.dat","wb") -pickle.dump(list,file) -file.close() \ No newline at end of file +file = open("student.dat", "wb") +pickle.dump(list, file) +file.close() diff --git a/fileHandling/fileCompress.py b/fileHandling/fileCompress.py index b43d3d2..03e9e94 100644 --- a/fileHandling/fileCompress.py +++ b/fileHandling/fileCompress.py @@ -1,4 +1,4 @@ -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- # Name: compress file # Purpose: compress any file so that we can save a lots of bits and byte # @@ -7,12 +7,15 @@ # Created: 18-04-2017 # Copyright: rakesh kumar # Licence: MIT-2.0 -#------------------------------------------------------------------------------- +# ------------------------------------------------------------------------------- import re + def compress(): - string = re.sub('[ \t\n]+',' ','The quick brown \n\n \t fox') - print(string) - + string = re.sub( + '[ \t\n]+', ' ', 'The quick brown \n\n \t fox \n\n\n This is me rakesh \n\n\n also love to code in python') + print(string) + + if __name__ == '__main__': compress() diff --git a/fileHandling/oswalk.py b/fileHandling/oswalk.py new file mode 100644 index 0000000..025d2b6 --- /dev/null +++ b/fileHandling/oswalk.py @@ -0,0 +1,6 @@ +import os +import glob + +for root, folders, files in os.walk(os.getcwd()): + files = glob.glob(files + '/*.py') + print(files) diff --git a/fileHandling/random_word.py b/fileHandling/random_word.py index 62b1315..a915d7d 100644 --- a/fileHandling/random_word.py +++ b/fileHandling/random_word.py @@ -3,7 +3,6 @@ # program by : rakesh kumar # website : https://cbsetoday.com - import random as r with open("sowpods.txt") as file: data = file.read().split() diff --git a/fileHandling/read_binary_file.py b/fileHandling/read_binary_file.py index 17df838..4faf422 100644 --- a/fileHandling/read_binary_file.py +++ b/fileHandling/read_binary_file.py @@ -1,9 +1,10 @@ -#program to read a binary file of records - Just like structure +# program to read a binary file of records - Just like structure # made by : rakesh kumar # Compiled on : 8-July-2018 import pickle -file = open("student.dat","rb") + +file = open("student.dat", "rb") list = pickle.load(file) print(list) -file.close() \ No newline at end of file +file.close() diff --git a/fileHandling/removeExtraSpaceNewline.py b/fileHandling/removeExtraSpaceNewline.py new file mode 100644 index 0000000..d8bcdb9 --- /dev/null +++ b/fileHandling/removeExtraSpaceNewline.py @@ -0,0 +1,6 @@ +import re + +file = open("abcd.txt") +data = file.read() +data = re.sub('[ \t\n]+', ' ', data) +print(data) diff --git a/fileHandling/search_in_binary_file.py b/fileHandling/search_in_binary_file.py new file mode 100644 index 0000000..7bc1173 --- /dev/null +++ b/fileHandling/search_in_binary_file.py @@ -0,0 +1,17 @@ +# program to read a binary file of records - Just like structure +# made by : rakesh kumar +# Compiled on : 8-July-2018 + +import pickle + +name = input('Enter name that you want to search in binary file :') + +file = open("student.dat", "rb") +list = pickle.load(file) +file.close() + +found = 0 +for x in list: + if name in x['name']: + found = 1 +print("Found in binary file" if found == 1 else "Not found") diff --git a/student.dat b/student.dat index 6ccc16c04b2199feea20e98d8d48dd829cc85792..36a5f17d276c8963fefa60ea84ab29b683b81f07 100644 GIT binary patch delta 48 zcmaznn&7U@#=yXkm{(eqm|n^04m4} A(f|Me delta 23 ecmXSloZv3R$-ux+oS0jbnUa!`S;$eEss{j1KnC;x