新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:Python導入包的注意事項
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。

1、使用注意
(1)只是導入包不能隨便使用其中的模塊,要導入到具體模塊或者變量的層次
(2)文件夾與文件之間可以用.也可以用from import格式,而文件與里面的變量之間只能用from import格式,即不能import folder1.abcd.b
2、實例
>>> import folder1 >>> folder1.abcd.b Traceback (most recent call last): File "", line 1, in AttributeError: module 'folder1' has no attribute 'abcd' >>> from folder1 import abcd >>> bob = abcd.Myclass(name = 'Bob', age = 20) >>> bob.name 'Bob' >>> bob.get_info()my name is Bob and age is 20 >>> from folder1.abcd import b >>> b 2 >>> import folder1.abcd >>> abcd.bTraceback (most recent call last): File " ", line 1, in NameError: name 'abcd' is not defined >>> folder1.abcd.b2 >>> import folder1.abcd as aa >>> aa.b 2
以上就是Python導入包的注意事項,希望能對大家有所幫助。更多Python學習指路:創(chuàng)新互聯(lián)python教程
網(wǎng)站欄目:創(chuàng)新互聯(lián)Python教程:Python導入包的注意事項
文章地址:http://fisionsoft.com.cn/article/djjjocs.html


咨詢
建站咨詢
