I have problems with function Replace(): Python/ CRC32/MD5

-2

when I input 2 time, position value will be changed.enter image description here

import hashlib
import binascii
import fileinput
from sys import argv

script,file,file_checksum = argv
def Find_CRC32(file):
    flat = 0
    global position
    searchfile = open(file,'r')
    for line in searchfile:
        if "CRC32" in line:
            position = flat
        flat = flat +1
    return position

def Find_MD5(file):
    flat = 0
    global position
    searchfile = open(file,'r')
    for line in searchfile:
        if "MD5" in line:
            position = flat
        flat = flat +1
    return position

def Search(file,position):
    fo = open(file,'rw+')
    for i in range(position+1):
        line = fo.readline()
    return line

def MD5hash(filename):
    hasher = hashlib.md5()
    with open(filename,"rb") as afile:
        buf= afile.read()
        hasher.update(bufmn,)
    return hasher.hexdigest()

def CRC32(script):
    buf = (binascii.crc32(script) & 0xFFFFFFFF)
    return "%08X" % buf
def Replace(file,search,value): 
    with open(file,'r') as file:
            filedata = file.read()
    filedata = filedata.replace(search,value + "\n")
    file.close()
    with open('ReleaseNote.txt','w') as update_file:
        update_file.write(filedata)
    update_file.close()



if __name__ == '__main__':
    position = 0
    a = Find_MD5(file)
    print a
    b = Find_CRC32(file)
    print b
    c = Search(file,a)  
    d = Search(file,b)
    print c
    print d
    f1 = open(file_checksum,'r')
    f2 = f1.read()
    f3 = MD5hash(file_checksum)
    f4 = CRC32(f2)

    Replace (file,c,f3)
    Replace(file,d,f4)

At function Replace(): Before I can't use : with open(file,'w') as update_file:

Can every help source code and show many solution to my script can be work better I think my code is very length, if you can help me, fix it.

python
replace
crc32
md5sum
asked on Stack Overflow Jul 13, 2018 by Duy Trần

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0