Hi All,

I am using the .search function.

strValue="XXX"
strTemp1="YYYXXX"
strTemp= strTemp1.search(strValue)

Python is not able to recognise the .search function.
AttributeError: 'str' object has no attribute 'search'

What should I import for this?
Please help!

Recommended Answers

All 2 Replies

Python is not able to recognise the .search function.
AttributeError: 'str' object has no attribute 'search'

yes...that would be the response
to find the available methods for string class..try help(string) at the python prompt...
that shud help

Peace...

If you want to just find out if one string is contained inside another:

strvalue1 in strvalue2

If you want to find out how many occurrences of one string there are in another:

num = strvalue.count(strvalue2)

If you want to find the index of the first occurrence of one string in another:

ind = strvalue1.find(strvalue2)
commented: nice help +12
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.