re.sub(r'((?<=\A)|(?<=,))(?=,|\Z)', 'NA', ',1,,,two,3,,,') how does it work?

2026-08-10 Thread Veek M
look-ahead look-behind don't consume string so how does it advance through the string - could someone clearly explain how it works. re.sub(r'((?<=\A)|(?<=,))(?=,|\Z)', 'NA', ',1,,,two,3,,,') 'NA,1,NA,NA,two,3,NA,NA,NA' re.sub(r'(?https://mail.python.org/mailman3//lists/python-list.python.org

ANN: tumblelog 6.5.4: a static microblog generator

2026-08-10 Thread John Bokma via Python-list
Dear reader, I just released version 6.5.4 of tumblelog, a static microblog generator which generates HTML5, an RSS feed, a JSON feed and optionally tag pages from a single Markdown file with additional directives. Example microblog: https://plu.com/ GitHub: https://github.com/john-bokma

Re: re.sub(r'((?<=\A)|(?<=,))(?=,|\Z)', 'NA', ',1,,,two,3,,,') how does it work?

2026-08-10 Thread Jon Ribbens via Python-list
On 2026-08-09, Veek M wrote: > look-ahead look-behind don't consume string so how does it advance through > the string - could someone clearly explain how it works. > > re.sub(r'((?<=\A)|(?<=,))(?=,|\Z)', 'NA', ',1,,,two,3,,,') > 'NA,1,NA,NA,two,3,NA,NA,NA' It's matching the empty string. It'll

Re: open: 'ascii', 'backslashreplace' not behaving as expected - why?

2026-08-10 Thread Veek M
On Sat, 8 Aug 2026 04:25:43 - (UTC), Veek M wrote: > On Sat, 8 Aug 2026 04:22:59 - (UTC), Veek M wrote: > >> On Sat, 8 Aug 2026 01:19:32 - (UTC), Lawrence D’Oliveiro wrote: >> >>> b'\xef\xbf\xbf\n'.decode() >> >> Could you explain how it works and what exactly is going on? >> >> fh

Re: open: 'ascii', 'backslashreplace' not behaving as expected - why?

2026-08-10 Thread Veek M
On Sat, 8 Aug 2026 01:19:32 - (UTC), Lawrence D’Oliveiro wrote: > b'\xef\xbf\xbf\n'.decode() Could you explain how it works and what exactly is going on? fh.readline() returns a unicode string with the funny chars (bytes 0xff 0xff) encoded as \\xef \\xbf \\xbf - why is it \\? why not just u

Re: open: 'ascii', 'backslashreplace' not behaving as expected - why?

2026-08-10 Thread Veek M
On Sat, 8 Aug 2026 04:22:59 - (UTC), Veek M wrote: > On Sat, 8 Aug 2026 01:19:32 - (UTC), Lawrence D’Oliveiro wrote: > >> b'\xef\xbf\xbf\n'.decode() > > Could you explain how it works and what exactly is going on? > > fh.readline() returns a unicode string with the funny chars (bytes 0x

open: 'ascii', 'backslashreplace' not behaving as expected - why?

2026-08-10 Thread Veek M
So in kate, i Ctrl-Shift-U and type to enter a unicode codepoint of 0x. Then at the REPL prompt i do fh = open('/tmp/x', 'rt', -1, 'ascii', 'backslashreplace', None) and i get fh.readline() '\\xef\\xbf\\xbf\n' Since I wrote two bytes 0xff and 0xff into Kate - why am i getting 0xef 0