79291439

Date: 2024-12-18 14:35:07
Score: 4
Natty:
Report link

Why not just try to make the path and then check it?

def path_type(my_path):
    if os.path.exists(my_path):
        return 'dir'
    else:
        try:
            p = os.path.makedirs(my_path)
            os.remove(p)
            return 'dir'
        except:
            pass
        return 'file'
Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Unregistered user (0.5):
  • Starts with a question (0.5): Why not
  • Low reputation (1):
Posted by: Luke