Per the Name and Binding docs:
The scope of names defined in a class block is limited to the class block; it does not extend to the code blocks of methods – this includes comprehensions and generator expressions since they are implemented using a function scope. This means that the following will fail:
class A: a = 42 b = list(a + i for i in range(10))
See this answer for more details.
In Python2, it is possible to use list comprehensions, since they were implemented without using a function scope:
dict([(e,loadings[e]) for e in loadings])
But this code would break if run in Python3. So here is an alternative workaround which would work in Python2 and Python3:
class Foo:
def loadings():
load = dict(hi=1)
if 'hi' in load:
print(load['hi'])
print({e:load[e] for e in load})
return load
loadings = loadings()
print(Foo.loadings)