1

我对python很陌生,想使用pyodbc将一个表从一个mdb复制到另一个mdb。如果文件夹名称以数字开头,则路径似乎存在问题。我现在google了一个小时,找不到解决方案:

DBfile = r"W:\path\1020 Folder\MDB1.mdb"
conn = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};DBQ='+DBfile1)
cursor = conn.cursor()

sql = """SELECT Table1.* INTO test FROM [W:\path\A 1020 Folder\MB2.mdb].Table1;""" 
sql1 = """SELECT Table1.* INTO test FROM [W:\path\1020 Folder\MB2.mdb].Table1;""" 

cursor.execute(sql) #WORKING
cursor.execute(sql1)  #NOT WORKING
conn.commit()

非常感谢,阿奇姆

4

1 回答 1

2

You must be very careful when you want to use backshlash \ in strings. You can escape those using \\:

sql1 = """SELECT Table1.* INTO test FROM [W:\\path\\1020 Folder\\MB2.mdb].Table1;""" 

You can also use raw string just like you did it with DBfile

于 2012-12-12T12:01:49.313 回答