Ask Your Question
0

imports in sage/combinat/free_module.py

asked 2015-07-27 10:39:17 +0200

SL gravatar image

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?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2015-07-27 11:07:02 +0200

tmonteil gravatar image

updated 2015-07-27 11:13:50 +0200

The 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()
edit flag offensive delete link more
1

answered 2015-07-27 10:57:31 +0200

Nathann gravatar image

For such questions, please write to sage-devel https://groups.google.com/forum/#!for...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-07-27 10:39:17 +0200

Seen: 421 times

Last updated: Jul 27 '15