Open optozorax opened 4 years ago
Hmmm, sorry for being husty. I'm discovered that simple print()
inside inline python didn't show anything on my console.
I use Windows 10 + Git Bash.
On PowerShell python errors and print showed correctly.
Also, the original error is this:
baseName = os.path.basename(sys.argv[0])
IndexError: list index out of range
So, this hack works:
import sys
sys.argv = ["./myprog"]
Therefore Original issue expanded to two problems:
sys.argv
is emptyI think by default sys.args[0]
should contain program address.
Interesting. Here on Linux, sys.argv
is ['']
, not []
. Your example runs fine here.
Apparently something about sys.argv
is different on Windows.
I don't have a Windows computer here to test, but looking at the CPython source code, it looks like it should be impossible for sys.argv
to be empty:
/* sys.argv must be non-empty: empty argv is replaced with [''] */
assert(config->argv.length >= 1);
So not sure what's happening in your case.
This is also the documented behaviour:
If no script name was passed to the Python interpreter, argv[0] is the empty string.
I'm trying to run this code:
But get only this error:
But this code works as single python file.
It will be fine to get errors from python interpreter why code is failed to execute.
Also, is
import
supported?