gpt4 book ai didi

python - 错误 - 多级文件夹中的 pypyodbc.win_create_mdb

转载 作者:太空宇宙 更新时间:2023-11-04 01:18:53 25 4
gpt4 key购买 nike

>>> pypyodbc.win_create_mdb('E:/Database/Japan/201112.mdb')

它在双层文件夹中工作正常,但是当我创建 tripper-level 文件夹错误时出现错误。你能帮我遮一盏灯吗>谢谢。 MS Access library for python

>>> import pypyodbc    
>>> pypyodbc.win_create_mdb('E:/Database/Japan/JLeague/201112.mdb')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Anaconda\lib\site-packages\pypyodbc-1.3.1-py2.7.egg\pypyodbc.py", line 2715, in win_create_mdb
raise Exception('Failed to create Access mdb file - "%s". Please check file path, permission and Access driver readiness.' %mdb_path)
Exception: Failed to create Access mdb file - "E:/Database/Japan/JLeague/201112.mdb". Please check file path, permission and Access driver readiness.

最佳答案

如果目录不存在,

win_create_mdb 将不会自动创建目录,因此您需要检查并可能在尝试在其中创建数据库文件之前自行创建目录。尝试这样的事情

# -*- coding: utf-8 -*-
import os
import pypyodbc
directory = 'E:/Database/Japan/J League/'
if not os.path.exists(directory):
os.makedirs(directory)
pypyodbc.win_create_mdb('"' + directory + '201112.mdb' + '"')

关于python - 错误 - 多级文件夹中的 pypyodbc.win_create_mdb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22583089/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com