Read a Txt File Without Newlines n in Python

Question:

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

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

Output:

nn
some text here some text here
nn
some text here some text here
nn
Asked By: Jav Ll

||

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/htmlnn{}".format(post.content))
Answered By: hysteriafg

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

Answered By: L'Artiste
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.