May-18-2021, 06:21 AM
all i want to do is count the lines in each file but there are strange binary bytes or older ISO codes.
i think the only things it uses from sfc are os and cd (called with no args changes directory to user home directory.
Output:Traceback (most recent call last):
File "last-edited.py", line 38, in <module>
pf(t,n)
File "last-edited.py", line 7, in pf
c = len([x for x in f])
File "last-edited.py", line 7, in <listcomp>
c = len([x for x in f])
File "/usr/host/bin/../../lib/python3.6/codecs.py", line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa9 in position 93: invalid start byte
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
from sfc import * def pf(t,n): if os.path.exists(n): with open (n) as f: c = len ([x for x in f]) print (t, str (c).rjust( 8 ),n) fn = '.edit_log' argv.pop( 0 ) cd() # be in home directory with open (fn) as el: nt = {} for ee in el: t,e,n = ee.strip().split()[: 3 ] if n in nt: nt[n].append(t) else : nt[n] = [t] ns = sorted (nt.keys()) tn = {} for n in ns: nt[n].sort() for n in ns: t = nt[n][ - 1 ] if t[ 13 ] = = '-' : t = t[ 0 : 7 ] + t[ 8 : 13 ] + t[ 14 : 16 ] + t[ 17 :] tn[t] = n for t,n in sorted ([x for x in sorted (tn.items())]): if argv: for a in argv: if n.endswith(a): if os.path.exists(n): pf(t,n) break else : # none requested so print all if os.path.exists(n): pf(t,n) |
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.