Mar-31-2018, 12:34 AM
i wrote a function two different ways. can someone tell me which is better and why?
edit
in case it mattered to you and you didn't figure it out, p is class Path from pathlib.
def pathftn(p,unknown='?'): if p.is_symlink: return 'l' if p.is_block_device: return 'b' if p.is_char_device: return 'c' if p.is_dir: return 'd' if p.is_file: return 'f' if p.is_socket: return 's' if p.is_fifo: return 'p' return unknown
def pathftn(p,unknown='?'): t=unknown if p.is_symlink: t='l' elif p.is_block_device: t='b' elif p.is_char_device: t='c' elif p.is_dir: t='d' elif p.is_file: t='f' elif p.is_socket: t='s' elif p.is_fifo: t='p' return tor do you have a better idea?
edit
in case it mattered to you and you didn't figure it out, p is class Path from pathlib.