tags:

views:

67

answers:

3

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
+6  A: 

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.

Space_C0wb0y
Nope, then I get nodes.append(node(k,positions[k],posChanendsD[k]))
Ups, I ment: "TypeError: 'module' object is not callable"
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])`.
Space_C0wb0y
A: 

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

from node import *
-1: Read this: http://docs.python.org/howto/doanddont.html#at-module-level. It's a bad solution.
S.Lott
A: 

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.

Robert Rossney