-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-31454: Include information about "import X as Y" in tutorial #4041
Conversation
Doc/tutorial/modules.rst
Outdated
@@ -112,6 +112,17 @@ Note that in general the practice of importing ``*`` from a module or package is | |||
frowned upon, since it often causes poorly readable code. However, it is okay to | |||
use it to save typing in interactive sessions. | |||
|
|||
If as a user of the module you would like to import a module and make it available | |||
under a different name within the current namespace you can use ``import as``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "[...] you can use ``import as``" part can be confusing since import as
is not valid Python.
I'd use the following sentence as a base in Doc/reference/simple_stmts.rst
:
* If the module name is followed by :keyword:`as`, then the name
following :keyword:`as` is bound directly to the imported module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, please end the sentence with ::
(or add it not the next line):
[...] you can use ``import as``::
>>> import fibo as fib
...
or
[...] you can use ``import as``.
::
>>> import fibo as fib
...
Doc/tutorial/modules.rst
Outdated
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 | ||
|
||
This is effectively importing the module in the same way that ``import fibo`` | ||
will do, with the only difference of it being available under a different name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be better to explicitly say "[...] being available as ``fib``" (you can use different wording -- I just use it as an example) instead of "[...] being available under a different name".
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
I have made the requested changes; please review again |
Thanks for making the requested changes! @berkerpeksag: please review the changes made to this pull request. |
Thanks! I've also incorporated your suggestion from the issue tracker Let me know if it needs any re-wording! |
Doc/tutorial/modules.rst
Outdated
This is effectively importing the module in the same way that ``import fibo`` | ||
will do, with the only difference of it being available as ``fib``. | ||
|
||
It can be also used when utilising the ``from`` keyword with similar effects: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:keyword:`from`
Doc/tutorial/modules.rst
Outdated
|
||
:: | ||
|
||
>>> import fibo import fib as fibonacci |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first import
should read from
.
Doc/tutorial/modules.rst
Outdated
|
||
It can be also used when utilising the ``from`` keyword with similar effects: | ||
|
||
:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you ended the previous sentence with "[...] effects:", we can just write
[...] with similar effects::
instead of
[...] with similar effects:
::
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
I have made the requested changes; please review again |
Thanks for making the requested changes! @berkerpeksag: please review the changes made to this pull request. |
Previously "It can be also "
I made a small change in line 127: from "It can be also ..." to "It can also be .. ". |
Thanks @mariocj89 for the PR, and @Mariatta for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7, 3.6. |
Thanks @mariocj89 for the PR, and @Mariatta for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7. |
…ial (pythonGH-4041) (cherry picked from commit fbee882) Co-authored-by: Mario Corchero <mariocj89@gmail.com>
GH-5894 is a backport of this pull request to the 3.6 branch. |
…ial (pythonGH-4041) (cherry picked from commit fbee882) Co-authored-by: Mario Corchero <mariocj89@gmail.com>
GH-5895 is a backport of this pull request to the 3.7 branch. |
…ial (pythonGH-4041) (cherry picked from commit fbee882) Co-authored-by: Mario Corchero <mariocj89@gmail.com>
GH-5896 is a backport of this pull request to the 2.7 branch. |
Add some information about "import as" in the tutorial.
Happy to change the wording!
https://bugs.python.org/issue31454