File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -2474,6 +2474,37 @@ The right-hand side of the sub-expression (after a comparsion operator) can be:
24742474 - lists, e.g. ``"['A','B']" ``
24752475 - variables that are defined in the local names space, e.g. ``date ``
24762476
2477+ .. note ::
2478+
2479+ Passing a string to a query by interpolating it into the query
2480+ expression is not recommended. Simply assign the string of interest to a
2481+ variable and use that variable in an expression. For example, do this
2482+
2483+ .. code-block :: python
2484+
2485+ string = " HolyMoly'"
2486+ store.select(' df' , ' index == string' )
2487+
2488+ instead of this
2489+
2490+ .. code-block :: python
2491+
2492+ string = " HolyMoly'"
2493+ store.select(' df' , ' index == %s ' % string)
2494+
2495+ The latter will ** not ** work and will raise a `` SyntaxError `` .Note that
2496+ there' s a single quote followed by a double quote in the ``string``
2497+ variable.
2498+
2499+ If you * must* interpolate, use the `` ' %r ' `` format specifier
2500+
2501+ .. code- block:: python
2502+
2503+ store.select(' df' , ' index == %r ' % string)
2504+
2505+ which will quote `` string`` .
2506+
2507+
24772508 Here are some examples:
24782509
24792510.. ipython :: python
You can’t perform that action at this time.
0 commit comments