简体   繁体   中英

In the if else statement, else block is not working in python

if (filenames.rfind(fileName) != -1):
    sftp.chmod(sftpPath + filenames, 0644)
    print (" Permission changed successfully ")
else:
    print (" No file available to process ")

In the above code if statement works but the else block doesnt work(its not printing if file is not available)

The syntax looks good, there is a probability that content of the variable 'filename' exists in some other string too other than the file you are testing. You may try to print the filename under if condition and try that out. You can also reduce your search scope by entering a beginning and end index, str.rfind(sub_str, beg=0 end=len(string)).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM