pyTooling.Common
Common types, helper functions and classes.
Hint
See high-level help for explanations and usage examples.
Variables
Functions
isnestedclass()
: Returns true, if the given classcls
is a member on an outer classscope
.getsizeof()
: Recursively calculate the “true” size of an object including complex members like__dict__
.firstElement()
: Returns the first element from an indexable.lastElement()
: Returns the last element from an indexable.firstItem()
: Returns the first item from an iterable.lastItem()
: Returns the last item from an iterable.firstKey()
: Retrieves the first key from a dictionary’s keys.firstValue()
: Retrieves the first value from a dictionary’s values.firstPair()
: Retrieves the first key-value-pair from a dictionary.mergedicts()
: Merge multiple dictionaries into a single new dictionary.zipdicts()
: Iterate multiple dictionaries simultaneously.
Variables
- pyTooling.Common.CurrentPlatform
Gathered information for the current platform.
Platforms.Linux
Functions
- pyTooling.Common.isnestedclass(cls, scope)[source]
Returns true, if the given class
cls
is a member on an outer classscope
.
- pyTooling.Common.getsizeof(obj)[source]
Recursively calculate the “true” size of an object including complex members like
__dict__
.- Parameters:
obj (
Any
) – Object to calculate the size of.- Return type:
- Returns:
True size of an object in bytes.
Background Information
The function
sys.getsizeof()
only returns the raw size of a Python object and doesn’t account for the overhead of e.g._dict__
to store dynamically allocated object members.See also
The code is based on code snippets and ideas from:
Compute Memory Footprint of an Object and its Contents (MIT Lizense)
How do I determine the size of an object in Python? (CC BY-SA 4.0)
Python __slots__, slots, and object layout (MIT Lizense)
- pyTooling.Common.mergedicts(*dicts, filter=None)[source]
Merge multiple dictionaries into a single new dictionary.
If parameter
filter
isn’tNone
, then this function is applied to every element during the merge operation. If it returns true, the dictionary element will be present in the resulting dictionary.
- pyTooling.Common.zipdicts(*dicts)[source]
Iterate multiple dictionaries simultaneously.
- Parameters:
dicts (
Tuple
[Dict
,...
]) – Tuple of dictionaries to iterate as positional parameters.- Return type:
- Returns:
A generator returning a tuple containing the key and values of each dictionary in the order of given dictionaries.
See also
The code is based on code snippets and ideas from:
zipping together Python dicts (MIT Lizense)