Reading two text files line by line simultaneously

with open(“textfile1”) as textfile1, open(“textfile2″) as textfile2: for x, y in izip(textfile1, textfile2): x = x.strip() y = y.strip() print(f”{x}\t{y}”) In Python 2, replace built-in zip with itertools.izip: from itertools import izip with open(“textfile1”) as textfile1, open(“textfile2”) as textfile2: for x, y in izip(textfile1, textfile2): x = x.strip() y = y.strip() print(“{0}\t{1}”.format(x, y))

ReadFile in Base64 Nodejs

Latest and greatest way to do this: Node supports file and buffer operations with the base64 encoding: const fs = require(‘fs’); const contents = fs.readFileSync(‘/path/to/file.jpg’, {encoding: ‘base64’}); Or using the new promises API: const fs = require(‘fs’).promises; const contents = await fs.readFile(‘/path/to/file.jpg’, {encoding: ‘base64’});

open read and close a file in 1 line of code

You don’t really have to close it – Python will do it automatically either during garbage collection or at program exit. But as @delnan noted, it’s better practice to explicitly close it for various reasons. So, what you can do to keep it short, simple and explicit: with open(‘pagehead.section.htm’, ‘r’) as f: output = f.read() … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)