prettycsv.py
· 789 B · Python
Originalformat
#!/bin/env python
"""Print pretty csv data on terminal
vim: ft=python
Author: Dominic Reich <quick.hat4396@qtztsjosmprqmgtunjyf.com>
Created: 2025-02-05T19:49:59+0100
Last modified: 2025-02-05T19:50:07+0100
Usage:
------
Use with arguments (filename of csv data).
./pretty_csv <filename>
"""
import sys
import os
import pandas as pd
def main():
if len(sys.argv) <= 1:
print("Sorry, what is it?")
exit(1)
else:
filename=sys.argv[1]
if os.path.isfile(filename) and os.access(filename, os.R_OK):
csv_file = pd.read_csv(filename, dtype=str)
print(csv_file)
else:
print("File ›{}‹ not found or not readable. Aborting.".format(filename))
exit(1)
if __name__ == "__main__":
main()
| 1 | #!/bin/env python |
| 2 | |
| 3 | """Print pretty csv data on terminal |
| 4 | vim: ft=python |
| 5 | |
| 6 | Author: Dominic Reich <quick.hat4396@qtztsjosmprqmgtunjyf.com> |
| 7 | Created: 2025-02-05T19:49:59+0100 |
| 8 | Last modified: 2025-02-05T19:50:07+0100 |
| 9 | |
| 10 | Usage: |
| 11 | ------ |
| 12 | Use with arguments (filename of csv data). |
| 13 | ./pretty_csv <filename> |
| 14 | """ |
| 15 | |
| 16 | import sys |
| 17 | import os |
| 18 | import pandas as pd |
| 19 | |
| 20 | |
| 21 | def main(): |
| 22 | |
| 23 | if len(sys.argv) <= 1: |
| 24 | print("Sorry, what is it?") |
| 25 | exit(1) |
| 26 | else: |
| 27 | filename=sys.argv[1] |
| 28 | |
| 29 | if os.path.isfile(filename) and os.access(filename, os.R_OK): |
| 30 | csv_file = pd.read_csv(filename, dtype=str) |
| 31 | |
| 32 | print(csv_file) |
| 33 | else: |
| 34 | print("File ›{}‹ not found or not readable. Aborting.".format(filename)) |
| 35 | exit(1) |
| 36 | |
| 37 | |
| 38 | if __name__ == "__main__": |
| 39 | main() |
| 40 |