Currently, i am unable to save the dictionary data using set operator. can you check whether the syntax is correct.
def get_table_details(conn, ctry, city, cate):
cur = conn.cursor()
names = {}
cur.execute(""" select inputfies from input_tables where a.country= %s and a.client= %s and a.category_code= %s """, (ctry, city, cate))
for row in cur:
names[row[0]] = 1
return names
tablelist = get_table_details(conn, ctry, city, cate)
# Open the tablemeasure.txt file in read mode
required = tablelist.keys()
You have defined a dictionary not a set.
If you want a set use this
def get_table_details(conn, ctry, city, cate):
cur = conn.cursor()
names = set()
cur.execute(""" select inputfies from input_tables where a.country= %s and a.client= %s and a.category_code= %s """, (ctry, city, cate))
for row in cur:
names.add(row[0])
return names
I am trying to compare two files and trying to find the unique lines.
I am looking to get rid of writing the temp file.
# Open the column.txt file in read mode
with open(bin+'columnmlist.txt', 'r') as co1:
# Read the lines from the columnlist.txt file
actual = col1.readlines()
col1.close()
actual_set = set(actual)
required = tablelist.keys()
required_set = set(required)
missing = actual_set.difference(required_set)
In python3 it is not required to call the keys() method of dictionary.
And sets do not keys to ask for. here are some examples.
d = {'x': 4, 'a': 1}
for key in d:
print(key)
print(d[key])
list_of_lists = list(d)
s = set(['x', 'a'])
for value in s:
print(value)
list_of_values = list(s)
Exactly as it says. The purpose of a dictionary is to store some non-duplicate “keys” that can be used to look up a corresponding “value” directly. But a set does not have separate keys and values; it just has elements (similarly to a list or a tuple) that cannot be duplicate. It is also not allowed to index into a set. To see all of its elements, iterate over it: for example by using a for loop, or by converting it to a list or tuple with those constructors.