ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 27 Jul 2015 11:07:02 +0200imports in sage/combinat/free_module.pyhttps://ask.sagemath.org/question/28710/imports-in-sagecombinatfree_modulepy/I was reading the code in `sage/combinat/free_module.py` and I noticed some weirdness in the imports. In the second line there is a
from sage.structure.element import Element, have_same_parent
and then in the fourth line there is
from sage.structure.element import have_same_parent
and later on we find
import sage.structure.element
Why is this so? Can't some of these lines be erased?
Mon, 27 Jul 2015 10:39:17 +0200https://ask.sagemath.org/question/28710/imports-in-sagecombinatfree_modulepy/Answer by Nathann for <p>I was reading the code in <code>sage/combinat/free_module.py</code> and I noticed some weirdness in the imports. In the second line there is a</p>
<pre><code>from sage.structure.element import Element, have_same_parent
</code></pre>
<p>and then in the fourth line there is</p>
<pre><code>from sage.structure.element import have_same_parent
</code></pre>
<p>and later on we find</p>
<pre><code>import sage.structure.element
</code></pre>
<p>Why is this so? Can't some of these lines be erased?</p>
https://ask.sagemath.org/question/28710/imports-in-sagecombinatfree_modulepy/?answer=28713#post-id-28713For such questions, please write to sage-devel
https://groups.google.com/forum/#!forum/sage-devel Mon, 27 Jul 2015 10:57:31 +0200https://ask.sagemath.org/question/28710/imports-in-sagecombinatfree_modulepy/?answer=28713#post-id-28713Answer by tmonteil for <p>I was reading the code in <code>sage/combinat/free_module.py</code> and I noticed some weirdness in the imports. In the second line there is a</p>
<pre><code>from sage.structure.element import Element, have_same_parent
</code></pre>
<p>and then in the fourth line there is</p>
<pre><code>from sage.structure.element import have_same_parent
</code></pre>
<p>and later on we find</p>
<pre><code>import sage.structure.element
</code></pre>
<p>Why is this so? Can't some of these lines be erased?</p>
https://ask.sagemath.org/question/28710/imports-in-sagecombinatfree_modulepy/?answer=28714#post-id-28714The second import statement can indeed be removed since it is contained in the first. However, none of the first and third imply the other. With the first you can call the function `have_same_parent()` directly, while with the third you have to call the longer `sage.structure.element.have_same_parent()` but you will also be able to call the other functions of the `sage.structure.element` module such as `sage.structure.element.make_element()`.
Note that it is also possible to get the benefits of both types of imports (short to write and get many functions of the same module) as follows:
sage: import sage.structure.element as el
sage: el.have_same_parent()
sage: el.make_element()
Mon, 27 Jul 2015 11:07:02 +0200https://ask.sagemath.org/question/28710/imports-in-sagecombinatfree_modulepy/?answer=28714#post-id-28714