bash - Python and environmental variables -
executing following commands in ubuntu terminal have expected results:
$export number=3 echo $number ###3 $python >>>import os >>>print(os.environ['number']) ###prints 3
while :
$python -c 'import os;print(os.environ['number'])'
results in : nameerror : name 'number' not defined.
why? possible env variables python -c?
make sure change single quotes double quotes (the outer ones, @ least) avoid having problem
python -c "import os;print(os.environ['number'])" 3
works fine because single quotation marks inside double quotes.
edit: problem example not fact you're using single quotes within python, problem it's shell that's interpreting single quotes.
from bash man page:
a single quote may not occur between single quotes, when preceded backslash.
Comments
Post a Comment