Python’s “subprocess” module makes it really easy to invoke an external program and grab its output. For example, you can say import subprocess print(subprocess.check_output('ls')) and the output is then $ ./blog.py b'blog.py\nblog.py~\ndictslice.py\ndictslice.py~\nhexnums.txt\nnums.txt\npeanut-butter.jpg\nregexp\nshowfile.py\nsieve.py\ntest.py\ntestintern.py\n' subprocess.check_output returns a bytestring with the filenames on my desktop. To deal with them in a more serious ...

Read More

One of Python’s mantras is “batteries included.” which means that even with a bare-bones installation, you can do quite a bit. You can (and should) install packages from PyPI, but many day-to-day tasks can be accomplished with just the built-in data structures, functions, and methods. What I’ve discovered over the ...

Read More

If you’re like many of the Python developers I know, the basics are easy for you: Strings, lists, tuples, dictionaries, functions, and even objects roll off of your fingers and onto your keyboard. Your day-to-day tasks have become significantly easier as a result of Python, and you’re comfortable using it ...

Read More

Whenever I teach Python courses, most of my students are using Windows. And thus, when it comes time to do an exercise, I inevitably end up with someone who does the following: for one_line in open('c:\abc\def\ghi'): print(one_line) The above code looks like it should work. But it almost certainly doesn’t. ...

Read More