Message355355
Yes, this is not a good place to use regular expressions.
Using regular expressions:
def actual_re_demo():
import re
# This is an indefinite string...
text = "tf.where(condition, x=None, y=None, name=None) tf.batch_gather ..."
# Converting fields that need to be matched into regular expressions is also an indefinite string
pattern_str = re.compile('(tf\\.batch_gather)|(None)|(a1)')
#I don't know how many, so it's over \ \ 100 \ \ n
x = re.sub(pattern_str, '`'+'\\1\\2'+'`', text)
print(x)
# hope if:tf.Prefix needs to match,The result will be:`tf.xx`,
# But in fact, it's not just TF. As a prefix, it's a random character, it can be a suffix, it can be other characters.
# If more than 100, the result is=>:989¡¢£¤¥¦§89¨©ª«¬®¯89°±²³´µ¶·89¸¹º»¼½¾¿890123`, name=`None@ABCDEFG89HIJKLMNO89PQRSTUVW89XYZ[\]^_89`abcdefg89hijklmno89pqrstuvw89xyz{|}~8901234567890123456789
# I noticed in the comment area that it was caused by a confusion of Radix, which seems to be embarrassing.
Use replace to solve it. It looks much better.
def no_need_re():
text = "tf.where(condition, x=None, y=None, name=None) tf.batch_gather ..."
pattern_list = ['tf.batch_gather', 'None']
for item in pattern_list:
text=text.replace(item, '`'+item+'`')
print(text)
no_need_re()
Expect to report an error directly if it exceeds the limit, instead of overflowing the character, like this:
989¡¢£¤¥¦§89¨©ª«¬®¯89°±²³´µ¶·89¸¹º»¼½¾¿890123`, name=`None@ABCDEFG89HIJKLMNO89PQRSTUVW89XYZ[\]^_89`abcdefg89hijklmno89pqrstuvw89xyz{|}~8901234567890123456789 |
|
Date |
User |
Action |
Args |
2019-10-25 07:24:01 | veaba | set | recipients:
+ veaba, ezio.melotti, mrabarnett, serhiy.storchaka, malin, veky |
2019-10-25 07:24:01 | veaba | set | messageid: <1571988241.08.0.12918263297.issue38582@roundup.psfhosted.org> |
2019-10-25 07:24:01 | veaba | link | issue38582 messages |
2019-10-25 07:24:00 | veaba | create | |
|