6 ms·
Interesting approach, I'm taking notes! Something I'm currently doing for my CV application[0] is auto-generating variables for every table/column name in my S
by harryvederci 4y ago
Interesting approach, I'm taking notes!
Something I'm currently doing for my CV application[0] is auto-generating variables for every table/column name in my SQLite DB. As I'm using a dynamically typed language, it's normally easy to mess up with a typo when getting a valuable out of a query result. But when I use the auto-generated variables I'll know I messed up during compile time. That also means my SQLite schema is always my source of truth. Maybe there are better ways to do it, but I find it really useful so far!
[0] https://withoutdistractions.com/cv https://withoutdistractions.com/cv - I'm doing a "Show HN" today here: https://news.ycombinator.com/item?id=31246696 https://news.ycombinator.com/item?id=31246696
(I have to admit I'm kinda jaleous you beat me to the front page within half an hour. What sacrifice did you make to which algorithm deity? I won't tell anyone.)
- drothlis 4y agoThanks! Coincidentally one of the first articles I wrote for my blog was about compile-time checking of table/column names: https://david.rothlis.net/d/templates/ https://david.rothlis.net/d/templates/ (Just something I was messing around with, not anything I ever used in production.)
- simonw 4y agoSpotted this in the code: def _left_pad(text, indent=" "): """Maybe I can find a package in pypi for this?""" return "\n".join(indent + line for line in text.split('\n')) You can use the textwrap module from the Python standard library for this: textwrap.indent('hello\nthis\n is a demo', ' ') # ' hello\n this\n is a demo'
- drothlis 4y agoHa! I use `textwrap.dedent` all the time but didn't make the leap of logic to check for the existence of `indent`. :-) I suspect this was a leftover from Python 2.7 days.