Python 3 replacement for java.util.Properties (via pyjavaproperties)

0.7 · abandoned · verified Sun Apr 12

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

Install

Imports

Quickstart

Demonstrates loading, accessing, modifying, and listing properties from a Java-style .properties file.

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')

view raw JSON →