I placed a text file in the same directory as models.py and wrote a file opening and reading code in models.py to open and read the file content. I have set all permissions of the file properly as well. But the file is not read. I'm not sure whether it's a location error. The code works well independently (that means if the python code is run alone, not within odoo). Please help me in this...
The solution you found works in your computer, but it'll break if you try to use the module anywhere else. A better solution is to get the path of your module, then append the .txt file name:
directory_path = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
return os.path.join(directory_path, 'filename.txt')
By the way, unless you have a good reason not to do so, I advise you to use "with open(...) as logFile:" instead of "logFile = open(...)", since it makes sure it'll always close the file, even if there's an exception. Otherwise, you might leak file handles.
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
About This Community
|Asked: 11/8/15, 11:17 PM|
|Seen: 1477 times|
|Last updated: 11/10/15, 11:47 PM|