Less indentation

main
Bob Mottram 2024-07-02 20:55:58 +01:00
parent 80ea6cb86b
commit 76d0bcf3fd
1 changed files with 30 additions and 25 deletions

View File

@ -28,8 +28,13 @@ def set_pet_name(base_dir: str, nickname: str, domain: str,
# does this entry already exist? # does this entry already exist?
if os.path.isfile(petnames_filename): if os.path.isfile(petnames_filename):
with open(petnames_filename, 'r', encoding='utf-8') as petnames_file: petnames_str = ''
try:
with open(petnames_filename, 'r',
encoding='utf-8') as petnames_file:
petnames_str = petnames_file.read() petnames_str = petnames_file.read()
except OSError:
print('EX: set_pet_name unable to read ' + petnames_filename)
if entry in petnames_str: if entry in petnames_str:
return True return True
if ' ' + handle + '\n' in petnames_str: if ' ' + handle + '\n' in petnames_str:
@ -46,7 +51,7 @@ def set_pet_name(base_dir: str, nickname: str, domain: str,
encoding='utf-8') as petnames_file: encoding='utf-8') as petnames_file:
petnames_file.write(new_petnames_str) petnames_file.write(new_petnames_str)
except OSError: except OSError:
print('EX: unable to save ' + petnames_filename) print('EX: set_pet_name unable to save ' + petnames_filename)
return False return False
return True return True
# entry does not exist in the petnames file # entry does not exist in the petnames file
@ -55,7 +60,7 @@ def set_pet_name(base_dir: str, nickname: str, domain: str,
encoding='utf-8') as petnames_file: encoding='utf-8') as petnames_file:
petnames_file.write(entry) petnames_file.write(entry)
except OSError: except OSError:
print('EX: unable to append ' + petnames_filename) print('EX: set_pet_name unable to append ' + petnames_filename)
return False return False
return True return True