두 개의 파이썬 스크립트 사이에서 값을 공유하려고합니다. 첫 번째 스크립트에서 값을 싱글 톤으로 설정하지만 두 번째 스크립트에서 값을 얻으면 기본값 (0) 반환됩니다. 여기파이썬 : 공유 값은 항상 0입니다.
내 파일입니다
import mod #import the singleton class
...
mod.setDistance(35) #set the value with the singleton file mod.py
싱글 톤 파일 : (mod.py)
값을 설정import mod #import the singleton class
...
def sendDistance(self):
print(mod.getDistance()) #get the value
파일 : 값을 가져옵니다 파일
import distance #import the file where value is stored
def setDistance(val): #set Value function
distance.x=val
def getDistance(): #get value function
return distance.x
값이 저장된 파일 : (distance.py)
x=0 #the default value that should be modified from mod
값을 설정하는 파일 (print (mod.getValue()))에서 값을 가져 오려고하면 값이 올바르게 표시됩니다. 게터 측에서 값은 항상 0입니다.
이 질문의 어떤 부분도 나에게 의미가 없습니다. [mcve]? – melpomene
좋아요, 질문을 편집했습니다 – aphi
어떻게 완성 되었습니까? – melpomene