troubleshooting Question

Python - path

Avatar of craigdev
craigdev asked on
Python
2 Comments1 Solution930 ViewsLast Modified:
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.








Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros