Hi there, I’m stuck and probably relatively simple python action. but for the life of me I can not figure it out. it for a skill to read ebooks… it works fine on that part but for the section to continue reading ebooks I am stuck on . basically I just wanted to write a dat file with a name of the book being read and a line count file that keeps tracks of the last line read.
i can write the the book path no problem. and read it but can not input it as a variable.
and the count i can neither write or import as a variable.
i want hard copy of the data then i continue listening to a book from where i last left off at after a power outage.
well here basically where I am stuck
#################
@intent_file_handler('continue.read.intent')
def handle_continue_read(self, message):
self.is_reading = True
self.speak(' one moment ')
#filepath = '/opt/mycroft/skills/gutenberg-library-skill/ebook/little_women' ### works as direct link
#cnt = 6 ## works fine
filepath = open("book.dat","r") ## TypeError: expected str, bytes or os.PathLike object, not _io.TextIOWrapper -- when inputting to -- with open(filepath) as f:
cnt = open("cnt.dat","r") ## out puts error TypeError: '_io.TextIOWrapper' object cannot be interpreted as an integer --- when inputting into -- for i in range(cnt):
with open(filepath) as f:
for i in range(cnt):
f.readline()
for line in (f):
if self.is_reading is False:
#print ('stopping book')
break
else:
#print ('reading book')
wait_while_speaking()
self.speak("{}".format(line))
cnt = cnt+1
file1 = open("cnt.dat","w") ## file1.write(cnt) ---TypeError: write() argument must be str, not int ---- can not write file
file1.write(cnt)
if self.is_reading is True:
self.is_reading = False