I have read Why is Python giving me "an integer is required" when it shouldn't be?. It is nearly a complete solution for my issue, but not quite.
Here is my code:
#! usr/local/bin/python3.6
# coding: utf-8
from os import getcwd, listdir
import psycopg2
from io import open
conn = psycopg2.connect("dbname=ktab user=malikarumi")
cur = conn.cursor()
path = getcwd()
filenames = listdir(path)
for filename in filenames:
with open(filename, 'r', 'utf-16') as f:
f1 = f.read()
cur.execute("INSERT INTO testable (title, content, chron_date, clock)\
VALUES (%s, %s, %s, %s)"),
(filename, f1, '2017-12-30', '23:59:00'),
conn.commit()
cur.close()
conn.close()
After reading the older SO post, I modified my code as above, so as to specify which io module I wanted and restrict the os modules to the two I was using. Sublime Text 3 has a tooltip which indicates I am calling io.open(), but when I run the code, it is plainly os.open() (I know because of the error):
(lifeandtimes) malikarumi@Tetuoan2:~/Projects/Progress_Logs/2017$
python ktab_odt4.py
Traceback (most recent call last):
File "ktab_odt4.py", line 17, in <module>
with open(filename, 'r', 'utf-16') as f:
TypeError: an integer is required (got type str)
Note: I already tried with io.open() and import io. In both cases pylint squawked and the interpreter gave me name errors. Using 'rb' got past pylint but the interpreter still gives me the TypeError. What is the workaround for this situation?