How to pass a list as an environment variable?

后端 未结 4 2254
猫巷女王i
猫巷女王i 2021-02-07 01:52

I use a list as part of a Python program, and wanted to convert that to an environment variable.

So, it\'s like this:

list1 = [\'a.1\',\'b.2\',\'c.3\']
         


        
4条回答
  •  南旧
    南旧 (楼主)
    2021-02-07 02:38

    I'm not sure why you'd do it through the environment variables, but you can do this:

    export LIST_ITEMS ="a.1 b.2 c.3"
    

    And in Python:

    list1 = [i.split(".") for i in os.environ.get("LIST_ITEMS").split(" ")] 
    
    for k, v in list1:
        print(k, v)
    

提交回复
热议问题