KevinJohnson
02-27-2012, 10:58 AM
Here's what i'm trying to do:
1. Generate a random file
2. Read that file in by n-byte chunks
3. Store each chunk in it's own Array element
error produced:
----------------------------------------------------------------------------------------------------------
SyntaxError: can't assign to function call
----------------------------------------------------------------------------------------------------------
Bits and info:
================
- i'm on python 2.7
- OS is Linux 64 bit
================
am i using the wrong kind of data structure to store the chunks of data?
here's my code:
# Split the File int an Array
def SplitFile(filename, blocksize):
with open(filename, "rb") as f:
i = 0
byte = f.read(blocksize)
while byte:
# Put the Data Blocks into the Array Elements
FileData.append[i] = f.read(blocksize)
i = i + 1
f.close()
def RandomFile(n, filename):
filedata = ""
for i in range(n):
rnd = random.randint(0,255)
filedata = filedata + chr(rnd)
# Write the data to the disk
f = open(filename, 'w')
f.write(filedata)
f.close()
blocksize = 16000
filename = 'RndFile.rnd'
FileData = []
a = RandomFile(blocksize * 8, filename)
SplitFile(filename, blocksize)
1. Generate a random file
2. Read that file in by n-byte chunks
3. Store each chunk in it's own Array element
error produced:
----------------------------------------------------------------------------------------------------------
SyntaxError: can't assign to function call
----------------------------------------------------------------------------------------------------------
Bits and info:
================
- i'm on python 2.7
- OS is Linux 64 bit
================
am i using the wrong kind of data structure to store the chunks of data?
here's my code:
# Split the File int an Array
def SplitFile(filename, blocksize):
with open(filename, "rb") as f:
i = 0
byte = f.read(blocksize)
while byte:
# Put the Data Blocks into the Array Elements
FileData.append[i] = f.read(blocksize)
i = i + 1
f.close()
def RandomFile(n, filename):
filedata = ""
for i in range(n):
rnd = random.randint(0,255)
filedata = filedata + chr(rnd)
# Write the data to the disk
f = open(filename, 'w')
f.write(filedata)
f.close()
blocksize = 16000
filename = 'RndFile.rnd'
FileData = []
a = RandomFile(blocksize * 8, filename)
SplitFile(filename, blocksize)