The util module
The util module contains utility methods for various types
of actions such as manipulating strings, or debugging systems.
The debugging module
The debugging module contains utility methods which are useful when
debugging systems.
-
pyamp.util.debugging.getStackTrace()[source]
Get the current stack trace as a string.
-
pyamp.util.debugging.getClassName(obj)[source]
Get the class name for the given object.
The dictionary module
The dictionary module Contains utility methods for manipulating and dealing
with dictionary objects.
-
pyamp.util.dictionary.addNotNone(dictionary, key, value)[source]
Add the given value for the given key to the dictionary, only if the
value is not None.
- dictionary – The dictionary to add the key to
- key – The key
- value – The value for the key
-
pyamp.util.dictionary.getItems(dictionary, items, default=None)[source]
Return the given items in the dictionary, each item is taken
from the dictionary contained within the previous item, and if
one of the items in the chain does not exist this function
returns the default value.
Example:
from pyamp.util.dictionary import getItems
d = {"first": {"second": {"third": 500}}}
# Prints: 500
print getItems(d, ["first", "second", "third"])
# Prints: 200
print getItems(d, ["first", "non-existent"], 200)
- dictionary – The dictionary
- items – The list of items
- default – The default value
The sockets module
Contains utility methods for modifying socket attributes.
-
pyamp.util.sockets.setReusable(sockFd)[source]
Set the given socket to be reusable.
- sockFd – The socket file descriptor
The strings module
Contains utility methods pertaining to strings.
-
pyamp.util.strings.levenshtein(str1, str2, case=True)[source]
Calculate the Levenshtein distance between two strings.
- str1 – The first string
- str2 – The second string
- case – True for case sensitivity, False otherwise