I have this python code to execute an sql file:
import mysql.connector
cnx = mysql.connector.connect(user='skynetadmin',
password='Skynetadmin1',
host='silmysskytest01.sing.micron.com',
database='skynet_msa')
cursor =cnx.cursor()
def executeScriptsFromFile(filename):
fd = open(filename, 'r')
sqlFile = fd.read()
fd.close()
sqlCommands = sqlFile.split(';')
for command in sqlCommands:
try:
if command.strip() != '':
cursor.execute(command)
executeScriptsFromFile('C:\Users\gsumarlin\Documents\dumps\Dump20220428\Query_for_testingintern.sql')
cnx.commit()
Hwv, I have this error:
executeScriptsFromFile('C:\Users\gsumarlin\Documents\dumps\Dump20220428')
^ unexpected unindent
I tried moving ard with the indents but it gives me no solution.
Any help is appreciated!
import mysql.connector
def executeScriptsFromFile(Query_for_testingintern):
fd = open(Query_for_testingintern, 'r')
sqlFile = fd.read()
fd.close()
sqlCommands = sqlFile.split(';')
for command in sqlCommands:
try:
if command.strip() != '':
cursor.execute(command)
except:
pass
cnx = mysql.connector.connect(user='skynetadmin',password='Skynetadmin1',host='silmysskytest01.sing.micron.com',database='skynet_msa')
cursor =cnx.cursor()
executeScriptsFromFile("C:\\Users\gsumarlin\Documents\dumps\Dump20220428")
cnx.commit()
Do you use Notepad++ or something like that?
You can simply open the file there and select all (Ctrl + A) Then click on "Edit" -> Non printable characters -> Convert Tabs to Spaces
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.