【发布时间】:2017-08-27 05:21:39
【问题描述】:
我有一个简单的 python dict,它以以下格式打印,
{'stats1': {'var': {'avail': 'yes'}, 'target': {'avail': 'no'}}}
但我正在寻找以以下格式打印此内容的方法,例如 ruby hash,
{'stats1'=> {'var'=> {'avail'=> 'yes'}, 'target'=> {'avail'=> 'no'}}}
我尝试 Google 以获取以 ruby 哈希格式打印 python dict 的方法,但没有运气。
【问题讨论】:
-
你能告诉我们你到目前为止的尝试吗?
-
对于它的价值:
{'stats1': {'var': {'avail': 'yes'}, 'target': {'avail': 'no'}}}已经是一个有效的 Ruby 哈希,用符号作为键。它显示为{:stats1=>{:var=>{:avail=>"yes"}, :target=>{:avail=>"no"}}}
标签: python ruby dictionary hash