Re: [Tutor] formatting xml (again)

2016-12-27 Thread David Rock
* Alan Gauld via Tutor [2016-12-28 00:40]: > On 27/12/16 19:44, richard kappler wrote: > > Using python 2.7 - I have a large log file we recorded of streamed xml data > > that I now need to feed into another app for stress testing. The problem is > > the data comes in 2 formats. > > > > 1. each '

Re: [Tutor] formatting xml (again)

2016-12-27 Thread Alan Gauld via Tutor
On 27/12/16 19:44, richard kappler wrote: > Using python 2.7 - I have a large log file we recorded of streamed xml data > that I now need to feed into another app for stress testing. The problem is > the data comes in 2 formats. > > 1. each 'event' is a full set of xml data with opening and closin

Re: [Tutor] formatting xml (again)

2016-12-27 Thread David Rock
* richard kappler [2016-12-27 16:05]: > The input is consistent in that it all has stx at the beginning of each > 'event.' I'm leaning towards regex. When you say: > > " find stx, stuff lines until I see the next stx, then dump and continue" > > Might I trouble you for an example of how you do t

Re: [Tutor] formatting xml (again)

2016-12-27 Thread richard kappler
The input is consistent in that it all has stx at the beginning of each 'event.' I'm leaning towards regex. When you say: " find stx, stuff lines until I see the next stx, then dump and continue" Might I trouble you for an example of how you do that? I can find stx, I can find etx using something

Re: [Tutor] formatting xml (again)

2016-12-27 Thread David Rock
* richard kappler [2016-12-27 15:39]: > I was actually working somewhat in that direction while I waited. I had in > mind to use something along the lines of: > > > stx = '\x02' > etx = '\x03' > line1 = "" > > with open('original.log', 'r') as f1: >with open('new.log', 'w') as f2: >

Re: [Tutor] formatting xml (again)

2016-12-27 Thread richard kappler
I was actually working somewhat in that direction while I waited. I had in mind to use something along the lines of: stx = '\x02' etx = '\x03' line1 = "" with open('original.log', 'r') as f1: with open('new.log', 'w') as f2: for line in f1: if stx in line:

Re: [Tutor] formatting xml (again)

2016-12-27 Thread David Rock
* richard kappler [2016-12-27 14:44]: > > I have tried to feed this raw into our other app (Splunk) and the app reads > each line (gedit numbered line) as an event. I want everything in between > each stx and etx to be one event. > > I have tried: > > # > wit

[Tutor] formatting xml (again)

2016-12-27 Thread richard kappler
Using python 2.7 - I have a large log file we recorded of streamed xml data that I now need to feed into another app for stress testing. The problem is the data comes in 2 formats. 1. each 'event' is a full set of xml data with opening and closing tags + x02 and x03 (stx and etx) 2. some events h

Re: [Tutor] IndexError: list index out of range

2016-12-27 Thread Alan Gauld via Tutor
On 27/12/16 15:22, Mysore Ventaka Rama Kumar wrote: > Please review and comment/correct my error! Rather than expect us to read through many lines of code it would help id you posted the entire error message which will tell us exactly where the problem lies. Also tell us for completeness which P

[Tutor] IndexError: list index out of range

2016-12-27 Thread Mysore Ventaka Rama Kumar
Please review and comment/correct my error! Many thanks in advance. # Required module import os # Function for getting files from a folder def fetchFiles(pathToFolder, flag, keyWord): ''' fetchFiles() requires three arguments: pathToFolder, flag and keyWord flag must be 'STARTS_WI

Re: [Tutor] overriding brackets in lvalue assignment possible?

2016-12-27 Thread Peter Otten
James Hartley wrote: > I can successfully override __getitem__() for rvalues, but the following > example shows that more is required when used as an lvalue: > > ===8<- > #!/usr/bin/env python > > class Foo(): > def __init__(self, n): > self.d = dict.fromkeys([i for i in range(0,

Re: [Tutor] overriding brackets in lvalue assignment possible?

2016-12-27 Thread Zachary Ware
On Tue, Dec 27, 2016 at 10:48 AM, James Hartley wrote: > I can successfully override __getitem__() for rvalues, but the following > example shows that more is required when used as an lvalue: > > ===8<- > #!/usr/bin/env python > > class Foo(): > def __init__(self, n): > self.d = di

[Tutor] overriding brackets in lvalue assignment possible?

2016-12-27 Thread James Hartley
I can successfully override __getitem__() for rvalues, but the following example shows that more is required when used as an lvalue: ===8<- #!/usr/bin/env python class Foo(): def __init__(self, n): self.d = dict.fromkeys([i for i in range(0, n)]) def __getitem__(self, i):