I am using this in Python 3.6:
filetest="test.txt"
with open(filetest,"r") as file:
How should I make Python console to display "File not available" as an output if no input on the filetest is detected? (such as there is no test.txt in the directory)
try/exceptblock or check the presence of the file before hand usingosorpathmoduleFileNotFoundErrorif the file you want to read is not exists. Catch a bare exception is not a good habit for all programming language.'test.txt'is a string with a file name,test.txtis the attributetxtof the objecttest.