我为python脚本创建了一个文件参数。我的想法是从JSON文件中读取这些参数,然后在需要的地方执行。在
以下是示例文件:
{
"configfiles": [
{
"log": "/home/ubuntu/scripts/mtm-etl/etl-process-log",
"connection":"/home/ubuntu/scripts/mtm-etl/etlconfig/mtm-connection",
"query_redshift_library":"/home/ubuntu/scripts/mtm-etl/etlconfig/query_redshift_library"
}
]
}
好的,现在我假装在脚本中读取for中的键和值,将它们分配给变量,然后,我的代码如下:
^{pr2}$我的问题是在elif
中,因为一个变量被指定了正确的数据类型作为字符串,但是由于某些原因,logfile
和{
感谢你的反馈
谢谢
错误是由此处的多余逗号引起的:
移除它们,您将得到str形式的变量:
^{pr2}$至于为什么会这样工作:python解释以逗号结尾的行,就好像您确实在为变量分配单元素元组(实际上不需要括号),就像下面这个更简单的例子:
相关问题 更多 >
编程相关推荐