我可以控制多行字符串的格式吗?

以下代码:

from ruamel.yaml import YAML
import sys, textwrap

yaml = YAML()
yaml.default_flow_style = False
yaml.dump({
    'hello.py': textwrap.dedent("""\
        import sys
        sys.stdout.write("hello world")
    """)
}, sys.stdout)

产生:

hello.py: "import sys\nsys.stdout.write(\"hello world\")\n"

有没有办法让它产生:

hello.py: |
    import sys
    sys.stdout.write("hello world")

而不是?

版本:

python: 2.7.16 on Win10 (1903)
ruamel.ordereddict==0.4.14
ruamel.yaml==0.16.0
ruamel.yaml.clib==0.1.0

转载请注明出处:http://www.0591kyj.com/article/20230526/1907073.html