0
Follow
17
View

How do I avoid errors when python uses decode?

tongwenbin1984 注册会员
2023-02-28 22:27

or is it necessary to intercept all the bytes of the Chinese character?

guangyuduan 注册会员
2023-02-28 22:27

For example, do you want to intercept the first four bytes of 'ab string 'to mean 'ab character'?

didadoc 注册会员
2023-02-28 22:27
< div class = "md_content_show e397 data - v - 3967" = "" >

two step transcoding results, you need to obtain what data?

ecdysis3238 注册会员
2023-02-28 22:27

Post an example?
According to your thinking, can you consider one or both more cases?

rendongxing9 注册会员
2023-02-28 22:27

I want to intercept file names no more than 9 bytes Chinese characters are UTF8 encoding, taking up 3, so I need encode to intercept again,
So when you get a file name of "one, two, three" you can cut the first nine digits.
But the file name is "1, 1, 2, 3" and I'll get an error if I cut the first 9 digits.
May I ask how to handle such an exception?

djf0711 注册会员
2023-02-28 22:27
< div class = " md_content_show“数据- v - 3967 e397 = " " >

< div class = " aw-list-img " > img

WJKENT 注册会员
2023-02-28 22:27

First slice in transcoding can not do it
' string '[0:4].encode().decode
or say how how something

csxpeter0 注册会员
2023-02-28 22:27

I want to intercept file names no more than 9 bytes Chinese characters are UTF8 encoding, taking up 3, so I need encode to intercept again,
So when you get a file name of "one, two, three" you can cut the first nine digits.
But the file name is "1, 1, 2, 3" and I'll get an error if I cut the first 9 digits.
May I ask how to handle such an exception?

zhouguang 注册会员
2023-02-28 22:27

What do you need if the file name is 1, 1, 2, 3? If it is 1, 1, 2, the first three digits are captured by decode.

dujunting80 注册会员
2023-02-28 22:27

no error, I need to get "1, 1, 2". Remove the last two extra characters.
Shall I try catch two ifs... I think there might be a better way, so I came to ask

About the Author

Question Info

Publish Time
2023-02-28 22:27
Update Time
2023-02-28 22:27