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.

treddy
  • 2,771
  • 2
  • 18
  • 31
Haohan Wang
  • 607
  • 2
  • 9
  • 25
  • 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? – Haohan Wang Dec 19 '13 at 16:51
  • *Aside*: your title is incorrect. [`string.find()`](http://docs.python.org/2/library/string.html#string.find) **does** take keyword arguments, as your own answer indicates. [`str.find()`](http://docs.python.org/2/library/stdtypes.html#str.find) **does not** take keyword arguments, as the question points out. – Robᵩ Dec 19 '13 at 17:26

2 Answers2

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

thefourtheye
  • 233,700
  • 52
  • 457
  • 497
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 :-)

Haohan Wang
  • 607
  • 2
  • 9
  • 25