Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
replace text in a txt
#6
Thank you so much for the methods and i come with a new question:


i want to build an insert query for each match from that file and then send it to my own database..


for example from

Verona - Napoli
10.42% (9.60) 1.11% 1
27.08% (3.69) 11.11% X
62.5% (1.60) -11.11% 2
37.5% (2.67) 11.11% 1X
89.58% (1.12) -1.11% X2
72.92% (1.37) -11.11% 12

create the query
INSERT INTO sbostats (partita,p1,pX,p2,p1x,px2,p12) VALUES ("Verona - Napoli","10.42% (9.60) 1.11% 1" ,"27.08% (3.69) 11.11% X ","62.5% (1.60) -11.11% 2 ","37.5% (2.67) 11.11% 1X " ," 89.58% (1.12) -1.11% X2"," 72.92% (1.37) -11.11% 12 " );

and so on...

i have to take the number of rows of file and then do same from line 1 to 7 than 8 to 14 and so on?

import mysql.connector
from mysql.connector import errorcode



mydb = mysql.connector.connect(
  host="localhost",
  user="root",
  database="my_db"
)

mycursor = mydb.cursor()

sql = "INSERT INTO sbostats (partita,p1,pX,p2,p1x,px2,p12) VALUES (%s, %s,%s, %s,%s, %s, %s)"
val = ("test1", "test2","3", "4", "5", "6", "7")

mycursor.execute(sql, val)

mydb.commit()

print(mycursor.rowcount, "record inserted.")
i saw also that i can connect to my database :) and i can send the query .. All was fine

so i have to put datas in "val" and iterate.. but i have no idea how to do that!
Reply


Messages In This Thread
replace text in a txt - by cartonics - Oct-12-2023, 07:50 AM
RE: replace text in a txt - by buran - Oct-12-2023, 07:52 AM
RE: replace text in a txt - by cartonics - Oct-12-2023, 08:01 AM
RE: replace text in a txt - by buran - Oct-12-2023, 09:11 AM
RE: replace text in a txt - by perfringo - Oct-12-2023, 09:43 AM
RE: replace text in a txt - by cartonics - Oct-12-2023, 10:54 AM
RE: replace text in a txt - by deanhystad - Oct-12-2023, 08:01 PM
RE: replace text in a txt - by cartonics - Oct-13-2023, 07:31 AM
RE: replace text in a txt - by deanhystad - Oct-13-2023, 11:35 AM
RE: replace text in a txt - by cartonics - Oct-13-2023, 12:48 PM
RE: replace text in a txt - by deanhystad - Oct-13-2023, 01:27 PM
RE: replace text in a txt - by cartonics - Oct-13-2023, 02:28 PM
RE: replace text in a txt - by deanhystad - Oct-13-2023, 06:35 PM
RE: replace text in a txt - by cartonics - Oct-13-2023, 08:01 PM
RE: replace text in a txt - by deanhystad - Oct-13-2023, 08:42 PM
RE: replace text in a txt - by cartonics - Oct-14-2023, 06:33 AM
RE: replace text in a txt - by nicoali - Dec-15-2023, 06:28 PM
RE: replace text in a txt - by nicoali - Dec-16-2023, 04:07 PM
RE: replace text in a txt - by logicielfr - Jan-23-2024, 09:33 PM
RE: replace text in a txt - by Athi - Jan-30-2024, 06:58 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Replace a text/word in docx file using Python Devan 4 4,572 Oct-17-2023, 06:03 PM
Last Post: Devan
  python-docx regex: replace any word in docx text Tmagpy 4 2,453 Jun-18-2022, 09:12 AM
Last Post: Tmagpy
  Replace String in multiple text-files [SOLVED] AlphaInc 5 8,578 Aug-08-2021, 04:59 PM
Last Post: Axel_Erfurt
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 6,361 Aug-10-2020, 11:01 PM
Last Post: medatib531
  Search & Replace - Newlines Added After Replace dj99 3 3,536 Jul-22-2018, 01:42 PM
Last Post: buran
  Need to replace (remove) Unicode characters in text ineuw 1 8,769 Jan-02-2018, 08:01 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020