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
# http://www.python.org/dev/peps/pep-3101/ | |
# "My name is Fred" | |
"My name is {0}".format('Fred') | |
"My name is {0.name}".format(open('out.txt', 'w')) | |
"My name is {0[name]}".format(dict(name='Fred')) |
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
# append dict extra to dict orig | |
orig.update(extra) | |
# make new dict with blend of both | |
dest = dict(orig) # or dict(**orig) or dict.copy() | |
dest.update(extra) | |
# Reference: | |
# http://stackoverflow.com/questions/8930915/python-append-dictionary-to-dictionary |
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
# Importing MATLAB .mat files into Python | |
import scipy.io | |
mat = scipy.io.loadmat('file.mat') |
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
# This example passes one formal (positional) argument, and two more variable length arguments. | |
def test_var_args(farg, *args): | |
print "formal arg:", farg | |
for arg in args: | |
print "another arg:", arg | |
test_var_args(1, "two", 3) | |
# Here is an example of how to use the keyworded form. Again, one formal argument and two keyworded variable arguments are passed. | |
def test_var_kwargs(farg, **kwargs): |
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
s = " \t foo \n bar " | |
"".join(s.split()) | |
#http://stackoverflow.com/questions/3739909/how-to-strip-all-whitespace-from-string |
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
gitk --all | |
git log --graph --all --oneline |
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
# will attempt to merge into the current/active branch | |
git merge [branch_name] |
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
git commit --ammend | |
# what this does is add the content of the staging area to the latest commit | |
# you'll then be asked for a commit message. This commit and its message will override the previous commit - but CREATES A NEW HEASH |
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
git reset --hard HEAD | |
# the --hard flag puts the content of whatever is in the targeted commit (in this case, HEAD) into both the working directory and staging area | |
# roll back individual files | |
git checkout | |
git checkout HEAD file.ext |
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 numpy as np | |
x = array([3,4,None,55]) | |
y = np.array(x,dtype=float) | |
# OR | |
y = np.array(x) | |
z = y.astype(float) |