[Tutor] character that means beginning of line for readlines
sigurd at 12move.de
Mon Mar 22 11:14:15 EST 2004
On 22 Mar 2004, Vicki Stanfield <- vicki at stanfield.net wrote:
> it doesn't. I know how to do this with search in the vi editor; "^" means
> beginning of line. I found information that the same RE is used in Python.
Yes, but you don't use a regexp here.
> For some reason, I can't get it to work the way I want. I am using split
> to separate the line into tokens if that matters. Here is the code that
> isn't working:
> if tokens[i] == '0x11':
> if tokens[i-1]in ('0x3', '0x4','^'):
That tests if the token before '0x11' is either equal '0x3', '0x4' or
'^' (this is a literal character; it is here no meta character as in a
> The first 0x11, is converted to "0x31|0x31| even though it begins a line.
> Can someone explain this? I know that I can toggle a flag to determine
> this, but I'd rather do it with a regular expression.
Well you didn't use a regexp at all, but you could do it simpler IMO.
Since `i' seems to be an index the first token has index 0 or am I
wrong? If not just test if i == 0 if tokens[i] == '0x11'. So the test
would become: if tokens[i] == '0x11' and i == 0: ...
Please do *not* send copies of replies to me.
I read the list
More information about the Tutor