I have created a link 'verbs.txt' in one directory to a text file 'verbs.txt' in another directory, and I'd like to be able to open the target file via its link. The 'verbs.txt' file was created w/ BBEdit; the link to it was created using Mac's option-command-drag for creating links (aka aliases).
Here's the minimal example (test.py), where the working directory is set to the directory containing the link:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import os
import re
parsePattern = re.compile( '(.+);(.+)' )
verbsSpanish = []
verbsEnglish = []
factor = 1
verbFile = open( 'verbs.txt', 'r' )
for line in verbFile:
match = parsePattern.search( line )
if match:
for i in range(factor):
verbsSpanish.append( match.group( 1 ) )
verbsEnglish.append( match.group( 2 ) )
else:
print( line + '\n')
print( 'Success' )
sys.exit()
It appears that the open()
function works, but the code fails at the for statement with the following traceback:
practice ____ ./test.py
Traceback (most recent call last):
File "./test.py", line 11, in <module>
for line in verbFile:
File "/Users/drjackbo/.pyenv/versions/3.8.5/lib/python3.8/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa4 in position 24: invalid start byte
The script runs correctly if 'verbs.txt' is a copy of, not a link to, the original file:
practice ____ ./test.py
Success