anydbm biasing

Discussion in 'Python' started by Eric S. Johansson, Jan 18, 2005.

  1. I have a preference for gdbm when building DBM based dictionaries but
    have found I cannot count on it being there all the time. Therefore, I
    have created this little tidbit which you call before opening your
    anydbm database to bias the preference towards gdbm instead of dbhash:

    # bias DBM towards gdbm if at all possible.
    def bias_anydbm():
    """bias anydbm to gdbm"""

    try:
    _mod = __import__("gdbm")
    except ImportError:
    pass
    else:
    # and other words, if you can import gdbm, make it the default
    anydbm._defaultmod = _mod


    usage:
    bias_anydbm()
    open_DBM = anydbm.open(DBM_path, 'c')

    if you have gdbm enabled, it will use that otherwise it will default to
    the search list in anydbm. obviously, this can be used to bias anydbm
    to meet your own preferences

    ---eric
     
    Eric S. Johansson, Jan 18, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John D.

    Example code for anydbm wanted...

    John D., Aug 4, 2003, in forum: Python
    Replies:
    0
    Views:
    340
    John D.
    Aug 4, 2003
  2. Gary Richardson

    anydbm bug ?

    Gary Richardson, Dec 4, 2003, in forum: Python
    Replies:
    2
    Views:
    588
    Dennis Lee Bieber
    Dec 5, 2003
  3. =?ISO-8859-1?Q?=22C=E9dric_V=2E=22?=

    error at "import anydbm"

    =?ISO-8859-1?Q?=22C=E9dric_V=2E=22?=, Jan 13, 2004, in forum: Python
    Replies:
    4
    Views:
    556
    Peter Hansen
    Jan 14, 2004
  4. Anton Sherwood

    text storage: shelve vs anydbm vs ?

    Anton Sherwood, Apr 17, 2004, in forum: Python
    Replies:
    1
    Views:
    449
    Larry Bates
    Apr 17, 2004
  5. Derek Basch
    Replies:
    1
    Views:
    410
    Dan Sommers
    Jan 11, 2005
Loading...

Share This Page