MySQL Forums
Forum List  »  Connector/Python

Re: serious problems...
Posted by: Jason Massey
Date: October 18, 2006 04:17PM

How about some code, Josh, so we can see what you've tried.

If you've already got the table set up in your database then you don't need the location,latitude,longitude headings at the top of your text file.

We'll assume that:

database = mydatabase
table = mytable
import MySQLdb

db = MySQLdb.connect(user='xxx',passwd='xxxxx',host='127.0.01')
db.select_db('mydatabase')
cursor = db.cursor()
data = open(r"yourfile.txt","r").readlines()
for line in data:
  loc,lat,long = line.split(',')
  cursor.execute("""insert into mytable (location,latitude,longitude) values (%s,%s,%s)""", (loc,lat,long))

Something along those lines

Options: ReplyQuote


Subject
Written By
Posted
October 09, 2006 07:04PM
Re: serious problems...
October 18, 2006 04:17PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.