In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.