在python中打开/编码文本文件时遇到问题

2024-05-16 19:33:29 发布

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

以下是原始文本:

Issue / Problem Encountered                         Solution / Lessons

• Sample result on the print out was reported with a

“sample not seen” message indication

• Symbol character (*, ?) next to the sample value

result

• Impact :

– Wrong result / NC generation

– Downtime and delay in Lot disposition

Check for print out errors like:

•    If an error is displayed for example:

“sample not seen” refer to SOP- 013499 and repeat sample.

•    Sample result should not have an

interrogation mark before the sample value.

• Impact to the area:

– Minimize possible OOS results – Minimize NC

– Reduce cost for OOS

Investigation

Always ensure to verify that the print out report:

Does not has the message “sample not seen” and the symbol

“sample not

seen” message

Sample result should not have an interrogation mark before the sample value

characters on the sample value result

现在,我使用以下代码来处理数据:

for ix, f in enumerate(listdir(directory_learning_group)):
    if isfile(join(directory_learning_group,f)):

        if "OPL" in f:
            try:
                dataset_outer_folder_OPL.loc[ix, "ID"] = f.split('_')[0]
                dataset_outer_folder_OPL.loc[ix, "Filename"] = f

                # Open a file
                fd = io.open(directory_learning_group+'{}'.format(f), encoding = 'utf8', errors = 'ignore')

                # Reading text
                ret = fd.read()
                dataset_outer_folder_OPL.loc[ix, "Text"] = ret
            except:
                print(f)
dataset_learning_group_OPL= dataset_learning_group_OPL.reset_index(drop = True)

并最终得到以下结果:

'A\x00M\x00L\x00 \x006\x00 \x00P\x00U\x00R\x00 \x00O\x00n\x00e\x00-\x00P\x00o\x00i\x00n\x00t\x00 \x00L\x00e\x00s\x00s\x00o\x00n\x00:\x00 \x00I\x00n\x00c\x00o\x00r\x00r\x00e\x00c\x00t\x00 \x00E\x00n\x00d\x00o\x00t\x00o\x00x\x00i\x00n\x00 \x00r\x00e\x00s\x00u\x00l\x00t\x00 \x00o\x00n\x00 \x00t\x00h\x00e\x00 \x00p\x00r\x00i\x00n\x00t\x00 \x00o\x00u\x00t\x00 \x00r\x00e\x00p\x00o\x00r\x00t\

我很难理解这里到底发生了什么。这个.txt看起来与我能够毫无问题地读入的其他文件没有什么不同

即使我们尝试对其进行解码/编码,也毫无帮助

任何帮助/指导都将不胜感激


Tags: thesamplegroupnotresultdatasetlearningprint
1条回答
网友
1楼 · 发布于 2024-05-16 19:33:29

您可能应该将您的全部代码发布到问题中。无论如何,我用您发布的内容测试了一个原始文本文件,它适用于Python 3.x上的以下代码:

with open('10020_OPL Endotoxin testing.txt', 'rb') as f:
    file = f.readlines()
    print(file)

相关问题 更多 >