Re: File Creation Not Working In A Thread Class?



It's difficult to know what's wrong with the code you posted because:

* it is not self-contained: otherFile, fileName, pattern are names
which you do not define;

* the IOError you reported earlier can't arise as a result of running
this code.

* you claim it works unless you put it in a subclass of
threading.Thread. Why don't you post this instead, and show us the
traceback?

HTH

FWIW, my crystal ball (whose predictions I don't usually report!) tells
me the same as Garry Herron's.

Here's the thread class:

#single file is the file we're working on, whose name is passed into the class and which does exist
#matrix is a list of lists that contains info about the files - for this example, [c][0] contains a string, [c][2] contains true or false, and [c][3] contains a pattern to match
#tfValue is another true or false value


class FileProcThread(threading.Thread):
def __init__(self, singleFile, matrix, tfValue):
self.singleFile = singleFile
self.matrix = matrix
self.tfValue = tfValue
threading.Thread.__init__(self)
def run(self):
(dirName, fileName) = os.path.split(self.singleFile)
f = open(self.singleFile).readlines()
copying = False
for i in range(len(f)):
for c in range (len(self.matrix)):
if (re.search(self.matrix[c][3], f[i])):
if (self.matrix[c][2] == True):
copying = True
if os.name == "posix":
if (self.tfValue == False):
tempfileName = "\"proctemp/" + self.matrix[c][0] + "_tmp_" + fileName +
".txt\""
else:
tempfileName = "\"proctemp/" + self.matrix[c][0] + "_other.txt\""
else:
if (self.tfValue == False):
tempfileName = "\"proctemp\\" + self.matrix[c][0] + "_tmp_" + fileName + ".txt\""
else:
tempfileName = "\"proctemp\\" + self.matrix[c][0] + "_other.txt\""
else:
copying = False
if (re.search(self.matrix[c][4], f[i])):
copying = False
if (copying):
print "We're in copying, and tempfileName is: %s...\n" % tempfileName
#The above line correctly prints the temporary file name every time! The directory exists, too!
g = open(tempfileName, 'a') #This does not work. Notice I do NOT have quotes around tempfileName, as I said.
g.write(f[i])
g.close()

Like I said, this works FINE outside the thread class. I hope that the formatting comes through...
.



Relevant Pages

  • Re: File Creation Not Working In A Thread Class?
    ... When I put the same line in a thread class, it no longer works, and I ... It's telling you that you haven't got a file called 'fileName'. ... otherFile, fileName, pattern are names ... my crystal ball (whose predictions I don't usually report!) ...
    (comp.lang.python)
  • Re: Found a big mistake...still need your help!
    ... The column from which you are copying is text, ... Tom Ellison ... I generated a report, The Associate ID being the one and only ... list all the recorded times for the assocaite it will look something ...
    (microsoft.public.access.reports)
  • Re: help issues
    ... > Pop quiz: How do you copy a string? ... > Time yourself on finding the help topic on copying ... > Report your results back here. ...
    (borland.public.delphi.non-technical)
  • Yes/No and default values
    ... the check boxes to be white and blank until checked. ... there a way of storing the Yes and No choices as text? ... there is a report based on the form. ... copying one from the form to the report. ...
    (microsoft.public.access.gettingstarted)
  • Re: help issues
    ... >>Time yourself on finding the help topic on copying ... >>Report your results back here. ... filter on Delphi for Win32 ... Edmund ...
    (borland.public.delphi.non-technical)