#coding:utf-8 #pip install pyyaml import yaml import os desired_caps = { 'platformName': 'Android', 'platformVersion': '7.0', 'deviceName': 'ASRNW1111111111', 'appPackage': 'com.tencent.com', 'appActivity': 'ui.LauncherUI', 'automationName': 'Uiautomator2', 'unicodeKeyboard': True, 'resetKeyboard': True, 'noReset': True, 'chromeOptions': {'androidProcess': 'com.tencent.com'} } curpath = os.path.dirname(os.path.realpath(__file__)) yamlpath = os.path.join(curpath, "cfgyaml.yaml") def read_yml(file=yamlpath): with open(file, 'r', encoding='utf-8') as f: return yaml.load(f.read(), Loader=yaml.FullLoader) def write_yml(file,data): with open(file, 'w', encoding="utf-8") as f: yaml.dump(data=data, stream=f,allow_unicode=True) if __name__ == "__main__": write_yml(yamlpath,desired_caps) result = read_yml() print(result) #{'appActivity': 'ui.LauncherUI', 'appPackage': 'com.tencent.com', 'automationName': 'Uiautomator2', 'chromeOptions': {'androidProcess': 'com.tencent.com'}, 'deviceName': 'ASRNW1111111111', 'noReset': True, 'platformName': 'Android', 'platformVersion': '7.0', 'resetKeyboard': True, 'unicodeKeyboard': True}