Skip to content

Commit

Permalink
bianry file handling
Browse files Browse the repository at this point in the history
  • Loading branch information
linrakesh committed Nov 27, 2019
1 parent 6f87185 commit 07e9009
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 27 deletions.
11 changes: 6 additions & 5 deletions Automation/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"""
4 changes: 0 additions & 4 deletions database/select_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions fileHandling/Create_binary_file.py
Original file line number Diff line number Diff line change
@@ -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()
file = open("student.dat", "wb")
pickle.dump(list, file)
file.close()
13 changes: 8 additions & 5 deletions fileHandling/fileCompress.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#-------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
# Name: compress file
# Purpose: compress any file so that we can save a lots of bits and byte
#
Expand All @@ -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()
6 changes: 6 additions & 0 deletions fileHandling/oswalk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os
import glob

for root, folders, files in os.walk(os.getcwd()):
files = glob.glob(files + '/*.py')
print(files)
1 change: 0 additions & 1 deletion fileHandling/random_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions fileHandling/read_binary_file.py
Original file line number Diff line number Diff line change
@@ -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()
file.close()
6 changes: 6 additions & 0 deletions fileHandling/removeExtraSpaceNewline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import re

file = open("abcd.txt")
data = file.read()
data = re.sub('[ \t\n]+', ' ', data)
print(data)
17 changes: 17 additions & 0 deletions fileHandling/search_in_binary_file.py
Original file line number Diff line number Diff line change
@@ -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")
Binary file modified student.dat
Binary file not shown.

0 comments on commit 07e9009

Please sign in to comment.