-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512


On June 14, 2014 8:50:48 AM GMT+03:00, LCD 47 <lcd...@gmail.com> wrote:
>On 13 June 2014, BaRud <bnrj.ru...@live.com> wrote:
>> Hi,
>>
>> I am trying to write a vimscript that uses python, but cant interface
>> it properly.
>>
>> A minimal example is:
>>
>> function! Usrnm(nm)
>> python << endpython
>> import vim
>> import os
>> nm=vim.eval(os.getlogin())
>> endpython
>> echo nm
>> endfunction
>>
>> call IMAP ('`foo', "@nm \<CR> Usrnm(nm)", "fortran")
>>
>> Can anyone please help me achiving this? i.e. getting the login name
>> to be used in the IMAP call?
>
>    You got it backwards, vim.eval() is for passing Vim values to
>Python, not the other way around.  You probably want vim.command()
>instead:
>
>
>function! Usrnm()
>
>    if has('python')
>        python <<EOT
>import vim
>import getpass
>vim.command("let nm = '%s'" % getpass.getuser())
>EOT
>        echo nm
>    else
>        echo 'no python, no cry'
>    endif
>endfunction

There is pyeval() for this case:

    python import getpass
    return pyeval('getpass.getuser()')

>
>
>    For returning dictionaries, lists, or funcrefs, there is also
>vim.bindeval(), thanks to ZyX. :) See the manual for details.
>
>    /lcd
-----BEGIN PGP SIGNATURE-----
Version: APG v1.1.1

iQI1BAEBCgAfBQJTnBv0GBxaeVggPHp5eC52aW1AZ21haWwuY29tPgAKCRCf3UKj
HhHSvoITD/wK3k8EYTJ9yivcBrIZdYk9AuWWR3TNQBr3LHl2vGdIa8nMMYMQ1fMq
ochw1icB2ybSqrEHC5il00rsnjht8aYFJWX4n0syo/7pQIG12MyKdO31Q61HfBdR
Jr2bBR5KUBiG3a8fMn97ZAcZK5a8CqKRHuRpVcesKv4xxSVU/mzRtAHARdv38WlY
t7jUKzu91fKdHdR7Arov1opeAcQToinhZ1gVCHcotHNUQXgwY/1mQgJECWNV949U
oF73U8qVZO51n2I60wGxw4O8vXiE+MND6TkooVMWXsz39UAnOr9WKYWgDkoqPnza
oPtZxiJhl4Qw+pjX+3b0PSpvzmckqvmHFGLrRkniTcnpOkAR+w0MSznAdz/6Yl/h
aQ17OzLUQFA/bQpjdYnygo9n4UlvJ+mX8KMkvPcb467rc+wmt3OWGFB+kCjhQwWN
NAqZKiuWLMmPrdDYUmIamgO4DOCNkPSuJOAEpcvZnarLosRQyg+K68uYr7eqvNED
vghvXpJnVfeu7QkGH291f/pgEY7I8dNxQ4rgJtLL6xEB8dGalyMpCJYoRFqJk534
Aej6VB4R3qpk8HbnwpT9KdQT3eFuGkB5lR/lGpCBcH/EtFNY5zmpxWJ5xExb6mZv
QM7b3yoFXGRDd+7pGNkYfMPJ5EIEOV3+j3oqx+FldUTEb5YVxGkxAg==
=EH6h
-----END PGP SIGNATURE-----

-- 
-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_use+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to