Bottom Page

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
Quote
#2
In python2.6 and earlier you need indices in the format specs

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

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  ValueError: time data 'None' does not match format '%Y-%m-%dT%H:%M:%S.%f' rajesh3383 4 332 Sep-03-2020, 08:22 PM
Last Post: buran
  ValueError: could not convert string to float: RandomCoder 3 477 Jul-27-2020, 07:38 AM
Last Post: ndc85430
  find a string in a field in MongoDB Leon79 2 242 Jul-19-2020, 09:20 PM
Last Post: menator01
  Receiving ValueError("bad input shape {0}".format(shape)) error SuryaCitizen 2 460 Jun-01-2020, 06:45 AM
Last Post: pyzyx3qwerty
  getting error ValueError: time data '' does not match format '%H:%M' srisrinu 2 420 Apr-09-2020, 11:12 AM
Last Post: srisrinu
  How to compare two columns and highlight the unique values of column two using pandas shubhamjainj 0 692 Feb-24-2020, 06:19 AM
Last Post: shubhamjainj
  How can i limit length string? perrfect 3 366 Feb-10-2020, 04:52 PM
Last Post: Jendker
  MySQLdb._exceptions.ProgrammingError: not enough arguments for format string. farah97 0 600 Jan-22-2020, 03:49 AM
Last Post: farah97
  Highlight and remove specific string of text itsalmade 5 609 Dec-11-2019, 11:58 PM
Last Post: micseydel
  How to highlight the cell SriRajesh 3 618 Dec-08-2019, 02:17 PM
Last Post: michael1789

Forum Jump:


Users browsing this thread: 1 Guest(s)