2012-11-27 100 views
1

我正在寫一個Sublime2插件並打了一下。AttributeError:'str'對象沒有屬性'切片'

代碼是:

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 

輸出是:

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

它是如何我得到'str' object has no attribute 'slice'? (Python版本爲2.6)

+3

難道你不是指「分裂」? –

+1

我認爲你通常會像''asdasd'[1:3]'切片一樣......我認爲bradley.ayers得到了它......我沒有想到它:( –

回答

3

字符串在Python中沒有slice方法 - 你的意思是split(或其某些變體,如rsplit)?

+0

愚蠢的我......信號告訴它是時候我想要去睡覺 – apneadiving