Guest User

Untitled

a guest
Oct 20th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. script_dir = os.path.dirname(__file__)
  2. file_path = os.path.join(script_dir, 'config.yaml')
  3.  
  4. with open(file_path, 'r') as stream:
  5. index = 'two'
  6. load = yaml.load(stream)
  7. USER = load[index]['USER']
  8. PASS = load[index]['PASS']
  9. HOST = load[index]['HOST']
  10. PORT = load[index]['PORT']
  11. ...
  12.  
  13. one:
  14. USER: "john"
  15. PASS: "qwerty"
  16. HOST: "127.0.0.1"
  17. PORT: "20"
  18. two:
  19. USER: "jane"
  20. PASS: "qwerty"
  21. HOST: "196.162.0.1"
  22. PORT: "80"
  23.  
  24. import yaml
  25. import os
  26.  
  27. script_dir = os.path.dirname(__file__)
  28. file_path = os.path.join(script_dir, 'config.yaml')
  29.  
  30. index = 'two'
  31.  
  32. with open(file_path, 'r') as stream:
  33. load = yaml.safe_load(stream)
  34.  
  35. for key in load[index]:
  36. globals()[key] = load[index][key]
  37.  
  38. print(USER)
  39. print(PORT)
Add Comment
Please, Sign In to add comment