Problem--IOError: [Errno 13] Permission denied

patrick.waldo at patrick.waldo at
Sun Oct 28 22:25:04 CET 2007

Hi all,

After sludging my way through many obstacles with this interesting
puzzle of a text parsing program, I found myself with one final error:

Traceback (most recent call last):
  File "C:\Python24\Lib\site-packages\pythonwin\pywin\framework
\", line 310, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Documents and Settings\Patrick Waldo\My Documents\Python
\WORD\try5-2-file-1-all", line 77, in ?
    input =, 'r','utf8')
  File "C:\Python24\lib\", line 666, in open
    file =, mode, buffering)
IOError: [Errno 13] Permission denied: 'C:\\text_samples\\test\

The error doesn't stop the program from functioning as it should,
except the last line of every document gets split with | in between
the words, which is just strange.  I have no idea why either is
happening, but perhaps they are related.

Any ideas?

#For text files in a directory...
#Analyzes a randomly organized UTF8 document with EINECS, CAS,
Chemical, and Chemical Formula
#into a document structured as EINECS|CAS|Chemical|Chemical Formula.

import os
import codecs
import re

path = "C:\\text_samples\\test\\"
path2 = "C:\\text_samples\\test\\output\\"

EINECS = re.compile(r'^\d\d\d-\d\d\d-\d$')
FORMULA = re.compile(r'([A-Z][a-zA-Z0-9]*\.?[A-Za-z0-9]*/?[A-Za-
FALSE_POS = re.compile(r'^[A-Z][a-z]{4,40}\)?\.?')
FALSE_POS1 = re.compile(r'C\.I\..*')
FALSE_POS2 = re.compile(r'vit.*')
FALSE_NEG = re.compile(r'C\d+\.')

def iter_elements(tokens):
    product = []
    for tok in tokens:
        if EINECS.match(tok) and len(product) >= 3:
            match = re.match(FORMULA,product[-1])
            match_false_pos = re.match(FALSE_POS,product[-1])
            match_false_pos1 = re.match(FALSE_POS1,product[-1])
            match_false_pos2 = re.match(FALSE_POS2,product[2])
            match_false_neg = re.match(FALSE_NEG,product[-1])
            if match_false_neg:
                product[2:-1] = [' '.join(product[2:])]
                del product[-1]
                yield product
                product = []
            elif match_false_pos:
                product[2:-1] = [' '.join(product[2:])]
                del product[-1]
                yield product
                product = []
            elif match:
                product[2:-1] = [' '.join(product[2:-1])]
                yield product
                product = []
            elif match_false_pos1 or match_false_pos2:
                product[2:-1] = [' '.join(product[2:])]
                del product[-1]
                yield product
                product = []
                product[2:-1] = [' '.join(product[2:])]
                del product[-1]
                yield product
                product = []
    yield product

for text in os.listdir(path):
    input_text = os.path.join(path,text)
    output_text = os.path.join(path2,text)
    input =, 'r','utf8')
    output =, 'w', 'utf8')
    tokens =
    for element in iter_elements(tokens):

More information about the Python-list mailing list