The difference between import and from ... import when Python introduces a module

Source: Internet
Author: User

Import DateTime is the introduction of the entire DateTime package, and if you use a DateTime class in a DateTime package, you need to add the module name qualification.

1 Import datetime2 3 print Datetime.datetime.now ()

If you do not add a module name qualification, an error occurs: TypeError: ' Module ' object is not callable \ Attributeerror: ' Module ' object have no attribute ' now '

The From datetime import datetime is a DateTime class that is only introduced in a DateTime package and does not require the qualification of the module name when it is used.

1 from datetime import datetime2 3 print DateTime.Now ()

Summary : Python imports modules in two ways: Import module and from module import, the difference is that the former all imported things to use with the module name qualification, the latter do not need.

Ext.: http://www.cnblogs.com/xxoome/p/5880693.html

When Python introduces a module, the import differs from the From ... import (GO)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.