pyyaml

    1熱度

    1回答

    我有一個python函數,它將打開一個YAML文件並讀取數據。 YAML文件包含兩個API鍵和一個域。我想在字典中返回每個值,以便可以在程序中使用它。但是我得到錯誤 「列表索引必須是整數,而不是str」。 我應該做的變量全球性的,所以它沒有返回任何東西? 的代碼是: def ImportConfig(): with open("config.yml", 'r') as ymlfile:

    2熱度

    1回答

    我有YAML文件site.yaml: Kvm_BLOCK: ip_address: 10.X.X.X property: null server_type: zone 加載,然後用甩: ruamel.yaml.dump(site_yaml, new_file, Dumper=ruamel.yaml.RoundTripDumper) 成爲 Kvm_BLOCK:

    1熱度

    1回答

    我正在嘗試爲我的類編寫正確的from_yaml方法,以便在使用ruamel.yaml庫加載YAML文件時能夠反序列化回到它。 讓我們假設,在我的to_yaml類的方法,我回來是這樣的:現在在反序列化方法 @classmethod def from_yaml(cls, constructor, node): dict_representation = constructor.constr

    0熱度

    1回答

    我有我的啓用密碼設置爲無。基本上我只需按回車即可在提示輸入密碼時訪問我的啓用模式。我如何在yaml中配置它?

    0熱度

    1回答

    我有一個示例YAML文件,我無法使用PyYAML庫解析它。 setup.yml: key: HostName deviceid: port1 Python代碼 with open('../configs/setup.yml') as stream: try: print 'yaml.data ==', yaml.load(stream) print 'yam

    2熱度

    1回答

    我想創建一個YAML過濾器讀取YAML文件,處理它事後轉儲它。 必須解決所有的別名(即很好的工作已經開箱): >>> yaml.dump(yaml.load(""" Foo: &bar name: bar Foo2: <<: *bar """)) 'Foo: {name: bar}\nFoo2: {name: bar}\n' 但它也應保留任何​​表達,如: >>>

    3熱度

    1回答

    ruamel.yaml.RoundTripRepresenter.add_representer(type(None), represent) 工作正常 如何在舊版本使用相同的功能(< = 0.11)ruamel.yaml軟件包還是以前版本的軟件包使用的替代方法? 我這裏是我的程序運行上面的代碼 def represent(self, data): return self.repre

    1熱度

    2回答

    最近我試圖用ruamel.yaml來管理我的docker-compose服務配置(即docker-compose.yml)。 我需要註釋掉&需要時取消註釋服務塊。假設我有以下文件: version: '2' services: srv1: image: alpine container_name: srv1 volumes: - som

    1熱度

    1回答

    我想在多行字符串中使用\n字符,但YAML不允許我使用\n字符。我如何使用\n字符。 我YAML: treeroot: branch1: name: > hello my friend\n how are you ? i am fine and you ?\n yes\nthanks branch1-1: n

    2熱度

    2回答

    我得到這個奇怪的問題,同時加載一個yaml文件與地址轉換爲數字的mac地址。 >>> yaml.safe_load('abc: 11:00:00:00:00:00') {'abc': 8553600000} >>> yaml.safe_load('abc: 99:00:00:00:00:00') {'abc': 76982400000} 但後來我嘗試了以下,我得到的答案如預期。 >>>