471,050 Members | 1,153 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,050 software developers and data experts.

How to tell the parent frame is a C module? (Lazy importing)

Hello all,
I've been working on a lazy import module to be found here:

The basic idea is that a module proxy for foo is returned from an
'import foo' statement. When an attribute of foo is accessed, or
dir(foo) is called, or a from foo import * is done, the module is
actually loaded, and the module proxy is replaced in the calling
frame. This relies on the proxy being able to intercept __getattr__,
etc from the module and behaving appropriately.

This seems to work very well except in the case where the importing
module is a C module.

When getting the attributes of a class in C, python does the following check:

if (!PyModule_Check(m)) {
return NULL;
d = ((PyModuleObject *)m) -> md_dict;

Which does an end-run around all of my module-related evilness.

I'm hoping that there is some way to somehow detect when the import
statement is being called from a C module, and in that case just load
the module normally. But I can't figure out any way to detect that
from python. In fact, in sys.frame it looks like any C modules are
simply skipped over. I could try to detect that an intermdiate frame
is missing, I suppose....

Any pointers?
Feb 15 '06 #1
0 851

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Stuart Wexler | last post: by
2 posts views Thread by Amadelle | last post: by
3 posts views Thread by Zachary Pincus | last post: by
5 posts views Thread by dg.google.groups | last post: by
1 post views Thread by Ryan Krauss | last post: by
1 post views Thread by michal.podlewski | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.