读写配置文件的简单示例程序:
import os
import myfunc as mf
import configparser as cp
conf=cp.ConfigParser()
file=os.path.realpath(__file__)
print('%s %s' %(type(file), file))
cur_path=os.path.dirname(os.path.realpath(__file__))
parentpath=os.path.dirname(cur_path)
print('%s %s' %(type(cur_path), cur_path))
print('%s %s' %(type(parentpath), parentpath))
grandpath=os.path.dirname(parentpath)
print('%s %s' %(type(grandpath), grandpath))
config_path=os.path.join(grandpath,'config.ini')
conf.read(config_path, 'utf-8')
pdf_root=conf.get('root', 'fatherpdfroot')
print('my father %s' % pdf_root)
print('call it......')
dubi=mf.funct(' input var-yes he..............')
print('end ...............................%s' % dubi)
读写配置文件示例

本文提供了一个使用Python读取和写入配置文件的简单示例。通过ConfigParser模块读取配置文件,并调用自定义函数进行后续操作。示例展示了如何获取当前文件路径、父目录及上上级目录。
299

被折叠的 条评论
为什么被折叠?



