Why 'files.py' does not print the filenames into a table format?

Simpleton support at superhost.gr
Mon Jun 17 05:18:27 EDT 2013


On 17/6/2013 12:07 μμ, Simpleton wrote:
> # Load'em
> for filename in filenames:
>      try:
>          # Check the presence of current filename against it's database
> presence
>          cur.execute('''SELECT url FROM files WHERE url = %s''', filename )
>          data = cur.fetchone()
>
>          if not data:
>              # First time for file; primary key is automatic, hit is
> defaulted
>              cur.execute('''INSERT INTO files (url, host, lastvisit)
> VALUES (%s, %s, %s)''', (filename, host, lastvisit) )
>      except pymysql.ProgrammingError as e:
>          print( repr(e) )


Also i just alternated the above code to:

# Load'em
for filename in filenames:
	try:
		# try to insert the file into the database
		cur.execute('''INSERT INTO files (url, host, lastvisit) VALUES (%s, 
%s, %s)''', (filename, host, lastvisit) )
	except pymysql.ProgrammingError as e:
		# Insertion failed, file already into database, skip this, go to next 
filename
		pass

Isn't more compact and straightforward this way?
but i have to set the url's type into unique type for the abpve to work?

-- 
What is now proved was at first only imagined!



More information about the Python-list mailing list