Tarrrror在缩进中使用制表符和空格不一致

问题描述 投票:0回答:1

有人可以帮我解决错误。我能够解决制表符/空格错误,但现在我遇到了此错误

root@test/tmp # python3 1.py
Traceback (most recent call last):
  File "1.py", line 9, in <module>
    del element['testdir']
TypeError: 'str' object does not support item deletion

1.py:

import json, subprocess, os, sys, shutil, time
from subprocess import Popen, PIPE

os.system('curl -s -u xxxxx > list.txt')

with open('list.txt') as data_file:    
    list = json.load(data_file)
    for element in list: 
        del element['testdir']

for dir in list:
    print('dir' + dir)
python-3.x
1个回答
0
投票
只需用空格替换选项卡。由于看起来您使用的是类似Unix的操作系统,因此您可以使用sed:
© www.soinside.com 2019 - 2024. All rights reserved.