How to run a Python program in a folder whose name has a space in it?

runner

#1

I have a python program called main.py that I want to run.

The issue is, main.py is in a folder called “Simple Test” which has a space in it.

So when I click run, I get the error
python2: can't open file '/home/ubuntu/workspace/Simple': [Errno 2] No such file or directory

How can I run my program? Currently it’s trying to run it with the command Simple\ Test/main.py which is obviously not working. Is this a bug on Cloud9’s side? Are there currently any workarounds?


#2

Good solution: Don’t include spaces in your directory names. This is not standard and can cause simple issues like this that aren’t necessary. Instead use camel case or snake case or something else you like. Just no spaces :slight_smile:

Bad solution: In the terminal, type it as Simple\ Test.


#3

Okay! Thank you for the response.

The odd thing is that I only noticed this issue when I tried opening up some previous programs and they wouldn’t run anymore.

In other words, this wasn’t a problem before, but now something has changed to make it so the programs will no longer run (even though they ran just fine inside directories with spaces in them before.)

Do you by chance know what changed that broke this functionality?

(If it helps, I can try to track down what date the programs were working for me.)


#4

Also, when I try the “Bad solution” (naming the folder “Simple\ Test”), a red error on the top pops up that says the slash is an invalid character.

Am I following the bad solution correctly?


#5

Oh woops, I meant to type it with a slash when you’re in the terminal :slight_smile: I’ve updated my answer to be more clear :wink:


#6

When you say “in the terminal,” do you mean that the “command” slot in my terminal should read Simple\ Test/main.py?

If so, I don’t think that will work, since the error from running that command is what brought me here. (When I click “Run” when I’m on the file main.py, Simple\ Test/main.py is what runs automatically. As I mentioned before, running this command used to work. So, I feel like it should still work, but it doesn’t. Thus the question.)

If not, how should/could I use Simple\ Test in the terminal?


#7

Tough to tell what might be happening here. Close the file, close the run pane, see “Good Solution”, open the file, click Run, then you should be rolling.


#8

Yup, the “Good Solution” works great. I was just curious because I believe the “Bad Solution” had worked for me in the past, so I’m curious to know why it no longer works.

Thanks for all of your help!