Opening the Chou Chou, again a few questions it faces Python, Python face questions No20

This exam face questions from the public number: undergraduate non-programmers finishing release

Question 1: How to understand Django is known as MTV mode?

The problem is that the object-oriented design and design patterns start of.
You may be more familiar pattern is called: MVC. Said that the Model View Controller, while in Django view show as Template to deal with, so called:
MTV.
Took over to ask is layered concept, there is a saying: "There is no problem that can not be solved by increasing the level, if there is, then add a layer." Of course there will be some design patterns the principle of waiting for you, such as open - closed principle, the principle of single responsibility and so on.

Question 2: What is next explain what ORM as well as its strengths and weaknesses?

ORM: Object Relational Mapping (Object-relational mapping), it is to help us do what packaging operation of the database, we avoid to write SQL code is not very good maintenance.

  • The advantage is to allow us to write code that is easier to maintain, because it was not mixed with a variety of SQL code.
  • The disadvantage is the loss of flexibility of SQL, and the more generic ORM framework, performance loss will be greater.

When it comes to performance loss, then you can talk in a raw sql Django, that Model.objects.raw use this method, its role, principles, performance improvements and so on. Another problem can continue to talk a commonplace: N + 1 problem.

Question 3: How Django configured in the system long connection to the database?

This involves the question of how to deal with Django database connection details. For each connection request Django will establish a new database by default. This means that when a request is too large there will be a database (MySQL) is Too many connection problems, for that matter, there is such thing as connection pooling in other languages ​​framework to reduce the number of connections to the database, to improve connections efficiency. In Django, in order to deal with this issue, we added a configuration:

CONN_MAX_AGEIn DATABASES configuration settings in. After you configure this option, Django will remain linked with the database (length depends on the value set when CONN_MAX_AGE), will no longer have to create a new connection for each request.

However, note that this concept with the database connection pool also not the same.

Question 4: Please explain the difference between a thread lock Lock and Rlock the python, and you have in the project is how to use?

In the same thread, for RLock multiple acquire () operation, the program will not block: In principle.
Resources are always limited, if the program is running to operate on the same object, it may cause resource contention, and even lead to a deadlock could lead to confusion literacy

Question 5: dictionary, when the time complexity of the query list what?  

List is a sequence can be interpreted as an array data structure, can be understood as the dictionary data structure hashmap, the structure of the python list stored in the object is used in linear form, so the complexity of the query O(n).
Dict object stored configuration uses a hash table (hash table), which in most cases the query complexity is O (1).
dict of memory for a little more than a large list, will be around 1.5 times.

Question 6: Focus on questions, most recently updated in public a magic number of how-to articles series

More welcome attention https://dwz.cn/r4lCXEuL

Guess you like

Origin www.cnblogs.com/happymeng/p/10941617.html