Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80517 > unrolled thread
| Started by | satishmlmlml@gmail.com |
|---|---|
| First post | 2014-11-11 01:37 -0800 |
| Last post | 2014-11-11 17:34 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
What is ?s here? satishmlmlml@gmail.com - 2014-11-11 01:37 -0800
Re: What is ?s here? Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-11 17:34 +0000
| From | satishmlmlml@gmail.com |
|---|---|
| Date | 2014-11-11 01:37 -0800 |
| Subject | What is ?s here? |
| Message-ID | <a4b767a7-9669-4b4a-8068-63c23c2ef1c0@googlegroups.com> |
What does ?s do in the following piece of code?
import re, pprint
text = open('books.xml').read()
pattern = '(?s)isbn="(.*?)".*?<title>(.*?)</title>'
found = re.findall(pattern, text)
mapping = {isbn: title for (isbn, title) in found}
pprint.pprint(mapping)
Here is books.xml
<catalog>
<book isbn="0-596-00128-2">
<title>Python & XML</title>
<date>December 2001</date>
<author>Jones, Drake</author>
</book>
</catalog>
[toc] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2014-11-11 17:34 +0000 |
| Message-ID | <m3thb9$vod$2@dont-email.me> |
| In reply to | #80517 |
On Tue, 11 Nov 2014 01:37:21 -0800, satishmlmlml wrote: > What does ?s do in the following piece of code? It tells you to learn about regex. -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web