Friday, June 9, 2017

python practice

check if dict has key

if key in dict

python 3.6 install package

after 3.4, pip is not standalone, to install a package, run
python -m pip install SomePackage

functools.partial

returns a function with partially providing the parameters
https://docs.python.org/2/howto/functional.html 

python threads pool

csvFiles = list(filter(isFile, os.listdir("d:/quotes")))
with  multiprocessing.Pool(multiprocessing.cpu_count() - 1) as p:
    p.map(loadCsv, csvFiles)
Here loadCsv is the function, csvFiles is the list to iterate
https://docs.python.org/3.6/library/multiprocessing.html

pickle

with open('filename', 'a') as f:
        pickle.dump(data, f)

with open('filename', 'rb') as f:
    x = pickle.load(f)

python prirnt current exception

import traceback
traceback.print_exc()

No comments:

Post a Comment