Python Forum
Highlight/Underline a string | ValueError: zero length field name in format
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Highlight/Underline a string | ValueError: zero length field name in format
#1
Hi, I'm building a python script which put an underline on a matched string on my regex pattern. Issue is when migrated to 2.6 I'm getting the below traceback. What would be the correct way to build this correctly?

finalout = re.sub(r'>.*(?=.*)', lambda m: '\x1b[4m{}\x1b[0m'.format(m.group()),compout)
print finalout
Error:
Traceback (most recent call last): File "compcon.py", line 313, in <module> main() File "compcon.py", line 302, in main finalout = re.sub(r'>.*(?=.*)', lambda m: '\x1b[4m{}\x1b[0m'.format(m.group()),compout) File "/usr/lib64/python2.6/re.py", line 151, in sub return _compile(pattern, 0).sub(repl, string, count) File "compcon.py", line 302, in <lambda> finalout = re.sub(r'>.*(?=.*)', lambda m: '\x1b[4m{}\x1b[0m'.format(m.group()),compout) ValueError: zero length field name in format
Reply
#2
In python2.6 and earlier you need indices in the format specs

try:
'\x1b[4m{0}\x1b[0m'.format(m.group())
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  highlight the columns and capture amy83 0 773 Mar-24-2023, 07:19 PM
Last Post: amy83
  Set string in custom format korenron 4 1,048 Jan-16-2023, 07:46 PM
Last Post: mutantGOD
  Format String NewPi 2 908 Oct-10-2022, 05:50 PM
Last Post: NewPi
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,011 May-17-2022, 11:38 AM
Last Post: Larz60+
  TypeError: not enough arguments for format string MaartenRo 6 2,858 Jan-09-2022, 06:46 PM
Last Post: ibreeden
  How to get datetime from numeric format field klllmmm 3 1,957 Nov-06-2021, 03:26 PM
Last Post: snippsat
  string format challenge jfc 2 1,741 Oct-23-2021, 10:30 AM
Last Post: ibreeden
  Print first day of the week as string in date format MyerzzD 2 1,979 Sep-29-2021, 06:43 AM
Last Post: MyerzzD
  string.format() suddenly causing errors with google drive API zwitrader 0 1,733 Jun-28-2021, 11:38 PM
Last Post: zwitrader
  String to Date format SAF 2 2,412 Apr-06-2021, 02:09 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020