gpt4 book ai didi

python - 属性错误 : 'str' object has no attribute 'slice'

转载 作者:太空宇宙 更新时间:2023-11-04 10:51:26 25 4
gpt4 key购买 nike

我正在编写一个 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

输出是:

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

最佳答案

字符串在 Python 中没有 slice 方法 - 你是说 split (或其某些变体,例如 rsplit )?

关于python - 属性错误 : 'str' object has no attribute 'slice' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13575622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com