LoginSignup
19

More than 3 years have passed since last update.

importで別ファイルの変数を取得

Posted at

目的

別のファイル(A)で定義している変数を別のファイル(B)で使えるようにする。
BでimportしたAの変数を利用する。

構成

-A.py
-B.py

やり方

A.py
size = 50
name = "hoge"
rate = 0.3

この変数をimport先で使う

B.py
import A

print(A.size)
print(A.name)
print(A.rate)

結果
$ python B.py

50
hoge
0.3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
19