1

I use Windows 7 64b, Python 3.5.1 32b, Django 1.9.2 and WAMP 2.5.

I try to open file:

  path = ''.join([config_object.bat_files_path, os.sep, config_object.id, ".bat"])
  with open(path, 'w') as file:
       file.write(command)

When I use development server everything is ok, but when I use WAMP, an error occur:

File "C:\\wamp\\www\\xxx\\tasks.py", line 254, in create_bat_file
with open(path), 'w' as file:
FileNotFoundError: [Errno 2] No such file or directory: 'X:\\\\Auto\\\\xxx\\\\bat_files\\\\01.bat'

But I'm sure, that path is correct, because when I test it:

print(os.path.is_file(path))

it returned True. Path is:

'X:\\Auto\\xxx\\bat_files\\01.bat'

So, why I have 4 slashes? I have tried to replace them, but at the end path is always splitted by 4 slashes. Any idea, why is that?

8
  • What's the value of config_object.bat_files_path? May 19, 2016 at 15:22
  • It's a path in database (as string). Exactly: "X:\Auto\xxx\bat_files"
    – Jareq
    May 19, 2016 at 15:25
  • Unrelated to the problem, but you could use os.path.join (plus format). path = os.path.join(config_object.bat_files_path, '{}.bat'.format(config_object.id)).
    – Matthias
    May 19, 2016 at 15:38
  • Are you sure that there are only single backslashes in your database? Please do a print(repr(config_object.bat_files_path)) to see the real content.
    – Matthias
    May 19, 2016 at 15:40
  • @Matthias: result: 'X:\\\\Auto\\\\xxx\\\\bat_files', and without repr: 'X:\\Auto\\xxx\\bat_files', i don't know why, because in DB i entered path with one backslash... In Django admin also is visilble one backslash as a separator.
    – Jareq
    May 19, 2016 at 15:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.