[Python Intermediate] Split the string according to a fixed length

[Python Intermediate] Split the string according to a fixed length

1. Background

Recently, there is a work of base64 encoding pictures into strings, refer to the blog:
[Python Intermediate] Base64 encoding converts picture data into strings
https://jn10010537.blog.csdn.net/article/details/131894686

After I encode the picture into a string, I write it into a python script and assign it to a variable, as shown below:

Create the ui_indicatePic.py text, and assign the string after the base64 encoded picture to indicatePic_2_base64_utf8.
insert image description here
Because I often modify this picture aesthetically, the string after base64 encoding the picture is actually a very, very long string.
For the sake of beauty, I need to manually enter and enter to form the effect of the picture above!
very tired! And not convenient enough!

The method is to use the findall function of the re module to split the string

re :提供了正则表达式匹配操作,正则表达式是一个特殊的字符序列,方便的检查一个字符串是否与某种模式匹配。
re.findall

Guess you like

Origin blog.csdn.net/jn10010537/article/details/131928875