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


Groups > comp.lang.python > #66728

Re: Insert variable into text search string

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:text': 0.05; 'subject:into': 0.09; 'subject:string': 0.09; 'supported,': 0.09; 'whichever': 0.09; 'cc:addr:python-list': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:search': 0.16; 'subject:variable': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'skip:% 10': 0.24; 'cc:2**0': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'am,': 0.29; 'kevin': 0.30; 'message- id:@mail.gmail.com': 0.30; 'but': 0.35; 'received:google.com': 0.35; 'much.': 0.36; 'thank': 0.38; 'whatever': 0.38; 'either': 0.39; 'different': 0.65; '20,': 0.68; 'results': 0.69; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=BUahCnQ6pbJsTkYbphK3zt7vQLeeLou0K8kOuUXSy78=; b=eR2X+bCuO2vyBAHkRLXg1qac2wdWOl64uEnFc0DHzeiIIjrKmgWIhZHSJZ0C/4lfjU +YxyWpXXlt71TcHfG23CJ/Ck76IB8eQHsBwuXOhMrdH6o26hBaw4EzJ+iiw+vR08cJMz mwSnaVFstJYFL/XTs24dxVaLukpTsJhkXHjwD/wYAxZSRbYH4VC5gzqirGPNzXiGVCGF KXWmkoYyCxDfy4KeLZqEYYFHhNiuTFhCfnVI+YjzVUr2hDkrRbtVvxPRQ2757qiMRji0 9MuWv1OsuhQ5LFIUZ+adfGDbvP2/8AP7XUG+w7WuXucUSXQSjAUQGvO+cGu6TSqo30R2 wABQ==
MIME-Version 1.0
X-Received by 10.66.160.2 with SMTP id xg2mr43144157pab.23.1392861981912; Wed, 19 Feb 2014 18:06:21 -0800 (PST)
In-Reply-To <6e8fa7a0-f943-4802-aedd-4672ad18c352@googlegroups.com>
References <7a20fe74-e689-4261-b608-73d0f49736f3@googlegroups.com> <6e8fa7a0-f943-4802-aedd-4672ad18c352@googlegroups.com>
Date Thu, 20 Feb 2014 13:06:21 +1100
Subject Re: Insert variable into text search string
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.7170.1392861986.18130.python-list@python.org> (permalink)
Lines 12
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1392861986 news.xs4all.nl 2841 [2001:888:2000:d::a6]:58187
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:66728

Show key headers only | 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