1樓:python酷
除了使用異常捕捉之外,我提供乙個不同的方法,使用importlib庫中的find_spec
from
importlib.util
import
find_spec
has_lib
=find_spec
("lib_name")
2樓:璃墨Limour
importos,
resep=re
.compile(r
'\s+'
)def
_sep(s
):s=sep
.sub
(' ',s
).strip
()returns.
split
(' '
)def
getDict
():alllib=os
.popen
('pip3 list').
read
()alist
=alllib
.splitlines
()assert
len(
alist
)>2,
alllib
alist
=alist
.__iter__
()assert
next
(alist).
startswith
('Package'
),alllib
assert
next
(alist).
startswith
('---'
),alllib
return
dict
(map
(_sep
,alist
))def
keepInstalled
(libset
):libdict
=getDict
()for
libin
libset:if
libnot
inlibdict
:print(os
.popen(f
"pip3 install ")
.read())
python如何判斷stdin裡面是否有資料?
呵呵一笑百媚生 fcntl import osimport sys 非阻塞模式fd sys.stdin fileno fl fcntl fcntl fd fcntl F GETFL fcntl fcntl fd fcntl F SETFL,fl os.O NONBLOCK try for line ...
怎麼用Python判斷閏年和平年
閏年 Leap Year 是為了彌補因人為曆法規定造成的年度天數與地球實際公轉週期的時間差而設立的,補上時間差的年份為閏年,閏年共有366天 閏年是曆法中的名詞,分為普通閏年和世紀閏年。1582年以來設定閏年的規則 普通閏年 公曆年份是4的倍數,且不是100的倍數的,為閏年 如2004年 2020年...
python 如何判斷某一列的數值是否連續
In 27 import functools In 28 check add one lambda arr functools.reduce lambda x,y x 1 y if isinstance x,int else x 0 and x 1 1 y,y arr 0 In 29 check a...