简体   繁体   中英

How to remove word wraps in python text ouput?

Pycharm automatically wraps long outputs saved to txt into multiple lines, using \\n symbols which may force me to make changes to other code reading these files later. How to disable that word wrap option?

I didn't find a parameter, method nor Pycharm option for supressing the word wrap, but the workaround is to import textwrap package and define width long enough so the entire line will fit:

wrapper = textwrap.TextWrapper(width=600)
word_list = wrapper.wrap(text=wrapped_line)
text_file.write(str(word_list))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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