classification
Title: os.stat() 's inappropriate behavior when dealing with a broken link in linux systems.
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: hynek, maliubiao@gmail.com, r.david.murray
Priority: normal Keywords:

Created on 2012-07-26 21:03 by maliubiao@gmail.com, last changed 2012-07-27 06:17 by hynek. This issue is now closed.

Messages (3)
msg166519 - (view) Author: coder.maliubiao (maliubiao@gmail.com) Date: 2012-07-26 21:03
the code:
import os,stat
mode=os.stat("a broken link file").st_mode
then i got :OSError: [Errno 2] No such file or directory.

why not just treat a broken link as something existing and don't report any error.
msg166533 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-07-27 02:23
Because we are doing what the linux stat call (and command) does .  See man stat.
msg166543 - (view) Author: Hynek Schlawack (hynek) * (Python committer) Date: 2012-07-27 06:17
For the sake of completeness: what you're looking for is os.lstat.
History
Date User Action Args
2012-07-27 06:17:19hyneksetnosy: + hynek
messages: + msg166543
2012-07-27 02:23:28r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg166533

resolution: not a bug
stage: resolved
2012-07-26 21:03:20maliubiao@gmail.comcreate