JavaScript 在末尾添加“·”字符
JavaScript adding "·" character to endline
所以我正在尝试 运行 tests.js 我写的 python 代码,一切看起来都很好,但是在每一行的末尾 ("\n"字符),tests.js 文件附加了一个“·”字符。该文件在内部使用 toString() 方法将 python 输出转换为字符串,然后使用 toEqual().
将其与预期字符串进行比较
我的代码:
def print_help():
print("""Usage :-
$ ./task add 2 hello world # Add a new item with priority 2 and text "hello world" to the list
$ ./task ls # Show incomplete priority list items sorted by priority in ascending order
$ ./task del INDEX # Delete the incomplete item with the given index
$ ./task done INDEX # Mark the incomplete item with the given index as complete
$ ./task help # Show usage
$ ./task report # Statistics""", end="")
输出:
tests.js代码:
test("prints help", () => {
let received = execSync(tasksTxtCli("help")).toString("utf8");
expect(received).toEqual(expect.stringContaining(usage));
});
我不知道您在 Node.js 中使用什么作为输出,但这很可能实际上不是中间点字符,而是您的终端仿真器无法打印的字符。
换句话说,您所看到的 并不存在。只是那里有 东西。
我认为这是 \r\n
和 \n
换行符的区别。您的比较字符串可能没有 \r\n
,但 Python 输出可能有。
如果您想真正确定它是什么,请将您的 Python 输出通过管道传输到一个文件,然后使用十六进制编辑器将其打开。或者甚至,只是不转换为字符串并使用 console.log()
(或 util.inspect()
)来查看二进制输出的十六进制表示。
根据我的解决方案将您的代码修改为:
def print_help():
help="""Usage :-
$ ./task add 2 hello world # Add a new item with priority 2 and text "hello world" to the list
$ ./task ls # Show incomplete priority list items sorted by priority in ascending order
$ ./task del INDEX # Delete the incomplete item with the given index
$ ./task done INDEX # Mark the incomplete item with the given index as complete
$ ./task help # Show usage
$ ./task report # Statistics"""
sys.stdout.buffer.write(help.encode('utf8'))
这样,命令行中就不会出现点(.)了。
参考:https://github.com/nseadlc-2020/package-todo-cli-task/issues/12
所以我正在尝试 运行 tests.js 我写的 python 代码,一切看起来都很好,但是在每一行的末尾 ("\n"字符),tests.js 文件附加了一个“·”字符。该文件在内部使用 toString() 方法将 python 输出转换为字符串,然后使用 toEqual().
将其与预期字符串进行比较我的代码:
def print_help():
print("""Usage :-
$ ./task add 2 hello world # Add a new item with priority 2 and text "hello world" to the list
$ ./task ls # Show incomplete priority list items sorted by priority in ascending order
$ ./task del INDEX # Delete the incomplete item with the given index
$ ./task done INDEX # Mark the incomplete item with the given index as complete
$ ./task help # Show usage
$ ./task report # Statistics""", end="")
输出:
tests.js代码:
test("prints help", () => {
let received = execSync(tasksTxtCli("help")).toString("utf8");
expect(received).toEqual(expect.stringContaining(usage));
});
我不知道您在 Node.js 中使用什么作为输出,但这很可能实际上不是中间点字符,而是您的终端仿真器无法打印的字符。
换句话说,您所看到的 并不存在。只是那里有 东西。
我认为这是 \r\n
和 \n
换行符的区别。您的比较字符串可能没有 \r\n
,但 Python 输出可能有。
如果您想真正确定它是什么,请将您的 Python 输出通过管道传输到一个文件,然后使用十六进制编辑器将其打开。或者甚至,只是不转换为字符串并使用 console.log()
(或 util.inspect()
)来查看二进制输出的十六进制表示。
根据我的解决方案将您的代码修改为:
def print_help():
help="""Usage :-
$ ./task add 2 hello world # Add a new item with priority 2 and text "hello world" to the list
$ ./task ls # Show incomplete priority list items sorted by priority in ascending order
$ ./task del INDEX # Delete the incomplete item with the given index
$ ./task done INDEX # Mark the incomplete item with the given index as complete
$ ./task help # Show usage
$ ./task report # Statistics"""
sys.stdout.buffer.write(help.encode('utf8'))
这样,命令行中就不会出现点(.)了。 参考:https://github.com/nseadlc-2020/package-todo-cli-task/issues/12