PandaX007 2022-03-05 20:59 采纳率: 100%
浏览 11
已结题

为什么python如下代码中find_index总是执行else语句部分

问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果

-- 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.

  • 写回答

1条回答 默认 最新

  • 陈年椰子 2022-03-05 22:45
    关注

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 3月14日
  • 已采纳回答 3月6日
  • 创建了问题 3月5日

悬赏问题

  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 YOLOv8obb获取边框坐标时报错AttributeError: 'NoneType' object has no attribute 'xywhr'