The Best of the Rest
Highlights the most useful of the remaining functionality in supybot.utils
Strike
Supybot provides a wealth of utilities for plugin writers in the supybot.utils module, this tutorial describes these utilities and shows you how to use them.
Page
4
of
4.
Intro
Rather than document each of the remaining portions of the supybot.utils module, I've elected to just pick out the choice bits from specific parts and document those instead. Here they are, broken out by module name.
supybot.utils.file - file utilities
touch(filename)- updates the access time of a file by opening it for writing and immediately closing itmktemp(suffix="")- creates a decent random string, suitable for a temporary filename with the given suffix, if provided- the
AtomicFileclass - used for files that need to be atomically written, i.e., if there's a failure the original file remains unmodified. For more info consultfile.pyinsrc/utils
supybot.utils.gen - general utilities
timeElapsed(elapsed, [lots of optional args])- given the number of seconds elapsed, returns a string with the English description of the amount of time passed, consultgen.pyinsrc/utilsfor the exact argument list and documentation if you feel you could use this function.exnToString(e)- improved exception-to-string function. Provides nicer output than a simplestr(e).InsensitivePreservingDictclass - adictclass that is case-insensitive when accessing keys
supybot.utils.iter - iterable utilities
len(iterable)- returns the length of a given iterablegroupby(key, iterable)- equivalent to theitertools.groupbyfunction available as of Python 2.4. Provided for backwards compatibility.any(p, iterable)- Returns true if any element in the iterable satisfies the predicatepall(p, iterable)- Returns true if all elements in the iterable satisfy the predicatepchoice(iterable)- Returns a random element from the iterable