Como posso ver se um arquivo existe ou não, sem utilizar a declaração try
?
Você tem a função os.path.exists
:
import os.path
os.path.exists(file_path)
Isto retorna "Verdade" tanto para arquivos quanto para diretórios, mas você pode, em vez disso, utilizar
os.path.isfile(file_path)
para testar se ele'é um arquivo especificamente. Ele segue os links simbólicos.
import os
os.path.exists(path) # Returns whether the path (directory or file) exists or not
os.path.isfile(path) # Returns whether the file exists or not