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 7733527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:00:51+00:00 2026-06-01T07:00:51+00:00

I have a Python script that queries a MySQL database every 5 seconds, gathering

  • 0

I have a Python script that queries a MySQL database every 5 seconds, gathering the latest three ID’s for helpdesk tickets. I am using MySQLdb as my driver. But the issue is in my “while” loop, when I check if two arrays are equal. If they are NOT equal, I print “A new ticket has arrived.” But this never prints! See my code:

import MySQLdb
import time

# Connect
db = MySQLdb.connect(host="MySQL.example.com", user="example", passwd="example", db="helpdesk_db", port=4040)
cursor = db.cursor()

IDarray = ([0,0,0])
IDarray_prev = ([0,0,0])

cursor.execute("SELECT id FROM Tickets ORDER BY id DESC limit 3;")
numrows = int(cursor.rowcount)
for x in range(0,numrows):
   row = cursor.fetchone()
   for num in row:
      IDarray_prev[x] = int(num)
cursor.close()
db.commit()

while 1:
   cursor = db.cursor()
   cursor.execute("SELECT id FROM Tickets ORDER BY id DESC limit 3;")

   numrows = int(cursor.rowcount)
   for x in range(0,numrows):
      row = cursor.fetchone()
      for num in row:
         IDarray[x] = int(num)

   print IDarray_prev, " --> ", IDarray
   if(IDarray != IDarray_prev): 
      print "A new ticket has arrived."

   time.sleep(5)
   IDarray_prev = IDarray
   cursor.close()
   db.commit()

Now when this ran, then I created a new ticket, the output looks like this:

[11474, 11473, 11472]  -->  [11474, 11473, 11472]
[11474, 11473, 11472]  -->  [11474, 11473, 11472]
[11474, 11473, 11472]  -->  [11474, 11473, 11472]
[11474, 11473, 11472]  -->  [11474, 11473, 11472]
[11475, 11474, 11473]  -->  [11475, 11474, 11473]
[11475, 11474, 11473]  -->  [11475, 11474, 11473]
[11475, 11474, 11473]  -->  [11475, 11474, 11473]
[11475, 11474, 11473]  -->  [11475, 11474, 11473]
[11475, 11474, 11473]  -->  [11475, 11474, 11473]

Where the format of my output is:

[Previous_Last_Ticket, Prev_2nd_to_last, Prev_3rd] --> [Current_Last, 2nd-to-last, 3rd]

Notice the change in numbers and, more importantly, the lack of “A new ticket has arrived”!

  • 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-01T07:00:52+00:00Added an answer on June 1, 2026 at 7:00 am

    The problem is the following line:

    IDarray_prev = IDarray
    

    In Python, this makes IDarray_prev refer to the same underlying list as IDarray. Changes in one will be reflected in the other, because they both point to the same thing.

    To make a copy of the list that you can use to compare later, try:

    IDarray_prev = IDarray[:]
    

    The [:] is Python slice notation that means “a copy of the whole list”.

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

Sidebar

Related Questions

I have a python script that makes about ten INSERTs into a MySQL database.
I have a python script that globally invokes a database connection object with mySQL.
I have a python script that has to launch a shell command for every
I have a python script that takes input using a pattern like this: 1**
I have a python script that makes a series of url calls using urllib2.
I have python script that converts data.xml to html using stylesheet.xsl. And i have
I have a Python script that is connecting to the database. To that, obviously,
I have a python script that is using the SIGSTOP and .SIGCONT commands with
I have a python script that analyzes a set of error messages and checks
I have a Python script that needs to execute an external program, but for

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.