I am trying to import variables from a second python file however when running it in cmd it doesn`t recognise the variable names used in the second file. All files are in the same directory
main.py:
import curses
from curses import wrapper
from settings import *
def main(stdscr):
curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_RED)
stdscr.clear()
stdscr.refresh()
stdscr.addstr('Hello', curses.color_pair(BLUE_AND_RED))
stdscr.getch()
wrapper(main)
settings.py:
BLUE_AND_RED = 1
Exact Error:
File "C:UsersJaDesktopcodingcursesmain.py", line 13, in <module>
wrapper(main)
File "C:UsersJaAppDataLocalProgramsPythonPython312Libcurses__init__.py", line 94, in wrapper
return func(stdscr, *args, **kwds)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:UsersJaDesktopcodingcursesmain.py", line 10, in main
stdscr.addstr('Hello', curses.color_pair(BLUE_AND_RED))
^^^^^^^^^^^^
NameError: name 'BLUE_AND_RED' is not defined
I have read somewhere to add a empty init.py file to the directory in order to make python recognise it as a package but that has failed too.
New contributor
3