peter peter -4 years ago 157
Python Question

read whole file at once

I need to read whole source data from file (not uncompress it)

I tried

f = open('')
s =
return s

but it returns only few bytes and not whole source data. Any idea how to achieve it? Thanks

Answer Source

Use binary mode(b) when you're dealing with binary file.

def read_zipfile(path):
    with open(path, 'rb') as f:

BTW, use with statement instead of manual close.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download