def()函数使用我的缩进

2024-10-01 15:32:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编写一个基本脚本,它扫描文件,如果文件符合用户设置的某些条件,就会移动它们

我尝试过遵从它的要求,但结果是每一行代码都被缩进一行而不是另一行

def check():
    #code simplication
    for i in range(2):
        if fileScanDestination == '':
            noValue(moveFrom)
        else:
            #exits

        if fileMoveDestination == '':
            noValue(moveTo)
        else:
            #exits

        if specialFileExtension == '':
            str(specialFileExtension) == 'nil'
        else:
            #exits

        if fileNameSpecial == '':
            str(fileNameSpecial) == str('nil')
        else:
            #exits

def p(text):
    print(text)

#setting up tkinter


# getting variable data

p('Please enter the path for the files you would like to sort.')
fileScanDestination == str(input())

这应该只需要缩进一次,然后退出。但是因为它想缩进每一行,这看起来很糟糕


Tags: 文件thetext脚本forifdefelse
1条回答
网友
1楼 · 发布于 2024-10-01 15:32:21

试着在else语句后面放一些pass指令,或者如果你说它应该退出的话放一些return指令

你甚至可以通过以下方式缩短整个过程:

if any([
    fileScanDestination == '',
    fileMoveDestination == '',
    specialFileExtension == '',
    str(specialFileExtension) == 'nil',
    str(fileNameSpecial) == str('nil'),
    fileNameSpecial == ''
]):
    return

相关问题 更多 >

    热门问题