0

I'm writing a script where by a user registers his/her username, but a function checks whether this username is already in the db or not. But I'm stuck on how to match my query with the input. Here is the code:

def checker(self, insane):                                                  
        t = (insane,)                                                           
    cmd = "SELECT admin_user FROM admin_db where admin_user = \"%s\";" %t
    self.cursor.execute(cmd)
    namer = self.cursor.fetchone()
    print namer
    if namer == insane:                                                     
        print("Username is already chosen!")
        exit(1)
    else:
        pass

Since

namer
returns as
(u'maverick',)
It doesn't match with the input. How should I go about implementing that?

1 Answer 1

1

The DB fetch models return a tuple for each row. Since you've only selected a single field, you can simply access namer[0] to get the actual value.

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

1 Comment

aha, didn't know that. Got what I wanted. Thanks! [answer accepted] ;)

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.