python - When using from XXX import (XXX, XXX, XXX,) to import a module, what is the significance of the brackets ()?
世界只因有你
世界只因有你 2017-05-18 10:49:54
0
2
1092

When reading the django source code, I found that upper brackets are always added when importing modules, for example:

from django.core.exceptions import (
    DisallowedHost, ImproperlyConfigured, RequestDataTooBig,
)

from django.utils.encoding import (
    escape_uri_path, force_bytes, force_str, force_text, iri_to_uri,
)

Please tell me from XXX import (XXX, XXX, XXX,) What is the meaning of the brackets when importing the module like this?

世界只因有你
世界只因有你

reply all(2)
仅有的幸福

This is a coding specification started with PEP 328. When not adding parentheses, you need to add a backslash at the end of the line when breaking the line, as shown below:

from xxx import aaa, bbb, \
    ccc

Or write each line againfrom xxx import yyy:

from xxx import aaa
from xxx import bbb
from xxx import ccc

With parentheses, you can wrap new lines at will inside the parentheses:

from xxx import (
    aaa,
    bbb,
    ccc,
)

See PEP328

PHPzhong

Personal understanding:

from django.core.exceptions import (
DisallowedHost, ImproperlyConfigured, RequestDataTooBig
)

Equivalent

from django.core.exceptions import DisallowedHost;
from django.core.exceptions import ImproperlyConfigured;
from django.core.exceptions import RequestDataTooBig;

The syntax looks simpler, and you can tell at a glance which methods are imported from a module. It's also a matter of habit. The benevolent sees benevolence and the wise see wisdom. Personally, it’s OK if it’s comfortable

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!