Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mysql.connector
- import os
- cnx = mysql.connector.connect(user='cheevu_rs',password="dummy123",database="lp")
- cur = cnx.cursor()
- def fn():
- with open('file.txt', 'r') as fp:
- next(fp)
- for line in fp:
- print (line)
- words=line.split(" ")
- print (words)
- question_marks=[]
- a=0
- while a<len(words):
- question_marks.append('"%s"')
- a+=1
- quests = ','.join(question_marks)
- print (quests)
- print(tuple(words))
- p="INSERT INTO tabel VALUES(%s)" % quests
- print (p%tuple(words))
- cur.execute(p%tuple(words))
- cnx.commit()
- ip = input("Does table exist already? (y/n)")
- if ip =="y":
- f=1
- else:
- f=0
- line = open("file.txt").readline()
- print (line)
- if f==0:
- words=line.split(" ")
- print (words)
- for i in words:
- if i == words[0]:
- cur.execute("CREATE TABLE tabel(%s %s);" % (i,"VARCHAR(50)"))
- else:
- cur.execute("ALTER TABLE tabel ADD COLUMN %s %s;" % (i,"VARCHAR(50)"))
- fn()
- else:
- fn()
Add Comment
Please, Sign In to add comment