5

I'm writing a Sublime2 plugin and fighting a bit.

Code is:

  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

Output is:

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

How is it I get 'str' object has no attribute 'slice' ? (Python version is 2.6)

2
  • 3
    Don't you mean 'split' ? Commented Nov 27, 2012 at 0:38
  • 2
    I think you normally slice like "asdasd"[1:3] ... ahh I think bradley.ayers got it ... I didnt figure it out :( Commented Nov 27, 2012 at 0:39

2 Answers 2

8

Strings don't have a slice method in Python - did you mean split (or some variation thereof, such as rsplit)?

Sign up to request clarification or add additional context in comments.

2 Comments

Silly me... signal to tell it's time to go to bed I guess
Same here. Too much JS in my life
0

$slice() method doesn't works with pandas.Series so first we have to convert it into StringMethods by using .str then we can apply slice notation.

s=pd.Series(["2020", "2010", "2013"]) s 0 2020 1 2010 2 2013 dtype: object s.slice() # doesn't work s.str.slice(2,4).astype(int) 0 20 1 10 2 13 dtype: int32

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.