Python 3.x 有没有解决isADirectory错误的方法

Python 3.x 有没有解决isADirectory错误的方法,python-3.x,Python 3.x,在运行了整个程序之后,我得到了这个错误 standard_codes = "/root/malware/ops.txt" app_dir = "/root/malware/decompiled/" ef std_codes_list(standard_codes): std_codes = [] with open(standard_codes,'r') as fp: for cnt, line in enumerate(fp):

在运行了整个程序之后,我得到了这个错误

standard_codes = "/root/malware/ops.txt"
app_dir = "/root/malware/decompiled/"

ef std_codes_list(standard_codes):

std_codes = []

with open(standard_codes,'r') as fp:
    for cnt, line in enumerate(fp): 
        read_lines = fp.read();
        read_lines = read_lines.split("\n")
        std_codes = read_lines
        std_codes.pop() 

return std_codes

您使用了错误的路径,因为正如您所提到的/root/malware/ops.txt是一个目录。由于实际文件为“/root/malware/ops.txt/ops.txt”,请尝试以下代码:

IsADirectoryError Traceback (most recent call last)
in
----> 1 std_codes = std_codes_list(standard_codes)
2
3 apk_list = pickle.load(open('apk_pickle_list.pkl', 'rb'))
4
5 for each_apk in apk_list:

in std_codes_list(standard_codes)
3 std_codes = [] #empty list which will later contain all the standard op-codes read from the ops.txt file
4
----> 5 with open(standard_codes,'r') as fp:
6 for cnt, line in enumerate(fp): # reading each op-code in the txt file
7 read_lines = fp.read();

IsADirectoryError: [Errno 21] Is a directory: '/root/malware/ops.txt'

/root/malware/ops.txt
是目录还是文件?如果你
ls-l/root/malware/ops.txt
,你会得到什么?is/root/malware/ops.txt它是一个包含文件名ops.txt的目录,那么你使用了错误的路径。
standard_codes = "/root/malware/ops.txt/ops.txt"
app_dir = "/root/malware/decompiled/"

ef std_codes_list(standard_codes):

std_codes = []

with open(standard_codes,'r') as fp:
    for cnt, line in enumerate(fp): 
        read_lines = fp.read();
        read_lines = read_lines.split("\n")
        std_codes = read_lines
        std_codes.pop() 

return std_codes