Skip to main content

Attributes-accessible mappings chainstuf (like ChainMap) & counterstuf (like Counter)

Project description

Attribute-accesible collections inspired by stuf. Implements chainstuf and counterstuf: versions of ChainMap and Counter that expose their keys as attributes.

The ultimate goal of this module is to have these functions available in the stuf module, and this sidecar to be retired.

Usage

Use these just like you would ChainMap and Counter, except that you get attribute-style access as well.

For chainstuf:

from chainstuf import chainstuf

d1 = dict(this=1, that=2)
d2 = dict(roger=99, that=100)

# test simple attribute equivalence
c = chainstuf(d1, d2)

assert c.this == 1
assert c.roger == 99

c.roger = 'wilco'
assert c.roger
print "roger", c.roger

d1.update(feeling='fancypants!')
print "i'm feeling", c.feeling     # passed through, since d2 lacks 'feeling'

For counterstuf:

from counterstuf import counterstuf

c = counterstuf()
c.update("this and this is this but that isn't this".split())
c.total = sum(c.values())

print "everything:", c.total
print "'this' mentioned", c.this, "times"
print "'bozo' mentioned", c.bozo, "times"
print c

Notes

  • Commenced automated multi-version testing with pytest and tox.
  • Now successfully packaged and tested for Python 2.6, 2.7, 3.2, 3.3 and PyPy 1.9 (aka Python 2.7.2). Previous exceptions for Python 2.6 have been eliminated.
  • The author, Jonathan Eunice or @jeunice on Twitter welcomes your comments and suggestions.

Installation

pip install otherstuf

To easy_install under a specific Python version (3.3 in this example):

python3.3 -m easy_install otherstuf

(You may need to prefix these with “sudo ” to authorize installation. If they’re already installed, the --upgrade flag will be helpful; add it right before the package name.)

Project details


Release history Release notifications

History Node

1.1.0

History Node

1.0.1

History Node

1.0.0

History Node

0.902

History Node

0.803

History Node

0.802

This version
History Node

0.704

History Node

0.702

History Node

0.651

History Node

0.604

History Node

0.509

History Node

0.507

History Node

0.503

History Node

0.502

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
otherstuf-0.704.tar.gz (3.9 kB) Copy SHA256 hash SHA256 Source None Oct 31, 2012
otherstuf-0.704.zip (8.4 kB) Copy SHA256 hash SHA256 Source None Oct 31, 2012

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page