Skip to main content
# list_property
Module for making list properties or named lists


## list_property - function
```python
import list_property

class Person(list):
first_name = list_property(0)
last_name = list_property(1)
middle_initial = list_property(2, '')

p = Person(("John", "Smith"))
assert p == ["John", "Smith"]

assert p.first_name == 'John'
assert p[0] == 'John'
assert p.last_name == 'Smith'
assert p[1] == 'Smith'
assert p.middle_initial == ''
try:
assert p[2] == ''
raise AssertionError('Index 2 was not set and there should be an IndexError!')
except IndexError:
pass # Success

p.first_name = "Hello"
p.last_name = 'World!'
p.middle_initial = 'T'
assert p.first_name == 'Hello'
assert p[0] == 'Hello'
assert p.last_name == 'World!'
assert p[1] == 'World!'
assert p.middle_initial == 'T'
assert p[2] == 'T' # Note: p[2] is now set
```
This class also works like a property decorator

```python
import list_property

class Person(list):
@list_property(0)
def first_name(self):
try:
return self[0]
except:
return 'anonymous'

middle_initial = list_property(2)

@middle_initial.setter
def middle_initial(self, value):
self[2] = str(value)[0].upper()
```


## namedlist
Named list factory function like named tuple

```python
from list_property import namedlist, NamedList

Person = namedlist('Person', 'first_name last_name middle_initial', {'middle_initial': 'T'})

p = Person('John', 'Smith')
assert p.first_name == 'John'
assert p[0] == 'John'
assert p.last_name == 'Smith'
assert p[1] == 'Smith'
assert p.middle_initial == 'T'
assert p[2] == 'T'
assert isinstance(p, list)
assert isinstance(p, NamedList)
```

Metadata

Release files for list-property 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for list-property 0.0.1
File Size Uploaded Provenance Actions
list_property-0.0.1.tar.gz 5.2 kB Without provenance Details for list_property-0.0.1.tar.gz

Release files / list_property-0.0.1.tar.gz

Download URL list_property-0.0.1.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
40d8728905dfd66b8aedc6b486c0d138b31fb517ebf8228c707ad16494e22756
BLAKE2b-256 checksum
How to use checksums
26142b17d528304a7120368dd5fc722c255c7435613d8468104ed31bf103814f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for list-property 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page