当我加载文件时,'\ n'自动转换为'\\ n'。 我可以获得原始字符串吗?或者你有什么想法吗?
setting.yaml:
before : '\n'
after : ''
源:
with open(r"C:\setting.yaml", 'r', encoding='utf-8') as text:
print(text)
raw_yml = yaml.load(text)
before = raw_yml.get("before") # '\\n'
after = raw_yml.get("after") # ''
sample_str = "\n\n\txxxx\n\n"
result = sample_str.replace(before, after)
# I want to get "\txxxx", but "\n\n\txxxx\n\n" was printed.
print(result)