hey guys am really confused about the working of dot operator..The code which i have tried..
class Name:
class x:
def __init__(self,y):
self.y = y
def __init__(self):
pass
some = Name()
some.x.y = 'foo'
print some.x.y
When i run this code it succesfully outputs foo.
But when i tried the code
class Name:
class x:
def __init__(self,y,z):
self.y = y
self.z = z
def __init__(self):
pass
some = Name()
some.x.y.z = 'foo'
print some.x.y.z
i get an error..how can i use like some.x.y.z and get the output as foo??..
Any useful help would be appreciated..Thanks
self.x.z? - EdChumsome.x.yandsome.x.z. Butzisn't insidey, so why would you expectsome.x.y.zto work? - Barmar__init__of your nested class is never called, because you never instantiate the class. When you set ``some.x.y` you're setting a class attribute onsome.x. In some sense this doesn't matter, sincexis itself a class variable, but it suggests you're not really understanding what your code is doing. What are you trying to accomplish here? - BrenBarnsome.x.y.z? Rather than talking about syntax, can you describe the meaning of what you want to do? - user2357112 supports Monica