"import" not working?

Lionel lionel.keene at gmail.com
Fri Feb 20 19:40:03 EST 2009


On Feb 20, 4:15 pm, Matimus <mccre... at gmail.com> wrote:
> On Feb 20, 3:56 pm, Lionel <lionel.ke... at gmail.com> wrote:
>
>
>
>
>
> > On Feb 20, 3:52 pm, Chris Rebert <c... at rebertia.com> wrote:
>
> > > On Fri, Feb 20, 2009 at 3:33 PM, Lionel <lionel.ke... at gmail.com> wrote:
> > > > Hello all:
>
> > > > I've crafted several classes and exceptions which I've stored in a
> > > > file called "DataFileType.py". I then invoke them from within other
> > > > files like this:
>
> > > > # Top of file
>
> > > > import sys
> > > > sys.path.append("c:\DataFileTypes")
>
> > > Recall that the backslash is the escape character in Python and that
> > > therefore you need to put \\ to get a backslash in the resulting path
> > > string. Thus, the path you think you're adding isn't the path that's
> > > getting added.
> > > Alternatively, you can just use forward slashes instead (yes, that
> > > works on Windows from Python).
>
> > > Cheers,
> > > Chris
>
> > > --
> > > Follow the path of the Iguana...http://rebertia.com
>
> > But I'm only using a single backslash in the first example I gave, and
> > it works just fine there. How can this be?
>
> You must be running the python script from a directory where the file
> you are trying to import is already in the path. It never tries to
> look in the (bad) path because it found a file with the same name
> locally. My guess is that you are running the wx example from another
> location, and that is when you run into problems.
>
> Matt- Hide quoted text -
>
> - Show quoted text -

Okay, moving the wx example into the same directory containing the
first example that was working fixed it. This directory only contains
these two modules and nothing else. The old directory which contained
the example that wasn't working did not contain a module with the same
name as the one I was trying to import, so i don't know why this "fix"
worked.



More information about the Python-list mailing list