mps - My Python Snippets¶
My Python Snippets is a collection of nice to have and missing batteries for Python. The goal of this package is to increase developer productivity. This is done by providing often used functionality together with tools for development.
mps package¶
-
mps.
randstr
(n=8)¶ randstr creates a random string of numbers and upper/lowercase characters.
>>> randstr() "0YH58H9E" >>> randstr(5) "0ds34"
This code is slighty modified version of http://stackoverflow.com/questions/2257441/random-string-generation-with-upper-case-letters-and-digits-in-python
-
mps.
hdcache
(directory)¶ Decorator function that permantly cache function calls in a file
Example
>>> @hdcache("cachedresult.db") >>> def docomputation(x, y): >>> print("Doing hard computation for {} + {}".format(x, y)) >>> return str(x+y)
>>> docomputation(2, 3, cachekey="2 plus 3") "Doing hard computation for 2 + 5" "5" >>> docomputation(2, 3, cachekey="2 plus 3") "5"
The second docomputation does not call the actual function but retrieves the result from the file “cachedresult.db” Moreover, next time the program is called the result will also be cached
-
mps.
deco_logger
(log, length=None)¶
-
class
mps.
MemoizeWithTimeout
(timeout=2)¶ Bases:
object
Memoize With Timeout
The implementation builds on Leslie Polzer code from http://code.activestate.com/recipes/325905-memoize-decorator-with-timeout The code have been modified to support log and flushing.
-
collect
()¶ Clear cache of results which have timed out
-
-
class
mps.
ErrorRecoveryFile
(save_path, data, prefix=None)¶ Bases:
object
-
get_status
()¶
-
remove
()¶
-
set_status
(value)¶
-
status
¶
-
-
mps.
of_enumerate
(the_list)¶
Submodules¶
mps.countries module¶
-
mps.countries.
by_alpha2
(alpha2)¶
-
mps.countries.
by_alpha3
(alpha3)¶
-
mps.countries.
by_name
(name)¶
-
mps.countries.
by_numeric
(numeric)¶
mps.days module¶
mps.errorrecoveryfile module¶
-
class
mps.errorrecoveryfile.
ErrorRecoveryFile
(save_path, data, prefix=None)¶ Bases:
object
-
get_status
()¶
-
remove
()¶
-
set_status
(value)¶
-
status
¶
-
-
mps.errorrecoveryfile.
randstr
(n)¶
mps.hdcache module¶
-
mps.hdcache.
hdcache
(directory)¶ Decorator function that permantly cache function calls in a file
Example
>>> @hdcache("cachedresult.db") >>> def docomputation(x, y): >>> print("Doing hard computation for {} + {}".format(x, y)) >>> return str(x+y)
>>> docomputation(2, 3, cachekey="2 plus 3") "Doing hard computation for 2 + 5" "5" >>> docomputation(2, 3, cachekey="2 plus 3") "5"
The second docomputation does not call the actual function but retrieves the result from the file “cachedresult.db” Moreover, next time the program is called the result will also be cached
mps.mwt module¶
-
class
mps.mwt.
MemoizeWithTimeout
(timeout=2)¶ Bases:
object
Memoize With Timeout
The implementation builds on Leslie Polzer code from http://code.activestate.com/recipes/325905-memoize-decorator-with-timeout The code have been modified to support log and flushing.
-
collect
()¶ Clear cache of results which have timed out
-
mps.randstr module¶
-
mps.randstr.
randstr
(n=8)¶ randstr creates a random string of numbers and upper/lowercase characters.
>>> randstr() "0YH58H9E" >>> randstr(5) "0ds34"
This code is slighty modified version of http://stackoverflow.com/questions/2257441/random-string-generation-with-upper-case-letters-and-digits-in-python