'Why does python expects a statement when I use "except FileNotFoundError" function? Isn't the "FileNotFoundError" already a statement?
I'm making an app that locks your apps. The only way you can open them is if you plug in a flash drive that has the correct id. But, python expects a statement when I write, "except File Not Found Error"? Here's the code, I'm using hyperlink because stack overflow keeps giving me an error when I post the code here
#!/usr/bin/python
import time
import subprocess
import random
# Variables
authorization = False
# Opening save file
with open("save.txt", "r") as fa:
current_id = fa.read()
# Open a file
path = r"G:\Authorization\5.txt"
# Checking if it has the correct ID
with open(path, 'r') as f:
file_contents = f.read()
except FileNotFoundError:
print("ACCESS DENIED")
if file_contents == str(current_id):
authorization = True
Solution 1:[1]
# Checking if it has the correct ID
try:
with open(path, 'r') as f:
file_contents = f.read()
except FileNotFoundError:
print("ACCESS DENIED")
if file_contents == str(current_id):
authorization = True
Except only work with a "try" statement aswell. This shouldn't give you a missing statement. Try/except documentation
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
