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

Discussion in 'Python' started by Joel Hedlund, Nov 11, 2006.

  1. Joel Hedlund

    Joel Hedlund Guest

    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
    Joel Hedlund, Nov 11, 2006
    #1
    1. Advertising

  2. 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>
    Fredrik Lundh, Nov 11, 2006
    #2
    1. Advertising

  3. Joel Hedlund

    Joel Hedlund Guest

    > 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
    Joel Hedlund, Nov 11, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UnVkeQ==?=

    Sub Dir, Virtual dir, what do I use?

    =?Utf-8?B?UnVkeQ==?=, Jun 12, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    421
    =?Utf-8?B?UnVkeQ==?=
    Jun 12, 2005
  2. per9000
    Replies:
    7
    Views:
    402
    Magnus Lycka
    Feb 27, 2006
  3. Joel Hedlund
    Replies:
    0
    Views:
    303
    Joel Hedlund
    Nov 11, 2006
  4. Krist
    Replies:
    6
    Views:
    736
    Arne Vajhøj
    May 7, 2010
  5. Matthew Denner
    Replies:
    1
    Views:
    176
Loading...

Share This Page