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

标签 python string vim

这是 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/

相关文章:

python - python中的UDP广播和自动服务器发现,TCP套接字不可用

string - 为什么我不能将 const(char)* 连接到 D 中的字符串?

string - 为什么 Powershell 中的 split() 函数不匹配整个给定的字符串?

vim - 如何在 Vim 中映射特定文件类型的键?

vim - 在 vimrc 中使用 autocmd 进行多重高亮

python - 在 Python 中添加以 checkin if-else block

python - 每个输入文件单独的测试用例?

javascript - 谷歌应用引擎中 channel api中的 channel 断开通知

比较文本文件中的字符串,然后打印整行

vim - 如何删除直到(不包括)该行的最后一个字符