# Flag pager_ Non analysis of pages

Time：2021-5-6

Database information:

Code program:

``````if __name__ == "__main__":
user=User.query.paginate(1,2)
for i in user.iter_pages():
print(i,end="   ")

Output information: 1 2 3 4 5 none 8 9``````

Today, I have a look at the source code to analyze it

``````def iter_pages(self, left_edge=2, left_current=2,
right_current=5, right_edge=2):
last = 0
for num in xrange(1, self.pages + 1):
if num <= left_edge or
(num > self.page - left_current - 1 and
num < self.page + right_current) or
num > self.pages - right_edge:
if last + 1 != num:
yield None
yield num
last = num``````

You can see clearly whenlast+1 != numThe next problem is if you can make the
last+1 != Num, that’s when
num <= left_edge or
(num > self.page – left_current – 1 and num < self.page + right_current) or
num > self.pages – right_ When edge was not established,
The next loop will make last + 1= num。
So, how do we end up with the goal that many people want to traverse completely? That is to change the value of the default parameter so that any of the above three conditions will always hold, such as num < = left_ Edge forever

``````for i in user.iter_pages(left_edge=user.pages):
print(i,end="   ")

Output result: 1 2 3 4 5 6 7 8 9``````

This is the perfect solution. Of course, any of the above three arbitrary conditions can be used for complete traversal. Of course, there are other traversal methods. You can think about them.

## The 50 MySQL interview questions, Ali’s interviewer called the expert (Part 1)

preface As for the so-called golden, silver and four, friends who want to change jobs to big factories should also be actively preparing for this period of time. Mysql, as one of the most popular relational database management systems, probably does not need me to say more about its importance. It is almost necessary to […]