[Tutor] Can anyone explain this

Dave Angel davea at davea.name
Thu Aug 8 02:11:58 CEST 2013


Amandeep Behl wrote:

> Can anyone explain this code below:
>
>
>
> <div dir="ltr"><div>Can anyone explain this code below:</div><div><br></div><br><div><div>import sys</div><div>import os</div><div>                              </div><div>if __name__ == '__main__':  </div><div>    sys.path.insert(0, "..") </div>
> <div>else:                        </div><div>    sys.path.insert(0, os.path.join(</div><div>        os.path.split(__file__)[0], '..'))</div></div></div>
>

Yes, the gobbledygook is caused by selecting html email, rather than the
needed text form.

As for the code that's buried inside there, it seems to have no
usefulness if the file is run directly as a script, but if it's imported
from another script, it adds a particular directory to the search path.

Subsequent imports may find imports in that directory.

-- 
DaveA




More information about the Tutor mailing list