Re: [Tutor] string delimiters

2015-06-03 Thread Alan Gauld
On 03/06/15 21:23, richard kappler wrote: hold the phone I have no idea why it worked, would love an explanation, but I changed my previous test script by eliminating for tag in (icdm): This loops over the string assigning the characters i,c,d and m to tag if 'icdm' in line: This

Re: [Tutor] string delimiters

2015-06-03 Thread Alan Gauld
On 03/06/15 20:10, richard kappler wrote: for formatting a string and adding descriptors: test = 'datetimepart1part2part3the_rest' If this is really about parsing dates and times have you looked at the datetime module and its parsing/formatting functions (ie strptime/strftime)? Can I stop

Re: [Tutor] string delimiters

2015-06-03 Thread richard kappler
I was trying to keep it simple, you'd think by now I'd know better. My fault and my apology. It's definitely not all dates and times, the data and character types vary. This is the output from my log parser script which you helped on the other day. there are essentially two types of line: Tue

Re: [Tutor] string delimiters

2015-06-03 Thread richard kappler
hold the phone I have no idea why it worked, would love an explanation, but I changed my previous test script by eliminating for tag in (icdm): and changing if tag in line to if 'icdm' in line: and it works perfectly! It only iterates over the file once, and the else executes so both

Re: [Tutor] string delimiters

2015-06-03 Thread Alan Gauld
On 03/06/15 21:13, richard kappler wrote: I was trying to keep it simple, you'd think by now I'd know better. My fault and my apology. It's definitely not all dates and times, the data and character types vary. This is the output from my log parser script which you helped on the other day.

Re: [Tutor] string delimiters

2015-06-03 Thread richard kappler
figured that out from your last post, and thank you, now I understand how that works. I thought I was looking for the entire string, not each character. That bit all makes sense now. A descriptor is, for example, for the following part of a string '0032.4' the descriptor would be weight, so the

[Tutor] string delimiters

2015-06-03 Thread richard kappler
for formatting a string and adding descriptors: test = 'datetimepart1part2part3the_rest' newtest = 'date=' + test[0:4] + ' time=' + test[4:8] + ' part1=' + test[8:13] + ' part2=' + test[13:18] + ' part3=' + test[18:23] + ' the rest=' + test[23:] and while this may be ugly, it does what I want

Re: [Tutor] string delimiters

2015-06-03 Thread Alex Kleider
On 2015-06-03 12:53, Alan Gauld wrote: ... If this is really about parsing dates and times have you looked at the datetime module and its parsing/formatting functions (ie strptime/strftime)? I asssume strftime gets its name from 'string from time.' What about strptime? How did that get its

Re: [Tutor] string delimiters

2015-06-03 Thread Cameron Simpson
On 03Jun2015 14:16, Alex Kleider aklei...@sonic.net wrote: On 2015-06-03 12:53, Alan Gauld wrote: ... If this is really about parsing dates and times have you looked at the datetime module and its parsing/formatting functions (ie strptime/strftime)? I asssume strftime gets its name from

Re: [Tutor] string delimiters

2015-06-03 Thread Alex Kleider
On 2015-06-03 15:13, Mark Lawrence wrote: 'f' for format, 'p' for parse, having originally come from plain old C. More here https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior So I was wrong about the 'f' as well as having no clue about the 'p'! Thank you very much

Re: [Tutor] string delimiters

2015-06-03 Thread richard kappler
Perhaps the better way for me to have asked this question would have been: How can I find the location within a string of every instance of a character such as ']'? regards, Richard On Wed, Jun 3, 2015 at 5:16 PM, Alex Kleider aklei...@sonic.net wrote: On 2015-06-03 12:53, Alan Gauld wrote:

Re: [Tutor] string delimiters

2015-06-03 Thread Mark Lawrence
On 03/06/2015 22:16, Alex Kleider wrote: On 2015-06-03 12:53, Alan Gauld wrote: ... If this is really about parsing dates and times have you looked at the datetime module and its parsing/formatting functions (ie strptime/strftime)? I asssume strftime gets its name from 'string from time.'

Re: [Tutor] string delimiters

2015-06-03 Thread Alan Gauld
On 03/06/15 22:16, Alex Kleider wrote: On 2015-06-03 12:53, Alan Gauld wrote: ... If this is really about parsing dates and times have you looked at the datetime module and its parsing/formatting functions (ie strptime/strftime)? I asssume strftime gets its name from 'string from time.' What

Re: [Tutor] string delimiters

2015-06-03 Thread Cameron Simpson
On 03Jun2015 17:35, richard kappler richkapp...@gmail.com wrote: Perhaps the better way for me to have asked this question would have been: How can I find the location within a string of every instance of a character such as ']'? With the str.find method! s = 'a]b]c' pos = s.find(']')

Re: [Tutor] string delimiters

2015-06-03 Thread Peter Otten
richard kappler wrote: Perhaps the better way for me to have asked this question would have been: How can I find the location within a string of every instance of a character such as ']'? import re s = alpha]beta]gamma]delta [m.start() for m in re.finditer(r], s)] [5, 10, 16] But do you