472,126 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

import parser does not import parser.py in same dir on win

Hi!

I have a possibly dumb question about imports. I've written two python
modules:

parser.py
------------------------------------
class Parser(object):
"my parser"
------------------------------------

app.py
------------------------------------
from parser import Parser
print "import successful"
------------------------------------

Running app.py on linux, gives:
------------------------------------
import succesful
------------------------------------

However, runnning it on windows gives:
------------------------------------
Traceback (most recent call last):
File "test.py", line 1, in ?
from parser import Parser
ImportError: cannot import name Parser
------------------------------------

It turns out that on Windows, the builtin parser module is imported
instead. Why? Why is there a difference? What other names are "taken"?

In both cases the script dir is first on sys.path, and I'm using the
plain old terminal/cmd window.

Thanks for your time.

Cheers!
/Joel Hedlund
Nov 11 '06 #1
2 3102
Joel Hedlund wrote:
It turns out that on Windows, the builtin parser module is imported
instead. Why?
the table of built-in modules are checked before searching the path.
Why is there a difference? What other names are "taken"?
depends on how the interpreter is built; there's a sys variable that
contains a list of all built-ins:

http://effbot.org/pyref/sys.builtin_module_names

</F>

Nov 11 '06 #2
the table of built-in modules are checked before searching the path.

I figured as much. But why is the behavior different on linux/win? Is
this documented somewhere?

/Joel
Nov 11 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Dennis | last post: by
2 posts views Thread by bearclaws | last post: by
5 posts views Thread by szepesg | 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.