What I’m trying to do:
Use the FileLoader module to upload and parse a plain text file, line by line.
What I’ve tried and what’s not working:
I’ve tried several different methods to parse it including readline() and split(’\n’). Nothing seems to work.
Code Sample:
# this is a formatted code snippet.
# paste your code between ```
def file_loader_transcript_change(self, file, **event_args):
"""This method is called when a new file is loaded into this FileLoader"""
if file.name.endswith("_otter_ai.txt"):
fileReader = str(file.get_bytes()).split('\n')
for line in fileReader:
print(line)
pass
Clone link:
It’s not worth sharing at this point.
Hello @olesens and welcome!
I think a clone is worth sharing (with a sample text file) so that volunteers can jump right in without creating an app themselves.
Also, when you say that it is not working, do you mean that there’s an error or that nothing is printed? Any specifics there might help others.
1 Like
Fair enough. I appreciate the offer.
Here’s a link to the file I’m trying to load and parse.
Click the “Get transcript timecodes” button, select that file, and check the output. There should be multiple “Here comes a new line.” lines printed, but I only see one at the end. I would also expect the “\n” to be removed with the .split() function, but they’re still there.
Here’s the code I’m using:
def file_loader_transcript_change(self, file, **event_args):
“”“This method is called when a new file is loaded into this FileLoader”""
if file.name.endswith("_otter_ai.txt"):
fileReader = str(file.get_bytes()).split(’\n’)
for line in fileReader:
print(line)
print(‘Here comes a new line.’)
pass

1 Like
I figured it out. I simply needed to escape the backslash.

2 Likes