Day4 python Reflection

Source: Internet
Author: User

The file hierarchy is as follows:

Reflact

Backend

account.py

admin.py

index.py

The function login () in account.py needs to be used in index, and the reflection code is as follows:

#等同于import
data = input (' plase input ur URL: ')
Array = data.split ('/')

File = __import__ (' backend. ') +array[0]) #加字符串的拼接, can be completed two times after joining GetAttr
Model = getattr (file, array[0])
Func = GetAttr (model, array[1]) #导入对了, module has no properties
#再加一层getattr
Func ()

‘‘‘
Import Backend.account

‘‘‘

Day4 python Reflection

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.