gpt4 book ai didi

python - 为什么这些字符串被评估为不相等?

转载 作者:行者123 更新时间:2023-11-30 23:27:24 25 4
gpt4 key购买 nike

这是 vim 脚本 x.vim:

python << endpy
import vim
import time
import os
cb = vim.current.buffer
bufferString = '\n'.join(cb[:])
with open(cb.name, "r") as currentFile:
fileString = currentFile.read()
print bufferString
print "================="
print fileString
if bufferString != fileString:
print "File changed!"
else:
print "Nothing changed!"
endpy

在vim中打开脚本并输入:so %,它会打印出文件和缓冲区,根据python,它们是不同的,但是通过目测,你可以看到它们明显相等。为什么?

最佳答案

您所读取的文件的最后一行末尾可能有一个换行符。但是,从 vim 获取行并用 \n 连接它们将在最后一行的末尾没有换行符

关于python - 为什么这些字符串被评估为不相等?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22082767/

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