How can I write a file with this script without empty blank lines? That is, when writing to a file for some reason I’m not aware, "\ n" is added to each line. I don't need this. Code:

import requests addr = requests.get('http://fh79272k.bget.ru/py_test/index.html') #addr = requests.get('http://prozaik.16mb.com/works/weekend_projects/site_himmler_homepage/index.php') print(addr.status_code) print(addr.text) try: f2 = open("text2.txt", 'w') except Exception: print('open error') except: print('error') else: try: f2.write(addr.text) except Exception: print('write error') except: print('error') else: print('write OK') finally: f2.close() 

Closed due to the fact that off-topic participants jfs , aleksandr barakin , zRrr , user194374, Nicolas Chabanovsky Mar 28 '16 at 7:30 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reasons:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Nicolas Chabanovsky
  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - jfs, aleksandr barakin, zRrr, Community Spirit
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • apparently, they are written in addr.text / addr.status_code, of.maunal does not say anything about such features, dip3 without a wiper writes to one line with several commands. - etki

1 answer 1

Launched your sample code. Received exactly the same text as in the source code of the page http://fh79272k.bget.ru/py_test/index.html

I repent, I tried in Nix, Python2.7. In order of delirium: maybe dig in the direction of os.linesep and so on. system parameters?

  • Checked for 3.4 (win7) - the same thing, no extra \ n - gil9red