文件创建不在线程类中? [英] File Creation Not Working In A Thread Class?
问题描述
大家好,
提前感谢您提供的任何帮助!
我有这个代码:
g = open(fileName,'a'')
其中fileName是在它使用的行之前定义的。它工作正常
当我在线程类之外使用它时。
当我在线程类中放入相同的行时,它不再有效,我得到了
一个错误:
IOError:[Errno 2]没有这样的文件u''fileName''
不允许线程创建文件?
bc90021< py **** @ bc90021.netwrites:
大家好,
提前感谢您提供的任何帮助!
我有这个代码:
>
g = open(fileName,''a'')
其中fileName是在它被使用的行之前定义的。它工作正常
当我在线程类之外使用它时。
Wh我把同一行放在一个线程类中,它不再有效,我得到了
一个错误:
IOError:[Errno 2]没有这样的file u''fileName''
它告诉你,你没有一个名为''fileName''的文件。
发布触发此错误的代码将允许人们准确地诊断错误而不是猜测错误。
-
Arnaud
bc90021写道:
大家好,
预先感谢您提供的任何帮助!
我有这个代码:
g = open(fileName,''a'' )
我不相信你。我觉得你有类似的东西
g = open(''fileName'',''a'')
而不是(当你声明)
g = open(fileName,''a'')
你看到了区别吗?
>
培养阅读错误信息的技巧*非常*。您的错误说没有名为fileName的文件,如果您考虑磁盘上的内容,我敢打赌您找不到名称为fileName的文件。
Gary Herron
其中fileName在使用之前定义。工作正常
当我在线程类之外使用它。
当我在线程类中放入相同的行时,它不再有效,并且我得到
错误:
IOError:[Errno 2]没有这样的文件u''fileName''
不允许线程创建文件吗?
-
http:// mail。 python.org/mailman/listinfo/python-list
On Sun,2008年5月11日18:36:25 +0100,Arnaud Delobelle写道:
bc90021< py **** @ bc90021.netwrites:
>大家好,
提前感谢您的帮助!
我有这个代码:
g = open(fileName,''a'')
其中fileName是在它使用的行之前定义的。当我在外面使用它时它工作正常
一个线程类。
当我在线程类中放入相同的行时,它不再有效,并且我收到错误:
IOError:[Errno 2]没有这样的文件u''fileName''
它告诉你,你没有一个名为''fileName的文件''。发布
触发此错误的代码将允许人们准确诊断
错误而不是猜测。
f = open(otherFile).readlines()
我在len(f)的
:
for c在范围(0,24,1):
如果os.name ==" posix":
tempfileName =" \" proctemp /" + self.matrix [c] [0]
+" _tmp_" + fileName +" .txt \""
如果re.search(f [i],pattern):
g = open(tempfileName,''a '')
g.write(f [i])
除非我把它放在继承自
$ b的类中,否则这段代码完美无缺* $ b threading.Thread。在线程类中,一切正常(我可以看到
" c"值,我可以打印出f [i]中的每一行,它只是g
=开放行不起作用。
Hi All,
Thanks in advance for any and all help!
I have this code:
g = open(fileName, ''a'')
where fileName is defined before the line it''s used in. It works fine
when I use it outside a thread class.
When I put the same line in a thread class, it no longer works, and I get
an error:
IOError: [Errno 2] no such file u''fileName''
Are threads not allowed to create files?
bc90021 <py****@bc90021.netwrites:
Hi All,
Thanks in advance for any and all help!
I have this code:
g = open(fileName, ''a'')
where fileName is defined before the line it''s used in. It works fine
when I use it outside a thread class.
When I put the same line in a thread class, it no longer works, and I get
an error:
IOError: [Errno 2] no such file u''fileName''
It''s telling you that you haven''t got a file called ''fileName''.
Posting the code that triggers this error would allow people to
diagnose the error accurately rather than guessing.
--
Arnaud
bc90021 wrote:Hi All,
Thanks in advance for any and all help!
I have this code:
g = open(fileName, ''a'')
I don''t believe you. I think you have something like
g = open(''fileName'', ''a'')
instead of (as you claim)
g = open(fileName, ''a'')
Do you see the difference?
Develop the skill of reading the error messages *very* carefully. Your error says there is no file named "fileName", and if you think about what''s on your disk, I''ll bet you won''t find a file whose name is "fileName".
Gary Herron
where fileName is defined before the line it''s used in. It works fine
when I use it outside a thread class.
When I put the same line in a thread class, it no longer works, and I get
an error:
IOError: [Errno 2] no such file u''fileName''
Are threads not allowed to create files?
--
http://mail.python.org/mailman/listinfo/python-list
On Sun, 11 May 2008 18:36:25 +0100, Arnaud Delobelle wrote:
bc90021 <py****@bc90021.netwrites:
>Hi All,
Thanks in advance for any and all help!
I have this code:
g = open(fileName, ''a'')
where fileName is defined before the line it''s used in. It works fine
when I use it outside a thread class.
When I put the same line in a thread class, it no longer works, and I
get an error:
IOError: [Errno 2] no such file u''fileName''
It''s telling you that you haven''t got a file called ''fileName''. Posting
the code that triggers this error would allow people to diagnose the
error accurately rather than guessing.f = open(otherFile).readlines()
for i in len(f):
for c in range(0,24,1):
if os.name == "posix":
tempfileName = "\"proctemp/" + self.matrix[c][0]
+ "_tmp_" + fileName + ".txt\""
if re.search(f[i], pattern):
g = open(tempfileName, ''a'')
g.write(f[i])
This code works *perfectly* unless I put it in a class that inherits from
threading.Thread. In the thread class, everything works (I can see the
"c" value, and I can print out each line in "f[i]", it''s just that the g
= open line doesn''t work.
这篇关于文件创建不在线程类中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!