472,779 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 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 1689
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: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.