I have a python program, which loads a python module created with c++ and imported as dll. In the python program, I created a file called cpp.conf in the working directory.
with open('cpp.conf', 'w') as cppconf:
cppconf.write("blabla")
The c++ module is imported later by the python program. On the c++ side, I tried to open the file cpp.conf, but it failed.
std::string configFile = "cpp.conf";
std::ifstream ifs(configFile.c_str());
if (ifs.good()) {
std::cout << "opened file successfully." << std::endl;
}
else {
std::cout << "failed to open file." << std::endl;
}
However, after the program is finished, I can see the file cpp.conf. I thought it could be that the c++ needs some time to let the file be seen on the disk, so I tried the following:
with open('cpp.conf', 'w') as cppconf:
cppconf.write("blabla")
import time
time.sleep(5) # wait 5 seconds
it did not help either.
If the python program did not touch the file, that is, did not open it to write, the c++ side can open the file successfully.
Is there a reason to this effect?
The platform is windows 7, I did not try on Linux.
SOLVED!