Movatterモバイル変換
[0]ホーム
[Python-Dev] Returning Windows file attribute information viaos.stat()
Ben Hoytbenhoyt at gmail.com
Tue Jun 10 14:19:54 CEST 2014
> > FILE_ATTRIBUTE_HIDDEN = 2 # constant defined in Windows.h> >> > if hasattr(st, 'st_winattrs') and st.st_winattrs & FILE_ATTRIBUTE_HIDDEN:>> I don't like such API, it requires to import constants, use masks, etc.>> I would prefer something like:>> if st.win_hidden: ...>> Or maybe:>> if st.winattrs.hidden: ...Yes, fair call. However, it looks like the precent for the attributesin os.stat()'s return value has long since been set -- this isOS-specific stuff. For example, what's in "st_flags"? It's notdocumented, but comes straight from the OS. Same with st_rdev,st_type, etc -- the documentation doesn't define them, and it lookslike they're OS-specific values.I don't think the st.win_hidden approach gains us much, because thenext person is going to ask for the FILE_ATTRIBUTE_ENCRYPTED orFILE_ATTRIBUTE_COMPRESSED flag. So we really need all the bits ornothing. I don't mind the st.st_winattrs.hidden approach, except thatwe'd need 17 sub-attributes, and they'd all have to be documented. Andif Windows added another attribute, Python wouldn't have it, etc. So Ithink the OS-defined constant is the way to go.Because these are fixed-forever constants, I suspect in library codeand the like people would just KISS and use an integer literal and acomment, avoiding the import/constant thing: if getattr(st, 'st_winattrs', 0) & 2: # FILE_ATTRIBUTE_HIDDEN ...-Ben
More information about the Python-Devmailing list
[8]ページ先頭