python:导入模块的三种不同方法,类似于import

1、类似   import numpy 或from helloworld import hello

2、使用系统函数__import__()    类似于np = __import__('numpy')

3、使用exec 类似于np="import numpy as np",然后执行exec(np)

另外: 查看所有变量用locals(),dir()

   查看变量是否具有某属性和方法,用hasattr(string,'count'),就是判断变量string是否具有count属性(方法)

   查看


猜你喜欢

转载自blog.csdn.net/hanfeixue11/article/details/77773369
今日推荐