0

I have a python file that must be called from within a software (which use python 2.7). This python file use np.loadtxt() to read some data. The software have its own working directory, so when I want to run the python file from within the software, I must put the data files into its working directory. I want to put data files and the python file in a folder and address this folder so that when I run the code by the software, this code find the folder address and its containing data (not to copy paste data in the software's directory each time). I used os.getcwd as:

data = np.loadtxt(os.getcwd() + "/" + "data.csv")

but it didn't help. While when I get its full address like:

data = np.loadtxt("C:\...\data.csv")

It will work. How could I do this using os modules to find folder directory automatically. It seems it is running from shell, perhaps it be relating to this.

2
  • I'm not sure I understand the question. To find files in the same directory as the script file you can try using __file__ in the script Commented Apr 7, 2022 at 9:33
  • Unless you are specifically asking about how to solve a cross-version compatibility problem (in which case your question should obviously describe that problem) you should not mix the python-2.7 and python-3.x tags. I have removed the latter as you say you need a Python 2 solution. Commented Apr 7, 2022 at 9:48

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.