[英]Python os.walk() failing
I have created a script to give me the list of files in a folder directory. 我创建了一个脚本,为我提供了文件夹目录中的文件列表。 Yet, I am occasionally getting this error.
但是,我偶尔会遇到此错误。 What does this mean?
这是什么意思?
portion of the error: 错误的一部分:
Script failed due to an error:
Traceback (most recent call last):
File "<script>", line 12, in <module>
File "C:\Program Files\Nuix\Nuix 6\lib\jython.jar\Lib\os.py", line 309, in walk
File "C:\Program Files\Nuix\Nuix 6\lib\jython.jar\Lib\os.py", line 299, in walk
File "C:\Program Files\Nuix\Nuix 6\lib\jython.jar\Lib\genericpath.py", line 41, in isdir
File "C:\Program Files\Nuix\Nuix 6\lib\jython.jar\Lib\genericpath.py", line 41, in isdir
java.lang.AbstractMethodError: org.python.modules.posix.PythonPOSIXHandler.error(Ljnr/constants/platform/Errno;Ljava/lang/String;Ljava/lang/String;)V
at jnr.posix.BaseNativePOSIX.stat(BaseNativePOSIX.java:309)
at jnr.posix.CheckedPOSIX.stat(CheckedPOSIX.java:265)
at jnr.posix.LazyPOSIX.stat(LazyPOSIX.java:267)
The script: 剧本:
import os
import codecs
import shutil
import datetime
import sys
exportpath = 'P:/Output/Export7/{6136BAF2-85BA-4E64-8C11-A2C59398FC02}/'
tempnativefolder = 'NATIVESOrig'
for dir, sub, file in os.walk(exportpath + tempnativefolder):
for fname in file:
#source path
source = os.path.join(dir, fname).replace('\\', '/')
print source
print("Natives moved to subfolders")
I found out that the presence of these characters(see "diamond with question mark" character in screenshot) in the file name causes the issue. 我发现文件名中存在这些字符(请参见屏幕快照中的“带问号的钻石”字符)会导致此问题。 Once I replaced those, my script works.
一旦替换了这些脚本,我的脚本就可以工作。 thanks so much.
非常感谢。
What the error means: AbstractMethodError
means that some code tried to call a method which was not implemented. 错误的含义:
AbstractMethodError
意味着某些代码试图调用未实现的方法。
PythonPOSIXHandler
implements jnr.posix.POSIXHandler
. PythonPOSIXHandler
实现jnr.posix.POSIXHandler
。 JRuby also uses JNR and the interface is subtly different between the two. JRuby还使用JNR,并且两者之间的接口略有不同。 JRuby's newer copy of JNR has that one additional
#error(Errno, String, String)
method and Jython's implementation lacks that method, because it's compiled against the interface when the method didn't exist. JRuby的JNR的较新副本具有一个附加的
#error(Errno, String, String)
方法,而Jython的实现缺少该方法,因为当该方法不存在时,它是根据接口编译的。
I usually see this problem in the other direction - where stuff in Jython's jar breaks JRuby. 我通常在另一个方向看到这个问题-Jython罐子里的东西破坏了JRuby。 I assume it entirely depends on the order of the jars in the classpath.
我认为这完全取决于类路径中jar的顺序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.