Python import xxx with the From XXX import XX module introduces the difference

Source: Internet
Author: User






The following script is script1.py:



A= ' AAAA '
b= ' bbbb '

Print A,b,c






1. Use import in command line interactive mode 1:



>>>import SCRIPT1



Then enter the command print separately:



>>>print script1. A, Script1. B, Script1. C



>>>print A,b,c



The results are as follows:






Can see



Print script1. A, Script1. B, Script1. C Normal fetch to the value of A,b,c



But print a,b,c an error, and a didn't declare it.



2. Use the From ... import ... The way to import:



>>>from script1 Import A,b,c



Enter the command to print separately:



>>>print script1. A, Script1. B, Script1. C



>>>print A,b,c



The results of the operation are as follows:









As you can see, the print a,b,c correctly takes the value, but script1. A error, SCRIPT1 not declared



There are two ways to introduce the difference, the two ways to import the variable storage is this:












Python import xxx with the From XXX import XX module introduces the difference


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.