code – Tools for representing JavaScript code — PyMongo 2.5 documentation

### Navigation

- index
- modules |
- next |
- previous |
- PyMongo 2.5 documentation »
- API Documentation »
- `bson` – BSON (Binary JSON) Encoding and Decoding »

# `code` – Tools for representing JavaScript code

Tools for representing JavaScript code in BSON.

class `bson.code.``Code`(code[, scope=None[, **kwargs]])

  Bases: `str`

  BSON’s JavaScript code type.

  Raises `TypeError` if code is not an instance of `basestring` (`str` in python 3) or scope is not `None` or an instance of `dict`.

  Scope variables can be set by passing a dictionary as the scope argument or by using keyword arguments. If a variable is set as a keyword argument it will override any setting for that variable in the scope dictionary.

  Parameters : | code: string containing JavaScript code to be evaluated scope (optional): dictionary representing the scope in which code should be evaluated - a mapping from identifiers (as strings) to values **kwargs (optional): scope variables can also be passed as keyword arguments

  New in version 1.9: Ability to pass scope values using keyword arguments.

  `scope`

    Scope dictionary for this instance.

### Navigation

- index
- modules |
- next |
- previous |
- PyMongo 2.5 documentation »
- API Documentation »
- `bson` – BSON (Binary JSON) Encoding and Decoding »