This seems, to be, as far as I can tell, completely random. I don’t know what’s going on with it. I’m on Windows.
>>> python ex.py
File "<stdin>", line 1
python ex.py
^
SyntaxError: invalid syntax
Can anyone tell me what’s causing it? It’s weird as hell… python 2.7, by the way. Comes up the same whether I go through Powershell or CMD.
You are inside an interactive session of the python interpreter itself, and you can not make calls to python in that way.
Run the command directly from the command line instead.
If you want to execute a file from within python in this way, you must use:
By the way, don’t get in the habit of using
execfile– while handy, unless you really know what you’re doing and why, it’s not considered the best idea.To elaborate on that, per @Levon’s request,
execfile, along withexecandeval, cause your script to run absolutely arbitrary code. If you control all of your code and are the sole user, then this isn’t really a problem. However, because this power is so great, it could easily be abused by others. So, if you distribute your code, and there is absolutely any other way to design it other than to useexecfile, do so.