Advertisement
Guest User

Untitled

a guest
Jun 17th, 2023
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. import os
  2.  
  3. home_dir = os.path.expanduser("~")
  4.  
  5. conf_dir = "python-course-home-dir-conf"
  6. conf_dir_path = os.path.join(home_dir, conf_dir)
  7. os.makedirs(conf_dir_path, exist_ok=True)
  8.  
  9. conf_file_name = "message.conf"
  10. conf_file_path = os.path.join(conf_dir_path, conf_file_name)
  11. print(conf_dir_path)
  12.  
  13. DEFAULT_MESSAGE = "Change me!"
  14. if os.path.exists(conf_file_path):
  15.     with open(conf_file_path) as msg_file:
  16.         message = msg_file.read()
  17.         print(f"Configured message: {message}")
  18. else:
  19.     with open(conf_dir_path, "w") as msg_file:
  20.         msg_file.write(DEFAULT_MESSAGE)
  21.         print(f"Message set!")
  22.  
  23.  
  24.  
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement