Parse file into array

Craig Marshall craig9 at gmail.com
Mon Nov 14 16:59:45 EST 2005


> I was wondering how i could parse the contents of a file into an array.
>  the file would look something like this:
>
> gif:image/gif
> html:text/html
> jpg:image/jpeg

Try something like this:

d = {}
for line in open("input.txt").readlines():
  ext, mime = line.strip().split(":")
  d[ext] = mime
print d

Craig



More information about the Python-list mailing list