Functions defined in __init__ are not recognized when called on another variable

I have a Python code for a GUI app that I need to migrate. Here’s the global structure (it’s a flat-layout):

Project/
|-- format_controllers/
|   |-- __init__.py
|   |-- controller1/
|   |-- controller2/
|-- core/
|   |-- vars.py
|   |-- __init__.py (empty)
|-- Ctrl_App

The module vars.py define global variables, including this one:

global appCache
appCache = None

Then in my __init__.py file, there are many functions made to handle metadata about the main controllers, and the appCache var is finally initialized :

from core import vars
class AppCache():

    # Initialisation
    def __init__(self):
        self.__dataTypeMetaDict = {}
...

# End of AppCache ========================================================

basevars.CtrlCache = ControllerCache()

Finally, in my Ctrl_App (where there is import format_controllers, I have lines like this:

metaInfo = vars.appCache.metaInfoForType(self.config.dataType)

To sum it up, in Ctrl_App, functions from the __init__.py file of the package format_controllers are used on a global variable defined in a module from the core package, initialized to None, and reinitialized to something not null in the same __init__.py.

My problem is that I get errors. Because appCache is initialized to None in the init from the controllers package, in my Ctrl_App I get errors like this:

AttributeError: 'NoneType' object has no attribute 'metaInfoForType'

I’ve tried to redefine the variable in the beginning but at the end it’s the same. I don’t know why the __init__.py file, where the variable is initialized, is not taken into account when I import the package.

Is there an easier, and cleaner way to do that to finally fix this error? I can patch it but just writing global appCache and appCache = ControllerCache() in all the modules that use this variable but

  1. I think it’s not clean at all
  2. I’m afraid it’s a very unstable solution

Plus there must have been a good reason for the developer to do that this way, unfortunately I can’t get in touch with them or with anybody that could know.

Important to note : The code was written in Python 2.7 and used a lot of deprecated librairies and functions.

New contributor

axelle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

3

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật