在 Python 中使用设置文件的最佳实践是什么? [关闭] - What's the best practice using a settings file in Python? [closed]

问题:

Closed . 关闭 This question needs to be more focused . 这个问题需要更加集中 It is not currently accepting answers. 它目前不接受答案。

Want to improve this question?想改善这个问题吗? Update the question so it focuses on one problem only by editing this post .更新问题,使其仅通过编辑这篇文章来关注一个问题。

Closed 3 years ago . 3年前关闭。

I have a command line script that I run with a lot of arguments.我有一个带有很多参数的命令行脚本。 I have now come to a point where I have too many arguments, and I want to have some arguments in dictionary form too.我现在已经到了我有太多论点的地步,我也想以字典的形式有一些论点。

So in order to simplify things I would like to run the script with a settings file instead.所以为了简化事情,我想用一个设置文件来运行脚本。 I don't really know what libraries to use for the parsing of the file.我真的不知道使用哪些库来解析文件。 What's the best practice for doing this?这样做的最佳做法是什么? I could of course hammer something out myself, but if there is some library for this, I'm all ears.我当然可以自己敲出一些东西,但如果有一些图书馆,我会全神贯注。

A few 'demands':几个“要求”:

  • Rather than using pickle I would like it to be a straight forward text file that can easily be read and edited.我不希望使用pickle而是希望它是一个易于阅读和编辑的直接文本文件。
  • I want to be able to add dictionary-like data in it, ie, some form of nesting should be supported.我希望能够在其中添加类似字典的数据,即应该支持某种形式的嵌套。

A simplified pseudo example file:一个简化的伪示例文件:

truck:
    color: blue
    brand: ford
city: new york
cabriolet:
    color: black
    engine:
        cylinders: 8
        placement: mid
    doors: 2

解决方案:

参考一: https://stackoom.com/question/LD2w
参考二: What's the best practice using a settings file in Python? [closed]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章