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?