In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
2025-10-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
The yaml module is used to process yaml files. Yaml is a lighter file format than xml and json. K8s cluster declares that the resource object is to use yaml files, and it is more convenient to use the yaml module to process yaml files.
Common methods of module
Dump: generates a python object as an yaml document
Load: returns an object
Dump_all:
Load_all:
Simple example demonstration
Load
Yaml_str1 = "" name: jackage: 25job: IT "" print (yaml_str1, type (yaml_str1)) contnet = yaml.load (yaml_str1) print (contnet, type (contnet))
Output
Name: jackage: 25job: IT {'name':' jack', 'age': 25,' job': 'IT'}
Dump
Import yamlyaml_str1 = "name: jackage: 25job: IT"print (yaml_str1, type (yaml_str1)) contnet = yaml.load (yaml_str1) print (contnet, type (contnet)) new_content = yaml.dump (contnet, open ('t1.yamlite,' wicked, encoding='utf-8'))
View the generated file
# generate the yaml file of nginx
Import yamlwith open ('nginx.yaml',' ritual, encoding='utf-8') as F1: content = yaml.load (F1) print (F1) with open ('nginxv2.yaml', 'walled, encoding='utf-8') as f2: yaml.dump (content, f2) # file stored after contnet object f2 generation
View the generated file
The generated file can be run
Multiple resource objects can be declared in the yaml file, using load_all
Import yamlwith open ('nginx_busy.yaml',' ritual, encoding='utf-8') as F1: content = yaml.load_all (F1) new_content = yaml.dump_all (content) print (new_content, type (new_content)) with open ('ng_busy.yaml', 'walled, encoding='utf-8') as f2: f2.write (new_content)
View the generated file
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.