에 업데이트되지 나는 글로벌 VAR와 파이썬 파일을 가지고 클래스를 정의 :파이썬 글로벌 새 개체 인스턴스
ROOT = 'https://api.example.com/2.0/'
class Mail(object):
def __init__(self, api_key):
self.name = "FName"
if api_key.find('-'):
dc = api_key.split('-')[1]
global ROOT
print "initing root to: %s" % (ROOT,)
ROOT = ROOT.replace('https://api.', 'https://'+dc+'.api.')
print "initing after replace of ROOT: %s" % (ROOT,)
def pprint(self):
print 'POST to %s' % (ROOT,)
이 설정되어 일단 ROOT
세계가 갱신되지 않습니다 보인다
>>> import pyglob
>>> mc = pyglob.Mail('dfadsfad-us1')
initing root to: https://api.example.com/2.0/
initing after replace of ROOT: https://us1.api.example.com/2.0/
>>> mc.pprint()
POST to https://us1.api.example.com/2.0/
>>> mc3 = pyglob.Mail('dfadsfad-us3')
initing root to: https://us1.api.example.com/2.0/
initing after replace of ROOT: https://us1.api.example.com/2.0/
>>> mc3.pprint()
POST to https://us1.api.example.com/2.0/
>>> mc.pprint()
POST to https://us1.api.example.com/2.0/
누군가가 어떻게 작동하는지 설명하고 원인을 설명 할 수 있습니까? 'https://api.'
더 이상 대체 --you've ROOT
에 있기 때문에 당신이 ROOT = https://us1.api.example.com/2.0/
을 변경 한 후
첫 번째 바꾸기 호출 이후에 대체 할 'https : // api.'가 없기 때문에. –
@AshwiniChaudhary, 아! 그게 오는 것을 보지 못했습니다. – Gezim