2

I have this line in my bat file:

C:\Python26\python.exe C:\myPythonDirectory.py

But it fails giving the error: can't open file [Errno2] no such file or directory.

Could it be giving an error because there is a space in one of the folder names in my python directory?

1
  • myPythonDirectory.py is a strange name for a module! Commented Nov 3, 2011 at 23:09

2 Answers 2

2

Absolutely. If there's a space in the path, you need to put the whole path in double quotes.

Sign up to request clarification or add additional context in comments.

Comments

0

If there are spaces in the names of the directories you need to use the below code. For example, the name of the directory and the path is "D:\My New Bot\main.py" . as there is a gap between the words , python recognises only the first word and tries to find path as "D:\My" which does not exist. Please use the below code :

path = r"D:\My New Bot\main.py"

This will work.

2 Comments

This does not really answer the question, which was about calling the script in a batch file. Your syntax would be for creating a path variable inside the Python script with a file name that has spaces, on Windows.
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.