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.








Python

Avatar of undefined
Last Comment
pepr

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
ramrom

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
pepr

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Your help has saved me hundreds of hours of internet surfing.
fblack61