Fool Python class with imaginary members (serious guru stuff inside)
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Thu Sep 20 15:15:06 EDT 2012
More information about the Python-list mailing list
Thu Sep 20 15:15:06 EDT 2012
- Previous message (by thread): Fool Python class with imaginary members (serious guru stuff inside)
- Next message (by thread): How to limit CPU usage in Python
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, 20 Sep 2012 06:52:07 -0700, Jure Erznožnik wrote: > I'm trying to create a class that would lie to the user that a member is > in some cases a simple variable and in other cases a class. The nature > of the member would depend on call syntax like so: > 1. x = obj.member #x becomes the "simple" value contained in member > 2. x = obj.member.another_member #x becomes the "simple" value > contained in first member's another_member. Why do you hate your users so much that you want to cause them enormous difficulty with perfectly reasonable code like this? tmp = obj.member x = tmp.another_member > So the first method "detects" that we only need a simple value and > returns that. Fortunately that is impossible without nasty bytecode or AST hacks. Thank the stars that Python doesn't allow anything as badly designed as this! -- Steven
- Previous message (by thread): Fool Python class with imaginary members (serious guru stuff inside)
- Next message (by thread): How to limit CPU usage in Python
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list