输出字典到csv文件
我有一个以下格式的嵌套字典,用于国际化(这允许我们的翻译人员和非程序员根据需要编辑此文件;我的备份计划是使用 JSON 格式,但这不太适合这些用户。 )。
dict[LANGUAGE][KEY] = VALUE
我将其输出到以下格式的 csv 文件中:
KEY, VALUE-LANG-1, ... VALUE-LANG-N
其中 VALUE-LANG-I = dict[LANGUAGE-I][KEY]
只要 VALUE 是简单字符串,就可以正常工作。但是,如果 VALUE 更复杂(嵌套字典或列表),我会遇到问题。有没有办法稳健地处理这个问题?
I have a nested dictionary in the following format, used for internationalization (this allows our translators and non-programmers to edit this file as necessary; my backup plan is to use JSON format, but this would not be as suitable for these users..).
dict[LANGUAGE][KEY] = VALUE
I output this into a csv file in the following format:
KEY, VALUE-LANG-1, ... VALUE-LANG-N
where VALUE-LANG-I = dict[LANGUAGE-I][KEY]
This works fine, so long as the VALUEs are simple strings. I run into a problem, though, if the VALUE is anything more complex (a nested dict or a list). Is there a way to handle this robustly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在不知道要存储在那里的数据结构的确切细节(例如您提到的嵌套字典/列表)的情况下,很难建议适合非技术用户手动编辑的替代格式。
一个明显的建议是坚持使用计算机友好的格式并提供一个可用的 GUI 来编辑这些文件。
It is hard to suggest an alternative format suitable for manual editing by non-technical users without knowing the exact details of the data structures you want to store there (e.g. the nested dicts/lists that you mention).
One obvious suggestion is to stick with a computer-friendly format and provide a usable GUI for editing those files.