Hi to everyone :), i have a challenge right now in python that for now needs a bit of help in one part of the c0de.
The task is create a new file with the name of the file defined by the ASCII content between the 3 byte and the 16 byte that is parsed from the binary file, the file is over 20 Mb i need to create a file for each record ( each record contains the len of 820 ), so right now i know how to read it and do something with it, like :
Now the problem is , how do i get the name file that i want that is the string between the 2 byte and the 16 byte and how to save every 820 bytes to a new file like :
---------- Post updated 30-11-12 at 10:26 AM ---------- Previous update was 29-11-12 at 10:42 AM ----------
here is the solution :
The task is create a new file with the name of the file defined by the ASCII content between the 3 byte and the 16 byte that is parsed from the binary file, the file is over 20 Mb i need to create a file for each record ( each record contains the len of 820 ), so right now i know how to read it and do something with it, like :
Code:
Code:
#!/usr/bin/python
with open("file", "rb") as f:
byte = f.read()
if byte > 820:
print "Reach the 1 record mark on the File you have defined "
Code:
#attention noob code coming for quick understading i have a for loop for #example not for use i have to use it for the each 820 bytes new file
#with the read of the 820 bytes on the new file and save it and go for the
#next 820 bytes and so on until the end of the file.
for f.read(820) in file:
if f.read() = 820:
a = f.read()
b = open("Iam_from_2_to_16_byte_string", w)
b.write(a)
b.close
here is the solution :
Code:
n = 820
with open('/home/drdos/work/file.PDA', "rb") as f:
while True:
data = f.read(n)
if not data:
break
filename = str(data[16:32])
x = open(filename, 'wb').write(data)