首页IT科技python中包的导入(Python导入包的注意事项)

python中包的导入(Python导入包的注意事项)

时间2025-07-29 04:33:22分类IT科技浏览4006
导读:本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。...

本文教程操作环境:windows7系统             、Python 3.9.1             ,DELL G3电脑             。

1                   、使用注意

(1)只是导入包不能随便使用其中的模块                   ,要导入到具体模块或者变量的层次

(2)文件夹与文件之间可以用.也可以用from import格式      ,而文件与里面的变量之间只能用from import格式       ,即不能import folder1.abcd.b

2      、实例

>>>importfolder1 >>>folder1.abcd.b Traceback(mostrecentcalllast): File"<stdin>",line1,in<module> AttributeError:modulefolder1hasnoattributeabcd >>>fromfolder1importabcd >>>bob=abcd.Myclass(name=Bob,age=20) >>>bob.name Bob >>>bob.get_info()mynameisBobandageis20 >>>fromfolder1.abcdimportb >>>b 2 >>>importfolder1.abcd >>>abcd.bTraceback(mostrecentcalllast):File"<stdin>",line1,in<module>NameError:nameabcdisnotdefined >>>folder1.abcd.b2 >>>importfolder1.abcdasaa >>>aa.b 2

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
局域网故障处理(局域网故障怎么排除?) 白帽子ctf(白帽子是干嘛)