Take the 2-minute tour ×

I have a file main.py like this:

import node.py
[my code...]

and a node.py like this:

[more of my code]

When executing main.py, I get this error:

  File "/home/loldrup/repo/trunk/src/src/main.py", line 2, in <module>
    import node.py
ImportError: No module named py
share|improve this question
What tutorial are you using? Where did you see code like this? Can you quote or link to an example of this? –  S.Lott Oct 27 '10 at 11:59

3 Answers 3

You should just say import node. The . in the name makes python think you want to load a submodule named py of the packagenode, hence the error. All of this is explained in detail in the Python Tutorial.

share|improve this answer
Nope, then I get nodes.append(node(k,positions[k],posChanendsD[k])) –  user488736 Oct 27 '10 at 12:24
Ups, I ment: "TypeError: 'module' object is not callable" –  user488736 Oct 27 '10 at 12:25
Well you should not have a function that has the same name as a module. If you have a node-class in the node-module, qualify the name like this: node.node(k,positions[k],posChanendsD[k]). –  Björn Pollex Oct 27 '10 at 12:26

If you have a function named node in a module called node, the clearest thing to do is:

from node import node

This adds the name node to the local symbol table and makes it reference the function named node in the node module.

It's often less confusing if you give the module and its members different names - though as you learn when you start working with the datetime class in the datetime module, it's not so confusing that the included batteries don't do it.

share|improve this answer

I friend helped me out. It turns out I shall use:

from node import *
share|improve this answer
-1: Read this: docs.python.org/howto/doanddont.html#at-module-level. It's a bad solution. –  S.Lott Oct 27 '10 at 15:30

Your Answer


