how to read all bytes of a file in a list?

Mike Meyer mwm at mired.org
Mon Dec 16 15:36:50 EST 2002


Benjamin <phncontact.libero.it@> writes:

> hi
> 
> i have a file, and wrote a little program which should load every
> single byte of the file into a list.
> 
> file_location = raw_input("file path > ")
> 
> list = []
> 
> input = open(file_location,"r")
> s = input.read()
> s = str(s)
> print s
> input.close()
> 
> print list
> 
> 
> well, i just don't get it. i tried also some other versions, but none
> worked. what am i doing wrong?

Why do you think your list should contain a list of all the bytes?

Anyway, you can do it this way:

input = open(file_location, "r")
l = list(input.read())
input.close()

        <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list