簡體   English   中英

如何將變量導入 Python 3.3+ 中的其他 python 文件?

[英]How can I import variables to other python file in Python 3.3+?

我有一個這樣的工作區結構:

folder
      file1
      file2

我想將 file1 的變量導入到文件 2。我在 Anaconda 環境中使用 python 3.7.6。

當我在文件 2 中寫入

import file1

我明白了

Error: ModuleNotFoundError: No module named 'file1'

我試圖在目錄中保存一個名為__init__.ipynb的空文件,但它不起作用。

我努力了:

from file1 import #variables

但我明白了。 錯誤

提前致謝。

這應該可以解決問題:

from file1 import YourClass # or your functions, etc.

暫無
暫無

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

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