将shell脚本中定义的环境变量读入python。
shellvars-p的Python项目详细描述
将shell脚本中定义的环境变量读入Python。 这个库使用shell获取变量值,并处理 多行变量。
#用法
给定一个shell文件:myvars.env:
`shell #!/bin/bash export VAR1=1 export VAR2="This is a multiline value" export VAR3=3 NOT_EXPORTED=4 `
获取变量
`python >>> import shellvars >>> shellvars.get_vars('myvars.env') {'VAR1': '1', 'VAR2': 'This\nis\na\nmultiline value', 'VAR3': '3' } `
###列表#变量 列出脚本中的变量名。 `python >>> import shellvars >>> shellvars.list_vars('myvars.env') ['VAR1', 'VAR2', 'VAR3'] `
这相当于,但比 `python >>> shellvars.get_vars('myvars.env').keys() `