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.

tripleee
  • 175,061
  • 34
  • 275
  • 318
maryam sh
  • 21
  • 3
  • 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 – SiP Apr 07 '22 at 09: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 [tag:python-2.7] and [tag:python-3.x] tags. I have removed the latter as you say you need a Python 2 solution. – tripleee Apr 07 '22 at 09:48

0 Answers0