I' just tried to implment your idea by correcting file names as: # Compute a set of current fullpaths fullpaths = set() path = "/home/nikos/www/data/apps/"
for root, dirs, files in os.walk(path): for fullpath in files: fullpaths.add( os.path.join(root, fullpath) ) # Load'em for fullpath in fullpaths: try: # Check the presence of a file against the database and insert if it doesn't exist cur.execute('''SELECT url FROM files WHERE url = %s''', ( fullpath.encode('ISO-8859-7').decode('latin-1'), ) data = cur.fetchone() #URL is unique, so should only be one This gave me this error: root@nikos [~]# [Tue Jun 04 16:55:51 2013] [error] [client 46.12.95.59] File "files.py", line 68 [Tue Jun 04 16:55:51 2013] [error] [client 46.12.95.59] data = cur.fetchone() #URL is unique, so should only be one [Tue Jun 04 16:55:51 2013] [error] [client 46.12.95.59] ^ [Tue Jun 04 16:55:51 2013] [error] [client 46.12.95.59] SyntaxError: invalid syntax [Tue Jun 04 16:55:51 2013] [error] [client 46.12.95.59] Premature end of script headers: files.py [Tue Jun 04 16:55:51 2013] [error] [client 46.12.95.59] File does not exist: /home/nikos/public_html/500.shtml It seem that this approach overcame the error, won't you agree? But i see no syntax error in the exact follow up line. data = cur.fetchone() #URL is unique, so should only be one -- http://mail.python.org/mailman/listinfo/python-list