0

i have same title and same title in row in my db table i want to compare this for finding equality. i try this but not work , any solution ? thank :)

    def get_files_to_load(dir):
    files_to_load = []
    files = os.listdir(dir)    
    for file in files:
        file_full_path = os.path.join(os.path.abspath(dir),file)
        with open(file_full_path, 'r', errors='ignore'):
            file_to_load = file[:-4]
            files_to_load.append(file_to_load)
                                
    return files_to_load 

    files_fullpath = get_files_to_load('./foo/foo/static/media/pdf')
    print(files_fullpath)
try:
    connection = psycopg2.connect(user="foo",
                                  password="foo",
                                  host="localhost",
                                  database="foo")
  
    cursor = connection.cursor()
    postgreSQL_select_Query = "select * from table"

    cursor.execute(postgreSQL_select_Query)
    print("Selecting rows from actes table using cursor.fetchall")
    acte_records = cursor.fetchall()

    print("Print each row and it's columns values")
    for row in acte_records:
        if row[1] == files_fullpath:
            print( row[1])
        else:
            print ('...')
hugo
  • 1
  • 1
  • recommendation to use RealDictCursor so you can access the result's rows as a dict instead of as a tuple. how to do that is shown here: https://stackoverflow.com/a/9230872/42346 – mechanical_meat Jan 26 '22 at 15:11
  • You can do the matching in SQL; see https://www.postgresql.org/docs/14/tutorial-select.html – snakecharmerb Jan 26 '22 at 15:22
  • 1
    @mechanical_meat, thank you , i was try it's good to have two dict i understant, it's good. now i try to check one by one for a future search result :) – hugo Jan 26 '22 at 16:42
  • no problem! i'm glad it worked out! it can be difficult to find previous results if you don't know exactly what you need. – mechanical_meat Jan 26 '22 at 16:45
  • @snakecharmerb thank you, i testing that , in pure sql it work but i d'ont know how to compare equality after with my files in my folder – hugo Jan 26 '22 at 16:46

0 Answers0