I've been reading that you shouldn't just use 'pass' when using try/except in python. I have a couple of situations where I use it in:
source = os.listdir("../myprogdir") # directory where original configs are located
destination = '//' + servername + r'/c$/remotedir/' # destination server directory
for files in source:
if files.endswith("myconfig.exe.config"):
try:
os.makedirs(destination, exist_ok=True)
shutil.copy(files,destination)
except:
pass
and
source = r'//' + servername + '/c$/remotedir/'
dest = r"../myprogdir"
file = "myconfig.exe.config"
if os.path.isfile(os.path.join(source, file)): # isfile checks if filename already exists on remote computer
try:
shutil.copyfile(os.path.join(source, file), os.path.join(dest, file))
except:
print (" Local directory you are copying to does not exist.")
else:
print (" ...filename does not exist...")
The thing is, I am using these in functions where I run through multiple computers in a list that I have. If I throw an error such as a computer being down/turned off or a directory/filename does not exist, I just want to skip over it into the next computer name on my list.
So is it ok to use pass in this situation? I guess something could happen if the user running my program does not have permission to perform some of the functions.
What situations would I need to use proper exception handling?
How can I write out a permissions exception error? That is the only thing that might cause a problem with the program. Even though the only people running the program should have proper permissions anyways.