Answer the question
In order to leave comments, you need to log in
Outputting a line that starts with...?
Hello! I have a text document that I have already opened and read with Python, now I want to count the number of lines that start with 123(text) for example. That is, they start with 123 and what is in brackets no longer matters.
Answer the question
In order to leave comments, you need to log in
with open('file', 'r') as fp:
print len([i for i in fp if i.startswith('123')])
as an option, you translate its contents into str and compare with the first three characters 123
if mystr[0:3] == '123':
condition1
else:
condition2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question