当前位置: 首页 > 面试题库 >

Python未将完整字符串写入文件

孙池暝
2023-03-14
问题内容

我试图将比对的蛋白质序列输出到文件,但是,每次我尝试将字符串写入文件时,输出字符串都会被截断。我尝试写入的字符串长4603个字符,并以正确的字符数打印到控制台。我要附加的第一段代码与输出变量本身有关。我将在此处包括完整的字符串,因为对我而言,在写入文件时字符串被截断的方式是可以重现的。

out=open('out.7.9.12.txt','a+')

score_dict={}
Max='1ZER'
al1='XMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX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XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

score_dict[Max]=al1

for name,sequence in score_dict.items():
            out.write('>')
            out.write(name)
            out.write('\n')
            for line in score_dict[name]:
                    out.write(line)
            out.write('\n')

使用此代码段,文件的输出应等于al1。但是,该文件的输出如下:

XMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX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XXXXXXXXXXXXXXXXXXAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXVXXEKIXXXXPXXXXLIPSTPEXXEMSXEMLXXXXQXXLCXXXSXYXVXXXXXRFXKVPXQXXXXXXXXQIXLQXGXLVDVXXRXXIXPXXXHNXNXXFYRKXLXXXFLXXXXXXXXEIXVXSEXXXXXXKXXSXXXXXRYSXLXXXHXQNMXXXDKIXXXXXXXXXXKVXPTQXXIXXIWXXXXGXXXKQDXXXQVLXXDVXXXXSGADMLXXAKXXXSIAXNCQVXXEXXLXLEXXNCGXHSVVMEXRPRXXXKXTAKLXXIIDFLASVHNTDNNKKLDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

将这两个序列粘贴到文字处理器中并计算字符数,将显示第一个包含4603个字符,第二个包含4090个字符。

我为这里的顺序块表示歉意,但是我不确定我还能如何准确表示这个问题。

编辑:该代码现在应该工作(我修复了缓冲区问题和引号问题)


问题答案:

您是否在最后关闭文件?可能是某些数据位于缓冲区中,所以在完成后关闭文件是很不错的(如果由于某种原因不想关闭文件,则可以冲洗()它)。

更好的是,使用with将在完成或发生异常时为您关闭文件的构造:

with open('out.7.9.12.txt','a+') as out:
   # the rest of your code indented under here
   # ....
   score_dict={}
   Max=245

从flush()文档中注意:

注意
flush()不一定会将文件的数据写入磁盘。使用flush()后跟os.fsync()来确保此行为



 类似资料:
  • 问题内容: 我将日志保存到sdcard上的.txt文件中,但是一旦保存了两行,它就会覆盖它并重新开始? 这是我的代码: 在恢复中挂载/ data后,/ sdcard和/ data / media / 0中的日志文件会显示完整的日志历史记录,但在设备开机时不会显示完整的日志历史记录 问题答案: 这是完成的方式。以下示例代码在单击提交按钮后将详细信息保存到文件中: 希望这可以帮助 :)

  • wef:使用apache poi写入xlsm(Excel 2007) 当我向文件中写入一个简单的字符串时,我无法打开该文件。错误-“Excel无法打开文件“Test1.xlsm”,因为文件格式或文件扩展名无效”

  • 问题内容: 有没有一种方法可以将字符串直接写入tarfile?从http://docs.python.org/library/tarfile.html看来,只能添加已经写入文件系统的文件。 问题答案: 我想说,通过将StringIO作为文件对象传递给TarInfo e TarFile.addfile是有可能的。 很粗糙,但可以

  • 问题内容: 我正在尝试使用以下脚本创建一个包含Python中字符串列表内容的csv文件。但是,当我检查输出文件时,发现每个字符都用逗号分隔。如何指示定界列表中的每个字符串而不是每个字符? 我检查了PEP 305,找不到任何特定的东西。 问题答案: 该方法以iterable作为参数。您的结果集必须是列表(列)的列表(行)。 将 行 参数写入编写者的文件对象,并根据当前方言格式化。 执行以下任一操作:

  • 问题内容: 我认为能够将文本文件读入和写出字符串数组的能力是相当普遍的要求。从一种语言开始消除最初访问数据库的需求时,它也非常有用。Golang中是否存在? 例如 和 我宁愿使用现有的而不是重复的。 问题答案: 从Go1.1版本开始,有一个bufio.Scanner API可以轻松读取文件中的行。考虑上面的以下示例,该示例使用Scanner重写:

  • 问题内容: 我有一个返回字符串的函数。该字符串包含回车符和换行符(0x0D,0x0A)。但是,当我写入文件时,它仅包含换行符。有没有一种方法可以使输出包括回车和换行符。 问题答案: 如果要写入字节,则应以二进制模式打开文件。