File path error handed over to stored in python

Asked 2 years ago, Updated 2 years ago, 82 views

I'm a beginner at python.Thank you for your cooperation.

  • I want to store sqlserver from python
  • The stored argument is the file path
  • Error specifying file path for argument
  • I somehow understand that the reason is that the \ in the
  • path becomes \\, but
    I don't know how to solve it
input_file=r'C:\xxxx\ImportData\test.csv'
sql=f "usp_test {input_file}"
_cn.execute(sql)
 '42000', "[42000] [Microsoft] [ODBC SQL Server Driver] [SQL Server]'\\' Invalid syntax in neighborhood. (102) (SQLExecDirectW)"

python sql-server

2022-09-29 21:52

1 Answers

I solved myself.
It worked by rewriting to / instead of \.
I thought I couldn't use /.

input_file='C:/xxxx/ImportData/test.csv'


2022-09-29 21:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.