Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is "sys.argv" not available in Sublime API?

This question was already asked on Sublime Forum, but it seems no one can answer it. Maybe you can?

I've got the same issue on Windows 7 and 8, Sublime 2.0.1 x86 version:

Traceback (most recent call last):
File "./sublime_plugin.py", line 362, in run_
File "./myTestPlugin.py", line 8, in run
AttributeError: 'module' object has no attribute 'argv'
like image 221
astronaut Avatar asked Nov 28 '12 07:11

astronaut


1 Answers

Because sublime plugins are not scripts. There is no command line, so there are no command line arguments to parse.

Python, in Sublime, is embedded, and for embedded python code to have sys.argv set, Sublime would have to set the arguments explicitly. See Intro to embedding Python.

If you feel strongly about this, you'd have to make a case with the Sublime Text 2 developer to add a PySys_SetArgvEx(argc, argv, updatepath) call after Py_Initialize().

like image 64
Martijn Pieters Avatar answered Oct 18 '22 21:10

Martijn Pieters