Link to home
Start Free TrialLog in
Avatar of craigdev
craigdev

asked on

Python - path

Hi Im using Python from .NET and am getting a bit confused by the path variable.

Ideally I want to have my relevant .py files in a separate subfolder and be able to set that to wherever I like. So for instance I have a file called test.py that sits in the same folder as my .NET executable, then the following .NET code allows me to run the test script .....

            PythonEngine.Initialize()
            PythonEngine.ImportModule("test")

Imagine in this case that the path to the exe and .py folder is C:\app\app.exe and C:\app\test.py

Now if I want to move the test.py file to C:\app\pyfiles\test.py how would I change the path so Python can find it in the new folder?

PythonEngine.ImportModule("pyfiles\test") does not seem to work.

Furthermore, in the test.py file I am writing a new text file with this code: f = file(' newfile.txt', 'w') so the newfile.txt appears in whichever folder the test.py script sits in. Ideally I would like to be able to write to a folder such as C:\app\output instead of just whichever folder python is working from.








ASKER CERTIFIED SOLUTION
Avatar of ramrom
ramrom
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of pepr
pepr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial