Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #66714
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python@mrabarnett.plus.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'subject:text': 0.05; 'string': 0.09; 'subject:into': 0.09; 'subject:string': 0.09; 'variable,': 0.09; 'python': 0.11; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'occurs.': 0.16; 'received:192.168.1.4': 0.16; 'subject:search': 0.16; 'subject:variable': 0.16; 'words.': 0.16; 'essential': 0.16; 'wrote:': 0.18; 'print': 0.22; 'header:User-Agent:1': 0.23; 'please?': 0.24; 'replace': 0.24; 'header:In-Reply-To:1': 0.27; 'kevin': 0.30; 'lines': 0.31; 'two': 0.37; 'list': 0.37; 'e.g.': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'times': 0.62; 'total': 0.65; 'different': 0.65; 'results': 0.69; '2.7.': 0.84; 'carries': 0.91 |
| X-CM-Score | 0.00 |
| X-CNFS-Analysis | v=2.1 cv=eZmzft0H c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=sASEtNAQL0YA:10 a=jO7lqlrM8jMA:10 a=ihvODaAuJD4A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=9rLSLMRDN9wA:10 a=zv1LiPhDcNNucFRH5BwA:9 a=QEXdDO2ut3YA:10 |
| X-AUTH | mrabarnett:2500 |
| Date | Wed, 19 Feb 2014 19:46:50 +0000 |
| From | MRAB <python@mrabarnett.plus.com> |
| User-Agent | Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Insert variable into text search string |
| References | <7a20fe74-e689-4261-b608-73d0f49736f3@googlegroups.com> |
| In-Reply-To | <7a20fe74-e689-4261-b608-73d0f49736f3@googlegroups.com> |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| 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.7162.1392839218.18130.python-list@python.org> (permalink) |
| Lines | 17 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1392839218 news.xs4all.nl 2832 [2001:888:2000:d::a6]:44083 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:66714 |
Show key headers only | View raw
On 2014-02-19 19:39, Kevin Glover wrote:
> These two lines are from a program that carries out a phrase search of Wikipedia and returns the total number of times that the specific phrase occurs. It is essential that the search contains an apostrophe:
>
> results = w.search("\"of the cat's\"", type=ALL, start=1, count=1)
> print results.total
>
> I want to replace the word "cat" with a variable, e.g.
>
> q = "cat"
>
> so that I can generate the same search format for a list of different words. How do I format the search string to include the variable, please? I am using Python 2.7.
>
Try string concatenation:
results = w.search("\"of the " + q + "'s\"", type=ALL, start=1,
count=1)
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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