python - 指示在 Python 的 D:/database.ini 文件中找不到部分 postgresql 的消息
问题描述
我想使用 Python 连接到我的数据库。这是我写的函数:
def config(filename='D:/database.ini', section='postgresql'):
# create a parser
parser = ConfigParser()
# read config file
parser.read(filename)
# get section, default to postgresql
db = {}
if parser.has_section(section):
params = parser.items(section)
for param in params:
db[param[0]] = param[1]
else:
raise Exception('section {0} not found in the {1} file'.format(section, filename))
return db
这是 database.ini 文件的内容:
[postgresql]
host=localhost
database=corpus
user=postgres
password=1234
但是,会出现以下消息:
section postgresql not found in the D:/database.ini file
我应该怎么办?
解决方案
推荐阅读
- x86 - DY 和 DZ 伪指令在 NASM 中如何工作?
- typescript - 如何在打字稿中正确实现和扩展?
- python-3.x - 使用将保留 AND 西里尔字符的格式化程序使用 BeautifulSoup 进行美化?
- python - Python Pandas df如何将1列的行转置为多列
- html - 如何使路径元素与我的 svg 元素的宽度相同?
- r - pivot_longer:values_ptypes:无法转换
到 - docker-desktop - 如何让 Mac 上的 Docker Desktop 指向 VM 映像的新位置?
- javascript - 用动态数据反应图像滑块,第一个图像出现在 clickEvent 之后
- android - 当我输入这个时,它给了我“以下函数都不能用提供的参数调用。”
- python - Tensorflow 卷积神经网络负维度大小