Python, import a modulo from a father directory
Question: I want to know how import a file that is one level up. I read in google this:

    
    
    >>> sys.path.append("../")
    

But I dont like it and i hope there are a better solution


Answer: Another option, if what you are writing is part of a package, is to use
relative imports like so:

    
    
    from .. import foo
    

where `foo` is the name of the module you're trying to import.

Similarly, if you've got another module in the current directory, you can use:

    
    
    from . import bar
    

Sadly (or perhaps not so sadly), though, this doesn't extend any further than
this. You can't go up to a grandparent, or higher.

**EDIT** :

As so graciously pointed out by JAB, my last comment there is not true:

> from ...sys import path
>
> Note that while that last case is legal, it is certainly discouraged
> ("insane" was the word Guido used).

I must have internalized Guido's description of it too much. ;^)

**EDIT** :

Okay, I just verified this in 2.7 - this apparently goes as deep as you like,
and is dependent on the number of `.`

    
    
    from .... import greatgrandparent
    

works juuuust fine. I think I'm going to need [a
bucket](http://en.wikipedia.org/wiki/Mr_Creosote)

