How do you print a string after it's been searched for an RE?

John Salerno johnjsal at gmail.com
Thu Jun 23 17:14:16 EDT 2011


On Jun 23, 3:47 pm, Ian Kelly <ian.g.ke... at gmail.com> wrote:
> On Thu, Jun 23, 2011 at 1:58 PM, John Salerno <johnj... at gmail.com> wrote:
> > After I've run the re.search function on a string and no match was
> > found, how can I access that string? When I try to print it directly,
> > it's an empty string, I assume because it has been "consumed." How do
> > I prevent this?
>
> This has nothing to do with regular expressions. It would appear that
> page.read() is letting you read the response body multiple times in
> 2.x but not in 3.x, probably due to a change in buffering.  Just store
> the string in a variable and avoid calling page.read() multiple times.

Thank you. That worked, and as a result I think my code will look
cleaner.



More information about the Python-list mailing list