Skip to content

more and more backslashes when repeatedly dump and load #441

@Difocd

Description

@Difocd

When I dump something contains backslash to file and then load it, there are double backslashes. Like the below:

import toml

with open('test.toml', 'w', encoding='utf-8') as f:
    toml.dump({"c:\\test": {}}, f)

for _ in range(5):
    with open('test.toml', encoding='utf-8') as f:
        contents = toml.load(f)
    print(contents)
    with open('test.toml', 'w', encoding='utf-8') as f:
        toml.dump(contents, f)

This will print:

{'c:\\\\test': {}}
{'c:\\\\\\\\test': {}}
{'c:\\\\\\\\\\\\\\\\test': {}}
{'c:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\test': {}}
{'c:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\test': {}}

I don't know if this is a bug or just a feature. If this is a feature, how can I avoid this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions