删除字符串中的NUL

2024-09-30 04:29:21 发布

您现在位置:Python中文网/ 问答频道 /正文

如何删除字符串中的NUL字符/空格? 我试着在这里使用完整的答案和评论。似乎他们都不适合我。在

例如,字符串是m o d e m

 for part_entry in part_list:
        partStr = unicode(part_entry[5])
        partStr.rstrip(' \t\r\n\0')
        logging.debug('******')
        logging.debug('PartName= '+partStr)

This is我当前编译的内容。在

我试着记录它,它像这样呈现输出

Python NUL logs


Tags: 字符串答案indebugforloggingunicode评论
1条回答
网友
1楼 · 发布于 2024-09-30 04:29:21

试试这个:

content = []
with open('file.ext', as 'r') as file_in:
    content = file_in.readlines()

new_content = [] 
for line in file:
    clean_line = line.replace('\00', '')
    new_content.append(clean_line)

with open('outfile.ext', 'w') as file_out:
    file_out.writelines(new_content)

相关问题 更多 >

    热门问题