UnboundLocalError: local variable ‘path‘ referenced before assignment

The gods are silent-personal CSDN blog post directory

Operating environment, error message, cause and solution:
Linux, Python 3

This is a very typical Python programming problem, which is called before defining (or "allocating", that is, assigning a space to a variable) a variable.
A common situation (the one I encountered) is that the variable is defined elsewhere (a conditional statement), but is called outside of the conditional statement.
My problem is that I wrote the wrong variable name, I just change it to the variable name that should be called under the current conditions.

Traceback (most recent call last):
  File "main.py", line 493, in <module>
    main()
  File "main.py", line 167, in main
    data = load_data(path_data, args.dataset, args.scale)
  File "util.py", line 163, in load_data
    with open(path, 'rb') as f:
UnboundLocalError: local variable 'path' referenced before assignment

Guess you like

Origin blog.csdn.net/PolarisRisingWar/article/details/129032815