0

Trying to run bot in server. Ubuntu 20.1

Line in code(Python3)

...
for elem in items['stats']:
        f = open(r"\root\bot_python\list.txt", "r+")
...

Traceback

Traceback (most recent call last):
  File "bot_last_final_18_01_2021.py", line 57, in <module>
    f = open(r"\root\bot_python\list.txt", "r+")
FileNotFoundError: [Errno 2] No such file or directory: '\\root\\bot_python\\list.txt'

How correctly write directoty?

8
  • You are opening the file in read (r+) mode and the file doesn't exists so you get the FileNotFound error as expected. To create a new file and write contents to it, you need to open it in write mode. Jan 18, 2021 at 12:42
  • No, he is already on server. Already check it.
    – Antony
    Jan 18, 2021 at 12:45
  • bot_last_final_18_01_2021.py list.txt
    – Antony
    Jan 18, 2021 at 12:45
  • but you are trying to open this file \root\bot_python\list.txt in read mode? Does list.txt exist in the `\root\bot_python` directory? Jan 18, 2021 at 12:46
  • i think problem in wrong syntax
    – Antony
    Jan 18, 2021 at 12:47

2 Answers 2

0

Directory paths in Linux use forward slash, so try:

for elem in items['stats']:
    f = open("/root/bot_python/list.txt", "r+")
3
  • Traceback (most recent call last): File "bot_last_final_18_01_2021.py", line 57, in <module> f = open("\root\bot_python\list.txt", "r+") FileNotFoundError: [Errno 2] No such file or directory: '\root\x08ot_python\\list.txt'
    – Antony
    Jan 18, 2021 at 12:50
  • If this is the solution and works for you it would be nice if you could mark it as accepted answer :)
    – mcdeck
    Jan 18, 2021 at 13:03
  • Can't accept. Thanks for the feedback! Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score.
    – Antony
    Jan 19, 2021 at 14:00
0

On linux you use "/" instead of "\". So the file location would be /root/bot_python/list.txt. If that doesn't work then try without the .txt at the end. That should be it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.