python 4-2 如何判断字符串a是否以字符串b开头或结尾
在当前目录下查找以sh或者以py结尾的文件名,并且将其权限修改成777
import os,stat
for filename in [ name for name in os.listdir(".") if name.endswith(("sh","py")) ]:
os.chmod(filename,os.stat(filename).st_mode | stat.S_IRWXU | stat.S_IRWXO | stat.S_IRWXG )
print os.stat(filename)
python 4-2.py
(33279, 12591688L, 51L, 1, 13350, 25, 0L, 1484961785, 1484961785, 1484965975)
(33279, 12591689L, 51L, 1, 13350, 25, 0L, 1484961787, 1484961787, 1484965975)
(33279, 12591690L, 51L, 1, 13350, 25, 0L, 1484961789, 1484961789, 1484965975)
(33279, 12591691L, 51L, 1, 13350, 25, 0L, 1484961793, 1484961793, 1484965975)
(33279, 12591692L, 51L, 1, 13350, 25, 0L, 1484961795, 1484961795, 1484965975)
(33279, 12591696L, 51L, 1, 13350, 25, 0L, 1484963413, 1484963413, 1484965975)
(33279, 12591698L, 51L, 1, 13350, 25, 225L, 1484965294, 1484965974, 1484965975)
help(str.startswith/str.endswith)
>>> help(str.startswith)
Help on method_descriptor:
startswith(...)
S.startswith(prefix[, start[, end]]) -> bool
Return True if S starts with the specified prefix, False otherwise.
With optional start, test S beginning at that position.
With optional end, stop comparing S at that position.
prefix can also be a tuple of strings to try.
>>> help(str.endswith)
Help on method_descriptor:
endswith(...)
S.endswith(suffix[, start[, end]]) -> bool
Return True if S ends with the specified suffix, False otherwise.
With optional start, test S beginning at that position.
With optional end, stop comparing S at that position.
suffix can also be a tuple of strings to try.
>>>