简体   繁体   中英

how to get keys and value from os.environ in python3

environment: win10 python3.7 ipdb

when I type(os.environ) it report a environ({.....}) the data in environ() seems a dict, but os.environ is not dict when I use os.environ['CURRENT_USER_NAME'] , it is return the value.

I try to get the key list by os.environ.keys() , it return a keysview. I don't know how to get the keys and value from os.environ as dict.

my purpose is that print the os.environ by pprint, who know how to do it?

You can try this:

import os
import pprint as pp

pp.pprint(dict(os.environ))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM