File: envs.rst

package info (click to toggle)
python-sh 2.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 900 kB
  • sloc: python: 4,157; makefile: 25
file content (33 lines) | stat: -rw-r--r-- 829 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
.. _environments:

Environments
============

The :ref:`_env <env>` special kwarg allows you to pass a dictionary of
environment variables and their corresponding values:

.. code-block:: python

	import sh
	sh.google_chrome(_env={"SOCKS_SERVER": "localhost:1234"})
	

:ref:`_env <env>` replaces your process's environment completely.  Only the
key-value pairs in :ref:`_env <env>` will be used for its environment.  If you
want to add new environment variables for a process *in addition to* your
existing environment, try something like this:

.. code-block:: python

    import os
    import sh
    
    new_env = os.environ.copy()
    new_env["SOCKS_SERVER"] = "localhost:1234"
    
    sh.google_chrome(_env=new_env)

.. seealso::

    To make an environment apply to all sh commands look into
    :ref:`default_arguments`.