Sharing data within a Python module -
i have written python libraries , structured them module. files within module require data text file work. easiest solution let each library read file whenever need it. however, reading same file several times seems inefficient. prefer read file once , share these data among different libraries. write additional library read data upon initialization , store in global variable, can imported other libraries afterwards. although may work, still think solution not elegant. there best practice kind of problem?
since supposed used commonly among modules, use should create file called constants inside package , initialize variable file contents in it. afterthought, init file of package candidate such kind of data.
Comments
Post a Comment