x = "error" def test(x): class Test(object): x = x print ("x:", x) print ("Test.x:", Test.x) class Test2(object): y = x print ("Test2.y:", Test2.y) class Test3(object): y = x x = x print ("Test3.x:", Test3.x) print ("Test3.y:", Test3.y) class Test4(object): pass Test4.x = x print ("Test4.x:", Test4.x) test("success") from dis import dis dis(test)