May-19-2021, 07:37 AM
If I need to have quick look at number of lines in file then I use
wc
in terminal.cat my_filename | wc -lIt is easy to use in Python with subprocess. Specific example on file named shakespeare.txt; check_output returns bytes so I converted it into integer:
>>> import subprocess >>> source = subprocess.Popen(['cat', 'shakespeare.txt'], stdout=subprocess.PIPE) >>> lines = int(subprocess.check_output(['wc', '-l'], stdin=source.stdout)) >>> lines 4155
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.