November 6, 2023 at 12:00 am
Comments posted to this topic are about the item SQL Server and Python Tutorial
November 6, 2023 at 6:39 am
Finely written article. And well explained, thank you. I do have a question or two.
with open('c:\data\currencies.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file)
next(csv_reader) # Skip the header row if it exists
for row in csv_reader:
currency_code = row[0]
name = row[1]
stored_procedure = 'InsertCurrency'
cursor.execute("{CALL " + stored_procedure + " (?, ?)}", (currency_code, name))
connection.commit()
print(f"Inserted: {currency_code}, {name}")
print("All currencies inserted successfully!")
Where does the loop end? It seems by layman's eyes that everything under "for row in csv_reader " would be indented once. Currency and name are but the rest of the lines are not.
Also since this seems to do a row by row operation, call to a SP, it seems I would not recommend this for a csv file holding tons of records. I would look to Bulk Insert for that. Or am I wrong?
----------------------------------------------------
November 6, 2023 at 9:55 am
Some practical examples of where Python beats standard SQL Server functions would be interesting. Or is this aimed simply at people who prefer writing their code in Python?
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply