How to test if a file is a symbolic link?

Peng Yu pengyu.ut at
Thu Oct 29 04:19:55 CET 2009

'symbolic_link' is a symbolic link in the current directory. I run
'python', but it does not return me anything. I want to check
if a file is a symbolic link. I'm wondering what is the correct way to
do so?

import stat
import os

st = os.stat('symbolic_link')
if stat.S_ISLNK(st.st_mode):
  print "Hello"

More information about the Python-list mailing list