I don't understand the point of this test:
> if sys.stdin.isatty() and args.infile.name == "<stdin>":
> sys.exit("Please give some input")
We want to disallow a particular file name, but only if we're connected to a tty? If you want to prompt when input is coming from stdin, then we shouldn't be testing the file _name_:
if args.infile.isatty():
print("Please enter your data:")
We don't need to read a line at a time. `prettytable` can do that for us:
table = prettytable.from_csv(args.infile)
However, it requires the stream to be seekable, so if it's not, we'll need to read it into memory and pass that as a stream:
if not args.infile.seekable():
from io import StringIO
args.infile = StringIO(args.infile.read())
table = prettytable.from_csv(args.infile)
----
It's probably a good idea to print only the message from any exceptions, rather than an entire backtrace (unless the user asks for the extra detail):
try:
table = prettytable.from_csv(args.infile)
print(table)
except Exception as e:
logging.error(e, exc_info=(args.loglevel<=logging.INFO))
exit(1)