Jump to content
Fórum Script Brasil
  • 0

dividir valores com csv.reader


astatonn

Question

Ola,

 

Gostaria de ler um arquivo csv e cada valor estar dentro de aspas simples.

Segue meu código:

def InsertData (check_enter, Table):
    with open (check_enter, encoding="utf8"as csv_file:
        csv_reader = csv.reader(csv_file, delimiter=',')
        next(csv_reader)
        for row in csv_reader:
            row = (', '.join(row))
            sql = "INSERT INTO {} VALUES ({})".format(Table,row)
            # cursor.execute(sql)
            # db.commit()
            print (sql)

saída:

INSERT INTO shapes VALUES (2731-1, -30.209293, -51.177531, 44)
INSERT INTO shapes VALUES (2731-1, -30.209224, -51.177674, 45)
INSERT INTO shapes VALUES (2731-1, -30.209062, -51.178096, 46)
INSERT INTO shapes VALUES (2731-1, -30.208796, -51.17887, 47)
INSERT INTO shapes VALUES (2731-1, -30.208766, -51.178904, 48)
INSERT INTO shapes VALUES (2731-1, -30.208691, -51.178892, 49)
INSERT INTO shapes VALUES (2731-1, -30.207825, -51.178549, 50)

 

Como deveria ser:

INSERT INTO shapes VALUES ('2731-1', '-30.209293', '-51.177531, 44')
INSERT INTO shapes VALUES ('2731-1',' -30.209224', '-51.177674', '45')
INSERT INTO shapes VALUES ('2731-1', '-30.209062',' -51.178096', '46')
.

.

.
INSERT INTO shapes VALUES ('2731-1', '-30.207825',' -51.178549', '50')

 

 

 

Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Cloud Computing


  • Forum Statistics

    • Total Topics
      148706
    • Total Posts
      644498
×
×
  • Create New...