468,305 Members | 1,510 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,305 developers. It's quick & easy.

Why doesn't this work? :)

Jumping right into the code (which should speak for itself):

# -----------------------------------

try:
# this will fail and be caught
# below, weeee
import foobar

except ImportError, error:
class foobar:
@staticmethod
def __getattr__(*args, **kargs):
return None

print foobar.bg

# -----------------------------------

This doesn't work and I'm just curious as to why? I can, of course, make
__getattr__ non-static, instantiate a foolbar object, and everything
works; but, the "idea" above seems cleaner and whatnot. :)

Am I misunderstanding something fundamental about the builtin __*
functions? Can they not be "static?"

No rush on this, just curious. I'm using the following in a more general
way, and it works fine for now... :)

# -----------------------------------

try:
import foobar

except ImportError, error:
class Foobar:
def __getattr__(*args, **kargs):
return None

foobar = Foobar()

print foobar.bg

# -----------------------------------
Oct 28 '05 #1
1 1278
Jeremy Moles <je****@emperorlinux.com> wrote:
Am I misunderstanding something fundamental about the builtin __*
functions? Can they not be "static?"


They can and must be static when their specification say they are (e.g.,
__new__) and they cannot and must not be static when their specification
says otherwise (just about all of them).
Alex
Oct 29 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

39 posts views Thread by Mark Johnson | last post: by
149 posts views Thread by Christopher Benson-Manica | last post: by
4 posts views Thread by bbp | last post: by
3 posts views Thread by Dave Moore | last post: by
10 posts views Thread by Sourcerer | last post: by
6 posts views Thread by Johnny Jörgensen | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.