Read a Txt File Without Newlines \n in Python

Viewed 51

Get txt File content Without the \n or \t ; here is the code:

pos = requests.get(url,headers=headers)
print("content-type: text/html\n\n")
print(pos.content)

Output:

\n\n
some text here some text here
\n\n
some text here some text here
\n\n
2 Answers

When you call a new print statement, the string will be printed on a newline. For it to be on the same line, you can use string formatting.

print("content-type: text/html\n\n{}".format(post.content))

Use response.text :

import requests

headers = {'Accept-Encoding': 'identity'}
pos = requests.get("https://www.sec.gov/Archives/edgar/data/840551/000117184322006038/0001171843-22-006038.txt",headers=headers)
html = pos.text

>>> print(html)

enter image description here

Related