2018年1月9日 星期二

Python: Access environment variables

Python: Access environment variables

Python Basic: Exercise-53 with Solution

Write a python program to access environment variables.
Sample Solution:-
import os
# Access all environment variables 
print('*----------------------------------*')
print(os.environ)
print('*----------------------------------*')
# Access a particular environment variable 
print(os.environ['HOME'])
print('*----------------------------------*')
print(os.environ['PATH'])
print('*----------------------------------*')

=========== RESTART: F:/Python_APSC/py-ex-basic-53.py ==============
*----------------------------------*
environ({'ALLUSERSPROFILE': 'C:\\ProgramData', 'COMSPEC': 'C:\\Windows\\system32\\cmd.exe', 'PROCESSOR_REVISION': '2a07', 'USERPROFILE': 'C:\\Users\\User', 'WINDOWS_TRACING_LOGFILE': 'C:\\BVTBin\\Tests\\installpackage\\csilogfile.log', 'TMP': 'C:\\Users\\User\\AppData\\Local\\Temp', 'PATH': 'C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\Intel\\OpenCL SDK\\2.0\\bin\\x86;C:\\Program Files (x86)\\Intel\\OpenCL SDK\\2.0\\bin\\x64;C:\\Program Files (x86)\\B1 Free Archiver;C:\\Program Files\\Common Files\\Autodesk Shared\\;C:\\Program Files (x86)\\QuickTime\\QTSystem\\;%QUARTUS_ROOTDIR%\\bin;C:\\Program Files\\Git\\cmd;C:\\Program Files\\Microsoft SQL Server\\110\\Tools\\Binn\\;C:\\Users\\User\\Miniconda3;C:\\Users\\User\\Miniconda3\\Scripts;C:\\Users\\User\\Miniconda3\\Library\\bin', 'HOME': 'C:\\Users\\User\\AppData\\Roaming\\SPB_16.6', 'ADSK_3DSMAX_X64_2015': 'C:\\Program Files\\Autodesk\\3ds Max 2015\\', 'NUMBER_OF_PROCESSORS': '4', 'COMPUTERNAME': 'USER-PC', 'VS110COMNTOOLS': 'C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\Common7\\Tools\\', 'USERDOMAIN': 'User-PC', 'HOMEPATH': '\\Users\\User', 'PROGRAMDATA': 'C:\\ProgramData', 'LOGONSERVER': '\\\\USER-PC', 'COMMONPROGRAMFILES(X86)': 'C:\\Program Files (x86)\\Common Files', 'ASL.LOG': 'Destination=file', 'PROCESSOR_ARCHITEW6432': 'AMD64', 'OS': 'Windows_NT', 'PROCESSOR_IDENTIFIER': 'Intel64 Family 6 Model 42 Stepping 7, GenuineIntel', 'SYSTEMROOT': 'C:\\Windows', 'TEMP': 'C:\\Users\\User\\AppData\\Local\\Temp', 'COMMONPROGRAMFILES': 'C:\\Program Files (x86)\\Common Files', 'PUBLIC': 'C:\\Users\\Public', 'SESSIONNAME': 'Console', 'WINDIR': 'C:\\Windows', 'PROGRAMFILES': 'C:\\Program Files (x86)', 'PATHEXT': '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC', 'PROGRAMW6432': 'C:\\Program Files', 'PROCESSOR_LEVEL': '6', 'PSMODULEPATH': 'C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules\\', 'SYSTEMDRIVE': 'C:', 'LOCALAPPDATA': 'C:\\Users\\User\\AppData\\Local', 'COMMONPROGRAMW6432': 'C:\\Program Files\\Common Files', 'APPDATA': 'C:\\Users\\User\\AppData\\Roaming', 'PROGRAMFILES(X86)': 'C:\\Program Files (x86)', 'KISYSMOD': 'C:\\Program Files\\KiCad\\share\\kicad\\modules', 'WINDOWS_TRACING_FLAGS': '3', 'PROCESSOR_ARCHITECTURE': 'x86', 'KISYS3DMOD': 'C:\\Program Files\\KiCad\\share\\kicad\\modules\\packages3d', 'KICAD_PTEMPLATES': 'C:\\Program Files\\KiCad\\share\\kicad\\template', 'FP_NO_HOST_CHECK': 'NO', 'USERNAME': 'User', 'MOZ_PLUGIN_PATH': 'C:\\Program Files (x86)\\Foxit Software\\Foxit Reader\\plugins\\', 'HOMEDRIVE': 'C:'})
*----------------------------------*
C:\Users\User\AppData\Roaming\SPB_16.6
*----------------------------------*
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files (x86)\B1 Free Archiver;C:\Program Files\Common Files\Autodesk Shared\;C:\Program Files (x86)\QuickTime\QTSystem\;%QUARTUS_ROOTDIR%\bin;C:\Program Files\Git\cmd;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Users\User\Miniconda3;C:\Users\User\Miniconda3\Scripts;C:\Users\User\Miniconda3\Library\bin
*----------------------------------*
>>> 

沒有留言:

張貼留言

OPEN DATA AQI 空氣品質監測網 + NODE-RED

OPEN DATA AQI 空氣品質監測網 + NODE-RED  首頁 - 空氣品質監測網  https://airtw.moenv.gov.tw/ https://data.gov.tw/datasets/search?p=1&size=10&s=_score...