from nqueens.chessboard import Chessboard
from nqueens.printer import Printer
from nqueens.solver import Solver


board = Chessboard.create(8)
solver = Solver.create(board)
solution = solver.solve()
if solution is not None:
    printer = Printer.create(solution)
    printer.printBoard()

#!/usr/bin/env python3
import os
import sys
import getopt
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from nqueens.chessboard import Chessboard
from nqueens.printer import Printer
from nqueens.solver import Solver


def main():
    try:
        n = parse_command_line()
    except ValueError as e:
        print("Error: " + str(e))
        print("Usage: nqueens.py <n>")
        sys.exit(1)
    solution = solve_for(n)
    if solution is None:
        print("No solution found")
    else:
        print_solution(solution)


def parse_command_line():
    try:
        opts, args = getopt.getopt(sys.argv[1:], "", [])
    except getopt.GetoptError:
        raise ValueError("Could not parse command line")
    if len(args) == 0:
        raise ValueError("No arguments supplied")
    if len(args) > 1:
        raise ValueError("Too many arguments supplied")
    n = args[0]
    if not n.isdigit() or int(n) < 1:
        raise ValueError("n must be a positive number")
    return int(n)


def solve_for(n):
    board = Chessboard.create(n)
    solver = Solver.create(board)
    return solver.solve()


def print_solution(solution):
    printer = Printer.create(solution)
    printer.printBoard()


if __name__ == '__main__':
    sys.exit(main())

Add ability to run problems from command line