Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #66728

Re: Insert variable into text search string

References <7a20fe74-e689-4261-b608-73d0f49736f3@googlegroups.com> <6e8fa7a0-f943-4802-aedd-4672ad18c352@googlegroups.com>
Date 2014-02-20 13:06 +1100
Subject Re: Insert variable into text search string
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.7170.1392861986.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, Feb 20, 2014 at 7:15 AM, Kevin Glover <kevingloveruk@gmail.com> wrote:
> Thank you both so much. I had tried % but not successfully.

To do it with %, just do this:

whatever = "cat"
results = w.search("\"of the %s's\""%whatever, type=ALL, start=1, count=1)

Use either that or .format(), whichever you like - both are fully
supported, and they have different strengths.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Insert variable into text search string Kevin Glover <kevingloveruk@gmail.com> - 2014-02-19 11:39 -0800
  Re: Insert variable into text search string MRAB <python@mrabarnett.plus.com> - 2014-02-19 19:46 +0000
  Re: Insert variable into text search string Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2014-02-19 21:59 +0200
  Re: Insert variable into text search string Kevin Glover <kevingloveruk@gmail.com> - 2014-02-19 12:15 -0800
    Re: Insert variable into text search string Chris Angelico <rosuav@gmail.com> - 2014-02-20 13:06 +1100

csiph-web