gpt4 book ai didi

Python,拆分字符串

转载 作者:太空狗 更新时间:2023-10-30 02:06:16 25 4
gpt4 key购买 nike

我有一个很大的字符串文本文件,我想每 117 个字符拆分一次字符串,然后将接下来的 117 个字符放在换行符上,依此类推,直到文件末尾。

我试过这个:`s = """出于可见性原因,我删除了字符串"""空格 = """

"""file = open('testoutput.txt', 'w')而 s: 打印 s[:10] 输出 = 输出 + s + """

"""
s = s[10:]

文件.写入(输出)文件.close()打印“完成”`

但文件中的最终输出看起来像这样的级联问题:`这个 [SHIFT]r[BACKSPACE] 分子及其后代将 av[BACKSPACE][BACKSPACE] 由于突变而变化

T]r[BACKSPACE]molecule and its descendants would av[BACKSPACE][BACKSPACE]vary because of mutations



ACE]molecule and its descendants would av[BACKSPACE][BACKSPACE]vary because of mutations



le and its descendants would av[BACKSPACE][BACKSPACE]vary because of mutations



descendants would av[BACKSPACE][BACKSPACE]vary because of mutations



ts would av[BACKSPACE][BACKSPACE]vary because of mutations



v[BACKSPACE][BACKSPACE]vary because of mutations



E][BACKSPACE]vary because of mutations



CE]vary because of mutations



cause of mutations



utations

`

最佳答案

while s:
print s[:117]
s = s[117:]

关于Python,拆分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4882569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com