如何使用Argparse打开和读取属性文件

问题描述

我陷入了这个python程序中,该程序使用Argparse参数读取文件。在读取属性文件application-DEV.properties)时,它以某种方式给我错误“没有这样的文件和目录”。但是我可以在代码存储库中看到该文件。下面是我的代码

要执行的命令:

python create_param_store.py --Tier DEV

Python代码

def load_envproperties(sep='=',comment_char='#'):
    
    props = {}
    with open("../../../src/main/resources/application.properties",'rt') as f:
        e=set(f.readlines())
        
    with open("'../../../src/main/resources/application-' +  pa.Tier + '.properties'",'rt') as f:
        d=set(f.readlines())
        for line in list(d-e):
            l = line.strip()
            if l and not l.startswith(comment_char):
                key_value = l.split(sep)
                key = key_value[0].strip()
                value = sep.join(key_value[1:]).strip().strip('"') 
                props[key] = value
                print(props[key])
                putssm(Name=key,Value=props[key])
            
        
def init():
    global pa
    parser = argparse.ArgumentParser(description='Additional Params.')
    parser.add_argument('--Tier',nargs='?',dest='Tier',required=False,help='Tier')
    pa = parser.parse_args()

错误

 File "create_param_store.py",line 59,in main
    load_envproperties()
  File "create_param_store.py",line 38,in load_envproperties
    with open("'../../../src/main/resources/application-' +  pa.Tier + '.properties'",'rt') as f:
FileNotFoundError: [Errno 2] No such file or directory: "'../../../src/main/resources/application-' +  pa.Tier + '.properties'"

[Container] 2020/08/30 21:37:42 Command did not exit successfully python create_param_store.py --Tier $Tier exit status 1
[Container] 2020/08/30 21:37:42 Phase complete: BUILD State: Failed

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...