#!/usr/bin/env python3
"""
    Naam      : R. Wacanno
    UvAnetID  : 11741163
    Studie    : BSc Informatica

    script.py
    -Contains a script which prints the grid of numbers contained in
     the file given as the first argument.
"""
import sys


def read_file(path):
    """Reads a grid of numbers, separated by spaces, from a file and
    returns a list with nested lists for each row of the file.
    These nested lists contain the numbers."""
    try:
        with open(path) as grid_file:
            return [[int(x) for x in line.split()] for line in grid_file]
    except NameError:
        print("Given file is invalid")
    except ValueError:
        print("File contains non-integers")


def list_to_string(lst):
    """Convers a list with nested lists to a string which represents
    a grid with eacht nested list as a row."""
    try:
        return "\n".join(" ".join(map(str, inner)) for inner in lst)
    except TypeError:
        print("Given list is invalid")


if __name__ == "__main__":
    try:
        print(list_to_string(read_file(sys.argv[1])))
    except IndexError:
        print("No file given")
