Python Scripting Toolbox: sys and fileinput

Ryan Palo on June 06, 2018

Cover Photo by Fleur Treurniet on Unsplash Python is an extremely flexible language with uses in tons of different applications and fields: web ... [Read Full]
markdown guide
 

It seems like every language has its equivalent of the sys routines. And, whenever I find myself tempted to use them, part of me ends up asking myself, "why am I wrapping this mess in rather than just doing it with a naked shell script." The more I dick with other languages, the more it makes me appreciate how flexible naked shell can truly be ...even if that functionality comes at the cost of really byzantine and obscure invocations.

But that probably all comes down to excuse-making for not bothering to attain the same level of mastery in new-to-me languages than I've attained in previous automation and reporting methods. =)

 

That’s so funny, that’s the same reason I try not to use shell scripts for much. Because I’m not as familiar with Bash scripting, I figure I might as well write it in something i won’t hate life in, and something I’ll be able to read when I come back to it in 6 months.

Do you have any favorite shell scripting resources?

 

TLDP maintains really good documentation ...at least from a technical content perspective: their presentation is mostly rubbish (like 1990s HTML).

Beyond their, StackOverflow, the man pages and the O'Reilly reference books (thank god they're electronic, now) are all solid. StackOverflow has the benefit of being more "bite-sized" and the answers you find tend to align very closely to your specific need.

But, what really helps is knowing exactly what it is you're trying to achieve, the technical terms for it and then how to make Google dance with those terms. =)

 

Great! As someone who uses pipes extensively in scripts, I feel that fileinput is underappreciated in the Python world. Argparse+fileinput is a great combo.

 

I know, I just discovered it. When I'm writing Ruby scripts, I really love having the ARGF. fileinput is basically Python's version of that, and it makes me happy.

BTW, argparse is going to be featured in Part 2!

code of conduct - report abuse