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
Release history Release notifications | RSS feed
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)
Built Distribution
objectlist-1.0.2-py3-none-any.whl
(17.2 kB
view hashes)
Close
Hashes for objectlist-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6e4cd31810785b233fe13372a14293b379dcaa05e7851196050d6d52f786f05 |
|
MD5 | 548ab93bf90aa7f739aceb4f2387e657 |
|
BLAKE2b-256 | add767a38f79e8912703ca78e0669c6b93893b742843a30fa6bc61c7e1b039ab |