Skip to main content

Use methods and method chaining on lists of objects.

Project description

ObjectList

Use methods and method chaining on lists of objects. Also allowing clean syntax for parallel processing.

Examples

As an example we define an ObjectList of Path objects.

from objectlist import ObjectList

from pathlib import Path
path_list = [Path('foo/a'), Path('foo/bar/b'), Path('foo/bar/c')]
path_objectlist = ObjectList(path_list)

Getting object attributes and properties

If we would like to get the parents of all paths

[WindowsPath('foo'), WindowsPath('foo/bar'), WindowsPath('foo/bar')]

then using a normal list it is necessary to use a loop:

[p.parent for p in path_list]

but using an ObjectList this can be done by

path_objectlist.parent

ObjectLists can be easily converted to strings:

path_objectlist.parent.str
['foo', 'foo\\bar', 'foo\\bar']

Using object methods and passing arguments

Object methods can also be used

path_objectlist.with_suffix('.txt')
[WindowsPath('foo/a.txt'), WindowsPath('foo/bar/b.txt'), WindowsPath('foo/bar/c.txt')]

Using parallel processing

Parallel processing can be activated on existing ObjectLists by using .parallel

path_objectlist.parallel.with_suffix('.txt')

Alternatively parallel processing can be activated when the ObjectList is defined:

path_objectlist = ObjectList(path_list, 
                             use_parallel_processing=True, 
                             number_of_cores=None,
                             parallel_processing_kwargs=dict(verbose=0), 
                             return_none_if_all_none=True)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

objectlist-1.0.2.tar.gz (17.3 kB view hashes)

Uploaded Source

Built Distribution

objectlist-1.0.2-py3-none-any.whl (17.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page