Skip to content

Instantly share code, notes, and snippets.

@sengstacken
Last active February 5, 2019 23:15
Show Gist options
  • Save sengstacken/200feaa67386622b57a91427773f8d48 to your computer and use it in GitHub Desktop.
Save sengstacken/200feaa67386622b57a91427773f8d48 to your computer and use it in GitHub Desktop.
Python Snips

Python Tips

File I/O!

f = open('workfile.b','r')
a = f.read() # or .readlines()
f.close()

f = open('workfile.b','w')
f.write('hello,world')
f.close()

FastAI Debug

python -m fastai.utils.show_install

Pickle!

import pickle
p = pickle.load(open('loadercards.p','r'))
pickle.dump(x,open('loadercard.p','wb'))

Time

import datetime
timestring = datetime.datetime.now().isoformat()
timestring = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

Find differences between two lists

temp1 = ['One', 'Two', 'Three', 'Four']
temp2 = ['One', 'Two', 'Five']
diff1 = list(set(temp1) - set(temp2))
diff2 = list(set(temp2) - set(temp1))

#what is common?
common = set(temp1).intersection(set(temp2))

Start Jupyter (ipython) Notebook

navigate to folder
open cmd window
jupyter notebook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment