-
Notifications
You must be signed in to change notification settings - Fork 62
Capture variables
Alexander Ponomarev edited this page Jan 5, 2022
·
2 revisions
It's possible to use python variables directly in shell scripts. An example:
import json
import os
import tempfile
# get the api answer with curl
answer = `curl https://api.github.com/users/python
answer_json = json.loads(answer.stdout)
avatar_url = answer_json['avatar_url']
destination = os.path.join(tempfile.gettempdir(), 'python.png')
# execute curl once again, this time to get the image
result = `curl {avatar_url} > {destination}
p`ls -l {destination}
You can see that avatar_url
and destination
are python variables, but can be accessed from the shell script. The __str__()
method of variable will be used for the variable representation in shell.