Python – Range()


I’m new to Python, I have tried to create a simple loop in order for me to list users that has userID of value integer. However the userID on the DB seems weird (Users 1-72 are displayed properly, next to 72 is 712 already), so I need to skip those users who does not have any userID 73-711. What exception must be done or do I need to create a simple if else?

for iD in range(1, 720):
        loginID = iD
        for users in tls.getUserByID(loginID):
            fname = users.get('firstName')
            lname = users.get('lastName')
            print(loginID, fname +" "+ lname)

The error I’m getting is..

raise testlinkerrors.TLResponseError(
testlink.testlinkerrors.TLResponseError: NO_USER_BY_ID_LOGIN: (getUserByID) - Cannot Find User with DB ID (73)


You can try this @ckmb

     for iD in range(60, 720):
        if iD not in [* range(73, 712)]:
            loginID = iD
                api_getUser = tls.getUserByID(loginID)
                for user in api_getUser:
                  fname = user.get('firstName')
                  lname = user.get('lastName')
                  print(loginID, fname + " " + lname)
            except testlinkerrors.TLResponseError:
                print(loginID, "not found")

Answered By – kodemetrics

Answer Checked By – Cary Denson (AngularFixing Admin)

Leave a Reply

Your email address will not be published.