I am moving Perl (from which I have very little knowledge) a script in python.
$path = $ENV{ 'SOME_NAME' } || die " SOME_NAME ENV VARIABLE NOT FOUND\n";
I can (hopefully) see what this line does, either set the variable "path" to the environment variable "SOME_NAME", or not execute it, and then print the error message to the user. (Note: does anyone know how to get a search engine to search for special characters such as "||"?)
I tried to implement it in a "pythonic" way (itβs easier to ask for forgiveness than permission) using:
try: path = os.environ['SOME_NAME'] except KeyError,e: print "SOME_NAME ENVIRONMENT VARIABLE NOT FOUND\n" raise e
but it seems rather cumbersome, especially since I do it for three different environment variables.
Any ideas if there is a more efficient implementation, or would you say that this is a "pythonic" way to do this?
Many thanks
python perl
Jdog
source share