File size: 1,321 Bytes
a839836 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | import yaml
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--a', type=str, required=True)
args = parser.parse_args()
result = yaml.dump(yaml.safe_load(args.a), default_style='|') # 字面块样式
print(result)
# ==================================================
# Sample Test Cases (randomly selected)
# ==================================================
# ===== Test Case 1 =====
# Input:
# --a = '[apple, banana, cherry]'
# Output:
# - |-
# apple
# - |-
# banana
# - |-
# cherry
# Return Code: 0
# ===== Test Case 2 =====
# Input:
# --a = 'omap: !!omap\n - key1: value1\n - key2: value2\n - key3: value3'
# Output:
# "omap":
# - !!python/tuple
# - |-
# key1
# - |-
# value1
# - !!python/tuple
# - |-
# key2
# - |-
# value2
# - !!python/tuple
# - |-
# key3
# - |-
# value3
# Return Code: 0
# ===== Test Case 3 =====
# Input:
# --a = 'large: 1.23e10\nsmall: 5.67e-8'
# Output:
# "large": |-
# 1.23e10
# "small": !!float |-
# 5.67e-08
# Return Code: 0
# ===== Test Case 4 =====
# Input:
# --a = 'folded_block: >\n This is a folded\n string that will\n be on one line.'
# Output:
# "folded_block": |-
# This is a folded string that will be on one line.
# Return Code: 0
|