![](/img/trans.png)
[英]Why isn't this code working without an else block to the if statement? - Python
[英]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 ")
在上面的代碼中,if語句有效,但else塊無效(如果文件不可用,則不打印)
語法看起來不錯,除了您要測試的文件外,變量'filename'的內容也可能存在於其他字符串中。 您可以嘗試在if條件下打印文件名,然后嘗試一下。 您還可以通過輸入開始索引和結束索引str.rfind(sub_str,beg = 0 end = len(string))來縮小搜索范圍。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.