首页
学习
活动
专区
圈层
工具
发布

python 测试文件

os.path.exists

isfile isdir islink

import os os.path.exists('/etc/passwd') True os.path.exists('/tmp/spam') False

Is a regular file os.path.isfile('/etc/passwd') True

Is a directory os.path.isdir('/etc/passwd') False

Is a symbolic link os.path.islink('/usr/local/bin/python3') True

Get the file linked to os.path.realpath('/usr/local/bin/python3') '/usr/local/bin/python3.3'

os.path.getsize('/etc/passwd') 3669 os.path.getmtime('/etc/passwd') 1272478234.0 import time time.ctime(os.path.getmtime('/etc/passwd')) 'Wed Apr 28 13:10:34 2010'

下一篇
举报
领券