Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中使用index()需要导入什么?_Python - Fatal编程技术网

在python中使用index()需要导入什么?

在python中使用index()需要导入什么?,python,Python,我打电话是跟在funtion后面 import clr import System import ServiceDesk import BaseModel class Model(BaseModel.Model): def ExecuteCustomAction(self,args,env): resault = self.account.ExecuteService('service',args,env) re

我打电话是跟在funtion后面

    import clr
    import System
    import ServiceDesk
    import BaseModel
    class Model(BaseModel.Model):
      def ExecuteCustomAction(self,args,env):
        resault = self.account.ExecuteService('service',args,env)
        res = {}
        if resault.Count>0:
            for customaction in resault.Rows:
                CustomActions = customaction['CustomActions']
                if CustomActions !="":
                    Lable = self.find_between( CustomActions, "Lable", "d" )
                    CallBack = self.find_between( CustomActions, "CallBack", ";" )
                    Action = self.find_between( CustomActions, "Action", "f" )
                    res['Lable'] = Lable
                    res['CallBack'] = CallBack
                    res['Action'] = Action
        return res

    def find_between( text, first, last ,self):
        try:
            start = text.index( first ) + len( first )
            end = text.index( last, start )
            return text[start:end]

        except ValueError:
            return ""
但当我执行这个时,它说

对象没有属性“index”


需要导入什么?

当您传递不正确的
文本值时,将出现此错误<代码>文本
这里必须是一个字符串,索引方法才能工作。例如:

>>> def find_between( text, first, last ,self):
...     try:
...         start = text.index( first ) + len( first )
...         end = text.index( last, start )
...         return text[start:end]
...     except ValueError:
...         return ""
... 
>>> find_between("some_string", "s", "t", None)
'ome_s'

>>> find_between(123, "s", "t", None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in find_between
AttributeError: 'int' object has no attribute 'index'

>>> find_between(None, "s", "t", None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in find_between
AttributeError: 'NoneType' object has no attribute 'index'

您如何调用该函数?也请附加那个代码。没什么,但不管“text”是什么,它都没有方法“index”。它可能不是你想象的那样。你不需要导入任何东西;您需要传递一个具有方法
index
的对象。我插入了完整的代码。那么
CustomActions
到底是什么…?
def find_between(self, text, first, last):