既出のこの内容そのものと思われますが、いかがでしょう?個人的にはクラス化するか、もし複数の共通変数が存在するなら、まとめて共通で使用する変数を辞書にしてしまう手とか?
Python - Python 外部ファイルで定義した変数を使用したい|teratail
とりあえず、以上をまとめてみました。まだ初心者なので違っていたらすいません。
python3
1#te177123other.py
2
3x=''
4mainx=''
5objclass=''
6
7dictx={
8 'dx':''
9}
10
11def testglobal():
12 global x
13 ulr = "ここでulrアクセスする"
14 x = ulr
15 dictx['dx']= ulr
16
17class Testclass():
18 def __init__(self):
19 ulr = "ここでulrアクセスする"
20 Testclass.cx = ulr
21 self.ix= ulr
22 def retix(self):
23 return self.ix
python3
1#te177123main02.py
2import te177123other
3
4print("otherのglobal指定")
5print("te177123main02:te177123other.x:{}".format(te177123other.x))
6print("otherの辞書変数指定")
7print("te177123main02:te177123other.dictx['dx']:{}".format(te177123other.dictx['dx']))
8print("te177123main00内でte177123other.mainx指定")
9print("te177123main02:te177123other.mainx:{}".format(te177123other.mainx))
10
11obj=te177123other.objclass
12print("otherのClassインスタンス変数指定")
13print("te177123main02:te177123other.objclass.ix:{}".format(obj.ix))
14print("otherのClassインスタンス変数の戻り値指定")
15print("te177123main02:te177123other.objclass.retix():{}".format(obj.retix()))
16print("otherのClassクラス変数指定")
17print("te177123main02:te177123other.objclass.cx:{}".format(obj.cx))
python3
1#te177123main00.py
2import te177123other
3def init():
4 te177123other.testglobal()
5 te177123other.objclass=te177123other.Testclass()
6 ulr = "ここでulrアクセスする"
7 te177123other.mainx= ulr
python3
1#te177123.py
2import te177123main00
3te177123main00.init()
4import te177123main02
5
6print("test ok")
result
1otherのglobal指定
2te177123main02:te177123other.x:ここでulrアクセスする
3otherの辞書変数指定
4te177123main02:te177123other.dictx['dx']:ここでulrアクセスする
5te177123main00内でte177123other.mainx指定
6te177123main02:te177123other.mainx:ここでulrアクセスする
7otherのClassインスタンス変数指定
8te177123main02:te177123other.objclass.ix:ここでulrアクセスする
9otherのClassインスタンス変数の戻り値指定
10te177123main02:te177123other.objclass.retix():ここでulrアクセスする
11otherのClassクラス変数指定
12te177123main02:te177123other.objclass.cx:ここでulrアクセスする
13test ok
こんな感じで間違ってないですかね?ちょっと自信ないですが。
te177123.py(主プログラム)
te177123other.py(定義)
te177123main00.py(URLを設定するプログラム)
te177123main02.py(それぞれのプログラム)