A "Best of the Best Practices" (BOBP) guide to developing in Python.
- "Build tools for others that you want to be built for you." - Kenneth Reitz
- "Simplicity is alway better than functionality." - Pieter Hintjens
from contextlib import contextmanager | |
import sys, os | |
@contextmanager | |
def suppress_stdout(): | |
""" | |
source: https://gist.github.com/djsmith42/3956189 | |
usage: | |
print "You can see this" | |
with suppress_stdout(): |
from contextlib import contextmanager | |
import sys, os | |
@contextmanager | |
def suppress_stdout(): | |
with open(os.devnull, "w") as devnull: | |
old_stdout = sys.stdout | |
sys.stdout = devnull | |
try: | |
yield |
#!/usr/bin/env python | |
from __future__ import print_function | |
__author__ = 'github.com/ruxi' | |
__license__= 'MIT' | |
import sys | |
import os.path | |
import subprocess | |
def runbash(cmd, cwd=".", shell=True, logname="runbash.log", ioprint=True): | |
""" | |
cmd: bash command to run. example: 'ls -l' |
# Rename all *.fasta to *.sra | |
for f in *.fasta; do | |
mv -- "$f" "${f%.fasta}.sra" | |
done |
#!/usr/bin/env python | |
__author__ = "github.com/ruxi" | |
__license__ = "MIT" | |
import requests | |
import tqdm # progress bar | |
import os.path | |
def download_file(url, filename=False, verbose = False): | |
""" | |
Download file with progressbar | |
#!/usr/bin/env python | |
# Note, updated version of | |
# https://github.com/ipython/ipython-in-depth/blob/master/tools/nbmerge.py | |
""" | |
usage: | |
python nbmerge.py A.ipynb B.ipynb C.ipynb > merged.ipynb | |
""" | |
import io |