I have the following code inside a try/except block:
if current_path is not None and isinstance(current_path, str) and os.path.exists(current_path):
os.chdir(current_path)
Under normal circumstances this works fine, however if the code fails before current_path gets assigned I get an error saying it's referenced before assignment. The first condition in the if statement is to check that it gets assigned or not, I was under the assumption that if the first condition is false, i will always get false is this not the case?
Any suggestions as to how to do this better? My only other thought would be a nested if statement. Any suggestions would be appreciated.