[英]Using Python Functions in Terminal
我刚开始学习Python,并且很难在终端中进行测试。 我想做的就是在Python解释器中运行一个预编写的Python方法。 (我知道如何通过执行python file_name.py来运行它,但是我想在解释器本身中运行它)。
因此,例如,如果我有文件“ exampleModule.py”:
def exampleFunc(data):
print(data)
然后在终端中运行Python并执行以下操作:
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import exampleModule
>>> exampleFunc('Hello')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'exampleFunc' is not defined
我没有得到的是,如果我在Python IDLE中运行模块,则可以访问exampleFunc,但不能在终端解释器中访问。
谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.