title: How to count lines of code in Python excluding comments and docstrings?
body: <p>I want to count the lines of code in a multi-file Python project as accurately as possible, but without including comments, docstrings or blank lines in the total.</p>
  
  <p>I first tried using cloc, which is available as a Debian package. But cloc  treats most docstrings as code - even though they are comments. (<strong>Update:</strong> no longer - recent versions of cloc now treat Python docstrings as comments.)</p>
  
  <p>I notice some comments below saying that docstrings should be included in the total because they might be used by the code to influence behaviour at runtime and hence count as part of the programs code/data/config. A prominent example of this is 'ply', which asks you to write functions with docstrings which, as I recall, contain grammar and regular expressions which are central to the program's operation. However, this seems to me to be very much a rare exception. Most of the time docstrings act just like comments. Specifically, I know for a fact that is true for all the code I want to measure. So I want to exclude them as such from my line counts.</p>