Wolfpack'08
Wolfpack'08

Reputation: 4128

Python: How do I call a script in a parent directory's subdirectory?

I'm trying to open a Python script from the Python command line. There's a bug in Python that makes adding Python to my environmental variable's path ineffective. So, I have to run Python command line from the Python directory.

My script is at c:/mydir/myfile.py

How do I open it from c:/python27/python.exe; >>?

Upvotes: 0

Views: 166

Answers (1)

onemach
onemach

Reputation: 4325

access your parent directory by

import sys
sys.path.append("..")

then you access a subdirectory by placing a __init__.py in subdirectory and writing something in it like

__all__ = ['myfile']

then you can import myfile

Or you just want to run it. In that case you can use an absolute path. eg. python c:\mydir\myfile.py

Upvotes: 1

Related Questions