python
python copied to clipboard
[New Concept Exercise] : imports
This issue describes how to implement the imports concept exercise for the Python track, which should explain how & why it is useful to import names (libraries, modules, classes, functions, etc.) in Python. We're naming the concept "imports" to avoid a file name clash with the import keyword.
Getting started
Please please please read the docs before starting. Posting PRs without reading these docs will be a lot more frustrating for you during the review cycle, and exhaust Exercism's maintainers' time. So, before diving into the implementation, please read up on the following documents:
Please also watch the following video:
Goal
This concept exercise should convey a basic understanding and usage of import and import from in a Python program. Additionally, the student should learn how to employ the as keyword for aliasing (re-naming) in animport context.
Learning objectives
- Use the
importkeyword to import an entire Python library or module for use in a program - use the
askeyword to refer to an imported module by some other (aliased) name - use the
fromkeyword to import only specific classes/functions/names from a library or module - use the
askeyword with thefromkeyword to alias or re-name the specific classes/functions/names imported from a library or module. - be aware of
importconventions as outlined in PEP8
Out of scope
- The
importlibmodule, and the customization of import behavior.
Concepts
importstatementimport fromstatementimport ... asstatement
Prerequisites
basics
Resources to refer to
import(python docs)- yawpitchroll blog: import (The 35 words you need to Python)
- yawpitchroll blog: as (The 35 words you need to Python)
- Real Python: the Import keywords
- PEP-8: imports
Hints
- Hints should refer to one or more of the links above, or analogous links from trusted sources or the Python docs.
Concept Description
(a variant of this can be used for the v3/languages/python/concepts/<concept>/about.md doc and this exercises introduction.md doc.)
Concept Description Needs to Be Filled In Here/Written
Some "extras" that we might want to include as notes in the concept description, or as links in links.json:
- Considerations and conventions when importing a large amount of libraries.
- Specific conventions used in large frameworks and projects such as django or pandas
- More details on Pythons import system and
importlib - Modules and and the module search path
Representer
No changes required.
Analyzer
No changes required.
Implementing
The general Python track concept exercise implantation guide can be found here.
Tests should be written using unittest.TestCase and the test file named imports_test.py.
Code in the .meta/example.py file should only use syntax & concepts introduced in this exercise or one of its prerequisites. Please do not use comprehensions, generator expressions, or other syntax not previously covered. Please also follow PEP8 guidelines.
Help
If you have any questions while implementing the exercise, please post the questions as comments in this issue, or contact one of the maintainers on our Slack channel.
Edits
- Added additional links for
asandfromkeywords. Re-phrased goals and objectives for clarity. @BethanyG
Not yet sure we need/want an entire exercise devoted to import. Putting this back on hold until we decide.
Flagging as close and re-open with new issue template. Also needs clarification on scope.