在Termin中使用Python函数

2024-09-27 21:26:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我刚刚开始学习Python,我很难在终端上进行测试。 我只想在Python解释器中运行一个预先编写的Python方法。(我知道如何通过python文件运行它_名称.py,但我想在解释器中运行它)。在

所以如果我有档案“示例模块.py“:

def exampleFunc(data):
    print(data)

然后在终端中运行Python并执行以下操作:

^{pr2}$

我不明白的是,如果我在pythonidle中运行模块,我可以访问exampleFunc,但不能在终端解释器中访问。在

谢谢!在


Tags: 模块文件方法py名称终端示例data
1条回答
网友
1楼 · 发布于 2024-09-27 21:26:06

当你这么做的时候

import exampleModule

你必须写下它函数的全名。根据Docs*

This does not enter the names of the functions defined in exampleModule directly in the current symbol table; it only enters the module name exampleModule there. Using the module name you can access the functions

如果只想写函数名,那么就写

^{pr2}$

根据Docs*

This does not introduce the module name from which the imports are taken in the local symbol table (so in the example, exampleModule is not defined).

**为了更好地理解,将函数名称改为您的名称。*

相关问题 更多 >

    热门问题