File tree 1 file changed +31
-0
lines changed
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:
2474
2474
- lists, e.g. ``"['A','B']" ``
2475
2475
- variables that are defined in the local names space, e.g. ``date ``
2476
2476
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
+
2477
2508
Here are some examples:
2478
2509
2479
2510
.. ipython :: python
You can’t perform that action at this time.
0 commit comments