Skip to content

Supybot Website

Sections
Personal tools
You are here: Home » Documentation » Supybot Help Center » Tutorials » Using Supybot's utils module » The Best of the Rest

The Best of the Rest

Document Actions
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 it
  • mktemp(suffix="") - creates a decent random string, suitable for a temporary filename with the given suffix, if provided
  • the AtomicFile class - used for files that need to be atomically written, i.e., if there's a failure the original file remains unmodified. For more info consult file.py in src/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, consult gen.py in src/utils for 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 simple str(e).
  • InsensitivePreservingDict class - a dict class that is case-insensitive when accessing keys

supybot.utils.iter - iterable utilities

  • len(iterable) - returns the length of a given iterable
  • groupby(key, iterable) - equivalent to the itertools.groupby function available as of Python 2.4. Provided for backwards compatibility.
  • any(p, iterable) - Returns true if any element in the iterable satisfies the predicate p
  • all(p, iterable) - Returns true if all elements in the iterable satisfy the predicate p
  • choice(iterable) - Returns a random element from the iterable
Created by Strike
Contributors : Strike
Last modified 19:46 April 26, 2006
 

Powered by Plone

This site conforms to the following standards: