Is there a built-in python analogue for unix wc for sniffing a file?

All this is done - from the shell you need details about the text file (more than just ls -l gives you), in particular, this file has the number of lines , therefore:

@ > wc -l iris.txt
 149 iris.txt

I know that I can access shell utilities from python, but I'm looking for inline python if there is one.

The essence of my question is to get this information without opening the file (therefore, my link to the unix * wc - * l utility)

("sniffs" the correct term for this, that is, views the file without opening it? ")

+2
source share
2 answers

You can always quickly scan it, right?

lc = sum(1 for l in open('iris.txt'))
+5
source

, "". Sniffing , , Ethernet.

, . , - ( "\n" linux) , open().

+2

All Articles