Re: [Tutor] Logical error?

2014-05-04 Thread Dave Angel
Danny Yoo Wrote in message: > > > > >> Hopefully, this makes the point clearer: we must not try to decode >> individual lines. By that time, the damage has been done: the act of >> trying to break the file into lines by looking naively at newline byte >> characters is invalid when certain cha

Re: [Tutor] Logical error?

2014-05-03 Thread Danny Yoo
> > for encoding in ('utf-8', 'utf-16', 'utf-32'): > for i in range(0x11): > aChar = unichr(i) > try: > someBytes = aChar.encode(encoding) > if '\n' in someBytes: > print("%r contains a newlin

Re: [Tutor] Logical error?

2014-05-03 Thread Danny Yoo
>> A small note about performance here. If your log files are very large >> (say, hundreds of thousands or millions of lines) you will find that >> this part is *horribly horrible slow*. There's two problems, a minor and >> a major one. > > Ah, actually I was mistaken about that. I forgot that for

Re: [Tutor] Logical error?

2014-05-03 Thread Steven D'Aprano
On Sat, May 03, 2014 at 11:53:27AM +1000, Steven D'Aprano wrote: > [...] > > fullPath = [] # declare (initially empty) lists > > truncPath = [] > > > > with codecs.open('/var/log/rsyncd.log', 'r') as rsyncd_log: > > for line in rsyncd_log.readlines(): > > fullPath += [line.decode('u

Re: [Tutor] Logical error?

2014-05-03 Thread Bob Williams
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Steven, On 03/05/14 02:53, Steven D'Aprano wrote: > Hi Bob, and welcome! > > My responses interleaved with yours, below. > > On Fri, May 02, 2014 at 11:19:26PM +0100, Bob Williams wrote: >> -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 >> >> Hi,

Re: [Tutor] Logical error?

2014-05-02 Thread Steven D'Aprano
Hi Bob, and welcome! My responses interleaved with yours, below. On Fri, May 02, 2014 at 11:19:26PM +0100, Bob Williams wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Hi, > > I'm fairly new to coding and python. My system is linux (openSUSE > 13.1). Nice to know. And I see you h

[Tutor] Logical error?

2014-05-02 Thread Bob Williams
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, I'm fairly new to coding and python. My system is linux (openSUSE 13.1). I've written the following code to examine a log file, and extract strings from certain lines if two conditions are met, namely that the file has been modified today, and the