VIM/Python cannot return value to VIM
Question: I'm trying to create a Python plugin for VIM that will detect whether or not
the current project is an Android Project. Unfortunately, I cannot get it to
return boolean values back to VIM. Calling the plugin from within VIM just
outputs nothing. The code below uses the `print` command but I've also tried
`vim.command("return {value}")` and setting vim variables from within the
script. Any insight?

I have a plugin file with these contents

    
    
    if !has('python')
        echo "Error: Required vim compiled with +python"
        finish
    endif
    
    
    " Get local path for the script, so we can import other files
    let s:script_folder_path = escape( expand( '<sfile>:p:h' ), '\' )
    let s:python_folder_path = s:script_folder_path . '/../python/'
    
    " Start the python file in the scriptdir
    function! s:startPyfile(fileName)
        execute "pyfile " . s:python_folder_path . a:fileName
    endfunction
    command! Detect call Detect()
    function! Detect()
      call s:startPyfile("vim_detect.py")
    endfunction
    

which calls vim_detect.py which contains this

    
    
    #! /usr/bin/env python
    
    import vim
    import os
    import sys
    
    # Add current scriptdir to import sources
    current_script_dir = vim.eval('s:python_folder_path')
    sys.path.append(current_script_dir)
    
    class VimDetect:
    
        def executeCommand(self):
            if self.isAndroidGradleProject():
                print 1
            else:
                print 0
    
    
        def isAndroidGradleProject():
            if(isGradleProject() and isAndroidProject()):
                return True
            else:
                return False
    
    
        def isGradleProject():
            if findFileInDirectory("build.gradle"):
                return True
            else:
                return False
    
        def isAndroidProject():
            if findFileInDirectory("AndroidManifest.xml"):
                return True
            else:
                return False
    
        def findFileInDirectory(filename):
            top = os.getcwd()
    
            matches = 0
            for root, dirnames, files in os.walk(top):
                for file in fnmatch.filter(files, filename):
                    matches = matches + 1
            if matches > 0:
                return True
            else:
                return False
    


Answer: As others have commented, your example code (which you should have condensed
to a minimal example) isn't actually invoked. The way I've returned a result
from Python is by setting a Vim variable, like this:

    
    
    strValue = "just a test"
    vim.command("let python_result = '%s'" % str(strValue).replace("'", "''"))
    

For a boolean, just return `0` / `1` as a number, simplifying the logic:

    
    
    vim.command("let python_result = %d" % int(boolValue))
    

