Daily Shaarli
October 3, 2020
In this week's post you learned how to a command line tool that manipulates CSV files. You learned how to use the csv module to read and write CSV files, as well as how to use csv.Sniffer to automatically deduce the "dialect" of a CSV file. You also learned how to use compile and exec to run text as Python code.
My challenge to you:
Build a tool like csv-proc that allows you to filter CSV files based on some criteria. For example, if you only want to view prediabetic patients from data.csv, you could call your program like this:
$ csv-filter data.csv '100 <= float(row.glucose_mgdL) < 126'
If you enjoyed this week's post, share it with your friends and stay tuned for next week's post. See you then!
In this chapter, we will look at how to run dynamic SQL in a civilised way. I like to point out there is nothing in the examples in this chapter that calls for dynamic SQL, and from that point of view they are bad examples, because you should not use dynamic SQL when there is no reason to. However, I opted to do it this way, because I wanted to focus on the essentials and keep the examples the simple. Actual use cases will come in the later chapters.