8000 GitHub - ksamuel/drecord
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ksamuel/drecord

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

drecord: Dynamic record type for python

I often wish Python had a literal syntax for a record type that you can dynamically create on the fly.

NamedTuple is nice, but must be defined before hand. SimpleNamespace is also interesting, but is not iterable, nor sliceable.

This repo is a PoC of what such a dynamic record type could be:

>>> from drecord import r
>>> record = r(a=0, b=1, c=2, d=3, e=4, f=5, g=5)
>>> record[0]
0
>>> record.a
0
>>> list(record)
[0, 1, 2, 3, 4, 5, 5]
>>> record == (0, 1, 2, 3, 4, 5, 5)
True
>>> record[1:4]
r(b=1 c=2 d=3)
>>> record["b":"e"]
r(b=1 c=2 d=3)
>>> record(a="foo", b="bar")
r(a=foo b=bar c=2 d=3 e=4 f=5 g=5)
>>> record.__dict__
{'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 5}

It's not a on pypi but it's a single standalone file.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0