Skip to content

Instantly share code, notes, and snippets.

@bthaman
Last active January 31, 2024 17:32
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bthaman/f7b2b8db006313f73074fe3dcebf0952 to your computer and use it in GitHub Desktop.
Save bthaman/f7b2b8db006313f73074fe3dcebf0952 to your computer and use it in GitHub Desktop.
Python script to list all environment variables, and split the 'path' variable
""" lists environment variables, and splits elements in path variable """
import os
for k, v in sorted(os.environ.items()):
print(k+':', v)
print('\n')
# list elements in path environment variable
[print(item) for item in os.environ['PATH'].split(';')]
@mortn
Copy link

mortn commented May 25, 2021

Thanks for sharing. An alternative way to print all environment variables could be

print( '\n'.join([f'{k}: {v}' for k, v in sorted(os.environ.items())]) )

@pablodz
Copy link

pablodz commented Nov 2, 2021

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment