1

I am trying to set a python variable in vim using vimscript output. The following code is causing the issue:

 python os.environ['DJANGO_SETTINGS_MODULE'] = split(expand("%:p:h"), "\/")[4].'.settings'

The issue is that i am running a line of python code, but want everything after the "=" sign to be evaluated by vim, as I want to assign the value of the :split(expand("%:p:h"), "\/")[4].'.settings' vim command to the python variable os.environ['DJANGO_SETTINGS_MODULE']

How can I do this?

1 Answer 1

2

Try something like this:

import vim
os.environ['DJANGO_SETTINGS_MODULE'] = \
    vim.eval("""expand("%:p:h")""").split('/')[4] + '.settings'
Sign up to request clarification or add additional context in comments.

1 Comment

Fantastic, thank you very much! To insert this into a .vimrc, the following lines are what do it. python import vim <NEW-LINE> python os.environ['DJANGO_SETTINGS_MODULE'] = vim.eval("""split(expand("%:p:h"), "\/")[4].'.settings'""")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.