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

Mike Brown mike at skew.org
Mon Dec 16 21:50:44 EST 2002


"Benjamin" <phncontact.libero.it@> wrote:>
> 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?

Look for the token "list" in your code.
I think you will see why you get an empty list, at least :)

Try this:

file_location = raw_input("file path > ")
input = open(file_location, "rb")
s = input.read()
input.close()
l = list(s)






More information about the Python-list mailing list