1
a=open('D:/1.txt','r')
b=a.readlines()

now we get b which contains all the line in 1.txt.
But we know that in Python when we don't use a line we could use

\# mark

to ignore the specific line.
Is there any command we could use in TXT to ignore a specific line when use readlines?

0

1 Answer 1

2

Text files have no specific syntax, they are just a sequence of characters. It is up to your program to decide if any of these characters have particular meaning for your program.

For example if you wanted to read all lines, but discard those starting with '#' then you could filter those out using a list comprehension

with open('D:/1.txt','r') as a:
    lines = [line for line in a if not line.startswith('#')]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.