Created
March 26, 2020 18:03
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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