import os def open_all(): """open_all() → [file(rb)] Open the default sshwot files""" try: homedir = os.environ['HOME'] except KeyError as err: raise KeyError('$HOME is not set') from err # If the directory doesn't exist, just return empty sshwot_dir_path = os.path.join(homedir, '.sshwot') try: sshwot_dir = os.listdir(sshwot_dir_path) except FileNotFoundError: return [] # Read all the .sshwot files from /.sshwot by default files = [] for dir_entry in sshwot_dir: if dir_entry.split('.')[-1] == 'sshwot': path = os.path.join(sshwot_dir_path, dir_entry) files.append(open(path, 'rb')) return files