Properties Class
- class javaproperties.Properties(data: None | Mapping[str, str] | Iterable[tuple[str, str]] = None, defaults: Properties | None = None)[source]
A port of Java 8’s
java.util.Propertiesthat tries to match its behavior as much as is Pythonically possible.Propertiesbehaves like a normalMutableMappingclass (i.e., you can doprops[key] = valueand so forth), except that it may only be used to storestrvalues.Two
Propertiesinstances compare equal iff both their key-value pairs anddefaultsattributes are equal. When comparing aPropertiesinstance to any other type of mapping, only the key-value pairs are considered.Changed in version 0.5.0:
Propertiesinstances can now compare equal todicts and other mapping types- Parameters:
data (mapping or
None) – A mapping or iterable of(key, value)pairs with which to initialize thePropertiesinstance. All keys and values indatamust be text strings.defaults (Optional[Properties]) – a set of default properties that will be used as fallback for
getProperty
- copy() Properties[source]
Added in version 0.5.0.
Create a shallow copy of the mapping. The copy’s
defaultsattribute will be the same instance as the original’sdefaults.
- defaults
A
Propertiessubobject used as fallback forgetProperty. OnlygetProperty,propertyNames,stringPropertyNames, and__eq__use this attribute; all other methods (including the standard mapping methods) ignore it.
- getProperty(key: str, defaultValue: T | None = None) str | T | None[source]
Fetch the value associated with the key
keyin thePropertiesinstance. If the key is not present,defaultsis checked, and then itsdefaults, etc., until either a value forkeyis found or the nextdefaultsisNone, in which casedefaultValueis returned.- Parameters:
key (str) – the key to look up the value of
defaultValue (Any) – the value to return if
keyis not found in thePropertiesinstance
- Return type:
str (if
keywas found)
- load(inStream: IO) None[source]
Update the
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 anInvalidUEscapeErrorto be raised- Parameters:
inStream (IO) – the file from which to read the
.propertiesdocument- Returns:
- Raises:
InvalidUEscapeError – if an invalid
\uXXXXescape sequence occurs in the input
- loadFromXML(inStream: IO) None[source]
Update the
Propertiesinstance with the entries in the XML properties fileinStream.Beyond basic XML well-formedness,
loadFromXMLonly checks that the root element is namedpropertiesand that all of itsentrychildren havekeyattributes; no further validation is performed.- Parameters:
inStream (IO) – the file from which to read the XML properties document
- Returns:
- Raises:
ValueError – if the root of the XML tree is not a
<properties>tag or an<entry>element is missing akeyattribute
- propertyNames() Iterator[str][source]
Returns a generator of all distinct keys in the
Propertiesinstance and itsdefaults(and itsdefaults’sdefaults, etc.) in unspecified order- Return type:
Iterator[str]
- store(out: TextIO, comments: str | None = None) None[source]
Write the
Propertiesinstance’s entries (in unspecified order) in.propertiesformat toout, including the current timestamp.