ajout script main6.py

This commit is contained in:
Éric Wegrzynowski 2021-01-08 11:54:45 +01:00
parent 890b6c5b79
commit 4028ac2440
1 changed files with 61 additions and 0 deletions

61
main6.py Executable file
View File

@ -0,0 +1,61 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
:mod: module
:author: `Eric W`
:date: 2020, december
"""
GRID='''
+-------+-------+-------+
| 9 . 6 | . 2 8 | . . 3 |
| . 4 . | 5 . . | . . 1 |
| . 8 . | 9 . . | . 4 . |
+-------+-------+-------+
| 6 . . | . . . | . 7 . |
| . . 8 | 2 . 6 | 9 . . |
| . 3 . | . . . | . . 5 |
+-------+-------+-------+
| . 5 . | . . 3 | . 6 . |
| 1 . . | . . 2 | . 8 . |
| 2 . . | 8 7 . | 5 . . |
+-------+-------+-------+
'''
def usage():
print('Usage: {:s} <grid> [<filename>]'.format(sys.argv[0]))
print('where\n\t<grid> is a 81 characters string describing a valid sudoku grid')
print('\t<filename>, if given, = filename to save the image')
print('\nExamples: with the grid')
print(GRID)
print('$ {:s} 906028003040500001080900040600000070008206900030000005050003060100002080200870500'.format(sys.argv[0]))
print('show a « à la Mondrian » representation of the grid')
print('$ {:s} 906028003040500001080900040600000070008206900030000005050003060100002080200870500 essai.png'.format(sys.argv[0]))
print('image saved in file essai.png')
exit(1)
if __name__ == '__main__':
import sys
import sudoku_grid, sudoku_mondrian
if len(sys.argv) not in (2, 3):
usage()
else:
strgrid = sys.argv[1]
try:
grid = sudoku_grid.SudokuGrid(strgrid)
except sudoku_grid.SudokuGridError:
usage()
print('Sudoku to represent')
grid.pretty_print()
img = sudoku_mondrian.colorie_sudoku(grid)
img.show()
_ = input('Tapez entrée pour terminer')
if len(sys.argv) == 3:
filename = sys.argv[2]
img.save(filename)
print('Image sauvegardée dans le fichier {:s}'.format(filename))
exit(0)