I tried two ways:
1.
f = path (file_location + '1_classes /' + self.lineedit1.text () + '.txt')
If F.is_file ():
self.uch ()
File.Close ()
ELSE:
self.och ()
File.Close ()
2.
try:
File = Open (File_Location + 1_CLASSES / "+ Self.LineEdit1.Text () + '.txt')
Except Ioerror AS E:
self.och ()
File.Close ()
ELSE:
self.uch ()
File.Close ()
Does do not work. If necessary, I found the path to the file so:
file_location + '1_classes /' + self.lineedit1.text () + '.txt'
The path is formed correctly, verified.
Even if there is a file, the code opens the window that reports an error.
Answer 1
Use the OS.path.exist (* File_path *)
Library OS
This method returns True
in existence of a file. In File_Path
Specify the end address of the file.
if os.path.exists (file_location + '1_classes /' + self.lineedit1.text () + '. TXT '):
self.uch ()
File.Close ()
ELSE:
self.och ()
File.Close ()