Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IO Error while storing data in pickle

Tags:

python

pickle

i have a following code in a python to store data in pickle , but i am getting IO Error

[Errno 13] Permission denied: 'data.pkl'

Code

def SaveUserData(request):
       datalist={}
       datalist['empid']='127113'
       datalist['empname']='eric'
       datalist['empphone']='66335500'
       datalist['email']='[email protected]'
       output = open('data.pkl', 'wb')
       pickle.dump(datalist, output)
       output.close()
       data = simplejson.dumps(datalist, indent=4)
       return HttpResponse(data,mimetype='application/javascript')
like image 283
Hunt Avatar asked Mar 12 '11 20:03

Hunt


People also ask

How do I save my pickle data?

To save a pickle, use pickle. dump . A convention is to name pickle files *. pickle , but you can name it whatever you want.

How do I fix permission denied Python?

The PermissionError: [errno 13] permission denied error occurs when you try to access a file from Python without having the necessary permissions. To fix this error, use the chmod or chown command to change the permissions of the file so that the right user and/or group can access the file.

What is dump and load in pickle?

dump() function to store the object data to the file. pickle. dump() function takes 3 arguments. The first argument is the object that you want to store. The second argument is the file object you get by opening the desired file in write-binary (wb) mode.

Does pickle dump overwrite or append?

Pickle dump replaces current file data.


2 Answers

Well i assigned the absolute path & it worked !!

output = open('/home/user/test/wsservice/data.pkl', 'wb')
like image 92
Hunt Avatar answered Sep 29 '22 21:09

Hunt


I've noticed in Python 3.4 you can do it like:
output = open(str(dataList), "wb")

like image 21
user3825864 Avatar answered Sep 29 '22 20:09

user3825864