Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8684407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:18:01+00:00 2026-06-12T22:18:01+00:00

I have this python code in Tornado: if not usr: self.lock_tables(write, [‘devices_permissions’]) self.db.execute(INSERT devices_permissions

  • 0

I have this python code in Tornado:

if not usr:
    self.lock_tables("write", ['devices_permissions'])
        self.db.execute("INSERT devices_permissions SET user_id=%s, network_id=%s, device_id=%s, perm=%s",
                         usrid, netid, sensid, perm)
        self.unlock_tables();

    else:

      if perm == 0:
        self.lock_tables("write", ['devices_permissions'])
        self.db.execute("DELETE FROM devices_permissions \
                         WHERE user_id=%s AND device_id=%s", usrid, sensid)
        self.unlock_tables();


      else:
        self.lock_tables("write", ['devices_permissions'])
        self.db.execute("UPDATE devices_permissions SET perm=%s \
                         WHERE user_id=%s AND device_id=%s", perm, usrid, sensid)
        self.unlock_tables();

I have a problem with the second if…else statement. My program enter in the first else block, but in the second if…else seems not to work the if perm == 0 statement. I have print the perm variable and its value is 0. So I don’t know where sould be the error.

I want this if…else statement because I want delete from my DB the users that didn’t have anymore a permission on a device.

perm is a variable of value 0 or 1. usr is a list of user. Thank you very much.

EDIT

I change the statement in this way:

# Check whether the user has already priviledges on the device
    self.lock_tables("read", ['devices_permissions'])
    usr = self.db.get("SELECT device_id, user_id FROM devices_permissions \
                              WHERE user_id=%s AND device_id=%s", usrid, sensid)
    self.unlock_tables();

    if not usr:
    self.lock_tables("write", ['devices_permissions'])
        self.db.execute("INSERT devices_permissions SET user_id=%s, network_id=%s, device_id=%s, perm=%s",
                         usrid, netid, sensid, perm)
        self.unlock_tables();

    elif perm == 0:
        self.lock_tables("write", ['devices_permissions'])
        self.db.execute("DELETE FROM devices_permissions \
                         WHERE user_id=%s AND device_id=%s", usrid, sensid)
        self.unlock_tables();          

    else:
        self.lock_tables("write", ['devices_permissions'])
        self.db.execute("UPDATE devices_permissions SET perm=%s \
                         WHERE user_id=%s AND device_id=%s", perm, usrid, sensid)
        self.unlock_tables();

and after some test I think that the program enter always in the if not usr statement, also if the usr list is not empty. What’s the problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:18:02+00:00Added an answer on June 12, 2026 at 10:18 pm

    Could it be that perm is the string zero rather than an integer zero? If so, the test perm == 0 would fail. You can answer this question with a print statement:

    print type(perm)
    

    if it prints <type 'str'> then that’s your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Python I have this code: now = datetime.now().isoformat() if . not in now:
I have this code: def display(self): print self.doc.toprettyxml(indent= ) strigName ='/Users/my_user/Desktop/python/' + str(datetime.datetime.now()) +
I have this python code: import os try: os.system('wrongcommand') except: print(command does not work)
So let's say i have this python code: def loopForEachFileInDirectory(self, conn): for filename in
I have this piece of python code in gae. def post(self): cases=self.request.get('cases') while cases:
I'm modifying Python code that have this form: def foo(self): try: connect socket except
I have this code in Python inputted = input(Enter in something: ) print(Input is
Say I have this sample code I'm writing for a Python lesson I'm holding:
I'm newbie in Python. I have this simple code a = 0 b =
I have a python script the runs this code: strpath = sudo svnadmin create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.