Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install value

How to install value

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install value
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
Windows (64-bit)
Mac OS X (10.5+)
Linux (32-bit)
0.1.0 Available View build log
Linux (64-bit)
0.1.0 Available View build log
0.1.0 Available View build log
 
License
MIT
Imports
Lastest release
version 0.1.0 on Mar 26th, 2013

From Wikipedia:

A value object is a small object that represents a simple entity whose equality isn't based on identity: i.e. two value objects are equal when they have the same value, not necessarily being the same object.

By default (if you subclass from object) Python follows "reference semantics", i.e. two objects are equal if they are the same instance. Value class implements "value semantics", i.e. if you subclass it your objects will be equall if they hold the same data.

This implementation will also inspect your __init__ signature to automatically assign instance variables and produce a nice __repr__ for your objects, dogether with a suitable __hash__ implementation.

Instead of asigning each instance variable manually:

System Message: ERROR/3 (<string>, line 24)

Unknown directive type "code".

.. code:: python

    >>> class Date(object):
    ...
    ...     def __init__(self, year, month=1, day=1):
    ...         self.year = year
    ...         self.month = month
    ...         self.day = day

Value defines __new__ that will look at your __init__ signature and assign instance variables based on it:

System Message: ERROR/3 (<string>, line 37)

Unknown directive type "code".

.. code:: python

    >>> from value import Value
    ...
    >>> class Date(Value):
    ...
    ...     def __init__(self, year, month=1, day=1):
    ...         pass
    ...
    >>> Date(2013, 3).year == 2013
    True
    >>> Date(2013, 3).month == 3
    True
    >>> Date(2013, 3).day == 1
    True

Value defines __eq__ and __ne__ to implement value object semantics, i.e. objects holding the same data are compared equal:

System Message: ERROR/3 (<string>, line 57)

Unknown directive type "code".

.. code:: python

    >>> Date(2013, 3, 18) == Date(2013, 3, 18)
    True
    >>> Date(2013, 3, 18) != Date(1988)
    True

Value also defines __repr__ for you based on __init__ signature:

System Message: ERROR/3 (<string>, line 67)

Unknown directive type "code".

.. code:: python

    >>> repr(Date(2013, 3, 18))
    'Date(2013, 3, 18)'
    >>> repr(Date(1988, 1, 1))
    'Date(1988)'

Value also defines __hash__ for you, so that instances could be used in sets and as dictionary keys.

Installation

Use pip or easy_install:

pip install value==0.1.0

Alternatively, you can just drop value.py file into your project—it is self-contained.

Subscribe to package updates

Last updated Mar 26th, 2013

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.