问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
-- coding: utf-8 --
"""
Created on Sat Mar 5 11:33:51 2022
@author: Administrator
"""
class pxcheck:
def init(self):
pass
def check_exist(self,path,mark):
if type(path)==str and type(mark)==str:
decision=mark in path
print('Is the mark in the path string:',decision)
return(decision)
else:
print('Please input path and mark in string!')
def find_index(self,path,mark):
if type(path)==str and type(mark)==str:
decision=self.check_exist(path,mark)
if decision:
index=0
index_set=[]
for each_mark in path:
index+=1
if each_mark==mark:
temp_index=index-1
index_set.append(temp_index)
return(index_set)
else:
print('There is no mark %s here.'%mark)
else:
print('Please input path and mark in string!')
def check_suffix(self,path):
if type(path)==str:
index_set=self.find_index(path,mark='.')
length=len(index_set)
index=index_set[length-1]+1
length1=len(path)
suffix=path[index:length1]
return(suffix)
if name=='main':
a=pxcheck()
testpath=r'www.http.xls'
a.find_index(testpath,'.')
testsuffix=a.check_suffix(testpath)
运行结果:a.find_index(testpath,'.')
There is no mark . here.