python模块如何实现简单调用
python模块如何实现简单调用
本文教程操作环境:windows7系统、Python3.9.1,DELLG3电脑。
1、比如我们有一个trymodule的文件夹,里面有一个first.py文件,文件中的内容如下
a=1
defmyfun(s):
print(s+1)
2、在trymodule的文件夹下打开命令行窗口(按住shift单击鼠标右键,选择“在此处打开命令窗口”),输入python进入命令行交互模式
>>>importfirst
>>>a
Traceback(mostrecentcalllast):
File"",line1,in
NameError:name'a'isnotdefined
>>>first.a1
>>>first.myfun(2)
3
3、所以说first.py文件就是一个模块,可以用import导入,里面变量都要用first.前缀来引用,如果想不使用这个前缀可以这样
>>>fromfirstimporta
>>>a
1
以上就是Python模块实现简单调用的方法,希望能对大家有所帮助。更多Python学习教程请关注IT培训机构:千锋教育。

猜你喜欢LIKE
相关推荐HOT
更多>>
python日志记录器的配置
python日志记录器的配置Logger对象有三个任务。第一,它们将一些方法暴露给应用程序代码,使应用程序能够在运行时记录消息。第二,记录器对象将...详情>>
2023-11-14 20:38:29
pythonvlookup函数功能是什么?
python中vlookup函数功能是什么?exce中的vlookup功能非常强大和方便。但总是手动操作,终究还是效率不高。在VBA,将一系列人工操作改为一键操作...详情>>
2023-11-14 16:51:57
pythonpathlib模块的用法有哪些?
python中pathlib模块的用法有哪些?在这个世界上,人们每天都在用Python完成着不同的工作。而文件操作,则是大家最常需要解决的任务之一。使用Py...详情>>
2023-11-14 16:29:17
python内置方法的汇总整理
python内置方法的汇总整理1、replace替换后是需要用另一种数据类型接受的数据。m=n.replace(“0b”,"")替换m中0b为“空“变量名.replace(“要替...详情>>
2023-11-14 15:53:51热门推荐
python中string和float之间的转换
沸python中UDP编程实现通信
热python中如何使用numpy.zeros()函数?
热python中子类与父类的关系
新python中泊松分布是什么意思?
python实现信息熵的计算代码
python日志记录器的配置
python如何对Python数据表进行检查
python基于LBPH的人脸识别操作
python中列表的索引如何理解?
python的id函数如何判断分片产生的列表?
python如何使用append函数扩展列表?
python如何实现信息增益和信息增益率
python使用import调用模块
技术干货






