Python 从一个文件中调用另一个文件的类方法
作者:刺客五六柒 时间:2022-02-22 23:36:35
如果是在同一个 module中(也就是同一个py文件里),直接用就可以
如果在不同的module里,例如
a.py里有 class A:
b.py 里有 class B:
如果你要在class B里用class A 需要在 b.py的开头写上 from a import A
举个例子:
比如我在文件lingkingtables.py的文件中构造了三个类,在另一个文件中想要引用这三个类,那么用如下语句即可
from lingkingtables import Lnode
from lingkingtables import Llist
from lingkingtables import LinkListUnderFlow
注意:类名要和文件名符合,且引用时要注意原始文件类的基类与派生类的关系
来源:https://blog.csdn.net/qq_39521554/article/details/79156119
标签:Python,文件,类
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
WAP中的ASP技术
2008-05-18 13:30:00
Python3导入自定义模块的三种方法详解
2021-06-05 18:49:27
![](https://img.aspxhome.com/file/2023/3/86533_0s.png)
asp如何让服务器延时执行更改后的数据?
2010-05-13 16:35:00
python实现将json多行数据传入到mysql中使用
2022-12-28 06:41:51
tensorflow 输出权重到csv或txt的实例
2021-07-19 11:54:52
用正则表达式表示不包含2950的字符串
2010-03-02 22:10:00
python爬虫爬取某站上海租房图片
2023-04-21 09:09:56
![](https://img.aspxhome.com/file/2023/2/115442_0s.png)
ASP平台如何打造金牌英文网站
2008-04-10 08:47:00
python Kmeans算法原理深入解析
2022-03-01 07:26:55
![](https://img.aspxhome.com/file/2023/8/95548_0s.png)
Python 使用Opencv实现目标检测与识别的示例代码
2023-01-23 17:46:11
![](https://img.aspxhome.com/file/2023/6/92416_0s.jpg)
Python中求对数方法总结
2023-04-13 22:20:28
![](https://img.aspxhome.com/file/2023/1/107591_0s.png)
python使用协程实现并发操作的方法详解
2021-09-24 11:23:10
Python抽象类的新写法
2022-12-04 13:39:38
python使用Plotly绘图工具绘制散点图、线形图
2022-06-24 08:11:50
![](https://img.aspxhome.com/file/2023/7/78607_0s.png)
使用Python webdriver图书馆抢座自动预约的正确方法
2021-01-26 10:21:07
![](https://img.aspxhome.com/file/2023/9/92439_0s.jpg)
学习ASP的理由 分析小结
2011-02-26 10:54:00
Python中删除文件的几种方法实例
2021-02-02 05:57:13
在Python中使用SimpleParse模块进行解析的教程
2021-04-11 12:17:53
python中验证码连通域分割的方法详解
2022-09-30 11:04:00
全面了解Python环境配置及项目建立
2023-11-03 18:40:44
![](https://img.aspxhome.com/file/2023/6/107876_0s.jpg)