Код: Выделить всё
def write_to_json(IP, slice_id, json_lines):
#IP = "127.0.0.1" (or any other network id as str)
#slice_id = 1
#json_lines: string
output_file = r"\\{}\hatches\slice{}.json".format(IP, slice_id)
subprocess.run(f"echo. >> {output_file}", shell=True)
with open(output_file, "a") as f: #also tried w
for line in json_lines:
f.write(line + '\n')
Код: Выделить всё
[Errno 2] No such file or directory: '\\\\127.0.0.1\\hatches\\slice1.json'
- передача пути как
Код: Выделить всё
output_file = r"{}\hatches\slice{}.json".format(IP, slice_id)
Код: Выделить всё
[Errno 2] No such file or directory: '127.0.0.1\\hatches\\slice1.json'
- удаление обратной косой черты приводит к:
Код: Выделить всё
output_file.remove(r"\\","")
[Errno 2] Не удалось подключиться к сети «127.0.0.1hatchesslice1.json»
Есть ли у кого-нибудь идеи, как решить эту проблему с обратной косой чертой? (Синакс изменить нельзя, так как в противном случае соединение будет невозможно.)
Подробнее здесь: https://stackoverflow.com/questions/782 ... alled-by-q