home changes contents help options

208:環境変数にアクセスする

osモジュールのenviron関数を使います。一覧を出すのはこんな感じ。

 >>> import os
 >>> for k, v in os.environ.items():
        print "%s=%s" % (k,v)

 TMP=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp
 COMPUTERNAME=PRIVATE-6Q4Z5JV
 USERDOMAIN=PRIVATE-6Q4Z5JV
 COMMONPROGRAMFILES=C:\Program Files\Common Files
 PROCESSOR_IDENTIFIER=x86 Family 6 Model 6 Stepping 5, GenuineIntel
 PROGRAMFILES=C:\Program Files
 PROCESSOR_REVISION=0605
 PATH=C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\PROGRA~1\CHECKP~1\SECURE~1\bin;;
 HOME=C:\Documents and Settings\Administrator
 TK_LIBRARY=c:\Python23jp\tcl\tk8.4
 TEMP=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp
 PROCESSOR_ARCHITECTURE=x86
 TIX_LIBRARY=c:\Python23jp\tcl\tix8.1
 ALLUSERSPROFILE=C:\Documents and Settings\All Users
 HOMEPATH=\Documents and Settings\Administrator
 USERNAME=Administrator
 LOGONSERVER=\\PRIVATE-6Q4Z5JV
 SYSTEMROOT=C:\WINNT
 COMSPEC=C:\WINNT\system32\cmd.exe
 TCL_LIBRARY=c:\Python23jp\tcl\tcl8.4
 PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
 WINDIR=C:\WINNT
 APPDATA=C:\Documents and Settings\Administrator\Application Data
 HOMEDRIVE=C:
 SYSTEMDRIVE=C:
 NUMBER_OF_PROCESSORS=1
 PROCESSOR_LEVEL=6
 OS2LIBPATH=C:\WINNT\system32\os2\dll;
 OS=Windows_NT
 USERPROFILE=C:\Documents and Settings\Administrator