Reputation: 27
I perform an os.popen()
command to access a measurement stored in InfluxDB from the command line. The data is a table, but I am only concerned with two specific columns of the table, which is why I use splitlines()
.
To display the specific two columns in the GUI, I use a for
loop, and I strip the title line, store values of column 2 and column 3 in separate arrays as follows:
list_of_number = []
list_of_assigned = []
for line in output[1:]:
self.cameraOutputTextEdit.append(line[2] + " " + line[1])
dict = {}
dict['claimed'] = line[1]
dict['eya_cam'] = line[2]
list_of_assigned.append(dict['claimed'])
list_of_number.append(dict['eya_cam'])
print(list_of_assigned)
print (list_of_number)
The print statements yield the output:
['claimed', '-------', 'false', 'true']
['eya_cam', '-------', '2', '1']
I now need to perform certain if conditions:
camNum = self.cameraNumber.text()
t="true"
f="false"
if (camNum in list_of_number and t in list_of assigned):
do_something
if (camNum list_of_number and f in list_of assigned):
do_something
if (camNum not in list_of_number):
do_something
The issue with this is that when camera number '2' is given, it executes the first condition even though it has been assigned as 'false' in the Database. Where am I going wrong with this logic?
Upvotes: 0
Views: 71
Reputation: 101
t in list_of_assigned
['claimed', '-------', 'false', 'true']
You are testing if the value 'true'
is in your list_of_assigned
variable. As long as there is one true in this list, t in list_of_assigned
will always return true. You should either zip these two tables and parse through them together in a loop or check the index of the camera in your list_of_number
list then check if that index in list_of_assigned
is true.
Upvotes: 1
Reputation: 1609
Did you accidentally typed assigned
word?
if (camNum in list_of_number and t in list_of_assigned):
I think you may intent to write as above.
Upvotes: 0