从python shell导入自己的*.py文件

2024-09-27 07:19:46 发布

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

我使用名为“test.py”的vim在Python3中创建了一个测试文件

def addtwo(one, two):
    new = one + two
    return new

我把那个文件保存在我的$HOME目录中

然后我通过键入python3打开Python shell

在shell I类型中:

from test.py import *

我得到的回报是:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'test.py'; 'test' is not a package

我想这是一个文件路径问题,我在谷歌上搜索了一下,但我可能没有正确地表达我的问题。有人能帮我照一下吗


Tags: 文件pytest目录homenewreturndef

热门问题