I found out a code from a script that prevented it to be opened with import
def begin(stdscr):
    stdscr.clear()
    curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK)
    init_maze()
    generate_maze()
    mainloop()
if __name__ == '__main__':
    curses.setupterm()
    stdscr = curses.initscr()
    curses.curs_set(False)
    stdscr.keypad(True)
    cols = curses.tigetnum('cols')
    lines = curses.tigetnum('lines')
    while width < cols and height + 5 < lines:
        curses.wrapper(begin)
        width += 10
        height += 6
The main one is if __name__ == '__main__':
Can anyone tell me how to make so that the game can works without if __name__ == '__main__': and works with import?
EDIT: If I delete if __name__ == '__main__':, the script doesn't work anymore
 
     
    