Python 3 replacement for java.util.Properties (via pyjavaproperties)
This library, identified by the PyPI name `pyjavaproperties`, provides a Python 3 compatible replacement for Java's `java.util.Properties` class, enabling basic parsing and manipulation of Java Properties files. It is a fork of an ASPN recipe and aimed for cross-compatibility with Python 2 and Python 3. The project has not seen updates since early 2019.
Warnings
- breaking The package name 'pyjavaproperties3' at version '0.6' as specified in the prompt does not appear to exist on PyPI. This entry refers to 'pyjavaproperties' version '0.7', which matches the provided summary and is the most likely intended package. Attempting to install `pyjavaproperties3` will fail.
- gotcha The library internally uses Python 2 string types, which means proper Unicode support is still missing and can lead to issues with non-ASCII characters in Python 3 environments.
- gotcha The project appears to be unmaintained. The last release on PyPI was in January 2019, indicating that there will be no further updates, bug fixes, or security patches.
- gotcha For new projects or if robust maintenance and full Unicode support are critical, consider the `javaproperties` library (e.g., `pip install javaproperties`), which offers a more actively maintained and feature-rich solution for handling Java .properties files.
Install
-
pip install pyjavaproperties
Imports
- Properties
from pyjavaproperties import Properties
Quickstart
from pyjavaproperties import Properties
import os
# Create a dummy properties file for demonstration
with open('test.properties', 'w') as f:
f.write('name1=value1\n')
f.write('name2=value2 with spaces\n')
f.write('name3=another value\n')
p = Properties()
# Load properties from a file
with open('test.properties', 'r') as f:
p.load(f)
print("Loaded properties:")
p.list()
# Access properties
print(f"Value of name3: {p['name3']}")
# Modify and add properties
p['name3'] = 'changed = value'
p['new key'] = 'new value with = sign'
print("\nModified properties:")
print(p)
# To save properties to a file (optional)
# with open('output.properties', 'w') as f:
# p.store(f, 'Generated by pyjavaproperties')
# Clean up dummy file
os.remove('test.properties')