Я пытаюсь использовать обработку исключений для предотвращения сбоя моей системы, я использовал приведенные ниже коды, где этот файл CSV на самом деле не существует. Но система падает, хотя. Может кто-нибудь помочь мне исправить мои коды, пожалуйста .... помогите мне, пожалуйста
Это мои исходные коды:
while True:
try:
import pandas as pd # data processing, csv file I/O(e.g pd.read_csv)
df = pd.read_csv('C:/Users/User/Desktop/Coding/parsehubjsonfileeg/assd.csv')
print(df)
except Exception as err:
print("Uh oh, please send me this message: '" + err + "'")
Ошибки, которые у меня возникают
Traceback (most recent call last):
File "C:/Users/User/PycharmProjects/EmotionAnalysis/abcd.py", line 5, in <module>
df = pd.read_csv('C:/Users/User/Desktop/Coding/parsehubjsonfileeg/assd.csv')
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\io\parsers.py", line 685, in parser_f
return _read(filepath_or_buffer, kwds)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\io\parsers.py", line 457, in _read
parser = TextFileReader(fp_or_buf, **kwds)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\io\parsers.py", line 895, in __init__
self._make_engine(self.engine)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\io\parsers.py", line 1135, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\io\parsers.py", line 1917, in __init__
self._reader = parsers.TextReader(src, **kwds)
File "pandas/_libs/parsers.pyx", line 382, in pandas._libs.parsers.TextReader.__cinit__
File "pandas/_libs/parsers.pyx", line 689, in pandas._libs.parsers.TextReader._setup_parser_source
FileNotFoundError: [Errno 2] File b'C:/Users/User/Desktop/Coding/parsehubjsonfileeg/assd.csv' does not exist: b'C:/Users/User/Desktop/Coding/parsehubjsonfileeg/assd.csv'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/User/PycharmProjects/EmotionAnalysis/abcd.py", line 8, in <module>
print("Uh oh, please send me this message: '" + err + "'")
TypeError: must be str, not FileNotFoundError
Process finished with exit code 1