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
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
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
Thanks a lot. The webserver I am writing works now :)
--
http://mail.python.org/mailman/listinfo/python-list
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
> 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
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