Hello all!

I would like to ask you the following: what should i do to be executed my correctly?

The error:
Traceback <most recent call last>:
  File "insert_into_db_v9.py", line 55, in <module>
TypeError: an integer is required

The code i use is the following:

import psycopg2
import os
from os import sep, listdir, path
import io

libfolder = "C:\\Blender_Library\\BlenderLib\\objectLib\\"

#we are in C:\\Blender_Library\\BlenderLib\\objectLib\\
for dir1 in os.listdir(libfolder):
        print libfolder + dir1
        if os.path.isdir(os.path.dirname(libfolder + dir1)):    
                tempdir = libfolder + dir1
                tempfiles = os.listdir(tempdir)
#we are for example in C:\\Blender_Library\\BlenderLib\\objectLib\\Osaka"
                for f in tempfiles:
                        if os.path.isdir(libfolder + dir1 + os.sep + f):
                                tempdir1 = libfolder + dir1 + os.sep + f
                                tempfiles1 = os.listdir(tempdir1)
#we are for example in C:\\Blender_Library\\BlenderLib\\objectLib\\Faqns\\Osaka"
                                for ff in tempfiles1:
                                        print libfolder + dir1 + os.sep + f + 
os.sep + ff
                                        if ff[-5:] == "blend":
                                                # !!! that is test data. It 
must be changed
conn=psycopg2.connect("host=localhost dbname=postgres user=postgres password=test")

#conn.cursor will return a cursor oject, you can use this cursor to perform queries
                                                cursor = conn.cursor()

                                                # psycopg2.Binary() escapes all 
data that needs that
data1 = psycopg2.Binary(io.open( tempdir1 + os.sep + ff, 'rb' ).read())
        
                                                # execute our Query
                                                cursor.execute("""UPDATE 
testtable SET blend = %s)
WHERE testtable_n = %s""", data1, str(os.path.splitext(file)[0]))

                                                # Save (commit) the changes
                                                conn.commit()
                
                                                # We can also close the cursor 
if we are done with it
                                                cursor.close()
                                elif ff[-3:] == "jpg" or ff[-4:] == "jpeg":
                                                # !!! that is test data. It 
must be changed
conn=psycopg2.connect("host=localhost dbname=postgres user=postgres password=test")

#conn.cursor will return a cursor oject, you can use this cursor to perform queries
                                                cursor = conn.cursor()

                                                # psycopg2.Binary() escapes all 
data that needs that
data1 = psycopg2.Binary(io.open( tempdir1 + os.sep + ff, 'rb' ).read())
        
                                                # execute our Query
                                                cursor.execute("""UPDATE 
testtable SET jpeg = %s)
WHERE testtable_n = %s""", data1, str(os.path.splitext(file)[0]))

                                                # Save (commit) the changes
                                                conn.commit()
                
                                                # We can also close the cursor 
if we are done with it
                                                cursor.close()
                                        elif ff[-3:] == "txt":
                                                # !!! that is test data. It 
must be changed
conn=psycopg2.connect("host=localhost dbname=postgres user=postgres password=test")

#conn.cursor will return a cursor oject, you can use this cursor to perform queries
                                                cursor = conn.cursor()
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to