This is a followup to this Stackoverflow post
How to use Python variables in Google Colab terminal command?
Which asks how to send python variables to the command line.
The answer is you need to place a $ in front of it. In other cases, you need to quote everything like this '$variable'
This works for me except for curl commands. For example
emailBody1 = ' this is some test text'
!curl -X POST 'http://localhost.yxy' -H "Content-Type: application/json" -d '{"emails": [{"emailBody": '$emailBody1'}}'
I tried no quotes, single quotes, and double quotes. No quotes results in an error, and single/double quotes just sends whatever is inside as a string; no reference to the variable.
This works for me
-d '{{"emails": [{{"emailBody": "$emailBody1" }}]}}'
or
-d '{{"emails": [{{"emailBody": "{emailBody1}" }}]}}'
All string is inside ' '
(or " "
) without spliting to 'string' $var 'string'
And normal { }
has to be converted to {{ }}
because it uses { }
to put values from variables.
I tested it with http://httpbin.org/post which sends back all data so I could see what was send.
emailBody1 = ' this is some test text'
!curl -X POST 'http://httpbin.org/post' -H "Content-Type: application/json" -d '{{"emails": [{{"emailBody": "{emailBody1}" }}]}}'