May-10-2024, 12:26 AM
which way would be better (WWWBB)?
1.
or...
2.
and why?
could performance be considered an issue? would you code this with more spacing? ...more lines?
1.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
from stat import S_ISREG,S_ISDIR,S_ISLNK,S_ISBLK,S_ISCHR from stat import S_ISFIFO,S_ISSOCK,S_ISPORT,S_ISDOOR,S_ISWHT def _get_type(a): """Get type of file object by path.""" try : s = os.stat(a) except FileNotFoundError: t = 'n' if S_ISREG(s.st_mode):t = 'f' elif S_ISDIR(s.st_mode):t = 'd' elif S_ISLNK(s.st_mode):t = 'l' elif S_ISBLK(s.st_mode):t = 'b' elif S_ISCHR(s.st_mode):t = 'c' elif S_ISFIFO(s.st_mode):t = 'p' elif S_ISSOCK(s.st_mode):t = 's' elif S_ISPORT(s.st_mode):t = 'P' elif S_ISDOOR(s.st_mode):t = 'D' elif S_ISWHT(s.st_mode):t = 'W' else t = '?' return t |
2.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
from stat import S_ISREG,S_ISDIR,S_ISLNK,S_ISBLK,S_ISCHR from stat import S_ISFIFO,S_ISSOCK,S_ISPORT,S_ISDOOR,S_ISWHT def _get_type(a): """Get type of file object by path.""" try : s = os.stat(a) t = '?' except FileNotFoundError: return 'n' if S_ISREG(s.st_mode): return 'f' elif S_ISDIR(s.st_mode): return 'd' elif S_ISLNK(s.st_mode): return 'l' elif S_ISBLK(s.st_mode): return 'b' elif S_ISCHR(s.st_mode): return 'c' elif S_ISFIFO(s.st_mode): return 'p' elif S_ISSOCK(s.st_mode): return 's' elif S_ISPORT(s.st_mode): return 'P' elif S_ISDOOR(s.st_mode): return 'D' elif S_ISWHT(s.st_mode): return 'W' return '?' |
could performance be considered an issue? would you code this with more spacing? ...more lines?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.