Go Back   CodingForums.com > :: Server side development > Other server side languages/ issues > Python

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-27-2012, 10:58 AM   PM User | #1
KevinJohnson
Regular Coder

 
Join Date: May 2009
Location: China
Posts: 133
Thanks: 1
Thanked 1 Time in 1 Post
KevinJohnson has a little shameless behaviour in the past
Can't load binary file into Array...

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:

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)
KevinJohnson is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:56 PM.


Advertisement
Log in to turn off these ads.