Python Forum
I can't use file __init__ to store shared variables and classes in the package - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/Forum-Python-Coding)
+--- Forum: General Coding Help (https://python-forum.io/Forum-General-Coding-Help)
+--- Thread: I can't use file __init__ to store shared variables and classes in the package (/Thread-I-can-t-use-file-init-to-store-shared-variables-and-classes-in-the-package)



I can't use file __init__ to store shared variables and classes in the package - AlekseyPython - Feb-03-2019

I placed global variables in file __init__ for each package. Now I get an error when I try to access these attributes:
Error:
AttributeError: 'method-wrapper' object has no attribute 'FormsDirectory'
There is a single line in the __init__ file of the Forms package:
FormsDirectory = '/home/alesha/eclipse-workspace/AnalysisData/Forms/'
In another file (where I want to use this variable) I wrote:
from Forms import __init__ as MyForms
d = MyForms.FormsDirectory // ERROR !!!
I looked in the debugger- mode: indeed, the variable MyForms has the type methodwrapper... Why?


RE: I can't use file __init__ to store shared variables and classes in the package - ichabod801 - Feb-03-2019

Why not just import Forms?

import Forms
d = Forms.FormsDirectory



RE: I can't use file __init__ to store shared variables and classes in the package - AlekseyPython - Feb-04-2019

(Feb-03-2019, 08:49 PM)ichabod801 Wrote: Why not just import Forms?

import Forms
d = Forms.FormsDirectory

Thank you! Dance