第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

python 判斷文件是文件還是文件夾

python 判斷文件是文件還是文件夾

qq_笑_17 2019-06-07 13:06:24
python 判斷文件是文件還是文件夾
查看完整描述

3 回答

?
一只甜甜圈

TA貢獻1836條經(jīng)驗 獲得超5個贊

在os.path模塊中有個isfile的方法,該方法可以判斷是不是文件,返回True說明是文件,返回False則不是文件,下面的英文是摘自python文檔

os.path.isfile(path)

Return True if path is an existing regular file. This follows symbolic links, so both islink() and isfile() can be true for the same path.

用法也很簡單

1

2

3

import os

filename='/tmp/test.txt'

print os.path.isfile(filename)


 


查看完整回答
反對 回復 2019-06-08
?
慕俠2389804

TA貢獻1719條經(jīng)驗 獲得超6個贊

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

>>> import os.path

>>> help(os.path.isfile)

Help on function isfile in module genericpath:

 

isfile(path)

    Test whether a path is a regular file

 

>>> help(os.path.isdir)

Help on function isdir in module genericpath:

 

isdir(s)

    Return true if the pathname refers to an existing directory.

 

>>> os.path.isfile('/etc/hostname')

True

>>> os.path.isdir('/etc/hostname')

False

>>> 

兩個函數(shù)都在os.path模塊里面。參見上文。

 


查看完整回答
反對 回復 2019-06-08
  • 3 回答
  • 0 關(guān)注
  • 4555 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號