4

I'm having a problem with the Python string.find() method. It seems to work just fine this way:

 p = mystr.find('id=')

It correctly returns the first match.

However, when I try to use the format with other arguments, like:

 p2 = mystr.find('id=', start=p+3)

It reports that: find() not take keyword arguments

I'm not sure what's going on here.

2
  • Thanks, @Robᵩ but I beg to differ. I asked this question because there is no straight solution in that any other questions. The answer of this question is more useful, right? Dec 19, 2013 at 16:51
  • Aside: your title is incorrect. string.find() does take keyword arguments, as your own answer indicates. str.find() does not take keyword arguments, as the question points out.
    – Robᵩ
    Dec 19, 2013 at 17:26

2 Answers 2

2

Don't use start, directly give p+3 like this

p2 = mystr.find('id=', p+3)

For example,

p = "id=id=1"
i = p.find("id=")
print p.find("id=", i + 3)

would print 3

0
1

I did not find where goes wrong, but I found a solution for this problem:-)

Just use find() in another way, like:

 import string as st
 p2 = st.find(mystr, 'id=', start=p+3)

works great :-)

1

Not the answer you're looking for? Browse other questions tagged or ask your own question.