Skip to content

Instantly share code, notes, and snippets.

@Mlawrence95
Created March 26, 2020 18:03
Show Gist options
  • Save Mlawrence95/73b781905cc7d8a27a6ee862ea31ae1d to your computer and use it in GitHub Desktop.
Save Mlawrence95/73b781905cc7d8a27a6ee862ea31ae1d to your computer and use it in GitHub Desktop.
Helpers to open common file types to python data analysis, json and pickle. Great addition to your startup.ipy file in ~/.ipython/profile_default/startup/
import json
import pickle
def openJSON(path):
"""
Safely opens json file at 'path'
"""
with open(path, 'r') as File:
data = json.load(File)
return data
def openPickle(path):
"""
Opens pickle file located at "path"
>>> openPickle('../data.pickle')
"""
with open(path, 'r') as open_file:
data = pickle.load(open_file)
return data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment