简体   繁体   English

python 2.7的logging.info(string)和换行符

[英]python 2.7's logging.info(string) and newline characters

Does python 2.7's logging.info(string) (import logging) automatically strip newline characters from the given string? python 2.7的logging.info(string)(import logging)是否会自动从给定的字符串中删除换行符? If not, is there a command to make it behave like that? 如果没有,是否有命令使它像这样运行? If so which command is that? 如果是这样,那是哪个命令?

Thank's a lot! 非常感谢!

No, it will not automatically strip newlines. 不,它不会自动删除换行符。

You can remove them yourself by calling the .replace() method of the string: 您可以通过调用字符串的.replace()方法自己删除它们:

without_newlines = my_string.replace("\n", "")

(Another, slightly more potentially efficient option is to use the deletion feature of .translate() , but .replace() may be more readable if you don't care about high levels of optimization.) (另一种可能更有效的选择是使用.translate()的删除功能,但如果您不关心高级优化,则.replace()可能更具可读性。)

Refer to to pydoc: logging.debug 请参考pydoc: logging.debug

The format is like what you write in print() 格式类似于您在print()中编写的格式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM