Re: Parse file into array

2005-11-15 Thread Bengt Richter
On 14 Nov 2005 13:48:45 -0800, "amfr" <[EMAIL PROTECTED]> wrote: >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 >... > >As you can see, it contains the mime type and the file exten

Re: Parse file into array

2005-11-15 Thread Andrew Nelis
If it helps, there's a builtin module for figuring out mimetypes; http://docs.python.org/lib/module-mimetypes.html >>> import mimetypes >>> mimetypes.guess_type('.gif') ('image/gif', None) Cheers, Andy. -- http://mail.python.org/mailman/listinfo/python-list

Re: Parse file into array

2005-11-14 Thread Leif K-Brooks
Leif K-Brooks wrote: > line = line.rsplit('\r\n') Er, that should be line.rstrip, not line.rsplit. -- http://mail.python.org/mailman/listinfo/python-list

Re: Parse file into array

2005-11-14 Thread amfr
Thanks a lot. The webserver I am writing works now :) -- http://mail.python.org/mailman/listinfo/python-list

Re: Parse file into array

2005-11-14 Thread Leif K-Brooks
amfr wrote: > 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 > ... > > As you can see, it contains the mime type and the file extension > seperated by commas, 1 per line. I wa

Re: Parse file into array

2005-11-14 Thread Craig Marshall
> 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] = mim

Parse file into array

2005-11-14 Thread amfr
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 ... As you can see, it contains the mime type and the file extension seperated by commas, 1 per line. I was wondering if it was possible t