jason
jason

Reputation: 3075

HTTP_USER_AGENT script

Can someone explain this script?

 device = {}

    ua = request.META.get('HTTP_USER_AGENT', '').lower()

    if ua.find("iphone") > 0:
        device['iphone'] = "iphone" + re.search("iphone os (\d)", ua).groups(0)[0]

I know it gets the user agent and the first bit searches the string for iphone. but

why > 0? and what is the second like doing?

Upvotes: 0

Views: 316

Answers (1)

user823738
user823738

Reputation: 17521

I am not a python guy but I am almost sure that .find() returns position where the string "iphone" occurs.

So if it was found, it will be >= 0.

Upvotes: 1

Related Questions