Python “from matplotlib import pyplot as plt” == “import matplotlib.pyplot as plt”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30558087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is "from matplotlib import pyplot as plt" == "import matplotlib.pyplot as plt"?
提问by megashigger
from matplotlib import pyplot as plt
import matplotlib.pyplot as plt
Are the above statements equivalent? Which is more readable/better form?
以上陈述是否等价?哪个更易读/更好的形式?
采纳答案by Eric Appelt
Even though they are equivalent, I think there is a pretty good argument that the second form import matplotlib.pyplot as plt
is objectively more readable:
尽管它们是等价的,但我认为有一个很好的论点,即第二种形式import matplotlib.pyplot as plt
客观上更具可读性:
It is generally customary to use
import matplotlib.pyplot as plt
and suggested in the matplotlib documentation (see http://matplotlib.org/users/pyplot_tutorial.htmletc...) so this will be more familiar to most readers.import matplotlib.pyplot as plt
is shorter but no less clear.import matplotlib.pyplot as plt
gives an unfamiliar reader a hint that pyplotis a module, rather than a function which could be incorrectly assumed from the first form.
通常习惯于
import matplotlib.pyplot as plt
在 matplotlib 文档中使用和建议(参见http://matplotlib.org/users/pyplot_tutorial.html等...),因此大多数读者会更熟悉这一点。import matplotlib.pyplot as plt
更短但同样清晰。import matplotlib.pyplot as plt
给不熟悉的读者一个提示,即pyplot是一个模块,而不是一个可能从第一种形式错误地假设的函数。
回答by Padraic Cunningham
They both work the same so it is up to you which you prefer, personally I don't like typing so I would prefer the second.
它们的工作方式相同,因此您喜欢哪种取决于您,我个人不喜欢打字,所以我更喜欢第二种。
from matplotlib import pyplot as plt
import matplotlib.pyplot as plt1
print(dir(plt) == dir(plt1))
True
回答by Priya Bharti
Yes,Both are same. It's Depends upon you what you prefer to import.
是的,两者都是一样的。这取决于你喜欢导入什么。
Personally I Like to Write :
我个人喜欢写:
from matplotlib import pyplot as plt
Because it's look more clear and clean to me.
因为它对我来说看起来更清晰和干净。