Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pickle save

import pickle

pickle.dump( favorite_color, open( "save.p", "wb" ) )
favorite_color = pickle.load( open( "save.p", "rb" ) )
Comment

save a file as a pickle

with open('mypickle.pickle', 'wb') as f:
    pickle.dump(some_obj, f)

# note that this will overwrite any existing file
# in the current working directory called 'mypickle.pickle'
Comment

how to save a pickle file

Python 3.4.1 (default, May 21 2014, 12:39:51) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> mylist = ['I wish to complain about this parrot what I purchased not half an hour ago from this very boutique.', "Oh yes, the, uh, the Norwegian Blue...What's,uh...What's wrong with it?", "I'll tell you what's wrong with it, my lad. 'E's dead, that's what's wrong with it!", "No, no, 'e's uh,...he's resting."]
>>> 
>>> import pickle
>>> 
>>> with open('parrot.pkl', 'wb') as f:
...   pickle.dump(mylist, f)
... 
>>>  with open('parrot.pkl', 'wb') as f:
...   new_list = pickle.load(mylist, f)

Comment

how to save a pickle file

Python 3.4.1 (default, May 21 2014, 12:39:51) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> with open('parrot.pkl', 'rb') as f:
...   mynewlist = pickle.load(f)
... 
>>> mynewlist
['I wish to complain about this parrot what I purchased not half an hour ago from this very boutique.', "Oh yes, the, uh, the Norwegian Blue...What's,uh...What's wrong with it?", "I'll tell you what's wrong with it, my lad. 'E's dead, that's what's wrong with it!", "No, no, 'e's uh,...he's resting."]
>>>
Comment

PREVIOUS NEXT
Code Example
Python :: Check for duplicate values in dataframe 
Python :: python how to code discord bot kick members 
Python :: concat tensors pytorch 
Python :: how to set the location on a pygame window 
Python :: python tkinter lable on bottom of screen 
Python :: Python Current time using time module 
Python :: sns scatter plot 
Python :: matplotlib transparency 
Python :: matplotlib change bar color under threshold 
Python :: replace "-" for nan in dataframe 
Python :: FizzBuzz FizzBuzz is a well known programming assignment, asked during interviews. 
Python :: decyphing vigener cypher without key 
Python :: how to use an indefinite number of args in python 
Python :: anaconda create environment python version 
Python :: generate 12 random numbers python 
Python :: convert string array to integer python 
Python :: random name generator in python 
Python :: django logout 
Python :: django model query add annotation field to show duplicate count 
Python :: views.home not found django 
Python :: turn of axis 
Python :: histogram seaborn 
Python :: repeat 10 times python 
Python :: display flask across network 
Python :: who wrote permission to dance 
Python :: Date difference in minutes in Python 
Python :: Replace empty string and "records with only spaces" with npnan pandas 
Python :: procfile heroku django 
Python :: how to change colour of rows in csv using pandas 
Python :: one hot encoder python 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =