一、配置文件hdfs.conf二、读取配置文件参数 一、配置文件hdfs.conf
[cdhprod]corePath: /Users/f/PycharmProjects/firstProject/hdfs/core-site.xmlhdfsPath: /Users/f/PycharmProjects/firstProject/hdfs/hdfs-site.xmlkrb5Conf: /Users/f/PycharmProjects/firstProject/hdfs/krb5.confkeytab: /Users/f/PycharmProjects/firstProject/hdfs/optics.keytabClusterName: hdfs://optics-cdhkeytabUser: optics@CDH.optics.COM[cdhtest]ClusterName: hdfs://optics-cdh-test
二、读取配置文件参数import configparsercf = configparser.ConfigParser()cf.read("/Users/f/PycharmProjects/firstProject/hdfs.conf")//读取配置文件头['cdhprod', 'cdhtest']secs = cf.sections()print(secs)//读取配置文件对应头内的参数//以读取keytab属性为例keytab = cf['cdhprod']['keytab']print(keytab)
输出如下所示:
['cdhprod']/Users/f/PycharmProjects/firstProject/hdfs/optics.keytab