473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

where's "import" in the C sources?

Hi,

i tried to find the file and line in the C sources of python
where the command "import" is implemented. Can anybody give
me some hint on this?
Thanks,
Torsten.

Jul 18 '05 #1
2 1724
Torsten Mohr <tm***@s.netic.de> writes:
i tried to find the file and line in the C sources of python
where the command "import" is implemented. Can anybody give
me some hint on this?


Well, there are several levels, depending on what you are looking for.
The literal "import" syntax in a source module is translated by the
Python compiler to various IMPORT_* bytecodes, which are processed in
the main interpreter loop (see ceval.c).

They all basically bubble down to making use of the builtin __import__
method, which is obtained from the builtin module defined in
bltinmodule.c.

That in turn makes use of the import processing module whose code can
be found in import.c - which is the same source that also implements
the "imp" module to provide lower layer access to to the import
internals.

Now, when it comes to physically loading in a module, Python source
and compiled modules are handled by import (well, not the compiling
part), but dynamically loaded extension modules are OS specific. You
can find the handling of such extension modules in OS-specific source
files dynload_*.c (e.g., dynload_win.c for Windows).

All of these files can be found in the dist/src/Python directory in
the Python source tree.

-- David
Jul 18 '05 #2
Hi David,

thanks for the explanation. That is very helpful to me.
Best regards,
Torsten.
David Bolen wrote:
Torsten Mohr <tm***@s.netic.de> writes:
i tried to find the file and line in the C sources of python
where the command "import" is implemented. Can anybody give
me some hint on this?


Well, there are several levels, depending on what you are looking for.
The literal "import" syntax in a source module is translated by the
Python compiler to various IMPORT_* bytecodes, which are processed in
the main interpreter loop (see ceval.c).

They all basically bubble down to making use of the builtin __import__
method, which is obtained from the builtin module defined in
bltinmodule.c.

That in turn makes use of the import processing module whose code can
be found in import.c - which is the same source that also implements
the "imp" module to provide lower layer access to to the import
internals.

Now, when it comes to physically loading in a module, Python source
and compiled modules are handled by import (well, not the compiling
part), but dynamically loaded extension modules are OS specific. You
can find the handling of such extension modules in OS-specific source
files dynload_*.c (e.g., dynload_win.c for Windows).

All of these files can be found in the dist/src/Python directory in
the Python source tree.

-- David


Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Vio | last post by:
Hi, I've been trying to embed (statically) wxPy alongside an embedded py interpreter on a linux/gtk box. At one point, for some reason misc.o linking reported "multiple definitions of...
2
by: Tian | last post by:
I am writing a python program which needs to support some plug-ins. I have an XML file storing some dynamic structures. XML file records some class names whose instance needs to be created in the...
9
by: monkey | last post by:
I just learn to make a blank windows frame with python and wxpython. I found the statment "import wx" cannot work as the original "from wxPython.wx import *". I see in the readme file of wxpython...
3
by: Mudcat | last post by:
I have a directory structure that contains different modules that run depending on what the user selects. They are identical in name and structure, but what varies is the content of the functions....
3
by: Chris | last post by:
Hi, 1) In file test.aspx, i put: <%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %> <%@ import namespace="System.Data"%> <%@ import...
5
by: mark_galeck_spam_magnet | last post by:
Hi, why does complain name 'compileFile' not defined. But works. Why? (I did read the tutorial, it seems to say "import module" should work. Thank you, Mark
14
by: Paulo da Silva | last post by:
Hi! If I have two files .py such as m.py from c import * ... x=c() ... os.any_method ...
1
by: Eric Hanchrow | last post by:
(This is with Python 2.5.2, on Ubuntu Hardy, if it matters.) This seems so basic that I'm surprised that I didn't find anything about it in the FAQ. (Yes, I am fairly new to Python.) Here are...
3
by: J. Cliff Dyer | last post by:
On Thu, 2008-05-08 at 12:00 -0700, Eric Hanchrow wrote: It's the same reason as this: 5 5 6 5 Python "variables" are just names that point at objects. When you
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.