Skip to content

Instantly share code, notes, and snippets.

@dhoss
Last active July 18, 2018 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhoss/1992a15366642adb75e6d459e665f185 to your computer and use it in GitHub Desktop.
Save dhoss/1992a15366642adb75e6d459e665f185 to your computer and use it in GitHub Desktop.
# I've tried both of these:
try:
for part in parts:
dirs = [dir for dir in os.listdir(path_to_check) if not isfile(os.path.join(path_to_check, dir))]
if "thing" in dirs:
return path_to_check
del path_parts[-1]
else:
raise ValueError("thing not found")
except ValueError as e:
print(e.value())
#############################
for part in parts:
dirs = [dir for dir in os.listdir(path_to_check) if not isfile(os.path.join(path_to_check, dir))]
if "thing" in dirs:
return path_to_check
del path_parts[-1]
else:
raise ValueError("thing not found")
# test
with self.assertRaises(ValueError):
self.stupid_function()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment