I am trying to run the following code on ubuntu but getting file not found error. But same code is working fine on my windows machine
...
for elem in items['stats']:
f = open(r"\root\bot_python\list.txt", "r+")
...
I am trying to run the following code on ubuntu but getting file not found error. But same code is working fine on my windows machine
...
for elem in items['stats']:
f = open(r"\root\bot_python\list.txt", "r+")
...
You should use double back slash instead of single. Like this:
...
for elem in items['stats']:
f = open(r"\\root\\bot_python\\list.txt", "r+")
...
Because the path separator is different between Ubuntu and Windows. See Path separator for Windows and Unix and separator for both Linux and Windows. For python, you could use os.path.join to parse your file path before reading it. Btw, pathlib is also a good option if you're familiar with some object-oriented concepts.
I think you need root permission to access the file see you are trying to access a file inside root directory... Try Running the python script with "sudo python file_name.py" Maybe it solves your issue. And use backward slashes for spaces whenever possible.