Python Tools
- python_tools.bsh
Functions to help communicate with python
- array_to_python_ast_list_of_strings
- Arguments:
$1
- Variable to set result to. If the destination is an array, it will be unset (and become global)[
$2
…] - Array elements (to be treated as strings)
Set $1
to a python ast.literal_eval compliant string for an list of strings
Example
array_to_python_ast_list_of_strings x 1 '1"1' "2'2" stuff
# x=["1", "1\"1", "2'2", "stuff"]
- array_to_python_ast_list_of_literals
- Arguments:
$1
- Variable to set result to. If the destination is an array, it will be unset (and become global)[
$2
…] - Array elements (to be treated literally)
Set $1
to a python ast.literal_eval compliant string representing a “list of strings”
Example
array_to_python_ast_list_of_literals x 1 '"1\"1"' "\"2'2\"" 3.3
# x=[1, "1\"1", "2'2", 3.3]
array_to_python_ast_list_of_literals x 1+1
# x=[1+1], valid for python eval, but not ast.literal_eval
array_to_python_ast_list_of_literals x "$((1+1))"
# x=[2], valid for ast.literal_eval
- vsi::python::virtualenv_bin
- Arguments:
$1
- Virtual environment path, do not includebin
orScripts
$2
- Name of binary to run, without.exe
extension
A cross-OS compatible function to call a binary in a virtual environment folder that handles the differences between Windows and Linux.
Example
"$(vsi::python::virtualenv_bin "${my_python_dir}" pip)" install numpy