Index in a list

A

Anatoli Hristov

Hello,

I'm trying to index a text in a list as I'm importing a log file and
each line is a list.

What I'm trying to do is find the right line which contains the text
User : and take the username right after the text "User :", but the
list.index("(User :") is indexing only if all the text matching. How
can I have the right position of the line which contains the word
("(User :")

Thanks

Anatoli
 
H

Hans Mulder

I'm trying to index a text in a list as I'm importing a log file and
each line is a list.

What I'm trying to do is find the right line which contains the text
User : and take the username right after the text "User :", but the
list.index("(User :") is indexing only if all the text matching. How
can I have the right position of the line which contains the word
("(User :")

Perhaps something like:

target = "(User :"
for line in your_list:
position = line.find(target)
if position >= 0:
print line[position+len(target):]


Hope this helps,

-- HansM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top