A port of Java 8’s
java.util.Propertiesthat tries to match its behavior as much as is Pythonically possible.
Propertiesbehaves like a normal
MutableMappingclass (i.e., you can do
props[key] = valueand so forth), except that it may only be used to store strings (
unicodein Python 2; just
strin Python 3). Attempts to use a non-string object as a key or value will produce a
Propertiesinstances compare equal iff both their key-value pairs and
defaultsattributes are equal. When comparing a
Propertiesinstance to any other type of mapping, only the key-value pairs are considered.
New in version 0.5.0.
Propertiessubobject used as fallback for
__eq__use this attribute; all other methods (including the standard mapping methods) ignore it.
Fetch the value associated with the key
Propertiesinstance. If the key is not present,
defaultsis checked, and then its
defaults, etc., until either a value for
keyis found or the next
None, in which case
Propertiesinstance with the entries in a
.propertiesfile or file-like object.
inStreammay be either a text or binary filehandle, with or without universal newlines enabled. If it is a binary filehandle, its contents are decoded as Latin-1.
Changed in version 0.5.0: Invalid
\uXXXXescape sequences will now cause an
InvalidUEscapeErrorto be raised
Propertiesinstance with the entries in the XML properties file
Beyond basic XML well-formedness,
loadFromXMLonly checks that the root element is named
propertiesand that all of its
keyattributes; no further validation is performed.
xml.etree.ElementTreefor parsing, which does not have decent support for
unicodeinput in Python 2. Files containing non-ASCII characters need to be opened in binary mode in Python 2, while Python 3 accepts both binary and text input.
- Return type
generator of text strings
self[key] = value
Propertiesinstance’s entries (in unspecified order) in
out, including the current timestamp.
storeToXML(out, comment=None, encoding='UTF-8')¶
Propertiesinstance’s entries (in unspecified order) in XML properties format to
out (binary file-like object) – a file-like object to write the properties to
encoding (string) – the name of the encoding to use for the XML document (also included in the XML declaration)