AttributeError: 'str' 对象没有属性 'slice'

apn*_*ing 3 python

我正在编写一个 Sublime2 插件并且有点挣扎。

代码是:

  def run(self, edit):
    self.edit            = edit
    self.view.window().show_input_panel("New Controller and View Path (ex: client_area/index )", "", self.trigger, None, None)

  def trigger(self, user_entry):
    formatted_entry = user_entry.encode('utf-8')
    print formatted_entry.__class__
    print formatted_entry
    if formatted_entry.slice('/')[0] == '':
      #some code
Run Code Online (Sandbox Code Playgroud)

输出是:

<type 'str'>
client_area/index
Traceback (most recent call last):
  File "./PluginName.py", line 27, in trigger
AttributeError: 'str' object has no attribute 'slice'
Run Code Online (Sandbox Code Playgroud)

我怎么了'str' object has no attribute 'slice'?(Python 版本为 2.6)

ars*_*jii 7

字符串slice在 Python 中没有方法 - 您的意思是split(或其一些变体,例如rsplit)?

  • 我真傻……我猜是在示意该睡觉了 (2认同)