Advertisement
stuppid_bot

Неправильная работа с путями (проблемы при работе из консол)

Dec 15th, 2016
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. # with open('xampp/passwords.txt') as f:
  2. # Если запустить скрипт из командной строки, то файл не будет найден:
  3. # C:\Users\Сергей>python d:\\test.py
  4. # Traceback (most recent call last):
  5. #   File "d:\\test.py", line 1, in <module>
  6. #     with open('xampp/passwords.txt') as f:
  7. # FileNotFoundError: [Errno 2] No such file or directory: 'xampp/passwords.txt'
  8. import os.path
  9. cur_dir = os.path.dirname(os.path.realpath(__file__))
  10. with open(os.path.join(cur_dir, 'xampp/passwords.txt')) as f:
  11.     print(f.read())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement