-2

我每次都会收到此代码的缩进错误:

    if resulttaglist[1].childNodes[0].toxml() == 0:
    sys.exit
else:
    subdomaintaglist = doc.getElementsByTagName('subdomain')
    subdomain = subdomaintaglist[0].childNodes[0].toxml()
        maindomaintaglist = doc.getElementsByTagName('DOMAIN')
        maindomain = maindomaintaglist[0].childNodes[0].toxml()
    domain =  subdomain + '.' + maindomain
    usertaglist = doc.getElementsByTagName('USER')
    user = usertaglist[0].childNodes[0].toxml()
        docroot, yip, alias = createvhosts.getvars(domain)
        serverip = createvhosts.getmainip()
                if yip == serverip:
                    createvhosts.writeconfshared(user, domain, docroot, yip, alias)
                else:
                    createvhosts.writeconfded(user, domain, docroot, yip, alias)
        proc = subprocess.Popen("/etc/init.d/nginx restart > /dev/null 2>&1", shell=True)

每次我试图纠正它都不起作用,谁能告诉我什么是错的?谢谢

4

2 回答 2

1

尝试:

if resulttaglist[1].childNodes[0].toxml() == 0:
    sys.exit()
else:
    subdomaintaglist = doc.getElementsByTagName('subdomain')
    subdomain = subdomaintaglist[0].childNodes[0].toxml()
    maindomaintaglist = doc.getElementsByTagName('DOMAIN')
    maindomain = maindomaintaglist[0].childNodes[0].toxml()
    domain =  subdomain + '.' + maindomain
    usertaglist = doc.getElementsByTagName('USER')
    user = usertaglist[0].childNodes[0].toxml()
    docroot, yip, alias = createvhosts.getvars(domain)
    serverip = createvhosts.getmainip()
    if yip == serverip:
        createvhosts.writeconfshared(user, domain, docroot, yip, alias)
    else:
        createvhosts.writeconfded(user, domain, docroot, yip, alias)
    proc = subprocess.Popen("/etc/init.d/nginx restart > /dev/null 2>&1", shell=True)

确保您的编辑器只保存空格或制表符,但不能同时保存两者。我个人的偏好是空间。

于 2013-09-08T22:15:39.513 回答
0

我认为您正在混淆制表符和空格。如果我没有错,如果 /else 不正确,则开始时的缩进会导致更糟糕的缩进。尝试这个:-

if resulttaglist[1].childNodes[0].toxml() == 0:
    sys.exit
else:
    subdomaintaglist = doc.getElementsByTagName('subdomain')
    subdomain = subdom.........
于 2020-06-14T16:31:25.513 回答