Lyman
Lyman

Reputation: 9

Why len return different values?

c=b.readlines()
print(len(c))
print(len(b.readlines()))

this is what I got: 2 0

Why are these two results different?

Upvotes: 0

Views: 45

Answers (2)

Bathsheba
Bathsheba

Reputation: 234695

readlines() is a function with a side-effect: it is clearly consuming data from b.

So a second invocation may well give you a different result.

Upvotes: 0

Tom Tanner
Tom Tanner

Reputation: 9354

because you've already read the lines from b and it has nothing left to return

Upvotes: 2

Related Questions