import tabulate
import sys
import csv
def main():
if len(sys.argv) == 1:
sys.exit('Too few command-line arguments')
elif len(sys.argv) > 2:
sys.exit('Too many command-line arguments')
elif not sys.argv[1].endswith('.csv'):
sys.exit('Not a CSV file')
elif len(sys.argv) == 2:
try:
with open(sys.argv[1], 'w') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(tabulate(writerwriter, header="firstrow", tablefmt="grid"))
except FileNotFoundError:
sys.exit('File does not exist')
if __name__ == '__main__':
main()
I want to print a tabulated version of an inputted csv file in the command line. It should open the file in write mode, and then re-write that file in a tabulated graph format with the header as the first line. However, when I run the graph, I get:
Traceback (most recent call last):
File "/workspaces/112136537/pizza/pizza.py", line 22, in <module>
main()
File "/workspaces/112136537/pizza/pizza.py", line 16, in main
spamwriter.writerow(tabulate(spamwriter, header="firstrow", tablefmt="grid"))
TypeError: 'module' object is not callable
Why can't the module be called?