On the use of judgment sentences in Python

I wrote a method as follows:

file = None
for f in os.listdir(os.getcwd()):
    if os.path.splitext(f)[1] == ".*" and os.path.splitext(f)[0] == os.getenv("") or "text":
        file = f
return file
The

expectation is that if the file does not exist, it returns None , which actually returns _ _ pycache__ .

I modified the method as follows:

file = None
for f in os.listdir(os.getcwd()):
    if os.path.splitext(f)[1] == ".*":
        if os.path.splitext(f)[0] == os.getenv("") or "text":
            file = f
return file

this returns the expected value None .

excuse me, why?

Mar.28,2021

and takes precedence over or

your first method is slightly modified,

file = None
for f in os.listdir(os.getcwd()):
    if os.path.splitext(f)[1] == '.*' and (os.path.splitext(f)[0] == os.getenv('') or 'text'):
        file = f
return file

should meet your expectations.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b30e1c-e29c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b30e1c-e29c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?