Thursday, November 24, 2016




How do you store & retrieve native Python data objects in file (without using the eval() function)?

We can use the pickle module and its dump() and load() functions to store and retrieve the data objects to and from a file respectively. 

In the code block below we are storing a dictionary object D to a file & reading it back in E.


In 3.5.1

The same works for python 2.x

Note:- Using eval() is considered as a security hole since if used in conjunction with the built-in input() function it can lead to dynamically injected intrusive code that can, for example, wipe out the entire data on your system!



No comments:

Post a Comment