reading files into dicts

Tim Williams (gmail) tdwdotnet at gmail.com
Thu Dec 29 19:35:02 EST 2005


On 30/12/05, Giovanni Bajo <noway at sorry.com> wrote:
>
>
> >>> d = {'.\\sync_pics.py': 1135900993, '.\\file_history.txt': 1135900994,
> .... '.\\New Text Document.txt': 1135900552}
> >>> file("foo", "w").write(repr(d))
> >>> data = file("foo").read()
> >>> data
> "{'.\\\\sync_pics.py': 1135900993, '.\\\\file_history.txt': 1135900994,
> '.\\\\New Text Document.txt': 1135900552}"
> >>> d = eval(data)
> >>> d
> {'.\\sync_pics.py': 1135900993, '.\\file_history.txt': 1135900994, '.\\New
> Text
> Document.txt': 1135900552}
>
> eval() is risky if you can't control the contents of the file  :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20051230/aaef6526/attachment.html>


More information about the Python-list mailing list