problems with mysql db

golu bhardwajjayesh7 at gmail.com
Mon Jun 29 08:55:39 EDT 2009


here i have posted my code...plz tell why am i getting the error "int
argument required" on the hash marked line(see below) although i am
giving an int value
#the code
import os
import string
import MySQLdb
import stopcheck
conn = MySQLdb.connect(host='localhost',user='root',db='urdb')

def file_extractor(dir_name):
    url_count = 0

    for file in os.listdir(dir_name):
      if(file[-4:] == '.txt'):
        file_path = os.path.join(dir_name,file)
        curse = conn.cursor()
        url_count += 1
        curse.execute("INSERT INTO URL_TABLE VALUES(%d,%s)",
(url_count,file_path)) #error
        word_extractor(url_count,file_path)
def word_extractor(url_count,file):
    fhandle =  open(file)
    line = fhandle.readline()
    k=stopcheck.checker()
    k.create()

    while line:
       words = line.split()
       cursor = conn.cursor()
       for word1 in words:
           if word1 not in string.punctuation:
                if (k.check(word1) is 0) and (word1[0:4] != 'http') :
                   word_count+=1
                   try:
                    cursor.execute("INSERT INTO word_table(id,word)
VALUES(%d,%s)" , (word_count,word1))
                    cursor.execute("INSERT INTO wordmatch
(word_id,url_id) values(%d,%d)",(word_count,url_count))
                   except MySQLdb.Error, e:
                         print "Error %d: %s" % (e.args[0], e.args[1])
       line=fhandle.readline()

if __name__ == '__main__':
    #url_count=0
    #word_count=0

    dir = os.path.join('D://','acm')
    file_extractor(dir)



More information about the Python-list mailing list