Man, I've been coding Python for 6 years by now - and never heard of __dir__ for tab completion. This channel is pure gold.
@Quarky_ Жыл бұрын
Thanks for the __dir__ comment, I got stuck on this couple weeks ago when I was implementing __getattr__ to expose attributes of an underlying "private" object.
@kai3341 Жыл бұрын
Thank you for video. Also great thank you for your english -- it's easy to recognize it and then understand
@williamli558 ай бұрын
Hello Anthony. I've been watching your videos for a while now, and I think they're great. I was wondering if you might be willing to do a video which goes further into depth on __getattr__, __setattr__, and __getattribute__. I'd love to have a better understanding of how to properly use these methods. I feel like I often don't implement them properly.
@dorb1337 Жыл бұрын
When I created a def __dir__(self): return list(globals()) under a class C (like you created, just with the __dir__ function inside the class instead of outside to it) and i called c.__dir__() I got a lot of random gibbrish output, do you have any idea what it might point to ? ( My idea was that when globals() is called under a class, it just returns some random memory values that points to stuff, but when printed to the screen has no meaning) . here's my output example - ['__name__', '__doc__', '__package__', '__loader__', '__spec__', '__builtin__', '__builtins__', '_ih', '_oh', '_dh', 'In', 'Out', 'get_ipython', 'exit', 'quit', '_', '__', '___', '_i', '_ii', '_iii', '_i1', 'C', '_i2', '_i3', 'c', '_i4', '_4', '_i5', '_i6', '_6', '_i7', 'B', '_i8', 'b', '_i9', '_9', '_i10', '_10', '_i11', 'A', '_i12', '_i13', 'a', '_i14', '_i15', '_15', '_i16', '__dir__', '_i17', '_i18', '_18', '_i19', '_i20', '_i21', '_21', '_i22', '_22', '_i23']
@anthonywritescode Жыл бұрын
that's ipython garbage
@b_0rk Жыл бұрын
hi does this also work on python 2.4
@cerealport2726 Жыл бұрын
You could just try it and see...but as was explained, it seems it was added in 3.7