簡體   English   中英

從 python shell 導入自己的 *.py 文件

[英]Import own *.py file from the python shell

我使用名為“test.py”的 vim 在 Python 3 中創建了一個測試文件

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

我將該文件保存在$HOME目錄中。

然后我通過鍵入python3打開 Python shell

在 shell 中,我輸入:

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

我認為這是某種文件路徑問題並做了一些谷歌搜索,但我可能沒有正確地表達我的問題。 有人可以透露一些信息嗎?

代替

from test.py import *

它是

from test import *

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM