Skip to content

Instantly share code, notes, and snippets.

@andilabs andilabs/NamedTuple.py
Last active May 21, 2017

Embed
What would you like to do?
# Python 3.5.2 (default, Nov 17 2016, 17:05:23)
# Type "copyright", "credits" or "license" for more information.
# IPython 5.3.0 -- An enhanced Interactive Python.
# ? -> Introduction and overview of IPython's features.
# %quickref -> Quick reference.
# help -> Python's own help system.
# object? -> Details about 'object', use 'object??' for extra details.
In [1]: from typing import NamedTuple
In [2]: from decimal import Decimal
In [3]: data = {'latitude': Decimal('52.23959'), 'longitude': Decimal('21.02276'
...: )}
In [4]: GeoPoint = NamedTuple('GeoPoint', [('longitude', float), ('latitude', fl
...: oat)])
In [5]: geo = GeoPoint(**data)
In [6]: geo
Out[6]: GeoPoint(longitude=Decimal('21.02276'), latitude=Decimal('52.23959'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.