semvec/pypi-packages huggingface dataset:
typedtuple 0.1.0
namedtuple with validation
License: MIT

typedtuple
==========

install
-------

::

  $ pip install typedtuple

basic definition
----------------

.. code:: python

    from typedtuple import typedtuple

    # definition dictionary is converted to voluptuous.Schema(definition_dict, required=True)
    Vector = typedtuple('Vector', {'x': float, 'y': float, 'z': float})
    v0 = Vector(x=10.0, y=20.0, z=30.0)
    print v0.x  # 10.0
    v1 = Vector(x=10, y=20)  # raises exception

using voluptuous schema
-----------------------

.. code:: python

    from voluptuous import Schema

    # can use voluptuous.Schema as definition
    Vector = typedtuple('Vector', Schema({'x': float, 'y': float, 'z': float}, required=True))

using @schema decorator
-----------------------

.. code:: python

    from math import sqrt
    from typedtuple import schema

    @schema({'x': float, 'y': float, 'z': float})
    class Vector(object):
        @property
        def length(self):
            return sqrt(pow(self.x, 2.0) + pow(self.y, 2.0) + pow(self.z, 2.0))

    v = Vector(x=1.0, y=2.0, z=2.0)
    print v.length  # 3.0

using voluptuous functions
--------------------------

.. code:: python

    from voluptuous import Coerce
    from typedtuple import schema

    @schema({'x': Coerce(float), 'y': Coerce(float)})
    class Vector(object):
        pass

    v0 = Vector(x=10, y='20.0')
    print v0.x  # 10.0
    print v0.y  # 20.0

using OrderedDict
-----------------

.. code:: python

    from collections import OrderedDict
    from typedtuple import schema

    @schema(OrderedDict((('x', float), ('y', float), ('z', float))))
    class Vector(object):
        pass

    print Vector._fields  # ('x', 'y', 'z')

caveat
------

TypedTuple is tuple. so...

.. code:: python

    from collections import OrderedDict
    from typedtuple import typedtuple

    Vector0 = typedtuple('Vector0', OrderedDict((('x', float), ('y', float))))
    Vector1 = typedtuple('Vector1', OrderedDict((('y', float), ('x', float))))

    v0 = Vector0(x=10.0, y=20.0)
    v1 = Vector1(x=20.0, y=10.0)
    v0 == v1  # True

TODO
----

use nose for test

benchmark
luapatt 0.9.0b5
Python implementation of Lua-style pattern matching
License: MIT
Keywords: Lua pattern matching regex regular expressions

luapatt |travis-develop|
========================

A Python 3.3+ implementation of the `Lua language’s`_ pattern matching
functions. Lua’s pattern matching is simpler than regular expressions
and lacks several features that regexes have, such as ``|`` for
alternation, but also contains some features difficult or impossible to
duplicate in most regex flavors, such as the ability to easily match a
balanced pair of parentheses (or any two other characters).

Installation
------------

``pip install luapatt``

Documentation
-------------

For documentation on how pattern matching works, please read the `Lua
reference manual`_. This library contains the following differences from
stock Lua:

-  ``%c``, ``%g``, ``%p``, and their negated counterparts are not
   available; attempting to use them will raise the built-in
   ``NotImplementedError``.
-  Other character classes that rely on the meaning of a character call
   Python’s ``str.is*`` family of methods, and so use the Unicode
   definition of that meaning.
-  String positions are zero-based instead of one-based, reflecting the
   fact that Python is generally zero-based (as opposed to Lua, which
   has one-based indexes). This affects position captures and the
   indexes returned as the first two results from ``find()``.
-  Function return values are combined into a tuple, as is standard with
   Python. However, singleton tuples are not returned; the single value
   is returned directly instead.
-  ``gsub()`` does *not* return the number of substitutions by default,
   instead returning only the new string. To get the count, pass the
   named argument ``count=True`` to the call (which will result in a
   2-tuple of the new string and the count).
-  An extra function, ``set_escape_char()``, is provided to change the
   escape character. It takes one argument: the new escape character,
   which must be a ``str`` object of length 1. The escape character
   cannot be set to any of the other special characters. While it is
   possible to set it to a letter or number, this is not recommended as
   it may interfere with other aspects of pattern matching, and doing so
   may be disallowed in the future.

   -  **NOTE:** Because ``set_escape_char`` modifies global state, it is
      **not** thread-safe.

-  Unlike Lua, which has no notion of a Unicode string and assumes all
   characters are one byte in length, this library operates on full
   Unicode strings (i.e. ``str`` objects). If you pass bytes objects to
   this library, the behavior is undefined.

Licensing
---------

As with Lua itself, this library is released under the MIT License.

.. _Lua language’s: http://www.lua.org/home.html
.. _Lua reference manual: http://www.lua.org/manual/5.3/manual.html#6.4.1
.. |travis-develop| image:: https://travis-ci.org/jcgoble3/luapatt.svg?branch=develop
   :target: https://travis-ci.org/jcgoble3/luapatt