문제

나는 이것이 매우 사악하다는 것을 알고 있지만 다른 모듈의 글로벌에 물체를 추가 할 수 있습니다.

#module dog.py
import cat
cat.globals.addVar('name','mittens')

그리고

#module cat.py
print name #mittens
도움이 되었습니까?

해결책

setattr(cat, 'name', 'mittens')

또는

cat.name = 'mittens'
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top