33
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 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
33
24
0

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
  3. You can use dark theme
What you can do with signing up
33
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?