Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- script_dir = os.path.dirname(__file__)
- file_path = os.path.join(script_dir, 'config.yaml')
- with open(file_path, 'r') as stream:
- index = 'two'
- load = yaml.load(stream)
- USER = load[index]['USER']
- PASS = load[index]['PASS']
- HOST = load[index]['HOST']
- PORT = load[index]['PORT']
- ...
- one:
- USER: "john"
- PASS: "qwerty"
- HOST: "127.0.0.1"
- PORT: "20"
- two:
- USER: "jane"
- PASS: "qwerty"
- HOST: "196.162.0.1"
- PORT: "80"
- import yaml
- import os
- script_dir = os.path.dirname(__file__)
- file_path = os.path.join(script_dir, 'config.yaml')
- index = 'two'
- with open(file_path, 'r') as stream:
- load = yaml.safe_load(stream)
- for key in load[index]:
- globals()[key] = load[index][key]
- print(USER)
- print(PORT)
Add Comment
Please, Sign In to add comment