【问题标题】:How to edit .cs files created with Visual Studio with python 3 script如何使用 python 3 脚本编辑使用 Visual Studio 创建的 .cs 文件
【发布时间】:2017-02-19 15:38:51
【问题描述】:

我正在尝试编写一个 python 脚本来搜索和替换我的一些 C# 代码,但是我遇到了编码和 BOM 的问题。例如,我试图比较文件开头的字符串,但 BOM 导致匹配不匹配。

with open(filename) as f:
    lines = f.readlines()
if lines[0] == '//\n':
    # fails even though the file begins with //

【问题讨论】:

  • dunno 关于 python 但 c# 不包括通过 readline 准备好的行中的行尾字符。什么是 BOM
  • BOM 是字节顺序标记。它用于指示文件的编码方式。

标签: c# python unicode


【解决方案1】:

我必须在公开电话中添加encoding='utf-8-sig'。读写调用都必须要有。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多