3 ms·
Quick question on the code. I'm looking at this commit: https://github.com/kennethreitz/requests/commit/773630b0109c7671930b7ab38bb71c22ac8a94c5#L0R16 https://
by bialecki 15y ago
Quick question on the code. I'm looking at this commit:
https://github.com/kennethreitz/requests/commit/773630b0109c7671930b7ab38bb71c22ac8a94c5#L0R16 https://github.com/kennethreitz/requests/commit/773630b0109c...
and wondering what "from .status_codes import codes" does?
Specifically the fact that it's not "status_codes" and has a dot prepended. Is that something special in Python (guessing no) or some convention that is used? Just curious.
- bialecki 15y agoJust needed to look at the docs: http://docs.python.org/reference/simple_stmts.html#the-import-statement http://docs.python.org/reference/simple_stmts.html#the-impor.... The relevant bit: "When specifying what module to import you do not have to specify the absolute name of the module. When a module or package is contained within another package it is possible to make a relative import within the same top package without having to mention the package name. By using leading dots in the specified module or package after from you can specify how high to traverse up the current package hierarchy without specifying exact names. One leading dot means the current package where the module making the import exists. Two dots means up one package level. Three dots is up two levels, etc. So if you execute from . import mod from a module in the pkg package then you will end up importing pkg.mod. If you execute from ..subpkg2 import mod from within pkg.subpkg1 you will import pkg.subpkg2.mod. The specification for relative imports is contained within PEP 328." Cool stuff.
- dheerosaur 15y agoReally cool stuff indeed. Thank you.
- pangram 15y agoIt's a relative import -- where "relative" here is like relative vs. absolute paths. See: http://docs.python.org/tutorial/modules.html http://docs.python.org/tutorial/modules.html