1

A vim-script file calls a python script through:

let s:pyscript = resolve(expand('<sfile>:p:h:h')) . '/pyscript/deploy.py'

echom "sourcing " . s:pyscript
pyfile s:pyscript

the echom-command shows me the expansion points to the correct file, but the following pyfile s:pyscript results in an error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
IOError: [Errno 2] file or directory not found: '&s:pyscript' 

Which let's me conclude, that everythin after pyfile is immediately considered "python" and vim doesn't evaluate the s:pyscript variable.

What's the way around it? Either in the python-script or the vim-"master" script is fine.

Don Question
  • 11,227
  • 5
  • 36
  • 54

1 Answers1

8

Use :execute:

execute 'pyfile ' . s:pyscript
icktoofay
  • 126,289
  • 21
  • 250
  • 231
  • The second after i posted my question, i got the same idea. Just tried it and was in the process to answer myself, but you beat me to it! ;-) Thx nevertheless! – Don Question Jan 19 '14 at 02:11
  • Sometimes you just don't see the forest ... - will accept your answer after the time-lapse! – Don Question Jan 19 '14 at 02:12
  • Great. This info, including the process to build the path to the python script, is vital to run python scripts inside Vim, so it should be prominent in the Vim scripting docs. – jose Jul 21 '15 at 08:22