psychopy.org | Reference | Downloads | Github

Error in JS about cannot read from null when reading from file


I have written the following python code

correct = 0
totCorr = 0
filename = "file_which.txt"
filec = open(filename, "r")
lines = filec.read()
#lines = lines[0]
#lines = [int(line.rstrip()) for line in lines]
filec.close()
if lines[0]== 1:
    expInfo["file_for_practice"]="practice1.xlsx"
    filer = open(filename, "w")
    filer.write("2")
else:
    expInfo["file_for_practice"]="practice2.xlsx"
    filer = open(filename, "w")
    filer.write("1")
filer.close()

which successfully gets converted to JS like so

correct = 0;
totCorr = 0;
filename = "file_which.txt";
filec = open(filename, "r");
lines = filec.read();
filec.close();
if ((lines[0] === 1)) {
    expInfo["file_for_practice"] = "practice1.xlsx";
    filer = open(filename, "w");
    filer.write("2");
} else {
    expInfo["file_for_practice"] = "practice2.xlsx";
    filer = open(filename, "w");
    filer.write("1");
}
filer.close();

But I keep getting a TypeError whether I use read or readlines (screenshot). I am wondering what i might be doing wrong. I have not written javascript and I went over the cheat sheet but could not find something about reading from a file.
I must mention that the code runs locally but fails in local JS Debug.
Kindly suggest what I might be doing wrong.